blob: c50384f60be693d598754a85af38a3bc9cb61c90 [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 Garry7eb78692015-11-18 00:50:31 +080040struct hisi_sas_phy {
41 struct asd_sas_phy sas_phy;
John Garry5d742422015-11-18 00:50:38 +080042 u64 dev_sas_addr;
John Garry7eb78692015-11-18 00:50:31 +080043};
44
45struct hisi_sas_port {
46 struct asd_sas_port sas_port;
47};
48
John Garry9101a072015-11-18 00:50:37 +080049struct hisi_sas_cq {
50 struct hisi_hba *hisi_hba;
51 int id;
52};
53
John Garry6be6de12015-11-18 00:50:34 +080054struct hisi_sas_slot {
55};
56
John Garry7eb78692015-11-18 00:50:31 +080057struct hisi_sas_hw {
John Garry6be6de12015-11-18 00:50:34 +080058 int complete_hdr_size;
John Garry7eb78692015-11-18 00:50:31 +080059};
60
61struct hisi_hba {
62 /* This must be the first element, used by SHOST_TO_SAS_HA */
63 struct sas_ha_struct *p;
64
65 struct platform_device *pdev;
John Garrye26b2f42015-11-18 00:50:32 +080066 void __iomem *regs;
67 struct regmap *ctrl;
68 u32 ctrl_reset_reg;
69 u32 ctrl_reset_sts_reg;
70 u32 ctrl_clock_ena_reg;
John Garry7eb78692015-11-18 00:50:31 +080071 u8 sas_addr[SAS_ADDR_SIZE];
72
73 int n_phy;
74
John Garry257efd12015-11-18 00:50:36 +080075
76 int slot_index_count;
77 unsigned long *slot_index_tags;
78
John Garry7eb78692015-11-18 00:50:31 +080079 /* SCSI/SAS glue */
80 struct sas_ha_struct sha;
81 struct Scsi_Host *shost;
John Garry9101a072015-11-18 00:50:37 +080082
83 struct hisi_sas_cq cq[HISI_SAS_MAX_QUEUES];
John Garry7eb78692015-11-18 00:50:31 +080084 struct hisi_sas_phy phy[HISI_SAS_MAX_PHYS];
85 struct hisi_sas_port port[HISI_SAS_MAX_PHYS];
John Garrye26b2f42015-11-18 00:50:32 +080086
87 int queue_count;
88 char *int_names;
John Garry6be6de12015-11-18 00:50:34 +080089
90 struct dma_pool *sge_page_pool;
91 struct dma_pool *command_table_pool;
92 struct dma_pool *status_buffer_pool;
93 struct hisi_sas_cmd_hdr *cmd_hdr[HISI_SAS_MAX_QUEUES];
94 dma_addr_t cmd_hdr_dma[HISI_SAS_MAX_QUEUES];
95 void *complete_hdr[HISI_SAS_MAX_QUEUES];
96 dma_addr_t complete_hdr_dma[HISI_SAS_MAX_QUEUES];
97 struct hisi_sas_initial_fis *initial_fis;
98 dma_addr_t initial_fis_dma;
99 struct hisi_sas_itct *itct;
100 dma_addr_t itct_dma;
101 struct hisi_sas_iost *iost;
102 dma_addr_t iost_dma;
103 struct hisi_sas_breakpoint *breakpoint;
104 dma_addr_t breakpoint_dma;
105 struct hisi_sas_breakpoint *sata_breakpoint;
106 dma_addr_t sata_breakpoint_dma;
107 struct hisi_sas_slot *slot_info;
John Garry7eb78692015-11-18 00:50:31 +0800108 const struct hisi_sas_hw *hw; /* Low level hw interface */
109};
110
John Garryc799d6b2015-11-18 00:50:33 +0800111/* Generic HW DMA host memory structures */
112/* Delivery queue header */
113struct hisi_sas_cmd_hdr {
114 /* dw0 */
115 __le32 dw0;
116
117 /* dw1 */
118 __le32 dw1;
119
120 /* dw2 */
121 __le32 dw2;
122
123 /* dw3 */
124 __le32 transfer_tags;
125
126 /* dw4 */
127 __le32 data_transfer_len;
128
129 /* dw5 */
130 __le32 first_burst_num;
131
132 /* dw6 */
133 __le32 sg_len;
134
135 /* dw7 */
136 __le32 dw7;
137
138 /* dw8-9 */
139 __le64 cmd_table_addr;
140
141 /* dw10-11 */
142 __le64 sts_buffer_addr;
143
144 /* dw12-13 */
145 __le64 prd_table_addr;
146
147 /* dw14-15 */
148 __le64 dif_prd_table_addr;
149};
150
151struct hisi_sas_itct {
152 __le64 qw0;
153 __le64 sas_addr;
154 __le64 qw2;
155 __le64 qw3;
156 __le64 qw4;
157 __le64 qw_sata_ncq0_3;
158 __le64 qw_sata_ncq7_4;
159 __le64 qw_sata_ncq11_8;
160 __le64 qw_sata_ncq15_12;
161 __le64 qw_sata_ncq19_16;
162 __le64 qw_sata_ncq23_20;
163 __le64 qw_sata_ncq27_24;
164 __le64 qw_sata_ncq31_28;
165 __le64 qw_non_ncq_iptt;
166 __le64 qw_rsvd0;
167 __le64 qw_rsvd1;
168};
169
170struct hisi_sas_iost {
171 __le64 qw0;
172 __le64 qw1;
173 __le64 qw2;
174 __le64 qw3;
175};
176
177struct hisi_sas_err_record {
178 /* dw0 */
179 __le32 dma_err_type;
180
181 /* dw1 */
182 __le32 trans_tx_fail_type;
183
184 /* dw2 */
185 __le32 trans_rx_fail_type;
186
187 /* dw3 */
188 u32 rsvd;
189};
190
191struct hisi_sas_initial_fis {
192 struct hisi_sas_err_record err_record;
193 struct dev_to_host_fis fis;
194 u32 rsvd[3];
195};
196
197struct hisi_sas_breakpoint {
198 u8 data[128]; /*io128 byte*/
199};
200
201struct hisi_sas_sge {
202 __le64 addr;
203 __le32 page_ctrl_0;
204 __le32 page_ctrl_1;
205 __le32 data_len;
206 __le32 data_off;
207};
208
209struct hisi_sas_command_table_smp {
210 u8 bytes[44];
211};
212
213struct hisi_sas_command_table_stp {
214 struct host_to_dev_fis command_fis;
215 u8 dummy[12];
216 u8 atapi_cdb[ATAPI_CDB_LEN];
217};
218
John Garry7eb78692015-11-18 00:50:31 +0800219#define HISI_SAS_SGE_PAGE_CNT SCSI_MAX_SG_SEGMENTS
John Garryc799d6b2015-11-18 00:50:33 +0800220struct hisi_sas_sge_page {
221 struct hisi_sas_sge sge[HISI_SAS_SGE_PAGE_CNT];
222};
223
224struct hisi_sas_command_table_ssp {
225 struct ssp_frame_hdr hdr;
226 union {
227 struct {
228 struct ssp_command_iu task;
229 u32 prot[6];
230 };
231 struct ssp_tmf_iu ssp_task;
232 struct xfer_rdy_iu xfer_rdy;
233 struct ssp_response_iu ssp_res;
234 } u;
235};
236
237union hisi_sas_command_table {
238 struct hisi_sas_command_table_ssp ssp;
239 struct hisi_sas_command_table_smp smp;
240 struct hisi_sas_command_table_stp stp;
241};
242
John Garrye8899fa2015-11-18 00:50:30 +0800243#endif