hisi_sas_v1_hw.c 55 KB

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