blob: a018a8afa8943a18e12f4909fe0024ec2d8aa610 [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
John Garry4d558c72016-02-04 02:26:08 +080015#include <linux/acpi.h>
John Garry3bc45af2016-10-04 19:11:11 +080016#include <linux/clk.h>
John Garrye8899fa2015-11-18 00:50:30 +080017#include <linux/dmapool.h>
18#include <linux/mfd/syscon.h>
19#include <linux/module.h>
20#include <linux/of_address.h>
John Garrye8899fa2015-11-18 00:50:30 +080021#include <linux/platform_device.h>
John Garry4d558c72016-02-04 02:26:08 +080022#include <linux/property.h>
John Garrye8899fa2015-11-18 00:50:30 +080023#include <linux/regmap.h>
John Garry6f2ff1a2016-01-26 02:47:20 +080024#include <scsi/sas_ata.h>
John Garrye8899fa2015-11-18 00:50:30 +080025#include <scsi/libsas.h>
26
John Garry6328d902016-08-24 19:05:54 +080027#define DRV_VERSION "v1.6"
John Garrye8899fa2015-11-18 00:50:30 +080028
John Garry7eb78692015-11-18 00:50:31 +080029#define HISI_SAS_MAX_PHYS 9
John Garry6be6de12015-11-18 00:50:34 +080030#define HISI_SAS_MAX_QUEUES 32
31#define HISI_SAS_QUEUE_SLOTS 512
John Garry5560e9f2016-01-26 02:47:04 +080032#define HISI_SAS_MAX_ITCT_ENTRIES 2048
John Garry7eb78692015-11-18 00:50:31 +080033#define HISI_SAS_MAX_DEVICES HISI_SAS_MAX_ITCT_ENTRIES
John Garry7eb78692015-11-18 00:50:31 +080034
John Garry6be6de12015-11-18 00:50:34 +080035#define HISI_SAS_STATUS_BUF_SZ \
36 (sizeof(struct hisi_sas_err_record) + 1024)
37#define HISI_SAS_COMMAND_TABLE_SZ \
38 (((sizeof(union hisi_sas_command_table)+3)/4)*4)
39
John Garry42e7a692015-11-18 00:50:49 +080040#define HISI_SAS_MAX_SSP_RESP_SZ (sizeof(struct ssp_frame_hdr) + 1024)
John Garry66ee9992015-11-18 00:50:54 +080041#define HISI_SAS_MAX_SMP_RESP_SZ 1028
John Garry6f2ff1a2016-01-26 02:47:20 +080042#define HISI_SAS_MAX_STP_RESP_SZ 28
John Garry42e7a692015-11-18 00:50:49 +080043
John Garry98bf39f2016-01-26 02:47:02 +080044#define DEV_IS_EXPANDER(type) \
45 ((type == SAS_EDGE_EXPANDER_DEVICE) || \
46 (type == SAS_FANOUT_EXPANDER_DEVICE))
47
John Garryabda97c2015-11-18 00:50:51 +080048struct hisi_hba;
John Garryaf740db2015-11-18 00:50:41 +080049
John Garry07d78592015-11-18 00:50:47 +080050enum {
51 PORT_TYPE_SAS = (1U << 1),
52 PORT_TYPE_SATA = (1U << 0),
53};
54
John Garryaf740db2015-11-18 00:50:41 +080055enum dev_status {
56 HISI_SAS_DEV_NORMAL,
57 HISI_SAS_DEV_EH,
58};
John Garryabda97c2015-11-18 00:50:51 +080059
John Garry441c2742016-08-24 19:05:47 +080060enum {
61 HISI_SAS_INT_ABT_CMD = 0,
62 HISI_SAS_INT_ABT_DEV = 1,
63};
64
John Garryabda97c2015-11-18 00:50:51 +080065enum hisi_sas_dev_type {
66 HISI_SAS_DEV_TYPE_STP = 0,
67 HISI_SAS_DEV_TYPE_SSP,
68 HISI_SAS_DEV_TYPE_SATA,
69};
70
John Garry7eb78692015-11-18 00:50:31 +080071struct hisi_sas_phy {
John Garry976867e2015-11-18 00:50:42 +080072 struct hisi_hba *hisi_hba;
73 struct hisi_sas_port *port;
John Garry7eb78692015-11-18 00:50:31 +080074 struct asd_sas_phy sas_phy;
John Garry976867e2015-11-18 00:50:42 +080075 struct sas_identify identify;
76 struct timer_list timer;
John Garry66139922015-11-18 00:50:48 +080077 struct work_struct phyup_ws;
John Garry976867e2015-11-18 00:50:42 +080078 u64 port_id; /* from hw */
John Garry5d742422015-11-18 00:50:38 +080079 u64 dev_sas_addr;
John Garry976867e2015-11-18 00:50:42 +080080 u64 phy_type;
81 u64 frame_rcvd_size;
82 u8 frame_rcvd[32];
83 u8 phy_attached;
84 u8 reserved[3];
85 enum sas_linkrate minimum_linkrate;
86 enum sas_linkrate maximum_linkrate;
John Garry7eb78692015-11-18 00:50:31 +080087};
88
89struct hisi_sas_port {
90 struct asd_sas_port sas_port;
John Garry976867e2015-11-18 00:50:42 +080091 u8 port_attached;
92 u8 id; /* from hw */
93 struct list_head list;
John Garry7eb78692015-11-18 00:50:31 +080094};
95
John Garry9101a072015-11-18 00:50:37 +080096struct hisi_sas_cq {
97 struct hisi_hba *hisi_hba;
John Garryd177c402017-01-03 20:24:48 +080098 struct tasklet_struct tasklet;
John Garrye6c346f2016-09-06 23:36:11 +080099 int rd_point;
John Garry9101a072015-11-18 00:50:37 +0800100 int id;
101};
102
John Garry4fde02a2016-09-06 23:36:12 +0800103struct hisi_sas_dq {
104 struct hisi_hba *hisi_hba;
105 int wr_point;
106 int id;
107};
108
John Garryaf740db2015-11-18 00:50:41 +0800109struct hisi_sas_device {
110 enum sas_device_type dev_type;
John Garryabda97c2015-11-18 00:50:51 +0800111 struct hisi_hba *hisi_hba;
112 struct domain_device *sas_device;
113 u64 attached_phy;
John Garryaf740db2015-11-18 00:50:41 +0800114 u64 device_id;
John Garryf696cc32016-11-07 20:48:39 +0800115 atomic64_t running_req;
John Garryaf740db2015-11-18 00:50:41 +0800116 u8 dev_status;
117};
118
John Garry6be6de12015-11-18 00:50:34 +0800119struct hisi_sas_slot {
John Garry42e7a692015-11-18 00:50:49 +0800120 struct list_head entry;
121 struct sas_task *task;
122 struct hisi_sas_port *port;
123 u64 n_elem;
124 int dlvry_queue;
125 int dlvry_queue_slot;
John Garry27a3f222015-11-18 00:50:50 +0800126 int cmplt_queue;
127 int cmplt_queue_slot;
John Garry42e7a692015-11-18 00:50:49 +0800128 int idx;
John Garrycac9b2a2016-02-25 17:42:11 +0800129 int abort;
John Garry42e7a692015-11-18 00:50:49 +0800130 void *cmd_hdr;
131 dma_addr_t cmd_hdr_dma;
132 void *status_buffer;
133 dma_addr_t status_buffer_dma;
134 void *command_table;
135 dma_addr_t command_table_dma;
136 struct hisi_sas_sge_page *sge_page;
137 dma_addr_t sge_page_dma;
John Garrycac9b2a2016-02-25 17:42:11 +0800138 struct work_struct abort_slot;
John Garry42e7a692015-11-18 00:50:49 +0800139};
140
141struct hisi_sas_tmf_task {
142 u8 tmf;
143 u16 tag_of_task_to_be_managed;
John Garry6be6de12015-11-18 00:50:34 +0800144};
145
John Garry7eb78692015-11-18 00:50:31 +0800146struct hisi_sas_hw {
John Garry8ff1d572015-11-18 00:50:46 +0800147 int (*hw_init)(struct hisi_hba *hisi_hba);
John Garryabda97c2015-11-18 00:50:51 +0800148 void (*setup_itct)(struct hisi_hba *hisi_hba,
149 struct hisi_sas_device *device);
John Garry685b6d62016-04-15 21:36:36 +0800150 int (*slot_index_alloc)(struct hisi_hba *hisi_hba, int *slot_idx,
151 struct domain_device *device);
152 struct hisi_sas_device *(*alloc_dev)(struct domain_device *device);
John Garry66139922015-11-18 00:50:48 +0800153 void (*sl_notify)(struct hisi_hba *hisi_hba, int phy_no);
Xiang Chenc70f1fb2016-11-07 20:48:31 +0800154 int (*get_free_slot)(struct hisi_hba *hisi_hba, u32 dev_id,
155 int *q, int *s);
John Garry42e7a692015-11-18 00:50:49 +0800156 void (*start_delivery)(struct hisi_hba *hisi_hba);
157 int (*prep_ssp)(struct hisi_hba *hisi_hba,
158 struct hisi_sas_slot *slot, int is_tmf,
159 struct hisi_sas_tmf_task *tmf);
John Garry66ee9992015-11-18 00:50:54 +0800160 int (*prep_smp)(struct hisi_hba *hisi_hba,
161 struct hisi_sas_slot *slot);
John Garry6f2ff1a2016-01-26 02:47:20 +0800162 int (*prep_stp)(struct hisi_hba *hisi_hba,
163 struct hisi_sas_slot *slot);
John Garry441c2742016-08-24 19:05:47 +0800164 int (*prep_abort)(struct hisi_hba *hisi_hba,
165 struct hisi_sas_slot *slot,
166 int device_id, int abort_flag, int tag_to_abort);
John Garry27a3f222015-11-18 00:50:50 +0800167 int (*slot_complete)(struct hisi_hba *hisi_hba,
168 struct hisi_sas_slot *slot, int abort);
John Garrye4189d52015-11-18 00:50:57 +0800169 void (*phy_enable)(struct hisi_hba *hisi_hba, int phy_no);
170 void (*phy_disable)(struct hisi_hba *hisi_hba, int phy_no);
171 void (*phy_hard_reset)(struct hisi_hba *hisi_hba, int phy_no);
Xiang Chen2ae75782016-11-07 20:48:40 +0800172 void (*phy_set_linkrate)(struct hisi_hba *hisi_hba, int phy_no,
173 struct sas_phy_linkrates *linkrates);
174 enum sas_linkrate (*phy_get_max_linkrate)(void);
John Garry27a3f222015-11-18 00:50:50 +0800175 void (*free_device)(struct hisi_hba *hisi_hba,
176 struct hisi_sas_device *dev);
John Garry184a4632015-11-18 00:50:52 +0800177 int (*get_wideport_bitmap)(struct hisi_hba *hisi_hba, int port_id);
John Garrya8d547b2016-01-26 02:47:03 +0800178 int max_command_entries;
John Garry6be6de12015-11-18 00:50:34 +0800179 int complete_hdr_size;
John Garry7eb78692015-11-18 00:50:31 +0800180};
181
182struct hisi_hba {
183 /* This must be the first element, used by SHOST_TO_SAS_HA */
184 struct sas_ha_struct *p;
185
186 struct platform_device *pdev;
John Garrye26b2f42015-11-18 00:50:32 +0800187 void __iomem *regs;
188 struct regmap *ctrl;
189 u32 ctrl_reset_reg;
190 u32 ctrl_reset_sts_reg;
191 u32 ctrl_clock_ena_reg;
John Garry3bc45af2016-10-04 19:11:11 +0800192 u32 refclk_frequency_mhz;
John Garry7eb78692015-11-18 00:50:31 +0800193 u8 sas_addr[SAS_ADDR_SIZE];
194
195 int n_phy;
John Garry701f75e2015-11-18 00:50:55 +0800196 int scan_finished;
John Garryfa42d802015-11-18 00:50:43 +0800197 spinlock_t lock;
John Garry7eb78692015-11-18 00:50:31 +0800198
John Garryfa42d802015-11-18 00:50:43 +0800199 struct timer_list timer;
John Garry7e9080e2015-11-18 00:50:40 +0800200 struct workqueue_struct *wq;
John Garry257efd12015-11-18 00:50:36 +0800201
202 int slot_index_count;
203 unsigned long *slot_index_tags;
204
John Garry7eb78692015-11-18 00:50:31 +0800205 /* SCSI/SAS glue */
206 struct sas_ha_struct sha;
207 struct Scsi_Host *shost;
John Garry9101a072015-11-18 00:50:37 +0800208
209 struct hisi_sas_cq cq[HISI_SAS_MAX_QUEUES];
John Garry4fde02a2016-09-06 23:36:12 +0800210 struct hisi_sas_dq dq[HISI_SAS_MAX_QUEUES];
John Garry7eb78692015-11-18 00:50:31 +0800211 struct hisi_sas_phy phy[HISI_SAS_MAX_PHYS];
212 struct hisi_sas_port port[HISI_SAS_MAX_PHYS];
John Garrye26b2f42015-11-18 00:50:32 +0800213
214 int queue_count;
John Garry42e7a692015-11-18 00:50:49 +0800215 struct hisi_sas_slot *slot_prep;
John Garry6be6de12015-11-18 00:50:34 +0800216
217 struct dma_pool *sge_page_pool;
John Garryaf740db2015-11-18 00:50:41 +0800218 struct hisi_sas_device devices[HISI_SAS_MAX_DEVICES];
John Garry6be6de12015-11-18 00:50:34 +0800219 struct dma_pool *command_table_pool;
220 struct dma_pool *status_buffer_pool;
221 struct hisi_sas_cmd_hdr *cmd_hdr[HISI_SAS_MAX_QUEUES];
222 dma_addr_t cmd_hdr_dma[HISI_SAS_MAX_QUEUES];
223 void *complete_hdr[HISI_SAS_MAX_QUEUES];
224 dma_addr_t complete_hdr_dma[HISI_SAS_MAX_QUEUES];
225 struct hisi_sas_initial_fis *initial_fis;
226 dma_addr_t initial_fis_dma;
227 struct hisi_sas_itct *itct;
228 dma_addr_t itct_dma;
229 struct hisi_sas_iost *iost;
230 dma_addr_t iost_dma;
231 struct hisi_sas_breakpoint *breakpoint;
232 dma_addr_t breakpoint_dma;
233 struct hisi_sas_breakpoint *sata_breakpoint;
234 dma_addr_t sata_breakpoint_dma;
235 struct hisi_sas_slot *slot_info;
John Garry7eb78692015-11-18 00:50:31 +0800236 const struct hisi_sas_hw *hw; /* Low level hw interface */
237};
238
John Garryc799d6b2015-11-18 00:50:33 +0800239/* Generic HW DMA host memory structures */
240/* Delivery queue header */
241struct hisi_sas_cmd_hdr {
242 /* dw0 */
243 __le32 dw0;
244
245 /* dw1 */
246 __le32 dw1;
247
248 /* dw2 */
249 __le32 dw2;
250
251 /* dw3 */
252 __le32 transfer_tags;
253
254 /* dw4 */
255 __le32 data_transfer_len;
256
257 /* dw5 */
258 __le32 first_burst_num;
259
260 /* dw6 */
261 __le32 sg_len;
262
263 /* dw7 */
264 __le32 dw7;
265
266 /* dw8-9 */
267 __le64 cmd_table_addr;
268
269 /* dw10-11 */
270 __le64 sts_buffer_addr;
271
272 /* dw12-13 */
273 __le64 prd_table_addr;
274
275 /* dw14-15 */
276 __le64 dif_prd_table_addr;
277};
278
279struct hisi_sas_itct {
280 __le64 qw0;
281 __le64 sas_addr;
282 __le64 qw2;
283 __le64 qw3;
John Garry281e3bf2016-01-26 02:47:06 +0800284 __le64 qw4_15[12];
John Garryc799d6b2015-11-18 00:50:33 +0800285};
286
287struct hisi_sas_iost {
288 __le64 qw0;
289 __le64 qw1;
290 __le64 qw2;
291 __le64 qw3;
292};
293
294struct hisi_sas_err_record {
John Garry8d1eee72016-01-26 02:47:05 +0800295 u32 data[4];
John Garryc799d6b2015-11-18 00:50:33 +0800296};
297
298struct hisi_sas_initial_fis {
299 struct hisi_sas_err_record err_record;
300 struct dev_to_host_fis fis;
301 u32 rsvd[3];
302};
303
304struct hisi_sas_breakpoint {
305 u8 data[128]; /*io128 byte*/
306};
307
308struct hisi_sas_sge {
309 __le64 addr;
310 __le32 page_ctrl_0;
311 __le32 page_ctrl_1;
312 __le32 data_len;
313 __le32 data_off;
314};
315
316struct hisi_sas_command_table_smp {
317 u8 bytes[44];
318};
319
320struct hisi_sas_command_table_stp {
321 struct host_to_dev_fis command_fis;
322 u8 dummy[12];
323 u8 atapi_cdb[ATAPI_CDB_LEN];
324};
325
Ming Lin65e86172016-04-04 14:48:10 -0700326#define HISI_SAS_SGE_PAGE_CNT SG_CHUNK_SIZE
John Garryc799d6b2015-11-18 00:50:33 +0800327struct hisi_sas_sge_page {
328 struct hisi_sas_sge sge[HISI_SAS_SGE_PAGE_CNT];
329};
330
331struct hisi_sas_command_table_ssp {
332 struct ssp_frame_hdr hdr;
333 union {
334 struct {
335 struct ssp_command_iu task;
336 u32 prot[6];
337 };
338 struct ssp_tmf_iu ssp_task;
339 struct xfer_rdy_iu xfer_rdy;
340 struct ssp_response_iu ssp_res;
341 } u;
342};
343
344union hisi_sas_command_table {
345 struct hisi_sas_command_table_ssp ssp;
346 struct hisi_sas_command_table_smp smp;
347 struct hisi_sas_command_table_stp stp;
348};
John Garry2e244f02017-03-23 01:25:17 +0800349
350extern struct hisi_sas_port *to_hisi_sas_port(struct asd_sas_port *sas_port);
John Garry9fb10b52015-11-18 00:50:44 +0800351extern int hisi_sas_probe(struct platform_device *pdev,
352 const struct hisi_sas_hw *ops);
353extern int hisi_sas_remove(struct platform_device *pdev);
John Garryc799d6b2015-11-18 00:50:33 +0800354
John Garry184a4632015-11-18 00:50:52 +0800355extern void hisi_sas_phy_down(struct hisi_hba *hisi_hba, int phy_no, int rdy);
John Garry27a3f222015-11-18 00:50:50 +0800356extern void hisi_sas_slot_task_free(struct hisi_hba *hisi_hba,
357 struct sas_task *task,
358 struct hisi_sas_slot *slot);
John Garrye8899fa2015-11-18 00:50:30 +0800359#endif