hisi_sas_v1_hw.c 55 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882
  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. #include "hisi_sas.h"
  12. #define DRV_NAME "hisi_sas_v1_hw"
  13. /* global registers need init*/
  14. #define DLVRY_QUEUE_ENABLE 0x0
  15. #define IOST_BASE_ADDR_LO 0x8
  16. #define IOST_BASE_ADDR_HI 0xc
  17. #define ITCT_BASE_ADDR_LO 0x10
  18. #define ITCT_BASE_ADDR_HI 0x14
  19. #define BROKEN_MSG_ADDR_LO 0x18
  20. #define BROKEN_MSG_ADDR_HI 0x1c
  21. #define PHY_CONTEXT 0x20
  22. #define PHY_STATE 0x24
  23. #define PHY_PORT_NUM_MA 0x28
  24. #define PORT_STATE 0x2c
  25. #define PHY_CONN_RATE 0x30
  26. #define HGC_TRANS_TASK_CNT_LIMIT 0x38
  27. #define AXI_AHB_CLK_CFG 0x3c
  28. #define HGC_SAS_TXFAIL_RETRY_CTRL 0x84
  29. #define HGC_GET_ITV_TIME 0x90
  30. #define DEVICE_MSG_WORK_MODE 0x94
  31. #define I_T_NEXUS_LOSS_TIME 0xa0
  32. #define BUS_INACTIVE_LIMIT_TIME 0xa8
  33. #define REJECT_TO_OPEN_LIMIT_TIME 0xac
  34. #define CFG_AGING_TIME 0xbc
  35. #define CFG_AGING_TIME_ITCT_REL_OFF 0
  36. #define CFG_AGING_TIME_ITCT_REL_MSK (0x1 << CFG_AGING_TIME_ITCT_REL_OFF)
  37. #define HGC_DFX_CFG2 0xc0
  38. #define FIS_LIST_BADDR_L 0xc4
  39. #define CFG_1US_TIMER_TRSH 0xcc
  40. #define CFG_SAS_CONFIG 0xd4
  41. #define HGC_IOST_ECC_ADDR 0x140
  42. #define HGC_IOST_ECC_ADDR_BAD_OFF 16
  43. #define HGC_IOST_ECC_ADDR_BAD_MSK (0x3ff << HGC_IOST_ECC_ADDR_BAD_OFF)
  44. #define HGC_DQ_ECC_ADDR 0x144
  45. #define HGC_DQ_ECC_ADDR_BAD_OFF 16
  46. #define HGC_DQ_ECC_ADDR_BAD_MSK (0xfff << HGC_DQ_ECC_ADDR_BAD_OFF)
  47. #define HGC_INVLD_DQE_INFO 0x148
  48. #define HGC_INVLD_DQE_INFO_DQ_OFF 0
  49. #define HGC_INVLD_DQE_INFO_DQ_MSK (0xffff << HGC_INVLD_DQE_INFO_DQ_OFF)
  50. #define HGC_INVLD_DQE_INFO_TYPE_OFF 16
  51. #define HGC_INVLD_DQE_INFO_TYPE_MSK (0x1 << HGC_INVLD_DQE_INFO_TYPE_OFF)
  52. #define HGC_INVLD_DQE_INFO_FORCE_OFF 17
  53. #define HGC_INVLD_DQE_INFO_FORCE_MSK (0x1 << HGC_INVLD_DQE_INFO_FORCE_OFF)
  54. #define HGC_INVLD_DQE_INFO_PHY_OFF 18
  55. #define HGC_INVLD_DQE_INFO_PHY_MSK (0x1 << HGC_INVLD_DQE_INFO_PHY_OFF)
  56. #define HGC_INVLD_DQE_INFO_ABORT_OFF 19
  57. #define HGC_INVLD_DQE_INFO_ABORT_MSK (0x1 << HGC_INVLD_DQE_INFO_ABORT_OFF)
  58. #define HGC_INVLD_DQE_INFO_IPTT_OF_OFF 20
  59. #define HGC_INVLD_DQE_INFO_IPTT_OF_MSK (0x1 << HGC_INVLD_DQE_INFO_IPTT_OF_OFF)
  60. #define HGC_INVLD_DQE_INFO_SSP_ERR_OFF 21
  61. #define HGC_INVLD_DQE_INFO_SSP_ERR_MSK (0x1 << HGC_INVLD_DQE_INFO_SSP_ERR_OFF)
  62. #define HGC_INVLD_DQE_INFO_OFL_OFF 22
  63. #define HGC_INVLD_DQE_INFO_OFL_MSK (0x1 << HGC_INVLD_DQE_INFO_OFL_OFF)
  64. #define HGC_ITCT_ECC_ADDR 0x150
  65. #define HGC_ITCT_ECC_ADDR_BAD_OFF 16
  66. #define HGC_ITCT_ECC_ADDR_BAD_MSK (0x3ff << HGC_ITCT_ECC_ADDR_BAD_OFF)
  67. #define HGC_AXI_FIFO_ERR_INFO 0x154
  68. #define INT_COAL_EN 0x1bc
  69. #define OQ_INT_COAL_TIME 0x1c0
  70. #define OQ_INT_COAL_CNT 0x1c4
  71. #define ENT_INT_COAL_TIME 0x1c8
  72. #define ENT_INT_COAL_CNT 0x1cc
  73. #define OQ_INT_SRC 0x1d0
  74. #define OQ_INT_SRC_MSK 0x1d4
  75. #define ENT_INT_SRC1 0x1d8
  76. #define ENT_INT_SRC2 0x1dc
  77. #define ENT_INT_SRC2_DQ_CFG_ERR_OFF 25
  78. #define ENT_INT_SRC2_DQ_CFG_ERR_MSK (0x1 << ENT_INT_SRC2_DQ_CFG_ERR_OFF)
  79. #define ENT_INT_SRC2_CQ_CFG_ERR_OFF 27
  80. #define ENT_INT_SRC2_CQ_CFG_ERR_MSK (0x1 << ENT_INT_SRC2_CQ_CFG_ERR_OFF)
  81. #define ENT_INT_SRC2_AXI_WRONG_INT_OFF 28
  82. #define ENT_INT_SRC2_AXI_WRONG_INT_MSK (0x1 << ENT_INT_SRC2_AXI_WRONG_INT_OFF)
  83. #define ENT_INT_SRC2_AXI_OVERLF_INT_OFF 29
  84. #define ENT_INT_SRC2_AXI_OVERLF_INT_MSK (0x1 << ENT_INT_SRC2_AXI_OVERLF_INT_OFF)
  85. #define ENT_INT_SRC_MSK1 0x1e0
  86. #define ENT_INT_SRC_MSK2 0x1e4
  87. #define SAS_ECC_INTR 0x1e8
  88. #define SAS_ECC_INTR_DQ_ECC1B_OFF 0
  89. #define SAS_ECC_INTR_DQ_ECC1B_MSK (0x1 << SAS_ECC_INTR_DQ_ECC1B_OFF)
  90. #define SAS_ECC_INTR_DQ_ECCBAD_OFF 1
  91. #define SAS_ECC_INTR_DQ_ECCBAD_MSK (0x1 << SAS_ECC_INTR_DQ_ECCBAD_OFF)
  92. #define SAS_ECC_INTR_IOST_ECC1B_OFF 2
  93. #define SAS_ECC_INTR_IOST_ECC1B_MSK (0x1 << SAS_ECC_INTR_IOST_ECC1B_OFF)
  94. #define SAS_ECC_INTR_IOST_ECCBAD_OFF 3
  95. #define SAS_ECC_INTR_IOST_ECCBAD_MSK (0x1 << SAS_ECC_INTR_IOST_ECCBAD_OFF)
  96. #define SAS_ECC_INTR_ITCT_ECC1B_OFF 4
  97. #define SAS_ECC_INTR_ITCT_ECC1B_MSK (0x1 << SAS_ECC_INTR_ITCT_ECC1B_OFF)
  98. #define SAS_ECC_INTR_ITCT_ECCBAD_OFF 5
  99. #define SAS_ECC_INTR_ITCT_ECCBAD_MSK (0x1 << SAS_ECC_INTR_ITCT_ECCBAD_OFF)
  100. #define SAS_ECC_INTR_MSK 0x1ec
  101. #define HGC_ERR_STAT_EN 0x238
  102. #define DLVRY_Q_0_BASE_ADDR_LO 0x260
  103. #define DLVRY_Q_0_BASE_ADDR_HI 0x264
  104. #define DLVRY_Q_0_DEPTH 0x268
  105. #define DLVRY_Q_0_WR_PTR 0x26c
  106. #define DLVRY_Q_0_RD_PTR 0x270
  107. #define COMPL_Q_0_BASE_ADDR_LO 0x4e0
  108. #define COMPL_Q_0_BASE_ADDR_HI 0x4e4
  109. #define COMPL_Q_0_DEPTH 0x4e8
  110. #define COMPL_Q_0_WR_PTR 0x4ec
  111. #define COMPL_Q_0_RD_PTR 0x4f0
  112. #define HGC_ECC_ERR 0x7d0
  113. /* phy registers need init */
  114. #define PORT_BASE (0x800)
  115. #define PHY_CFG (PORT_BASE + 0x0)
  116. #define PHY_CFG_ENA_OFF 0
  117. #define PHY_CFG_ENA_MSK (0x1 << PHY_CFG_ENA_OFF)
  118. #define PHY_CFG_DC_OPT_OFF 2
  119. #define PHY_CFG_DC_OPT_MSK (0x1 << PHY_CFG_DC_OPT_OFF)
  120. #define PROG_PHY_LINK_RATE (PORT_BASE + 0xc)
  121. #define PROG_PHY_LINK_RATE_MAX_OFF 0
  122. #define PROG_PHY_LINK_RATE_MAX_MSK (0xf << PROG_PHY_LINK_RATE_MAX_OFF)
  123. #define PROG_PHY_LINK_RATE_MIN_OFF 4
  124. #define PROG_PHY_LINK_RATE_MIN_MSK (0xf << PROG_PHY_LINK_RATE_MIN_OFF)
  125. #define PROG_PHY_LINK_RATE_OOB_OFF 8
  126. #define PROG_PHY_LINK_RATE_OOB_MSK (0xf << PROG_PHY_LINK_RATE_OOB_OFF)
  127. #define PHY_CTRL (PORT_BASE + 0x14)
  128. #define PHY_CTRL_RESET_OFF 0
  129. #define PHY_CTRL_RESET_MSK (0x1 << PHY_CTRL_RESET_OFF)
  130. #define PHY_RATE_NEGO (PORT_BASE + 0x30)
  131. #define PHY_PCN (PORT_BASE + 0x44)
  132. #define SL_TOUT_CFG (PORT_BASE + 0x8c)
  133. #define SL_CONTROL (PORT_BASE + 0x94)
  134. #define SL_CONTROL_NOTIFY_EN_OFF 0
  135. #define SL_CONTROL_NOTIFY_EN_MSK (0x1 << SL_CONTROL_NOTIFY_EN_OFF)
  136. #define TX_ID_DWORD0 (PORT_BASE + 0x9c)
  137. #define TX_ID_DWORD1 (PORT_BASE + 0xa0)
  138. #define TX_ID_DWORD2 (PORT_BASE + 0xa4)
  139. #define TX_ID_DWORD3 (PORT_BASE + 0xa8)
  140. #define TX_ID_DWORD4 (PORT_BASE + 0xaC)
  141. #define TX_ID_DWORD5 (PORT_BASE + 0xb0)
  142. #define TX_ID_DWORD6 (PORT_BASE + 0xb4)
  143. #define RX_IDAF_DWORD0 (PORT_BASE + 0xc4)
  144. #define RX_IDAF_DWORD1 (PORT_BASE + 0xc8)
  145. #define RX_IDAF_DWORD2 (PORT_BASE + 0xcc)
  146. #define RX_IDAF_DWORD3 (PORT_BASE + 0xd0)
  147. #define RX_IDAF_DWORD4 (PORT_BASE + 0xd4)
  148. #define RX_IDAF_DWORD5 (PORT_BASE + 0xd8)
  149. #define RX_IDAF_DWORD6 (PORT_BASE + 0xdc)
  150. #define RXOP_CHECK_CFG_H (PORT_BASE + 0xfc)
  151. #define DONE_RECEIVED_TIME (PORT_BASE + 0x12c)
  152. #define CON_CFG_DRIVER (PORT_BASE + 0x130)
  153. #define PHY_CONFIG2 (PORT_BASE + 0x1a8)
  154. #define PHY_CONFIG2_FORCE_TXDEEMPH_OFF 3
  155. #define PHY_CONFIG2_FORCE_TXDEEMPH_MSK (0x1 << PHY_CONFIG2_FORCE_TXDEEMPH_OFF)
  156. #define PHY_CONFIG2_TX_TRAIN_COMP_OFF 24
  157. #define PHY_CONFIG2_TX_TRAIN_COMP_MSK (0x1 << PHY_CONFIG2_TX_TRAIN_COMP_OFF)
  158. #define CHL_INT0 (PORT_BASE + 0x1b0)
  159. #define CHL_INT0_PHYCTRL_NOTRDY_OFF 0
  160. #define CHL_INT0_PHYCTRL_NOTRDY_MSK (0x1 << CHL_INT0_PHYCTRL_NOTRDY_OFF)
  161. #define CHL_INT0_SN_FAIL_NGR_OFF 2
  162. #define CHL_INT0_SN_FAIL_NGR_MSK (0x1 << CHL_INT0_SN_FAIL_NGR_OFF)
  163. #define CHL_INT0_DWS_LOST_OFF 4
  164. #define CHL_INT0_DWS_LOST_MSK (0x1 << CHL_INT0_DWS_LOST_OFF)
  165. #define CHL_INT0_SL_IDAF_FAIL_OFF 10
  166. #define CHL_INT0_SL_IDAF_FAIL_MSK (0x1 << CHL_INT0_SL_IDAF_FAIL_OFF)
  167. #define CHL_INT0_ID_TIMEOUT_OFF 11
  168. #define CHL_INT0_ID_TIMEOUT_MSK (0x1 << CHL_INT0_ID_TIMEOUT_OFF)
  169. #define CHL_INT0_SL_OPAF_FAIL_OFF 12
  170. #define CHL_INT0_SL_OPAF_FAIL_MSK (0x1 << CHL_INT0_SL_OPAF_FAIL_OFF)
  171. #define CHL_INT0_SL_PS_FAIL_OFF 21
  172. #define CHL_INT0_SL_PS_FAIL_MSK (0x1 << CHL_INT0_SL_PS_FAIL_OFF)
  173. #define CHL_INT1 (PORT_BASE + 0x1b4)
  174. #define CHL_INT2 (PORT_BASE + 0x1b8)
  175. #define CHL_INT2_SL_RX_BC_ACK_OFF 2
  176. #define CHL_INT2_SL_RX_BC_ACK_MSK (0x1 << CHL_INT2_SL_RX_BC_ACK_OFF)
  177. #define CHL_INT2_SL_PHY_ENA_OFF 6
  178. #define CHL_INT2_SL_PHY_ENA_MSK (0x1 << CHL_INT2_SL_PHY_ENA_OFF)
  179. #define CHL_INT0_MSK (PORT_BASE + 0x1bc)
  180. #define CHL_INT0_MSK_PHYCTRL_NOTRDY_OFF 0
  181. #define CHL_INT0_MSK_PHYCTRL_NOTRDY_MSK (0x1 << CHL_INT0_MSK_PHYCTRL_NOTRDY_OFF)
  182. #define CHL_INT1_MSK (PORT_BASE + 0x1c0)
  183. #define CHL_INT2_MSK (PORT_BASE + 0x1c4)
  184. #define CHL_INT_COAL_EN (PORT_BASE + 0x1d0)
  185. #define DMA_TX_STATUS (PORT_BASE + 0x2d0)
  186. #define DMA_TX_STATUS_BUSY_OFF 0
  187. #define DMA_TX_STATUS_BUSY_MSK (0x1 << DMA_TX_STATUS_BUSY_OFF)
  188. #define DMA_RX_STATUS (PORT_BASE + 0x2e8)
  189. #define DMA_RX_STATUS_BUSY_OFF 0
  190. #define DMA_RX_STATUS_BUSY_MSK (0x1 << DMA_RX_STATUS_BUSY_OFF)
  191. #define AXI_CFG 0x5100
  192. #define RESET_VALUE 0x7ffff
  193. /* HW dma structures */
  194. /* Delivery queue header */
  195. /* dw0 */
  196. #define CMD_HDR_RESP_REPORT_OFF 5
  197. #define CMD_HDR_RESP_REPORT_MSK 0x20
  198. #define CMD_HDR_TLR_CTRL_OFF 6
  199. #define CMD_HDR_TLR_CTRL_MSK 0xc0
  200. #define CMD_HDR_PORT_OFF 17
  201. #define CMD_HDR_PORT_MSK 0xe0000
  202. #define CMD_HDR_PRIORITY_OFF 27
  203. #define CMD_HDR_PRIORITY_MSK 0x8000000
  204. #define CMD_HDR_MODE_OFF 28
  205. #define CMD_HDR_MODE_MSK 0x10000000
  206. #define CMD_HDR_CMD_OFF 29
  207. #define CMD_HDR_CMD_MSK 0xe0000000
  208. /* dw1 */
  209. #define CMD_HDR_VERIFY_DTL_OFF 10
  210. #define CMD_HDR_VERIFY_DTL_MSK 0x400
  211. #define CMD_HDR_SSP_FRAME_TYPE_OFF 13
  212. #define CMD_HDR_SSP_FRAME_TYPE_MSK 0xe000
  213. #define CMD_HDR_DEVICE_ID_OFF 16
  214. #define CMD_HDR_DEVICE_ID_MSK 0xffff0000
  215. /* dw2 */
  216. #define CMD_HDR_CFL_OFF 0
  217. #define CMD_HDR_CFL_MSK 0x1ff
  218. #define CMD_HDR_MRFL_OFF 15
  219. #define CMD_HDR_MRFL_MSK 0xff8000
  220. #define CMD_HDR_FIRST_BURST_OFF 25
  221. #define CMD_HDR_FIRST_BURST_MSK 0x2000000
  222. /* dw3 */
  223. #define CMD_HDR_IPTT_OFF 0
  224. #define CMD_HDR_IPTT_MSK 0xffff
  225. /* dw6 */
  226. #define CMD_HDR_DATA_SGL_LEN_OFF 16
  227. #define CMD_HDR_DATA_SGL_LEN_MSK 0xffff0000
  228. /* Completion header */
  229. #define CMPLT_HDR_IPTT_OFF 0
  230. #define CMPLT_HDR_IPTT_MSK (0xffff << CMPLT_HDR_IPTT_OFF)
  231. #define CMPLT_HDR_CMD_CMPLT_OFF 17
  232. #define CMPLT_HDR_CMD_CMPLT_MSK (0x1 << CMPLT_HDR_CMD_CMPLT_OFF)
  233. #define CMPLT_HDR_ERR_RCRD_XFRD_OFF 18
  234. #define CMPLT_HDR_ERR_RCRD_XFRD_MSK (0x1 << CMPLT_HDR_ERR_RCRD_XFRD_OFF)
  235. #define CMPLT_HDR_RSPNS_XFRD_OFF 19
  236. #define CMPLT_HDR_RSPNS_XFRD_MSK (0x1 << CMPLT_HDR_RSPNS_XFRD_OFF)
  237. #define CMPLT_HDR_IO_CFG_ERR_OFF 27
  238. #define CMPLT_HDR_IO_CFG_ERR_MSK (0x1 << CMPLT_HDR_IO_CFG_ERR_OFF)
  239. /* ITCT header */
  240. /* qw0 */
  241. #define ITCT_HDR_DEV_TYPE_OFF 0
  242. #define ITCT_HDR_DEV_TYPE_MSK (0x3ULL << ITCT_HDR_DEV_TYPE_OFF)
  243. #define ITCT_HDR_VALID_OFF 2
  244. #define ITCT_HDR_VALID_MSK (0x1ULL << ITCT_HDR_VALID_OFF)
  245. #define ITCT_HDR_AWT_CONTROL_OFF 4
  246. #define ITCT_HDR_AWT_CONTROL_MSK (0x1ULL << ITCT_HDR_AWT_CONTROL_OFF)
  247. #define ITCT_HDR_MAX_CONN_RATE_OFF 5
  248. #define ITCT_HDR_MAX_CONN_RATE_MSK (0xfULL << ITCT_HDR_MAX_CONN_RATE_OFF)
  249. #define ITCT_HDR_VALID_LINK_NUM_OFF 9
  250. #define ITCT_HDR_VALID_LINK_NUM_MSK (0xfULL << ITCT_HDR_VALID_LINK_NUM_OFF)
  251. #define ITCT_HDR_PORT_ID_OFF 13
  252. #define ITCT_HDR_PORT_ID_MSK (0x7ULL << ITCT_HDR_PORT_ID_OFF)
  253. #define ITCT_HDR_SMP_TIMEOUT_OFF 16
  254. #define ITCT_HDR_SMP_TIMEOUT_MSK (0xffffULL << ITCT_HDR_SMP_TIMEOUT_OFF)
  255. /* qw1 */
  256. #define ITCT_HDR_MAX_SAS_ADDR_OFF 0
  257. #define ITCT_HDR_MAX_SAS_ADDR_MSK (0xffffffffffffffff << \
  258. ITCT_HDR_MAX_SAS_ADDR_OFF)
  259. /* qw2 */
  260. #define ITCT_HDR_IT_NEXUS_LOSS_TL_OFF 0
  261. #define ITCT_HDR_IT_NEXUS_LOSS_TL_MSK (0xffffULL << \
  262. ITCT_HDR_IT_NEXUS_LOSS_TL_OFF)
  263. #define ITCT_HDR_BUS_INACTIVE_TL_OFF 16
  264. #define ITCT_HDR_BUS_INACTIVE_TL_MSK (0xffffULL << \
  265. ITCT_HDR_BUS_INACTIVE_TL_OFF)
  266. #define ITCT_HDR_MAX_CONN_TL_OFF 32
  267. #define ITCT_HDR_MAX_CONN_TL_MSK (0xffffULL << \
  268. ITCT_HDR_MAX_CONN_TL_OFF)
  269. #define ITCT_HDR_REJ_OPEN_TL_OFF 48
  270. #define ITCT_HDR_REJ_OPEN_TL_MSK (0xffffULL << \
  271. ITCT_HDR_REJ_OPEN_TL_OFF)
  272. /* Err record header */
  273. #define ERR_HDR_DMA_TX_ERR_TYPE_OFF 0
  274. #define ERR_HDR_DMA_TX_ERR_TYPE_MSK (0xffff << ERR_HDR_DMA_TX_ERR_TYPE_OFF)
  275. #define ERR_HDR_DMA_RX_ERR_TYPE_OFF 16
  276. #define ERR_HDR_DMA_RX_ERR_TYPE_MSK (0xffff << ERR_HDR_DMA_RX_ERR_TYPE_OFF)
  277. struct hisi_sas_complete_v1_hdr {
  278. __le32 data;
  279. };
  280. struct hisi_sas_err_record_v1 {
  281. /* dw0 */
  282. __le32 dma_err_type;
  283. /* dw1 */
  284. __le32 trans_tx_fail_type;
  285. /* dw2 */
  286. __le32 trans_rx_fail_type;
  287. /* dw3 */
  288. u32 rsvd;
  289. };
  290. enum {
  291. HISI_SAS_PHY_BCAST_ACK = 0,
  292. HISI_SAS_PHY_SL_PHY_ENABLED,
  293. HISI_SAS_PHY_INT_ABNORMAL,
  294. HISI_SAS_PHY_INT_NR
  295. };
  296. enum {
  297. DMA_TX_ERR_BASE = 0x0,
  298. DMA_RX_ERR_BASE = 0x100,
  299. TRANS_TX_FAIL_BASE = 0x200,
  300. TRANS_RX_FAIL_BASE = 0x300,
  301. /* dma tx */
  302. DMA_TX_DIF_CRC_ERR = DMA_TX_ERR_BASE, /* 0x0 */
  303. DMA_TX_DIF_APP_ERR, /* 0x1 */
  304. DMA_TX_DIF_RPP_ERR, /* 0x2 */
  305. DMA_TX_AXI_BUS_ERR, /* 0x3 */
  306. DMA_TX_DATA_SGL_OVERFLOW_ERR, /* 0x4 */
  307. DMA_TX_DIF_SGL_OVERFLOW_ERR, /* 0x5 */
  308. DMA_TX_UNEXP_XFER_RDY_ERR, /* 0x6 */
  309. DMA_TX_XFER_RDY_OFFSET_ERR, /* 0x7 */
  310. DMA_TX_DATA_UNDERFLOW_ERR, /* 0x8 */
  311. DMA_TX_XFER_RDY_LENGTH_OVERFLOW_ERR, /* 0x9 */
  312. /* dma rx */
  313. DMA_RX_BUFFER_ECC_ERR = DMA_RX_ERR_BASE, /* 0x100 */
  314. DMA_RX_DIF_CRC_ERR, /* 0x101 */
  315. DMA_RX_DIF_APP_ERR, /* 0x102 */
  316. DMA_RX_DIF_RPP_ERR, /* 0x103 */
  317. DMA_RX_RESP_BUFFER_OVERFLOW_ERR, /* 0x104 */
  318. DMA_RX_AXI_BUS_ERR, /* 0x105 */
  319. DMA_RX_DATA_SGL_OVERFLOW_ERR, /* 0x106 */
  320. DMA_RX_DIF_SGL_OVERFLOW_ERR, /* 0x107 */
  321. DMA_RX_DATA_OFFSET_ERR, /* 0x108 */
  322. DMA_RX_UNEXP_RX_DATA_ERR, /* 0x109 */
  323. DMA_RX_DATA_OVERFLOW_ERR, /* 0x10a */
  324. DMA_RX_DATA_UNDERFLOW_ERR, /* 0x10b */
  325. DMA_RX_UNEXP_RETRANS_RESP_ERR, /* 0x10c */
  326. /* trans tx */
  327. TRANS_TX_RSVD0_ERR = TRANS_TX_FAIL_BASE, /* 0x200 */
  328. TRANS_TX_PHY_NOT_ENABLE_ERR, /* 0x201 */
  329. TRANS_TX_OPEN_REJCT_WRONG_DEST_ERR, /* 0x202 */
  330. TRANS_TX_OPEN_REJCT_ZONE_VIOLATION_ERR, /* 0x203 */
  331. TRANS_TX_OPEN_REJCT_BY_OTHER_ERR, /* 0x204 */
  332. TRANS_TX_RSVD1_ERR, /* 0x205 */
  333. TRANS_TX_OPEN_REJCT_AIP_TIMEOUT_ERR, /* 0x206 */
  334. TRANS_TX_OPEN_REJCT_STP_BUSY_ERR, /* 0x207 */
  335. TRANS_TX_OPEN_REJCT_PROTOCOL_NOT_SUPPORT_ERR, /* 0x208 */
  336. TRANS_TX_OPEN_REJCT_RATE_NOT_SUPPORT_ERR, /* 0x209 */
  337. TRANS_TX_OPEN_REJCT_BAD_DEST_ERR, /* 0x20a */
  338. TRANS_TX_OPEN_BREAK_RECEIVE_ERR, /* 0x20b */
  339. TRANS_TX_LOW_PHY_POWER_ERR, /* 0x20c */
  340. TRANS_TX_OPEN_REJCT_PATHWAY_BLOCKED_ERR, /* 0x20d */
  341. TRANS_TX_OPEN_TIMEOUT_ERR, /* 0x20e */
  342. TRANS_TX_OPEN_REJCT_NO_DEST_ERR, /* 0x20f */
  343. TRANS_TX_OPEN_RETRY_ERR, /* 0x210 */
  344. TRANS_TX_RSVD2_ERR, /* 0x211 */
  345. TRANS_TX_BREAK_TIMEOUT_ERR, /* 0x212 */
  346. TRANS_TX_BREAK_REQUEST_ERR, /* 0x213 */
  347. TRANS_TX_BREAK_RECEIVE_ERR, /* 0x214 */
  348. TRANS_TX_CLOSE_TIMEOUT_ERR, /* 0x215 */
  349. TRANS_TX_CLOSE_NORMAL_ERR, /* 0x216 */
  350. TRANS_TX_CLOSE_PHYRESET_ERR, /* 0x217 */
  351. TRANS_TX_WITH_CLOSE_DWS_TIMEOUT_ERR, /* 0x218 */
  352. TRANS_TX_WITH_CLOSE_COMINIT_ERR, /* 0x219 */
  353. TRANS_TX_NAK_RECEIVE_ERR, /* 0x21a */
  354. TRANS_TX_ACK_NAK_TIMEOUT_ERR, /* 0x21b */
  355. TRANS_TX_CREDIT_TIMEOUT_ERR, /* 0x21c */
  356. TRANS_TX_IPTT_CONFLICT_ERR, /* 0x21d */
  357. TRANS_TX_TXFRM_TYPE_ERR, /* 0x21e */
  358. TRANS_TX_TXSMP_LENGTH_ERR, /* 0x21f */
  359. /* trans rx */
  360. TRANS_RX_FRAME_CRC_ERR = TRANS_RX_FAIL_BASE, /* 0x300 */
  361. TRANS_RX_FRAME_DONE_ERR, /* 0x301 */
  362. TRANS_RX_FRAME_ERRPRM_ERR, /* 0x302 */
  363. TRANS_RX_FRAME_NO_CREDIT_ERR, /* 0x303 */
  364. TRANS_RX_RSVD0_ERR, /* 0x304 */
  365. TRANS_RX_FRAME_OVERRUN_ERR, /* 0x305 */
  366. TRANS_RX_FRAME_NO_EOF_ERR, /* 0x306 */
  367. TRANS_RX_LINK_BUF_OVERRUN_ERR, /* 0x307 */
  368. TRANS_RX_BREAK_TIMEOUT_ERR, /* 0x308 */
  369. TRANS_RX_BREAK_REQUEST_ERR, /* 0x309 */
  370. TRANS_RX_BREAK_RECEIVE_ERR, /* 0x30a */
  371. TRANS_RX_CLOSE_TIMEOUT_ERR, /* 0x30b */
  372. TRANS_RX_CLOSE_NORMAL_ERR, /* 0x30c */
  373. TRANS_RX_CLOSE_PHYRESET_ERR, /* 0x30d */
  374. TRANS_RX_WITH_CLOSE_DWS_TIMEOUT_ERR, /* 0x30e */
  375. TRANS_RX_WITH_CLOSE_COMINIT_ERR, /* 0x30f */
  376. TRANS_RX_DATA_LENGTH0_ERR, /* 0x310 */
  377. TRANS_RX_BAD_HASH_ERR, /* 0x311 */
  378. TRANS_RX_XRDY_ZERO_ERR, /* 0x312 */
  379. TRANS_RX_SSP_FRAME_LEN_ERR, /* 0x313 */
  380. TRANS_RX_TRANS_RX_RSVD1_ERR, /* 0x314 */
  381. TRANS_RX_NO_BALANCE_ERR, /* 0x315 */
  382. TRANS_RX_TRANS_RX_RSVD2_ERR, /* 0x316 */
  383. TRANS_RX_TRANS_RX_RSVD3_ERR, /* 0x317 */
  384. TRANS_RX_BAD_FRAME_TYPE_ERR, /* 0x318 */
  385. TRANS_RX_SMP_FRAME_LEN_ERR, /* 0x319 */
  386. TRANS_RX_SMP_RESP_TIMEOUT_ERR, /* 0x31a */
  387. };
  388. #define HISI_SAS_COMMAND_ENTRIES_V1_HW 8192
  389. #define HISI_SAS_PHY_MAX_INT_NR (HISI_SAS_PHY_INT_NR * HISI_SAS_MAX_PHYS)
  390. #define HISI_SAS_CQ_MAX_INT_NR (HISI_SAS_MAX_QUEUES)
  391. #define HISI_SAS_FATAL_INT_NR (2)
  392. #define HISI_SAS_MAX_INT_NR \
  393. (HISI_SAS_PHY_MAX_INT_NR + HISI_SAS_CQ_MAX_INT_NR +\
  394. HISI_SAS_FATAL_INT_NR)
  395. static u32 hisi_sas_read32(struct hisi_hba *hisi_hba, u32 off)
  396. {
  397. void __iomem *regs = hisi_hba->regs + off;
  398. return readl(regs);
  399. }
  400. static u32 hisi_sas_read32_relaxed(struct hisi_hba *hisi_hba, u32 off)
  401. {
  402. void __iomem *regs = hisi_hba->regs + off;
  403. return readl_relaxed(regs);
  404. }
  405. static void hisi_sas_write32(struct hisi_hba *hisi_hba,
  406. u32 off, u32 val)
  407. {
  408. void __iomem *regs = hisi_hba->regs + off;
  409. writel(val, regs);
  410. }
  411. static void hisi_sas_phy_write32(struct hisi_hba *hisi_hba,
  412. int phy_no, u32 off, u32 val)
  413. {
  414. void __iomem *regs = hisi_hba->regs + (0x400 * phy_no) + off;
  415. writel(val, regs);
  416. }
  417. static u32 hisi_sas_phy_read32(struct hisi_hba *hisi_hba,
  418. int phy_no, u32 off)
  419. {
  420. void __iomem *regs = hisi_hba->regs + (0x400 * phy_no) + off;
  421. return readl(regs);
  422. }
  423. static void config_phy_opt_mode_v1_hw(struct hisi_hba *hisi_hba, int phy_no)
  424. {
  425. u32 cfg = hisi_sas_phy_read32(hisi_hba, phy_no, PHY_CFG);
  426. cfg &= ~PHY_CFG_DC_OPT_MSK;
  427. cfg |= 1 << PHY_CFG_DC_OPT_OFF;
  428. hisi_sas_phy_write32(hisi_hba, phy_no, PHY_CFG, cfg);
  429. }
  430. static void config_tx_tfe_autoneg_v1_hw(struct hisi_hba *hisi_hba, int phy_no)
  431. {
  432. u32 cfg = hisi_sas_phy_read32(hisi_hba, phy_no, PHY_CONFIG2);
  433. cfg &= ~PHY_CONFIG2_FORCE_TXDEEMPH_MSK;
  434. hisi_sas_phy_write32(hisi_hba, phy_no, PHY_CONFIG2, cfg);
  435. }
  436. static void config_id_frame_v1_hw(struct hisi_hba *hisi_hba, int phy_no)
  437. {
  438. struct sas_identify_frame identify_frame;
  439. u32 *identify_buffer;
  440. memset(&identify_frame, 0, sizeof(identify_frame));
  441. identify_frame.dev_type = SAS_END_DEVICE;
  442. identify_frame.frame_type = 0;
  443. identify_frame._un1 = 1;
  444. identify_frame.initiator_bits = SAS_PROTOCOL_ALL;
  445. identify_frame.target_bits = SAS_PROTOCOL_NONE;
  446. memcpy(&identify_frame._un4_11[0], hisi_hba->sas_addr, SAS_ADDR_SIZE);
  447. memcpy(&identify_frame.sas_addr[0], hisi_hba->sas_addr, SAS_ADDR_SIZE);
  448. identify_frame.phy_id = phy_no;
  449. identify_buffer = (u32 *)(&identify_frame);
  450. hisi_sas_phy_write32(hisi_hba, phy_no, TX_ID_DWORD0,
  451. __swab32(identify_buffer[0]));
  452. hisi_sas_phy_write32(hisi_hba, phy_no, TX_ID_DWORD1,
  453. __swab32(identify_buffer[1]));
  454. hisi_sas_phy_write32(hisi_hba, phy_no, TX_ID_DWORD2,
  455. __swab32(identify_buffer[2]));
  456. hisi_sas_phy_write32(hisi_hba, phy_no, TX_ID_DWORD3,
  457. __swab32(identify_buffer[3]));
  458. hisi_sas_phy_write32(hisi_hba, phy_no, TX_ID_DWORD4,
  459. __swab32(identify_buffer[4]));
  460. hisi_sas_phy_write32(hisi_hba, phy_no, TX_ID_DWORD5,
  461. __swab32(identify_buffer[5]));
  462. }
  463. static void setup_itct_v1_hw(struct hisi_hba *hisi_hba,
  464. struct hisi_sas_device *sas_dev)
  465. {
  466. struct domain_device *device = sas_dev->sas_device;
  467. struct device *dev = hisi_hba->dev;
  468. u64 qw0, device_id = sas_dev->device_id;
  469. struct hisi_sas_itct *itct = &hisi_hba->itct[device_id];
  470. struct asd_sas_port *sas_port = device->port;
  471. struct hisi_sas_port *port = to_hisi_sas_port(sas_port);
  472. memset(itct, 0, sizeof(*itct));
  473. /* qw0 */
  474. qw0 = 0;
  475. switch (sas_dev->dev_type) {
  476. case SAS_END_DEVICE:
  477. case SAS_EDGE_EXPANDER_DEVICE:
  478. case SAS_FANOUT_EXPANDER_DEVICE:
  479. qw0 = HISI_SAS_DEV_TYPE_SSP << ITCT_HDR_DEV_TYPE_OFF;
  480. break;
  481. default:
  482. dev_warn(dev, "setup itct: unsupported dev type (%d)\n",
  483. sas_dev->dev_type);
  484. }
  485. qw0 |= ((1 << ITCT_HDR_VALID_OFF) |
  486. (1 << ITCT_HDR_AWT_CONTROL_OFF) |
  487. (device->max_linkrate << ITCT_HDR_MAX_CONN_RATE_OFF) |
  488. (1 << ITCT_HDR_VALID_LINK_NUM_OFF) |
  489. (port->id << ITCT_HDR_PORT_ID_OFF));
  490. itct->qw0 = cpu_to_le64(qw0);
  491. /* qw1 */
  492. memcpy(&itct->sas_addr, device->sas_addr, SAS_ADDR_SIZE);
  493. itct->sas_addr = __swab64(itct->sas_addr);
  494. /* qw2 */
  495. itct->qw2 = cpu_to_le64((500ULL << ITCT_HDR_IT_NEXUS_LOSS_TL_OFF) |
  496. (0xff00ULL << ITCT_HDR_BUS_INACTIVE_TL_OFF) |
  497. (0xff00ULL << ITCT_HDR_MAX_CONN_TL_OFF) |
  498. (0xff00ULL << ITCT_HDR_REJ_OPEN_TL_OFF));
  499. }
  500. static void clear_itct_v1_hw(struct hisi_hba *hisi_hba,
  501. struct hisi_sas_device *sas_dev)
  502. {
  503. u64 dev_id = sas_dev->device_id;
  504. struct hisi_sas_itct *itct = &hisi_hba->itct[dev_id];
  505. u64 qw0;
  506. u32 reg_val = hisi_sas_read32(hisi_hba, CFG_AGING_TIME);
  507. reg_val |= CFG_AGING_TIME_ITCT_REL_MSK;
  508. hisi_sas_write32(hisi_hba, CFG_AGING_TIME, reg_val);
  509. /* free itct */
  510. udelay(1);
  511. reg_val = hisi_sas_read32(hisi_hba, CFG_AGING_TIME);
  512. reg_val &= ~CFG_AGING_TIME_ITCT_REL_MSK;
  513. hisi_sas_write32(hisi_hba, CFG_AGING_TIME, reg_val);
  514. qw0 = cpu_to_le64(itct->qw0);
  515. qw0 &= ~ITCT_HDR_VALID_MSK;
  516. itct->qw0 = cpu_to_le64(qw0);
  517. }
  518. static int reset_hw_v1_hw(struct hisi_hba *hisi_hba)
  519. {
  520. int i;
  521. unsigned long end_time;
  522. u32 val;
  523. struct device *dev = hisi_hba->dev;
  524. for (i = 0; i < hisi_hba->n_phy; i++) {
  525. u32 phy_ctrl = hisi_sas_phy_read32(hisi_hba, i, PHY_CTRL);
  526. phy_ctrl |= PHY_CTRL_RESET_MSK;
  527. hisi_sas_phy_write32(hisi_hba, i, PHY_CTRL, phy_ctrl);
  528. }
  529. msleep(1); /* It is safe to wait for 50us */
  530. /* Ensure DMA tx & rx idle */
  531. for (i = 0; i < hisi_hba->n_phy; i++) {
  532. u32 dma_tx_status, dma_rx_status;
  533. end_time = jiffies + msecs_to_jiffies(1000);
  534. while (1) {
  535. dma_tx_status = hisi_sas_phy_read32(hisi_hba, i,
  536. DMA_TX_STATUS);
  537. dma_rx_status = hisi_sas_phy_read32(hisi_hba, i,
  538. DMA_RX_STATUS);
  539. if (!(dma_tx_status & DMA_TX_STATUS_BUSY_MSK) &&
  540. !(dma_rx_status & DMA_RX_STATUS_BUSY_MSK))
  541. break;
  542. msleep(20);
  543. if (time_after(jiffies, end_time))
  544. return -EIO;
  545. }
  546. }
  547. /* Ensure axi bus idle */
  548. end_time = jiffies + msecs_to_jiffies(1000);
  549. while (1) {
  550. u32 axi_status =
  551. hisi_sas_read32(hisi_hba, AXI_CFG);
  552. if (axi_status == 0)
  553. break;
  554. msleep(20);
  555. if (time_after(jiffies, end_time))
  556. return -EIO;
  557. }
  558. if (ACPI_HANDLE(dev)) {
  559. acpi_status s;
  560. s = acpi_evaluate_object(ACPI_HANDLE(dev), "_RST", NULL, NULL);
  561. if (ACPI_FAILURE(s)) {
  562. dev_err(dev, "Reset failed\n");
  563. return -EIO;
  564. }
  565. } else if (hisi_hba->ctrl) {
  566. /* Apply reset and disable clock */
  567. /* clk disable reg is offset by +4 bytes from clk enable reg */
  568. regmap_write(hisi_hba->ctrl, hisi_hba->ctrl_reset_reg,
  569. RESET_VALUE);
  570. regmap_write(hisi_hba->ctrl, hisi_hba->ctrl_clock_ena_reg + 4,
  571. RESET_VALUE);
  572. msleep(1);
  573. regmap_read(hisi_hba->ctrl, hisi_hba->ctrl_reset_sts_reg, &val);
  574. if (RESET_VALUE != (val & RESET_VALUE)) {
  575. dev_err(dev, "Reset failed\n");
  576. return -EIO;
  577. }
  578. /* De-reset and enable clock */
  579. /* deassert rst reg is offset by +4 bytes from assert reg */
  580. regmap_write(hisi_hba->ctrl, hisi_hba->ctrl_reset_reg + 4,
  581. RESET_VALUE);
  582. regmap_write(hisi_hba->ctrl, hisi_hba->ctrl_clock_ena_reg,
  583. RESET_VALUE);
  584. msleep(1);
  585. regmap_read(hisi_hba->ctrl, hisi_hba->ctrl_reset_sts_reg, &val);
  586. if (val & RESET_VALUE) {
  587. dev_err(dev, "De-reset failed\n");
  588. return -EIO;
  589. }
  590. } else {
  591. dev_warn(dev, "no reset method\n");
  592. return -EINVAL;
  593. }
  594. return 0;
  595. }
  596. static void init_reg_v1_hw(struct hisi_hba *hisi_hba)
  597. {
  598. int i;
  599. /* Global registers init*/
  600. hisi_sas_write32(hisi_hba, DLVRY_QUEUE_ENABLE,
  601. (u32)((1ULL << hisi_hba->queue_count) - 1));
  602. hisi_sas_write32(hisi_hba, HGC_TRANS_TASK_CNT_LIMIT, 0x11);
  603. hisi_sas_write32(hisi_hba, DEVICE_MSG_WORK_MODE, 0x1);
  604. hisi_sas_write32(hisi_hba, HGC_SAS_TXFAIL_RETRY_CTRL, 0x1ff);
  605. hisi_sas_write32(hisi_hba, HGC_ERR_STAT_EN, 0x401);
  606. hisi_sas_write32(hisi_hba, CFG_1US_TIMER_TRSH, 0x64);
  607. hisi_sas_write32(hisi_hba, HGC_GET_ITV_TIME, 0x1);
  608. hisi_sas_write32(hisi_hba, I_T_NEXUS_LOSS_TIME, 0x64);
  609. hisi_sas_write32(hisi_hba, BUS_INACTIVE_LIMIT_TIME, 0x2710);
  610. hisi_sas_write32(hisi_hba, REJECT_TO_OPEN_LIMIT_TIME, 0x1);
  611. hisi_sas_write32(hisi_hba, CFG_AGING_TIME, 0x7a12);
  612. hisi_sas_write32(hisi_hba, HGC_DFX_CFG2, 0x9c40);
  613. hisi_sas_write32(hisi_hba, FIS_LIST_BADDR_L, 0x2);
  614. hisi_sas_write32(hisi_hba, INT_COAL_EN, 0xc);
  615. hisi_sas_write32(hisi_hba, OQ_INT_COAL_TIME, 0x186a0);
  616. hisi_sas_write32(hisi_hba, OQ_INT_COAL_CNT, 1);
  617. hisi_sas_write32(hisi_hba, ENT_INT_COAL_TIME, 0x1);
  618. hisi_sas_write32(hisi_hba, ENT_INT_COAL_CNT, 0x1);
  619. hisi_sas_write32(hisi_hba, OQ_INT_SRC, 0xffffffff);
  620. hisi_sas_write32(hisi_hba, OQ_INT_SRC_MSK, 0);
  621. hisi_sas_write32(hisi_hba, ENT_INT_SRC1, 0xffffffff);
  622. hisi_sas_write32(hisi_hba, ENT_INT_SRC_MSK1, 0);
  623. hisi_sas_write32(hisi_hba, ENT_INT_SRC2, 0xffffffff);
  624. hisi_sas_write32(hisi_hba, ENT_INT_SRC_MSK2, 0);
  625. hisi_sas_write32(hisi_hba, SAS_ECC_INTR_MSK, 0);
  626. hisi_sas_write32(hisi_hba, AXI_AHB_CLK_CFG, 0x2);
  627. hisi_sas_write32(hisi_hba, CFG_SAS_CONFIG, 0x22000000);
  628. for (i = 0; i < hisi_hba->n_phy; i++) {
  629. hisi_sas_phy_write32(hisi_hba, i, PROG_PHY_LINK_RATE, 0x88a);
  630. hisi_sas_phy_write32(hisi_hba, i, PHY_CONFIG2, 0x7c080);
  631. hisi_sas_phy_write32(hisi_hba, i, PHY_RATE_NEGO, 0x415ee00);
  632. hisi_sas_phy_write32(hisi_hba, i, PHY_PCN, 0x80a80000);
  633. hisi_sas_phy_write32(hisi_hba, i, SL_TOUT_CFG, 0x7d7d7d7d);
  634. hisi_sas_phy_write32(hisi_hba, i, DONE_RECEIVED_TIME, 0x0);
  635. hisi_sas_phy_write32(hisi_hba, i, RXOP_CHECK_CFG_H, 0x1000);
  636. hisi_sas_phy_write32(hisi_hba, i, DONE_RECEIVED_TIME, 0);
  637. hisi_sas_phy_write32(hisi_hba, i, CON_CFG_DRIVER, 0x13f0a);
  638. hisi_sas_phy_write32(hisi_hba, i, CHL_INT_COAL_EN, 3);
  639. hisi_sas_phy_write32(hisi_hba, i, DONE_RECEIVED_TIME, 8);
  640. }
  641. for (i = 0; i < hisi_hba->queue_count; i++) {
  642. /* Delivery queue */
  643. hisi_sas_write32(hisi_hba,
  644. DLVRY_Q_0_BASE_ADDR_HI + (i * 0x14),
  645. upper_32_bits(hisi_hba->cmd_hdr_dma[i]));
  646. hisi_sas_write32(hisi_hba,
  647. DLVRY_Q_0_BASE_ADDR_LO + (i * 0x14),
  648. lower_32_bits(hisi_hba->cmd_hdr_dma[i]));
  649. hisi_sas_write32(hisi_hba,
  650. DLVRY_Q_0_DEPTH + (i * 0x14),
  651. HISI_SAS_QUEUE_SLOTS);
  652. /* Completion queue */
  653. hisi_sas_write32(hisi_hba,
  654. COMPL_Q_0_BASE_ADDR_HI + (i * 0x14),
  655. upper_32_bits(hisi_hba->complete_hdr_dma[i]));
  656. hisi_sas_write32(hisi_hba,
  657. COMPL_Q_0_BASE_ADDR_LO + (i * 0x14),
  658. lower_32_bits(hisi_hba->complete_hdr_dma[i]));
  659. hisi_sas_write32(hisi_hba, COMPL_Q_0_DEPTH + (i * 0x14),
  660. HISI_SAS_QUEUE_SLOTS);
  661. }
  662. /* itct */
  663. hisi_sas_write32(hisi_hba, ITCT_BASE_ADDR_LO,
  664. lower_32_bits(hisi_hba->itct_dma));
  665. hisi_sas_write32(hisi_hba, ITCT_BASE_ADDR_HI,
  666. upper_32_bits(hisi_hba->itct_dma));
  667. /* iost */
  668. hisi_sas_write32(hisi_hba, IOST_BASE_ADDR_LO,
  669. lower_32_bits(hisi_hba->iost_dma));
  670. hisi_sas_write32(hisi_hba, IOST_BASE_ADDR_HI,
  671. upper_32_bits(hisi_hba->iost_dma));
  672. /* breakpoint */
  673. hisi_sas_write32(hisi_hba, BROKEN_MSG_ADDR_LO,
  674. lower_32_bits(hisi_hba->breakpoint_dma));
  675. hisi_sas_write32(hisi_hba, BROKEN_MSG_ADDR_HI,
  676. upper_32_bits(hisi_hba->breakpoint_dma));
  677. }
  678. static int hw_init_v1_hw(struct hisi_hba *hisi_hba)
  679. {
  680. struct device *dev = hisi_hba->dev;
  681. int rc;
  682. rc = reset_hw_v1_hw(hisi_hba);
  683. if (rc) {
  684. dev_err(dev, "hisi_sas_reset_hw failed, rc=%d", rc);
  685. return rc;
  686. }
  687. msleep(100);
  688. init_reg_v1_hw(hisi_hba);
  689. return 0;
  690. }
  691. static void enable_phy_v1_hw(struct hisi_hba *hisi_hba, int phy_no)
  692. {
  693. u32 cfg = hisi_sas_phy_read32(hisi_hba, phy_no, PHY_CFG);
  694. cfg |= PHY_CFG_ENA_MSK;
  695. hisi_sas_phy_write32(hisi_hba, phy_no, PHY_CFG, cfg);
  696. }
  697. static void disable_phy_v1_hw(struct hisi_hba *hisi_hba, int phy_no)
  698. {
  699. u32 cfg = hisi_sas_phy_read32(hisi_hba, phy_no, PHY_CFG);
  700. cfg &= ~PHY_CFG_ENA_MSK;
  701. hisi_sas_phy_write32(hisi_hba, phy_no, PHY_CFG, cfg);
  702. }
  703. static void start_phy_v1_hw(struct hisi_hba *hisi_hba, int phy_no)
  704. {
  705. config_id_frame_v1_hw(hisi_hba, phy_no);
  706. config_phy_opt_mode_v1_hw(hisi_hba, phy_no);
  707. config_tx_tfe_autoneg_v1_hw(hisi_hba, phy_no);
  708. enable_phy_v1_hw(hisi_hba, phy_no);
  709. }
  710. static void stop_phy_v1_hw(struct hisi_hba *hisi_hba, int phy_no)
  711. {
  712. disable_phy_v1_hw(hisi_hba, phy_no);
  713. }
  714. static void phy_hard_reset_v1_hw(struct hisi_hba *hisi_hba, int phy_no)
  715. {
  716. stop_phy_v1_hw(hisi_hba, phy_no);
  717. msleep(100);
  718. start_phy_v1_hw(hisi_hba, phy_no);
  719. }
  720. static void start_phys_v1_hw(struct timer_list *t)
  721. {
  722. struct hisi_hba *hisi_hba = from_timer(hisi_hba, t, timer);
  723. int i;
  724. for (i = 0; i < hisi_hba->n_phy; i++) {
  725. hisi_sas_phy_write32(hisi_hba, i, CHL_INT2_MSK, 0x12a);
  726. start_phy_v1_hw(hisi_hba, i);
  727. }
  728. }
  729. static void phys_init_v1_hw(struct hisi_hba *hisi_hba)
  730. {
  731. int i;
  732. struct timer_list *timer = &hisi_hba->timer;
  733. for (i = 0; i < hisi_hba->n_phy; i++) {
  734. hisi_sas_phy_write32(hisi_hba, i, CHL_INT2_MSK, 0x6a);
  735. hisi_sas_phy_read32(hisi_hba, i, CHL_INT2_MSK);
  736. }
  737. timer_setup(timer, start_phys_v1_hw, 0);
  738. mod_timer(timer, jiffies + HZ);
  739. }
  740. static void sl_notify_ssp_v1_hw(struct hisi_hba *hisi_hba, int phy_no)
  741. {
  742. u32 sl_control;
  743. sl_control = hisi_sas_phy_read32(hisi_hba, phy_no, SL_CONTROL);
  744. sl_control |= SL_CONTROL_NOTIFY_EN_MSK;
  745. hisi_sas_phy_write32(hisi_hba, phy_no, SL_CONTROL, sl_control);
  746. msleep(1);
  747. sl_control = hisi_sas_phy_read32(hisi_hba, phy_no, SL_CONTROL);
  748. sl_control &= ~SL_CONTROL_NOTIFY_EN_MSK;
  749. hisi_sas_phy_write32(hisi_hba, phy_no, SL_CONTROL, sl_control);
  750. }
  751. static enum sas_linkrate phy_get_max_linkrate_v1_hw(void)
  752. {
  753. return SAS_LINK_RATE_6_0_GBPS;
  754. }
  755. static void phy_set_linkrate_v1_hw(struct hisi_hba *hisi_hba, int phy_no,
  756. struct sas_phy_linkrates *r)
  757. {
  758. enum sas_linkrate max = r->maximum_linkrate;
  759. u32 prog_phy_link_rate = 0x800;
  760. prog_phy_link_rate |= hisi_sas_get_prog_phy_linkrate_mask(max);
  761. hisi_sas_phy_write32(hisi_hba, phy_no, PROG_PHY_LINK_RATE,
  762. prog_phy_link_rate);
  763. }
  764. static int get_wideport_bitmap_v1_hw(struct hisi_hba *hisi_hba, int port_id)
  765. {
  766. int i, bitmap = 0;
  767. u32 phy_port_num_ma = hisi_sas_read32(hisi_hba, PHY_PORT_NUM_MA);
  768. for (i = 0; i < hisi_hba->n_phy; i++)
  769. if (((phy_port_num_ma >> (i * 4)) & 0xf) == port_id)
  770. bitmap |= 1 << i;
  771. return bitmap;
  772. }
  773. /*
  774. * The callpath to this function and upto writing the write
  775. * queue pointer should be safe from interruption.
  776. */
  777. static int
  778. get_free_slot_v1_hw(struct hisi_hba *hisi_hba, struct hisi_sas_dq *dq)
  779. {
  780. struct device *dev = hisi_hba->dev;
  781. int queue = dq->id;
  782. u32 r, w;
  783. w = dq->wr_point;
  784. r = hisi_sas_read32_relaxed(hisi_hba,
  785. DLVRY_Q_0_RD_PTR + (queue * 0x14));
  786. if (r == (w+1) % HISI_SAS_QUEUE_SLOTS) {
  787. dev_warn(dev, "could not find free slot\n");
  788. return -EAGAIN;
  789. }
  790. dq->wr_point = (dq->wr_point + 1) % HISI_SAS_QUEUE_SLOTS;
  791. return w;
  792. }
  793. /* DQ lock must be taken here */
  794. static void start_delivery_v1_hw(struct hisi_sas_dq *dq)
  795. {
  796. struct hisi_hba *hisi_hba = dq->hisi_hba;
  797. struct hisi_sas_slot *s, *s1, *s2 = NULL;
  798. int dlvry_queue = dq->id;
  799. int wp;
  800. list_for_each_entry_safe(s, s1, &dq->list, delivery) {
  801. if (!s->ready)
  802. break;
  803. s2 = s;
  804. list_del(&s->delivery);
  805. }
  806. if (!s2)
  807. return;
  808. /*
  809. * Ensure that memories for slots built on other CPUs is observed.
  810. */
  811. smp_rmb();
  812. wp = (s2->dlvry_queue_slot + 1) % HISI_SAS_QUEUE_SLOTS;
  813. hisi_sas_write32(hisi_hba, DLVRY_Q_0_WR_PTR + (dlvry_queue * 0x14), wp);
  814. }
  815. static void prep_prd_sge_v1_hw(struct hisi_hba *hisi_hba,
  816. struct hisi_sas_slot *slot,
  817. struct hisi_sas_cmd_hdr *hdr,
  818. struct scatterlist *scatter,
  819. int n_elem)
  820. {
  821. struct hisi_sas_sge_page *sge_page = hisi_sas_sge_addr_mem(slot);
  822. struct scatterlist *sg;
  823. int i;
  824. for_each_sg(scatter, sg, n_elem, i) {
  825. struct hisi_sas_sge *entry = &sge_page->sge[i];
  826. entry->addr = cpu_to_le64(sg_dma_address(sg));
  827. entry->page_ctrl_0 = entry->page_ctrl_1 = 0;
  828. entry->data_len = cpu_to_le32(sg_dma_len(sg));
  829. entry->data_off = 0;
  830. }
  831. hdr->prd_table_addr = cpu_to_le64(hisi_sas_sge_addr_dma(slot));
  832. hdr->sg_len = cpu_to_le32(n_elem << CMD_HDR_DATA_SGL_LEN_OFF);
  833. }
  834. static void prep_smp_v1_hw(struct hisi_hba *hisi_hba,
  835. struct hisi_sas_slot *slot)
  836. {
  837. struct sas_task *task = slot->task;
  838. struct hisi_sas_cmd_hdr *hdr = slot->cmd_hdr;
  839. struct domain_device *device = task->dev;
  840. struct hisi_sas_port *port = slot->port;
  841. struct scatterlist *sg_req;
  842. struct hisi_sas_device *sas_dev = device->lldd_dev;
  843. dma_addr_t req_dma_addr;
  844. unsigned int req_len;
  845. /* req */
  846. sg_req = &task->smp_task.smp_req;
  847. req_len = sg_dma_len(sg_req);
  848. req_dma_addr = sg_dma_address(sg_req);
  849. /* create header */
  850. /* dw0 */
  851. hdr->dw0 = cpu_to_le32((port->id << CMD_HDR_PORT_OFF) |
  852. (1 << CMD_HDR_PRIORITY_OFF) | /* high pri */
  853. (1 << CMD_HDR_MODE_OFF) | /* ini mode */
  854. (2 << CMD_HDR_CMD_OFF)); /* smp */
  855. /* map itct entry */
  856. hdr->dw1 = cpu_to_le32(sas_dev->device_id << CMD_HDR_DEVICE_ID_OFF);
  857. /* dw2 */
  858. hdr->dw2 = cpu_to_le32((((req_len-4)/4) << CMD_HDR_CFL_OFF) |
  859. (HISI_SAS_MAX_SMP_RESP_SZ/4 <<
  860. CMD_HDR_MRFL_OFF));
  861. hdr->transfer_tags = cpu_to_le32(slot->idx << CMD_HDR_IPTT_OFF);
  862. hdr->cmd_table_addr = cpu_to_le64(req_dma_addr);
  863. hdr->sts_buffer_addr = cpu_to_le64(hisi_sas_status_buf_addr_dma(slot));
  864. }
  865. static void prep_ssp_v1_hw(struct hisi_hba *hisi_hba,
  866. struct hisi_sas_slot *slot)
  867. {
  868. struct sas_task *task = slot->task;
  869. struct hisi_sas_cmd_hdr *hdr = slot->cmd_hdr;
  870. struct domain_device *device = task->dev;
  871. struct hisi_sas_device *sas_dev = device->lldd_dev;
  872. struct hisi_sas_port *port = slot->port;
  873. struct sas_ssp_task *ssp_task = &task->ssp_task;
  874. struct scsi_cmnd *scsi_cmnd = ssp_task->cmd;
  875. struct hisi_sas_tmf_task *tmf = slot->tmf;
  876. int has_data = 0, priority = !!tmf;
  877. u8 *buf_cmd, fburst = 0;
  878. u32 dw1, dw2;
  879. /* create header */
  880. hdr->dw0 = cpu_to_le32((1 << CMD_HDR_RESP_REPORT_OFF) |
  881. (0x2 << CMD_HDR_TLR_CTRL_OFF) |
  882. (port->id << CMD_HDR_PORT_OFF) |
  883. (priority << CMD_HDR_PRIORITY_OFF) |
  884. (1 << CMD_HDR_MODE_OFF) | /* ini mode */
  885. (1 << CMD_HDR_CMD_OFF)); /* ssp */
  886. dw1 = 1 << CMD_HDR_VERIFY_DTL_OFF;
  887. if (tmf) {
  888. dw1 |= 3 << CMD_HDR_SSP_FRAME_TYPE_OFF;
  889. } else {
  890. switch (scsi_cmnd->sc_data_direction) {
  891. case DMA_TO_DEVICE:
  892. dw1 |= 2 << CMD_HDR_SSP_FRAME_TYPE_OFF;
  893. has_data = 1;
  894. break;
  895. case DMA_FROM_DEVICE:
  896. dw1 |= 1 << CMD_HDR_SSP_FRAME_TYPE_OFF;
  897. has_data = 1;
  898. break;
  899. default:
  900. dw1 |= 0 << CMD_HDR_SSP_FRAME_TYPE_OFF;
  901. }
  902. }
  903. /* map itct entry */
  904. dw1 |= sas_dev->device_id << CMD_HDR_DEVICE_ID_OFF;
  905. hdr->dw1 = cpu_to_le32(dw1);
  906. if (tmf) {
  907. dw2 = ((sizeof(struct ssp_tmf_iu) +
  908. sizeof(struct ssp_frame_hdr)+3)/4) <<
  909. CMD_HDR_CFL_OFF;
  910. } else {
  911. dw2 = ((sizeof(struct ssp_command_iu) +
  912. sizeof(struct ssp_frame_hdr)+3)/4) <<
  913. CMD_HDR_CFL_OFF;
  914. }
  915. dw2 |= (HISI_SAS_MAX_SSP_RESP_SZ/4) << CMD_HDR_MRFL_OFF;
  916. hdr->transfer_tags = cpu_to_le32(slot->idx << CMD_HDR_IPTT_OFF);
  917. if (has_data)
  918. prep_prd_sge_v1_hw(hisi_hba, slot, hdr, task->scatter,
  919. slot->n_elem);
  920. hdr->data_transfer_len = cpu_to_le32(task->total_xfer_len);
  921. hdr->cmd_table_addr = cpu_to_le64(hisi_sas_cmd_hdr_addr_dma(slot));
  922. hdr->sts_buffer_addr = cpu_to_le64(hisi_sas_status_buf_addr_dma(slot));
  923. buf_cmd = hisi_sas_cmd_hdr_addr_mem(slot) +
  924. sizeof(struct ssp_frame_hdr);
  925. if (task->ssp_task.enable_first_burst) {
  926. fburst = (1 << 7);
  927. dw2 |= 1 << CMD_HDR_FIRST_BURST_OFF;
  928. }
  929. hdr->dw2 = cpu_to_le32(dw2);
  930. memcpy(buf_cmd, &task->ssp_task.LUN, 8);
  931. if (!tmf) {
  932. buf_cmd[9] = fburst | task->ssp_task.task_attr |
  933. (task->ssp_task.task_prio << 3);
  934. memcpy(buf_cmd + 12, task->ssp_task.cmd->cmnd,
  935. task->ssp_task.cmd->cmd_len);
  936. } else {
  937. buf_cmd[10] = tmf->tmf;
  938. switch (tmf->tmf) {
  939. case TMF_ABORT_TASK:
  940. case TMF_QUERY_TASK:
  941. buf_cmd[12] =
  942. (tmf->tag_of_task_to_be_managed >> 8) & 0xff;
  943. buf_cmd[13] =
  944. tmf->tag_of_task_to_be_managed & 0xff;
  945. break;
  946. default:
  947. break;
  948. }
  949. }
  950. }
  951. /* by default, task resp is complete */
  952. static void slot_err_v1_hw(struct hisi_hba *hisi_hba,
  953. struct sas_task *task,
  954. struct hisi_sas_slot *slot)
  955. {
  956. struct task_status_struct *ts = &task->task_status;
  957. struct hisi_sas_err_record_v1 *err_record =
  958. hisi_sas_status_buf_addr_mem(slot);
  959. struct device *dev = hisi_hba->dev;
  960. switch (task->task_proto) {
  961. case SAS_PROTOCOL_SSP:
  962. {
  963. int error = -1;
  964. u32 dma_err_type = cpu_to_le32(err_record->dma_err_type);
  965. u32 dma_tx_err_type = ((dma_err_type &
  966. ERR_HDR_DMA_TX_ERR_TYPE_MSK)) >>
  967. ERR_HDR_DMA_TX_ERR_TYPE_OFF;
  968. u32 dma_rx_err_type = ((dma_err_type &
  969. ERR_HDR_DMA_RX_ERR_TYPE_MSK)) >>
  970. ERR_HDR_DMA_RX_ERR_TYPE_OFF;
  971. u32 trans_tx_fail_type =
  972. cpu_to_le32(err_record->trans_tx_fail_type);
  973. u32 trans_rx_fail_type =
  974. cpu_to_le32(err_record->trans_rx_fail_type);
  975. if (dma_tx_err_type) {
  976. /* dma tx err */
  977. error = ffs(dma_tx_err_type)
  978. - 1 + DMA_TX_ERR_BASE;
  979. } else if (dma_rx_err_type) {
  980. /* dma rx err */
  981. error = ffs(dma_rx_err_type)
  982. - 1 + DMA_RX_ERR_BASE;
  983. } else if (trans_tx_fail_type) {
  984. /* trans tx err */
  985. error = ffs(trans_tx_fail_type)
  986. - 1 + TRANS_TX_FAIL_BASE;
  987. } else if (trans_rx_fail_type) {
  988. /* trans rx err */
  989. error = ffs(trans_rx_fail_type)
  990. - 1 + TRANS_RX_FAIL_BASE;
  991. }
  992. switch (error) {
  993. case DMA_TX_DATA_UNDERFLOW_ERR:
  994. case DMA_RX_DATA_UNDERFLOW_ERR:
  995. {
  996. ts->residual = 0;
  997. ts->stat = SAS_DATA_UNDERRUN;
  998. break;
  999. }
  1000. case DMA_TX_DATA_SGL_OVERFLOW_ERR:
  1001. case DMA_TX_DIF_SGL_OVERFLOW_ERR:
  1002. case DMA_TX_XFER_RDY_LENGTH_OVERFLOW_ERR:
  1003. case DMA_RX_DATA_OVERFLOW_ERR:
  1004. case TRANS_RX_FRAME_OVERRUN_ERR:
  1005. case TRANS_RX_LINK_BUF_OVERRUN_ERR:
  1006. {
  1007. ts->stat = SAS_DATA_OVERRUN;
  1008. ts->residual = 0;
  1009. break;
  1010. }
  1011. case TRANS_TX_PHY_NOT_ENABLE_ERR:
  1012. {
  1013. ts->stat = SAS_PHY_DOWN;
  1014. break;
  1015. }
  1016. case TRANS_TX_OPEN_REJCT_WRONG_DEST_ERR:
  1017. case TRANS_TX_OPEN_REJCT_ZONE_VIOLATION_ERR:
  1018. case TRANS_TX_OPEN_REJCT_BY_OTHER_ERR:
  1019. case TRANS_TX_OPEN_REJCT_AIP_TIMEOUT_ERR:
  1020. case TRANS_TX_OPEN_REJCT_STP_BUSY_ERR:
  1021. case TRANS_TX_OPEN_REJCT_PROTOCOL_NOT_SUPPORT_ERR:
  1022. case TRANS_TX_OPEN_REJCT_RATE_NOT_SUPPORT_ERR:
  1023. case TRANS_TX_OPEN_REJCT_BAD_DEST_ERR:
  1024. case TRANS_TX_OPEN_BREAK_RECEIVE_ERR:
  1025. case TRANS_TX_OPEN_REJCT_PATHWAY_BLOCKED_ERR:
  1026. case TRANS_TX_OPEN_REJCT_NO_DEST_ERR:
  1027. case TRANS_TX_OPEN_RETRY_ERR:
  1028. {
  1029. ts->stat = SAS_OPEN_REJECT;
  1030. ts->open_rej_reason = SAS_OREJ_UNKNOWN;
  1031. break;
  1032. }
  1033. case TRANS_TX_OPEN_TIMEOUT_ERR:
  1034. {
  1035. ts->stat = SAS_OPEN_TO;
  1036. break;
  1037. }
  1038. case TRANS_TX_NAK_RECEIVE_ERR:
  1039. case TRANS_TX_ACK_NAK_TIMEOUT_ERR:
  1040. {
  1041. ts->stat = SAS_NAK_R_ERR;
  1042. break;
  1043. }
  1044. case TRANS_TX_CREDIT_TIMEOUT_ERR:
  1045. case TRANS_TX_CLOSE_NORMAL_ERR:
  1046. {
  1047. /* This will request a retry */
  1048. ts->stat = SAS_QUEUE_FULL;
  1049. slot->abort = 1;
  1050. break;
  1051. }
  1052. default:
  1053. {
  1054. ts->stat = SAM_STAT_CHECK_CONDITION;
  1055. break;
  1056. }
  1057. }
  1058. }
  1059. break;
  1060. case SAS_PROTOCOL_SMP:
  1061. ts->stat = SAM_STAT_CHECK_CONDITION;
  1062. break;
  1063. case SAS_PROTOCOL_SATA:
  1064. case SAS_PROTOCOL_STP:
  1065. case SAS_PROTOCOL_SATA | SAS_PROTOCOL_STP:
  1066. {
  1067. dev_err(dev, "slot err: SATA/STP not supported");
  1068. }
  1069. break;
  1070. default:
  1071. break;
  1072. }
  1073. }
  1074. static int slot_complete_v1_hw(struct hisi_hba *hisi_hba,
  1075. struct hisi_sas_slot *slot)
  1076. {
  1077. struct sas_task *task = slot->task;
  1078. struct hisi_sas_device *sas_dev;
  1079. struct device *dev = hisi_hba->dev;
  1080. struct task_status_struct *ts;
  1081. struct domain_device *device;
  1082. enum exec_status sts;
  1083. struct hisi_sas_complete_v1_hdr *complete_queue =
  1084. hisi_hba->complete_hdr[slot->cmplt_queue];
  1085. struct hisi_sas_complete_v1_hdr *complete_hdr;
  1086. unsigned long flags;
  1087. u32 cmplt_hdr_data;
  1088. complete_hdr = &complete_queue[slot->cmplt_queue_slot];
  1089. cmplt_hdr_data = le32_to_cpu(complete_hdr->data);
  1090. if (unlikely(!task || !task->lldd_task || !task->dev))
  1091. return -EINVAL;
  1092. ts = &task->task_status;
  1093. device = task->dev;
  1094. sas_dev = device->lldd_dev;
  1095. spin_lock_irqsave(&task->task_state_lock, flags);
  1096. task->task_state_flags &=
  1097. ~(SAS_TASK_STATE_PENDING | SAS_TASK_AT_INITIATOR);
  1098. task->task_state_flags |= SAS_TASK_STATE_DONE;
  1099. spin_unlock_irqrestore(&task->task_state_lock, flags);
  1100. memset(ts, 0, sizeof(*ts));
  1101. ts->resp = SAS_TASK_COMPLETE;
  1102. if (unlikely(!sas_dev)) {
  1103. dev_dbg(dev, "slot complete: port has no device\n");
  1104. ts->stat = SAS_PHY_DOWN;
  1105. goto out;
  1106. }
  1107. if (cmplt_hdr_data & CMPLT_HDR_IO_CFG_ERR_MSK) {
  1108. u32 info_reg = hisi_sas_read32(hisi_hba, HGC_INVLD_DQE_INFO);
  1109. if (info_reg & HGC_INVLD_DQE_INFO_DQ_MSK)
  1110. dev_err(dev, "slot complete: [%d:%d] has dq IPTT err",
  1111. slot->cmplt_queue, slot->cmplt_queue_slot);
  1112. if (info_reg & HGC_INVLD_DQE_INFO_TYPE_MSK)
  1113. dev_err(dev, "slot complete: [%d:%d] has dq type err",
  1114. slot->cmplt_queue, slot->cmplt_queue_slot);
  1115. if (info_reg & HGC_INVLD_DQE_INFO_FORCE_MSK)
  1116. dev_err(dev, "slot complete: [%d:%d] has dq force phy err",
  1117. slot->cmplt_queue, slot->cmplt_queue_slot);
  1118. if (info_reg & HGC_INVLD_DQE_INFO_PHY_MSK)
  1119. dev_err(dev, "slot complete: [%d:%d] has dq phy id err",
  1120. slot->cmplt_queue, slot->cmplt_queue_slot);
  1121. if (info_reg & HGC_INVLD_DQE_INFO_ABORT_MSK)
  1122. dev_err(dev, "slot complete: [%d:%d] has dq abort flag err",
  1123. slot->cmplt_queue, slot->cmplt_queue_slot);
  1124. if (info_reg & HGC_INVLD_DQE_INFO_IPTT_OF_MSK)
  1125. dev_err(dev, "slot complete: [%d:%d] has dq IPTT or ICT err",
  1126. slot->cmplt_queue, slot->cmplt_queue_slot);
  1127. if (info_reg & HGC_INVLD_DQE_INFO_SSP_ERR_MSK)
  1128. dev_err(dev, "slot complete: [%d:%d] has dq SSP frame type err",
  1129. slot->cmplt_queue, slot->cmplt_queue_slot);
  1130. if (info_reg & HGC_INVLD_DQE_INFO_OFL_MSK)
  1131. dev_err(dev, "slot complete: [%d:%d] has dq order frame len err",
  1132. slot->cmplt_queue, slot->cmplt_queue_slot);
  1133. ts->stat = SAS_OPEN_REJECT;
  1134. ts->open_rej_reason = SAS_OREJ_UNKNOWN;
  1135. goto out;
  1136. }
  1137. if (cmplt_hdr_data & CMPLT_HDR_ERR_RCRD_XFRD_MSK &&
  1138. !(cmplt_hdr_data & CMPLT_HDR_RSPNS_XFRD_MSK)) {
  1139. slot_err_v1_hw(hisi_hba, task, slot);
  1140. if (unlikely(slot->abort))
  1141. return ts->stat;
  1142. goto out;
  1143. }
  1144. switch (task->task_proto) {
  1145. case SAS_PROTOCOL_SSP:
  1146. {
  1147. struct hisi_sas_status_buffer *status_buffer =
  1148. hisi_sas_status_buf_addr_mem(slot);
  1149. struct ssp_response_iu *iu = (struct ssp_response_iu *)
  1150. &status_buffer->iu[0];
  1151. sas_ssp_task_response(dev, task, iu);
  1152. break;
  1153. }
  1154. case SAS_PROTOCOL_SMP:
  1155. {
  1156. void *to;
  1157. struct scatterlist *sg_resp = &task->smp_task.smp_resp;
  1158. ts->stat = SAM_STAT_GOOD;
  1159. to = kmap_atomic(sg_page(sg_resp));
  1160. dma_unmap_sg(dev, &task->smp_task.smp_resp, 1,
  1161. DMA_FROM_DEVICE);
  1162. dma_unmap_sg(dev, &task->smp_task.smp_req, 1,
  1163. DMA_TO_DEVICE);
  1164. memcpy(to + sg_resp->offset,
  1165. hisi_sas_status_buf_addr_mem(slot) +
  1166. sizeof(struct hisi_sas_err_record),
  1167. sg_dma_len(sg_resp));
  1168. kunmap_atomic(to);
  1169. break;
  1170. }
  1171. case SAS_PROTOCOL_SATA:
  1172. case SAS_PROTOCOL_STP:
  1173. case SAS_PROTOCOL_SATA | SAS_PROTOCOL_STP:
  1174. dev_err(dev, "slot complete: SATA/STP not supported");
  1175. break;
  1176. default:
  1177. ts->stat = SAM_STAT_CHECK_CONDITION;
  1178. break;
  1179. }
  1180. if (!slot->port->port_attached) {
  1181. dev_err(dev, "slot complete: port %d has removed\n",
  1182. slot->port->sas_port.id);
  1183. ts->stat = SAS_PHY_DOWN;
  1184. }
  1185. out:
  1186. hisi_sas_slot_task_free(hisi_hba, task, slot);
  1187. sts = ts->stat;
  1188. if (task->task_done)
  1189. task->task_done(task);
  1190. return sts;
  1191. }
  1192. /* Interrupts */
  1193. static irqreturn_t int_phyup_v1_hw(int irq_no, void *p)
  1194. {
  1195. struct hisi_sas_phy *phy = p;
  1196. struct hisi_hba *hisi_hba = phy->hisi_hba;
  1197. struct device *dev = hisi_hba->dev;
  1198. struct asd_sas_phy *sas_phy = &phy->sas_phy;
  1199. int i, phy_no = sas_phy->id;
  1200. u32 irq_value, context, port_id, link_rate;
  1201. u32 *frame_rcvd = (u32 *)sas_phy->frame_rcvd;
  1202. struct sas_identify_frame *id = (struct sas_identify_frame *)frame_rcvd;
  1203. irqreturn_t res = IRQ_HANDLED;
  1204. unsigned long flags;
  1205. irq_value = hisi_sas_phy_read32(hisi_hba, phy_no, CHL_INT2);
  1206. if (!(irq_value & CHL_INT2_SL_PHY_ENA_MSK)) {
  1207. dev_dbg(dev, "phyup: irq_value = %x not set enable bit\n",
  1208. irq_value);
  1209. res = IRQ_NONE;
  1210. goto end;
  1211. }
  1212. context = hisi_sas_read32(hisi_hba, PHY_CONTEXT);
  1213. if (context & 1 << phy_no) {
  1214. dev_err(dev, "phyup: phy%d SATA attached equipment\n",
  1215. phy_no);
  1216. goto end;
  1217. }
  1218. port_id = (hisi_sas_read32(hisi_hba, PHY_PORT_NUM_MA) >> (4 * phy_no))
  1219. & 0xf;
  1220. if (port_id == 0xf) {
  1221. dev_err(dev, "phyup: phy%d invalid portid\n", phy_no);
  1222. res = IRQ_NONE;
  1223. goto end;
  1224. }
  1225. for (i = 0; i < 6; i++) {
  1226. u32 idaf = hisi_sas_phy_read32(hisi_hba, phy_no,
  1227. RX_IDAF_DWORD0 + (i * 4));
  1228. frame_rcvd[i] = __swab32(idaf);
  1229. }
  1230. /* Get the linkrate */
  1231. link_rate = hisi_sas_read32(hisi_hba, PHY_CONN_RATE);
  1232. link_rate = (link_rate >> (phy_no * 4)) & 0xf;
  1233. sas_phy->linkrate = link_rate;
  1234. sas_phy->oob_mode = SAS_OOB_MODE;
  1235. memcpy(sas_phy->attached_sas_addr,
  1236. &id->sas_addr, SAS_ADDR_SIZE);
  1237. dev_info(dev, "phyup: phy%d link_rate=%d\n",
  1238. phy_no, link_rate);
  1239. phy->port_id = port_id;
  1240. phy->phy_type &= ~(PORT_TYPE_SAS | PORT_TYPE_SATA);
  1241. phy->phy_type |= PORT_TYPE_SAS;
  1242. phy->phy_attached = 1;
  1243. phy->identify.device_type = id->dev_type;
  1244. phy->frame_rcvd_size = sizeof(struct sas_identify_frame);
  1245. if (phy->identify.device_type == SAS_END_DEVICE)
  1246. phy->identify.target_port_protocols =
  1247. SAS_PROTOCOL_SSP;
  1248. else if (phy->identify.device_type != SAS_PHY_UNUSED)
  1249. phy->identify.target_port_protocols =
  1250. SAS_PROTOCOL_SMP;
  1251. hisi_sas_notify_phy_event(phy, HISI_PHYE_PHY_UP);
  1252. spin_lock_irqsave(&phy->lock, flags);
  1253. if (phy->reset_completion) {
  1254. phy->in_reset = 0;
  1255. complete(phy->reset_completion);
  1256. }
  1257. spin_unlock_irqrestore(&phy->lock, flags);
  1258. end:
  1259. hisi_sas_phy_write32(hisi_hba, phy_no, CHL_INT2,
  1260. CHL_INT2_SL_PHY_ENA_MSK);
  1261. if (irq_value & CHL_INT2_SL_PHY_ENA_MSK) {
  1262. u32 chl_int0 = hisi_sas_phy_read32(hisi_hba, phy_no, CHL_INT0);
  1263. chl_int0 &= ~CHL_INT0_PHYCTRL_NOTRDY_MSK;
  1264. hisi_sas_phy_write32(hisi_hba, phy_no, CHL_INT0, chl_int0);
  1265. hisi_sas_phy_write32(hisi_hba, phy_no, CHL_INT0_MSK, 0x3ce3ee);
  1266. }
  1267. return res;
  1268. }
  1269. static irqreturn_t int_bcast_v1_hw(int irq, void *p)
  1270. {
  1271. struct hisi_sas_phy *phy = p;
  1272. struct hisi_hba *hisi_hba = phy->hisi_hba;
  1273. struct asd_sas_phy *sas_phy = &phy->sas_phy;
  1274. struct sas_ha_struct *sha = &hisi_hba->sha;
  1275. struct device *dev = hisi_hba->dev;
  1276. int phy_no = sas_phy->id;
  1277. u32 irq_value;
  1278. irqreturn_t res = IRQ_HANDLED;
  1279. irq_value = hisi_sas_phy_read32(hisi_hba, phy_no, CHL_INT2);
  1280. if (!(irq_value & CHL_INT2_SL_RX_BC_ACK_MSK)) {
  1281. dev_err(dev, "bcast: irq_value = %x not set enable bit",
  1282. irq_value);
  1283. res = IRQ_NONE;
  1284. goto end;
  1285. }
  1286. if (!test_bit(HISI_SAS_RESET_BIT, &hisi_hba->flags))
  1287. sha->notify_port_event(sas_phy, PORTE_BROADCAST_RCVD);
  1288. end:
  1289. hisi_sas_phy_write32(hisi_hba, phy_no, CHL_INT2,
  1290. CHL_INT2_SL_RX_BC_ACK_MSK);
  1291. return res;
  1292. }
  1293. static irqreturn_t int_abnormal_v1_hw(int irq, void *p)
  1294. {
  1295. struct hisi_sas_phy *phy = p;
  1296. struct hisi_hba *hisi_hba = phy->hisi_hba;
  1297. struct device *dev = hisi_hba->dev;
  1298. struct asd_sas_phy *sas_phy = &phy->sas_phy;
  1299. u32 irq_value, irq_mask_old;
  1300. int phy_no = sas_phy->id;
  1301. /* mask_int0 */
  1302. irq_mask_old = hisi_sas_phy_read32(hisi_hba, phy_no, CHL_INT0_MSK);
  1303. hisi_sas_phy_write32(hisi_hba, phy_no, CHL_INT0_MSK, 0x3fffff);
  1304. /* read int0 */
  1305. irq_value = hisi_sas_phy_read32(hisi_hba, phy_no, CHL_INT0);
  1306. if (irq_value & CHL_INT0_PHYCTRL_NOTRDY_MSK) {
  1307. u32 phy_state = hisi_sas_read32(hisi_hba, PHY_STATE);
  1308. hisi_sas_phy_down(hisi_hba, phy_no,
  1309. (phy_state & 1 << phy_no) ? 1 : 0);
  1310. }
  1311. if (irq_value & CHL_INT0_ID_TIMEOUT_MSK)
  1312. dev_dbg(dev, "abnormal: ID_TIMEOUT phy%d identify timeout\n",
  1313. phy_no);
  1314. if (irq_value & CHL_INT0_DWS_LOST_MSK)
  1315. dev_dbg(dev, "abnormal: DWS_LOST phy%d dws lost\n", phy_no);
  1316. if (irq_value & CHL_INT0_SN_FAIL_NGR_MSK)
  1317. dev_dbg(dev, "abnormal: SN_FAIL_NGR phy%d sn fail ngr\n",
  1318. phy_no);
  1319. if (irq_value & CHL_INT0_SL_IDAF_FAIL_MSK ||
  1320. irq_value & CHL_INT0_SL_OPAF_FAIL_MSK)
  1321. dev_dbg(dev, "abnormal: SL_ID/OPAF_FAIL phy%d check adr frm err\n",
  1322. phy_no);
  1323. if (irq_value & CHL_INT0_SL_PS_FAIL_OFF)
  1324. dev_dbg(dev, "abnormal: SL_PS_FAIL phy%d fail\n", phy_no);
  1325. /* write to zero */
  1326. hisi_sas_phy_write32(hisi_hba, phy_no, CHL_INT0, irq_value);
  1327. if (irq_value & CHL_INT0_PHYCTRL_NOTRDY_MSK)
  1328. hisi_sas_phy_write32(hisi_hba, phy_no, CHL_INT0_MSK,
  1329. 0x3fffff & ~CHL_INT0_MSK_PHYCTRL_NOTRDY_MSK);
  1330. else
  1331. hisi_sas_phy_write32(hisi_hba, phy_no, CHL_INT0_MSK,
  1332. irq_mask_old);
  1333. return IRQ_HANDLED;
  1334. }
  1335. static irqreturn_t cq_interrupt_v1_hw(int irq, void *p)
  1336. {
  1337. struct hisi_sas_cq *cq = p;
  1338. struct hisi_hba *hisi_hba = cq->hisi_hba;
  1339. struct hisi_sas_slot *slot;
  1340. int queue = cq->id;
  1341. struct hisi_sas_complete_v1_hdr *complete_queue =
  1342. (struct hisi_sas_complete_v1_hdr *)
  1343. hisi_hba->complete_hdr[queue];
  1344. u32 irq_value, rd_point = cq->rd_point, wr_point;
  1345. spin_lock(&hisi_hba->lock);
  1346. irq_value = hisi_sas_read32(hisi_hba, OQ_INT_SRC);
  1347. hisi_sas_write32(hisi_hba, OQ_INT_SRC, 1 << queue);
  1348. wr_point = hisi_sas_read32(hisi_hba,
  1349. COMPL_Q_0_WR_PTR + (0x14 * queue));
  1350. while (rd_point != wr_point) {
  1351. struct hisi_sas_complete_v1_hdr *complete_hdr;
  1352. int idx;
  1353. u32 cmplt_hdr_data;
  1354. complete_hdr = &complete_queue[rd_point];
  1355. cmplt_hdr_data = cpu_to_le32(complete_hdr->data);
  1356. idx = (cmplt_hdr_data & CMPLT_HDR_IPTT_MSK) >>
  1357. CMPLT_HDR_IPTT_OFF;
  1358. slot = &hisi_hba->slot_info[idx];
  1359. /* The completion queue and queue slot index are not
  1360. * necessarily the same as the delivery queue and
  1361. * queue slot index.
  1362. */
  1363. slot->cmplt_queue_slot = rd_point;
  1364. slot->cmplt_queue = queue;
  1365. slot_complete_v1_hw(hisi_hba, slot);
  1366. if (++rd_point >= HISI_SAS_QUEUE_SLOTS)
  1367. rd_point = 0;
  1368. }
  1369. /* update rd_point */
  1370. cq->rd_point = rd_point;
  1371. hisi_sas_write32(hisi_hba, COMPL_Q_0_RD_PTR + (0x14 * queue), rd_point);
  1372. spin_unlock(&hisi_hba->lock);
  1373. return IRQ_HANDLED;
  1374. }
  1375. static irqreturn_t fatal_ecc_int_v1_hw(int irq, void *p)
  1376. {
  1377. struct hisi_hba *hisi_hba = p;
  1378. struct device *dev = hisi_hba->dev;
  1379. u32 ecc_int = hisi_sas_read32(hisi_hba, SAS_ECC_INTR);
  1380. if (ecc_int & SAS_ECC_INTR_DQ_ECC1B_MSK) {
  1381. u32 ecc_err = hisi_sas_read32(hisi_hba, HGC_ECC_ERR);
  1382. panic("%s: Fatal DQ 1b ECC interrupt (0x%x)\n",
  1383. dev_name(dev), ecc_err);
  1384. }
  1385. if (ecc_int & SAS_ECC_INTR_DQ_ECCBAD_MSK) {
  1386. u32 addr = (hisi_sas_read32(hisi_hba, HGC_DQ_ECC_ADDR) &
  1387. HGC_DQ_ECC_ADDR_BAD_MSK) >>
  1388. HGC_DQ_ECC_ADDR_BAD_OFF;
  1389. panic("%s: Fatal DQ RAM ECC interrupt @ 0x%08x\n",
  1390. dev_name(dev), addr);
  1391. }
  1392. if (ecc_int & SAS_ECC_INTR_IOST_ECC1B_MSK) {
  1393. u32 ecc_err = hisi_sas_read32(hisi_hba, HGC_ECC_ERR);
  1394. panic("%s: Fatal IOST 1b ECC interrupt (0x%x)\n",
  1395. dev_name(dev), ecc_err);
  1396. }
  1397. if (ecc_int & SAS_ECC_INTR_IOST_ECCBAD_MSK) {
  1398. u32 addr = (hisi_sas_read32(hisi_hba, HGC_IOST_ECC_ADDR) &
  1399. HGC_IOST_ECC_ADDR_BAD_MSK) >>
  1400. HGC_IOST_ECC_ADDR_BAD_OFF;
  1401. panic("%s: Fatal IOST RAM ECC interrupt @ 0x%08x\n",
  1402. dev_name(dev), addr);
  1403. }
  1404. if (ecc_int & SAS_ECC_INTR_ITCT_ECCBAD_MSK) {
  1405. u32 addr = (hisi_sas_read32(hisi_hba, HGC_ITCT_ECC_ADDR) &
  1406. HGC_ITCT_ECC_ADDR_BAD_MSK) >>
  1407. HGC_ITCT_ECC_ADDR_BAD_OFF;
  1408. panic("%s: Fatal TCT RAM ECC interrupt @ 0x%08x\n",
  1409. dev_name(dev), addr);
  1410. }
  1411. if (ecc_int & SAS_ECC_INTR_ITCT_ECC1B_MSK) {
  1412. u32 ecc_err = hisi_sas_read32(hisi_hba, HGC_ECC_ERR);
  1413. panic("%s: Fatal ITCT 1b ECC interrupt (0x%x)\n",
  1414. dev_name(dev), ecc_err);
  1415. }
  1416. hisi_sas_write32(hisi_hba, SAS_ECC_INTR, ecc_int | 0x3f);
  1417. return IRQ_HANDLED;
  1418. }
  1419. static irqreturn_t fatal_axi_int_v1_hw(int irq, void *p)
  1420. {
  1421. struct hisi_hba *hisi_hba = p;
  1422. struct device *dev = hisi_hba->dev;
  1423. u32 axi_int = hisi_sas_read32(hisi_hba, ENT_INT_SRC2);
  1424. u32 axi_info = hisi_sas_read32(hisi_hba, HGC_AXI_FIFO_ERR_INFO);
  1425. if (axi_int & ENT_INT_SRC2_DQ_CFG_ERR_MSK)
  1426. panic("%s: Fatal DQ_CFG_ERR interrupt (0x%x)\n",
  1427. dev_name(dev), axi_info);
  1428. if (axi_int & ENT_INT_SRC2_CQ_CFG_ERR_MSK)
  1429. panic("%s: Fatal CQ_CFG_ERR interrupt (0x%x)\n",
  1430. dev_name(dev), axi_info);
  1431. if (axi_int & ENT_INT_SRC2_AXI_WRONG_INT_MSK)
  1432. panic("%s: Fatal AXI_WRONG_INT interrupt (0x%x)\n",
  1433. dev_name(dev), axi_info);
  1434. if (axi_int & ENT_INT_SRC2_AXI_OVERLF_INT_MSK)
  1435. panic("%s: Fatal AXI_OVERLF_INT incorrect interrupt (0x%x)\n",
  1436. dev_name(dev), axi_info);
  1437. hisi_sas_write32(hisi_hba, ENT_INT_SRC2, axi_int | 0x30000000);
  1438. return IRQ_HANDLED;
  1439. }
  1440. static irq_handler_t phy_interrupts[HISI_SAS_PHY_INT_NR] = {
  1441. int_bcast_v1_hw,
  1442. int_phyup_v1_hw,
  1443. int_abnormal_v1_hw
  1444. };
  1445. static irq_handler_t fatal_interrupts[HISI_SAS_MAX_QUEUES] = {
  1446. fatal_ecc_int_v1_hw,
  1447. fatal_axi_int_v1_hw
  1448. };
  1449. static int interrupt_init_v1_hw(struct hisi_hba *hisi_hba)
  1450. {
  1451. struct platform_device *pdev = hisi_hba->platform_dev;
  1452. struct device *dev = &pdev->dev;
  1453. int i, j, irq, rc, idx;
  1454. for (i = 0; i < hisi_hba->n_phy; i++) {
  1455. struct hisi_sas_phy *phy = &hisi_hba->phy[i];
  1456. idx = i * HISI_SAS_PHY_INT_NR;
  1457. for (j = 0; j < HISI_SAS_PHY_INT_NR; j++, idx++) {
  1458. irq = platform_get_irq(pdev, idx);
  1459. if (!irq) {
  1460. dev_err(dev,
  1461. "irq init: fail map phy interrupt %d\n",
  1462. idx);
  1463. return -ENOENT;
  1464. }
  1465. rc = devm_request_irq(dev, irq, phy_interrupts[j], 0,
  1466. DRV_NAME " phy", phy);
  1467. if (rc) {
  1468. dev_err(dev, "irq init: could not request "
  1469. "phy interrupt %d, rc=%d\n",
  1470. irq, rc);
  1471. return -ENOENT;
  1472. }
  1473. }
  1474. }
  1475. idx = hisi_hba->n_phy * HISI_SAS_PHY_INT_NR;
  1476. for (i = 0; i < hisi_hba->queue_count; i++, idx++) {
  1477. irq = platform_get_irq(pdev, idx);
  1478. if (!irq) {
  1479. dev_err(dev, "irq init: could not map cq interrupt %d\n",
  1480. idx);
  1481. return -ENOENT;
  1482. }
  1483. rc = devm_request_irq(dev, irq, cq_interrupt_v1_hw, 0,
  1484. DRV_NAME " cq", &hisi_hba->cq[i]);
  1485. if (rc) {
  1486. dev_err(dev, "irq init: could not request cq interrupt %d, rc=%d\n",
  1487. irq, rc);
  1488. return -ENOENT;
  1489. }
  1490. }
  1491. idx = (hisi_hba->n_phy * HISI_SAS_PHY_INT_NR) + hisi_hba->queue_count;
  1492. for (i = 0; i < HISI_SAS_FATAL_INT_NR; i++, idx++) {
  1493. irq = platform_get_irq(pdev, idx);
  1494. if (!irq) {
  1495. dev_err(dev, "irq init: could not map fatal interrupt %d\n",
  1496. idx);
  1497. return -ENOENT;
  1498. }
  1499. rc = devm_request_irq(dev, irq, fatal_interrupts[i], 0,
  1500. DRV_NAME " fatal", hisi_hba);
  1501. if (rc) {
  1502. dev_err(dev,
  1503. "irq init: could not request fatal interrupt %d, rc=%d\n",
  1504. irq, rc);
  1505. return -ENOENT;
  1506. }
  1507. }
  1508. return 0;
  1509. }
  1510. static int interrupt_openall_v1_hw(struct hisi_hba *hisi_hba)
  1511. {
  1512. int i;
  1513. u32 val;
  1514. for (i = 0; i < hisi_hba->n_phy; i++) {
  1515. /* Clear interrupt status */
  1516. val = hisi_sas_phy_read32(hisi_hba, i, CHL_INT0);
  1517. hisi_sas_phy_write32(hisi_hba, i, CHL_INT0, val);
  1518. val = hisi_sas_phy_read32(hisi_hba, i, CHL_INT1);
  1519. hisi_sas_phy_write32(hisi_hba, i, CHL_INT1, val);
  1520. val = hisi_sas_phy_read32(hisi_hba, i, CHL_INT2);
  1521. hisi_sas_phy_write32(hisi_hba, i, CHL_INT2, val);
  1522. /* Unmask interrupt */
  1523. hisi_sas_phy_write32(hisi_hba, i, CHL_INT0_MSK, 0x3ce3ee);
  1524. hisi_sas_phy_write32(hisi_hba, i, CHL_INT1_MSK, 0x17fff);
  1525. hisi_sas_phy_write32(hisi_hba, i, CHL_INT2_MSK, 0x8000012a);
  1526. /* bypass chip bug mask abnormal intr */
  1527. hisi_sas_phy_write32(hisi_hba, i, CHL_INT0_MSK,
  1528. 0x3fffff & ~CHL_INT0_MSK_PHYCTRL_NOTRDY_MSK);
  1529. }
  1530. return 0;
  1531. }
  1532. static int hisi_sas_v1_init(struct hisi_hba *hisi_hba)
  1533. {
  1534. int rc;
  1535. rc = hw_init_v1_hw(hisi_hba);
  1536. if (rc)
  1537. return rc;
  1538. rc = interrupt_init_v1_hw(hisi_hba);
  1539. if (rc)
  1540. return rc;
  1541. rc = interrupt_openall_v1_hw(hisi_hba);
  1542. if (rc)
  1543. return rc;
  1544. return 0;
  1545. }
  1546. static struct scsi_host_template sht_v1_hw = {
  1547. .name = DRV_NAME,
  1548. .module = THIS_MODULE,
  1549. .queuecommand = sas_queuecommand,
  1550. .target_alloc = sas_target_alloc,
  1551. .slave_configure = hisi_sas_slave_configure,
  1552. .scan_finished = hisi_sas_scan_finished,
  1553. .scan_start = hisi_sas_scan_start,
  1554. .change_queue_depth = sas_change_queue_depth,
  1555. .bios_param = sas_bios_param,
  1556. .can_queue = 1,
  1557. .this_id = -1,
  1558. .sg_tablesize = SG_ALL,
  1559. .max_sectors = SCSI_DEFAULT_MAX_SECTORS,
  1560. .use_clustering = ENABLE_CLUSTERING,
  1561. .eh_device_reset_handler = sas_eh_device_reset_handler,
  1562. .eh_target_reset_handler = sas_eh_target_reset_handler,
  1563. .target_destroy = sas_target_destroy,
  1564. .ioctl = sas_ioctl,
  1565. .shost_attrs = host_attrs,
  1566. };
  1567. static const struct hisi_sas_hw hisi_sas_v1_hw = {
  1568. .hw_init = hisi_sas_v1_init,
  1569. .setup_itct = setup_itct_v1_hw,
  1570. .sl_notify_ssp = sl_notify_ssp_v1_hw,
  1571. .clear_itct = clear_itct_v1_hw,
  1572. .prep_smp = prep_smp_v1_hw,
  1573. .prep_ssp = prep_ssp_v1_hw,
  1574. .get_free_slot = get_free_slot_v1_hw,
  1575. .start_delivery = start_delivery_v1_hw,
  1576. .slot_complete = slot_complete_v1_hw,
  1577. .phys_init = phys_init_v1_hw,
  1578. .phy_start = start_phy_v1_hw,
  1579. .phy_disable = disable_phy_v1_hw,
  1580. .phy_hard_reset = phy_hard_reset_v1_hw,
  1581. .phy_set_linkrate = phy_set_linkrate_v1_hw,
  1582. .phy_get_max_linkrate = phy_get_max_linkrate_v1_hw,
  1583. .get_wideport_bitmap = get_wideport_bitmap_v1_hw,
  1584. .max_command_entries = HISI_SAS_COMMAND_ENTRIES_V1_HW,
  1585. .complete_hdr_size = sizeof(struct hisi_sas_complete_v1_hdr),
  1586. .sht = &sht_v1_hw,
  1587. };
  1588. static int hisi_sas_v1_probe(struct platform_device *pdev)
  1589. {
  1590. return hisi_sas_probe(pdev, &hisi_sas_v1_hw);
  1591. }
  1592. static int hisi_sas_v1_remove(struct platform_device *pdev)
  1593. {
  1594. return hisi_sas_remove(pdev);
  1595. }
  1596. static const struct of_device_id sas_v1_of_match[] = {
  1597. { .compatible = "hisilicon,hip05-sas-v1",},
  1598. {},
  1599. };
  1600. MODULE_DEVICE_TABLE(of, sas_v1_of_match);
  1601. static const struct acpi_device_id sas_v1_acpi_match[] = {
  1602. { "HISI0161", 0 },
  1603. { }
  1604. };
  1605. MODULE_DEVICE_TABLE(acpi, sas_v1_acpi_match);
  1606. static struct platform_driver hisi_sas_v1_driver = {
  1607. .probe = hisi_sas_v1_probe,
  1608. .remove = hisi_sas_v1_remove,
  1609. .driver = {
  1610. .name = DRV_NAME,
  1611. .of_match_table = sas_v1_of_match,
  1612. .acpi_match_table = ACPI_PTR(sas_v1_acpi_match),
  1613. },
  1614. };
  1615. module_platform_driver(hisi_sas_v1_driver);
  1616. MODULE_LICENSE("GPL");
  1617. MODULE_AUTHOR("John Garry <john.garry@huawei.com>");
  1618. MODULE_DESCRIPTION("HISILICON SAS controller v1 hw driver");
  1619. MODULE_ALIAS("platform:" DRV_NAME);