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