2 * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
4 * Copyright (c) 2011, 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, http://www.lustre.org
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.
28 #ifndef _SOCKLND_SOCKLND_H_
29 #define _SOCKLND_SOCKLND_H_
31 #define DEBUG_PORTAL_ALLOC
32 #define DEBUG_SUBSYSTEM S_LND
34 #include <linux/crc32.h>
35 #include <linux/errno.h>
37 #include <linux/init.h>
38 #include <linux/kernel.h>
39 #include <linux/kthread.h>
40 #include <linux/kmod.h>
41 #include <linux/list.h>
43 #include <linux/module.h>
44 #include <linux/pagemap.h>
45 #include <linux/refcount.h>
46 #include <linux/stat.h>
47 #include <linux/string.h>
48 #include <linux/syscalls.h>
49 #include <linux/sysctl.h>
50 #include <linux/uio.h>
51 #include <linux/unistd.h>
52 #include <linux/hashtable.h>
56 #include <lnet/lib-lnet.h>
57 #include <lnet/socklnd.h>
59 #include <libcfs/linux/linux-net.h>
61 #ifndef NETIF_F_CSUM_MASK
62 # define NETIF_F_CSUM_MASK NETIF_F_ALL_CSUM
65 /* assume one thread for each connection type */
66 #define SOCKNAL_NSCHEDS 3
67 #define SOCKNAL_NSCHEDS_HIGH (SOCKNAL_NSCHEDS << 1)
69 #define SOCKNAL_PEER_HASH_BITS 7 /* log2 of # peer_ni lists */
70 #define SOCKNAL_INSANITY_RECONN 5000 /* connd is trying on reconn infinitely */
71 #define SOCKNAL_ENOMEM_RETRY 1 /* seconds between retries */
73 #define SOCKNAL_SINGLE_FRAG_TX 0 /* disable multi-fragment sends */
74 #define SOCKNAL_SINGLE_FRAG_RX 0 /* disable multi-fragment receives */
76 #define SOCKNAL_VERSION_DEBUG 0 /* enable protocol version debugging */
78 /* risk kmap deadlock on multi-frag I/O (backs off to single-frag if disabled).
79 * no risk if we're not running on a CONFIG_HIGHMEM platform. */
81 # define SOCKNAL_RISK_KMAP_DEADLOCK 0
83 # define SOCKNAL_RISK_KMAP_DEADLOCK 1
86 /* per scheduler state */
90 /* conn waiting to be written */
91 struct list_head kss_rx_conns;
92 struct list_head kss_tx_conns;
93 /* zombie noop tx list */
94 struct list_head kss_zombie_noop_txs;
95 /* where scheduler sleeps */
96 wait_queue_head_t kss_waitq;
97 /* # connections assigned to this scheduler */
99 /* max allowed threads */
100 int kss_nthreads_max;
101 /* number of threads */
107 #define KSOCK_CPT_SHIFT 16
108 #define KSOCK_THREAD_ID(cpt, sid) (((cpt) << KSOCK_CPT_SHIFT) | (sid))
109 #define KSOCK_THREAD_CPT(id) ((id) >> KSOCK_CPT_SHIFT)
110 #define KSOCK_THREAD_SID(id) ((id) & ((1UL << KSOCK_CPT_SHIFT) - 1))
112 struct ksock_interface { /* in-use interface */
113 int ksni_index; /* Linux interface index */
114 struct sockaddr_storage ksni_addr; /* interface's address */
115 __u32 ksni_netmask; /* interface's network mask */
116 int ksni_nroutes; /* # routes using (active) */
117 int ksni_npeers; /* # peers using (passive) */
118 char ksni_name[IFNAMSIZ]; /* interface name */
121 struct ksock_tunables {
122 /* "stuck" socket timeout (seconds) */
124 /* # scheduler threads in each pool while starting */
126 int *ksnd_nconnds; /* # connection daemons */
127 int *ksnd_nconnds_max; /* max # connection daemons */
128 int *ksnd_min_reconnectms; /* first connection retry after (ms)... */
129 int *ksnd_max_reconnectms; /* ...exponentially increasing to this */
130 int *ksnd_eager_ack; /* make TCP ack eagerly? */
131 int *ksnd_typed_conns; /* drive sockets by type? */
132 int *ksnd_min_bulk; /* smallest "large" message */
133 int *ksnd_tx_buffer_size; /* socket tx buffer size */
134 int *ksnd_rx_buffer_size; /* socket rx buffer size */
135 int *ksnd_nagle; /* enable NAGLE? */
136 int *ksnd_round_robin; /* round robin for multiple interfaces */
137 int *ksnd_keepalive; /* # secs for sending keepalive NOOP */
138 int *ksnd_keepalive_idle; /* # idle secs before 1st probe */
139 int *ksnd_keepalive_count; /* # probes */
140 int *ksnd_keepalive_intvl; /* time between probes */
141 int *ksnd_credits; /* # concurrent sends */
142 int *ksnd_peertxcredits; /* # concurrent sends to 1 peer_ni */
143 int *ksnd_peerrtrcredits; /* # per-peer_ni router buffer credits */
144 int *ksnd_peertimeout; /* seconds to consider peer_ni dead */
145 int *ksnd_enable_csum; /* enable check sum */
146 int *ksnd_inject_csum_error; /* set non-zero to inject checksum error */
147 int *ksnd_nonblk_zcack; /* always send zc-ack on non-blocking connection */
148 unsigned int *ksnd_zc_min_payload; /* minimum zero copy payload size */
149 int *ksnd_zc_recv; /* enable ZC receive (for Chelsio TOE) */
150 int *ksnd_zc_recv_min_nfrags; /* minimum # of fragments to enable ZC receive */
151 int *ksnd_irq_affinity; /* enable IRQ affinity? */
152 #ifdef SOCKNAL_BACKOFF
153 int *ksnd_backoff_init; /* initial TCP backoff */
154 int *ksnd_backoff_max; /* maximum TCP backoff */
156 #if SOCKNAL_VERSION_DEBUG
157 int *ksnd_protocol; /* protocol version */
159 int *ksnd_conns_per_peer; /* for typed mode, yields:
160 * 1 + 2*conns_per_peer total
162 * conns_per_peer total
167 __u64 ksnn_incarnation; /* my epoch */
168 struct list_head ksnn_list; /* chain on global list */
169 atomic_t ksnn_npeers; /* # peers */
170 struct ksock_interface ksnn_interface; /* IP interface */
171 struct lnet_ni *ksnn_ni;
173 /* When the ksock_net is shut down, this (negative) bias is added to
174 * ksnn_npeers, which prevents new peers from being added.
176 #define SOCKNAL_SHUTDOWN_BIAS (INT_MIN+1)
179 #define SOCKNAL_CONND_TIMEOUT 120
180 /** reserved thread for accepting & creating new connd */
181 #define SOCKNAL_CONND_RESV 1
183 struct ksock_nal_data {
184 int ksnd_init; /* initialisation state */
185 int ksnd_nnets; /* # networks set up */
186 struct list_head ksnd_nets; /* list of nets */
187 /* stabilize peer_ni/conn ops */
188 rwlock_t ksnd_global_lock;
189 /* hash table of all my known peers */
190 DECLARE_HASHTABLE(ksnd_peers, SOCKNAL_PEER_HASH_BITS);
192 atomic_t ksnd_nthreads; /* # live threads */
193 int ksnd_shuttingdown; /* tell threads to exit */
194 /* schedulers information */
195 struct ksock_sched **ksnd_schedulers;
197 atomic_t ksnd_nactive_txs; /* #active txs */
199 /* conns to close: reaper_lock*/
200 struct list_head ksnd_deathrow_conns;
201 /* conns to free: reaper_lock */
202 struct list_head ksnd_zombie_conns;
203 /* conns to retry: reaper_lock*/
204 struct list_head ksnd_enomem_conns;
205 /* reaper sleeps here */
206 wait_queue_head_t ksnd_reaper_waitq;
207 /* when reaper will wake */
208 time64_t ksnd_reaper_waketime;
210 spinlock_t ksnd_reaper_lock;
212 int ksnd_enomem_tx; /* test ENOMEM sender */
213 int ksnd_stall_tx; /* test sluggish sender */
214 int ksnd_stall_rx; /* test sluggish receiver */
216 /* incoming connection requests */
217 struct list_head ksnd_connd_connreqs;
218 /* routes waiting to be connected */
219 struct list_head ksnd_connd_routes;
220 /* connds sleep here */
221 wait_queue_head_t ksnd_connd_waitq;
222 /* # connds connecting */
223 int ksnd_connd_connecting;
224 /** time stamp of the last failed connecting attempt */
225 time64_t ksnd_connd_failed_stamp;
226 /** # starting connd */
227 unsigned ksnd_connd_starting;
228 /** time stamp of the last starting connd */
229 time64_t ksnd_connd_starting_stamp;
230 /** # running connd */
231 unsigned ksnd_connd_running;
233 spinlock_t ksnd_connd_lock;
235 /* list head for freed noop tx */
236 struct list_head ksnd_idle_noop_txs;
237 /* serialise, g_lock unsafe */
238 spinlock_t ksnd_tx_lock;
241 #define SOCKNAL_INIT_NOTHING 0
242 #define SOCKNAL_INIT_DATA 1
243 #define SOCKNAL_INIT_ALL 2
245 /* A packet just assembled for transmission is represented by 1
246 * struct iovec fragment - the portals header - followed by 0
247 * or more struct bio_vec fragments.
249 * On the receive side, initially 1 struct kvec fragment is posted for
250 * receive (the header). Once the header has been received, the payload is
251 * received into struct bio_vec fragments.
253 struct ksock_conn; /* forward ref */
254 struct ksock_conn_cb; /* forward ref */
255 struct ksock_proto; /* forward ref */
257 struct ksock_tx { /* transmit packet */
258 struct list_head tx_list; /* queue on conn for transmission etc */
259 struct list_head tx_zc_list; /* queue on peer_ni for ZC request */
260 refcount_t tx_refcount; /* tx reference count */
261 int tx_nob; /* # packet bytes */
262 int tx_resid; /* residual bytes */
263 int tx_niov; /* # packet kvec frags */
264 int tx_nkiov; /* # packet page frags */
265 unsigned short tx_zc_aborted; /* aborted ZC request */
266 unsigned short tx_zc_capable:1; /* payload is large enough for ZC */
267 unsigned short tx_zc_checked:1; /* Have I checked if I should ZC? */
268 unsigned short tx_nonblk:1; /* it's a non-blocking ACK */
269 struct bio_vec *tx_kiov; /* packet page frags */
270 struct ksock_conn *tx_conn; /* owning conn */
271 struct lnet_msg *tx_lnetmsg; /* lnet message for lnet_finalize() */
272 time64_t tx_deadline; /* when (in secs) tx times out */
273 struct ksock_msg tx_msg; /* socklnd message buffer */
274 int tx_desc_size; /* size of this descriptor */
275 enum lnet_msg_hstatus tx_hstatus; /* health status of tx */
276 struct kvec tx_hdr; /* virt hdr */
277 struct bio_vec tx_payload[0]; /* paged payload */
280 #define KSOCK_NOOP_TX_SIZE ((int)offsetof(struct ksock_tx, tx_payload[0]))
282 /* space for the rx frag descriptors; we either read a single contiguous
283 * header, or up to LNET_MAX_IOV frags of payload of either type. */
284 union ksock_rxiovspace {
285 struct kvec iov[LNET_MAX_IOV];
286 struct bio_vec kiov[LNET_MAX_IOV];
289 #define SOCKNAL_RX_KSM_HEADER 1 /* reading ksock message header */
290 #define SOCKNAL_RX_LNET_HEADER 2 /* reading lnet message header */
291 #define SOCKNAL_RX_PARSE 3 /* Calling lnet_parse() */
292 #define SOCKNAL_RX_PARSE_WAIT 4 /* waiting to be told to read the body */
293 #define SOCKNAL_RX_LNET_PAYLOAD 5 /* reading lnet payload (to deliver here) */
294 #define SOCKNAL_RX_SLOP 6 /* skipping body */
297 struct ksock_peer_ni *ksnc_peer; /* owning peer_ni */
298 struct ksock_conn_cb *ksnc_conn_cb; /* owning conn control block */
299 struct list_head ksnc_list; /* on peer_ni's conn list */
300 struct socket *ksnc_sock; /* actual socket */
301 void *ksnc_saved_data_ready; /* socket's original
303 void *ksnc_saved_write_space; /* socket's original
304 * write_space() cb */
305 refcount_t ksnc_conn_refcount; /* conn refcount */
306 refcount_t ksnc_sock_refcount; /* sock refcount */
307 struct ksock_sched *ksnc_scheduler; /* who schedules this
309 struct sockaddr_storage ksnc_myaddr; /* my address */
310 struct sockaddr_storage ksnc_peeraddr; /* peer_ni's address */
311 signed int ksnc_type:3; /* type of connection,
314 unsigned int ksnc_closing:1; /* being shut down */
315 unsigned int ksnc_flip:1; /* flip or not, only for V2.x */
316 unsigned int ksnc_zc_capable:1; /* enable to ZC */
317 const struct ksock_proto *ksnc_proto; /* protocol for the connection */
321 /* where I enq waiting input or a forwarding descriptor */
322 struct list_head ksnc_rx_list;
323 time64_t ksnc_rx_deadline; /* when (in seconds) receive times out */
324 __u8 ksnc_rx_started; /* started receiving a message */
325 __u8 ksnc_rx_ready; /* data ready to read */
326 __u8 ksnc_rx_scheduled;/* being progressed */
327 __u8 ksnc_rx_state; /* what is being read */
328 int ksnc_rx_nob_left; /* # bytes to next hdr/body */
329 int ksnc_rx_nob_wanted; /* bytes actually wanted */
330 int ksnc_rx_niov; /* # kvec frags */
331 struct kvec *ksnc_rx_iov; /* the kvec frags */
332 int ksnc_rx_nkiov; /* # page frags */
333 struct bio_vec *ksnc_rx_kiov; /* the page frags */
334 union ksock_rxiovspace ksnc_rx_iov_space;/* space for frag descriptors */
335 __u32 ksnc_rx_csum; /* partial checksum for incoming
337 struct lnet_msg *ksnc_lnet_msg; /* rx lnet_finalize arg*/
338 struct ksock_msg ksnc_msg; /* incoming message buffer:
339 * V2.x message takes the
341 * V1.x message is a bare
342 * struct lnet_hdr_nid4, it's
344 * ksnc_msg.ksm_u.lnetmsg
347 /* where I enq waiting for output space */
348 struct list_head ksnc_tx_list;
349 /* packets waiting to be sent */
350 struct list_head ksnc_tx_queue;
351 /* next TX that can carry a LNet message or ZC-ACK */
352 struct ksock_tx *ksnc_tx_carrier;
353 /* when (in seconds) tx times out */
354 time64_t ksnc_tx_deadline;
355 /* send buffer marker */
358 atomic_t ksnc_tx_nob;
361 /* being progressed */
362 int ksnc_tx_scheduled;
363 /* time stamp of the last posted TX */
364 time64_t ksnc_tx_last_post;
367 #define SOCKNAL_CONN_COUNT_MAX_BITS 8 /* max conn count bits */
368 #define SOCKNAL_MAX_BUSY_RETRIES 3
370 struct ksock_conn_cb {
371 struct list_head ksnr_connd_list;/* chain on ksnr_connd_routes */
372 struct ksock_peer_ni *ksnr_peer; /* owning peer_ni */
373 refcount_t ksnr_refcount; /* # users */
374 time64_t ksnr_timeout; /* when (in secs) reconnection
377 time64_t ksnr_retry_interval;/* secs between retries */
378 int ksnr_myiface; /* interface index */
379 struct sockaddr_storage ksnr_addr; /* IP address to connect to */
380 unsigned int ksnr_scheduled:1;/* scheduled for attention */
381 unsigned int ksnr_connecting:1;/* connection in progress */
382 unsigned int ksnr_connected:4;/* connections by type */
383 unsigned int ksnr_deleted:1; /* been removed from peer_ni? */
384 unsigned int ksnr_ctrl_conn_count:2; /* # conns by type */
385 unsigned int ksnr_blki_conn_count:8;
386 unsigned int ksnr_blko_conn_count:8;
387 int ksnr_conn_count;/* total # conns for this cb */
388 unsigned int ksnr_max_conns; /* conns_per_peer at peer
391 unsigned int ksnr_busy_retry_count;/* counts retry attempts
396 #define SOCKNAL_KEEPALIVE_PING 1 /* cookie for keepalive ping */
398 struct ksock_peer_ni {
399 struct hlist_node ksnp_list; /* stash on global peer_ni list */
400 time64_t ksnp_last_alive;/* when (in seconds) I was last alive */
401 struct lnet_processid ksnp_id; /* who's on the other end(s) */
402 refcount_t ksnp_refcount; /* # users */
403 int ksnp_closing; /* being closed */
404 int ksnp_accepting; /* # passive connections pending */
405 int ksnp_error; /* errno on closing last conn */
406 __u64 ksnp_zc_next_cookie;/* ZC completion cookie */
407 __u64 ksnp_incarnation; /* latest known peer_ni incarnation */
408 const struct ksock_proto *ksnp_proto; /* latest known protocol */
409 struct list_head ksnp_conns; /* all active connections */
410 struct ksock_conn_cb *ksnp_conn_cb; /* conn control block */
411 struct list_head ksnp_tx_queue; /* waiting packets */
412 spinlock_t ksnp_lock; /* serialize, g_lock unsafe */
413 /* zero copy requests wait for ACK */
414 struct list_head ksnp_zc_req_list;
415 time64_t ksnp_send_keepalive; /* time to send keepalive */
416 struct lnet_ni *ksnp_ni; /* which network */
419 struct ksock_connreq {
420 /* stash on ksnd_connd_connreqs */
421 struct list_head ksncr_list;
423 struct lnet_ni *ksncr_ni;
424 /* accepted socket */
425 struct socket *ksncr_sock;
428 extern struct ksock_nal_data ksocknal_data;
429 extern struct ksock_tunables ksocknal_tunables;
431 #define SOCKNAL_MATCH_NO 0 /* TX can't match type of connection */
432 #define SOCKNAL_MATCH_YES 1 /* TX matches type of connection */
433 #define SOCKNAL_MATCH_MAY 2 /* TX can be sent on the connection, but not preferred */
436 int pro_version; /* version number of protocol */
437 int (*pro_send_hello)(struct ksock_conn *, struct ksock_hello_msg *); /* handshake function */
438 int (*pro_recv_hello)(struct ksock_conn *, struct ksock_hello_msg *, int);/* handshake function */
439 void (*pro_pack)(struct ksock_tx *); /* message pack */
440 void (*pro_unpack)(struct ksock_msg *, struct lnet_hdr *); /* message unpack */
441 struct ksock_tx *(*pro_queue_tx_msg)(struct ksock_conn *, struct ksock_tx *); /* queue tx on the connection */
442 int (*pro_queue_tx_zcack)(struct ksock_conn *, struct ksock_tx *, __u64); /* queue ZC ack on the connection */
443 int (*pro_handle_zcreq)(struct ksock_conn *, __u64, int); /* handle ZC request */
444 int (*pro_handle_zcack)(struct ksock_conn *, __u64, __u64); /* handle ZC ACK */
445 int (*pro_match_tx)(struct ksock_conn *, struct ksock_tx *, int); /* msg type matches the connection type:
447 * return MATCH_NO : no
448 * return MATCH_YES : matching type
449 * return MATCH_MAY : can be backup */
452 extern const struct ksock_proto ksocknal_protocol_v1x;
453 extern const struct ksock_proto ksocknal_protocol_v2x;
454 extern const struct ksock_proto ksocknal_protocol_v3x;
455 extern const struct ksock_proto ksocknal_protocol_v4x;
457 #define KSOCK_PROTO_V1_MAJOR LNET_PROTO_TCP_VERSION_MAJOR
458 #define KSOCK_PROTO_V1_MINOR LNET_PROTO_TCP_VERSION_MINOR
459 #define KSOCK_PROTO_V1 KSOCK_PROTO_V1_MAJOR
461 #ifndef CPU_MASK_NONE
462 #define CPU_MASK_NONE 0UL
465 #if LINUX_VERSION_CODE < KERNEL_VERSION(3, 11, 0)
466 #undef netdev_notifier_info_to_dev
467 #define netdev_notifier_info_to_dev(ndev) ndev
470 static inline __u32 ksocknal_csum(__u32 crc, unsigned char const *p, size_t len)
473 return crc32_le(crc, p, len);
476 crc = ((crc + 0x100) & ~0xff) | ((crc + *p++) & 0xff) ;
483 ksocknal_conn_cb_mask(void)
485 if (!*ksocknal_tunables.ksnd_typed_conns)
486 return BIT(SOCKLND_CONN_ANY);
488 return (BIT(SOCKLND_CONN_CONTROL) |
489 BIT(SOCKLND_CONN_BULK_IN) |
490 BIT(SOCKLND_CONN_BULK_OUT));
494 ksocknal_conn_addref(struct ksock_conn *conn)
496 refcount_inc(&conn->ksnc_conn_refcount);
499 extern void ksocknal_queue_zombie_conn(struct ksock_conn *conn);
500 extern void ksocknal_finalize_zcreq(struct ksock_conn *conn);
503 ksocknal_conn_decref(struct ksock_conn *conn)
505 if (refcount_dec_and_test(&conn->ksnc_conn_refcount))
506 ksocknal_queue_zombie_conn(conn);
510 ksocknal_connsock_addref(struct ksock_conn *conn)
514 read_lock(&ksocknal_data.ksnd_global_lock);
515 if (!conn->ksnc_closing) {
516 refcount_inc(&conn->ksnc_sock_refcount);
519 read_unlock(&ksocknal_data.ksnd_global_lock);
525 ksocknal_connsock_decref(struct ksock_conn *conn)
527 if (refcount_dec_and_test(&conn->ksnc_sock_refcount)) {
528 LASSERT (conn->ksnc_closing);
529 sock_release(conn->ksnc_sock);
530 conn->ksnc_sock = NULL;
531 ksocknal_finalize_zcreq(conn);
536 ksocknal_tx_addref(struct ksock_tx *tx)
538 refcount_inc(&tx->tx_refcount);
541 extern void ksocknal_tx_prep(struct ksock_conn *, struct ksock_tx *tx);
542 extern void ksocknal_tx_done(struct lnet_ni *ni, struct ksock_tx *tx, int error);
545 ksocknal_tx_decref(struct ksock_tx *tx)
547 if (refcount_dec_and_test(&tx->tx_refcount))
548 ksocknal_tx_done(NULL, tx, 0);
552 ksocknal_conn_cb_addref(struct ksock_conn_cb *conn_cb)
554 refcount_inc(&conn_cb->ksnr_refcount);
557 extern void ksocknal_destroy_conn_cb(struct ksock_conn_cb *conn_cb);
560 ksocknal_conn_cb_decref(struct ksock_conn_cb *conn_cb)
562 if (refcount_dec_and_test(&conn_cb->ksnr_refcount))
563 ksocknal_destroy_conn_cb(conn_cb);
567 ksocknal_peer_addref(struct ksock_peer_ni *peer_ni)
569 refcount_inc(&peer_ni->ksnp_refcount);
572 extern void ksocknal_destroy_peer(struct ksock_peer_ni *peer_ni);
575 ksocknal_peer_decref(struct ksock_peer_ni *peer_ni)
577 if (refcount_dec_and_test(&peer_ni->ksnp_refcount))
578 ksocknal_destroy_peer(peer_ni);
581 static inline int ksocknal_timeout(void)
583 return *ksocknal_tunables.ksnd_timeout ?: lnet_get_lnd_timeout();
586 static inline int ksocknal_conns_per_peer(void)
588 return *ksocknal_tunables.ksnd_conns_per_peer ?: 1;
591 int ksocknal_startup(struct lnet_ni *ni);
592 void ksocknal_shutdown(struct lnet_ni *ni);
593 int ksocknal_ctl(struct lnet_ni *ni, unsigned int cmd, void *arg);
594 int ksocknal_send(struct lnet_ni *ni, void *private, struct lnet_msg *lntmsg);
595 int ksocknal_recv(struct lnet_ni *ni, void *private, struct lnet_msg *lntmsg,
596 int delayed, unsigned int niov,
597 struct bio_vec *kiov,
598 unsigned int offset, unsigned int mlen, unsigned int rlen);
599 int ksocknal_accept(struct lnet_ni *ni, struct socket *sock);
601 int ksocknal_add_peer(struct lnet_ni *ni, struct lnet_processid *id,
602 struct sockaddr *addr);
603 struct ksock_peer_ni *ksocknal_find_peer_locked(struct lnet_ni *ni,
604 struct lnet_processid *id);
605 struct ksock_peer_ni *ksocknal_find_peer(struct lnet_ni *ni,
606 struct lnet_processid *id);
607 extern void ksocknal_peer_failed(struct ksock_peer_ni *peer_ni);
608 extern int ksocknal_create_conn(struct lnet_ni *ni,
609 struct ksock_conn_cb *conn_cb,
610 struct socket *sock, int type);
611 extern void ksocknal_close_conn_locked(struct ksock_conn *conn, int why);
612 extern void ksocknal_terminate_conn(struct ksock_conn *conn);
613 extern void ksocknal_destroy_conn(struct ksock_conn *conn);
614 extern int ksocknal_close_peer_conns_locked(struct ksock_peer_ni *peer_ni,
615 struct sockaddr *peer, int why);
616 extern int ksocknal_close_conn_and_siblings(struct ksock_conn *conn, int why);
617 int ksocknal_close_matching_conns(struct lnet_processid *id, __u32 ipaddr);
618 extern struct ksock_conn *ksocknal_find_conn_locked(struct ksock_peer_ni *peer_ni,
619 struct ksock_tx *tx, int nonblk);
621 extern int ksocknal_launch_packet(struct lnet_ni *ni, struct ksock_tx *tx,
622 struct lnet_processid *id);
623 extern struct ksock_tx *ksocknal_alloc_tx(int type, int size);
624 extern void ksocknal_free_tx(struct ksock_tx *tx);
625 extern struct ksock_tx *ksocknal_alloc_tx_noop(__u64 cookie, int nonblk);
626 extern void ksocknal_next_tx_carrier(struct ksock_conn *conn);
627 extern void ksocknal_queue_tx_locked(struct ksock_tx *tx, struct ksock_conn *conn);
628 extern void ksocknal_txlist_done(struct lnet_ni *ni, struct list_head *txlist,
630 #define ksocknal_thread_start(fn, data, namefmt, arg...) \
632 struct task_struct *__task = kthread_run(fn, data, \
634 if (!IS_ERR(__task)) \
635 atomic_inc(&ksocknal_data.ksnd_nthreads); \
636 PTR_ERR_OR_ZERO(__task); \
639 extern void ksocknal_thread_fini(void);
640 extern void ksocknal_launch_all_connections_locked(struct ksock_peer_ni *peer_ni);
641 extern struct ksock_conn_cb *ksocknal_find_connectable_conn_cb_locked(struct ksock_peer_ni *peer_ni);
642 extern struct ksock_conn_cb *ksocknal_find_connecting_conn_cb_locked(struct ksock_peer_ni *peer_ni);
643 extern int ksocknal_new_packet(struct ksock_conn *conn, int skip);
644 extern int ksocknal_scheduler(void *arg);
645 extern int ksocknal_connd(void *arg);
646 extern int ksocknal_reaper(void *arg);
647 int ksocknal_send_hello(struct lnet_ni *ni, struct ksock_conn *conn,
648 struct lnet_nid *peer_nid,
649 struct ksock_hello_msg *hello);
650 int ksocknal_recv_hello(struct lnet_ni *ni, struct ksock_conn *conn,
651 struct ksock_hello_msg *hello,
652 struct lnet_processid *id,
654 extern void ksocknal_read_callback(struct ksock_conn *conn);
655 extern void ksocknal_write_callback(struct ksock_conn *conn);
657 extern int ksocknal_lib_zc_capable(struct ksock_conn *conn);
658 extern void ksocknal_lib_save_callback(struct socket *sock, struct ksock_conn *conn);
659 extern void ksocknal_lib_set_callback(struct socket *sock, struct ksock_conn *conn);
660 extern void ksocknal_lib_reset_callback(struct socket *sock,
661 struct ksock_conn *conn);
662 extern void ksocknal_lib_push_conn(struct ksock_conn *conn);
663 extern int ksocknal_lib_get_conn_addrs(struct ksock_conn *conn);
664 extern int ksocknal_lib_setup_sock(struct socket *so);
665 extern int ksocknal_lib_send_hdr(struct ksock_conn *conn, struct ksock_tx *tx,
666 struct kvec *scratch_iov);
667 extern int ksocknal_lib_send_kiov(struct ksock_conn *conn, struct ksock_tx *tx,
668 struct kvec *scratch_iov);
669 extern void ksocknal_lib_eager_ack(struct ksock_conn *conn);
670 extern int ksocknal_lib_recv_iov(struct ksock_conn *conn,
671 struct kvec *scratchiov);
672 extern int ksocknal_lib_recv_kiov(struct ksock_conn *conn, struct page **pages,
673 struct kvec *scratchiov);
674 extern int ksocknal_lib_get_conn_tunables(struct ksock_conn *conn, int *txmem,
675 int *rxmem, int *nagle);
677 extern int ksocknal_tunables_init(void);
678 extern void ksocknal_tunables_setup(struct lnet_ni *ni);
680 extern void ksocknal_lib_csum_tx(struct ksock_tx *tx);
682 extern int ksocknal_lib_memory_pressure(struct ksock_conn *conn);
684 #endif /* _SOCKLND_SOCKLND_H_ */