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