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 | 4dadd15 | 2020-05-03 14:38:50 +0200 | [diff] [blame] | 162 | static void smc_llc_enqueue(struct smc_link *link, union smc_llc_msg *llc); |
| 163 | |
Karsten Graul | 555da9a | 2020-04-30 15:55:38 +0200 | [diff] [blame] | 164 | struct smc_llc_qentry *smc_llc_flow_qentry_clr(struct smc_llc_flow *flow) |
| 165 | { |
| 166 | struct smc_llc_qentry *qentry = flow->qentry; |
| 167 | |
| 168 | flow->qentry = NULL; |
| 169 | return qentry; |
| 170 | } |
| 171 | |
| 172 | void smc_llc_flow_qentry_del(struct smc_llc_flow *flow) |
| 173 | { |
| 174 | struct smc_llc_qentry *qentry; |
| 175 | |
| 176 | if (flow->qentry) { |
| 177 | qentry = flow->qentry; |
| 178 | flow->qentry = NULL; |
| 179 | kfree(qentry); |
| 180 | } |
| 181 | } |
| 182 | |
| 183 | static inline void smc_llc_flow_qentry_set(struct smc_llc_flow *flow, |
| 184 | struct smc_llc_qentry *qentry) |
| 185 | { |
| 186 | flow->qentry = qentry; |
| 187 | } |
| 188 | |
Karsten Graul | 6778a6b | 2020-07-08 17:05:11 +0200 | [diff] [blame] | 189 | static void smc_llc_flow_parallel(struct smc_link_group *lgr, u8 flow_type, |
| 190 | struct smc_llc_qentry *qentry) |
| 191 | { |
| 192 | u8 msg_type = qentry->msg.raw.hdr.common.type; |
| 193 | |
| 194 | if ((msg_type == SMC_LLC_ADD_LINK || msg_type == SMC_LLC_DELETE_LINK) && |
| 195 | flow_type != msg_type && !lgr->delayed_event) { |
| 196 | lgr->delayed_event = qentry; |
| 197 | return; |
| 198 | } |
| 199 | /* drop parallel or already-in-progress llc requests */ |
| 200 | if (flow_type != msg_type) |
| 201 | pr_warn_once("smc: SMC-R lg %*phN dropped parallel " |
| 202 | "LLC msg: msg %d flow %d role %d\n", |
| 203 | SMC_LGR_ID_SIZE, &lgr->id, |
| 204 | qentry->msg.raw.hdr.common.type, |
| 205 | flow_type, lgr->role); |
| 206 | kfree(qentry); |
| 207 | } |
| 208 | |
Karsten Graul | 555da9a | 2020-04-30 15:55:38 +0200 | [diff] [blame] | 209 | /* try to start a new llc flow, initiated by an incoming llc msg */ |
| 210 | static bool smc_llc_flow_start(struct smc_llc_flow *flow, |
| 211 | struct smc_llc_qentry *qentry) |
| 212 | { |
| 213 | struct smc_link_group *lgr = qentry->link->lgr; |
| 214 | |
| 215 | spin_lock_bh(&lgr->llc_flow_lock); |
| 216 | if (flow->type) { |
| 217 | /* a flow is already active */ |
Karsten Graul | 6778a6b | 2020-07-08 17:05:11 +0200 | [diff] [blame] | 218 | smc_llc_flow_parallel(lgr, flow->type, qentry); |
Karsten Graul | 555da9a | 2020-04-30 15:55:38 +0200 | [diff] [blame] | 219 | spin_unlock_bh(&lgr->llc_flow_lock); |
| 220 | return false; |
| 221 | } |
| 222 | switch (qentry->msg.raw.hdr.common.type) { |
| 223 | case SMC_LLC_ADD_LINK: |
| 224 | flow->type = SMC_LLC_FLOW_ADD_LINK; |
| 225 | break; |
| 226 | case SMC_LLC_DELETE_LINK: |
| 227 | flow->type = SMC_LLC_FLOW_DEL_LINK; |
| 228 | break; |
| 229 | case SMC_LLC_CONFIRM_RKEY: |
| 230 | case SMC_LLC_DELETE_RKEY: |
| 231 | flow->type = SMC_LLC_FLOW_RKEY; |
| 232 | break; |
| 233 | default: |
| 234 | flow->type = SMC_LLC_FLOW_NONE; |
| 235 | } |
| 236 | if (qentry == lgr->delayed_event) |
| 237 | lgr->delayed_event = NULL; |
Karsten Graul | 555da9a | 2020-04-30 15:55:38 +0200 | [diff] [blame] | 238 | smc_llc_flow_qentry_set(flow, qentry); |
Karsten Graul | 6778a6b | 2020-07-08 17:05:11 +0200 | [diff] [blame] | 239 | spin_unlock_bh(&lgr->llc_flow_lock); |
Karsten Graul | 555da9a | 2020-04-30 15:55:38 +0200 | [diff] [blame] | 240 | return true; |
| 241 | } |
| 242 | |
| 243 | /* start a new local llc flow, wait till current flow finished */ |
| 244 | int smc_llc_flow_initiate(struct smc_link_group *lgr, |
| 245 | enum smc_llc_flowtype type) |
| 246 | { |
| 247 | enum smc_llc_flowtype allowed_remote = SMC_LLC_FLOW_NONE; |
| 248 | int rc; |
| 249 | |
| 250 | /* all flows except confirm_rkey and delete_rkey are exclusive, |
| 251 | * confirm/delete rkey flows can run concurrently (local and remote) |
| 252 | */ |
| 253 | if (type == SMC_LLC_FLOW_RKEY) |
| 254 | allowed_remote = SMC_LLC_FLOW_RKEY; |
| 255 | again: |
| 256 | if (list_empty(&lgr->list)) |
| 257 | return -ENODEV; |
| 258 | spin_lock_bh(&lgr->llc_flow_lock); |
| 259 | if (lgr->llc_flow_lcl.type == SMC_LLC_FLOW_NONE && |
| 260 | (lgr->llc_flow_rmt.type == SMC_LLC_FLOW_NONE || |
| 261 | lgr->llc_flow_rmt.type == allowed_remote)) { |
| 262 | lgr->llc_flow_lcl.type = type; |
| 263 | spin_unlock_bh(&lgr->llc_flow_lock); |
| 264 | return 0; |
| 265 | } |
| 266 | spin_unlock_bh(&lgr->llc_flow_lock); |
Karsten Graul | 6778a6b | 2020-07-08 17:05:11 +0200 | [diff] [blame] | 267 | rc = wait_event_timeout(lgr->llc_flow_waiter, (list_empty(&lgr->list) || |
| 268 | (lgr->llc_flow_lcl.type == SMC_LLC_FLOW_NONE && |
| 269 | (lgr->llc_flow_rmt.type == SMC_LLC_FLOW_NONE || |
| 270 | lgr->llc_flow_rmt.type == allowed_remote))), |
| 271 | SMC_LLC_WAIT_TIME * 10); |
Karsten Graul | 555da9a | 2020-04-30 15:55:38 +0200 | [diff] [blame] | 272 | if (!rc) |
| 273 | return -ETIMEDOUT; |
| 274 | goto again; |
| 275 | } |
| 276 | |
| 277 | /* finish the current llc flow */ |
| 278 | void smc_llc_flow_stop(struct smc_link_group *lgr, struct smc_llc_flow *flow) |
| 279 | { |
| 280 | spin_lock_bh(&lgr->llc_flow_lock); |
| 281 | memset(flow, 0, sizeof(*flow)); |
| 282 | flow->type = SMC_LLC_FLOW_NONE; |
| 283 | spin_unlock_bh(&lgr->llc_flow_lock); |
| 284 | if (!list_empty(&lgr->list) && lgr->delayed_event && |
| 285 | flow == &lgr->llc_flow_lcl) |
| 286 | schedule_work(&lgr->llc_event_work); |
| 287 | else |
Karsten Graul | 6778a6b | 2020-07-08 17:05:11 +0200 | [diff] [blame] | 288 | wake_up(&lgr->llc_flow_waiter); |
Karsten Graul | 555da9a | 2020-04-30 15:55:38 +0200 | [diff] [blame] | 289 | } |
| 290 | |
| 291 | /* lnk is optional and used for early wakeup when link goes down, useful in |
| 292 | * cases where we wait for a response on the link after we sent a request |
| 293 | */ |
| 294 | struct smc_llc_qentry *smc_llc_wait(struct smc_link_group *lgr, |
| 295 | struct smc_link *lnk, |
| 296 | int time_out, u8 exp_msg) |
| 297 | { |
| 298 | struct smc_llc_flow *flow = &lgr->llc_flow_lcl; |
Karsten Graul | 6778a6b | 2020-07-08 17:05:11 +0200 | [diff] [blame] | 299 | u8 rcv_msg; |
Karsten Graul | 555da9a | 2020-04-30 15:55:38 +0200 | [diff] [blame] | 300 | |
Karsten Graul | 6778a6b | 2020-07-08 17:05:11 +0200 | [diff] [blame] | 301 | wait_event_timeout(lgr->llc_msg_waiter, |
| 302 | (flow->qentry || |
| 303 | (lnk && !smc_link_usable(lnk)) || |
| 304 | list_empty(&lgr->list)), |
| 305 | time_out); |
Karsten Graul | 555da9a | 2020-04-30 15:55:38 +0200 | [diff] [blame] | 306 | if (!flow->qentry || |
| 307 | (lnk && !smc_link_usable(lnk)) || list_empty(&lgr->list)) { |
| 308 | smc_llc_flow_qentry_del(flow); |
| 309 | goto out; |
| 310 | } |
Karsten Graul | 6778a6b | 2020-07-08 17:05:11 +0200 | [diff] [blame] | 311 | rcv_msg = flow->qentry->msg.raw.hdr.common.type; |
| 312 | if (exp_msg && rcv_msg != exp_msg) { |
Karsten Graul | 555da9a | 2020-04-30 15:55:38 +0200 | [diff] [blame] | 313 | if (exp_msg == SMC_LLC_ADD_LINK && |
Karsten Graul | 6778a6b | 2020-07-08 17:05:11 +0200 | [diff] [blame] | 314 | rcv_msg == SMC_LLC_DELETE_LINK) { |
Karsten Graul | 555da9a | 2020-04-30 15:55:38 +0200 | [diff] [blame] | 315 | /* flow_start will delay the unexpected msg */ |
| 316 | smc_llc_flow_start(&lgr->llc_flow_lcl, |
| 317 | smc_llc_flow_qentry_clr(flow)); |
| 318 | return NULL; |
| 319 | } |
Karsten Graul | 6778a6b | 2020-07-08 17:05:11 +0200 | [diff] [blame] | 320 | pr_warn_once("smc: SMC-R lg %*phN dropped unexpected LLC msg: " |
| 321 | "msg %d exp %d flow %d role %d flags %x\n", |
| 322 | SMC_LGR_ID_SIZE, &lgr->id, rcv_msg, exp_msg, |
| 323 | flow->type, lgr->role, |
| 324 | flow->qentry->msg.raw.hdr.flags); |
Karsten Graul | 555da9a | 2020-04-30 15:55:38 +0200 | [diff] [blame] | 325 | smc_llc_flow_qentry_del(flow); |
| 326 | } |
| 327 | out: |
| 328 | return flow->qentry; |
| 329 | } |
| 330 | |
Ursula Braun | 9bf9abe | 2017-01-09 16:55:21 +0100 | [diff] [blame] | 331 | /********************************** send *************************************/ |
| 332 | |
| 333 | struct smc_llc_tx_pend { |
| 334 | }; |
| 335 | |
| 336 | /* handler for send/transmission completion of an LLC msg */ |
| 337 | static void smc_llc_tx_handler(struct smc_wr_tx_pend_priv *pend, |
| 338 | struct smc_link *link, |
| 339 | enum ib_wc_status wc_status) |
| 340 | { |
| 341 | /* future work: handle wc_status error for recovery and failover */ |
| 342 | } |
| 343 | |
| 344 | /** |
| 345 | * smc_llc_add_pending_send() - add LLC control message to pending WQE transmits |
| 346 | * @link: Pointer to SMC link used for sending LLC control message. |
| 347 | * @wr_buf: Out variable returning pointer to work request payload buffer. |
| 348 | * @pend: Out variable returning pointer to private pending WR tracking. |
| 349 | * It's the context the transmit complete handler will get. |
| 350 | * |
| 351 | * Reserves and pre-fills an entry for a pending work request send/tx. |
| 352 | * Used by mid-level smc_llc_send_msg() to prepare for later actual send/tx. |
| 353 | * Can sleep due to smc_get_ctrl_buf (if not in softirq context). |
| 354 | * |
| 355 | * Return: 0 on success, otherwise an error value. |
| 356 | */ |
| 357 | static int smc_llc_add_pending_send(struct smc_link *link, |
| 358 | struct smc_wr_buf **wr_buf, |
| 359 | struct smc_wr_tx_pend_priv **pend) |
| 360 | { |
| 361 | int rc; |
| 362 | |
Ursula Braun | ad6f317 | 2019-02-04 13:44:44 +0100 | [diff] [blame] | 363 | rc = smc_wr_tx_get_free_slot(link, smc_llc_tx_handler, wr_buf, NULL, |
| 364 | pend); |
Ursula Braun | 9bf9abe | 2017-01-09 16:55:21 +0100 | [diff] [blame] | 365 | if (rc < 0) |
| 366 | return rc; |
| 367 | BUILD_BUG_ON_MSG( |
| 368 | sizeof(union smc_llc_msg) > SMC_WR_BUF_SIZE, |
| 369 | "must increase SMC_WR_BUF_SIZE to at least sizeof(struct smc_llc_msg)"); |
| 370 | BUILD_BUG_ON_MSG( |
| 371 | sizeof(union smc_llc_msg) != SMC_WR_TX_SIZE, |
| 372 | "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()"); |
| 373 | BUILD_BUG_ON_MSG( |
| 374 | sizeof(struct smc_llc_tx_pend) > SMC_WR_TX_PEND_PRIV_SIZE, |
| 375 | "must increase SMC_WR_TX_PEND_PRIV_SIZE to at least sizeof(struct smc_llc_tx_pend)"); |
| 376 | return 0; |
| 377 | } |
| 378 | |
| 379 | /* high-level API to send LLC confirm link */ |
Ursula Braun | 947541f | 2018-07-25 16:35:30 +0200 | [diff] [blame] | 380 | int smc_llc_send_confirm_link(struct smc_link *link, |
Ursula Braun | 9bf9abe | 2017-01-09 16:55:21 +0100 | [diff] [blame] | 381 | enum smc_llc_reqresp reqresp) |
| 382 | { |
Ursula Braun | 9bf9abe | 2017-01-09 16:55:21 +0100 | [diff] [blame] | 383 | struct smc_llc_msg_confirm_link *confllc; |
| 384 | struct smc_wr_tx_pend_priv *pend; |
| 385 | struct smc_wr_buf *wr_buf; |
| 386 | int rc; |
| 387 | |
| 388 | rc = smc_llc_add_pending_send(link, &wr_buf, &pend); |
| 389 | if (rc) |
| 390 | return rc; |
| 391 | confllc = (struct smc_llc_msg_confirm_link *)wr_buf; |
| 392 | memset(confllc, 0, sizeof(*confllc)); |
| 393 | confllc->hd.common.type = SMC_LLC_CONFIRM_LINK; |
| 394 | confllc->hd.length = sizeof(struct smc_llc_msg_confirm_link); |
Karsten Graul | 75d320d | 2018-03-01 13:51:31 +0100 | [diff] [blame] | 395 | confllc->hd.flags |= SMC_LLC_FLAG_NO_RMBE_EYEC; |
Ursula Braun | 9bf9abe | 2017-01-09 16:55:21 +0100 | [diff] [blame] | 396 | if (reqresp == SMC_LLC_RESP) |
| 397 | confllc->hd.flags |= SMC_LLC_FLAG_RESP; |
Ursula Braun | 947541f | 2018-07-25 16:35:30 +0200 | [diff] [blame] | 398 | memcpy(confllc->sender_mac, link->smcibdev->mac[link->ibport - 1], |
| 399 | ETH_ALEN); |
Ursula Braun | 7005ada | 2018-07-25 16:35:31 +0200 | [diff] [blame] | 400 | memcpy(confllc->sender_gid, link->gid, SMC_GID_SIZE); |
Ursula Braun | 9bf9abe | 2017-01-09 16:55:21 +0100 | [diff] [blame] | 401 | hton24(confllc->sender_qp_num, link->roce_qp->qp_num); |
Karsten Graul | 2be922f | 2018-02-28 12:44:08 +0100 | [diff] [blame] | 402 | confllc->link_num = link->link_id; |
Karsten Graul | 45fa8da | 2020-05-04 14:18:47 +0200 | [diff] [blame] | 403 | memcpy(confllc->link_uid, link->link_uid, SMC_LGR_ID_SIZE); |
Karsten Graul | b1570a8 | 2020-05-03 14:38:42 +0200 | [diff] [blame] | 404 | confllc->max_links = SMC_LLC_ADD_LNK_MAX_LINKS; |
Karsten Graul | 52bedf3 | 2018-03-01 13:51:32 +0100 | [diff] [blame] | 405 | /* send llc message */ |
| 406 | rc = smc_wr_tx_send(link, pend); |
| 407 | return rc; |
| 408 | } |
| 409 | |
Karsten Graul | 44aa81c | 2018-05-15 17:04:55 +0200 | [diff] [blame] | 410 | /* send LLC confirm rkey request */ |
Karsten Graul | 3d88a21 | 2020-04-30 15:55:44 +0200 | [diff] [blame] | 411 | static int smc_llc_send_confirm_rkey(struct smc_link *send_link, |
Karsten Graul | 44aa81c | 2018-05-15 17:04:55 +0200 | [diff] [blame] | 412 | struct smc_buf_desc *rmb_desc) |
| 413 | { |
| 414 | struct smc_llc_msg_confirm_rkey *rkeyllc; |
| 415 | struct smc_wr_tx_pend_priv *pend; |
| 416 | struct smc_wr_buf *wr_buf; |
Karsten Graul | 3d88a21 | 2020-04-30 15:55:44 +0200 | [diff] [blame] | 417 | struct smc_link *link; |
| 418 | int i, rc, rtok_ix; |
Karsten Graul | 44aa81c | 2018-05-15 17:04:55 +0200 | [diff] [blame] | 419 | |
Karsten Graul | 3d88a21 | 2020-04-30 15:55:44 +0200 | [diff] [blame] | 420 | rc = smc_llc_add_pending_send(send_link, &wr_buf, &pend); |
Karsten Graul | 44aa81c | 2018-05-15 17:04:55 +0200 | [diff] [blame] | 421 | if (rc) |
| 422 | return rc; |
| 423 | rkeyllc = (struct smc_llc_msg_confirm_rkey *)wr_buf; |
| 424 | memset(rkeyllc, 0, sizeof(*rkeyllc)); |
| 425 | rkeyllc->hd.common.type = SMC_LLC_CONFIRM_RKEY; |
| 426 | rkeyllc->hd.length = sizeof(struct smc_llc_msg_confirm_rkey); |
Karsten Graul | 3d88a21 | 2020-04-30 15:55:44 +0200 | [diff] [blame] | 427 | |
| 428 | rtok_ix = 1; |
| 429 | for (i = 0; i < SMC_LINKS_PER_LGR_MAX; i++) { |
| 430 | link = &send_link->lgr->lnk[i]; |
Karsten Graul | 741a49a | 2020-07-18 15:06:16 +0200 | [diff] [blame^] | 431 | if (smc_link_active(link) && link != send_link) { |
Karsten Graul | 3d88a21 | 2020-04-30 15:55:44 +0200 | [diff] [blame] | 432 | rkeyllc->rtoken[rtok_ix].link_id = link->link_id; |
| 433 | rkeyllc->rtoken[rtok_ix].rmb_key = |
| 434 | htonl(rmb_desc->mr_rx[link->link_idx]->rkey); |
| 435 | rkeyllc->rtoken[rtok_ix].rmb_vaddr = cpu_to_be64( |
| 436 | (u64)sg_dma_address( |
| 437 | rmb_desc->sgt[link->link_idx].sgl)); |
| 438 | rtok_ix++; |
| 439 | } |
| 440 | } |
| 441 | /* rkey of send_link is in rtoken[0] */ |
| 442 | rkeyllc->rtoken[0].num_rkeys = rtok_ix - 1; |
Karsten Graul | 44aa81c | 2018-05-15 17:04:55 +0200 | [diff] [blame] | 443 | rkeyllc->rtoken[0].rmb_key = |
Karsten Graul | 3d88a21 | 2020-04-30 15:55:44 +0200 | [diff] [blame] | 444 | htonl(rmb_desc->mr_rx[send_link->link_idx]->rkey); |
Karsten Graul | 44aa81c | 2018-05-15 17:04:55 +0200 | [diff] [blame] | 445 | rkeyllc->rtoken[0].rmb_vaddr = cpu_to_be64( |
Karsten Graul | 3d88a21 | 2020-04-30 15:55:44 +0200 | [diff] [blame] | 446 | (u64)sg_dma_address(rmb_desc->sgt[send_link->link_idx].sgl)); |
Karsten Graul | 44aa81c | 2018-05-15 17:04:55 +0200 | [diff] [blame] | 447 | /* send llc message */ |
Karsten Graul | 3d88a21 | 2020-04-30 15:55:44 +0200 | [diff] [blame] | 448 | rc = smc_wr_tx_send(send_link, pend); |
Karsten Graul | 44aa81c | 2018-05-15 17:04:55 +0200 | [diff] [blame] | 449 | return rc; |
| 450 | } |
| 451 | |
Karsten Graul | 60e03c6 | 2018-11-22 10:26:42 +0100 | [diff] [blame] | 452 | /* send LLC delete rkey request */ |
| 453 | static int smc_llc_send_delete_rkey(struct smc_link *link, |
| 454 | struct smc_buf_desc *rmb_desc) |
| 455 | { |
| 456 | struct smc_llc_msg_delete_rkey *rkeyllc; |
| 457 | struct smc_wr_tx_pend_priv *pend; |
| 458 | struct smc_wr_buf *wr_buf; |
| 459 | int rc; |
| 460 | |
| 461 | rc = smc_llc_add_pending_send(link, &wr_buf, &pend); |
| 462 | if (rc) |
| 463 | return rc; |
| 464 | rkeyllc = (struct smc_llc_msg_delete_rkey *)wr_buf; |
| 465 | memset(rkeyllc, 0, sizeof(*rkeyllc)); |
| 466 | rkeyllc->hd.common.type = SMC_LLC_DELETE_RKEY; |
| 467 | rkeyllc->hd.length = sizeof(struct smc_llc_msg_delete_rkey); |
| 468 | rkeyllc->num_rkeys = 1; |
Karsten Graul | 387707f | 2020-04-29 17:10:40 +0200 | [diff] [blame] | 469 | rkeyllc->rkey[0] = htonl(rmb_desc->mr_rx[link->link_idx]->rkey); |
Karsten Graul | 60e03c6 | 2018-11-22 10:26:42 +0100 | [diff] [blame] | 470 | /* send llc message */ |
| 471 | rc = smc_wr_tx_send(link, pend); |
| 472 | return rc; |
| 473 | } |
| 474 | |
Karsten Graul | 52bedf3 | 2018-03-01 13:51:32 +0100 | [diff] [blame] | 475 | /* send ADD LINK request or response */ |
Ursula Braun | 7005ada | 2018-07-25 16:35:31 +0200 | [diff] [blame] | 476 | 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] | 477 | struct smc_link *link_new, |
Karsten Graul | 52bedf3 | 2018-03-01 13:51:32 +0100 | [diff] [blame] | 478 | enum smc_llc_reqresp reqresp) |
| 479 | { |
| 480 | struct smc_llc_msg_add_link *addllc; |
| 481 | struct smc_wr_tx_pend_priv *pend; |
| 482 | struct smc_wr_buf *wr_buf; |
| 483 | int rc; |
| 484 | |
| 485 | rc = smc_llc_add_pending_send(link, &wr_buf, &pend); |
| 486 | if (rc) |
| 487 | return rc; |
| 488 | addllc = (struct smc_llc_msg_add_link *)wr_buf; |
Karsten Graul | fbed3b3 | 2020-05-01 12:48:04 +0200 | [diff] [blame] | 489 | |
| 490 | memset(addllc, 0, sizeof(*addllc)); |
| 491 | addllc->hd.common.type = SMC_LLC_ADD_LINK; |
| 492 | addllc->hd.length = sizeof(struct smc_llc_msg_add_link); |
| 493 | if (reqresp == SMC_LLC_RESP) |
| 494 | addllc->hd.flags |= SMC_LLC_FLAG_RESP; |
| 495 | memcpy(addllc->sender_mac, mac, ETH_ALEN); |
| 496 | memcpy(addllc->sender_gid, gid, SMC_GID_SIZE); |
| 497 | if (link_new) { |
| 498 | addllc->link_num = link_new->link_id; |
| 499 | hton24(addllc->sender_qp_num, link_new->roce_qp->qp_num); |
| 500 | hton24(addllc->initial_psn, link_new->psn_initial); |
| 501 | if (reqresp == SMC_LLC_REQ) |
| 502 | addllc->qp_mtu = link_new->path_mtu; |
| 503 | else |
| 504 | addllc->qp_mtu = min(link_new->path_mtu, |
| 505 | link_new->peer_mtu); |
| 506 | } |
Karsten Graul | 52bedf3 | 2018-03-01 13:51:32 +0100 | [diff] [blame] | 507 | /* send llc message */ |
| 508 | rc = smc_wr_tx_send(link, pend); |
| 509 | return rc; |
| 510 | } |
| 511 | |
| 512 | /* send DELETE LINK request or response */ |
Karsten Graul | fbed3b3 | 2020-05-01 12:48:04 +0200 | [diff] [blame] | 513 | int smc_llc_send_delete_link(struct smc_link *link, u8 link_del_id, |
| 514 | enum smc_llc_reqresp reqresp, bool orderly, |
| 515 | u32 reason) |
Karsten Graul | 52bedf3 | 2018-03-01 13:51:32 +0100 | [diff] [blame] | 516 | { |
| 517 | struct smc_llc_msg_del_link *delllc; |
| 518 | struct smc_wr_tx_pend_priv *pend; |
| 519 | struct smc_wr_buf *wr_buf; |
| 520 | int rc; |
| 521 | |
| 522 | rc = smc_llc_add_pending_send(link, &wr_buf, &pend); |
| 523 | if (rc) |
| 524 | return rc; |
| 525 | delllc = (struct smc_llc_msg_del_link *)wr_buf; |
Karsten Graul | fbed3b3 | 2020-05-01 12:48:04 +0200 | [diff] [blame] | 526 | |
| 527 | memset(delllc, 0, sizeof(*delllc)); |
| 528 | delllc->hd.common.type = SMC_LLC_DELETE_LINK; |
| 529 | delllc->hd.length = sizeof(struct smc_llc_msg_del_link); |
| 530 | if (reqresp == SMC_LLC_RESP) |
| 531 | delllc->hd.flags |= SMC_LLC_FLAG_RESP; |
| 532 | if (orderly) |
| 533 | delllc->hd.flags |= SMC_LLC_FLAG_DEL_LINK_ORDERLY; |
| 534 | if (link_del_id) |
| 535 | delllc->link_num = link_del_id; |
| 536 | else |
| 537 | delllc->hd.flags |= SMC_LLC_FLAG_DEL_LINK_ALL; |
| 538 | delllc->reason = htonl(reason); |
Ursula Braun | 9bf9abe | 2017-01-09 16:55:21 +0100 | [diff] [blame] | 539 | /* send llc message */ |
| 540 | rc = smc_wr_tx_send(link, pend); |
| 541 | return rc; |
| 542 | } |
| 543 | |
Karsten Graul | d97935f | 2018-05-15 17:04:57 +0200 | [diff] [blame] | 544 | /* send LLC test link request */ |
| 545 | 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] | 546 | { |
| 547 | struct smc_llc_msg_test_link *testllc; |
| 548 | struct smc_wr_tx_pend_priv *pend; |
| 549 | struct smc_wr_buf *wr_buf; |
| 550 | int rc; |
| 551 | |
| 552 | rc = smc_llc_add_pending_send(link, &wr_buf, &pend); |
| 553 | if (rc) |
| 554 | return rc; |
| 555 | testllc = (struct smc_llc_msg_test_link *)wr_buf; |
| 556 | memset(testllc, 0, sizeof(*testllc)); |
| 557 | testllc->hd.common.type = SMC_LLC_TEST_LINK; |
| 558 | testllc->hd.length = sizeof(struct smc_llc_msg_test_link); |
Karsten Graul | 313164d | 2018-03-01 13:51:29 +0100 | [diff] [blame] | 559 | memcpy(testllc->user_data, user_data, sizeof(testllc->user_data)); |
| 560 | /* send llc message */ |
| 561 | rc = smc_wr_tx_send(link, pend); |
| 562 | return rc; |
| 563 | } |
| 564 | |
Karsten Graul | 6c8968c | 2020-04-29 17:10:46 +0200 | [diff] [blame] | 565 | /* schedule an llc send on link, may wait for buffers */ |
| 566 | static int smc_llc_send_message(struct smc_link *link, void *llcbuf) |
Karsten Graul | 4ed75de | 2018-03-01 13:51:30 +0100 | [diff] [blame] | 567 | { |
| 568 | struct smc_wr_tx_pend_priv *pend; |
| 569 | struct smc_wr_buf *wr_buf; |
| 570 | int rc; |
| 571 | |
Karsten Graul | 6c8968c | 2020-04-29 17:10:46 +0200 | [diff] [blame] | 572 | if (!smc_link_usable(link)) |
| 573 | return -ENOLINK; |
| 574 | rc = smc_llc_add_pending_send(link, &wr_buf, &pend); |
Karsten Graul | 4ed75de | 2018-03-01 13:51:30 +0100 | [diff] [blame] | 575 | if (rc) |
Karsten Graul | 6c8968c | 2020-04-29 17:10:46 +0200 | [diff] [blame] | 576 | return rc; |
| 577 | memcpy(wr_buf, llcbuf, sizeof(union smc_llc_msg)); |
| 578 | return smc_wr_tx_send(link, pend); |
Karsten Graul | 4ed75de | 2018-03-01 13:51:30 +0100 | [diff] [blame] | 579 | } |
| 580 | |
Karsten Graul | f3811fd | 2020-05-04 14:18:42 +0200 | [diff] [blame] | 581 | /* schedule an llc send on link, may wait for buffers, |
| 582 | * and wait for send completion notification. |
| 583 | * @return 0 on success |
| 584 | */ |
| 585 | static int smc_llc_send_message_wait(struct smc_link *link, void *llcbuf) |
| 586 | { |
| 587 | struct smc_wr_tx_pend_priv *pend; |
| 588 | struct smc_wr_buf *wr_buf; |
| 589 | int rc; |
| 590 | |
| 591 | if (!smc_link_usable(link)) |
| 592 | return -ENOLINK; |
| 593 | rc = smc_llc_add_pending_send(link, &wr_buf, &pend); |
| 594 | if (rc) |
| 595 | return rc; |
| 596 | memcpy(wr_buf, llcbuf, sizeof(union smc_llc_msg)); |
| 597 | return smc_wr_tx_send_wait(link, pend, SMC_LLC_WAIT_TIME); |
| 598 | } |
| 599 | |
Ursula Braun | 9bf9abe | 2017-01-09 16:55:21 +0100 | [diff] [blame] | 600 | /********************************* receive ***********************************/ |
| 601 | |
Karsten Graul | 336ba09 | 2020-05-03 14:38:40 +0200 | [diff] [blame] | 602 | static int smc_llc_alloc_alt_link(struct smc_link_group *lgr, |
| 603 | enum smc_lgr_type lgr_new_t) |
| 604 | { |
| 605 | int i; |
| 606 | |
| 607 | if (lgr->type == SMC_LGR_SYMMETRIC || |
| 608 | (lgr->type != SMC_LGR_SINGLE && |
| 609 | (lgr_new_t == SMC_LGR_ASYMMETRIC_LOCAL || |
| 610 | lgr_new_t == SMC_LGR_ASYMMETRIC_PEER))) |
| 611 | return -EMLINK; |
| 612 | |
| 613 | if (lgr_new_t == SMC_LGR_ASYMMETRIC_LOCAL || |
| 614 | lgr_new_t == SMC_LGR_ASYMMETRIC_PEER) { |
| 615 | for (i = SMC_LINKS_PER_LGR_MAX - 1; i >= 0; i--) |
| 616 | if (lgr->lnk[i].state == SMC_LNK_UNUSED) |
| 617 | return i; |
| 618 | } else { |
| 619 | for (i = 0; i < SMC_LINKS_PER_LGR_MAX; i++) |
| 620 | if (lgr->lnk[i].state == SMC_LNK_UNUSED) |
| 621 | return i; |
| 622 | } |
| 623 | return -EMLINK; |
| 624 | } |
| 625 | |
Karsten Graul | 87f88cd | 2020-05-03 14:38:41 +0200 | [diff] [blame] | 626 | /* return first buffer from any of the next buf lists */ |
| 627 | static struct smc_buf_desc *_smc_llc_get_next_rmb(struct smc_link_group *lgr, |
| 628 | int *buf_lst) |
| 629 | { |
| 630 | struct smc_buf_desc *buf_pos; |
| 631 | |
| 632 | while (*buf_lst < SMC_RMBE_SIZES) { |
| 633 | buf_pos = list_first_entry_or_null(&lgr->rmbs[*buf_lst], |
| 634 | struct smc_buf_desc, list); |
| 635 | if (buf_pos) |
| 636 | return buf_pos; |
| 637 | (*buf_lst)++; |
| 638 | } |
| 639 | return NULL; |
| 640 | } |
| 641 | |
| 642 | /* return next rmb from buffer lists */ |
| 643 | static struct smc_buf_desc *smc_llc_get_next_rmb(struct smc_link_group *lgr, |
| 644 | int *buf_lst, |
| 645 | struct smc_buf_desc *buf_pos) |
| 646 | { |
| 647 | struct smc_buf_desc *buf_next; |
| 648 | |
| 649 | if (!buf_pos || list_is_last(&buf_pos->list, &lgr->rmbs[*buf_lst])) { |
| 650 | (*buf_lst)++; |
| 651 | return _smc_llc_get_next_rmb(lgr, buf_lst); |
| 652 | } |
| 653 | buf_next = list_next_entry(buf_pos, list); |
| 654 | return buf_next; |
| 655 | } |
| 656 | |
| 657 | static struct smc_buf_desc *smc_llc_get_first_rmb(struct smc_link_group *lgr, |
| 658 | int *buf_lst) |
| 659 | { |
| 660 | *buf_lst = 0; |
| 661 | return smc_llc_get_next_rmb(lgr, buf_lst, NULL); |
| 662 | } |
| 663 | |
| 664 | /* send one add_link_continue msg */ |
| 665 | static int smc_llc_add_link_cont(struct smc_link *link, |
| 666 | struct smc_link *link_new, u8 *num_rkeys_todo, |
| 667 | int *buf_lst, struct smc_buf_desc **buf_pos) |
| 668 | { |
| 669 | struct smc_llc_msg_add_link_cont *addc_llc; |
| 670 | struct smc_link_group *lgr = link->lgr; |
| 671 | int prim_lnk_idx, lnk_idx, i, rc; |
| 672 | struct smc_wr_tx_pend_priv *pend; |
| 673 | struct smc_wr_buf *wr_buf; |
| 674 | struct smc_buf_desc *rmb; |
| 675 | u8 n; |
| 676 | |
| 677 | rc = smc_llc_add_pending_send(link, &wr_buf, &pend); |
| 678 | if (rc) |
| 679 | return rc; |
| 680 | addc_llc = (struct smc_llc_msg_add_link_cont *)wr_buf; |
| 681 | memset(addc_llc, 0, sizeof(*addc_llc)); |
| 682 | |
| 683 | prim_lnk_idx = link->link_idx; |
| 684 | lnk_idx = link_new->link_idx; |
| 685 | addc_llc->link_num = link_new->link_id; |
| 686 | addc_llc->num_rkeys = *num_rkeys_todo; |
| 687 | n = *num_rkeys_todo; |
| 688 | for (i = 0; i < min_t(u8, n, SMC_LLC_RKEYS_PER_CONT_MSG); i++) { |
| 689 | if (!*buf_pos) { |
| 690 | addc_llc->num_rkeys = addc_llc->num_rkeys - |
| 691 | *num_rkeys_todo; |
| 692 | *num_rkeys_todo = 0; |
| 693 | break; |
| 694 | } |
| 695 | rmb = *buf_pos; |
| 696 | |
| 697 | addc_llc->rt[i].rmb_key = htonl(rmb->mr_rx[prim_lnk_idx]->rkey); |
| 698 | addc_llc->rt[i].rmb_key_new = htonl(rmb->mr_rx[lnk_idx]->rkey); |
| 699 | addc_llc->rt[i].rmb_vaddr_new = |
| 700 | cpu_to_be64((u64)sg_dma_address(rmb->sgt[lnk_idx].sgl)); |
| 701 | |
| 702 | (*num_rkeys_todo)--; |
| 703 | *buf_pos = smc_llc_get_next_rmb(lgr, buf_lst, *buf_pos); |
| 704 | while (*buf_pos && !(*buf_pos)->used) |
| 705 | *buf_pos = smc_llc_get_next_rmb(lgr, buf_lst, *buf_pos); |
| 706 | } |
| 707 | addc_llc->hd.common.type = SMC_LLC_ADD_LINK_CONT; |
| 708 | addc_llc->hd.length = sizeof(struct smc_llc_msg_add_link_cont); |
| 709 | if (lgr->role == SMC_CLNT) |
| 710 | addc_llc->hd.flags |= SMC_LLC_FLAG_RESP; |
| 711 | return smc_wr_tx_send(link, pend); |
| 712 | } |
| 713 | |
| 714 | static int smc_llc_cli_rkey_exchange(struct smc_link *link, |
| 715 | struct smc_link *link_new) |
| 716 | { |
| 717 | struct smc_llc_msg_add_link_cont *addc_llc; |
| 718 | struct smc_link_group *lgr = link->lgr; |
| 719 | u8 max, num_rkeys_send, num_rkeys_recv; |
| 720 | struct smc_llc_qentry *qentry; |
| 721 | struct smc_buf_desc *buf_pos; |
| 722 | int buf_lst; |
| 723 | int rc = 0; |
| 724 | int i; |
| 725 | |
| 726 | mutex_lock(&lgr->rmbs_lock); |
| 727 | num_rkeys_send = lgr->conns_num; |
| 728 | buf_pos = smc_llc_get_first_rmb(lgr, &buf_lst); |
| 729 | do { |
| 730 | qentry = smc_llc_wait(lgr, NULL, SMC_LLC_WAIT_TIME, |
| 731 | SMC_LLC_ADD_LINK_CONT); |
| 732 | if (!qentry) { |
| 733 | rc = -ETIMEDOUT; |
| 734 | break; |
| 735 | } |
| 736 | addc_llc = &qentry->msg.add_link_cont; |
| 737 | num_rkeys_recv = addc_llc->num_rkeys; |
| 738 | max = min_t(u8, num_rkeys_recv, SMC_LLC_RKEYS_PER_CONT_MSG); |
| 739 | for (i = 0; i < max; i++) { |
| 740 | smc_rtoken_set(lgr, link->link_idx, link_new->link_idx, |
| 741 | addc_llc->rt[i].rmb_key, |
| 742 | addc_llc->rt[i].rmb_vaddr_new, |
| 743 | addc_llc->rt[i].rmb_key_new); |
| 744 | num_rkeys_recv--; |
| 745 | } |
| 746 | smc_llc_flow_qentry_del(&lgr->llc_flow_lcl); |
| 747 | rc = smc_llc_add_link_cont(link, link_new, &num_rkeys_send, |
| 748 | &buf_lst, &buf_pos); |
| 749 | if (rc) |
| 750 | break; |
| 751 | } while (num_rkeys_send || num_rkeys_recv); |
| 752 | |
| 753 | mutex_unlock(&lgr->rmbs_lock); |
| 754 | return rc; |
| 755 | } |
| 756 | |
Karsten Graul | 336ba09 | 2020-05-03 14:38:40 +0200 | [diff] [blame] | 757 | /* prepare and send an add link reject response */ |
| 758 | static int smc_llc_cli_add_link_reject(struct smc_llc_qentry *qentry) |
| 759 | { |
| 760 | qentry->msg.raw.hdr.flags |= SMC_LLC_FLAG_RESP; |
| 761 | qentry->msg.raw.hdr.flags |= SMC_LLC_FLAG_ADD_LNK_REJ; |
| 762 | qentry->msg.raw.hdr.add_link_rej_rsn = SMC_LLC_REJ_RSN_NO_ALT_PATH; |
| 763 | return smc_llc_send_message(qentry->link, &qentry->msg); |
| 764 | } |
| 765 | |
Karsten Graul | b1570a8 | 2020-05-03 14:38:42 +0200 | [diff] [blame] | 766 | static int smc_llc_cli_conf_link(struct smc_link *link, |
| 767 | struct smc_init_info *ini, |
| 768 | struct smc_link *link_new, |
| 769 | enum smc_lgr_type lgr_new_t) |
| 770 | { |
| 771 | struct smc_link_group *lgr = link->lgr; |
Karsten Graul | b1570a8 | 2020-05-03 14:38:42 +0200 | [diff] [blame] | 772 | struct smc_llc_qentry *qentry = NULL; |
| 773 | int rc = 0; |
| 774 | |
| 775 | /* receive CONFIRM LINK request over RoCE fabric */ |
| 776 | qentry = smc_llc_wait(lgr, NULL, SMC_LLC_WAIT_FIRST_TIME, 0); |
| 777 | if (!qentry) { |
| 778 | rc = smc_llc_send_delete_link(link, link_new->link_id, |
| 779 | SMC_LLC_REQ, false, |
| 780 | SMC_LLC_DEL_LOST_PATH); |
| 781 | return -ENOLINK; |
| 782 | } |
| 783 | if (qentry->msg.raw.hdr.common.type != SMC_LLC_CONFIRM_LINK) { |
| 784 | /* received DELETE_LINK instead */ |
Karsten Graul | b1570a8 | 2020-05-03 14:38:42 +0200 | [diff] [blame] | 785 | qentry->msg.raw.hdr.flags |= SMC_LLC_FLAG_RESP; |
| 786 | smc_llc_send_message(link, &qentry->msg); |
| 787 | smc_llc_flow_qentry_del(&lgr->llc_flow_lcl); |
| 788 | return -ENOLINK; |
| 789 | } |
Karsten Graul | 649758f | 2020-05-04 14:18:48 +0200 | [diff] [blame] | 790 | smc_llc_save_peer_uid(qentry); |
Karsten Graul | b1570a8 | 2020-05-03 14:38:42 +0200 | [diff] [blame] | 791 | smc_llc_flow_qentry_del(&lgr->llc_flow_lcl); |
| 792 | |
| 793 | rc = smc_ib_modify_qp_rts(link_new); |
| 794 | if (rc) { |
| 795 | smc_llc_send_delete_link(link, link_new->link_id, SMC_LLC_REQ, |
| 796 | false, SMC_LLC_DEL_LOST_PATH); |
| 797 | return -ENOLINK; |
| 798 | } |
| 799 | smc_wr_remember_qp_attr(link_new); |
| 800 | |
| 801 | rc = smcr_buf_reg_lgr(link_new); |
| 802 | if (rc) { |
| 803 | smc_llc_send_delete_link(link, link_new->link_id, SMC_LLC_REQ, |
| 804 | false, SMC_LLC_DEL_LOST_PATH); |
| 805 | return -ENOLINK; |
| 806 | } |
| 807 | |
| 808 | /* send CONFIRM LINK response over RoCE fabric */ |
| 809 | rc = smc_llc_send_confirm_link(link_new, SMC_LLC_RESP); |
| 810 | if (rc) { |
| 811 | smc_llc_send_delete_link(link, link_new->link_id, SMC_LLC_REQ, |
| 812 | false, SMC_LLC_DEL_LOST_PATH); |
| 813 | return -ENOLINK; |
| 814 | } |
| 815 | smc_llc_link_active(link_new); |
Karsten Graul | ad6c111 | 2020-05-04 14:18:44 +0200 | [diff] [blame] | 816 | if (lgr_new_t == SMC_LGR_ASYMMETRIC_LOCAL || |
| 817 | lgr_new_t == SMC_LGR_ASYMMETRIC_PEER) |
| 818 | smcr_lgr_set_type_asym(lgr, lgr_new_t, link_new->link_idx); |
| 819 | else |
| 820 | smcr_lgr_set_type(lgr, lgr_new_t); |
Karsten Graul | b1570a8 | 2020-05-03 14:38:42 +0200 | [diff] [blame] | 821 | return 0; |
| 822 | } |
| 823 | |
Karsten Graul | 336ba09 | 2020-05-03 14:38:40 +0200 | [diff] [blame] | 824 | static void smc_llc_save_add_link_info(struct smc_link *link, |
| 825 | struct smc_llc_msg_add_link *add_llc) |
| 826 | { |
| 827 | link->peer_qpn = ntoh24(add_llc->sender_qp_num); |
| 828 | memcpy(link->peer_gid, add_llc->sender_gid, SMC_GID_SIZE); |
| 829 | memcpy(link->peer_mac, add_llc->sender_mac, ETH_ALEN); |
| 830 | link->peer_psn = ntoh24(add_llc->initial_psn); |
| 831 | link->peer_mtu = add_llc->qp_mtu; |
| 832 | } |
| 833 | |
| 834 | /* as an SMC client, process an add link request */ |
| 835 | int smc_llc_cli_add_link(struct smc_link *link, struct smc_llc_qentry *qentry) |
| 836 | { |
| 837 | struct smc_llc_msg_add_link *llc = &qentry->msg.add_link; |
| 838 | enum smc_lgr_type lgr_new_t = SMC_LGR_SYMMETRIC; |
| 839 | struct smc_link_group *lgr = smc_get_lgr(link); |
| 840 | struct smc_link *lnk_new = NULL; |
| 841 | struct smc_init_info ini; |
| 842 | int lnk_idx, rc = 0; |
| 843 | |
| 844 | ini.vlan_id = lgr->vlan_id; |
| 845 | smc_pnet_find_alt_roce(lgr, &ini, link->smcibdev); |
| 846 | if (!memcmp(llc->sender_gid, link->peer_gid, SMC_GID_SIZE) && |
| 847 | !memcmp(llc->sender_mac, link->peer_mac, ETH_ALEN)) { |
| 848 | if (!ini.ib_dev) |
| 849 | goto out_reject; |
| 850 | lgr_new_t = SMC_LGR_ASYMMETRIC_PEER; |
| 851 | } |
| 852 | if (!ini.ib_dev) { |
| 853 | lgr_new_t = SMC_LGR_ASYMMETRIC_LOCAL; |
| 854 | ini.ib_dev = link->smcibdev; |
| 855 | ini.ib_port = link->ibport; |
| 856 | } |
| 857 | lnk_idx = smc_llc_alloc_alt_link(lgr, lgr_new_t); |
| 858 | if (lnk_idx < 0) |
| 859 | goto out_reject; |
| 860 | lnk_new = &lgr->lnk[lnk_idx]; |
| 861 | rc = smcr_link_init(lgr, lnk_new, lnk_idx, &ini); |
| 862 | if (rc) |
| 863 | goto out_reject; |
| 864 | smc_llc_save_add_link_info(lnk_new, llc); |
Karsten Graul | 45fa8da | 2020-05-04 14:18:47 +0200 | [diff] [blame] | 865 | lnk_new->link_id = llc->link_num; /* SMC server assigns link id */ |
| 866 | smc_llc_link_set_uid(lnk_new); |
Karsten Graul | 336ba09 | 2020-05-03 14:38:40 +0200 | [diff] [blame] | 867 | |
| 868 | rc = smc_ib_ready_link(lnk_new); |
| 869 | if (rc) |
| 870 | goto out_clear_lnk; |
| 871 | |
| 872 | rc = smcr_buf_map_lgr(lnk_new); |
| 873 | if (rc) |
| 874 | goto out_clear_lnk; |
| 875 | |
| 876 | rc = smc_llc_send_add_link(link, |
| 877 | lnk_new->smcibdev->mac[ini.ib_port - 1], |
| 878 | lnk_new->gid, lnk_new, SMC_LLC_RESP); |
| 879 | if (rc) |
| 880 | goto out_clear_lnk; |
Karsten Graul | 87f88cd | 2020-05-03 14:38:41 +0200 | [diff] [blame] | 881 | rc = smc_llc_cli_rkey_exchange(link, lnk_new); |
Karsten Graul | 336ba09 | 2020-05-03 14:38:40 +0200 | [diff] [blame] | 882 | if (rc) { |
| 883 | rc = 0; |
| 884 | goto out_clear_lnk; |
| 885 | } |
Karsten Graul | b1570a8 | 2020-05-03 14:38:42 +0200 | [diff] [blame] | 886 | 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] | 887 | if (!rc) |
| 888 | goto out; |
| 889 | out_clear_lnk: |
Karsten Graul | 0a99be4 | 2020-05-05 15:01:20 +0200 | [diff] [blame] | 890 | smcr_link_clear(lnk_new, false); |
Karsten Graul | 336ba09 | 2020-05-03 14:38:40 +0200 | [diff] [blame] | 891 | out_reject: |
| 892 | smc_llc_cli_add_link_reject(qentry); |
| 893 | out: |
| 894 | kfree(qentry); |
| 895 | return rc; |
| 896 | } |
| 897 | |
Karsten Graul | c48254f | 2020-07-18 15:06:14 +0200 | [diff] [blame] | 898 | /* as an SMC client, invite server to start the add_link processing */ |
| 899 | static void smc_llc_cli_add_link_invite(struct smc_link *link, |
| 900 | struct smc_llc_qentry *qentry) |
| 901 | { |
| 902 | struct smc_link_group *lgr = smc_get_lgr(link); |
| 903 | struct smc_init_info ini; |
| 904 | |
| 905 | if (lgr->type == SMC_LGR_SYMMETRIC || |
| 906 | lgr->type == SMC_LGR_ASYMMETRIC_PEER) |
| 907 | goto out; |
| 908 | |
| 909 | ini.vlan_id = lgr->vlan_id; |
| 910 | smc_pnet_find_alt_roce(lgr, &ini, link->smcibdev); |
| 911 | if (!ini.ib_dev) |
| 912 | goto out; |
| 913 | |
| 914 | smc_llc_send_add_link(link, ini.ib_dev->mac[ini.ib_port - 1], |
| 915 | ini.ib_gid, NULL, SMC_LLC_REQ); |
| 916 | out: |
| 917 | kfree(qentry); |
| 918 | } |
| 919 | |
| 920 | static bool smc_llc_is_local_add_link(union smc_llc_msg *llc) |
| 921 | { |
| 922 | if (llc->raw.hdr.common.type == SMC_LLC_ADD_LINK && |
| 923 | !llc->add_link.qp_mtu && !llc->add_link.link_num) |
| 924 | return true; |
| 925 | return false; |
| 926 | } |
| 927 | |
Karsten Graul | b1570a8 | 2020-05-03 14:38:42 +0200 | [diff] [blame] | 928 | static void smc_llc_process_cli_add_link(struct smc_link_group *lgr) |
| 929 | { |
| 930 | struct smc_llc_qentry *qentry; |
| 931 | |
| 932 | qentry = smc_llc_flow_qentry_clr(&lgr->llc_flow_lcl); |
| 933 | |
| 934 | mutex_lock(&lgr->llc_conf_mutex); |
Karsten Graul | c48254f | 2020-07-18 15:06:14 +0200 | [diff] [blame] | 935 | if (smc_llc_is_local_add_link(&qentry->msg)) |
| 936 | smc_llc_cli_add_link_invite(qentry->link, qentry); |
| 937 | else |
| 938 | smc_llc_cli_add_link(qentry->link, qentry); |
Karsten Graul | b1570a8 | 2020-05-03 14:38:42 +0200 | [diff] [blame] | 939 | mutex_unlock(&lgr->llc_conf_mutex); |
| 940 | } |
| 941 | |
Karsten Graul | 9c41687 | 2020-05-03 14:38:48 +0200 | [diff] [blame] | 942 | static int smc_llc_active_link_count(struct smc_link_group *lgr) |
| 943 | { |
| 944 | int i, link_count = 0; |
| 945 | |
| 946 | for (i = 0; i < SMC_LINKS_PER_LGR_MAX; i++) { |
Karsten Graul | 741a49a | 2020-07-18 15:06:16 +0200 | [diff] [blame^] | 947 | if (!smc_link_active(&lgr->lnk[i])) |
Karsten Graul | 9c41687 | 2020-05-03 14:38:48 +0200 | [diff] [blame] | 948 | continue; |
| 949 | link_count++; |
| 950 | } |
| 951 | return link_count; |
| 952 | } |
| 953 | |
Karsten Graul | c9a5d24 | 2020-05-03 14:38:46 +0200 | [diff] [blame] | 954 | /* find the asymmetric link when 3 links are established */ |
| 955 | static struct smc_link *smc_llc_find_asym_link(struct smc_link_group *lgr) |
| 956 | { |
| 957 | int asym_idx = -ENOENT; |
| 958 | int i, j, k; |
| 959 | bool found; |
| 960 | |
| 961 | /* determine asymmetric link */ |
| 962 | found = false; |
| 963 | for (i = 0; i < SMC_LINKS_PER_LGR_MAX; i++) { |
| 964 | for (j = i + 1; j < SMC_LINKS_PER_LGR_MAX; j++) { |
| 965 | if (!smc_link_usable(&lgr->lnk[i]) || |
| 966 | !smc_link_usable(&lgr->lnk[j])) |
| 967 | continue; |
| 968 | if (!memcmp(lgr->lnk[i].gid, lgr->lnk[j].gid, |
| 969 | SMC_GID_SIZE)) { |
| 970 | found = true; /* asym_lnk is i or j */ |
| 971 | break; |
| 972 | } |
| 973 | } |
| 974 | if (found) |
| 975 | break; |
| 976 | } |
| 977 | if (!found) |
| 978 | goto out; /* no asymmetric link */ |
| 979 | for (k = 0; k < SMC_LINKS_PER_LGR_MAX; k++) { |
| 980 | if (!smc_link_usable(&lgr->lnk[k])) |
| 981 | continue; |
| 982 | if (k != i && |
| 983 | !memcmp(lgr->lnk[i].peer_gid, lgr->lnk[k].peer_gid, |
| 984 | SMC_GID_SIZE)) { |
| 985 | asym_idx = i; |
| 986 | break; |
| 987 | } |
| 988 | if (k != j && |
| 989 | !memcmp(lgr->lnk[j].peer_gid, lgr->lnk[k].peer_gid, |
| 990 | SMC_GID_SIZE)) { |
| 991 | asym_idx = j; |
| 992 | break; |
| 993 | } |
| 994 | } |
| 995 | out: |
| 996 | return (asym_idx < 0) ? NULL : &lgr->lnk[asym_idx]; |
| 997 | } |
| 998 | |
| 999 | static void smc_llc_delete_asym_link(struct smc_link_group *lgr) |
| 1000 | { |
| 1001 | struct smc_link *lnk_new = NULL, *lnk_asym; |
| 1002 | struct smc_llc_qentry *qentry; |
| 1003 | int rc; |
| 1004 | |
| 1005 | lnk_asym = smc_llc_find_asym_link(lgr); |
| 1006 | if (!lnk_asym) |
| 1007 | return; /* no asymmetric link */ |
| 1008 | if (!smc_link_downing(&lnk_asym->state)) |
| 1009 | return; |
Karsten Graul | c6f02eb | 2020-05-04 14:18:38 +0200 | [diff] [blame] | 1010 | lnk_new = smc_switch_conns(lgr, lnk_asym, false); |
Karsten Graul | c9a5d24 | 2020-05-03 14:38:46 +0200 | [diff] [blame] | 1011 | smc_wr_tx_wait_no_pending_sends(lnk_asym); |
| 1012 | if (!lnk_new) |
| 1013 | goto out_free; |
| 1014 | /* change flow type from ADD_LINK into DEL_LINK */ |
| 1015 | lgr->llc_flow_lcl.type = SMC_LLC_FLOW_DEL_LINK; |
| 1016 | rc = smc_llc_send_delete_link(lnk_new, lnk_asym->link_id, SMC_LLC_REQ, |
| 1017 | true, SMC_LLC_DEL_NO_ASYM_NEEDED); |
| 1018 | if (rc) { |
| 1019 | smcr_link_down_cond(lnk_new); |
| 1020 | goto out_free; |
| 1021 | } |
| 1022 | qentry = smc_llc_wait(lgr, lnk_new, SMC_LLC_WAIT_TIME, |
| 1023 | SMC_LLC_DELETE_LINK); |
| 1024 | if (!qentry) { |
| 1025 | smcr_link_down_cond(lnk_new); |
| 1026 | goto out_free; |
| 1027 | } |
| 1028 | smc_llc_flow_qentry_del(&lgr->llc_flow_lcl); |
| 1029 | out_free: |
Karsten Graul | 0a99be4 | 2020-05-05 15:01:20 +0200 | [diff] [blame] | 1030 | smcr_link_clear(lnk_asym, true); |
Karsten Graul | c9a5d24 | 2020-05-03 14:38:46 +0200 | [diff] [blame] | 1031 | } |
| 1032 | |
Karsten Graul | 57b4992 | 2020-05-03 14:38:44 +0200 | [diff] [blame] | 1033 | static int smc_llc_srv_rkey_exchange(struct smc_link *link, |
| 1034 | struct smc_link *link_new) |
| 1035 | { |
| 1036 | struct smc_llc_msg_add_link_cont *addc_llc; |
| 1037 | struct smc_link_group *lgr = link->lgr; |
| 1038 | u8 max, num_rkeys_send, num_rkeys_recv; |
| 1039 | struct smc_llc_qentry *qentry = NULL; |
| 1040 | struct smc_buf_desc *buf_pos; |
| 1041 | int buf_lst; |
| 1042 | int rc = 0; |
| 1043 | int i; |
| 1044 | |
| 1045 | mutex_lock(&lgr->rmbs_lock); |
| 1046 | num_rkeys_send = lgr->conns_num; |
| 1047 | buf_pos = smc_llc_get_first_rmb(lgr, &buf_lst); |
| 1048 | do { |
| 1049 | smc_llc_add_link_cont(link, link_new, &num_rkeys_send, |
| 1050 | &buf_lst, &buf_pos); |
| 1051 | qentry = smc_llc_wait(lgr, link, SMC_LLC_WAIT_TIME, |
| 1052 | SMC_LLC_ADD_LINK_CONT); |
| 1053 | if (!qentry) { |
| 1054 | rc = -ETIMEDOUT; |
| 1055 | goto out; |
| 1056 | } |
| 1057 | addc_llc = &qentry->msg.add_link_cont; |
| 1058 | num_rkeys_recv = addc_llc->num_rkeys; |
| 1059 | max = min_t(u8, num_rkeys_recv, SMC_LLC_RKEYS_PER_CONT_MSG); |
| 1060 | for (i = 0; i < max; i++) { |
| 1061 | smc_rtoken_set(lgr, link->link_idx, link_new->link_idx, |
| 1062 | addc_llc->rt[i].rmb_key, |
| 1063 | addc_llc->rt[i].rmb_vaddr_new, |
| 1064 | addc_llc->rt[i].rmb_key_new); |
| 1065 | num_rkeys_recv--; |
| 1066 | } |
| 1067 | smc_llc_flow_qentry_del(&lgr->llc_flow_lcl); |
| 1068 | } while (num_rkeys_send || num_rkeys_recv); |
| 1069 | out: |
| 1070 | mutex_unlock(&lgr->rmbs_lock); |
| 1071 | return rc; |
| 1072 | } |
| 1073 | |
Karsten Graul | 1551c95 | 2020-05-03 14:38:45 +0200 | [diff] [blame] | 1074 | static int smc_llc_srv_conf_link(struct smc_link *link, |
| 1075 | struct smc_link *link_new, |
| 1076 | enum smc_lgr_type lgr_new_t) |
| 1077 | { |
| 1078 | struct smc_link_group *lgr = link->lgr; |
| 1079 | struct smc_llc_qentry *qentry = NULL; |
| 1080 | int rc; |
| 1081 | |
| 1082 | /* send CONFIRM LINK request over the RoCE fabric */ |
| 1083 | rc = smc_llc_send_confirm_link(link_new, SMC_LLC_REQ); |
| 1084 | if (rc) |
| 1085 | return -ENOLINK; |
| 1086 | /* receive CONFIRM LINK response over the RoCE fabric */ |
Karsten Graul | a35fffb | 2020-07-18 15:06:09 +0200 | [diff] [blame] | 1087 | qentry = smc_llc_wait(lgr, link, SMC_LLC_WAIT_FIRST_TIME, 0); |
| 1088 | if (!qentry || |
| 1089 | qentry->msg.raw.hdr.common.type != SMC_LLC_CONFIRM_LINK) { |
Karsten Graul | 1551c95 | 2020-05-03 14:38:45 +0200 | [diff] [blame] | 1090 | /* send DELETE LINK */ |
| 1091 | smc_llc_send_delete_link(link, link_new->link_id, SMC_LLC_REQ, |
| 1092 | false, SMC_LLC_DEL_LOST_PATH); |
Karsten Graul | a35fffb | 2020-07-18 15:06:09 +0200 | [diff] [blame] | 1093 | if (qentry) |
| 1094 | smc_llc_flow_qentry_del(&lgr->llc_flow_lcl); |
Karsten Graul | 1551c95 | 2020-05-03 14:38:45 +0200 | [diff] [blame] | 1095 | return -ENOLINK; |
| 1096 | } |
Karsten Graul | 649758f | 2020-05-04 14:18:48 +0200 | [diff] [blame] | 1097 | smc_llc_save_peer_uid(qentry); |
Karsten Graul | 1551c95 | 2020-05-03 14:38:45 +0200 | [diff] [blame] | 1098 | smc_llc_link_active(link_new); |
Karsten Graul | ad6c111 | 2020-05-04 14:18:44 +0200 | [diff] [blame] | 1099 | if (lgr_new_t == SMC_LGR_ASYMMETRIC_LOCAL || |
| 1100 | lgr_new_t == SMC_LGR_ASYMMETRIC_PEER) |
| 1101 | smcr_lgr_set_type_asym(lgr, lgr_new_t, link_new->link_idx); |
| 1102 | else |
| 1103 | smcr_lgr_set_type(lgr, lgr_new_t); |
Karsten Graul | 1551c95 | 2020-05-03 14:38:45 +0200 | [diff] [blame] | 1104 | smc_llc_flow_qentry_del(&lgr->llc_flow_lcl); |
| 1105 | return 0; |
| 1106 | } |
| 1107 | |
Karsten Graul | 2d2209f | 2020-05-03 14:38:43 +0200 | [diff] [blame] | 1108 | int smc_llc_srv_add_link(struct smc_link *link) |
| 1109 | { |
| 1110 | enum smc_lgr_type lgr_new_t = SMC_LGR_SYMMETRIC; |
| 1111 | struct smc_link_group *lgr = link->lgr; |
| 1112 | struct smc_llc_msg_add_link *add_llc; |
| 1113 | struct smc_llc_qentry *qentry = NULL; |
| 1114 | struct smc_link *link_new; |
| 1115 | struct smc_init_info ini; |
| 1116 | int lnk_idx, rc = 0; |
| 1117 | |
| 1118 | /* ignore client add link recommendation, start new flow */ |
| 1119 | ini.vlan_id = lgr->vlan_id; |
| 1120 | smc_pnet_find_alt_roce(lgr, &ini, link->smcibdev); |
| 1121 | if (!ini.ib_dev) { |
| 1122 | lgr_new_t = SMC_LGR_ASYMMETRIC_LOCAL; |
| 1123 | ini.ib_dev = link->smcibdev; |
| 1124 | ini.ib_port = link->ibport; |
| 1125 | } |
| 1126 | lnk_idx = smc_llc_alloc_alt_link(lgr, lgr_new_t); |
| 1127 | if (lnk_idx < 0) |
| 1128 | return 0; |
| 1129 | |
| 1130 | rc = smcr_link_init(lgr, &lgr->lnk[lnk_idx], lnk_idx, &ini); |
| 1131 | if (rc) |
| 1132 | return rc; |
| 1133 | link_new = &lgr->lnk[lnk_idx]; |
| 1134 | rc = smc_llc_send_add_link(link, |
| 1135 | link_new->smcibdev->mac[ini.ib_port - 1], |
| 1136 | link_new->gid, link_new, SMC_LLC_REQ); |
| 1137 | if (rc) |
| 1138 | goto out_err; |
| 1139 | /* receive ADD LINK response over the RoCE fabric */ |
| 1140 | qentry = smc_llc_wait(lgr, link, SMC_LLC_WAIT_TIME, SMC_LLC_ADD_LINK); |
| 1141 | if (!qentry) { |
| 1142 | rc = -ETIMEDOUT; |
| 1143 | goto out_err; |
| 1144 | } |
| 1145 | add_llc = &qentry->msg.add_link; |
| 1146 | if (add_llc->hd.flags & SMC_LLC_FLAG_ADD_LNK_REJ) { |
| 1147 | smc_llc_flow_qentry_del(&lgr->llc_flow_lcl); |
| 1148 | rc = -ENOLINK; |
| 1149 | goto out_err; |
| 1150 | } |
| 1151 | if (lgr->type == SMC_LGR_SINGLE && |
| 1152 | (!memcmp(add_llc->sender_gid, link->peer_gid, SMC_GID_SIZE) && |
| 1153 | !memcmp(add_llc->sender_mac, link->peer_mac, ETH_ALEN))) { |
| 1154 | lgr_new_t = SMC_LGR_ASYMMETRIC_PEER; |
| 1155 | } |
| 1156 | smc_llc_save_add_link_info(link_new, add_llc); |
| 1157 | smc_llc_flow_qentry_del(&lgr->llc_flow_lcl); |
| 1158 | |
| 1159 | rc = smc_ib_ready_link(link_new); |
| 1160 | if (rc) |
| 1161 | goto out_err; |
| 1162 | rc = smcr_buf_map_lgr(link_new); |
| 1163 | if (rc) |
| 1164 | goto out_err; |
| 1165 | rc = smcr_buf_reg_lgr(link_new); |
| 1166 | if (rc) |
| 1167 | goto out_err; |
Karsten Graul | 57b4992 | 2020-05-03 14:38:44 +0200 | [diff] [blame] | 1168 | rc = smc_llc_srv_rkey_exchange(link, link_new); |
Karsten Graul | 2d2209f | 2020-05-03 14:38:43 +0200 | [diff] [blame] | 1169 | if (rc) |
| 1170 | goto out_err; |
Karsten Graul | 1551c95 | 2020-05-03 14:38:45 +0200 | [diff] [blame] | 1171 | rc = smc_llc_srv_conf_link(link, link_new, lgr_new_t); |
Karsten Graul | 2d2209f | 2020-05-03 14:38:43 +0200 | [diff] [blame] | 1172 | if (rc) |
| 1173 | goto out_err; |
| 1174 | return 0; |
| 1175 | out_err: |
Karsten Graul | 0a99be4 | 2020-05-05 15:01:20 +0200 | [diff] [blame] | 1176 | smcr_link_clear(link_new, false); |
Karsten Graul | 2d2209f | 2020-05-03 14:38:43 +0200 | [diff] [blame] | 1177 | return rc; |
| 1178 | } |
| 1179 | |
| 1180 | static void smc_llc_process_srv_add_link(struct smc_link_group *lgr) |
| 1181 | { |
| 1182 | struct smc_link *link = lgr->llc_flow_lcl.qentry->link; |
| 1183 | int rc; |
| 1184 | |
| 1185 | smc_llc_flow_qentry_del(&lgr->llc_flow_lcl); |
| 1186 | |
| 1187 | mutex_lock(&lgr->llc_conf_mutex); |
| 1188 | rc = smc_llc_srv_add_link(link); |
| 1189 | if (!rc && lgr->type == SMC_LGR_SYMMETRIC) { |
| 1190 | /* delete any asymmetric link */ |
Karsten Graul | c9a5d24 | 2020-05-03 14:38:46 +0200 | [diff] [blame] | 1191 | smc_llc_delete_asym_link(lgr); |
Karsten Graul | 2d2209f | 2020-05-03 14:38:43 +0200 | [diff] [blame] | 1192 | } |
| 1193 | mutex_unlock(&lgr->llc_conf_mutex); |
| 1194 | } |
| 1195 | |
Karsten Graul | c48254f | 2020-07-18 15:06:14 +0200 | [diff] [blame] | 1196 | /* enqueue a local add_link req to trigger a new add_link flow */ |
| 1197 | void smc_llc_add_link_local(struct smc_link *link) |
Karsten Graul | 4dadd15 | 2020-05-03 14:38:50 +0200 | [diff] [blame] | 1198 | { |
| 1199 | struct smc_llc_msg_add_link add_llc = {0}; |
| 1200 | |
| 1201 | add_llc.hd.length = sizeof(add_llc); |
| 1202 | add_llc.hd.common.type = SMC_LLC_ADD_LINK; |
Karsten Graul | c48254f | 2020-07-18 15:06:14 +0200 | [diff] [blame] | 1203 | /* no dev and port needed */ |
Karsten Graul | 4dadd15 | 2020-05-03 14:38:50 +0200 | [diff] [blame] | 1204 | smc_llc_enqueue(link, (union smc_llc_msg *)&add_llc); |
| 1205 | } |
| 1206 | |
Karsten Graul | b45e7f9 | 2020-05-01 12:48:13 +0200 | [diff] [blame] | 1207 | /* worker to process an add link message */ |
| 1208 | static void smc_llc_add_link_work(struct work_struct *work) |
| 1209 | { |
| 1210 | struct smc_link_group *lgr = container_of(work, struct smc_link_group, |
| 1211 | llc_add_link_work); |
| 1212 | |
| 1213 | if (list_empty(&lgr->list)) { |
| 1214 | /* link group is terminating */ |
| 1215 | smc_llc_flow_qentry_del(&lgr->llc_flow_lcl); |
| 1216 | goto out; |
| 1217 | } |
| 1218 | |
Karsten Graul | b1570a8 | 2020-05-03 14:38:42 +0200 | [diff] [blame] | 1219 | if (lgr->role == SMC_CLNT) |
| 1220 | smc_llc_process_cli_add_link(lgr); |
Karsten Graul | 2d2209f | 2020-05-03 14:38:43 +0200 | [diff] [blame] | 1221 | else |
| 1222 | smc_llc_process_srv_add_link(lgr); |
Karsten Graul | b45e7f9 | 2020-05-01 12:48:13 +0200 | [diff] [blame] | 1223 | out: |
| 1224 | smc_llc_flow_stop(lgr, &lgr->llc_flow_lcl); |
| 1225 | } |
| 1226 | |
Karsten Graul | 4dadd15 | 2020-05-03 14:38:50 +0200 | [diff] [blame] | 1227 | /* enqueue a local del_link msg to trigger a new del_link flow, |
| 1228 | * called only for role SMC_SERV |
| 1229 | */ |
| 1230 | void smc_llc_srv_delete_link_local(struct smc_link *link, u8 del_link_id) |
| 1231 | { |
| 1232 | struct smc_llc_msg_del_link del_llc = {0}; |
| 1233 | |
| 1234 | del_llc.hd.length = sizeof(del_llc); |
| 1235 | del_llc.hd.common.type = SMC_LLC_DELETE_LINK; |
| 1236 | del_llc.link_num = del_link_id; |
| 1237 | del_llc.reason = htonl(SMC_LLC_DEL_LOST_PATH); |
| 1238 | del_llc.hd.flags |= SMC_LLC_FLAG_DEL_LINK_ORDERLY; |
| 1239 | smc_llc_enqueue(link, (union smc_llc_msg *)&del_llc); |
| 1240 | } |
| 1241 | |
Karsten Graul | 9c41687 | 2020-05-03 14:38:48 +0200 | [diff] [blame] | 1242 | static void smc_llc_process_cli_delete_link(struct smc_link_group *lgr) |
| 1243 | { |
| 1244 | struct smc_link *lnk_del = NULL, *lnk_asym, *lnk; |
| 1245 | struct smc_llc_msg_del_link *del_llc; |
| 1246 | struct smc_llc_qentry *qentry; |
| 1247 | int active_links; |
| 1248 | int lnk_idx; |
| 1249 | |
| 1250 | qentry = smc_llc_flow_qentry_clr(&lgr->llc_flow_lcl); |
| 1251 | lnk = qentry->link; |
| 1252 | del_llc = &qentry->msg.delete_link; |
| 1253 | |
| 1254 | if (del_llc->hd.flags & SMC_LLC_FLAG_DEL_LINK_ALL) { |
| 1255 | smc_lgr_terminate_sched(lgr); |
| 1256 | goto out; |
| 1257 | } |
| 1258 | mutex_lock(&lgr->llc_conf_mutex); |
| 1259 | /* delete single link */ |
| 1260 | for (lnk_idx = 0; lnk_idx < SMC_LINKS_PER_LGR_MAX; lnk_idx++) { |
| 1261 | if (lgr->lnk[lnk_idx].link_id != del_llc->link_num) |
| 1262 | continue; |
| 1263 | lnk_del = &lgr->lnk[lnk_idx]; |
| 1264 | break; |
| 1265 | } |
| 1266 | del_llc->hd.flags |= SMC_LLC_FLAG_RESP; |
| 1267 | if (!lnk_del) { |
| 1268 | /* link was not found */ |
| 1269 | del_llc->reason = htonl(SMC_LLC_DEL_NOLNK); |
| 1270 | smc_llc_send_message(lnk, &qentry->msg); |
| 1271 | goto out_unlock; |
| 1272 | } |
| 1273 | lnk_asym = smc_llc_find_asym_link(lgr); |
| 1274 | |
| 1275 | del_llc->reason = 0; |
| 1276 | smc_llc_send_message(lnk, &qentry->msg); /* response */ |
| 1277 | |
| 1278 | if (smc_link_downing(&lnk_del->state)) { |
Karsten Graul | b7eede7 | 2020-07-08 17:05:12 +0200 | [diff] [blame] | 1279 | if (smc_switch_conns(lgr, lnk_del, false)) |
| 1280 | smc_wr_tx_wait_no_pending_sends(lnk_del); |
Karsten Graul | 9c41687 | 2020-05-03 14:38:48 +0200 | [diff] [blame] | 1281 | } |
Karsten Graul | 0a99be4 | 2020-05-05 15:01:20 +0200 | [diff] [blame] | 1282 | smcr_link_clear(lnk_del, true); |
Karsten Graul | 9c41687 | 2020-05-03 14:38:48 +0200 | [diff] [blame] | 1283 | |
| 1284 | active_links = smc_llc_active_link_count(lgr); |
| 1285 | if (lnk_del == lnk_asym) { |
| 1286 | /* expected deletion of asym link, don't change lgr state */ |
| 1287 | } else if (active_links == 1) { |
Karsten Graul | ad6c111 | 2020-05-04 14:18:44 +0200 | [diff] [blame] | 1288 | smcr_lgr_set_type(lgr, SMC_LGR_SINGLE); |
Karsten Graul | 9c41687 | 2020-05-03 14:38:48 +0200 | [diff] [blame] | 1289 | } else if (!active_links) { |
Karsten Graul | ad6c111 | 2020-05-04 14:18:44 +0200 | [diff] [blame] | 1290 | smcr_lgr_set_type(lgr, SMC_LGR_NONE); |
Karsten Graul | 9c41687 | 2020-05-03 14:38:48 +0200 | [diff] [blame] | 1291 | smc_lgr_terminate_sched(lgr); |
| 1292 | } |
| 1293 | out_unlock: |
| 1294 | mutex_unlock(&lgr->llc_conf_mutex); |
| 1295 | out: |
| 1296 | kfree(qentry); |
| 1297 | } |
| 1298 | |
Karsten Graul | f3811fd | 2020-05-04 14:18:42 +0200 | [diff] [blame] | 1299 | /* try to send a DELETE LINK ALL request on any active link, |
| 1300 | * waiting for send completion |
| 1301 | */ |
| 1302 | void smc_llc_send_link_delete_all(struct smc_link_group *lgr, bool ord, u32 rsn) |
| 1303 | { |
| 1304 | struct smc_llc_msg_del_link delllc = {0}; |
| 1305 | int i; |
| 1306 | |
| 1307 | delllc.hd.common.type = SMC_LLC_DELETE_LINK; |
| 1308 | delllc.hd.length = sizeof(delllc); |
| 1309 | if (ord) |
| 1310 | delllc.hd.flags |= SMC_LLC_FLAG_DEL_LINK_ORDERLY; |
| 1311 | delllc.hd.flags |= SMC_LLC_FLAG_DEL_LINK_ALL; |
| 1312 | delllc.reason = htonl(rsn); |
| 1313 | |
| 1314 | for (i = 0; i < SMC_LINKS_PER_LGR_MAX; i++) { |
| 1315 | if (!smc_link_usable(&lgr->lnk[i])) |
| 1316 | continue; |
| 1317 | if (!smc_llc_send_message_wait(&lgr->lnk[i], &delllc)) |
| 1318 | break; |
| 1319 | } |
| 1320 | } |
| 1321 | |
Karsten Graul | 08ae27d | 2020-05-03 14:38:49 +0200 | [diff] [blame] | 1322 | static void smc_llc_process_srv_delete_link(struct smc_link_group *lgr) |
| 1323 | { |
| 1324 | struct smc_llc_msg_del_link *del_llc; |
| 1325 | struct smc_link *lnk, *lnk_del; |
| 1326 | struct smc_llc_qentry *qentry; |
| 1327 | int active_links; |
| 1328 | int i; |
| 1329 | |
| 1330 | mutex_lock(&lgr->llc_conf_mutex); |
| 1331 | qentry = smc_llc_flow_qentry_clr(&lgr->llc_flow_lcl); |
| 1332 | lnk = qentry->link; |
| 1333 | del_llc = &qentry->msg.delete_link; |
| 1334 | |
| 1335 | if (qentry->msg.delete_link.hd.flags & SMC_LLC_FLAG_DEL_LINK_ALL) { |
| 1336 | /* delete entire lgr */ |
Karsten Graul | f3811fd | 2020-05-04 14:18:42 +0200 | [diff] [blame] | 1337 | smc_llc_send_link_delete_all(lgr, true, ntohl( |
| 1338 | qentry->msg.delete_link.reason)); |
Karsten Graul | 08ae27d | 2020-05-03 14:38:49 +0200 | [diff] [blame] | 1339 | smc_lgr_terminate_sched(lgr); |
| 1340 | goto out; |
| 1341 | } |
| 1342 | /* delete single link */ |
| 1343 | lnk_del = NULL; |
| 1344 | for (i = 0; i < SMC_LINKS_PER_LGR_MAX; i++) { |
| 1345 | if (lgr->lnk[i].link_id == del_llc->link_num) { |
| 1346 | lnk_del = &lgr->lnk[i]; |
| 1347 | break; |
| 1348 | } |
| 1349 | } |
| 1350 | if (!lnk_del) |
| 1351 | goto out; /* asymmetric link already deleted */ |
| 1352 | |
| 1353 | if (smc_link_downing(&lnk_del->state)) { |
Karsten Graul | b7eede7 | 2020-07-08 17:05:12 +0200 | [diff] [blame] | 1354 | if (smc_switch_conns(lgr, lnk_del, false)) |
| 1355 | smc_wr_tx_wait_no_pending_sends(lnk_del); |
Karsten Graul | 08ae27d | 2020-05-03 14:38:49 +0200 | [diff] [blame] | 1356 | } |
| 1357 | if (!list_empty(&lgr->list)) { |
| 1358 | /* qentry is either a request from peer (send it back to |
| 1359 | * initiate the DELETE_LINK processing), or a locally |
| 1360 | * enqueued DELETE_LINK request (forward it) |
| 1361 | */ |
| 1362 | if (!smc_llc_send_message(lnk, &qentry->msg)) { |
Karsten Graul | 08ae27d | 2020-05-03 14:38:49 +0200 | [diff] [blame] | 1363 | struct smc_llc_qentry *qentry2; |
| 1364 | |
| 1365 | qentry2 = smc_llc_wait(lgr, lnk, SMC_LLC_WAIT_TIME, |
| 1366 | SMC_LLC_DELETE_LINK); |
YueHaibing | ca7e3ed | 2020-05-07 16:24:06 +0200 | [diff] [blame] | 1367 | if (qentry2) |
Karsten Graul | 08ae27d | 2020-05-03 14:38:49 +0200 | [diff] [blame] | 1368 | smc_llc_flow_qentry_del(&lgr->llc_flow_lcl); |
Karsten Graul | 08ae27d | 2020-05-03 14:38:49 +0200 | [diff] [blame] | 1369 | } |
| 1370 | } |
Karsten Graul | 0a99be4 | 2020-05-05 15:01:20 +0200 | [diff] [blame] | 1371 | smcr_link_clear(lnk_del, true); |
Karsten Graul | 08ae27d | 2020-05-03 14:38:49 +0200 | [diff] [blame] | 1372 | |
| 1373 | active_links = smc_llc_active_link_count(lgr); |
| 1374 | if (active_links == 1) { |
Karsten Graul | ad6c111 | 2020-05-04 14:18:44 +0200 | [diff] [blame] | 1375 | smcr_lgr_set_type(lgr, SMC_LGR_SINGLE); |
Karsten Graul | 08ae27d | 2020-05-03 14:38:49 +0200 | [diff] [blame] | 1376 | } else if (!active_links) { |
Karsten Graul | ad6c111 | 2020-05-04 14:18:44 +0200 | [diff] [blame] | 1377 | smcr_lgr_set_type(lgr, SMC_LGR_NONE); |
Karsten Graul | 08ae27d | 2020-05-03 14:38:49 +0200 | [diff] [blame] | 1378 | smc_lgr_terminate_sched(lgr); |
| 1379 | } |
| 1380 | |
| 1381 | if (lgr->type == SMC_LGR_SINGLE && !list_empty(&lgr->list)) { |
| 1382 | /* trigger setup of asymm alt link */ |
Karsten Graul | c48254f | 2020-07-18 15:06:14 +0200 | [diff] [blame] | 1383 | smc_llc_add_link_local(lnk); |
Karsten Graul | 08ae27d | 2020-05-03 14:38:49 +0200 | [diff] [blame] | 1384 | } |
| 1385 | out: |
| 1386 | mutex_unlock(&lgr->llc_conf_mutex); |
| 1387 | kfree(qentry); |
| 1388 | } |
| 1389 | |
Karsten Graul | 9ec6bf1 | 2020-05-03 14:38:47 +0200 | [diff] [blame] | 1390 | static void smc_llc_delete_link_work(struct work_struct *work) |
Karsten Graul | 52bedf3 | 2018-03-01 13:51:32 +0100 | [diff] [blame] | 1391 | { |
Karsten Graul | 9ec6bf1 | 2020-05-03 14:38:47 +0200 | [diff] [blame] | 1392 | struct smc_link_group *lgr = container_of(work, struct smc_link_group, |
| 1393 | llc_del_link_work); |
Karsten Graul | 52bedf3 | 2018-03-01 13:51:32 +0100 | [diff] [blame] | 1394 | |
Karsten Graul | 9ec6bf1 | 2020-05-03 14:38:47 +0200 | [diff] [blame] | 1395 | if (list_empty(&lgr->list)) { |
| 1396 | /* link group is terminating */ |
| 1397 | smc_llc_flow_qentry_del(&lgr->llc_flow_lcl); |
| 1398 | goto out; |
Karsten Graul | 52bedf3 | 2018-03-01 13:51:32 +0100 | [diff] [blame] | 1399 | } |
Karsten Graul | 9c41687 | 2020-05-03 14:38:48 +0200 | [diff] [blame] | 1400 | |
| 1401 | if (lgr->role == SMC_CLNT) |
| 1402 | smc_llc_process_cli_delete_link(lgr); |
Karsten Graul | 08ae27d | 2020-05-03 14:38:49 +0200 | [diff] [blame] | 1403 | else |
| 1404 | smc_llc_process_srv_delete_link(lgr); |
Karsten Graul | 9ec6bf1 | 2020-05-03 14:38:47 +0200 | [diff] [blame] | 1405 | out: |
| 1406 | smc_llc_flow_stop(lgr, &lgr->llc_flow_lcl); |
Karsten Graul | 52bedf3 | 2018-03-01 13:51:32 +0100 | [diff] [blame] | 1407 | } |
| 1408 | |
Karsten Graul | 3bc67e0 | 2020-04-30 15:55:48 +0200 | [diff] [blame] | 1409 | /* process a confirm_rkey request from peer, remote flow */ |
| 1410 | static void smc_llc_rmt_conf_rkey(struct smc_link_group *lgr) |
Karsten Graul | 4ed75de | 2018-03-01 13:51:30 +0100 | [diff] [blame] | 1411 | { |
Karsten Graul | 3bc67e0 | 2020-04-30 15:55:48 +0200 | [diff] [blame] | 1412 | struct smc_llc_msg_confirm_rkey *llc; |
| 1413 | struct smc_llc_qentry *qentry; |
| 1414 | struct smc_link *link; |
| 1415 | int num_entries; |
| 1416 | int rk_idx; |
| 1417 | int i; |
Karsten Graul | 4ed75de | 2018-03-01 13:51:30 +0100 | [diff] [blame] | 1418 | |
Karsten Graul | 3bc67e0 | 2020-04-30 15:55:48 +0200 | [diff] [blame] | 1419 | qentry = lgr->llc_flow_rmt.qentry; |
| 1420 | llc = &qentry->msg.confirm_rkey; |
| 1421 | link = qentry->link; |
Karsten Graul | 4ed75de | 2018-03-01 13:51:30 +0100 | [diff] [blame] | 1422 | |
Karsten Graul | 3bc67e0 | 2020-04-30 15:55:48 +0200 | [diff] [blame] | 1423 | num_entries = llc->rtoken[0].num_rkeys; |
| 1424 | /* first rkey entry is for receiving link */ |
| 1425 | rk_idx = smc_rtoken_add(link, |
| 1426 | llc->rtoken[0].rmb_vaddr, |
| 1427 | llc->rtoken[0].rmb_key); |
| 1428 | if (rk_idx < 0) |
| 1429 | goto out_err; |
Karsten Graul | 4ed75de | 2018-03-01 13:51:30 +0100 | [diff] [blame] | 1430 | |
Karsten Graul | 3bc67e0 | 2020-04-30 15:55:48 +0200 | [diff] [blame] | 1431 | for (i = 1; i <= min_t(u8, num_entries, SMC_LLC_RKEYS_PER_MSG - 1); i++) |
| 1432 | smc_rtoken_set2(lgr, rk_idx, llc->rtoken[i].link_id, |
| 1433 | llc->rtoken[i].rmb_vaddr, |
| 1434 | llc->rtoken[i].rmb_key); |
| 1435 | /* max links is 3 so there is no need to support conf_rkey_cont msgs */ |
| 1436 | goto out; |
| 1437 | out_err: |
| 1438 | llc->hd.flags |= SMC_LLC_FLAG_RKEY_NEG; |
| 1439 | llc->hd.flags |= SMC_LLC_FLAG_RKEY_RETRY; |
| 1440 | out: |
Karsten Graul | ef79d43 | 2020-04-29 17:10:47 +0200 | [diff] [blame] | 1441 | llc->hd.flags |= SMC_LLC_FLAG_RESP; |
Karsten Graul | 3bc67e0 | 2020-04-30 15:55:48 +0200 | [diff] [blame] | 1442 | smc_llc_send_message(link, &qentry->msg); |
| 1443 | smc_llc_flow_qentry_del(&lgr->llc_flow_rmt); |
Karsten Graul | 4ed75de | 2018-03-01 13:51:30 +0100 | [diff] [blame] | 1444 | } |
| 1445 | |
Karsten Graul | 218b24f | 2020-04-30 15:55:49 +0200 | [diff] [blame] | 1446 | /* process a delete_rkey request from peer, remote flow */ |
| 1447 | static void smc_llc_rmt_delete_rkey(struct smc_link_group *lgr) |
Karsten Graul | 4ed75de | 2018-03-01 13:51:30 +0100 | [diff] [blame] | 1448 | { |
Karsten Graul | 218b24f | 2020-04-30 15:55:49 +0200 | [diff] [blame] | 1449 | struct smc_llc_msg_delete_rkey *llc; |
| 1450 | struct smc_llc_qentry *qentry; |
| 1451 | struct smc_link *link; |
Karsten Graul | 4ed75de | 2018-03-01 13:51:30 +0100 | [diff] [blame] | 1452 | u8 err_mask = 0; |
| 1453 | int i, max; |
| 1454 | |
Karsten Graul | 218b24f | 2020-04-30 15:55:49 +0200 | [diff] [blame] | 1455 | qentry = lgr->llc_flow_rmt.qentry; |
| 1456 | llc = &qentry->msg.delete_rkey; |
| 1457 | link = qentry->link; |
| 1458 | |
Karsten Graul | ef79d43 | 2020-04-29 17:10:47 +0200 | [diff] [blame] | 1459 | max = min_t(u8, llc->num_rkeys, SMC_LLC_DEL_RKEY_MAX); |
| 1460 | for (i = 0; i < max; i++) { |
| 1461 | if (smc_rtoken_delete(link, llc->rkey[i])) |
| 1462 | err_mask |= 1 << (SMC_LLC_DEL_RKEY_MAX - 1 - i); |
Karsten Graul | 4ed75de | 2018-03-01 13:51:30 +0100 | [diff] [blame] | 1463 | } |
Karsten Graul | ef79d43 | 2020-04-29 17:10:47 +0200 | [diff] [blame] | 1464 | if (err_mask) { |
| 1465 | llc->hd.flags |= SMC_LLC_FLAG_RKEY_NEG; |
| 1466 | llc->err_mask = err_mask; |
| 1467 | } |
Karsten Graul | 218b24f | 2020-04-30 15:55:49 +0200 | [diff] [blame] | 1468 | llc->hd.flags |= SMC_LLC_FLAG_RESP; |
| 1469 | smc_llc_send_message(link, &qentry->msg); |
| 1470 | smc_llc_flow_qentry_del(&lgr->llc_flow_rmt); |
| 1471 | } |
Karsten Graul | ef79d43 | 2020-04-29 17:10:47 +0200 | [diff] [blame] | 1472 | |
Karsten Graul | 3e0c40a | 2020-05-04 14:18:45 +0200 | [diff] [blame] | 1473 | static void smc_llc_protocol_violation(struct smc_link_group *lgr, u8 type) |
| 1474 | { |
| 1475 | pr_warn_ratelimited("smc: SMC-R lg %*phN LLC protocol violation: " |
| 1476 | "llc_type %d\n", SMC_LGR_ID_SIZE, &lgr->id, type); |
| 1477 | smc_llc_set_termination_rsn(lgr, SMC_LLC_DEL_PROT_VIOL); |
| 1478 | smc_lgr_terminate_sched(lgr); |
| 1479 | } |
| 1480 | |
Karsten Graul | 6c8968c | 2020-04-29 17:10:46 +0200 | [diff] [blame] | 1481 | /* flush the llc event queue */ |
Karsten Graul | 00a049c | 2020-04-29 17:10:49 +0200 | [diff] [blame] | 1482 | static void smc_llc_event_flush(struct smc_link_group *lgr) |
Ursula Braun | 9bf9abe | 2017-01-09 16:55:21 +0100 | [diff] [blame] | 1483 | { |
Karsten Graul | 6c8968c | 2020-04-29 17:10:46 +0200 | [diff] [blame] | 1484 | struct smc_llc_qentry *qentry, *q; |
Ursula Braun | 9bf9abe | 2017-01-09 16:55:21 +0100 | [diff] [blame] | 1485 | |
Karsten Graul | 6c8968c | 2020-04-29 17:10:46 +0200 | [diff] [blame] | 1486 | spin_lock_bh(&lgr->llc_event_q_lock); |
| 1487 | list_for_each_entry_safe(qentry, q, &lgr->llc_event_q, list) { |
| 1488 | list_del_init(&qentry->list); |
| 1489 | kfree(qentry); |
| 1490 | } |
| 1491 | spin_unlock_bh(&lgr->llc_event_q_lock); |
| 1492 | } |
| 1493 | |
| 1494 | static void smc_llc_event_handler(struct smc_llc_qentry *qentry) |
| 1495 | { |
| 1496 | union smc_llc_msg *llc = &qentry->msg; |
| 1497 | struct smc_link *link = qentry->link; |
Karsten Graul | 0fb0b02 | 2020-04-30 15:55:43 +0200 | [diff] [blame] | 1498 | struct smc_link_group *lgr = link->lgr; |
Karsten Graul | 6c8968c | 2020-04-29 17:10:46 +0200 | [diff] [blame] | 1499 | |
Karsten Graul | d854fcb | 2020-04-29 17:10:43 +0200 | [diff] [blame] | 1500 | if (!smc_link_usable(link)) |
Karsten Graul | 6c8968c | 2020-04-29 17:10:46 +0200 | [diff] [blame] | 1501 | goto out; |
Karsten Graul | 313164d | 2018-03-01 13:51:29 +0100 | [diff] [blame] | 1502 | |
| 1503 | switch (llc->raw.hdr.common.type) { |
| 1504 | case SMC_LLC_TEST_LINK: |
Karsten Graul | 56e8091 | 2020-04-30 15:55:46 +0200 | [diff] [blame] | 1505 | llc->test_link.hd.flags |= SMC_LLC_FLAG_RESP; |
| 1506 | smc_llc_send_message(link, llc); |
Karsten Graul | 313164d | 2018-03-01 13:51:29 +0100 | [diff] [blame] | 1507 | break; |
Karsten Graul | 52bedf3 | 2018-03-01 13:51:32 +0100 | [diff] [blame] | 1508 | case SMC_LLC_ADD_LINK: |
Karsten Graul | 0fb0b02 | 2020-04-30 15:55:43 +0200 | [diff] [blame] | 1509 | if (list_empty(&lgr->list)) |
| 1510 | goto out; /* lgr is terminating */ |
| 1511 | if (lgr->role == SMC_CLNT) { |
Karsten Graul | c48254f | 2020-07-18 15:06:14 +0200 | [diff] [blame] | 1512 | if (smc_llc_is_local_add_link(llc)) { |
| 1513 | if (lgr->llc_flow_lcl.type == |
| 1514 | SMC_LLC_FLOW_ADD_LINK) |
| 1515 | break; /* add_link in progress */ |
| 1516 | if (smc_llc_flow_start(&lgr->llc_flow_lcl, |
| 1517 | qentry)) { |
| 1518 | schedule_work(&lgr->llc_add_link_work); |
| 1519 | } |
| 1520 | return; |
| 1521 | } |
| 1522 | if (lgr->llc_flow_lcl.type == SMC_LLC_FLOW_ADD_LINK && |
| 1523 | !lgr->llc_flow_lcl.qentry) { |
Karsten Graul | 0fb0b02 | 2020-04-30 15:55:43 +0200 | [diff] [blame] | 1524 | /* a flow is waiting for this message */ |
| 1525 | smc_llc_flow_qentry_set(&lgr->llc_flow_lcl, |
| 1526 | qentry); |
Karsten Graul | 6778a6b | 2020-07-08 17:05:11 +0200 | [diff] [blame] | 1527 | wake_up(&lgr->llc_msg_waiter); |
Karsten Graul | 0fb0b02 | 2020-04-30 15:55:43 +0200 | [diff] [blame] | 1528 | } else if (smc_llc_flow_start(&lgr->llc_flow_lcl, |
| 1529 | qentry)) { |
Karsten Graul | b45e7f9 | 2020-05-01 12:48:13 +0200 | [diff] [blame] | 1530 | schedule_work(&lgr->llc_add_link_work); |
Karsten Graul | 0fb0b02 | 2020-04-30 15:55:43 +0200 | [diff] [blame] | 1531 | } |
| 1532 | } else if (smc_llc_flow_start(&lgr->llc_flow_lcl, qentry)) { |
| 1533 | /* as smc server, handle client suggestion */ |
Karsten Graul | b45e7f9 | 2020-05-01 12:48:13 +0200 | [diff] [blame] | 1534 | schedule_work(&lgr->llc_add_link_work); |
Karsten Graul | 0fb0b02 | 2020-04-30 15:55:43 +0200 | [diff] [blame] | 1535 | } |
| 1536 | return; |
| 1537 | case SMC_LLC_CONFIRM_LINK: |
Karsten Graul | 87f88cd | 2020-05-03 14:38:41 +0200 | [diff] [blame] | 1538 | case SMC_LLC_ADD_LINK_CONT: |
Karsten Graul | 0fb0b02 | 2020-04-30 15:55:43 +0200 | [diff] [blame] | 1539 | if (lgr->llc_flow_lcl.type != SMC_LLC_FLOW_NONE) { |
| 1540 | /* a flow is waiting for this message */ |
| 1541 | smc_llc_flow_qentry_set(&lgr->llc_flow_lcl, qentry); |
Karsten Graul | 6778a6b | 2020-07-08 17:05:11 +0200 | [diff] [blame] | 1542 | wake_up(&lgr->llc_msg_waiter); |
Karsten Graul | 0fb0b02 | 2020-04-30 15:55:43 +0200 | [diff] [blame] | 1543 | return; |
| 1544 | } |
Karsten Graul | 52bedf3 | 2018-03-01 13:51:32 +0100 | [diff] [blame] | 1545 | break; |
| 1546 | case SMC_LLC_DELETE_LINK: |
Karsten Graul | b9979c2 | 2020-07-18 15:06:15 +0200 | [diff] [blame] | 1547 | if (lgr->llc_flow_lcl.type == SMC_LLC_FLOW_ADD_LINK && |
| 1548 | !lgr->llc_flow_lcl.qentry) { |
| 1549 | /* DEL LINK REQ during ADD LINK SEQ */ |
| 1550 | smc_llc_flow_qentry_set(&lgr->llc_flow_lcl, qentry); |
| 1551 | wake_up(&lgr->llc_msg_waiter); |
| 1552 | } else if (smc_llc_flow_start(&lgr->llc_flow_lcl, qentry)) { |
| 1553 | schedule_work(&lgr->llc_del_link_work); |
Karsten Graul | 9ec6bf1 | 2020-05-03 14:38:47 +0200 | [diff] [blame] | 1554 | } |
| 1555 | return; |
Karsten Graul | 4ed75de | 2018-03-01 13:51:30 +0100 | [diff] [blame] | 1556 | case SMC_LLC_CONFIRM_RKEY: |
Karsten Graul | 3bc67e0 | 2020-04-30 15:55:48 +0200 | [diff] [blame] | 1557 | /* new request from remote, assign to remote flow */ |
| 1558 | if (smc_llc_flow_start(&lgr->llc_flow_rmt, qentry)) { |
| 1559 | /* process here, does not wait for more llc msgs */ |
| 1560 | smc_llc_rmt_conf_rkey(lgr); |
| 1561 | smc_llc_flow_stop(lgr, &lgr->llc_flow_rmt); |
| 1562 | } |
| 1563 | return; |
Karsten Graul | 4ed75de | 2018-03-01 13:51:30 +0100 | [diff] [blame] | 1564 | case SMC_LLC_CONFIRM_RKEY_CONT: |
Karsten Graul | 42d18ac | 2020-04-30 15:55:50 +0200 | [diff] [blame] | 1565 | /* not used because max links is 3, and 3 rkeys fit into |
| 1566 | * one CONFIRM_RKEY message |
| 1567 | */ |
Karsten Graul | 4ed75de | 2018-03-01 13:51:30 +0100 | [diff] [blame] | 1568 | break; |
| 1569 | case SMC_LLC_DELETE_RKEY: |
Karsten Graul | 218b24f | 2020-04-30 15:55:49 +0200 | [diff] [blame] | 1570 | /* new request from remote, assign to remote flow */ |
| 1571 | if (smc_llc_flow_start(&lgr->llc_flow_rmt, qentry)) { |
| 1572 | /* process here, does not wait for more llc msgs */ |
| 1573 | smc_llc_rmt_delete_rkey(lgr); |
| 1574 | smc_llc_flow_stop(lgr, &lgr->llc_flow_rmt); |
| 1575 | } |
| 1576 | return; |
Karsten Graul | 3e0c40a | 2020-05-04 14:18:45 +0200 | [diff] [blame] | 1577 | default: |
| 1578 | smc_llc_protocol_violation(lgr, llc->raw.hdr.common.type); |
| 1579 | break; |
Karsten Graul | 313164d | 2018-03-01 13:51:29 +0100 | [diff] [blame] | 1580 | } |
Karsten Graul | 6c8968c | 2020-04-29 17:10:46 +0200 | [diff] [blame] | 1581 | out: |
| 1582 | kfree(qentry); |
| 1583 | } |
| 1584 | |
| 1585 | /* worker to process llc messages on the event queue */ |
| 1586 | static void smc_llc_event_work(struct work_struct *work) |
| 1587 | { |
| 1588 | struct smc_link_group *lgr = container_of(work, struct smc_link_group, |
| 1589 | llc_event_work); |
| 1590 | struct smc_llc_qentry *qentry; |
| 1591 | |
Karsten Graul | 555da9a | 2020-04-30 15:55:38 +0200 | [diff] [blame] | 1592 | if (!lgr->llc_flow_lcl.type && lgr->delayed_event) { |
| 1593 | if (smc_link_usable(lgr->delayed_event->link)) { |
| 1594 | smc_llc_event_handler(lgr->delayed_event); |
| 1595 | } else { |
| 1596 | qentry = lgr->delayed_event; |
| 1597 | lgr->delayed_event = NULL; |
| 1598 | kfree(qentry); |
| 1599 | } |
| 1600 | } |
| 1601 | |
Karsten Graul | 6c8968c | 2020-04-29 17:10:46 +0200 | [diff] [blame] | 1602 | again: |
| 1603 | spin_lock_bh(&lgr->llc_event_q_lock); |
| 1604 | if (!list_empty(&lgr->llc_event_q)) { |
| 1605 | qentry = list_first_entry(&lgr->llc_event_q, |
| 1606 | struct smc_llc_qentry, list); |
| 1607 | list_del_init(&qentry->list); |
| 1608 | spin_unlock_bh(&lgr->llc_event_q_lock); |
| 1609 | smc_llc_event_handler(qentry); |
| 1610 | goto again; |
| 1611 | } |
| 1612 | spin_unlock_bh(&lgr->llc_event_q_lock); |
| 1613 | } |
| 1614 | |
Karsten Graul | ef79d43 | 2020-04-29 17:10:47 +0200 | [diff] [blame] | 1615 | /* process llc responses in tasklet context */ |
Karsten Graul | a6688d9 | 2020-04-30 15:55:39 +0200 | [diff] [blame] | 1616 | static void smc_llc_rx_response(struct smc_link *link, |
| 1617 | struct smc_llc_qentry *qentry) |
Karsten Graul | ef79d43 | 2020-04-29 17:10:47 +0200 | [diff] [blame] | 1618 | { |
Karsten Graul | 2ff0867 | 2020-07-18 15:06:13 +0200 | [diff] [blame] | 1619 | enum smc_llc_flowtype flowtype = link->lgr->llc_flow_lcl.type; |
| 1620 | struct smc_llc_flow *flow = &link->lgr->llc_flow_lcl; |
Karsten Graul | a6688d9 | 2020-04-30 15:55:39 +0200 | [diff] [blame] | 1621 | u8 llc_type = qentry->msg.raw.hdr.common.type; |
Karsten Graul | ef79d43 | 2020-04-29 17:10:47 +0200 | [diff] [blame] | 1622 | |
Karsten Graul | a6688d9 | 2020-04-30 15:55:39 +0200 | [diff] [blame] | 1623 | switch (llc_type) { |
Karsten Graul | ef79d43 | 2020-04-29 17:10:47 +0200 | [diff] [blame] | 1624 | case SMC_LLC_TEST_LINK: |
Karsten Graul | 741a49a | 2020-07-18 15:06:16 +0200 | [diff] [blame^] | 1625 | if (smc_link_active(link)) |
Karsten Graul | ef79d43 | 2020-04-29 17:10:47 +0200 | [diff] [blame] | 1626 | complete(&link->llc_testlink_resp); |
| 1627 | break; |
Karsten Graul | ef79d43 | 2020-04-29 17:10:47 +0200 | [diff] [blame] | 1628 | case SMC_LLC_ADD_LINK: |
Karsten Graul | 87f88cd | 2020-05-03 14:38:41 +0200 | [diff] [blame] | 1629 | case SMC_LLC_ADD_LINK_CONT: |
Karsten Graul | 2ff0867 | 2020-07-18 15:06:13 +0200 | [diff] [blame] | 1630 | case SMC_LLC_CONFIRM_LINK: |
| 1631 | if (flowtype != SMC_LLC_FLOW_ADD_LINK || flow->qentry) |
| 1632 | break; /* drop out-of-flow response */ |
| 1633 | goto assign; |
| 1634 | case SMC_LLC_DELETE_LINK: |
| 1635 | if (flowtype != SMC_LLC_FLOW_DEL_LINK || flow->qentry) |
| 1636 | break; /* drop out-of-flow response */ |
| 1637 | goto assign; |
Karsten Graul | 3d88a21 | 2020-04-30 15:55:44 +0200 | [diff] [blame] | 1638 | case SMC_LLC_CONFIRM_RKEY: |
Karsten Graul | 6d74c3a | 2020-04-30 15:55:45 +0200 | [diff] [blame] | 1639 | case SMC_LLC_DELETE_RKEY: |
Karsten Graul | 2ff0867 | 2020-07-18 15:06:13 +0200 | [diff] [blame] | 1640 | if (flowtype != SMC_LLC_FLOW_RKEY || flow->qentry) |
| 1641 | break; /* drop out-of-flow response */ |
| 1642 | goto assign; |
Karsten Graul | ef79d43 | 2020-04-29 17:10:47 +0200 | [diff] [blame] | 1643 | case SMC_LLC_CONFIRM_RKEY_CONT: |
Karsten Graul | 42d18ac | 2020-04-30 15:55:50 +0200 | [diff] [blame] | 1644 | /* not used because max links is 3 */ |
Karsten Graul | ef79d43 | 2020-04-29 17:10:47 +0200 | [diff] [blame] | 1645 | break; |
Karsten Graul | 3e0c40a | 2020-05-04 14:18:45 +0200 | [diff] [blame] | 1646 | default: |
| 1647 | smc_llc_protocol_violation(link->lgr, llc_type); |
| 1648 | break; |
Karsten Graul | ef79d43 | 2020-04-29 17:10:47 +0200 | [diff] [blame] | 1649 | } |
Karsten Graul | a6688d9 | 2020-04-30 15:55:39 +0200 | [diff] [blame] | 1650 | kfree(qentry); |
Karsten Graul | 2ff0867 | 2020-07-18 15:06:13 +0200 | [diff] [blame] | 1651 | return; |
| 1652 | assign: |
| 1653 | /* assign responses to the local flow, we requested them */ |
| 1654 | smc_llc_flow_qentry_set(&link->lgr->llc_flow_lcl, qentry); |
| 1655 | wake_up(&link->lgr->llc_msg_waiter); |
Karsten Graul | ef79d43 | 2020-04-29 17:10:47 +0200 | [diff] [blame] | 1656 | } |
| 1657 | |
Karsten Graul | a6688d9 | 2020-04-30 15:55:39 +0200 | [diff] [blame] | 1658 | 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] | 1659 | { |
Karsten Graul | 6c8968c | 2020-04-29 17:10:46 +0200 | [diff] [blame] | 1660 | struct smc_link_group *lgr = link->lgr; |
| 1661 | struct smc_llc_qentry *qentry; |
Karsten Graul | 6c8968c | 2020-04-29 17:10:46 +0200 | [diff] [blame] | 1662 | unsigned long flags; |
| 1663 | |
Karsten Graul | 6c8968c | 2020-04-29 17:10:46 +0200 | [diff] [blame] | 1664 | qentry = kmalloc(sizeof(*qentry), GFP_ATOMIC); |
| 1665 | if (!qentry) |
| 1666 | return; |
| 1667 | qentry->link = link; |
| 1668 | INIT_LIST_HEAD(&qentry->list); |
| 1669 | memcpy(&qentry->msg, llc, sizeof(union smc_llc_msg)); |
Karsten Graul | a6688d9 | 2020-04-30 15:55:39 +0200 | [diff] [blame] | 1670 | |
| 1671 | /* process responses immediately */ |
| 1672 | if (llc->raw.hdr.flags & SMC_LLC_FLAG_RESP) { |
| 1673 | smc_llc_rx_response(link, qentry); |
| 1674 | return; |
| 1675 | } |
| 1676 | |
| 1677 | /* add requests to event queue */ |
Karsten Graul | 6c8968c | 2020-04-29 17:10:46 +0200 | [diff] [blame] | 1678 | spin_lock_irqsave(&lgr->llc_event_q_lock, flags); |
| 1679 | list_add_tail(&qentry->list, &lgr->llc_event_q); |
| 1680 | spin_unlock_irqrestore(&lgr->llc_event_q_lock, flags); |
Karsten Graul | 6778a6b | 2020-07-08 17:05:11 +0200 | [diff] [blame] | 1681 | schedule_work(&lgr->llc_event_work); |
Ursula Braun | 9bf9abe | 2017-01-09 16:55:21 +0100 | [diff] [blame] | 1682 | } |
| 1683 | |
Karsten Graul | a6688d9 | 2020-04-30 15:55:39 +0200 | [diff] [blame] | 1684 | /* copy received msg and add it to the event queue */ |
| 1685 | static void smc_llc_rx_handler(struct ib_wc *wc, void *buf) |
| 1686 | { |
| 1687 | struct smc_link *link = (struct smc_link *)wc->qp->qp_context; |
| 1688 | union smc_llc_msg *llc = buf; |
| 1689 | |
| 1690 | if (wc->byte_len < sizeof(*llc)) |
| 1691 | return; /* short message */ |
| 1692 | if (llc->raw.hdr.length != sizeof(*llc)) |
| 1693 | return; /* invalid message */ |
| 1694 | |
| 1695 | smc_llc_enqueue(link, llc); |
| 1696 | } |
| 1697 | |
Karsten Graul | 44aa81c | 2018-05-15 17:04:55 +0200 | [diff] [blame] | 1698 | /***************************** worker, utils *********************************/ |
Karsten Graul | 877ae5b | 2018-05-02 16:56:44 +0200 | [diff] [blame] | 1699 | |
| 1700 | static void smc_llc_testlink_work(struct work_struct *work) |
| 1701 | { |
| 1702 | struct smc_link *link = container_of(to_delayed_work(work), |
| 1703 | struct smc_link, llc_testlink_wrk); |
| 1704 | unsigned long next_interval; |
Karsten Graul | 877ae5b | 2018-05-02 16:56:44 +0200 | [diff] [blame] | 1705 | unsigned long expire_time; |
| 1706 | u8 user_data[16] = { 0 }; |
| 1707 | int rc; |
| 1708 | |
Karsten Graul | 741a49a | 2020-07-18 15:06:16 +0200 | [diff] [blame^] | 1709 | if (!smc_link_active(link)) |
Karsten Graul | 877ae5b | 2018-05-02 16:56:44 +0200 | [diff] [blame] | 1710 | return; /* don't reschedule worker */ |
| 1711 | expire_time = link->wr_rx_tstamp + link->llc_testlink_time; |
| 1712 | if (time_is_after_jiffies(expire_time)) { |
| 1713 | next_interval = expire_time - jiffies; |
| 1714 | goto out; |
| 1715 | } |
| 1716 | reinit_completion(&link->llc_testlink_resp); |
Karsten Graul | d97935f | 2018-05-15 17:04:57 +0200 | [diff] [blame] | 1717 | smc_llc_send_test_link(link, user_data); |
Karsten Graul | 877ae5b | 2018-05-02 16:56:44 +0200 | [diff] [blame] | 1718 | /* receive TEST LINK response over RoCE fabric */ |
| 1719 | rc = wait_for_completion_interruptible_timeout(&link->llc_testlink_resp, |
| 1720 | SMC_LLC_WAIT_TIME); |
Karsten Graul | 741a49a | 2020-07-18 15:06:16 +0200 | [diff] [blame^] | 1721 | if (!smc_link_active(link)) |
Karsten Graul | 1020e1e | 2020-04-29 17:10:44 +0200 | [diff] [blame] | 1722 | return; /* link state changed */ |
Karsten Graul | 877ae5b | 2018-05-02 16:56:44 +0200 | [diff] [blame] | 1723 | if (rc <= 0) { |
Karsten Graul | 8752393 | 2020-05-01 12:48:09 +0200 | [diff] [blame] | 1724 | smcr_link_down_cond_sched(link); |
Karsten Graul | 877ae5b | 2018-05-02 16:56:44 +0200 | [diff] [blame] | 1725 | return; |
| 1726 | } |
| 1727 | next_interval = link->llc_testlink_time; |
| 1728 | out: |
Karsten Graul | 1020e1e | 2020-04-29 17:10:44 +0200 | [diff] [blame] | 1729 | schedule_delayed_work(&link->llc_testlink_wrk, next_interval); |
Karsten Graul | 877ae5b | 2018-05-02 16:56:44 +0200 | [diff] [blame] | 1730 | } |
| 1731 | |
Karsten Graul | 00a049c | 2020-04-29 17:10:49 +0200 | [diff] [blame] | 1732 | void smc_llc_lgr_init(struct smc_link_group *lgr, struct smc_sock *smc) |
| 1733 | { |
| 1734 | struct net *net = sock_net(smc->clcsock->sk); |
| 1735 | |
| 1736 | INIT_WORK(&lgr->llc_event_work, smc_llc_event_work); |
Karsten Graul | b45e7f9 | 2020-05-01 12:48:13 +0200 | [diff] [blame] | 1737 | INIT_WORK(&lgr->llc_add_link_work, smc_llc_add_link_work); |
Karsten Graul | 9ec6bf1 | 2020-05-03 14:38:47 +0200 | [diff] [blame] | 1738 | INIT_WORK(&lgr->llc_del_link_work, smc_llc_delete_link_work); |
Karsten Graul | 00a049c | 2020-04-29 17:10:49 +0200 | [diff] [blame] | 1739 | INIT_LIST_HEAD(&lgr->llc_event_q); |
| 1740 | spin_lock_init(&lgr->llc_event_q_lock); |
Karsten Graul | 555da9a | 2020-04-30 15:55:38 +0200 | [diff] [blame] | 1741 | spin_lock_init(&lgr->llc_flow_lock); |
Karsten Graul | 6778a6b | 2020-07-08 17:05:11 +0200 | [diff] [blame] | 1742 | init_waitqueue_head(&lgr->llc_flow_waiter); |
| 1743 | init_waitqueue_head(&lgr->llc_msg_waiter); |
Karsten Graul | d550066 | 2020-05-01 12:48:05 +0200 | [diff] [blame] | 1744 | mutex_init(&lgr->llc_conf_mutex); |
Karsten Graul | 00a049c | 2020-04-29 17:10:49 +0200 | [diff] [blame] | 1745 | lgr->llc_testlink_time = net->ipv4.sysctl_tcp_keepalive_time; |
| 1746 | } |
| 1747 | |
| 1748 | /* called after lgr was removed from lgr_list */ |
| 1749 | void smc_llc_lgr_clear(struct smc_link_group *lgr) |
| 1750 | { |
| 1751 | smc_llc_event_flush(lgr); |
Karsten Graul | 6778a6b | 2020-07-08 17:05:11 +0200 | [diff] [blame] | 1752 | wake_up_all(&lgr->llc_flow_waiter); |
| 1753 | wake_up_all(&lgr->llc_msg_waiter); |
Karsten Graul | 00a049c | 2020-04-29 17:10:49 +0200 | [diff] [blame] | 1754 | cancel_work_sync(&lgr->llc_event_work); |
Karsten Graul | b45e7f9 | 2020-05-01 12:48:13 +0200 | [diff] [blame] | 1755 | cancel_work_sync(&lgr->llc_add_link_work); |
Karsten Graul | 9ec6bf1 | 2020-05-03 14:38:47 +0200 | [diff] [blame] | 1756 | cancel_work_sync(&lgr->llc_del_link_work); |
Karsten Graul | 555da9a | 2020-04-30 15:55:38 +0200 | [diff] [blame] | 1757 | if (lgr->delayed_event) { |
| 1758 | kfree(lgr->delayed_event); |
| 1759 | lgr->delayed_event = NULL; |
| 1760 | } |
Karsten Graul | 00a049c | 2020-04-29 17:10:49 +0200 | [diff] [blame] | 1761 | } |
| 1762 | |
Karsten Graul | 2a4c57a | 2018-05-15 17:04:59 +0200 | [diff] [blame] | 1763 | int smc_llc_link_init(struct smc_link *link) |
Karsten Graul | 877ae5b | 2018-05-02 16:56:44 +0200 | [diff] [blame] | 1764 | { |
| 1765 | init_completion(&link->llc_testlink_resp); |
| 1766 | INIT_DELAYED_WORK(&link->llc_testlink_wrk, smc_llc_testlink_work); |
Karsten Graul | 2a4c57a | 2018-05-15 17:04:59 +0200 | [diff] [blame] | 1767 | return 0; |
Karsten Graul | b32cf4a | 2018-05-15 17:04:58 +0200 | [diff] [blame] | 1768 | } |
| 1769 | |
Karsten Graul | 00a049c | 2020-04-29 17:10:49 +0200 | [diff] [blame] | 1770 | void smc_llc_link_active(struct smc_link *link) |
Karsten Graul | b32cf4a | 2018-05-15 17:04:58 +0200 | [diff] [blame] | 1771 | { |
Karsten Graul | 0a99be4 | 2020-05-05 15:01:20 +0200 | [diff] [blame] | 1772 | pr_warn_ratelimited("smc: SMC-R lg %*phN link added: id %*phN, " |
| 1773 | "peerid %*phN, ibdev %s, ibport %d\n", |
| 1774 | SMC_LGR_ID_SIZE, &link->lgr->id, |
| 1775 | SMC_LGR_ID_SIZE, &link->link_uid, |
| 1776 | SMC_LGR_ID_SIZE, &link->peer_link_uid, |
| 1777 | link->smcibdev->ibdev->name, link->ibport); |
Karsten Graul | 877ae5b | 2018-05-02 16:56:44 +0200 | [diff] [blame] | 1778 | link->state = SMC_LNK_ACTIVE; |
Karsten Graul | 00a049c | 2020-04-29 17:10:49 +0200 | [diff] [blame] | 1779 | if (link->lgr->llc_testlink_time) { |
| 1780 | link->llc_testlink_time = link->lgr->llc_testlink_time * HZ; |
Karsten Graul | 1020e1e | 2020-04-29 17:10:44 +0200 | [diff] [blame] | 1781 | schedule_delayed_work(&link->llc_testlink_wrk, |
| 1782 | link->llc_testlink_time); |
Karsten Graul | 877ae5b | 2018-05-02 16:56:44 +0200 | [diff] [blame] | 1783 | } |
| 1784 | } |
| 1785 | |
Karsten Graul | 877ae5b | 2018-05-02 16:56:44 +0200 | [diff] [blame] | 1786 | /* called in worker context */ |
Karsten Graul | 0a99be4 | 2020-05-05 15:01:20 +0200 | [diff] [blame] | 1787 | void smc_llc_link_clear(struct smc_link *link, bool log) |
Karsten Graul | 877ae5b | 2018-05-02 16:56:44 +0200 | [diff] [blame] | 1788 | { |
Karsten Graul | 0a99be4 | 2020-05-05 15:01:20 +0200 | [diff] [blame] | 1789 | if (log) |
| 1790 | pr_warn_ratelimited("smc: SMC-R lg %*phN link removed: id %*phN" |
| 1791 | ", peerid %*phN, ibdev %s, ibport %d\n", |
| 1792 | SMC_LGR_ID_SIZE, &link->lgr->id, |
| 1793 | SMC_LGR_ID_SIZE, &link->link_uid, |
| 1794 | SMC_LGR_ID_SIZE, &link->peer_link_uid, |
| 1795 | link->smcibdev->ibdev->name, link->ibport); |
Karsten Graul | 2140ac2 | 2020-04-29 17:10:45 +0200 | [diff] [blame] | 1796 | complete(&link->llc_testlink_resp); |
| 1797 | cancel_delayed_work_sync(&link->llc_testlink_wrk); |
| 1798 | smc_wr_wakeup_reg_wait(link); |
| 1799 | smc_wr_wakeup_tx_wait(link); |
Karsten Graul | 877ae5b | 2018-05-02 16:56:44 +0200 | [diff] [blame] | 1800 | } |
| 1801 | |
Karsten Graul | 3d88a21 | 2020-04-30 15:55:44 +0200 | [diff] [blame] | 1802 | /* register a new rtoken at the remote peer (for all links) */ |
| 1803 | int smc_llc_do_confirm_rkey(struct smc_link *send_link, |
Karsten Graul | 44aa81c | 2018-05-15 17:04:55 +0200 | [diff] [blame] | 1804 | struct smc_buf_desc *rmb_desc) |
| 1805 | { |
Karsten Graul | 3d88a21 | 2020-04-30 15:55:44 +0200 | [diff] [blame] | 1806 | struct smc_link_group *lgr = send_link->lgr; |
| 1807 | struct smc_llc_qentry *qentry = NULL; |
| 1808 | int rc = 0; |
Karsten Graul | 44aa81c | 2018-05-15 17:04:55 +0200 | [diff] [blame] | 1809 | |
Karsten Graul | 3d88a21 | 2020-04-30 15:55:44 +0200 | [diff] [blame] | 1810 | rc = smc_llc_send_confirm_rkey(send_link, rmb_desc); |
| 1811 | if (rc) |
| 1812 | goto out; |
Karsten Graul | 44aa81c | 2018-05-15 17:04:55 +0200 | [diff] [blame] | 1813 | /* receive CONFIRM RKEY response from server over RoCE fabric */ |
Karsten Graul | 3d88a21 | 2020-04-30 15:55:44 +0200 | [diff] [blame] | 1814 | qentry = smc_llc_wait(lgr, send_link, SMC_LLC_WAIT_TIME, |
| 1815 | SMC_LLC_CONFIRM_RKEY); |
| 1816 | if (!qentry || (qentry->msg.raw.hdr.flags & SMC_LLC_FLAG_RKEY_NEG)) |
| 1817 | rc = -EFAULT; |
| 1818 | out: |
| 1819 | if (qentry) |
| 1820 | smc_llc_flow_qentry_del(&lgr->llc_flow_lcl); |
Karsten Graul | 3d88a21 | 2020-04-30 15:55:44 +0200 | [diff] [blame] | 1821 | return rc; |
Karsten Graul | 44aa81c | 2018-05-15 17:04:55 +0200 | [diff] [blame] | 1822 | } |
| 1823 | |
Karsten Graul | 60e03c6 | 2018-11-22 10:26:42 +0100 | [diff] [blame] | 1824 | /* unregister an rtoken at the remote peer */ |
Karsten Graul | 6d74c3a | 2020-04-30 15:55:45 +0200 | [diff] [blame] | 1825 | int smc_llc_do_delete_rkey(struct smc_link_group *lgr, |
Karsten Graul | 60e03c6 | 2018-11-22 10:26:42 +0100 | [diff] [blame] | 1826 | struct smc_buf_desc *rmb_desc) |
| 1827 | { |
Karsten Graul | 6d74c3a | 2020-04-30 15:55:45 +0200 | [diff] [blame] | 1828 | struct smc_llc_qentry *qentry = NULL; |
| 1829 | struct smc_link *send_link; |
Ursula Braun | 0b29ec6 | 2019-11-14 13:02:47 +0100 | [diff] [blame] | 1830 | int rc = 0; |
Karsten Graul | 60e03c6 | 2018-11-22 10:26:42 +0100 | [diff] [blame] | 1831 | |
Karsten Graul | 6d74c3a | 2020-04-30 15:55:45 +0200 | [diff] [blame] | 1832 | send_link = smc_llc_usable_link(lgr); |
| 1833 | if (!send_link) |
| 1834 | return -ENOLINK; |
| 1835 | |
Karsten Graul | 6d74c3a | 2020-04-30 15:55:45 +0200 | [diff] [blame] | 1836 | /* protected by llc_flow control */ |
| 1837 | rc = smc_llc_send_delete_rkey(send_link, rmb_desc); |
Karsten Graul | 60e03c6 | 2018-11-22 10:26:42 +0100 | [diff] [blame] | 1838 | if (rc) |
| 1839 | goto out; |
| 1840 | /* receive DELETE RKEY response from server over RoCE fabric */ |
Karsten Graul | 6d74c3a | 2020-04-30 15:55:45 +0200 | [diff] [blame] | 1841 | qentry = smc_llc_wait(lgr, send_link, SMC_LLC_WAIT_TIME, |
| 1842 | SMC_LLC_DELETE_RKEY); |
| 1843 | if (!qentry || (qentry->msg.raw.hdr.flags & SMC_LLC_FLAG_RKEY_NEG)) |
Karsten Graul | 60e03c6 | 2018-11-22 10:26:42 +0100 | [diff] [blame] | 1844 | rc = -EFAULT; |
Karsten Graul | 60e03c6 | 2018-11-22 10:26:42 +0100 | [diff] [blame] | 1845 | out: |
Karsten Graul | 6d74c3a | 2020-04-30 15:55:45 +0200 | [diff] [blame] | 1846 | if (qentry) |
| 1847 | smc_llc_flow_qentry_del(&lgr->llc_flow_lcl); |
Karsten Graul | 60e03c6 | 2018-11-22 10:26:42 +0100 | [diff] [blame] | 1848 | return rc; |
| 1849 | } |
| 1850 | |
Karsten Graul | 45fa8da | 2020-05-04 14:18:47 +0200 | [diff] [blame] | 1851 | void smc_llc_link_set_uid(struct smc_link *link) |
| 1852 | { |
| 1853 | __be32 link_uid; |
| 1854 | |
| 1855 | link_uid = htonl(*((u32 *)link->lgr->id) + link->link_id); |
| 1856 | memcpy(link->link_uid, &link_uid, SMC_LGR_ID_SIZE); |
| 1857 | } |
| 1858 | |
Karsten Graul | 649758f | 2020-05-04 14:18:48 +0200 | [diff] [blame] | 1859 | /* save peers link user id, used for debug purposes */ |
| 1860 | void smc_llc_save_peer_uid(struct smc_llc_qentry *qentry) |
| 1861 | { |
| 1862 | memcpy(qentry->link->peer_link_uid, qentry->msg.confirm_link.link_uid, |
| 1863 | SMC_LGR_ID_SIZE); |
| 1864 | } |
| 1865 | |
Karsten Graul | 92334cf | 2020-04-30 15:55:41 +0200 | [diff] [blame] | 1866 | /* evaluate confirm link request or response */ |
| 1867 | int smc_llc_eval_conf_link(struct smc_llc_qentry *qentry, |
| 1868 | enum smc_llc_reqresp type) |
| 1869 | { |
Karsten Graul | 45fa8da | 2020-05-04 14:18:47 +0200 | [diff] [blame] | 1870 | if (type == SMC_LLC_REQ) { /* SMC server assigns link_id */ |
Karsten Graul | 92334cf | 2020-04-30 15:55:41 +0200 | [diff] [blame] | 1871 | qentry->link->link_id = qentry->msg.confirm_link.link_num; |
Karsten Graul | 45fa8da | 2020-05-04 14:18:47 +0200 | [diff] [blame] | 1872 | smc_llc_link_set_uid(qentry->link); |
| 1873 | } |
Karsten Graul | 92334cf | 2020-04-30 15:55:41 +0200 | [diff] [blame] | 1874 | if (!(qentry->msg.raw.hdr.flags & SMC_LLC_FLAG_NO_RMBE_EYEC)) |
| 1875 | return -ENOTSUPP; |
| 1876 | return 0; |
| 1877 | } |
| 1878 | |
Ursula Braun | 9bf9abe | 2017-01-09 16:55:21 +0100 | [diff] [blame] | 1879 | /***************************** init, exit, misc ******************************/ |
| 1880 | |
| 1881 | static struct smc_wr_rx_handler smc_llc_rx_handlers[] = { |
| 1882 | { |
| 1883 | .handler = smc_llc_rx_handler, |
| 1884 | .type = SMC_LLC_CONFIRM_LINK |
| 1885 | }, |
| 1886 | { |
Karsten Graul | 313164d | 2018-03-01 13:51:29 +0100 | [diff] [blame] | 1887 | .handler = smc_llc_rx_handler, |
| 1888 | .type = SMC_LLC_TEST_LINK |
| 1889 | }, |
| 1890 | { |
Karsten Graul | 4ed75de | 2018-03-01 13:51:30 +0100 | [diff] [blame] | 1891 | .handler = smc_llc_rx_handler, |
Karsten Graul | 52bedf3 | 2018-03-01 13:51:32 +0100 | [diff] [blame] | 1892 | .type = SMC_LLC_ADD_LINK |
| 1893 | }, |
| 1894 | { |
| 1895 | .handler = smc_llc_rx_handler, |
Karsten Graul | 87f88cd | 2020-05-03 14:38:41 +0200 | [diff] [blame] | 1896 | .type = SMC_LLC_ADD_LINK_CONT |
| 1897 | }, |
| 1898 | { |
| 1899 | .handler = smc_llc_rx_handler, |
Karsten Graul | 52bedf3 | 2018-03-01 13:51:32 +0100 | [diff] [blame] | 1900 | .type = SMC_LLC_DELETE_LINK |
| 1901 | }, |
| 1902 | { |
| 1903 | .handler = smc_llc_rx_handler, |
Karsten Graul | 4ed75de | 2018-03-01 13:51:30 +0100 | [diff] [blame] | 1904 | .type = SMC_LLC_CONFIRM_RKEY |
| 1905 | }, |
| 1906 | { |
| 1907 | .handler = smc_llc_rx_handler, |
| 1908 | .type = SMC_LLC_CONFIRM_RKEY_CONT |
| 1909 | }, |
| 1910 | { |
| 1911 | .handler = smc_llc_rx_handler, |
| 1912 | .type = SMC_LLC_DELETE_RKEY |
| 1913 | }, |
| 1914 | { |
Ursula Braun | 9bf9abe | 2017-01-09 16:55:21 +0100 | [diff] [blame] | 1915 | .handler = NULL, |
| 1916 | } |
| 1917 | }; |
| 1918 | |
| 1919 | int __init smc_llc_init(void) |
| 1920 | { |
| 1921 | struct smc_wr_rx_handler *handler; |
| 1922 | int rc = 0; |
| 1923 | |
| 1924 | for (handler = smc_llc_rx_handlers; handler->handler; handler++) { |
| 1925 | INIT_HLIST_NODE(&handler->list); |
| 1926 | rc = smc_wr_rx_register_handler(handler); |
| 1927 | if (rc) |
| 1928 | break; |
| 1929 | } |
| 1930 | return rc; |
| 1931 | } |