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 | |
| 15 | #include <linux/dmapool.h> |
| 16 | #include <linux/mfd/syscon.h> |
| 17 | #include <linux/module.h> |
| 18 | #include <linux/of_address.h> |
| 19 | #include <linux/of_irq.h> |
| 20 | #include <linux/platform_device.h> |
| 21 | #include <linux/regmap.h> |
| 22 | #include <scsi/libsas.h> |
| 23 | |
| 24 | #define DRV_VERSION "v1.0" |
| 25 | |
John Garry | 7eb7869 | 2015-11-18 00:50:31 +0800 | [diff] [blame] | 26 | #define HISI_SAS_MAX_PHYS 9 |
John Garry | 6be6de1 | 2015-11-18 00:50:34 +0800 | [diff] [blame] | 27 | #define HISI_SAS_MAX_QUEUES 32 |
| 28 | #define HISI_SAS_QUEUE_SLOTS 512 |
John Garry | 7eb7869 | 2015-11-18 00:50:31 +0800 | [diff] [blame] | 29 | #define HISI_SAS_MAX_ITCT_ENTRIES 4096 |
| 30 | #define HISI_SAS_MAX_DEVICES HISI_SAS_MAX_ITCT_ENTRIES |
| 31 | #define HISI_SAS_COMMAND_ENTRIES 8192 |
| 32 | |
John Garry | 6be6de1 | 2015-11-18 00:50:34 +0800 | [diff] [blame] | 33 | #define HISI_SAS_STATUS_BUF_SZ \ |
| 34 | (sizeof(struct hisi_sas_err_record) + 1024) |
| 35 | #define HISI_SAS_COMMAND_TABLE_SZ \ |
| 36 | (((sizeof(union hisi_sas_command_table)+3)/4)*4) |
| 37 | |
John Garry | 42e7a69 | 2015-11-18 00:50:49 +0800 | [diff] [blame^] | 38 | #define HISI_SAS_MAX_SSP_RESP_SZ (sizeof(struct ssp_frame_hdr) + 1024) |
| 39 | |
John Garry | e26b2f4 | 2015-11-18 00:50:32 +0800 | [diff] [blame] | 40 | #define HISI_SAS_NAME_LEN 32 |
| 41 | |
John Garry | af740db | 2015-11-18 00:50:41 +0800 | [diff] [blame] | 42 | |
John Garry | 07d7859 | 2015-11-18 00:50:47 +0800 | [diff] [blame] | 43 | enum { |
| 44 | PORT_TYPE_SAS = (1U << 1), |
| 45 | PORT_TYPE_SATA = (1U << 0), |
| 46 | }; |
| 47 | |
John Garry | af740db | 2015-11-18 00:50:41 +0800 | [diff] [blame] | 48 | enum dev_status { |
| 49 | HISI_SAS_DEV_NORMAL, |
| 50 | HISI_SAS_DEV_EH, |
| 51 | }; |
John Garry | 7eb7869 | 2015-11-18 00:50:31 +0800 | [diff] [blame] | 52 | struct hisi_sas_phy { |
John Garry | 976867e | 2015-11-18 00:50:42 +0800 | [diff] [blame] | 53 | struct hisi_hba *hisi_hba; |
| 54 | struct hisi_sas_port *port; |
John Garry | 7eb7869 | 2015-11-18 00:50:31 +0800 | [diff] [blame] | 55 | struct asd_sas_phy sas_phy; |
John Garry | 976867e | 2015-11-18 00:50:42 +0800 | [diff] [blame] | 56 | struct sas_identify identify; |
| 57 | struct timer_list timer; |
John Garry | 6613992 | 2015-11-18 00:50:48 +0800 | [diff] [blame] | 58 | struct work_struct phyup_ws; |
John Garry | 976867e | 2015-11-18 00:50:42 +0800 | [diff] [blame] | 59 | u64 port_id; /* from hw */ |
John Garry | 5d74242 | 2015-11-18 00:50:38 +0800 | [diff] [blame] | 60 | u64 dev_sas_addr; |
John Garry | 976867e | 2015-11-18 00:50:42 +0800 | [diff] [blame] | 61 | u64 phy_type; |
| 62 | u64 frame_rcvd_size; |
| 63 | u8 frame_rcvd[32]; |
| 64 | u8 phy_attached; |
| 65 | u8 reserved[3]; |
| 66 | enum sas_linkrate minimum_linkrate; |
| 67 | enum sas_linkrate maximum_linkrate; |
John Garry | 7eb7869 | 2015-11-18 00:50:31 +0800 | [diff] [blame] | 68 | }; |
| 69 | |
| 70 | struct hisi_sas_port { |
| 71 | struct asd_sas_port sas_port; |
John Garry | 976867e | 2015-11-18 00:50:42 +0800 | [diff] [blame] | 72 | u8 port_attached; |
| 73 | u8 id; /* from hw */ |
| 74 | struct list_head list; |
John Garry | 7eb7869 | 2015-11-18 00:50:31 +0800 | [diff] [blame] | 75 | }; |
| 76 | |
John Garry | 9101a07 | 2015-11-18 00:50:37 +0800 | [diff] [blame] | 77 | struct hisi_sas_cq { |
| 78 | struct hisi_hba *hisi_hba; |
| 79 | int id; |
| 80 | }; |
| 81 | |
John Garry | af740db | 2015-11-18 00:50:41 +0800 | [diff] [blame] | 82 | struct hisi_sas_device { |
| 83 | enum sas_device_type dev_type; |
| 84 | u64 device_id; |
John Garry | 42e7a69 | 2015-11-18 00:50:49 +0800 | [diff] [blame^] | 85 | u64 running_req; |
John Garry | af740db | 2015-11-18 00:50:41 +0800 | [diff] [blame] | 86 | u8 dev_status; |
| 87 | }; |
| 88 | |
John Garry | 6be6de1 | 2015-11-18 00:50:34 +0800 | [diff] [blame] | 89 | struct hisi_sas_slot { |
John Garry | 42e7a69 | 2015-11-18 00:50:49 +0800 | [diff] [blame^] | 90 | struct list_head entry; |
| 91 | struct sas_task *task; |
| 92 | struct hisi_sas_port *port; |
| 93 | u64 n_elem; |
| 94 | int dlvry_queue; |
| 95 | int dlvry_queue_slot; |
| 96 | int idx; |
| 97 | void *cmd_hdr; |
| 98 | dma_addr_t cmd_hdr_dma; |
| 99 | void *status_buffer; |
| 100 | dma_addr_t status_buffer_dma; |
| 101 | void *command_table; |
| 102 | dma_addr_t command_table_dma; |
| 103 | struct hisi_sas_sge_page *sge_page; |
| 104 | dma_addr_t sge_page_dma; |
| 105 | }; |
| 106 | |
| 107 | struct hisi_sas_tmf_task { |
| 108 | u8 tmf; |
| 109 | u16 tag_of_task_to_be_managed; |
John Garry | 6be6de1 | 2015-11-18 00:50:34 +0800 | [diff] [blame] | 110 | }; |
| 111 | |
John Garry | 7eb7869 | 2015-11-18 00:50:31 +0800 | [diff] [blame] | 112 | struct hisi_sas_hw { |
John Garry | 8ff1d57 | 2015-11-18 00:50:46 +0800 | [diff] [blame] | 113 | int (*hw_init)(struct hisi_hba *hisi_hba); |
John Garry | 6613992 | 2015-11-18 00:50:48 +0800 | [diff] [blame] | 114 | void (*sl_notify)(struct hisi_hba *hisi_hba, int phy_no); |
John Garry | 42e7a69 | 2015-11-18 00:50:49 +0800 | [diff] [blame^] | 115 | int (*get_free_slot)(struct hisi_hba *hisi_hba, int *q, int *s); |
| 116 | void (*start_delivery)(struct hisi_hba *hisi_hba); |
| 117 | int (*prep_ssp)(struct hisi_hba *hisi_hba, |
| 118 | struct hisi_sas_slot *slot, int is_tmf, |
| 119 | struct hisi_sas_tmf_task *tmf); |
John Garry | 6be6de1 | 2015-11-18 00:50:34 +0800 | [diff] [blame] | 120 | int complete_hdr_size; |
John Garry | 7eb7869 | 2015-11-18 00:50:31 +0800 | [diff] [blame] | 121 | }; |
| 122 | |
| 123 | struct hisi_hba { |
| 124 | /* This must be the first element, used by SHOST_TO_SAS_HA */ |
| 125 | struct sas_ha_struct *p; |
| 126 | |
| 127 | struct platform_device *pdev; |
John Garry | e26b2f4 | 2015-11-18 00:50:32 +0800 | [diff] [blame] | 128 | void __iomem *regs; |
| 129 | struct regmap *ctrl; |
| 130 | u32 ctrl_reset_reg; |
| 131 | u32 ctrl_reset_sts_reg; |
| 132 | u32 ctrl_clock_ena_reg; |
John Garry | 7eb7869 | 2015-11-18 00:50:31 +0800 | [diff] [blame] | 133 | u8 sas_addr[SAS_ADDR_SIZE]; |
| 134 | |
| 135 | int n_phy; |
John Garry | fa42d80 | 2015-11-18 00:50:43 +0800 | [diff] [blame] | 136 | spinlock_t lock; |
John Garry | 7eb7869 | 2015-11-18 00:50:31 +0800 | [diff] [blame] | 137 | |
John Garry | fa42d80 | 2015-11-18 00:50:43 +0800 | [diff] [blame] | 138 | struct timer_list timer; |
John Garry | 7e9080e | 2015-11-18 00:50:40 +0800 | [diff] [blame] | 139 | struct workqueue_struct *wq; |
John Garry | 257efd1 | 2015-11-18 00:50:36 +0800 | [diff] [blame] | 140 | |
| 141 | int slot_index_count; |
| 142 | unsigned long *slot_index_tags; |
| 143 | |
John Garry | 7eb7869 | 2015-11-18 00:50:31 +0800 | [diff] [blame] | 144 | /* SCSI/SAS glue */ |
| 145 | struct sas_ha_struct sha; |
| 146 | struct Scsi_Host *shost; |
John Garry | 9101a07 | 2015-11-18 00:50:37 +0800 | [diff] [blame] | 147 | |
| 148 | struct hisi_sas_cq cq[HISI_SAS_MAX_QUEUES]; |
John Garry | 7eb7869 | 2015-11-18 00:50:31 +0800 | [diff] [blame] | 149 | struct hisi_sas_phy phy[HISI_SAS_MAX_PHYS]; |
| 150 | struct hisi_sas_port port[HISI_SAS_MAX_PHYS]; |
John Garry | e26b2f4 | 2015-11-18 00:50:32 +0800 | [diff] [blame] | 151 | |
| 152 | int queue_count; |
John Garry | 42e7a69 | 2015-11-18 00:50:49 +0800 | [diff] [blame^] | 153 | int queue; |
John Garry | e26b2f4 | 2015-11-18 00:50:32 +0800 | [diff] [blame] | 154 | char *int_names; |
John Garry | 42e7a69 | 2015-11-18 00:50:49 +0800 | [diff] [blame^] | 155 | struct hisi_sas_slot *slot_prep; |
John Garry | 6be6de1 | 2015-11-18 00:50:34 +0800 | [diff] [blame] | 156 | |
| 157 | struct dma_pool *sge_page_pool; |
John Garry | af740db | 2015-11-18 00:50:41 +0800 | [diff] [blame] | 158 | struct hisi_sas_device devices[HISI_SAS_MAX_DEVICES]; |
John Garry | 6be6de1 | 2015-11-18 00:50:34 +0800 | [diff] [blame] | 159 | struct dma_pool *command_table_pool; |
| 160 | struct dma_pool *status_buffer_pool; |
| 161 | struct hisi_sas_cmd_hdr *cmd_hdr[HISI_SAS_MAX_QUEUES]; |
| 162 | dma_addr_t cmd_hdr_dma[HISI_SAS_MAX_QUEUES]; |
| 163 | void *complete_hdr[HISI_SAS_MAX_QUEUES]; |
| 164 | dma_addr_t complete_hdr_dma[HISI_SAS_MAX_QUEUES]; |
| 165 | struct hisi_sas_initial_fis *initial_fis; |
| 166 | dma_addr_t initial_fis_dma; |
| 167 | struct hisi_sas_itct *itct; |
| 168 | dma_addr_t itct_dma; |
| 169 | struct hisi_sas_iost *iost; |
| 170 | dma_addr_t iost_dma; |
| 171 | struct hisi_sas_breakpoint *breakpoint; |
| 172 | dma_addr_t breakpoint_dma; |
| 173 | struct hisi_sas_breakpoint *sata_breakpoint; |
| 174 | dma_addr_t sata_breakpoint_dma; |
| 175 | struct hisi_sas_slot *slot_info; |
John Garry | 7eb7869 | 2015-11-18 00:50:31 +0800 | [diff] [blame] | 176 | const struct hisi_sas_hw *hw; /* Low level hw interface */ |
| 177 | }; |
| 178 | |
John Garry | c799d6b | 2015-11-18 00:50:33 +0800 | [diff] [blame] | 179 | /* Generic HW DMA host memory structures */ |
| 180 | /* Delivery queue header */ |
| 181 | struct hisi_sas_cmd_hdr { |
| 182 | /* dw0 */ |
| 183 | __le32 dw0; |
| 184 | |
| 185 | /* dw1 */ |
| 186 | __le32 dw1; |
| 187 | |
| 188 | /* dw2 */ |
| 189 | __le32 dw2; |
| 190 | |
| 191 | /* dw3 */ |
| 192 | __le32 transfer_tags; |
| 193 | |
| 194 | /* dw4 */ |
| 195 | __le32 data_transfer_len; |
| 196 | |
| 197 | /* dw5 */ |
| 198 | __le32 first_burst_num; |
| 199 | |
| 200 | /* dw6 */ |
| 201 | __le32 sg_len; |
| 202 | |
| 203 | /* dw7 */ |
| 204 | __le32 dw7; |
| 205 | |
| 206 | /* dw8-9 */ |
| 207 | __le64 cmd_table_addr; |
| 208 | |
| 209 | /* dw10-11 */ |
| 210 | __le64 sts_buffer_addr; |
| 211 | |
| 212 | /* dw12-13 */ |
| 213 | __le64 prd_table_addr; |
| 214 | |
| 215 | /* dw14-15 */ |
| 216 | __le64 dif_prd_table_addr; |
| 217 | }; |
| 218 | |
| 219 | struct hisi_sas_itct { |
| 220 | __le64 qw0; |
| 221 | __le64 sas_addr; |
| 222 | __le64 qw2; |
| 223 | __le64 qw3; |
| 224 | __le64 qw4; |
| 225 | __le64 qw_sata_ncq0_3; |
| 226 | __le64 qw_sata_ncq7_4; |
| 227 | __le64 qw_sata_ncq11_8; |
| 228 | __le64 qw_sata_ncq15_12; |
| 229 | __le64 qw_sata_ncq19_16; |
| 230 | __le64 qw_sata_ncq23_20; |
| 231 | __le64 qw_sata_ncq27_24; |
| 232 | __le64 qw_sata_ncq31_28; |
| 233 | __le64 qw_non_ncq_iptt; |
| 234 | __le64 qw_rsvd0; |
| 235 | __le64 qw_rsvd1; |
| 236 | }; |
| 237 | |
| 238 | struct hisi_sas_iost { |
| 239 | __le64 qw0; |
| 240 | __le64 qw1; |
| 241 | __le64 qw2; |
| 242 | __le64 qw3; |
| 243 | }; |
| 244 | |
| 245 | struct hisi_sas_err_record { |
| 246 | /* dw0 */ |
| 247 | __le32 dma_err_type; |
| 248 | |
| 249 | /* dw1 */ |
| 250 | __le32 trans_tx_fail_type; |
| 251 | |
| 252 | /* dw2 */ |
| 253 | __le32 trans_rx_fail_type; |
| 254 | |
| 255 | /* dw3 */ |
| 256 | u32 rsvd; |
| 257 | }; |
| 258 | |
| 259 | struct hisi_sas_initial_fis { |
| 260 | struct hisi_sas_err_record err_record; |
| 261 | struct dev_to_host_fis fis; |
| 262 | u32 rsvd[3]; |
| 263 | }; |
| 264 | |
| 265 | struct hisi_sas_breakpoint { |
| 266 | u8 data[128]; /*io128 byte*/ |
| 267 | }; |
| 268 | |
| 269 | struct hisi_sas_sge { |
| 270 | __le64 addr; |
| 271 | __le32 page_ctrl_0; |
| 272 | __le32 page_ctrl_1; |
| 273 | __le32 data_len; |
| 274 | __le32 data_off; |
| 275 | }; |
| 276 | |
| 277 | struct hisi_sas_command_table_smp { |
| 278 | u8 bytes[44]; |
| 279 | }; |
| 280 | |
| 281 | struct hisi_sas_command_table_stp { |
| 282 | struct host_to_dev_fis command_fis; |
| 283 | u8 dummy[12]; |
| 284 | u8 atapi_cdb[ATAPI_CDB_LEN]; |
| 285 | }; |
| 286 | |
John Garry | 7eb7869 | 2015-11-18 00:50:31 +0800 | [diff] [blame] | 287 | #define HISI_SAS_SGE_PAGE_CNT SCSI_MAX_SG_SEGMENTS |
John Garry | c799d6b | 2015-11-18 00:50:33 +0800 | [diff] [blame] | 288 | struct hisi_sas_sge_page { |
| 289 | struct hisi_sas_sge sge[HISI_SAS_SGE_PAGE_CNT]; |
| 290 | }; |
| 291 | |
| 292 | struct hisi_sas_command_table_ssp { |
| 293 | struct ssp_frame_hdr hdr; |
| 294 | union { |
| 295 | struct { |
| 296 | struct ssp_command_iu task; |
| 297 | u32 prot[6]; |
| 298 | }; |
| 299 | struct ssp_tmf_iu ssp_task; |
| 300 | struct xfer_rdy_iu xfer_rdy; |
| 301 | struct ssp_response_iu ssp_res; |
| 302 | } u; |
| 303 | }; |
| 304 | |
| 305 | union hisi_sas_command_table { |
| 306 | struct hisi_sas_command_table_ssp ssp; |
| 307 | struct hisi_sas_command_table_smp smp; |
| 308 | struct hisi_sas_command_table_stp stp; |
| 309 | }; |
John Garry | 9fb10b5 | 2015-11-18 00:50:44 +0800 | [diff] [blame] | 310 | extern int hisi_sas_probe(struct platform_device *pdev, |
| 311 | const struct hisi_sas_hw *ops); |
| 312 | extern int hisi_sas_remove(struct platform_device *pdev); |
John Garry | c799d6b | 2015-11-18 00:50:33 +0800 | [diff] [blame] | 313 | |
John Garry | e8899fa | 2015-11-18 00:50:30 +0800 | [diff] [blame] | 314 | #endif |