blob: 938fa755300b1958e89deedf38b88b7f1f173a2f [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
John Garry07d78592015-11-18 00:50:47 +080041enum {
42 PORT_TYPE_SAS = (1U << 1),
43 PORT_TYPE_SATA = (1U << 0),
44};
45
John Garryaf740db2015-11-18 00:50:41 +080046enum dev_status {
47 HISI_SAS_DEV_NORMAL,
48 HISI_SAS_DEV_EH,
49};
John Garry7eb78692015-11-18 00:50:31 +080050struct hisi_sas_phy {
John Garry976867e2015-11-18 00:50:42 +080051 struct hisi_hba *hisi_hba;
52 struct hisi_sas_port *port;
John Garry7eb78692015-11-18 00:50:31 +080053 struct asd_sas_phy sas_phy;
John Garry976867e2015-11-18 00:50:42 +080054 struct sas_identify identify;
55 struct timer_list timer;
56 u64 port_id; /* from hw */
John Garry5d742422015-11-18 00:50:38 +080057 u64 dev_sas_addr;
John Garry976867e2015-11-18 00:50:42 +080058 u64 phy_type;
59 u64 frame_rcvd_size;
60 u8 frame_rcvd[32];
61 u8 phy_attached;
62 u8 reserved[3];
63 enum sas_linkrate minimum_linkrate;
64 enum sas_linkrate maximum_linkrate;
John Garry7eb78692015-11-18 00:50:31 +080065};
66
67struct hisi_sas_port {
68 struct asd_sas_port sas_port;
John Garry976867e2015-11-18 00:50:42 +080069 u8 port_attached;
70 u8 id; /* from hw */
71 struct list_head list;
John Garry7eb78692015-11-18 00:50:31 +080072};
73
John Garry9101a072015-11-18 00:50:37 +080074struct hisi_sas_cq {
75 struct hisi_hba *hisi_hba;
76 int id;
77};
78
John Garryaf740db2015-11-18 00:50:41 +080079struct hisi_sas_device {
80 enum sas_device_type dev_type;
81 u64 device_id;
82 u8 dev_status;
83};
84
John Garry6be6de12015-11-18 00:50:34 +080085struct hisi_sas_slot {
86};
87
John Garry7eb78692015-11-18 00:50:31 +080088struct hisi_sas_hw {
John Garry8ff1d572015-11-18 00:50:46 +080089 int (*hw_init)(struct hisi_hba *hisi_hba);
John Garry6be6de12015-11-18 00:50:34 +080090 int complete_hdr_size;
John Garry7eb78692015-11-18 00:50:31 +080091};
92
93struct hisi_hba {
94 /* This must be the first element, used by SHOST_TO_SAS_HA */
95 struct sas_ha_struct *p;
96
97 struct platform_device *pdev;
John Garrye26b2f42015-11-18 00:50:32 +080098 void __iomem *regs;
99 struct regmap *ctrl;
100 u32 ctrl_reset_reg;
101 u32 ctrl_reset_sts_reg;
102 u32 ctrl_clock_ena_reg;
John Garry7eb78692015-11-18 00:50:31 +0800103 u8 sas_addr[SAS_ADDR_SIZE];
104
105 int n_phy;
John Garryfa42d802015-11-18 00:50:43 +0800106 spinlock_t lock;
John Garry7eb78692015-11-18 00:50:31 +0800107
John Garryfa42d802015-11-18 00:50:43 +0800108 struct timer_list timer;
John Garry7e9080e2015-11-18 00:50:40 +0800109 struct workqueue_struct *wq;
John Garry257efd12015-11-18 00:50:36 +0800110
111 int slot_index_count;
112 unsigned long *slot_index_tags;
113
John Garry7eb78692015-11-18 00:50:31 +0800114 /* SCSI/SAS glue */
115 struct sas_ha_struct sha;
116 struct Scsi_Host *shost;
John Garry9101a072015-11-18 00:50:37 +0800117
118 struct hisi_sas_cq cq[HISI_SAS_MAX_QUEUES];
John Garry7eb78692015-11-18 00:50:31 +0800119 struct hisi_sas_phy phy[HISI_SAS_MAX_PHYS];
120 struct hisi_sas_port port[HISI_SAS_MAX_PHYS];
John Garrye26b2f42015-11-18 00:50:32 +0800121
122 int queue_count;
123 char *int_names;
John Garry6be6de12015-11-18 00:50:34 +0800124
125 struct dma_pool *sge_page_pool;
John Garryaf740db2015-11-18 00:50:41 +0800126 struct hisi_sas_device devices[HISI_SAS_MAX_DEVICES];
John Garry6be6de12015-11-18 00:50:34 +0800127 struct dma_pool *command_table_pool;
128 struct dma_pool *status_buffer_pool;
129 struct hisi_sas_cmd_hdr *cmd_hdr[HISI_SAS_MAX_QUEUES];
130 dma_addr_t cmd_hdr_dma[HISI_SAS_MAX_QUEUES];
131 void *complete_hdr[HISI_SAS_MAX_QUEUES];
132 dma_addr_t complete_hdr_dma[HISI_SAS_MAX_QUEUES];
133 struct hisi_sas_initial_fis *initial_fis;
134 dma_addr_t initial_fis_dma;
135 struct hisi_sas_itct *itct;
136 dma_addr_t itct_dma;
137 struct hisi_sas_iost *iost;
138 dma_addr_t iost_dma;
139 struct hisi_sas_breakpoint *breakpoint;
140 dma_addr_t breakpoint_dma;
141 struct hisi_sas_breakpoint *sata_breakpoint;
142 dma_addr_t sata_breakpoint_dma;
143 struct hisi_sas_slot *slot_info;
John Garry7eb78692015-11-18 00:50:31 +0800144 const struct hisi_sas_hw *hw; /* Low level hw interface */
145};
146
John Garryc799d6b2015-11-18 00:50:33 +0800147/* Generic HW DMA host memory structures */
148/* Delivery queue header */
149struct hisi_sas_cmd_hdr {
150 /* dw0 */
151 __le32 dw0;
152
153 /* dw1 */
154 __le32 dw1;
155
156 /* dw2 */
157 __le32 dw2;
158
159 /* dw3 */
160 __le32 transfer_tags;
161
162 /* dw4 */
163 __le32 data_transfer_len;
164
165 /* dw5 */
166 __le32 first_burst_num;
167
168 /* dw6 */
169 __le32 sg_len;
170
171 /* dw7 */
172 __le32 dw7;
173
174 /* dw8-9 */
175 __le64 cmd_table_addr;
176
177 /* dw10-11 */
178 __le64 sts_buffer_addr;
179
180 /* dw12-13 */
181 __le64 prd_table_addr;
182
183 /* dw14-15 */
184 __le64 dif_prd_table_addr;
185};
186
187struct hisi_sas_itct {
188 __le64 qw0;
189 __le64 sas_addr;
190 __le64 qw2;
191 __le64 qw3;
192 __le64 qw4;
193 __le64 qw_sata_ncq0_3;
194 __le64 qw_sata_ncq7_4;
195 __le64 qw_sata_ncq11_8;
196 __le64 qw_sata_ncq15_12;
197 __le64 qw_sata_ncq19_16;
198 __le64 qw_sata_ncq23_20;
199 __le64 qw_sata_ncq27_24;
200 __le64 qw_sata_ncq31_28;
201 __le64 qw_non_ncq_iptt;
202 __le64 qw_rsvd0;
203 __le64 qw_rsvd1;
204};
205
206struct hisi_sas_iost {
207 __le64 qw0;
208 __le64 qw1;
209 __le64 qw2;
210 __le64 qw3;
211};
212
213struct hisi_sas_err_record {
214 /* dw0 */
215 __le32 dma_err_type;
216
217 /* dw1 */
218 __le32 trans_tx_fail_type;
219
220 /* dw2 */
221 __le32 trans_rx_fail_type;
222
223 /* dw3 */
224 u32 rsvd;
225};
226
227struct hisi_sas_initial_fis {
228 struct hisi_sas_err_record err_record;
229 struct dev_to_host_fis fis;
230 u32 rsvd[3];
231};
232
233struct hisi_sas_breakpoint {
234 u8 data[128]; /*io128 byte*/
235};
236
237struct hisi_sas_sge {
238 __le64 addr;
239 __le32 page_ctrl_0;
240 __le32 page_ctrl_1;
241 __le32 data_len;
242 __le32 data_off;
243};
244
245struct hisi_sas_command_table_smp {
246 u8 bytes[44];
247};
248
249struct hisi_sas_command_table_stp {
250 struct host_to_dev_fis command_fis;
251 u8 dummy[12];
252 u8 atapi_cdb[ATAPI_CDB_LEN];
253};
254
John Garry7eb78692015-11-18 00:50:31 +0800255#define HISI_SAS_SGE_PAGE_CNT SCSI_MAX_SG_SEGMENTS
John Garryc799d6b2015-11-18 00:50:33 +0800256struct hisi_sas_sge_page {
257 struct hisi_sas_sge sge[HISI_SAS_SGE_PAGE_CNT];
258};
259
260struct hisi_sas_command_table_ssp {
261 struct ssp_frame_hdr hdr;
262 union {
263 struct {
264 struct ssp_command_iu task;
265 u32 prot[6];
266 };
267 struct ssp_tmf_iu ssp_task;
268 struct xfer_rdy_iu xfer_rdy;
269 struct ssp_response_iu ssp_res;
270 } u;
271};
272
273union hisi_sas_command_table {
274 struct hisi_sas_command_table_ssp ssp;
275 struct hisi_sas_command_table_smp smp;
276 struct hisi_sas_command_table_stp stp;
277};
John Garry9fb10b52015-11-18 00:50:44 +0800278extern int hisi_sas_probe(struct platform_device *pdev,
279 const struct hisi_sas_hw *ops);
280extern int hisi_sas_remove(struct platform_device *pdev);
John Garryc799d6b2015-11-18 00:50:33 +0800281
John Garrye8899fa2015-11-18 00:50:30 +0800282#endif