blob: 5bb6759f41ea209bd857cab95718fb66279de8a4 [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>
Luo Jiaxingef634642018-12-19 23:56:39 +080017#include <linux/debugfs.h>
John Garrye8899fa2015-11-18 00:50:30 +080018#include <linux/dmapool.h>
Xiang Chena25d0d32017-08-11 00:09:40 +080019#include <linux/iopoll.h>
Xiang Chen2ba5afb2018-05-31 20:50:48 +080020#include <linux/lcm.h>
John Garrye8899fa2015-11-18 00:50:30 +080021#include <linux/mfd/syscon.h>
22#include <linux/module.h>
23#include <linux/of_address.h>
John Garry11b75242017-06-14 23:33:17 +080024#include <linux/pci.h>
John Garrye8899fa2015-11-18 00:50:30 +080025#include <linux/platform_device.h>
John Garry4d558c72016-02-04 02:26:08 +080026#include <linux/property.h>
John Garrye8899fa2015-11-18 00:50:30 +080027#include <linux/regmap.h>
John Garry6f2ff1a2016-01-26 02:47:20 +080028#include <scsi/sas_ata.h>
John Garrye8899fa2015-11-18 00:50:30 +080029#include <scsi/libsas.h>
30
John Garry7eb78692015-11-18 00:50:31 +080031#define HISI_SAS_MAX_PHYS 9
John Garry6be6de12015-11-18 00:50:34 +080032#define HISI_SAS_MAX_QUEUES 32
33#define HISI_SAS_QUEUE_SLOTS 512
Xiang Chen3297ded2017-10-24 23:51:35 +080034#define HISI_SAS_MAX_ITCT_ENTRIES 1024
John Garry7eb78692015-11-18 00:50:31 +080035#define HISI_SAS_MAX_DEVICES HISI_SAS_MAX_ITCT_ENTRIES
Xiang Chen06ec0fb2017-03-23 01:25:18 +080036#define HISI_SAS_RESET_BIT 0
Xiaofei Tan917d3bd2017-08-11 00:09:26 +080037#define HISI_SAS_REJECT_CMD_BIT 1
Xiang Chen784b46b2018-09-24 23:06:33 +080038#define HISI_SAS_RESERVED_IPTT_CNT 96
John Garry7eb78692015-11-18 00:50:31 +080039
Xiaofei Tanf557e322017-06-29 21:02:14 +080040#define HISI_SAS_STATUS_BUF_SZ (sizeof(struct hisi_sas_status_buffer))
41#define HISI_SAS_COMMAND_TABLE_SZ (sizeof(union hisi_sas_command_table))
42
43#define hisi_sas_status_buf_addr(buf) \
44 (buf + offsetof(struct hisi_sas_slot_buf_table, status_buffer))
45#define hisi_sas_status_buf_addr_mem(slot) hisi_sas_status_buf_addr(slot->buf)
46#define hisi_sas_status_buf_addr_dma(slot) \
47 hisi_sas_status_buf_addr(slot->buf_dma)
48
49#define hisi_sas_cmd_hdr_addr(buf) \
50 (buf + offsetof(struct hisi_sas_slot_buf_table, command_header))
51#define hisi_sas_cmd_hdr_addr_mem(slot) hisi_sas_cmd_hdr_addr(slot->buf)
52#define hisi_sas_cmd_hdr_addr_dma(slot) hisi_sas_cmd_hdr_addr(slot->buf_dma)
53
54#define hisi_sas_sge_addr(buf) \
55 (buf + offsetof(struct hisi_sas_slot_buf_table, sge_page))
56#define hisi_sas_sge_addr_mem(slot) hisi_sas_sge_addr(slot->buf)
57#define hisi_sas_sge_addr_dma(slot) hisi_sas_sge_addr(slot->buf_dma)
John Garry6be6de12015-11-18 00:50:34 +080058
John Garry42e7a692015-11-18 00:50:49 +080059#define HISI_SAS_MAX_SSP_RESP_SZ (sizeof(struct ssp_frame_hdr) + 1024)
John Garry66ee9992015-11-18 00:50:54 +080060#define HISI_SAS_MAX_SMP_RESP_SZ 1028
John Garry6f2ff1a2016-01-26 02:47:20 +080061#define HISI_SAS_MAX_STP_RESP_SZ 28
John Garry42e7a692015-11-18 00:50:49 +080062
John Garry98bf39f2016-01-26 02:47:02 +080063#define DEV_IS_EXPANDER(type) \
64 ((type == SAS_EDGE_EXPANDER_DEVICE) || \
65 (type == SAS_FANOUT_EXPANDER_DEVICE))
66
Xiang Chen6c7bb8a2017-06-14 23:33:14 +080067#define HISI_SAS_SATA_PROTOCOL_NONDATA 0x1
68#define HISI_SAS_SATA_PROTOCOL_PIO 0x2
69#define HISI_SAS_SATA_PROTOCOL_DMA 0x4
70#define HISI_SAS_SATA_PROTOCOL_FPDMA 0x8
71#define HISI_SAS_SATA_PROTOCOL_ATAPI 0x10
72
Xiang Chend6a90002018-12-17 22:40:07 +080073#define HISI_SAS_DIF_PROT_MASK (SHOST_DIF_TYPE1_PROTECTION | \
74 SHOST_DIF_TYPE2_PROTECTION | \
75 SHOST_DIF_TYPE3_PROTECTION)
76
77#define HISI_SAS_PROT_MASK (HISI_SAS_DIF_PROT_MASK)
78
John Garryabda97c2015-11-18 00:50:51 +080079struct hisi_hba;
John Garryaf740db2015-11-18 00:50:41 +080080
John Garry07d78592015-11-18 00:50:47 +080081enum {
82 PORT_TYPE_SAS = (1U << 1),
83 PORT_TYPE_SATA = (1U << 0),
84};
85
John Garryaf740db2015-11-18 00:50:41 +080086enum dev_status {
87 HISI_SAS_DEV_NORMAL,
88 HISI_SAS_DEV_EH,
89};
John Garryabda97c2015-11-18 00:50:51 +080090
John Garry441c2742016-08-24 19:05:47 +080091enum {
92 HISI_SAS_INT_ABT_CMD = 0,
93 HISI_SAS_INT_ABT_DEV = 1,
94};
95
John Garryabda97c2015-11-18 00:50:51 +080096enum hisi_sas_dev_type {
97 HISI_SAS_DEV_TYPE_STP = 0,
98 HISI_SAS_DEV_TYPE_SSP,
99 HISI_SAS_DEV_TYPE_SATA,
100};
101
John Garry2b383352017-08-11 00:09:30 +0800102struct hisi_sas_hw_error {
103 u32 irq_msk;
104 u32 msk;
105 int shift;
106 const char *msg;
107 int reg;
Shiju Jose729428c2017-10-24 23:51:39 +0800108 const struct hisi_sas_hw_error *sub;
John Garry2b383352017-08-11 00:09:30 +0800109};
110
Xiaofei Tane402acd2017-12-09 01:16:38 +0800111struct hisi_sas_rst {
112 struct hisi_hba *hisi_hba;
113 struct completion *completion;
114 struct work_struct work;
115 bool done;
116};
117
118#define HISI_SAS_RST_WORK_INIT(r, c) \
119 { .hisi_hba = hisi_hba, \
120 .completion = &c, \
121 .work = __WORK_INITIALIZER(r.work, \
122 hisi_sas_sync_rst_work_handler), \
123 .done = false, \
124 }
125
126#define HISI_SAS_DECLARE_RST_WORK_ON_STACK(r) \
127 DECLARE_COMPLETION_ONSTACK(c); \
128 DECLARE_WORK(w, hisi_sas_sync_rst_work_handler); \
129 struct hisi_sas_rst r = HISI_SAS_RST_WORK_INIT(r, c)
130
131enum hisi_sas_bit_err_type {
132 HISI_SAS_ERR_SINGLE_BIT_ECC = 0x0,
133 HISI_SAS_ERR_MULTI_BIT_ECC = 0x1,
134};
135
Xiaofei Tane537b622017-12-09 01:16:44 +0800136enum hisi_sas_phy_event {
137 HISI_PHYE_PHY_UP = 0U,
Xiaofei Tan057c3d12017-12-09 01:16:45 +0800138 HISI_PHYE_LINK_RESET,
Xiaofei Tane537b622017-12-09 01:16:44 +0800139 HISI_PHYES_NUM,
140};
141
John Garry7eb78692015-11-18 00:50:31 +0800142struct hisi_sas_phy {
Xiaofei Tane537b622017-12-09 01:16:44 +0800143 struct work_struct works[HISI_PHYES_NUM];
John Garry976867e2015-11-18 00:50:42 +0800144 struct hisi_hba *hisi_hba;
145 struct hisi_sas_port *port;
John Garry7eb78692015-11-18 00:50:31 +0800146 struct asd_sas_phy sas_phy;
John Garry976867e2015-11-18 00:50:42 +0800147 struct sas_identify identify;
Xiang Chen3e1fb1b2018-05-21 18:09:25 +0800148 struct completion *reset_completion;
149 spinlock_t lock;
John Garry976867e2015-11-18 00:50:42 +0800150 u64 port_id; /* from hw */
John Garry976867e2015-11-18 00:50:42 +0800151 u64 frame_rcvd_size;
152 u8 frame_rcvd[32];
153 u8 phy_attached;
Xiang Chen3e1fb1b2018-05-21 18:09:25 +0800154 u8 in_reset;
155 u8 reserved[2];
John Garryd0ef10c2017-06-26 18:27:28 +0800156 u32 phy_type;
John Garry976867e2015-11-18 00:50:42 +0800157 enum sas_linkrate minimum_linkrate;
158 enum sas_linkrate maximum_linkrate;
John Garry7eb78692015-11-18 00:50:31 +0800159};
160
161struct hisi_sas_port {
162 struct asd_sas_port sas_port;
John Garry976867e2015-11-18 00:50:42 +0800163 u8 port_attached;
164 u8 id; /* from hw */
John Garry7eb78692015-11-18 00:50:31 +0800165};
166
John Garry9101a072015-11-18 00:50:37 +0800167struct hisi_sas_cq {
168 struct hisi_hba *hisi_hba;
John Garryd177c402017-01-03 20:24:48 +0800169 struct tasklet_struct tasklet;
John Garrye6c346f2016-09-06 23:36:11 +0800170 int rd_point;
John Garry9101a072015-11-18 00:50:37 +0800171 int id;
172};
173
John Garry4fde02a2016-09-06 23:36:12 +0800174struct hisi_sas_dq {
175 struct hisi_hba *hisi_hba;
Xiang Chenfa222db2018-05-09 23:10:48 +0800176 struct list_head list;
Xiang Chenb1a49412017-06-14 23:33:13 +0800177 spinlock_t lock;
John Garry4fde02a2016-09-06 23:36:12 +0800178 int wr_point;
179 int id;
180};
181
John Garryaf740db2015-11-18 00:50:41 +0800182struct hisi_sas_device {
John Garryabda97c2015-11-18 00:50:51 +0800183 struct hisi_hba *hisi_hba;
184 struct domain_device *sas_device;
Xiang Chen640acc92017-08-11 00:09:33 +0800185 struct completion *completion;
Xiang Chenb1a49412017-06-14 23:33:13 +0800186 struct hisi_sas_dq *dq;
John Garry405314d2017-03-23 01:25:21 +0800187 struct list_head list;
John Garryad604832017-06-14 23:33:12 +0800188 enum sas_device_type dev_type;
189 int device_id;
Xiaofei Tan32ccba52017-04-10 21:21:57 +0800190 int sata_idx;
John Garryad604832017-06-14 23:33:12 +0800191 u8 dev_status;
John Garryaf740db2015-11-18 00:50:41 +0800192};
193
Xiaofei Tan78bd2b42018-05-21 18:09:21 +0800194struct hisi_sas_tmf_task {
Xiaofei Tanb09fcd02018-05-21 18:09:22 +0800195 int force_phy;
196 int phy_id;
Xiaofei Tan78bd2b42018-05-21 18:09:21 +0800197 u8 tmf;
198 u16 tag_of_task_to_be_managed;
199};
200
John Garry6be6de12015-11-18 00:50:34 +0800201struct hisi_sas_slot {
John Garry42e7a692015-11-18 00:50:49 +0800202 struct list_head entry;
Xiang Chenfa222db2018-05-09 23:10:48 +0800203 struct list_head delivery;
John Garry42e7a692015-11-18 00:50:49 +0800204 struct sas_task *task;
205 struct hisi_sas_port *port;
206 u64 n_elem;
207 int dlvry_queue;
208 int dlvry_queue_slot;
John Garry27a3f222015-11-18 00:50:50 +0800209 int cmplt_queue;
210 int cmplt_queue_slot;
John Garrycac9b2a2016-02-25 17:42:11 +0800211 int abort;
Xiang Chenfa222db2018-05-09 23:10:48 +0800212 int ready;
John Garry42e7a692015-11-18 00:50:49 +0800213 void *cmd_hdr;
214 dma_addr_t cmd_hdr_dma;
John Garry0844a3f2017-04-10 21:21:59 +0800215 struct timer_list internal_abort_timer;
Xiang Chencd938e52018-05-02 23:56:26 +0800216 bool is_internal;
Xiaofei Tan78bd2b42018-05-21 18:09:21 +0800217 struct hisi_sas_tmf_task *tmf;
Xiang Chen2ba5afb2018-05-31 20:50:48 +0800218 /* Do not reorder/change members after here */
219 void *buf;
220 dma_addr_t buf_dma;
John Garry735bcc72018-12-06 21:34:40 +0800221 u16 idx;
John Garry6be6de12015-11-18 00:50:34 +0800222};
223
Luo Jiaxingcaefac12018-12-19 23:56:42 +0800224#define HISI_SAS_DEBUGFS_REG(x) {#x, x}
225
226struct hisi_sas_debugfs_reg_lu {
227 char *name;
228 int off;
229};
230
Luo Jiaxingeb1c2b72018-12-19 23:56:40 +0800231struct hisi_sas_debugfs_reg {
Luo Jiaxingcaefac12018-12-19 23:56:42 +0800232 const struct hisi_sas_debugfs_reg_lu *lu;
Luo Jiaxingeb1c2b72018-12-19 23:56:40 +0800233 int count;
Luo Jiaxing49159a52018-12-19 23:56:41 +0800234 int base_off;
235 union {
236 u32 (*read_global_reg)(struct hisi_hba *hisi_hba, u32 off);
237 u32 (*read_port_reg)(struct hisi_hba *hisi_hba, int port,
238 u32 off);
239 };
Luo Jiaxingeb1c2b72018-12-19 23:56:40 +0800240};
241
John Garry7eb78692015-11-18 00:50:31 +0800242struct hisi_sas_hw {
John Garry8ff1d572015-11-18 00:50:46 +0800243 int (*hw_init)(struct hisi_hba *hisi_hba);
John Garryabda97c2015-11-18 00:50:51 +0800244 void (*setup_itct)(struct hisi_hba *hisi_hba,
245 struct hisi_sas_device *device);
Xiang Chen784b46b2018-09-24 23:06:33 +0800246 int (*slot_index_alloc)(struct hisi_hba *hisi_hba,
John Garry685b6d62016-04-15 21:36:36 +0800247 struct domain_device *device);
248 struct hisi_sas_device *(*alloc_dev)(struct domain_device *device);
John Garry66139922015-11-18 00:50:48 +0800249 void (*sl_notify)(struct hisi_hba *hisi_hba, int phy_no);
Xiang Chenb1a49412017-06-14 23:33:13 +0800250 int (*get_free_slot)(struct hisi_hba *hisi_hba, struct hisi_sas_dq *dq);
251 void (*start_delivery)(struct hisi_sas_dq *dq);
Xiang Chena2b38202018-05-09 23:10:46 +0800252 void (*prep_ssp)(struct hisi_hba *hisi_hba,
Xiaofei Tan78bd2b42018-05-21 18:09:21 +0800253 struct hisi_sas_slot *slot);
Xiang Chena2b38202018-05-09 23:10:46 +0800254 void (*prep_smp)(struct hisi_hba *hisi_hba,
John Garry66ee9992015-11-18 00:50:54 +0800255 struct hisi_sas_slot *slot);
Xiang Chena2b38202018-05-09 23:10:46 +0800256 void (*prep_stp)(struct hisi_hba *hisi_hba,
John Garry6f2ff1a2016-01-26 02:47:20 +0800257 struct hisi_sas_slot *slot);
Xiang Chena2b38202018-05-09 23:10:46 +0800258 void (*prep_abort)(struct hisi_hba *hisi_hba,
John Garry441c2742016-08-24 19:05:47 +0800259 struct hisi_sas_slot *slot,
260 int device_id, int abort_flag, int tag_to_abort);
John Garry27a3f222015-11-18 00:50:50 +0800261 int (*slot_complete)(struct hisi_hba *hisi_hba,
John Garry405314d2017-03-23 01:25:21 +0800262 struct hisi_sas_slot *slot);
John Garry396b8042017-03-23 01:25:19 +0800263 void (*phys_init)(struct hisi_hba *hisi_hba);
Xiang Chen1eb8eea2017-10-24 23:51:36 +0800264 void (*phy_start)(struct hisi_hba *hisi_hba, int phy_no);
John Garrye4189d52015-11-18 00:50:57 +0800265 void (*phy_disable)(struct hisi_hba *hisi_hba, int phy_no);
266 void (*phy_hard_reset)(struct hisi_hba *hisi_hba, int phy_no);
Xiaofei Tanc52108c2017-08-11 00:09:29 +0800267 void (*get_events)(struct hisi_hba *hisi_hba, int phy_no);
Xiang Chen2ae75782016-11-07 20:48:40 +0800268 void (*phy_set_linkrate)(struct hisi_hba *hisi_hba, int phy_no,
269 struct sas_phy_linkrates *linkrates);
270 enum sas_linkrate (*phy_get_max_linkrate)(void);
Xiaofei Tan02581412017-12-09 01:16:34 +0800271 void (*clear_itct)(struct hisi_hba *hisi_hba,
John Garry27a3f222015-11-18 00:50:50 +0800272 struct hisi_sas_device *dev);
Xiaofei Tan02581412017-12-09 01:16:34 +0800273 void (*free_device)(struct hisi_sas_device *sas_dev);
John Garry184a4632015-11-18 00:50:52 +0800274 int (*get_wideport_bitmap)(struct hisi_hba *hisi_hba, int port_id);
Xiang Chend30ff262017-06-14 23:33:32 +0800275 void (*dereg_device)(struct hisi_hba *hisi_hba,
276 struct domain_device *device);
Xiang Chen06ec0fb2017-03-23 01:25:18 +0800277 int (*soft_reset)(struct hisi_hba *hisi_hba);
Xiaofei Tan917d3bd2017-08-11 00:09:26 +0800278 u32 (*get_phys_state)(struct hisi_hba *hisi_hba);
Xiaofei Tan6379c562018-01-18 00:46:53 +0800279 int (*write_gpio)(struct hisi_hba *hisi_hba, u8 reg_type,
280 u8 reg_index, u8 reg_count, u8 *write_data);
Luo Jiaxing49159a52018-12-19 23:56:41 +0800281 int (*wait_cmds_complete_timeout)(struct hisi_hba *hisi_hba,
282 int delay_ms, int timeout_ms);
283 void (*snapshot_prepare)(struct hisi_hba *hisi_hba);
284 void (*snapshot_restore)(struct hisi_hba *hisi_hba);
John Garrya8d547b2016-01-26 02:47:03 +0800285 int max_command_entries;
John Garry6be6de12015-11-18 00:50:34 +0800286 int complete_hdr_size;
Xiang Chen235bfc72018-05-21 18:09:18 +0800287 struct scsi_host_template *sht;
Luo Jiaxingeb1c2b72018-12-19 23:56:40 +0800288
289 const struct hisi_sas_debugfs_reg *debugfs_reg_global;
290 const struct hisi_sas_debugfs_reg *debugfs_reg_port;
John Garry7eb78692015-11-18 00:50:31 +0800291};
292
293struct hisi_hba {
294 /* This must be the first element, used by SHOST_TO_SAS_HA */
295 struct sas_ha_struct *p;
296
John Garry11b75242017-06-14 23:33:17 +0800297 struct platform_device *platform_dev;
298 struct pci_dev *pci_dev;
299 struct device *dev;
300
Xiang Chend6a90002018-12-17 22:40:07 +0800301 int prot_mask;
302
John Garrye26b2f42015-11-18 00:50:32 +0800303 void __iomem *regs;
Xiaofei Tan6379c562018-01-18 00:46:53 +0800304 void __iomem *sgpio_regs;
John Garrye26b2f42015-11-18 00:50:32 +0800305 struct regmap *ctrl;
306 u32 ctrl_reset_reg;
307 u32 ctrl_reset_sts_reg;
308 u32 ctrl_clock_ena_reg;
John Garry3bc45af2016-10-04 19:11:11 +0800309 u32 refclk_frequency_mhz;
John Garry7eb78692015-11-18 00:50:31 +0800310 u8 sas_addr[SAS_ADDR_SIZE];
311
312 int n_phy;
John Garryfa42d802015-11-18 00:50:43 +0800313 spinlock_t lock;
Xiaofei Tand2fc4012018-05-31 20:50:44 +0800314 struct semaphore sem;
John Garry7eb78692015-11-18 00:50:31 +0800315
John Garryfa42d802015-11-18 00:50:43 +0800316 struct timer_list timer;
John Garry7e9080e2015-11-18 00:50:40 +0800317 struct workqueue_struct *wq;
John Garry257efd12015-11-18 00:50:36 +0800318
319 int slot_index_count;
Xiang Chenfa3be0f2018-05-21 18:09:14 +0800320 int last_slot_index;
Xiang Chen1b865182018-05-21 18:09:15 +0800321 int last_dev_id;
John Garry257efd12015-11-18 00:50:36 +0800322 unsigned long *slot_index_tags;
Xiaofei Tanc7b9d362017-04-10 21:21:56 +0800323 unsigned long reject_stp_links_msk;
John Garry257efd12015-11-18 00:50:36 +0800324
John Garry7eb78692015-11-18 00:50:31 +0800325 /* SCSI/SAS glue */
326 struct sas_ha_struct sha;
327 struct Scsi_Host *shost;
John Garry9101a072015-11-18 00:50:37 +0800328
329 struct hisi_sas_cq cq[HISI_SAS_MAX_QUEUES];
John Garry4fde02a2016-09-06 23:36:12 +0800330 struct hisi_sas_dq dq[HISI_SAS_MAX_QUEUES];
John Garry7eb78692015-11-18 00:50:31 +0800331 struct hisi_sas_phy phy[HISI_SAS_MAX_PHYS];
332 struct hisi_sas_port port[HISI_SAS_MAX_PHYS];
John Garrye26b2f42015-11-18 00:50:32 +0800333
334 int queue_count;
John Garry6be6de12015-11-18 00:50:34 +0800335
John Garryaf740db2015-11-18 00:50:41 +0800336 struct hisi_sas_device devices[HISI_SAS_MAX_DEVICES];
John Garry6be6de12015-11-18 00:50:34 +0800337 struct hisi_sas_cmd_hdr *cmd_hdr[HISI_SAS_MAX_QUEUES];
338 dma_addr_t cmd_hdr_dma[HISI_SAS_MAX_QUEUES];
339 void *complete_hdr[HISI_SAS_MAX_QUEUES];
340 dma_addr_t complete_hdr_dma[HISI_SAS_MAX_QUEUES];
341 struct hisi_sas_initial_fis *initial_fis;
342 dma_addr_t initial_fis_dma;
343 struct hisi_sas_itct *itct;
344 dma_addr_t itct_dma;
345 struct hisi_sas_iost *iost;
346 dma_addr_t iost_dma;
347 struct hisi_sas_breakpoint *breakpoint;
348 dma_addr_t breakpoint_dma;
349 struct hisi_sas_breakpoint *sata_breakpoint;
350 dma_addr_t sata_breakpoint_dma;
351 struct hisi_sas_slot *slot_info;
Xiang Chen06ec0fb2017-03-23 01:25:18 +0800352 unsigned long flags;
John Garry7eb78692015-11-18 00:50:31 +0800353 const struct hisi_sas_hw *hw; /* Low level hw interface */
Xiaofei Tan32ccba52017-04-10 21:21:57 +0800354 unsigned long sata_dev_bitmap[BITS_TO_LONGS(HISI_SAS_MAX_DEVICES)];
Xiang Chen06ec0fb2017-03-23 01:25:18 +0800355 struct work_struct rst_work;
Luo Jiaxing49159a52018-12-19 23:56:41 +0800356 struct work_struct debugfs_work;
Xiaofei Tan45222042018-07-18 22:14:28 +0800357 u32 phy_state;
Xiang Chen37359792018-11-09 22:06:34 +0800358 u32 intr_coal_ticks; /* Time of interrupt coalesce in us */
359 u32 intr_coal_count; /* Interrupt count to coalesce */
Luo Jiaxingef634642018-12-19 23:56:39 +0800360
Luo Jiaxingeb1c2b72018-12-19 23:56:40 +0800361 /* debugfs memories */
John Garry5b0eeac2019-01-25 22:22:28 +0800362 u32 *debugfs_global_reg;
363 u32 *debugfs_port_reg[HISI_SAS_MAX_PHYS];
Luo Jiaxingeb1c2b72018-12-19 23:56:40 +0800364 void *debugfs_complete_hdr[HISI_SAS_MAX_QUEUES];
365 struct hisi_sas_cmd_hdr *debugfs_cmd_hdr[HISI_SAS_MAX_QUEUES];
366 struct hisi_sas_iost *debugfs_iost;
367 struct hisi_sas_itct *debugfs_itct;
368
Luo Jiaxingef634642018-12-19 23:56:39 +0800369 struct dentry *debugfs_dir;
Luo Jiaxing49159a52018-12-19 23:56:41 +0800370 struct dentry *debugfs_dump_dentry;
John Garryc2c7e742019-01-25 22:22:27 +0800371 bool debugfs_snapshot;
John Garry7eb78692015-11-18 00:50:31 +0800372};
373
John Garryc799d6b2015-11-18 00:50:33 +0800374/* Generic HW DMA host memory structures */
375/* Delivery queue header */
376struct hisi_sas_cmd_hdr {
377 /* dw0 */
378 __le32 dw0;
379
380 /* dw1 */
381 __le32 dw1;
382
383 /* dw2 */
384 __le32 dw2;
385
386 /* dw3 */
387 __le32 transfer_tags;
388
389 /* dw4 */
390 __le32 data_transfer_len;
391
392 /* dw5 */
393 __le32 first_burst_num;
394
395 /* dw6 */
396 __le32 sg_len;
397
398 /* dw7 */
399 __le32 dw7;
400
401 /* dw8-9 */
402 __le64 cmd_table_addr;
403
404 /* dw10-11 */
405 __le64 sts_buffer_addr;
406
407 /* dw12-13 */
408 __le64 prd_table_addr;
409
410 /* dw14-15 */
411 __le64 dif_prd_table_addr;
412};
413
414struct hisi_sas_itct {
415 __le64 qw0;
416 __le64 sas_addr;
417 __le64 qw2;
418 __le64 qw3;
John Garry281e3bf2016-01-26 02:47:06 +0800419 __le64 qw4_15[12];
John Garryc799d6b2015-11-18 00:50:33 +0800420};
421
422struct hisi_sas_iost {
423 __le64 qw0;
424 __le64 qw1;
425 __le64 qw2;
426 __le64 qw3;
427};
428
429struct hisi_sas_err_record {
John Garry8d1eee72016-01-26 02:47:05 +0800430 u32 data[4];
John Garryc799d6b2015-11-18 00:50:33 +0800431};
432
433struct hisi_sas_initial_fis {
434 struct hisi_sas_err_record err_record;
435 struct dev_to_host_fis fis;
436 u32 rsvd[3];
437};
438
439struct hisi_sas_breakpoint {
Xiang Chen3297ded2017-10-24 23:51:35 +0800440 u8 data[128];
441};
442
443struct hisi_sas_sata_breakpoint {
444 struct hisi_sas_breakpoint tag[32];
John Garryc799d6b2015-11-18 00:50:33 +0800445};
446
447struct hisi_sas_sge {
448 __le64 addr;
449 __le32 page_ctrl_0;
450 __le32 page_ctrl_1;
451 __le32 data_len;
452 __le32 data_off;
453};
454
455struct hisi_sas_command_table_smp {
456 u8 bytes[44];
457};
458
459struct hisi_sas_command_table_stp {
460 struct host_to_dev_fis command_fis;
461 u8 dummy[12];
462 u8 atapi_cdb[ATAPI_CDB_LEN];
463};
464
Ming Lin65e86172016-04-04 14:48:10 -0700465#define HISI_SAS_SGE_PAGE_CNT SG_CHUNK_SIZE
John Garryc799d6b2015-11-18 00:50:33 +0800466struct hisi_sas_sge_page {
467 struct hisi_sas_sge sge[HISI_SAS_SGE_PAGE_CNT];
Xiaofei Tanf557e322017-06-29 21:02:14 +0800468} __aligned(16);
John Garryc799d6b2015-11-18 00:50:33 +0800469
470struct hisi_sas_command_table_ssp {
471 struct ssp_frame_hdr hdr;
472 union {
473 struct {
474 struct ssp_command_iu task;
Xiang Chena14da7a2018-05-02 23:56:27 +0800475 u32 prot[7];
John Garryc799d6b2015-11-18 00:50:33 +0800476 };
477 struct ssp_tmf_iu ssp_task;
478 struct xfer_rdy_iu xfer_rdy;
479 struct ssp_response_iu ssp_res;
480 } u;
481};
482
483union hisi_sas_command_table {
484 struct hisi_sas_command_table_ssp ssp;
485 struct hisi_sas_command_table_smp smp;
486 struct hisi_sas_command_table_stp stp;
Xiaofei Tanf557e322017-06-29 21:02:14 +0800487} __aligned(16);
488
489struct hisi_sas_status_buffer {
490 struct hisi_sas_err_record err;
491 u8 iu[1024];
492} __aligned(16);
493
494struct hisi_sas_slot_buf_table {
495 struct hisi_sas_status_buffer status_buffer;
496 union hisi_sas_command_table command_header;
497 struct hisi_sas_sge_page sge_page;
John Garryc799d6b2015-11-18 00:50:33 +0800498};
John Garry2e244f02017-03-23 01:25:17 +0800499
John Garrye21fe3a2017-06-14 23:33:20 +0800500extern struct scsi_transport_template *hisi_sas_stt;
Luo Jiaxingef634642018-12-19 23:56:39 +0800501
502extern bool hisi_sas_debugfs_enable;
503extern struct dentry *hisi_sas_debugfs_dir;
504
Xiang Chena25d0d32017-08-11 00:09:40 +0800505extern void hisi_sas_stop_phys(struct hisi_hba *hisi_hba);
John Garrye21fe3a2017-06-14 23:33:20 +0800506extern int hisi_sas_alloc(struct hisi_hba *hisi_hba, struct Scsi_Host *shost);
507extern void hisi_sas_free(struct hisi_hba *hisi_hba);
chenxiang468f4b82017-12-28 18:20:47 +0800508extern u8 hisi_sas_get_ata_protocol(struct host_to_dev_fis *fis,
509 int direction);
John Garry2e244f02017-03-23 01:25:17 +0800510extern struct hisi_sas_port *to_hisi_sas_port(struct asd_sas_port *sas_port);
Xiang Chen75904072017-06-14 23:33:15 +0800511extern void hisi_sas_sata_done(struct sas_task *task,
512 struct hisi_sas_slot *slot);
Xiang Chen318913c2017-06-14 23:33:16 +0800513extern int hisi_sas_get_ncq_tag(struct sas_task *task, u32 *tag);
John Garry0fa24c12017-06-14 23:33:18 +0800514extern int hisi_sas_get_fw_info(struct hisi_hba *hisi_hba);
John Garry9fb10b52015-11-18 00:50:44 +0800515extern int hisi_sas_probe(struct platform_device *pdev,
516 const struct hisi_sas_hw *ops);
517extern int hisi_sas_remove(struct platform_device *pdev);
John Garryc799d6b2015-11-18 00:50:33 +0800518
Xiang Chen235bfc72018-05-21 18:09:18 +0800519extern int hisi_sas_slave_configure(struct scsi_device *sdev);
520extern int hisi_sas_scan_finished(struct Scsi_Host *shost, unsigned long time);
521extern void hisi_sas_scan_start(struct Scsi_Host *shost);
Xiang Chen235bfc72018-05-21 18:09:18 +0800522extern int hisi_sas_host_reset(struct Scsi_Host *shost, int reset_type);
John Garry184a4632015-11-18 00:50:52 +0800523extern void hisi_sas_phy_down(struct hisi_hba *hisi_hba, int phy_no, int rdy);
John Garry27a3f222015-11-18 00:50:50 +0800524extern void hisi_sas_slot_task_free(struct hisi_hba *hisi_hba,
525 struct sas_task *task,
526 struct hisi_sas_slot *slot);
Xiang Chen06ec0fb2017-03-23 01:25:18 +0800527extern void hisi_sas_init_mem(struct hisi_hba *hisi_hba);
Xiaofei Tanb4241f02017-10-24 23:51:45 +0800528extern void hisi_sas_rst_work_handler(struct work_struct *work);
Xiaofei Tane402acd2017-12-09 01:16:38 +0800529extern void hisi_sas_sync_rst_work_handler(struct work_struct *work);
Xiaofei Tan571295f2017-10-24 23:51:47 +0800530extern void hisi_sas_kill_tasklets(struct hisi_hba *hisi_hba);
Xiaofei Tane537b622017-12-09 01:16:44 +0800531extern bool hisi_sas_notify_phy_event(struct hisi_sas_phy *phy,
532 enum hisi_sas_phy_event event);
Xiang Chen4d0951e2017-12-09 01:16:50 +0800533extern void hisi_sas_release_tasks(struct hisi_hba *hisi_hba);
Xiang Chenc2c1d9d2018-05-02 23:56:30 +0800534extern u8 hisi_sas_get_prog_phy_linkrate_mask(enum sas_linkrate max);
Xiaofei Tan45222042018-07-18 22:14:28 +0800535extern void hisi_sas_controller_reset_prepare(struct hisi_hba *hisi_hba);
536extern void hisi_sas_controller_reset_done(struct hisi_hba *hisi_hba);
Luo Jiaxingef634642018-12-19 23:56:39 +0800537extern void hisi_sas_debugfs_init(struct hisi_hba *hisi_hba);
538extern void hisi_sas_debugfs_exit(struct hisi_hba *hisi_hba);
Luo Jiaxing49159a52018-12-19 23:56:41 +0800539extern void hisi_sas_debugfs_work_handler(struct work_struct *work);
John Garrye8899fa2015-11-18 00:50:30 +0800540#endif