FreeBSD/sys/dev/cxgbe/common/t4_hw.c
/**
 *	t4_mem_read - read EDC 0, EDC 1 or MC into buffer
 *	@adap: the adapter
 *	@mtype: memory type: MEM_EDC0, MEM_EDC1 or MEM_MC
 *	@addr: address within indicated memory type
 *	@len: amount of memory to read
 *	@buf: host memory buffer
 *
 *	Reads an [almost] arbitrary memory region in the firmware: the
 *	firmware memory address, length and host buffer must be aligned on
 *	32-bit boudaries.  The memory is returned as a raw byte sequence from
 *	the firmware's memory.  If this memory contains data structures which
 *	contain multi-byte integers, it's the callers responsibility to
 *	perform appropriate byte order conversions.
 */


Reads an [almost] arbitrary memory region in the firmware: the
firmware memory address, length and host buffer must be aligned on
32-bit boudaries.  The memory is returned as a raw byte sequence from
the firmware's memory.  If this memory contains data structures which
contain multi-byte integers, it's the callers responsibility to
perform appropriate byte order conversions.
Reads an [ almost ] arbitrary memory region in the firmware : the firmware memory address length and host buffer must be aligned on 32 - bit boudaries . The memory is returned as a raw byte sequence from the firmware ' s memory . If this memory contains data structures which contain multi - byte integers it ' s the callers responsibility to perform appropriate byte order conversions .
int t4_mem_read(struct adapter *adap, int mtype, u32 addr, u32 len,
		__be32 *buf)
{
	u32 pos, start, end, offset;
	int ret;
	if ((addr & 0x3) || (len & 0x3))
		return -EINVAL;
	start = rounddown2(addr, 64);
	end = roundup2(addr + len, 64);
	offset = (addr - start)/sizeof(__be32);
	for (pos = start; pos < end; pos += 64, offset = 0) {
		__be32 data[16];
		if ((mtype == MEM_MC) || (mtype == MEM_MC1))
			ret = t4_mc_read(adap, mtype - MEM_MC, pos, data, NULL);
		else
			ret = t4_edc_read(adap, mtype, pos, data, NULL);
		if (ret)
			return ret;
		while (offset < 16 && len > 0) {
			*buf++ = data[offset++];
			len -= sizeof(__be32);
		}
	}
	return 0;
}
int t4_mem_read ( struct adapter * adap , int mtype , u32 addr , u32 len , __be32 * buf ) { u32 pos , start , end , offset ; int ret ; if ( ( addr & 0x3 ) || ( len & 0x3 ) ) return - EINVAL ; start = rounddown2 ( addr , 64 ) ; end = roundup2 ( addr + len , 64 ) ; offset = ( addr - start ) / sizeof ( __be32 ) ; for ( pos = start ; pos < end ; pos += 64 , offset = 0 ) { __be32 data [ 16 ] ; if ( ( mtype == MEM_MC ) || ( mtype == MEM_MC1 ) ) ret = t4_mc_read ( adap , mtype - MEM_MC , pos , data , NULL ) ; else ret = t4_edc_read ( adap , mtype , pos , data , NULL ) ; if ( ret ) return ret ; while ( offset < 16 && len > 0 ) { * buf ++ = data [ offset ++ ] ; len -= sizeof ( __be32 ) ; } } return 0 ; }
t4_mem_read - read EDC 0, EDC 1 or MC into buffer
      @adap: the adapter
      @mtype: memory type: MEM_EDC0, MEM_EDC1 or MEM_MC
      @addr: address within indicated memory type
      @len: amount of memory to read
      @buf: host memory buffer
t4_mem_read - read EDC 0 EDC 1 or MC into buffer @adap : the adapter @mtype : memory type : MEM_EDC0 MEM_EDC1 or MEM_MC @addr : address within indicated memory type @len : amount of memory to read @buf : host memory buffer
/*
	 * Argument sanity checks ...
	 */ /*
	 * The underlaying EDC/MC read routines read 64 bytes at a time so we
	 * need to round down the start and round up the end.  We'll start
	 * copying out of the first line at (addr - start) a word at a time.
	 */ /*
		 * Read the chip's memory block and bail if there's an error.
		 */ /*
		 * Copy the data into the caller's memory buffer.
		 */