Lines Matching defs:softc

70 	TARG_STATE_OPENED	= 0x01, /* Device opened, softc initialized */
126 static cam_status targenable(struct targ_softc *softc,
129 static cam_status targdisable(struct targ_softc *softc);
133 static int targusermerge(struct targ_softc *softc,
136 static int targsendccb(struct targ_softc *softc, union ccb *ccb,
140 static int targreturnccb(struct targ_softc *softc,
142 static union ccb * targgetccb(struct targ_softc *softc, xpt_opcode type,
144 static void targfreeccb(struct targ_softc *softc, union ccb *ccb);
146 targgetdescr(struct targ_softc *softc);
150 static void abort_all_pending(struct targ_softc *softc);
151 static void notify_user(struct targ_softc *softc);
164 /* Disable LUN if enabled and teardown softc */
168 struct targ_softc *softc;
171 softc = data;
172 if (softc->periph == NULL) {
174 free(softc, M_TARG);
182 periph = softc->periph;
185 (void)targdisable(softc);
186 if (softc->periph != NULL) {
187 cam_periph_invalidate(softc->periph);
188 softc->periph = NULL;
192 free(softc, M_TARG);
196 * Create softc and initialize it. There is no locking here because a
203 struct targ_softc *softc;
205 /* Allocate its softc, initialize it */
206 softc = malloc(sizeof(*softc), M_TARG,
208 softc->state = TARG_STATE_OPENED;
209 softc->periph = NULL;
210 softc->path = NULL;
212 TAILQ_INIT(&softc->pending_ccb_queue);
213 TAILQ_INIT(&softc->work_queue);
214 TAILQ_INIT(&softc->abort_queue);
215 TAILQ_INIT(&softc->user_ccb_queue);
216 knlist_init_mtx(&softc->read_select.si_note, NULL);
218 devfs_set_cdevpriv(softc, targcdevdtor);
226 struct targ_softc *softc;
229 devfs_get_cdevpriv((void **)&softc);
247 status = targenable(softc, path, new_lun->grp6_len,
254 if (softc->periph == NULL) {
258 cam_periph_lock(softc->periph);
259 status = targdisable(softc);
260 cam_periph_unlock(softc->periph);
267 if ((softc->state & TARG_STATE_LUN_ENABLED) == 0) {
276 xpt_setup_ccb(&cdbg.ccb_h, softc->path, CAM_PRIORITY_NORMAL);
295 struct targ_softc *softc;
298 devfs_get_cdevpriv((void **)&softc);
304 cam_periph_lock(softc->periph);
305 if (!TAILQ_EMPTY(&softc->user_ccb_queue) ||
306 !TAILQ_EMPTY(&softc->abort_queue)) {
309 cam_periph_unlock(softc->periph);
312 selrecord(td, &softc->read_select);
321 struct targ_softc *softc;
323 devfs_get_cdevpriv((void **)&softc);
324 kn->kn_hook = (caddr_t)softc;
326 knlist_add(&softc->read_select.si_note, kn, 0);
333 struct targ_softc *softc;
335 softc = (struct targ_softc *)kn->kn_hook;
336 knlist_remove(&softc->read_select.si_note, kn, 0);
343 struct targ_softc *softc;
346 softc = (struct targ_softc *)kn->kn_hook;
347 cam_periph_lock(softc->periph);
348 retval = !TAILQ_EMPTY(&softc->user_ccb_queue) ||
349 !TAILQ_EMPTY(&softc->abort_queue);
350 cam_periph_unlock(softc->periph);
380 targenable(struct targ_softc *softc, struct cam_path *path, int grp6_len,
387 if ((softc->state & TARG_STATE_LUN_ENABLED) != 0)
403 softc->maxio = DFLTPHYS; /* traditional default */
405 softc->maxio = maxphys; /* for safety */
407 softc->maxio = cpi.maxio; /* real value */
414 del_softc = (struct targ_softc *)periph->softc;
428 "targ", CAM_PERIPH_BIO, path, targasync, 0, softc);
446 softc->state |= TARG_STATE_LUN_ENABLED;
452 /* Disable this softc's target instance if enabled */
454 targdisable(struct targ_softc *softc)
458 if ((softc->state & TARG_STATE_LUN_ENABLED) == 0)
461 CAM_DEBUG(softc->path, CAM_DEBUG_PERIPH, ("targdisable\n"));
464 abort_all_pending(softc);
467 status = targendislun(softc->path, /*enable*/0,
470 softc->state &= ~TARG_STATE_LUN_ENABLED;
481 struct targ_softc *softc;
483 /* Store pointer to softc for periph-driven routines */
484 softc = (struct targ_softc *)arg;
485 periph->softc = softc;
486 softc->periph = periph;
487 softc->path = periph->path;
494 struct targ_softc *softc;
498 softc = (struct targ_softc *)periph->softc;
505 while ((ccb_h = TAILQ_FIRST(&softc->user_ccb_queue)) != NULL) {
506 TAILQ_REMOVE(&softc->user_ccb_queue, ccb_h, periph_links.tqe);
507 targfreeccb(softc, (union ccb *)ccb_h);
509 while ((descr = TAILQ_FIRST(&softc->abort_queue)) != NULL) {
510 TAILQ_REMOVE(&softc->abort_queue, descr, tqe);
514 softc->periph = NULL;
515 softc->path = NULL;
516 periph->softc = NULL;
524 struct targ_softc *softc;
529 devfs_get_cdevpriv((void **)&softc);
531 CAM_DEBUG(softc->path, CAM_DEBUG_PERIPH,
538 CAM_DEBUG(softc->path, CAM_DEBUG_PERIPH,
552 cam_periph_lock(softc->periph);
553 ccb = targgetccb(softc, func_code, priority);
557 CAM_DEBUG(softc->path, CAM_DEBUG_PERIPH,
560 TAILQ_INSERT_TAIL(&softc->pending_ccb_queue,
563 cam_periph_unlock(softc->periph);
566 cam_periph_lock(softc->periph);
568 CAM_DEBUG(softc->path, CAM_DEBUG_PERIPH,
571 descr = targgetdescr(softc);
575 TAILQ_INSERT_TAIL(&softc->work_queue,
577 xpt_schedule(softc->periph, priority);
579 CAM_DEBUG(softc->path, CAM_DEBUG_PERIPH,
582 ccb = targgetccb(softc, func_code, priority);
588 if (targusermerge(softc, descr, ccb) != EFAULT)
589 targsendccb(softc, ccb, descr);
590 targreturnccb(softc, ccb);
592 cam_periph_unlock(softc->periph);
615 struct targ_softc *softc;
619 softc = (struct targ_softc *)periph->softc;
620 CAM_DEBUG(softc->path, CAM_DEBUG_PERIPH, ("targstart %p\n", start_ccb));
622 descr = TAILQ_FIRST(&softc->work_queue);
626 TAILQ_REMOVE(&softc->work_queue, descr, tqe);
627 next_descr = TAILQ_FIRST(&softc->work_queue);
630 error = targusermerge(softc, descr, start_ccb);
632 error = targsendccb(softc, start_ccb, descr);
639 TAILQ_INSERT_TAIL(&softc->abort_queue, descr, tqe);
640 notify_user(softc);
650 targusermerge(struct targ_softc *softc, struct targ_cmd_descr *descr,
664 xpt_setup_ccb(k_ccbh, softc->path, descr->priority);
682 TAILQ_FOREACH(ccb_h, &softc->pending_ccb_queue,
688 CAM_DEBUG(softc->path, CAM_DEBUG_PERIPH,
707 targsendccb(struct targ_softc *softc, union ccb *ccb,
729 error = cam_periph_mapmem(ccb, mapinfo, softc->maxio);
746 CAM_DEBUG(softc->path, CAM_DEBUG_PERIPH, ("sendccb %p\n", ccb));
748 TAILQ_INSERT_TAIL(&softc->pending_ccb_queue, ccb_h,
760 struct targ_softc *softc;
763 softc = (struct targ_softc *)periph->softc;
764 TAILQ_REMOVE(&softc->pending_ccb_queue, &done_ccb->ccb_h,
768 if ((softc->state & TARG_STATE_LUN_ENABLED) == 0) {
769 targfreeccb(softc, done_ccb);
773 if (TAILQ_EMPTY(&softc->pending_ccb_queue))
774 wakeup(&softc->pending_ccb_queue);
782 TAILQ_INSERT_TAIL(&softc->user_ccb_queue, &done_ccb->ccb_h,
784 cam_periph_unlock(softc->periph);
785 notify_user(softc);
786 cam_periph_lock(softc->periph);
801 struct targ_softc *softc;
809 devfs_get_cdevpriv((void **)&softc);
810 user_queue = &softc->user_ccb_queue;
811 abort_queue = &softc->abort_queue;
812 CAM_DEBUG(softc->path, CAM_DEBUG_PERIPH, ("targread\n"));
815 cam_periph_lock(softc->periph);
820 error = cam_periph_sleep(softc->periph, user_queue,
832 cam_periph_unlock(softc->periph);
846 CAM_DEBUG(softc->path, CAM_DEBUG_PERIPH,
848 error = targreturnccb(softc, (union ccb *)ccb_h);
851 cam_periph_unlock(softc->periph);
853 cam_periph_lock(softc->periph);
867 CAM_DEBUG(softc->path, CAM_DEBUG_PERIPH,
874 cam_periph_unlock(softc->periph);
876 cam_periph_lock(softc->periph);
893 cam_periph_unlock(softc->periph);
899 targreturnccb(struct targ_softc *softc, union ccb *ccb)
906 CAM_DEBUG(softc->path, CAM_DEBUG_PERIPH, ("targreturnccb %p\n", ccb));
915 xpt_print(softc->path,
931 xpt_print(softc->path,
936 targfreeccb(softc, ccb);
942 targgetccb(struct targ_softc *softc, xpt_opcode type, int priority)
949 CAM_DEBUG(softc->path, CAM_DEBUG_PERIPH, ("getccb %p\n", ccb));
953 xpt_setup_ccb(&ccb->ccb_h, softc->path, priority);
956 ccb->ccb_h.targ_descr = targgetdescr(softc);
965 targfreeccb(struct targ_softc *softc, union ccb *ccb)
994 targgetdescr(struct targ_softc *softc)
1025 abort_all_pending(struct targ_softc *softc)
1031 CAM_DEBUG(softc->path, CAM_DEBUG_PERIPH, ("abort_all_pending\n"));
1034 while ((descr = TAILQ_FIRST(&softc->work_queue)) != NULL) {
1035 CAM_DEBUG(softc->path, CAM_DEBUG_PERIPH,
1037 TAILQ_REMOVE(&softc->work_queue, descr, tqe);
1038 TAILQ_INSERT_TAIL(&softc->abort_queue, descr, tqe);
1046 xpt_setup_ccb(&cab.ccb_h, softc->path, CAM_PRIORITY_NORMAL);
1049 TAILQ_FOREACH(ccb_h, &softc->pending_ccb_queue, periph_links.tqe) {
1050 CAM_DEBUG(softc->path, CAM_DEBUG_PERIPH,
1063 cam_periph_sleep(softc->periph, &softc->pending_ccb_queue,
1068 if (!TAILQ_EMPTY(&softc->user_ccb_queue)
1069 || !TAILQ_EMPTY(&softc->abort_queue)) {
1070 cam_periph_unlock(softc->periph);
1071 notify_user(softc);
1072 cam_periph_lock(softc->periph);
1078 notify_user(struct targ_softc *softc)
1084 selwakeuppri(&softc->read_select, PRIBIO);
1085 KNOTE_UNLOCKED(&softc->read_select.si_note, 0);
1086 wakeup(&softc->user_ccb_queue);