Lines Matching refs:ecb

276 ahb_send_mbox(struct ahb_softc *sc, int opcode, struct ahb_ecb *ecb)
298 sc->sc_dmamap_ecb->dm_segs[0].ds_addr + AHB_ECB_OFF(ecb));
300 ecb->xs->xs_periph->periph_target);
302 if ((ecb->xs->xs_control & XS_CTL_POLL) == 0)
303 callout_reset(&ecb->xs->xs_callout,
304 mstohz(ecb->timeout), ahb_timeout, ecb);
311 ahb_send_immed(struct ahb_softc *sc, u_int32_t cmd, struct ahb_ecb *ecb)
331 ecb->xs->xs_periph->periph_target);
333 if ((ecb->xs->xs_control & XS_CTL_POLL) == 0)
334 callout_reset(&ecb->xs->xs_callout,
335 mstohz(ecb->timeout), ahb_timeout, ecb);
347 struct ahb_ecb *ecb;
378 ecb = ahb_ecb_phys_kv(sc, mboxval);
379 if (!ecb) {
386 ecb = sc->sc_immed_ecb;
388 ecb->flags |= ECB_IMMED_FAIL;
392 ecb = sc->sc_immed_ecb;
402 callout_stop(&ecb->xs->xs_callout);
403 ahb_done(sc, ecb);
412 ahb_reset_ecb(struct ahb_softc *sc, struct ahb_ecb *ecb)
415 ecb->flags = 0;
419 * A ecb (and hence a mbx-out is put onto the
423 ahb_free_ecb(struct ahb_softc *sc, struct ahb_ecb *ecb)
428 ahb_reset_ecb(sc, ecb);
429 TAILQ_INSERT_HEAD(&sc->sc_free_ecb, ecb, chain);
437 ahb_init_ecb(struct ahb_softc *sc, struct ahb_ecb *ecb)
446 0, BUS_DMA_NOWAIT|BUS_DMA_ALLOCNOW, &ecb->dmamap_xfer);
448 aprint_error_dev(&sc->sc_dev, "can't create ecb dmamap_xfer\n");
456 ecb->hashkey = sc->sc_dmamap_ecb->dm_segs[0].ds_addr +
457 AHB_ECB_OFF(ecb);
458 hashnum = ECB_HASH(ecb->hashkey);
459 ecb->nexthash = sc->sc_ecbhash[hashnum];
460 sc->sc_ecbhash[hashnum] = ecb;
461 ahb_reset_ecb(sc, ecb);
468 struct ahb_ecb *ecb;
473 ecb = &ecbstore[i];
474 if ((error = ahb_init_ecb(sc, ecb)) != 0) {
475 aprint_error_dev(&sc->sc_dev, "unable to initialize ecb, error = %d\n",
479 TAILQ_INSERT_TAIL(&sc->sc_free_ecb, ecb, chain);
486 * Get a free ecb
494 struct ahb_ecb *ecb;
498 ecb = TAILQ_FIRST(&sc->sc_free_ecb);
499 if (ecb != NULL) {
500 TAILQ_REMOVE(&sc->sc_free_ecb, ecb, chain);
501 ecb->flags |= ECB_ALLOC;
504 return (ecb);
508 * given a physical address, find the ecb that it corresponds to.
514 struct ahb_ecb *ecb = sc->sc_ecbhash[hashnum];
516 while (ecb) {
517 if (ecb->hashkey == ecb_phys)
519 ecb = ecb->nexthash;
521 return ecb;
525 * We have a ecb which has been processed by the adaptor, now we look to see
529 ahb_done(struct ahb_softc *sc, struct ahb_ecb *ecb)
533 struct scsipi_xfer *xs = ecb->xs;
538 AHB_ECB_OFF(ecb), sizeof(struct ahb_ecb),
546 bus_dmamap_sync(dmat, ecb->dmamap_xfer, 0,
547 ecb->dmamap_xfer->dm_mapsize,
550 bus_dmamap_unload(dmat, ecb->dmamap_xfer);
557 if ((ecb->flags & ECB_ALLOC) == 0) {
558 aprint_error_dev(&sc->sc_dev, "exiting ecb not allocated!\n");
561 if (ecb->flags & ECB_IMMED) {
562 if (ecb->flags & ECB_IMMED_FAIL)
567 if (ecb->ecb_status.host_stat != HS_OK) {
568 switch (ecb->ecb_status.host_stat) {
574 device_xname(&sc->sc_dev), ecb->ecb_status.host_stat);
577 } else if (ecb->ecb_status.target_stat != SCSI_OK) {
578 switch (ecb->ecb_status.target_stat) {
580 s1 = &ecb->ecb_sense;
590 device_xname(&sc->sc_dev), ecb->ecb_status.target_stat);
597 ahb_free_ecb(sc, ecb);
722 aprint_error_dev(&sc->sc_dev, "unable to create ecb DMA map, error = %d\n",
728 aprint_error_dev(&sc->sc_dev, "unable to load ecb DMA map, error = %d\n",
773 struct ahb_ecb *ecb;
785 ecb = ahb_get_ecb(sc);
791 if (ecb == NULL) {
793 printf("unable to allocate ecb\n");
798 ecb->xs = xs;
799 ecb->timeout = xs->timeout;
803 * command, and store its ecb for later
808 ecb->flags |= ECB_IMMED;
810 ahb_free_ecb(sc, ecb);
815 sc->sc_immed_ecb = ecb;
818 ahb_send_immed(sc, AHB_TARG_RESET, ecb);
827 if (ahb_poll(sc, xs, ecb->timeout))
828 ahb_timeout(ecb);
833 * Put all the arguments for the xfer in the ecb
835 if (xs->cmdlen > sizeof(ecb->scsi_cmd)) {
841 ecb->opcode = ECB_SCSI_OP;
842 ecb->opt1 = ECB_SES /*| ECB_DSB*/ | ECB_ARS;
843 ecb->opt2 = periph->periph_lun | ECB_NRB;
844 memcpy(&ecb->scsi_cmd, xs->cmd,
845 ecb->scsi_cmd_length = xs->cmdlen);
846 ecb->sense_ptr = sc->sc_dmamap_ecb->dm_segs[0].ds_addr +
847 AHB_ECB_OFF(ecb) + offsetof(struct ahb_ecb, ecb_sense);
848 ecb->req_sense_length = sizeof(ecb->ecb_sense);
849 ecb->status = sc->sc_dmamap_ecb->dm_segs[0].ds_addr +
850 AHB_ECB_OFF(ecb) + offsetof(struct ahb_ecb, ecb_status);
851 ecb->ecb_status.host_stat = 0x00;
852 ecb->ecb_status.target_stat = 0x00;
861 ecb->dmamap_xfer, (struct uio *)xs->data,
867 ecb->dmamap_xfer, xs->data, xs->datalen,
885 ahb_free_ecb(sc, ecb);
890 bus_dmamap_sync(dmat, ecb->dmamap_xfer, 0,
891 ecb->dmamap_xfer->dm_mapsize,
899 for (seg = 0; seg < ecb->dmamap_xfer->dm_nsegs; seg++) {
900 ecb->ahb_dma[seg].seg_addr =
901 ecb->dmamap_xfer->dm_segs[seg].ds_addr;
902 ecb->ahb_dma[seg].seg_len =
903 ecb->dmamap_xfer->dm_segs[seg].ds_len;
906 ecb->data_addr = sc->sc_dmamap_ecb->dm_segs[0].ds_addr +
907 AHB_ECB_OFF(ecb) +
909 ecb->data_length = ecb->dmamap_xfer->dm_nsegs *
911 ecb->opt1 |= ECB_S_G;
913 ecb->data_addr = (physaddr)0;
914 ecb->data_length = 0;
916 ecb->link_addr = (physaddr)0;
919 AHB_ECB_OFF(ecb), sizeof(struct ahb_ecb),
923 ahb_send_mbox(sc, OP_START_ECB, ecb);
932 if (ahb_poll(sc, xs, ecb->timeout)) {
933 ahb_timeout(ecb);
934 if (ahb_poll(sc, xs, ecb->timeout))
935 ahb_timeout(ecb);
976 struct ahb_ecb *ecb = arg;
977 struct scsipi_xfer *xs = ecb->xs;
988 if (ecb->flags & ECB_IMMED) {
990 ecb->flags |= ECB_IMMED_FAIL;
999 if (ecb->flags & ECB_ABORT) {
1006 ecb->xs->error = XS_TIMEOUT;
1007 ecb->timeout = AHB_ABORT_TIMEOUT;
1008 ecb->flags |= ECB_ABORT;
1009 ahb_send_mbox(sc, OP_ABORT_ECB, ecb);