hisi_sas.h 18 KB

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