blob: d7cab724f203fadcc2f35cf8d4bd5c0ab68f54ab [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 Garrye8899fa2015-11-18 00:50:30 +080016#include <linux/dmapool.h>
17#include <linux/mfd/syscon.h>
18#include <linux/module.h>
19#include <linux/of_address.h>
John Garrye8899fa2015-11-18 00:50:30 +080020#include <linux/platform_device.h>
John Garry4d558c72016-02-04 02:26:08 +080021#include <linux/property.h>
John Garrye8899fa2015-11-18 00:50:30 +080022#include <linux/regmap.h>
John Garry6f2ff1a2016-01-26 02:47:20 +080023#include <scsi/sas_ata.h>
John Garrye8899fa2015-11-18 00:50:30 +080024#include <scsi/libsas.h>
25
John Garry33e56e42016-04-08 17:23:15 +080026#define DRV_VERSION "v1.4"
John Garrye8899fa2015-11-18 00:50:30 +080027
John Garry7eb78692015-11-18 00:50:31 +080028#define HISI_SAS_MAX_PHYS 9
John Garry6be6de12015-11-18 00:50:34 +080029#define HISI_SAS_MAX_QUEUES 32
30#define HISI_SAS_QUEUE_SLOTS 512
John Garry5560e9f2016-01-26 02:47:04 +080031#define HISI_SAS_MAX_ITCT_ENTRIES 2048
John Garry7eb78692015-11-18 00:50:31 +080032#define HISI_SAS_MAX_DEVICES HISI_SAS_MAX_ITCT_ENTRIES
John Garry7eb78692015-11-18 00:50:31 +080033
John Garry6be6de12015-11-18 00:50:34 +080034#define HISI_SAS_STATUS_BUF_SZ \
35 (sizeof(struct hisi_sas_err_record) + 1024)
36#define HISI_SAS_COMMAND_TABLE_SZ \
37 (((sizeof(union hisi_sas_command_table)+3)/4)*4)
38
John Garry42e7a692015-11-18 00:50:49 +080039#define HISI_SAS_MAX_SSP_RESP_SZ (sizeof(struct ssp_frame_hdr) + 1024)
John Garry66ee9992015-11-18 00:50:54 +080040#define HISI_SAS_MAX_SMP_RESP_SZ 1028
John Garry6f2ff1a2016-01-26 02:47:20 +080041#define HISI_SAS_MAX_STP_RESP_SZ 28
John Garry42e7a692015-11-18 00:50:49 +080042
John Garry98bf39f2016-01-26 02:47:02 +080043#define DEV_IS_EXPANDER(type) \
44 ((type == SAS_EDGE_EXPANDER_DEVICE) || \
45 (type == SAS_FANOUT_EXPANDER_DEVICE))
46
John Garryabda97c2015-11-18 00:50:51 +080047struct hisi_hba;
John Garryaf740db2015-11-18 00:50:41 +080048
John Garry07d78592015-11-18 00:50:47 +080049enum {
50 PORT_TYPE_SAS = (1U << 1),
51 PORT_TYPE_SATA = (1U << 0),
52};
53
John Garryaf740db2015-11-18 00:50:41 +080054enum dev_status {
55 HISI_SAS_DEV_NORMAL,
56 HISI_SAS_DEV_EH,
57};
John Garryabda97c2015-11-18 00:50:51 +080058
59enum hisi_sas_dev_type {
60 HISI_SAS_DEV_TYPE_STP = 0,
61 HISI_SAS_DEV_TYPE_SSP,
62 HISI_SAS_DEV_TYPE_SATA,
63};
64
John Garry7eb78692015-11-18 00:50:31 +080065struct hisi_sas_phy {
John Garry976867e2015-11-18 00:50:42 +080066 struct hisi_hba *hisi_hba;
67 struct hisi_sas_port *port;
John Garry7eb78692015-11-18 00:50:31 +080068 struct asd_sas_phy sas_phy;
John Garry976867e2015-11-18 00:50:42 +080069 struct sas_identify identify;
70 struct timer_list timer;
John Garry66139922015-11-18 00:50:48 +080071 struct work_struct phyup_ws;
John Garry976867e2015-11-18 00:50:42 +080072 u64 port_id; /* from hw */
John Garry5d742422015-11-18 00:50:38 +080073 u64 dev_sas_addr;
John Garry976867e2015-11-18 00:50:42 +080074 u64 phy_type;
75 u64 frame_rcvd_size;
76 u8 frame_rcvd[32];
77 u8 phy_attached;
78 u8 reserved[3];
79 enum sas_linkrate minimum_linkrate;
80 enum sas_linkrate maximum_linkrate;
John Garry7eb78692015-11-18 00:50:31 +080081};
82
83struct hisi_sas_port {
84 struct asd_sas_port sas_port;
John Garry976867e2015-11-18 00:50:42 +080085 u8 port_attached;
86 u8 id; /* from hw */
87 struct list_head list;
John Garry7eb78692015-11-18 00:50:31 +080088};
89
John Garry9101a072015-11-18 00:50:37 +080090struct hisi_sas_cq {
91 struct hisi_hba *hisi_hba;
92 int id;
93};
94
John Garryaf740db2015-11-18 00:50:41 +080095struct hisi_sas_device {
96 enum sas_device_type dev_type;
John Garryabda97c2015-11-18 00:50:51 +080097 struct hisi_hba *hisi_hba;
98 struct domain_device *sas_device;
99 u64 attached_phy;
John Garryaf740db2015-11-18 00:50:41 +0800100 u64 device_id;
John Garry42e7a692015-11-18 00:50:49 +0800101 u64 running_req;
John Garryaf740db2015-11-18 00:50:41 +0800102 u8 dev_status;
103};
104
John Garry6be6de12015-11-18 00:50:34 +0800105struct hisi_sas_slot {
John Garry42e7a692015-11-18 00:50:49 +0800106 struct list_head entry;
107 struct sas_task *task;
108 struct hisi_sas_port *port;
109 u64 n_elem;
110 int dlvry_queue;
111 int dlvry_queue_slot;
John Garry27a3f222015-11-18 00:50:50 +0800112 int cmplt_queue;
113 int cmplt_queue_slot;
John Garry42e7a692015-11-18 00:50:49 +0800114 int idx;
John Garrycac9b2a2016-02-25 17:42:11 +0800115 int abort;
John Garry42e7a692015-11-18 00:50:49 +0800116 void *cmd_hdr;
117 dma_addr_t cmd_hdr_dma;
118 void *status_buffer;
119 dma_addr_t status_buffer_dma;
120 void *command_table;
121 dma_addr_t command_table_dma;
122 struct hisi_sas_sge_page *sge_page;
123 dma_addr_t sge_page_dma;
John Garrycac9b2a2016-02-25 17:42:11 +0800124 struct work_struct abort_slot;
John Garry42e7a692015-11-18 00:50:49 +0800125};
126
127struct hisi_sas_tmf_task {
128 u8 tmf;
129 u16 tag_of_task_to_be_managed;
John Garry6be6de12015-11-18 00:50:34 +0800130};
131
John Garry7eb78692015-11-18 00:50:31 +0800132struct hisi_sas_hw {
John Garry8ff1d572015-11-18 00:50:46 +0800133 int (*hw_init)(struct hisi_hba *hisi_hba);
John Garryabda97c2015-11-18 00:50:51 +0800134 void (*setup_itct)(struct hisi_hba *hisi_hba,
135 struct hisi_sas_device *device);
John Garry685b6d62016-04-15 21:36:36 +0800136 int (*slot_index_alloc)(struct hisi_hba *hisi_hba, int *slot_idx,
137 struct domain_device *device);
138 struct hisi_sas_device *(*alloc_dev)(struct domain_device *device);
John Garry66139922015-11-18 00:50:48 +0800139 void (*sl_notify)(struct hisi_hba *hisi_hba, int phy_no);
John Garry42e7a692015-11-18 00:50:49 +0800140 int (*get_free_slot)(struct hisi_hba *hisi_hba, int *q, int *s);
141 void (*start_delivery)(struct hisi_hba *hisi_hba);
142 int (*prep_ssp)(struct hisi_hba *hisi_hba,
143 struct hisi_sas_slot *slot, int is_tmf,
144 struct hisi_sas_tmf_task *tmf);
John Garry66ee9992015-11-18 00:50:54 +0800145 int (*prep_smp)(struct hisi_hba *hisi_hba,
146 struct hisi_sas_slot *slot);
John Garry6f2ff1a2016-01-26 02:47:20 +0800147 int (*prep_stp)(struct hisi_hba *hisi_hba,
148 struct hisi_sas_slot *slot);
John Garry27a3f222015-11-18 00:50:50 +0800149 int (*slot_complete)(struct hisi_hba *hisi_hba,
150 struct hisi_sas_slot *slot, int abort);
John Garrye4189d52015-11-18 00:50:57 +0800151 void (*phy_enable)(struct hisi_hba *hisi_hba, int phy_no);
152 void (*phy_disable)(struct hisi_hba *hisi_hba, int phy_no);
153 void (*phy_hard_reset)(struct hisi_hba *hisi_hba, int phy_no);
John Garry27a3f222015-11-18 00:50:50 +0800154 void (*free_device)(struct hisi_hba *hisi_hba,
155 struct hisi_sas_device *dev);
John Garry184a4632015-11-18 00:50:52 +0800156 int (*get_wideport_bitmap)(struct hisi_hba *hisi_hba, int port_id);
John Garrya8d547b2016-01-26 02:47:03 +0800157 int max_command_entries;
John Garry6be6de12015-11-18 00:50:34 +0800158 int complete_hdr_size;
John Garry7eb78692015-11-18 00:50:31 +0800159};
160
161struct hisi_hba {
162 /* This must be the first element, used by SHOST_TO_SAS_HA */
163 struct sas_ha_struct *p;
164
165 struct platform_device *pdev;
John Garrye26b2f42015-11-18 00:50:32 +0800166 void __iomem *regs;
167 struct regmap *ctrl;
168 u32 ctrl_reset_reg;
169 u32 ctrl_reset_sts_reg;
170 u32 ctrl_clock_ena_reg;
John Garry7eb78692015-11-18 00:50:31 +0800171 u8 sas_addr[SAS_ADDR_SIZE];
172
173 int n_phy;
John Garry701f75e2015-11-18 00:50:55 +0800174 int scan_finished;
John Garryfa42d802015-11-18 00:50:43 +0800175 spinlock_t lock;
John Garry7eb78692015-11-18 00:50:31 +0800176
John Garryfa42d802015-11-18 00:50:43 +0800177 struct timer_list timer;
John Garry7e9080e2015-11-18 00:50:40 +0800178 struct workqueue_struct *wq;
John Garry257efd12015-11-18 00:50:36 +0800179
180 int slot_index_count;
181 unsigned long *slot_index_tags;
182
John Garry7eb78692015-11-18 00:50:31 +0800183 /* SCSI/SAS glue */
184 struct sas_ha_struct sha;
185 struct Scsi_Host *shost;
John Garry9101a072015-11-18 00:50:37 +0800186
187 struct hisi_sas_cq cq[HISI_SAS_MAX_QUEUES];
John Garry7eb78692015-11-18 00:50:31 +0800188 struct hisi_sas_phy phy[HISI_SAS_MAX_PHYS];
189 struct hisi_sas_port port[HISI_SAS_MAX_PHYS];
John Garrye26b2f42015-11-18 00:50:32 +0800190
191 int queue_count;
John Garry42e7a692015-11-18 00:50:49 +0800192 int queue;
John Garry42e7a692015-11-18 00:50:49 +0800193 struct hisi_sas_slot *slot_prep;
John Garry6be6de12015-11-18 00:50:34 +0800194
195 struct dma_pool *sge_page_pool;
John Garryaf740db2015-11-18 00:50:41 +0800196 struct hisi_sas_device devices[HISI_SAS_MAX_DEVICES];
John Garry6be6de12015-11-18 00:50:34 +0800197 struct dma_pool *command_table_pool;
198 struct dma_pool *status_buffer_pool;
199 struct hisi_sas_cmd_hdr *cmd_hdr[HISI_SAS_MAX_QUEUES];
200 dma_addr_t cmd_hdr_dma[HISI_SAS_MAX_QUEUES];
201 void *complete_hdr[HISI_SAS_MAX_QUEUES];
202 dma_addr_t complete_hdr_dma[HISI_SAS_MAX_QUEUES];
203 struct hisi_sas_initial_fis *initial_fis;
204 dma_addr_t initial_fis_dma;
205 struct hisi_sas_itct *itct;
206 dma_addr_t itct_dma;
207 struct hisi_sas_iost *iost;
208 dma_addr_t iost_dma;
209 struct hisi_sas_breakpoint *breakpoint;
210 dma_addr_t breakpoint_dma;
211 struct hisi_sas_breakpoint *sata_breakpoint;
212 dma_addr_t sata_breakpoint_dma;
213 struct hisi_sas_slot *slot_info;
John Garry7eb78692015-11-18 00:50:31 +0800214 const struct hisi_sas_hw *hw; /* Low level hw interface */
215};
216
John Garryc799d6b2015-11-18 00:50:33 +0800217/* Generic HW DMA host memory structures */
218/* Delivery queue header */
219struct hisi_sas_cmd_hdr {
220 /* dw0 */
221 __le32 dw0;
222
223 /* dw1 */
224 __le32 dw1;
225
226 /* dw2 */
227 __le32 dw2;
228
229 /* dw3 */
230 __le32 transfer_tags;
231
232 /* dw4 */
233 __le32 data_transfer_len;
234
235 /* dw5 */
236 __le32 first_burst_num;
237
238 /* dw6 */
239 __le32 sg_len;
240
241 /* dw7 */
242 __le32 dw7;
243
244 /* dw8-9 */
245 __le64 cmd_table_addr;
246
247 /* dw10-11 */
248 __le64 sts_buffer_addr;
249
250 /* dw12-13 */
251 __le64 prd_table_addr;
252
253 /* dw14-15 */
254 __le64 dif_prd_table_addr;
255};
256
257struct hisi_sas_itct {
258 __le64 qw0;
259 __le64 sas_addr;
260 __le64 qw2;
261 __le64 qw3;
John Garry281e3bf2016-01-26 02:47:06 +0800262 __le64 qw4_15[12];
John Garryc799d6b2015-11-18 00:50:33 +0800263};
264
265struct hisi_sas_iost {
266 __le64 qw0;
267 __le64 qw1;
268 __le64 qw2;
269 __le64 qw3;
270};
271
272struct hisi_sas_err_record {
John Garry8d1eee72016-01-26 02:47:05 +0800273 u32 data[4];
John Garryc799d6b2015-11-18 00:50:33 +0800274};
275
276struct hisi_sas_initial_fis {
277 struct hisi_sas_err_record err_record;
278 struct dev_to_host_fis fis;
279 u32 rsvd[3];
280};
281
282struct hisi_sas_breakpoint {
283 u8 data[128]; /*io128 byte*/
284};
285
286struct hisi_sas_sge {
287 __le64 addr;
288 __le32 page_ctrl_0;
289 __le32 page_ctrl_1;
290 __le32 data_len;
291 __le32 data_off;
292};
293
294struct hisi_sas_command_table_smp {
295 u8 bytes[44];
296};
297
298struct hisi_sas_command_table_stp {
299 struct host_to_dev_fis command_fis;
300 u8 dummy[12];
301 u8 atapi_cdb[ATAPI_CDB_LEN];
302};
303
Ming Lin65e86172016-04-04 14:48:10 -0700304#define HISI_SAS_SGE_PAGE_CNT SG_CHUNK_SIZE
John Garryc799d6b2015-11-18 00:50:33 +0800305struct hisi_sas_sge_page {
306 struct hisi_sas_sge sge[HISI_SAS_SGE_PAGE_CNT];
307};
308
309struct hisi_sas_command_table_ssp {
310 struct ssp_frame_hdr hdr;
311 union {
312 struct {
313 struct ssp_command_iu task;
314 u32 prot[6];
315 };
316 struct ssp_tmf_iu ssp_task;
317 struct xfer_rdy_iu xfer_rdy;
318 struct ssp_response_iu ssp_res;
319 } u;
320};
321
322union hisi_sas_command_table {
323 struct hisi_sas_command_table_ssp ssp;
324 struct hisi_sas_command_table_smp smp;
325 struct hisi_sas_command_table_stp stp;
326};
John Garry9fb10b52015-11-18 00:50:44 +0800327extern int hisi_sas_probe(struct platform_device *pdev,
328 const struct hisi_sas_hw *ops);
329extern int hisi_sas_remove(struct platform_device *pdev);
John Garryc799d6b2015-11-18 00:50:33 +0800330
John Garry184a4632015-11-18 00:50:52 +0800331extern void hisi_sas_phy_down(struct hisi_hba *hisi_hba, int phy_no, int rdy);
John Garry27a3f222015-11-18 00:50:50 +0800332extern void hisi_sas_slot_task_free(struct hisi_hba *hisi_hba,
333 struct sas_task *task,
334 struct hisi_sas_slot *slot);
John Garrye8899fa2015-11-18 00:50:30 +0800335#endif