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