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