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