blob: f00b55b241e591eacac9d32ca6013acc6f2f2121 [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>
John Garrye8899fa2015-11-18 00:50:30 +080019#include <linux/platform_device.h>
20#include <linux/regmap.h>
John Garry6f2ff1a2016-01-26 02:47:20 +080021#include <scsi/sas_ata.h>
John Garrye8899fa2015-11-18 00:50:30 +080022#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 Garry5560e9f2016-01-26 02:47:04 +080029#define HISI_SAS_MAX_ITCT_ENTRIES 2048
John Garry7eb78692015-11-18 00:50:31 +080030#define HISI_SAS_MAX_DEVICES HISI_SAS_MAX_ITCT_ENTRIES
John Garry7eb78692015-11-18 00:50:31 +080031
John Garry6be6de12015-11-18 00:50:34 +080032#define HISI_SAS_STATUS_BUF_SZ \
33 (sizeof(struct hisi_sas_err_record) + 1024)
34#define HISI_SAS_COMMAND_TABLE_SZ \
35 (((sizeof(union hisi_sas_command_table)+3)/4)*4)
36
John Garry42e7a692015-11-18 00:50:49 +080037#define HISI_SAS_MAX_SSP_RESP_SZ (sizeof(struct ssp_frame_hdr) + 1024)
John Garry66ee9992015-11-18 00:50:54 +080038#define HISI_SAS_MAX_SMP_RESP_SZ 1028
John Garry6f2ff1a2016-01-26 02:47:20 +080039#define HISI_SAS_MAX_STP_RESP_SZ 28
John Garry42e7a692015-11-18 00:50:49 +080040
John Garry98bf39f2016-01-26 02:47:02 +080041#define DEV_IS_EXPANDER(type) \
42 ((type == SAS_EDGE_EXPANDER_DEVICE) || \
43 (type == SAS_FANOUT_EXPANDER_DEVICE))
44
John Garryabda97c2015-11-18 00:50:51 +080045struct hisi_hba;
John Garryaf740db2015-11-18 00:50:41 +080046
John Garry07d78592015-11-18 00:50:47 +080047enum {
48 PORT_TYPE_SAS = (1U << 1),
49 PORT_TYPE_SATA = (1U << 0),
50};
51
John Garryaf740db2015-11-18 00:50:41 +080052enum dev_status {
53 HISI_SAS_DEV_NORMAL,
54 HISI_SAS_DEV_EH,
55};
John Garryabda97c2015-11-18 00:50:51 +080056
57enum hisi_sas_dev_type {
58 HISI_SAS_DEV_TYPE_STP = 0,
59 HISI_SAS_DEV_TYPE_SSP,
60 HISI_SAS_DEV_TYPE_SATA,
61};
62
John Garry7eb78692015-11-18 00:50:31 +080063struct hisi_sas_phy {
John Garry976867e2015-11-18 00:50:42 +080064 struct hisi_hba *hisi_hba;
65 struct hisi_sas_port *port;
John Garry7eb78692015-11-18 00:50:31 +080066 struct asd_sas_phy sas_phy;
John Garry976867e2015-11-18 00:50:42 +080067 struct sas_identify identify;
68 struct timer_list timer;
John Garry66139922015-11-18 00:50:48 +080069 struct work_struct phyup_ws;
John Garry976867e2015-11-18 00:50:42 +080070 u64 port_id; /* from hw */
John Garry5d742422015-11-18 00:50:38 +080071 u64 dev_sas_addr;
John Garry976867e2015-11-18 00:50:42 +080072 u64 phy_type;
73 u64 frame_rcvd_size;
74 u8 frame_rcvd[32];
75 u8 phy_attached;
76 u8 reserved[3];
77 enum sas_linkrate minimum_linkrate;
78 enum sas_linkrate maximum_linkrate;
John Garry7eb78692015-11-18 00:50:31 +080079};
80
81struct hisi_sas_port {
82 struct asd_sas_port sas_port;
John Garry976867e2015-11-18 00:50:42 +080083 u8 port_attached;
84 u8 id; /* from hw */
85 struct list_head list;
John Garry7eb78692015-11-18 00:50:31 +080086};
87
John Garry9101a072015-11-18 00:50:37 +080088struct hisi_sas_cq {
89 struct hisi_hba *hisi_hba;
90 int id;
91};
92
John Garryaf740db2015-11-18 00:50:41 +080093struct hisi_sas_device {
94 enum sas_device_type dev_type;
John Garryabda97c2015-11-18 00:50:51 +080095 struct hisi_hba *hisi_hba;
96 struct domain_device *sas_device;
97 u64 attached_phy;
John Garryaf740db2015-11-18 00:50:41 +080098 u64 device_id;
John Garry42e7a692015-11-18 00:50:49 +080099 u64 running_req;
John Garryaf740db2015-11-18 00:50:41 +0800100 u8 dev_status;
101};
102
John Garry6be6de12015-11-18 00:50:34 +0800103struct hisi_sas_slot {
John Garry42e7a692015-11-18 00:50:49 +0800104 struct list_head entry;
105 struct sas_task *task;
106 struct hisi_sas_port *port;
107 u64 n_elem;
108 int dlvry_queue;
109 int dlvry_queue_slot;
John Garry27a3f222015-11-18 00:50:50 +0800110 int cmplt_queue;
111 int cmplt_queue_slot;
John Garry42e7a692015-11-18 00:50:49 +0800112 int idx;
113 void *cmd_hdr;
114 dma_addr_t cmd_hdr_dma;
115 void *status_buffer;
116 dma_addr_t status_buffer_dma;
117 void *command_table;
118 dma_addr_t command_table_dma;
119 struct hisi_sas_sge_page *sge_page;
120 dma_addr_t sge_page_dma;
121};
122
123struct hisi_sas_tmf_task {
124 u8 tmf;
125 u16 tag_of_task_to_be_managed;
John Garry6be6de12015-11-18 00:50:34 +0800126};
127
John Garry7eb78692015-11-18 00:50:31 +0800128struct hisi_sas_hw {
John Garry8ff1d572015-11-18 00:50:46 +0800129 int (*hw_init)(struct hisi_hba *hisi_hba);
John Garryabda97c2015-11-18 00:50:51 +0800130 void (*setup_itct)(struct hisi_hba *hisi_hba,
131 struct hisi_sas_device *device);
John Garry66139922015-11-18 00:50:48 +0800132 void (*sl_notify)(struct hisi_hba *hisi_hba, int phy_no);
John Garry42e7a692015-11-18 00:50:49 +0800133 int (*get_free_slot)(struct hisi_hba *hisi_hba, int *q, int *s);
134 void (*start_delivery)(struct hisi_hba *hisi_hba);
135 int (*prep_ssp)(struct hisi_hba *hisi_hba,
136 struct hisi_sas_slot *slot, int is_tmf,
137 struct hisi_sas_tmf_task *tmf);
John Garry66ee9992015-11-18 00:50:54 +0800138 int (*prep_smp)(struct hisi_hba *hisi_hba,
139 struct hisi_sas_slot *slot);
John Garry6f2ff1a2016-01-26 02:47:20 +0800140 int (*prep_stp)(struct hisi_hba *hisi_hba,
141 struct hisi_sas_slot *slot);
John Garry27a3f222015-11-18 00:50:50 +0800142 int (*slot_complete)(struct hisi_hba *hisi_hba,
143 struct hisi_sas_slot *slot, int abort);
John Garrye4189d52015-11-18 00:50:57 +0800144 void (*phy_enable)(struct hisi_hba *hisi_hba, int phy_no);
145 void (*phy_disable)(struct hisi_hba *hisi_hba, int phy_no);
146 void (*phy_hard_reset)(struct hisi_hba *hisi_hba, int phy_no);
John Garry27a3f222015-11-18 00:50:50 +0800147 void (*free_device)(struct hisi_hba *hisi_hba,
148 struct hisi_sas_device *dev);
John Garry184a4632015-11-18 00:50:52 +0800149 int (*get_wideport_bitmap)(struct hisi_hba *hisi_hba, int port_id);
John Garrya8d547b2016-01-26 02:47:03 +0800150 int max_command_entries;
John Garry6be6de12015-11-18 00:50:34 +0800151 int complete_hdr_size;
John Garry7eb78692015-11-18 00:50:31 +0800152};
153
154struct hisi_hba {
155 /* This must be the first element, used by SHOST_TO_SAS_HA */
156 struct sas_ha_struct *p;
157
158 struct platform_device *pdev;
John Garrye26b2f42015-11-18 00:50:32 +0800159 void __iomem *regs;
160 struct regmap *ctrl;
161 u32 ctrl_reset_reg;
162 u32 ctrl_reset_sts_reg;
163 u32 ctrl_clock_ena_reg;
John Garry7eb78692015-11-18 00:50:31 +0800164 u8 sas_addr[SAS_ADDR_SIZE];
165
166 int n_phy;
John Garry701f75e2015-11-18 00:50:55 +0800167 int scan_finished;
John Garryfa42d802015-11-18 00:50:43 +0800168 spinlock_t lock;
John Garry7eb78692015-11-18 00:50:31 +0800169
John Garryfa42d802015-11-18 00:50:43 +0800170 struct timer_list timer;
John Garry7e9080e2015-11-18 00:50:40 +0800171 struct workqueue_struct *wq;
John Garry257efd12015-11-18 00:50:36 +0800172
173 int slot_index_count;
174 unsigned long *slot_index_tags;
175
John Garry7eb78692015-11-18 00:50:31 +0800176 /* SCSI/SAS glue */
177 struct sas_ha_struct sha;
178 struct Scsi_Host *shost;
John Garry9101a072015-11-18 00:50:37 +0800179
180 struct hisi_sas_cq cq[HISI_SAS_MAX_QUEUES];
John Garry7eb78692015-11-18 00:50:31 +0800181 struct hisi_sas_phy phy[HISI_SAS_MAX_PHYS];
182 struct hisi_sas_port port[HISI_SAS_MAX_PHYS];
John Garrye26b2f42015-11-18 00:50:32 +0800183
184 int queue_count;
John Garry42e7a692015-11-18 00:50:49 +0800185 int queue;
John Garry42e7a692015-11-18 00:50:49 +0800186 struct hisi_sas_slot *slot_prep;
John Garry6be6de12015-11-18 00:50:34 +0800187
188 struct dma_pool *sge_page_pool;
John Garryaf740db2015-11-18 00:50:41 +0800189 struct hisi_sas_device devices[HISI_SAS_MAX_DEVICES];
John Garry6be6de12015-11-18 00:50:34 +0800190 struct dma_pool *command_table_pool;
191 struct dma_pool *status_buffer_pool;
192 struct hisi_sas_cmd_hdr *cmd_hdr[HISI_SAS_MAX_QUEUES];
193 dma_addr_t cmd_hdr_dma[HISI_SAS_MAX_QUEUES];
194 void *complete_hdr[HISI_SAS_MAX_QUEUES];
195 dma_addr_t complete_hdr_dma[HISI_SAS_MAX_QUEUES];
196 struct hisi_sas_initial_fis *initial_fis;
197 dma_addr_t initial_fis_dma;
198 struct hisi_sas_itct *itct;
199 dma_addr_t itct_dma;
200 struct hisi_sas_iost *iost;
201 dma_addr_t iost_dma;
202 struct hisi_sas_breakpoint *breakpoint;
203 dma_addr_t breakpoint_dma;
204 struct hisi_sas_breakpoint *sata_breakpoint;
205 dma_addr_t sata_breakpoint_dma;
206 struct hisi_sas_slot *slot_info;
John Garry7eb78692015-11-18 00:50:31 +0800207 const struct hisi_sas_hw *hw; /* Low level hw interface */
208};
209
John Garryc799d6b2015-11-18 00:50:33 +0800210/* Generic HW DMA host memory structures */
211/* Delivery queue header */
212struct hisi_sas_cmd_hdr {
213 /* dw0 */
214 __le32 dw0;
215
216 /* dw1 */
217 __le32 dw1;
218
219 /* dw2 */
220 __le32 dw2;
221
222 /* dw3 */
223 __le32 transfer_tags;
224
225 /* dw4 */
226 __le32 data_transfer_len;
227
228 /* dw5 */
229 __le32 first_burst_num;
230
231 /* dw6 */
232 __le32 sg_len;
233
234 /* dw7 */
235 __le32 dw7;
236
237 /* dw8-9 */
238 __le64 cmd_table_addr;
239
240 /* dw10-11 */
241 __le64 sts_buffer_addr;
242
243 /* dw12-13 */
244 __le64 prd_table_addr;
245
246 /* dw14-15 */
247 __le64 dif_prd_table_addr;
248};
249
250struct hisi_sas_itct {
251 __le64 qw0;
252 __le64 sas_addr;
253 __le64 qw2;
254 __le64 qw3;
John Garry281e3bf2016-01-26 02:47:06 +0800255 __le64 qw4_15[12];
John Garryc799d6b2015-11-18 00:50:33 +0800256};
257
258struct hisi_sas_iost {
259 __le64 qw0;
260 __le64 qw1;
261 __le64 qw2;
262 __le64 qw3;
263};
264
265struct hisi_sas_err_record {
John Garry8d1eee72016-01-26 02:47:05 +0800266 u32 data[4];
John Garryc799d6b2015-11-18 00:50:33 +0800267};
268
269struct hisi_sas_initial_fis {
270 struct hisi_sas_err_record err_record;
271 struct dev_to_host_fis fis;
272 u32 rsvd[3];
273};
274
275struct hisi_sas_breakpoint {
276 u8 data[128]; /*io128 byte*/
277};
278
279struct hisi_sas_sge {
280 __le64 addr;
281 __le32 page_ctrl_0;
282 __le32 page_ctrl_1;
283 __le32 data_len;
284 __le32 data_off;
285};
286
287struct hisi_sas_command_table_smp {
288 u8 bytes[44];
289};
290
291struct hisi_sas_command_table_stp {
292 struct host_to_dev_fis command_fis;
293 u8 dummy[12];
294 u8 atapi_cdb[ATAPI_CDB_LEN];
295};
296
John Garry7eb78692015-11-18 00:50:31 +0800297#define HISI_SAS_SGE_PAGE_CNT SCSI_MAX_SG_SEGMENTS
John Garryc799d6b2015-11-18 00:50:33 +0800298struct hisi_sas_sge_page {
299 struct hisi_sas_sge sge[HISI_SAS_SGE_PAGE_CNT];
300};
301
302struct hisi_sas_command_table_ssp {
303 struct ssp_frame_hdr hdr;
304 union {
305 struct {
306 struct ssp_command_iu task;
307 u32 prot[6];
308 };
309 struct ssp_tmf_iu ssp_task;
310 struct xfer_rdy_iu xfer_rdy;
311 struct ssp_response_iu ssp_res;
312 } u;
313};
314
315union hisi_sas_command_table {
316 struct hisi_sas_command_table_ssp ssp;
317 struct hisi_sas_command_table_smp smp;
318 struct hisi_sas_command_table_stp stp;
319};
John Garry9fb10b52015-11-18 00:50:44 +0800320extern int hisi_sas_probe(struct platform_device *pdev,
321 const struct hisi_sas_hw *ops);
322extern int hisi_sas_remove(struct platform_device *pdev);
John Garryc799d6b2015-11-18 00:50:33 +0800323
John Garry184a4632015-11-18 00:50:52 +0800324extern void hisi_sas_phy_down(struct hisi_hba *hisi_hba, int phy_no, int rdy);
John Garry27a3f222015-11-18 00:50:50 +0800325extern void hisi_sas_slot_task_free(struct hisi_hba *hisi_hba,
326 struct sas_task *task,
327 struct hisi_sas_slot *slot);
John Garrye8899fa2015-11-18 00:50:30 +0800328#endif