Introduce `ufshcd_dme_rmw` API to read, modify, and write DME
attributes in UFS host controllers using a mask and value.
Signed-off-by: Nitin Rawat <quic_nitirawa@quicinc.com>
---
include/ufs/ufshcd.h | 26 ++++++++++++++++++++++++++
1 file changed, 26 insertions(+)
diff --git a/include/ufs/ufshcd.h b/include/ufs/ufshcd.h
index 9b3515cee711..fe4bb248484c 100644
--- a/include/ufs/ufshcd.h
+++ b/include/ufs/ufshcd.h
@@ -1498,6 +1498,32 @@ static inline int ufshcd_vops_phy_initialization(struct ufs_hba *hba)
return 0;
}
+/**
+ * ufshcd_dme_rmw - get modify set a dme attribute
+ * @hba - per adapter instance
+ * @mask - mask to apply on read value
+ * @val - actual value to write
+ * @attr - dme attribute
+ */
+static inline int ufshcd_dme_rmw(struct ufs_hba *hba, u32 mask,
+ u32 val, u32 attr)
+{
+ u32 cfg = 0;
+ int err = 0;
+
+ err = ufshcd_dme_get(hba, UIC_ARG_MIB(attr), &cfg);
+ if (err)
+ goto out;
+
+ cfg &= ~mask;
+ cfg |= (val & mask);
+
+ err = ufshcd_dme_set(hba, UIC_ARG_MIB(attr), cfg);
+
+out:
+ return err;
+}
+
extern const struct ufs_pm_lvl_states ufs_pm_lvl_states[];
int ufshcd_dump_regs(struct ufs_hba *hba, size_t offset, size_t len,
--
2.48.1
On Tue, Jul 08, 2025 at 02:32:59AM GMT, Nitin Rawat wrote: > Introduce `ufshcd_dme_rmw` API to read, modify, and write DME > attributes in UFS host controllers using a mask and value. > > Signed-off-by: Nitin Rawat <quic_nitirawa@quicinc.com> > --- > include/ufs/ufshcd.h | 26 ++++++++++++++++++++++++++ > 1 file changed, 26 insertions(+) > > diff --git a/include/ufs/ufshcd.h b/include/ufs/ufshcd.h > index 9b3515cee711..fe4bb248484c 100644 > --- a/include/ufs/ufshcd.h > +++ b/include/ufs/ufshcd.h > @@ -1498,6 +1498,32 @@ static inline int ufshcd_vops_phy_initialization(struct ufs_hba *hba) > return 0; > } > > +/** > + * ufshcd_dme_rmw - get modify set a dme attribute s/dme/DME Maybe name the function as, 'ufshcd_dme_update()'? > + * @hba - per adapter instance > + * @mask - mask to apply on read value > + * @val - actual value to write > + * @attr - dme attribute > + */ > +static inline int ufshcd_dme_rmw(struct ufs_hba *hba, u32 mask, > + u32 val, u32 attr) Please move the definition to ufshcd.c > +{ > + u32 cfg = 0; > + int err = 0; No need to initialize these. > + > + err = ufshcd_dme_get(hba, UIC_ARG_MIB(attr), &cfg); > + if (err) > + goto out; Just do, 'return err'. > + > + cfg &= ~mask; > + cfg |= (val & mask); > + > + err = ufshcd_dme_set(hba, UIC_ARG_MIB(attr), cfg); return ufshcd_dme_set(); - Mani -- மணிவண்ணன் சதாசிவம்
On 7/7/25 2:02 PM, Nitin Rawat wrote: > +/** > + * ufshcd_dme_rmw - get modify set a dme attribute > + * @hba - per adapter instance > + * @mask - mask to apply on read value > + * @val - actual value to write > + * @attr - dme attribute > + */ > +static inline int ufshcd_dme_rmw(struct ufs_hba *hba, u32 mask, > + u32 val, u32 attr) > +{ > + u32 cfg = 0; > + int err = 0; I don't think that it is necessary to zero-initialize 'err' because the next statement overwrites the value of 'err'. > + > + err = ufshcd_dme_get(hba, UIC_ARG_MIB(attr), &cfg); > + if (err) > + goto out; > + > + cfg &= ~mask; > + cfg |= (val & mask); > + > + err = ufshcd_dme_set(hba, UIC_ARG_MIB(attr), cfg); > + > +out: > + return err; > +} Since this code is not performance-critical, please move the function definition into source file ufshcd.c. Thanks, Bart.
© 2016 - 2025 Red Hat, Inc.