FreeBSD/sys/cam/scsi/scsi_enc.c
/**
 * \brief Invoke the handler of the highest priority pending
 *	  state in the SES state machine.
 *
 * \param enc  The SES instance invoking the state machine.
 */
\brief Invoke the handler of the highest priority pending
state in the SES state machine.

\param enc  The SES instance invoking the state machine.
\ brief Invoke the handler of the highest priority pending state in the SES state machine . \ param enc The SES instance invoking the state machine .
static void
enc_fsm_step(enc_softc_t *enc)
{
	union ccb            *ccb;
	uint8_t              *buf;
	struct enc_fsm_state *cur_state;
	int		      error;
	uint32_t	      xfer_len;
	ENC_DLOG(enc, "%s enter %p\n", __func__, enc);
	enc->current_action   = ffs(enc->pending_actions) - 1;
	enc->pending_actions &= ~(0x1 << enc->current_action);
	cur_state = &enc->enc_fsm_states[enc->current_action];
	buf = NULL;
	if (cur_state->buf_size != 0) {
		cam_periph_unlock(enc->periph);
		buf = malloc(cur_state->buf_size, M_SCSIENC, M_WAITOK|M_ZERO);
		cam_periph_lock(enc->periph);
	}
	error = 0;
	ccb   = NULL;
	if (cur_state->fill != NULL) {
		ccb = cam_periph_getccb(enc->periph, CAM_PRIORITY_NORMAL);
		error = cur_state->fill(enc, cur_state, ccb, buf);
		if (error != 0)
			goto done;
		error = cam_periph_runccb(ccb, cur_state->error,
					  ENC_CFLAGS,
					  ENC_FLAGS|SF_QUIET_IR, NULL);
	}
	if (ccb != NULL) {
		if (ccb->ccb_h.func_code == XPT_ATA_IO)
			xfer_len = ccb->ataio.dxfer_len - ccb->ataio.resid;
		else
			xfer_len = ccb->csio.dxfer_len - ccb->csio.resid;
	} else
		xfer_len = 0;
	cam_periph_unlock(enc->periph);
	cur_state->done(enc, cur_state, ccb, &buf, error, xfer_len);
	cam_periph_lock(enc->periph);
done:
	ENC_DLOG(enc, "%s exit - result %d\n", __func__, error);
	ENC_FREE_AND_NULL(buf);
	if (ccb != NULL)
		xpt_release_ccb(ccb);
}
static void enc_fsm_step ( enc_softc_t * enc ) { union ccb * ccb ; uint8_t * buf ; struct enc_fsm_state * cur_state ; int error ; uint32_t xfer_len ; ENC_DLOG ( enc , " \n " , __func__ , enc ) ; enc -> current_action = ffs ( enc -> pending_actions ) - 1 ; enc -> pending_actions &= ~ ( 0x1 << enc -> current_action ) ; cur_state = & enc -> enc_fsm_states [ enc -> current_action ] ; buf = NULL ; if ( cur_state -> buf_size != 0 ) { cam_periph_unlock ( enc -> periph ) ; buf = malloc ( cur_state -> buf_size , M_SCSIENC , M_WAITOK | M_ZERO ) ; cam_periph_lock ( enc -> periph ) ; } error = 0 ; ccb = NULL ; if ( cur_state -> fill != NULL ) { ccb = cam_periph_getccb ( enc -> periph , CAM_PRIORITY_NORMAL ) ; error = cur_state -> fill ( enc , cur_state , ccb , buf ) ; if ( error != 0 ) goto done ; error = cam_periph_runccb ( ccb , cur_state -> error , ENC_CFLAGS , ENC_FLAGS | SF_QUIET_IR , NULL ) ; } if ( ccb != NULL ) { if ( ccb -> ccb_h . func_code == XPT_ATA_IO ) xfer_len = ccb -> ataio . dxfer_len - ccb -> ataio . resid ; else xfer_len = ccb -> csio . dxfer_len - ccb -> csio . resid ; } else xfer_len = 0 ; cam_periph_unlock ( enc -> periph ) ; cur_state -> done ( enc , cur_state , ccb , & buf , error , xfer_len ) ; cam_periph_lock ( enc -> periph ) ; done : ENC_DLOG ( enc , " \n " , __func__ , error ) ; ENC_FREE_AND_NULL ( buf ) ; if ( ccb != NULL ) xpt_release_ccb ( ccb ) ; }
\brief Invoke the handler of the highest priority pending
        state in the SES state machine.
\ brief Invoke the handler of the highest priority pending state in the SES state machine .