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