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