hisi_sas_v2_hw.c 107 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661
  1. /*
  2. * Copyright (c) 2016 Linaro Ltd.
  3. * Copyright (c) 2016 Hisilicon Limited.
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. */
  11. #include "hisi_sas.h"
  12. #define DRV_NAME "hisi_sas_v2_hw"
  13. /* global registers need init*/
  14. #define DLVRY_QUEUE_ENABLE 0x0
  15. #define IOST_BASE_ADDR_LO 0x8
  16. #define IOST_BASE_ADDR_HI 0xc
  17. #define ITCT_BASE_ADDR_LO 0x10
  18. #define ITCT_BASE_ADDR_HI 0x14
  19. #define IO_BROKEN_MSG_ADDR_LO 0x18
  20. #define IO_BROKEN_MSG_ADDR_HI 0x1c
  21. #define PHY_CONTEXT 0x20
  22. #define PHY_STATE 0x24
  23. #define PHY_PORT_NUM_MA 0x28
  24. #define PORT_STATE 0x2c
  25. #define PORT_STATE_PHY8_PORT_NUM_OFF 16
  26. #define PORT_STATE_PHY8_PORT_NUM_MSK (0xf << PORT_STATE_PHY8_PORT_NUM_OFF)
  27. #define PORT_STATE_PHY8_CONN_RATE_OFF 20
  28. #define PORT_STATE_PHY8_CONN_RATE_MSK (0xf << PORT_STATE_PHY8_CONN_RATE_OFF)
  29. #define PHY_CONN_RATE 0x30
  30. #define HGC_TRANS_TASK_CNT_LIMIT 0x38
  31. #define AXI_AHB_CLK_CFG 0x3c
  32. #define ITCT_CLR 0x44
  33. #define ITCT_CLR_EN_OFF 16
  34. #define ITCT_CLR_EN_MSK (0x1 << ITCT_CLR_EN_OFF)
  35. #define ITCT_DEV_OFF 0
  36. #define ITCT_DEV_MSK (0x7ff << ITCT_DEV_OFF)
  37. #define AXI_USER1 0x48
  38. #define AXI_USER2 0x4c
  39. #define IO_SATA_BROKEN_MSG_ADDR_LO 0x58
  40. #define IO_SATA_BROKEN_MSG_ADDR_HI 0x5c
  41. #define SATA_INITI_D2H_STORE_ADDR_LO 0x60
  42. #define SATA_INITI_D2H_STORE_ADDR_HI 0x64
  43. #define HGC_SAS_TX_OPEN_FAIL_RETRY_CTRL 0x84
  44. #define HGC_SAS_TXFAIL_RETRY_CTRL 0x88
  45. #define HGC_GET_ITV_TIME 0x90
  46. #define DEVICE_MSG_WORK_MODE 0x94
  47. #define OPENA_WT_CONTI_TIME 0x9c
  48. #define I_T_NEXUS_LOSS_TIME 0xa0
  49. #define MAX_CON_TIME_LIMIT_TIME 0xa4
  50. #define BUS_INACTIVE_LIMIT_TIME 0xa8
  51. #define REJECT_TO_OPEN_LIMIT_TIME 0xac
  52. #define CFG_AGING_TIME 0xbc
  53. #define HGC_DFX_CFG2 0xc0
  54. #define HGC_IOMB_PROC1_STATUS 0x104
  55. #define CFG_1US_TIMER_TRSH 0xcc
  56. #define HGC_LM_DFX_STATUS2 0x128
  57. #define HGC_LM_DFX_STATUS2_IOSTLIST_OFF 0
  58. #define HGC_LM_DFX_STATUS2_IOSTLIST_MSK (0xfff << \
  59. HGC_LM_DFX_STATUS2_IOSTLIST_OFF)
  60. #define HGC_LM_DFX_STATUS2_ITCTLIST_OFF 12
  61. #define HGC_LM_DFX_STATUS2_ITCTLIST_MSK (0x7ff << \
  62. HGC_LM_DFX_STATUS2_ITCTLIST_OFF)
  63. #define HGC_CQE_ECC_ADDR 0x13c
  64. #define HGC_CQE_ECC_1B_ADDR_OFF 0
  65. #define HGC_CQE_ECC_1B_ADDR_MSK (0x3f << HGC_CQE_ECC_1B_ADDR_OFF)
  66. #define HGC_CQE_ECC_MB_ADDR_OFF 8
  67. #define HGC_CQE_ECC_MB_ADDR_MSK (0x3f << HGC_CQE_ECC_MB_ADDR_OFF)
  68. #define HGC_IOST_ECC_ADDR 0x140
  69. #define HGC_IOST_ECC_1B_ADDR_OFF 0
  70. #define HGC_IOST_ECC_1B_ADDR_MSK (0x3ff << HGC_IOST_ECC_1B_ADDR_OFF)
  71. #define HGC_IOST_ECC_MB_ADDR_OFF 16
  72. #define HGC_IOST_ECC_MB_ADDR_MSK (0x3ff << HGC_IOST_ECC_MB_ADDR_OFF)
  73. #define HGC_DQE_ECC_ADDR 0x144
  74. #define HGC_DQE_ECC_1B_ADDR_OFF 0
  75. #define HGC_DQE_ECC_1B_ADDR_MSK (0xfff << HGC_DQE_ECC_1B_ADDR_OFF)
  76. #define HGC_DQE_ECC_MB_ADDR_OFF 16
  77. #define HGC_DQE_ECC_MB_ADDR_MSK (0xfff << HGC_DQE_ECC_MB_ADDR_OFF)
  78. #define HGC_INVLD_DQE_INFO 0x148
  79. #define HGC_INVLD_DQE_INFO_FB_CH0_OFF 9
  80. #define HGC_INVLD_DQE_INFO_FB_CH0_MSK (0x1 << HGC_INVLD_DQE_INFO_FB_CH0_OFF)
  81. #define HGC_INVLD_DQE_INFO_FB_CH3_OFF 18
  82. #define HGC_ITCT_ECC_ADDR 0x150
  83. #define HGC_ITCT_ECC_1B_ADDR_OFF 0
  84. #define HGC_ITCT_ECC_1B_ADDR_MSK (0x3ff << \
  85. HGC_ITCT_ECC_1B_ADDR_OFF)
  86. #define HGC_ITCT_ECC_MB_ADDR_OFF 16
  87. #define HGC_ITCT_ECC_MB_ADDR_MSK (0x3ff << \
  88. HGC_ITCT_ECC_MB_ADDR_OFF)
  89. #define HGC_AXI_FIFO_ERR_INFO 0x154
  90. #define AXI_ERR_INFO_OFF 0
  91. #define AXI_ERR_INFO_MSK (0xff << AXI_ERR_INFO_OFF)
  92. #define FIFO_ERR_INFO_OFF 8
  93. #define FIFO_ERR_INFO_MSK (0xff << FIFO_ERR_INFO_OFF)
  94. #define INT_COAL_EN 0x19c
  95. #define OQ_INT_COAL_TIME 0x1a0
  96. #define OQ_INT_COAL_CNT 0x1a4
  97. #define ENT_INT_COAL_TIME 0x1a8
  98. #define ENT_INT_COAL_CNT 0x1ac
  99. #define OQ_INT_SRC 0x1b0
  100. #define OQ_INT_SRC_MSK 0x1b4
  101. #define ENT_INT_SRC1 0x1b8
  102. #define ENT_INT_SRC1_D2H_FIS_CH0_OFF 0
  103. #define ENT_INT_SRC1_D2H_FIS_CH0_MSK (0x1 << ENT_INT_SRC1_D2H_FIS_CH0_OFF)
  104. #define ENT_INT_SRC1_D2H_FIS_CH1_OFF 8
  105. #define ENT_INT_SRC1_D2H_FIS_CH1_MSK (0x1 << ENT_INT_SRC1_D2H_FIS_CH1_OFF)
  106. #define ENT_INT_SRC2 0x1bc
  107. #define ENT_INT_SRC3 0x1c0
  108. #define ENT_INT_SRC3_WP_DEPTH_OFF 8
  109. #define ENT_INT_SRC3_IPTT_SLOT_NOMATCH_OFF 9
  110. #define ENT_INT_SRC3_RP_DEPTH_OFF 10
  111. #define ENT_INT_SRC3_AXI_OFF 11
  112. #define ENT_INT_SRC3_FIFO_OFF 12
  113. #define ENT_INT_SRC3_LM_OFF 14
  114. #define ENT_INT_SRC3_ITC_INT_OFF 15
  115. #define ENT_INT_SRC3_ITC_INT_MSK (0x1 << ENT_INT_SRC3_ITC_INT_OFF)
  116. #define ENT_INT_SRC3_ABT_OFF 16
  117. #define ENT_INT_SRC_MSK1 0x1c4
  118. #define ENT_INT_SRC_MSK2 0x1c8
  119. #define ENT_INT_SRC_MSK3 0x1cc
  120. #define ENT_INT_SRC_MSK3_ENT95_MSK_OFF 31
  121. #define ENT_INT_SRC_MSK3_ENT95_MSK_MSK (0x1 << ENT_INT_SRC_MSK3_ENT95_MSK_OFF)
  122. #define SAS_ECC_INTR 0x1e8
  123. #define SAS_ECC_INTR_DQE_ECC_1B_OFF 0
  124. #define SAS_ECC_INTR_DQE_ECC_MB_OFF 1
  125. #define SAS_ECC_INTR_IOST_ECC_1B_OFF 2
  126. #define SAS_ECC_INTR_IOST_ECC_MB_OFF 3
  127. #define SAS_ECC_INTR_ITCT_ECC_MB_OFF 4
  128. #define SAS_ECC_INTR_ITCT_ECC_1B_OFF 5
  129. #define SAS_ECC_INTR_IOSTLIST_ECC_MB_OFF 6
  130. #define SAS_ECC_INTR_IOSTLIST_ECC_1B_OFF 7
  131. #define SAS_ECC_INTR_ITCTLIST_ECC_1B_OFF 8
  132. #define SAS_ECC_INTR_ITCTLIST_ECC_MB_OFF 9
  133. #define SAS_ECC_INTR_CQE_ECC_1B_OFF 10
  134. #define SAS_ECC_INTR_CQE_ECC_MB_OFF 11
  135. #define SAS_ECC_INTR_NCQ_MEM0_ECC_MB_OFF 12
  136. #define SAS_ECC_INTR_NCQ_MEM0_ECC_1B_OFF 13
  137. #define SAS_ECC_INTR_NCQ_MEM1_ECC_MB_OFF 14
  138. #define SAS_ECC_INTR_NCQ_MEM1_ECC_1B_OFF 15
  139. #define SAS_ECC_INTR_NCQ_MEM2_ECC_MB_OFF 16
  140. #define SAS_ECC_INTR_NCQ_MEM2_ECC_1B_OFF 17
  141. #define SAS_ECC_INTR_NCQ_MEM3_ECC_MB_OFF 18
  142. #define SAS_ECC_INTR_NCQ_MEM3_ECC_1B_OFF 19
  143. #define SAS_ECC_INTR_MSK 0x1ec
  144. #define HGC_ERR_STAT_EN 0x238
  145. #define CQE_SEND_CNT 0x248
  146. #define DLVRY_Q_0_BASE_ADDR_LO 0x260
  147. #define DLVRY_Q_0_BASE_ADDR_HI 0x264
  148. #define DLVRY_Q_0_DEPTH 0x268
  149. #define DLVRY_Q_0_WR_PTR 0x26c
  150. #define DLVRY_Q_0_RD_PTR 0x270
  151. #define HYPER_STREAM_ID_EN_CFG 0xc80
  152. #define OQ0_INT_SRC_MSK 0xc90
  153. #define COMPL_Q_0_BASE_ADDR_LO 0x4e0
  154. #define COMPL_Q_0_BASE_ADDR_HI 0x4e4
  155. #define COMPL_Q_0_DEPTH 0x4e8
  156. #define COMPL_Q_0_WR_PTR 0x4ec
  157. #define COMPL_Q_0_RD_PTR 0x4f0
  158. #define HGC_RXM_DFX_STATUS14 0xae8
  159. #define HGC_RXM_DFX_STATUS14_MEM0_OFF 0
  160. #define HGC_RXM_DFX_STATUS14_MEM0_MSK (0x1ff << \
  161. HGC_RXM_DFX_STATUS14_MEM0_OFF)
  162. #define HGC_RXM_DFX_STATUS14_MEM1_OFF 9
  163. #define HGC_RXM_DFX_STATUS14_MEM1_MSK (0x1ff << \
  164. HGC_RXM_DFX_STATUS14_MEM1_OFF)
  165. #define HGC_RXM_DFX_STATUS14_MEM2_OFF 18
  166. #define HGC_RXM_DFX_STATUS14_MEM2_MSK (0x1ff << \
  167. HGC_RXM_DFX_STATUS14_MEM2_OFF)
  168. #define HGC_RXM_DFX_STATUS15 0xaec
  169. #define HGC_RXM_DFX_STATUS15_MEM3_OFF 0
  170. #define HGC_RXM_DFX_STATUS15_MEM3_MSK (0x1ff << \
  171. HGC_RXM_DFX_STATUS15_MEM3_OFF)
  172. /* phy registers need init */
  173. #define PORT_BASE (0x2000)
  174. #define PHY_CFG (PORT_BASE + 0x0)
  175. #define HARD_PHY_LINKRATE (PORT_BASE + 0x4)
  176. #define PHY_CFG_ENA_OFF 0
  177. #define PHY_CFG_ENA_MSK (0x1 << PHY_CFG_ENA_OFF)
  178. #define PHY_CFG_DC_OPT_OFF 2
  179. #define PHY_CFG_DC_OPT_MSK (0x1 << PHY_CFG_DC_OPT_OFF)
  180. #define PROG_PHY_LINK_RATE (PORT_BASE + 0x8)
  181. #define PROG_PHY_LINK_RATE_MAX_OFF 0
  182. #define PROG_PHY_LINK_RATE_MAX_MSK (0xff << PROG_PHY_LINK_RATE_MAX_OFF)
  183. #define PHY_CTRL (PORT_BASE + 0x14)
  184. #define PHY_CTRL_RESET_OFF 0
  185. #define PHY_CTRL_RESET_MSK (0x1 << PHY_CTRL_RESET_OFF)
  186. #define SAS_PHY_CTRL (PORT_BASE + 0x20)
  187. #define SL_CFG (PORT_BASE + 0x84)
  188. #define PHY_PCN (PORT_BASE + 0x44)
  189. #define SL_TOUT_CFG (PORT_BASE + 0x8c)
  190. #define SL_CONTROL (PORT_BASE + 0x94)
  191. #define SL_CONTROL_NOTIFY_EN_OFF 0
  192. #define SL_CONTROL_NOTIFY_EN_MSK (0x1 << SL_CONTROL_NOTIFY_EN_OFF)
  193. #define SL_CONTROL_CTA_OFF 17
  194. #define SL_CONTROL_CTA_MSK (0x1 << SL_CONTROL_CTA_OFF)
  195. #define RX_PRIMS_STATUS (PORT_BASE + 0x98)
  196. #define RX_BCAST_CHG_OFF 1
  197. #define RX_BCAST_CHG_MSK (0x1 << RX_BCAST_CHG_OFF)
  198. #define TX_ID_DWORD0 (PORT_BASE + 0x9c)
  199. #define TX_ID_DWORD1 (PORT_BASE + 0xa0)
  200. #define TX_ID_DWORD2 (PORT_BASE + 0xa4)
  201. #define TX_ID_DWORD3 (PORT_BASE + 0xa8)
  202. #define TX_ID_DWORD4 (PORT_BASE + 0xaC)
  203. #define TX_ID_DWORD5 (PORT_BASE + 0xb0)
  204. #define TX_ID_DWORD6 (PORT_BASE + 0xb4)
  205. #define TXID_AUTO (PORT_BASE + 0xb8)
  206. #define TXID_AUTO_CT3_OFF 1
  207. #define TXID_AUTO_CT3_MSK (0x1 << TXID_AUTO_CT3_OFF)
  208. #define TXID_AUTO_CTB_OFF 11
  209. #define TXID_AUTO_CTB_MSK (0x1 << TXID_AUTO_CTB_OFF)
  210. #define TX_HARDRST_OFF 2
  211. #define TX_HARDRST_MSK (0x1 << TX_HARDRST_OFF)
  212. #define RX_IDAF_DWORD0 (PORT_BASE + 0xc4)
  213. #define RX_IDAF_DWORD1 (PORT_BASE + 0xc8)
  214. #define RX_IDAF_DWORD2 (PORT_BASE + 0xcc)
  215. #define RX_IDAF_DWORD3 (PORT_BASE + 0xd0)
  216. #define RX_IDAF_DWORD4 (PORT_BASE + 0xd4)
  217. #define RX_IDAF_DWORD5 (PORT_BASE + 0xd8)
  218. #define RX_IDAF_DWORD6 (PORT_BASE + 0xdc)
  219. #define RXOP_CHECK_CFG_H (PORT_BASE + 0xfc)
  220. #define CON_CONTROL (PORT_BASE + 0x118)
  221. #define CON_CONTROL_CFG_OPEN_ACC_STP_OFF 0
  222. #define CON_CONTROL_CFG_OPEN_ACC_STP_MSK \
  223. (0x01 << CON_CONTROL_CFG_OPEN_ACC_STP_OFF)
  224. #define DONE_RECEIVED_TIME (PORT_BASE + 0x11c)
  225. #define CHL_INT0 (PORT_BASE + 0x1b4)
  226. #define CHL_INT0_HOTPLUG_TOUT_OFF 0
  227. #define CHL_INT0_HOTPLUG_TOUT_MSK (0x1 << CHL_INT0_HOTPLUG_TOUT_OFF)
  228. #define CHL_INT0_SL_RX_BCST_ACK_OFF 1
  229. #define CHL_INT0_SL_RX_BCST_ACK_MSK (0x1 << CHL_INT0_SL_RX_BCST_ACK_OFF)
  230. #define CHL_INT0_SL_PHY_ENABLE_OFF 2
  231. #define CHL_INT0_SL_PHY_ENABLE_MSK (0x1 << CHL_INT0_SL_PHY_ENABLE_OFF)
  232. #define CHL_INT0_NOT_RDY_OFF 4
  233. #define CHL_INT0_NOT_RDY_MSK (0x1 << CHL_INT0_NOT_RDY_OFF)
  234. #define CHL_INT0_PHY_RDY_OFF 5
  235. #define CHL_INT0_PHY_RDY_MSK (0x1 << CHL_INT0_PHY_RDY_OFF)
  236. #define CHL_INT1 (PORT_BASE + 0x1b8)
  237. #define CHL_INT1_DMAC_TX_ECC_ERR_OFF 15
  238. #define CHL_INT1_DMAC_TX_ECC_ERR_MSK (0x1 << CHL_INT1_DMAC_TX_ECC_ERR_OFF)
  239. #define CHL_INT1_DMAC_RX_ECC_ERR_OFF 17
  240. #define CHL_INT1_DMAC_RX_ECC_ERR_MSK (0x1 << CHL_INT1_DMAC_RX_ECC_ERR_OFF)
  241. #define CHL_INT1_DMAC_TX_AXI_WR_ERR_OFF 19
  242. #define CHL_INT1_DMAC_TX_AXI_RD_ERR_OFF 20
  243. #define CHL_INT1_DMAC_RX_AXI_WR_ERR_OFF 21
  244. #define CHL_INT1_DMAC_RX_AXI_RD_ERR_OFF 22
  245. #define CHL_INT2 (PORT_BASE + 0x1bc)
  246. #define CHL_INT2_SL_IDAF_TOUT_CONF_OFF 0
  247. #define CHL_INT0_MSK (PORT_BASE + 0x1c0)
  248. #define CHL_INT1_MSK (PORT_BASE + 0x1c4)
  249. #define CHL_INT2_MSK (PORT_BASE + 0x1c8)
  250. #define CHL_INT_COAL_EN (PORT_BASE + 0x1d0)
  251. #define DMA_TX_DFX0 (PORT_BASE + 0x200)
  252. #define DMA_TX_DFX1 (PORT_BASE + 0x204)
  253. #define DMA_TX_DFX1_IPTT_OFF 0
  254. #define DMA_TX_DFX1_IPTT_MSK (0xffff << DMA_TX_DFX1_IPTT_OFF)
  255. #define DMA_TX_FIFO_DFX0 (PORT_BASE + 0x240)
  256. #define PORT_DFX0 (PORT_BASE + 0x258)
  257. #define LINK_DFX2 (PORT_BASE + 0X264)
  258. #define LINK_DFX2_RCVR_HOLD_STS_OFF 9
  259. #define LINK_DFX2_RCVR_HOLD_STS_MSK (0x1 << LINK_DFX2_RCVR_HOLD_STS_OFF)
  260. #define LINK_DFX2_SEND_HOLD_STS_OFF 10
  261. #define LINK_DFX2_SEND_HOLD_STS_MSK (0x1 << LINK_DFX2_SEND_HOLD_STS_OFF)
  262. #define SAS_ERR_CNT4_REG (PORT_BASE + 0x290)
  263. #define SAS_ERR_CNT6_REG (PORT_BASE + 0x298)
  264. #define PHY_CTRL_RDY_MSK (PORT_BASE + 0x2b0)
  265. #define PHYCTRL_NOT_RDY_MSK (PORT_BASE + 0x2b4)
  266. #define PHYCTRL_DWS_RESET_MSK (PORT_BASE + 0x2b8)
  267. #define PHYCTRL_PHY_ENA_MSK (PORT_BASE + 0x2bc)
  268. #define SL_RX_BCAST_CHK_MSK (PORT_BASE + 0x2c0)
  269. #define PHYCTRL_OOB_RESTART_MSK (PORT_BASE + 0x2c4)
  270. #define DMA_TX_STATUS (PORT_BASE + 0x2d0)
  271. #define DMA_TX_STATUS_BUSY_OFF 0
  272. #define DMA_TX_STATUS_BUSY_MSK (0x1 << DMA_TX_STATUS_BUSY_OFF)
  273. #define DMA_RX_STATUS (PORT_BASE + 0x2e8)
  274. #define DMA_RX_STATUS_BUSY_OFF 0
  275. #define DMA_RX_STATUS_BUSY_MSK (0x1 << DMA_RX_STATUS_BUSY_OFF)
  276. #define AXI_CFG (0x5100)
  277. #define AM_CFG_MAX_TRANS (0x5010)
  278. #define AM_CFG_SINGLE_PORT_MAX_TRANS (0x5014)
  279. #define AXI_MASTER_CFG_BASE (0x5000)
  280. #define AM_CTRL_GLOBAL (0x0)
  281. #define AM_CURR_TRANS_RETURN (0x150)
  282. /* HW dma structures */
  283. /* Delivery queue header */
  284. /* dw0 */
  285. #define CMD_HDR_ABORT_FLAG_OFF 0
  286. #define CMD_HDR_ABORT_FLAG_MSK (0x3 << CMD_HDR_ABORT_FLAG_OFF)
  287. #define CMD_HDR_ABORT_DEVICE_TYPE_OFF 2
  288. #define CMD_HDR_ABORT_DEVICE_TYPE_MSK (0x1 << CMD_HDR_ABORT_DEVICE_TYPE_OFF)
  289. #define CMD_HDR_RESP_REPORT_OFF 5
  290. #define CMD_HDR_RESP_REPORT_MSK (0x1 << CMD_HDR_RESP_REPORT_OFF)
  291. #define CMD_HDR_TLR_CTRL_OFF 6
  292. #define CMD_HDR_TLR_CTRL_MSK (0x3 << CMD_HDR_TLR_CTRL_OFF)
  293. #define CMD_HDR_PHY_ID_OFF 8
  294. #define CMD_HDR_PHY_ID_MSK (0x1ff << CMD_HDR_PHY_ID_OFF)
  295. #define CMD_HDR_FORCE_PHY_OFF 17
  296. #define CMD_HDR_FORCE_PHY_MSK (0x1 << CMD_HDR_FORCE_PHY_OFF)
  297. #define CMD_HDR_PORT_OFF 18
  298. #define CMD_HDR_PORT_MSK (0xf << CMD_HDR_PORT_OFF)
  299. #define CMD_HDR_PRIORITY_OFF 27
  300. #define CMD_HDR_PRIORITY_MSK (0x1 << CMD_HDR_PRIORITY_OFF)
  301. #define CMD_HDR_CMD_OFF 29
  302. #define CMD_HDR_CMD_MSK (0x7 << CMD_HDR_CMD_OFF)
  303. /* dw1 */
  304. #define CMD_HDR_DIR_OFF 5
  305. #define CMD_HDR_DIR_MSK (0x3 << CMD_HDR_DIR_OFF)
  306. #define CMD_HDR_RESET_OFF 7
  307. #define CMD_HDR_RESET_MSK (0x1 << CMD_HDR_RESET_OFF)
  308. #define CMD_HDR_VDTL_OFF 10
  309. #define CMD_HDR_VDTL_MSK (0x1 << CMD_HDR_VDTL_OFF)
  310. #define CMD_HDR_FRAME_TYPE_OFF 11
  311. #define CMD_HDR_FRAME_TYPE_MSK (0x1f << CMD_HDR_FRAME_TYPE_OFF)
  312. #define CMD_HDR_DEV_ID_OFF 16
  313. #define CMD_HDR_DEV_ID_MSK (0xffff << CMD_HDR_DEV_ID_OFF)
  314. /* dw2 */
  315. #define CMD_HDR_CFL_OFF 0
  316. #define CMD_HDR_CFL_MSK (0x1ff << CMD_HDR_CFL_OFF)
  317. #define CMD_HDR_NCQ_TAG_OFF 10
  318. #define CMD_HDR_NCQ_TAG_MSK (0x1f << CMD_HDR_NCQ_TAG_OFF)
  319. #define CMD_HDR_MRFL_OFF 15
  320. #define CMD_HDR_MRFL_MSK (0x1ff << CMD_HDR_MRFL_OFF)
  321. #define CMD_HDR_SG_MOD_OFF 24
  322. #define CMD_HDR_SG_MOD_MSK (0x3 << CMD_HDR_SG_MOD_OFF)
  323. #define CMD_HDR_FIRST_BURST_OFF 26
  324. #define CMD_HDR_FIRST_BURST_MSK (0x1 << CMD_HDR_SG_MOD_OFF)
  325. /* dw3 */
  326. #define CMD_HDR_IPTT_OFF 0
  327. #define CMD_HDR_IPTT_MSK (0xffff << CMD_HDR_IPTT_OFF)
  328. /* dw6 */
  329. #define CMD_HDR_DIF_SGL_LEN_OFF 0
  330. #define CMD_HDR_DIF_SGL_LEN_MSK (0xffff << CMD_HDR_DIF_SGL_LEN_OFF)
  331. #define CMD_HDR_DATA_SGL_LEN_OFF 16
  332. #define CMD_HDR_DATA_SGL_LEN_MSK (0xffff << CMD_HDR_DATA_SGL_LEN_OFF)
  333. #define CMD_HDR_ABORT_IPTT_OFF 16
  334. #define CMD_HDR_ABORT_IPTT_MSK (0xffff << CMD_HDR_ABORT_IPTT_OFF)
  335. /* Completion header */
  336. /* dw0 */
  337. #define CMPLT_HDR_ERR_PHASE_OFF 2
  338. #define CMPLT_HDR_ERR_PHASE_MSK (0xff << CMPLT_HDR_ERR_PHASE_OFF)
  339. #define CMPLT_HDR_RSPNS_XFRD_OFF 10
  340. #define CMPLT_HDR_RSPNS_XFRD_MSK (0x1 << CMPLT_HDR_RSPNS_XFRD_OFF)
  341. #define CMPLT_HDR_ERX_OFF 12
  342. #define CMPLT_HDR_ERX_MSK (0x1 << CMPLT_HDR_ERX_OFF)
  343. #define CMPLT_HDR_ABORT_STAT_OFF 13
  344. #define CMPLT_HDR_ABORT_STAT_MSK (0x7 << CMPLT_HDR_ABORT_STAT_OFF)
  345. /* abort_stat */
  346. #define STAT_IO_NOT_VALID 0x1
  347. #define STAT_IO_NO_DEVICE 0x2
  348. #define STAT_IO_COMPLETE 0x3
  349. #define STAT_IO_ABORTED 0x4
  350. /* dw1 */
  351. #define CMPLT_HDR_IPTT_OFF 0
  352. #define CMPLT_HDR_IPTT_MSK (0xffff << CMPLT_HDR_IPTT_OFF)
  353. #define CMPLT_HDR_DEV_ID_OFF 16
  354. #define CMPLT_HDR_DEV_ID_MSK (0xffff << CMPLT_HDR_DEV_ID_OFF)
  355. /* ITCT header */
  356. /* qw0 */
  357. #define ITCT_HDR_DEV_TYPE_OFF 0
  358. #define ITCT_HDR_DEV_TYPE_MSK (0x3 << ITCT_HDR_DEV_TYPE_OFF)
  359. #define ITCT_HDR_VALID_OFF 2
  360. #define ITCT_HDR_VALID_MSK (0x1 << ITCT_HDR_VALID_OFF)
  361. #define ITCT_HDR_MCR_OFF 5
  362. #define ITCT_HDR_MCR_MSK (0xf << ITCT_HDR_MCR_OFF)
  363. #define ITCT_HDR_VLN_OFF 9
  364. #define ITCT_HDR_VLN_MSK (0xf << ITCT_HDR_VLN_OFF)
  365. #define ITCT_HDR_SMP_TIMEOUT_OFF 16
  366. #define ITCT_HDR_SMP_TIMEOUT_8US 1
  367. #define ITCT_HDR_SMP_TIMEOUT (ITCT_HDR_SMP_TIMEOUT_8US * \
  368. 250) /* 2ms */
  369. #define ITCT_HDR_AWT_CONTINUE_OFF 25
  370. #define ITCT_HDR_PORT_ID_OFF 28
  371. #define ITCT_HDR_PORT_ID_MSK (0xf << ITCT_HDR_PORT_ID_OFF)
  372. /* qw2 */
  373. #define ITCT_HDR_INLT_OFF 0
  374. #define ITCT_HDR_INLT_MSK (0xffffULL << ITCT_HDR_INLT_OFF)
  375. #define ITCT_HDR_BITLT_OFF 16
  376. #define ITCT_HDR_BITLT_MSK (0xffffULL << ITCT_HDR_BITLT_OFF)
  377. #define ITCT_HDR_MCTLT_OFF 32
  378. #define ITCT_HDR_MCTLT_MSK (0xffffULL << ITCT_HDR_MCTLT_OFF)
  379. #define ITCT_HDR_RTOLT_OFF 48
  380. #define ITCT_HDR_RTOLT_MSK (0xffffULL << ITCT_HDR_RTOLT_OFF)
  381. #define HISI_SAS_FATAL_INT_NR 2
  382. struct hisi_sas_complete_v2_hdr {
  383. __le32 dw0;
  384. __le32 dw1;
  385. __le32 act;
  386. __le32 dw3;
  387. };
  388. struct hisi_sas_err_record_v2 {
  389. /* dw0 */
  390. __le32 trans_tx_fail_type;
  391. /* dw1 */
  392. __le32 trans_rx_fail_type;
  393. /* dw2 */
  394. __le16 dma_tx_err_type;
  395. __le16 sipc_rx_err_type;
  396. /* dw3 */
  397. __le32 dma_rx_err_type;
  398. };
  399. struct signal_attenuation_s {
  400. u32 de_emphasis;
  401. u32 preshoot;
  402. u32 boost;
  403. };
  404. struct sig_atten_lu_s {
  405. const struct signal_attenuation_s *att;
  406. u32 sas_phy_ctrl;
  407. };
  408. static const struct hisi_sas_hw_error one_bit_ecc_errors[] = {
  409. {
  410. .irq_msk = BIT(SAS_ECC_INTR_DQE_ECC_1B_OFF),
  411. .msk = HGC_DQE_ECC_1B_ADDR_MSK,
  412. .shift = HGC_DQE_ECC_1B_ADDR_OFF,
  413. .msg = "hgc_dqe_acc1b_intr found: Ram address is 0x%08X\n",
  414. .reg = HGC_DQE_ECC_ADDR,
  415. },
  416. {
  417. .irq_msk = BIT(SAS_ECC_INTR_IOST_ECC_1B_OFF),
  418. .msk = HGC_IOST_ECC_1B_ADDR_MSK,
  419. .shift = HGC_IOST_ECC_1B_ADDR_OFF,
  420. .msg = "hgc_iost_acc1b_intr found: Ram address is 0x%08X\n",
  421. .reg = HGC_IOST_ECC_ADDR,
  422. },
  423. {
  424. .irq_msk = BIT(SAS_ECC_INTR_ITCT_ECC_1B_OFF),
  425. .msk = HGC_ITCT_ECC_1B_ADDR_MSK,
  426. .shift = HGC_ITCT_ECC_1B_ADDR_OFF,
  427. .msg = "hgc_itct_acc1b_intr found: am address is 0x%08X\n",
  428. .reg = HGC_ITCT_ECC_ADDR,
  429. },
  430. {
  431. .irq_msk = BIT(SAS_ECC_INTR_IOSTLIST_ECC_1B_OFF),
  432. .msk = HGC_LM_DFX_STATUS2_IOSTLIST_MSK,
  433. .shift = HGC_LM_DFX_STATUS2_IOSTLIST_OFF,
  434. .msg = "hgc_iostl_acc1b_intr found: memory address is 0x%08X\n",
  435. .reg = HGC_LM_DFX_STATUS2,
  436. },
  437. {
  438. .irq_msk = BIT(SAS_ECC_INTR_ITCTLIST_ECC_1B_OFF),
  439. .msk = HGC_LM_DFX_STATUS2_ITCTLIST_MSK,
  440. .shift = HGC_LM_DFX_STATUS2_ITCTLIST_OFF,
  441. .msg = "hgc_itctl_acc1b_intr found: memory address is 0x%08X\n",
  442. .reg = HGC_LM_DFX_STATUS2,
  443. },
  444. {
  445. .irq_msk = BIT(SAS_ECC_INTR_CQE_ECC_1B_OFF),
  446. .msk = HGC_CQE_ECC_1B_ADDR_MSK,
  447. .shift = HGC_CQE_ECC_1B_ADDR_OFF,
  448. .msg = "hgc_cqe_acc1b_intr found: Ram address is 0x%08X\n",
  449. .reg = HGC_CQE_ECC_ADDR,
  450. },
  451. {
  452. .irq_msk = BIT(SAS_ECC_INTR_NCQ_MEM0_ECC_1B_OFF),
  453. .msk = HGC_RXM_DFX_STATUS14_MEM0_MSK,
  454. .shift = HGC_RXM_DFX_STATUS14_MEM0_OFF,
  455. .msg = "rxm_mem0_acc1b_intr found: memory address is 0x%08X\n",
  456. .reg = HGC_RXM_DFX_STATUS14,
  457. },
  458. {
  459. .irq_msk = BIT(SAS_ECC_INTR_NCQ_MEM1_ECC_1B_OFF),
  460. .msk = HGC_RXM_DFX_STATUS14_MEM1_MSK,
  461. .shift = HGC_RXM_DFX_STATUS14_MEM1_OFF,
  462. .msg = "rxm_mem1_acc1b_intr found: memory address is 0x%08X\n",
  463. .reg = HGC_RXM_DFX_STATUS14,
  464. },
  465. {
  466. .irq_msk = BIT(SAS_ECC_INTR_NCQ_MEM2_ECC_1B_OFF),
  467. .msk = HGC_RXM_DFX_STATUS14_MEM2_MSK,
  468. .shift = HGC_RXM_DFX_STATUS14_MEM2_OFF,
  469. .msg = "rxm_mem2_acc1b_intr found: memory address is 0x%08X\n",
  470. .reg = HGC_RXM_DFX_STATUS14,
  471. },
  472. {
  473. .irq_msk = BIT(SAS_ECC_INTR_NCQ_MEM3_ECC_1B_OFF),
  474. .msk = HGC_RXM_DFX_STATUS15_MEM3_MSK,
  475. .shift = HGC_RXM_DFX_STATUS15_MEM3_OFF,
  476. .msg = "rxm_mem3_acc1b_intr found: memory address is 0x%08X\n",
  477. .reg = HGC_RXM_DFX_STATUS15,
  478. },
  479. };
  480. static const struct hisi_sas_hw_error multi_bit_ecc_errors[] = {
  481. {
  482. .irq_msk = BIT(SAS_ECC_INTR_DQE_ECC_MB_OFF),
  483. .msk = HGC_DQE_ECC_MB_ADDR_MSK,
  484. .shift = HGC_DQE_ECC_MB_ADDR_OFF,
  485. .msg = "hgc_dqe_accbad_intr (0x%x) found: Ram address is 0x%08X\n",
  486. .reg = HGC_DQE_ECC_ADDR,
  487. },
  488. {
  489. .irq_msk = BIT(SAS_ECC_INTR_IOST_ECC_MB_OFF),
  490. .msk = HGC_IOST_ECC_MB_ADDR_MSK,
  491. .shift = HGC_IOST_ECC_MB_ADDR_OFF,
  492. .msg = "hgc_iost_accbad_intr (0x%x) found: Ram address is 0x%08X\n",
  493. .reg = HGC_IOST_ECC_ADDR,
  494. },
  495. {
  496. .irq_msk = BIT(SAS_ECC_INTR_ITCT_ECC_MB_OFF),
  497. .msk = HGC_ITCT_ECC_MB_ADDR_MSK,
  498. .shift = HGC_ITCT_ECC_MB_ADDR_OFF,
  499. .msg = "hgc_itct_accbad_intr (0x%x) found: Ram address is 0x%08X\n",
  500. .reg = HGC_ITCT_ECC_ADDR,
  501. },
  502. {
  503. .irq_msk = BIT(SAS_ECC_INTR_IOSTLIST_ECC_MB_OFF),
  504. .msk = HGC_LM_DFX_STATUS2_IOSTLIST_MSK,
  505. .shift = HGC_LM_DFX_STATUS2_IOSTLIST_OFF,
  506. .msg = "hgc_iostl_accbad_intr (0x%x) found: memory address is 0x%08X\n",
  507. .reg = HGC_LM_DFX_STATUS2,
  508. },
  509. {
  510. .irq_msk = BIT(SAS_ECC_INTR_ITCTLIST_ECC_MB_OFF),
  511. .msk = HGC_LM_DFX_STATUS2_ITCTLIST_MSK,
  512. .shift = HGC_LM_DFX_STATUS2_ITCTLIST_OFF,
  513. .msg = "hgc_itctl_accbad_intr (0x%x) found: memory address is 0x%08X\n",
  514. .reg = HGC_LM_DFX_STATUS2,
  515. },
  516. {
  517. .irq_msk = BIT(SAS_ECC_INTR_CQE_ECC_MB_OFF),
  518. .msk = HGC_CQE_ECC_MB_ADDR_MSK,
  519. .shift = HGC_CQE_ECC_MB_ADDR_OFF,
  520. .msg = "hgc_cqe_accbad_intr (0x%x) found: Ram address is 0x%08X\n",
  521. .reg = HGC_CQE_ECC_ADDR,
  522. },
  523. {
  524. .irq_msk = BIT(SAS_ECC_INTR_NCQ_MEM0_ECC_MB_OFF),
  525. .msk = HGC_RXM_DFX_STATUS14_MEM0_MSK,
  526. .shift = HGC_RXM_DFX_STATUS14_MEM0_OFF,
  527. .msg = "rxm_mem0_accbad_intr (0x%x) found: memory address is 0x%08X\n",
  528. .reg = HGC_RXM_DFX_STATUS14,
  529. },
  530. {
  531. .irq_msk = BIT(SAS_ECC_INTR_NCQ_MEM1_ECC_MB_OFF),
  532. .msk = HGC_RXM_DFX_STATUS14_MEM1_MSK,
  533. .shift = HGC_RXM_DFX_STATUS14_MEM1_OFF,
  534. .msg = "rxm_mem1_accbad_intr (0x%x) found: memory address is 0x%08X\n",
  535. .reg = HGC_RXM_DFX_STATUS14,
  536. },
  537. {
  538. .irq_msk = BIT(SAS_ECC_INTR_NCQ_MEM2_ECC_MB_OFF),
  539. .msk = HGC_RXM_DFX_STATUS14_MEM2_MSK,
  540. .shift = HGC_RXM_DFX_STATUS14_MEM2_OFF,
  541. .msg = "rxm_mem2_accbad_intr (0x%x) found: memory address is 0x%08X\n",
  542. .reg = HGC_RXM_DFX_STATUS14,
  543. },
  544. {
  545. .irq_msk = BIT(SAS_ECC_INTR_NCQ_MEM3_ECC_MB_OFF),
  546. .msk = HGC_RXM_DFX_STATUS15_MEM3_MSK,
  547. .shift = HGC_RXM_DFX_STATUS15_MEM3_OFF,
  548. .msg = "rxm_mem3_accbad_intr (0x%x) found: memory address is 0x%08X\n",
  549. .reg = HGC_RXM_DFX_STATUS15,
  550. },
  551. };
  552. enum {
  553. HISI_SAS_PHY_PHY_UPDOWN,
  554. HISI_SAS_PHY_CHNL_INT,
  555. HISI_SAS_PHY_INT_NR
  556. };
  557. enum {
  558. TRANS_TX_FAIL_BASE = 0x0, /* dw0 */
  559. TRANS_RX_FAIL_BASE = 0x20, /* dw1 */
  560. DMA_TX_ERR_BASE = 0x40, /* dw2 bit 15-0 */
  561. SIPC_RX_ERR_BASE = 0x50, /* dw2 bit 31-16*/
  562. DMA_RX_ERR_BASE = 0x60, /* dw3 */
  563. /* trans tx*/
  564. TRANS_TX_OPEN_FAIL_WITH_IT_NEXUS_LOSS = TRANS_TX_FAIL_BASE, /* 0x0 */
  565. TRANS_TX_ERR_PHY_NOT_ENABLE, /* 0x1 */
  566. TRANS_TX_OPEN_CNX_ERR_WRONG_DESTINATION, /* 0x2 */
  567. TRANS_TX_OPEN_CNX_ERR_ZONE_VIOLATION, /* 0x3 */
  568. TRANS_TX_OPEN_CNX_ERR_BY_OTHER, /* 0x4 */
  569. RESERVED0, /* 0x5 */
  570. TRANS_TX_OPEN_CNX_ERR_AIP_TIMEOUT, /* 0x6 */
  571. TRANS_TX_OPEN_CNX_ERR_STP_RESOURCES_BUSY, /* 0x7 */
  572. TRANS_TX_OPEN_CNX_ERR_PROTOCOL_NOT_SUPPORTED, /* 0x8 */
  573. TRANS_TX_OPEN_CNX_ERR_CONNECTION_RATE_NOT_SUPPORTED, /* 0x9 */
  574. TRANS_TX_OPEN_CNX_ERR_BAD_DESTINATION, /* 0xa */
  575. TRANS_TX_OPEN_CNX_ERR_BREAK_RCVD, /* 0xb */
  576. TRANS_TX_OPEN_CNX_ERR_LOW_PHY_POWER, /* 0xc */
  577. TRANS_TX_OPEN_CNX_ERR_PATHWAY_BLOCKED, /* 0xd */
  578. TRANS_TX_OPEN_CNX_ERR_OPEN_TIMEOUT, /* 0xe */
  579. TRANS_TX_OPEN_CNX_ERR_NO_DESTINATION, /* 0xf */
  580. TRANS_TX_OPEN_RETRY_ERR_THRESHOLD_REACHED, /* 0x10 */
  581. TRANS_TX_ERR_FRAME_TXED, /* 0x11 */
  582. TRANS_TX_ERR_WITH_BREAK_TIMEOUT, /* 0x12 */
  583. TRANS_TX_ERR_WITH_BREAK_REQUEST, /* 0x13 */
  584. TRANS_TX_ERR_WITH_BREAK_RECEVIED, /* 0x14 */
  585. TRANS_TX_ERR_WITH_CLOSE_TIMEOUT, /* 0x15 */
  586. TRANS_TX_ERR_WITH_CLOSE_NORMAL, /* 0x16 for ssp*/
  587. TRANS_TX_ERR_WITH_CLOSE_PHYDISALE, /* 0x17 */
  588. TRANS_TX_ERR_WITH_CLOSE_DWS_TIMEOUT, /* 0x18 */
  589. TRANS_TX_ERR_WITH_CLOSE_COMINIT, /* 0x19 */
  590. TRANS_TX_ERR_WITH_NAK_RECEVIED, /* 0x1a for ssp*/
  591. TRANS_TX_ERR_WITH_ACK_NAK_TIMEOUT, /* 0x1b for ssp*/
  592. /*IO_TX_ERR_WITH_R_ERR_RECEVIED, [> 0x1b for sata/stp<] */
  593. TRANS_TX_ERR_WITH_CREDIT_TIMEOUT, /* 0x1c for ssp */
  594. /*IO_RX_ERR_WITH_SATA_DEVICE_LOST 0x1c for sata/stp */
  595. TRANS_TX_ERR_WITH_IPTT_CONFLICT, /* 0x1d for ssp/smp */
  596. TRANS_TX_ERR_WITH_OPEN_BY_DES_OR_OTHERS, /* 0x1e */
  597. /*IO_TX_ERR_WITH_SYNC_RXD, [> 0x1e <] for sata/stp */
  598. TRANS_TX_ERR_WITH_WAIT_RECV_TIMEOUT, /* 0x1f for sata/stp */
  599. /* trans rx */
  600. TRANS_RX_ERR_WITH_RXFRAME_CRC_ERR = TRANS_RX_FAIL_BASE, /* 0x20 */
  601. TRANS_RX_ERR_WITH_RXFIS_8B10B_DISP_ERR, /* 0x21 for sata/stp */
  602. TRANS_RX_ERR_WITH_RXFRAME_HAVE_ERRPRM, /* 0x22 for ssp/smp */
  603. /*IO_ERR_WITH_RXFIS_8B10B_CODE_ERR, [> 0x22 <] for sata/stp */
  604. TRANS_RX_ERR_WITH_RXFIS_DECODE_ERROR, /* 0x23 for sata/stp */
  605. TRANS_RX_ERR_WITH_RXFIS_CRC_ERR, /* 0x24 for sata/stp */
  606. TRANS_RX_ERR_WITH_RXFRAME_LENGTH_OVERRUN, /* 0x25 for smp */
  607. /*IO_ERR_WITH_RXFIS_TX SYNCP, [> 0x25 <] for sata/stp */
  608. TRANS_RX_ERR_WITH_RXFIS_RX_SYNCP, /* 0x26 for sata/stp*/
  609. TRANS_RX_ERR_WITH_LINK_BUF_OVERRUN, /* 0x27 */
  610. TRANS_RX_ERR_WITH_BREAK_TIMEOUT, /* 0x28 */
  611. TRANS_RX_ERR_WITH_BREAK_REQUEST, /* 0x29 */
  612. TRANS_RX_ERR_WITH_BREAK_RECEVIED, /* 0x2a */
  613. RESERVED1, /* 0x2b */
  614. TRANS_RX_ERR_WITH_CLOSE_NORMAL, /* 0x2c */
  615. TRANS_RX_ERR_WITH_CLOSE_PHY_DISABLE, /* 0x2d */
  616. TRANS_RX_ERR_WITH_CLOSE_DWS_TIMEOUT, /* 0x2e */
  617. TRANS_RX_ERR_WITH_CLOSE_COMINIT, /* 0x2f */
  618. TRANS_RX_ERR_WITH_DATA_LEN0, /* 0x30 for ssp/smp */
  619. TRANS_RX_ERR_WITH_BAD_HASH, /* 0x31 for ssp */
  620. /*IO_RX_ERR_WITH_FIS_TOO_SHORT, [> 0x31 <] for sata/stp */
  621. TRANS_RX_XRDY_WLEN_ZERO_ERR, /* 0x32 for ssp*/
  622. /*IO_RX_ERR_WITH_FIS_TOO_LONG, [> 0x32 <] for sata/stp */
  623. TRANS_RX_SSP_FRM_LEN_ERR, /* 0x33 for ssp */
  624. /*IO_RX_ERR_WITH_SATA_DEVICE_LOST, [> 0x33 <] for sata */
  625. RESERVED2, /* 0x34 */
  626. RESERVED3, /* 0x35 */
  627. RESERVED4, /* 0x36 */
  628. RESERVED5, /* 0x37 */
  629. TRANS_RX_ERR_WITH_BAD_FRM_TYPE, /* 0x38 */
  630. TRANS_RX_SMP_FRM_LEN_ERR, /* 0x39 */
  631. TRANS_RX_SMP_RESP_TIMEOUT_ERR, /* 0x3a */
  632. RESERVED6, /* 0x3b */
  633. RESERVED7, /* 0x3c */
  634. RESERVED8, /* 0x3d */
  635. RESERVED9, /* 0x3e */
  636. TRANS_RX_R_ERR, /* 0x3f */
  637. /* dma tx */
  638. DMA_TX_DIF_CRC_ERR = DMA_TX_ERR_BASE, /* 0x40 */
  639. DMA_TX_DIF_APP_ERR, /* 0x41 */
  640. DMA_TX_DIF_RPP_ERR, /* 0x42 */
  641. DMA_TX_DATA_SGL_OVERFLOW, /* 0x43 */
  642. DMA_TX_DIF_SGL_OVERFLOW, /* 0x44 */
  643. DMA_TX_UNEXP_XFER_ERR, /* 0x45 */
  644. DMA_TX_UNEXP_RETRANS_ERR, /* 0x46 */
  645. DMA_TX_XFER_LEN_OVERFLOW, /* 0x47 */
  646. DMA_TX_XFER_OFFSET_ERR, /* 0x48 */
  647. DMA_TX_RAM_ECC_ERR, /* 0x49 */
  648. DMA_TX_DIF_LEN_ALIGN_ERR, /* 0x4a */
  649. DMA_TX_MAX_ERR_CODE,
  650. /* sipc rx */
  651. SIPC_RX_FIS_STATUS_ERR_BIT_VLD = SIPC_RX_ERR_BASE, /* 0x50 */
  652. SIPC_RX_PIO_WRSETUP_STATUS_DRQ_ERR, /* 0x51 */
  653. SIPC_RX_FIS_STATUS_BSY_BIT_ERR, /* 0x52 */
  654. SIPC_RX_WRSETUP_LEN_ODD_ERR, /* 0x53 */
  655. SIPC_RX_WRSETUP_LEN_ZERO_ERR, /* 0x54 */
  656. SIPC_RX_WRDATA_LEN_NOT_MATCH_ERR, /* 0x55 */
  657. SIPC_RX_NCQ_WRSETUP_OFFSET_ERR, /* 0x56 */
  658. SIPC_RX_NCQ_WRSETUP_AUTO_ACTIVE_ERR, /* 0x57 */
  659. SIPC_RX_SATA_UNEXP_FIS_ERR, /* 0x58 */
  660. SIPC_RX_WRSETUP_ESTATUS_ERR, /* 0x59 */
  661. SIPC_RX_DATA_UNDERFLOW_ERR, /* 0x5a */
  662. SIPC_RX_MAX_ERR_CODE,
  663. /* dma rx */
  664. DMA_RX_DIF_CRC_ERR = DMA_RX_ERR_BASE, /* 0x60 */
  665. DMA_RX_DIF_APP_ERR, /* 0x61 */
  666. DMA_RX_DIF_RPP_ERR, /* 0x62 */
  667. DMA_RX_DATA_SGL_OVERFLOW, /* 0x63 */
  668. DMA_RX_DIF_SGL_OVERFLOW, /* 0x64 */
  669. DMA_RX_DATA_LEN_OVERFLOW, /* 0x65 */
  670. DMA_RX_DATA_LEN_UNDERFLOW, /* 0x66 */
  671. DMA_RX_DATA_OFFSET_ERR, /* 0x67 */
  672. RESERVED10, /* 0x68 */
  673. DMA_RX_SATA_FRAME_TYPE_ERR, /* 0x69 */
  674. DMA_RX_RESP_BUF_OVERFLOW, /* 0x6a */
  675. DMA_RX_UNEXP_RETRANS_RESP_ERR, /* 0x6b */
  676. DMA_RX_UNEXP_NORM_RESP_ERR, /* 0x6c */
  677. DMA_RX_UNEXP_RDFRAME_ERR, /* 0x6d */
  678. DMA_RX_PIO_DATA_LEN_ERR, /* 0x6e */
  679. DMA_RX_RDSETUP_STATUS_ERR, /* 0x6f */
  680. DMA_RX_RDSETUP_STATUS_DRQ_ERR, /* 0x70 */
  681. DMA_RX_RDSETUP_STATUS_BSY_ERR, /* 0x71 */
  682. DMA_RX_RDSETUP_LEN_ODD_ERR, /* 0x72 */
  683. DMA_RX_RDSETUP_LEN_ZERO_ERR, /* 0x73 */
  684. DMA_RX_RDSETUP_LEN_OVER_ERR, /* 0x74 */
  685. DMA_RX_RDSETUP_OFFSET_ERR, /* 0x75 */
  686. DMA_RX_RDSETUP_ACTIVE_ERR, /* 0x76 */
  687. DMA_RX_RDSETUP_ESTATUS_ERR, /* 0x77 */
  688. DMA_RX_RAM_ECC_ERR, /* 0x78 */
  689. DMA_RX_UNKNOWN_FRM_ERR, /* 0x79 */
  690. DMA_RX_MAX_ERR_CODE,
  691. };
  692. #define HISI_SAS_COMMAND_ENTRIES_V2_HW 4096
  693. #define HISI_MAX_SATA_SUPPORT_V2_HW (HISI_SAS_COMMAND_ENTRIES_V2_HW/64 - 1)
  694. #define DIR_NO_DATA 0
  695. #define DIR_TO_INI 1
  696. #define DIR_TO_DEVICE 2
  697. #define DIR_RESERVED 3
  698. #define ERR_ON_TX_PHASE(err_phase) (err_phase == 0x2 || \
  699. err_phase == 0x4 || err_phase == 0x8 ||\
  700. err_phase == 0x6 || err_phase == 0xa)
  701. #define ERR_ON_RX_PHASE(err_phase) (err_phase == 0x10 || \
  702. err_phase == 0x20 || err_phase == 0x40)
  703. static void link_timeout_disable_link(struct timer_list *t);
  704. static u32 hisi_sas_read32(struct hisi_hba *hisi_hba, u32 off)
  705. {
  706. void __iomem *regs = hisi_hba->regs + off;
  707. return readl(regs);
  708. }
  709. static u32 hisi_sas_read32_relaxed(struct hisi_hba *hisi_hba, u32 off)
  710. {
  711. void __iomem *regs = hisi_hba->regs + off;
  712. return readl_relaxed(regs);
  713. }
  714. static void hisi_sas_write32(struct hisi_hba *hisi_hba, u32 off, u32 val)
  715. {
  716. void __iomem *regs = hisi_hba->regs + off;
  717. writel(val, regs);
  718. }
  719. static void hisi_sas_phy_write32(struct hisi_hba *hisi_hba, int phy_no,
  720. u32 off, u32 val)
  721. {
  722. void __iomem *regs = hisi_hba->regs + (0x400 * phy_no) + off;
  723. writel(val, regs);
  724. }
  725. static u32 hisi_sas_phy_read32(struct hisi_hba *hisi_hba,
  726. int phy_no, u32 off)
  727. {
  728. void __iomem *regs = hisi_hba->regs + (0x400 * phy_no) + off;
  729. return readl(regs);
  730. }
  731. /* This function needs to be protected from pre-emption. */
  732. static int
  733. slot_index_alloc_quirk_v2_hw(struct hisi_hba *hisi_hba, int *slot_idx,
  734. struct domain_device *device)
  735. {
  736. int sata_dev = dev_is_sata(device);
  737. void *bitmap = hisi_hba->slot_index_tags;
  738. struct hisi_sas_device *sas_dev = device->lldd_dev;
  739. int sata_idx = sas_dev->sata_idx;
  740. int start, end;
  741. if (!sata_dev) {
  742. /*
  743. * STP link SoC bug workaround: index starts from 1.
  744. * additionally, we can only allocate odd IPTT(1~4095)
  745. * for SAS/SMP device.
  746. */
  747. start = 1;
  748. end = hisi_hba->slot_index_count;
  749. } else {
  750. if (sata_idx >= HISI_MAX_SATA_SUPPORT_V2_HW)
  751. return -EINVAL;
  752. /*
  753. * For SATA device: allocate even IPTT in this interval
  754. * [64*(sata_idx+1), 64*(sata_idx+2)], then each SATA device
  755. * own 32 IPTTs. IPTT 0 shall not be used duing to STP link
  756. * SoC bug workaround. So we ignore the first 32 even IPTTs.
  757. */
  758. start = 64 * (sata_idx + 1);
  759. end = 64 * (sata_idx + 2);
  760. }
  761. while (1) {
  762. start = find_next_zero_bit(bitmap,
  763. hisi_hba->slot_index_count, start);
  764. if (start >= end)
  765. return -SAS_QUEUE_FULL;
  766. /*
  767. * SAS IPTT bit0 should be 1, and SATA IPTT bit0 should be 0.
  768. */
  769. if (sata_dev ^ (start & 1))
  770. break;
  771. start++;
  772. }
  773. set_bit(start, bitmap);
  774. *slot_idx = start;
  775. return 0;
  776. }
  777. static bool sata_index_alloc_v2_hw(struct hisi_hba *hisi_hba, int *idx)
  778. {
  779. unsigned int index;
  780. struct device *dev = hisi_hba->dev;
  781. void *bitmap = hisi_hba->sata_dev_bitmap;
  782. index = find_first_zero_bit(bitmap, HISI_MAX_SATA_SUPPORT_V2_HW);
  783. if (index >= HISI_MAX_SATA_SUPPORT_V2_HW) {
  784. dev_warn(dev, "alloc sata index failed, index=%d\n", index);
  785. return false;
  786. }
  787. set_bit(index, bitmap);
  788. *idx = index;
  789. return true;
  790. }
  791. static struct
  792. hisi_sas_device *alloc_dev_quirk_v2_hw(struct domain_device *device)
  793. {
  794. struct hisi_hba *hisi_hba = device->port->ha->lldd_ha;
  795. struct hisi_sas_device *sas_dev = NULL;
  796. int i, sata_dev = dev_is_sata(device);
  797. int sata_idx = -1;
  798. unsigned long flags;
  799. spin_lock_irqsave(&hisi_hba->lock, flags);
  800. if (sata_dev)
  801. if (!sata_index_alloc_v2_hw(hisi_hba, &sata_idx))
  802. goto out;
  803. for (i = 0; i < HISI_SAS_MAX_DEVICES; i++) {
  804. /*
  805. * SATA device id bit0 should be 0
  806. */
  807. if (sata_dev && (i & 1))
  808. continue;
  809. if (hisi_hba->devices[i].dev_type == SAS_PHY_UNUSED) {
  810. int queue = i % hisi_hba->queue_count;
  811. struct hisi_sas_dq *dq = &hisi_hba->dq[queue];
  812. hisi_hba->devices[i].device_id = i;
  813. sas_dev = &hisi_hba->devices[i];
  814. sas_dev->dev_status = HISI_SAS_DEV_NORMAL;
  815. sas_dev->dev_type = device->dev_type;
  816. sas_dev->hisi_hba = hisi_hba;
  817. sas_dev->sas_device = device;
  818. sas_dev->sata_idx = sata_idx;
  819. sas_dev->dq = dq;
  820. INIT_LIST_HEAD(&hisi_hba->devices[i].list);
  821. break;
  822. }
  823. }
  824. out:
  825. spin_unlock_irqrestore(&hisi_hba->lock, flags);
  826. return sas_dev;
  827. }
  828. static void config_phy_opt_mode_v2_hw(struct hisi_hba *hisi_hba, int phy_no)
  829. {
  830. u32 cfg = hisi_sas_phy_read32(hisi_hba, phy_no, PHY_CFG);
  831. cfg &= ~PHY_CFG_DC_OPT_MSK;
  832. cfg |= 1 << PHY_CFG_DC_OPT_OFF;
  833. hisi_sas_phy_write32(hisi_hba, phy_no, PHY_CFG, cfg);
  834. }
  835. static void config_id_frame_v2_hw(struct hisi_hba *hisi_hba, int phy_no)
  836. {
  837. struct sas_identify_frame identify_frame;
  838. u32 *identify_buffer;
  839. memset(&identify_frame, 0, sizeof(identify_frame));
  840. identify_frame.dev_type = SAS_END_DEVICE;
  841. identify_frame.frame_type = 0;
  842. identify_frame._un1 = 1;
  843. identify_frame.initiator_bits = SAS_PROTOCOL_ALL;
  844. identify_frame.target_bits = SAS_PROTOCOL_NONE;
  845. memcpy(&identify_frame._un4_11[0], hisi_hba->sas_addr, SAS_ADDR_SIZE);
  846. memcpy(&identify_frame.sas_addr[0], hisi_hba->sas_addr, SAS_ADDR_SIZE);
  847. identify_frame.phy_id = phy_no;
  848. identify_buffer = (u32 *)(&identify_frame);
  849. hisi_sas_phy_write32(hisi_hba, phy_no, TX_ID_DWORD0,
  850. __swab32(identify_buffer[0]));
  851. hisi_sas_phy_write32(hisi_hba, phy_no, TX_ID_DWORD1,
  852. __swab32(identify_buffer[1]));
  853. hisi_sas_phy_write32(hisi_hba, phy_no, TX_ID_DWORD2,
  854. __swab32(identify_buffer[2]));
  855. hisi_sas_phy_write32(hisi_hba, phy_no, TX_ID_DWORD3,
  856. __swab32(identify_buffer[3]));
  857. hisi_sas_phy_write32(hisi_hba, phy_no, TX_ID_DWORD4,
  858. __swab32(identify_buffer[4]));
  859. hisi_sas_phy_write32(hisi_hba, phy_no, TX_ID_DWORD5,
  860. __swab32(identify_buffer[5]));
  861. }
  862. static void setup_itct_v2_hw(struct hisi_hba *hisi_hba,
  863. struct hisi_sas_device *sas_dev)
  864. {
  865. struct domain_device *device = sas_dev->sas_device;
  866. struct device *dev = hisi_hba->dev;
  867. u64 qw0, device_id = sas_dev->device_id;
  868. struct hisi_sas_itct *itct = &hisi_hba->itct[device_id];
  869. struct domain_device *parent_dev = device->parent;
  870. struct asd_sas_port *sas_port = device->port;
  871. struct hisi_sas_port *port = to_hisi_sas_port(sas_port);
  872. memset(itct, 0, sizeof(*itct));
  873. /* qw0 */
  874. qw0 = 0;
  875. switch (sas_dev->dev_type) {
  876. case SAS_END_DEVICE:
  877. case SAS_EDGE_EXPANDER_DEVICE:
  878. case SAS_FANOUT_EXPANDER_DEVICE:
  879. qw0 = HISI_SAS_DEV_TYPE_SSP << ITCT_HDR_DEV_TYPE_OFF;
  880. break;
  881. case SAS_SATA_DEV:
  882. case SAS_SATA_PENDING:
  883. if (parent_dev && DEV_IS_EXPANDER(parent_dev->dev_type))
  884. qw0 = HISI_SAS_DEV_TYPE_STP << ITCT_HDR_DEV_TYPE_OFF;
  885. else
  886. qw0 = HISI_SAS_DEV_TYPE_SATA << ITCT_HDR_DEV_TYPE_OFF;
  887. break;
  888. default:
  889. dev_warn(dev, "setup itct: unsupported dev type (%d)\n",
  890. sas_dev->dev_type);
  891. }
  892. qw0 |= ((1 << ITCT_HDR_VALID_OFF) |
  893. (device->linkrate << ITCT_HDR_MCR_OFF) |
  894. (1 << ITCT_HDR_VLN_OFF) |
  895. (ITCT_HDR_SMP_TIMEOUT << ITCT_HDR_SMP_TIMEOUT_OFF) |
  896. (1 << ITCT_HDR_AWT_CONTINUE_OFF) |
  897. (port->id << ITCT_HDR_PORT_ID_OFF));
  898. itct->qw0 = cpu_to_le64(qw0);
  899. /* qw1 */
  900. memcpy(&itct->sas_addr, device->sas_addr, SAS_ADDR_SIZE);
  901. itct->sas_addr = __swab64(itct->sas_addr);
  902. /* qw2 */
  903. if (!dev_is_sata(device))
  904. itct->qw2 = cpu_to_le64((5000ULL << ITCT_HDR_INLT_OFF) |
  905. (0x1ULL << ITCT_HDR_BITLT_OFF) |
  906. (0x32ULL << ITCT_HDR_MCTLT_OFF) |
  907. (0x1ULL << ITCT_HDR_RTOLT_OFF));
  908. }
  909. static void clear_itct_v2_hw(struct hisi_hba *hisi_hba,
  910. struct hisi_sas_device *sas_dev)
  911. {
  912. DECLARE_COMPLETION_ONSTACK(completion);
  913. u64 dev_id = sas_dev->device_id;
  914. struct hisi_sas_itct *itct = &hisi_hba->itct[dev_id];
  915. u32 reg_val = hisi_sas_read32(hisi_hba, ENT_INT_SRC3);
  916. int i;
  917. sas_dev->completion = &completion;
  918. /* clear the itct interrupt state */
  919. if (ENT_INT_SRC3_ITC_INT_MSK & reg_val)
  920. hisi_sas_write32(hisi_hba, ENT_INT_SRC3,
  921. ENT_INT_SRC3_ITC_INT_MSK);
  922. for (i = 0; i < 2; i++) {
  923. reg_val = ITCT_CLR_EN_MSK | (dev_id & ITCT_DEV_MSK);
  924. hisi_sas_write32(hisi_hba, ITCT_CLR, reg_val);
  925. wait_for_completion(sas_dev->completion);
  926. memset(itct, 0, sizeof(struct hisi_sas_itct));
  927. }
  928. }
  929. static void free_device_v2_hw(struct hisi_sas_device *sas_dev)
  930. {
  931. struct hisi_hba *hisi_hba = sas_dev->hisi_hba;
  932. /* SoC bug workaround */
  933. if (dev_is_sata(sas_dev->sas_device))
  934. clear_bit(sas_dev->sata_idx, hisi_hba->sata_dev_bitmap);
  935. }
  936. static int reset_hw_v2_hw(struct hisi_hba *hisi_hba)
  937. {
  938. int i, reset_val;
  939. u32 val;
  940. unsigned long end_time;
  941. struct device *dev = hisi_hba->dev;
  942. /* The mask needs to be set depending on the number of phys */
  943. if (hisi_hba->n_phy == 9)
  944. reset_val = 0x1fffff;
  945. else
  946. reset_val = 0x7ffff;
  947. hisi_sas_write32(hisi_hba, DLVRY_QUEUE_ENABLE, 0);
  948. /* Disable all of the PHYs */
  949. for (i = 0; i < hisi_hba->n_phy; i++) {
  950. u32 phy_cfg = hisi_sas_phy_read32(hisi_hba, i, PHY_CFG);
  951. phy_cfg &= ~PHY_CTRL_RESET_MSK;
  952. hisi_sas_phy_write32(hisi_hba, i, PHY_CFG, phy_cfg);
  953. }
  954. udelay(50);
  955. /* Ensure DMA tx & rx idle */
  956. for (i = 0; i < hisi_hba->n_phy; i++) {
  957. u32 dma_tx_status, dma_rx_status;
  958. end_time = jiffies + msecs_to_jiffies(1000);
  959. while (1) {
  960. dma_tx_status = hisi_sas_phy_read32(hisi_hba, i,
  961. DMA_TX_STATUS);
  962. dma_rx_status = hisi_sas_phy_read32(hisi_hba, i,
  963. DMA_RX_STATUS);
  964. if (!(dma_tx_status & DMA_TX_STATUS_BUSY_MSK) &&
  965. !(dma_rx_status & DMA_RX_STATUS_BUSY_MSK))
  966. break;
  967. msleep(20);
  968. if (time_after(jiffies, end_time))
  969. return -EIO;
  970. }
  971. }
  972. /* Ensure axi bus idle */
  973. end_time = jiffies + msecs_to_jiffies(1000);
  974. while (1) {
  975. u32 axi_status =
  976. hisi_sas_read32(hisi_hba, AXI_CFG);
  977. if (axi_status == 0)
  978. break;
  979. msleep(20);
  980. if (time_after(jiffies, end_time))
  981. return -EIO;
  982. }
  983. if (ACPI_HANDLE(dev)) {
  984. acpi_status s;
  985. s = acpi_evaluate_object(ACPI_HANDLE(dev), "_RST", NULL, NULL);
  986. if (ACPI_FAILURE(s)) {
  987. dev_err(dev, "Reset failed\n");
  988. return -EIO;
  989. }
  990. } else if (hisi_hba->ctrl) {
  991. /* reset and disable clock*/
  992. regmap_write(hisi_hba->ctrl, hisi_hba->ctrl_reset_reg,
  993. reset_val);
  994. regmap_write(hisi_hba->ctrl, hisi_hba->ctrl_clock_ena_reg + 4,
  995. reset_val);
  996. msleep(1);
  997. regmap_read(hisi_hba->ctrl, hisi_hba->ctrl_reset_sts_reg, &val);
  998. if (reset_val != (val & reset_val)) {
  999. dev_err(dev, "SAS reset fail.\n");
  1000. return -EIO;
  1001. }
  1002. /* De-reset and enable clock*/
  1003. regmap_write(hisi_hba->ctrl, hisi_hba->ctrl_reset_reg + 4,
  1004. reset_val);
  1005. regmap_write(hisi_hba->ctrl, hisi_hba->ctrl_clock_ena_reg,
  1006. reset_val);
  1007. msleep(1);
  1008. regmap_read(hisi_hba->ctrl, hisi_hba->ctrl_reset_sts_reg,
  1009. &val);
  1010. if (val & reset_val) {
  1011. dev_err(dev, "SAS de-reset fail.\n");
  1012. return -EIO;
  1013. }
  1014. } else {
  1015. dev_err(dev, "no reset method\n");
  1016. return -EINVAL;
  1017. }
  1018. return 0;
  1019. }
  1020. /* This function needs to be called after resetting SAS controller. */
  1021. static void phys_reject_stp_links_v2_hw(struct hisi_hba *hisi_hba)
  1022. {
  1023. u32 cfg;
  1024. int phy_no;
  1025. hisi_hba->reject_stp_links_msk = (1 << hisi_hba->n_phy) - 1;
  1026. for (phy_no = 0; phy_no < hisi_hba->n_phy; phy_no++) {
  1027. cfg = hisi_sas_phy_read32(hisi_hba, phy_no, CON_CONTROL);
  1028. if (!(cfg & CON_CONTROL_CFG_OPEN_ACC_STP_MSK))
  1029. continue;
  1030. cfg &= ~CON_CONTROL_CFG_OPEN_ACC_STP_MSK;
  1031. hisi_sas_phy_write32(hisi_hba, phy_no, CON_CONTROL, cfg);
  1032. }
  1033. }
  1034. static void phys_try_accept_stp_links_v2_hw(struct hisi_hba *hisi_hba)
  1035. {
  1036. int phy_no;
  1037. u32 dma_tx_dfx1;
  1038. for (phy_no = 0; phy_no < hisi_hba->n_phy; phy_no++) {
  1039. if (!(hisi_hba->reject_stp_links_msk & BIT(phy_no)))
  1040. continue;
  1041. dma_tx_dfx1 = hisi_sas_phy_read32(hisi_hba, phy_no,
  1042. DMA_TX_DFX1);
  1043. if (dma_tx_dfx1 & DMA_TX_DFX1_IPTT_MSK) {
  1044. u32 cfg = hisi_sas_phy_read32(hisi_hba,
  1045. phy_no, CON_CONTROL);
  1046. cfg |= CON_CONTROL_CFG_OPEN_ACC_STP_MSK;
  1047. hisi_sas_phy_write32(hisi_hba, phy_no,
  1048. CON_CONTROL, cfg);
  1049. clear_bit(phy_no, &hisi_hba->reject_stp_links_msk);
  1050. }
  1051. }
  1052. }
  1053. static const struct signal_attenuation_s x6000 = {9200, 0, 10476};
  1054. static const struct sig_atten_lu_s sig_atten_lu[] = {
  1055. { &x6000, 0x3016a68 },
  1056. };
  1057. static void init_reg_v2_hw(struct hisi_hba *hisi_hba)
  1058. {
  1059. struct device *dev = hisi_hba->dev;
  1060. u32 sas_phy_ctrl = 0x30b9908;
  1061. u32 signal[3];
  1062. int i;
  1063. /* Global registers init */
  1064. /* Deal with am-max-transmissions quirk */
  1065. if (device_property_present(dev, "hip06-sas-v2-quirk-amt")) {
  1066. hisi_sas_write32(hisi_hba, AM_CFG_MAX_TRANS, 0x2020);
  1067. hisi_sas_write32(hisi_hba, AM_CFG_SINGLE_PORT_MAX_TRANS,
  1068. 0x2020);
  1069. } /* Else, use defaults -> do nothing */
  1070. hisi_sas_write32(hisi_hba, DLVRY_QUEUE_ENABLE,
  1071. (u32)((1ULL << hisi_hba->queue_count) - 1));
  1072. hisi_sas_write32(hisi_hba, AXI_USER1, 0xc0000000);
  1073. hisi_sas_write32(hisi_hba, AXI_USER2, 0x10000);
  1074. hisi_sas_write32(hisi_hba, HGC_SAS_TXFAIL_RETRY_CTRL, 0x0);
  1075. hisi_sas_write32(hisi_hba, HGC_SAS_TX_OPEN_FAIL_RETRY_CTRL, 0x7FF);
  1076. hisi_sas_write32(hisi_hba, OPENA_WT_CONTI_TIME, 0x1);
  1077. hisi_sas_write32(hisi_hba, I_T_NEXUS_LOSS_TIME, 0x1F4);
  1078. hisi_sas_write32(hisi_hba, MAX_CON_TIME_LIMIT_TIME, 0x32);
  1079. hisi_sas_write32(hisi_hba, BUS_INACTIVE_LIMIT_TIME, 0x1);
  1080. hisi_sas_write32(hisi_hba, CFG_AGING_TIME, 0x1);
  1081. hisi_sas_write32(hisi_hba, HGC_ERR_STAT_EN, 0x1);
  1082. hisi_sas_write32(hisi_hba, HGC_GET_ITV_TIME, 0x1);
  1083. hisi_sas_write32(hisi_hba, INT_COAL_EN, 0xc);
  1084. hisi_sas_write32(hisi_hba, OQ_INT_COAL_TIME, 0x60);
  1085. hisi_sas_write32(hisi_hba, OQ_INT_COAL_CNT, 0x3);
  1086. hisi_sas_write32(hisi_hba, ENT_INT_COAL_TIME, 0x1);
  1087. hisi_sas_write32(hisi_hba, ENT_INT_COAL_CNT, 0x1);
  1088. hisi_sas_write32(hisi_hba, OQ_INT_SRC, 0x0);
  1089. hisi_sas_write32(hisi_hba, ENT_INT_SRC1, 0xffffffff);
  1090. hisi_sas_write32(hisi_hba, ENT_INT_SRC2, 0xffffffff);
  1091. hisi_sas_write32(hisi_hba, ENT_INT_SRC3, 0xffffffff);
  1092. hisi_sas_write32(hisi_hba, ENT_INT_SRC_MSK1, 0x7efefefe);
  1093. hisi_sas_write32(hisi_hba, ENT_INT_SRC_MSK2, 0x7efefefe);
  1094. hisi_sas_write32(hisi_hba, ENT_INT_SRC_MSK3, 0x7ffe20fe);
  1095. hisi_sas_write32(hisi_hba, SAS_ECC_INTR_MSK, 0xfff00c30);
  1096. for (i = 0; i < hisi_hba->queue_count; i++)
  1097. hisi_sas_write32(hisi_hba, OQ0_INT_SRC_MSK+0x4*i, 0);
  1098. hisi_sas_write32(hisi_hba, AXI_AHB_CLK_CFG, 1);
  1099. hisi_sas_write32(hisi_hba, HYPER_STREAM_ID_EN_CFG, 1);
  1100. /* Get sas_phy_ctrl value to deal with TX FFE issue. */
  1101. if (!device_property_read_u32_array(dev, "hisilicon,signal-attenuation",
  1102. signal, ARRAY_SIZE(signal))) {
  1103. for (i = 0; i < ARRAY_SIZE(sig_atten_lu); i++) {
  1104. const struct sig_atten_lu_s *lookup = &sig_atten_lu[i];
  1105. const struct signal_attenuation_s *att = lookup->att;
  1106. if ((signal[0] == att->de_emphasis) &&
  1107. (signal[1] == att->preshoot) &&
  1108. (signal[2] == att->boost)) {
  1109. sas_phy_ctrl = lookup->sas_phy_ctrl;
  1110. break;
  1111. }
  1112. }
  1113. if (i == ARRAY_SIZE(sig_atten_lu))
  1114. dev_warn(dev, "unknown signal attenuation values, using default PHY ctrl config\n");
  1115. }
  1116. for (i = 0; i < hisi_hba->n_phy; i++) {
  1117. struct hisi_sas_phy *phy = &hisi_hba->phy[i];
  1118. struct asd_sas_phy *sas_phy = &phy->sas_phy;
  1119. u32 prog_phy_link_rate = 0x800;
  1120. if (!sas_phy->phy || (sas_phy->phy->maximum_linkrate <
  1121. SAS_LINK_RATE_1_5_GBPS)) {
  1122. prog_phy_link_rate = 0x855;
  1123. } else {
  1124. enum sas_linkrate max = sas_phy->phy->maximum_linkrate;
  1125. prog_phy_link_rate =
  1126. hisi_sas_get_prog_phy_linkrate_mask(max) |
  1127. 0x800;
  1128. }
  1129. hisi_sas_phy_write32(hisi_hba, i, PROG_PHY_LINK_RATE,
  1130. prog_phy_link_rate);
  1131. hisi_sas_phy_write32(hisi_hba, i, SAS_PHY_CTRL, sas_phy_ctrl);
  1132. hisi_sas_phy_write32(hisi_hba, i, SL_TOUT_CFG, 0x7d7d7d7d);
  1133. hisi_sas_phy_write32(hisi_hba, i, SL_CONTROL, 0x0);
  1134. hisi_sas_phy_write32(hisi_hba, i, TXID_AUTO, 0x2);
  1135. hisi_sas_phy_write32(hisi_hba, i, DONE_RECEIVED_TIME, 0x8);
  1136. hisi_sas_phy_write32(hisi_hba, i, CHL_INT0, 0xffffffff);
  1137. hisi_sas_phy_write32(hisi_hba, i, CHL_INT1, 0xffffffff);
  1138. hisi_sas_phy_write32(hisi_hba, i, CHL_INT2, 0xfff87fff);
  1139. hisi_sas_phy_write32(hisi_hba, i, RXOP_CHECK_CFG_H, 0x1000);
  1140. hisi_sas_phy_write32(hisi_hba, i, CHL_INT1_MSK, 0xff857fff);
  1141. hisi_sas_phy_write32(hisi_hba, i, CHL_INT2_MSK, 0x8ffffbfe);
  1142. hisi_sas_phy_write32(hisi_hba, i, SL_CFG, 0x13f801fc);
  1143. hisi_sas_phy_write32(hisi_hba, i, PHY_CTRL_RDY_MSK, 0x0);
  1144. hisi_sas_phy_write32(hisi_hba, i, PHYCTRL_NOT_RDY_MSK, 0x0);
  1145. hisi_sas_phy_write32(hisi_hba, i, PHYCTRL_DWS_RESET_MSK, 0x0);
  1146. hisi_sas_phy_write32(hisi_hba, i, PHYCTRL_PHY_ENA_MSK, 0x0);
  1147. hisi_sas_phy_write32(hisi_hba, i, SL_RX_BCAST_CHK_MSK, 0x0);
  1148. hisi_sas_phy_write32(hisi_hba, i, CHL_INT_COAL_EN, 0x0);
  1149. hisi_sas_phy_write32(hisi_hba, i, PHYCTRL_OOB_RESTART_MSK, 0x0);
  1150. if (hisi_hba->refclk_frequency_mhz == 66)
  1151. hisi_sas_phy_write32(hisi_hba, i, PHY_CTRL, 0x199B694);
  1152. /* else, do nothing -> leave it how you found it */
  1153. }
  1154. for (i = 0; i < hisi_hba->queue_count; i++) {
  1155. /* Delivery queue */
  1156. hisi_sas_write32(hisi_hba,
  1157. DLVRY_Q_0_BASE_ADDR_HI + (i * 0x14),
  1158. upper_32_bits(hisi_hba->cmd_hdr_dma[i]));
  1159. hisi_sas_write32(hisi_hba, DLVRY_Q_0_BASE_ADDR_LO + (i * 0x14),
  1160. lower_32_bits(hisi_hba->cmd_hdr_dma[i]));
  1161. hisi_sas_write32(hisi_hba, DLVRY_Q_0_DEPTH + (i * 0x14),
  1162. HISI_SAS_QUEUE_SLOTS);
  1163. /* Completion queue */
  1164. hisi_sas_write32(hisi_hba, COMPL_Q_0_BASE_ADDR_HI + (i * 0x14),
  1165. upper_32_bits(hisi_hba->complete_hdr_dma[i]));
  1166. hisi_sas_write32(hisi_hba, COMPL_Q_0_BASE_ADDR_LO + (i * 0x14),
  1167. lower_32_bits(hisi_hba->complete_hdr_dma[i]));
  1168. hisi_sas_write32(hisi_hba, COMPL_Q_0_DEPTH + (i * 0x14),
  1169. HISI_SAS_QUEUE_SLOTS);
  1170. }
  1171. /* itct */
  1172. hisi_sas_write32(hisi_hba, ITCT_BASE_ADDR_LO,
  1173. lower_32_bits(hisi_hba->itct_dma));
  1174. hisi_sas_write32(hisi_hba, ITCT_BASE_ADDR_HI,
  1175. upper_32_bits(hisi_hba->itct_dma));
  1176. /* iost */
  1177. hisi_sas_write32(hisi_hba, IOST_BASE_ADDR_LO,
  1178. lower_32_bits(hisi_hba->iost_dma));
  1179. hisi_sas_write32(hisi_hba, IOST_BASE_ADDR_HI,
  1180. upper_32_bits(hisi_hba->iost_dma));
  1181. /* breakpoint */
  1182. hisi_sas_write32(hisi_hba, IO_BROKEN_MSG_ADDR_LO,
  1183. lower_32_bits(hisi_hba->breakpoint_dma));
  1184. hisi_sas_write32(hisi_hba, IO_BROKEN_MSG_ADDR_HI,
  1185. upper_32_bits(hisi_hba->breakpoint_dma));
  1186. /* SATA broken msg */
  1187. hisi_sas_write32(hisi_hba, IO_SATA_BROKEN_MSG_ADDR_LO,
  1188. lower_32_bits(hisi_hba->sata_breakpoint_dma));
  1189. hisi_sas_write32(hisi_hba, IO_SATA_BROKEN_MSG_ADDR_HI,
  1190. upper_32_bits(hisi_hba->sata_breakpoint_dma));
  1191. /* SATA initial fis */
  1192. hisi_sas_write32(hisi_hba, SATA_INITI_D2H_STORE_ADDR_LO,
  1193. lower_32_bits(hisi_hba->initial_fis_dma));
  1194. hisi_sas_write32(hisi_hba, SATA_INITI_D2H_STORE_ADDR_HI,
  1195. upper_32_bits(hisi_hba->initial_fis_dma));
  1196. }
  1197. static void link_timeout_enable_link(struct timer_list *t)
  1198. {
  1199. struct hisi_hba *hisi_hba = from_timer(hisi_hba, t, timer);
  1200. int i, reg_val;
  1201. for (i = 0; i < hisi_hba->n_phy; i++) {
  1202. if (hisi_hba->reject_stp_links_msk & BIT(i))
  1203. continue;
  1204. reg_val = hisi_sas_phy_read32(hisi_hba, i, CON_CONTROL);
  1205. if (!(reg_val & BIT(0))) {
  1206. hisi_sas_phy_write32(hisi_hba, i,
  1207. CON_CONTROL, 0x7);
  1208. break;
  1209. }
  1210. }
  1211. hisi_hba->timer.function = link_timeout_disable_link;
  1212. mod_timer(&hisi_hba->timer, jiffies + msecs_to_jiffies(900));
  1213. }
  1214. static void link_timeout_disable_link(struct timer_list *t)
  1215. {
  1216. struct hisi_hba *hisi_hba = from_timer(hisi_hba, t, timer);
  1217. int i, reg_val;
  1218. reg_val = hisi_sas_read32(hisi_hba, PHY_STATE);
  1219. for (i = 0; i < hisi_hba->n_phy && reg_val; i++) {
  1220. if (hisi_hba->reject_stp_links_msk & BIT(i))
  1221. continue;
  1222. if (reg_val & BIT(i)) {
  1223. hisi_sas_phy_write32(hisi_hba, i,
  1224. CON_CONTROL, 0x6);
  1225. break;
  1226. }
  1227. }
  1228. hisi_hba->timer.function = link_timeout_enable_link;
  1229. mod_timer(&hisi_hba->timer, jiffies + msecs_to_jiffies(100));
  1230. }
  1231. static void set_link_timer_quirk(struct hisi_hba *hisi_hba)
  1232. {
  1233. hisi_hba->timer.function = link_timeout_disable_link;
  1234. hisi_hba->timer.expires = jiffies + msecs_to_jiffies(1000);
  1235. add_timer(&hisi_hba->timer);
  1236. }
  1237. static int hw_init_v2_hw(struct hisi_hba *hisi_hba)
  1238. {
  1239. struct device *dev = hisi_hba->dev;
  1240. int rc;
  1241. rc = reset_hw_v2_hw(hisi_hba);
  1242. if (rc) {
  1243. dev_err(dev, "hisi_sas_reset_hw failed, rc=%d", rc);
  1244. return rc;
  1245. }
  1246. msleep(100);
  1247. init_reg_v2_hw(hisi_hba);
  1248. return 0;
  1249. }
  1250. static void enable_phy_v2_hw(struct hisi_hba *hisi_hba, int phy_no)
  1251. {
  1252. u32 cfg = hisi_sas_phy_read32(hisi_hba, phy_no, PHY_CFG);
  1253. cfg |= PHY_CFG_ENA_MSK;
  1254. hisi_sas_phy_write32(hisi_hba, phy_no, PHY_CFG, cfg);
  1255. }
  1256. static bool is_sata_phy_v2_hw(struct hisi_hba *hisi_hba, int phy_no)
  1257. {
  1258. u32 context;
  1259. context = hisi_sas_read32(hisi_hba, PHY_CONTEXT);
  1260. if (context & (1 << phy_no))
  1261. return true;
  1262. return false;
  1263. }
  1264. static bool tx_fifo_is_empty_v2_hw(struct hisi_hba *hisi_hba, int phy_no)
  1265. {
  1266. u32 dfx_val;
  1267. dfx_val = hisi_sas_phy_read32(hisi_hba, phy_no, DMA_TX_DFX1);
  1268. if (dfx_val & BIT(16))
  1269. return false;
  1270. return true;
  1271. }
  1272. static bool axi_bus_is_idle_v2_hw(struct hisi_hba *hisi_hba, int phy_no)
  1273. {
  1274. int i, max_loop = 1000;
  1275. struct device *dev = hisi_hba->dev;
  1276. u32 status, axi_status, dfx_val, dfx_tx_val;
  1277. for (i = 0; i < max_loop; i++) {
  1278. status = hisi_sas_read32_relaxed(hisi_hba,
  1279. AXI_MASTER_CFG_BASE + AM_CURR_TRANS_RETURN);
  1280. axi_status = hisi_sas_read32(hisi_hba, AXI_CFG);
  1281. dfx_val = hisi_sas_phy_read32(hisi_hba, phy_no, DMA_TX_DFX1);
  1282. dfx_tx_val = hisi_sas_phy_read32(hisi_hba,
  1283. phy_no, DMA_TX_FIFO_DFX0);
  1284. if ((status == 0x3) && (axi_status == 0x0) &&
  1285. (dfx_val & BIT(20)) && (dfx_tx_val & BIT(10)))
  1286. return true;
  1287. udelay(10);
  1288. }
  1289. dev_err(dev, "bus is not idle phy%d, axi150:0x%x axi100:0x%x port204:0x%x port240:0x%x\n",
  1290. phy_no, status, axi_status,
  1291. dfx_val, dfx_tx_val);
  1292. return false;
  1293. }
  1294. static bool wait_io_done_v2_hw(struct hisi_hba *hisi_hba, int phy_no)
  1295. {
  1296. int i, max_loop = 1000;
  1297. struct device *dev = hisi_hba->dev;
  1298. u32 status, tx_dfx0;
  1299. for (i = 0; i < max_loop; i++) {
  1300. status = hisi_sas_phy_read32(hisi_hba, phy_no, LINK_DFX2);
  1301. status = (status & 0x3fc0) >> 6;
  1302. if (status != 0x1)
  1303. return true;
  1304. tx_dfx0 = hisi_sas_phy_read32(hisi_hba, phy_no, DMA_TX_DFX0);
  1305. if ((tx_dfx0 & 0x1ff) == 0x2)
  1306. return true;
  1307. udelay(10);
  1308. }
  1309. dev_err(dev, "IO not done phy%d, port264:0x%x port200:0x%x\n",
  1310. phy_no, status, tx_dfx0);
  1311. return false;
  1312. }
  1313. static bool allowed_disable_phy_v2_hw(struct hisi_hba *hisi_hba, int phy_no)
  1314. {
  1315. if (tx_fifo_is_empty_v2_hw(hisi_hba, phy_no))
  1316. return true;
  1317. if (!axi_bus_is_idle_v2_hw(hisi_hba, phy_no))
  1318. return false;
  1319. if (!wait_io_done_v2_hw(hisi_hba, phy_no))
  1320. return false;
  1321. return true;
  1322. }
  1323. static void disable_phy_v2_hw(struct hisi_hba *hisi_hba, int phy_no)
  1324. {
  1325. u32 cfg, axi_val, dfx0_val, txid_auto;
  1326. struct device *dev = hisi_hba->dev;
  1327. /* Close axi bus. */
  1328. axi_val = hisi_sas_read32(hisi_hba, AXI_MASTER_CFG_BASE +
  1329. AM_CTRL_GLOBAL);
  1330. axi_val |= 0x1;
  1331. hisi_sas_write32(hisi_hba, AXI_MASTER_CFG_BASE +
  1332. AM_CTRL_GLOBAL, axi_val);
  1333. if (is_sata_phy_v2_hw(hisi_hba, phy_no)) {
  1334. if (allowed_disable_phy_v2_hw(hisi_hba, phy_no))
  1335. goto do_disable;
  1336. /* Reset host controller. */
  1337. queue_work(hisi_hba->wq, &hisi_hba->rst_work);
  1338. return;
  1339. }
  1340. dfx0_val = hisi_sas_phy_read32(hisi_hba, phy_no, PORT_DFX0);
  1341. dfx0_val = (dfx0_val & 0x1fc0) >> 6;
  1342. if (dfx0_val != 0x4)
  1343. goto do_disable;
  1344. if (!tx_fifo_is_empty_v2_hw(hisi_hba, phy_no)) {
  1345. dev_warn(dev, "phy%d, wait tx fifo need send break\n",
  1346. phy_no);
  1347. txid_auto = hisi_sas_phy_read32(hisi_hba, phy_no,
  1348. TXID_AUTO);
  1349. txid_auto |= TXID_AUTO_CTB_MSK;
  1350. hisi_sas_phy_write32(hisi_hba, phy_no, TXID_AUTO,
  1351. txid_auto);
  1352. }
  1353. do_disable:
  1354. cfg = hisi_sas_phy_read32(hisi_hba, phy_no, PHY_CFG);
  1355. cfg &= ~PHY_CFG_ENA_MSK;
  1356. hisi_sas_phy_write32(hisi_hba, phy_no, PHY_CFG, cfg);
  1357. /* Open axi bus. */
  1358. axi_val &= ~0x1;
  1359. hisi_sas_write32(hisi_hba, AXI_MASTER_CFG_BASE +
  1360. AM_CTRL_GLOBAL, axi_val);
  1361. }
  1362. static void start_phy_v2_hw(struct hisi_hba *hisi_hba, int phy_no)
  1363. {
  1364. config_id_frame_v2_hw(hisi_hba, phy_no);
  1365. config_phy_opt_mode_v2_hw(hisi_hba, phy_no);
  1366. enable_phy_v2_hw(hisi_hba, phy_no);
  1367. }
  1368. static void phy_hard_reset_v2_hw(struct hisi_hba *hisi_hba, int phy_no)
  1369. {
  1370. struct hisi_sas_phy *phy = &hisi_hba->phy[phy_no];
  1371. u32 txid_auto;
  1372. disable_phy_v2_hw(hisi_hba, phy_no);
  1373. if (phy->identify.device_type == SAS_END_DEVICE) {
  1374. txid_auto = hisi_sas_phy_read32(hisi_hba, phy_no, TXID_AUTO);
  1375. hisi_sas_phy_write32(hisi_hba, phy_no, TXID_AUTO,
  1376. txid_auto | TX_HARDRST_MSK);
  1377. }
  1378. msleep(100);
  1379. start_phy_v2_hw(hisi_hba, phy_no);
  1380. }
  1381. static void phy_get_events_v2_hw(struct hisi_hba *hisi_hba, int phy_no)
  1382. {
  1383. struct hisi_sas_phy *phy = &hisi_hba->phy[phy_no];
  1384. struct asd_sas_phy *sas_phy = &phy->sas_phy;
  1385. struct sas_phy *sphy = sas_phy->phy;
  1386. u32 err4_reg_val, err6_reg_val;
  1387. /* loss dword syn, phy reset problem */
  1388. err4_reg_val = hisi_sas_phy_read32(hisi_hba, phy_no, SAS_ERR_CNT4_REG);
  1389. /* disparity err, invalid dword */
  1390. err6_reg_val = hisi_sas_phy_read32(hisi_hba, phy_no, SAS_ERR_CNT6_REG);
  1391. sphy->loss_of_dword_sync_count += (err4_reg_val >> 16) & 0xFFFF;
  1392. sphy->phy_reset_problem_count += err4_reg_val & 0xFFFF;
  1393. sphy->invalid_dword_count += (err6_reg_val & 0xFF0000) >> 16;
  1394. sphy->running_disparity_error_count += err6_reg_val & 0xFF;
  1395. }
  1396. static void phys_init_v2_hw(struct hisi_hba *hisi_hba)
  1397. {
  1398. int i;
  1399. for (i = 0; i < hisi_hba->n_phy; i++) {
  1400. struct hisi_sas_phy *phy = &hisi_hba->phy[i];
  1401. struct asd_sas_phy *sas_phy = &phy->sas_phy;
  1402. if (!sas_phy->phy->enabled)
  1403. continue;
  1404. start_phy_v2_hw(hisi_hba, i);
  1405. }
  1406. }
  1407. static void sl_notify_ssp_v2_hw(struct hisi_hba *hisi_hba, int phy_no)
  1408. {
  1409. u32 sl_control;
  1410. sl_control = hisi_sas_phy_read32(hisi_hba, phy_no, SL_CONTROL);
  1411. sl_control |= SL_CONTROL_NOTIFY_EN_MSK;
  1412. hisi_sas_phy_write32(hisi_hba, phy_no, SL_CONTROL, sl_control);
  1413. msleep(1);
  1414. sl_control = hisi_sas_phy_read32(hisi_hba, phy_no, SL_CONTROL);
  1415. sl_control &= ~SL_CONTROL_NOTIFY_EN_MSK;
  1416. hisi_sas_phy_write32(hisi_hba, phy_no, SL_CONTROL, sl_control);
  1417. }
  1418. static enum sas_linkrate phy_get_max_linkrate_v2_hw(void)
  1419. {
  1420. return SAS_LINK_RATE_12_0_GBPS;
  1421. }
  1422. static void phy_set_linkrate_v2_hw(struct hisi_hba *hisi_hba, int phy_no,
  1423. struct sas_phy_linkrates *r)
  1424. {
  1425. enum sas_linkrate max = r->maximum_linkrate;
  1426. u32 prog_phy_link_rate = 0x800;
  1427. prog_phy_link_rate |= hisi_sas_get_prog_phy_linkrate_mask(max);
  1428. hisi_sas_phy_write32(hisi_hba, phy_no, PROG_PHY_LINK_RATE,
  1429. prog_phy_link_rate);
  1430. }
  1431. static int get_wideport_bitmap_v2_hw(struct hisi_hba *hisi_hba, int port_id)
  1432. {
  1433. int i, bitmap = 0;
  1434. u32 phy_port_num_ma = hisi_sas_read32(hisi_hba, PHY_PORT_NUM_MA);
  1435. u32 phy_state = hisi_sas_read32(hisi_hba, PHY_STATE);
  1436. for (i = 0; i < (hisi_hba->n_phy < 9 ? hisi_hba->n_phy : 8); i++)
  1437. if (phy_state & 1 << i)
  1438. if (((phy_port_num_ma >> (i * 4)) & 0xf) == port_id)
  1439. bitmap |= 1 << i;
  1440. if (hisi_hba->n_phy == 9) {
  1441. u32 port_state = hisi_sas_read32(hisi_hba, PORT_STATE);
  1442. if (phy_state & 1 << 8)
  1443. if (((port_state & PORT_STATE_PHY8_PORT_NUM_MSK) >>
  1444. PORT_STATE_PHY8_PORT_NUM_OFF) == port_id)
  1445. bitmap |= 1 << 9;
  1446. }
  1447. return bitmap;
  1448. }
  1449. /*
  1450. * The callpath to this function and upto writing the write
  1451. * queue pointer should be safe from interruption.
  1452. */
  1453. static int
  1454. get_free_slot_v2_hw(struct hisi_hba *hisi_hba, struct hisi_sas_dq *dq)
  1455. {
  1456. struct device *dev = hisi_hba->dev;
  1457. int queue = dq->id;
  1458. u32 r, w;
  1459. w = dq->wr_point;
  1460. r = hisi_sas_read32_relaxed(hisi_hba,
  1461. DLVRY_Q_0_RD_PTR + (queue * 0x14));
  1462. if (r == (w+1) % HISI_SAS_QUEUE_SLOTS) {
  1463. dev_warn(dev, "full queue=%d r=%d w=%d\n",
  1464. queue, r, w);
  1465. return -EAGAIN;
  1466. }
  1467. dq->wr_point = (dq->wr_point + 1) % HISI_SAS_QUEUE_SLOTS;
  1468. return w;
  1469. }
  1470. /* DQ lock must be taken here */
  1471. static void start_delivery_v2_hw(struct hisi_sas_dq *dq)
  1472. {
  1473. struct hisi_hba *hisi_hba = dq->hisi_hba;
  1474. struct hisi_sas_slot *s, *s1, *s2 = NULL;
  1475. int dlvry_queue = dq->id;
  1476. int wp;
  1477. list_for_each_entry_safe(s, s1, &dq->list, delivery) {
  1478. if (!s->ready)
  1479. break;
  1480. s2 = s;
  1481. list_del(&s->delivery);
  1482. }
  1483. if (!s2)
  1484. return;
  1485. /*
  1486. * Ensure that memories for slots built on other CPUs is observed.
  1487. */
  1488. smp_rmb();
  1489. wp = (s2->dlvry_queue_slot + 1) % HISI_SAS_QUEUE_SLOTS;
  1490. hisi_sas_write32(hisi_hba, DLVRY_Q_0_WR_PTR + (dlvry_queue * 0x14), wp);
  1491. }
  1492. static void prep_prd_sge_v2_hw(struct hisi_hba *hisi_hba,
  1493. struct hisi_sas_slot *slot,
  1494. struct hisi_sas_cmd_hdr *hdr,
  1495. struct scatterlist *scatter,
  1496. int n_elem)
  1497. {
  1498. struct hisi_sas_sge_page *sge_page = hisi_sas_sge_addr_mem(slot);
  1499. struct scatterlist *sg;
  1500. int i;
  1501. for_each_sg(scatter, sg, n_elem, i) {
  1502. struct hisi_sas_sge *entry = &sge_page->sge[i];
  1503. entry->addr = cpu_to_le64(sg_dma_address(sg));
  1504. entry->page_ctrl_0 = entry->page_ctrl_1 = 0;
  1505. entry->data_len = cpu_to_le32(sg_dma_len(sg));
  1506. entry->data_off = 0;
  1507. }
  1508. hdr->prd_table_addr = cpu_to_le64(hisi_sas_sge_addr_dma(slot));
  1509. hdr->sg_len = cpu_to_le32(n_elem << CMD_HDR_DATA_SGL_LEN_OFF);
  1510. }
  1511. static void prep_smp_v2_hw(struct hisi_hba *hisi_hba,
  1512. struct hisi_sas_slot *slot)
  1513. {
  1514. struct sas_task *task = slot->task;
  1515. struct hisi_sas_cmd_hdr *hdr = slot->cmd_hdr;
  1516. struct domain_device *device = task->dev;
  1517. struct hisi_sas_port *port = slot->port;
  1518. struct scatterlist *sg_req;
  1519. struct hisi_sas_device *sas_dev = device->lldd_dev;
  1520. dma_addr_t req_dma_addr;
  1521. unsigned int req_len;
  1522. /* req */
  1523. sg_req = &task->smp_task.smp_req;
  1524. req_dma_addr = sg_dma_address(sg_req);
  1525. req_len = sg_dma_len(&task->smp_task.smp_req);
  1526. /* create header */
  1527. /* dw0 */
  1528. hdr->dw0 = cpu_to_le32((port->id << CMD_HDR_PORT_OFF) |
  1529. (1 << CMD_HDR_PRIORITY_OFF) | /* high pri */
  1530. (2 << CMD_HDR_CMD_OFF)); /* smp */
  1531. /* map itct entry */
  1532. hdr->dw1 = cpu_to_le32((sas_dev->device_id << CMD_HDR_DEV_ID_OFF) |
  1533. (1 << CMD_HDR_FRAME_TYPE_OFF) |
  1534. (DIR_NO_DATA << CMD_HDR_DIR_OFF));
  1535. /* dw2 */
  1536. hdr->dw2 = cpu_to_le32((((req_len - 4) / 4) << CMD_HDR_CFL_OFF) |
  1537. (HISI_SAS_MAX_SMP_RESP_SZ / 4 <<
  1538. CMD_HDR_MRFL_OFF));
  1539. hdr->transfer_tags = cpu_to_le32(slot->idx << CMD_HDR_IPTT_OFF);
  1540. hdr->cmd_table_addr = cpu_to_le64(req_dma_addr);
  1541. hdr->sts_buffer_addr = cpu_to_le64(hisi_sas_status_buf_addr_dma(slot));
  1542. }
  1543. static void prep_ssp_v2_hw(struct hisi_hba *hisi_hba,
  1544. struct hisi_sas_slot *slot)
  1545. {
  1546. struct sas_task *task = slot->task;
  1547. struct hisi_sas_cmd_hdr *hdr = slot->cmd_hdr;
  1548. struct domain_device *device = task->dev;
  1549. struct hisi_sas_device *sas_dev = device->lldd_dev;
  1550. struct hisi_sas_port *port = slot->port;
  1551. struct sas_ssp_task *ssp_task = &task->ssp_task;
  1552. struct scsi_cmnd *scsi_cmnd = ssp_task->cmd;
  1553. struct hisi_sas_tmf_task *tmf = slot->tmf;
  1554. int has_data = 0, priority = !!tmf;
  1555. u8 *buf_cmd;
  1556. u32 dw1 = 0, dw2 = 0;
  1557. hdr->dw0 = cpu_to_le32((1 << CMD_HDR_RESP_REPORT_OFF) |
  1558. (2 << CMD_HDR_TLR_CTRL_OFF) |
  1559. (port->id << CMD_HDR_PORT_OFF) |
  1560. (priority << CMD_HDR_PRIORITY_OFF) |
  1561. (1 << CMD_HDR_CMD_OFF)); /* ssp */
  1562. dw1 = 1 << CMD_HDR_VDTL_OFF;
  1563. if (tmf) {
  1564. dw1 |= 2 << CMD_HDR_FRAME_TYPE_OFF;
  1565. dw1 |= DIR_NO_DATA << CMD_HDR_DIR_OFF;
  1566. } else {
  1567. dw1 |= 1 << CMD_HDR_FRAME_TYPE_OFF;
  1568. switch (scsi_cmnd->sc_data_direction) {
  1569. case DMA_TO_DEVICE:
  1570. has_data = 1;
  1571. dw1 |= DIR_TO_DEVICE << CMD_HDR_DIR_OFF;
  1572. break;
  1573. case DMA_FROM_DEVICE:
  1574. has_data = 1;
  1575. dw1 |= DIR_TO_INI << CMD_HDR_DIR_OFF;
  1576. break;
  1577. default:
  1578. dw1 &= ~CMD_HDR_DIR_MSK;
  1579. }
  1580. }
  1581. /* map itct entry */
  1582. dw1 |= sas_dev->device_id << CMD_HDR_DEV_ID_OFF;
  1583. hdr->dw1 = cpu_to_le32(dw1);
  1584. dw2 = (((sizeof(struct ssp_command_iu) + sizeof(struct ssp_frame_hdr)
  1585. + 3) / 4) << CMD_HDR_CFL_OFF) |
  1586. ((HISI_SAS_MAX_SSP_RESP_SZ / 4) << CMD_HDR_MRFL_OFF) |
  1587. (2 << CMD_HDR_SG_MOD_OFF);
  1588. hdr->dw2 = cpu_to_le32(dw2);
  1589. hdr->transfer_tags = cpu_to_le32(slot->idx);
  1590. if (has_data)
  1591. prep_prd_sge_v2_hw(hisi_hba, slot, hdr, task->scatter,
  1592. slot->n_elem);
  1593. hdr->data_transfer_len = cpu_to_le32(task->total_xfer_len);
  1594. hdr->cmd_table_addr = cpu_to_le64(hisi_sas_cmd_hdr_addr_dma(slot));
  1595. hdr->sts_buffer_addr = cpu_to_le64(hisi_sas_status_buf_addr_dma(slot));
  1596. buf_cmd = hisi_sas_cmd_hdr_addr_mem(slot) +
  1597. sizeof(struct ssp_frame_hdr);
  1598. memcpy(buf_cmd, &task->ssp_task.LUN, 8);
  1599. if (!tmf) {
  1600. buf_cmd[9] = task->ssp_task.task_attr |
  1601. (task->ssp_task.task_prio << 3);
  1602. memcpy(buf_cmd + 12, task->ssp_task.cmd->cmnd,
  1603. task->ssp_task.cmd->cmd_len);
  1604. } else {
  1605. buf_cmd[10] = tmf->tmf;
  1606. switch (tmf->tmf) {
  1607. case TMF_ABORT_TASK:
  1608. case TMF_QUERY_TASK:
  1609. buf_cmd[12] =
  1610. (tmf->tag_of_task_to_be_managed >> 8) & 0xff;
  1611. buf_cmd[13] =
  1612. tmf->tag_of_task_to_be_managed & 0xff;
  1613. break;
  1614. default:
  1615. break;
  1616. }
  1617. }
  1618. }
  1619. #define TRANS_TX_ERR 0
  1620. #define TRANS_RX_ERR 1
  1621. #define DMA_TX_ERR 2
  1622. #define SIPC_RX_ERR 3
  1623. #define DMA_RX_ERR 4
  1624. #define DMA_TX_ERR_OFF 0
  1625. #define DMA_TX_ERR_MSK (0xffff << DMA_TX_ERR_OFF)
  1626. #define SIPC_RX_ERR_OFF 16
  1627. #define SIPC_RX_ERR_MSK (0xffff << SIPC_RX_ERR_OFF)
  1628. static int parse_trans_tx_err_code_v2_hw(u32 err_msk)
  1629. {
  1630. static const u8 trans_tx_err_code_prio[] = {
  1631. TRANS_TX_OPEN_FAIL_WITH_IT_NEXUS_LOSS,
  1632. TRANS_TX_ERR_PHY_NOT_ENABLE,
  1633. TRANS_TX_OPEN_CNX_ERR_WRONG_DESTINATION,
  1634. TRANS_TX_OPEN_CNX_ERR_ZONE_VIOLATION,
  1635. TRANS_TX_OPEN_CNX_ERR_BY_OTHER,
  1636. RESERVED0,
  1637. TRANS_TX_OPEN_CNX_ERR_AIP_TIMEOUT,
  1638. TRANS_TX_OPEN_CNX_ERR_STP_RESOURCES_BUSY,
  1639. TRANS_TX_OPEN_CNX_ERR_PROTOCOL_NOT_SUPPORTED,
  1640. TRANS_TX_OPEN_CNX_ERR_CONNECTION_RATE_NOT_SUPPORTED,
  1641. TRANS_TX_OPEN_CNX_ERR_BAD_DESTINATION,
  1642. TRANS_TX_OPEN_CNX_ERR_BREAK_RCVD,
  1643. TRANS_TX_OPEN_CNX_ERR_LOW_PHY_POWER,
  1644. TRANS_TX_OPEN_CNX_ERR_PATHWAY_BLOCKED,
  1645. TRANS_TX_OPEN_CNX_ERR_OPEN_TIMEOUT,
  1646. TRANS_TX_OPEN_CNX_ERR_NO_DESTINATION,
  1647. TRANS_TX_OPEN_RETRY_ERR_THRESHOLD_REACHED,
  1648. TRANS_TX_ERR_WITH_CLOSE_PHYDISALE,
  1649. TRANS_TX_ERR_WITH_CLOSE_DWS_TIMEOUT,
  1650. TRANS_TX_ERR_WITH_CLOSE_COMINIT,
  1651. TRANS_TX_ERR_WITH_BREAK_TIMEOUT,
  1652. TRANS_TX_ERR_WITH_BREAK_REQUEST,
  1653. TRANS_TX_ERR_WITH_BREAK_RECEVIED,
  1654. TRANS_TX_ERR_WITH_CLOSE_TIMEOUT,
  1655. TRANS_TX_ERR_WITH_CLOSE_NORMAL,
  1656. TRANS_TX_ERR_WITH_NAK_RECEVIED,
  1657. TRANS_TX_ERR_WITH_ACK_NAK_TIMEOUT,
  1658. TRANS_TX_ERR_WITH_CREDIT_TIMEOUT,
  1659. TRANS_TX_ERR_WITH_IPTT_CONFLICT,
  1660. TRANS_TX_ERR_WITH_OPEN_BY_DES_OR_OTHERS,
  1661. TRANS_TX_ERR_WITH_WAIT_RECV_TIMEOUT,
  1662. };
  1663. int index, i;
  1664. for (i = 0; i < ARRAY_SIZE(trans_tx_err_code_prio); i++) {
  1665. index = trans_tx_err_code_prio[i] - TRANS_TX_FAIL_BASE;
  1666. if (err_msk & (1 << index))
  1667. return trans_tx_err_code_prio[i];
  1668. }
  1669. return -1;
  1670. }
  1671. static int parse_trans_rx_err_code_v2_hw(u32 err_msk)
  1672. {
  1673. static const u8 trans_rx_err_code_prio[] = {
  1674. TRANS_RX_ERR_WITH_RXFRAME_CRC_ERR,
  1675. TRANS_RX_ERR_WITH_RXFIS_8B10B_DISP_ERR,
  1676. TRANS_RX_ERR_WITH_RXFRAME_HAVE_ERRPRM,
  1677. TRANS_RX_ERR_WITH_RXFIS_DECODE_ERROR,
  1678. TRANS_RX_ERR_WITH_RXFIS_CRC_ERR,
  1679. TRANS_RX_ERR_WITH_RXFRAME_LENGTH_OVERRUN,
  1680. TRANS_RX_ERR_WITH_RXFIS_RX_SYNCP,
  1681. TRANS_RX_ERR_WITH_LINK_BUF_OVERRUN,
  1682. TRANS_RX_ERR_WITH_CLOSE_PHY_DISABLE,
  1683. TRANS_RX_ERR_WITH_CLOSE_DWS_TIMEOUT,
  1684. TRANS_RX_ERR_WITH_CLOSE_COMINIT,
  1685. TRANS_RX_ERR_WITH_BREAK_TIMEOUT,
  1686. TRANS_RX_ERR_WITH_BREAK_REQUEST,
  1687. TRANS_RX_ERR_WITH_BREAK_RECEVIED,
  1688. RESERVED1,
  1689. TRANS_RX_ERR_WITH_CLOSE_NORMAL,
  1690. TRANS_RX_ERR_WITH_DATA_LEN0,
  1691. TRANS_RX_ERR_WITH_BAD_HASH,
  1692. TRANS_RX_XRDY_WLEN_ZERO_ERR,
  1693. TRANS_RX_SSP_FRM_LEN_ERR,
  1694. RESERVED2,
  1695. RESERVED3,
  1696. RESERVED4,
  1697. RESERVED5,
  1698. TRANS_RX_ERR_WITH_BAD_FRM_TYPE,
  1699. TRANS_RX_SMP_FRM_LEN_ERR,
  1700. TRANS_RX_SMP_RESP_TIMEOUT_ERR,
  1701. RESERVED6,
  1702. RESERVED7,
  1703. RESERVED8,
  1704. RESERVED9,
  1705. TRANS_RX_R_ERR,
  1706. };
  1707. int index, i;
  1708. for (i = 0; i < ARRAY_SIZE(trans_rx_err_code_prio); i++) {
  1709. index = trans_rx_err_code_prio[i] - TRANS_RX_FAIL_BASE;
  1710. if (err_msk & (1 << index))
  1711. return trans_rx_err_code_prio[i];
  1712. }
  1713. return -1;
  1714. }
  1715. static int parse_dma_tx_err_code_v2_hw(u32 err_msk)
  1716. {
  1717. static const u8 dma_tx_err_code_prio[] = {
  1718. DMA_TX_UNEXP_XFER_ERR,
  1719. DMA_TX_UNEXP_RETRANS_ERR,
  1720. DMA_TX_XFER_LEN_OVERFLOW,
  1721. DMA_TX_XFER_OFFSET_ERR,
  1722. DMA_TX_RAM_ECC_ERR,
  1723. DMA_TX_DIF_LEN_ALIGN_ERR,
  1724. DMA_TX_DIF_CRC_ERR,
  1725. DMA_TX_DIF_APP_ERR,
  1726. DMA_TX_DIF_RPP_ERR,
  1727. DMA_TX_DATA_SGL_OVERFLOW,
  1728. DMA_TX_DIF_SGL_OVERFLOW,
  1729. };
  1730. int index, i;
  1731. for (i = 0; i < ARRAY_SIZE(dma_tx_err_code_prio); i++) {
  1732. index = dma_tx_err_code_prio[i] - DMA_TX_ERR_BASE;
  1733. err_msk = err_msk & DMA_TX_ERR_MSK;
  1734. if (err_msk & (1 << index))
  1735. return dma_tx_err_code_prio[i];
  1736. }
  1737. return -1;
  1738. }
  1739. static int parse_sipc_rx_err_code_v2_hw(u32 err_msk)
  1740. {
  1741. static const u8 sipc_rx_err_code_prio[] = {
  1742. SIPC_RX_FIS_STATUS_ERR_BIT_VLD,
  1743. SIPC_RX_PIO_WRSETUP_STATUS_DRQ_ERR,
  1744. SIPC_RX_FIS_STATUS_BSY_BIT_ERR,
  1745. SIPC_RX_WRSETUP_LEN_ODD_ERR,
  1746. SIPC_RX_WRSETUP_LEN_ZERO_ERR,
  1747. SIPC_RX_WRDATA_LEN_NOT_MATCH_ERR,
  1748. SIPC_RX_NCQ_WRSETUP_OFFSET_ERR,
  1749. SIPC_RX_NCQ_WRSETUP_AUTO_ACTIVE_ERR,
  1750. SIPC_RX_SATA_UNEXP_FIS_ERR,
  1751. SIPC_RX_WRSETUP_ESTATUS_ERR,
  1752. SIPC_RX_DATA_UNDERFLOW_ERR,
  1753. };
  1754. int index, i;
  1755. for (i = 0; i < ARRAY_SIZE(sipc_rx_err_code_prio); i++) {
  1756. index = sipc_rx_err_code_prio[i] - SIPC_RX_ERR_BASE;
  1757. err_msk = err_msk & SIPC_RX_ERR_MSK;
  1758. if (err_msk & (1 << (index + 0x10)))
  1759. return sipc_rx_err_code_prio[i];
  1760. }
  1761. return -1;
  1762. }
  1763. static int parse_dma_rx_err_code_v2_hw(u32 err_msk)
  1764. {
  1765. static const u8 dma_rx_err_code_prio[] = {
  1766. DMA_RX_UNKNOWN_FRM_ERR,
  1767. DMA_RX_DATA_LEN_OVERFLOW,
  1768. DMA_RX_DATA_LEN_UNDERFLOW,
  1769. DMA_RX_DATA_OFFSET_ERR,
  1770. RESERVED10,
  1771. DMA_RX_SATA_FRAME_TYPE_ERR,
  1772. DMA_RX_RESP_BUF_OVERFLOW,
  1773. DMA_RX_UNEXP_RETRANS_RESP_ERR,
  1774. DMA_RX_UNEXP_NORM_RESP_ERR,
  1775. DMA_RX_UNEXP_RDFRAME_ERR,
  1776. DMA_RX_PIO_DATA_LEN_ERR,
  1777. DMA_RX_RDSETUP_STATUS_ERR,
  1778. DMA_RX_RDSETUP_STATUS_DRQ_ERR,
  1779. DMA_RX_RDSETUP_STATUS_BSY_ERR,
  1780. DMA_RX_RDSETUP_LEN_ODD_ERR,
  1781. DMA_RX_RDSETUP_LEN_ZERO_ERR,
  1782. DMA_RX_RDSETUP_LEN_OVER_ERR,
  1783. DMA_RX_RDSETUP_OFFSET_ERR,
  1784. DMA_RX_RDSETUP_ACTIVE_ERR,
  1785. DMA_RX_RDSETUP_ESTATUS_ERR,
  1786. DMA_RX_RAM_ECC_ERR,
  1787. DMA_RX_DIF_CRC_ERR,
  1788. DMA_RX_DIF_APP_ERR,
  1789. DMA_RX_DIF_RPP_ERR,
  1790. DMA_RX_DATA_SGL_OVERFLOW,
  1791. DMA_RX_DIF_SGL_OVERFLOW,
  1792. };
  1793. int index, i;
  1794. for (i = 0; i < ARRAY_SIZE(dma_rx_err_code_prio); i++) {
  1795. index = dma_rx_err_code_prio[i] - DMA_RX_ERR_BASE;
  1796. if (err_msk & (1 << index))
  1797. return dma_rx_err_code_prio[i];
  1798. }
  1799. return -1;
  1800. }
  1801. /* by default, task resp is complete */
  1802. static void slot_err_v2_hw(struct hisi_hba *hisi_hba,
  1803. struct sas_task *task,
  1804. struct hisi_sas_slot *slot,
  1805. int err_phase)
  1806. {
  1807. struct task_status_struct *ts = &task->task_status;
  1808. struct hisi_sas_err_record_v2 *err_record =
  1809. hisi_sas_status_buf_addr_mem(slot);
  1810. u32 trans_tx_fail_type = cpu_to_le32(err_record->trans_tx_fail_type);
  1811. u32 trans_rx_fail_type = cpu_to_le32(err_record->trans_rx_fail_type);
  1812. u16 dma_tx_err_type = cpu_to_le16(err_record->dma_tx_err_type);
  1813. u16 sipc_rx_err_type = cpu_to_le16(err_record->sipc_rx_err_type);
  1814. u32 dma_rx_err_type = cpu_to_le32(err_record->dma_rx_err_type);
  1815. int error = -1;
  1816. if (err_phase == 1) {
  1817. /* error in TX phase, the priority of error is: DW2 > DW0 */
  1818. error = parse_dma_tx_err_code_v2_hw(dma_tx_err_type);
  1819. if (error == -1)
  1820. error = parse_trans_tx_err_code_v2_hw(
  1821. trans_tx_fail_type);
  1822. } else if (err_phase == 2) {
  1823. /* error in RX phase, the priority is: DW1 > DW3 > DW2 */
  1824. error = parse_trans_rx_err_code_v2_hw(
  1825. trans_rx_fail_type);
  1826. if (error == -1) {
  1827. error = parse_dma_rx_err_code_v2_hw(
  1828. dma_rx_err_type);
  1829. if (error == -1)
  1830. error = parse_sipc_rx_err_code_v2_hw(
  1831. sipc_rx_err_type);
  1832. }
  1833. }
  1834. switch (task->task_proto) {
  1835. case SAS_PROTOCOL_SSP:
  1836. {
  1837. switch (error) {
  1838. case TRANS_TX_OPEN_CNX_ERR_NO_DESTINATION:
  1839. {
  1840. ts->stat = SAS_OPEN_REJECT;
  1841. ts->open_rej_reason = SAS_OREJ_NO_DEST;
  1842. break;
  1843. }
  1844. case TRANS_TX_OPEN_CNX_ERR_PROTOCOL_NOT_SUPPORTED:
  1845. {
  1846. ts->stat = SAS_OPEN_REJECT;
  1847. ts->open_rej_reason = SAS_OREJ_EPROTO;
  1848. break;
  1849. }
  1850. case TRANS_TX_OPEN_CNX_ERR_CONNECTION_RATE_NOT_SUPPORTED:
  1851. {
  1852. ts->stat = SAS_OPEN_REJECT;
  1853. ts->open_rej_reason = SAS_OREJ_CONN_RATE;
  1854. break;
  1855. }
  1856. case TRANS_TX_OPEN_CNX_ERR_BAD_DESTINATION:
  1857. {
  1858. ts->stat = SAS_OPEN_REJECT;
  1859. ts->open_rej_reason = SAS_OREJ_BAD_DEST;
  1860. break;
  1861. }
  1862. case TRANS_TX_OPEN_CNX_ERR_WRONG_DESTINATION:
  1863. {
  1864. ts->stat = SAS_OPEN_REJECT;
  1865. ts->open_rej_reason = SAS_OREJ_WRONG_DEST;
  1866. break;
  1867. }
  1868. case DMA_RX_UNEXP_NORM_RESP_ERR:
  1869. case TRANS_TX_OPEN_CNX_ERR_ZONE_VIOLATION:
  1870. case DMA_RX_RESP_BUF_OVERFLOW:
  1871. {
  1872. ts->stat = SAS_OPEN_REJECT;
  1873. ts->open_rej_reason = SAS_OREJ_UNKNOWN;
  1874. break;
  1875. }
  1876. case TRANS_TX_OPEN_CNX_ERR_LOW_PHY_POWER:
  1877. {
  1878. /* not sure */
  1879. ts->stat = SAS_DEV_NO_RESPONSE;
  1880. break;
  1881. }
  1882. case DMA_RX_DATA_LEN_OVERFLOW:
  1883. {
  1884. ts->stat = SAS_DATA_OVERRUN;
  1885. ts->residual = 0;
  1886. break;
  1887. }
  1888. case DMA_RX_DATA_LEN_UNDERFLOW:
  1889. {
  1890. ts->residual = trans_tx_fail_type;
  1891. ts->stat = SAS_DATA_UNDERRUN;
  1892. break;
  1893. }
  1894. case TRANS_TX_OPEN_FAIL_WITH_IT_NEXUS_LOSS:
  1895. case TRANS_TX_ERR_PHY_NOT_ENABLE:
  1896. case TRANS_TX_OPEN_CNX_ERR_BY_OTHER:
  1897. case TRANS_TX_OPEN_CNX_ERR_AIP_TIMEOUT:
  1898. case TRANS_TX_OPEN_CNX_ERR_BREAK_RCVD:
  1899. case TRANS_TX_OPEN_CNX_ERR_PATHWAY_BLOCKED:
  1900. case TRANS_TX_OPEN_CNX_ERR_OPEN_TIMEOUT:
  1901. case TRANS_TX_OPEN_RETRY_ERR_THRESHOLD_REACHED:
  1902. case TRANS_TX_ERR_WITH_BREAK_TIMEOUT:
  1903. case TRANS_TX_ERR_WITH_BREAK_REQUEST:
  1904. case TRANS_TX_ERR_WITH_BREAK_RECEVIED:
  1905. case TRANS_TX_ERR_WITH_CLOSE_TIMEOUT:
  1906. case TRANS_TX_ERR_WITH_CLOSE_NORMAL:
  1907. case TRANS_TX_ERR_WITH_CLOSE_PHYDISALE:
  1908. case TRANS_TX_ERR_WITH_CLOSE_DWS_TIMEOUT:
  1909. case TRANS_TX_ERR_WITH_CLOSE_COMINIT:
  1910. case TRANS_TX_ERR_WITH_NAK_RECEVIED:
  1911. case TRANS_TX_ERR_WITH_ACK_NAK_TIMEOUT:
  1912. case TRANS_TX_ERR_WITH_CREDIT_TIMEOUT:
  1913. case TRANS_TX_ERR_WITH_IPTT_CONFLICT:
  1914. case TRANS_RX_ERR_WITH_RXFRAME_CRC_ERR:
  1915. case TRANS_RX_ERR_WITH_RXFIS_8B10B_DISP_ERR:
  1916. case TRANS_RX_ERR_WITH_RXFRAME_HAVE_ERRPRM:
  1917. case TRANS_RX_ERR_WITH_LINK_BUF_OVERRUN:
  1918. case TRANS_RX_ERR_WITH_BREAK_TIMEOUT:
  1919. case TRANS_RX_ERR_WITH_BREAK_REQUEST:
  1920. case TRANS_RX_ERR_WITH_BREAK_RECEVIED:
  1921. case TRANS_RX_ERR_WITH_CLOSE_NORMAL:
  1922. case TRANS_RX_ERR_WITH_CLOSE_DWS_TIMEOUT:
  1923. case TRANS_RX_ERR_WITH_CLOSE_COMINIT:
  1924. case TRANS_TX_ERR_FRAME_TXED:
  1925. case TRANS_RX_ERR_WITH_CLOSE_PHY_DISABLE:
  1926. case TRANS_RX_ERR_WITH_DATA_LEN0:
  1927. case TRANS_RX_ERR_WITH_BAD_HASH:
  1928. case TRANS_RX_XRDY_WLEN_ZERO_ERR:
  1929. case TRANS_RX_SSP_FRM_LEN_ERR:
  1930. case TRANS_RX_ERR_WITH_BAD_FRM_TYPE:
  1931. case DMA_TX_DATA_SGL_OVERFLOW:
  1932. case DMA_TX_UNEXP_XFER_ERR:
  1933. case DMA_TX_UNEXP_RETRANS_ERR:
  1934. case DMA_TX_XFER_LEN_OVERFLOW:
  1935. case DMA_TX_XFER_OFFSET_ERR:
  1936. case SIPC_RX_DATA_UNDERFLOW_ERR:
  1937. case DMA_RX_DATA_SGL_OVERFLOW:
  1938. case DMA_RX_DATA_OFFSET_ERR:
  1939. case DMA_RX_RDSETUP_LEN_ODD_ERR:
  1940. case DMA_RX_RDSETUP_LEN_ZERO_ERR:
  1941. case DMA_RX_RDSETUP_LEN_OVER_ERR:
  1942. case DMA_RX_SATA_FRAME_TYPE_ERR:
  1943. case DMA_RX_UNKNOWN_FRM_ERR:
  1944. {
  1945. /* This will request a retry */
  1946. ts->stat = SAS_QUEUE_FULL;
  1947. slot->abort = 1;
  1948. break;
  1949. }
  1950. default:
  1951. break;
  1952. }
  1953. }
  1954. break;
  1955. case SAS_PROTOCOL_SMP:
  1956. ts->stat = SAM_STAT_CHECK_CONDITION;
  1957. break;
  1958. case SAS_PROTOCOL_SATA:
  1959. case SAS_PROTOCOL_STP:
  1960. case SAS_PROTOCOL_SATA | SAS_PROTOCOL_STP:
  1961. {
  1962. switch (error) {
  1963. case TRANS_TX_OPEN_CNX_ERR_NO_DESTINATION:
  1964. {
  1965. ts->stat = SAS_OPEN_REJECT;
  1966. ts->open_rej_reason = SAS_OREJ_NO_DEST;
  1967. break;
  1968. }
  1969. case TRANS_TX_OPEN_CNX_ERR_LOW_PHY_POWER:
  1970. {
  1971. ts->resp = SAS_TASK_UNDELIVERED;
  1972. ts->stat = SAS_DEV_NO_RESPONSE;
  1973. break;
  1974. }
  1975. case TRANS_TX_OPEN_CNX_ERR_PROTOCOL_NOT_SUPPORTED:
  1976. {
  1977. ts->stat = SAS_OPEN_REJECT;
  1978. ts->open_rej_reason = SAS_OREJ_EPROTO;
  1979. break;
  1980. }
  1981. case TRANS_TX_OPEN_CNX_ERR_CONNECTION_RATE_NOT_SUPPORTED:
  1982. {
  1983. ts->stat = SAS_OPEN_REJECT;
  1984. ts->open_rej_reason = SAS_OREJ_CONN_RATE;
  1985. break;
  1986. }
  1987. case TRANS_TX_OPEN_CNX_ERR_BAD_DESTINATION:
  1988. {
  1989. ts->stat = SAS_OPEN_REJECT;
  1990. ts->open_rej_reason = SAS_OREJ_CONN_RATE;
  1991. break;
  1992. }
  1993. case TRANS_TX_OPEN_CNX_ERR_WRONG_DESTINATION:
  1994. {
  1995. ts->stat = SAS_OPEN_REJECT;
  1996. ts->open_rej_reason = SAS_OREJ_WRONG_DEST;
  1997. break;
  1998. }
  1999. case DMA_RX_RESP_BUF_OVERFLOW:
  2000. case DMA_RX_UNEXP_NORM_RESP_ERR:
  2001. case TRANS_TX_OPEN_CNX_ERR_ZONE_VIOLATION:
  2002. {
  2003. ts->stat = SAS_OPEN_REJECT;
  2004. ts->open_rej_reason = SAS_OREJ_UNKNOWN;
  2005. break;
  2006. }
  2007. case DMA_RX_DATA_LEN_OVERFLOW:
  2008. {
  2009. ts->stat = SAS_DATA_OVERRUN;
  2010. ts->residual = 0;
  2011. break;
  2012. }
  2013. case DMA_RX_DATA_LEN_UNDERFLOW:
  2014. {
  2015. ts->residual = trans_tx_fail_type;
  2016. ts->stat = SAS_DATA_UNDERRUN;
  2017. break;
  2018. }
  2019. case TRANS_TX_OPEN_FAIL_WITH_IT_NEXUS_LOSS:
  2020. case TRANS_TX_ERR_PHY_NOT_ENABLE:
  2021. case TRANS_TX_OPEN_CNX_ERR_BY_OTHER:
  2022. case TRANS_TX_OPEN_CNX_ERR_AIP_TIMEOUT:
  2023. case TRANS_TX_OPEN_CNX_ERR_BREAK_RCVD:
  2024. case TRANS_TX_OPEN_CNX_ERR_PATHWAY_BLOCKED:
  2025. case TRANS_TX_OPEN_CNX_ERR_OPEN_TIMEOUT:
  2026. case TRANS_TX_OPEN_RETRY_ERR_THRESHOLD_REACHED:
  2027. case TRANS_TX_ERR_WITH_BREAK_TIMEOUT:
  2028. case TRANS_TX_ERR_WITH_BREAK_REQUEST:
  2029. case TRANS_TX_ERR_WITH_BREAK_RECEVIED:
  2030. case TRANS_TX_ERR_WITH_CLOSE_TIMEOUT:
  2031. case TRANS_TX_ERR_WITH_CLOSE_NORMAL:
  2032. case TRANS_TX_ERR_WITH_CLOSE_PHYDISALE:
  2033. case TRANS_TX_ERR_WITH_CLOSE_DWS_TIMEOUT:
  2034. case TRANS_TX_ERR_WITH_CLOSE_COMINIT:
  2035. case TRANS_TX_ERR_WITH_ACK_NAK_TIMEOUT:
  2036. case TRANS_TX_ERR_WITH_CREDIT_TIMEOUT:
  2037. case TRANS_TX_ERR_WITH_OPEN_BY_DES_OR_OTHERS:
  2038. case TRANS_TX_ERR_WITH_WAIT_RECV_TIMEOUT:
  2039. case TRANS_RX_ERR_WITH_RXFRAME_HAVE_ERRPRM:
  2040. case TRANS_RX_ERR_WITH_RXFIS_8B10B_DISP_ERR:
  2041. case TRANS_RX_ERR_WITH_RXFIS_DECODE_ERROR:
  2042. case TRANS_RX_ERR_WITH_RXFIS_CRC_ERR:
  2043. case TRANS_RX_ERR_WITH_RXFRAME_LENGTH_OVERRUN:
  2044. case TRANS_RX_ERR_WITH_RXFIS_RX_SYNCP:
  2045. case TRANS_RX_ERR_WITH_LINK_BUF_OVERRUN:
  2046. case TRANS_RX_ERR_WITH_BREAK_TIMEOUT:
  2047. case TRANS_RX_ERR_WITH_BREAK_REQUEST:
  2048. case TRANS_RX_ERR_WITH_BREAK_RECEVIED:
  2049. case TRANS_RX_ERR_WITH_CLOSE_NORMAL:
  2050. case TRANS_RX_ERR_WITH_CLOSE_PHY_DISABLE:
  2051. case TRANS_RX_ERR_WITH_CLOSE_DWS_TIMEOUT:
  2052. case TRANS_RX_ERR_WITH_CLOSE_COMINIT:
  2053. case TRANS_RX_ERR_WITH_DATA_LEN0:
  2054. case TRANS_RX_ERR_WITH_BAD_HASH:
  2055. case TRANS_RX_XRDY_WLEN_ZERO_ERR:
  2056. case TRANS_RX_ERR_WITH_BAD_FRM_TYPE:
  2057. case DMA_TX_DATA_SGL_OVERFLOW:
  2058. case DMA_TX_UNEXP_XFER_ERR:
  2059. case DMA_TX_UNEXP_RETRANS_ERR:
  2060. case DMA_TX_XFER_LEN_OVERFLOW:
  2061. case DMA_TX_XFER_OFFSET_ERR:
  2062. case SIPC_RX_FIS_STATUS_ERR_BIT_VLD:
  2063. case SIPC_RX_PIO_WRSETUP_STATUS_DRQ_ERR:
  2064. case SIPC_RX_FIS_STATUS_BSY_BIT_ERR:
  2065. case SIPC_RX_WRSETUP_LEN_ODD_ERR:
  2066. case SIPC_RX_WRSETUP_LEN_ZERO_ERR:
  2067. case SIPC_RX_WRDATA_LEN_NOT_MATCH_ERR:
  2068. case SIPC_RX_SATA_UNEXP_FIS_ERR:
  2069. case DMA_RX_DATA_SGL_OVERFLOW:
  2070. case DMA_RX_DATA_OFFSET_ERR:
  2071. case DMA_RX_SATA_FRAME_TYPE_ERR:
  2072. case DMA_RX_UNEXP_RDFRAME_ERR:
  2073. case DMA_RX_PIO_DATA_LEN_ERR:
  2074. case DMA_RX_RDSETUP_STATUS_ERR:
  2075. case DMA_RX_RDSETUP_STATUS_DRQ_ERR:
  2076. case DMA_RX_RDSETUP_STATUS_BSY_ERR:
  2077. case DMA_RX_RDSETUP_LEN_ODD_ERR:
  2078. case DMA_RX_RDSETUP_LEN_ZERO_ERR:
  2079. case DMA_RX_RDSETUP_LEN_OVER_ERR:
  2080. case DMA_RX_RDSETUP_OFFSET_ERR:
  2081. case DMA_RX_RDSETUP_ACTIVE_ERR:
  2082. case DMA_RX_RDSETUP_ESTATUS_ERR:
  2083. case DMA_RX_UNKNOWN_FRM_ERR:
  2084. case TRANS_RX_SSP_FRM_LEN_ERR:
  2085. case TRANS_TX_OPEN_CNX_ERR_STP_RESOURCES_BUSY:
  2086. {
  2087. slot->abort = 1;
  2088. ts->stat = SAS_PHY_DOWN;
  2089. break;
  2090. }
  2091. default:
  2092. {
  2093. ts->stat = SAS_PROTO_RESPONSE;
  2094. break;
  2095. }
  2096. }
  2097. hisi_sas_sata_done(task, slot);
  2098. }
  2099. break;
  2100. default:
  2101. break;
  2102. }
  2103. }
  2104. static int
  2105. slot_complete_v2_hw(struct hisi_hba *hisi_hba, struct hisi_sas_slot *slot)
  2106. {
  2107. struct sas_task *task = slot->task;
  2108. struct hisi_sas_device *sas_dev;
  2109. struct device *dev = hisi_hba->dev;
  2110. struct task_status_struct *ts;
  2111. struct domain_device *device;
  2112. struct sas_ha_struct *ha;
  2113. enum exec_status sts;
  2114. struct hisi_sas_complete_v2_hdr *complete_queue =
  2115. hisi_hba->complete_hdr[slot->cmplt_queue];
  2116. struct hisi_sas_complete_v2_hdr *complete_hdr =
  2117. &complete_queue[slot->cmplt_queue_slot];
  2118. unsigned long flags;
  2119. bool is_internal = slot->is_internal;
  2120. if (unlikely(!task || !task->lldd_task || !task->dev))
  2121. return -EINVAL;
  2122. ts = &task->task_status;
  2123. device = task->dev;
  2124. ha = device->port->ha;
  2125. sas_dev = device->lldd_dev;
  2126. spin_lock_irqsave(&task->task_state_lock, flags);
  2127. task->task_state_flags &=
  2128. ~(SAS_TASK_STATE_PENDING | SAS_TASK_AT_INITIATOR);
  2129. spin_unlock_irqrestore(&task->task_state_lock, flags);
  2130. memset(ts, 0, sizeof(*ts));
  2131. ts->resp = SAS_TASK_COMPLETE;
  2132. if (unlikely(!sas_dev)) {
  2133. dev_dbg(dev, "slot complete: port has no device\n");
  2134. ts->stat = SAS_PHY_DOWN;
  2135. goto out;
  2136. }
  2137. /* Use SAS+TMF status codes */
  2138. switch ((complete_hdr->dw0 & CMPLT_HDR_ABORT_STAT_MSK)
  2139. >> CMPLT_HDR_ABORT_STAT_OFF) {
  2140. case STAT_IO_ABORTED:
  2141. /* this io has been aborted by abort command */
  2142. ts->stat = SAS_ABORTED_TASK;
  2143. goto out;
  2144. case STAT_IO_COMPLETE:
  2145. /* internal abort command complete */
  2146. ts->stat = TMF_RESP_FUNC_SUCC;
  2147. del_timer(&slot->internal_abort_timer);
  2148. goto out;
  2149. case STAT_IO_NO_DEVICE:
  2150. ts->stat = TMF_RESP_FUNC_COMPLETE;
  2151. del_timer(&slot->internal_abort_timer);
  2152. goto out;
  2153. case STAT_IO_NOT_VALID:
  2154. /* abort single io, controller don't find
  2155. * the io need to abort
  2156. */
  2157. ts->stat = TMF_RESP_FUNC_FAILED;
  2158. del_timer(&slot->internal_abort_timer);
  2159. goto out;
  2160. default:
  2161. break;
  2162. }
  2163. if ((complete_hdr->dw0 & CMPLT_HDR_ERX_MSK) &&
  2164. (!(complete_hdr->dw0 & CMPLT_HDR_RSPNS_XFRD_MSK))) {
  2165. u32 err_phase = (complete_hdr->dw0 & CMPLT_HDR_ERR_PHASE_MSK)
  2166. >> CMPLT_HDR_ERR_PHASE_OFF;
  2167. u32 *error_info = hisi_sas_status_buf_addr_mem(slot);
  2168. /* Analyse error happens on which phase TX or RX */
  2169. if (ERR_ON_TX_PHASE(err_phase))
  2170. slot_err_v2_hw(hisi_hba, task, slot, 1);
  2171. else if (ERR_ON_RX_PHASE(err_phase))
  2172. slot_err_v2_hw(hisi_hba, task, slot, 2);
  2173. if (ts->stat != SAS_DATA_UNDERRUN)
  2174. dev_info(dev, "erroneous completion iptt=%d task=%p dev id=%d "
  2175. "CQ hdr: 0x%x 0x%x 0x%x 0x%x "
  2176. "Error info: 0x%x 0x%x 0x%x 0x%x\n",
  2177. slot->idx, task, sas_dev->device_id,
  2178. complete_hdr->dw0, complete_hdr->dw1,
  2179. complete_hdr->act, complete_hdr->dw3,
  2180. error_info[0], error_info[1],
  2181. error_info[2], error_info[3]);
  2182. if (unlikely(slot->abort))
  2183. return ts->stat;
  2184. goto out;
  2185. }
  2186. switch (task->task_proto) {
  2187. case SAS_PROTOCOL_SSP:
  2188. {
  2189. struct hisi_sas_status_buffer *status_buffer =
  2190. hisi_sas_status_buf_addr_mem(slot);
  2191. struct ssp_response_iu *iu = (struct ssp_response_iu *)
  2192. &status_buffer->iu[0];
  2193. sas_ssp_task_response(dev, task, iu);
  2194. break;
  2195. }
  2196. case SAS_PROTOCOL_SMP:
  2197. {
  2198. struct scatterlist *sg_resp = &task->smp_task.smp_resp;
  2199. void *to;
  2200. ts->stat = SAM_STAT_GOOD;
  2201. to = kmap_atomic(sg_page(sg_resp));
  2202. dma_unmap_sg(dev, &task->smp_task.smp_resp, 1,
  2203. DMA_FROM_DEVICE);
  2204. dma_unmap_sg(dev, &task->smp_task.smp_req, 1,
  2205. DMA_TO_DEVICE);
  2206. memcpy(to + sg_resp->offset,
  2207. hisi_sas_status_buf_addr_mem(slot) +
  2208. sizeof(struct hisi_sas_err_record),
  2209. sg_dma_len(sg_resp));
  2210. kunmap_atomic(to);
  2211. break;
  2212. }
  2213. case SAS_PROTOCOL_SATA:
  2214. case SAS_PROTOCOL_STP:
  2215. case SAS_PROTOCOL_SATA | SAS_PROTOCOL_STP:
  2216. {
  2217. ts->stat = SAM_STAT_GOOD;
  2218. hisi_sas_sata_done(task, slot);
  2219. break;
  2220. }
  2221. default:
  2222. ts->stat = SAM_STAT_CHECK_CONDITION;
  2223. break;
  2224. }
  2225. if (!slot->port->port_attached) {
  2226. dev_warn(dev, "slot complete: port %d has removed\n",
  2227. slot->port->sas_port.id);
  2228. ts->stat = SAS_PHY_DOWN;
  2229. }
  2230. out:
  2231. sts = ts->stat;
  2232. spin_lock_irqsave(&task->task_state_lock, flags);
  2233. if (task->task_state_flags & SAS_TASK_STATE_ABORTED) {
  2234. spin_unlock_irqrestore(&task->task_state_lock, flags);
  2235. dev_info(dev, "slot complete: task(%p) aborted\n", task);
  2236. return SAS_ABORTED_TASK;
  2237. }
  2238. task->task_state_flags |= SAS_TASK_STATE_DONE;
  2239. spin_unlock_irqrestore(&task->task_state_lock, flags);
  2240. hisi_sas_slot_task_free(hisi_hba, task, slot);
  2241. if (!is_internal && (task->task_proto != SAS_PROTOCOL_SMP)) {
  2242. spin_lock_irqsave(&device->done_lock, flags);
  2243. if (test_bit(SAS_HA_FROZEN, &ha->state)) {
  2244. spin_unlock_irqrestore(&device->done_lock, flags);
  2245. dev_info(dev, "slot complete: task(%p) ignored\n ",
  2246. task);
  2247. return sts;
  2248. }
  2249. spin_unlock_irqrestore(&device->done_lock, flags);
  2250. }
  2251. if (task->task_done)
  2252. task->task_done(task);
  2253. return sts;
  2254. }
  2255. static void prep_ata_v2_hw(struct hisi_hba *hisi_hba,
  2256. struct hisi_sas_slot *slot)
  2257. {
  2258. struct sas_task *task = slot->task;
  2259. struct domain_device *device = task->dev;
  2260. struct domain_device *parent_dev = device->parent;
  2261. struct hisi_sas_device *sas_dev = device->lldd_dev;
  2262. struct hisi_sas_cmd_hdr *hdr = slot->cmd_hdr;
  2263. struct asd_sas_port *sas_port = device->port;
  2264. struct hisi_sas_port *port = to_hisi_sas_port(sas_port);
  2265. struct hisi_sas_tmf_task *tmf = slot->tmf;
  2266. u8 *buf_cmd;
  2267. int has_data = 0, hdr_tag = 0;
  2268. u32 dw1 = 0, dw2 = 0;
  2269. /* create header */
  2270. /* dw0 */
  2271. hdr->dw0 = cpu_to_le32(port->id << CMD_HDR_PORT_OFF);
  2272. if (parent_dev && DEV_IS_EXPANDER(parent_dev->dev_type))
  2273. hdr->dw0 |= cpu_to_le32(3 << CMD_HDR_CMD_OFF);
  2274. else
  2275. hdr->dw0 |= cpu_to_le32(4 << CMD_HDR_CMD_OFF);
  2276. if (tmf && tmf->force_phy) {
  2277. hdr->dw0 |= CMD_HDR_FORCE_PHY_MSK;
  2278. hdr->dw0 |= cpu_to_le32((1 << tmf->phy_id)
  2279. << CMD_HDR_PHY_ID_OFF);
  2280. }
  2281. /* dw1 */
  2282. switch (task->data_dir) {
  2283. case DMA_TO_DEVICE:
  2284. has_data = 1;
  2285. dw1 |= DIR_TO_DEVICE << CMD_HDR_DIR_OFF;
  2286. break;
  2287. case DMA_FROM_DEVICE:
  2288. has_data = 1;
  2289. dw1 |= DIR_TO_INI << CMD_HDR_DIR_OFF;
  2290. break;
  2291. default:
  2292. dw1 &= ~CMD_HDR_DIR_MSK;
  2293. }
  2294. if ((task->ata_task.fis.command == ATA_CMD_DEV_RESET) &&
  2295. (task->ata_task.fis.control & ATA_SRST))
  2296. dw1 |= 1 << CMD_HDR_RESET_OFF;
  2297. dw1 |= (hisi_sas_get_ata_protocol(
  2298. &task->ata_task.fis, task->data_dir))
  2299. << CMD_HDR_FRAME_TYPE_OFF;
  2300. dw1 |= sas_dev->device_id << CMD_HDR_DEV_ID_OFF;
  2301. hdr->dw1 = cpu_to_le32(dw1);
  2302. /* dw2 */
  2303. if (task->ata_task.use_ncq && hisi_sas_get_ncq_tag(task, &hdr_tag)) {
  2304. task->ata_task.fis.sector_count |= (u8) (hdr_tag << 3);
  2305. dw2 |= hdr_tag << CMD_HDR_NCQ_TAG_OFF;
  2306. }
  2307. dw2 |= (HISI_SAS_MAX_STP_RESP_SZ / 4) << CMD_HDR_CFL_OFF |
  2308. 2 << CMD_HDR_SG_MOD_OFF;
  2309. hdr->dw2 = cpu_to_le32(dw2);
  2310. /* dw3 */
  2311. hdr->transfer_tags = cpu_to_le32(slot->idx);
  2312. if (has_data)
  2313. prep_prd_sge_v2_hw(hisi_hba, slot, hdr, task->scatter,
  2314. slot->n_elem);
  2315. hdr->data_transfer_len = cpu_to_le32(task->total_xfer_len);
  2316. hdr->cmd_table_addr = cpu_to_le64(hisi_sas_cmd_hdr_addr_dma(slot));
  2317. hdr->sts_buffer_addr = cpu_to_le64(hisi_sas_status_buf_addr_dma(slot));
  2318. buf_cmd = hisi_sas_cmd_hdr_addr_mem(slot);
  2319. if (likely(!task->ata_task.device_control_reg_update))
  2320. task->ata_task.fis.flags |= 0x80; /* C=1: update ATA cmd reg */
  2321. /* fill in command FIS */
  2322. memcpy(buf_cmd, &task->ata_task.fis, sizeof(struct host_to_dev_fis));
  2323. }
  2324. static void hisi_sas_internal_abort_quirk_timeout(struct timer_list *t)
  2325. {
  2326. struct hisi_sas_slot *slot = from_timer(slot, t, internal_abort_timer);
  2327. struct hisi_sas_port *port = slot->port;
  2328. struct asd_sas_port *asd_sas_port;
  2329. struct asd_sas_phy *sas_phy;
  2330. if (!port)
  2331. return;
  2332. asd_sas_port = &port->sas_port;
  2333. /* Kick the hardware - send break command */
  2334. list_for_each_entry(sas_phy, &asd_sas_port->phy_list, port_phy_el) {
  2335. struct hisi_sas_phy *phy = sas_phy->lldd_phy;
  2336. struct hisi_hba *hisi_hba = phy->hisi_hba;
  2337. int phy_no = sas_phy->id;
  2338. u32 link_dfx2;
  2339. link_dfx2 = hisi_sas_phy_read32(hisi_hba, phy_no, LINK_DFX2);
  2340. if ((link_dfx2 == LINK_DFX2_RCVR_HOLD_STS_MSK) ||
  2341. (link_dfx2 & LINK_DFX2_SEND_HOLD_STS_MSK)) {
  2342. u32 txid_auto;
  2343. txid_auto = hisi_sas_phy_read32(hisi_hba, phy_no,
  2344. TXID_AUTO);
  2345. txid_auto |= TXID_AUTO_CTB_MSK;
  2346. hisi_sas_phy_write32(hisi_hba, phy_no, TXID_AUTO,
  2347. txid_auto);
  2348. return;
  2349. }
  2350. }
  2351. }
  2352. static void prep_abort_v2_hw(struct hisi_hba *hisi_hba,
  2353. struct hisi_sas_slot *slot,
  2354. int device_id, int abort_flag, int tag_to_abort)
  2355. {
  2356. struct sas_task *task = slot->task;
  2357. struct domain_device *dev = task->dev;
  2358. struct hisi_sas_cmd_hdr *hdr = slot->cmd_hdr;
  2359. struct hisi_sas_port *port = slot->port;
  2360. struct timer_list *timer = &slot->internal_abort_timer;
  2361. /* setup the quirk timer */
  2362. timer_setup(timer, hisi_sas_internal_abort_quirk_timeout, 0);
  2363. /* Set the timeout to 10ms less than internal abort timeout */
  2364. mod_timer(timer, jiffies + msecs_to_jiffies(100));
  2365. /* dw0 */
  2366. hdr->dw0 = cpu_to_le32((5 << CMD_HDR_CMD_OFF) | /*abort*/
  2367. (port->id << CMD_HDR_PORT_OFF) |
  2368. (dev_is_sata(dev) <<
  2369. CMD_HDR_ABORT_DEVICE_TYPE_OFF) |
  2370. (abort_flag << CMD_HDR_ABORT_FLAG_OFF));
  2371. /* dw1 */
  2372. hdr->dw1 = cpu_to_le32(device_id << CMD_HDR_DEV_ID_OFF);
  2373. /* dw7 */
  2374. hdr->dw7 = cpu_to_le32(tag_to_abort << CMD_HDR_ABORT_IPTT_OFF);
  2375. hdr->transfer_tags = cpu_to_le32(slot->idx);
  2376. }
  2377. static int phy_up_v2_hw(int phy_no, struct hisi_hba *hisi_hba)
  2378. {
  2379. int i, res = IRQ_HANDLED;
  2380. u32 port_id, link_rate;
  2381. struct hisi_sas_phy *phy = &hisi_hba->phy[phy_no];
  2382. struct asd_sas_phy *sas_phy = &phy->sas_phy;
  2383. struct device *dev = hisi_hba->dev;
  2384. u32 *frame_rcvd = (u32 *)sas_phy->frame_rcvd;
  2385. struct sas_identify_frame *id = (struct sas_identify_frame *)frame_rcvd;
  2386. unsigned long flags;
  2387. hisi_sas_phy_write32(hisi_hba, phy_no, PHYCTRL_PHY_ENA_MSK, 1);
  2388. if (is_sata_phy_v2_hw(hisi_hba, phy_no))
  2389. goto end;
  2390. if (phy_no == 8) {
  2391. u32 port_state = hisi_sas_read32(hisi_hba, PORT_STATE);
  2392. port_id = (port_state & PORT_STATE_PHY8_PORT_NUM_MSK) >>
  2393. PORT_STATE_PHY8_PORT_NUM_OFF;
  2394. link_rate = (port_state & PORT_STATE_PHY8_CONN_RATE_MSK) >>
  2395. PORT_STATE_PHY8_CONN_RATE_OFF;
  2396. } else {
  2397. port_id = hisi_sas_read32(hisi_hba, PHY_PORT_NUM_MA);
  2398. port_id = (port_id >> (4 * phy_no)) & 0xf;
  2399. link_rate = hisi_sas_read32(hisi_hba, PHY_CONN_RATE);
  2400. link_rate = (link_rate >> (phy_no * 4)) & 0xf;
  2401. }
  2402. if (port_id == 0xf) {
  2403. dev_err(dev, "phyup: phy%d invalid portid\n", phy_no);
  2404. res = IRQ_NONE;
  2405. goto end;
  2406. }
  2407. for (i = 0; i < 6; i++) {
  2408. u32 idaf = hisi_sas_phy_read32(hisi_hba, phy_no,
  2409. RX_IDAF_DWORD0 + (i * 4));
  2410. frame_rcvd[i] = __swab32(idaf);
  2411. }
  2412. sas_phy->linkrate = link_rate;
  2413. sas_phy->oob_mode = SAS_OOB_MODE;
  2414. memcpy(sas_phy->attached_sas_addr, &id->sas_addr, SAS_ADDR_SIZE);
  2415. dev_info(dev, "phyup: phy%d link_rate=%d\n", phy_no, link_rate);
  2416. phy->port_id = port_id;
  2417. phy->phy_type &= ~(PORT_TYPE_SAS | PORT_TYPE_SATA);
  2418. phy->phy_type |= PORT_TYPE_SAS;
  2419. phy->phy_attached = 1;
  2420. phy->identify.device_type = id->dev_type;
  2421. phy->frame_rcvd_size = sizeof(struct sas_identify_frame);
  2422. if (phy->identify.device_type == SAS_END_DEVICE)
  2423. phy->identify.target_port_protocols =
  2424. SAS_PROTOCOL_SSP;
  2425. else if (phy->identify.device_type != SAS_PHY_UNUSED) {
  2426. phy->identify.target_port_protocols =
  2427. SAS_PROTOCOL_SMP;
  2428. if (!timer_pending(&hisi_hba->timer))
  2429. set_link_timer_quirk(hisi_hba);
  2430. }
  2431. hisi_sas_notify_phy_event(phy, HISI_PHYE_PHY_UP);
  2432. spin_lock_irqsave(&phy->lock, flags);
  2433. if (phy->reset_completion) {
  2434. phy->in_reset = 0;
  2435. complete(phy->reset_completion);
  2436. }
  2437. spin_unlock_irqrestore(&phy->lock, flags);
  2438. end:
  2439. hisi_sas_phy_write32(hisi_hba, phy_no, CHL_INT0,
  2440. CHL_INT0_SL_PHY_ENABLE_MSK);
  2441. hisi_sas_phy_write32(hisi_hba, phy_no, PHYCTRL_PHY_ENA_MSK, 0);
  2442. return res;
  2443. }
  2444. static bool check_any_wideports_v2_hw(struct hisi_hba *hisi_hba)
  2445. {
  2446. u32 port_state;
  2447. port_state = hisi_sas_read32(hisi_hba, PORT_STATE);
  2448. if (port_state & 0x1ff)
  2449. return true;
  2450. return false;
  2451. }
  2452. static int phy_down_v2_hw(int phy_no, struct hisi_hba *hisi_hba)
  2453. {
  2454. u32 phy_state, sl_ctrl, txid_auto;
  2455. struct hisi_sas_phy *phy = &hisi_hba->phy[phy_no];
  2456. struct hisi_sas_port *port = phy->port;
  2457. struct device *dev = hisi_hba->dev;
  2458. hisi_sas_phy_write32(hisi_hba, phy_no, PHYCTRL_NOT_RDY_MSK, 1);
  2459. phy_state = hisi_sas_read32(hisi_hba, PHY_STATE);
  2460. dev_info(dev, "phydown: phy%d phy_state=0x%x\n", phy_no, phy_state);
  2461. hisi_sas_phy_down(hisi_hba, phy_no, (phy_state & 1 << phy_no) ? 1 : 0);
  2462. sl_ctrl = hisi_sas_phy_read32(hisi_hba, phy_no, SL_CONTROL);
  2463. hisi_sas_phy_write32(hisi_hba, phy_no, SL_CONTROL,
  2464. sl_ctrl & ~SL_CONTROL_CTA_MSK);
  2465. if (port && !get_wideport_bitmap_v2_hw(hisi_hba, port->id))
  2466. if (!check_any_wideports_v2_hw(hisi_hba) &&
  2467. timer_pending(&hisi_hba->timer))
  2468. del_timer(&hisi_hba->timer);
  2469. txid_auto = hisi_sas_phy_read32(hisi_hba, phy_no, TXID_AUTO);
  2470. hisi_sas_phy_write32(hisi_hba, phy_no, TXID_AUTO,
  2471. txid_auto | TXID_AUTO_CT3_MSK);
  2472. hisi_sas_phy_write32(hisi_hba, phy_no, CHL_INT0, CHL_INT0_NOT_RDY_MSK);
  2473. hisi_sas_phy_write32(hisi_hba, phy_no, PHYCTRL_NOT_RDY_MSK, 0);
  2474. return IRQ_HANDLED;
  2475. }
  2476. static irqreturn_t int_phy_updown_v2_hw(int irq_no, void *p)
  2477. {
  2478. struct hisi_hba *hisi_hba = p;
  2479. u32 irq_msk;
  2480. int phy_no = 0;
  2481. irqreturn_t res = IRQ_NONE;
  2482. irq_msk = (hisi_sas_read32(hisi_hba, HGC_INVLD_DQE_INFO)
  2483. >> HGC_INVLD_DQE_INFO_FB_CH0_OFF) & 0x1ff;
  2484. while (irq_msk) {
  2485. if (irq_msk & 1) {
  2486. u32 reg_value = hisi_sas_phy_read32(hisi_hba, phy_no,
  2487. CHL_INT0);
  2488. switch (reg_value & (CHL_INT0_NOT_RDY_MSK |
  2489. CHL_INT0_SL_PHY_ENABLE_MSK)) {
  2490. case CHL_INT0_SL_PHY_ENABLE_MSK:
  2491. /* phy up */
  2492. if (phy_up_v2_hw(phy_no, hisi_hba) ==
  2493. IRQ_HANDLED)
  2494. res = IRQ_HANDLED;
  2495. break;
  2496. case CHL_INT0_NOT_RDY_MSK:
  2497. /* phy down */
  2498. if (phy_down_v2_hw(phy_no, hisi_hba) ==
  2499. IRQ_HANDLED)
  2500. res = IRQ_HANDLED;
  2501. break;
  2502. case (CHL_INT0_NOT_RDY_MSK |
  2503. CHL_INT0_SL_PHY_ENABLE_MSK):
  2504. reg_value = hisi_sas_read32(hisi_hba,
  2505. PHY_STATE);
  2506. if (reg_value & BIT(phy_no)) {
  2507. /* phy up */
  2508. if (phy_up_v2_hw(phy_no, hisi_hba) ==
  2509. IRQ_HANDLED)
  2510. res = IRQ_HANDLED;
  2511. } else {
  2512. /* phy down */
  2513. if (phy_down_v2_hw(phy_no, hisi_hba) ==
  2514. IRQ_HANDLED)
  2515. res = IRQ_HANDLED;
  2516. }
  2517. break;
  2518. default:
  2519. break;
  2520. }
  2521. }
  2522. irq_msk >>= 1;
  2523. phy_no++;
  2524. }
  2525. return res;
  2526. }
  2527. static void phy_bcast_v2_hw(int phy_no, struct hisi_hba *hisi_hba)
  2528. {
  2529. struct hisi_sas_phy *phy = &hisi_hba->phy[phy_no];
  2530. struct asd_sas_phy *sas_phy = &phy->sas_phy;
  2531. struct sas_ha_struct *sas_ha = &hisi_hba->sha;
  2532. u32 bcast_status;
  2533. hisi_sas_phy_write32(hisi_hba, phy_no, SL_RX_BCAST_CHK_MSK, 1);
  2534. bcast_status = hisi_sas_phy_read32(hisi_hba, phy_no, RX_PRIMS_STATUS);
  2535. if ((bcast_status & RX_BCAST_CHG_MSK) &&
  2536. !test_bit(HISI_SAS_RESET_BIT, &hisi_hba->flags))
  2537. sas_ha->notify_port_event(sas_phy, PORTE_BROADCAST_RCVD);
  2538. hisi_sas_phy_write32(hisi_hba, phy_no, CHL_INT0,
  2539. CHL_INT0_SL_RX_BCST_ACK_MSK);
  2540. hisi_sas_phy_write32(hisi_hba, phy_no, SL_RX_BCAST_CHK_MSK, 0);
  2541. }
  2542. static const struct hisi_sas_hw_error port_ecc_axi_error[] = {
  2543. {
  2544. .irq_msk = BIT(CHL_INT1_DMAC_TX_ECC_ERR_OFF),
  2545. .msg = "dmac_tx_ecc_bad_err",
  2546. },
  2547. {
  2548. .irq_msk = BIT(CHL_INT1_DMAC_RX_ECC_ERR_OFF),
  2549. .msg = "dmac_rx_ecc_bad_err",
  2550. },
  2551. {
  2552. .irq_msk = BIT(CHL_INT1_DMAC_TX_AXI_WR_ERR_OFF),
  2553. .msg = "dma_tx_axi_wr_err",
  2554. },
  2555. {
  2556. .irq_msk = BIT(CHL_INT1_DMAC_TX_AXI_RD_ERR_OFF),
  2557. .msg = "dma_tx_axi_rd_err",
  2558. },
  2559. {
  2560. .irq_msk = BIT(CHL_INT1_DMAC_RX_AXI_WR_ERR_OFF),
  2561. .msg = "dma_rx_axi_wr_err",
  2562. },
  2563. {
  2564. .irq_msk = BIT(CHL_INT1_DMAC_RX_AXI_RD_ERR_OFF),
  2565. .msg = "dma_rx_axi_rd_err",
  2566. },
  2567. };
  2568. static irqreturn_t int_chnl_int_v2_hw(int irq_no, void *p)
  2569. {
  2570. struct hisi_hba *hisi_hba = p;
  2571. struct device *dev = hisi_hba->dev;
  2572. u32 ent_msk, ent_tmp, irq_msk;
  2573. int phy_no = 0;
  2574. ent_msk = hisi_sas_read32(hisi_hba, ENT_INT_SRC_MSK3);
  2575. ent_tmp = ent_msk;
  2576. ent_msk |= ENT_INT_SRC_MSK3_ENT95_MSK_MSK;
  2577. hisi_sas_write32(hisi_hba, ENT_INT_SRC_MSK3, ent_msk);
  2578. irq_msk = (hisi_sas_read32(hisi_hba, HGC_INVLD_DQE_INFO) >>
  2579. HGC_INVLD_DQE_INFO_FB_CH3_OFF) & 0x1ff;
  2580. while (irq_msk) {
  2581. u32 irq_value0 = hisi_sas_phy_read32(hisi_hba, phy_no,
  2582. CHL_INT0);
  2583. u32 irq_value1 = hisi_sas_phy_read32(hisi_hba, phy_no,
  2584. CHL_INT1);
  2585. u32 irq_value2 = hisi_sas_phy_read32(hisi_hba, phy_no,
  2586. CHL_INT2);
  2587. if ((irq_msk & (1 << phy_no)) && irq_value1) {
  2588. int i;
  2589. for (i = 0; i < ARRAY_SIZE(port_ecc_axi_error); i++) {
  2590. const struct hisi_sas_hw_error *error =
  2591. &port_ecc_axi_error[i];
  2592. if (!(irq_value1 & error->irq_msk))
  2593. continue;
  2594. dev_warn(dev, "%s error (phy%d 0x%x) found!\n",
  2595. error->msg, phy_no, irq_value1);
  2596. queue_work(hisi_hba->wq, &hisi_hba->rst_work);
  2597. }
  2598. hisi_sas_phy_write32(hisi_hba, phy_no,
  2599. CHL_INT1, irq_value1);
  2600. }
  2601. if ((irq_msk & (1 << phy_no)) && irq_value2) {
  2602. struct hisi_sas_phy *phy = &hisi_hba->phy[phy_no];
  2603. if (irq_value2 & BIT(CHL_INT2_SL_IDAF_TOUT_CONF_OFF)) {
  2604. dev_warn(dev, "phy%d identify timeout\n",
  2605. phy_no);
  2606. hisi_sas_notify_phy_event(phy,
  2607. HISI_PHYE_LINK_RESET);
  2608. }
  2609. hisi_sas_phy_write32(hisi_hba, phy_no,
  2610. CHL_INT2, irq_value2);
  2611. }
  2612. if ((irq_msk & (1 << phy_no)) && irq_value0) {
  2613. if (irq_value0 & CHL_INT0_SL_RX_BCST_ACK_MSK)
  2614. phy_bcast_v2_hw(phy_no, hisi_hba);
  2615. hisi_sas_phy_write32(hisi_hba, phy_no,
  2616. CHL_INT0, irq_value0
  2617. & (~CHL_INT0_HOTPLUG_TOUT_MSK)
  2618. & (~CHL_INT0_SL_PHY_ENABLE_MSK)
  2619. & (~CHL_INT0_NOT_RDY_MSK));
  2620. }
  2621. irq_msk &= ~(1 << phy_no);
  2622. phy_no++;
  2623. }
  2624. hisi_sas_write32(hisi_hba, ENT_INT_SRC_MSK3, ent_tmp);
  2625. return IRQ_HANDLED;
  2626. }
  2627. static void
  2628. one_bit_ecc_error_process_v2_hw(struct hisi_hba *hisi_hba, u32 irq_value)
  2629. {
  2630. struct device *dev = hisi_hba->dev;
  2631. const struct hisi_sas_hw_error *ecc_error;
  2632. u32 val;
  2633. int i;
  2634. for (i = 0; i < ARRAY_SIZE(one_bit_ecc_errors); i++) {
  2635. ecc_error = &one_bit_ecc_errors[i];
  2636. if (irq_value & ecc_error->irq_msk) {
  2637. val = hisi_sas_read32(hisi_hba, ecc_error->reg);
  2638. val &= ecc_error->msk;
  2639. val >>= ecc_error->shift;
  2640. dev_warn(dev, ecc_error->msg, val);
  2641. }
  2642. }
  2643. }
  2644. static void multi_bit_ecc_error_process_v2_hw(struct hisi_hba *hisi_hba,
  2645. u32 irq_value)
  2646. {
  2647. struct device *dev = hisi_hba->dev;
  2648. const struct hisi_sas_hw_error *ecc_error;
  2649. u32 val;
  2650. int i;
  2651. for (i = 0; i < ARRAY_SIZE(multi_bit_ecc_errors); i++) {
  2652. ecc_error = &multi_bit_ecc_errors[i];
  2653. if (irq_value & ecc_error->irq_msk) {
  2654. val = hisi_sas_read32(hisi_hba, ecc_error->reg);
  2655. val &= ecc_error->msk;
  2656. val >>= ecc_error->shift;
  2657. dev_err(dev, ecc_error->msg, irq_value, val);
  2658. queue_work(hisi_hba->wq, &hisi_hba->rst_work);
  2659. }
  2660. }
  2661. return;
  2662. }
  2663. static irqreturn_t fatal_ecc_int_v2_hw(int irq_no, void *p)
  2664. {
  2665. struct hisi_hba *hisi_hba = p;
  2666. u32 irq_value, irq_msk;
  2667. irq_msk = hisi_sas_read32(hisi_hba, SAS_ECC_INTR_MSK);
  2668. hisi_sas_write32(hisi_hba, SAS_ECC_INTR_MSK, irq_msk | 0xffffffff);
  2669. irq_value = hisi_sas_read32(hisi_hba, SAS_ECC_INTR);
  2670. if (irq_value) {
  2671. one_bit_ecc_error_process_v2_hw(hisi_hba, irq_value);
  2672. multi_bit_ecc_error_process_v2_hw(hisi_hba, irq_value);
  2673. }
  2674. hisi_sas_write32(hisi_hba, SAS_ECC_INTR, irq_value);
  2675. hisi_sas_write32(hisi_hba, SAS_ECC_INTR_MSK, irq_msk);
  2676. return IRQ_HANDLED;
  2677. }
  2678. static const struct hisi_sas_hw_error axi_error[] = {
  2679. { .msk = BIT(0), .msg = "IOST_AXI_W_ERR" },
  2680. { .msk = BIT(1), .msg = "IOST_AXI_R_ERR" },
  2681. { .msk = BIT(2), .msg = "ITCT_AXI_W_ERR" },
  2682. { .msk = BIT(3), .msg = "ITCT_AXI_R_ERR" },
  2683. { .msk = BIT(4), .msg = "SATA_AXI_W_ERR" },
  2684. { .msk = BIT(5), .msg = "SATA_AXI_R_ERR" },
  2685. { .msk = BIT(6), .msg = "DQE_AXI_R_ERR" },
  2686. { .msk = BIT(7), .msg = "CQE_AXI_W_ERR" },
  2687. {},
  2688. };
  2689. static const struct hisi_sas_hw_error fifo_error[] = {
  2690. { .msk = BIT(8), .msg = "CQE_WINFO_FIFO" },
  2691. { .msk = BIT(9), .msg = "CQE_MSG_FIFIO" },
  2692. { .msk = BIT(10), .msg = "GETDQE_FIFO" },
  2693. { .msk = BIT(11), .msg = "CMDP_FIFO" },
  2694. { .msk = BIT(12), .msg = "AWTCTRL_FIFO" },
  2695. {},
  2696. };
  2697. static const struct hisi_sas_hw_error fatal_axi_errors[] = {
  2698. {
  2699. .irq_msk = BIT(ENT_INT_SRC3_WP_DEPTH_OFF),
  2700. .msg = "write pointer and depth",
  2701. },
  2702. {
  2703. .irq_msk = BIT(ENT_INT_SRC3_IPTT_SLOT_NOMATCH_OFF),
  2704. .msg = "iptt no match slot",
  2705. },
  2706. {
  2707. .irq_msk = BIT(ENT_INT_SRC3_RP_DEPTH_OFF),
  2708. .msg = "read pointer and depth",
  2709. },
  2710. {
  2711. .irq_msk = BIT(ENT_INT_SRC3_AXI_OFF),
  2712. .reg = HGC_AXI_FIFO_ERR_INFO,
  2713. .sub = axi_error,
  2714. },
  2715. {
  2716. .irq_msk = BIT(ENT_INT_SRC3_FIFO_OFF),
  2717. .reg = HGC_AXI_FIFO_ERR_INFO,
  2718. .sub = fifo_error,
  2719. },
  2720. {
  2721. .irq_msk = BIT(ENT_INT_SRC3_LM_OFF),
  2722. .msg = "LM add/fetch list",
  2723. },
  2724. {
  2725. .irq_msk = BIT(ENT_INT_SRC3_ABT_OFF),
  2726. .msg = "SAS_HGC_ABT fetch LM list",
  2727. },
  2728. };
  2729. static irqreturn_t fatal_axi_int_v2_hw(int irq_no, void *p)
  2730. {
  2731. struct hisi_hba *hisi_hba = p;
  2732. u32 irq_value, irq_msk, err_value;
  2733. struct device *dev = hisi_hba->dev;
  2734. const struct hisi_sas_hw_error *axi_error;
  2735. int i;
  2736. irq_msk = hisi_sas_read32(hisi_hba, ENT_INT_SRC_MSK3);
  2737. hisi_sas_write32(hisi_hba, ENT_INT_SRC_MSK3, irq_msk | 0xfffffffe);
  2738. irq_value = hisi_sas_read32(hisi_hba, ENT_INT_SRC3);
  2739. for (i = 0; i < ARRAY_SIZE(fatal_axi_errors); i++) {
  2740. axi_error = &fatal_axi_errors[i];
  2741. if (!(irq_value & axi_error->irq_msk))
  2742. continue;
  2743. hisi_sas_write32(hisi_hba, ENT_INT_SRC3,
  2744. 1 << axi_error->shift);
  2745. if (axi_error->sub) {
  2746. const struct hisi_sas_hw_error *sub = axi_error->sub;
  2747. err_value = hisi_sas_read32(hisi_hba, axi_error->reg);
  2748. for (; sub->msk || sub->msg; sub++) {
  2749. if (!(err_value & sub->msk))
  2750. continue;
  2751. dev_err(dev, "%s (0x%x) found!\n",
  2752. sub->msg, irq_value);
  2753. queue_work(hisi_hba->wq, &hisi_hba->rst_work);
  2754. }
  2755. } else {
  2756. dev_err(dev, "%s (0x%x) found!\n",
  2757. axi_error->msg, irq_value);
  2758. queue_work(hisi_hba->wq, &hisi_hba->rst_work);
  2759. }
  2760. }
  2761. if (irq_value & BIT(ENT_INT_SRC3_ITC_INT_OFF)) {
  2762. u32 reg_val = hisi_sas_read32(hisi_hba, ITCT_CLR);
  2763. u32 dev_id = reg_val & ITCT_DEV_MSK;
  2764. struct hisi_sas_device *sas_dev = &hisi_hba->devices[dev_id];
  2765. hisi_sas_write32(hisi_hba, ITCT_CLR, 0);
  2766. dev_dbg(dev, "clear ITCT ok\n");
  2767. complete(sas_dev->completion);
  2768. }
  2769. hisi_sas_write32(hisi_hba, ENT_INT_SRC3, irq_value);
  2770. hisi_sas_write32(hisi_hba, ENT_INT_SRC_MSK3, irq_msk);
  2771. return IRQ_HANDLED;
  2772. }
  2773. static void cq_tasklet_v2_hw(unsigned long val)
  2774. {
  2775. struct hisi_sas_cq *cq = (struct hisi_sas_cq *)val;
  2776. struct hisi_hba *hisi_hba = cq->hisi_hba;
  2777. struct hisi_sas_slot *slot;
  2778. struct hisi_sas_itct *itct;
  2779. struct hisi_sas_complete_v2_hdr *complete_queue;
  2780. u32 rd_point = cq->rd_point, wr_point, dev_id;
  2781. int queue = cq->id;
  2782. if (unlikely(hisi_hba->reject_stp_links_msk))
  2783. phys_try_accept_stp_links_v2_hw(hisi_hba);
  2784. complete_queue = hisi_hba->complete_hdr[queue];
  2785. wr_point = hisi_sas_read32(hisi_hba, COMPL_Q_0_WR_PTR +
  2786. (0x14 * queue));
  2787. while (rd_point != wr_point) {
  2788. struct hisi_sas_complete_v2_hdr *complete_hdr;
  2789. int iptt;
  2790. complete_hdr = &complete_queue[rd_point];
  2791. /* Check for NCQ completion */
  2792. if (complete_hdr->act) {
  2793. u32 act_tmp = complete_hdr->act;
  2794. int ncq_tag_count = ffs(act_tmp);
  2795. dev_id = (complete_hdr->dw1 & CMPLT_HDR_DEV_ID_MSK) >>
  2796. CMPLT_HDR_DEV_ID_OFF;
  2797. itct = &hisi_hba->itct[dev_id];
  2798. /* The NCQ tags are held in the itct header */
  2799. while (ncq_tag_count) {
  2800. __le64 *ncq_tag = &itct->qw4_15[0];
  2801. ncq_tag_count -= 1;
  2802. iptt = (ncq_tag[ncq_tag_count / 5]
  2803. >> (ncq_tag_count % 5) * 12) & 0xfff;
  2804. slot = &hisi_hba->slot_info[iptt];
  2805. slot->cmplt_queue_slot = rd_point;
  2806. slot->cmplt_queue = queue;
  2807. slot_complete_v2_hw(hisi_hba, slot);
  2808. act_tmp &= ~(1 << ncq_tag_count);
  2809. ncq_tag_count = ffs(act_tmp);
  2810. }
  2811. } else {
  2812. iptt = (complete_hdr->dw1) & CMPLT_HDR_IPTT_MSK;
  2813. slot = &hisi_hba->slot_info[iptt];
  2814. slot->cmplt_queue_slot = rd_point;
  2815. slot->cmplt_queue = queue;
  2816. slot_complete_v2_hw(hisi_hba, slot);
  2817. }
  2818. if (++rd_point >= HISI_SAS_QUEUE_SLOTS)
  2819. rd_point = 0;
  2820. }
  2821. /* update rd_point */
  2822. cq->rd_point = rd_point;
  2823. hisi_sas_write32(hisi_hba, COMPL_Q_0_RD_PTR + (0x14 * queue), rd_point);
  2824. }
  2825. static irqreturn_t cq_interrupt_v2_hw(int irq_no, void *p)
  2826. {
  2827. struct hisi_sas_cq *cq = p;
  2828. struct hisi_hba *hisi_hba = cq->hisi_hba;
  2829. int queue = cq->id;
  2830. hisi_sas_write32(hisi_hba, OQ_INT_SRC, 1 << queue);
  2831. tasklet_schedule(&cq->tasklet);
  2832. return IRQ_HANDLED;
  2833. }
  2834. static irqreturn_t sata_int_v2_hw(int irq_no, void *p)
  2835. {
  2836. struct hisi_sas_phy *phy = p;
  2837. struct hisi_hba *hisi_hba = phy->hisi_hba;
  2838. struct asd_sas_phy *sas_phy = &phy->sas_phy;
  2839. struct device *dev = hisi_hba->dev;
  2840. struct hisi_sas_initial_fis *initial_fis;
  2841. struct dev_to_host_fis *fis;
  2842. u32 ent_tmp, ent_msk, ent_int, port_id, link_rate, hard_phy_linkrate;
  2843. irqreturn_t res = IRQ_HANDLED;
  2844. u8 attached_sas_addr[SAS_ADDR_SIZE] = {0};
  2845. unsigned long flags;
  2846. int phy_no, offset;
  2847. phy_no = sas_phy->id;
  2848. initial_fis = &hisi_hba->initial_fis[phy_no];
  2849. fis = &initial_fis->fis;
  2850. offset = 4 * (phy_no / 4);
  2851. ent_msk = hisi_sas_read32(hisi_hba, ENT_INT_SRC_MSK1 + offset);
  2852. hisi_sas_write32(hisi_hba, ENT_INT_SRC_MSK1 + offset,
  2853. ent_msk | 1 << ((phy_no % 4) * 8));
  2854. ent_int = hisi_sas_read32(hisi_hba, ENT_INT_SRC1 + offset);
  2855. ent_tmp = ent_int & (1 << (ENT_INT_SRC1_D2H_FIS_CH1_OFF *
  2856. (phy_no % 4)));
  2857. ent_int >>= ENT_INT_SRC1_D2H_FIS_CH1_OFF * (phy_no % 4);
  2858. if ((ent_int & ENT_INT_SRC1_D2H_FIS_CH0_MSK) == 0) {
  2859. dev_warn(dev, "sata int: phy%d did not receive FIS\n", phy_no);
  2860. res = IRQ_NONE;
  2861. goto end;
  2862. }
  2863. /* check ERR bit of Status Register */
  2864. if (fis->status & ATA_ERR) {
  2865. dev_warn(dev, "sata int: phy%d FIS status: 0x%x\n", phy_no,
  2866. fis->status);
  2867. hisi_sas_notify_phy_event(phy, HISI_PHYE_LINK_RESET);
  2868. res = IRQ_NONE;
  2869. goto end;
  2870. }
  2871. if (unlikely(phy_no == 8)) {
  2872. u32 port_state = hisi_sas_read32(hisi_hba, PORT_STATE);
  2873. port_id = (port_state & PORT_STATE_PHY8_PORT_NUM_MSK) >>
  2874. PORT_STATE_PHY8_PORT_NUM_OFF;
  2875. link_rate = (port_state & PORT_STATE_PHY8_CONN_RATE_MSK) >>
  2876. PORT_STATE_PHY8_CONN_RATE_OFF;
  2877. } else {
  2878. port_id = hisi_sas_read32(hisi_hba, PHY_PORT_NUM_MA);
  2879. port_id = (port_id >> (4 * phy_no)) & 0xf;
  2880. link_rate = hisi_sas_read32(hisi_hba, PHY_CONN_RATE);
  2881. link_rate = (link_rate >> (phy_no * 4)) & 0xf;
  2882. }
  2883. if (port_id == 0xf) {
  2884. dev_err(dev, "sata int: phy%d invalid portid\n", phy_no);
  2885. res = IRQ_NONE;
  2886. goto end;
  2887. }
  2888. sas_phy->linkrate = link_rate;
  2889. hard_phy_linkrate = hisi_sas_phy_read32(hisi_hba, phy_no,
  2890. HARD_PHY_LINKRATE);
  2891. phy->maximum_linkrate = hard_phy_linkrate & 0xf;
  2892. phy->minimum_linkrate = (hard_phy_linkrate >> 4) & 0xf;
  2893. sas_phy->oob_mode = SATA_OOB_MODE;
  2894. /* Make up some unique SAS address */
  2895. attached_sas_addr[0] = 0x50;
  2896. attached_sas_addr[6] = hisi_hba->shost->host_no;
  2897. attached_sas_addr[7] = phy_no;
  2898. memcpy(sas_phy->attached_sas_addr, attached_sas_addr, SAS_ADDR_SIZE);
  2899. memcpy(sas_phy->frame_rcvd, fis, sizeof(struct dev_to_host_fis));
  2900. dev_info(dev, "sata int phyup: phy%d link_rate=%d\n", phy_no, link_rate);
  2901. phy->phy_type &= ~(PORT_TYPE_SAS | PORT_TYPE_SATA);
  2902. phy->port_id = port_id;
  2903. phy->phy_type |= PORT_TYPE_SATA;
  2904. phy->phy_attached = 1;
  2905. phy->identify.device_type = SAS_SATA_DEV;
  2906. phy->frame_rcvd_size = sizeof(struct dev_to_host_fis);
  2907. phy->identify.target_port_protocols = SAS_PROTOCOL_SATA;
  2908. hisi_sas_notify_phy_event(phy, HISI_PHYE_PHY_UP);
  2909. spin_lock_irqsave(&phy->lock, flags);
  2910. if (phy->reset_completion) {
  2911. phy->in_reset = 0;
  2912. complete(phy->reset_completion);
  2913. }
  2914. spin_unlock_irqrestore(&phy->lock, flags);
  2915. end:
  2916. hisi_sas_write32(hisi_hba, ENT_INT_SRC1 + offset, ent_tmp);
  2917. hisi_sas_write32(hisi_hba, ENT_INT_SRC_MSK1 + offset, ent_msk);
  2918. return res;
  2919. }
  2920. static irq_handler_t phy_interrupts[HISI_SAS_PHY_INT_NR] = {
  2921. int_phy_updown_v2_hw,
  2922. int_chnl_int_v2_hw,
  2923. };
  2924. static irq_handler_t fatal_interrupts[HISI_SAS_FATAL_INT_NR] = {
  2925. fatal_ecc_int_v2_hw,
  2926. fatal_axi_int_v2_hw
  2927. };
  2928. /**
  2929. * There is a limitation in the hip06 chipset that we need
  2930. * to map in all mbigen interrupts, even if they are not used.
  2931. */
  2932. static int interrupt_init_v2_hw(struct hisi_hba *hisi_hba)
  2933. {
  2934. struct platform_device *pdev = hisi_hba->platform_dev;
  2935. struct device *dev = &pdev->dev;
  2936. int irq, rc, irq_map[128];
  2937. int i, phy_no, fatal_no, queue_no, k;
  2938. for (i = 0; i < 128; i++)
  2939. irq_map[i] = platform_get_irq(pdev, i);
  2940. for (i = 0; i < HISI_SAS_PHY_INT_NR; i++) {
  2941. irq = irq_map[i + 1]; /* Phy up/down is irq1 */
  2942. rc = devm_request_irq(dev, irq, phy_interrupts[i], 0,
  2943. DRV_NAME " phy", hisi_hba);
  2944. if (rc) {
  2945. dev_err(dev, "irq init: could not request "
  2946. "phy interrupt %d, rc=%d\n",
  2947. irq, rc);
  2948. rc = -ENOENT;
  2949. goto free_phy_int_irqs;
  2950. }
  2951. }
  2952. for (phy_no = 0; phy_no < hisi_hba->n_phy; phy_no++) {
  2953. struct hisi_sas_phy *phy = &hisi_hba->phy[phy_no];
  2954. irq = irq_map[phy_no + 72];
  2955. rc = devm_request_irq(dev, irq, sata_int_v2_hw, 0,
  2956. DRV_NAME " sata", phy);
  2957. if (rc) {
  2958. dev_err(dev, "irq init: could not request "
  2959. "sata interrupt %d, rc=%d\n",
  2960. irq, rc);
  2961. rc = -ENOENT;
  2962. goto free_sata_int_irqs;
  2963. }
  2964. }
  2965. for (fatal_no = 0; fatal_no < HISI_SAS_FATAL_INT_NR; fatal_no++) {
  2966. irq = irq_map[fatal_no + 81];
  2967. rc = devm_request_irq(dev, irq, fatal_interrupts[fatal_no], 0,
  2968. DRV_NAME " fatal", hisi_hba);
  2969. if (rc) {
  2970. dev_err(dev,
  2971. "irq init: could not request fatal interrupt %d, rc=%d\n",
  2972. irq, rc);
  2973. rc = -ENOENT;
  2974. goto free_fatal_int_irqs;
  2975. }
  2976. }
  2977. for (queue_no = 0; queue_no < hisi_hba->queue_count; queue_no++) {
  2978. struct hisi_sas_cq *cq = &hisi_hba->cq[queue_no];
  2979. struct tasklet_struct *t = &cq->tasklet;
  2980. irq = irq_map[queue_no + 96];
  2981. rc = devm_request_irq(dev, irq, cq_interrupt_v2_hw, 0,
  2982. DRV_NAME " cq", cq);
  2983. if (rc) {
  2984. dev_err(dev,
  2985. "irq init: could not request cq interrupt %d, rc=%d\n",
  2986. irq, rc);
  2987. rc = -ENOENT;
  2988. goto free_cq_int_irqs;
  2989. }
  2990. tasklet_init(t, cq_tasklet_v2_hw, (unsigned long)cq);
  2991. }
  2992. return 0;
  2993. free_cq_int_irqs:
  2994. for (k = 0; k < queue_no; k++) {
  2995. struct hisi_sas_cq *cq = &hisi_hba->cq[k];
  2996. free_irq(irq_map[k + 96], cq);
  2997. tasklet_kill(&cq->tasklet);
  2998. }
  2999. free_fatal_int_irqs:
  3000. for (k = 0; k < fatal_no; k++)
  3001. free_irq(irq_map[k + 81], hisi_hba);
  3002. free_sata_int_irqs:
  3003. for (k = 0; k < phy_no; k++) {
  3004. struct hisi_sas_phy *phy = &hisi_hba->phy[k];
  3005. free_irq(irq_map[k + 72], phy);
  3006. }
  3007. free_phy_int_irqs:
  3008. for (k = 0; k < i; k++)
  3009. free_irq(irq_map[k + 1], hisi_hba);
  3010. return rc;
  3011. }
  3012. static int hisi_sas_v2_init(struct hisi_hba *hisi_hba)
  3013. {
  3014. int rc;
  3015. memset(hisi_hba->sata_dev_bitmap, 0, sizeof(hisi_hba->sata_dev_bitmap));
  3016. rc = hw_init_v2_hw(hisi_hba);
  3017. if (rc)
  3018. return rc;
  3019. rc = interrupt_init_v2_hw(hisi_hba);
  3020. if (rc)
  3021. return rc;
  3022. return 0;
  3023. }
  3024. static void interrupt_disable_v2_hw(struct hisi_hba *hisi_hba)
  3025. {
  3026. struct platform_device *pdev = hisi_hba->platform_dev;
  3027. int i;
  3028. for (i = 0; i < hisi_hba->queue_count; i++)
  3029. hisi_sas_write32(hisi_hba, OQ0_INT_SRC_MSK + 0x4 * i, 0x1);
  3030. hisi_sas_write32(hisi_hba, ENT_INT_SRC_MSK1, 0xffffffff);
  3031. hisi_sas_write32(hisi_hba, ENT_INT_SRC_MSK2, 0xffffffff);
  3032. hisi_sas_write32(hisi_hba, ENT_INT_SRC_MSK3, 0xffffffff);
  3033. hisi_sas_write32(hisi_hba, SAS_ECC_INTR_MSK, 0xffffffff);
  3034. for (i = 0; i < hisi_hba->n_phy; i++) {
  3035. hisi_sas_phy_write32(hisi_hba, i, CHL_INT1_MSK, 0xffffffff);
  3036. hisi_sas_phy_write32(hisi_hba, i, CHL_INT2_MSK, 0xffffffff);
  3037. }
  3038. for (i = 0; i < 128; i++)
  3039. synchronize_irq(platform_get_irq(pdev, i));
  3040. }
  3041. static u32 get_phys_state_v2_hw(struct hisi_hba *hisi_hba)
  3042. {
  3043. return hisi_sas_read32(hisi_hba, PHY_STATE);
  3044. }
  3045. static int soft_reset_v2_hw(struct hisi_hba *hisi_hba)
  3046. {
  3047. struct device *dev = hisi_hba->dev;
  3048. int rc, cnt;
  3049. interrupt_disable_v2_hw(hisi_hba);
  3050. hisi_sas_write32(hisi_hba, DLVRY_QUEUE_ENABLE, 0x0);
  3051. hisi_sas_kill_tasklets(hisi_hba);
  3052. hisi_sas_stop_phys(hisi_hba);
  3053. mdelay(10);
  3054. hisi_sas_write32(hisi_hba, AXI_MASTER_CFG_BASE + AM_CTRL_GLOBAL, 0x1);
  3055. /* wait until bus idle */
  3056. cnt = 0;
  3057. while (1) {
  3058. u32 status = hisi_sas_read32_relaxed(hisi_hba,
  3059. AXI_MASTER_CFG_BASE + AM_CURR_TRANS_RETURN);
  3060. if (status == 0x3)
  3061. break;
  3062. udelay(10);
  3063. if (cnt++ > 10) {
  3064. dev_err(dev, "wait axi bus state to idle timeout!\n");
  3065. return -1;
  3066. }
  3067. }
  3068. hisi_sas_init_mem(hisi_hba);
  3069. rc = hw_init_v2_hw(hisi_hba);
  3070. if (rc)
  3071. return rc;
  3072. phys_reject_stp_links_v2_hw(hisi_hba);
  3073. return 0;
  3074. }
  3075. static int write_gpio_v2_hw(struct hisi_hba *hisi_hba, u8 reg_type,
  3076. u8 reg_index, u8 reg_count, u8 *write_data)
  3077. {
  3078. struct device *dev = hisi_hba->dev;
  3079. int phy_no, count;
  3080. if (!hisi_hba->sgpio_regs)
  3081. return -EOPNOTSUPP;
  3082. switch (reg_type) {
  3083. case SAS_GPIO_REG_TX:
  3084. count = reg_count * 4;
  3085. count = min(count, hisi_hba->n_phy);
  3086. for (phy_no = 0; phy_no < count; phy_no++) {
  3087. /*
  3088. * GPIO_TX[n] register has the highest numbered drive
  3089. * of the four in the first byte and the lowest
  3090. * numbered drive in the fourth byte.
  3091. * See SFF-8485 Rev. 0.7 Table 24.
  3092. */
  3093. void __iomem *reg_addr = hisi_hba->sgpio_regs +
  3094. reg_index * 4 + phy_no;
  3095. int data_idx = phy_no + 3 - (phy_no % 4) * 2;
  3096. writeb(write_data[data_idx], reg_addr);
  3097. }
  3098. break;
  3099. default:
  3100. dev_err(dev, "write gpio: unsupported or bad reg type %d\n",
  3101. reg_type);
  3102. return -EINVAL;
  3103. }
  3104. return 0;
  3105. }
  3106. static void wait_cmds_complete_timeout_v2_hw(struct hisi_hba *hisi_hba,
  3107. int delay_ms, int timeout_ms)
  3108. {
  3109. struct device *dev = hisi_hba->dev;
  3110. int entries, entries_old = 0, time;
  3111. for (time = 0; time < timeout_ms; time += delay_ms) {
  3112. entries = hisi_sas_read32(hisi_hba, CQE_SEND_CNT);
  3113. if (entries == entries_old)
  3114. break;
  3115. entries_old = entries;
  3116. msleep(delay_ms);
  3117. }
  3118. dev_dbg(dev, "wait commands complete %dms\n", time);
  3119. }
  3120. static struct scsi_host_template sht_v2_hw = {
  3121. .name = DRV_NAME,
  3122. .module = THIS_MODULE,
  3123. .queuecommand = sas_queuecommand,
  3124. .target_alloc = sas_target_alloc,
  3125. .slave_configure = hisi_sas_slave_configure,
  3126. .scan_finished = hisi_sas_scan_finished,
  3127. .scan_start = hisi_sas_scan_start,
  3128. .change_queue_depth = sas_change_queue_depth,
  3129. .bios_param = sas_bios_param,
  3130. .can_queue = 1,
  3131. .this_id = -1,
  3132. .sg_tablesize = SG_ALL,
  3133. .max_sectors = SCSI_DEFAULT_MAX_SECTORS,
  3134. .use_clustering = ENABLE_CLUSTERING,
  3135. .eh_device_reset_handler = sas_eh_device_reset_handler,
  3136. .eh_target_reset_handler = sas_eh_target_reset_handler,
  3137. .target_destroy = sas_target_destroy,
  3138. .ioctl = sas_ioctl,
  3139. .shost_attrs = host_attrs,
  3140. };
  3141. static const struct hisi_sas_hw hisi_sas_v2_hw = {
  3142. .hw_init = hisi_sas_v2_init,
  3143. .setup_itct = setup_itct_v2_hw,
  3144. .slot_index_alloc = slot_index_alloc_quirk_v2_hw,
  3145. .alloc_dev = alloc_dev_quirk_v2_hw,
  3146. .sl_notify_ssp = sl_notify_ssp_v2_hw,
  3147. .get_wideport_bitmap = get_wideport_bitmap_v2_hw,
  3148. .clear_itct = clear_itct_v2_hw,
  3149. .free_device = free_device_v2_hw,
  3150. .prep_smp = prep_smp_v2_hw,
  3151. .prep_ssp = prep_ssp_v2_hw,
  3152. .prep_stp = prep_ata_v2_hw,
  3153. .prep_abort = prep_abort_v2_hw,
  3154. .get_free_slot = get_free_slot_v2_hw,
  3155. .start_delivery = start_delivery_v2_hw,
  3156. .slot_complete = slot_complete_v2_hw,
  3157. .phys_init = phys_init_v2_hw,
  3158. .phy_start = start_phy_v2_hw,
  3159. .phy_disable = disable_phy_v2_hw,
  3160. .phy_hard_reset = phy_hard_reset_v2_hw,
  3161. .get_events = phy_get_events_v2_hw,
  3162. .phy_set_linkrate = phy_set_linkrate_v2_hw,
  3163. .phy_get_max_linkrate = phy_get_max_linkrate_v2_hw,
  3164. .max_command_entries = HISI_SAS_COMMAND_ENTRIES_V2_HW,
  3165. .complete_hdr_size = sizeof(struct hisi_sas_complete_v2_hdr),
  3166. .soft_reset = soft_reset_v2_hw,
  3167. .get_phys_state = get_phys_state_v2_hw,
  3168. .write_gpio = write_gpio_v2_hw,
  3169. .wait_cmds_complete_timeout = wait_cmds_complete_timeout_v2_hw,
  3170. .sht = &sht_v2_hw,
  3171. };
  3172. static int hisi_sas_v2_probe(struct platform_device *pdev)
  3173. {
  3174. /*
  3175. * Check if we should defer the probe before we probe the
  3176. * upper layer, as it's hard to defer later on.
  3177. */
  3178. int ret = platform_get_irq(pdev, 0);
  3179. if (ret < 0) {
  3180. if (ret != -EPROBE_DEFER)
  3181. dev_err(&pdev->dev, "cannot obtain irq\n");
  3182. return ret;
  3183. }
  3184. return hisi_sas_probe(pdev, &hisi_sas_v2_hw);
  3185. }
  3186. static int hisi_sas_v2_remove(struct platform_device *pdev)
  3187. {
  3188. struct sas_ha_struct *sha = platform_get_drvdata(pdev);
  3189. struct hisi_hba *hisi_hba = sha->lldd_ha;
  3190. hisi_sas_kill_tasklets(hisi_hba);
  3191. return hisi_sas_remove(pdev);
  3192. }
  3193. static const struct of_device_id sas_v2_of_match[] = {
  3194. { .compatible = "hisilicon,hip06-sas-v2",},
  3195. { .compatible = "hisilicon,hip07-sas-v2",},
  3196. {},
  3197. };
  3198. MODULE_DEVICE_TABLE(of, sas_v2_of_match);
  3199. static const struct acpi_device_id sas_v2_acpi_match[] = {
  3200. { "HISI0162", 0 },
  3201. { }
  3202. };
  3203. MODULE_DEVICE_TABLE(acpi, sas_v2_acpi_match);
  3204. static struct platform_driver hisi_sas_v2_driver = {
  3205. .probe = hisi_sas_v2_probe,
  3206. .remove = hisi_sas_v2_remove,
  3207. .driver = {
  3208. .name = DRV_NAME,
  3209. .of_match_table = sas_v2_of_match,
  3210. .acpi_match_table = ACPI_PTR(sas_v2_acpi_match),
  3211. },
  3212. };
  3213. module_platform_driver(hisi_sas_v2_driver);
  3214. MODULE_LICENSE("GPL");
  3215. MODULE_AUTHOR("John Garry <john.garry@huawei.com>");
  3216. MODULE_DESCRIPTION("HISILICON SAS controller v2 hw driver");
  3217. MODULE_ALIAS("platform:" DRV_NAME);