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