/* Wait until an operation is completed by checking a bit in a register up to @attempts times. If @valp is not NULL the value of the register at the time it indicated completion is stored there. Returns 0 if the operation completes and -EAGAIN otherwise.  */
int t3_wait_op_done_val(struct adapter *adapter, int reg, u32 mask, int polarity, int attempts, int delay, u32 *valp)
/* Wait until an operation is completed by checking a bit in a register up to @attempts times. If @valp is not NULL the value of the register at the time it indicated completion is stored there. Returns 0 if the operation completes and -EAGAIN otherwise.  */
int t3_wait_op_done_val(struct adapter *adapter, int reg, u32 mask, int polarity, int attempts, int delay, u32 *valp)
{
	while (1) {
		u32 val = t3_read_reg(adapter, reg);
		if (!!(val & mask) == polarity) {
			if (valp)
				*valp = val;
			return 0;
		}
		if (--attempts == 0)
			return -EAGAIN;
		if (delay)
			udelay(delay);
	}
}