FreeBSD/sys/dev/bxe/ecore_sp.c
/**
 * ecore_func_state_change - perform Function state change transition
 *
 * @sc:		device handle
 * @params:	parameters to perform the transaction
 *
 * returns 0 in case of successfully completed transition,
 *         negative error code in case of failure, positive
 *         (EBUSY) value if there is a completion to that is
 *         still pending (possible only if RAMROD_COMP_WAIT is
 *         not set in params->ramrod_flags for asynchronous
 *         commands).
 */
perform Function state change transition
@sc:         device handle
@params:     parameters to perform the transaction

returns 0 in case of successfully completed transition,
negative error code in case of failure, positive
(EBUSY) value if there is a completion to that is
still pending (possible only if RAMROD_COMP_WAIT is
not set in params->ramrod_flags for asynchronous
commands).
perform Function state change transition @sc : device handle @params : parameters to perform the transaction returns 0 in case of successfully completed transition negative error code in case of failure positive ( EBUSY ) value if there is a completion to that is still pending ( possible only if RAMROD_COMP_WAIT is not set in params - > ramrod_flags for asynchronous commands ) .
int ecore_func_state_change(struct bxe_softc *sc,
			    struct ecore_func_state_params *params)
{
	struct ecore_func_sp_obj *o = params->f_obj;
	int rc, cnt = 300;
	enum ecore_func_cmd cmd = params->cmd;
	unsigned long *pending = &o->pending;
	ECORE_MUTEX_LOCK(&o->one_pending_mutex);
	rc = o->check_transition(sc, o, params);
	if ((rc == ECORE_BUSY) &&
	    (ECORE_TEST_BIT(RAMROD_RETRY, &params->ramrod_flags))) {
		while ((rc == ECORE_BUSY) && (--cnt > 0)) {
			ECORE_MUTEX_UNLOCK(&o->one_pending_mutex);
			ECORE_MSLEEP(10);
			ECORE_MUTEX_LOCK(&o->one_pending_mutex);
			rc = o->check_transition(sc, o, params);
		}
		if (rc == ECORE_BUSY) {
			ECORE_MUTEX_UNLOCK(&o->one_pending_mutex);
			ECORE_ERR("timeout waiting for previous ramrod completion\n");
			return rc;
		}
	} else if (rc) {
		ECORE_MUTEX_UNLOCK(&o->one_pending_mutex);
		return rc;
	}
	ECORE_SET_BIT(cmd, pending);
	if (ECORE_TEST_BIT(RAMROD_DRV_CLR_ONLY, &params->ramrod_flags)) {
		ecore_func_state_change_comp(sc, o, cmd);
		ECORE_MUTEX_UNLOCK(&o->one_pending_mutex);
	} else {
		rc = o->send_cmd(sc, params);
		ECORE_MUTEX_UNLOCK(&o->one_pending_mutex);
		if (rc) {
			o->next_state = ECORE_F_STATE_MAX;
			ECORE_CLEAR_BIT(cmd, pending);
			ECORE_SMP_MB_AFTER_CLEAR_BIT();
			return rc;
		}
		if (ECORE_TEST_BIT(RAMROD_COMP_WAIT, &params->ramrod_flags)) {
			rc = o->wait_comp(sc, o, cmd);
			if (rc)
				return rc;
			return ECORE_SUCCESS;
		}
	}
	return ECORE_RET_PENDING(cmd, pending);
}
int ecore_func_state_change ( struct bxe_softc * sc , struct ecore_func_state_params * params ) { struct ecore_func_sp_obj * o = params -> f_obj ; int rc , cnt = 300 ; enum ecore_func_cmd cmd = params -> cmd ; unsigned long * pending = & o -> pending ; ECORE_MUTEX_LOCK ( & o -> one_pending_mutex ) ; rc = o -> check_transition ( sc , o , params ) ; if ( ( rc == ECORE_BUSY ) && ( ECORE_TEST_BIT ( RAMROD_RETRY , & params -> ramrod_flags ) ) ) { while ( ( rc == ECORE_BUSY ) && ( -- cnt > 0 ) ) { ECORE_MUTEX_UNLOCK ( & o -> one_pending_mutex ) ; ECORE_MSLEEP ( 10 ) ; ECORE_MUTEX_LOCK ( & o -> one_pending_mutex ) ; rc = o -> check_transition ( sc , o , params ) ; } if ( rc == ECORE_BUSY ) { ECORE_MUTEX_UNLOCK ( & o -> one_pending_mutex ) ; ECORE_ERR ( " \n " ) ; return rc ; } } else if ( rc ) { ECORE_MUTEX_UNLOCK ( & o -> one_pending_mutex ) ; return rc ; } ECORE_SET_BIT ( cmd , pending ) ; if ( ECORE_TEST_BIT ( RAMROD_DRV_CLR_ONLY , & params -> ramrod_flags ) ) { ecore_func_state_change_comp ( sc , o , cmd ) ; ECORE_MUTEX_UNLOCK ( & o -> one_pending_mutex ) ; } else { rc = o -> send_cmd ( sc , params ) ; ECORE_MUTEX_UNLOCK ( & o -> one_pending_mutex ) ; if ( rc ) { o -> next_state = ECORE_F_STATE_MAX ; ECORE_CLEAR_BIT ( cmd , pending ) ; ECORE_SMP_MB_AFTER_CLEAR_BIT ( ) ; return rc ; } if ( ECORE_TEST_BIT ( RAMROD_COMP_WAIT , & params -> ramrod_flags ) ) { rc = o -> wait_comp ( sc , o , cmd ) ; if ( rc ) return rc ; return ECORE_SUCCESS ; } } return ECORE_RET_PENDING ( cmd , pending ) ; }
ecore_func_state_change - perform Function state change transition
 @sc:         device handle
 @params:     parameters to perform the transaction
ecore_func_state_change - perform Function state change transition @sc : device handle @params : parameters to perform the transaction
/* Check that the requested transition is legal */ /* Set "pending" bit */ /* Don't send a command if only driver cleanup was requested */ /* Send a ramrod */