Bug Summary

File:modules/iscsi_initiator/../../dev/iscsi_initiator/iscsi.c
Warning:line 560, column 17
Copies out a struct with a partially unsanitized field

Annotated Source Code

/usr/src/sys/modules/iscsi_initiator/../../dev/iscsi_initiator/iscsi.c

1/*-
2 * Copyright (c) 2005-2011 Daniel Braniss <[email protected]>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 *
26 */
27/*
28 | $Id: iscsi.c 752 2009-08-20 11:23:28Z danny $
29 */
30
31#include <sys/cdefs.h>
32__FBSDID("$FreeBSD: releng/11.0/sys/dev/iscsi_initiator/iscsi.c 298955 2016-05-03 03:41:25Z pfg $")__asm__(".ident\t\"" "$FreeBSD: releng/11.0/sys/dev/iscsi_initiator/iscsi.c 298955 2016-05-03 03:41:25Z pfg $"
"\"")
;
33
34#include "opt_iscsi_initiator.h"
35
36#include <sys/param.h>
37#include <sys/capsicum.h>
38#include <sys/kernel.h>
39#include <sys/module.h>
40#include <sys/conf.h>
41#include <sys/bus.h>
42#include <sys/systm.h>
43#include <sys/malloc.h>
44#include <sys/ctype.h>
45#include <sys/errno.h>
46#include <sys/sysctl.h>
47#include <sys/file.h>
48#include <sys/uio.h>
49#include <sys/socketvar.h>
50#include <sys/socket.h>
51#include <sys/protosw.h>
52#include <sys/proc.h>
53#include <sys/ioccom.h>
54#include <sys/queue.h>
55#include <sys/kthread.h>
56#include <sys/mbuf.h>
57#include <sys/syslog.h>
58#include <vm/uma.h>
59#include <sys/sx.h>
60
61#include <dev/iscsi_initiator/iscsi.h>
62#include <dev/iscsi_initiator/iscsivar.h>
63static char *iscsi_driver_version = "2.3.1";
64
65static struct isc_softc *isc;
66
67MALLOC_DEFINE(M_ISCSI, "iSCSI", "iSCSI driver")struct malloc_type M_ISCSI[1] = { { ((void *)0), 877983977, "iSCSI"
, ((void *)0) } }; static struct sysinit M_ISCSI_init_sys_init
= { SI_SUB_KMEM, SI_ORDER_THIRD, (sysinit_cfunc_t)(sysinit_nfunc_t
)malloc_init, ((void *)(M_ISCSI)) }; __asm__(".globl " "__start_set_sysinit_set"
); __asm__(".globl " "__stop_set_sysinit_set"); static void const
* const __set_sysinit_set_sym_M_ISCSI_init_sys_init __attribute__
((__section__("set_" "sysinit_set"))) __attribute__((__used__
)) = &(M_ISCSI_init_sys_init); static struct sysinit M_ISCSI_uninit_sys_uninit
= { SI_SUB_KMEM, SI_ORDER_ANY, (sysinit_cfunc_t)(sysinit_nfunc_t
)malloc_uninit, ((void *)(M_ISCSI)) }; __asm__(".globl " "__start_set_sysuninit_set"
); __asm__(".globl " "__stop_set_sysuninit_set"); static void
const * const __set_sysuninit_set_sym_M_ISCSI_uninit_sys_uninit
__attribute__((__section__("set_" "sysuninit_set"))) __attribute__
((__used__)) = &(M_ISCSI_uninit_sys_uninit)
;
68MALLOC_DEFINE(M_ISCSIBUF, "iSCbuf", "iSCSI buffers")struct malloc_type M_ISCSIBUF[1] = { { ((void *)0), 877983977
, "iSCbuf", ((void *)0) } }; static struct sysinit M_ISCSIBUF_init_sys_init
= { SI_SUB_KMEM, SI_ORDER_THIRD, (sysinit_cfunc_t)(sysinit_nfunc_t
)malloc_init, ((void *)(M_ISCSIBUF)) }; __asm__(".globl " "__start_set_sysinit_set"
); __asm__(".globl " "__stop_set_sysinit_set"); static void const
* const __set_sysinit_set_sym_M_ISCSIBUF_init_sys_init __attribute__
((__section__("set_" "sysinit_set"))) __attribute__((__used__
)) = &(M_ISCSIBUF_init_sys_init); static struct sysinit M_ISCSIBUF_uninit_sys_uninit
= { SI_SUB_KMEM, SI_ORDER_ANY, (sysinit_cfunc_t)(sysinit_nfunc_t
)malloc_uninit, ((void *)(M_ISCSIBUF)) }; __asm__(".globl " "__start_set_sysuninit_set"
); __asm__(".globl " "__stop_set_sysuninit_set"); static void
const * const __set_sysuninit_set_sym_M_ISCSIBUF_uninit_sys_uninit
__attribute__((__section__("set_" "sysuninit_set"))) __attribute__
((__used__)) = &(M_ISCSIBUF_uninit_sys_uninit)
;
69static MALLOC_DEFINE(M_TMP, "iSCtmp", "iSCSI tmp")struct malloc_type M_TMP[1] = { { ((void *)0), 877983977, "iSCtmp"
, ((void *)0) } }; static struct sysinit M_TMP_init_sys_init =
{ SI_SUB_KMEM, SI_ORDER_THIRD, (sysinit_cfunc_t)(sysinit_nfunc_t
)malloc_init, ((void *)(M_TMP)) }; __asm__(".globl " "__start_set_sysinit_set"
); __asm__(".globl " "__stop_set_sysinit_set"); static void const
* const __set_sysinit_set_sym_M_TMP_init_sys_init __attribute__
((__section__("set_" "sysinit_set"))) __attribute__((__used__
)) = &(M_TMP_init_sys_init); static struct sysinit M_TMP_uninit_sys_uninit
= { SI_SUB_KMEM, SI_ORDER_ANY, (sysinit_cfunc_t)(sysinit_nfunc_t
)malloc_uninit, ((void *)(M_TMP)) }; __asm__(".globl " "__start_set_sysuninit_set"
); __asm__(".globl " "__stop_set_sysuninit_set"); static void
const * const __set_sysuninit_set_sym_M_TMP_uninit_sys_uninit
__attribute__((__section__("set_" "sysuninit_set"))) __attribute__
((__used__)) = &(M_TMP_uninit_sys_uninit)
;
70
71#ifdef ISCSI_INITIATOR_DEBUG1
72int iscsi_debug = ISCSI_INITIATOR_DEBUG1;
73SYSCTL_INT(_debug, OID_AUTO, iscsi_initiator, CTLFLAG_RW, &iscsi_debug, 0,static struct sysctl_oid sysctl___debug_iscsi_initiator = { .
oid_parent = ((&(&sysctl___debug)->oid_children)),
.oid_children = { ((void *)0) }, .oid_number = ((-1)), .oid_kind
= (2 | 0x00040000 | ((0x80000000|0x40000000))), .oid_arg1 = (
&iscsi_debug), .oid_arg2 = (0), .oid_name = ("iscsi_initiator"
), .oid_handler = (sysctl_handle_int), .oid_fmt = ("I"), .oid_descr
= "iSCSI driver debug flag" }; __asm__(".globl " "__start_set_sysctl_set"
); __asm__(".globl " "__stop_set_sysctl_set"); static void const
* const __set_sysctl_set_sym_sysctl___debug_iscsi_initiator __attribute__
((__section__("set_" "sysctl_set"))) __attribute__((__used__)
) = &(sysctl___debug_iscsi_initiator); _Static_assert((((
(0x80000000|0x40000000)) & 0xf) == 0 || (((0x80000000|0x40000000
)) & 0xf) == 2) && sizeof(int) == sizeof(*(&iscsi_debug
)), "compile-time assertion failed")
74 "iSCSI driver debug flag")static struct sysctl_oid sysctl___debug_iscsi_initiator = { .
oid_parent = ((&(&sysctl___debug)->oid_children)),
.oid_children = { ((void *)0) }, .oid_number = ((-1)), .oid_kind
= (2 | 0x00040000 | ((0x80000000|0x40000000))), .oid_arg1 = (
&iscsi_debug), .oid_arg2 = (0), .oid_name = ("iscsi_initiator"
), .oid_handler = (sysctl_handle_int), .oid_fmt = ("I"), .oid_descr
= "iSCSI driver debug flag" }; __asm__(".globl " "__start_set_sysctl_set"
); __asm__(".globl " "__stop_set_sysctl_set"); static void const
* const __set_sysctl_set_sym_sysctl___debug_iscsi_initiator __attribute__
((__section__("set_" "sysctl_set"))) __attribute__((__used__)
) = &(sysctl___debug_iscsi_initiator); _Static_assert((((
(0x80000000|0x40000000)) & 0xf) == 0 || (((0x80000000|0x40000000
)) & 0xf) == 2) && sizeof(int) == sizeof(*(&iscsi_debug
)), "compile-time assertion failed")
;
75
76struct mtx iscsi_dbg_mtx;
77#endif
78
79static int max_sessions = MAX_SESSIONS64;
80SYSCTL_INT(_net, OID_AUTO, iscsi_initiator_max_sessions, CTLFLAG_RDTUN,static struct sysctl_oid sysctl___net_iscsi_initiator_max_sessions
= { .oid_parent = ((&(&sysctl___net)->oid_children
)), .oid_children = { ((void *)0) }, .oid_number = ((-1)), .oid_kind
= (2 | 0x00040000 | ((0x80000000|0x00080000))), .oid_arg1 = (
&max_sessions), .oid_arg2 = (0), .oid_name = ("iscsi_initiator_max_sessions"
), .oid_handler = (sysctl_handle_int), .oid_fmt = ("I"), .oid_descr
= "Max sessions allowed" }; __asm__(".globl " "__start_set_sysctl_set"
); __asm__(".globl " "__stop_set_sysctl_set"); static void const
* const __set_sysctl_set_sym_sysctl___net_iscsi_initiator_max_sessions
__attribute__((__section__("set_" "sysctl_set"))) __attribute__
((__used__)) = &(sysctl___net_iscsi_initiator_max_sessions
); _Static_assert(((((0x80000000|0x00080000)) & 0xf) == 0
|| (((0x80000000|0x00080000)) & 0xf) == 2) && sizeof
(int) == sizeof(*(&max_sessions)), "compile-time assertion failed"
)
81 &max_sessions, 0, "Max sessions allowed")static struct sysctl_oid sysctl___net_iscsi_initiator_max_sessions
= { .oid_parent = ((&(&sysctl___net)->oid_children
)), .oid_children = { ((void *)0) }, .oid_number = ((-1)), .oid_kind
= (2 | 0x00040000 | ((0x80000000|0x00080000))), .oid_arg1 = (
&max_sessions), .oid_arg2 = (0), .oid_name = ("iscsi_initiator_max_sessions"
), .oid_handler = (sysctl_handle_int), .oid_fmt = ("I"), .oid_descr
= "Max sessions allowed" }; __asm__(".globl " "__start_set_sysctl_set"
); __asm__(".globl " "__stop_set_sysctl_set"); static void const
* const __set_sysctl_set_sym_sysctl___net_iscsi_initiator_max_sessions
__attribute__((__section__("set_" "sysctl_set"))) __attribute__
((__used__)) = &(sysctl___net_iscsi_initiator_max_sessions
); _Static_assert(((((0x80000000|0x00080000)) & 0xf) == 0
|| (((0x80000000|0x00080000)) & 0xf) == 2) && sizeof
(int) == sizeof(*(&max_sessions)), "compile-time assertion failed"
)
;
82static int max_pdus = MAX_PDUS(64*256);
83SYSCTL_INT(_net, OID_AUTO, iscsi_initiator_max_pdus, CTLFLAG_RDTUN,static struct sysctl_oid sysctl___net_iscsi_initiator_max_pdus
= { .oid_parent = ((&(&sysctl___net)->oid_children
)), .oid_children = { ((void *)0) }, .oid_number = ((-1)), .oid_kind
= (2 | 0x00040000 | ((0x80000000|0x00080000))), .oid_arg1 = (
&max_pdus), .oid_arg2 = (0), .oid_name = ("iscsi_initiator_max_pdus"
), .oid_handler = (sysctl_handle_int), .oid_fmt = ("I"), .oid_descr
= "Max PDU pool" }; __asm__(".globl " "__start_set_sysctl_set"
); __asm__(".globl " "__stop_set_sysctl_set"); static void const
* const __set_sysctl_set_sym_sysctl___net_iscsi_initiator_max_pdus
__attribute__((__section__("set_" "sysctl_set"))) __attribute__
((__used__)) = &(sysctl___net_iscsi_initiator_max_pdus); _Static_assert
(((((0x80000000|0x00080000)) & 0xf) == 0 || (((0x80000000
|0x00080000)) & 0xf) == 2) && sizeof(int) == sizeof
(*(&max_pdus)), "compile-time assertion failed")
84 &max_pdus, 0, "Max PDU pool")static struct sysctl_oid sysctl___net_iscsi_initiator_max_pdus
= { .oid_parent = ((&(&sysctl___net)->oid_children
)), .oid_children = { ((void *)0) }, .oid_number = ((-1)), .oid_kind
= (2 | 0x00040000 | ((0x80000000|0x00080000))), .oid_arg1 = (
&max_pdus), .oid_arg2 = (0), .oid_name = ("iscsi_initiator_max_pdus"
), .oid_handler = (sysctl_handle_int), .oid_fmt = ("I"), .oid_descr
= "Max PDU pool" }; __asm__(".globl " "__start_set_sysctl_set"
); __asm__(".globl " "__stop_set_sysctl_set"); static void const
* const __set_sysctl_set_sym_sysctl___net_iscsi_initiator_max_pdus
__attribute__((__section__("set_" "sysctl_set"))) __attribute__
((__used__)) = &(sysctl___net_iscsi_initiator_max_pdus); _Static_assert
(((((0x80000000|0x00080000)) & 0xf) == 0 || (((0x80000000
|0x00080000)) & 0xf) == 2) && sizeof(int) == sizeof
(*(&max_pdus)), "compile-time assertion failed")
;
85
86static char isid[6+1] = {
87 0x80,
88 'D',
89 'I',
90 'B',
91 '0',
92 '0',
93 0
94};
95
96static int i_create_session(struct cdev *dev, int *ndev);
97
98static int i_ping(struct cdev *dev);
99static int i_send(struct cdev *dev, caddr_t arg, struct thread *td);
100static int i_recv(struct cdev *dev, caddr_t arg, struct thread *td);
101static int i_setsoc(isc_session_t *sp, int fd, struct thread *td);
102static int i_fullfeature(struct cdev *dev, int flag);
103
104static d_open_t iscsi_open;
105static d_close_t iscsi_close;
106static d_ioctl_t iscsi_ioctl;
107#ifdef ISCSI_INITIATOR_DEBUG1
108static d_read_t iscsi_read;
109#endif
110
111static struct cdevsw iscsi_cdevsw = {
112 .d_version = D_VERSION0x17122009,
113 .d_open = iscsi_open,
114 .d_close = iscsi_close,
115 .d_ioctl = iscsi_ioctl,
116#ifdef ISCSI_INITIATOR_DEBUG1
117 .d_read = iscsi_read,
118#endif
119 .d_name = "iSCSI",
120};
121
122static int
123iscsi_open(struct cdev *dev, int flags, int otype, struct thread *td)
124{
125 debug_called(8)do {if(8 <= iscsi_debug) printf("%s: called\n", __func__);
} while(0)
;
126
127 debug(7, "dev=%d", dev2unit(dev))do {if(7 <= iscsi_debug) printf("%s: " "dev=%d" "\n", __func__
, ((dev)->si_drv0));} while(0)
;
128
129 if(dev2unit(dev)((dev)->si_drv0) > max_sessions) {
130 // should not happen
131 return ENODEV19;
132 }
133 return 0;
134}
135
136static int
137iscsi_close(struct cdev *dev, int flag, int otyp, struct thread *td)
138{
139 isc_session_t *sp;
140
141 debug_called(8)do {if(8 <= iscsi_debug) printf("%s: called\n", __func__);
} while(0)
;
142
143 debug(3, "session=%d flag=%x", dev2unit(dev), flag)do {if(3 <= iscsi_debug) printf("%s: " "session=%d flag=%x"
"\n", __func__ , ((dev)->si_drv0), flag);} while(0)
;
144
145 if(dev2unit(dev)((dev)->si_drv0) == max_sessions) {
146 return 0;
147 }
148 sp = dev->si_drv2;
149 if(sp != NULL((void *)0)) {
150 sdebug(3, "sp->flags=%x", sp->flags )do {if(3 <= iscsi_debug) printf("%d] %s: " "sp->flags=%x"
"\n", sp->sid, __func__ , sp->flags);} while(0)
;
151 /*
152 | if still in full phase, this probably means
153 | that something went really bad.
154 | it could be a result from 'shutdown', in which case
155 | we will ignore it (so buffers can be flushed).
156 | the problem is that there is no way of differentiating
157 | between a shutdown procedure and 'iscontrol' dying.
158 */
159 if(sp->flags & ISC_FFPHASE(1 <<(8)))
160 // delay in case this is a shutdown.
161 tsleep(sp, PRIBIO, "isc-cls", 60*hz)_sleep((sp), ((void *)0), (((80) + 12)), ("isc-cls"), tick_sbt
* (60*hz), 0, 0x0100)
;
162 ism_stop(sp);
163 }
164 debug(2, "done")do {if(2 <= iscsi_debug) printf("%s: " "done" "\n", __func__
);} while(0)
;
165 return 0;
166}
167
168static int
169iscsi_ioctl(struct cdev *dev, u_long cmd, caddr_t arg, int mode, struct thread *td)
170{
171 struct isc_softc *sc;
172 isc_session_t *sp;
173 isc_opt_t *opt;
174 int error;
175
176 debug_called(8)do {if(8 <= iscsi_debug) printf("%s: called\n", __func__);
} while(0)
;
177
178 error = 0;
179 if(dev2unit(dev)((dev)->si_drv0) == max_sessions) {
180 /*
181 | non Session commands
182 */
183 sc = dev->si_drv1;
184 if(sc == NULL((void *)0))
185 return ENXIO6;
186
187 switch(cmd) {
188 case ISCSISETSES((unsigned long) ((0x40000000) | (((sizeof(int)) & ((1 <<
13) - 1)) << 16) | ((('i')) << 8) | ((1))))
:
189 error = i_create_session(dev, (int *)arg);
190 if(error == 0)
191 break;
192
193 default:
194 error = ENXIO6;
195 }
196 return error;
197 }
198 /*
199 | session commands
200 */
201 sp = dev->si_drv2;
202 if(sp == NULL((void *)0))
203 return ENXIO6;
204
205 sdebug(6, "dev=%d cmd=%d", dev2unit(dev), (int)(cmd & 0xff))do {if(6 <= iscsi_debug) printf("%d] %s: " "dev=%d cmd=%d"
"\n", sp->sid, __func__ , ((dev)->si_drv0), (int)(cmd &
0xff));} while(0)
;
206
207 switch(cmd) {
208 case ISCSISETSOC((unsigned long) ((0x80000000) | (((sizeof(int)) & ((1 <<
13) - 1)) << 16) | ((('i')) << 8) | ((2))))
:
209 error = i_setsoc(sp, *(u_int *)arg, td);
210 break;
211
212 case ISCSISETOPT((unsigned long) ((0x80000000) | (((sizeof(isc_opt_t)) & (
(1 << 13) - 1)) << 16) | ((('i')) << 8) | (
(5))))
:
213 opt = (isc_opt_t *)arg;
214 error = i_setopt(sp, opt);
215 break;
216
217 case ISCSISEND((unsigned long) ((0x80000000) | (((sizeof(pdu_t)) & ((1 <<
13) - 1)) << 16) | ((('i')) << 8) | ((10))))
:
218 error = i_send(dev, arg, td);
219 break;
220
221 case ISCSIRECV((unsigned long) (((0x80000000|0x40000000)) | (((sizeof(pdu_t
)) & ((1 << 13) - 1)) << 16) | ((('i')) <<
8) | ((11))))
:
222 error = i_recv(dev, arg, td);
223 break;
224
225 case ISCSIPING((unsigned long) ((0x20000000) | (((0) & ((1 << 13)
- 1)) << 16) | ((('i')) << 8) | ((20))))
:
226 error = i_ping(dev);
227 break;
228
229 case ISCSISTART((unsigned long) ((0x20000000) | (((0) & ((1 << 13)
- 1)) << 16) | ((('i')) << 8) | ((30))))
:
230 error = sp->soc == NULL((void *)0)? ENOTCONN57: i_fullfeature(dev, 1);
231 if(error == 0) {
232 sp->proc = td->td_proc;
233 SYSCTL_ADD_INT(&sp->clist, SYSCTL_CHILDREN(sp->oid),({ int *__ptr = (&sp->proc->p_pid); _Static_assert(
((0x80000000) & 0xf) == 0 || ((0x80000000) & 0xf) == 2
, "compile-time assertion failed"); sysctl_add_oid(&sp->
clist, (&(sp->oid)->oid_children), (-1), "pid", 2 |
0x00040000 | (0x80000000), __ptr, sizeof(pid_t), sysctl_handle_int
, "I", "control process id"); })
234 OID_AUTO, "pid", CTLFLAG_RD,({ int *__ptr = (&sp->proc->p_pid); _Static_assert(
((0x80000000) & 0xf) == 0 || ((0x80000000) & 0xf) == 2
, "compile-time assertion failed"); sysctl_add_oid(&sp->
clist, (&(sp->oid)->oid_children), (-1), "pid", 2 |
0x00040000 | (0x80000000), __ptr, sizeof(pid_t), sysctl_handle_int
, "I", "control process id"); })
235 &sp->proc->p_pid, sizeof(pid_t), "control process id")({ int *__ptr = (&sp->proc->p_pid); _Static_assert(
((0x80000000) & 0xf) == 0 || ((0x80000000) & 0xf) == 2
, "compile-time assertion failed"); sysctl_add_oid(&sp->
clist, (&(sp->oid)->oid_children), (-1), "pid", 2 |
0x00040000 | (0x80000000), __ptr, sizeof(pid_t), sysctl_handle_int
, "I", "control process id"); })
;
236 }
237 break;
238
239 case ISCSIRESTART((unsigned long) ((0x20000000) | (((0) & ((1 << 13)
- 1)) << 16) | ((('i')) << 8) | ((31))))
:
240 error = sp->soc == NULL((void *)0)? ENOTCONN57: i_fullfeature(dev, 2);
241 break;
242
243 case ISCSISTOP((unsigned long) ((0x20000000) | (((0) & ((1 << 13)
- 1)) << 16) | ((('i')) << 8) | ((32))))
:
244 error = i_fullfeature(dev, 0);
245 break;
246
247 case ISCSISIGNAL((unsigned long) ((0x80000000) | (((sizeof(int *)) & ((1 <<
13) - 1)) << 16) | ((('i')) << 8) | ((21))))
: {
248 int sig = *(int *)arg;
249
250 if(sig < 0 || sig > _SIG_MAXSIG128)
251 error = EINVAL22;
252 else
253 sp->signal = sig;
254 break;
255 }
256
257 case ISCSIGETCAM((unsigned long) ((0x40000000) | (((sizeof(iscsi_cam_t)) &
((1 << 13) - 1)) << 16) | ((('i')) << 8) |
((33))))
: {
258 iscsi_cam_t *cp = (iscsi_cam_t *)arg;
259
260 error = ic_getCamVals(sp, cp);
261 break;
262 }
263
264 default:
265 error = ENOIOCTL(-3);
266 }
267
268 return error;
269}
270
271static int
272iscsi_read(struct cdev *dev, struct uio *uio, int ioflag)
273{
274#ifdef ISCSI_INITIATOR_DEBUG1
275 struct isc_softc *sc;
276 isc_session_t *sp;
277 pduq_t *pq;
278 char buf[1024];
279
280 sc = dev->si_drv1;
281 sp = dev->si_drv2;
282 if(dev2unit(dev)((dev)->si_drv0) == max_sessions) {
283 sprintf(buf, "/----- Session ------/\n");
284 uiomove(buf, strlen(buf), uio);
285 int i = 0;
286
287 TAILQ_FOREACH(sp, &sc->isc_sess, sp_link)for ((sp) = (((&sc->isc_sess))->tqh_first); (sp); (
sp) = (((sp))->sp_link.tqe_next))
{
288 if(uio->uio_resid == 0)
289 return 0;
290 sprintf(buf, "%03d] '%s' '%s'\n", i++, sp->opt.targetAddress, sp->opt.targetName);
291 uiomove(buf, strlen(buf), uio);
292 }
293 sprintf(buf, "free npdu_alloc=%d, npdu_max=%d\n", sc->npdu_alloc, sc->npdu_max);
294 uiomove(buf, strlen(buf), uio);
295 }
296 else {
297 int i = 0;
298 struct socket *so = sp->soc;
299#define pukeit(i, pq)do { sprintf(buf, "%03d] %06x %02x %06x %06x %jd\n", i, (__builtin_constant_p
(pq->pdu.ipdu.bhs.OpcodeSpecificFields[1]) ? (((__uint32_t
)((__uint16_t)(__builtin_constant_p(((__uint32_t)(pq->pdu.
ipdu.bhs.OpcodeSpecificFields[1])) & 0xffff) ? (__uint16_t
)(((__uint16_t)(((__uint32_t)(pq->pdu.ipdu.bhs.OpcodeSpecificFields
[1])) & 0xffff)) << 8 | ((__uint16_t)(((__uint32_t)
(pq->pdu.ipdu.bhs.OpcodeSpecificFields[1])) & 0xffff))
>> 8) : __bswap16_var(((__uint32_t)(pq->pdu.ipdu.bhs
.OpcodeSpecificFields[1])) & 0xffff))) << 16) | ((__uint16_t
)(__builtin_constant_p(((__uint32_t)(pq->pdu.ipdu.bhs.OpcodeSpecificFields
[1])) >> 16) ? (__uint16_t)(((__uint16_t)(((__uint32_t)
(pq->pdu.ipdu.bhs.OpcodeSpecificFields[1])) >> 16)) <<
8 | ((__uint16_t)(((__uint32_t)(pq->pdu.ipdu.bhs.OpcodeSpecificFields
[1])) >> 16)) >> 8) : __bswap16_var(((__uint32_t)
(pq->pdu.ipdu.bhs.OpcodeSpecificFields[1])) >> 16)))
) : __bswap32_var(pq->pdu.ipdu.bhs.OpcodeSpecificFields[1]
)), pq->pdu.ipdu.bhs.opcode, (__builtin_constant_p(pq->
pdu.ipdu.bhs.itt) ? (((__uint32_t)((__uint16_t)(__builtin_constant_p
(((__uint32_t)(pq->pdu.ipdu.bhs.itt)) & 0xffff) ? (__uint16_t
)(((__uint16_t)(((__uint32_t)(pq->pdu.ipdu.bhs.itt)) &
0xffff)) << 8 | ((__uint16_t)(((__uint32_t)(pq->pdu
.ipdu.bhs.itt)) & 0xffff)) >> 8) : __bswap16_var(((
__uint32_t)(pq->pdu.ipdu.bhs.itt)) & 0xffff))) <<
16) | ((__uint16_t)(__builtin_constant_p(((__uint32_t)(pq->
pdu.ipdu.bhs.itt)) >> 16) ? (__uint16_t)(((__uint16_t)(
((__uint32_t)(pq->pdu.ipdu.bhs.itt)) >> 16)) <<
8 | ((__uint16_t)(((__uint32_t)(pq->pdu.ipdu.bhs.itt)) >>
16)) >> 8) : __bswap16_var(((__uint32_t)(pq->pdu.ipdu
.bhs.itt)) >> 16)))) : __bswap32_var(pq->pdu.ipdu.bhs
.itt)), (__builtin_constant_p(pq->pdu.ipdu.bhs.OpcodeSpecificFields
[2]) ? (((__uint32_t)((__uint16_t)(__builtin_constant_p(((__uint32_t
)(pq->pdu.ipdu.bhs.OpcodeSpecificFields[2])) & 0xffff)
? (__uint16_t)(((__uint16_t)(((__uint32_t)(pq->pdu.ipdu.bhs
.OpcodeSpecificFields[2])) & 0xffff)) << 8 | ((__uint16_t
)(((__uint32_t)(pq->pdu.ipdu.bhs.OpcodeSpecificFields[2]))
& 0xffff)) >> 8) : __bswap16_var(((__uint32_t)(pq->
pdu.ipdu.bhs.OpcodeSpecificFields[2])) & 0xffff))) <<
16) | ((__uint16_t)(__builtin_constant_p(((__uint32_t)(pq->
pdu.ipdu.bhs.OpcodeSpecificFields[2])) >> 16) ? (__uint16_t
)(((__uint16_t)(((__uint32_t)(pq->pdu.ipdu.bhs.OpcodeSpecificFields
[2])) >> 16)) << 8 | ((__uint16_t)(((__uint32_t)(
pq->pdu.ipdu.bhs.OpcodeSpecificFields[2])) >> 16)) >>
8) : __bswap16_var(((__uint32_t)(pq->pdu.ipdu.bhs.OpcodeSpecificFields
[2])) >> 16)))) : __bswap32_var(pq->pdu.ipdu.bhs.OpcodeSpecificFields
[2])), (intmax_t)pq->ts.sec); } while(0)
do {\
300 sprintf(buf, "%03d] %06x %02x %06x %06x %jd\n",\
301 i, ntohl(pq->pdu.ipdu.bhs.CmdSN)(__builtin_constant_p(pq->pdu.ipdu.bhs.OpcodeSpecificFields
[1]) ? (((__uint32_t)((__uint16_t)(__builtin_constant_p(((__uint32_t
)(pq->pdu.ipdu.bhs.OpcodeSpecificFields[1])) & 0xffff)
? (__uint16_t)(((__uint16_t)(((__uint32_t)(pq->pdu.ipdu.bhs
.OpcodeSpecificFields[1])) & 0xffff)) << 8 | ((__uint16_t
)(((__uint32_t)(pq->pdu.ipdu.bhs.OpcodeSpecificFields[1]))
& 0xffff)) >> 8) : __bswap16_var(((__uint32_t)(pq->
pdu.ipdu.bhs.OpcodeSpecificFields[1])) & 0xffff))) <<
16) | ((__uint16_t)(__builtin_constant_p(((__uint32_t)(pq->
pdu.ipdu.bhs.OpcodeSpecificFields[1])) >> 16) ? (__uint16_t
)(((__uint16_t)(((__uint32_t)(pq->pdu.ipdu.bhs.OpcodeSpecificFields
[1])) >> 16)) << 8 | ((__uint16_t)(((__uint32_t)(
pq->pdu.ipdu.bhs.OpcodeSpecificFields[1])) >> 16)) >>
8) : __bswap16_var(((__uint32_t)(pq->pdu.ipdu.bhs.OpcodeSpecificFields
[1])) >> 16)))) : __bswap32_var(pq->pdu.ipdu.bhs.OpcodeSpecificFields
[1]))
,\
302 pq->pdu.ipdu.bhs.opcode, ntohl(pq->pdu.ipdu.bhs.itt)(__builtin_constant_p(pq->pdu.ipdu.bhs.itt) ? (((__uint32_t
)((__uint16_t)(__builtin_constant_p(((__uint32_t)(pq->pdu.
ipdu.bhs.itt)) & 0xffff) ? (__uint16_t)(((__uint16_t)(((__uint32_t
)(pq->pdu.ipdu.bhs.itt)) & 0xffff)) << 8 | ((__uint16_t
)(((__uint32_t)(pq->pdu.ipdu.bhs.itt)) & 0xffff)) >>
8) : __bswap16_var(((__uint32_t)(pq->pdu.ipdu.bhs.itt)) &
0xffff))) << 16) | ((__uint16_t)(__builtin_constant_p(
((__uint32_t)(pq->pdu.ipdu.bhs.itt)) >> 16) ? (__uint16_t
)(((__uint16_t)(((__uint32_t)(pq->pdu.ipdu.bhs.itt)) >>
16)) << 8 | ((__uint16_t)(((__uint32_t)(pq->pdu.ipdu
.bhs.itt)) >> 16)) >> 8) : __bswap16_var(((__uint32_t
)(pq->pdu.ipdu.bhs.itt)) >> 16)))) : __bswap32_var(pq
->pdu.ipdu.bhs.itt))
,\
303 ntohl(pq->pdu.ipdu.bhs.ExpStSN)(__builtin_constant_p(pq->pdu.ipdu.bhs.OpcodeSpecificFields
[2]) ? (((__uint32_t)((__uint16_t)(__builtin_constant_p(((__uint32_t
)(pq->pdu.ipdu.bhs.OpcodeSpecificFields[2])) & 0xffff)
? (__uint16_t)(((__uint16_t)(((__uint32_t)(pq->pdu.ipdu.bhs
.OpcodeSpecificFields[2])) & 0xffff)) << 8 | ((__uint16_t
)(((__uint32_t)(pq->pdu.ipdu.bhs.OpcodeSpecificFields[2]))
& 0xffff)) >> 8) : __bswap16_var(((__uint32_t)(pq->
pdu.ipdu.bhs.OpcodeSpecificFields[2])) & 0xffff))) <<
16) | ((__uint16_t)(__builtin_constant_p(((__uint32_t)(pq->
pdu.ipdu.bhs.OpcodeSpecificFields[2])) >> 16) ? (__uint16_t
)(((__uint16_t)(((__uint32_t)(pq->pdu.ipdu.bhs.OpcodeSpecificFields
[2])) >> 16)) << 8 | ((__uint16_t)(((__uint32_t)(
pq->pdu.ipdu.bhs.OpcodeSpecificFields[2])) >> 16)) >>
8) : __bswap16_var(((__uint32_t)(pq->pdu.ipdu.bhs.OpcodeSpecificFields
[2])) >> 16)))) : __bswap32_var(pq->pdu.ipdu.bhs.OpcodeSpecificFields
[2]))
,\
304 (intmax_t)pq->ts.sec);\
305 } while(0)
306
307 sprintf(buf, "%d/%d /---- hld -----/\n", sp->stats.nhld, sp->stats.max_hld);
308 uiomove(buf, strlen(buf), uio);
309 TAILQ_FOREACH(pq, &sp->hld, pq_link)for ((pq) = (((&sp->hld))->tqh_first); (pq); (pq) =
(((pq))->pq_link.tqe_next))
{
310 if(uio->uio_resid == 0)
311 return 0;
312 pukeit(i, pq)do { sprintf(buf, "%03d] %06x %02x %06x %06x %jd\n", i, (__builtin_constant_p
(pq->pdu.ipdu.bhs.OpcodeSpecificFields[1]) ? (((__uint32_t
)((__uint16_t)(__builtin_constant_p(((__uint32_t)(pq->pdu.
ipdu.bhs.OpcodeSpecificFields[1])) & 0xffff) ? (__uint16_t
)(((__uint16_t)(((__uint32_t)(pq->pdu.ipdu.bhs.OpcodeSpecificFields
[1])) & 0xffff)) << 8 | ((__uint16_t)(((__uint32_t)
(pq->pdu.ipdu.bhs.OpcodeSpecificFields[1])) & 0xffff))
>> 8) : __bswap16_var(((__uint32_t)(pq->pdu.ipdu.bhs
.OpcodeSpecificFields[1])) & 0xffff))) << 16) | ((__uint16_t
)(__builtin_constant_p(((__uint32_t)(pq->pdu.ipdu.bhs.OpcodeSpecificFields
[1])) >> 16) ? (__uint16_t)(((__uint16_t)(((__uint32_t)
(pq->pdu.ipdu.bhs.OpcodeSpecificFields[1])) >> 16)) <<
8 | ((__uint16_t)(((__uint32_t)(pq->pdu.ipdu.bhs.OpcodeSpecificFields
[1])) >> 16)) >> 8) : __bswap16_var(((__uint32_t)
(pq->pdu.ipdu.bhs.OpcodeSpecificFields[1])) >> 16)))
) : __bswap32_var(pq->pdu.ipdu.bhs.OpcodeSpecificFields[1]
)), pq->pdu.ipdu.bhs.opcode, (__builtin_constant_p(pq->
pdu.ipdu.bhs.itt) ? (((__uint32_t)((__uint16_t)(__builtin_constant_p
(((__uint32_t)(pq->pdu.ipdu.bhs.itt)) & 0xffff) ? (__uint16_t
)(((__uint16_t)(((__uint32_t)(pq->pdu.ipdu.bhs.itt)) &
0xffff)) << 8 | ((__uint16_t)(((__uint32_t)(pq->pdu
.ipdu.bhs.itt)) & 0xffff)) >> 8) : __bswap16_var(((
__uint32_t)(pq->pdu.ipdu.bhs.itt)) & 0xffff))) <<
16) | ((__uint16_t)(__builtin_constant_p(((__uint32_t)(pq->
pdu.ipdu.bhs.itt)) >> 16) ? (__uint16_t)(((__uint16_t)(
((__uint32_t)(pq->pdu.ipdu.bhs.itt)) >> 16)) <<
8 | ((__uint16_t)(((__uint32_t)(pq->pdu.ipdu.bhs.itt)) >>
16)) >> 8) : __bswap16_var(((__uint32_t)(pq->pdu.ipdu
.bhs.itt)) >> 16)))) : __bswap32_var(pq->pdu.ipdu.bhs
.itt)), (__builtin_constant_p(pq->pdu.ipdu.bhs.OpcodeSpecificFields
[2]) ? (((__uint32_t)((__uint16_t)(__builtin_constant_p(((__uint32_t
)(pq->pdu.ipdu.bhs.OpcodeSpecificFields[2])) & 0xffff)
? (__uint16_t)(((__uint16_t)(((__uint32_t)(pq->pdu.ipdu.bhs
.OpcodeSpecificFields[2])) & 0xffff)) << 8 | ((__uint16_t
)(((__uint32_t)(pq->pdu.ipdu.bhs.OpcodeSpecificFields[2]))
& 0xffff)) >> 8) : __bswap16_var(((__uint32_t)(pq->
pdu.ipdu.bhs.OpcodeSpecificFields[2])) & 0xffff))) <<
16) | ((__uint16_t)(__builtin_constant_p(((__uint32_t)(pq->
pdu.ipdu.bhs.OpcodeSpecificFields[2])) >> 16) ? (__uint16_t
)(((__uint16_t)(((__uint32_t)(pq->pdu.ipdu.bhs.OpcodeSpecificFields
[2])) >> 16)) << 8 | ((__uint16_t)(((__uint32_t)(
pq->pdu.ipdu.bhs.OpcodeSpecificFields[2])) >> 16)) >>
8) : __bswap16_var(((__uint32_t)(pq->pdu.ipdu.bhs.OpcodeSpecificFields
[2])) >> 16)))) : __bswap32_var(pq->pdu.ipdu.bhs.OpcodeSpecificFields
[2])), (intmax_t)pq->ts.sec); } while(0)
; i++;
313 uiomove(buf, strlen(buf), uio);
314 }
315 sprintf(buf, "%d/%d /---- rsp -----/\n", sp->stats.nrsp, sp->stats.max_rsp);
316 uiomove(buf, strlen(buf), uio);
317 i = 0;
318 TAILQ_FOREACH(pq, &sp->rsp, pq_link)for ((pq) = (((&sp->rsp))->tqh_first); (pq); (pq) =
(((pq))->pq_link.tqe_next))
{
319 if(uio->uio_resid == 0)
320 return 0;
321 pukeit(i, pq)do { sprintf(buf, "%03d] %06x %02x %06x %06x %jd\n", i, (__builtin_constant_p
(pq->pdu.ipdu.bhs.OpcodeSpecificFields[1]) ? (((__uint32_t
)((__uint16_t)(__builtin_constant_p(((__uint32_t)(pq->pdu.
ipdu.bhs.OpcodeSpecificFields[1])) & 0xffff) ? (__uint16_t
)(((__uint16_t)(((__uint32_t)(pq->pdu.ipdu.bhs.OpcodeSpecificFields
[1])) & 0xffff)) << 8 | ((__uint16_t)(((__uint32_t)
(pq->pdu.ipdu.bhs.OpcodeSpecificFields[1])) & 0xffff))
>> 8) : __bswap16_var(((__uint32_t)(pq->pdu.ipdu.bhs
.OpcodeSpecificFields[1])) & 0xffff))) << 16) | ((__uint16_t
)(__builtin_constant_p(((__uint32_t)(pq->pdu.ipdu.bhs.OpcodeSpecificFields
[1])) >> 16) ? (__uint16_t)(((__uint16_t)(((__uint32_t)
(pq->pdu.ipdu.bhs.OpcodeSpecificFields[1])) >> 16)) <<
8 | ((__uint16_t)(((__uint32_t)(pq->pdu.ipdu.bhs.OpcodeSpecificFields
[1])) >> 16)) >> 8) : __bswap16_var(((__uint32_t)
(pq->pdu.ipdu.bhs.OpcodeSpecificFields[1])) >> 16)))
) : __bswap32_var(pq->pdu.ipdu.bhs.OpcodeSpecificFields[1]
)), pq->pdu.ipdu.bhs.opcode, (__builtin_constant_p(pq->
pdu.ipdu.bhs.itt) ? (((__uint32_t)((__uint16_t)(__builtin_constant_p
(((__uint32_t)(pq->pdu.ipdu.bhs.itt)) & 0xffff) ? (__uint16_t
)(((__uint16_t)(((__uint32_t)(pq->pdu.ipdu.bhs.itt)) &
0xffff)) << 8 | ((__uint16_t)(((__uint32_t)(pq->pdu
.ipdu.bhs.itt)) & 0xffff)) >> 8) : __bswap16_var(((
__uint32_t)(pq->pdu.ipdu.bhs.itt)) & 0xffff))) <<
16) | ((__uint16_t)(__builtin_constant_p(((__uint32_t)(pq->
pdu.ipdu.bhs.itt)) >> 16) ? (__uint16_t)(((__uint16_t)(
((__uint32_t)(pq->pdu.ipdu.bhs.itt)) >> 16)) <<
8 | ((__uint16_t)(((__uint32_t)(pq->pdu.ipdu.bhs.itt)) >>
16)) >> 8) : __bswap16_var(((__uint32_t)(pq->pdu.ipdu
.bhs.itt)) >> 16)))) : __bswap32_var(pq->pdu.ipdu.bhs
.itt)), (__builtin_constant_p(pq->pdu.ipdu.bhs.OpcodeSpecificFields
[2]) ? (((__uint32_t)((__uint16_t)(__builtin_constant_p(((__uint32_t
)(pq->pdu.ipdu.bhs.OpcodeSpecificFields[2])) & 0xffff)
? (__uint16_t)(((__uint16_t)(((__uint32_t)(pq->pdu.ipdu.bhs
.OpcodeSpecificFields[2])) & 0xffff)) << 8 | ((__uint16_t
)(((__uint32_t)(pq->pdu.ipdu.bhs.OpcodeSpecificFields[2]))
& 0xffff)) >> 8) : __bswap16_var(((__uint32_t)(pq->
pdu.ipdu.bhs.OpcodeSpecificFields[2])) & 0xffff))) <<
16) | ((__uint16_t)(__builtin_constant_p(((__uint32_t)(pq->
pdu.ipdu.bhs.OpcodeSpecificFields[2])) >> 16) ? (__uint16_t
)(((__uint16_t)(((__uint32_t)(pq->pdu.ipdu.bhs.OpcodeSpecificFields
[2])) >> 16)) << 8 | ((__uint16_t)(((__uint32_t)(
pq->pdu.ipdu.bhs.OpcodeSpecificFields[2])) >> 16)) >>
8) : __bswap16_var(((__uint32_t)(pq->pdu.ipdu.bhs.OpcodeSpecificFields
[2])) >> 16)))) : __bswap32_var(pq->pdu.ipdu.bhs.OpcodeSpecificFields
[2])), (intmax_t)pq->ts.sec); } while(0)
; i++;
322 uiomove(buf, strlen(buf), uio);
323 }
324 sprintf(buf, "%d/%d /---- csnd -----/\n", sp->stats.ncsnd, sp->stats.max_csnd);
325 i = 0;
326 uiomove(buf, strlen(buf), uio);
327 TAILQ_FOREACH(pq, &sp->csnd, pq_link)for ((pq) = (((&sp->csnd))->tqh_first); (pq); (pq) =
(((pq))->pq_link.tqe_next))
{
328 if(uio->uio_resid == 0)
329 return 0;
330 pukeit(i, pq)do { sprintf(buf, "%03d] %06x %02x %06x %06x %jd\n", i, (__builtin_constant_p
(pq->pdu.ipdu.bhs.OpcodeSpecificFields[1]) ? (((__uint32_t
)((__uint16_t)(__builtin_constant_p(((__uint32_t)(pq->pdu.
ipdu.bhs.OpcodeSpecificFields[1])) & 0xffff) ? (__uint16_t
)(((__uint16_t)(((__uint32_t)(pq->pdu.ipdu.bhs.OpcodeSpecificFields
[1])) & 0xffff)) << 8 | ((__uint16_t)(((__uint32_t)
(pq->pdu.ipdu.bhs.OpcodeSpecificFields[1])) & 0xffff))
>> 8) : __bswap16_var(((__uint32_t)(pq->pdu.ipdu.bhs
.OpcodeSpecificFields[1])) & 0xffff))) << 16) | ((__uint16_t
)(__builtin_constant_p(((__uint32_t)(pq->pdu.ipdu.bhs.OpcodeSpecificFields
[1])) >> 16) ? (__uint16_t)(((__uint16_t)(((__uint32_t)
(pq->pdu.ipdu.bhs.OpcodeSpecificFields[1])) >> 16)) <<
8 | ((__uint16_t)(((__uint32_t)(pq->pdu.ipdu.bhs.OpcodeSpecificFields
[1])) >> 16)) >> 8) : __bswap16_var(((__uint32_t)
(pq->pdu.ipdu.bhs.OpcodeSpecificFields[1])) >> 16)))
) : __bswap32_var(pq->pdu.ipdu.bhs.OpcodeSpecificFields[1]
)), pq->pdu.ipdu.bhs.opcode, (__builtin_constant_p(pq->
pdu.ipdu.bhs.itt) ? (((__uint32_t)((__uint16_t)(__builtin_constant_p
(((__uint32_t)(pq->pdu.ipdu.bhs.itt)) & 0xffff) ? (__uint16_t
)(((__uint16_t)(((__uint32_t)(pq->pdu.ipdu.bhs.itt)) &
0xffff)) << 8 | ((__uint16_t)(((__uint32_t)(pq->pdu
.ipdu.bhs.itt)) & 0xffff)) >> 8) : __bswap16_var(((
__uint32_t)(pq->pdu.ipdu.bhs.itt)) & 0xffff))) <<
16) | ((__uint16_t)(__builtin_constant_p(((__uint32_t)(pq->
pdu.ipdu.bhs.itt)) >> 16) ? (__uint16_t)(((__uint16_t)(
((__uint32_t)(pq->pdu.ipdu.bhs.itt)) >> 16)) <<
8 | ((__uint16_t)(((__uint32_t)(pq->pdu.ipdu.bhs.itt)) >>
16)) >> 8) : __bswap16_var(((__uint32_t)(pq->pdu.ipdu
.bhs.itt)) >> 16)))) : __bswap32_var(pq->pdu.ipdu.bhs
.itt)), (__builtin_constant_p(pq->pdu.ipdu.bhs.OpcodeSpecificFields
[2]) ? (((__uint32_t)((__uint16_t)(__builtin_constant_p(((__uint32_t
)(pq->pdu.ipdu.bhs.OpcodeSpecificFields[2])) & 0xffff)
? (__uint16_t)(((__uint16_t)(((__uint32_t)(pq->pdu.ipdu.bhs
.OpcodeSpecificFields[2])) & 0xffff)) << 8 | ((__uint16_t
)(((__uint32_t)(pq->pdu.ipdu.bhs.OpcodeSpecificFields[2]))
& 0xffff)) >> 8) : __bswap16_var(((__uint32_t)(pq->
pdu.ipdu.bhs.OpcodeSpecificFields[2])) & 0xffff))) <<
16) | ((__uint16_t)(__builtin_constant_p(((__uint32_t)(pq->
pdu.ipdu.bhs.OpcodeSpecificFields[2])) >> 16) ? (__uint16_t
)(((__uint16_t)(((__uint32_t)(pq->pdu.ipdu.bhs.OpcodeSpecificFields
[2])) >> 16)) << 8 | ((__uint16_t)(((__uint32_t)(
pq->pdu.ipdu.bhs.OpcodeSpecificFields[2])) >> 16)) >>
8) : __bswap16_var(((__uint32_t)(pq->pdu.ipdu.bhs.OpcodeSpecificFields
[2])) >> 16)))) : __bswap32_var(pq->pdu.ipdu.bhs.OpcodeSpecificFields
[2])), (intmax_t)pq->ts.sec); } while(0)
; i++;
331 uiomove(buf, strlen(buf), uio);
332 }
333 sprintf(buf, "%d/%d /---- wsnd -----/\n", sp->stats.nwsnd, sp->stats.max_wsnd);
334 i = 0;
335 uiomove(buf, strlen(buf), uio);
336 TAILQ_FOREACH(pq, &sp->wsnd, pq_link)for ((pq) = (((&sp->wsnd))->tqh_first); (pq); (pq) =
(((pq))->pq_link.tqe_next))
{
337 if(uio->uio_resid == 0)
338 return 0;
339 pukeit(i, pq)do { sprintf(buf, "%03d] %06x %02x %06x %06x %jd\n", i, (__builtin_constant_p
(pq->pdu.ipdu.bhs.OpcodeSpecificFields[1]) ? (((__uint32_t
)((__uint16_t)(__builtin_constant_p(((__uint32_t)(pq->pdu.
ipdu.bhs.OpcodeSpecificFields[1])) & 0xffff) ? (__uint16_t
)(((__uint16_t)(((__uint32_t)(pq->pdu.ipdu.bhs.OpcodeSpecificFields
[1])) & 0xffff)) << 8 | ((__uint16_t)(((__uint32_t)
(pq->pdu.ipdu.bhs.OpcodeSpecificFields[1])) & 0xffff))
>> 8) : __bswap16_var(((__uint32_t)(pq->pdu.ipdu.bhs
.OpcodeSpecificFields[1])) & 0xffff))) << 16) | ((__uint16_t
)(__builtin_constant_p(((__uint32_t)(pq->pdu.ipdu.bhs.OpcodeSpecificFields
[1])) >> 16) ? (__uint16_t)(((__uint16_t)(((__uint32_t)
(pq->pdu.ipdu.bhs.OpcodeSpecificFields[1])) >> 16)) <<
8 | ((__uint16_t)(((__uint32_t)(pq->pdu.ipdu.bhs.OpcodeSpecificFields
[1])) >> 16)) >> 8) : __bswap16_var(((__uint32_t)
(pq->pdu.ipdu.bhs.OpcodeSpecificFields[1])) >> 16)))
) : __bswap32_var(pq->pdu.ipdu.bhs.OpcodeSpecificFields[1]
)), pq->pdu.ipdu.bhs.opcode, (__builtin_constant_p(pq->
pdu.ipdu.bhs.itt) ? (((__uint32_t)((__uint16_t)(__builtin_constant_p
(((__uint32_t)(pq->pdu.ipdu.bhs.itt)) & 0xffff) ? (__uint16_t
)(((__uint16_t)(((__uint32_t)(pq->pdu.ipdu.bhs.itt)) &
0xffff)) << 8 | ((__uint16_t)(((__uint32_t)(pq->pdu
.ipdu.bhs.itt)) & 0xffff)) >> 8) : __bswap16_var(((
__uint32_t)(pq->pdu.ipdu.bhs.itt)) & 0xffff))) <<
16) | ((__uint16_t)(__builtin_constant_p(((__uint32_t)(pq->
pdu.ipdu.bhs.itt)) >> 16) ? (__uint16_t)(((__uint16_t)(
((__uint32_t)(pq->pdu.ipdu.bhs.itt)) >> 16)) <<
8 | ((__uint16_t)(((__uint32_t)(pq->pdu.ipdu.bhs.itt)) >>
16)) >> 8) : __bswap16_var(((__uint32_t)(pq->pdu.ipdu
.bhs.itt)) >> 16)))) : __bswap32_var(pq->pdu.ipdu.bhs
.itt)), (__builtin_constant_p(pq->pdu.ipdu.bhs.OpcodeSpecificFields
[2]) ? (((__uint32_t)((__uint16_t)(__builtin_constant_p(((__uint32_t
)(pq->pdu.ipdu.bhs.OpcodeSpecificFields[2])) & 0xffff)
? (__uint16_t)(((__uint16_t)(((__uint32_t)(pq->pdu.ipdu.bhs
.OpcodeSpecificFields[2])) & 0xffff)) << 8 | ((__uint16_t
)(((__uint32_t)(pq->pdu.ipdu.bhs.OpcodeSpecificFields[2]))
& 0xffff)) >> 8) : __bswap16_var(((__uint32_t)(pq->
pdu.ipdu.bhs.OpcodeSpecificFields[2])) & 0xffff))) <<
16) | ((__uint16_t)(__builtin_constant_p(((__uint32_t)(pq->
pdu.ipdu.bhs.OpcodeSpecificFields[2])) >> 16) ? (__uint16_t
)(((__uint16_t)(((__uint32_t)(pq->pdu.ipdu.bhs.OpcodeSpecificFields
[2])) >> 16)) << 8 | ((__uint16_t)(((__uint32_t)(
pq->pdu.ipdu.bhs.OpcodeSpecificFields[2])) >> 16)) >>
8) : __bswap16_var(((__uint32_t)(pq->pdu.ipdu.bhs.OpcodeSpecificFields
[2])) >> 16)))) : __bswap32_var(pq->pdu.ipdu.bhs.OpcodeSpecificFields
[2])), (intmax_t)pq->ts.sec); } while(0)
; i++;
340 uiomove(buf, strlen(buf), uio);
341 }
342 sprintf(buf, "%d/%d /---- isnd -----/\n", sp->stats.nisnd, sp->stats.max_isnd);
343 i = 0;
344 uiomove(buf, strlen(buf), uio);
345 TAILQ_FOREACH(pq, &sp->isnd, pq_link)for ((pq) = (((&sp->isnd))->tqh_first); (pq); (pq) =
(((pq))->pq_link.tqe_next))
{
346 if(uio->uio_resid == 0)
347 return 0;
348 pukeit(i, pq)do { sprintf(buf, "%03d] %06x %02x %06x %06x %jd\n", i, (__builtin_constant_p
(pq->pdu.ipdu.bhs.OpcodeSpecificFields[1]) ? (((__uint32_t
)((__uint16_t)(__builtin_constant_p(((__uint32_t)(pq->pdu.
ipdu.bhs.OpcodeSpecificFields[1])) & 0xffff) ? (__uint16_t
)(((__uint16_t)(((__uint32_t)(pq->pdu.ipdu.bhs.OpcodeSpecificFields
[1])) & 0xffff)) << 8 | ((__uint16_t)(((__uint32_t)
(pq->pdu.ipdu.bhs.OpcodeSpecificFields[1])) & 0xffff))
>> 8) : __bswap16_var(((__uint32_t)(pq->pdu.ipdu.bhs
.OpcodeSpecificFields[1])) & 0xffff))) << 16) | ((__uint16_t
)(__builtin_constant_p(((__uint32_t)(pq->pdu.ipdu.bhs.OpcodeSpecificFields
[1])) >> 16) ? (__uint16_t)(((__uint16_t)(((__uint32_t)
(pq->pdu.ipdu.bhs.OpcodeSpecificFields[1])) >> 16)) <<
8 | ((__uint16_t)(((__uint32_t)(pq->pdu.ipdu.bhs.OpcodeSpecificFields
[1])) >> 16)) >> 8) : __bswap16_var(((__uint32_t)
(pq->pdu.ipdu.bhs.OpcodeSpecificFields[1])) >> 16)))
) : __bswap32_var(pq->pdu.ipdu.bhs.OpcodeSpecificFields[1]
)), pq->pdu.ipdu.bhs.opcode, (__builtin_constant_p(pq->
pdu.ipdu.bhs.itt) ? (((__uint32_t)((__uint16_t)(__builtin_constant_p
(((__uint32_t)(pq->pdu.ipdu.bhs.itt)) & 0xffff) ? (__uint16_t
)(((__uint16_t)(((__uint32_t)(pq->pdu.ipdu.bhs.itt)) &
0xffff)) << 8 | ((__uint16_t)(((__uint32_t)(pq->pdu
.ipdu.bhs.itt)) & 0xffff)) >> 8) : __bswap16_var(((
__uint32_t)(pq->pdu.ipdu.bhs.itt)) & 0xffff))) <<
16) | ((__uint16_t)(__builtin_constant_p(((__uint32_t)(pq->
pdu.ipdu.bhs.itt)) >> 16) ? (__uint16_t)(((__uint16_t)(
((__uint32_t)(pq->pdu.ipdu.bhs.itt)) >> 16)) <<
8 | ((__uint16_t)(((__uint32_t)(pq->pdu.ipdu.bhs.itt)) >>
16)) >> 8) : __bswap16_var(((__uint32_t)(pq->pdu.ipdu
.bhs.itt)) >> 16)))) : __bswap32_var(pq->pdu.ipdu.bhs
.itt)), (__builtin_constant_p(pq->pdu.ipdu.bhs.OpcodeSpecificFields
[2]) ? (((__uint32_t)((__uint16_t)(__builtin_constant_p(((__uint32_t
)(pq->pdu.ipdu.bhs.OpcodeSpecificFields[2])) & 0xffff)
? (__uint16_t)(((__uint16_t)(((__uint32_t)(pq->pdu.ipdu.bhs
.OpcodeSpecificFields[2])) & 0xffff)) << 8 | ((__uint16_t
)(((__uint32_t)(pq->pdu.ipdu.bhs.OpcodeSpecificFields[2]))
& 0xffff)) >> 8) : __bswap16_var(((__uint32_t)(pq->
pdu.ipdu.bhs.OpcodeSpecificFields[2])) & 0xffff))) <<
16) | ((__uint16_t)(__builtin_constant_p(((__uint32_t)(pq->
pdu.ipdu.bhs.OpcodeSpecificFields[2])) >> 16) ? (__uint16_t
)(((__uint16_t)(((__uint32_t)(pq->pdu.ipdu.bhs.OpcodeSpecificFields
[2])) >> 16)) << 8 | ((__uint16_t)(((__uint32_t)(
pq->pdu.ipdu.bhs.OpcodeSpecificFields[2])) >> 16)) >>
8) : __bswap16_var(((__uint32_t)(pq->pdu.ipdu.bhs.OpcodeSpecificFields
[2])) >> 16)))) : __bswap32_var(pq->pdu.ipdu.bhs.OpcodeSpecificFields
[2])), (intmax_t)pq->ts.sec); } while(0)
; i++;
349 uiomove(buf, strlen(buf), uio);
350 }
351
352 sprintf(buf, "/---- Stats ---/\n");
353 uiomove(buf, strlen(buf), uio);
354
355 sprintf(buf, "recv=%d sent=%d\n", sp->stats.nrecv, sp->stats.nsent);
356 uiomove(buf, strlen(buf), uio);
357
358 sprintf(buf, "flags=%x pdus: alloc=%d max=%d\n",
359 sp->flags, sc->npdu_alloc, sc->npdu_max);
360 uiomove(buf, strlen(buf), uio);
361
362 sprintf(buf, "cws=%d last cmd=%x exp=%x max=%x stat=%x itt=%x\n",
363 sp->cws, sp->sn.cmd, sp->sn.expCmd, sp->sn.maxCmd, sp->sn.stat, sp->sn.itt);
364 uiomove(buf, strlen(buf), uio);
365
366 sprintf(buf, "/---- socket -----/\nso_count=%d so_state=%x\n", so->so_count, so->so_state);
367 uiomove(buf, strlen(buf), uio);
368
369 }
370#endif
371 return 0;
372}
373
374static int
375i_ping(struct cdev *dev)
376{
377 return 0;
378}
379/*
380 | low level I/O
381 */
382static int
383i_setsoc(isc_session_t *sp, int fd, struct thread *td)
384{
385 cap_rights_t rights;
386 int error = 0;
387
388 if(sp->soc != NULL((void *)0))
389 isc_stop_receiver(sp);
390
391 error = fget(td, fd, cap_rights_init(&rights, CAP_SOCK_CLIENT)__cap_rights_init(0, &rights, (((1ULL << (57 + (0))
) | (0x0000000080000000ULL)) | ((1ULL << (57 + (0))) | (
0x0000000100000000ULL)) | ((1ULL << (57 + (0))) | (0x0000000200000000ULL
)) | ((1ULL << (57 + (0))) | (0x0000000400000000ULL)) |
((1ULL << (57 + (0))) | (0x0000001000000000ULL)) | ((1ULL
<< (57 + (0))) | (0x0000000000000001ULL)) | ((1ULL <<
(57 + (0))) | (0x0000000000000002ULL)) | ((1ULL << (57
+ (0))) | (0x0000002000000000ULL)) | ((1ULL << (57 + (
0))) | (0x0000004000000000ULL))), 0ULL)
, &sp->fp);
392 if(error)
393 return error;
394
395 error = fgetsock(td, fd, cap_rights_init(&rights, CAP_SOCK_CLIENT)__cap_rights_init(0, &rights, (((1ULL << (57 + (0))
) | (0x0000000080000000ULL)) | ((1ULL << (57 + (0))) | (
0x0000000100000000ULL)) | ((1ULL << (57 + (0))) | (0x0000000200000000ULL
)) | ((1ULL << (57 + (0))) | (0x0000000400000000ULL)) |
((1ULL << (57 + (0))) | (0x0000001000000000ULL)) | ((1ULL
<< (57 + (0))) | (0x0000000000000001ULL)) | ((1ULL <<
(57 + (0))) | (0x0000000000000002ULL)) | ((1ULL << (57
+ (0))) | (0x0000002000000000ULL)) | ((1ULL << (57 + (
0))) | (0x0000004000000000ULL))), 0ULL)
,
396 &sp->soc, 0);
397 if(error == 0) {
398 sp->td = td;
399 isc_start_receiver(sp);
400 }
401 else {
402 fdrop(sp->fp, td)(refcount_release(&(sp->fp)->f_count) ? _fdrop((sp->
fp), (td)) : _fnoop())
;
403 sp->fp = NULL((void *)0);
404 }
405
406 return error;
407}
408
409static int
410i_send(struct cdev *dev, caddr_t arg, struct thread *td)
411{
412 isc_session_t *sp = dev->si_drv2;
413 caddr_t bp;
414 pduq_t *pq;
415 pdu_t *pp;
416 int n, error;
417
418 debug_called(8)do {if(8 <= iscsi_debug) printf("%s: called\n", __func__);
} while(0)
;
419
420 if(sp->soc == NULL((void *)0))
421 return ENOTCONN57;
422
423 if((pq = pdu_alloc(sp->isc, M_NOWAIT0x0001)) == NULL((void *)0))
424 return EAGAIN35;
425 pp = &pq->pdu;
426 pq->pdu = *(pdu_t *)arg;
427 if((error = i_prepPDU(sp, pq)) != 0)
428 goto out;
429
430 bp = NULL((void *)0);
431 if((pq->len - sizeof(union ipdu_u)) > 0) {
432 pq->buf = bp = malloc(pq->len - sizeof(union ipdu_u), M_ISCSIBUF, M_NOWAIT0x0001);
433 if(pq->buf == NULL((void *)0)) {
434 error = EAGAIN35;
435 goto out;
436 }
437 }
438 else
439 pq->buf = NULL((void *)0); // just in case?
440
441 sdebug(2, "len=%d ahs_len=%d ds_len=%d buf=%zu@%p",do {if(2 <= iscsi_debug) printf("%d] %s: " "len=%d ahs_len=%d ds_len=%d buf=%zu@%p"
"\n", sp->sid, __func__ , pq->len, pp->ahs_len, pp->
ds_len, pq->len - sizeof(union ipdu_u), bp);} while(0)
442 pq->len, pp->ahs_len, pp->ds_len, pq->len - sizeof(union ipdu_u), bp)do {if(2 <= iscsi_debug) printf("%d] %s: " "len=%d ahs_len=%d ds_len=%d buf=%zu@%p"
"\n", sp->sid, __func__ , pq->len, pp->ahs_len, pp->
ds_len, pq->len - sizeof(union ipdu_u), bp);} while(0)
;
443
444 if(pp->ahs_len) {
445 // XXX: never tested, looks suspicious
446 n = pp->ahs_len;
447 error = copyin(pp->ahs_addr, bp, n);
448 if(error != 0) {
449 sdebug(3, "copyin ahs: error=%d", error)do {if(3 <= iscsi_debug) printf("%d] %s: " "copyin ahs: error=%d"
"\n", sp->sid, __func__ , error);} while(0)
;
450 goto out;
451 }
452 pp->ahs_addr = (ahs_t *)bp;
453 bp += n;
454 }
455 if(pp->ds_len) {
456 n = pp->ds_len;
457 error = copyin(pp->ds_addr, bp, n);
458 if(error != 0) {
459 sdebug(3, "copyin ds: error=%d", error)do {if(3 <= iscsi_debug) printf("%d] %s: " "copyin ds: error=%d"
"\n", sp->sid, __func__ , error);} while(0)
;
460 goto out;
461 }
462 pp->ds_addr = bp;
463 bp += n;
464 while(n & 03) {
465 n++;
466 *bp++ = 0;
467 }
468 }
469
470 error = isc_qout(sp, pq);
471 if(error == 0)
472 wakeup(&sp->flags); // XXX: to 'push' proc_out ...
473out:
474 if(error)
475 pdu_free(sp->isc, pq);
476
477 return error;
478}
479
480static int
481i_recv(struct cdev *dev, caddr_t arg, struct thread *td)
482{
483 isc_session_t *sp = dev->si_drv2;
484 pduq_t *pq;
485 pdu_t *pp, *up;
486 caddr_t bp;
487 int error, mustfree, cnt;
488 size_t need, have, n;
489
490 debug_called(8)do {if(8 <= iscsi_debug) printf("%s: called\n", __func__);
} while(0)
;
491
492 if(sp == NULL((void *)0))
1
Assuming 'sp' is not equal to null
2
Taking false branch
493 return EIO5;
494
495 if(sp->soc == NULL((void *)0))
3
Taking false branch
496 return ENOTCONN57;
497 cnt = 6; // XXX: maybe the user can request a time out?
498 mtx_lock(&sp->rsp_mtx)__mtx_lock_flags(&((((&sp->rsp_mtx))))->mtx_lock
, ((0)), ("/usr/src/sys/modules/iscsi_initiator/../../dev/iscsi_initiator/iscsi.c"
), (498))
;
499 while((pq = TAILQ_FIRST(&sp->rsp)((&sp->rsp)->tqh_first)) == NULL((void *)0)) {
4
Loop condition is false. Execution continues on line 503
500 msleep(&sp->rsp, &sp->rsp_mtx, PRIBIO, "isc_rsp", hz*10)_sleep((&sp->rsp), &(&sp->rsp_mtx)->lock_object
, (((80) + 12)), ("isc_rsp"), tick_sbt * (hz*10), 0, 0x0100)
;
501 if(cnt-- == 0) break; // XXX: for now, needs work
502 }
503 if(pq != NULL((void *)0)) {
5
Taking true branch
504 sp->stats.nrsp--;
505 TAILQ_REMOVE(&sp->rsp, pq, pq_link)do { ; ; ; ; if (((((pq))->pq_link.tqe_next)) != ((void *)
0)) (((pq))->pq_link.tqe_next)->pq_link.tqe_prev = (pq)
->pq_link.tqe_prev; else { (&sp->rsp)->tqh_last =
(pq)->pq_link.tqe_prev; ; } *(pq)->pq_link.tqe_prev = (
((pq))->pq_link.tqe_next); ; ; ; } while (0)
;
506 }
507 mtx_unlock(&sp->rsp_mtx)__mtx_unlock_flags(&((((&sp->rsp_mtx))))->mtx_lock
, ((0)), ("/usr/src/sys/modules/iscsi_initiator/../../dev/iscsi_initiator/iscsi.c"
), (507))
;
508
509 sdebug(6, "cnt=%d", cnt)do {if(6 <= iscsi_debug) printf("%d] %s: " "cnt=%d" "\n", sp
->sid, __func__ , cnt);} while(0)
;
510
511 if(pq == NULL((void *)0)) {
6
Taking false branch
512 error = ENOTCONN57;
513 sdebug(3, "error=%d sp->flags=%x ", error, sp->flags)do {if(3 <= iscsi_debug) printf("%d] %s: " "error=%d sp->flags=%x "
"\n", sp->sid, __func__ , error, sp->flags);} while(0)
;
514 return error;
515 }
516 up = (pdu_t *)arg;
517 pp = &pq->pdu;
518 up->ipdu = pp->ipdu;
519 n = 0;
520 up->ds_len = 0;
521 up->ahs_len = 0;
522 error = 0;
523
524 if(pq->mp) {
7
Taking true branch
525 u_int len;
526
527 // Grr...
528 len = 0;
529 if(pp->ahs_len) {
8
Taking false branch
530 len += pp->ahs_len;
531 }
532 if(pp->ds_len) {
9
Taking true branch
533 len += pp->ds_len;
534 }
535
536 mustfree = 0;
537 if(len > pq->mp->m_len) {
10
Taking true branch
538 mustfree++;
539 bp = malloc(len, M_TMP, M_WAITOK0x0002);
540 sdebug(4, "need mbufcopy: %d", len)do {if(4 <= iscsi_debug) printf("%d] %s: " "need mbufcopy: %d"
"\n", sp->sid, __func__ , len);} while(0)
;
541 i_mbufcopy(pq->mp, bp, len);
11
Calling 'i_mbufcopy'
21
Returning from 'i_mbufcopy'
542 }
543 else
544 bp = mtod(pq->mp, caddr_t)((caddr_t)((pq->mp)->m_data));
545
546 if(pp->ahs_len) {
22
Taking false branch
547 need = pp->ahs_len;
548 n = MIN(up->ahs_size, need)(((up->ahs_size)<(need))?(up->ahs_size):(need));
549 error = copyout(bp, (caddr_t)up->ahs_addr, n);
550 up->ahs_len = n;
551 bp += need;
552 }
553 if(!error && pp->ds_len) {
23
Taking true branch
554 need = pp->ds_len;
555 if((have = up->ds_size) == 0) {
24
Taking false branch
556 have = up->ahs_size - n;
557 up->ds_addr = (caddr_t)up->ahs_addr + n;
558 }
559 n = MIN(have, need)(((have)<(need))?(have):(need));
560 error = copyout(bp, (caddr_t)up->ds_addr, n);
25
Copies out a struct with a partially unsanitized field
561 up->ds_len = n;
562 }
563
564 if(mustfree)
565 free(bp, M_TMP);
566 }
567
568 sdebug(6, "len=%d ahs_len=%d ds_len=%d", pq->len, pp->ahs_len, pp->ds_len)do {if(6 <= iscsi_debug) printf("%d] %s: " "len=%d ahs_len=%d ds_len=%d"
"\n", sp->sid, __func__ , pq->len, pp->ahs_len, pp->
ds_len);} while(0)
;
569
570 pdu_free(sp->isc, pq);
571
572 return error;
573}
574
575static int
576i_fullfeature(struct cdev *dev, int flag)
577{
578 isc_session_t *sp = dev->si_drv2;
579 int error;
580
581 sdebug(2, "flag=%d", flag)do {if(2 <= iscsi_debug) printf("%d] %s: " "flag=%d" "\n",
sp->sid, __func__ , flag);} while(0)
;
582
583 error = 0;
584 switch(flag) {
585 case 0: // stop
586 sp->flags &= ~ISC_FFPHASE(1 <<(8));
587 break;
588 case 1: // start
589 sp->flags |= ISC_FFPHASE(1 <<(8));
590 error = ic_init(sp);
591 break;
592 case 2: // restart
593 sp->flags |= ISC_FFPHASE(1 <<(8));
594 ism_restart(sp);
595 break;
596 }
597 return error;
598}
599
600static int
601i_create_session(struct cdev *dev, int *ndev)
602{
603 struct isc_softc *sc = dev->si_drv1;
604 isc_session_t *sp;
605 int error, n;
606
607 debug_called(8)do {if(8 <= iscsi_debug) printf("%s: called\n", __func__);
} while(0)
;
608
609 sp = malloc(sizeof(isc_session_t), M_ISCSI, M_WAITOK0x0002 | M_ZERO0x0100);
610 if(sp == NULL((void *)0))
611 return ENOMEM12;
612
613 sx_xlock(&sc->unit_sx)(void)_sx_xlock(((&sc->unit_sx)), 0, ("/usr/src/sys/modules/iscsi_initiator/../../dev/iscsi_initiator/iscsi.c"
), (613))
;
614 if((n = alloc_unr(sc->unit)) < 0) {
615 sx_unlock(&sc->unit_sx)do { if (((((&sc->unit_sx))->sx_lock & ~((0x01 |
0x02 | 0x04 | 0x08) & ~0x01)) == (uintptr_t)(__curthread
()))) _sx_xunlock(((&sc->unit_sx)), ("/usr/src/sys/modules/iscsi_initiator/../../dev/iscsi_initiator/iscsi.c"
), (615)); else _sx_sunlock(((&sc->unit_sx)), ("/usr/src/sys/modules/iscsi_initiator/../../dev/iscsi_initiator/iscsi.c"
), (615)); } while (0)
;
616 free(sp, M_ISCSI);
617 xdebug("too many sessions!")printf(">>> %s: " "too many sessions!" "\n", __func__
)
;
618 return EPERM1;
619 }
620 sx_unlock(&sc->unit_sx)do { if (((((&sc->unit_sx))->sx_lock & ~((0x01 |
0x02 | 0x04 | 0x08) & ~0x01)) == (uintptr_t)(__curthread
()))) _sx_xunlock(((&sc->unit_sx)), ("/usr/src/sys/modules/iscsi_initiator/../../dev/iscsi_initiator/iscsi.c"
), (620)); else _sx_sunlock(((&sc->unit_sx)), ("/usr/src/sys/modules/iscsi_initiator/../../dev/iscsi_initiator/iscsi.c"
), (620)); } while (0)
;
621
622 mtx_lock(&sc->isc_mtx)__mtx_lock_flags(&((((&sc->isc_mtx))))->mtx_lock
, ((0)), ("/usr/src/sys/modules/iscsi_initiator/../../dev/iscsi_initiator/iscsi.c"
), (622))
;
623 TAILQ_INSERT_TAIL(&sc->isc_sess, sp, sp_link)do { ; (((sp))->sp_link.tqe_next) = ((void *)0); (sp)->
sp_link.tqe_prev = (&sc->isc_sess)->tqh_last; *(&
sc->isc_sess)->tqh_last = (sp); (&sc->isc_sess)->
tqh_last = &(((sp))->sp_link.tqe_next); ; ; } while (0
)
;
624 isc->nsess++;
625 mtx_unlock(&sc->isc_mtx)__mtx_unlock_flags(&((((&sc->isc_mtx))))->mtx_lock
, ((0)), ("/usr/src/sys/modules/iscsi_initiator/../../dev/iscsi_initiator/iscsi.c"
), (625))
;
626
627 sp->dev = make_dev(&iscsi_cdevsw, n, UID_ROOT0, GID_WHEEL0, 0600, "iscsi%d", n);
628 *ndev = sp->sid = n;
629 sp->isc = sc;
630 sp->dev->si_drv1 = sc;
631 sp->dev->si_drv2 = sp;
632
633 sp->opt.maxRecvDataSegmentLength = 8192;
634 sp->opt.maxXmitDataSegmentLength = 8192;
635 sp->opt.maxBurstLength = 65536; // 64k
636 sp->opt.maxluns = ISCSI_MAX_LUNS128;
637
638 error = ism_start(sp);
639
640 return error;
641}
642
643#ifdef notused
644static void
645iscsi_counters(isc_session_t *sp)
646{
647 int h, r, s;
648 pduq_t *pq;
649
650#define _puke(i, pq) do {\
651 debug(2, "%03d] %06x %02x %x %ld %jd %x\n",\do {if(2 <= iscsi_debug) printf("%s: " "%03d] %06x %02x %x %ld %jd %x\n"
"\n", __func__ , i, (__builtin_constant_p(pq->pdu.ipdu.bhs
.OpcodeSpecificFields[1]) ? (((__uint32_t)((__uint16_t)(__builtin_constant_p
(((__uint32_t)(pq->pdu.ipdu.bhs.OpcodeSpecificFields[1])) &
0xffff) ? (__uint16_t)(((__uint16_t)(((__uint32_t)(pq->pdu
.ipdu.bhs.OpcodeSpecificFields[1])) & 0xffff)) << 8
| ((__uint16_t)(((__uint32_t)(pq->pdu.ipdu.bhs.OpcodeSpecificFields
[1])) & 0xffff)) >> 8) : __bswap16_var(((__uint32_t
)(pq->pdu.ipdu.bhs.OpcodeSpecificFields[1])) & 0xffff)
)) << 16) | ((__uint16_t)(__builtin_constant_p(((__uint32_t
)(pq->pdu.ipdu.bhs.OpcodeSpecificFields[1])) >> 16) ?
(__uint16_t)(((__uint16_t)(((__uint32_t)(pq->pdu.ipdu.bhs
.OpcodeSpecificFields[1])) >> 16)) << 8 | ((__uint16_t
)(((__uint32_t)(pq->pdu.ipdu.bhs.OpcodeSpecificFields[1]))
>> 16)) >> 8) : __bswap16_var(((__uint32_t)(pq->
pdu.ipdu.bhs.OpcodeSpecificFields[1])) >> 16)))) : __bswap32_var
(pq->pdu.ipdu.bhs.OpcodeSpecificFields[1])), pq->pdu.ipdu
.bhs.opcode, (__builtin_constant_p(pq->pdu.ipdu.bhs.itt) ?
(((__uint32_t)((__uint16_t)(__builtin_constant_p(((__uint32_t
)(pq->pdu.ipdu.bhs.itt)) & 0xffff) ? (__uint16_t)(((__uint16_t
)(((__uint32_t)(pq->pdu.ipdu.bhs.itt)) & 0xffff)) <<
8 | ((__uint16_t)(((__uint32_t)(pq->pdu.ipdu.bhs.itt)) &
0xffff)) >> 8) : __bswap16_var(((__uint32_t)(pq->pdu
.ipdu.bhs.itt)) & 0xffff))) << 16) | ((__uint16_t)(
__builtin_constant_p(((__uint32_t)(pq->pdu.ipdu.bhs.itt)) >>
16) ? (__uint16_t)(((__uint16_t)(((__uint32_t)(pq->pdu.ipdu
.bhs.itt)) >> 16)) << 8 | ((__uint16_t)(((__uint32_t
)(pq->pdu.ipdu.bhs.itt)) >> 16)) >> 8) : __bswap16_var
(((__uint32_t)(pq->pdu.ipdu.bhs.itt)) >> 16)))) : __bswap32_var
(pq->pdu.ipdu.bhs.itt)), (long)pq->ts.sec, pq->ts.frac
, pq->flags);} while(0)
652 i, ntohl( pq->pdu.ipdu.bhs.CmdSN), \do {if(2 <= iscsi_debug) printf("%s: " "%03d] %06x %02x %x %ld %jd %x\n"
"\n", __func__ , i, (__builtin_constant_p(pq->pdu.ipdu.bhs
.OpcodeSpecificFields[1]) ? (((__uint32_t)((__uint16_t)(__builtin_constant_p
(((__uint32_t)(pq->pdu.ipdu.bhs.OpcodeSpecificFields[1])) &
0xffff) ? (__uint16_t)(((__uint16_t)(((__uint32_t)(pq->pdu
.ipdu.bhs.OpcodeSpecificFields[1])) & 0xffff)) << 8
| ((__uint16_t)(((__uint32_t)(pq->pdu.ipdu.bhs.OpcodeSpecificFields
[1])) & 0xffff)) >> 8) : __bswap16_var(((__uint32_t
)(pq->pdu.ipdu.bhs.OpcodeSpecificFields[1])) & 0xffff)
)) << 16) | ((__uint16_t)(__builtin_constant_p(((__uint32_t
)(pq->pdu.ipdu.bhs.OpcodeSpecificFields[1])) >> 16) ?
(__uint16_t)(((__uint16_t)(((__uint32_t)(pq->pdu.ipdu.bhs
.OpcodeSpecificFields[1])) >> 16)) << 8 | ((__uint16_t
)(((__uint32_t)(pq->pdu.ipdu.bhs.OpcodeSpecificFields[1]))
>> 16)) >> 8) : __bswap16_var(((__uint32_t)(pq->
pdu.ipdu.bhs.OpcodeSpecificFields[1])) >> 16)))) : __bswap32_var
(pq->pdu.ipdu.bhs.OpcodeSpecificFields[1])), pq->pdu.ipdu
.bhs.opcode, (__builtin_constant_p(pq->pdu.ipdu.bhs.itt) ?
(((__uint32_t)((__uint16_t)(__builtin_constant_p(((__uint32_t
)(pq->pdu.ipdu.bhs.itt)) & 0xffff) ? (__uint16_t)(((__uint16_t
)(((__uint32_t)(pq->pdu.ipdu.bhs.itt)) & 0xffff)) <<
8 | ((__uint16_t)(((__uint32_t)(pq->pdu.ipdu.bhs.itt)) &
0xffff)) >> 8) : __bswap16_var(((__uint32_t)(pq->pdu
.ipdu.bhs.itt)) & 0xffff))) << 16) | ((__uint16_t)(
__builtin_constant_p(((__uint32_t)(pq->pdu.ipdu.bhs.itt)) >>
16) ? (__uint16_t)(((__uint16_t)(((__uint32_t)(pq->pdu.ipdu
.bhs.itt)) >> 16)) << 8 | ((__uint16_t)(((__uint32_t
)(pq->pdu.ipdu.bhs.itt)) >> 16)) >> 8) : __bswap16_var
(((__uint32_t)(pq->pdu.ipdu.bhs.itt)) >> 16)))) : __bswap32_var
(pq->pdu.ipdu.bhs.itt)), (long)pq->ts.sec, pq->ts.frac
, pq->flags);} while(0)
653 pq->pdu.ipdu.bhs.opcode, ntohl(pq->pdu.ipdu.bhs.itt),\do {if(2 <= iscsi_debug) printf("%s: " "%03d] %06x %02x %x %ld %jd %x\n"
"\n", __func__ , i, (__builtin_constant_p(pq->pdu.ipdu.bhs
.OpcodeSpecificFields[1]) ? (((__uint32_t)((__uint16_t)(__builtin_constant_p
(((__uint32_t)(pq->pdu.ipdu.bhs.OpcodeSpecificFields[1])) &
0xffff) ? (__uint16_t)(((__uint16_t)(((__uint32_t)(pq->pdu
.ipdu.bhs.OpcodeSpecificFields[1])) & 0xffff)) << 8
| ((__uint16_t)(((__uint32_t)(pq->pdu.ipdu.bhs.OpcodeSpecificFields
[1])) & 0xffff)) >> 8) : __bswap16_var(((__uint32_t
)(pq->pdu.ipdu.bhs.OpcodeSpecificFields[1])) & 0xffff)
)) << 16) | ((__uint16_t)(__builtin_constant_p(((__uint32_t
)(pq->pdu.ipdu.bhs.OpcodeSpecificFields[1])) >> 16) ?
(__uint16_t)(((__uint16_t)(((__uint32_t)(pq->pdu.ipdu.bhs
.OpcodeSpecificFields[1])) >> 16)) << 8 | ((__uint16_t
)(((__uint32_t)(pq->pdu.ipdu.bhs.OpcodeSpecificFields[1]))
>> 16)) >> 8) : __bswap16_var(((__uint32_t)(pq->
pdu.ipdu.bhs.OpcodeSpecificFields[1])) >> 16)))) : __bswap32_var
(pq->pdu.ipdu.bhs.OpcodeSpecificFields[1])), pq->pdu.ipdu
.bhs.opcode, (__builtin_constant_p(pq->pdu.ipdu.bhs.itt) ?
(((__uint32_t)((__uint16_t)(__builtin_constant_p(((__uint32_t
)(pq->pdu.ipdu.bhs.itt)) & 0xffff) ? (__uint16_t)(((__uint16_t
)(((__uint32_t)(pq->pdu.ipdu.bhs.itt)) & 0xffff)) <<
8 | ((__uint16_t)(((__uint32_t)(pq->pdu.ipdu.bhs.itt)) &
0xffff)) >> 8) : __bswap16_var(((__uint32_t)(pq->pdu
.ipdu.bhs.itt)) & 0xffff))) << 16) | ((__uint16_t)(
__builtin_constant_p(((__uint32_t)(pq->pdu.ipdu.bhs.itt)) >>
16) ? (__uint16_t)(((__uint16_t)(((__uint32_t)(pq->pdu.ipdu
.bhs.itt)) >> 16)) << 8 | ((__uint16_t)(((__uint32_t
)(pq->pdu.ipdu.bhs.itt)) >> 16)) >> 8) : __bswap16_var
(((__uint32_t)(pq->pdu.ipdu.bhs.itt)) >> 16)))) : __bswap32_var
(pq->pdu.ipdu.bhs.itt)), (long)pq->ts.sec, pq->ts.frac
, pq->flags);} while(0)
654 (long)pq->ts.sec, pq->ts.frac, pq->flags)do {if(2 <= iscsi_debug) printf("%s: " "%03d] %06x %02x %x %ld %jd %x\n"
"\n", __func__ , i, (__builtin_constant_p(pq->pdu.ipdu.bhs
.OpcodeSpecificFields[1]) ? (((__uint32_t)((__uint16_t)(__builtin_constant_p
(((__uint32_t)(pq->pdu.ipdu.bhs.OpcodeSpecificFields[1])) &
0xffff) ? (__uint16_t)(((__uint16_t)(((__uint32_t)(pq->pdu
.ipdu.bhs.OpcodeSpecificFields[1])) & 0xffff)) << 8
| ((__uint16_t)(((__uint32_t)(pq->pdu.ipdu.bhs.OpcodeSpecificFields
[1])) & 0xffff)) >> 8) : __bswap16_var(((__uint32_t
)(pq->pdu.ipdu.bhs.OpcodeSpecificFields[1])) & 0xffff)
)) << 16) | ((__uint16_t)(__builtin_constant_p(((__uint32_t
)(pq->pdu.ipdu.bhs.OpcodeSpecificFields[1])) >> 16) ?
(__uint16_t)(((__uint16_t)(((__uint32_t)(pq->pdu.ipdu.bhs
.OpcodeSpecificFields[1])) >> 16)) << 8 | ((__uint16_t
)(((__uint32_t)(pq->pdu.ipdu.bhs.OpcodeSpecificFields[1]))
>> 16)) >> 8) : __bswap16_var(((__uint32_t)(pq->
pdu.ipdu.bhs.OpcodeSpecificFields[1])) >> 16)))) : __bswap32_var
(pq->pdu.ipdu.bhs.OpcodeSpecificFields[1])), pq->pdu.ipdu
.bhs.opcode, (__builtin_constant_p(pq->pdu.ipdu.bhs.itt) ?
(((__uint32_t)((__uint16_t)(__builtin_constant_p(((__uint32_t
)(pq->pdu.ipdu.bhs.itt)) & 0xffff) ? (__uint16_t)(((__uint16_t
)(((__uint32_t)(pq->pdu.ipdu.bhs.itt)) & 0xffff)) <<
8 | ((__uint16_t)(((__uint32_t)(pq->pdu.ipdu.bhs.itt)) &
0xffff)) >> 8) : __bswap16_var(((__uint32_t)(pq->pdu
.ipdu.bhs.itt)) & 0xffff))) << 16) | ((__uint16_t)(
__builtin_constant_p(((__uint32_t)(pq->pdu.ipdu.bhs.itt)) >>
16) ? (__uint16_t)(((__uint16_t)(((__uint32_t)(pq->pdu.ipdu
.bhs.itt)) >> 16)) << 8 | ((__uint16_t)(((__uint32_t
)(pq->pdu.ipdu.bhs.itt)) >> 16)) >> 8) : __bswap16_var
(((__uint32_t)(pq->pdu.ipdu.bhs.itt)) >> 16)))) : __bswap32_var
(pq->pdu.ipdu.bhs.itt)), (long)pq->ts.sec, pq->ts.frac
, pq->flags);} while(0)
;\
655 } while(0)
656
657 h = r = s = 0;
658 TAILQ_FOREACH(pq, &sp->hld, pq_link)for ((pq) = (((&sp->hld))->tqh_first); (pq); (pq) =
(((pq))->pq_link.tqe_next))
{
659 _puke(h, pq);
660 h++;
661 }
662 TAILQ_FOREACH(pq, &sp->rsp, pq_link)for ((pq) = (((&sp->rsp))->tqh_first); (pq); (pq) =
(((pq))->pq_link.tqe_next))
r++;
663 TAILQ_FOREACH(pq, &sp->csnd, pq_link)for ((pq) = (((&sp->csnd))->tqh_first); (pq); (pq) =
(((pq))->pq_link.tqe_next))
s++;
664 TAILQ_FOREACH(pq, &sp->wsnd, pq_link)for ((pq) = (((&sp->wsnd))->tqh_first); (pq); (pq) =
(((pq))->pq_link.tqe_next))
s++;
665 TAILQ_FOREACH(pq, &sp->isnd, pq_link)for ((pq) = (((&sp->isnd))->tqh_first); (pq); (pq) =
(((pq))->pq_link.tqe_next))
s++;
666 debug(2, "hld=%d rsp=%d snd=%d", h, r, s)do {if(2 <= iscsi_debug) printf("%s: " "hld=%d rsp=%d snd=%d"
"\n", __func__ , h, r, s);} while(0)
;
667}
668#endif
669
670static void
671iscsi_shutdown(void *v)
672{
673 struct isc_softc *sc = v;
674 isc_session_t *sp;
675 int n;
676
677 debug_called(8)do {if(8 <= iscsi_debug) printf("%s: called\n", __func__);
} while(0)
;
678 if(sc == NULL((void *)0)) {
679 xdebug("sc is NULL!")printf(">>> %s: " "sc is NULL!" "\n", __func__);
680 return;
681 }
682#ifdef DO_EVENTHANDLER
683 if(sc->eh == NULL((void *)0))
684 debug(2, "sc->eh is NULL")do {if(2 <= iscsi_debug) printf("%s: " "sc->eh is NULL"
"\n", __func__);} while(0)
;
685 else {
686 EVENTHANDLER_DEREGISTER(shutdown_pre_sync, sc->eh)do { struct eventhandler_list *_el; if ((_el = eventhandler_find_list
("shutdown_pre_sync")) != ((void *)0)) eventhandler_deregister
(_el, sc->eh); } while(0)
;
687 debug(2, "done n=%d", sc->nsess)do {if(2 <= iscsi_debug) printf("%s: " "done n=%d" "\n", __func__
, sc->nsess);} while(0)
;
688 }
689#endif
690 n = 0;
691 TAILQ_FOREACH(sp, &sc->isc_sess, sp_link)for ((sp) = (((&sc->isc_sess))->tqh_first); (sp); (
sp) = (((sp))->sp_link.tqe_next))
{
692 debug(2, "%2d] sp->flags=0x%08x", n, sp->flags)do {if(2 <= iscsi_debug) printf("%s: " "%2d] sp->flags=0x%08x"
"\n", __func__ , n, sp->flags);} while(0)
;
693 n++;
694 }
695 debug(2, "done")do {if(2 <= iscsi_debug) printf("%s: " "done" "\n", __func__
);} while(0)
;
696}
697
698static void
699free_pdus(struct isc_softc *sc)
700{
701 debug_called(8)do {if(8 <= iscsi_debug) printf("%s: called\n", __func__);
} while(0)
;
702
703 if(sc->pdu_zone != NULL((void *)0)) {
704 uma_zdestroy(sc->pdu_zone);
705 sc->pdu_zone = NULL((void *)0);
706 }
707}
708
709static int
710iscsi_start(void)
711{
712 debug_called(8)do {if(8 <= iscsi_debug) printf("%s: called\n", __func__);
} while(0)
;
713
714 isc = malloc(sizeof(struct isc_softc), M_ISCSI, M_ZERO0x0100|M_WAITOK0x0002);
715 mtx_init(&isc->isc_mtx, "iscsi-isc", NULL, MTX_DEF)_mtx_init(&(&isc->isc_mtx)->mtx_lock, "iscsi-isc"
, ((void *)0), 0x00000000)
;
716
717 TAILQ_INIT(&isc->isc_sess)do { (((&isc->isc_sess))->tqh_first) = ((void *)0);
(&isc->isc_sess)->tqh_last = &(((&isc->
isc_sess))->tqh_first); ; } while (0)
;
718 /*
719 | now init the free pdu list
720 */
721 isc->pdu_zone = uma_zcreate("pdu", sizeof(pduq_t),
722 NULL((void *)0), NULL((void *)0), NULL((void *)0), NULL((void *)0),
723 0, 0);
724 uma_zone_set_max(isc->pdu_zone, max_pdus);
725 isc->unit = new_unrhdr(0, max_sessions-1, NULL((void *)0));
726 sx_init(&isc->unit_sx, "iscsi sx")sx_init_flags((&isc->unit_sx), ("iscsi sx"), 0);
727
728#ifdef DO_EVENTHANDLER
729 if((isc->eh = EVENTHANDLER_REGISTER(shutdown_pre_sync, iscsi_shutdown,eventhandler_register(((void *)0), "shutdown_pre_sync", iscsi_shutdown
, sc, 10000 -1)
730 sc, SHUTDOWN_PRI_DEFAULT-1)eventhandler_register(((void *)0), "shutdown_pre_sync", iscsi_shutdown
, sc, 10000 -1)
) == NULL((void *)0))
731 xdebug("shutdown event registration failed\n")printf(">>> %s: " "shutdown event registration failed\n"
"\n", __func__)
;
732#endif
733 /*
734 | sysctl stuff
735 */
736 sysctl_ctx_init(&isc->clist);
737 isc->oid = SYSCTL_ADD_NODE(&isc->clist,({ _Static_assert(((0x80000000) & 0xf) == 0 || ((0x80000000
) & 0xf) == 1, "compile-time assertion failed"); sysctl_add_oid
(&isc->clist, (&sysctl___net.oid_children), (-1), "iscsi_initiator"
, 1|(0x80000000), ((void *)0), 0, 0, "N", "iSCSI Subsystem");
})
738 SYSCTL_STATIC_CHILDREN(_net),({ _Static_assert(((0x80000000) & 0xf) == 0 || ((0x80000000
) & 0xf) == 1, "compile-time assertion failed"); sysctl_add_oid
(&isc->clist, (&sysctl___net.oid_children), (-1), "iscsi_initiator"
, 1|(0x80000000), ((void *)0), 0, 0, "N", "iSCSI Subsystem");
})
739 OID_AUTO,({ _Static_assert(((0x80000000) & 0xf) == 0 || ((0x80000000
) & 0xf) == 1, "compile-time assertion failed"); sysctl_add_oid
(&isc->clist, (&sysctl___net.oid_children), (-1), "iscsi_initiator"
, 1|(0x80000000), ((void *)0), 0, 0, "N", "iSCSI Subsystem");
})
740 "iscsi_initiator",({ _Static_assert(((0x80000000) & 0xf) == 0 || ((0x80000000
) & 0xf) == 1, "compile-time assertion failed"); sysctl_add_oid
(&isc->clist, (&sysctl___net.oid_children), (-1), "iscsi_initiator"
, 1|(0x80000000), ((void *)0), 0, 0, "N", "iSCSI Subsystem");
})
741 CTLFLAG_RD,({ _Static_assert(((0x80000000) & 0xf) == 0 || ((0x80000000
) & 0xf) == 1, "compile-time assertion failed"); sysctl_add_oid
(&isc->clist, (&sysctl___net.oid_children), (-1), "iscsi_initiator"
, 1|(0x80000000), ((void *)0), 0, 0, "N", "iSCSI Subsystem");
})
742 0,({ _Static_assert(((0x80000000) & 0xf) == 0 || ((0x80000000
) & 0xf) == 1, "compile-time assertion failed"); sysctl_add_oid
(&isc->clist, (&sysctl___net.oid_children), (-1), "iscsi_initiator"
, 1|(0x80000000), ((void *)0), 0, 0, "N", "iSCSI Subsystem");
})
743 "iSCSI Subsystem")({ _Static_assert(((0x80000000) & 0xf) == 0 || ((0x80000000
) & 0xf) == 1, "compile-time assertion failed"); sysctl_add_oid
(&isc->clist, (&sysctl___net.oid_children), (-1), "iscsi_initiator"
, 1|(0x80000000), ((void *)0), 0, 0, "N", "iSCSI Subsystem");
})
;
744
745 SYSCTL_ADD_STRING(&isc->clist,({ char *__arg = (iscsi_driver_version); _Static_assert(((0x80000000
) & 0xf) == 0 || ((0x80000000) & 0xf) == 3, "compile-time assertion failed"
); sysctl_add_oid(&isc->clist, (&(isc->oid)->
oid_children), (-1), "driver_version", 3|(0x80000000), __arg,
0, sysctl_handle_string, "A", "iscsi driver version"); })
746 SYSCTL_CHILDREN(isc->oid),({ char *__arg = (iscsi_driver_version); _Static_assert(((0x80000000
) & 0xf) == 0 || ((0x80000000) & 0xf) == 3, "compile-time assertion failed"
); sysctl_add_oid(&isc->clist, (&(isc->oid)->
oid_children), (-1), "driver_version", 3|(0x80000000), __arg,
0, sysctl_handle_string, "A", "iscsi driver version"); })
747 OID_AUTO,({ char *__arg = (iscsi_driver_version); _Static_assert(((0x80000000
) & 0xf) == 0 || ((0x80000000) & 0xf) == 3, "compile-time assertion failed"
); sysctl_add_oid(&isc->clist, (&(isc->oid)->
oid_children), (-1), "driver_version", 3|(0x80000000), __arg,
0, sysctl_handle_string, "A", "iscsi driver version"); })
748 "driver_version",({ char *__arg = (iscsi_driver_version); _Static_assert(((0x80000000
) & 0xf) == 0 || ((0x80000000) & 0xf) == 3, "compile-time assertion failed"
); sysctl_add_oid(&isc->clist, (&(isc->oid)->
oid_children), (-1), "driver_version", 3|(0x80000000), __arg,
0, sysctl_handle_string, "A", "iscsi driver version"); })
749 CTLFLAG_RD,({ char *__arg = (iscsi_driver_version); _Static_assert(((0x80000000
) & 0xf) == 0 || ((0x80000000) & 0xf) == 3, "compile-time assertion failed"
); sysctl_add_oid(&isc->clist, (&(isc->oid)->
oid_children), (-1), "driver_version", 3|(0x80000000), __arg,
0, sysctl_handle_string, "A", "iscsi driver version"); })
750 iscsi_driver_version,({ char *__arg = (iscsi_driver_version); _Static_assert(((0x80000000
) & 0xf) == 0 || ((0x80000000) & 0xf) == 3, "compile-time assertion failed"
); sysctl_add_oid(&isc->clist, (&(isc->oid)->
oid_children), (-1), "driver_version", 3|(0x80000000), __arg,
0, sysctl_handle_string, "A", "iscsi driver version"); })
751 0,({ char *__arg = (iscsi_driver_version); _Static_assert(((0x80000000
) & 0xf) == 0 || ((0x80000000) & 0xf) == 3, "compile-time assertion failed"
); sysctl_add_oid(&isc->clist, (&(isc->oid)->
oid_children), (-1), "driver_version", 3|(0x80000000), __arg,
0, sysctl_handle_string, "A", "iscsi driver version"); })
752 "iscsi driver version")({ char *__arg = (iscsi_driver_version); _Static_assert(((0x80000000
) & 0xf) == 0 || ((0x80000000) & 0xf) == 3, "compile-time assertion failed"
); sysctl_add_oid(&isc->clist, (&(isc->oid)->
oid_children), (-1), "driver_version", 3|(0x80000000), __arg,
0, sysctl_handle_string, "A", "iscsi driver version"); })
;
753
754 SYSCTL_ADD_STRING(&isc->clist,({ char *__arg = (isid); _Static_assert((((0x80000000|0x40000000
)) & 0xf) == 0 || (((0x80000000|0x40000000)) & 0xf) ==
3, "compile-time assertion failed"); sysctl_add_oid(&isc
->clist, (&(isc->oid)->oid_children), (-1), "isid"
, 3|((0x80000000|0x40000000)), __arg, 6+1, sysctl_handle_string
, "A", "initiator part of the Session Identifier"); })
755 SYSCTL_CHILDREN(isc->oid),({ char *__arg = (isid); _Static_assert((((0x80000000|0x40000000
)) & 0xf) == 0 || (((0x80000000|0x40000000)) & 0xf) ==
3, "compile-time assertion failed"); sysctl_add_oid(&isc
->clist, (&(isc->oid)->oid_children), (-1), "isid"
, 3|((0x80000000|0x40000000)), __arg, 6+1, sysctl_handle_string
, "A", "initiator part of the Session Identifier"); })
756 OID_AUTO,({ char *__arg = (isid); _Static_assert((((0x80000000|0x40000000
)) & 0xf) == 0 || (((0x80000000|0x40000000)) & 0xf) ==
3, "compile-time assertion failed"); sysctl_add_oid(&isc
->clist, (&(isc->oid)->oid_children), (-1), "isid"
, 3|((0x80000000|0x40000000)), __arg, 6+1, sysctl_handle_string
, "A", "initiator part of the Session Identifier"); })
757 "isid",({ char *__arg = (isid); _Static_assert((((0x80000000|0x40000000
)) & 0xf) == 0 || (((0x80000000|0x40000000)) & 0xf) ==
3, "compile-time assertion failed"); sysctl_add_oid(&isc
->clist, (&(isc->oid)->oid_children), (-1), "isid"
, 3|((0x80000000|0x40000000)), __arg, 6+1, sysctl_handle_string
, "A", "initiator part of the Session Identifier"); })
758 CTLFLAG_RW,({ char *__arg = (isid); _Static_assert((((0x80000000|0x40000000
)) & 0xf) == 0 || (((0x80000000|0x40000000)) & 0xf) ==
3, "compile-time assertion failed"); sysctl_add_oid(&isc
->clist, (&(isc->oid)->oid_children), (-1), "isid"
, 3|((0x80000000|0x40000000)), __arg, 6+1, sysctl_handle_string
, "A", "initiator part of the Session Identifier"); })
759 isid,({ char *__arg = (isid); _Static_assert((((0x80000000|0x40000000
)) & 0xf) == 0 || (((0x80000000|0x40000000)) & 0xf) ==
3, "compile-time assertion failed"); sysctl_add_oid(&isc
->clist, (&(isc->oid)->oid_children), (-1), "isid"
, 3|((0x80000000|0x40000000)), __arg, 6+1, sysctl_handle_string
, "A", "initiator part of the Session Identifier"); })
760 6+1,({ char *__arg = (isid); _Static_assert((((0x80000000|0x40000000
)) & 0xf) == 0 || (((0x80000000|0x40000000)) & 0xf) ==
3, "compile-time assertion failed"); sysctl_add_oid(&isc
->clist, (&(isc->oid)->oid_children), (-1), "isid"
, 3|((0x80000000|0x40000000)), __arg, 6+1, sysctl_handle_string
, "A", "initiator part of the Session Identifier"); })
761 "initiator part of the Session Identifier")({ char *__arg = (isid); _Static_assert((((0x80000000|0x40000000
)) & 0xf) == 0 || (((0x80000000|0x40000000)) & 0xf) ==
3, "compile-time assertion failed"); sysctl_add_oid(&isc
->clist, (&(isc->oid)->oid_children), (-1), "isid"
, 3|((0x80000000|0x40000000)), __arg, 6+1, sysctl_handle_string
, "A", "initiator part of the Session Identifier"); })
;
762
763 SYSCTL_ADD_INT(&isc->clist,({ int *__ptr = (&isc->nsess); _Static_assert(((0x80000000
) & 0xf) == 0 || ((0x80000000) & 0xf) == 2, "compile-time assertion failed"
); sysctl_add_oid(&isc->clist, (&(isc->oid)->
oid_children), (-1), "sessions", 2 | 0x00040000 | (0x80000000
), __ptr, sizeof(isc->nsess), sysctl_handle_int, "I", "number of active session"
); })
764 SYSCTL_CHILDREN(isc->oid),({ int *__ptr = (&isc->nsess); _Static_assert(((0x80000000
) & 0xf) == 0 || ((0x80000000) & 0xf) == 2, "compile-time assertion failed"
); sysctl_add_oid(&isc->clist, (&(isc->oid)->
oid_children), (-1), "sessions", 2 | 0x00040000 | (0x80000000
), __ptr, sizeof(isc->nsess), sysctl_handle_int, "I", "number of active session"
); })
765 OID_AUTO,({ int *__ptr = (&isc->nsess); _Static_assert(((0x80000000
) & 0xf) == 0 || ((0x80000000) & 0xf) == 2, "compile-time assertion failed"
); sysctl_add_oid(&isc->clist, (&(isc->oid)->
oid_children), (-1), "sessions", 2 | 0x00040000 | (0x80000000
), __ptr, sizeof(isc->nsess), sysctl_handle_int, "I", "number of active session"
); })
766 "sessions",({ int *__ptr = (&isc->nsess); _Static_assert(((0x80000000
) & 0xf) == 0 || ((0x80000000) & 0xf) == 2, "compile-time assertion failed"
); sysctl_add_oid(&isc->clist, (&(isc->oid)->
oid_children), (-1), "sessions", 2 | 0x00040000 | (0x80000000
), __ptr, sizeof(isc->nsess), sysctl_handle_int, "I", "number of active session"
); })
767 CTLFLAG_RD,({ int *__ptr = (&isc->nsess); _Static_assert(((0x80000000
) & 0xf) == 0 || ((0x80000000) & 0xf) == 2, "compile-time assertion failed"
); sysctl_add_oid(&isc->clist, (&(isc->oid)->
oid_children), (-1), "sessions", 2 | 0x00040000 | (0x80000000
), __ptr, sizeof(isc->nsess), sysctl_handle_int, "I", "number of active session"
); })
768 &isc->nsess,({ int *__ptr = (&isc->nsess); _Static_assert(((0x80000000
) & 0xf) == 0 || ((0x80000000) & 0xf) == 2, "compile-time assertion failed"
); sysctl_add_oid(&isc->clist, (&(isc->oid)->
oid_children), (-1), "sessions", 2 | 0x00040000 | (0x80000000
), __ptr, sizeof(isc->nsess), sysctl_handle_int, "I", "number of active session"
); })
769 sizeof(isc->nsess),({ int *__ptr = (&isc->nsess); _Static_assert(((0x80000000
) & 0xf) == 0 || ((0x80000000) & 0xf) == 2, "compile-time assertion failed"
); sysctl_add_oid(&isc->clist, (&(isc->oid)->
oid_children), (-1), "sessions", 2 | 0x00040000 | (0x80000000
), __ptr, sizeof(isc->nsess), sysctl_handle_int, "I", "number of active session"
); })
770 "number of active session")({ int *__ptr = (&isc->nsess); _Static_assert(((0x80000000
) & 0xf) == 0 || ((0x80000000) & 0xf) == 2, "compile-time assertion failed"
); sysctl_add_oid(&isc->clist, (&(isc->oid)->
oid_children), (-1), "sessions", 2 | 0x00040000 | (0x80000000
), __ptr, sizeof(isc->nsess), sysctl_handle_int, "I", "number of active session"
); })
;
771
772#ifdef ISCSI_INITIATOR_DEBUG1
773 mtx_init(&iscsi_dbg_mtx, "iscsi_dbg", NULL, MTX_DEF)_mtx_init(&(&iscsi_dbg_mtx)->mtx_lock, "iscsi_dbg"
, ((void *)0), 0x00000000)
;
774#endif
775
776 isc->dev = make_dev_credf(MAKEDEV_CHECKNAME0x20, &iscsi_cdevsw, max_sessions,
777 NULL((void *)0), UID_ROOT0, GID_WHEEL0, 0600, "iscsi");
778 if (isc->dev == NULL((void *)0)) {
779 xdebug("iscsi_initiator: make_dev_credf failed")printf(">>> %s: " "iscsi_initiator: make_dev_credf failed"
"\n", __func__)
;
780 return (EEXIST17);
781 }
782 isc->dev->si_drv1 = isc;
783
784 printf("iscsi: version %s\n", iscsi_driver_version);
785 return (0);
786}
787
788/*
789 | Notes:
790 | unload SHOULD fail if there is activity
791 | activity: there is/are active session/s
792 */
793static void
794iscsi_stop(void)
795{
796 isc_session_t *sp, *sp_tmp;
797
798 debug_called(8)do {if(8 <= iscsi_debug) printf("%s: called\n", __func__);
} while(0)
;
799
800 /*
801 | go through all the sessions
802 | Note: close should have done this ...
803 */
804 TAILQ_FOREACH_SAFE(sp, &isc->isc_sess, sp_link, sp_tmp)for ((sp) = (((&isc->isc_sess))->tqh_first); (sp) &&
((sp_tmp) = (((sp))->sp_link.tqe_next), 1); (sp) = (sp_tmp
))
{
805 //XXX: check for activity ...
806 ism_stop(sp);
807 }
808 mtx_destroy(&isc->isc_mtx)_mtx_destroy(&(&isc->isc_mtx)->mtx_lock);
809 sx_destroy(&isc->unit_sx);
810
811 free_pdus(isc);
812
813 if(isc->dev)
814 destroy_dev(isc->dev);
815
816 if(sysctl_ctx_free(&isc->clist))
817 xdebug("sysctl_ctx_free failed")printf(">>> %s: " "sysctl_ctx_free failed" "\n", __func__
)
;
818
819 iscsi_shutdown(isc); // XXX: check EVENTHANDLER_ ...
820
821#ifdef ISCSI_INITIATOR_DEBUG1
822 mtx_destroy(&iscsi_dbg_mtx)_mtx_destroy(&(&iscsi_dbg_mtx)->mtx_lock);
823#endif
824
825 free(isc, M_ISCSI);
826}
827
828static int
829iscsi_modevent(module_t mod, int what, void *arg)
830{
831 int error = 0;
832
833 debug_called(8)do {if(8 <= iscsi_debug) printf("%s: called\n", __func__);
} while(0)
;
834
835 switch(what) {
836 case MOD_LOAD:
837 error = iscsi_start();
838 break;
839
840 case MOD_QUIESCE:
841 if(isc->nsess) {
842 xdebug("iscsi module busy(nsess=%d), cannot unload", isc->nsess)printf(">>> %s: " "iscsi module busy(nsess=%d), cannot unload"
"\n", __func__ , isc->nsess)
;
843 log(LOG_ERR3, "iscsi module busy, cannot unload");
844 }
845 return isc->nsess;
846
847 case MOD_SHUTDOWN:
848 break;
849
850 case MOD_UNLOAD:
851 iscsi_stop();
852 break;
853
854 default:
855 break;
856 }
857 return (error);
858}
859
860moduledata_t iscsi_mod = {
861 "iscsi_initiator",
862 (modeventhand_t) iscsi_modevent,
863 0
864};
865
866#ifdef ISCSI_ROOT
867static void
868iscsi_rootconf(void)
869{
870#if 0
871 nfs_setup_diskless();
872 if (nfs_diskless_valid)
873 rootdevnames[0] = "nfs:";
874#endif
875 printf("** iscsi_rootconf **\n");
876}
877
878SYSINIT(cpu_rootconf1, SI_SUB_ROOT_CONF, SI_ORDER_FIRST, iscsi_rootconf, NULL)static struct sysinit cpu_rootconf1_sys_init = { SI_SUB_ROOT_CONF
, SI_ORDER_FIRST, (sysinit_cfunc_t)(sysinit_nfunc_t)iscsi_rootconf
, ((void *)(((void *)0))) }; __asm__(".globl " "__start_set_sysinit_set"
); __asm__(".globl " "__stop_set_sysinit_set"); static void const
* const __set_sysinit_set_sym_cpu_rootconf1_sys_init __attribute__
((__section__("set_" "sysinit_set"))) __attribute__((__used__
)) = &(cpu_rootconf1_sys_init)
879#endif
880
881DECLARE_MODULE(iscsi_initiator, iscsi_mod, SI_SUB_DRIVERS, SI_ORDER_MIDDLE)static struct mod_depend _iscsi_initiator_depend_on_kernel __attribute__
((__section__(".data"))) = { 1100122, 1100122, (((((1100122)+
((100000)-1))/(100000))*(100000)) - 1) }; static struct mod_metadata
_mod_metadata_md_iscsi_initiator_on_kernel = { 1, 1, &_iscsi_initiator_depend_on_kernel
, "kernel" }; __asm__(".globl " "__start_set_modmetadata_set"
); __asm__(".globl " "__stop_set_modmetadata_set"); static void
const * const __set_modmetadata_set_sym__mod_metadata_md_iscsi_initiator_on_kernel
__attribute__((__section__("set_" "modmetadata_set"))) __attribute__
((__used__)) = &(_mod_metadata_md_iscsi_initiator_on_kernel
); static struct mod_metadata _mod_metadata_md_iscsi_initiator
= { 1, 2, &iscsi_mod, "iscsi_initiator" }; __asm__(".globl "
"__start_set_modmetadata_set"); __asm__(".globl " "__stop_set_modmetadata_set"
); static void const * const __set_modmetadata_set_sym__mod_metadata_md_iscsi_initiator
__attribute__((__section__("set_" "modmetadata_set"))) __attribute__
((__used__)) = &(_mod_metadata_md_iscsi_initiator); static
struct sysinit iscsi_initiatormodule_sys_init = { SI_SUB_DRIVERS
, SI_ORDER_MIDDLE, (sysinit_cfunc_t)(sysinit_nfunc_t)module_register_init
, ((void *)(&iscsi_mod)) }; __asm__(".globl " "__start_set_sysinit_set"
); __asm__(".globl " "__stop_set_sysinit_set"); static void const
* const __set_sysinit_set_sym_iscsi_initiatormodule_sys_init
__attribute__((__section__("set_" "sysinit_set"))) __attribute__
((__used__)) = &(iscsi_initiatormodule_sys_init); struct __hack
;
882MODULE_DEPEND(iscsi_initiator, cam, 1, 1, 1)static struct mod_depend _iscsi_initiator_depend_on_cam __attribute__
((__section__(".data"))) = { 1, 1, 1 }; static struct mod_metadata
_mod_metadata_md_iscsi_initiator_on_cam = { 1, 1, &_iscsi_initiator_depend_on_cam
, "cam" }; __asm__(".globl " "__start_set_modmetadata_set"); __asm__
(".globl " "__stop_set_modmetadata_set"); static void const *
const __set_modmetadata_set_sym__mod_metadata_md_iscsi_initiator_on_cam
__attribute__((__section__("set_" "modmetadata_set"))) __attribute__
((__used__)) = &(_mod_metadata_md_iscsi_initiator_on_cam)
;

