blob: 21eb2bb1c1c8431f09de58d4e457089c4958e622 [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>
John Garrye8899fa2015-11-18 00:50:30 +080019#include <linux/platform_device.h>
20#include <linux/regmap.h>
21#include <scsi/libsas.h>
22
23#define DRV_VERSION "v1.0"
24
John Garry7eb78692015-11-18 00:50:31 +080025#define HISI_SAS_MAX_PHYS 9
John Garry6be6de12015-11-18 00:50:34 +080026#define HISI_SAS_MAX_QUEUES 32
27#define HISI_SAS_QUEUE_SLOTS 512
John Garry7eb78692015-11-18 00:50:31 +080028#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
John Garry6be6de12015-11-18 00:50:34 +080032#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
John Garry42e7a692015-11-18 00:50:49 +080037#define HISI_SAS_MAX_SSP_RESP_SZ (sizeof(struct ssp_frame_hdr) + 1024)
John Garry66ee9992015-11-18 00:50:54 +080038#define HISI_SAS_MAX_SMP_RESP_SZ 1028
John Garry42e7a692015-11-18 00:50:49 +080039
John Garry98bf39f2016-01-26 02:47:02 +080040#define DEV_IS_EXPANDER(type) \
41 ((type == SAS_EDGE_EXPANDER_DEVICE) || \
42 (type == SAS_FANOUT_EXPANDER_DEVICE))
43
John Garryabda97c2015-11-18 00:50:51 +080044struct hisi_hba;
John Garryaf740db2015-11-18 00:50:41 +080045
John Garry07d78592015-11-18 00:50:47 +080046enum {
47 PORT_TYPE_SAS = (1U << 1),
48 PORT_TYPE_SATA = (1U << 0),
49};
50
John Garryaf740db2015-11-18 00:50:41 +080051enum dev_status {
52 HISI_SAS_DEV_NORMAL,
53 HISI_SAS_DEV_EH,
54};
John Garryabda97c2015-11-18 00:50:51 +080055
56enum hisi_sas_dev_type {
57 HISI_SAS_DEV_TYPE_STP = 0,
58 HISI_SAS_DEV_TYPE_SSP,
59 HISI_SAS_DEV_TYPE_SATA,
60};
61
John Garry7eb78692015-11-18 00:50:31 +080062struct hisi_sas_phy {
John Garry976867e2015-11-18 00:50:42 +080063 struct hisi_hba *hisi_hba;
64 struct hisi_sas_port *port;
John Garry7eb78692015-11-18 00:50:31 +080065 struct asd_sas_phy sas_phy;
John Garry976867e2015-11-18 00:50:42 +080066 struct sas_identify identify;
67 struct timer_list timer;
John Garry66139922015-11-18 00:50:48 +080068 struct work_struct phyup_ws;
John Garry976867e2015-11-18 00:50:42 +080069 u64 port_id; /* from hw */
John Garry5d742422015-11-18 00:50:38 +080070 u64 dev_sas_addr;
John Garry976867e2015-11-18 00:50:42 +080071 u64 phy_type;
72 u64 frame_rcvd_size;
73 u8 frame_rcvd[32];
74 u8 phy_attached;
75 u8 reserved[3];
76 enum sas_linkrate minimum_linkrate;
77 enum sas_linkrate maximum_linkrate;
John Garry7eb78692015-11-18 00:50:31 +080078};
79
80struct hisi_sas_port {
81 struct asd_sas_port sas_port;
John Garry976867e2015-11-18 00:50:42 +080082 u8 port_attached;
83 u8 id; /* from hw */
84 struct list_head list;
John Garry7eb78692015-11-18 00:50:31 +080085};
86
John Garry9101a072015-11-18 00:50:37 +080087struct hisi_sas_cq {
88 struct hisi_hba *hisi_hba;
89 int id;
90};
91
John Garryaf740db2015-11-18 00:50:41 +080092struct hisi_sas_device {
93 enum sas_device_type dev_type;
John Garryabda97c2015-11-18 00:50:51 +080094 struct hisi_hba *hisi_hba;
95 struct domain_device *sas_device;
96 u64 attached_phy;
John Garryaf740db2015-11-18 00:50:41 +080097 u64 device_id;
John Garry42e7a692015-11-18 00:50:49 +080098 u64 running_req;
John Garryaf740db2015-11-18 00:50:41 +080099 u8 dev_status;
100};
101
John Garry6be6de12015-11-18 00:50:34 +0800102struct hisi_sas_slot {
John Garry42e7a692015-11-18 00:50:49 +0800103 struct list_head entry;
104 struct sas_task *task;
105 struct hisi_sas_port *port;
106 u64 n_elem;
107 int dlvry_queue;
108 int dlvry_queue_slot;
John Garry27a3f222015-11-18 00:50:50 +0800109 int cmplt_queue;
110 int cmplt_queue_slot;
John Garry42e7a692015-11-18 00:50:49 +0800111 int idx;
112 void *cmd_hdr;
113 dma_addr_t cmd_hdr_dma;
114 void *status_buffer;
115 dma_addr_t status_buffer_dma;
116 void *command_table;
117 dma_addr_t command_table_dma;
118 struct hisi_sas_sge_page *sge_page;
119 dma_addr_t sge_page_dma;
120};
121
122struct hisi_sas_tmf_task {
123 u8 tmf;
124 u16 tag_of_task_to_be_managed;
John Garry6be6de12015-11-18 00:50:34 +0800125};
126
John Garry7eb78692015-11-18 00:50:31 +0800127struct hisi_sas_hw {
John Garry8ff1d572015-11-18 00:50:46 +0800128 int (*hw_init)(struct hisi_hba *hisi_hba);
John Garryabda97c2015-11-18 00:50:51 +0800129 void (*setup_itct)(struct hisi_hba *hisi_hba,
130 struct hisi_sas_device *device);
John Garry66139922015-11-18 00:50:48 +0800131 void (*sl_notify)(struct hisi_hba *hisi_hba, int phy_no);
John Garry42e7a692015-11-18 00:50:49 +0800132 int (*get_free_slot)(struct hisi_hba *hisi_hba, int *q, int *s);
133 void (*start_delivery)(struct hisi_hba *hisi_hba);
134 int (*prep_ssp)(struct hisi_hba *hisi_hba,
135 struct hisi_sas_slot *slot, int is_tmf,
136 struct hisi_sas_tmf_task *tmf);
John Garry66ee9992015-11-18 00:50:54 +0800137 int (*prep_smp)(struct hisi_hba *hisi_hba,
138 struct hisi_sas_slot *slot);
John Garry27a3f222015-11-18 00:50:50 +0800139 int (*slot_complete)(struct hisi_hba *hisi_hba,
140 struct hisi_sas_slot *slot, int abort);
John Garrye4189d52015-11-18 00:50:57 +0800141 void (*phy_enable)(struct hisi_hba *hisi_hba, int phy_no);
142 void (*phy_disable)(struct hisi_hba *hisi_hba, int phy_no);
143 void (*phy_hard_reset)(struct hisi_hba *hisi_hba, int phy_no);
John Garry27a3f222015-11-18 00:50:50 +0800144 void (*free_device)(struct hisi_hba *hisi_hba,
145 struct hisi_sas_device *dev);
John Garry184a4632015-11-18 00:50:52 +0800146 int (*get_wideport_bitmap)(struct hisi_hba *hisi_hba, int port_id);
John Garry6be6de12015-11-18 00:50:34 +0800147 int complete_hdr_size;
John Garry7eb78692015-11-18 00:50:31 +0800148};
149
150struct 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;
John Garrye26b2f42015-11-18 00:50:32 +0800155 void __iomem *regs;
156 struct regmap *ctrl;
157 u32 ctrl_reset_reg;
158 u32 ctrl_reset_sts_reg;
159 u32 ctrl_clock_ena_reg;
John Garry7eb78692015-11-18 00:50:31 +0800160 u8 sas_addr[SAS_ADDR_SIZE];
161
162 int n_phy;
John Garry701f75e2015-11-18 00:50:55 +0800163 int scan_finished;
John Garryfa42d802015-11-18 00:50:43 +0800164 spinlock_t lock;
John Garry7eb78692015-11-18 00:50:31 +0800165
John Garryfa42d802015-11-18 00:50:43 +0800166 struct timer_list timer;
John Garry7e9080e2015-11-18 00:50:40 +0800167 struct workqueue_struct *wq;
John Garry257efd12015-11-18 00:50:36 +0800168
169 int slot_index_count;
170 unsigned long *slot_index_tags;
171
John Garry7eb78692015-11-18 00:50:31 +0800172 /* SCSI/SAS glue */
173 struct sas_ha_struct sha;
174 struct Scsi_Host *shost;
John Garry9101a072015-11-18 00:50:37 +0800175
176 struct hisi_sas_cq cq[HISI_SAS_MAX_QUEUES];
John Garry7eb78692015-11-18 00:50:31 +0800177 struct hisi_sas_phy phy[HISI_SAS_MAX_PHYS];
178 struct hisi_sas_port port[HISI_SAS_MAX_PHYS];
John Garrye26b2f42015-11-18 00:50:32 +0800179
180 int queue_count;
John Garry42e7a692015-11-18 00:50:49 +0800181 int queue;
John Garry42e7a692015-11-18 00:50:49 +0800182 struct hisi_sas_slot *slot_prep;
John Garry6be6de12015-11-18 00:50:34 +0800183
184 struct dma_pool *sge_page_pool;
John Garryaf740db2015-11-18 00:50:41 +0800185 struct hisi_sas_device devices[HISI_SAS_MAX_DEVICES];
John Garry6be6de12015-11-18 00:50:34 +0800186 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;
John Garry7eb78692015-11-18 00:50:31 +0800203 const struct hisi_sas_hw *hw; /* Low level hw interface */
204};
205
John Garryc799d6b2015-11-18 00:50:33 +0800206/* Generic HW DMA host memory structures */
207/* Delivery queue header */
208struct 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
246struct hisi_sas_itct {
247 __le64 qw0;
248 __le64 sas_addr;
249 __le64 qw2;
250 __le64 qw3;
251 __le64 qw4;
252 __le64 qw_sata_ncq0_3;
253 __le64 qw_sata_ncq7_4;
254 __le64 qw_sata_ncq11_8;
255 __le64 qw_sata_ncq15_12;
256 __le64 qw_sata_ncq19_16;
257 __le64 qw_sata_ncq23_20;
258 __le64 qw_sata_ncq27_24;
259 __le64 qw_sata_ncq31_28;
260 __le64 qw_non_ncq_iptt;
261 __le64 qw_rsvd0;
262 __le64 qw_rsvd1;
263};
264
265struct hisi_sas_iost {
266 __le64 qw0;
267 __le64 qw1;
268 __le64 qw2;
269 __le64 qw3;
270};
271
272struct hisi_sas_err_record {
273 /* dw0 */
274 __le32 dma_err_type;
275
276 /* dw1 */
277 __le32 trans_tx_fail_type;
278
279 /* dw2 */
280 __le32 trans_rx_fail_type;
281
282 /* dw3 */
283 u32 rsvd;
284};
285
286struct hisi_sas_initial_fis {
287 struct hisi_sas_err_record err_record;
288 struct dev_to_host_fis fis;
289 u32 rsvd[3];
290};
291
292struct hisi_sas_breakpoint {
293 u8 data[128]; /*io128 byte*/
294};
295
296struct hisi_sas_sge {
297 __le64 addr;
298 __le32 page_ctrl_0;
299 __le32 page_ctrl_1;
300 __le32 data_len;
301 __le32 data_off;
302};
303
304struct hisi_sas_command_table_smp {
305 u8 bytes[44];
306};
307
308struct hisi_sas_command_table_stp {
309 struct host_to_dev_fis command_fis;
310 u8 dummy[12];
311 u8 atapi_cdb[ATAPI_CDB_LEN];
312};
313
John Garry7eb78692015-11-18 00:50:31 +0800314#define HISI_SAS_SGE_PAGE_CNT SCSI_MAX_SG_SEGMENTS
John Garryc799d6b2015-11-18 00:50:33 +0800315struct hisi_sas_sge_page {
316 struct hisi_sas_sge sge[HISI_SAS_SGE_PAGE_CNT];
317};
318
319struct hisi_sas_command_table_ssp {
320 struct ssp_frame_hdr hdr;
321 union {
322 struct {
323 struct ssp_command_iu task;
324 u32 prot[6];
325 };
326 struct ssp_tmf_iu ssp_task;
327 struct xfer_rdy_iu xfer_rdy;
328 struct ssp_response_iu ssp_res;
329 } u;
330};
331
332union hisi_sas_command_table {
333 struct hisi_sas_command_table_ssp ssp;
334 struct hisi_sas_command_table_smp smp;
335 struct hisi_sas_command_table_stp stp;
336};
John Garry9fb10b52015-11-18 00:50:44 +0800337extern int hisi_sas_probe(struct platform_device *pdev,
338 const struct hisi_sas_hw *ops);
339extern int hisi_sas_remove(struct platform_device *pdev);
John Garryc799d6b2015-11-18 00:50:33 +0800340
John Garry184a4632015-11-18 00:50:52 +0800341extern void hisi_sas_phy_down(struct hisi_hba *hisi_hba, int phy_no, int rdy);
John Garry27a3f222015-11-18 00:50:50 +0800342extern void hisi_sas_slot_task_free(struct hisi_hba *hisi_hba,
343 struct sas_task *task,
344 struct hisi_sas_slot *slot);
John Garrye8899fa2015-11-18 00:50:30 +0800345#endif