blob: 999f31955bee2face671101285264c547990c8b6 [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 Garryabda97c2015-11-18 00:50:51 +080042struct hisi_hba;
John Garryaf740db2015-11-18 00:50:41 +080043
John Garry07d78592015-11-18 00:50:47 +080044enum {
45 PORT_TYPE_SAS = (1U << 1),
46 PORT_TYPE_SATA = (1U << 0),
47};
48
John Garryaf740db2015-11-18 00:50:41 +080049enum dev_status {
50 HISI_SAS_DEV_NORMAL,
51 HISI_SAS_DEV_EH,
52};
John Garryabda97c2015-11-18 00:50:51 +080053
54enum hisi_sas_dev_type {
55 HISI_SAS_DEV_TYPE_STP = 0,
56 HISI_SAS_DEV_TYPE_SSP,
57 HISI_SAS_DEV_TYPE_SATA,
58};
59
John Garry7eb78692015-11-18 00:50:31 +080060struct hisi_sas_phy {
John Garry976867e2015-11-18 00:50:42 +080061 struct hisi_hba *hisi_hba;
62 struct hisi_sas_port *port;
John Garry7eb78692015-11-18 00:50:31 +080063 struct asd_sas_phy sas_phy;
John Garry976867e2015-11-18 00:50:42 +080064 struct sas_identify identify;
65 struct timer_list timer;
John Garry66139922015-11-18 00:50:48 +080066 struct work_struct phyup_ws;
John Garry976867e2015-11-18 00:50:42 +080067 u64 port_id; /* from hw */
John Garry5d742422015-11-18 00:50:38 +080068 u64 dev_sas_addr;
John Garry976867e2015-11-18 00:50:42 +080069 u64 phy_type;
70 u64 frame_rcvd_size;
71 u8 frame_rcvd[32];
72 u8 phy_attached;
73 u8 reserved[3];
74 enum sas_linkrate minimum_linkrate;
75 enum sas_linkrate maximum_linkrate;
John Garry7eb78692015-11-18 00:50:31 +080076};
77
78struct hisi_sas_port {
79 struct asd_sas_port sas_port;
John Garry976867e2015-11-18 00:50:42 +080080 u8 port_attached;
81 u8 id; /* from hw */
82 struct list_head list;
John Garry7eb78692015-11-18 00:50:31 +080083};
84
John Garry9101a072015-11-18 00:50:37 +080085struct hisi_sas_cq {
86 struct hisi_hba *hisi_hba;
87 int id;
88};
89
John Garryaf740db2015-11-18 00:50:41 +080090struct hisi_sas_device {
91 enum sas_device_type dev_type;
John Garryabda97c2015-11-18 00:50:51 +080092 struct hisi_hba *hisi_hba;
93 struct domain_device *sas_device;
94 u64 attached_phy;
John Garryaf740db2015-11-18 00:50:41 +080095 u64 device_id;
John Garry42e7a692015-11-18 00:50:49 +080096 u64 running_req;
John Garryaf740db2015-11-18 00:50:41 +080097 u8 dev_status;
98};
99
John Garry6be6de12015-11-18 00:50:34 +0800100struct hisi_sas_slot {
John Garry42e7a692015-11-18 00:50:49 +0800101 struct list_head entry;
102 struct sas_task *task;
103 struct hisi_sas_port *port;
104 u64 n_elem;
105 int dlvry_queue;
106 int dlvry_queue_slot;
John Garry27a3f222015-11-18 00:50:50 +0800107 int cmplt_queue;
108 int cmplt_queue_slot;
John Garry42e7a692015-11-18 00:50:49 +0800109 int idx;
110 void *cmd_hdr;
111 dma_addr_t cmd_hdr_dma;
112 void *status_buffer;
113 dma_addr_t status_buffer_dma;
114 void *command_table;
115 dma_addr_t command_table_dma;
116 struct hisi_sas_sge_page *sge_page;
117 dma_addr_t sge_page_dma;
118};
119
120struct hisi_sas_tmf_task {
121 u8 tmf;
122 u16 tag_of_task_to_be_managed;
John Garry6be6de12015-11-18 00:50:34 +0800123};
124
John Garry7eb78692015-11-18 00:50:31 +0800125struct hisi_sas_hw {
John Garry8ff1d572015-11-18 00:50:46 +0800126 int (*hw_init)(struct hisi_hba *hisi_hba);
John Garryabda97c2015-11-18 00:50:51 +0800127 void (*setup_itct)(struct hisi_hba *hisi_hba,
128 struct hisi_sas_device *device);
John Garry66139922015-11-18 00:50:48 +0800129 void (*sl_notify)(struct hisi_hba *hisi_hba, int phy_no);
John Garry42e7a692015-11-18 00:50:49 +0800130 int (*get_free_slot)(struct hisi_hba *hisi_hba, int *q, int *s);
131 void (*start_delivery)(struct hisi_hba *hisi_hba);
132 int (*prep_ssp)(struct hisi_hba *hisi_hba,
133 struct hisi_sas_slot *slot, int is_tmf,
134 struct hisi_sas_tmf_task *tmf);
John Garry27a3f222015-11-18 00:50:50 +0800135 int (*slot_complete)(struct hisi_hba *hisi_hba,
136 struct hisi_sas_slot *slot, int abort);
137 void (*free_device)(struct hisi_hba *hisi_hba,
138 struct hisi_sas_device *dev);
John Garry6be6de12015-11-18 00:50:34 +0800139 int complete_hdr_size;
John Garry7eb78692015-11-18 00:50:31 +0800140};
141
142struct hisi_hba {
143 /* This must be the first element, used by SHOST_TO_SAS_HA */
144 struct sas_ha_struct *p;
145
146 struct platform_device *pdev;
John Garrye26b2f42015-11-18 00:50:32 +0800147 void __iomem *regs;
148 struct regmap *ctrl;
149 u32 ctrl_reset_reg;
150 u32 ctrl_reset_sts_reg;
151 u32 ctrl_clock_ena_reg;
John Garry7eb78692015-11-18 00:50:31 +0800152 u8 sas_addr[SAS_ADDR_SIZE];
153
154 int n_phy;
John Garryfa42d802015-11-18 00:50:43 +0800155 spinlock_t lock;
John Garry7eb78692015-11-18 00:50:31 +0800156
John Garryfa42d802015-11-18 00:50:43 +0800157 struct timer_list timer;
John Garry7e9080e2015-11-18 00:50:40 +0800158 struct workqueue_struct *wq;
John Garry257efd12015-11-18 00:50:36 +0800159
160 int slot_index_count;
161 unsigned long *slot_index_tags;
162
John Garry7eb78692015-11-18 00:50:31 +0800163 /* SCSI/SAS glue */
164 struct sas_ha_struct sha;
165 struct Scsi_Host *shost;
John Garry9101a072015-11-18 00:50:37 +0800166
167 struct hisi_sas_cq cq[HISI_SAS_MAX_QUEUES];
John Garry7eb78692015-11-18 00:50:31 +0800168 struct hisi_sas_phy phy[HISI_SAS_MAX_PHYS];
169 struct hisi_sas_port port[HISI_SAS_MAX_PHYS];
John Garrye26b2f42015-11-18 00:50:32 +0800170
171 int queue_count;
John Garry42e7a692015-11-18 00:50:49 +0800172 int queue;
John Garrye26b2f42015-11-18 00:50:32 +0800173 char *int_names;
John Garry42e7a692015-11-18 00:50:49 +0800174 struct hisi_sas_slot *slot_prep;
John Garry6be6de12015-11-18 00:50:34 +0800175
176 struct dma_pool *sge_page_pool;
John Garryaf740db2015-11-18 00:50:41 +0800177 struct hisi_sas_device devices[HISI_SAS_MAX_DEVICES];
John Garry6be6de12015-11-18 00:50:34 +0800178 struct dma_pool *command_table_pool;
179 struct dma_pool *status_buffer_pool;
180 struct hisi_sas_cmd_hdr *cmd_hdr[HISI_SAS_MAX_QUEUES];
181 dma_addr_t cmd_hdr_dma[HISI_SAS_MAX_QUEUES];
182 void *complete_hdr[HISI_SAS_MAX_QUEUES];
183 dma_addr_t complete_hdr_dma[HISI_SAS_MAX_QUEUES];
184 struct hisi_sas_initial_fis *initial_fis;
185 dma_addr_t initial_fis_dma;
186 struct hisi_sas_itct *itct;
187 dma_addr_t itct_dma;
188 struct hisi_sas_iost *iost;
189 dma_addr_t iost_dma;
190 struct hisi_sas_breakpoint *breakpoint;
191 dma_addr_t breakpoint_dma;
192 struct hisi_sas_breakpoint *sata_breakpoint;
193 dma_addr_t sata_breakpoint_dma;
194 struct hisi_sas_slot *slot_info;
John Garry7eb78692015-11-18 00:50:31 +0800195 const struct hisi_sas_hw *hw; /* Low level hw interface */
196};
197
John Garryc799d6b2015-11-18 00:50:33 +0800198/* Generic HW DMA host memory structures */
199/* Delivery queue header */
200struct hisi_sas_cmd_hdr {
201 /* dw0 */
202 __le32 dw0;
203
204 /* dw1 */
205 __le32 dw1;
206
207 /* dw2 */
208 __le32 dw2;
209
210 /* dw3 */
211 __le32 transfer_tags;
212
213 /* dw4 */
214 __le32 data_transfer_len;
215
216 /* dw5 */
217 __le32 first_burst_num;
218
219 /* dw6 */
220 __le32 sg_len;
221
222 /* dw7 */
223 __le32 dw7;
224
225 /* dw8-9 */
226 __le64 cmd_table_addr;
227
228 /* dw10-11 */
229 __le64 sts_buffer_addr;
230
231 /* dw12-13 */
232 __le64 prd_table_addr;
233
234 /* dw14-15 */
235 __le64 dif_prd_table_addr;
236};
237
238struct hisi_sas_itct {
239 __le64 qw0;
240 __le64 sas_addr;
241 __le64 qw2;
242 __le64 qw3;
243 __le64 qw4;
244 __le64 qw_sata_ncq0_3;
245 __le64 qw_sata_ncq7_4;
246 __le64 qw_sata_ncq11_8;
247 __le64 qw_sata_ncq15_12;
248 __le64 qw_sata_ncq19_16;
249 __le64 qw_sata_ncq23_20;
250 __le64 qw_sata_ncq27_24;
251 __le64 qw_sata_ncq31_28;
252 __le64 qw_non_ncq_iptt;
253 __le64 qw_rsvd0;
254 __le64 qw_rsvd1;
255};
256
257struct hisi_sas_iost {
258 __le64 qw0;
259 __le64 qw1;
260 __le64 qw2;
261 __le64 qw3;
262};
263
264struct hisi_sas_err_record {
265 /* dw0 */
266 __le32 dma_err_type;
267
268 /* dw1 */
269 __le32 trans_tx_fail_type;
270
271 /* dw2 */
272 __le32 trans_rx_fail_type;
273
274 /* dw3 */
275 u32 rsvd;
276};
277
278struct hisi_sas_initial_fis {
279 struct hisi_sas_err_record err_record;
280 struct dev_to_host_fis fis;
281 u32 rsvd[3];
282};
283
284struct hisi_sas_breakpoint {
285 u8 data[128]; /*io128 byte*/
286};
287
288struct hisi_sas_sge {
289 __le64 addr;
290 __le32 page_ctrl_0;
291 __le32 page_ctrl_1;
292 __le32 data_len;
293 __le32 data_off;
294};
295
296struct hisi_sas_command_table_smp {
297 u8 bytes[44];
298};
299
300struct hisi_sas_command_table_stp {
301 struct host_to_dev_fis command_fis;
302 u8 dummy[12];
303 u8 atapi_cdb[ATAPI_CDB_LEN];
304};
305
John Garry7eb78692015-11-18 00:50:31 +0800306#define HISI_SAS_SGE_PAGE_CNT SCSI_MAX_SG_SEGMENTS
John Garryc799d6b2015-11-18 00:50:33 +0800307struct hisi_sas_sge_page {
308 struct hisi_sas_sge sge[HISI_SAS_SGE_PAGE_CNT];
309};
310
311struct hisi_sas_command_table_ssp {
312 struct ssp_frame_hdr hdr;
313 union {
314 struct {
315 struct ssp_command_iu task;
316 u32 prot[6];
317 };
318 struct ssp_tmf_iu ssp_task;
319 struct xfer_rdy_iu xfer_rdy;
320 struct ssp_response_iu ssp_res;
321 } u;
322};
323
324union hisi_sas_command_table {
325 struct hisi_sas_command_table_ssp ssp;
326 struct hisi_sas_command_table_smp smp;
327 struct hisi_sas_command_table_stp stp;
328};
John Garry9fb10b52015-11-18 00:50:44 +0800329extern int hisi_sas_probe(struct platform_device *pdev,
330 const struct hisi_sas_hw *ops);
331extern int hisi_sas_remove(struct platform_device *pdev);
John Garryc799d6b2015-11-18 00:50:33 +0800332
John Garry27a3f222015-11-18 00:50:50 +0800333extern void hisi_sas_slot_task_free(struct hisi_hba *hisi_hba,
334 struct sas_task *task,
335 struct hisi_sas_slot *slot);
John Garrye8899fa2015-11-18 00:50:30 +0800336#endif