Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Ursula Braun | 5f08318 | 2017-01-09 16:55:22 +0100 | [diff] [blame] | 2 | /* |
| 3 | * Shared Memory Communications over RDMA (SMC-R) and RoCE |
| 4 | * |
| 5 | * Connection Data Control (CDC) |
| 6 | * handles flow control |
| 7 | * |
| 8 | * Copyright IBM Corp. 2016 |
| 9 | * |
| 10 | * Author(s): Ursula Braun <ubraun@linux.vnet.ibm.com> |
| 11 | */ |
| 12 | |
| 13 | #include <linux/spinlock.h> |
| 14 | |
| 15 | #include "smc.h" |
| 16 | #include "smc_wr.h" |
| 17 | #include "smc_cdc.h" |
Ursula Braun | e6727f3 | 2017-01-09 16:55:23 +0100 | [diff] [blame] | 18 | #include "smc_tx.h" |
Ursula Braun | 952310c | 2017-01-09 16:55:24 +0100 | [diff] [blame] | 19 | #include "smc_rx.h" |
Ursula Braun | b38d732 | 2017-01-09 16:55:25 +0100 | [diff] [blame] | 20 | #include "smc_close.h" |
Ursula Braun | 5f08318 | 2017-01-09 16:55:22 +0100 | [diff] [blame] | 21 | |
| 22 | /********************************** send *************************************/ |
| 23 | |
Ursula Braun | 5f08318 | 2017-01-09 16:55:22 +0100 | [diff] [blame] | 24 | /* handler for send/transmission completion of a CDC msg */ |
| 25 | static void smc_cdc_tx_handler(struct smc_wr_tx_pend_priv *pnd_snd, |
| 26 | struct smc_link *link, |
| 27 | enum ib_wc_status wc_status) |
| 28 | { |
| 29 | struct smc_cdc_tx_pend *cdcpend = (struct smc_cdc_tx_pend *)pnd_snd; |
Stefan Raspl | bac6de7 | 2018-07-23 13:53:09 +0200 | [diff] [blame] | 30 | struct smc_connection *conn = cdcpend->conn; |
Ursula Braun | 5f08318 | 2017-01-09 16:55:22 +0100 | [diff] [blame] | 31 | struct smc_sock *smc; |
| 32 | int diff; |
| 33 | |
Stefan Raspl | bac6de7 | 2018-07-23 13:53:09 +0200 | [diff] [blame] | 34 | if (!conn) |
Ursula Braun | 5f08318 | 2017-01-09 16:55:22 +0100 | [diff] [blame] | 35 | /* already dismissed */ |
| 36 | return; |
| 37 | |
Stefan Raspl | bac6de7 | 2018-07-23 13:53:09 +0200 | [diff] [blame] | 38 | smc = container_of(conn, struct smc_sock, conn); |
Ursula Braun | 5f08318 | 2017-01-09 16:55:22 +0100 | [diff] [blame] | 39 | bh_lock_sock(&smc->sk); |
| 40 | if (!wc_status) { |
Hans Wippel | 69cb7dc | 2018-05-18 09:34:10 +0200 | [diff] [blame] | 41 | diff = smc_curs_diff(cdcpend->conn->sndbuf_desc->len, |
Ursula Braun | 5f08318 | 2017-01-09 16:55:22 +0100 | [diff] [blame] | 42 | &cdcpend->conn->tx_curs_fin, |
| 43 | &cdcpend->cursor); |
| 44 | /* sndbuf_space is decreased in smc_sendmsg */ |
| 45 | smp_mb__before_atomic(); |
| 46 | atomic_add(diff, &cdcpend->conn->sndbuf_space); |
Hans Wippel | 69cb7dc | 2018-05-18 09:34:10 +0200 | [diff] [blame] | 47 | /* guarantee 0 <= sndbuf_space <= sndbuf_desc->len */ |
Ursula Braun | 5f08318 | 2017-01-09 16:55:22 +0100 | [diff] [blame] | 48 | smp_mb__after_atomic(); |
Stefan Raspl | bac6de7 | 2018-07-23 13:53:09 +0200 | [diff] [blame] | 49 | smc_curs_copy(&conn->tx_curs_fin, &cdcpend->cursor, conn); |
Ursula Braun | 5f08318 | 2017-01-09 16:55:22 +0100 | [diff] [blame] | 50 | } |
Ursula Braun | e6727f3 | 2017-01-09 16:55:23 +0100 | [diff] [blame] | 51 | smc_tx_sndbuf_nonfull(smc); |
Ursula Braun | 5f08318 | 2017-01-09 16:55:22 +0100 | [diff] [blame] | 52 | bh_unlock_sock(&smc->sk); |
| 53 | } |
| 54 | |
Ursula Braun | 51957bc | 2017-09-21 09:17:34 +0200 | [diff] [blame] | 55 | int smc_cdc_get_free_slot(struct smc_connection *conn, |
Ursula Braun | 5f08318 | 2017-01-09 16:55:22 +0100 | [diff] [blame] | 56 | struct smc_wr_buf **wr_buf, |
Ursula Braun | ad6f317 | 2019-02-04 13:44:44 +0100 | [diff] [blame] | 57 | struct smc_rdma_wr **wr_rdma_buf, |
Ursula Braun | 5f08318 | 2017-01-09 16:55:22 +0100 | [diff] [blame] | 58 | struct smc_cdc_tx_pend **pend) |
| 59 | { |
Ursula Braun | 51957bc | 2017-09-21 09:17:34 +0200 | [diff] [blame] | 60 | struct smc_link *link = &conn->lgr->lnk[SMC_SINGLE_LINK]; |
Ursula Braun | 1a0a04c | 2018-01-25 11:15:36 +0100 | [diff] [blame] | 61 | int rc; |
Ursula Braun | 51957bc | 2017-09-21 09:17:34 +0200 | [diff] [blame] | 62 | |
Ursula Braun | 1a0a04c | 2018-01-25 11:15:36 +0100 | [diff] [blame] | 63 | rc = smc_wr_tx_get_free_slot(link, smc_cdc_tx_handler, wr_buf, |
Ursula Braun | ad6f317 | 2019-02-04 13:44:44 +0100 | [diff] [blame] | 64 | wr_rdma_buf, |
Ursula Braun | 1a0a04c | 2018-01-25 11:15:36 +0100 | [diff] [blame] | 65 | (struct smc_wr_tx_pend_priv **)pend); |
| 66 | if (!conn->alert_token_local) |
| 67 | /* abnormal termination */ |
| 68 | rc = -EPIPE; |
| 69 | return rc; |
Ursula Braun | 5f08318 | 2017-01-09 16:55:22 +0100 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | static inline void smc_cdc_add_pending_send(struct smc_connection *conn, |
| 73 | struct smc_cdc_tx_pend *pend) |
| 74 | { |
| 75 | BUILD_BUG_ON_MSG( |
| 76 | sizeof(struct smc_cdc_msg) > SMC_WR_BUF_SIZE, |
| 77 | "must increase SMC_WR_BUF_SIZE to at least sizeof(struct smc_cdc_msg)"); |
| 78 | BUILD_BUG_ON_MSG( |
Ursula Braun | b9a22dd | 2018-11-20 16:46:42 +0100 | [diff] [blame] | 79 | offsetofend(struct smc_cdc_msg, reserved) > SMC_WR_TX_SIZE, |
Ursula Braun | 5f08318 | 2017-01-09 16:55:22 +0100 | [diff] [blame] | 80 | "must adapt SMC_WR_TX_SIZE to sizeof(struct smc_cdc_msg); if not all smc_wr upper layer protocols use the same message size any more, must start to set link->wr_tx_sges[i].length on each individual smc_wr_tx_send()"); |
| 81 | BUILD_BUG_ON_MSG( |
| 82 | sizeof(struct smc_cdc_tx_pend) > SMC_WR_TX_PEND_PRIV_SIZE, |
| 83 | "must increase SMC_WR_TX_PEND_PRIV_SIZE to at least sizeof(struct smc_cdc_tx_pend)"); |
| 84 | pend->conn = conn; |
| 85 | pend->cursor = conn->tx_curs_sent; |
| 86 | pend->p_cursor = conn->local_tx_ctrl.prod; |
| 87 | pend->ctrl_seq = conn->tx_cdc_seq; |
| 88 | } |
| 89 | |
| 90 | int smc_cdc_msg_send(struct smc_connection *conn, |
| 91 | struct smc_wr_buf *wr_buf, |
| 92 | struct smc_cdc_tx_pend *pend) |
| 93 | { |
Ursula Braun | b8649ef | 2019-02-04 13:44:45 +0100 | [diff] [blame] | 94 | union smc_host_cursor cfed; |
Ursula Braun | 5f08318 | 2017-01-09 16:55:22 +0100 | [diff] [blame] | 95 | struct smc_link *link; |
| 96 | int rc; |
| 97 | |
| 98 | link = &conn->lgr->lnk[SMC_SINGLE_LINK]; |
| 99 | |
| 100 | smc_cdc_add_pending_send(conn, pend); |
| 101 | |
| 102 | conn->tx_cdc_seq++; |
| 103 | conn->local_tx_ctrl.seqno = conn->tx_cdc_seq; |
| 104 | smc_host_msg_to_cdc((struct smc_cdc_msg *)wr_buf, |
| 105 | &conn->local_tx_ctrl, conn); |
Ursula Braun | b8649ef | 2019-02-04 13:44:45 +0100 | [diff] [blame] | 106 | smc_curs_copy(&cfed, &((struct smc_host_cdc_msg *)wr_buf)->cons, conn); |
Ursula Braun | 5f08318 | 2017-01-09 16:55:22 +0100 | [diff] [blame] | 107 | rc = smc_wr_tx_send(link, (struct smc_wr_tx_pend_priv *)pend); |
Karsten Graul | 4dff63c | 2019-02-12 16:29:50 +0100 | [diff] [blame^] | 108 | if (!rc) { |
Ursula Braun | b8649ef | 2019-02-04 13:44:45 +0100 | [diff] [blame] | 109 | smc_curs_copy(&conn->rx_curs_confirmed, &cfed, conn); |
Karsten Graul | 4dff63c | 2019-02-12 16:29:50 +0100 | [diff] [blame^] | 110 | conn->local_rx_ctrl.prod_flags.cons_curs_upd_req = 0; |
| 111 | } |
Ursula Braun | 5f08318 | 2017-01-09 16:55:22 +0100 | [diff] [blame] | 112 | |
| 113 | return rc; |
| 114 | } |
| 115 | |
Hans Wippel | be244f2 | 2018-06-28 19:05:10 +0200 | [diff] [blame] | 116 | static int smcr_cdc_get_slot_and_msg_send(struct smc_connection *conn) |
Ursula Braun | 5f08318 | 2017-01-09 16:55:22 +0100 | [diff] [blame] | 117 | { |
| 118 | struct smc_cdc_tx_pend *pend; |
| 119 | struct smc_wr_buf *wr_buf; |
| 120 | int rc; |
| 121 | |
Ursula Braun | ad6f317 | 2019-02-04 13:44:44 +0100 | [diff] [blame] | 122 | rc = smc_cdc_get_free_slot(conn, &wr_buf, NULL, &pend); |
Ursula Braun | 5f08318 | 2017-01-09 16:55:22 +0100 | [diff] [blame] | 123 | if (rc) |
| 124 | return rc; |
| 125 | |
Karsten Graul | 2dee25a | 2019-01-30 18:51:06 +0100 | [diff] [blame] | 126 | spin_lock_bh(&conn->send_lock); |
| 127 | rc = smc_cdc_msg_send(conn, wr_buf, pend); |
| 128 | spin_unlock_bh(&conn->send_lock); |
| 129 | return rc; |
Ursula Braun | 5f08318 | 2017-01-09 16:55:22 +0100 | [diff] [blame] | 130 | } |
| 131 | |
Hans Wippel | be244f2 | 2018-06-28 19:05:10 +0200 | [diff] [blame] | 132 | int smc_cdc_get_slot_and_msg_send(struct smc_connection *conn) |
| 133 | { |
| 134 | int rc; |
| 135 | |
| 136 | if (conn->lgr->is_smcd) { |
| 137 | spin_lock_bh(&conn->send_lock); |
| 138 | rc = smcd_cdc_msg_send(conn); |
| 139 | spin_unlock_bh(&conn->send_lock); |
| 140 | } else { |
| 141 | rc = smcr_cdc_get_slot_and_msg_send(conn); |
| 142 | } |
| 143 | |
| 144 | return rc; |
| 145 | } |
| 146 | |
Ursula Braun | 5f08318 | 2017-01-09 16:55:22 +0100 | [diff] [blame] | 147 | static bool smc_cdc_tx_filter(struct smc_wr_tx_pend_priv *tx_pend, |
| 148 | unsigned long data) |
| 149 | { |
| 150 | struct smc_connection *conn = (struct smc_connection *)data; |
| 151 | struct smc_cdc_tx_pend *cdc_pend = |
| 152 | (struct smc_cdc_tx_pend *)tx_pend; |
| 153 | |
| 154 | return cdc_pend->conn == conn; |
| 155 | } |
| 156 | |
| 157 | static void smc_cdc_tx_dismisser(struct smc_wr_tx_pend_priv *tx_pend) |
| 158 | { |
| 159 | struct smc_cdc_tx_pend *cdc_pend = |
| 160 | (struct smc_cdc_tx_pend *)tx_pend; |
| 161 | |
| 162 | cdc_pend->conn = NULL; |
| 163 | } |
| 164 | |
| 165 | void smc_cdc_tx_dismiss_slots(struct smc_connection *conn) |
| 166 | { |
| 167 | struct smc_link *link = &conn->lgr->lnk[SMC_SINGLE_LINK]; |
| 168 | |
| 169 | smc_wr_tx_dismiss_slots(link, SMC_CDC_MSG_TYPE, |
| 170 | smc_cdc_tx_filter, smc_cdc_tx_dismisser, |
| 171 | (unsigned long)conn); |
| 172 | } |
| 173 | |
Hans Wippel | be244f2 | 2018-06-28 19:05:10 +0200 | [diff] [blame] | 174 | /* Send a SMC-D CDC header. |
| 175 | * This increments the free space available in our send buffer. |
| 176 | * Also update the confirmed receive buffer with what was sent to the peer. |
| 177 | */ |
| 178 | int smcd_cdc_msg_send(struct smc_connection *conn) |
| 179 | { |
| 180 | struct smc_sock *smc = container_of(conn, struct smc_sock, conn); |
Ursula Braun | b9a22dd | 2018-11-20 16:46:42 +0100 | [diff] [blame] | 181 | union smc_host_cursor curs; |
Hans Wippel | be244f2 | 2018-06-28 19:05:10 +0200 | [diff] [blame] | 182 | struct smcd_cdc_msg cdc; |
| 183 | int rc, diff; |
| 184 | |
| 185 | memset(&cdc, 0, sizeof(cdc)); |
| 186 | cdc.common.type = SMC_CDC_MSG_TYPE; |
Ursula Braun | b9a22dd | 2018-11-20 16:46:42 +0100 | [diff] [blame] | 187 | curs.acurs.counter = atomic64_read(&conn->local_tx_ctrl.prod.acurs); |
| 188 | cdc.prod.wrap = curs.wrap; |
| 189 | cdc.prod.count = curs.count; |
| 190 | curs.acurs.counter = atomic64_read(&conn->local_tx_ctrl.cons.acurs); |
| 191 | cdc.cons.wrap = curs.wrap; |
| 192 | cdc.cons.count = curs.count; |
| 193 | cdc.cons.prod_flags = conn->local_tx_ctrl.prod_flags; |
| 194 | cdc.cons.conn_state_flags = conn->local_tx_ctrl.conn_state_flags; |
Hans Wippel | be244f2 | 2018-06-28 19:05:10 +0200 | [diff] [blame] | 195 | rc = smcd_tx_ism_write(conn, &cdc, sizeof(cdc), 0, 1); |
| 196 | if (rc) |
| 197 | return rc; |
Ursula Braun | b9a22dd | 2018-11-20 16:46:42 +0100 | [diff] [blame] | 198 | smc_curs_copy(&conn->rx_curs_confirmed, &curs, conn); |
Karsten Graul | 4dff63c | 2019-02-12 16:29:50 +0100 | [diff] [blame^] | 199 | conn->local_rx_ctrl.prod_flags.cons_curs_upd_req = 0; |
Hans Wippel | be244f2 | 2018-06-28 19:05:10 +0200 | [diff] [blame] | 200 | /* Calculate transmitted data and increment free send buffer space */ |
| 201 | diff = smc_curs_diff(conn->sndbuf_desc->len, &conn->tx_curs_fin, |
| 202 | &conn->tx_curs_sent); |
| 203 | /* increased by confirmed number of bytes */ |
| 204 | smp_mb__before_atomic(); |
| 205 | atomic_add(diff, &conn->sndbuf_space); |
| 206 | /* guarantee 0 <= sndbuf_space <= sndbuf_desc->len */ |
| 207 | smp_mb__after_atomic(); |
Stefan Raspl | bac6de7 | 2018-07-23 13:53:09 +0200 | [diff] [blame] | 208 | smc_curs_copy(&conn->tx_curs_fin, &conn->tx_curs_sent, conn); |
Hans Wippel | be244f2 | 2018-06-28 19:05:10 +0200 | [diff] [blame] | 209 | |
| 210 | smc_tx_sndbuf_nonfull(smc); |
| 211 | return rc; |
| 212 | } |
| 213 | |
Ursula Braun | 5f08318 | 2017-01-09 16:55:22 +0100 | [diff] [blame] | 214 | /********************************* receive ***********************************/ |
| 215 | |
| 216 | static inline bool smc_cdc_before(u16 seq1, u16 seq2) |
| 217 | { |
| 218 | return (s16)(seq1 - seq2) < 0; |
| 219 | } |
| 220 | |
Stefan Raspl | de8474e | 2018-05-23 16:38:11 +0200 | [diff] [blame] | 221 | static void smc_cdc_handle_urg_data_arrival(struct smc_sock *smc, |
| 222 | int *diff_prod) |
| 223 | { |
| 224 | struct smc_connection *conn = &smc->conn; |
| 225 | char *base; |
| 226 | |
| 227 | /* new data included urgent business */ |
Stefan Raspl | bac6de7 | 2018-07-23 13:53:09 +0200 | [diff] [blame] | 228 | smc_curs_copy(&conn->urg_curs, &conn->local_rx_ctrl.prod, conn); |
Stefan Raspl | de8474e | 2018-05-23 16:38:11 +0200 | [diff] [blame] | 229 | conn->urg_state = SMC_URG_VALID; |
| 230 | if (!sock_flag(&smc->sk, SOCK_URGINLINE)) |
| 231 | /* we'll skip the urgent byte, so don't account for it */ |
| 232 | (*diff_prod)--; |
Hans Wippel | be244f2 | 2018-06-28 19:05:10 +0200 | [diff] [blame] | 233 | base = (char *)conn->rmb_desc->cpu_addr + conn->rx_off; |
Stefan Raspl | de8474e | 2018-05-23 16:38:11 +0200 | [diff] [blame] | 234 | if (conn->urg_curs.count) |
| 235 | conn->urg_rx_byte = *(base + conn->urg_curs.count - 1); |
| 236 | else |
| 237 | conn->urg_rx_byte = *(base + conn->rmb_desc->len - 1); |
| 238 | sk_send_sigurg(&smc->sk); |
| 239 | } |
| 240 | |
Ursula Braun | 5f08318 | 2017-01-09 16:55:22 +0100 | [diff] [blame] | 241 | static void smc_cdc_msg_recv_action(struct smc_sock *smc, |
Ursula Braun | 5f08318 | 2017-01-09 16:55:22 +0100 | [diff] [blame] | 242 | struct smc_cdc_msg *cdc) |
| 243 | { |
| 244 | union smc_host_cursor cons_old, prod_old; |
| 245 | struct smc_connection *conn = &smc->conn; |
| 246 | int diff_cons, diff_prod; |
| 247 | |
Stefan Raspl | bac6de7 | 2018-07-23 13:53:09 +0200 | [diff] [blame] | 248 | smc_curs_copy(&prod_old, &conn->local_rx_ctrl.prod, conn); |
| 249 | smc_curs_copy(&cons_old, &conn->local_rx_ctrl.cons, conn); |
Ursula Braun | 5f08318 | 2017-01-09 16:55:22 +0100 | [diff] [blame] | 250 | smc_cdc_msg_to_host(&conn->local_rx_ctrl, cdc, conn); |
| 251 | |
| 252 | diff_cons = smc_curs_diff(conn->peer_rmbe_size, &cons_old, |
| 253 | &conn->local_rx_ctrl.cons); |
| 254 | if (diff_cons) { |
| 255 | /* peer_rmbe_space is decreased during data transfer with RDMA |
| 256 | * write |
| 257 | */ |
| 258 | smp_mb__before_atomic(); |
| 259 | atomic_add(diff_cons, &conn->peer_rmbe_space); |
| 260 | /* guarantee 0 <= peer_rmbe_space <= peer_rmbe_size */ |
| 261 | smp_mb__after_atomic(); |
| 262 | } |
| 263 | |
Hans Wippel | 69cb7dc | 2018-05-18 09:34:10 +0200 | [diff] [blame] | 264 | diff_prod = smc_curs_diff(conn->rmb_desc->len, &prod_old, |
Ursula Braun | 5f08318 | 2017-01-09 16:55:22 +0100 | [diff] [blame] | 265 | &conn->local_rx_ctrl.prod); |
| 266 | if (diff_prod) { |
Stefan Raspl | de8474e | 2018-05-23 16:38:11 +0200 | [diff] [blame] | 267 | if (conn->local_rx_ctrl.prod_flags.urg_data_present) |
| 268 | smc_cdc_handle_urg_data_arrival(smc, &diff_prod); |
Ursula Braun | 5f08318 | 2017-01-09 16:55:22 +0100 | [diff] [blame] | 269 | /* bytes_to_rcv is decreased in smc_recvmsg */ |
| 270 | smp_mb__before_atomic(); |
| 271 | atomic_add(diff_prod, &conn->bytes_to_rcv); |
Hans Wippel | 69cb7dc | 2018-05-18 09:34:10 +0200 | [diff] [blame] | 272 | /* guarantee 0 <= bytes_to_rcv <= rmb_desc->len */ |
Ursula Braun | 5f08318 | 2017-01-09 16:55:22 +0100 | [diff] [blame] | 273 | smp_mb__after_atomic(); |
Ursula Braun | 952310c | 2017-01-09 16:55:24 +0100 | [diff] [blame] | 274 | smc->sk.sk_data_ready(&smc->sk); |
Stefan Raspl | de8474e | 2018-05-23 16:38:11 +0200 | [diff] [blame] | 275 | } else { |
| 276 | if (conn->local_rx_ctrl.prod_flags.write_blocked || |
| 277 | conn->local_rx_ctrl.prod_flags.cons_curs_upd_req || |
| 278 | conn->local_rx_ctrl.prod_flags.urg_data_pending) { |
| 279 | if (conn->local_rx_ctrl.prod_flags.urg_data_pending) |
| 280 | conn->urg_state = SMC_URG_NOTYET; |
| 281 | /* force immediate tx of current consumer cursor, but |
| 282 | * under send_lock to guarantee arrival in seqno-order |
| 283 | */ |
Ursula Braun | 5607016 | 2018-08-03 10:38:33 +0200 | [diff] [blame] | 284 | if (smc->sk.sk_state != SMC_INIT) |
| 285 | smc_tx_sndbuf_nonempty(conn); |
Stefan Raspl | de8474e | 2018-05-23 16:38:11 +0200 | [diff] [blame] | 286 | } |
Ursula Braun | 5f08318 | 2017-01-09 16:55:22 +0100 | [diff] [blame] | 287 | } |
| 288 | |
Ursula Braun | 51f1de7 | 2018-01-26 09:28:48 +0100 | [diff] [blame] | 289 | /* piggy backed tx info */ |
| 290 | /* trigger sndbuf consumer: RDMA write into peer RMBE and CDC */ |
| 291 | if (diff_cons && smc_tx_prepared_sends(conn)) { |
| 292 | smc_tx_sndbuf_nonempty(conn); |
| 293 | /* trigger socket release if connection closed */ |
| 294 | smc_close_wake_tx_prepared(smc); |
| 295 | } |
Stefan Raspl | de8474e | 2018-05-23 16:38:11 +0200 | [diff] [blame] | 296 | if (diff_cons && conn->urg_tx_pend && |
| 297 | atomic_read(&conn->peer_rmbe_space) == conn->peer_rmbe_size) { |
| 298 | /* urg data confirmed by peer, indicate we're ready for more */ |
| 299 | conn->urg_tx_pend = false; |
| 300 | smc->sk.sk_write_space(&smc->sk); |
| 301 | } |
Ursula Braun | 51f1de7 | 2018-01-26 09:28:48 +0100 | [diff] [blame] | 302 | |
Ursula Braun | b38d732 | 2017-01-09 16:55:25 +0100 | [diff] [blame] | 303 | if (conn->local_rx_ctrl.conn_state_flags.peer_conn_abort) { |
Ursula Braun | 5f08318 | 2017-01-09 16:55:22 +0100 | [diff] [blame] | 304 | smc->sk.sk_err = ECONNRESET; |
Ursula Braun | b38d732 | 2017-01-09 16:55:25 +0100 | [diff] [blame] | 305 | conn->local_tx_ctrl.conn_state_flags.peer_conn_abort = 1; |
| 306 | } |
Ursula Braun | 46c28db | 2017-04-10 14:58:01 +0200 | [diff] [blame] | 307 | if (smc_cdc_rxed_any_close_or_senddone(conn)) { |
| 308 | smc->sk.sk_shutdown |= RCV_SHUTDOWN; |
| 309 | if (smc->clcsock && smc->clcsock->sk) |
| 310 | smc->clcsock->sk->sk_shutdown |= RCV_SHUTDOWN; |
| 311 | sock_set_flag(&smc->sk, SOCK_DONE); |
Ursula Braun | 51f1de7 | 2018-01-26 09:28:48 +0100 | [diff] [blame] | 312 | sock_hold(&smc->sk); /* sock_put in close_work */ |
| 313 | if (!schedule_work(&conn->close_work)) |
| 314 | sock_put(&smc->sk); |
Ursula Braun | b38d732 | 2017-01-09 16:55:25 +0100 | [diff] [blame] | 315 | } |
Ursula Braun | 5f08318 | 2017-01-09 16:55:22 +0100 | [diff] [blame] | 316 | } |
| 317 | |
| 318 | /* called under tasklet context */ |
Hans Wippel | d7b0e37 | 2018-05-18 09:34:15 +0200 | [diff] [blame] | 319 | static void smc_cdc_msg_recv(struct smc_sock *smc, struct smc_cdc_msg *cdc) |
Ursula Braun | 5f08318 | 2017-01-09 16:55:22 +0100 | [diff] [blame] | 320 | { |
Ursula Braun | 5f08318 | 2017-01-09 16:55:22 +0100 | [diff] [blame] | 321 | sock_hold(&smc->sk); |
Ursula Braun | 5f08318 | 2017-01-09 16:55:22 +0100 | [diff] [blame] | 322 | bh_lock_sock(&smc->sk); |
Hans Wippel | d7b0e37 | 2018-05-18 09:34:15 +0200 | [diff] [blame] | 323 | smc_cdc_msg_recv_action(smc, cdc); |
Ursula Braun | 5f08318 | 2017-01-09 16:55:22 +0100 | [diff] [blame] | 324 | bh_unlock_sock(&smc->sk); |
| 325 | sock_put(&smc->sk); /* no free sk in softirq-context */ |
| 326 | } |
| 327 | |
Hans Wippel | be244f2 | 2018-06-28 19:05:10 +0200 | [diff] [blame] | 328 | /* Schedule a tasklet for this connection. Triggered from the ISM device IRQ |
| 329 | * handler to indicate update in the DMBE. |
| 330 | * |
| 331 | * Context: |
| 332 | * - tasklet context |
| 333 | */ |
| 334 | static void smcd_cdc_rx_tsklet(unsigned long data) |
| 335 | { |
| 336 | struct smc_connection *conn = (struct smc_connection *)data; |
Ursula Braun | b9a22dd | 2018-11-20 16:46:42 +0100 | [diff] [blame] | 337 | struct smcd_cdc_msg *data_cdc; |
Hans Wippel | be244f2 | 2018-06-28 19:05:10 +0200 | [diff] [blame] | 338 | struct smcd_cdc_msg cdc; |
| 339 | struct smc_sock *smc; |
| 340 | |
| 341 | if (!conn) |
| 342 | return; |
| 343 | |
Ursula Braun | b9a22dd | 2018-11-20 16:46:42 +0100 | [diff] [blame] | 344 | data_cdc = (struct smcd_cdc_msg *)conn->rmb_desc->cpu_addr; |
| 345 | smcd_curs_copy(&cdc.prod, &data_cdc->prod, conn); |
| 346 | smcd_curs_copy(&cdc.cons, &data_cdc->cons, conn); |
Hans Wippel | be244f2 | 2018-06-28 19:05:10 +0200 | [diff] [blame] | 347 | smc = container_of(conn, struct smc_sock, conn); |
| 348 | smc_cdc_msg_recv(smc, (struct smc_cdc_msg *)&cdc); |
| 349 | } |
| 350 | |
| 351 | /* Initialize receive tasklet. Called from ISM device IRQ handler to start |
| 352 | * receiver side. |
| 353 | */ |
| 354 | void smcd_cdc_rx_init(struct smc_connection *conn) |
| 355 | { |
| 356 | tasklet_init(&conn->rx_tsklet, smcd_cdc_rx_tsklet, (unsigned long)conn); |
| 357 | } |
| 358 | |
Ursula Braun | 5f08318 | 2017-01-09 16:55:22 +0100 | [diff] [blame] | 359 | /***************************** init, exit, misc ******************************/ |
| 360 | |
| 361 | static void smc_cdc_rx_handler(struct ib_wc *wc, void *buf) |
| 362 | { |
| 363 | struct smc_link *link = (struct smc_link *)wc->qp->qp_context; |
| 364 | struct smc_cdc_msg *cdc = buf; |
Hans Wippel | d7b0e37 | 2018-05-18 09:34:15 +0200 | [diff] [blame] | 365 | struct smc_connection *conn; |
| 366 | struct smc_link_group *lgr; |
| 367 | struct smc_sock *smc; |
Ursula Braun | 5f08318 | 2017-01-09 16:55:22 +0100 | [diff] [blame] | 368 | |
| 369 | if (wc->byte_len < offsetof(struct smc_cdc_msg, reserved)) |
| 370 | return; /* short message */ |
Karsten Graul | cbba07a | 2018-02-28 12:44:07 +0100 | [diff] [blame] | 371 | if (cdc->len != SMC_WR_TX_SIZE) |
Ursula Braun | 5f08318 | 2017-01-09 16:55:22 +0100 | [diff] [blame] | 372 | return; /* invalid message */ |
Hans Wippel | d7b0e37 | 2018-05-18 09:34:15 +0200 | [diff] [blame] | 373 | |
| 374 | /* lookup connection */ |
Stefan Raspl | 00e5fb2 | 2018-07-23 13:53:10 +0200 | [diff] [blame] | 375 | lgr = smc_get_lgr(link); |
Hans Wippel | d7b0e37 | 2018-05-18 09:34:15 +0200 | [diff] [blame] | 376 | read_lock_bh(&lgr->conns_lock); |
| 377 | conn = smc_lgr_find_conn(ntohl(cdc->token), lgr); |
| 378 | read_unlock_bh(&lgr->conns_lock); |
| 379 | if (!conn) |
| 380 | return; |
| 381 | smc = container_of(conn, struct smc_sock, conn); |
| 382 | |
| 383 | if (!cdc->prod_flags.failover_validation) { |
| 384 | if (smc_cdc_before(ntohs(cdc->seqno), |
| 385 | conn->local_rx_ctrl.seqno)) |
| 386 | /* received seqno is old */ |
| 387 | return; |
| 388 | } |
| 389 | smc_cdc_msg_recv(smc, cdc); |
Ursula Braun | 5f08318 | 2017-01-09 16:55:22 +0100 | [diff] [blame] | 390 | } |
| 391 | |
| 392 | static struct smc_wr_rx_handler smc_cdc_rx_handlers[] = { |
| 393 | { |
| 394 | .handler = smc_cdc_rx_handler, |
| 395 | .type = SMC_CDC_MSG_TYPE |
| 396 | }, |
| 397 | { |
| 398 | .handler = NULL, |
| 399 | } |
| 400 | }; |
| 401 | |
| 402 | int __init smc_cdc_init(void) |
| 403 | { |
| 404 | struct smc_wr_rx_handler *handler; |
| 405 | int rc = 0; |
| 406 | |
| 407 | for (handler = smc_cdc_rx_handlers; handler->handler; handler++) { |
| 408 | INIT_HLIST_NODE(&handler->list); |
| 409 | rc = smc_wr_rx_register_handler(handler); |
| 410 | if (rc) |
| 411 | break; |
| 412 | } |
| 413 | return rc; |
| 414 | } |