Thomas Gleixner | 09c434b | 2019-05-19 13:08:20 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Ursula Braun | ac71387 | 2017-01-09 16:55:13 +0100 | [diff] [blame] | 2 | /* |
| 3 | * Shared Memory Communications over RDMA (SMC-R) and RoCE |
| 4 | * |
| 5 | * AF_SMC protocol family socket handler keeping the AF_INET sock address type |
| 6 | * applies to SOCK_STREAM sockets only |
| 7 | * offers an alternative communication option for TCP-protocol sockets |
| 8 | * applicable with RoCE-cards only |
| 9 | * |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 10 | * Initial restrictions: |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 11 | * - support for alternate links postponed |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 12 | * |
Karsten Graul | aaa4d33 | 2018-03-16 15:06:41 +0100 | [diff] [blame] | 13 | * Copyright IBM Corp. 2016, 2018 |
Ursula Braun | ac71387 | 2017-01-09 16:55:13 +0100 | [diff] [blame] | 14 | * |
| 15 | * Author(s): Ursula Braun <ubraun@linux.vnet.ibm.com> |
| 16 | * based on prototype from Frank Blaschka |
| 17 | */ |
| 18 | |
| 19 | #define KMSG_COMPONENT "smc" |
| 20 | #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt |
| 21 | |
| 22 | #include <linux/module.h> |
| 23 | #include <linux/socket.h> |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 24 | #include <linux/workqueue.h> |
Ursula Braun | 5f08318 | 2017-01-09 16:55:22 +0100 | [diff] [blame] | 25 | #include <linux/in.h> |
Ingo Molnar | c3edc40 | 2017-02-02 08:35:14 +0100 | [diff] [blame] | 26 | #include <linux/sched/signal.h> |
Hans Wippel | 4134984 | 2018-06-28 19:05:11 +0200 | [diff] [blame] | 27 | #include <linux/if_vlan.h> |
Ursula Braun | 4ead9c9 | 2019-11-16 17:47:31 +0100 | [diff] [blame] | 28 | #include <linux/rcupdate_wait.h> |
Ingo Molnar | c3edc40 | 2017-02-02 08:35:14 +0100 | [diff] [blame] | 29 | |
Ursula Braun | ac71387 | 2017-01-09 16:55:13 +0100 | [diff] [blame] | 30 | #include <net/sock.h> |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 31 | #include <net/tcp.h> |
Ursula Braun | f16a7dd | 2017-01-09 16:55:26 +0100 | [diff] [blame] | 32 | #include <net/smc.h> |
Ursula Braun | 9b67e26 | 2018-05-02 16:56:46 +0200 | [diff] [blame] | 33 | #include <asm/ioctls.h> |
Ursula Braun | ac71387 | 2017-01-09 16:55:13 +0100 | [diff] [blame] | 34 | |
Hans Wippel | 64e28b5 | 2019-02-21 13:01:02 +0100 | [diff] [blame] | 35 | #include <net/net_namespace.h> |
| 36 | #include <net/netns/generic.h> |
| 37 | #include "smc_netns.h" |
| 38 | |
Ursula Braun | ac71387 | 2017-01-09 16:55:13 +0100 | [diff] [blame] | 39 | #include "smc.h" |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 40 | #include "smc_clc.h" |
Ursula Braun | 9bf9abe | 2017-01-09 16:55:21 +0100 | [diff] [blame] | 41 | #include "smc_llc.h" |
Ursula Braun | 5f08318 | 2017-01-09 16:55:22 +0100 | [diff] [blame] | 42 | #include "smc_cdc.h" |
Ursula Braun | 0cfdd8f | 2017-01-09 16:55:17 +0100 | [diff] [blame] | 43 | #include "smc_core.h" |
Ursula Braun | a4cf044 | 2017-01-09 16:55:14 +0100 | [diff] [blame] | 44 | #include "smc_ib.h" |
Hans Wippel | 4134984 | 2018-06-28 19:05:11 +0200 | [diff] [blame] | 45 | #include "smc_ism.h" |
Thomas Richter | 6812baa | 2017-01-09 16:55:15 +0100 | [diff] [blame] | 46 | #include "smc_pnet.h" |
Ursula Braun | e6727f3 | 2017-01-09 16:55:23 +0100 | [diff] [blame] | 47 | #include "smc_tx.h" |
Ursula Braun | 952310c | 2017-01-09 16:55:24 +0100 | [diff] [blame] | 48 | #include "smc_rx.h" |
Ursula Braun | b38d732 | 2017-01-09 16:55:25 +0100 | [diff] [blame] | 49 | #include "smc_close.h" |
Ursula Braun | ac71387 | 2017-01-09 16:55:13 +0100 | [diff] [blame] | 50 | |
Hans Wippel | 72a36a8 | 2019-02-07 15:56:18 +0100 | [diff] [blame] | 51 | static DEFINE_MUTEX(smc_server_lgr_pending); /* serialize link group |
| 52 | * creation on server |
| 53 | */ |
| 54 | static DEFINE_MUTEX(smc_client_lgr_pending); /* serialize link group |
| 55 | * creation on client |
Ursula Braun | 0cfdd8f | 2017-01-09 16:55:17 +0100 | [diff] [blame] | 56 | */ |
| 57 | |
Karsten Graul | 22ef473 | 2020-09-10 18:48:29 +0200 | [diff] [blame] | 58 | struct workqueue_struct *smc_hs_wq; /* wq for handshake work */ |
| 59 | struct workqueue_struct *smc_close_wq; /* wq for close work */ |
| 60 | |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 61 | static void smc_tcp_listen_work(struct work_struct *); |
Ursula Braun | 24ac3a0 | 2018-06-27 17:59:50 +0200 | [diff] [blame] | 62 | static void smc_connect_work(struct work_struct *); |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 63 | |
Ursula Braun | ac71387 | 2017-01-09 16:55:13 +0100 | [diff] [blame] | 64 | static void smc_set_keepalive(struct sock *sk, int val) |
| 65 | { |
| 66 | struct smc_sock *smc = smc_sk(sk); |
| 67 | |
| 68 | smc->clcsock->sk->sk_prot->keepalive(smc->clcsock->sk, val); |
| 69 | } |
| 70 | |
Ursula Braun | f16a7dd | 2017-01-09 16:55:26 +0100 | [diff] [blame] | 71 | static struct smc_hashinfo smc_v4_hashinfo = { |
| 72 | .lock = __RW_LOCK_UNLOCKED(smc_v4_hashinfo.lock), |
| 73 | }; |
| 74 | |
Karsten Graul | aaa4d33 | 2018-03-16 15:06:41 +0100 | [diff] [blame] | 75 | static struct smc_hashinfo smc_v6_hashinfo = { |
| 76 | .lock = __RW_LOCK_UNLOCKED(smc_v6_hashinfo.lock), |
| 77 | }; |
| 78 | |
Ursula Braun | f16a7dd | 2017-01-09 16:55:26 +0100 | [diff] [blame] | 79 | int smc_hash_sk(struct sock *sk) |
| 80 | { |
| 81 | struct smc_hashinfo *h = sk->sk_prot->h.smc_hash; |
| 82 | struct hlist_head *head; |
| 83 | |
| 84 | head = &h->ht; |
| 85 | |
| 86 | write_lock_bh(&h->lock); |
| 87 | sk_add_node(sk, head); |
| 88 | sock_prot_inuse_add(sock_net(sk), sk->sk_prot, 1); |
| 89 | write_unlock_bh(&h->lock); |
| 90 | |
| 91 | return 0; |
| 92 | } |
| 93 | EXPORT_SYMBOL_GPL(smc_hash_sk); |
| 94 | |
| 95 | void smc_unhash_sk(struct sock *sk) |
| 96 | { |
| 97 | struct smc_hashinfo *h = sk->sk_prot->h.smc_hash; |
| 98 | |
| 99 | write_lock_bh(&h->lock); |
| 100 | if (sk_del_node_init(sk)) |
| 101 | sock_prot_inuse_add(sock_net(sk), sk->sk_prot, -1); |
| 102 | write_unlock_bh(&h->lock); |
| 103 | } |
| 104 | EXPORT_SYMBOL_GPL(smc_unhash_sk); |
| 105 | |
| 106 | struct proto smc_proto = { |
Ursula Braun | ac71387 | 2017-01-09 16:55:13 +0100 | [diff] [blame] | 107 | .name = "SMC", |
| 108 | .owner = THIS_MODULE, |
| 109 | .keepalive = smc_set_keepalive, |
Ursula Braun | f16a7dd | 2017-01-09 16:55:26 +0100 | [diff] [blame] | 110 | .hash = smc_hash_sk, |
| 111 | .unhash = smc_unhash_sk, |
Ursula Braun | ac71387 | 2017-01-09 16:55:13 +0100 | [diff] [blame] | 112 | .obj_size = sizeof(struct smc_sock), |
Ursula Braun | f16a7dd | 2017-01-09 16:55:26 +0100 | [diff] [blame] | 113 | .h.smc_hash = &smc_v4_hashinfo, |
Paul E. McKenney | 5f0d5a3 | 2017-01-18 02:53:44 -0800 | [diff] [blame] | 114 | .slab_flags = SLAB_TYPESAFE_BY_RCU, |
Ursula Braun | ac71387 | 2017-01-09 16:55:13 +0100 | [diff] [blame] | 115 | }; |
Ursula Braun | f16a7dd | 2017-01-09 16:55:26 +0100 | [diff] [blame] | 116 | EXPORT_SYMBOL_GPL(smc_proto); |
Ursula Braun | ac71387 | 2017-01-09 16:55:13 +0100 | [diff] [blame] | 117 | |
Karsten Graul | aaa4d33 | 2018-03-16 15:06:41 +0100 | [diff] [blame] | 118 | struct proto smc_proto6 = { |
| 119 | .name = "SMC6", |
| 120 | .owner = THIS_MODULE, |
| 121 | .keepalive = smc_set_keepalive, |
| 122 | .hash = smc_hash_sk, |
| 123 | .unhash = smc_unhash_sk, |
| 124 | .obj_size = sizeof(struct smc_sock), |
| 125 | .h.smc_hash = &smc_v6_hashinfo, |
| 126 | .slab_flags = SLAB_TYPESAFE_BY_RCU, |
| 127 | }; |
| 128 | EXPORT_SYMBOL_GPL(smc_proto6); |
| 129 | |
Ursula Braun | f536dff | 2019-10-23 15:44:05 +0200 | [diff] [blame] | 130 | static void smc_restore_fallback_changes(struct smc_sock *smc) |
| 131 | { |
Karsten Graul | 1ad2405 | 2020-07-18 15:06:18 +0200 | [diff] [blame] | 132 | if (smc->clcsock->file) { /* non-accepted sockets have no file yet */ |
| 133 | smc->clcsock->file->private_data = smc->sk.sk_socket; |
| 134 | smc->clcsock->file = NULL; |
| 135 | } |
Ursula Braun | f536dff | 2019-10-23 15:44:05 +0200 | [diff] [blame] | 136 | } |
| 137 | |
Ursula Braun | 39f41f3 | 2019-06-27 15:04:52 +0200 | [diff] [blame] | 138 | static int __smc_release(struct smc_sock *smc) |
Ursula Braun | ac71387 | 2017-01-09 16:55:13 +0100 | [diff] [blame] | 139 | { |
Ursula Braun | 39f41f3 | 2019-06-27 15:04:52 +0200 | [diff] [blame] | 140 | struct sock *sk = &smc->sk; |
Ursula Braun | b38d732 | 2017-01-09 16:55:25 +0100 | [diff] [blame] | 141 | int rc = 0; |
Ursula Braun | ac71387 | 2017-01-09 16:55:13 +0100 | [diff] [blame] | 142 | |
Ursula Braun | 51f1de7 | 2018-01-26 09:28:48 +0100 | [diff] [blame] | 143 | if (!smc->use_fallback) { |
Ursula Braun | b38d732 | 2017-01-09 16:55:25 +0100 | [diff] [blame] | 144 | rc = smc_close_active(smc); |
| 145 | sock_set_flag(sk, SOCK_DEAD); |
| 146 | sk->sk_shutdown |= SHUTDOWN_MASK; |
Ursula Braun | b03faa1 | 2019-02-07 15:56:15 +0100 | [diff] [blame] | 147 | } else { |
| 148 | if (sk->sk_state != SMC_LISTEN && sk->sk_state != SMC_INIT) |
| 149 | sock_put(sk); /* passive closing */ |
| 150 | if (sk->sk_state == SMC_LISTEN) { |
| 151 | /* wake up clcsock accept */ |
| 152 | rc = kernel_sock_shutdown(smc->clcsock, SHUT_RDWR); |
| 153 | } |
| 154 | sk->sk_state = SMC_CLOSED; |
| 155 | sk->sk_state_change(sk); |
Ursula Braun | f536dff | 2019-10-23 15:44:05 +0200 | [diff] [blame] | 156 | smc_restore_fallback_changes(smc); |
Ursula Braun | b38d732 | 2017-01-09 16:55:25 +0100 | [diff] [blame] | 157 | } |
Cong Wang | 26d92e9 | 2019-01-05 23:45:26 -0800 | [diff] [blame] | 158 | |
| 159 | sk->sk_prot->unhash(sk); |
| 160 | |
Ursula Braun | b03faa1 | 2019-02-07 15:56:15 +0100 | [diff] [blame] | 161 | if (sk->sk_state == SMC_CLOSED) { |
| 162 | if (smc->clcsock) { |
Karsten Graul | fd57770 | 2019-04-11 11:17:30 +0200 | [diff] [blame] | 163 | release_sock(sk); |
| 164 | smc_clcsock_release(smc); |
| 165 | lock_sock(sk); |
Myungho Jung | 78abe3d | 2018-12-18 09:02:25 -0800 | [diff] [blame] | 166 | } |
Ursula Braun | b03faa1 | 2019-02-07 15:56:15 +0100 | [diff] [blame] | 167 | if (!smc->use_fallback) |
| 168 | smc_conn_free(&smc->conn); |
Ursula Braun | 51f1de7 | 2018-01-26 09:28:48 +0100 | [diff] [blame] | 169 | } |
Ursula Braun | ac71387 | 2017-01-09 16:55:13 +0100 | [diff] [blame] | 170 | |
Ursula Braun | 39f41f3 | 2019-06-27 15:04:52 +0200 | [diff] [blame] | 171 | return rc; |
| 172 | } |
| 173 | |
| 174 | static int smc_release(struct socket *sock) |
| 175 | { |
| 176 | struct sock *sk = sock->sk; |
| 177 | struct smc_sock *smc; |
| 178 | int rc = 0; |
| 179 | |
| 180 | if (!sk) |
| 181 | goto out; |
| 182 | |
Ursula Braun | 81cf4f4 | 2019-10-21 16:13:15 +0200 | [diff] [blame] | 183 | sock_hold(sk); /* sock_put below */ |
Ursula Braun | 39f41f3 | 2019-06-27 15:04:52 +0200 | [diff] [blame] | 184 | smc = smc_sk(sk); |
| 185 | |
| 186 | /* cleanup for a dangling non-blocking connect */ |
| 187 | if (smc->connect_nonblock && sk->sk_state == SMC_INIT) |
| 188 | tcp_abort(smc->clcsock->sk, ECONNABORTED); |
| 189 | flush_work(&smc->connect_work); |
| 190 | |
| 191 | if (sk->sk_state == SMC_LISTEN) |
| 192 | /* smc_close_non_accepted() is called and acquires |
| 193 | * sock lock for child sockets again |
| 194 | */ |
| 195 | lock_sock_nested(sk, SINGLE_DEPTH_NESTING); |
| 196 | else |
| 197 | lock_sock(sk); |
| 198 | |
| 199 | rc = __smc_release(smc); |
| 200 | |
Ursula Braun | ac71387 | 2017-01-09 16:55:13 +0100 | [diff] [blame] | 201 | /* detach socket */ |
| 202 | sock_orphan(sk); |
| 203 | sock->sk = NULL; |
| 204 | release_sock(sk); |
| 205 | |
Ursula Braun | 81cf4f4 | 2019-10-21 16:13:15 +0200 | [diff] [blame] | 206 | sock_put(sk); /* sock_hold above */ |
Ursula Braun | 51f1de7 | 2018-01-26 09:28:48 +0100 | [diff] [blame] | 207 | sock_put(sk); /* final sock_put */ |
Ursula Braun | ac71387 | 2017-01-09 16:55:13 +0100 | [diff] [blame] | 208 | out: |
Ursula Braun | b38d732 | 2017-01-09 16:55:25 +0100 | [diff] [blame] | 209 | return rc; |
Ursula Braun | ac71387 | 2017-01-09 16:55:13 +0100 | [diff] [blame] | 210 | } |
| 211 | |
| 212 | static void smc_destruct(struct sock *sk) |
| 213 | { |
| 214 | if (sk->sk_state != SMC_CLOSED) |
| 215 | return; |
| 216 | if (!sock_flag(sk, SOCK_DEAD)) |
| 217 | return; |
| 218 | |
| 219 | sk_refcnt_debug_dec(sk); |
| 220 | } |
| 221 | |
Karsten Graul | aaa4d33 | 2018-03-16 15:06:41 +0100 | [diff] [blame] | 222 | static struct sock *smc_sock_alloc(struct net *net, struct socket *sock, |
| 223 | int protocol) |
Ursula Braun | ac71387 | 2017-01-09 16:55:13 +0100 | [diff] [blame] | 224 | { |
| 225 | struct smc_sock *smc; |
Karsten Graul | aaa4d33 | 2018-03-16 15:06:41 +0100 | [diff] [blame] | 226 | struct proto *prot; |
Ursula Braun | ac71387 | 2017-01-09 16:55:13 +0100 | [diff] [blame] | 227 | struct sock *sk; |
| 228 | |
Karsten Graul | aaa4d33 | 2018-03-16 15:06:41 +0100 | [diff] [blame] | 229 | prot = (protocol == SMCPROTO_SMC6) ? &smc_proto6 : &smc_proto; |
| 230 | sk = sk_alloc(net, PF_SMC, GFP_KERNEL, prot, 0); |
Ursula Braun | ac71387 | 2017-01-09 16:55:13 +0100 | [diff] [blame] | 231 | if (!sk) |
| 232 | return NULL; |
| 233 | |
| 234 | sock_init_data(sock, sk); /* sets sk_refcnt to 1 */ |
| 235 | sk->sk_state = SMC_INIT; |
| 236 | sk->sk_destruct = smc_destruct; |
Karsten Graul | aaa4d33 | 2018-03-16 15:06:41 +0100 | [diff] [blame] | 237 | sk->sk_protocol = protocol; |
Ursula Braun | ac71387 | 2017-01-09 16:55:13 +0100 | [diff] [blame] | 238 | smc = smc_sk(sk); |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 239 | INIT_WORK(&smc->tcp_listen_work, smc_tcp_listen_work); |
Ursula Braun | 24ac3a0 | 2018-06-27 17:59:50 +0200 | [diff] [blame] | 240 | INIT_WORK(&smc->connect_work, smc_connect_work); |
Eric Dumazet | be7f3e5 | 2018-05-17 03:54:21 -0700 | [diff] [blame] | 241 | INIT_DELAYED_WORK(&smc->conn.tx_work, smc_tx_work); |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 242 | INIT_LIST_HEAD(&smc->accept_q); |
| 243 | spin_lock_init(&smc->accept_q_lock); |
Eric Dumazet | be7f3e5 | 2018-05-17 03:54:21 -0700 | [diff] [blame] | 244 | spin_lock_init(&smc->conn.send_lock); |
Ursula Braun | f16a7dd | 2017-01-09 16:55:26 +0100 | [diff] [blame] | 245 | sk->sk_prot->hash(sk); |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 246 | sk_refcnt_debug_inc(sk); |
Myungho Jung | 78abe3d | 2018-12-18 09:02:25 -0800 | [diff] [blame] | 247 | mutex_init(&smc->clcsock_release_lock); |
Ursula Braun | ac71387 | 2017-01-09 16:55:13 +0100 | [diff] [blame] | 248 | |
| 249 | return sk; |
| 250 | } |
| 251 | |
| 252 | static int smc_bind(struct socket *sock, struct sockaddr *uaddr, |
| 253 | int addr_len) |
| 254 | { |
| 255 | struct sockaddr_in *addr = (struct sockaddr_in *)uaddr; |
| 256 | struct sock *sk = sock->sk; |
| 257 | struct smc_sock *smc; |
| 258 | int rc; |
| 259 | |
| 260 | smc = smc_sk(sk); |
| 261 | |
| 262 | /* replicate tests from inet_bind(), to be safe wrt. future changes */ |
| 263 | rc = -EINVAL; |
| 264 | if (addr_len < sizeof(struct sockaddr_in)) |
| 265 | goto out; |
| 266 | |
| 267 | rc = -EAFNOSUPPORT; |
Karsten Graul | aaa4d33 | 2018-03-16 15:06:41 +0100 | [diff] [blame] | 268 | if (addr->sin_family != AF_INET && |
| 269 | addr->sin_family != AF_INET6 && |
| 270 | addr->sin_family != AF_UNSPEC) |
| 271 | goto out; |
Ursula Braun | ac71387 | 2017-01-09 16:55:13 +0100 | [diff] [blame] | 272 | /* accept AF_UNSPEC (mapped to AF_INET) only if s_addr is INADDR_ANY */ |
Karsten Graul | aaa4d33 | 2018-03-16 15:06:41 +0100 | [diff] [blame] | 273 | if (addr->sin_family == AF_UNSPEC && |
| 274 | addr->sin_addr.s_addr != htonl(INADDR_ANY)) |
Ursula Braun | ac71387 | 2017-01-09 16:55:13 +0100 | [diff] [blame] | 275 | goto out; |
| 276 | |
| 277 | lock_sock(sk); |
| 278 | |
| 279 | /* Check if socket is already active */ |
| 280 | rc = -EINVAL; |
Ursula Braun | cd20636 | 2019-08-02 10:47:50 +0200 | [diff] [blame] | 281 | if (sk->sk_state != SMC_INIT || smc->connect_nonblock) |
Ursula Braun | ac71387 | 2017-01-09 16:55:13 +0100 | [diff] [blame] | 282 | goto out_rel; |
| 283 | |
| 284 | smc->clcsock->sk->sk_reuse = sk->sk_reuse; |
| 285 | rc = kernel_bind(smc->clcsock, uaddr, addr_len); |
| 286 | |
| 287 | out_rel: |
| 288 | release_sock(sk); |
| 289 | out: |
| 290 | return rc; |
| 291 | } |
| 292 | |
| 293 | static void smc_copy_sock_settings(struct sock *nsk, struct sock *osk, |
| 294 | unsigned long mask) |
| 295 | { |
| 296 | /* options we don't get control via setsockopt for */ |
| 297 | nsk->sk_type = osk->sk_type; |
| 298 | nsk->sk_sndbuf = osk->sk_sndbuf; |
| 299 | nsk->sk_rcvbuf = osk->sk_rcvbuf; |
| 300 | nsk->sk_sndtimeo = osk->sk_sndtimeo; |
| 301 | nsk->sk_rcvtimeo = osk->sk_rcvtimeo; |
| 302 | nsk->sk_mark = osk->sk_mark; |
| 303 | nsk->sk_priority = osk->sk_priority; |
| 304 | nsk->sk_rcvlowat = osk->sk_rcvlowat; |
| 305 | nsk->sk_bound_dev_if = osk->sk_bound_dev_if; |
| 306 | nsk->sk_err = osk->sk_err; |
| 307 | |
| 308 | nsk->sk_flags &= ~mask; |
| 309 | nsk->sk_flags |= osk->sk_flags & mask; |
| 310 | } |
| 311 | |
| 312 | #define SK_FLAGS_SMC_TO_CLC ((1UL << SOCK_URGINLINE) | \ |
| 313 | (1UL << SOCK_KEEPOPEN) | \ |
| 314 | (1UL << SOCK_LINGER) | \ |
| 315 | (1UL << SOCK_BROADCAST) | \ |
| 316 | (1UL << SOCK_TIMESTAMP) | \ |
| 317 | (1UL << SOCK_DBG) | \ |
| 318 | (1UL << SOCK_RCVTSTAMP) | \ |
| 319 | (1UL << SOCK_RCVTSTAMPNS) | \ |
| 320 | (1UL << SOCK_LOCALROUTE) | \ |
| 321 | (1UL << SOCK_TIMESTAMPING_RX_SOFTWARE) | \ |
| 322 | (1UL << SOCK_RXQ_OVFL) | \ |
| 323 | (1UL << SOCK_WIFI_STATUS) | \ |
| 324 | (1UL << SOCK_NOFCS) | \ |
Deepa Dinamani | 9718475 | 2019-02-02 07:34:51 -0800 | [diff] [blame] | 325 | (1UL << SOCK_FILTER_LOCKED) | \ |
| 326 | (1UL << SOCK_TSTAMP_NEW)) |
Ursula Braun | ac71387 | 2017-01-09 16:55:13 +0100 | [diff] [blame] | 327 | /* copy only relevant settings and flags of SOL_SOCKET level from smc to |
| 328 | * clc socket (since smc is not called for these options from net/core) |
| 329 | */ |
| 330 | static void smc_copy_sock_settings_to_clc(struct smc_sock *smc) |
| 331 | { |
| 332 | smc_copy_sock_settings(smc->clcsock->sk, &smc->sk, SK_FLAGS_SMC_TO_CLC); |
| 333 | } |
| 334 | |
| 335 | #define SK_FLAGS_CLC_TO_SMC ((1UL << SOCK_URGINLINE) | \ |
| 336 | (1UL << SOCK_KEEPOPEN) | \ |
| 337 | (1UL << SOCK_LINGER) | \ |
| 338 | (1UL << SOCK_DBG)) |
| 339 | /* copy only settings and flags relevant for smc from clc to smc socket */ |
| 340 | static void smc_copy_sock_settings_to_smc(struct smc_sock *smc) |
| 341 | { |
| 342 | smc_copy_sock_settings(&smc->sk, smc->clcsock->sk, SK_FLAGS_CLC_TO_SMC); |
| 343 | } |
| 344 | |
Karsten Graul | b924754 | 2020-04-29 17:10:41 +0200 | [diff] [blame] | 345 | /* register the new rmb on all links */ |
Karsten Graul | 7562a13 | 2020-05-01 12:48:01 +0200 | [diff] [blame] | 346 | static int smcr_lgr_reg_rmbs(struct smc_link *link, |
Karsten Graul | b924754 | 2020-04-29 17:10:41 +0200 | [diff] [blame] | 347 | struct smc_buf_desc *rmb_desc) |
| 348 | { |
Karsten Graul | 7562a13 | 2020-05-01 12:48:01 +0200 | [diff] [blame] | 349 | struct smc_link_group *lgr = link->lgr; |
| 350 | int i, rc = 0; |
Karsten Graul | b924754 | 2020-04-29 17:10:41 +0200 | [diff] [blame] | 351 | |
Karsten Graul | d550066 | 2020-05-01 12:48:05 +0200 | [diff] [blame] | 352 | rc = smc_llc_flow_initiate(lgr, SMC_LLC_FLOW_RKEY); |
| 353 | if (rc) |
| 354 | return rc; |
| 355 | /* protect against parallel smc_llc_cli_rkey_exchange() and |
| 356 | * parallel smcr_link_reg_rmb() |
| 357 | */ |
| 358 | mutex_lock(&lgr->llc_conf_mutex); |
Karsten Graul | b924754 | 2020-04-29 17:10:41 +0200 | [diff] [blame] | 359 | for (i = 0; i < SMC_LINKS_PER_LGR_MAX; i++) { |
Karsten Graul | 741a49a | 2020-07-18 15:06:16 +0200 | [diff] [blame] | 360 | if (!smc_link_active(&lgr->lnk[i])) |
Karsten Graul | b924754 | 2020-04-29 17:10:41 +0200 | [diff] [blame] | 361 | continue; |
Karsten Graul | 7562a13 | 2020-05-01 12:48:01 +0200 | [diff] [blame] | 362 | rc = smcr_link_reg_rmb(&lgr->lnk[i], rmb_desc); |
Karsten Graul | b924754 | 2020-04-29 17:10:41 +0200 | [diff] [blame] | 363 | if (rc) |
Karsten Graul | 7562a13 | 2020-05-01 12:48:01 +0200 | [diff] [blame] | 364 | goto out; |
Karsten Graul | b924754 | 2020-04-29 17:10:41 +0200 | [diff] [blame] | 365 | } |
Karsten Graul | 7562a13 | 2020-05-01 12:48:01 +0200 | [diff] [blame] | 366 | |
| 367 | /* exchange confirm_rkey msg with peer */ |
| 368 | rc = smc_llc_do_confirm_rkey(link, rmb_desc); |
| 369 | if (rc) { |
| 370 | rc = -EFAULT; |
| 371 | goto out; |
| 372 | } |
| 373 | rmb_desc->is_conf_rkey = true; |
| 374 | out: |
Karsten Graul | d550066 | 2020-05-01 12:48:05 +0200 | [diff] [blame] | 375 | mutex_unlock(&lgr->llc_conf_mutex); |
| 376 | smc_llc_flow_stop(lgr, &lgr->llc_flow_lcl); |
Karsten Graul | 7562a13 | 2020-05-01 12:48:01 +0200 | [diff] [blame] | 377 | return rc; |
Karsten Graul | b924754 | 2020-04-29 17:10:41 +0200 | [diff] [blame] | 378 | } |
| 379 | |
| 380 | static int smcr_clnt_conf_first_link(struct smc_sock *smc) |
Ursula Braun | 9bf9abe | 2017-01-09 16:55:21 +0100 | [diff] [blame] | 381 | { |
Karsten Graul | 387707f | 2020-04-29 17:10:40 +0200 | [diff] [blame] | 382 | struct smc_link *link = smc->conn.lnk; |
Karsten Graul | 0fb0b02 | 2020-04-30 15:55:43 +0200 | [diff] [blame] | 383 | struct smc_llc_qentry *qentry; |
Ursula Braun | 9bf9abe | 2017-01-09 16:55:21 +0100 | [diff] [blame] | 384 | int rc; |
| 385 | |
Ursula Braun | 9bf9abe | 2017-01-09 16:55:21 +0100 | [diff] [blame] | 386 | /* receive CONFIRM LINK request from server over RoCE fabric */ |
Karsten Graul | 0fb0b02 | 2020-04-30 15:55:43 +0200 | [diff] [blame] | 387 | qentry = smc_llc_wait(link->lgr, NULL, SMC_LLC_WAIT_TIME, |
| 388 | SMC_LLC_CONFIRM_LINK); |
| 389 | if (!qentry) { |
Ursula Braun | 9bf9abe | 2017-01-09 16:55:21 +0100 | [diff] [blame] | 390 | struct smc_clc_msg_decline dclc; |
| 391 | |
| 392 | rc = smc_clc_wait_msg(smc, &dclc, sizeof(dclc), |
Ursula Braun | 2b59f58 | 2018-11-22 10:26:39 +0100 | [diff] [blame] | 393 | SMC_CLC_DECLINE, CLC_WAIT_TIME_SHORT); |
Ursula Braun | 9ed2855 | 2018-11-22 10:26:37 +0100 | [diff] [blame] | 394 | return rc == -EAGAIN ? SMC_CLC_DECL_TIMEOUT_CL : rc; |
Ursula Braun | 9bf9abe | 2017-01-09 16:55:21 +0100 | [diff] [blame] | 395 | } |
Karsten Graul | 649758f | 2020-05-04 14:18:48 +0200 | [diff] [blame] | 396 | smc_llc_save_peer_uid(qentry); |
Karsten Graul | 0fb0b02 | 2020-04-30 15:55:43 +0200 | [diff] [blame] | 397 | rc = smc_llc_eval_conf_link(qentry, SMC_LLC_REQ); |
| 398 | smc_llc_flow_qentry_del(&link->lgr->llc_flow_lcl); |
| 399 | if (rc) |
Karsten Graul | 75d320d | 2018-03-01 13:51:31 +0100 | [diff] [blame] | 400 | return SMC_CLC_DECL_RMBE_EC; |
| 401 | |
Ursula Braun | 9bf9abe | 2017-01-09 16:55:21 +0100 | [diff] [blame] | 402 | rc = smc_ib_modify_qp_rts(link); |
| 403 | if (rc) |
Karsten Graul | 603cc14 | 2018-07-25 16:35:32 +0200 | [diff] [blame] | 404 | return SMC_CLC_DECL_ERR_RDYLNK; |
Ursula Braun | 9bf9abe | 2017-01-09 16:55:21 +0100 | [diff] [blame] | 405 | |
| 406 | smc_wr_remember_qp_attr(link); |
Ursula Braun | 652a1e4 | 2017-07-28 13:56:17 +0200 | [diff] [blame] | 407 | |
Karsten Graul | 7562a13 | 2020-05-01 12:48:01 +0200 | [diff] [blame] | 408 | if (smcr_link_reg_rmb(link, smc->conn.rmb_desc)) |
Karsten Graul | 603cc14 | 2018-07-25 16:35:32 +0200 | [diff] [blame] | 409 | return SMC_CLC_DECL_ERR_REGRMB; |
Ursula Braun | 652a1e4 | 2017-07-28 13:56:17 +0200 | [diff] [blame] | 410 | |
Karsten Graul | 0fb0b02 | 2020-04-30 15:55:43 +0200 | [diff] [blame] | 411 | /* confirm_rkey is implicit on 1st contact */ |
| 412 | smc->conn.rmb_desc->is_conf_rkey = true; |
| 413 | |
Ursula Braun | 9bf9abe | 2017-01-09 16:55:21 +0100 | [diff] [blame] | 414 | /* send CONFIRM LINK response over RoCE fabric */ |
Ursula Braun | 947541f | 2018-07-25 16:35:30 +0200 | [diff] [blame] | 415 | rc = smc_llc_send_confirm_link(link, SMC_LLC_RESP); |
Ursula Braun | 9bf9abe | 2017-01-09 16:55:21 +0100 | [diff] [blame] | 416 | if (rc < 0) |
Karsten Graul | 603cc14 | 2018-07-25 16:35:32 +0200 | [diff] [blame] | 417 | return SMC_CLC_DECL_TIMEOUT_CL; |
Ursula Braun | 9bf9abe | 2017-01-09 16:55:21 +0100 | [diff] [blame] | 418 | |
Karsten Graul | 0fb0b02 | 2020-04-30 15:55:43 +0200 | [diff] [blame] | 419 | smc_llc_link_active(link); |
Karsten Graul | 0a99be4 | 2020-05-05 15:01:20 +0200 | [diff] [blame] | 420 | smcr_lgr_set_type(link->lgr, SMC_LGR_SINGLE); |
Karsten Graul | 0fb0b02 | 2020-04-30 15:55:43 +0200 | [diff] [blame] | 421 | |
| 422 | /* optional 2nd link, receive ADD LINK request from server */ |
| 423 | qentry = smc_llc_wait(link->lgr, NULL, SMC_LLC_WAIT_TIME, |
| 424 | SMC_LLC_ADD_LINK); |
| 425 | if (!qentry) { |
Karsten Graul | 52bedf3 | 2018-03-01 13:51:32 +0100 | [diff] [blame] | 426 | struct smc_clc_msg_decline dclc; |
| 427 | |
| 428 | rc = smc_clc_wait_msg(smc, &dclc, sizeof(dclc), |
Ursula Braun | 2b59f58 | 2018-11-22 10:26:39 +0100 | [diff] [blame] | 429 | SMC_CLC_DECLINE, CLC_WAIT_TIME_SHORT); |
Karsten Graul | 0fb0b02 | 2020-04-30 15:55:43 +0200 | [diff] [blame] | 430 | if (rc == -EAGAIN) |
| 431 | rc = 0; /* no DECLINE received, go with one link */ |
| 432 | return rc; |
Karsten Graul | 52bedf3 | 2018-03-01 13:51:32 +0100 | [diff] [blame] | 433 | } |
Karsten Graul | 0fb0b02 | 2020-04-30 15:55:43 +0200 | [diff] [blame] | 434 | smc_llc_flow_qentry_clr(&link->lgr->llc_flow_lcl); |
Karsten Graul | b1570a8 | 2020-05-03 14:38:42 +0200 | [diff] [blame] | 435 | smc_llc_cli_add_link(link, qentry); |
Karsten Graul | 75d320d | 2018-03-01 13:51:31 +0100 | [diff] [blame] | 436 | return 0; |
Ursula Braun | 9bf9abe | 2017-01-09 16:55:21 +0100 | [diff] [blame] | 437 | } |
| 438 | |
Hans Wippel | 4134984 | 2018-06-28 19:05:11 +0200 | [diff] [blame] | 439 | static void smcr_conn_save_peer_info(struct smc_sock *smc, |
| 440 | struct smc_clc_msg_accept_confirm *clc) |
Ursula Braun | 0cfdd8f | 2017-01-09 16:55:17 +0100 | [diff] [blame] | 441 | { |
Ursula Braun | 3d9725a | 2020-09-10 18:48:23 +0200 | [diff] [blame] | 442 | int bufsize = smc_uncompress_bufsize(clc->r0.rmbe_size); |
Hans Wippel | 95d8d263 | 2018-05-18 09:34:13 +0200 | [diff] [blame] | 443 | |
Ursula Braun | 3d9725a | 2020-09-10 18:48:23 +0200 | [diff] [blame] | 444 | smc->conn.peer_rmbe_idx = clc->r0.rmbe_idx; |
| 445 | smc->conn.local_tx_ctrl.token = ntohl(clc->r0.rmbe_alert_token); |
Hans Wippel | 95d8d263 | 2018-05-18 09:34:13 +0200 | [diff] [blame] | 446 | smc->conn.peer_rmbe_size = bufsize; |
Ursula Braun | cd6851f | 2017-01-09 16:55:18 +0100 | [diff] [blame] | 447 | atomic_set(&smc->conn.peer_rmbe_space, smc->conn.peer_rmbe_size); |
Hans Wippel | 95d8d263 | 2018-05-18 09:34:13 +0200 | [diff] [blame] | 448 | smc->conn.tx_off = bufsize * (smc->conn.peer_rmbe_idx - 1); |
Ursula Braun | 0cfdd8f | 2017-01-09 16:55:17 +0100 | [diff] [blame] | 449 | } |
| 450 | |
Hans Wippel | 4134984 | 2018-06-28 19:05:11 +0200 | [diff] [blame] | 451 | static void smcd_conn_save_peer_info(struct smc_sock *smc, |
| 452 | struct smc_clc_msg_accept_confirm *clc) |
| 453 | { |
Ursula Braun | 3d9725a | 2020-09-10 18:48:23 +0200 | [diff] [blame] | 454 | int bufsize = smc_uncompress_bufsize(clc->d0.dmbe_size); |
Hans Wippel | 4134984 | 2018-06-28 19:05:11 +0200 | [diff] [blame] | 455 | |
Ursula Braun | 3d9725a | 2020-09-10 18:48:23 +0200 | [diff] [blame] | 456 | smc->conn.peer_rmbe_idx = clc->d0.dmbe_idx; |
| 457 | smc->conn.peer_token = clc->d0.token; |
Hans Wippel | 4134984 | 2018-06-28 19:05:11 +0200 | [diff] [blame] | 458 | /* msg header takes up space in the buffer */ |
| 459 | smc->conn.peer_rmbe_size = bufsize - sizeof(struct smcd_cdc_msg); |
| 460 | atomic_set(&smc->conn.peer_rmbe_space, smc->conn.peer_rmbe_size); |
| 461 | smc->conn.tx_off = bufsize * smc->conn.peer_rmbe_idx; |
| 462 | } |
| 463 | |
| 464 | static void smc_conn_save_peer_info(struct smc_sock *smc, |
| 465 | struct smc_clc_msg_accept_confirm *clc) |
| 466 | { |
| 467 | if (smc->conn.lgr->is_smcd) |
| 468 | smcd_conn_save_peer_info(smc, clc); |
| 469 | else |
| 470 | smcr_conn_save_peer_info(smc, clc); |
| 471 | } |
| 472 | |
Ursula Braun | 0cfdd8f | 2017-01-09 16:55:17 +0100 | [diff] [blame] | 473 | static void smc_link_save_peer_info(struct smc_link *link, |
| 474 | struct smc_clc_msg_accept_confirm *clc) |
| 475 | { |
Ursula Braun | 3d9725a | 2020-09-10 18:48:23 +0200 | [diff] [blame] | 476 | link->peer_qpn = ntoh24(clc->r0.qpn); |
| 477 | memcpy(link->peer_gid, clc->r0.lcl.gid, SMC_GID_SIZE); |
| 478 | memcpy(link->peer_mac, clc->r0.lcl.mac, sizeof(link->peer_mac)); |
| 479 | link->peer_psn = ntoh24(clc->r0.psn); |
| 480 | link->peer_mtu = clc->r0.qp_mtu; |
Ursula Braun | 0cfdd8f | 2017-01-09 16:55:17 +0100 | [diff] [blame] | 481 | } |
| 482 | |
Ursula Braun | 07603b2 | 2019-04-11 11:17:32 +0200 | [diff] [blame] | 483 | static void smc_switch_to_fallback(struct smc_sock *smc) |
| 484 | { |
| 485 | smc->use_fallback = true; |
| 486 | if (smc->sk.sk_socket && smc->sk.sk_socket->file) { |
| 487 | smc->clcsock->file = smc->sk.sk_socket->file; |
| 488 | smc->clcsock->file->private_data = smc->clcsock; |
Ursula Braun | 67f562e | 2020-02-14 08:58:59 +0100 | [diff] [blame] | 489 | smc->clcsock->wq.fasync_list = |
| 490 | smc->sk.sk_socket->wq.fasync_list; |
Ursula Braun | 07603b2 | 2019-04-11 11:17:32 +0200 | [diff] [blame] | 491 | } |
| 492 | } |
| 493 | |
Hans Wippel | 3b2dec2 | 2018-05-18 09:34:18 +0200 | [diff] [blame] | 494 | /* fall back during connect */ |
Karsten Graul | 603cc14 | 2018-07-25 16:35:32 +0200 | [diff] [blame] | 495 | static int smc_connect_fallback(struct smc_sock *smc, int reason_code) |
Hans Wippel | 3b2dec2 | 2018-05-18 09:34:18 +0200 | [diff] [blame] | 496 | { |
Ursula Braun | 07603b2 | 2019-04-11 11:17:32 +0200 | [diff] [blame] | 497 | smc_switch_to_fallback(smc); |
Karsten Graul | 603cc14 | 2018-07-25 16:35:32 +0200 | [diff] [blame] | 498 | smc->fallback_rsn = reason_code; |
Hans Wippel | 3b2dec2 | 2018-05-18 09:34:18 +0200 | [diff] [blame] | 499 | smc_copy_sock_settings_to_clc(smc); |
Ursula Braun | 50717a3 | 2019-04-12 12:57:23 +0200 | [diff] [blame] | 500 | smc->connect_nonblock = 0; |
Hans Wippel | 3b2dec2 | 2018-05-18 09:34:18 +0200 | [diff] [blame] | 501 | if (smc->sk.sk_state == SMC_INIT) |
| 502 | smc->sk.sk_state = SMC_ACTIVE; |
| 503 | return 0; |
| 504 | } |
| 505 | |
| 506 | /* decline and fall back during connect */ |
| 507 | static int smc_connect_decline_fallback(struct smc_sock *smc, int reason_code) |
| 508 | { |
| 509 | int rc; |
| 510 | |
Ursula Braun | e1bbdd5 | 2018-07-05 16:15:30 +0200 | [diff] [blame] | 511 | if (reason_code < 0) { /* error, fallback is not possible */ |
| 512 | if (smc->sk.sk_state == SMC_INIT) |
| 513 | sock_put(&smc->sk); /* passive closing */ |
Hans Wippel | 3b2dec2 | 2018-05-18 09:34:18 +0200 | [diff] [blame] | 514 | return reason_code; |
Ursula Braun | e1bbdd5 | 2018-07-05 16:15:30 +0200 | [diff] [blame] | 515 | } |
Karsten Graul | 603cc14 | 2018-07-25 16:35:32 +0200 | [diff] [blame] | 516 | if (reason_code != SMC_CLC_DECL_PEERDECL) { |
Hans Wippel | 3b2dec2 | 2018-05-18 09:34:18 +0200 | [diff] [blame] | 517 | rc = smc_clc_send_decline(smc, reason_code); |
Ursula Braun | e1bbdd5 | 2018-07-05 16:15:30 +0200 | [diff] [blame] | 518 | if (rc < 0) { |
| 519 | if (smc->sk.sk_state == SMC_INIT) |
| 520 | sock_put(&smc->sk); /* passive closing */ |
Hans Wippel | 3b2dec2 | 2018-05-18 09:34:18 +0200 | [diff] [blame] | 521 | return rc; |
Ursula Braun | e1bbdd5 | 2018-07-05 16:15:30 +0200 | [diff] [blame] | 522 | } |
Hans Wippel | 3b2dec2 | 2018-05-18 09:34:18 +0200 | [diff] [blame] | 523 | } |
Karsten Graul | 603cc14 | 2018-07-25 16:35:32 +0200 | [diff] [blame] | 524 | return smc_connect_fallback(smc, reason_code); |
Hans Wippel | 3b2dec2 | 2018-05-18 09:34:18 +0200 | [diff] [blame] | 525 | } |
| 526 | |
| 527 | /* abort connecting */ |
| 528 | static int smc_connect_abort(struct smc_sock *smc, int reason_code, |
Ursula Braun | 5ac54d8 | 2020-09-10 18:48:21 +0200 | [diff] [blame] | 529 | int local_first) |
Hans Wippel | 3b2dec2 | 2018-05-18 09:34:18 +0200 | [diff] [blame] | 530 | { |
Ursula Braun | 51e3dfa | 2020-02-25 16:34:36 +0100 | [diff] [blame] | 531 | bool is_smcd = smc->conn.lgr->is_smcd; |
| 532 | |
Ursula Braun | 5ac54d8 | 2020-09-10 18:48:21 +0200 | [diff] [blame] | 533 | if (local_first) |
Ursula Braun | 51e3dfa | 2020-02-25 16:34:36 +0100 | [diff] [blame] | 534 | smc_lgr_cleanup_early(&smc->conn); |
| 535 | else |
| 536 | smc_conn_free(&smc->conn); |
| 537 | if (is_smcd) |
Hans Wippel | 72a36a8 | 2019-02-07 15:56:18 +0100 | [diff] [blame] | 538 | /* there is only one lgr role for SMC-D; use server lock */ |
| 539 | mutex_unlock(&smc_server_lgr_pending); |
| 540 | else |
| 541 | mutex_unlock(&smc_client_lgr_pending); |
| 542 | |
Ursula Braun | 50717a3 | 2019-04-12 12:57:23 +0200 | [diff] [blame] | 543 | smc->connect_nonblock = 0; |
Hans Wippel | 3b2dec2 | 2018-05-18 09:34:18 +0200 | [diff] [blame] | 544 | return reason_code; |
| 545 | } |
| 546 | |
| 547 | /* check if there is a rdma device available for this connection. */ |
| 548 | /* called for connect and listen */ |
Karsten Graul | 228bae0 | 2019-04-12 12:57:28 +0200 | [diff] [blame] | 549 | static int smc_find_rdma_device(struct smc_sock *smc, struct smc_init_info *ini) |
Hans Wippel | 3b2dec2 | 2018-05-18 09:34:18 +0200 | [diff] [blame] | 550 | { |
Hans Wippel | 3b2dec2 | 2018-05-18 09:34:18 +0200 | [diff] [blame] | 551 | /* PNET table look up: search active ib_device and port |
| 552 | * within same PNETID that also contains the ethernet device |
| 553 | * used for the internal TCP socket |
| 554 | */ |
Karsten Graul | bc36d2f | 2019-04-12 12:57:26 +0200 | [diff] [blame] | 555 | smc_pnet_find_roce_resource(smc->clcsock->sk, ini); |
Karsten Graul | 9aa68d2 | 2019-04-12 12:57:29 +0200 | [diff] [blame] | 556 | if (!ini->ib_dev) |
| 557 | return SMC_CLC_DECL_NOSMCRDEV; |
Karsten Graul | bc36d2f | 2019-04-12 12:57:26 +0200 | [diff] [blame] | 558 | return 0; |
Hans Wippel | 3b2dec2 | 2018-05-18 09:34:18 +0200 | [diff] [blame] | 559 | } |
| 560 | |
Hans Wippel | 4134984 | 2018-06-28 19:05:11 +0200 | [diff] [blame] | 561 | /* check if there is an ISM device available for this connection. */ |
| 562 | /* called for connect and listen */ |
Karsten Graul | 228bae0 | 2019-04-12 12:57:28 +0200 | [diff] [blame] | 563 | static int smc_find_ism_device(struct smc_sock *smc, struct smc_init_info *ini) |
Hans Wippel | 4134984 | 2018-06-28 19:05:11 +0200 | [diff] [blame] | 564 | { |
| 565 | /* Find ISM device with same PNETID as connecting interface */ |
Karsten Graul | bc36d2f | 2019-04-12 12:57:26 +0200 | [diff] [blame] | 566 | smc_pnet_find_ism_resource(smc->clcsock->sk, ini); |
Ursula Braun | 3fc6493 | 2020-09-26 12:44:23 +0200 | [diff] [blame] | 567 | if (!ini->ism_dev[0]) |
Karsten Graul | 9aa68d2 | 2019-04-12 12:57:29 +0200 | [diff] [blame] | 568 | return SMC_CLC_DECL_NOSMCDDEV; |
Ursula Braun | 8caaccf | 2020-09-26 12:44:25 +0200 | [diff] [blame^] | 569 | else |
| 570 | ini->ism_chid[0] = smc_ism_get_chid(ini->ism_dev[0]); |
Hans Wippel | 4134984 | 2018-06-28 19:05:11 +0200 | [diff] [blame] | 571 | return 0; |
| 572 | } |
| 573 | |
| 574 | /* Check for VLAN ID and register it on ISM device just for CLC handshake */ |
| 575 | static int smc_connect_ism_vlan_setup(struct smc_sock *smc, |
Karsten Graul | bc36d2f | 2019-04-12 12:57:26 +0200 | [diff] [blame] | 576 | struct smc_init_info *ini) |
Hans Wippel | 4134984 | 2018-06-28 19:05:11 +0200 | [diff] [blame] | 577 | { |
Ursula Braun | 3fc6493 | 2020-09-26 12:44:23 +0200 | [diff] [blame] | 578 | if (ini->vlan_id && smc_ism_get_vlan(ini->ism_dev[0], ini->vlan_id)) |
Karsten Graul | 7a62725 | 2019-04-12 12:57:30 +0200 | [diff] [blame] | 579 | return SMC_CLC_DECL_ISMVLANERR; |
Hans Wippel | 4134984 | 2018-06-28 19:05:11 +0200 | [diff] [blame] | 580 | return 0; |
| 581 | } |
| 582 | |
| 583 | /* cleanup temporary VLAN ID registration used for CLC handshake. If ISM is |
| 584 | * used, the VLAN ID will be registered again during the connection setup. |
| 585 | */ |
| 586 | static int smc_connect_ism_vlan_cleanup(struct smc_sock *smc, bool is_smcd, |
Karsten Graul | bc36d2f | 2019-04-12 12:57:26 +0200 | [diff] [blame] | 587 | struct smc_init_info *ini) |
Hans Wippel | 4134984 | 2018-06-28 19:05:11 +0200 | [diff] [blame] | 588 | { |
| 589 | if (!is_smcd) |
| 590 | return 0; |
Ursula Braun | 3fc6493 | 2020-09-26 12:44:23 +0200 | [diff] [blame] | 591 | if (ini->vlan_id && smc_ism_put_vlan(ini->ism_dev[0], ini->vlan_id)) |
Hans Wippel | 4134984 | 2018-06-28 19:05:11 +0200 | [diff] [blame] | 592 | return SMC_CLC_DECL_CNFERR; |
| 593 | return 0; |
| 594 | } |
| 595 | |
Hans Wippel | 3b2dec2 | 2018-05-18 09:34:18 +0200 | [diff] [blame] | 596 | /* CLC handshake during connect */ |
Hans Wippel | c758dfd | 2018-06-28 19:05:09 +0200 | [diff] [blame] | 597 | static int smc_connect_clc(struct smc_sock *smc, int smc_type, |
Hans Wippel | 3b2dec2 | 2018-05-18 09:34:18 +0200 | [diff] [blame] | 598 | struct smc_clc_msg_accept_confirm *aclc, |
Karsten Graul | bc36d2f | 2019-04-12 12:57:26 +0200 | [diff] [blame] | 599 | struct smc_init_info *ini) |
Hans Wippel | 3b2dec2 | 2018-05-18 09:34:18 +0200 | [diff] [blame] | 600 | { |
| 601 | int rc = 0; |
| 602 | |
| 603 | /* do inband token exchange */ |
Karsten Graul | bc36d2f | 2019-04-12 12:57:26 +0200 | [diff] [blame] | 604 | rc = smc_clc_send_proposal(smc, smc_type, ini); |
Hans Wippel | 3b2dec2 | 2018-05-18 09:34:18 +0200 | [diff] [blame] | 605 | if (rc) |
| 606 | return rc; |
| 607 | /* receive SMC Accept CLC message */ |
Ursula Braun | 2b59f58 | 2018-11-22 10:26:39 +0100 | [diff] [blame] | 608 | return smc_clc_wait_msg(smc, aclc, sizeof(*aclc), SMC_CLC_ACCEPT, |
| 609 | CLC_WAIT_TIME); |
Hans Wippel | 3b2dec2 | 2018-05-18 09:34:18 +0200 | [diff] [blame] | 610 | } |
| 611 | |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 612 | /* setup for RDMA connection of client */ |
Hans Wippel | 3b2dec2 | 2018-05-18 09:34:18 +0200 | [diff] [blame] | 613 | static int smc_connect_rdma(struct smc_sock *smc, |
| 614 | struct smc_clc_msg_accept_confirm *aclc, |
Karsten Graul | bc36d2f | 2019-04-12 12:57:26 +0200 | [diff] [blame] | 615 | struct smc_init_info *ini) |
Hans Wippel | 3b2dec2 | 2018-05-18 09:34:18 +0200 | [diff] [blame] | 616 | { |
Karsten Graul | 0fb0b02 | 2020-04-30 15:55:43 +0200 | [diff] [blame] | 617 | int i, reason_code = 0; |
Hans Wippel | 3b2dec2 | 2018-05-18 09:34:18 +0200 | [diff] [blame] | 618 | struct smc_link *link; |
Hans Wippel | 3b2dec2 | 2018-05-18 09:34:18 +0200 | [diff] [blame] | 619 | |
Karsten Graul | bc36d2f | 2019-04-12 12:57:26 +0200 | [diff] [blame] | 620 | ini->is_smcd = false; |
Ursula Braun | 3d9725a | 2020-09-10 18:48:23 +0200 | [diff] [blame] | 621 | ini->ib_lcl = &aclc->r0.lcl; |
| 622 | ini->ib_clcqpn = ntoh24(aclc->r0.qpn); |
Ursula Braun | f1eb02f | 2020-09-26 12:44:20 +0200 | [diff] [blame] | 623 | ini->first_contact_peer = aclc->hdr.typev2 & SMC_FIRST_CONTACT_MASK; |
Karsten Graul | bc36d2f | 2019-04-12 12:57:26 +0200 | [diff] [blame] | 624 | |
Hans Wippel | 72a36a8 | 2019-02-07 15:56:18 +0100 | [diff] [blame] | 625 | mutex_lock(&smc_client_lgr_pending); |
Karsten Graul | 7a62725 | 2019-04-12 12:57:30 +0200 | [diff] [blame] | 626 | reason_code = smc_conn_create(smc, ini); |
| 627 | if (reason_code) { |
Hans Wippel | 72a36a8 | 2019-02-07 15:56:18 +0100 | [diff] [blame] | 628 | mutex_unlock(&smc_client_lgr_pending); |
| 629 | return reason_code; |
Hans Wippel | 3b2dec2 | 2018-05-18 09:34:18 +0200 | [diff] [blame] | 630 | } |
Hans Wippel | 3b2dec2 | 2018-05-18 09:34:18 +0200 | [diff] [blame] | 631 | |
| 632 | smc_conn_save_peer_info(smc, aclc); |
| 633 | |
Ursula Braun | 5ac54d8 | 2020-09-10 18:48:21 +0200 | [diff] [blame] | 634 | if (ini->first_contact_local) { |
Karsten Graul | 0fb0b02 | 2020-04-30 15:55:43 +0200 | [diff] [blame] | 635 | link = smc->conn.lnk; |
| 636 | } else { |
| 637 | /* set link that was assigned by server */ |
| 638 | link = NULL; |
| 639 | for (i = 0; i < SMC_LINKS_PER_LGR_MAX; i++) { |
| 640 | struct smc_link *l = &smc->conn.lgr->lnk[i]; |
| 641 | |
Ursula Braun | 3d9725a | 2020-09-10 18:48:23 +0200 | [diff] [blame] | 642 | if (l->peer_qpn == ntoh24(aclc->r0.qpn) && |
| 643 | !memcmp(l->peer_gid, &aclc->r0.lcl.gid, |
| 644 | SMC_GID_SIZE) && |
| 645 | !memcmp(l->peer_mac, &aclc->r0.lcl.mac, |
| 646 | sizeof(l->peer_mac))) { |
Karsten Graul | 0fb0b02 | 2020-04-30 15:55:43 +0200 | [diff] [blame] | 647 | link = l; |
| 648 | break; |
| 649 | } |
| 650 | } |
| 651 | if (!link) |
| 652 | return smc_connect_abort(smc, SMC_CLC_DECL_NOSRVLINK, |
Ursula Braun | 5ac54d8 | 2020-09-10 18:48:21 +0200 | [diff] [blame] | 653 | ini->first_contact_local); |
Karsten Graul | 0fb0b02 | 2020-04-30 15:55:43 +0200 | [diff] [blame] | 654 | smc->conn.lnk = link; |
| 655 | } |
| 656 | |
Hans Wippel | 3b2dec2 | 2018-05-18 09:34:18 +0200 | [diff] [blame] | 657 | /* create send buffer and rmb */ |
Hans Wippel | c6ba7c9 | 2018-06-28 19:05:07 +0200 | [diff] [blame] | 658 | if (smc_buf_create(smc, false)) |
Karsten Graul | 7a62725 | 2019-04-12 12:57:30 +0200 | [diff] [blame] | 659 | return smc_connect_abort(smc, SMC_CLC_DECL_MEM, |
Ursula Braun | 5ac54d8 | 2020-09-10 18:48:21 +0200 | [diff] [blame] | 660 | ini->first_contact_local); |
Hans Wippel | 3b2dec2 | 2018-05-18 09:34:18 +0200 | [diff] [blame] | 661 | |
Ursula Braun | 5ac54d8 | 2020-09-10 18:48:21 +0200 | [diff] [blame] | 662 | if (ini->first_contact_local) |
Hans Wippel | 3b2dec2 | 2018-05-18 09:34:18 +0200 | [diff] [blame] | 663 | smc_link_save_peer_info(link, aclc); |
| 664 | |
Karsten Graul | e07d31d | 2020-04-29 17:10:42 +0200 | [diff] [blame] | 665 | if (smc_rmb_rtoken_handling(&smc->conn, link, aclc)) |
Karsten Graul | 603cc14 | 2018-07-25 16:35:32 +0200 | [diff] [blame] | 666 | return smc_connect_abort(smc, SMC_CLC_DECL_ERR_RTOK, |
Ursula Braun | 5ac54d8 | 2020-09-10 18:48:21 +0200 | [diff] [blame] | 667 | ini->first_contact_local); |
Hans Wippel | 3b2dec2 | 2018-05-18 09:34:18 +0200 | [diff] [blame] | 668 | |
| 669 | smc_close_init(smc); |
| 670 | smc_rx_init(smc); |
| 671 | |
Ursula Braun | 5ac54d8 | 2020-09-10 18:48:21 +0200 | [diff] [blame] | 672 | if (ini->first_contact_local) { |
Hans Wippel | 3b2dec2 | 2018-05-18 09:34:18 +0200 | [diff] [blame] | 673 | if (smc_ib_ready_link(link)) |
Karsten Graul | 603cc14 | 2018-07-25 16:35:32 +0200 | [diff] [blame] | 674 | return smc_connect_abort(smc, SMC_CLC_DECL_ERR_RDYLNK, |
Ursula Braun | 5ac54d8 | 2020-09-10 18:48:21 +0200 | [diff] [blame] | 675 | ini->first_contact_local); |
Hans Wippel | 3b2dec2 | 2018-05-18 09:34:18 +0200 | [diff] [blame] | 676 | } else { |
Karsten Graul | 7562a13 | 2020-05-01 12:48:01 +0200 | [diff] [blame] | 677 | if (smcr_lgr_reg_rmbs(link, smc->conn.rmb_desc)) |
Karsten Graul | 603cc14 | 2018-07-25 16:35:32 +0200 | [diff] [blame] | 678 | return smc_connect_abort(smc, SMC_CLC_DECL_ERR_REGRMB, |
Ursula Braun | 5ac54d8 | 2020-09-10 18:48:21 +0200 | [diff] [blame] | 679 | ini->first_contact_local); |
Hans Wippel | 3b2dec2 | 2018-05-18 09:34:18 +0200 | [diff] [blame] | 680 | } |
| 681 | smc_rmb_sync_sg_for_device(&smc->conn); |
| 682 | |
| 683 | reason_code = smc_clc_send_confirm(smc); |
| 684 | if (reason_code) |
Karsten Graul | 7a62725 | 2019-04-12 12:57:30 +0200 | [diff] [blame] | 685 | return smc_connect_abort(smc, reason_code, |
Ursula Braun | 5ac54d8 | 2020-09-10 18:48:21 +0200 | [diff] [blame] | 686 | ini->first_contact_local); |
Hans Wippel | 3b2dec2 | 2018-05-18 09:34:18 +0200 | [diff] [blame] | 687 | |
| 688 | smc_tx_init(smc); |
| 689 | |
Ursula Braun | 5ac54d8 | 2020-09-10 18:48:21 +0200 | [diff] [blame] | 690 | if (ini->first_contact_local) { |
Hans Wippel | 3b2dec2 | 2018-05-18 09:34:18 +0200 | [diff] [blame] | 691 | /* QP confirmation over RoCE fabric */ |
Karsten Graul | 0fb0b02 | 2020-04-30 15:55:43 +0200 | [diff] [blame] | 692 | smc_llc_flow_initiate(link->lgr, SMC_LLC_FLOW_ADD_LINK); |
Karsten Graul | b924754 | 2020-04-29 17:10:41 +0200 | [diff] [blame] | 693 | reason_code = smcr_clnt_conf_first_link(smc); |
Karsten Graul | 0fb0b02 | 2020-04-30 15:55:43 +0200 | [diff] [blame] | 694 | smc_llc_flow_stop(link->lgr, &link->lgr->llc_flow_lcl); |
Hans Wippel | 3b2dec2 | 2018-05-18 09:34:18 +0200 | [diff] [blame] | 695 | if (reason_code) |
| 696 | return smc_connect_abort(smc, reason_code, |
Ursula Braun | 5ac54d8 | 2020-09-10 18:48:21 +0200 | [diff] [blame] | 697 | ini->first_contact_local); |
Hans Wippel | 3b2dec2 | 2018-05-18 09:34:18 +0200 | [diff] [blame] | 698 | } |
Hans Wippel | 72a36a8 | 2019-02-07 15:56:18 +0100 | [diff] [blame] | 699 | mutex_unlock(&smc_client_lgr_pending); |
Hans Wippel | 3b2dec2 | 2018-05-18 09:34:18 +0200 | [diff] [blame] | 700 | |
| 701 | smc_copy_sock_settings_to_clc(smc); |
Ursula Braun | 50717a3 | 2019-04-12 12:57:23 +0200 | [diff] [blame] | 702 | smc->connect_nonblock = 0; |
Hans Wippel | 3b2dec2 | 2018-05-18 09:34:18 +0200 | [diff] [blame] | 703 | if (smc->sk.sk_state == SMC_INIT) |
| 704 | smc->sk.sk_state = SMC_ACTIVE; |
| 705 | |
| 706 | return 0; |
| 707 | } |
| 708 | |
Hans Wippel | 4134984 | 2018-06-28 19:05:11 +0200 | [diff] [blame] | 709 | /* setup for ISM connection of client */ |
| 710 | static int smc_connect_ism(struct smc_sock *smc, |
| 711 | struct smc_clc_msg_accept_confirm *aclc, |
Karsten Graul | bc36d2f | 2019-04-12 12:57:26 +0200 | [diff] [blame] | 712 | struct smc_init_info *ini) |
Hans Wippel | 4134984 | 2018-06-28 19:05:11 +0200 | [diff] [blame] | 713 | { |
Hans Wippel | 4134984 | 2018-06-28 19:05:11 +0200 | [diff] [blame] | 714 | int rc = 0; |
| 715 | |
Karsten Graul | bc36d2f | 2019-04-12 12:57:26 +0200 | [diff] [blame] | 716 | ini->is_smcd = true; |
Ursula Braun | 3fc6493 | 2020-09-26 12:44:23 +0200 | [diff] [blame] | 717 | ini->ism_peer_gid[0] = aclc->d0.gid; |
Ursula Braun | f1eb02f | 2020-09-26 12:44:20 +0200 | [diff] [blame] | 718 | ini->first_contact_peer = aclc->hdr.typev2 & SMC_FIRST_CONTACT_MASK; |
Karsten Graul | bc36d2f | 2019-04-12 12:57:26 +0200 | [diff] [blame] | 719 | |
Hans Wippel | 72a36a8 | 2019-02-07 15:56:18 +0100 | [diff] [blame] | 720 | /* there is only one lgr role for SMC-D; use server lock */ |
| 721 | mutex_lock(&smc_server_lgr_pending); |
Karsten Graul | 7a62725 | 2019-04-12 12:57:30 +0200 | [diff] [blame] | 722 | rc = smc_conn_create(smc, ini); |
| 723 | if (rc) { |
Hans Wippel | 72a36a8 | 2019-02-07 15:56:18 +0100 | [diff] [blame] | 724 | mutex_unlock(&smc_server_lgr_pending); |
Karsten Graul | 7a62725 | 2019-04-12 12:57:30 +0200 | [diff] [blame] | 725 | return rc; |
Hans Wippel | 72a36a8 | 2019-02-07 15:56:18 +0100 | [diff] [blame] | 726 | } |
Hans Wippel | 4134984 | 2018-06-28 19:05:11 +0200 | [diff] [blame] | 727 | |
| 728 | /* Create send and receive buffers */ |
Karsten Graul | 72b7f6c | 2020-07-26 20:34:28 +0200 | [diff] [blame] | 729 | rc = smc_buf_create(smc, true); |
| 730 | if (rc) |
| 731 | return smc_connect_abort(smc, (rc == -ENOSPC) ? |
| 732 | SMC_CLC_DECL_MAX_DMB : |
| 733 | SMC_CLC_DECL_MEM, |
Ursula Braun | 5ac54d8 | 2020-09-10 18:48:21 +0200 | [diff] [blame] | 734 | ini->first_contact_local); |
Hans Wippel | 4134984 | 2018-06-28 19:05:11 +0200 | [diff] [blame] | 735 | |
| 736 | smc_conn_save_peer_info(smc, aclc); |
| 737 | smc_close_init(smc); |
| 738 | smc_rx_init(smc); |
| 739 | smc_tx_init(smc); |
| 740 | |
| 741 | rc = smc_clc_send_confirm(smc); |
| 742 | if (rc) |
Ursula Braun | 5ac54d8 | 2020-09-10 18:48:21 +0200 | [diff] [blame] | 743 | return smc_connect_abort(smc, rc, ini->first_contact_local); |
Hans Wippel | 72a36a8 | 2019-02-07 15:56:18 +0100 | [diff] [blame] | 744 | mutex_unlock(&smc_server_lgr_pending); |
Hans Wippel | 4134984 | 2018-06-28 19:05:11 +0200 | [diff] [blame] | 745 | |
| 746 | smc_copy_sock_settings_to_clc(smc); |
Ursula Braun | 50717a3 | 2019-04-12 12:57:23 +0200 | [diff] [blame] | 747 | smc->connect_nonblock = 0; |
Hans Wippel | 4134984 | 2018-06-28 19:05:11 +0200 | [diff] [blame] | 748 | if (smc->sk.sk_state == SMC_INIT) |
| 749 | smc->sk.sk_state = SMC_ACTIVE; |
| 750 | |
| 751 | return 0; |
| 752 | } |
| 753 | |
Hans Wippel | 3b2dec2 | 2018-05-18 09:34:18 +0200 | [diff] [blame] | 754 | /* perform steps before actually connecting */ |
| 755 | static int __smc_connect(struct smc_sock *smc) |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 756 | { |
Hans Wippel | 4134984 | 2018-06-28 19:05:11 +0200 | [diff] [blame] | 757 | bool ism_supported = false, rdma_supported = false; |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 758 | struct smc_clc_msg_accept_confirm aclc; |
Ursula Braun | 3fc6493 | 2020-09-26 12:44:23 +0200 | [diff] [blame] | 759 | struct smc_init_info *ini = NULL; |
Hans Wippel | 4134984 | 2018-06-28 19:05:11 +0200 | [diff] [blame] | 760 | int smc_type; |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 761 | int rc = 0; |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 762 | |
Ursula Braun | ee9dfbe | 2018-04-26 17:18:21 +0200 | [diff] [blame] | 763 | if (smc->use_fallback) |
Karsten Graul | 603cc14 | 2018-07-25 16:35:32 +0200 | [diff] [blame] | 764 | return smc_connect_fallback(smc, smc->fallback_rsn); |
Ursula Braun | ee9dfbe | 2018-04-26 17:18:21 +0200 | [diff] [blame] | 765 | |
Hans Wippel | 3b2dec2 | 2018-05-18 09:34:18 +0200 | [diff] [blame] | 766 | /* if peer has not signalled SMC-capability, fall back */ |
| 767 | if (!tcp_sk(smc->clcsock->sk)->syn_smc) |
Karsten Graul | 603cc14 | 2018-07-25 16:35:32 +0200 | [diff] [blame] | 768 | return smc_connect_fallback(smc, SMC_CLC_DECL_PEERNOSMC); |
Ursula Braun | c5c1cc9 | 2017-10-25 11:01:46 +0200 | [diff] [blame] | 769 | |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 770 | /* IPSec connections opt out of SMC-R optimizations */ |
Hans Wippel | 3b2dec2 | 2018-05-18 09:34:18 +0200 | [diff] [blame] | 771 | if (using_ipsec(smc)) |
| 772 | return smc_connect_decline_fallback(smc, SMC_CLC_DECL_IPSEC); |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 773 | |
Ursula Braun | 3fc6493 | 2020-09-26 12:44:23 +0200 | [diff] [blame] | 774 | ini = kzalloc(sizeof(*ini), GFP_KERNEL); |
| 775 | if (!ini) |
| 776 | return smc_connect_decline_fallback(smc, SMC_CLC_DECL_MEM); |
| 777 | |
Karsten Graul | fba7e8e | 2019-04-12 12:57:27 +0200 | [diff] [blame] | 778 | /* get vlan id from IP device */ |
Ursula Braun | 3fc6493 | 2020-09-26 12:44:23 +0200 | [diff] [blame] | 779 | if (smc_vlan_by_tcpsk(smc->clcsock, ini)) { |
| 780 | kfree(ini); |
Karsten Graul | fba7e8e | 2019-04-12 12:57:27 +0200 | [diff] [blame] | 781 | return smc_connect_decline_fallback(smc, |
| 782 | SMC_CLC_DECL_GETVLANERR); |
Ursula Braun | 3fc6493 | 2020-09-26 12:44:23 +0200 | [diff] [blame] | 783 | } |
Hans Wippel | 4134984 | 2018-06-28 19:05:11 +0200 | [diff] [blame] | 784 | |
| 785 | /* check if there is an ism device available */ |
Ursula Braun | 3fc6493 | 2020-09-26 12:44:23 +0200 | [diff] [blame] | 786 | if (!smc_find_ism_device(smc, ini) && |
| 787 | !smc_connect_ism_vlan_setup(smc, ini)) { |
Hans Wippel | 4134984 | 2018-06-28 19:05:11 +0200 | [diff] [blame] | 788 | /* ISM is supported for this connection */ |
| 789 | ism_supported = true; |
| 790 | smc_type = SMC_TYPE_D; |
| 791 | } |
| 792 | |
| 793 | /* check if there is a rdma device available */ |
Ursula Braun | 3fc6493 | 2020-09-26 12:44:23 +0200 | [diff] [blame] | 794 | if (!smc_find_rdma_device(smc, ini)) { |
Hans Wippel | 4134984 | 2018-06-28 19:05:11 +0200 | [diff] [blame] | 795 | /* RDMA is supported for this connection */ |
| 796 | rdma_supported = true; |
| 797 | if (ism_supported) |
| 798 | smc_type = SMC_TYPE_B; /* both */ |
| 799 | else |
| 800 | smc_type = SMC_TYPE_R; /* only RDMA */ |
| 801 | } |
| 802 | |
| 803 | /* if neither ISM nor RDMA are supported, fallback */ |
Ursula Braun | 3fc6493 | 2020-09-26 12:44:23 +0200 | [diff] [blame] | 804 | if (!rdma_supported && !ism_supported) { |
| 805 | kfree(ini); |
Karsten Graul | 603cc14 | 2018-07-25 16:35:32 +0200 | [diff] [blame] | 806 | return smc_connect_decline_fallback(smc, SMC_CLC_DECL_NOSMCDEV); |
Ursula Braun | 3fc6493 | 2020-09-26 12:44:23 +0200 | [diff] [blame] | 807 | } |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 808 | |
Hans Wippel | 3b2dec2 | 2018-05-18 09:34:18 +0200 | [diff] [blame] | 809 | /* perform CLC handshake */ |
Ursula Braun | 3fc6493 | 2020-09-26 12:44:23 +0200 | [diff] [blame] | 810 | rc = smc_connect_clc(smc, smc_type, &aclc, ini); |
Hans Wippel | 4134984 | 2018-06-28 19:05:11 +0200 | [diff] [blame] | 811 | if (rc) { |
Ursula Braun | 3fc6493 | 2020-09-26 12:44:23 +0200 | [diff] [blame] | 812 | smc_connect_ism_vlan_cleanup(smc, ism_supported, ini); |
| 813 | kfree(ini); |
Hans Wippel | 3b2dec2 | 2018-05-18 09:34:18 +0200 | [diff] [blame] | 814 | return smc_connect_decline_fallback(smc, rc); |
Hans Wippel | 4134984 | 2018-06-28 19:05:11 +0200 | [diff] [blame] | 815 | } |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 816 | |
Hans Wippel | 4134984 | 2018-06-28 19:05:11 +0200 | [diff] [blame] | 817 | /* depending on previous steps, connect using rdma or ism */ |
Ursula Braun | f1eb02f | 2020-09-26 12:44:20 +0200 | [diff] [blame] | 818 | if (rdma_supported && aclc.hdr.typev1 == SMC_TYPE_R) |
Ursula Braun | 3fc6493 | 2020-09-26 12:44:23 +0200 | [diff] [blame] | 819 | rc = smc_connect_rdma(smc, &aclc, ini); |
Ursula Braun | f1eb02f | 2020-09-26 12:44:20 +0200 | [diff] [blame] | 820 | else if (ism_supported && aclc.hdr.typev1 == SMC_TYPE_D) |
Ursula Braun | 3fc6493 | 2020-09-26 12:44:23 +0200 | [diff] [blame] | 821 | rc = smc_connect_ism(smc, &aclc, ini); |
Hans Wippel | 4134984 | 2018-06-28 19:05:11 +0200 | [diff] [blame] | 822 | else |
Karsten Graul | 603cc14 | 2018-07-25 16:35:32 +0200 | [diff] [blame] | 823 | rc = SMC_CLC_DECL_MODEUNSUPP; |
Hans Wippel | 4134984 | 2018-06-28 19:05:11 +0200 | [diff] [blame] | 824 | if (rc) { |
Ursula Braun | 3fc6493 | 2020-09-26 12:44:23 +0200 | [diff] [blame] | 825 | smc_connect_ism_vlan_cleanup(smc, ism_supported, ini); |
| 826 | kfree(ini); |
Hans Wippel | 3b2dec2 | 2018-05-18 09:34:18 +0200 | [diff] [blame] | 827 | return smc_connect_decline_fallback(smc, rc); |
Hans Wippel | 4134984 | 2018-06-28 19:05:11 +0200 | [diff] [blame] | 828 | } |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 829 | |
Ursula Braun | 3fc6493 | 2020-09-26 12:44:23 +0200 | [diff] [blame] | 830 | smc_connect_ism_vlan_cleanup(smc, ism_supported, ini); |
| 831 | kfree(ini); |
Hans Wippel | 3b2dec2 | 2018-05-18 09:34:18 +0200 | [diff] [blame] | 832 | return 0; |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 833 | } |
| 834 | |
Ursula Braun | 24ac3a0 | 2018-06-27 17:59:50 +0200 | [diff] [blame] | 835 | static void smc_connect_work(struct work_struct *work) |
| 836 | { |
| 837 | struct smc_sock *smc = container_of(work, struct smc_sock, |
| 838 | connect_work); |
Ursula Braun | 50717a3 | 2019-04-12 12:57:23 +0200 | [diff] [blame] | 839 | long timeo = smc->sk.sk_sndtimeo; |
| 840 | int rc = 0; |
Ursula Braun | 24ac3a0 | 2018-06-27 17:59:50 +0200 | [diff] [blame] | 841 | |
Ursula Braun | 50717a3 | 2019-04-12 12:57:23 +0200 | [diff] [blame] | 842 | if (!timeo) |
| 843 | timeo = MAX_SCHEDULE_TIMEOUT; |
| 844 | lock_sock(smc->clcsock->sk); |
Ursula Braun | 24ac3a0 | 2018-06-27 17:59:50 +0200 | [diff] [blame] | 845 | if (smc->clcsock->sk->sk_err) { |
| 846 | smc->sk.sk_err = smc->clcsock->sk->sk_err; |
Ursula Braun | 50717a3 | 2019-04-12 12:57:23 +0200 | [diff] [blame] | 847 | } else if ((1 << smc->clcsock->sk->sk_state) & |
| 848 | (TCPF_SYN_SENT | TCP_SYN_RECV)) { |
| 849 | rc = sk_stream_wait_connect(smc->clcsock->sk, &timeo); |
| 850 | if ((rc == -EPIPE) && |
| 851 | ((1 << smc->clcsock->sk->sk_state) & |
| 852 | (TCPF_ESTABLISHED | TCPF_CLOSE_WAIT))) |
| 853 | rc = 0; |
Ursula Braun | 24ac3a0 | 2018-06-27 17:59:50 +0200 | [diff] [blame] | 854 | } |
Ursula Braun | 50717a3 | 2019-04-12 12:57:23 +0200 | [diff] [blame] | 855 | release_sock(smc->clcsock->sk); |
| 856 | lock_sock(&smc->sk); |
| 857 | if (rc != 0 || smc->sk.sk_err) { |
| 858 | smc->sk.sk_state = SMC_CLOSED; |
| 859 | if (rc == -EPIPE || rc == -EAGAIN) |
| 860 | smc->sk.sk_err = EPIPE; |
| 861 | else if (signal_pending(current)) |
| 862 | smc->sk.sk_err = -sock_intr_errno(timeo); |
Ursula Braun | 6d6dd52 | 2019-11-12 16:03:41 +0100 | [diff] [blame] | 863 | sock_put(&smc->sk); /* passive closing */ |
Ursula Braun | 24ac3a0 | 2018-06-27 17:59:50 +0200 | [diff] [blame] | 864 | goto out; |
| 865 | } |
| 866 | |
| 867 | rc = __smc_connect(smc); |
| 868 | if (rc < 0) |
| 869 | smc->sk.sk_err = -rc; |
| 870 | |
| 871 | out: |
Ursula Braun | 07603b2 | 2019-04-11 11:17:32 +0200 | [diff] [blame] | 872 | if (!sock_flag(&smc->sk, SOCK_DEAD)) { |
| 873 | if (smc->sk.sk_err) { |
| 874 | smc->sk.sk_state_change(&smc->sk); |
| 875 | } else { /* allow polling before and after fallback decision */ |
| 876 | smc->clcsock->sk->sk_write_space(smc->clcsock->sk); |
| 877 | smc->sk.sk_write_space(&smc->sk); |
| 878 | } |
| 879 | } |
Ursula Braun | 24ac3a0 | 2018-06-27 17:59:50 +0200 | [diff] [blame] | 880 | release_sock(&smc->sk); |
| 881 | } |
| 882 | |
Ursula Braun | ac71387 | 2017-01-09 16:55:13 +0100 | [diff] [blame] | 883 | static int smc_connect(struct socket *sock, struct sockaddr *addr, |
| 884 | int alen, int flags) |
| 885 | { |
| 886 | struct sock *sk = sock->sk; |
| 887 | struct smc_sock *smc; |
| 888 | int rc = -EINVAL; |
| 889 | |
| 890 | smc = smc_sk(sk); |
| 891 | |
| 892 | /* separate smc parameter checking to be safe */ |
| 893 | if (alen < sizeof(addr->sa_family)) |
| 894 | goto out_err; |
Karsten Graul | aaa4d33 | 2018-03-16 15:06:41 +0100 | [diff] [blame] | 895 | if (addr->sa_family != AF_INET && addr->sa_family != AF_INET6) |
Ursula Braun | ac71387 | 2017-01-09 16:55:13 +0100 | [diff] [blame] | 896 | goto out_err; |
| 897 | |
| 898 | lock_sock(sk); |
| 899 | switch (sk->sk_state) { |
| 900 | default: |
| 901 | goto out; |
| 902 | case SMC_ACTIVE: |
| 903 | rc = -EISCONN; |
| 904 | goto out; |
| 905 | case SMC_INIT: |
| 906 | rc = 0; |
| 907 | break; |
| 908 | } |
| 909 | |
| 910 | smc_copy_sock_settings_to_clc(smc); |
Ursula Braun | c5c1cc9 | 2017-10-25 11:01:46 +0200 | [diff] [blame] | 911 | tcp_sk(smc->clcsock->sk)->syn_smc = 1; |
Ursula Braun | 50717a3 | 2019-04-12 12:57:23 +0200 | [diff] [blame] | 912 | if (smc->connect_nonblock) { |
| 913 | rc = -EALREADY; |
| 914 | goto out; |
| 915 | } |
| 916 | rc = kernel_connect(smc->clcsock, addr, alen, flags); |
| 917 | if (rc && rc != -EINPROGRESS) |
| 918 | goto out; |
Ursula Braun | 301428e | 2019-10-29 12:41:26 +0100 | [diff] [blame] | 919 | |
| 920 | sock_hold(&smc->sk); /* sock put in passive closing */ |
Ursula Braun | 8643474 | 2019-12-12 22:35:58 +0100 | [diff] [blame] | 921 | if (smc->use_fallback) |
| 922 | goto out; |
Ursula Braun | 24ac3a0 | 2018-06-27 17:59:50 +0200 | [diff] [blame] | 923 | if (flags & O_NONBLOCK) { |
Karsten Graul | 22ef473 | 2020-09-10 18:48:29 +0200 | [diff] [blame] | 924 | if (queue_work(smc_hs_wq, &smc->connect_work)) |
Ursula Braun | 50717a3 | 2019-04-12 12:57:23 +0200 | [diff] [blame] | 925 | smc->connect_nonblock = 1; |
Ursula Braun | 24ac3a0 | 2018-06-27 17:59:50 +0200 | [diff] [blame] | 926 | rc = -EINPROGRESS; |
| 927 | } else { |
Ursula Braun | 24ac3a0 | 2018-06-27 17:59:50 +0200 | [diff] [blame] | 928 | rc = __smc_connect(smc); |
| 929 | if (rc < 0) |
| 930 | goto out; |
| 931 | else |
| 932 | rc = 0; /* success cases including fallback */ |
| 933 | } |
Ursula Braun | ac71387 | 2017-01-09 16:55:13 +0100 | [diff] [blame] | 934 | |
| 935 | out: |
| 936 | release_sock(sk); |
| 937 | out_err: |
| 938 | return rc; |
| 939 | } |
| 940 | |
| 941 | static int smc_clcsock_accept(struct smc_sock *lsmc, struct smc_sock **new_smc) |
| 942 | { |
Ursula Braun | 3163c50 | 2018-01-24 10:28:12 +0100 | [diff] [blame] | 943 | struct socket *new_clcsock = NULL; |
| 944 | struct sock *lsk = &lsmc->sk; |
Ursula Braun | ac71387 | 2017-01-09 16:55:13 +0100 | [diff] [blame] | 945 | struct sock *new_sk; |
Myungho Jung | 78abe3d | 2018-12-18 09:02:25 -0800 | [diff] [blame] | 946 | int rc = -EINVAL; |
Ursula Braun | ac71387 | 2017-01-09 16:55:13 +0100 | [diff] [blame] | 947 | |
Ursula Braun | 3163c50 | 2018-01-24 10:28:12 +0100 | [diff] [blame] | 948 | release_sock(lsk); |
Karsten Graul | aaa4d33 | 2018-03-16 15:06:41 +0100 | [diff] [blame] | 949 | new_sk = smc_sock_alloc(sock_net(lsk), NULL, lsk->sk_protocol); |
Ursula Braun | ac71387 | 2017-01-09 16:55:13 +0100 | [diff] [blame] | 950 | if (!new_sk) { |
| 951 | rc = -ENOMEM; |
Ursula Braun | 3163c50 | 2018-01-24 10:28:12 +0100 | [diff] [blame] | 952 | lsk->sk_err = ENOMEM; |
Ursula Braun | ac71387 | 2017-01-09 16:55:13 +0100 | [diff] [blame] | 953 | *new_smc = NULL; |
Ursula Braun | 3163c50 | 2018-01-24 10:28:12 +0100 | [diff] [blame] | 954 | lock_sock(lsk); |
Ursula Braun | ac71387 | 2017-01-09 16:55:13 +0100 | [diff] [blame] | 955 | goto out; |
| 956 | } |
| 957 | *new_smc = smc_sk(new_sk); |
| 958 | |
Myungho Jung | 78abe3d | 2018-12-18 09:02:25 -0800 | [diff] [blame] | 959 | mutex_lock(&lsmc->clcsock_release_lock); |
| 960 | if (lsmc->clcsock) |
Ursula Braun | a60a2b1 | 2020-09-10 18:48:20 +0200 | [diff] [blame] | 961 | rc = kernel_accept(lsmc->clcsock, &new_clcsock, SOCK_NONBLOCK); |
Myungho Jung | 78abe3d | 2018-12-18 09:02:25 -0800 | [diff] [blame] | 962 | mutex_unlock(&lsmc->clcsock_release_lock); |
Ursula Braun | 3163c50 | 2018-01-24 10:28:12 +0100 | [diff] [blame] | 963 | lock_sock(lsk); |
Ursula Braun | a60a2b1 | 2020-09-10 18:48:20 +0200 | [diff] [blame] | 964 | if (rc < 0 && rc != -EAGAIN) |
Ursula Braun | 3163c50 | 2018-01-24 10:28:12 +0100 | [diff] [blame] | 965 | lsk->sk_err = -rc; |
Ursula Braun | 35a6b17 | 2018-01-24 10:28:13 +0100 | [diff] [blame] | 966 | if (rc < 0 || lsk->sk_state == SMC_CLOSED) { |
Ursula Braun | f61bca5 | 2019-04-11 11:17:34 +0200 | [diff] [blame] | 967 | new_sk->sk_prot->unhash(new_sk); |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 968 | if (new_clcsock) |
| 969 | sock_release(new_clcsock); |
| 970 | new_sk->sk_state = SMC_CLOSED; |
| 971 | sock_set_flag(new_sk, SOCK_DEAD); |
Ursula Braun | 51f1de7 | 2018-01-26 09:28:48 +0100 | [diff] [blame] | 972 | sock_put(new_sk); /* final */ |
Ursula Braun | ac71387 | 2017-01-09 16:55:13 +0100 | [diff] [blame] | 973 | *new_smc = NULL; |
| 974 | goto out; |
| 975 | } |
| 976 | |
Ursula Braun | a60a2b1 | 2020-09-10 18:48:20 +0200 | [diff] [blame] | 977 | /* new clcsock has inherited the smc listen-specific sk_data_ready |
| 978 | * function; switch it back to the original sk_data_ready function |
| 979 | */ |
| 980 | new_clcsock->sk->sk_data_ready = lsmc->clcsk_data_ready; |
Ursula Braun | ac71387 | 2017-01-09 16:55:13 +0100 | [diff] [blame] | 981 | (*new_smc)->clcsock = new_clcsock; |
| 982 | out: |
| 983 | return rc; |
| 984 | } |
| 985 | |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 986 | /* add a just created sock to the accept queue of the listen sock as |
| 987 | * candidate for a following socket accept call from user space |
| 988 | */ |
| 989 | static void smc_accept_enqueue(struct sock *parent, struct sock *sk) |
| 990 | { |
| 991 | struct smc_sock *par = smc_sk(parent); |
| 992 | |
Ursula Braun | 51f1de7 | 2018-01-26 09:28:48 +0100 | [diff] [blame] | 993 | sock_hold(sk); /* sock_put in smc_accept_unlink () */ |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 994 | spin_lock(&par->accept_q_lock); |
| 995 | list_add_tail(&smc_sk(sk)->accept_q, &par->accept_q); |
| 996 | spin_unlock(&par->accept_q_lock); |
| 997 | sk_acceptq_added(parent); |
| 998 | } |
| 999 | |
| 1000 | /* remove a socket from the accept queue of its parental listening socket */ |
| 1001 | static void smc_accept_unlink(struct sock *sk) |
| 1002 | { |
| 1003 | struct smc_sock *par = smc_sk(sk)->listen_smc; |
| 1004 | |
| 1005 | spin_lock(&par->accept_q_lock); |
| 1006 | list_del_init(&smc_sk(sk)->accept_q); |
| 1007 | spin_unlock(&par->accept_q_lock); |
| 1008 | sk_acceptq_removed(&smc_sk(sk)->listen_smc->sk); |
Ursula Braun | 51f1de7 | 2018-01-26 09:28:48 +0100 | [diff] [blame] | 1009 | sock_put(sk); /* sock_hold in smc_accept_enqueue */ |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 1010 | } |
| 1011 | |
| 1012 | /* remove a sock from the accept queue to bind it to a new socket created |
| 1013 | * for a socket accept call from user space |
| 1014 | */ |
Ursula Braun | b38d732 | 2017-01-09 16:55:25 +0100 | [diff] [blame] | 1015 | struct sock *smc_accept_dequeue(struct sock *parent, |
| 1016 | struct socket *new_sock) |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 1017 | { |
| 1018 | struct smc_sock *isk, *n; |
| 1019 | struct sock *new_sk; |
| 1020 | |
| 1021 | list_for_each_entry_safe(isk, n, &smc_sk(parent)->accept_q, accept_q) { |
| 1022 | new_sk = (struct sock *)isk; |
| 1023 | |
| 1024 | smc_accept_unlink(new_sk); |
| 1025 | if (new_sk->sk_state == SMC_CLOSED) { |
Ursula Braun | f61bca5 | 2019-04-11 11:17:34 +0200 | [diff] [blame] | 1026 | new_sk->sk_prot->unhash(new_sk); |
Ursula Braun | 127f497 | 2018-01-26 09:28:49 +0100 | [diff] [blame] | 1027 | if (isk->clcsock) { |
| 1028 | sock_release(isk->clcsock); |
| 1029 | isk->clcsock = NULL; |
| 1030 | } |
Ursula Braun | 51f1de7 | 2018-01-26 09:28:48 +0100 | [diff] [blame] | 1031 | sock_put(new_sk); /* final */ |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 1032 | continue; |
| 1033 | } |
Ursula Braun | 07603b2 | 2019-04-11 11:17:32 +0200 | [diff] [blame] | 1034 | if (new_sock) { |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 1035 | sock_graft(new_sk, new_sock); |
Ursula Braun | 07603b2 | 2019-04-11 11:17:32 +0200 | [diff] [blame] | 1036 | if (isk->use_fallback) { |
| 1037 | smc_sk(new_sk)->clcsock->file = new_sock->file; |
| 1038 | isk->clcsock->file->private_data = isk->clcsock; |
| 1039 | } |
| 1040 | } |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 1041 | return new_sk; |
| 1042 | } |
| 1043 | return NULL; |
| 1044 | } |
| 1045 | |
| 1046 | /* clean up for a created but never accepted sock */ |
Ursula Braun | b38d732 | 2017-01-09 16:55:25 +0100 | [diff] [blame] | 1047 | void smc_close_non_accepted(struct sock *sk) |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 1048 | { |
| 1049 | struct smc_sock *smc = smc_sk(sk); |
| 1050 | |
Ursula Braun | 81cf4f4 | 2019-10-21 16:13:15 +0200 | [diff] [blame] | 1051 | sock_hold(sk); /* sock_put below */ |
Ursula Braun | b38d732 | 2017-01-09 16:55:25 +0100 | [diff] [blame] | 1052 | lock_sock(sk); |
| 1053 | if (!sk->sk_lingertime) |
| 1054 | /* wait for peer closing */ |
| 1055 | sk->sk_lingertime = SMC_MAX_STREAM_WAIT_TIMEOUT; |
Ursula Braun | 39f41f3 | 2019-06-27 15:04:52 +0200 | [diff] [blame] | 1056 | __smc_release(smc); |
Ursula Braun | b38d732 | 2017-01-09 16:55:25 +0100 | [diff] [blame] | 1057 | release_sock(sk); |
Ursula Braun | 81cf4f4 | 2019-10-21 16:13:15 +0200 | [diff] [blame] | 1058 | sock_put(sk); /* sock_hold above */ |
Ursula Braun | 51f1de7 | 2018-01-26 09:28:48 +0100 | [diff] [blame] | 1059 | sock_put(sk); /* final sock_put */ |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 1060 | } |
| 1061 | |
Karsten Graul | b924754 | 2020-04-29 17:10:41 +0200 | [diff] [blame] | 1062 | static int smcr_serv_conf_first_link(struct smc_sock *smc) |
Ursula Braun | 9bf9abe | 2017-01-09 16:55:21 +0100 | [diff] [blame] | 1063 | { |
Karsten Graul | 387707f | 2020-04-29 17:10:40 +0200 | [diff] [blame] | 1064 | struct smc_link *link = smc->conn.lnk; |
Karsten Graul | 4667bb4 | 2020-04-30 15:55:42 +0200 | [diff] [blame] | 1065 | struct smc_llc_qentry *qentry; |
Ursula Braun | 9bf9abe | 2017-01-09 16:55:21 +0100 | [diff] [blame] | 1066 | int rc; |
| 1067 | |
Karsten Graul | 7562a13 | 2020-05-01 12:48:01 +0200 | [diff] [blame] | 1068 | if (smcr_link_reg_rmb(link, smc->conn.rmb_desc)) |
Karsten Graul | 603cc14 | 2018-07-25 16:35:32 +0200 | [diff] [blame] | 1069 | return SMC_CLC_DECL_ERR_REGRMB; |
Ursula Braun | 652a1e4 | 2017-07-28 13:56:17 +0200 | [diff] [blame] | 1070 | |
Ursula Braun | 9bf9abe | 2017-01-09 16:55:21 +0100 | [diff] [blame] | 1071 | /* send CONFIRM LINK request to client over the RoCE fabric */ |
Ursula Braun | 947541f | 2018-07-25 16:35:30 +0200 | [diff] [blame] | 1072 | rc = smc_llc_send_confirm_link(link, SMC_LLC_REQ); |
Ursula Braun | 9bf9abe | 2017-01-09 16:55:21 +0100 | [diff] [blame] | 1073 | if (rc < 0) |
Karsten Graul | 603cc14 | 2018-07-25 16:35:32 +0200 | [diff] [blame] | 1074 | return SMC_CLC_DECL_TIMEOUT_CL; |
Ursula Braun | 9bf9abe | 2017-01-09 16:55:21 +0100 | [diff] [blame] | 1075 | |
| 1076 | /* receive CONFIRM LINK response from client over the RoCE fabric */ |
Karsten Graul | 4667bb4 | 2020-04-30 15:55:42 +0200 | [diff] [blame] | 1077 | qentry = smc_llc_wait(link->lgr, link, SMC_LLC_WAIT_TIME, |
| 1078 | SMC_LLC_CONFIRM_LINK); |
| 1079 | if (!qentry) { |
Ursula Braun | 9bf9abe | 2017-01-09 16:55:21 +0100 | [diff] [blame] | 1080 | struct smc_clc_msg_decline dclc; |
| 1081 | |
| 1082 | rc = smc_clc_wait_msg(smc, &dclc, sizeof(dclc), |
Ursula Braun | 2b59f58 | 2018-11-22 10:26:39 +0100 | [diff] [blame] | 1083 | SMC_CLC_DECLINE, CLC_WAIT_TIME_SHORT); |
Ursula Braun | 9ed2855 | 2018-11-22 10:26:37 +0100 | [diff] [blame] | 1084 | return rc == -EAGAIN ? SMC_CLC_DECL_TIMEOUT_CL : rc; |
Ursula Braun | 9bf9abe | 2017-01-09 16:55:21 +0100 | [diff] [blame] | 1085 | } |
Karsten Graul | 649758f | 2020-05-04 14:18:48 +0200 | [diff] [blame] | 1086 | smc_llc_save_peer_uid(qentry); |
Karsten Graul | 4667bb4 | 2020-04-30 15:55:42 +0200 | [diff] [blame] | 1087 | rc = smc_llc_eval_conf_link(qentry, SMC_LLC_RESP); |
| 1088 | smc_llc_flow_qentry_del(&link->lgr->llc_flow_lcl); |
| 1089 | if (rc) |
Karsten Graul | 75d320d | 2018-03-01 13:51:31 +0100 | [diff] [blame] | 1090 | return SMC_CLC_DECL_RMBE_EC; |
| 1091 | |
Karsten Graul | 4667bb4 | 2020-04-30 15:55:42 +0200 | [diff] [blame] | 1092 | /* confirm_rkey is implicit on 1st contact */ |
| 1093 | smc->conn.rmb_desc->is_conf_rkey = true; |
Karsten Graul | 52bedf3 | 2018-03-01 13:51:32 +0100 | [diff] [blame] | 1094 | |
Karsten Graul | 00a049c | 2020-04-29 17:10:49 +0200 | [diff] [blame] | 1095 | smc_llc_link_active(link); |
Karsten Graul | 0a99be4 | 2020-05-05 15:01:20 +0200 | [diff] [blame] | 1096 | smcr_lgr_set_type(link->lgr, SMC_LGR_SINGLE); |
Karsten Graul | 52bedf3 | 2018-03-01 13:51:32 +0100 | [diff] [blame] | 1097 | |
Karsten Graul | 4667bb4 | 2020-04-30 15:55:42 +0200 | [diff] [blame] | 1098 | /* initial contact - try to establish second link */ |
Karsten Graul | 2d2209f | 2020-05-03 14:38:43 +0200 | [diff] [blame] | 1099 | smc_llc_srv_add_link(link); |
Karsten Graul | 75d320d | 2018-03-01 13:51:31 +0100 | [diff] [blame] | 1100 | return 0; |
Ursula Braun | 9bf9abe | 2017-01-09 16:55:21 +0100 | [diff] [blame] | 1101 | } |
| 1102 | |
Hans Wippel | 3b2dec2 | 2018-05-18 09:34:18 +0200 | [diff] [blame] | 1103 | /* listen worker: finish */ |
| 1104 | static void smc_listen_out(struct smc_sock *new_smc) |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 1105 | { |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 1106 | struct smc_sock *lsmc = new_smc->listen_smc; |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 1107 | struct sock *newsmcsk = &new_smc->sk; |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 1108 | |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 1109 | if (lsmc->sk.sk_state == SMC_LISTEN) { |
Karsten Graul | fd57770 | 2019-04-11 11:17:30 +0200 | [diff] [blame] | 1110 | lock_sock_nested(&lsmc->sk, SINGLE_DEPTH_NESTING); |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 1111 | smc_accept_enqueue(&lsmc->sk, newsmcsk); |
Karsten Graul | fd57770 | 2019-04-11 11:17:30 +0200 | [diff] [blame] | 1112 | release_sock(&lsmc->sk); |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 1113 | } else { /* no longer listening */ |
| 1114 | smc_close_non_accepted(newsmcsk); |
| 1115 | } |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 1116 | |
| 1117 | /* Wake up accept */ |
| 1118 | lsmc->sk.sk_data_ready(&lsmc->sk); |
| 1119 | sock_put(&lsmc->sk); /* sock_hold in smc_tcp_listen_work */ |
Hans Wippel | 3b2dec2 | 2018-05-18 09:34:18 +0200 | [diff] [blame] | 1120 | } |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 1121 | |
Hans Wippel | 3b2dec2 | 2018-05-18 09:34:18 +0200 | [diff] [blame] | 1122 | /* listen worker: finish in state connected */ |
| 1123 | static void smc_listen_out_connected(struct smc_sock *new_smc) |
| 1124 | { |
| 1125 | struct sock *newsmcsk = &new_smc->sk; |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 1126 | |
Hans Wippel | 3b2dec2 | 2018-05-18 09:34:18 +0200 | [diff] [blame] | 1127 | sk_refcnt_debug_inc(newsmcsk); |
| 1128 | if (newsmcsk->sk_state == SMC_INIT) |
| 1129 | newsmcsk->sk_state = SMC_ACTIVE; |
| 1130 | |
| 1131 | smc_listen_out(new_smc); |
| 1132 | } |
| 1133 | |
| 1134 | /* listen worker: finish in error state */ |
| 1135 | static void smc_listen_out_err(struct smc_sock *new_smc) |
| 1136 | { |
| 1137 | struct sock *newsmcsk = &new_smc->sk; |
| 1138 | |
Ursula Braun | 51f1de7 | 2018-01-26 09:28:48 +0100 | [diff] [blame] | 1139 | if (newsmcsk->sk_state == SMC_INIT) |
| 1140 | sock_put(&new_smc->sk); /* passive closing */ |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 1141 | newsmcsk->sk_state = SMC_CLOSED; |
Hans Wippel | 3b2dec2 | 2018-05-18 09:34:18 +0200 | [diff] [blame] | 1142 | |
| 1143 | smc_listen_out(new_smc); |
| 1144 | } |
| 1145 | |
| 1146 | /* listen worker: decline and fall back if possible */ |
| 1147 | static void smc_listen_decline(struct smc_sock *new_smc, int reason_code, |
Ursula Braun | 5ac54d8 | 2020-09-10 18:48:21 +0200 | [diff] [blame] | 1148 | bool local_first) |
Hans Wippel | 3b2dec2 | 2018-05-18 09:34:18 +0200 | [diff] [blame] | 1149 | { |
| 1150 | /* RDMA setup failed, switch back to TCP */ |
Ursula Braun | 5ac54d8 | 2020-09-10 18:48:21 +0200 | [diff] [blame] | 1151 | if (local_first) |
Ursula Braun | 51e3dfa | 2020-02-25 16:34:36 +0100 | [diff] [blame] | 1152 | smc_lgr_cleanup_early(&new_smc->conn); |
| 1153 | else |
| 1154 | smc_conn_free(&new_smc->conn); |
Hans Wippel | 3b2dec2 | 2018-05-18 09:34:18 +0200 | [diff] [blame] | 1155 | if (reason_code < 0) { /* error, no fallback possible */ |
| 1156 | smc_listen_out_err(new_smc); |
| 1157 | return; |
| 1158 | } |
Ursula Braun | 07603b2 | 2019-04-11 11:17:32 +0200 | [diff] [blame] | 1159 | smc_switch_to_fallback(new_smc); |
Karsten Graul | 603cc14 | 2018-07-25 16:35:32 +0200 | [diff] [blame] | 1160 | new_smc->fallback_rsn = reason_code; |
| 1161 | if (reason_code && reason_code != SMC_CLC_DECL_PEERDECL) { |
Hans Wippel | 3b2dec2 | 2018-05-18 09:34:18 +0200 | [diff] [blame] | 1162 | if (smc_clc_send_decline(new_smc, reason_code) < 0) { |
| 1163 | smc_listen_out_err(new_smc); |
| 1164 | return; |
| 1165 | } |
| 1166 | } |
| 1167 | smc_listen_out_connected(new_smc); |
| 1168 | } |
| 1169 | |
| 1170 | /* listen worker: check prefixes */ |
Karsten Graul | 5988669 | 2019-04-12 12:57:25 +0200 | [diff] [blame] | 1171 | static int smc_listen_prfx_check(struct smc_sock *new_smc, |
Hans Wippel | 3b2dec2 | 2018-05-18 09:34:18 +0200 | [diff] [blame] | 1172 | struct smc_clc_msg_proposal *pclc) |
| 1173 | { |
| 1174 | struct smc_clc_msg_proposal_prefix *pclc_prfx; |
| 1175 | struct socket *newclcsock = new_smc->clcsock; |
| 1176 | |
| 1177 | pclc_prfx = smc_clc_proposal_get_prefix(pclc); |
| 1178 | if (smc_clc_prfx_match(newclcsock, pclc_prfx)) |
Karsten Graul | 5988669 | 2019-04-12 12:57:25 +0200 | [diff] [blame] | 1179 | return SMC_CLC_DECL_DIFFPREFIX; |
Hans Wippel | 3b2dec2 | 2018-05-18 09:34:18 +0200 | [diff] [blame] | 1180 | |
| 1181 | return 0; |
| 1182 | } |
| 1183 | |
| 1184 | /* listen worker: initialize connection and buffers */ |
| 1185 | static int smc_listen_rdma_init(struct smc_sock *new_smc, |
Karsten Graul | 7a62725 | 2019-04-12 12:57:30 +0200 | [diff] [blame] | 1186 | struct smc_init_info *ini) |
Hans Wippel | 3b2dec2 | 2018-05-18 09:34:18 +0200 | [diff] [blame] | 1187 | { |
Karsten Graul | 7a62725 | 2019-04-12 12:57:30 +0200 | [diff] [blame] | 1188 | int rc; |
| 1189 | |
Hans Wippel | 3b2dec2 | 2018-05-18 09:34:18 +0200 | [diff] [blame] | 1190 | /* allocate connection / link group */ |
Karsten Graul | 7a62725 | 2019-04-12 12:57:30 +0200 | [diff] [blame] | 1191 | rc = smc_conn_create(new_smc, ini); |
| 1192 | if (rc) |
| 1193 | return rc; |
Hans Wippel | 3b2dec2 | 2018-05-18 09:34:18 +0200 | [diff] [blame] | 1194 | |
| 1195 | /* create send buffer and rmb */ |
Hans Wippel | c6ba7c9 | 2018-06-28 19:05:07 +0200 | [diff] [blame] | 1196 | if (smc_buf_create(new_smc, false)) |
Hans Wippel | 3b2dec2 | 2018-05-18 09:34:18 +0200 | [diff] [blame] | 1197 | return SMC_CLC_DECL_MEM; |
| 1198 | |
| 1199 | return 0; |
| 1200 | } |
| 1201 | |
Hans Wippel | 4134984 | 2018-06-28 19:05:11 +0200 | [diff] [blame] | 1202 | /* listen worker: initialize connection and buffers for SMC-D */ |
| 1203 | static int smc_listen_ism_init(struct smc_sock *new_smc, |
Karsten Graul | 7a62725 | 2019-04-12 12:57:30 +0200 | [diff] [blame] | 1204 | struct smc_init_info *ini) |
Hans Wippel | 4134984 | 2018-06-28 19:05:11 +0200 | [diff] [blame] | 1205 | { |
Karsten Graul | 7a62725 | 2019-04-12 12:57:30 +0200 | [diff] [blame] | 1206 | int rc; |
Hans Wippel | 4134984 | 2018-06-28 19:05:11 +0200 | [diff] [blame] | 1207 | |
Karsten Graul | 7a62725 | 2019-04-12 12:57:30 +0200 | [diff] [blame] | 1208 | rc = smc_conn_create(new_smc, ini); |
| 1209 | if (rc) |
| 1210 | return rc; |
Hans Wippel | 4134984 | 2018-06-28 19:05:11 +0200 | [diff] [blame] | 1211 | |
Hans Wippel | 4134984 | 2018-06-28 19:05:11 +0200 | [diff] [blame] | 1212 | /* Create send and receive buffers */ |
Karsten Graul | 72b7f6c | 2020-07-26 20:34:28 +0200 | [diff] [blame] | 1213 | rc = smc_buf_create(new_smc, true); |
| 1214 | if (rc) { |
Ursula Braun | 5ac54d8 | 2020-09-10 18:48:21 +0200 | [diff] [blame] | 1215 | if (ini->first_contact_local) |
Ursula Braun | 51e3dfa | 2020-02-25 16:34:36 +0100 | [diff] [blame] | 1216 | smc_lgr_cleanup_early(&new_smc->conn); |
| 1217 | else |
| 1218 | smc_conn_free(&new_smc->conn); |
Karsten Graul | 72b7f6c | 2020-07-26 20:34:28 +0200 | [diff] [blame] | 1219 | return (rc == -ENOSPC) ? SMC_CLC_DECL_MAX_DMB : |
| 1220 | SMC_CLC_DECL_MEM; |
Hans Wippel | 4134984 | 2018-06-28 19:05:11 +0200 | [diff] [blame] | 1221 | } |
| 1222 | |
| 1223 | return 0; |
| 1224 | } |
| 1225 | |
Ursula Braun | 7affc80 | 2020-09-26 12:44:21 +0200 | [diff] [blame] | 1226 | static void smc_find_ism_device_serv(struct smc_sock *new_smc, |
| 1227 | struct smc_clc_msg_proposal *pclc, |
| 1228 | struct smc_init_info *ini) |
| 1229 | { |
| 1230 | struct smc_clc_msg_smcd *pclc_smcd = smc_get_clc_msg_smcd(pclc); |
| 1231 | |
| 1232 | if (!smcd_indicated(pclc->hdr.typev1)) |
| 1233 | goto not_found; |
| 1234 | ini->is_smcd = true; /* prepare ISM check */ |
Ursula Braun | 3fc6493 | 2020-09-26 12:44:23 +0200 | [diff] [blame] | 1235 | ini->ism_peer_gid[0] = pclc_smcd->gid; |
Ursula Braun | 7affc80 | 2020-09-26 12:44:21 +0200 | [diff] [blame] | 1236 | if (smc_find_ism_device(new_smc, ini)) |
| 1237 | goto not_found; |
| 1238 | if (!smc_listen_ism_init(new_smc, ini)) |
| 1239 | return; /* ISM device found */ |
| 1240 | |
| 1241 | not_found: |
Ursula Braun | 3fc6493 | 2020-09-26 12:44:23 +0200 | [diff] [blame] | 1242 | ini->ism_dev[0] = NULL; |
Ursula Braun | 7affc80 | 2020-09-26 12:44:21 +0200 | [diff] [blame] | 1243 | ini->is_smcd = false; |
| 1244 | } |
| 1245 | |
Hans Wippel | 3b2dec2 | 2018-05-18 09:34:18 +0200 | [diff] [blame] | 1246 | /* listen worker: register buffers */ |
Ursula Braun | 5ac54d8 | 2020-09-10 18:48:21 +0200 | [diff] [blame] | 1247 | static int smc_listen_rdma_reg(struct smc_sock *new_smc, bool local_first) |
Hans Wippel | 3b2dec2 | 2018-05-18 09:34:18 +0200 | [diff] [blame] | 1248 | { |
Karsten Graul | b924754 | 2020-04-29 17:10:41 +0200 | [diff] [blame] | 1249 | struct smc_connection *conn = &new_smc->conn; |
Hans Wippel | 3b2dec2 | 2018-05-18 09:34:18 +0200 | [diff] [blame] | 1250 | |
Ursula Braun | 5ac54d8 | 2020-09-10 18:48:21 +0200 | [diff] [blame] | 1251 | if (!local_first) { |
Karsten Graul | 7562a13 | 2020-05-01 12:48:01 +0200 | [diff] [blame] | 1252 | if (smcr_lgr_reg_rmbs(conn->lnk, conn->rmb_desc)) |
Karsten Graul | c7674c0 | 2018-11-22 10:26:43 +0100 | [diff] [blame] | 1253 | return SMC_CLC_DECL_ERR_REGRMB; |
Hans Wippel | 3b2dec2 | 2018-05-18 09:34:18 +0200 | [diff] [blame] | 1254 | } |
| 1255 | smc_rmb_sync_sg_for_device(&new_smc->conn); |
| 1256 | |
| 1257 | return 0; |
| 1258 | } |
| 1259 | |
Ursula Braun | 7affc80 | 2020-09-26 12:44:21 +0200 | [diff] [blame] | 1260 | static int smc_find_rdma_device_serv(struct smc_sock *new_smc, |
| 1261 | struct smc_clc_msg_proposal *pclc, |
| 1262 | struct smc_init_info *ini) |
| 1263 | { |
| 1264 | int rc; |
| 1265 | |
| 1266 | if (!smcr_indicated(pclc->hdr.typev1)) |
| 1267 | return SMC_CLC_DECL_NOSMCDEV; |
| 1268 | |
| 1269 | /* prepare RDMA check */ |
| 1270 | ini->ib_lcl = &pclc->lcl; |
| 1271 | rc = smc_find_rdma_device(new_smc, ini); |
| 1272 | if (rc) { |
| 1273 | /* no RDMA device found */ |
| 1274 | if (pclc->hdr.typev1 == SMC_TYPE_B) |
| 1275 | /* neither ISM nor RDMA device found */ |
| 1276 | rc = SMC_CLC_DECL_NOSMCDEV; |
| 1277 | return rc; |
| 1278 | } |
| 1279 | rc = smc_listen_rdma_init(new_smc, ini); |
| 1280 | if (rc) |
| 1281 | return rc; |
| 1282 | return smc_listen_rdma_reg(new_smc, ini->first_contact_local); |
| 1283 | } |
| 1284 | |
| 1285 | /* determine the local device matching to proposal */ |
| 1286 | static int smc_listen_find_device(struct smc_sock *new_smc, |
| 1287 | struct smc_clc_msg_proposal *pclc, |
| 1288 | struct smc_init_info *ini) |
| 1289 | { |
| 1290 | /* check if ISM is available */ |
| 1291 | smc_find_ism_device_serv(new_smc, pclc, ini); |
| 1292 | if (ini->is_smcd) |
| 1293 | return 0; |
| 1294 | if (pclc->hdr.typev1 == SMC_TYPE_D) |
| 1295 | return SMC_CLC_DECL_NOSMCDDEV; /* skip RDMA and decline */ |
| 1296 | |
| 1297 | /* check if RDMA is available */ |
| 1298 | return smc_find_rdma_device_serv(new_smc, pclc, ini); |
| 1299 | } |
| 1300 | |
Hans Wippel | 3b2dec2 | 2018-05-18 09:34:18 +0200 | [diff] [blame] | 1301 | /* listen worker: finish RDMA setup */ |
Ursula Braun | 1ca52fc | 2018-09-18 15:46:35 +0200 | [diff] [blame] | 1302 | static int smc_listen_rdma_finish(struct smc_sock *new_smc, |
| 1303 | struct smc_clc_msg_accept_confirm *cclc, |
Ursula Braun | 5ac54d8 | 2020-09-10 18:48:21 +0200 | [diff] [blame] | 1304 | bool local_first) |
Hans Wippel | 3b2dec2 | 2018-05-18 09:34:18 +0200 | [diff] [blame] | 1305 | { |
Karsten Graul | 387707f | 2020-04-29 17:10:40 +0200 | [diff] [blame] | 1306 | struct smc_link *link = new_smc->conn.lnk; |
Hans Wippel | 3b2dec2 | 2018-05-18 09:34:18 +0200 | [diff] [blame] | 1307 | int reason_code = 0; |
| 1308 | |
Ursula Braun | 5ac54d8 | 2020-09-10 18:48:21 +0200 | [diff] [blame] | 1309 | if (local_first) |
Hans Wippel | 3b2dec2 | 2018-05-18 09:34:18 +0200 | [diff] [blame] | 1310 | smc_link_save_peer_info(link, cclc); |
| 1311 | |
Ursula Braun | 0c881ad | 2020-09-10 18:48:25 +0200 | [diff] [blame] | 1312 | if (smc_rmb_rtoken_handling(&new_smc->conn, link, cclc)) |
| 1313 | return SMC_CLC_DECL_ERR_RTOK; |
Hans Wippel | 3b2dec2 | 2018-05-18 09:34:18 +0200 | [diff] [blame] | 1314 | |
Ursula Braun | 5ac54d8 | 2020-09-10 18:48:21 +0200 | [diff] [blame] | 1315 | if (local_first) { |
Ursula Braun | 0c881ad | 2020-09-10 18:48:25 +0200 | [diff] [blame] | 1316 | if (smc_ib_ready_link(link)) |
| 1317 | return SMC_CLC_DECL_ERR_RDYLNK; |
Hans Wippel | 3b2dec2 | 2018-05-18 09:34:18 +0200 | [diff] [blame] | 1318 | /* QP confirmation over RoCE fabric */ |
Karsten Graul | 4667bb4 | 2020-04-30 15:55:42 +0200 | [diff] [blame] | 1319 | smc_llc_flow_initiate(link->lgr, SMC_LLC_FLOW_ADD_LINK); |
Karsten Graul | b924754 | 2020-04-29 17:10:41 +0200 | [diff] [blame] | 1320 | reason_code = smcr_serv_conf_first_link(new_smc); |
Karsten Graul | 4667bb4 | 2020-04-30 15:55:42 +0200 | [diff] [blame] | 1321 | smc_llc_flow_stop(link->lgr, &link->lgr->llc_flow_lcl); |
Hans Wippel | 3b2dec2 | 2018-05-18 09:34:18 +0200 | [diff] [blame] | 1322 | } |
Ursula Braun | 1ca52fc | 2018-09-18 15:46:35 +0200 | [diff] [blame] | 1323 | return reason_code; |
Hans Wippel | 3b2dec2 | 2018-05-18 09:34:18 +0200 | [diff] [blame] | 1324 | } |
| 1325 | |
Ursula Braun | 7affc80 | 2020-09-26 12:44:21 +0200 | [diff] [blame] | 1326 | /* setup for connection of server */ |
Hans Wippel | 3b2dec2 | 2018-05-18 09:34:18 +0200 | [diff] [blame] | 1327 | static void smc_listen_work(struct work_struct *work) |
| 1328 | { |
| 1329 | struct smc_sock *new_smc = container_of(work, struct smc_sock, |
| 1330 | smc_listen_work); |
| 1331 | struct socket *newclcsock = new_smc->clcsock; |
| 1332 | struct smc_clc_msg_accept_confirm cclc; |
Ursula Braun | 6bb14e48 | 2020-09-10 18:48:22 +0200 | [diff] [blame] | 1333 | struct smc_clc_msg_proposal_area *buf; |
Hans Wippel | 3b2dec2 | 2018-05-18 09:34:18 +0200 | [diff] [blame] | 1334 | struct smc_clc_msg_proposal *pclc; |
Ursula Braun | 3fc6493 | 2020-09-26 12:44:23 +0200 | [diff] [blame] | 1335 | struct smc_init_info *ini = NULL; |
Hans Wippel | 3b2dec2 | 2018-05-18 09:34:18 +0200 | [diff] [blame] | 1336 | int rc = 0; |
Hans Wippel | 3b2dec2 | 2018-05-18 09:34:18 +0200 | [diff] [blame] | 1337 | |
Karsten Graul | fd57770 | 2019-04-11 11:17:30 +0200 | [diff] [blame] | 1338 | if (new_smc->listen_smc->sk.sk_state != SMC_LISTEN) |
| 1339 | return smc_listen_out_err(new_smc); |
| 1340 | |
Hans Wippel | 3b2dec2 | 2018-05-18 09:34:18 +0200 | [diff] [blame] | 1341 | if (new_smc->use_fallback) { |
| 1342 | smc_listen_out_connected(new_smc); |
| 1343 | return; |
| 1344 | } |
| 1345 | |
| 1346 | /* check if peer is smc capable */ |
| 1347 | if (!tcp_sk(newclcsock->sk)->syn_smc) { |
Ursula Braun | 07603b2 | 2019-04-11 11:17:32 +0200 | [diff] [blame] | 1348 | smc_switch_to_fallback(new_smc); |
Karsten Graul | 603cc14 | 2018-07-25 16:35:32 +0200 | [diff] [blame] | 1349 | new_smc->fallback_rsn = SMC_CLC_DECL_PEERNOSMC; |
Hans Wippel | 3b2dec2 | 2018-05-18 09:34:18 +0200 | [diff] [blame] | 1350 | smc_listen_out_connected(new_smc); |
| 1351 | return; |
| 1352 | } |
| 1353 | |
| 1354 | /* do inband token exchange - |
| 1355 | * wait for and receive SMC Proposal CLC message |
| 1356 | */ |
Ursula Braun | 6bb14e48 | 2020-09-10 18:48:22 +0200 | [diff] [blame] | 1357 | buf = kzalloc(sizeof(*buf), GFP_KERNEL); |
| 1358 | if (!buf) { |
| 1359 | rc = SMC_CLC_DECL_MEM; |
| 1360 | goto out_decl; |
| 1361 | } |
| 1362 | pclc = (struct smc_clc_msg_proposal *)buf; |
| 1363 | rc = smc_clc_wait_msg(new_smc, pclc, sizeof(*buf), |
Karsten Graul | 228bae0 | 2019-04-12 12:57:28 +0200 | [diff] [blame] | 1364 | SMC_CLC_PROPOSAL, CLC_WAIT_TIME); |
Karsten Graul | 9aa68d2 | 2019-04-12 12:57:29 +0200 | [diff] [blame] | 1365 | if (rc) |
| 1366 | goto out_decl; |
Hans Wippel | 3b2dec2 | 2018-05-18 09:34:18 +0200 | [diff] [blame] | 1367 | |
| 1368 | /* IPSec connections opt out of SMC-R optimizations */ |
| 1369 | if (using_ipsec(new_smc)) { |
Karsten Graul | 9aa68d2 | 2019-04-12 12:57:29 +0200 | [diff] [blame] | 1370 | rc = SMC_CLC_DECL_IPSEC; |
| 1371 | goto out_decl; |
Hans Wippel | 3b2dec2 | 2018-05-18 09:34:18 +0200 | [diff] [blame] | 1372 | } |
| 1373 | |
Karsten Graul | 5988669 | 2019-04-12 12:57:25 +0200 | [diff] [blame] | 1374 | /* check for matching IP prefix and subnet length */ |
| 1375 | rc = smc_listen_prfx_check(new_smc, pclc); |
Karsten Graul | 9aa68d2 | 2019-04-12 12:57:29 +0200 | [diff] [blame] | 1376 | if (rc) |
| 1377 | goto out_decl; |
Karsten Graul | 5988669 | 2019-04-12 12:57:25 +0200 | [diff] [blame] | 1378 | |
Ursula Braun | 3fc6493 | 2020-09-26 12:44:23 +0200 | [diff] [blame] | 1379 | ini = kzalloc(sizeof(*ini), GFP_KERNEL); |
| 1380 | if (!ini) { |
| 1381 | rc = SMC_CLC_DECL_MEM; |
| 1382 | goto out_decl; |
| 1383 | } |
| 1384 | |
Karsten Graul | fba7e8e | 2019-04-12 12:57:27 +0200 | [diff] [blame] | 1385 | /* get vlan id from IP device */ |
Ursula Braun | 3fc6493 | 2020-09-26 12:44:23 +0200 | [diff] [blame] | 1386 | if (smc_vlan_by_tcpsk(new_smc->clcsock, ini)) { |
Karsten Graul | 9aa68d2 | 2019-04-12 12:57:29 +0200 | [diff] [blame] | 1387 | rc = SMC_CLC_DECL_GETVLANERR; |
| 1388 | goto out_decl; |
Karsten Graul | fba7e8e | 2019-04-12 12:57:27 +0200 | [diff] [blame] | 1389 | } |
| 1390 | |
Hans Wippel | 72a36a8 | 2019-02-07 15:56:18 +0100 | [diff] [blame] | 1391 | mutex_lock(&smc_server_lgr_pending); |
Hans Wippel | 3b2dec2 | 2018-05-18 09:34:18 +0200 | [diff] [blame] | 1392 | smc_close_init(new_smc); |
| 1393 | smc_rx_init(new_smc); |
| 1394 | smc_tx_init(new_smc); |
| 1395 | |
Ursula Braun | 7affc80 | 2020-09-26 12:44:21 +0200 | [diff] [blame] | 1396 | /* determine ISM or RoCE device used for connection */ |
Ursula Braun | 3fc6493 | 2020-09-26 12:44:23 +0200 | [diff] [blame] | 1397 | rc = smc_listen_find_device(new_smc, pclc, ini); |
Ursula Braun | 7affc80 | 2020-09-26 12:44:21 +0200 | [diff] [blame] | 1398 | if (rc) |
| 1399 | goto out_unlock; |
Hans Wippel | 3b2dec2 | 2018-05-18 09:34:18 +0200 | [diff] [blame] | 1400 | |
| 1401 | /* send SMC Accept CLC message */ |
Ursula Braun | 3fc6493 | 2020-09-26 12:44:23 +0200 | [diff] [blame] | 1402 | rc = smc_clc_send_accept(new_smc, ini->first_contact_local); |
Karsten Graul | 9aa68d2 | 2019-04-12 12:57:29 +0200 | [diff] [blame] | 1403 | if (rc) |
| 1404 | goto out_unlock; |
Hans Wippel | 3b2dec2 | 2018-05-18 09:34:18 +0200 | [diff] [blame] | 1405 | |
Hans Wippel | 62c7139 | 2019-02-07 15:56:17 +0100 | [diff] [blame] | 1406 | /* SMC-D does not need this lock any more */ |
Ursula Braun | 3fc6493 | 2020-09-26 12:44:23 +0200 | [diff] [blame] | 1407 | if (ini->is_smcd) |
Hans Wippel | 72a36a8 | 2019-02-07 15:56:18 +0100 | [diff] [blame] | 1408 | mutex_unlock(&smc_server_lgr_pending); |
Hans Wippel | 62c7139 | 2019-02-07 15:56:17 +0100 | [diff] [blame] | 1409 | |
Hans Wippel | 3b2dec2 | 2018-05-18 09:34:18 +0200 | [diff] [blame] | 1410 | /* receive SMC Confirm CLC message */ |
Karsten Graul | 228bae0 | 2019-04-12 12:57:28 +0200 | [diff] [blame] | 1411 | rc = smc_clc_wait_msg(new_smc, &cclc, sizeof(cclc), |
| 1412 | SMC_CLC_CONFIRM, CLC_WAIT_TIME); |
| 1413 | if (rc) { |
Ursula Braun | 3fc6493 | 2020-09-26 12:44:23 +0200 | [diff] [blame] | 1414 | if (!ini->is_smcd) |
Karsten Graul | 9aa68d2 | 2019-04-12 12:57:29 +0200 | [diff] [blame] | 1415 | goto out_unlock; |
| 1416 | goto out_decl; |
Hans Wippel | 3b2dec2 | 2018-05-18 09:34:18 +0200 | [diff] [blame] | 1417 | } |
| 1418 | |
| 1419 | /* finish worker */ |
Ursula Braun | 3fc6493 | 2020-09-26 12:44:23 +0200 | [diff] [blame] | 1420 | if (!ini->is_smcd) { |
Karsten Graul | 7a62725 | 2019-04-12 12:57:30 +0200 | [diff] [blame] | 1421 | rc = smc_listen_rdma_finish(new_smc, &cclc, |
Ursula Braun | 3fc6493 | 2020-09-26 12:44:23 +0200 | [diff] [blame] | 1422 | ini->first_contact_local); |
Hans Wippel | 62c7139 | 2019-02-07 15:56:17 +0100 | [diff] [blame] | 1423 | if (rc) |
Ursula Braun | 0c881ad | 2020-09-10 18:48:25 +0200 | [diff] [blame] | 1424 | goto out_unlock; |
| 1425 | mutex_unlock(&smc_server_lgr_pending); |
Ursula Braun | 1ca52fc | 2018-09-18 15:46:35 +0200 | [diff] [blame] | 1426 | } |
Hans Wippel | 3b2dec2 | 2018-05-18 09:34:18 +0200 | [diff] [blame] | 1427 | smc_conn_save_peer_info(new_smc, &cclc); |
Hans Wippel | 3b2dec2 | 2018-05-18 09:34:18 +0200 | [diff] [blame] | 1428 | smc_listen_out_connected(new_smc); |
Ursula Braun | ac67936 | 2020-09-17 22:46:02 +0200 | [diff] [blame] | 1429 | goto out_free; |
Karsten Graul | 9aa68d2 | 2019-04-12 12:57:29 +0200 | [diff] [blame] | 1430 | |
| 1431 | out_unlock: |
| 1432 | mutex_unlock(&smc_server_lgr_pending); |
| 1433 | out_decl: |
Ursula Braun | 3fc6493 | 2020-09-26 12:44:23 +0200 | [diff] [blame] | 1434 | smc_listen_decline(new_smc, rc, ini ? ini->first_contact_local : 0); |
Ursula Braun | ac67936 | 2020-09-17 22:46:02 +0200 | [diff] [blame] | 1435 | out_free: |
Ursula Braun | 3fc6493 | 2020-09-26 12:44:23 +0200 | [diff] [blame] | 1436 | kfree(ini); |
Ursula Braun | 6bb14e48 | 2020-09-10 18:48:22 +0200 | [diff] [blame] | 1437 | kfree(buf); |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 1438 | } |
| 1439 | |
| 1440 | static void smc_tcp_listen_work(struct work_struct *work) |
| 1441 | { |
| 1442 | struct smc_sock *lsmc = container_of(work, struct smc_sock, |
| 1443 | tcp_listen_work); |
Ursula Braun | 3163c50 | 2018-01-24 10:28:12 +0100 | [diff] [blame] | 1444 | struct sock *lsk = &lsmc->sk; |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 1445 | struct smc_sock *new_smc; |
| 1446 | int rc = 0; |
| 1447 | |
Ursula Braun | 3163c50 | 2018-01-24 10:28:12 +0100 | [diff] [blame] | 1448 | lock_sock(lsk); |
| 1449 | while (lsk->sk_state == SMC_LISTEN) { |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 1450 | rc = smc_clcsock_accept(lsmc, &new_smc); |
Ursula Braun | a60a2b1 | 2020-09-10 18:48:20 +0200 | [diff] [blame] | 1451 | if (rc) /* clcsock accept queue empty or error */ |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 1452 | goto out; |
| 1453 | if (!new_smc) |
| 1454 | continue; |
| 1455 | |
| 1456 | new_smc->listen_smc = lsmc; |
Ursula Braun | ee9dfbe | 2018-04-26 17:18:21 +0200 | [diff] [blame] | 1457 | new_smc->use_fallback = lsmc->use_fallback; |
Karsten Graul | 603cc14 | 2018-07-25 16:35:32 +0200 | [diff] [blame] | 1458 | new_smc->fallback_rsn = lsmc->fallback_rsn; |
Ursula Braun | 3163c50 | 2018-01-24 10:28:12 +0100 | [diff] [blame] | 1459 | sock_hold(lsk); /* sock_put in smc_listen_work */ |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 1460 | INIT_WORK(&new_smc->smc_listen_work, smc_listen_work); |
| 1461 | smc_copy_sock_settings_to_smc(new_smc); |
Ursula Braun | bd58c7e | 2018-08-08 14:13:20 +0200 | [diff] [blame] | 1462 | new_smc->sk.sk_sndbuf = lsmc->sk.sk_sndbuf; |
| 1463 | new_smc->sk.sk_rcvbuf = lsmc->sk.sk_rcvbuf; |
Ursula Braun | 51f1de7 | 2018-01-26 09:28:48 +0100 | [diff] [blame] | 1464 | sock_hold(&new_smc->sk); /* sock_put in passive closing */ |
Karsten Graul | 22ef473 | 2020-09-10 18:48:29 +0200 | [diff] [blame] | 1465 | if (!queue_work(smc_hs_wq, &new_smc->smc_listen_work)) |
Ursula Braun | 51f1de7 | 2018-01-26 09:28:48 +0100 | [diff] [blame] | 1466 | sock_put(&new_smc->sk); |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 1467 | } |
| 1468 | |
| 1469 | out: |
Ursula Braun | 3163c50 | 2018-01-24 10:28:12 +0100 | [diff] [blame] | 1470 | release_sock(lsk); |
Ursula Braun | a60a2b1 | 2020-09-10 18:48:20 +0200 | [diff] [blame] | 1471 | sock_put(&lsmc->sk); /* sock_hold in smc_clcsock_data_ready() */ |
| 1472 | } |
| 1473 | |
| 1474 | static void smc_clcsock_data_ready(struct sock *listen_clcsock) |
| 1475 | { |
| 1476 | struct smc_sock *lsmc; |
| 1477 | |
| 1478 | lsmc = (struct smc_sock *) |
| 1479 | ((uintptr_t)listen_clcsock->sk_user_data & ~SK_USER_DATA_NOCOPY); |
| 1480 | if (!lsmc) |
| 1481 | return; |
| 1482 | lsmc->clcsk_data_ready(listen_clcsock); |
| 1483 | if (lsmc->sk.sk_state == SMC_LISTEN) { |
| 1484 | sock_hold(&lsmc->sk); /* sock_put in smc_tcp_listen_work() */ |
Karsten Graul | 22ef473 | 2020-09-10 18:48:29 +0200 | [diff] [blame] | 1485 | if (!queue_work(smc_hs_wq, &lsmc->tcp_listen_work)) |
Ursula Braun | a60a2b1 | 2020-09-10 18:48:20 +0200 | [diff] [blame] | 1486 | sock_put(&lsmc->sk); |
| 1487 | } |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 1488 | } |
| 1489 | |
Ursula Braun | ac71387 | 2017-01-09 16:55:13 +0100 | [diff] [blame] | 1490 | static int smc_listen(struct socket *sock, int backlog) |
| 1491 | { |
| 1492 | struct sock *sk = sock->sk; |
| 1493 | struct smc_sock *smc; |
| 1494 | int rc; |
| 1495 | |
| 1496 | smc = smc_sk(sk); |
| 1497 | lock_sock(sk); |
| 1498 | |
| 1499 | rc = -EINVAL; |
Ursula Braun | cd20636 | 2019-08-02 10:47:50 +0200 | [diff] [blame] | 1500 | if ((sk->sk_state != SMC_INIT && sk->sk_state != SMC_LISTEN) || |
| 1501 | smc->connect_nonblock) |
Ursula Braun | ac71387 | 2017-01-09 16:55:13 +0100 | [diff] [blame] | 1502 | goto out; |
| 1503 | |
| 1504 | rc = 0; |
| 1505 | if (sk->sk_state == SMC_LISTEN) { |
| 1506 | sk->sk_max_ack_backlog = backlog; |
| 1507 | goto out; |
| 1508 | } |
| 1509 | /* some socket options are handled in core, so we could not apply |
| 1510 | * them to the clc socket -- copy smc socket options to clc socket |
| 1511 | */ |
| 1512 | smc_copy_sock_settings_to_clc(smc); |
Ursula Braun | ee9dfbe | 2018-04-26 17:18:21 +0200 | [diff] [blame] | 1513 | if (!smc->use_fallback) |
| 1514 | tcp_sk(smc->clcsock->sk)->syn_smc = 1; |
Ursula Braun | ac71387 | 2017-01-09 16:55:13 +0100 | [diff] [blame] | 1515 | |
Ursula Braun | a60a2b1 | 2020-09-10 18:48:20 +0200 | [diff] [blame] | 1516 | /* save original sk_data_ready function and establish |
| 1517 | * smc-specific sk_data_ready function |
| 1518 | */ |
| 1519 | smc->clcsk_data_ready = smc->clcsock->sk->sk_data_ready; |
| 1520 | smc->clcsock->sk->sk_data_ready = smc_clcsock_data_ready; |
| 1521 | smc->clcsock->sk->sk_user_data = |
| 1522 | (void *)((uintptr_t)smc | SK_USER_DATA_NOCOPY); |
Ursula Braun | ac71387 | 2017-01-09 16:55:13 +0100 | [diff] [blame] | 1523 | rc = kernel_listen(smc->clcsock, backlog); |
| 1524 | if (rc) |
| 1525 | goto out; |
| 1526 | sk->sk_max_ack_backlog = backlog; |
| 1527 | sk->sk_ack_backlog = 0; |
| 1528 | sk->sk_state = SMC_LISTEN; |
| 1529 | |
| 1530 | out: |
| 1531 | release_sock(sk); |
| 1532 | return rc; |
| 1533 | } |
| 1534 | |
| 1535 | static int smc_accept(struct socket *sock, struct socket *new_sock, |
David Howells | cdfbabf | 2017-03-09 08:09:05 +0000 | [diff] [blame] | 1536 | int flags, bool kern) |
Ursula Braun | ac71387 | 2017-01-09 16:55:13 +0100 | [diff] [blame] | 1537 | { |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 1538 | struct sock *sk = sock->sk, *nsk; |
| 1539 | DECLARE_WAITQUEUE(wait, current); |
Ursula Braun | ac71387 | 2017-01-09 16:55:13 +0100 | [diff] [blame] | 1540 | struct smc_sock *lsmc; |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 1541 | long timeo; |
| 1542 | int rc = 0; |
Ursula Braun | ac71387 | 2017-01-09 16:55:13 +0100 | [diff] [blame] | 1543 | |
| 1544 | lsmc = smc_sk(sk); |
Ursula Braun | 51f1de7 | 2018-01-26 09:28:48 +0100 | [diff] [blame] | 1545 | sock_hold(sk); /* sock_put below */ |
Ursula Braun | ac71387 | 2017-01-09 16:55:13 +0100 | [diff] [blame] | 1546 | lock_sock(sk); |
| 1547 | |
| 1548 | if (lsmc->sk.sk_state != SMC_LISTEN) { |
| 1549 | rc = -EINVAL; |
Ursula Braun | abb190f | 2018-04-26 17:18:23 +0200 | [diff] [blame] | 1550 | release_sock(sk); |
Ursula Braun | ac71387 | 2017-01-09 16:55:13 +0100 | [diff] [blame] | 1551 | goto out; |
| 1552 | } |
| 1553 | |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 1554 | /* Wait for an incoming connection */ |
| 1555 | timeo = sock_rcvtimeo(sk, flags & O_NONBLOCK); |
| 1556 | add_wait_queue_exclusive(sk_sleep(sk), &wait); |
| 1557 | while (!(nsk = smc_accept_dequeue(sk, new_sock))) { |
| 1558 | set_current_state(TASK_INTERRUPTIBLE); |
| 1559 | if (!timeo) { |
| 1560 | rc = -EAGAIN; |
| 1561 | break; |
| 1562 | } |
| 1563 | release_sock(sk); |
| 1564 | timeo = schedule_timeout(timeo); |
| 1565 | /* wakeup by sk_data_ready in smc_listen_work() */ |
| 1566 | sched_annotate_sleep(); |
| 1567 | lock_sock(sk); |
| 1568 | if (signal_pending(current)) { |
| 1569 | rc = sock_intr_errno(timeo); |
| 1570 | break; |
| 1571 | } |
| 1572 | } |
| 1573 | set_current_state(TASK_RUNNING); |
| 1574 | remove_wait_queue(sk_sleep(sk), &wait); |
Ursula Braun | ac71387 | 2017-01-09 16:55:13 +0100 | [diff] [blame] | 1575 | |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 1576 | if (!rc) |
| 1577 | rc = sock_error(nsk); |
Ursula Braun | abb190f | 2018-04-26 17:18:23 +0200 | [diff] [blame] | 1578 | release_sock(sk); |
| 1579 | if (rc) |
| 1580 | goto out; |
| 1581 | |
| 1582 | if (lsmc->sockopt_defer_accept && !(flags & O_NONBLOCK)) { |
| 1583 | /* wait till data arrives on the socket */ |
| 1584 | timeo = msecs_to_jiffies(lsmc->sockopt_defer_accept * |
| 1585 | MSEC_PER_SEC); |
| 1586 | if (smc_sk(nsk)->use_fallback) { |
| 1587 | struct sock *clcsk = smc_sk(nsk)->clcsock->sk; |
| 1588 | |
| 1589 | lock_sock(clcsk); |
| 1590 | if (skb_queue_empty(&clcsk->sk_receive_queue)) |
| 1591 | sk_wait_data(clcsk, &timeo, NULL); |
| 1592 | release_sock(clcsk); |
| 1593 | } else if (!atomic_read(&smc_sk(nsk)->conn.bytes_to_rcv)) { |
| 1594 | lock_sock(nsk); |
Stefan Raspl | b51fa1b | 2018-05-03 18:12:37 +0200 | [diff] [blame] | 1595 | smc_rx_wait(smc_sk(nsk), &timeo, smc_rx_data_available); |
Ursula Braun | abb190f | 2018-04-26 17:18:23 +0200 | [diff] [blame] | 1596 | release_sock(nsk); |
| 1597 | } |
| 1598 | } |
Ursula Braun | ac71387 | 2017-01-09 16:55:13 +0100 | [diff] [blame] | 1599 | |
| 1600 | out: |
Ursula Braun | 51f1de7 | 2018-01-26 09:28:48 +0100 | [diff] [blame] | 1601 | sock_put(sk); /* sock_hold above */ |
Ursula Braun | ac71387 | 2017-01-09 16:55:13 +0100 | [diff] [blame] | 1602 | return rc; |
| 1603 | } |
| 1604 | |
| 1605 | static int smc_getname(struct socket *sock, struct sockaddr *addr, |
Denys Vlasenko | 9b2c45d | 2018-02-12 20:00:20 +0100 | [diff] [blame] | 1606 | int peer) |
Ursula Braun | ac71387 | 2017-01-09 16:55:13 +0100 | [diff] [blame] | 1607 | { |
| 1608 | struct smc_sock *smc; |
| 1609 | |
Ursula Braun | b38d732 | 2017-01-09 16:55:25 +0100 | [diff] [blame] | 1610 | if (peer && (sock->sk->sk_state != SMC_ACTIVE) && |
| 1611 | (sock->sk->sk_state != SMC_APPCLOSEWAIT1)) |
Ursula Braun | ac71387 | 2017-01-09 16:55:13 +0100 | [diff] [blame] | 1612 | return -ENOTCONN; |
| 1613 | |
| 1614 | smc = smc_sk(sock->sk); |
| 1615 | |
Denys Vlasenko | 9b2c45d | 2018-02-12 20:00:20 +0100 | [diff] [blame] | 1616 | return smc->clcsock->ops->getname(smc->clcsock, addr, peer); |
Ursula Braun | ac71387 | 2017-01-09 16:55:13 +0100 | [diff] [blame] | 1617 | } |
| 1618 | |
| 1619 | static int smc_sendmsg(struct socket *sock, struct msghdr *msg, size_t len) |
| 1620 | { |
| 1621 | struct sock *sk = sock->sk; |
| 1622 | struct smc_sock *smc; |
| 1623 | int rc = -EPIPE; |
| 1624 | |
| 1625 | smc = smc_sk(sk); |
| 1626 | lock_sock(sk); |
Ursula Braun | b38d732 | 2017-01-09 16:55:25 +0100 | [diff] [blame] | 1627 | if ((sk->sk_state != SMC_ACTIVE) && |
| 1628 | (sk->sk_state != SMC_APPCLOSEWAIT1) && |
| 1629 | (sk->sk_state != SMC_INIT)) |
Ursula Braun | ac71387 | 2017-01-09 16:55:13 +0100 | [diff] [blame] | 1630 | goto out; |
Ursula Braun | ee9dfbe | 2018-04-26 17:18:21 +0200 | [diff] [blame] | 1631 | |
| 1632 | if (msg->msg_flags & MSG_FASTOPEN) { |
Ursula Braun | cd20636 | 2019-08-02 10:47:50 +0200 | [diff] [blame] | 1633 | if (sk->sk_state == SMC_INIT && !smc->connect_nonblock) { |
Ursula Braun | 07603b2 | 2019-04-11 11:17:32 +0200 | [diff] [blame] | 1634 | smc_switch_to_fallback(smc); |
Karsten Graul | 603cc14 | 2018-07-25 16:35:32 +0200 | [diff] [blame] | 1635 | smc->fallback_rsn = SMC_CLC_DECL_OPTUNSUPP; |
Ursula Braun | ee9dfbe | 2018-04-26 17:18:21 +0200 | [diff] [blame] | 1636 | } else { |
| 1637 | rc = -EINVAL; |
| 1638 | goto out; |
| 1639 | } |
| 1640 | } |
| 1641 | |
Ursula Braun | ac71387 | 2017-01-09 16:55:13 +0100 | [diff] [blame] | 1642 | if (smc->use_fallback) |
| 1643 | rc = smc->clcsock->ops->sendmsg(smc->clcsock, msg, len); |
| 1644 | else |
Ursula Braun | e6727f3 | 2017-01-09 16:55:23 +0100 | [diff] [blame] | 1645 | rc = smc_tx_sendmsg(smc, msg, len); |
Ursula Braun | ac71387 | 2017-01-09 16:55:13 +0100 | [diff] [blame] | 1646 | out: |
| 1647 | release_sock(sk); |
| 1648 | return rc; |
| 1649 | } |
| 1650 | |
| 1651 | static int smc_recvmsg(struct socket *sock, struct msghdr *msg, size_t len, |
| 1652 | int flags) |
| 1653 | { |
| 1654 | struct sock *sk = sock->sk; |
| 1655 | struct smc_sock *smc; |
| 1656 | int rc = -ENOTCONN; |
| 1657 | |
| 1658 | smc = smc_sk(sk); |
| 1659 | lock_sock(sk); |
Karsten Graul | 51c5aba | 2019-01-30 18:51:04 +0100 | [diff] [blame] | 1660 | if (sk->sk_state == SMC_CLOSED && (sk->sk_shutdown & RCV_SHUTDOWN)) { |
| 1661 | /* socket was connected before, no more data to read */ |
| 1662 | rc = 0; |
| 1663 | goto out; |
| 1664 | } |
Ursula Braun | b38d732 | 2017-01-09 16:55:25 +0100 | [diff] [blame] | 1665 | if ((sk->sk_state == SMC_INIT) || |
| 1666 | (sk->sk_state == SMC_LISTEN) || |
| 1667 | (sk->sk_state == SMC_CLOSED)) |
Ursula Braun | ac71387 | 2017-01-09 16:55:13 +0100 | [diff] [blame] | 1668 | goto out; |
| 1669 | |
Ursula Braun | b38d732 | 2017-01-09 16:55:25 +0100 | [diff] [blame] | 1670 | if (sk->sk_state == SMC_PEERFINCLOSEWAIT) { |
| 1671 | rc = 0; |
| 1672 | goto out; |
| 1673 | } |
| 1674 | |
Stefan Raspl | 9014db2 | 2018-05-03 18:12:39 +0200 | [diff] [blame] | 1675 | if (smc->use_fallback) { |
Ursula Braun | ac71387 | 2017-01-09 16:55:13 +0100 | [diff] [blame] | 1676 | rc = smc->clcsock->ops->recvmsg(smc->clcsock, msg, len, flags); |
Stefan Raspl | 9014db2 | 2018-05-03 18:12:39 +0200 | [diff] [blame] | 1677 | } else { |
| 1678 | msg->msg_namelen = 0; |
| 1679 | rc = smc_rx_recvmsg(smc, msg, NULL, len, flags); |
| 1680 | } |
Ursula Braun | b38d732 | 2017-01-09 16:55:25 +0100 | [diff] [blame] | 1681 | |
Ursula Braun | ac71387 | 2017-01-09 16:55:13 +0100 | [diff] [blame] | 1682 | out: |
| 1683 | release_sock(sk); |
| 1684 | return rc; |
| 1685 | } |
| 1686 | |
Al Viro | ade994f | 2017-07-03 00:01:49 -0400 | [diff] [blame] | 1687 | static __poll_t smc_accept_poll(struct sock *parent) |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 1688 | { |
Ursula Braun | 8dce278 | 2018-01-26 09:28:47 +0100 | [diff] [blame] | 1689 | struct smc_sock *isk = smc_sk(parent); |
Al Viro | 63e2480 | 2018-02-01 10:02:53 -0500 | [diff] [blame] | 1690 | __poll_t mask = 0; |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 1691 | |
Ursula Braun | 8dce278 | 2018-01-26 09:28:47 +0100 | [diff] [blame] | 1692 | spin_lock(&isk->accept_q_lock); |
| 1693 | if (!list_empty(&isk->accept_q)) |
Linus Torvalds | a9a0884 | 2018-02-11 14:34:03 -0800 | [diff] [blame] | 1694 | mask = EPOLLIN | EPOLLRDNORM; |
Ursula Braun | 8dce278 | 2018-01-26 09:28:47 +0100 | [diff] [blame] | 1695 | spin_unlock(&isk->accept_q_lock); |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 1696 | |
Ursula Braun | 8dce278 | 2018-01-26 09:28:47 +0100 | [diff] [blame] | 1697 | return mask; |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 1698 | } |
| 1699 | |
Linus Torvalds | a11e1d4 | 2018-06-28 09:43:44 -0700 | [diff] [blame] | 1700 | static __poll_t smc_poll(struct file *file, struct socket *sock, |
| 1701 | poll_table *wait) |
Ursula Braun | ac71387 | 2017-01-09 16:55:13 +0100 | [diff] [blame] | 1702 | { |
| 1703 | struct sock *sk = sock->sk; |
Ursula Braun | ac71387 | 2017-01-09 16:55:13 +0100 | [diff] [blame] | 1704 | struct smc_sock *smc; |
Ursula Braun | 50717a3 | 2019-04-12 12:57:23 +0200 | [diff] [blame] | 1705 | __poll_t mask = 0; |
Ursula Braun | ac71387 | 2017-01-09 16:55:13 +0100 | [diff] [blame] | 1706 | |
Ursula Braun | 8dce278 | 2018-01-26 09:28:47 +0100 | [diff] [blame] | 1707 | if (!sk) |
Linus Torvalds | a9a0884 | 2018-02-11 14:34:03 -0800 | [diff] [blame] | 1708 | return EPOLLNVAL; |
Ursula Braun | 8dce278 | 2018-01-26 09:28:47 +0100 | [diff] [blame] | 1709 | |
Ursula Braun | ac71387 | 2017-01-09 16:55:13 +0100 | [diff] [blame] | 1710 | smc = smc_sk(sock->sk); |
Ursula Braun | 648a5a7 | 2018-09-18 15:46:34 +0200 | [diff] [blame] | 1711 | if (smc->use_fallback) { |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 1712 | /* delegate to CLC child sock */ |
Linus Torvalds | a11e1d4 | 2018-06-28 09:43:44 -0700 | [diff] [blame] | 1713 | mask = smc->clcsock->ops->poll(file, smc->clcsock, wait); |
Ursula Braun | 784813a | 2018-05-02 16:53:56 +0200 | [diff] [blame] | 1714 | sk->sk_err = smc->clcsock->sk->sk_err; |
Ursula Braun | ac71387 | 2017-01-09 16:55:13 +0100 | [diff] [blame] | 1715 | } else { |
Linus Torvalds | 410da1e | 2018-07-03 09:53:43 -0700 | [diff] [blame] | 1716 | if (sk->sk_state != SMC_CLOSED) |
Karsten Graul | 89ab066 | 2018-10-23 13:40:39 +0200 | [diff] [blame] | 1717 | sock_poll_wait(file, sock, wait); |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 1718 | if (sk->sk_err) |
Linus Torvalds | a9a0884 | 2018-02-11 14:34:03 -0800 | [diff] [blame] | 1719 | mask |= EPOLLERR; |
Ursula Braun | b38d732 | 2017-01-09 16:55:25 +0100 | [diff] [blame] | 1720 | if ((sk->sk_shutdown == SHUTDOWN_MASK) || |
| 1721 | (sk->sk_state == SMC_CLOSED)) |
Linus Torvalds | a9a0884 | 2018-02-11 14:34:03 -0800 | [diff] [blame] | 1722 | mask |= EPOLLHUP; |
Ursula Braun | 8dce278 | 2018-01-26 09:28:47 +0100 | [diff] [blame] | 1723 | if (sk->sk_state == SMC_LISTEN) { |
| 1724 | /* woken up by sk_data_ready in smc_listen_work() */ |
Ursula Braun | 50717a3 | 2019-04-12 12:57:23 +0200 | [diff] [blame] | 1725 | mask |= smc_accept_poll(sk); |
| 1726 | } else if (smc->use_fallback) { /* as result of connect_work()*/ |
| 1727 | mask |= smc->clcsock->ops->poll(file, smc->clcsock, |
| 1728 | wait); |
| 1729 | sk->sk_err = smc->clcsock->sk->sk_err; |
Ursula Braun | 8dce278 | 2018-01-26 09:28:47 +0100 | [diff] [blame] | 1730 | } else { |
Ursula Braun | 50717a3 | 2019-04-12 12:57:23 +0200 | [diff] [blame] | 1731 | if ((sk->sk_state != SMC_INIT && |
| 1732 | atomic_read(&smc->conn.sndbuf_space)) || |
Ursula Braun | 8dce278 | 2018-01-26 09:28:47 +0100 | [diff] [blame] | 1733 | sk->sk_shutdown & SEND_SHUTDOWN) { |
Linus Torvalds | a9a0884 | 2018-02-11 14:34:03 -0800 | [diff] [blame] | 1734 | mask |= EPOLLOUT | EPOLLWRNORM; |
Ursula Braun | 8dce278 | 2018-01-26 09:28:47 +0100 | [diff] [blame] | 1735 | } else { |
| 1736 | sk_set_bit(SOCKWQ_ASYNC_NOSPACE, sk); |
| 1737 | set_bit(SOCK_NOSPACE, &sk->sk_socket->flags); |
| 1738 | } |
| 1739 | if (atomic_read(&smc->conn.bytes_to_rcv)) |
Linus Torvalds | a9a0884 | 2018-02-11 14:34:03 -0800 | [diff] [blame] | 1740 | mask |= EPOLLIN | EPOLLRDNORM; |
Ursula Braun | 8dce278 | 2018-01-26 09:28:47 +0100 | [diff] [blame] | 1741 | if (sk->sk_shutdown & RCV_SHUTDOWN) |
Linus Torvalds | a9a0884 | 2018-02-11 14:34:03 -0800 | [diff] [blame] | 1742 | mask |= EPOLLIN | EPOLLRDNORM | EPOLLRDHUP; |
Ursula Braun | 8dce278 | 2018-01-26 09:28:47 +0100 | [diff] [blame] | 1743 | if (sk->sk_state == SMC_APPCLOSEWAIT1) |
Linus Torvalds | a9a0884 | 2018-02-11 14:34:03 -0800 | [diff] [blame] | 1744 | mask |= EPOLLIN; |
Karsten Graul | 71d117f | 2018-09-18 15:46:37 +0200 | [diff] [blame] | 1745 | if (smc->conn.urg_state == SMC_URG_VALID) |
| 1746 | mask |= EPOLLPRI; |
Ursula Braun | 8dce278 | 2018-01-26 09:28:47 +0100 | [diff] [blame] | 1747 | } |
Ursula Braun | ac71387 | 2017-01-09 16:55:13 +0100 | [diff] [blame] | 1748 | } |
| 1749 | |
| 1750 | return mask; |
| 1751 | } |
| 1752 | |
| 1753 | static int smc_shutdown(struct socket *sock, int how) |
| 1754 | { |
| 1755 | struct sock *sk = sock->sk; |
| 1756 | struct smc_sock *smc; |
| 1757 | int rc = -EINVAL; |
Ursula Braun | b38d732 | 2017-01-09 16:55:25 +0100 | [diff] [blame] | 1758 | int rc1 = 0; |
Ursula Braun | ac71387 | 2017-01-09 16:55:13 +0100 | [diff] [blame] | 1759 | |
| 1760 | smc = smc_sk(sk); |
| 1761 | |
| 1762 | if ((how < SHUT_RD) || (how > SHUT_RDWR)) |
Ursula Braun | b38d732 | 2017-01-09 16:55:25 +0100 | [diff] [blame] | 1763 | return rc; |
Ursula Braun | ac71387 | 2017-01-09 16:55:13 +0100 | [diff] [blame] | 1764 | |
| 1765 | lock_sock(sk); |
| 1766 | |
| 1767 | rc = -ENOTCONN; |
Ursula Braun | caa21e1 | 2018-08-08 14:13:19 +0200 | [diff] [blame] | 1768 | if ((sk->sk_state != SMC_ACTIVE) && |
Ursula Braun | b38d732 | 2017-01-09 16:55:25 +0100 | [diff] [blame] | 1769 | (sk->sk_state != SMC_PEERCLOSEWAIT1) && |
| 1770 | (sk->sk_state != SMC_PEERCLOSEWAIT2) && |
| 1771 | (sk->sk_state != SMC_APPCLOSEWAIT1) && |
| 1772 | (sk->sk_state != SMC_APPCLOSEWAIT2) && |
| 1773 | (sk->sk_state != SMC_APPFINCLOSEWAIT)) |
Ursula Braun | ac71387 | 2017-01-09 16:55:13 +0100 | [diff] [blame] | 1774 | goto out; |
| 1775 | if (smc->use_fallback) { |
| 1776 | rc = kernel_sock_shutdown(smc->clcsock, how); |
| 1777 | sk->sk_shutdown = smc->clcsock->sk->sk_shutdown; |
| 1778 | if (sk->sk_shutdown == SHUTDOWN_MASK) |
| 1779 | sk->sk_state = SMC_CLOSED; |
Ursula Braun | b38d732 | 2017-01-09 16:55:25 +0100 | [diff] [blame] | 1780 | goto out; |
Ursula Braun | ac71387 | 2017-01-09 16:55:13 +0100 | [diff] [blame] | 1781 | } |
Ursula Braun | b38d732 | 2017-01-09 16:55:25 +0100 | [diff] [blame] | 1782 | switch (how) { |
| 1783 | case SHUT_RDWR: /* shutdown in both directions */ |
| 1784 | rc = smc_close_active(smc); |
| 1785 | break; |
| 1786 | case SHUT_WR: |
| 1787 | rc = smc_close_shutdown_write(smc); |
| 1788 | break; |
| 1789 | case SHUT_RD: |
Ursula Braun | 1255fcb | 2018-04-19 15:56:40 +0200 | [diff] [blame] | 1790 | rc = 0; |
| 1791 | /* nothing more to do because peer is not involved */ |
Ursula Braun | b38d732 | 2017-01-09 16:55:25 +0100 | [diff] [blame] | 1792 | break; |
| 1793 | } |
Ursula Braun | 1255fcb | 2018-04-19 15:56:40 +0200 | [diff] [blame] | 1794 | if (smc->clcsock) |
| 1795 | rc1 = kernel_sock_shutdown(smc->clcsock, how); |
Ursula Braun | b38d732 | 2017-01-09 16:55:25 +0100 | [diff] [blame] | 1796 | /* map sock_shutdown_cmd constants to sk_shutdown value range */ |
| 1797 | sk->sk_shutdown |= how + 1; |
Ursula Braun | ac71387 | 2017-01-09 16:55:13 +0100 | [diff] [blame] | 1798 | |
| 1799 | out: |
| 1800 | release_sock(sk); |
Ursula Braun | b38d732 | 2017-01-09 16:55:25 +0100 | [diff] [blame] | 1801 | return rc ? rc : rc1; |
Ursula Braun | ac71387 | 2017-01-09 16:55:13 +0100 | [diff] [blame] | 1802 | } |
| 1803 | |
| 1804 | static int smc_setsockopt(struct socket *sock, int level, int optname, |
Christoph Hellwig | a7b75c5 | 2020-07-23 08:09:07 +0200 | [diff] [blame] | 1805 | sockptr_t optval, unsigned int optlen) |
Ursula Braun | ac71387 | 2017-01-09 16:55:13 +0100 | [diff] [blame] | 1806 | { |
| 1807 | struct sock *sk = sock->sk; |
| 1808 | struct smc_sock *smc; |
Ursula Braun | 01d2f7e | 2018-04-26 17:18:22 +0200 | [diff] [blame] | 1809 | int val, rc; |
Ursula Braun | ac71387 | 2017-01-09 16:55:13 +0100 | [diff] [blame] | 1810 | |
| 1811 | smc = smc_sk(sk); |
| 1812 | |
| 1813 | /* generic setsockopts reaching us here always apply to the |
| 1814 | * CLC socket |
| 1815 | */ |
Christoph Hellwig | a44d9e7 | 2020-07-17 08:23:31 +0200 | [diff] [blame] | 1816 | if (unlikely(!smc->clcsock->ops->setsockopt)) |
| 1817 | rc = -EOPNOTSUPP; |
| 1818 | else |
| 1819 | rc = smc->clcsock->ops->setsockopt(smc->clcsock, level, optname, |
| 1820 | optval, optlen); |
Ursula Braun | ee9dfbe | 2018-04-26 17:18:21 +0200 | [diff] [blame] | 1821 | if (smc->clcsock->sk->sk_err) { |
| 1822 | sk->sk_err = smc->clcsock->sk->sk_err; |
| 1823 | sk->sk_error_report(sk); |
| 1824 | } |
Ursula Braun | ee9dfbe | 2018-04-26 17:18:21 +0200 | [diff] [blame] | 1825 | |
Ursula Braun | 01d2f7e | 2018-04-26 17:18:22 +0200 | [diff] [blame] | 1826 | if (optlen < sizeof(int)) |
Wei Yongjun | 3dc9f55 | 2018-05-31 02:31:22 +0000 | [diff] [blame] | 1827 | return -EINVAL; |
Christoph Hellwig | a7b75c5 | 2020-07-23 08:09:07 +0200 | [diff] [blame] | 1828 | if (copy_from_sockptr(&val, optval, sizeof(int))) |
Ursula Braun | ac0107e | 2018-07-18 15:22:50 +0200 | [diff] [blame] | 1829 | return -EFAULT; |
Ursula Braun | 01d2f7e | 2018-04-26 17:18:22 +0200 | [diff] [blame] | 1830 | |
Ursula Braun | ee9dfbe | 2018-04-26 17:18:21 +0200 | [diff] [blame] | 1831 | lock_sock(sk); |
Ursula Braun | 8643474 | 2019-12-12 22:35:58 +0100 | [diff] [blame] | 1832 | if (rc || smc->use_fallback) |
| 1833 | goto out; |
Ursula Braun | ee9dfbe | 2018-04-26 17:18:21 +0200 | [diff] [blame] | 1834 | switch (optname) { |
| 1835 | case TCP_ULP: |
| 1836 | case TCP_FASTOPEN: |
| 1837 | case TCP_FASTOPEN_CONNECT: |
| 1838 | case TCP_FASTOPEN_KEY: |
| 1839 | case TCP_FASTOPEN_NO_COOKIE: |
| 1840 | /* option not supported by SMC */ |
Ursula Braun | 8204df7 | 2019-11-15 12:39:30 +0100 | [diff] [blame] | 1841 | if (sk->sk_state == SMC_INIT && !smc->connect_nonblock) { |
Ursula Braun | 07603b2 | 2019-04-11 11:17:32 +0200 | [diff] [blame] | 1842 | smc_switch_to_fallback(smc); |
Karsten Graul | 603cc14 | 2018-07-25 16:35:32 +0200 | [diff] [blame] | 1843 | smc->fallback_rsn = SMC_CLC_DECL_OPTUNSUPP; |
Ursula Braun | ee9dfbe | 2018-04-26 17:18:21 +0200 | [diff] [blame] | 1844 | } else { |
Ursula Braun | 8643474 | 2019-12-12 22:35:58 +0100 | [diff] [blame] | 1845 | rc = -EINVAL; |
Ursula Braun | ee9dfbe | 2018-04-26 17:18:21 +0200 | [diff] [blame] | 1846 | } |
| 1847 | break; |
Ursula Braun | 01d2f7e | 2018-04-26 17:18:22 +0200 | [diff] [blame] | 1848 | case TCP_NODELAY: |
Ursula Braun | f9cedf1 | 2019-08-02 10:16:38 +0200 | [diff] [blame] | 1849 | if (sk->sk_state != SMC_INIT && |
| 1850 | sk->sk_state != SMC_LISTEN && |
| 1851 | sk->sk_state != SMC_CLOSED) { |
Ursula Braun | 8643474 | 2019-12-12 22:35:58 +0100 | [diff] [blame] | 1852 | if (val) |
Karsten Graul | 22ef473 | 2020-09-10 18:48:29 +0200 | [diff] [blame] | 1853 | mod_delayed_work(smc->conn.lgr->tx_wq, |
| 1854 | &smc->conn.tx_work, 0); |
Ursula Braun | 01d2f7e | 2018-04-26 17:18:22 +0200 | [diff] [blame] | 1855 | } |
| 1856 | break; |
| 1857 | case TCP_CORK: |
Ursula Braun | f9cedf1 | 2019-08-02 10:16:38 +0200 | [diff] [blame] | 1858 | if (sk->sk_state != SMC_INIT && |
| 1859 | sk->sk_state != SMC_LISTEN && |
| 1860 | sk->sk_state != SMC_CLOSED) { |
Ursula Braun | 8643474 | 2019-12-12 22:35:58 +0100 | [diff] [blame] | 1861 | if (!val) |
Karsten Graul | 22ef473 | 2020-09-10 18:48:29 +0200 | [diff] [blame] | 1862 | mod_delayed_work(smc->conn.lgr->tx_wq, |
| 1863 | &smc->conn.tx_work, 0); |
Ursula Braun | 01d2f7e | 2018-04-26 17:18:22 +0200 | [diff] [blame] | 1864 | } |
| 1865 | break; |
Ursula Braun | abb190f | 2018-04-26 17:18:23 +0200 | [diff] [blame] | 1866 | case TCP_DEFER_ACCEPT: |
| 1867 | smc->sockopt_defer_accept = val; |
| 1868 | break; |
Ursula Braun | ee9dfbe | 2018-04-26 17:18:21 +0200 | [diff] [blame] | 1869 | default: |
| 1870 | break; |
| 1871 | } |
Ursula Braun | 8643474 | 2019-12-12 22:35:58 +0100 | [diff] [blame] | 1872 | out: |
Ursula Braun | ee9dfbe | 2018-04-26 17:18:21 +0200 | [diff] [blame] | 1873 | release_sock(sk); |
| 1874 | |
| 1875 | return rc; |
Ursula Braun | ac71387 | 2017-01-09 16:55:13 +0100 | [diff] [blame] | 1876 | } |
| 1877 | |
| 1878 | static int smc_getsockopt(struct socket *sock, int level, int optname, |
| 1879 | char __user *optval, int __user *optlen) |
| 1880 | { |
| 1881 | struct smc_sock *smc; |
| 1882 | |
| 1883 | smc = smc_sk(sock->sk); |
| 1884 | /* socket options apply to the CLC socket */ |
Christoph Hellwig | a44d9e7 | 2020-07-17 08:23:31 +0200 | [diff] [blame] | 1885 | if (unlikely(!smc->clcsock->ops->getsockopt)) |
| 1886 | return -EOPNOTSUPP; |
Ursula Braun | ac71387 | 2017-01-09 16:55:13 +0100 | [diff] [blame] | 1887 | return smc->clcsock->ops->getsockopt(smc->clcsock, level, optname, |
| 1888 | optval, optlen); |
| 1889 | } |
| 1890 | |
| 1891 | static int smc_ioctl(struct socket *sock, unsigned int cmd, |
| 1892 | unsigned long arg) |
| 1893 | { |
Stefan Raspl | de8474e | 2018-05-23 16:38:11 +0200 | [diff] [blame] | 1894 | union smc_host_cursor cons, urg; |
| 1895 | struct smc_connection *conn; |
Ursula Braun | ac71387 | 2017-01-09 16:55:13 +0100 | [diff] [blame] | 1896 | struct smc_sock *smc; |
Ursula Braun | 9b67e26 | 2018-05-02 16:56:46 +0200 | [diff] [blame] | 1897 | int answ; |
Ursula Braun | ac71387 | 2017-01-09 16:55:13 +0100 | [diff] [blame] | 1898 | |
| 1899 | smc = smc_sk(sock->sk); |
Stefan Raspl | de8474e | 2018-05-23 16:38:11 +0200 | [diff] [blame] | 1900 | conn = &smc->conn; |
Ursula Braun | 1992d99 | 2018-07-16 13:56:52 +0200 | [diff] [blame] | 1901 | lock_sock(&smc->sk); |
Ursula Braun | 7311d66 | 2018-08-08 14:13:21 +0200 | [diff] [blame] | 1902 | if (smc->use_fallback) { |
| 1903 | if (!smc->clcsock) { |
| 1904 | release_sock(&smc->sk); |
| 1905 | return -EBADF; |
| 1906 | } |
| 1907 | answ = smc->clcsock->ops->ioctl(smc->clcsock, cmd, arg); |
| 1908 | release_sock(&smc->sk); |
| 1909 | return answ; |
| 1910 | } |
Ursula Braun | 9b67e26 | 2018-05-02 16:56:46 +0200 | [diff] [blame] | 1911 | switch (cmd) { |
| 1912 | case SIOCINQ: /* same as FIONREAD */ |
Ursula Braun | 1992d99 | 2018-07-16 13:56:52 +0200 | [diff] [blame] | 1913 | if (smc->sk.sk_state == SMC_LISTEN) { |
| 1914 | release_sock(&smc->sk); |
Ursula Braun | 9b67e26 | 2018-05-02 16:56:46 +0200 | [diff] [blame] | 1915 | return -EINVAL; |
Ursula Braun | 1992d99 | 2018-07-16 13:56:52 +0200 | [diff] [blame] | 1916 | } |
Ursula Braun | 2351abe | 2018-05-23 16:38:09 +0200 | [diff] [blame] | 1917 | if (smc->sk.sk_state == SMC_INIT || |
| 1918 | smc->sk.sk_state == SMC_CLOSED) |
| 1919 | answ = 0; |
| 1920 | else |
| 1921 | answ = atomic_read(&smc->conn.bytes_to_rcv); |
Ursula Braun | 9b67e26 | 2018-05-02 16:56:46 +0200 | [diff] [blame] | 1922 | break; |
| 1923 | case SIOCOUTQ: |
| 1924 | /* output queue size (not send + not acked) */ |
Ursula Braun | 1992d99 | 2018-07-16 13:56:52 +0200 | [diff] [blame] | 1925 | if (smc->sk.sk_state == SMC_LISTEN) { |
| 1926 | release_sock(&smc->sk); |
Ursula Braun | 9b67e26 | 2018-05-02 16:56:46 +0200 | [diff] [blame] | 1927 | return -EINVAL; |
Ursula Braun | 1992d99 | 2018-07-16 13:56:52 +0200 | [diff] [blame] | 1928 | } |
Ursula Braun | 2351abe | 2018-05-23 16:38:09 +0200 | [diff] [blame] | 1929 | if (smc->sk.sk_state == SMC_INIT || |
| 1930 | smc->sk.sk_state == SMC_CLOSED) |
| 1931 | answ = 0; |
| 1932 | else |
| 1933 | answ = smc->conn.sndbuf_desc->len - |
Ursula Braun | 9b67e26 | 2018-05-02 16:56:46 +0200 | [diff] [blame] | 1934 | atomic_read(&smc->conn.sndbuf_space); |
| 1935 | break; |
| 1936 | case SIOCOUTQNSD: |
| 1937 | /* output queue size (not send only) */ |
Ursula Braun | 1992d99 | 2018-07-16 13:56:52 +0200 | [diff] [blame] | 1938 | if (smc->sk.sk_state == SMC_LISTEN) { |
| 1939 | release_sock(&smc->sk); |
Ursula Braun | 9b67e26 | 2018-05-02 16:56:46 +0200 | [diff] [blame] | 1940 | return -EINVAL; |
Ursula Braun | 1992d99 | 2018-07-16 13:56:52 +0200 | [diff] [blame] | 1941 | } |
Ursula Braun | 2351abe | 2018-05-23 16:38:09 +0200 | [diff] [blame] | 1942 | if (smc->sk.sk_state == SMC_INIT || |
| 1943 | smc->sk.sk_state == SMC_CLOSED) |
| 1944 | answ = 0; |
| 1945 | else |
| 1946 | answ = smc_tx_prepared_sends(&smc->conn); |
Ursula Braun | 9b67e26 | 2018-05-02 16:56:46 +0200 | [diff] [blame] | 1947 | break; |
Stefan Raspl | de8474e | 2018-05-23 16:38:11 +0200 | [diff] [blame] | 1948 | case SIOCATMARK: |
Ursula Braun | 1992d99 | 2018-07-16 13:56:52 +0200 | [diff] [blame] | 1949 | if (smc->sk.sk_state == SMC_LISTEN) { |
| 1950 | release_sock(&smc->sk); |
Stefan Raspl | de8474e | 2018-05-23 16:38:11 +0200 | [diff] [blame] | 1951 | return -EINVAL; |
Ursula Braun | 1992d99 | 2018-07-16 13:56:52 +0200 | [diff] [blame] | 1952 | } |
Stefan Raspl | de8474e | 2018-05-23 16:38:11 +0200 | [diff] [blame] | 1953 | if (smc->sk.sk_state == SMC_INIT || |
| 1954 | smc->sk.sk_state == SMC_CLOSED) { |
| 1955 | answ = 0; |
| 1956 | } else { |
Stefan Raspl | bac6de7 | 2018-07-23 13:53:09 +0200 | [diff] [blame] | 1957 | smc_curs_copy(&cons, &conn->local_tx_ctrl.cons, conn); |
| 1958 | smc_curs_copy(&urg, &conn->urg_curs, conn); |
Stefan Raspl | de8474e | 2018-05-23 16:38:11 +0200 | [diff] [blame] | 1959 | answ = smc_curs_diff(conn->rmb_desc->len, |
| 1960 | &cons, &urg) == 1; |
| 1961 | } |
| 1962 | break; |
Ursula Braun | 9b67e26 | 2018-05-02 16:56:46 +0200 | [diff] [blame] | 1963 | default: |
Ursula Braun | 1992d99 | 2018-07-16 13:56:52 +0200 | [diff] [blame] | 1964 | release_sock(&smc->sk); |
Ursula Braun | 9b67e26 | 2018-05-02 16:56:46 +0200 | [diff] [blame] | 1965 | return -ENOIOCTLCMD; |
| 1966 | } |
Ursula Braun | 1992d99 | 2018-07-16 13:56:52 +0200 | [diff] [blame] | 1967 | release_sock(&smc->sk); |
Ursula Braun | 9b67e26 | 2018-05-02 16:56:46 +0200 | [diff] [blame] | 1968 | |
| 1969 | return put_user(answ, (int __user *)arg); |
Ursula Braun | ac71387 | 2017-01-09 16:55:13 +0100 | [diff] [blame] | 1970 | } |
| 1971 | |
| 1972 | static ssize_t smc_sendpage(struct socket *sock, struct page *page, |
| 1973 | int offset, size_t size, int flags) |
| 1974 | { |
| 1975 | struct sock *sk = sock->sk; |
| 1976 | struct smc_sock *smc; |
| 1977 | int rc = -EPIPE; |
| 1978 | |
| 1979 | smc = smc_sk(sk); |
| 1980 | lock_sock(sk); |
Stefan Raspl | bda27ff | 2018-05-03 17:57:39 +0200 | [diff] [blame] | 1981 | if (sk->sk_state != SMC_ACTIVE) { |
| 1982 | release_sock(sk); |
Ursula Braun | ac71387 | 2017-01-09 16:55:13 +0100 | [diff] [blame] | 1983 | goto out; |
Stefan Raspl | bda27ff | 2018-05-03 17:57:39 +0200 | [diff] [blame] | 1984 | } |
| 1985 | release_sock(sk); |
Ursula Braun | ac71387 | 2017-01-09 16:55:13 +0100 | [diff] [blame] | 1986 | if (smc->use_fallback) |
| 1987 | rc = kernel_sendpage(smc->clcsock, page, offset, |
| 1988 | size, flags); |
| 1989 | else |
| 1990 | rc = sock_no_sendpage(sock, page, offset, size, flags); |
| 1991 | |
| 1992 | out: |
Ursula Braun | ac71387 | 2017-01-09 16:55:13 +0100 | [diff] [blame] | 1993 | return rc; |
| 1994 | } |
| 1995 | |
Stefan Raspl | 9014db2 | 2018-05-03 18:12:39 +0200 | [diff] [blame] | 1996 | /* Map the affected portions of the rmbe into an spd, note the number of bytes |
| 1997 | * to splice in conn->splice_pending, and press 'go'. Delays consumer cursor |
| 1998 | * updates till whenever a respective page has been fully processed. |
| 1999 | * Note that subsequent recv() calls have to wait till all splice() processing |
| 2000 | * completed. |
| 2001 | */ |
Ursula Braun | ac71387 | 2017-01-09 16:55:13 +0100 | [diff] [blame] | 2002 | static ssize_t smc_splice_read(struct socket *sock, loff_t *ppos, |
| 2003 | struct pipe_inode_info *pipe, size_t len, |
Stefan Raspl | 9014db2 | 2018-05-03 18:12:39 +0200 | [diff] [blame] | 2004 | unsigned int flags) |
Ursula Braun | ac71387 | 2017-01-09 16:55:13 +0100 | [diff] [blame] | 2005 | { |
| 2006 | struct sock *sk = sock->sk; |
| 2007 | struct smc_sock *smc; |
| 2008 | int rc = -ENOTCONN; |
| 2009 | |
| 2010 | smc = smc_sk(sk); |
| 2011 | lock_sock(sk); |
Karsten Graul | 51c5aba | 2019-01-30 18:51:04 +0100 | [diff] [blame] | 2012 | if (sk->sk_state == SMC_CLOSED && (sk->sk_shutdown & RCV_SHUTDOWN)) { |
| 2013 | /* socket was connected before, no more data to read */ |
| 2014 | rc = 0; |
| 2015 | goto out; |
| 2016 | } |
Stefan Raspl | 9014db2 | 2018-05-03 18:12:39 +0200 | [diff] [blame] | 2017 | if (sk->sk_state == SMC_INIT || |
| 2018 | sk->sk_state == SMC_LISTEN || |
| 2019 | sk->sk_state == SMC_CLOSED) |
Ursula Braun | ac71387 | 2017-01-09 16:55:13 +0100 | [diff] [blame] | 2020 | goto out; |
Stefan Raspl | 9014db2 | 2018-05-03 18:12:39 +0200 | [diff] [blame] | 2021 | |
| 2022 | if (sk->sk_state == SMC_PEERFINCLOSEWAIT) { |
| 2023 | rc = 0; |
| 2024 | goto out; |
| 2025 | } |
| 2026 | |
Ursula Braun | ac71387 | 2017-01-09 16:55:13 +0100 | [diff] [blame] | 2027 | if (smc->use_fallback) { |
| 2028 | rc = smc->clcsock->ops->splice_read(smc->clcsock, ppos, |
| 2029 | pipe, len, flags); |
| 2030 | } else { |
Stefan Raspl | 9014db2 | 2018-05-03 18:12:39 +0200 | [diff] [blame] | 2031 | if (*ppos) { |
| 2032 | rc = -ESPIPE; |
| 2033 | goto out; |
| 2034 | } |
| 2035 | if (flags & SPLICE_F_NONBLOCK) |
| 2036 | flags = MSG_DONTWAIT; |
| 2037 | else |
| 2038 | flags = 0; |
| 2039 | rc = smc_rx_recvmsg(smc, NULL, pipe, len, flags); |
Ursula Braun | ac71387 | 2017-01-09 16:55:13 +0100 | [diff] [blame] | 2040 | } |
| 2041 | out: |
| 2042 | release_sock(sk); |
Stefan Raspl | 9014db2 | 2018-05-03 18:12:39 +0200 | [diff] [blame] | 2043 | |
Ursula Braun | ac71387 | 2017-01-09 16:55:13 +0100 | [diff] [blame] | 2044 | return rc; |
| 2045 | } |
| 2046 | |
| 2047 | /* must look like tcp */ |
| 2048 | static const struct proto_ops smc_sock_ops = { |
| 2049 | .family = PF_SMC, |
| 2050 | .owner = THIS_MODULE, |
| 2051 | .release = smc_release, |
| 2052 | .bind = smc_bind, |
| 2053 | .connect = smc_connect, |
| 2054 | .socketpair = sock_no_socketpair, |
| 2055 | .accept = smc_accept, |
| 2056 | .getname = smc_getname, |
Linus Torvalds | a11e1d4 | 2018-06-28 09:43:44 -0700 | [diff] [blame] | 2057 | .poll = smc_poll, |
Ursula Braun | ac71387 | 2017-01-09 16:55:13 +0100 | [diff] [blame] | 2058 | .ioctl = smc_ioctl, |
| 2059 | .listen = smc_listen, |
| 2060 | .shutdown = smc_shutdown, |
| 2061 | .setsockopt = smc_setsockopt, |
| 2062 | .getsockopt = smc_getsockopt, |
| 2063 | .sendmsg = smc_sendmsg, |
| 2064 | .recvmsg = smc_recvmsg, |
| 2065 | .mmap = sock_no_mmap, |
| 2066 | .sendpage = smc_sendpage, |
| 2067 | .splice_read = smc_splice_read, |
| 2068 | }; |
| 2069 | |
| 2070 | static int smc_create(struct net *net, struct socket *sock, int protocol, |
| 2071 | int kern) |
| 2072 | { |
Karsten Graul | aaa4d33 | 2018-03-16 15:06:41 +0100 | [diff] [blame] | 2073 | int family = (protocol == SMCPROTO_SMC6) ? PF_INET6 : PF_INET; |
Ursula Braun | ac71387 | 2017-01-09 16:55:13 +0100 | [diff] [blame] | 2074 | struct smc_sock *smc; |
| 2075 | struct sock *sk; |
| 2076 | int rc; |
| 2077 | |
| 2078 | rc = -ESOCKTNOSUPPORT; |
| 2079 | if (sock->type != SOCK_STREAM) |
| 2080 | goto out; |
| 2081 | |
| 2082 | rc = -EPROTONOSUPPORT; |
Karsten Graul | aaa4d33 | 2018-03-16 15:06:41 +0100 | [diff] [blame] | 2083 | if (protocol != SMCPROTO_SMC && protocol != SMCPROTO_SMC6) |
Ursula Braun | ac71387 | 2017-01-09 16:55:13 +0100 | [diff] [blame] | 2084 | goto out; |
| 2085 | |
| 2086 | rc = -ENOBUFS; |
| 2087 | sock->ops = &smc_sock_ops; |
Karsten Graul | aaa4d33 | 2018-03-16 15:06:41 +0100 | [diff] [blame] | 2088 | sk = smc_sock_alloc(net, sock, protocol); |
Ursula Braun | ac71387 | 2017-01-09 16:55:13 +0100 | [diff] [blame] | 2089 | if (!sk) |
| 2090 | goto out; |
| 2091 | |
| 2092 | /* create internal TCP socket for CLC handshake and fallback */ |
| 2093 | smc = smc_sk(sk); |
Ursula Braun | a046d57 | 2017-01-09 16:55:16 +0100 | [diff] [blame] | 2094 | smc->use_fallback = false; /* assume rdma capability first */ |
Karsten Graul | 603cc14 | 2018-07-25 16:35:32 +0200 | [diff] [blame] | 2095 | smc->fallback_rsn = 0; |
Karsten Graul | aaa4d33 | 2018-03-16 15:06:41 +0100 | [diff] [blame] | 2096 | rc = sock_create_kern(net, family, SOCK_STREAM, IPPROTO_TCP, |
| 2097 | &smc->clcsock); |
Davide Caratti | a5dcb73 | 2018-02-28 12:44:09 +0100 | [diff] [blame] | 2098 | if (rc) { |
Ursula Braun | ac71387 | 2017-01-09 16:55:13 +0100 | [diff] [blame] | 2099 | sk_common_release(sk); |
Davide Caratti | a5dcb73 | 2018-02-28 12:44:09 +0100 | [diff] [blame] | 2100 | goto out; |
| 2101 | } |
Ursula Braun | cd6851f | 2017-01-09 16:55:18 +0100 | [diff] [blame] | 2102 | smc->sk.sk_sndbuf = max(smc->clcsock->sk->sk_sndbuf, SMC_BUF_MIN_SIZE); |
| 2103 | smc->sk.sk_rcvbuf = max(smc->clcsock->sk->sk_rcvbuf, SMC_BUF_MIN_SIZE); |
Ursula Braun | ac71387 | 2017-01-09 16:55:13 +0100 | [diff] [blame] | 2104 | |
| 2105 | out: |
| 2106 | return rc; |
| 2107 | } |
| 2108 | |
| 2109 | static const struct net_proto_family smc_sock_family_ops = { |
| 2110 | .family = PF_SMC, |
| 2111 | .owner = THIS_MODULE, |
| 2112 | .create = smc_create, |
| 2113 | }; |
| 2114 | |
Hans Wippel | 64e28b5 | 2019-02-21 13:01:02 +0100 | [diff] [blame] | 2115 | unsigned int smc_net_id; |
| 2116 | |
| 2117 | static __net_init int smc_net_init(struct net *net) |
| 2118 | { |
| 2119 | return smc_pnet_net_init(net); |
| 2120 | } |
| 2121 | |
| 2122 | static void __net_exit smc_net_exit(struct net *net) |
| 2123 | { |
| 2124 | smc_pnet_net_exit(net); |
| 2125 | } |
| 2126 | |
| 2127 | static struct pernet_operations smc_net_ops = { |
| 2128 | .init = smc_net_init, |
| 2129 | .exit = smc_net_exit, |
| 2130 | .id = &smc_net_id, |
| 2131 | .size = sizeof(struct smc_net), |
| 2132 | }; |
| 2133 | |
Ursula Braun | ac71387 | 2017-01-09 16:55:13 +0100 | [diff] [blame] | 2134 | static int __init smc_init(void) |
| 2135 | { |
| 2136 | int rc; |
| 2137 | |
Hans Wippel | 64e28b5 | 2019-02-21 13:01:02 +0100 | [diff] [blame] | 2138 | rc = register_pernet_subsys(&smc_net_ops); |
| 2139 | if (rc) |
| 2140 | return rc; |
| 2141 | |
Ursula Braun | 201091e | 2020-09-26 12:44:24 +0200 | [diff] [blame] | 2142 | smc_ism_init(); |
| 2143 | |
Thomas Richter | 6812baa | 2017-01-09 16:55:15 +0100 | [diff] [blame] | 2144 | rc = smc_pnet_init(); |
| 2145 | if (rc) |
YueHaibing | 8c33bf1 | 2019-06-26 17:47:50 +0200 | [diff] [blame] | 2146 | goto out_pernet_subsys; |
Thomas Richter | 6812baa | 2017-01-09 16:55:15 +0100 | [diff] [blame] | 2147 | |
Karsten Graul | 22ef473 | 2020-09-10 18:48:29 +0200 | [diff] [blame] | 2148 | rc = -ENOMEM; |
| 2149 | smc_hs_wq = alloc_workqueue("smc_hs_wq", 0, 0); |
| 2150 | if (!smc_hs_wq) |
| 2151 | goto out_pnet; |
| 2152 | |
| 2153 | smc_close_wq = alloc_workqueue("smc_close_wq", 0, 0); |
| 2154 | if (!smc_close_wq) |
| 2155 | goto out_alloc_hs_wq; |
| 2156 | |
Ursula Braun | 6dabd40 | 2019-11-16 17:47:29 +0100 | [diff] [blame] | 2157 | rc = smc_core_init(); |
| 2158 | if (rc) { |
| 2159 | pr_err("%s: smc_core_init fails with %d\n", __func__, rc); |
Karsten Graul | 22ef473 | 2020-09-10 18:48:29 +0200 | [diff] [blame] | 2160 | goto out_alloc_wqs; |
Ursula Braun | 6dabd40 | 2019-11-16 17:47:29 +0100 | [diff] [blame] | 2161 | } |
| 2162 | |
Ursula Braun | 9bf9abe | 2017-01-09 16:55:21 +0100 | [diff] [blame] | 2163 | rc = smc_llc_init(); |
| 2164 | if (rc) { |
| 2165 | pr_err("%s: smc_llc_init fails with %d\n", __func__, rc); |
Ursula Braun | 6dabd40 | 2019-11-16 17:47:29 +0100 | [diff] [blame] | 2166 | goto out_core; |
Ursula Braun | 9bf9abe | 2017-01-09 16:55:21 +0100 | [diff] [blame] | 2167 | } |
| 2168 | |
Ursula Braun | 5f08318 | 2017-01-09 16:55:22 +0100 | [diff] [blame] | 2169 | rc = smc_cdc_init(); |
| 2170 | if (rc) { |
| 2171 | pr_err("%s: smc_cdc_init fails with %d\n", __func__, rc); |
Ursula Braun | 6dabd40 | 2019-11-16 17:47:29 +0100 | [diff] [blame] | 2172 | goto out_core; |
Ursula Braun | 5f08318 | 2017-01-09 16:55:22 +0100 | [diff] [blame] | 2173 | } |
| 2174 | |
Ursula Braun | ac71387 | 2017-01-09 16:55:13 +0100 | [diff] [blame] | 2175 | rc = proto_register(&smc_proto, 1); |
| 2176 | if (rc) { |
Karsten Graul | aaa4d33 | 2018-03-16 15:06:41 +0100 | [diff] [blame] | 2177 | pr_err("%s: proto_register(v4) fails with %d\n", __func__, rc); |
Ursula Braun | 6dabd40 | 2019-11-16 17:47:29 +0100 | [diff] [blame] | 2178 | goto out_core; |
Ursula Braun | ac71387 | 2017-01-09 16:55:13 +0100 | [diff] [blame] | 2179 | } |
| 2180 | |
Karsten Graul | aaa4d33 | 2018-03-16 15:06:41 +0100 | [diff] [blame] | 2181 | rc = proto_register(&smc_proto6, 1); |
| 2182 | if (rc) { |
| 2183 | pr_err("%s: proto_register(v6) fails with %d\n", __func__, rc); |
| 2184 | goto out_proto; |
| 2185 | } |
| 2186 | |
Ursula Braun | ac71387 | 2017-01-09 16:55:13 +0100 | [diff] [blame] | 2187 | rc = sock_register(&smc_sock_family_ops); |
| 2188 | if (rc) { |
| 2189 | pr_err("%s: sock_register fails with %d\n", __func__, rc); |
Karsten Graul | aaa4d33 | 2018-03-16 15:06:41 +0100 | [diff] [blame] | 2190 | goto out_proto6; |
Ursula Braun | ac71387 | 2017-01-09 16:55:13 +0100 | [diff] [blame] | 2191 | } |
Ursula Braun | f16a7dd | 2017-01-09 16:55:26 +0100 | [diff] [blame] | 2192 | INIT_HLIST_HEAD(&smc_v4_hashinfo.ht); |
Karsten Graul | aaa4d33 | 2018-03-16 15:06:41 +0100 | [diff] [blame] | 2193 | INIT_HLIST_HEAD(&smc_v6_hashinfo.ht); |
Ursula Braun | ac71387 | 2017-01-09 16:55:13 +0100 | [diff] [blame] | 2194 | |
Ursula Braun | a4cf044 | 2017-01-09 16:55:14 +0100 | [diff] [blame] | 2195 | rc = smc_ib_register_client(); |
| 2196 | if (rc) { |
| 2197 | pr_err("%s: ib_register fails with %d\n", __func__, rc); |
| 2198 | goto out_sock; |
| 2199 | } |
| 2200 | |
Ursula Braun | c5c1cc9 | 2017-10-25 11:01:46 +0200 | [diff] [blame] | 2201 | static_branch_enable(&tcp_have_smc); |
Ursula Braun | ac71387 | 2017-01-09 16:55:13 +0100 | [diff] [blame] | 2202 | return 0; |
| 2203 | |
Ursula Braun | a4cf044 | 2017-01-09 16:55:14 +0100 | [diff] [blame] | 2204 | out_sock: |
| 2205 | sock_unregister(PF_SMC); |
Karsten Graul | aaa4d33 | 2018-03-16 15:06:41 +0100 | [diff] [blame] | 2206 | out_proto6: |
| 2207 | proto_unregister(&smc_proto6); |
Ursula Braun | ac71387 | 2017-01-09 16:55:13 +0100 | [diff] [blame] | 2208 | out_proto: |
| 2209 | proto_unregister(&smc_proto); |
Ursula Braun | 6dabd40 | 2019-11-16 17:47:29 +0100 | [diff] [blame] | 2210 | out_core: |
| 2211 | smc_core_exit(); |
Karsten Graul | 22ef473 | 2020-09-10 18:48:29 +0200 | [diff] [blame] | 2212 | out_alloc_wqs: |
| 2213 | destroy_workqueue(smc_close_wq); |
| 2214 | out_alloc_hs_wq: |
| 2215 | destroy_workqueue(smc_hs_wq); |
Thomas Richter | 6812baa | 2017-01-09 16:55:15 +0100 | [diff] [blame] | 2216 | out_pnet: |
| 2217 | smc_pnet_exit(); |
YueHaibing | 8c33bf1 | 2019-06-26 17:47:50 +0200 | [diff] [blame] | 2218 | out_pernet_subsys: |
| 2219 | unregister_pernet_subsys(&smc_net_ops); |
| 2220 | |
Ursula Braun | ac71387 | 2017-01-09 16:55:13 +0100 | [diff] [blame] | 2221 | return rc; |
| 2222 | } |
| 2223 | |
| 2224 | static void __exit smc_exit(void) |
| 2225 | { |
Ursula Braun | c5c1cc9 | 2017-10-25 11:01:46 +0200 | [diff] [blame] | 2226 | static_branch_disable(&tcp_have_smc); |
Ursula Braun | ac71387 | 2017-01-09 16:55:13 +0100 | [diff] [blame] | 2227 | sock_unregister(PF_SMC); |
Ursula Braun | 6dabd40 | 2019-11-16 17:47:29 +0100 | [diff] [blame] | 2228 | smc_core_exit(); |
| 2229 | smc_ib_unregister_client(); |
Karsten Graul | 22ef473 | 2020-09-10 18:48:29 +0200 | [diff] [blame] | 2230 | destroy_workqueue(smc_close_wq); |
| 2231 | destroy_workqueue(smc_hs_wq); |
Karsten Graul | aaa4d33 | 2018-03-16 15:06:41 +0100 | [diff] [blame] | 2232 | proto_unregister(&smc_proto6); |
Ursula Braun | ac71387 | 2017-01-09 16:55:13 +0100 | [diff] [blame] | 2233 | proto_unregister(&smc_proto); |
Thomas Richter | 6812baa | 2017-01-09 16:55:15 +0100 | [diff] [blame] | 2234 | smc_pnet_exit(); |
Hans Wippel | 64e28b5 | 2019-02-21 13:01:02 +0100 | [diff] [blame] | 2235 | unregister_pernet_subsys(&smc_net_ops); |
Ursula Braun | 4ead9c9 | 2019-11-16 17:47:31 +0100 | [diff] [blame] | 2236 | rcu_barrier(); |
Ursula Braun | ac71387 | 2017-01-09 16:55:13 +0100 | [diff] [blame] | 2237 | } |
| 2238 | |
| 2239 | module_init(smc_init); |
| 2240 | module_exit(smc_exit); |
| 2241 | |
| 2242 | MODULE_AUTHOR("Ursula Braun <ubraun@linux.vnet.ibm.com>"); |
| 2243 | MODULE_DESCRIPTION("smc socket address family"); |
| 2244 | MODULE_LICENSE("GPL"); |
| 2245 | MODULE_ALIAS_NETPROTO(PF_SMC); |