/usr/src/sys/dev/iscsi_initiator/iscsivar.h

1/*-
2 * Copyright (c) 2005-2011 Daniel Braniss <[email protected]>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 *
26 * $FreeBSD: releng/11.0/sys/dev/iscsi_initiator/iscsivar.h 234233 2012-04-13 18:21:56Z jpaetzel $
27 */
28
29/*
30 | $Id: iscsivar.h 743 2009-08-08 10:54:53Z danny $
31 */
32#define ISCSI_MAX_LUNS128 128 // don't touch this
33#if ISCSI_MAX_LUNS128 > 8
34/*
35 | for this to work
36 | sysctl kern.cam.cam_srch_hi=1
37 */
38#endif
39
40#ifndef ISCSI_INITIATOR_DEBUG1
41#define ISCSI_INITIATOR_DEBUG1 1
42#endif
43
44#ifdef ISCSI_INITIATOR_DEBUG1
45extern int iscsi_debug;
46#define debug(level, fmt, args...)do {if(level <= iscsi_debug) printf("%s: " fmt "\n", __func__
, args...);} while(0)
do {if(level <= iscsi_debug)\
47 printf("%s: " fmt "\n", __func__ , ##args);} while(0)
48#define sdebug(level, fmt, args...)do {if(level <= iscsi_debug) printf("%d] %s: " fmt "\n", sp
->sid, __func__ , args...);} while(0)
do {if(level <= iscsi_debug)\
49 printf("%d] %s: " fmt "\n", sp->sid, __func__ , ##args);} while(0)
50#define debug_called(level)do {if(level <= iscsi_debug) printf("%s: called\n", __func__
);} while(0)
do {if(level <= iscsi_debug)\
51 printf("%s: called\n", __func__);} while(0)
52#else
53#define debug(level, fmt, args...)do {if(level <= iscsi_debug) printf("%s: " fmt "\n", __func__
, args...);} while(0)
54#define debug_called(level)do {if(level <= iscsi_debug) printf("%s: called\n", __func__
);} while(0)
55#define sdebug(level, fmt, args...)do {if(level <= iscsi_debug) printf("%d] %s: " fmt "\n", sp
->sid, __func__ , args...);} while(0)
56#endif /* ISCSI_INITIATOR_DEBUG */
57
58#define xdebug(fmt, args...)printf(">>> %s: " fmt "\n", __func__ , args...) printf(">>> %s: " fmt "\n", __func__ , ##args)
59
60#define MAX_SESSIONS64 ISCSI_MAX_TARGETS64
61#define MAX_PDUS(64*256) (MAX_SESSIONS64*256) // XXX: at the moment this is arbitrary
62
63typedef uint32_t digest_t(const void *, int len, uint32_t ocrc);
64
65MALLOC_DECLARE(M_ISCSI)extern struct malloc_type M_ISCSI[1];
66MALLOC_DECLARE(M_ISCSIBUF)extern struct malloc_type M_ISCSIBUF[1];
67
68#define ISOK2DIG(dig, pp)((dig != ((void *)0)) && ((pp->ipdu.bhs.opcode &
0x1f) != 0x03))
((dig != NULL((void *)0)) && ((pp->ipdu.bhs.opcode & 0x1f) != ISCSI_LOGIN_CMD0x03))
69
70#ifndef BIT
71#define BIT(n)(1 <<(n)) (1 <<(n))
72#endif
73
74#define ISC_SM_RUN(1 <<(0)) BIT(0)(1 <<(0))
75#define ISC_SM_RUNNING(1 <<(1)) BIT(1)(1 <<(1))
76
77#define ISC_LINK_UP(1 <<(2)) BIT(2)(1 <<(2))
78#define ISC_CON_RUN(1 <<(3)) BIT(3)(1 <<(3))
79#define ISC_CON_RUNNING(1 <<(4)) BIT(4)(1 <<(4))
80#define ISC_KILL(1 <<(5)) BIT(5)(1 <<(5))
81#define ISC_OQNOTEMPTY(1 <<(6)) BIT(6)(1 <<(6))
82#define ISC_OWAITING(1 <<(7)) BIT(7)(1 <<(7))
83#define ISC_FFPHASE(1 <<(8)) BIT(8)(1 <<(8))
84
85#define ISC_CAMDEVS(1 <<(9)) BIT(9)(1 <<(9))
86#define ISC_SCANWAIT(1 <<(10)) BIT(10)(1 <<(10))
87
88#define ISC_MEMWAIT(1 <<(11)) BIT(11)(1 <<(11))
89#define ISC_SIGNALED(1 <<(12)) BIT(12)(1 <<(12))
90
91#define ISC_HOLD(1 <<(15)) BIT(15)(1 <<(15))
92#define ISC_HOLDED(1 <<(16)) BIT(16)(1 <<(16))
93
94#define ISC_SHUTDOWN(1 <<(31)) BIT(31)(1 <<(31))
95
96/*
97 | some stats
98 */
99struct i_stats {
100 int npdu; // number of pdus malloc'ed.
101 int nrecv; // unprocessed received pdus
102 int nsent; // sent pdus
103
104 int nrsp, max_rsp;
105 int nrsv, max_rsv;
106 int ncsnd, max_csnd;
107 int nisnd, max_isnd;
108 int nwsnd, max_wsnd;
109 int nhld, max_hld;
110
111 struct bintime t_sent;
112 struct bintime t_recv;
113};
114
115/*
116 | one per 'session'
117 */
118
119typedef TAILQ_HEAD(, pduq)struct { struct pduq *tqh_first; struct pduq **tqh_last; } queue_t;
120
121typedef struct isc_session {
122 TAILQ_ENTRY(isc_session)struct { struct isc_session *tqe_next; struct isc_session **tqe_prev
; }
sp_link;
123 int flags;
124 struct cdev *dev;
125 struct socket *soc;
126 struct file *fp;
127 struct thread *td;
128
129 struct proc *proc; // the userland process
130 int signal;
131 struct proc *soc_proc;
132 struct proc *stp; // the sm thread
133
134 struct isc_softc *isc;
135
136 digest_t *hdrDigest; // the digest alg. if any
137 digest_t *dataDigest; // the digest alg. if any
138
139 int sid; // Session ID
140 sn_t sn; // sequence number stuff;
141 int cws; // current window size
142
143 int target_nluns; // this and target_lun are
144 // hopefully temporal till I
145 // figure out a better way.
146 int target_lun[ISCSI_MAX_LUNS128/(sizeof(int)*8) + 1];
147
148 struct mtx rsp_mtx;
149 struct mtx rsv_mtx;
150 struct mtx snd_mtx;
151 struct mtx hld_mtx;
152 struct mtx io_mtx;
153 queue_t rsp;
154 queue_t rsv;
155 queue_t csnd;
156 queue_t isnd;
157 queue_t wsnd;
158 queue_t hld;
159
160 isc_opt_t opt; // negotiable values
161
162 struct i_stats stats;
163 bhs_t bhs;
164 struct uio uio;
165 struct iovec iov;
166 /*
167 | cam stuff
168 */
169 struct cam_sim *cam_sim;
170 struct cam_path *cam_path;
171 struct mtx cam_mtx;
172 /*
173 | sysctl stuff
174 */
175 struct sysctl_ctx_list clist;
176 struct sysctl_oid *oid;
177 int douio; //XXX: turn on/off uio on read
178} isc_session_t;
179
180typedef struct pduq {
181 TAILQ_ENTRY(pduq)struct { struct pduq *tqe_next; struct pduq **tqe_prev; } pq_link;
182
183 caddr_t buf;
184 u_int len; // the total length of the pdu
185 pdu_t pdu;
186 union ccb *ccb;
187
188 struct uio uio;
189 struct iovec iov[5]; // XXX: careful ...
190 struct mbuf *mp;
191 struct bintime ts;
192 queue_t *pduq;
193} pduq_t;
194/*
195 */
196struct isc_softc {
197 struct mtx isc_mtx;
198 TAILQ_HEAD(,isc_session)struct { struct isc_session *tqh_first; struct isc_session **
tqh_last; }
isc_sess;
199 int nsess;
200 struct cdev *dev;
201 char isid[6]; // Initiator Session ID (48 bits)
202 struct unrhdr *unit;
203 struct sx unit_sx;
204
205 uma_zone_t pdu_zone; // pool of free pdu's
206 TAILQ_HEAD(,pduq)struct { struct pduq *tqh_first; struct pduq **tqh_last; } freepdu;
207
208#ifdef ISCSI_INITIATOR_DEBUG1
209 int npdu_alloc, npdu_max; // for instrumentation
210#endif
211#ifdef DO_EVENTHANDLER
212 eventhandler_tag eh;
213#endif
214 /*
215 | sysctl stuff
216 */
217 struct sysctl_ctx_list clist;
218 struct sysctl_oid *oid;
219};
220
221#ifdef ISCSI_INITIATOR_DEBUG1
222extern struct mtx iscsi_dbg_mtx;
223#endif
224
225void isc_start_receiver(isc_session_t *sp);
226void isc_stop_receiver(isc_session_t *sp);
227
228int isc_sendPDU(isc_session_t *sp, pduq_t *pq);
229int isc_qout(isc_session_t *sp, pduq_t *pq);
230int i_prepPDU(isc_session_t *sp, pduq_t *pq);
231
232int ism_fullfeature(struct cdev *dev, int flag);
233
234int i_pdu_flush(isc_session_t *sc);
235int i_setopt(isc_session_t *sp, isc_opt_t *opt);
236void i_freeopt(isc_opt_t *opt);
237
238int ic_init(isc_session_t *sp);
239void ic_destroy(isc_session_t *sp);
240void ic_lost_target(isc_session_t *sp, int target);
241int ic_getCamVals(isc_session_t *sp, iscsi_cam_t *cp);
242
243void ism_recv(isc_session_t *sp, pduq_t *pq);
244int ism_start(isc_session_t *sp);
245void ism_restart(isc_session_t *sp);
246void ism_stop(isc_session_t *sp);
247
248int scsi_encap(struct cam_sim *sim, union ccb *ccb);
249int scsi_decap(isc_session_t *sp, pduq_t *opq, pduq_t *pq);
250void iscsi_r2t(isc_session_t *sp, pduq_t *opq, pduq_t *pq);
251void iscsi_done(isc_session_t *sp, pduq_t *opq, pduq_t *pq);
252void iscsi_reject(isc_session_t *sp, pduq_t *opq, pduq_t *pq);
253void iscsi_async(isc_session_t *sp, pduq_t *pq);
254void iscsi_cleanup(isc_session_t *sp);
255int iscsi_requeue(isc_session_t *sp);
256
257// Serial Number Arithmetic
258#define _MAXINCR0x7FFFFFFF 0x7FFFFFFF // 2 ^ 31 - 1
259#define SNA_GT(i1, i2)((i1 != i2) && ( (i1 < i2 && i2 - i1 > 0x7FFFFFFF
) || (i1 > i2 && i1 - i2 < 0x7FFFFFFF))?1: 0)
((i1 != i2) && (\
260 (i1 < i2 && i2 - i1 > _MAXINCR0x7FFFFFFF) ||\
261 (i1 > i2 && i1 - i2 < _MAXINCR0x7FFFFFFF))?1: 0)
262
263/*
264 | inlines
265 */
266#ifdef _CAM_CAM_XPT_SIM_H
267
268#if __FreeBSD_version1100122 < 600000
269#define CAM_LOCK(arg)
270#define CAM_ULOCK(arg)
271
272static __inline void
273XPT_DONE(isc_session_t *sp, union ccb *ccb)
274{
275 mtx_lock(&Giant)__mtx_lock_flags(&((((&Giant))))->mtx_lock, ((0)),
("/usr/src/sys/dev/iscsi_initiator/iscsivar.h"), (275))
;
276 xpt_done(ccb);
277 mtx_unlock(&Giant)__mtx_unlock_flags(&((((&Giant))))->mtx_lock, ((0)
), ("/usr/src/sys/dev/iscsi_initiator/iscsivar.h"), (277))
;
278}
279#elif __FreeBSD_version1100122 >= 700000
280#define CAM_LOCK(arg) mtx_lock(&arg->cam_mtx)__mtx_lock_flags(&((((&arg->cam_mtx))))->mtx_lock
, ((0)), ("/usr/src/sys/dev/iscsi_initiator/iscsivar.h"), (280
))
281#define CAM_UNLOCK(arg) mtx_unlock(&arg->cam_mtx)__mtx_unlock_flags(&((((&arg->cam_mtx))))->mtx_lock
, ((0)), ("/usr/src/sys/dev/iscsi_initiator/iscsivar.h"), (281
))
282
283static __inline void
284XPT_DONE(isc_session_t *sp, union ccb *ccb)
285{
286 CAM_LOCK(sp);
287 xpt_done(ccb);
288 CAM_UNLOCK(sp);
289}
290#else
291//__FreeBSD_version >= 600000
292#define CAM_LOCK(arg)
293#define CAM_UNLOCK(arg)
294#define XPT_DONE(ignore, arg) xpt_done(arg)
295#endif
296
297#endif /* _CAM_CAM_XPT_SIM_H */
298
299static __inline pduq_t *
300pdu_alloc(struct isc_softc *isc, int wait)
301{
302 pduq_t *pq;
303
304 pq = (pduq_t *)uma_zalloc(isc->pdu_zone, wait /* M_WAITOK or M_NOWAIT*/);
305 if(pq == NULL((void *)0)) {
306 debug(7, "out of mem")do {if(7 <= iscsi_debug) printf("%s: " "out of mem" "\n", __func__
);} while(0)
;
307 return NULL((void *)0);
308 }
309#ifdef ISCSI_INITIATOR_DEBUG1
310 mtx_lock(&iscsi_dbg_mtx)__mtx_lock_flags(&((((&iscsi_dbg_mtx))))->mtx_lock
, ((0)), ("/usr/src/sys/dev/iscsi_initiator/iscsivar.h"), (310
))
;
311 isc->npdu_alloc++;
312 if(isc->npdu_alloc > isc->npdu_max)
313 isc->npdu_max = isc->npdu_alloc;
314 mtx_unlock(&iscsi_dbg_mtx)__mtx_unlock_flags(&((((&iscsi_dbg_mtx))))->mtx_lock
, ((0)), ("/usr/src/sys/dev/iscsi_initiator/iscsivar.h"), (314
))
;
315#endif
316 memset(pq, 0, sizeof(pduq_t));
317
318 return pq;
319}
320
321static __inline void
322pdu_free(struct isc_softc *isc, pduq_t *pq)
323{
324 if(pq->mp)
325 m_freem(pq->mp);
326#ifdef NO_USE_MBUF
327 if(pq->buf != NULL((void *)0))
328 free(pq->buf, M_ISCSIBUF);
329#endif
330 uma_zfree(isc->pdu_zone, pq);
331#ifdef ISCSI_INITIATOR_DEBUG1
332 mtx_lock(&iscsi_dbg_mtx)__mtx_lock_flags(&((((&iscsi_dbg_mtx))))->mtx_lock
, ((0)), ("/usr/src/sys/dev/iscsi_initiator/iscsivar.h"), (332
))
;
333 isc->npdu_alloc--;
334 mtx_unlock(&iscsi_dbg_mtx)__mtx_unlock_flags(&((((&iscsi_dbg_mtx))))->mtx_lock
, ((0)), ("/usr/src/sys/dev/iscsi_initiator/iscsivar.h"), (334
))
;
335#endif
336}
337
338static __inline void
339i_nqueue_rsp(isc_session_t *sp, pduq_t *pq)
340{
341 mtx_lock(&sp->rsp_mtx)__mtx_lock_flags(&((((&sp->rsp_mtx))))->mtx_lock
, ((0)), ("/usr/src/sys/dev/iscsi_initiator/iscsivar.h"), (341
))
;
342 if(++sp->stats.nrsp > sp->stats.max_rsp)
343 sp->stats.max_rsp = sp->stats.nrsp;
344 TAILQ_INSERT_TAIL(&sp->rsp, pq, pq_link)do { ; (((pq))->pq_link.tqe_next) = ((void *)0); (pq)->
pq_link.tqe_prev = (&sp->rsp)->tqh_last; *(&sp->
rsp)->tqh_last = (pq); (&sp->rsp)->tqh_last = &
(((pq))->pq_link.tqe_next); ; ; } while (0)
;
345 mtx_unlock(&sp->rsp_mtx)__mtx_unlock_flags(&((((&sp->rsp_mtx))))->mtx_lock
, ((0)), ("/usr/src/sys/dev/iscsi_initiator/iscsivar.h"), (345
))
;
346}
347
348static __inline pduq_t *
349i_dqueue_rsp(isc_session_t *sp)
350{
351 pduq_t *pq;
352
353 mtx_lock(&sp->rsp_mtx)__mtx_lock_flags(&((((&sp->rsp_mtx))))->mtx_lock
, ((0)), ("/usr/src/sys/dev/iscsi_initiator/iscsivar.h"), (353
))
;
354 if((pq = TAILQ_FIRST(&sp->rsp)((&sp->rsp)->tqh_first)) != NULL((void *)0)) {
355 sp->stats.nrsp--;
356 TAILQ_REMOVE(&sp->rsp, pq, pq_link)do { ; ; ; ; if (((((pq))->pq_link.tqe_next)) != ((void *)
0)) (((pq))->pq_link.tqe_next)->pq_link.tqe_prev = (pq)
->pq_link.tqe_prev; else { (&sp->rsp)->tqh_last =
(pq)->pq_link.tqe_prev; ; } *(pq)->pq_link.tqe_prev = (
((pq))->pq_link.tqe_next); ; ; ; } while (0)
;
357 }
358 mtx_unlock(&sp->rsp_mtx)__mtx_unlock_flags(&((((&sp->rsp_mtx))))->mtx_lock
, ((0)), ("/usr/src/sys/dev/iscsi_initiator/iscsivar.h"), (358
))
;
359
360 return pq;
361}
362
363static __inline void
364i_nqueue_rsv(isc_session_t *sp, pduq_t *pq)
365{
366 mtx_lock(&sp->rsv_mtx)__mtx_lock_flags(&((((&sp->rsv_mtx))))->mtx_lock
, ((0)), ("/usr/src/sys/dev/iscsi_initiator/iscsivar.h"), (366
))
;
367 if(++sp->stats.nrsv > sp->stats.max_rsv)
368 sp->stats.max_rsv = sp->stats.nrsv;
369 TAILQ_INSERT_TAIL(&sp->rsv, pq, pq_link)do { ; (((pq))->pq_link.tqe_next) = ((void *)0); (pq)->
pq_link.tqe_prev = (&sp->rsv)->tqh_last; *(&sp->
rsv)->tqh_last = (pq); (&sp->rsv)->tqh_last = &
(((pq))->pq_link.tqe_next); ; ; } while (0)
;
370 mtx_unlock(&sp->rsv_mtx)__mtx_unlock_flags(&((((&sp->rsv_mtx))))->mtx_lock
, ((0)), ("/usr/src/sys/dev/iscsi_initiator/iscsivar.h"), (370
))
;
371}
372
373static __inline pduq_t *
374i_dqueue_rsv(isc_session_t *sp)
375{
376 pduq_t *pq;
377
378 mtx_lock(&sp->rsv_mtx)__mtx_lock_flags(&((((&sp->rsv_mtx))))->mtx_lock
, ((0)), ("/usr/src/sys/dev/iscsi_initiator/iscsivar.h"), (378
))
;
379 if((pq = TAILQ_FIRST(&sp->rsv)((&sp->rsv)->tqh_first)) != NULL((void *)0)) {
380 sp->stats.nrsv--;
381 TAILQ_REMOVE(&sp->rsv, pq, pq_link)do { ; ; ; ; if (((((pq))->pq_link.tqe_next)) != ((void *)
0)) (((pq))->pq_link.tqe_next)->pq_link.tqe_prev = (pq)
->pq_link.tqe_prev; else { (&sp->rsv)->tqh_last =
(pq)->pq_link.tqe_prev; ; } *(pq)->pq_link.tqe_prev = (
((pq))->pq_link.tqe_next); ; ; ; } while (0)
;
382 }
383 mtx_unlock(&sp->rsv_mtx)__mtx_unlock_flags(&((((&sp->rsv_mtx))))->mtx_lock
, ((0)), ("/usr/src/sys/dev/iscsi_initiator/iscsivar.h"), (383
))
;
384
385 return pq;
386}
387
388static __inline void
389i_nqueue_csnd(isc_session_t *sp, pduq_t *pq)
390{
391 mtx_lock(&sp->snd_mtx)__mtx_lock_flags(&((((&sp->snd_mtx))))->mtx_lock
, ((0)), ("/usr/src/sys/dev/iscsi_initiator/iscsivar.h"), (391
))
;
392 if(++sp->stats.ncsnd > sp->stats.max_csnd)
393 sp->stats.max_csnd = sp->stats.ncsnd;
394 TAILQ_INSERT_TAIL(&sp->csnd, pq, pq_link)do { ; (((pq))->pq_link.tqe_next) = ((void *)0); (pq)->
pq_link.tqe_prev = (&sp->csnd)->tqh_last; *(&sp
->csnd)->tqh_last = (pq); (&sp->csnd)->tqh_last
= &(((pq))->pq_link.tqe_next); ; ; } while (0)
;
395 mtx_unlock(&sp->snd_mtx)__mtx_unlock_flags(&((((&sp->snd_mtx))))->mtx_lock
, ((0)), ("/usr/src/sys/dev/iscsi_initiator/iscsivar.h"), (395
))
;
396}
397
398static __inline pduq_t *
399i_dqueue_csnd(isc_session_t *sp)
400{
401 pduq_t *pq;
402
403 mtx_lock(&sp->snd_mtx)__mtx_lock_flags(&((((&sp->snd_mtx))))->mtx_lock
, ((0)), ("/usr/src/sys/dev/iscsi_initiator/iscsivar.h"), (403
))
;
404 if((pq = TAILQ_FIRST(&sp->csnd)((&sp->csnd)->tqh_first)) != NULL((void *)0)) {
405 sp->stats.ncsnd--;
406 TAILQ_REMOVE(&sp->csnd, pq, pq_link)do { ; ; ; ; if (((((pq))->pq_link.tqe_next)) != ((void *)
0)) (((pq))->pq_link.tqe_next)->pq_link.tqe_prev = (pq)
->pq_link.tqe_prev; else { (&sp->csnd)->tqh_last
= (pq)->pq_link.tqe_prev; ; } *(pq)->pq_link.tqe_prev =
(((pq))->pq_link.tqe_next); ; ; ; } while (0)
;
407 }
408 mtx_unlock(&sp->snd_mtx)__mtx_unlock_flags(&((((&sp->snd_mtx))))->mtx_lock
, ((0)), ("/usr/src/sys/dev/iscsi_initiator/iscsivar.h"), (408
))
;
409
410 return pq;
411}
412
413static __inline void
414i_nqueue_isnd(isc_session_t *sp, pduq_t *pq)
415{
416 mtx_lock(&sp->snd_mtx)__mtx_lock_flags(&((((&sp->snd_mtx))))->mtx_lock
, ((0)), ("/usr/src/sys/dev/iscsi_initiator/iscsivar.h"), (416
))
;
417 if(++sp->stats.nisnd > sp->stats.max_isnd)
418 sp->stats.max_isnd = sp->stats.nisnd;
419 TAILQ_INSERT_TAIL(&sp->isnd, pq, pq_link)do { ; (((pq))->pq_link.tqe_next) = ((void *)0); (pq)->
pq_link.tqe_prev = (&sp->isnd)->tqh_last; *(&sp
->isnd)->tqh_last = (pq); (&sp->isnd)->tqh_last
= &(((pq))->pq_link.tqe_next); ; ; } while (0)
;
420 mtx_unlock(&sp->snd_mtx)__mtx_unlock_flags(&((((&sp->snd_mtx))))->mtx_lock
, ((0)), ("/usr/src/sys/dev/iscsi_initiator/iscsivar.h"), (420
))
;
421}
422
423static __inline pduq_t *
424i_dqueue_isnd(isc_session_t *sp)
425{
426 pduq_t *pq;
427
428 mtx_lock(&sp->snd_mtx)__mtx_lock_flags(&((((&sp->snd_mtx))))->mtx_lock
, ((0)), ("/usr/src/sys/dev/iscsi_initiator/iscsivar.h"), (428
))
;
429 if((pq = TAILQ_FIRST(&sp->isnd)((&sp->isnd)->tqh_first)) != NULL((void *)0)) {
430 sp->stats.nisnd--;
431 TAILQ_REMOVE(&sp->isnd, pq, pq_link)do { ; ; ; ; if (((((pq))->pq_link.tqe_next)) != ((void *)
0)) (((pq))->pq_link.tqe_next)->pq_link.tqe_prev = (pq)
->pq_link.tqe_prev; else { (&sp->isnd)->tqh_last
= (pq)->pq_link.tqe_prev; ; } *(pq)->pq_link.tqe_prev =
(((pq))->pq_link.tqe_next); ; ; ; } while (0)
;
432 }
433 mtx_unlock(&sp->snd_mtx)__mtx_unlock_flags(&((((&sp->snd_mtx))))->mtx_lock
, ((0)), ("/usr/src/sys/dev/iscsi_initiator/iscsivar.h"), (433
))
;
434
435 return pq;
436}
437
438static __inline void
439i_nqueue_wsnd(isc_session_t *sp, pduq_t *pq)
440{
441 mtx_lock(&sp->snd_mtx)__mtx_lock_flags(&((((&sp->snd_mtx))))->mtx_lock
, ((0)), ("/usr/src/sys/dev/iscsi_initiator/iscsivar.h"), (441
))
;
442 if(++sp->stats.nwsnd > sp->stats.max_wsnd)
443 sp->stats.max_wsnd = sp->stats.nwsnd;
444 TAILQ_INSERT_TAIL(&sp->wsnd, pq, pq_link)do { ; (((pq))->pq_link.tqe_next) = ((void *)0); (pq)->
pq_link.tqe_prev = (&sp->wsnd)->tqh_last; *(&sp
->wsnd)->tqh_last = (pq); (&sp->wsnd)->tqh_last
= &(((pq))->pq_link.tqe_next); ; ; } while (0)
;
445 mtx_unlock(&sp->snd_mtx)__mtx_unlock_flags(&((((&sp->snd_mtx))))->mtx_lock
, ((0)), ("/usr/src/sys/dev/iscsi_initiator/iscsivar.h"), (445
))
;
446}
447
448static __inline pduq_t *
449i_dqueue_wsnd(isc_session_t *sp)
450{
451 pduq_t *pq;
452
453 mtx_lock(&sp->snd_mtx)__mtx_lock_flags(&((((&sp->snd_mtx))))->mtx_lock
, ((0)), ("/usr/src/sys/dev/iscsi_initiator/iscsivar.h"), (453
))
;
454 if((pq = TAILQ_FIRST(&sp->wsnd)((&sp->wsnd)->tqh_first)) != NULL((void *)0)) {
455 sp->stats.nwsnd--;
456 TAILQ_REMOVE(&sp->wsnd, pq, pq_link)do { ; ; ; ; if (((((pq))->pq_link.tqe_next)) != ((void *)
0)) (((pq))->pq_link.tqe_next)->pq_link.tqe_prev = (pq)
->pq_link.tqe_prev; else { (&sp->wsnd)->tqh_last
= (pq)->pq_link.tqe_prev; ; } *(pq)->pq_link.tqe_prev =
(((pq))->pq_link.tqe_next); ; ; ; } while (0)
;
457 }
458 mtx_unlock(&sp->snd_mtx)__mtx_unlock_flags(&((((&sp->snd_mtx))))->mtx_lock
, ((0)), ("/usr/src/sys/dev/iscsi_initiator/iscsivar.h"), (458
))
;
459
460 return pq;
461}
462
463static __inline pduq_t *
464i_dqueue_snd(isc_session_t *sp, int which)
465{
466 pduq_t *pq;
467
468 pq = NULL((void *)0);
469 mtx_lock(&sp->snd_mtx)__mtx_lock_flags(&((((&sp->snd_mtx))))->mtx_lock
, ((0)), ("/usr/src/sys/dev/iscsi_initiator/iscsivar.h"), (469
))
;
470 if((which & BIT(0)(1 <<(0))) && (pq = TAILQ_FIRST(&sp->isnd)((&sp->isnd)->tqh_first)) != NULL((void *)0)) {
471 sp->stats.nisnd--;
472 TAILQ_REMOVE(&sp->isnd, pq, pq_link)do { ; ; ; ; if (((((pq))->pq_link.tqe_next)) != ((void *)
0)) (((pq))->pq_link.tqe_next)->pq_link.tqe_prev = (pq)
->pq_link.tqe_prev; else { (&sp->isnd)->tqh_last
= (pq)->pq_link.tqe_prev; ; } *(pq)->pq_link.tqe_prev =
(((pq))->pq_link.tqe_next); ; ; ; } while (0)
;
473 pq->pduq = &sp->isnd; // remember where you came from
474 } else
475 if((which & BIT(1)(1 <<(1))) && (pq = TAILQ_FIRST(&sp->wsnd)((&sp->wsnd)->tqh_first)) != NULL((void *)0)) {
476 sp->stats.nwsnd--;
477 TAILQ_REMOVE(&sp->wsnd, pq, pq_link)do { ; ; ; ; if (((((pq))->pq_link.tqe_next)) != ((void *)
0)) (((pq))->pq_link.tqe_next)->pq_link.tqe_prev = (pq)
->pq_link.tqe_prev; else { (&sp->wsnd)->tqh_last
= (pq)->pq_link.tqe_prev; ; } *(pq)->pq_link.tqe_prev =
(((pq))->pq_link.tqe_next); ; ; ; } while (0)
;
478 pq->pduq = &sp->wsnd; // remember where you came from
479 } else
480 if((which & BIT(2)(1 <<(2))) && (pq = TAILQ_FIRST(&sp->csnd)((&sp->csnd)->tqh_first)) != NULL((void *)0)) {
481 sp->stats.ncsnd--;
482 TAILQ_REMOVE(&sp->csnd, pq, pq_link)do { ; ; ; ; if (((((pq))->pq_link.tqe_next)) != ((void *)
0)) (((pq))->pq_link.tqe_next)->pq_link.tqe_prev = (pq)
->pq_link.tqe_prev; else { (&sp->csnd)->tqh_last
= (pq)->pq_link.tqe_prev; ; } *(pq)->pq_link.tqe_prev =
(((pq))->pq_link.tqe_next); ; ; ; } while (0)
;
483 pq->pduq = &sp->csnd; // remember where you came from
484 }
485 mtx_unlock(&sp->snd_mtx)__mtx_unlock_flags(&((((&sp->snd_mtx))))->mtx_lock
, ((0)), ("/usr/src/sys/dev/iscsi_initiator/iscsivar.h"), (485
))
;
486
487 return pq;
488}
489
490static __inline void
491i_rqueue_pdu(isc_session_t *sp, pduq_t *pq)
492{
493 mtx_lock(&sp->snd_mtx)__mtx_lock_flags(&((((&sp->snd_mtx))))->mtx_lock
, ((0)), ("/usr/src/sys/dev/iscsi_initiator/iscsivar.h"), (493
))
;
494 KASSERT(pq->pduq != NULL, ("pq->pduq is NULL"))do { } while (0);
495 TAILQ_INSERT_TAIL(pq->pduq, pq, pq_link)do { ; (((pq))->pq_link.tqe_next) = ((void *)0); (pq)->
pq_link.tqe_prev = (pq->pduq)->tqh_last; *(pq->pduq)
->tqh_last = (pq); (pq->pduq)->tqh_last = &(((pq
))->pq_link.tqe_next); ; ; } while (0)
;
496 mtx_unlock(&sp->snd_mtx)__mtx_unlock_flags(&((((&sp->snd_mtx))))->mtx_lock
, ((0)), ("/usr/src/sys/dev/iscsi_initiator/iscsivar.h"), (496
))
;
497}
498
499/*
500 | Waiting for ACK (or something :-)
501 */
502static __inline void
503i_nqueue_hld(isc_session_t *sp, pduq_t *pq)
504{
505 getbintime(&pq->ts);
506 mtx_lock(&sp->hld_mtx)__mtx_lock_flags(&((((&sp->hld_mtx))))->mtx_lock
, ((0)), ("/usr/src/sys/dev/iscsi_initiator/iscsivar.h"), (506
))
;
507 if(++sp->stats.nhld > sp->stats.max_hld)
508 sp->stats.max_hld = sp->stats.nhld;
509 TAILQ_INSERT_TAIL(&sp->hld, pq, pq_link)do { ; (((pq))->pq_link.tqe_next) = ((void *)0); (pq)->
pq_link.tqe_prev = (&sp->hld)->tqh_last; *(&sp->
hld)->tqh_last = (pq); (&sp->hld)->tqh_last = &
(((pq))->pq_link.tqe_next); ; ; } while (0)
;
510 mtx_unlock(&sp->hld_mtx)__mtx_unlock_flags(&((((&sp->hld_mtx))))->mtx_lock
, ((0)), ("/usr/src/sys/dev/iscsi_initiator/iscsivar.h"), (510
))
;
511 return;
512}
513
514static __inline void
515i_remove_hld(isc_session_t *sp, pduq_t *pq)
516{
517 mtx_lock(&sp->hld_mtx)__mtx_lock_flags(&((((&sp->hld_mtx))))->mtx_lock
, ((0)), ("/usr/src/sys/dev/iscsi_initiator/iscsivar.h"), (517
))
;
518 sp->stats.nhld--;
519 TAILQ_REMOVE(&sp->hld, pq, pq_link)do { ; ; ; ; if (((((pq))->pq_link.tqe_next)) != ((void *)
0)) (((pq))->pq_link.tqe_next)->pq_link.tqe_prev = (pq)
->pq_link.tqe_prev; else { (&sp->hld)->tqh_last =
(pq)->pq_link.tqe_prev; ; } *(pq)->pq_link.tqe_prev = (
((pq))->pq_link.tqe_next); ; ; ; } while (0)
;
520 mtx_unlock(&sp->hld_mtx)__mtx_unlock_flags(&((((&sp->hld_mtx))))->mtx_lock
, ((0)), ("/usr/src/sys/dev/iscsi_initiator/iscsivar.h"), (520
))
;
521}
522
523static __inline pduq_t *
524i_dqueue_hld(isc_session_t *sp)
525{
526 pduq_t *pq;
527
528 mtx_lock(&sp->hld_mtx)__mtx_lock_flags(&((((&sp->hld_mtx))))->mtx_lock
, ((0)), ("/usr/src/sys/dev/iscsi_initiator/iscsivar.h"), (528
))
;
529 if((pq = TAILQ_FIRST(&sp->hld)((&sp->hld)->tqh_first)) != NULL((void *)0)) {
530 sp->stats.nhld--;
531 TAILQ_REMOVE(&sp->hld, pq, pq_link)do { ; ; ; ; if (((((pq))->pq_link.tqe_next)) != ((void *)
0)) (((pq))->pq_link.tqe_next)->pq_link.tqe_prev = (pq)
->pq_link.tqe_prev; else { (&sp->hld)->tqh_last =
(pq)->pq_link.tqe_prev; ; } *(pq)->pq_link.tqe_prev = (
((pq))->pq_link.tqe_next); ; ; ; } while (0)
;
532 }
533 mtx_unlock(&sp->hld_mtx)__mtx_unlock_flags(&((((&sp->hld_mtx))))->mtx_lock
, ((0)), ("/usr/src/sys/dev/iscsi_initiator/iscsivar.h"), (533
))
;
534
535 return pq;
536}
537
538static __inline pduq_t *
539i_search_hld(isc_session_t *sp, int itt, int keep)
540{
541 pduq_t *pq, *tmp;
542
543 pq = NULL((void *)0);
544
545 mtx_lock(&sp->hld_mtx)__mtx_lock_flags(&((((&sp->hld_mtx))))->mtx_lock
, ((0)), ("/usr/src/sys/dev/iscsi_initiator/iscsivar.h"), (545
))
;
546 TAILQ_FOREACH_SAFE(pq, &sp->hld, pq_link, tmp)for ((pq) = (((&sp->hld))->tqh_first); (pq) &&
((tmp) = (((pq))->pq_link.tqe_next), 1); (pq) = (tmp))
{
547 if(pq->pdu.ipdu.bhs.itt == itt) {
548 if(!keep) {
549 sp->stats.nhld--;
550 TAILQ_REMOVE(&sp->hld, pq, pq_link)do { ; ; ; ; if (((((pq))->pq_link.tqe_next)) != ((void *)
0)) (((pq))->pq_link.tqe_next)->pq_link.tqe_prev = (pq)
->pq_link.tqe_prev; else { (&sp->hld)->tqh_last =
(pq)->pq_link.tqe_prev; ; } *(pq)->pq_link.tqe_prev = (
((pq))->pq_link.tqe_next); ; ; ; } while (0)
;
551 }
552 break;
553 }
554 }
555 mtx_unlock(&sp->hld_mtx)__mtx_unlock_flags(&((((&sp->hld_mtx))))->mtx_lock
, ((0)), ("/usr/src/sys/dev/iscsi_initiator/iscsivar.h"), (555
))
;
556
557 return pq;
558}
559
560static __inline void
561i_acked_hld(isc_session_t *sp, pdu_t *op)
562{
563 pduq_t *pq, *tmp;
564 u_int exp = sp->sn.expCmd;
565
566 pq = NULL((void *)0);
567 mtx_lock(&sp->hld_mtx)__mtx_lock_flags(&((((&sp->hld_mtx))))->mtx_lock
, ((0)), ("/usr/src/sys/dev/iscsi_initiator/iscsivar.h"), (567
))
;
568 TAILQ_FOREACH_SAFE(pq, &sp->hld, pq_link, tmp)for ((pq) = (((&sp->hld))->tqh_first); (pq) &&
((tmp) = (((pq))->pq_link.tqe_next), 1); (pq) = (tmp))
{
569 if((op && op->ipdu.bhs.itt == pq->pdu.ipdu.bhs.itt)
570 || (pq->ccb == NULL((void *)0)
571 && (pq->pdu.ipdu.bhs.opcode != ISCSI_WRITE_DATA0x05)
572 && SNA_GT(exp, ntohl(pq->pdu.ipdu.bhs.ExpStSN))((exp != (__builtin_constant_p(pq->pdu.ipdu.bhs.OpcodeSpecificFields
[2]) ? (((__uint32_t)((__uint16_t)(__builtin_constant_p(((__uint32_t
)(pq->pdu.ipdu.bhs.OpcodeSpecificFields[2])) & 0xffff)
? (__uint16_t)(((__uint16_t)(((__uint32_t)(pq->pdu.ipdu.bhs
.OpcodeSpecificFields[2])) & 0xffff)) << 8 | ((__uint16_t
)(((__uint32_t)(pq->pdu.ipdu.bhs.OpcodeSpecificFields[2]))
& 0xffff)) >> 8) : __bswap16_var(((__uint32_t)(pq->
pdu.ipdu.bhs.OpcodeSpecificFields[2])) & 0xffff))) <<
16) | ((__uint16_t)(__builtin_constant_p(((__uint32_t)(pq->
pdu.ipdu.bhs.OpcodeSpecificFields[2])) >> 16) ? (__uint16_t
)(((__uint16_t)(((__uint32_t)(pq->pdu.ipdu.bhs.OpcodeSpecificFields
[2])) >> 16)) << 8 | ((__uint16_t)(((__uint32_t)(
pq->pdu.ipdu.bhs.OpcodeSpecificFields[2])) >> 16)) >>
8) : __bswap16_var(((__uint32_t)(pq->pdu.ipdu.bhs.OpcodeSpecificFields
[2])) >> 16)))) : __bswap32_var(pq->pdu.ipdu.bhs.OpcodeSpecificFields
[2]))) && ( (exp < (__builtin_constant_p(pq->pdu
.ipdu.bhs.OpcodeSpecificFields[2]) ? (((__uint32_t)((__uint16_t
)(__builtin_constant_p(((__uint32_t)(pq->pdu.ipdu.bhs.OpcodeSpecificFields
[2])) & 0xffff) ? (__uint16_t)(((__uint16_t)(((__uint32_t
)(pq->pdu.ipdu.bhs.OpcodeSpecificFields[2])) & 0xffff)
) << 8 | ((__uint16_t)(((__uint32_t)(pq->pdu.ipdu.bhs
.OpcodeSpecificFields[2])) & 0xffff)) >> 8) : __bswap16_var
(((__uint32_t)(pq->pdu.ipdu.bhs.OpcodeSpecificFields[2])) &
0xffff))) << 16) | ((__uint16_t)(__builtin_constant_p(
((__uint32_t)(pq->pdu.ipdu.bhs.OpcodeSpecificFields[2])) >>
16) ? (__uint16_t)(((__uint16_t)(((__uint32_t)(pq->pdu.ipdu
.bhs.OpcodeSpecificFields[2])) >> 16)) << 8 | ((__uint16_t
)(((__uint32_t)(pq->pdu.ipdu.bhs.OpcodeSpecificFields[2]))
>> 16)) >> 8) : __bswap16_var(((__uint32_t)(pq->
pdu.ipdu.bhs.OpcodeSpecificFields[2])) >> 16)))) : __bswap32_var
(pq->pdu.ipdu.bhs.OpcodeSpecificFields[2])) && (__builtin_constant_p
(pq->pdu.ipdu.bhs.OpcodeSpecificFields[2]) ? (((__uint32_t
)((__uint16_t)(__builtin_constant_p(((__uint32_t)(pq->pdu.
ipdu.bhs.OpcodeSpecificFields[2])) & 0xffff) ? (__uint16_t
)(((__uint16_t)(((__uint32_t)(pq->pdu.ipdu.bhs.OpcodeSpecificFields
[2])) & 0xffff)) << 8 | ((__uint16_t)(((__uint32_t)
(pq->pdu.ipdu.bhs.OpcodeSpecificFields[2])) & 0xffff))
>> 8) : __bswap16_var(((__uint32_t)(pq->pdu.ipdu.bhs
.OpcodeSpecificFields[2])) & 0xffff))) << 16) | ((__uint16_t
)(__builtin_constant_p(((__uint32_t)(pq->pdu.ipdu.bhs.OpcodeSpecificFields
[2])) >> 16) ? (__uint16_t)(((__uint16_t)(((__uint32_t)
(pq->pdu.ipdu.bhs.OpcodeSpecificFields[2])) >> 16)) <<
8 | ((__uint16_t)(((__uint32_t)(pq->pdu.ipdu.bhs.OpcodeSpecificFields
[2])) >> 16)) >> 8) : __bswap16_var(((__uint32_t)
(pq->pdu.ipdu.bhs.OpcodeSpecificFields[2])) >> 16)))
) : __bswap32_var(pq->pdu.ipdu.bhs.OpcodeSpecificFields[2]
)) - exp > 0x7FFFFFFF) || (exp > (__builtin_constant_p(
pq->pdu.ipdu.bhs.OpcodeSpecificFields[2]) ? (((__uint32_t)
((__uint16_t)(__builtin_constant_p(((__uint32_t)(pq->pdu.ipdu
.bhs.OpcodeSpecificFields[2])) & 0xffff) ? (__uint16_t)((
(__uint16_t)(((__uint32_t)(pq->pdu.ipdu.bhs.OpcodeSpecificFields
[2])) & 0xffff)) << 8 | ((__uint16_t)(((__uint32_t)
(pq->pdu.ipdu.bhs.OpcodeSpecificFields[2])) & 0xffff))
>> 8) : __bswap16_var(((__uint32_t)(pq->pdu.ipdu.bhs
.OpcodeSpecificFields[2])) & 0xffff))) << 16) | ((__uint16_t
)(__builtin_constant_p(((__uint32_t)(pq->pdu.ipdu.bhs.OpcodeSpecificFields
[2])) >> 16) ? (__uint16_t)(((__uint16_t)(((__uint32_t)
(pq->pdu.ipdu.bhs.OpcodeSpecificFields[2])) >> 16)) <<
8 | ((__uint16_t)(((__uint32_t)(pq->pdu.ipdu.bhs.OpcodeSpecificFields
[2])) >> 16)) >> 8) : __bswap16_var(((__uint32_t)
(pq->pdu.ipdu.bhs.OpcodeSpecificFields[2])) >> 16)))
) : __bswap32_var(pq->pdu.ipdu.bhs.OpcodeSpecificFields[2]
)) && exp - (__builtin_constant_p(pq->pdu.ipdu.bhs
.OpcodeSpecificFields[2]) ? (((__uint32_t)((__uint16_t)(__builtin_constant_p
(((__uint32_t)(pq->pdu.ipdu.bhs.OpcodeSpecificFields[2])) &
0xffff) ? (__uint16_t)(((__uint16_t)(((__uint32_t)(pq->pdu
.ipdu.bhs.OpcodeSpecificFields[2])) & 0xffff)) << 8
| ((__uint16_t)(((__uint32_t)(pq->pdu.ipdu.bhs.OpcodeSpecificFields
[2])) & 0xffff)) >> 8) : __bswap16_var(((__uint32_t
)(pq->pdu.ipdu.bhs.OpcodeSpecificFields[2])) & 0xffff)
)) << 16) | ((__uint16_t)(__builtin_constant_p(((__uint32_t
)(pq->pdu.ipdu.bhs.OpcodeSpecificFields[2])) >> 16) ?
(__uint16_t)(((__uint16_t)(((__uint32_t)(pq->pdu.ipdu.bhs
.OpcodeSpecificFields[2])) >> 16)) << 8 | ((__uint16_t
)(((__uint32_t)(pq->pdu.ipdu.bhs.OpcodeSpecificFields[2]))
>> 16)) >> 8) : __bswap16_var(((__uint32_t)(pq->
pdu.ipdu.bhs.OpcodeSpecificFields[2])) >> 16)))) : __bswap32_var
(pq->pdu.ipdu.bhs.OpcodeSpecificFields[2])) < 0x7FFFFFFF
))?1: 0)
)) {
573 sp->stats.nhld--;
574 TAILQ_REMOVE(&sp->hld, pq, pq_link)do { ; ; ; ; if (((((pq))->pq_link.tqe_next)) != ((void *)
0)) (((pq))->pq_link.tqe_next)->pq_link.tqe_prev = (pq)
->pq_link.tqe_prev; else { (&sp->hld)->tqh_last =
(pq)->pq_link.tqe_prev; ; } *(pq)->pq_link.tqe_prev = (
((pq))->pq_link.tqe_next); ; ; ; } while (0)
;
575 pdu_free(sp->isc, pq);
576 }
577 }
578 mtx_unlock(&sp->hld_mtx)__mtx_unlock_flags(&((((&sp->hld_mtx))))->mtx_lock
, ((0)), ("/usr/src/sys/dev/iscsi_initiator/iscsivar.h"), (578
))
;
579}
580
581static __inline void
582i_mbufcopy(struct mbuf *mp, caddr_t dp, int len)
583{
584 struct mbuf *m;
585 caddr_t bp;
586
587 for(m = mp; m != NULL((void *)0); m = m->m_next) {
12
Loop condition is true. Entering loop body
15
Assuming 'm' is not equal to null
16
Loop condition is true. Entering loop body
588 bp = mtod(m, caddr_t)((caddr_t)((m)->m_data));
589 /*
590 | the pdu is word (4 octed) aligned
591 | so len <= packet
592 */
593 memcpy(dp, bp, MIN(len, m->m_len)(((len)<(m->m_len))?(len):(m->m_len)));
17
Partial initialization occurs here
594 dp += m->m_len;
595 len -= m->m_len;
596 if(len <= 0)
13
Assuming 'len' is > 0
14
Taking false branch
18
Assuming 'len' is <= 0
19
Taking true branch
597 break;
20
Execution continues on line 596
598 }
599}