sc->sc_dev.dv_xname, target);
sc->sc_c.sc_dev.dv_xname, target);
siop_scsicmd(xs)	struct scsi_xfer *xs;{	struct siop_softc *sc = (struct siop_softc *)xs->sc_link->adapter_softc;	struct siop_cmd *siop_cmd;	int s, error, i, j;	const int target = xs->sc_link->target;	const int lun = xs->sc_link->lun;	s = splbio();#ifdef SIOP_DEBUG_SCHED	printf("starting cmd 0x%02x for %d:%d\n", xs->cmd->opcode, target, lun);#endif	siop_cmd = TAILQ_FIRST(&sc->free_list);	if (siop_cmd != NULL) {		TAILQ_REMOVE(&sc->free_list, siop_cmd, next);	} else {		xs->error = XS_DRIVER_STUFFUP;		splx(s);		return(TRY_AGAIN_LATER);	}	/* Always reset xs->stimeout, lest we timeout_del() with trash */	timeout_set(&xs->stimeout, siop_timeout, siop_cmd);#ifdef DIAGNOSTIC	if (siop_cmd->status != CMDST_FREE)		panic("siop_scsicmd: new cmd not free");#endif	if (sc->targets[target] == NULL) {#ifdef SIOP_DEBUG		printf("%s: alloc siop_target for target %d\n",			sc->sc_dev.dv_xname, target);#endif		sc->targets[target] =		    malloc(sizeof(struct siop_target), M_DEVBUF, M_NOWAIT);		if (sc->targets[target] == NULL) {			printf("%s: can't malloc memory for target %d\n",			    sc->sc_dev.dv_xname, target);			xs->error = XS_DRIVER_STUFFUP;			splx(s);			return(TRY_AGAIN_LATER);		}		sc->targets[target]->status = TARST_PROBING;		sc->targets[target]->flags  = 0;		sc->targets[target]->id = sc->clock_div << 24; /* scntl3 */		sc->targets[target]->id |=  target << 16; /* id */		/* sc->targets[target]->id |= 0x0 << 8; scxfer is 0 */		/* get a lun switch script */		sc->targets[target]->lunsw = siop_get_lunsw(sc);		if (sc->targets[target]->lunsw == NULL) {			printf("%s: can't alloc lunsw for target %d\n",			    sc->sc_dev.dv_xname, target);			xs->error = XS_DRIVER_STUFFUP;			splx(s);			return(TRY_AGAIN_LATER);		}		for (i=0; i < 8; i++)			sc->targets[target]->siop_lun[i] = NULL;		siop_add_reselsw(sc, target);	}	if (sc->targets[target]->siop_lun[lun] == NULL) {		sc->targets[target]->siop_lun[lun] =		    malloc(sizeof(struct siop_lun), M_DEVBUF, M_NOWAIT);		if (sc->targets[target]->siop_lun[lun] == NULL) {			printf("%s: can't alloc siop_lun for target %d "			    "lun %d\n", sc->sc_dev.dv_xname, target, lun);			xs->error = XS_DRIVER_STUFFUP;			splx(s);			return(TRY_AGAIN_LATER);		}		memset(sc->targets[target]->siop_lun[lun], 0,		    sizeof(struct siop_lun));	}	siop_cmd->siop_target = sc->targets[target];	siop_cmd->xs = xs;	siop_cmd->flags = 0;	siop_cmd->status = CMDST_READY;	/* load the DMA maps */	error = bus_dmamap_load(sc->sc_dmat, siop_cmd->dmamap_cmd,	    xs->cmd, xs->cmdlen, NULL, BUS_DMA_NOWAIT);	if (error) {		printf("%s: unable to load cmd DMA map: %d\n",		    sc->sc_dev.dv_xname, error);		xs->error = XS_DRIVER_STUFFUP;		splx(s);		return(TRY_AGAIN_LATER);	}	if (xs->flags & (SCSI_DATA_IN | SCSI_DATA_OUT)) {		error = bus_dmamap_load(sc->sc_dmat, siop_cmd->dmamap_data,		    xs->data, xs->datalen, NULL, BUS_DMA_NOWAIT);		if (error) {			printf("%s: unable to load cmd DMA map: %d\n",			    sc->sc_dev.dv_xname, error);			xs->error = XS_DRIVER_STUFFUP;			bus_dmamap_unload(sc->sc_dmat, siop_cmd->dmamap_cmd);			splx(s);			return(TRY_AGAIN_LATER);		}		bus_dmamap_sync(sc->sc_dmat, siop_cmd->dmamap_data,		    0, siop_cmd->dmamap_data->dm_mapsize,		    (xs->flags & SCSI_DATA_IN) ?		    BUS_DMASYNC_PREREAD : BUS_DMASYNC_PREWRITE);	}	bus_dmamap_sync(sc->sc_dmat, siop_cmd->dmamap_cmd,	    0, siop_cmd->dmamap_cmd->dm_mapsize,	    BUS_DMASYNC_PREWRITE);	siop_setuptables(siop_cmd);	TAILQ_INSERT_TAIL(&sc->ready_list, siop_cmd, next);	siop_start(sc);	if (xs->flags & SCSI_POLL) {		/* poll for command completion */		for(i = xs->timeout; i > 0; i--) {			siop_intr(sc);			if (xs->flags & ITSDONE) {				if ((xs->cmd->opcode == INQUIRY)				    && (xs->error == XS_NOERROR)) {					error = ((struct scsi_inquiry_data *)xs->data)->device & SID_QUAL;					if (error != SID_QUAL_BAD_LU) {						/* 						 * Allocate enough commands to hold at least max openings						 * worth of commands. Do this statically now because 						 * a) We can't rely on the upper layers to ask for more						 * b) Doing it dynamically in siop_startcmd may cause 						 *    calls to bus_dma* functions in interrupt context						 */						for (j = 0; j < SIOP_NTAG; j += SIOP_NCMDPB)							siop_morecbd(sc);						if (sc->targets[target]->status == TARST_PROBING)							sc->targets[target]->status = TARST_ASYNC;						/* Can't do lun 0 here, because flags not set yet */						if (lun > 0)							siop_add_dev(sc, target, lun);					}				}				break;			}			delay(1000);		}		splx(s);		if (i == 0) {			siop_timeout(siop_cmd);			while ((xs->flags & ITSDONE) == 0) {				s = splbio();				siop_intr(sc);				splx(s);			}		}		return (COMPLETE);	}	splx(s);	return (SUCCESSFULLY_QUEUED);}