blob: 6d1b7d88cb385d3b105f4230beef0d27faff98be [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
69 /* SCSI/SAS glue */
70 struct sas_ha_struct sha;
71 struct Scsi_Host *shost;
72 struct hisi_sas_phy phy[HISI_SAS_MAX_PHYS];
73 struct hisi_sas_port port[HISI_SAS_MAX_PHYS];
John Garrye26b2f42015-11-18 00:50:32 +080074
75 int queue_count;
76 char *int_names;
John Garry6be6de12015-11-18 00:50:34 +080077
78 struct dma_pool *sge_page_pool;
79 struct dma_pool *command_table_pool;
80 struct dma_pool *status_buffer_pool;
81 struct hisi_sas_cmd_hdr *cmd_hdr[HISI_SAS_MAX_QUEUES];
82 dma_addr_t cmd_hdr_dma[HISI_SAS_MAX_QUEUES];
83 void *complete_hdr[HISI_SAS_MAX_QUEUES];
84 dma_addr_t complete_hdr_dma[HISI_SAS_MAX_QUEUES];
85 struct hisi_sas_initial_fis *initial_fis;
86 dma_addr_t initial_fis_dma;
87 struct hisi_sas_itct *itct;
88 dma_addr_t itct_dma;
89 struct hisi_sas_iost *iost;
90 dma_addr_t iost_dma;
91 struct hisi_sas_breakpoint *breakpoint;
92 dma_addr_t breakpoint_dma;
93 struct hisi_sas_breakpoint *sata_breakpoint;
94 dma_addr_t sata_breakpoint_dma;
95 struct hisi_sas_slot *slot_info;
John Garry7eb78692015-11-18 00:50:31 +080096 const struct hisi_sas_hw *hw; /* Low level hw interface */
97};
98
John Garryc799d6b2015-11-18 00:50:33 +080099/* Generic HW DMA host memory structures */
100/* Delivery queue header */
101struct hisi_sas_cmd_hdr {
102 /* dw0 */
103 __le32 dw0;
104
105 /* dw1 */
106 __le32 dw1;
107
108 /* dw2 */
109 __le32 dw2;
110
111 /* dw3 */
112 __le32 transfer_tags;
113
114 /* dw4 */
115 __le32 data_transfer_len;
116
117 /* dw5 */
118 __le32 first_burst_num;
119
120 /* dw6 */
121 __le32 sg_len;
122
123 /* dw7 */
124 __le32 dw7;
125
126 /* dw8-9 */
127 __le64 cmd_table_addr;
128
129 /* dw10-11 */
130 __le64 sts_buffer_addr;
131
132 /* dw12-13 */
133 __le64 prd_table_addr;
134
135 /* dw14-15 */
136 __le64 dif_prd_table_addr;
137};
138
139struct hisi_sas_itct {
140 __le64 qw0;
141 __le64 sas_addr;
142 __le64 qw2;
143 __le64 qw3;
144 __le64 qw4;
145 __le64 qw_sata_ncq0_3;
146 __le64 qw_sata_ncq7_4;
147 __le64 qw_sata_ncq11_8;
148 __le64 qw_sata_ncq15_12;
149 __le64 qw_sata_ncq19_16;
150 __le64 qw_sata_ncq23_20;
151 __le64 qw_sata_ncq27_24;
152 __le64 qw_sata_ncq31_28;
153 __le64 qw_non_ncq_iptt;
154 __le64 qw_rsvd0;
155 __le64 qw_rsvd1;
156};
157
158struct hisi_sas_iost {
159 __le64 qw0;
160 __le64 qw1;
161 __le64 qw2;
162 __le64 qw3;
163};
164
165struct hisi_sas_err_record {
166 /* dw0 */
167 __le32 dma_err_type;
168
169 /* dw1 */
170 __le32 trans_tx_fail_type;
171
172 /* dw2 */
173 __le32 trans_rx_fail_type;
174
175 /* dw3 */
176 u32 rsvd;
177};
178
179struct hisi_sas_initial_fis {
180 struct hisi_sas_err_record err_record;
181 struct dev_to_host_fis fis;
182 u32 rsvd[3];
183};
184
185struct hisi_sas_breakpoint {
186 u8 data[128]; /*io128 byte*/
187};
188
189struct hisi_sas_sge {
190 __le64 addr;
191 __le32 page_ctrl_0;
192 __le32 page_ctrl_1;
193 __le32 data_len;
194 __le32 data_off;
195};
196
197struct hisi_sas_command_table_smp {
198 u8 bytes[44];
199};
200
201struct hisi_sas_command_table_stp {
202 struct host_to_dev_fis command_fis;
203 u8 dummy[12];
204 u8 atapi_cdb[ATAPI_CDB_LEN];
205};
206
John Garry7eb78692015-11-18 00:50:31 +0800207#define HISI_SAS_SGE_PAGE_CNT SCSI_MAX_SG_SEGMENTS
John Garryc799d6b2015-11-18 00:50:33 +0800208struct hisi_sas_sge_page {
209 struct hisi_sas_sge sge[HISI_SAS_SGE_PAGE_CNT];
210};
211
212struct hisi_sas_command_table_ssp {
213 struct ssp_frame_hdr hdr;
214 union {
215 struct {
216 struct ssp_command_iu task;
217 u32 prot[6];
218 };
219 struct ssp_tmf_iu ssp_task;
220 struct xfer_rdy_iu xfer_rdy;
221 struct ssp_response_iu ssp_res;
222 } u;
223};
224
225union hisi_sas_command_table {
226 struct hisi_sas_command_table_ssp ssp;
227 struct hisi_sas_command_table_smp smp;
228 struct hisi_sas_command_table_stp stp;
229};
230
John Garrye8899fa2015-11-18 00:50:30 +0800231#endif