blob: 3a2400e8bb9594079663d85b28cd9f7c405c7f71 [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 Garry6be6de12015-11-18 00:50:34 +080084 int complete_hdr_size;
John Garry7eb78692015-11-18 00:50:31 +080085};
86
87struct hisi_hba {
88 /* This must be the first element, used by SHOST_TO_SAS_HA */
89 struct sas_ha_struct *p;
90
91 struct platform_device *pdev;
John Garrye26b2f42015-11-18 00:50:32 +080092 void __iomem *regs;
93 struct regmap *ctrl;
94 u32 ctrl_reset_reg;
95 u32 ctrl_reset_sts_reg;
96 u32 ctrl_clock_ena_reg;
John Garry7eb78692015-11-18 00:50:31 +080097 u8 sas_addr[SAS_ADDR_SIZE];
98
99 int n_phy;
100
John Garry7e9080e2015-11-18 00:50:40 +0800101 struct workqueue_struct *wq;
John Garry257efd12015-11-18 00:50:36 +0800102
103 int slot_index_count;
104 unsigned long *slot_index_tags;
105
John Garry7eb78692015-11-18 00:50:31 +0800106 /* SCSI/SAS glue */
107 struct sas_ha_struct sha;
108 struct Scsi_Host *shost;
John Garry9101a072015-11-18 00:50:37 +0800109
110 struct hisi_sas_cq cq[HISI_SAS_MAX_QUEUES];
John Garry7eb78692015-11-18 00:50:31 +0800111 struct hisi_sas_phy phy[HISI_SAS_MAX_PHYS];
112 struct hisi_sas_port port[HISI_SAS_MAX_PHYS];
John Garrye26b2f42015-11-18 00:50:32 +0800113
114 int queue_count;
115 char *int_names;
John Garry6be6de12015-11-18 00:50:34 +0800116
117 struct dma_pool *sge_page_pool;
John Garryaf740db2015-11-18 00:50:41 +0800118 struct hisi_sas_device devices[HISI_SAS_MAX_DEVICES];
John Garry6be6de12015-11-18 00:50:34 +0800119 struct dma_pool *command_table_pool;
120 struct dma_pool *status_buffer_pool;
121 struct hisi_sas_cmd_hdr *cmd_hdr[HISI_SAS_MAX_QUEUES];
122 dma_addr_t cmd_hdr_dma[HISI_SAS_MAX_QUEUES];
123 void *complete_hdr[HISI_SAS_MAX_QUEUES];
124 dma_addr_t complete_hdr_dma[HISI_SAS_MAX_QUEUES];
125 struct hisi_sas_initial_fis *initial_fis;
126 dma_addr_t initial_fis_dma;
127 struct hisi_sas_itct *itct;
128 dma_addr_t itct_dma;
129 struct hisi_sas_iost *iost;
130 dma_addr_t iost_dma;
131 struct hisi_sas_breakpoint *breakpoint;
132 dma_addr_t breakpoint_dma;
133 struct hisi_sas_breakpoint *sata_breakpoint;
134 dma_addr_t sata_breakpoint_dma;
135 struct hisi_sas_slot *slot_info;
John Garry7eb78692015-11-18 00:50:31 +0800136 const struct hisi_sas_hw *hw; /* Low level hw interface */
137};
138
John Garryc799d6b2015-11-18 00:50:33 +0800139/* Generic HW DMA host memory structures */
140/* Delivery queue header */
141struct hisi_sas_cmd_hdr {
142 /* dw0 */
143 __le32 dw0;
144
145 /* dw1 */
146 __le32 dw1;
147
148 /* dw2 */
149 __le32 dw2;
150
151 /* dw3 */
152 __le32 transfer_tags;
153
154 /* dw4 */
155 __le32 data_transfer_len;
156
157 /* dw5 */
158 __le32 first_burst_num;
159
160 /* dw6 */
161 __le32 sg_len;
162
163 /* dw7 */
164 __le32 dw7;
165
166 /* dw8-9 */
167 __le64 cmd_table_addr;
168
169 /* dw10-11 */
170 __le64 sts_buffer_addr;
171
172 /* dw12-13 */
173 __le64 prd_table_addr;
174
175 /* dw14-15 */
176 __le64 dif_prd_table_addr;
177};
178
179struct hisi_sas_itct {
180 __le64 qw0;
181 __le64 sas_addr;
182 __le64 qw2;
183 __le64 qw3;
184 __le64 qw4;
185 __le64 qw_sata_ncq0_3;
186 __le64 qw_sata_ncq7_4;
187 __le64 qw_sata_ncq11_8;
188 __le64 qw_sata_ncq15_12;
189 __le64 qw_sata_ncq19_16;
190 __le64 qw_sata_ncq23_20;
191 __le64 qw_sata_ncq27_24;
192 __le64 qw_sata_ncq31_28;
193 __le64 qw_non_ncq_iptt;
194 __le64 qw_rsvd0;
195 __le64 qw_rsvd1;
196};
197
198struct hisi_sas_iost {
199 __le64 qw0;
200 __le64 qw1;
201 __le64 qw2;
202 __le64 qw3;
203};
204
205struct hisi_sas_err_record {
206 /* dw0 */
207 __le32 dma_err_type;
208
209 /* dw1 */
210 __le32 trans_tx_fail_type;
211
212 /* dw2 */
213 __le32 trans_rx_fail_type;
214
215 /* dw3 */
216 u32 rsvd;
217};
218
219struct hisi_sas_initial_fis {
220 struct hisi_sas_err_record err_record;
221 struct dev_to_host_fis fis;
222 u32 rsvd[3];
223};
224
225struct hisi_sas_breakpoint {
226 u8 data[128]; /*io128 byte*/
227};
228
229struct hisi_sas_sge {
230 __le64 addr;
231 __le32 page_ctrl_0;
232 __le32 page_ctrl_1;
233 __le32 data_len;
234 __le32 data_off;
235};
236
237struct hisi_sas_command_table_smp {
238 u8 bytes[44];
239};
240
241struct hisi_sas_command_table_stp {
242 struct host_to_dev_fis command_fis;
243 u8 dummy[12];
244 u8 atapi_cdb[ATAPI_CDB_LEN];
245};
246
John Garry7eb78692015-11-18 00:50:31 +0800247#define HISI_SAS_SGE_PAGE_CNT SCSI_MAX_SG_SEGMENTS
John Garryc799d6b2015-11-18 00:50:33 +0800248struct hisi_sas_sge_page {
249 struct hisi_sas_sge sge[HISI_SAS_SGE_PAGE_CNT];
250};
251
252struct hisi_sas_command_table_ssp {
253 struct ssp_frame_hdr hdr;
254 union {
255 struct {
256 struct ssp_command_iu task;
257 u32 prot[6];
258 };
259 struct ssp_tmf_iu ssp_task;
260 struct xfer_rdy_iu xfer_rdy;
261 struct ssp_response_iu ssp_res;
262 } u;
263};
264
265union hisi_sas_command_table {
266 struct hisi_sas_command_table_ssp ssp;
267 struct hisi_sas_command_table_smp smp;
268 struct hisi_sas_command_table_stp stp;
269};
270
John Garrye8899fa2015-11-18 00:50:30 +0800271#endif