Merge patch series "Prepare for upstreaming Pixel 6 and 7 UFS support"
[sfrench/cifs-2.6.git] / include / ufs / ufshcd.h
index c3dfa8084b5c36ec16c95e121d32782f8847aeb4..acdfa72d7230bfd0dd513d58b2a5d29bc14e56ff 100644 (file)
@@ -755,6 +755,7 @@ struct ufs_hba_monitor {
  * @vops: pointer to variant specific operations
  * @vps: pointer to variant specific parameters
  * @priv: pointer to variant specific private data
+ * @sg_entry_size: size of struct ufshcd_sg_entry (may include variant fields)
  * @irq: Irq number of the controller
  * @is_irq_enabled: whether or not the UFS controller interrupt is enabled.
  * @dev_ref_clk_freq: reference clock frequency
@@ -878,6 +879,9 @@ struct ufs_hba {
        const struct ufs_hba_variant_ops *vops;
        struct ufs_hba_variant_params *vps;
        void *priv;
+#ifdef CONFIG_SCSI_UFS_VARIABLE_SG_ENTRY_SIZE
+       size_t sg_entry_size;
+#endif
        unsigned int irq;
        bool is_irq_enabled;
        enum ufs_ref_clk_freq dev_ref_clk_freq;
@@ -981,6 +985,32 @@ struct ufs_hba {
        bool complete_put;
 };
 
+#ifdef CONFIG_SCSI_UFS_VARIABLE_SG_ENTRY_SIZE
+static inline size_t ufshcd_sg_entry_size(const struct ufs_hba *hba)
+{
+       return hba->sg_entry_size;
+}
+
+static inline void ufshcd_set_sg_entry_size(struct ufs_hba *hba, size_t sg_entry_size)
+{
+       WARN_ON_ONCE(sg_entry_size < sizeof(struct ufshcd_sg_entry));
+       hba->sg_entry_size = sg_entry_size;
+}
+#else
+static inline size_t ufshcd_sg_entry_size(const struct ufs_hba *hba)
+{
+       return sizeof(struct ufshcd_sg_entry);
+}
+
+#define ufshcd_set_sg_entry_size(hba, sg_entry_size)                   \
+       ({ (void)(hba); BUILD_BUG_ON(sg_entry_size != sizeof(struct ufshcd_sg_entry)); })
+#endif
+
+static inline size_t sizeof_utp_transfer_cmd_desc(const struct ufs_hba *hba)
+{
+       return sizeof(struct utp_transfer_cmd_desc) + SG_ALL * ufshcd_sg_entry_size(hba);
+}
+
 /* Returns true if clocks can be gated. Otherwise false */
 static inline bool ufshcd_is_clkgating_allowed(struct ufs_hba *hba)
 {