blob: c617ac8d831511e695d659a90fbdfc4c37e0141b [file] [log] [blame]
Thomas Gleixner2874c5f2019-05-27 08:55:01 +02001/* SPDX-License-Identifier: GPL-2.0-or-later */
John Garrye8899fa2015-11-18 00:50:30 +08002/*
3 * Copyright (c) 2015 Linaro Ltd.
4 * Copyright (c) 2015 Hisilicon Limited.
John Garrye8899fa2015-11-18 00:50:30 +08005 */
6
7#ifndef _HISI_SAS_H_
8#define _HISI_SAS_H_
9
John Garry4d558c72016-02-04 02:26:08 +080010#include <linux/acpi.h>
John Garry3bc45af2016-10-04 19:11:11 +080011#include <linux/clk.h>
Luo Jiaxingef634642018-12-19 23:56:39 +080012#include <linux/debugfs.h>
John Garrye8899fa2015-11-18 00:50:30 +080013#include <linux/dmapool.h>
Xiang Chena25d0d32017-08-11 00:09:40 +080014#include <linux/iopoll.h>
Xiang Chen2ba5afb2018-05-31 20:50:48 +080015#include <linux/lcm.h>
Xiang Chen57dbb2b2019-02-28 22:51:01 +080016#include <linux/libata.h>
John Garrye8899fa2015-11-18 00:50:30 +080017#include <linux/mfd/syscon.h>
18#include <linux/module.h>
19#include <linux/of_address.h>
John Garry11b75242017-06-14 23:33:17 +080020#include <linux/pci.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>
Luo Jiaxingd28ed832019-10-24 22:08:12 +080024#include <linux/timer.h>
John Garry6f2ff1a2016-01-26 02:47:20 +080025#include <scsi/sas_ata.h>
John Garrye8899fa2015-11-18 00:50:30 +080026#include <scsi/libsas.h>
27
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
Xiang Chen1273d652019-02-06 18:52:53 +080030#define HISI_SAS_QUEUE_SLOTS 4096
Xiang Chen3297ded2017-10-24 23:51:35 +080031#define HISI_SAS_MAX_ITCT_ENTRIES 1024
John Garry7eb78692015-11-18 00:50:31 +080032#define HISI_SAS_MAX_DEVICES HISI_SAS_MAX_ITCT_ENTRIES
Xiang Chen06ec0fb2017-03-23 01:25:18 +080033#define HISI_SAS_RESET_BIT 0
Xiaofei Tan917d3bd2017-08-11 00:09:26 +080034#define HISI_SAS_REJECT_CMD_BIT 1
John Garry93352ab2019-08-05 21:47:58 +080035#define HISI_SAS_MAX_COMMANDS (HISI_SAS_QUEUE_SLOTS)
36#define HISI_SAS_RESERVED_IPTT 96
37#define HISI_SAS_UNRESERVED_IPTT \
38 (HISI_SAS_MAX_COMMANDS - HISI_SAS_RESERVED_IPTT)
John Garry7eb78692015-11-18 00:50:31 +080039
Luo Jiaxingbbe0a7b2019-08-05 21:48:01 +080040#define HISI_SAS_IOST_ITCT_CACHE_NUM 64
41#define HISI_SAS_IOST_ITCT_CACHE_DW_SZ 10
42
Xiaofei Tanf557e322017-06-29 21:02:14 +080043#define HISI_SAS_STATUS_BUF_SZ (sizeof(struct hisi_sas_status_buffer))
44#define HISI_SAS_COMMAND_TABLE_SZ (sizeof(union hisi_sas_command_table))
45
46#define hisi_sas_status_buf_addr(buf) \
Xiang Chenb3cce122019-02-06 18:52:51 +080047 ((buf) + offsetof(struct hisi_sas_slot_buf_table, status_buffer))
48#define hisi_sas_status_buf_addr_mem(slot) hisi_sas_status_buf_addr((slot)->buf)
Xiaofei Tanf557e322017-06-29 21:02:14 +080049#define hisi_sas_status_buf_addr_dma(slot) \
Xiang Chenb3cce122019-02-06 18:52:51 +080050 hisi_sas_status_buf_addr((slot)->buf_dma)
Xiaofei Tanf557e322017-06-29 21:02:14 +080051
52#define hisi_sas_cmd_hdr_addr(buf) \
Xiang Chenb3cce122019-02-06 18:52:51 +080053 ((buf) + offsetof(struct hisi_sas_slot_buf_table, command_header))
54#define hisi_sas_cmd_hdr_addr_mem(slot) hisi_sas_cmd_hdr_addr((slot)->buf)
55#define hisi_sas_cmd_hdr_addr_dma(slot) hisi_sas_cmd_hdr_addr((slot)->buf_dma)
Xiaofei Tanf557e322017-06-29 21:02:14 +080056
57#define hisi_sas_sge_addr(buf) \
Xiang Chenb3cce122019-02-06 18:52:51 +080058 ((buf) + offsetof(struct hisi_sas_slot_buf_table, sge_page))
59#define hisi_sas_sge_addr_mem(slot) hisi_sas_sge_addr((slot)->buf)
60#define hisi_sas_sge_addr_dma(slot) hisi_sas_sge_addr((slot)->buf_dma)
61
62#define hisi_sas_sge_dif_addr(buf) \
63 ((buf) + offsetof(struct hisi_sas_slot_dif_buf_table, sge_dif_page))
64#define hisi_sas_sge_dif_addr_mem(slot) hisi_sas_sge_dif_addr((slot)->buf)
65#define hisi_sas_sge_dif_addr_dma(slot) hisi_sas_sge_dif_addr((slot)->buf_dma)
John Garry6be6de12015-11-18 00:50:34 +080066
John Garry42e7a692015-11-18 00:50:49 +080067#define HISI_SAS_MAX_SSP_RESP_SZ (sizeof(struct ssp_frame_hdr) + 1024)
John Garry66ee9992015-11-18 00:50:54 +080068#define HISI_SAS_MAX_SMP_RESP_SZ 1028
John Garry6f2ff1a2016-01-26 02:47:20 +080069#define HISI_SAS_MAX_STP_RESP_SZ 28
John Garry42e7a692015-11-18 00:50:49 +080070
Xiang Chen6c7bb8a2017-06-14 23:33:14 +080071#define HISI_SAS_SATA_PROTOCOL_NONDATA 0x1
72#define HISI_SAS_SATA_PROTOCOL_PIO 0x2
73#define HISI_SAS_SATA_PROTOCOL_DMA 0x4
74#define HISI_SAS_SATA_PROTOCOL_FPDMA 0x8
75#define HISI_SAS_SATA_PROTOCOL_ATAPI 0x10
76
Xiang Chend6a90002018-12-17 22:40:07 +080077#define HISI_SAS_DIF_PROT_MASK (SHOST_DIF_TYPE1_PROTECTION | \
78 SHOST_DIF_TYPE2_PROTECTION | \
79 SHOST_DIF_TYPE3_PROTECTION)
80
Xiang Chenb3cce122019-02-06 18:52:51 +080081#define HISI_SAS_DIX_PROT_MASK (SHOST_DIX_TYPE1_PROTECTION | \
82 SHOST_DIX_TYPE2_PROTECTION | \
83 SHOST_DIX_TYPE3_PROTECTION)
84
85#define HISI_SAS_PROT_MASK (HISI_SAS_DIF_PROT_MASK | HISI_SAS_DIX_PROT_MASK)
Xiang Chend6a90002018-12-17 22:40:07 +080086
Xiaofei Tanb6c9b152019-01-25 22:22:35 +080087#define HISI_SAS_WAIT_PHYUP_TIMEOUT 20
Xiang Chen8fa9a7b2019-10-24 22:08:10 +080088#define CLEAR_ITCT_TIMEOUT 20
Xiaofei Tanb6c9b152019-01-25 22:22:35 +080089
John Garryabda97c2015-11-18 00:50:51 +080090struct hisi_hba;
John Garryaf740db2015-11-18 00:50:41 +080091
John Garry07d78592015-11-18 00:50:47 +080092enum {
93 PORT_TYPE_SAS = (1U << 1),
94 PORT_TYPE_SATA = (1U << 0),
95};
96
Xiang Chen57dbb2b2019-02-28 22:51:01 +080097enum dev_status {
98 HISI_SAS_DEV_INIT,
99 HISI_SAS_DEV_NORMAL,
100};
101
John Garry441c2742016-08-24 19:05:47 +0800102enum {
103 HISI_SAS_INT_ABT_CMD = 0,
104 HISI_SAS_INT_ABT_DEV = 1,
105};
106
John Garryabda97c2015-11-18 00:50:51 +0800107enum hisi_sas_dev_type {
108 HISI_SAS_DEV_TYPE_STP = 0,
109 HISI_SAS_DEV_TYPE_SSP,
110 HISI_SAS_DEV_TYPE_SATA,
111};
112
John Garry2b383352017-08-11 00:09:30 +0800113struct hisi_sas_hw_error {
114 u32 irq_msk;
115 u32 msk;
116 int shift;
117 const char *msg;
118 int reg;
Shiju Jose729428c2017-10-24 23:51:39 +0800119 const struct hisi_sas_hw_error *sub;
John Garry2b383352017-08-11 00:09:30 +0800120};
121
Xiaofei Tane402acd2017-12-09 01:16:38 +0800122struct hisi_sas_rst {
123 struct hisi_hba *hisi_hba;
124 struct completion *completion;
125 struct work_struct work;
126 bool done;
127};
128
129#define HISI_SAS_RST_WORK_INIT(r, c) \
130 { .hisi_hba = hisi_hba, \
131 .completion = &c, \
132 .work = __WORK_INITIALIZER(r.work, \
133 hisi_sas_sync_rst_work_handler), \
134 .done = false, \
135 }
136
137#define HISI_SAS_DECLARE_RST_WORK_ON_STACK(r) \
138 DECLARE_COMPLETION_ONSTACK(c); \
Xiaofei Tane402acd2017-12-09 01:16:38 +0800139 struct hisi_sas_rst r = HISI_SAS_RST_WORK_INIT(r, c)
140
141enum hisi_sas_bit_err_type {
142 HISI_SAS_ERR_SINGLE_BIT_ECC = 0x0,
143 HISI_SAS_ERR_MULTI_BIT_ECC = 0x1,
144};
145
Xiaofei Tane537b622017-12-09 01:16:44 +0800146enum hisi_sas_phy_event {
147 HISI_PHYE_PHY_UP = 0U,
Xiaofei Tan057c3d12017-12-09 01:16:45 +0800148 HISI_PHYE_LINK_RESET,
Xiaofei Tane537b622017-12-09 01:16:44 +0800149 HISI_PHYES_NUM,
150};
151
John Garry7eb78692015-11-18 00:50:31 +0800152struct hisi_sas_phy {
Xiaofei Tane537b622017-12-09 01:16:44 +0800153 struct work_struct works[HISI_PHYES_NUM];
John Garry976867e2015-11-18 00:50:42 +0800154 struct hisi_hba *hisi_hba;
155 struct hisi_sas_port *port;
John Garry7eb78692015-11-18 00:50:31 +0800156 struct asd_sas_phy sas_phy;
John Garry976867e2015-11-18 00:50:42 +0800157 struct sas_identify identify;
Xiang Chen3e1fb1b2018-05-21 18:09:25 +0800158 struct completion *reset_completion;
Xiaofei Tanb6c9b152019-01-25 22:22:35 +0800159 struct timer_list timer;
Xiang Chen3e1fb1b2018-05-21 18:09:25 +0800160 spinlock_t lock;
John Garry976867e2015-11-18 00:50:42 +0800161 u64 port_id; /* from hw */
John Garry976867e2015-11-18 00:50:42 +0800162 u64 frame_rcvd_size;
163 u8 frame_rcvd[32];
164 u8 phy_attached;
Xiang Chen3e1fb1b2018-05-21 18:09:25 +0800165 u8 in_reset;
166 u8 reserved[2];
John Garryd0ef10c2017-06-26 18:27:28 +0800167 u32 phy_type;
Xiaofei Tanaaeb8232019-02-28 22:50:59 +0800168 u32 code_violation_err_count;
John Garry976867e2015-11-18 00:50:42 +0800169 enum sas_linkrate minimum_linkrate;
170 enum sas_linkrate maximum_linkrate;
John Garryc63b88c2019-04-11 20:46:38 +0800171 int enable;
Luo Jiaxingf873b662019-10-24 22:08:25 +0800172 atomic_t down_cnt;
John Garry7eb78692015-11-18 00:50:31 +0800173};
174
175struct hisi_sas_port {
176 struct asd_sas_port sas_port;
John Garry976867e2015-11-18 00:50:42 +0800177 u8 port_attached;
178 u8 id; /* from hw */
John Garry7eb78692015-11-18 00:50:31 +0800179};
180
John Garry9101a072015-11-18 00:50:37 +0800181struct hisi_sas_cq {
182 struct hisi_hba *hisi_hba;
John Garry11e67322020-01-20 20:22:36 +0800183 const struct cpumask *irq_mask;
John Garrye6c346f2016-09-06 23:36:11 +0800184 int rd_point;
John Garry9101a072015-11-18 00:50:37 +0800185 int id;
Xiang Chen81f338e2020-01-20 20:22:31 +0800186 int irq_no;
John Garry9101a072015-11-18 00:50:37 +0800187};
188
John Garry4fde02a2016-09-06 23:36:12 +0800189struct hisi_sas_dq {
190 struct hisi_hba *hisi_hba;
Xiang Chenfa222db2018-05-09 23:10:48 +0800191 struct list_head list;
Xiang Chenb1a49412017-06-14 23:33:13 +0800192 spinlock_t lock;
John Garry4fde02a2016-09-06 23:36:12 +0800193 int wr_point;
194 int id;
195};
196
John Garryaf740db2015-11-18 00:50:41 +0800197struct hisi_sas_device {
John Garryabda97c2015-11-18 00:50:51 +0800198 struct hisi_hba *hisi_hba;
199 struct domain_device *sas_device;
Xiang Chen640acc92017-08-11 00:09:33 +0800200 struct completion *completion;
Xiang Chenb1a49412017-06-14 23:33:13 +0800201 struct hisi_sas_dq *dq;
John Garry405314d2017-03-23 01:25:21 +0800202 struct list_head list;
John Garryad604832017-06-14 23:33:12 +0800203 enum sas_device_type dev_type;
Xiang Chen57dbb2b2019-02-28 22:51:01 +0800204 enum dev_status dev_status;
John Garryad604832017-06-14 23:33:12 +0800205 int device_id;
Xiaofei Tan32ccba52017-04-10 21:21:57 +0800206 int sata_idx;
Xiang Chen4fefe5b2019-02-06 18:52:55 +0800207 spinlock_t lock; /* For protecting slots */
John Garryaf740db2015-11-18 00:50:41 +0800208};
209
Xiaofei Tan78bd2b42018-05-21 18:09:21 +0800210struct hisi_sas_tmf_task {
Xiaofei Tanb09fcd02018-05-21 18:09:22 +0800211 int force_phy;
212 int phy_id;
Xiaofei Tan78bd2b42018-05-21 18:09:21 +0800213 u8 tmf;
214 u16 tag_of_task_to_be_managed;
215};
216
John Garry6be6de12015-11-18 00:50:34 +0800217struct hisi_sas_slot {
John Garry42e7a692015-11-18 00:50:49 +0800218 struct list_head entry;
Xiang Chenfa222db2018-05-09 23:10:48 +0800219 struct list_head delivery;
John Garry42e7a692015-11-18 00:50:49 +0800220 struct sas_task *task;
221 struct hisi_sas_port *port;
222 u64 n_elem;
Xiang Chenb3cce122019-02-06 18:52:51 +0800223 u64 n_elem_dif;
John Garry42e7a692015-11-18 00:50:49 +0800224 int dlvry_queue;
225 int dlvry_queue_slot;
John Garry27a3f222015-11-18 00:50:50 +0800226 int cmplt_queue;
227 int cmplt_queue_slot;
John Garrycac9b2a2016-02-25 17:42:11 +0800228 int abort;
Xiang Chenfa222db2018-05-09 23:10:48 +0800229 int ready;
Xiang Chen4fefe5b2019-02-06 18:52:55 +0800230 int device_id;
John Garry42e7a692015-11-18 00:50:49 +0800231 void *cmd_hdr;
232 dma_addr_t cmd_hdr_dma;
John Garry0844a3f2017-04-10 21:21:59 +0800233 struct timer_list internal_abort_timer;
Xiang Chencd938e52018-05-02 23:56:26 +0800234 bool is_internal;
Xiaofei Tan78bd2b42018-05-21 18:09:21 +0800235 struct hisi_sas_tmf_task *tmf;
Xiang Chen2ba5afb2018-05-31 20:50:48 +0800236 /* Do not reorder/change members after here */
237 void *buf;
238 dma_addr_t buf_dma;
John Garry735bcc72018-12-06 21:34:40 +0800239 u16 idx;
John Garry6be6de12015-11-18 00:50:34 +0800240};
241
Luo Jiaxingcaefac12018-12-19 23:56:42 +0800242#define HISI_SAS_DEBUGFS_REG(x) {#x, x}
243
244struct hisi_sas_debugfs_reg_lu {
245 char *name;
246 int off;
247};
248
Luo Jiaxingeb1c2b72018-12-19 23:56:40 +0800249struct hisi_sas_debugfs_reg {
Luo Jiaxingcaefac12018-12-19 23:56:42 +0800250 const struct hisi_sas_debugfs_reg_lu *lu;
Luo Jiaxingeb1c2b72018-12-19 23:56:40 +0800251 int count;
Luo Jiaxing49159a52018-12-19 23:56:41 +0800252 int base_off;
253 union {
254 u32 (*read_global_reg)(struct hisi_hba *hisi_hba, u32 off);
255 u32 (*read_port_reg)(struct hisi_hba *hisi_hba, int port,
256 u32 off);
257 };
Luo Jiaxingeb1c2b72018-12-19 23:56:40 +0800258};
259
Luo Jiaxingbbe0a7b2019-08-05 21:48:01 +0800260struct hisi_sas_iost_itct_cache {
261 u32 data[HISI_SAS_IOST_ITCT_CACHE_DW_SZ];
262};
263
Luo Jiaxingb0b3e4292019-08-05 21:48:02 +0800264enum hisi_sas_debugfs_reg_array_member {
265 DEBUGFS_GLOBAL = 0,
266 DEBUGFS_AXI,
267 DEBUGFS_RAS,
268 DEBUGFS_REGS_NUM
269};
270
Luo Jiaxingbbe0a7b2019-08-05 21:48:01 +0800271enum hisi_sas_debugfs_cache_type {
272 HISI_SAS_ITCT_CACHE,
273 HISI_SAS_IOST_CACHE,
274};
275
Luo Jiaxing2c4d5822020-09-01 19:13:07 +0800276enum hisi_sas_debugfs_bist_ffe_cfg {
277 FFE_SAS_1_5_GBPS,
278 FFE_SAS_3_0_GBPS,
279 FFE_SAS_6_0_GBPS,
280 FFE_SAS_12_0_GBPS,
281 FFE_RESV,
282 FFE_SATA_1_5_GBPS,
283 FFE_SATA_3_0_GBPS,
284 FFE_SATA_6_0_GBPS,
285 FFE_CFG_MAX
286};
287
Luo Jiaxing981cc232020-09-01 19:13:08 +0800288enum hisi_sas_debugfs_bist_fixed_code {
289 FIXED_CODE,
290 FIXED_CODE_1,
291 FIXED_CODE_MAX
292};
293
294enum {
295 HISI_SAS_BIST_CODE_MODE_PRBS7,
296 HISI_SAS_BIST_CODE_MODE_PRBS23,
297 HISI_SAS_BIST_CODE_MODE_PRBS31,
298 HISI_SAS_BIST_CODE_MODE_JTPAT,
299 HISI_SAS_BIST_CODE_MODE_CJTPAT,
300 HISI_SAS_BIST_CODE_MODE_SCRAMBED_0,
301 HISI_SAS_BIST_CODE_MODE_TRAIN,
302 HISI_SAS_BIST_CODE_MODE_TRAIN_DONE,
303 HISI_SAS_BIST_CODE_MODE_HFTP,
304 HISI_SAS_BIST_CODE_MODE_MFTP,
305 HISI_SAS_BIST_CODE_MODE_LFTP,
306 HISI_SAS_BIST_CODE_MODE_FIXED_DATA,
307};
308
John Garry7eb78692015-11-18 00:50:31 +0800309struct hisi_sas_hw {
John Garry8ff1d572015-11-18 00:50:46 +0800310 int (*hw_init)(struct hisi_hba *hisi_hba);
John Garryabda97c2015-11-18 00:50:51 +0800311 void (*setup_itct)(struct hisi_hba *hisi_hba,
312 struct hisi_sas_device *device);
Xiang Chen784b46b2018-09-24 23:06:33 +0800313 int (*slot_index_alloc)(struct hisi_hba *hisi_hba,
John Garry685b6d62016-04-15 21:36:36 +0800314 struct domain_device *device);
315 struct hisi_sas_device *(*alloc_dev)(struct domain_device *device);
Xiang Chen569eddc2019-01-25 22:22:30 +0800316 void (*sl_notify_ssp)(struct hisi_hba *hisi_hba, int phy_no);
Xiang Chenb1a49412017-06-14 23:33:13 +0800317 void (*start_delivery)(struct hisi_sas_dq *dq);
Xiang Chena2b38202018-05-09 23:10:46 +0800318 void (*prep_ssp)(struct hisi_hba *hisi_hba,
Xiaofei Tan78bd2b42018-05-21 18:09:21 +0800319 struct hisi_sas_slot *slot);
Xiang Chena2b38202018-05-09 23:10:46 +0800320 void (*prep_smp)(struct hisi_hba *hisi_hba,
John Garry66ee9992015-11-18 00:50:54 +0800321 struct hisi_sas_slot *slot);
Xiang Chena2b38202018-05-09 23:10:46 +0800322 void (*prep_stp)(struct hisi_hba *hisi_hba,
John Garry6f2ff1a2016-01-26 02:47:20 +0800323 struct hisi_sas_slot *slot);
Xiang Chena2b38202018-05-09 23:10:46 +0800324 void (*prep_abort)(struct hisi_hba *hisi_hba,
John Garry441c2742016-08-24 19:05:47 +0800325 struct hisi_sas_slot *slot,
326 int device_id, int abort_flag, int tag_to_abort);
John Garry396b8042017-03-23 01:25:19 +0800327 void (*phys_init)(struct hisi_hba *hisi_hba);
Xiang Chen1eb8eea2017-10-24 23:51:36 +0800328 void (*phy_start)(struct hisi_hba *hisi_hba, int phy_no);
John Garrye4189d52015-11-18 00:50:57 +0800329 void (*phy_disable)(struct hisi_hba *hisi_hba, int phy_no);
330 void (*phy_hard_reset)(struct hisi_hba *hisi_hba, int phy_no);
Xiaofei Tanc52108c2017-08-11 00:09:29 +0800331 void (*get_events)(struct hisi_hba *hisi_hba, int phy_no);
Xiang Chen2ae75782016-11-07 20:48:40 +0800332 void (*phy_set_linkrate)(struct hisi_hba *hisi_hba, int phy_no,
333 struct sas_phy_linkrates *linkrates);
334 enum sas_linkrate (*phy_get_max_linkrate)(void);
Xiang Chen8fa9a7b2019-10-24 22:08:10 +0800335 int (*clear_itct)(struct hisi_hba *hisi_hba,
336 struct hisi_sas_device *dev);
Xiaofei Tan02581412017-12-09 01:16:34 +0800337 void (*free_device)(struct hisi_sas_device *sas_dev);
John Garry184a4632015-11-18 00:50:52 +0800338 int (*get_wideport_bitmap)(struct hisi_hba *hisi_hba, int port_id);
Xiang Chend30ff262017-06-14 23:33:32 +0800339 void (*dereg_device)(struct hisi_hba *hisi_hba,
340 struct domain_device *device);
Xiang Chen06ec0fb2017-03-23 01:25:18 +0800341 int (*soft_reset)(struct hisi_hba *hisi_hba);
Xiaofei Tan917d3bd2017-08-11 00:09:26 +0800342 u32 (*get_phys_state)(struct hisi_hba *hisi_hba);
Xiaofei Tan6379c562018-01-18 00:46:53 +0800343 int (*write_gpio)(struct hisi_hba *hisi_hba, u8 reg_type,
344 u8 reg_index, u8 reg_count, u8 *write_data);
Luo Jiaxing4bc05802019-09-06 20:55:34 +0800345 void (*wait_cmds_complete_timeout)(struct hisi_hba *hisi_hba,
346 int delay_ms, int timeout_ms);
Luo Jiaxing49159a52018-12-19 23:56:41 +0800347 void (*snapshot_prepare)(struct hisi_hba *hisi_hba);
348 void (*snapshot_restore)(struct hisi_hba *hisi_hba);
Xiang Chen97b151e2019-09-06 20:55:36 +0800349 int (*set_bist)(struct hisi_hba *hisi_hba, bool enable);
Luo Jiaxingbbe0a7b2019-08-05 21:48:01 +0800350 void (*read_iost_itct_cache)(struct hisi_hba *hisi_hba,
351 enum hisi_sas_debugfs_cache_type type,
352 u32 *cache);
John Garry6be6de12015-11-18 00:50:34 +0800353 int complete_hdr_size;
Xiang Chen235bfc72018-05-21 18:09:18 +0800354 struct scsi_host_template *sht;
Luo Jiaxingeb1c2b72018-12-19 23:56:40 +0800355
Luo Jiaxingb0b3e4292019-08-05 21:48:02 +0800356 const struct hisi_sas_debugfs_reg *debugfs_reg_array[DEBUGFS_REGS_NUM];
Luo Jiaxingeb1c2b72018-12-19 23:56:40 +0800357 const struct hisi_sas_debugfs_reg *debugfs_reg_port;
John Garry7eb78692015-11-18 00:50:31 +0800358};
359
Luo Jiaxinga70e33e2019-10-24 22:08:21 +0800360#define HISI_SAS_MAX_DEBUGFS_DUMP (50)
361
Luo Jiaxing35ea6302019-10-24 22:08:13 +0800362struct hisi_sas_debugfs_cq {
363 struct hisi_sas_cq *cq;
364 void *complete_hdr;
365};
366
Luo Jiaxing1b54c4d2019-10-24 22:08:14 +0800367struct hisi_sas_debugfs_dq {
368 struct hisi_sas_dq *dq;
369 struct hisi_sas_cmd_hdr *hdr;
370};
371
Luo Jiaxingc6116392019-10-24 22:08:15 +0800372struct hisi_sas_debugfs_regs {
373 struct hisi_hba *hisi_hba;
374 u32 *data;
375};
376
Luo Jiaxing1f66e1f2019-10-24 22:08:16 +0800377struct hisi_sas_debugfs_port {
378 struct hisi_sas_phy *phy;
379 u32 *data;
380};
381
Luo Jiaxinge15f2e22019-10-24 22:08:17 +0800382struct hisi_sas_debugfs_iost {
383 struct hisi_sas_iost *iost;
384};
385
Luo Jiaxing0161d552019-10-24 22:08:18 +0800386struct hisi_sas_debugfs_itct {
387 struct hisi_sas_itct *itct;
388};
389
Luo Jiaxingb714dd82019-10-24 22:08:19 +0800390struct hisi_sas_debugfs_iost_cache {
391 struct hisi_sas_iost_itct_cache *cache;
392};
393
Luo Jiaxing357e4fc2019-10-24 22:08:20 +0800394struct hisi_sas_debugfs_itct_cache {
395 struct hisi_sas_iost_itct_cache *cache;
396};
397
John Garry7eb78692015-11-18 00:50:31 +0800398struct hisi_hba {
399 /* This must be the first element, used by SHOST_TO_SAS_HA */
400 struct sas_ha_struct *p;
401
John Garry11b75242017-06-14 23:33:17 +0800402 struct platform_device *platform_dev;
403 struct pci_dev *pci_dev;
404 struct device *dev;
405
Xiang Chend6a90002018-12-17 22:40:07 +0800406 int prot_mask;
407
John Garrye26b2f42015-11-18 00:50:32 +0800408 void __iomem *regs;
Xiaofei Tan6379c562018-01-18 00:46:53 +0800409 void __iomem *sgpio_regs;
John Garrye26b2f42015-11-18 00:50:32 +0800410 struct regmap *ctrl;
411 u32 ctrl_reset_reg;
412 u32 ctrl_reset_sts_reg;
413 u32 ctrl_clock_ena_reg;
John Garry3bc45af2016-10-04 19:11:11 +0800414 u32 refclk_frequency_mhz;
John Garry7eb78692015-11-18 00:50:31 +0800415 u8 sas_addr[SAS_ADDR_SIZE];
416
417 int n_phy;
John Garryfa42d802015-11-18 00:50:43 +0800418 spinlock_t lock;
Xiaofei Tand2fc4012018-05-31 20:50:44 +0800419 struct semaphore sem;
John Garry7eb78692015-11-18 00:50:31 +0800420
John Garryfa42d802015-11-18 00:50:43 +0800421 struct timer_list timer;
John Garry7e9080e2015-11-18 00:50:40 +0800422 struct workqueue_struct *wq;
John Garry257efd12015-11-18 00:50:36 +0800423
424 int slot_index_count;
Xiang Chenfa3be0f2018-05-21 18:09:14 +0800425 int last_slot_index;
Xiang Chen1b865182018-05-21 18:09:15 +0800426 int last_dev_id;
John Garry257efd12015-11-18 00:50:36 +0800427 unsigned long *slot_index_tags;
Xiaofei Tanc7b9d362017-04-10 21:21:56 +0800428 unsigned long reject_stp_links_msk;
John Garry257efd12015-11-18 00:50:36 +0800429
John Garry7eb78692015-11-18 00:50:31 +0800430 /* SCSI/SAS glue */
431 struct sas_ha_struct sha;
432 struct Scsi_Host *shost;
John Garry9101a072015-11-18 00:50:37 +0800433
434 struct hisi_sas_cq cq[HISI_SAS_MAX_QUEUES];
John Garry4fde02a2016-09-06 23:36:12 +0800435 struct hisi_sas_dq dq[HISI_SAS_MAX_QUEUES];
John Garry7eb78692015-11-18 00:50:31 +0800436 struct hisi_sas_phy phy[HISI_SAS_MAX_PHYS];
437 struct hisi_sas_port port[HISI_SAS_MAX_PHYS];
John Garrye26b2f42015-11-18 00:50:32 +0800438
439 int queue_count;
John Garry6be6de12015-11-18 00:50:34 +0800440
John Garryaf740db2015-11-18 00:50:41 +0800441 struct hisi_sas_device devices[HISI_SAS_MAX_DEVICES];
John Garry6be6de12015-11-18 00:50:34 +0800442 struct hisi_sas_cmd_hdr *cmd_hdr[HISI_SAS_MAX_QUEUES];
443 dma_addr_t cmd_hdr_dma[HISI_SAS_MAX_QUEUES];
444 void *complete_hdr[HISI_SAS_MAX_QUEUES];
445 dma_addr_t complete_hdr_dma[HISI_SAS_MAX_QUEUES];
446 struct hisi_sas_initial_fis *initial_fis;
447 dma_addr_t initial_fis_dma;
448 struct hisi_sas_itct *itct;
449 dma_addr_t itct_dma;
450 struct hisi_sas_iost *iost;
451 dma_addr_t iost_dma;
452 struct hisi_sas_breakpoint *breakpoint;
453 dma_addr_t breakpoint_dma;
454 struct hisi_sas_breakpoint *sata_breakpoint;
455 dma_addr_t sata_breakpoint_dma;
456 struct hisi_sas_slot *slot_info;
Xiang Chen06ec0fb2017-03-23 01:25:18 +0800457 unsigned long flags;
John Garry7eb78692015-11-18 00:50:31 +0800458 const struct hisi_sas_hw *hw; /* Low level hw interface */
Xiaofei Tan32ccba52017-04-10 21:21:57 +0800459 unsigned long sata_dev_bitmap[BITS_TO_LONGS(HISI_SAS_MAX_DEVICES)];
Xiang Chen06ec0fb2017-03-23 01:25:18 +0800460 struct work_struct rst_work;
Luo Jiaxing49159a52018-12-19 23:56:41 +0800461 struct work_struct debugfs_work;
Xiaofei Tan45222042018-07-18 22:14:28 +0800462 u32 phy_state;
Xiang Chen37359792018-11-09 22:06:34 +0800463 u32 intr_coal_ticks; /* Time of interrupt coalesce in us */
464 u32 intr_coal_count; /* Interrupt count to coalesce */
Luo Jiaxingef634642018-12-19 23:56:39 +0800465
John Garry795f25a2019-02-06 18:52:54 +0800466 int cq_nvecs;
Xiang Chen4fefe5b2019-02-06 18:52:55 +0800467 unsigned int *reply_map;
John Garry795f25a2019-02-06 18:52:54 +0800468
Xiang Chen97b151e2019-09-06 20:55:36 +0800469 /* bist */
470 enum sas_linkrate debugfs_bist_linkrate;
471 int debugfs_bist_code_mode;
472 int debugfs_bist_phy_no;
473 int debugfs_bist_mode;
474 u32 debugfs_bist_cnt;
475 int debugfs_bist_enable;
Luo Jiaxing2c4d5822020-09-01 19:13:07 +0800476 u32 debugfs_bist_ffe[HISI_SAS_MAX_PHYS][FFE_CFG_MAX];
Luo Jiaxing981cc232020-09-01 19:13:08 +0800477 u32 debugfs_bist_fixed_code[FIXED_CODE_MAX];
Xiang Chen97b151e2019-09-06 20:55:36 +0800478
Luo Jiaxingeb1c2b72018-12-19 23:56:40 +0800479 /* debugfs memories */
Luo Jiaxingb0b3e4292019-08-05 21:48:02 +0800480 /* Put Global AXI and RAS Register into register array */
Luo Jiaxinga70e33e2019-10-24 22:08:21 +0800481 struct hisi_sas_debugfs_regs debugfs_regs[HISI_SAS_MAX_DEBUGFS_DUMP][DEBUGFS_REGS_NUM];
482 struct hisi_sas_debugfs_port debugfs_port_reg[HISI_SAS_MAX_DEBUGFS_DUMP][HISI_SAS_MAX_PHYS];
483 struct hisi_sas_debugfs_cq debugfs_cq[HISI_SAS_MAX_DEBUGFS_DUMP][HISI_SAS_MAX_QUEUES];
484 struct hisi_sas_debugfs_dq debugfs_dq[HISI_SAS_MAX_DEBUGFS_DUMP][HISI_SAS_MAX_QUEUES];
485 struct hisi_sas_debugfs_iost debugfs_iost[HISI_SAS_MAX_DEBUGFS_DUMP];
486 struct hisi_sas_debugfs_itct debugfs_itct[HISI_SAS_MAX_DEBUGFS_DUMP];
487 struct hisi_sas_debugfs_iost_cache debugfs_iost_cache[HISI_SAS_MAX_DEBUGFS_DUMP];
488 struct hisi_sas_debugfs_itct_cache debugfs_itct_cache[HISI_SAS_MAX_DEBUGFS_DUMP];
489
Luo Jiaxing8f643292019-10-24 22:08:23 +0800490 u64 debugfs_timestamp[HISI_SAS_MAX_DEBUGFS_DUMP];
491 int debugfs_dump_index;
Luo Jiaxingef634642018-12-19 23:56:39 +0800492 struct dentry *debugfs_dir;
Luo Jiaxing49159a52018-12-19 23:56:41 +0800493 struct dentry *debugfs_dump_dentry;
Xiang Chen97b151e2019-09-06 20:55:36 +0800494 struct dentry *debugfs_bist_dentry;
John Garry7eb78692015-11-18 00:50:31 +0800495};
496
John Garryc799d6b2015-11-18 00:50:33 +0800497/* Generic HW DMA host memory structures */
498/* Delivery queue header */
499struct hisi_sas_cmd_hdr {
500 /* dw0 */
501 __le32 dw0;
502
503 /* dw1 */
504 __le32 dw1;
505
506 /* dw2 */
507 __le32 dw2;
508
509 /* dw3 */
510 __le32 transfer_tags;
511
512 /* dw4 */
513 __le32 data_transfer_len;
514
515 /* dw5 */
516 __le32 first_burst_num;
517
518 /* dw6 */
519 __le32 sg_len;
520
521 /* dw7 */
522 __le32 dw7;
523
524 /* dw8-9 */
525 __le64 cmd_table_addr;
526
527 /* dw10-11 */
528 __le64 sts_buffer_addr;
529
530 /* dw12-13 */
531 __le64 prd_table_addr;
532
533 /* dw14-15 */
534 __le64 dif_prd_table_addr;
535};
536
537struct hisi_sas_itct {
538 __le64 qw0;
539 __le64 sas_addr;
540 __le64 qw2;
541 __le64 qw3;
John Garry281e3bf2016-01-26 02:47:06 +0800542 __le64 qw4_15[12];
John Garryc799d6b2015-11-18 00:50:33 +0800543};
544
545struct hisi_sas_iost {
546 __le64 qw0;
547 __le64 qw1;
548 __le64 qw2;
549 __le64 qw3;
550};
551
552struct hisi_sas_err_record {
John Garry8d1eee72016-01-26 02:47:05 +0800553 u32 data[4];
John Garryc799d6b2015-11-18 00:50:33 +0800554};
555
556struct hisi_sas_initial_fis {
557 struct hisi_sas_err_record err_record;
558 struct dev_to_host_fis fis;
559 u32 rsvd[3];
560};
561
562struct hisi_sas_breakpoint {
Xiang Chen3297ded2017-10-24 23:51:35 +0800563 u8 data[128];
564};
565
566struct hisi_sas_sata_breakpoint {
567 struct hisi_sas_breakpoint tag[32];
John Garryc799d6b2015-11-18 00:50:33 +0800568};
569
570struct hisi_sas_sge {
571 __le64 addr;
572 __le32 page_ctrl_0;
573 __le32 page_ctrl_1;
574 __le32 data_len;
575 __le32 data_off;
576};
577
578struct hisi_sas_command_table_smp {
579 u8 bytes[44];
580};
581
582struct hisi_sas_command_table_stp {
583 struct host_to_dev_fis command_fis;
584 u8 dummy[12];
585 u8 atapi_cdb[ATAPI_CDB_LEN];
586};
587
John Garryc7669f52019-05-29 17:58:44 +0800588#define HISI_SAS_SGE_PAGE_CNT (124)
John Garryc799d6b2015-11-18 00:50:33 +0800589struct hisi_sas_sge_page {
590 struct hisi_sas_sge sge[HISI_SAS_SGE_PAGE_CNT];
Xiaofei Tanf557e322017-06-29 21:02:14 +0800591} __aligned(16);
John Garryc799d6b2015-11-18 00:50:33 +0800592
John Garryc7669f52019-05-29 17:58:44 +0800593#define HISI_SAS_SGE_DIF_PAGE_CNT HISI_SAS_SGE_PAGE_CNT
Xiang Chenb3cce122019-02-06 18:52:51 +0800594struct hisi_sas_sge_dif_page {
595 struct hisi_sas_sge sge[HISI_SAS_SGE_DIF_PAGE_CNT];
596} __aligned(16);
597
John Garryc799d6b2015-11-18 00:50:33 +0800598struct hisi_sas_command_table_ssp {
599 struct ssp_frame_hdr hdr;
600 union {
601 struct {
602 struct ssp_command_iu task;
Xiang Chena14da7a2018-05-02 23:56:27 +0800603 u32 prot[7];
John Garryc799d6b2015-11-18 00:50:33 +0800604 };
605 struct ssp_tmf_iu ssp_task;
606 struct xfer_rdy_iu xfer_rdy;
607 struct ssp_response_iu ssp_res;
608 } u;
609};
610
611union hisi_sas_command_table {
612 struct hisi_sas_command_table_ssp ssp;
613 struct hisi_sas_command_table_smp smp;
614 struct hisi_sas_command_table_stp stp;
Xiaofei Tanf557e322017-06-29 21:02:14 +0800615} __aligned(16);
616
617struct hisi_sas_status_buffer {
618 struct hisi_sas_err_record err;
619 u8 iu[1024];
620} __aligned(16);
621
622struct hisi_sas_slot_buf_table {
623 struct hisi_sas_status_buffer status_buffer;
624 union hisi_sas_command_table command_header;
625 struct hisi_sas_sge_page sge_page;
John Garryc799d6b2015-11-18 00:50:33 +0800626};
John Garry2e244f02017-03-23 01:25:17 +0800627
Xiang Chenb3cce122019-02-06 18:52:51 +0800628struct hisi_sas_slot_dif_buf_table {
629 struct hisi_sas_slot_buf_table slot_buf;
630 struct hisi_sas_sge_dif_page sge_dif_page;
631};
632
John Garrye21fe3a2017-06-14 23:33:20 +0800633extern struct scsi_transport_template *hisi_sas_stt;
Luo Jiaxingef634642018-12-19 23:56:39 +0800634
635extern bool hisi_sas_debugfs_enable;
Luo Jiaxing905ab012019-10-24 22:08:22 +0800636extern u32 hisi_sas_debugfs_dump_count;
Luo Jiaxingef634642018-12-19 23:56:39 +0800637extern struct dentry *hisi_sas_debugfs_dir;
638
Xiang Chena25d0d32017-08-11 00:09:40 +0800639extern void hisi_sas_stop_phys(struct hisi_hba *hisi_hba);
Xiang Chenae68b562019-01-25 22:22:33 +0800640extern int hisi_sas_alloc(struct hisi_hba *hisi_hba);
John Garrye21fe3a2017-06-14 23:33:20 +0800641extern void hisi_sas_free(struct hisi_hba *hisi_hba);
chenxiang468f4b82017-12-28 18:20:47 +0800642extern u8 hisi_sas_get_ata_protocol(struct host_to_dev_fis *fis,
643 int direction);
John Garry2e244f02017-03-23 01:25:17 +0800644extern struct hisi_sas_port *to_hisi_sas_port(struct asd_sas_port *sas_port);
Xiang Chen75904072017-06-14 23:33:15 +0800645extern void hisi_sas_sata_done(struct sas_task *task,
646 struct hisi_sas_slot *slot);
John Garry0fa24c12017-06-14 23:33:18 +0800647extern int hisi_sas_get_fw_info(struct hisi_hba *hisi_hba);
John Garry9fb10b52015-11-18 00:50:44 +0800648extern int hisi_sas_probe(struct platform_device *pdev,
649 const struct hisi_sas_hw *ops);
650extern int hisi_sas_remove(struct platform_device *pdev);
John Garryc799d6b2015-11-18 00:50:33 +0800651
Xiang Chen235bfc72018-05-21 18:09:18 +0800652extern int hisi_sas_slave_configure(struct scsi_device *sdev);
653extern int hisi_sas_scan_finished(struct Scsi_Host *shost, unsigned long time);
654extern void hisi_sas_scan_start(struct Scsi_Host *shost);
Xiang Chen235bfc72018-05-21 18:09:18 +0800655extern int hisi_sas_host_reset(struct Scsi_Host *shost, int reset_type);
John Garryc63b88c2019-04-11 20:46:38 +0800656extern void hisi_sas_phy_enable(struct hisi_hba *hisi_hba, int phy_no,
657 int enable);
John Garry184a4632015-11-18 00:50:52 +0800658extern void hisi_sas_phy_down(struct hisi_hba *hisi_hba, int phy_no, int rdy);
John Garry27a3f222015-11-18 00:50:50 +0800659extern void hisi_sas_slot_task_free(struct hisi_hba *hisi_hba,
660 struct sas_task *task,
661 struct hisi_sas_slot *slot);
Xiang Chen06ec0fb2017-03-23 01:25:18 +0800662extern void hisi_sas_init_mem(struct hisi_hba *hisi_hba);
Xiaofei Tanb4241f02017-10-24 23:51:45 +0800663extern void hisi_sas_rst_work_handler(struct work_struct *work);
Xiaofei Tane402acd2017-12-09 01:16:38 +0800664extern void hisi_sas_sync_rst_work_handler(struct work_struct *work);
Xiang Chen81f338e2020-01-20 20:22:31 +0800665extern void hisi_sas_sync_irqs(struct hisi_hba *hisi_hba);
Xiaofei Tanb6c9b152019-01-25 22:22:35 +0800666extern void hisi_sas_phy_oob_ready(struct hisi_hba *hisi_hba, int phy_no);
Xiaofei Tane537b622017-12-09 01:16:44 +0800667extern bool hisi_sas_notify_phy_event(struct hisi_sas_phy *phy,
668 enum hisi_sas_phy_event event);
Xiang Chen4d0951e2017-12-09 01:16:50 +0800669extern void hisi_sas_release_tasks(struct hisi_hba *hisi_hba);
Xiang Chenc2c1d9d2018-05-02 23:56:30 +0800670extern u8 hisi_sas_get_prog_phy_linkrate_mask(enum sas_linkrate max);
Xiaofei Tan45222042018-07-18 22:14:28 +0800671extern void hisi_sas_controller_reset_prepare(struct hisi_hba *hisi_hba);
672extern void hisi_sas_controller_reset_done(struct hisi_hba *hisi_hba);
Luo Jiaxingef634642018-12-19 23:56:39 +0800673extern void hisi_sas_debugfs_init(struct hisi_hba *hisi_hba);
674extern void hisi_sas_debugfs_exit(struct hisi_hba *hisi_hba);
Luo Jiaxing49159a52018-12-19 23:56:41 +0800675extern void hisi_sas_debugfs_work_handler(struct work_struct *work);
John Garrye8899fa2015-11-18 00:50:30 +0800676#endif