2 * Copyright (c) 2012 The FreeBSD Foundation
5 * This software was developed by Edward Tomasz Napierala under sponsorship
6 * from the FreeBSD Foundation.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 * iSCSI Common Layer. It's used by both the initiator and target to send
37 * and receive iSCSI PDUs.
43 TAILQ_ENTRY(icl_pdu) ip_next;
44 struct icl_conn *ip_conn;
45 struct iscsi_bhs *ip_bhs;
46 struct mbuf *ip_bhs_mbuf;
48 struct mbuf *ip_ahs_mbuf;
50 struct mbuf *ip_data_mbuf;
53 * User (initiator or provider) private fields.
60 struct icl_pdu *icl_pdu_new_bhs(struct icl_conn *ic, int flags);
61 size_t icl_pdu_data_segment_length(const struct icl_pdu *ip);
62 int icl_pdu_append_data(struct icl_pdu *ip, const void *addr, size_t len, int flags);
63 void icl_pdu_get_data(struct icl_pdu *ip, size_t off, void *addr, size_t len);
64 void icl_pdu_queue(struct icl_pdu *ip);
65 void icl_pdu_free(struct icl_pdu *ip);
67 #define ICL_CONN_STATE_INVALID 0
68 #define ICL_CONN_STATE_BHS 1
69 #define ICL_CONN_STATE_AHS 2
70 #define ICL_CONN_STATE_HEADER_DIGEST 3
71 #define ICL_CONN_STATE_DATA 4
72 #define ICL_CONN_STATE_DATA_DIGEST 5
74 #define ICL_MAX_DATA_SEGMENT_LENGTH (128 * 1024)
78 struct socket *ic_socket;
79 volatile u_int ic_outstanding_pdus;
80 TAILQ_HEAD(, icl_pdu) ic_to_send;
81 size_t ic_receive_len;
83 struct icl_pdu *ic_receive_pdu;
85 struct cv ic_receive_cv;
86 bool ic_header_crc32c;
89 bool ic_receive_running;
90 size_t ic_max_data_segment_length;
91 bool ic_disconnecting;
94 void (*ic_receive)(struct icl_pdu *);
95 void (*ic_error)(struct icl_conn *);
98 * User (initiator or provider) private fields.
103 struct icl_conn *icl_conn_new(void);
104 void icl_conn_free(struct icl_conn *ic);
105 int icl_conn_handoff(struct icl_conn *ic, int fd);
106 void icl_conn_shutdown(struct icl_conn *ic);
107 void icl_conn_close(struct icl_conn *ic);
108 bool icl_conn_connected(struct icl_conn *ic);
110 #ifdef ICL_KERNEL_PROXY
115 struct icl_listen_sock {
116 TAILQ_ENTRY(icl_listen_sock) ils_next;
117 struct icl_listen *ils_listen;
118 struct socket *ils_socket;
120 bool ils_disconnecting;
124 TAILQ_HEAD(, icl_listen_sock) il_sockets;
126 void (*il_accept)(struct socket *);
132 int icl_conn_connect(struct icl_conn *ic, bool rdma,
133 int domain, int socktype, int protocol,
134 struct sockaddr *from_sa, struct sockaddr *to_sa);
138 struct icl_listen *icl_listen_new(void (*accept_cb)(struct socket *));
139 void icl_listen_free(struct icl_listen *il);
140 int icl_listen_add(struct icl_listen *il, bool rdma, int domain,
141 int socktype, int protocol, struct sockaddr *sa);
142 int icl_listen_remove(struct icl_listen *il, struct sockaddr *sa);
145 * This one is not a public API; only to be used by icl_proxy.c.
147 int icl_conn_handoff_sock(struct icl_conn *ic, struct socket *so);
149 #endif /* ICL_KERNEL_PROXY */