blob: 8d9a8fb2dd32e043627aad442465ca14dc95fa1b [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>
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 Garry7eb78692015-11-18 00:50:31 +080027#define HISI_SAS_MAX_PHYS 9
John Garry6be6de12015-11-18 00:50:34 +080028#define HISI_SAS_MAX_QUEUES 32
Xiang Chen1273d652019-02-06 18:52:53 +080029#define HISI_SAS_QUEUE_SLOTS 4096
Xiang Chen3297ded2017-10-24 23:51:35 +080030#define HISI_SAS_MAX_ITCT_ENTRIES 1024
John Garry7eb78692015-11-18 00:50:31 +080031#define HISI_SAS_MAX_DEVICES HISI_SAS_MAX_ITCT_ENTRIES
Xiang Chen06ec0fb2017-03-23 01:25:18 +080032#define HISI_SAS_RESET_BIT 0
Xiaofei Tan917d3bd2017-08-11 00:09:26 +080033#define HISI_SAS_REJECT_CMD_BIT 1
Xiang Chen784b46b2018-09-24 23:06:33 +080034#define HISI_SAS_RESERVED_IPTT_CNT 96
John Garry7eb78692015-11-18 00:50:31 +080035
Xiaofei Tanf557e322017-06-29 21:02:14 +080036#define HISI_SAS_STATUS_BUF_SZ (sizeof(struct hisi_sas_status_buffer))
37#define HISI_SAS_COMMAND_TABLE_SZ (sizeof(union hisi_sas_command_table))
38
39#define hisi_sas_status_buf_addr(buf) \
Xiang Chenb3cce122019-02-06 18:52:51 +080040 ((buf) + offsetof(struct hisi_sas_slot_buf_table, status_buffer))
41#define hisi_sas_status_buf_addr_mem(slot) hisi_sas_status_buf_addr((slot)->buf)
Xiaofei Tanf557e322017-06-29 21:02:14 +080042#define hisi_sas_status_buf_addr_dma(slot) \
Xiang Chenb3cce122019-02-06 18:52:51 +080043 hisi_sas_status_buf_addr((slot)->buf_dma)
Xiaofei Tanf557e322017-06-29 21:02:14 +080044
45#define hisi_sas_cmd_hdr_addr(buf) \
Xiang Chenb3cce122019-02-06 18:52:51 +080046 ((buf) + offsetof(struct hisi_sas_slot_buf_table, command_header))
47#define hisi_sas_cmd_hdr_addr_mem(slot) hisi_sas_cmd_hdr_addr((slot)->buf)
48#define hisi_sas_cmd_hdr_addr_dma(slot) hisi_sas_cmd_hdr_addr((slot)->buf_dma)
Xiaofei Tanf557e322017-06-29 21:02:14 +080049
50#define hisi_sas_sge_addr(buf) \
Xiang Chenb3cce122019-02-06 18:52:51 +080051 ((buf) + offsetof(struct hisi_sas_slot_buf_table, sge_page))
52#define hisi_sas_sge_addr_mem(slot) hisi_sas_sge_addr((slot)->buf)
53#define hisi_sas_sge_addr_dma(slot) hisi_sas_sge_addr((slot)->buf_dma)
54
55#define hisi_sas_sge_dif_addr(buf) \
56 ((buf) + offsetof(struct hisi_sas_slot_dif_buf_table, sge_dif_page))
57#define hisi_sas_sge_dif_addr_mem(slot) hisi_sas_sge_dif_addr((slot)->buf)
58#define hisi_sas_sge_dif_addr_dma(slot) hisi_sas_sge_dif_addr((slot)->buf_dma)
John Garry6be6de12015-11-18 00:50:34 +080059
John Garry42e7a692015-11-18 00:50:49 +080060#define HISI_SAS_MAX_SSP_RESP_SZ (sizeof(struct ssp_frame_hdr) + 1024)
John Garry66ee9992015-11-18 00:50:54 +080061#define HISI_SAS_MAX_SMP_RESP_SZ 1028
John Garry6f2ff1a2016-01-26 02:47:20 +080062#define HISI_SAS_MAX_STP_RESP_SZ 28
John Garry42e7a692015-11-18 00:50:49 +080063
John Garry98bf39f2016-01-26 02:47:02 +080064#define DEV_IS_EXPANDER(type) \
65 ((type == SAS_EDGE_EXPANDER_DEVICE) || \
66 (type == SAS_FANOUT_EXPANDER_DEVICE))
67
Xiang Chen6c7bb8a2017-06-14 23:33:14 +080068#define HISI_SAS_SATA_PROTOCOL_NONDATA 0x1
69#define HISI_SAS_SATA_PROTOCOL_PIO 0x2
70#define HISI_SAS_SATA_PROTOCOL_DMA 0x4
71#define HISI_SAS_SATA_PROTOCOL_FPDMA 0x8
72#define HISI_SAS_SATA_PROTOCOL_ATAPI 0x10
73
Xiang Chend6a90002018-12-17 22:40:07 +080074#define HISI_SAS_DIF_PROT_MASK (SHOST_DIF_TYPE1_PROTECTION | \
75 SHOST_DIF_TYPE2_PROTECTION | \
76 SHOST_DIF_TYPE3_PROTECTION)
77
Xiang Chenb3cce122019-02-06 18:52:51 +080078#define HISI_SAS_DIX_PROT_MASK (SHOST_DIX_TYPE1_PROTECTION | \
79 SHOST_DIX_TYPE2_PROTECTION | \
80 SHOST_DIX_TYPE3_PROTECTION)
81
82#define HISI_SAS_PROT_MASK (HISI_SAS_DIF_PROT_MASK | HISI_SAS_DIX_PROT_MASK)
Xiang Chend6a90002018-12-17 22:40:07 +080083
Xiaofei Tanb6c9b152019-01-25 22:22:35 +080084#define HISI_SAS_WAIT_PHYUP_TIMEOUT 20
85
John Garryabda97c2015-11-18 00:50:51 +080086struct hisi_hba;
John Garryaf740db2015-11-18 00:50:41 +080087
John Garry07d78592015-11-18 00:50:47 +080088enum {
89 PORT_TYPE_SAS = (1U << 1),
90 PORT_TYPE_SATA = (1U << 0),
91};
92
Xiang Chen57dbb2b2019-02-28 22:51:01 +080093enum dev_status {
94 HISI_SAS_DEV_INIT,
95 HISI_SAS_DEV_NORMAL,
96};
97
John Garry441c2742016-08-24 19:05:47 +080098enum {
99 HISI_SAS_INT_ABT_CMD = 0,
100 HISI_SAS_INT_ABT_DEV = 1,
101};
102
John Garryabda97c2015-11-18 00:50:51 +0800103enum hisi_sas_dev_type {
104 HISI_SAS_DEV_TYPE_STP = 0,
105 HISI_SAS_DEV_TYPE_SSP,
106 HISI_SAS_DEV_TYPE_SATA,
107};
108
John Garry2b383352017-08-11 00:09:30 +0800109struct hisi_sas_hw_error {
110 u32 irq_msk;
111 u32 msk;
112 int shift;
113 const char *msg;
114 int reg;
Shiju Jose729428c2017-10-24 23:51:39 +0800115 const struct hisi_sas_hw_error *sub;
John Garry2b383352017-08-11 00:09:30 +0800116};
117
Xiaofei Tane402acd2017-12-09 01:16:38 +0800118struct hisi_sas_rst {
119 struct hisi_hba *hisi_hba;
120 struct completion *completion;
121 struct work_struct work;
122 bool done;
123};
124
125#define HISI_SAS_RST_WORK_INIT(r, c) \
126 { .hisi_hba = hisi_hba, \
127 .completion = &c, \
128 .work = __WORK_INITIALIZER(r.work, \
129 hisi_sas_sync_rst_work_handler), \
130 .done = false, \
131 }
132
133#define HISI_SAS_DECLARE_RST_WORK_ON_STACK(r) \
134 DECLARE_COMPLETION_ONSTACK(c); \
135 DECLARE_WORK(w, hisi_sas_sync_rst_work_handler); \
136 struct hisi_sas_rst r = HISI_SAS_RST_WORK_INIT(r, c)
137
138enum hisi_sas_bit_err_type {
139 HISI_SAS_ERR_SINGLE_BIT_ECC = 0x0,
140 HISI_SAS_ERR_MULTI_BIT_ECC = 0x1,
141};
142
Xiaofei Tane537b622017-12-09 01:16:44 +0800143enum hisi_sas_phy_event {
144 HISI_PHYE_PHY_UP = 0U,
Xiaofei Tan057c3d12017-12-09 01:16:45 +0800145 HISI_PHYE_LINK_RESET,
Xiaofei Tane537b622017-12-09 01:16:44 +0800146 HISI_PHYES_NUM,
147};
148
John Garry7eb78692015-11-18 00:50:31 +0800149struct hisi_sas_phy {
Xiaofei Tane537b622017-12-09 01:16:44 +0800150 struct work_struct works[HISI_PHYES_NUM];
John Garry976867e2015-11-18 00:50:42 +0800151 struct hisi_hba *hisi_hba;
152 struct hisi_sas_port *port;
John Garry7eb78692015-11-18 00:50:31 +0800153 struct asd_sas_phy sas_phy;
John Garry976867e2015-11-18 00:50:42 +0800154 struct sas_identify identify;
Xiang Chen3e1fb1b2018-05-21 18:09:25 +0800155 struct completion *reset_completion;
Xiaofei Tanb6c9b152019-01-25 22:22:35 +0800156 struct timer_list timer;
Xiang Chen3e1fb1b2018-05-21 18:09:25 +0800157 spinlock_t lock;
John Garry976867e2015-11-18 00:50:42 +0800158 u64 port_id; /* from hw */
John Garry976867e2015-11-18 00:50:42 +0800159 u64 frame_rcvd_size;
160 u8 frame_rcvd[32];
161 u8 phy_attached;
Xiang Chen3e1fb1b2018-05-21 18:09:25 +0800162 u8 in_reset;
163 u8 reserved[2];
John Garryd0ef10c2017-06-26 18:27:28 +0800164 u32 phy_type;
Xiaofei Tanaaeb8232019-02-28 22:50:59 +0800165 u32 code_violation_err_count;
John Garry976867e2015-11-18 00:50:42 +0800166 enum sas_linkrate minimum_linkrate;
167 enum sas_linkrate maximum_linkrate;
John Garryc63b88c2019-04-11 20:46:38 +0800168 int enable;
John Garry7eb78692015-11-18 00:50:31 +0800169};
170
171struct hisi_sas_port {
172 struct asd_sas_port sas_port;
John Garry976867e2015-11-18 00:50:42 +0800173 u8 port_attached;
174 u8 id; /* from hw */
John Garry7eb78692015-11-18 00:50:31 +0800175};
176
John Garry9101a072015-11-18 00:50:37 +0800177struct hisi_sas_cq {
178 struct hisi_hba *hisi_hba;
Xiang Chen4fefe5b2019-02-06 18:52:55 +0800179 const struct cpumask *pci_irq_mask;
John Garryd177c402017-01-03 20:24:48 +0800180 struct tasklet_struct tasklet;
John Garrye6c346f2016-09-06 23:36:11 +0800181 int rd_point;
John Garry9101a072015-11-18 00:50:37 +0800182 int id;
183};
184
John Garry4fde02a2016-09-06 23:36:12 +0800185struct hisi_sas_dq {
186 struct hisi_hba *hisi_hba;
Xiang Chenfa222db2018-05-09 23:10:48 +0800187 struct list_head list;
Xiang Chenb1a49412017-06-14 23:33:13 +0800188 spinlock_t lock;
John Garry4fde02a2016-09-06 23:36:12 +0800189 int wr_point;
190 int id;
191};
192
John Garryaf740db2015-11-18 00:50:41 +0800193struct hisi_sas_device {
John Garryabda97c2015-11-18 00:50:51 +0800194 struct hisi_hba *hisi_hba;
195 struct domain_device *sas_device;
Xiang Chen640acc92017-08-11 00:09:33 +0800196 struct completion *completion;
Xiang Chenb1a49412017-06-14 23:33:13 +0800197 struct hisi_sas_dq *dq;
John Garry405314d2017-03-23 01:25:21 +0800198 struct list_head list;
John Garryad604832017-06-14 23:33:12 +0800199 enum sas_device_type dev_type;
Xiang Chen57dbb2b2019-02-28 22:51:01 +0800200 enum dev_status dev_status;
John Garryad604832017-06-14 23:33:12 +0800201 int device_id;
Xiaofei Tan32ccba52017-04-10 21:21:57 +0800202 int sata_idx;
Xiang Chen4fefe5b2019-02-06 18:52:55 +0800203 spinlock_t lock; /* For protecting slots */
John Garryaf740db2015-11-18 00:50:41 +0800204};
205
Xiaofei Tan78bd2b42018-05-21 18:09:21 +0800206struct hisi_sas_tmf_task {
Xiaofei Tanb09fcd02018-05-21 18:09:22 +0800207 int force_phy;
208 int phy_id;
Xiaofei Tan78bd2b42018-05-21 18:09:21 +0800209 u8 tmf;
210 u16 tag_of_task_to_be_managed;
211};
212
John Garry6be6de12015-11-18 00:50:34 +0800213struct hisi_sas_slot {
John Garry42e7a692015-11-18 00:50:49 +0800214 struct list_head entry;
Xiang Chenfa222db2018-05-09 23:10:48 +0800215 struct list_head delivery;
John Garry42e7a692015-11-18 00:50:49 +0800216 struct sas_task *task;
217 struct hisi_sas_port *port;
218 u64 n_elem;
Xiang Chenb3cce122019-02-06 18:52:51 +0800219 u64 n_elem_dif;
John Garry42e7a692015-11-18 00:50:49 +0800220 int dlvry_queue;
221 int dlvry_queue_slot;
John Garry27a3f222015-11-18 00:50:50 +0800222 int cmplt_queue;
223 int cmplt_queue_slot;
John Garrycac9b2a2016-02-25 17:42:11 +0800224 int abort;
Xiang Chenfa222db2018-05-09 23:10:48 +0800225 int ready;
Xiang Chen4fefe5b2019-02-06 18:52:55 +0800226 int device_id;
John Garry42e7a692015-11-18 00:50:49 +0800227 void *cmd_hdr;
228 dma_addr_t cmd_hdr_dma;
John Garry0844a3f2017-04-10 21:21:59 +0800229 struct timer_list internal_abort_timer;
Xiang Chencd938e52018-05-02 23:56:26 +0800230 bool is_internal;
Xiaofei Tan78bd2b42018-05-21 18:09:21 +0800231 struct hisi_sas_tmf_task *tmf;
Xiang Chen2ba5afb2018-05-31 20:50:48 +0800232 /* Do not reorder/change members after here */
233 void *buf;
234 dma_addr_t buf_dma;
John Garry735bcc72018-12-06 21:34:40 +0800235 u16 idx;
John Garry6be6de12015-11-18 00:50:34 +0800236};
237
Luo Jiaxingcaefac12018-12-19 23:56:42 +0800238#define HISI_SAS_DEBUGFS_REG(x) {#x, x}
239
240struct hisi_sas_debugfs_reg_lu {
241 char *name;
242 int off;
243};
244
Luo Jiaxingeb1c2b72018-12-19 23:56:40 +0800245struct hisi_sas_debugfs_reg {
Luo Jiaxingcaefac12018-12-19 23:56:42 +0800246 const struct hisi_sas_debugfs_reg_lu *lu;
Luo Jiaxingeb1c2b72018-12-19 23:56:40 +0800247 int count;
Luo Jiaxing49159a52018-12-19 23:56:41 +0800248 int base_off;
249 union {
250 u32 (*read_global_reg)(struct hisi_hba *hisi_hba, u32 off);
251 u32 (*read_port_reg)(struct hisi_hba *hisi_hba, int port,
252 u32 off);
253 };
Luo Jiaxingeb1c2b72018-12-19 23:56:40 +0800254};
255
John Garry7eb78692015-11-18 00:50:31 +0800256struct hisi_sas_hw {
John Garry8ff1d572015-11-18 00:50:46 +0800257 int (*hw_init)(struct hisi_hba *hisi_hba);
John Garryabda97c2015-11-18 00:50:51 +0800258 void (*setup_itct)(struct hisi_hba *hisi_hba,
259 struct hisi_sas_device *device);
Xiang Chen784b46b2018-09-24 23:06:33 +0800260 int (*slot_index_alloc)(struct hisi_hba *hisi_hba,
John Garry685b6d62016-04-15 21:36:36 +0800261 struct domain_device *device);
262 struct hisi_sas_device *(*alloc_dev)(struct domain_device *device);
Xiang Chen569eddc2019-01-25 22:22:30 +0800263 void (*sl_notify_ssp)(struct hisi_hba *hisi_hba, int phy_no);
Xiang Chenb1a49412017-06-14 23:33:13 +0800264 int (*get_free_slot)(struct hisi_hba *hisi_hba, struct hisi_sas_dq *dq);
265 void (*start_delivery)(struct hisi_sas_dq *dq);
Xiang Chena2b38202018-05-09 23:10:46 +0800266 void (*prep_ssp)(struct hisi_hba *hisi_hba,
Xiaofei Tan78bd2b42018-05-21 18:09:21 +0800267 struct hisi_sas_slot *slot);
Xiang Chena2b38202018-05-09 23:10:46 +0800268 void (*prep_smp)(struct hisi_hba *hisi_hba,
John Garry66ee9992015-11-18 00:50:54 +0800269 struct hisi_sas_slot *slot);
Xiang Chena2b38202018-05-09 23:10:46 +0800270 void (*prep_stp)(struct hisi_hba *hisi_hba,
John Garry6f2ff1a2016-01-26 02:47:20 +0800271 struct hisi_sas_slot *slot);
Xiang Chena2b38202018-05-09 23:10:46 +0800272 void (*prep_abort)(struct hisi_hba *hisi_hba,
John Garry441c2742016-08-24 19:05:47 +0800273 struct hisi_sas_slot *slot,
274 int device_id, int abort_flag, int tag_to_abort);
John Garry27a3f222015-11-18 00:50:50 +0800275 int (*slot_complete)(struct hisi_hba *hisi_hba,
John Garry405314d2017-03-23 01:25:21 +0800276 struct hisi_sas_slot *slot);
John Garry396b8042017-03-23 01:25:19 +0800277 void (*phys_init)(struct hisi_hba *hisi_hba);
Xiang Chen1eb8eea2017-10-24 23:51:36 +0800278 void (*phy_start)(struct hisi_hba *hisi_hba, int phy_no);
John Garrye4189d52015-11-18 00:50:57 +0800279 void (*phy_disable)(struct hisi_hba *hisi_hba, int phy_no);
280 void (*phy_hard_reset)(struct hisi_hba *hisi_hba, int phy_no);
Xiaofei Tanc52108c2017-08-11 00:09:29 +0800281 void (*get_events)(struct hisi_hba *hisi_hba, int phy_no);
Xiang Chen2ae75782016-11-07 20:48:40 +0800282 void (*phy_set_linkrate)(struct hisi_hba *hisi_hba, int phy_no,
283 struct sas_phy_linkrates *linkrates);
284 enum sas_linkrate (*phy_get_max_linkrate)(void);
Xiaofei Tan02581412017-12-09 01:16:34 +0800285 void (*clear_itct)(struct hisi_hba *hisi_hba,
John Garry27a3f222015-11-18 00:50:50 +0800286 struct hisi_sas_device *dev);
Xiaofei Tan02581412017-12-09 01:16:34 +0800287 void (*free_device)(struct hisi_sas_device *sas_dev);
John Garry184a4632015-11-18 00:50:52 +0800288 int (*get_wideport_bitmap)(struct hisi_hba *hisi_hba, int port_id);
Xiang Chend30ff262017-06-14 23:33:32 +0800289 void (*dereg_device)(struct hisi_hba *hisi_hba,
290 struct domain_device *device);
Xiang Chen06ec0fb2017-03-23 01:25:18 +0800291 int (*soft_reset)(struct hisi_hba *hisi_hba);
Xiaofei Tan917d3bd2017-08-11 00:09:26 +0800292 u32 (*get_phys_state)(struct hisi_hba *hisi_hba);
Xiaofei Tan6379c562018-01-18 00:46:53 +0800293 int (*write_gpio)(struct hisi_hba *hisi_hba, u8 reg_type,
294 u8 reg_index, u8 reg_count, u8 *write_data);
Luo Jiaxing49159a52018-12-19 23:56:41 +0800295 int (*wait_cmds_complete_timeout)(struct hisi_hba *hisi_hba,
296 int delay_ms, int timeout_ms);
297 void (*snapshot_prepare)(struct hisi_hba *hisi_hba);
298 void (*snapshot_restore)(struct hisi_hba *hisi_hba);
John Garrya8d547b2016-01-26 02:47:03 +0800299 int max_command_entries;
John Garry6be6de12015-11-18 00:50:34 +0800300 int complete_hdr_size;
Xiang Chen235bfc72018-05-21 18:09:18 +0800301 struct scsi_host_template *sht;
Luo Jiaxingeb1c2b72018-12-19 23:56:40 +0800302
303 const struct hisi_sas_debugfs_reg *debugfs_reg_global;
304 const struct hisi_sas_debugfs_reg *debugfs_reg_port;
John Garry7eb78692015-11-18 00:50:31 +0800305};
306
307struct hisi_hba {
308 /* This must be the first element, used by SHOST_TO_SAS_HA */
309 struct sas_ha_struct *p;
310
John Garry11b75242017-06-14 23:33:17 +0800311 struct platform_device *platform_dev;
312 struct pci_dev *pci_dev;
313 struct device *dev;
314
Xiang Chend6a90002018-12-17 22:40:07 +0800315 int prot_mask;
316
John Garrye26b2f42015-11-18 00:50:32 +0800317 void __iomem *regs;
Xiaofei Tan6379c562018-01-18 00:46:53 +0800318 void __iomem *sgpio_regs;
John Garrye26b2f42015-11-18 00:50:32 +0800319 struct regmap *ctrl;
320 u32 ctrl_reset_reg;
321 u32 ctrl_reset_sts_reg;
322 u32 ctrl_clock_ena_reg;
John Garry3bc45af2016-10-04 19:11:11 +0800323 u32 refclk_frequency_mhz;
John Garry7eb78692015-11-18 00:50:31 +0800324 u8 sas_addr[SAS_ADDR_SIZE];
325
326 int n_phy;
John Garryfa42d802015-11-18 00:50:43 +0800327 spinlock_t lock;
Xiaofei Tand2fc4012018-05-31 20:50:44 +0800328 struct semaphore sem;
John Garry7eb78692015-11-18 00:50:31 +0800329
John Garryfa42d802015-11-18 00:50:43 +0800330 struct timer_list timer;
John Garry7e9080e2015-11-18 00:50:40 +0800331 struct workqueue_struct *wq;
John Garry257efd12015-11-18 00:50:36 +0800332
333 int slot_index_count;
Xiang Chenfa3be0f2018-05-21 18:09:14 +0800334 int last_slot_index;
Xiang Chen1b865182018-05-21 18:09:15 +0800335 int last_dev_id;
John Garry257efd12015-11-18 00:50:36 +0800336 unsigned long *slot_index_tags;
Xiaofei Tanc7b9d362017-04-10 21:21:56 +0800337 unsigned long reject_stp_links_msk;
John Garry257efd12015-11-18 00:50:36 +0800338
John Garry7eb78692015-11-18 00:50:31 +0800339 /* SCSI/SAS glue */
340 struct sas_ha_struct sha;
341 struct Scsi_Host *shost;
John Garry9101a072015-11-18 00:50:37 +0800342
343 struct hisi_sas_cq cq[HISI_SAS_MAX_QUEUES];
John Garry4fde02a2016-09-06 23:36:12 +0800344 struct hisi_sas_dq dq[HISI_SAS_MAX_QUEUES];
John Garry7eb78692015-11-18 00:50:31 +0800345 struct hisi_sas_phy phy[HISI_SAS_MAX_PHYS];
346 struct hisi_sas_port port[HISI_SAS_MAX_PHYS];
John Garrye26b2f42015-11-18 00:50:32 +0800347
348 int queue_count;
John Garry6be6de12015-11-18 00:50:34 +0800349
John Garryaf740db2015-11-18 00:50:41 +0800350 struct hisi_sas_device devices[HISI_SAS_MAX_DEVICES];
John Garry6be6de12015-11-18 00:50:34 +0800351 struct hisi_sas_cmd_hdr *cmd_hdr[HISI_SAS_MAX_QUEUES];
352 dma_addr_t cmd_hdr_dma[HISI_SAS_MAX_QUEUES];
353 void *complete_hdr[HISI_SAS_MAX_QUEUES];
354 dma_addr_t complete_hdr_dma[HISI_SAS_MAX_QUEUES];
355 struct hisi_sas_initial_fis *initial_fis;
356 dma_addr_t initial_fis_dma;
357 struct hisi_sas_itct *itct;
358 dma_addr_t itct_dma;
359 struct hisi_sas_iost *iost;
360 dma_addr_t iost_dma;
361 struct hisi_sas_breakpoint *breakpoint;
362 dma_addr_t breakpoint_dma;
363 struct hisi_sas_breakpoint *sata_breakpoint;
364 dma_addr_t sata_breakpoint_dma;
365 struct hisi_sas_slot *slot_info;
Xiang Chen06ec0fb2017-03-23 01:25:18 +0800366 unsigned long flags;
John Garry7eb78692015-11-18 00:50:31 +0800367 const struct hisi_sas_hw *hw; /* Low level hw interface */
Xiaofei Tan32ccba52017-04-10 21:21:57 +0800368 unsigned long sata_dev_bitmap[BITS_TO_LONGS(HISI_SAS_MAX_DEVICES)];
Xiang Chen06ec0fb2017-03-23 01:25:18 +0800369 struct work_struct rst_work;
Luo Jiaxing49159a52018-12-19 23:56:41 +0800370 struct work_struct debugfs_work;
Xiaofei Tan45222042018-07-18 22:14:28 +0800371 u32 phy_state;
Xiang Chen37359792018-11-09 22:06:34 +0800372 u32 intr_coal_ticks; /* Time of interrupt coalesce in us */
373 u32 intr_coal_count; /* Interrupt count to coalesce */
Luo Jiaxingef634642018-12-19 23:56:39 +0800374
John Garry795f25a2019-02-06 18:52:54 +0800375 int cq_nvecs;
Xiang Chen4fefe5b2019-02-06 18:52:55 +0800376 unsigned int *reply_map;
John Garry795f25a2019-02-06 18:52:54 +0800377
Luo Jiaxingeb1c2b72018-12-19 23:56:40 +0800378 /* debugfs memories */
John Garry5b0eeac2019-01-25 22:22:28 +0800379 u32 *debugfs_global_reg;
380 u32 *debugfs_port_reg[HISI_SAS_MAX_PHYS];
Luo Jiaxingeb1c2b72018-12-19 23:56:40 +0800381 void *debugfs_complete_hdr[HISI_SAS_MAX_QUEUES];
382 struct hisi_sas_cmd_hdr *debugfs_cmd_hdr[HISI_SAS_MAX_QUEUES];
383 struct hisi_sas_iost *debugfs_iost;
384 struct hisi_sas_itct *debugfs_itct;
385
Luo Jiaxingef634642018-12-19 23:56:39 +0800386 struct dentry *debugfs_dir;
Luo Jiaxing49159a52018-12-19 23:56:41 +0800387 struct dentry *debugfs_dump_dentry;
John Garryc2c7e742019-01-25 22:22:27 +0800388 bool debugfs_snapshot;
John Garry7eb78692015-11-18 00:50:31 +0800389};
390
John Garryc799d6b2015-11-18 00:50:33 +0800391/* Generic HW DMA host memory structures */
392/* Delivery queue header */
393struct hisi_sas_cmd_hdr {
394 /* dw0 */
395 __le32 dw0;
396
397 /* dw1 */
398 __le32 dw1;
399
400 /* dw2 */
401 __le32 dw2;
402
403 /* dw3 */
404 __le32 transfer_tags;
405
406 /* dw4 */
407 __le32 data_transfer_len;
408
409 /* dw5 */
410 __le32 first_burst_num;
411
412 /* dw6 */
413 __le32 sg_len;
414
415 /* dw7 */
416 __le32 dw7;
417
418 /* dw8-9 */
419 __le64 cmd_table_addr;
420
421 /* dw10-11 */
422 __le64 sts_buffer_addr;
423
424 /* dw12-13 */
425 __le64 prd_table_addr;
426
427 /* dw14-15 */
428 __le64 dif_prd_table_addr;
429};
430
431struct hisi_sas_itct {
432 __le64 qw0;
433 __le64 sas_addr;
434 __le64 qw2;
435 __le64 qw3;
John Garry281e3bf2016-01-26 02:47:06 +0800436 __le64 qw4_15[12];
John Garryc799d6b2015-11-18 00:50:33 +0800437};
438
439struct hisi_sas_iost {
440 __le64 qw0;
441 __le64 qw1;
442 __le64 qw2;
443 __le64 qw3;
444};
445
446struct hisi_sas_err_record {
John Garry8d1eee72016-01-26 02:47:05 +0800447 u32 data[4];
John Garryc799d6b2015-11-18 00:50:33 +0800448};
449
450struct hisi_sas_initial_fis {
451 struct hisi_sas_err_record err_record;
452 struct dev_to_host_fis fis;
453 u32 rsvd[3];
454};
455
456struct hisi_sas_breakpoint {
Xiang Chen3297ded2017-10-24 23:51:35 +0800457 u8 data[128];
458};
459
460struct hisi_sas_sata_breakpoint {
461 struct hisi_sas_breakpoint tag[32];
John Garryc799d6b2015-11-18 00:50:33 +0800462};
463
464struct hisi_sas_sge {
465 __le64 addr;
466 __le32 page_ctrl_0;
467 __le32 page_ctrl_1;
468 __le32 data_len;
469 __le32 data_off;
470};
471
472struct hisi_sas_command_table_smp {
473 u8 bytes[44];
474};
475
476struct hisi_sas_command_table_stp {
477 struct host_to_dev_fis command_fis;
478 u8 dummy[12];
479 u8 atapi_cdb[ATAPI_CDB_LEN];
480};
481
Ming Lin65e86172016-04-04 14:48:10 -0700482#define HISI_SAS_SGE_PAGE_CNT SG_CHUNK_SIZE
John Garryc799d6b2015-11-18 00:50:33 +0800483struct hisi_sas_sge_page {
484 struct hisi_sas_sge sge[HISI_SAS_SGE_PAGE_CNT];
Xiaofei Tanf557e322017-06-29 21:02:14 +0800485} __aligned(16);
John Garryc799d6b2015-11-18 00:50:33 +0800486
Xiang Chenb3cce122019-02-06 18:52:51 +0800487#define HISI_SAS_SGE_DIF_PAGE_CNT SG_CHUNK_SIZE
488struct hisi_sas_sge_dif_page {
489 struct hisi_sas_sge sge[HISI_SAS_SGE_DIF_PAGE_CNT];
490} __aligned(16);
491
John Garryc799d6b2015-11-18 00:50:33 +0800492struct hisi_sas_command_table_ssp {
493 struct ssp_frame_hdr hdr;
494 union {
495 struct {
496 struct ssp_command_iu task;
Xiang Chena14da7a2018-05-02 23:56:27 +0800497 u32 prot[7];
John Garryc799d6b2015-11-18 00:50:33 +0800498 };
499 struct ssp_tmf_iu ssp_task;
500 struct xfer_rdy_iu xfer_rdy;
501 struct ssp_response_iu ssp_res;
502 } u;
503};
504
505union hisi_sas_command_table {
506 struct hisi_sas_command_table_ssp ssp;
507 struct hisi_sas_command_table_smp smp;
508 struct hisi_sas_command_table_stp stp;
Xiaofei Tanf557e322017-06-29 21:02:14 +0800509} __aligned(16);
510
511struct hisi_sas_status_buffer {
512 struct hisi_sas_err_record err;
513 u8 iu[1024];
514} __aligned(16);
515
516struct hisi_sas_slot_buf_table {
517 struct hisi_sas_status_buffer status_buffer;
518 union hisi_sas_command_table command_header;
519 struct hisi_sas_sge_page sge_page;
John Garryc799d6b2015-11-18 00:50:33 +0800520};
John Garry2e244f02017-03-23 01:25:17 +0800521
Xiang Chenb3cce122019-02-06 18:52:51 +0800522struct hisi_sas_slot_dif_buf_table {
523 struct hisi_sas_slot_buf_table slot_buf;
524 struct hisi_sas_sge_dif_page sge_dif_page;
525};
526
John Garrye21fe3a2017-06-14 23:33:20 +0800527extern struct scsi_transport_template *hisi_sas_stt;
Luo Jiaxingef634642018-12-19 23:56:39 +0800528
529extern bool hisi_sas_debugfs_enable;
530extern struct dentry *hisi_sas_debugfs_dir;
531
Xiang Chena25d0d32017-08-11 00:09:40 +0800532extern void hisi_sas_stop_phys(struct hisi_hba *hisi_hba);
Xiang Chenae68b562019-01-25 22:22:33 +0800533extern int hisi_sas_alloc(struct hisi_hba *hisi_hba);
John Garrye21fe3a2017-06-14 23:33:20 +0800534extern void hisi_sas_free(struct hisi_hba *hisi_hba);
chenxiang468f4b82017-12-28 18:20:47 +0800535extern u8 hisi_sas_get_ata_protocol(struct host_to_dev_fis *fis,
536 int direction);
John Garry2e244f02017-03-23 01:25:17 +0800537extern struct hisi_sas_port *to_hisi_sas_port(struct asd_sas_port *sas_port);
Xiang Chen75904072017-06-14 23:33:15 +0800538extern void hisi_sas_sata_done(struct sas_task *task,
539 struct hisi_sas_slot *slot);
Xiang Chen318913c2017-06-14 23:33:16 +0800540extern int hisi_sas_get_ncq_tag(struct sas_task *task, u32 *tag);
John Garry0fa24c12017-06-14 23:33:18 +0800541extern int hisi_sas_get_fw_info(struct hisi_hba *hisi_hba);
John Garry9fb10b52015-11-18 00:50:44 +0800542extern int hisi_sas_probe(struct platform_device *pdev,
543 const struct hisi_sas_hw *ops);
544extern int hisi_sas_remove(struct platform_device *pdev);
John Garryc799d6b2015-11-18 00:50:33 +0800545
Xiang Chen235bfc72018-05-21 18:09:18 +0800546extern int hisi_sas_slave_configure(struct scsi_device *sdev);
547extern int hisi_sas_scan_finished(struct Scsi_Host *shost, unsigned long time);
548extern void hisi_sas_scan_start(struct Scsi_Host *shost);
Xiang Chen235bfc72018-05-21 18:09:18 +0800549extern int hisi_sas_host_reset(struct Scsi_Host *shost, int reset_type);
John Garryc63b88c2019-04-11 20:46:38 +0800550extern void hisi_sas_phy_enable(struct hisi_hba *hisi_hba, int phy_no,
551 int enable);
John Garry184a4632015-11-18 00:50:52 +0800552extern void hisi_sas_phy_down(struct hisi_hba *hisi_hba, int phy_no, int rdy);
John Garry27a3f222015-11-18 00:50:50 +0800553extern void hisi_sas_slot_task_free(struct hisi_hba *hisi_hba,
554 struct sas_task *task,
555 struct hisi_sas_slot *slot);
Xiang Chen06ec0fb2017-03-23 01:25:18 +0800556extern void hisi_sas_init_mem(struct hisi_hba *hisi_hba);
Xiaofei Tanb4241f02017-10-24 23:51:45 +0800557extern void hisi_sas_rst_work_handler(struct work_struct *work);
Xiaofei Tane402acd2017-12-09 01:16:38 +0800558extern void hisi_sas_sync_rst_work_handler(struct work_struct *work);
Xiaofei Tan571295f2017-10-24 23:51:47 +0800559extern void hisi_sas_kill_tasklets(struct hisi_hba *hisi_hba);
Xiaofei Tanb6c9b152019-01-25 22:22:35 +0800560extern void hisi_sas_phy_oob_ready(struct hisi_hba *hisi_hba, int phy_no);
Xiaofei Tane537b622017-12-09 01:16:44 +0800561extern bool hisi_sas_notify_phy_event(struct hisi_sas_phy *phy,
562 enum hisi_sas_phy_event event);
Xiang Chen4d0951e2017-12-09 01:16:50 +0800563extern void hisi_sas_release_tasks(struct hisi_hba *hisi_hba);
Xiang Chenc2c1d9d2018-05-02 23:56:30 +0800564extern u8 hisi_sas_get_prog_phy_linkrate_mask(enum sas_linkrate max);
Xiaofei Tan45222042018-07-18 22:14:28 +0800565extern void hisi_sas_controller_reset_prepare(struct hisi_hba *hisi_hba);
566extern void hisi_sas_controller_reset_done(struct hisi_hba *hisi_hba);
Luo Jiaxingef634642018-12-19 23:56:39 +0800567extern void hisi_sas_debugfs_init(struct hisi_hba *hisi_hba);
568extern void hisi_sas_debugfs_exit(struct hisi_hba *hisi_hba);
Luo Jiaxing49159a52018-12-19 23:56:41 +0800569extern void hisi_sas_debugfs_work_handler(struct work_struct *work);
John Garrye8899fa2015-11-18 00:50:30 +0800570#endif