Deleted Added
full compact
isc_cam.c (196352) isc_cam.c (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

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

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

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

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
27/*
28 | $Id: isc_cam.c 998 2009-12-20 10:32:45Z danny $
29 */
28#include <sys/cdefs.h>
30#include <sys/cdefs.h>
29__FBSDID("$FreeBSD: head/sys/dev/iscsi/initiator/isc_cam.c 196352 2009-08-18 08:46:54Z mav $");
31__FBSDID("$FreeBSD: head/sys/dev/iscsi/initiator/isc_cam.c 211095 2010-08-09 12:36:36Z des $");
30
31#include "opt_iscsi_initiator.h"
32
33#include <sys/param.h>
34#include <sys/kernel.h>
35#include <sys/callout.h>
36#if __FreeBSD_version >= 700000
37#include <sys/lock.h>
38#include <sys/mutex.h>
39#endif
40#include <sys/conf.h>
41#include <sys/systm.h>
42#include <sys/malloc.h>
43#include <sys/mbuf.h>
44#include <sys/uio.h>
45#include <sys/sysctl.h>
32
33#include "opt_iscsi_initiator.h"
34
35#include <sys/param.h>
36#include <sys/kernel.h>
37#include <sys/callout.h>
38#if __FreeBSD_version >= 700000
39#include <sys/lock.h>
40#include <sys/mutex.h>
41#endif
42#include <sys/conf.h>
43#include <sys/systm.h>
44#include <sys/malloc.h>
45#include <sys/mbuf.h>
46#include <sys/uio.h>
47#include <sys/sysctl.h>
48#include <sys/sx.h>
46
47#include <cam/cam.h>
48#include <cam/cam_ccb.h>
49#include <cam/cam_sim.h>
50#include <cam/cam_xpt_sim.h>
51#include <cam/cam_periph.h>
52
53#include <dev/iscsi/initiator/iscsi.h>
54#include <dev/iscsi/initiator/iscsivar.h>
55
49
50#include <cam/cam.h>
51#include <cam/cam_ccb.h>
52#include <cam/cam_sim.h>
53#include <cam/cam_xpt_sim.h>
54#include <cam/cam_periph.h>
55
56#include <dev/iscsi/initiator/iscsi.h>
57#include <dev/iscsi/initiator/iscsivar.h>
58
56// XXX: untested/incomplete
57void
58ic_freeze(isc_session_t *sp)
59static void
60_inq(struct cam_sim *sim, union ccb *ccb)
59{
61{
62 struct ccb_pathinq *cpi = &ccb->cpi;
63 isc_session_t *sp = cam_sim_softc(sim);
64
60 debug_called(8);
65 debug_called(8);
61#if 0
62 sdebug(2, "freezing path=%p", sp->cam_path == NULL? 0: sp->cam_path);
63 if((sp->cam_path != NULL) && !(sp->flags & ISC_FROZEN)) {
64 xpt_freeze_devq(sp->cam_path, 1);
65 }
66 debug(3, "sid=%d target=%d lun=%d", sp->sid, ccb->ccb_h.target_id, ccb->ccb_h.target_lun);
67
68 cpi->version_num = 1; /* XXX??? */
69 cpi->hba_inquiry = PI_SDTR_ABLE | PI_TAG_ABLE | PI_WIDE_32;
70 cpi->target_sprt = 0;
71 cpi->hba_misc = 0;
72 cpi->hba_eng_cnt = 0;
73 cpi->max_target = 0; //ISCSI_MAX_TARGETS - 1;
74 cpi->initiator_id = ISCSI_MAX_TARGETS;
75 cpi->max_lun = sp->opt.maxluns - 1;
76 cpi->bus_id = cam_sim_bus(sim);
77 cpi->base_transfer_speed = 3300; // 40000; // XXX:
78 strncpy(cpi->sim_vid, "FreeBSD", SIM_IDLEN);
79 strncpy(cpi->hba_vid, "iSCSI", HBA_IDLEN);
80 strncpy(cpi->dev_name, cam_sim_name(sim), DEV_IDLEN);
81 cpi->unit_number = cam_sim_unit(sim);
82 cpi->ccb_h.status = CAM_REQ_CMP;
83#if defined(KNOB_VALID_ADDRESS)
84 cpi->transport = XPORT_ISCSI;
85 cpi->transport_version = 0;
66#endif
86#endif
67 sp->flags |= ISC_FROZEN;
68}
69
87}
88
70// XXX: untested/incomplete
71void
72ic_release(isc_session_t *sp)
89static __inline int
90_scsi_encap(struct cam_sim *sim, union ccb *ccb)
73{
91{
74 debug_called(8);
75#if 0
76 sdebug(2, "release path=%p", sp->cam_path == NULL? 0: sp->cam_path);
77 if((sp->cam_path != NULL) && (sp->flags & ISC_FROZEN)) {
78 xpt_release_devq(sp->cam_path, 1, TRUE);
79 }
92 int ret;
93
94#if __FreeBSD_version < 700000
95 ret = scsi_encap(sim, ccb);
96#else
97 isc_session_t *sp = cam_sim_softc(sim);
98
99 mtx_unlock(&sp->cam_mtx);
100 ret = scsi_encap(sim, ccb);
101 mtx_lock(&sp->cam_mtx);
80#endif
102#endif
81 sp->flags &= ~ISC_FROZEN;
103 return ret;
82}
83
84void
85ic_lost_target(isc_session_t *sp, int target)
86{
104}
105
106void
107ic_lost_target(isc_session_t *sp, int target)
108{
87 struct isc_softc *isp = sp->isc;
88
89 debug_called(8);
109 debug_called(8);
90 sdebug(2, "target=%d", target);
110 sdebug(2, "lost target=%d", target);
111
91 if(sp->cam_path != NULL) {
112 if(sp->cam_path != NULL) {
92 mtx_lock(&isp->cam_mtx);
113 mtx_lock(&sp->cam_mtx);
93 xpt_async(AC_LOST_DEVICE, sp->cam_path, NULL);
94 xpt_free_path(sp->cam_path);
114 xpt_async(AC_LOST_DEVICE, sp->cam_path, NULL);
115 xpt_free_path(sp->cam_path);
95 mtx_unlock(&isp->cam_mtx);
116 mtx_unlock(&sp->cam_mtx);
96 sp->cam_path = 0; // XXX
97 }
98}
99
100static void
117 sp->cam_path = 0; // XXX
118 }
119}
120
121static void
101_scan_callback(struct cam_periph *periph, union ccb *ccb)
122scan_callback(struct cam_periph *periph, union ccb *ccb)
102{
103 isc_session_t *sp = (isc_session_t *)ccb->ccb_h.spriv_ptr0;
104
105 debug_called(8);
106
107 free(ccb, M_TEMP);
108
123{
124 isc_session_t *sp = (isc_session_t *)ccb->ccb_h.spriv_ptr0;
125
126 debug_called(8);
127
128 free(ccb, M_TEMP);
129
109 if(sp->flags & ISC_FFPWAIT) {
110 sp->flags &= ~ISC_FFPWAIT;
130 if(sp->flags & ISC_SCANWAIT) {
131 sp->flags &= ~ISC_SCANWAIT;
111 wakeup(sp);
112 }
113}
114
132 wakeup(sp);
133 }
134}
135
115static void
116_scan_target(isc_session_t *sp, int target)
136static int
137ic_scan(isc_session_t *sp)
117{
138{
118 union ccb *ccb;
139 union ccb *ccb;
119
120 debug_called(8);
140
141 debug_called(8);
121 sdebug(2, "target=%d", target);
142 sdebug(2, "scanning sid=%d", sp->sid);
122
123 if((ccb = malloc(sizeof(union ccb), M_TEMP, M_WAITOK | M_ZERO)) == NULL) {
124 xdebug("scan failed (can't allocate CCB)");
143
144 if((ccb = malloc(sizeof(union ccb), M_TEMP, M_WAITOK | M_ZERO)) == NULL) {
145 xdebug("scan failed (can't allocate CCB)");
125 return;
146 return ENOMEM; // XXX
126 }
147 }
127 CAM_LOCK(sp->isc);
148
149 sp->flags &= ~ISC_CAMDEVS;
150 sp->flags |= ISC_SCANWAIT;
151
152 CAM_LOCK(sp);
153 if(xpt_create_path(&sp->cam_path, xpt_periph, cam_sim_path(sp->cam_sim),
154 0, CAM_LUN_WILDCARD) != CAM_REQ_CMP) {
155 xdebug("can't create cam path");
156 CAM_UNLOCK(sp);
157 free(ccb, M_TEMP);
158 return ENODEV; // XXX
159 }
128 xpt_setup_ccb(&ccb->ccb_h, sp->cam_path, 5/*priority (low)*/);
129 ccb->ccb_h.func_code = XPT_SCAN_BUS;
160 xpt_setup_ccb(&ccb->ccb_h, sp->cam_path, 5/*priority (low)*/);
161 ccb->ccb_h.func_code = XPT_SCAN_BUS;
130 ccb->ccb_h.cbfcnp = _scan_callback;
162 ccb->ccb_h.cbfcnp = scan_callback;
131 ccb->crcn.flags = CAM_FLAG_NONE;
132 ccb->ccb_h.spriv_ptr0 = sp;
133
134 xpt_action(ccb);
163 ccb->crcn.flags = CAM_FLAG_NONE;
164 ccb->ccb_h.spriv_ptr0 = sp;
165
166 xpt_action(ccb);
135 CAM_UNLOCK(sp->isc);
136}
167 CAM_UNLOCK(sp);
137
168
138int
139ic_fullfeature(struct cdev *dev)
140{
141 struct isc_softc *isp = dev->si_drv1;
142 isc_session_t *sp = (isc_session_t *)dev->si_drv2;
143
144 debug_called(8);
145 sdebug(3, "dev=%d sc=%p", dev2unit(dev), isp);
146
147 sp->flags &= ~ISC_FFPHASE;
148 sp->flags |= ISC_FFPWAIT;
149
150 CAM_LOCK(isp);
151 if(xpt_create_path(&sp->cam_path, xpt_periph, cam_sim_path(sp->isc->cam_sim),
152 sp->sid, CAM_LUN_WILDCARD) != CAM_REQ_CMP) {
153 xdebug("can't create cam path");
154 CAM_UNLOCK(isp);
155 return ENODEV; // XXX
156 }
157 CAM_UNLOCK(isp);
158
159 _scan_target(sp, sp->sid);
160
161 while(sp->flags & ISC_FFPWAIT)
169 while(sp->flags & ISC_SCANWAIT)
162 tsleep(sp, PRIBIO, "ffp", 5*hz); // the timeout time should
163 // be configurable
170 tsleep(sp, PRIBIO, "ffp", 5*hz); // the timeout time should
171 // be configurable
172 sdebug(2, "# of luns=%d", sp->target_nluns);
173
164 if(sp->target_nluns > 0) {
174 if(sp->target_nluns > 0) {
165 sp->flags |= ISC_FFPHASE;
175 sp->flags |= ISC_CAMDEVS;
166 return 0;
167 }
168
169 return ENODEV;
170}
171
172static void
176 return 0;
177 }
178
179 return ENODEV;
180}
181
182static void
173_inq(struct cam_sim *sim, union ccb *ccb, int maxluns)
174{
175 struct ccb_pathinq *cpi = &ccb->cpi;
176
177 debug_called(4);
178
179 cpi->version_num = 1; /* XXX??? */
180 cpi->hba_inquiry = PI_SDTR_ABLE | PI_TAG_ABLE | PI_WIDE_32;
181 cpi->target_sprt = 0;
182 cpi->hba_misc = 0;
183 cpi->hba_eng_cnt = 0;
184 cpi->max_target = ISCSI_MAX_TARGETS - 1;
185 cpi->initiator_id = ISCSI_MAX_TARGETS;
186 cpi->max_lun = maxluns;
187 cpi->bus_id = cam_sim_bus(sim);
188 cpi->base_transfer_speed = 3300;
189 strncpy(cpi->sim_vid, "FreeBSD", SIM_IDLEN);
190 strncpy(cpi->hba_vid, "iSCSI", HBA_IDLEN);
191 strncpy(cpi->dev_name, cam_sim_name(sim), DEV_IDLEN);
192 cpi->unit_number = cam_sim_unit(sim);
193 cpi->transport = XPORT_ISCSI;
194 cpi->transport_version = 0;
195 cpi->ccb_h.status = CAM_REQ_CMP;
196}
197
198static __inline int
199_scsi_encap(struct cam_sim *sim, union ccb *ccb)
200{
201 int ret;
202
203#if __FreeBSD_version < 700000
204 ret = scsi_encap(sim, ccb);
205#else
206 struct isc_softc *isp = (struct isc_softc *)cam_sim_softc(sim);
207
208 mtx_unlock(&isp->cam_mtx);
209 ret = scsi_encap(sim, ccb);
210 mtx_lock(&isp->cam_mtx);
211#endif
212 return ret;
213}
214
215static void
216ic_action(struct cam_sim *sim, union ccb *ccb)
217{
183ic_action(struct cam_sim *sim, union ccb *ccb)
184{
185 isc_session_t *sp = cam_sim_softc(sim);
218 struct ccb_hdr *ccb_h = &ccb->ccb_h;
186 struct ccb_hdr *ccb_h = &ccb->ccb_h;
219 struct isc_softc *isp = (struct isc_softc *)cam_sim_softc(sim);
220 isc_session_t *sp;
221
222 debug_called(8);
223
187
188 debug_called(8);
189
224 if((ccb_h->target_id != CAM_TARGET_WILDCARD) && (ccb_h->target_id < MAX_SESSIONS))
225 sp = isp->sessions[ccb_h->target_id];
226 else
227 sp = NULL;
228
229 ccb_h->spriv_ptr0 = sp;
190 ccb_h->spriv_ptr0 = sp;
230
231 debug(4, "func_code=0x%x flags=0x%x status=0x%x target=%d lun=%d retry_count=%d timeout=%d",
191 sdebug(4, "func_code=0x%x flags=0x%x status=0x%x target=%d lun=%d retry_count=%d timeout=%d",
232 ccb_h->func_code, ccb->ccb_h.flags, ccb->ccb_h.status,
233 ccb->ccb_h.target_id, ccb->ccb_h.target_lun,
234 ccb->ccb_h.retry_count, ccb_h->timeout);
192 ccb_h->func_code, ccb->ccb_h.flags, ccb->ccb_h.status,
193 ccb->ccb_h.target_id, ccb->ccb_h.target_lun,
194 ccb->ccb_h.retry_count, ccb_h->timeout);
235 /*
236 | first quick check
237 */
195 if(sp == NULL) {
196 xdebug("sp == NULL! cannot happen");
197 return;
198 }
238 switch(ccb_h->func_code) {
199 switch(ccb_h->func_code) {
239 default:
240 // XXX: maybe check something else?
241 break;
242
243 case XPT_SCSI_IO:
244 case XPT_RESET_DEV:
245 case XPT_GET_TRAN_SETTINGS:
246 case XPT_SET_TRAN_SETTINGS:
247 case XPT_CALC_GEOMETRY:
248 if(sp == NULL) {
249 ccb->ccb_h.status = CAM_DEV_NOT_THERE;
250#if __FreeBSD_version < 700000
251 XPT_DONE(isp, ccb);
252#else
253 xpt_done(ccb);
254#endif
255 return;
256 }
257 break;
258
259 case XPT_PATH_INQ:
200 case XPT_PATH_INQ:
260 case XPT_NOOP:
261 if(sp == NULL && ccb->ccb_h.target_id != CAM_TARGET_WILDCARD) {
262 ccb->ccb_h.status = CAM_DEV_NOT_THERE;
263#if __FreeBSD_version < 700000
264 XPT_DONE(isp, ccb);
265#else
266 xpt_done(ccb);
267#endif
268 debug(4, "status = CAM_DEV_NOT_THERE");
269 return;
270 }
271 }
272
273 switch(ccb_h->func_code) {
274
275 case XPT_PATH_INQ:
276 _inq(sim, ccb, (sp? sp->opt.maxluns: ISCSI_MAX_LUNS) - 1);
201 _inq(sim, ccb);
277 break;
278
279 case XPT_RESET_BUS: // (can just be a stub that does nothing and completes)
280 {
281 struct ccb_pathinq *cpi = &ccb->cpi;
282
283 debug(3, "XPT_RESET_BUS");
284 cpi->ccb_h.status = CAM_REQ_CMP;

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

305 break;
306 }
307
308 case XPT_CALC_GEOMETRY:
309 {
310 struct ccb_calc_geometry *ccg;
311
312 ccg = &ccb->ccg;
202 break;
203
204 case XPT_RESET_BUS: // (can just be a stub that does nothing and completes)
205 {
206 struct ccb_pathinq *cpi = &ccb->cpi;
207
208 debug(3, "XPT_RESET_BUS");
209 cpi->ccb_h.status = CAM_REQ_CMP;

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

230 break;
231 }
232
233 case XPT_CALC_GEOMETRY:
234 {
235 struct ccb_calc_geometry *ccg;
236
237 ccg = &ccb->ccg;
313 debug(6, "XPT_CALC_GEOMETRY vsize=%jd bsize=%d", ccg->volume_size, ccg->block_size);
238 debug(4, "sid=%d target=%d lun=%d XPT_CALC_GEOMETRY vsize=%jd bsize=%d",
239 sp->sid, ccb->ccb_h.target_id, ccb->ccb_h.target_lun,
240 ccg->volume_size, ccg->block_size);
314 if(ccg->block_size == 0 ||
315 (ccg->volume_size < ccg->block_size)) {
316 // print error message ...
317 /* XXX: what error is appropiate? */
318 break;
241 if(ccg->block_size == 0 ||
242 (ccg->volume_size < ccg->block_size)) {
243 // print error message ...
244 /* XXX: what error is appropiate? */
245 break;
319 } else
246 }
247 else {
248 int lun, *off, boff;
249
250 lun = ccb->ccb_h.target_lun;
251 if(lun > ISCSI_MAX_LUNS) {
252 // XXX:
253 xdebug("lun %d > ISCSI_MAX_LUNS!\n", lun);
254 lun %= ISCSI_MAX_LUNS;
255 }
256 off = &sp->target_lun[lun / (sizeof(int)*8)];
257 boff = BIT(lun % (sizeof(int)*8));
258 debug(4, "sp->target_nluns=%d *off=%x boff=%x",
259 sp->target_nluns, *off, boff);
260
261 if((*off & boff) == 0) {
262 sp->target_nluns++;
263 *off |= boff;
264 }
320 cam_calc_geometry(ccg, /*extended*/1);
265 cam_calc_geometry(ccg, /*extended*/1);
266 }
321 break;
322 }
323
324 case XPT_GET_TRAN_SETTINGS:
325 default:
326 ccb_h->status = CAM_REQ_INVALID;
327 break;
328 }
329#if __FreeBSD_version < 700000
267 break;
268 }
269
270 case XPT_GET_TRAN_SETTINGS:
271 default:
272 ccb_h->status = CAM_REQ_INVALID;
273 break;
274 }
275#if __FreeBSD_version < 700000
330 XPT_DONE(isp, ccb);
276 XPT_DONE(sp, ccb);
331#else
332 xpt_done(ccb);
333#endif
334 return;
335}
336
337static void
338ic_poll(struct cam_sim *sim)
339{
277#else
278 xpt_done(ccb);
279#endif
280 return;
281}
282
283static void
284ic_poll(struct cam_sim *sim)
285{
340 debug_called(8);
286 debug_called(4);
341
342}
343
344int
345ic_getCamVals(isc_session_t *sp, iscsi_cam_t *cp)
346{
287
288}
289
290int
291ic_getCamVals(isc_session_t *sp, iscsi_cam_t *cp)
292{
347 int i;
348
349 debug_called(8);
350
293 debug_called(8);
294
351 if(sp && sp->isc->cam_sim) {
352 cp->path_id = cam_sim_path(sp->isc->cam_sim);
353 cp->target_id = sp->sid;
354 cp->target_nluns = sp->target_nluns; // XXX: -1?
355 for(i = 0; i < cp->target_nluns; i++)
356 cp->target_lun[i] = sp->target_lun[i];
295 if(sp && sp->cam_sim) {
296 cp->path_id = cam_sim_path(sp->cam_sim);
297 cp->target_id = 0;
298 cp->target_nluns = ISCSI_MAX_LUNS; // XXX: -1?
357 return 0;
358 }
359 return ENXIO;
360}
361
362void
299 return 0;
300 }
301 return ENXIO;
302}
303
304void
363ic_destroy(struct isc_softc *isp)
305ic_destroy(isc_session_t *sp )
364{
365 debug_called(8);
366
306{
307 debug_called(8);
308
367 CAM_LOCK(isp); // can't harm :-)
309 if(sp->cam_path != NULL) {
310 sdebug(2, "name=%s unit=%d",
311 cam_sim_name(sp->cam_sim), cam_sim_unit(sp->cam_sim));
312 CAM_LOCK(sp);
313#if 0
314 xpt_async(AC_LOST_DEVICE, sp->cam_path, NULL);
315#else
316 xpt_async(XPT_RESET_BUS, sp->cam_path, NULL);
317#endif
318 xpt_free_path(sp->cam_path);
319 xpt_bus_deregister(cam_sim_path(sp->cam_sim));
320 cam_sim_free(sp->cam_sim, TRUE /*free_devq*/);
368
321
369 xpt_async(AC_LOST_DEVICE, isp->cam_path, NULL);
370 xpt_free_path(isp->cam_path);
371
372 xpt_bus_deregister(cam_sim_path(isp->cam_sim));
373 cam_sim_free(isp->cam_sim, TRUE /*free_devq*/);
374
375 CAM_UNLOCK(isp);
322 CAM_UNLOCK(sp);
323 sdebug(2, "done");
324 }
376}
377
378int
325}
326
327int
379ic_init(struct isc_softc *isp)
328ic_init(isc_session_t *sp)
380{
381 struct cam_sim *sim;
382 struct cam_devq *devq;
329{
330 struct cam_sim *sim;
331 struct cam_devq *devq;
383 struct cam_path *path;
384
332
333 debug_called(8);
334
385 if((devq = cam_simq_alloc(256)) == NULL)
386 return ENOMEM;
387
388#if __FreeBSD_version >= 700000
335 if((devq = cam_simq_alloc(256)) == NULL)
336 return ENOMEM;
337
338#if __FreeBSD_version >= 700000
389 mtx_init(&isp->cam_mtx, "isc-cam", NULL, MTX_DEF);
339 mtx_init(&sp->cam_mtx, "isc-cam", NULL, MTX_DEF);
390#else
391 isp->cam_mtx = Giant;
392#endif
340#else
341 isp->cam_mtx = Giant;
342#endif
393 sim = cam_sim_alloc(ic_action, ic_poll,
394 "iscsi", isp, 0/*unit*/,
343 sim = cam_sim_alloc(ic_action,
344 ic_poll,
345 "iscsi",
346 sp,
347 sp->sid, // unit
395#if __FreeBSD_version >= 700000
348#if __FreeBSD_version >= 700000
396 &isp->cam_mtx,
349 &sp->cam_mtx,
397#endif
350#endif
398 1/*max_dev_transactions*/,
399 100/*max_tagged_dev_transactions*/,
351 1, // max_dev_transactions
352 0, // max_tagged_dev_transactions
400 devq);
401 if(sim == NULL) {
402 cam_simq_free(devq);
403#if __FreeBSD_version >= 700000
353 devq);
354 if(sim == NULL) {
355 cam_simq_free(devq);
356#if __FreeBSD_version >= 700000
404 mtx_destroy(&isp->cam_mtx);
357 mtx_destroy(&sp->cam_mtx);
405#endif
406 return ENXIO;
407 }
358#endif
359 return ENXIO;
360 }
408 CAM_LOCK(isp);
361
362 CAM_LOCK(sp);
409 if(xpt_bus_register(sim,
410#if __FreeBSD_version >= 700000
411 NULL,
412#endif
363 if(xpt_bus_register(sim,
364#if __FreeBSD_version >= 700000
365 NULL,
366#endif
413 0/*bus_number*/) != CAM_SUCCESS)
414 goto bad;
367 0/*bus_number*/) != CAM_SUCCESS) {
415
368
416 if(xpt_create_path(&path, xpt_periph, cam_sim_path(sim),
417 CAM_TARGET_WILDCARD, CAM_LUN_WILDCARD) != CAM_REQ_CMP) {
418 xpt_bus_deregister(cam_sim_path(sim));
419 goto bad;
369 cam_sim_free(sim, /*free_devq*/TRUE);
370 CAM_UNLOCK(sp);
371#if __FreeBSD_version >= 700000
372 mtx_destroy(&sp->cam_mtx);
373#endif
374 return ENXIO;
420 }
375 }
376 sp->cam_sim = sim;
377 CAM_UNLOCK(sp);
421
378
422 CAM_UNLOCK(isp);
379 sdebug(1, "cam subsystem initialized");
423
380
424 isp->cam_sim = sim;
425 isp->cam_path = path;
381 ic_scan(sp);
426
382
427 debug(2, "cam subsystem initialized"); // XXX: add dev ...
428 debug(4, "sim=%p path=%p", sim, path);
429 return 0;
383 return 0;
430
431 bad:
432 cam_sim_free(sim, /*free_devq*/TRUE);
433 CAM_UNLOCK(isp);
434#if __FreeBSD_version >= 700000
435 mtx_destroy(&isp->cam_mtx);
436#endif
437 return ENXIO;
438}
384}