FreeBSD/sys/dev/cxgbe/common/t4_hw.c
/**
 *	t4_fw_upgrade - perform all of the steps necessary to upgrade FW
 *	@adap: the adapter
 *	@mbox: mailbox to use for the FW RESET command (if desired)
 *	@fw_data: the firmware image to write
 *	@size: image size
 *	@force: force upgrade even if firmware doesn't cooperate
 *
 *	Perform all of the steps necessary for upgrading an adapter's
 *	firmware image.  Normally this requires the cooperation of the
 *	existing firmware in order to halt all existing activities
 *	but if an invalid mailbox token is passed in we skip that step
 *	(though we'll still put the adapter microprocessor into RESET in
 *	that case).
 *
 *	On successful return the new firmware will have been loaded and
 *	the adapter will have been fully RESET losing all previous setup
 *	state.  On unsuccessful return the adapter may be completely hosed ...
 *	positive errno indicates that the adapter is ~probably~ intact, a
 *	negative errno indicates that things are looking bad ...
 */


Perform all of the steps necessary for upgrading an adapter's
firmware image.  Normally this requires the cooperation of the
existing firmware in order to halt all existing activities
but if an invalid mailbox token is passed in we skip that step
(though we'll still put the adapter microprocessor into RESET in
that case).

On successful return the new firmware will have been loaded and
the adapter will have been fully RESET losing all previous setup
state.  On unsuccessful return the adapter may be completely hosed
positive errno indicates that the adapter is ~probably~ intact, a
negative errno indicates that things are looking bad
Perform all of the steps necessary for upgrading an adapter ' s firmware image . Normally this requires the cooperation of the existing firmware in order to halt all existing activities but if an invalid mailbox token is passed in we skip that step ( though we ' ll still put the adapter microprocessor into RESET in that case ) . On successful return the new firmware will have been loaded and the adapter will have been fully RESET losing all previous setup state . On unsuccessful return the adapter may be completely hosed positive errno indicates that the adapter is ~probably~ intact a negative errno indicates that things are looking bad
int t4_fw_upgrade(struct adapter *adap, unsigned int mbox,
		  const u8 *fw_data, unsigned int size, int force)
{
	const struct fw_hdr *fw_hdr = (const struct fw_hdr *)fw_data;
	unsigned int bootstrap =
	    be32_to_cpu(fw_hdr->magic) == FW_HDR_MAGIC_BOOTSTRAP;
	int reset, ret;
	if (!t4_fw_matches_chip(adap, fw_hdr))
		return -EINVAL;
	if (!bootstrap) {
		ret = t4_fw_halt(adap, mbox, force);
		if (ret < 0 && !force)
			return ret;
	}
	ret = t4_load_fw(adap, fw_data, size);
	if (ret < 0 || bootstrap)
		return ret;
	reset = ((be32_to_cpu(fw_hdr->flags) & FW_HDR_FLAGS_RESET_HALT) == 0);
	return t4_fw_restart(adap, mbox, reset);
}
int t4_fw_upgrade ( struct adapter * adap , unsigned int mbox , const u8 * fw_data , unsigned int size , int force ) { const struct fw_hdr * fw_hdr = ( const struct fw_hdr * ) fw_data ; unsigned int bootstrap = be32_to_cpu ( fw_hdr -> magic ) == FW_HDR_MAGIC_BOOTSTRAP ; int reset , ret ; if ( ! t4_fw_matches_chip ( adap , fw_hdr ) ) return - EINVAL ; if ( ! bootstrap ) { ret = t4_fw_halt ( adap , mbox , force ) ; if ( ret < 0 && ! force ) return ret ; } ret = t4_load_fw ( adap , fw_data , size ) ; if ( ret < 0 || bootstrap ) return ret ; reset = ( ( be32_to_cpu ( fw_hdr -> flags ) & FW_HDR_FLAGS_RESET_HALT ) == 0 ) ; return t4_fw_restart ( adap , mbox , reset ) ; }
t4_fw_upgrade - perform all of the steps necessary to upgrade FW
      @adap: the adapter
      @mbox: mailbox to use for the FW RESET command (if desired)
      @fw_data: the firmware image to write
      @size: image size
      @force: force upgrade even if firmware doesn't cooperate
t4_fw_upgrade - perform all of the steps necessary to upgrade FW @adap : the adapter @mbox : mailbox to use for the FW RESET command ( if desired ) @fw_data : the firmware image to write @size : image size @force : force upgrade even if firmware doesn ' t cooperate
/*
	 * Older versions of the firmware don't understand the new
	 * PCIE_FW.HALT flag and so won't know to perform a RESET when they
	 * restart.  So for newly loaded older firmware we'll have to do the
	 * RESET for it so it starts up on a clean slate.  We can tell if
	 * the newly loaded firmware will handle this right by checking
	 * its header flags to see if it advertises the capability.
	 */