FreeBSD/sys/dev/cxgb/common/cxgb_t3_hw.c
/*
 *	t3_load_fw - download firmware
 *	@adapter: the adapter
 *	@fw_data: the firmware image to write
 *	@size: image size
 *
 *	Write the supplied firmware image to the card's serial flash.
 *	The FW image has the following sections: @size - 8 bytes of code and
 *	data, followed by 4 bytes of FW version, followed by the 32-bit
 *	1's complement checksum of the whole image.
 */
download firmware
@adapter: the adapter
@fw_data: the firmware image to write
@size: image size

Write the supplied firmware image to the card's serial flash.
The FW image has the following sections: @size - 8 bytes of code and
data, followed by 4 bytes of FW version, followed by the 32-bit
1's complement checksum of the whole image.
download firmware @adapter : the adapter @fw_data : the firmware image to write @size : image size Write the supplied firmware image to the card ' s serial flash . The FW image has the following sections : @size - 8 bytes of code and data followed by 4 bytes of FW version followed by the 32 - bit 1 ' s complement checksum of the whole image .
int t3_load_fw(adapter_t *adapter, const u8 *fw_data, unsigned int size)
{
	u32 version, csum, fw_version_addr;
	unsigned int i;
	const u32 *p = (const u32 *)fw_data;
	int ret, addr, fw_sector = FW_FLASH_BOOT_ADDR >> 16;
	if ((size & 3) || size < FW_MIN_SIZE)
		return -EINVAL;
	if (size - 8 > FW_MAX_SIZE)
		return -EFBIG;
	version = ntohl(*(const u32 *)(fw_data + size - 8));
	if (G_FW_VERSION_MAJOR(version) < 8) {
		fw_version_addr = FW_VERS_ADDR_PRE8;
		if (size - 8 > FW_MAX_SIZE_PRE8)
			return -EFBIG;
	} else
		fw_version_addr = FW_VERS_ADDR;
	for (csum = 0, i = 0; i < size / sizeof(csum); i++)
		csum += ntohl(p[i]);
	if (csum != 0xffffffff) {
		CH_ERR(adapter, "corrupted firmware image, checksum %u\n",
		       csum);
		return -EINVAL;
	}
	ret = t3_flash_erase_sectors(adapter, fw_sector, fw_sector);
	if (ret)
		goto out;
	size -= 8;  
	for (addr = FW_FLASH_BOOT_ADDR; size; ) {
		unsigned int chunk_size = min(size, 256U);
		ret = t3_write_flash(adapter, addr, chunk_size, fw_data, 1);
		if (ret)
			goto out;
		addr += chunk_size;
		fw_data += chunk_size;
		size -= chunk_size;
	}
	ret = t3_write_flash(adapter, fw_version_addr, 4, fw_data, 1);
out:
	if (ret)
		CH_ERR(adapter, "firmware download failed, error %d\n", ret);
	return ret;
}
int t3_load_fw ( adapter_t * adapter , const u8 * fw_data , unsigned int size ) { u32 version , csum , fw_version_addr ; unsigned int i ; const u32 * p = ( const u32 * ) fw_data ; int ret , addr , fw_sector = FW_FLASH_BOOT_ADDR >> 16 ; if ( ( size & 3 ) || size < FW_MIN_SIZE ) return - EINVAL ; if ( size - 8 > FW_MAX_SIZE ) return - EFBIG ; version = ntohl ( * ( const u32 * ) ( fw_data + size - 8 ) ) ; if ( G_FW_VERSION_MAJOR ( version ) < 8 ) { fw_version_addr = FW_VERS_ADDR_PRE8 ; if ( size - 8 > FW_MAX_SIZE_PRE8 ) return - EFBIG ; } else fw_version_addr = FW_VERS_ADDR ; for ( csum = 0 , i = 0 ; i < size / sizeof ( csum ) ; i ++ ) csum += ntohl ( p [ i ] ) ; if ( csum != 0xffffffff ) { CH_ERR ( adapter , " \n " , csum ) ; return - EINVAL ; } ret = t3_flash_erase_sectors ( adapter , fw_sector , fw_sector ) ; if ( ret ) goto out ; size -= 8 ; for ( addr = FW_FLASH_BOOT_ADDR ; size ; ) { unsigned int chunk_size = min ( size , 256U ) ; ret = t3_write_flash ( adapter , addr , chunk_size , fw_data , 1 ) ; if ( ret ) goto out ; addr += chunk_size ; fw_data += chunk_size ; size -= chunk_size ; } ret = t3_write_flash ( adapter , fw_version_addr , 4 , fw_data , 1 ) ; out : if ( ret ) CH_ERR ( adapter , " \n " , ret ) ; return ret ; }
t3_load_fw - download firmware
      @adapter: the adapter
      @fw_data: the firmware image to write
      @size: image size
t3_load_fw - download firmware @adapter : the adapter @fw_data : the firmware image to write @size : image size
/* trim off version and checksum */