2 * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
4 * Author: Zach Brown <zab@zabbo.net>
5 * Author: Peter J. Braam <braam@clusterfs.com>
6 * Author: Phil Schwan <phil@clusterfs.com>
7 * Author: Eric Barton <eric@bartonsoftware.com>
9 * This file is part of Portals, http://www.sf.net/projects/sandiaportals/
11 * Portals is free software; you can redistribute it and/or
12 * modify it under the terms of version 2 of the GNU General Public
13 * License as published by the Free Software Foundation.
15 * Portals is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with Portals; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
29 * pro_send_hello : send hello message
30 * pro_recv_hello : receive hello message
31 * pro_pack : pack message header
32 * pro_unpack : unpack message header
33 * pro_queue_tx_zcack() : Called holding BH lock: kss_lock
34 * return 1 if ACK is piggybacked, otherwise return 0
35 * pro_queue_tx_msg() : Called holding BH lock: kss_lock
36 * return the ACK that piggybacked by my message, or NULL
37 * pro_handle_zcreq() : handler of incoming ZC-REQ
38 * pro_handle_zcack() : handler of incoming ZC-ACK
39 * pro_match_tx() : Called holding glock
43 ksocknal_queue_tx_msg_v1(ksock_conn_t *conn, ksock_tx_t *tx_msg)
45 /* V1.x, just enqueue it */
46 cfs_list_add_tail(&tx_msg->tx_list, &conn->ksnc_tx_queue);
51 ksocknal_next_tx_carrier(ksock_conn_t *conn)
53 ksock_tx_t *tx = conn->ksnc_tx_carrier;
55 /* Called holding BH lock: conn->ksnc_scheduler->kss_lock */
56 LASSERT (!cfs_list_empty(&conn->ksnc_tx_queue));
59 /* Next TX that can carry ZC-ACK or LNet message */
60 if (tx->tx_list.next == &conn->ksnc_tx_queue) {
61 /* no more packets queued */
62 conn->ksnc_tx_carrier = NULL;
64 conn->ksnc_tx_carrier = cfs_list_entry(tx->tx_list.next,
66 LASSERT (conn->ksnc_tx_carrier->tx_msg.ksm_type == tx->tx_msg.ksm_type);
71 ksocknal_queue_tx_zcack_v2(ksock_conn_t *conn,
72 ksock_tx_t *tx_ack, __u64 cookie)
74 ksock_tx_t *tx = conn->ksnc_tx_carrier;
76 LASSERT (tx_ack == NULL ||
77 tx_ack->tx_msg.ksm_type == KSOCK_MSG_NOOP);
80 * Enqueue or piggyback tx_ack / cookie
81 * . no tx can piggyback cookie of tx_ack (or cookie), just
82 * enqueue the tx_ack (if tx_ack != NUL) and return NULL.
83 * . There is tx can piggyback cookie of tx_ack (or cookie),
84 * piggyback the cookie and return the tx.
88 cfs_list_add_tail(&tx_ack->tx_list,
89 &conn->ksnc_tx_queue);
90 conn->ksnc_tx_carrier = tx_ack;
95 if (tx->tx_msg.ksm_type == KSOCK_MSG_NOOP) {
96 /* tx is noop zc-ack, can't piggyback zc-ack cookie */
98 cfs_list_add_tail(&tx_ack->tx_list,
99 &conn->ksnc_tx_queue);
103 LASSERT(tx->tx_msg.ksm_type == KSOCK_MSG_LNET);
104 LASSERT(tx->tx_msg.ksm_zc_cookies[1] == 0);
107 cookie = tx_ack->tx_msg.ksm_zc_cookies[1];
109 /* piggyback the zc-ack cookie */
110 tx->tx_msg.ksm_zc_cookies[1] = cookie;
111 /* move on to the next TX which can carry cookie */
112 ksocknal_next_tx_carrier(conn);
118 ksocknal_queue_tx_msg_v2(ksock_conn_t *conn, ksock_tx_t *tx_msg)
120 ksock_tx_t *tx = conn->ksnc_tx_carrier;
124 * . If there is no NOOP on the connection, just enqueue
125 * tx_msg and return NULL
126 * . If there is NOOP on the connection, piggyback the cookie
127 * and replace the NOOP tx, and return the NOOP tx.
129 if (tx == NULL) { /* nothing on queue */
130 cfs_list_add_tail(&tx_msg->tx_list, &conn->ksnc_tx_queue);
131 conn->ksnc_tx_carrier = tx_msg;
135 if (tx->tx_msg.ksm_type == KSOCK_MSG_LNET) { /* nothing to carry */
136 cfs_list_add_tail(&tx_msg->tx_list, &conn->ksnc_tx_queue);
140 LASSERT (tx->tx_msg.ksm_type == KSOCK_MSG_NOOP);
142 /* There is a noop zc-ack can be piggybacked */
143 tx_msg->tx_msg.ksm_zc_cookies[1] = tx->tx_msg.ksm_zc_cookies[1];
144 ksocknal_next_tx_carrier(conn);
146 /* use new_tx to replace the noop zc-ack packet */
147 cfs_list_add(&tx_msg->tx_list, &tx->tx_list);
148 cfs_list_del(&tx->tx_list);
154 ksocknal_queue_tx_zcack_v3(ksock_conn_t *conn,
155 ksock_tx_t *tx_ack, __u64 cookie)
159 if (conn->ksnc_type != SOCKLND_CONN_ACK)
160 return ksocknal_queue_tx_zcack_v2(conn, tx_ack, cookie);
162 /* non-blocking ZC-ACK (to router) */
163 LASSERT (tx_ack == NULL ||
164 tx_ack->tx_msg.ksm_type == KSOCK_MSG_NOOP);
166 if ((tx = conn->ksnc_tx_carrier) == NULL) {
167 if (tx_ack != NULL) {
168 cfs_list_add_tail(&tx_ack->tx_list,
169 &conn->ksnc_tx_queue);
170 conn->ksnc_tx_carrier = tx_ack;
175 /* conn->ksnc_tx_carrier != NULL */
178 cookie = tx_ack->tx_msg.ksm_zc_cookies[1];
180 if (cookie == SOCKNAL_KEEPALIVE_PING) /* ignore keepalive PING */
183 if (tx->tx_msg.ksm_zc_cookies[1] == SOCKNAL_KEEPALIVE_PING) {
184 /* replace the keepalive PING with a real ACK */
185 LASSERT (tx->tx_msg.ksm_zc_cookies[0] == 0);
186 tx->tx_msg.ksm_zc_cookies[1] = cookie;
190 if (cookie == tx->tx_msg.ksm_zc_cookies[0] ||
191 cookie == tx->tx_msg.ksm_zc_cookies[1]) {
192 CWARN("%s: duplicated ZC cookie: "LPU64"\n",
193 libcfs_id2str(conn->ksnc_peer->ksnp_id), cookie);
194 return 1; /* XXX return error in the future */
197 if (tx->tx_msg.ksm_zc_cookies[0] == 0) {
198 /* NOOP tx has only one ZC-ACK cookie, can carry at least one more */
199 if (tx->tx_msg.ksm_zc_cookies[1] > cookie) {
200 tx->tx_msg.ksm_zc_cookies[0] = tx->tx_msg.ksm_zc_cookies[1];
201 tx->tx_msg.ksm_zc_cookies[1] = cookie;
203 tx->tx_msg.ksm_zc_cookies[0] = cookie;
206 if (tx->tx_msg.ksm_zc_cookies[0] - tx->tx_msg.ksm_zc_cookies[1] > 2) {
207 /* not likely to carry more ACKs, skip it to simplify logic */
208 ksocknal_next_tx_carrier(conn);
214 /* takes two or more cookies already */
216 if (tx->tx_msg.ksm_zc_cookies[0] > tx->tx_msg.ksm_zc_cookies[1]) {
219 /* two seperated cookies: (a+2, a) or (a+1, a) */
220 LASSERT (tx->tx_msg.ksm_zc_cookies[0] -
221 tx->tx_msg.ksm_zc_cookies[1] <= 2);
223 if (tx->tx_msg.ksm_zc_cookies[0] -
224 tx->tx_msg.ksm_zc_cookies[1] == 2) {
225 if (cookie == tx->tx_msg.ksm_zc_cookies[1] + 1)
227 } else if (cookie == tx->tx_msg.ksm_zc_cookies[1] - 1) {
228 tmp = tx->tx_msg.ksm_zc_cookies[1];
229 } else if (cookie == tx->tx_msg.ksm_zc_cookies[0] + 1) {
230 tmp = tx->tx_msg.ksm_zc_cookies[0];
234 /* range of cookies */
235 tx->tx_msg.ksm_zc_cookies[0] = tmp - 1;
236 tx->tx_msg.ksm_zc_cookies[1] = tmp + 1;
241 /* ksm_zc_cookies[0] < ksm_zc_cookies[1], it is range of cookies */
242 if (cookie >= tx->tx_msg.ksm_zc_cookies[0] &&
243 cookie <= tx->tx_msg.ksm_zc_cookies[1]) {
244 CWARN("%s: duplicated ZC cookie: "LPU64"\n",
245 libcfs_id2str(conn->ksnc_peer->ksnp_id), cookie);
246 return 1; /* XXX: return error in the future */
249 if (cookie == tx->tx_msg.ksm_zc_cookies[1] + 1) {
250 tx->tx_msg.ksm_zc_cookies[1] = cookie;
254 if (cookie == tx->tx_msg.ksm_zc_cookies[0] - 1) {
255 tx->tx_msg.ksm_zc_cookies[0] = cookie;
260 /* failed to piggyback ZC-ACK */
261 if (tx_ack != NULL) {
262 cfs_list_add_tail(&tx_ack->tx_list, &conn->ksnc_tx_queue);
263 /* the next tx can piggyback at least 1 ACK */
264 ksocknal_next_tx_carrier(conn);
271 ksocknal_match_tx(ksock_conn_t *conn, ksock_tx_t *tx, int nonblk)
275 #if SOCKNAL_VERSION_DEBUG
276 if (!*ksocknal_tunables.ksnd_typed_conns)
277 return SOCKNAL_MATCH_YES;
280 if (tx == NULL || tx->tx_lnetmsg == NULL) {
282 nob = offsetof(ksock_msg_t, ksm_u);
284 nob = tx->tx_lnetmsg->msg_len +
285 ((conn->ksnc_proto == &ksocknal_protocol_v1x) ?
286 sizeof(lnet_hdr_t) : sizeof(ksock_msg_t));
289 /* default checking for typed connection */
290 switch (conn->ksnc_type) {
292 CERROR("ksnc_type bad: %u\n", conn->ksnc_type);
294 case SOCKLND_CONN_ANY:
295 return SOCKNAL_MATCH_YES;
297 case SOCKLND_CONN_BULK_IN:
298 return SOCKNAL_MATCH_MAY;
300 case SOCKLND_CONN_BULK_OUT:
301 if (nob < *ksocknal_tunables.ksnd_min_bulk)
302 return SOCKNAL_MATCH_MAY;
304 return SOCKNAL_MATCH_YES;
306 case SOCKLND_CONN_CONTROL:
307 if (nob >= *ksocknal_tunables.ksnd_min_bulk)
308 return SOCKNAL_MATCH_MAY;
310 return SOCKNAL_MATCH_YES;
315 ksocknal_match_tx_v3(ksock_conn_t *conn, ksock_tx_t *tx, int nonblk)
319 if (tx == NULL || tx->tx_lnetmsg == NULL)
320 nob = offsetof(ksock_msg_t, ksm_u);
322 nob = tx->tx_lnetmsg->msg_len + sizeof(ksock_msg_t);
324 switch (conn->ksnc_type) {
326 CERROR("ksnc_type bad: %u\n", conn->ksnc_type);
328 case SOCKLND_CONN_ANY:
329 return SOCKNAL_MATCH_NO;
331 case SOCKLND_CONN_ACK:
333 return SOCKNAL_MATCH_YES;
334 else if (tx == NULL || tx->tx_lnetmsg == NULL)
335 return SOCKNAL_MATCH_MAY;
337 return SOCKNAL_MATCH_NO;
339 case SOCKLND_CONN_BULK_OUT:
341 return SOCKNAL_MATCH_NO;
342 else if (nob < *ksocknal_tunables.ksnd_min_bulk)
343 return SOCKNAL_MATCH_MAY;
345 return SOCKNAL_MATCH_YES;
347 case SOCKLND_CONN_CONTROL:
349 return SOCKNAL_MATCH_NO;
350 else if (nob >= *ksocknal_tunables.ksnd_min_bulk)
351 return SOCKNAL_MATCH_MAY;
353 return SOCKNAL_MATCH_YES;
357 /* (Sink) handle incoming ZC request from sender */
359 ksocknal_handle_zcreq(ksock_conn_t *c, __u64 cookie, int remote)
361 ksock_peer_t *peer = c->ksnc_peer;
366 cfs_read_lock (&ksocknal_data.ksnd_global_lock);
368 conn = ksocknal_find_conn_locked(peer, NULL, !!remote);
370 ksock_sched_t *sched = conn->ksnc_scheduler;
372 LASSERT (conn->ksnc_proto->pro_queue_tx_zcack != NULL);
374 cfs_spin_lock_bh (&sched->kss_lock);
376 rc = conn->ksnc_proto->pro_queue_tx_zcack(conn, NULL, cookie);
378 cfs_spin_unlock_bh (&sched->kss_lock);
380 if (rc) { /* piggybacked */
381 cfs_read_unlock (&ksocknal_data.ksnd_global_lock);
386 cfs_read_unlock (&ksocknal_data.ksnd_global_lock);
388 /* ACK connection is not ready, or can't piggyback the ACK */
389 tx = ksocknal_alloc_tx_noop(cookie, !!remote);
393 if ((rc = ksocknal_launch_packet(peer->ksnp_ni, tx, peer->ksnp_id)) == 0)
396 ksocknal_free_tx(tx);
400 /* (Sender) handle ZC_ACK from sink */
402 ksocknal_handle_zcack(ksock_conn_t *conn, __u64 cookie1, __u64 cookie2)
404 ksock_peer_t *peer = conn->ksnc_peer;
407 CFS_LIST_HEAD (zlist);
413 count = (cookie1 > cookie2) ? 2 : (cookie2 - cookie1 + 1);
415 if (cookie2 == SOCKNAL_KEEPALIVE_PING &&
416 conn->ksnc_proto == &ksocknal_protocol_v3x) {
417 /* keepalive PING for V3.x, just ignore it */
418 return count == 1 ? 0 : -EPROTO;
421 cfs_spin_lock(&peer->ksnp_lock);
423 cfs_list_for_each_entry_safe(tx, tmp,
424 &peer->ksnp_zc_req_list, tx_zc_list) {
425 __u64 c = tx->tx_msg.ksm_zc_cookies[0];
427 if (c == cookie1 || c == cookie2 || (cookie1 < c && c < cookie2)) {
428 tx->tx_msg.ksm_zc_cookies[0] = 0;
429 cfs_list_del(&tx->tx_zc_list);
430 cfs_list_add(&tx->tx_zc_list, &zlist);
437 cfs_spin_unlock(&peer->ksnp_lock);
439 while (!cfs_list_empty(&zlist)) {
440 tx = cfs_list_entry(zlist.next, ksock_tx_t, tx_zc_list);
441 cfs_list_del(&tx->tx_zc_list);
442 ksocknal_tx_decref(tx);
445 return count == 0 ? 0 : -EPROTO;
449 ksocknal_send_hello_v1 (ksock_conn_t *conn, ksock_hello_msg_t *hello)
451 cfs_socket_t *sock = conn->ksnc_sock;
453 lnet_magicversion_t *hmv;
457 CLASSERT(sizeof(lnet_magicversion_t) == offsetof(lnet_hdr_t, src_nid));
459 LIBCFS_ALLOC(hdr, sizeof(*hdr));
461 CERROR("Can't allocate lnet_hdr_t\n");
465 hmv = (lnet_magicversion_t *)&hdr->dest_nid;
467 /* Re-organize V2.x message header to V1.x (lnet_hdr_t)
468 * header and send out */
469 hmv->magic = cpu_to_le32 (LNET_PROTO_TCP_MAGIC);
470 hmv->version_major = cpu_to_le16 (KSOCK_PROTO_V1_MAJOR);
471 hmv->version_minor = cpu_to_le16 (KSOCK_PROTO_V1_MINOR);
473 if (the_lnet.ln_testprotocompat != 0) {
474 /* single-shot proto check */
476 if ((the_lnet.ln_testprotocompat & 1) != 0) {
477 hmv->version_major++; /* just different! */
478 the_lnet.ln_testprotocompat &= ~1;
480 if ((the_lnet.ln_testprotocompat & 2) != 0) {
481 hmv->magic = LNET_PROTO_MAGIC;
482 the_lnet.ln_testprotocompat &= ~2;
487 hdr->src_nid = cpu_to_le64 (hello->kshm_src_nid);
488 hdr->src_pid = cpu_to_le32 (hello->kshm_src_pid);
489 hdr->type = cpu_to_le32 (LNET_MSG_HELLO);
490 hdr->payload_length = cpu_to_le32 (hello->kshm_nips * sizeof(__u32));
491 hdr->msg.hello.type = cpu_to_le32 (hello->kshm_ctype);
492 hdr->msg.hello.incarnation = cpu_to_le64 (hello->kshm_src_incarnation);
494 rc = libcfs_sock_write(sock, hdr, sizeof(*hdr),lnet_acceptor_timeout());
497 CNETERR("Error %d sending HELLO hdr to %u.%u.%u.%u/%d\n",
498 rc, HIPQUAD(conn->ksnc_ipaddr), conn->ksnc_port);
502 if (hello->kshm_nips == 0)
505 for (i = 0; i < (int) hello->kshm_nips; i++) {
506 hello->kshm_ips[i] = __cpu_to_le32 (hello->kshm_ips[i]);
509 rc = libcfs_sock_write(sock, hello->kshm_ips,
510 hello->kshm_nips * sizeof(__u32),
511 lnet_acceptor_timeout());
513 CNETERR("Error %d sending HELLO payload (%d)"
514 " to %u.%u.%u.%u/%d\n", rc, hello->kshm_nips,
515 HIPQUAD(conn->ksnc_ipaddr), conn->ksnc_port);
518 LIBCFS_FREE(hdr, sizeof(*hdr));
524 ksocknal_send_hello_v2 (ksock_conn_t *conn, ksock_hello_msg_t *hello)
526 cfs_socket_t *sock = conn->ksnc_sock;
529 hello->kshm_magic = LNET_PROTO_MAGIC;
530 hello->kshm_version = conn->ksnc_proto->pro_version;
532 if (the_lnet.ln_testprotocompat != 0) {
533 /* single-shot proto check */
535 if ((the_lnet.ln_testprotocompat & 1) != 0) {
536 hello->kshm_version++; /* just different! */
537 the_lnet.ln_testprotocompat &= ~1;
542 rc = libcfs_sock_write(sock, hello, offsetof(ksock_hello_msg_t, kshm_ips),
543 lnet_acceptor_timeout());
546 CNETERR("Error %d sending HELLO hdr to %u.%u.%u.%u/%d\n",
547 rc, HIPQUAD(conn->ksnc_ipaddr), conn->ksnc_port);
551 if (hello->kshm_nips == 0)
554 rc = libcfs_sock_write(sock, hello->kshm_ips,
555 hello->kshm_nips * sizeof(__u32),
556 lnet_acceptor_timeout());
558 CNETERR("Error %d sending HELLO payload (%d)"
559 " to %u.%u.%u.%u/%d\n", rc, hello->kshm_nips,
560 HIPQUAD(conn->ksnc_ipaddr), conn->ksnc_port);
567 ksocknal_recv_hello_v1(ksock_conn_t *conn, ksock_hello_msg_t *hello,int timeout)
569 cfs_socket_t *sock = conn->ksnc_sock;
574 LIBCFS_ALLOC(hdr, sizeof(*hdr));
576 CERROR("Can't allocate lnet_hdr_t\n");
580 rc = libcfs_sock_read(sock, &hdr->src_nid,
581 sizeof (*hdr) - offsetof (lnet_hdr_t, src_nid),
584 CERROR ("Error %d reading rest of HELLO hdr from %u.%u.%u.%u\n",
585 rc, HIPQUAD(conn->ksnc_ipaddr));
586 LASSERT (rc < 0 && rc != -EALREADY);
590 /* ...and check we got what we expected */
591 if (hdr->type != cpu_to_le32 (LNET_MSG_HELLO)) {
592 CERROR ("Expecting a HELLO hdr,"
593 " but got type %d from %u.%u.%u.%u\n",
594 le32_to_cpu (hdr->type),
595 HIPQUAD(conn->ksnc_ipaddr));
600 hello->kshm_src_nid = le64_to_cpu (hdr->src_nid);
601 hello->kshm_src_pid = le32_to_cpu (hdr->src_pid);
602 hello->kshm_src_incarnation = le64_to_cpu (hdr->msg.hello.incarnation);
603 hello->kshm_ctype = le32_to_cpu (hdr->msg.hello.type);
604 hello->kshm_nips = le32_to_cpu (hdr->payload_length) /
607 if (hello->kshm_nips > LNET_MAX_INTERFACES) {
608 CERROR("Bad nips %d from ip %u.%u.%u.%u\n",
609 hello->kshm_nips, HIPQUAD(conn->ksnc_ipaddr));
614 if (hello->kshm_nips == 0)
617 rc = libcfs_sock_read(sock, hello->kshm_ips,
618 hello->kshm_nips * sizeof(__u32), timeout);
620 CERROR ("Error %d reading IPs from ip %u.%u.%u.%u\n",
621 rc, HIPQUAD(conn->ksnc_ipaddr));
622 LASSERT (rc < 0 && rc != -EALREADY);
626 for (i = 0; i < (int) hello->kshm_nips; i++) {
627 hello->kshm_ips[i] = __le32_to_cpu(hello->kshm_ips[i]);
629 if (hello->kshm_ips[i] == 0) {
630 CERROR("Zero IP[%d] from ip %u.%u.%u.%u\n",
631 i, HIPQUAD(conn->ksnc_ipaddr));
637 LIBCFS_FREE(hdr, sizeof(*hdr));
643 ksocknal_recv_hello_v2 (ksock_conn_t *conn, ksock_hello_msg_t *hello, int timeout)
645 cfs_socket_t *sock = conn->ksnc_sock;
649 if (hello->kshm_magic == LNET_PROTO_MAGIC)
654 rc = libcfs_sock_read(sock, &hello->kshm_src_nid,
655 offsetof(ksock_hello_msg_t, kshm_ips) -
656 offsetof(ksock_hello_msg_t, kshm_src_nid),
659 CERROR ("Error %d reading HELLO from %u.%u.%u.%u\n",
660 rc, HIPQUAD(conn->ksnc_ipaddr));
661 LASSERT (rc < 0 && rc != -EALREADY);
665 if (conn->ksnc_flip) {
666 __swab32s(&hello->kshm_src_pid);
667 __swab64s(&hello->kshm_src_nid);
668 __swab32s(&hello->kshm_dst_pid);
669 __swab64s(&hello->kshm_dst_nid);
670 __swab64s(&hello->kshm_src_incarnation);
671 __swab64s(&hello->kshm_dst_incarnation);
672 __swab32s(&hello->kshm_ctype);
673 __swab32s(&hello->kshm_nips);
676 if (hello->kshm_nips > LNET_MAX_INTERFACES) {
677 CERROR("Bad nips %d from ip %u.%u.%u.%u\n",
678 hello->kshm_nips, HIPQUAD(conn->ksnc_ipaddr));
682 if (hello->kshm_nips == 0)
685 rc = libcfs_sock_read(sock, hello->kshm_ips,
686 hello->kshm_nips * sizeof(__u32), timeout);
688 CERROR ("Error %d reading IPs from ip %u.%u.%u.%u\n",
689 rc, HIPQUAD(conn->ksnc_ipaddr));
690 LASSERT (rc < 0 && rc != -EALREADY);
694 for (i = 0; i < (int) hello->kshm_nips; i++) {
696 __swab32s(&hello->kshm_ips[i]);
698 if (hello->kshm_ips[i] == 0) {
699 CERROR("Zero IP[%d] from ip %u.%u.%u.%u\n",
700 i, HIPQUAD(conn->ksnc_ipaddr));
709 ksocknal_pack_msg_v1(ksock_tx_t *tx)
711 /* V1.x has no KSOCK_MSG_NOOP */
712 LASSERT(tx->tx_msg.ksm_type != KSOCK_MSG_NOOP);
713 LASSERT(tx->tx_lnetmsg != NULL);
715 tx->tx_iov[0].iov_base = (void *)&tx->tx_lnetmsg->msg_hdr;
716 tx->tx_iov[0].iov_len = sizeof(lnet_hdr_t);
718 tx->tx_resid = tx->tx_nob = tx->tx_lnetmsg->msg_len + sizeof(lnet_hdr_t);
722 ksocknal_pack_msg_v2(ksock_tx_t *tx)
724 tx->tx_iov[0].iov_base = (void *)&tx->tx_msg;
726 if (tx->tx_lnetmsg != NULL) {
727 LASSERT(tx->tx_msg.ksm_type != KSOCK_MSG_NOOP);
729 tx->tx_msg.ksm_u.lnetmsg.ksnm_hdr = tx->tx_lnetmsg->msg_hdr;
730 tx->tx_iov[0].iov_len = sizeof(ksock_msg_t);
731 tx->tx_resid = tx->tx_nob = sizeof(ksock_msg_t) + tx->tx_lnetmsg->msg_len;
733 LASSERT(tx->tx_msg.ksm_type == KSOCK_MSG_NOOP);
735 tx->tx_iov[0].iov_len = offsetof(ksock_msg_t, ksm_u.lnetmsg.ksnm_hdr);
736 tx->tx_resid = tx->tx_nob = offsetof(ksock_msg_t, ksm_u.lnetmsg.ksnm_hdr);
738 /* Don't checksum before start sending, because packet can be piggybacked with ACK */
742 ksocknal_unpack_msg_v1(ksock_msg_t *msg)
745 msg->ksm_type = KSOCK_MSG_LNET;
746 msg->ksm_zc_cookies[0] = msg->ksm_zc_cookies[1] = 0;
750 ksocknal_unpack_msg_v2(ksock_msg_t *msg)
752 return; /* Do nothing */
755 ksock_proto_t ksocknal_protocol_v1x =
757 .pro_version = KSOCK_PROTO_V1,
758 .pro_send_hello = ksocknal_send_hello_v1,
759 .pro_recv_hello = ksocknal_recv_hello_v1,
760 .pro_pack = ksocknal_pack_msg_v1,
761 .pro_unpack = ksocknal_unpack_msg_v1,
762 .pro_queue_tx_msg = ksocknal_queue_tx_msg_v1,
763 .pro_handle_zcreq = NULL,
764 .pro_handle_zcack = NULL,
765 .pro_queue_tx_zcack = NULL,
766 .pro_match_tx = ksocknal_match_tx
769 ksock_proto_t ksocknal_protocol_v2x =
771 .pro_version = KSOCK_PROTO_V2,
772 .pro_send_hello = ksocknal_send_hello_v2,
773 .pro_recv_hello = ksocknal_recv_hello_v2,
774 .pro_pack = ksocknal_pack_msg_v2,
775 .pro_unpack = ksocknal_unpack_msg_v2,
776 .pro_queue_tx_msg = ksocknal_queue_tx_msg_v2,
777 .pro_queue_tx_zcack = ksocknal_queue_tx_zcack_v2,
778 .pro_handle_zcreq = ksocknal_handle_zcreq,
779 .pro_handle_zcack = ksocknal_handle_zcack,
780 .pro_match_tx = ksocknal_match_tx
783 ksock_proto_t ksocknal_protocol_v3x =
785 .pro_version = KSOCK_PROTO_V3,
786 .pro_send_hello = ksocknal_send_hello_v2,
787 .pro_recv_hello = ksocknal_recv_hello_v2,
788 .pro_pack = ksocknal_pack_msg_v2,
789 .pro_unpack = ksocknal_unpack_msg_v2,
790 .pro_queue_tx_msg = ksocknal_queue_tx_msg_v2,
791 .pro_queue_tx_zcack = ksocknal_queue_tx_zcack_v3,
792 .pro_handle_zcreq = ksocknal_handle_zcreq,
793 .pro_handle_zcack = ksocknal_handle_zcack,
794 .pro_match_tx = ksocknal_match_tx_v3