hisi_sas_v2_hw.c 107 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678
  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,
  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. unsigned long flags;
  742. if (!sata_dev) {
  743. /*
  744. * STP link SoC bug workaround: index starts from 1.
  745. * additionally, we can only allocate odd IPTT(1~4095)
  746. * for SAS/SMP device.
  747. */
  748. start = 1;
  749. end = hisi_hba->slot_index_count;
  750. } else {
  751. if (sata_idx >= HISI_MAX_SATA_SUPPORT_V2_HW)
  752. return -EINVAL;
  753. /*
  754. * For SATA device: allocate even IPTT in this interval
  755. * [64*(sata_idx+1), 64*(sata_idx+2)], then each SATA device
  756. * own 32 IPTTs. IPTT 0 shall not be used duing to STP link
  757. * SoC bug workaround. So we ignore the first 32 even IPTTs.
  758. */
  759. start = 64 * (sata_idx + 1);
  760. end = 64 * (sata_idx + 2);
  761. }
  762. spin_lock_irqsave(&hisi_hba->lock, flags);
  763. while (1) {
  764. start = find_next_zero_bit(bitmap,
  765. hisi_hba->slot_index_count, start);
  766. if (start >= end) {
  767. spin_unlock_irqrestore(&hisi_hba->lock, flags);
  768. return -SAS_QUEUE_FULL;
  769. }
  770. /*
  771. * SAS IPTT bit0 should be 1, and SATA IPTT bit0 should be 0.
  772. */
  773. if (sata_dev ^ (start & 1))
  774. break;
  775. start++;
  776. }
  777. set_bit(start, bitmap);
  778. spin_unlock_irqrestore(&hisi_hba->lock, flags);
  779. return start;
  780. }
  781. static bool sata_index_alloc_v2_hw(struct hisi_hba *hisi_hba, int *idx)
  782. {
  783. unsigned int index;
  784. struct device *dev = hisi_hba->dev;
  785. void *bitmap = hisi_hba->sata_dev_bitmap;
  786. index = find_first_zero_bit(bitmap, HISI_MAX_SATA_SUPPORT_V2_HW);
  787. if (index >= HISI_MAX_SATA_SUPPORT_V2_HW) {
  788. dev_warn(dev, "alloc sata index failed, index=%d\n", index);
  789. return false;
  790. }
  791. set_bit(index, bitmap);
  792. *idx = index;
  793. return true;
  794. }
  795. static struct
  796. hisi_sas_device *alloc_dev_quirk_v2_hw(struct domain_device *device)
  797. {
  798. struct hisi_hba *hisi_hba = device->port->ha->lldd_ha;
  799. struct hisi_sas_device *sas_dev = NULL;
  800. int i, sata_dev = dev_is_sata(device);
  801. int sata_idx = -1;
  802. unsigned long flags;
  803. spin_lock_irqsave(&hisi_hba->lock, flags);
  804. if (sata_dev)
  805. if (!sata_index_alloc_v2_hw(hisi_hba, &sata_idx))
  806. goto out;
  807. for (i = 0; i < HISI_SAS_MAX_DEVICES; i++) {
  808. /*
  809. * SATA device id bit0 should be 0
  810. */
  811. if (sata_dev && (i & 1))
  812. continue;
  813. if (hisi_hba->devices[i].dev_type == SAS_PHY_UNUSED) {
  814. int queue = i % hisi_hba->queue_count;
  815. struct hisi_sas_dq *dq = &hisi_hba->dq[queue];
  816. hisi_hba->devices[i].device_id = i;
  817. sas_dev = &hisi_hba->devices[i];
  818. sas_dev->dev_status = HISI_SAS_DEV_NORMAL;
  819. sas_dev->dev_type = device->dev_type;
  820. sas_dev->hisi_hba = hisi_hba;
  821. sas_dev->sas_device = device;
  822. sas_dev->sata_idx = sata_idx;
  823. sas_dev->dq = dq;
  824. INIT_LIST_HEAD(&hisi_hba->devices[i].list);
  825. break;
  826. }
  827. }
  828. out:
  829. spin_unlock_irqrestore(&hisi_hba->lock, flags);
  830. return sas_dev;
  831. }
  832. static void config_phy_opt_mode_v2_hw(struct hisi_hba *hisi_hba, int phy_no)
  833. {
  834. u32 cfg = hisi_sas_phy_read32(hisi_hba, phy_no, PHY_CFG);
  835. cfg &= ~PHY_CFG_DC_OPT_MSK;
  836. cfg |= 1 << PHY_CFG_DC_OPT_OFF;
  837. hisi_sas_phy_write32(hisi_hba, phy_no, PHY_CFG, cfg);
  838. }
  839. static void config_id_frame_v2_hw(struct hisi_hba *hisi_hba, int phy_no)
  840. {
  841. struct sas_identify_frame identify_frame;
  842. u32 *identify_buffer;
  843. memset(&identify_frame, 0, sizeof(identify_frame));
  844. identify_frame.dev_type = SAS_END_DEVICE;
  845. identify_frame.frame_type = 0;
  846. identify_frame._un1 = 1;
  847. identify_frame.initiator_bits = SAS_PROTOCOL_ALL;
  848. identify_frame.target_bits = SAS_PROTOCOL_NONE;
  849. memcpy(&identify_frame._un4_11[0], hisi_hba->sas_addr, SAS_ADDR_SIZE);
  850. memcpy(&identify_frame.sas_addr[0], hisi_hba->sas_addr, SAS_ADDR_SIZE);
  851. identify_frame.phy_id = phy_no;
  852. identify_buffer = (u32 *)(&identify_frame);
  853. hisi_sas_phy_write32(hisi_hba, phy_no, TX_ID_DWORD0,
  854. __swab32(identify_buffer[0]));
  855. hisi_sas_phy_write32(hisi_hba, phy_no, TX_ID_DWORD1,
  856. __swab32(identify_buffer[1]));
  857. hisi_sas_phy_write32(hisi_hba, phy_no, TX_ID_DWORD2,
  858. __swab32(identify_buffer[2]));
  859. hisi_sas_phy_write32(hisi_hba, phy_no, TX_ID_DWORD3,
  860. __swab32(identify_buffer[3]));
  861. hisi_sas_phy_write32(hisi_hba, phy_no, TX_ID_DWORD4,
  862. __swab32(identify_buffer[4]));
  863. hisi_sas_phy_write32(hisi_hba, phy_no, TX_ID_DWORD5,
  864. __swab32(identify_buffer[5]));
  865. }
  866. static void setup_itct_v2_hw(struct hisi_hba *hisi_hba,
  867. struct hisi_sas_device *sas_dev)
  868. {
  869. struct domain_device *device = sas_dev->sas_device;
  870. struct device *dev = hisi_hba->dev;
  871. u64 qw0, device_id = sas_dev->device_id;
  872. struct hisi_sas_itct *itct = &hisi_hba->itct[device_id];
  873. struct domain_device *parent_dev = device->parent;
  874. struct asd_sas_port *sas_port = device->port;
  875. struct hisi_sas_port *port = to_hisi_sas_port(sas_port);
  876. u64 sas_addr;
  877. memset(itct, 0, sizeof(*itct));
  878. /* qw0 */
  879. qw0 = 0;
  880. switch (sas_dev->dev_type) {
  881. case SAS_END_DEVICE:
  882. case SAS_EDGE_EXPANDER_DEVICE:
  883. case SAS_FANOUT_EXPANDER_DEVICE:
  884. qw0 = HISI_SAS_DEV_TYPE_SSP << ITCT_HDR_DEV_TYPE_OFF;
  885. break;
  886. case SAS_SATA_DEV:
  887. case SAS_SATA_PENDING:
  888. if (parent_dev && DEV_IS_EXPANDER(parent_dev->dev_type))
  889. qw0 = HISI_SAS_DEV_TYPE_STP << ITCT_HDR_DEV_TYPE_OFF;
  890. else
  891. qw0 = HISI_SAS_DEV_TYPE_SATA << ITCT_HDR_DEV_TYPE_OFF;
  892. break;
  893. default:
  894. dev_warn(dev, "setup itct: unsupported dev type (%d)\n",
  895. sas_dev->dev_type);
  896. }
  897. qw0 |= ((1 << ITCT_HDR_VALID_OFF) |
  898. (device->linkrate << ITCT_HDR_MCR_OFF) |
  899. (1 << ITCT_HDR_VLN_OFF) |
  900. (ITCT_HDR_SMP_TIMEOUT << ITCT_HDR_SMP_TIMEOUT_OFF) |
  901. (1 << ITCT_HDR_AWT_CONTINUE_OFF) |
  902. (port->id << ITCT_HDR_PORT_ID_OFF));
  903. itct->qw0 = cpu_to_le64(qw0);
  904. /* qw1 */
  905. memcpy(&sas_addr, device->sas_addr, SAS_ADDR_SIZE);
  906. itct->sas_addr = cpu_to_le64(__swab64(sas_addr));
  907. /* qw2 */
  908. if (!dev_is_sata(device))
  909. itct->qw2 = cpu_to_le64((5000ULL << ITCT_HDR_INLT_OFF) |
  910. (0x1ULL << ITCT_HDR_BITLT_OFF) |
  911. (0x32ULL << ITCT_HDR_MCTLT_OFF) |
  912. (0x1ULL << ITCT_HDR_RTOLT_OFF));
  913. }
  914. static void clear_itct_v2_hw(struct hisi_hba *hisi_hba,
  915. struct hisi_sas_device *sas_dev)
  916. {
  917. DECLARE_COMPLETION_ONSTACK(completion);
  918. u64 dev_id = sas_dev->device_id;
  919. struct hisi_sas_itct *itct = &hisi_hba->itct[dev_id];
  920. u32 reg_val = hisi_sas_read32(hisi_hba, ENT_INT_SRC3);
  921. int i;
  922. sas_dev->completion = &completion;
  923. /* clear the itct interrupt state */
  924. if (ENT_INT_SRC3_ITC_INT_MSK & reg_val)
  925. hisi_sas_write32(hisi_hba, ENT_INT_SRC3,
  926. ENT_INT_SRC3_ITC_INT_MSK);
  927. for (i = 0; i < 2; i++) {
  928. reg_val = ITCT_CLR_EN_MSK | (dev_id & ITCT_DEV_MSK);
  929. hisi_sas_write32(hisi_hba, ITCT_CLR, reg_val);
  930. wait_for_completion(sas_dev->completion);
  931. memset(itct, 0, sizeof(struct hisi_sas_itct));
  932. }
  933. }
  934. static void free_device_v2_hw(struct hisi_sas_device *sas_dev)
  935. {
  936. struct hisi_hba *hisi_hba = sas_dev->hisi_hba;
  937. /* SoC bug workaround */
  938. if (dev_is_sata(sas_dev->sas_device))
  939. clear_bit(sas_dev->sata_idx, hisi_hba->sata_dev_bitmap);
  940. }
  941. static int reset_hw_v2_hw(struct hisi_hba *hisi_hba)
  942. {
  943. int i, reset_val;
  944. u32 val;
  945. unsigned long end_time;
  946. struct device *dev = hisi_hba->dev;
  947. /* The mask needs to be set depending on the number of phys */
  948. if (hisi_hba->n_phy == 9)
  949. reset_val = 0x1fffff;
  950. else
  951. reset_val = 0x7ffff;
  952. hisi_sas_write32(hisi_hba, DLVRY_QUEUE_ENABLE, 0);
  953. /* Disable all of the PHYs */
  954. for (i = 0; i < hisi_hba->n_phy; i++) {
  955. u32 phy_cfg = hisi_sas_phy_read32(hisi_hba, i, PHY_CFG);
  956. phy_cfg &= ~PHY_CTRL_RESET_MSK;
  957. hisi_sas_phy_write32(hisi_hba, i, PHY_CFG, phy_cfg);
  958. }
  959. udelay(50);
  960. /* Ensure DMA tx & rx idle */
  961. for (i = 0; i < hisi_hba->n_phy; i++) {
  962. u32 dma_tx_status, dma_rx_status;
  963. end_time = jiffies + msecs_to_jiffies(1000);
  964. while (1) {
  965. dma_tx_status = hisi_sas_phy_read32(hisi_hba, i,
  966. DMA_TX_STATUS);
  967. dma_rx_status = hisi_sas_phy_read32(hisi_hba, i,
  968. DMA_RX_STATUS);
  969. if (!(dma_tx_status & DMA_TX_STATUS_BUSY_MSK) &&
  970. !(dma_rx_status & DMA_RX_STATUS_BUSY_MSK))
  971. break;
  972. msleep(20);
  973. if (time_after(jiffies, end_time))
  974. return -EIO;
  975. }
  976. }
  977. /* Ensure axi bus idle */
  978. end_time = jiffies + msecs_to_jiffies(1000);
  979. while (1) {
  980. u32 axi_status =
  981. hisi_sas_read32(hisi_hba, AXI_CFG);
  982. if (axi_status == 0)
  983. break;
  984. msleep(20);
  985. if (time_after(jiffies, end_time))
  986. return -EIO;
  987. }
  988. if (ACPI_HANDLE(dev)) {
  989. acpi_status s;
  990. s = acpi_evaluate_object(ACPI_HANDLE(dev), "_RST", NULL, NULL);
  991. if (ACPI_FAILURE(s)) {
  992. dev_err(dev, "Reset failed\n");
  993. return -EIO;
  994. }
  995. } else if (hisi_hba->ctrl) {
  996. /* reset and disable clock*/
  997. regmap_write(hisi_hba->ctrl, hisi_hba->ctrl_reset_reg,
  998. reset_val);
  999. regmap_write(hisi_hba->ctrl, hisi_hba->ctrl_clock_ena_reg + 4,
  1000. reset_val);
  1001. msleep(1);
  1002. regmap_read(hisi_hba->ctrl, hisi_hba->ctrl_reset_sts_reg, &val);
  1003. if (reset_val != (val & reset_val)) {
  1004. dev_err(dev, "SAS reset fail.\n");
  1005. return -EIO;
  1006. }
  1007. /* De-reset and enable clock*/
  1008. regmap_write(hisi_hba->ctrl, hisi_hba->ctrl_reset_reg + 4,
  1009. reset_val);
  1010. regmap_write(hisi_hba->ctrl, hisi_hba->ctrl_clock_ena_reg,
  1011. reset_val);
  1012. msleep(1);
  1013. regmap_read(hisi_hba->ctrl, hisi_hba->ctrl_reset_sts_reg,
  1014. &val);
  1015. if (val & reset_val) {
  1016. dev_err(dev, "SAS de-reset fail.\n");
  1017. return -EIO;
  1018. }
  1019. } else {
  1020. dev_err(dev, "no reset method\n");
  1021. return -EINVAL;
  1022. }
  1023. return 0;
  1024. }
  1025. /* This function needs to be called after resetting SAS controller. */
  1026. static void phys_reject_stp_links_v2_hw(struct hisi_hba *hisi_hba)
  1027. {
  1028. u32 cfg;
  1029. int phy_no;
  1030. hisi_hba->reject_stp_links_msk = (1 << hisi_hba->n_phy) - 1;
  1031. for (phy_no = 0; phy_no < hisi_hba->n_phy; phy_no++) {
  1032. cfg = hisi_sas_phy_read32(hisi_hba, phy_no, CON_CONTROL);
  1033. if (!(cfg & CON_CONTROL_CFG_OPEN_ACC_STP_MSK))
  1034. continue;
  1035. cfg &= ~CON_CONTROL_CFG_OPEN_ACC_STP_MSK;
  1036. hisi_sas_phy_write32(hisi_hba, phy_no, CON_CONTROL, cfg);
  1037. }
  1038. }
  1039. static void phys_try_accept_stp_links_v2_hw(struct hisi_hba *hisi_hba)
  1040. {
  1041. int phy_no;
  1042. u32 dma_tx_dfx1;
  1043. for (phy_no = 0; phy_no < hisi_hba->n_phy; phy_no++) {
  1044. if (!(hisi_hba->reject_stp_links_msk & BIT(phy_no)))
  1045. continue;
  1046. dma_tx_dfx1 = hisi_sas_phy_read32(hisi_hba, phy_no,
  1047. DMA_TX_DFX1);
  1048. if (dma_tx_dfx1 & DMA_TX_DFX1_IPTT_MSK) {
  1049. u32 cfg = hisi_sas_phy_read32(hisi_hba,
  1050. phy_no, CON_CONTROL);
  1051. cfg |= CON_CONTROL_CFG_OPEN_ACC_STP_MSK;
  1052. hisi_sas_phy_write32(hisi_hba, phy_no,
  1053. CON_CONTROL, cfg);
  1054. clear_bit(phy_no, &hisi_hba->reject_stp_links_msk);
  1055. }
  1056. }
  1057. }
  1058. static const struct signal_attenuation_s x6000 = {9200, 0, 10476};
  1059. static const struct sig_atten_lu_s sig_atten_lu[] = {
  1060. { &x6000, 0x3016a68 },
  1061. };
  1062. static void init_reg_v2_hw(struct hisi_hba *hisi_hba)
  1063. {
  1064. struct device *dev = hisi_hba->dev;
  1065. u32 sas_phy_ctrl = 0x30b9908;
  1066. u32 signal[3];
  1067. int i;
  1068. /* Global registers init */
  1069. /* Deal with am-max-transmissions quirk */
  1070. if (device_property_present(dev, "hip06-sas-v2-quirk-amt")) {
  1071. hisi_sas_write32(hisi_hba, AM_CFG_MAX_TRANS, 0x2020);
  1072. hisi_sas_write32(hisi_hba, AM_CFG_SINGLE_PORT_MAX_TRANS,
  1073. 0x2020);
  1074. } /* Else, use defaults -> do nothing */
  1075. hisi_sas_write32(hisi_hba, DLVRY_QUEUE_ENABLE,
  1076. (u32)((1ULL << hisi_hba->queue_count) - 1));
  1077. hisi_sas_write32(hisi_hba, AXI_USER1, 0xc0000000);
  1078. hisi_sas_write32(hisi_hba, AXI_USER2, 0x10000);
  1079. hisi_sas_write32(hisi_hba, HGC_SAS_TXFAIL_RETRY_CTRL, 0x0);
  1080. hisi_sas_write32(hisi_hba, HGC_SAS_TX_OPEN_FAIL_RETRY_CTRL, 0x7FF);
  1081. hisi_sas_write32(hisi_hba, OPENA_WT_CONTI_TIME, 0x1);
  1082. hisi_sas_write32(hisi_hba, I_T_NEXUS_LOSS_TIME, 0x1F4);
  1083. hisi_sas_write32(hisi_hba, MAX_CON_TIME_LIMIT_TIME, 0x32);
  1084. hisi_sas_write32(hisi_hba, BUS_INACTIVE_LIMIT_TIME, 0x1);
  1085. hisi_sas_write32(hisi_hba, CFG_AGING_TIME, 0x1);
  1086. hisi_sas_write32(hisi_hba, HGC_ERR_STAT_EN, 0x1);
  1087. hisi_sas_write32(hisi_hba, HGC_GET_ITV_TIME, 0x1);
  1088. hisi_sas_write32(hisi_hba, INT_COAL_EN, 0xc);
  1089. hisi_sas_write32(hisi_hba, OQ_INT_COAL_TIME, 0x60);
  1090. hisi_sas_write32(hisi_hba, OQ_INT_COAL_CNT, 0x3);
  1091. hisi_sas_write32(hisi_hba, ENT_INT_COAL_TIME, 0x1);
  1092. hisi_sas_write32(hisi_hba, ENT_INT_COAL_CNT, 0x1);
  1093. hisi_sas_write32(hisi_hba, OQ_INT_SRC, 0x0);
  1094. hisi_sas_write32(hisi_hba, ENT_INT_SRC1, 0xffffffff);
  1095. hisi_sas_write32(hisi_hba, ENT_INT_SRC2, 0xffffffff);
  1096. hisi_sas_write32(hisi_hba, ENT_INT_SRC3, 0xffffffff);
  1097. hisi_sas_write32(hisi_hba, ENT_INT_SRC_MSK1, 0x7efefefe);
  1098. hisi_sas_write32(hisi_hba, ENT_INT_SRC_MSK2, 0x7efefefe);
  1099. hisi_sas_write32(hisi_hba, ENT_INT_SRC_MSK3, 0x7ffe20fe);
  1100. hisi_sas_write32(hisi_hba, SAS_ECC_INTR_MSK, 0xfff00c30);
  1101. for (i = 0; i < hisi_hba->queue_count; i++)
  1102. hisi_sas_write32(hisi_hba, OQ0_INT_SRC_MSK+0x4*i, 0);
  1103. hisi_sas_write32(hisi_hba, AXI_AHB_CLK_CFG, 1);
  1104. hisi_sas_write32(hisi_hba, HYPER_STREAM_ID_EN_CFG, 1);
  1105. /* Get sas_phy_ctrl value to deal with TX FFE issue. */
  1106. if (!device_property_read_u32_array(dev, "hisilicon,signal-attenuation",
  1107. signal, ARRAY_SIZE(signal))) {
  1108. for (i = 0; i < ARRAY_SIZE(sig_atten_lu); i++) {
  1109. const struct sig_atten_lu_s *lookup = &sig_atten_lu[i];
  1110. const struct signal_attenuation_s *att = lookup->att;
  1111. if ((signal[0] == att->de_emphasis) &&
  1112. (signal[1] == att->preshoot) &&
  1113. (signal[2] == att->boost)) {
  1114. sas_phy_ctrl = lookup->sas_phy_ctrl;
  1115. break;
  1116. }
  1117. }
  1118. if (i == ARRAY_SIZE(sig_atten_lu))
  1119. dev_warn(dev, "unknown signal attenuation values, using default PHY ctrl config\n");
  1120. }
  1121. for (i = 0; i < hisi_hba->n_phy; i++) {
  1122. struct hisi_sas_phy *phy = &hisi_hba->phy[i];
  1123. struct asd_sas_phy *sas_phy = &phy->sas_phy;
  1124. u32 prog_phy_link_rate = 0x800;
  1125. if (!sas_phy->phy || (sas_phy->phy->maximum_linkrate <
  1126. SAS_LINK_RATE_1_5_GBPS)) {
  1127. prog_phy_link_rate = 0x855;
  1128. } else {
  1129. enum sas_linkrate max = sas_phy->phy->maximum_linkrate;
  1130. prog_phy_link_rate =
  1131. hisi_sas_get_prog_phy_linkrate_mask(max) |
  1132. 0x800;
  1133. }
  1134. hisi_sas_phy_write32(hisi_hba, i, PROG_PHY_LINK_RATE,
  1135. prog_phy_link_rate);
  1136. hisi_sas_phy_write32(hisi_hba, i, SAS_PHY_CTRL, sas_phy_ctrl);
  1137. hisi_sas_phy_write32(hisi_hba, i, SL_TOUT_CFG, 0x7d7d7d7d);
  1138. hisi_sas_phy_write32(hisi_hba, i, SL_CONTROL, 0x0);
  1139. hisi_sas_phy_write32(hisi_hba, i, TXID_AUTO, 0x2);
  1140. hisi_sas_phy_write32(hisi_hba, i, DONE_RECEIVED_TIME, 0x8);
  1141. hisi_sas_phy_write32(hisi_hba, i, CHL_INT0, 0xffffffff);
  1142. hisi_sas_phy_write32(hisi_hba, i, CHL_INT1, 0xffffffff);
  1143. hisi_sas_phy_write32(hisi_hba, i, CHL_INT2, 0xfff87fff);
  1144. hisi_sas_phy_write32(hisi_hba, i, RXOP_CHECK_CFG_H, 0x1000);
  1145. hisi_sas_phy_write32(hisi_hba, i, CHL_INT1_MSK, 0xff857fff);
  1146. hisi_sas_phy_write32(hisi_hba, i, CHL_INT2_MSK, 0x8ffffbfe);
  1147. hisi_sas_phy_write32(hisi_hba, i, SL_CFG, 0x13f801fc);
  1148. hisi_sas_phy_write32(hisi_hba, i, PHY_CTRL_RDY_MSK, 0x0);
  1149. hisi_sas_phy_write32(hisi_hba, i, PHYCTRL_NOT_RDY_MSK, 0x0);
  1150. hisi_sas_phy_write32(hisi_hba, i, PHYCTRL_DWS_RESET_MSK, 0x0);
  1151. hisi_sas_phy_write32(hisi_hba, i, PHYCTRL_PHY_ENA_MSK, 0x0);
  1152. hisi_sas_phy_write32(hisi_hba, i, SL_RX_BCAST_CHK_MSK, 0x0);
  1153. hisi_sas_phy_write32(hisi_hba, i, CHL_INT_COAL_EN, 0x0);
  1154. hisi_sas_phy_write32(hisi_hba, i, PHYCTRL_OOB_RESTART_MSK, 0x0);
  1155. if (hisi_hba->refclk_frequency_mhz == 66)
  1156. hisi_sas_phy_write32(hisi_hba, i, PHY_CTRL, 0x199B694);
  1157. /* else, do nothing -> leave it how you found it */
  1158. }
  1159. for (i = 0; i < hisi_hba->queue_count; i++) {
  1160. /* Delivery queue */
  1161. hisi_sas_write32(hisi_hba,
  1162. DLVRY_Q_0_BASE_ADDR_HI + (i * 0x14),
  1163. upper_32_bits(hisi_hba->cmd_hdr_dma[i]));
  1164. hisi_sas_write32(hisi_hba, DLVRY_Q_0_BASE_ADDR_LO + (i * 0x14),
  1165. lower_32_bits(hisi_hba->cmd_hdr_dma[i]));
  1166. hisi_sas_write32(hisi_hba, DLVRY_Q_0_DEPTH + (i * 0x14),
  1167. HISI_SAS_QUEUE_SLOTS);
  1168. /* Completion queue */
  1169. hisi_sas_write32(hisi_hba, COMPL_Q_0_BASE_ADDR_HI + (i * 0x14),
  1170. upper_32_bits(hisi_hba->complete_hdr_dma[i]));
  1171. hisi_sas_write32(hisi_hba, COMPL_Q_0_BASE_ADDR_LO + (i * 0x14),
  1172. lower_32_bits(hisi_hba->complete_hdr_dma[i]));
  1173. hisi_sas_write32(hisi_hba, COMPL_Q_0_DEPTH + (i * 0x14),
  1174. HISI_SAS_QUEUE_SLOTS);
  1175. }
  1176. /* itct */
  1177. hisi_sas_write32(hisi_hba, ITCT_BASE_ADDR_LO,
  1178. lower_32_bits(hisi_hba->itct_dma));
  1179. hisi_sas_write32(hisi_hba, ITCT_BASE_ADDR_HI,
  1180. upper_32_bits(hisi_hba->itct_dma));
  1181. /* iost */
  1182. hisi_sas_write32(hisi_hba, IOST_BASE_ADDR_LO,
  1183. lower_32_bits(hisi_hba->iost_dma));
  1184. hisi_sas_write32(hisi_hba, IOST_BASE_ADDR_HI,
  1185. upper_32_bits(hisi_hba->iost_dma));
  1186. /* breakpoint */
  1187. hisi_sas_write32(hisi_hba, IO_BROKEN_MSG_ADDR_LO,
  1188. lower_32_bits(hisi_hba->breakpoint_dma));
  1189. hisi_sas_write32(hisi_hba, IO_BROKEN_MSG_ADDR_HI,
  1190. upper_32_bits(hisi_hba->breakpoint_dma));
  1191. /* SATA broken msg */
  1192. hisi_sas_write32(hisi_hba, IO_SATA_BROKEN_MSG_ADDR_LO,
  1193. lower_32_bits(hisi_hba->sata_breakpoint_dma));
  1194. hisi_sas_write32(hisi_hba, IO_SATA_BROKEN_MSG_ADDR_HI,
  1195. upper_32_bits(hisi_hba->sata_breakpoint_dma));
  1196. /* SATA initial fis */
  1197. hisi_sas_write32(hisi_hba, SATA_INITI_D2H_STORE_ADDR_LO,
  1198. lower_32_bits(hisi_hba->initial_fis_dma));
  1199. hisi_sas_write32(hisi_hba, SATA_INITI_D2H_STORE_ADDR_HI,
  1200. upper_32_bits(hisi_hba->initial_fis_dma));
  1201. }
  1202. static void link_timeout_enable_link(struct timer_list *t)
  1203. {
  1204. struct hisi_hba *hisi_hba = from_timer(hisi_hba, t, timer);
  1205. int i, reg_val;
  1206. for (i = 0; i < hisi_hba->n_phy; i++) {
  1207. if (hisi_hba->reject_stp_links_msk & BIT(i))
  1208. continue;
  1209. reg_val = hisi_sas_phy_read32(hisi_hba, i, CON_CONTROL);
  1210. if (!(reg_val & BIT(0))) {
  1211. hisi_sas_phy_write32(hisi_hba, i,
  1212. CON_CONTROL, 0x7);
  1213. break;
  1214. }
  1215. }
  1216. hisi_hba->timer.function = link_timeout_disable_link;
  1217. mod_timer(&hisi_hba->timer, jiffies + msecs_to_jiffies(900));
  1218. }
  1219. static void link_timeout_disable_link(struct timer_list *t)
  1220. {
  1221. struct hisi_hba *hisi_hba = from_timer(hisi_hba, t, timer);
  1222. int i, reg_val;
  1223. reg_val = hisi_sas_read32(hisi_hba, PHY_STATE);
  1224. for (i = 0; i < hisi_hba->n_phy && reg_val; i++) {
  1225. if (hisi_hba->reject_stp_links_msk & BIT(i))
  1226. continue;
  1227. if (reg_val & BIT(i)) {
  1228. hisi_sas_phy_write32(hisi_hba, i,
  1229. CON_CONTROL, 0x6);
  1230. break;
  1231. }
  1232. }
  1233. hisi_hba->timer.function = link_timeout_enable_link;
  1234. mod_timer(&hisi_hba->timer, jiffies + msecs_to_jiffies(100));
  1235. }
  1236. static void set_link_timer_quirk(struct hisi_hba *hisi_hba)
  1237. {
  1238. hisi_hba->timer.function = link_timeout_disable_link;
  1239. hisi_hba->timer.expires = jiffies + msecs_to_jiffies(1000);
  1240. add_timer(&hisi_hba->timer);
  1241. }
  1242. static int hw_init_v2_hw(struct hisi_hba *hisi_hba)
  1243. {
  1244. struct device *dev = hisi_hba->dev;
  1245. int rc;
  1246. rc = reset_hw_v2_hw(hisi_hba);
  1247. if (rc) {
  1248. dev_err(dev, "hisi_sas_reset_hw failed, rc=%d", rc);
  1249. return rc;
  1250. }
  1251. msleep(100);
  1252. init_reg_v2_hw(hisi_hba);
  1253. return 0;
  1254. }
  1255. static void enable_phy_v2_hw(struct hisi_hba *hisi_hba, int phy_no)
  1256. {
  1257. u32 cfg = hisi_sas_phy_read32(hisi_hba, phy_no, PHY_CFG);
  1258. cfg |= PHY_CFG_ENA_MSK;
  1259. hisi_sas_phy_write32(hisi_hba, phy_no, PHY_CFG, cfg);
  1260. }
  1261. static bool is_sata_phy_v2_hw(struct hisi_hba *hisi_hba, int phy_no)
  1262. {
  1263. u32 context;
  1264. context = hisi_sas_read32(hisi_hba, PHY_CONTEXT);
  1265. if (context & (1 << phy_no))
  1266. return true;
  1267. return false;
  1268. }
  1269. static bool tx_fifo_is_empty_v2_hw(struct hisi_hba *hisi_hba, int phy_no)
  1270. {
  1271. u32 dfx_val;
  1272. dfx_val = hisi_sas_phy_read32(hisi_hba, phy_no, DMA_TX_DFX1);
  1273. if (dfx_val & BIT(16))
  1274. return false;
  1275. return true;
  1276. }
  1277. static bool axi_bus_is_idle_v2_hw(struct hisi_hba *hisi_hba, int phy_no)
  1278. {
  1279. int i, max_loop = 1000;
  1280. struct device *dev = hisi_hba->dev;
  1281. u32 status, axi_status, dfx_val, dfx_tx_val;
  1282. for (i = 0; i < max_loop; i++) {
  1283. status = hisi_sas_read32_relaxed(hisi_hba,
  1284. AXI_MASTER_CFG_BASE + AM_CURR_TRANS_RETURN);
  1285. axi_status = hisi_sas_read32(hisi_hba, AXI_CFG);
  1286. dfx_val = hisi_sas_phy_read32(hisi_hba, phy_no, DMA_TX_DFX1);
  1287. dfx_tx_val = hisi_sas_phy_read32(hisi_hba,
  1288. phy_no, DMA_TX_FIFO_DFX0);
  1289. if ((status == 0x3) && (axi_status == 0x0) &&
  1290. (dfx_val & BIT(20)) && (dfx_tx_val & BIT(10)))
  1291. return true;
  1292. udelay(10);
  1293. }
  1294. dev_err(dev, "bus is not idle phy%d, axi150:0x%x axi100:0x%x port204:0x%x port240:0x%x\n",
  1295. phy_no, status, axi_status,
  1296. dfx_val, dfx_tx_val);
  1297. return false;
  1298. }
  1299. static bool wait_io_done_v2_hw(struct hisi_hba *hisi_hba, int phy_no)
  1300. {
  1301. int i, max_loop = 1000;
  1302. struct device *dev = hisi_hba->dev;
  1303. u32 status, tx_dfx0;
  1304. for (i = 0; i < max_loop; i++) {
  1305. status = hisi_sas_phy_read32(hisi_hba, phy_no, LINK_DFX2);
  1306. status = (status & 0x3fc0) >> 6;
  1307. if (status != 0x1)
  1308. return true;
  1309. tx_dfx0 = hisi_sas_phy_read32(hisi_hba, phy_no, DMA_TX_DFX0);
  1310. if ((tx_dfx0 & 0x1ff) == 0x2)
  1311. return true;
  1312. udelay(10);
  1313. }
  1314. dev_err(dev, "IO not done phy%d, port264:0x%x port200:0x%x\n",
  1315. phy_no, status, tx_dfx0);
  1316. return false;
  1317. }
  1318. static bool allowed_disable_phy_v2_hw(struct hisi_hba *hisi_hba, int phy_no)
  1319. {
  1320. if (tx_fifo_is_empty_v2_hw(hisi_hba, phy_no))
  1321. return true;
  1322. if (!axi_bus_is_idle_v2_hw(hisi_hba, phy_no))
  1323. return false;
  1324. if (!wait_io_done_v2_hw(hisi_hba, phy_no))
  1325. return false;
  1326. return true;
  1327. }
  1328. static void disable_phy_v2_hw(struct hisi_hba *hisi_hba, int phy_no)
  1329. {
  1330. u32 cfg, axi_val, dfx0_val, txid_auto;
  1331. struct device *dev = hisi_hba->dev;
  1332. /* Close axi bus. */
  1333. axi_val = hisi_sas_read32(hisi_hba, AXI_MASTER_CFG_BASE +
  1334. AM_CTRL_GLOBAL);
  1335. axi_val |= 0x1;
  1336. hisi_sas_write32(hisi_hba, AXI_MASTER_CFG_BASE +
  1337. AM_CTRL_GLOBAL, axi_val);
  1338. if (is_sata_phy_v2_hw(hisi_hba, phy_no)) {
  1339. if (allowed_disable_phy_v2_hw(hisi_hba, phy_no))
  1340. goto do_disable;
  1341. /* Reset host controller. */
  1342. queue_work(hisi_hba->wq, &hisi_hba->rst_work);
  1343. return;
  1344. }
  1345. dfx0_val = hisi_sas_phy_read32(hisi_hba, phy_no, PORT_DFX0);
  1346. dfx0_val = (dfx0_val & 0x1fc0) >> 6;
  1347. if (dfx0_val != 0x4)
  1348. goto do_disable;
  1349. if (!tx_fifo_is_empty_v2_hw(hisi_hba, phy_no)) {
  1350. dev_warn(dev, "phy%d, wait tx fifo need send break\n",
  1351. phy_no);
  1352. txid_auto = hisi_sas_phy_read32(hisi_hba, phy_no,
  1353. TXID_AUTO);
  1354. txid_auto |= TXID_AUTO_CTB_MSK;
  1355. hisi_sas_phy_write32(hisi_hba, phy_no, TXID_AUTO,
  1356. txid_auto);
  1357. }
  1358. do_disable:
  1359. cfg = hisi_sas_phy_read32(hisi_hba, phy_no, PHY_CFG);
  1360. cfg &= ~PHY_CFG_ENA_MSK;
  1361. hisi_sas_phy_write32(hisi_hba, phy_no, PHY_CFG, cfg);
  1362. /* Open axi bus. */
  1363. axi_val &= ~0x1;
  1364. hisi_sas_write32(hisi_hba, AXI_MASTER_CFG_BASE +
  1365. AM_CTRL_GLOBAL, axi_val);
  1366. }
  1367. static void start_phy_v2_hw(struct hisi_hba *hisi_hba, int phy_no)
  1368. {
  1369. config_id_frame_v2_hw(hisi_hba, phy_no);
  1370. config_phy_opt_mode_v2_hw(hisi_hba, phy_no);
  1371. enable_phy_v2_hw(hisi_hba, phy_no);
  1372. }
  1373. static void phy_hard_reset_v2_hw(struct hisi_hba *hisi_hba, int phy_no)
  1374. {
  1375. struct hisi_sas_phy *phy = &hisi_hba->phy[phy_no];
  1376. u32 txid_auto;
  1377. disable_phy_v2_hw(hisi_hba, phy_no);
  1378. if (phy->identify.device_type == SAS_END_DEVICE) {
  1379. txid_auto = hisi_sas_phy_read32(hisi_hba, phy_no, TXID_AUTO);
  1380. hisi_sas_phy_write32(hisi_hba, phy_no, TXID_AUTO,
  1381. txid_auto | TX_HARDRST_MSK);
  1382. }
  1383. msleep(100);
  1384. start_phy_v2_hw(hisi_hba, phy_no);
  1385. }
  1386. static void phy_get_events_v2_hw(struct hisi_hba *hisi_hba, int phy_no)
  1387. {
  1388. struct hisi_sas_phy *phy = &hisi_hba->phy[phy_no];
  1389. struct asd_sas_phy *sas_phy = &phy->sas_phy;
  1390. struct sas_phy *sphy = sas_phy->phy;
  1391. u32 err4_reg_val, err6_reg_val;
  1392. /* loss dword syn, phy reset problem */
  1393. err4_reg_val = hisi_sas_phy_read32(hisi_hba, phy_no, SAS_ERR_CNT4_REG);
  1394. /* disparity err, invalid dword */
  1395. err6_reg_val = hisi_sas_phy_read32(hisi_hba, phy_no, SAS_ERR_CNT6_REG);
  1396. sphy->loss_of_dword_sync_count += (err4_reg_val >> 16) & 0xFFFF;
  1397. sphy->phy_reset_problem_count += err4_reg_val & 0xFFFF;
  1398. sphy->invalid_dword_count += (err6_reg_val & 0xFF0000) >> 16;
  1399. sphy->running_disparity_error_count += err6_reg_val & 0xFF;
  1400. }
  1401. static void phys_init_v2_hw(struct hisi_hba *hisi_hba)
  1402. {
  1403. int i;
  1404. for (i = 0; i < hisi_hba->n_phy; i++) {
  1405. struct hisi_sas_phy *phy = &hisi_hba->phy[i];
  1406. struct asd_sas_phy *sas_phy = &phy->sas_phy;
  1407. if (!sas_phy->phy->enabled)
  1408. continue;
  1409. start_phy_v2_hw(hisi_hba, i);
  1410. }
  1411. }
  1412. static void sl_notify_ssp_v2_hw(struct hisi_hba *hisi_hba, int phy_no)
  1413. {
  1414. u32 sl_control;
  1415. sl_control = hisi_sas_phy_read32(hisi_hba, phy_no, SL_CONTROL);
  1416. sl_control |= SL_CONTROL_NOTIFY_EN_MSK;
  1417. hisi_sas_phy_write32(hisi_hba, phy_no, SL_CONTROL, sl_control);
  1418. msleep(1);
  1419. sl_control = hisi_sas_phy_read32(hisi_hba, phy_no, SL_CONTROL);
  1420. sl_control &= ~SL_CONTROL_NOTIFY_EN_MSK;
  1421. hisi_sas_phy_write32(hisi_hba, phy_no, SL_CONTROL, sl_control);
  1422. }
  1423. static enum sas_linkrate phy_get_max_linkrate_v2_hw(void)
  1424. {
  1425. return SAS_LINK_RATE_12_0_GBPS;
  1426. }
  1427. static void phy_set_linkrate_v2_hw(struct hisi_hba *hisi_hba, int phy_no,
  1428. struct sas_phy_linkrates *r)
  1429. {
  1430. enum sas_linkrate max = r->maximum_linkrate;
  1431. u32 prog_phy_link_rate = 0x800;
  1432. prog_phy_link_rate |= hisi_sas_get_prog_phy_linkrate_mask(max);
  1433. hisi_sas_phy_write32(hisi_hba, phy_no, PROG_PHY_LINK_RATE,
  1434. prog_phy_link_rate);
  1435. }
  1436. static int get_wideport_bitmap_v2_hw(struct hisi_hba *hisi_hba, int port_id)
  1437. {
  1438. int i, bitmap = 0;
  1439. u32 phy_port_num_ma = hisi_sas_read32(hisi_hba, PHY_PORT_NUM_MA);
  1440. u32 phy_state = hisi_sas_read32(hisi_hba, PHY_STATE);
  1441. for (i = 0; i < (hisi_hba->n_phy < 9 ? hisi_hba->n_phy : 8); i++)
  1442. if (phy_state & 1 << i)
  1443. if (((phy_port_num_ma >> (i * 4)) & 0xf) == port_id)
  1444. bitmap |= 1 << i;
  1445. if (hisi_hba->n_phy == 9) {
  1446. u32 port_state = hisi_sas_read32(hisi_hba, PORT_STATE);
  1447. if (phy_state & 1 << 8)
  1448. if (((port_state & PORT_STATE_PHY8_PORT_NUM_MSK) >>
  1449. PORT_STATE_PHY8_PORT_NUM_OFF) == port_id)
  1450. bitmap |= 1 << 9;
  1451. }
  1452. return bitmap;
  1453. }
  1454. /*
  1455. * The callpath to this function and upto writing the write
  1456. * queue pointer should be safe from interruption.
  1457. */
  1458. static int
  1459. get_free_slot_v2_hw(struct hisi_hba *hisi_hba, struct hisi_sas_dq *dq)
  1460. {
  1461. struct device *dev = hisi_hba->dev;
  1462. int queue = dq->id;
  1463. u32 r, w;
  1464. w = dq->wr_point;
  1465. r = hisi_sas_read32_relaxed(hisi_hba,
  1466. DLVRY_Q_0_RD_PTR + (queue * 0x14));
  1467. if (r == (w+1) % HISI_SAS_QUEUE_SLOTS) {
  1468. dev_warn(dev, "full queue=%d r=%d w=%d\n",
  1469. queue, r, w);
  1470. return -EAGAIN;
  1471. }
  1472. dq->wr_point = (dq->wr_point + 1) % HISI_SAS_QUEUE_SLOTS;
  1473. return w;
  1474. }
  1475. /* DQ lock must be taken here */
  1476. static void start_delivery_v2_hw(struct hisi_sas_dq *dq)
  1477. {
  1478. struct hisi_hba *hisi_hba = dq->hisi_hba;
  1479. struct hisi_sas_slot *s, *s1, *s2 = NULL;
  1480. int dlvry_queue = dq->id;
  1481. int wp;
  1482. list_for_each_entry_safe(s, s1, &dq->list, delivery) {
  1483. if (!s->ready)
  1484. break;
  1485. s2 = s;
  1486. list_del(&s->delivery);
  1487. }
  1488. if (!s2)
  1489. return;
  1490. /*
  1491. * Ensure that memories for slots built on other CPUs is observed.
  1492. */
  1493. smp_rmb();
  1494. wp = (s2->dlvry_queue_slot + 1) % HISI_SAS_QUEUE_SLOTS;
  1495. hisi_sas_write32(hisi_hba, DLVRY_Q_0_WR_PTR + (dlvry_queue * 0x14), wp);
  1496. }
  1497. static void prep_prd_sge_v2_hw(struct hisi_hba *hisi_hba,
  1498. struct hisi_sas_slot *slot,
  1499. struct hisi_sas_cmd_hdr *hdr,
  1500. struct scatterlist *scatter,
  1501. int n_elem)
  1502. {
  1503. struct hisi_sas_sge_page *sge_page = hisi_sas_sge_addr_mem(slot);
  1504. struct scatterlist *sg;
  1505. int i;
  1506. for_each_sg(scatter, sg, n_elem, i) {
  1507. struct hisi_sas_sge *entry = &sge_page->sge[i];
  1508. entry->addr = cpu_to_le64(sg_dma_address(sg));
  1509. entry->page_ctrl_0 = entry->page_ctrl_1 = 0;
  1510. entry->data_len = cpu_to_le32(sg_dma_len(sg));
  1511. entry->data_off = 0;
  1512. }
  1513. hdr->prd_table_addr = cpu_to_le64(hisi_sas_sge_addr_dma(slot));
  1514. hdr->sg_len = cpu_to_le32(n_elem << CMD_HDR_DATA_SGL_LEN_OFF);
  1515. }
  1516. static void prep_smp_v2_hw(struct hisi_hba *hisi_hba,
  1517. struct hisi_sas_slot *slot)
  1518. {
  1519. struct sas_task *task = slot->task;
  1520. struct hisi_sas_cmd_hdr *hdr = slot->cmd_hdr;
  1521. struct domain_device *device = task->dev;
  1522. struct hisi_sas_port *port = slot->port;
  1523. struct scatterlist *sg_req;
  1524. struct hisi_sas_device *sas_dev = device->lldd_dev;
  1525. dma_addr_t req_dma_addr;
  1526. unsigned int req_len;
  1527. /* req */
  1528. sg_req = &task->smp_task.smp_req;
  1529. req_dma_addr = sg_dma_address(sg_req);
  1530. req_len = sg_dma_len(&task->smp_task.smp_req);
  1531. /* create header */
  1532. /* dw0 */
  1533. hdr->dw0 = cpu_to_le32((port->id << CMD_HDR_PORT_OFF) |
  1534. (1 << CMD_HDR_PRIORITY_OFF) | /* high pri */
  1535. (2 << CMD_HDR_CMD_OFF)); /* smp */
  1536. /* map itct entry */
  1537. hdr->dw1 = cpu_to_le32((sas_dev->device_id << CMD_HDR_DEV_ID_OFF) |
  1538. (1 << CMD_HDR_FRAME_TYPE_OFF) |
  1539. (DIR_NO_DATA << CMD_HDR_DIR_OFF));
  1540. /* dw2 */
  1541. hdr->dw2 = cpu_to_le32((((req_len - 4) / 4) << CMD_HDR_CFL_OFF) |
  1542. (HISI_SAS_MAX_SMP_RESP_SZ / 4 <<
  1543. CMD_HDR_MRFL_OFF));
  1544. hdr->transfer_tags = cpu_to_le32(slot->idx << CMD_HDR_IPTT_OFF);
  1545. hdr->cmd_table_addr = cpu_to_le64(req_dma_addr);
  1546. hdr->sts_buffer_addr = cpu_to_le64(hisi_sas_status_buf_addr_dma(slot));
  1547. }
  1548. static void prep_ssp_v2_hw(struct hisi_hba *hisi_hba,
  1549. struct hisi_sas_slot *slot)
  1550. {
  1551. struct sas_task *task = slot->task;
  1552. struct hisi_sas_cmd_hdr *hdr = slot->cmd_hdr;
  1553. struct domain_device *device = task->dev;
  1554. struct hisi_sas_device *sas_dev = device->lldd_dev;
  1555. struct hisi_sas_port *port = slot->port;
  1556. struct sas_ssp_task *ssp_task = &task->ssp_task;
  1557. struct scsi_cmnd *scsi_cmnd = ssp_task->cmd;
  1558. struct hisi_sas_tmf_task *tmf = slot->tmf;
  1559. int has_data = 0, priority = !!tmf;
  1560. u8 *buf_cmd;
  1561. u32 dw1 = 0, dw2 = 0;
  1562. hdr->dw0 = cpu_to_le32((1 << CMD_HDR_RESP_REPORT_OFF) |
  1563. (2 << CMD_HDR_TLR_CTRL_OFF) |
  1564. (port->id << CMD_HDR_PORT_OFF) |
  1565. (priority << CMD_HDR_PRIORITY_OFF) |
  1566. (1 << CMD_HDR_CMD_OFF)); /* ssp */
  1567. dw1 = 1 << CMD_HDR_VDTL_OFF;
  1568. if (tmf) {
  1569. dw1 |= 2 << CMD_HDR_FRAME_TYPE_OFF;
  1570. dw1 |= DIR_NO_DATA << CMD_HDR_DIR_OFF;
  1571. } else {
  1572. dw1 |= 1 << CMD_HDR_FRAME_TYPE_OFF;
  1573. switch (scsi_cmnd->sc_data_direction) {
  1574. case DMA_TO_DEVICE:
  1575. has_data = 1;
  1576. dw1 |= DIR_TO_DEVICE << CMD_HDR_DIR_OFF;
  1577. break;
  1578. case DMA_FROM_DEVICE:
  1579. has_data = 1;
  1580. dw1 |= DIR_TO_INI << CMD_HDR_DIR_OFF;
  1581. break;
  1582. default:
  1583. dw1 &= ~CMD_HDR_DIR_MSK;
  1584. }
  1585. }
  1586. /* map itct entry */
  1587. dw1 |= sas_dev->device_id << CMD_HDR_DEV_ID_OFF;
  1588. hdr->dw1 = cpu_to_le32(dw1);
  1589. dw2 = (((sizeof(struct ssp_command_iu) + sizeof(struct ssp_frame_hdr)
  1590. + 3) / 4) << CMD_HDR_CFL_OFF) |
  1591. ((HISI_SAS_MAX_SSP_RESP_SZ / 4) << CMD_HDR_MRFL_OFF) |
  1592. (2 << CMD_HDR_SG_MOD_OFF);
  1593. hdr->dw2 = cpu_to_le32(dw2);
  1594. hdr->transfer_tags = cpu_to_le32(slot->idx);
  1595. if (has_data)
  1596. prep_prd_sge_v2_hw(hisi_hba, slot, hdr, task->scatter,
  1597. slot->n_elem);
  1598. hdr->data_transfer_len = cpu_to_le32(task->total_xfer_len);
  1599. hdr->cmd_table_addr = cpu_to_le64(hisi_sas_cmd_hdr_addr_dma(slot));
  1600. hdr->sts_buffer_addr = cpu_to_le64(hisi_sas_status_buf_addr_dma(slot));
  1601. buf_cmd = hisi_sas_cmd_hdr_addr_mem(slot) +
  1602. sizeof(struct ssp_frame_hdr);
  1603. memcpy(buf_cmd, &task->ssp_task.LUN, 8);
  1604. if (!tmf) {
  1605. buf_cmd[9] = task->ssp_task.task_attr |
  1606. (task->ssp_task.task_prio << 3);
  1607. memcpy(buf_cmd + 12, task->ssp_task.cmd->cmnd,
  1608. task->ssp_task.cmd->cmd_len);
  1609. } else {
  1610. buf_cmd[10] = tmf->tmf;
  1611. switch (tmf->tmf) {
  1612. case TMF_ABORT_TASK:
  1613. case TMF_QUERY_TASK:
  1614. buf_cmd[12] =
  1615. (tmf->tag_of_task_to_be_managed >> 8) & 0xff;
  1616. buf_cmd[13] =
  1617. tmf->tag_of_task_to_be_managed & 0xff;
  1618. break;
  1619. default:
  1620. break;
  1621. }
  1622. }
  1623. }
  1624. #define TRANS_TX_ERR 0
  1625. #define TRANS_RX_ERR 1
  1626. #define DMA_TX_ERR 2
  1627. #define SIPC_RX_ERR 3
  1628. #define DMA_RX_ERR 4
  1629. #define DMA_TX_ERR_OFF 0
  1630. #define DMA_TX_ERR_MSK (0xffff << DMA_TX_ERR_OFF)
  1631. #define SIPC_RX_ERR_OFF 16
  1632. #define SIPC_RX_ERR_MSK (0xffff << SIPC_RX_ERR_OFF)
  1633. static int parse_trans_tx_err_code_v2_hw(u32 err_msk)
  1634. {
  1635. static const u8 trans_tx_err_code_prio[] = {
  1636. TRANS_TX_OPEN_FAIL_WITH_IT_NEXUS_LOSS,
  1637. TRANS_TX_ERR_PHY_NOT_ENABLE,
  1638. TRANS_TX_OPEN_CNX_ERR_WRONG_DESTINATION,
  1639. TRANS_TX_OPEN_CNX_ERR_ZONE_VIOLATION,
  1640. TRANS_TX_OPEN_CNX_ERR_BY_OTHER,
  1641. RESERVED0,
  1642. TRANS_TX_OPEN_CNX_ERR_AIP_TIMEOUT,
  1643. TRANS_TX_OPEN_CNX_ERR_STP_RESOURCES_BUSY,
  1644. TRANS_TX_OPEN_CNX_ERR_PROTOCOL_NOT_SUPPORTED,
  1645. TRANS_TX_OPEN_CNX_ERR_CONNECTION_RATE_NOT_SUPPORTED,
  1646. TRANS_TX_OPEN_CNX_ERR_BAD_DESTINATION,
  1647. TRANS_TX_OPEN_CNX_ERR_BREAK_RCVD,
  1648. TRANS_TX_OPEN_CNX_ERR_LOW_PHY_POWER,
  1649. TRANS_TX_OPEN_CNX_ERR_PATHWAY_BLOCKED,
  1650. TRANS_TX_OPEN_CNX_ERR_OPEN_TIMEOUT,
  1651. TRANS_TX_OPEN_CNX_ERR_NO_DESTINATION,
  1652. TRANS_TX_OPEN_RETRY_ERR_THRESHOLD_REACHED,
  1653. TRANS_TX_ERR_WITH_CLOSE_PHYDISALE,
  1654. TRANS_TX_ERR_WITH_CLOSE_DWS_TIMEOUT,
  1655. TRANS_TX_ERR_WITH_CLOSE_COMINIT,
  1656. TRANS_TX_ERR_WITH_BREAK_TIMEOUT,
  1657. TRANS_TX_ERR_WITH_BREAK_REQUEST,
  1658. TRANS_TX_ERR_WITH_BREAK_RECEVIED,
  1659. TRANS_TX_ERR_WITH_CLOSE_TIMEOUT,
  1660. TRANS_TX_ERR_WITH_CLOSE_NORMAL,
  1661. TRANS_TX_ERR_WITH_NAK_RECEVIED,
  1662. TRANS_TX_ERR_WITH_ACK_NAK_TIMEOUT,
  1663. TRANS_TX_ERR_WITH_CREDIT_TIMEOUT,
  1664. TRANS_TX_ERR_WITH_IPTT_CONFLICT,
  1665. TRANS_TX_ERR_WITH_OPEN_BY_DES_OR_OTHERS,
  1666. TRANS_TX_ERR_WITH_WAIT_RECV_TIMEOUT,
  1667. };
  1668. int index, i;
  1669. for (i = 0; i < ARRAY_SIZE(trans_tx_err_code_prio); i++) {
  1670. index = trans_tx_err_code_prio[i] - TRANS_TX_FAIL_BASE;
  1671. if (err_msk & (1 << index))
  1672. return trans_tx_err_code_prio[i];
  1673. }
  1674. return -1;
  1675. }
  1676. static int parse_trans_rx_err_code_v2_hw(u32 err_msk)
  1677. {
  1678. static const u8 trans_rx_err_code_prio[] = {
  1679. TRANS_RX_ERR_WITH_RXFRAME_CRC_ERR,
  1680. TRANS_RX_ERR_WITH_RXFIS_8B10B_DISP_ERR,
  1681. TRANS_RX_ERR_WITH_RXFRAME_HAVE_ERRPRM,
  1682. TRANS_RX_ERR_WITH_RXFIS_DECODE_ERROR,
  1683. TRANS_RX_ERR_WITH_RXFIS_CRC_ERR,
  1684. TRANS_RX_ERR_WITH_RXFRAME_LENGTH_OVERRUN,
  1685. TRANS_RX_ERR_WITH_RXFIS_RX_SYNCP,
  1686. TRANS_RX_ERR_WITH_LINK_BUF_OVERRUN,
  1687. TRANS_RX_ERR_WITH_CLOSE_PHY_DISABLE,
  1688. TRANS_RX_ERR_WITH_CLOSE_DWS_TIMEOUT,
  1689. TRANS_RX_ERR_WITH_CLOSE_COMINIT,
  1690. TRANS_RX_ERR_WITH_BREAK_TIMEOUT,
  1691. TRANS_RX_ERR_WITH_BREAK_REQUEST,
  1692. TRANS_RX_ERR_WITH_BREAK_RECEVIED,
  1693. RESERVED1,
  1694. TRANS_RX_ERR_WITH_CLOSE_NORMAL,
  1695. TRANS_RX_ERR_WITH_DATA_LEN0,
  1696. TRANS_RX_ERR_WITH_BAD_HASH,
  1697. TRANS_RX_XRDY_WLEN_ZERO_ERR,
  1698. TRANS_RX_SSP_FRM_LEN_ERR,
  1699. RESERVED2,
  1700. RESERVED3,
  1701. RESERVED4,
  1702. RESERVED5,
  1703. TRANS_RX_ERR_WITH_BAD_FRM_TYPE,
  1704. TRANS_RX_SMP_FRM_LEN_ERR,
  1705. TRANS_RX_SMP_RESP_TIMEOUT_ERR,
  1706. RESERVED6,
  1707. RESERVED7,
  1708. RESERVED8,
  1709. RESERVED9,
  1710. TRANS_RX_R_ERR,
  1711. };
  1712. int index, i;
  1713. for (i = 0; i < ARRAY_SIZE(trans_rx_err_code_prio); i++) {
  1714. index = trans_rx_err_code_prio[i] - TRANS_RX_FAIL_BASE;
  1715. if (err_msk & (1 << index))
  1716. return trans_rx_err_code_prio[i];
  1717. }
  1718. return -1;
  1719. }
  1720. static int parse_dma_tx_err_code_v2_hw(u32 err_msk)
  1721. {
  1722. static const u8 dma_tx_err_code_prio[] = {
  1723. DMA_TX_UNEXP_XFER_ERR,
  1724. DMA_TX_UNEXP_RETRANS_ERR,
  1725. DMA_TX_XFER_LEN_OVERFLOW,
  1726. DMA_TX_XFER_OFFSET_ERR,
  1727. DMA_TX_RAM_ECC_ERR,
  1728. DMA_TX_DIF_LEN_ALIGN_ERR,
  1729. DMA_TX_DIF_CRC_ERR,
  1730. DMA_TX_DIF_APP_ERR,
  1731. DMA_TX_DIF_RPP_ERR,
  1732. DMA_TX_DATA_SGL_OVERFLOW,
  1733. DMA_TX_DIF_SGL_OVERFLOW,
  1734. };
  1735. int index, i;
  1736. for (i = 0; i < ARRAY_SIZE(dma_tx_err_code_prio); i++) {
  1737. index = dma_tx_err_code_prio[i] - DMA_TX_ERR_BASE;
  1738. err_msk = err_msk & DMA_TX_ERR_MSK;
  1739. if (err_msk & (1 << index))
  1740. return dma_tx_err_code_prio[i];
  1741. }
  1742. return -1;
  1743. }
  1744. static int parse_sipc_rx_err_code_v2_hw(u32 err_msk)
  1745. {
  1746. static const u8 sipc_rx_err_code_prio[] = {
  1747. SIPC_RX_FIS_STATUS_ERR_BIT_VLD,
  1748. SIPC_RX_PIO_WRSETUP_STATUS_DRQ_ERR,
  1749. SIPC_RX_FIS_STATUS_BSY_BIT_ERR,
  1750. SIPC_RX_WRSETUP_LEN_ODD_ERR,
  1751. SIPC_RX_WRSETUP_LEN_ZERO_ERR,
  1752. SIPC_RX_WRDATA_LEN_NOT_MATCH_ERR,
  1753. SIPC_RX_NCQ_WRSETUP_OFFSET_ERR,
  1754. SIPC_RX_NCQ_WRSETUP_AUTO_ACTIVE_ERR,
  1755. SIPC_RX_SATA_UNEXP_FIS_ERR,
  1756. SIPC_RX_WRSETUP_ESTATUS_ERR,
  1757. SIPC_RX_DATA_UNDERFLOW_ERR,
  1758. };
  1759. int index, i;
  1760. for (i = 0; i < ARRAY_SIZE(sipc_rx_err_code_prio); i++) {
  1761. index = sipc_rx_err_code_prio[i] - SIPC_RX_ERR_BASE;
  1762. err_msk = err_msk & SIPC_RX_ERR_MSK;
  1763. if (err_msk & (1 << (index + 0x10)))
  1764. return sipc_rx_err_code_prio[i];
  1765. }
  1766. return -1;
  1767. }
  1768. static int parse_dma_rx_err_code_v2_hw(u32 err_msk)
  1769. {
  1770. static const u8 dma_rx_err_code_prio[] = {
  1771. DMA_RX_UNKNOWN_FRM_ERR,
  1772. DMA_RX_DATA_LEN_OVERFLOW,
  1773. DMA_RX_DATA_LEN_UNDERFLOW,
  1774. DMA_RX_DATA_OFFSET_ERR,
  1775. RESERVED10,
  1776. DMA_RX_SATA_FRAME_TYPE_ERR,
  1777. DMA_RX_RESP_BUF_OVERFLOW,
  1778. DMA_RX_UNEXP_RETRANS_RESP_ERR,
  1779. DMA_RX_UNEXP_NORM_RESP_ERR,
  1780. DMA_RX_UNEXP_RDFRAME_ERR,
  1781. DMA_RX_PIO_DATA_LEN_ERR,
  1782. DMA_RX_RDSETUP_STATUS_ERR,
  1783. DMA_RX_RDSETUP_STATUS_DRQ_ERR,
  1784. DMA_RX_RDSETUP_STATUS_BSY_ERR,
  1785. DMA_RX_RDSETUP_LEN_ODD_ERR,
  1786. DMA_RX_RDSETUP_LEN_ZERO_ERR,
  1787. DMA_RX_RDSETUP_LEN_OVER_ERR,
  1788. DMA_RX_RDSETUP_OFFSET_ERR,
  1789. DMA_RX_RDSETUP_ACTIVE_ERR,
  1790. DMA_RX_RDSETUP_ESTATUS_ERR,
  1791. DMA_RX_RAM_ECC_ERR,
  1792. DMA_RX_DIF_CRC_ERR,
  1793. DMA_RX_DIF_APP_ERR,
  1794. DMA_RX_DIF_RPP_ERR,
  1795. DMA_RX_DATA_SGL_OVERFLOW,
  1796. DMA_RX_DIF_SGL_OVERFLOW,
  1797. };
  1798. int index, i;
  1799. for (i = 0; i < ARRAY_SIZE(dma_rx_err_code_prio); i++) {
  1800. index = dma_rx_err_code_prio[i] - DMA_RX_ERR_BASE;
  1801. if (err_msk & (1 << index))
  1802. return dma_rx_err_code_prio[i];
  1803. }
  1804. return -1;
  1805. }
  1806. /* by default, task resp is complete */
  1807. static void slot_err_v2_hw(struct hisi_hba *hisi_hba,
  1808. struct sas_task *task,
  1809. struct hisi_sas_slot *slot,
  1810. int err_phase)
  1811. {
  1812. struct task_status_struct *ts = &task->task_status;
  1813. struct hisi_sas_err_record_v2 *err_record =
  1814. hisi_sas_status_buf_addr_mem(slot);
  1815. u32 trans_tx_fail_type = le32_to_cpu(err_record->trans_tx_fail_type);
  1816. u32 trans_rx_fail_type = le32_to_cpu(err_record->trans_rx_fail_type);
  1817. u16 dma_tx_err_type = le16_to_cpu(err_record->dma_tx_err_type);
  1818. u16 sipc_rx_err_type = le16_to_cpu(err_record->sipc_rx_err_type);
  1819. u32 dma_rx_err_type = le32_to_cpu(err_record->dma_rx_err_type);
  1820. int error = -1;
  1821. if (err_phase == 1) {
  1822. /* error in TX phase, the priority of error is: DW2 > DW0 */
  1823. error = parse_dma_tx_err_code_v2_hw(dma_tx_err_type);
  1824. if (error == -1)
  1825. error = parse_trans_tx_err_code_v2_hw(
  1826. trans_tx_fail_type);
  1827. } else if (err_phase == 2) {
  1828. /* error in RX phase, the priority is: DW1 > DW3 > DW2 */
  1829. error = parse_trans_rx_err_code_v2_hw(trans_rx_fail_type);
  1830. if (error == -1) {
  1831. error = parse_dma_rx_err_code_v2_hw(
  1832. dma_rx_err_type);
  1833. if (error == -1)
  1834. error = parse_sipc_rx_err_code_v2_hw(
  1835. sipc_rx_err_type);
  1836. }
  1837. }
  1838. switch (task->task_proto) {
  1839. case SAS_PROTOCOL_SSP:
  1840. {
  1841. switch (error) {
  1842. case TRANS_TX_OPEN_CNX_ERR_NO_DESTINATION:
  1843. {
  1844. ts->stat = SAS_OPEN_REJECT;
  1845. ts->open_rej_reason = SAS_OREJ_NO_DEST;
  1846. break;
  1847. }
  1848. case TRANS_TX_OPEN_CNX_ERR_PROTOCOL_NOT_SUPPORTED:
  1849. {
  1850. ts->stat = SAS_OPEN_REJECT;
  1851. ts->open_rej_reason = SAS_OREJ_EPROTO;
  1852. break;
  1853. }
  1854. case TRANS_TX_OPEN_CNX_ERR_CONNECTION_RATE_NOT_SUPPORTED:
  1855. {
  1856. ts->stat = SAS_OPEN_REJECT;
  1857. ts->open_rej_reason = SAS_OREJ_CONN_RATE;
  1858. break;
  1859. }
  1860. case TRANS_TX_OPEN_CNX_ERR_BAD_DESTINATION:
  1861. {
  1862. ts->stat = SAS_OPEN_REJECT;
  1863. ts->open_rej_reason = SAS_OREJ_BAD_DEST;
  1864. break;
  1865. }
  1866. case TRANS_TX_OPEN_CNX_ERR_WRONG_DESTINATION:
  1867. {
  1868. ts->stat = SAS_OPEN_REJECT;
  1869. ts->open_rej_reason = SAS_OREJ_WRONG_DEST;
  1870. break;
  1871. }
  1872. case DMA_RX_UNEXP_NORM_RESP_ERR:
  1873. case TRANS_TX_OPEN_CNX_ERR_ZONE_VIOLATION:
  1874. case DMA_RX_RESP_BUF_OVERFLOW:
  1875. {
  1876. ts->stat = SAS_OPEN_REJECT;
  1877. ts->open_rej_reason = SAS_OREJ_UNKNOWN;
  1878. break;
  1879. }
  1880. case TRANS_TX_OPEN_CNX_ERR_LOW_PHY_POWER:
  1881. {
  1882. /* not sure */
  1883. ts->stat = SAS_DEV_NO_RESPONSE;
  1884. break;
  1885. }
  1886. case DMA_RX_DATA_LEN_OVERFLOW:
  1887. {
  1888. ts->stat = SAS_DATA_OVERRUN;
  1889. ts->residual = 0;
  1890. break;
  1891. }
  1892. case DMA_RX_DATA_LEN_UNDERFLOW:
  1893. {
  1894. ts->residual = trans_tx_fail_type;
  1895. ts->stat = SAS_DATA_UNDERRUN;
  1896. break;
  1897. }
  1898. case TRANS_TX_OPEN_FAIL_WITH_IT_NEXUS_LOSS:
  1899. case TRANS_TX_ERR_PHY_NOT_ENABLE:
  1900. case TRANS_TX_OPEN_CNX_ERR_BY_OTHER:
  1901. case TRANS_TX_OPEN_CNX_ERR_AIP_TIMEOUT:
  1902. case TRANS_TX_OPEN_CNX_ERR_BREAK_RCVD:
  1903. case TRANS_TX_OPEN_CNX_ERR_PATHWAY_BLOCKED:
  1904. case TRANS_TX_OPEN_CNX_ERR_OPEN_TIMEOUT:
  1905. case TRANS_TX_OPEN_RETRY_ERR_THRESHOLD_REACHED:
  1906. case TRANS_TX_ERR_WITH_BREAK_TIMEOUT:
  1907. case TRANS_TX_ERR_WITH_BREAK_REQUEST:
  1908. case TRANS_TX_ERR_WITH_BREAK_RECEVIED:
  1909. case TRANS_TX_ERR_WITH_CLOSE_TIMEOUT:
  1910. case TRANS_TX_ERR_WITH_CLOSE_NORMAL:
  1911. case TRANS_TX_ERR_WITH_CLOSE_PHYDISALE:
  1912. case TRANS_TX_ERR_WITH_CLOSE_DWS_TIMEOUT:
  1913. case TRANS_TX_ERR_WITH_CLOSE_COMINIT:
  1914. case TRANS_TX_ERR_WITH_NAK_RECEVIED:
  1915. case TRANS_TX_ERR_WITH_ACK_NAK_TIMEOUT:
  1916. case TRANS_TX_ERR_WITH_CREDIT_TIMEOUT:
  1917. case TRANS_TX_ERR_WITH_IPTT_CONFLICT:
  1918. case TRANS_RX_ERR_WITH_RXFRAME_CRC_ERR:
  1919. case TRANS_RX_ERR_WITH_RXFIS_8B10B_DISP_ERR:
  1920. case TRANS_RX_ERR_WITH_RXFRAME_HAVE_ERRPRM:
  1921. case TRANS_RX_ERR_WITH_LINK_BUF_OVERRUN:
  1922. case TRANS_RX_ERR_WITH_BREAK_TIMEOUT:
  1923. case TRANS_RX_ERR_WITH_BREAK_REQUEST:
  1924. case TRANS_RX_ERR_WITH_BREAK_RECEVIED:
  1925. case TRANS_RX_ERR_WITH_CLOSE_NORMAL:
  1926. case TRANS_RX_ERR_WITH_CLOSE_DWS_TIMEOUT:
  1927. case TRANS_RX_ERR_WITH_CLOSE_COMINIT:
  1928. case TRANS_TX_ERR_FRAME_TXED:
  1929. case TRANS_RX_ERR_WITH_CLOSE_PHY_DISABLE:
  1930. case TRANS_RX_ERR_WITH_DATA_LEN0:
  1931. case TRANS_RX_ERR_WITH_BAD_HASH:
  1932. case TRANS_RX_XRDY_WLEN_ZERO_ERR:
  1933. case TRANS_RX_SSP_FRM_LEN_ERR:
  1934. case TRANS_RX_ERR_WITH_BAD_FRM_TYPE:
  1935. case DMA_TX_DATA_SGL_OVERFLOW:
  1936. case DMA_TX_UNEXP_XFER_ERR:
  1937. case DMA_TX_UNEXP_RETRANS_ERR:
  1938. case DMA_TX_XFER_LEN_OVERFLOW:
  1939. case DMA_TX_XFER_OFFSET_ERR:
  1940. case SIPC_RX_DATA_UNDERFLOW_ERR:
  1941. case DMA_RX_DATA_SGL_OVERFLOW:
  1942. case DMA_RX_DATA_OFFSET_ERR:
  1943. case DMA_RX_RDSETUP_LEN_ODD_ERR:
  1944. case DMA_RX_RDSETUP_LEN_ZERO_ERR:
  1945. case DMA_RX_RDSETUP_LEN_OVER_ERR:
  1946. case DMA_RX_SATA_FRAME_TYPE_ERR:
  1947. case DMA_RX_UNKNOWN_FRM_ERR:
  1948. {
  1949. /* This will request a retry */
  1950. ts->stat = SAS_QUEUE_FULL;
  1951. slot->abort = 1;
  1952. break;
  1953. }
  1954. default:
  1955. break;
  1956. }
  1957. }
  1958. break;
  1959. case SAS_PROTOCOL_SMP:
  1960. ts->stat = SAM_STAT_CHECK_CONDITION;
  1961. break;
  1962. case SAS_PROTOCOL_SATA:
  1963. case SAS_PROTOCOL_STP:
  1964. case SAS_PROTOCOL_SATA | SAS_PROTOCOL_STP:
  1965. {
  1966. switch (error) {
  1967. case TRANS_TX_OPEN_CNX_ERR_NO_DESTINATION:
  1968. {
  1969. ts->stat = SAS_OPEN_REJECT;
  1970. ts->open_rej_reason = SAS_OREJ_NO_DEST;
  1971. break;
  1972. }
  1973. case TRANS_TX_OPEN_CNX_ERR_LOW_PHY_POWER:
  1974. {
  1975. ts->resp = SAS_TASK_UNDELIVERED;
  1976. ts->stat = SAS_DEV_NO_RESPONSE;
  1977. break;
  1978. }
  1979. case TRANS_TX_OPEN_CNX_ERR_PROTOCOL_NOT_SUPPORTED:
  1980. {
  1981. ts->stat = SAS_OPEN_REJECT;
  1982. ts->open_rej_reason = SAS_OREJ_EPROTO;
  1983. break;
  1984. }
  1985. case TRANS_TX_OPEN_CNX_ERR_CONNECTION_RATE_NOT_SUPPORTED:
  1986. {
  1987. ts->stat = SAS_OPEN_REJECT;
  1988. ts->open_rej_reason = SAS_OREJ_CONN_RATE;
  1989. break;
  1990. }
  1991. case TRANS_TX_OPEN_CNX_ERR_BAD_DESTINATION:
  1992. {
  1993. ts->stat = SAS_OPEN_REJECT;
  1994. ts->open_rej_reason = SAS_OREJ_CONN_RATE;
  1995. break;
  1996. }
  1997. case TRANS_TX_OPEN_CNX_ERR_WRONG_DESTINATION:
  1998. {
  1999. ts->stat = SAS_OPEN_REJECT;
  2000. ts->open_rej_reason = SAS_OREJ_WRONG_DEST;
  2001. break;
  2002. }
  2003. case DMA_RX_RESP_BUF_OVERFLOW:
  2004. case DMA_RX_UNEXP_NORM_RESP_ERR:
  2005. case TRANS_TX_OPEN_CNX_ERR_ZONE_VIOLATION:
  2006. {
  2007. ts->stat = SAS_OPEN_REJECT;
  2008. ts->open_rej_reason = SAS_OREJ_UNKNOWN;
  2009. break;
  2010. }
  2011. case DMA_RX_DATA_LEN_OVERFLOW:
  2012. {
  2013. ts->stat = SAS_DATA_OVERRUN;
  2014. ts->residual = 0;
  2015. break;
  2016. }
  2017. case DMA_RX_DATA_LEN_UNDERFLOW:
  2018. {
  2019. ts->residual = trans_tx_fail_type;
  2020. ts->stat = SAS_DATA_UNDERRUN;
  2021. break;
  2022. }
  2023. case TRANS_TX_OPEN_FAIL_WITH_IT_NEXUS_LOSS:
  2024. case TRANS_TX_ERR_PHY_NOT_ENABLE:
  2025. case TRANS_TX_OPEN_CNX_ERR_BY_OTHER:
  2026. case TRANS_TX_OPEN_CNX_ERR_AIP_TIMEOUT:
  2027. case TRANS_TX_OPEN_CNX_ERR_BREAK_RCVD:
  2028. case TRANS_TX_OPEN_CNX_ERR_PATHWAY_BLOCKED:
  2029. case TRANS_TX_OPEN_CNX_ERR_OPEN_TIMEOUT:
  2030. case TRANS_TX_OPEN_RETRY_ERR_THRESHOLD_REACHED:
  2031. case TRANS_TX_ERR_WITH_BREAK_TIMEOUT:
  2032. case TRANS_TX_ERR_WITH_BREAK_REQUEST:
  2033. case TRANS_TX_ERR_WITH_BREAK_RECEVIED:
  2034. case TRANS_TX_ERR_WITH_CLOSE_TIMEOUT:
  2035. case TRANS_TX_ERR_WITH_CLOSE_NORMAL:
  2036. case TRANS_TX_ERR_WITH_CLOSE_PHYDISALE:
  2037. case TRANS_TX_ERR_WITH_CLOSE_DWS_TIMEOUT:
  2038. case TRANS_TX_ERR_WITH_CLOSE_COMINIT:
  2039. case TRANS_TX_ERR_WITH_ACK_NAK_TIMEOUT:
  2040. case TRANS_TX_ERR_WITH_CREDIT_TIMEOUT:
  2041. case TRANS_TX_ERR_WITH_OPEN_BY_DES_OR_OTHERS:
  2042. case TRANS_TX_ERR_WITH_WAIT_RECV_TIMEOUT:
  2043. case TRANS_RX_ERR_WITH_RXFRAME_HAVE_ERRPRM:
  2044. case TRANS_RX_ERR_WITH_RXFIS_8B10B_DISP_ERR:
  2045. case TRANS_RX_ERR_WITH_RXFIS_DECODE_ERROR:
  2046. case TRANS_RX_ERR_WITH_RXFIS_CRC_ERR:
  2047. case TRANS_RX_ERR_WITH_RXFRAME_LENGTH_OVERRUN:
  2048. case TRANS_RX_ERR_WITH_RXFIS_RX_SYNCP:
  2049. case TRANS_RX_ERR_WITH_LINK_BUF_OVERRUN:
  2050. case TRANS_RX_ERR_WITH_BREAK_TIMEOUT:
  2051. case TRANS_RX_ERR_WITH_BREAK_REQUEST:
  2052. case TRANS_RX_ERR_WITH_BREAK_RECEVIED:
  2053. case TRANS_RX_ERR_WITH_CLOSE_NORMAL:
  2054. case TRANS_RX_ERR_WITH_CLOSE_PHY_DISABLE:
  2055. case TRANS_RX_ERR_WITH_CLOSE_DWS_TIMEOUT:
  2056. case TRANS_RX_ERR_WITH_CLOSE_COMINIT:
  2057. case TRANS_RX_ERR_WITH_DATA_LEN0:
  2058. case TRANS_RX_ERR_WITH_BAD_HASH:
  2059. case TRANS_RX_XRDY_WLEN_ZERO_ERR:
  2060. case TRANS_RX_ERR_WITH_BAD_FRM_TYPE:
  2061. case DMA_TX_DATA_SGL_OVERFLOW:
  2062. case DMA_TX_UNEXP_XFER_ERR:
  2063. case DMA_TX_UNEXP_RETRANS_ERR:
  2064. case DMA_TX_XFER_LEN_OVERFLOW:
  2065. case DMA_TX_XFER_OFFSET_ERR:
  2066. case SIPC_RX_FIS_STATUS_ERR_BIT_VLD:
  2067. case SIPC_RX_PIO_WRSETUP_STATUS_DRQ_ERR:
  2068. case SIPC_RX_FIS_STATUS_BSY_BIT_ERR:
  2069. case SIPC_RX_WRSETUP_LEN_ODD_ERR:
  2070. case SIPC_RX_WRSETUP_LEN_ZERO_ERR:
  2071. case SIPC_RX_WRDATA_LEN_NOT_MATCH_ERR:
  2072. case SIPC_RX_SATA_UNEXP_FIS_ERR:
  2073. case DMA_RX_DATA_SGL_OVERFLOW:
  2074. case DMA_RX_DATA_OFFSET_ERR:
  2075. case DMA_RX_SATA_FRAME_TYPE_ERR:
  2076. case DMA_RX_UNEXP_RDFRAME_ERR:
  2077. case DMA_RX_PIO_DATA_LEN_ERR:
  2078. case DMA_RX_RDSETUP_STATUS_ERR:
  2079. case DMA_RX_RDSETUP_STATUS_DRQ_ERR:
  2080. case DMA_RX_RDSETUP_STATUS_BSY_ERR:
  2081. case DMA_RX_RDSETUP_LEN_ODD_ERR:
  2082. case DMA_RX_RDSETUP_LEN_ZERO_ERR:
  2083. case DMA_RX_RDSETUP_LEN_OVER_ERR:
  2084. case DMA_RX_RDSETUP_OFFSET_ERR:
  2085. case DMA_RX_RDSETUP_ACTIVE_ERR:
  2086. case DMA_RX_RDSETUP_ESTATUS_ERR:
  2087. case DMA_RX_UNKNOWN_FRM_ERR:
  2088. case TRANS_RX_SSP_FRM_LEN_ERR:
  2089. case TRANS_TX_OPEN_CNX_ERR_STP_RESOURCES_BUSY:
  2090. {
  2091. slot->abort = 1;
  2092. ts->stat = SAS_PHY_DOWN;
  2093. break;
  2094. }
  2095. default:
  2096. {
  2097. ts->stat = SAS_PROTO_RESPONSE;
  2098. break;
  2099. }
  2100. }
  2101. hisi_sas_sata_done(task, slot);
  2102. }
  2103. break;
  2104. default:
  2105. break;
  2106. }
  2107. }
  2108. static int
  2109. slot_complete_v2_hw(struct hisi_hba *hisi_hba, struct hisi_sas_slot *slot)
  2110. {
  2111. struct sas_task *task = slot->task;
  2112. struct hisi_sas_device *sas_dev;
  2113. struct device *dev = hisi_hba->dev;
  2114. struct task_status_struct *ts;
  2115. struct domain_device *device;
  2116. struct sas_ha_struct *ha;
  2117. enum exec_status sts;
  2118. struct hisi_sas_complete_v2_hdr *complete_queue =
  2119. hisi_hba->complete_hdr[slot->cmplt_queue];
  2120. struct hisi_sas_complete_v2_hdr *complete_hdr =
  2121. &complete_queue[slot->cmplt_queue_slot];
  2122. unsigned long flags;
  2123. bool is_internal = slot->is_internal;
  2124. u32 dw0;
  2125. if (unlikely(!task || !task->lldd_task || !task->dev))
  2126. return -EINVAL;
  2127. ts = &task->task_status;
  2128. device = task->dev;
  2129. ha = device->port->ha;
  2130. sas_dev = device->lldd_dev;
  2131. spin_lock_irqsave(&task->task_state_lock, flags);
  2132. task->task_state_flags &=
  2133. ~(SAS_TASK_STATE_PENDING | SAS_TASK_AT_INITIATOR);
  2134. spin_unlock_irqrestore(&task->task_state_lock, flags);
  2135. memset(ts, 0, sizeof(*ts));
  2136. ts->resp = SAS_TASK_COMPLETE;
  2137. if (unlikely(!sas_dev)) {
  2138. dev_dbg(dev, "slot complete: port has no device\n");
  2139. ts->stat = SAS_PHY_DOWN;
  2140. goto out;
  2141. }
  2142. /* Use SAS+TMF status codes */
  2143. dw0 = le32_to_cpu(complete_hdr->dw0);
  2144. switch ((dw0 & CMPLT_HDR_ABORT_STAT_MSK) >>
  2145. CMPLT_HDR_ABORT_STAT_OFF) {
  2146. case STAT_IO_ABORTED:
  2147. /* this io has been aborted by abort command */
  2148. ts->stat = SAS_ABORTED_TASK;
  2149. goto out;
  2150. case STAT_IO_COMPLETE:
  2151. /* internal abort command complete */
  2152. ts->stat = TMF_RESP_FUNC_SUCC;
  2153. del_timer(&slot->internal_abort_timer);
  2154. goto out;
  2155. case STAT_IO_NO_DEVICE:
  2156. ts->stat = TMF_RESP_FUNC_COMPLETE;
  2157. del_timer(&slot->internal_abort_timer);
  2158. goto out;
  2159. case STAT_IO_NOT_VALID:
  2160. /* abort single io, controller don't find
  2161. * the io need to abort
  2162. */
  2163. ts->stat = TMF_RESP_FUNC_FAILED;
  2164. del_timer(&slot->internal_abort_timer);
  2165. goto out;
  2166. default:
  2167. break;
  2168. }
  2169. if ((dw0 & CMPLT_HDR_ERX_MSK) && (!(dw0 & CMPLT_HDR_RSPNS_XFRD_MSK))) {
  2170. u32 err_phase = (dw0 & CMPLT_HDR_ERR_PHASE_MSK)
  2171. >> CMPLT_HDR_ERR_PHASE_OFF;
  2172. u32 *error_info = hisi_sas_status_buf_addr_mem(slot);
  2173. /* Analyse error happens on which phase TX or RX */
  2174. if (ERR_ON_TX_PHASE(err_phase))
  2175. slot_err_v2_hw(hisi_hba, task, slot, 1);
  2176. else if (ERR_ON_RX_PHASE(err_phase))
  2177. slot_err_v2_hw(hisi_hba, task, slot, 2);
  2178. if (ts->stat != SAS_DATA_UNDERRUN)
  2179. dev_info(dev, "erroneous completion iptt=%d task=%p dev id=%d "
  2180. "CQ hdr: 0x%x 0x%x 0x%x 0x%x "
  2181. "Error info: 0x%x 0x%x 0x%x 0x%x\n",
  2182. slot->idx, task, sas_dev->device_id,
  2183. complete_hdr->dw0, complete_hdr->dw1,
  2184. complete_hdr->act, complete_hdr->dw3,
  2185. error_info[0], error_info[1],
  2186. error_info[2], error_info[3]);
  2187. if (unlikely(slot->abort))
  2188. return ts->stat;
  2189. goto out;
  2190. }
  2191. switch (task->task_proto) {
  2192. case SAS_PROTOCOL_SSP:
  2193. {
  2194. struct hisi_sas_status_buffer *status_buffer =
  2195. hisi_sas_status_buf_addr_mem(slot);
  2196. struct ssp_response_iu *iu = (struct ssp_response_iu *)
  2197. &status_buffer->iu[0];
  2198. sas_ssp_task_response(dev, task, iu);
  2199. break;
  2200. }
  2201. case SAS_PROTOCOL_SMP:
  2202. {
  2203. struct scatterlist *sg_resp = &task->smp_task.smp_resp;
  2204. void *to;
  2205. ts->stat = SAM_STAT_GOOD;
  2206. to = kmap_atomic(sg_page(sg_resp));
  2207. dma_unmap_sg(dev, &task->smp_task.smp_resp, 1,
  2208. DMA_FROM_DEVICE);
  2209. dma_unmap_sg(dev, &task->smp_task.smp_req, 1,
  2210. DMA_TO_DEVICE);
  2211. memcpy(to + sg_resp->offset,
  2212. hisi_sas_status_buf_addr_mem(slot) +
  2213. sizeof(struct hisi_sas_err_record),
  2214. sg_dma_len(sg_resp));
  2215. kunmap_atomic(to);
  2216. break;
  2217. }
  2218. case SAS_PROTOCOL_SATA:
  2219. case SAS_PROTOCOL_STP:
  2220. case SAS_PROTOCOL_SATA | SAS_PROTOCOL_STP:
  2221. {
  2222. ts->stat = SAM_STAT_GOOD;
  2223. hisi_sas_sata_done(task, slot);
  2224. break;
  2225. }
  2226. default:
  2227. ts->stat = SAM_STAT_CHECK_CONDITION;
  2228. break;
  2229. }
  2230. if (!slot->port->port_attached) {
  2231. dev_warn(dev, "slot complete: port %d has removed\n",
  2232. slot->port->sas_port.id);
  2233. ts->stat = SAS_PHY_DOWN;
  2234. }
  2235. out:
  2236. sts = ts->stat;
  2237. spin_lock_irqsave(&task->task_state_lock, flags);
  2238. if (task->task_state_flags & SAS_TASK_STATE_ABORTED) {
  2239. spin_unlock_irqrestore(&task->task_state_lock, flags);
  2240. dev_info(dev, "slot complete: task(%p) aborted\n", task);
  2241. return SAS_ABORTED_TASK;
  2242. }
  2243. task->task_state_flags |= SAS_TASK_STATE_DONE;
  2244. spin_unlock_irqrestore(&task->task_state_lock, flags);
  2245. hisi_sas_slot_task_free(hisi_hba, task, slot);
  2246. if (!is_internal && (task->task_proto != SAS_PROTOCOL_SMP)) {
  2247. spin_lock_irqsave(&device->done_lock, flags);
  2248. if (test_bit(SAS_HA_FROZEN, &ha->state)) {
  2249. spin_unlock_irqrestore(&device->done_lock, flags);
  2250. dev_info(dev, "slot complete: task(%p) ignored\n ",
  2251. task);
  2252. return sts;
  2253. }
  2254. spin_unlock_irqrestore(&device->done_lock, flags);
  2255. }
  2256. if (task->task_done)
  2257. task->task_done(task);
  2258. return sts;
  2259. }
  2260. static void prep_ata_v2_hw(struct hisi_hba *hisi_hba,
  2261. struct hisi_sas_slot *slot)
  2262. {
  2263. struct sas_task *task = slot->task;
  2264. struct domain_device *device = task->dev;
  2265. struct domain_device *parent_dev = device->parent;
  2266. struct hisi_sas_device *sas_dev = device->lldd_dev;
  2267. struct hisi_sas_cmd_hdr *hdr = slot->cmd_hdr;
  2268. struct asd_sas_port *sas_port = device->port;
  2269. struct hisi_sas_port *port = to_hisi_sas_port(sas_port);
  2270. struct hisi_sas_tmf_task *tmf = slot->tmf;
  2271. u8 *buf_cmd;
  2272. int has_data = 0, hdr_tag = 0;
  2273. u32 dw0, dw1 = 0, dw2 = 0;
  2274. /* create header */
  2275. /* dw0 */
  2276. dw0 = port->id << CMD_HDR_PORT_OFF;
  2277. if (parent_dev && DEV_IS_EXPANDER(parent_dev->dev_type))
  2278. dw0 |= 3 << CMD_HDR_CMD_OFF;
  2279. else
  2280. dw0 |= 4 << CMD_HDR_CMD_OFF;
  2281. if (tmf && tmf->force_phy) {
  2282. dw0 |= CMD_HDR_FORCE_PHY_MSK;
  2283. dw0 |= (1 << tmf->phy_id) << CMD_HDR_PHY_ID_OFF;
  2284. }
  2285. hdr->dw0 = cpu_to_le32(dw0);
  2286. /* dw1 */
  2287. switch (task->data_dir) {
  2288. case DMA_TO_DEVICE:
  2289. has_data = 1;
  2290. dw1 |= DIR_TO_DEVICE << CMD_HDR_DIR_OFF;
  2291. break;
  2292. case DMA_FROM_DEVICE:
  2293. has_data = 1;
  2294. dw1 |= DIR_TO_INI << CMD_HDR_DIR_OFF;
  2295. break;
  2296. default:
  2297. dw1 &= ~CMD_HDR_DIR_MSK;
  2298. }
  2299. if ((task->ata_task.fis.command == ATA_CMD_DEV_RESET) &&
  2300. (task->ata_task.fis.control & ATA_SRST))
  2301. dw1 |= 1 << CMD_HDR_RESET_OFF;
  2302. dw1 |= (hisi_sas_get_ata_protocol(
  2303. &task->ata_task.fis, task->data_dir))
  2304. << CMD_HDR_FRAME_TYPE_OFF;
  2305. dw1 |= sas_dev->device_id << CMD_HDR_DEV_ID_OFF;
  2306. hdr->dw1 = cpu_to_le32(dw1);
  2307. /* dw2 */
  2308. if (task->ata_task.use_ncq && hisi_sas_get_ncq_tag(task, &hdr_tag)) {
  2309. task->ata_task.fis.sector_count |= (u8) (hdr_tag << 3);
  2310. dw2 |= hdr_tag << CMD_HDR_NCQ_TAG_OFF;
  2311. }
  2312. dw2 |= (HISI_SAS_MAX_STP_RESP_SZ / 4) << CMD_HDR_CFL_OFF |
  2313. 2 << CMD_HDR_SG_MOD_OFF;
  2314. hdr->dw2 = cpu_to_le32(dw2);
  2315. /* dw3 */
  2316. hdr->transfer_tags = cpu_to_le32(slot->idx);
  2317. if (has_data)
  2318. prep_prd_sge_v2_hw(hisi_hba, slot, hdr, task->scatter,
  2319. slot->n_elem);
  2320. hdr->data_transfer_len = cpu_to_le32(task->total_xfer_len);
  2321. hdr->cmd_table_addr = cpu_to_le64(hisi_sas_cmd_hdr_addr_dma(slot));
  2322. hdr->sts_buffer_addr = cpu_to_le64(hisi_sas_status_buf_addr_dma(slot));
  2323. buf_cmd = hisi_sas_cmd_hdr_addr_mem(slot);
  2324. if (likely(!task->ata_task.device_control_reg_update))
  2325. task->ata_task.fis.flags |= 0x80; /* C=1: update ATA cmd reg */
  2326. /* fill in command FIS */
  2327. memcpy(buf_cmd, &task->ata_task.fis, sizeof(struct host_to_dev_fis));
  2328. }
  2329. static void hisi_sas_internal_abort_quirk_timeout(struct timer_list *t)
  2330. {
  2331. struct hisi_sas_slot *slot = from_timer(slot, t, internal_abort_timer);
  2332. struct hisi_sas_port *port = slot->port;
  2333. struct asd_sas_port *asd_sas_port;
  2334. struct asd_sas_phy *sas_phy;
  2335. if (!port)
  2336. return;
  2337. asd_sas_port = &port->sas_port;
  2338. /* Kick the hardware - send break command */
  2339. list_for_each_entry(sas_phy, &asd_sas_port->phy_list, port_phy_el) {
  2340. struct hisi_sas_phy *phy = sas_phy->lldd_phy;
  2341. struct hisi_hba *hisi_hba = phy->hisi_hba;
  2342. int phy_no = sas_phy->id;
  2343. u32 link_dfx2;
  2344. link_dfx2 = hisi_sas_phy_read32(hisi_hba, phy_no, LINK_DFX2);
  2345. if ((link_dfx2 == LINK_DFX2_RCVR_HOLD_STS_MSK) ||
  2346. (link_dfx2 & LINK_DFX2_SEND_HOLD_STS_MSK)) {
  2347. u32 txid_auto;
  2348. txid_auto = hisi_sas_phy_read32(hisi_hba, phy_no,
  2349. TXID_AUTO);
  2350. txid_auto |= TXID_AUTO_CTB_MSK;
  2351. hisi_sas_phy_write32(hisi_hba, phy_no, TXID_AUTO,
  2352. txid_auto);
  2353. return;
  2354. }
  2355. }
  2356. }
  2357. static void prep_abort_v2_hw(struct hisi_hba *hisi_hba,
  2358. struct hisi_sas_slot *slot,
  2359. int device_id, int abort_flag, int tag_to_abort)
  2360. {
  2361. struct sas_task *task = slot->task;
  2362. struct domain_device *dev = task->dev;
  2363. struct hisi_sas_cmd_hdr *hdr = slot->cmd_hdr;
  2364. struct hisi_sas_port *port = slot->port;
  2365. struct timer_list *timer = &slot->internal_abort_timer;
  2366. /* setup the quirk timer */
  2367. timer_setup(timer, hisi_sas_internal_abort_quirk_timeout, 0);
  2368. /* Set the timeout to 10ms less than internal abort timeout */
  2369. mod_timer(timer, jiffies + msecs_to_jiffies(100));
  2370. /* dw0 */
  2371. hdr->dw0 = cpu_to_le32((5 << CMD_HDR_CMD_OFF) | /*abort*/
  2372. (port->id << CMD_HDR_PORT_OFF) |
  2373. (dev_is_sata(dev) <<
  2374. CMD_HDR_ABORT_DEVICE_TYPE_OFF) |
  2375. (abort_flag << CMD_HDR_ABORT_FLAG_OFF));
  2376. /* dw1 */
  2377. hdr->dw1 = cpu_to_le32(device_id << CMD_HDR_DEV_ID_OFF);
  2378. /* dw7 */
  2379. hdr->dw7 = cpu_to_le32(tag_to_abort << CMD_HDR_ABORT_IPTT_OFF);
  2380. hdr->transfer_tags = cpu_to_le32(slot->idx);
  2381. }
  2382. static int phy_up_v2_hw(int phy_no, struct hisi_hba *hisi_hba)
  2383. {
  2384. int i, res = IRQ_HANDLED;
  2385. u32 port_id, link_rate;
  2386. struct hisi_sas_phy *phy = &hisi_hba->phy[phy_no];
  2387. struct asd_sas_phy *sas_phy = &phy->sas_phy;
  2388. struct device *dev = hisi_hba->dev;
  2389. u32 *frame_rcvd = (u32 *)sas_phy->frame_rcvd;
  2390. struct sas_identify_frame *id = (struct sas_identify_frame *)frame_rcvd;
  2391. unsigned long flags;
  2392. hisi_sas_phy_write32(hisi_hba, phy_no, PHYCTRL_PHY_ENA_MSK, 1);
  2393. if (is_sata_phy_v2_hw(hisi_hba, phy_no))
  2394. goto end;
  2395. if (phy_no == 8) {
  2396. u32 port_state = hisi_sas_read32(hisi_hba, PORT_STATE);
  2397. port_id = (port_state & PORT_STATE_PHY8_PORT_NUM_MSK) >>
  2398. PORT_STATE_PHY8_PORT_NUM_OFF;
  2399. link_rate = (port_state & PORT_STATE_PHY8_CONN_RATE_MSK) >>
  2400. PORT_STATE_PHY8_CONN_RATE_OFF;
  2401. } else {
  2402. port_id = hisi_sas_read32(hisi_hba, PHY_PORT_NUM_MA);
  2403. port_id = (port_id >> (4 * phy_no)) & 0xf;
  2404. link_rate = hisi_sas_read32(hisi_hba, PHY_CONN_RATE);
  2405. link_rate = (link_rate >> (phy_no * 4)) & 0xf;
  2406. }
  2407. if (port_id == 0xf) {
  2408. dev_err(dev, "phyup: phy%d invalid portid\n", phy_no);
  2409. res = IRQ_NONE;
  2410. goto end;
  2411. }
  2412. for (i = 0; i < 6; i++) {
  2413. u32 idaf = hisi_sas_phy_read32(hisi_hba, phy_no,
  2414. RX_IDAF_DWORD0 + (i * 4));
  2415. frame_rcvd[i] = __swab32(idaf);
  2416. }
  2417. sas_phy->linkrate = link_rate;
  2418. sas_phy->oob_mode = SAS_OOB_MODE;
  2419. memcpy(sas_phy->attached_sas_addr, &id->sas_addr, SAS_ADDR_SIZE);
  2420. dev_info(dev, "phyup: phy%d link_rate=%d\n", phy_no, link_rate);
  2421. phy->port_id = port_id;
  2422. phy->phy_type &= ~(PORT_TYPE_SAS | PORT_TYPE_SATA);
  2423. phy->phy_type |= PORT_TYPE_SAS;
  2424. phy->phy_attached = 1;
  2425. phy->identify.device_type = id->dev_type;
  2426. phy->frame_rcvd_size = sizeof(struct sas_identify_frame);
  2427. if (phy->identify.device_type == SAS_END_DEVICE)
  2428. phy->identify.target_port_protocols =
  2429. SAS_PROTOCOL_SSP;
  2430. else if (phy->identify.device_type != SAS_PHY_UNUSED) {
  2431. phy->identify.target_port_protocols =
  2432. SAS_PROTOCOL_SMP;
  2433. if (!timer_pending(&hisi_hba->timer))
  2434. set_link_timer_quirk(hisi_hba);
  2435. }
  2436. hisi_sas_notify_phy_event(phy, HISI_PHYE_PHY_UP);
  2437. spin_lock_irqsave(&phy->lock, flags);
  2438. if (phy->reset_completion) {
  2439. phy->in_reset = 0;
  2440. complete(phy->reset_completion);
  2441. }
  2442. spin_unlock_irqrestore(&phy->lock, flags);
  2443. end:
  2444. hisi_sas_phy_write32(hisi_hba, phy_no, CHL_INT0,
  2445. CHL_INT0_SL_PHY_ENABLE_MSK);
  2446. hisi_sas_phy_write32(hisi_hba, phy_no, PHYCTRL_PHY_ENA_MSK, 0);
  2447. return res;
  2448. }
  2449. static bool check_any_wideports_v2_hw(struct hisi_hba *hisi_hba)
  2450. {
  2451. u32 port_state;
  2452. port_state = hisi_sas_read32(hisi_hba, PORT_STATE);
  2453. if (port_state & 0x1ff)
  2454. return true;
  2455. return false;
  2456. }
  2457. static int phy_down_v2_hw(int phy_no, struct hisi_hba *hisi_hba)
  2458. {
  2459. u32 phy_state, sl_ctrl, txid_auto;
  2460. struct hisi_sas_phy *phy = &hisi_hba->phy[phy_no];
  2461. struct hisi_sas_port *port = phy->port;
  2462. struct device *dev = hisi_hba->dev;
  2463. hisi_sas_phy_write32(hisi_hba, phy_no, PHYCTRL_NOT_RDY_MSK, 1);
  2464. phy_state = hisi_sas_read32(hisi_hba, PHY_STATE);
  2465. dev_info(dev, "phydown: phy%d phy_state=0x%x\n", phy_no, phy_state);
  2466. hisi_sas_phy_down(hisi_hba, phy_no, (phy_state & 1 << phy_no) ? 1 : 0);
  2467. sl_ctrl = hisi_sas_phy_read32(hisi_hba, phy_no, SL_CONTROL);
  2468. hisi_sas_phy_write32(hisi_hba, phy_no, SL_CONTROL,
  2469. sl_ctrl & ~SL_CONTROL_CTA_MSK);
  2470. if (port && !get_wideport_bitmap_v2_hw(hisi_hba, port->id))
  2471. if (!check_any_wideports_v2_hw(hisi_hba) &&
  2472. timer_pending(&hisi_hba->timer))
  2473. del_timer(&hisi_hba->timer);
  2474. txid_auto = hisi_sas_phy_read32(hisi_hba, phy_no, TXID_AUTO);
  2475. hisi_sas_phy_write32(hisi_hba, phy_no, TXID_AUTO,
  2476. txid_auto | TXID_AUTO_CT3_MSK);
  2477. hisi_sas_phy_write32(hisi_hba, phy_no, CHL_INT0, CHL_INT0_NOT_RDY_MSK);
  2478. hisi_sas_phy_write32(hisi_hba, phy_no, PHYCTRL_NOT_RDY_MSK, 0);
  2479. return IRQ_HANDLED;
  2480. }
  2481. static irqreturn_t int_phy_updown_v2_hw(int irq_no, void *p)
  2482. {
  2483. struct hisi_hba *hisi_hba = p;
  2484. u32 irq_msk;
  2485. int phy_no = 0;
  2486. irqreturn_t res = IRQ_NONE;
  2487. irq_msk = (hisi_sas_read32(hisi_hba, HGC_INVLD_DQE_INFO)
  2488. >> HGC_INVLD_DQE_INFO_FB_CH0_OFF) & 0x1ff;
  2489. while (irq_msk) {
  2490. if (irq_msk & 1) {
  2491. u32 reg_value = hisi_sas_phy_read32(hisi_hba, phy_no,
  2492. CHL_INT0);
  2493. switch (reg_value & (CHL_INT0_NOT_RDY_MSK |
  2494. CHL_INT0_SL_PHY_ENABLE_MSK)) {
  2495. case CHL_INT0_SL_PHY_ENABLE_MSK:
  2496. /* phy up */
  2497. if (phy_up_v2_hw(phy_no, hisi_hba) ==
  2498. IRQ_HANDLED)
  2499. res = IRQ_HANDLED;
  2500. break;
  2501. case CHL_INT0_NOT_RDY_MSK:
  2502. /* phy down */
  2503. if (phy_down_v2_hw(phy_no, hisi_hba) ==
  2504. IRQ_HANDLED)
  2505. res = IRQ_HANDLED;
  2506. break;
  2507. case (CHL_INT0_NOT_RDY_MSK |
  2508. CHL_INT0_SL_PHY_ENABLE_MSK):
  2509. reg_value = hisi_sas_read32(hisi_hba,
  2510. PHY_STATE);
  2511. if (reg_value & BIT(phy_no)) {
  2512. /* phy up */
  2513. if (phy_up_v2_hw(phy_no, hisi_hba) ==
  2514. IRQ_HANDLED)
  2515. res = IRQ_HANDLED;
  2516. } else {
  2517. /* phy down */
  2518. if (phy_down_v2_hw(phy_no, hisi_hba) ==
  2519. IRQ_HANDLED)
  2520. res = IRQ_HANDLED;
  2521. }
  2522. break;
  2523. default:
  2524. break;
  2525. }
  2526. }
  2527. irq_msk >>= 1;
  2528. phy_no++;
  2529. }
  2530. return res;
  2531. }
  2532. static void phy_bcast_v2_hw(int phy_no, struct hisi_hba *hisi_hba)
  2533. {
  2534. struct hisi_sas_phy *phy = &hisi_hba->phy[phy_no];
  2535. struct asd_sas_phy *sas_phy = &phy->sas_phy;
  2536. struct sas_ha_struct *sas_ha = &hisi_hba->sha;
  2537. u32 bcast_status;
  2538. hisi_sas_phy_write32(hisi_hba, phy_no, SL_RX_BCAST_CHK_MSK, 1);
  2539. bcast_status = hisi_sas_phy_read32(hisi_hba, phy_no, RX_PRIMS_STATUS);
  2540. if ((bcast_status & RX_BCAST_CHG_MSK) &&
  2541. !test_bit(HISI_SAS_RESET_BIT, &hisi_hba->flags))
  2542. sas_ha->notify_port_event(sas_phy, PORTE_BROADCAST_RCVD);
  2543. hisi_sas_phy_write32(hisi_hba, phy_no, CHL_INT0,
  2544. CHL_INT0_SL_RX_BCST_ACK_MSK);
  2545. hisi_sas_phy_write32(hisi_hba, phy_no, SL_RX_BCAST_CHK_MSK, 0);
  2546. }
  2547. static const struct hisi_sas_hw_error port_ecc_axi_error[] = {
  2548. {
  2549. .irq_msk = BIT(CHL_INT1_DMAC_TX_ECC_ERR_OFF),
  2550. .msg = "dmac_tx_ecc_bad_err",
  2551. },
  2552. {
  2553. .irq_msk = BIT(CHL_INT1_DMAC_RX_ECC_ERR_OFF),
  2554. .msg = "dmac_rx_ecc_bad_err",
  2555. },
  2556. {
  2557. .irq_msk = BIT(CHL_INT1_DMAC_TX_AXI_WR_ERR_OFF),
  2558. .msg = "dma_tx_axi_wr_err",
  2559. },
  2560. {
  2561. .irq_msk = BIT(CHL_INT1_DMAC_TX_AXI_RD_ERR_OFF),
  2562. .msg = "dma_tx_axi_rd_err",
  2563. },
  2564. {
  2565. .irq_msk = BIT(CHL_INT1_DMAC_RX_AXI_WR_ERR_OFF),
  2566. .msg = "dma_rx_axi_wr_err",
  2567. },
  2568. {
  2569. .irq_msk = BIT(CHL_INT1_DMAC_RX_AXI_RD_ERR_OFF),
  2570. .msg = "dma_rx_axi_rd_err",
  2571. },
  2572. };
  2573. static irqreturn_t int_chnl_int_v2_hw(int irq_no, void *p)
  2574. {
  2575. struct hisi_hba *hisi_hba = p;
  2576. struct device *dev = hisi_hba->dev;
  2577. u32 ent_msk, ent_tmp, irq_msk;
  2578. int phy_no = 0;
  2579. ent_msk = hisi_sas_read32(hisi_hba, ENT_INT_SRC_MSK3);
  2580. ent_tmp = ent_msk;
  2581. ent_msk |= ENT_INT_SRC_MSK3_ENT95_MSK_MSK;
  2582. hisi_sas_write32(hisi_hba, ENT_INT_SRC_MSK3, ent_msk);
  2583. irq_msk = (hisi_sas_read32(hisi_hba, HGC_INVLD_DQE_INFO) >>
  2584. HGC_INVLD_DQE_INFO_FB_CH3_OFF) & 0x1ff;
  2585. while (irq_msk) {
  2586. u32 irq_value0 = hisi_sas_phy_read32(hisi_hba, phy_no,
  2587. CHL_INT0);
  2588. u32 irq_value1 = hisi_sas_phy_read32(hisi_hba, phy_no,
  2589. CHL_INT1);
  2590. u32 irq_value2 = hisi_sas_phy_read32(hisi_hba, phy_no,
  2591. CHL_INT2);
  2592. if ((irq_msk & (1 << phy_no)) && irq_value1) {
  2593. int i;
  2594. for (i = 0; i < ARRAY_SIZE(port_ecc_axi_error); i++) {
  2595. const struct hisi_sas_hw_error *error =
  2596. &port_ecc_axi_error[i];
  2597. if (!(irq_value1 & error->irq_msk))
  2598. continue;
  2599. dev_warn(dev, "%s error (phy%d 0x%x) found!\n",
  2600. error->msg, phy_no, irq_value1);
  2601. queue_work(hisi_hba->wq, &hisi_hba->rst_work);
  2602. }
  2603. hisi_sas_phy_write32(hisi_hba, phy_no,
  2604. CHL_INT1, irq_value1);
  2605. }
  2606. if ((irq_msk & (1 << phy_no)) && irq_value2) {
  2607. struct hisi_sas_phy *phy = &hisi_hba->phy[phy_no];
  2608. if (irq_value2 & BIT(CHL_INT2_SL_IDAF_TOUT_CONF_OFF)) {
  2609. dev_warn(dev, "phy%d identify timeout\n",
  2610. phy_no);
  2611. hisi_sas_notify_phy_event(phy,
  2612. HISI_PHYE_LINK_RESET);
  2613. }
  2614. hisi_sas_phy_write32(hisi_hba, phy_no,
  2615. CHL_INT2, irq_value2);
  2616. }
  2617. if ((irq_msk & (1 << phy_no)) && irq_value0) {
  2618. if (irq_value0 & CHL_INT0_SL_RX_BCST_ACK_MSK)
  2619. phy_bcast_v2_hw(phy_no, hisi_hba);
  2620. hisi_sas_phy_write32(hisi_hba, phy_no,
  2621. CHL_INT0, irq_value0
  2622. & (~CHL_INT0_HOTPLUG_TOUT_MSK)
  2623. & (~CHL_INT0_SL_PHY_ENABLE_MSK)
  2624. & (~CHL_INT0_NOT_RDY_MSK));
  2625. }
  2626. irq_msk &= ~(1 << phy_no);
  2627. phy_no++;
  2628. }
  2629. hisi_sas_write32(hisi_hba, ENT_INT_SRC_MSK3, ent_tmp);
  2630. return IRQ_HANDLED;
  2631. }
  2632. static void
  2633. one_bit_ecc_error_process_v2_hw(struct hisi_hba *hisi_hba, u32 irq_value)
  2634. {
  2635. struct device *dev = hisi_hba->dev;
  2636. const struct hisi_sas_hw_error *ecc_error;
  2637. u32 val;
  2638. int i;
  2639. for (i = 0; i < ARRAY_SIZE(one_bit_ecc_errors); i++) {
  2640. ecc_error = &one_bit_ecc_errors[i];
  2641. if (irq_value & ecc_error->irq_msk) {
  2642. val = hisi_sas_read32(hisi_hba, ecc_error->reg);
  2643. val &= ecc_error->msk;
  2644. val >>= ecc_error->shift;
  2645. dev_warn(dev, ecc_error->msg, val);
  2646. }
  2647. }
  2648. }
  2649. static void multi_bit_ecc_error_process_v2_hw(struct hisi_hba *hisi_hba,
  2650. u32 irq_value)
  2651. {
  2652. struct device *dev = hisi_hba->dev;
  2653. const struct hisi_sas_hw_error *ecc_error;
  2654. u32 val;
  2655. int i;
  2656. for (i = 0; i < ARRAY_SIZE(multi_bit_ecc_errors); i++) {
  2657. ecc_error = &multi_bit_ecc_errors[i];
  2658. if (irq_value & ecc_error->irq_msk) {
  2659. val = hisi_sas_read32(hisi_hba, ecc_error->reg);
  2660. val &= ecc_error->msk;
  2661. val >>= ecc_error->shift;
  2662. dev_err(dev, ecc_error->msg, irq_value, val);
  2663. queue_work(hisi_hba->wq, &hisi_hba->rst_work);
  2664. }
  2665. }
  2666. return;
  2667. }
  2668. static irqreturn_t fatal_ecc_int_v2_hw(int irq_no, void *p)
  2669. {
  2670. struct hisi_hba *hisi_hba = p;
  2671. u32 irq_value, irq_msk;
  2672. irq_msk = hisi_sas_read32(hisi_hba, SAS_ECC_INTR_MSK);
  2673. hisi_sas_write32(hisi_hba, SAS_ECC_INTR_MSK, irq_msk | 0xffffffff);
  2674. irq_value = hisi_sas_read32(hisi_hba, SAS_ECC_INTR);
  2675. if (irq_value) {
  2676. one_bit_ecc_error_process_v2_hw(hisi_hba, irq_value);
  2677. multi_bit_ecc_error_process_v2_hw(hisi_hba, irq_value);
  2678. }
  2679. hisi_sas_write32(hisi_hba, SAS_ECC_INTR, irq_value);
  2680. hisi_sas_write32(hisi_hba, SAS_ECC_INTR_MSK, irq_msk);
  2681. return IRQ_HANDLED;
  2682. }
  2683. static const struct hisi_sas_hw_error axi_error[] = {
  2684. { .msk = BIT(0), .msg = "IOST_AXI_W_ERR" },
  2685. { .msk = BIT(1), .msg = "IOST_AXI_R_ERR" },
  2686. { .msk = BIT(2), .msg = "ITCT_AXI_W_ERR" },
  2687. { .msk = BIT(3), .msg = "ITCT_AXI_R_ERR" },
  2688. { .msk = BIT(4), .msg = "SATA_AXI_W_ERR" },
  2689. { .msk = BIT(5), .msg = "SATA_AXI_R_ERR" },
  2690. { .msk = BIT(6), .msg = "DQE_AXI_R_ERR" },
  2691. { .msk = BIT(7), .msg = "CQE_AXI_W_ERR" },
  2692. {},
  2693. };
  2694. static const struct hisi_sas_hw_error fifo_error[] = {
  2695. { .msk = BIT(8), .msg = "CQE_WINFO_FIFO" },
  2696. { .msk = BIT(9), .msg = "CQE_MSG_FIFIO" },
  2697. { .msk = BIT(10), .msg = "GETDQE_FIFO" },
  2698. { .msk = BIT(11), .msg = "CMDP_FIFO" },
  2699. { .msk = BIT(12), .msg = "AWTCTRL_FIFO" },
  2700. {},
  2701. };
  2702. static const struct hisi_sas_hw_error fatal_axi_errors[] = {
  2703. {
  2704. .irq_msk = BIT(ENT_INT_SRC3_WP_DEPTH_OFF),
  2705. .msg = "write pointer and depth",
  2706. },
  2707. {
  2708. .irq_msk = BIT(ENT_INT_SRC3_IPTT_SLOT_NOMATCH_OFF),
  2709. .msg = "iptt no match slot",
  2710. },
  2711. {
  2712. .irq_msk = BIT(ENT_INT_SRC3_RP_DEPTH_OFF),
  2713. .msg = "read pointer and depth",
  2714. },
  2715. {
  2716. .irq_msk = BIT(ENT_INT_SRC3_AXI_OFF),
  2717. .reg = HGC_AXI_FIFO_ERR_INFO,
  2718. .sub = axi_error,
  2719. },
  2720. {
  2721. .irq_msk = BIT(ENT_INT_SRC3_FIFO_OFF),
  2722. .reg = HGC_AXI_FIFO_ERR_INFO,
  2723. .sub = fifo_error,
  2724. },
  2725. {
  2726. .irq_msk = BIT(ENT_INT_SRC3_LM_OFF),
  2727. .msg = "LM add/fetch list",
  2728. },
  2729. {
  2730. .irq_msk = BIT(ENT_INT_SRC3_ABT_OFF),
  2731. .msg = "SAS_HGC_ABT fetch LM list",
  2732. },
  2733. };
  2734. static irqreturn_t fatal_axi_int_v2_hw(int irq_no, void *p)
  2735. {
  2736. struct hisi_hba *hisi_hba = p;
  2737. u32 irq_value, irq_msk, err_value;
  2738. struct device *dev = hisi_hba->dev;
  2739. const struct hisi_sas_hw_error *axi_error;
  2740. int i;
  2741. irq_msk = hisi_sas_read32(hisi_hba, ENT_INT_SRC_MSK3);
  2742. hisi_sas_write32(hisi_hba, ENT_INT_SRC_MSK3, irq_msk | 0xfffffffe);
  2743. irq_value = hisi_sas_read32(hisi_hba, ENT_INT_SRC3);
  2744. for (i = 0; i < ARRAY_SIZE(fatal_axi_errors); i++) {
  2745. axi_error = &fatal_axi_errors[i];
  2746. if (!(irq_value & axi_error->irq_msk))
  2747. continue;
  2748. hisi_sas_write32(hisi_hba, ENT_INT_SRC3,
  2749. 1 << axi_error->shift);
  2750. if (axi_error->sub) {
  2751. const struct hisi_sas_hw_error *sub = axi_error->sub;
  2752. err_value = hisi_sas_read32(hisi_hba, axi_error->reg);
  2753. for (; sub->msk || sub->msg; sub++) {
  2754. if (!(err_value & sub->msk))
  2755. continue;
  2756. dev_err(dev, "%s (0x%x) found!\n",
  2757. sub->msg, irq_value);
  2758. queue_work(hisi_hba->wq, &hisi_hba->rst_work);
  2759. }
  2760. } else {
  2761. dev_err(dev, "%s (0x%x) found!\n",
  2762. axi_error->msg, irq_value);
  2763. queue_work(hisi_hba->wq, &hisi_hba->rst_work);
  2764. }
  2765. }
  2766. if (irq_value & BIT(ENT_INT_SRC3_ITC_INT_OFF)) {
  2767. u32 reg_val = hisi_sas_read32(hisi_hba, ITCT_CLR);
  2768. u32 dev_id = reg_val & ITCT_DEV_MSK;
  2769. struct hisi_sas_device *sas_dev = &hisi_hba->devices[dev_id];
  2770. hisi_sas_write32(hisi_hba, ITCT_CLR, 0);
  2771. dev_dbg(dev, "clear ITCT ok\n");
  2772. complete(sas_dev->completion);
  2773. }
  2774. hisi_sas_write32(hisi_hba, ENT_INT_SRC3, irq_value);
  2775. hisi_sas_write32(hisi_hba, ENT_INT_SRC_MSK3, irq_msk);
  2776. return IRQ_HANDLED;
  2777. }
  2778. static void cq_tasklet_v2_hw(unsigned long val)
  2779. {
  2780. struct hisi_sas_cq *cq = (struct hisi_sas_cq *)val;
  2781. struct hisi_hba *hisi_hba = cq->hisi_hba;
  2782. struct hisi_sas_slot *slot;
  2783. struct hisi_sas_itct *itct;
  2784. struct hisi_sas_complete_v2_hdr *complete_queue;
  2785. u32 rd_point = cq->rd_point, wr_point, dev_id;
  2786. int queue = cq->id;
  2787. if (unlikely(hisi_hba->reject_stp_links_msk))
  2788. phys_try_accept_stp_links_v2_hw(hisi_hba);
  2789. complete_queue = hisi_hba->complete_hdr[queue];
  2790. wr_point = hisi_sas_read32(hisi_hba, COMPL_Q_0_WR_PTR +
  2791. (0x14 * queue));
  2792. while (rd_point != wr_point) {
  2793. struct hisi_sas_complete_v2_hdr *complete_hdr;
  2794. int iptt;
  2795. complete_hdr = &complete_queue[rd_point];
  2796. /* Check for NCQ completion */
  2797. if (complete_hdr->act) {
  2798. u32 act_tmp = le32_to_cpu(complete_hdr->act);
  2799. int ncq_tag_count = ffs(act_tmp);
  2800. u32 dw1 = le32_to_cpu(complete_hdr->dw1);
  2801. dev_id = (dw1 & CMPLT_HDR_DEV_ID_MSK) >>
  2802. CMPLT_HDR_DEV_ID_OFF;
  2803. itct = &hisi_hba->itct[dev_id];
  2804. /* The NCQ tags are held in the itct header */
  2805. while (ncq_tag_count) {
  2806. __le64 *_ncq_tag = &itct->qw4_15[0], __ncq_tag;
  2807. u64 ncq_tag;
  2808. ncq_tag_count--;
  2809. __ncq_tag = _ncq_tag[ncq_tag_count / 5];
  2810. ncq_tag = le64_to_cpu(__ncq_tag);
  2811. iptt = (ncq_tag >> (ncq_tag_count % 5) * 12) &
  2812. 0xfff;
  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. act_tmp &= ~(1 << ncq_tag_count);
  2818. ncq_tag_count = ffs(act_tmp);
  2819. }
  2820. } else {
  2821. u32 dw1 = le32_to_cpu(complete_hdr->dw1);
  2822. iptt = dw1 & CMPLT_HDR_IPTT_MSK;
  2823. slot = &hisi_hba->slot_info[iptt];
  2824. slot->cmplt_queue_slot = rd_point;
  2825. slot->cmplt_queue = queue;
  2826. slot_complete_v2_hw(hisi_hba, slot);
  2827. }
  2828. if (++rd_point >= HISI_SAS_QUEUE_SLOTS)
  2829. rd_point = 0;
  2830. }
  2831. /* update rd_point */
  2832. cq->rd_point = rd_point;
  2833. hisi_sas_write32(hisi_hba, COMPL_Q_0_RD_PTR + (0x14 * queue), rd_point);
  2834. }
  2835. static irqreturn_t cq_interrupt_v2_hw(int irq_no, void *p)
  2836. {
  2837. struct hisi_sas_cq *cq = p;
  2838. struct hisi_hba *hisi_hba = cq->hisi_hba;
  2839. int queue = cq->id;
  2840. hisi_sas_write32(hisi_hba, OQ_INT_SRC, 1 << queue);
  2841. tasklet_schedule(&cq->tasklet);
  2842. return IRQ_HANDLED;
  2843. }
  2844. static irqreturn_t sata_int_v2_hw(int irq_no, void *p)
  2845. {
  2846. struct hisi_sas_phy *phy = p;
  2847. struct hisi_hba *hisi_hba = phy->hisi_hba;
  2848. struct asd_sas_phy *sas_phy = &phy->sas_phy;
  2849. struct device *dev = hisi_hba->dev;
  2850. struct hisi_sas_initial_fis *initial_fis;
  2851. struct dev_to_host_fis *fis;
  2852. u32 ent_tmp, ent_msk, ent_int, port_id, link_rate, hard_phy_linkrate;
  2853. irqreturn_t res = IRQ_HANDLED;
  2854. u8 attached_sas_addr[SAS_ADDR_SIZE] = {0};
  2855. unsigned long flags;
  2856. int phy_no, offset;
  2857. phy_no = sas_phy->id;
  2858. initial_fis = &hisi_hba->initial_fis[phy_no];
  2859. fis = &initial_fis->fis;
  2860. offset = 4 * (phy_no / 4);
  2861. ent_msk = hisi_sas_read32(hisi_hba, ENT_INT_SRC_MSK1 + offset);
  2862. hisi_sas_write32(hisi_hba, ENT_INT_SRC_MSK1 + offset,
  2863. ent_msk | 1 << ((phy_no % 4) * 8));
  2864. ent_int = hisi_sas_read32(hisi_hba, ENT_INT_SRC1 + offset);
  2865. ent_tmp = ent_int & (1 << (ENT_INT_SRC1_D2H_FIS_CH1_OFF *
  2866. (phy_no % 4)));
  2867. ent_int >>= ENT_INT_SRC1_D2H_FIS_CH1_OFF * (phy_no % 4);
  2868. if ((ent_int & ENT_INT_SRC1_D2H_FIS_CH0_MSK) == 0) {
  2869. dev_warn(dev, "sata int: phy%d did not receive FIS\n", phy_no);
  2870. res = IRQ_NONE;
  2871. goto end;
  2872. }
  2873. /* check ERR bit of Status Register */
  2874. if (fis->status & ATA_ERR) {
  2875. dev_warn(dev, "sata int: phy%d FIS status: 0x%x\n", phy_no,
  2876. fis->status);
  2877. hisi_sas_notify_phy_event(phy, HISI_PHYE_LINK_RESET);
  2878. res = IRQ_NONE;
  2879. goto end;
  2880. }
  2881. if (unlikely(phy_no == 8)) {
  2882. u32 port_state = hisi_sas_read32(hisi_hba, PORT_STATE);
  2883. port_id = (port_state & PORT_STATE_PHY8_PORT_NUM_MSK) >>
  2884. PORT_STATE_PHY8_PORT_NUM_OFF;
  2885. link_rate = (port_state & PORT_STATE_PHY8_CONN_RATE_MSK) >>
  2886. PORT_STATE_PHY8_CONN_RATE_OFF;
  2887. } else {
  2888. port_id = hisi_sas_read32(hisi_hba, PHY_PORT_NUM_MA);
  2889. port_id = (port_id >> (4 * phy_no)) & 0xf;
  2890. link_rate = hisi_sas_read32(hisi_hba, PHY_CONN_RATE);
  2891. link_rate = (link_rate >> (phy_no * 4)) & 0xf;
  2892. }
  2893. if (port_id == 0xf) {
  2894. dev_err(dev, "sata int: phy%d invalid portid\n", phy_no);
  2895. res = IRQ_NONE;
  2896. goto end;
  2897. }
  2898. sas_phy->linkrate = link_rate;
  2899. hard_phy_linkrate = hisi_sas_phy_read32(hisi_hba, phy_no,
  2900. HARD_PHY_LINKRATE);
  2901. phy->maximum_linkrate = hard_phy_linkrate & 0xf;
  2902. phy->minimum_linkrate = (hard_phy_linkrate >> 4) & 0xf;
  2903. sas_phy->oob_mode = SATA_OOB_MODE;
  2904. /* Make up some unique SAS address */
  2905. attached_sas_addr[0] = 0x50;
  2906. attached_sas_addr[6] = hisi_hba->shost->host_no;
  2907. attached_sas_addr[7] = phy_no;
  2908. memcpy(sas_phy->attached_sas_addr, attached_sas_addr, SAS_ADDR_SIZE);
  2909. memcpy(sas_phy->frame_rcvd, fis, sizeof(struct dev_to_host_fis));
  2910. dev_info(dev, "sata int phyup: phy%d link_rate=%d\n", phy_no, link_rate);
  2911. phy->phy_type &= ~(PORT_TYPE_SAS | PORT_TYPE_SATA);
  2912. phy->port_id = port_id;
  2913. phy->phy_type |= PORT_TYPE_SATA;
  2914. phy->phy_attached = 1;
  2915. phy->identify.device_type = SAS_SATA_DEV;
  2916. phy->frame_rcvd_size = sizeof(struct dev_to_host_fis);
  2917. phy->identify.target_port_protocols = SAS_PROTOCOL_SATA;
  2918. hisi_sas_notify_phy_event(phy, HISI_PHYE_PHY_UP);
  2919. spin_lock_irqsave(&phy->lock, flags);
  2920. if (phy->reset_completion) {
  2921. phy->in_reset = 0;
  2922. complete(phy->reset_completion);
  2923. }
  2924. spin_unlock_irqrestore(&phy->lock, flags);
  2925. end:
  2926. hisi_sas_write32(hisi_hba, ENT_INT_SRC1 + offset, ent_tmp);
  2927. hisi_sas_write32(hisi_hba, ENT_INT_SRC_MSK1 + offset, ent_msk);
  2928. return res;
  2929. }
  2930. static irq_handler_t phy_interrupts[HISI_SAS_PHY_INT_NR] = {
  2931. int_phy_updown_v2_hw,
  2932. int_chnl_int_v2_hw,
  2933. };
  2934. static irq_handler_t fatal_interrupts[HISI_SAS_FATAL_INT_NR] = {
  2935. fatal_ecc_int_v2_hw,
  2936. fatal_axi_int_v2_hw
  2937. };
  2938. /**
  2939. * There is a limitation in the hip06 chipset that we need
  2940. * to map in all mbigen interrupts, even if they are not used.
  2941. */
  2942. static int interrupt_init_v2_hw(struct hisi_hba *hisi_hba)
  2943. {
  2944. struct platform_device *pdev = hisi_hba->platform_dev;
  2945. struct device *dev = &pdev->dev;
  2946. int irq, rc, irq_map[128];
  2947. int i, phy_no, fatal_no, queue_no, k;
  2948. for (i = 0; i < 128; i++)
  2949. irq_map[i] = platform_get_irq(pdev, i);
  2950. for (i = 0; i < HISI_SAS_PHY_INT_NR; i++) {
  2951. irq = irq_map[i + 1]; /* Phy up/down is irq1 */
  2952. rc = devm_request_irq(dev, irq, phy_interrupts[i], 0,
  2953. DRV_NAME " phy", hisi_hba);
  2954. if (rc) {
  2955. dev_err(dev, "irq init: could not request "
  2956. "phy interrupt %d, rc=%d\n",
  2957. irq, rc);
  2958. rc = -ENOENT;
  2959. goto free_phy_int_irqs;
  2960. }
  2961. }
  2962. for (phy_no = 0; phy_no < hisi_hba->n_phy; phy_no++) {
  2963. struct hisi_sas_phy *phy = &hisi_hba->phy[phy_no];
  2964. irq = irq_map[phy_no + 72];
  2965. rc = devm_request_irq(dev, irq, sata_int_v2_hw, 0,
  2966. DRV_NAME " sata", phy);
  2967. if (rc) {
  2968. dev_err(dev, "irq init: could not request "
  2969. "sata interrupt %d, rc=%d\n",
  2970. irq, rc);
  2971. rc = -ENOENT;
  2972. goto free_sata_int_irqs;
  2973. }
  2974. }
  2975. for (fatal_no = 0; fatal_no < HISI_SAS_FATAL_INT_NR; fatal_no++) {
  2976. irq = irq_map[fatal_no + 81];
  2977. rc = devm_request_irq(dev, irq, fatal_interrupts[fatal_no], 0,
  2978. DRV_NAME " fatal", hisi_hba);
  2979. if (rc) {
  2980. dev_err(dev,
  2981. "irq init: could not request fatal interrupt %d, rc=%d\n",
  2982. irq, rc);
  2983. rc = -ENOENT;
  2984. goto free_fatal_int_irqs;
  2985. }
  2986. }
  2987. for (queue_no = 0; queue_no < hisi_hba->queue_count; queue_no++) {
  2988. struct hisi_sas_cq *cq = &hisi_hba->cq[queue_no];
  2989. struct tasklet_struct *t = &cq->tasklet;
  2990. irq = irq_map[queue_no + 96];
  2991. rc = devm_request_irq(dev, irq, cq_interrupt_v2_hw, 0,
  2992. DRV_NAME " cq", cq);
  2993. if (rc) {
  2994. dev_err(dev,
  2995. "irq init: could not request cq interrupt %d, rc=%d\n",
  2996. irq, rc);
  2997. rc = -ENOENT;
  2998. goto free_cq_int_irqs;
  2999. }
  3000. tasklet_init(t, cq_tasklet_v2_hw, (unsigned long)cq);
  3001. }
  3002. return 0;
  3003. free_cq_int_irqs:
  3004. for (k = 0; k < queue_no; k++) {
  3005. struct hisi_sas_cq *cq = &hisi_hba->cq[k];
  3006. free_irq(irq_map[k + 96], cq);
  3007. tasklet_kill(&cq->tasklet);
  3008. }
  3009. free_fatal_int_irqs:
  3010. for (k = 0; k < fatal_no; k++)
  3011. free_irq(irq_map[k + 81], hisi_hba);
  3012. free_sata_int_irqs:
  3013. for (k = 0; k < phy_no; k++) {
  3014. struct hisi_sas_phy *phy = &hisi_hba->phy[k];
  3015. free_irq(irq_map[k + 72], phy);
  3016. }
  3017. free_phy_int_irqs:
  3018. for (k = 0; k < i; k++)
  3019. free_irq(irq_map[k + 1], hisi_hba);
  3020. return rc;
  3021. }
  3022. static int hisi_sas_v2_init(struct hisi_hba *hisi_hba)
  3023. {
  3024. int rc;
  3025. memset(hisi_hba->sata_dev_bitmap, 0, sizeof(hisi_hba->sata_dev_bitmap));
  3026. rc = hw_init_v2_hw(hisi_hba);
  3027. if (rc)
  3028. return rc;
  3029. rc = interrupt_init_v2_hw(hisi_hba);
  3030. if (rc)
  3031. return rc;
  3032. return 0;
  3033. }
  3034. static void interrupt_disable_v2_hw(struct hisi_hba *hisi_hba)
  3035. {
  3036. struct platform_device *pdev = hisi_hba->platform_dev;
  3037. int i;
  3038. for (i = 0; i < hisi_hba->queue_count; i++)
  3039. hisi_sas_write32(hisi_hba, OQ0_INT_SRC_MSK + 0x4 * i, 0x1);
  3040. hisi_sas_write32(hisi_hba, ENT_INT_SRC_MSK1, 0xffffffff);
  3041. hisi_sas_write32(hisi_hba, ENT_INT_SRC_MSK2, 0xffffffff);
  3042. hisi_sas_write32(hisi_hba, ENT_INT_SRC_MSK3, 0xffffffff);
  3043. hisi_sas_write32(hisi_hba, SAS_ECC_INTR_MSK, 0xffffffff);
  3044. for (i = 0; i < hisi_hba->n_phy; i++) {
  3045. hisi_sas_phy_write32(hisi_hba, i, CHL_INT1_MSK, 0xffffffff);
  3046. hisi_sas_phy_write32(hisi_hba, i, CHL_INT2_MSK, 0xffffffff);
  3047. }
  3048. for (i = 0; i < 128; i++)
  3049. synchronize_irq(platform_get_irq(pdev, i));
  3050. }
  3051. static u32 get_phys_state_v2_hw(struct hisi_hba *hisi_hba)
  3052. {
  3053. return hisi_sas_read32(hisi_hba, PHY_STATE);
  3054. }
  3055. static int soft_reset_v2_hw(struct hisi_hba *hisi_hba)
  3056. {
  3057. struct device *dev = hisi_hba->dev;
  3058. int rc, cnt;
  3059. interrupt_disable_v2_hw(hisi_hba);
  3060. hisi_sas_write32(hisi_hba, DLVRY_QUEUE_ENABLE, 0x0);
  3061. hisi_sas_kill_tasklets(hisi_hba);
  3062. hisi_sas_stop_phys(hisi_hba);
  3063. mdelay(10);
  3064. hisi_sas_write32(hisi_hba, AXI_MASTER_CFG_BASE + AM_CTRL_GLOBAL, 0x1);
  3065. /* wait until bus idle */
  3066. cnt = 0;
  3067. while (1) {
  3068. u32 status = hisi_sas_read32_relaxed(hisi_hba,
  3069. AXI_MASTER_CFG_BASE + AM_CURR_TRANS_RETURN);
  3070. if (status == 0x3)
  3071. break;
  3072. udelay(10);
  3073. if (cnt++ > 10) {
  3074. dev_err(dev, "wait axi bus state to idle timeout!\n");
  3075. return -1;
  3076. }
  3077. }
  3078. hisi_sas_init_mem(hisi_hba);
  3079. rc = hw_init_v2_hw(hisi_hba);
  3080. if (rc)
  3081. return rc;
  3082. phys_reject_stp_links_v2_hw(hisi_hba);
  3083. return 0;
  3084. }
  3085. static int write_gpio_v2_hw(struct hisi_hba *hisi_hba, u8 reg_type,
  3086. u8 reg_index, u8 reg_count, u8 *write_data)
  3087. {
  3088. struct device *dev = hisi_hba->dev;
  3089. int phy_no, count;
  3090. if (!hisi_hba->sgpio_regs)
  3091. return -EOPNOTSUPP;
  3092. switch (reg_type) {
  3093. case SAS_GPIO_REG_TX:
  3094. count = reg_count * 4;
  3095. count = min(count, hisi_hba->n_phy);
  3096. for (phy_no = 0; phy_no < count; phy_no++) {
  3097. /*
  3098. * GPIO_TX[n] register has the highest numbered drive
  3099. * of the four in the first byte and the lowest
  3100. * numbered drive in the fourth byte.
  3101. * See SFF-8485 Rev. 0.7 Table 24.
  3102. */
  3103. void __iomem *reg_addr = hisi_hba->sgpio_regs +
  3104. reg_index * 4 + phy_no;
  3105. int data_idx = phy_no + 3 - (phy_no % 4) * 2;
  3106. writeb(write_data[data_idx], reg_addr);
  3107. }
  3108. break;
  3109. default:
  3110. dev_err(dev, "write gpio: unsupported or bad reg type %d\n",
  3111. reg_type);
  3112. return -EINVAL;
  3113. }
  3114. return 0;
  3115. }
  3116. static void wait_cmds_complete_timeout_v2_hw(struct hisi_hba *hisi_hba,
  3117. int delay_ms, int timeout_ms)
  3118. {
  3119. struct device *dev = hisi_hba->dev;
  3120. int entries, entries_old = 0, time;
  3121. for (time = 0; time < timeout_ms; time += delay_ms) {
  3122. entries = hisi_sas_read32(hisi_hba, CQE_SEND_CNT);
  3123. if (entries == entries_old)
  3124. break;
  3125. entries_old = entries;
  3126. msleep(delay_ms);
  3127. }
  3128. dev_dbg(dev, "wait commands complete %dms\n", time);
  3129. }
  3130. static struct device_attribute *host_attrs_v2_hw[] = {
  3131. &dev_attr_phy_event_threshold,
  3132. NULL
  3133. };
  3134. static struct scsi_host_template sht_v2_hw = {
  3135. .name = DRV_NAME,
  3136. .module = THIS_MODULE,
  3137. .queuecommand = sas_queuecommand,
  3138. .target_alloc = sas_target_alloc,
  3139. .slave_configure = hisi_sas_slave_configure,
  3140. .scan_finished = hisi_sas_scan_finished,
  3141. .scan_start = hisi_sas_scan_start,
  3142. .change_queue_depth = sas_change_queue_depth,
  3143. .bios_param = sas_bios_param,
  3144. .this_id = -1,
  3145. .sg_tablesize = HISI_SAS_SGE_PAGE_CNT,
  3146. .max_sectors = SCSI_DEFAULT_MAX_SECTORS,
  3147. .use_clustering = ENABLE_CLUSTERING,
  3148. .eh_device_reset_handler = sas_eh_device_reset_handler,
  3149. .eh_target_reset_handler = sas_eh_target_reset_handler,
  3150. .target_destroy = sas_target_destroy,
  3151. .ioctl = sas_ioctl,
  3152. .shost_attrs = host_attrs_v2_hw,
  3153. };
  3154. static const struct hisi_sas_hw hisi_sas_v2_hw = {
  3155. .hw_init = hisi_sas_v2_init,
  3156. .setup_itct = setup_itct_v2_hw,
  3157. .slot_index_alloc = slot_index_alloc_quirk_v2_hw,
  3158. .alloc_dev = alloc_dev_quirk_v2_hw,
  3159. .sl_notify_ssp = sl_notify_ssp_v2_hw,
  3160. .get_wideport_bitmap = get_wideport_bitmap_v2_hw,
  3161. .clear_itct = clear_itct_v2_hw,
  3162. .free_device = free_device_v2_hw,
  3163. .prep_smp = prep_smp_v2_hw,
  3164. .prep_ssp = prep_ssp_v2_hw,
  3165. .prep_stp = prep_ata_v2_hw,
  3166. .prep_abort = prep_abort_v2_hw,
  3167. .get_free_slot = get_free_slot_v2_hw,
  3168. .start_delivery = start_delivery_v2_hw,
  3169. .slot_complete = slot_complete_v2_hw,
  3170. .phys_init = phys_init_v2_hw,
  3171. .phy_start = start_phy_v2_hw,
  3172. .phy_disable = disable_phy_v2_hw,
  3173. .phy_hard_reset = phy_hard_reset_v2_hw,
  3174. .get_events = phy_get_events_v2_hw,
  3175. .phy_set_linkrate = phy_set_linkrate_v2_hw,
  3176. .phy_get_max_linkrate = phy_get_max_linkrate_v2_hw,
  3177. .max_command_entries = HISI_SAS_COMMAND_ENTRIES_V2_HW,
  3178. .complete_hdr_size = sizeof(struct hisi_sas_complete_v2_hdr),
  3179. .soft_reset = soft_reset_v2_hw,
  3180. .get_phys_state = get_phys_state_v2_hw,
  3181. .write_gpio = write_gpio_v2_hw,
  3182. .wait_cmds_complete_timeout = wait_cmds_complete_timeout_v2_hw,
  3183. .sht = &sht_v2_hw,
  3184. };
  3185. static int hisi_sas_v2_probe(struct platform_device *pdev)
  3186. {
  3187. /*
  3188. * Check if we should defer the probe before we probe the
  3189. * upper layer, as it's hard to defer later on.
  3190. */
  3191. int ret = platform_get_irq(pdev, 0);
  3192. if (ret < 0) {
  3193. if (ret != -EPROBE_DEFER)
  3194. dev_err(&pdev->dev, "cannot obtain irq\n");
  3195. return ret;
  3196. }
  3197. return hisi_sas_probe(pdev, &hisi_sas_v2_hw);
  3198. }
  3199. static int hisi_sas_v2_remove(struct platform_device *pdev)
  3200. {
  3201. struct sas_ha_struct *sha = platform_get_drvdata(pdev);
  3202. struct hisi_hba *hisi_hba = sha->lldd_ha;
  3203. hisi_sas_kill_tasklets(hisi_hba);
  3204. return hisi_sas_remove(pdev);
  3205. }
  3206. static const struct of_device_id sas_v2_of_match[] = {
  3207. { .compatible = "hisilicon,hip06-sas-v2",},
  3208. { .compatible = "hisilicon,hip07-sas-v2",},
  3209. {},
  3210. };
  3211. MODULE_DEVICE_TABLE(of, sas_v2_of_match);
  3212. static const struct acpi_device_id sas_v2_acpi_match[] = {
  3213. { "HISI0162", 0 },
  3214. { }
  3215. };
  3216. MODULE_DEVICE_TABLE(acpi, sas_v2_acpi_match);
  3217. static struct platform_driver hisi_sas_v2_driver = {
  3218. .probe = hisi_sas_v2_probe,
  3219. .remove = hisi_sas_v2_remove,
  3220. .driver = {
  3221. .name = DRV_NAME,
  3222. .of_match_table = sas_v2_of_match,
  3223. .acpi_match_table = ACPI_PTR(sas_v2_acpi_match),
  3224. },
  3225. };
  3226. module_platform_driver(hisi_sas_v2_driver);
  3227. MODULE_LICENSE("GPL");
  3228. MODULE_AUTHOR("John Garry <john.garry@huawei.com>");
  3229. MODULE_DESCRIPTION("HISILICON SAS controller v2 hw driver");
  3230. MODULE_ALIAS("platform:" DRV_NAME);