Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Ursula Braun | e6727f3 | 2017-01-09 16:55:23 +0100 | [diff] [blame] | 2 | /* |
| 3 | * Shared Memory Communications over RDMA (SMC-R) and RoCE |
| 4 | * |
| 5 | * Manage send buffer. |
| 6 | * Producer: |
| 7 | * Copy user space data into send buffer, if send buffer space available. |
| 8 | * Consumer: |
| 9 | * Trigger RDMA write into RMBE of peer and send CDC, if RMBE space available. |
| 10 | * |
| 11 | * Copyright IBM Corp. 2016 |
| 12 | * |
| 13 | * Author(s): Ursula Braun <ubraun@linux.vnet.ibm.com> |
| 14 | */ |
| 15 | |
| 16 | #include <linux/net.h> |
| 17 | #include <linux/rcupdate.h> |
| 18 | #include <linux/workqueue.h> |
Ingo Molnar | c3edc40 | 2017-02-02 08:35:14 +0100 | [diff] [blame] | 19 | #include <linux/sched/signal.h> |
| 20 | |
Ursula Braun | e6727f3 | 2017-01-09 16:55:23 +0100 | [diff] [blame] | 21 | #include <net/sock.h> |
Ursula Braun | 01d2f7e | 2018-04-26 17:18:22 +0200 | [diff] [blame] | 22 | #include <net/tcp.h> |
Ursula Braun | e6727f3 | 2017-01-09 16:55:23 +0100 | [diff] [blame] | 23 | |
| 24 | #include "smc.h" |
| 25 | #include "smc_wr.h" |
| 26 | #include "smc_cdc.h" |
Karsten Graul | 5bc056d | 2019-02-12 16:29:51 +0100 | [diff] [blame] | 27 | #include "smc_close.h" |
Hans Wippel | be244f2 | 2018-06-28 19:05:10 +0200 | [diff] [blame] | 28 | #include "smc_ism.h" |
Ursula Braun | e6727f3 | 2017-01-09 16:55:23 +0100 | [diff] [blame] | 29 | #include "smc_tx.h" |
| 30 | |
Karsten Graul | 16297d1 | 2019-02-12 16:29:52 +0100 | [diff] [blame] | 31 | #define SMC_TX_WORK_DELAY 0 |
Ursula Braun | 01d2f7e | 2018-04-26 17:18:22 +0200 | [diff] [blame] | 32 | #define SMC_TX_CORK_DELAY (HZ >> 2) /* 250 ms */ |
Ursula Braun | 18e537c | 2017-09-21 09:16:33 +0200 | [diff] [blame] | 33 | |
Ursula Braun | e6727f3 | 2017-01-09 16:55:23 +0100 | [diff] [blame] | 34 | /***************************** sndbuf producer *******************************/ |
| 35 | |
| 36 | /* callback implementation for sk.sk_write_space() |
Stefan Raspl | de8474e | 2018-05-23 16:38:11 +0200 | [diff] [blame] | 37 | * to wakeup sndbuf producers that blocked with smc_tx_wait(). |
Ursula Braun | e6727f3 | 2017-01-09 16:55:23 +0100 | [diff] [blame] | 38 | * called under sk_socket lock. |
| 39 | */ |
| 40 | static void smc_tx_write_space(struct sock *sk) |
| 41 | { |
| 42 | struct socket *sock = sk->sk_socket; |
| 43 | struct smc_sock *smc = smc_sk(sk); |
| 44 | struct socket_wq *wq; |
| 45 | |
| 46 | /* similar to sk_stream_write_space */ |
| 47 | if (atomic_read(&smc->conn.sndbuf_space) && sock) { |
| 48 | clear_bit(SOCK_NOSPACE, &sock->flags); |
| 49 | rcu_read_lock(); |
| 50 | wq = rcu_dereference(sk->sk_wq); |
| 51 | if (skwq_has_sleeper(wq)) |
| 52 | wake_up_interruptible_poll(&wq->wait, |
Linus Torvalds | a9a0884 | 2018-02-11 14:34:03 -0800 | [diff] [blame] | 53 | EPOLLOUT | EPOLLWRNORM | |
| 54 | EPOLLWRBAND); |
Ursula Braun | e6727f3 | 2017-01-09 16:55:23 +0100 | [diff] [blame] | 55 | if (wq && wq->fasync_list && !(sk->sk_shutdown & SEND_SHUTDOWN)) |
| 56 | sock_wake_async(wq, SOCK_WAKE_SPACE, POLL_OUT); |
| 57 | rcu_read_unlock(); |
| 58 | } |
| 59 | } |
| 60 | |
Stefan Raspl | de8474e | 2018-05-23 16:38:11 +0200 | [diff] [blame] | 61 | /* Wakeup sndbuf producers that blocked with smc_tx_wait(). |
Ursula Braun | e6727f3 | 2017-01-09 16:55:23 +0100 | [diff] [blame] | 62 | * Cf. tcp_data_snd_check()=>tcp_check_space()=>tcp_new_space(). |
| 63 | */ |
| 64 | void smc_tx_sndbuf_nonfull(struct smc_sock *smc) |
| 65 | { |
| 66 | if (smc->sk.sk_socket && |
| 67 | test_bit(SOCK_NOSPACE, &smc->sk.sk_socket->flags)) |
| 68 | smc->sk.sk_write_space(&smc->sk); |
| 69 | } |
| 70 | |
Stefan Raspl | de8474e | 2018-05-23 16:38:11 +0200 | [diff] [blame] | 71 | /* blocks sndbuf producer until at least one byte of free space available |
| 72 | * or urgent Byte was consumed |
| 73 | */ |
| 74 | static int smc_tx_wait(struct smc_sock *smc, int flags) |
Ursula Braun | e6727f3 | 2017-01-09 16:55:23 +0100 | [diff] [blame] | 75 | { |
| 76 | DEFINE_WAIT_FUNC(wait, woken_wake_function); |
| 77 | struct smc_connection *conn = &smc->conn; |
| 78 | struct sock *sk = &smc->sk; |
Ursula Braun | e6727f3 | 2017-01-09 16:55:23 +0100 | [diff] [blame] | 79 | long timeo; |
| 80 | int rc = 0; |
| 81 | |
| 82 | /* similar to sk_stream_wait_memory */ |
| 83 | timeo = sock_sndtimeo(sk, flags & MSG_DONTWAIT); |
Ursula Braun | e6727f3 | 2017-01-09 16:55:23 +0100 | [diff] [blame] | 84 | add_wait_queue(sk_sleep(sk), &wait); |
| 85 | while (1) { |
| 86 | sk_set_bit(SOCKWQ_ASYNC_NOSPACE, sk); |
| 87 | if (sk->sk_err || |
| 88 | (sk->sk_shutdown & SEND_SHUTDOWN) || |
Ursula Braun | b290098 | 2019-10-21 16:13:08 +0200 | [diff] [blame] | 89 | conn->killed || |
Ursula Braun | e6727f3 | 2017-01-09 16:55:23 +0100 | [diff] [blame] | 90 | conn->local_tx_ctrl.conn_state_flags.peer_done_writing) { |
| 91 | rc = -EPIPE; |
| 92 | break; |
| 93 | } |
Ursula Braun | aa377e6 | 2018-01-24 10:28:17 +0100 | [diff] [blame] | 94 | if (smc_cdc_rxed_any_close(conn)) { |
Ursula Braun | e6727f3 | 2017-01-09 16:55:23 +0100 | [diff] [blame] | 95 | rc = -ECONNRESET; |
| 96 | break; |
| 97 | } |
| 98 | if (!timeo) { |
Jason Baron | 4651d18 | 2019-08-19 14:36:01 -0400 | [diff] [blame] | 99 | /* ensure EPOLLOUT is subsequently generated */ |
| 100 | set_bit(SOCK_NOSPACE, &sk->sk_socket->flags); |
Ursula Braun | e6727f3 | 2017-01-09 16:55:23 +0100 | [diff] [blame] | 101 | rc = -EAGAIN; |
| 102 | break; |
| 103 | } |
| 104 | if (signal_pending(current)) { |
| 105 | rc = sock_intr_errno(timeo); |
| 106 | break; |
| 107 | } |
| 108 | sk_clear_bit(SOCKWQ_ASYNC_NOSPACE, sk); |
Stefan Raspl | de8474e | 2018-05-23 16:38:11 +0200 | [diff] [blame] | 109 | if (atomic_read(&conn->sndbuf_space) && !conn->urg_tx_pend) |
| 110 | break; /* at least 1 byte of free & no urgent data */ |
Ursula Braun | e6727f3 | 2017-01-09 16:55:23 +0100 | [diff] [blame] | 111 | set_bit(SOCK_NOSPACE, &sk->sk_socket->flags); |
Ursula Braun | e6727f3 | 2017-01-09 16:55:23 +0100 | [diff] [blame] | 112 | sk_wait_event(sk, &timeo, |
| 113 | sk->sk_err || |
| 114 | (sk->sk_shutdown & SEND_SHUTDOWN) || |
Ursula Braun | aa377e6 | 2018-01-24 10:28:17 +0100 | [diff] [blame] | 115 | smc_cdc_rxed_any_close(conn) || |
Stefan Raspl | de8474e | 2018-05-23 16:38:11 +0200 | [diff] [blame] | 116 | (atomic_read(&conn->sndbuf_space) && |
| 117 | !conn->urg_tx_pend), |
Ursula Braun | e6727f3 | 2017-01-09 16:55:23 +0100 | [diff] [blame] | 118 | &wait); |
Ursula Braun | e6727f3 | 2017-01-09 16:55:23 +0100 | [diff] [blame] | 119 | } |
| 120 | remove_wait_queue(sk_sleep(sk), &wait); |
| 121 | return rc; |
| 122 | } |
| 123 | |
Ursula Braun | 01d2f7e | 2018-04-26 17:18:22 +0200 | [diff] [blame] | 124 | static bool smc_tx_is_corked(struct smc_sock *smc) |
| 125 | { |
| 126 | struct tcp_sock *tp = tcp_sk(smc->clcsock->sk); |
| 127 | |
| 128 | return (tp->nonagle & TCP_NAGLE_CORK) ? true : false; |
| 129 | } |
| 130 | |
Ursula Braun | e6727f3 | 2017-01-09 16:55:23 +0100 | [diff] [blame] | 131 | /* sndbuf producer: main API called by socket layer. |
| 132 | * called under sock lock. |
| 133 | */ |
| 134 | int smc_tx_sendmsg(struct smc_sock *smc, struct msghdr *msg, size_t len) |
| 135 | { |
| 136 | size_t copylen, send_done = 0, send_remaining = len; |
| 137 | size_t chunk_len, chunk_off, chunk_len_sum; |
| 138 | struct smc_connection *conn = &smc->conn; |
| 139 | union smc_host_cursor prep; |
| 140 | struct sock *sk = &smc->sk; |
| 141 | char *sndbuf_base; |
| 142 | int tx_cnt_prep; |
| 143 | int writespace; |
| 144 | int rc, chunk; |
| 145 | |
| 146 | /* This should be in poll */ |
| 147 | sk_clear_bit(SOCKWQ_ASYNC_NOSPACE, sk); |
| 148 | |
| 149 | if (sk->sk_err || (sk->sk_shutdown & SEND_SHUTDOWN)) { |
| 150 | rc = -EPIPE; |
| 151 | goto out_err; |
| 152 | } |
| 153 | |
| 154 | while (msg_data_left(msg)) { |
| 155 | if (sk->sk_state == SMC_INIT) |
| 156 | return -ENOTCONN; |
| 157 | if (smc->sk.sk_shutdown & SEND_SHUTDOWN || |
Ursula Braun | b38d732 | 2017-01-09 16:55:25 +0100 | [diff] [blame] | 158 | (smc->sk.sk_err == ECONNABORTED) || |
Ursula Braun | b290098 | 2019-10-21 16:13:08 +0200 | [diff] [blame] | 159 | conn->killed) |
Ursula Braun | e6727f3 | 2017-01-09 16:55:23 +0100 | [diff] [blame] | 160 | return -EPIPE; |
| 161 | if (smc_cdc_rxed_any_close(conn)) |
| 162 | return send_done ?: -ECONNRESET; |
| 163 | |
Stefan Raspl | de8474e | 2018-05-23 16:38:11 +0200 | [diff] [blame] | 164 | if (msg->msg_flags & MSG_OOB) |
| 165 | conn->local_tx_ctrl.prod_flags.urg_data_pending = 1; |
| 166 | |
| 167 | if (!atomic_read(&conn->sndbuf_space) || conn->urg_tx_pend) { |
Karsten Graul | 6889b36 | 2019-01-30 18:51:03 +0100 | [diff] [blame] | 168 | if (send_done) |
| 169 | return send_done; |
Stefan Raspl | de8474e | 2018-05-23 16:38:11 +0200 | [diff] [blame] | 170 | rc = smc_tx_wait(smc, msg->msg_flags); |
Karsten Graul | 6889b36 | 2019-01-30 18:51:03 +0100 | [diff] [blame] | 171 | if (rc) |
Ursula Braun | e6727f3 | 2017-01-09 16:55:23 +0100 | [diff] [blame] | 172 | goto out_err; |
Ursula Braun | e6727f3 | 2017-01-09 16:55:23 +0100 | [diff] [blame] | 173 | continue; |
| 174 | } |
| 175 | |
| 176 | /* initialize variables for 1st iteration of subsequent loop */ |
Stefan Raspl | de8474e | 2018-05-23 16:38:11 +0200 | [diff] [blame] | 177 | /* could be just 1 byte, even after smc_tx_wait above */ |
Ursula Braun | e6727f3 | 2017-01-09 16:55:23 +0100 | [diff] [blame] | 178 | writespace = atomic_read(&conn->sndbuf_space); |
| 179 | /* not more than what user space asked for */ |
| 180 | copylen = min_t(size_t, send_remaining, writespace); |
| 181 | /* determine start of sndbuf */ |
| 182 | sndbuf_base = conn->sndbuf_desc->cpu_addr; |
Stefan Raspl | bac6de7 | 2018-07-23 13:53:09 +0200 | [diff] [blame] | 183 | smc_curs_copy(&prep, &conn->tx_curs_prep, conn); |
Ursula Braun | e6727f3 | 2017-01-09 16:55:23 +0100 | [diff] [blame] | 184 | tx_cnt_prep = prep.count; |
| 185 | /* determine chunks where to write into sndbuf */ |
| 186 | /* either unwrapped case, or 1st chunk of wrapped case */ |
Hans Wippel | 69cb7dc | 2018-05-18 09:34:10 +0200 | [diff] [blame] | 187 | chunk_len = min_t(size_t, copylen, conn->sndbuf_desc->len - |
| 188 | tx_cnt_prep); |
Ursula Braun | e6727f3 | 2017-01-09 16:55:23 +0100 | [diff] [blame] | 189 | chunk_len_sum = chunk_len; |
| 190 | chunk_off = tx_cnt_prep; |
Ursula Braun | 10428dd | 2017-07-28 13:56:22 +0200 | [diff] [blame] | 191 | smc_sndbuf_sync_sg_for_cpu(conn); |
Ursula Braun | e6727f3 | 2017-01-09 16:55:23 +0100 | [diff] [blame] | 192 | for (chunk = 0; chunk < 2; chunk++) { |
| 193 | rc = memcpy_from_msg(sndbuf_base + chunk_off, |
| 194 | msg, chunk_len); |
| 195 | if (rc) { |
Ursula Braun | 10428dd | 2017-07-28 13:56:22 +0200 | [diff] [blame] | 196 | smc_sndbuf_sync_sg_for_device(conn); |
Ursula Braun | e6727f3 | 2017-01-09 16:55:23 +0100 | [diff] [blame] | 197 | if (send_done) |
| 198 | return send_done; |
| 199 | goto out_err; |
| 200 | } |
| 201 | send_done += chunk_len; |
| 202 | send_remaining -= chunk_len; |
| 203 | |
| 204 | if (chunk_len_sum == copylen) |
| 205 | break; /* either on 1st or 2nd iteration */ |
| 206 | /* prepare next (== 2nd) iteration */ |
| 207 | chunk_len = copylen - chunk_len; /* remainder */ |
| 208 | chunk_len_sum += chunk_len; |
| 209 | chunk_off = 0; /* modulo offset in send ring buffer */ |
| 210 | } |
Ursula Braun | 10428dd | 2017-07-28 13:56:22 +0200 | [diff] [blame] | 211 | smc_sndbuf_sync_sg_for_device(conn); |
Ursula Braun | e6727f3 | 2017-01-09 16:55:23 +0100 | [diff] [blame] | 212 | /* update cursors */ |
Hans Wippel | 69cb7dc | 2018-05-18 09:34:10 +0200 | [diff] [blame] | 213 | smc_curs_add(conn->sndbuf_desc->len, &prep, copylen); |
Stefan Raspl | bac6de7 | 2018-07-23 13:53:09 +0200 | [diff] [blame] | 214 | smc_curs_copy(&conn->tx_curs_prep, &prep, conn); |
Ursula Braun | e6727f3 | 2017-01-09 16:55:23 +0100 | [diff] [blame] | 215 | /* increased in send tasklet smc_cdc_tx_handler() */ |
| 216 | smp_mb__before_atomic(); |
| 217 | atomic_sub(copylen, &conn->sndbuf_space); |
Hans Wippel | 69cb7dc | 2018-05-18 09:34:10 +0200 | [diff] [blame] | 218 | /* guarantee 0 <= sndbuf_space <= sndbuf_desc->len */ |
Ursula Braun | e6727f3 | 2017-01-09 16:55:23 +0100 | [diff] [blame] | 219 | smp_mb__after_atomic(); |
| 220 | /* since we just produced more new data into sndbuf, |
| 221 | * trigger sndbuf consumer: RDMA write into peer RMBE and CDC |
| 222 | */ |
Stefan Raspl | de8474e | 2018-05-23 16:38:11 +0200 | [diff] [blame] | 223 | if ((msg->msg_flags & MSG_OOB) && !send_remaining) |
| 224 | conn->urg_tx_pend = true; |
Ursula Braun | 01d2f7e | 2018-04-26 17:18:22 +0200 | [diff] [blame] | 225 | if ((msg->msg_flags & MSG_MORE || smc_tx_is_corked(smc)) && |
| 226 | (atomic_read(&conn->sndbuf_space) > |
Hans Wippel | 69cb7dc | 2018-05-18 09:34:10 +0200 | [diff] [blame] | 227 | (conn->sndbuf_desc->len >> 1))) |
Ursula Braun | 01d2f7e | 2018-04-26 17:18:22 +0200 | [diff] [blame] | 228 | /* for a corked socket defer the RDMA writes if there |
| 229 | * is still sufficient sndbuf_space available |
| 230 | */ |
| 231 | schedule_delayed_work(&conn->tx_work, |
| 232 | SMC_TX_CORK_DELAY); |
| 233 | else |
| 234 | smc_tx_sndbuf_nonempty(conn); |
Ursula Braun | e6727f3 | 2017-01-09 16:55:23 +0100 | [diff] [blame] | 235 | } /* while (msg_data_left(msg)) */ |
| 236 | |
| 237 | return send_done; |
| 238 | |
| 239 | out_err: |
| 240 | rc = sk_stream_error(sk, msg->msg_flags, rc); |
| 241 | /* make sure we wake any epoll edge trigger waiter */ |
| 242 | if (unlikely(rc == -EAGAIN)) |
| 243 | sk->sk_write_space(sk); |
| 244 | return rc; |
| 245 | } |
| 246 | |
| 247 | /***************************** sndbuf consumer *******************************/ |
| 248 | |
Hans Wippel | be244f2 | 2018-06-28 19:05:10 +0200 | [diff] [blame] | 249 | /* sndbuf consumer: actual data transfer of one target chunk with ISM write */ |
| 250 | int smcd_tx_ism_write(struct smc_connection *conn, void *data, size_t len, |
| 251 | u32 offset, int signal) |
| 252 | { |
| 253 | struct smc_ism_position pos; |
| 254 | int rc; |
| 255 | |
| 256 | memset(&pos, 0, sizeof(pos)); |
| 257 | pos.token = conn->peer_token; |
| 258 | pos.index = conn->peer_rmbe_idx; |
| 259 | pos.offset = conn->tx_off + offset; |
| 260 | pos.signal = signal; |
| 261 | rc = smc_ism_write(conn->lgr->smcd, &pos, data, len); |
| 262 | if (rc) |
| 263 | conn->local_tx_ctrl.conn_state_flags.peer_conn_abort = 1; |
| 264 | return rc; |
| 265 | } |
| 266 | |
Ursula Braun | e6727f3 | 2017-01-09 16:55:23 +0100 | [diff] [blame] | 267 | /* sndbuf consumer: actual data transfer of one target chunk with RDMA write */ |
| 268 | static int smc_tx_rdma_write(struct smc_connection *conn, int peer_rmbe_offset, |
Ursula Braun | ad6f317 | 2019-02-04 13:44:44 +0100 | [diff] [blame] | 269 | int num_sges, struct ib_rdma_wr *rdma_wr) |
Ursula Braun | e6727f3 | 2017-01-09 16:55:23 +0100 | [diff] [blame] | 270 | { |
| 271 | struct smc_link_group *lgr = conn->lgr; |
Karsten Graul | 387707f | 2020-04-29 17:10:40 +0200 | [diff] [blame] | 272 | struct smc_link *link = conn->lnk; |
Ursula Braun | e6727f3 | 2017-01-09 16:55:23 +0100 | [diff] [blame] | 273 | int rc; |
| 274 | |
Ursula Braun | ad6f317 | 2019-02-04 13:44:44 +0100 | [diff] [blame] | 275 | rdma_wr->wr.wr_id = smc_wr_tx_get_next_wr_id(link); |
| 276 | rdma_wr->wr.num_sge = num_sges; |
| 277 | rdma_wr->remote_addr = |
Karsten Graul | 387707f | 2020-04-29 17:10:40 +0200 | [diff] [blame] | 278 | lgr->rtokens[conn->rtoken_idx][link->link_idx].dma_addr + |
Ursula Braun | e6727f3 | 2017-01-09 16:55:23 +0100 | [diff] [blame] | 279 | /* RMBE within RMB */ |
Hans Wippel | 95d8d263 | 2018-05-18 09:34:13 +0200 | [diff] [blame] | 280 | conn->tx_off + |
Ursula Braun | e6727f3 | 2017-01-09 16:55:23 +0100 | [diff] [blame] | 281 | /* offset within RMBE */ |
| 282 | peer_rmbe_offset; |
Karsten Graul | 387707f | 2020-04-29 17:10:40 +0200 | [diff] [blame] | 283 | rdma_wr->rkey = lgr->rtokens[conn->rtoken_idx][link->link_idx].rkey; |
Ursula Braun | ad6f317 | 2019-02-04 13:44:44 +0100 | [diff] [blame] | 284 | rc = ib_post_send(link->roce_qp, &rdma_wr->wr, NULL); |
Ursula Braun | b290098 | 2019-10-21 16:13:08 +0200 | [diff] [blame] | 285 | if (rc) |
Karsten Graul | 8752393 | 2020-05-01 12:48:09 +0200 | [diff] [blame] | 286 | smcr_link_down_cond_sched(link); |
Ursula Braun | e6727f3 | 2017-01-09 16:55:23 +0100 | [diff] [blame] | 287 | return rc; |
| 288 | } |
| 289 | |
| 290 | /* sndbuf consumer */ |
| 291 | static inline void smc_tx_advance_cursors(struct smc_connection *conn, |
| 292 | union smc_host_cursor *prod, |
| 293 | union smc_host_cursor *sent, |
| 294 | size_t len) |
| 295 | { |
| 296 | smc_curs_add(conn->peer_rmbe_size, prod, len); |
| 297 | /* increased in recv tasklet smc_cdc_msg_rcv() */ |
| 298 | smp_mb__before_atomic(); |
| 299 | /* data in flight reduces usable snd_wnd */ |
| 300 | atomic_sub(len, &conn->peer_rmbe_space); |
| 301 | /* guarantee 0 <= peer_rmbe_space <= peer_rmbe_size */ |
| 302 | smp_mb__after_atomic(); |
Hans Wippel | 69cb7dc | 2018-05-18 09:34:10 +0200 | [diff] [blame] | 303 | smc_curs_add(conn->sndbuf_desc->len, sent, len); |
Ursula Braun | e6727f3 | 2017-01-09 16:55:23 +0100 | [diff] [blame] | 304 | } |
| 305 | |
Hans Wippel | be244f2 | 2018-06-28 19:05:10 +0200 | [diff] [blame] | 306 | /* SMC-R helper for smc_tx_rdma_writes() */ |
| 307 | static int smcr_tx_rdma_writes(struct smc_connection *conn, size_t len, |
| 308 | size_t src_off, size_t src_len, |
Ursula Braun | ad6f317 | 2019-02-04 13:44:44 +0100 | [diff] [blame] | 309 | size_t dst_off, size_t dst_len, |
| 310 | struct smc_rdma_wr *wr_rdma_buf) |
Ursula Braun | e6727f3 | 2017-01-09 16:55:23 +0100 | [diff] [blame] | 311 | { |
Karsten Graul | 387707f | 2020-04-29 17:10:40 +0200 | [diff] [blame] | 312 | struct smc_link *link = conn->lnk; |
| 313 | |
Hans Wippel | be244f2 | 2018-06-28 19:05:10 +0200 | [diff] [blame] | 314 | dma_addr_t dma_addr = |
Karsten Graul | 387707f | 2020-04-29 17:10:40 +0200 | [diff] [blame] | 315 | sg_dma_address(conn->sndbuf_desc->sgt[link->link_idx].sgl); |
Hans Wippel | be244f2 | 2018-06-28 19:05:10 +0200 | [diff] [blame] | 316 | int src_len_sum = src_len, dst_len_sum = dst_len; |
Hans Wippel | be244f2 | 2018-06-28 19:05:10 +0200 | [diff] [blame] | 317 | int sent_count = src_off; |
| 318 | int srcchunk, dstchunk; |
Ursula Braun | e6727f3 | 2017-01-09 16:55:23 +0100 | [diff] [blame] | 319 | int num_sges; |
| 320 | int rc; |
| 321 | |
Ursula Braun | e6727f3 | 2017-01-09 16:55:23 +0100 | [diff] [blame] | 322 | for (dstchunk = 0; dstchunk < 2; dstchunk++) { |
Ursula Braun | ad6f317 | 2019-02-04 13:44:44 +0100 | [diff] [blame] | 323 | struct ib_sge *sge = |
| 324 | wr_rdma_buf->wr_tx_rdma[dstchunk].wr.sg_list; |
| 325 | |
Ursula Braun | e6727f3 | 2017-01-09 16:55:23 +0100 | [diff] [blame] | 326 | num_sges = 0; |
| 327 | for (srcchunk = 0; srcchunk < 2; srcchunk++) { |
Ursula Braun | ad6f317 | 2019-02-04 13:44:44 +0100 | [diff] [blame] | 328 | sge[srcchunk].addr = dma_addr + src_off; |
| 329 | sge[srcchunk].length = src_len; |
Ursula Braun | e6727f3 | 2017-01-09 16:55:23 +0100 | [diff] [blame] | 330 | num_sges++; |
Hans Wippel | be244f2 | 2018-06-28 19:05:10 +0200 | [diff] [blame] | 331 | |
Ursula Braun | e6727f3 | 2017-01-09 16:55:23 +0100 | [diff] [blame] | 332 | src_off += src_len; |
Hans Wippel | 69cb7dc | 2018-05-18 09:34:10 +0200 | [diff] [blame] | 333 | if (src_off >= conn->sndbuf_desc->len) |
| 334 | src_off -= conn->sndbuf_desc->len; |
Ursula Braun | e6727f3 | 2017-01-09 16:55:23 +0100 | [diff] [blame] | 335 | /* modulo in send ring */ |
| 336 | if (src_len_sum == dst_len) |
| 337 | break; /* either on 1st or 2nd iteration */ |
| 338 | /* prepare next (== 2nd) iteration */ |
| 339 | src_len = dst_len - src_len; /* remainder */ |
| 340 | src_len_sum += src_len; |
| 341 | } |
Ursula Braun | ad6f317 | 2019-02-04 13:44:44 +0100 | [diff] [blame] | 342 | rc = smc_tx_rdma_write(conn, dst_off, num_sges, |
| 343 | &wr_rdma_buf->wr_tx_rdma[dstchunk]); |
Ursula Braun | e6727f3 | 2017-01-09 16:55:23 +0100 | [diff] [blame] | 344 | if (rc) |
| 345 | return rc; |
| 346 | if (dst_len_sum == len) |
| 347 | break; /* either on 1st or 2nd iteration */ |
| 348 | /* prepare next (== 2nd) iteration */ |
| 349 | dst_off = 0; /* modulo offset in RMBE ring buffer */ |
| 350 | dst_len = len - dst_len; /* remainder */ |
| 351 | dst_len_sum += dst_len; |
Hans Wippel | be244f2 | 2018-06-28 19:05:10 +0200 | [diff] [blame] | 352 | src_len = min_t(int, dst_len, conn->sndbuf_desc->len - |
| 353 | sent_count); |
Ursula Braun | e6727f3 | 2017-01-09 16:55:23 +0100 | [diff] [blame] | 354 | src_len_sum = src_len; |
| 355 | } |
Hans Wippel | be244f2 | 2018-06-28 19:05:10 +0200 | [diff] [blame] | 356 | return 0; |
| 357 | } |
| 358 | |
| 359 | /* SMC-D helper for smc_tx_rdma_writes() */ |
| 360 | static int smcd_tx_rdma_writes(struct smc_connection *conn, size_t len, |
| 361 | size_t src_off, size_t src_len, |
| 362 | size_t dst_off, size_t dst_len) |
| 363 | { |
| 364 | int src_len_sum = src_len, dst_len_sum = dst_len; |
| 365 | int srcchunk, dstchunk; |
| 366 | int rc; |
| 367 | |
| 368 | for (dstchunk = 0; dstchunk < 2; dstchunk++) { |
| 369 | for (srcchunk = 0; srcchunk < 2; srcchunk++) { |
| 370 | void *data = conn->sndbuf_desc->cpu_addr + src_off; |
| 371 | |
| 372 | rc = smcd_tx_ism_write(conn, data, src_len, dst_off + |
| 373 | sizeof(struct smcd_cdc_msg), 0); |
| 374 | if (rc) |
| 375 | return rc; |
| 376 | dst_off += src_len; |
| 377 | src_off += src_len; |
| 378 | if (src_off >= conn->sndbuf_desc->len) |
| 379 | src_off -= conn->sndbuf_desc->len; |
| 380 | /* modulo in send ring */ |
| 381 | if (src_len_sum == dst_len) |
| 382 | break; /* either on 1st or 2nd iteration */ |
| 383 | /* prepare next (== 2nd) iteration */ |
| 384 | src_len = dst_len - src_len; /* remainder */ |
| 385 | src_len_sum += src_len; |
| 386 | } |
| 387 | if (dst_len_sum == len) |
| 388 | break; /* either on 1st or 2nd iteration */ |
| 389 | /* prepare next (== 2nd) iteration */ |
| 390 | dst_off = 0; /* modulo offset in RMBE ring buffer */ |
| 391 | dst_len = len - dst_len; /* remainder */ |
| 392 | dst_len_sum += dst_len; |
| 393 | src_len = min_t(int, dst_len, conn->sndbuf_desc->len - src_off); |
| 394 | src_len_sum = src_len; |
| 395 | } |
| 396 | return 0; |
| 397 | } |
| 398 | |
Ursula Braun | e6727f3 | 2017-01-09 16:55:23 +0100 | [diff] [blame] | 399 | /* sndbuf consumer: prepare all necessary (src&dst) chunks of data transmit; |
| 400 | * usable snd_wnd as max transmit |
| 401 | */ |
Ursula Braun | ad6f317 | 2019-02-04 13:44:44 +0100 | [diff] [blame] | 402 | static int smc_tx_rdma_writes(struct smc_connection *conn, |
| 403 | struct smc_rdma_wr *wr_rdma_buf) |
Ursula Braun | e6727f3 | 2017-01-09 16:55:23 +0100 | [diff] [blame] | 404 | { |
Hans Wippel | be244f2 | 2018-06-28 19:05:10 +0200 | [diff] [blame] | 405 | size_t len, src_len, dst_off, dst_len; /* current chunk values */ |
Ursula Braun | e6727f3 | 2017-01-09 16:55:23 +0100 | [diff] [blame] | 406 | union smc_host_cursor sent, prep, prod, cons; |
Ursula Braun | e6727f3 | 2017-01-09 16:55:23 +0100 | [diff] [blame] | 407 | struct smc_cdc_producer_flags *pflags; |
| 408 | int to_send, rmbespace; |
Ursula Braun | e6727f3 | 2017-01-09 16:55:23 +0100 | [diff] [blame] | 409 | int rc; |
| 410 | |
| 411 | /* source: sndbuf */ |
Stefan Raspl | bac6de7 | 2018-07-23 13:53:09 +0200 | [diff] [blame] | 412 | smc_curs_copy(&sent, &conn->tx_curs_sent, conn); |
| 413 | smc_curs_copy(&prep, &conn->tx_curs_prep, conn); |
Ursula Braun | e6727f3 | 2017-01-09 16:55:23 +0100 | [diff] [blame] | 414 | /* cf. wmem_alloc - (snd_max - snd_una) */ |
| 415 | to_send = smc_curs_diff(conn->sndbuf_desc->len, &sent, &prep); |
| 416 | if (to_send <= 0) |
| 417 | return 0; |
| 418 | |
| 419 | /* destination: RMBE */ |
| 420 | /* cf. snd_wnd */ |
| 421 | rmbespace = atomic_read(&conn->peer_rmbe_space); |
| 422 | if (rmbespace <= 0) |
| 423 | return 0; |
Stefan Raspl | bac6de7 | 2018-07-23 13:53:09 +0200 | [diff] [blame] | 424 | smc_curs_copy(&prod, &conn->local_tx_ctrl.prod, conn); |
| 425 | smc_curs_copy(&cons, &conn->local_rx_ctrl.cons, conn); |
Ursula Braun | e6727f3 | 2017-01-09 16:55:23 +0100 | [diff] [blame] | 426 | |
| 427 | /* if usable snd_wnd closes ask peer to advertise once it opens again */ |
| 428 | pflags = &conn->local_tx_ctrl.prod_flags; |
| 429 | pflags->write_blocked = (to_send >= rmbespace); |
| 430 | /* cf. usable snd_wnd */ |
| 431 | len = min(to_send, rmbespace); |
| 432 | |
| 433 | /* initialize variables for first iteration of subsequent nested loop */ |
Ursula Braun | e6727f3 | 2017-01-09 16:55:23 +0100 | [diff] [blame] | 434 | dst_off = prod.count; |
| 435 | if (prod.wrap == cons.wrap) { |
| 436 | /* the filled destination area is unwrapped, |
| 437 | * hence the available free destination space is wrapped |
| 438 | * and we need 2 destination chunks of sum len; start with 1st |
| 439 | * which is limited by what's available in sndbuf |
| 440 | */ |
| 441 | dst_len = min_t(size_t, |
| 442 | conn->peer_rmbe_size - prod.count, len); |
| 443 | } else { |
| 444 | /* the filled destination area is wrapped, |
| 445 | * hence the available free destination space is unwrapped |
| 446 | * and we need a single destination chunk of entire len |
| 447 | */ |
| 448 | dst_len = len; |
| 449 | } |
Ursula Braun | e6727f3 | 2017-01-09 16:55:23 +0100 | [diff] [blame] | 450 | /* dst_len determines the maximum src_len */ |
| 451 | if (sent.count + dst_len <= conn->sndbuf_desc->len) { |
| 452 | /* unwrapped src case: single chunk of entire dst_len */ |
| 453 | src_len = dst_len; |
| 454 | } else { |
| 455 | /* wrapped src case: 2 chunks of sum dst_len; start with 1st: */ |
| 456 | src_len = conn->sndbuf_desc->len - sent.count; |
| 457 | } |
Hans Wippel | be244f2 | 2018-06-28 19:05:10 +0200 | [diff] [blame] | 458 | |
| 459 | if (conn->lgr->is_smcd) |
| 460 | rc = smcd_tx_rdma_writes(conn, len, sent.count, src_len, |
| 461 | dst_off, dst_len); |
| 462 | else |
| 463 | rc = smcr_tx_rdma_writes(conn, len, sent.count, src_len, |
Ursula Braun | ad6f317 | 2019-02-04 13:44:44 +0100 | [diff] [blame] | 464 | dst_off, dst_len, wr_rdma_buf); |
Hans Wippel | be244f2 | 2018-06-28 19:05:10 +0200 | [diff] [blame] | 465 | if (rc) |
| 466 | return rc; |
Ursula Braun | e6727f3 | 2017-01-09 16:55:23 +0100 | [diff] [blame] | 467 | |
Stefan Raspl | de8474e | 2018-05-23 16:38:11 +0200 | [diff] [blame] | 468 | if (conn->urg_tx_pend && len == to_send) |
| 469 | pflags->urg_data_present = 1; |
Ursula Braun | e6727f3 | 2017-01-09 16:55:23 +0100 | [diff] [blame] | 470 | smc_tx_advance_cursors(conn, &prod, &sent, len); |
| 471 | /* update connection's cursors with advanced local cursors */ |
Stefan Raspl | bac6de7 | 2018-07-23 13:53:09 +0200 | [diff] [blame] | 472 | smc_curs_copy(&conn->local_tx_ctrl.prod, &prod, conn); |
Ursula Braun | e6727f3 | 2017-01-09 16:55:23 +0100 | [diff] [blame] | 473 | /* dst: peer RMBE */ |
Stefan Raspl | bac6de7 | 2018-07-23 13:53:09 +0200 | [diff] [blame] | 474 | smc_curs_copy(&conn->tx_curs_sent, &sent, conn);/* src: local sndbuf */ |
Ursula Braun | e6727f3 | 2017-01-09 16:55:23 +0100 | [diff] [blame] | 475 | |
| 476 | return 0; |
| 477 | } |
| 478 | |
| 479 | /* Wakeup sndbuf consumers from any context (IRQ or process) |
| 480 | * since there is more data to transmit; usable snd_wnd as max transmit |
| 481 | */ |
Hans Wippel | be244f2 | 2018-06-28 19:05:10 +0200 | [diff] [blame] | 482 | static int smcr_tx_sndbuf_nonempty(struct smc_connection *conn) |
Ursula Braun | e6727f3 | 2017-01-09 16:55:23 +0100 | [diff] [blame] | 483 | { |
Ursula Braun | cecc7a3 | 2019-02-21 13:00:58 +0100 | [diff] [blame] | 484 | struct smc_cdc_producer_flags *pflags = &conn->local_tx_ctrl.prod_flags; |
Karsten Graul | c6f02eb | 2020-05-04 14:18:38 +0200 | [diff] [blame] | 485 | struct smc_link *link = conn->lnk; |
Ursula Braun | ad6f317 | 2019-02-04 13:44:44 +0100 | [diff] [blame] | 486 | struct smc_rdma_wr *wr_rdma_buf; |
Ursula Braun | e6727f3 | 2017-01-09 16:55:23 +0100 | [diff] [blame] | 487 | struct smc_cdc_tx_pend *pend; |
| 488 | struct smc_wr_buf *wr_buf; |
| 489 | int rc; |
| 490 | |
Karsten Graul | c6f02eb | 2020-05-04 14:18:38 +0200 | [diff] [blame] | 491 | rc = smc_cdc_get_free_slot(conn, link, &wr_buf, &wr_rdma_buf, &pend); |
Ursula Braun | e6727f3 | 2017-01-09 16:55:23 +0100 | [diff] [blame] | 492 | if (rc < 0) { |
| 493 | if (rc == -EBUSY) { |
Ursula Braun | b38d732 | 2017-01-09 16:55:25 +0100 | [diff] [blame] | 494 | struct smc_sock *smc = |
| 495 | container_of(conn, struct smc_sock, conn); |
| 496 | |
Karsten Graul | 33f3fcc | 2019-01-30 18:51:05 +0100 | [diff] [blame] | 497 | if (smc->sk.sk_err == ECONNABORTED) |
| 498 | return sock_error(&smc->sk); |
Ursula Braun | b290098 | 2019-10-21 16:13:08 +0200 | [diff] [blame] | 499 | if (conn->killed) |
| 500 | return -EPIPE; |
Ursula Braun | e6727f3 | 2017-01-09 16:55:23 +0100 | [diff] [blame] | 501 | rc = 0; |
Ursula Braun | b290098 | 2019-10-21 16:13:08 +0200 | [diff] [blame] | 502 | mod_delayed_work(system_wq, &conn->tx_work, |
| 503 | SMC_TX_WORK_DELAY); |
Ursula Braun | e6727f3 | 2017-01-09 16:55:23 +0100 | [diff] [blame] | 504 | } |
Karsten Graul | 33f3fcc | 2019-01-30 18:51:05 +0100 | [diff] [blame] | 505 | return rc; |
Ursula Braun | e6727f3 | 2017-01-09 16:55:23 +0100 | [diff] [blame] | 506 | } |
| 507 | |
Karsten Graul | 33f3fcc | 2019-01-30 18:51:05 +0100 | [diff] [blame] | 508 | spin_lock_bh(&conn->send_lock); |
Karsten Graul | c6f02eb | 2020-05-04 14:18:38 +0200 | [diff] [blame] | 509 | if (link != conn->lnk) { |
| 510 | /* link of connection changed, tx_work will restart */ |
| 511 | smc_wr_tx_put_slot(link, |
| 512 | (struct smc_wr_tx_pend_priv *)pend); |
| 513 | rc = -ENOLINK; |
| 514 | goto out_unlock; |
| 515 | } |
Ursula Braun | cecc7a3 | 2019-02-21 13:00:58 +0100 | [diff] [blame] | 516 | if (!pflags->urg_data_present) { |
Ursula Braun | ad6f317 | 2019-02-04 13:44:44 +0100 | [diff] [blame] | 517 | rc = smc_tx_rdma_writes(conn, wr_rdma_buf); |
Stefan Raspl | de8474e | 2018-05-23 16:38:11 +0200 | [diff] [blame] | 518 | if (rc) { |
Karsten Graul | c6f02eb | 2020-05-04 14:18:38 +0200 | [diff] [blame] | 519 | smc_wr_tx_put_slot(link, |
Stefan Raspl | de8474e | 2018-05-23 16:38:11 +0200 | [diff] [blame] | 520 | (struct smc_wr_tx_pend_priv *)pend); |
| 521 | goto out_unlock; |
| 522 | } |
Ursula Braun | e6727f3 | 2017-01-09 16:55:23 +0100 | [diff] [blame] | 523 | } |
| 524 | |
| 525 | rc = smc_cdc_msg_send(conn, wr_buf, pend); |
Stefan Raspl | de8474e | 2018-05-23 16:38:11 +0200 | [diff] [blame] | 526 | if (!rc && pflags->urg_data_present) { |
| 527 | pflags->urg_data_pending = 0; |
| 528 | pflags->urg_data_present = 0; |
| 529 | } |
Ursula Braun | e6727f3 | 2017-01-09 16:55:23 +0100 | [diff] [blame] | 530 | |
| 531 | out_unlock: |
| 532 | spin_unlock_bh(&conn->send_lock); |
| 533 | return rc; |
| 534 | } |
| 535 | |
Hans Wippel | be244f2 | 2018-06-28 19:05:10 +0200 | [diff] [blame] | 536 | static int smcd_tx_sndbuf_nonempty(struct smc_connection *conn) |
| 537 | { |
| 538 | struct smc_cdc_producer_flags *pflags = &conn->local_tx_ctrl.prod_flags; |
| 539 | int rc = 0; |
| 540 | |
| 541 | spin_lock_bh(&conn->send_lock); |
| 542 | if (!pflags->urg_data_present) |
Ursula Braun | ad6f317 | 2019-02-04 13:44:44 +0100 | [diff] [blame] | 543 | rc = smc_tx_rdma_writes(conn, NULL); |
Hans Wippel | be244f2 | 2018-06-28 19:05:10 +0200 | [diff] [blame] | 544 | if (!rc) |
| 545 | rc = smcd_cdc_msg_send(conn); |
| 546 | |
| 547 | if (!rc && pflags->urg_data_present) { |
| 548 | pflags->urg_data_pending = 0; |
| 549 | pflags->urg_data_present = 0; |
| 550 | } |
| 551 | spin_unlock_bh(&conn->send_lock); |
| 552 | return rc; |
| 553 | } |
| 554 | |
| 555 | int smc_tx_sndbuf_nonempty(struct smc_connection *conn) |
| 556 | { |
| 557 | int rc; |
| 558 | |
Ursula Braun | b290098 | 2019-10-21 16:13:08 +0200 | [diff] [blame] | 559 | if (conn->killed || |
| 560 | conn->local_rx_ctrl.conn_state_flags.peer_conn_abort) |
| 561 | return -EPIPE; /* connection being aborted */ |
Hans Wippel | be244f2 | 2018-06-28 19:05:10 +0200 | [diff] [blame] | 562 | if (conn->lgr->is_smcd) |
| 563 | rc = smcd_tx_sndbuf_nonempty(conn); |
| 564 | else |
| 565 | rc = smcr_tx_sndbuf_nonempty(conn); |
| 566 | |
Karsten Graul | 5bc056d | 2019-02-12 16:29:51 +0100 | [diff] [blame] | 567 | if (!rc) { |
| 568 | /* trigger socket release if connection is closing */ |
| 569 | struct smc_sock *smc = container_of(conn, struct smc_sock, |
| 570 | conn); |
| 571 | smc_close_wake_tx_prepared(smc); |
| 572 | } |
Hans Wippel | be244f2 | 2018-06-28 19:05:10 +0200 | [diff] [blame] | 573 | return rc; |
| 574 | } |
| 575 | |
Ursula Braun | e6727f3 | 2017-01-09 16:55:23 +0100 | [diff] [blame] | 576 | /* Wakeup sndbuf consumers from process context |
| 577 | * since there is more data to transmit |
| 578 | */ |
Eric Dumazet | be7f3e5 | 2018-05-17 03:54:21 -0700 | [diff] [blame] | 579 | void smc_tx_work(struct work_struct *work) |
Ursula Braun | e6727f3 | 2017-01-09 16:55:23 +0100 | [diff] [blame] | 580 | { |
Ursula Braun | 18e537c | 2017-09-21 09:16:33 +0200 | [diff] [blame] | 581 | struct smc_connection *conn = container_of(to_delayed_work(work), |
Ursula Braun | e6727f3 | 2017-01-09 16:55:23 +0100 | [diff] [blame] | 582 | struct smc_connection, |
| 583 | tx_work); |
| 584 | struct smc_sock *smc = container_of(conn, struct smc_sock, conn); |
Ursula Braun | 90cacb2 | 2017-04-10 14:57:59 +0200 | [diff] [blame] | 585 | int rc; |
Ursula Braun | e6727f3 | 2017-01-09 16:55:23 +0100 | [diff] [blame] | 586 | |
| 587 | lock_sock(&smc->sk); |
Ursula Braun | b290098 | 2019-10-21 16:13:08 +0200 | [diff] [blame] | 588 | if (smc->sk.sk_err) |
Ursula Braun | 1a0a04c | 2018-01-25 11:15:36 +0100 | [diff] [blame] | 589 | goto out; |
| 590 | |
Ursula Braun | 90cacb2 | 2017-04-10 14:57:59 +0200 | [diff] [blame] | 591 | rc = smc_tx_sndbuf_nonempty(conn); |
| 592 | if (!rc && conn->local_rx_ctrl.prod_flags.write_blocked && |
| 593 | !atomic_read(&conn->bytes_to_rcv)) |
| 594 | conn->local_rx_ctrl.prod_flags.write_blocked = 0; |
Ursula Braun | 1a0a04c | 2018-01-25 11:15:36 +0100 | [diff] [blame] | 595 | |
| 596 | out: |
Ursula Braun | e6727f3 | 2017-01-09 16:55:23 +0100 | [diff] [blame] | 597 | release_sock(&smc->sk); |
| 598 | } |
| 599 | |
Stefan Raspl | de8474e | 2018-05-23 16:38:11 +0200 | [diff] [blame] | 600 | void smc_tx_consumer_update(struct smc_connection *conn, bool force) |
Ursula Braun | 952310c | 2017-01-09 16:55:24 +0100 | [diff] [blame] | 601 | { |
Ursula Braun | 99be51f | 2018-07-18 15:22:49 +0200 | [diff] [blame] | 602 | union smc_host_cursor cfed, cons, prod; |
| 603 | int sender_free = conn->rmb_desc->len; |
Ursula Braun | 6b5771a | 2017-12-07 13:38:48 +0100 | [diff] [blame] | 604 | int to_confirm; |
Ursula Braun | 952310c | 2017-01-09 16:55:24 +0100 | [diff] [blame] | 605 | |
Stefan Raspl | bac6de7 | 2018-07-23 13:53:09 +0200 | [diff] [blame] | 606 | smc_curs_copy(&cons, &conn->local_tx_ctrl.cons, conn); |
| 607 | smc_curs_copy(&cfed, &conn->rx_curs_confirmed, conn); |
Hans Wippel | 69cb7dc | 2018-05-18 09:34:10 +0200 | [diff] [blame] | 608 | to_confirm = smc_curs_diff(conn->rmb_desc->len, &cfed, &cons); |
Ursula Braun | 99be51f | 2018-07-18 15:22:49 +0200 | [diff] [blame] | 609 | if (to_confirm > conn->rmbe_update_limit) { |
Stefan Raspl | bac6de7 | 2018-07-23 13:53:09 +0200 | [diff] [blame] | 610 | smc_curs_copy(&prod, &conn->local_rx_ctrl.prod, conn); |
Ursula Braun | 99be51f | 2018-07-18 15:22:49 +0200 | [diff] [blame] | 611 | sender_free = conn->rmb_desc->len - |
Ursula Braun | b8649ef | 2019-02-04 13:44:45 +0100 | [diff] [blame] | 612 | smc_curs_diff_large(conn->rmb_desc->len, |
| 613 | &cfed, &prod); |
Ursula Braun | 99be51f | 2018-07-18 15:22:49 +0200 | [diff] [blame] | 614 | } |
Ursula Braun | 952310c | 2017-01-09 16:55:24 +0100 | [diff] [blame] | 615 | |
| 616 | if (conn->local_rx_ctrl.prod_flags.cons_curs_upd_req || |
Stefan Raspl | de8474e | 2018-05-23 16:38:11 +0200 | [diff] [blame] | 617 | force || |
Ursula Braun | 952310c | 2017-01-09 16:55:24 +0100 | [diff] [blame] | 618 | ((to_confirm > conn->rmbe_update_limit) && |
Ursula Braun | 99be51f | 2018-07-18 15:22:49 +0200 | [diff] [blame] | 619 | ((sender_free <= (conn->rmb_desc->len / 2)) || |
Ursula Braun | 952310c | 2017-01-09 16:55:24 +0100 | [diff] [blame] | 620 | conn->local_rx_ctrl.prod_flags.write_blocked))) { |
Ursula Braun | b290098 | 2019-10-21 16:13:08 +0200 | [diff] [blame] | 621 | if (conn->killed || |
| 622 | conn->local_rx_ctrl.conn_state_flags.peer_conn_abort) |
| 623 | return; |
Ursula Braun | 1a0a04c | 2018-01-25 11:15:36 +0100 | [diff] [blame] | 624 | if ((smc_cdc_get_slot_and_msg_send(conn) < 0) && |
Ursula Braun | b290098 | 2019-10-21 16:13:08 +0200 | [diff] [blame] | 625 | !conn->killed) { |
Ursula Braun | 18e537c | 2017-09-21 09:16:33 +0200 | [diff] [blame] | 626 | schedule_delayed_work(&conn->tx_work, |
| 627 | SMC_TX_WORK_DELAY); |
Ursula Braun | 952310c | 2017-01-09 16:55:24 +0100 | [diff] [blame] | 628 | return; |
| 629 | } |
Ursula Braun | 952310c | 2017-01-09 16:55:24 +0100 | [diff] [blame] | 630 | } |
| 631 | if (conn->local_rx_ctrl.prod_flags.write_blocked && |
| 632 | !atomic_read(&conn->bytes_to_rcv)) |
| 633 | conn->local_rx_ctrl.prod_flags.write_blocked = 0; |
| 634 | } |
| 635 | |
Ursula Braun | e6727f3 | 2017-01-09 16:55:23 +0100 | [diff] [blame] | 636 | /***************************** send initialize *******************************/ |
| 637 | |
| 638 | /* Initialize send properties on connection establishment. NB: not __init! */ |
| 639 | void smc_tx_init(struct smc_sock *smc) |
| 640 | { |
| 641 | smc->sk.sk_write_space = smc_tx_write_space; |
Ursula Braun | e6727f3 | 2017-01-09 16:55:23 +0100 | [diff] [blame] | 642 | } |