Deleted Added
full compact
iscsivar.h (185289) iscsivar.h (211095)
1/*-
1/*-
2 * Copyright (c) 2005-2008 Daniel Braniss <danny@cs.huji.ac.il>
2 * Copyright (c) 2005-2010 Daniel Braniss <danny@cs.huji.ac.il>
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

--- 7 unchanged lines hidden (view full) ---

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 *
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

--- 7 unchanged lines hidden (view full) ---

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: head/sys/dev/iscsi/initiator/iscsivar.h 185289 2008-11-25 07:17:11Z scottl $
26 * $FreeBSD: head/sys/dev/iscsi/initiator/iscsivar.h 211095 2010-08-09 12:36:36Z des $
27 */
27 */
28
28/*
29/*
29 | $Id: iscsivar.h,v 1.30 2007/04/22 10:12:11 danny Exp danny $
30 | $Id: iscsivar.h 743 2009-08-08 10:54:53Z danny $
30 */
31 */
32#define ISCSI_MAX_LUNS 128 // don't touch this
33#if ISCSI_MAX_LUNS > 8
34/*
35 | for this to work
36 | sysctl kern.cam.cam_srch_hi=1
37 */
38#endif
39
31#ifndef ISCSI_INITIATOR_DEBUG
32#define ISCSI_INITIATOR_DEBUG 1
33#endif
34
35#ifdef ISCSI_INITIATOR_DEBUG
36extern int iscsi_debug;
37#define debug(level, fmt, args...) do {if(level <= iscsi_debug)\
38 printf("%s: " fmt "\n", __func__ , ##args);} while(0)

--- 4 unchanged lines hidden (view full) ---

43#else
44#define debug(level, fmt, args...)
45#define debug_called(level)
46#define sdebug(level, fmt, args...)
47#endif /* ISCSI_INITIATOR_DEBUG */
48
49#define xdebug(fmt, args...) printf(">>> %s: " fmt "\n", __func__ , ##args)
50
40#ifndef ISCSI_INITIATOR_DEBUG
41#define ISCSI_INITIATOR_DEBUG 1
42#endif
43
44#ifdef ISCSI_INITIATOR_DEBUG
45extern int iscsi_debug;
46#define debug(level, fmt, args...) do {if(level <= iscsi_debug)\
47 printf("%s: " fmt "\n", __func__ , ##args);} while(0)

--- 4 unchanged lines hidden (view full) ---

52#else
53#define debug(level, fmt, args...)
54#define debug_called(level)
55#define sdebug(level, fmt, args...)
56#endif /* ISCSI_INITIATOR_DEBUG */
57
58#define xdebug(fmt, args...) printf(">>> %s: " fmt "\n", __func__ , ##args)
59
51#define MAX_SESSIONS ISCSI_MAX_TARGETS
60#define MAX_SESSIONS ISCSI_MAX_TARGETS
61#define MAX_PDUS (MAX_SESSIONS*256) // XXX: at the moment this is arbitrary
52
53typedef uint32_t digest_t(const void *, int len, uint32_t ocrc);
54
55MALLOC_DECLARE(M_ISCSI);
62
63typedef uint32_t digest_t(const void *, int len, uint32_t ocrc);
64
65MALLOC_DECLARE(M_ISCSI);
66MALLOC_DECLARE(M_ISCSIBUF);
56MALLOC_DECLARE(M_PDU);
57
67MALLOC_DECLARE(M_PDU);
68
69#define ISOK2DIG(dig, pp) ((dig != NULL) && ((pp->ipdu.bhs.opcode & 0x1f) != ISCSI_LOGIN_CMD))
70
58#ifndef BIT
59#define BIT(n) (1 <<(n))
60#endif
61
62#define ISC_SM_RUN BIT(0)
63#define ISC_SM_RUNNING BIT(1)
64
65#define ISC_LINK_UP BIT(2)
66#define ISC_CON_RUN BIT(3)
67#define ISC_CON_RUNNING BIT(4)
68#define ISC_KILL BIT(5)
69#define ISC_OQNOTEMPTY BIT(6)
70#define ISC_OWAITING BIT(7)
71#define ISC_FFPHASE BIT(8)
71#ifndef BIT
72#define BIT(n) (1 <<(n))
73#endif
74
75#define ISC_SM_RUN BIT(0)
76#define ISC_SM_RUNNING BIT(1)
77
78#define ISC_LINK_UP BIT(2)
79#define ISC_CON_RUN BIT(3)
80#define ISC_CON_RUNNING BIT(4)
81#define ISC_KILL BIT(5)
82#define ISC_OQNOTEMPTY BIT(6)
83#define ISC_OWAITING BIT(7)
84#define ISC_FFPHASE BIT(8)
72#define ISC_FFPWAIT BIT(9)
73
85
74#define ISC_MEMWAIT BIT(10)
75#define ISC_SIGNALED BIT(11)
76#define ISC_FROZEN BIT(12)
77#define ISC_STALLED BIT(13)
86#define ISC_CAMDEVS BIT(9)
87#define ISC_SCANWAIT BIT(10)
78
88
79#define ISC_HOLD BIT(14)
80#define ISC_HOLDED BIT(15)
89#define ISC_MEMWAIT BIT(11)
90#define ISC_SIGNALED BIT(12)
81
91
92#define ISC_HOLD BIT(15)
93#define ISC_HOLDED BIT(16)
94
82#define ISC_SHUTDOWN BIT(31)
83
84/*
85 | some stats
86 */
87struct i_stats {
88 int npdu; // number of pdus malloc'ed.
89 int nrecv; // unprocessed received pdus

--- 21 unchanged lines hidden (view full) ---

111 int flags;
112 struct cdev *dev;
113 struct socket *soc;
114 struct file *fp;
115 struct thread *td;
116
117 struct proc *proc; // the userland process
118 int signal;
95#define ISC_SHUTDOWN BIT(31)
96
97/*
98 | some stats
99 */
100struct i_stats {
101 int npdu; // number of pdus malloc'ed.
102 int nrecv; // unprocessed received pdus

--- 21 unchanged lines hidden (view full) ---

124 int flags;
125 struct cdev *dev;
126 struct socket *soc;
127 struct file *fp;
128 struct thread *td;
129
130 struct proc *proc; // the userland process
131 int signal;
119
120 struct proc *soc_proc;
132 struct proc *soc_proc;
121
122 struct proc *stp; // the sm thread
123
124 struct isc_softc *isc;
125
126 digest_t *hdrDigest; // the digest alg. if any
127 digest_t *dataDigest; // the digest alg. if any
128
129 int sid; // Session ID
133 struct proc *stp; // the sm thread
134
135 struct isc_softc *isc;
136
137 digest_t *hdrDigest; // the digest alg. if any
138 digest_t *dataDigest; // the digest alg. if any
139
140 int sid; // Session ID
130 int targetid;
131// int cid; // Connection ID
132// int tsih; // target session identifier handle
133 sn_t sn; // sequence number stuff;
134 int cws; // current window size
135
136 int target_nluns; // this and target_lun are
137 // hopefully temporal till I
138 // figure out a better way.
141 sn_t sn; // sequence number stuff;
142 int cws; // current window size
143
144 int target_nluns; // this and target_lun are
145 // hopefully temporal till I
146 // figure out a better way.
139 lun_id_t target_lun[ISCSI_MAX_LUNS];
147 int target_lun[ISCSI_MAX_LUNS/(sizeof(int)*8) + 1];
140
141 struct mtx rsp_mtx;
142 struct mtx rsv_mtx;
143 struct mtx snd_mtx;
144 struct mtx hld_mtx;
145 struct mtx io_mtx;
146 queue_t rsp;
147 queue_t rsv;
148 queue_t csnd;
149 queue_t isnd;
150 queue_t wsnd;
151 queue_t hld;
152
148
149 struct mtx rsp_mtx;
150 struct mtx rsv_mtx;
151 struct mtx snd_mtx;
152 struct mtx hld_mtx;
153 struct mtx io_mtx;
154 queue_t rsp;
155 queue_t rsv;
156 queue_t csnd;
157 queue_t isnd;
158 queue_t wsnd;
159 queue_t hld;
160
153 /*
154 | negotiable values
155 */
156 isc_opt_t opt;
161 isc_opt_t opt; // negotiable values
157
158 struct i_stats stats;
162
163 struct i_stats stats;
159 struct cam_path *cam_path;
160 bhs_t bhs;
161 struct uio uio;
162 struct iovec iov;
163 /*
164 bhs_t bhs;
165 struct uio uio;
166 struct iovec iov;
167 /*
168 | cam stuff
169 */
170 struct cam_sim *cam_sim;
171 struct cam_path *cam_path;
172 struct mtx cam_mtx;
173 /*
164 | sysctl stuff
165 */
166 struct sysctl_ctx_list clist;
167 struct sysctl_oid *oid;
168 int douio; //XXX: turn on/off uio on read
169} isc_session_t;
170
171typedef struct pduq {
172 TAILQ_ENTRY(pduq) pq_link;
173
174 caddr_t buf;
175 u_int len; // the total length of the pdu
176 pdu_t pdu;
177 union ccb *ccb;
178
179 struct uio uio;
180 struct iovec iov[5]; // XXX: careful ...
181 struct mbuf *mp;
182 struct bintime ts;
174 | sysctl stuff
175 */
176 struct sysctl_ctx_list clist;
177 struct sysctl_oid *oid;
178 int douio; //XXX: turn on/off uio on read
179} isc_session_t;
180
181typedef struct pduq {
182 TAILQ_ENTRY(pduq) pq_link;
183
184 caddr_t buf;
185 u_int len; // the total length of the pdu
186 pdu_t pdu;
187 union ccb *ccb;
188
189 struct uio uio;
190 struct iovec iov[5]; // XXX: careful ...
191 struct mbuf *mp;
192 struct bintime ts;
183 queue_t *pduq;
193 queue_t *pduq;
184} pduq_t;
194} pduq_t;
185
195/*
196 */
186struct isc_softc {
197struct isc_softc {
187 //int state;
198 struct mtx isc_mtx;
199 TAILQ_HEAD(,isc_session) isc_sess;
200 int nsess;
188 struct cdev *dev;
201 struct cdev *dev;
189 eventhandler_tag eh;
190 char isid[6]; // Initiator Session ID (48 bits)
202 char isid[6]; // Initiator Session ID (48 bits)
191 struct mtx mtx;
203 struct unrhdr *unit;
204 struct sx unit_sx;
192
205
193 int nsess;
194 TAILQ_HEAD(,isc_session) isc_sess;
195 isc_session_t *sessions[MAX_SESSIONS];
206 struct mtx pdu_mtx;
207 uma_zone_t pdu_zone; // pool of free pdu's
208 TAILQ_HEAD(,pduq) freepdu;
196
209
197 struct mtx pdu_mtx;
198#ifdef ISCSI_INITIATOR_DEBUG
210#ifdef ISCSI_INITIATOR_DEBUG
199 int npdu_alloc, npdu_max; // for instrumentation
211 int npdu_alloc, npdu_max; // for instrumentation
200#endif
212#endif
201#define MAX_PDUS (MAX_SESSIONS*256) // XXX: at the moment this is arbitrary
202 uma_zone_t pdu_zone; // pool of free pdu's
203 TAILQ_HEAD(,pduq) freepdu;
213#ifdef DO_EVENTHANDLER
214 eventhandler_tag eh;
215#endif
204 /*
216 /*
205 | cam stuff
206 */
207 struct cam_sim *cam_sim;
208 struct cam_path *cam_path;
209 struct mtx cam_mtx;
210 /*
211 | sysctl stuff
212 */
213 struct sysctl_ctx_list clist;
214 struct sysctl_oid *oid;
215};
216
217#ifdef ISCSI_INITIATOR_DEBUG
218extern struct mtx iscsi_dbg_mtx;

--- 7 unchanged lines hidden (view full) ---

226int i_prepPDU(isc_session_t *sp, pduq_t *pq);
227
228int ism_fullfeature(struct cdev *dev, int flag);
229
230int i_pdu_flush(isc_session_t *sc);
231int i_setopt(isc_session_t *sp, isc_opt_t *opt);
232void i_freeopt(isc_opt_t *opt);
233
217 | sysctl stuff
218 */
219 struct sysctl_ctx_list clist;
220 struct sysctl_oid *oid;
221};
222
223#ifdef ISCSI_INITIATOR_DEBUG
224extern struct mtx iscsi_dbg_mtx;

--- 7 unchanged lines hidden (view full) ---

232int i_prepPDU(isc_session_t *sp, pduq_t *pq);
233
234int ism_fullfeature(struct cdev *dev, int flag);
235
236int i_pdu_flush(isc_session_t *sc);
237int i_setopt(isc_session_t *sp, isc_opt_t *opt);
238void i_freeopt(isc_opt_t *opt);
239
234int ic_init(struct isc_softc *sc);
235void ic_destroy(struct isc_softc *sc);
236int ic_fullfeature(struct cdev *dev);
240int ic_init(isc_session_t *sp);
241void ic_destroy(isc_session_t *sp);
237void ic_lost_target(isc_session_t *sp, int target);
238int ic_getCamVals(isc_session_t *sp, iscsi_cam_t *cp);
239
240void ism_recv(isc_session_t *sp, pduq_t *pq);
241int ism_start(isc_session_t *sp);
242void ic_lost_target(isc_session_t *sp, int target);
243int ic_getCamVals(isc_session_t *sp, iscsi_cam_t *cp);
244
245void ism_recv(isc_session_t *sp, pduq_t *pq);
246int ism_start(isc_session_t *sp);
247void ism_restart(isc_session_t *sp);
242void ism_stop(isc_session_t *sp);
243
244int scsi_encap(struct cam_sim *sim, union ccb *ccb);
245int scsi_decap(isc_session_t *sp, pduq_t *opq, pduq_t *pq);
246void iscsi_r2t(isc_session_t *sp, pduq_t *opq, pduq_t *pq);
247void iscsi_done(isc_session_t *sp, pduq_t *opq, pduq_t *pq);
248void iscsi_reject(isc_session_t *sp, pduq_t *opq, pduq_t *pq);
249void iscsi_async(isc_session_t *sp, pduq_t *pq);
250void iscsi_cleanup(isc_session_t *sp);
251int iscsi_requeue(isc_session_t *sp);
252
248void ism_stop(isc_session_t *sp);
249
250int scsi_encap(struct cam_sim *sim, union ccb *ccb);
251int scsi_decap(isc_session_t *sp, pduq_t *opq, pduq_t *pq);
252void iscsi_r2t(isc_session_t *sp, pduq_t *opq, pduq_t *pq);
253void iscsi_done(isc_session_t *sp, pduq_t *opq, pduq_t *pq);
254void iscsi_reject(isc_session_t *sp, pduq_t *opq, pduq_t *pq);
255void iscsi_async(isc_session_t *sp, pduq_t *pq);
256void iscsi_cleanup(isc_session_t *sp);
257int iscsi_requeue(isc_session_t *sp);
258
253void ic_freeze(isc_session_t *sp);
254void ic_release(isc_session_t *sp);
255
256// Serial Number Arithmetic
257#define _MAXINCR 0x7FFFFFFF // 2 ^ 31 - 1
258#define SNA_GT(i1, i2) ((i1 != i2) && (\
259 (i1 < i2 && i2 - i1 > _MAXINCR) ||\
260 (i1 > i2 && i1 - i2 < _MAXINCR))?1: 0)
261
262/*
263 | inlines
264 */
265#ifdef _CAM_CAM_XPT_SIM_H
266
267#if __FreeBSD_version < 600000
268#define CAM_LOCK(arg)
269#define CAM_ULOCK(arg)
270
271static __inline void
259// Serial Number Arithmetic
260#define _MAXINCR 0x7FFFFFFF // 2 ^ 31 - 1
261#define SNA_GT(i1, i2) ((i1 != i2) && (\
262 (i1 < i2 && i2 - i1 > _MAXINCR) ||\
263 (i1 > i2 && i1 - i2 < _MAXINCR))?1: 0)
264
265/*
266 | inlines
267 */
268#ifdef _CAM_CAM_XPT_SIM_H
269
270#if __FreeBSD_version < 600000
271#define CAM_LOCK(arg)
272#define CAM_ULOCK(arg)
273
274static __inline void
272XPT_DONE(struct isc_softc *isp, union ccb *ccb)
275XPT_DONE(isc_session_t *sp, union ccb *ccb)
273{
274 mtx_lock(&Giant);
275 xpt_done(ccb);
276 mtx_unlock(&Giant);
277}
278#elif __FreeBSD_version >= 700000
279#define CAM_LOCK(arg) mtx_lock(&arg->cam_mtx)
280#define CAM_UNLOCK(arg) mtx_unlock(&arg->cam_mtx)
281
282static __inline void
276{
277 mtx_lock(&Giant);
278 xpt_done(ccb);
279 mtx_unlock(&Giant);
280}
281#elif __FreeBSD_version >= 700000
282#define CAM_LOCK(arg) mtx_lock(&arg->cam_mtx)
283#define CAM_UNLOCK(arg) mtx_unlock(&arg->cam_mtx)
284
285static __inline void
283XPT_DONE(struct isc_softc *isp, union ccb *ccb)
286XPT_DONE(isc_session_t *sp, union ccb *ccb)
284{
287{
285 CAM_LOCK(isp);
288 CAM_LOCK(sp);
286 xpt_done(ccb);
289 xpt_done(ccb);
287 CAM_UNLOCK(isp);
290 CAM_UNLOCK(sp);
288}
289#else
290//__FreeBSD_version >= 600000
291#define CAM_LOCK(arg)
292#define CAM_UNLOCK(arg)
293#define XPT_DONE(ignore, arg) xpt_done(arg)
294#endif
295

--- 31 unchanged lines hidden (view full) ---

327
328static __inline void
329pdu_free(struct isc_softc *isc, pduq_t *pq)
330{
331 if(pq->mp)
332 m_freem(pq->mp);
333#ifdef NO_USE_MBUF
334 if(pq->buf != NULL)
291}
292#else
293//__FreeBSD_version >= 600000
294#define CAM_LOCK(arg)
295#define CAM_UNLOCK(arg)
296#define XPT_DONE(ignore, arg) xpt_done(arg)
297#endif
298

--- 31 unchanged lines hidden (view full) ---

330
331static __inline void
332pdu_free(struct isc_softc *isc, pduq_t *pq)
333{
334 if(pq->mp)
335 m_freem(pq->mp);
336#ifdef NO_USE_MBUF
337 if(pq->buf != NULL)
335 free(pq->buf, M_ISCSI);
338 free(pq->buf, M_ISCSIBUF);
336#endif
337 mtx_lock(&isc->pdu_mtx);
338 TAILQ_INSERT_TAIL(&isc->freepdu, pq, pq_link);
339#ifdef ISCSI_INITIATOR_DEBUG
340 isc->npdu_alloc--;
341#endif
342 mtx_unlock(&isc->pdu_mtx);
343}

--- 216 unchanged lines hidden (view full) ---

560 }
561 }
562 mtx_unlock(&sp->hld_mtx);
563
564 return pq;
565}
566
567static __inline void
339#endif
340 mtx_lock(&isc->pdu_mtx);
341 TAILQ_INSERT_TAIL(&isc->freepdu, pq, pq_link);
342#ifdef ISCSI_INITIATOR_DEBUG
343 isc->npdu_alloc--;
344#endif
345 mtx_unlock(&isc->pdu_mtx);
346}

