i = 0; maxtarget = 16; if (target != CAM_TARGET_WILDCARD) { i = target; if (channel == 'B') i += 8; maxtarget = i + 1; }  if (lun == CAM_LUN_WILDCARD) {   minlun = 0; maxlun = 1; if ((ahc->flags & AHC_SCB_BTT) != 0) maxlun = AHC_NUM_LUNS; } else { minlun = lun; maxlun = lun + 1; }  for (;i < maxtarget; i++) { for (j = minlun;j < maxlun; j++) ahc_unbusy_tcl(ahc, BUILD_TCL(i << 4, j)); }
{ u_int8_t next, prev;  next = ahc_inb(ahc, WAITING_SCBH); prev = SCB_LIST_NULL;  while (next != SCB_LIST_NULL) { u_int8_t scb_index;  ahc_outb(ahc, SCBPTR, next); scb_index = ahc_inb(ahc, SCB_TAG); if (scb_index >= ahc->scb_data->numscbs) { panic("Waiting List inconsistency. " "SCB index == %d, yet numscbs == %d.", scb_index, ahc->scb_data->numscbs); } scbp = &ahc->scb_data->scbarray[scb_index]; if (ahc_match_scb(scbp, target, channel, lun, SCB_LIST_NULL, role)) {  next = ahc_abort_wscb(ahc, next, prev); } else {  prev = next; next = ahc_inb(ahc, SCB_NEXT); } } }
ahc_abort_scbs(struct ahc_softc *ahc, int target, char channel,	       int lun, u_int tag, role_t role, uint32_t status){	struct	scb *scbp;	struct	scb *scbp_next;	u_int	active_scb;	int	i, j;	int	maxtarget;	int	minlun;	int	maxlun;	int	found;	/*	 * Don't attempt to run any queued untagged transactions	 * until we are done with the abort process.	 */	ahc_freeze_untagged_queues(ahc);	/* restore this when we're done */	active_scb = ahc_inb(ahc, SCBPTR);	found = ahc_search_qinfifo(ahc, target, channel, lun, SCB_LIST_NULL,				   role, CAM_REQUEUE_REQ, SEARCH_COMPLETE);	/*	 * Clean out the busy target table for any untagged commands.	 */	i = 0;	maxtarget = 16;	if (target != CAM_TARGET_WILDCARD) {		i = target;		if (channel == 'B')			i += 8;		maxtarget = i + 1;	}	if (lun == CAM_LUN_WILDCARD) {		/*		 * Unless we are using an SCB based		 * busy targets table, there is only		 * one table entry for all luns of		 * a target.		 */		minlun = 0;		maxlun = 1;		if ((ahc->flags & AHC_SCB_BTT) != 0)			maxlun = AHC_NUM_LUNS;	} else {		minlun = lun;		maxlun = lun + 1;	}	for (;i < maxtarget; i++) {		for (j = minlun;j < maxlun; j++)			ahc_unbusy_tcl(ahc, BUILD_TCL(i << 4, j));	}	/*	 * Go through the disconnected list and remove any entries we	 * have queued for completion, 0'ing their control byte too.	 * We save the active SCB and restore it ourselves, so there	 * is no reason for this search to restore it too.	 */	ahc_search_disc_list(ahc, target, channel, lun, tag,			     /*stop_on_first*/FALSE, /*remove*/TRUE,			     /*save_state*/FALSE);	/*	 * Go through the hardware SCB array looking for commands that	 * were active but not on any list.	 */	for (i = 0; i < ahc->scb_data->maxhscbs; i++) {		u_int scbid;		ahc_outb(ahc, SCBPTR, i);		scbid = ahc_inb(ahc, SCB_TAG);		scbp = ahc_lookup_scb(ahc, scbid);		if (scbp != NULL		 && ahc_match_scb(ahc, scbp, target, channel, lun, tag, role))			ahc_add_curscb_to_free_list(ahc);	}	/*	 * Go through the pending CCB list and look for	 * commands for this target that are still active.	 * These are other tagged commands that were	 * disconnected when the reset occurred.	 */	scbp_next = LIST_FIRST(&ahc->pending_scbs);	while (scbp_next != NULL) {		scbp = scbp_next;		scbp_next = LIST_NEXT(scbp, pending_links);		if (ahc_match_scb(ahc, scbp, target, channel, lun, tag, role)) {			cam_status ostat;			ostat = ahc_get_transaction_status(scbp);			if (ostat == CAM_REQ_INPROG)				ahc_set_transaction_status(scbp, status);			if (ahc_get_transaction_status(scbp) != CAM_REQ_CMP)				ahc_freeze_scb(scbp);			if ((scbp->flags & SCB_ACTIVE) == 0)				printf("Inactive SCB on pending list\n");			ahc_done(ahc, scbp);			found++;		}	}	ahc_outb(ahc, SCBPTR, active_scb);	ahc_platform_abort_scbs(ahc, target, channel, lun, tag, role, status);	ahc_release_untagged_queues(ahc);	return found;}