ba3bf5eed74559bb01eb68301a7aa2bfa5fc2887
[sfrench/cifs-2.6.git] / drivers / scsi / hisi_sas / hisi_sas.h
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
15 #include <linux/dmapool.h>
16 #include <linux/mfd/syscon.h>
17 #include <linux/module.h>
18 #include <linux/of_address.h>
19 #include <linux/of_irq.h>
20 #include <linux/platform_device.h>
21 #include <linux/regmap.h>
22 #include <scsi/libsas.h>
23
24 #define DRV_VERSION "v1.0"
25
26 #define HISI_SAS_MAX_PHYS       9
27 #define HISI_SAS_MAX_QUEUES     32
28 #define HISI_SAS_QUEUE_SLOTS 512
29 #define HISI_SAS_MAX_ITCT_ENTRIES 4096
30 #define HISI_SAS_MAX_DEVICES HISI_SAS_MAX_ITCT_ENTRIES
31 #define HISI_SAS_COMMAND_ENTRIES 8192
32
33 #define HISI_SAS_STATUS_BUF_SZ \
34                 (sizeof(struct hisi_sas_err_record) + 1024)
35 #define HISI_SAS_COMMAND_TABLE_SZ \
36                 (((sizeof(union hisi_sas_command_table)+3)/4)*4)
37
38 #define HISI_SAS_NAME_LEN 32
39
40
41 enum dev_status {
42         HISI_SAS_DEV_NORMAL,
43         HISI_SAS_DEV_EH,
44 };
45 struct hisi_sas_phy {
46         struct hisi_hba *hisi_hba;
47         struct hisi_sas_port    *port;
48         struct asd_sas_phy      sas_phy;
49         struct sas_identify     identify;
50         struct timer_list       timer;
51         u64             port_id; /* from hw */
52         u64             dev_sas_addr;
53         u64             phy_type;
54         u64             frame_rcvd_size;
55         u8              frame_rcvd[32];
56         u8              phy_attached;
57         u8              reserved[3];
58         enum sas_linkrate       minimum_linkrate;
59         enum sas_linkrate       maximum_linkrate;
60 };
61
62 struct hisi_sas_port {
63         struct asd_sas_port     sas_port;
64         u8      port_attached;
65         u8      id; /* from hw */
66         struct list_head        list;
67 };
68
69 struct hisi_sas_cq {
70         struct hisi_hba *hisi_hba;
71         int     id;
72 };
73
74 struct hisi_sas_device {
75         enum sas_device_type    dev_type;
76         u64 device_id;
77         u8 dev_status;
78 };
79
80 struct hisi_sas_slot {
81 };
82
83 struct hisi_sas_hw {
84         int (*hw_init)(struct hisi_hba *hisi_hba);
85         int complete_hdr_size;
86 };
87
88 struct hisi_hba {
89         /* This must be the first element, used by SHOST_TO_SAS_HA */
90         struct sas_ha_struct *p;
91
92         struct platform_device *pdev;
93         void __iomem *regs;
94         struct regmap *ctrl;
95         u32 ctrl_reset_reg;
96         u32 ctrl_reset_sts_reg;
97         u32 ctrl_clock_ena_reg;
98         u8 sas_addr[SAS_ADDR_SIZE];
99
100         int n_phy;
101         spinlock_t lock;
102
103         struct timer_list timer;
104         struct workqueue_struct *wq;
105
106         int slot_index_count;
107         unsigned long *slot_index_tags;
108
109         /* SCSI/SAS glue */
110         struct sas_ha_struct sha;
111         struct Scsi_Host *shost;
112
113         struct hisi_sas_cq cq[HISI_SAS_MAX_QUEUES];
114         struct hisi_sas_phy phy[HISI_SAS_MAX_PHYS];
115         struct hisi_sas_port port[HISI_SAS_MAX_PHYS];
116
117         int     queue_count;
118         char    *int_names;
119
120         struct dma_pool *sge_page_pool;
121         struct hisi_sas_device  devices[HISI_SAS_MAX_DEVICES];
122         struct dma_pool *command_table_pool;
123         struct dma_pool *status_buffer_pool;
124         struct hisi_sas_cmd_hdr *cmd_hdr[HISI_SAS_MAX_QUEUES];
125         dma_addr_t cmd_hdr_dma[HISI_SAS_MAX_QUEUES];
126         void *complete_hdr[HISI_SAS_MAX_QUEUES];
127         dma_addr_t complete_hdr_dma[HISI_SAS_MAX_QUEUES];
128         struct hisi_sas_initial_fis *initial_fis;
129         dma_addr_t initial_fis_dma;
130         struct hisi_sas_itct *itct;
131         dma_addr_t itct_dma;
132         struct hisi_sas_iost *iost;
133         dma_addr_t iost_dma;
134         struct hisi_sas_breakpoint *breakpoint;
135         dma_addr_t breakpoint_dma;
136         struct hisi_sas_breakpoint *sata_breakpoint;
137         dma_addr_t sata_breakpoint_dma;
138         struct hisi_sas_slot    *slot_info;
139         const struct hisi_sas_hw *hw;   /* Low level hw interface */
140 };
141
142 /* Generic HW DMA host memory structures */
143 /* Delivery queue header */
144 struct hisi_sas_cmd_hdr {
145         /* dw0 */
146         __le32 dw0;
147
148         /* dw1 */
149         __le32 dw1;
150
151         /* dw2 */
152         __le32 dw2;
153
154         /* dw3 */
155         __le32 transfer_tags;
156
157         /* dw4 */
158         __le32 data_transfer_len;
159
160         /* dw5 */
161         __le32 first_burst_num;
162
163         /* dw6 */
164         __le32 sg_len;
165
166         /* dw7 */
167         __le32 dw7;
168
169         /* dw8-9 */
170         __le64 cmd_table_addr;
171
172         /* dw10-11 */
173         __le64 sts_buffer_addr;
174
175         /* dw12-13 */
176         __le64 prd_table_addr;
177
178         /* dw14-15 */
179         __le64 dif_prd_table_addr;
180 };
181
182 struct hisi_sas_itct {
183         __le64 qw0;
184         __le64 sas_addr;
185         __le64 qw2;
186         __le64 qw3;
187         __le64 qw4;
188         __le64 qw_sata_ncq0_3;
189         __le64 qw_sata_ncq7_4;
190         __le64 qw_sata_ncq11_8;
191         __le64 qw_sata_ncq15_12;
192         __le64 qw_sata_ncq19_16;
193         __le64 qw_sata_ncq23_20;
194         __le64 qw_sata_ncq27_24;
195         __le64 qw_sata_ncq31_28;
196         __le64 qw_non_ncq_iptt;
197         __le64 qw_rsvd0;
198         __le64 qw_rsvd1;
199 };
200
201 struct hisi_sas_iost {
202         __le64 qw0;
203         __le64 qw1;
204         __le64 qw2;
205         __le64 qw3;
206 };
207
208 struct hisi_sas_err_record {
209         /* dw0 */
210         __le32 dma_err_type;
211
212         /* dw1 */
213         __le32 trans_tx_fail_type;
214
215         /* dw2 */
216         __le32 trans_rx_fail_type;
217
218         /* dw3 */
219         u32 rsvd;
220 };
221
222 struct hisi_sas_initial_fis {
223         struct hisi_sas_err_record err_record;
224         struct dev_to_host_fis fis;
225         u32 rsvd[3];
226 };
227
228 struct hisi_sas_breakpoint {
229         u8      data[128];      /*io128 byte*/
230 };
231
232 struct hisi_sas_sge {
233         __le64 addr;
234         __le32 page_ctrl_0;
235         __le32 page_ctrl_1;
236         __le32 data_len;
237         __le32 data_off;
238 };
239
240 struct hisi_sas_command_table_smp {
241         u8 bytes[44];
242 };
243
244 struct hisi_sas_command_table_stp {
245         struct  host_to_dev_fis command_fis;
246         u8      dummy[12];
247         u8      atapi_cdb[ATAPI_CDB_LEN];
248 };
249
250 #define HISI_SAS_SGE_PAGE_CNT SCSI_MAX_SG_SEGMENTS
251 struct hisi_sas_sge_page {
252         struct hisi_sas_sge sge[HISI_SAS_SGE_PAGE_CNT];
253 };
254
255 struct hisi_sas_command_table_ssp {
256         struct ssp_frame_hdr hdr;
257         union {
258                 struct {
259                         struct ssp_command_iu task;
260                         u32 prot[6];
261                 };
262                 struct ssp_tmf_iu ssp_task;
263                 struct xfer_rdy_iu xfer_rdy;
264                 struct ssp_response_iu ssp_res;
265         } u;
266 };
267
268 union hisi_sas_command_table {
269         struct hisi_sas_command_table_ssp ssp;
270         struct hisi_sas_command_table_smp smp;
271         struct hisi_sas_command_table_stp stp;
272 };
273 extern int hisi_sas_probe(struct platform_device *pdev,
274                           const struct hisi_sas_hw *ops);
275 extern int hisi_sas_remove(struct platform_device *pdev);
276
277 #endif