Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 2 | /* |
| 3 | * Shared Memory Communications over RDMA (SMC-R) and RoCE |
| 4 | * |
| 5 | * CLC (connection layer control) handshake over initial TCP socket to |
| 6 | * prepare for RDMA traffic |
| 7 | * |
| 8 | * Copyright IBM Corp. 2016 |
| 9 | * |
| 10 | * Author(s): Ursula Braun <ubraun@linux.vnet.ibm.com> |
| 11 | */ |
| 12 | |
| 13 | #include <linux/in.h> |
Ursula Braun | 143c017 | 2017-01-12 14:57:15 +0100 | [diff] [blame] | 14 | #include <linux/if_ether.h> |
Ingo Molnar | c3edc40 | 2017-02-02 08:35:14 +0100 | [diff] [blame] | 15 | #include <linux/sched/signal.h> |
| 16 | |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 17 | #include <net/sock.h> |
| 18 | #include <net/tcp.h> |
| 19 | |
| 20 | #include "smc.h" |
Ursula Braun | 0cfdd8f | 2017-01-09 16:55:17 +0100 | [diff] [blame] | 21 | #include "smc_core.h" |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 22 | #include "smc_clc.h" |
| 23 | #include "smc_ib.h" |
| 24 | |
Stefan Raspl | 0f62712 | 2018-03-01 13:51:26 +0100 | [diff] [blame^] | 25 | /* eye catcher "SMCR" EBCDIC for CLC messages */ |
| 26 | static const char SMC_EYECATCHER[4] = {'\xe2', '\xd4', '\xc3', '\xd9'}; |
| 27 | |
Ursula Braun | e7b7a64 | 2017-12-07 13:38:49 +0100 | [diff] [blame] | 28 | /* check if received message has a correct header length and contains valid |
| 29 | * heading and trailing eyecatchers |
| 30 | */ |
| 31 | static bool smc_clc_msg_hdr_valid(struct smc_clc_msg_hdr *clcm) |
| 32 | { |
| 33 | struct smc_clc_msg_proposal_prefix *pclc_prfx; |
| 34 | struct smc_clc_msg_accept_confirm *clc; |
| 35 | struct smc_clc_msg_proposal *pclc; |
| 36 | struct smc_clc_msg_decline *dclc; |
| 37 | struct smc_clc_msg_trail *trl; |
| 38 | |
| 39 | if (memcmp(clcm->eyecatcher, SMC_EYECATCHER, sizeof(SMC_EYECATCHER))) |
| 40 | return false; |
| 41 | switch (clcm->type) { |
| 42 | case SMC_CLC_PROPOSAL: |
| 43 | pclc = (struct smc_clc_msg_proposal *)clcm; |
| 44 | pclc_prfx = smc_clc_proposal_get_prefix(pclc); |
| 45 | if (ntohs(pclc->hdr.length) != |
| 46 | sizeof(*pclc) + ntohs(pclc->iparea_offset) + |
| 47 | sizeof(*pclc_prfx) + |
| 48 | pclc_prfx->ipv6_prefixes_cnt * |
| 49 | sizeof(struct smc_clc_ipv6_prefix) + |
| 50 | sizeof(*trl)) |
| 51 | return false; |
| 52 | trl = (struct smc_clc_msg_trail *) |
| 53 | ((u8 *)pclc + ntohs(pclc->hdr.length) - sizeof(*trl)); |
| 54 | break; |
| 55 | case SMC_CLC_ACCEPT: |
| 56 | case SMC_CLC_CONFIRM: |
| 57 | clc = (struct smc_clc_msg_accept_confirm *)clcm; |
| 58 | if (ntohs(clc->hdr.length) != sizeof(*clc)) |
| 59 | return false; |
| 60 | trl = &clc->trl; |
| 61 | break; |
| 62 | case SMC_CLC_DECLINE: |
| 63 | dclc = (struct smc_clc_msg_decline *)clcm; |
| 64 | if (ntohs(dclc->hdr.length) != sizeof(*dclc)) |
| 65 | return false; |
| 66 | trl = &dclc->trl; |
| 67 | break; |
| 68 | default: |
| 69 | return false; |
| 70 | } |
| 71 | if (memcmp(trl->eyecatcher, SMC_EYECATCHER, sizeof(SMC_EYECATCHER))) |
| 72 | return false; |
| 73 | return true; |
| 74 | } |
| 75 | |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 76 | /* Wait for data on the tcp-socket, analyze received data |
| 77 | * Returns: |
| 78 | * 0 if success and it was not a decline that we received. |
| 79 | * SMC_CLC_DECL_REPLY if decline received for fallback w/o another decl send. |
| 80 | * clcsock error, -EINTR, -ECONNRESET, -EPROTO otherwise. |
| 81 | */ |
| 82 | int smc_clc_wait_msg(struct smc_sock *smc, void *buf, int buflen, |
| 83 | u8 expected_type) |
| 84 | { |
| 85 | struct sock *clc_sk = smc->clcsock->sk; |
| 86 | struct smc_clc_msg_hdr *clcm = buf; |
| 87 | struct msghdr msg = {NULL, 0}; |
| 88 | int reason_code = 0; |
Al Viro | d63d271 | 2017-09-20 20:21:22 -0400 | [diff] [blame] | 89 | struct kvec vec = {buf, buflen}; |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 90 | int len, datlen; |
| 91 | int krflags; |
| 92 | |
| 93 | /* peek the first few bytes to determine length of data to receive |
| 94 | * so we don't consume any subsequent CLC message or payload data |
| 95 | * in the TCP byte stream |
| 96 | */ |
Al Viro | d63d271 | 2017-09-20 20:21:22 -0400 | [diff] [blame] | 97 | /* |
| 98 | * Caller must make sure that buflen is no less than |
| 99 | * sizeof(struct smc_clc_msg_hdr) |
| 100 | */ |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 101 | krflags = MSG_PEEK | MSG_WAITALL; |
| 102 | smc->clcsock->sk->sk_rcvtimeo = CLC_WAIT_TIME; |
Al Viro | d63d271 | 2017-09-20 20:21:22 -0400 | [diff] [blame] | 103 | iov_iter_kvec(&msg.msg_iter, READ | ITER_KVEC, &vec, 1, |
| 104 | sizeof(struct smc_clc_msg_hdr)); |
| 105 | len = sock_recvmsg(smc->clcsock, &msg, krflags); |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 106 | if (signal_pending(current)) { |
| 107 | reason_code = -EINTR; |
| 108 | clc_sk->sk_err = EINTR; |
| 109 | smc->sk.sk_err = EINTR; |
| 110 | goto out; |
| 111 | } |
| 112 | if (clc_sk->sk_err) { |
| 113 | reason_code = -clc_sk->sk_err; |
| 114 | smc->sk.sk_err = clc_sk->sk_err; |
| 115 | goto out; |
| 116 | } |
| 117 | if (!len) { /* peer has performed orderly shutdown */ |
| 118 | smc->sk.sk_err = ECONNRESET; |
| 119 | reason_code = -ECONNRESET; |
| 120 | goto out; |
| 121 | } |
| 122 | if (len < 0) { |
| 123 | smc->sk.sk_err = -len; |
| 124 | reason_code = len; |
| 125 | goto out; |
| 126 | } |
| 127 | datlen = ntohs(clcm->length); |
| 128 | if ((len < sizeof(struct smc_clc_msg_hdr)) || |
Ursula Braun | e7b7a64 | 2017-12-07 13:38:49 +0100 | [diff] [blame] | 129 | (datlen > buflen) || |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 130 | ((clcm->type != SMC_CLC_DECLINE) && |
| 131 | (clcm->type != expected_type))) { |
| 132 | smc->sk.sk_err = EPROTO; |
| 133 | reason_code = -EPROTO; |
| 134 | goto out; |
| 135 | } |
| 136 | |
| 137 | /* receive the complete CLC message */ |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 138 | memset(&msg, 0, sizeof(struct msghdr)); |
Al Viro | d63d271 | 2017-09-20 20:21:22 -0400 | [diff] [blame] | 139 | iov_iter_kvec(&msg.msg_iter, READ | ITER_KVEC, &vec, 1, buflen); |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 140 | krflags = MSG_WAITALL; |
| 141 | smc->clcsock->sk->sk_rcvtimeo = CLC_WAIT_TIME; |
Al Viro | d63d271 | 2017-09-20 20:21:22 -0400 | [diff] [blame] | 142 | len = sock_recvmsg(smc->clcsock, &msg, krflags); |
Ursula Braun | e7b7a64 | 2017-12-07 13:38:49 +0100 | [diff] [blame] | 143 | if (len < datlen || !smc_clc_msg_hdr_valid(clcm)) { |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 144 | smc->sk.sk_err = EPROTO; |
| 145 | reason_code = -EPROTO; |
| 146 | goto out; |
| 147 | } |
Ursula Braun | 0cfdd8f | 2017-01-09 16:55:17 +0100 | [diff] [blame] | 148 | if (clcm->type == SMC_CLC_DECLINE) { |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 149 | reason_code = SMC_CLC_DECL_REPLY; |
Ursula Braun | bfbedfd | 2017-09-21 09:16:32 +0200 | [diff] [blame] | 150 | if (((struct smc_clc_msg_decline *)buf)->hdr.flag) { |
Ursula Braun | 0cfdd8f | 2017-01-09 16:55:17 +0100 | [diff] [blame] | 151 | smc->conn.lgr->sync_err = true; |
Ursula Braun | bfbedfd | 2017-09-21 09:16:32 +0200 | [diff] [blame] | 152 | smc_lgr_terminate(smc->conn.lgr); |
| 153 | } |
Ursula Braun | 0cfdd8f | 2017-01-09 16:55:17 +0100 | [diff] [blame] | 154 | } |
| 155 | |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 156 | out: |
| 157 | return reason_code; |
| 158 | } |
| 159 | |
| 160 | /* send CLC DECLINE message across internal TCP socket */ |
Ursula Braun | bfbedfd | 2017-09-21 09:16:32 +0200 | [diff] [blame] | 161 | int smc_clc_send_decline(struct smc_sock *smc, u32 peer_diag_info) |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 162 | { |
| 163 | struct smc_clc_msg_decline dclc; |
| 164 | struct msghdr msg; |
| 165 | struct kvec vec; |
| 166 | int len; |
| 167 | |
| 168 | memset(&dclc, 0, sizeof(dclc)); |
| 169 | memcpy(dclc.hdr.eyecatcher, SMC_EYECATCHER, sizeof(SMC_EYECATCHER)); |
| 170 | dclc.hdr.type = SMC_CLC_DECLINE; |
| 171 | dclc.hdr.length = htons(sizeof(struct smc_clc_msg_decline)); |
| 172 | dclc.hdr.version = SMC_CLC_V1; |
Ursula Braun | bfbedfd | 2017-09-21 09:16:32 +0200 | [diff] [blame] | 173 | dclc.hdr.flag = (peer_diag_info == SMC_CLC_DECL_SYNCERR) ? 1 : 0; |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 174 | memcpy(dclc.id_for_peer, local_systemid, sizeof(local_systemid)); |
| 175 | dclc.peer_diagnosis = htonl(peer_diag_info); |
| 176 | memcpy(dclc.trl.eyecatcher, SMC_EYECATCHER, sizeof(SMC_EYECATCHER)); |
| 177 | |
| 178 | memset(&msg, 0, sizeof(msg)); |
| 179 | vec.iov_base = &dclc; |
| 180 | vec.iov_len = sizeof(struct smc_clc_msg_decline); |
| 181 | len = kernel_sendmsg(smc->clcsock, &msg, &vec, 1, |
| 182 | sizeof(struct smc_clc_msg_decline)); |
| 183 | if (len < sizeof(struct smc_clc_msg_decline)) |
| 184 | smc->sk.sk_err = EPROTO; |
| 185 | if (len < 0) |
| 186 | smc->sk.sk_err = -len; |
Ursula Braun | 0c9f151 | 2017-12-07 13:38:45 +0100 | [diff] [blame] | 187 | return sock_error(&smc->sk); |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 188 | } |
| 189 | |
| 190 | /* send CLC PROPOSAL message across internal TCP socket */ |
| 191 | int smc_clc_send_proposal(struct smc_sock *smc, |
| 192 | struct smc_ib_device *smcibdev, |
| 193 | u8 ibport) |
| 194 | { |
Ursula Braun | e7b7a64 | 2017-12-07 13:38:49 +0100 | [diff] [blame] | 195 | struct smc_clc_msg_proposal_prefix pclc_prfx; |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 196 | struct smc_clc_msg_proposal pclc; |
Ursula Braun | e7b7a64 | 2017-12-07 13:38:49 +0100 | [diff] [blame] | 197 | struct smc_clc_msg_trail trl; |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 198 | int reason_code = 0; |
Ursula Braun | e7b7a64 | 2017-12-07 13:38:49 +0100 | [diff] [blame] | 199 | struct kvec vec[3]; |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 200 | struct msghdr msg; |
Ursula Braun | e7b7a64 | 2017-12-07 13:38:49 +0100 | [diff] [blame] | 201 | int len, plen, rc; |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 202 | |
| 203 | /* send SMC Proposal CLC message */ |
Ursula Braun | e7b7a64 | 2017-12-07 13:38:49 +0100 | [diff] [blame] | 204 | plen = sizeof(pclc) + sizeof(pclc_prfx) + sizeof(trl); |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 205 | memset(&pclc, 0, sizeof(pclc)); |
| 206 | memcpy(pclc.hdr.eyecatcher, SMC_EYECATCHER, sizeof(SMC_EYECATCHER)); |
| 207 | pclc.hdr.type = SMC_CLC_PROPOSAL; |
Ursula Braun | e7b7a64 | 2017-12-07 13:38:49 +0100 | [diff] [blame] | 208 | pclc.hdr.length = htons(plen); |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 209 | pclc.hdr.version = SMC_CLC_V1; /* SMC version */ |
| 210 | memcpy(pclc.lcl.id_for_peer, local_systemid, sizeof(local_systemid)); |
| 211 | memcpy(&pclc.lcl.gid, &smcibdev->gid[ibport - 1], SMC_GID_SIZE); |
Ursula Braun | 143c017 | 2017-01-12 14:57:15 +0100 | [diff] [blame] | 212 | memcpy(&pclc.lcl.mac, &smcibdev->mac[ibport - 1], ETH_ALEN); |
Ursula Braun | e7b7a64 | 2017-12-07 13:38:49 +0100 | [diff] [blame] | 213 | pclc.iparea_offset = htons(0); |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 214 | |
Ursula Braun | e7b7a64 | 2017-12-07 13:38:49 +0100 | [diff] [blame] | 215 | memset(&pclc_prfx, 0, sizeof(pclc_prfx)); |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 216 | /* determine subnet and mask from internal TCP socket */ |
Ursula Braun | e7b7a64 | 2017-12-07 13:38:49 +0100 | [diff] [blame] | 217 | rc = smc_netinfo_by_tcpsk(smc->clcsock, &pclc_prfx.outgoing_subnet, |
| 218 | &pclc_prfx.prefix_len); |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 219 | if (rc) |
| 220 | return SMC_CLC_DECL_CNFERR; /* configuration error */ |
Ursula Braun | e7b7a64 | 2017-12-07 13:38:49 +0100 | [diff] [blame] | 221 | pclc_prfx.ipv6_prefixes_cnt = 0; |
| 222 | memcpy(trl.eyecatcher, SMC_EYECATCHER, sizeof(SMC_EYECATCHER)); |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 223 | memset(&msg, 0, sizeof(msg)); |
Ursula Braun | e7b7a64 | 2017-12-07 13:38:49 +0100 | [diff] [blame] | 224 | vec[0].iov_base = &pclc; |
| 225 | vec[0].iov_len = sizeof(pclc); |
| 226 | vec[1].iov_base = &pclc_prfx; |
| 227 | vec[1].iov_len = sizeof(pclc_prfx); |
| 228 | vec[2].iov_base = &trl; |
| 229 | vec[2].iov_len = sizeof(trl); |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 230 | /* due to the few bytes needed for clc-handshake this cannot block */ |
Ursula Braun | e7b7a64 | 2017-12-07 13:38:49 +0100 | [diff] [blame] | 231 | len = kernel_sendmsg(smc->clcsock, &msg, vec, 3, plen); |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 232 | if (len < sizeof(pclc)) { |
| 233 | if (len >= 0) { |
| 234 | reason_code = -ENETUNREACH; |
| 235 | smc->sk.sk_err = -reason_code; |
| 236 | } else { |
| 237 | smc->sk.sk_err = smc->clcsock->sk->sk_err; |
| 238 | reason_code = -smc->sk.sk_err; |
| 239 | } |
| 240 | } |
| 241 | |
| 242 | return reason_code; |
| 243 | } |
| 244 | |
| 245 | /* send CLC CONFIRM message across internal TCP socket */ |
| 246 | int smc_clc_send_confirm(struct smc_sock *smc) |
| 247 | { |
Ursula Braun | 0cfdd8f | 2017-01-09 16:55:17 +0100 | [diff] [blame] | 248 | struct smc_connection *conn = &smc->conn; |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 249 | struct smc_clc_msg_accept_confirm cclc; |
Ursula Braun | 0cfdd8f | 2017-01-09 16:55:17 +0100 | [diff] [blame] | 250 | struct smc_link *link; |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 251 | int reason_code = 0; |
| 252 | struct msghdr msg; |
| 253 | struct kvec vec; |
| 254 | int len; |
| 255 | |
Ursula Braun | 0cfdd8f | 2017-01-09 16:55:17 +0100 | [diff] [blame] | 256 | link = &conn->lgr->lnk[SMC_SINGLE_LINK]; |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 257 | /* send SMC Confirm CLC msg */ |
| 258 | memset(&cclc, 0, sizeof(cclc)); |
| 259 | memcpy(cclc.hdr.eyecatcher, SMC_EYECATCHER, sizeof(SMC_EYECATCHER)); |
| 260 | cclc.hdr.type = SMC_CLC_CONFIRM; |
| 261 | cclc.hdr.length = htons(sizeof(cclc)); |
| 262 | cclc.hdr.version = SMC_CLC_V1; /* SMC version */ |
| 263 | memcpy(cclc.lcl.id_for_peer, local_systemid, sizeof(local_systemid)); |
Ursula Braun | 0cfdd8f | 2017-01-09 16:55:17 +0100 | [diff] [blame] | 264 | memcpy(&cclc.lcl.gid, &link->smcibdev->gid[link->ibport - 1], |
| 265 | SMC_GID_SIZE); |
Ursula Braun | 143c017 | 2017-01-12 14:57:15 +0100 | [diff] [blame] | 266 | memcpy(&cclc.lcl.mac, &link->smcibdev->mac[link->ibport - 1], ETH_ALEN); |
Ursula Braun | 0cfdd8f | 2017-01-09 16:55:17 +0100 | [diff] [blame] | 267 | hton24(cclc.qpn, link->roce_qp->qp_num); |
Ursula Braun | bd4ad57 | 2017-01-09 16:55:20 +0100 | [diff] [blame] | 268 | cclc.rmb_rkey = |
Ursula Braun | 897e1c2 | 2017-07-28 13:56:16 +0200 | [diff] [blame] | 269 | htonl(conn->rmb_desc->mr_rx[SMC_SINGLE_LINK]->rkey); |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 270 | cclc.conn_idx = 1; /* for now: 1 RMB = 1 RMBE */ |
Ursula Braun | 0cfdd8f | 2017-01-09 16:55:17 +0100 | [diff] [blame] | 271 | cclc.rmbe_alert_token = htonl(conn->alert_token_local); |
| 272 | cclc.qp_mtu = min(link->path_mtu, link->peer_mtu); |
Ursula Braun | bd4ad57 | 2017-01-09 16:55:20 +0100 | [diff] [blame] | 273 | cclc.rmbe_size = conn->rmbe_size_short; |
Ursula Braun | a3fe3d0 | 2017-07-28 13:56:15 +0200 | [diff] [blame] | 274 | cclc.rmb_dma_addr = cpu_to_be64( |
| 275 | (u64)sg_dma_address(conn->rmb_desc->sgt[SMC_SINGLE_LINK].sgl)); |
Ursula Braun | 0cfdd8f | 2017-01-09 16:55:17 +0100 | [diff] [blame] | 276 | hton24(cclc.psn, link->psn_initial); |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 277 | |
| 278 | memcpy(cclc.trl.eyecatcher, SMC_EYECATCHER, sizeof(SMC_EYECATCHER)); |
| 279 | |
| 280 | memset(&msg, 0, sizeof(msg)); |
| 281 | vec.iov_base = &cclc; |
| 282 | vec.iov_len = sizeof(cclc); |
| 283 | len = kernel_sendmsg(smc->clcsock, &msg, &vec, 1, sizeof(cclc)); |
| 284 | if (len < sizeof(cclc)) { |
| 285 | if (len >= 0) { |
| 286 | reason_code = -ENETUNREACH; |
| 287 | smc->sk.sk_err = -reason_code; |
| 288 | } else { |
| 289 | smc->sk.sk_err = smc->clcsock->sk->sk_err; |
| 290 | reason_code = -smc->sk.sk_err; |
| 291 | } |
| 292 | } |
| 293 | return reason_code; |
| 294 | } |
| 295 | |
| 296 | /* send CLC ACCEPT message across internal TCP socket */ |
Ursula Braun | 0cfdd8f | 2017-01-09 16:55:17 +0100 | [diff] [blame] | 297 | int smc_clc_send_accept(struct smc_sock *new_smc, int srv_first_contact) |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 298 | { |
Ursula Braun | 0cfdd8f | 2017-01-09 16:55:17 +0100 | [diff] [blame] | 299 | struct smc_connection *conn = &new_smc->conn; |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 300 | struct smc_clc_msg_accept_confirm aclc; |
Ursula Braun | 0cfdd8f | 2017-01-09 16:55:17 +0100 | [diff] [blame] | 301 | struct smc_link *link; |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 302 | struct msghdr msg; |
| 303 | struct kvec vec; |
| 304 | int rc = 0; |
| 305 | int len; |
| 306 | |
Ursula Braun | 0cfdd8f | 2017-01-09 16:55:17 +0100 | [diff] [blame] | 307 | link = &conn->lgr->lnk[SMC_SINGLE_LINK]; |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 308 | memset(&aclc, 0, sizeof(aclc)); |
| 309 | memcpy(aclc.hdr.eyecatcher, SMC_EYECATCHER, sizeof(SMC_EYECATCHER)); |
| 310 | aclc.hdr.type = SMC_CLC_ACCEPT; |
| 311 | aclc.hdr.length = htons(sizeof(aclc)); |
| 312 | aclc.hdr.version = SMC_CLC_V1; /* SMC version */ |
Ursula Braun | 0cfdd8f | 2017-01-09 16:55:17 +0100 | [diff] [blame] | 313 | if (srv_first_contact) |
| 314 | aclc.hdr.flag = 1; |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 315 | memcpy(aclc.lcl.id_for_peer, local_systemid, sizeof(local_systemid)); |
Ursula Braun | 0cfdd8f | 2017-01-09 16:55:17 +0100 | [diff] [blame] | 316 | memcpy(&aclc.lcl.gid, &link->smcibdev->gid[link->ibport - 1], |
| 317 | SMC_GID_SIZE); |
Ursula Braun | 143c017 | 2017-01-12 14:57:15 +0100 | [diff] [blame] | 318 | memcpy(&aclc.lcl.mac, link->smcibdev->mac[link->ibport - 1], ETH_ALEN); |
Ursula Braun | 0cfdd8f | 2017-01-09 16:55:17 +0100 | [diff] [blame] | 319 | hton24(aclc.qpn, link->roce_qp->qp_num); |
Ursula Braun | bd4ad57 | 2017-01-09 16:55:20 +0100 | [diff] [blame] | 320 | aclc.rmb_rkey = |
Ursula Braun | 897e1c2 | 2017-07-28 13:56:16 +0200 | [diff] [blame] | 321 | htonl(conn->rmb_desc->mr_rx[SMC_SINGLE_LINK]->rkey); |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 322 | aclc.conn_idx = 1; /* as long as 1 RMB = 1 RMBE */ |
Ursula Braun | 0cfdd8f | 2017-01-09 16:55:17 +0100 | [diff] [blame] | 323 | aclc.rmbe_alert_token = htonl(conn->alert_token_local); |
| 324 | aclc.qp_mtu = link->path_mtu; |
Ursula Braun | cd6851f | 2017-01-09 16:55:18 +0100 | [diff] [blame] | 325 | aclc.rmbe_size = conn->rmbe_size_short, |
Ursula Braun | a3fe3d0 | 2017-07-28 13:56:15 +0200 | [diff] [blame] | 326 | aclc.rmb_dma_addr = cpu_to_be64( |
| 327 | (u64)sg_dma_address(conn->rmb_desc->sgt[SMC_SINGLE_LINK].sgl)); |
Ursula Braun | 0cfdd8f | 2017-01-09 16:55:17 +0100 | [diff] [blame] | 328 | hton24(aclc.psn, link->psn_initial); |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 329 | memcpy(aclc.trl.eyecatcher, SMC_EYECATCHER, sizeof(SMC_EYECATCHER)); |
| 330 | |
| 331 | memset(&msg, 0, sizeof(msg)); |
| 332 | vec.iov_base = &aclc; |
| 333 | vec.iov_len = sizeof(aclc); |
| 334 | len = kernel_sendmsg(new_smc->clcsock, &msg, &vec, 1, sizeof(aclc)); |
| 335 | if (len < sizeof(aclc)) { |
| 336 | if (len >= 0) |
| 337 | new_smc->sk.sk_err = EPROTO; |
| 338 | else |
| 339 | new_smc->sk.sk_err = new_smc->clcsock->sk->sk_err; |
| 340 | rc = sock_error(&new_smc->sk); |
| 341 | } |
| 342 | |
| 343 | return rc; |
| 344 | } |