2 * Universal Flash Storage Host controller driver
4 * This code is based on drivers/scsi/ufs/ufshcd.h
5 * Copyright (C) 2011-2013 Samsung India Software Operations
6 * Copyright (c) 2013-2016, The Linux Foundation. All rights reserved.
9 * Santosh Yaraganavi <santosh.sy@samsung.com>
10 * Vinayak Holikatti <h.vinayak@samsung.com>
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 * See the COPYING file in the top-level directory or visit
17 * <http://www.gnu.org/licenses/gpl-2.0.html>
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * This program is provided "AS IS" and "WITH ALL FAULTS" and
25 * without warranty of any kind. You are solely responsible for
26 * determining the appropriateness of using and distributing
27 * the program and assume all risks associated with your exercise
28 * of rights with respect to the program, including but not limited
29 * to infringement of third party rights, the risks and costs of
30 * program errors, damage to or loss of data, programs or equipment,
31 * and unavailability or interruption of operations. Under no
32 * circumstances will the contributor of this Program be liable for
33 * any damages of any kind arising from your use or distribution of
40 #include <linux/module.h>
41 #include <linux/kernel.h>
42 #include <linux/init.h>
43 #include <linux/interrupt.h>
45 #include <linux/delay.h>
46 #include <linux/slab.h>
47 #include <linux/spinlock.h>
48 #include <linux/workqueue.h>
49 #include <linux/errno.h>
50 #include <linux/types.h>
51 #include <linux/wait.h>
52 #include <linux/bitops.h>
53 #include <linux/pm_runtime.h>
54 #include <linux/clk.h>
55 #include <linux/completion.h>
56 #include <linux/regulator/consumer.h>
60 #include <asm/byteorder.h>
61 #include <scsi/scsi.h>
62 #include <scsi/scsi_cmnd.h>
63 #include <scsi/scsi_host.h>
64 #include <scsi/scsi_tcq.h>
65 #include <scsi/scsi_dbg.h>
66 #include <scsi/scsi_eh.h>
71 #define UFSHCD "ufshcd"
72 #define UFSHCD_DRIVER_VERSION "0.2"
77 DEV_CMD_TYPE_NOP = 0x0,
78 DEV_CMD_TYPE_QUERY = 0x1,
82 * struct uic_command - UIC command structure
83 * @command: UIC command
84 * @argument1: UIC command argument 1
85 * @argument2: UIC command argument 2
86 * @argument3: UIC command argument 3
87 * @cmd_active: Indicate if UIC command is outstanding
88 * @result: UIC command result
89 * @done: UIC command completion
98 struct completion done;
101 /* Used to differentiate the power management options */
108 #define ufshcd_is_runtime_pm(op) ((op) == UFS_RUNTIME_PM)
109 #define ufshcd_is_system_pm(op) ((op) == UFS_SYSTEM_PM)
110 #define ufshcd_is_shutdown_pm(op) ((op) == UFS_SHUTDOWN_PM)
112 /* Host <-> Device UniPro Link state */
113 enum uic_link_state {
114 UIC_LINK_OFF_STATE = 0, /* Link powered down or disabled */
115 UIC_LINK_ACTIVE_STATE = 1, /* Link is in Fast/Slow/Sleep state */
116 UIC_LINK_HIBERN8_STATE = 2, /* Link is in Hibernate state */
119 #define ufshcd_is_link_off(hba) ((hba)->uic_link_state == UIC_LINK_OFF_STATE)
120 #define ufshcd_is_link_active(hba) ((hba)->uic_link_state == \
121 UIC_LINK_ACTIVE_STATE)
122 #define ufshcd_is_link_hibern8(hba) ((hba)->uic_link_state == \
123 UIC_LINK_HIBERN8_STATE)
124 #define ufshcd_set_link_off(hba) ((hba)->uic_link_state = UIC_LINK_OFF_STATE)
125 #define ufshcd_set_link_active(hba) ((hba)->uic_link_state = \
126 UIC_LINK_ACTIVE_STATE)
127 #define ufshcd_set_link_hibern8(hba) ((hba)->uic_link_state = \
128 UIC_LINK_HIBERN8_STATE)
131 * UFS Power management levels.
132 * Each level is in increasing order of power savings.
135 UFS_PM_LVL_0, /* UFS_ACTIVE_PWR_MODE, UIC_LINK_ACTIVE_STATE */
136 UFS_PM_LVL_1, /* UFS_ACTIVE_PWR_MODE, UIC_LINK_HIBERN8_STATE */
137 UFS_PM_LVL_2, /* UFS_SLEEP_PWR_MODE, UIC_LINK_ACTIVE_STATE */
138 UFS_PM_LVL_3, /* UFS_SLEEP_PWR_MODE, UIC_LINK_HIBERN8_STATE */
139 UFS_PM_LVL_4, /* UFS_POWERDOWN_PWR_MODE, UIC_LINK_HIBERN8_STATE */
140 UFS_PM_LVL_5, /* UFS_POWERDOWN_PWR_MODE, UIC_LINK_OFF_STATE */
144 struct ufs_pm_lvl_states {
145 enum ufs_dev_pwr_mode dev_state;
146 enum uic_link_state link_state;
150 * struct ufshcd_lrb - local reference block
151 * @utr_descriptor_ptr: UTRD address of the command
152 * @ucd_req_ptr: UCD address of the command
153 * @ucd_rsp_ptr: Response UPIU address for this command
154 * @ucd_prdt_ptr: PRDT address of the command
155 * @cmd: pointer to SCSI command
156 * @sense_buffer: pointer to sense buffer address of the SCSI command
157 * @sense_bufflen: Length of the sense buffer
158 * @scsi_status: SCSI status of the command
159 * @command_type: SCSI, UFS, Query.
160 * @task_tag: Task tag of the command
161 * @lun: LUN of the command
162 * @intr_cmd: Interrupt command (doesn't participate in interrupt aggregation)
165 struct utp_transfer_req_desc *utr_descriptor_ptr;
166 struct utp_upiu_req *ucd_req_ptr;
167 struct utp_upiu_rsp *ucd_rsp_ptr;
168 struct ufshcd_sg_entry *ucd_prdt_ptr;
170 struct scsi_cmnd *cmd;
172 unsigned int sense_bufflen;
177 u8 lun; /* UPIU LUN id field is only 8-bit wide */
182 * struct ufs_query - holds relevant data structures for query request
183 * @request: request upiu and function
184 * @descriptor: buffer for sending/receiving descriptor
185 * @response: response upiu and response
188 struct ufs_query_req request;
190 struct ufs_query_res response;
194 * struct ufs_dev_cmd - all assosiated fields with device management commands
195 * @type: device management command type - Query, NOP OUT
196 * @lock: lock to allow one command at a time
197 * @complete: internal commands completion
198 * @tag_wq: wait queue until free command slot is available
201 enum dev_cmd_type type;
203 struct completion *complete;
204 wait_queue_head_t tag_wq;
205 struct ufs_query query;
208 struct ufs_desc_size {
218 * struct ufs_clk_info - UFS clock related info
219 * @list: list headed by hba->clk_list_head
222 * @max_freq: maximum frequency supported by the clock
223 * @min_freq: min frequency that can be used for clock scaling
224 * @curr_freq: indicates the current frequency that it is set to
225 * @enabled: variable to check against multiple enable/disable
227 struct ufs_clk_info {
228 struct list_head list;
237 enum ufs_notify_change_status {
242 struct ufs_pa_layer_attr {
252 struct ufs_pwr_mode_info {
254 struct ufs_pa_layer_attr info;
258 * struct ufs_hba_variant_ops - variant specific callbacks
259 * @name: variant name
260 * @init: called when the driver is initialized
261 * @exit: called to cleanup everything done in init
262 * @get_ufs_hci_version: called to get UFS HCI version
263 * @clk_scale_notify: notifies that clks are scaled up/down
264 * @setup_clocks: called before touching any of the controller registers
265 * @setup_regulators: called before accessing the host controller
266 * @hce_enable_notify: called before and after HCE enable bit is set to allow
267 * variant specific Uni-Pro initialization.
268 * @link_startup_notify: called before and after Link startup is carried out
269 * to allow variant specific Uni-Pro initialization.
270 * @pwr_change_notify: called before and after a power mode change
271 * is carried out to allow vendor spesific capabilities
273 * @apply_dev_quirks: called to apply device specific quirks
274 * @suspend: called during host controller PM callback
275 * @resume: called during host controller PM callback
276 * @dbg_register_dump: used to dump controller debug information
277 * @phy_initialization: used to initialize phys
279 struct ufs_hba_variant_ops {
281 int (*init)(struct ufs_hba *);
282 void (*exit)(struct ufs_hba *);
283 u32 (*get_ufs_hci_version)(struct ufs_hba *);
284 int (*clk_scale_notify)(struct ufs_hba *, bool,
285 enum ufs_notify_change_status);
286 int (*setup_clocks)(struct ufs_hba *, bool);
287 int (*setup_regulators)(struct ufs_hba *, bool);
288 int (*hce_enable_notify)(struct ufs_hba *,
289 enum ufs_notify_change_status);
290 int (*link_startup_notify)(struct ufs_hba *,
291 enum ufs_notify_change_status);
292 int (*pwr_change_notify)(struct ufs_hba *,
293 enum ufs_notify_change_status status,
294 struct ufs_pa_layer_attr *,
295 struct ufs_pa_layer_attr *);
296 int (*apply_dev_quirks)(struct ufs_hba *);
297 int (*suspend)(struct ufs_hba *, enum ufs_pm_op);
298 int (*resume)(struct ufs_hba *, enum ufs_pm_op);
299 void (*dbg_register_dump)(struct ufs_hba *hba);
300 int (*phy_initialization)(struct ufs_hba *);
303 /* clock gating state */
304 enum clk_gating_state {
312 * struct ufs_clk_gating - UFS clock gating related info
313 * @gate_work: worker to turn off clocks after some delay as specified in
315 * @ungate_work: worker to turn on clocks that will be used in case of
317 * @state: the current clocks state
318 * @delay_ms: gating delay in ms
319 * @is_suspended: clk gating is suspended when set to 1 which can be used
320 * during suspend/resume
321 * @delay_attr: sysfs attribute to control delay_attr
322 * @active_reqs: number of requests that are pending and should be waited for
323 * completion before gating clocks.
325 struct ufs_clk_gating {
326 struct delayed_work gate_work;
327 struct work_struct ungate_work;
328 enum clk_gating_state state;
329 unsigned long delay_ms;
331 struct device_attribute delay_attr;
335 struct ufs_clk_scaling {
336 ktime_t busy_start_t;
337 bool is_busy_started;
338 unsigned long tot_busy_t;
339 unsigned long window_start_t;
343 * struct ufs_init_prefetch - contains data that is pre-fetched once during
345 * @icc_level: icc level which was read during initialization
347 struct ufs_init_prefetch {
352 * struct ufs_hba - per adapter private structure
353 * @mmio_base: UFSHCI base register address
354 * @ucdl_base_addr: UFS Command Descriptor base address
355 * @utrdl_base_addr: UTP Transfer Request Descriptor base address
356 * @utmrdl_base_addr: UTP Task Management Descriptor base address
357 * @ucdl_dma_addr: UFS Command Descriptor DMA address
358 * @utrdl_dma_addr: UTRDL DMA address
359 * @utmrdl_dma_addr: UTMRDL DMA address
360 * @host: Scsi_Host instance of the driver
361 * @dev: device handle
362 * @lrb: local reference block
363 * @lrb_in_use: lrb in use
364 * @outstanding_tasks: Bits representing outstanding task requests
365 * @outstanding_reqs: Bits representing outstanding transfer requests
366 * @capabilities: UFS Controller Capabilities
367 * @nutrs: Transfer Request Queue depth supported by controller
368 * @nutmrs: Task Management Queue depth supported by controller
369 * @ufs_version: UFS Version to which controller complies
370 * @vops: pointer to variant specific operations
371 * @priv: pointer to variant specific private data
372 * @irq: Irq number of the controller
373 * @active_uic_cmd: handle of active UIC command
374 * @uic_cmd_mutex: mutex for uic command
375 * @tm_wq: wait queue for task management
376 * @tm_tag_wq: wait queue for free task management slots
377 * @tm_slots_in_use: bit map of task management request slots in use
378 * @pwr_done: completion for power mode change
379 * @tm_condition: condition variable for task management
380 * @ufshcd_state: UFSHCD states
381 * @eh_flags: Error handling flags
382 * @intr_mask: Interrupt Mask Bits
383 * @ee_ctrl_mask: Exception event control mask
384 * @is_powered: flag to check if HBA is powered
385 * @is_init_prefetch: flag to check if data was pre-fetched in initialization
386 * @init_prefetch_data: data pre-fetched during initialization
387 * @eh_work: Worker to handle UFS errors that require s/w attention
388 * @eeh_work: Worker to handle exception events
389 * @errors: HBA errors
390 * @uic_error: UFS interconnect layer error status
391 * @saved_err: sticky error mask
392 * @saved_uic_err: sticky UIC error mask
393 * @dev_cmd: ufs device management command information
394 * @last_dme_cmd_tstamp: time stamp of the last completed DME command
395 * @auto_bkops_enabled: to track whether bkops is enabled in device
396 * @vreg_info: UFS device voltage regulator information
397 * @clk_list_head: UFS host controller clocks list node head
398 * @pwr_info: holds current power mode
399 * @max_pwr_info: keeps the device max valid pwm
400 * @desc_size: descriptor sizes reported by device
401 * @urgent_bkops_lvl: keeps track of urgent bkops level for device
402 * @is_urgent_bkops_lvl_checked: keeps track if the urgent bkops level for
403 * device is known or not.
406 void __iomem *mmio_base;
408 /* Virtual memory reference */
409 struct utp_transfer_cmd_desc *ucdl_base_addr;
410 struct utp_transfer_req_desc *utrdl_base_addr;
411 struct utp_task_req_desc *utmrdl_base_addr;
413 /* DMA memory reference */
414 dma_addr_t ucdl_dma_addr;
415 dma_addr_t utrdl_dma_addr;
416 dma_addr_t utmrdl_dma_addr;
418 struct Scsi_Host *host;
421 * This field is to keep a reference to "scsi_device" corresponding to
424 struct scsi_device *sdev_ufs_device;
426 enum ufs_dev_pwr_mode curr_dev_pwr_mode;
427 enum uic_link_state uic_link_state;
428 /* Desired UFS power management level during runtime PM */
429 enum ufs_pm_level rpm_lvl;
430 /* Desired UFS power management level during system PM */
431 enum ufs_pm_level spm_lvl;
432 int pm_op_in_progress;
434 struct ufshcd_lrb *lrb;
435 unsigned long lrb_in_use;
437 unsigned long outstanding_tasks;
438 unsigned long outstanding_reqs;
444 struct ufs_hba_variant_ops *vops;
449 /* Interrupt aggregation support is broken */
450 #define UFSHCD_QUIRK_BROKEN_INTR_AGGR UFS_BIT(0)
453 * delay before each dme command is required as the unipro
454 * layer has shown instabilities
456 #define UFSHCD_QUIRK_DELAY_BEFORE_DME_CMDS UFS_BIT(1)
459 * If UFS host controller is having issue in processing LCC (Line
460 * Control Command) coming from device then enable this quirk.
461 * When this quirk is enabled, host controller driver should disable
462 * the LCC transmission on UFS device (by clearing TX_LCC_ENABLE
463 * attribute of device to 0).
465 #define UFSHCD_QUIRK_BROKEN_LCC UFS_BIT(2)
468 * The attribute PA_RXHSUNTERMCAP specifies whether or not the
469 * inbound Link supports unterminated line in HS mode. Setting this
470 * attribute to 1 fixes moving to HS gear.
472 #define UFSHCD_QUIRK_BROKEN_PA_RXHSUNTERMCAP UFS_BIT(3)
475 * This quirk needs to be enabled if the host contoller only allows
476 * accessing the peer dme attributes in AUTO mode (FAST AUTO or
479 #define UFSHCD_QUIRK_DME_PEER_ACCESS_AUTO_MODE UFS_BIT(4)
482 * This quirk needs to be enabled if the host contoller doesn't
483 * advertise the correct version in UFS_VER register. If this quirk
484 * is enabled, standard UFS host driver will call the vendor specific
485 * ops (get_ufs_hci_version) to get the correct version.
487 #define UFSHCD_QUIRK_BROKEN_UFS_HCI_VERSION UFS_BIT(5)
490 * This quirk needs to be enabled if the host contoller regards
491 * resolution of the values of PRDTO and PRDTL in UTRD as byte.
493 #define UFSHCD_QUIRK_PRDT_BYTE_GRAN UFS_BIT(7)
495 unsigned int quirks; /* Deviations from standard UFSHCI spec. */
497 /* Device deviations from standard UFS device spec. */
498 unsigned int dev_quirks;
500 wait_queue_head_t tm_wq;
501 wait_queue_head_t tm_tag_wq;
502 unsigned long tm_condition;
503 unsigned long tm_slots_in_use;
505 struct uic_command *active_uic_cmd;
506 struct mutex uic_cmd_mutex;
507 struct completion *uic_async_done;
514 bool is_init_prefetch;
515 struct ufs_init_prefetch init_prefetch_data;
518 struct work_struct eh_work;
519 struct work_struct eeh_work;
527 /* Device management request data */
528 struct ufs_dev_cmd dev_cmd;
529 ktime_t last_dme_cmd_tstamp;
531 /* Keeps information of the UFS device connected to this host */
532 struct ufs_dev_info dev_info;
533 bool auto_bkops_enabled;
534 struct ufs_vreg_info vreg_info;
535 struct list_head clk_list_head;
537 bool wlun_dev_clr_ua;
539 /* Number of lanes available (1 or 2) for Rx/Tx */
540 u32 lanes_per_direction;
541 struct ufs_pa_layer_attr pwr_info;
542 struct ufs_pwr_mode_info max_pwr_info;
544 struct ufs_clk_gating clk_gating;
545 /* Control to enable/disable host capabilities */
547 /* Allow dynamic clk gating */
548 #define UFSHCD_CAP_CLK_GATING (1 << 0)
549 /* Allow hiberb8 with clk gating */
550 #define UFSHCD_CAP_HIBERN8_WITH_CLK_GATING (1 << 1)
551 /* Allow dynamic clk scaling */
552 #define UFSHCD_CAP_CLK_SCALING (1 << 2)
553 /* Allow auto bkops to enabled during runtime suspend */
554 #define UFSHCD_CAP_AUTO_BKOPS_SUSPEND (1 << 3)
556 * This capability allows host controller driver to use the UFS HCI's
557 * interrupt aggregation capability.
558 * CAUTION: Enabling this might reduce overall UFS throughput.
560 #define UFSHCD_CAP_INTR_AGGR (1 << 4)
562 * This capability allows the device auto-bkops to be always enabled
563 * except during suspend (both runtime and suspend).
564 * Enabling this capability means that device will always be allowed
565 * to do background operation when it's active but it might degrade
566 * the performance of ongoing read/write operations.
568 #define UFSHCD_CAP_KEEP_AUTO_BKOPS_ENABLED_EXCEPT_SUSPEND (1 << 5)
570 struct devfreq *devfreq;
571 struct ufs_clk_scaling clk_scaling;
572 bool is_sys_suspended;
574 enum bkops_status urgent_bkops_lvl;
575 bool is_urgent_bkops_lvl_checked;
577 struct ufs_desc_size desc_size;
580 /* Returns true if clocks can be gated. Otherwise false */
581 static inline bool ufshcd_is_clkgating_allowed(struct ufs_hba *hba)
583 return hba->caps & UFSHCD_CAP_CLK_GATING;
585 static inline bool ufshcd_can_hibern8_during_gating(struct ufs_hba *hba)
587 return hba->caps & UFSHCD_CAP_HIBERN8_WITH_CLK_GATING;
589 static inline int ufshcd_is_clkscaling_enabled(struct ufs_hba *hba)
591 return hba->caps & UFSHCD_CAP_CLK_SCALING;
593 static inline bool ufshcd_can_autobkops_during_suspend(struct ufs_hba *hba)
595 return hba->caps & UFSHCD_CAP_AUTO_BKOPS_SUSPEND;
598 static inline bool ufshcd_is_intr_aggr_allowed(struct ufs_hba *hba)
600 /* DWC UFS Core has the Interrupt aggregation feature but is not detectable*/
601 #ifndef CONFIG_SCSI_UFS_DWC
602 if ((hba->caps & UFSHCD_CAP_INTR_AGGR) &&
603 !(hba->quirks & UFSHCD_QUIRK_BROKEN_INTR_AGGR))
612 #define ufshcd_writel(hba, val, reg) \
613 writel((val), (hba)->mmio_base + (reg))
614 #define ufshcd_readl(hba, reg) \
615 readl((hba)->mmio_base + (reg))
618 * ufshcd_rmwl - read modify write into a register
619 * @hba - per adapter instance
620 * @mask - mask to apply on read value
621 * @val - actual value to write
622 * @reg - register address
624 static inline void ufshcd_rmwl(struct ufs_hba *hba, u32 mask, u32 val, u32 reg)
628 tmp = ufshcd_readl(hba, reg);
631 ufshcd_writel(hba, tmp, reg);
634 int ufshcd_alloc_host(struct device *, struct ufs_hba **);
635 void ufshcd_dealloc_host(struct ufs_hba *);
636 int ufshcd_init(struct ufs_hba * , void __iomem * , unsigned int);
637 void ufshcd_remove(struct ufs_hba *);
638 int ufshcd_wait_for_register(struct ufs_hba *hba, u32 reg, u32 mask,
639 u32 val, unsigned long interval_us,
640 unsigned long timeout_ms, bool can_sleep);
642 static inline void check_upiu_size(void)
644 BUILD_BUG_ON(ALIGNED_UPIU_SIZE <
645 GENERAL_UPIU_REQUEST_SIZE + QUERY_DESC_MAX_SIZE);
649 * ufshcd_set_variant - set variant specific data to the hba
650 * @hba - per adapter instance
651 * @variant - pointer to variant specific data
653 static inline void ufshcd_set_variant(struct ufs_hba *hba, void *variant)
660 * ufshcd_get_variant - get variant specific data from the hba
661 * @hba - per adapter instance
663 static inline void *ufshcd_get_variant(struct ufs_hba *hba)
668 static inline bool ufshcd_keep_autobkops_enabled_except_suspend(
671 return hba->caps & UFSHCD_CAP_KEEP_AUTO_BKOPS_ENABLED_EXCEPT_SUSPEND;
674 extern int ufshcd_runtime_suspend(struct ufs_hba *hba);
675 extern int ufshcd_runtime_resume(struct ufs_hba *hba);
676 extern int ufshcd_runtime_idle(struct ufs_hba *hba);
677 extern int ufshcd_system_suspend(struct ufs_hba *hba);
678 extern int ufshcd_system_resume(struct ufs_hba *hba);
679 extern int ufshcd_shutdown(struct ufs_hba *hba);
680 extern int ufshcd_dme_set_attr(struct ufs_hba *hba, u32 attr_sel,
681 u8 attr_set, u32 mib_val, u8 peer);
682 extern int ufshcd_dme_get_attr(struct ufs_hba *hba, u32 attr_sel,
683 u32 *mib_val, u8 peer);
685 /* UIC command interfaces for DME primitives */
688 #define ATTR_SET_NOR 0 /* NORMAL */
689 #define ATTR_SET_ST 1 /* STATIC */
691 static inline int ufshcd_dme_set(struct ufs_hba *hba, u32 attr_sel,
694 return ufshcd_dme_set_attr(hba, attr_sel, ATTR_SET_NOR,
698 static inline int ufshcd_dme_st_set(struct ufs_hba *hba, u32 attr_sel,
701 return ufshcd_dme_set_attr(hba, attr_sel, ATTR_SET_ST,
705 static inline int ufshcd_dme_peer_set(struct ufs_hba *hba, u32 attr_sel,
708 return ufshcd_dme_set_attr(hba, attr_sel, ATTR_SET_NOR,
712 static inline int ufshcd_dme_peer_st_set(struct ufs_hba *hba, u32 attr_sel,
715 return ufshcd_dme_set_attr(hba, attr_sel, ATTR_SET_ST,
719 static inline int ufshcd_dme_get(struct ufs_hba *hba,
720 u32 attr_sel, u32 *mib_val)
722 return ufshcd_dme_get_attr(hba, attr_sel, mib_val, DME_LOCAL);
725 static inline int ufshcd_dme_peer_get(struct ufs_hba *hba,
726 u32 attr_sel, u32 *mib_val)
728 return ufshcd_dme_get_attr(hba, attr_sel, mib_val, DME_PEER);
731 int ufshcd_read_device_desc(struct ufs_hba *hba, u8 *buf, u32 size);
733 static inline bool ufshcd_is_hs_mode(struct ufs_pa_layer_attr *pwr_info)
735 return (pwr_info->pwr_rx == FAST_MODE ||
736 pwr_info->pwr_rx == FASTAUTO_MODE) &&
737 (pwr_info->pwr_tx == FAST_MODE ||
738 pwr_info->pwr_tx == FASTAUTO_MODE);
741 #define ASCII_STD true
743 int ufshcd_read_string_desc(struct ufs_hba *hba, int desc_index, u8 *buf,
744 u32 size, bool ascii);
746 /* Expose Query-Request API */
747 int ufshcd_query_flag(struct ufs_hba *hba, enum query_opcode opcode,
748 enum flag_idn idn, bool *flag_res);
749 int ufshcd_hold(struct ufs_hba *hba, bool async);
750 void ufshcd_release(struct ufs_hba *hba);
752 int ufshcd_map_desc_id_to_length(struct ufs_hba *hba, enum desc_idn desc_id,
755 u32 ufshcd_get_local_unipro_ver(struct ufs_hba *hba);
757 /* Wrapper functions for safely calling variant operations */
758 static inline const char *ufshcd_get_var_name(struct ufs_hba *hba)
761 return hba->vops->name;
765 static inline int ufshcd_vops_init(struct ufs_hba *hba)
767 if (hba->vops && hba->vops->init)
768 return hba->vops->init(hba);
773 static inline void ufshcd_vops_exit(struct ufs_hba *hba)
775 if (hba->vops && hba->vops->exit)
776 return hba->vops->exit(hba);
779 static inline u32 ufshcd_vops_get_ufs_hci_version(struct ufs_hba *hba)
781 if (hba->vops && hba->vops->get_ufs_hci_version)
782 return hba->vops->get_ufs_hci_version(hba);
784 return ufshcd_readl(hba, REG_UFS_VERSION);
787 static inline int ufshcd_vops_clk_scale_notify(struct ufs_hba *hba,
788 bool up, enum ufs_notify_change_status status)
790 if (hba->vops && hba->vops->clk_scale_notify)
791 return hba->vops->clk_scale_notify(hba, up, status);
795 static inline int ufshcd_vops_setup_clocks(struct ufs_hba *hba, bool on)
797 if (hba->vops && hba->vops->setup_clocks)
798 return hba->vops->setup_clocks(hba, on);
802 static inline int ufshcd_vops_setup_regulators(struct ufs_hba *hba, bool status)
804 if (hba->vops && hba->vops->setup_regulators)
805 return hba->vops->setup_regulators(hba, status);
810 static inline int ufshcd_vops_hce_enable_notify(struct ufs_hba *hba,
813 if (hba->vops && hba->vops->hce_enable_notify)
814 return hba->vops->hce_enable_notify(hba, status);
818 static inline int ufshcd_vops_link_startup_notify(struct ufs_hba *hba,
821 if (hba->vops && hba->vops->link_startup_notify)
822 return hba->vops->link_startup_notify(hba, status);
827 static inline int ufshcd_vops_pwr_change_notify(struct ufs_hba *hba,
829 struct ufs_pa_layer_attr *dev_max_params,
830 struct ufs_pa_layer_attr *dev_req_params)
832 if (hba->vops && hba->vops->pwr_change_notify)
833 return hba->vops->pwr_change_notify(hba, status,
834 dev_max_params, dev_req_params);
839 static inline int ufshcd_vops_apply_dev_quirks(struct ufs_hba *hba)
841 if (hba->vops && hba->vops->apply_dev_quirks)
842 return hba->vops->apply_dev_quirks(hba);
846 static inline int ufshcd_vops_suspend(struct ufs_hba *hba, enum ufs_pm_op op)
848 if (hba->vops && hba->vops->suspend)
849 return hba->vops->suspend(hba, op);
854 static inline int ufshcd_vops_resume(struct ufs_hba *hba, enum ufs_pm_op op)
856 if (hba->vops && hba->vops->resume)
857 return hba->vops->resume(hba, op);
862 static inline void ufshcd_vops_dbg_register_dump(struct ufs_hba *hba)
864 if (hba->vops && hba->vops->dbg_register_dump)
865 hba->vops->dbg_register_dump(hba);
868 #endif /* End of Header */