Merge tag 'char-misc-4.6-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh...
[linux-2.6-block.git] / drivers / scsi / hisi_sas / hisi_sas.h
CommitLineData
e8899fad
JG
1/*
2 * Copyright (c) 2015 Linaro Ltd.
3 * Copyright (c) 2015 Hisilicon Limited.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 */
11
12#ifndef _HISI_SAS_H_
13#define _HISI_SAS_H_
14
4d558c77 15#include <linux/acpi.h>
e8899fad
JG
16#include <linux/dmapool.h>
17#include <linux/mfd/syscon.h>
18#include <linux/module.h>
19#include <linux/of_address.h>
e8899fad 20#include <linux/platform_device.h>
4d558c77 21#include <linux/property.h>
e8899fad 22#include <linux/regmap.h>
6f2ff1a1 23#include <scsi/sas_ata.h>
e8899fad
JG
24#include <scsi/libsas.h>
25
268d11e9 26#define DRV_VERSION "v1.3"
e8899fad 27
7eb7869f 28#define HISI_SAS_MAX_PHYS 9
6be6de18
JG
29#define HISI_SAS_MAX_QUEUES 32
30#define HISI_SAS_QUEUE_SLOTS 512
5560e9fb 31#define HISI_SAS_MAX_ITCT_ENTRIES 2048
7eb7869f 32#define HISI_SAS_MAX_DEVICES HISI_SAS_MAX_ITCT_ENTRIES
7eb7869f 33
6be6de18
JG
34#define HISI_SAS_STATUS_BUF_SZ \
35 (sizeof(struct hisi_sas_err_record) + 1024)
36#define HISI_SAS_COMMAND_TABLE_SZ \
37 (((sizeof(union hisi_sas_command_table)+3)/4)*4)
38
42e7a693 39#define HISI_SAS_MAX_SSP_RESP_SZ (sizeof(struct ssp_frame_hdr) + 1024)
66ee999b 40#define HISI_SAS_MAX_SMP_RESP_SZ 1028
6f2ff1a1 41#define HISI_SAS_MAX_STP_RESP_SZ 28
42e7a693 42
98bf39fc
JG
43#define DEV_IS_EXPANDER(type) \
44 ((type == SAS_EDGE_EXPANDER_DEVICE) || \
45 (type == SAS_FANOUT_EXPANDER_DEVICE))
46
abda97c2 47struct hisi_hba;
af740dbe 48
07d78592
JG
49enum {
50 PORT_TYPE_SAS = (1U << 1),
51 PORT_TYPE_SATA = (1U << 0),
52};
53
af740dbe
JG
54enum dev_status {
55 HISI_SAS_DEV_NORMAL,
56 HISI_SAS_DEV_EH,
57};
abda97c2
JG
58
59enum hisi_sas_dev_type {
60 HISI_SAS_DEV_TYPE_STP = 0,
61 HISI_SAS_DEV_TYPE_SSP,
62 HISI_SAS_DEV_TYPE_SATA,
63};
64
7eb7869f 65struct hisi_sas_phy {
976867e6
JG
66 struct hisi_hba *hisi_hba;
67 struct hisi_sas_port *port;
7eb7869f 68 struct asd_sas_phy sas_phy;
976867e6
JG
69 struct sas_identify identify;
70 struct timer_list timer;
66139921 71 struct work_struct phyup_ws;
976867e6 72 u64 port_id; /* from hw */
5d74242e 73 u64 dev_sas_addr;
976867e6
JG
74 u64 phy_type;
75 u64 frame_rcvd_size;
76 u8 frame_rcvd[32];
77 u8 phy_attached;
78 u8 reserved[3];
79 enum sas_linkrate minimum_linkrate;
80 enum sas_linkrate maximum_linkrate;
7eb7869f
JG
81};
82
83struct hisi_sas_port {
84 struct asd_sas_port sas_port;
976867e6
JG
85 u8 port_attached;
86 u8 id; /* from hw */
87 struct list_head list;
7eb7869f
JG
88};
89
9101a079
JG
90struct hisi_sas_cq {
91 struct hisi_hba *hisi_hba;
92 int id;
93};
94
af740dbe
JG
95struct hisi_sas_device {
96 enum sas_device_type dev_type;
abda97c2
JG
97 struct hisi_hba *hisi_hba;
98 struct domain_device *sas_device;
99 u64 attached_phy;
af740dbe 100 u64 device_id;
42e7a693 101 u64 running_req;
af740dbe
JG
102 u8 dev_status;
103};
104
6be6de18 105struct hisi_sas_slot {
42e7a693
JG
106 struct list_head entry;
107 struct sas_task *task;
108 struct hisi_sas_port *port;
109 u64 n_elem;
110 int dlvry_queue;
111 int dlvry_queue_slot;
27a3f229
JG
112 int cmplt_queue;
113 int cmplt_queue_slot;
42e7a693 114 int idx;
cac9b2a2 115 int abort;
42e7a693
JG
116 void *cmd_hdr;
117 dma_addr_t cmd_hdr_dma;
118 void *status_buffer;
119 dma_addr_t status_buffer_dma;
120 void *command_table;
121 dma_addr_t command_table_dma;
122 struct hisi_sas_sge_page *sge_page;
123 dma_addr_t sge_page_dma;
cac9b2a2 124 struct work_struct abort_slot;
42e7a693
JG
125};
126
127struct hisi_sas_tmf_task {
128 u8 tmf;
129 u16 tag_of_task_to_be_managed;
6be6de18
JG
130};
131
7eb7869f 132struct hisi_sas_hw {
8ff1d571 133 int (*hw_init)(struct hisi_hba *hisi_hba);
abda97c2
JG
134 void (*setup_itct)(struct hisi_hba *hisi_hba,
135 struct hisi_sas_device *device);
66139921 136 void (*sl_notify)(struct hisi_hba *hisi_hba, int phy_no);
42e7a693
JG
137 int (*get_free_slot)(struct hisi_hba *hisi_hba, int *q, int *s);
138 void (*start_delivery)(struct hisi_hba *hisi_hba);
139 int (*prep_ssp)(struct hisi_hba *hisi_hba,
140 struct hisi_sas_slot *slot, int is_tmf,
141 struct hisi_sas_tmf_task *tmf);
66ee999b
JG
142 int (*prep_smp)(struct hisi_hba *hisi_hba,
143 struct hisi_sas_slot *slot);
6f2ff1a1
JG
144 int (*prep_stp)(struct hisi_hba *hisi_hba,
145 struct hisi_sas_slot *slot);
27a3f229
JG
146 int (*slot_complete)(struct hisi_hba *hisi_hba,
147 struct hisi_sas_slot *slot, int abort);
e4189d53
JG
148 void (*phy_enable)(struct hisi_hba *hisi_hba, int phy_no);
149 void (*phy_disable)(struct hisi_hba *hisi_hba, int phy_no);
150 void (*phy_hard_reset)(struct hisi_hba *hisi_hba, int phy_no);
27a3f229
JG
151 void (*free_device)(struct hisi_hba *hisi_hba,
152 struct hisi_sas_device *dev);
184a4635 153 int (*get_wideport_bitmap)(struct hisi_hba *hisi_hba, int port_id);
a8d547bd 154 int max_command_entries;
6be6de18 155 int complete_hdr_size;
7eb7869f
JG
156};
157
158struct hisi_hba {
159 /* This must be the first element, used by SHOST_TO_SAS_HA */
160 struct sas_ha_struct *p;
161
162 struct platform_device *pdev;
e26b2f40
JG
163 void __iomem *regs;
164 struct regmap *ctrl;
165 u32 ctrl_reset_reg;
166 u32 ctrl_reset_sts_reg;
167 u32 ctrl_clock_ena_reg;
7eb7869f
JG
168 u8 sas_addr[SAS_ADDR_SIZE];
169
170 int n_phy;
701f75ec 171 int scan_finished;
fa42d80d 172 spinlock_t lock;
7eb7869f 173
fa42d80d 174 struct timer_list timer;
7e9080e1 175 struct workqueue_struct *wq;
257efd1f
JG
176
177 int slot_index_count;
178 unsigned long *slot_index_tags;
179
7eb7869f
JG
180 /* SCSI/SAS glue */
181 struct sas_ha_struct sha;
182 struct Scsi_Host *shost;
9101a079
JG
183
184 struct hisi_sas_cq cq[HISI_SAS_MAX_QUEUES];
7eb7869f
JG
185 struct hisi_sas_phy phy[HISI_SAS_MAX_PHYS];
186 struct hisi_sas_port port[HISI_SAS_MAX_PHYS];
e26b2f40
JG
187
188 int queue_count;
42e7a693 189 int queue;
42e7a693 190 struct hisi_sas_slot *slot_prep;
6be6de18
JG
191
192 struct dma_pool *sge_page_pool;
af740dbe 193 struct hisi_sas_device devices[HISI_SAS_MAX_DEVICES];
6be6de18
JG
194 struct dma_pool *command_table_pool;
195 struct dma_pool *status_buffer_pool;
196 struct hisi_sas_cmd_hdr *cmd_hdr[HISI_SAS_MAX_QUEUES];
197 dma_addr_t cmd_hdr_dma[HISI_SAS_MAX_QUEUES];
198 void *complete_hdr[HISI_SAS_MAX_QUEUES];
199 dma_addr_t complete_hdr_dma[HISI_SAS_MAX_QUEUES];
200 struct hisi_sas_initial_fis *initial_fis;
201 dma_addr_t initial_fis_dma;
202 struct hisi_sas_itct *itct;
203 dma_addr_t itct_dma;
204 struct hisi_sas_iost *iost;
205 dma_addr_t iost_dma;
206 struct hisi_sas_breakpoint *breakpoint;
207 dma_addr_t breakpoint_dma;
208 struct hisi_sas_breakpoint *sata_breakpoint;
209 dma_addr_t sata_breakpoint_dma;
210 struct hisi_sas_slot *slot_info;
7eb7869f
JG
211 const struct hisi_sas_hw *hw; /* Low level hw interface */
212};
213
c799d6bd
JG
214/* Generic HW DMA host memory structures */
215/* Delivery queue header */
216struct hisi_sas_cmd_hdr {
217 /* dw0 */
218 __le32 dw0;
219
220 /* dw1 */
221 __le32 dw1;
222
223 /* dw2 */
224 __le32 dw2;
225
226 /* dw3 */
227 __le32 transfer_tags;
228
229 /* dw4 */
230 __le32 data_transfer_len;
231
232 /* dw5 */
233 __le32 first_burst_num;
234
235 /* dw6 */
236 __le32 sg_len;
237
238 /* dw7 */
239 __le32 dw7;
240
241 /* dw8-9 */
242 __le64 cmd_table_addr;
243
244 /* dw10-11 */
245 __le64 sts_buffer_addr;
246
247 /* dw12-13 */
248 __le64 prd_table_addr;
249
250 /* dw14-15 */
251 __le64 dif_prd_table_addr;
252};
253
254struct hisi_sas_itct {
255 __le64 qw0;
256 __le64 sas_addr;
257 __le64 qw2;
258 __le64 qw3;
281e3bf6 259 __le64 qw4_15[12];
c799d6bd
JG
260};
261
262struct hisi_sas_iost {
263 __le64 qw0;
264 __le64 qw1;
265 __le64 qw2;
266 __le64 qw3;
267};
268
269struct hisi_sas_err_record {
8d1eee7d 270 u32 data[4];
c799d6bd
JG
271};
272
273struct hisi_sas_initial_fis {
274 struct hisi_sas_err_record err_record;
275 struct dev_to_host_fis fis;
276 u32 rsvd[3];
277};
278
279struct hisi_sas_breakpoint {
280 u8 data[128]; /*io128 byte*/
281};
282
283struct hisi_sas_sge {
284 __le64 addr;
285 __le32 page_ctrl_0;
286 __le32 page_ctrl_1;
287 __le32 data_len;
288 __le32 data_off;
289};
290
291struct hisi_sas_command_table_smp {
292 u8 bytes[44];
293};
294
295struct hisi_sas_command_table_stp {
296 struct host_to_dev_fis command_fis;
297 u8 dummy[12];
298 u8 atapi_cdb[ATAPI_CDB_LEN];
299};
300
7eb7869f 301#define HISI_SAS_SGE_PAGE_CNT SCSI_MAX_SG_SEGMENTS
c799d6bd
JG
302struct hisi_sas_sge_page {
303 struct hisi_sas_sge sge[HISI_SAS_SGE_PAGE_CNT];
304};
305
306struct hisi_sas_command_table_ssp {
307 struct ssp_frame_hdr hdr;
308 union {
309 struct {
310 struct ssp_command_iu task;
311 u32 prot[6];
312 };
313 struct ssp_tmf_iu ssp_task;
314 struct xfer_rdy_iu xfer_rdy;
315 struct ssp_response_iu ssp_res;
316 } u;
317};
318
319union hisi_sas_command_table {
320 struct hisi_sas_command_table_ssp ssp;
321 struct hisi_sas_command_table_smp smp;
322 struct hisi_sas_command_table_stp stp;
323};
9fb10b54
JG
324extern int hisi_sas_probe(struct platform_device *pdev,
325 const struct hisi_sas_hw *ops);
326extern int hisi_sas_remove(struct platform_device *pdev);
c799d6bd 327
184a4635 328extern void hisi_sas_phy_down(struct hisi_hba *hisi_hba, int phy_no, int rdy);
27a3f229
JG
329extern void hisi_sas_slot_task_free(struct hisi_hba *hisi_hba,
330 struct sas_task *task,
331 struct hisi_sas_slot *slot);
e8899fad 332#endif