--- 216 unchanged lines hidden (view full) ---

563 }
564 }
565 mtx_unlock(&sp->hld_mtx);
566
567 return pq;
568}
569
570static __inline void
571i_acked_hld(isc_session_t *sp, pdu_t *op)
572{
573 pduq_t *pq, *tmp;
574 u_int exp = sp->sn.expCmd;
575
576 pq = NULL;
577 mtx_lock(&sp->hld_mtx);
578 TAILQ_FOREACH_SAFE(pq, &sp->hld, pq_link, tmp) {
579 if((op && op->ipdu.bhs.itt == pq->pdu.ipdu.bhs.itt)
580 || (pq->ccb == NULL
581 && (pq->pdu.ipdu.bhs.opcode != ISCSI_WRITE_DATA)
582 && SNA_GT(exp, ntohl(pq->pdu.ipdu.bhs.ExpStSN)))) {
583 sp->stats.nhld--;
584 TAILQ_REMOVE(&sp->hld, pq, pq_link);
585 pdu_free(sp->isc, pq);
586 }
587 }
588 mtx_unlock(&sp->hld_mtx);
589}
590
591static __inline void
568i_mbufcopy(struct mbuf *mp, caddr_t dp, int len)
569{
570 struct mbuf *m;
571 caddr_t bp;
572
573 for(m = mp; m != NULL; m = m->m_next) {
574 bp = mtod(m, caddr_t);
575 /*
576 | the pdu is word (4 octed) aligned
577 | so len <= packet
578 */
579 memcpy(dp, bp, MIN(len, m->m_len));
580 dp += m->m_len;
581 len -= m->m_len;
582 if(len <= 0)
583 break;
584 }
585}
592i_mbufcopy(struct mbuf *mp, caddr_t dp, int len)
593{
594 struct mbuf *m;
595 caddr_t bp;
596
597 for(m = mp; m != NULL; m = m->m_next) {
598 bp = mtod(m, caddr_t);
599 /*
600 | the pdu is word (4 octed) aligned
601 | so len <= packet
602 */
603 memcpy(dp, bp, MIN(len, m->m_len));
604 dp += m->m_len;
605 len -= m->m_len;
606 if(len <= 0)
607 break;
608 }
609}