12874c5fdSThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-or-later */ 2e8899fadSJohn Garry /* 3e8899fadSJohn Garry * Copyright (c) 2015 Linaro Ltd. 4e8899fadSJohn Garry * Copyright (c) 2015 Hisilicon Limited. 5e8899fadSJohn Garry */ 6e8899fadSJohn Garry 7e8899fadSJohn Garry #ifndef _HISI_SAS_H_ 8e8899fadSJohn Garry #define _HISI_SAS_H_ 9e8899fadSJohn Garry 104d558c77SJohn Garry #include <linux/acpi.h> 113bc45af8SJohn Garry #include <linux/clk.h> 12ef63464bSLuo Jiaxing #include <linux/debugfs.h> 13e8899fadSJohn Garry #include <linux/dmapool.h> 14a25d0d3dSXiang Chen #include <linux/iopoll.h> 152ba5afb6SXiang Chen #include <linux/lcm.h> 1657dbb2b2SXiang Chen #include <linux/libata.h> 17e8899fadSJohn Garry #include <linux/mfd/syscon.h> 18e8899fadSJohn Garry #include <linux/module.h> 19e8899fadSJohn Garry #include <linux/of_address.h> 2011b75249SJohn Garry #include <linux/pci.h> 21e8899fadSJohn Garry #include <linux/platform_device.h> 224d558c77SJohn Garry #include <linux/property.h> 23e8899fadSJohn Garry #include <linux/regmap.h> 24d28ed83bSLuo Jiaxing #include <linux/timer.h> 256f2ff1a1SJohn Garry #include <scsi/sas_ata.h> 26e8899fadSJohn Garry #include <scsi/libsas.h> 27e8899fadSJohn Garry 287eb7869fSJohn Garry #define HISI_SAS_MAX_PHYS 9 296be6de18SJohn Garry #define HISI_SAS_MAX_QUEUES 32 301273d65fSXiang Chen #define HISI_SAS_QUEUE_SLOTS 4096 313297ded1SXiang Chen #define HISI_SAS_MAX_ITCT_ENTRIES 1024 327eb7869fSJohn Garry #define HISI_SAS_MAX_DEVICES HISI_SAS_MAX_ITCT_ENTRIES 3306ec0fb9SXiang Chen #define HISI_SAS_RESET_BIT 0 34917d3bdaSXiaofei Tan #define HISI_SAS_REJECT_CMD_BIT 1 3593352abcSJohn Garry #define HISI_SAS_MAX_COMMANDS (HISI_SAS_QUEUE_SLOTS) 3693352abcSJohn Garry #define HISI_SAS_RESERVED_IPTT 96 3793352abcSJohn Garry #define HISI_SAS_UNRESERVED_IPTT \ 3893352abcSJohn Garry (HISI_SAS_MAX_COMMANDS - HISI_SAS_RESERVED_IPTT) 397eb7869fSJohn Garry 40bbe0a7b3SLuo Jiaxing #define HISI_SAS_IOST_ITCT_CACHE_NUM 64 41bbe0a7b3SLuo Jiaxing #define HISI_SAS_IOST_ITCT_CACHE_DW_SZ 10 42bbe0a7b3SLuo Jiaxing 43f557e32cSXiaofei Tan #define HISI_SAS_STATUS_BUF_SZ (sizeof(struct hisi_sas_status_buffer)) 44f557e32cSXiaofei Tan #define HISI_SAS_COMMAND_TABLE_SZ (sizeof(union hisi_sas_command_table)) 45f557e32cSXiaofei Tan 46f557e32cSXiaofei Tan #define hisi_sas_status_buf_addr(buf) \ 47b3cce125SXiang Chen ((buf) + offsetof(struct hisi_sas_slot_buf_table, status_buffer)) 48b3cce125SXiang Chen #define hisi_sas_status_buf_addr_mem(slot) hisi_sas_status_buf_addr((slot)->buf) 49f557e32cSXiaofei Tan #define hisi_sas_status_buf_addr_dma(slot) \ 50b3cce125SXiang Chen hisi_sas_status_buf_addr((slot)->buf_dma) 51f557e32cSXiaofei Tan 52f557e32cSXiaofei Tan #define hisi_sas_cmd_hdr_addr(buf) \ 53b3cce125SXiang Chen ((buf) + offsetof(struct hisi_sas_slot_buf_table, command_header)) 54b3cce125SXiang Chen #define hisi_sas_cmd_hdr_addr_mem(slot) hisi_sas_cmd_hdr_addr((slot)->buf) 55b3cce125SXiang Chen #define hisi_sas_cmd_hdr_addr_dma(slot) hisi_sas_cmd_hdr_addr((slot)->buf_dma) 56f557e32cSXiaofei Tan 57f557e32cSXiaofei Tan #define hisi_sas_sge_addr(buf) \ 58b3cce125SXiang Chen ((buf) + offsetof(struct hisi_sas_slot_buf_table, sge_page)) 59b3cce125SXiang Chen #define hisi_sas_sge_addr_mem(slot) hisi_sas_sge_addr((slot)->buf) 60b3cce125SXiang Chen #define hisi_sas_sge_addr_dma(slot) hisi_sas_sge_addr((slot)->buf_dma) 61b3cce125SXiang Chen 62b3cce125SXiang Chen #define hisi_sas_sge_dif_addr(buf) \ 63b3cce125SXiang Chen ((buf) + offsetof(struct hisi_sas_slot_dif_buf_table, sge_dif_page)) 64b3cce125SXiang Chen #define hisi_sas_sge_dif_addr_mem(slot) hisi_sas_sge_dif_addr((slot)->buf) 65b3cce125SXiang Chen #define hisi_sas_sge_dif_addr_dma(slot) hisi_sas_sge_dif_addr((slot)->buf_dma) 666be6de18SJohn Garry 6742e7a693SJohn Garry #define HISI_SAS_MAX_SSP_RESP_SZ (sizeof(struct ssp_frame_hdr) + 1024) 6866ee999bSJohn Garry #define HISI_SAS_MAX_SMP_RESP_SZ 1028 696f2ff1a1SJohn Garry #define HISI_SAS_MAX_STP_RESP_SZ 28 7042e7a693SJohn Garry 716c7bb8a1SXiang Chen #define HISI_SAS_SATA_PROTOCOL_NONDATA 0x1 726c7bb8a1SXiang Chen #define HISI_SAS_SATA_PROTOCOL_PIO 0x2 736c7bb8a1SXiang Chen #define HISI_SAS_SATA_PROTOCOL_DMA 0x4 746c7bb8a1SXiang Chen #define HISI_SAS_SATA_PROTOCOL_FPDMA 0x8 756c7bb8a1SXiang Chen #define HISI_SAS_SATA_PROTOCOL_ATAPI 0x10 766c7bb8a1SXiang Chen 77d6a9000bSXiang Chen #define HISI_SAS_DIF_PROT_MASK (SHOST_DIF_TYPE1_PROTECTION | \ 78d6a9000bSXiang Chen SHOST_DIF_TYPE2_PROTECTION | \ 79d6a9000bSXiang Chen SHOST_DIF_TYPE3_PROTECTION) 80d6a9000bSXiang Chen 81b3cce125SXiang Chen #define HISI_SAS_DIX_PROT_MASK (SHOST_DIX_TYPE1_PROTECTION | \ 82b3cce125SXiang Chen SHOST_DIX_TYPE2_PROTECTION | \ 83b3cce125SXiang Chen SHOST_DIX_TYPE3_PROTECTION) 84b3cce125SXiang Chen 85b3cce125SXiang Chen #define HISI_SAS_PROT_MASK (HISI_SAS_DIF_PROT_MASK | HISI_SAS_DIX_PROT_MASK) 86d6a9000bSXiang Chen 87b6c9b15eSXiaofei Tan #define HISI_SAS_WAIT_PHYUP_TIMEOUT 20 888fa9a7bdSXiang Chen #define CLEAR_ITCT_TIMEOUT 20 89b6c9b15eSXiaofei Tan 90abda97c2SJohn Garry struct hisi_hba; 91af740dbeSJohn Garry 9207d78592SJohn Garry enum { 9307d78592SJohn Garry PORT_TYPE_SAS = (1U << 1), 9407d78592SJohn Garry PORT_TYPE_SATA = (1U << 0), 9507d78592SJohn Garry }; 9607d78592SJohn Garry 9757dbb2b2SXiang Chen enum dev_status { 9857dbb2b2SXiang Chen HISI_SAS_DEV_INIT, 9957dbb2b2SXiang Chen HISI_SAS_DEV_NORMAL, 10057dbb2b2SXiang Chen }; 10157dbb2b2SXiang Chen 102441c2740SJohn Garry enum { 103441c2740SJohn Garry HISI_SAS_INT_ABT_CMD = 0, 104441c2740SJohn Garry HISI_SAS_INT_ABT_DEV = 1, 105441c2740SJohn Garry }; 106441c2740SJohn Garry 107abda97c2SJohn Garry enum hisi_sas_dev_type { 108abda97c2SJohn Garry HISI_SAS_DEV_TYPE_STP = 0, 109abda97c2SJohn Garry HISI_SAS_DEV_TYPE_SSP, 110abda97c2SJohn Garry HISI_SAS_DEV_TYPE_SATA, 111abda97c2SJohn Garry }; 112abda97c2SJohn Garry 1132b383351SJohn Garry struct hisi_sas_hw_error { 1142b383351SJohn Garry u32 irq_msk; 1152b383351SJohn Garry u32 msk; 1162b383351SJohn Garry int shift; 1172b383351SJohn Garry const char *msg; 1182b383351SJohn Garry int reg; 119729428caSShiju Jose const struct hisi_sas_hw_error *sub; 1202b383351SJohn Garry }; 1212b383351SJohn Garry 122e402acdbSXiaofei Tan struct hisi_sas_rst { 123e402acdbSXiaofei Tan struct hisi_hba *hisi_hba; 124e402acdbSXiaofei Tan struct completion *completion; 125e402acdbSXiaofei Tan struct work_struct work; 126e402acdbSXiaofei Tan bool done; 127e402acdbSXiaofei Tan }; 128e402acdbSXiaofei Tan 129e402acdbSXiaofei Tan #define HISI_SAS_RST_WORK_INIT(r, c) \ 130e402acdbSXiaofei Tan { .hisi_hba = hisi_hba, \ 131e402acdbSXiaofei Tan .completion = &c, \ 132e402acdbSXiaofei Tan .work = __WORK_INITIALIZER(r.work, \ 133e402acdbSXiaofei Tan hisi_sas_sync_rst_work_handler), \ 134e402acdbSXiaofei Tan .done = false, \ 135e402acdbSXiaofei Tan } 136e402acdbSXiaofei Tan 137e402acdbSXiaofei Tan #define HISI_SAS_DECLARE_RST_WORK_ON_STACK(r) \ 138e402acdbSXiaofei Tan DECLARE_COMPLETION_ONSTACK(c); \ 139e402acdbSXiaofei Tan struct hisi_sas_rst r = HISI_SAS_RST_WORK_INIT(r, c) 140e402acdbSXiaofei Tan 141e402acdbSXiaofei Tan enum hisi_sas_bit_err_type { 142e402acdbSXiaofei Tan HISI_SAS_ERR_SINGLE_BIT_ECC = 0x0, 143e402acdbSXiaofei Tan HISI_SAS_ERR_MULTI_BIT_ECC = 0x1, 144e402acdbSXiaofei Tan }; 145e402acdbSXiaofei Tan 146e537b62bSXiaofei Tan enum hisi_sas_phy_event { 147e537b62bSXiaofei Tan HISI_PHYE_PHY_UP = 0U, 148057c3d1fSXiaofei Tan HISI_PHYE_LINK_RESET, 149e537b62bSXiaofei Tan HISI_PHYES_NUM, 150e537b62bSXiaofei Tan }; 151e537b62bSXiaofei Tan 1527eb7869fSJohn Garry struct hisi_sas_phy { 153e537b62bSXiaofei Tan struct work_struct works[HISI_PHYES_NUM]; 154976867e6SJohn Garry struct hisi_hba *hisi_hba; 155976867e6SJohn Garry struct hisi_sas_port *port; 1567eb7869fSJohn Garry struct asd_sas_phy sas_phy; 157976867e6SJohn Garry struct sas_identify identify; 1583e1fb1b8SXiang Chen struct completion *reset_completion; 159b6c9b15eSXiaofei Tan struct timer_list timer; 1603e1fb1b8SXiang Chen spinlock_t lock; 161976867e6SJohn Garry u64 port_id; /* from hw */ 162976867e6SJohn Garry u64 frame_rcvd_size; 163976867e6SJohn Garry u8 frame_rcvd[32]; 164976867e6SJohn Garry u8 phy_attached; 1653e1fb1b8SXiang Chen u8 in_reset; 1663e1fb1b8SXiang Chen u8 reserved[2]; 167d0ef10c9SJohn Garry u32 phy_type; 168aaeb8232SXiaofei Tan u32 code_violation_err_count; 169976867e6SJohn Garry enum sas_linkrate minimum_linkrate; 170976867e6SJohn Garry enum sas_linkrate maximum_linkrate; 171c63b88ccSJohn Garry int enable; 1727eb7869fSJohn Garry }; 1737eb7869fSJohn Garry 1747eb7869fSJohn Garry struct hisi_sas_port { 1757eb7869fSJohn Garry struct asd_sas_port sas_port; 176976867e6SJohn Garry u8 port_attached; 177976867e6SJohn Garry u8 id; /* from hw */ 1787eb7869fSJohn Garry }; 1797eb7869fSJohn Garry 1809101a079SJohn Garry struct hisi_sas_cq { 1819101a079SJohn Garry struct hisi_hba *hisi_hba; 1824fefe5bbSXiang Chen const struct cpumask *pci_irq_mask; 183d177c408SJohn Garry struct tasklet_struct tasklet; 184e6c346f3SJohn Garry int rd_point; 1859101a079SJohn Garry int id; 1869101a079SJohn Garry }; 1879101a079SJohn Garry 1884fde02adSJohn Garry struct hisi_sas_dq { 1894fde02adSJohn Garry struct hisi_hba *hisi_hba; 190fa222db0SXiang Chen struct list_head list; 191b1a49412SXiang Chen spinlock_t lock; 1924fde02adSJohn Garry int wr_point; 1934fde02adSJohn Garry int id; 1944fde02adSJohn Garry }; 1954fde02adSJohn Garry 196af740dbeSJohn Garry struct hisi_sas_device { 197abda97c2SJohn Garry struct hisi_hba *hisi_hba; 198abda97c2SJohn Garry struct domain_device *sas_device; 199640acc9aSXiang Chen struct completion *completion; 200b1a49412SXiang Chen struct hisi_sas_dq *dq; 201405314dfSJohn Garry struct list_head list; 202ad604832SJohn Garry enum sas_device_type dev_type; 20357dbb2b2SXiang Chen enum dev_status dev_status; 204ad604832SJohn Garry int device_id; 20532ccba52SXiaofei Tan int sata_idx; 2064fefe5bbSXiang Chen spinlock_t lock; /* For protecting slots */ 207af740dbeSJohn Garry }; 208af740dbeSJohn Garry 20978bd2b4fSXiaofei Tan struct hisi_sas_tmf_task { 210b09fcd09SXiaofei Tan int force_phy; 211b09fcd09SXiaofei Tan int phy_id; 21278bd2b4fSXiaofei Tan u8 tmf; 21378bd2b4fSXiaofei Tan u16 tag_of_task_to_be_managed; 21478bd2b4fSXiaofei Tan }; 21578bd2b4fSXiaofei Tan 2166be6de18SJohn Garry struct hisi_sas_slot { 21742e7a693SJohn Garry struct list_head entry; 218fa222db0SXiang Chen struct list_head delivery; 21942e7a693SJohn Garry struct sas_task *task; 22042e7a693SJohn Garry struct hisi_sas_port *port; 22142e7a693SJohn Garry u64 n_elem; 222b3cce125SXiang Chen u64 n_elem_dif; 22342e7a693SJohn Garry int dlvry_queue; 22442e7a693SJohn Garry int dlvry_queue_slot; 22527a3f229SJohn Garry int cmplt_queue; 22627a3f229SJohn Garry int cmplt_queue_slot; 227cac9b2a2SJohn Garry int abort; 228fa222db0SXiang Chen int ready; 2294fefe5bbSXiang Chen int device_id; 23042e7a693SJohn Garry void *cmd_hdr; 23142e7a693SJohn Garry dma_addr_t cmd_hdr_dma; 2320844a3ffSJohn Garry struct timer_list internal_abort_timer; 233cd938e53SXiang Chen bool is_internal; 23478bd2b4fSXiaofei Tan struct hisi_sas_tmf_task *tmf; 2352ba5afb6SXiang Chen /* Do not reorder/change members after here */ 2362ba5afb6SXiang Chen void *buf; 2372ba5afb6SXiang Chen dma_addr_t buf_dma; 238735bcc77SJohn Garry u16 idx; 2396be6de18SJohn Garry }; 2406be6de18SJohn Garry 241caefac19SLuo Jiaxing #define HISI_SAS_DEBUGFS_REG(x) {#x, x} 242caefac19SLuo Jiaxing 243caefac19SLuo Jiaxing struct hisi_sas_debugfs_reg_lu { 244caefac19SLuo Jiaxing char *name; 245caefac19SLuo Jiaxing int off; 246caefac19SLuo Jiaxing }; 247caefac19SLuo Jiaxing 248eb1c2b72SLuo Jiaxing struct hisi_sas_debugfs_reg { 249caefac19SLuo Jiaxing const struct hisi_sas_debugfs_reg_lu *lu; 250eb1c2b72SLuo Jiaxing int count; 25149159a5eSLuo Jiaxing int base_off; 25249159a5eSLuo Jiaxing union { 25349159a5eSLuo Jiaxing u32 (*read_global_reg)(struct hisi_hba *hisi_hba, u32 off); 25449159a5eSLuo Jiaxing u32 (*read_port_reg)(struct hisi_hba *hisi_hba, int port, 25549159a5eSLuo Jiaxing u32 off); 25649159a5eSLuo Jiaxing }; 257eb1c2b72SLuo Jiaxing }; 258eb1c2b72SLuo Jiaxing 259bbe0a7b3SLuo Jiaxing struct hisi_sas_iost_itct_cache { 260bbe0a7b3SLuo Jiaxing u32 data[HISI_SAS_IOST_ITCT_CACHE_DW_SZ]; 261bbe0a7b3SLuo Jiaxing }; 262bbe0a7b3SLuo Jiaxing 263b0b3e429SLuo Jiaxing enum hisi_sas_debugfs_reg_array_member { 264b0b3e429SLuo Jiaxing DEBUGFS_GLOBAL = 0, 265b0b3e429SLuo Jiaxing DEBUGFS_AXI, 266b0b3e429SLuo Jiaxing DEBUGFS_RAS, 267b0b3e429SLuo Jiaxing DEBUGFS_REGS_NUM 268b0b3e429SLuo Jiaxing }; 269b0b3e429SLuo Jiaxing 270bbe0a7b3SLuo Jiaxing enum hisi_sas_debugfs_cache_type { 271bbe0a7b3SLuo Jiaxing HISI_SAS_ITCT_CACHE, 272bbe0a7b3SLuo Jiaxing HISI_SAS_IOST_CACHE, 273bbe0a7b3SLuo Jiaxing }; 274bbe0a7b3SLuo Jiaxing 2757eb7869fSJohn Garry struct hisi_sas_hw { 2768ff1d571SJohn Garry int (*hw_init)(struct hisi_hba *hisi_hba); 277abda97c2SJohn Garry void (*setup_itct)(struct hisi_hba *hisi_hba, 278abda97c2SJohn Garry struct hisi_sas_device *device); 279784b46b7SXiang Chen int (*slot_index_alloc)(struct hisi_hba *hisi_hba, 280685b6d6eSJohn Garry struct domain_device *device); 281685b6d6eSJohn Garry struct hisi_sas_device *(*alloc_dev)(struct domain_device *device); 282569eddcfSXiang Chen void (*sl_notify_ssp)(struct hisi_hba *hisi_hba, int phy_no); 283b1a49412SXiang Chen void (*start_delivery)(struct hisi_sas_dq *dq); 284a2b3820bSXiang Chen void (*prep_ssp)(struct hisi_hba *hisi_hba, 28578bd2b4fSXiaofei Tan struct hisi_sas_slot *slot); 286a2b3820bSXiang Chen void (*prep_smp)(struct hisi_hba *hisi_hba, 28766ee999bSJohn Garry struct hisi_sas_slot *slot); 288a2b3820bSXiang Chen void (*prep_stp)(struct hisi_hba *hisi_hba, 2896f2ff1a1SJohn Garry struct hisi_sas_slot *slot); 290a2b3820bSXiang Chen void (*prep_abort)(struct hisi_hba *hisi_hba, 291441c2740SJohn Garry struct hisi_sas_slot *slot, 292441c2740SJohn Garry int device_id, int abort_flag, int tag_to_abort); 293396b8044SJohn Garry void (*phys_init)(struct hisi_hba *hisi_hba); 2941eb8eeacSXiang Chen void (*phy_start)(struct hisi_hba *hisi_hba, int phy_no); 295e4189d53SJohn Garry void (*phy_disable)(struct hisi_hba *hisi_hba, int phy_no); 296e4189d53SJohn Garry void (*phy_hard_reset)(struct hisi_hba *hisi_hba, int phy_no); 297c52108c6SXiaofei Tan void (*get_events)(struct hisi_hba *hisi_hba, int phy_no); 2982ae75787SXiang Chen void (*phy_set_linkrate)(struct hisi_hba *hisi_hba, int phy_no, 2992ae75787SXiang Chen struct sas_phy_linkrates *linkrates); 3002ae75787SXiang Chen enum sas_linkrate (*phy_get_max_linkrate)(void); 3018fa9a7bdSXiang Chen int (*clear_itct)(struct hisi_hba *hisi_hba, 30227a3f229SJohn Garry struct hisi_sas_device *dev); 3030258141aSXiaofei Tan void (*free_device)(struct hisi_sas_device *sas_dev); 304184a4635SJohn Garry int (*get_wideport_bitmap)(struct hisi_hba *hisi_hba, int port_id); 305d30ff263SXiang Chen void (*dereg_device)(struct hisi_hba *hisi_hba, 306d30ff263SXiang Chen struct domain_device *device); 30706ec0fb9SXiang Chen int (*soft_reset)(struct hisi_hba *hisi_hba); 308917d3bdaSXiaofei Tan u32 (*get_phys_state)(struct hisi_hba *hisi_hba); 3096379c560SXiaofei Tan int (*write_gpio)(struct hisi_hba *hisi_hba, u8 reg_type, 3106379c560SXiaofei Tan u8 reg_index, u8 reg_count, u8 *write_data); 3114bc05809SLuo Jiaxing void (*wait_cmds_complete_timeout)(struct hisi_hba *hisi_hba, 312a865ae14SXiaofei Tan int delay_ms, int timeout_ms); 31349159a5eSLuo Jiaxing void (*snapshot_prepare)(struct hisi_hba *hisi_hba); 31449159a5eSLuo Jiaxing void (*snapshot_restore)(struct hisi_hba *hisi_hba); 31597b151e7SXiang Chen int (*set_bist)(struct hisi_hba *hisi_hba, bool enable); 316bbe0a7b3SLuo Jiaxing void (*read_iost_itct_cache)(struct hisi_hba *hisi_hba, 317bbe0a7b3SLuo Jiaxing enum hisi_sas_debugfs_cache_type type, 318bbe0a7b3SLuo Jiaxing u32 *cache); 3196be6de18SJohn Garry int complete_hdr_size; 320235bfc7fSXiang Chen struct scsi_host_template *sht; 321eb1c2b72SLuo Jiaxing 322b0b3e429SLuo Jiaxing const struct hisi_sas_debugfs_reg *debugfs_reg_array[DEBUGFS_REGS_NUM]; 323eb1c2b72SLuo Jiaxing const struct hisi_sas_debugfs_reg *debugfs_reg_port; 3247eb7869fSJohn Garry }; 3257eb7869fSJohn Garry 326a70e33eaSLuo Jiaxing #define HISI_SAS_MAX_DEBUGFS_DUMP (50) 327a70e33eaSLuo Jiaxing 32835ea630bSLuo Jiaxing struct hisi_sas_debugfs_cq { 32935ea630bSLuo Jiaxing struct hisi_sas_cq *cq; 33035ea630bSLuo Jiaxing void *complete_hdr; 33135ea630bSLuo Jiaxing }; 33235ea630bSLuo Jiaxing 3331b54c4dbSLuo Jiaxing struct hisi_sas_debugfs_dq { 3341b54c4dbSLuo Jiaxing struct hisi_sas_dq *dq; 3351b54c4dbSLuo Jiaxing struct hisi_sas_cmd_hdr *hdr; 3361b54c4dbSLuo Jiaxing }; 3371b54c4dbSLuo Jiaxing 338c6116398SLuo Jiaxing struct hisi_sas_debugfs_regs { 339c6116398SLuo Jiaxing struct hisi_hba *hisi_hba; 340c6116398SLuo Jiaxing u32 *data; 341c6116398SLuo Jiaxing }; 342c6116398SLuo Jiaxing 3431f66e1fdSLuo Jiaxing struct hisi_sas_debugfs_port { 3441f66e1fdSLuo Jiaxing struct hisi_sas_phy *phy; 3451f66e1fdSLuo Jiaxing u32 *data; 3461f66e1fdSLuo Jiaxing }; 3471f66e1fdSLuo Jiaxing 348e15f2e2dSLuo Jiaxing struct hisi_sas_debugfs_iost { 349e15f2e2dSLuo Jiaxing struct hisi_sas_iost *iost; 350e15f2e2dSLuo Jiaxing }; 351e15f2e2dSLuo Jiaxing 3520161d55fSLuo Jiaxing struct hisi_sas_debugfs_itct { 3530161d55fSLuo Jiaxing struct hisi_sas_itct *itct; 3540161d55fSLuo Jiaxing }; 3550161d55fSLuo Jiaxing 356b714dd8fSLuo Jiaxing struct hisi_sas_debugfs_iost_cache { 357b714dd8fSLuo Jiaxing struct hisi_sas_iost_itct_cache *cache; 358b714dd8fSLuo Jiaxing }; 359b714dd8fSLuo Jiaxing 360357e4fc7SLuo Jiaxing struct hisi_sas_debugfs_itct_cache { 361357e4fc7SLuo Jiaxing struct hisi_sas_iost_itct_cache *cache; 362357e4fc7SLuo Jiaxing }; 363357e4fc7SLuo Jiaxing 3647eb7869fSJohn Garry struct hisi_hba { 3657eb7869fSJohn Garry /* This must be the first element, used by SHOST_TO_SAS_HA */ 3667eb7869fSJohn Garry struct sas_ha_struct *p; 3677eb7869fSJohn Garry 36811b75249SJohn Garry struct platform_device *platform_dev; 36911b75249SJohn Garry struct pci_dev *pci_dev; 37011b75249SJohn Garry struct device *dev; 37111b75249SJohn Garry 372d6a9000bSXiang Chen int prot_mask; 373d6a9000bSXiang Chen 374e26b2f40SJohn Garry void __iomem *regs; 3756379c560SXiaofei Tan void __iomem *sgpio_regs; 376e26b2f40SJohn Garry struct regmap *ctrl; 377e26b2f40SJohn Garry u32 ctrl_reset_reg; 378e26b2f40SJohn Garry u32 ctrl_reset_sts_reg; 379e26b2f40SJohn Garry u32 ctrl_clock_ena_reg; 3803bc45af8SJohn Garry u32 refclk_frequency_mhz; 3817eb7869fSJohn Garry u8 sas_addr[SAS_ADDR_SIZE]; 3827eb7869fSJohn Garry 3837eb7869fSJohn Garry int n_phy; 384fa42d80dSJohn Garry spinlock_t lock; 385d2fc401eSXiaofei Tan struct semaphore sem; 3867eb7869fSJohn Garry 387fa42d80dSJohn Garry struct timer_list timer; 3887e9080e1SJohn Garry struct workqueue_struct *wq; 389257efd1fSJohn Garry 390257efd1fSJohn Garry int slot_index_count; 391fa3be0f2SXiang Chen int last_slot_index; 3921b865185SXiang Chen int last_dev_id; 393257efd1fSJohn Garry unsigned long *slot_index_tags; 394c7b9d369SXiaofei Tan unsigned long reject_stp_links_msk; 395257efd1fSJohn Garry 3967eb7869fSJohn Garry /* SCSI/SAS glue */ 3977eb7869fSJohn Garry struct sas_ha_struct sha; 3987eb7869fSJohn Garry struct Scsi_Host *shost; 3999101a079SJohn Garry 4009101a079SJohn Garry struct hisi_sas_cq cq[HISI_SAS_MAX_QUEUES]; 4014fde02adSJohn Garry struct hisi_sas_dq dq[HISI_SAS_MAX_QUEUES]; 4027eb7869fSJohn Garry struct hisi_sas_phy phy[HISI_SAS_MAX_PHYS]; 4037eb7869fSJohn Garry struct hisi_sas_port port[HISI_SAS_MAX_PHYS]; 404e26b2f40SJohn Garry 405e26b2f40SJohn Garry int queue_count; 4066be6de18SJohn Garry 407af740dbeSJohn Garry struct hisi_sas_device devices[HISI_SAS_MAX_DEVICES]; 4086be6de18SJohn Garry struct hisi_sas_cmd_hdr *cmd_hdr[HISI_SAS_MAX_QUEUES]; 4096be6de18SJohn Garry dma_addr_t cmd_hdr_dma[HISI_SAS_MAX_QUEUES]; 4106be6de18SJohn Garry void *complete_hdr[HISI_SAS_MAX_QUEUES]; 4116be6de18SJohn Garry dma_addr_t complete_hdr_dma[HISI_SAS_MAX_QUEUES]; 4126be6de18SJohn Garry struct hisi_sas_initial_fis *initial_fis; 4136be6de18SJohn Garry dma_addr_t initial_fis_dma; 4146be6de18SJohn Garry struct hisi_sas_itct *itct; 4156be6de18SJohn Garry dma_addr_t itct_dma; 4166be6de18SJohn Garry struct hisi_sas_iost *iost; 4176be6de18SJohn Garry dma_addr_t iost_dma; 4186be6de18SJohn Garry struct hisi_sas_breakpoint *breakpoint; 4196be6de18SJohn Garry dma_addr_t breakpoint_dma; 4206be6de18SJohn Garry struct hisi_sas_breakpoint *sata_breakpoint; 4216be6de18SJohn Garry dma_addr_t sata_breakpoint_dma; 4226be6de18SJohn Garry struct hisi_sas_slot *slot_info; 42306ec0fb9SXiang Chen unsigned long flags; 4247eb7869fSJohn Garry const struct hisi_sas_hw *hw; /* Low level hw interface */ 42532ccba52SXiaofei Tan unsigned long sata_dev_bitmap[BITS_TO_LONGS(HISI_SAS_MAX_DEVICES)]; 42606ec0fb9SXiang Chen struct work_struct rst_work; 42749159a5eSLuo Jiaxing struct work_struct debugfs_work; 4284522204aSXiaofei Tan u32 phy_state; 42937359798SXiang Chen u32 intr_coal_ticks; /* Time of interrupt coalesce in us */ 43037359798SXiang Chen u32 intr_coal_count; /* Interrupt count to coalesce */ 431ef63464bSLuo Jiaxing 432795f25a3SJohn Garry int cq_nvecs; 4334fefe5bbSXiang Chen unsigned int *reply_map; 434795f25a3SJohn Garry 43597b151e7SXiang Chen /* bist */ 43697b151e7SXiang Chen enum sas_linkrate debugfs_bist_linkrate; 43797b151e7SXiang Chen int debugfs_bist_code_mode; 43897b151e7SXiang Chen int debugfs_bist_phy_no; 43997b151e7SXiang Chen int debugfs_bist_mode; 44097b151e7SXiang Chen u32 debugfs_bist_cnt; 44197b151e7SXiang Chen int debugfs_bist_enable; 44297b151e7SXiang Chen 443eb1c2b72SLuo Jiaxing /* debugfs memories */ 444b0b3e429SLuo Jiaxing /* Put Global AXI and RAS Register into register array */ 445a70e33eaSLuo Jiaxing struct hisi_sas_debugfs_regs debugfs_regs[HISI_SAS_MAX_DEBUGFS_DUMP][DEBUGFS_REGS_NUM]; 446a70e33eaSLuo Jiaxing struct hisi_sas_debugfs_port debugfs_port_reg[HISI_SAS_MAX_DEBUGFS_DUMP][HISI_SAS_MAX_PHYS]; 447a70e33eaSLuo Jiaxing struct hisi_sas_debugfs_cq debugfs_cq[HISI_SAS_MAX_DEBUGFS_DUMP][HISI_SAS_MAX_QUEUES]; 448a70e33eaSLuo Jiaxing struct hisi_sas_debugfs_dq debugfs_dq[HISI_SAS_MAX_DEBUGFS_DUMP][HISI_SAS_MAX_QUEUES]; 449a70e33eaSLuo Jiaxing struct hisi_sas_debugfs_iost debugfs_iost[HISI_SAS_MAX_DEBUGFS_DUMP]; 450a70e33eaSLuo Jiaxing struct hisi_sas_debugfs_itct debugfs_itct[HISI_SAS_MAX_DEBUGFS_DUMP]; 451a70e33eaSLuo Jiaxing struct hisi_sas_debugfs_iost_cache debugfs_iost_cache[HISI_SAS_MAX_DEBUGFS_DUMP]; 452a70e33eaSLuo Jiaxing struct hisi_sas_debugfs_itct_cache debugfs_itct_cache[HISI_SAS_MAX_DEBUGFS_DUMP]; 453a70e33eaSLuo Jiaxing 454*8f643298SLuo Jiaxing u64 debugfs_timestamp[HISI_SAS_MAX_DEBUGFS_DUMP]; 455*8f643298SLuo Jiaxing int debugfs_dump_index; 456ef63464bSLuo Jiaxing struct dentry *debugfs_dir; 45749159a5eSLuo Jiaxing struct dentry *debugfs_dump_dentry; 45897b151e7SXiang Chen struct dentry *debugfs_bist_dentry; 4597eb7869fSJohn Garry }; 4607eb7869fSJohn Garry 461c799d6bdSJohn Garry /* Generic HW DMA host memory structures */ 462c799d6bdSJohn Garry /* Delivery queue header */ 463c799d6bdSJohn Garry struct hisi_sas_cmd_hdr { 464c799d6bdSJohn Garry /* dw0 */ 465c799d6bdSJohn Garry __le32 dw0; 466c799d6bdSJohn Garry 467c799d6bdSJohn Garry /* dw1 */ 468c799d6bdSJohn Garry __le32 dw1; 469c799d6bdSJohn Garry 470c799d6bdSJohn Garry /* dw2 */ 471c799d6bdSJohn Garry __le32 dw2; 472c799d6bdSJohn Garry 473c799d6bdSJohn Garry /* dw3 */ 474c799d6bdSJohn Garry __le32 transfer_tags; 475c799d6bdSJohn Garry 476c799d6bdSJohn Garry /* dw4 */ 477c799d6bdSJohn Garry __le32 data_transfer_len; 478c799d6bdSJohn Garry 479c799d6bdSJohn Garry /* dw5 */ 480c799d6bdSJohn Garry __le32 first_burst_num; 481c799d6bdSJohn Garry 482c799d6bdSJohn Garry /* dw6 */ 483c799d6bdSJohn Garry __le32 sg_len; 484c799d6bdSJohn Garry 485c799d6bdSJohn Garry /* dw7 */ 486c799d6bdSJohn Garry __le32 dw7; 487c799d6bdSJohn Garry 488c799d6bdSJohn Garry /* dw8-9 */ 489c799d6bdSJohn Garry __le64 cmd_table_addr; 490c799d6bdSJohn Garry 491c799d6bdSJohn Garry /* dw10-11 */ 492c799d6bdSJohn Garry __le64 sts_buffer_addr; 493c799d6bdSJohn Garry 494c799d6bdSJohn Garry /* dw12-13 */ 495c799d6bdSJohn Garry __le64 prd_table_addr; 496c799d6bdSJohn Garry 497c799d6bdSJohn Garry /* dw14-15 */ 498c799d6bdSJohn Garry __le64 dif_prd_table_addr; 499c799d6bdSJohn Garry }; 500c799d6bdSJohn Garry 501c799d6bdSJohn Garry struct hisi_sas_itct { 502c799d6bdSJohn Garry __le64 qw0; 503c799d6bdSJohn Garry __le64 sas_addr; 504c799d6bdSJohn Garry __le64 qw2; 505c799d6bdSJohn Garry __le64 qw3; 506281e3bf6SJohn Garry __le64 qw4_15[12]; 507c799d6bdSJohn Garry }; 508c799d6bdSJohn Garry 509c799d6bdSJohn Garry struct hisi_sas_iost { 510c799d6bdSJohn Garry __le64 qw0; 511c799d6bdSJohn Garry __le64 qw1; 512c799d6bdSJohn Garry __le64 qw2; 513c799d6bdSJohn Garry __le64 qw3; 514c799d6bdSJohn Garry }; 515c799d6bdSJohn Garry 516c799d6bdSJohn Garry struct hisi_sas_err_record { 5178d1eee7dSJohn Garry u32 data[4]; 518c799d6bdSJohn Garry }; 519c799d6bdSJohn Garry 520c799d6bdSJohn Garry struct hisi_sas_initial_fis { 521c799d6bdSJohn Garry struct hisi_sas_err_record err_record; 522c799d6bdSJohn Garry struct dev_to_host_fis fis; 523c799d6bdSJohn Garry u32 rsvd[3]; 524c799d6bdSJohn Garry }; 525c799d6bdSJohn Garry 526c799d6bdSJohn Garry struct hisi_sas_breakpoint { 5273297ded1SXiang Chen u8 data[128]; 5283297ded1SXiang Chen }; 5293297ded1SXiang Chen 5303297ded1SXiang Chen struct hisi_sas_sata_breakpoint { 5313297ded1SXiang Chen struct hisi_sas_breakpoint tag[32]; 532c799d6bdSJohn Garry }; 533c799d6bdSJohn Garry 534c799d6bdSJohn Garry struct hisi_sas_sge { 535c799d6bdSJohn Garry __le64 addr; 536c799d6bdSJohn Garry __le32 page_ctrl_0; 537c799d6bdSJohn Garry __le32 page_ctrl_1; 538c799d6bdSJohn Garry __le32 data_len; 539c799d6bdSJohn Garry __le32 data_off; 540c799d6bdSJohn Garry }; 541c799d6bdSJohn Garry 542c799d6bdSJohn Garry struct hisi_sas_command_table_smp { 543c799d6bdSJohn Garry u8 bytes[44]; 544c799d6bdSJohn Garry }; 545c799d6bdSJohn Garry 546c799d6bdSJohn Garry struct hisi_sas_command_table_stp { 547c799d6bdSJohn Garry struct host_to_dev_fis command_fis; 548c799d6bdSJohn Garry u8 dummy[12]; 549c799d6bdSJohn Garry u8 atapi_cdb[ATAPI_CDB_LEN]; 550c799d6bdSJohn Garry }; 551c799d6bdSJohn Garry 552c7669f50SJohn Garry #define HISI_SAS_SGE_PAGE_CNT (124) 553c799d6bdSJohn Garry struct hisi_sas_sge_page { 554c799d6bdSJohn Garry struct hisi_sas_sge sge[HISI_SAS_SGE_PAGE_CNT]; 555f557e32cSXiaofei Tan } __aligned(16); 556c799d6bdSJohn Garry 557c7669f50SJohn Garry #define HISI_SAS_SGE_DIF_PAGE_CNT HISI_SAS_SGE_PAGE_CNT 558b3cce125SXiang Chen struct hisi_sas_sge_dif_page { 559b3cce125SXiang Chen struct hisi_sas_sge sge[HISI_SAS_SGE_DIF_PAGE_CNT]; 560b3cce125SXiang Chen } __aligned(16); 561b3cce125SXiang Chen 562c799d6bdSJohn Garry struct hisi_sas_command_table_ssp { 563c799d6bdSJohn Garry struct ssp_frame_hdr hdr; 564c799d6bdSJohn Garry union { 565c799d6bdSJohn Garry struct { 566c799d6bdSJohn Garry struct ssp_command_iu task; 567a14da7a2SXiang Chen u32 prot[7]; 568c799d6bdSJohn Garry }; 569c799d6bdSJohn Garry struct ssp_tmf_iu ssp_task; 570c799d6bdSJohn Garry struct xfer_rdy_iu xfer_rdy; 571c799d6bdSJohn Garry struct ssp_response_iu ssp_res; 572c799d6bdSJohn Garry } u; 573c799d6bdSJohn Garry }; 574c799d6bdSJohn Garry 575c799d6bdSJohn Garry union hisi_sas_command_table { 576c799d6bdSJohn Garry struct hisi_sas_command_table_ssp ssp; 577c799d6bdSJohn Garry struct hisi_sas_command_table_smp smp; 578c799d6bdSJohn Garry struct hisi_sas_command_table_stp stp; 579f557e32cSXiaofei Tan } __aligned(16); 580f557e32cSXiaofei Tan 581f557e32cSXiaofei Tan struct hisi_sas_status_buffer { 582f557e32cSXiaofei Tan struct hisi_sas_err_record err; 583f557e32cSXiaofei Tan u8 iu[1024]; 584f557e32cSXiaofei Tan } __aligned(16); 585f557e32cSXiaofei Tan 586f557e32cSXiaofei Tan struct hisi_sas_slot_buf_table { 587f557e32cSXiaofei Tan struct hisi_sas_status_buffer status_buffer; 588f557e32cSXiaofei Tan union hisi_sas_command_table command_header; 589f557e32cSXiaofei Tan struct hisi_sas_sge_page sge_page; 590c799d6bdSJohn Garry }; 5912e244f0fSJohn Garry 592b3cce125SXiang Chen struct hisi_sas_slot_dif_buf_table { 593b3cce125SXiang Chen struct hisi_sas_slot_buf_table slot_buf; 594b3cce125SXiang Chen struct hisi_sas_sge_dif_page sge_dif_page; 595b3cce125SXiang Chen }; 596b3cce125SXiang Chen 597e21fe3a5SJohn Garry extern struct scsi_transport_template *hisi_sas_stt; 598ef63464bSLuo Jiaxing 599ef63464bSLuo Jiaxing extern bool hisi_sas_debugfs_enable; 600905ab01fSLuo Jiaxing extern u32 hisi_sas_debugfs_dump_count; 601ef63464bSLuo Jiaxing extern struct dentry *hisi_sas_debugfs_dir; 602ef63464bSLuo Jiaxing 603a25d0d3dSXiang Chen extern void hisi_sas_stop_phys(struct hisi_hba *hisi_hba); 604ae68b566SXiang Chen extern int hisi_sas_alloc(struct hisi_hba *hisi_hba); 605e21fe3a5SJohn Garry extern void hisi_sas_free(struct hisi_hba *hisi_hba); 606468f4b8dSchenxiang extern u8 hisi_sas_get_ata_protocol(struct host_to_dev_fis *fis, 607468f4b8dSchenxiang int direction); 6082e244f0fSJohn Garry extern struct hisi_sas_port *to_hisi_sas_port(struct asd_sas_port *sas_port); 60975904077SXiang Chen extern void hisi_sas_sata_done(struct sas_task *task, 61075904077SXiang Chen struct hisi_sas_slot *slot); 6110fa24c19SJohn Garry extern int hisi_sas_get_fw_info(struct hisi_hba *hisi_hba); 6129fb10b54SJohn Garry extern int hisi_sas_probe(struct platform_device *pdev, 6139fb10b54SJohn Garry const struct hisi_sas_hw *ops); 6149fb10b54SJohn Garry extern int hisi_sas_remove(struct platform_device *pdev); 615c799d6bdSJohn Garry 616235bfc7fSXiang Chen extern int hisi_sas_slave_configure(struct scsi_device *sdev); 617235bfc7fSXiang Chen extern int hisi_sas_scan_finished(struct Scsi_Host *shost, unsigned long time); 618235bfc7fSXiang Chen extern void hisi_sas_scan_start(struct Scsi_Host *shost); 619235bfc7fSXiang Chen extern int hisi_sas_host_reset(struct Scsi_Host *shost, int reset_type); 620c63b88ccSJohn Garry extern void hisi_sas_phy_enable(struct hisi_hba *hisi_hba, int phy_no, 621c63b88ccSJohn Garry int enable); 622184a4635SJohn Garry extern void hisi_sas_phy_down(struct hisi_hba *hisi_hba, int phy_no, int rdy); 62327a3f229SJohn Garry extern void hisi_sas_slot_task_free(struct hisi_hba *hisi_hba, 62427a3f229SJohn Garry struct sas_task *task, 62527a3f229SJohn Garry struct hisi_sas_slot *slot); 62606ec0fb9SXiang Chen extern void hisi_sas_init_mem(struct hisi_hba *hisi_hba); 627b4241f0fSXiaofei Tan extern void hisi_sas_rst_work_handler(struct work_struct *work); 628e402acdbSXiaofei Tan extern void hisi_sas_sync_rst_work_handler(struct work_struct *work); 629571295f8SXiaofei Tan extern void hisi_sas_kill_tasklets(struct hisi_hba *hisi_hba); 630b6c9b15eSXiaofei Tan extern void hisi_sas_phy_oob_ready(struct hisi_hba *hisi_hba, int phy_no); 631e537b62bSXiaofei Tan extern bool hisi_sas_notify_phy_event(struct hisi_sas_phy *phy, 632e537b62bSXiaofei Tan enum hisi_sas_phy_event event); 6334d0951eeSXiang Chen extern void hisi_sas_release_tasks(struct hisi_hba *hisi_hba); 634c2c1d9deSXiang Chen extern u8 hisi_sas_get_prog_phy_linkrate_mask(enum sas_linkrate max); 6354522204aSXiaofei Tan extern void hisi_sas_controller_reset_prepare(struct hisi_hba *hisi_hba); 6364522204aSXiaofei Tan extern void hisi_sas_controller_reset_done(struct hisi_hba *hisi_hba); 637ef63464bSLuo Jiaxing extern void hisi_sas_debugfs_init(struct hisi_hba *hisi_hba); 638ef63464bSLuo Jiaxing extern void hisi_sas_debugfs_exit(struct hisi_hba *hisi_hba); 63949159a5eSLuo Jiaxing extern void hisi_sas_debugfs_work_handler(struct work_struct *work); 640e8899fadSJohn Garry #endif 641