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> |
John Garry | e8899fa | 2015-11-18 00:50:30 +0800 | [diff] [blame] | 17 | #include <linux/dmapool.h> |
| 18 | #include <linux/mfd/syscon.h> |
| 19 | #include <linux/module.h> |
| 20 | #include <linux/of_address.h> |
John Garry | 11b7524 | 2017-06-14 23:33:17 +0800 | [diff] [blame] | 21 | #include <linux/pci.h> |
John Garry | e8899fa | 2015-11-18 00:50:30 +0800 | [diff] [blame] | 22 | #include <linux/platform_device.h> |
John Garry | 4d558c7 | 2016-02-04 02:26:08 +0800 | [diff] [blame] | 23 | #include <linux/property.h> |
John Garry | e8899fa | 2015-11-18 00:50:30 +0800 | [diff] [blame] | 24 | #include <linux/regmap.h> |
John Garry | 6f2ff1a | 2016-01-26 02:47:20 +0800 | [diff] [blame] | 25 | #include <scsi/sas_ata.h> |
John Garry | e8899fa | 2015-11-18 00:50:30 +0800 | [diff] [blame] | 26 | #include <scsi/libsas.h> |
| 27 | |
John Garry | 6328d90 | 2016-08-24 19:05:54 +0800 | [diff] [blame] | 28 | #define DRV_VERSION "v1.6" |
John Garry | e8899fa | 2015-11-18 00:50:30 +0800 | [diff] [blame] | 29 | |
John Garry | 7eb7869 | 2015-11-18 00:50:31 +0800 | [diff] [blame] | 30 | #define HISI_SAS_MAX_PHYS 9 |
John Garry | 6be6de1 | 2015-11-18 00:50:34 +0800 | [diff] [blame] | 31 | #define HISI_SAS_MAX_QUEUES 32 |
| 32 | #define HISI_SAS_QUEUE_SLOTS 512 |
John Garry | 5560e9f | 2016-01-26 02:47:04 +0800 | [diff] [blame] | 33 | #define HISI_SAS_MAX_ITCT_ENTRIES 2048 |
John Garry | 7eb7869 | 2015-11-18 00:50:31 +0800 | [diff] [blame] | 34 | #define HISI_SAS_MAX_DEVICES HISI_SAS_MAX_ITCT_ENTRIES |
Xiang Chen | 06ec0fb | 2017-03-23 01:25:18 +0800 | [diff] [blame] | 35 | #define HISI_SAS_RESET_BIT 0 |
Xiaofei Tan | 917d3bd | 2017-08-11 00:09:26 +0800 | [diff] [blame] | 36 | #define HISI_SAS_REJECT_CMD_BIT 1 |
John Garry | 7eb7869 | 2015-11-18 00:50:31 +0800 | [diff] [blame] | 37 | |
Xiaofei Tan | f557e32 | 2017-06-29 21:02:14 +0800 | [diff] [blame] | 38 | #define HISI_SAS_STATUS_BUF_SZ (sizeof(struct hisi_sas_status_buffer)) |
| 39 | #define HISI_SAS_COMMAND_TABLE_SZ (sizeof(union hisi_sas_command_table)) |
| 40 | |
| 41 | #define hisi_sas_status_buf_addr(buf) \ |
| 42 | (buf + offsetof(struct hisi_sas_slot_buf_table, status_buffer)) |
| 43 | #define hisi_sas_status_buf_addr_mem(slot) hisi_sas_status_buf_addr(slot->buf) |
| 44 | #define hisi_sas_status_buf_addr_dma(slot) \ |
| 45 | hisi_sas_status_buf_addr(slot->buf_dma) |
| 46 | |
| 47 | #define hisi_sas_cmd_hdr_addr(buf) \ |
| 48 | (buf + offsetof(struct hisi_sas_slot_buf_table, command_header)) |
| 49 | #define hisi_sas_cmd_hdr_addr_mem(slot) hisi_sas_cmd_hdr_addr(slot->buf) |
| 50 | #define hisi_sas_cmd_hdr_addr_dma(slot) hisi_sas_cmd_hdr_addr(slot->buf_dma) |
| 51 | |
| 52 | #define hisi_sas_sge_addr(buf) \ |
| 53 | (buf + offsetof(struct hisi_sas_slot_buf_table, sge_page)) |
| 54 | #define hisi_sas_sge_addr_mem(slot) hisi_sas_sge_addr(slot->buf) |
| 55 | #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] | 56 | |
John Garry | 42e7a69 | 2015-11-18 00:50:49 +0800 | [diff] [blame] | 57 | #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] | 58 | #define HISI_SAS_MAX_SMP_RESP_SZ 1028 |
John Garry | 6f2ff1a | 2016-01-26 02:47:20 +0800 | [diff] [blame] | 59 | #define HISI_SAS_MAX_STP_RESP_SZ 28 |
John Garry | 42e7a69 | 2015-11-18 00:50:49 +0800 | [diff] [blame] | 60 | |
John Garry | 98bf39f | 2016-01-26 02:47:02 +0800 | [diff] [blame] | 61 | #define DEV_IS_EXPANDER(type) \ |
| 62 | ((type == SAS_EDGE_EXPANDER_DEVICE) || \ |
| 63 | (type == SAS_FANOUT_EXPANDER_DEVICE)) |
| 64 | |
Xiang Chen | 6c7bb8a | 2017-06-14 23:33:14 +0800 | [diff] [blame] | 65 | #define HISI_SAS_SATA_PROTOCOL_NONDATA 0x1 |
| 66 | #define HISI_SAS_SATA_PROTOCOL_PIO 0x2 |
| 67 | #define HISI_SAS_SATA_PROTOCOL_DMA 0x4 |
| 68 | #define HISI_SAS_SATA_PROTOCOL_FPDMA 0x8 |
| 69 | #define HISI_SAS_SATA_PROTOCOL_ATAPI 0x10 |
| 70 | |
John Garry | abda97c | 2015-11-18 00:50:51 +0800 | [diff] [blame] | 71 | struct hisi_hba; |
John Garry | af740db | 2015-11-18 00:50:41 +0800 | [diff] [blame] | 72 | |
John Garry | 07d7859 | 2015-11-18 00:50:47 +0800 | [diff] [blame] | 73 | enum { |
| 74 | PORT_TYPE_SAS = (1U << 1), |
| 75 | PORT_TYPE_SATA = (1U << 0), |
| 76 | }; |
| 77 | |
John Garry | af740db | 2015-11-18 00:50:41 +0800 | [diff] [blame] | 78 | enum dev_status { |
| 79 | HISI_SAS_DEV_NORMAL, |
| 80 | HISI_SAS_DEV_EH, |
| 81 | }; |
John Garry | abda97c | 2015-11-18 00:50:51 +0800 | [diff] [blame] | 82 | |
John Garry | 441c274 | 2016-08-24 19:05:47 +0800 | [diff] [blame] | 83 | enum { |
| 84 | HISI_SAS_INT_ABT_CMD = 0, |
| 85 | HISI_SAS_INT_ABT_DEV = 1, |
| 86 | }; |
| 87 | |
John Garry | abda97c | 2015-11-18 00:50:51 +0800 | [diff] [blame] | 88 | enum hisi_sas_dev_type { |
| 89 | HISI_SAS_DEV_TYPE_STP = 0, |
| 90 | HISI_SAS_DEV_TYPE_SSP, |
| 91 | HISI_SAS_DEV_TYPE_SATA, |
| 92 | }; |
| 93 | |
John Garry | 7eb7869 | 2015-11-18 00:50:31 +0800 | [diff] [blame] | 94 | struct hisi_sas_phy { |
John Garry | 976867e | 2015-11-18 00:50:42 +0800 | [diff] [blame] | 95 | struct hisi_hba *hisi_hba; |
| 96 | struct hisi_sas_port *port; |
John Garry | 7eb7869 | 2015-11-18 00:50:31 +0800 | [diff] [blame] | 97 | struct asd_sas_phy sas_phy; |
John Garry | 976867e | 2015-11-18 00:50:42 +0800 | [diff] [blame] | 98 | struct sas_identify identify; |
| 99 | struct timer_list timer; |
John Garry | 6613992 | 2015-11-18 00:50:48 +0800 | [diff] [blame] | 100 | struct work_struct phyup_ws; |
John Garry | 976867e | 2015-11-18 00:50:42 +0800 | [diff] [blame] | 101 | u64 port_id; /* from hw */ |
John Garry | 5d74242 | 2015-11-18 00:50:38 +0800 | [diff] [blame] | 102 | u64 dev_sas_addr; |
John Garry | 976867e | 2015-11-18 00:50:42 +0800 | [diff] [blame] | 103 | u64 frame_rcvd_size; |
| 104 | u8 frame_rcvd[32]; |
| 105 | u8 phy_attached; |
| 106 | u8 reserved[3]; |
John Garry | d0ef10c | 2017-06-26 18:27:28 +0800 | [diff] [blame] | 107 | u32 phy_type; |
John Garry | 976867e | 2015-11-18 00:50:42 +0800 | [diff] [blame] | 108 | enum sas_linkrate minimum_linkrate; |
| 109 | enum sas_linkrate maximum_linkrate; |
John Garry | 7eb7869 | 2015-11-18 00:50:31 +0800 | [diff] [blame] | 110 | }; |
| 111 | |
| 112 | struct hisi_sas_port { |
| 113 | struct asd_sas_port sas_port; |
John Garry | 976867e | 2015-11-18 00:50:42 +0800 | [diff] [blame] | 114 | u8 port_attached; |
| 115 | u8 id; /* from hw */ |
John Garry | 7eb7869 | 2015-11-18 00:50:31 +0800 | [diff] [blame] | 116 | }; |
| 117 | |
John Garry | 9101a07 | 2015-11-18 00:50:37 +0800 | [diff] [blame] | 118 | struct hisi_sas_cq { |
| 119 | struct hisi_hba *hisi_hba; |
John Garry | d177c40 | 2017-01-03 20:24:48 +0800 | [diff] [blame] | 120 | struct tasklet_struct tasklet; |
John Garry | e6c346f | 2016-09-06 23:36:11 +0800 | [diff] [blame] | 121 | int rd_point; |
John Garry | 9101a07 | 2015-11-18 00:50:37 +0800 | [diff] [blame] | 122 | int id; |
| 123 | }; |
| 124 | |
John Garry | 4fde02a | 2016-09-06 23:36:12 +0800 | [diff] [blame] | 125 | struct hisi_sas_dq { |
| 126 | struct hisi_hba *hisi_hba; |
Xiang Chen | b1a4941 | 2017-06-14 23:33:13 +0800 | [diff] [blame] | 127 | struct hisi_sas_slot *slot_prep; |
| 128 | spinlock_t lock; |
John Garry | 4fde02a | 2016-09-06 23:36:12 +0800 | [diff] [blame] | 129 | int wr_point; |
| 130 | int id; |
| 131 | }; |
| 132 | |
John Garry | af740db | 2015-11-18 00:50:41 +0800 | [diff] [blame] | 133 | struct hisi_sas_device { |
John Garry | abda97c | 2015-11-18 00:50:51 +0800 | [diff] [blame] | 134 | struct hisi_hba *hisi_hba; |
| 135 | struct domain_device *sas_device; |
Xiang Chen | b1a4941 | 2017-06-14 23:33:13 +0800 | [diff] [blame] | 136 | struct hisi_sas_dq *dq; |
John Garry | 405314d | 2017-03-23 01:25:21 +0800 | [diff] [blame] | 137 | struct list_head list; |
John Garry | ad60483 | 2017-06-14 23:33:12 +0800 | [diff] [blame] | 138 | u64 attached_phy; |
| 139 | atomic64_t running_req; |
| 140 | enum sas_device_type dev_type; |
| 141 | int device_id; |
Xiaofei Tan | 32ccba5 | 2017-04-10 21:21:57 +0800 | [diff] [blame] | 142 | int sata_idx; |
John Garry | ad60483 | 2017-06-14 23:33:12 +0800 | [diff] [blame] | 143 | u8 dev_status; |
John Garry | af740db | 2015-11-18 00:50:41 +0800 | [diff] [blame] | 144 | }; |
| 145 | |
John Garry | 6be6de1 | 2015-11-18 00:50:34 +0800 | [diff] [blame] | 146 | struct hisi_sas_slot { |
John Garry | 42e7a69 | 2015-11-18 00:50:49 +0800 | [diff] [blame] | 147 | struct list_head entry; |
| 148 | struct sas_task *task; |
| 149 | struct hisi_sas_port *port; |
| 150 | u64 n_elem; |
| 151 | int dlvry_queue; |
| 152 | int dlvry_queue_slot; |
John Garry | 27a3f22 | 2015-11-18 00:50:50 +0800 | [diff] [blame] | 153 | int cmplt_queue; |
| 154 | int cmplt_queue_slot; |
John Garry | 42e7a69 | 2015-11-18 00:50:49 +0800 | [diff] [blame] | 155 | int idx; |
John Garry | cac9b2a | 2016-02-25 17:42:11 +0800 | [diff] [blame] | 156 | int abort; |
Xiaofei Tan | f557e32 | 2017-06-29 21:02:14 +0800 | [diff] [blame] | 157 | void *buf; |
| 158 | dma_addr_t buf_dma; |
John Garry | 42e7a69 | 2015-11-18 00:50:49 +0800 | [diff] [blame] | 159 | void *cmd_hdr; |
| 160 | dma_addr_t cmd_hdr_dma; |
John Garry | cac9b2a | 2016-02-25 17:42:11 +0800 | [diff] [blame] | 161 | struct work_struct abort_slot; |
John Garry | 0844a3f | 2017-04-10 21:21:59 +0800 | [diff] [blame] | 162 | struct timer_list internal_abort_timer; |
John Garry | 42e7a69 | 2015-11-18 00:50:49 +0800 | [diff] [blame] | 163 | }; |
| 164 | |
| 165 | struct hisi_sas_tmf_task { |
| 166 | u8 tmf; |
| 167 | u16 tag_of_task_to_be_managed; |
John Garry | 6be6de1 | 2015-11-18 00:50:34 +0800 | [diff] [blame] | 168 | }; |
| 169 | |
John Garry | 7eb7869 | 2015-11-18 00:50:31 +0800 | [diff] [blame] | 170 | struct hisi_sas_hw { |
John Garry | 8ff1d57 | 2015-11-18 00:50:46 +0800 | [diff] [blame] | 171 | int (*hw_init)(struct hisi_hba *hisi_hba); |
John Garry | abda97c | 2015-11-18 00:50:51 +0800 | [diff] [blame] | 172 | void (*setup_itct)(struct hisi_hba *hisi_hba, |
| 173 | struct hisi_sas_device *device); |
John Garry | 685b6d6 | 2016-04-15 21:36:36 +0800 | [diff] [blame] | 174 | int (*slot_index_alloc)(struct hisi_hba *hisi_hba, int *slot_idx, |
| 175 | struct domain_device *device); |
| 176 | struct hisi_sas_device *(*alloc_dev)(struct domain_device *device); |
John Garry | 6613992 | 2015-11-18 00:50:48 +0800 | [diff] [blame] | 177 | void (*sl_notify)(struct hisi_hba *hisi_hba, int phy_no); |
Xiang Chen | b1a4941 | 2017-06-14 23:33:13 +0800 | [diff] [blame] | 178 | int (*get_free_slot)(struct hisi_hba *hisi_hba, struct hisi_sas_dq *dq); |
| 179 | void (*start_delivery)(struct hisi_sas_dq *dq); |
John Garry | 42e7a69 | 2015-11-18 00:50:49 +0800 | [diff] [blame] | 180 | int (*prep_ssp)(struct hisi_hba *hisi_hba, |
| 181 | struct hisi_sas_slot *slot, int is_tmf, |
| 182 | struct hisi_sas_tmf_task *tmf); |
John Garry | 66ee999 | 2015-11-18 00:50:54 +0800 | [diff] [blame] | 183 | int (*prep_smp)(struct hisi_hba *hisi_hba, |
| 184 | struct hisi_sas_slot *slot); |
John Garry | 6f2ff1a | 2016-01-26 02:47:20 +0800 | [diff] [blame] | 185 | int (*prep_stp)(struct hisi_hba *hisi_hba, |
| 186 | struct hisi_sas_slot *slot); |
John Garry | 441c274 | 2016-08-24 19:05:47 +0800 | [diff] [blame] | 187 | int (*prep_abort)(struct hisi_hba *hisi_hba, |
| 188 | struct hisi_sas_slot *slot, |
| 189 | int device_id, int abort_flag, int tag_to_abort); |
John Garry | 27a3f22 | 2015-11-18 00:50:50 +0800 | [diff] [blame] | 190 | int (*slot_complete)(struct hisi_hba *hisi_hba, |
John Garry | 405314d | 2017-03-23 01:25:21 +0800 | [diff] [blame] | 191 | struct hisi_sas_slot *slot); |
John Garry | 396b804 | 2017-03-23 01:25:19 +0800 | [diff] [blame] | 192 | void (*phys_init)(struct hisi_hba *hisi_hba); |
John Garry | e4189d5 | 2015-11-18 00:50:57 +0800 | [diff] [blame] | 193 | void (*phy_enable)(struct hisi_hba *hisi_hba, int phy_no); |
| 194 | void (*phy_disable)(struct hisi_hba *hisi_hba, int phy_no); |
| 195 | void (*phy_hard_reset)(struct hisi_hba *hisi_hba, int phy_no); |
Xiaofei Tan | c52108c | 2017-08-11 00:09:29 +0800 | [diff] [blame^] | 196 | void (*get_events)(struct hisi_hba *hisi_hba, int phy_no); |
Xiang Chen | 2ae7578 | 2016-11-07 20:48:40 +0800 | [diff] [blame] | 197 | void (*phy_set_linkrate)(struct hisi_hba *hisi_hba, int phy_no, |
| 198 | struct sas_phy_linkrates *linkrates); |
| 199 | enum sas_linkrate (*phy_get_max_linkrate)(void); |
John Garry | 27a3f22 | 2015-11-18 00:50:50 +0800 | [diff] [blame] | 200 | void (*free_device)(struct hisi_hba *hisi_hba, |
| 201 | struct hisi_sas_device *dev); |
John Garry | 184a463 | 2015-11-18 00:50:52 +0800 | [diff] [blame] | 202 | int (*get_wideport_bitmap)(struct hisi_hba *hisi_hba, int port_id); |
Xiang Chen | d30ff26 | 2017-06-14 23:33:32 +0800 | [diff] [blame] | 203 | void (*dereg_device)(struct hisi_hba *hisi_hba, |
| 204 | struct domain_device *device); |
Xiang Chen | 06ec0fb | 2017-03-23 01:25:18 +0800 | [diff] [blame] | 205 | int (*soft_reset)(struct hisi_hba *hisi_hba); |
Xiaofei Tan | 917d3bd | 2017-08-11 00:09:26 +0800 | [diff] [blame] | 206 | u32 (*get_phys_state)(struct hisi_hba *hisi_hba); |
John Garry | a8d547b | 2016-01-26 02:47:03 +0800 | [diff] [blame] | 207 | int max_command_entries; |
John Garry | 6be6de1 | 2015-11-18 00:50:34 +0800 | [diff] [blame] | 208 | int complete_hdr_size; |
John Garry | 7eb7869 | 2015-11-18 00:50:31 +0800 | [diff] [blame] | 209 | }; |
| 210 | |
| 211 | struct hisi_hba { |
| 212 | /* This must be the first element, used by SHOST_TO_SAS_HA */ |
| 213 | struct sas_ha_struct *p; |
| 214 | |
John Garry | 11b7524 | 2017-06-14 23:33:17 +0800 | [diff] [blame] | 215 | struct platform_device *platform_dev; |
| 216 | struct pci_dev *pci_dev; |
| 217 | struct device *dev; |
| 218 | |
John Garry | e26b2f4 | 2015-11-18 00:50:32 +0800 | [diff] [blame] | 219 | void __iomem *regs; |
| 220 | struct regmap *ctrl; |
| 221 | u32 ctrl_reset_reg; |
| 222 | u32 ctrl_reset_sts_reg; |
| 223 | u32 ctrl_clock_ena_reg; |
John Garry | 3bc45af | 2016-10-04 19:11:11 +0800 | [diff] [blame] | 224 | u32 refclk_frequency_mhz; |
John Garry | 7eb7869 | 2015-11-18 00:50:31 +0800 | [diff] [blame] | 225 | u8 sas_addr[SAS_ADDR_SIZE]; |
| 226 | |
| 227 | int n_phy; |
John Garry | fa42d80 | 2015-11-18 00:50:43 +0800 | [diff] [blame] | 228 | spinlock_t lock; |
John Garry | 7eb7869 | 2015-11-18 00:50:31 +0800 | [diff] [blame] | 229 | |
John Garry | fa42d80 | 2015-11-18 00:50:43 +0800 | [diff] [blame] | 230 | struct timer_list timer; |
John Garry | 7e9080e | 2015-11-18 00:50:40 +0800 | [diff] [blame] | 231 | struct workqueue_struct *wq; |
John Garry | 257efd1 | 2015-11-18 00:50:36 +0800 | [diff] [blame] | 232 | |
| 233 | int slot_index_count; |
| 234 | unsigned long *slot_index_tags; |
Xiaofei Tan | c7b9d36 | 2017-04-10 21:21:56 +0800 | [diff] [blame] | 235 | unsigned long reject_stp_links_msk; |
John Garry | 257efd1 | 2015-11-18 00:50:36 +0800 | [diff] [blame] | 236 | |
John Garry | 7eb7869 | 2015-11-18 00:50:31 +0800 | [diff] [blame] | 237 | /* SCSI/SAS glue */ |
| 238 | struct sas_ha_struct sha; |
| 239 | struct Scsi_Host *shost; |
John Garry | 9101a07 | 2015-11-18 00:50:37 +0800 | [diff] [blame] | 240 | |
| 241 | struct hisi_sas_cq cq[HISI_SAS_MAX_QUEUES]; |
John Garry | 4fde02a | 2016-09-06 23:36:12 +0800 | [diff] [blame] | 242 | struct hisi_sas_dq dq[HISI_SAS_MAX_QUEUES]; |
John Garry | 7eb7869 | 2015-11-18 00:50:31 +0800 | [diff] [blame] | 243 | struct hisi_sas_phy phy[HISI_SAS_MAX_PHYS]; |
| 244 | struct hisi_sas_port port[HISI_SAS_MAX_PHYS]; |
John Garry | e26b2f4 | 2015-11-18 00:50:32 +0800 | [diff] [blame] | 245 | |
| 246 | int queue_count; |
John Garry | 6be6de1 | 2015-11-18 00:50:34 +0800 | [diff] [blame] | 247 | |
Xiaofei Tan | f557e32 | 2017-06-29 21:02:14 +0800 | [diff] [blame] | 248 | struct dma_pool *buffer_pool; |
John Garry | af740db | 2015-11-18 00:50:41 +0800 | [diff] [blame] | 249 | struct hisi_sas_device devices[HISI_SAS_MAX_DEVICES]; |
John Garry | 6be6de1 | 2015-11-18 00:50:34 +0800 | [diff] [blame] | 250 | struct hisi_sas_cmd_hdr *cmd_hdr[HISI_SAS_MAX_QUEUES]; |
| 251 | dma_addr_t cmd_hdr_dma[HISI_SAS_MAX_QUEUES]; |
| 252 | void *complete_hdr[HISI_SAS_MAX_QUEUES]; |
| 253 | dma_addr_t complete_hdr_dma[HISI_SAS_MAX_QUEUES]; |
| 254 | struct hisi_sas_initial_fis *initial_fis; |
| 255 | dma_addr_t initial_fis_dma; |
| 256 | struct hisi_sas_itct *itct; |
| 257 | dma_addr_t itct_dma; |
| 258 | struct hisi_sas_iost *iost; |
| 259 | dma_addr_t iost_dma; |
| 260 | struct hisi_sas_breakpoint *breakpoint; |
| 261 | dma_addr_t breakpoint_dma; |
| 262 | struct hisi_sas_breakpoint *sata_breakpoint; |
| 263 | dma_addr_t sata_breakpoint_dma; |
| 264 | struct hisi_sas_slot *slot_info; |
Xiang Chen | 06ec0fb | 2017-03-23 01:25:18 +0800 | [diff] [blame] | 265 | unsigned long flags; |
John Garry | 7eb7869 | 2015-11-18 00:50:31 +0800 | [diff] [blame] | 266 | const struct hisi_sas_hw *hw; /* Low level hw interface */ |
Xiaofei Tan | 32ccba5 | 2017-04-10 21:21:57 +0800 | [diff] [blame] | 267 | unsigned long sata_dev_bitmap[BITS_TO_LONGS(HISI_SAS_MAX_DEVICES)]; |
Xiang Chen | 06ec0fb | 2017-03-23 01:25:18 +0800 | [diff] [blame] | 268 | struct work_struct rst_work; |
John Garry | 7eb7869 | 2015-11-18 00:50:31 +0800 | [diff] [blame] | 269 | }; |
| 270 | |
John Garry | c799d6b | 2015-11-18 00:50:33 +0800 | [diff] [blame] | 271 | /* Generic HW DMA host memory structures */ |
| 272 | /* Delivery queue header */ |
| 273 | struct hisi_sas_cmd_hdr { |
| 274 | /* dw0 */ |
| 275 | __le32 dw0; |
| 276 | |
| 277 | /* dw1 */ |
| 278 | __le32 dw1; |
| 279 | |
| 280 | /* dw2 */ |
| 281 | __le32 dw2; |
| 282 | |
| 283 | /* dw3 */ |
| 284 | __le32 transfer_tags; |
| 285 | |
| 286 | /* dw4 */ |
| 287 | __le32 data_transfer_len; |
| 288 | |
| 289 | /* dw5 */ |
| 290 | __le32 first_burst_num; |
| 291 | |
| 292 | /* dw6 */ |
| 293 | __le32 sg_len; |
| 294 | |
| 295 | /* dw7 */ |
| 296 | __le32 dw7; |
| 297 | |
| 298 | /* dw8-9 */ |
| 299 | __le64 cmd_table_addr; |
| 300 | |
| 301 | /* dw10-11 */ |
| 302 | __le64 sts_buffer_addr; |
| 303 | |
| 304 | /* dw12-13 */ |
| 305 | __le64 prd_table_addr; |
| 306 | |
| 307 | /* dw14-15 */ |
| 308 | __le64 dif_prd_table_addr; |
| 309 | }; |
| 310 | |
| 311 | struct hisi_sas_itct { |
| 312 | __le64 qw0; |
| 313 | __le64 sas_addr; |
| 314 | __le64 qw2; |
| 315 | __le64 qw3; |
John Garry | 281e3bf | 2016-01-26 02:47:06 +0800 | [diff] [blame] | 316 | __le64 qw4_15[12]; |
John Garry | c799d6b | 2015-11-18 00:50:33 +0800 | [diff] [blame] | 317 | }; |
| 318 | |
| 319 | struct hisi_sas_iost { |
| 320 | __le64 qw0; |
| 321 | __le64 qw1; |
| 322 | __le64 qw2; |
| 323 | __le64 qw3; |
| 324 | }; |
| 325 | |
| 326 | struct hisi_sas_err_record { |
John Garry | 8d1eee7 | 2016-01-26 02:47:05 +0800 | [diff] [blame] | 327 | u32 data[4]; |
John Garry | c799d6b | 2015-11-18 00:50:33 +0800 | [diff] [blame] | 328 | }; |
| 329 | |
| 330 | struct hisi_sas_initial_fis { |
| 331 | struct hisi_sas_err_record err_record; |
| 332 | struct dev_to_host_fis fis; |
| 333 | u32 rsvd[3]; |
| 334 | }; |
| 335 | |
| 336 | struct hisi_sas_breakpoint { |
| 337 | u8 data[128]; /*io128 byte*/ |
| 338 | }; |
| 339 | |
| 340 | struct hisi_sas_sge { |
| 341 | __le64 addr; |
| 342 | __le32 page_ctrl_0; |
| 343 | __le32 page_ctrl_1; |
| 344 | __le32 data_len; |
| 345 | __le32 data_off; |
| 346 | }; |
| 347 | |
| 348 | struct hisi_sas_command_table_smp { |
| 349 | u8 bytes[44]; |
| 350 | }; |
| 351 | |
| 352 | struct hisi_sas_command_table_stp { |
| 353 | struct host_to_dev_fis command_fis; |
| 354 | u8 dummy[12]; |
| 355 | u8 atapi_cdb[ATAPI_CDB_LEN]; |
| 356 | }; |
| 357 | |
Ming Lin | 65e8617 | 2016-04-04 14:48:10 -0700 | [diff] [blame] | 358 | #define HISI_SAS_SGE_PAGE_CNT SG_CHUNK_SIZE |
John Garry | c799d6b | 2015-11-18 00:50:33 +0800 | [diff] [blame] | 359 | struct hisi_sas_sge_page { |
| 360 | struct hisi_sas_sge sge[HISI_SAS_SGE_PAGE_CNT]; |
Xiaofei Tan | f557e32 | 2017-06-29 21:02:14 +0800 | [diff] [blame] | 361 | } __aligned(16); |
John Garry | c799d6b | 2015-11-18 00:50:33 +0800 | [diff] [blame] | 362 | |
| 363 | struct hisi_sas_command_table_ssp { |
| 364 | struct ssp_frame_hdr hdr; |
| 365 | union { |
| 366 | struct { |
| 367 | struct ssp_command_iu task; |
| 368 | u32 prot[6]; |
| 369 | }; |
| 370 | struct ssp_tmf_iu ssp_task; |
| 371 | struct xfer_rdy_iu xfer_rdy; |
| 372 | struct ssp_response_iu ssp_res; |
| 373 | } u; |
| 374 | }; |
| 375 | |
| 376 | union hisi_sas_command_table { |
| 377 | struct hisi_sas_command_table_ssp ssp; |
| 378 | struct hisi_sas_command_table_smp smp; |
| 379 | struct hisi_sas_command_table_stp stp; |
Xiaofei Tan | f557e32 | 2017-06-29 21:02:14 +0800 | [diff] [blame] | 380 | } __aligned(16); |
| 381 | |
| 382 | struct hisi_sas_status_buffer { |
| 383 | struct hisi_sas_err_record err; |
| 384 | u8 iu[1024]; |
| 385 | } __aligned(16); |
| 386 | |
| 387 | struct hisi_sas_slot_buf_table { |
| 388 | struct hisi_sas_status_buffer status_buffer; |
| 389 | union hisi_sas_command_table command_header; |
| 390 | struct hisi_sas_sge_page sge_page; |
John Garry | c799d6b | 2015-11-18 00:50:33 +0800 | [diff] [blame] | 391 | }; |
John Garry | 2e244f0 | 2017-03-23 01:25:17 +0800 | [diff] [blame] | 392 | |
John Garry | e21fe3a | 2017-06-14 23:33:20 +0800 | [diff] [blame] | 393 | extern struct scsi_transport_template *hisi_sas_stt; |
| 394 | extern struct scsi_host_template *hisi_sas_sht; |
| 395 | |
| 396 | extern void hisi_sas_init_add(struct hisi_hba *hisi_hba); |
| 397 | extern int hisi_sas_alloc(struct hisi_hba *hisi_hba, struct Scsi_Host *shost); |
| 398 | extern void hisi_sas_free(struct hisi_hba *hisi_hba); |
Xiang Chen | 6c7bb8a | 2017-06-14 23:33:14 +0800 | [diff] [blame] | 399 | extern u8 hisi_sas_get_ata_protocol(u8 cmd, int direction); |
John Garry | 2e244f0 | 2017-03-23 01:25:17 +0800 | [diff] [blame] | 400 | 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] | 401 | extern void hisi_sas_sata_done(struct sas_task *task, |
| 402 | struct hisi_sas_slot *slot); |
Xiang Chen | 318913c | 2017-06-14 23:33:16 +0800 | [diff] [blame] | 403 | 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] | 404 | extern int hisi_sas_get_fw_info(struct hisi_hba *hisi_hba); |
John Garry | 9fb10b5 | 2015-11-18 00:50:44 +0800 | [diff] [blame] | 405 | extern int hisi_sas_probe(struct platform_device *pdev, |
| 406 | const struct hisi_sas_hw *ops); |
| 407 | extern int hisi_sas_remove(struct platform_device *pdev); |
John Garry | c799d6b | 2015-11-18 00:50:33 +0800 | [diff] [blame] | 408 | |
John Garry | 184a463 | 2015-11-18 00:50:52 +0800 | [diff] [blame] | 409 | 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] | 410 | extern void hisi_sas_slot_task_free(struct hisi_hba *hisi_hba, |
| 411 | struct sas_task *task, |
| 412 | struct hisi_sas_slot *slot); |
Xiang Chen | 06ec0fb | 2017-03-23 01:25:18 +0800 | [diff] [blame] | 413 | extern void hisi_sas_init_mem(struct hisi_hba *hisi_hba); |
John Garry | e8899fa | 2015-11-18 00:50:30 +0800 | [diff] [blame] | 414 | #endif |