2 * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
4 * Copyright (c) 2012, 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.hpdd.intel.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
45 ksocknal_queue_tx_msg_v1(ksock_conn_t *conn, ksock_tx_t *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(ksock_conn_t *conn)
55 ksock_tx_t *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_entry(tx->tx_list.next,
68 LASSERT(conn->ksnc_tx_carrier->tx_msg.ksm_type ==
74 ksocknal_queue_tx_zcack_v2(ksock_conn_t *conn,
75 ksock_tx_t *tx_ack, __u64 cookie)
77 ksock_tx_t *tx = conn->ksnc_tx_carrier;
79 LASSERT (tx_ack == NULL ||
80 tx_ack->tx_msg.ksm_type == KSOCK_MSG_NOOP);
83 * Enqueue or piggyback tx_ack / cookie
84 * . no tx can piggyback cookie of tx_ack (or cookie), just
85 * enqueue the tx_ack (if tx_ack != NUL) and return NULL.
86 * . There is tx can piggyback cookie of tx_ack (or cookie),
87 * piggyback the cookie and return the tx.
91 list_add_tail(&tx_ack->tx_list,
92 &conn->ksnc_tx_queue);
93 conn->ksnc_tx_carrier = tx_ack;
98 if (tx->tx_msg.ksm_type == KSOCK_MSG_NOOP) {
99 /* tx is noop zc-ack, can't piggyback zc-ack cookie */
101 list_add_tail(&tx_ack->tx_list,
102 &conn->ksnc_tx_queue);
106 LASSERT(tx->tx_msg.ksm_type == KSOCK_MSG_LNET);
107 LASSERT(tx->tx_msg.ksm_zc_cookies[1] == 0);
110 cookie = tx_ack->tx_msg.ksm_zc_cookies[1];
112 /* piggyback the zc-ack cookie */
113 tx->tx_msg.ksm_zc_cookies[1] = cookie;
114 /* move on to the next TX which can carry cookie */
115 ksocknal_next_tx_carrier(conn);
121 ksocknal_queue_tx_msg_v2(ksock_conn_t *conn, ksock_tx_t *tx_msg)
123 ksock_tx_t *tx = conn->ksnc_tx_carrier;
127 * . If there is no NOOP on the connection, just enqueue
128 * tx_msg and return NULL
129 * . If there is NOOP on the connection, piggyback the cookie
130 * and replace the NOOP tx, and return the NOOP tx.
132 if (tx == NULL) { /* nothing on queue */
133 list_add_tail(&tx_msg->tx_list, &conn->ksnc_tx_queue);
134 conn->ksnc_tx_carrier = tx_msg;
138 if (tx->tx_msg.ksm_type == KSOCK_MSG_LNET) { /* nothing to carry */
139 list_add_tail(&tx_msg->tx_list, &conn->ksnc_tx_queue);
143 LASSERT (tx->tx_msg.ksm_type == KSOCK_MSG_NOOP);
145 /* There is a noop zc-ack can be piggybacked */
146 tx_msg->tx_msg.ksm_zc_cookies[1] = tx->tx_msg.ksm_zc_cookies[1];
147 ksocknal_next_tx_carrier(conn);
149 /* use new_tx to replace the noop zc-ack packet */
150 list_add(&tx_msg->tx_list, &tx->tx_list);
151 list_del(&tx->tx_list);
157 ksocknal_queue_tx_zcack_v3(ksock_conn_t *conn,
158 ksock_tx_t *tx_ack, __u64 cookie)
162 if (conn->ksnc_type != SOCKLND_CONN_ACK)
163 return ksocknal_queue_tx_zcack_v2(conn, tx_ack, cookie);
165 /* non-blocking ZC-ACK (to router) */
166 LASSERT (tx_ack == NULL ||
167 tx_ack->tx_msg.ksm_type == KSOCK_MSG_NOOP);
169 if ((tx = conn->ksnc_tx_carrier) == NULL) {
170 if (tx_ack != NULL) {
171 list_add_tail(&tx_ack->tx_list,
172 &conn->ksnc_tx_queue);
173 conn->ksnc_tx_carrier = tx_ack;
178 /* conn->ksnc_tx_carrier != NULL */
181 cookie = tx_ack->tx_msg.ksm_zc_cookies[1];
183 if (cookie == SOCKNAL_KEEPALIVE_PING) /* ignore keepalive PING */
186 if (tx->tx_msg.ksm_zc_cookies[1] == SOCKNAL_KEEPALIVE_PING) {
187 /* replace the keepalive PING with a real ACK */
188 LASSERT (tx->tx_msg.ksm_zc_cookies[0] == 0);
189 tx->tx_msg.ksm_zc_cookies[1] = cookie;
193 if (cookie == tx->tx_msg.ksm_zc_cookies[0] ||
194 cookie == tx->tx_msg.ksm_zc_cookies[1]) {
195 CWARN("%s: duplicated ZC cookie: %llu\n",
196 libcfs_id2str(conn->ksnc_peer->ksnp_id), cookie);
197 return 1; /* XXX return error in the future */
200 if (tx->tx_msg.ksm_zc_cookies[0] == 0) {
201 /* NOOP tx has only one ZC-ACK cookie, can carry at least one more */
202 if (tx->tx_msg.ksm_zc_cookies[1] > cookie) {
203 tx->tx_msg.ksm_zc_cookies[0] = tx->tx_msg.ksm_zc_cookies[1];
204 tx->tx_msg.ksm_zc_cookies[1] = cookie;
206 tx->tx_msg.ksm_zc_cookies[0] = cookie;
209 if (tx->tx_msg.ksm_zc_cookies[0] - tx->tx_msg.ksm_zc_cookies[1] > 2) {
210 /* not likely to carry more ACKs, skip it to simplify logic */
211 ksocknal_next_tx_carrier(conn);
217 /* takes two or more cookies already */
219 if (tx->tx_msg.ksm_zc_cookies[0] > tx->tx_msg.ksm_zc_cookies[1]) {
222 /* two separated cookies: (a+2, a) or (a+1, a) */
223 LASSERT (tx->tx_msg.ksm_zc_cookies[0] -
224 tx->tx_msg.ksm_zc_cookies[1] <= 2);
226 if (tx->tx_msg.ksm_zc_cookies[0] -
227 tx->tx_msg.ksm_zc_cookies[1] == 2) {
228 if (cookie == tx->tx_msg.ksm_zc_cookies[1] + 1)
230 } else if (cookie == tx->tx_msg.ksm_zc_cookies[1] - 1) {
231 tmp = tx->tx_msg.ksm_zc_cookies[1];
232 } else if (cookie == tx->tx_msg.ksm_zc_cookies[0] + 1) {
233 tmp = tx->tx_msg.ksm_zc_cookies[0];
237 /* range of cookies */
238 tx->tx_msg.ksm_zc_cookies[0] = tmp - 1;
239 tx->tx_msg.ksm_zc_cookies[1] = tmp + 1;
244 /* ksm_zc_cookies[0] < ksm_zc_cookies[1], it is range of cookies */
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_id2str(conn->ksnc_peer->ksnp_id), cookie);
249 return 1; /* XXX: return error in the future */
252 if (cookie == tx->tx_msg.ksm_zc_cookies[1] + 1) {
253 tx->tx_msg.ksm_zc_cookies[1] = cookie;
257 if (cookie == tx->tx_msg.ksm_zc_cookies[0] - 1) {
258 tx->tx_msg.ksm_zc_cookies[0] = cookie;
263 /* failed to piggyback ZC-ACK */
264 if (tx_ack != NULL) {
265 list_add_tail(&tx_ack->tx_list, &conn->ksnc_tx_queue);
266 /* the next tx can piggyback at least 1 ACK */
267 ksocknal_next_tx_carrier(conn);
274 ksocknal_match_tx(ksock_conn_t *conn, ksock_tx_t *tx, int nonblk)
278 #if SOCKNAL_VERSION_DEBUG
279 if (!*ksocknal_tunables.ksnd_typed_conns)
280 return SOCKNAL_MATCH_YES;
283 if (tx == NULL || tx->tx_lnetmsg == NULL) {
285 nob = offsetof(struct ksock_msg, ksm_u);
287 nob = tx->tx_lnetmsg->msg_len +
288 ((conn->ksnc_proto == &ksocknal_protocol_v1x) ?
289 sizeof(struct lnet_hdr) : sizeof(struct ksock_msg));
292 /* default checking for typed connection */
293 switch (conn->ksnc_type) {
295 CERROR("ksnc_type bad: %u\n", conn->ksnc_type);
297 case SOCKLND_CONN_ANY:
298 return SOCKNAL_MATCH_YES;
300 case SOCKLND_CONN_BULK_IN:
301 return SOCKNAL_MATCH_MAY;
303 case SOCKLND_CONN_BULK_OUT:
304 if (nob < *ksocknal_tunables.ksnd_min_bulk)
305 return SOCKNAL_MATCH_MAY;
307 return SOCKNAL_MATCH_YES;
309 case SOCKLND_CONN_CONTROL:
310 if (nob >= *ksocknal_tunables.ksnd_min_bulk)
311 return SOCKNAL_MATCH_MAY;
313 return SOCKNAL_MATCH_YES;
318 ksocknal_match_tx_v3(ksock_conn_t *conn, ksock_tx_t *tx, int nonblk)
322 if (tx == NULL || tx->tx_lnetmsg == NULL)
323 nob = offsetof(struct ksock_msg, ksm_u);
325 nob = tx->tx_lnetmsg->msg_len + sizeof(struct ksock_msg);
327 switch (conn->ksnc_type) {
329 CERROR("ksnc_type bad: %u\n", conn->ksnc_type);
331 case SOCKLND_CONN_ANY:
332 return SOCKNAL_MATCH_NO;
334 case SOCKLND_CONN_ACK:
336 return SOCKNAL_MATCH_YES;
337 else if (tx == NULL || tx->tx_lnetmsg == NULL)
338 return SOCKNAL_MATCH_MAY;
340 return SOCKNAL_MATCH_NO;
342 case SOCKLND_CONN_BULK_OUT:
344 return SOCKNAL_MATCH_NO;
345 else if (nob < *ksocknal_tunables.ksnd_min_bulk)
346 return SOCKNAL_MATCH_MAY;
348 return SOCKNAL_MATCH_YES;
350 case SOCKLND_CONN_CONTROL:
352 return SOCKNAL_MATCH_NO;
353 else if (nob >= *ksocknal_tunables.ksnd_min_bulk)
354 return SOCKNAL_MATCH_MAY;
356 return SOCKNAL_MATCH_YES;
360 /* (Sink) handle incoming ZC request from sender */
362 ksocknal_handle_zcreq(ksock_conn_t *c, __u64 cookie, int remote)
364 ksock_peer_ni_t *peer_ni = c->ksnc_peer;
369 read_lock(&ksocknal_data.ksnd_global_lock);
371 conn = ksocknal_find_conn_locked(peer_ni, NULL, !!remote);
373 ksock_sched_t *sched = conn->ksnc_scheduler;
375 LASSERT(conn->ksnc_proto->pro_queue_tx_zcack != NULL);
377 spin_lock_bh(&sched->kss_lock);
379 rc = conn->ksnc_proto->pro_queue_tx_zcack(conn, NULL, cookie);
381 spin_unlock_bh(&sched->kss_lock);
383 if (rc) { /* piggybacked */
384 read_unlock(&ksocknal_data.ksnd_global_lock);
389 read_unlock(&ksocknal_data.ksnd_global_lock);
391 /* ACK connection is not ready, or can't piggyback the ACK */
392 tx = ksocknal_alloc_tx_noop(cookie, !!remote);
396 if ((rc = ksocknal_launch_packet(peer_ni->ksnp_ni, tx, peer_ni->ksnp_id)) == 0)
399 ksocknal_free_tx(tx);
403 /* (Sender) handle ZC_ACK from sink */
405 ksocknal_handle_zcack(ksock_conn_t *conn, __u64 cookie1, __u64 cookie2)
407 ksock_peer_ni_t *peer_ni = conn->ksnc_peer;
410 struct list_head zlist = LIST_HEAD_INIT(zlist);
416 count = (cookie1 > cookie2) ? 2 : (cookie2 - cookie1 + 1);
418 if (cookie2 == SOCKNAL_KEEPALIVE_PING &&
419 conn->ksnc_proto == &ksocknal_protocol_v3x) {
420 /* keepalive PING for V3.x, just ignore it */
421 return count == 1 ? 0 : -EPROTO;
424 spin_lock(&peer_ni->ksnp_lock);
426 list_for_each_entry_safe(tx, tmp,
427 &peer_ni->ksnp_zc_req_list, tx_zc_list) {
428 __u64 c = tx->tx_msg.ksm_zc_cookies[0];
430 if (c == cookie1 || c == cookie2 || (cookie1 < c && c < cookie2)) {
431 tx->tx_msg.ksm_zc_cookies[0] = 0;
432 list_del(&tx->tx_zc_list);
433 list_add(&tx->tx_zc_list, &zlist);
440 spin_unlock(&peer_ni->ksnp_lock);
442 while (!list_empty(&zlist)) {
443 tx = list_entry(zlist.next, ksock_tx_t, tx_zc_list);
444 list_del(&tx->tx_zc_list);
445 ksocknal_tx_decref(tx);
448 return count == 0 ? 0 : -EPROTO;
452 ksocknal_send_hello_v1 (ksock_conn_t *conn, struct ksock_hello_msg *hello)
454 struct socket *sock = conn->ksnc_sock;
455 struct lnet_hdr *hdr;
456 struct lnet_magicversion *hmv;
460 CLASSERT(sizeof(struct lnet_magicversion) ==
461 offsetof(struct lnet_hdr, src_nid));
463 LIBCFS_ALLOC(hdr, sizeof(*hdr));
465 CERROR("Can't allocate struct lnet_hdr\n");
469 hmv = (struct lnet_magicversion *)&hdr->dest_nid;
471 /* Re-organize V2.x message header to V1.x (struct lnet_hdr)
472 * header and send out */
473 hmv->magic = cpu_to_le32 (LNET_PROTO_TCP_MAGIC);
474 hmv->version_major = cpu_to_le16 (KSOCK_PROTO_V1_MAJOR);
475 hmv->version_minor = cpu_to_le16 (KSOCK_PROTO_V1_MINOR);
477 if (the_lnet.ln_testprotocompat != 0) {
478 /* single-shot proto check */
480 if ((the_lnet.ln_testprotocompat & 1) != 0) {
481 hmv->version_major++; /* just different! */
482 the_lnet.ln_testprotocompat &= ~1;
484 if ((the_lnet.ln_testprotocompat & 2) != 0) {
485 hmv->magic = LNET_PROTO_MAGIC;
486 the_lnet.ln_testprotocompat &= ~2;
491 hdr->src_nid = cpu_to_le64 (hello->kshm_src_nid);
492 hdr->src_pid = cpu_to_le32 (hello->kshm_src_pid);
493 hdr->type = cpu_to_le32 (LNET_MSG_HELLO);
494 hdr->payload_length = cpu_to_le32 (hello->kshm_nips * sizeof(__u32));
495 hdr->msg.hello.type = cpu_to_le32 (hello->kshm_ctype);
496 hdr->msg.hello.incarnation = cpu_to_le64 (hello->kshm_src_incarnation);
498 rc = lnet_sock_write(sock, hdr, sizeof(*hdr), lnet_acceptor_timeout());
500 CNETERR("Error %d sending HELLO hdr to %pI4h/%d\n",
501 rc, &conn->ksnc_ipaddr, conn->ksnc_port);
505 if (hello->kshm_nips == 0)
508 for (i = 0; i < (int) hello->kshm_nips; i++) {
509 hello->kshm_ips[i] = __cpu_to_le32 (hello->kshm_ips[i]);
512 rc = lnet_sock_write(sock, hello->kshm_ips,
513 hello->kshm_nips * sizeof(__u32),
514 lnet_acceptor_timeout());
516 CNETERR("Error %d sending HELLO payload (%d)"
517 " to %pI4h/%d\n", rc, hello->kshm_nips,
518 &conn->ksnc_ipaddr, conn->ksnc_port);
521 LIBCFS_FREE(hdr, sizeof(*hdr));
527 ksocknal_send_hello_v2 (ksock_conn_t *conn, struct ksock_hello_msg *hello)
529 struct socket *sock = conn->ksnc_sock;
532 hello->kshm_magic = LNET_PROTO_MAGIC;
533 hello->kshm_version = conn->ksnc_proto->pro_version;
535 if (the_lnet.ln_testprotocompat != 0) {
536 /* single-shot proto check */
538 if ((the_lnet.ln_testprotocompat & 1) != 0) {
539 hello->kshm_version++; /* just different! */
540 the_lnet.ln_testprotocompat &= ~1;
545 rc = lnet_sock_write(sock, hello, offsetof(struct ksock_hello_msg, kshm_ips),
546 lnet_acceptor_timeout());
549 CNETERR("Error %d sending HELLO hdr to %pI4h/%d\n",
550 rc, &conn->ksnc_ipaddr, conn->ksnc_port);
554 if (hello->kshm_nips == 0)
557 rc = lnet_sock_write(sock, hello->kshm_ips,
558 hello->kshm_nips * sizeof(__u32),
559 lnet_acceptor_timeout());
561 CNETERR("Error %d sending HELLO payload (%d)"
562 " to %pI4h/%d\n", rc, hello->kshm_nips,
563 &conn->ksnc_ipaddr, conn->ksnc_port);
570 ksocknal_recv_hello_v1(ksock_conn_t *conn, struct ksock_hello_msg *hello,int timeout)
572 struct socket *sock = conn->ksnc_sock;
573 struct lnet_hdr *hdr;
577 LIBCFS_ALLOC(hdr, sizeof(*hdr));
579 CERROR("Can't allocate struct lnet_hdr\n");
583 rc = lnet_sock_read(sock, &hdr->src_nid,
584 sizeof(*hdr) - offsetof(struct lnet_hdr, src_nid),
587 CERROR("Error %d reading rest of HELLO hdr from %pI4h\n",
588 rc, &conn->ksnc_ipaddr);
589 LASSERT(rc < 0 && rc != -EALREADY);
593 /* ...and check we got what we expected */
594 if (hdr->type != cpu_to_le32 (LNET_MSG_HELLO)) {
595 CERROR ("Expecting a HELLO hdr,"
596 " but got type %d from %pI4h\n",
597 le32_to_cpu (hdr->type),
603 hello->kshm_src_nid = le64_to_cpu (hdr->src_nid);
604 hello->kshm_src_pid = le32_to_cpu (hdr->src_pid);
605 hello->kshm_src_incarnation = le64_to_cpu (hdr->msg.hello.incarnation);
606 hello->kshm_ctype = le32_to_cpu (hdr->msg.hello.type);
607 hello->kshm_nips = le32_to_cpu (hdr->payload_length) /
610 if (hello->kshm_nips > LNET_NUM_INTERFACES) {
611 CERROR("Bad nips %d from ip %pI4h\n",
612 hello->kshm_nips, &conn->ksnc_ipaddr);
617 if (hello->kshm_nips == 0)
620 rc = lnet_sock_read(sock, hello->kshm_ips,
621 hello->kshm_nips * sizeof(__u32), timeout);
623 CERROR("Error %d reading IPs from ip %pI4h\n",
624 rc, &conn->ksnc_ipaddr);
625 LASSERT(rc < 0 && rc != -EALREADY);
629 for (i = 0; i < (int) hello->kshm_nips; i++) {
630 hello->kshm_ips[i] = __le32_to_cpu(hello->kshm_ips[i]);
632 if (hello->kshm_ips[i] == 0) {
633 CERROR("Zero IP[%d] from ip %pI4h\n",
634 i, &conn->ksnc_ipaddr);
640 LIBCFS_FREE(hdr, sizeof(*hdr));
646 ksocknal_recv_hello_v2(ksock_conn_t *conn, struct ksock_hello_msg *hello,
649 struct socket *sock = conn->ksnc_sock;
653 if (hello->kshm_magic == LNET_PROTO_MAGIC)
658 rc = lnet_sock_read(sock, &hello->kshm_src_nid,
659 offsetof(struct ksock_hello_msg, kshm_ips) -
660 offsetof(struct ksock_hello_msg, kshm_src_nid),
663 CERROR("Error %d reading HELLO from %pI4h\n",
664 rc, &conn->ksnc_ipaddr);
665 LASSERT(rc < 0 && rc != -EALREADY);
669 if (conn->ksnc_flip) {
670 __swab32s(&hello->kshm_src_pid);
671 __swab64s(&hello->kshm_src_nid);
672 __swab32s(&hello->kshm_dst_pid);
673 __swab64s(&hello->kshm_dst_nid);
674 __swab64s(&hello->kshm_src_incarnation);
675 __swab64s(&hello->kshm_dst_incarnation);
676 __swab32s(&hello->kshm_ctype);
677 __swab32s(&hello->kshm_nips);
680 if (hello->kshm_nips > LNET_NUM_INTERFACES) {
681 CERROR("Bad nips %d from ip %pI4h\n",
682 hello->kshm_nips, &conn->ksnc_ipaddr);
686 if (hello->kshm_nips == 0)
689 rc = lnet_sock_read(sock, hello->kshm_ips,
690 hello->kshm_nips * sizeof(__u32), timeout);
692 CERROR("Error %d reading IPs from ip %pI4h\n",
693 rc, &conn->ksnc_ipaddr);
694 LASSERT(rc < 0 && rc != -EALREADY);
698 for (i = 0; i < (int) hello->kshm_nips; i++) {
700 __swab32s(&hello->kshm_ips[i]);
702 if (hello->kshm_ips[i] == 0) {
703 CERROR("Zero IP[%d] from ip %pI4h\n",
704 i, &conn->ksnc_ipaddr);
713 ksocknal_pack_msg_v1(ksock_tx_t *tx)
715 /* V1.x has no KSOCK_MSG_NOOP */
716 LASSERT(tx->tx_msg.ksm_type != KSOCK_MSG_NOOP);
717 LASSERT(tx->tx_lnetmsg != NULL);
719 tx->tx_iov[0].iov_base = (void *)&tx->tx_lnetmsg->msg_hdr;
720 tx->tx_iov[0].iov_len = sizeof(struct lnet_hdr);
722 tx->tx_nob = tx->tx_lnetmsg->msg_len + sizeof(struct lnet_hdr);
723 tx->tx_resid = tx->tx_nob;
727 ksocknal_pack_msg_v2(ksock_tx_t *tx)
729 tx->tx_iov[0].iov_base = (void *)&tx->tx_msg;
731 if (tx->tx_lnetmsg != NULL) {
732 LASSERT(tx->tx_msg.ksm_type != KSOCK_MSG_NOOP);
734 tx->tx_msg.ksm_u.lnetmsg.ksnm_hdr = tx->tx_lnetmsg->msg_hdr;
735 tx->tx_iov[0].iov_len = sizeof(struct ksock_msg);
736 tx->tx_resid = tx->tx_nob = sizeof(struct ksock_msg) + tx->tx_lnetmsg->msg_len;
738 LASSERT(tx->tx_msg.ksm_type == KSOCK_MSG_NOOP);
740 tx->tx_iov[0].iov_len = offsetof(struct ksock_msg, ksm_u.lnetmsg.ksnm_hdr);
741 tx->tx_resid = tx->tx_nob = offsetof(struct ksock_msg, ksm_u.lnetmsg.ksnm_hdr);
743 /* Don't checksum before start sending, because packet can be piggybacked with ACK */
747 ksocknal_unpack_msg_v1(struct ksock_msg *msg)
750 msg->ksm_type = KSOCK_MSG_LNET;
751 msg->ksm_zc_cookies[0] = msg->ksm_zc_cookies[1] = 0;
755 ksocknal_unpack_msg_v2(struct ksock_msg *msg)
757 return; /* Do nothing */
760 ksock_proto_t ksocknal_protocol_v1x =
762 .pro_version = KSOCK_PROTO_V1,
763 .pro_send_hello = ksocknal_send_hello_v1,
764 .pro_recv_hello = ksocknal_recv_hello_v1,
765 .pro_pack = ksocknal_pack_msg_v1,
766 .pro_unpack = ksocknal_unpack_msg_v1,
767 .pro_queue_tx_msg = ksocknal_queue_tx_msg_v1,
768 .pro_handle_zcreq = NULL,
769 .pro_handle_zcack = NULL,
770 .pro_queue_tx_zcack = NULL,
771 .pro_match_tx = ksocknal_match_tx
774 ksock_proto_t ksocknal_protocol_v2x =
776 .pro_version = KSOCK_PROTO_V2,
777 .pro_send_hello = ksocknal_send_hello_v2,
778 .pro_recv_hello = ksocknal_recv_hello_v2,
779 .pro_pack = ksocknal_pack_msg_v2,
780 .pro_unpack = ksocknal_unpack_msg_v2,
781 .pro_queue_tx_msg = ksocknal_queue_tx_msg_v2,
782 .pro_queue_tx_zcack = ksocknal_queue_tx_zcack_v2,
783 .pro_handle_zcreq = ksocknal_handle_zcreq,
784 .pro_handle_zcack = ksocknal_handle_zcack,
785 .pro_match_tx = ksocknal_match_tx
788 ksock_proto_t ksocknal_protocol_v3x =
790 .pro_version = KSOCK_PROTO_V3,
791 .pro_send_hello = ksocknal_send_hello_v2,
792 .pro_recv_hello = ksocknal_recv_hello_v2,
793 .pro_pack = ksocknal_pack_msg_v2,
794 .pro_unpack = ksocknal_unpack_msg_v2,
795 .pro_queue_tx_msg = ksocknal_queue_tx_msg_v2,
796 .pro_queue_tx_zcack = ksocknal_queue_tx_zcack_v3,
797 .pro_handle_zcreq = ksocknal_handle_zcreq,
798 .pro_handle_zcack = ksocknal_handle_zcack,
799 .pro_match_tx = ksocknal_match_tx_v3