FreeBSD/sys/dev/cxgb/common/cxgb_t3_hw.c
/**
 *	t3_mc7_bd_read - read from MC7 through backdoor accesses
 *	@mc7: identifies MC7 to read from
 *	@start: index of first 64-bit word to read
 *	@n: number of 64-bit words to read
 *	@buf: where to store the read result
 *
 *	Read n 64-bit words from MC7 starting at word start, using backdoor
 *	accesses.
 */
read from MC7 through backdoor accesses
@mc7: identifies MC7 to read from
@start: index of first 64-bit word to read
@n: number of 64-bit words to read
@buf: where to store the read result

Read n 64-bit words from MC7 starting at word start, using backdoor
accesses.
read from MC7 through backdoor accesses @mc7 : identifies MC7 to read from @start : index of first 64 - bit word to read @n : number of 64 - bit words to read @buf : where to store the read result Read n 64 - bit words from MC7 starting at word start using backdoor accesses .
int t3_mc7_bd_read(struct mc7 *mc7, unsigned int start, unsigned int n,
                   u64 *buf)
{
	static int shift[] = { 0, 0, 16, 24 };
	static int step[]  = { 0, 32, 16, 8 };
	unsigned int size64 = mc7->size / 8;  
	adapter_t *adap = mc7->adapter;
	if (start >= size64 || start + n > size64)
		return -EINVAL;
	start *= (8 << mc7->width);
	while (n--) {
		int i;
		u64 val64 = 0;
		for (i = (1 << mc7->width) - 1; i >= 0; --i) {
			int attempts = 10;
			u32 val;
			t3_write_reg(adap, mc7->offset + A_MC7_BD_ADDR,
				       start);
			t3_write_reg(adap, mc7->offset + A_MC7_BD_OP, 0);
			val = t3_read_reg(adap, mc7->offset + A_MC7_BD_OP);
			while ((val & F_BUSY) && attempts--)
				val = t3_read_reg(adap,
						  mc7->offset + A_MC7_BD_OP);
			if (val & F_BUSY)
				return -EIO;
			val = t3_read_reg(adap, mc7->offset + A_MC7_BD_DATA1);
			if (mc7->width == 0) {
				val64 = t3_read_reg(adap,
						mc7->offset + A_MC7_BD_DATA0);
				val64 |= (u64)val << 32;
			} else {
				if (mc7->width > 1)
					val >>= shift[mc7->width];
				val64 |= (u64)val << (step[mc7->width] * i);
			}
			start += 8;
		}
		*buf++ = val64;
	}
	return 0;
}
int t3_mc7_bd_read ( struct mc7 * mc7 , unsigned int start , unsigned int n , u64 * buf ) { static int shift [ ] = { 0 , 0 , 16 , 24 } ; static int step [ ] = { 0 , 32 , 16 , 8 } ; unsigned int size64 = mc7 -> size / 8 ; adapter_t * adap = mc7 -> adapter ; if ( start >= size64 || start + n > size64 ) return - EINVAL ; start *= ( 8 << mc7 -> width ) ; while ( n -- ) { int i ; u64 val64 = 0 ; for ( i = ( 1 << mc7 -> width ) - 1 ; i >= 0 ; -- i ) { int attempts = 10 ; u32 val ; t3_write_reg ( adap , mc7 -> offset + A_MC7_BD_ADDR , start ) ; t3_write_reg ( adap , mc7 -> offset + A_MC7_BD_OP , 0 ) ; val = t3_read_reg ( adap , mc7 -> offset + A_MC7_BD_OP ) ; while ( ( val & F_BUSY ) && attempts -- ) val = t3_read_reg ( adap , mc7 -> offset + A_MC7_BD_OP ) ; if ( val & F_BUSY ) return - EIO ; val = t3_read_reg ( adap , mc7 -> offset + A_MC7_BD_DATA1 ) ; if ( mc7 -> width == 0 ) { val64 = t3_read_reg ( adap , mc7 -> offset + A_MC7_BD_DATA0 ) ; val64 |= ( u64 ) val << 32 ; } else { if ( mc7 -> width > 1 ) val >>= shift [ mc7 -> width ] ; val64 |= ( u64 ) val << ( step [ mc7 -> width ] * i ) ; } start += 8 ; } * buf ++ = val64 ; } return 0 ; }
t3_mc7_bd_read - read from MC7 through backdoor accesses
      @mc7: identifies MC7 to read from
      @start: index of first 64-bit word to read
      @n: number of 64-bit words to read
      @buf: where to store the read result
t3_mc7_bd_read - read from MC7 through backdoor accesses @mc7 : identifies MC7 to read from @start : index of first 64 - bit word to read @n : number of 64 - bit words to read @buf : where to store the read result
/* # of 64-bit words */