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