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