hisi_sas_v1_hw.c 56 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888
  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. u64 sas_addr;
  473. memset(itct, 0, sizeof(*itct));
  474. /* qw0 */
  475. qw0 = 0;
  476. switch (sas_dev->dev_type) {
  477. case SAS_END_DEVICE:
  478. case SAS_EDGE_EXPANDER_DEVICE:
  479. case SAS_FANOUT_EXPANDER_DEVICE:
  480. qw0 = HISI_SAS_DEV_TYPE_SSP << ITCT_HDR_DEV_TYPE_OFF;
  481. break;
  482. default:
  483. dev_warn(dev, "setup itct: unsupported dev type (%d)\n",
  484. sas_dev->dev_type);
  485. }
  486. qw0 |= ((1 << ITCT_HDR_VALID_OFF) |
  487. (1 << ITCT_HDR_AWT_CONTROL_OFF) |
  488. (device->max_linkrate << ITCT_HDR_MAX_CONN_RATE_OFF) |
  489. (1 << ITCT_HDR_VALID_LINK_NUM_OFF) |
  490. (port->id << ITCT_HDR_PORT_ID_OFF));
  491. itct->qw0 = cpu_to_le64(qw0);
  492. /* qw1 */
  493. memcpy(&sas_addr, device->sas_addr, SAS_ADDR_SIZE);
  494. itct->sas_addr = cpu_to_le64(__swab64(sas_addr));
  495. /* qw2 */
  496. itct->qw2 = cpu_to_le64((500ULL << ITCT_HDR_IT_NEXUS_LOSS_TL_OFF) |
  497. (0xff00ULL << ITCT_HDR_BUS_INACTIVE_TL_OFF) |
  498. (0xff00ULL << ITCT_HDR_MAX_CONN_TL_OFF) |
  499. (0xff00ULL << ITCT_HDR_REJ_OPEN_TL_OFF));
  500. }
  501. static void clear_itct_v1_hw(struct hisi_hba *hisi_hba,
  502. struct hisi_sas_device *sas_dev)
  503. {
  504. u64 dev_id = sas_dev->device_id;
  505. struct hisi_sas_itct *itct = &hisi_hba->itct[dev_id];
  506. u64 qw0;
  507. u32 reg_val = hisi_sas_read32(hisi_hba, CFG_AGING_TIME);
  508. reg_val |= CFG_AGING_TIME_ITCT_REL_MSK;
  509. hisi_sas_write32(hisi_hba, CFG_AGING_TIME, reg_val);
  510. /* free itct */
  511. udelay(1);
  512. reg_val = hisi_sas_read32(hisi_hba, CFG_AGING_TIME);
  513. reg_val &= ~CFG_AGING_TIME_ITCT_REL_MSK;
  514. hisi_sas_write32(hisi_hba, CFG_AGING_TIME, reg_val);
  515. qw0 = le64_to_cpu(itct->qw0);
  516. qw0 &= ~ITCT_HDR_VALID_MSK;
  517. itct->qw0 = cpu_to_le64(qw0);
  518. }
  519. static int reset_hw_v1_hw(struct hisi_hba *hisi_hba)
  520. {
  521. int i;
  522. unsigned long end_time;
  523. u32 val;
  524. struct device *dev = hisi_hba->dev;
  525. for (i = 0; i < hisi_hba->n_phy; i++) {
  526. u32 phy_ctrl = hisi_sas_phy_read32(hisi_hba, i, PHY_CTRL);
  527. phy_ctrl |= PHY_CTRL_RESET_MSK;
  528. hisi_sas_phy_write32(hisi_hba, i, PHY_CTRL, phy_ctrl);
  529. }
  530. msleep(1); /* It is safe to wait for 50us */
  531. /* Ensure DMA tx & rx idle */
  532. for (i = 0; i < hisi_hba->n_phy; i++) {
  533. u32 dma_tx_status, dma_rx_status;
  534. end_time = jiffies + msecs_to_jiffies(1000);
  535. while (1) {
  536. dma_tx_status = hisi_sas_phy_read32(hisi_hba, i,
  537. DMA_TX_STATUS);
  538. dma_rx_status = hisi_sas_phy_read32(hisi_hba, i,
  539. DMA_RX_STATUS);
  540. if (!(dma_tx_status & DMA_TX_STATUS_BUSY_MSK) &&
  541. !(dma_rx_status & DMA_RX_STATUS_BUSY_MSK))
  542. break;
  543. msleep(20);
  544. if (time_after(jiffies, end_time))
  545. return -EIO;
  546. }
  547. }
  548. /* Ensure axi bus idle */
  549. end_time = jiffies + msecs_to_jiffies(1000);
  550. while (1) {
  551. u32 axi_status =
  552. hisi_sas_read32(hisi_hba, AXI_CFG);
  553. if (axi_status == 0)
  554. break;
  555. msleep(20);
  556. if (time_after(jiffies, end_time))
  557. return -EIO;
  558. }
  559. if (ACPI_HANDLE(dev)) {
  560. acpi_status s;
  561. s = acpi_evaluate_object(ACPI_HANDLE(dev), "_RST", NULL, NULL);
  562. if (ACPI_FAILURE(s)) {
  563. dev_err(dev, "Reset failed\n");
  564. return -EIO;
  565. }
  566. } else if (hisi_hba->ctrl) {
  567. /* Apply reset and disable clock */
  568. /* clk disable reg is offset by +4 bytes from clk enable reg */
  569. regmap_write(hisi_hba->ctrl, hisi_hba->ctrl_reset_reg,
  570. RESET_VALUE);
  571. regmap_write(hisi_hba->ctrl, hisi_hba->ctrl_clock_ena_reg + 4,
  572. RESET_VALUE);
  573. msleep(1);
  574. regmap_read(hisi_hba->ctrl, hisi_hba->ctrl_reset_sts_reg, &val);
  575. if (RESET_VALUE != (val & RESET_VALUE)) {
  576. dev_err(dev, "Reset failed\n");
  577. return -EIO;
  578. }
  579. /* De-reset and enable clock */
  580. /* deassert rst reg is offset by +4 bytes from assert reg */
  581. regmap_write(hisi_hba->ctrl, hisi_hba->ctrl_reset_reg + 4,
  582. RESET_VALUE);
  583. regmap_write(hisi_hba->ctrl, hisi_hba->ctrl_clock_ena_reg,
  584. RESET_VALUE);
  585. msleep(1);
  586. regmap_read(hisi_hba->ctrl, hisi_hba->ctrl_reset_sts_reg, &val);
  587. if (val & RESET_VALUE) {
  588. dev_err(dev, "De-reset failed\n");
  589. return -EIO;
  590. }
  591. } else {
  592. dev_warn(dev, "no reset method\n");
  593. return -EINVAL;
  594. }
  595. return 0;
  596. }
  597. static void init_reg_v1_hw(struct hisi_hba *hisi_hba)
  598. {
  599. int i;
  600. /* Global registers init*/
  601. hisi_sas_write32(hisi_hba, DLVRY_QUEUE_ENABLE,
  602. (u32)((1ULL << hisi_hba->queue_count) - 1));
  603. hisi_sas_write32(hisi_hba, HGC_TRANS_TASK_CNT_LIMIT, 0x11);
  604. hisi_sas_write32(hisi_hba, DEVICE_MSG_WORK_MODE, 0x1);
  605. hisi_sas_write32(hisi_hba, HGC_SAS_TXFAIL_RETRY_CTRL, 0x1ff);
  606. hisi_sas_write32(hisi_hba, HGC_ERR_STAT_EN, 0x401);
  607. hisi_sas_write32(hisi_hba, CFG_1US_TIMER_TRSH, 0x64);
  608. hisi_sas_write32(hisi_hba, HGC_GET_ITV_TIME, 0x1);
  609. hisi_sas_write32(hisi_hba, I_T_NEXUS_LOSS_TIME, 0x64);
  610. hisi_sas_write32(hisi_hba, BUS_INACTIVE_LIMIT_TIME, 0x2710);
  611. hisi_sas_write32(hisi_hba, REJECT_TO_OPEN_LIMIT_TIME, 0x1);
  612. hisi_sas_write32(hisi_hba, CFG_AGING_TIME, 0x7a12);
  613. hisi_sas_write32(hisi_hba, HGC_DFX_CFG2, 0x9c40);
  614. hisi_sas_write32(hisi_hba, FIS_LIST_BADDR_L, 0x2);
  615. hisi_sas_write32(hisi_hba, INT_COAL_EN, 0xc);
  616. hisi_sas_write32(hisi_hba, OQ_INT_COAL_TIME, 0x186a0);
  617. hisi_sas_write32(hisi_hba, OQ_INT_COAL_CNT, 1);
  618. hisi_sas_write32(hisi_hba, ENT_INT_COAL_TIME, 0x1);
  619. hisi_sas_write32(hisi_hba, ENT_INT_COAL_CNT, 0x1);
  620. hisi_sas_write32(hisi_hba, OQ_INT_SRC, 0xffffffff);
  621. hisi_sas_write32(hisi_hba, OQ_INT_SRC_MSK, 0);
  622. hisi_sas_write32(hisi_hba, ENT_INT_SRC1, 0xffffffff);
  623. hisi_sas_write32(hisi_hba, ENT_INT_SRC_MSK1, 0);
  624. hisi_sas_write32(hisi_hba, ENT_INT_SRC2, 0xffffffff);
  625. hisi_sas_write32(hisi_hba, ENT_INT_SRC_MSK2, 0);
  626. hisi_sas_write32(hisi_hba, SAS_ECC_INTR_MSK, 0);
  627. hisi_sas_write32(hisi_hba, AXI_AHB_CLK_CFG, 0x2);
  628. hisi_sas_write32(hisi_hba, CFG_SAS_CONFIG, 0x22000000);
  629. for (i = 0; i < hisi_hba->n_phy; i++) {
  630. hisi_sas_phy_write32(hisi_hba, i, PROG_PHY_LINK_RATE, 0x88a);
  631. hisi_sas_phy_write32(hisi_hba, i, PHY_CONFIG2, 0x7c080);
  632. hisi_sas_phy_write32(hisi_hba, i, PHY_RATE_NEGO, 0x415ee00);
  633. hisi_sas_phy_write32(hisi_hba, i, PHY_PCN, 0x80a80000);
  634. hisi_sas_phy_write32(hisi_hba, i, SL_TOUT_CFG, 0x7d7d7d7d);
  635. hisi_sas_phy_write32(hisi_hba, i, DONE_RECEIVED_TIME, 0x0);
  636. hisi_sas_phy_write32(hisi_hba, i, RXOP_CHECK_CFG_H, 0x1000);
  637. hisi_sas_phy_write32(hisi_hba, i, DONE_RECEIVED_TIME, 0);
  638. hisi_sas_phy_write32(hisi_hba, i, CON_CFG_DRIVER, 0x13f0a);
  639. hisi_sas_phy_write32(hisi_hba, i, CHL_INT_COAL_EN, 3);
  640. hisi_sas_phy_write32(hisi_hba, i, DONE_RECEIVED_TIME, 8);
  641. }
  642. for (i = 0; i < hisi_hba->queue_count; i++) {
  643. /* Delivery queue */
  644. hisi_sas_write32(hisi_hba,
  645. DLVRY_Q_0_BASE_ADDR_HI + (i * 0x14),
  646. upper_32_bits(hisi_hba->cmd_hdr_dma[i]));
  647. hisi_sas_write32(hisi_hba,
  648. DLVRY_Q_0_BASE_ADDR_LO + (i * 0x14),
  649. lower_32_bits(hisi_hba->cmd_hdr_dma[i]));
  650. hisi_sas_write32(hisi_hba,
  651. DLVRY_Q_0_DEPTH + (i * 0x14),
  652. HISI_SAS_QUEUE_SLOTS);
  653. /* Completion queue */
  654. hisi_sas_write32(hisi_hba,
  655. COMPL_Q_0_BASE_ADDR_HI + (i * 0x14),
  656. upper_32_bits(hisi_hba->complete_hdr_dma[i]));
  657. hisi_sas_write32(hisi_hba,
  658. COMPL_Q_0_BASE_ADDR_LO + (i * 0x14),
  659. lower_32_bits(hisi_hba->complete_hdr_dma[i]));
  660. hisi_sas_write32(hisi_hba, COMPL_Q_0_DEPTH + (i * 0x14),
  661. HISI_SAS_QUEUE_SLOTS);
  662. }
  663. /* itct */
  664. hisi_sas_write32(hisi_hba, ITCT_BASE_ADDR_LO,
  665. lower_32_bits(hisi_hba->itct_dma));
  666. hisi_sas_write32(hisi_hba, ITCT_BASE_ADDR_HI,
  667. upper_32_bits(hisi_hba->itct_dma));
  668. /* iost */
  669. hisi_sas_write32(hisi_hba, IOST_BASE_ADDR_LO,
  670. lower_32_bits(hisi_hba->iost_dma));
  671. hisi_sas_write32(hisi_hba, IOST_BASE_ADDR_HI,
  672. upper_32_bits(hisi_hba->iost_dma));
  673. /* breakpoint */
  674. hisi_sas_write32(hisi_hba, BROKEN_MSG_ADDR_LO,
  675. lower_32_bits(hisi_hba->breakpoint_dma));
  676. hisi_sas_write32(hisi_hba, BROKEN_MSG_ADDR_HI,
  677. upper_32_bits(hisi_hba->breakpoint_dma));
  678. }
  679. static int hw_init_v1_hw(struct hisi_hba *hisi_hba)
  680. {
  681. struct device *dev = hisi_hba->dev;
  682. int rc;
  683. rc = reset_hw_v1_hw(hisi_hba);
  684. if (rc) {
  685. dev_err(dev, "hisi_sas_reset_hw failed, rc=%d", rc);
  686. return rc;
  687. }
  688. msleep(100);
  689. init_reg_v1_hw(hisi_hba);
  690. return 0;
  691. }
  692. static void enable_phy_v1_hw(struct hisi_hba *hisi_hba, int phy_no)
  693. {
  694. u32 cfg = hisi_sas_phy_read32(hisi_hba, phy_no, PHY_CFG);
  695. cfg |= PHY_CFG_ENA_MSK;
  696. hisi_sas_phy_write32(hisi_hba, phy_no, PHY_CFG, cfg);
  697. }
  698. static void disable_phy_v1_hw(struct hisi_hba *hisi_hba, int phy_no)
  699. {
  700. u32 cfg = hisi_sas_phy_read32(hisi_hba, phy_no, PHY_CFG);
  701. cfg &= ~PHY_CFG_ENA_MSK;
  702. hisi_sas_phy_write32(hisi_hba, phy_no, PHY_CFG, cfg);
  703. }
  704. static void start_phy_v1_hw(struct hisi_hba *hisi_hba, int phy_no)
  705. {
  706. config_id_frame_v1_hw(hisi_hba, phy_no);
  707. config_phy_opt_mode_v1_hw(hisi_hba, phy_no);
  708. config_tx_tfe_autoneg_v1_hw(hisi_hba, phy_no);
  709. enable_phy_v1_hw(hisi_hba, phy_no);
  710. }
  711. static void stop_phy_v1_hw(struct hisi_hba *hisi_hba, int phy_no)
  712. {
  713. disable_phy_v1_hw(hisi_hba, phy_no);
  714. }
  715. static void phy_hard_reset_v1_hw(struct hisi_hba *hisi_hba, int phy_no)
  716. {
  717. stop_phy_v1_hw(hisi_hba, phy_no);
  718. msleep(100);
  719. start_phy_v1_hw(hisi_hba, phy_no);
  720. }
  721. static void start_phys_v1_hw(struct timer_list *t)
  722. {
  723. struct hisi_hba *hisi_hba = from_timer(hisi_hba, t, timer);
  724. int i;
  725. for (i = 0; i < hisi_hba->n_phy; i++) {
  726. hisi_sas_phy_write32(hisi_hba, i, CHL_INT2_MSK, 0x12a);
  727. start_phy_v1_hw(hisi_hba, i);
  728. }
  729. }
  730. static void phys_init_v1_hw(struct hisi_hba *hisi_hba)
  731. {
  732. int i;
  733. struct timer_list *timer = &hisi_hba->timer;
  734. for (i = 0; i < hisi_hba->n_phy; i++) {
  735. hisi_sas_phy_write32(hisi_hba, i, CHL_INT2_MSK, 0x6a);
  736. hisi_sas_phy_read32(hisi_hba, i, CHL_INT2_MSK);
  737. }
  738. timer_setup(timer, start_phys_v1_hw, 0);
  739. mod_timer(timer, jiffies + HZ);
  740. }
  741. static void sl_notify_ssp_v1_hw(struct hisi_hba *hisi_hba, int phy_no)
  742. {
  743. u32 sl_control;
  744. sl_control = hisi_sas_phy_read32(hisi_hba, phy_no, SL_CONTROL);
  745. sl_control |= SL_CONTROL_NOTIFY_EN_MSK;
  746. hisi_sas_phy_write32(hisi_hba, phy_no, SL_CONTROL, sl_control);
  747. msleep(1);
  748. sl_control = hisi_sas_phy_read32(hisi_hba, phy_no, SL_CONTROL);
  749. sl_control &= ~SL_CONTROL_NOTIFY_EN_MSK;
  750. hisi_sas_phy_write32(hisi_hba, phy_no, SL_CONTROL, sl_control);
  751. }
  752. static enum sas_linkrate phy_get_max_linkrate_v1_hw(void)
  753. {
  754. return SAS_LINK_RATE_6_0_GBPS;
  755. }
  756. static void phy_set_linkrate_v1_hw(struct hisi_hba *hisi_hba, int phy_no,
  757. struct sas_phy_linkrates *r)
  758. {
  759. enum sas_linkrate max = r->maximum_linkrate;
  760. u32 prog_phy_link_rate = 0x800;
  761. prog_phy_link_rate |= hisi_sas_get_prog_phy_linkrate_mask(max);
  762. hisi_sas_phy_write32(hisi_hba, phy_no, PROG_PHY_LINK_RATE,
  763. prog_phy_link_rate);
  764. }
  765. static int get_wideport_bitmap_v1_hw(struct hisi_hba *hisi_hba, int port_id)
  766. {
  767. int i, bitmap = 0;
  768. u32 phy_port_num_ma = hisi_sas_read32(hisi_hba, PHY_PORT_NUM_MA);
  769. for (i = 0; i < hisi_hba->n_phy; i++)
  770. if (((phy_port_num_ma >> (i * 4)) & 0xf) == port_id)
  771. bitmap |= 1 << i;
  772. return bitmap;
  773. }
  774. /*
  775. * The callpath to this function and upto writing the write
  776. * queue pointer should be safe from interruption.
  777. */
  778. static int
  779. get_free_slot_v1_hw(struct hisi_hba *hisi_hba, struct hisi_sas_dq *dq)
  780. {
  781. struct device *dev = hisi_hba->dev;
  782. int queue = dq->id;
  783. u32 r, w;
  784. w = dq->wr_point;
  785. r = hisi_sas_read32_relaxed(hisi_hba,
  786. DLVRY_Q_0_RD_PTR + (queue * 0x14));
  787. if (r == (w+1) % HISI_SAS_QUEUE_SLOTS) {
  788. dev_warn(dev, "could not find free slot\n");
  789. return -EAGAIN;
  790. }
  791. dq->wr_point = (dq->wr_point + 1) % HISI_SAS_QUEUE_SLOTS;
  792. return w;
  793. }
  794. /* DQ lock must be taken here */
  795. static void start_delivery_v1_hw(struct hisi_sas_dq *dq)
  796. {
  797. struct hisi_hba *hisi_hba = dq->hisi_hba;
  798. struct hisi_sas_slot *s, *s1, *s2 = NULL;
  799. int dlvry_queue = dq->id;
  800. int wp;
  801. list_for_each_entry_safe(s, s1, &dq->list, delivery) {
  802. if (!s->ready)
  803. break;
  804. s2 = s;
  805. list_del(&s->delivery);
  806. }
  807. if (!s2)
  808. return;
  809. /*
  810. * Ensure that memories for slots built on other CPUs is observed.
  811. */
  812. smp_rmb();
  813. wp = (s2->dlvry_queue_slot + 1) % HISI_SAS_QUEUE_SLOTS;
  814. hisi_sas_write32(hisi_hba, DLVRY_Q_0_WR_PTR + (dlvry_queue * 0x14), wp);
  815. }
  816. static void prep_prd_sge_v1_hw(struct hisi_hba *hisi_hba,
  817. struct hisi_sas_slot *slot,
  818. struct hisi_sas_cmd_hdr *hdr,
  819. struct scatterlist *scatter,
  820. int n_elem)
  821. {
  822. struct hisi_sas_sge_page *sge_page = hisi_sas_sge_addr_mem(slot);
  823. struct scatterlist *sg;
  824. int i;
  825. for_each_sg(scatter, sg, n_elem, i) {
  826. struct hisi_sas_sge *entry = &sge_page->sge[i];
  827. entry->addr = cpu_to_le64(sg_dma_address(sg));
  828. entry->page_ctrl_0 = entry->page_ctrl_1 = 0;
  829. entry->data_len = cpu_to_le32(sg_dma_len(sg));
  830. entry->data_off = 0;
  831. }
  832. hdr->prd_table_addr = cpu_to_le64(hisi_sas_sge_addr_dma(slot));
  833. hdr->sg_len = cpu_to_le32(n_elem << CMD_HDR_DATA_SGL_LEN_OFF);
  834. }
  835. static void prep_smp_v1_hw(struct hisi_hba *hisi_hba,
  836. struct hisi_sas_slot *slot)
  837. {
  838. struct sas_task *task = slot->task;
  839. struct hisi_sas_cmd_hdr *hdr = slot->cmd_hdr;
  840. struct domain_device *device = task->dev;
  841. struct hisi_sas_port *port = slot->port;
  842. struct scatterlist *sg_req;
  843. struct hisi_sas_device *sas_dev = device->lldd_dev;
  844. dma_addr_t req_dma_addr;
  845. unsigned int req_len;
  846. /* req */
  847. sg_req = &task->smp_task.smp_req;
  848. req_len = sg_dma_len(sg_req);
  849. req_dma_addr = sg_dma_address(sg_req);
  850. /* create header */
  851. /* dw0 */
  852. hdr->dw0 = cpu_to_le32((port->id << CMD_HDR_PORT_OFF) |
  853. (1 << CMD_HDR_PRIORITY_OFF) | /* high pri */
  854. (1 << CMD_HDR_MODE_OFF) | /* ini mode */
  855. (2 << CMD_HDR_CMD_OFF)); /* smp */
  856. /* map itct entry */
  857. hdr->dw1 = cpu_to_le32(sas_dev->device_id << CMD_HDR_DEVICE_ID_OFF);
  858. /* dw2 */
  859. hdr->dw2 = cpu_to_le32((((req_len-4)/4) << CMD_HDR_CFL_OFF) |
  860. (HISI_SAS_MAX_SMP_RESP_SZ/4 <<
  861. CMD_HDR_MRFL_OFF));
  862. hdr->transfer_tags = cpu_to_le32(slot->idx << CMD_HDR_IPTT_OFF);
  863. hdr->cmd_table_addr = cpu_to_le64(req_dma_addr);
  864. hdr->sts_buffer_addr = cpu_to_le64(hisi_sas_status_buf_addr_dma(slot));
  865. }
  866. static void prep_ssp_v1_hw(struct hisi_hba *hisi_hba,
  867. struct hisi_sas_slot *slot)
  868. {
  869. struct sas_task *task = slot->task;
  870. struct hisi_sas_cmd_hdr *hdr = slot->cmd_hdr;
  871. struct domain_device *device = task->dev;
  872. struct hisi_sas_device *sas_dev = device->lldd_dev;
  873. struct hisi_sas_port *port = slot->port;
  874. struct sas_ssp_task *ssp_task = &task->ssp_task;
  875. struct scsi_cmnd *scsi_cmnd = ssp_task->cmd;
  876. struct hisi_sas_tmf_task *tmf = slot->tmf;
  877. int has_data = 0, priority = !!tmf;
  878. u8 *buf_cmd, fburst = 0;
  879. u32 dw1, dw2;
  880. /* create header */
  881. hdr->dw0 = cpu_to_le32((1 << CMD_HDR_RESP_REPORT_OFF) |
  882. (0x2 << CMD_HDR_TLR_CTRL_OFF) |
  883. (port->id << CMD_HDR_PORT_OFF) |
  884. (priority << CMD_HDR_PRIORITY_OFF) |
  885. (1 << CMD_HDR_MODE_OFF) | /* ini mode */
  886. (1 << CMD_HDR_CMD_OFF)); /* ssp */
  887. dw1 = 1 << CMD_HDR_VERIFY_DTL_OFF;
  888. if (tmf) {
  889. dw1 |= 3 << CMD_HDR_SSP_FRAME_TYPE_OFF;
  890. } else {
  891. switch (scsi_cmnd->sc_data_direction) {
  892. case DMA_TO_DEVICE:
  893. dw1 |= 2 << CMD_HDR_SSP_FRAME_TYPE_OFF;
  894. has_data = 1;
  895. break;
  896. case DMA_FROM_DEVICE:
  897. dw1 |= 1 << CMD_HDR_SSP_FRAME_TYPE_OFF;
  898. has_data = 1;
  899. break;
  900. default:
  901. dw1 |= 0 << CMD_HDR_SSP_FRAME_TYPE_OFF;
  902. }
  903. }
  904. /* map itct entry */
  905. dw1 |= sas_dev->device_id << CMD_HDR_DEVICE_ID_OFF;
  906. hdr->dw1 = cpu_to_le32(dw1);
  907. if (tmf) {
  908. dw2 = ((sizeof(struct ssp_tmf_iu) +
  909. sizeof(struct ssp_frame_hdr)+3)/4) <<
  910. CMD_HDR_CFL_OFF;
  911. } else {
  912. dw2 = ((sizeof(struct ssp_command_iu) +
  913. sizeof(struct ssp_frame_hdr)+3)/4) <<
  914. CMD_HDR_CFL_OFF;
  915. }
  916. dw2 |= (HISI_SAS_MAX_SSP_RESP_SZ/4) << CMD_HDR_MRFL_OFF;
  917. hdr->transfer_tags = cpu_to_le32(slot->idx << CMD_HDR_IPTT_OFF);
  918. if (has_data)
  919. prep_prd_sge_v1_hw(hisi_hba, slot, hdr, task->scatter,
  920. slot->n_elem);
  921. hdr->data_transfer_len = cpu_to_le32(task->total_xfer_len);
  922. hdr->cmd_table_addr = cpu_to_le64(hisi_sas_cmd_hdr_addr_dma(slot));
  923. hdr->sts_buffer_addr = cpu_to_le64(hisi_sas_status_buf_addr_dma(slot));
  924. buf_cmd = hisi_sas_cmd_hdr_addr_mem(slot) +
  925. sizeof(struct ssp_frame_hdr);
  926. if (task->ssp_task.enable_first_burst) {
  927. fburst = (1 << 7);
  928. dw2 |= 1 << CMD_HDR_FIRST_BURST_OFF;
  929. }
  930. hdr->dw2 = cpu_to_le32(dw2);
  931. memcpy(buf_cmd, &task->ssp_task.LUN, 8);
  932. if (!tmf) {
  933. buf_cmd[9] = fburst | task->ssp_task.task_attr |
  934. (task->ssp_task.task_prio << 3);
  935. memcpy(buf_cmd + 12, task->ssp_task.cmd->cmnd,
  936. task->ssp_task.cmd->cmd_len);
  937. } else {
  938. buf_cmd[10] = tmf->tmf;
  939. switch (tmf->tmf) {
  940. case TMF_ABORT_TASK:
  941. case TMF_QUERY_TASK:
  942. buf_cmd[12] =
  943. (tmf->tag_of_task_to_be_managed >> 8) & 0xff;
  944. buf_cmd[13] =
  945. tmf->tag_of_task_to_be_managed & 0xff;
  946. break;
  947. default:
  948. break;
  949. }
  950. }
  951. }
  952. /* by default, task resp is complete */
  953. static void slot_err_v1_hw(struct hisi_hba *hisi_hba,
  954. struct sas_task *task,
  955. struct hisi_sas_slot *slot)
  956. {
  957. struct task_status_struct *ts = &task->task_status;
  958. struct hisi_sas_err_record_v1 *err_record =
  959. hisi_sas_status_buf_addr_mem(slot);
  960. struct device *dev = hisi_hba->dev;
  961. switch (task->task_proto) {
  962. case SAS_PROTOCOL_SSP:
  963. {
  964. int error = -1;
  965. u32 dma_err_type = le32_to_cpu(err_record->dma_err_type);
  966. u32 dma_tx_err_type = ((dma_err_type &
  967. ERR_HDR_DMA_TX_ERR_TYPE_MSK)) >>
  968. ERR_HDR_DMA_TX_ERR_TYPE_OFF;
  969. u32 dma_rx_err_type = ((dma_err_type &
  970. ERR_HDR_DMA_RX_ERR_TYPE_MSK)) >>
  971. ERR_HDR_DMA_RX_ERR_TYPE_OFF;
  972. u32 trans_tx_fail_type =
  973. le32_to_cpu(err_record->trans_tx_fail_type);
  974. u32 trans_rx_fail_type =
  975. le32_to_cpu(err_record->trans_rx_fail_type);
  976. if (dma_tx_err_type) {
  977. /* dma tx err */
  978. error = ffs(dma_tx_err_type)
  979. - 1 + DMA_TX_ERR_BASE;
  980. } else if (dma_rx_err_type) {
  981. /* dma rx err */
  982. error = ffs(dma_rx_err_type)
  983. - 1 + DMA_RX_ERR_BASE;
  984. } else if (trans_tx_fail_type) {
  985. /* trans tx err */
  986. error = ffs(trans_tx_fail_type)
  987. - 1 + TRANS_TX_FAIL_BASE;
  988. } else if (trans_rx_fail_type) {
  989. /* trans rx err */
  990. error = ffs(trans_rx_fail_type)
  991. - 1 + TRANS_RX_FAIL_BASE;
  992. }
  993. switch (error) {
  994. case DMA_TX_DATA_UNDERFLOW_ERR:
  995. case DMA_RX_DATA_UNDERFLOW_ERR:
  996. {
  997. ts->residual = 0;
  998. ts->stat = SAS_DATA_UNDERRUN;
  999. break;
  1000. }
  1001. case DMA_TX_DATA_SGL_OVERFLOW_ERR:
  1002. case DMA_TX_DIF_SGL_OVERFLOW_ERR:
  1003. case DMA_TX_XFER_RDY_LENGTH_OVERFLOW_ERR:
  1004. case DMA_RX_DATA_OVERFLOW_ERR:
  1005. case TRANS_RX_FRAME_OVERRUN_ERR:
  1006. case TRANS_RX_LINK_BUF_OVERRUN_ERR:
  1007. {
  1008. ts->stat = SAS_DATA_OVERRUN;
  1009. ts->residual = 0;
  1010. break;
  1011. }
  1012. case TRANS_TX_PHY_NOT_ENABLE_ERR:
  1013. {
  1014. ts->stat = SAS_PHY_DOWN;
  1015. break;
  1016. }
  1017. case TRANS_TX_OPEN_REJCT_WRONG_DEST_ERR:
  1018. case TRANS_TX_OPEN_REJCT_ZONE_VIOLATION_ERR:
  1019. case TRANS_TX_OPEN_REJCT_BY_OTHER_ERR:
  1020. case TRANS_TX_OPEN_REJCT_AIP_TIMEOUT_ERR:
  1021. case TRANS_TX_OPEN_REJCT_STP_BUSY_ERR:
  1022. case TRANS_TX_OPEN_REJCT_PROTOCOL_NOT_SUPPORT_ERR:
  1023. case TRANS_TX_OPEN_REJCT_RATE_NOT_SUPPORT_ERR:
  1024. case TRANS_TX_OPEN_REJCT_BAD_DEST_ERR:
  1025. case TRANS_TX_OPEN_BREAK_RECEIVE_ERR:
  1026. case TRANS_TX_OPEN_REJCT_PATHWAY_BLOCKED_ERR:
  1027. case TRANS_TX_OPEN_REJCT_NO_DEST_ERR:
  1028. case TRANS_TX_OPEN_RETRY_ERR:
  1029. {
  1030. ts->stat = SAS_OPEN_REJECT;
  1031. ts->open_rej_reason = SAS_OREJ_UNKNOWN;
  1032. break;
  1033. }
  1034. case TRANS_TX_OPEN_TIMEOUT_ERR:
  1035. {
  1036. ts->stat = SAS_OPEN_TO;
  1037. break;
  1038. }
  1039. case TRANS_TX_NAK_RECEIVE_ERR:
  1040. case TRANS_TX_ACK_NAK_TIMEOUT_ERR:
  1041. {
  1042. ts->stat = SAS_NAK_R_ERR;
  1043. break;
  1044. }
  1045. case TRANS_TX_CREDIT_TIMEOUT_ERR:
  1046. case TRANS_TX_CLOSE_NORMAL_ERR:
  1047. {
  1048. /* This will request a retry */
  1049. ts->stat = SAS_QUEUE_FULL;
  1050. slot->abort = 1;
  1051. break;
  1052. }
  1053. default:
  1054. {
  1055. ts->stat = SAM_STAT_CHECK_CONDITION;
  1056. break;
  1057. }
  1058. }
  1059. }
  1060. break;
  1061. case SAS_PROTOCOL_SMP:
  1062. ts->stat = SAM_STAT_CHECK_CONDITION;
  1063. break;
  1064. case SAS_PROTOCOL_SATA:
  1065. case SAS_PROTOCOL_STP:
  1066. case SAS_PROTOCOL_SATA | SAS_PROTOCOL_STP:
  1067. {
  1068. dev_err(dev, "slot err: SATA/STP not supported");
  1069. }
  1070. break;
  1071. default:
  1072. break;
  1073. }
  1074. }
  1075. static int slot_complete_v1_hw(struct hisi_hba *hisi_hba,
  1076. struct hisi_sas_slot *slot)
  1077. {
  1078. struct sas_task *task = slot->task;
  1079. struct hisi_sas_device *sas_dev;
  1080. struct device *dev = hisi_hba->dev;
  1081. struct task_status_struct *ts;
  1082. struct domain_device *device;
  1083. enum exec_status sts;
  1084. struct hisi_sas_complete_v1_hdr *complete_queue =
  1085. hisi_hba->complete_hdr[slot->cmplt_queue];
  1086. struct hisi_sas_complete_v1_hdr *complete_hdr;
  1087. unsigned long flags;
  1088. u32 cmplt_hdr_data;
  1089. complete_hdr = &complete_queue[slot->cmplt_queue_slot];
  1090. cmplt_hdr_data = le32_to_cpu(complete_hdr->data);
  1091. if (unlikely(!task || !task->lldd_task || !task->dev))
  1092. return -EINVAL;
  1093. ts = &task->task_status;
  1094. device = task->dev;
  1095. sas_dev = device->lldd_dev;
  1096. spin_lock_irqsave(&task->task_state_lock, flags);
  1097. task->task_state_flags &=
  1098. ~(SAS_TASK_STATE_PENDING | SAS_TASK_AT_INITIATOR);
  1099. task->task_state_flags |= SAS_TASK_STATE_DONE;
  1100. spin_unlock_irqrestore(&task->task_state_lock, flags);
  1101. memset(ts, 0, sizeof(*ts));
  1102. ts->resp = SAS_TASK_COMPLETE;
  1103. if (unlikely(!sas_dev)) {
  1104. dev_dbg(dev, "slot complete: port has no device\n");
  1105. ts->stat = SAS_PHY_DOWN;
  1106. goto out;
  1107. }
  1108. if (cmplt_hdr_data & CMPLT_HDR_IO_CFG_ERR_MSK) {
  1109. u32 info_reg = hisi_sas_read32(hisi_hba, HGC_INVLD_DQE_INFO);
  1110. if (info_reg & HGC_INVLD_DQE_INFO_DQ_MSK)
  1111. dev_err(dev, "slot complete: [%d:%d] has dq IPTT err",
  1112. slot->cmplt_queue, slot->cmplt_queue_slot);
  1113. if (info_reg & HGC_INVLD_DQE_INFO_TYPE_MSK)
  1114. dev_err(dev, "slot complete: [%d:%d] has dq type err",
  1115. slot->cmplt_queue, slot->cmplt_queue_slot);
  1116. if (info_reg & HGC_INVLD_DQE_INFO_FORCE_MSK)
  1117. dev_err(dev, "slot complete: [%d:%d] has dq force phy err",
  1118. slot->cmplt_queue, slot->cmplt_queue_slot);
  1119. if (info_reg & HGC_INVLD_DQE_INFO_PHY_MSK)
  1120. dev_err(dev, "slot complete: [%d:%d] has dq phy id err",
  1121. slot->cmplt_queue, slot->cmplt_queue_slot);
  1122. if (info_reg & HGC_INVLD_DQE_INFO_ABORT_MSK)
  1123. dev_err(dev, "slot complete: [%d:%d] has dq abort flag err",
  1124. slot->cmplt_queue, slot->cmplt_queue_slot);
  1125. if (info_reg & HGC_INVLD_DQE_INFO_IPTT_OF_MSK)
  1126. dev_err(dev, "slot complete: [%d:%d] has dq IPTT or ICT err",
  1127. slot->cmplt_queue, slot->cmplt_queue_slot);
  1128. if (info_reg & HGC_INVLD_DQE_INFO_SSP_ERR_MSK)
  1129. dev_err(dev, "slot complete: [%d:%d] has dq SSP frame type err",
  1130. slot->cmplt_queue, slot->cmplt_queue_slot);
  1131. if (info_reg & HGC_INVLD_DQE_INFO_OFL_MSK)
  1132. dev_err(dev, "slot complete: [%d:%d] has dq order frame len err",
  1133. slot->cmplt_queue, slot->cmplt_queue_slot);
  1134. ts->stat = SAS_OPEN_REJECT;
  1135. ts->open_rej_reason = SAS_OREJ_UNKNOWN;
  1136. goto out;
  1137. }
  1138. if (cmplt_hdr_data & CMPLT_HDR_ERR_RCRD_XFRD_MSK &&
  1139. !(cmplt_hdr_data & CMPLT_HDR_RSPNS_XFRD_MSK)) {
  1140. slot_err_v1_hw(hisi_hba, task, slot);
  1141. if (unlikely(slot->abort))
  1142. return ts->stat;
  1143. goto out;
  1144. }
  1145. switch (task->task_proto) {
  1146. case SAS_PROTOCOL_SSP:
  1147. {
  1148. struct hisi_sas_status_buffer *status_buffer =
  1149. hisi_sas_status_buf_addr_mem(slot);
  1150. struct ssp_response_iu *iu = (struct ssp_response_iu *)
  1151. &status_buffer->iu[0];
  1152. sas_ssp_task_response(dev, task, iu);
  1153. break;
  1154. }
  1155. case SAS_PROTOCOL_SMP:
  1156. {
  1157. void *to;
  1158. struct scatterlist *sg_resp = &task->smp_task.smp_resp;
  1159. ts->stat = SAM_STAT_GOOD;
  1160. to = kmap_atomic(sg_page(sg_resp));
  1161. dma_unmap_sg(dev, &task->smp_task.smp_resp, 1,
  1162. DMA_FROM_DEVICE);
  1163. dma_unmap_sg(dev, &task->smp_task.smp_req, 1,
  1164. DMA_TO_DEVICE);
  1165. memcpy(to + sg_resp->offset,
  1166. hisi_sas_status_buf_addr_mem(slot) +
  1167. sizeof(struct hisi_sas_err_record),
  1168. sg_dma_len(sg_resp));
  1169. kunmap_atomic(to);
  1170. break;
  1171. }
  1172. case SAS_PROTOCOL_SATA:
  1173. case SAS_PROTOCOL_STP:
  1174. case SAS_PROTOCOL_SATA | SAS_PROTOCOL_STP:
  1175. dev_err(dev, "slot complete: SATA/STP not supported");
  1176. break;
  1177. default:
  1178. ts->stat = SAM_STAT_CHECK_CONDITION;
  1179. break;
  1180. }
  1181. if (!slot->port->port_attached) {
  1182. dev_err(dev, "slot complete: port %d has removed\n",
  1183. slot->port->sas_port.id);
  1184. ts->stat = SAS_PHY_DOWN;
  1185. }
  1186. out:
  1187. hisi_sas_slot_task_free(hisi_hba, task, slot);
  1188. sts = ts->stat;
  1189. if (task->task_done)
  1190. task->task_done(task);
  1191. return sts;
  1192. }
  1193. /* Interrupts */
  1194. static irqreturn_t int_phyup_v1_hw(int irq_no, void *p)
  1195. {
  1196. struct hisi_sas_phy *phy = p;
  1197. struct hisi_hba *hisi_hba = phy->hisi_hba;
  1198. struct device *dev = hisi_hba->dev;
  1199. struct asd_sas_phy *sas_phy = &phy->sas_phy;
  1200. int i, phy_no = sas_phy->id;
  1201. u32 irq_value, context, port_id, link_rate;
  1202. u32 *frame_rcvd = (u32 *)sas_phy->frame_rcvd;
  1203. struct sas_identify_frame *id = (struct sas_identify_frame *)frame_rcvd;
  1204. irqreturn_t res = IRQ_HANDLED;
  1205. unsigned long flags;
  1206. irq_value = hisi_sas_phy_read32(hisi_hba, phy_no, CHL_INT2);
  1207. if (!(irq_value & CHL_INT2_SL_PHY_ENA_MSK)) {
  1208. dev_dbg(dev, "phyup: irq_value = %x not set enable bit\n",
  1209. irq_value);
  1210. res = IRQ_NONE;
  1211. goto end;
  1212. }
  1213. context = hisi_sas_read32(hisi_hba, PHY_CONTEXT);
  1214. if (context & 1 << phy_no) {
  1215. dev_err(dev, "phyup: phy%d SATA attached equipment\n",
  1216. phy_no);
  1217. goto end;
  1218. }
  1219. port_id = (hisi_sas_read32(hisi_hba, PHY_PORT_NUM_MA) >> (4 * phy_no))
  1220. & 0xf;
  1221. if (port_id == 0xf) {
  1222. dev_err(dev, "phyup: phy%d invalid portid\n", phy_no);
  1223. res = IRQ_NONE;
  1224. goto end;
  1225. }
  1226. for (i = 0; i < 6; i++) {
  1227. u32 idaf = hisi_sas_phy_read32(hisi_hba, phy_no,
  1228. RX_IDAF_DWORD0 + (i * 4));
  1229. frame_rcvd[i] = __swab32(idaf);
  1230. }
  1231. /* Get the linkrate */
  1232. link_rate = hisi_sas_read32(hisi_hba, PHY_CONN_RATE);
  1233. link_rate = (link_rate >> (phy_no * 4)) & 0xf;
  1234. sas_phy->linkrate = link_rate;
  1235. sas_phy->oob_mode = SAS_OOB_MODE;
  1236. memcpy(sas_phy->attached_sas_addr,
  1237. &id->sas_addr, SAS_ADDR_SIZE);
  1238. dev_info(dev, "phyup: phy%d link_rate=%d\n",
  1239. phy_no, link_rate);
  1240. phy->port_id = port_id;
  1241. phy->phy_type &= ~(PORT_TYPE_SAS | PORT_TYPE_SATA);
  1242. phy->phy_type |= PORT_TYPE_SAS;
  1243. phy->phy_attached = 1;
  1244. phy->identify.device_type = id->dev_type;
  1245. phy->frame_rcvd_size = sizeof(struct sas_identify_frame);
  1246. if (phy->identify.device_type == SAS_END_DEVICE)
  1247. phy->identify.target_port_protocols =
  1248. SAS_PROTOCOL_SSP;
  1249. else if (phy->identify.device_type != SAS_PHY_UNUSED)
  1250. phy->identify.target_port_protocols =
  1251. SAS_PROTOCOL_SMP;
  1252. hisi_sas_notify_phy_event(phy, HISI_PHYE_PHY_UP);
  1253. spin_lock_irqsave(&phy->lock, flags);
  1254. if (phy->reset_completion) {
  1255. phy->in_reset = 0;
  1256. complete(phy->reset_completion);
  1257. }
  1258. spin_unlock_irqrestore(&phy->lock, flags);
  1259. end:
  1260. hisi_sas_phy_write32(hisi_hba, phy_no, CHL_INT2,
  1261. CHL_INT2_SL_PHY_ENA_MSK);
  1262. if (irq_value & CHL_INT2_SL_PHY_ENA_MSK) {
  1263. u32 chl_int0 = hisi_sas_phy_read32(hisi_hba, phy_no, CHL_INT0);
  1264. chl_int0 &= ~CHL_INT0_PHYCTRL_NOTRDY_MSK;
  1265. hisi_sas_phy_write32(hisi_hba, phy_no, CHL_INT0, chl_int0);
  1266. hisi_sas_phy_write32(hisi_hba, phy_no, CHL_INT0_MSK, 0x3ce3ee);
  1267. }
  1268. return res;
  1269. }
  1270. static irqreturn_t int_bcast_v1_hw(int irq, void *p)
  1271. {
  1272. struct hisi_sas_phy *phy = p;
  1273. struct hisi_hba *hisi_hba = phy->hisi_hba;
  1274. struct asd_sas_phy *sas_phy = &phy->sas_phy;
  1275. struct sas_ha_struct *sha = &hisi_hba->sha;
  1276. struct device *dev = hisi_hba->dev;
  1277. int phy_no = sas_phy->id;
  1278. u32 irq_value;
  1279. irqreturn_t res = IRQ_HANDLED;
  1280. irq_value = hisi_sas_phy_read32(hisi_hba, phy_no, CHL_INT2);
  1281. if (!(irq_value & CHL_INT2_SL_RX_BC_ACK_MSK)) {
  1282. dev_err(dev, "bcast: irq_value = %x not set enable bit",
  1283. irq_value);
  1284. res = IRQ_NONE;
  1285. goto end;
  1286. }
  1287. if (!test_bit(HISI_SAS_RESET_BIT, &hisi_hba->flags))
  1288. sha->notify_port_event(sas_phy, PORTE_BROADCAST_RCVD);
  1289. end:
  1290. hisi_sas_phy_write32(hisi_hba, phy_no, CHL_INT2,
  1291. CHL_INT2_SL_RX_BC_ACK_MSK);
  1292. return res;
  1293. }
  1294. static irqreturn_t int_abnormal_v1_hw(int irq, void *p)
  1295. {
  1296. struct hisi_sas_phy *phy = p;
  1297. struct hisi_hba *hisi_hba = phy->hisi_hba;
  1298. struct device *dev = hisi_hba->dev;
  1299. struct asd_sas_phy *sas_phy = &phy->sas_phy;
  1300. u32 irq_value, irq_mask_old;
  1301. int phy_no = sas_phy->id;
  1302. /* mask_int0 */
  1303. irq_mask_old = hisi_sas_phy_read32(hisi_hba, phy_no, CHL_INT0_MSK);
  1304. hisi_sas_phy_write32(hisi_hba, phy_no, CHL_INT0_MSK, 0x3fffff);
  1305. /* read int0 */
  1306. irq_value = hisi_sas_phy_read32(hisi_hba, phy_no, CHL_INT0);
  1307. if (irq_value & CHL_INT0_PHYCTRL_NOTRDY_MSK) {
  1308. u32 phy_state = hisi_sas_read32(hisi_hba, PHY_STATE);
  1309. hisi_sas_phy_down(hisi_hba, phy_no,
  1310. (phy_state & 1 << phy_no) ? 1 : 0);
  1311. }
  1312. if (irq_value & CHL_INT0_ID_TIMEOUT_MSK)
  1313. dev_dbg(dev, "abnormal: ID_TIMEOUT phy%d identify timeout\n",
  1314. phy_no);
  1315. if (irq_value & CHL_INT0_DWS_LOST_MSK)
  1316. dev_dbg(dev, "abnormal: DWS_LOST phy%d dws lost\n", phy_no);
  1317. if (irq_value & CHL_INT0_SN_FAIL_NGR_MSK)
  1318. dev_dbg(dev, "abnormal: SN_FAIL_NGR phy%d sn fail ngr\n",
  1319. phy_no);
  1320. if (irq_value & CHL_INT0_SL_IDAF_FAIL_MSK ||
  1321. irq_value & CHL_INT0_SL_OPAF_FAIL_MSK)
  1322. dev_dbg(dev, "abnormal: SL_ID/OPAF_FAIL phy%d check adr frm err\n",
  1323. phy_no);
  1324. if (irq_value & CHL_INT0_SL_PS_FAIL_OFF)
  1325. dev_dbg(dev, "abnormal: SL_PS_FAIL phy%d fail\n", phy_no);
  1326. /* write to zero */
  1327. hisi_sas_phy_write32(hisi_hba, phy_no, CHL_INT0, irq_value);
  1328. if (irq_value & CHL_INT0_PHYCTRL_NOTRDY_MSK)
  1329. hisi_sas_phy_write32(hisi_hba, phy_no, CHL_INT0_MSK,
  1330. 0x3fffff & ~CHL_INT0_MSK_PHYCTRL_NOTRDY_MSK);
  1331. else
  1332. hisi_sas_phy_write32(hisi_hba, phy_no, CHL_INT0_MSK,
  1333. irq_mask_old);
  1334. return IRQ_HANDLED;
  1335. }
  1336. static irqreturn_t cq_interrupt_v1_hw(int irq, void *p)
  1337. {
  1338. struct hisi_sas_cq *cq = p;
  1339. struct hisi_hba *hisi_hba = cq->hisi_hba;
  1340. struct hisi_sas_slot *slot;
  1341. int queue = cq->id;
  1342. struct hisi_sas_complete_v1_hdr *complete_queue =
  1343. (struct hisi_sas_complete_v1_hdr *)
  1344. hisi_hba->complete_hdr[queue];
  1345. u32 irq_value, rd_point = cq->rd_point, wr_point;
  1346. spin_lock(&hisi_hba->lock);
  1347. irq_value = hisi_sas_read32(hisi_hba, OQ_INT_SRC);
  1348. hisi_sas_write32(hisi_hba, OQ_INT_SRC, 1 << queue);
  1349. wr_point = hisi_sas_read32(hisi_hba,
  1350. COMPL_Q_0_WR_PTR + (0x14 * queue));
  1351. while (rd_point != wr_point) {
  1352. struct hisi_sas_complete_v1_hdr *complete_hdr;
  1353. int idx;
  1354. u32 cmplt_hdr_data;
  1355. complete_hdr = &complete_queue[rd_point];
  1356. cmplt_hdr_data = le32_to_cpu(complete_hdr->data);
  1357. idx = (cmplt_hdr_data & CMPLT_HDR_IPTT_MSK) >>
  1358. CMPLT_HDR_IPTT_OFF;
  1359. slot = &hisi_hba->slot_info[idx];
  1360. /* The completion queue and queue slot index are not
  1361. * necessarily the same as the delivery queue and
  1362. * queue slot index.
  1363. */
  1364. slot->cmplt_queue_slot = rd_point;
  1365. slot->cmplt_queue = queue;
  1366. slot_complete_v1_hw(hisi_hba, slot);
  1367. if (++rd_point >= HISI_SAS_QUEUE_SLOTS)
  1368. rd_point = 0;
  1369. }
  1370. /* update rd_point */
  1371. cq->rd_point = rd_point;
  1372. hisi_sas_write32(hisi_hba, COMPL_Q_0_RD_PTR + (0x14 * queue), rd_point);
  1373. spin_unlock(&hisi_hba->lock);
  1374. return IRQ_HANDLED;
  1375. }
  1376. static irqreturn_t fatal_ecc_int_v1_hw(int irq, void *p)
  1377. {
  1378. struct hisi_hba *hisi_hba = p;
  1379. struct device *dev = hisi_hba->dev;
  1380. u32 ecc_int = hisi_sas_read32(hisi_hba, SAS_ECC_INTR);
  1381. if (ecc_int & SAS_ECC_INTR_DQ_ECC1B_MSK) {
  1382. u32 ecc_err = hisi_sas_read32(hisi_hba, HGC_ECC_ERR);
  1383. panic("%s: Fatal DQ 1b ECC interrupt (0x%x)\n",
  1384. dev_name(dev), ecc_err);
  1385. }
  1386. if (ecc_int & SAS_ECC_INTR_DQ_ECCBAD_MSK) {
  1387. u32 addr = (hisi_sas_read32(hisi_hba, HGC_DQ_ECC_ADDR) &
  1388. HGC_DQ_ECC_ADDR_BAD_MSK) >>
  1389. HGC_DQ_ECC_ADDR_BAD_OFF;
  1390. panic("%s: Fatal DQ RAM ECC interrupt @ 0x%08x\n",
  1391. dev_name(dev), addr);
  1392. }
  1393. if (ecc_int & SAS_ECC_INTR_IOST_ECC1B_MSK) {
  1394. u32 ecc_err = hisi_sas_read32(hisi_hba, HGC_ECC_ERR);
  1395. panic("%s: Fatal IOST 1b ECC interrupt (0x%x)\n",
  1396. dev_name(dev), ecc_err);
  1397. }
  1398. if (ecc_int & SAS_ECC_INTR_IOST_ECCBAD_MSK) {
  1399. u32 addr = (hisi_sas_read32(hisi_hba, HGC_IOST_ECC_ADDR) &
  1400. HGC_IOST_ECC_ADDR_BAD_MSK) >>
  1401. HGC_IOST_ECC_ADDR_BAD_OFF;
  1402. panic("%s: Fatal IOST RAM ECC interrupt @ 0x%08x\n",
  1403. dev_name(dev), addr);
  1404. }
  1405. if (ecc_int & SAS_ECC_INTR_ITCT_ECCBAD_MSK) {
  1406. u32 addr = (hisi_sas_read32(hisi_hba, HGC_ITCT_ECC_ADDR) &
  1407. HGC_ITCT_ECC_ADDR_BAD_MSK) >>
  1408. HGC_ITCT_ECC_ADDR_BAD_OFF;
  1409. panic("%s: Fatal TCT RAM ECC interrupt @ 0x%08x\n",
  1410. dev_name(dev), addr);
  1411. }
  1412. if (ecc_int & SAS_ECC_INTR_ITCT_ECC1B_MSK) {
  1413. u32 ecc_err = hisi_sas_read32(hisi_hba, HGC_ECC_ERR);
  1414. panic("%s: Fatal ITCT 1b ECC interrupt (0x%x)\n",
  1415. dev_name(dev), ecc_err);
  1416. }
  1417. hisi_sas_write32(hisi_hba, SAS_ECC_INTR, ecc_int | 0x3f);
  1418. return IRQ_HANDLED;
  1419. }
  1420. static irqreturn_t fatal_axi_int_v1_hw(int irq, void *p)
  1421. {
  1422. struct hisi_hba *hisi_hba = p;
  1423. struct device *dev = hisi_hba->dev;
  1424. u32 axi_int = hisi_sas_read32(hisi_hba, ENT_INT_SRC2);
  1425. u32 axi_info = hisi_sas_read32(hisi_hba, HGC_AXI_FIFO_ERR_INFO);
  1426. if (axi_int & ENT_INT_SRC2_DQ_CFG_ERR_MSK)
  1427. panic("%s: Fatal DQ_CFG_ERR interrupt (0x%x)\n",
  1428. dev_name(dev), axi_info);
  1429. if (axi_int & ENT_INT_SRC2_CQ_CFG_ERR_MSK)
  1430. panic("%s: Fatal CQ_CFG_ERR interrupt (0x%x)\n",
  1431. dev_name(dev), axi_info);
  1432. if (axi_int & ENT_INT_SRC2_AXI_WRONG_INT_MSK)
  1433. panic("%s: Fatal AXI_WRONG_INT interrupt (0x%x)\n",
  1434. dev_name(dev), axi_info);
  1435. if (axi_int & ENT_INT_SRC2_AXI_OVERLF_INT_MSK)
  1436. panic("%s: Fatal AXI_OVERLF_INT incorrect interrupt (0x%x)\n",
  1437. dev_name(dev), axi_info);
  1438. hisi_sas_write32(hisi_hba, ENT_INT_SRC2, axi_int | 0x30000000);
  1439. return IRQ_HANDLED;
  1440. }
  1441. static irq_handler_t phy_interrupts[HISI_SAS_PHY_INT_NR] = {
  1442. int_bcast_v1_hw,
  1443. int_phyup_v1_hw,
  1444. int_abnormal_v1_hw
  1445. };
  1446. static irq_handler_t fatal_interrupts[HISI_SAS_MAX_QUEUES] = {
  1447. fatal_ecc_int_v1_hw,
  1448. fatal_axi_int_v1_hw
  1449. };
  1450. static int interrupt_init_v1_hw(struct hisi_hba *hisi_hba)
  1451. {
  1452. struct platform_device *pdev = hisi_hba->platform_dev;
  1453. struct device *dev = &pdev->dev;
  1454. int i, j, irq, rc, idx;
  1455. for (i = 0; i < hisi_hba->n_phy; i++) {
  1456. struct hisi_sas_phy *phy = &hisi_hba->phy[i];
  1457. idx = i * HISI_SAS_PHY_INT_NR;
  1458. for (j = 0; j < HISI_SAS_PHY_INT_NR; j++, idx++) {
  1459. irq = platform_get_irq(pdev, idx);
  1460. if (!irq) {
  1461. dev_err(dev,
  1462. "irq init: fail map phy interrupt %d\n",
  1463. idx);
  1464. return -ENOENT;
  1465. }
  1466. rc = devm_request_irq(dev, irq, phy_interrupts[j], 0,
  1467. DRV_NAME " phy", phy);
  1468. if (rc) {
  1469. dev_err(dev, "irq init: could not request "
  1470. "phy interrupt %d, rc=%d\n",
  1471. irq, rc);
  1472. return -ENOENT;
  1473. }
  1474. }
  1475. }
  1476. idx = hisi_hba->n_phy * HISI_SAS_PHY_INT_NR;
  1477. for (i = 0; i < hisi_hba->queue_count; i++, idx++) {
  1478. irq = platform_get_irq(pdev, idx);
  1479. if (!irq) {
  1480. dev_err(dev, "irq init: could not map cq interrupt %d\n",
  1481. idx);
  1482. return -ENOENT;
  1483. }
  1484. rc = devm_request_irq(dev, irq, cq_interrupt_v1_hw, 0,
  1485. DRV_NAME " cq", &hisi_hba->cq[i]);
  1486. if (rc) {
  1487. dev_err(dev, "irq init: could not request cq interrupt %d, rc=%d\n",
  1488. irq, rc);
  1489. return -ENOENT;
  1490. }
  1491. }
  1492. idx = (hisi_hba->n_phy * HISI_SAS_PHY_INT_NR) + hisi_hba->queue_count;
  1493. for (i = 0; i < HISI_SAS_FATAL_INT_NR; i++, idx++) {
  1494. irq = platform_get_irq(pdev, idx);
  1495. if (!irq) {
  1496. dev_err(dev, "irq init: could not map fatal interrupt %d\n",
  1497. idx);
  1498. return -ENOENT;
  1499. }
  1500. rc = devm_request_irq(dev, irq, fatal_interrupts[i], 0,
  1501. DRV_NAME " fatal", hisi_hba);
  1502. if (rc) {
  1503. dev_err(dev,
  1504. "irq init: could not request fatal interrupt %d, rc=%d\n",
  1505. irq, rc);
  1506. return -ENOENT;
  1507. }
  1508. }
  1509. return 0;
  1510. }
  1511. static int interrupt_openall_v1_hw(struct hisi_hba *hisi_hba)
  1512. {
  1513. int i;
  1514. u32 val;
  1515. for (i = 0; i < hisi_hba->n_phy; i++) {
  1516. /* Clear interrupt status */
  1517. val = hisi_sas_phy_read32(hisi_hba, i, CHL_INT0);
  1518. hisi_sas_phy_write32(hisi_hba, i, CHL_INT0, val);
  1519. val = hisi_sas_phy_read32(hisi_hba, i, CHL_INT1);
  1520. hisi_sas_phy_write32(hisi_hba, i, CHL_INT1, val);
  1521. val = hisi_sas_phy_read32(hisi_hba, i, CHL_INT2);
  1522. hisi_sas_phy_write32(hisi_hba, i, CHL_INT2, val);
  1523. /* Unmask interrupt */
  1524. hisi_sas_phy_write32(hisi_hba, i, CHL_INT0_MSK, 0x3ce3ee);
  1525. hisi_sas_phy_write32(hisi_hba, i, CHL_INT1_MSK, 0x17fff);
  1526. hisi_sas_phy_write32(hisi_hba, i, CHL_INT2_MSK, 0x8000012a);
  1527. /* bypass chip bug mask abnormal intr */
  1528. hisi_sas_phy_write32(hisi_hba, i, CHL_INT0_MSK,
  1529. 0x3fffff & ~CHL_INT0_MSK_PHYCTRL_NOTRDY_MSK);
  1530. }
  1531. return 0;
  1532. }
  1533. static int hisi_sas_v1_init(struct hisi_hba *hisi_hba)
  1534. {
  1535. int rc;
  1536. rc = hw_init_v1_hw(hisi_hba);
  1537. if (rc)
  1538. return rc;
  1539. rc = interrupt_init_v1_hw(hisi_hba);
  1540. if (rc)
  1541. return rc;
  1542. rc = interrupt_openall_v1_hw(hisi_hba);
  1543. if (rc)
  1544. return rc;
  1545. return 0;
  1546. }
  1547. static struct device_attribute *host_attrs_v1_hw[] = {
  1548. &dev_attr_phy_event_threshold,
  1549. NULL
  1550. };
  1551. static struct scsi_host_template sht_v1_hw = {
  1552. .name = DRV_NAME,
  1553. .module = THIS_MODULE,
  1554. .queuecommand = sas_queuecommand,
  1555. .target_alloc = sas_target_alloc,
  1556. .slave_configure = hisi_sas_slave_configure,
  1557. .scan_finished = hisi_sas_scan_finished,
  1558. .scan_start = hisi_sas_scan_start,
  1559. .change_queue_depth = sas_change_queue_depth,
  1560. .bios_param = sas_bios_param,
  1561. .this_id = -1,
  1562. .sg_tablesize = HISI_SAS_SGE_PAGE_CNT,
  1563. .max_sectors = SCSI_DEFAULT_MAX_SECTORS,
  1564. .use_clustering = ENABLE_CLUSTERING,
  1565. .eh_device_reset_handler = sas_eh_device_reset_handler,
  1566. .eh_target_reset_handler = sas_eh_target_reset_handler,
  1567. .target_destroy = sas_target_destroy,
  1568. .ioctl = sas_ioctl,
  1569. .shost_attrs = host_attrs_v1_hw,
  1570. };
  1571. static const struct hisi_sas_hw hisi_sas_v1_hw = {
  1572. .hw_init = hisi_sas_v1_init,
  1573. .setup_itct = setup_itct_v1_hw,
  1574. .sl_notify_ssp = sl_notify_ssp_v1_hw,
  1575. .clear_itct = clear_itct_v1_hw,
  1576. .prep_smp = prep_smp_v1_hw,
  1577. .prep_ssp = prep_ssp_v1_hw,
  1578. .get_free_slot = get_free_slot_v1_hw,
  1579. .start_delivery = start_delivery_v1_hw,
  1580. .slot_complete = slot_complete_v1_hw,
  1581. .phys_init = phys_init_v1_hw,
  1582. .phy_start = start_phy_v1_hw,
  1583. .phy_disable = disable_phy_v1_hw,
  1584. .phy_hard_reset = phy_hard_reset_v1_hw,
  1585. .phy_set_linkrate = phy_set_linkrate_v1_hw,
  1586. .phy_get_max_linkrate = phy_get_max_linkrate_v1_hw,
  1587. .get_wideport_bitmap = get_wideport_bitmap_v1_hw,
  1588. .max_command_entries = HISI_SAS_COMMAND_ENTRIES_V1_HW,
  1589. .complete_hdr_size = sizeof(struct hisi_sas_complete_v1_hdr),
  1590. .sht = &sht_v1_hw,
  1591. };
  1592. static int hisi_sas_v1_probe(struct platform_device *pdev)
  1593. {
  1594. return hisi_sas_probe(pdev, &hisi_sas_v1_hw);
  1595. }
  1596. static int hisi_sas_v1_remove(struct platform_device *pdev)
  1597. {
  1598. return hisi_sas_remove(pdev);
  1599. }
  1600. static const struct of_device_id sas_v1_of_match[] = {
  1601. { .compatible = "hisilicon,hip05-sas-v1",},
  1602. {},
  1603. };
  1604. MODULE_DEVICE_TABLE(of, sas_v1_of_match);
  1605. static const struct acpi_device_id sas_v1_acpi_match[] = {
  1606. { "HISI0161", 0 },
  1607. { }
  1608. };
  1609. MODULE_DEVICE_TABLE(acpi, sas_v1_acpi_match);
  1610. static struct platform_driver hisi_sas_v1_driver = {
  1611. .probe = hisi_sas_v1_probe,
  1612. .remove = hisi_sas_v1_remove,
  1613. .driver = {
  1614. .name = DRV_NAME,
  1615. .of_match_table = sas_v1_of_match,
  1616. .acpi_match_table = ACPI_PTR(sas_v1_acpi_match),
  1617. },
  1618. };
  1619. module_platform_driver(hisi_sas_v1_driver);
  1620. MODULE_LICENSE("GPL");
  1621. MODULE_AUTHOR("John Garry <john.garry@huawei.com>");
  1622. MODULE_DESCRIPTION("HISILICON SAS controller v1 hw driver");
  1623. MODULE_ALIAS("platform:" DRV_NAME);