FreeBSD kernel CAM code
scsi_target.c
Go to the documentation of this file.
1/*-
2 * Generic SCSI Target Kernel Mode Driver
3 *
4 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
5 *
6 * Copyright (c) 2002 Nate Lawson.
7 * Copyright (c) 1998, 1999, 2001, 2002 Justin T. Gibbs.
8 * All rights reserved.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions, and the following disclaimer,
15 * without modification, immediately at the beginning of the file.
16 * 2. The name of the author may not be used to endorse or promote products
17 * derived from this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
23 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
30 */
31
32#include <sys/cdefs.h>
33__FBSDID("$FreeBSD$");
34
35#include <sys/param.h>
36#include <sys/systm.h>
37#include <sys/kernel.h>
38#include <sys/conf.h>
39#include <sys/malloc.h>
40#include <sys/poll.h>
41#include <sys/vnode.h>
42#include <sys/lock.h>
43#include <sys/mutex.h>
44#include <sys/devicestat.h>
45#include <sys/proc.h>
46/* Includes to support callout */
47#include <sys/types.h>
48#include <sys/systm.h>
49
50#include <cam/cam.h>
51#include <cam/cam_ccb.h>
52#include <cam/cam_periph.h>
53#include <cam/cam_xpt_periph.h>
54#include <cam/cam_sim.h>
56
57/* Transaction information attached to each CCB sent by the user */
60 TAILQ_ENTRY(targ_cmd_descr) tqe;
61 union ccb *user_ccb;
62 int priority;
63 int func_code;
64};
65
66/* Offset into the private CCB area for storing our descriptor */
67#define targ_descr periph_priv.entries[1].ptr
68
70
71typedef enum {
72 TARG_STATE_RESV = 0x00, /* Invalid state */
73 TARG_STATE_OPENED = 0x01, /* Device opened, softc initialized */
74 TARG_STATE_LUN_ENABLED = 0x02 /* Device enabled for a path */
76
77/* Per-instance device software context */
78struct targ_softc {
79 /* CCBs (CTIOs, ATIOs, INOTs) pending on the controller */
80 struct ccb_queue pending_ccb_queue;
81
82 /* Command descriptors awaiting CTIO resources from the XPT */
83 struct descr_queue work_queue;
84
85 /* Command descriptors that have been aborted back to the user. */
86 struct descr_queue abort_queue;
87
88 /*
89 * Queue of CCBs that have been copied out to userland, but our
90 * userland daemon has not yet seen.
91 */
92 struct ccb_queue user_ccb_queue;
93
95 struct cam_path *path;
97 u_int maxio;
98 struct selinfo read_select;
99 struct devstat device_stats;
100};
101
102static d_open_t targopen;
103static d_read_t targread;
104static d_write_t targwrite;
105static d_ioctl_t targioctl;
106static d_poll_t targpoll;
107static d_kqfilter_t targkqfilter;
108static void targreadfiltdetach(struct knote *kn);
109static int targreadfilt(struct knote *kn, long hint);
110static struct filterops targread_filtops = {
111 .f_isfd = 1,
112 .f_detach = targreadfiltdetach,
113 .f_event = targreadfilt,
114};
115
116static struct cdevsw targ_cdevsw = {
117 .d_version = D_VERSION,
118 .d_open = targopen,
119 .d_read = targread,
120 .d_write = targwrite,
121 .d_ioctl = targioctl,
122 .d_poll = targpoll,
123 .d_name = "targ",
124 .d_kqfilter = targkqfilter
125};
126
127static cam_status targendislun(struct cam_path *path, int enable,
128 int grp6_len, int grp7_len);
129static cam_status targenable(struct targ_softc *softc,
130 struct cam_path *path,
131 int grp6_len, int grp7_len);
132static cam_status targdisable(struct targ_softc *softc);
136static int targusermerge(struct targ_softc *softc,
137 struct targ_cmd_descr *descr,
138 union ccb *ccb);
139static int targsendccb(struct targ_softc *softc, union ccb *ccb,
140 struct targ_cmd_descr *descr);
141static void targdone(struct cam_periph *periph,
142 union ccb *done_ccb);
143static int targreturnccb(struct targ_softc *softc,
144 union ccb *ccb);
145static union ccb * targgetccb(struct targ_softc *softc, xpt_opcode type,
146 int priority);
147static void targfreeccb(struct targ_softc *softc, union ccb *ccb);
148static struct targ_cmd_descr *
149 targgetdescr(struct targ_softc *softc);
151static void targasync(void *callback_arg, u_int32_t code,
152 struct cam_path *path, void *arg);
153static void abort_all_pending(struct targ_softc *softc);
154static void notify_user(struct targ_softc *softc);
155static int targcamstatus(cam_status status);
156static size_t targccblen(xpt_opcode func_code);
157
159{
160 targinit, "targ",
161 TAILQ_HEAD_INITIALIZER(targdriver.units), /* generation */ 0
162};
164
165static MALLOC_DEFINE(M_TARG, "TARG", "TARG data");
166
167/* Disable LUN if enabled and teardown softc */
168static void
169targcdevdtor(void *data)
170{
171 struct targ_softc *softc;
172 struct cam_periph *periph;
173
174 softc = data;
175 if (softc->periph == NULL) {
176 printf("%s: destroying non-enabled target\n", __func__);
177 free(softc, M_TARG);
178 return;
179 }
180
181 /*
182 * Acquire a hold on the periph so that it doesn't go away before
183 * we are ready at the end of the function.
184 */
185 periph = softc->periph;
186 cam_periph_acquire(periph);
187 cam_periph_lock(periph);
188 (void)targdisable(softc);
189 if (softc->periph != NULL) {
191 softc->periph = NULL;
192 }
193 cam_periph_unlock(periph);
194 cam_periph_release(periph);
195 free(softc, M_TARG);
196}
197
198/*
199 * Create softc and initialize it. There is no locking here because a
200 * periph doesn't get created until an ioctl is issued to do so, and
201 * that can't happen until this method returns.
202 */
203static int
204targopen(struct cdev *dev, int flags, int fmt, struct thread *td)
205{
206 struct targ_softc *softc;
207
208 /* Allocate its softc, initialize it */
209 softc = malloc(sizeof(*softc), M_TARG,
210 M_WAITOK | M_ZERO);
211 softc->state = TARG_STATE_OPENED;
212 softc->periph = NULL;
213 softc->path = NULL;
214
215 TAILQ_INIT(&softc->pending_ccb_queue);
216 TAILQ_INIT(&softc->work_queue);
217 TAILQ_INIT(&softc->abort_queue);
218 TAILQ_INIT(&softc->user_ccb_queue);
219 knlist_init_mtx(&softc->read_select.si_note, NULL);
220
221 devfs_set_cdevpriv(softc, targcdevdtor);
222 return (0);
223}
224
225/* Enable/disable LUNs, set debugging level */
226static int
227targioctl(struct cdev *dev, u_long cmd, caddr_t addr, int flag, struct thread *td)
228{
229 struct targ_softc *softc;
230 cam_status status;
231
232 devfs_get_cdevpriv((void **)&softc);
233
234 switch (cmd) {
235 case TARGIOCENABLE:
236 {
237 struct ioc_enable_lun *new_lun;
238 struct cam_path *path;
239
240 new_lun = (struct ioc_enable_lun *)addr;
241 status = xpt_create_path(&path, /*periph*/NULL,
242 new_lun->path_id,
243 new_lun->target_id,
244 new_lun->lun_id);
245 if (status != CAM_REQ_CMP) {
246 printf("Couldn't create path, status %#x\n", status);
247 break;
248 }
249 xpt_path_lock(path);
250 status = targenable(softc, path, new_lun->grp6_len,
251 new_lun->grp7_len);
252 xpt_path_unlock(path);
253 xpt_free_path(path);
254 break;
255 }
256 case TARGIOCDISABLE:
257 if (softc->periph == NULL) {
258 status = CAM_DEV_NOT_THERE;
259 break;
260 }
261 cam_periph_lock(softc->periph);
262 status = targdisable(softc);
264 break;
265 case TARGIOCDEBUG:
266 {
267 struct ccb_debug cdbg;
268
269 /* If no periph available, disallow debugging changes */
270 if ((softc->state & TARG_STATE_LUN_ENABLED) == 0) {
271 status = CAM_DEV_NOT_THERE;
272 break;
273 }
274 bzero(&cdbg, sizeof cdbg);
275 if (*((int *)addr) != 0)
276 cdbg.flags = CAM_DEBUG_PERIPH;
277 else
278 cdbg.flags = CAM_DEBUG_NONE;
281 cdbg.ccb_h.cbfcnp = targdone;
282 xpt_action((union ccb *)&cdbg);
283 status = cdbg.ccb_h.status & CAM_STATUS_MASK;
284 break;
285 }
286 default:
287 status = CAM_PROVIDE_FAIL;
288 break;
289 }
290
291 return (targcamstatus(status));
292}
293
294/* Writes are always ready, reads wait for user_ccb_queue or abort_queue */
295static int
296targpoll(struct cdev *dev, int poll_events, struct thread *td)
297{
298 struct targ_softc *softc;
299 int revents;
300
301 devfs_get_cdevpriv((void **)&softc);
302
303 /* Poll for write() is always ok. */
304 revents = poll_events & (POLLOUT | POLLWRNORM);
305 if ((poll_events & (POLLIN | POLLRDNORM)) != 0) {
306 /* Poll for read() depends on user and abort queues. */
307 cam_periph_lock(softc->periph);
308 if (!TAILQ_EMPTY(&softc->user_ccb_queue) ||
309 !TAILQ_EMPTY(&softc->abort_queue)) {
310 revents |= poll_events & (POLLIN | POLLRDNORM);
311 }
313 /* Only sleep if the user didn't poll for write. */
314 if (revents == 0)
315 selrecord(td, &softc->read_select);
316 }
317
318 return (revents);
319}
320
321static int
322targkqfilter(struct cdev *dev, struct knote *kn)
323{
324 struct targ_softc *softc;
325
326 devfs_get_cdevpriv((void **)&softc);
327 kn->kn_hook = (caddr_t)softc;
328 kn->kn_fop = &targread_filtops;
329 knlist_add(&softc->read_select.si_note, kn, 0);
330 return (0);
331}
332
333static void
334targreadfiltdetach(struct knote *kn)
335{
336 struct targ_softc *softc;
337
338 softc = (struct targ_softc *)kn->kn_hook;
339 knlist_remove(&softc->read_select.si_note, kn, 0);
340}
341
342/* Notify the user's kqueue when the user queue or abort queue gets a CCB */
343static int
344targreadfilt(struct knote *kn, long hint)
345{
346 struct targ_softc *softc;
347 int retval;
348
349 softc = (struct targ_softc *)kn->kn_hook;
350 cam_periph_lock(softc->periph);
351 retval = !TAILQ_EMPTY(&softc->user_ccb_queue) ||
352 !TAILQ_EMPTY(&softc->abort_queue);
354 return (retval);
355}
356
357/* Send the HBA the enable/disable message */
358static cam_status
359targendislun(struct cam_path *path, int enable, int grp6_len, int grp7_len)
360{
361 struct ccb_en_lun en_ccb;
362 cam_status status;
363
364 /* Tell the lun to begin answering selects */
365 memset(&en_ccb, 0, sizeof(en_ccb));
367 en_ccb.ccb_h.func_code = XPT_EN_LUN;
368 /* Don't need support for any vendor specific commands */
369 en_ccb.grp6_len = grp6_len;
370 en_ccb.grp7_len = grp7_len;
371 en_ccb.enable = enable ? 1 : 0;
372 xpt_action((union ccb *)&en_ccb);
373 status = en_ccb.ccb_h.status & CAM_STATUS_MASK;
374 if (status != CAM_REQ_CMP) {
375 xpt_print(path, "%sable lun CCB rejected, status %#x\n",
376 enable ? "en" : "dis", status);
377 }
378 return (status);
379}
380
381/* Enable target mode on a LUN, given its path */
382static cam_status
383targenable(struct targ_softc *softc, struct cam_path *path, int grp6_len,
384 int grp7_len)
385{
386 struct cam_periph *periph;
387 struct ccb_pathinq cpi;
388 cam_status status;
389
390 if ((softc->state & TARG_STATE_LUN_ENABLED) != 0)
391 return (CAM_LUN_ALRDY_ENA);
392
393 /* Make sure SIM supports target mode */
394 xpt_path_inq(&cpi, path);
395 status = cpi.ccb_h.status & CAM_STATUS_MASK;
396 if (status != CAM_REQ_CMP) {
397 printf("pathinq failed, status %#x\n", status);
398 goto enable_fail;
399 }
400 if ((cpi.target_sprt & PIT_PROCESSOR) == 0) {
401 printf("controller does not support target mode\n");
402 status = CAM_FUNC_NOTAVAIL;
403 goto enable_fail;
404 }
405 if (cpi.maxio == 0)
406 softc->maxio = DFLTPHYS; /* traditional default */
407 else if (cpi.maxio > maxphys)
408 softc->maxio = maxphys; /* for safety */
409 else
410 softc->maxio = cpi.maxio; /* real value */
411
412 /* Destroy any periph on our path if it is disabled */
413 periph = cam_periph_find(path, "targ");
414 if (periph != NULL) {
415 struct targ_softc *del_softc;
416
417 del_softc = (struct targ_softc *)periph->softc;
418 if ((del_softc->state & TARG_STATE_LUN_ENABLED) == 0) {
419 cam_periph_invalidate(del_softc->periph);
420 del_softc->periph = NULL;
421 } else {
422 printf("Requested path still in use by targ%d\n",
424 status = CAM_LUN_ALRDY_ENA;
425 goto enable_fail;
426 }
427 }
428
429 /* Create a periph instance attached to this path */
431 "targ", CAM_PERIPH_BIO, path, targasync, 0, softc);
432 if (status != CAM_REQ_CMP) {
433 printf("cam_periph_alloc failed, status %#x\n", status);
434 goto enable_fail;
435 }
436
437 /* Ensure that the periph now exists. */
438 if (cam_periph_find(path, "targ") == NULL) {
439 panic("targenable: succeeded but no periph?");
440 /* NOTREACHED */
441 }
442
443 /* Send the enable lun message */
444 status = targendislun(path, /*enable*/1, grp6_len, grp7_len);
445 if (status != CAM_REQ_CMP) {
446 printf("enable lun failed, status %#x\n", status);
447 goto enable_fail;
448 }
450
451enable_fail:
452 return (status);
453}
454
455/* Disable this softc's target instance if enabled */
456static cam_status
458{
459 cam_status status;
460
461 if ((softc->state & TARG_STATE_LUN_ENABLED) == 0)
462 return (CAM_REQ_CMP);
463
464 CAM_DEBUG(softc->path, CAM_DEBUG_PERIPH, ("targdisable\n"));
465
466 /* Abort any ccbs pending on the controller */
467 abort_all_pending(softc);
468
469 /* Disable this lun */
470 status = targendislun(softc->path, /*enable*/0,
471 /*grp6_len*/0, /*grp7_len*/0);
472 if (status == CAM_REQ_CMP)
473 softc->state &= ~TARG_STATE_LUN_ENABLED;
474 else
475 printf("Disable lun failed, status %#x\n", status);
476
477 return (status);
478}
479
480/* Initialize a periph (called from cam_periph_alloc) */
481static cam_status
482targctor(struct cam_periph *periph, void *arg)
483{
484 struct targ_softc *softc;
485
486 /* Store pointer to softc for periph-driven routines */
487 softc = (struct targ_softc *)arg;
488 periph->softc = softc;
489 softc->periph = periph;
490 softc->path = periph->path;
491 return (CAM_REQ_CMP);
492}
493
494static void
496{
497 struct targ_softc *softc;
498 struct ccb_hdr *ccb_h;
499 struct targ_cmd_descr *descr;
500
501 softc = (struct targ_softc *)periph->softc;
502
503 /*
504 * targdisable() aborts CCBs back to the user and leaves them
505 * on user_ccb_queue and abort_queue in case the user is still
506 * interested in them. We free them now.
507 */
508 while ((ccb_h = TAILQ_FIRST(&softc->user_ccb_queue)) != NULL) {
509 TAILQ_REMOVE(&softc->user_ccb_queue, ccb_h, periph_links.tqe);
510 targfreeccb(softc, (union ccb *)ccb_h);
511 }
512 while ((descr = TAILQ_FIRST(&softc->abort_queue)) != NULL) {
513 TAILQ_REMOVE(&softc->abort_queue, descr, tqe);
514 free(descr, M_TARG);
515 }
516
517 softc->periph = NULL;
518 softc->path = NULL;
519 periph->softc = NULL;
520}
521
522/* Receive CCBs from user mode proc and send them to the HBA */
523static int
524targwrite(struct cdev *dev, struct uio *uio, int ioflag)
525{
526 union ccb *user_ccb;
527 struct targ_softc *softc;
528 struct targ_cmd_descr *descr;
529 int write_len, error;
530 int func_code, priority;
531
532 devfs_get_cdevpriv((void **)&softc);
533 write_len = error = 0;
535 ("write - uio_resid %zd\n", uio->uio_resid));
536 while (uio->uio_resid >= sizeof(user_ccb) && error == 0) {
537 union ccb *ccb;
538
539 error = uiomove((caddr_t)&user_ccb, sizeof(user_ccb), uio);
540 if (error != 0) {
542 ("write - uiomove failed (%d)\n", error));
543 break;
544 }
545 priority = fuword32(&user_ccb->ccb_h.pinfo.priority);
546 if (priority == CAM_PRIORITY_NONE) {
547 error = EINVAL;
548 break;
549 }
550 func_code = fuword32(&user_ccb->ccb_h.func_code);
551 switch (func_code) {
553 case XPT_IMMED_NOTIFY:
555 cam_periph_lock(softc->periph);
556 ccb = targgetccb(softc, func_code, priority);
557 descr = (struct targ_cmd_descr *)ccb->ccb_h.targ_descr;
558 descr->user_ccb = user_ccb;
559 descr->func_code = func_code;
561 ("Sent ATIO/INOT (%p)\n", user_ccb));
563 TAILQ_INSERT_TAIL(&softc->pending_ccb_queue,
564 &ccb->ccb_h,
565 periph_links.tqe);
567 break;
568 default:
569 cam_periph_lock(softc->periph);
570 if ((func_code & XPT_FC_QUEUED) != 0) {
572 ("Sending queued ccb %#x (%p)\n",
573 func_code, user_ccb));
574 descr = targgetdescr(softc);
575 descr->user_ccb = user_ccb;
576 descr->priority = priority;
577 descr->func_code = func_code;
578 TAILQ_INSERT_TAIL(&softc->work_queue,
579 descr, tqe);
580 xpt_schedule(softc->periph, priority);
581 } else {
583 ("Sending inline ccb %#x (%p)\n",
584 func_code, user_ccb));
585 ccb = targgetccb(softc, func_code, priority);
586 descr = (struct targ_cmd_descr *)
587 ccb->ccb_h.targ_descr;
588 descr->user_ccb = user_ccb;
589 descr->priority = priority;
590 descr->func_code = func_code;
591 if (targusermerge(softc, descr, ccb) != EFAULT)
592 targsendccb(softc, ccb, descr);
593 targreturnccb(softc, ccb);
594 }
596 break;
597 }
598 write_len += sizeof(user_ccb);
599 }
600
601 /*
602 * If we've successfully taken in some amount of
603 * data, return success for that data first. If
604 * an error is persistent, it will be reported
605 * on the next write.
606 */
607 if (error != 0 && write_len == 0)
608 return (error);
609 if (write_len == 0 && uio->uio_resid != 0)
610 return (ENOSPC);
611 return (0);
612}
613
614/* Process requests (descrs) via the periph-supplied CCBs */
615static void
616targstart(struct cam_periph *periph, union ccb *start_ccb)
617{
618 struct targ_softc *softc;
619 struct targ_cmd_descr *descr, *next_descr;
620 int error;
621
622 softc = (struct targ_softc *)periph->softc;
623 CAM_DEBUG(softc->path, CAM_DEBUG_PERIPH, ("targstart %p\n", start_ccb));
624
625 descr = TAILQ_FIRST(&softc->work_queue);
626 if (descr == NULL) {
627 xpt_release_ccb(start_ccb);
628 } else {
629 TAILQ_REMOVE(&softc->work_queue, descr, tqe);
630 next_descr = TAILQ_FIRST(&softc->work_queue);
631
632 /* Initiate a transaction using the descr and supplied CCB */
633 error = targusermerge(softc, descr, start_ccb);
634 if (error == 0)
635 error = targsendccb(softc, start_ccb, descr);
636 if (error != 0) {
638 "targsendccb failed, err %d\n", error);
639 xpt_release_ccb(start_ccb);
640 suword(&descr->user_ccb->ccb_h.status,
642 TAILQ_INSERT_TAIL(&softc->abort_queue, descr, tqe);
643 notify_user(softc);
644 }
645
646 /* If we have more work to do, stay scheduled */
647 if (next_descr != NULL)
648 xpt_schedule(periph, next_descr->priority);
649 }
650}
651
652static int
653targusermerge(struct targ_softc *softc, struct targ_cmd_descr *descr,
654 union ccb *ccb)
655{
656 struct ccb_hdr *u_ccbh, *k_ccbh;
657 size_t ccb_len;
658 int error;
659
660 u_ccbh = &descr->user_ccb->ccb_h;
661 k_ccbh = &ccb->ccb_h;
662
663 /*
664 * There are some fields in the CCB header that need to be
665 * preserved, the rest we get from the user ccb. (See xpt_merge_ccb)
666 */
667 xpt_setup_ccb(k_ccbh, softc->path, descr->priority);
668 k_ccbh->retry_count = fuword32(&u_ccbh->retry_count);
669 k_ccbh->func_code = descr->func_code;
670 k_ccbh->flags = fuword32(&u_ccbh->flags);
671 k_ccbh->timeout = fuword32(&u_ccbh->timeout);
672 ccb_len = targccblen(k_ccbh->func_code) - sizeof(struct ccb_hdr);
673 error = copyin(u_ccbh + 1, k_ccbh + 1, ccb_len);
674 if (error != 0) {
675 k_ccbh->status = CAM_REQ_CMP_ERR;
676 return (error);
677 }
678
679 /* Translate usermode abort_ccb pointer to its kernel counterpart */
680 if (k_ccbh->func_code == XPT_ABORT) {
681 struct ccb_abort *cab;
682 struct ccb_hdr *ccb_h;
683
684 cab = (struct ccb_abort *)ccb;
685 TAILQ_FOREACH(ccb_h, &softc->pending_ccb_queue,
686 periph_links.tqe) {
687 struct targ_cmd_descr *ab_descr;
688
689 ab_descr = (struct targ_cmd_descr *)ccb_h->targ_descr;
690 if (ab_descr->user_ccb == cab->abort_ccb) {
692 ("Changing abort for %p to %p\n",
693 cab->abort_ccb, ccb_h));
694 cab->abort_ccb = (union ccb *)ccb_h;
695 break;
696 }
697 }
698 /* CCB not found, set appropriate status */
699 if (ccb_h == NULL) {
700 k_ccbh->status = CAM_PATH_INVALID;
701 error = ESRCH;
702 }
703 }
704
705 return (error);
706}
707
708/* Build and send a kernel CCB formed from descr->user_ccb */
709static int
710targsendccb(struct targ_softc *softc, union ccb *ccb,
711 struct targ_cmd_descr *descr)
712{
713 struct cam_periph_map_info *mapinfo;
714 struct ccb_hdr *ccb_h;
715 int error;
716
717 ccb_h = &ccb->ccb_h;
718 mapinfo = &descr->mapinfo;
719 mapinfo->num_bufs_used = 0;
720
721 /*
722 * There's no way for the user to have a completion
723 * function, so we put our own completion function in here.
724 * We also stash in a reference to our descriptor so targreturnccb()
725 * can find our mapping info.
726 */
727 ccb_h->cbfcnp = targdone;
728 ccb_h->targ_descr = descr;
729
730 if ((ccb_h->func_code == XPT_CONT_TARGET_IO) ||
731 (ccb_h->func_code == XPT_DEV_MATCH)) {
732 error = cam_periph_mapmem(ccb, mapinfo, softc->maxio);
733
734 /*
735 * cam_periph_mapmem returned an error, we can't continue.
736 * Return the error to the user.
737 */
738 if (error) {
739 ccb_h->status = CAM_REQ_CMP_ERR;
740 mapinfo->num_bufs_used = 0;
741 return (error);
742 }
743 }
744
745 /*
746 * Once queued on the pending CCB list, this CCB will be protected
747 * by our error recovery handler.
748 */
749 CAM_DEBUG(softc->path, CAM_DEBUG_PERIPH, ("sendccb %p\n", ccb));
750 if (XPT_FC_IS_QUEUED(ccb)) {
751 TAILQ_INSERT_TAIL(&softc->pending_ccb_queue, ccb_h,
752 periph_links.tqe);
753 }
755
756 return (0);
757}
758
759/* Completion routine for CCBs (called at splsoftcam) */
760static void
761targdone(struct cam_periph *periph, union ccb *done_ccb)
762{
763 struct targ_softc *softc;
764
765 CAM_DEBUG(periph->path, CAM_DEBUG_PERIPH, ("targdone %p\n", done_ccb));
766 softc = (struct targ_softc *)periph->softc;
767 TAILQ_REMOVE(&softc->pending_ccb_queue, &done_ccb->ccb_h,
768 periph_links.tqe);
769
770 /* If we're no longer enabled, throw away CCB */
771 if ((softc->state & TARG_STATE_LUN_ENABLED) == 0) {
772 targfreeccb(softc, done_ccb);
773 return;
774 }
775 /* abort_all_pending() waits for pending queue to be empty */
776 if (TAILQ_EMPTY(&softc->pending_ccb_queue))
777 wakeup(&softc->pending_ccb_queue);
778
779 switch (done_ccb->ccb_h.func_code) {
780 /* All FC_*_QUEUED CCBs go back to userland */
781 case XPT_IMMED_NOTIFY:
785 TAILQ_INSERT_TAIL(&softc->user_ccb_queue, &done_ccb->ccb_h,
786 periph_links.tqe);
788 notify_user(softc);
789 cam_periph_lock(softc->periph);
790 break;
791 default:
792 panic("targdone: impossible xpt opcode %#x",
793 done_ccb->ccb_h.func_code);
794 /* NOTREACHED */
795 }
796}
797
798/* Return CCBs to the user from the user queue and abort queue */
799static int
800targread(struct cdev *dev, struct uio *uio, int ioflag)
801{
802 struct descr_queue *abort_queue;
803 struct targ_cmd_descr *user_descr;
804 struct targ_softc *softc;
805 struct ccb_queue *user_queue;
806 struct ccb_hdr *ccb_h;
807 union ccb *user_ccb;
808 int read_len, error;
809
810 error = 0;
811 read_len = 0;
812 devfs_get_cdevpriv((void **)&softc);
813 user_queue = &softc->user_ccb_queue;
814 abort_queue = &softc->abort_queue;
815 CAM_DEBUG(softc->path, CAM_DEBUG_PERIPH, ("targread\n"));
816
817 /* If no data is available, wait or return immediately */
818 cam_periph_lock(softc->periph);
819 ccb_h = TAILQ_FIRST(user_queue);
820 user_descr = TAILQ_FIRST(abort_queue);
821 while (ccb_h == NULL && user_descr == NULL) {
822 if ((ioflag & IO_NDELAY) == 0) {
823 error = cam_periph_sleep(softc->periph, user_queue,
824 PRIBIO | PCATCH, "targrd", 0);
825 ccb_h = TAILQ_FIRST(user_queue);
826 user_descr = TAILQ_FIRST(abort_queue);
827 if (error != 0) {
828 if (error == ERESTART) {
829 continue;
830 } else {
831 goto read_fail;
832 }
833 }
834 } else {
836 return (EAGAIN);
837 }
838 }
839
840 /* Data is available so fill the user's buffer */
841 while (ccb_h != NULL) {
842 struct targ_cmd_descr *descr;
843
844 if (uio->uio_resid < sizeof(user_ccb))
845 break;
846 TAILQ_REMOVE(user_queue, ccb_h, periph_links.tqe);
847 descr = (struct targ_cmd_descr *)ccb_h->targ_descr;
848 user_ccb = descr->user_ccb;
850 ("targread ccb %p (%p)\n", ccb_h, user_ccb));
851 error = targreturnccb(softc, (union ccb *)ccb_h);
852 if (error != 0)
853 goto read_fail;
855 error = uiomove((caddr_t)&user_ccb, sizeof(user_ccb), uio);
856 cam_periph_lock(softc->periph);
857 if (error != 0)
858 goto read_fail;
859 read_len += sizeof(user_ccb);
860
861 ccb_h = TAILQ_FIRST(user_queue);
862 }
863
864 /* Flush out any aborted descriptors */
865 while (user_descr != NULL) {
866 if (uio->uio_resid < sizeof(user_ccb))
867 break;
868 TAILQ_REMOVE(abort_queue, user_descr, tqe);
869 user_ccb = user_descr->user_ccb;
871 ("targread aborted descr %p (%p)\n",
872 user_descr, user_ccb));
873 suword(&user_ccb->ccb_h.status, CAM_REQ_ABORTED);
875 error = uiomove((caddr_t)&user_ccb, sizeof(user_ccb), uio);
876 cam_periph_lock(softc->periph);
877 if (error != 0)
878 goto read_fail;
879 read_len += sizeof(user_ccb);
880
881 user_descr = TAILQ_FIRST(abort_queue);
882 }
883
884 /*
885 * If we've successfully read some amount of data, don't report an
886 * error. If the error is persistent, it will be reported on the
887 * next read().
888 */
889 if (read_len == 0 && uio->uio_resid != 0)
890 error = ENOSPC;
891
892read_fail:
894 return (error);
895}
896
897/* Copy completed ccb back to the user */
898static int
899targreturnccb(struct targ_softc *softc, union ccb *ccb)
900{
901 struct targ_cmd_descr *descr;
902 struct ccb_hdr *u_ccbh;
903 size_t ccb_len;
904 int error;
905
906 CAM_DEBUG(softc->path, CAM_DEBUG_PERIPH, ("targreturnccb %p\n", ccb));
907 descr = (struct targ_cmd_descr *)ccb->ccb_h.targ_descr;
908 u_ccbh = &descr->user_ccb->ccb_h;
909
910 /* Copy out the central portion of the ccb_hdr */
911 copyout(&ccb->ccb_h.retry_count, &u_ccbh->retry_count,
912 offsetof(struct ccb_hdr, periph_priv) -
913 offsetof(struct ccb_hdr, retry_count));
914
915 /* Copy out the rest of the ccb (after the ccb_hdr) */
916 ccb_len = targccblen(ccb->ccb_h.func_code) - sizeof(struct ccb_hdr);
917 if (descr->mapinfo.num_bufs_used != 0)
919 error = copyout(&ccb->ccb_h + 1, u_ccbh + 1, ccb_len);
920 if (error != 0) {
921 xpt_print(softc->path,
922 "targreturnccb - CCB copyout failed (%d)\n", error);
923 }
924 /* Free CCB or send back to devq. */
925 targfreeccb(softc, ccb);
926
927 return (error);
928}
929
930static union ccb *
931targgetccb(struct targ_softc *softc, xpt_opcode type, int priority)
932{
933 union ccb *ccb;
934 int ccb_len;
935
936 ccb_len = targccblen(type);
937 ccb = malloc(ccb_len, M_TARG, M_NOWAIT | M_ZERO);
938 CAM_DEBUG(softc->path, CAM_DEBUG_PERIPH, ("getccb %p\n", ccb));
939 if (ccb == NULL) {
940 return (ccb);
941 }
942 xpt_setup_ccb(&ccb->ccb_h, softc->path, priority);
943 ccb->ccb_h.func_code = type;
945 ccb->ccb_h.targ_descr = targgetdescr(softc);
946 if (ccb->ccb_h.targ_descr == NULL) {
947 free (ccb, M_TARG);
948 ccb = NULL;
949 }
950 return (ccb);
951}
952
953static void
954targfreeccb(struct targ_softc *softc, union ccb *ccb)
955{
956 CAM_DEBUG_PRINT(CAM_DEBUG_PERIPH, ("targfreeccb descr %p and\n",
957 ccb->ccb_h.targ_descr));
958 free(ccb->ccb_h.targ_descr, M_TARG);
959
960 switch (ccb->ccb_h.func_code) {
962 case XPT_IMMED_NOTIFY:
964 CAM_DEBUG_PRINT(CAM_DEBUG_PERIPH, ("freeing ccb %p\n", ccb));
965 free(ccb, M_TARG);
966 break;
967 default:
968 /* Send back CCB if we got it from the periph */
969 if (XPT_FC_IS_QUEUED(ccb)) {
971 ("returning queued ccb %p\n", ccb));
973 } else {
975 ("freeing ccb %p\n", ccb));
976 free(ccb, M_TARG);
977 }
978 break;
979 }
980}
981
982static struct targ_cmd_descr *
984{
985 struct targ_cmd_descr *descr;
986
987 descr = malloc(sizeof(*descr), M_TARG,
988 M_NOWAIT);
989 if (descr) {
990 descr->mapinfo.num_bufs_used = 0;
991 }
992 return (descr);
993}
994
995static void
996targinit(void)
997{
998 struct cdev *dev;
999
1000 /* Add symbolic link to targ0 for compatibility. */
1001 dev = make_dev(&targ_cdevsw, 0, UID_ROOT, GID_WHEEL, 0600, "targ");
1002 make_dev_alias(dev, "targ0");
1003}
1004
1005static void
1006targasync(void *callback_arg, u_int32_t code, struct cam_path *path, void *arg)
1007{
1008 /* All events are handled in usermode by INOTs */
1009 panic("targasync() called, should be an INOT instead");
1010}
1011
1012/* Cancel all pending requests and CCBs awaiting work. */
1013static void
1015{
1016 struct targ_cmd_descr *descr;
1017 struct ccb_abort cab;
1018 struct ccb_hdr *ccb_h;
1019
1020 CAM_DEBUG(softc->path, CAM_DEBUG_PERIPH, ("abort_all_pending\n"));
1021
1022 /* First abort the descriptors awaiting resources */
1023 while ((descr = TAILQ_FIRST(&softc->work_queue)) != NULL) {
1025 ("Aborting descr from workq %p\n", descr));
1026 TAILQ_REMOVE(&softc->work_queue, descr, tqe);
1027 TAILQ_INSERT_TAIL(&softc->abort_queue, descr, tqe);
1028 }
1029
1030 /*
1031 * Then abort all pending CCBs.
1032 * targdone() will return the aborted CCB via user_ccb_queue
1033 */
1034 memset(&cab, 0, sizeof(cab));
1038 TAILQ_FOREACH(ccb_h, &softc->pending_ccb_queue, periph_links.tqe) {
1040 ("Aborting pending CCB %p\n", ccb_h));
1041 cab.abort_ccb = (union ccb *)ccb_h;
1042 xpt_action((union ccb *)&cab);
1043 if (cab.ccb_h.status != CAM_REQ_CMP) {
1045 "Unable to abort CCB, status %#x\n",
1046 cab.ccb_h.status);
1047 }
1048 }
1049
1050 /* If we aborted at least one pending CCB ok, wait for it. */
1051 if (cab.ccb_h.status == CAM_REQ_CMP) {
1053 PRIBIO | PCATCH, "tgabrt", 0);
1054 }
1055
1056 /* If we aborted anything from the work queue, wakeup user. */
1057 if (!TAILQ_EMPTY(&softc->user_ccb_queue)
1058 || !TAILQ_EMPTY(&softc->abort_queue)) {
1059 cam_periph_unlock(softc->periph);
1060 notify_user(softc);
1061 cam_periph_lock(softc->periph);
1062 }
1063}
1064
1065/* Notify the user that data is ready */
1066static void
1068{
1069 /*
1070 * Notify users sleeping via poll(), kqueue(), and
1071 * blocking read().
1072 */
1073 selwakeuppri(&softc->read_select, PRIBIO);
1074 KNOTE_UNLOCKED(&softc->read_select.si_note, 0);
1075 wakeup(&softc->user_ccb_queue);
1076}
1077
1078/* Convert CAM status to errno values */
1079static int
1081{
1082 switch (status & CAM_STATUS_MASK) {
1083 case CAM_REQ_CMP: /* CCB request completed without error */
1084 return (0);
1085 case CAM_REQ_INPROG: /* CCB request is in progress */
1086 return (EINPROGRESS);
1087 case CAM_REQ_CMP_ERR: /* CCB request completed with an error */
1088 return (EIO);
1089 case CAM_PROVIDE_FAIL: /* Unable to provide requested capability */
1090 return (ENOTTY);
1091 case CAM_FUNC_NOTAVAIL: /* The requested function is not available */
1092 return (ENOTSUP);
1093 case CAM_LUN_ALRDY_ENA: /* LUN is already enabled for target mode */
1094 return (EADDRINUSE);
1095 case CAM_PATH_INVALID: /* Supplied Path ID is invalid */
1096 case CAM_DEV_NOT_THERE: /* SCSI Device Not Installed/there */
1097 return (ENOENT);
1098 case CAM_REQ_ABORTED: /* CCB request aborted by the host */
1099 return (ECANCELED);
1100 case CAM_CMD_TIMEOUT: /* Command timeout */
1101 return (ETIMEDOUT);
1102 case CAM_REQUEUE_REQ: /* Requeue to preserve transaction ordering */
1103 return (EAGAIN);
1104 case CAM_REQ_INVALID: /* CCB request was invalid */
1105 return (EINVAL);
1106 case CAM_RESRC_UNAVAIL: /* Resource Unavailable */
1107 return (ENOMEM);
1108 case CAM_BUSY: /* CAM subsystem is busy */
1109 case CAM_UA_ABORT: /* Unable to abort CCB request */
1110 return (EBUSY);
1111 default:
1112 return (ENXIO);
1113 }
1114}
1115
1116static size_t
1118{
1119 int len;
1120
1121 /* Codes we expect to see as a target */
1122 switch (func_code) {
1123 case XPT_CONT_TARGET_IO:
1124 case XPT_SCSI_IO:
1125 len = sizeof(struct ccb_scsiio);
1126 break;
1128 len = sizeof(struct ccb_accept_tio);
1129 break;
1130 case XPT_IMMED_NOTIFY:
1131 len = sizeof(struct ccb_immed_notify);
1132 break;
1134 len = sizeof(struct ccb_immediate_notify);
1135 break;
1136 case XPT_REL_SIMQ:
1137 len = sizeof(struct ccb_relsim);
1138 break;
1139 case XPT_PATH_INQ:
1140 len = sizeof(struct ccb_pathinq);
1141 break;
1142 case XPT_DEBUG:
1143 len = sizeof(struct ccb_debug);
1144 break;
1145 case XPT_ABORT:
1146 len = sizeof(struct ccb_abort);
1147 break;
1148 case XPT_EN_LUN:
1149 len = sizeof(struct ccb_en_lun);
1150 break;
1151 default:
1152 len = sizeof(union ccb);
1153 break;
1154 }
1155
1156 return (len);
1157}
#define CAM_PRIORITY_NORMAL
Definition: cam.h:92
#define CAM_PRIORITY_NONE
Definition: cam.h:93
cam_status
Definition: cam.h:132
@ CAM_PATH_INVALID
Definition: cam.h:155
@ CAM_REQ_INVALID
Definition: cam.h:152
@ CAM_REQ_INPROG
Definition: cam.h:134
@ CAM_BUSY
Definition: cam.h:149
@ CAM_PROVIDE_FAIL
Definition: cam.h:200
@ CAM_REQ_CMP
Definition: cam.h:137
@ CAM_REQUEUE_REQ
Definition: cam.h:222
@ CAM_DEV_NOT_THERE
Definition: cam.h:158
@ CAM_CMD_TIMEOUT
Definition: cam.h:167
@ CAM_UA_ABORT
Definition: cam.h:143
@ CAM_RESRC_UNAVAIL
Definition: cam.h:247
@ CAM_REQ_CMP_ERR
Definition: cam.h:146
@ CAM_STATUS_MASK
Definition: cam.h:302
@ CAM_REQ_ABORTED
Definition: cam.h:140
@ CAM_FUNC_NOTAVAIL
Definition: cam.h:265
@ CAM_LUN_ALRDY_ENA
Definition: cam.h:277
@ PIT_PROCESSOR
Definition: cam_ccb.h:608
#define XPT_FC_IS_QUEUED(ccb)
Definition: cam_ccb.h:273
xpt_opcode
Definition: cam_ccb.h:129
@ XPT_IMMED_NOTIFY
Definition: cam_ccb.h:245
@ XPT_DEBUG
Definition: cam_ccb.h:160
@ XPT_FC_QUEUED
Definition: cam_ccb.h:131
@ XPT_SCSI_IO
Definition: cam_ccb.h:141
@ XPT_ACCEPT_TARGET_IO
Definition: cam_ccb.h:241
@ XPT_REL_SIMQ
Definition: cam_ccb.h:149
@ XPT_IMMEDIATE_NOTIFY
Definition: cam_ccb.h:249
@ XPT_ABORT
Definition: cam_ccb.h:172
@ XPT_EN_LUN
Definition: cam_ccb.h:237
@ XPT_PATH_INQ
Definition: cam_ccb.h:147
@ XPT_DEV_MATCH
Definition: cam_ccb.h:158
@ XPT_CONT_TARGET_IO
Definition: cam_ccb.h:243
@ CAM_DEBUG_NONE
Definition: cam_debug.h:39
@ CAM_DEBUG_PERIPH
Definition: cam_debug.h:45
#define CAM_DEBUG(path, flag, printfargs)
Definition: cam_debug.h:93
#define CAM_DEBUG_PRINT(flag, printfargs)
Definition: cam_debug.h:115
struct cam_periph * cam_periph_find(struct cam_path *path, char *name)
Definition: cam_periph.c:340
void cam_periph_unmapmem(union ccb *ccb, struct cam_periph_map_info *mapinfo)
Definition: cam_periph.c:1005
int cam_periph_acquire(struct cam_periph *periph)
Definition: cam_periph.c:413
void cam_periph_release(struct cam_periph *periph)
Definition: cam_periph.c:465
void cam_periph_invalidate(struct cam_periph *periph)
Definition: cam_periph.c:655
int cam_periph_mapmem(union ccb *ccb, struct cam_periph_map_info *mapinfo, u_int maxmap)
Definition: cam_periph.c:793
cam_status cam_periph_alloc(periph_ctor_t *periph_ctor, periph_oninv_t *periph_oninvalidate, periph_dtor_t *periph_dtor, periph_start_t *periph_start, char *name, cam_periph_type type, struct cam_path *path, ac_callback_t *ac_callback, ac_code code, void *arg)
Definition: cam_periph.c:197
cam_status periph_ctor_t(struct cam_periph *periph, void *arg)
Definition: cam_periph.h:115
#define cam_periph_lock(periph)
Definition: cam_periph.h:224
#define cam_periph_unlock(periph)
Definition: cam_periph.h:227
void periph_dtor_t(struct cam_periph *periph)
Definition: cam_periph.h:118
void periph_start_t(struct cam_periph *periph, union ccb *start_ccb)
Definition: cam_periph.h:113
#define cam_periph_sleep(periph, chan, priority, wmesg, timo)
Definition: cam_periph.h:233
@ CAM_PERIPH_BIO
Definition: cam_periph.h:104
void() periph_init_t(void)
Definition: cam_periph.h:85
void xpt_schedule(struct cam_periph *periph, u_int32_t new_priority)
Definition: cam_xpt.c:3243
cam_status xpt_create_path(struct cam_path **new_path_ptr, struct cam_periph *perph, path_id_t path_id, target_id_t target_id, lun_id_t lun_id)
Definition: cam_xpt.c:3527
void xpt_print(struct cam_path *path, const char *fmt,...)
Definition: cam_xpt.c:3814
void xpt_setup_ccb(struct ccb_hdr *ccb_h, struct cam_path *path, u_int32_t priority)
Definition: cam_xpt.c:3520
void xpt_action(union ccb *start_ccb)
Definition: cam_xpt.c:2601
void xpt_free_path(struct cam_path *path)
Definition: cam_xpt.c:3672
void xpt_release_ccb(union ccb *free_ccb)
Definition: cam_xpt.c:3924
#define xpt_path_unlock(path)
Definition: cam_xpt.h:129
#define xpt_path_lock(path)
Definition: cam_xpt.h:128
static void xpt_path_inq(struct ccb_pathinq *cpi, struct cam_path *path)
Definition: cam_xpt.h:156
union ccb * ccb
Definition: mmc_sim_if.m:53
static int targreadfilt(struct knote *kn, long hint)
Definition: scsi_target.c:344
static void targasync(void *callback_arg, u_int32_t code, struct cam_path *path, void *arg)
Definition: scsi_target.c:1006
PERIPHDRIVER_DECLARE(targ, targdriver)
static periph_dtor_t targdtor
Definition: scsi_target.c:134
static d_kqfilter_t targkqfilter
Definition: scsi_target.c:107
targ_state
Definition: scsi_target.c:71
@ TARG_STATE_LUN_ENABLED
Definition: scsi_target.c:74
@ TARG_STATE_RESV
Definition: scsi_target.c:72
@ TARG_STATE_OPENED
Definition: scsi_target.c:73
static d_poll_t targpoll
Definition: scsi_target.c:106
TAILQ_HEAD(descr_queue, targ_cmd_descr)
static void targdone(struct cam_periph *periph, union ccb *done_ccb)
Definition: scsi_target.c:761
static void notify_user(struct targ_softc *softc)
Definition: scsi_target.c:1067
static int targusermerge(struct targ_softc *softc, struct targ_cmd_descr *descr, union ccb *ccb)
Definition: scsi_target.c:653
static union ccb * targgetccb(struct targ_softc *softc, xpt_opcode type, int priority)
Definition: scsi_target.c:931
static struct periph_driver targdriver
Definition: scsi_target.c:158
static int targcamstatus(cam_status status)
Definition: scsi_target.c:1080
static periph_init_t targinit
Definition: scsi_target.c:150
__FBSDID("$FreeBSD$")
static int targsendccb(struct targ_softc *softc, union ccb *ccb, struct targ_cmd_descr *descr)
Definition: scsi_target.c:710
static d_open_t targopen
Definition: scsi_target.c:102
static periph_start_t targstart
Definition: scsi_target.c:135
static struct cdevsw targ_cdevsw
Definition: scsi_target.c:116
static d_ioctl_t targioctl
Definition: scsi_target.c:105
static cam_status targenable(struct targ_softc *softc, struct cam_path *path, int grp6_len, int grp7_len)
Definition: scsi_target.c:383
static void targfreeccb(struct targ_softc *softc, union ccb *ccb)
Definition: scsi_target.c:954
static size_t targccblen(xpt_opcode func_code)
Definition: scsi_target.c:1117
static void abort_all_pending(struct targ_softc *softc)
Definition: scsi_target.c:1014
static void targcdevdtor(void *data)
Definition: scsi_target.c:169
static cam_status targdisable(struct targ_softc *softc)
Definition: scsi_target.c:457
static struct filterops targread_filtops
Definition: scsi_target.c:110
static MALLOC_DEFINE(M_TARG, "TARG", "TARG data")
static int targreturnccb(struct targ_softc *softc, union ccb *ccb)
Definition: scsi_target.c:899
static cam_status targendislun(struct cam_path *path, int enable, int grp6_len, int grp7_len)
Definition: scsi_target.c:359
static d_write_t targwrite
Definition: scsi_target.c:104
static d_read_t targread
Definition: scsi_target.c:103
static void targreadfiltdetach(struct knote *kn)
Definition: scsi_target.c:334
static periph_ctor_t targctor
Definition: scsi_target.c:133
static struct targ_cmd_descr * targgetdescr(struct targ_softc *softc)
Definition: scsi_target.c:983
#define TARGIOCDISABLE
Definition: scsi_targetio.h:70
#define TARGIOCENABLE
Definition: scsi_targetio.h:69
#define TARGIOCDEBUG
Definition: scsi_targetio.h:75
u_int32_t unit_number
Definition: cam_periph.h:127
void * softc
Definition: cam_periph.h:125
struct cam_path * path
Definition: cam_periph.h:124
u_int32_t flags
Definition: cam_periph.h:129
struct ccb_hdr ccb_h
Definition: cam_ccb.h:924
union ccb * abort_ccb
Definition: cam_ccb.h:925
struct ccb_hdr ccb_h
Definition: cam_ccb.h:1198
cam_debug_flags flags
Definition: cam_ccb.h:1199
u_int8_t enable
Definition: cam_ccb.h:1208
struct ccb_hdr ccb_h
Definition: cam_ccb.h:1205
u_int16_t grp7_len
Definition: cam_ccb.h:1207
u_int16_t grp6_len
Definition: cam_ccb.h:1206
u_int32_t flags
Definition: cam_ccb.h:368
struct cam_path * path
Definition: cam_ccb.h:364
xpt_opcode func_code
Definition: cam_ccb.h:362
u_int32_t timeout
Definition: cam_ccb.h:373
u_int32_t status
Definition: cam_ccb.h:363
camq_entry periph_links
Definition: cam_ccb.h:352
u_int16_t retry_count
Definition: cam_ccb.h:354
void(* cbfcnp)(struct cam_periph *, union ccb *)
Definition: cam_ccb.h:360
u_int16_t target_sprt
Definition: cam_ccb.h:664
struct ccb_hdr ccb_h
Definition: cam_ccb.h:661
u_int maxio
Definition: cam_ccb.h:691
target_id_t target_id
Definition: scsi_targetio.h:64
lun_id_t lun_id
Definition: scsi_targetio.h:65
path_id_t path_id
Definition: scsi_targetio.h:63
struct cam_periph_map_info mapinfo
Definition: scsi_target.c:59
struct descr_queue work_queue
Definition: scsi_target.c:83
u_int maxio
Definition: scsi_target.c:97
struct selinfo read_select
Definition: scsi_target.c:98
struct ccb_queue user_ccb_queue
Definition: scsi_target.c:92
struct cam_path * path
Definition: scsi_target.c:95
struct devstat device_stats
Definition: scsi_target.c:99
targ_state state
Definition: scsi_target.c:96
struct descr_queue abort_queue
Definition: scsi_target.c:86
struct ccb_queue pending_ccb_queue
Definition: scsi_target.c:80
struct cam_periph * periph
Definition: scsi_target.c:94
Definition: cam_ccb.h:1345
struct ccb_abort cab
Definition: cam_ccb.h:1360
struct ccb_hdr ccb_h
Definition: cam_ccb.h:1346