hisi_sas_v3_hw.c 81 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773
  1. /*
  2. * Copyright (c) 2017 Hisilicon Limited.
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. */
  10. #include "hisi_sas.h"
  11. #define DRV_NAME "hisi_sas_v3_hw"
  12. /* global registers need init*/
  13. #define DLVRY_QUEUE_ENABLE 0x0
  14. #define IOST_BASE_ADDR_LO 0x8
  15. #define IOST_BASE_ADDR_HI 0xc
  16. #define ITCT_BASE_ADDR_LO 0x10
  17. #define ITCT_BASE_ADDR_HI 0x14
  18. #define IO_BROKEN_MSG_ADDR_LO 0x18
  19. #define IO_BROKEN_MSG_ADDR_HI 0x1c
  20. #define PHY_CONTEXT 0x20
  21. #define PHY_STATE 0x24
  22. #define PHY_PORT_NUM_MA 0x28
  23. #define PHY_CONN_RATE 0x30
  24. #define ITCT_CLR 0x44
  25. #define ITCT_CLR_EN_OFF 16
  26. #define ITCT_CLR_EN_MSK (0x1 << ITCT_CLR_EN_OFF)
  27. #define ITCT_DEV_OFF 0
  28. #define ITCT_DEV_MSK (0x7ff << ITCT_DEV_OFF)
  29. #define IO_SATA_BROKEN_MSG_ADDR_LO 0x58
  30. #define IO_SATA_BROKEN_MSG_ADDR_HI 0x5c
  31. #define SATA_INITI_D2H_STORE_ADDR_LO 0x60
  32. #define SATA_INITI_D2H_STORE_ADDR_HI 0x64
  33. #define CFG_MAX_TAG 0x68
  34. #define HGC_SAS_TX_OPEN_FAIL_RETRY_CTRL 0x84
  35. #define HGC_SAS_TXFAIL_RETRY_CTRL 0x88
  36. #define HGC_GET_ITV_TIME 0x90
  37. #define DEVICE_MSG_WORK_MODE 0x94
  38. #define OPENA_WT_CONTI_TIME 0x9c
  39. #define I_T_NEXUS_LOSS_TIME 0xa0
  40. #define MAX_CON_TIME_LIMIT_TIME 0xa4
  41. #define BUS_INACTIVE_LIMIT_TIME 0xa8
  42. #define REJECT_TO_OPEN_LIMIT_TIME 0xac
  43. #define CQ_INT_CONVERGE_EN 0xb0
  44. #define CFG_AGING_TIME 0xbc
  45. #define HGC_DFX_CFG2 0xc0
  46. #define CFG_ABT_SET_QUERY_IPTT 0xd4
  47. #define CFG_SET_ABORTED_IPTT_OFF 0
  48. #define CFG_SET_ABORTED_IPTT_MSK (0xfff << CFG_SET_ABORTED_IPTT_OFF)
  49. #define CFG_SET_ABORTED_EN_OFF 12
  50. #define CFG_ABT_SET_IPTT_DONE 0xd8
  51. #define CFG_ABT_SET_IPTT_DONE_OFF 0
  52. #define HGC_IOMB_PROC1_STATUS 0x104
  53. #define CHNL_INT_STATUS 0x148
  54. #define HGC_AXI_FIFO_ERR_INFO 0x154
  55. #define AXI_ERR_INFO_OFF 0
  56. #define AXI_ERR_INFO_MSK (0xff << AXI_ERR_INFO_OFF)
  57. #define FIFO_ERR_INFO_OFF 8
  58. #define FIFO_ERR_INFO_MSK (0xff << FIFO_ERR_INFO_OFF)
  59. #define INT_COAL_EN 0x19c
  60. #define OQ_INT_COAL_TIME 0x1a0
  61. #define OQ_INT_COAL_CNT 0x1a4
  62. #define ENT_INT_COAL_TIME 0x1a8
  63. #define ENT_INT_COAL_CNT 0x1ac
  64. #define OQ_INT_SRC 0x1b0
  65. #define OQ_INT_SRC_MSK 0x1b4
  66. #define ENT_INT_SRC1 0x1b8
  67. #define ENT_INT_SRC1_D2H_FIS_CH0_OFF 0
  68. #define ENT_INT_SRC1_D2H_FIS_CH0_MSK (0x1 << ENT_INT_SRC1_D2H_FIS_CH0_OFF)
  69. #define ENT_INT_SRC1_D2H_FIS_CH1_OFF 8
  70. #define ENT_INT_SRC1_D2H_FIS_CH1_MSK (0x1 << ENT_INT_SRC1_D2H_FIS_CH1_OFF)
  71. #define ENT_INT_SRC2 0x1bc
  72. #define ENT_INT_SRC3 0x1c0
  73. #define ENT_INT_SRC3_WP_DEPTH_OFF 8
  74. #define ENT_INT_SRC3_IPTT_SLOT_NOMATCH_OFF 9
  75. #define ENT_INT_SRC3_RP_DEPTH_OFF 10
  76. #define ENT_INT_SRC3_AXI_OFF 11
  77. #define ENT_INT_SRC3_FIFO_OFF 12
  78. #define ENT_INT_SRC3_LM_OFF 14
  79. #define ENT_INT_SRC3_ITC_INT_OFF 15
  80. #define ENT_INT_SRC3_ITC_INT_MSK (0x1 << ENT_INT_SRC3_ITC_INT_OFF)
  81. #define ENT_INT_SRC3_ABT_OFF 16
  82. #define ENT_INT_SRC_MSK1 0x1c4
  83. #define ENT_INT_SRC_MSK2 0x1c8
  84. #define ENT_INT_SRC_MSK3 0x1cc
  85. #define ENT_INT_SRC_MSK3_ENT95_MSK_OFF 31
  86. #define CHNL_PHYUPDOWN_INT_MSK 0x1d0
  87. #define CHNL_ENT_INT_MSK 0x1d4
  88. #define HGC_COM_INT_MSK 0x1d8
  89. #define ENT_INT_SRC_MSK3_ENT95_MSK_MSK (0x1 << ENT_INT_SRC_MSK3_ENT95_MSK_OFF)
  90. #define SAS_ECC_INTR 0x1e8
  91. #define SAS_ECC_INTR_MSK 0x1ec
  92. #define HGC_ERR_STAT_EN 0x238
  93. #define CQE_SEND_CNT 0x248
  94. #define DLVRY_Q_0_BASE_ADDR_LO 0x260
  95. #define DLVRY_Q_0_BASE_ADDR_HI 0x264
  96. #define DLVRY_Q_0_DEPTH 0x268
  97. #define DLVRY_Q_0_WR_PTR 0x26c
  98. #define DLVRY_Q_0_RD_PTR 0x270
  99. #define HYPER_STREAM_ID_EN_CFG 0xc80
  100. #define OQ0_INT_SRC_MSK 0xc90
  101. #define COMPL_Q_0_BASE_ADDR_LO 0x4e0
  102. #define COMPL_Q_0_BASE_ADDR_HI 0x4e4
  103. #define COMPL_Q_0_DEPTH 0x4e8
  104. #define COMPL_Q_0_WR_PTR 0x4ec
  105. #define COMPL_Q_0_RD_PTR 0x4f0
  106. #define AWQOS_AWCACHE_CFG 0xc84
  107. #define ARQOS_ARCACHE_CFG 0xc88
  108. #define HILINK_ERR_DFX 0xe04
  109. #define SAS_GPIO_CFG_0 0x1000
  110. #define SAS_GPIO_CFG_1 0x1004
  111. #define SAS_GPIO_TX_0_1 0x1040
  112. #define SAS_CFG_DRIVE_VLD 0x1070
  113. /* phy registers requiring init */
  114. #define PORT_BASE (0x2000)
  115. #define PHY_CFG (PORT_BASE + 0x0)
  116. #define HARD_PHY_LINKRATE (PORT_BASE + 0x4)
  117. #define PHY_CFG_ENA_OFF 0
  118. #define PHY_CFG_ENA_MSK (0x1 << PHY_CFG_ENA_OFF)
  119. #define PHY_CFG_DC_OPT_OFF 2
  120. #define PHY_CFG_DC_OPT_MSK (0x1 << PHY_CFG_DC_OPT_OFF)
  121. #define PHY_CFG_PHY_RST_OFF 3
  122. #define PHY_CFG_PHY_RST_MSK (0x1 << PHY_CFG_PHY_RST_OFF)
  123. #define PROG_PHY_LINK_RATE (PORT_BASE + 0x8)
  124. #define PHY_CTRL (PORT_BASE + 0x14)
  125. #define PHY_CTRL_RESET_OFF 0
  126. #define PHY_CTRL_RESET_MSK (0x1 << PHY_CTRL_RESET_OFF)
  127. #define SL_CFG (PORT_BASE + 0x84)
  128. #define AIP_LIMIT (PORT_BASE + 0x90)
  129. #define SL_CONTROL (PORT_BASE + 0x94)
  130. #define SL_CONTROL_NOTIFY_EN_OFF 0
  131. #define SL_CONTROL_NOTIFY_EN_MSK (0x1 << SL_CONTROL_NOTIFY_EN_OFF)
  132. #define SL_CTA_OFF 17
  133. #define SL_CTA_MSK (0x1 << SL_CTA_OFF)
  134. #define RX_PRIMS_STATUS (PORT_BASE + 0x98)
  135. #define RX_BCAST_CHG_OFF 1
  136. #define RX_BCAST_CHG_MSK (0x1 << RX_BCAST_CHG_OFF)
  137. #define TX_ID_DWORD0 (PORT_BASE + 0x9c)
  138. #define TX_ID_DWORD1 (PORT_BASE + 0xa0)
  139. #define TX_ID_DWORD2 (PORT_BASE + 0xa4)
  140. #define TX_ID_DWORD3 (PORT_BASE + 0xa8)
  141. #define TX_ID_DWORD4 (PORT_BASE + 0xaC)
  142. #define TX_ID_DWORD5 (PORT_BASE + 0xb0)
  143. #define TX_ID_DWORD6 (PORT_BASE + 0xb4)
  144. #define TXID_AUTO (PORT_BASE + 0xb8)
  145. #define CT3_OFF 1
  146. #define CT3_MSK (0x1 << CT3_OFF)
  147. #define TX_HARDRST_OFF 2
  148. #define TX_HARDRST_MSK (0x1 << TX_HARDRST_OFF)
  149. #define RX_IDAF_DWORD0 (PORT_BASE + 0xc4)
  150. #define RXOP_CHECK_CFG_H (PORT_BASE + 0xfc)
  151. #define STP_LINK_TIMER (PORT_BASE + 0x120)
  152. #define STP_LINK_TIMEOUT_STATE (PORT_BASE + 0x124)
  153. #define CON_CFG_DRIVER (PORT_BASE + 0x130)
  154. #define SAS_SSP_CON_TIMER_CFG (PORT_BASE + 0x134)
  155. #define SAS_SMP_CON_TIMER_CFG (PORT_BASE + 0x138)
  156. #define SAS_STP_CON_TIMER_CFG (PORT_BASE + 0x13c)
  157. #define CHL_INT0 (PORT_BASE + 0x1b4)
  158. #define CHL_INT0_HOTPLUG_TOUT_OFF 0
  159. #define CHL_INT0_HOTPLUG_TOUT_MSK (0x1 << CHL_INT0_HOTPLUG_TOUT_OFF)
  160. #define CHL_INT0_SL_RX_BCST_ACK_OFF 1
  161. #define CHL_INT0_SL_RX_BCST_ACK_MSK (0x1 << CHL_INT0_SL_RX_BCST_ACK_OFF)
  162. #define CHL_INT0_SL_PHY_ENABLE_OFF 2
  163. #define CHL_INT0_SL_PHY_ENABLE_MSK (0x1 << CHL_INT0_SL_PHY_ENABLE_OFF)
  164. #define CHL_INT0_NOT_RDY_OFF 4
  165. #define CHL_INT0_NOT_RDY_MSK (0x1 << CHL_INT0_NOT_RDY_OFF)
  166. #define CHL_INT0_PHY_RDY_OFF 5
  167. #define CHL_INT0_PHY_RDY_MSK (0x1 << CHL_INT0_PHY_RDY_OFF)
  168. #define CHL_INT1 (PORT_BASE + 0x1b8)
  169. #define CHL_INT1_DMAC_TX_ECC_ERR_OFF 15
  170. #define CHL_INT1_DMAC_TX_ECC_ERR_MSK (0x1 << CHL_INT1_DMAC_TX_ECC_ERR_OFF)
  171. #define CHL_INT1_DMAC_RX_ECC_ERR_OFF 17
  172. #define CHL_INT1_DMAC_RX_ECC_ERR_MSK (0x1 << CHL_INT1_DMAC_RX_ECC_ERR_OFF)
  173. #define CHL_INT1_DMAC_TX_AXI_WR_ERR_OFF 19
  174. #define CHL_INT1_DMAC_TX_AXI_RD_ERR_OFF 20
  175. #define CHL_INT1_DMAC_RX_AXI_WR_ERR_OFF 21
  176. #define CHL_INT1_DMAC_RX_AXI_RD_ERR_OFF 22
  177. #define CHL_INT2 (PORT_BASE + 0x1bc)
  178. #define CHL_INT2_SL_IDAF_TOUT_CONF_OFF 0
  179. #define CHL_INT2_RX_INVLD_DW_OFF 30
  180. #define CHL_INT2_STP_LINK_TIMEOUT_OFF 31
  181. #define CHL_INT0_MSK (PORT_BASE + 0x1c0)
  182. #define CHL_INT1_MSK (PORT_BASE + 0x1c4)
  183. #define CHL_INT2_MSK (PORT_BASE + 0x1c8)
  184. #define CHL_INT_COAL_EN (PORT_BASE + 0x1d0)
  185. #define SAS_RX_TRAIN_TIMER (PORT_BASE + 0x2a4)
  186. #define PHY_CTRL_RDY_MSK (PORT_BASE + 0x2b0)
  187. #define PHYCTRL_NOT_RDY_MSK (PORT_BASE + 0x2b4)
  188. #define PHYCTRL_DWS_RESET_MSK (PORT_BASE + 0x2b8)
  189. #define PHYCTRL_PHY_ENA_MSK (PORT_BASE + 0x2bc)
  190. #define SL_RX_BCAST_CHK_MSK (PORT_BASE + 0x2c0)
  191. #define PHYCTRL_OOB_RESTART_MSK (PORT_BASE + 0x2c4)
  192. #define DMA_TX_STATUS (PORT_BASE + 0x2d0)
  193. #define DMA_TX_STATUS_BUSY_OFF 0
  194. #define DMA_TX_STATUS_BUSY_MSK (0x1 << DMA_TX_STATUS_BUSY_OFF)
  195. #define DMA_RX_STATUS (PORT_BASE + 0x2e8)
  196. #define DMA_RX_STATUS_BUSY_OFF 0
  197. #define DMA_RX_STATUS_BUSY_MSK (0x1 << DMA_RX_STATUS_BUSY_OFF)
  198. #define COARSETUNE_TIME (PORT_BASE + 0x304)
  199. #define ERR_CNT_DWS_LOST (PORT_BASE + 0x380)
  200. #define ERR_CNT_RESET_PROB (PORT_BASE + 0x384)
  201. #define ERR_CNT_INVLD_DW (PORT_BASE + 0x390)
  202. #define ERR_CNT_DISP_ERR (PORT_BASE + 0x398)
  203. #define DEFAULT_ITCT_HW 2048 /* reset value, not reprogrammed */
  204. #if (HISI_SAS_MAX_DEVICES > DEFAULT_ITCT_HW)
  205. #error Max ITCT exceeded
  206. #endif
  207. #define AXI_MASTER_CFG_BASE (0x5000)
  208. #define AM_CTRL_GLOBAL (0x0)
  209. #define AM_CTRL_SHUTDOWN_REQ_OFF 0
  210. #define AM_CTRL_SHUTDOWN_REQ_MSK (0x1 << AM_CTRL_SHUTDOWN_REQ_OFF)
  211. #define AM_CURR_TRANS_RETURN (0x150)
  212. #define AM_CFG_MAX_TRANS (0x5010)
  213. #define AM_CFG_SINGLE_PORT_MAX_TRANS (0x5014)
  214. #define AXI_CFG (0x5100)
  215. #define AM_ROB_ECC_ERR_ADDR (0x510c)
  216. #define AM_ROB_ECC_ONEBIT_ERR_ADDR_OFF 0
  217. #define AM_ROB_ECC_ONEBIT_ERR_ADDR_MSK (0xff << AM_ROB_ECC_ONEBIT_ERR_ADDR_OFF)
  218. #define AM_ROB_ECC_MULBIT_ERR_ADDR_OFF 8
  219. #define AM_ROB_ECC_MULBIT_ERR_ADDR_MSK (0xff << AM_ROB_ECC_MULBIT_ERR_ADDR_OFF)
  220. /* RAS registers need init */
  221. #define RAS_BASE (0x6000)
  222. #define SAS_RAS_INTR0 (RAS_BASE)
  223. #define SAS_RAS_INTR1 (RAS_BASE + 0x04)
  224. #define SAS_RAS_INTR0_MASK (RAS_BASE + 0x08)
  225. #define SAS_RAS_INTR1_MASK (RAS_BASE + 0x0c)
  226. #define CFG_SAS_RAS_INTR_MASK (RAS_BASE + 0x1c)
  227. #define SAS_RAS_INTR2 (RAS_BASE + 0x20)
  228. #define SAS_RAS_INTR2_MASK (RAS_BASE + 0x24)
  229. /* HW dma structures */
  230. /* Delivery queue header */
  231. /* dw0 */
  232. #define CMD_HDR_ABORT_FLAG_OFF 0
  233. #define CMD_HDR_ABORT_FLAG_MSK (0x3 << CMD_HDR_ABORT_FLAG_OFF)
  234. #define CMD_HDR_ABORT_DEVICE_TYPE_OFF 2
  235. #define CMD_HDR_ABORT_DEVICE_TYPE_MSK (0x1 << CMD_HDR_ABORT_DEVICE_TYPE_OFF)
  236. #define CMD_HDR_RESP_REPORT_OFF 5
  237. #define CMD_HDR_RESP_REPORT_MSK (0x1 << CMD_HDR_RESP_REPORT_OFF)
  238. #define CMD_HDR_TLR_CTRL_OFF 6
  239. #define CMD_HDR_TLR_CTRL_MSK (0x3 << CMD_HDR_TLR_CTRL_OFF)
  240. #define CMD_HDR_PORT_OFF 18
  241. #define CMD_HDR_PORT_MSK (0xf << CMD_HDR_PORT_OFF)
  242. #define CMD_HDR_PRIORITY_OFF 27
  243. #define CMD_HDR_PRIORITY_MSK (0x1 << CMD_HDR_PRIORITY_OFF)
  244. #define CMD_HDR_CMD_OFF 29
  245. #define CMD_HDR_CMD_MSK (0x7 << CMD_HDR_CMD_OFF)
  246. /* dw1 */
  247. #define CMD_HDR_UNCON_CMD_OFF 3
  248. #define CMD_HDR_DIR_OFF 5
  249. #define CMD_HDR_DIR_MSK (0x3 << CMD_HDR_DIR_OFF)
  250. #define CMD_HDR_RESET_OFF 7
  251. #define CMD_HDR_RESET_MSK (0x1 << CMD_HDR_RESET_OFF)
  252. #define CMD_HDR_VDTL_OFF 10
  253. #define CMD_HDR_VDTL_MSK (0x1 << CMD_HDR_VDTL_OFF)
  254. #define CMD_HDR_FRAME_TYPE_OFF 11
  255. #define CMD_HDR_FRAME_TYPE_MSK (0x1f << CMD_HDR_FRAME_TYPE_OFF)
  256. #define CMD_HDR_DEV_ID_OFF 16
  257. #define CMD_HDR_DEV_ID_MSK (0xffff << CMD_HDR_DEV_ID_OFF)
  258. /* dw2 */
  259. #define CMD_HDR_CFL_OFF 0
  260. #define CMD_HDR_CFL_MSK (0x1ff << CMD_HDR_CFL_OFF)
  261. #define CMD_HDR_NCQ_TAG_OFF 10
  262. #define CMD_HDR_NCQ_TAG_MSK (0x1f << CMD_HDR_NCQ_TAG_OFF)
  263. #define CMD_HDR_MRFL_OFF 15
  264. #define CMD_HDR_MRFL_MSK (0x1ff << CMD_HDR_MRFL_OFF)
  265. #define CMD_HDR_SG_MOD_OFF 24
  266. #define CMD_HDR_SG_MOD_MSK (0x3 << CMD_HDR_SG_MOD_OFF)
  267. /* dw3 */
  268. #define CMD_HDR_IPTT_OFF 0
  269. #define CMD_HDR_IPTT_MSK (0xffff << CMD_HDR_IPTT_OFF)
  270. /* dw6 */
  271. #define CMD_HDR_DIF_SGL_LEN_OFF 0
  272. #define CMD_HDR_DIF_SGL_LEN_MSK (0xffff << CMD_HDR_DIF_SGL_LEN_OFF)
  273. #define CMD_HDR_DATA_SGL_LEN_OFF 16
  274. #define CMD_HDR_DATA_SGL_LEN_MSK (0xffff << CMD_HDR_DATA_SGL_LEN_OFF)
  275. /* dw7 */
  276. #define CMD_HDR_ADDR_MODE_SEL_OFF 15
  277. #define CMD_HDR_ADDR_MODE_SEL_MSK (1 << CMD_HDR_ADDR_MODE_SEL_OFF)
  278. #define CMD_HDR_ABORT_IPTT_OFF 16
  279. #define CMD_HDR_ABORT_IPTT_MSK (0xffff << CMD_HDR_ABORT_IPTT_OFF)
  280. /* Completion header */
  281. /* dw0 */
  282. #define CMPLT_HDR_CMPLT_OFF 0
  283. #define CMPLT_HDR_CMPLT_MSK (0x3 << CMPLT_HDR_CMPLT_OFF)
  284. #define CMPLT_HDR_ERROR_PHASE_OFF 2
  285. #define CMPLT_HDR_ERROR_PHASE_MSK (0xff << CMPLT_HDR_ERROR_PHASE_OFF)
  286. #define CMPLT_HDR_RSPNS_XFRD_OFF 10
  287. #define CMPLT_HDR_RSPNS_XFRD_MSK (0x1 << CMPLT_HDR_RSPNS_XFRD_OFF)
  288. #define CMPLT_HDR_ERX_OFF 12
  289. #define CMPLT_HDR_ERX_MSK (0x1 << CMPLT_HDR_ERX_OFF)
  290. #define CMPLT_HDR_ABORT_STAT_OFF 13
  291. #define CMPLT_HDR_ABORT_STAT_MSK (0x7 << CMPLT_HDR_ABORT_STAT_OFF)
  292. /* abort_stat */
  293. #define STAT_IO_NOT_VALID 0x1
  294. #define STAT_IO_NO_DEVICE 0x2
  295. #define STAT_IO_COMPLETE 0x3
  296. #define STAT_IO_ABORTED 0x4
  297. /* dw1 */
  298. #define CMPLT_HDR_IPTT_OFF 0
  299. #define CMPLT_HDR_IPTT_MSK (0xffff << CMPLT_HDR_IPTT_OFF)
  300. #define CMPLT_HDR_DEV_ID_OFF 16
  301. #define CMPLT_HDR_DEV_ID_MSK (0xffff << CMPLT_HDR_DEV_ID_OFF)
  302. /* dw3 */
  303. #define CMPLT_HDR_IO_IN_TARGET_OFF 17
  304. #define CMPLT_HDR_IO_IN_TARGET_MSK (0x1 << CMPLT_HDR_IO_IN_TARGET_OFF)
  305. /* ITCT header */
  306. /* qw0 */
  307. #define ITCT_HDR_DEV_TYPE_OFF 0
  308. #define ITCT_HDR_DEV_TYPE_MSK (0x3 << ITCT_HDR_DEV_TYPE_OFF)
  309. #define ITCT_HDR_VALID_OFF 2
  310. #define ITCT_HDR_VALID_MSK (0x1 << ITCT_HDR_VALID_OFF)
  311. #define ITCT_HDR_MCR_OFF 5
  312. #define ITCT_HDR_MCR_MSK (0xf << ITCT_HDR_MCR_OFF)
  313. #define ITCT_HDR_VLN_OFF 9
  314. #define ITCT_HDR_VLN_MSK (0xf << ITCT_HDR_VLN_OFF)
  315. #define ITCT_HDR_SMP_TIMEOUT_OFF 16
  316. #define ITCT_HDR_AWT_CONTINUE_OFF 25
  317. #define ITCT_HDR_PORT_ID_OFF 28
  318. #define ITCT_HDR_PORT_ID_MSK (0xf << ITCT_HDR_PORT_ID_OFF)
  319. /* qw2 */
  320. #define ITCT_HDR_INLT_OFF 0
  321. #define ITCT_HDR_INLT_MSK (0xffffULL << ITCT_HDR_INLT_OFF)
  322. #define ITCT_HDR_RTOLT_OFF 48
  323. #define ITCT_HDR_RTOLT_MSK (0xffffULL << ITCT_HDR_RTOLT_OFF)
  324. struct hisi_sas_complete_v3_hdr {
  325. __le32 dw0;
  326. __le32 dw1;
  327. __le32 act;
  328. __le32 dw3;
  329. };
  330. struct hisi_sas_err_record_v3 {
  331. /* dw0 */
  332. __le32 trans_tx_fail_type;
  333. /* dw1 */
  334. __le32 trans_rx_fail_type;
  335. /* dw2 */
  336. __le16 dma_tx_err_type;
  337. __le16 sipc_rx_err_type;
  338. /* dw3 */
  339. __le32 dma_rx_err_type;
  340. };
  341. #define RX_DATA_LEN_UNDERFLOW_OFF 6
  342. #define RX_DATA_LEN_UNDERFLOW_MSK (1 << RX_DATA_LEN_UNDERFLOW_OFF)
  343. #define HISI_SAS_COMMAND_ENTRIES_V3_HW 4096
  344. #define HISI_SAS_MSI_COUNT_V3_HW 32
  345. #define DIR_NO_DATA 0
  346. #define DIR_TO_INI 1
  347. #define DIR_TO_DEVICE 2
  348. #define DIR_RESERVED 3
  349. #define FIS_CMD_IS_UNCONSTRAINED(fis) \
  350. ((fis.command == ATA_CMD_READ_LOG_EXT) || \
  351. (fis.command == ATA_CMD_READ_LOG_DMA_EXT) || \
  352. ((fis.command == ATA_CMD_DEV_RESET) && \
  353. ((fis.control & ATA_SRST) != 0)))
  354. static bool hisi_sas_intr_conv;
  355. MODULE_PARM_DESC(intr_conv, "interrupt converge enable (0-1)");
  356. static u32 hisi_sas_read32(struct hisi_hba *hisi_hba, u32 off)
  357. {
  358. void __iomem *regs = hisi_hba->regs + off;
  359. return readl(regs);
  360. }
  361. static u32 hisi_sas_read32_relaxed(struct hisi_hba *hisi_hba, u32 off)
  362. {
  363. void __iomem *regs = hisi_hba->regs + off;
  364. return readl_relaxed(regs);
  365. }
  366. static void hisi_sas_write32(struct hisi_hba *hisi_hba, u32 off, u32 val)
  367. {
  368. void __iomem *regs = hisi_hba->regs + off;
  369. writel(val, regs);
  370. }
  371. static void hisi_sas_phy_write32(struct hisi_hba *hisi_hba, int phy_no,
  372. u32 off, u32 val)
  373. {
  374. void __iomem *regs = hisi_hba->regs + (0x400 * phy_no) + off;
  375. writel(val, regs);
  376. }
  377. static u32 hisi_sas_phy_read32(struct hisi_hba *hisi_hba,
  378. int phy_no, u32 off)
  379. {
  380. void __iomem *regs = hisi_hba->regs + (0x400 * phy_no) + off;
  381. return readl(regs);
  382. }
  383. #define hisi_sas_read32_poll_timeout(off, val, cond, delay_us, \
  384. timeout_us) \
  385. ({ \
  386. void __iomem *regs = hisi_hba->regs + off; \
  387. readl_poll_timeout(regs, val, cond, delay_us, timeout_us); \
  388. })
  389. #define hisi_sas_read32_poll_timeout_atomic(off, val, cond, delay_us, \
  390. timeout_us) \
  391. ({ \
  392. void __iomem *regs = hisi_hba->regs + off; \
  393. readl_poll_timeout_atomic(regs, val, cond, delay_us, timeout_us);\
  394. })
  395. static void init_reg_v3_hw(struct hisi_hba *hisi_hba)
  396. {
  397. struct pci_dev *pdev = hisi_hba->pci_dev;
  398. int i;
  399. /* Global registers init */
  400. hisi_sas_write32(hisi_hba, DLVRY_QUEUE_ENABLE,
  401. (u32)((1ULL << hisi_hba->queue_count) - 1));
  402. hisi_sas_write32(hisi_hba, CFG_MAX_TAG, 0xfff0400);
  403. hisi_sas_write32(hisi_hba, HGC_SAS_TXFAIL_RETRY_CTRL, 0x108);
  404. hisi_sas_write32(hisi_hba, CFG_AGING_TIME, 0x1);
  405. hisi_sas_write32(hisi_hba, INT_COAL_EN, 0x1);
  406. hisi_sas_write32(hisi_hba, OQ_INT_COAL_TIME, 0x1);
  407. hisi_sas_write32(hisi_hba, OQ_INT_COAL_CNT, 0x1);
  408. hisi_sas_write32(hisi_hba, CQ_INT_CONVERGE_EN,
  409. hisi_sas_intr_conv);
  410. hisi_sas_write32(hisi_hba, OQ_INT_SRC, 0xffff);
  411. hisi_sas_write32(hisi_hba, ENT_INT_SRC1, 0xffffffff);
  412. hisi_sas_write32(hisi_hba, ENT_INT_SRC2, 0xffffffff);
  413. hisi_sas_write32(hisi_hba, ENT_INT_SRC3, 0xffffffff);
  414. hisi_sas_write32(hisi_hba, ENT_INT_SRC_MSK1, 0xfefefefe);
  415. hisi_sas_write32(hisi_hba, ENT_INT_SRC_MSK2, 0xfefefefe);
  416. if (pdev->revision >= 0x21)
  417. hisi_sas_write32(hisi_hba, ENT_INT_SRC_MSK3, 0xffff7aff);
  418. else
  419. hisi_sas_write32(hisi_hba, ENT_INT_SRC_MSK3, 0xfffe20ff);
  420. hisi_sas_write32(hisi_hba, CHNL_PHYUPDOWN_INT_MSK, 0x0);
  421. hisi_sas_write32(hisi_hba, CHNL_ENT_INT_MSK, 0x0);
  422. hisi_sas_write32(hisi_hba, HGC_COM_INT_MSK, 0x0);
  423. hisi_sas_write32(hisi_hba, SAS_ECC_INTR_MSK, 0x0);
  424. hisi_sas_write32(hisi_hba, AWQOS_AWCACHE_CFG, 0xf0f0);
  425. hisi_sas_write32(hisi_hba, ARQOS_ARCACHE_CFG, 0xf0f0);
  426. for (i = 0; i < hisi_hba->queue_count; i++)
  427. hisi_sas_write32(hisi_hba, OQ0_INT_SRC_MSK+0x4*i, 0);
  428. hisi_sas_write32(hisi_hba, HYPER_STREAM_ID_EN_CFG, 1);
  429. for (i = 0; i < hisi_hba->n_phy; i++) {
  430. struct hisi_sas_phy *phy = &hisi_hba->phy[i];
  431. struct asd_sas_phy *sas_phy = &phy->sas_phy;
  432. u32 prog_phy_link_rate = 0x800;
  433. if (!sas_phy->phy || (sas_phy->phy->maximum_linkrate <
  434. SAS_LINK_RATE_1_5_GBPS)) {
  435. prog_phy_link_rate = 0x855;
  436. } else {
  437. enum sas_linkrate max = sas_phy->phy->maximum_linkrate;
  438. prog_phy_link_rate =
  439. hisi_sas_get_prog_phy_linkrate_mask(max) |
  440. 0x800;
  441. }
  442. hisi_sas_phy_write32(hisi_hba, i, PROG_PHY_LINK_RATE,
  443. prog_phy_link_rate);
  444. hisi_sas_phy_write32(hisi_hba, i, SAS_RX_TRAIN_TIMER, 0x13e80);
  445. hisi_sas_phy_write32(hisi_hba, i, CHL_INT0, 0xffffffff);
  446. hisi_sas_phy_write32(hisi_hba, i, CHL_INT1, 0xffffffff);
  447. hisi_sas_phy_write32(hisi_hba, i, CHL_INT2, 0xffffffff);
  448. hisi_sas_phy_write32(hisi_hba, i, RXOP_CHECK_CFG_H, 0x1000);
  449. if (pdev->revision >= 0x21)
  450. hisi_sas_phy_write32(hisi_hba, i, CHL_INT1_MSK,
  451. 0xffffffff);
  452. else
  453. hisi_sas_phy_write32(hisi_hba, i, CHL_INT1_MSK,
  454. 0xff87ffff);
  455. hisi_sas_phy_write32(hisi_hba, i, CHL_INT2_MSK, 0xffffbfe);
  456. hisi_sas_phy_write32(hisi_hba, i, PHY_CTRL_RDY_MSK, 0x0);
  457. hisi_sas_phy_write32(hisi_hba, i, PHYCTRL_NOT_RDY_MSK, 0x0);
  458. hisi_sas_phy_write32(hisi_hba, i, PHYCTRL_DWS_RESET_MSK, 0x0);
  459. hisi_sas_phy_write32(hisi_hba, i, PHYCTRL_PHY_ENA_MSK, 0x0);
  460. hisi_sas_phy_write32(hisi_hba, i, SL_RX_BCAST_CHK_MSK, 0x0);
  461. hisi_sas_phy_write32(hisi_hba, i, PHYCTRL_OOB_RESTART_MSK, 0x1);
  462. hisi_sas_phy_write32(hisi_hba, i, STP_LINK_TIMER, 0x7f7a120);
  463. hisi_sas_phy_write32(hisi_hba, i, CON_CFG_DRIVER, 0x2a0a01);
  464. hisi_sas_phy_write32(hisi_hba, i, SAS_SSP_CON_TIMER_CFG, 0x32);
  465. /* used for 12G negotiate */
  466. hisi_sas_phy_write32(hisi_hba, i, COARSETUNE_TIME, 0x1e);
  467. hisi_sas_phy_write32(hisi_hba, i, AIP_LIMIT, 0x2ffff);
  468. }
  469. for (i = 0; i < hisi_hba->queue_count; i++) {
  470. /* Delivery queue */
  471. hisi_sas_write32(hisi_hba,
  472. DLVRY_Q_0_BASE_ADDR_HI + (i * 0x14),
  473. upper_32_bits(hisi_hba->cmd_hdr_dma[i]));
  474. hisi_sas_write32(hisi_hba, DLVRY_Q_0_BASE_ADDR_LO + (i * 0x14),
  475. lower_32_bits(hisi_hba->cmd_hdr_dma[i]));
  476. hisi_sas_write32(hisi_hba, DLVRY_Q_0_DEPTH + (i * 0x14),
  477. HISI_SAS_QUEUE_SLOTS);
  478. /* Completion queue */
  479. hisi_sas_write32(hisi_hba, COMPL_Q_0_BASE_ADDR_HI + (i * 0x14),
  480. upper_32_bits(hisi_hba->complete_hdr_dma[i]));
  481. hisi_sas_write32(hisi_hba, COMPL_Q_0_BASE_ADDR_LO + (i * 0x14),
  482. lower_32_bits(hisi_hba->complete_hdr_dma[i]));
  483. hisi_sas_write32(hisi_hba, COMPL_Q_0_DEPTH + (i * 0x14),
  484. HISI_SAS_QUEUE_SLOTS);
  485. }
  486. /* itct */
  487. hisi_sas_write32(hisi_hba, ITCT_BASE_ADDR_LO,
  488. lower_32_bits(hisi_hba->itct_dma));
  489. hisi_sas_write32(hisi_hba, ITCT_BASE_ADDR_HI,
  490. upper_32_bits(hisi_hba->itct_dma));
  491. /* iost */
  492. hisi_sas_write32(hisi_hba, IOST_BASE_ADDR_LO,
  493. lower_32_bits(hisi_hba->iost_dma));
  494. hisi_sas_write32(hisi_hba, IOST_BASE_ADDR_HI,
  495. upper_32_bits(hisi_hba->iost_dma));
  496. /* breakpoint */
  497. hisi_sas_write32(hisi_hba, IO_BROKEN_MSG_ADDR_LO,
  498. lower_32_bits(hisi_hba->breakpoint_dma));
  499. hisi_sas_write32(hisi_hba, IO_BROKEN_MSG_ADDR_HI,
  500. upper_32_bits(hisi_hba->breakpoint_dma));
  501. /* SATA broken msg */
  502. hisi_sas_write32(hisi_hba, IO_SATA_BROKEN_MSG_ADDR_LO,
  503. lower_32_bits(hisi_hba->sata_breakpoint_dma));
  504. hisi_sas_write32(hisi_hba, IO_SATA_BROKEN_MSG_ADDR_HI,
  505. upper_32_bits(hisi_hba->sata_breakpoint_dma));
  506. /* SATA initial fis */
  507. hisi_sas_write32(hisi_hba, SATA_INITI_D2H_STORE_ADDR_LO,
  508. lower_32_bits(hisi_hba->initial_fis_dma));
  509. hisi_sas_write32(hisi_hba, SATA_INITI_D2H_STORE_ADDR_HI,
  510. upper_32_bits(hisi_hba->initial_fis_dma));
  511. /* RAS registers init */
  512. hisi_sas_write32(hisi_hba, SAS_RAS_INTR0_MASK, 0x0);
  513. hisi_sas_write32(hisi_hba, SAS_RAS_INTR1_MASK, 0x0);
  514. hisi_sas_write32(hisi_hba, SAS_RAS_INTR2_MASK, 0x0);
  515. hisi_sas_write32(hisi_hba, CFG_SAS_RAS_INTR_MASK, 0x0);
  516. /* LED registers init */
  517. hisi_sas_write32(hisi_hba, SAS_CFG_DRIVE_VLD, 0x80000ff);
  518. hisi_sas_write32(hisi_hba, SAS_GPIO_TX_0_1, 0x80808080);
  519. hisi_sas_write32(hisi_hba, SAS_GPIO_TX_0_1 + 0x4, 0x80808080);
  520. /* Configure blink generator rate A to 1Hz and B to 4Hz */
  521. hisi_sas_write32(hisi_hba, SAS_GPIO_CFG_1, 0x121700);
  522. hisi_sas_write32(hisi_hba, SAS_GPIO_CFG_0, 0x800000);
  523. }
  524. static void config_phy_opt_mode_v3_hw(struct hisi_hba *hisi_hba, int phy_no)
  525. {
  526. u32 cfg = hisi_sas_phy_read32(hisi_hba, phy_no, PHY_CFG);
  527. cfg &= ~PHY_CFG_DC_OPT_MSK;
  528. cfg |= 1 << PHY_CFG_DC_OPT_OFF;
  529. hisi_sas_phy_write32(hisi_hba, phy_no, PHY_CFG, cfg);
  530. }
  531. static void config_id_frame_v3_hw(struct hisi_hba *hisi_hba, int phy_no)
  532. {
  533. struct sas_identify_frame identify_frame;
  534. u32 *identify_buffer;
  535. memset(&identify_frame, 0, sizeof(identify_frame));
  536. identify_frame.dev_type = SAS_END_DEVICE;
  537. identify_frame.frame_type = 0;
  538. identify_frame._un1 = 1;
  539. identify_frame.initiator_bits = SAS_PROTOCOL_ALL;
  540. identify_frame.target_bits = SAS_PROTOCOL_NONE;
  541. memcpy(&identify_frame._un4_11[0], hisi_hba->sas_addr, SAS_ADDR_SIZE);
  542. memcpy(&identify_frame.sas_addr[0], hisi_hba->sas_addr, SAS_ADDR_SIZE);
  543. identify_frame.phy_id = phy_no;
  544. identify_buffer = (u32 *)(&identify_frame);
  545. hisi_sas_phy_write32(hisi_hba, phy_no, TX_ID_DWORD0,
  546. __swab32(identify_buffer[0]));
  547. hisi_sas_phy_write32(hisi_hba, phy_no, TX_ID_DWORD1,
  548. __swab32(identify_buffer[1]));
  549. hisi_sas_phy_write32(hisi_hba, phy_no, TX_ID_DWORD2,
  550. __swab32(identify_buffer[2]));
  551. hisi_sas_phy_write32(hisi_hba, phy_no, TX_ID_DWORD3,
  552. __swab32(identify_buffer[3]));
  553. hisi_sas_phy_write32(hisi_hba, phy_no, TX_ID_DWORD4,
  554. __swab32(identify_buffer[4]));
  555. hisi_sas_phy_write32(hisi_hba, phy_no, TX_ID_DWORD5,
  556. __swab32(identify_buffer[5]));
  557. }
  558. static void setup_itct_v3_hw(struct hisi_hba *hisi_hba,
  559. struct hisi_sas_device *sas_dev)
  560. {
  561. struct domain_device *device = sas_dev->sas_device;
  562. struct device *dev = hisi_hba->dev;
  563. u64 qw0, device_id = sas_dev->device_id;
  564. struct hisi_sas_itct *itct = &hisi_hba->itct[device_id];
  565. struct domain_device *parent_dev = device->parent;
  566. struct asd_sas_port *sas_port = device->port;
  567. struct hisi_sas_port *port = to_hisi_sas_port(sas_port);
  568. u64 sas_addr;
  569. memset(itct, 0, sizeof(*itct));
  570. /* qw0 */
  571. qw0 = 0;
  572. switch (sas_dev->dev_type) {
  573. case SAS_END_DEVICE:
  574. case SAS_EDGE_EXPANDER_DEVICE:
  575. case SAS_FANOUT_EXPANDER_DEVICE:
  576. qw0 = HISI_SAS_DEV_TYPE_SSP << ITCT_HDR_DEV_TYPE_OFF;
  577. break;
  578. case SAS_SATA_DEV:
  579. case SAS_SATA_PENDING:
  580. if (parent_dev && DEV_IS_EXPANDER(parent_dev->dev_type))
  581. qw0 = HISI_SAS_DEV_TYPE_STP << ITCT_HDR_DEV_TYPE_OFF;
  582. else
  583. qw0 = HISI_SAS_DEV_TYPE_SATA << ITCT_HDR_DEV_TYPE_OFF;
  584. break;
  585. default:
  586. dev_warn(dev, "setup itct: unsupported dev type (%d)\n",
  587. sas_dev->dev_type);
  588. }
  589. qw0 |= ((1 << ITCT_HDR_VALID_OFF) |
  590. (device->linkrate << ITCT_HDR_MCR_OFF) |
  591. (1 << ITCT_HDR_VLN_OFF) |
  592. (0xfa << ITCT_HDR_SMP_TIMEOUT_OFF) |
  593. (1 << ITCT_HDR_AWT_CONTINUE_OFF) |
  594. (port->id << ITCT_HDR_PORT_ID_OFF));
  595. itct->qw0 = cpu_to_le64(qw0);
  596. /* qw1 */
  597. memcpy(&sas_addr, device->sas_addr, SAS_ADDR_SIZE);
  598. itct->sas_addr = cpu_to_le64(__swab64(sas_addr));
  599. /* qw2 */
  600. if (!dev_is_sata(device))
  601. itct->qw2 = cpu_to_le64((5000ULL << ITCT_HDR_INLT_OFF) |
  602. (0x1ULL << ITCT_HDR_RTOLT_OFF));
  603. }
  604. static void clear_itct_v3_hw(struct hisi_hba *hisi_hba,
  605. struct hisi_sas_device *sas_dev)
  606. {
  607. DECLARE_COMPLETION_ONSTACK(completion);
  608. u64 dev_id = sas_dev->device_id;
  609. struct hisi_sas_itct *itct = &hisi_hba->itct[dev_id];
  610. u32 reg_val = hisi_sas_read32(hisi_hba, ENT_INT_SRC3);
  611. sas_dev->completion = &completion;
  612. /* clear the itct interrupt state */
  613. if (ENT_INT_SRC3_ITC_INT_MSK & reg_val)
  614. hisi_sas_write32(hisi_hba, ENT_INT_SRC3,
  615. ENT_INT_SRC3_ITC_INT_MSK);
  616. /* clear the itct table*/
  617. reg_val = ITCT_CLR_EN_MSK | (dev_id & ITCT_DEV_MSK);
  618. hisi_sas_write32(hisi_hba, ITCT_CLR, reg_val);
  619. wait_for_completion(sas_dev->completion);
  620. memset(itct, 0, sizeof(struct hisi_sas_itct));
  621. }
  622. static void dereg_device_v3_hw(struct hisi_hba *hisi_hba,
  623. struct domain_device *device)
  624. {
  625. struct hisi_sas_slot *slot, *slot2;
  626. struct hisi_sas_device *sas_dev = device->lldd_dev;
  627. u32 cfg_abt_set_query_iptt;
  628. cfg_abt_set_query_iptt = hisi_sas_read32(hisi_hba,
  629. CFG_ABT_SET_QUERY_IPTT);
  630. list_for_each_entry_safe(slot, slot2, &sas_dev->list, entry) {
  631. cfg_abt_set_query_iptt &= ~CFG_SET_ABORTED_IPTT_MSK;
  632. cfg_abt_set_query_iptt |= (1 << CFG_SET_ABORTED_EN_OFF) |
  633. (slot->idx << CFG_SET_ABORTED_IPTT_OFF);
  634. hisi_sas_write32(hisi_hba, CFG_ABT_SET_QUERY_IPTT,
  635. cfg_abt_set_query_iptt);
  636. }
  637. cfg_abt_set_query_iptt &= ~(1 << CFG_SET_ABORTED_EN_OFF);
  638. hisi_sas_write32(hisi_hba, CFG_ABT_SET_QUERY_IPTT,
  639. cfg_abt_set_query_iptt);
  640. hisi_sas_write32(hisi_hba, CFG_ABT_SET_IPTT_DONE,
  641. 1 << CFG_ABT_SET_IPTT_DONE_OFF);
  642. }
  643. static int reset_hw_v3_hw(struct hisi_hba *hisi_hba)
  644. {
  645. struct device *dev = hisi_hba->dev;
  646. int ret;
  647. u32 val;
  648. hisi_sas_write32(hisi_hba, DLVRY_QUEUE_ENABLE, 0);
  649. /* Disable all of the PHYs */
  650. hisi_sas_stop_phys(hisi_hba);
  651. udelay(50);
  652. /* Ensure axi bus idle */
  653. ret = hisi_sas_read32_poll_timeout(AXI_CFG, val, !val,
  654. 20000, 1000000);
  655. if (ret) {
  656. dev_err(dev, "axi bus is not idle, ret = %d!\n", ret);
  657. return -EIO;
  658. }
  659. if (ACPI_HANDLE(dev)) {
  660. acpi_status s;
  661. s = acpi_evaluate_object(ACPI_HANDLE(dev), "_RST", NULL, NULL);
  662. if (ACPI_FAILURE(s)) {
  663. dev_err(dev, "Reset failed\n");
  664. return -EIO;
  665. }
  666. } else {
  667. dev_err(dev, "no reset method!\n");
  668. return -EINVAL;
  669. }
  670. return 0;
  671. }
  672. static int hw_init_v3_hw(struct hisi_hba *hisi_hba)
  673. {
  674. struct device *dev = hisi_hba->dev;
  675. int rc;
  676. rc = reset_hw_v3_hw(hisi_hba);
  677. if (rc) {
  678. dev_err(dev, "hisi_sas_reset_hw failed, rc=%d", rc);
  679. return rc;
  680. }
  681. msleep(100);
  682. init_reg_v3_hw(hisi_hba);
  683. return 0;
  684. }
  685. static void enable_phy_v3_hw(struct hisi_hba *hisi_hba, int phy_no)
  686. {
  687. u32 cfg = hisi_sas_phy_read32(hisi_hba, phy_no, PHY_CFG);
  688. cfg |= PHY_CFG_ENA_MSK;
  689. cfg &= ~PHY_CFG_PHY_RST_MSK;
  690. hisi_sas_phy_write32(hisi_hba, phy_no, PHY_CFG, cfg);
  691. }
  692. static void disable_phy_v3_hw(struct hisi_hba *hisi_hba, int phy_no)
  693. {
  694. u32 cfg = hisi_sas_phy_read32(hisi_hba, phy_no, PHY_CFG);
  695. u32 state;
  696. cfg &= ~PHY_CFG_ENA_MSK;
  697. hisi_sas_phy_write32(hisi_hba, phy_no, PHY_CFG, cfg);
  698. mdelay(50);
  699. state = hisi_sas_read32(hisi_hba, PHY_STATE);
  700. if (state & BIT(phy_no)) {
  701. cfg |= PHY_CFG_PHY_RST_MSK;
  702. hisi_sas_phy_write32(hisi_hba, phy_no, PHY_CFG, cfg);
  703. }
  704. }
  705. static void start_phy_v3_hw(struct hisi_hba *hisi_hba, int phy_no)
  706. {
  707. config_id_frame_v3_hw(hisi_hba, phy_no);
  708. config_phy_opt_mode_v3_hw(hisi_hba, phy_no);
  709. enable_phy_v3_hw(hisi_hba, phy_no);
  710. }
  711. static void phy_hard_reset_v3_hw(struct hisi_hba *hisi_hba, int phy_no)
  712. {
  713. struct hisi_sas_phy *phy = &hisi_hba->phy[phy_no];
  714. u32 txid_auto;
  715. disable_phy_v3_hw(hisi_hba, phy_no);
  716. if (phy->identify.device_type == SAS_END_DEVICE) {
  717. txid_auto = hisi_sas_phy_read32(hisi_hba, phy_no, TXID_AUTO);
  718. hisi_sas_phy_write32(hisi_hba, phy_no, TXID_AUTO,
  719. txid_auto | TX_HARDRST_MSK);
  720. }
  721. msleep(100);
  722. start_phy_v3_hw(hisi_hba, phy_no);
  723. }
  724. static enum sas_linkrate phy_get_max_linkrate_v3_hw(void)
  725. {
  726. return SAS_LINK_RATE_12_0_GBPS;
  727. }
  728. static void phys_init_v3_hw(struct hisi_hba *hisi_hba)
  729. {
  730. int i;
  731. for (i = 0; i < hisi_hba->n_phy; i++) {
  732. struct hisi_sas_phy *phy = &hisi_hba->phy[i];
  733. struct asd_sas_phy *sas_phy = &phy->sas_phy;
  734. if (!sas_phy->phy->enabled)
  735. continue;
  736. start_phy_v3_hw(hisi_hba, i);
  737. }
  738. }
  739. static void sl_notify_ssp_v3_hw(struct hisi_hba *hisi_hba, int phy_no)
  740. {
  741. u32 sl_control;
  742. sl_control = hisi_sas_phy_read32(hisi_hba, phy_no, SL_CONTROL);
  743. sl_control |= SL_CONTROL_NOTIFY_EN_MSK;
  744. hisi_sas_phy_write32(hisi_hba, phy_no, SL_CONTROL, sl_control);
  745. msleep(1);
  746. sl_control = hisi_sas_phy_read32(hisi_hba, phy_no, SL_CONTROL);
  747. sl_control &= ~SL_CONTROL_NOTIFY_EN_MSK;
  748. hisi_sas_phy_write32(hisi_hba, phy_no, SL_CONTROL, sl_control);
  749. }
  750. static int get_wideport_bitmap_v3_hw(struct hisi_hba *hisi_hba, int port_id)
  751. {
  752. int i, bitmap = 0;
  753. u32 phy_port_num_ma = hisi_sas_read32(hisi_hba, PHY_PORT_NUM_MA);
  754. u32 phy_state = hisi_sas_read32(hisi_hba, PHY_STATE);
  755. for (i = 0; i < hisi_hba->n_phy; i++)
  756. if (phy_state & BIT(i))
  757. if (((phy_port_num_ma >> (i * 4)) & 0xf) == port_id)
  758. bitmap |= BIT(i);
  759. return bitmap;
  760. }
  761. /**
  762. * The callpath to this function and upto writing the write
  763. * queue pointer should be safe from interruption.
  764. */
  765. static int
  766. get_free_slot_v3_hw(struct hisi_hba *hisi_hba, struct hisi_sas_dq *dq)
  767. {
  768. struct device *dev = hisi_hba->dev;
  769. int queue = dq->id;
  770. u32 r, w;
  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. dev_warn(dev, "full queue=%d r=%d w=%d\n",
  776. queue, r, w);
  777. return -EAGAIN;
  778. }
  779. dq->wr_point = (dq->wr_point + 1) % HISI_SAS_QUEUE_SLOTS;
  780. return w;
  781. }
  782. static void start_delivery_v3_hw(struct hisi_sas_dq *dq)
  783. {
  784. struct hisi_hba *hisi_hba = dq->hisi_hba;
  785. struct hisi_sas_slot *s, *s1, *s2 = NULL;
  786. int dlvry_queue = dq->id;
  787. int wp;
  788. list_for_each_entry_safe(s, s1, &dq->list, delivery) {
  789. if (!s->ready)
  790. break;
  791. s2 = s;
  792. list_del(&s->delivery);
  793. }
  794. if (!s2)
  795. return;
  796. /*
  797. * Ensure that memories for slots built on other CPUs is observed.
  798. */
  799. smp_rmb();
  800. wp = (s2->dlvry_queue_slot + 1) % HISI_SAS_QUEUE_SLOTS;
  801. hisi_sas_write32(hisi_hba, DLVRY_Q_0_WR_PTR + (dlvry_queue * 0x14), wp);
  802. }
  803. static void prep_prd_sge_v3_hw(struct hisi_hba *hisi_hba,
  804. struct hisi_sas_slot *slot,
  805. struct hisi_sas_cmd_hdr *hdr,
  806. struct scatterlist *scatter,
  807. int n_elem)
  808. {
  809. struct hisi_sas_sge_page *sge_page = hisi_sas_sge_addr_mem(slot);
  810. struct scatterlist *sg;
  811. int i;
  812. for_each_sg(scatter, sg, n_elem, i) {
  813. struct hisi_sas_sge *entry = &sge_page->sge[i];
  814. entry->addr = cpu_to_le64(sg_dma_address(sg));
  815. entry->page_ctrl_0 = entry->page_ctrl_1 = 0;
  816. entry->data_len = cpu_to_le32(sg_dma_len(sg));
  817. entry->data_off = 0;
  818. }
  819. hdr->prd_table_addr = cpu_to_le64(hisi_sas_sge_addr_dma(slot));
  820. hdr->sg_len = cpu_to_le32(n_elem << CMD_HDR_DATA_SGL_LEN_OFF);
  821. }
  822. static void prep_ssp_v3_hw(struct hisi_hba *hisi_hba,
  823. struct hisi_sas_slot *slot)
  824. {
  825. struct sas_task *task = slot->task;
  826. struct hisi_sas_cmd_hdr *hdr = slot->cmd_hdr;
  827. struct domain_device *device = task->dev;
  828. struct hisi_sas_device *sas_dev = device->lldd_dev;
  829. struct hisi_sas_port *port = slot->port;
  830. struct sas_ssp_task *ssp_task = &task->ssp_task;
  831. struct scsi_cmnd *scsi_cmnd = ssp_task->cmd;
  832. struct hisi_sas_tmf_task *tmf = slot->tmf;
  833. int has_data = 0, priority = !!tmf;
  834. u8 *buf_cmd;
  835. u32 dw1 = 0, dw2 = 0;
  836. hdr->dw0 = cpu_to_le32((1 << CMD_HDR_RESP_REPORT_OFF) |
  837. (2 << CMD_HDR_TLR_CTRL_OFF) |
  838. (port->id << CMD_HDR_PORT_OFF) |
  839. (priority << CMD_HDR_PRIORITY_OFF) |
  840. (1 << CMD_HDR_CMD_OFF)); /* ssp */
  841. dw1 = 1 << CMD_HDR_VDTL_OFF;
  842. if (tmf) {
  843. dw1 |= 2 << CMD_HDR_FRAME_TYPE_OFF;
  844. dw1 |= DIR_NO_DATA << CMD_HDR_DIR_OFF;
  845. } else {
  846. dw1 |= 1 << CMD_HDR_FRAME_TYPE_OFF;
  847. switch (scsi_cmnd->sc_data_direction) {
  848. case DMA_TO_DEVICE:
  849. has_data = 1;
  850. dw1 |= DIR_TO_DEVICE << CMD_HDR_DIR_OFF;
  851. break;
  852. case DMA_FROM_DEVICE:
  853. has_data = 1;
  854. dw1 |= DIR_TO_INI << CMD_HDR_DIR_OFF;
  855. break;
  856. default:
  857. dw1 &= ~CMD_HDR_DIR_MSK;
  858. }
  859. }
  860. /* map itct entry */
  861. dw1 |= sas_dev->device_id << CMD_HDR_DEV_ID_OFF;
  862. hdr->dw1 = cpu_to_le32(dw1);
  863. dw2 = (((sizeof(struct ssp_command_iu) + sizeof(struct ssp_frame_hdr)
  864. + 3) / 4) << CMD_HDR_CFL_OFF) |
  865. ((HISI_SAS_MAX_SSP_RESP_SZ / 4) << CMD_HDR_MRFL_OFF) |
  866. (2 << CMD_HDR_SG_MOD_OFF);
  867. hdr->dw2 = cpu_to_le32(dw2);
  868. hdr->transfer_tags = cpu_to_le32(slot->idx);
  869. if (has_data)
  870. prep_prd_sge_v3_hw(hisi_hba, slot, hdr, task->scatter,
  871. slot->n_elem);
  872. hdr->data_transfer_len = cpu_to_le32(task->total_xfer_len);
  873. hdr->cmd_table_addr = cpu_to_le64(hisi_sas_cmd_hdr_addr_dma(slot));
  874. hdr->sts_buffer_addr = cpu_to_le64(hisi_sas_status_buf_addr_dma(slot));
  875. buf_cmd = hisi_sas_cmd_hdr_addr_mem(slot) +
  876. sizeof(struct ssp_frame_hdr);
  877. memcpy(buf_cmd, &task->ssp_task.LUN, 8);
  878. if (!tmf) {
  879. buf_cmd[9] = ssp_task->task_attr | (ssp_task->task_prio << 3);
  880. memcpy(buf_cmd + 12, scsi_cmnd->cmnd, scsi_cmnd->cmd_len);
  881. } else {
  882. buf_cmd[10] = tmf->tmf;
  883. switch (tmf->tmf) {
  884. case TMF_ABORT_TASK:
  885. case TMF_QUERY_TASK:
  886. buf_cmd[12] =
  887. (tmf->tag_of_task_to_be_managed >> 8) & 0xff;
  888. buf_cmd[13] =
  889. tmf->tag_of_task_to_be_managed & 0xff;
  890. break;
  891. default:
  892. break;
  893. }
  894. }
  895. }
  896. static void prep_smp_v3_hw(struct hisi_hba *hisi_hba,
  897. struct hisi_sas_slot *slot)
  898. {
  899. struct sas_task *task = slot->task;
  900. struct hisi_sas_cmd_hdr *hdr = slot->cmd_hdr;
  901. struct domain_device *device = task->dev;
  902. struct hisi_sas_port *port = slot->port;
  903. struct scatterlist *sg_req;
  904. struct hisi_sas_device *sas_dev = device->lldd_dev;
  905. dma_addr_t req_dma_addr;
  906. unsigned int req_len;
  907. /* req */
  908. sg_req = &task->smp_task.smp_req;
  909. req_len = sg_dma_len(sg_req);
  910. req_dma_addr = sg_dma_address(sg_req);
  911. /* create header */
  912. /* dw0 */
  913. hdr->dw0 = cpu_to_le32((port->id << CMD_HDR_PORT_OFF) |
  914. (1 << CMD_HDR_PRIORITY_OFF) | /* high pri */
  915. (2 << CMD_HDR_CMD_OFF)); /* smp */
  916. /* map itct entry */
  917. hdr->dw1 = cpu_to_le32((sas_dev->device_id << CMD_HDR_DEV_ID_OFF) |
  918. (1 << CMD_HDR_FRAME_TYPE_OFF) |
  919. (DIR_NO_DATA << CMD_HDR_DIR_OFF));
  920. /* dw2 */
  921. hdr->dw2 = cpu_to_le32((((req_len - 4) / 4) << CMD_HDR_CFL_OFF) |
  922. (HISI_SAS_MAX_SMP_RESP_SZ / 4 <<
  923. CMD_HDR_MRFL_OFF));
  924. hdr->transfer_tags = cpu_to_le32(slot->idx << CMD_HDR_IPTT_OFF);
  925. hdr->cmd_table_addr = cpu_to_le64(req_dma_addr);
  926. hdr->sts_buffer_addr = cpu_to_le64(hisi_sas_status_buf_addr_dma(slot));
  927. }
  928. static void prep_ata_v3_hw(struct hisi_hba *hisi_hba,
  929. struct hisi_sas_slot *slot)
  930. {
  931. struct sas_task *task = slot->task;
  932. struct domain_device *device = task->dev;
  933. struct domain_device *parent_dev = device->parent;
  934. struct hisi_sas_device *sas_dev = device->lldd_dev;
  935. struct hisi_sas_cmd_hdr *hdr = slot->cmd_hdr;
  936. struct asd_sas_port *sas_port = device->port;
  937. struct hisi_sas_port *port = to_hisi_sas_port(sas_port);
  938. u8 *buf_cmd;
  939. int has_data = 0, hdr_tag = 0;
  940. u32 dw1 = 0, dw2 = 0;
  941. hdr->dw0 = cpu_to_le32(port->id << CMD_HDR_PORT_OFF);
  942. if (parent_dev && DEV_IS_EXPANDER(parent_dev->dev_type))
  943. hdr->dw0 |= cpu_to_le32(3 << CMD_HDR_CMD_OFF);
  944. else
  945. hdr->dw0 |= cpu_to_le32(4 << CMD_HDR_CMD_OFF);
  946. switch (task->data_dir) {
  947. case DMA_TO_DEVICE:
  948. has_data = 1;
  949. dw1 |= DIR_TO_DEVICE << CMD_HDR_DIR_OFF;
  950. break;
  951. case DMA_FROM_DEVICE:
  952. has_data = 1;
  953. dw1 |= DIR_TO_INI << CMD_HDR_DIR_OFF;
  954. break;
  955. default:
  956. dw1 &= ~CMD_HDR_DIR_MSK;
  957. }
  958. if ((task->ata_task.fis.command == ATA_CMD_DEV_RESET) &&
  959. (task->ata_task.fis.control & ATA_SRST))
  960. dw1 |= 1 << CMD_HDR_RESET_OFF;
  961. dw1 |= (hisi_sas_get_ata_protocol(
  962. &task->ata_task.fis, task->data_dir))
  963. << CMD_HDR_FRAME_TYPE_OFF;
  964. dw1 |= sas_dev->device_id << CMD_HDR_DEV_ID_OFF;
  965. if (FIS_CMD_IS_UNCONSTRAINED(task->ata_task.fis))
  966. dw1 |= 1 << CMD_HDR_UNCON_CMD_OFF;
  967. hdr->dw1 = cpu_to_le32(dw1);
  968. /* dw2 */
  969. if (task->ata_task.use_ncq && hisi_sas_get_ncq_tag(task, &hdr_tag)) {
  970. task->ata_task.fis.sector_count |= (u8) (hdr_tag << 3);
  971. dw2 |= hdr_tag << CMD_HDR_NCQ_TAG_OFF;
  972. }
  973. dw2 |= (HISI_SAS_MAX_STP_RESP_SZ / 4) << CMD_HDR_CFL_OFF |
  974. 2 << CMD_HDR_SG_MOD_OFF;
  975. hdr->dw2 = cpu_to_le32(dw2);
  976. /* dw3 */
  977. hdr->transfer_tags = cpu_to_le32(slot->idx);
  978. if (has_data)
  979. prep_prd_sge_v3_hw(hisi_hba, slot, hdr, task->scatter,
  980. slot->n_elem);
  981. hdr->data_transfer_len = cpu_to_le32(task->total_xfer_len);
  982. hdr->cmd_table_addr = cpu_to_le64(hisi_sas_cmd_hdr_addr_dma(slot));
  983. hdr->sts_buffer_addr = cpu_to_le64(hisi_sas_status_buf_addr_dma(slot));
  984. buf_cmd = hisi_sas_cmd_hdr_addr_mem(slot);
  985. if (likely(!task->ata_task.device_control_reg_update))
  986. task->ata_task.fis.flags |= 0x80; /* C=1: update ATA cmd reg */
  987. /* fill in command FIS */
  988. memcpy(buf_cmd, &task->ata_task.fis, sizeof(struct host_to_dev_fis));
  989. }
  990. static void prep_abort_v3_hw(struct hisi_hba *hisi_hba,
  991. struct hisi_sas_slot *slot,
  992. int device_id, int abort_flag, int tag_to_abort)
  993. {
  994. struct sas_task *task = slot->task;
  995. struct domain_device *dev = task->dev;
  996. struct hisi_sas_cmd_hdr *hdr = slot->cmd_hdr;
  997. struct hisi_sas_port *port = slot->port;
  998. /* dw0 */
  999. hdr->dw0 = cpu_to_le32((5 << CMD_HDR_CMD_OFF) | /*abort*/
  1000. (port->id << CMD_HDR_PORT_OFF) |
  1001. (dev_is_sata(dev)
  1002. << CMD_HDR_ABORT_DEVICE_TYPE_OFF) |
  1003. (abort_flag
  1004. << CMD_HDR_ABORT_FLAG_OFF));
  1005. /* dw1 */
  1006. hdr->dw1 = cpu_to_le32(device_id
  1007. << CMD_HDR_DEV_ID_OFF);
  1008. /* dw7 */
  1009. hdr->dw7 = cpu_to_le32(tag_to_abort << CMD_HDR_ABORT_IPTT_OFF);
  1010. hdr->transfer_tags = cpu_to_le32(slot->idx);
  1011. }
  1012. static irqreturn_t phy_up_v3_hw(int phy_no, struct hisi_hba *hisi_hba)
  1013. {
  1014. int i, res;
  1015. u32 context, port_id, link_rate;
  1016. struct hisi_sas_phy *phy = &hisi_hba->phy[phy_no];
  1017. struct asd_sas_phy *sas_phy = &phy->sas_phy;
  1018. struct device *dev = hisi_hba->dev;
  1019. unsigned long flags;
  1020. hisi_sas_phy_write32(hisi_hba, phy_no, PHYCTRL_PHY_ENA_MSK, 1);
  1021. port_id = hisi_sas_read32(hisi_hba, PHY_PORT_NUM_MA);
  1022. port_id = (port_id >> (4 * phy_no)) & 0xf;
  1023. link_rate = hisi_sas_read32(hisi_hba, PHY_CONN_RATE);
  1024. link_rate = (link_rate >> (phy_no * 4)) & 0xf;
  1025. if (port_id == 0xf) {
  1026. dev_err(dev, "phyup: phy%d invalid portid\n", phy_no);
  1027. res = IRQ_NONE;
  1028. goto end;
  1029. }
  1030. sas_phy->linkrate = link_rate;
  1031. phy->phy_type &= ~(PORT_TYPE_SAS | PORT_TYPE_SATA);
  1032. /* Check for SATA dev */
  1033. context = hisi_sas_read32(hisi_hba, PHY_CONTEXT);
  1034. if (context & (1 << phy_no)) {
  1035. struct hisi_sas_initial_fis *initial_fis;
  1036. struct dev_to_host_fis *fis;
  1037. u8 attached_sas_addr[SAS_ADDR_SIZE] = {0};
  1038. dev_info(dev, "phyup: phy%d link_rate=%d(sata)\n", phy_no, link_rate);
  1039. initial_fis = &hisi_hba->initial_fis[phy_no];
  1040. fis = &initial_fis->fis;
  1041. /* check ERR bit of Status Register */
  1042. if (fis->status & ATA_ERR) {
  1043. dev_warn(dev, "sata int: phy%d FIS status: 0x%x\n",
  1044. phy_no, fis->status);
  1045. hisi_sas_notify_phy_event(phy, HISI_PHYE_LINK_RESET);
  1046. res = IRQ_NONE;
  1047. goto end;
  1048. }
  1049. sas_phy->oob_mode = SATA_OOB_MODE;
  1050. attached_sas_addr[0] = 0x50;
  1051. attached_sas_addr[7] = phy_no;
  1052. memcpy(sas_phy->attached_sas_addr,
  1053. attached_sas_addr,
  1054. SAS_ADDR_SIZE);
  1055. memcpy(sas_phy->frame_rcvd, fis,
  1056. sizeof(struct dev_to_host_fis));
  1057. phy->phy_type |= PORT_TYPE_SATA;
  1058. phy->identify.device_type = SAS_SATA_DEV;
  1059. phy->frame_rcvd_size = sizeof(struct dev_to_host_fis);
  1060. phy->identify.target_port_protocols = SAS_PROTOCOL_SATA;
  1061. } else {
  1062. u32 *frame_rcvd = (u32 *)sas_phy->frame_rcvd;
  1063. struct sas_identify_frame *id =
  1064. (struct sas_identify_frame *)frame_rcvd;
  1065. dev_info(dev, "phyup: phy%d link_rate=%d\n", phy_no, link_rate);
  1066. for (i = 0; i < 6; i++) {
  1067. u32 idaf = hisi_sas_phy_read32(hisi_hba, phy_no,
  1068. RX_IDAF_DWORD0 + (i * 4));
  1069. frame_rcvd[i] = __swab32(idaf);
  1070. }
  1071. sas_phy->oob_mode = SAS_OOB_MODE;
  1072. memcpy(sas_phy->attached_sas_addr,
  1073. &id->sas_addr,
  1074. SAS_ADDR_SIZE);
  1075. phy->phy_type |= PORT_TYPE_SAS;
  1076. phy->identify.device_type = id->dev_type;
  1077. phy->frame_rcvd_size = sizeof(struct sas_identify_frame);
  1078. if (phy->identify.device_type == SAS_END_DEVICE)
  1079. phy->identify.target_port_protocols =
  1080. SAS_PROTOCOL_SSP;
  1081. else if (phy->identify.device_type != SAS_PHY_UNUSED)
  1082. phy->identify.target_port_protocols =
  1083. SAS_PROTOCOL_SMP;
  1084. }
  1085. phy->port_id = port_id;
  1086. phy->phy_attached = 1;
  1087. hisi_sas_notify_phy_event(phy, HISI_PHYE_PHY_UP);
  1088. res = IRQ_HANDLED;
  1089. spin_lock_irqsave(&phy->lock, flags);
  1090. if (phy->reset_completion) {
  1091. phy->in_reset = 0;
  1092. complete(phy->reset_completion);
  1093. }
  1094. spin_unlock_irqrestore(&phy->lock, flags);
  1095. end:
  1096. hisi_sas_phy_write32(hisi_hba, phy_no, CHL_INT0,
  1097. CHL_INT0_SL_PHY_ENABLE_MSK);
  1098. hisi_sas_phy_write32(hisi_hba, phy_no, PHYCTRL_PHY_ENA_MSK, 0);
  1099. return res;
  1100. }
  1101. static irqreturn_t phy_down_v3_hw(int phy_no, struct hisi_hba *hisi_hba)
  1102. {
  1103. u32 phy_state, sl_ctrl, txid_auto;
  1104. struct device *dev = hisi_hba->dev;
  1105. hisi_sas_phy_write32(hisi_hba, phy_no, PHYCTRL_NOT_RDY_MSK, 1);
  1106. phy_state = hisi_sas_read32(hisi_hba, PHY_STATE);
  1107. dev_info(dev, "phydown: phy%d phy_state=0x%x\n", phy_no, phy_state);
  1108. hisi_sas_phy_down(hisi_hba, phy_no, (phy_state & 1 << phy_no) ? 1 : 0);
  1109. sl_ctrl = hisi_sas_phy_read32(hisi_hba, phy_no, SL_CONTROL);
  1110. hisi_sas_phy_write32(hisi_hba, phy_no, SL_CONTROL,
  1111. sl_ctrl&(~SL_CTA_MSK));
  1112. txid_auto = hisi_sas_phy_read32(hisi_hba, phy_no, TXID_AUTO);
  1113. hisi_sas_phy_write32(hisi_hba, phy_no, TXID_AUTO,
  1114. txid_auto | CT3_MSK);
  1115. hisi_sas_phy_write32(hisi_hba, phy_no, CHL_INT0, CHL_INT0_NOT_RDY_MSK);
  1116. hisi_sas_phy_write32(hisi_hba, phy_no, PHYCTRL_NOT_RDY_MSK, 0);
  1117. return IRQ_HANDLED;
  1118. }
  1119. static irqreturn_t phy_bcast_v3_hw(int phy_no, struct hisi_hba *hisi_hba)
  1120. {
  1121. struct hisi_sas_phy *phy = &hisi_hba->phy[phy_no];
  1122. struct asd_sas_phy *sas_phy = &phy->sas_phy;
  1123. struct sas_ha_struct *sas_ha = &hisi_hba->sha;
  1124. u32 bcast_status;
  1125. hisi_sas_phy_write32(hisi_hba, phy_no, SL_RX_BCAST_CHK_MSK, 1);
  1126. bcast_status = hisi_sas_phy_read32(hisi_hba, phy_no, RX_PRIMS_STATUS);
  1127. if ((bcast_status & RX_BCAST_CHG_MSK) &&
  1128. !test_bit(HISI_SAS_RESET_BIT, &hisi_hba->flags))
  1129. sas_ha->notify_port_event(sas_phy, PORTE_BROADCAST_RCVD);
  1130. hisi_sas_phy_write32(hisi_hba, phy_no, CHL_INT0,
  1131. CHL_INT0_SL_RX_BCST_ACK_MSK);
  1132. hisi_sas_phy_write32(hisi_hba, phy_no, SL_RX_BCAST_CHK_MSK, 0);
  1133. return IRQ_HANDLED;
  1134. }
  1135. static irqreturn_t int_phy_up_down_bcast_v3_hw(int irq_no, void *p)
  1136. {
  1137. struct hisi_hba *hisi_hba = p;
  1138. u32 irq_msk;
  1139. int phy_no = 0;
  1140. irqreturn_t res = IRQ_NONE;
  1141. irq_msk = hisi_sas_read32(hisi_hba, CHNL_INT_STATUS)
  1142. & 0x11111111;
  1143. while (irq_msk) {
  1144. if (irq_msk & 1) {
  1145. u32 irq_value = hisi_sas_phy_read32(hisi_hba, phy_no,
  1146. CHL_INT0);
  1147. u32 phy_state = hisi_sas_read32(hisi_hba, PHY_STATE);
  1148. int rdy = phy_state & (1 << phy_no);
  1149. if (rdy) {
  1150. if (irq_value & CHL_INT0_SL_PHY_ENABLE_MSK)
  1151. /* phy up */
  1152. if (phy_up_v3_hw(phy_no, hisi_hba)
  1153. == IRQ_HANDLED)
  1154. res = IRQ_HANDLED;
  1155. if (irq_value & CHL_INT0_SL_RX_BCST_ACK_MSK)
  1156. /* phy bcast */
  1157. if (phy_bcast_v3_hw(phy_no, hisi_hba)
  1158. == IRQ_HANDLED)
  1159. res = IRQ_HANDLED;
  1160. } else {
  1161. if (irq_value & CHL_INT0_NOT_RDY_MSK)
  1162. /* phy down */
  1163. if (phy_down_v3_hw(phy_no, hisi_hba)
  1164. == IRQ_HANDLED)
  1165. res = IRQ_HANDLED;
  1166. }
  1167. }
  1168. irq_msk >>= 4;
  1169. phy_no++;
  1170. }
  1171. return res;
  1172. }
  1173. static const struct hisi_sas_hw_error port_axi_error[] = {
  1174. {
  1175. .irq_msk = BIT(CHL_INT1_DMAC_TX_AXI_WR_ERR_OFF),
  1176. .msg = "dma_tx_axi_wr_err",
  1177. },
  1178. {
  1179. .irq_msk = BIT(CHL_INT1_DMAC_TX_AXI_RD_ERR_OFF),
  1180. .msg = "dma_tx_axi_rd_err",
  1181. },
  1182. {
  1183. .irq_msk = BIT(CHL_INT1_DMAC_RX_AXI_WR_ERR_OFF),
  1184. .msg = "dma_rx_axi_wr_err",
  1185. },
  1186. {
  1187. .irq_msk = BIT(CHL_INT1_DMAC_RX_AXI_RD_ERR_OFF),
  1188. .msg = "dma_rx_axi_rd_err",
  1189. },
  1190. };
  1191. static void handle_chl_int1_v3_hw(struct hisi_hba *hisi_hba, int phy_no)
  1192. {
  1193. u32 irq_value = hisi_sas_phy_read32(hisi_hba, phy_no, CHL_INT1);
  1194. u32 irq_msk = hisi_sas_phy_read32(hisi_hba, phy_no, CHL_INT1_MSK);
  1195. struct device *dev = hisi_hba->dev;
  1196. int i;
  1197. irq_value &= ~irq_msk;
  1198. if (!irq_value)
  1199. return;
  1200. for (i = 0; i < ARRAY_SIZE(port_axi_error); i++) {
  1201. const struct hisi_sas_hw_error *error = &port_axi_error[i];
  1202. if (!(irq_value & error->irq_msk))
  1203. continue;
  1204. dev_err(dev, "%s error (phy%d 0x%x) found!\n",
  1205. error->msg, phy_no, irq_value);
  1206. queue_work(hisi_hba->wq, &hisi_hba->rst_work);
  1207. }
  1208. hisi_sas_phy_write32(hisi_hba, phy_no, CHL_INT1, irq_value);
  1209. }
  1210. static void handle_chl_int2_v3_hw(struct hisi_hba *hisi_hba, int phy_no)
  1211. {
  1212. u32 irq_msk = hisi_sas_phy_read32(hisi_hba, phy_no, CHL_INT2_MSK);
  1213. u32 irq_value = hisi_sas_phy_read32(hisi_hba, phy_no, CHL_INT2);
  1214. struct hisi_sas_phy *phy = &hisi_hba->phy[phy_no];
  1215. struct pci_dev *pci_dev = hisi_hba->pci_dev;
  1216. struct device *dev = hisi_hba->dev;
  1217. irq_value &= ~irq_msk;
  1218. if (!irq_value)
  1219. return;
  1220. if (irq_value & BIT(CHL_INT2_SL_IDAF_TOUT_CONF_OFF)) {
  1221. dev_warn(dev, "phy%d identify timeout\n", phy_no);
  1222. hisi_sas_notify_phy_event(phy, HISI_PHYE_LINK_RESET);
  1223. }
  1224. if (irq_value & BIT(CHL_INT2_STP_LINK_TIMEOUT_OFF)) {
  1225. u32 reg_value = hisi_sas_phy_read32(hisi_hba, phy_no,
  1226. STP_LINK_TIMEOUT_STATE);
  1227. dev_warn(dev, "phy%d stp link timeout (0x%x)\n",
  1228. phy_no, reg_value);
  1229. if (reg_value & BIT(4))
  1230. hisi_sas_notify_phy_event(phy, HISI_PHYE_LINK_RESET);
  1231. }
  1232. if ((irq_value & BIT(CHL_INT2_RX_INVLD_DW_OFF)) &&
  1233. (pci_dev->revision == 0x20)) {
  1234. u32 reg_value;
  1235. int rc;
  1236. rc = hisi_sas_read32_poll_timeout_atomic(
  1237. HILINK_ERR_DFX, reg_value,
  1238. !((reg_value >> 8) & BIT(phy_no)),
  1239. 1000, 10000);
  1240. if (rc)
  1241. hisi_sas_notify_phy_event(phy, HISI_PHYE_LINK_RESET);
  1242. }
  1243. hisi_sas_phy_write32(hisi_hba, phy_no, CHL_INT2, irq_value);
  1244. }
  1245. static irqreturn_t int_chnl_int_v3_hw(int irq_no, void *p)
  1246. {
  1247. struct hisi_hba *hisi_hba = p;
  1248. u32 irq_msk;
  1249. int phy_no = 0;
  1250. irq_msk = hisi_sas_read32(hisi_hba, CHNL_INT_STATUS)
  1251. & 0xeeeeeeee;
  1252. while (irq_msk) {
  1253. u32 irq_value0 = hisi_sas_phy_read32(hisi_hba, phy_no,
  1254. CHL_INT0);
  1255. if (irq_msk & (4 << (phy_no * 4)))
  1256. handle_chl_int1_v3_hw(hisi_hba, phy_no);
  1257. if (irq_msk & (8 << (phy_no * 4)))
  1258. handle_chl_int2_v3_hw(hisi_hba, phy_no);
  1259. if (irq_msk & (2 << (phy_no * 4)) && irq_value0) {
  1260. hisi_sas_phy_write32(hisi_hba, phy_no,
  1261. CHL_INT0, irq_value0
  1262. & (~CHL_INT0_SL_RX_BCST_ACK_MSK)
  1263. & (~CHL_INT0_SL_PHY_ENABLE_MSK)
  1264. & (~CHL_INT0_NOT_RDY_MSK));
  1265. }
  1266. irq_msk &= ~(0xe << (phy_no * 4));
  1267. phy_no++;
  1268. }
  1269. return IRQ_HANDLED;
  1270. }
  1271. static const struct hisi_sas_hw_error axi_error[] = {
  1272. { .msk = BIT(0), .msg = "IOST_AXI_W_ERR" },
  1273. { .msk = BIT(1), .msg = "IOST_AXI_R_ERR" },
  1274. { .msk = BIT(2), .msg = "ITCT_AXI_W_ERR" },
  1275. { .msk = BIT(3), .msg = "ITCT_AXI_R_ERR" },
  1276. { .msk = BIT(4), .msg = "SATA_AXI_W_ERR" },
  1277. { .msk = BIT(5), .msg = "SATA_AXI_R_ERR" },
  1278. { .msk = BIT(6), .msg = "DQE_AXI_R_ERR" },
  1279. { .msk = BIT(7), .msg = "CQE_AXI_W_ERR" },
  1280. {},
  1281. };
  1282. static const struct hisi_sas_hw_error fifo_error[] = {
  1283. { .msk = BIT(8), .msg = "CQE_WINFO_FIFO" },
  1284. { .msk = BIT(9), .msg = "CQE_MSG_FIFIO" },
  1285. { .msk = BIT(10), .msg = "GETDQE_FIFO" },
  1286. { .msk = BIT(11), .msg = "CMDP_FIFO" },
  1287. { .msk = BIT(12), .msg = "AWTCTRL_FIFO" },
  1288. {},
  1289. };
  1290. static const struct hisi_sas_hw_error fatal_axi_error[] = {
  1291. {
  1292. .irq_msk = BIT(ENT_INT_SRC3_WP_DEPTH_OFF),
  1293. .msg = "write pointer and depth",
  1294. },
  1295. {
  1296. .irq_msk = BIT(ENT_INT_SRC3_IPTT_SLOT_NOMATCH_OFF),
  1297. .msg = "iptt no match slot",
  1298. },
  1299. {
  1300. .irq_msk = BIT(ENT_INT_SRC3_RP_DEPTH_OFF),
  1301. .msg = "read pointer and depth",
  1302. },
  1303. {
  1304. .irq_msk = BIT(ENT_INT_SRC3_AXI_OFF),
  1305. .reg = HGC_AXI_FIFO_ERR_INFO,
  1306. .sub = axi_error,
  1307. },
  1308. {
  1309. .irq_msk = BIT(ENT_INT_SRC3_FIFO_OFF),
  1310. .reg = HGC_AXI_FIFO_ERR_INFO,
  1311. .sub = fifo_error,
  1312. },
  1313. {
  1314. .irq_msk = BIT(ENT_INT_SRC3_LM_OFF),
  1315. .msg = "LM add/fetch list",
  1316. },
  1317. {
  1318. .irq_msk = BIT(ENT_INT_SRC3_ABT_OFF),
  1319. .msg = "SAS_HGC_ABT fetch LM list",
  1320. },
  1321. };
  1322. static irqreturn_t fatal_axi_int_v3_hw(int irq_no, void *p)
  1323. {
  1324. u32 irq_value, irq_msk;
  1325. struct hisi_hba *hisi_hba = p;
  1326. struct device *dev = hisi_hba->dev;
  1327. struct pci_dev *pdev = hisi_hba->pci_dev;
  1328. int i;
  1329. irq_msk = hisi_sas_read32(hisi_hba, ENT_INT_SRC_MSK3);
  1330. hisi_sas_write32(hisi_hba, ENT_INT_SRC_MSK3, irq_msk | 0x1df00);
  1331. irq_value = hisi_sas_read32(hisi_hba, ENT_INT_SRC3);
  1332. irq_value &= ~irq_msk;
  1333. for (i = 0; i < ARRAY_SIZE(fatal_axi_error); i++) {
  1334. const struct hisi_sas_hw_error *error = &fatal_axi_error[i];
  1335. if (!(irq_value & error->irq_msk))
  1336. continue;
  1337. if (error->sub) {
  1338. const struct hisi_sas_hw_error *sub = error->sub;
  1339. u32 err_value = hisi_sas_read32(hisi_hba, error->reg);
  1340. for (; sub->msk || sub->msg; sub++) {
  1341. if (!(err_value & sub->msk))
  1342. continue;
  1343. dev_err(dev, "%s error (0x%x) found!\n",
  1344. sub->msg, irq_value);
  1345. queue_work(hisi_hba->wq, &hisi_hba->rst_work);
  1346. }
  1347. } else {
  1348. dev_err(dev, "%s error (0x%x) found!\n",
  1349. error->msg, irq_value);
  1350. queue_work(hisi_hba->wq, &hisi_hba->rst_work);
  1351. }
  1352. if (pdev->revision < 0x21) {
  1353. u32 reg_val;
  1354. reg_val = hisi_sas_read32(hisi_hba,
  1355. AXI_MASTER_CFG_BASE +
  1356. AM_CTRL_GLOBAL);
  1357. reg_val |= AM_CTRL_SHUTDOWN_REQ_MSK;
  1358. hisi_sas_write32(hisi_hba, AXI_MASTER_CFG_BASE +
  1359. AM_CTRL_GLOBAL, reg_val);
  1360. }
  1361. }
  1362. if (irq_value & BIT(ENT_INT_SRC3_ITC_INT_OFF)) {
  1363. u32 reg_val = hisi_sas_read32(hisi_hba, ITCT_CLR);
  1364. u32 dev_id = reg_val & ITCT_DEV_MSK;
  1365. struct hisi_sas_device *sas_dev =
  1366. &hisi_hba->devices[dev_id];
  1367. hisi_sas_write32(hisi_hba, ITCT_CLR, 0);
  1368. dev_dbg(dev, "clear ITCT ok\n");
  1369. complete(sas_dev->completion);
  1370. }
  1371. hisi_sas_write32(hisi_hba, ENT_INT_SRC3, irq_value & 0x1df00);
  1372. hisi_sas_write32(hisi_hba, ENT_INT_SRC_MSK3, irq_msk);
  1373. return IRQ_HANDLED;
  1374. }
  1375. static void
  1376. slot_err_v3_hw(struct hisi_hba *hisi_hba, struct sas_task *task,
  1377. struct hisi_sas_slot *slot)
  1378. {
  1379. struct task_status_struct *ts = &task->task_status;
  1380. struct hisi_sas_complete_v3_hdr *complete_queue =
  1381. hisi_hba->complete_hdr[slot->cmplt_queue];
  1382. struct hisi_sas_complete_v3_hdr *complete_hdr =
  1383. &complete_queue[slot->cmplt_queue_slot];
  1384. struct hisi_sas_err_record_v3 *record =
  1385. hisi_sas_status_buf_addr_mem(slot);
  1386. u32 dma_rx_err_type = le32_to_cpu(record->dma_rx_err_type);
  1387. u32 trans_tx_fail_type = le32_to_cpu(record->trans_tx_fail_type);
  1388. u32 dw3 = le32_to_cpu(complete_hdr->dw3);
  1389. switch (task->task_proto) {
  1390. case SAS_PROTOCOL_SSP:
  1391. if (dma_rx_err_type & RX_DATA_LEN_UNDERFLOW_MSK) {
  1392. ts->residual = trans_tx_fail_type;
  1393. ts->stat = SAS_DATA_UNDERRUN;
  1394. } else if (dw3 & CMPLT_HDR_IO_IN_TARGET_MSK) {
  1395. ts->stat = SAS_QUEUE_FULL;
  1396. slot->abort = 1;
  1397. } else {
  1398. ts->stat = SAS_OPEN_REJECT;
  1399. ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
  1400. }
  1401. break;
  1402. case SAS_PROTOCOL_SATA:
  1403. case SAS_PROTOCOL_STP:
  1404. case SAS_PROTOCOL_SATA | SAS_PROTOCOL_STP:
  1405. if (dma_rx_err_type & RX_DATA_LEN_UNDERFLOW_MSK) {
  1406. ts->residual = trans_tx_fail_type;
  1407. ts->stat = SAS_DATA_UNDERRUN;
  1408. } else if (dw3 & CMPLT_HDR_IO_IN_TARGET_MSK) {
  1409. ts->stat = SAS_PHY_DOWN;
  1410. slot->abort = 1;
  1411. } else {
  1412. ts->stat = SAS_OPEN_REJECT;
  1413. ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
  1414. }
  1415. hisi_sas_sata_done(task, slot);
  1416. break;
  1417. case SAS_PROTOCOL_SMP:
  1418. ts->stat = SAM_STAT_CHECK_CONDITION;
  1419. break;
  1420. default:
  1421. break;
  1422. }
  1423. }
  1424. static int
  1425. slot_complete_v3_hw(struct hisi_hba *hisi_hba, struct hisi_sas_slot *slot)
  1426. {
  1427. struct sas_task *task = slot->task;
  1428. struct hisi_sas_device *sas_dev;
  1429. struct device *dev = hisi_hba->dev;
  1430. struct task_status_struct *ts;
  1431. struct domain_device *device;
  1432. struct sas_ha_struct *ha;
  1433. enum exec_status sts;
  1434. struct hisi_sas_complete_v3_hdr *complete_queue =
  1435. hisi_hba->complete_hdr[slot->cmplt_queue];
  1436. struct hisi_sas_complete_v3_hdr *complete_hdr =
  1437. &complete_queue[slot->cmplt_queue_slot];
  1438. unsigned long flags;
  1439. bool is_internal = slot->is_internal;
  1440. u32 dw0, dw1, dw3;
  1441. if (unlikely(!task || !task->lldd_task || !task->dev))
  1442. return -EINVAL;
  1443. ts = &task->task_status;
  1444. device = task->dev;
  1445. ha = device->port->ha;
  1446. sas_dev = device->lldd_dev;
  1447. spin_lock_irqsave(&task->task_state_lock, flags);
  1448. task->task_state_flags &=
  1449. ~(SAS_TASK_STATE_PENDING | SAS_TASK_AT_INITIATOR);
  1450. spin_unlock_irqrestore(&task->task_state_lock, flags);
  1451. memset(ts, 0, sizeof(*ts));
  1452. ts->resp = SAS_TASK_COMPLETE;
  1453. if (unlikely(!sas_dev)) {
  1454. dev_dbg(dev, "slot complete: port has not device\n");
  1455. ts->stat = SAS_PHY_DOWN;
  1456. goto out;
  1457. }
  1458. dw0 = le32_to_cpu(complete_hdr->dw0);
  1459. dw1 = le32_to_cpu(complete_hdr->dw1);
  1460. dw3 = le32_to_cpu(complete_hdr->dw3);
  1461. /*
  1462. * Use SAS+TMF status codes
  1463. */
  1464. switch ((dw0 & CMPLT_HDR_ABORT_STAT_MSK) >> CMPLT_HDR_ABORT_STAT_OFF) {
  1465. case STAT_IO_ABORTED:
  1466. /* this IO has been aborted by abort command */
  1467. ts->stat = SAS_ABORTED_TASK;
  1468. goto out;
  1469. case STAT_IO_COMPLETE:
  1470. /* internal abort command complete */
  1471. ts->stat = TMF_RESP_FUNC_SUCC;
  1472. goto out;
  1473. case STAT_IO_NO_DEVICE:
  1474. ts->stat = TMF_RESP_FUNC_COMPLETE;
  1475. goto out;
  1476. case STAT_IO_NOT_VALID:
  1477. /*
  1478. * abort single IO, the controller can't find the IO
  1479. */
  1480. ts->stat = TMF_RESP_FUNC_FAILED;
  1481. goto out;
  1482. default:
  1483. break;
  1484. }
  1485. /* check for erroneous completion */
  1486. if ((dw0 & CMPLT_HDR_CMPLT_MSK) == 0x3) {
  1487. u32 *error_info = hisi_sas_status_buf_addr_mem(slot);
  1488. slot_err_v3_hw(hisi_hba, task, slot);
  1489. if (ts->stat != SAS_DATA_UNDERRUN)
  1490. dev_info(dev, "erroneous completion iptt=%d task=%p dev id=%d "
  1491. "CQ hdr: 0x%x 0x%x 0x%x 0x%x "
  1492. "Error info: 0x%x 0x%x 0x%x 0x%x\n",
  1493. slot->idx, task, sas_dev->device_id,
  1494. dw0, dw1, complete_hdr->act, dw3,
  1495. error_info[0], error_info[1],
  1496. error_info[2], error_info[3]);
  1497. if (unlikely(slot->abort))
  1498. return ts->stat;
  1499. goto out;
  1500. }
  1501. switch (task->task_proto) {
  1502. case SAS_PROTOCOL_SSP: {
  1503. struct ssp_response_iu *iu =
  1504. hisi_sas_status_buf_addr_mem(slot) +
  1505. sizeof(struct hisi_sas_err_record);
  1506. sas_ssp_task_response(dev, task, iu);
  1507. break;
  1508. }
  1509. case SAS_PROTOCOL_SMP: {
  1510. struct scatterlist *sg_resp = &task->smp_task.smp_resp;
  1511. void *to;
  1512. ts->stat = SAM_STAT_GOOD;
  1513. to = kmap_atomic(sg_page(sg_resp));
  1514. dma_unmap_sg(dev, &task->smp_task.smp_resp, 1,
  1515. DMA_FROM_DEVICE);
  1516. dma_unmap_sg(dev, &task->smp_task.smp_req, 1,
  1517. DMA_TO_DEVICE);
  1518. memcpy(to + sg_resp->offset,
  1519. hisi_sas_status_buf_addr_mem(slot) +
  1520. sizeof(struct hisi_sas_err_record),
  1521. sg_dma_len(sg_resp));
  1522. kunmap_atomic(to);
  1523. break;
  1524. }
  1525. case SAS_PROTOCOL_SATA:
  1526. case SAS_PROTOCOL_STP:
  1527. case SAS_PROTOCOL_SATA | SAS_PROTOCOL_STP:
  1528. ts->stat = SAM_STAT_GOOD;
  1529. hisi_sas_sata_done(task, slot);
  1530. break;
  1531. default:
  1532. ts->stat = SAM_STAT_CHECK_CONDITION;
  1533. break;
  1534. }
  1535. if (!slot->port->port_attached) {
  1536. dev_warn(dev, "slot complete: port %d has removed\n",
  1537. slot->port->sas_port.id);
  1538. ts->stat = SAS_PHY_DOWN;
  1539. }
  1540. out:
  1541. sts = ts->stat;
  1542. spin_lock_irqsave(&task->task_state_lock, flags);
  1543. if (task->task_state_flags & SAS_TASK_STATE_ABORTED) {
  1544. spin_unlock_irqrestore(&task->task_state_lock, flags);
  1545. dev_info(dev, "slot complete: task(%p) aborted\n", task);
  1546. return SAS_ABORTED_TASK;
  1547. }
  1548. task->task_state_flags |= SAS_TASK_STATE_DONE;
  1549. spin_unlock_irqrestore(&task->task_state_lock, flags);
  1550. hisi_sas_slot_task_free(hisi_hba, task, slot);
  1551. if (!is_internal && (task->task_proto != SAS_PROTOCOL_SMP)) {
  1552. spin_lock_irqsave(&device->done_lock, flags);
  1553. if (test_bit(SAS_HA_FROZEN, &ha->state)) {
  1554. spin_unlock_irqrestore(&device->done_lock, flags);
  1555. dev_info(dev, "slot complete: task(%p) ignored\n ",
  1556. task);
  1557. return sts;
  1558. }
  1559. spin_unlock_irqrestore(&device->done_lock, flags);
  1560. }
  1561. if (task->task_done)
  1562. task->task_done(task);
  1563. return sts;
  1564. }
  1565. static void cq_tasklet_v3_hw(unsigned long val)
  1566. {
  1567. struct hisi_sas_cq *cq = (struct hisi_sas_cq *)val;
  1568. struct hisi_hba *hisi_hba = cq->hisi_hba;
  1569. struct hisi_sas_slot *slot;
  1570. struct hisi_sas_complete_v3_hdr *complete_queue;
  1571. u32 rd_point = cq->rd_point, wr_point;
  1572. int queue = cq->id;
  1573. complete_queue = hisi_hba->complete_hdr[queue];
  1574. wr_point = hisi_sas_read32(hisi_hba, COMPL_Q_0_WR_PTR +
  1575. (0x14 * queue));
  1576. while (rd_point != wr_point) {
  1577. struct hisi_sas_complete_v3_hdr *complete_hdr;
  1578. struct device *dev = hisi_hba->dev;
  1579. u32 dw1;
  1580. int iptt;
  1581. complete_hdr = &complete_queue[rd_point];
  1582. dw1 = le32_to_cpu(complete_hdr->dw1);
  1583. iptt = dw1 & CMPLT_HDR_IPTT_MSK;
  1584. if (likely(iptt < HISI_SAS_COMMAND_ENTRIES_V3_HW)) {
  1585. slot = &hisi_hba->slot_info[iptt];
  1586. slot->cmplt_queue_slot = rd_point;
  1587. slot->cmplt_queue = queue;
  1588. slot_complete_v3_hw(hisi_hba, slot);
  1589. } else
  1590. dev_err(dev, "IPTT %d is invalid, discard it.\n", iptt);
  1591. if (++rd_point >= HISI_SAS_QUEUE_SLOTS)
  1592. rd_point = 0;
  1593. }
  1594. /* update rd_point */
  1595. cq->rd_point = rd_point;
  1596. hisi_sas_write32(hisi_hba, COMPL_Q_0_RD_PTR + (0x14 * queue), rd_point);
  1597. }
  1598. static irqreturn_t cq_interrupt_v3_hw(int irq_no, void *p)
  1599. {
  1600. struct hisi_sas_cq *cq = p;
  1601. struct hisi_hba *hisi_hba = cq->hisi_hba;
  1602. int queue = cq->id;
  1603. hisi_sas_write32(hisi_hba, OQ_INT_SRC, 1 << queue);
  1604. tasklet_schedule(&cq->tasklet);
  1605. return IRQ_HANDLED;
  1606. }
  1607. static int interrupt_init_v3_hw(struct hisi_hba *hisi_hba)
  1608. {
  1609. struct device *dev = hisi_hba->dev;
  1610. struct pci_dev *pdev = hisi_hba->pci_dev;
  1611. int vectors, rc;
  1612. int i, k;
  1613. int max_msi = HISI_SAS_MSI_COUNT_V3_HW;
  1614. vectors = pci_alloc_irq_vectors(hisi_hba->pci_dev, 1,
  1615. max_msi, PCI_IRQ_MSI);
  1616. if (vectors < max_msi) {
  1617. dev_err(dev, "could not allocate all msi (%d)\n", vectors);
  1618. return -ENOENT;
  1619. }
  1620. rc = devm_request_irq(dev, pci_irq_vector(pdev, 1),
  1621. int_phy_up_down_bcast_v3_hw, 0,
  1622. DRV_NAME " phy", hisi_hba);
  1623. if (rc) {
  1624. dev_err(dev, "could not request phy interrupt, rc=%d\n", rc);
  1625. rc = -ENOENT;
  1626. goto free_irq_vectors;
  1627. }
  1628. rc = devm_request_irq(dev, pci_irq_vector(pdev, 2),
  1629. int_chnl_int_v3_hw, 0,
  1630. DRV_NAME " channel", hisi_hba);
  1631. if (rc) {
  1632. dev_err(dev, "could not request chnl interrupt, rc=%d\n", rc);
  1633. rc = -ENOENT;
  1634. goto free_phy_irq;
  1635. }
  1636. rc = devm_request_irq(dev, pci_irq_vector(pdev, 11),
  1637. fatal_axi_int_v3_hw, 0,
  1638. DRV_NAME " fatal", hisi_hba);
  1639. if (rc) {
  1640. dev_err(dev, "could not request fatal interrupt, rc=%d\n", rc);
  1641. rc = -ENOENT;
  1642. goto free_chnl_interrupt;
  1643. }
  1644. /* Init tasklets for cq only */
  1645. for (i = 0; i < hisi_hba->queue_count; i++) {
  1646. struct hisi_sas_cq *cq = &hisi_hba->cq[i];
  1647. struct tasklet_struct *t = &cq->tasklet;
  1648. int nr = hisi_sas_intr_conv ? 16 : 16 + i;
  1649. unsigned long irqflags = hisi_sas_intr_conv ? IRQF_SHARED : 0;
  1650. rc = devm_request_irq(dev, pci_irq_vector(pdev, nr),
  1651. cq_interrupt_v3_hw, irqflags,
  1652. DRV_NAME " cq", cq);
  1653. if (rc) {
  1654. dev_err(dev,
  1655. "could not request cq%d interrupt, rc=%d\n",
  1656. i, rc);
  1657. rc = -ENOENT;
  1658. goto free_cq_irqs;
  1659. }
  1660. tasklet_init(t, cq_tasklet_v3_hw, (unsigned long)cq);
  1661. }
  1662. return 0;
  1663. free_cq_irqs:
  1664. for (k = 0; k < i; k++) {
  1665. struct hisi_sas_cq *cq = &hisi_hba->cq[k];
  1666. int nr = hisi_sas_intr_conv ? 16 : 16 + k;
  1667. free_irq(pci_irq_vector(pdev, nr), cq);
  1668. }
  1669. free_irq(pci_irq_vector(pdev, 11), hisi_hba);
  1670. free_chnl_interrupt:
  1671. free_irq(pci_irq_vector(pdev, 2), hisi_hba);
  1672. free_phy_irq:
  1673. free_irq(pci_irq_vector(pdev, 1), hisi_hba);
  1674. free_irq_vectors:
  1675. pci_free_irq_vectors(pdev);
  1676. return rc;
  1677. }
  1678. static int hisi_sas_v3_init(struct hisi_hba *hisi_hba)
  1679. {
  1680. int rc;
  1681. rc = hw_init_v3_hw(hisi_hba);
  1682. if (rc)
  1683. return rc;
  1684. rc = interrupt_init_v3_hw(hisi_hba);
  1685. if (rc)
  1686. return rc;
  1687. return 0;
  1688. }
  1689. static void phy_set_linkrate_v3_hw(struct hisi_hba *hisi_hba, int phy_no,
  1690. struct sas_phy_linkrates *r)
  1691. {
  1692. enum sas_linkrate max = r->maximum_linkrate;
  1693. u32 prog_phy_link_rate = 0x800;
  1694. prog_phy_link_rate |= hisi_sas_get_prog_phy_linkrate_mask(max);
  1695. hisi_sas_phy_write32(hisi_hba, phy_no, PROG_PHY_LINK_RATE,
  1696. prog_phy_link_rate);
  1697. }
  1698. static void interrupt_disable_v3_hw(struct hisi_hba *hisi_hba)
  1699. {
  1700. struct pci_dev *pdev = hisi_hba->pci_dev;
  1701. int i;
  1702. synchronize_irq(pci_irq_vector(pdev, 1));
  1703. synchronize_irq(pci_irq_vector(pdev, 2));
  1704. synchronize_irq(pci_irq_vector(pdev, 11));
  1705. for (i = 0; i < hisi_hba->queue_count; i++) {
  1706. hisi_sas_write32(hisi_hba, OQ0_INT_SRC_MSK + 0x4 * i, 0x1);
  1707. synchronize_irq(pci_irq_vector(pdev, i + 16));
  1708. }
  1709. hisi_sas_write32(hisi_hba, ENT_INT_SRC_MSK1, 0xffffffff);
  1710. hisi_sas_write32(hisi_hba, ENT_INT_SRC_MSK2, 0xffffffff);
  1711. hisi_sas_write32(hisi_hba, ENT_INT_SRC_MSK3, 0xffffffff);
  1712. hisi_sas_write32(hisi_hba, SAS_ECC_INTR_MSK, 0xffffffff);
  1713. for (i = 0; i < hisi_hba->n_phy; i++) {
  1714. hisi_sas_phy_write32(hisi_hba, i, CHL_INT1_MSK, 0xffffffff);
  1715. hisi_sas_phy_write32(hisi_hba, i, CHL_INT2_MSK, 0xffffffff);
  1716. hisi_sas_phy_write32(hisi_hba, i, PHYCTRL_NOT_RDY_MSK, 0x1);
  1717. hisi_sas_phy_write32(hisi_hba, i, PHYCTRL_PHY_ENA_MSK, 0x1);
  1718. hisi_sas_phy_write32(hisi_hba, i, SL_RX_BCAST_CHK_MSK, 0x1);
  1719. }
  1720. }
  1721. static u32 get_phys_state_v3_hw(struct hisi_hba *hisi_hba)
  1722. {
  1723. return hisi_sas_read32(hisi_hba, PHY_STATE);
  1724. }
  1725. static void phy_get_events_v3_hw(struct hisi_hba *hisi_hba, int phy_no)
  1726. {
  1727. struct hisi_sas_phy *phy = &hisi_hba->phy[phy_no];
  1728. struct asd_sas_phy *sas_phy = &phy->sas_phy;
  1729. struct sas_phy *sphy = sas_phy->phy;
  1730. u32 reg_value;
  1731. /* loss dword sync */
  1732. reg_value = hisi_sas_phy_read32(hisi_hba, phy_no, ERR_CNT_DWS_LOST);
  1733. sphy->loss_of_dword_sync_count += reg_value;
  1734. /* phy reset problem */
  1735. reg_value = hisi_sas_phy_read32(hisi_hba, phy_no, ERR_CNT_RESET_PROB);
  1736. sphy->phy_reset_problem_count += reg_value;
  1737. /* invalid dword */
  1738. reg_value = hisi_sas_phy_read32(hisi_hba, phy_no, ERR_CNT_INVLD_DW);
  1739. sphy->invalid_dword_count += reg_value;
  1740. /* disparity err */
  1741. reg_value = hisi_sas_phy_read32(hisi_hba, phy_no, ERR_CNT_DISP_ERR);
  1742. sphy->running_disparity_error_count += reg_value;
  1743. }
  1744. static int disable_host_v3_hw(struct hisi_hba *hisi_hba)
  1745. {
  1746. struct device *dev = hisi_hba->dev;
  1747. u32 status, reg_val;
  1748. int rc;
  1749. interrupt_disable_v3_hw(hisi_hba);
  1750. hisi_sas_write32(hisi_hba, DLVRY_QUEUE_ENABLE, 0x0);
  1751. hisi_sas_kill_tasklets(hisi_hba);
  1752. hisi_sas_stop_phys(hisi_hba);
  1753. mdelay(10);
  1754. reg_val = hisi_sas_read32(hisi_hba, AXI_MASTER_CFG_BASE +
  1755. AM_CTRL_GLOBAL);
  1756. reg_val |= AM_CTRL_SHUTDOWN_REQ_MSK;
  1757. hisi_sas_write32(hisi_hba, AXI_MASTER_CFG_BASE +
  1758. AM_CTRL_GLOBAL, reg_val);
  1759. /* wait until bus idle */
  1760. rc = hisi_sas_read32_poll_timeout(AXI_MASTER_CFG_BASE +
  1761. AM_CURR_TRANS_RETURN, status,
  1762. status == 0x3, 10, 100);
  1763. if (rc) {
  1764. dev_err(dev, "axi bus is not idle, rc=%d\n", rc);
  1765. return rc;
  1766. }
  1767. return 0;
  1768. }
  1769. static int soft_reset_v3_hw(struct hisi_hba *hisi_hba)
  1770. {
  1771. struct device *dev = hisi_hba->dev;
  1772. int rc;
  1773. rc = disable_host_v3_hw(hisi_hba);
  1774. if (rc) {
  1775. dev_err(dev, "soft reset: disable host failed rc=%d\n", rc);
  1776. return rc;
  1777. }
  1778. hisi_sas_init_mem(hisi_hba);
  1779. return hw_init_v3_hw(hisi_hba);
  1780. }
  1781. static int write_gpio_v3_hw(struct hisi_hba *hisi_hba, u8 reg_type,
  1782. u8 reg_index, u8 reg_count, u8 *write_data)
  1783. {
  1784. struct device *dev = hisi_hba->dev;
  1785. u32 *data = (u32 *)write_data;
  1786. int i;
  1787. switch (reg_type) {
  1788. case SAS_GPIO_REG_TX:
  1789. if ((reg_index + reg_count) > ((hisi_hba->n_phy + 3) / 4)) {
  1790. dev_err(dev, "write gpio: invalid reg range[%d, %d]\n",
  1791. reg_index, reg_index + reg_count - 1);
  1792. return -EINVAL;
  1793. }
  1794. for (i = 0; i < reg_count; i++)
  1795. hisi_sas_write32(hisi_hba,
  1796. SAS_GPIO_TX_0_1 + (reg_index + i) * 4,
  1797. data[i]);
  1798. break;
  1799. default:
  1800. dev_err(dev, "write gpio: unsupported or bad reg type %d\n",
  1801. reg_type);
  1802. return -EINVAL;
  1803. }
  1804. return 0;
  1805. }
  1806. static void wait_cmds_complete_timeout_v3_hw(struct hisi_hba *hisi_hba,
  1807. int delay_ms, int timeout_ms)
  1808. {
  1809. struct device *dev = hisi_hba->dev;
  1810. int entries, entries_old = 0, time;
  1811. for (time = 0; time < timeout_ms; time += delay_ms) {
  1812. entries = hisi_sas_read32(hisi_hba, CQE_SEND_CNT);
  1813. if (entries == entries_old)
  1814. break;
  1815. entries_old = entries;
  1816. msleep(delay_ms);
  1817. }
  1818. dev_dbg(dev, "wait commands complete %dms\n", time);
  1819. }
  1820. static ssize_t intr_conv_v3_hw_show(struct device *dev,
  1821. struct device_attribute *attr, char *buf)
  1822. {
  1823. return scnprintf(buf, PAGE_SIZE, "%u\n", hisi_sas_intr_conv);
  1824. }
  1825. static DEVICE_ATTR_RO(intr_conv_v3_hw);
  1826. static void config_intr_coal_v3_hw(struct hisi_hba *hisi_hba)
  1827. {
  1828. /* config those registers between enable and disable PHYs */
  1829. hisi_sas_stop_phys(hisi_hba);
  1830. if (hisi_hba->intr_coal_ticks == 0 ||
  1831. hisi_hba->intr_coal_count == 0) {
  1832. hisi_sas_write32(hisi_hba, INT_COAL_EN, 0x1);
  1833. hisi_sas_write32(hisi_hba, OQ_INT_COAL_TIME, 0x1);
  1834. hisi_sas_write32(hisi_hba, OQ_INT_COAL_CNT, 0x1);
  1835. } else {
  1836. hisi_sas_write32(hisi_hba, INT_COAL_EN, 0x3);
  1837. hisi_sas_write32(hisi_hba, OQ_INT_COAL_TIME,
  1838. hisi_hba->intr_coal_ticks);
  1839. hisi_sas_write32(hisi_hba, OQ_INT_COAL_CNT,
  1840. hisi_hba->intr_coal_count);
  1841. }
  1842. phys_init_v3_hw(hisi_hba);
  1843. }
  1844. static ssize_t intr_coal_ticks_v3_hw_show(struct device *dev,
  1845. struct device_attribute *attr,
  1846. char *buf)
  1847. {
  1848. struct Scsi_Host *shost = class_to_shost(dev);
  1849. struct hisi_hba *hisi_hba = shost_priv(shost);
  1850. return scnprintf(buf, PAGE_SIZE, "%u\n",
  1851. hisi_hba->intr_coal_ticks);
  1852. }
  1853. static ssize_t intr_coal_ticks_v3_hw_store(struct device *dev,
  1854. struct device_attribute *attr,
  1855. const char *buf, size_t count)
  1856. {
  1857. struct Scsi_Host *shost = class_to_shost(dev);
  1858. struct hisi_hba *hisi_hba = shost_priv(shost);
  1859. u32 intr_coal_ticks;
  1860. int ret;
  1861. ret = kstrtou32(buf, 10, &intr_coal_ticks);
  1862. if (ret) {
  1863. dev_err(dev, "Input data of interrupt coalesce unmatch\n");
  1864. return -EINVAL;
  1865. }
  1866. if (intr_coal_ticks >= BIT(24)) {
  1867. dev_err(dev, "intr_coal_ticks must be less than 2^24!\n");
  1868. return -EINVAL;
  1869. }
  1870. hisi_hba->intr_coal_ticks = intr_coal_ticks;
  1871. config_intr_coal_v3_hw(hisi_hba);
  1872. return count;
  1873. }
  1874. static DEVICE_ATTR_RW(intr_coal_ticks_v3_hw);
  1875. static ssize_t intr_coal_count_v3_hw_show(struct device *dev,
  1876. struct device_attribute
  1877. *attr, char *buf)
  1878. {
  1879. struct Scsi_Host *shost = class_to_shost(dev);
  1880. struct hisi_hba *hisi_hba = shost_priv(shost);
  1881. return scnprintf(buf, PAGE_SIZE, "%u\n",
  1882. hisi_hba->intr_coal_count);
  1883. }
  1884. static ssize_t intr_coal_count_v3_hw_store(struct device *dev,
  1885. struct device_attribute
  1886. *attr, const char *buf, size_t count)
  1887. {
  1888. struct Scsi_Host *shost = class_to_shost(dev);
  1889. struct hisi_hba *hisi_hba = shost_priv(shost);
  1890. u32 intr_coal_count;
  1891. int ret;
  1892. ret = kstrtou32(buf, 10, &intr_coal_count);
  1893. if (ret) {
  1894. dev_err(dev, "Input data of interrupt coalesce unmatch\n");
  1895. return -EINVAL;
  1896. }
  1897. if (intr_coal_count >= BIT(8)) {
  1898. dev_err(dev, "intr_coal_count must be less than 2^8!\n");
  1899. return -EINVAL;
  1900. }
  1901. hisi_hba->intr_coal_count = intr_coal_count;
  1902. config_intr_coal_v3_hw(hisi_hba);
  1903. return count;
  1904. }
  1905. static DEVICE_ATTR_RW(intr_coal_count_v3_hw);
  1906. static struct device_attribute *host_attrs_v3_hw[] = {
  1907. &dev_attr_phy_event_threshold,
  1908. &dev_attr_intr_conv_v3_hw,
  1909. &dev_attr_intr_coal_ticks_v3_hw,
  1910. &dev_attr_intr_coal_count_v3_hw,
  1911. NULL
  1912. };
  1913. static struct scsi_host_template sht_v3_hw = {
  1914. .name = DRV_NAME,
  1915. .module = THIS_MODULE,
  1916. .queuecommand = sas_queuecommand,
  1917. .target_alloc = sas_target_alloc,
  1918. .slave_configure = hisi_sas_slave_configure,
  1919. .scan_finished = hisi_sas_scan_finished,
  1920. .scan_start = hisi_sas_scan_start,
  1921. .change_queue_depth = sas_change_queue_depth,
  1922. .bios_param = sas_bios_param,
  1923. .this_id = -1,
  1924. .sg_tablesize = HISI_SAS_SGE_PAGE_CNT,
  1925. .max_sectors = SCSI_DEFAULT_MAX_SECTORS,
  1926. .use_clustering = ENABLE_CLUSTERING,
  1927. .eh_device_reset_handler = sas_eh_device_reset_handler,
  1928. .eh_target_reset_handler = sas_eh_target_reset_handler,
  1929. .target_destroy = sas_target_destroy,
  1930. .ioctl = sas_ioctl,
  1931. .shost_attrs = host_attrs_v3_hw,
  1932. .tag_alloc_policy = BLK_TAG_ALLOC_RR,
  1933. };
  1934. static const struct hisi_sas_hw hisi_sas_v3_hw = {
  1935. .hw_init = hisi_sas_v3_init,
  1936. .setup_itct = setup_itct_v3_hw,
  1937. .max_command_entries = HISI_SAS_COMMAND_ENTRIES_V3_HW,
  1938. .get_wideport_bitmap = get_wideport_bitmap_v3_hw,
  1939. .complete_hdr_size = sizeof(struct hisi_sas_complete_v3_hdr),
  1940. .clear_itct = clear_itct_v3_hw,
  1941. .sl_notify_ssp = sl_notify_ssp_v3_hw,
  1942. .prep_ssp = prep_ssp_v3_hw,
  1943. .prep_smp = prep_smp_v3_hw,
  1944. .prep_stp = prep_ata_v3_hw,
  1945. .prep_abort = prep_abort_v3_hw,
  1946. .get_free_slot = get_free_slot_v3_hw,
  1947. .start_delivery = start_delivery_v3_hw,
  1948. .slot_complete = slot_complete_v3_hw,
  1949. .phys_init = phys_init_v3_hw,
  1950. .phy_start = start_phy_v3_hw,
  1951. .phy_disable = disable_phy_v3_hw,
  1952. .phy_hard_reset = phy_hard_reset_v3_hw,
  1953. .phy_get_max_linkrate = phy_get_max_linkrate_v3_hw,
  1954. .phy_set_linkrate = phy_set_linkrate_v3_hw,
  1955. .dereg_device = dereg_device_v3_hw,
  1956. .soft_reset = soft_reset_v3_hw,
  1957. .get_phys_state = get_phys_state_v3_hw,
  1958. .get_events = phy_get_events_v3_hw,
  1959. .write_gpio = write_gpio_v3_hw,
  1960. .wait_cmds_complete_timeout = wait_cmds_complete_timeout_v3_hw,
  1961. };
  1962. static struct Scsi_Host *
  1963. hisi_sas_shost_alloc_pci(struct pci_dev *pdev)
  1964. {
  1965. struct Scsi_Host *shost;
  1966. struct hisi_hba *hisi_hba;
  1967. struct device *dev = &pdev->dev;
  1968. shost = scsi_host_alloc(&sht_v3_hw, sizeof(*hisi_hba));
  1969. if (!shost) {
  1970. dev_err(dev, "shost alloc failed\n");
  1971. return NULL;
  1972. }
  1973. hisi_hba = shost_priv(shost);
  1974. INIT_WORK(&hisi_hba->rst_work, hisi_sas_rst_work_handler);
  1975. hisi_hba->hw = &hisi_sas_v3_hw;
  1976. hisi_hba->pci_dev = pdev;
  1977. hisi_hba->dev = dev;
  1978. hisi_hba->shost = shost;
  1979. SHOST_TO_SAS_HA(shost) = &hisi_hba->sha;
  1980. timer_setup(&hisi_hba->timer, NULL, 0);
  1981. if (hisi_sas_get_fw_info(hisi_hba) < 0)
  1982. goto err_out;
  1983. if (hisi_sas_alloc(hisi_hba, shost)) {
  1984. hisi_sas_free(hisi_hba);
  1985. goto err_out;
  1986. }
  1987. return shost;
  1988. err_out:
  1989. scsi_host_put(shost);
  1990. dev_err(dev, "shost alloc failed\n");
  1991. return NULL;
  1992. }
  1993. static int
  1994. hisi_sas_v3_probe(struct pci_dev *pdev, const struct pci_device_id *id)
  1995. {
  1996. struct Scsi_Host *shost;
  1997. struct hisi_hba *hisi_hba;
  1998. struct device *dev = &pdev->dev;
  1999. struct asd_sas_phy **arr_phy;
  2000. struct asd_sas_port **arr_port;
  2001. struct sas_ha_struct *sha;
  2002. int rc, phy_nr, port_nr, i;
  2003. rc = pci_enable_device(pdev);
  2004. if (rc)
  2005. goto err_out;
  2006. pci_set_master(pdev);
  2007. rc = pci_request_regions(pdev, DRV_NAME);
  2008. if (rc)
  2009. goto err_out_disable_device;
  2010. rc = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
  2011. if (rc)
  2012. rc = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
  2013. if (rc) {
  2014. dev_err(dev, "No usable DMA addressing method\n");
  2015. rc = -ENODEV;
  2016. goto err_out_regions;
  2017. }
  2018. shost = hisi_sas_shost_alloc_pci(pdev);
  2019. if (!shost) {
  2020. rc = -ENOMEM;
  2021. goto err_out_regions;
  2022. }
  2023. sha = SHOST_TO_SAS_HA(shost);
  2024. hisi_hba = shost_priv(shost);
  2025. dev_set_drvdata(dev, sha);
  2026. hisi_hba->regs = pcim_iomap(pdev, 5, 0);
  2027. if (!hisi_hba->regs) {
  2028. dev_err(dev, "cannot map register.\n");
  2029. rc = -ENOMEM;
  2030. goto err_out_ha;
  2031. }
  2032. phy_nr = port_nr = hisi_hba->n_phy;
  2033. arr_phy = devm_kcalloc(dev, phy_nr, sizeof(void *), GFP_KERNEL);
  2034. arr_port = devm_kcalloc(dev, port_nr, sizeof(void *), GFP_KERNEL);
  2035. if (!arr_phy || !arr_port) {
  2036. rc = -ENOMEM;
  2037. goto err_out_ha;
  2038. }
  2039. sha->sas_phy = arr_phy;
  2040. sha->sas_port = arr_port;
  2041. sha->core.shost = shost;
  2042. sha->lldd_ha = hisi_hba;
  2043. shost->transportt = hisi_sas_stt;
  2044. shost->max_id = HISI_SAS_MAX_DEVICES;
  2045. shost->max_lun = ~0;
  2046. shost->max_channel = 1;
  2047. shost->max_cmd_len = 16;
  2048. shost->can_queue = hisi_hba->hw->max_command_entries -
  2049. HISI_SAS_RESERVED_IPTT_CNT;
  2050. shost->cmd_per_lun = hisi_hba->hw->max_command_entries -
  2051. HISI_SAS_RESERVED_IPTT_CNT;
  2052. sha->sas_ha_name = DRV_NAME;
  2053. sha->dev = dev;
  2054. sha->lldd_module = THIS_MODULE;
  2055. sha->sas_addr = &hisi_hba->sas_addr[0];
  2056. sha->num_phys = hisi_hba->n_phy;
  2057. sha->core.shost = hisi_hba->shost;
  2058. for (i = 0; i < hisi_hba->n_phy; i++) {
  2059. sha->sas_phy[i] = &hisi_hba->phy[i].sas_phy;
  2060. sha->sas_port[i] = &hisi_hba->port[i].sas_port;
  2061. }
  2062. rc = scsi_add_host(shost, dev);
  2063. if (rc)
  2064. goto err_out_ha;
  2065. rc = sas_register_ha(sha);
  2066. if (rc)
  2067. goto err_out_register_ha;
  2068. rc = hisi_hba->hw->hw_init(hisi_hba);
  2069. if (rc)
  2070. goto err_out_register_ha;
  2071. scsi_scan_host(shost);
  2072. return 0;
  2073. err_out_register_ha:
  2074. scsi_remove_host(shost);
  2075. err_out_ha:
  2076. scsi_host_put(shost);
  2077. err_out_regions:
  2078. pci_release_regions(pdev);
  2079. err_out_disable_device:
  2080. pci_disable_device(pdev);
  2081. err_out:
  2082. return rc;
  2083. }
  2084. static void
  2085. hisi_sas_v3_destroy_irqs(struct pci_dev *pdev, struct hisi_hba *hisi_hba)
  2086. {
  2087. int i;
  2088. free_irq(pci_irq_vector(pdev, 1), hisi_hba);
  2089. free_irq(pci_irq_vector(pdev, 2), hisi_hba);
  2090. free_irq(pci_irq_vector(pdev, 11), hisi_hba);
  2091. for (i = 0; i < hisi_hba->queue_count; i++) {
  2092. struct hisi_sas_cq *cq = &hisi_hba->cq[i];
  2093. int nr = hisi_sas_intr_conv ? 16 : 16 + i;
  2094. free_irq(pci_irq_vector(pdev, nr), cq);
  2095. }
  2096. pci_free_irq_vectors(pdev);
  2097. }
  2098. static void hisi_sas_v3_remove(struct pci_dev *pdev)
  2099. {
  2100. struct device *dev = &pdev->dev;
  2101. struct sas_ha_struct *sha = dev_get_drvdata(dev);
  2102. struct hisi_hba *hisi_hba = sha->lldd_ha;
  2103. struct Scsi_Host *shost = sha->core.shost;
  2104. if (timer_pending(&hisi_hba->timer))
  2105. del_timer(&hisi_hba->timer);
  2106. sas_unregister_ha(sha);
  2107. sas_remove_host(sha->core.shost);
  2108. hisi_sas_v3_destroy_irqs(pdev, hisi_hba);
  2109. hisi_sas_kill_tasklets(hisi_hba);
  2110. pci_release_regions(pdev);
  2111. pci_disable_device(pdev);
  2112. hisi_sas_free(hisi_hba);
  2113. scsi_host_put(shost);
  2114. }
  2115. static const struct hisi_sas_hw_error sas_ras_intr0_nfe[] = {
  2116. { .irq_msk = BIT(19), .msg = "HILINK_INT" },
  2117. { .irq_msk = BIT(20), .msg = "HILINK_PLL0_OUT_OF_LOCK" },
  2118. { .irq_msk = BIT(21), .msg = "HILINK_PLL1_OUT_OF_LOCK" },
  2119. { .irq_msk = BIT(22), .msg = "HILINK_LOSS_OF_REFCLK0" },
  2120. { .irq_msk = BIT(23), .msg = "HILINK_LOSS_OF_REFCLK1" },
  2121. { .irq_msk = BIT(24), .msg = "DMAC0_TX_POISON" },
  2122. { .irq_msk = BIT(25), .msg = "DMAC1_TX_POISON" },
  2123. { .irq_msk = BIT(26), .msg = "DMAC2_TX_POISON" },
  2124. { .irq_msk = BIT(27), .msg = "DMAC3_TX_POISON" },
  2125. { .irq_msk = BIT(28), .msg = "DMAC4_TX_POISON" },
  2126. { .irq_msk = BIT(29), .msg = "DMAC5_TX_POISON" },
  2127. { .irq_msk = BIT(30), .msg = "DMAC6_TX_POISON" },
  2128. { .irq_msk = BIT(31), .msg = "DMAC7_TX_POISON" },
  2129. };
  2130. static const struct hisi_sas_hw_error sas_ras_intr1_nfe[] = {
  2131. { .irq_msk = BIT(0), .msg = "RXM_CFG_MEM3_ECC2B_INTR" },
  2132. { .irq_msk = BIT(1), .msg = "RXM_CFG_MEM2_ECC2B_INTR" },
  2133. { .irq_msk = BIT(2), .msg = "RXM_CFG_MEM1_ECC2B_INTR" },
  2134. { .irq_msk = BIT(3), .msg = "RXM_CFG_MEM0_ECC2B_INTR" },
  2135. { .irq_msk = BIT(4), .msg = "HGC_CQE_ECC2B_INTR" },
  2136. { .irq_msk = BIT(5), .msg = "LM_CFG_IOSTL_ECC2B_INTR" },
  2137. { .irq_msk = BIT(6), .msg = "LM_CFG_ITCTL_ECC2B_INTR" },
  2138. { .irq_msk = BIT(7), .msg = "HGC_ITCT_ECC2B_INTR" },
  2139. { .irq_msk = BIT(8), .msg = "HGC_IOST_ECC2B_INTR" },
  2140. { .irq_msk = BIT(9), .msg = "HGC_DQE_ECC2B_INTR" },
  2141. { .irq_msk = BIT(10), .msg = "DMAC0_RAM_ECC2B_INTR" },
  2142. { .irq_msk = BIT(11), .msg = "DMAC1_RAM_ECC2B_INTR" },
  2143. { .irq_msk = BIT(12), .msg = "DMAC2_RAM_ECC2B_INTR" },
  2144. { .irq_msk = BIT(13), .msg = "DMAC3_RAM_ECC2B_INTR" },
  2145. { .irq_msk = BIT(14), .msg = "DMAC4_RAM_ECC2B_INTR" },
  2146. { .irq_msk = BIT(15), .msg = "DMAC5_RAM_ECC2B_INTR" },
  2147. { .irq_msk = BIT(16), .msg = "DMAC6_RAM_ECC2B_INTR" },
  2148. { .irq_msk = BIT(17), .msg = "DMAC7_RAM_ECC2B_INTR" },
  2149. { .irq_msk = BIT(18), .msg = "OOO_RAM_ECC2B_INTR" },
  2150. { .irq_msk = BIT(20), .msg = "HGC_DQE_POISON_INTR" },
  2151. { .irq_msk = BIT(21), .msg = "HGC_IOST_POISON_INTR" },
  2152. { .irq_msk = BIT(22), .msg = "HGC_ITCT_POISON_INTR" },
  2153. { .irq_msk = BIT(23), .msg = "HGC_ITCT_NCQ_POISON_INTR" },
  2154. { .irq_msk = BIT(24), .msg = "DMAC0_RX_POISON" },
  2155. { .irq_msk = BIT(25), .msg = "DMAC1_RX_POISON" },
  2156. { .irq_msk = BIT(26), .msg = "DMAC2_RX_POISON" },
  2157. { .irq_msk = BIT(27), .msg = "DMAC3_RX_POISON" },
  2158. { .irq_msk = BIT(28), .msg = "DMAC4_RX_POISON" },
  2159. { .irq_msk = BIT(29), .msg = "DMAC5_RX_POISON" },
  2160. { .irq_msk = BIT(30), .msg = "DMAC6_RX_POISON" },
  2161. { .irq_msk = BIT(31), .msg = "DMAC7_RX_POISON" },
  2162. };
  2163. static const struct hisi_sas_hw_error sas_ras_intr2_nfe[] = {
  2164. { .irq_msk = BIT(0), .msg = "DMAC0_AXI_BUS_ERR" },
  2165. { .irq_msk = BIT(1), .msg = "DMAC1_AXI_BUS_ERR" },
  2166. { .irq_msk = BIT(2), .msg = "DMAC2_AXI_BUS_ERR" },
  2167. { .irq_msk = BIT(3), .msg = "DMAC3_AXI_BUS_ERR" },
  2168. { .irq_msk = BIT(4), .msg = "DMAC4_AXI_BUS_ERR" },
  2169. { .irq_msk = BIT(5), .msg = "DMAC5_AXI_BUS_ERR" },
  2170. { .irq_msk = BIT(6), .msg = "DMAC6_AXI_BUS_ERR" },
  2171. { .irq_msk = BIT(7), .msg = "DMAC7_AXI_BUS_ERR" },
  2172. { .irq_msk = BIT(8), .msg = "DMAC0_FIFO_OMIT_ERR" },
  2173. { .irq_msk = BIT(9), .msg = "DMAC1_FIFO_OMIT_ERR" },
  2174. { .irq_msk = BIT(10), .msg = "DMAC2_FIFO_OMIT_ERR" },
  2175. { .irq_msk = BIT(11), .msg = "DMAC3_FIFO_OMIT_ERR" },
  2176. { .irq_msk = BIT(12), .msg = "DMAC4_FIFO_OMIT_ERR" },
  2177. { .irq_msk = BIT(13), .msg = "DMAC5_FIFO_OMIT_ERR" },
  2178. { .irq_msk = BIT(14), .msg = "DMAC6_FIFO_OMIT_ERR" },
  2179. { .irq_msk = BIT(15), .msg = "DMAC7_FIFO_OMIT_ERR" },
  2180. { .irq_msk = BIT(16), .msg = "HGC_RLSE_SLOT_UNMATCH" },
  2181. { .irq_msk = BIT(17), .msg = "HGC_LM_ADD_FCH_LIST_ERR" },
  2182. { .irq_msk = BIT(18), .msg = "HGC_AXI_BUS_ERR" },
  2183. { .irq_msk = BIT(19), .msg = "HGC_FIFO_OMIT_ERR" },
  2184. };
  2185. static bool process_non_fatal_error_v3_hw(struct hisi_hba *hisi_hba)
  2186. {
  2187. struct device *dev = hisi_hba->dev;
  2188. const struct hisi_sas_hw_error *ras_error;
  2189. bool need_reset = false;
  2190. u32 irq_value;
  2191. int i;
  2192. irq_value = hisi_sas_read32(hisi_hba, SAS_RAS_INTR0);
  2193. for (i = 0; i < ARRAY_SIZE(sas_ras_intr0_nfe); i++) {
  2194. ras_error = &sas_ras_intr0_nfe[i];
  2195. if (ras_error->irq_msk & irq_value) {
  2196. dev_warn(dev, "SAS_RAS_INTR0: %s(irq_value=0x%x) found.\n",
  2197. ras_error->msg, irq_value);
  2198. need_reset = true;
  2199. }
  2200. }
  2201. hisi_sas_write32(hisi_hba, SAS_RAS_INTR0, irq_value);
  2202. irq_value = hisi_sas_read32(hisi_hba, SAS_RAS_INTR1);
  2203. for (i = 0; i < ARRAY_SIZE(sas_ras_intr1_nfe); i++) {
  2204. ras_error = &sas_ras_intr1_nfe[i];
  2205. if (ras_error->irq_msk & irq_value) {
  2206. dev_warn(dev, "SAS_RAS_INTR1: %s(irq_value=0x%x) found.\n",
  2207. ras_error->msg, irq_value);
  2208. need_reset = true;
  2209. }
  2210. }
  2211. hisi_sas_write32(hisi_hba, SAS_RAS_INTR1, irq_value);
  2212. irq_value = hisi_sas_read32(hisi_hba, SAS_RAS_INTR2);
  2213. for (i = 0; i < ARRAY_SIZE(sas_ras_intr2_nfe); i++) {
  2214. ras_error = &sas_ras_intr2_nfe[i];
  2215. if (ras_error->irq_msk & irq_value) {
  2216. dev_warn(dev, "SAS_RAS_INTR2: %s(irq_value=0x%x) found.\n",
  2217. ras_error->msg, irq_value);
  2218. need_reset = true;
  2219. }
  2220. }
  2221. hisi_sas_write32(hisi_hba, SAS_RAS_INTR2, irq_value);
  2222. return need_reset;
  2223. }
  2224. static pci_ers_result_t hisi_sas_error_detected_v3_hw(struct pci_dev *pdev,
  2225. pci_channel_state_t state)
  2226. {
  2227. struct sas_ha_struct *sha = pci_get_drvdata(pdev);
  2228. struct hisi_hba *hisi_hba = sha->lldd_ha;
  2229. struct device *dev = hisi_hba->dev;
  2230. dev_info(dev, "PCI error: detected callback, state(%d)!!\n", state);
  2231. if (state == pci_channel_io_perm_failure)
  2232. return PCI_ERS_RESULT_DISCONNECT;
  2233. if (process_non_fatal_error_v3_hw(hisi_hba))
  2234. return PCI_ERS_RESULT_NEED_RESET;
  2235. return PCI_ERS_RESULT_CAN_RECOVER;
  2236. }
  2237. static pci_ers_result_t hisi_sas_mmio_enabled_v3_hw(struct pci_dev *pdev)
  2238. {
  2239. return PCI_ERS_RESULT_RECOVERED;
  2240. }
  2241. static pci_ers_result_t hisi_sas_slot_reset_v3_hw(struct pci_dev *pdev)
  2242. {
  2243. struct sas_ha_struct *sha = pci_get_drvdata(pdev);
  2244. struct hisi_hba *hisi_hba = sha->lldd_ha;
  2245. struct device *dev = hisi_hba->dev;
  2246. HISI_SAS_DECLARE_RST_WORK_ON_STACK(r);
  2247. dev_info(dev, "PCI error: slot reset callback!!\n");
  2248. queue_work(hisi_hba->wq, &r.work);
  2249. wait_for_completion(r.completion);
  2250. if (r.done)
  2251. return PCI_ERS_RESULT_RECOVERED;
  2252. return PCI_ERS_RESULT_DISCONNECT;
  2253. }
  2254. static void hisi_sas_reset_prepare_v3_hw(struct pci_dev *pdev)
  2255. {
  2256. struct sas_ha_struct *sha = pci_get_drvdata(pdev);
  2257. struct hisi_hba *hisi_hba = sha->lldd_ha;
  2258. struct device *dev = hisi_hba->dev;
  2259. int rc;
  2260. dev_info(dev, "FLR prepare\n");
  2261. set_bit(HISI_SAS_RESET_BIT, &hisi_hba->flags);
  2262. hisi_sas_controller_reset_prepare(hisi_hba);
  2263. rc = disable_host_v3_hw(hisi_hba);
  2264. if (rc)
  2265. dev_err(dev, "FLR: disable host failed rc=%d\n", rc);
  2266. }
  2267. static void hisi_sas_reset_done_v3_hw(struct pci_dev *pdev)
  2268. {
  2269. struct sas_ha_struct *sha = pci_get_drvdata(pdev);
  2270. struct hisi_hba *hisi_hba = sha->lldd_ha;
  2271. struct device *dev = hisi_hba->dev;
  2272. int rc;
  2273. hisi_sas_init_mem(hisi_hba);
  2274. rc = hw_init_v3_hw(hisi_hba);
  2275. if (rc) {
  2276. dev_err(dev, "FLR: hw init failed rc=%d\n", rc);
  2277. return;
  2278. }
  2279. hisi_sas_controller_reset_done(hisi_hba);
  2280. dev_info(dev, "FLR done\n");
  2281. }
  2282. enum {
  2283. /* instances of the controller */
  2284. hip08,
  2285. };
  2286. static int hisi_sas_v3_suspend(struct pci_dev *pdev, pm_message_t state)
  2287. {
  2288. struct sas_ha_struct *sha = pci_get_drvdata(pdev);
  2289. struct hisi_hba *hisi_hba = sha->lldd_ha;
  2290. struct device *dev = hisi_hba->dev;
  2291. struct Scsi_Host *shost = hisi_hba->shost;
  2292. pci_power_t device_state;
  2293. int rc;
  2294. if (!pdev->pm_cap) {
  2295. dev_err(dev, "PCI PM not supported\n");
  2296. return -ENODEV;
  2297. }
  2298. if (test_and_set_bit(HISI_SAS_RESET_BIT, &hisi_hba->flags))
  2299. return -1;
  2300. scsi_block_requests(shost);
  2301. set_bit(HISI_SAS_REJECT_CMD_BIT, &hisi_hba->flags);
  2302. flush_workqueue(hisi_hba->wq);
  2303. rc = disable_host_v3_hw(hisi_hba);
  2304. if (rc) {
  2305. dev_err(dev, "PM suspend: disable host failed rc=%d\n", rc);
  2306. clear_bit(HISI_SAS_REJECT_CMD_BIT, &hisi_hba->flags);
  2307. clear_bit(HISI_SAS_RESET_BIT, &hisi_hba->flags);
  2308. scsi_unblock_requests(shost);
  2309. return rc;
  2310. }
  2311. hisi_sas_init_mem(hisi_hba);
  2312. device_state = pci_choose_state(pdev, state);
  2313. dev_warn(dev, "entering operating state [D%d]\n",
  2314. device_state);
  2315. pci_save_state(pdev);
  2316. pci_disable_device(pdev);
  2317. pci_set_power_state(pdev, device_state);
  2318. hisi_sas_release_tasks(hisi_hba);
  2319. sas_suspend_ha(sha);
  2320. return 0;
  2321. }
  2322. static int hisi_sas_v3_resume(struct pci_dev *pdev)
  2323. {
  2324. struct sas_ha_struct *sha = pci_get_drvdata(pdev);
  2325. struct hisi_hba *hisi_hba = sha->lldd_ha;
  2326. struct Scsi_Host *shost = hisi_hba->shost;
  2327. struct device *dev = hisi_hba->dev;
  2328. unsigned int rc;
  2329. pci_power_t device_state = pdev->current_state;
  2330. dev_warn(dev, "resuming from operating state [D%d]\n",
  2331. device_state);
  2332. pci_set_power_state(pdev, PCI_D0);
  2333. pci_enable_wake(pdev, PCI_D0, 0);
  2334. pci_restore_state(pdev);
  2335. rc = pci_enable_device(pdev);
  2336. if (rc)
  2337. dev_err(dev, "enable device failed during resume (%d)\n", rc);
  2338. pci_set_master(pdev);
  2339. scsi_unblock_requests(shost);
  2340. clear_bit(HISI_SAS_REJECT_CMD_BIT, &hisi_hba->flags);
  2341. sas_prep_resume_ha(sha);
  2342. init_reg_v3_hw(hisi_hba);
  2343. hisi_hba->hw->phys_init(hisi_hba);
  2344. sas_resume_ha(sha);
  2345. clear_bit(HISI_SAS_RESET_BIT, &hisi_hba->flags);
  2346. return 0;
  2347. }
  2348. static const struct pci_device_id sas_v3_pci_table[] = {
  2349. { PCI_VDEVICE(HUAWEI, 0xa230), hip08 },
  2350. {}
  2351. };
  2352. MODULE_DEVICE_TABLE(pci, sas_v3_pci_table);
  2353. static const struct pci_error_handlers hisi_sas_err_handler = {
  2354. .error_detected = hisi_sas_error_detected_v3_hw,
  2355. .mmio_enabled = hisi_sas_mmio_enabled_v3_hw,
  2356. .slot_reset = hisi_sas_slot_reset_v3_hw,
  2357. .reset_prepare = hisi_sas_reset_prepare_v3_hw,
  2358. .reset_done = hisi_sas_reset_done_v3_hw,
  2359. };
  2360. static struct pci_driver sas_v3_pci_driver = {
  2361. .name = DRV_NAME,
  2362. .id_table = sas_v3_pci_table,
  2363. .probe = hisi_sas_v3_probe,
  2364. .remove = hisi_sas_v3_remove,
  2365. .suspend = hisi_sas_v3_suspend,
  2366. .resume = hisi_sas_v3_resume,
  2367. .err_handler = &hisi_sas_err_handler,
  2368. };
  2369. module_pci_driver(sas_v3_pci_driver);
  2370. module_param_named(intr_conv, hisi_sas_intr_conv, bool, 0444);
  2371. MODULE_LICENSE("GPL");
  2372. MODULE_AUTHOR("John Garry <john.garry@huawei.com>");
  2373. MODULE_DESCRIPTION("HISILICON SAS controller v3 hw driver based on pci device");
  2374. MODULE_ALIAS("pci:" DRV_NAME);