Re: [PATCH net 3/3] i2c: designware: support hardware lock for Wangxun 10Gb NIC

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Aug 29, 2024 at 05:15:42PM +0800, Jiawen Wu wrote:
> On Fri, Aug 23, 2024 10:13 PM, Andy Shevchenko wrote:
> > On Fri, Aug 23, 2024 at 11:02:42AM +0800, Jiawen Wu wrote:

...

> > > +static int i2c_dw_txgbe_acquire_lock(struct dw_i2c_dev *dev)
> > > +{
> > > +	void __iomem *req_addr;
> > > +	u32 swsm;
> > > +	int i;
> > > +
> > > +	req_addr = dev->ext + I2C_DW_TXGBE_MNG_SW;
> > > +
> > > +	for (i = 0; i < I2C_DW_TXGBE_REQ_RETRY_CNT; i++) {
> > 
> > Retry loops much better in a form of
> > 
> > 	unsigned int retries = ...;
> > 	...
> > 	do {
> > 		...
> > 	} while (--retries);
> > 
> > BUT... see below.
> > 
> > > +		writel(I2C_DW_TXGBE_MNG_SW_SM, req_addr);
> > > +
> > > +		/* If we set the bit successfully then we got semaphore. */
> > > +		swsm = readl(req_addr);
> > > +		if (swsm & I2C_DW_TXGBE_MNG_SW_SM)
> > > +			break;
> > > +
> > > +		udelay(50);
> > 
> > So, can a macro from iopoll.h be utilised here? Why not?
> 
> I need to write the register first and then read it in this loop.
> It does not seem to apply to the macros in iopoll.h.

I don't see how does it prevent from using read_poll_timeout() macro.
You need to implement a body of the loop as a helper function that you supply
into macro as a parameter.

> > > +	}
> > > +
> > > +	if (i == I2C_DW_TXGBE_REQ_RETRY_CNT)
> > > +		return -ETIMEDOUT;
> > > +
> > > +	return 0;
> > > +}

-- 
With Best Regards,
Andy Shevchenko






[Index of Archives]     [Linux Kernel]     [Kernel Development Newbies]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite Hiking]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux