2 * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
4 * Copyright (c) 2012, 2017, Intel Corporation.
6 * Author: Zach Brown <zab@zabbo.net>
7 * Author: Peter J. Braam <braam@clusterfs.com>
8 * Author: Phil Schwan <phil@clusterfs.com>
9 * Author: Eric Barton <eric@bartonsoftware.com>
11 * This file is part of Lustre, https://wiki.whamcloud.com/
13 * Portals is free software; you can redistribute it and/or
14 * modify it under the terms of version 2 of the GNU General Public
15 * License as published by the Free Software Foundation.
17 * Portals is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with Portals; if not, write to the Free Software
24 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
31 * pro_send_hello : send hello message
32 * pro_recv_hello : receive hello message
33 * pro_pack : pack message header
34 * pro_unpack : unpack message header
35 * pro_queue_tx_zcack() : Called holding BH lock: kss_lock
36 * return 1 if ACK is piggybacked, otherwise return 0
37 * pro_queue_tx_msg() : Called holding BH lock: kss_lock
38 * return the ACK that piggybacked by my message, or NULL
39 * pro_handle_zcreq() : handler of incoming ZC-REQ
40 * pro_handle_zcack() : handler of incoming ZC-ACK
41 * pro_match_tx() : Called holding glock
44 static struct ksock_tx *
45 ksocknal_queue_tx_msg_v1(struct ksock_conn *conn, struct ksock_tx *tx_msg)
47 /* V1.x, just enqueue it */
48 list_add_tail(&tx_msg->tx_list, &conn->ksnc_tx_queue);
53 ksocknal_next_tx_carrier(struct ksock_conn *conn)
55 struct ksock_tx *tx = conn->ksnc_tx_carrier;
57 /* Called holding BH lock: conn->ksnc_scheduler->kss_lock */
58 LASSERT(!list_empty(&conn->ksnc_tx_queue));
61 /* Next TX that can carry ZC-ACK or LNet message */
62 if (tx->tx_list.next == &conn->ksnc_tx_queue) {
63 /* no more packets queued */
64 conn->ksnc_tx_carrier = NULL;
66 conn->ksnc_tx_carrier = list_next_entry(tx, tx_list);
67 LASSERT(conn->ksnc_tx_carrier->tx_msg.ksm_type ==
73 ksocknal_queue_tx_zcack_v2(struct ksock_conn *conn,
74 struct ksock_tx *tx_ack, __u64 cookie)
76 struct ksock_tx *tx = conn->ksnc_tx_carrier;
78 LASSERT (tx_ack == NULL ||
79 tx_ack->tx_msg.ksm_type == KSOCK_MSG_NOOP);
82 * Enqueue or piggyback tx_ack / cookie
83 * . no tx can piggyback cookie of tx_ack (or cookie), just
84 * enqueue the tx_ack (if tx_ack != NUL) and return NULL.
85 * . There is tx can piggyback cookie of tx_ack (or cookie),
86 * piggyback the cookie and return the tx.
90 list_add_tail(&tx_ack->tx_list,
91 &conn->ksnc_tx_queue);
92 conn->ksnc_tx_carrier = tx_ack;
97 if (tx->tx_msg.ksm_type == KSOCK_MSG_NOOP) {
98 /* tx is noop zc-ack, can't piggyback zc-ack cookie */
100 list_add_tail(&tx_ack->tx_list,
101 &conn->ksnc_tx_queue);
105 LASSERT(tx->tx_msg.ksm_type == KSOCK_MSG_LNET);
106 LASSERT(tx->tx_msg.ksm_zc_cookies[1] == 0);
109 cookie = tx_ack->tx_msg.ksm_zc_cookies[1];
111 /* piggyback the zc-ack cookie */
112 tx->tx_msg.ksm_zc_cookies[1] = cookie;
113 /* move on to the next TX which can carry cookie */
114 ksocknal_next_tx_carrier(conn);
119 static struct ksock_tx *
120 ksocknal_queue_tx_msg_v2(struct ksock_conn *conn, struct ksock_tx *tx_msg)
122 struct ksock_tx *tx = conn->ksnc_tx_carrier;
126 * . If there is no NOOP on the connection, just enqueue
127 * tx_msg and return NULL
128 * . If there is NOOP on the connection, piggyback the cookie
129 * and replace the NOOP tx, and return the NOOP tx.
131 if (tx == NULL) { /* nothing on queue */
132 list_add_tail(&tx_msg->tx_list, &conn->ksnc_tx_queue);
133 conn->ksnc_tx_carrier = tx_msg;
137 if (tx->tx_msg.ksm_type == KSOCK_MSG_LNET) { /* nothing to carry */
138 list_add_tail(&tx_msg->tx_list, &conn->ksnc_tx_queue);
142 LASSERT (tx->tx_msg.ksm_type == KSOCK_MSG_NOOP);
144 /* There is a noop zc-ack can be piggybacked */
145 tx_msg->tx_msg.ksm_zc_cookies[1] = tx->tx_msg.ksm_zc_cookies[1];
146 ksocknal_next_tx_carrier(conn);
148 /* use new_tx to replace the noop zc-ack packet */
149 list_splice(&tx->tx_list, &tx_msg->tx_list);
155 ksocknal_queue_tx_zcack_v3(struct ksock_conn *conn,
156 struct ksock_tx *tx_ack, __u64 cookie)
160 if (conn->ksnc_type != SOCKLND_CONN_ACK)
161 return ksocknal_queue_tx_zcack_v2(conn, tx_ack, cookie);
163 /* non-blocking ZC-ACK (to router) */
164 LASSERT (tx_ack == NULL ||
165 tx_ack->tx_msg.ksm_type == KSOCK_MSG_NOOP);
167 if ((tx = conn->ksnc_tx_carrier) == NULL) {
168 if (tx_ack != NULL) {
169 list_add_tail(&tx_ack->tx_list,
170 &conn->ksnc_tx_queue);
171 conn->ksnc_tx_carrier = tx_ack;
176 /* conn->ksnc_tx_carrier != NULL */
179 cookie = tx_ack->tx_msg.ksm_zc_cookies[1];
181 if (cookie == SOCKNAL_KEEPALIVE_PING) /* ignore keepalive PING */
184 if (tx->tx_msg.ksm_zc_cookies[1] == SOCKNAL_KEEPALIVE_PING) {
185 /* replace the keepalive PING with a real ACK */
186 LASSERT (tx->tx_msg.ksm_zc_cookies[0] == 0);
187 tx->tx_msg.ksm_zc_cookies[1] = cookie;
191 if (cookie == tx->tx_msg.ksm_zc_cookies[0] ||
192 cookie == tx->tx_msg.ksm_zc_cookies[1]) {
193 CWARN("%s: duplicated ZC cookie: %llu\n",
194 libcfs_idstr(&conn->ksnc_peer->ksnp_id), cookie);
195 return 1; /* XXX return error in the future */
198 if (tx->tx_msg.ksm_zc_cookies[0] == 0) {
199 /* NOOP tx has only one ZC-ACK cookie, can carry at least one more */
200 if (tx->tx_msg.ksm_zc_cookies[1] > cookie) {
201 tx->tx_msg.ksm_zc_cookies[0] = tx->tx_msg.ksm_zc_cookies[1];
202 tx->tx_msg.ksm_zc_cookies[1] = cookie;
204 tx->tx_msg.ksm_zc_cookies[0] = cookie;
207 if (tx->tx_msg.ksm_zc_cookies[0] - tx->tx_msg.ksm_zc_cookies[1] > 2) {
208 /* not likely to carry more ACKs, skip it to simplify logic */
209 ksocknal_next_tx_carrier(conn);
215 /* takes two or more cookies already */
217 if (tx->tx_msg.ksm_zc_cookies[0] > tx->tx_msg.ksm_zc_cookies[1]) {
220 /* two separated cookies: (a+2, a) or (a+1, a) */
221 LASSERT (tx->tx_msg.ksm_zc_cookies[0] -
222 tx->tx_msg.ksm_zc_cookies[1] <= 2);
224 if (tx->tx_msg.ksm_zc_cookies[0] -
225 tx->tx_msg.ksm_zc_cookies[1] == 2) {
226 if (cookie == tx->tx_msg.ksm_zc_cookies[1] + 1)
228 } else if (cookie == tx->tx_msg.ksm_zc_cookies[1] - 1) {
229 tmp = tx->tx_msg.ksm_zc_cookies[1];
230 } else if (cookie == tx->tx_msg.ksm_zc_cookies[0] + 1) {
231 tmp = tx->tx_msg.ksm_zc_cookies[0];
235 /* range of cookies */
236 tx->tx_msg.ksm_zc_cookies[0] = tmp - 1;
237 tx->tx_msg.ksm_zc_cookies[1] = tmp + 1;
242 /* ksm_zc_cookies[0] < ksm_zc_cookies[1], it is a range
245 if (cookie >= tx->tx_msg.ksm_zc_cookies[0] &&
246 cookie <= tx->tx_msg.ksm_zc_cookies[1]) {
247 CWARN("%s: duplicated ZC cookie: %llu\n",
248 libcfs_idstr(&conn->ksnc_peer->ksnp_id),
250 return 1; /* XXX: return error in the future */
253 if (cookie == tx->tx_msg.ksm_zc_cookies[1] + 1) {
254 tx->tx_msg.ksm_zc_cookies[1] = cookie;
258 if (cookie == tx->tx_msg.ksm_zc_cookies[0] - 1) {
259 tx->tx_msg.ksm_zc_cookies[0] = cookie;
264 /* failed to piggyback ZC-ACK */
265 if (tx_ack != NULL) {
266 list_add_tail(&tx_ack->tx_list, &conn->ksnc_tx_queue);
267 /* the next tx can piggyback at least 1 ACK */
268 ksocknal_next_tx_carrier(conn);
275 ksocknal_match_tx(struct ksock_conn *conn, struct ksock_tx *tx, int nonblk)
279 #if SOCKNAL_VERSION_DEBUG
280 if (!*ksocknal_tunables.ksnd_typed_conns)
281 return SOCKNAL_MATCH_YES;
284 if (tx == NULL || tx->tx_lnetmsg == NULL) {
286 nob = sizeof(struct ksock_msg_hdr);
288 nob = tx->tx_lnetmsg->msg_len +
289 ((conn->ksnc_proto == &ksocknal_protocol_v1x) ?
290 0 : sizeof(struct ksock_msg_hdr)) +
291 sizeof(struct lnet_hdr);
294 /* default checking for typed connection */
295 switch (conn->ksnc_type) {
297 CERROR("ksnc_type bad: %u\n", conn->ksnc_type);
299 case SOCKLND_CONN_ANY:
300 return SOCKNAL_MATCH_YES;
302 case SOCKLND_CONN_BULK_IN:
303 return SOCKNAL_MATCH_MAY;
305 case SOCKLND_CONN_BULK_OUT:
306 if (nob < *ksocknal_tunables.ksnd_min_bulk)
307 return SOCKNAL_MATCH_MAY;
309 return SOCKNAL_MATCH_YES;
311 case SOCKLND_CONN_CONTROL:
312 if (nob >= *ksocknal_tunables.ksnd_min_bulk)
313 return SOCKNAL_MATCH_MAY;
315 return SOCKNAL_MATCH_YES;
320 ksocknal_match_tx_v3(struct ksock_conn *conn, struct ksock_tx *tx, int nonblk)
324 if (tx == NULL || tx->tx_lnetmsg == NULL)
325 nob = sizeof(struct ksock_msg_hdr);
327 nob = sizeof(struct ksock_msg_hdr) + sizeof(struct lnet_hdr) +
328 tx->tx_lnetmsg->msg_len;
330 switch (conn->ksnc_type) {
332 CERROR("ksnc_type bad: %u\n", conn->ksnc_type);
334 case SOCKLND_CONN_ANY:
335 return SOCKNAL_MATCH_NO;
337 case SOCKLND_CONN_ACK:
339 return SOCKNAL_MATCH_YES;
340 else if (tx == NULL || tx->tx_lnetmsg == NULL)
341 return SOCKNAL_MATCH_MAY;
343 return SOCKNAL_MATCH_NO;
345 case SOCKLND_CONN_BULK_OUT:
347 return SOCKNAL_MATCH_NO;
348 else if (nob < *ksocknal_tunables.ksnd_min_bulk)
349 return SOCKNAL_MATCH_MAY;
351 return SOCKNAL_MATCH_YES;
353 case SOCKLND_CONN_CONTROL:
355 return SOCKNAL_MATCH_NO;
356 else if (nob >= *ksocknal_tunables.ksnd_min_bulk)
357 return SOCKNAL_MATCH_MAY;
359 return SOCKNAL_MATCH_YES;
363 /* (Sink) handle incoming ZC request from sender */
365 ksocknal_handle_zcreq(struct ksock_conn *c, __u64 cookie, int remote)
367 struct ksock_peer_ni *peer_ni = c->ksnc_peer;
368 struct ksock_conn *conn;
372 read_lock(&ksocknal_data.ksnd_global_lock);
374 conn = ksocknal_find_conn_locked(peer_ni, NULL, !!remote);
376 struct ksock_sched *sched = conn->ksnc_scheduler;
378 LASSERT(conn->ksnc_proto->pro_queue_tx_zcack != NULL);
380 spin_lock_bh(&sched->kss_lock);
382 rc = conn->ksnc_proto->pro_queue_tx_zcack(conn, NULL, cookie);
384 spin_unlock_bh(&sched->kss_lock);
386 if (rc) { /* piggybacked */
387 read_unlock(&ksocknal_data.ksnd_global_lock);
392 read_unlock(&ksocknal_data.ksnd_global_lock);
394 /* ACK connection is not ready, or can't piggyback the ACK */
395 tx = ksocknal_alloc_tx_noop(cookie, !!remote);
399 rc = ksocknal_launch_packet(peer_ni->ksnp_ni, tx, &peer_ni->ksnp_id);
403 ksocknal_free_tx(tx);
407 /* (Sender) handle ZC_ACK from sink */
409 ksocknal_handle_zcack(struct ksock_conn *conn, __u64 cookie1, __u64 cookie2)
411 struct ksock_peer_ni *peer_ni = conn->ksnc_peer;
413 struct ksock_tx *tmp;
420 count = (cookie1 > cookie2) ? 2 : (cookie2 - cookie1 + 1);
422 if (cookie2 == SOCKNAL_KEEPALIVE_PING &&
423 conn->ksnc_proto == &ksocknal_protocol_v3x) {
424 /* keepalive PING for V3.x, just ignore it */
425 return count == 1 ? 0 : -EPROTO;
428 spin_lock(&peer_ni->ksnp_lock);
430 list_for_each_entry_safe(tx, tmp, &peer_ni->ksnp_zc_req_list,
432 __u64 c = tx->tx_msg.ksm_zc_cookies[0];
434 if (c == cookie1 || c == cookie2 || (cookie1 < c && c < cookie2)) {
435 tx->tx_msg.ksm_zc_cookies[0] = 0;
436 list_move(&tx->tx_zc_list, &zlist);
443 spin_unlock(&peer_ni->ksnp_lock);
445 while ((tx = list_first_entry_or_null(&zlist, struct ksock_tx,
446 tx_zc_list)) != NULL) {
447 list_del(&tx->tx_zc_list);
448 ksocknal_tx_decref(tx);
451 return count == 0 ? 0 : -EPROTO;
455 ksocknal_send_hello_v1(struct ksock_conn *conn, struct ksock_hello_msg *hello)
457 struct socket *sock = conn->ksnc_sock;
458 struct lnet_hdr *hdr;
459 struct lnet_magicversion *hmv;
463 BUILD_BUG_ON(sizeof(struct lnet_magicversion) !=
464 offsetof(struct lnet_hdr, src_nid));
466 LIBCFS_ALLOC(hdr, sizeof(*hdr));
468 CERROR("Can't allocate struct lnet_hdr\n");
472 hmv = (struct lnet_magicversion *)&hdr->dest_nid;
474 /* Re-organize V2.x message header to V1.x (struct lnet_hdr)
475 * header and send out */
476 hmv->magic = cpu_to_le32 (LNET_PROTO_TCP_MAGIC);
477 hmv->version_major = cpu_to_le16 (KSOCK_PROTO_V1_MAJOR);
478 hmv->version_minor = cpu_to_le16 (KSOCK_PROTO_V1_MINOR);
480 if (the_lnet.ln_testprotocompat) {
481 /* single-shot proto check */
482 if (test_and_clear_bit(0, &the_lnet.ln_testprotocompat))
483 hmv->version_major++; /* just different! */
485 if (test_and_clear_bit(1, &the_lnet.ln_testprotocompat))
486 hmv->magic = LNET_PROTO_MAGIC;
489 hdr->src_nid = cpu_to_le64 (hello->kshm_src_nid);
490 hdr->src_pid = cpu_to_le32 (hello->kshm_src_pid);
491 hdr->type = cpu_to_le32 (LNET_MSG_HELLO);
492 hdr->payload_length = cpu_to_le32 (hello->kshm_nips * sizeof(__u32));
493 hdr->msg.hello.type = cpu_to_le32 (hello->kshm_ctype);
494 hdr->msg.hello.incarnation = cpu_to_le64 (hello->kshm_src_incarnation);
496 rc = lnet_sock_write(sock, hdr, sizeof(*hdr), lnet_acceptor_timeout());
498 CNETERR("Error %d sending HELLO hdr to %pISp\n",
499 rc, &conn->ksnc_peeraddr);
503 if (hello->kshm_nips == 0)
506 for (i = 0; i < (int) hello->kshm_nips; i++) {
507 hello->kshm_ips[i] = __cpu_to_le32 (hello->kshm_ips[i]);
510 rc = lnet_sock_write(sock, hello->kshm_ips,
511 hello->kshm_nips * sizeof(__u32),
512 lnet_acceptor_timeout());
514 CNETERR("Error %d sending HELLO payload (%d) to %pISp\n",
515 rc, hello->kshm_nips,
516 &conn->ksnc_peeraddr);
519 LIBCFS_FREE(hdr, sizeof(*hdr));
525 ksocknal_send_hello_v2(struct ksock_conn *conn, struct ksock_hello_msg *hello)
527 struct socket *sock = conn->ksnc_sock;
530 hello->kshm_magic = LNET_PROTO_MAGIC;
531 hello->kshm_version = conn->ksnc_proto->pro_version;
533 if (the_lnet.ln_testprotocompat) {
534 /* single-shot proto check */
535 if (test_and_clear_bit(0, &the_lnet.ln_testprotocompat))
536 hello->kshm_version++; /* just different! */
539 rc = lnet_sock_write(sock, hello, offsetof(struct ksock_hello_msg, kshm_ips),
540 lnet_acceptor_timeout());
543 CNETERR("Error %d sending HELLO hdr to %pISp\n",
544 rc, &conn->ksnc_peeraddr);
548 if (hello->kshm_nips == 0)
551 rc = lnet_sock_write(sock, hello->kshm_ips,
552 hello->kshm_nips * sizeof(__u32),
553 lnet_acceptor_timeout());
555 CNETERR("Error %d sending HELLO payload (%d) to %pISp\n", rc,
557 &conn->ksnc_peeraddr);
564 ksocknal_recv_hello_v1(struct ksock_conn *conn, struct ksock_hello_msg *hello,
567 struct socket *sock = conn->ksnc_sock;
568 struct lnet_hdr *hdr;
572 LIBCFS_ALLOC(hdr, sizeof(*hdr));
574 CERROR("Can't allocate struct lnet_hdr\n");
578 rc = lnet_sock_read(sock, &hdr->src_nid,
579 sizeof(*hdr) - offsetof(struct lnet_hdr, src_nid),
582 CERROR("Error %d reading rest of HELLO hdr from %pIS\n",
583 rc, &conn->ksnc_peeraddr);
584 LASSERT(rc < 0 && rc != -EALREADY);
588 /* ...and check we got what we expected */
589 if (hdr->type != cpu_to_le32 (LNET_MSG_HELLO)) {
590 CERROR("Expecting a HELLO hdr, but got type %d from %pIS\n",
591 le32_to_cpu(hdr->type),
592 &conn->ksnc_peeraddr);
597 hello->kshm_src_nid = le64_to_cpu (hdr->src_nid);
598 hello->kshm_src_pid = le32_to_cpu (hdr->src_pid);
599 hello->kshm_src_incarnation = le64_to_cpu (hdr->msg.hello.incarnation);
600 hello->kshm_ctype = le32_to_cpu (hdr->msg.hello.type);
601 hello->kshm_nips = le32_to_cpu (hdr->payload_length) /
604 if (hello->kshm_nips > LNET_INTERFACES_NUM) {
605 CERROR("Bad nips %d from ip %pIS\n",
606 hello->kshm_nips, &conn->ksnc_peeraddr);
611 if (hello->kshm_nips == 0)
614 rc = lnet_sock_read(sock, hello->kshm_ips,
615 hello->kshm_nips * sizeof(__u32), timeout);
617 CERROR("Error %d reading IPs from ip %pIS\n",
618 rc, &conn->ksnc_peeraddr);
619 LASSERT(rc < 0 && rc != -EALREADY);
623 for (i = 0; i < (int) hello->kshm_nips; i++) {
624 hello->kshm_ips[i] = __le32_to_cpu(hello->kshm_ips[i]);
626 if (hello->kshm_ips[i] == 0) {
627 CERROR("Zero IP[%d] from ip %pIS\n",
628 i, &conn->ksnc_peeraddr);
634 LIBCFS_FREE(hdr, sizeof(*hdr));
640 ksocknal_recv_hello_v2(struct ksock_conn *conn, struct ksock_hello_msg *hello,
643 struct socket *sock = conn->ksnc_sock;
647 if (hello->kshm_magic == LNET_PROTO_MAGIC)
652 rc = lnet_sock_read(sock, &hello->kshm_src_nid,
653 offsetof(struct ksock_hello_msg, kshm_ips) -
654 offsetof(struct ksock_hello_msg, kshm_src_nid),
657 CERROR("Error %d reading HELLO from %pIS\n",
658 rc, &conn->ksnc_peeraddr);
659 LASSERT(rc < 0 && rc != -EALREADY);
663 if (conn->ksnc_flip) {
664 __swab32s(&hello->kshm_src_pid);
665 __swab64s(&hello->kshm_src_nid);
666 __swab32s(&hello->kshm_dst_pid);
667 __swab64s(&hello->kshm_dst_nid);
668 __swab64s(&hello->kshm_src_incarnation);
669 __swab64s(&hello->kshm_dst_incarnation);
670 __swab32s(&hello->kshm_ctype);
671 __swab32s(&hello->kshm_nips);
674 if (hello->kshm_nips > LNET_INTERFACES_NUM) {
675 CERROR("Bad nips %d from ip %pIS\n",
676 hello->kshm_nips, &conn->ksnc_peeraddr);
680 if (hello->kshm_nips == 0)
683 rc = lnet_sock_read(sock, hello->kshm_ips,
684 hello->kshm_nips * sizeof(__u32), timeout);
686 CERROR("Error %d reading IPs from ip %pIS\n",
687 rc, &conn->ksnc_peeraddr);
688 LASSERT(rc < 0 && rc != -EALREADY);
692 for (i = 0; i < (int) hello->kshm_nips; i++) {
694 __swab32s(&hello->kshm_ips[i]);
696 if (hello->kshm_ips[i] == 0) {
697 CERROR("Zero IP[%d] from ip %pIS\n",
698 i, &conn->ksnc_peeraddr);
707 ksocknal_pack_msg_v1(struct ksock_tx *tx)
709 /* V1.x has no KSOCK_MSG_NOOP */
710 LASSERT(tx->tx_msg.ksm_type != KSOCK_MSG_NOOP);
711 LASSERT(tx->tx_lnetmsg != NULL);
713 tx->tx_hdr.iov_base = (void *)&tx->tx_lnetmsg->msg_hdr;
714 tx->tx_hdr.iov_len = sizeof(struct lnet_hdr);
716 tx->tx_nob = tx->tx_lnetmsg->msg_len + sizeof(struct lnet_hdr);
717 tx->tx_resid = tx->tx_nob;
721 ksocknal_pack_msg_v2(struct ksock_tx *tx)
725 tx->tx_hdr.iov_base = (void *)&tx->tx_msg;
727 switch (tx->tx_msg.ksm_type) {
729 LASSERT(tx->tx_lnetmsg != NULL);
730 hdr_size = (sizeof(struct ksock_msg_hdr) +
731 sizeof(struct lnet_hdr));
733 tx->tx_msg.ksm_u.lnetmsg = tx->tx_lnetmsg->msg_hdr;
734 tx->tx_hdr.iov_len = hdr_size;
735 tx->tx_resid = tx->tx_nob = hdr_size + tx->tx_lnetmsg->msg_len;
738 LASSERT(tx->tx_lnetmsg == NULL);
739 hdr_size = sizeof(struct ksock_msg_hdr);
741 tx->tx_hdr.iov_len = hdr_size;
742 tx->tx_resid = tx->tx_nob = hdr_size;
747 /* Don't checksum before start sending, because packet can be
748 * piggybacked with ACK
753 ksocknal_unpack_msg_v1(struct ksock_msg *msg)
756 msg->ksm_type = KSOCK_MSG_LNET;
757 msg->ksm_zc_cookies[0] = msg->ksm_zc_cookies[1] = 0;
761 ksocknal_unpack_msg_v2(struct ksock_msg *msg)
763 return; /* Do nothing */
766 const struct ksock_proto ksocknal_protocol_v1x =
768 .pro_version = KSOCK_PROTO_V1,
769 .pro_send_hello = ksocknal_send_hello_v1,
770 .pro_recv_hello = ksocknal_recv_hello_v1,
771 .pro_pack = ksocknal_pack_msg_v1,
772 .pro_unpack = ksocknal_unpack_msg_v1,
773 .pro_queue_tx_msg = ksocknal_queue_tx_msg_v1,
774 .pro_handle_zcreq = NULL,
775 .pro_handle_zcack = NULL,
776 .pro_queue_tx_zcack = NULL,
777 .pro_match_tx = ksocknal_match_tx
780 const struct ksock_proto ksocknal_protocol_v2x =
782 .pro_version = KSOCK_PROTO_V2,
783 .pro_send_hello = ksocknal_send_hello_v2,
784 .pro_recv_hello = ksocknal_recv_hello_v2,
785 .pro_pack = ksocknal_pack_msg_v2,
786 .pro_unpack = ksocknal_unpack_msg_v2,
787 .pro_queue_tx_msg = ksocknal_queue_tx_msg_v2,
788 .pro_queue_tx_zcack = ksocknal_queue_tx_zcack_v2,
789 .pro_handle_zcreq = ksocknal_handle_zcreq,
790 .pro_handle_zcack = ksocknal_handle_zcack,
791 .pro_match_tx = ksocknal_match_tx
794 const struct ksock_proto ksocknal_protocol_v3x =
796 .pro_version = KSOCK_PROTO_V3,
797 .pro_send_hello = ksocknal_send_hello_v2,
798 .pro_recv_hello = ksocknal_recv_hello_v2,
799 .pro_pack = ksocknal_pack_msg_v2,
800 .pro_unpack = ksocknal_unpack_msg_v2,
801 .pro_queue_tx_msg = ksocknal_queue_tx_msg_v2,
802 .pro_queue_tx_zcack = ksocknal_queue_tx_zcack_v3,
803 .pro_handle_zcreq = ksocknal_handle_zcreq,
804 .pro_handle_zcack = ksocknal_handle_zcack,
805 .pro_match_tx = ksocknal_match_tx_v3