2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (c) 2012 The FreeBSD Foundation
6 * This software was developed by Edward Tomasz Napierala under sponsorship
7 * from the FreeBSD Foundation.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37 * iSCSI Common Layer. It's used by both the initiator and target to send
38 * and receive iSCSI PDUs.
41 #include <sys/types.h>
43 #include <sys/condvar.h>
44 #include <sys/sysctl.h>
46 SYSCTL_DECL(_kern_icl);
50 #define ICL_DEBUG(X, ...) \
53 printf("%s: " X "\n", __func__, ## __VA_ARGS__);\
56 #define ICL_WARN(X, ...) \
58 if (icl_debug > 0) { \
59 printf("WARNING: %s: " X "\n", \
60 __func__, ## __VA_ARGS__); \
69 STAILQ_ENTRY(icl_pdu) ip_next;
70 struct icl_conn *ip_conn;
71 struct iscsi_bhs *ip_bhs;
72 struct mbuf *ip_bhs_mbuf;
74 struct mbuf *ip_ahs_mbuf;
76 struct mbuf *ip_data_mbuf;
79 * User (initiator or provider) private fields.
85 #define ICL_CONN_STATE_INVALID 0
86 #define ICL_CONN_STATE_BHS 1
87 #define ICL_CONN_STATE_AHS 2
88 #define ICL_CONN_STATE_HEADER_DIGEST 3
89 #define ICL_CONN_STATE_DATA 4
90 #define ICL_CONN_STATE_DATA_DIGEST 5
92 #define ICL_NOCOPY (1 << 30)
97 struct socket *ic_socket;
99 volatile u_int ic_outstanding_pdus;
101 STAILQ_HEAD(, icl_pdu) ic_to_send;
102 bool ic_check_send_space;
103 size_t ic_receive_len;
104 int ic_receive_state;
105 struct icl_pdu *ic_receive_pdu;
106 struct cv ic_send_cv;
107 struct cv ic_receive_cv;
108 bool ic_header_crc32c;
110 bool ic_send_running;
111 bool ic_receive_running;
112 uint32_t ic_max_recv_data_segment_length;
113 uint32_t ic_max_send_data_segment_length;
115 bool ic_disconnecting;
119 const char *ic_offload;
121 void (*ic_receive)(struct icl_pdu *);
122 void (*ic_error)(struct icl_conn *);
125 * User (initiator or provider) private fields.
130 struct icl_drv_limits {
131 int idl_max_recv_data_segment_length;
132 int idl_max_send_data_segment_length;
133 int idl_max_burst_length;
134 int idl_first_burst_length;
138 typedef void (*icl_pdu_cb)(struct icl_pdu *, int error);
140 struct icl_conn *icl_new_conn(const char *offload, bool iser, const char *name,
142 int icl_limits(const char *offload, bool iser,
143 struct icl_drv_limits *idl);
144 int icl_register(const char *offload, bool iser, int priority,
145 int (*limits)(struct icl_drv_limits *),
146 struct icl_conn *(*new_conn)(const char *, struct mtx *));
147 int icl_unregister(const char *offload, bool rdma);
149 #ifdef ICL_KERNEL_PROXY
157 struct icl_listen *icl_listen_new(void (*accept_cb)(struct socket *,
158 struct sockaddr *, int));
159 void icl_listen_free(struct icl_listen *il);
160 int icl_listen_add(struct icl_listen *il, bool rdma,
161 int domain, int socktype, int protocol,
162 struct sockaddr *sa, int portal_id);
163 int icl_listen_remove(struct icl_listen *il, struct sockaddr *sa);
166 * Those two are not a public API; only to be used between icl_soft.c
167 * and icl_soft_proxy.c.
169 int icl_soft_handoff_sock(struct icl_conn *ic, struct socket *so);
170 int icl_soft_proxy_connect(struct icl_conn *ic, int domain,
171 int socktype, int protocol, struct sockaddr *from_sa,
172 struct sockaddr *to_sa);
173 #endif /* ICL_KERNEL_PROXY */