Vinayak Holikatti | e0eca63 | 2013-02-25 21:44:33 +0530 | [diff] [blame] | 1 | /* |
| 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 Gardi | dc3c8d3 | 2016-02-01 15:02:46 +0200 | [diff] [blame] | 6 | * Copyright (c) 2013-2016, The Linux Foundation. All rights reserved. |
Vinayak Holikatti | e0eca63 | 2013-02-25 21:44:33 +0530 | [diff] [blame] | 7 | * |
| 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 Jeon | 6ccf44fe | 2013-06-26 22:39:29 +0530 | [diff] [blame] | 55 | #include <linux/completion.h> |
Sujit Reddy Thumma | aa49761 | 2014-09-25 15:32:22 +0300 | [diff] [blame] | 56 | #include <linux/regulator/consumer.h> |
Yaniv Gardi | f37aabc | 2016-03-10 17:37:20 +0200 | [diff] [blame] | 57 | #include "unipro.h" |
Vinayak Holikatti | e0eca63 | 2013-02-25 21:44:33 +0530 | [diff] [blame] | 58 | |
| 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 Thumma | 5c0c28a | 2014-09-25 15:32:21 +0300 | [diff] [blame] | 74 | struct ufs_hba; |
| 75 | |
Sujit Reddy Thumma | 5a0b0cb | 2013-07-30 00:35:57 +0530 | [diff] [blame] | 76 | enum dev_cmd_type { |
| 77 | DEV_CMD_TYPE_NOP = 0x0, |
Dolev Raviv | 68078d5 | 2013-07-30 00:35:58 +0530 | [diff] [blame] | 78 | DEV_CMD_TYPE_QUERY = 0x1, |
Sujit Reddy Thumma | 5a0b0cb | 2013-07-30 00:35:57 +0530 | [diff] [blame] | 79 | }; |
| 80 | |
Vinayak Holikatti | e0eca63 | 2013-02-25 21:44:33 +0530 | [diff] [blame] | 81 | /** |
| 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 Jeon | 6ccf44fe | 2013-06-26 22:39:29 +0530 | [diff] [blame] | 89 | * @done: UIC command completion |
Vinayak Holikatti | e0eca63 | 2013-02-25 21:44:33 +0530 | [diff] [blame] | 90 | */ |
| 91 | struct uic_command { |
| 92 | u32 command; |
| 93 | u32 argument1; |
| 94 | u32 argument2; |
| 95 | u32 argument3; |
| 96 | int cmd_active; |
| 97 | int result; |
Seungwon Jeon | 6ccf44fe | 2013-06-26 22:39:29 +0530 | [diff] [blame] | 98 | struct completion done; |
Vinayak Holikatti | e0eca63 | 2013-02-25 21:44:33 +0530 | [diff] [blame] | 99 | }; |
| 100 | |
Subhash Jadavani | 57d104c | 2014-09-25 15:32:30 +0300 | [diff] [blame] | 101 | /* Used to differentiate the power management options */ |
| 102 | enum 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 */ |
| 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 */ |
| 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 | */ |
| 134 | enum 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 | |
| 144 | struct ufs_pm_lvl_states { |
| 145 | enum ufs_dev_pwr_mode dev_state; |
| 146 | enum uic_link_state link_state; |
| 147 | }; |
| 148 | |
Vinayak Holikatti | e0eca63 | 2013-02-25 21:44:33 +0530 | [diff] [blame] | 149 | /** |
| 150 | * struct ufshcd_lrb - local reference block |
| 151 | * @utr_descriptor_ptr: UTRD address of the command |
Sujit Reddy Thumma | 5a0b0cb | 2013-07-30 00:35:57 +0530 | [diff] [blame] | 152 | * @ucd_req_ptr: UCD address of the command |
Vinayak Holikatti | e0eca63 | 2013-02-25 21:44:33 +0530 | [diff] [blame] | 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 |
Sujit Reddy Thumma | 5a0b0cb | 2013-07-30 00:35:57 +0530 | [diff] [blame] | 162 | * @intr_cmd: Interrupt command (doesn't participate in interrupt aggregation) |
Vinayak Holikatti | e0eca63 | 2013-02-25 21:44:33 +0530 | [diff] [blame] | 163 | */ |
| 164 | struct ufshcd_lrb { |
| 165 | struct utp_transfer_req_desc *utr_descriptor_ptr; |
Sujit Reddy Thumma | 5a0b0cb | 2013-07-30 00:35:57 +0530 | [diff] [blame] | 166 | struct utp_upiu_req *ucd_req_ptr; |
Vinayak Holikatti | e0eca63 | 2013-02-25 21:44:33 +0530 | [diff] [blame] | 167 | struct utp_upiu_rsp *ucd_rsp_ptr; |
| 168 | struct ufshcd_sg_entry *ucd_prdt_ptr; |
| 169 | |
| 170 | struct scsi_cmnd *cmd; |
| 171 | u8 *sense_buffer; |
| 172 | unsigned int sense_bufflen; |
| 173 | int scsi_status; |
| 174 | |
| 175 | int command_type; |
| 176 | int task_tag; |
Subhash Jadavani | 0ce147d | 2014-09-25 15:32:29 +0300 | [diff] [blame] | 177 | u8 lun; /* UPIU LUN id field is only 8-bit wide */ |
Sujit Reddy Thumma | 5a0b0cb | 2013-07-30 00:35:57 +0530 | [diff] [blame] | 178 | bool intr_cmd; |
Vinayak Holikatti | e0eca63 | 2013-02-25 21:44:33 +0530 | [diff] [blame] | 179 | }; |
| 180 | |
Sujit Reddy Thumma | 5a0b0cb | 2013-07-30 00:35:57 +0530 | [diff] [blame] | 181 | /** |
Tomas Winkler | a230c2f | 2016-02-09 10:25:41 +0200 | [diff] [blame] | 182 | * struct ufs_query - holds relevant data structures for query request |
Dolev Raviv | 68078d5 | 2013-07-30 00:35:58 +0530 | [diff] [blame] | 183 | * @request: request upiu and function |
| 184 | * @descriptor: buffer for sending/receiving descriptor |
| 185 | * @response: response upiu and response |
| 186 | */ |
| 187 | struct ufs_query { |
| 188 | struct ufs_query_req request; |
| 189 | u8 *descriptor; |
| 190 | struct ufs_query_res response; |
| 191 | }; |
| 192 | |
| 193 | /** |
Sujit Reddy Thumma | 5a0b0cb | 2013-07-30 00:35:57 +0530 | [diff] [blame] | 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 |
| 199 | */ |
| 200 | struct ufs_dev_cmd { |
| 201 | enum dev_cmd_type type; |
| 202 | struct mutex lock; |
| 203 | struct completion *complete; |
| 204 | wait_queue_head_t tag_wq; |
Dolev Raviv | 68078d5 | 2013-07-30 00:35:58 +0530 | [diff] [blame] | 205 | struct ufs_query query; |
Sujit Reddy Thumma | 5a0b0cb | 2013-07-30 00:35:57 +0530 | [diff] [blame] | 206 | }; |
Vinayak Holikatti | e0eca63 | 2013-02-25 21:44:33 +0530 | [diff] [blame] | 207 | |
Sujit Reddy Thumma | c6e79da | 2014-09-25 15:32:23 +0300 | [diff] [blame] | 208 | /** |
| 209 | * struct ufs_clk_info - UFS clock related info |
| 210 | * @list: list headed by hba->clk_list_head |
| 211 | * @clk: clock node |
| 212 | * @name: clock name |
| 213 | * @max_freq: maximum frequency supported by the clock |
Sahitya Tummala | 4cff6d99 | 2014-09-25 15:32:33 +0300 | [diff] [blame] | 214 | * @min_freq: min frequency that can be used for clock scaling |
Sahitya Tummala | 856b348 | 2014-09-25 15:32:34 +0300 | [diff] [blame] | 215 | * @curr_freq: indicates the current frequency that it is set to |
Sujit Reddy Thumma | c6e79da | 2014-09-25 15:32:23 +0300 | [diff] [blame] | 216 | * @enabled: variable to check against multiple enable/disable |
| 217 | */ |
| 218 | struct ufs_clk_info { |
| 219 | struct list_head list; |
| 220 | struct clk *clk; |
| 221 | const char *name; |
| 222 | u32 max_freq; |
Sahitya Tummala | 4cff6d99 | 2014-09-25 15:32:33 +0300 | [diff] [blame] | 223 | u32 min_freq; |
Sahitya Tummala | 856b348 | 2014-09-25 15:32:34 +0300 | [diff] [blame] | 224 | u32 curr_freq; |
Sujit Reddy Thumma | c6e79da | 2014-09-25 15:32:23 +0300 | [diff] [blame] | 225 | bool enabled; |
| 226 | }; |
| 227 | |
Yaniv Gardi | f06fcc7 | 2015-10-28 13:15:51 +0200 | [diff] [blame] | 228 | enum ufs_notify_change_status { |
| 229 | PRE_CHANGE, |
| 230 | POST_CHANGE, |
| 231 | }; |
Dolev Raviv | 7eb584d | 2014-09-25 15:32:31 +0300 | [diff] [blame] | 232 | |
| 233 | struct ufs_pa_layer_attr { |
| 234 | u32 gear_rx; |
| 235 | u32 gear_tx; |
| 236 | u32 lane_rx; |
| 237 | u32 lane_tx; |
| 238 | u32 pwr_rx; |
| 239 | u32 pwr_tx; |
| 240 | u32 hs_rate; |
| 241 | }; |
| 242 | |
| 243 | struct ufs_pwr_mode_info { |
| 244 | bool is_valid; |
| 245 | struct ufs_pa_layer_attr info; |
| 246 | }; |
| 247 | |
Sujit Reddy Thumma | 5c0c28a | 2014-09-25 15:32:21 +0300 | [diff] [blame] | 248 | /** |
| 249 | * struct ufs_hba_variant_ops - variant specific callbacks |
| 250 | * @name: variant name |
| 251 | * @init: called when the driver is initialized |
| 252 | * @exit: called to cleanup everything done in init |
Yaniv Gardi | 9949e70 | 2015-05-17 18:55:05 +0300 | [diff] [blame] | 253 | * @get_ufs_hci_version: called to get UFS HCI version |
Sahitya Tummala | 856b348 | 2014-09-25 15:32:34 +0300 | [diff] [blame] | 254 | * @clk_scale_notify: notifies that clks are scaled up/down |
Sujit Reddy Thumma | 5c0c28a | 2014-09-25 15:32:21 +0300 | [diff] [blame] | 255 | * @setup_clocks: called before touching any of the controller registers |
| 256 | * @setup_regulators: called before accessing the host controller |
| 257 | * @hce_enable_notify: called before and after HCE enable bit is set to allow |
| 258 | * variant specific Uni-Pro initialization. |
| 259 | * @link_startup_notify: called before and after Link startup is carried out |
| 260 | * to allow variant specific Uni-Pro initialization. |
Dolev Raviv | 7eb584d | 2014-09-25 15:32:31 +0300 | [diff] [blame] | 261 | * @pwr_change_notify: called before and after a power mode change |
| 262 | * is carried out to allow vendor spesific capabilities |
| 263 | * to be set. |
Subhash Jadavani | 57d104c | 2014-09-25 15:32:30 +0300 | [diff] [blame] | 264 | * @suspend: called during host controller PM callback |
| 265 | * @resume: called during host controller PM callback |
Yaniv Gardi | 6e3fd44 | 2015-10-28 13:15:50 +0200 | [diff] [blame] | 266 | * @dbg_register_dump: used to dump controller debug information |
Joao Pinto | 4b9ffb5 | 2016-05-11 12:21:30 +0100 | [diff] [blame] | 267 | * @phy_initialization: used to initialize phys |
Sujit Reddy Thumma | 5c0c28a | 2014-09-25 15:32:21 +0300 | [diff] [blame] | 268 | */ |
| 269 | struct ufs_hba_variant_ops { |
| 270 | const char *name; |
| 271 | int (*init)(struct ufs_hba *); |
| 272 | void (*exit)(struct ufs_hba *); |
Yaniv Gardi | 9949e70 | 2015-05-17 18:55:05 +0300 | [diff] [blame] | 273 | u32 (*get_ufs_hci_version)(struct ufs_hba *); |
Yaniv Gardi | f06fcc7 | 2015-10-28 13:15:51 +0200 | [diff] [blame] | 274 | int (*clk_scale_notify)(struct ufs_hba *, bool, |
| 275 | enum ufs_notify_change_status); |
| 276 | int (*setup_clocks)(struct ufs_hba *, bool); |
Sujit Reddy Thumma | 5c0c28a | 2014-09-25 15:32:21 +0300 | [diff] [blame] | 277 | int (*setup_regulators)(struct ufs_hba *, bool); |
Yaniv Gardi | f06fcc7 | 2015-10-28 13:15:51 +0200 | [diff] [blame] | 278 | int (*hce_enable_notify)(struct ufs_hba *, |
| 279 | enum ufs_notify_change_status); |
| 280 | int (*link_startup_notify)(struct ufs_hba *, |
| 281 | enum ufs_notify_change_status); |
Dolev Raviv | 7eb584d | 2014-09-25 15:32:31 +0300 | [diff] [blame] | 282 | int (*pwr_change_notify)(struct ufs_hba *, |
Yaniv Gardi | f06fcc7 | 2015-10-28 13:15:51 +0200 | [diff] [blame] | 283 | enum ufs_notify_change_status status, |
| 284 | struct ufs_pa_layer_attr *, |
Dolev Raviv | 7eb584d | 2014-09-25 15:32:31 +0300 | [diff] [blame] | 285 | struct ufs_pa_layer_attr *); |
Subhash Jadavani | 57d104c | 2014-09-25 15:32:30 +0300 | [diff] [blame] | 286 | int (*suspend)(struct ufs_hba *, enum ufs_pm_op); |
| 287 | int (*resume)(struct ufs_hba *, enum ufs_pm_op); |
Yaniv Gardi | 6e3fd44 | 2015-10-28 13:15:50 +0200 | [diff] [blame] | 288 | void (*dbg_register_dump)(struct ufs_hba *hba); |
Joao Pinto | 4b9ffb5 | 2016-05-11 12:21:30 +0100 | [diff] [blame] | 289 | int (*phy_initialization)(struct ufs_hba *); |
Sujit Reddy Thumma | 5c0c28a | 2014-09-25 15:32:21 +0300 | [diff] [blame] | 290 | }; |
| 291 | |
Sahitya Tummala | 1ab27c9 | 2014-09-25 15:32:32 +0300 | [diff] [blame] | 292 | /* clock gating state */ |
| 293 | enum clk_gating_state { |
| 294 | CLKS_OFF, |
| 295 | CLKS_ON, |
| 296 | REQ_CLKS_OFF, |
| 297 | REQ_CLKS_ON, |
| 298 | }; |
| 299 | |
| 300 | /** |
| 301 | * struct ufs_clk_gating - UFS clock gating related info |
| 302 | * @gate_work: worker to turn off clocks after some delay as specified in |
| 303 | * delay_ms |
| 304 | * @ungate_work: worker to turn on clocks that will be used in case of |
| 305 | * interrupt context |
| 306 | * @state: the current clocks state |
| 307 | * @delay_ms: gating delay in ms |
| 308 | * @is_suspended: clk gating is suspended when set to 1 which can be used |
| 309 | * during suspend/resume |
| 310 | * @delay_attr: sysfs attribute to control delay_attr |
| 311 | * @active_reqs: number of requests that are pending and should be waited for |
| 312 | * completion before gating clocks. |
| 313 | */ |
| 314 | struct ufs_clk_gating { |
| 315 | struct delayed_work gate_work; |
| 316 | struct work_struct ungate_work; |
| 317 | enum clk_gating_state state; |
| 318 | unsigned long delay_ms; |
| 319 | bool is_suspended; |
| 320 | struct device_attribute delay_attr; |
| 321 | int active_reqs; |
| 322 | }; |
| 323 | |
Sahitya Tummala | 856b348 | 2014-09-25 15:32:34 +0300 | [diff] [blame] | 324 | struct ufs_clk_scaling { |
| 325 | ktime_t busy_start_t; |
| 326 | bool is_busy_started; |
| 327 | unsigned long tot_busy_t; |
| 328 | unsigned long window_start_t; |
| 329 | }; |
| 330 | |
Vinayak Holikatti | e0eca63 | 2013-02-25 21:44:33 +0530 | [diff] [blame] | 331 | /** |
Yaniv Gardi | 3a4bf06 | 2014-09-25 15:32:27 +0300 | [diff] [blame] | 332 | * struct ufs_init_prefetch - contains data that is pre-fetched once during |
| 333 | * initialization |
| 334 | * @icc_level: icc level which was read during initialization |
| 335 | */ |
| 336 | struct ufs_init_prefetch { |
| 337 | u32 icc_level; |
| 338 | }; |
| 339 | |
| 340 | /** |
Vinayak Holikatti | e0eca63 | 2013-02-25 21:44:33 +0530 | [diff] [blame] | 341 | * struct ufs_hba - per adapter private structure |
| 342 | * @mmio_base: UFSHCI base register address |
| 343 | * @ucdl_base_addr: UFS Command Descriptor base address |
| 344 | * @utrdl_base_addr: UTP Transfer Request Descriptor base address |
| 345 | * @utmrdl_base_addr: UTP Task Management Descriptor base address |
| 346 | * @ucdl_dma_addr: UFS Command Descriptor DMA address |
| 347 | * @utrdl_dma_addr: UTRDL DMA address |
| 348 | * @utmrdl_dma_addr: UTMRDL DMA address |
| 349 | * @host: Scsi_Host instance of the driver |
| 350 | * @dev: device handle |
| 351 | * @lrb: local reference block |
Sujit Reddy Thumma | 5a0b0cb | 2013-07-30 00:35:57 +0530 | [diff] [blame] | 352 | * @lrb_in_use: lrb in use |
Vinayak Holikatti | e0eca63 | 2013-02-25 21:44:33 +0530 | [diff] [blame] | 353 | * @outstanding_tasks: Bits representing outstanding task requests |
| 354 | * @outstanding_reqs: Bits representing outstanding transfer requests |
| 355 | * @capabilities: UFS Controller Capabilities |
| 356 | * @nutrs: Transfer Request Queue depth supported by controller |
| 357 | * @nutmrs: Task Management Queue depth supported by controller |
| 358 | * @ufs_version: UFS Version to which controller complies |
Sujit Reddy Thumma | 5c0c28a | 2014-09-25 15:32:21 +0300 | [diff] [blame] | 359 | * @vops: pointer to variant specific operations |
| 360 | * @priv: pointer to variant specific private data |
Vinayak Holikatti | e0eca63 | 2013-02-25 21:44:33 +0530 | [diff] [blame] | 361 | * @irq: Irq number of the controller |
| 362 | * @active_uic_cmd: handle of active UIC command |
Seungwon Jeon | 6ccf44fe | 2013-06-26 22:39:29 +0530 | [diff] [blame] | 363 | * @uic_cmd_mutex: mutex for uic command |
Sujit Reddy Thumma | e293313 | 2014-05-26 10:59:12 +0530 | [diff] [blame] | 364 | * @tm_wq: wait queue for task management |
| 365 | * @tm_tag_wq: wait queue for free task management slots |
| 366 | * @tm_slots_in_use: bit map of task management request slots in use |
Seungwon Jeon | 53b3d9c | 2013-08-31 21:40:22 +0530 | [diff] [blame] | 367 | * @pwr_done: completion for power mode change |
Vinayak Holikatti | e0eca63 | 2013-02-25 21:44:33 +0530 | [diff] [blame] | 368 | * @tm_condition: condition variable for task management |
| 369 | * @ufshcd_state: UFSHCD states |
Sujit Reddy Thumma | 3441da7 | 2014-05-26 10:59:14 +0530 | [diff] [blame] | 370 | * @eh_flags: Error handling flags |
Seungwon Jeon | 2fbd009 | 2013-06-26 22:39:27 +0530 | [diff] [blame] | 371 | * @intr_mask: Interrupt Mask Bits |
Sujit Reddy Thumma | 66ec6d5 | 2013-07-30 00:35:59 +0530 | [diff] [blame] | 372 | * @ee_ctrl_mask: Exception event control mask |
Sujit Reddy Thumma | 1d337ec | 2014-09-25 15:32:26 +0300 | [diff] [blame] | 373 | * @is_powered: flag to check if HBA is powered |
Yaniv Gardi | 3a4bf06 | 2014-09-25 15:32:27 +0300 | [diff] [blame] | 374 | * @is_init_prefetch: flag to check if data was pre-fetched in initialization |
| 375 | * @init_prefetch_data: data pre-fetched during initialization |
Sujit Reddy Thumma | e8e7f27 | 2014-05-26 10:59:15 +0530 | [diff] [blame] | 376 | * @eh_work: Worker to handle UFS errors that require s/w attention |
Sujit Reddy Thumma | 66ec6d5 | 2013-07-30 00:35:59 +0530 | [diff] [blame] | 377 | * @eeh_work: Worker to handle exception events |
Vinayak Holikatti | e0eca63 | 2013-02-25 21:44:33 +0530 | [diff] [blame] | 378 | * @errors: HBA errors |
Sujit Reddy Thumma | e8e7f27 | 2014-05-26 10:59:15 +0530 | [diff] [blame] | 379 | * @uic_error: UFS interconnect layer error status |
| 380 | * @saved_err: sticky error mask |
| 381 | * @saved_uic_err: sticky UIC error mask |
Sujit Reddy Thumma | 5a0b0cb | 2013-07-30 00:35:57 +0530 | [diff] [blame] | 382 | * @dev_cmd: ufs device management command information |
Yaniv Gardi | cad2e03 | 2015-03-31 17:37:14 +0300 | [diff] [blame] | 383 | * @last_dme_cmd_tstamp: time stamp of the last completed DME command |
Sujit Reddy Thumma | 66ec6d5 | 2013-07-30 00:35:59 +0530 | [diff] [blame] | 384 | * @auto_bkops_enabled: to track whether bkops is enabled in device |
Sujit Reddy Thumma | aa49761 | 2014-09-25 15:32:22 +0300 | [diff] [blame] | 385 | * @vreg_info: UFS device voltage regulator information |
Sujit Reddy Thumma | c6e79da | 2014-09-25 15:32:23 +0300 | [diff] [blame] | 386 | * @clk_list_head: UFS host controller clocks list node head |
Dolev Raviv | 7eb584d | 2014-09-25 15:32:31 +0300 | [diff] [blame] | 387 | * @pwr_info: holds current power mode |
| 388 | * @max_pwr_info: keeps the device max valid pwm |
Yaniv Gardi | afdfff5 | 2016-03-10 17:37:15 +0200 | [diff] [blame] | 389 | * @urgent_bkops_lvl: keeps track of urgent bkops level for device |
| 390 | * @is_urgent_bkops_lvl_checked: keeps track if the urgent bkops level for |
| 391 | * device is known or not. |
Vinayak Holikatti | e0eca63 | 2013-02-25 21:44:33 +0530 | [diff] [blame] | 392 | */ |
| 393 | struct ufs_hba { |
| 394 | void __iomem *mmio_base; |
| 395 | |
| 396 | /* Virtual memory reference */ |
| 397 | struct utp_transfer_cmd_desc *ucdl_base_addr; |
| 398 | struct utp_transfer_req_desc *utrdl_base_addr; |
| 399 | struct utp_task_req_desc *utmrdl_base_addr; |
| 400 | |
| 401 | /* DMA memory reference */ |
| 402 | dma_addr_t ucdl_dma_addr; |
| 403 | dma_addr_t utrdl_dma_addr; |
| 404 | dma_addr_t utmrdl_dma_addr; |
| 405 | |
| 406 | struct Scsi_Host *host; |
| 407 | struct device *dev; |
Subhash Jadavani | 2a8fa60 | 2014-09-25 15:32:28 +0300 | [diff] [blame] | 408 | /* |
| 409 | * This field is to keep a reference to "scsi_device" corresponding to |
| 410 | * "UFS device" W-LU. |
| 411 | */ |
| 412 | struct scsi_device *sdev_ufs_device; |
Vinayak Holikatti | e0eca63 | 2013-02-25 21:44:33 +0530 | [diff] [blame] | 413 | |
Subhash Jadavani | 57d104c | 2014-09-25 15:32:30 +0300 | [diff] [blame] | 414 | enum ufs_dev_pwr_mode curr_dev_pwr_mode; |
| 415 | enum uic_link_state uic_link_state; |
| 416 | /* Desired UFS power management level during runtime PM */ |
| 417 | enum ufs_pm_level rpm_lvl; |
| 418 | /* Desired UFS power management level during system PM */ |
| 419 | enum ufs_pm_level spm_lvl; |
| 420 | int pm_op_in_progress; |
| 421 | |
Vinayak Holikatti | e0eca63 | 2013-02-25 21:44:33 +0530 | [diff] [blame] | 422 | struct ufshcd_lrb *lrb; |
Sujit Reddy Thumma | 5a0b0cb | 2013-07-30 00:35:57 +0530 | [diff] [blame] | 423 | unsigned long lrb_in_use; |
Vinayak Holikatti | e0eca63 | 2013-02-25 21:44:33 +0530 | [diff] [blame] | 424 | |
| 425 | unsigned long outstanding_tasks; |
| 426 | unsigned long outstanding_reqs; |
| 427 | |
| 428 | u32 capabilities; |
| 429 | int nutrs; |
| 430 | int nutmrs; |
| 431 | u32 ufs_version; |
Sujit Reddy Thumma | 5c0c28a | 2014-09-25 15:32:21 +0300 | [diff] [blame] | 432 | struct ufs_hba_variant_ops *vops; |
| 433 | void *priv; |
Vinayak Holikatti | e0eca63 | 2013-02-25 21:44:33 +0530 | [diff] [blame] | 434 | unsigned int irq; |
Subhash Jadavani | 57d104c | 2014-09-25 15:32:30 +0300 | [diff] [blame] | 435 | bool is_irq_enabled; |
Vinayak Holikatti | e0eca63 | 2013-02-25 21:44:33 +0530 | [diff] [blame] | 436 | |
Yaniv Gardi | b852190 | 2015-05-17 18:54:57 +0300 | [diff] [blame] | 437 | /* Interrupt aggregation support is broken */ |
| 438 | #define UFSHCD_QUIRK_BROKEN_INTR_AGGR UFS_BIT(0) |
| 439 | |
Yaniv Gardi | cad2e03 | 2015-03-31 17:37:14 +0300 | [diff] [blame] | 440 | /* |
| 441 | * delay before each dme command is required as the unipro |
| 442 | * layer has shown instabilities |
| 443 | */ |
Yaniv Gardi | b852190 | 2015-05-17 18:54:57 +0300 | [diff] [blame] | 444 | #define UFSHCD_QUIRK_DELAY_BEFORE_DME_CMDS UFS_BIT(1) |
| 445 | |
Yaniv Gardi | 7ca38cf | 2015-05-17 18:54:59 +0300 | [diff] [blame] | 446 | /* |
| 447 | * If UFS host controller is having issue in processing LCC (Line |
| 448 | * Control Command) coming from device then enable this quirk. |
| 449 | * When this quirk is enabled, host controller driver should disable |
| 450 | * the LCC transmission on UFS device (by clearing TX_LCC_ENABLE |
| 451 | * attribute of device to 0). |
| 452 | */ |
| 453 | #define UFSHCD_QUIRK_BROKEN_LCC UFS_BIT(2) |
Yaniv Gardi | cad2e03 | 2015-03-31 17:37:14 +0300 | [diff] [blame] | 454 | |
Yaniv Gardi | c3a2f9e | 2015-05-17 18:55:01 +0300 | [diff] [blame] | 455 | /* |
| 456 | * The attribute PA_RXHSUNTERMCAP specifies whether or not the |
| 457 | * inbound Link supports unterminated line in HS mode. Setting this |
| 458 | * attribute to 1 fixes moving to HS gear. |
| 459 | */ |
| 460 | #define UFSHCD_QUIRK_BROKEN_PA_RXHSUNTERMCAP UFS_BIT(3) |
| 461 | |
Yaniv Gardi | 874237f | 2015-05-17 18:55:03 +0300 | [diff] [blame] | 462 | /* |
| 463 | * This quirk needs to be enabled if the host contoller only allows |
| 464 | * accessing the peer dme attributes in AUTO mode (FAST AUTO or |
| 465 | * SLOW AUTO). |
| 466 | */ |
| 467 | #define UFSHCD_QUIRK_DME_PEER_ACCESS_AUTO_MODE UFS_BIT(4) |
| 468 | |
Yaniv Gardi | 9949e70 | 2015-05-17 18:55:05 +0300 | [diff] [blame] | 469 | /* |
| 470 | * This quirk needs to be enabled if the host contoller doesn't |
| 471 | * advertise the correct version in UFS_VER register. If this quirk |
| 472 | * is enabled, standard UFS host driver will call the vendor specific |
| 473 | * ops (get_ufs_hci_version) to get the correct version. |
| 474 | */ |
| 475 | #define UFSHCD_QUIRK_BROKEN_UFS_HCI_VERSION UFS_BIT(5) |
| 476 | |
Yaniv Gardi | cad2e03 | 2015-03-31 17:37:14 +0300 | [diff] [blame] | 477 | unsigned int quirks; /* Deviations from standard UFSHCI spec. */ |
Seungwon Jeon | 6ccf44fe | 2013-06-26 22:39:29 +0530 | [diff] [blame] | 478 | |
Yaniv Gardi | c58ab7a | 2016-03-10 17:37:10 +0200 | [diff] [blame] | 479 | /* Device deviations from standard UFS device spec. */ |
| 480 | unsigned int dev_quirks; |
| 481 | |
Sujit Reddy Thumma | e293313 | 2014-05-26 10:59:12 +0530 | [diff] [blame] | 482 | wait_queue_head_t tm_wq; |
| 483 | wait_queue_head_t tm_tag_wq; |
Vinayak Holikatti | e0eca63 | 2013-02-25 21:44:33 +0530 | [diff] [blame] | 484 | unsigned long tm_condition; |
Sujit Reddy Thumma | e293313 | 2014-05-26 10:59:12 +0530 | [diff] [blame] | 485 | unsigned long tm_slots_in_use; |
Vinayak Holikatti | e0eca63 | 2013-02-25 21:44:33 +0530 | [diff] [blame] | 486 | |
Subhash Jadavani | 57d104c | 2014-09-25 15:32:30 +0300 | [diff] [blame] | 487 | struct uic_command *active_uic_cmd; |
| 488 | struct mutex uic_cmd_mutex; |
| 489 | struct completion *uic_async_done; |
Seungwon Jeon | 53b3d9c | 2013-08-31 21:40:22 +0530 | [diff] [blame] | 490 | |
Vinayak Holikatti | e0eca63 | 2013-02-25 21:44:33 +0530 | [diff] [blame] | 491 | u32 ufshcd_state; |
Sujit Reddy Thumma | 3441da7 | 2014-05-26 10:59:14 +0530 | [diff] [blame] | 492 | u32 eh_flags; |
Seungwon Jeon | 2fbd009 | 2013-06-26 22:39:27 +0530 | [diff] [blame] | 493 | u32 intr_mask; |
Sujit Reddy Thumma | 66ec6d5 | 2013-07-30 00:35:59 +0530 | [diff] [blame] | 494 | u16 ee_ctrl_mask; |
Sujit Reddy Thumma | 1d337ec | 2014-09-25 15:32:26 +0300 | [diff] [blame] | 495 | bool is_powered; |
Yaniv Gardi | 3a4bf06 | 2014-09-25 15:32:27 +0300 | [diff] [blame] | 496 | bool is_init_prefetch; |
| 497 | struct ufs_init_prefetch init_prefetch_data; |
Vinayak Holikatti | e0eca63 | 2013-02-25 21:44:33 +0530 | [diff] [blame] | 498 | |
| 499 | /* Work Queues */ |
Sujit Reddy Thumma | e8e7f27 | 2014-05-26 10:59:15 +0530 | [diff] [blame] | 500 | struct work_struct eh_work; |
Sujit Reddy Thumma | 66ec6d5 | 2013-07-30 00:35:59 +0530 | [diff] [blame] | 501 | struct work_struct eeh_work; |
Vinayak Holikatti | e0eca63 | 2013-02-25 21:44:33 +0530 | [diff] [blame] | 502 | |
| 503 | /* HBA Errors */ |
| 504 | u32 errors; |
Sujit Reddy Thumma | e8e7f27 | 2014-05-26 10:59:15 +0530 | [diff] [blame] | 505 | u32 uic_error; |
| 506 | u32 saved_err; |
| 507 | u32 saved_uic_err; |
Sujit Reddy Thumma | 5a0b0cb | 2013-07-30 00:35:57 +0530 | [diff] [blame] | 508 | |
| 509 | /* Device management request data */ |
| 510 | struct ufs_dev_cmd dev_cmd; |
Yaniv Gardi | cad2e03 | 2015-03-31 17:37:14 +0300 | [diff] [blame] | 511 | ktime_t last_dme_cmd_tstamp; |
Sujit Reddy Thumma | 66ec6d5 | 2013-07-30 00:35:59 +0530 | [diff] [blame] | 512 | |
Subhash Jadavani | 57d104c | 2014-09-25 15:32:30 +0300 | [diff] [blame] | 513 | /* Keeps information of the UFS device connected to this host */ |
| 514 | struct ufs_dev_info dev_info; |
Sujit Reddy Thumma | 66ec6d5 | 2013-07-30 00:35:59 +0530 | [diff] [blame] | 515 | bool auto_bkops_enabled; |
Sujit Reddy Thumma | aa49761 | 2014-09-25 15:32:22 +0300 | [diff] [blame] | 516 | struct ufs_vreg_info vreg_info; |
Sujit Reddy Thumma | c6e79da | 2014-09-25 15:32:23 +0300 | [diff] [blame] | 517 | struct list_head clk_list_head; |
Subhash Jadavani | 57d104c | 2014-09-25 15:32:30 +0300 | [diff] [blame] | 518 | |
| 519 | bool wlun_dev_clr_ua; |
Dolev Raviv | 7eb584d | 2014-09-25 15:32:31 +0300 | [diff] [blame] | 520 | |
Yaniv Gardi | 54b879b | 2016-03-10 17:37:05 +0200 | [diff] [blame] | 521 | /* Number of lanes available (1 or 2) for Rx/Tx */ |
| 522 | u32 lanes_per_direction; |
Dolev Raviv | 7eb584d | 2014-09-25 15:32:31 +0300 | [diff] [blame] | 523 | struct ufs_pa_layer_attr pwr_info; |
| 524 | struct ufs_pwr_mode_info max_pwr_info; |
Sahitya Tummala | 1ab27c9 | 2014-09-25 15:32:32 +0300 | [diff] [blame] | 525 | |
| 526 | struct ufs_clk_gating clk_gating; |
| 527 | /* Control to enable/disable host capabilities */ |
| 528 | u32 caps; |
| 529 | /* Allow dynamic clk gating */ |
| 530 | #define UFSHCD_CAP_CLK_GATING (1 << 0) |
| 531 | /* Allow hiberb8 with clk gating */ |
| 532 | #define UFSHCD_CAP_HIBERN8_WITH_CLK_GATING (1 << 1) |
Sahitya Tummala | 856b348 | 2014-09-25 15:32:34 +0300 | [diff] [blame] | 533 | /* Allow dynamic clk scaling */ |
| 534 | #define UFSHCD_CAP_CLK_SCALING (1 << 2) |
Subhash Jadavani | 374a246 | 2014-09-25 15:32:35 +0300 | [diff] [blame] | 535 | /* Allow auto bkops to enabled during runtime suspend */ |
| 536 | #define UFSHCD_CAP_AUTO_BKOPS_SUSPEND (1 << 3) |
Yaniv Gardi | b852190 | 2015-05-17 18:54:57 +0300 | [diff] [blame] | 537 | /* |
| 538 | * This capability allows host controller driver to use the UFS HCI's |
| 539 | * interrupt aggregation capability. |
| 540 | * CAUTION: Enabling this might reduce overall UFS throughput. |
| 541 | */ |
| 542 | #define UFSHCD_CAP_INTR_AGGR (1 << 4) |
Sahitya Tummala | 856b348 | 2014-09-25 15:32:34 +0300 | [diff] [blame] | 543 | |
| 544 | struct devfreq *devfreq; |
| 545 | struct ufs_clk_scaling clk_scaling; |
Dolev Raviv | e785060 | 2014-09-25 15:32:36 +0300 | [diff] [blame] | 546 | bool is_sys_suspended; |
Yaniv Gardi | afdfff5 | 2016-03-10 17:37:15 +0200 | [diff] [blame] | 547 | |
| 548 | enum bkops_status urgent_bkops_lvl; |
| 549 | bool is_urgent_bkops_lvl_checked; |
Vinayak Holikatti | e0eca63 | 2013-02-25 21:44:33 +0530 | [diff] [blame] | 550 | }; |
| 551 | |
Sahitya Tummala | 1ab27c9 | 2014-09-25 15:32:32 +0300 | [diff] [blame] | 552 | /* Returns true if clocks can be gated. Otherwise false */ |
| 553 | static inline bool ufshcd_is_clkgating_allowed(struct ufs_hba *hba) |
| 554 | { |
| 555 | return hba->caps & UFSHCD_CAP_CLK_GATING; |
| 556 | } |
| 557 | static inline bool ufshcd_can_hibern8_during_gating(struct ufs_hba *hba) |
| 558 | { |
| 559 | return hba->caps & UFSHCD_CAP_HIBERN8_WITH_CLK_GATING; |
| 560 | } |
Sahitya Tummala | 856b348 | 2014-09-25 15:32:34 +0300 | [diff] [blame] | 561 | static inline int ufshcd_is_clkscaling_enabled(struct ufs_hba *hba) |
| 562 | { |
| 563 | return hba->caps & UFSHCD_CAP_CLK_SCALING; |
| 564 | } |
Subhash Jadavani | 374a246 | 2014-09-25 15:32:35 +0300 | [diff] [blame] | 565 | static inline bool ufshcd_can_autobkops_during_suspend(struct ufs_hba *hba) |
| 566 | { |
| 567 | return hba->caps & UFSHCD_CAP_AUTO_BKOPS_SUSPEND; |
| 568 | } |
| 569 | |
Yaniv Gardi | b852190 | 2015-05-17 18:54:57 +0300 | [diff] [blame] | 570 | static inline bool ufshcd_is_intr_aggr_allowed(struct ufs_hba *hba) |
| 571 | { |
Joao Pinto | 4b9ffb5 | 2016-05-11 12:21:30 +0100 | [diff] [blame] | 572 | /* DWC UFS Core has the Interrupt aggregation feature but is not detectable*/ |
| 573 | #ifndef CONFIG_SCSI_UFS_DWC |
Yaniv Gardi | b852190 | 2015-05-17 18:54:57 +0300 | [diff] [blame] | 574 | if ((hba->caps & UFSHCD_CAP_INTR_AGGR) && |
| 575 | !(hba->quirks & UFSHCD_QUIRK_BROKEN_INTR_AGGR)) |
| 576 | return true; |
| 577 | else |
| 578 | return false; |
Joao Pinto | 4b9ffb5 | 2016-05-11 12:21:30 +0100 | [diff] [blame] | 579 | #else |
| 580 | return true; |
| 581 | #endif |
Yaniv Gardi | b852190 | 2015-05-17 18:54:57 +0300 | [diff] [blame] | 582 | } |
| 583 | |
Seungwon Jeon | b873a275 | 2013-06-26 22:39:26 +0530 | [diff] [blame] | 584 | #define ufshcd_writel(hba, val, reg) \ |
| 585 | writel((val), (hba)->mmio_base + (reg)) |
| 586 | #define ufshcd_readl(hba, reg) \ |
| 587 | readl((hba)->mmio_base + (reg)) |
| 588 | |
Dolev Raviv | e785060 | 2014-09-25 15:32:36 +0300 | [diff] [blame] | 589 | /** |
| 590 | * ufshcd_rmwl - read modify write into a register |
| 591 | * @hba - per adapter instance |
| 592 | * @mask - mask to apply on read value |
| 593 | * @val - actual value to write |
| 594 | * @reg - register address |
| 595 | */ |
| 596 | static inline void ufshcd_rmwl(struct ufs_hba *hba, u32 mask, u32 val, u32 reg) |
| 597 | { |
| 598 | u32 tmp; |
| 599 | |
| 600 | tmp = ufshcd_readl(hba, reg); |
| 601 | tmp &= ~mask; |
| 602 | tmp |= (val & mask); |
| 603 | ufshcd_writel(hba, tmp, reg); |
| 604 | } |
| 605 | |
Sujit Reddy Thumma | 5c0c28a | 2014-09-25 15:32:21 +0300 | [diff] [blame] | 606 | int ufshcd_alloc_host(struct device *, struct ufs_hba **); |
Yaniv Gardi | 47555a5 | 2015-10-28 13:15:49 +0200 | [diff] [blame] | 607 | void ufshcd_dealloc_host(struct ufs_hba *); |
Sujit Reddy Thumma | 5c0c28a | 2014-09-25 15:32:21 +0300 | [diff] [blame] | 608 | int ufshcd_init(struct ufs_hba * , void __iomem * , unsigned int); |
Vinayak Holikatti | e0eca63 | 2013-02-25 21:44:33 +0530 | [diff] [blame] | 609 | void ufshcd_remove(struct ufs_hba *); |
Yaniv Gardi | 596585a | 2016-03-10 17:37:08 +0200 | [diff] [blame] | 610 | int ufshcd_wait_for_register(struct ufs_hba *hba, u32 reg, u32 mask, |
| 611 | u32 val, unsigned long interval_us, |
| 612 | unsigned long timeout_ms, bool can_sleep); |
Vinayak Holikatti | e0eca63 | 2013-02-25 21:44:33 +0530 | [diff] [blame] | 613 | |
Dolev Raviv | 68078d5 | 2013-07-30 00:35:58 +0530 | [diff] [blame] | 614 | static inline void check_upiu_size(void) |
| 615 | { |
| 616 | BUILD_BUG_ON(ALIGNED_UPIU_SIZE < |
| 617 | GENERAL_UPIU_REQUEST_SIZE + QUERY_DESC_MAX_SIZE); |
| 618 | } |
| 619 | |
Yaniv Gardi | 1ce5898 | 2015-10-28 13:15:47 +0200 | [diff] [blame] | 620 | /** |
| 621 | * ufshcd_set_variant - set variant specific data to the hba |
| 622 | * @hba - per adapter instance |
| 623 | * @variant - pointer to variant specific data |
| 624 | */ |
| 625 | static inline void ufshcd_set_variant(struct ufs_hba *hba, void *variant) |
| 626 | { |
| 627 | BUG_ON(!hba); |
| 628 | hba->priv = variant; |
| 629 | } |
| 630 | |
| 631 | /** |
| 632 | * ufshcd_get_variant - get variant specific data from the hba |
| 633 | * @hba - per adapter instance |
| 634 | */ |
| 635 | static inline void *ufshcd_get_variant(struct ufs_hba *hba) |
| 636 | { |
| 637 | BUG_ON(!hba); |
| 638 | return hba->priv; |
| 639 | } |
| 640 | |
Sujit Reddy Thumma | 66ec6d5 | 2013-07-30 00:35:59 +0530 | [diff] [blame] | 641 | extern int ufshcd_runtime_suspend(struct ufs_hba *hba); |
| 642 | extern int ufshcd_runtime_resume(struct ufs_hba *hba); |
| 643 | extern int ufshcd_runtime_idle(struct ufs_hba *hba); |
Subhash Jadavani | 57d104c | 2014-09-25 15:32:30 +0300 | [diff] [blame] | 644 | extern int ufshcd_system_suspend(struct ufs_hba *hba); |
| 645 | extern int ufshcd_system_resume(struct ufs_hba *hba); |
| 646 | extern int ufshcd_shutdown(struct ufs_hba *hba); |
Seungwon Jeon | 12b4fdb | 2013-08-31 21:40:21 +0530 | [diff] [blame] | 647 | extern int ufshcd_dme_set_attr(struct ufs_hba *hba, u32 attr_sel, |
| 648 | u8 attr_set, u32 mib_val, u8 peer); |
| 649 | extern int ufshcd_dme_get_attr(struct ufs_hba *hba, u32 attr_sel, |
| 650 | u32 *mib_val, u8 peer); |
| 651 | |
| 652 | /* UIC command interfaces for DME primitives */ |
| 653 | #define DME_LOCAL 0 |
| 654 | #define DME_PEER 1 |
| 655 | #define ATTR_SET_NOR 0 /* NORMAL */ |
| 656 | #define ATTR_SET_ST 1 /* STATIC */ |
| 657 | |
| 658 | static inline int ufshcd_dme_set(struct ufs_hba *hba, u32 attr_sel, |
| 659 | u32 mib_val) |
| 660 | { |
| 661 | return ufshcd_dme_set_attr(hba, attr_sel, ATTR_SET_NOR, |
| 662 | mib_val, DME_LOCAL); |
| 663 | } |
| 664 | |
| 665 | static inline int ufshcd_dme_st_set(struct ufs_hba *hba, u32 attr_sel, |
| 666 | u32 mib_val) |
| 667 | { |
| 668 | return ufshcd_dme_set_attr(hba, attr_sel, ATTR_SET_ST, |
| 669 | mib_val, DME_LOCAL); |
| 670 | } |
| 671 | |
| 672 | static inline int ufshcd_dme_peer_set(struct ufs_hba *hba, u32 attr_sel, |
| 673 | u32 mib_val) |
| 674 | { |
| 675 | return ufshcd_dme_set_attr(hba, attr_sel, ATTR_SET_NOR, |
| 676 | mib_val, DME_PEER); |
| 677 | } |
| 678 | |
| 679 | static inline int ufshcd_dme_peer_st_set(struct ufs_hba *hba, u32 attr_sel, |
| 680 | u32 mib_val) |
| 681 | { |
| 682 | return ufshcd_dme_set_attr(hba, attr_sel, ATTR_SET_ST, |
| 683 | mib_val, DME_PEER); |
| 684 | } |
| 685 | |
| 686 | static inline int ufshcd_dme_get(struct ufs_hba *hba, |
| 687 | u32 attr_sel, u32 *mib_val) |
| 688 | { |
| 689 | return ufshcd_dme_get_attr(hba, attr_sel, mib_val, DME_LOCAL); |
| 690 | } |
| 691 | |
| 692 | static inline int ufshcd_dme_peer_get(struct ufs_hba *hba, |
| 693 | u32 attr_sel, u32 *mib_val) |
| 694 | { |
| 695 | return ufshcd_dme_get_attr(hba, attr_sel, mib_val, DME_PEER); |
| 696 | } |
| 697 | |
Yaniv Gardi | b573d48 | 2016-03-10 17:37:09 +0200 | [diff] [blame] | 698 | int ufshcd_read_device_desc(struct ufs_hba *hba, u8 *buf, u32 size); |
| 699 | |
Yaniv Gardi | f37aabc | 2016-03-10 17:37:20 +0200 | [diff] [blame] | 700 | static inline bool ufshcd_is_hs_mode(struct ufs_pa_layer_attr *pwr_info) |
| 701 | { |
| 702 | return (pwr_info->pwr_rx == FAST_MODE || |
| 703 | pwr_info->pwr_rx == FASTAUTO_MODE) && |
| 704 | (pwr_info->pwr_tx == FAST_MODE || |
| 705 | pwr_info->pwr_tx == FASTAUTO_MODE); |
| 706 | } |
| 707 | |
Yaniv Gardi | b573d48 | 2016-03-10 17:37:09 +0200 | [diff] [blame] | 708 | #define ASCII_STD true |
| 709 | |
| 710 | int ufshcd_read_string_desc(struct ufs_hba *hba, int desc_index, u8 *buf, |
| 711 | u32 size, bool ascii); |
| 712 | |
Yaniv Gardi | dc3c8d3 | 2016-02-01 15:02:46 +0200 | [diff] [blame] | 713 | /* Expose Query-Request API */ |
| 714 | int ufshcd_query_flag(struct ufs_hba *hba, enum query_opcode opcode, |
| 715 | enum flag_idn idn, bool *flag_res); |
Sahitya Tummala | 1ab27c9 | 2014-09-25 15:32:32 +0300 | [diff] [blame] | 716 | int ufshcd_hold(struct ufs_hba *hba, bool async); |
| 717 | void ufshcd_release(struct ufs_hba *hba); |
Yaniv Gardi | 3711310 | 2016-03-10 17:37:16 +0200 | [diff] [blame] | 718 | u32 ufshcd_get_local_unipro_ver(struct ufs_hba *hba); |
Yaniv Gardi | 0263bcd | 2015-10-28 13:15:48 +0200 | [diff] [blame] | 719 | |
| 720 | /* Wrapper functions for safely calling variant operations */ |
| 721 | static inline const char *ufshcd_get_var_name(struct ufs_hba *hba) |
| 722 | { |
| 723 | if (hba->vops) |
| 724 | return hba->vops->name; |
| 725 | return ""; |
| 726 | } |
| 727 | |
| 728 | static inline int ufshcd_vops_init(struct ufs_hba *hba) |
| 729 | { |
| 730 | if (hba->vops && hba->vops->init) |
| 731 | return hba->vops->init(hba); |
| 732 | |
| 733 | return 0; |
| 734 | } |
| 735 | |
| 736 | static inline void ufshcd_vops_exit(struct ufs_hba *hba) |
| 737 | { |
| 738 | if (hba->vops && hba->vops->exit) |
| 739 | return hba->vops->exit(hba); |
| 740 | } |
| 741 | |
| 742 | static inline u32 ufshcd_vops_get_ufs_hci_version(struct ufs_hba *hba) |
| 743 | { |
| 744 | if (hba->vops && hba->vops->get_ufs_hci_version) |
| 745 | return hba->vops->get_ufs_hci_version(hba); |
| 746 | |
| 747 | return ufshcd_readl(hba, REG_UFS_VERSION); |
| 748 | } |
| 749 | |
Yaniv Gardi | f06fcc7 | 2015-10-28 13:15:51 +0200 | [diff] [blame] | 750 | static inline int ufshcd_vops_clk_scale_notify(struct ufs_hba *hba, |
| 751 | bool up, enum ufs_notify_change_status status) |
Yaniv Gardi | 0263bcd | 2015-10-28 13:15:48 +0200 | [diff] [blame] | 752 | { |
| 753 | if (hba->vops && hba->vops->clk_scale_notify) |
Yaniv Gardi | f06fcc7 | 2015-10-28 13:15:51 +0200 | [diff] [blame] | 754 | return hba->vops->clk_scale_notify(hba, up, status); |
| 755 | return 0; |
Yaniv Gardi | 0263bcd | 2015-10-28 13:15:48 +0200 | [diff] [blame] | 756 | } |
| 757 | |
| 758 | static inline int ufshcd_vops_setup_clocks(struct ufs_hba *hba, bool on) |
| 759 | { |
| 760 | if (hba->vops && hba->vops->setup_clocks) |
| 761 | return hba->vops->setup_clocks(hba, on); |
Yaniv Gardi | 0263bcd | 2015-10-28 13:15:48 +0200 | [diff] [blame] | 762 | return 0; |
| 763 | } |
| 764 | |
| 765 | static inline int ufshcd_vops_setup_regulators(struct ufs_hba *hba, bool status) |
| 766 | { |
| 767 | if (hba->vops && hba->vops->setup_regulators) |
| 768 | return hba->vops->setup_regulators(hba, status); |
| 769 | |
| 770 | return 0; |
| 771 | } |
| 772 | |
| 773 | static inline int ufshcd_vops_hce_enable_notify(struct ufs_hba *hba, |
| 774 | bool status) |
| 775 | { |
| 776 | if (hba->vops && hba->vops->hce_enable_notify) |
| 777 | return hba->vops->hce_enable_notify(hba, status); |
| 778 | |
| 779 | return 0; |
| 780 | } |
| 781 | static inline int ufshcd_vops_link_startup_notify(struct ufs_hba *hba, |
| 782 | bool status) |
| 783 | { |
| 784 | if (hba->vops && hba->vops->link_startup_notify) |
| 785 | return hba->vops->link_startup_notify(hba, status); |
| 786 | |
| 787 | return 0; |
| 788 | } |
| 789 | |
| 790 | static inline int ufshcd_vops_pwr_change_notify(struct ufs_hba *hba, |
| 791 | bool status, |
| 792 | struct ufs_pa_layer_attr *dev_max_params, |
| 793 | struct ufs_pa_layer_attr *dev_req_params) |
| 794 | { |
| 795 | if (hba->vops && hba->vops->pwr_change_notify) |
| 796 | return hba->vops->pwr_change_notify(hba, status, |
| 797 | dev_max_params, dev_req_params); |
| 798 | |
| 799 | return -ENOTSUPP; |
| 800 | } |
| 801 | |
| 802 | static inline int ufshcd_vops_suspend(struct ufs_hba *hba, enum ufs_pm_op op) |
| 803 | { |
| 804 | if (hba->vops && hba->vops->suspend) |
| 805 | return hba->vops->suspend(hba, op); |
| 806 | |
| 807 | return 0; |
| 808 | } |
| 809 | |
| 810 | static inline int ufshcd_vops_resume(struct ufs_hba *hba, enum ufs_pm_op op) |
| 811 | { |
| 812 | if (hba->vops && hba->vops->resume) |
| 813 | return hba->vops->resume(hba, op); |
| 814 | |
| 815 | return 0; |
| 816 | } |
| 817 | |
Yaniv Gardi | 6e3fd44 | 2015-10-28 13:15:50 +0200 | [diff] [blame] | 818 | static inline void ufshcd_vops_dbg_register_dump(struct ufs_hba *hba) |
| 819 | { |
| 820 | if (hba->vops && hba->vops->dbg_register_dump) |
| 821 | hba->vops->dbg_register_dump(hba); |
| 822 | } |
| 823 | |
Vinayak Holikatti | e0eca63 | 2013-02-25 21:44:33 +0530 | [diff] [blame] | 824 | #endif /* End of Header */ |