On Sun, 27 Oct 2024 09:40:48 -0700 Stephen Hemminger <step...@networkplumber.org> wrote:
> On Tue, 22 Oct 2024 20:20:42 +0800 > Junlong Wang <wang.junlo...@zte.com.cn> wrote: > > > +int32_t zxdh_acquire_lock(struct zxdh_hw *hw) > > +{ > > + uint32_t var = zxdh_read_comm_reg((uint64_t)hw->common_cfg, > > ZXDH_VF_LOCK_REG); > > + > > + /* check whether lock is used */ > > + if (!(var & ZXDH_VF_LOCK_ENABLE_MASK)) > > + return -1; > > + > > + return 0; > > +} > > + > > +int32_t zxdh_release_lock(struct zxdh_hw *hw) > > +{ > > + uint32_t var = zxdh_read_comm_reg((uint64_t)hw->common_cfg, > > ZXDH_VF_LOCK_REG); > > + > > + if (var & ZXDH_VF_LOCK_ENABLE_MASK) { > > + var &= ~ZXDH_VF_LOCK_ENABLE_MASK; > > + zxdh_write_comm_reg((uint64_t)hw->common_cfg, ZXDH_VF_LOCK_REG, > > var); > > + return 0; > > + } > > + > > + return -1; > > +} > > + > > It is your driver, so you are free to name functions as appropriate. > > But it would make more sense to make the hardware lock follow the pattern > of existing spinlock's etc. I am suggesting: static bool zxdh_try_lock(hw); void zxdh_release_lock(hw); also, move the loop into a new function, something like: int zxdh_timedlock(hw, uint32_t us);