Lines Matching refs:ccb
74 int twe_cmd(struct twe_ccb *ccb, int flags, int wait);
75 int twe_start(struct twe_ccb *ccb, int wait);
76 int twe_complete(struct twe_ccb *ccb);
77 int twe_done(struct twe_softc *sc, struct twe_ccb *ccb);
86 struct twe_ccb *ccb; in twe_get_ccb() local
89 ccb = TAILQ_LAST(&sc->sc_free_ccb, twe_queue_head); in twe_get_ccb()
90 if (ccb != NULL) in twe_get_ccb()
91 TAILQ_REMOVE(&sc->sc_free_ccb, ccb, ccb_link); in twe_get_ccb()
94 return (ccb); in twe_get_ccb()
101 struct twe_ccb *ccb = xccb; in twe_put_ccb() local
103 ccb->ccb_state = TWE_CCB_FREE; in twe_put_ccb()
105 TAILQ_INSERT_TAIL(&sc->sc_free_ccb, ccb, ccb_link); in twe_put_ccb()
112 register struct twe_ccb *ccb; in twe_dispose() local
116 for (ccb = &sc->sc_ccbs[TWE_MAXCMDS - 1]; ccb >= sc->sc_ccbs; ccb--) in twe_dispose()
117 if (ccb->ccb_dmamap) in twe_dispose()
118 bus_dmamap_destroy(sc->dmat, ccb->ccb_dmamap); in twe_dispose()
134 struct twe_ccb *ccb; in twe_attach() local
190 ccb = &sc->sc_ccbs[cmd->cmd_index]; in twe_attach()
193 BUS_DMA_NOWAIT | BUS_DMA_ALLOCNOW, &ccb->ccb_dmamap); in twe_attach()
199 ccb->ccb_sc = sc; in twe_attach()
200 ccb->ccb_cmd = cmd; in twe_attach()
201 ccb->ccb_cmdpa = pa; in twe_attach()
202 ccb->ccb_state = TWE_CCB_FREE; in twe_attach()
203 TAILQ_INSERT_TAIL(&sc->sc_free_ccb, ccb, ccb_link); in twe_attach()
245 ccb = scsi_io_get(&sc->sc_iopool, 0); in twe_attach()
246 if (ccb == NULL) { in twe_attach()
251 ccb->ccb_xs = NULL; in twe_attach()
252 ccb->ccb_data = pb; in twe_attach()
253 ccb->ccb_length = TWE_SECTOR_SIZE; in twe_attach()
254 ccb->ccb_state = TWE_CCB_READY; in twe_attach()
255 cmd = ccb->ccb_cmd; in twe_attach()
264 error = twe_cmd(ccb, BUS_DMA_NOWAIT, 1); in twe_attach()
265 scsi_io_put(&sc->sc_iopool, ccb); in twe_attach()
316 ccb = scsi_io_get(&sc->sc_iopool, 0); in twe_attach()
317 if (ccb == NULL) { in twe_attach()
323 ccb->ccb_xs = NULL; in twe_attach()
324 ccb->ccb_data = pb; in twe_attach()
325 ccb->ccb_length = TWE_SECTOR_SIZE; in twe_attach()
326 ccb->ccb_state = TWE_CCB_READY; in twe_attach()
327 cmd = ccb->ccb_cmd; in twe_attach()
336 error = twe_cmd(ccb, BUS_DMA_NOWAIT, 1); in twe_attach()
337 scsi_io_put(&sc->sc_iopool, ccb); in twe_attach()
351 ccb = scsi_io_get(&sc->sc_iopool, 0); in twe_attach()
352 if (ccb == NULL) { in twe_attach()
358 ccb->ccb_xs = NULL; in twe_attach()
359 ccb->ccb_data = cap; in twe_attach()
360 ccb->ccb_length = TWE_SECTOR_SIZE; in twe_attach()
361 ccb->ccb_state = TWE_CCB_READY; in twe_attach()
362 cmd = ccb->ccb_cmd; in twe_attach()
372 error = twe_cmd(ccb, BUS_DMA_NOWAIT, 1); in twe_attach()
374 scsi_io_put(&sc->sc_iopool, ccb); in twe_attach()
445 struct twe_ccb *ccb; in twe_thread() local
454 ccb = TAILQ_FIRST(&sc->sc_done_ccb); in twe_thread()
455 TAILQ_REMOVE(&sc->sc_done_ccb, ccb, ccb_link); in twe_thread()
456 if ((err = twe_done(sc, ccb))) in twe_thread()
467 ccb = TAILQ_LAST(&sc->sc_ccb2q, twe_queue_head); in twe_thread()
468 TAILQ_REMOVE(&sc->sc_ccb2q, ccb, ccb_link); in twe_thread()
470 ccb->ccb_state = TWE_CCB_QUEUED; in twe_thread()
471 TAILQ_INSERT_TAIL(&sc->sc_ccbq, ccb, ccb_link); in twe_thread()
473 ccb->ccb_cmdpa); in twe_thread()
491 twe_cmd(struct twe_ccb *ccb, int flags, int wait) in twe_cmd() argument
493 struct twe_softc *sc = ccb->ccb_sc; in twe_cmd()
499 if (ccb->ccb_data && ((u_long)ccb->ccb_data & (TWE_ALIGN - 1))) { in twe_cmd()
500 TWE_DPRINTF(TWE_D_DMA, ("data=%p is unaligned ",ccb->ccb_data)); in twe_cmd()
501 ccb->ccb_realdata = ccb->ccb_data; in twe_cmd()
503 error = bus_dmamem_alloc(sc->dmat, ccb->ccb_length, PAGE_SIZE, in twe_cmd()
504 0, ccb->ccb_2bseg, TWE_MAXOFFSETS, &ccb->ccb_2nseg, in twe_cmd()
511 error = bus_dmamem_map(sc->dmat, ccb->ccb_2bseg, ccb->ccb_2nseg, in twe_cmd()
512 ccb->ccb_length, (caddr_t *)&ccb->ccb_data, BUS_DMA_NOWAIT); in twe_cmd()
515 bus_dmamem_free(sc->dmat, ccb->ccb_2bseg, ccb->ccb_2nseg); in twe_cmd()
518 bcopy(ccb->ccb_realdata, ccb->ccb_data, ccb->ccb_length); in twe_cmd()
520 ccb->ccb_realdata = NULL; in twe_cmd()
522 dmap = ccb->ccb_dmamap; in twe_cmd()
523 cmd = ccb->ccb_cmd; in twe_cmd()
526 if (ccb->ccb_data) { in twe_cmd()
527 error = bus_dmamap_load(sc->dmat, dmap, ccb->ccb_data, in twe_cmd()
528 ccb->ccb_length, NULL, flags); in twe_cmd()
535 if (ccb->ccb_realdata) { in twe_cmd()
536 bus_dmamem_unmap(sc->dmat, ccb->ccb_data, in twe_cmd()
537 ccb->ccb_length); in twe_cmd()
538 bus_dmamem_free(sc->dmat, ccb->ccb_2bseg, in twe_cmd()
539 ccb->ccb_2nseg); in twe_cmd()
560 TWE_DPRINTF(TWE_D_DMA, ("data=%p<", ccb->ccb_data)); in twe_cmd()
583 if ((error = twe_start(ccb, wait))) { in twe_cmd()
585 if (ccb->ccb_realdata) { in twe_cmd()
586 bus_dmamem_unmap(sc->dmat, ccb->ccb_data, in twe_cmd()
587 ccb->ccb_length); in twe_cmd()
588 bus_dmamem_free(sc->dmat, ccb->ccb_2bseg, in twe_cmd()
589 ccb->ccb_2nseg); in twe_cmd()
594 return wait? twe_complete(ccb) : 0; in twe_cmd()
598 twe_start(struct twe_ccb *ccb, int wait) in twe_start() argument
600 struct twe_softc*sc = ccb->ccb_sc; in twe_start()
601 struct twe_cmd *cmd = ccb->ccb_cmd; in twe_start()
610 ccb->ccb_state = TWE_CCB_PREQUEUED; in twe_start()
611 TAILQ_INSERT_TAIL(&sc->sc_ccb2q, ccb, ccb_link); in twe_start()
627 ccb->ccb_cmdpa); in twe_start()
630 ccb->ccb_state = TWE_CCB_QUEUED; in twe_start()
631 TAILQ_INSERT_TAIL(&sc->sc_ccbq, ccb, ccb_link); in twe_start()
644 twe_complete(struct twe_ccb *ccb) in twe_complete() argument
646 struct twe_softc *sc = ccb->ccb_sc; in twe_complete()
647 struct scsi_xfer *xs = ccb->ccb_xs; in twe_complete()
668 if (!twe_done(sc, ccb1) && ccb1 == ccb) { in twe_complete()
683 twe_done(struct twe_softc *sc, struct twe_ccb *ccb) in twe_done() argument
685 struct twe_cmd *cmd = ccb->ccb_cmd; in twe_done()
686 struct scsi_xfer *xs = ccb->ccb_xs; in twe_done()
692 if (ccb->ccb_state != TWE_CCB_DONE) { in twe_done()
698 dmap = ccb->ccb_dmamap; in twe_done()
727 if (ccb->ccb_realdata) { in twe_done()
728 bcopy(ccb->ccb_data, ccb->ccb_realdata, ccb->ccb_length); in twe_done()
729 bus_dmamem_unmap(sc->dmat, ccb->ccb_data, ccb->ccb_length); in twe_done()
730 bus_dmamem_free(sc->dmat, ccb->ccb_2bseg, ccb->ccb_2nseg); in twe_done()
749 struct twe_ccb *ccb = xs->io; in twe_scsi_cmd() local
871 ccb->ccb_xs = xs; in twe_scsi_cmd()
872 ccb->ccb_data = xs->data; in twe_scsi_cmd()
873 ccb->ccb_length = xs->datalen; in twe_scsi_cmd()
874 ccb->ccb_state = TWE_CCB_READY; in twe_scsi_cmd()
875 cmd = ccb->ccb_cmd; in twe_scsi_cmd()
885 if ((error = twe_cmd(ccb, ((xs->flags & SCSI_NOSLEEP)? in twe_scsi_cmd()
909 struct twe_ccb *ccb; in twe_intr() local
939 ccb = &sc->sc_ccbs[TWE_READYID(ready)]; in twe_intr()
940 TAILQ_REMOVE(&sc->sc_ccbq, ccb, ccb_link); in twe_intr()
941 ccb->ccb_state = TWE_CCB_DONE; in twe_intr()
942 TAILQ_INSERT_TAIL(&sc->sc_done_ccb, ccb, ccb_link); in twe_intr()
980 struct twe_ccb *ccb = io; in twe_aen() local
981 struct twe_cmd *cmd = ccb->ccb_cmd; in twe_aen()
991 ccb->ccb_xs = NULL; in twe_aen()
992 ccb->ccb_data = pb; in twe_aen()
993 ccb->ccb_length = TWE_SECTOR_SIZE; in twe_aen()
994 ccb->ccb_state = TWE_CCB_READY; in twe_aen()
1005 error = twe_cmd(ccb, BUS_DMA_NOWAIT, 1); in twe_aen()
1007 scsi_io_put(&sc->sc_iopool, ccb); in twe_aen()