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