FreeBSD/sys/dev/bxe/ecore_sp.c
/**
 * ecore_func_chk_transition - perform function state machine transition
 *
 * @sc:		device handle
 * @o:
 * @params:
 *
 * It both checks if the requested command is legal in a current
 * state and, if it's legal, sets a `next_state' in the object
 * that will be used in the completion flow to set the `state'
 * of the object.
 *
 * returns 0 if a requested command is a legal transition,
 *         ECORE_INVAL otherwise.
 */
perform function state machine transition
@sc:         device handle
@o:
@params.

It both checks if the requested command is legal in a current
state and, if it's legal, sets a `next_state' in the object
that will be used in the completion flow to set the `state'
of the object.

returns 0 if a requested command is a legal transition,
ECORE_INVAL otherwise.
perform function state machine transition @sc : device handle @o : @params . It both checks if the requested command is legal in a current state and if it ' s legal sets a ` next_state ' in the object that will be used in the completion flow to set the ` state ' of the object . returns 0 if a requested command is a legal transition ECORE_INVAL otherwise .
static int ecore_func_chk_transition(struct bxe_softc *sc,
				     struct ecore_func_sp_obj *o,
				     struct ecore_func_state_params *params)
{
	enum ecore_func_state state = o->state, next_state = ECORE_F_STATE_MAX;
	enum ecore_func_cmd cmd = params->cmd;
	if (ECORE_TEST_BIT(RAMROD_DRV_CLR_ONLY, &params->ramrod_flags)) {
		o->pending = 0;
		o->next_state = ECORE_F_STATE_MAX;
	}
	if (o->pending)
		return ECORE_BUSY;
	switch (state) {
	case ECORE_F_STATE_RESET:
		if (cmd == ECORE_F_CMD_HW_INIT)
			next_state = ECORE_F_STATE_INITIALIZED;
		break;
	case ECORE_F_STATE_INITIALIZED:
		if (cmd == ECORE_F_CMD_START)
			next_state = ECORE_F_STATE_STARTED;
		else if (cmd == ECORE_F_CMD_HW_RESET)
			next_state = ECORE_F_STATE_RESET;
		break;
	case ECORE_F_STATE_STARTED:
		if (cmd == ECORE_F_CMD_STOP)
			next_state = ECORE_F_STATE_INITIALIZED;
		else if ((cmd == ECORE_F_CMD_AFEX_UPDATE) &&
			 (!ECORE_TEST_BIT(ECORE_F_CMD_STOP, &o->pending)))
			next_state = ECORE_F_STATE_STARTED;
		else if ((cmd == ECORE_F_CMD_AFEX_VIFLISTS) &&
			 (!ECORE_TEST_BIT(ECORE_F_CMD_STOP, &o->pending)))
			next_state = ECORE_F_STATE_STARTED;
		else if ((cmd == ECORE_F_CMD_SWITCH_UPDATE) &&
			 (!ECORE_TEST_BIT(ECORE_F_CMD_STOP, &o->pending)))
			next_state = ECORE_F_STATE_STARTED;
		else if ((cmd == ECORE_F_CMD_SET_TIMESYNC) &&
			 (!ECORE_TEST_BIT(ECORE_F_CMD_STOP, &o->pending)))
			next_state = ECORE_F_STATE_STARTED;
		else if (cmd == ECORE_F_CMD_TX_STOP)
			next_state = ECORE_F_STATE_TX_STOPPED;
		break;
	case ECORE_F_STATE_TX_STOPPED:
		if ((cmd == ECORE_F_CMD_SWITCH_UPDATE) &&
		    (!ECORE_TEST_BIT(ECORE_F_CMD_STOP, &o->pending)))
			next_state = ECORE_F_STATE_TX_STOPPED;
		else if ((cmd == ECORE_F_CMD_SET_TIMESYNC) &&
		    (!ECORE_TEST_BIT(ECORE_F_CMD_STOP, &o->pending)))
			next_state = ECORE_F_STATE_TX_STOPPED;
		else if (cmd == ECORE_F_CMD_TX_START)
			next_state = ECORE_F_STATE_STARTED;
		break;
	default:
		ECORE_ERR("Unknown state: %d\n", state);
	}
	if (next_state != ECORE_F_STATE_MAX) {
		ECORE_MSG(sc, "Good function state transition: %d(%d)->%d\n",
			  state, cmd, next_state);
		o->next_state = next_state;
		return ECORE_SUCCESS;
	}
	ECORE_MSG(sc, "Bad function state transition request: %d %d\n",
		  state, cmd);
	return ECORE_INVAL;
}
static int ecore_func_chk_transition ( struct bxe_softc * sc , struct ecore_func_sp_obj * o , struct ecore_func_state_params * params ) { enum ecore_func_state state = o -> state , next_state = ECORE_F_STATE_MAX ; enum ecore_func_cmd cmd = params -> cmd ; if ( ECORE_TEST_BIT ( RAMROD_DRV_CLR_ONLY , & params -> ramrod_flags ) ) { o -> pending = 0 ; o -> next_state = ECORE_F_STATE_MAX ; } if ( o -> pending ) return ECORE_BUSY ; switch ( state ) { case ECORE_F_STATE_RESET : if ( cmd == ECORE_F_CMD_HW_INIT ) next_state = ECORE_F_STATE_INITIALIZED ; break ; case ECORE_F_STATE_INITIALIZED : if ( cmd == ECORE_F_CMD_START ) next_state = ECORE_F_STATE_STARTED ; else if ( cmd == ECORE_F_CMD_HW_RESET ) next_state = ECORE_F_STATE_RESET ; break ; case ECORE_F_STATE_STARTED : if ( cmd == ECORE_F_CMD_STOP ) next_state = ECORE_F_STATE_INITIALIZED ; else if ( ( cmd == ECORE_F_CMD_AFEX_UPDATE ) && ( ! ECORE_TEST_BIT ( ECORE_F_CMD_STOP , & o -> pending ) ) ) next_state = ECORE_F_STATE_STARTED ; else if ( ( cmd == ECORE_F_CMD_AFEX_VIFLISTS ) && ( ! ECORE_TEST_BIT ( ECORE_F_CMD_STOP , & o -> pending ) ) ) next_state = ECORE_F_STATE_STARTED ; else if ( ( cmd == ECORE_F_CMD_SWITCH_UPDATE ) && ( ! ECORE_TEST_BIT ( ECORE_F_CMD_STOP , & o -> pending ) ) ) next_state = ECORE_F_STATE_STARTED ; else if ( ( cmd == ECORE_F_CMD_SET_TIMESYNC ) && ( ! ECORE_TEST_BIT ( ECORE_F_CMD_STOP , & o -> pending ) ) ) next_state = ECORE_F_STATE_STARTED ; else if ( cmd == ECORE_F_CMD_TX_STOP ) next_state = ECORE_F_STATE_TX_STOPPED ; break ; case ECORE_F_STATE_TX_STOPPED : if ( ( cmd == ECORE_F_CMD_SWITCH_UPDATE ) && ( ! ECORE_TEST_BIT ( ECORE_F_CMD_STOP , & o -> pending ) ) ) next_state = ECORE_F_STATE_TX_STOPPED ; else if ( ( cmd == ECORE_F_CMD_SET_TIMESYNC ) && ( ! ECORE_TEST_BIT ( ECORE_F_CMD_STOP , & o -> pending ) ) ) next_state = ECORE_F_STATE_TX_STOPPED ; else if ( cmd == ECORE_F_CMD_TX_START ) next_state = ECORE_F_STATE_STARTED ; break ; default : ECORE_ERR ( " \n " , state ) ; } if ( next_state != ECORE_F_STATE_MAX ) { ECORE_MSG ( sc , " \n " , state , cmd , next_state ) ; o -> next_state = next_state ; return ECORE_SUCCESS ; } ECORE_MSG ( sc , " \n " , state , cmd ) ; return ECORE_INVAL ; }
ecore_func_chk_transition - perform function state machine transition
 @sc:         device handle
 @o:
 @params:
ecore_func_chk_transition - perform function state machine transition @sc : device handle @o : @params :
/* Forget all pending for completion commands if a driver only state
	 * transition has been requested.
	 */ /* Don't allow a next state transition if we are in the middle of
	 * the previous one.
	 */ /* afex ramrods can be sent only in started mode, and only
		 * if not pending for function_stop ramrod completion
		 * for these events - next state remained STARTED.
		 */ /* Switch_update ramrod can be sent in either started or
		 * tx_stopped state, and it doesn't change the state.
		 */ /* Transition is assured */