John Garry | e8899fa | 2015-11-18 00:50:30 +0800 | [diff] [blame] | 1 | /* |
| 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 Garry | 4d558c7 | 2016-02-04 02:26:08 +0800 | [diff] [blame] | 15 | #include <linux/acpi.h> |
John Garry | 3bc45af | 2016-10-04 19:11:11 +0800 | [diff] [blame] | 16 | #include <linux/clk.h> |
Luo Jiaxing | ef63464 | 2018-12-19 23:56:39 +0800 | [diff] [blame] | 17 | #include <linux/debugfs.h> |
John Garry | e8899fa | 2015-11-18 00:50:30 +0800 | [diff] [blame] | 18 | #include <linux/dmapool.h> |
Xiang Chen | a25d0d3 | 2017-08-11 00:09:40 +0800 | [diff] [blame] | 19 | #include <linux/iopoll.h> |
Xiang Chen | 2ba5afb | 2018-05-31 20:50:48 +0800 | [diff] [blame] | 20 | #include <linux/lcm.h> |
John Garry | e8899fa | 2015-11-18 00:50:30 +0800 | [diff] [blame] | 21 | #include <linux/mfd/syscon.h> |
| 22 | #include <linux/module.h> |
| 23 | #include <linux/of_address.h> |
John Garry | 11b7524 | 2017-06-14 23:33:17 +0800 | [diff] [blame] | 24 | #include <linux/pci.h> |
John Garry | e8899fa | 2015-11-18 00:50:30 +0800 | [diff] [blame] | 25 | #include <linux/platform_device.h> |
John Garry | 4d558c7 | 2016-02-04 02:26:08 +0800 | [diff] [blame] | 26 | #include <linux/property.h> |
John Garry | e8899fa | 2015-11-18 00:50:30 +0800 | [diff] [blame] | 27 | #include <linux/regmap.h> |
John Garry | 6f2ff1a | 2016-01-26 02:47:20 +0800 | [diff] [blame] | 28 | #include <scsi/sas_ata.h> |
John Garry | e8899fa | 2015-11-18 00:50:30 +0800 | [diff] [blame] | 29 | #include <scsi/libsas.h> |
| 30 | |
John Garry | 7eb7869 | 2015-11-18 00:50:31 +0800 | [diff] [blame] | 31 | #define HISI_SAS_MAX_PHYS 9 |
John Garry | 6be6de1 | 2015-11-18 00:50:34 +0800 | [diff] [blame] | 32 | #define HISI_SAS_MAX_QUEUES 32 |
| 33 | #define HISI_SAS_QUEUE_SLOTS 512 |
Xiang Chen | 3297ded | 2017-10-24 23:51:35 +0800 | [diff] [blame] | 34 | #define HISI_SAS_MAX_ITCT_ENTRIES 1024 |
John Garry | 7eb7869 | 2015-11-18 00:50:31 +0800 | [diff] [blame] | 35 | #define HISI_SAS_MAX_DEVICES HISI_SAS_MAX_ITCT_ENTRIES |
Xiang Chen | 06ec0fb | 2017-03-23 01:25:18 +0800 | [diff] [blame] | 36 | #define HISI_SAS_RESET_BIT 0 |
Xiaofei Tan | 917d3bd | 2017-08-11 00:09:26 +0800 | [diff] [blame] | 37 | #define HISI_SAS_REJECT_CMD_BIT 1 |
Xiang Chen | 784b46b | 2018-09-24 23:06:33 +0800 | [diff] [blame] | 38 | #define HISI_SAS_RESERVED_IPTT_CNT 96 |
John Garry | 7eb7869 | 2015-11-18 00:50:31 +0800 | [diff] [blame] | 39 | |
Xiaofei Tan | f557e32 | 2017-06-29 21:02:14 +0800 | [diff] [blame] | 40 | #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 Garry | 6be6de1 | 2015-11-18 00:50:34 +0800 | [diff] [blame] | 58 | |
John Garry | 42e7a69 | 2015-11-18 00:50:49 +0800 | [diff] [blame] | 59 | #define HISI_SAS_MAX_SSP_RESP_SZ (sizeof(struct ssp_frame_hdr) + 1024) |
John Garry | 66ee999 | 2015-11-18 00:50:54 +0800 | [diff] [blame] | 60 | #define HISI_SAS_MAX_SMP_RESP_SZ 1028 |
John Garry | 6f2ff1a | 2016-01-26 02:47:20 +0800 | [diff] [blame] | 61 | #define HISI_SAS_MAX_STP_RESP_SZ 28 |
John Garry | 42e7a69 | 2015-11-18 00:50:49 +0800 | [diff] [blame] | 62 | |
John Garry | 98bf39f | 2016-01-26 02:47:02 +0800 | [diff] [blame] | 63 | #define DEV_IS_EXPANDER(type) \ |
| 64 | ((type == SAS_EDGE_EXPANDER_DEVICE) || \ |
| 65 | (type == SAS_FANOUT_EXPANDER_DEVICE)) |
| 66 | |
Xiang Chen | 6c7bb8a | 2017-06-14 23:33:14 +0800 | [diff] [blame] | 67 | #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 Chen | d6a9000 | 2018-12-17 22:40:07 +0800 | [diff] [blame] | 73 | #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 Garry | abda97c | 2015-11-18 00:50:51 +0800 | [diff] [blame] | 79 | struct hisi_hba; |
John Garry | af740db | 2015-11-18 00:50:41 +0800 | [diff] [blame] | 80 | |
John Garry | 07d7859 | 2015-11-18 00:50:47 +0800 | [diff] [blame] | 81 | enum { |
| 82 | PORT_TYPE_SAS = (1U << 1), |
| 83 | PORT_TYPE_SATA = (1U << 0), |
| 84 | }; |
| 85 | |
John Garry | af740db | 2015-11-18 00:50:41 +0800 | [diff] [blame] | 86 | enum dev_status { |
| 87 | HISI_SAS_DEV_NORMAL, |
| 88 | HISI_SAS_DEV_EH, |
| 89 | }; |
John Garry | abda97c | 2015-11-18 00:50:51 +0800 | [diff] [blame] | 90 | |
John Garry | 441c274 | 2016-08-24 19:05:47 +0800 | [diff] [blame] | 91 | enum { |
| 92 | HISI_SAS_INT_ABT_CMD = 0, |
| 93 | HISI_SAS_INT_ABT_DEV = 1, |
| 94 | }; |
| 95 | |
John Garry | abda97c | 2015-11-18 00:50:51 +0800 | [diff] [blame] | 96 | enum 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 Garry | 2b38335 | 2017-08-11 00:09:30 +0800 | [diff] [blame] | 102 | struct hisi_sas_hw_error { |
| 103 | u32 irq_msk; |
| 104 | u32 msk; |
| 105 | int shift; |
| 106 | const char *msg; |
| 107 | int reg; |
Shiju Jose | 729428c | 2017-10-24 23:51:39 +0800 | [diff] [blame] | 108 | const struct hisi_sas_hw_error *sub; |
John Garry | 2b38335 | 2017-08-11 00:09:30 +0800 | [diff] [blame] | 109 | }; |
| 110 | |
Xiaofei Tan | e402acd | 2017-12-09 01:16:38 +0800 | [diff] [blame] | 111 | struct 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 | |
| 131 | enum hisi_sas_bit_err_type { |
| 132 | HISI_SAS_ERR_SINGLE_BIT_ECC = 0x0, |
| 133 | HISI_SAS_ERR_MULTI_BIT_ECC = 0x1, |
| 134 | }; |
| 135 | |
Xiaofei Tan | e537b62 | 2017-12-09 01:16:44 +0800 | [diff] [blame] | 136 | enum hisi_sas_phy_event { |
| 137 | HISI_PHYE_PHY_UP = 0U, |
Xiaofei Tan | 057c3d1 | 2017-12-09 01:16:45 +0800 | [diff] [blame] | 138 | HISI_PHYE_LINK_RESET, |
Xiaofei Tan | e537b62 | 2017-12-09 01:16:44 +0800 | [diff] [blame] | 139 | HISI_PHYES_NUM, |
| 140 | }; |
| 141 | |
John Garry | 7eb7869 | 2015-11-18 00:50:31 +0800 | [diff] [blame] | 142 | struct hisi_sas_phy { |
Xiaofei Tan | e537b62 | 2017-12-09 01:16:44 +0800 | [diff] [blame] | 143 | struct work_struct works[HISI_PHYES_NUM]; |
John Garry | 976867e | 2015-11-18 00:50:42 +0800 | [diff] [blame] | 144 | struct hisi_hba *hisi_hba; |
| 145 | struct hisi_sas_port *port; |
John Garry | 7eb7869 | 2015-11-18 00:50:31 +0800 | [diff] [blame] | 146 | struct asd_sas_phy sas_phy; |
John Garry | 976867e | 2015-11-18 00:50:42 +0800 | [diff] [blame] | 147 | struct sas_identify identify; |
Xiang Chen | 3e1fb1b | 2018-05-21 18:09:25 +0800 | [diff] [blame] | 148 | struct completion *reset_completion; |
| 149 | spinlock_t lock; |
John Garry | 976867e | 2015-11-18 00:50:42 +0800 | [diff] [blame] | 150 | u64 port_id; /* from hw */ |
John Garry | 976867e | 2015-11-18 00:50:42 +0800 | [diff] [blame] | 151 | u64 frame_rcvd_size; |
| 152 | u8 frame_rcvd[32]; |
| 153 | u8 phy_attached; |
Xiang Chen | 3e1fb1b | 2018-05-21 18:09:25 +0800 | [diff] [blame] | 154 | u8 in_reset; |
| 155 | u8 reserved[2]; |
John Garry | d0ef10c | 2017-06-26 18:27:28 +0800 | [diff] [blame] | 156 | u32 phy_type; |
John Garry | 976867e | 2015-11-18 00:50:42 +0800 | [diff] [blame] | 157 | enum sas_linkrate minimum_linkrate; |
| 158 | enum sas_linkrate maximum_linkrate; |
John Garry | 7eb7869 | 2015-11-18 00:50:31 +0800 | [diff] [blame] | 159 | }; |
| 160 | |
| 161 | struct hisi_sas_port { |
| 162 | struct asd_sas_port sas_port; |
John Garry | 976867e | 2015-11-18 00:50:42 +0800 | [diff] [blame] | 163 | u8 port_attached; |
| 164 | u8 id; /* from hw */ |
John Garry | 7eb7869 | 2015-11-18 00:50:31 +0800 | [diff] [blame] | 165 | }; |
| 166 | |
John Garry | 9101a07 | 2015-11-18 00:50:37 +0800 | [diff] [blame] | 167 | struct hisi_sas_cq { |
| 168 | struct hisi_hba *hisi_hba; |
John Garry | d177c40 | 2017-01-03 20:24:48 +0800 | [diff] [blame] | 169 | struct tasklet_struct tasklet; |
John Garry | e6c346f | 2016-09-06 23:36:11 +0800 | [diff] [blame] | 170 | int rd_point; |
John Garry | 9101a07 | 2015-11-18 00:50:37 +0800 | [diff] [blame] | 171 | int id; |
| 172 | }; |
| 173 | |
John Garry | 4fde02a | 2016-09-06 23:36:12 +0800 | [diff] [blame] | 174 | struct hisi_sas_dq { |
| 175 | struct hisi_hba *hisi_hba; |
Xiang Chen | fa222db | 2018-05-09 23:10:48 +0800 | [diff] [blame] | 176 | struct list_head list; |
Xiang Chen | b1a4941 | 2017-06-14 23:33:13 +0800 | [diff] [blame] | 177 | spinlock_t lock; |
John Garry | 4fde02a | 2016-09-06 23:36:12 +0800 | [diff] [blame] | 178 | int wr_point; |
| 179 | int id; |
| 180 | }; |
| 181 | |
John Garry | af740db | 2015-11-18 00:50:41 +0800 | [diff] [blame] | 182 | struct hisi_sas_device { |
John Garry | abda97c | 2015-11-18 00:50:51 +0800 | [diff] [blame] | 183 | struct hisi_hba *hisi_hba; |
| 184 | struct domain_device *sas_device; |
Xiang Chen | 640acc9 | 2017-08-11 00:09:33 +0800 | [diff] [blame] | 185 | struct completion *completion; |
Xiang Chen | b1a4941 | 2017-06-14 23:33:13 +0800 | [diff] [blame] | 186 | struct hisi_sas_dq *dq; |
John Garry | 405314d | 2017-03-23 01:25:21 +0800 | [diff] [blame] | 187 | struct list_head list; |
John Garry | ad60483 | 2017-06-14 23:33:12 +0800 | [diff] [blame] | 188 | enum sas_device_type dev_type; |
| 189 | int device_id; |
Xiaofei Tan | 32ccba5 | 2017-04-10 21:21:57 +0800 | [diff] [blame] | 190 | int sata_idx; |
John Garry | ad60483 | 2017-06-14 23:33:12 +0800 | [diff] [blame] | 191 | u8 dev_status; |
John Garry | af740db | 2015-11-18 00:50:41 +0800 | [diff] [blame] | 192 | }; |
| 193 | |
Xiaofei Tan | 78bd2b4 | 2018-05-21 18:09:21 +0800 | [diff] [blame] | 194 | struct hisi_sas_tmf_task { |
Xiaofei Tan | b09fcd0 | 2018-05-21 18:09:22 +0800 | [diff] [blame] | 195 | int force_phy; |
| 196 | int phy_id; |
Xiaofei Tan | 78bd2b4 | 2018-05-21 18:09:21 +0800 | [diff] [blame] | 197 | u8 tmf; |
| 198 | u16 tag_of_task_to_be_managed; |
| 199 | }; |
| 200 | |
John Garry | 6be6de1 | 2015-11-18 00:50:34 +0800 | [diff] [blame] | 201 | struct hisi_sas_slot { |
John Garry | 42e7a69 | 2015-11-18 00:50:49 +0800 | [diff] [blame] | 202 | struct list_head entry; |
Xiang Chen | fa222db | 2018-05-09 23:10:48 +0800 | [diff] [blame] | 203 | struct list_head delivery; |
John Garry | 42e7a69 | 2015-11-18 00:50:49 +0800 | [diff] [blame] | 204 | struct sas_task *task; |
| 205 | struct hisi_sas_port *port; |
| 206 | u64 n_elem; |
| 207 | int dlvry_queue; |
| 208 | int dlvry_queue_slot; |
John Garry | 27a3f22 | 2015-11-18 00:50:50 +0800 | [diff] [blame] | 209 | int cmplt_queue; |
| 210 | int cmplt_queue_slot; |
John Garry | cac9b2a | 2016-02-25 17:42:11 +0800 | [diff] [blame] | 211 | int abort; |
Xiang Chen | fa222db | 2018-05-09 23:10:48 +0800 | [diff] [blame] | 212 | int ready; |
John Garry | 42e7a69 | 2015-11-18 00:50:49 +0800 | [diff] [blame] | 213 | void *cmd_hdr; |
| 214 | dma_addr_t cmd_hdr_dma; |
John Garry | 0844a3f | 2017-04-10 21:21:59 +0800 | [diff] [blame] | 215 | struct timer_list internal_abort_timer; |
Xiang Chen | cd938e5 | 2018-05-02 23:56:26 +0800 | [diff] [blame] | 216 | bool is_internal; |
Xiaofei Tan | 78bd2b4 | 2018-05-21 18:09:21 +0800 | [diff] [blame] | 217 | struct hisi_sas_tmf_task *tmf; |
Xiang Chen | 2ba5afb | 2018-05-31 20:50:48 +0800 | [diff] [blame] | 218 | /* Do not reorder/change members after here */ |
| 219 | void *buf; |
| 220 | dma_addr_t buf_dma; |
John Garry | 735bcc7 | 2018-12-06 21:34:40 +0800 | [diff] [blame] | 221 | u16 idx; |
John Garry | 6be6de1 | 2015-11-18 00:50:34 +0800 | [diff] [blame] | 222 | }; |
| 223 | |
Luo Jiaxing | caefac1 | 2018-12-19 23:56:42 +0800 | [diff] [blame] | 224 | #define HISI_SAS_DEBUGFS_REG(x) {#x, x} |
| 225 | |
| 226 | struct hisi_sas_debugfs_reg_lu { |
| 227 | char *name; |
| 228 | int off; |
| 229 | }; |
| 230 | |
Luo Jiaxing | eb1c2b7 | 2018-12-19 23:56:40 +0800 | [diff] [blame] | 231 | struct hisi_sas_debugfs_reg { |
Luo Jiaxing | caefac1 | 2018-12-19 23:56:42 +0800 | [diff] [blame] | 232 | const struct hisi_sas_debugfs_reg_lu *lu; |
Luo Jiaxing | eb1c2b7 | 2018-12-19 23:56:40 +0800 | [diff] [blame] | 233 | int count; |
Luo Jiaxing | 49159a5 | 2018-12-19 23:56:41 +0800 | [diff] [blame] | 234 | 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 Jiaxing | eb1c2b7 | 2018-12-19 23:56:40 +0800 | [diff] [blame] | 240 | }; |
| 241 | |
John Garry | 7eb7869 | 2015-11-18 00:50:31 +0800 | [diff] [blame] | 242 | struct hisi_sas_hw { |
John Garry | 8ff1d57 | 2015-11-18 00:50:46 +0800 | [diff] [blame] | 243 | int (*hw_init)(struct hisi_hba *hisi_hba); |
John Garry | abda97c | 2015-11-18 00:50:51 +0800 | [diff] [blame] | 244 | void (*setup_itct)(struct hisi_hba *hisi_hba, |
| 245 | struct hisi_sas_device *device); |
Xiang Chen | 784b46b | 2018-09-24 23:06:33 +0800 | [diff] [blame] | 246 | int (*slot_index_alloc)(struct hisi_hba *hisi_hba, |
John Garry | 685b6d6 | 2016-04-15 21:36:36 +0800 | [diff] [blame] | 247 | struct domain_device *device); |
| 248 | struct hisi_sas_device *(*alloc_dev)(struct domain_device *device); |
John Garry | 6613992 | 2015-11-18 00:50:48 +0800 | [diff] [blame] | 249 | void (*sl_notify)(struct hisi_hba *hisi_hba, int phy_no); |
Xiang Chen | b1a4941 | 2017-06-14 23:33:13 +0800 | [diff] [blame] | 250 | int (*get_free_slot)(struct hisi_hba *hisi_hba, struct hisi_sas_dq *dq); |
| 251 | void (*start_delivery)(struct hisi_sas_dq *dq); |
Xiang Chen | a2b3820 | 2018-05-09 23:10:46 +0800 | [diff] [blame] | 252 | void (*prep_ssp)(struct hisi_hba *hisi_hba, |
Xiaofei Tan | 78bd2b4 | 2018-05-21 18:09:21 +0800 | [diff] [blame] | 253 | struct hisi_sas_slot *slot); |
Xiang Chen | a2b3820 | 2018-05-09 23:10:46 +0800 | [diff] [blame] | 254 | void (*prep_smp)(struct hisi_hba *hisi_hba, |
John Garry | 66ee999 | 2015-11-18 00:50:54 +0800 | [diff] [blame] | 255 | struct hisi_sas_slot *slot); |
Xiang Chen | a2b3820 | 2018-05-09 23:10:46 +0800 | [diff] [blame] | 256 | void (*prep_stp)(struct hisi_hba *hisi_hba, |
John Garry | 6f2ff1a | 2016-01-26 02:47:20 +0800 | [diff] [blame] | 257 | struct hisi_sas_slot *slot); |
Xiang Chen | a2b3820 | 2018-05-09 23:10:46 +0800 | [diff] [blame] | 258 | void (*prep_abort)(struct hisi_hba *hisi_hba, |
John Garry | 441c274 | 2016-08-24 19:05:47 +0800 | [diff] [blame] | 259 | struct hisi_sas_slot *slot, |
| 260 | int device_id, int abort_flag, int tag_to_abort); |
John Garry | 27a3f22 | 2015-11-18 00:50:50 +0800 | [diff] [blame] | 261 | int (*slot_complete)(struct hisi_hba *hisi_hba, |
John Garry | 405314d | 2017-03-23 01:25:21 +0800 | [diff] [blame] | 262 | struct hisi_sas_slot *slot); |
John Garry | 396b804 | 2017-03-23 01:25:19 +0800 | [diff] [blame] | 263 | void (*phys_init)(struct hisi_hba *hisi_hba); |
Xiang Chen | 1eb8eea | 2017-10-24 23:51:36 +0800 | [diff] [blame] | 264 | void (*phy_start)(struct hisi_hba *hisi_hba, int phy_no); |
John Garry | e4189d5 | 2015-11-18 00:50:57 +0800 | [diff] [blame] | 265 | 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 Tan | c52108c | 2017-08-11 00:09:29 +0800 | [diff] [blame] | 267 | void (*get_events)(struct hisi_hba *hisi_hba, int phy_no); |
Xiang Chen | 2ae7578 | 2016-11-07 20:48:40 +0800 | [diff] [blame] | 268 | 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 Tan | 0258141 | 2017-12-09 01:16:34 +0800 | [diff] [blame] | 271 | void (*clear_itct)(struct hisi_hba *hisi_hba, |
John Garry | 27a3f22 | 2015-11-18 00:50:50 +0800 | [diff] [blame] | 272 | struct hisi_sas_device *dev); |
Xiaofei Tan | 0258141 | 2017-12-09 01:16:34 +0800 | [diff] [blame] | 273 | void (*free_device)(struct hisi_sas_device *sas_dev); |
John Garry | 184a463 | 2015-11-18 00:50:52 +0800 | [diff] [blame] | 274 | int (*get_wideport_bitmap)(struct hisi_hba *hisi_hba, int port_id); |
Xiang Chen | d30ff26 | 2017-06-14 23:33:32 +0800 | [diff] [blame] | 275 | void (*dereg_device)(struct hisi_hba *hisi_hba, |
| 276 | struct domain_device *device); |
Xiang Chen | 06ec0fb | 2017-03-23 01:25:18 +0800 | [diff] [blame] | 277 | int (*soft_reset)(struct hisi_hba *hisi_hba); |
Xiaofei Tan | 917d3bd | 2017-08-11 00:09:26 +0800 | [diff] [blame] | 278 | u32 (*get_phys_state)(struct hisi_hba *hisi_hba); |
Xiaofei Tan | 6379c56 | 2018-01-18 00:46:53 +0800 | [diff] [blame] | 279 | int (*write_gpio)(struct hisi_hba *hisi_hba, u8 reg_type, |
| 280 | u8 reg_index, u8 reg_count, u8 *write_data); |
Luo Jiaxing | 49159a5 | 2018-12-19 23:56:41 +0800 | [diff] [blame] | 281 | 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 Garry | a8d547b | 2016-01-26 02:47:03 +0800 | [diff] [blame] | 285 | int max_command_entries; |
John Garry | 6be6de1 | 2015-11-18 00:50:34 +0800 | [diff] [blame] | 286 | int complete_hdr_size; |
Xiang Chen | 235bfc7 | 2018-05-21 18:09:18 +0800 | [diff] [blame] | 287 | struct scsi_host_template *sht; |
Luo Jiaxing | eb1c2b7 | 2018-12-19 23:56:40 +0800 | [diff] [blame] | 288 | |
| 289 | const struct hisi_sas_debugfs_reg *debugfs_reg_global; |
| 290 | const struct hisi_sas_debugfs_reg *debugfs_reg_port; |
John Garry | 7eb7869 | 2015-11-18 00:50:31 +0800 | [diff] [blame] | 291 | }; |
| 292 | |
| 293 | struct hisi_hba { |
| 294 | /* This must be the first element, used by SHOST_TO_SAS_HA */ |
| 295 | struct sas_ha_struct *p; |
| 296 | |
John Garry | 11b7524 | 2017-06-14 23:33:17 +0800 | [diff] [blame] | 297 | struct platform_device *platform_dev; |
| 298 | struct pci_dev *pci_dev; |
| 299 | struct device *dev; |
| 300 | |
Xiang Chen | d6a9000 | 2018-12-17 22:40:07 +0800 | [diff] [blame] | 301 | int prot_mask; |
| 302 | |
John Garry | e26b2f4 | 2015-11-18 00:50:32 +0800 | [diff] [blame] | 303 | void __iomem *regs; |
Xiaofei Tan | 6379c56 | 2018-01-18 00:46:53 +0800 | [diff] [blame] | 304 | void __iomem *sgpio_regs; |
John Garry | e26b2f4 | 2015-11-18 00:50:32 +0800 | [diff] [blame] | 305 | struct regmap *ctrl; |
| 306 | u32 ctrl_reset_reg; |
| 307 | u32 ctrl_reset_sts_reg; |
| 308 | u32 ctrl_clock_ena_reg; |
John Garry | 3bc45af | 2016-10-04 19:11:11 +0800 | [diff] [blame] | 309 | u32 refclk_frequency_mhz; |
John Garry | 7eb7869 | 2015-11-18 00:50:31 +0800 | [diff] [blame] | 310 | u8 sas_addr[SAS_ADDR_SIZE]; |
| 311 | |
| 312 | int n_phy; |
John Garry | fa42d80 | 2015-11-18 00:50:43 +0800 | [diff] [blame] | 313 | spinlock_t lock; |
Xiaofei Tan | d2fc401 | 2018-05-31 20:50:44 +0800 | [diff] [blame] | 314 | struct semaphore sem; |
John Garry | 7eb7869 | 2015-11-18 00:50:31 +0800 | [diff] [blame] | 315 | |
John Garry | fa42d80 | 2015-11-18 00:50:43 +0800 | [diff] [blame] | 316 | struct timer_list timer; |
John Garry | 7e9080e | 2015-11-18 00:50:40 +0800 | [diff] [blame] | 317 | struct workqueue_struct *wq; |
John Garry | 257efd1 | 2015-11-18 00:50:36 +0800 | [diff] [blame] | 318 | |
| 319 | int slot_index_count; |
Xiang Chen | fa3be0f | 2018-05-21 18:09:14 +0800 | [diff] [blame] | 320 | int last_slot_index; |
Xiang Chen | 1b86518 | 2018-05-21 18:09:15 +0800 | [diff] [blame] | 321 | int last_dev_id; |
John Garry | 257efd1 | 2015-11-18 00:50:36 +0800 | [diff] [blame] | 322 | unsigned long *slot_index_tags; |
Xiaofei Tan | c7b9d36 | 2017-04-10 21:21:56 +0800 | [diff] [blame] | 323 | unsigned long reject_stp_links_msk; |
John Garry | 257efd1 | 2015-11-18 00:50:36 +0800 | [diff] [blame] | 324 | |
John Garry | 7eb7869 | 2015-11-18 00:50:31 +0800 | [diff] [blame] | 325 | /* SCSI/SAS glue */ |
| 326 | struct sas_ha_struct sha; |
| 327 | struct Scsi_Host *shost; |
John Garry | 9101a07 | 2015-11-18 00:50:37 +0800 | [diff] [blame] | 328 | |
| 329 | struct hisi_sas_cq cq[HISI_SAS_MAX_QUEUES]; |
John Garry | 4fde02a | 2016-09-06 23:36:12 +0800 | [diff] [blame] | 330 | struct hisi_sas_dq dq[HISI_SAS_MAX_QUEUES]; |
John Garry | 7eb7869 | 2015-11-18 00:50:31 +0800 | [diff] [blame] | 331 | struct hisi_sas_phy phy[HISI_SAS_MAX_PHYS]; |
| 332 | struct hisi_sas_port port[HISI_SAS_MAX_PHYS]; |
John Garry | e26b2f4 | 2015-11-18 00:50:32 +0800 | [diff] [blame] | 333 | |
| 334 | int queue_count; |
John Garry | 6be6de1 | 2015-11-18 00:50:34 +0800 | [diff] [blame] | 335 | |
John Garry | af740db | 2015-11-18 00:50:41 +0800 | [diff] [blame] | 336 | struct hisi_sas_device devices[HISI_SAS_MAX_DEVICES]; |
John Garry | 6be6de1 | 2015-11-18 00:50:34 +0800 | [diff] [blame] | 337 | 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 Chen | 06ec0fb | 2017-03-23 01:25:18 +0800 | [diff] [blame] | 352 | unsigned long flags; |
John Garry | 7eb7869 | 2015-11-18 00:50:31 +0800 | [diff] [blame] | 353 | const struct hisi_sas_hw *hw; /* Low level hw interface */ |
Xiaofei Tan | 32ccba5 | 2017-04-10 21:21:57 +0800 | [diff] [blame] | 354 | unsigned long sata_dev_bitmap[BITS_TO_LONGS(HISI_SAS_MAX_DEVICES)]; |
Xiang Chen | 06ec0fb | 2017-03-23 01:25:18 +0800 | [diff] [blame] | 355 | struct work_struct rst_work; |
Luo Jiaxing | 49159a5 | 2018-12-19 23:56:41 +0800 | [diff] [blame] | 356 | struct work_struct debugfs_work; |
Xiaofei Tan | 4522204 | 2018-07-18 22:14:28 +0800 | [diff] [blame] | 357 | u32 phy_state; |
Xiang Chen | 3735979 | 2018-11-09 22:06:34 +0800 | [diff] [blame] | 358 | u32 intr_coal_ticks; /* Time of interrupt coalesce in us */ |
| 359 | u32 intr_coal_count; /* Interrupt count to coalesce */ |
Luo Jiaxing | ef63464 | 2018-12-19 23:56:39 +0800 | [diff] [blame] | 360 | |
Luo Jiaxing | eb1c2b7 | 2018-12-19 23:56:40 +0800 | [diff] [blame] | 361 | /* debugfs memories */ |
John Garry | 5b0eeac | 2019-01-25 22:22:28 +0800 | [diff] [blame^] | 362 | u32 *debugfs_global_reg; |
| 363 | u32 *debugfs_port_reg[HISI_SAS_MAX_PHYS]; |
Luo Jiaxing | eb1c2b7 | 2018-12-19 23:56:40 +0800 | [diff] [blame] | 364 | 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 Jiaxing | ef63464 | 2018-12-19 23:56:39 +0800 | [diff] [blame] | 369 | struct dentry *debugfs_dir; |
Luo Jiaxing | 49159a5 | 2018-12-19 23:56:41 +0800 | [diff] [blame] | 370 | struct dentry *debugfs_dump_dentry; |
John Garry | c2c7e74 | 2019-01-25 22:22:27 +0800 | [diff] [blame] | 371 | bool debugfs_snapshot; |
John Garry | 7eb7869 | 2015-11-18 00:50:31 +0800 | [diff] [blame] | 372 | }; |
| 373 | |
John Garry | c799d6b | 2015-11-18 00:50:33 +0800 | [diff] [blame] | 374 | /* Generic HW DMA host memory structures */ |
| 375 | /* Delivery queue header */ |
| 376 | struct 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 | |
| 414 | struct hisi_sas_itct { |
| 415 | __le64 qw0; |
| 416 | __le64 sas_addr; |
| 417 | __le64 qw2; |
| 418 | __le64 qw3; |
John Garry | 281e3bf | 2016-01-26 02:47:06 +0800 | [diff] [blame] | 419 | __le64 qw4_15[12]; |
John Garry | c799d6b | 2015-11-18 00:50:33 +0800 | [diff] [blame] | 420 | }; |
| 421 | |
| 422 | struct hisi_sas_iost { |
| 423 | __le64 qw0; |
| 424 | __le64 qw1; |
| 425 | __le64 qw2; |
| 426 | __le64 qw3; |
| 427 | }; |
| 428 | |
| 429 | struct hisi_sas_err_record { |
John Garry | 8d1eee7 | 2016-01-26 02:47:05 +0800 | [diff] [blame] | 430 | u32 data[4]; |
John Garry | c799d6b | 2015-11-18 00:50:33 +0800 | [diff] [blame] | 431 | }; |
| 432 | |
| 433 | struct 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 | |
| 439 | struct hisi_sas_breakpoint { |
Xiang Chen | 3297ded | 2017-10-24 23:51:35 +0800 | [diff] [blame] | 440 | u8 data[128]; |
| 441 | }; |
| 442 | |
| 443 | struct hisi_sas_sata_breakpoint { |
| 444 | struct hisi_sas_breakpoint tag[32]; |
John Garry | c799d6b | 2015-11-18 00:50:33 +0800 | [diff] [blame] | 445 | }; |
| 446 | |
| 447 | struct 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 | |
| 455 | struct hisi_sas_command_table_smp { |
| 456 | u8 bytes[44]; |
| 457 | }; |
| 458 | |
| 459 | struct 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 Lin | 65e8617 | 2016-04-04 14:48:10 -0700 | [diff] [blame] | 465 | #define HISI_SAS_SGE_PAGE_CNT SG_CHUNK_SIZE |
John Garry | c799d6b | 2015-11-18 00:50:33 +0800 | [diff] [blame] | 466 | struct hisi_sas_sge_page { |
| 467 | struct hisi_sas_sge sge[HISI_SAS_SGE_PAGE_CNT]; |
Xiaofei Tan | f557e32 | 2017-06-29 21:02:14 +0800 | [diff] [blame] | 468 | } __aligned(16); |
John Garry | c799d6b | 2015-11-18 00:50:33 +0800 | [diff] [blame] | 469 | |
| 470 | struct hisi_sas_command_table_ssp { |
| 471 | struct ssp_frame_hdr hdr; |
| 472 | union { |
| 473 | struct { |
| 474 | struct ssp_command_iu task; |
Xiang Chen | a14da7a | 2018-05-02 23:56:27 +0800 | [diff] [blame] | 475 | u32 prot[7]; |
John Garry | c799d6b | 2015-11-18 00:50:33 +0800 | [diff] [blame] | 476 | }; |
| 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 | |
| 483 | union 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 Tan | f557e32 | 2017-06-29 21:02:14 +0800 | [diff] [blame] | 487 | } __aligned(16); |
| 488 | |
| 489 | struct hisi_sas_status_buffer { |
| 490 | struct hisi_sas_err_record err; |
| 491 | u8 iu[1024]; |
| 492 | } __aligned(16); |
| 493 | |
| 494 | struct 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 Garry | c799d6b | 2015-11-18 00:50:33 +0800 | [diff] [blame] | 498 | }; |
John Garry | 2e244f0 | 2017-03-23 01:25:17 +0800 | [diff] [blame] | 499 | |
John Garry | e21fe3a | 2017-06-14 23:33:20 +0800 | [diff] [blame] | 500 | extern struct scsi_transport_template *hisi_sas_stt; |
Luo Jiaxing | ef63464 | 2018-12-19 23:56:39 +0800 | [diff] [blame] | 501 | |
| 502 | extern bool hisi_sas_debugfs_enable; |
| 503 | extern struct dentry *hisi_sas_debugfs_dir; |
| 504 | |
Xiang Chen | a25d0d3 | 2017-08-11 00:09:40 +0800 | [diff] [blame] | 505 | extern void hisi_sas_stop_phys(struct hisi_hba *hisi_hba); |
John Garry | e21fe3a | 2017-06-14 23:33:20 +0800 | [diff] [blame] | 506 | extern int hisi_sas_alloc(struct hisi_hba *hisi_hba, struct Scsi_Host *shost); |
| 507 | extern void hisi_sas_free(struct hisi_hba *hisi_hba); |
chenxiang | 468f4b8 | 2017-12-28 18:20:47 +0800 | [diff] [blame] | 508 | extern u8 hisi_sas_get_ata_protocol(struct host_to_dev_fis *fis, |
| 509 | int direction); |
John Garry | 2e244f0 | 2017-03-23 01:25:17 +0800 | [diff] [blame] | 510 | extern struct hisi_sas_port *to_hisi_sas_port(struct asd_sas_port *sas_port); |
Xiang Chen | 7590407 | 2017-06-14 23:33:15 +0800 | [diff] [blame] | 511 | extern void hisi_sas_sata_done(struct sas_task *task, |
| 512 | struct hisi_sas_slot *slot); |
Xiang Chen | 318913c | 2017-06-14 23:33:16 +0800 | [diff] [blame] | 513 | extern int hisi_sas_get_ncq_tag(struct sas_task *task, u32 *tag); |
John Garry | 0fa24c1 | 2017-06-14 23:33:18 +0800 | [diff] [blame] | 514 | extern int hisi_sas_get_fw_info(struct hisi_hba *hisi_hba); |
John Garry | 9fb10b5 | 2015-11-18 00:50:44 +0800 | [diff] [blame] | 515 | extern int hisi_sas_probe(struct platform_device *pdev, |
| 516 | const struct hisi_sas_hw *ops); |
| 517 | extern int hisi_sas_remove(struct platform_device *pdev); |
John Garry | c799d6b | 2015-11-18 00:50:33 +0800 | [diff] [blame] | 518 | |
Xiang Chen | 235bfc7 | 2018-05-21 18:09:18 +0800 | [diff] [blame] | 519 | extern int hisi_sas_slave_configure(struct scsi_device *sdev); |
| 520 | extern int hisi_sas_scan_finished(struct Scsi_Host *shost, unsigned long time); |
| 521 | extern void hisi_sas_scan_start(struct Scsi_Host *shost); |
Xiang Chen | 235bfc7 | 2018-05-21 18:09:18 +0800 | [diff] [blame] | 522 | extern int hisi_sas_host_reset(struct Scsi_Host *shost, int reset_type); |
John Garry | 184a463 | 2015-11-18 00:50:52 +0800 | [diff] [blame] | 523 | extern void hisi_sas_phy_down(struct hisi_hba *hisi_hba, int phy_no, int rdy); |
John Garry | 27a3f22 | 2015-11-18 00:50:50 +0800 | [diff] [blame] | 524 | extern void hisi_sas_slot_task_free(struct hisi_hba *hisi_hba, |
| 525 | struct sas_task *task, |
| 526 | struct hisi_sas_slot *slot); |
Xiang Chen | 06ec0fb | 2017-03-23 01:25:18 +0800 | [diff] [blame] | 527 | extern void hisi_sas_init_mem(struct hisi_hba *hisi_hba); |
Xiaofei Tan | b4241f0 | 2017-10-24 23:51:45 +0800 | [diff] [blame] | 528 | extern void hisi_sas_rst_work_handler(struct work_struct *work); |
Xiaofei Tan | e402acd | 2017-12-09 01:16:38 +0800 | [diff] [blame] | 529 | extern void hisi_sas_sync_rst_work_handler(struct work_struct *work); |
Xiaofei Tan | 571295f | 2017-10-24 23:51:47 +0800 | [diff] [blame] | 530 | extern void hisi_sas_kill_tasklets(struct hisi_hba *hisi_hba); |
Xiaofei Tan | e537b62 | 2017-12-09 01:16:44 +0800 | [diff] [blame] | 531 | extern bool hisi_sas_notify_phy_event(struct hisi_sas_phy *phy, |
| 532 | enum hisi_sas_phy_event event); |
Xiang Chen | 4d0951e | 2017-12-09 01:16:50 +0800 | [diff] [blame] | 533 | extern void hisi_sas_release_tasks(struct hisi_hba *hisi_hba); |
Xiang Chen | c2c1d9d | 2018-05-02 23:56:30 +0800 | [diff] [blame] | 534 | extern u8 hisi_sas_get_prog_phy_linkrate_mask(enum sas_linkrate max); |
Xiaofei Tan | 4522204 | 2018-07-18 22:14:28 +0800 | [diff] [blame] | 535 | extern void hisi_sas_controller_reset_prepare(struct hisi_hba *hisi_hba); |
| 536 | extern void hisi_sas_controller_reset_done(struct hisi_hba *hisi_hba); |
Luo Jiaxing | ef63464 | 2018-12-19 23:56:39 +0800 | [diff] [blame] | 537 | extern void hisi_sas_debugfs_init(struct hisi_hba *hisi_hba); |
| 538 | extern void hisi_sas_debugfs_exit(struct hisi_hba *hisi_hba); |
Luo Jiaxing | 49159a5 | 2018-12-19 23:56:41 +0800 | [diff] [blame] | 539 | extern void hisi_sas_debugfs_work_handler(struct work_struct *work); |
John Garry | e8899fa | 2015-11-18 00:50:30 +0800 | [diff] [blame] | 540 | #endif |