Lines Matching defs:ccb
232 /* Make sure we clear CCB_SENDING before finishing a CCB. */
273 struct bha_ccb *ccb;
284 /* Get a CCB to use. */
285 ccb = bha_get_ccb(sc);
291 if (ccb == NULL) {
293 printf("unable to allocate ccb\n");
298 ccb->xs = xs;
299 ccb->timeout = xs->timeout;
302 * Put all the arguments for the xfer in the ccb
305 ccb->opcode = BHA_RESET_CCB;
306 ccb->scsi_cmd_length = 0;
309 if (xs->cmdlen > sizeof(ccb->scsi_cmd)) {
310 printf("%s: cmdlen %d too large for CCB\n",
315 ccb->opcode = (xs->datalen ? BHA_INIT_SCAT_GATH_CCB
317 memcpy(&ccb->scsi_cmd, xs->cmd,
318 ccb->scsi_cmd_length = xs->cmdlen);
328 ccb->dmamap_xfer, (struct uio *)xs->data,
337 ccb->dmamap_xfer, xs->data, xs->datalen,
359 bha_free_ccb(sc, ccb);
364 bus_dmamap_sync(dmat, ccb->dmamap_xfer, 0,
365 ccb->dmamap_xfer->dm_mapsize,
373 for (seg = 0; seg < ccb->dmamap_xfer->dm_nsegs; seg++) {
374 ltophys(ccb->dmamap_xfer->dm_segs[seg].ds_addr,
375 ccb->scat_gath[seg].seg_addr);
376 ltophys(ccb->dmamap_xfer->dm_segs[seg].ds_len,
377 ccb->scat_gath[seg].seg_len);
380 ltophys(ccb->hashkey + offsetof(struct bha_ccb,
381 scat_gath), ccb->data_addr);
382 ltophys(ccb->dmamap_xfer->dm_nsegs *
383 sizeof(struct bha_scat_gath), ccb->data_length);
388 ltophys(0, ccb->data_addr);
389 ltophys(0, ccb->data_length);
393 ccb->tag_enable = 1;
394 ccb->tag_type = xs->xs_tag_type & 0x03;
396 ccb->tag_enable = 0;
397 ccb->tag_type = 0;
400 ccb->data_out = 0;
401 ccb->data_in = 0;
402 ccb->target = periph->periph_target;
403 ccb->lun = periph->periph_lun;
404 ltophys(ccb->hashkey + offsetof(struct bha_ccb, scsi_sense),
405 ccb->sense_ptr);
406 ccb->req_sense_length = sizeof(ccb->scsi_sense);
407 ccb->host_stat = 0x00;
408 ccb->target_stat = 0x00;
409 ccb->link_id = 0;
410 ltophys(0, ccb->link_addr);
412 BHA_CCB_SYNC(sc, ccb, BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE);
415 bha_queue_ccb(sc, ccb);
425 if (bha_poll(sc, xs, ccb->timeout)) {
426 bha_timeout(ccb);
427 if (bha_poll(sc, xs, ccb->timeout))
428 bha_timeout(ccb);
581 * A CCB has completed execution. Pass the status back to the
585 bha_done(struct bha_softc *sc, struct bha_ccb *ccb)
588 struct scsipi_xfer *xs = ccb->xs;
593 if (ccb->flags & CCB_SENDING) {
594 printf("%s: exiting ccb still in transit!\n",
600 if ((ccb->flags & CCB_ALLOC) == 0) {
601 aprint_error_dev(sc->sc_dev, "exiting ccb not allocated!\n");
611 bus_dmamap_sync(dmat, ccb->dmamap_xfer, 0,
612 ccb
615 bus_dmamap_unload(dmat, ccb->dmamap_xfer);
619 if (ccb->host_stat != BHA_OK) {
620 switch (ccb->host_stat) {
626 device_xname(sc->sc_dev), ccb->host_stat);
630 } else if (ccb->target_stat != SCSI_OK) {
631 switch (ccb->target_stat) {
634 &ccb->scsi_sense,
643 device_xname(sc->sc_dev), ccb->target_stat);
651 bha_free_ccb(sc, ccb);
686 * CCB timeout handler.
691 struct bha_ccb *ccb = arg;
692 struct scsipi_xfer *xs = ccb->xs;
705 * If the ccb's mbx is not free, then the board has gone Far East?
708 if (ccb->flags & CCB_SENDING) {
719 if (ccb->flags & CCB_ABORT) {
726 ccb->xs->error = XS_TIMEOUT;
727 ccb->timeout = BHA_ABORT_TIMEOUT;
728 ccb->flags |= CCB_ABORT;
729 bha_queue_ccb(sc, ccb);
1214 * Determine the maximum CCB count and whether or not
1223 * The internal CCB counts are:
1256 * available. A mailbox isn't required while a CCB is executing,
1326 * Double the initial CCB count, for good measure.
1331 * Sanity check the initial CCB count; don't create more than
1402 * CCB execution engine
1408 * Queue a CCB to be sent to the controller, and send it if possible.
1411 bha_queue_ccb(struct bha_softc *sc, struct bha_ccb *ccb)
1414 TAILQ_INSERT_TAIL(&sc->sc_waiting_ccb, ccb, chain);
1430 struct bha_ccb *ccb;
1434 while ((ccb = TAILQ_FIRST(&sc->sc_waiting_ccb)) != NULL) {
1462 TAILQ_REMOVE(&sc->sc_waiting_ccb, ccb, chain);
1464 ccb->flags |= CCB_SENDING;
1468 * Put the CCB in the mailbox.
1470 bcg = BHA_CCB_GROUP(ccb);
1472 BHA_CCB_OFFSET(ccb), mbo->ccb_addr);
1473 if (ccb->flags & CCB_ABORT)
1484 if ((ccb->xs->xs_control & XS_CTL_POLL) == 0)
1485 callout_reset(&ccb->xs->xs_callout,
1486 mstohz(ccb->timeout), bha_timeout, ccb);
1504 struct bha_ccb *ccb;
1537 ccb = bha_ccb_phys_kv(sc, phystol(mbi->ccb_addr));
1538 if (ccb == NULL) {
1539 aprint_error_dev(sc->sc_dev, "bad mbi ccb pointer 0x%08x; skipping\n",
1544 BHA_CCB_SYNC(sc, ccb,
1549 u_char *cp = ccb->scsi_cmd;
1554 printf("ccb addr = %p\n", ccb);
1561 if ((ccb->flags & CCB_ABORT) != 0) {
1564 * to complete before clearing the CCB. We
1568 * the CCB a bit later than we need to. BFD.
1578 * Even if the CCB wasn't found, we clear it anyway.
1589 callout_stop(&ccb->xs->xs_callout);
1590 bha_done(sc, ccb);
1594 BHA_CCB_SYNC(sc, ccb,
1688 struct bha_ccb *ccb;
1700 ccb = bha_ccb_phys_kv(sc, phystol(mbo->ccb_addr));
1701 ccb->flags &= ~CCB_SENDING;
1712 * CCB management functions
1716 bha_reset_ccb(struct bha_ccb *ccb)
1719 ccb->flags = 0;
1727 * We determine the target CCB count, and then keep creating them
1738 struct bha_ccb *ccb;
1744 * If the current CCB count is already the max number we're
1760 * CCB group yet.
1770 "unable to allocate CCB group, error = %d\n", error);
1779 "unable to map CCB group, error = %d\n", error);
1789 "unable to create CCB group DMA map, error = %d\n", error);
1797 "unable to load CCB group DMA map, error = %d\n", error);
1806 panic("bha_create_ccbs: CCB group size botch");
1813 ccb = &bcg->bcg_ccbs[i];
1814 TAILQ_INSERT_TAIL(&sc->sc_allocating_ccbs, ccb, chain);
1819 * Loop over the allocating list until we reach our CCB target.
1824 ccb = TAILQ_FIRST(&sc->sc_allocating_ccbs);
1825 if (ccb == NULL)
1827 if (bha_init_ccb(sc, ccb) != 0) {
1829 * We were unable to initialize the CCB.
1855 * Initialize a CCB; helper function for bha_create_ccbs().
1858 bha_init_ccb(struct bha_softc *sc, struct bha_ccb *ccb)
1860 struct bha_ccb_group *bcg = BHA_CCB_GROUP(ccb);
1864 * Create the DMA map for this CCB.
1871 &ccb->dmamap_xfer);
1874 "unable to create CCB DMA map, error = %d\n", error);
1878 TAILQ_REMOVE(&sc->sc_allocating_ccbs, ccb, chain);
1881 * Put the CCB into the phystokv hash table.
1883 ccb->hashkey = bcg->bcg_dmamap->dm_segs[0].ds_addr +
1884 BHA_CCB_OFFSET(ccb);
1885 hashnum = CCB_HASH(ccb->hashkey);
1886 ccb->nexthash = sc->sc_ccbhash[hashnum];
1887 sc->sc_ccbhash[hashnum] = ccb;
1888 bha_reset_ccb(ccb);
1890 TAILQ_INSERT_HEAD(&sc->sc_free_ccb, ccb, chain);
1899 * Get a CCB for the SCSI operation. If there are none left,
1905 struct bha_ccb *ccb;
1909 ccb = TAILQ_FIRST(&sc->sc_free_ccb);
1910 if (ccb != NULL) {
1911 TAILQ_REMOVE(&sc->sc_free_ccb, ccb, chain);
1912 ccb->flags |= CCB_ALLOC;
1915 return (ccb);
1921 * Put a CCB back onto the free list.
1924 bha_free_ccb(struct bha_softc *sc, struct bha_ccb *ccb)
1929 bha_reset_ccb(ccb);
1930 TAILQ_INSERT_HEAD(&sc->sc_free_ccb, ccb, chain);
1937 * Given a CCB DMA address, locate the CCB in kernel virtual space.
1943 struct bha_ccb *ccb = sc->sc_ccbhash[hashnum];
1945 while (ccb) {
1946 if (ccb->hashkey == ccb_phys)
1948 ccb = ccb->nexthash;
1950 return (ccb);