FreeBSD/sys/dev/cxgb/common/cxgb_t3_hw.c
/**
 *	t3_write_flash - write up to a page of data to the serial flash
 *	@adapter: the adapter
 *	@addr: the start address to write
 *	@n: length of data to write
 *	@data: the data to write
 *	@byte_oriented: whether to store data as bytes or as words
 *
 *	Writes up to a page of data (256 bytes) to the serial flash starting
 *	at the given address.
 *	If @byte_oriented is set the write data is stored as a 32-bit
 *	big-endian array, otherwise in the processor's native endianness.
 *
 */


Writes up to a page of data (256 bytes) to the serial flash starting
at the given address.
If @byte_oriented is set the write data is stored as a 32-bit
big-endian array, otherwise in the processor's native endianness.
Writes up to a page of data ( 256 bytes ) to the serial flash starting at the given address . If @byte_oriented is set the write data is stored as a 32 - bit big - endian array otherwise in the processor ' s native endianness .
static int t3_write_flash(adapter_t *adapter, unsigned int addr,
			  unsigned int n, const u8 *data,
			  int byte_oriented)
{
	int ret;
	u32 buf[64];
	unsigned int c, left, val, offset = addr & 0xff;
	if (addr + n > SF_SIZE || offset + n > 256)
		return -EINVAL;
	val = swab32(addr) | SF_PROG_PAGE;
	if ((ret = sf1_write(adapter, 1, 0, SF_WR_ENABLE)) != 0 ||
	    (ret = sf1_write(adapter, 4, 1, val)) != 0)
		return ret;
	for (left = n; left; left -= c) {
		c = min(left, 4U);
		val = *(const u32*)data;
		data += c;
		if (byte_oriented)
			val = htonl(val);
		ret = sf1_write(adapter, c, c != left, val);
		if (ret)
			return ret;
	}
	if ((ret = flash_wait_op(adapter, 5, 1)) != 0)
		return ret;
	ret = t3_read_flash(adapter, addr & ~0xff, ARRAY_SIZE(buf), buf,
			    byte_oriented);
	if (ret)
		return ret;
	if (memcmp(data - n, (u8 *)buf + offset, n))
		return -EIO;
	return 0;
}
static int t3_write_flash ( adapter_t * adapter , unsigned int addr , unsigned int n , const u8 * data , int byte_oriented ) { int ret ; u32 buf [ 64 ] ; unsigned int c , left , val , offset = addr & 0xff ; if ( addr + n > SF_SIZE || offset + n > 256 ) return - EINVAL ; val = swab32 ( addr ) | SF_PROG_PAGE ; if ( ( ret = sf1_write ( adapter , 1 , 0 , SF_WR_ENABLE ) ) != 0 || ( ret = sf1_write ( adapter , 4 , 1 , val ) ) != 0 ) return ret ; for ( left = n ; left ; left -= c ) { c = min ( left , 4U ) ; val = * ( const u32 * ) data ; data += c ; if ( byte_oriented ) val = htonl ( val ) ; ret = sf1_write ( adapter , c , c != left , val ) ; if ( ret ) return ret ; } if ( ( ret = flash_wait_op ( adapter , 5 , 1 ) ) != 0 ) return ret ; ret = t3_read_flash ( adapter , addr & ~ 0xff , ARRAY_SIZE ( buf ) , buf , byte_oriented ) ; if ( ret ) return ret ; if ( memcmp ( data - n , ( u8 * ) buf + offset , n ) ) return - EIO ; return 0 ; }
t3_write_flash - write up to a page of data to the serial flash
      @adapter: the adapter
      @addr: the start address to write
      @n: length of data to write
      @data: the data to write
      @byte_oriented: whether to store data as bytes or as words
t3_write_flash - write up to a page of data to the serial flash @adapter : the adapter @addr : the start address to write @n : length of data to write @data : the data to write @byte_oriented : whether to store data as bytes or as words
/* Read the page to verify the write succeeded */