blob: ba3bf5eed74559bb01eb68301a7aa2bfa5fc2887 [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 Garrye26b2f42015-11-18 00:50:32 +080038#define HISI_SAS_NAME_LEN 32
39
John Garryaf740db2015-11-18 00:50:41 +080040
41enum dev_status {
42 HISI_SAS_DEV_NORMAL,
43 HISI_SAS_DEV_EH,
44};
John Garry7eb78692015-11-18 00:50:31 +080045struct hisi_sas_phy {
John Garry976867e2015-11-18 00:50:42 +080046 struct hisi_hba *hisi_hba;
47 struct hisi_sas_port *port;
John Garry7eb78692015-11-18 00:50:31 +080048 struct asd_sas_phy sas_phy;
John Garry976867e2015-11-18 00:50:42 +080049 struct sas_identify identify;
50 struct timer_list timer;
51 u64 port_id; /* from hw */
John Garry5d742422015-11-18 00:50:38 +080052 u64 dev_sas_addr;
John Garry976867e2015-11-18 00:50:42 +080053 u64 phy_type;
54 u64 frame_rcvd_size;
55 u8 frame_rcvd[32];
56 u8 phy_attached;
57 u8 reserved[3];
58 enum sas_linkrate minimum_linkrate;
59 enum sas_linkrate maximum_linkrate;
John Garry7eb78692015-11-18 00:50:31 +080060};
61
62struct hisi_sas_port {
63 struct asd_sas_port sas_port;
John Garry976867e2015-11-18 00:50:42 +080064 u8 port_attached;
65 u8 id; /* from hw */
66 struct list_head list;
John Garry7eb78692015-11-18 00:50:31 +080067};
68
John Garry9101a072015-11-18 00:50:37 +080069struct hisi_sas_cq {
70 struct hisi_hba *hisi_hba;
71 int id;
72};
73
John Garryaf740db2015-11-18 00:50:41 +080074struct hisi_sas_device {
75 enum sas_device_type dev_type;
76 u64 device_id;
77 u8 dev_status;
78};
79
John Garry6be6de12015-11-18 00:50:34 +080080struct hisi_sas_slot {
81};
82
John Garry7eb78692015-11-18 00:50:31 +080083struct hisi_sas_hw {
John Garry8ff1d572015-11-18 00:50:46 +080084 int (*hw_init)(struct hisi_hba *hisi_hba);
John Garry6be6de12015-11-18 00:50:34 +080085 int complete_hdr_size;
John Garry7eb78692015-11-18 00:50:31 +080086};
87
88struct hisi_hba {
89 /* This must be the first element, used by SHOST_TO_SAS_HA */
90 struct sas_ha_struct *p;
91
92 struct platform_device *pdev;
John Garrye26b2f42015-11-18 00:50:32 +080093 void __iomem *regs;
94 struct regmap *ctrl;
95 u32 ctrl_reset_reg;
96 u32 ctrl_reset_sts_reg;
97 u32 ctrl_clock_ena_reg;
John Garry7eb78692015-11-18 00:50:31 +080098 u8 sas_addr[SAS_ADDR_SIZE];
99
100 int n_phy;
John Garryfa42d802015-11-18 00:50:43 +0800101 spinlock_t lock;
John Garry7eb78692015-11-18 00:50:31 +0800102
John Garryfa42d802015-11-18 00:50:43 +0800103 struct timer_list timer;
John Garry7e9080e2015-11-18 00:50:40 +0800104 struct workqueue_struct *wq;
John Garry257efd12015-11-18 00:50:36 +0800105
106 int slot_index_count;
107 unsigned long *slot_index_tags;
108
John Garry7eb78692015-11-18 00:50:31 +0800109 /* SCSI/SAS glue */
110 struct sas_ha_struct sha;
111 struct Scsi_Host *shost;
John Garry9101a072015-11-18 00:50:37 +0800112
113 struct hisi_sas_cq cq[HISI_SAS_MAX_QUEUES];
John Garry7eb78692015-11-18 00:50:31 +0800114 struct hisi_sas_phy phy[HISI_SAS_MAX_PHYS];
115 struct hisi_sas_port port[HISI_SAS_MAX_PHYS];
John Garrye26b2f42015-11-18 00:50:32 +0800116
117 int queue_count;
118 char *int_names;
John Garry6be6de12015-11-18 00:50:34 +0800119
120 struct dma_pool *sge_page_pool;
John Garryaf740db2015-11-18 00:50:41 +0800121 struct hisi_sas_device devices[HISI_SAS_MAX_DEVICES];
John Garry6be6de12015-11-18 00:50:34 +0800122 struct dma_pool *command_table_pool;
123 struct dma_pool *status_buffer_pool;
124 struct hisi_sas_cmd_hdr *cmd_hdr[HISI_SAS_MAX_QUEUES];
125 dma_addr_t cmd_hdr_dma[HISI_SAS_MAX_QUEUES];
126 void *complete_hdr[HISI_SAS_MAX_QUEUES];
127 dma_addr_t complete_hdr_dma[HISI_SAS_MAX_QUEUES];
128 struct hisi_sas_initial_fis *initial_fis;
129 dma_addr_t initial_fis_dma;
130 struct hisi_sas_itct *itct;
131 dma_addr_t itct_dma;
132 struct hisi_sas_iost *iost;
133 dma_addr_t iost_dma;
134 struct hisi_sas_breakpoint *breakpoint;
135 dma_addr_t breakpoint_dma;
136 struct hisi_sas_breakpoint *sata_breakpoint;
137 dma_addr_t sata_breakpoint_dma;
138 struct hisi_sas_slot *slot_info;
John Garry7eb78692015-11-18 00:50:31 +0800139 const struct hisi_sas_hw *hw; /* Low level hw interface */
140};
141
John Garryc799d6b2015-11-18 00:50:33 +0800142/* Generic HW DMA host memory structures */
143/* Delivery queue header */
144struct hisi_sas_cmd_hdr {
145 /* dw0 */
146 __le32 dw0;
147
148 /* dw1 */
149 __le32 dw1;
150
151 /* dw2 */
152 __le32 dw2;
153
154 /* dw3 */
155 __le32 transfer_tags;
156
157 /* dw4 */
158 __le32 data_transfer_len;
159
160 /* dw5 */
161 __le32 first_burst_num;
162
163 /* dw6 */
164 __le32 sg_len;
165
166 /* dw7 */
167 __le32 dw7;
168
169 /* dw8-9 */
170 __le64 cmd_table_addr;
171
172 /* dw10-11 */
173 __le64 sts_buffer_addr;
174
175 /* dw12-13 */
176 __le64 prd_table_addr;
177
178 /* dw14-15 */
179 __le64 dif_prd_table_addr;
180};
181
182struct hisi_sas_itct {
183 __le64 qw0;
184 __le64 sas_addr;
185 __le64 qw2;
186 __le64 qw3;
187 __le64 qw4;
188 __le64 qw_sata_ncq0_3;
189 __le64 qw_sata_ncq7_4;
190 __le64 qw_sata_ncq11_8;
191 __le64 qw_sata_ncq15_12;
192 __le64 qw_sata_ncq19_16;
193 __le64 qw_sata_ncq23_20;
194 __le64 qw_sata_ncq27_24;
195 __le64 qw_sata_ncq31_28;
196 __le64 qw_non_ncq_iptt;
197 __le64 qw_rsvd0;
198 __le64 qw_rsvd1;
199};
200
201struct hisi_sas_iost {
202 __le64 qw0;
203 __le64 qw1;
204 __le64 qw2;
205 __le64 qw3;
206};
207
208struct hisi_sas_err_record {
209 /* dw0 */
210 __le32 dma_err_type;
211
212 /* dw1 */
213 __le32 trans_tx_fail_type;
214
215 /* dw2 */
216 __le32 trans_rx_fail_type;
217
218 /* dw3 */
219 u32 rsvd;
220};
221
222struct hisi_sas_initial_fis {
223 struct hisi_sas_err_record err_record;
224 struct dev_to_host_fis fis;
225 u32 rsvd[3];
226};
227
228struct hisi_sas_breakpoint {
229 u8 data[128]; /*io128 byte*/
230};
231
232struct hisi_sas_sge {
233 __le64 addr;
234 __le32 page_ctrl_0;
235 __le32 page_ctrl_1;
236 __le32 data_len;
237 __le32 data_off;
238};
239
240struct hisi_sas_command_table_smp {
241 u8 bytes[44];
242};
243
244struct hisi_sas_command_table_stp {
245 struct host_to_dev_fis command_fis;
246 u8 dummy[12];
247 u8 atapi_cdb[ATAPI_CDB_LEN];
248};
249
John Garry7eb78692015-11-18 00:50:31 +0800250#define HISI_SAS_SGE_PAGE_CNT SCSI_MAX_SG_SEGMENTS
John Garryc799d6b2015-11-18 00:50:33 +0800251struct hisi_sas_sge_page {
252 struct hisi_sas_sge sge[HISI_SAS_SGE_PAGE_CNT];
253};
254
255struct hisi_sas_command_table_ssp {
256 struct ssp_frame_hdr hdr;
257 union {
258 struct {
259 struct ssp_command_iu task;
260 u32 prot[6];
261 };
262 struct ssp_tmf_iu ssp_task;
263 struct xfer_rdy_iu xfer_rdy;
264 struct ssp_response_iu ssp_res;
265 } u;
266};
267
268union hisi_sas_command_table {
269 struct hisi_sas_command_table_ssp ssp;
270 struct hisi_sas_command_table_smp smp;
271 struct hisi_sas_command_table_stp stp;
272};
John Garry9fb10b52015-11-18 00:50:44 +0800273extern int hisi_sas_probe(struct platform_device *pdev,
274 const struct hisi_sas_hw *ops);
275extern int hisi_sas_remove(struct platform_device *pdev);
John Garryc799d6b2015-11-18 00:50:33 +0800276
John Garrye8899fa2015-11-18 00:50:30 +0800277#endif