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 | e26b2f4 | 2015-11-18 00:50:32 +0800 | [diff] [blame] | 38 | #define HISI_SAS_NAME_LEN 32 |
| 39 | |
John Garry | af740db | 2015-11-18 00:50:41 +0800 | [diff] [blame] | 40 | |
| 41 | enum dev_status { |
| 42 | HISI_SAS_DEV_NORMAL, |
| 43 | HISI_SAS_DEV_EH, |
| 44 | }; |
John Garry | 7eb7869 | 2015-11-18 00:50:31 +0800 | [diff] [blame] | 45 | struct hisi_sas_phy { |
John Garry | 976867e | 2015-11-18 00:50:42 +0800 | [diff] [blame] | 46 | struct hisi_hba *hisi_hba; |
| 47 | struct hisi_sas_port *port; |
John Garry | 7eb7869 | 2015-11-18 00:50:31 +0800 | [diff] [blame] | 48 | struct asd_sas_phy sas_phy; |
John Garry | 976867e | 2015-11-18 00:50:42 +0800 | [diff] [blame] | 49 | struct sas_identify identify; |
| 50 | struct timer_list timer; |
| 51 | u64 port_id; /* from hw */ |
John Garry | 5d74242 | 2015-11-18 00:50:38 +0800 | [diff] [blame] | 52 | u64 dev_sas_addr; |
John Garry | 976867e | 2015-11-18 00:50:42 +0800 | [diff] [blame] | 53 | u64 phy_type; |
| 54 | u64 frame_rcvd_size; |
| 55 | u8 frame_rcvd[32]; |
| 56 | u8 phy_attached; |
| 57 | u8 reserved[3]; |
| 58 | enum sas_linkrate minimum_linkrate; |
| 59 | enum sas_linkrate maximum_linkrate; |
John Garry | 7eb7869 | 2015-11-18 00:50:31 +0800 | [diff] [blame] | 60 | }; |
| 61 | |
| 62 | struct hisi_sas_port { |
| 63 | struct asd_sas_port sas_port; |
John Garry | 976867e | 2015-11-18 00:50:42 +0800 | [diff] [blame] | 64 | u8 port_attached; |
| 65 | u8 id; /* from hw */ |
| 66 | struct list_head list; |
John Garry | 7eb7869 | 2015-11-18 00:50:31 +0800 | [diff] [blame] | 67 | }; |
| 68 | |
John Garry | 9101a07 | 2015-11-18 00:50:37 +0800 | [diff] [blame] | 69 | struct hisi_sas_cq { |
| 70 | struct hisi_hba *hisi_hba; |
| 71 | int id; |
| 72 | }; |
| 73 | |
John Garry | af740db | 2015-11-18 00:50:41 +0800 | [diff] [blame] | 74 | struct hisi_sas_device { |
| 75 | enum sas_device_type dev_type; |
| 76 | u64 device_id; |
| 77 | u8 dev_status; |
| 78 | }; |
| 79 | |
John Garry | 6be6de1 | 2015-11-18 00:50:34 +0800 | [diff] [blame] | 80 | struct hisi_sas_slot { |
| 81 | }; |
| 82 | |
John Garry | 7eb7869 | 2015-11-18 00:50:31 +0800 | [diff] [blame] | 83 | struct hisi_sas_hw { |
John Garry | 6be6de1 | 2015-11-18 00:50:34 +0800 | [diff] [blame] | 84 | int complete_hdr_size; |
John Garry | 7eb7869 | 2015-11-18 00:50:31 +0800 | [diff] [blame] | 85 | }; |
| 86 | |
| 87 | struct hisi_hba { |
| 88 | /* This must be the first element, used by SHOST_TO_SAS_HA */ |
| 89 | struct sas_ha_struct *p; |
| 90 | |
| 91 | struct platform_device *pdev; |
John Garry | e26b2f4 | 2015-11-18 00:50:32 +0800 | [diff] [blame] | 92 | void __iomem *regs; |
| 93 | struct regmap *ctrl; |
| 94 | u32 ctrl_reset_reg; |
| 95 | u32 ctrl_reset_sts_reg; |
| 96 | u32 ctrl_clock_ena_reg; |
John Garry | 7eb7869 | 2015-11-18 00:50:31 +0800 | [diff] [blame] | 97 | u8 sas_addr[SAS_ADDR_SIZE]; |
| 98 | |
| 99 | int n_phy; |
John Garry | fa42d80 | 2015-11-18 00:50:43 +0800 | [diff] [blame^] | 100 | spinlock_t lock; |
John Garry | 7eb7869 | 2015-11-18 00:50:31 +0800 | [diff] [blame] | 101 | |
John Garry | fa42d80 | 2015-11-18 00:50:43 +0800 | [diff] [blame^] | 102 | struct timer_list timer; |
John Garry | 7e9080e | 2015-11-18 00:50:40 +0800 | [diff] [blame] | 103 | struct workqueue_struct *wq; |
John Garry | 257efd1 | 2015-11-18 00:50:36 +0800 | [diff] [blame] | 104 | |
| 105 | int slot_index_count; |
| 106 | unsigned long *slot_index_tags; |
| 107 | |
John Garry | 7eb7869 | 2015-11-18 00:50:31 +0800 | [diff] [blame] | 108 | /* SCSI/SAS glue */ |
| 109 | struct sas_ha_struct sha; |
| 110 | struct Scsi_Host *shost; |
John Garry | 9101a07 | 2015-11-18 00:50:37 +0800 | [diff] [blame] | 111 | |
| 112 | struct hisi_sas_cq cq[HISI_SAS_MAX_QUEUES]; |
John Garry | 7eb7869 | 2015-11-18 00:50:31 +0800 | [diff] [blame] | 113 | struct hisi_sas_phy phy[HISI_SAS_MAX_PHYS]; |
| 114 | struct hisi_sas_port port[HISI_SAS_MAX_PHYS]; |
John Garry | e26b2f4 | 2015-11-18 00:50:32 +0800 | [diff] [blame] | 115 | |
| 116 | int queue_count; |
| 117 | char *int_names; |
John Garry | 6be6de1 | 2015-11-18 00:50:34 +0800 | [diff] [blame] | 118 | |
| 119 | struct dma_pool *sge_page_pool; |
John Garry | af740db | 2015-11-18 00:50:41 +0800 | [diff] [blame] | 120 | struct hisi_sas_device devices[HISI_SAS_MAX_DEVICES]; |
John Garry | 6be6de1 | 2015-11-18 00:50:34 +0800 | [diff] [blame] | 121 | struct dma_pool *command_table_pool; |
| 122 | struct dma_pool *status_buffer_pool; |
| 123 | struct hisi_sas_cmd_hdr *cmd_hdr[HISI_SAS_MAX_QUEUES]; |
| 124 | dma_addr_t cmd_hdr_dma[HISI_SAS_MAX_QUEUES]; |
| 125 | void *complete_hdr[HISI_SAS_MAX_QUEUES]; |
| 126 | dma_addr_t complete_hdr_dma[HISI_SAS_MAX_QUEUES]; |
| 127 | struct hisi_sas_initial_fis *initial_fis; |
| 128 | dma_addr_t initial_fis_dma; |
| 129 | struct hisi_sas_itct *itct; |
| 130 | dma_addr_t itct_dma; |
| 131 | struct hisi_sas_iost *iost; |
| 132 | dma_addr_t iost_dma; |
| 133 | struct hisi_sas_breakpoint *breakpoint; |
| 134 | dma_addr_t breakpoint_dma; |
| 135 | struct hisi_sas_breakpoint *sata_breakpoint; |
| 136 | dma_addr_t sata_breakpoint_dma; |
| 137 | struct hisi_sas_slot *slot_info; |
John Garry | 7eb7869 | 2015-11-18 00:50:31 +0800 | [diff] [blame] | 138 | const struct hisi_sas_hw *hw; /* Low level hw interface */ |
| 139 | }; |
| 140 | |
John Garry | c799d6b | 2015-11-18 00:50:33 +0800 | [diff] [blame] | 141 | /* Generic HW DMA host memory structures */ |
| 142 | /* Delivery queue header */ |
| 143 | struct hisi_sas_cmd_hdr { |
| 144 | /* dw0 */ |
| 145 | __le32 dw0; |
| 146 | |
| 147 | /* dw1 */ |
| 148 | __le32 dw1; |
| 149 | |
| 150 | /* dw2 */ |
| 151 | __le32 dw2; |
| 152 | |
| 153 | /* dw3 */ |
| 154 | __le32 transfer_tags; |
| 155 | |
| 156 | /* dw4 */ |
| 157 | __le32 data_transfer_len; |
| 158 | |
| 159 | /* dw5 */ |
| 160 | __le32 first_burst_num; |
| 161 | |
| 162 | /* dw6 */ |
| 163 | __le32 sg_len; |
| 164 | |
| 165 | /* dw7 */ |
| 166 | __le32 dw7; |
| 167 | |
| 168 | /* dw8-9 */ |
| 169 | __le64 cmd_table_addr; |
| 170 | |
| 171 | /* dw10-11 */ |
| 172 | __le64 sts_buffer_addr; |
| 173 | |
| 174 | /* dw12-13 */ |
| 175 | __le64 prd_table_addr; |
| 176 | |
| 177 | /* dw14-15 */ |
| 178 | __le64 dif_prd_table_addr; |
| 179 | }; |
| 180 | |
| 181 | struct hisi_sas_itct { |
| 182 | __le64 qw0; |
| 183 | __le64 sas_addr; |
| 184 | __le64 qw2; |
| 185 | __le64 qw3; |
| 186 | __le64 qw4; |
| 187 | __le64 qw_sata_ncq0_3; |
| 188 | __le64 qw_sata_ncq7_4; |
| 189 | __le64 qw_sata_ncq11_8; |
| 190 | __le64 qw_sata_ncq15_12; |
| 191 | __le64 qw_sata_ncq19_16; |
| 192 | __le64 qw_sata_ncq23_20; |
| 193 | __le64 qw_sata_ncq27_24; |
| 194 | __le64 qw_sata_ncq31_28; |
| 195 | __le64 qw_non_ncq_iptt; |
| 196 | __le64 qw_rsvd0; |
| 197 | __le64 qw_rsvd1; |
| 198 | }; |
| 199 | |
| 200 | struct hisi_sas_iost { |
| 201 | __le64 qw0; |
| 202 | __le64 qw1; |
| 203 | __le64 qw2; |
| 204 | __le64 qw3; |
| 205 | }; |
| 206 | |
| 207 | struct hisi_sas_err_record { |
| 208 | /* dw0 */ |
| 209 | __le32 dma_err_type; |
| 210 | |
| 211 | /* dw1 */ |
| 212 | __le32 trans_tx_fail_type; |
| 213 | |
| 214 | /* dw2 */ |
| 215 | __le32 trans_rx_fail_type; |
| 216 | |
| 217 | /* dw3 */ |
| 218 | u32 rsvd; |
| 219 | }; |
| 220 | |
| 221 | struct hisi_sas_initial_fis { |
| 222 | struct hisi_sas_err_record err_record; |
| 223 | struct dev_to_host_fis fis; |
| 224 | u32 rsvd[3]; |
| 225 | }; |
| 226 | |
| 227 | struct hisi_sas_breakpoint { |
| 228 | u8 data[128]; /*io128 byte*/ |
| 229 | }; |
| 230 | |
| 231 | struct hisi_sas_sge { |
| 232 | __le64 addr; |
| 233 | __le32 page_ctrl_0; |
| 234 | __le32 page_ctrl_1; |
| 235 | __le32 data_len; |
| 236 | __le32 data_off; |
| 237 | }; |
| 238 | |
| 239 | struct hisi_sas_command_table_smp { |
| 240 | u8 bytes[44]; |
| 241 | }; |
| 242 | |
| 243 | struct hisi_sas_command_table_stp { |
| 244 | struct host_to_dev_fis command_fis; |
| 245 | u8 dummy[12]; |
| 246 | u8 atapi_cdb[ATAPI_CDB_LEN]; |
| 247 | }; |
| 248 | |
John Garry | 7eb7869 | 2015-11-18 00:50:31 +0800 | [diff] [blame] | 249 | #define HISI_SAS_SGE_PAGE_CNT SCSI_MAX_SG_SEGMENTS |
John Garry | c799d6b | 2015-11-18 00:50:33 +0800 | [diff] [blame] | 250 | struct hisi_sas_sge_page { |
| 251 | struct hisi_sas_sge sge[HISI_SAS_SGE_PAGE_CNT]; |
| 252 | }; |
| 253 | |
| 254 | struct hisi_sas_command_table_ssp { |
| 255 | struct ssp_frame_hdr hdr; |
| 256 | union { |
| 257 | struct { |
| 258 | struct ssp_command_iu task; |
| 259 | u32 prot[6]; |
| 260 | }; |
| 261 | struct ssp_tmf_iu ssp_task; |
| 262 | struct xfer_rdy_iu xfer_rdy; |
| 263 | struct ssp_response_iu ssp_res; |
| 264 | } u; |
| 265 | }; |
| 266 | |
| 267 | union hisi_sas_command_table { |
| 268 | struct hisi_sas_command_table_ssp ssp; |
| 269 | struct hisi_sas_command_table_smp smp; |
| 270 | struct hisi_sas_command_table_stp stp; |
| 271 | }; |
| 272 | |
John Garry | e8899fa | 2015-11-18 00:50:30 +0800 | [diff] [blame] | 273 | #endif |