Lines Matching +full:wr +full:- +full:active
1 // SPDX-License-Identifier: GPL-2.0
3 * Shared Memory Communications over RDMA (SMC-R) and RoCE
5 * Socket Closing - normal and abnormal
28 if (smc->listen_smc && current_work() != &smc->smc_listen_work) in smc_clcsock_release()
29 cancel_work_sync(&smc->smc_listen_work); in smc_clcsock_release()
30 mutex_lock(&smc->clcsock_release_lock); in smc_clcsock_release()
31 if (smc->clcsock) { in smc_clcsock_release()
32 tcp = smc->clcsock; in smc_clcsock_release()
33 smc->clcsock = NULL; in smc_clcsock_release()
36 mutex_unlock(&smc->clcsock_release_lock); in smc_clcsock_release()
43 /* Close non-accepted connections */ in smc_close_cleanup_listen()
52 struct sock *sk = &smc->sk; in smc_close_stream_wait()
57 if (!smc_tx_prepared_sends(&smc->conn)) in smc_close_stream_wait()
61 smc_tx_pending(&smc->conn); in smc_close_stream_wait()
63 smc->wait_close_tx_prepared = 1; in smc_close_stream_wait()
69 !smc_tx_prepared_sends(&smc->conn) || in smc_close_stream_wait()
70 READ_ONCE(sk->sk_err) == ECONNABORTED || in smc_close_stream_wait()
71 READ_ONCE(sk->sk_err) == ECONNRESET || in smc_close_stream_wait()
72 smc->conn.killed, in smc_close_stream_wait()
78 smc->wait_close_tx_prepared = 0; in smc_close_stream_wait()
83 if (smc->wait_close_tx_prepared) in smc_close_wake_tx_prepared()
85 smc->sk.sk_state_change(&smc->sk); in smc_close_wake_tx_prepared()
90 conn->local_tx_ctrl.conn_state_flags.peer_done_writing = 1; in smc_close_wr()
97 if (atomic_read(&conn->bytes_to_rcv)) in smc_close_final()
98 conn->local_tx_ctrl.conn_state_flags.peer_conn_abort = 1; in smc_close_final()
100 conn->local_tx_ctrl.conn_state_flags.peer_conn_closed = 1; in smc_close_final()
101 if (conn->killed) in smc_close_final()
102 return -EPIPE; in smc_close_final()
109 conn->local_tx_ctrl.conn_state_flags.peer_conn_abort = 1; in smc_close_abort()
116 struct sock *sk = &smc->sk; in smc_close_cancel_work()
119 if (cancel_work_sync(&smc->conn.close_work)) in smc_close_cancel_work()
121 cancel_delayed_work_sync(&smc->conn.tx_work); in smc_close_cancel_work()
125 /* terminate smc socket abnormally - active abort
130 struct sock *sk = &smc->sk; in smc_close_active_abort()
133 if (sk->sk_state != SMC_INIT && smc->clcsock && smc->clcsock->sk) { in smc_close_active_abort()
134 sk->sk_err = ECONNABORTED; in smc_close_active_abort()
135 if (smc->clcsock && smc->clcsock->sk) in smc_close_active_abort()
136 tcp_abort(smc->clcsock->sk, ECONNABORTED); in smc_close_active_abort()
138 switch (sk->sk_state) { in smc_close_active_abort()
142 sk->sk_state = SMC_PEERABORTWAIT; in smc_close_active_abort()
144 if (sk->sk_state != SMC_PEERABORTWAIT) in smc_close_active_abort()
146 sk->sk_state = SMC_CLOSED; in smc_close_active_abort()
152 sk->sk_state = SMC_PEERABORTWAIT; in smc_close_active_abort()
154 if (sk->sk_state != SMC_PEERABORTWAIT) in smc_close_active_abort()
156 sk->sk_state = SMC_CLOSED; in smc_close_active_abort()
157 smc_conn_free(&smc->conn); in smc_close_active_abort()
163 sk->sk_state = SMC_PEERABORTWAIT; in smc_close_active_abort()
165 if (sk->sk_state != SMC_PEERABORTWAIT) in smc_close_active_abort()
167 sk->sk_state = SMC_CLOSED; in smc_close_active_abort()
168 smc_conn_free(&smc->conn); in smc_close_active_abort()
178 sk->sk_state_change(sk); in smc_close_active_abort()
189 return conn->local_tx_ctrl.conn_state_flags.peer_conn_abort || in smc_close_sent_any_close()
190 conn->local_tx_ctrl.conn_state_flags.peer_conn_closed; in smc_close_sent_any_close()
196 &smc->conn.local_tx_ctrl.conn_state_flags; in smc_close_active()
197 struct smc_connection *conn = &smc->conn; in smc_close_active()
198 struct sock *sk = &smc->sk; in smc_close_active()
204 timeout = current->flags & PF_EXITING ? in smc_close_active()
206 sk->sk_lingertime : SMC_MAX_STREAM_WAIT_TIMEOUT; in smc_close_active()
208 old_state = sk->sk_state; in smc_close_active()
210 switch (sk->sk_state) { in smc_close_active()
212 sk->sk_state = SMC_CLOSED; in smc_close_active()
215 sk->sk_state = SMC_CLOSED; in smc_close_active()
216 sk->sk_state_change(sk); /* wake up accept */ in smc_close_active()
217 if (smc->clcsock && smc->clcsock->sk) { in smc_close_active()
218 write_lock_bh(&smc->clcsock->sk->sk_callback_lock); in smc_close_active()
219 smc_clcsock_restore_cb(&smc->clcsock->sk->sk_data_ready, in smc_close_active()
220 &smc->clcsk_data_ready); in smc_close_active()
221 smc->clcsock->sk->sk_user_data = NULL; in smc_close_active()
222 write_unlock_bh(&smc->clcsock->sk->sk_callback_lock); in smc_close_active()
223 rc = kernel_sock_shutdown(smc->clcsock, SHUT_RDWR); in smc_close_active()
227 flush_work(&smc->tcp_listen_work); in smc_close_active()
233 cancel_delayed_work_sync(&conn->tx_work); in smc_close_active()
235 if (sk->sk_state == SMC_ACTIVE) { in smc_close_active()
238 sk->sk_state = SMC_PEERCLOSEWAIT1; in smc_close_active()
243 if (smc->clcsock && smc->clcsock->sk) { in smc_close_active()
244 rc1 = kernel_sock_shutdown(smc->clcsock, in smc_close_active()
254 /* socket already shutdown wr or both (active close) */ in smc_close_active()
255 if (txflags->peer_done_writing && in smc_close_active()
257 /* just shutdown wr done, send close request */ in smc_close_active()
260 sk->sk_state = SMC_CLOSED; in smc_close_active()
267 cancel_delayed_work_sync(&conn->tx_work); in smc_close_active()
269 if (sk->sk_state != SMC_APPCLOSEWAIT1 && in smc_close_active()
270 sk->sk_state != SMC_APPCLOSEWAIT2) in smc_close_active()
276 sk->sk_state = SMC_CLOSED; in smc_close_active()
280 sk->sk_state = SMC_PEERFINCLOSEWAIT; in smc_close_active()
285 if (txflags->peer_done_writing && in smc_close_active()
287 /* just shutdown wr done, send close request */ in smc_close_active()
297 sk->sk_state = SMC_CLOSED; in smc_close_active()
300 sk->sk_state = SMC_CLOSED; in smc_close_active()
307 if (old_state != sk->sk_state) in smc_close_active()
308 sk->sk_state_change(sk); in smc_close_active()
315 &smc->conn.local_tx_ctrl.conn_state_flags; in smc_close_passive_abort_received()
316 struct sock *sk = &smc->sk; in smc_close_passive_abort_received()
318 switch (sk->sk_state) { in smc_close_passive_abort_received()
322 sk->sk_state = SMC_PROCESSABORT; in smc_close_passive_abort_received()
326 sk->sk_state = SMC_PROCESSABORT; in smc_close_passive_abort_received()
330 if (txflags->peer_done_writing && in smc_close_passive_abort_received()
331 !smc_close_sent_any_close(&smc->conn)) in smc_close_passive_abort_received()
333 sk->sk_state = SMC_PROCESSABORT; in smc_close_passive_abort_received()
335 sk->sk_state = SMC_CLOSED; in smc_close_passive_abort_received()
340 sk->sk_state = SMC_CLOSED; in smc_close_passive_abort_received()
344 sk->sk_state = SMC_CLOSED; in smc_close_passive_abort_received()
364 struct sock *sk = &smc->sk; in smc_close_passive_work()
368 old_state = sk->sk_state; in smc_close_passive_work()
370 rxflags = &conn->local_rx_ctrl.conn_state_flags; in smc_close_passive_work()
371 if (rxflags->peer_conn_abort) { in smc_close_passive_work()
375 cancel_delayed_work_sync(&conn->tx_work); in smc_close_passive_work()
380 switch (sk->sk_state) { in smc_close_passive_work()
382 sk->sk_state = SMC_APPCLOSEWAIT1; in smc_close_passive_work()
385 sk->sk_state = SMC_APPCLOSEWAIT1; in smc_close_passive_work()
391 if (rxflags->peer_done_writing) in smc_close_passive_work()
392 sk->sk_state = SMC_PEERCLOSEWAIT2; in smc_close_passive_work()
401 sk->sk_state = SMC_CLOSED; in smc_close_passive_work()
404 sk->sk_state = SMC_APPFINCLOSEWAIT; in smc_close_passive_work()
410 sk->sk_state = SMC_CLOSED; in smc_close_passive_work()
429 sk->sk_data_ready(sk); /* wakeup blocked rcvbuf consumers */ in smc_close_passive_work()
430 sk->sk_write_space(sk); /* wakeup blocked sndbuf producers */ in smc_close_passive_work()
432 if (old_state != sk->sk_state) { in smc_close_passive_work()
433 sk->sk_state_change(sk); in smc_close_passive_work()
434 if ((sk->sk_state == SMC_CLOSED) && in smc_close_passive_work()
435 (sock_flag(sk, SOCK_DEAD) || !sk->sk_socket)) { in smc_close_passive_work()
437 if (smc->clcsock) in smc_close_passive_work()
449 struct smc_connection *conn = &smc->conn; in smc_close_shutdown_write()
450 struct sock *sk = &smc->sk; in smc_close_shutdown_write()
455 timeout = current->flags & PF_EXITING ? in smc_close_shutdown_write()
457 sk->sk_lingertime : SMC_MAX_STREAM_WAIT_TIMEOUT; in smc_close_shutdown_write()
459 old_state = sk->sk_state; in smc_close_shutdown_write()
461 switch (sk->sk_state) { in smc_close_shutdown_write()
465 cancel_delayed_work_sync(&conn->tx_work); in smc_close_shutdown_write()
467 if (sk->sk_state != SMC_ACTIVE) in smc_close_shutdown_write()
469 /* send close wr request */ in smc_close_shutdown_write()
471 sk->sk_state = SMC_PEERCLOSEWAIT1; in smc_close_shutdown_write()
478 cancel_delayed_work_sync(&conn->tx_work); in smc_close_shutdown_write()
480 if (sk->sk_state != SMC_APPCLOSEWAIT1) in smc_close_shutdown_write()
484 sk->sk_state = SMC_APPCLOSEWAIT2; in smc_close_shutdown_write()
497 if (old_state != sk->sk_state) in smc_close_shutdown_write()
498 sk->sk_state_change(sk); in smc_close_shutdown_write()
505 INIT_WORK(&smc->conn.close_work, smc_close_passive_work); in smc_close_init()