blob: e1bde0598d92e5f7901e1da59693b1e281eb59b1 [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
6 *
7 * Authors:
8 * Santosh Yaraganavi <santosh.sy@samsung.com>
9 * Vinayak Holikatti <h.vinayak@samsung.com>
10 *
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version 2
14 * of the License, or (at your option) any later version.
15 * See the COPYING file in the top-level directory or visit
16 * <http://www.gnu.org/licenses/gpl-2.0.html>
17 *
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * This program is provided "AS IS" and "WITH ALL FAULTS" and
24 * without warranty of any kind. You are solely responsible for
25 * determining the appropriateness of using and distributing
26 * the program and assume all risks associated with your exercise
27 * of rights with respect to the program, including but not limited
28 * to infringement of third party rights, the risks and costs of
29 * program errors, damage to or loss of data, programs or equipment,
30 * and unavailability or interruption of operations. Under no
31 * circumstances will the contributor of this Program be liable for
32 * any damages of any kind arising from your use or distribution of
33 * this program.
34 */
35
36#ifndef _UFSHCD_H
37#define _UFSHCD_H
38
39#include <linux/module.h>
40#include <linux/kernel.h>
41#include <linux/init.h>
42#include <linux/interrupt.h>
43#include <linux/io.h>
44#include <linux/delay.h>
45#include <linux/slab.h>
46#include <linux/spinlock.h>
47#include <linux/workqueue.h>
48#include <linux/errno.h>
49#include <linux/types.h>
50#include <linux/wait.h>
51#include <linux/bitops.h>
52#include <linux/pm_runtime.h>
53#include <linux/clk.h>
Seungwon Jeon6ccf44fe2013-06-26 22:39:29 +053054#include <linux/completion.h>
Sujit Reddy Thummaaa497612014-09-25 15:32:22 +030055#include <linux/regulator/consumer.h>
Vinayak Holikattie0eca632013-02-25 21:44:33 +053056
57#include <asm/irq.h>
58#include <asm/byteorder.h>
59#include <scsi/scsi.h>
60#include <scsi/scsi_cmnd.h>
61#include <scsi/scsi_host.h>
62#include <scsi/scsi_tcq.h>
63#include <scsi/scsi_dbg.h>
64#include <scsi/scsi_eh.h>
65
66#include "ufs.h"
67#include "ufshci.h"
68
69#define UFSHCD "ufshcd"
70#define UFSHCD_DRIVER_VERSION "0.2"
71
Sujit Reddy Thumma5c0c28a2014-09-25 15:32:21 +030072struct ufs_hba;
73
Sujit Reddy Thumma5a0b0cb2013-07-30 00:35:57 +053074enum dev_cmd_type {
75 DEV_CMD_TYPE_NOP = 0x0,
Dolev Raviv68078d52013-07-30 00:35:58 +053076 DEV_CMD_TYPE_QUERY = 0x1,
Sujit Reddy Thumma5a0b0cb2013-07-30 00:35:57 +053077};
78
Vinayak Holikattie0eca632013-02-25 21:44:33 +053079/**
80 * struct uic_command - UIC command structure
81 * @command: UIC command
82 * @argument1: UIC command argument 1
83 * @argument2: UIC command argument 2
84 * @argument3: UIC command argument 3
85 * @cmd_active: Indicate if UIC command is outstanding
86 * @result: UIC command result
Seungwon Jeon6ccf44fe2013-06-26 22:39:29 +053087 * @done: UIC command completion
Vinayak Holikattie0eca632013-02-25 21:44:33 +053088 */
89struct uic_command {
90 u32 command;
91 u32 argument1;
92 u32 argument2;
93 u32 argument3;
94 int cmd_active;
95 int result;
Seungwon Jeon6ccf44fe2013-06-26 22:39:29 +053096 struct completion done;
Vinayak Holikattie0eca632013-02-25 21:44:33 +053097};
98
Subhash Jadavani57d104c2014-09-25 15:32:30 +030099/* Used to differentiate the power management options */
100enum ufs_pm_op {
101 UFS_RUNTIME_PM,
102 UFS_SYSTEM_PM,
103 UFS_SHUTDOWN_PM,
104};
105
106#define ufshcd_is_runtime_pm(op) ((op) == UFS_RUNTIME_PM)
107#define ufshcd_is_system_pm(op) ((op) == UFS_SYSTEM_PM)
108#define ufshcd_is_shutdown_pm(op) ((op) == UFS_SHUTDOWN_PM)
109
110/* Host <-> Device UniPro Link state */
111enum uic_link_state {
112 UIC_LINK_OFF_STATE = 0, /* Link powered down or disabled */
113 UIC_LINK_ACTIVE_STATE = 1, /* Link is in Fast/Slow/Sleep state */
114 UIC_LINK_HIBERN8_STATE = 2, /* Link is in Hibernate state */
115};
116
117#define ufshcd_is_link_off(hba) ((hba)->uic_link_state == UIC_LINK_OFF_STATE)
118#define ufshcd_is_link_active(hba) ((hba)->uic_link_state == \
119 UIC_LINK_ACTIVE_STATE)
120#define ufshcd_is_link_hibern8(hba) ((hba)->uic_link_state == \
121 UIC_LINK_HIBERN8_STATE)
122#define ufshcd_set_link_off(hba) ((hba)->uic_link_state = UIC_LINK_OFF_STATE)
123#define ufshcd_set_link_active(hba) ((hba)->uic_link_state = \
124 UIC_LINK_ACTIVE_STATE)
125#define ufshcd_set_link_hibern8(hba) ((hba)->uic_link_state = \
126 UIC_LINK_HIBERN8_STATE)
127
128/*
129 * UFS Power management levels.
130 * Each level is in increasing order of power savings.
131 */
132enum ufs_pm_level {
133 UFS_PM_LVL_0, /* UFS_ACTIVE_PWR_MODE, UIC_LINK_ACTIVE_STATE */
134 UFS_PM_LVL_1, /* UFS_ACTIVE_PWR_MODE, UIC_LINK_HIBERN8_STATE */
135 UFS_PM_LVL_2, /* UFS_SLEEP_PWR_MODE, UIC_LINK_ACTIVE_STATE */
136 UFS_PM_LVL_3, /* UFS_SLEEP_PWR_MODE, UIC_LINK_HIBERN8_STATE */
137 UFS_PM_LVL_4, /* UFS_POWERDOWN_PWR_MODE, UIC_LINK_HIBERN8_STATE */
138 UFS_PM_LVL_5, /* UFS_POWERDOWN_PWR_MODE, UIC_LINK_OFF_STATE */
139 UFS_PM_LVL_MAX
140};
141
142struct ufs_pm_lvl_states {
143 enum ufs_dev_pwr_mode dev_state;
144 enum uic_link_state link_state;
145};
146
Vinayak Holikattie0eca632013-02-25 21:44:33 +0530147/**
148 * struct ufshcd_lrb - local reference block
149 * @utr_descriptor_ptr: UTRD address of the command
Sujit Reddy Thumma5a0b0cb2013-07-30 00:35:57 +0530150 * @ucd_req_ptr: UCD address of the command
Vinayak Holikattie0eca632013-02-25 21:44:33 +0530151 * @ucd_rsp_ptr: Response UPIU address for this command
152 * @ucd_prdt_ptr: PRDT address of the command
153 * @cmd: pointer to SCSI command
154 * @sense_buffer: pointer to sense buffer address of the SCSI command
155 * @sense_bufflen: Length of the sense buffer
156 * @scsi_status: SCSI status of the command
157 * @command_type: SCSI, UFS, Query.
158 * @task_tag: Task tag of the command
159 * @lun: LUN of the command
Sujit Reddy Thumma5a0b0cb2013-07-30 00:35:57 +0530160 * @intr_cmd: Interrupt command (doesn't participate in interrupt aggregation)
Vinayak Holikattie0eca632013-02-25 21:44:33 +0530161 */
162struct ufshcd_lrb {
163 struct utp_transfer_req_desc *utr_descriptor_ptr;
Sujit Reddy Thumma5a0b0cb2013-07-30 00:35:57 +0530164 struct utp_upiu_req *ucd_req_ptr;
Vinayak Holikattie0eca632013-02-25 21:44:33 +0530165 struct utp_upiu_rsp *ucd_rsp_ptr;
166 struct ufshcd_sg_entry *ucd_prdt_ptr;
167
168 struct scsi_cmnd *cmd;
169 u8 *sense_buffer;
170 unsigned int sense_bufflen;
171 int scsi_status;
172
173 int command_type;
174 int task_tag;
Subhash Jadavani0ce147d2014-09-25 15:32:29 +0300175 u8 lun; /* UPIU LUN id field is only 8-bit wide */
Sujit Reddy Thumma5a0b0cb2013-07-30 00:35:57 +0530176 bool intr_cmd;
Vinayak Holikattie0eca632013-02-25 21:44:33 +0530177};
178
Sujit Reddy Thumma5a0b0cb2013-07-30 00:35:57 +0530179/**
Dolev Raviv68078d52013-07-30 00:35:58 +0530180 * struct ufs_query - holds relevent data structures for query request
181 * @request: request upiu and function
182 * @descriptor: buffer for sending/receiving descriptor
183 * @response: response upiu and response
184 */
185struct ufs_query {
186 struct ufs_query_req request;
187 u8 *descriptor;
188 struct ufs_query_res response;
189};
190
191/**
Sujit Reddy Thumma5a0b0cb2013-07-30 00:35:57 +0530192 * struct ufs_dev_cmd - all assosiated fields with device management commands
193 * @type: device management command type - Query, NOP OUT
194 * @lock: lock to allow one command at a time
195 * @complete: internal commands completion
196 * @tag_wq: wait queue until free command slot is available
197 */
198struct ufs_dev_cmd {
199 enum dev_cmd_type type;
200 struct mutex lock;
201 struct completion *complete;
202 wait_queue_head_t tag_wq;
Dolev Raviv68078d52013-07-30 00:35:58 +0530203 struct ufs_query query;
Sujit Reddy Thumma5a0b0cb2013-07-30 00:35:57 +0530204};
Vinayak Holikattie0eca632013-02-25 21:44:33 +0530205
Sujit Reddy Thummac6e79da2014-09-25 15:32:23 +0300206/**
207 * struct ufs_clk_info - UFS clock related info
208 * @list: list headed by hba->clk_list_head
209 * @clk: clock node
210 * @name: clock name
211 * @max_freq: maximum frequency supported by the clock
212 * @enabled: variable to check against multiple enable/disable
213 */
214struct ufs_clk_info {
215 struct list_head list;
216 struct clk *clk;
217 const char *name;
218 u32 max_freq;
219 bool enabled;
220};
221
Sujit Reddy Thumma5c0c28a2014-09-25 15:32:21 +0300222#define PRE_CHANGE 0
223#define POST_CHANGE 1
224/**
225 * struct ufs_hba_variant_ops - variant specific callbacks
226 * @name: variant name
227 * @init: called when the driver is initialized
228 * @exit: called to cleanup everything done in init
229 * @setup_clocks: called before touching any of the controller registers
230 * @setup_regulators: called before accessing the host controller
231 * @hce_enable_notify: called before and after HCE enable bit is set to allow
232 * variant specific Uni-Pro initialization.
233 * @link_startup_notify: called before and after Link startup is carried out
234 * to allow variant specific Uni-Pro initialization.
Subhash Jadavani57d104c2014-09-25 15:32:30 +0300235 * @suspend: called during host controller PM callback
236 * @resume: called during host controller PM callback
Sujit Reddy Thumma5c0c28a2014-09-25 15:32:21 +0300237 */
238struct ufs_hba_variant_ops {
239 const char *name;
240 int (*init)(struct ufs_hba *);
241 void (*exit)(struct ufs_hba *);
242 int (*setup_clocks)(struct ufs_hba *, bool);
243 int (*setup_regulators)(struct ufs_hba *, bool);
244 int (*hce_enable_notify)(struct ufs_hba *, bool);
245 int (*link_startup_notify)(struct ufs_hba *, bool);
Subhash Jadavani57d104c2014-09-25 15:32:30 +0300246 int (*suspend)(struct ufs_hba *, enum ufs_pm_op);
247 int (*resume)(struct ufs_hba *, enum ufs_pm_op);
Sujit Reddy Thumma5c0c28a2014-09-25 15:32:21 +0300248};
249
Vinayak Holikattie0eca632013-02-25 21:44:33 +0530250/**
Yaniv Gardi3a4bf062014-09-25 15:32:27 +0300251 * struct ufs_init_prefetch - contains data that is pre-fetched once during
252 * initialization
253 * @icc_level: icc level which was read during initialization
254 */
255struct ufs_init_prefetch {
256 u32 icc_level;
257};
258
259/**
Vinayak Holikattie0eca632013-02-25 21:44:33 +0530260 * struct ufs_hba - per adapter private structure
261 * @mmio_base: UFSHCI base register address
262 * @ucdl_base_addr: UFS Command Descriptor base address
263 * @utrdl_base_addr: UTP Transfer Request Descriptor base address
264 * @utmrdl_base_addr: UTP Task Management Descriptor base address
265 * @ucdl_dma_addr: UFS Command Descriptor DMA address
266 * @utrdl_dma_addr: UTRDL DMA address
267 * @utmrdl_dma_addr: UTMRDL DMA address
268 * @host: Scsi_Host instance of the driver
269 * @dev: device handle
270 * @lrb: local reference block
Sujit Reddy Thumma5a0b0cb2013-07-30 00:35:57 +0530271 * @lrb_in_use: lrb in use
Vinayak Holikattie0eca632013-02-25 21:44:33 +0530272 * @outstanding_tasks: Bits representing outstanding task requests
273 * @outstanding_reqs: Bits representing outstanding transfer requests
274 * @capabilities: UFS Controller Capabilities
275 * @nutrs: Transfer Request Queue depth supported by controller
276 * @nutmrs: Task Management Queue depth supported by controller
277 * @ufs_version: UFS Version to which controller complies
Sujit Reddy Thumma5c0c28a2014-09-25 15:32:21 +0300278 * @vops: pointer to variant specific operations
279 * @priv: pointer to variant specific private data
Vinayak Holikattie0eca632013-02-25 21:44:33 +0530280 * @irq: Irq number of the controller
281 * @active_uic_cmd: handle of active UIC command
Seungwon Jeon6ccf44fe2013-06-26 22:39:29 +0530282 * @uic_cmd_mutex: mutex for uic command
Sujit Reddy Thummae2933132014-05-26 10:59:12 +0530283 * @tm_wq: wait queue for task management
284 * @tm_tag_wq: wait queue for free task management slots
285 * @tm_slots_in_use: bit map of task management request slots in use
Seungwon Jeon53b3d9c2013-08-31 21:40:22 +0530286 * @pwr_done: completion for power mode change
Vinayak Holikattie0eca632013-02-25 21:44:33 +0530287 * @tm_condition: condition variable for task management
288 * @ufshcd_state: UFSHCD states
Sujit Reddy Thumma3441da72014-05-26 10:59:14 +0530289 * @eh_flags: Error handling flags
Seungwon Jeon2fbd0092013-06-26 22:39:27 +0530290 * @intr_mask: Interrupt Mask Bits
Sujit Reddy Thumma66ec6d52013-07-30 00:35:59 +0530291 * @ee_ctrl_mask: Exception event control mask
Sujit Reddy Thumma1d337ec2014-09-25 15:32:26 +0300292 * @is_powered: flag to check if HBA is powered
Yaniv Gardi3a4bf062014-09-25 15:32:27 +0300293 * @is_init_prefetch: flag to check if data was pre-fetched in initialization
294 * @init_prefetch_data: data pre-fetched during initialization
Sujit Reddy Thummae8e7f272014-05-26 10:59:15 +0530295 * @eh_work: Worker to handle UFS errors that require s/w attention
Sujit Reddy Thumma66ec6d52013-07-30 00:35:59 +0530296 * @eeh_work: Worker to handle exception events
Vinayak Holikattie0eca632013-02-25 21:44:33 +0530297 * @errors: HBA errors
Sujit Reddy Thummae8e7f272014-05-26 10:59:15 +0530298 * @uic_error: UFS interconnect layer error status
299 * @saved_err: sticky error mask
300 * @saved_uic_err: sticky UIC error mask
Sujit Reddy Thumma5a0b0cb2013-07-30 00:35:57 +0530301 * @dev_cmd: ufs device management command information
Sujit Reddy Thumma66ec6d52013-07-30 00:35:59 +0530302 * @auto_bkops_enabled: to track whether bkops is enabled in device
Sujit Reddy Thummaaa497612014-09-25 15:32:22 +0300303 * @vreg_info: UFS device voltage regulator information
Sujit Reddy Thummac6e79da2014-09-25 15:32:23 +0300304 * @clk_list_head: UFS host controller clocks list node head
Vinayak Holikattie0eca632013-02-25 21:44:33 +0530305 */
306struct ufs_hba {
307 void __iomem *mmio_base;
308
309 /* Virtual memory reference */
310 struct utp_transfer_cmd_desc *ucdl_base_addr;
311 struct utp_transfer_req_desc *utrdl_base_addr;
312 struct utp_task_req_desc *utmrdl_base_addr;
313
314 /* DMA memory reference */
315 dma_addr_t ucdl_dma_addr;
316 dma_addr_t utrdl_dma_addr;
317 dma_addr_t utmrdl_dma_addr;
318
319 struct Scsi_Host *host;
320 struct device *dev;
Subhash Jadavani2a8fa602014-09-25 15:32:28 +0300321 /*
322 * This field is to keep a reference to "scsi_device" corresponding to
323 * "UFS device" W-LU.
324 */
325 struct scsi_device *sdev_ufs_device;
326 struct scsi_device *sdev_rpmb;
327 struct scsi_device *sdev_boot;
Vinayak Holikattie0eca632013-02-25 21:44:33 +0530328
Subhash Jadavani57d104c2014-09-25 15:32:30 +0300329 enum ufs_dev_pwr_mode curr_dev_pwr_mode;
330 enum uic_link_state uic_link_state;
331 /* Desired UFS power management level during runtime PM */
332 enum ufs_pm_level rpm_lvl;
333 /* Desired UFS power management level during system PM */
334 enum ufs_pm_level spm_lvl;
335 int pm_op_in_progress;
336
Vinayak Holikattie0eca632013-02-25 21:44:33 +0530337 struct ufshcd_lrb *lrb;
Sujit Reddy Thumma5a0b0cb2013-07-30 00:35:57 +0530338 unsigned long lrb_in_use;
Vinayak Holikattie0eca632013-02-25 21:44:33 +0530339
340 unsigned long outstanding_tasks;
341 unsigned long outstanding_reqs;
342
343 u32 capabilities;
344 int nutrs;
345 int nutmrs;
346 u32 ufs_version;
Sujit Reddy Thumma5c0c28a2014-09-25 15:32:21 +0300347 struct ufs_hba_variant_ops *vops;
348 void *priv;
Vinayak Holikattie0eca632013-02-25 21:44:33 +0530349 unsigned int irq;
Subhash Jadavani57d104c2014-09-25 15:32:30 +0300350 bool is_irq_enabled;
Vinayak Holikattie0eca632013-02-25 21:44:33 +0530351
Seungwon Jeon6ccf44fe2013-06-26 22:39:29 +0530352
Sujit Reddy Thummae2933132014-05-26 10:59:12 +0530353 wait_queue_head_t tm_wq;
354 wait_queue_head_t tm_tag_wq;
Vinayak Holikattie0eca632013-02-25 21:44:33 +0530355 unsigned long tm_condition;
Sujit Reddy Thummae2933132014-05-26 10:59:12 +0530356 unsigned long tm_slots_in_use;
Vinayak Holikattie0eca632013-02-25 21:44:33 +0530357
Subhash Jadavani57d104c2014-09-25 15:32:30 +0300358 struct uic_command *active_uic_cmd;
359 struct mutex uic_cmd_mutex;
360 struct completion *uic_async_done;
Seungwon Jeon53b3d9c2013-08-31 21:40:22 +0530361
Vinayak Holikattie0eca632013-02-25 21:44:33 +0530362 u32 ufshcd_state;
Sujit Reddy Thumma3441da72014-05-26 10:59:14 +0530363 u32 eh_flags;
Seungwon Jeon2fbd0092013-06-26 22:39:27 +0530364 u32 intr_mask;
Sujit Reddy Thumma66ec6d52013-07-30 00:35:59 +0530365 u16 ee_ctrl_mask;
Sujit Reddy Thumma1d337ec2014-09-25 15:32:26 +0300366 bool is_powered;
Yaniv Gardi3a4bf062014-09-25 15:32:27 +0300367 bool is_init_prefetch;
368 struct ufs_init_prefetch init_prefetch_data;
Vinayak Holikattie0eca632013-02-25 21:44:33 +0530369
370 /* Work Queues */
Sujit Reddy Thummae8e7f272014-05-26 10:59:15 +0530371 struct work_struct eh_work;
Sujit Reddy Thumma66ec6d52013-07-30 00:35:59 +0530372 struct work_struct eeh_work;
Vinayak Holikattie0eca632013-02-25 21:44:33 +0530373
374 /* HBA Errors */
375 u32 errors;
Sujit Reddy Thummae8e7f272014-05-26 10:59:15 +0530376 u32 uic_error;
377 u32 saved_err;
378 u32 saved_uic_err;
Sujit Reddy Thumma5a0b0cb2013-07-30 00:35:57 +0530379
380 /* Device management request data */
381 struct ufs_dev_cmd dev_cmd;
Sujit Reddy Thumma66ec6d52013-07-30 00:35:59 +0530382
Subhash Jadavani57d104c2014-09-25 15:32:30 +0300383 /* Keeps information of the UFS device connected to this host */
384 struct ufs_dev_info dev_info;
Sujit Reddy Thumma66ec6d52013-07-30 00:35:59 +0530385 bool auto_bkops_enabled;
Sujit Reddy Thummaaa497612014-09-25 15:32:22 +0300386 struct ufs_vreg_info vreg_info;
Sujit Reddy Thummac6e79da2014-09-25 15:32:23 +0300387 struct list_head clk_list_head;
Subhash Jadavani57d104c2014-09-25 15:32:30 +0300388
389 bool wlun_dev_clr_ua;
Vinayak Holikattie0eca632013-02-25 21:44:33 +0530390};
391
Seungwon Jeonb873a2752013-06-26 22:39:26 +0530392#define ufshcd_writel(hba, val, reg) \
393 writel((val), (hba)->mmio_base + (reg))
394#define ufshcd_readl(hba, reg) \
395 readl((hba)->mmio_base + (reg))
396
Sujit Reddy Thumma5c0c28a2014-09-25 15:32:21 +0300397int ufshcd_alloc_host(struct device *, struct ufs_hba **);
398int ufshcd_init(struct ufs_hba * , void __iomem * , unsigned int);
Vinayak Holikattie0eca632013-02-25 21:44:33 +0530399void ufshcd_remove(struct ufs_hba *);
400
401/**
402 * ufshcd_hba_stop - Send controller to reset state
403 * @hba: per adapter instance
404 */
405static inline void ufshcd_hba_stop(struct ufs_hba *hba)
406{
Seungwon Jeonb873a2752013-06-26 22:39:26 +0530407 ufshcd_writel(hba, CONTROLLER_DISABLE, REG_CONTROLLER_ENABLE);
Vinayak Holikattie0eca632013-02-25 21:44:33 +0530408}
409
Dolev Raviv68078d52013-07-30 00:35:58 +0530410static inline void check_upiu_size(void)
411{
412 BUILD_BUG_ON(ALIGNED_UPIU_SIZE <
413 GENERAL_UPIU_REQUEST_SIZE + QUERY_DESC_MAX_SIZE);
414}
415
Sujit Reddy Thumma66ec6d52013-07-30 00:35:59 +0530416extern int ufshcd_runtime_suspend(struct ufs_hba *hba);
417extern int ufshcd_runtime_resume(struct ufs_hba *hba);
418extern int ufshcd_runtime_idle(struct ufs_hba *hba);
Subhash Jadavani57d104c2014-09-25 15:32:30 +0300419extern int ufshcd_system_suspend(struct ufs_hba *hba);
420extern int ufshcd_system_resume(struct ufs_hba *hba);
421extern int ufshcd_shutdown(struct ufs_hba *hba);
Seungwon Jeon12b4fdb2013-08-31 21:40:21 +0530422extern int ufshcd_dme_set_attr(struct ufs_hba *hba, u32 attr_sel,
423 u8 attr_set, u32 mib_val, u8 peer);
424extern int ufshcd_dme_get_attr(struct ufs_hba *hba, u32 attr_sel,
425 u32 *mib_val, u8 peer);
426
427/* UIC command interfaces for DME primitives */
428#define DME_LOCAL 0
429#define DME_PEER 1
430#define ATTR_SET_NOR 0 /* NORMAL */
431#define ATTR_SET_ST 1 /* STATIC */
432
433static inline int ufshcd_dme_set(struct ufs_hba *hba, u32 attr_sel,
434 u32 mib_val)
435{
436 return ufshcd_dme_set_attr(hba, attr_sel, ATTR_SET_NOR,
437 mib_val, DME_LOCAL);
438}
439
440static inline int ufshcd_dme_st_set(struct ufs_hba *hba, u32 attr_sel,
441 u32 mib_val)
442{
443 return ufshcd_dme_set_attr(hba, attr_sel, ATTR_SET_ST,
444 mib_val, DME_LOCAL);
445}
446
447static inline int ufshcd_dme_peer_set(struct ufs_hba *hba, u32 attr_sel,
448 u32 mib_val)
449{
450 return ufshcd_dme_set_attr(hba, attr_sel, ATTR_SET_NOR,
451 mib_val, DME_PEER);
452}
453
454static inline int ufshcd_dme_peer_st_set(struct ufs_hba *hba, u32 attr_sel,
455 u32 mib_val)
456{
457 return ufshcd_dme_set_attr(hba, attr_sel, ATTR_SET_ST,
458 mib_val, DME_PEER);
459}
460
461static inline int ufshcd_dme_get(struct ufs_hba *hba,
462 u32 attr_sel, u32 *mib_val)
463{
464 return ufshcd_dme_get_attr(hba, attr_sel, mib_val, DME_LOCAL);
465}
466
467static inline int ufshcd_dme_peer_get(struct ufs_hba *hba,
468 u32 attr_sel, u32 *mib_val)
469{
470 return ufshcd_dme_get_attr(hba, attr_sel, mib_val, DME_PEER);
471}
472
Vinayak Holikattie0eca632013-02-25 21:44:33 +0530473#endif /* End of Header */