1 /* SPDX-License-Identifier: GPL-2.0-or-later */ 2 /* 3 * Copyright (c) 2015 Linaro Ltd. 4 * Copyright (c) 2015 Hisilicon Limited. 5 */ 6 7 #ifndef _HISI_SAS_H_ 8 #define _HISI_SAS_H_ 9 10 #include <linux/acpi.h> 11 #include <linux/blk-mq.h> 12 #include <linux/clk.h> 13 #include <linux/debugfs.h> 14 #include <linux/dmapool.h> 15 #include <linux/iopoll.h> 16 #include <linux/irq.h> 17 #include <linux/lcm.h> 18 #include <linux/libata.h> 19 #include <linux/mfd/syscon.h> 20 #include <linux/module.h> 21 #include <linux/of_address.h> 22 #include <linux/pci.h> 23 #include <linux/platform_device.h> 24 #include <linux/pm_runtime.h> 25 #include <linux/property.h> 26 #include <linux/regmap.h> 27 #include <linux/timer.h> 28 #include <scsi/sas_ata.h> 29 #include <scsi/libsas.h> 30 31 #define HISI_SAS_MAX_PHYS 9 32 #define HISI_SAS_MAX_QUEUES 32 33 #define HISI_SAS_QUEUE_SLOTS 4096 34 #define HISI_SAS_MAX_ITCT_ENTRIES 1024 35 #define HISI_SAS_MAX_DEVICES HISI_SAS_MAX_ITCT_ENTRIES 36 #define HISI_SAS_RESETTING_BIT 0 37 #define HISI_SAS_REJECT_CMD_BIT 1 38 #define HISI_SAS_PM_BIT 2 39 #define HISI_SAS_HW_FAULT_BIT 3 40 #define HISI_SAS_MAX_COMMANDS (HISI_SAS_QUEUE_SLOTS) 41 #define HISI_SAS_RESERVED_IPTT 96 42 #define HISI_SAS_UNRESERVED_IPTT \ 43 (HISI_SAS_MAX_COMMANDS - HISI_SAS_RESERVED_IPTT) 44 45 #define HISI_SAS_IOST_ITCT_CACHE_NUM 64 46 #define HISI_SAS_IOST_ITCT_CACHE_DW_SZ 10 47 #define HISI_SAS_FIFO_DATA_DW_SIZE 32 48 49 #define HISI_SAS_REG_MEM_SIZE 4 50 #define HISI_SAS_MAX_CDB_LEN 16 51 #define HISI_SAS_BLK_QUEUE_DEPTH 64 52 53 #define BYTE_TO_DW 4 54 #define BYTE_TO_DDW 8 55 56 #define HISI_SAS_STATUS_BUF_SZ (sizeof(struct hisi_sas_status_buffer)) 57 #define HISI_SAS_COMMAND_TABLE_SZ (sizeof(union hisi_sas_command_table)) 58 59 #define hisi_sas_status_buf_addr(buf) \ 60 ((buf) + offsetof(struct hisi_sas_slot_buf_table, status_buffer)) 61 #define hisi_sas_status_buf_addr_mem(slot) hisi_sas_status_buf_addr((slot)->buf) 62 #define hisi_sas_status_buf_addr_dma(slot) \ 63 hisi_sas_status_buf_addr((slot)->buf_dma) 64 65 #define hisi_sas_cmd_hdr_addr(buf) \ 66 ((buf) + offsetof(struct hisi_sas_slot_buf_table, command_header)) 67 #define hisi_sas_cmd_hdr_addr_mem(slot) hisi_sas_cmd_hdr_addr((slot)->buf) 68 #define hisi_sas_cmd_hdr_addr_dma(slot) hisi_sas_cmd_hdr_addr((slot)->buf_dma) 69 70 #define hisi_sas_sge_addr(buf) \ 71 ((buf) + offsetof(struct hisi_sas_slot_buf_table, sge_page)) 72 #define hisi_sas_sge_addr_mem(slot) hisi_sas_sge_addr((slot)->buf) 73 #define hisi_sas_sge_addr_dma(slot) hisi_sas_sge_addr((slot)->buf_dma) 74 75 #define hisi_sas_sge_dif_addr(buf) \ 76 ((buf) + offsetof(struct hisi_sas_slot_dif_buf_table, sge_dif_page)) 77 #define hisi_sas_sge_dif_addr_mem(slot) hisi_sas_sge_dif_addr((slot)->buf) 78 #define hisi_sas_sge_dif_addr_dma(slot) hisi_sas_sge_dif_addr((slot)->buf_dma) 79 80 #define HISI_SAS_MAX_SSP_RESP_SZ (sizeof(struct ssp_frame_hdr) + 1024) 81 #define HISI_SAS_MAX_SMP_RESP_SZ 1028 82 #define HISI_SAS_MAX_STP_RESP_SZ 28 83 84 #define HISI_SAS_SATA_PROTOCOL_NONDATA 0x1 85 #define HISI_SAS_SATA_PROTOCOL_PIO 0x2 86 #define HISI_SAS_SATA_PROTOCOL_DMA 0x4 87 #define HISI_SAS_SATA_PROTOCOL_FPDMA 0x8 88 #define HISI_SAS_SATA_PROTOCOL_ATAPI 0x10 89 90 #define HISI_SAS_DIF_PROT_MASK (SHOST_DIF_TYPE1_PROTECTION | \ 91 SHOST_DIF_TYPE2_PROTECTION | \ 92 SHOST_DIF_TYPE3_PROTECTION) 93 94 #define HISI_SAS_DIX_PROT_MASK (SHOST_DIX_TYPE1_PROTECTION | \ 95 SHOST_DIX_TYPE2_PROTECTION | \ 96 SHOST_DIX_TYPE3_PROTECTION) 97 98 #define HISI_SAS_PROT_MASK (HISI_SAS_DIF_PROT_MASK | HISI_SAS_DIX_PROT_MASK) 99 100 #define HISI_SAS_WAIT_PHYUP_TIMEOUT (30 * HZ) 101 #define HISI_SAS_CLEAR_ITCT_TIMEOUT (20 * HZ) 102 #define HISI_SAS_DELAY_FOR_PHY_DISABLE 100 103 #define NAME_BUF_SIZE 256 104 105 struct hisi_hba; 106 107 enum { 108 PORT_TYPE_SAS = (1U << 1), 109 PORT_TYPE_SATA = (1U << 0), 110 }; 111 112 enum dev_status { 113 HISI_SAS_DEV_INIT, 114 HISI_SAS_DEV_NORMAL, 115 HISI_SAS_DEV_NCQ_ERR, 116 }; 117 118 enum { 119 HISI_SAS_INT_ABT_CMD = 0, 120 HISI_SAS_INT_ABT_DEV = 1, 121 }; 122 123 enum hisi_sas_dev_type { 124 HISI_SAS_DEV_TYPE_STP = 0, 125 HISI_SAS_DEV_TYPE_SSP, 126 HISI_SAS_DEV_TYPE_SATA, 127 }; 128 129 struct hisi_sas_hw_error { 130 u32 irq_msk; 131 u32 msk; 132 int shift; 133 const char *msg; 134 int reg; 135 const struct hisi_sas_hw_error *sub; 136 }; 137 138 struct hisi_sas_rst { 139 struct hisi_hba *hisi_hba; 140 struct completion *completion; 141 struct work_struct work; 142 bool done; 143 }; 144 145 #define HISI_SAS_RST_WORK_INIT(r, c) \ 146 { .hisi_hba = hisi_hba, \ 147 .completion = &c, \ 148 .work = __WORK_INITIALIZER(r.work, \ 149 hisi_sas_sync_rst_work_handler), \ 150 .done = false, \ 151 } 152 153 #define HISI_SAS_DECLARE_RST_WORK_ON_STACK(r) \ 154 DECLARE_COMPLETION_ONSTACK(c); \ 155 struct hisi_sas_rst r = HISI_SAS_RST_WORK_INIT(r, c) 156 157 enum hisi_sas_bit_err_type { 158 HISI_SAS_ERR_SINGLE_BIT_ECC = 0x0, 159 HISI_SAS_ERR_MULTI_BIT_ECC = 0x1, 160 }; 161 162 enum hisi_sas_phy_event { 163 HISI_PHYE_PHY_UP = 0U, 164 HISI_PHYE_LINK_RESET, 165 HISI_PHYE_PHY_UP_PM, 166 HISI_PHYE_SPINUP_NOTIFY, 167 HISI_PHYES_NUM, 168 }; 169 170 struct hisi_sas_debugfs_fifo { 171 u32 signal_sel; 172 u32 dump_msk; 173 u32 dump_mode; 174 u32 trigger; 175 u32 trigger_msk; 176 u32 trigger_mode; 177 u32 rd_data[HISI_SAS_FIFO_DATA_DW_SIZE]; 178 }; 179 180 #define FRAME_RCVD_BUF 32 181 #define SAS_PHY_RESV_SIZE 2 182 struct hisi_sas_phy { 183 struct work_struct works[HISI_PHYES_NUM]; 184 struct hisi_hba *hisi_hba; 185 struct hisi_sas_port *port; 186 struct asd_sas_phy sas_phy; 187 struct sas_identify identify; 188 struct completion *reset_completion; 189 struct timer_list timer; 190 spinlock_t lock; 191 u64 port_id; /* from hw */ 192 u64 frame_rcvd_size; 193 u8 frame_rcvd[FRAME_RCVD_BUF]; 194 u8 phy_attached; 195 u8 in_reset; 196 u8 reserved[SAS_PHY_RESV_SIZE]; 197 u32 phy_type; 198 u32 code_violation_err_count; 199 enum sas_linkrate minimum_linkrate; 200 enum sas_linkrate maximum_linkrate; 201 int enable; 202 int wait_phyup_cnt; 203 atomic_t down_cnt; 204 205 /* Trace FIFO */ 206 struct hisi_sas_debugfs_fifo fifo; 207 }; 208 209 struct hisi_sas_port { 210 struct asd_sas_port sas_port; 211 u8 port_attached; 212 u8 id; /* from hw */ 213 }; 214 215 struct hisi_sas_cq { 216 struct hisi_hba *hisi_hba; 217 const struct cpumask *irq_mask; 218 int rd_point; 219 int id; 220 int irq_no; 221 spinlock_t poll_lock; 222 }; 223 224 struct hisi_sas_dq { 225 struct hisi_hba *hisi_hba; 226 struct list_head list; 227 spinlock_t lock; 228 int wr_point; 229 int id; 230 }; 231 232 struct hisi_sas_device { 233 struct hisi_hba *hisi_hba; 234 struct domain_device *sas_device; 235 struct completion *completion; 236 struct hisi_sas_dq *dq; 237 struct list_head list; 238 enum sas_device_type dev_type; 239 enum dev_status dev_status; 240 int device_id; 241 int sata_idx; 242 spinlock_t lock; /* For protecting slots */ 243 }; 244 245 struct hisi_sas_slot { 246 struct list_head entry; 247 struct list_head delivery; 248 struct sas_task *task; 249 struct hisi_sas_port *port; 250 u64 n_elem; 251 u64 n_elem_dif; 252 int dlvry_queue; 253 int dlvry_queue_slot; 254 int cmplt_queue; 255 int cmplt_queue_slot; 256 int abort; 257 int ready; 258 int device_id; 259 void *cmd_hdr; 260 dma_addr_t cmd_hdr_dma; 261 struct timer_list internal_abort_timer; 262 bool is_internal; 263 struct sas_tmf_task *tmf; 264 /* Do not reorder/change members after here */ 265 void *buf; 266 dma_addr_t buf_dma; 267 u16 idx; 268 }; 269 270 struct hisi_sas_iost_itct_cache { 271 u32 data[HISI_SAS_IOST_ITCT_CACHE_DW_SZ]; 272 }; 273 274 enum hisi_sas_debugfs_reg_array_member { 275 DEBUGFS_GLOBAL = 0, 276 DEBUGFS_AXI, 277 DEBUGFS_RAS, 278 DEBUGFS_REGS_NUM 279 }; 280 281 enum hisi_sas_debugfs_cache_type { 282 HISI_SAS_ITCT_CACHE, 283 HISI_SAS_IOST_CACHE, 284 }; 285 286 enum hisi_sas_debugfs_bist_ffe_cfg { 287 FFE_SAS_1_5_GBPS, 288 FFE_SAS_3_0_GBPS, 289 FFE_SAS_6_0_GBPS, 290 FFE_SAS_12_0_GBPS, 291 FFE_RESV, 292 FFE_SATA_1_5_GBPS, 293 FFE_SATA_3_0_GBPS, 294 FFE_SATA_6_0_GBPS, 295 FFE_CFG_MAX 296 }; 297 298 enum hisi_sas_debugfs_bist_fixed_code { 299 FIXED_CODE, 300 FIXED_CODE_1, 301 FIXED_CODE_MAX 302 }; 303 304 enum { 305 HISI_SAS_BIST_CODE_MODE_PRBS7, 306 HISI_SAS_BIST_CODE_MODE_PRBS23, 307 HISI_SAS_BIST_CODE_MODE_PRBS31, 308 HISI_SAS_BIST_CODE_MODE_JTPAT, 309 HISI_SAS_BIST_CODE_MODE_CJTPAT, 310 HISI_SAS_BIST_CODE_MODE_SCRAMBED_0, 311 HISI_SAS_BIST_CODE_MODE_TRAIN, 312 HISI_SAS_BIST_CODE_MODE_TRAIN_DONE, 313 HISI_SAS_BIST_CODE_MODE_HFTP, 314 HISI_SAS_BIST_CODE_MODE_MFTP, 315 HISI_SAS_BIST_CODE_MODE_LFTP, 316 HISI_SAS_BIST_CODE_MODE_FIXED_DATA, 317 }; 318 319 struct hisi_sas_hw { 320 int (*hw_init)(struct hisi_hba *hisi_hba); 321 int (*fw_info_check)(struct hisi_hba *hisi_hba); 322 int (*interrupt_preinit)(struct hisi_hba *hisi_hba); 323 void (*setup_itct)(struct hisi_hba *hisi_hba, 324 struct hisi_sas_device *device); 325 int (*slot_index_alloc)(struct hisi_hba *hisi_hba, 326 struct domain_device *device); 327 struct hisi_sas_device *(*alloc_dev)(struct domain_device *device); 328 void (*sl_notify_ssp)(struct hisi_hba *hisi_hba, int phy_no); 329 void (*start_delivery)(struct hisi_sas_dq *dq); 330 void (*prep_ssp)(struct hisi_hba *hisi_hba, 331 struct hisi_sas_slot *slot); 332 void (*prep_smp)(struct hisi_hba *hisi_hba, 333 struct hisi_sas_slot *slot); 334 void (*prep_stp)(struct hisi_hba *hisi_hba, 335 struct hisi_sas_slot *slot); 336 void (*prep_abort)(struct hisi_hba *hisi_hba, 337 struct hisi_sas_slot *slot); 338 void (*phys_init)(struct hisi_hba *hisi_hba); 339 void (*phy_start)(struct hisi_hba *hisi_hba, int phy_no); 340 void (*phy_disable)(struct hisi_hba *hisi_hba, int phy_no); 341 void (*phy_hard_reset)(struct hisi_hba *hisi_hba, int phy_no); 342 void (*get_events)(struct hisi_hba *hisi_hba, int phy_no); 343 void (*phy_set_linkrate)(struct hisi_hba *hisi_hba, int phy_no, 344 struct sas_phy_linkrates *linkrates); 345 enum sas_linkrate (*phy_get_max_linkrate)(void); 346 int (*clear_itct)(struct hisi_hba *hisi_hba, 347 struct hisi_sas_device *dev); 348 void (*free_device)(struct hisi_sas_device *sas_dev); 349 int (*get_wideport_bitmap)(struct hisi_hba *hisi_hba, int port_id); 350 void (*dereg_device)(struct hisi_hba *hisi_hba, 351 struct domain_device *device); 352 int (*soft_reset)(struct hisi_hba *hisi_hba); 353 u32 (*get_phys_state)(struct hisi_hba *hisi_hba); 354 int (*write_gpio)(struct hisi_hba *hisi_hba, u8 reg_type, 355 u8 reg_index, u8 reg_count, u8 *write_data); 356 void (*wait_cmds_complete_timeout)(struct hisi_hba *hisi_hba, 357 int delay_ms, int timeout_ms); 358 int (*debugfs_snapshot_regs)(struct hisi_hba *hisi_hba); 359 int complete_hdr_size; 360 const struct scsi_host_template *sht; 361 }; 362 363 #define HISI_SAS_MAX_DEBUGFS_DUMP 50 364 #define HISI_SAS_DEFAULT_DEBUGFS_DUMP 1 365 366 struct hisi_sas_debugfs_cq { 367 struct hisi_sas_cq *cq; 368 void *complete_hdr; 369 }; 370 371 struct hisi_sas_debugfs_dq { 372 struct hisi_sas_dq *dq; 373 struct hisi_sas_cmd_hdr *hdr; 374 }; 375 376 struct hisi_sas_debugfs_regs { 377 struct hisi_hba *hisi_hba; 378 u32 *data; 379 }; 380 381 struct hisi_sas_debugfs_port { 382 struct hisi_sas_phy *phy; 383 u32 *data; 384 }; 385 386 struct hisi_sas_debugfs_iost { 387 struct hisi_sas_iost *iost; 388 }; 389 390 struct hisi_sas_debugfs_itct { 391 struct hisi_sas_itct *itct; 392 }; 393 394 struct hisi_sas_debugfs_iost_cache { 395 struct hisi_sas_iost_itct_cache *cache; 396 }; 397 398 struct hisi_sas_debugfs_itct_cache { 399 struct hisi_sas_iost_itct_cache *cache; 400 }; 401 402 struct hisi_hba { 403 /* This must be the first element, used by SHOST_TO_SAS_HA */ 404 struct sas_ha_struct *p; 405 406 struct platform_device *platform_dev; 407 struct pci_dev *pci_dev; 408 struct device *dev; 409 410 int prot_mask; 411 412 void __iomem *regs; 413 void __iomem *sgpio_regs; 414 struct regmap *ctrl; 415 u32 ctrl_reset_reg; 416 u32 ctrl_reset_sts_reg; 417 u32 ctrl_clock_ena_reg; 418 u32 refclk_frequency_mhz; 419 u8 sas_addr[SAS_ADDR_SIZE]; 420 421 int *irq_map; /* v2 hw */ 422 423 int n_phy; 424 spinlock_t lock; 425 struct semaphore sem; 426 427 struct timer_list timer; 428 struct workqueue_struct *wq; 429 430 int slot_index_count; 431 int last_slot_index; 432 int last_dev_id; 433 unsigned long *slot_index_tags; 434 unsigned long reject_stp_links_msk; 435 436 /* SCSI/SAS glue */ 437 struct sas_ha_struct sha; 438 struct Scsi_Host *shost; 439 440 struct hisi_sas_cq cq[HISI_SAS_MAX_QUEUES]; 441 struct hisi_sas_dq dq[HISI_SAS_MAX_QUEUES]; 442 struct hisi_sas_phy phy[HISI_SAS_MAX_PHYS]; 443 struct hisi_sas_port port[HISI_SAS_MAX_PHYS]; 444 445 int queue_count; 446 447 struct hisi_sas_device devices[HISI_SAS_MAX_DEVICES]; 448 struct hisi_sas_cmd_hdr *cmd_hdr[HISI_SAS_MAX_QUEUES]; 449 dma_addr_t cmd_hdr_dma[HISI_SAS_MAX_QUEUES]; 450 void *complete_hdr[HISI_SAS_MAX_QUEUES]; 451 dma_addr_t complete_hdr_dma[HISI_SAS_MAX_QUEUES]; 452 struct hisi_sas_initial_fis *initial_fis; 453 dma_addr_t initial_fis_dma; 454 struct hisi_sas_itct *itct; 455 dma_addr_t itct_dma; 456 struct hisi_sas_iost *iost; 457 dma_addr_t iost_dma; 458 struct hisi_sas_breakpoint *breakpoint; 459 dma_addr_t breakpoint_dma; 460 struct hisi_sas_breakpoint *sata_breakpoint; 461 dma_addr_t sata_breakpoint_dma; 462 struct hisi_sas_slot *slot_info; 463 unsigned long flags; 464 const struct hisi_sas_hw *hw; /* Low level hw interface */ 465 unsigned long sata_dev_bitmap[BITS_TO_LONGS(HISI_SAS_MAX_DEVICES)]; 466 struct work_struct rst_work; 467 u32 phy_state; 468 u32 intr_coal_ticks; /* Time of interrupt coalesce in us */ 469 u32 intr_coal_count; /* Interrupt count to coalesce */ 470 471 int cq_nvecs; 472 473 /* bist */ 474 enum sas_linkrate debugfs_bist_linkrate; 475 int debugfs_bist_code_mode; 476 int debugfs_bist_phy_no; 477 int debugfs_bist_mode; 478 u32 debugfs_bist_cnt; 479 int debugfs_bist_enable; 480 u32 debugfs_bist_ffe[HISI_SAS_MAX_PHYS][FFE_CFG_MAX]; 481 u32 debugfs_bist_fixed_code[FIXED_CODE_MAX]; 482 483 /* debugfs memories */ 484 /* Put Global AXI and RAS Register into register array */ 485 struct hisi_sas_debugfs_regs debugfs_regs[HISI_SAS_MAX_DEBUGFS_DUMP][DEBUGFS_REGS_NUM]; 486 struct hisi_sas_debugfs_port debugfs_port_reg[HISI_SAS_MAX_DEBUGFS_DUMP][HISI_SAS_MAX_PHYS]; 487 struct hisi_sas_debugfs_cq debugfs_cq[HISI_SAS_MAX_DEBUGFS_DUMP][HISI_SAS_MAX_QUEUES]; 488 struct hisi_sas_debugfs_dq debugfs_dq[HISI_SAS_MAX_DEBUGFS_DUMP][HISI_SAS_MAX_QUEUES]; 489 struct hisi_sas_debugfs_iost debugfs_iost[HISI_SAS_MAX_DEBUGFS_DUMP]; 490 struct hisi_sas_debugfs_itct debugfs_itct[HISI_SAS_MAX_DEBUGFS_DUMP]; 491 struct hisi_sas_debugfs_iost_cache debugfs_iost_cache[HISI_SAS_MAX_DEBUGFS_DUMP]; 492 struct hisi_sas_debugfs_itct_cache debugfs_itct_cache[HISI_SAS_MAX_DEBUGFS_DUMP]; 493 494 u64 debugfs_timestamp[HISI_SAS_MAX_DEBUGFS_DUMP]; 495 int debugfs_dump_index; 496 struct dentry *debugfs_dir; 497 struct dentry *debugfs_dump_dentry; 498 struct dentry *debugfs_bist_dentry; 499 struct dentry *debugfs_fifo_dentry; 500 501 int iopoll_q_cnt; 502 }; 503 504 /* Generic HW DMA host memory structures */ 505 /* Delivery queue header */ 506 struct hisi_sas_cmd_hdr { 507 /* dw0 */ 508 __le32 dw0; 509 510 /* dw1 */ 511 __le32 dw1; 512 513 /* dw2 */ 514 __le32 dw2; 515 516 /* dw3 */ 517 __le32 transfer_tags; 518 519 /* dw4 */ 520 __le32 data_transfer_len; 521 522 /* dw5 */ 523 __le32 first_burst_num; 524 525 /* dw6 */ 526 __le32 sg_len; 527 528 /* dw7 */ 529 __le32 dw7; 530 531 /* dw8-9 */ 532 __le64 cmd_table_addr; 533 534 /* dw10-11 */ 535 __le64 sts_buffer_addr; 536 537 /* dw12-13 */ 538 __le64 prd_table_addr; 539 540 /* dw14-15 */ 541 __le64 dif_prd_table_addr; 542 }; 543 544 #define ITCT_RESV_DDW 12 545 struct hisi_sas_itct { 546 __le64 qw0; 547 __le64 sas_addr; 548 __le64 qw2; 549 __le64 qw3; 550 __le64 qw4_15[ITCT_RESV_DDW]; 551 }; 552 553 struct hisi_sas_iost { 554 __le64 qw0; 555 __le64 qw1; 556 __le64 qw2; 557 __le64 qw3; 558 }; 559 560 #define ERROR_RECORD_BUF_DW 4 561 struct hisi_sas_err_record { 562 u32 data[ERROR_RECORD_BUF_DW]; 563 }; 564 565 #define FIS_RESV_DW 3 566 struct hisi_sas_initial_fis { 567 struct hisi_sas_err_record err_record; 568 struct dev_to_host_fis fis; 569 u32 rsvd[FIS_RESV_DW]; 570 }; 571 572 #define BREAKPOINT_DATA_SIZE 128 573 struct hisi_sas_breakpoint { 574 u8 data[BREAKPOINT_DATA_SIZE]; 575 }; 576 577 #define BREAKPOINT_TAG_NUM 32 578 struct hisi_sas_sata_breakpoint { 579 struct hisi_sas_breakpoint tag[BREAKPOINT_TAG_NUM]; 580 }; 581 582 struct hisi_sas_sge { 583 __le64 addr; 584 __le32 page_ctrl_0; 585 __le32 page_ctrl_1; 586 __le32 data_len; 587 __le32 data_off; 588 }; 589 590 #define SMP_CMD_TABLE_SIZE 44 591 struct hisi_sas_command_table_smp { 592 u8 bytes[SMP_CMD_TABLE_SIZE]; 593 }; 594 595 #define DUMMY_BUF_SIZE 12 596 struct hisi_sas_command_table_stp { 597 struct host_to_dev_fis command_fis; 598 u8 dummy[DUMMY_BUF_SIZE]; 599 u8 atapi_cdb[ATAPI_CDB_LEN]; 600 }; 601 602 #define HISI_SAS_SGE_PAGE_CNT (124) 603 struct hisi_sas_sge_page { 604 struct hisi_sas_sge sge[HISI_SAS_SGE_PAGE_CNT]; 605 } __aligned(16); 606 607 #define HISI_SAS_SGE_DIF_PAGE_CNT HISI_SAS_SGE_PAGE_CNT 608 struct hisi_sas_sge_dif_page { 609 struct hisi_sas_sge sge[HISI_SAS_SGE_DIF_PAGE_CNT]; 610 } __aligned(16); 611 612 #define PROT_BUF_SIZE 7 613 struct hisi_sas_command_table_ssp { 614 struct ssp_frame_hdr hdr; 615 union { 616 struct { 617 struct ssp_command_iu task; 618 u32 prot[PROT_BUF_SIZE]; 619 }; 620 struct ssp_tmf_iu ssp_task; 621 struct xfer_rdy_iu xfer_rdy; 622 struct ssp_response_iu ssp_res; 623 } u; 624 }; 625 626 union hisi_sas_command_table { 627 struct hisi_sas_command_table_ssp ssp; 628 struct hisi_sas_command_table_smp smp; 629 struct hisi_sas_command_table_stp stp; 630 } __aligned(16); 631 632 #define IU_BUF_SIZE 1024 633 struct hisi_sas_status_buffer { 634 struct hisi_sas_err_record err; 635 u8 iu[IU_BUF_SIZE]; 636 } __aligned(16); 637 638 struct hisi_sas_slot_buf_table { 639 struct hisi_sas_status_buffer status_buffer; 640 union hisi_sas_command_table command_header; 641 struct hisi_sas_sge_page sge_page; 642 }; 643 644 struct hisi_sas_slot_dif_buf_table { 645 struct hisi_sas_slot_buf_table slot_buf; 646 struct hisi_sas_sge_dif_page sge_dif_page; 647 }; 648 649 extern struct scsi_transport_template *hisi_sas_stt; 650 651 extern bool hisi_sas_debugfs_enable; 652 extern u32 hisi_sas_debugfs_dump_count; 653 extern struct dentry *hisi_sas_debugfs_dir; 654 655 extern void hisi_sas_stop_phys(struct hisi_hba *hisi_hba); 656 extern int hisi_sas_alloc(struct hisi_hba *hisi_hba); 657 extern void hisi_sas_free(struct hisi_hba *hisi_hba); 658 extern u8 hisi_sas_get_ata_protocol(struct sas_task *task); 659 extern struct hisi_sas_port *to_hisi_sas_port(struct asd_sas_port *sas_port); 660 extern void hisi_sas_sata_done(struct sas_task *task, 661 struct hisi_sas_slot *slot); 662 extern int hisi_sas_get_fw_info(struct hisi_hba *hisi_hba); 663 extern int hisi_sas_probe(struct platform_device *pdev, 664 const struct hisi_sas_hw *ops); 665 extern void hisi_sas_remove(struct platform_device *pdev); 666 667 int hisi_sas_sdev_configure(struct scsi_device *sdev, struct queue_limits *lim); 668 extern int hisi_sas_sdev_init(struct scsi_device *sdev); 669 extern int hisi_sas_scan_finished(struct Scsi_Host *shost, unsigned long time); 670 extern void hisi_sas_scan_start(struct Scsi_Host *shost); 671 extern int hisi_sas_host_reset(struct Scsi_Host *shost, int reset_type); 672 extern void hisi_sas_phy_enable(struct hisi_hba *hisi_hba, int phy_no, 673 int enable); 674 extern void hisi_sas_phy_down(struct hisi_hba *hisi_hba, int phy_no, int rdy, 675 gfp_t gfp_flags); 676 extern void hisi_sas_phy_bcast(struct hisi_sas_phy *phy); 677 extern void hisi_sas_slot_task_free(struct hisi_hba *hisi_hba, 678 struct sas_task *task, 679 struct hisi_sas_slot *slot, 680 bool need_lock); 681 extern void hisi_sas_init_mem(struct hisi_hba *hisi_hba); 682 extern void hisi_sas_rst_work_handler(struct work_struct *work); 683 extern void hisi_sas_sync_rst_work_handler(struct work_struct *work); 684 extern void hisi_sas_phy_oob_ready(struct hisi_hba *hisi_hba, int phy_no); 685 extern bool hisi_sas_notify_phy_event(struct hisi_sas_phy *phy, 686 enum hisi_sas_phy_event event); 687 extern void hisi_sas_release_tasks(struct hisi_hba *hisi_hba); 688 extern u8 hisi_sas_get_prog_phy_linkrate_mask(enum sas_linkrate max); 689 extern void hisi_sas_sync_cqs(struct hisi_hba *hisi_hba); 690 extern void hisi_sas_sync_poll_cqs(struct hisi_hba *hisi_hba); 691 extern void hisi_sas_controller_reset_prepare(struct hisi_hba *hisi_hba); 692 extern void hisi_sas_controller_reset_done(struct hisi_hba *hisi_hba); 693 extern void hisi_sas_spinup_notify(struct hisi_hba *hisi_hba, 694 struct sas_task *task); 695 #endif 696