Lines Matching +full:burst +full:- +full:wrap
1 // SPDX-License-Identifier: GPL-2.0
3 * Shared Memory Communications over RDMA (SMC-R) and RoCE
43 struct socket *sock = sk->sk_socket; in smc_tx_write_space()
48 if (atomic_read(&smc->conn.sndbuf_space) && sock) { in smc_tx_write_space()
49 if (test_bit(SOCK_NOSPACE, &sock->flags)) in smc_tx_write_space()
50 SMC_STAT_RMB_TX_FULL(smc, !smc->conn.lnk); in smc_tx_write_space()
51 clear_bit(SOCK_NOSPACE, &sock->flags); in smc_tx_write_space()
53 wq = rcu_dereference(sk->sk_wq); in smc_tx_write_space()
55 wake_up_interruptible_poll(&wq->wait, in smc_tx_write_space()
58 if (wq && wq->fasync_list && !(sk->sk_shutdown & SEND_SHUTDOWN)) in smc_tx_write_space()
69 if (smc->sk.sk_socket && in smc_tx_sndbuf_nonfull()
70 test_bit(SOCK_NOSPACE, &smc->sk.sk_socket->flags)) in smc_tx_sndbuf_nonfull()
71 smc->sk.sk_write_space(&smc->sk); in smc_tx_sndbuf_nonfull()
80 struct smc_connection *conn = &smc->conn; in smc_tx_wait()
81 struct sock *sk = &smc->sk; in smc_tx_wait()
90 if (sk->sk_err || in smc_tx_wait()
91 (sk->sk_shutdown & SEND_SHUTDOWN) || in smc_tx_wait()
92 conn->killed || in smc_tx_wait()
93 conn->local_tx_ctrl.conn_state_flags.peer_done_writing) { in smc_tx_wait()
94 rc = -EPIPE; in smc_tx_wait()
98 rc = -ECONNRESET; in smc_tx_wait()
103 set_bit(SOCK_NOSPACE, &sk->sk_socket->flags); in smc_tx_wait()
104 rc = -EAGAIN; in smc_tx_wait()
112 if (atomic_read(&conn->sndbuf_space) && !conn->urg_tx_pend) in smc_tx_wait()
114 set_bit(SOCK_NOSPACE, &sk->sk_socket->flags); in smc_tx_wait()
116 READ_ONCE(sk->sk_err) || in smc_tx_wait()
117 (READ_ONCE(sk->sk_shutdown) & SEND_SHUTDOWN) || in smc_tx_wait()
119 (atomic_read(&conn->sndbuf_space) && in smc_tx_wait()
120 !conn->urg_tx_pend), in smc_tx_wait()
129 struct tcp_sock *tp = tcp_sk(smc->clcsock->sk); in smc_tx_is_corked()
131 return (tp->nonagle & TCP_NAGLE_CORK) ? true : false; in smc_tx_is_corked()
142 * 3. Don't cork to much data in a single RDMA Write to prevent burst
147 struct smc_connection *conn = &smc->conn; in smc_should_autocork()
150 corking_size = min_t(unsigned int, conn->sndbuf_desc->len >> 1, in smc_should_autocork()
151 sock_net(&smc->sk)->smc.sysctl_autocorking_size); in smc_should_autocork()
153 if (atomic_read(&conn->cdc_pend_tx_wr) == 0 || in smc_should_autocork()
161 struct smc_connection *conn = &smc->conn; in smc_tx_should_cork()
170 if ((msg->msg_flags & MSG_MORE || in smc_tx_should_cork()
172 atomic_read(&conn->sndbuf_space)) in smc_tx_should_cork()
185 struct smc_connection *conn = &smc->conn; in smc_tx_sendmsg()
187 struct sock *sk = &smc->sk; in smc_tx_sendmsg()
196 if (sk->sk_err || (sk->sk_shutdown & SEND_SHUTDOWN)) { in smc_tx_sendmsg()
197 rc = -EPIPE; in smc_tx_sendmsg()
201 if (sk->sk_state == SMC_INIT) in smc_tx_sendmsg()
202 return -ENOTCONN; in smc_tx_sendmsg()
204 if (len > conn->sndbuf_desc->len) in smc_tx_sendmsg()
205 SMC_STAT_RMB_TX_SIZE_SMALL(smc, !conn->lnk); in smc_tx_sendmsg()
207 if (len > conn->peer_rmbe_size) in smc_tx_sendmsg()
208 SMC_STAT_RMB_TX_PEER_SIZE_SMALL(smc, !conn->lnk); in smc_tx_sendmsg()
210 if (msg->msg_flags & MSG_OOB) in smc_tx_sendmsg()
214 if (smc->sk.sk_shutdown & SEND_SHUTDOWN || in smc_tx_sendmsg()
215 (smc->sk.sk_err == ECONNABORTED) || in smc_tx_sendmsg()
216 conn->killed) in smc_tx_sendmsg()
217 return -EPIPE; in smc_tx_sendmsg()
219 return send_done ?: -ECONNRESET; in smc_tx_sendmsg()
221 if (msg->msg_flags & MSG_OOB) in smc_tx_sendmsg()
222 conn->local_tx_ctrl.prod_flags.urg_data_pending = 1; in smc_tx_sendmsg()
224 if (!atomic_read(&conn->sndbuf_space) || conn->urg_tx_pend) { in smc_tx_sendmsg()
227 rc = smc_tx_wait(smc, msg->msg_flags); in smc_tx_sendmsg()
235 writespace = atomic_read(&conn->sndbuf_space); in smc_tx_sendmsg()
239 sndbuf_base = conn->sndbuf_desc->cpu_addr; in smc_tx_sendmsg()
240 smc_curs_copy(&prep, &conn->tx_curs_prep, conn); in smc_tx_sendmsg()
244 chunk_len = min_t(size_t, copylen, conn->sndbuf_desc->len - in smc_tx_sendmsg()
258 send_remaining -= chunk_len; in smc_tx_sendmsg()
263 chunk_len = copylen - chunk_len; /* remainder */ in smc_tx_sendmsg()
269 smc_curs_add(conn->sndbuf_desc->len, &prep, copylen); in smc_tx_sendmsg()
270 smc_curs_copy(&conn->tx_curs_prep, &prep, conn); in smc_tx_sendmsg()
273 atomic_sub(copylen, &conn->sndbuf_space); in smc_tx_sendmsg()
274 /* guarantee 0 <= sndbuf_space <= sndbuf_desc->len */ in smc_tx_sendmsg()
279 if ((msg->msg_flags & MSG_OOB) && !send_remaining) in smc_tx_sendmsg()
280 conn->urg_tx_pend = true; in smc_tx_sendmsg()
293 rc = sk_stream_error(sk, msg->msg_flags, rc); in smc_tx_sendmsg()
295 if (unlikely(rc == -EAGAIN)) in smc_tx_sendmsg()
296 sk->sk_write_space(sk); in smc_tx_sendmsg()
308 rc = smc_ism_write(conn->lgr->smcd, conn->peer_token, in smcd_tx_ism_write()
309 conn->peer_rmbe_idx, signal, conn->tx_off + offset, in smcd_tx_ism_write()
312 conn->local_tx_ctrl.conn_state_flags.peer_conn_abort = 1; in smcd_tx_ism_write()
320 struct smc_link_group *lgr = conn->lgr; in smc_tx_rdma_write()
321 struct smc_link *link = conn->lnk; in smc_tx_rdma_write()
324 rdma_wr->wr.wr_id = smc_wr_tx_get_next_wr_id(link); in smc_tx_rdma_write()
325 rdma_wr->wr.num_sge = num_sges; in smc_tx_rdma_write()
326 rdma_wr->remote_addr = in smc_tx_rdma_write()
327 lgr->rtokens[conn->rtoken_idx][link->link_idx].dma_addr + in smc_tx_rdma_write()
329 conn->tx_off + in smc_tx_rdma_write()
332 rdma_wr->rkey = lgr->rtokens[conn->rtoken_idx][link->link_idx].rkey; in smc_tx_rdma_write()
333 rc = ib_post_send(link->roce_qp, &rdma_wr->wr, NULL); in smc_tx_rdma_write()
345 smc_curs_add(conn->peer_rmbe_size, prod, len); in smc_tx_advance_cursors()
349 atomic_sub(len, &conn->peer_rmbe_space); in smc_tx_advance_cursors()
352 smc_curs_add(conn->sndbuf_desc->len, sent, len); in smc_tx_advance_cursors()
355 /* SMC-R helper for smc_tx_rdma_writes() */
361 struct smc_link *link = conn->lnk; in smcr_tx_rdma_writes()
364 sg_dma_address(conn->sndbuf_desc->sgt[link->link_idx].sgl); in smcr_tx_rdma_writes()
365 u64 virt_addr = (uintptr_t)conn->sndbuf_desc->cpu_addr; in smcr_tx_rdma_writes()
373 struct ib_rdma_wr *wr = &wr_rdma_buf->wr_tx_rdma[dstchunk]; in smcr_tx_rdma_writes()
374 struct ib_sge *sge = wr->wr.sg_list; in smcr_tx_rdma_writes()
377 if (dst_len < link->qp_attr.cap.max_inline_data) { in smcr_tx_rdma_writes()
379 wr->wr.send_flags |= IB_SEND_INLINE; in smcr_tx_rdma_writes()
381 wr->wr.send_flags &= ~IB_SEND_INLINE; in smcr_tx_rdma_writes()
386 sge[srcchunk].addr = conn->sndbuf_desc->is_vm ? in smcr_tx_rdma_writes()
389 if (conn->sndbuf_desc->is_vm) in smcr_tx_rdma_writes()
391 conn->sndbuf_desc->mr[link->link_idx]->lkey; in smcr_tx_rdma_writes()
395 if (src_off >= conn->sndbuf_desc->len) in smcr_tx_rdma_writes()
396 src_off -= conn->sndbuf_desc->len; in smcr_tx_rdma_writes()
401 src_len = dst_len - src_len; /* remainder */ in smcr_tx_rdma_writes()
411 dst_len = len - dst_len; /* remainder */ in smcr_tx_rdma_writes()
413 src_len = min_t(int, dst_len, conn->sndbuf_desc->len - in smcr_tx_rdma_writes()
420 /* SMC-D helper for smc_tx_rdma_writes() */
431 void *data = conn->sndbuf_desc->cpu_addr + src_off; in smcd_tx_rdma_writes()
439 if (src_off >= conn->sndbuf_desc->len) in smcd_tx_rdma_writes()
440 src_off -= conn->sndbuf_desc->len; in smcd_tx_rdma_writes()
445 src_len = dst_len - src_len; /* remainder */ in smcd_tx_rdma_writes()
452 dst_len = len - dst_len; /* remainder */ in smcd_tx_rdma_writes()
454 src_len = min_t(int, dst_len, conn->sndbuf_desc->len - src_off); in smcd_tx_rdma_writes()
473 smc_curs_copy(&sent, &conn->tx_curs_sent, conn); in smc_tx_rdma_writes()
474 smc_curs_copy(&prep, &conn->tx_curs_prep, conn); in smc_tx_rdma_writes()
475 /* cf. wmem_alloc - (snd_max - snd_una) */ in smc_tx_rdma_writes()
476 to_send = smc_curs_diff(conn->sndbuf_desc->len, &sent, &prep); in smc_tx_rdma_writes()
482 rmbespace = atomic_read(&conn->peer_rmbe_space); in smc_tx_rdma_writes()
486 SMC_STAT_RMB_TX_PEER_FULL(smc, !conn->lnk); in smc_tx_rdma_writes()
489 smc_curs_copy(&prod, &conn->local_tx_ctrl.prod, conn); in smc_tx_rdma_writes()
490 smc_curs_copy(&cons, &conn->local_rx_ctrl.cons, conn); in smc_tx_rdma_writes()
493 pflags = &conn->local_tx_ctrl.prod_flags; in smc_tx_rdma_writes()
494 pflags->write_blocked = (to_send >= rmbespace); in smc_tx_rdma_writes()
500 if (prod.wrap == cons.wrap) { in smc_tx_rdma_writes()
507 conn->peer_rmbe_size - prod.count, len); in smc_tx_rdma_writes()
516 if (sent.count + dst_len <= conn->sndbuf_desc->len) { in smc_tx_rdma_writes()
521 src_len = conn->sndbuf_desc->len - sent.count; in smc_tx_rdma_writes()
524 if (conn->lgr->is_smcd) in smc_tx_rdma_writes()
533 if (conn->urg_tx_pend && len == to_send) in smc_tx_rdma_writes()
534 pflags->urg_data_present = 1; in smc_tx_rdma_writes()
537 smc_curs_copy(&conn->local_tx_ctrl.prod, &prod, conn); in smc_tx_rdma_writes()
539 smc_curs_copy(&conn->tx_curs_sent, &sent, conn);/* src: local sndbuf */ in smc_tx_rdma_writes()
549 struct smc_cdc_producer_flags *pflags = &conn->local_tx_ctrl.prod_flags; in smcr_tx_sndbuf_nonempty()
550 struct smc_link *link = conn->lnk; in smcr_tx_sndbuf_nonempty()
557 return -ENOLINK; in smcr_tx_sndbuf_nonempty()
561 if (rc == -EBUSY) { in smcr_tx_sndbuf_nonempty()
565 if (smc->sk.sk_err == ECONNABORTED) in smcr_tx_sndbuf_nonempty()
566 return sock_error(&smc->sk); in smcr_tx_sndbuf_nonempty()
567 if (conn->killed) in smcr_tx_sndbuf_nonempty()
568 return -EPIPE; in smcr_tx_sndbuf_nonempty()
570 mod_delayed_work(conn->lgr->tx_wq, &conn->tx_work, in smcr_tx_sndbuf_nonempty()
576 spin_lock_bh(&conn->send_lock); in smcr_tx_sndbuf_nonempty()
577 if (link != conn->lnk) { in smcr_tx_sndbuf_nonempty()
581 rc = -ENOLINK; in smcr_tx_sndbuf_nonempty()
584 if (!pflags->urg_data_present) { in smcr_tx_sndbuf_nonempty()
594 if (!rc && pflags->urg_data_present) { in smcr_tx_sndbuf_nonempty()
595 pflags->urg_data_pending = 0; in smcr_tx_sndbuf_nonempty()
596 pflags->urg_data_present = 0; in smcr_tx_sndbuf_nonempty()
600 spin_unlock_bh(&conn->send_lock); in smcr_tx_sndbuf_nonempty()
607 struct smc_cdc_producer_flags *pflags = &conn->local_tx_ctrl.prod_flags; in smcd_tx_sndbuf_nonempty()
610 spin_lock_bh(&conn->send_lock); in smcd_tx_sndbuf_nonempty()
611 if (!pflags->urg_data_present) in smcd_tx_sndbuf_nonempty()
616 if (!rc && pflags->urg_data_present) { in smcd_tx_sndbuf_nonempty()
617 pflags->urg_data_pending = 0; in smcd_tx_sndbuf_nonempty()
618 pflags->urg_data_present = 0; in smcd_tx_sndbuf_nonempty()
620 spin_unlock_bh(&conn->send_lock); in smcd_tx_sndbuf_nonempty()
634 if (unlikely(atomic_read(&conn->peer_rmbe_space) <= 0)) { in smc_tx_sndbuf_nonempty()
635 SMC_STAT_RMB_TX_PEER_FULL(smc, !conn->lnk); in smc_tx_sndbuf_nonempty()
639 if (conn->killed || in smc_tx_sndbuf_nonempty()
640 conn->local_rx_ctrl.conn_state_flags.peer_conn_abort) { in smc_tx_sndbuf_nonempty()
641 rc = -EPIPE; /* connection being aborted */ in smc_tx_sndbuf_nonempty()
644 if (conn->lgr->is_smcd) in smc_tx_sndbuf_nonempty()
667 if (smc->sk.sk_err) in smc_tx_pending()
671 if (!rc && conn->local_rx_ctrl.prod_flags.write_blocked && in smc_tx_pending()
672 !atomic_read(&conn->bytes_to_rcv)) in smc_tx_pending()
673 conn->local_rx_ctrl.prod_flags.write_blocked = 0; in smc_tx_pending()
687 lock_sock(&smc->sk); in smc_tx_work()
689 release_sock(&smc->sk); in smc_tx_work()
695 int sender_free = conn->rmb_desc->len; in smc_tx_consumer_update()
698 smc_curs_copy(&cons, &conn->local_tx_ctrl.cons, conn); in smc_tx_consumer_update()
699 smc_curs_copy(&cfed, &conn->rx_curs_confirmed, conn); in smc_tx_consumer_update()
700 to_confirm = smc_curs_diff(conn->rmb_desc->len, &cfed, &cons); in smc_tx_consumer_update()
701 if (to_confirm > conn->rmbe_update_limit) { in smc_tx_consumer_update()
702 smc_curs_copy(&prod, &conn->local_rx_ctrl.prod, conn); in smc_tx_consumer_update()
703 sender_free = conn->rmb_desc->len - in smc_tx_consumer_update()
704 smc_curs_diff_large(conn->rmb_desc->len, in smc_tx_consumer_update()
708 if (conn->local_rx_ctrl.prod_flags.cons_curs_upd_req || in smc_tx_consumer_update()
710 ((to_confirm > conn->rmbe_update_limit) && in smc_tx_consumer_update()
711 ((sender_free <= (conn->rmb_desc->len / 2)) || in smc_tx_consumer_update()
712 conn->local_rx_ctrl.prod_flags.write_blocked))) { in smc_tx_consumer_update()
713 if (conn->killed || in smc_tx_consumer_update()
714 conn->local_rx_ctrl.conn_state_flags.peer_conn_abort) in smc_tx_consumer_update()
717 !conn->killed) { in smc_tx_consumer_update()
718 queue_delayed_work(conn->lgr->tx_wq, &conn->tx_work, in smc_tx_consumer_update()
723 if (conn->local_rx_ctrl.prod_flags.write_blocked && in smc_tx_consumer_update()
724 !atomic_read(&conn->bytes_to_rcv)) in smc_tx_consumer_update()
725 conn->local_rx_ctrl.prod_flags.write_blocked = 0; in smc_tx_consumer_update()
733 smc->sk.sk_write_space = smc_tx_write_space; in smc_tx_init()