blob: fe4055be325a8808976ace10faafd793c158338f [file] [log] [blame]
John Garrye8899fa2015-11-18 00:50:30 +08001/*
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
John Garry7eb78692015-11-18 00:50:31 +080026#define HISI_SAS_MAX_PHYS 9
John Garry6be6de12015-11-18 00:50:34 +080027#define HISI_SAS_MAX_QUEUES 32
28#define HISI_SAS_QUEUE_SLOTS 512
John Garry7eb78692015-11-18 00:50:31 +080029#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
John Garry6be6de12015-11-18 00:50:34 +080033#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
John Garry42e7a692015-11-18 00:50:49 +080038#define HISI_SAS_MAX_SSP_RESP_SZ (sizeof(struct ssp_frame_hdr) + 1024)
39
John Garrye26b2f42015-11-18 00:50:32 +080040#define HISI_SAS_NAME_LEN 32
41
John Garryaf740db2015-11-18 00:50:41 +080042
John Garry07d78592015-11-18 00:50:47 +080043enum {
44 PORT_TYPE_SAS = (1U << 1),
45 PORT_TYPE_SATA = (1U << 0),
46};
47
John Garryaf740db2015-11-18 00:50:41 +080048enum dev_status {
49 HISI_SAS_DEV_NORMAL,
50 HISI_SAS_DEV_EH,
51};
John Garry7eb78692015-11-18 00:50:31 +080052struct hisi_sas_phy {
John Garry976867e2015-11-18 00:50:42 +080053 struct hisi_hba *hisi_hba;
54 struct hisi_sas_port *port;
John Garry7eb78692015-11-18 00:50:31 +080055 struct asd_sas_phy sas_phy;
John Garry976867e2015-11-18 00:50:42 +080056 struct sas_identify identify;
57 struct timer_list timer;
John Garry66139922015-11-18 00:50:48 +080058 struct work_struct phyup_ws;
John Garry976867e2015-11-18 00:50:42 +080059 u64 port_id; /* from hw */
John Garry5d742422015-11-18 00:50:38 +080060 u64 dev_sas_addr;
John Garry976867e2015-11-18 00:50:42 +080061 u64 phy_type;
62 u64 frame_rcvd_size;
63 u8 frame_rcvd[32];
64 u8 phy_attached;
65 u8 reserved[3];
66 enum sas_linkrate minimum_linkrate;
67 enum sas_linkrate maximum_linkrate;
John Garry7eb78692015-11-18 00:50:31 +080068};
69
70struct hisi_sas_port {
71 struct asd_sas_port sas_port;
John Garry976867e2015-11-18 00:50:42 +080072 u8 port_attached;
73 u8 id; /* from hw */
74 struct list_head list;
John Garry7eb78692015-11-18 00:50:31 +080075};
76
John Garry9101a072015-11-18 00:50:37 +080077struct hisi_sas_cq {
78 struct hisi_hba *hisi_hba;
79 int id;
80};
81
John Garryaf740db2015-11-18 00:50:41 +080082struct hisi_sas_device {
83 enum sas_device_type dev_type;
84 u64 device_id;
John Garry42e7a692015-11-18 00:50:49 +080085 u64 running_req;
John Garryaf740db2015-11-18 00:50:41 +080086 u8 dev_status;
87};
88
John Garry6be6de12015-11-18 00:50:34 +080089struct hisi_sas_slot {
John Garry42e7a692015-11-18 00:50:49 +080090 struct list_head entry;
91 struct sas_task *task;
92 struct hisi_sas_port *port;
93 u64 n_elem;
94 int dlvry_queue;
95 int dlvry_queue_slot;
John Garry27a3f222015-11-18 00:50:50 +080096 int cmplt_queue;
97 int cmplt_queue_slot;
John Garry42e7a692015-11-18 00:50:49 +080098 int idx;
99 void *cmd_hdr;
100 dma_addr_t cmd_hdr_dma;
101 void *status_buffer;
102 dma_addr_t status_buffer_dma;
103 void *command_table;
104 dma_addr_t command_table_dma;
105 struct hisi_sas_sge_page *sge_page;
106 dma_addr_t sge_page_dma;
107};
108
109struct hisi_sas_tmf_task {
110 u8 tmf;
111 u16 tag_of_task_to_be_managed;
John Garry6be6de12015-11-18 00:50:34 +0800112};
113
John Garry7eb78692015-11-18 00:50:31 +0800114struct hisi_sas_hw {
John Garry8ff1d572015-11-18 00:50:46 +0800115 int (*hw_init)(struct hisi_hba *hisi_hba);
John Garry66139922015-11-18 00:50:48 +0800116 void (*sl_notify)(struct hisi_hba *hisi_hba, int phy_no);
John Garry42e7a692015-11-18 00:50:49 +0800117 int (*get_free_slot)(struct hisi_hba *hisi_hba, int *q, int *s);
118 void (*start_delivery)(struct hisi_hba *hisi_hba);
119 int (*prep_ssp)(struct hisi_hba *hisi_hba,
120 struct hisi_sas_slot *slot, int is_tmf,
121 struct hisi_sas_tmf_task *tmf);
John Garry27a3f222015-11-18 00:50:50 +0800122 int (*slot_complete)(struct hisi_hba *hisi_hba,
123 struct hisi_sas_slot *slot, int abort);
124 void (*free_device)(struct hisi_hba *hisi_hba,
125 struct hisi_sas_device *dev);
John Garry6be6de12015-11-18 00:50:34 +0800126 int complete_hdr_size;
John Garry7eb78692015-11-18 00:50:31 +0800127};
128
129struct hisi_hba {
130 /* This must be the first element, used by SHOST_TO_SAS_HA */
131 struct sas_ha_struct *p;
132
133 struct platform_device *pdev;
John Garrye26b2f42015-11-18 00:50:32 +0800134 void __iomem *regs;
135 struct regmap *ctrl;
136 u32 ctrl_reset_reg;
137 u32 ctrl_reset_sts_reg;
138 u32 ctrl_clock_ena_reg;
John Garry7eb78692015-11-18 00:50:31 +0800139 u8 sas_addr[SAS_ADDR_SIZE];
140
141 int n_phy;
John Garryfa42d802015-11-18 00:50:43 +0800142 spinlock_t lock;
John Garry7eb78692015-11-18 00:50:31 +0800143
John Garryfa42d802015-11-18 00:50:43 +0800144 struct timer_list timer;
John Garry7e9080e2015-11-18 00:50:40 +0800145 struct workqueue_struct *wq;
John Garry257efd12015-11-18 00:50:36 +0800146
147 int slot_index_count;
148 unsigned long *slot_index_tags;
149
John Garry7eb78692015-11-18 00:50:31 +0800150 /* SCSI/SAS glue */
151 struct sas_ha_struct sha;
152 struct Scsi_Host *shost;
John Garry9101a072015-11-18 00:50:37 +0800153
154 struct hisi_sas_cq cq[HISI_SAS_MAX_QUEUES];
John Garry7eb78692015-11-18 00:50:31 +0800155 struct hisi_sas_phy phy[HISI_SAS_MAX_PHYS];
156 struct hisi_sas_port port[HISI_SAS_MAX_PHYS];
John Garrye26b2f42015-11-18 00:50:32 +0800157
158 int queue_count;
John Garry42e7a692015-11-18 00:50:49 +0800159 int queue;
John Garrye26b2f42015-11-18 00:50:32 +0800160 char *int_names;
John Garry42e7a692015-11-18 00:50:49 +0800161 struct hisi_sas_slot *slot_prep;
John Garry6be6de12015-11-18 00:50:34 +0800162
163 struct dma_pool *sge_page_pool;
John Garryaf740db2015-11-18 00:50:41 +0800164 struct hisi_sas_device devices[HISI_SAS_MAX_DEVICES];
John Garry6be6de12015-11-18 00:50:34 +0800165 struct dma_pool *command_table_pool;
166 struct dma_pool *status_buffer_pool;
167 struct hisi_sas_cmd_hdr *cmd_hdr[HISI_SAS_MAX_QUEUES];
168 dma_addr_t cmd_hdr_dma[HISI_SAS_MAX_QUEUES];
169 void *complete_hdr[HISI_SAS_MAX_QUEUES];
170 dma_addr_t complete_hdr_dma[HISI_SAS_MAX_QUEUES];
171 struct hisi_sas_initial_fis *initial_fis;
172 dma_addr_t initial_fis_dma;
173 struct hisi_sas_itct *itct;
174 dma_addr_t itct_dma;
175 struct hisi_sas_iost *iost;
176 dma_addr_t iost_dma;
177 struct hisi_sas_breakpoint *breakpoint;
178 dma_addr_t breakpoint_dma;
179 struct hisi_sas_breakpoint *sata_breakpoint;
180 dma_addr_t sata_breakpoint_dma;
181 struct hisi_sas_slot *slot_info;
John Garry7eb78692015-11-18 00:50:31 +0800182 const struct hisi_sas_hw *hw; /* Low level hw interface */
183};
184
John Garryc799d6b2015-11-18 00:50:33 +0800185/* Generic HW DMA host memory structures */
186/* Delivery queue header */
187struct hisi_sas_cmd_hdr {
188 /* dw0 */
189 __le32 dw0;
190
191 /* dw1 */
192 __le32 dw1;
193
194 /* dw2 */
195 __le32 dw2;
196
197 /* dw3 */
198 __le32 transfer_tags;
199
200 /* dw4 */
201 __le32 data_transfer_len;
202
203 /* dw5 */
204 __le32 first_burst_num;
205
206 /* dw6 */
207 __le32 sg_len;
208
209 /* dw7 */
210 __le32 dw7;
211
212 /* dw8-9 */
213 __le64 cmd_table_addr;
214
215 /* dw10-11 */
216 __le64 sts_buffer_addr;
217
218 /* dw12-13 */
219 __le64 prd_table_addr;
220
221 /* dw14-15 */
222 __le64 dif_prd_table_addr;
223};
224
225struct hisi_sas_itct {
226 __le64 qw0;
227 __le64 sas_addr;
228 __le64 qw2;
229 __le64 qw3;
230 __le64 qw4;
231 __le64 qw_sata_ncq0_3;
232 __le64 qw_sata_ncq7_4;
233 __le64 qw_sata_ncq11_8;
234 __le64 qw_sata_ncq15_12;
235 __le64 qw_sata_ncq19_16;
236 __le64 qw_sata_ncq23_20;
237 __le64 qw_sata_ncq27_24;
238 __le64 qw_sata_ncq31_28;
239 __le64 qw_non_ncq_iptt;
240 __le64 qw_rsvd0;
241 __le64 qw_rsvd1;
242};
243
244struct hisi_sas_iost {
245 __le64 qw0;
246 __le64 qw1;
247 __le64 qw2;
248 __le64 qw3;
249};
250
251struct hisi_sas_err_record {
252 /* dw0 */
253 __le32 dma_err_type;
254
255 /* dw1 */
256 __le32 trans_tx_fail_type;
257
258 /* dw2 */
259 __le32 trans_rx_fail_type;
260
261 /* dw3 */
262 u32 rsvd;
263};
264
265struct 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
271struct hisi_sas_breakpoint {
272 u8 data[128]; /*io128 byte*/
273};
274
275struct 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
283struct hisi_sas_command_table_smp {
284 u8 bytes[44];
285};
286
287struct 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
John Garry7eb78692015-11-18 00:50:31 +0800293#define HISI_SAS_SGE_PAGE_CNT SCSI_MAX_SG_SEGMENTS
John Garryc799d6b2015-11-18 00:50:33 +0800294struct hisi_sas_sge_page {
295 struct hisi_sas_sge sge[HISI_SAS_SGE_PAGE_CNT];
296};
297
298struct 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
311union 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};
John Garry9fb10b52015-11-18 00:50:44 +0800316extern int hisi_sas_probe(struct platform_device *pdev,
317 const struct hisi_sas_hw *ops);
318extern int hisi_sas_remove(struct platform_device *pdev);
John Garryc799d6b2015-11-18 00:50:33 +0800319
John Garry27a3f222015-11-18 00:50:50 +0800320extern void hisi_sas_slot_task_free(struct hisi_hba *hisi_hba,
321 struct sas_task *task,
322 struct hisi_sas_slot *slot);
John Garrye8899fa2015-11-18 00:50:30 +0800323#endif