]>
Commit | Line | Data |
---|---|---|
e0eca63e VH |
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> | |
6ccf44fe | 54 | #include <linux/completion.h> |
e0eca63e VH |
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 | /** | |
72 | * struct uic_command - UIC command structure | |
73 | * @command: UIC command | |
74 | * @argument1: UIC command argument 1 | |
75 | * @argument2: UIC command argument 2 | |
76 | * @argument3: UIC command argument 3 | |
77 | * @cmd_active: Indicate if UIC command is outstanding | |
78 | * @result: UIC command result | |
6ccf44fe | 79 | * @done: UIC command completion |
e0eca63e VH |
80 | */ |
81 | struct uic_command { | |
82 | u32 command; | |
83 | u32 argument1; | |
84 | u32 argument2; | |
85 | u32 argument3; | |
86 | int cmd_active; | |
87 | int result; | |
6ccf44fe | 88 | struct completion done; |
e0eca63e VH |
89 | }; |
90 | ||
91 | /** | |
92 | * struct ufshcd_lrb - local reference block | |
93 | * @utr_descriptor_ptr: UTRD address of the command | |
94 | * @ucd_cmd_ptr: UCD address of the command | |
95 | * @ucd_rsp_ptr: Response UPIU address for this command | |
96 | * @ucd_prdt_ptr: PRDT address of the command | |
97 | * @cmd: pointer to SCSI command | |
98 | * @sense_buffer: pointer to sense buffer address of the SCSI command | |
99 | * @sense_bufflen: Length of the sense buffer | |
100 | * @scsi_status: SCSI status of the command | |
101 | * @command_type: SCSI, UFS, Query. | |
102 | * @task_tag: Task tag of the command | |
103 | * @lun: LUN of the command | |
104 | */ | |
105 | struct ufshcd_lrb { | |
106 | struct utp_transfer_req_desc *utr_descriptor_ptr; | |
107 | struct utp_upiu_cmd *ucd_cmd_ptr; | |
108 | struct utp_upiu_rsp *ucd_rsp_ptr; | |
109 | struct ufshcd_sg_entry *ucd_prdt_ptr; | |
110 | ||
111 | struct scsi_cmnd *cmd; | |
112 | u8 *sense_buffer; | |
113 | unsigned int sense_bufflen; | |
114 | int scsi_status; | |
115 | ||
116 | int command_type; | |
117 | int task_tag; | |
118 | unsigned int lun; | |
119 | }; | |
120 | ||
121 | ||
122 | /** | |
123 | * struct ufs_hba - per adapter private structure | |
124 | * @mmio_base: UFSHCI base register address | |
125 | * @ucdl_base_addr: UFS Command Descriptor base address | |
126 | * @utrdl_base_addr: UTP Transfer Request Descriptor base address | |
127 | * @utmrdl_base_addr: UTP Task Management Descriptor base address | |
128 | * @ucdl_dma_addr: UFS Command Descriptor DMA address | |
129 | * @utrdl_dma_addr: UTRDL DMA address | |
130 | * @utmrdl_dma_addr: UTMRDL DMA address | |
131 | * @host: Scsi_Host instance of the driver | |
132 | * @dev: device handle | |
133 | * @lrb: local reference block | |
134 | * @outstanding_tasks: Bits representing outstanding task requests | |
135 | * @outstanding_reqs: Bits representing outstanding transfer requests | |
136 | * @capabilities: UFS Controller Capabilities | |
137 | * @nutrs: Transfer Request Queue depth supported by controller | |
138 | * @nutmrs: Task Management Queue depth supported by controller | |
139 | * @ufs_version: UFS Version to which controller complies | |
140 | * @irq: Irq number of the controller | |
141 | * @active_uic_cmd: handle of active UIC command | |
6ccf44fe | 142 | * @uic_cmd_mutex: mutex for uic command |
e0eca63e VH |
143 | * @ufshcd_tm_wait_queue: wait queue for task management |
144 | * @tm_condition: condition variable for task management | |
145 | * @ufshcd_state: UFSHCD states | |
2fbd009b | 146 | * @intr_mask: Interrupt Mask Bits |
e0eca63e VH |
147 | * @feh_workq: Work queue for fatal controller error handling |
148 | * @errors: HBA errors | |
149 | */ | |
150 | struct ufs_hba { | |
151 | void __iomem *mmio_base; | |
152 | ||
153 | /* Virtual memory reference */ | |
154 | struct utp_transfer_cmd_desc *ucdl_base_addr; | |
155 | struct utp_transfer_req_desc *utrdl_base_addr; | |
156 | struct utp_task_req_desc *utmrdl_base_addr; | |
157 | ||
158 | /* DMA memory reference */ | |
159 | dma_addr_t ucdl_dma_addr; | |
160 | dma_addr_t utrdl_dma_addr; | |
161 | dma_addr_t utmrdl_dma_addr; | |
162 | ||
163 | struct Scsi_Host *host; | |
164 | struct device *dev; | |
165 | ||
166 | struct ufshcd_lrb *lrb; | |
167 | ||
168 | unsigned long outstanding_tasks; | |
169 | unsigned long outstanding_reqs; | |
170 | ||
171 | u32 capabilities; | |
172 | int nutrs; | |
173 | int nutmrs; | |
174 | u32 ufs_version; | |
175 | unsigned int irq; | |
176 | ||
6ccf44fe SJ |
177 | struct uic_command *active_uic_cmd; |
178 | struct mutex uic_cmd_mutex; | |
179 | ||
e0eca63e VH |
180 | wait_queue_head_t ufshcd_tm_wait_queue; |
181 | unsigned long tm_condition; | |
182 | ||
183 | u32 ufshcd_state; | |
2fbd009b | 184 | u32 intr_mask; |
e0eca63e VH |
185 | |
186 | /* Work Queues */ | |
e0eca63e VH |
187 | struct work_struct feh_workq; |
188 | ||
189 | /* HBA Errors */ | |
190 | u32 errors; | |
191 | }; | |
192 | ||
b873a275 SJ |
193 | #define ufshcd_writel(hba, val, reg) \ |
194 | writel((val), (hba)->mmio_base + (reg)) | |
195 | #define ufshcd_readl(hba, reg) \ | |
196 | readl((hba)->mmio_base + (reg)) | |
197 | ||
e0eca63e VH |
198 | int ufshcd_init(struct device *, struct ufs_hba ** , void __iomem * , |
199 | unsigned int); | |
200 | void ufshcd_remove(struct ufs_hba *); | |
201 | ||
202 | /** | |
203 | * ufshcd_hba_stop - Send controller to reset state | |
204 | * @hba: per adapter instance | |
205 | */ | |
206 | static inline void ufshcd_hba_stop(struct ufs_hba *hba) | |
207 | { | |
b873a275 | 208 | ufshcd_writel(hba, CONTROLLER_DISABLE, REG_CONTROLLER_ENABLE); |
e0eca63e VH |
209 | } |
210 | ||
211 | #endif /* End of Header */ |