FreeBSD/sys/dev/mps/mps.c
/* Wait for the chip to ACK a word that we've put into its FIFO 
 * Wait for <timeout> seconds. In single loop wait for busy loop
 * for 500 microseconds.
 * Total is [ 0.5 * (2000 * <timeout>) ] in miliseconds.
 * */
Wait for the chip to ACK a word that we've put into its FIFO
Wait for  seconds. In single loop wait for busy loop
for 500 microseconds.
Wait for the chip to ACK a word that we ' ve put into its FIFO Wait for seconds . In single loop wait for busy loop for 500 microseconds .
static int
mps_wait_db_ack(struct mps_softc *sc, int timeout, int sleep_flag)
{
	u32 cntdn, count;
	u32 int_status;
	u32 doorbell;
	count = 0;
	cntdn = (sleep_flag == CAN_SLEEP) ? 1000*timeout : 2000*timeout;
	do {
		int_status = mps_regread(sc, MPI2_HOST_INTERRUPT_STATUS_OFFSET);
		if (!(int_status & MPI2_HIS_SYS2IOC_DB_STATUS)) {
			mps_dprint(sc, MPS_INIT, 
			"%s: successful count(%d), timeout(%d)\n",
			__func__, count, timeout);
		return 0;
		} else if (int_status & MPI2_HIS_IOC2SYS_DB_STATUS) {
			doorbell = mps_regread(sc, MPI2_DOORBELL_OFFSET);
			if ((doorbell & MPI2_IOC_STATE_MASK) ==
				MPI2_IOC_STATE_FAULT) {
				mps_dprint(sc, MPS_FAULT, 
					"fault_state(0x%04x)!\n", doorbell);
				return (EFAULT);
			}
		} else if (int_status == 0xFFFFFFFF)
			goto out;
		if (mtx_owned(&sc->mps_mtx) && sleep_flag == CAN_SLEEP)
			msleep(&sc->msleep_fake_chan, &sc->mps_mtx, 0, 
			"mpsdba", hz/1000);
		else if (sleep_flag == CAN_SLEEP)
			pause("mpsdba", hz/1000);
		else
			DELAY(500);
		count++;
	} while (--cntdn);
	out:
	mps_dprint(sc, MPS_FAULT, "%s: failed due to timeout count(%d), "
		"int_status(%x)!\n", __func__, count, int_status);
	return (ETIMEDOUT);
}
static int mps_wait_db_ack ( struct mps_softc * sc , int timeout , int sleep_flag ) { u32 cntdn , count ; u32 int_status ; u32 doorbell ; count = 0 ; cntdn = ( sleep_flag == CAN_SLEEP ) ? 1000 * timeout : 2000 * timeout ; do { int_status = mps_regread ( sc , MPI2_HOST_INTERRUPT_STATUS_OFFSET ) ; if ( ! ( int_status & MPI2_HIS_SYS2IOC_DB_STATUS ) ) { mps_dprint ( sc , MPS_INIT , " \n " , __func__ , count , timeout ) ; return 0 ; } else if ( int_status & MPI2_HIS_IOC2SYS_DB_STATUS ) { doorbell = mps_regread ( sc , MPI2_DOORBELL_OFFSET ) ; if ( ( doorbell & MPI2_IOC_STATE_MASK ) == MPI2_IOC_STATE_FAULT ) { mps_dprint ( sc , MPS_FAULT , " \n " , doorbell ) ; return ( EFAULT ) ; } } else if ( int_status == 0xFFFFFFFF ) goto out ; if ( mtx_owned ( & sc -> mps_mtx ) && sleep_flag == CAN_SLEEP ) msleep ( & sc -> msleep_fake_chan , & sc -> mps_mtx , 0 , " " , hz / 1000 ) ; else if ( sleep_flag == CAN_SLEEP ) pause ( " " , hz / 1000 ) ; else DELAY ( 500 ) ; count ++ ; } while ( -- cntdn ) ; out : mps_dprint ( sc , MPS_FAULT , " " " \n " , __func__ , count , int_status ) ; return ( ETIMEDOUT ) ; }
Wait for the chip to ACK a word that we've put into its FIFO
 Wait for <timeout> seconds.
Wait for the chip to ACK a word that we ' ve put into its FIFO Wait for <timeout > seconds .
/* If it can sleep, sleep for 1 milisecond, else busy loop for 
		* 0.5 milisecond */