blob: b7ce12996a192228694cb0d05737d660bb927d94 [file] [log] [blame]
Vinayak Holikattie0eca632013-02-25 21:44:33 +05301/*
2 * Universal Flash Storage Host controller driver
3 *
4 * This code is based on drivers/scsi/ufs/ufshcd.h
5 * Copyright (C) 2011-2013 Samsung India Software Operations
Yaniv Gardidc3c8d32016-02-01 15:02:46 +02006 * Copyright (c) 2013-2016, The Linux Foundation. All rights reserved.
Vinayak Holikattie0eca632013-02-25 21:44:33 +05307 *
8 * Authors:
9 * Santosh Yaraganavi <santosh.sy@samsung.com>
10 * Vinayak Holikatti <h.vinayak@samsung.com>
11 *
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>
18 *
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.
23 *
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
34 * this program.
35 */
36
37#ifndef _UFSHCD_H
38#define _UFSHCD_H
39
40#include <linux/module.h>
41#include <linux/kernel.h>
42#include <linux/init.h>
43#include <linux/interrupt.h>
44#include <linux/io.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>
Seungwon Jeon6ccf44fe2013-06-26 22:39:29 +053055#include <linux/completion.h>
Sujit Reddy Thummaaa497612014-09-25 15:32:22 +030056#include <linux/regulator/consumer.h>
Yaniv Gardif37aabc2016-03-10 17:37:20 +020057#include "unipro.h"
Vinayak Holikattie0eca632013-02-25 21:44:33 +053058
59#include <asm/irq.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>
67
68#include "ufs.h"
69#include "ufshci.h"
70
71#define UFSHCD "ufshcd"
72#define UFSHCD_DRIVER_VERSION "0.2"
73
Sujit Reddy Thumma5c0c28a2014-09-25 15:32:21 +030074struct ufs_hba;
75
Sujit Reddy Thumma5a0b0cb2013-07-30 00:35:57 +053076enum dev_cmd_type {
77 DEV_CMD_TYPE_NOP = 0x0,
Dolev Raviv68078d52013-07-30 00:35:58 +053078 DEV_CMD_TYPE_QUERY = 0x1,
Sujit Reddy Thumma5a0b0cb2013-07-30 00:35:57 +053079};
80
Vinayak Holikattie0eca632013-02-25 21:44:33 +053081/**
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
Seungwon Jeon6ccf44fe2013-06-26 22:39:29 +053089 * @done: UIC command completion
Vinayak Holikattie0eca632013-02-25 21:44:33 +053090 */
91struct uic_command {
92 u32 command;
93 u32 argument1;
94 u32 argument2;
95 u32 argument3;
96 int cmd_active;
97 int result;
Seungwon Jeon6ccf44fe2013-06-26 22:39:29 +053098 struct completion done;
Vinayak Holikattie0eca632013-02-25 21:44:33 +053099};
100
Subhash Jadavani57d104c2014-09-25 15:32:30 +0300101/* Used to differentiate the power management options */
102enum ufs_pm_op {
103 UFS_RUNTIME_PM,
104 UFS_SYSTEM_PM,
105 UFS_SHUTDOWN_PM,
106};
107
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)
111
112/* Host <-> Device UniPro Link state */
113enum 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 */
117};
118
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)
129
130/*
131 * UFS Power management levels.
132 * Each level is in increasing order of power savings.
133 */
134enum ufs_pm_level {
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 */
141 UFS_PM_LVL_MAX
142};
143
144struct ufs_pm_lvl_states {
145 enum ufs_dev_pwr_mode dev_state;
146 enum uic_link_state link_state;
147};
148
Vinayak Holikattie0eca632013-02-25 21:44:33 +0530149/**
150 * struct ufshcd_lrb - local reference block
151 * @utr_descriptor_ptr: UTRD address of the command
Sujit Reddy Thumma5a0b0cb2013-07-30 00:35:57 +0530152 * @ucd_req_ptr: UCD address of the command
Vinayak Holikattie0eca632013-02-25 21:44:33 +0530153 * @ucd_rsp_ptr: Response UPIU address for this command
154 * @ucd_prdt_ptr: PRDT address of the command
Dolev Ravivff8e20c2016-12-22 18:42:18 -0800155 * @utrd_dma_addr: UTRD dma address for debug
156 * @ucd_prdt_dma_addr: PRDT dma address for debug
157 * @ucd_rsp_dma_addr: UPIU response dma address for debug
158 * @ucd_req_dma_addr: UPIU request dma address for debug
Vinayak Holikattie0eca632013-02-25 21:44:33 +0530159 * @cmd: pointer to SCSI command
160 * @sense_buffer: pointer to sense buffer address of the SCSI command
161 * @sense_bufflen: Length of the sense buffer
162 * @scsi_status: SCSI status of the command
163 * @command_type: SCSI, UFS, Query.
164 * @task_tag: Task tag of the command
165 * @lun: LUN of the command
Sujit Reddy Thumma5a0b0cb2013-07-30 00:35:57 +0530166 * @intr_cmd: Interrupt command (doesn't participate in interrupt aggregation)
Dolev Ravivff8e20c2016-12-22 18:42:18 -0800167 * @issue_time_stamp: time stamp for debug purposes
Gilad Bronere0b299e2017-02-03 16:56:40 -0800168 * @req_abort_skip: skip request abort task flag
Vinayak Holikattie0eca632013-02-25 21:44:33 +0530169 */
170struct ufshcd_lrb {
171 struct utp_transfer_req_desc *utr_descriptor_ptr;
Sujit Reddy Thumma5a0b0cb2013-07-30 00:35:57 +0530172 struct utp_upiu_req *ucd_req_ptr;
Vinayak Holikattie0eca632013-02-25 21:44:33 +0530173 struct utp_upiu_rsp *ucd_rsp_ptr;
174 struct ufshcd_sg_entry *ucd_prdt_ptr;
175
Dolev Ravivff8e20c2016-12-22 18:42:18 -0800176 dma_addr_t utrd_dma_addr;
177 dma_addr_t ucd_req_dma_addr;
178 dma_addr_t ucd_rsp_dma_addr;
179 dma_addr_t ucd_prdt_dma_addr;
180
Vinayak Holikattie0eca632013-02-25 21:44:33 +0530181 struct scsi_cmnd *cmd;
182 u8 *sense_buffer;
183 unsigned int sense_bufflen;
184 int scsi_status;
185
186 int command_type;
187 int task_tag;
Subhash Jadavani0ce147d2014-09-25 15:32:29 +0300188 u8 lun; /* UPIU LUN id field is only 8-bit wide */
Sujit Reddy Thumma5a0b0cb2013-07-30 00:35:57 +0530189 bool intr_cmd;
Dolev Ravivff8e20c2016-12-22 18:42:18 -0800190 ktime_t issue_time_stamp;
Gilad Bronere0b299e2017-02-03 16:56:40 -0800191
192 bool req_abort_skip;
Vinayak Holikattie0eca632013-02-25 21:44:33 +0530193};
194
Sujit Reddy Thumma5a0b0cb2013-07-30 00:35:57 +0530195/**
Tomas Winklera230c2f2016-02-09 10:25:41 +0200196 * struct ufs_query - holds relevant data structures for query request
Dolev Raviv68078d52013-07-30 00:35:58 +0530197 * @request: request upiu and function
198 * @descriptor: buffer for sending/receiving descriptor
199 * @response: response upiu and response
200 */
201struct ufs_query {
202 struct ufs_query_req request;
203 u8 *descriptor;
204 struct ufs_query_res response;
205};
206
207/**
Sujit Reddy Thumma5a0b0cb2013-07-30 00:35:57 +0530208 * struct ufs_dev_cmd - all assosiated fields with device management commands
209 * @type: device management command type - Query, NOP OUT
210 * @lock: lock to allow one command at a time
211 * @complete: internal commands completion
212 * @tag_wq: wait queue until free command slot is available
213 */
214struct ufs_dev_cmd {
215 enum dev_cmd_type type;
216 struct mutex lock;
217 struct completion *complete;
218 wait_queue_head_t tag_wq;
Dolev Raviv68078d52013-07-30 00:35:58 +0530219 struct ufs_query query;
Sujit Reddy Thumma5a0b0cb2013-07-30 00:35:57 +0530220};
Vinayak Holikattie0eca632013-02-25 21:44:33 +0530221
Sujit Reddy Thummac6e79da2014-09-25 15:32:23 +0300222/**
223 * struct ufs_clk_info - UFS clock related info
224 * @list: list headed by hba->clk_list_head
225 * @clk: clock node
226 * @name: clock name
227 * @max_freq: maximum frequency supported by the clock
Sahitya Tummala4cff6d992014-09-25 15:32:33 +0300228 * @min_freq: min frequency that can be used for clock scaling
Sahitya Tummala856b3482014-09-25 15:32:34 +0300229 * @curr_freq: indicates the current frequency that it is set to
Sujit Reddy Thummac6e79da2014-09-25 15:32:23 +0300230 * @enabled: variable to check against multiple enable/disable
231 */
232struct ufs_clk_info {
233 struct list_head list;
234 struct clk *clk;
235 const char *name;
236 u32 max_freq;
Sahitya Tummala4cff6d992014-09-25 15:32:33 +0300237 u32 min_freq;
Sahitya Tummala856b3482014-09-25 15:32:34 +0300238 u32 curr_freq;
Sujit Reddy Thummac6e79da2014-09-25 15:32:23 +0300239 bool enabled;
240};
241
Yaniv Gardif06fcc72015-10-28 13:15:51 +0200242enum ufs_notify_change_status {
243 PRE_CHANGE,
244 POST_CHANGE,
245};
Dolev Raviv7eb584d2014-09-25 15:32:31 +0300246
247struct ufs_pa_layer_attr {
248 u32 gear_rx;
249 u32 gear_tx;
250 u32 lane_rx;
251 u32 lane_tx;
252 u32 pwr_rx;
253 u32 pwr_tx;
254 u32 hs_rate;
255};
256
257struct ufs_pwr_mode_info {
258 bool is_valid;
259 struct ufs_pa_layer_attr info;
260};
261
Sujit Reddy Thumma5c0c28a2014-09-25 15:32:21 +0300262/**
263 * struct ufs_hba_variant_ops - variant specific callbacks
264 * @name: variant name
265 * @init: called when the driver is initialized
266 * @exit: called to cleanup everything done in init
Yaniv Gardi9949e702015-05-17 18:55:05 +0300267 * @get_ufs_hci_version: called to get UFS HCI version
Sahitya Tummala856b3482014-09-25 15:32:34 +0300268 * @clk_scale_notify: notifies that clks are scaled up/down
Sujit Reddy Thumma5c0c28a2014-09-25 15:32:21 +0300269 * @setup_clocks: called before touching any of the controller registers
270 * @setup_regulators: called before accessing the host controller
271 * @hce_enable_notify: called before and after HCE enable bit is set to allow
272 * variant specific Uni-Pro initialization.
273 * @link_startup_notify: called before and after Link startup is carried out
274 * to allow variant specific Uni-Pro initialization.
Dolev Raviv7eb584d2014-09-25 15:32:31 +0300275 * @pwr_change_notify: called before and after a power mode change
276 * is carried out to allow vendor spesific capabilities
277 * to be set.
Kiwoong Kim0e675ef2016-11-10 21:14:36 +0900278 * @setup_xfer_req: called before any transfer request is issued
279 * to set some things
Kiwoong Kimd2877be2016-11-10 21:16:15 +0900280 * @setup_task_mgmt: called before any task management request is issued
281 * to set some things
Kiwoong Kimee32c902016-11-10 21:17:43 +0900282 * @hibern8_notify: called around hibern8 enter/exit
Subhash Jadavani56d4a182016-12-05 19:25:32 -0800283 * @apply_dev_quirks: called to apply device specific quirks
Subhash Jadavani57d104c2014-09-25 15:32:30 +0300284 * @suspend: called during host controller PM callback
285 * @resume: called during host controller PM callback
Yaniv Gardi6e3fd442015-10-28 13:15:50 +0200286 * @dbg_register_dump: used to dump controller debug information
Joao Pinto4b9ffb52016-05-11 12:21:30 +0100287 * @phy_initialization: used to initialize phys
Sujit Reddy Thumma5c0c28a2014-09-25 15:32:21 +0300288 */
289struct ufs_hba_variant_ops {
290 const char *name;
291 int (*init)(struct ufs_hba *);
292 void (*exit)(struct ufs_hba *);
Yaniv Gardi9949e702015-05-17 18:55:05 +0300293 u32 (*get_ufs_hci_version)(struct ufs_hba *);
Yaniv Gardif06fcc72015-10-28 13:15:51 +0200294 int (*clk_scale_notify)(struct ufs_hba *, bool,
295 enum ufs_notify_change_status);
Subhash Jadavani1e879e82016-10-06 21:48:22 -0700296 int (*setup_clocks)(struct ufs_hba *, bool,
297 enum ufs_notify_change_status);
Sujit Reddy Thumma5c0c28a2014-09-25 15:32:21 +0300298 int (*setup_regulators)(struct ufs_hba *, bool);
Yaniv Gardif06fcc72015-10-28 13:15:51 +0200299 int (*hce_enable_notify)(struct ufs_hba *,
300 enum ufs_notify_change_status);
301 int (*link_startup_notify)(struct ufs_hba *,
302 enum ufs_notify_change_status);
Dolev Raviv7eb584d2014-09-25 15:32:31 +0300303 int (*pwr_change_notify)(struct ufs_hba *,
Yaniv Gardif06fcc72015-10-28 13:15:51 +0200304 enum ufs_notify_change_status status,
305 struct ufs_pa_layer_attr *,
Dolev Raviv7eb584d2014-09-25 15:32:31 +0300306 struct ufs_pa_layer_attr *);
Kiwoong Kim0e675ef2016-11-10 21:14:36 +0900307 void (*setup_xfer_req)(struct ufs_hba *, int, bool);
Kiwoong Kimd2877be2016-11-10 21:16:15 +0900308 void (*setup_task_mgmt)(struct ufs_hba *, int, u8);
Kiwoong Kimee32c902016-11-10 21:17:43 +0900309 void (*hibern8_notify)(struct ufs_hba *, enum uic_cmd_dme,
Subhash Jadavani56d4a182016-12-05 19:25:32 -0800310 enum ufs_notify_change_status);
311 int (*apply_dev_quirks)(struct ufs_hba *);
Subhash Jadavani57d104c2014-09-25 15:32:30 +0300312 int (*suspend)(struct ufs_hba *, enum ufs_pm_op);
313 int (*resume)(struct ufs_hba *, enum ufs_pm_op);
Yaniv Gardi6e3fd442015-10-28 13:15:50 +0200314 void (*dbg_register_dump)(struct ufs_hba *hba);
Joao Pinto4b9ffb52016-05-11 12:21:30 +0100315 int (*phy_initialization)(struct ufs_hba *);
Sujit Reddy Thumma5c0c28a2014-09-25 15:32:21 +0300316};
317
Sahitya Tummala1ab27c92014-09-25 15:32:32 +0300318/* clock gating state */
319enum clk_gating_state {
320 CLKS_OFF,
321 CLKS_ON,
322 REQ_CLKS_OFF,
323 REQ_CLKS_ON,
324};
325
326/**
327 * struct ufs_clk_gating - UFS clock gating related info
328 * @gate_work: worker to turn off clocks after some delay as specified in
329 * delay_ms
330 * @ungate_work: worker to turn on clocks that will be used in case of
331 * interrupt context
332 * @state: the current clocks state
333 * @delay_ms: gating delay in ms
334 * @is_suspended: clk gating is suspended when set to 1 which can be used
335 * during suspend/resume
336 * @delay_attr: sysfs attribute to control delay_attr
Sahitya Tummalab4274112016-12-22 18:40:39 -0800337 * @enable_attr: sysfs attribute to enable/disable clock gating
338 * @is_enabled: Indicates the current status of clock gating
Sahitya Tummala1ab27c92014-09-25 15:32:32 +0300339 * @active_reqs: number of requests that are pending and should be waited for
340 * completion before gating clocks.
341 */
342struct ufs_clk_gating {
343 struct delayed_work gate_work;
344 struct work_struct ungate_work;
345 enum clk_gating_state state;
346 unsigned long delay_ms;
347 bool is_suspended;
348 struct device_attribute delay_attr;
Sahitya Tummalab4274112016-12-22 18:40:39 -0800349 struct device_attribute enable_attr;
350 bool is_enabled;
Sahitya Tummala1ab27c92014-09-25 15:32:32 +0300351 int active_reqs;
352};
353
Sahitya Tummala856b3482014-09-25 15:32:34 +0300354struct ufs_clk_scaling {
355 ktime_t busy_start_t;
356 bool is_busy_started;
357 unsigned long tot_busy_t;
358 unsigned long window_start_t;
Sahitya Tummalafcb0c4b2016-12-22 18:40:50 -0800359 struct device_attribute enable_attr;
360 bool is_allowed;
Sahitya Tummala856b3482014-09-25 15:32:34 +0300361};
362
Vinayak Holikattie0eca632013-02-25 21:44:33 +0530363/**
Yaniv Gardi3a4bf062014-09-25 15:32:27 +0300364 * struct ufs_init_prefetch - contains data that is pre-fetched once during
365 * initialization
366 * @icc_level: icc level which was read during initialization
367 */
368struct ufs_init_prefetch {
369 u32 icc_level;
370};
371
Dolev Ravivff8e20c2016-12-22 18:42:18 -0800372#define UIC_ERR_REG_HIST_LENGTH 8
373/**
374 * struct ufs_uic_err_reg_hist - keeps history of uic errors
375 * @pos: index to indicate cyclic buffer position
376 * @reg: cyclic buffer for registers value
377 * @tstamp: cyclic buffer for time stamp
378 */
379struct ufs_uic_err_reg_hist {
380 int pos;
381 u32 reg[UIC_ERR_REG_HIST_LENGTH];
382 ktime_t tstamp[UIC_ERR_REG_HIST_LENGTH];
383};
384
385/**
386 * struct ufs_stats - keeps usage/err statistics
387 * @hibern8_exit_cnt: Counter to keep track of number of exits,
388 * reset this after link-startup.
389 * @last_hibern8_exit_tstamp: Set time after the hibern8 exit.
390 * Clear after the first successful command completion.
391 * @pa_err: tracks pa-uic errors
392 * @dl_err: tracks dl-uic errors
393 * @nl_err: tracks nl-uic errors
394 * @tl_err: tracks tl-uic errors
395 * @dme_err: tracks dme errors
396 */
397struct ufs_stats {
398 u32 hibern8_exit_cnt;
399 ktime_t last_hibern8_exit_tstamp;
400 struct ufs_uic_err_reg_hist pa_err;
401 struct ufs_uic_err_reg_hist dl_err;
402 struct ufs_uic_err_reg_hist nl_err;
403 struct ufs_uic_err_reg_hist tl_err;
404 struct ufs_uic_err_reg_hist dme_err;
405};
406
Yaniv Gardi3a4bf062014-09-25 15:32:27 +0300407/**
Vinayak Holikattie0eca632013-02-25 21:44:33 +0530408 * struct ufs_hba - per adapter private structure
409 * @mmio_base: UFSHCI base register address
410 * @ucdl_base_addr: UFS Command Descriptor base address
411 * @utrdl_base_addr: UTP Transfer Request Descriptor base address
412 * @utmrdl_base_addr: UTP Task Management Descriptor base address
413 * @ucdl_dma_addr: UFS Command Descriptor DMA address
414 * @utrdl_dma_addr: UTRDL DMA address
415 * @utmrdl_dma_addr: UTMRDL DMA address
416 * @host: Scsi_Host instance of the driver
417 * @dev: device handle
418 * @lrb: local reference block
Sujit Reddy Thumma5a0b0cb2013-07-30 00:35:57 +0530419 * @lrb_in_use: lrb in use
Vinayak Holikattie0eca632013-02-25 21:44:33 +0530420 * @outstanding_tasks: Bits representing outstanding task requests
421 * @outstanding_reqs: Bits representing outstanding transfer requests
422 * @capabilities: UFS Controller Capabilities
423 * @nutrs: Transfer Request Queue depth supported by controller
424 * @nutmrs: Task Management Queue depth supported by controller
425 * @ufs_version: UFS Version to which controller complies
Sujit Reddy Thumma5c0c28a2014-09-25 15:32:21 +0300426 * @vops: pointer to variant specific operations
427 * @priv: pointer to variant specific private data
Vinayak Holikattie0eca632013-02-25 21:44:33 +0530428 * @irq: Irq number of the controller
429 * @active_uic_cmd: handle of active UIC command
Seungwon Jeon6ccf44fe2013-06-26 22:39:29 +0530430 * @uic_cmd_mutex: mutex for uic command
Sujit Reddy Thummae2933132014-05-26 10:59:12 +0530431 * @tm_wq: wait queue for task management
432 * @tm_tag_wq: wait queue for free task management slots
433 * @tm_slots_in_use: bit map of task management request slots in use
Seungwon Jeon53b3d9c2013-08-31 21:40:22 +0530434 * @pwr_done: completion for power mode change
Vinayak Holikattie0eca632013-02-25 21:44:33 +0530435 * @tm_condition: condition variable for task management
436 * @ufshcd_state: UFSHCD states
Sujit Reddy Thumma3441da72014-05-26 10:59:14 +0530437 * @eh_flags: Error handling flags
Seungwon Jeon2fbd0092013-06-26 22:39:27 +0530438 * @intr_mask: Interrupt Mask Bits
Sujit Reddy Thumma66ec6d52013-07-30 00:35:59 +0530439 * @ee_ctrl_mask: Exception event control mask
Sujit Reddy Thumma1d337ec2014-09-25 15:32:26 +0300440 * @is_powered: flag to check if HBA is powered
Yaniv Gardi3a4bf062014-09-25 15:32:27 +0300441 * @is_init_prefetch: flag to check if data was pre-fetched in initialization
442 * @init_prefetch_data: data pre-fetched during initialization
Sujit Reddy Thummae8e7f272014-05-26 10:59:15 +0530443 * @eh_work: Worker to handle UFS errors that require s/w attention
Sujit Reddy Thumma66ec6d52013-07-30 00:35:59 +0530444 * @eeh_work: Worker to handle exception events
Vinayak Holikattie0eca632013-02-25 21:44:33 +0530445 * @errors: HBA errors
Sujit Reddy Thummae8e7f272014-05-26 10:59:15 +0530446 * @uic_error: UFS interconnect layer error status
447 * @saved_err: sticky error mask
448 * @saved_uic_err: sticky UIC error mask
Sujit Reddy Thumma5a0b0cb2013-07-30 00:35:57 +0530449 * @dev_cmd: ufs device management command information
Yaniv Gardicad2e032015-03-31 17:37:14 +0300450 * @last_dme_cmd_tstamp: time stamp of the last completed DME command
Sujit Reddy Thumma66ec6d52013-07-30 00:35:59 +0530451 * @auto_bkops_enabled: to track whether bkops is enabled in device
Sujit Reddy Thummaaa497612014-09-25 15:32:22 +0300452 * @vreg_info: UFS device voltage regulator information
Sujit Reddy Thummac6e79da2014-09-25 15:32:23 +0300453 * @clk_list_head: UFS host controller clocks list node head
Dolev Raviv7eb584d2014-09-25 15:32:31 +0300454 * @pwr_info: holds current power mode
455 * @max_pwr_info: keeps the device max valid pwm
Yaniv Gardiafdfff52016-03-10 17:37:15 +0200456 * @urgent_bkops_lvl: keeps track of urgent bkops level for device
457 * @is_urgent_bkops_lvl_checked: keeps track if the urgent bkops level for
458 * device is known or not.
Vinayak Holikattie0eca632013-02-25 21:44:33 +0530459 */
460struct ufs_hba {
461 void __iomem *mmio_base;
462
463 /* Virtual memory reference */
464 struct utp_transfer_cmd_desc *ucdl_base_addr;
465 struct utp_transfer_req_desc *utrdl_base_addr;
466 struct utp_task_req_desc *utmrdl_base_addr;
467
468 /* DMA memory reference */
469 dma_addr_t ucdl_dma_addr;
470 dma_addr_t utrdl_dma_addr;
471 dma_addr_t utmrdl_dma_addr;
472
473 struct Scsi_Host *host;
474 struct device *dev;
Subhash Jadavani2a8fa602014-09-25 15:32:28 +0300475 /*
476 * This field is to keep a reference to "scsi_device" corresponding to
477 * "UFS device" W-LU.
478 */
479 struct scsi_device *sdev_ufs_device;
Vinayak Holikattie0eca632013-02-25 21:44:33 +0530480
Subhash Jadavani57d104c2014-09-25 15:32:30 +0300481 enum ufs_dev_pwr_mode curr_dev_pwr_mode;
482 enum uic_link_state uic_link_state;
483 /* Desired UFS power management level during runtime PM */
484 enum ufs_pm_level rpm_lvl;
485 /* Desired UFS power management level during system PM */
486 enum ufs_pm_level spm_lvl;
subhashj@codeaurora.org09690d52016-12-22 18:41:00 -0800487 struct device_attribute rpm_lvl_attr;
488 struct device_attribute spm_lvl_attr;
Subhash Jadavani57d104c2014-09-25 15:32:30 +0300489 int pm_op_in_progress;
490
Vinayak Holikattie0eca632013-02-25 21:44:33 +0530491 struct ufshcd_lrb *lrb;
Sujit Reddy Thumma5a0b0cb2013-07-30 00:35:57 +0530492 unsigned long lrb_in_use;
Vinayak Holikattie0eca632013-02-25 21:44:33 +0530493
494 unsigned long outstanding_tasks;
495 unsigned long outstanding_reqs;
496
497 u32 capabilities;
498 int nutrs;
499 int nutmrs;
500 u32 ufs_version;
Sujit Reddy Thumma5c0c28a2014-09-25 15:32:21 +0300501 struct ufs_hba_variant_ops *vops;
502 void *priv;
Vinayak Holikattie0eca632013-02-25 21:44:33 +0530503 unsigned int irq;
Subhash Jadavani57d104c2014-09-25 15:32:30 +0300504 bool is_irq_enabled;
Vinayak Holikattie0eca632013-02-25 21:44:33 +0530505
Yaniv Gardib8521902015-05-17 18:54:57 +0300506 /* Interrupt aggregation support is broken */
507 #define UFSHCD_QUIRK_BROKEN_INTR_AGGR UFS_BIT(0)
508
Yaniv Gardicad2e032015-03-31 17:37:14 +0300509 /*
510 * delay before each dme command is required as the unipro
511 * layer has shown instabilities
512 */
Yaniv Gardib8521902015-05-17 18:54:57 +0300513 #define UFSHCD_QUIRK_DELAY_BEFORE_DME_CMDS UFS_BIT(1)
514
Yaniv Gardi7ca38cf2015-05-17 18:54:59 +0300515 /*
516 * If UFS host controller is having issue in processing LCC (Line
517 * Control Command) coming from device then enable this quirk.
518 * When this quirk is enabled, host controller driver should disable
519 * the LCC transmission on UFS device (by clearing TX_LCC_ENABLE
520 * attribute of device to 0).
521 */
522 #define UFSHCD_QUIRK_BROKEN_LCC UFS_BIT(2)
Yaniv Gardicad2e032015-03-31 17:37:14 +0300523
Yaniv Gardic3a2f9e2015-05-17 18:55:01 +0300524 /*
525 * The attribute PA_RXHSUNTERMCAP specifies whether or not the
526 * inbound Link supports unterminated line in HS mode. Setting this
527 * attribute to 1 fixes moving to HS gear.
528 */
529 #define UFSHCD_QUIRK_BROKEN_PA_RXHSUNTERMCAP UFS_BIT(3)
530
Yaniv Gardi874237f2015-05-17 18:55:03 +0300531 /*
532 * This quirk needs to be enabled if the host contoller only allows
533 * accessing the peer dme attributes in AUTO mode (FAST AUTO or
534 * SLOW AUTO).
535 */
536 #define UFSHCD_QUIRK_DME_PEER_ACCESS_AUTO_MODE UFS_BIT(4)
537
Yaniv Gardi9949e702015-05-17 18:55:05 +0300538 /*
539 * This quirk needs to be enabled if the host contoller doesn't
540 * advertise the correct version in UFS_VER register. If this quirk
541 * is enabled, standard UFS host driver will call the vendor specific
542 * ops (get_ufs_hci_version) to get the correct version.
543 */
544 #define UFSHCD_QUIRK_BROKEN_UFS_HCI_VERSION UFS_BIT(5)
545
Kiwoong Kim75b1cc42016-11-22 17:06:59 +0900546 /*
547 * This quirk needs to be enabled if the host contoller regards
548 * resolution of the values of PRDTO and PRDTL in UTRD as byte.
549 */
550 #define UFSHCD_QUIRK_PRDT_BYTE_GRAN UFS_BIT(7)
551
Yaniv Gardicad2e032015-03-31 17:37:14 +0300552 unsigned int quirks; /* Deviations from standard UFSHCI spec. */
Seungwon Jeon6ccf44fe2013-06-26 22:39:29 +0530553
Yaniv Gardic58ab7a2016-03-10 17:37:10 +0200554 /* Device deviations from standard UFS device spec. */
555 unsigned int dev_quirks;
556
Sujit Reddy Thummae2933132014-05-26 10:59:12 +0530557 wait_queue_head_t tm_wq;
558 wait_queue_head_t tm_tag_wq;
Vinayak Holikattie0eca632013-02-25 21:44:33 +0530559 unsigned long tm_condition;
Sujit Reddy Thummae2933132014-05-26 10:59:12 +0530560 unsigned long tm_slots_in_use;
Vinayak Holikattie0eca632013-02-25 21:44:33 +0530561
Subhash Jadavani57d104c2014-09-25 15:32:30 +0300562 struct uic_command *active_uic_cmd;
563 struct mutex uic_cmd_mutex;
564 struct completion *uic_async_done;
Seungwon Jeon53b3d9c2013-08-31 21:40:22 +0530565
Vinayak Holikattie0eca632013-02-25 21:44:33 +0530566 u32 ufshcd_state;
Sujit Reddy Thumma3441da72014-05-26 10:59:14 +0530567 u32 eh_flags;
Seungwon Jeon2fbd0092013-06-26 22:39:27 +0530568 u32 intr_mask;
Sujit Reddy Thumma66ec6d52013-07-30 00:35:59 +0530569 u16 ee_ctrl_mask;
Sujit Reddy Thumma1d337ec2014-09-25 15:32:26 +0300570 bool is_powered;
Yaniv Gardi3a4bf062014-09-25 15:32:27 +0300571 bool is_init_prefetch;
572 struct ufs_init_prefetch init_prefetch_data;
Vinayak Holikattie0eca632013-02-25 21:44:33 +0530573
574 /* Work Queues */
Sujit Reddy Thummae8e7f272014-05-26 10:59:15 +0530575 struct work_struct eh_work;
Sujit Reddy Thumma66ec6d52013-07-30 00:35:59 +0530576 struct work_struct eeh_work;
Vinayak Holikattie0eca632013-02-25 21:44:33 +0530577
578 /* HBA Errors */
579 u32 errors;
Sujit Reddy Thummae8e7f272014-05-26 10:59:15 +0530580 u32 uic_error;
581 u32 saved_err;
582 u32 saved_uic_err;
Dolev Ravivff8e20c2016-12-22 18:42:18 -0800583 struct ufs_stats ufs_stats;
Sujit Reddy Thumma5a0b0cb2013-07-30 00:35:57 +0530584
585 /* Device management request data */
586 struct ufs_dev_cmd dev_cmd;
Yaniv Gardicad2e032015-03-31 17:37:14 +0300587 ktime_t last_dme_cmd_tstamp;
Sujit Reddy Thumma66ec6d52013-07-30 00:35:59 +0530588
Subhash Jadavani57d104c2014-09-25 15:32:30 +0300589 /* Keeps information of the UFS device connected to this host */
590 struct ufs_dev_info dev_info;
Sujit Reddy Thumma66ec6d52013-07-30 00:35:59 +0530591 bool auto_bkops_enabled;
Sujit Reddy Thummaaa497612014-09-25 15:32:22 +0300592 struct ufs_vreg_info vreg_info;
Sujit Reddy Thummac6e79da2014-09-25 15:32:23 +0300593 struct list_head clk_list_head;
Subhash Jadavani57d104c2014-09-25 15:32:30 +0300594
595 bool wlun_dev_clr_ua;
Dolev Raviv7eb584d2014-09-25 15:32:31 +0300596
Gilad Broner7fabb772017-02-03 16:56:50 -0800597 /* Number of requests aborts */
598 int req_abort_count;
599
Yaniv Gardi54b879b2016-03-10 17:37:05 +0200600 /* Number of lanes available (1 or 2) for Rx/Tx */
601 u32 lanes_per_direction;
Dolev Raviv7eb584d2014-09-25 15:32:31 +0300602 struct ufs_pa_layer_attr pwr_info;
603 struct ufs_pwr_mode_info max_pwr_info;
Sahitya Tummala1ab27c92014-09-25 15:32:32 +0300604
605 struct ufs_clk_gating clk_gating;
606 /* Control to enable/disable host capabilities */
607 u32 caps;
608 /* Allow dynamic clk gating */
609#define UFSHCD_CAP_CLK_GATING (1 << 0)
610 /* Allow hiberb8 with clk gating */
611#define UFSHCD_CAP_HIBERN8_WITH_CLK_GATING (1 << 1)
Sahitya Tummala856b3482014-09-25 15:32:34 +0300612 /* Allow dynamic clk scaling */
613#define UFSHCD_CAP_CLK_SCALING (1 << 2)
Subhash Jadavani374a2462014-09-25 15:32:35 +0300614 /* Allow auto bkops to enabled during runtime suspend */
615#define UFSHCD_CAP_AUTO_BKOPS_SUSPEND (1 << 3)
Yaniv Gardib8521902015-05-17 18:54:57 +0300616 /*
617 * This capability allows host controller driver to use the UFS HCI's
618 * interrupt aggregation capability.
619 * CAUTION: Enabling this might reduce overall UFS throughput.
620 */
621#define UFSHCD_CAP_INTR_AGGR (1 << 4)
subhashj@codeaurora.org4e768e72016-12-22 18:41:22 -0800622 /*
623 * This capability allows the device auto-bkops to be always enabled
624 * except during suspend (both runtime and suspend).
625 * Enabling this capability means that device will always be allowed
626 * to do background operation when it's active but it might degrade
627 * the performance of ongoing read/write operations.
628 */
629#define UFSHCD_CAP_KEEP_AUTO_BKOPS_ENABLED_EXCEPT_SUSPEND (1 << 5)
Sahitya Tummala856b3482014-09-25 15:32:34 +0300630
631 struct devfreq *devfreq;
632 struct ufs_clk_scaling clk_scaling;
Dolev Ravive7850602014-09-25 15:32:36 +0300633 bool is_sys_suspended;
Yaniv Gardiafdfff52016-03-10 17:37:15 +0200634
635 enum bkops_status urgent_bkops_lvl;
636 bool is_urgent_bkops_lvl_checked;
Vinayak Holikattie0eca632013-02-25 21:44:33 +0530637};
638
Sahitya Tummala1ab27c92014-09-25 15:32:32 +0300639/* Returns true if clocks can be gated. Otherwise false */
640static inline bool ufshcd_is_clkgating_allowed(struct ufs_hba *hba)
641{
642 return hba->caps & UFSHCD_CAP_CLK_GATING;
643}
644static inline bool ufshcd_can_hibern8_during_gating(struct ufs_hba *hba)
645{
646 return hba->caps & UFSHCD_CAP_HIBERN8_WITH_CLK_GATING;
647}
Sahitya Tummalafcb0c4b2016-12-22 18:40:50 -0800648static inline int ufshcd_is_clkscaling_supported(struct ufs_hba *hba)
Sahitya Tummala856b3482014-09-25 15:32:34 +0300649{
650 return hba->caps & UFSHCD_CAP_CLK_SCALING;
651}
Subhash Jadavani374a2462014-09-25 15:32:35 +0300652static inline bool ufshcd_can_autobkops_during_suspend(struct ufs_hba *hba)
653{
654 return hba->caps & UFSHCD_CAP_AUTO_BKOPS_SUSPEND;
655}
656
Yaniv Gardib8521902015-05-17 18:54:57 +0300657static inline bool ufshcd_is_intr_aggr_allowed(struct ufs_hba *hba)
658{
Joao Pinto4b9ffb52016-05-11 12:21:30 +0100659/* DWC UFS Core has the Interrupt aggregation feature but is not detectable*/
660#ifndef CONFIG_SCSI_UFS_DWC
Yaniv Gardib8521902015-05-17 18:54:57 +0300661 if ((hba->caps & UFSHCD_CAP_INTR_AGGR) &&
662 !(hba->quirks & UFSHCD_QUIRK_BROKEN_INTR_AGGR))
663 return true;
664 else
665 return false;
Joao Pinto4b9ffb52016-05-11 12:21:30 +0100666#else
667return true;
668#endif
Yaniv Gardib8521902015-05-17 18:54:57 +0300669}
670
Seungwon Jeonb873a2752013-06-26 22:39:26 +0530671#define ufshcd_writel(hba, val, reg) \
672 writel((val), (hba)->mmio_base + (reg))
673#define ufshcd_readl(hba, reg) \
674 readl((hba)->mmio_base + (reg))
675
Dolev Ravive7850602014-09-25 15:32:36 +0300676/**
677 * ufshcd_rmwl - read modify write into a register
678 * @hba - per adapter instance
679 * @mask - mask to apply on read value
680 * @val - actual value to write
681 * @reg - register address
682 */
683static inline void ufshcd_rmwl(struct ufs_hba *hba, u32 mask, u32 val, u32 reg)
684{
685 u32 tmp;
686
687 tmp = ufshcd_readl(hba, reg);
688 tmp &= ~mask;
689 tmp |= (val & mask);
690 ufshcd_writel(hba, tmp, reg);
691}
692
Sujit Reddy Thumma5c0c28a2014-09-25 15:32:21 +0300693int ufshcd_alloc_host(struct device *, struct ufs_hba **);
Yaniv Gardi47555a52015-10-28 13:15:49 +0200694void ufshcd_dealloc_host(struct ufs_hba *);
Sujit Reddy Thumma5c0c28a2014-09-25 15:32:21 +0300695int ufshcd_init(struct ufs_hba * , void __iomem * , unsigned int);
Vinayak Holikattie0eca632013-02-25 21:44:33 +0530696void ufshcd_remove(struct ufs_hba *);
Yaniv Gardi596585a2016-03-10 17:37:08 +0200697int ufshcd_wait_for_register(struct ufs_hba *hba, u32 reg, u32 mask,
698 u32 val, unsigned long interval_us,
699 unsigned long timeout_ms, bool can_sleep);
Vinayak Holikattie0eca632013-02-25 21:44:33 +0530700
Dolev Raviv68078d52013-07-30 00:35:58 +0530701static inline void check_upiu_size(void)
702{
703 BUILD_BUG_ON(ALIGNED_UPIU_SIZE <
704 GENERAL_UPIU_REQUEST_SIZE + QUERY_DESC_MAX_SIZE);
705}
706
Yaniv Gardi1ce58982015-10-28 13:15:47 +0200707/**
708 * ufshcd_set_variant - set variant specific data to the hba
709 * @hba - per adapter instance
710 * @variant - pointer to variant specific data
711 */
712static inline void ufshcd_set_variant(struct ufs_hba *hba, void *variant)
713{
714 BUG_ON(!hba);
715 hba->priv = variant;
716}
717
718/**
719 * ufshcd_get_variant - get variant specific data from the hba
720 * @hba - per adapter instance
721 */
722static inline void *ufshcd_get_variant(struct ufs_hba *hba)
723{
724 BUG_ON(!hba);
725 return hba->priv;
726}
subhashj@codeaurora.org4e768e72016-12-22 18:41:22 -0800727static inline bool ufshcd_keep_autobkops_enabled_except_suspend(
728 struct ufs_hba *hba)
729{
730 return hba->caps & UFSHCD_CAP_KEEP_AUTO_BKOPS_ENABLED_EXCEPT_SUSPEND;
731}
Yaniv Gardi1ce58982015-10-28 13:15:47 +0200732
Sujit Reddy Thumma66ec6d52013-07-30 00:35:59 +0530733extern int ufshcd_runtime_suspend(struct ufs_hba *hba);
734extern int ufshcd_runtime_resume(struct ufs_hba *hba);
735extern int ufshcd_runtime_idle(struct ufs_hba *hba);
Subhash Jadavani57d104c2014-09-25 15:32:30 +0300736extern int ufshcd_system_suspend(struct ufs_hba *hba);
737extern int ufshcd_system_resume(struct ufs_hba *hba);
738extern int ufshcd_shutdown(struct ufs_hba *hba);
Seungwon Jeon12b4fdb2013-08-31 21:40:21 +0530739extern int ufshcd_dme_set_attr(struct ufs_hba *hba, u32 attr_sel,
740 u8 attr_set, u32 mib_val, u8 peer);
741extern int ufshcd_dme_get_attr(struct ufs_hba *hba, u32 attr_sel,
742 u32 *mib_val, u8 peer);
743
744/* UIC command interfaces for DME primitives */
745#define DME_LOCAL 0
746#define DME_PEER 1
747#define ATTR_SET_NOR 0 /* NORMAL */
748#define ATTR_SET_ST 1 /* STATIC */
749
750static inline int ufshcd_dme_set(struct ufs_hba *hba, u32 attr_sel,
751 u32 mib_val)
752{
753 return ufshcd_dme_set_attr(hba, attr_sel, ATTR_SET_NOR,
754 mib_val, DME_LOCAL);
755}
756
757static inline int ufshcd_dme_st_set(struct ufs_hba *hba, u32 attr_sel,
758 u32 mib_val)
759{
760 return ufshcd_dme_set_attr(hba, attr_sel, ATTR_SET_ST,
761 mib_val, DME_LOCAL);
762}
763
764static inline int ufshcd_dme_peer_set(struct ufs_hba *hba, u32 attr_sel,
765 u32 mib_val)
766{
767 return ufshcd_dme_set_attr(hba, attr_sel, ATTR_SET_NOR,
768 mib_val, DME_PEER);
769}
770
771static inline int ufshcd_dme_peer_st_set(struct ufs_hba *hba, u32 attr_sel,
772 u32 mib_val)
773{
774 return ufshcd_dme_set_attr(hba, attr_sel, ATTR_SET_ST,
775 mib_val, DME_PEER);
776}
777
778static inline int ufshcd_dme_get(struct ufs_hba *hba,
779 u32 attr_sel, u32 *mib_val)
780{
781 return ufshcd_dme_get_attr(hba, attr_sel, mib_val, DME_LOCAL);
782}
783
784static inline int ufshcd_dme_peer_get(struct ufs_hba *hba,
785 u32 attr_sel, u32 *mib_val)
786{
787 return ufshcd_dme_get_attr(hba, attr_sel, mib_val, DME_PEER);
788}
789
Yaniv Gardif37aabc2016-03-10 17:37:20 +0200790static inline bool ufshcd_is_hs_mode(struct ufs_pa_layer_attr *pwr_info)
791{
792 return (pwr_info->pwr_rx == FAST_MODE ||
793 pwr_info->pwr_rx == FASTAUTO_MODE) &&
794 (pwr_info->pwr_tx == FAST_MODE ||
795 pwr_info->pwr_tx == FASTAUTO_MODE);
796}
797
Yaniv Gardidc3c8d32016-02-01 15:02:46 +0200798/* Expose Query-Request API */
799int ufshcd_query_flag(struct ufs_hba *hba, enum query_opcode opcode,
800 enum flag_idn idn, bool *flag_res);
Sahitya Tummala1ab27c92014-09-25 15:32:32 +0300801int ufshcd_hold(struct ufs_hba *hba, bool async);
802void ufshcd_release(struct ufs_hba *hba);
Yaniv Gardi37113102016-03-10 17:37:16 +0200803u32 ufshcd_get_local_unipro_ver(struct ufs_hba *hba);
Yaniv Gardi0263bcd2015-10-28 13:15:48 +0200804
805/* Wrapper functions for safely calling variant operations */
806static inline const char *ufshcd_get_var_name(struct ufs_hba *hba)
807{
808 if (hba->vops)
809 return hba->vops->name;
810 return "";
811}
812
813static inline int ufshcd_vops_init(struct ufs_hba *hba)
814{
815 if (hba->vops && hba->vops->init)
816 return hba->vops->init(hba);
817
818 return 0;
819}
820
821static inline void ufshcd_vops_exit(struct ufs_hba *hba)
822{
823 if (hba->vops && hba->vops->exit)
824 return hba->vops->exit(hba);
825}
826
827static inline u32 ufshcd_vops_get_ufs_hci_version(struct ufs_hba *hba)
828{
829 if (hba->vops && hba->vops->get_ufs_hci_version)
830 return hba->vops->get_ufs_hci_version(hba);
831
832 return ufshcd_readl(hba, REG_UFS_VERSION);
833}
834
Yaniv Gardif06fcc72015-10-28 13:15:51 +0200835static inline int ufshcd_vops_clk_scale_notify(struct ufs_hba *hba,
836 bool up, enum ufs_notify_change_status status)
Yaniv Gardi0263bcd2015-10-28 13:15:48 +0200837{
838 if (hba->vops && hba->vops->clk_scale_notify)
Yaniv Gardif06fcc72015-10-28 13:15:51 +0200839 return hba->vops->clk_scale_notify(hba, up, status);
840 return 0;
Yaniv Gardi0263bcd2015-10-28 13:15:48 +0200841}
842
Subhash Jadavani1e879e82016-10-06 21:48:22 -0700843static inline int ufshcd_vops_setup_clocks(struct ufs_hba *hba, bool on,
844 enum ufs_notify_change_status status)
Yaniv Gardi0263bcd2015-10-28 13:15:48 +0200845{
846 if (hba->vops && hba->vops->setup_clocks)
Subhash Jadavani1e879e82016-10-06 21:48:22 -0700847 return hba->vops->setup_clocks(hba, on, status);
Yaniv Gardi0263bcd2015-10-28 13:15:48 +0200848 return 0;
849}
850
851static inline int ufshcd_vops_setup_regulators(struct ufs_hba *hba, bool status)
852{
853 if (hba->vops && hba->vops->setup_regulators)
854 return hba->vops->setup_regulators(hba, status);
855
856 return 0;
857}
858
859static inline int ufshcd_vops_hce_enable_notify(struct ufs_hba *hba,
860 bool status)
861{
862 if (hba->vops && hba->vops->hce_enable_notify)
863 return hba->vops->hce_enable_notify(hba, status);
864
865 return 0;
866}
867static inline int ufshcd_vops_link_startup_notify(struct ufs_hba *hba,
868 bool status)
869{
870 if (hba->vops && hba->vops->link_startup_notify)
871 return hba->vops->link_startup_notify(hba, status);
872
873 return 0;
874}
875
876static inline int ufshcd_vops_pwr_change_notify(struct ufs_hba *hba,
877 bool status,
878 struct ufs_pa_layer_attr *dev_max_params,
879 struct ufs_pa_layer_attr *dev_req_params)
880{
881 if (hba->vops && hba->vops->pwr_change_notify)
882 return hba->vops->pwr_change_notify(hba, status,
883 dev_max_params, dev_req_params);
884
885 return -ENOTSUPP;
886}
887
Kiwoong Kim0e675ef2016-11-10 21:14:36 +0900888static inline void ufshcd_vops_setup_xfer_req(struct ufs_hba *hba, int tag,
889 bool is_scsi_cmd)
890{
891 if (hba->vops && hba->vops->setup_xfer_req)
892 return hba->vops->setup_xfer_req(hba, tag, is_scsi_cmd);
893}
894
Kiwoong Kimd2877be2016-11-10 21:16:15 +0900895static inline void ufshcd_vops_setup_task_mgmt(struct ufs_hba *hba,
896 int tag, u8 tm_function)
897{
898 if (hba->vops && hba->vops->setup_task_mgmt)
899 return hba->vops->setup_task_mgmt(hba, tag, tm_function);
900}
901
Kiwoong Kimee32c902016-11-10 21:17:43 +0900902static inline void ufshcd_vops_hibern8_notify(struct ufs_hba *hba,
903 enum uic_cmd_dme cmd,
904 enum ufs_notify_change_status status)
905{
906 if (hba->vops && hba->vops->hibern8_notify)
907 return hba->vops->hibern8_notify(hba, cmd, status);
908}
909
Subhash Jadavani56d4a182016-12-05 19:25:32 -0800910static inline int ufshcd_vops_apply_dev_quirks(struct ufs_hba *hba)
911{
912 if (hba->vops && hba->vops->apply_dev_quirks)
913 return hba->vops->apply_dev_quirks(hba);
914 return 0;
915}
916
Yaniv Gardi0263bcd2015-10-28 13:15:48 +0200917static inline int ufshcd_vops_suspend(struct ufs_hba *hba, enum ufs_pm_op op)
918{
919 if (hba->vops && hba->vops->suspend)
920 return hba->vops->suspend(hba, op);
921
922 return 0;
923}
924
925static inline int ufshcd_vops_resume(struct ufs_hba *hba, enum ufs_pm_op op)
926{
927 if (hba->vops && hba->vops->resume)
928 return hba->vops->resume(hba, op);
929
930 return 0;
931}
932
Yaniv Gardi6e3fd442015-10-28 13:15:50 +0200933static inline void ufshcd_vops_dbg_register_dump(struct ufs_hba *hba)
934{
935 if (hba->vops && hba->vops->dbg_register_dump)
936 hba->vops->dbg_register_dump(hba);
937}
938
Vinayak Holikattie0eca632013-02-25 21:44:33 +0530939#endif /* End of Header */