]> git.karo-electronics.de Git - karo-tx-linux.git/blob - drivers/scsi/ufs/ufshcd.h
[SCSI] ufs: Add support for sending NOP OUT UPIU
[karo-tx-linux.git] / drivers / scsi / ufs / ufshcd.h
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
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>
54 #include <linux/completion.h>
55
56 #include <asm/irq.h>
57 #include <asm/byteorder.h>
58 #include <scsi/scsi.h>
59 #include <scsi/scsi_cmnd.h>
60 #include <scsi/scsi_host.h>
61 #include <scsi/scsi_tcq.h>
62 #include <scsi/scsi_dbg.h>
63 #include <scsi/scsi_eh.h>
64
65 #include "ufs.h"
66 #include "ufshci.h"
67
68 #define UFSHCD "ufshcd"
69 #define UFSHCD_DRIVER_VERSION "0.2"
70
71 enum dev_cmd_type {
72         DEV_CMD_TYPE_NOP                = 0x0,
73 };
74
75 /**
76  * struct uic_command - UIC command structure
77  * @command: UIC command
78  * @argument1: UIC command argument 1
79  * @argument2: UIC command argument 2
80  * @argument3: UIC command argument 3
81  * @cmd_active: Indicate if UIC command is outstanding
82  * @result: UIC command result
83  * @done: UIC command completion
84  */
85 struct uic_command {
86         u32 command;
87         u32 argument1;
88         u32 argument2;
89         u32 argument3;
90         int cmd_active;
91         int result;
92         struct completion done;
93 };
94
95 /**
96  * struct ufshcd_lrb - local reference block
97  * @utr_descriptor_ptr: UTRD address of the command
98  * @ucd_req_ptr: UCD address of the command
99  * @ucd_rsp_ptr: Response UPIU address for this command
100  * @ucd_prdt_ptr: PRDT address of the command
101  * @cmd: pointer to SCSI command
102  * @sense_buffer: pointer to sense buffer address of the SCSI command
103  * @sense_bufflen: Length of the sense buffer
104  * @scsi_status: SCSI status of the command
105  * @command_type: SCSI, UFS, Query.
106  * @task_tag: Task tag of the command
107  * @lun: LUN of the command
108  * @intr_cmd: Interrupt command (doesn't participate in interrupt aggregation)
109  */
110 struct ufshcd_lrb {
111         struct utp_transfer_req_desc *utr_descriptor_ptr;
112         struct utp_upiu_req *ucd_req_ptr;
113         struct utp_upiu_rsp *ucd_rsp_ptr;
114         struct ufshcd_sg_entry *ucd_prdt_ptr;
115
116         struct scsi_cmnd *cmd;
117         u8 *sense_buffer;
118         unsigned int sense_bufflen;
119         int scsi_status;
120
121         int command_type;
122         int task_tag;
123         unsigned int lun;
124         bool intr_cmd;
125 };
126
127 /**
128  * struct ufs_dev_cmd - all assosiated fields with device management commands
129  * @type: device management command type - Query, NOP OUT
130  * @lock: lock to allow one command at a time
131  * @complete: internal commands completion
132  * @tag_wq: wait queue until free command slot is available
133  */
134 struct ufs_dev_cmd {
135         enum dev_cmd_type type;
136         struct mutex lock;
137         struct completion *complete;
138         wait_queue_head_t tag_wq;
139 };
140
141 /**
142  * struct ufs_hba - per adapter private structure
143  * @mmio_base: UFSHCI base register address
144  * @ucdl_base_addr: UFS Command Descriptor base address
145  * @utrdl_base_addr: UTP Transfer Request Descriptor base address
146  * @utmrdl_base_addr: UTP Task Management Descriptor base address
147  * @ucdl_dma_addr: UFS Command Descriptor DMA address
148  * @utrdl_dma_addr: UTRDL DMA address
149  * @utmrdl_dma_addr: UTMRDL DMA address
150  * @host: Scsi_Host instance of the driver
151  * @dev: device handle
152  * @lrb: local reference block
153  * @lrb_in_use: lrb in use
154  * @outstanding_tasks: Bits representing outstanding task requests
155  * @outstanding_reqs: Bits representing outstanding transfer requests
156  * @capabilities: UFS Controller Capabilities
157  * @nutrs: Transfer Request Queue depth supported by controller
158  * @nutmrs: Task Management Queue depth supported by controller
159  * @ufs_version: UFS Version to which controller complies
160  * @irq: Irq number of the controller
161  * @active_uic_cmd: handle of active UIC command
162  * @uic_cmd_mutex: mutex for uic command
163  * @ufshcd_tm_wait_queue: wait queue for task management
164  * @tm_condition: condition variable for task management
165  * @ufshcd_state: UFSHCD states
166  * @intr_mask: Interrupt Mask Bits
167  * @feh_workq: Work queue for fatal controller error handling
168  * @errors: HBA errors
169  * @dev_cmd: ufs device management command information
170  */
171 struct ufs_hba {
172         void __iomem *mmio_base;
173
174         /* Virtual memory reference */
175         struct utp_transfer_cmd_desc *ucdl_base_addr;
176         struct utp_transfer_req_desc *utrdl_base_addr;
177         struct utp_task_req_desc *utmrdl_base_addr;
178
179         /* DMA memory reference */
180         dma_addr_t ucdl_dma_addr;
181         dma_addr_t utrdl_dma_addr;
182         dma_addr_t utmrdl_dma_addr;
183
184         struct Scsi_Host *host;
185         struct device *dev;
186
187         struct ufshcd_lrb *lrb;
188         unsigned long lrb_in_use;
189
190         unsigned long outstanding_tasks;
191         unsigned long outstanding_reqs;
192
193         u32 capabilities;
194         int nutrs;
195         int nutmrs;
196         u32 ufs_version;
197         unsigned int irq;
198
199         struct uic_command *active_uic_cmd;
200         struct mutex uic_cmd_mutex;
201
202         wait_queue_head_t ufshcd_tm_wait_queue;
203         unsigned long tm_condition;
204
205         u32 ufshcd_state;
206         u32 intr_mask;
207
208         /* Work Queues */
209         struct work_struct feh_workq;
210
211         /* HBA Errors */
212         u32 errors;
213
214         /* Device management request data */
215         struct ufs_dev_cmd dev_cmd;
216 };
217
218 #define ufshcd_writel(hba, val, reg)    \
219         writel((val), (hba)->mmio_base + (reg))
220 #define ufshcd_readl(hba, reg)  \
221         readl((hba)->mmio_base + (reg))
222
223 int ufshcd_init(struct device *, struct ufs_hba ** , void __iomem * ,
224                         unsigned int);
225 void ufshcd_remove(struct ufs_hba *);
226
227 /**
228  * ufshcd_hba_stop - Send controller to reset state
229  * @hba: per adapter instance
230  */
231 static inline void ufshcd_hba_stop(struct ufs_hba *hba)
232 {
233         ufshcd_writel(hba, CONTROLLER_DISABLE,  REG_CONTROLLER_ENABLE);
234 }
235
236 #endif /* End of Header */