pm8001_hwi.c 151 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713
  1. /*
  2. * PMC-Sierra SPC 8001 SAS/SATA based host adapters driver
  3. *
  4. * Copyright (c) 2008-2009 USI Co., Ltd.
  5. * All rights reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions
  9. * are met:
  10. * 1. Redistributions of source code must retain the above copyright
  11. * notice, this list of conditions, and the following disclaimer,
  12. * without modification.
  13. * 2. Redistributions in binary form must reproduce at minimum a disclaimer
  14. * substantially similar to the "NO WARRANTY" disclaimer below
  15. * ("Disclaimer") and any redistribution must be conditioned upon
  16. * including a substantially similar Disclaimer requirement for further
  17. * binary redistribution.
  18. * 3. Neither the names of the above-listed copyright holders nor the names
  19. * of any contributors may be used to endorse or promote products derived
  20. * from this software without specific prior written permission.
  21. *
  22. * Alternatively, this software may be distributed under the terms of the
  23. * GNU General Public License ("GPL") version 2 as published by the Free
  24. * Software Foundation.
  25. *
  26. * NO WARRANTY
  27. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  28. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  29. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
  30. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  31. * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  32. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  33. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  34. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  35. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
  36. * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  37. * POSSIBILITY OF SUCH DAMAGES.
  38. *
  39. */
  40. #include <linux/slab.h>
  41. #include "pm8001_sas.h"
  42. #include "pm8001_hwi.h"
  43. #include "pm8001_chips.h"
  44. #include "pm8001_ctl.h"
  45. /**
  46. * read_main_config_table - read the configure table and save it.
  47. * @pm8001_ha: our hba card information
  48. */
  49. static void __devinit read_main_config_table(struct pm8001_hba_info *pm8001_ha)
  50. {
  51. void __iomem *address = pm8001_ha->main_cfg_tbl_addr;
  52. pm8001_ha->main_cfg_tbl.signature = pm8001_mr32(address, 0x00);
  53. pm8001_ha->main_cfg_tbl.interface_rev = pm8001_mr32(address, 0x04);
  54. pm8001_ha->main_cfg_tbl.firmware_rev = pm8001_mr32(address, 0x08);
  55. pm8001_ha->main_cfg_tbl.max_out_io = pm8001_mr32(address, 0x0C);
  56. pm8001_ha->main_cfg_tbl.max_sgl = pm8001_mr32(address, 0x10);
  57. pm8001_ha->main_cfg_tbl.ctrl_cap_flag = pm8001_mr32(address, 0x14);
  58. pm8001_ha->main_cfg_tbl.gst_offset = pm8001_mr32(address, 0x18);
  59. pm8001_ha->main_cfg_tbl.inbound_queue_offset =
  60. pm8001_mr32(address, MAIN_IBQ_OFFSET);
  61. pm8001_ha->main_cfg_tbl.outbound_queue_offset =
  62. pm8001_mr32(address, MAIN_OBQ_OFFSET);
  63. pm8001_ha->main_cfg_tbl.hda_mode_flag =
  64. pm8001_mr32(address, MAIN_HDA_FLAGS_OFFSET);
  65. /* read analog Setting offset from the configuration table */
  66. pm8001_ha->main_cfg_tbl.anolog_setup_table_offset =
  67. pm8001_mr32(address, MAIN_ANALOG_SETUP_OFFSET);
  68. /* read Error Dump Offset and Length */
  69. pm8001_ha->main_cfg_tbl.fatal_err_dump_offset0 =
  70. pm8001_mr32(address, MAIN_FATAL_ERROR_RDUMP0_OFFSET);
  71. pm8001_ha->main_cfg_tbl.fatal_err_dump_length0 =
  72. pm8001_mr32(address, MAIN_FATAL_ERROR_RDUMP0_LENGTH);
  73. pm8001_ha->main_cfg_tbl.fatal_err_dump_offset1 =
  74. pm8001_mr32(address, MAIN_FATAL_ERROR_RDUMP1_OFFSET);
  75. pm8001_ha->main_cfg_tbl.fatal_err_dump_length1 =
  76. pm8001_mr32(address, MAIN_FATAL_ERROR_RDUMP1_LENGTH);
  77. }
  78. /**
  79. * read_general_status_table - read the general status table and save it.
  80. * @pm8001_ha: our hba card information
  81. */
  82. static void __devinit
  83. read_general_status_table(struct pm8001_hba_info *pm8001_ha)
  84. {
  85. void __iomem *address = pm8001_ha->general_stat_tbl_addr;
  86. pm8001_ha->gs_tbl.gst_len_mpistate = pm8001_mr32(address, 0x00);
  87. pm8001_ha->gs_tbl.iq_freeze_state0 = pm8001_mr32(address, 0x04);
  88. pm8001_ha->gs_tbl.iq_freeze_state1 = pm8001_mr32(address, 0x08);
  89. pm8001_ha->gs_tbl.msgu_tcnt = pm8001_mr32(address, 0x0C);
  90. pm8001_ha->gs_tbl.iop_tcnt = pm8001_mr32(address, 0x10);
  91. pm8001_ha->gs_tbl.reserved = pm8001_mr32(address, 0x14);
  92. pm8001_ha->gs_tbl.phy_state[0] = pm8001_mr32(address, 0x18);
  93. pm8001_ha->gs_tbl.phy_state[1] = pm8001_mr32(address, 0x1C);
  94. pm8001_ha->gs_tbl.phy_state[2] = pm8001_mr32(address, 0x20);
  95. pm8001_ha->gs_tbl.phy_state[3] = pm8001_mr32(address, 0x24);
  96. pm8001_ha->gs_tbl.phy_state[4] = pm8001_mr32(address, 0x28);
  97. pm8001_ha->gs_tbl.phy_state[5] = pm8001_mr32(address, 0x2C);
  98. pm8001_ha->gs_tbl.phy_state[6] = pm8001_mr32(address, 0x30);
  99. pm8001_ha->gs_tbl.phy_state[7] = pm8001_mr32(address, 0x34);
  100. pm8001_ha->gs_tbl.reserved1 = pm8001_mr32(address, 0x38);
  101. pm8001_ha->gs_tbl.reserved2 = pm8001_mr32(address, 0x3C);
  102. pm8001_ha->gs_tbl.reserved3 = pm8001_mr32(address, 0x40);
  103. pm8001_ha->gs_tbl.recover_err_info[0] = pm8001_mr32(address, 0x44);
  104. pm8001_ha->gs_tbl.recover_err_info[1] = pm8001_mr32(address, 0x48);
  105. pm8001_ha->gs_tbl.recover_err_info[2] = pm8001_mr32(address, 0x4C);
  106. pm8001_ha->gs_tbl.recover_err_info[3] = pm8001_mr32(address, 0x50);
  107. pm8001_ha->gs_tbl.recover_err_info[4] = pm8001_mr32(address, 0x54);
  108. pm8001_ha->gs_tbl.recover_err_info[5] = pm8001_mr32(address, 0x58);
  109. pm8001_ha->gs_tbl.recover_err_info[6] = pm8001_mr32(address, 0x5C);
  110. pm8001_ha->gs_tbl.recover_err_info[7] = pm8001_mr32(address, 0x60);
  111. }
  112. /**
  113. * read_inbnd_queue_table - read the inbound queue table and save it.
  114. * @pm8001_ha: our hba card information
  115. */
  116. static void __devinit
  117. read_inbnd_queue_table(struct pm8001_hba_info *pm8001_ha)
  118. {
  119. int inbQ_num = 1;
  120. int i;
  121. void __iomem *address = pm8001_ha->inbnd_q_tbl_addr;
  122. for (i = 0; i < inbQ_num; i++) {
  123. u32 offset = i * 0x20;
  124. pm8001_ha->inbnd_q_tbl[i].pi_pci_bar =
  125. get_pci_bar_index(pm8001_mr32(address, (offset + 0x14)));
  126. pm8001_ha->inbnd_q_tbl[i].pi_offset =
  127. pm8001_mr32(address, (offset + 0x18));
  128. }
  129. }
  130. /**
  131. * read_outbnd_queue_table - read the outbound queue table and save it.
  132. * @pm8001_ha: our hba card information
  133. */
  134. static void __devinit
  135. read_outbnd_queue_table(struct pm8001_hba_info *pm8001_ha)
  136. {
  137. int outbQ_num = 1;
  138. int i;
  139. void __iomem *address = pm8001_ha->outbnd_q_tbl_addr;
  140. for (i = 0; i < outbQ_num; i++) {
  141. u32 offset = i * 0x24;
  142. pm8001_ha->outbnd_q_tbl[i].ci_pci_bar =
  143. get_pci_bar_index(pm8001_mr32(address, (offset + 0x14)));
  144. pm8001_ha->outbnd_q_tbl[i].ci_offset =
  145. pm8001_mr32(address, (offset + 0x18));
  146. }
  147. }
  148. /**
  149. * init_default_table_values - init the default table.
  150. * @pm8001_ha: our hba card information
  151. */
  152. static void __devinit
  153. init_default_table_values(struct pm8001_hba_info *pm8001_ha)
  154. {
  155. int qn = 1;
  156. int i;
  157. u32 offsetib, offsetob;
  158. void __iomem *addressib = pm8001_ha->inbnd_q_tbl_addr;
  159. void __iomem *addressob = pm8001_ha->outbnd_q_tbl_addr;
  160. pm8001_ha->main_cfg_tbl.inbound_q_nppd_hppd = 0;
  161. pm8001_ha->main_cfg_tbl.outbound_hw_event_pid0_3 = 0;
  162. pm8001_ha->main_cfg_tbl.outbound_hw_event_pid4_7 = 0;
  163. pm8001_ha->main_cfg_tbl.outbound_ncq_event_pid0_3 = 0;
  164. pm8001_ha->main_cfg_tbl.outbound_ncq_event_pid4_7 = 0;
  165. pm8001_ha->main_cfg_tbl.outbound_tgt_ITNexus_event_pid0_3 = 0;
  166. pm8001_ha->main_cfg_tbl.outbound_tgt_ITNexus_event_pid4_7 = 0;
  167. pm8001_ha->main_cfg_tbl.outbound_tgt_ssp_event_pid0_3 = 0;
  168. pm8001_ha->main_cfg_tbl.outbound_tgt_ssp_event_pid4_7 = 0;
  169. pm8001_ha->main_cfg_tbl.outbound_tgt_smp_event_pid0_3 = 0;
  170. pm8001_ha->main_cfg_tbl.outbound_tgt_smp_event_pid4_7 = 0;
  171. pm8001_ha->main_cfg_tbl.upper_event_log_addr =
  172. pm8001_ha->memoryMap.region[AAP1].phys_addr_hi;
  173. pm8001_ha->main_cfg_tbl.lower_event_log_addr =
  174. pm8001_ha->memoryMap.region[AAP1].phys_addr_lo;
  175. pm8001_ha->main_cfg_tbl.event_log_size = PM8001_EVENT_LOG_SIZE;
  176. pm8001_ha->main_cfg_tbl.event_log_option = 0x01;
  177. pm8001_ha->main_cfg_tbl.upper_iop_event_log_addr =
  178. pm8001_ha->memoryMap.region[IOP].phys_addr_hi;
  179. pm8001_ha->main_cfg_tbl.lower_iop_event_log_addr =
  180. pm8001_ha->memoryMap.region[IOP].phys_addr_lo;
  181. pm8001_ha->main_cfg_tbl.iop_event_log_size = PM8001_EVENT_LOG_SIZE;
  182. pm8001_ha->main_cfg_tbl.iop_event_log_option = 0x01;
  183. pm8001_ha->main_cfg_tbl.fatal_err_interrupt = 0x01;
  184. for (i = 0; i < qn; i++) {
  185. pm8001_ha->inbnd_q_tbl[i].element_pri_size_cnt =
  186. 0x00000100 | (0x00000040 << 16) | (0x00<<30);
  187. pm8001_ha->inbnd_q_tbl[i].upper_base_addr =
  188. pm8001_ha->memoryMap.region[IB].phys_addr_hi;
  189. pm8001_ha->inbnd_q_tbl[i].lower_base_addr =
  190. pm8001_ha->memoryMap.region[IB].phys_addr_lo;
  191. pm8001_ha->inbnd_q_tbl[i].base_virt =
  192. (u8 *)pm8001_ha->memoryMap.region[IB].virt_ptr;
  193. pm8001_ha->inbnd_q_tbl[i].total_length =
  194. pm8001_ha->memoryMap.region[IB].total_len;
  195. pm8001_ha->inbnd_q_tbl[i].ci_upper_base_addr =
  196. pm8001_ha->memoryMap.region[CI].phys_addr_hi;
  197. pm8001_ha->inbnd_q_tbl[i].ci_lower_base_addr =
  198. pm8001_ha->memoryMap.region[CI].phys_addr_lo;
  199. pm8001_ha->inbnd_q_tbl[i].ci_virt =
  200. pm8001_ha->memoryMap.region[CI].virt_ptr;
  201. offsetib = i * 0x20;
  202. pm8001_ha->inbnd_q_tbl[i].pi_pci_bar =
  203. get_pci_bar_index(pm8001_mr32(addressib,
  204. (offsetib + 0x14)));
  205. pm8001_ha->inbnd_q_tbl[i].pi_offset =
  206. pm8001_mr32(addressib, (offsetib + 0x18));
  207. pm8001_ha->inbnd_q_tbl[i].producer_idx = 0;
  208. pm8001_ha->inbnd_q_tbl[i].consumer_index = 0;
  209. }
  210. for (i = 0; i < qn; i++) {
  211. pm8001_ha->outbnd_q_tbl[i].element_size_cnt =
  212. 256 | (64 << 16) | (1<<30);
  213. pm8001_ha->outbnd_q_tbl[i].upper_base_addr =
  214. pm8001_ha->memoryMap.region[OB].phys_addr_hi;
  215. pm8001_ha->outbnd_q_tbl[i].lower_base_addr =
  216. pm8001_ha->memoryMap.region[OB].phys_addr_lo;
  217. pm8001_ha->outbnd_q_tbl[i].base_virt =
  218. (u8 *)pm8001_ha->memoryMap.region[OB].virt_ptr;
  219. pm8001_ha->outbnd_q_tbl[i].total_length =
  220. pm8001_ha->memoryMap.region[OB].total_len;
  221. pm8001_ha->outbnd_q_tbl[i].pi_upper_base_addr =
  222. pm8001_ha->memoryMap.region[PI].phys_addr_hi;
  223. pm8001_ha->outbnd_q_tbl[i].pi_lower_base_addr =
  224. pm8001_ha->memoryMap.region[PI].phys_addr_lo;
  225. pm8001_ha->outbnd_q_tbl[i].interrup_vec_cnt_delay =
  226. 0 | (10 << 16) | (0 << 24);
  227. pm8001_ha->outbnd_q_tbl[i].pi_virt =
  228. pm8001_ha->memoryMap.region[PI].virt_ptr;
  229. offsetob = i * 0x24;
  230. pm8001_ha->outbnd_q_tbl[i].ci_pci_bar =
  231. get_pci_bar_index(pm8001_mr32(addressob,
  232. offsetob + 0x14));
  233. pm8001_ha->outbnd_q_tbl[i].ci_offset =
  234. pm8001_mr32(addressob, (offsetob + 0x18));
  235. pm8001_ha->outbnd_q_tbl[i].consumer_idx = 0;
  236. pm8001_ha->outbnd_q_tbl[i].producer_index = 0;
  237. }
  238. }
  239. /**
  240. * update_main_config_table - update the main default table to the HBA.
  241. * @pm8001_ha: our hba card information
  242. */
  243. static void __devinit
  244. update_main_config_table(struct pm8001_hba_info *pm8001_ha)
  245. {
  246. void __iomem *address = pm8001_ha->main_cfg_tbl_addr;
  247. pm8001_mw32(address, 0x24,
  248. pm8001_ha->main_cfg_tbl.inbound_q_nppd_hppd);
  249. pm8001_mw32(address, 0x28,
  250. pm8001_ha->main_cfg_tbl.outbound_hw_event_pid0_3);
  251. pm8001_mw32(address, 0x2C,
  252. pm8001_ha->main_cfg_tbl.outbound_hw_event_pid4_7);
  253. pm8001_mw32(address, 0x30,
  254. pm8001_ha->main_cfg_tbl.outbound_ncq_event_pid0_3);
  255. pm8001_mw32(address, 0x34,
  256. pm8001_ha->main_cfg_tbl.outbound_ncq_event_pid4_7);
  257. pm8001_mw32(address, 0x38,
  258. pm8001_ha->main_cfg_tbl.outbound_tgt_ITNexus_event_pid0_3);
  259. pm8001_mw32(address, 0x3C,
  260. pm8001_ha->main_cfg_tbl.outbound_tgt_ITNexus_event_pid4_7);
  261. pm8001_mw32(address, 0x40,
  262. pm8001_ha->main_cfg_tbl.outbound_tgt_ssp_event_pid0_3);
  263. pm8001_mw32(address, 0x44,
  264. pm8001_ha->main_cfg_tbl.outbound_tgt_ssp_event_pid4_7);
  265. pm8001_mw32(address, 0x48,
  266. pm8001_ha->main_cfg_tbl.outbound_tgt_smp_event_pid0_3);
  267. pm8001_mw32(address, 0x4C,
  268. pm8001_ha->main_cfg_tbl.outbound_tgt_smp_event_pid4_7);
  269. pm8001_mw32(address, 0x50,
  270. pm8001_ha->main_cfg_tbl.upper_event_log_addr);
  271. pm8001_mw32(address, 0x54,
  272. pm8001_ha->main_cfg_tbl.lower_event_log_addr);
  273. pm8001_mw32(address, 0x58, pm8001_ha->main_cfg_tbl.event_log_size);
  274. pm8001_mw32(address, 0x5C, pm8001_ha->main_cfg_tbl.event_log_option);
  275. pm8001_mw32(address, 0x60,
  276. pm8001_ha->main_cfg_tbl.upper_iop_event_log_addr);
  277. pm8001_mw32(address, 0x64,
  278. pm8001_ha->main_cfg_tbl.lower_iop_event_log_addr);
  279. pm8001_mw32(address, 0x68, pm8001_ha->main_cfg_tbl.iop_event_log_size);
  280. pm8001_mw32(address, 0x6C,
  281. pm8001_ha->main_cfg_tbl.iop_event_log_option);
  282. pm8001_mw32(address, 0x70,
  283. pm8001_ha->main_cfg_tbl.fatal_err_interrupt);
  284. }
  285. /**
  286. * update_inbnd_queue_table - update the inbound queue table to the HBA.
  287. * @pm8001_ha: our hba card information
  288. */
  289. static void __devinit
  290. update_inbnd_queue_table(struct pm8001_hba_info *pm8001_ha, int number)
  291. {
  292. void __iomem *address = pm8001_ha->inbnd_q_tbl_addr;
  293. u16 offset = number * 0x20;
  294. pm8001_mw32(address, offset + 0x00,
  295. pm8001_ha->inbnd_q_tbl[number].element_pri_size_cnt);
  296. pm8001_mw32(address, offset + 0x04,
  297. pm8001_ha->inbnd_q_tbl[number].upper_base_addr);
  298. pm8001_mw32(address, offset + 0x08,
  299. pm8001_ha->inbnd_q_tbl[number].lower_base_addr);
  300. pm8001_mw32(address, offset + 0x0C,
  301. pm8001_ha->inbnd_q_tbl[number].ci_upper_base_addr);
  302. pm8001_mw32(address, offset + 0x10,
  303. pm8001_ha->inbnd_q_tbl[number].ci_lower_base_addr);
  304. }
  305. /**
  306. * update_outbnd_queue_table - update the outbound queue table to the HBA.
  307. * @pm8001_ha: our hba card information
  308. */
  309. static void __devinit
  310. update_outbnd_queue_table(struct pm8001_hba_info *pm8001_ha, int number)
  311. {
  312. void __iomem *address = pm8001_ha->outbnd_q_tbl_addr;
  313. u16 offset = number * 0x24;
  314. pm8001_mw32(address, offset + 0x00,
  315. pm8001_ha->outbnd_q_tbl[number].element_size_cnt);
  316. pm8001_mw32(address, offset + 0x04,
  317. pm8001_ha->outbnd_q_tbl[number].upper_base_addr);
  318. pm8001_mw32(address, offset + 0x08,
  319. pm8001_ha->outbnd_q_tbl[number].lower_base_addr);
  320. pm8001_mw32(address, offset + 0x0C,
  321. pm8001_ha->outbnd_q_tbl[number].pi_upper_base_addr);
  322. pm8001_mw32(address, offset + 0x10,
  323. pm8001_ha->outbnd_q_tbl[number].pi_lower_base_addr);
  324. pm8001_mw32(address, offset + 0x1C,
  325. pm8001_ha->outbnd_q_tbl[number].interrup_vec_cnt_delay);
  326. }
  327. /**
  328. * pm8001_bar4_shift - function is called to shift BAR base address
  329. * @pm8001_ha : our hba card infomation
  330. * @shiftValue : shifting value in memory bar.
  331. */
  332. int pm8001_bar4_shift(struct pm8001_hba_info *pm8001_ha, u32 shiftValue)
  333. {
  334. u32 regVal;
  335. unsigned long start;
  336. /* program the inbound AXI translation Lower Address */
  337. pm8001_cw32(pm8001_ha, 1, SPC_IBW_AXI_TRANSLATION_LOW, shiftValue);
  338. /* confirm the setting is written */
  339. start = jiffies + HZ; /* 1 sec */
  340. do {
  341. regVal = pm8001_cr32(pm8001_ha, 1, SPC_IBW_AXI_TRANSLATION_LOW);
  342. } while ((regVal != shiftValue) && time_before(jiffies, start));
  343. if (regVal != shiftValue) {
  344. PM8001_INIT_DBG(pm8001_ha,
  345. pm8001_printk("TIMEOUT:SPC_IBW_AXI_TRANSLATION_LOW"
  346. " = 0x%x\n", regVal));
  347. return -1;
  348. }
  349. return 0;
  350. }
  351. /**
  352. * mpi_set_phys_g3_with_ssc
  353. * @pm8001_ha: our hba card information
  354. * @SSCbit: set SSCbit to 0 to disable all phys ssc; 1 to enable all phys ssc.
  355. */
  356. static void __devinit
  357. mpi_set_phys_g3_with_ssc(struct pm8001_hba_info *pm8001_ha, u32 SSCbit)
  358. {
  359. u32 value, offset, i;
  360. unsigned long flags;
  361. #define SAS2_SETTINGS_LOCAL_PHY_0_3_SHIFT_ADDR 0x00030000
  362. #define SAS2_SETTINGS_LOCAL_PHY_4_7_SHIFT_ADDR 0x00040000
  363. #define SAS2_SETTINGS_LOCAL_PHY_0_3_OFFSET 0x1074
  364. #define SAS2_SETTINGS_LOCAL_PHY_4_7_OFFSET 0x1074
  365. #define PHY_G3_WITHOUT_SSC_BIT_SHIFT 12
  366. #define PHY_G3_WITH_SSC_BIT_SHIFT 13
  367. #define SNW3_PHY_CAPABILITIES_PARITY 31
  368. /*
  369. * Using shifted destination address 0x3_0000:0x1074 + 0x4000*N (N=0:3)
  370. * Using shifted destination address 0x4_0000:0x1074 + 0x4000*(N-4) (N=4:7)
  371. */
  372. spin_lock_irqsave(&pm8001_ha->lock, flags);
  373. if (-1 == pm8001_bar4_shift(pm8001_ha,
  374. SAS2_SETTINGS_LOCAL_PHY_0_3_SHIFT_ADDR)) {
  375. spin_unlock_irqrestore(&pm8001_ha->lock, flags);
  376. return;
  377. }
  378. for (i = 0; i < 4; i++) {
  379. offset = SAS2_SETTINGS_LOCAL_PHY_0_3_OFFSET + 0x4000 * i;
  380. pm8001_cw32(pm8001_ha, 2, offset, 0x80001501);
  381. }
  382. /* shift membase 3 for SAS2_SETTINGS_LOCAL_PHY 4 - 7 */
  383. if (-1 == pm8001_bar4_shift(pm8001_ha,
  384. SAS2_SETTINGS_LOCAL_PHY_4_7_SHIFT_ADDR)) {
  385. spin_unlock_irqrestore(&pm8001_ha->lock, flags);
  386. return;
  387. }
  388. for (i = 4; i < 8; i++) {
  389. offset = SAS2_SETTINGS_LOCAL_PHY_4_7_OFFSET + 0x4000 * (i-4);
  390. pm8001_cw32(pm8001_ha, 2, offset, 0x80001501);
  391. }
  392. /*************************************************************
  393. Change the SSC upspreading value to 0x0 so that upspreading is disabled.
  394. Device MABC SMOD0 Controls
  395. Address: (via MEMBASE-III):
  396. Using shifted destination address 0x0_0000: with Offset 0xD8
  397. 31:28 R/W Reserved Do not change
  398. 27:24 R/W SAS_SMOD_SPRDUP 0000
  399. 23:20 R/W SAS_SMOD_SPRDDN 0000
  400. 19:0 R/W Reserved Do not change
  401. Upon power-up this register will read as 0x8990c016,
  402. and I would like you to change the SAS_SMOD_SPRDUP bits to 0b0000
  403. so that the written value will be 0x8090c016.
  404. This will ensure only down-spreading SSC is enabled on the SPC.
  405. *************************************************************/
  406. value = pm8001_cr32(pm8001_ha, 2, 0xd8);
  407. pm8001_cw32(pm8001_ha, 2, 0xd8, 0x8000C016);
  408. /*set the shifted destination address to 0x0 to avoid error operation */
  409. pm8001_bar4_shift(pm8001_ha, 0x0);
  410. spin_unlock_irqrestore(&pm8001_ha->lock, flags);
  411. return;
  412. }
  413. /**
  414. * mpi_set_open_retry_interval_reg
  415. * @pm8001_ha: our hba card information
  416. * @interval - interval time for each OPEN_REJECT (RETRY). The units are in 1us.
  417. */
  418. static void __devinit
  419. mpi_set_open_retry_interval_reg(struct pm8001_hba_info *pm8001_ha,
  420. u32 interval)
  421. {
  422. u32 offset;
  423. u32 value;
  424. u32 i;
  425. unsigned long flags;
  426. #define OPEN_RETRY_INTERVAL_PHY_0_3_SHIFT_ADDR 0x00030000
  427. #define OPEN_RETRY_INTERVAL_PHY_4_7_SHIFT_ADDR 0x00040000
  428. #define OPEN_RETRY_INTERVAL_PHY_0_3_OFFSET 0x30B4
  429. #define OPEN_RETRY_INTERVAL_PHY_4_7_OFFSET 0x30B4
  430. #define OPEN_RETRY_INTERVAL_REG_MASK 0x0000FFFF
  431. value = interval & OPEN_RETRY_INTERVAL_REG_MASK;
  432. spin_lock_irqsave(&pm8001_ha->lock, flags);
  433. /* shift bar and set the OPEN_REJECT(RETRY) interval time of PHY 0 -3.*/
  434. if (-1 == pm8001_bar4_shift(pm8001_ha,
  435. OPEN_RETRY_INTERVAL_PHY_0_3_SHIFT_ADDR)) {
  436. spin_unlock_irqrestore(&pm8001_ha->lock, flags);
  437. return;
  438. }
  439. for (i = 0; i < 4; i++) {
  440. offset = OPEN_RETRY_INTERVAL_PHY_0_3_OFFSET + 0x4000 * i;
  441. pm8001_cw32(pm8001_ha, 2, offset, value);
  442. }
  443. if (-1 == pm8001_bar4_shift(pm8001_ha,
  444. OPEN_RETRY_INTERVAL_PHY_4_7_SHIFT_ADDR)) {
  445. spin_unlock_irqrestore(&pm8001_ha->lock, flags);
  446. return;
  447. }
  448. for (i = 4; i < 8; i++) {
  449. offset = OPEN_RETRY_INTERVAL_PHY_4_7_OFFSET + 0x4000 * (i-4);
  450. pm8001_cw32(pm8001_ha, 2, offset, value);
  451. }
  452. /*set the shifted destination address to 0x0 to avoid error operation */
  453. pm8001_bar4_shift(pm8001_ha, 0x0);
  454. spin_unlock_irqrestore(&pm8001_ha->lock, flags);
  455. return;
  456. }
  457. /**
  458. * mpi_init_check - check firmware initialization status.
  459. * @pm8001_ha: our hba card information
  460. */
  461. static int mpi_init_check(struct pm8001_hba_info *pm8001_ha)
  462. {
  463. u32 max_wait_count;
  464. u32 value;
  465. u32 gst_len_mpistate;
  466. /* Write bit0=1 to Inbound DoorBell Register to tell the SPC FW the
  467. table is updated */
  468. pm8001_cw32(pm8001_ha, 0, MSGU_IBDB_SET, SPC_MSGU_CFG_TABLE_UPDATE);
  469. /* wait until Inbound DoorBell Clear Register toggled */
  470. max_wait_count = 1 * 1000 * 1000;/* 1 sec */
  471. do {
  472. udelay(1);
  473. value = pm8001_cr32(pm8001_ha, 0, MSGU_IBDB_SET);
  474. value &= SPC_MSGU_CFG_TABLE_UPDATE;
  475. } while ((value != 0) && (--max_wait_count));
  476. if (!max_wait_count)
  477. return -1;
  478. /* check the MPI-State for initialization */
  479. gst_len_mpistate =
  480. pm8001_mr32(pm8001_ha->general_stat_tbl_addr,
  481. GST_GSTLEN_MPIS_OFFSET);
  482. if (GST_MPI_STATE_INIT != (gst_len_mpistate & GST_MPI_STATE_MASK))
  483. return -1;
  484. /* check MPI Initialization error */
  485. gst_len_mpistate = gst_len_mpistate >> 16;
  486. if (0x0000 != gst_len_mpistate)
  487. return -1;
  488. return 0;
  489. }
  490. /**
  491. * check_fw_ready - The LLDD check if the FW is ready, if not, return error.
  492. * @pm8001_ha: our hba card information
  493. */
  494. static int check_fw_ready(struct pm8001_hba_info *pm8001_ha)
  495. {
  496. u32 value, value1;
  497. u32 max_wait_count;
  498. /* check error state */
  499. value = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_1);
  500. value1 = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_2);
  501. /* check AAP error */
  502. if (SCRATCH_PAD1_ERR == (value & SCRATCH_PAD_STATE_MASK)) {
  503. /* error state */
  504. value = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_0);
  505. return -1;
  506. }
  507. /* check IOP error */
  508. if (SCRATCH_PAD2_ERR == (value1 & SCRATCH_PAD_STATE_MASK)) {
  509. /* error state */
  510. value1 = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_3);
  511. return -1;
  512. }
  513. /* bit 4-31 of scratch pad1 should be zeros if it is not
  514. in error state*/
  515. if (value & SCRATCH_PAD1_STATE_MASK) {
  516. /* error case */
  517. pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_0);
  518. return -1;
  519. }
  520. /* bit 2, 4-31 of scratch pad2 should be zeros if it is not
  521. in error state */
  522. if (value1 & SCRATCH_PAD2_STATE_MASK) {
  523. /* error case */
  524. return -1;
  525. }
  526. max_wait_count = 1 * 1000 * 1000;/* 1 sec timeout */
  527. /* wait until scratch pad 1 and 2 registers in ready state */
  528. do {
  529. udelay(1);
  530. value = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_1)
  531. & SCRATCH_PAD1_RDY;
  532. value1 = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_2)
  533. & SCRATCH_PAD2_RDY;
  534. if ((--max_wait_count) == 0)
  535. return -1;
  536. } while ((value != SCRATCH_PAD1_RDY) || (value1 != SCRATCH_PAD2_RDY));
  537. return 0;
  538. }
  539. static void init_pci_device_addresses(struct pm8001_hba_info *pm8001_ha)
  540. {
  541. void __iomem *base_addr;
  542. u32 value;
  543. u32 offset;
  544. u32 pcibar;
  545. u32 pcilogic;
  546. value = pm8001_cr32(pm8001_ha, 0, 0x44);
  547. offset = value & 0x03FFFFFF;
  548. PM8001_INIT_DBG(pm8001_ha,
  549. pm8001_printk("Scratchpad 0 Offset: %x\n", offset));
  550. pcilogic = (value & 0xFC000000) >> 26;
  551. pcibar = get_pci_bar_index(pcilogic);
  552. PM8001_INIT_DBG(pm8001_ha,
  553. pm8001_printk("Scratchpad 0 PCI BAR: %d\n", pcibar));
  554. pm8001_ha->main_cfg_tbl_addr = base_addr =
  555. pm8001_ha->io_mem[pcibar].memvirtaddr + offset;
  556. pm8001_ha->general_stat_tbl_addr =
  557. base_addr + pm8001_cr32(pm8001_ha, pcibar, offset + 0x18);
  558. pm8001_ha->inbnd_q_tbl_addr =
  559. base_addr + pm8001_cr32(pm8001_ha, pcibar, offset + 0x1C);
  560. pm8001_ha->outbnd_q_tbl_addr =
  561. base_addr + pm8001_cr32(pm8001_ha, pcibar, offset + 0x20);
  562. }
  563. /**
  564. * pm8001_chip_init - the main init function that initialize whole PM8001 chip.
  565. * @pm8001_ha: our hba card information
  566. */
  567. static int __devinit pm8001_chip_init(struct pm8001_hba_info *pm8001_ha)
  568. {
  569. /* check the firmware status */
  570. if (-1 == check_fw_ready(pm8001_ha)) {
  571. PM8001_FAIL_DBG(pm8001_ha,
  572. pm8001_printk("Firmware is not ready!\n"));
  573. return -EBUSY;
  574. }
  575. /* Initialize pci space address eg: mpi offset */
  576. init_pci_device_addresses(pm8001_ha);
  577. init_default_table_values(pm8001_ha);
  578. read_main_config_table(pm8001_ha);
  579. read_general_status_table(pm8001_ha);
  580. read_inbnd_queue_table(pm8001_ha);
  581. read_outbnd_queue_table(pm8001_ha);
  582. /* update main config table ,inbound table and outbound table */
  583. update_main_config_table(pm8001_ha);
  584. update_inbnd_queue_table(pm8001_ha, 0);
  585. update_outbnd_queue_table(pm8001_ha, 0);
  586. mpi_set_phys_g3_with_ssc(pm8001_ha, 0);
  587. /* 7->130ms, 34->500ms, 119->1.5s */
  588. mpi_set_open_retry_interval_reg(pm8001_ha, 119);
  589. /* notify firmware update finished and check initialization status */
  590. if (0 == mpi_init_check(pm8001_ha)) {
  591. PM8001_INIT_DBG(pm8001_ha,
  592. pm8001_printk("MPI initialize successful!\n"));
  593. } else
  594. return -EBUSY;
  595. /*This register is a 16-bit timer with a resolution of 1us. This is the
  596. timer used for interrupt delay/coalescing in the PCIe Application Layer.
  597. Zero is not a valid value. A value of 1 in the register will cause the
  598. interrupts to be normal. A value greater than 1 will cause coalescing
  599. delays.*/
  600. pm8001_cw32(pm8001_ha, 1, 0x0033c0, 0x1);
  601. pm8001_cw32(pm8001_ha, 1, 0x0033c4, 0x0);
  602. return 0;
  603. }
  604. static int mpi_uninit_check(struct pm8001_hba_info *pm8001_ha)
  605. {
  606. u32 max_wait_count;
  607. u32 value;
  608. u32 gst_len_mpistate;
  609. init_pci_device_addresses(pm8001_ha);
  610. /* Write bit1=1 to Inbound DoorBell Register to tell the SPC FW the
  611. table is stop */
  612. pm8001_cw32(pm8001_ha, 0, MSGU_IBDB_SET, SPC_MSGU_CFG_TABLE_RESET);
  613. /* wait until Inbound DoorBell Clear Register toggled */
  614. max_wait_count = 1 * 1000 * 1000;/* 1 sec */
  615. do {
  616. udelay(1);
  617. value = pm8001_cr32(pm8001_ha, 0, MSGU_IBDB_SET);
  618. value &= SPC_MSGU_CFG_TABLE_RESET;
  619. } while ((value != 0) && (--max_wait_count));
  620. if (!max_wait_count) {
  621. PM8001_FAIL_DBG(pm8001_ha,
  622. pm8001_printk("TIMEOUT:IBDB value/=0x%x\n", value));
  623. return -1;
  624. }
  625. /* check the MPI-State for termination in progress */
  626. /* wait until Inbound DoorBell Clear Register toggled */
  627. max_wait_count = 1 * 1000 * 1000; /* 1 sec */
  628. do {
  629. udelay(1);
  630. gst_len_mpistate =
  631. pm8001_mr32(pm8001_ha->general_stat_tbl_addr,
  632. GST_GSTLEN_MPIS_OFFSET);
  633. if (GST_MPI_STATE_UNINIT ==
  634. (gst_len_mpistate & GST_MPI_STATE_MASK))
  635. break;
  636. } while (--max_wait_count);
  637. if (!max_wait_count) {
  638. PM8001_FAIL_DBG(pm8001_ha,
  639. pm8001_printk(" TIME OUT MPI State = 0x%x\n",
  640. gst_len_mpistate & GST_MPI_STATE_MASK));
  641. return -1;
  642. }
  643. return 0;
  644. }
  645. /**
  646. * soft_reset_ready_check - Function to check FW is ready for soft reset.
  647. * @pm8001_ha: our hba card information
  648. */
  649. static u32 soft_reset_ready_check(struct pm8001_hba_info *pm8001_ha)
  650. {
  651. u32 regVal, regVal1, regVal2;
  652. if (mpi_uninit_check(pm8001_ha) != 0) {
  653. PM8001_FAIL_DBG(pm8001_ha,
  654. pm8001_printk("MPI state is not ready\n"));
  655. return -1;
  656. }
  657. /* read the scratch pad 2 register bit 2 */
  658. regVal = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_2)
  659. & SCRATCH_PAD2_FWRDY_RST;
  660. if (regVal == SCRATCH_PAD2_FWRDY_RST) {
  661. PM8001_INIT_DBG(pm8001_ha,
  662. pm8001_printk("Firmware is ready for reset .\n"));
  663. } else {
  664. unsigned long flags;
  665. /* Trigger NMI twice via RB6 */
  666. spin_lock_irqsave(&pm8001_ha->lock, flags);
  667. if (-1 == pm8001_bar4_shift(pm8001_ha, RB6_ACCESS_REG)) {
  668. spin_unlock_irqrestore(&pm8001_ha->lock, flags);
  669. PM8001_FAIL_DBG(pm8001_ha,
  670. pm8001_printk("Shift Bar4 to 0x%x failed\n",
  671. RB6_ACCESS_REG));
  672. return -1;
  673. }
  674. pm8001_cw32(pm8001_ha, 2, SPC_RB6_OFFSET,
  675. RB6_MAGIC_NUMBER_RST);
  676. pm8001_cw32(pm8001_ha, 2, SPC_RB6_OFFSET, RB6_MAGIC_NUMBER_RST);
  677. /* wait for 100 ms */
  678. mdelay(100);
  679. regVal = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_2) &
  680. SCRATCH_PAD2_FWRDY_RST;
  681. if (regVal != SCRATCH_PAD2_FWRDY_RST) {
  682. regVal1 = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_1);
  683. regVal2 = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_2);
  684. PM8001_FAIL_DBG(pm8001_ha,
  685. pm8001_printk("TIMEOUT:MSGU_SCRATCH_PAD1"
  686. "=0x%x, MSGU_SCRATCH_PAD2=0x%x\n",
  687. regVal1, regVal2));
  688. PM8001_FAIL_DBG(pm8001_ha,
  689. pm8001_printk("SCRATCH_PAD0 value = 0x%x\n",
  690. pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_0)));
  691. PM8001_FAIL_DBG(pm8001_ha,
  692. pm8001_printk("SCRATCH_PAD3 value = 0x%x\n",
  693. pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_3)));
  694. spin_unlock_irqrestore(&pm8001_ha->lock, flags);
  695. return -1;
  696. }
  697. spin_unlock_irqrestore(&pm8001_ha->lock, flags);
  698. }
  699. return 0;
  700. }
  701. /**
  702. * pm8001_chip_soft_rst - soft reset the PM8001 chip, so that the clear all
  703. * the FW register status to the originated status.
  704. * @pm8001_ha: our hba card information
  705. * @signature: signature in host scratch pad0 register.
  706. */
  707. static int
  708. pm8001_chip_soft_rst(struct pm8001_hba_info *pm8001_ha, u32 signature)
  709. {
  710. u32 regVal, toggleVal;
  711. u32 max_wait_count;
  712. u32 regVal1, regVal2, regVal3;
  713. unsigned long flags;
  714. /* step1: Check FW is ready for soft reset */
  715. if (soft_reset_ready_check(pm8001_ha) != 0) {
  716. PM8001_FAIL_DBG(pm8001_ha, pm8001_printk("FW is not ready\n"));
  717. return -1;
  718. }
  719. /* step 2: clear NMI status register on AAP1 and IOP, write the same
  720. value to clear */
  721. /* map 0x60000 to BAR4(0x20), BAR2(win) */
  722. spin_lock_irqsave(&pm8001_ha->lock, flags);
  723. if (-1 == pm8001_bar4_shift(pm8001_ha, MBIC_AAP1_ADDR_BASE)) {
  724. spin_unlock_irqrestore(&pm8001_ha->lock, flags);
  725. PM8001_FAIL_DBG(pm8001_ha,
  726. pm8001_printk("Shift Bar4 to 0x%x failed\n",
  727. MBIC_AAP1_ADDR_BASE));
  728. return -1;
  729. }
  730. regVal = pm8001_cr32(pm8001_ha, 2, MBIC_NMI_ENABLE_VPE0_IOP);
  731. PM8001_INIT_DBG(pm8001_ha,
  732. pm8001_printk("MBIC - NMI Enable VPE0 (IOP)= 0x%x\n", regVal));
  733. pm8001_cw32(pm8001_ha, 2, MBIC_NMI_ENABLE_VPE0_IOP, 0x0);
  734. /* map 0x70000 to BAR4(0x20), BAR2(win) */
  735. if (-1 == pm8001_bar4_shift(pm8001_ha, MBIC_IOP_ADDR_BASE)) {
  736. spin_unlock_irqrestore(&pm8001_ha->lock, flags);
  737. PM8001_FAIL_DBG(pm8001_ha,
  738. pm8001_printk("Shift Bar4 to 0x%x failed\n",
  739. MBIC_IOP_ADDR_BASE));
  740. return -1;
  741. }
  742. regVal = pm8001_cr32(pm8001_ha, 2, MBIC_NMI_ENABLE_VPE0_AAP1);
  743. PM8001_INIT_DBG(pm8001_ha,
  744. pm8001_printk("MBIC - NMI Enable VPE0 (AAP1)= 0x%x\n", regVal));
  745. pm8001_cw32(pm8001_ha, 2, MBIC_NMI_ENABLE_VPE0_AAP1, 0x0);
  746. regVal = pm8001_cr32(pm8001_ha, 1, PCIE_EVENT_INTERRUPT_ENABLE);
  747. PM8001_INIT_DBG(pm8001_ha,
  748. pm8001_printk("PCIE -Event Interrupt Enable = 0x%x\n", regVal));
  749. pm8001_cw32(pm8001_ha, 1, PCIE_EVENT_INTERRUPT_ENABLE, 0x0);
  750. regVal = pm8001_cr32(pm8001_ha, 1, PCIE_EVENT_INTERRUPT);
  751. PM8001_INIT_DBG(pm8001_ha,
  752. pm8001_printk("PCIE - Event Interrupt = 0x%x\n", regVal));
  753. pm8001_cw32(pm8001_ha, 1, PCIE_EVENT_INTERRUPT, regVal);
  754. regVal = pm8001_cr32(pm8001_ha, 1, PCIE_ERROR_INTERRUPT_ENABLE);
  755. PM8001_INIT_DBG(pm8001_ha,
  756. pm8001_printk("PCIE -Error Interrupt Enable = 0x%x\n", regVal));
  757. pm8001_cw32(pm8001_ha, 1, PCIE_ERROR_INTERRUPT_ENABLE, 0x0);
  758. regVal = pm8001_cr32(pm8001_ha, 1, PCIE_ERROR_INTERRUPT);
  759. PM8001_INIT_DBG(pm8001_ha,
  760. pm8001_printk("PCIE - Error Interrupt = 0x%x\n", regVal));
  761. pm8001_cw32(pm8001_ha, 1, PCIE_ERROR_INTERRUPT, regVal);
  762. /* read the scratch pad 1 register bit 2 */
  763. regVal = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_1)
  764. & SCRATCH_PAD1_RST;
  765. toggleVal = regVal ^ SCRATCH_PAD1_RST;
  766. /* set signature in host scratch pad0 register to tell SPC that the
  767. host performs the soft reset */
  768. pm8001_cw32(pm8001_ha, 0, MSGU_HOST_SCRATCH_PAD_0, signature);
  769. /* read required registers for confirmming */
  770. /* map 0x0700000 to BAR4(0x20), BAR2(win) */
  771. if (-1 == pm8001_bar4_shift(pm8001_ha, GSM_ADDR_BASE)) {
  772. spin_unlock_irqrestore(&pm8001_ha->lock, flags);
  773. PM8001_FAIL_DBG(pm8001_ha,
  774. pm8001_printk("Shift Bar4 to 0x%x failed\n",
  775. GSM_ADDR_BASE));
  776. return -1;
  777. }
  778. PM8001_INIT_DBG(pm8001_ha,
  779. pm8001_printk("GSM 0x0(0x00007b88)-GSM Configuration and"
  780. " Reset = 0x%x\n",
  781. pm8001_cr32(pm8001_ha, 2, GSM_CONFIG_RESET)));
  782. /* step 3: host read GSM Configuration and Reset register */
  783. regVal = pm8001_cr32(pm8001_ha, 2, GSM_CONFIG_RESET);
  784. /* Put those bits to low */
  785. /* GSM XCBI offset = 0x70 0000
  786. 0x00 Bit 13 COM_SLV_SW_RSTB 1
  787. 0x00 Bit 12 QSSP_SW_RSTB 1
  788. 0x00 Bit 11 RAAE_SW_RSTB 1
  789. 0x00 Bit 9 RB_1_SW_RSTB 1
  790. 0x00 Bit 8 SM_SW_RSTB 1
  791. */
  792. regVal &= ~(0x00003b00);
  793. /* host write GSM Configuration and Reset register */
  794. pm8001_cw32(pm8001_ha, 2, GSM_CONFIG_RESET, regVal);
  795. PM8001_INIT_DBG(pm8001_ha,
  796. pm8001_printk("GSM 0x0 (0x00007b88 ==> 0x00004088) - GSM "
  797. "Configuration and Reset is set to = 0x%x\n",
  798. pm8001_cr32(pm8001_ha, 2, GSM_CONFIG_RESET)));
  799. /* step 4: */
  800. /* disable GSM - Read Address Parity Check */
  801. regVal1 = pm8001_cr32(pm8001_ha, 2, GSM_READ_ADDR_PARITY_CHECK);
  802. PM8001_INIT_DBG(pm8001_ha,
  803. pm8001_printk("GSM 0x700038 - Read Address Parity Check "
  804. "Enable = 0x%x\n", regVal1));
  805. pm8001_cw32(pm8001_ha, 2, GSM_READ_ADDR_PARITY_CHECK, 0x0);
  806. PM8001_INIT_DBG(pm8001_ha,
  807. pm8001_printk("GSM 0x700038 - Read Address Parity Check Enable"
  808. "is set to = 0x%x\n",
  809. pm8001_cr32(pm8001_ha, 2, GSM_READ_ADDR_PARITY_CHECK)));
  810. /* disable GSM - Write Address Parity Check */
  811. regVal2 = pm8001_cr32(pm8001_ha, 2, GSM_WRITE_ADDR_PARITY_CHECK);
  812. PM8001_INIT_DBG(pm8001_ha,
  813. pm8001_printk("GSM 0x700040 - Write Address Parity Check"
  814. " Enable = 0x%x\n", regVal2));
  815. pm8001_cw32(pm8001_ha, 2, GSM_WRITE_ADDR_PARITY_CHECK, 0x0);
  816. PM8001_INIT_DBG(pm8001_ha,
  817. pm8001_printk("GSM 0x700040 - Write Address Parity Check "
  818. "Enable is set to = 0x%x\n",
  819. pm8001_cr32(pm8001_ha, 2, GSM_WRITE_ADDR_PARITY_CHECK)));
  820. /* disable GSM - Write Data Parity Check */
  821. regVal3 = pm8001_cr32(pm8001_ha, 2, GSM_WRITE_DATA_PARITY_CHECK);
  822. PM8001_INIT_DBG(pm8001_ha,
  823. pm8001_printk("GSM 0x300048 - Write Data Parity Check"
  824. " Enable = 0x%x\n", regVal3));
  825. pm8001_cw32(pm8001_ha, 2, GSM_WRITE_DATA_PARITY_CHECK, 0x0);
  826. PM8001_INIT_DBG(pm8001_ha,
  827. pm8001_printk("GSM 0x300048 - Write Data Parity Check Enable"
  828. "is set to = 0x%x\n",
  829. pm8001_cr32(pm8001_ha, 2, GSM_WRITE_DATA_PARITY_CHECK)));
  830. /* step 5: delay 10 usec */
  831. udelay(10);
  832. /* step 5-b: set GPIO-0 output control to tristate anyway */
  833. if (-1 == pm8001_bar4_shift(pm8001_ha, GPIO_ADDR_BASE)) {
  834. spin_unlock_irqrestore(&pm8001_ha->lock, flags);
  835. PM8001_INIT_DBG(pm8001_ha,
  836. pm8001_printk("Shift Bar4 to 0x%x failed\n",
  837. GPIO_ADDR_BASE));
  838. return -1;
  839. }
  840. regVal = pm8001_cr32(pm8001_ha, 2, GPIO_GPIO_0_0UTPUT_CTL_OFFSET);
  841. PM8001_INIT_DBG(pm8001_ha,
  842. pm8001_printk("GPIO Output Control Register:"
  843. " = 0x%x\n", regVal));
  844. /* set GPIO-0 output control to tri-state */
  845. regVal &= 0xFFFFFFFC;
  846. pm8001_cw32(pm8001_ha, 2, GPIO_GPIO_0_0UTPUT_CTL_OFFSET, regVal);
  847. /* Step 6: Reset the IOP and AAP1 */
  848. /* map 0x00000 to BAR4(0x20), BAR2(win) */
  849. if (-1 == pm8001_bar4_shift(pm8001_ha, SPC_TOP_LEVEL_ADDR_BASE)) {
  850. spin_unlock_irqrestore(&pm8001_ha->lock, flags);
  851. PM8001_FAIL_DBG(pm8001_ha,
  852. pm8001_printk("SPC Shift Bar4 to 0x%x failed\n",
  853. SPC_TOP_LEVEL_ADDR_BASE));
  854. return -1;
  855. }
  856. regVal = pm8001_cr32(pm8001_ha, 2, SPC_REG_RESET);
  857. PM8001_INIT_DBG(pm8001_ha,
  858. pm8001_printk("Top Register before resetting IOP/AAP1"
  859. ":= 0x%x\n", regVal));
  860. regVal &= ~(SPC_REG_RESET_PCS_IOP_SS | SPC_REG_RESET_PCS_AAP1_SS);
  861. pm8001_cw32(pm8001_ha, 2, SPC_REG_RESET, regVal);
  862. /* step 7: Reset the BDMA/OSSP */
  863. regVal = pm8001_cr32(pm8001_ha, 2, SPC_REG_RESET);
  864. PM8001_INIT_DBG(pm8001_ha,
  865. pm8001_printk("Top Register before resetting BDMA/OSSP"
  866. ": = 0x%x\n", regVal));
  867. regVal &= ~(SPC_REG_RESET_BDMA_CORE | SPC_REG_RESET_OSSP);
  868. pm8001_cw32(pm8001_ha, 2, SPC_REG_RESET, regVal);
  869. /* step 8: delay 10 usec */
  870. udelay(10);
  871. /* step 9: bring the BDMA and OSSP out of reset */
  872. regVal = pm8001_cr32(pm8001_ha, 2, SPC_REG_RESET);
  873. PM8001_INIT_DBG(pm8001_ha,
  874. pm8001_printk("Top Register before bringing up BDMA/OSSP"
  875. ":= 0x%x\n", regVal));
  876. regVal |= (SPC_REG_RESET_BDMA_CORE | SPC_REG_RESET_OSSP);
  877. pm8001_cw32(pm8001_ha, 2, SPC_REG_RESET, regVal);
  878. /* step 10: delay 10 usec */
  879. udelay(10);
  880. /* step 11: reads and sets the GSM Configuration and Reset Register */
  881. /* map 0x0700000 to BAR4(0x20), BAR2(win) */
  882. if (-1 == pm8001_bar4_shift(pm8001_ha, GSM_ADDR_BASE)) {
  883. spin_unlock_irqrestore(&pm8001_ha->lock, flags);
  884. PM8001_FAIL_DBG(pm8001_ha,
  885. pm8001_printk("SPC Shift Bar4 to 0x%x failed\n",
  886. GSM_ADDR_BASE));
  887. return -1;
  888. }
  889. PM8001_INIT_DBG(pm8001_ha,
  890. pm8001_printk("GSM 0x0 (0x00007b88)-GSM Configuration and "
  891. "Reset = 0x%x\n", pm8001_cr32(pm8001_ha, 2, GSM_CONFIG_RESET)));
  892. regVal = pm8001_cr32(pm8001_ha, 2, GSM_CONFIG_RESET);
  893. /* Put those bits to high */
  894. /* GSM XCBI offset = 0x70 0000
  895. 0x00 Bit 13 COM_SLV_SW_RSTB 1
  896. 0x00 Bit 12 QSSP_SW_RSTB 1
  897. 0x00 Bit 11 RAAE_SW_RSTB 1
  898. 0x00 Bit 9 RB_1_SW_RSTB 1
  899. 0x00 Bit 8 SM_SW_RSTB 1
  900. */
  901. regVal |= (GSM_CONFIG_RESET_VALUE);
  902. pm8001_cw32(pm8001_ha, 2, GSM_CONFIG_RESET, regVal);
  903. PM8001_INIT_DBG(pm8001_ha,
  904. pm8001_printk("GSM (0x00004088 ==> 0x00007b88) - GSM"
  905. " Configuration and Reset is set to = 0x%x\n",
  906. pm8001_cr32(pm8001_ha, 2, GSM_CONFIG_RESET)));
  907. /* step 12: Restore GSM - Read Address Parity Check */
  908. regVal = pm8001_cr32(pm8001_ha, 2, GSM_READ_ADDR_PARITY_CHECK);
  909. /* just for debugging */
  910. PM8001_INIT_DBG(pm8001_ha,
  911. pm8001_printk("GSM 0x700038 - Read Address Parity Check Enable"
  912. " = 0x%x\n", regVal));
  913. pm8001_cw32(pm8001_ha, 2, GSM_READ_ADDR_PARITY_CHECK, regVal1);
  914. PM8001_INIT_DBG(pm8001_ha,
  915. pm8001_printk("GSM 0x700038 - Read Address Parity"
  916. " Check Enable is set to = 0x%x\n",
  917. pm8001_cr32(pm8001_ha, 2, GSM_READ_ADDR_PARITY_CHECK)));
  918. /* Restore GSM - Write Address Parity Check */
  919. regVal = pm8001_cr32(pm8001_ha, 2, GSM_WRITE_ADDR_PARITY_CHECK);
  920. pm8001_cw32(pm8001_ha, 2, GSM_WRITE_ADDR_PARITY_CHECK, regVal2);
  921. PM8001_INIT_DBG(pm8001_ha,
  922. pm8001_printk("GSM 0x700040 - Write Address Parity Check"
  923. " Enable is set to = 0x%x\n",
  924. pm8001_cr32(pm8001_ha, 2, GSM_WRITE_ADDR_PARITY_CHECK)));
  925. /* Restore GSM - Write Data Parity Check */
  926. regVal = pm8001_cr32(pm8001_ha, 2, GSM_WRITE_DATA_PARITY_CHECK);
  927. pm8001_cw32(pm8001_ha, 2, GSM_WRITE_DATA_PARITY_CHECK, regVal3);
  928. PM8001_INIT_DBG(pm8001_ha,
  929. pm8001_printk("GSM 0x700048 - Write Data Parity Check Enable"
  930. "is set to = 0x%x\n",
  931. pm8001_cr32(pm8001_ha, 2, GSM_WRITE_DATA_PARITY_CHECK)));
  932. /* step 13: bring the IOP and AAP1 out of reset */
  933. /* map 0x00000 to BAR4(0x20), BAR2(win) */
  934. if (-1 == pm8001_bar4_shift(pm8001_ha, SPC_TOP_LEVEL_ADDR_BASE)) {
  935. spin_unlock_irqrestore(&pm8001_ha->lock, flags);
  936. PM8001_FAIL_DBG(pm8001_ha,
  937. pm8001_printk("Shift Bar4 to 0x%x failed\n",
  938. SPC_TOP_LEVEL_ADDR_BASE));
  939. return -1;
  940. }
  941. regVal = pm8001_cr32(pm8001_ha, 2, SPC_REG_RESET);
  942. regVal |= (SPC_REG_RESET_PCS_IOP_SS | SPC_REG_RESET_PCS_AAP1_SS);
  943. pm8001_cw32(pm8001_ha, 2, SPC_REG_RESET, regVal);
  944. /* step 14: delay 10 usec - Normal Mode */
  945. udelay(10);
  946. /* check Soft Reset Normal mode or Soft Reset HDA mode */
  947. if (signature == SPC_SOFT_RESET_SIGNATURE) {
  948. /* step 15 (Normal Mode): wait until scratch pad1 register
  949. bit 2 toggled */
  950. max_wait_count = 2 * 1000 * 1000;/* 2 sec */
  951. do {
  952. udelay(1);
  953. regVal = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_1) &
  954. SCRATCH_PAD1_RST;
  955. } while ((regVal != toggleVal) && (--max_wait_count));
  956. if (!max_wait_count) {
  957. regVal = pm8001_cr32(pm8001_ha, 0,
  958. MSGU_SCRATCH_PAD_1);
  959. PM8001_FAIL_DBG(pm8001_ha,
  960. pm8001_printk("TIMEOUT : ToggleVal 0x%x,"
  961. "MSGU_SCRATCH_PAD1 = 0x%x\n",
  962. toggleVal, regVal));
  963. PM8001_FAIL_DBG(pm8001_ha,
  964. pm8001_printk("SCRATCH_PAD0 value = 0x%x\n",
  965. pm8001_cr32(pm8001_ha, 0,
  966. MSGU_SCRATCH_PAD_0)));
  967. PM8001_FAIL_DBG(pm8001_ha,
  968. pm8001_printk("SCRATCH_PAD2 value = 0x%x\n",
  969. pm8001_cr32(pm8001_ha, 0,
  970. MSGU_SCRATCH_PAD_2)));
  971. PM8001_FAIL_DBG(pm8001_ha,
  972. pm8001_printk("SCRATCH_PAD3 value = 0x%x\n",
  973. pm8001_cr32(pm8001_ha, 0,
  974. MSGU_SCRATCH_PAD_3)));
  975. spin_unlock_irqrestore(&pm8001_ha->lock, flags);
  976. return -1;
  977. }
  978. /* step 16 (Normal) - Clear ODMR and ODCR */
  979. pm8001_cw32(pm8001_ha, 0, MSGU_ODCR, ODCR_CLEAR_ALL);
  980. pm8001_cw32(pm8001_ha, 0, MSGU_ODMR, ODMR_CLEAR_ALL);
  981. /* step 17 (Normal Mode): wait for the FW and IOP to get
  982. ready - 1 sec timeout */
  983. /* Wait for the SPC Configuration Table to be ready */
  984. if (check_fw_ready(pm8001_ha) == -1) {
  985. regVal = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_1);
  986. /* return error if MPI Configuration Table not ready */
  987. PM8001_INIT_DBG(pm8001_ha,
  988. pm8001_printk("FW not ready SCRATCH_PAD1"
  989. " = 0x%x\n", regVal));
  990. regVal = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_2);
  991. /* return error if MPI Configuration Table not ready */
  992. PM8001_INIT_DBG(pm8001_ha,
  993. pm8001_printk("FW not ready SCRATCH_PAD2"
  994. " = 0x%x\n", regVal));
  995. PM8001_INIT_DBG(pm8001_ha,
  996. pm8001_printk("SCRATCH_PAD0 value = 0x%x\n",
  997. pm8001_cr32(pm8001_ha, 0,
  998. MSGU_SCRATCH_PAD_0)));
  999. PM8001_INIT_DBG(pm8001_ha,
  1000. pm8001_printk("SCRATCH_PAD3 value = 0x%x\n",
  1001. pm8001_cr32(pm8001_ha, 0,
  1002. MSGU_SCRATCH_PAD_3)));
  1003. spin_unlock_irqrestore(&pm8001_ha->lock, flags);
  1004. return -1;
  1005. }
  1006. }
  1007. pm8001_bar4_shift(pm8001_ha, 0);
  1008. spin_unlock_irqrestore(&pm8001_ha->lock, flags);
  1009. PM8001_INIT_DBG(pm8001_ha,
  1010. pm8001_printk("SPC soft reset Complete\n"));
  1011. return 0;
  1012. }
  1013. static void pm8001_hw_chip_rst(struct pm8001_hba_info *pm8001_ha)
  1014. {
  1015. u32 i;
  1016. u32 regVal;
  1017. PM8001_INIT_DBG(pm8001_ha,
  1018. pm8001_printk("chip reset start\n"));
  1019. /* do SPC chip reset. */
  1020. regVal = pm8001_cr32(pm8001_ha, 1, SPC_REG_RESET);
  1021. regVal &= ~(SPC_REG_RESET_DEVICE);
  1022. pm8001_cw32(pm8001_ha, 1, SPC_REG_RESET, regVal);
  1023. /* delay 10 usec */
  1024. udelay(10);
  1025. /* bring chip reset out of reset */
  1026. regVal = pm8001_cr32(pm8001_ha, 1, SPC_REG_RESET);
  1027. regVal |= SPC_REG_RESET_DEVICE;
  1028. pm8001_cw32(pm8001_ha, 1, SPC_REG_RESET, regVal);
  1029. /* delay 10 usec */
  1030. udelay(10);
  1031. /* wait for 20 msec until the firmware gets reloaded */
  1032. i = 20;
  1033. do {
  1034. mdelay(1);
  1035. } while ((--i) != 0);
  1036. PM8001_INIT_DBG(pm8001_ha,
  1037. pm8001_printk("chip reset finished\n"));
  1038. }
  1039. /**
  1040. * pm8001_chip_iounmap - which maped when initialized.
  1041. * @pm8001_ha: our hba card information
  1042. */
  1043. static void pm8001_chip_iounmap(struct pm8001_hba_info *pm8001_ha)
  1044. {
  1045. s8 bar, logical = 0;
  1046. for (bar = 0; bar < 6; bar++) {
  1047. /*
  1048. ** logical BARs for SPC:
  1049. ** bar 0 and 1 - logical BAR0
  1050. ** bar 2 and 3 - logical BAR1
  1051. ** bar4 - logical BAR2
  1052. ** bar5 - logical BAR3
  1053. ** Skip the appropriate assignments:
  1054. */
  1055. if ((bar == 1) || (bar == 3))
  1056. continue;
  1057. if (pm8001_ha->io_mem[logical].memvirtaddr) {
  1058. iounmap(pm8001_ha->io_mem[logical].memvirtaddr);
  1059. logical++;
  1060. }
  1061. }
  1062. }
  1063. /**
  1064. * pm8001_chip_interrupt_enable - enable PM8001 chip interrupt
  1065. * @pm8001_ha: our hba card information
  1066. */
  1067. static void
  1068. pm8001_chip_intx_interrupt_enable(struct pm8001_hba_info *pm8001_ha)
  1069. {
  1070. pm8001_cw32(pm8001_ha, 0, MSGU_ODMR, ODMR_CLEAR_ALL);
  1071. pm8001_cw32(pm8001_ha, 0, MSGU_ODCR, ODCR_CLEAR_ALL);
  1072. }
  1073. /**
  1074. * pm8001_chip_intx_interrupt_disable- disable PM8001 chip interrupt
  1075. * @pm8001_ha: our hba card information
  1076. */
  1077. static void
  1078. pm8001_chip_intx_interrupt_disable(struct pm8001_hba_info *pm8001_ha)
  1079. {
  1080. pm8001_cw32(pm8001_ha, 0, MSGU_ODMR, ODMR_MASK_ALL);
  1081. }
  1082. /**
  1083. * pm8001_chip_msix_interrupt_enable - enable PM8001 chip interrupt
  1084. * @pm8001_ha: our hba card information
  1085. */
  1086. static void
  1087. pm8001_chip_msix_interrupt_enable(struct pm8001_hba_info *pm8001_ha,
  1088. u32 int_vec_idx)
  1089. {
  1090. u32 msi_index;
  1091. u32 value;
  1092. msi_index = int_vec_idx * MSIX_TABLE_ELEMENT_SIZE;
  1093. msi_index += MSIX_TABLE_BASE;
  1094. pm8001_cw32(pm8001_ha, 0, msi_index, MSIX_INTERRUPT_ENABLE);
  1095. value = (1 << int_vec_idx);
  1096. pm8001_cw32(pm8001_ha, 0, MSGU_ODCR, value);
  1097. }
  1098. /**
  1099. * pm8001_chip_msix_interrupt_disable - disable PM8001 chip interrupt
  1100. * @pm8001_ha: our hba card information
  1101. */
  1102. static void
  1103. pm8001_chip_msix_interrupt_disable(struct pm8001_hba_info *pm8001_ha,
  1104. u32 int_vec_idx)
  1105. {
  1106. u32 msi_index;
  1107. msi_index = int_vec_idx * MSIX_TABLE_ELEMENT_SIZE;
  1108. msi_index += MSIX_TABLE_BASE;
  1109. pm8001_cw32(pm8001_ha, 0, msi_index, MSIX_INTERRUPT_DISABLE);
  1110. }
  1111. /**
  1112. * pm8001_chip_interrupt_enable - enable PM8001 chip interrupt
  1113. * @pm8001_ha: our hba card information
  1114. */
  1115. static void
  1116. pm8001_chip_interrupt_enable(struct pm8001_hba_info *pm8001_ha)
  1117. {
  1118. #ifdef PM8001_USE_MSIX
  1119. pm8001_chip_msix_interrupt_enable(pm8001_ha, 0);
  1120. return;
  1121. #endif
  1122. pm8001_chip_intx_interrupt_enable(pm8001_ha);
  1123. }
  1124. /**
  1125. * pm8001_chip_intx_interrupt_disable- disable PM8001 chip interrupt
  1126. * @pm8001_ha: our hba card information
  1127. */
  1128. static void
  1129. pm8001_chip_interrupt_disable(struct pm8001_hba_info *pm8001_ha)
  1130. {
  1131. #ifdef PM8001_USE_MSIX
  1132. pm8001_chip_msix_interrupt_disable(pm8001_ha, 0);
  1133. return;
  1134. #endif
  1135. pm8001_chip_intx_interrupt_disable(pm8001_ha);
  1136. }
  1137. /**
  1138. * mpi_msg_free_get- get the free message buffer for transfer inbound queue.
  1139. * @circularQ: the inbound queue we want to transfer to HBA.
  1140. * @messageSize: the message size of this transfer, normally it is 64 bytes
  1141. * @messagePtr: the pointer to message.
  1142. */
  1143. static int mpi_msg_free_get(struct inbound_queue_table *circularQ,
  1144. u16 messageSize, void **messagePtr)
  1145. {
  1146. u32 offset, consumer_index;
  1147. struct mpi_msg_hdr *msgHeader;
  1148. u8 bcCount = 1; /* only support single buffer */
  1149. /* Checks is the requested message size can be allocated in this queue*/
  1150. if (messageSize > 64) {
  1151. *messagePtr = NULL;
  1152. return -1;
  1153. }
  1154. /* Stores the new consumer index */
  1155. consumer_index = pm8001_read_32(circularQ->ci_virt);
  1156. circularQ->consumer_index = cpu_to_le32(consumer_index);
  1157. if (((circularQ->producer_idx + bcCount) % 256) ==
  1158. le32_to_cpu(circularQ->consumer_index)) {
  1159. *messagePtr = NULL;
  1160. return -1;
  1161. }
  1162. /* get memory IOMB buffer address */
  1163. offset = circularQ->producer_idx * 64;
  1164. /* increment to next bcCount element */
  1165. circularQ->producer_idx = (circularQ->producer_idx + bcCount) % 256;
  1166. /* Adds that distance to the base of the region virtual address plus
  1167. the message header size*/
  1168. msgHeader = (struct mpi_msg_hdr *)(circularQ->base_virt + offset);
  1169. *messagePtr = ((void *)msgHeader) + sizeof(struct mpi_msg_hdr);
  1170. return 0;
  1171. }
  1172. /**
  1173. * mpi_build_cmd- build the message queue for transfer, update the PI to FW
  1174. * to tell the fw to get this message from IOMB.
  1175. * @pm8001_ha: our hba card information
  1176. * @circularQ: the inbound queue we want to transfer to HBA.
  1177. * @opCode: the operation code represents commands which LLDD and fw recognized.
  1178. * @payload: the command payload of each operation command.
  1179. */
  1180. static int mpi_build_cmd(struct pm8001_hba_info *pm8001_ha,
  1181. struct inbound_queue_table *circularQ,
  1182. u32 opCode, void *payload)
  1183. {
  1184. u32 Header = 0, hpriority = 0, bc = 1, category = 0x02;
  1185. u32 responseQueue = 0;
  1186. void *pMessage;
  1187. if (mpi_msg_free_get(circularQ, 64, &pMessage) < 0) {
  1188. PM8001_IO_DBG(pm8001_ha,
  1189. pm8001_printk("No free mpi buffer\n"));
  1190. return -1;
  1191. }
  1192. BUG_ON(!payload);
  1193. /*Copy to the payload*/
  1194. memcpy(pMessage, payload, (64 - sizeof(struct mpi_msg_hdr)));
  1195. /*Build the header*/
  1196. Header = ((1 << 31) | (hpriority << 30) | ((bc & 0x1f) << 24)
  1197. | ((responseQueue & 0x3F) << 16)
  1198. | ((category & 0xF) << 12) | (opCode & 0xFFF));
  1199. pm8001_write_32((pMessage - 4), 0, cpu_to_le32(Header));
  1200. /*Update the PI to the firmware*/
  1201. pm8001_cw32(pm8001_ha, circularQ->pi_pci_bar,
  1202. circularQ->pi_offset, circularQ->producer_idx);
  1203. PM8001_IO_DBG(pm8001_ha,
  1204. pm8001_printk("after PI= %d CI= %d\n", circularQ->producer_idx,
  1205. circularQ->consumer_index));
  1206. return 0;
  1207. }
  1208. static u32 mpi_msg_free_set(struct pm8001_hba_info *pm8001_ha, void *pMsg,
  1209. struct outbound_queue_table *circularQ, u8 bc)
  1210. {
  1211. u32 producer_index;
  1212. struct mpi_msg_hdr *msgHeader;
  1213. struct mpi_msg_hdr *pOutBoundMsgHeader;
  1214. msgHeader = (struct mpi_msg_hdr *)(pMsg - sizeof(struct mpi_msg_hdr));
  1215. pOutBoundMsgHeader = (struct mpi_msg_hdr *)(circularQ->base_virt +
  1216. circularQ->consumer_idx * 64);
  1217. if (pOutBoundMsgHeader != msgHeader) {
  1218. PM8001_FAIL_DBG(pm8001_ha,
  1219. pm8001_printk("consumer_idx = %d msgHeader = %p\n",
  1220. circularQ->consumer_idx, msgHeader));
  1221. /* Update the producer index from SPC */
  1222. producer_index = pm8001_read_32(circularQ->pi_virt);
  1223. circularQ->producer_index = cpu_to_le32(producer_index);
  1224. PM8001_FAIL_DBG(pm8001_ha,
  1225. pm8001_printk("consumer_idx = %d producer_index = %d"
  1226. "msgHeader = %p\n", circularQ->consumer_idx,
  1227. circularQ->producer_index, msgHeader));
  1228. return 0;
  1229. }
  1230. /* free the circular queue buffer elements associated with the message*/
  1231. circularQ->consumer_idx = (circularQ->consumer_idx + bc) % 256;
  1232. /* update the CI of outbound queue */
  1233. pm8001_cw32(pm8001_ha, circularQ->ci_pci_bar, circularQ->ci_offset,
  1234. circularQ->consumer_idx);
  1235. /* Update the producer index from SPC*/
  1236. producer_index = pm8001_read_32(circularQ->pi_virt);
  1237. circularQ->producer_index = cpu_to_le32(producer_index);
  1238. PM8001_IO_DBG(pm8001_ha,
  1239. pm8001_printk(" CI=%d PI=%d\n", circularQ->consumer_idx,
  1240. circularQ->producer_index));
  1241. return 0;
  1242. }
  1243. /**
  1244. * mpi_msg_consume- get the MPI message from outbound queue message table.
  1245. * @pm8001_ha: our hba card information
  1246. * @circularQ: the outbound queue table.
  1247. * @messagePtr1: the message contents of this outbound message.
  1248. * @pBC: the message size.
  1249. */
  1250. static u32 mpi_msg_consume(struct pm8001_hba_info *pm8001_ha,
  1251. struct outbound_queue_table *circularQ,
  1252. void **messagePtr1, u8 *pBC)
  1253. {
  1254. struct mpi_msg_hdr *msgHeader;
  1255. __le32 msgHeader_tmp;
  1256. u32 header_tmp;
  1257. do {
  1258. /* If there are not-yet-delivered messages ... */
  1259. if (le32_to_cpu(circularQ->producer_index)
  1260. != circularQ->consumer_idx) {
  1261. /*Get the pointer to the circular queue buffer element*/
  1262. msgHeader = (struct mpi_msg_hdr *)
  1263. (circularQ->base_virt +
  1264. circularQ->consumer_idx * 64);
  1265. /* read header */
  1266. header_tmp = pm8001_read_32(msgHeader);
  1267. msgHeader_tmp = cpu_to_le32(header_tmp);
  1268. if (0 != (le32_to_cpu(msgHeader_tmp) & 0x80000000)) {
  1269. if (OPC_OUB_SKIP_ENTRY !=
  1270. (le32_to_cpu(msgHeader_tmp) & 0xfff)) {
  1271. *messagePtr1 =
  1272. ((u8 *)msgHeader) +
  1273. sizeof(struct mpi_msg_hdr);
  1274. *pBC = (u8)((le32_to_cpu(msgHeader_tmp)
  1275. >> 24) & 0x1f);
  1276. PM8001_IO_DBG(pm8001_ha,
  1277. pm8001_printk(": CI=%d PI=%d "
  1278. "msgHeader=%x\n",
  1279. circularQ->consumer_idx,
  1280. circularQ->producer_index,
  1281. msgHeader_tmp));
  1282. return MPI_IO_STATUS_SUCCESS;
  1283. } else {
  1284. circularQ->consumer_idx =
  1285. (circularQ->consumer_idx +
  1286. ((le32_to_cpu(msgHeader_tmp)
  1287. >> 24) & 0x1f)) % 256;
  1288. msgHeader_tmp = 0;
  1289. pm8001_write_32(msgHeader, 0, 0);
  1290. /* update the CI of outbound queue */
  1291. pm8001_cw32(pm8001_ha,
  1292. circularQ->ci_pci_bar,
  1293. circularQ->ci_offset,
  1294. circularQ->consumer_idx);
  1295. }
  1296. } else {
  1297. circularQ->consumer_idx =
  1298. (circularQ->consumer_idx +
  1299. ((le32_to_cpu(msgHeader_tmp) >> 24) &
  1300. 0x1f)) % 256;
  1301. msgHeader_tmp = 0;
  1302. pm8001_write_32(msgHeader, 0, 0);
  1303. /* update the CI of outbound queue */
  1304. pm8001_cw32(pm8001_ha, circularQ->ci_pci_bar,
  1305. circularQ->ci_offset,
  1306. circularQ->consumer_idx);
  1307. return MPI_IO_STATUS_FAIL;
  1308. }
  1309. } else {
  1310. u32 producer_index;
  1311. void *pi_virt = circularQ->pi_virt;
  1312. /* Update the producer index from SPC */
  1313. producer_index = pm8001_read_32(pi_virt);
  1314. circularQ->producer_index = cpu_to_le32(producer_index);
  1315. }
  1316. } while (le32_to_cpu(circularQ->producer_index) !=
  1317. circularQ->consumer_idx);
  1318. /* while we don't have any more not-yet-delivered message */
  1319. /* report empty */
  1320. return MPI_IO_STATUS_BUSY;
  1321. }
  1322. static void pm8001_work_fn(struct work_struct *work)
  1323. {
  1324. struct pm8001_work *pw = container_of(work, struct pm8001_work, work);
  1325. struct pm8001_device *pm8001_dev;
  1326. struct domain_device *dev;
  1327. /*
  1328. * So far, all users of this stash an associated structure here.
  1329. * If we get here, and this pointer is null, then the action
  1330. * was cancelled. This nullification happens when the device
  1331. * goes away.
  1332. */
  1333. pm8001_dev = pw->data; /* Most stash device structure */
  1334. if ((pm8001_dev == NULL)
  1335. || ((pw->handler != IO_XFER_ERROR_BREAK)
  1336. && (pm8001_dev->dev_type == NO_DEVICE))) {
  1337. kfree(pw);
  1338. return;
  1339. }
  1340. switch (pw->handler) {
  1341. case IO_XFER_ERROR_BREAK:
  1342. { /* This one stashes the sas_task instead */
  1343. struct sas_task *t = (struct sas_task *)pm8001_dev;
  1344. u32 tag;
  1345. struct pm8001_ccb_info *ccb;
  1346. struct pm8001_hba_info *pm8001_ha = pw->pm8001_ha;
  1347. unsigned long flags, flags1;
  1348. struct task_status_struct *ts;
  1349. int i;
  1350. if (pm8001_query_task(t) == TMF_RESP_FUNC_SUCC)
  1351. break; /* Task still on lu */
  1352. spin_lock_irqsave(&pm8001_ha->lock, flags);
  1353. spin_lock_irqsave(&t->task_state_lock, flags1);
  1354. if (unlikely((t->task_state_flags & SAS_TASK_STATE_DONE))) {
  1355. spin_unlock_irqrestore(&t->task_state_lock, flags1);
  1356. spin_unlock_irqrestore(&pm8001_ha->lock, flags);
  1357. break; /* Task got completed by another */
  1358. }
  1359. spin_unlock_irqrestore(&t->task_state_lock, flags1);
  1360. /* Search for a possible ccb that matches the task */
  1361. for (i = 0; ccb = NULL, i < PM8001_MAX_CCB; i++) {
  1362. ccb = &pm8001_ha->ccb_info[i];
  1363. tag = ccb->ccb_tag;
  1364. if ((tag != 0xFFFFFFFF) && (ccb->task == t))
  1365. break;
  1366. }
  1367. if (!ccb) {
  1368. spin_unlock_irqrestore(&pm8001_ha->lock, flags);
  1369. break; /* Task got freed by another */
  1370. }
  1371. ts = &t->task_status;
  1372. ts->resp = SAS_TASK_COMPLETE;
  1373. /* Force the midlayer to retry */
  1374. ts->stat = SAS_QUEUE_FULL;
  1375. pm8001_dev = ccb->device;
  1376. if (pm8001_dev)
  1377. pm8001_dev->running_req--;
  1378. spin_lock_irqsave(&t->task_state_lock, flags1);
  1379. t->task_state_flags &= ~SAS_TASK_STATE_PENDING;
  1380. t->task_state_flags &= ~SAS_TASK_AT_INITIATOR;
  1381. t->task_state_flags |= SAS_TASK_STATE_DONE;
  1382. if (unlikely((t->task_state_flags & SAS_TASK_STATE_ABORTED))) {
  1383. spin_unlock_irqrestore(&t->task_state_lock, flags1);
  1384. PM8001_FAIL_DBG(pm8001_ha, pm8001_printk("task 0x%p"
  1385. " done with event 0x%x resp 0x%x stat 0x%x but"
  1386. " aborted by upper layer!\n",
  1387. t, pw->handler, ts->resp, ts->stat));
  1388. pm8001_ccb_task_free(pm8001_ha, t, ccb, tag);
  1389. spin_unlock_irqrestore(&pm8001_ha->lock, flags);
  1390. } else {
  1391. spin_unlock_irqrestore(&t->task_state_lock, flags1);
  1392. pm8001_ccb_task_free(pm8001_ha, t, ccb, tag);
  1393. mb();/* in order to force CPU ordering */
  1394. spin_unlock_irqrestore(&pm8001_ha->lock, flags);
  1395. t->task_done(t);
  1396. }
  1397. } break;
  1398. case IO_XFER_OPEN_RETRY_TIMEOUT:
  1399. { /* This one stashes the sas_task instead */
  1400. struct sas_task *t = (struct sas_task *)pm8001_dev;
  1401. u32 tag;
  1402. struct pm8001_ccb_info *ccb;
  1403. struct pm8001_hba_info *pm8001_ha = pw->pm8001_ha;
  1404. unsigned long flags, flags1;
  1405. int i, ret = 0;
  1406. PM8001_IO_DBG(pm8001_ha,
  1407. pm8001_printk("IO_XFER_OPEN_RETRY_TIMEOUT\n"));
  1408. ret = pm8001_query_task(t);
  1409. PM8001_IO_DBG(pm8001_ha,
  1410. switch (ret) {
  1411. case TMF_RESP_FUNC_SUCC:
  1412. pm8001_printk("...Task on lu\n");
  1413. break;
  1414. case TMF_RESP_FUNC_COMPLETE:
  1415. pm8001_printk("...Task NOT on lu\n");
  1416. break;
  1417. default:
  1418. pm8001_printk("...query task failed!!!\n");
  1419. break;
  1420. });
  1421. spin_lock_irqsave(&pm8001_ha->lock, flags);
  1422. spin_lock_irqsave(&t->task_state_lock, flags1);
  1423. if (unlikely((t->task_state_flags & SAS_TASK_STATE_DONE))) {
  1424. spin_unlock_irqrestore(&t->task_state_lock, flags1);
  1425. spin_unlock_irqrestore(&pm8001_ha->lock, flags);
  1426. if (ret == TMF_RESP_FUNC_SUCC) /* task on lu */
  1427. (void)pm8001_abort_task(t);
  1428. break; /* Task got completed by another */
  1429. }
  1430. spin_unlock_irqrestore(&t->task_state_lock, flags1);
  1431. /* Search for a possible ccb that matches the task */
  1432. for (i = 0; ccb = NULL, i < PM8001_MAX_CCB; i++) {
  1433. ccb = &pm8001_ha->ccb_info[i];
  1434. tag = ccb->ccb_tag;
  1435. if ((tag != 0xFFFFFFFF) && (ccb->task == t))
  1436. break;
  1437. }
  1438. if (!ccb) {
  1439. spin_unlock_irqrestore(&pm8001_ha->lock, flags);
  1440. if (ret == TMF_RESP_FUNC_SUCC) /* task on lu */
  1441. (void)pm8001_abort_task(t);
  1442. break; /* Task got freed by another */
  1443. }
  1444. pm8001_dev = ccb->device;
  1445. dev = pm8001_dev->sas_device;
  1446. switch (ret) {
  1447. case TMF_RESP_FUNC_SUCC: /* task on lu */
  1448. ccb->open_retry = 1; /* Snub completion */
  1449. spin_unlock_irqrestore(&pm8001_ha->lock, flags);
  1450. ret = pm8001_abort_task(t);
  1451. ccb->open_retry = 0;
  1452. switch (ret) {
  1453. case TMF_RESP_FUNC_SUCC:
  1454. case TMF_RESP_FUNC_COMPLETE:
  1455. break;
  1456. default: /* device misbehavior */
  1457. ret = TMF_RESP_FUNC_FAILED;
  1458. PM8001_IO_DBG(pm8001_ha,
  1459. pm8001_printk("...Reset phy\n"));
  1460. pm8001_I_T_nexus_reset(dev);
  1461. break;
  1462. }
  1463. break;
  1464. case TMF_RESP_FUNC_COMPLETE: /* task not on lu */
  1465. spin_unlock_irqrestore(&pm8001_ha->lock, flags);
  1466. /* Do we need to abort the task locally? */
  1467. break;
  1468. default: /* device misbehavior */
  1469. spin_unlock_irqrestore(&pm8001_ha->lock, flags);
  1470. ret = TMF_RESP_FUNC_FAILED;
  1471. PM8001_IO_DBG(pm8001_ha,
  1472. pm8001_printk("...Reset phy\n"));
  1473. pm8001_I_T_nexus_reset(dev);
  1474. }
  1475. if (ret == TMF_RESP_FUNC_FAILED)
  1476. t = NULL;
  1477. pm8001_open_reject_retry(pm8001_ha, t, pm8001_dev);
  1478. PM8001_IO_DBG(pm8001_ha, pm8001_printk("...Complete\n"));
  1479. } break;
  1480. case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS:
  1481. dev = pm8001_dev->sas_device;
  1482. pm8001_I_T_nexus_reset(dev);
  1483. break;
  1484. case IO_OPEN_CNX_ERROR_STP_RESOURCES_BUSY:
  1485. dev = pm8001_dev->sas_device;
  1486. pm8001_I_T_nexus_reset(dev);
  1487. break;
  1488. case IO_DS_IN_ERROR:
  1489. dev = pm8001_dev->sas_device;
  1490. pm8001_I_T_nexus_reset(dev);
  1491. break;
  1492. case IO_DS_NON_OPERATIONAL:
  1493. dev = pm8001_dev->sas_device;
  1494. pm8001_I_T_nexus_reset(dev);
  1495. break;
  1496. }
  1497. kfree(pw);
  1498. }
  1499. static int pm8001_handle_event(struct pm8001_hba_info *pm8001_ha, void *data,
  1500. int handler)
  1501. {
  1502. struct pm8001_work *pw;
  1503. int ret = 0;
  1504. pw = kmalloc(sizeof(struct pm8001_work), GFP_ATOMIC);
  1505. if (pw) {
  1506. pw->pm8001_ha = pm8001_ha;
  1507. pw->data = data;
  1508. pw->handler = handler;
  1509. INIT_WORK(&pw->work, pm8001_work_fn);
  1510. queue_work(pm8001_wq, &pw->work);
  1511. } else
  1512. ret = -ENOMEM;
  1513. return ret;
  1514. }
  1515. /**
  1516. * mpi_ssp_completion- process the event that FW response to the SSP request.
  1517. * @pm8001_ha: our hba card information
  1518. * @piomb: the message contents of this outbound message.
  1519. *
  1520. * When FW has completed a ssp request for example a IO request, after it has
  1521. * filled the SG data with the data, it will trigger this event represent
  1522. * that he has finished the job,please check the coresponding buffer.
  1523. * So we will tell the caller who maybe waiting the result to tell upper layer
  1524. * that the task has been finished.
  1525. */
  1526. static void
  1527. mpi_ssp_completion(struct pm8001_hba_info *pm8001_ha , void *piomb)
  1528. {
  1529. struct sas_task *t;
  1530. struct pm8001_ccb_info *ccb;
  1531. unsigned long flags;
  1532. u32 status;
  1533. u32 param;
  1534. u32 tag;
  1535. struct ssp_completion_resp *psspPayload;
  1536. struct task_status_struct *ts;
  1537. struct ssp_response_iu *iu;
  1538. struct pm8001_device *pm8001_dev;
  1539. psspPayload = (struct ssp_completion_resp *)(piomb + 4);
  1540. status = le32_to_cpu(psspPayload->status);
  1541. tag = le32_to_cpu(psspPayload->tag);
  1542. ccb = &pm8001_ha->ccb_info[tag];
  1543. if ((status == IO_ABORTED) && ccb->open_retry) {
  1544. /* Being completed by another */
  1545. ccb->open_retry = 0;
  1546. return;
  1547. }
  1548. pm8001_dev = ccb->device;
  1549. param = le32_to_cpu(psspPayload->param);
  1550. t = ccb->task;
  1551. if (status && status != IO_UNDERFLOW)
  1552. PM8001_FAIL_DBG(pm8001_ha,
  1553. pm8001_printk("sas IO status 0x%x\n", status));
  1554. if (unlikely(!t || !t->lldd_task || !t->dev))
  1555. return;
  1556. ts = &t->task_status;
  1557. switch (status) {
  1558. case IO_SUCCESS:
  1559. PM8001_IO_DBG(pm8001_ha, pm8001_printk("IO_SUCCESS"
  1560. ",param = %d\n", param));
  1561. if (param == 0) {
  1562. ts->resp = SAS_TASK_COMPLETE;
  1563. ts->stat = SAM_STAT_GOOD;
  1564. } else {
  1565. ts->resp = SAS_TASK_COMPLETE;
  1566. ts->stat = SAS_PROTO_RESPONSE;
  1567. ts->residual = param;
  1568. iu = &psspPayload->ssp_resp_iu;
  1569. sas_ssp_task_response(pm8001_ha->dev, t, iu);
  1570. }
  1571. if (pm8001_dev)
  1572. pm8001_dev->running_req--;
  1573. break;
  1574. case IO_ABORTED:
  1575. PM8001_IO_DBG(pm8001_ha,
  1576. pm8001_printk("IO_ABORTED IOMB Tag\n"));
  1577. ts->resp = SAS_TASK_COMPLETE;
  1578. ts->stat = SAS_ABORTED_TASK;
  1579. break;
  1580. case IO_UNDERFLOW:
  1581. /* SSP Completion with error */
  1582. PM8001_IO_DBG(pm8001_ha, pm8001_printk("IO_UNDERFLOW"
  1583. ",param = %d\n", param));
  1584. ts->resp = SAS_TASK_COMPLETE;
  1585. ts->stat = SAS_DATA_UNDERRUN;
  1586. ts->residual = param;
  1587. if (pm8001_dev)
  1588. pm8001_dev->running_req--;
  1589. break;
  1590. case IO_NO_DEVICE:
  1591. PM8001_IO_DBG(pm8001_ha,
  1592. pm8001_printk("IO_NO_DEVICE\n"));
  1593. ts->resp = SAS_TASK_UNDELIVERED;
  1594. ts->stat = SAS_PHY_DOWN;
  1595. break;
  1596. case IO_XFER_ERROR_BREAK:
  1597. PM8001_IO_DBG(pm8001_ha,
  1598. pm8001_printk("IO_XFER_ERROR_BREAK\n"));
  1599. ts->resp = SAS_TASK_COMPLETE;
  1600. ts->stat = SAS_OPEN_REJECT;
  1601. /* Force the midlayer to retry */
  1602. ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
  1603. break;
  1604. case IO_XFER_ERROR_PHY_NOT_READY:
  1605. PM8001_IO_DBG(pm8001_ha,
  1606. pm8001_printk("IO_XFER_ERROR_PHY_NOT_READY\n"));
  1607. ts->resp = SAS_TASK_COMPLETE;
  1608. ts->stat = SAS_OPEN_REJECT;
  1609. ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
  1610. break;
  1611. case IO_OPEN_CNX_ERROR_PROTOCOL_NOT_SUPPORTED:
  1612. PM8001_IO_DBG(pm8001_ha,
  1613. pm8001_printk("IO_OPEN_CNX_ERROR_PROTOCOL_NOT_SUPPORTED\n"));
  1614. ts->resp = SAS_TASK_COMPLETE;
  1615. ts->stat = SAS_OPEN_REJECT;
  1616. ts->open_rej_reason = SAS_OREJ_EPROTO;
  1617. break;
  1618. case IO_OPEN_CNX_ERROR_ZONE_VIOLATION:
  1619. PM8001_IO_DBG(pm8001_ha,
  1620. pm8001_printk("IO_OPEN_CNX_ERROR_ZONE_VIOLATION\n"));
  1621. ts->resp = SAS_TASK_COMPLETE;
  1622. ts->stat = SAS_OPEN_REJECT;
  1623. ts->open_rej_reason = SAS_OREJ_UNKNOWN;
  1624. break;
  1625. case IO_OPEN_CNX_ERROR_BREAK:
  1626. PM8001_IO_DBG(pm8001_ha,
  1627. pm8001_printk("IO_OPEN_CNX_ERROR_BREAK\n"));
  1628. ts->resp = SAS_TASK_COMPLETE;
  1629. ts->stat = SAS_OPEN_REJECT;
  1630. ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
  1631. break;
  1632. case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS:
  1633. PM8001_IO_DBG(pm8001_ha,
  1634. pm8001_printk("IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS\n"));
  1635. ts->resp = SAS_TASK_COMPLETE;
  1636. ts->stat = SAS_OPEN_REJECT;
  1637. ts->open_rej_reason = SAS_OREJ_UNKNOWN;
  1638. if (!t->uldd_task)
  1639. pm8001_handle_event(pm8001_ha,
  1640. pm8001_dev,
  1641. IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS);
  1642. break;
  1643. case IO_OPEN_CNX_ERROR_BAD_DESTINATION:
  1644. PM8001_IO_DBG(pm8001_ha,
  1645. pm8001_printk("IO_OPEN_CNX_ERROR_BAD_DESTINATION\n"));
  1646. ts->resp = SAS_TASK_COMPLETE;
  1647. ts->stat = SAS_OPEN_REJECT;
  1648. ts->open_rej_reason = SAS_OREJ_BAD_DEST;
  1649. break;
  1650. case IO_OPEN_CNX_ERROR_CONNECTION_RATE_NOT_SUPPORTED:
  1651. PM8001_IO_DBG(pm8001_ha,
  1652. pm8001_printk("IO_OPEN_CNX_ERROR_CONNECTION_RATE_"
  1653. "NOT_SUPPORTED\n"));
  1654. ts->resp = SAS_TASK_COMPLETE;
  1655. ts->stat = SAS_OPEN_REJECT;
  1656. ts->open_rej_reason = SAS_OREJ_CONN_RATE;
  1657. break;
  1658. case IO_OPEN_CNX_ERROR_WRONG_DESTINATION:
  1659. PM8001_IO_DBG(pm8001_ha,
  1660. pm8001_printk("IO_OPEN_CNX_ERROR_WRONG_DESTINATION\n"));
  1661. ts->resp = SAS_TASK_UNDELIVERED;
  1662. ts->stat = SAS_OPEN_REJECT;
  1663. ts->open_rej_reason = SAS_OREJ_WRONG_DEST;
  1664. break;
  1665. case IO_XFER_ERROR_NAK_RECEIVED:
  1666. PM8001_IO_DBG(pm8001_ha,
  1667. pm8001_printk("IO_XFER_ERROR_NAK_RECEIVED\n"));
  1668. ts->resp = SAS_TASK_COMPLETE;
  1669. ts->stat = SAS_OPEN_REJECT;
  1670. ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
  1671. break;
  1672. case IO_XFER_ERROR_ACK_NAK_TIMEOUT:
  1673. PM8001_IO_DBG(pm8001_ha,
  1674. pm8001_printk("IO_XFER_ERROR_ACK_NAK_TIMEOUT\n"));
  1675. ts->resp = SAS_TASK_COMPLETE;
  1676. ts->stat = SAS_NAK_R_ERR;
  1677. break;
  1678. case IO_XFER_ERROR_DMA:
  1679. PM8001_IO_DBG(pm8001_ha,
  1680. pm8001_printk("IO_XFER_ERROR_DMA\n"));
  1681. ts->resp = SAS_TASK_COMPLETE;
  1682. ts->stat = SAS_OPEN_REJECT;
  1683. break;
  1684. case IO_XFER_OPEN_RETRY_TIMEOUT:
  1685. PM8001_IO_DBG(pm8001_ha,
  1686. pm8001_printk("IO_XFER_OPEN_RETRY_TIMEOUT\n"));
  1687. ts->resp = SAS_TASK_COMPLETE;
  1688. ts->stat = SAS_OPEN_REJECT;
  1689. ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
  1690. break;
  1691. case IO_XFER_ERROR_OFFSET_MISMATCH:
  1692. PM8001_IO_DBG(pm8001_ha,
  1693. pm8001_printk("IO_XFER_ERROR_OFFSET_MISMATCH\n"));
  1694. ts->resp = SAS_TASK_COMPLETE;
  1695. ts->stat = SAS_OPEN_REJECT;
  1696. break;
  1697. case IO_PORT_IN_RESET:
  1698. PM8001_IO_DBG(pm8001_ha,
  1699. pm8001_printk("IO_PORT_IN_RESET\n"));
  1700. ts->resp = SAS_TASK_COMPLETE;
  1701. ts->stat = SAS_OPEN_REJECT;
  1702. break;
  1703. case IO_DS_NON_OPERATIONAL:
  1704. PM8001_IO_DBG(pm8001_ha,
  1705. pm8001_printk("IO_DS_NON_OPERATIONAL\n"));
  1706. ts->resp = SAS_TASK_COMPLETE;
  1707. ts->stat = SAS_OPEN_REJECT;
  1708. if (!t->uldd_task)
  1709. pm8001_handle_event(pm8001_ha,
  1710. pm8001_dev,
  1711. IO_DS_NON_OPERATIONAL);
  1712. break;
  1713. case IO_DS_IN_RECOVERY:
  1714. PM8001_IO_DBG(pm8001_ha,
  1715. pm8001_printk("IO_DS_IN_RECOVERY\n"));
  1716. ts->resp = SAS_TASK_COMPLETE;
  1717. ts->stat = SAS_OPEN_REJECT;
  1718. break;
  1719. case IO_TM_TAG_NOT_FOUND:
  1720. PM8001_IO_DBG(pm8001_ha,
  1721. pm8001_printk("IO_TM_TAG_NOT_FOUND\n"));
  1722. ts->resp = SAS_TASK_COMPLETE;
  1723. ts->stat = SAS_OPEN_REJECT;
  1724. break;
  1725. case IO_SSP_EXT_IU_ZERO_LEN_ERROR:
  1726. PM8001_IO_DBG(pm8001_ha,
  1727. pm8001_printk("IO_SSP_EXT_IU_ZERO_LEN_ERROR\n"));
  1728. ts->resp = SAS_TASK_COMPLETE;
  1729. ts->stat = SAS_OPEN_REJECT;
  1730. break;
  1731. case IO_OPEN_CNX_ERROR_HW_RESOURCE_BUSY:
  1732. PM8001_IO_DBG(pm8001_ha,
  1733. pm8001_printk("IO_OPEN_CNX_ERROR_HW_RESOURCE_BUSY\n"));
  1734. ts->resp = SAS_TASK_COMPLETE;
  1735. ts->stat = SAS_OPEN_REJECT;
  1736. ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
  1737. break;
  1738. default:
  1739. PM8001_IO_DBG(pm8001_ha,
  1740. pm8001_printk("Unknown status 0x%x\n", status));
  1741. /* not allowed case. Therefore, return failed status */
  1742. ts->resp = SAS_TASK_COMPLETE;
  1743. ts->stat = SAS_OPEN_REJECT;
  1744. break;
  1745. }
  1746. PM8001_IO_DBG(pm8001_ha,
  1747. pm8001_printk("scsi_status = %x \n ",
  1748. psspPayload->ssp_resp_iu.status));
  1749. spin_lock_irqsave(&t->task_state_lock, flags);
  1750. t->task_state_flags &= ~SAS_TASK_STATE_PENDING;
  1751. t->task_state_flags &= ~SAS_TASK_AT_INITIATOR;
  1752. t->task_state_flags |= SAS_TASK_STATE_DONE;
  1753. if (unlikely((t->task_state_flags & SAS_TASK_STATE_ABORTED))) {
  1754. spin_unlock_irqrestore(&t->task_state_lock, flags);
  1755. PM8001_FAIL_DBG(pm8001_ha, pm8001_printk("task 0x%p done with"
  1756. " io_status 0x%x resp 0x%x "
  1757. "stat 0x%x but aborted by upper layer!\n",
  1758. t, status, ts->resp, ts->stat));
  1759. pm8001_ccb_task_free(pm8001_ha, t, ccb, tag);
  1760. } else {
  1761. spin_unlock_irqrestore(&t->task_state_lock, flags);
  1762. pm8001_ccb_task_free(pm8001_ha, t, ccb, tag);
  1763. mb();/* in order to force CPU ordering */
  1764. t->task_done(t);
  1765. }
  1766. }
  1767. /*See the comments for mpi_ssp_completion */
  1768. static void mpi_ssp_event(struct pm8001_hba_info *pm8001_ha , void *piomb)
  1769. {
  1770. struct sas_task *t;
  1771. unsigned long flags;
  1772. struct task_status_struct *ts;
  1773. struct pm8001_ccb_info *ccb;
  1774. struct pm8001_device *pm8001_dev;
  1775. struct ssp_event_resp *psspPayload =
  1776. (struct ssp_event_resp *)(piomb + 4);
  1777. u32 event = le32_to_cpu(psspPayload->event);
  1778. u32 tag = le32_to_cpu(psspPayload->tag);
  1779. u32 port_id = le32_to_cpu(psspPayload->port_id);
  1780. u32 dev_id = le32_to_cpu(psspPayload->device_id);
  1781. ccb = &pm8001_ha->ccb_info[tag];
  1782. t = ccb->task;
  1783. pm8001_dev = ccb->device;
  1784. if (event)
  1785. PM8001_FAIL_DBG(pm8001_ha,
  1786. pm8001_printk("sas IO status 0x%x\n", event));
  1787. if (unlikely(!t || !t->lldd_task || !t->dev))
  1788. return;
  1789. ts = &t->task_status;
  1790. PM8001_IO_DBG(pm8001_ha,
  1791. pm8001_printk("port_id = %x,device_id = %x\n",
  1792. port_id, dev_id));
  1793. switch (event) {
  1794. case IO_OVERFLOW:
  1795. PM8001_IO_DBG(pm8001_ha, pm8001_printk("IO_UNDERFLOW\n");)
  1796. ts->resp = SAS_TASK_COMPLETE;
  1797. ts->stat = SAS_DATA_OVERRUN;
  1798. ts->residual = 0;
  1799. if (pm8001_dev)
  1800. pm8001_dev->running_req--;
  1801. break;
  1802. case IO_XFER_ERROR_BREAK:
  1803. PM8001_IO_DBG(pm8001_ha,
  1804. pm8001_printk("IO_XFER_ERROR_BREAK\n"));
  1805. pm8001_handle_event(pm8001_ha, t, IO_XFER_ERROR_BREAK);
  1806. return;
  1807. case IO_XFER_ERROR_PHY_NOT_READY:
  1808. PM8001_IO_DBG(pm8001_ha,
  1809. pm8001_printk("IO_XFER_ERROR_PHY_NOT_READY\n"));
  1810. ts->resp = SAS_TASK_COMPLETE;
  1811. ts->stat = SAS_OPEN_REJECT;
  1812. ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
  1813. break;
  1814. case IO_OPEN_CNX_ERROR_PROTOCOL_NOT_SUPPORTED:
  1815. PM8001_IO_DBG(pm8001_ha,
  1816. pm8001_printk("IO_OPEN_CNX_ERROR_PROTOCOL_NOT"
  1817. "_SUPPORTED\n"));
  1818. ts->resp = SAS_TASK_COMPLETE;
  1819. ts->stat = SAS_OPEN_REJECT;
  1820. ts->open_rej_reason = SAS_OREJ_EPROTO;
  1821. break;
  1822. case IO_OPEN_CNX_ERROR_ZONE_VIOLATION:
  1823. PM8001_IO_DBG(pm8001_ha,
  1824. pm8001_printk("IO_OPEN_CNX_ERROR_ZONE_VIOLATION\n"));
  1825. ts->resp = SAS_TASK_COMPLETE;
  1826. ts->stat = SAS_OPEN_REJECT;
  1827. ts->open_rej_reason = SAS_OREJ_UNKNOWN;
  1828. break;
  1829. case IO_OPEN_CNX_ERROR_BREAK:
  1830. PM8001_IO_DBG(pm8001_ha,
  1831. pm8001_printk("IO_OPEN_CNX_ERROR_BREAK\n"));
  1832. ts->resp = SAS_TASK_COMPLETE;
  1833. ts->stat = SAS_OPEN_REJECT;
  1834. ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
  1835. break;
  1836. case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS:
  1837. PM8001_IO_DBG(pm8001_ha,
  1838. pm8001_printk("IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS\n"));
  1839. ts->resp = SAS_TASK_COMPLETE;
  1840. ts->stat = SAS_OPEN_REJECT;
  1841. ts->open_rej_reason = SAS_OREJ_UNKNOWN;
  1842. if (!t->uldd_task)
  1843. pm8001_handle_event(pm8001_ha,
  1844. pm8001_dev,
  1845. IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS);
  1846. break;
  1847. case IO_OPEN_CNX_ERROR_BAD_DESTINATION:
  1848. PM8001_IO_DBG(pm8001_ha,
  1849. pm8001_printk("IO_OPEN_CNX_ERROR_BAD_DESTINATION\n"));
  1850. ts->resp = SAS_TASK_COMPLETE;
  1851. ts->stat = SAS_OPEN_REJECT;
  1852. ts->open_rej_reason = SAS_OREJ_BAD_DEST;
  1853. break;
  1854. case IO_OPEN_CNX_ERROR_CONNECTION_RATE_NOT_SUPPORTED:
  1855. PM8001_IO_DBG(pm8001_ha,
  1856. pm8001_printk("IO_OPEN_CNX_ERROR_CONNECTION_RATE_"
  1857. "NOT_SUPPORTED\n"));
  1858. ts->resp = SAS_TASK_COMPLETE;
  1859. ts->stat = SAS_OPEN_REJECT;
  1860. ts->open_rej_reason = SAS_OREJ_CONN_RATE;
  1861. break;
  1862. case IO_OPEN_CNX_ERROR_WRONG_DESTINATION:
  1863. PM8001_IO_DBG(pm8001_ha,
  1864. pm8001_printk("IO_OPEN_CNX_ERROR_WRONG_DESTINATION\n"));
  1865. ts->resp = SAS_TASK_COMPLETE;
  1866. ts->stat = SAS_OPEN_REJECT;
  1867. ts->open_rej_reason = SAS_OREJ_WRONG_DEST;
  1868. break;
  1869. case IO_XFER_ERROR_NAK_RECEIVED:
  1870. PM8001_IO_DBG(pm8001_ha,
  1871. pm8001_printk("IO_XFER_ERROR_NAK_RECEIVED\n"));
  1872. ts->resp = SAS_TASK_COMPLETE;
  1873. ts->stat = SAS_OPEN_REJECT;
  1874. ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
  1875. break;
  1876. case IO_XFER_ERROR_ACK_NAK_TIMEOUT:
  1877. PM8001_IO_DBG(pm8001_ha,
  1878. pm8001_printk("IO_XFER_ERROR_ACK_NAK_TIMEOUT\n"));
  1879. ts->resp = SAS_TASK_COMPLETE;
  1880. ts->stat = SAS_NAK_R_ERR;
  1881. break;
  1882. case IO_XFER_OPEN_RETRY_TIMEOUT:
  1883. PM8001_IO_DBG(pm8001_ha,
  1884. pm8001_printk("IO_XFER_OPEN_RETRY_TIMEOUT\n"));
  1885. pm8001_handle_event(pm8001_ha, t, IO_XFER_OPEN_RETRY_TIMEOUT);
  1886. return;
  1887. case IO_XFER_ERROR_UNEXPECTED_PHASE:
  1888. PM8001_IO_DBG(pm8001_ha,
  1889. pm8001_printk("IO_XFER_ERROR_UNEXPECTED_PHASE\n"));
  1890. ts->resp = SAS_TASK_COMPLETE;
  1891. ts->stat = SAS_DATA_OVERRUN;
  1892. break;
  1893. case IO_XFER_ERROR_XFER_RDY_OVERRUN:
  1894. PM8001_IO_DBG(pm8001_ha,
  1895. pm8001_printk("IO_XFER_ERROR_XFER_RDY_OVERRUN\n"));
  1896. ts->resp = SAS_TASK_COMPLETE;
  1897. ts->stat = SAS_DATA_OVERRUN;
  1898. break;
  1899. case IO_XFER_ERROR_XFER_RDY_NOT_EXPECTED:
  1900. PM8001_IO_DBG(pm8001_ha,
  1901. pm8001_printk("IO_XFER_ERROR_XFER_RDY_NOT_EXPECTED\n"));
  1902. ts->resp = SAS_TASK_COMPLETE;
  1903. ts->stat = SAS_DATA_OVERRUN;
  1904. break;
  1905. case IO_XFER_ERROR_CMD_ISSUE_ACK_NAK_TIMEOUT:
  1906. PM8001_IO_DBG(pm8001_ha,
  1907. pm8001_printk("IO_XFER_ERROR_CMD_ISSUE_ACK_NAK_TIMEOUT\n"));
  1908. ts->resp = SAS_TASK_COMPLETE;
  1909. ts->stat = SAS_DATA_OVERRUN;
  1910. break;
  1911. case IO_XFER_ERROR_OFFSET_MISMATCH:
  1912. PM8001_IO_DBG(pm8001_ha,
  1913. pm8001_printk("IO_XFER_ERROR_OFFSET_MISMATCH\n"));
  1914. ts->resp = SAS_TASK_COMPLETE;
  1915. ts->stat = SAS_DATA_OVERRUN;
  1916. break;
  1917. case IO_XFER_ERROR_XFER_ZERO_DATA_LEN:
  1918. PM8001_IO_DBG(pm8001_ha,
  1919. pm8001_printk("IO_XFER_ERROR_XFER_ZERO_DATA_LEN\n"));
  1920. ts->resp = SAS_TASK_COMPLETE;
  1921. ts->stat = SAS_DATA_OVERRUN;
  1922. break;
  1923. case IO_XFER_CMD_FRAME_ISSUED:
  1924. PM8001_IO_DBG(pm8001_ha,
  1925. pm8001_printk(" IO_XFER_CMD_FRAME_ISSUED\n"));
  1926. return;
  1927. default:
  1928. PM8001_IO_DBG(pm8001_ha,
  1929. pm8001_printk("Unknown status 0x%x\n", event));
  1930. /* not allowed case. Therefore, return failed status */
  1931. ts->resp = SAS_TASK_COMPLETE;
  1932. ts->stat = SAS_DATA_OVERRUN;
  1933. break;
  1934. }
  1935. spin_lock_irqsave(&t->task_state_lock, flags);
  1936. t->task_state_flags &= ~SAS_TASK_STATE_PENDING;
  1937. t->task_state_flags &= ~SAS_TASK_AT_INITIATOR;
  1938. t->task_state_flags |= SAS_TASK_STATE_DONE;
  1939. if (unlikely((t->task_state_flags & SAS_TASK_STATE_ABORTED))) {
  1940. spin_unlock_irqrestore(&t->task_state_lock, flags);
  1941. PM8001_FAIL_DBG(pm8001_ha, pm8001_printk("task 0x%p done with"
  1942. " event 0x%x resp 0x%x "
  1943. "stat 0x%x but aborted by upper layer!\n",
  1944. t, event, ts->resp, ts->stat));
  1945. pm8001_ccb_task_free(pm8001_ha, t, ccb, tag);
  1946. } else {
  1947. spin_unlock_irqrestore(&t->task_state_lock, flags);
  1948. pm8001_ccb_task_free(pm8001_ha, t, ccb, tag);
  1949. mb();/* in order to force CPU ordering */
  1950. t->task_done(t);
  1951. }
  1952. }
  1953. /*See the comments for mpi_ssp_completion */
  1954. static void
  1955. mpi_sata_completion(struct pm8001_hba_info *pm8001_ha, void *piomb)
  1956. {
  1957. struct sas_task *t;
  1958. struct pm8001_ccb_info *ccb;
  1959. u32 param;
  1960. u32 status;
  1961. u32 tag;
  1962. struct sata_completion_resp *psataPayload;
  1963. struct task_status_struct *ts;
  1964. struct ata_task_resp *resp ;
  1965. u32 *sata_resp;
  1966. struct pm8001_device *pm8001_dev;
  1967. unsigned long flags;
  1968. psataPayload = (struct sata_completion_resp *)(piomb + 4);
  1969. status = le32_to_cpu(psataPayload->status);
  1970. tag = le32_to_cpu(psataPayload->tag);
  1971. ccb = &pm8001_ha->ccb_info[tag];
  1972. param = le32_to_cpu(psataPayload->param);
  1973. t = ccb->task;
  1974. ts = &t->task_status;
  1975. pm8001_dev = ccb->device;
  1976. if (status)
  1977. PM8001_FAIL_DBG(pm8001_ha,
  1978. pm8001_printk("sata IO status 0x%x\n", status));
  1979. if (unlikely(!t || !t->lldd_task || !t->dev))
  1980. return;
  1981. switch (status) {
  1982. case IO_SUCCESS:
  1983. PM8001_IO_DBG(pm8001_ha, pm8001_printk("IO_SUCCESS\n"));
  1984. if (param == 0) {
  1985. ts->resp = SAS_TASK_COMPLETE;
  1986. ts->stat = SAM_STAT_GOOD;
  1987. } else {
  1988. u8 len;
  1989. ts->resp = SAS_TASK_COMPLETE;
  1990. ts->stat = SAS_PROTO_RESPONSE;
  1991. ts->residual = param;
  1992. PM8001_IO_DBG(pm8001_ha,
  1993. pm8001_printk("SAS_PROTO_RESPONSE len = %d\n",
  1994. param));
  1995. sata_resp = &psataPayload->sata_resp[0];
  1996. resp = (struct ata_task_resp *)ts->buf;
  1997. if (t->ata_task.dma_xfer == 0 &&
  1998. t->data_dir == PCI_DMA_FROMDEVICE) {
  1999. len = sizeof(struct pio_setup_fis);
  2000. PM8001_IO_DBG(pm8001_ha,
  2001. pm8001_printk("PIO read len = %d\n", len));
  2002. } else if (t->ata_task.use_ncq) {
  2003. len = sizeof(struct set_dev_bits_fis);
  2004. PM8001_IO_DBG(pm8001_ha,
  2005. pm8001_printk("FPDMA len = %d\n", len));
  2006. } else {
  2007. len = sizeof(struct dev_to_host_fis);
  2008. PM8001_IO_DBG(pm8001_ha,
  2009. pm8001_printk("other len = %d\n", len));
  2010. }
  2011. if (SAS_STATUS_BUF_SIZE >= sizeof(*resp)) {
  2012. resp->frame_len = len;
  2013. memcpy(&resp->ending_fis[0], sata_resp, len);
  2014. ts->buf_valid_size = sizeof(*resp);
  2015. } else
  2016. PM8001_IO_DBG(pm8001_ha,
  2017. pm8001_printk("response to large\n"));
  2018. }
  2019. if (pm8001_dev)
  2020. pm8001_dev->running_req--;
  2021. break;
  2022. case IO_ABORTED:
  2023. PM8001_IO_DBG(pm8001_ha,
  2024. pm8001_printk("IO_ABORTED IOMB Tag\n"));
  2025. ts->resp = SAS_TASK_COMPLETE;
  2026. ts->stat = SAS_ABORTED_TASK;
  2027. if (pm8001_dev)
  2028. pm8001_dev->running_req--;
  2029. break;
  2030. /* following cases are to do cases */
  2031. case IO_UNDERFLOW:
  2032. /* SATA Completion with error */
  2033. PM8001_IO_DBG(pm8001_ha,
  2034. pm8001_printk("IO_UNDERFLOW param = %d\n", param));
  2035. ts->resp = SAS_TASK_COMPLETE;
  2036. ts->stat = SAS_DATA_UNDERRUN;
  2037. ts->residual = param;
  2038. if (pm8001_dev)
  2039. pm8001_dev->running_req--;
  2040. break;
  2041. case IO_NO_DEVICE:
  2042. PM8001_IO_DBG(pm8001_ha,
  2043. pm8001_printk("IO_NO_DEVICE\n"));
  2044. ts->resp = SAS_TASK_UNDELIVERED;
  2045. ts->stat = SAS_PHY_DOWN;
  2046. break;
  2047. case IO_XFER_ERROR_BREAK:
  2048. PM8001_IO_DBG(pm8001_ha,
  2049. pm8001_printk("IO_XFER_ERROR_BREAK\n"));
  2050. ts->resp = SAS_TASK_COMPLETE;
  2051. ts->stat = SAS_INTERRUPTED;
  2052. break;
  2053. case IO_XFER_ERROR_PHY_NOT_READY:
  2054. PM8001_IO_DBG(pm8001_ha,
  2055. pm8001_printk("IO_XFER_ERROR_PHY_NOT_READY\n"));
  2056. ts->resp = SAS_TASK_COMPLETE;
  2057. ts->stat = SAS_OPEN_REJECT;
  2058. ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
  2059. break;
  2060. case IO_OPEN_CNX_ERROR_PROTOCOL_NOT_SUPPORTED:
  2061. PM8001_IO_DBG(pm8001_ha,
  2062. pm8001_printk("IO_OPEN_CNX_ERROR_PROTOCOL_NOT"
  2063. "_SUPPORTED\n"));
  2064. ts->resp = SAS_TASK_COMPLETE;
  2065. ts->stat = SAS_OPEN_REJECT;
  2066. ts->open_rej_reason = SAS_OREJ_EPROTO;
  2067. break;
  2068. case IO_OPEN_CNX_ERROR_ZONE_VIOLATION:
  2069. PM8001_IO_DBG(pm8001_ha,
  2070. pm8001_printk("IO_OPEN_CNX_ERROR_ZONE_VIOLATION\n"));
  2071. ts->resp = SAS_TASK_COMPLETE;
  2072. ts->stat = SAS_OPEN_REJECT;
  2073. ts->open_rej_reason = SAS_OREJ_UNKNOWN;
  2074. break;
  2075. case IO_OPEN_CNX_ERROR_BREAK:
  2076. PM8001_IO_DBG(pm8001_ha,
  2077. pm8001_printk("IO_OPEN_CNX_ERROR_BREAK\n"));
  2078. ts->resp = SAS_TASK_COMPLETE;
  2079. ts->stat = SAS_OPEN_REJECT;
  2080. ts->open_rej_reason = SAS_OREJ_RSVD_CONT0;
  2081. break;
  2082. case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS:
  2083. PM8001_IO_DBG(pm8001_ha,
  2084. pm8001_printk("IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS\n"));
  2085. ts->resp = SAS_TASK_COMPLETE;
  2086. ts->stat = SAS_DEV_NO_RESPONSE;
  2087. if (!t->uldd_task) {
  2088. pm8001_handle_event(pm8001_ha,
  2089. pm8001_dev,
  2090. IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS);
  2091. ts->resp = SAS_TASK_UNDELIVERED;
  2092. ts->stat = SAS_QUEUE_FULL;
  2093. pm8001_ccb_task_free(pm8001_ha, t, ccb, tag);
  2094. mb();/*in order to force CPU ordering*/
  2095. spin_unlock_irq(&pm8001_ha->lock);
  2096. t->task_done(t);
  2097. spin_lock_irq(&pm8001_ha->lock);
  2098. return;
  2099. }
  2100. break;
  2101. case IO_OPEN_CNX_ERROR_BAD_DESTINATION:
  2102. PM8001_IO_DBG(pm8001_ha,
  2103. pm8001_printk("IO_OPEN_CNX_ERROR_BAD_DESTINATION\n"));
  2104. ts->resp = SAS_TASK_UNDELIVERED;
  2105. ts->stat = SAS_OPEN_REJECT;
  2106. ts->open_rej_reason = SAS_OREJ_BAD_DEST;
  2107. if (!t->uldd_task) {
  2108. pm8001_handle_event(pm8001_ha,
  2109. pm8001_dev,
  2110. IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS);
  2111. ts->resp = SAS_TASK_UNDELIVERED;
  2112. ts->stat = SAS_QUEUE_FULL;
  2113. pm8001_ccb_task_free(pm8001_ha, t, ccb, tag);
  2114. mb();/*ditto*/
  2115. spin_unlock_irq(&pm8001_ha->lock);
  2116. t->task_done(t);
  2117. spin_lock_irq(&pm8001_ha->lock);
  2118. return;
  2119. }
  2120. break;
  2121. case IO_OPEN_CNX_ERROR_CONNECTION_RATE_NOT_SUPPORTED:
  2122. PM8001_IO_DBG(pm8001_ha,
  2123. pm8001_printk("IO_OPEN_CNX_ERROR_CONNECTION_RATE_"
  2124. "NOT_SUPPORTED\n"));
  2125. ts->resp = SAS_TASK_COMPLETE;
  2126. ts->stat = SAS_OPEN_REJECT;
  2127. ts->open_rej_reason = SAS_OREJ_CONN_RATE;
  2128. break;
  2129. case IO_OPEN_CNX_ERROR_STP_RESOURCES_BUSY:
  2130. PM8001_IO_DBG(pm8001_ha,
  2131. pm8001_printk("IO_OPEN_CNX_ERROR_STP_RESOURCES"
  2132. "_BUSY\n"));
  2133. ts->resp = SAS_TASK_COMPLETE;
  2134. ts->stat = SAS_DEV_NO_RESPONSE;
  2135. if (!t->uldd_task) {
  2136. pm8001_handle_event(pm8001_ha,
  2137. pm8001_dev,
  2138. IO_OPEN_CNX_ERROR_STP_RESOURCES_BUSY);
  2139. ts->resp = SAS_TASK_UNDELIVERED;
  2140. ts->stat = SAS_QUEUE_FULL;
  2141. pm8001_ccb_task_free(pm8001_ha, t, ccb, tag);
  2142. mb();/* ditto*/
  2143. spin_unlock_irq(&pm8001_ha->lock);
  2144. t->task_done(t);
  2145. spin_lock_irq(&pm8001_ha->lock);
  2146. return;
  2147. }
  2148. break;
  2149. case IO_OPEN_CNX_ERROR_WRONG_DESTINATION:
  2150. PM8001_IO_DBG(pm8001_ha,
  2151. pm8001_printk("IO_OPEN_CNX_ERROR_WRONG_DESTINATION\n"));
  2152. ts->resp = SAS_TASK_COMPLETE;
  2153. ts->stat = SAS_OPEN_REJECT;
  2154. ts->open_rej_reason = SAS_OREJ_WRONG_DEST;
  2155. break;
  2156. case IO_XFER_ERROR_NAK_RECEIVED:
  2157. PM8001_IO_DBG(pm8001_ha,
  2158. pm8001_printk("IO_XFER_ERROR_NAK_RECEIVED\n"));
  2159. ts->resp = SAS_TASK_COMPLETE;
  2160. ts->stat = SAS_NAK_R_ERR;
  2161. break;
  2162. case IO_XFER_ERROR_ACK_NAK_TIMEOUT:
  2163. PM8001_IO_DBG(pm8001_ha,
  2164. pm8001_printk("IO_XFER_ERROR_ACK_NAK_TIMEOUT\n"));
  2165. ts->resp = SAS_TASK_COMPLETE;
  2166. ts->stat = SAS_NAK_R_ERR;
  2167. break;
  2168. case IO_XFER_ERROR_DMA:
  2169. PM8001_IO_DBG(pm8001_ha,
  2170. pm8001_printk("IO_XFER_ERROR_DMA\n"));
  2171. ts->resp = SAS_TASK_COMPLETE;
  2172. ts->stat = SAS_ABORTED_TASK;
  2173. break;
  2174. case IO_XFER_ERROR_SATA_LINK_TIMEOUT:
  2175. PM8001_IO_DBG(pm8001_ha,
  2176. pm8001_printk("IO_XFER_ERROR_SATA_LINK_TIMEOUT\n"));
  2177. ts->resp = SAS_TASK_UNDELIVERED;
  2178. ts->stat = SAS_DEV_NO_RESPONSE;
  2179. break;
  2180. case IO_XFER_ERROR_REJECTED_NCQ_MODE:
  2181. PM8001_IO_DBG(pm8001_ha,
  2182. pm8001_printk("IO_XFER_ERROR_REJECTED_NCQ_MODE\n"));
  2183. ts->resp = SAS_TASK_COMPLETE;
  2184. ts->stat = SAS_DATA_UNDERRUN;
  2185. break;
  2186. case IO_XFER_OPEN_RETRY_TIMEOUT:
  2187. PM8001_IO_DBG(pm8001_ha,
  2188. pm8001_printk("IO_XFER_OPEN_RETRY_TIMEOUT\n"));
  2189. ts->resp = SAS_TASK_COMPLETE;
  2190. ts->stat = SAS_OPEN_TO;
  2191. break;
  2192. case IO_PORT_IN_RESET:
  2193. PM8001_IO_DBG(pm8001_ha,
  2194. pm8001_printk("IO_PORT_IN_RESET\n"));
  2195. ts->resp = SAS_TASK_COMPLETE;
  2196. ts->stat = SAS_DEV_NO_RESPONSE;
  2197. break;
  2198. case IO_DS_NON_OPERATIONAL:
  2199. PM8001_IO_DBG(pm8001_ha,
  2200. pm8001_printk("IO_DS_NON_OPERATIONAL\n"));
  2201. ts->resp = SAS_TASK_COMPLETE;
  2202. ts->stat = SAS_DEV_NO_RESPONSE;
  2203. if (!t->uldd_task) {
  2204. pm8001_handle_event(pm8001_ha, pm8001_dev,
  2205. IO_DS_NON_OPERATIONAL);
  2206. ts->resp = SAS_TASK_UNDELIVERED;
  2207. ts->stat = SAS_QUEUE_FULL;
  2208. pm8001_ccb_task_free(pm8001_ha, t, ccb, tag);
  2209. mb();/*ditto*/
  2210. spin_unlock_irq(&pm8001_ha->lock);
  2211. t->task_done(t);
  2212. spin_lock_irq(&pm8001_ha->lock);
  2213. return;
  2214. }
  2215. break;
  2216. case IO_DS_IN_RECOVERY:
  2217. PM8001_IO_DBG(pm8001_ha,
  2218. pm8001_printk(" IO_DS_IN_RECOVERY\n"));
  2219. ts->resp = SAS_TASK_COMPLETE;
  2220. ts->stat = SAS_DEV_NO_RESPONSE;
  2221. break;
  2222. case IO_DS_IN_ERROR:
  2223. PM8001_IO_DBG(pm8001_ha,
  2224. pm8001_printk("IO_DS_IN_ERROR\n"));
  2225. ts->resp = SAS_TASK_COMPLETE;
  2226. ts->stat = SAS_DEV_NO_RESPONSE;
  2227. if (!t->uldd_task) {
  2228. pm8001_handle_event(pm8001_ha, pm8001_dev,
  2229. IO_DS_IN_ERROR);
  2230. ts->resp = SAS_TASK_UNDELIVERED;
  2231. ts->stat = SAS_QUEUE_FULL;
  2232. pm8001_ccb_task_free(pm8001_ha, t, ccb, tag);
  2233. mb();/*ditto*/
  2234. spin_unlock_irq(&pm8001_ha->lock);
  2235. t->task_done(t);
  2236. spin_lock_irq(&pm8001_ha->lock);
  2237. return;
  2238. }
  2239. break;
  2240. case IO_OPEN_CNX_ERROR_HW_RESOURCE_BUSY:
  2241. PM8001_IO_DBG(pm8001_ha,
  2242. pm8001_printk("IO_OPEN_CNX_ERROR_HW_RESOURCE_BUSY\n"));
  2243. ts->resp = SAS_TASK_COMPLETE;
  2244. ts->stat = SAS_OPEN_REJECT;
  2245. ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
  2246. default:
  2247. PM8001_IO_DBG(pm8001_ha,
  2248. pm8001_printk("Unknown status 0x%x\n", status));
  2249. /* not allowed case. Therefore, return failed status */
  2250. ts->resp = SAS_TASK_COMPLETE;
  2251. ts->stat = SAS_DEV_NO_RESPONSE;
  2252. break;
  2253. }
  2254. spin_lock_irqsave(&t->task_state_lock, flags);
  2255. t->task_state_flags &= ~SAS_TASK_STATE_PENDING;
  2256. t->task_state_flags &= ~SAS_TASK_AT_INITIATOR;
  2257. t->task_state_flags |= SAS_TASK_STATE_DONE;
  2258. if (unlikely((t->task_state_flags & SAS_TASK_STATE_ABORTED))) {
  2259. spin_unlock_irqrestore(&t->task_state_lock, flags);
  2260. PM8001_FAIL_DBG(pm8001_ha,
  2261. pm8001_printk("task 0x%p done with io_status 0x%x"
  2262. " resp 0x%x stat 0x%x but aborted by upper layer!\n",
  2263. t, status, ts->resp, ts->stat));
  2264. pm8001_ccb_task_free(pm8001_ha, t, ccb, tag);
  2265. } else if (t->uldd_task) {
  2266. spin_unlock_irqrestore(&t->task_state_lock, flags);
  2267. pm8001_ccb_task_free(pm8001_ha, t, ccb, tag);
  2268. mb();/* ditto */
  2269. spin_unlock_irq(&pm8001_ha->lock);
  2270. t->task_done(t);
  2271. spin_lock_irq(&pm8001_ha->lock);
  2272. } else if (!t->uldd_task) {
  2273. spin_unlock_irqrestore(&t->task_state_lock, flags);
  2274. pm8001_ccb_task_free(pm8001_ha, t, ccb, tag);
  2275. mb();/*ditto*/
  2276. spin_unlock_irq(&pm8001_ha->lock);
  2277. t->task_done(t);
  2278. spin_lock_irq(&pm8001_ha->lock);
  2279. }
  2280. }
  2281. /*See the comments for mpi_ssp_completion */
  2282. static void mpi_sata_event(struct pm8001_hba_info *pm8001_ha , void *piomb)
  2283. {
  2284. struct sas_task *t;
  2285. struct task_status_struct *ts;
  2286. struct pm8001_ccb_info *ccb;
  2287. struct pm8001_device *pm8001_dev;
  2288. struct sata_event_resp *psataPayload =
  2289. (struct sata_event_resp *)(piomb + 4);
  2290. u32 event = le32_to_cpu(psataPayload->event);
  2291. u32 tag = le32_to_cpu(psataPayload->tag);
  2292. u32 port_id = le32_to_cpu(psataPayload->port_id);
  2293. u32 dev_id = le32_to_cpu(psataPayload->device_id);
  2294. unsigned long flags;
  2295. ccb = &pm8001_ha->ccb_info[tag];
  2296. t = ccb->task;
  2297. pm8001_dev = ccb->device;
  2298. if (event)
  2299. PM8001_FAIL_DBG(pm8001_ha,
  2300. pm8001_printk("sata IO status 0x%x\n", event));
  2301. if (unlikely(!t || !t->lldd_task || !t->dev))
  2302. return;
  2303. ts = &t->task_status;
  2304. PM8001_IO_DBG(pm8001_ha,
  2305. pm8001_printk("port_id = %x,device_id = %x\n",
  2306. port_id, dev_id));
  2307. switch (event) {
  2308. case IO_OVERFLOW:
  2309. PM8001_IO_DBG(pm8001_ha, pm8001_printk("IO_UNDERFLOW\n"));
  2310. ts->resp = SAS_TASK_COMPLETE;
  2311. ts->stat = SAS_DATA_OVERRUN;
  2312. ts->residual = 0;
  2313. if (pm8001_dev)
  2314. pm8001_dev->running_req--;
  2315. break;
  2316. case IO_XFER_ERROR_BREAK:
  2317. PM8001_IO_DBG(pm8001_ha,
  2318. pm8001_printk("IO_XFER_ERROR_BREAK\n"));
  2319. ts->resp = SAS_TASK_COMPLETE;
  2320. ts->stat = SAS_INTERRUPTED;
  2321. break;
  2322. case IO_XFER_ERROR_PHY_NOT_READY:
  2323. PM8001_IO_DBG(pm8001_ha,
  2324. pm8001_printk("IO_XFER_ERROR_PHY_NOT_READY\n"));
  2325. ts->resp = SAS_TASK_COMPLETE;
  2326. ts->stat = SAS_OPEN_REJECT;
  2327. ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
  2328. break;
  2329. case IO_OPEN_CNX_ERROR_PROTOCOL_NOT_SUPPORTED:
  2330. PM8001_IO_DBG(pm8001_ha,
  2331. pm8001_printk("IO_OPEN_CNX_ERROR_PROTOCOL_NOT"
  2332. "_SUPPORTED\n"));
  2333. ts->resp = SAS_TASK_COMPLETE;
  2334. ts->stat = SAS_OPEN_REJECT;
  2335. ts->open_rej_reason = SAS_OREJ_EPROTO;
  2336. break;
  2337. case IO_OPEN_CNX_ERROR_ZONE_VIOLATION:
  2338. PM8001_IO_DBG(pm8001_ha,
  2339. pm8001_printk("IO_OPEN_CNX_ERROR_ZONE_VIOLATION\n"));
  2340. ts->resp = SAS_TASK_COMPLETE;
  2341. ts->stat = SAS_OPEN_REJECT;
  2342. ts->open_rej_reason = SAS_OREJ_UNKNOWN;
  2343. break;
  2344. case IO_OPEN_CNX_ERROR_BREAK:
  2345. PM8001_IO_DBG(pm8001_ha,
  2346. pm8001_printk("IO_OPEN_CNX_ERROR_BREAK\n"));
  2347. ts->resp = SAS_TASK_COMPLETE;
  2348. ts->stat = SAS_OPEN_REJECT;
  2349. ts->open_rej_reason = SAS_OREJ_RSVD_CONT0;
  2350. break;
  2351. case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS:
  2352. PM8001_IO_DBG(pm8001_ha,
  2353. pm8001_printk("IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS\n"));
  2354. ts->resp = SAS_TASK_UNDELIVERED;
  2355. ts->stat = SAS_DEV_NO_RESPONSE;
  2356. if (!t->uldd_task) {
  2357. pm8001_handle_event(pm8001_ha,
  2358. pm8001_dev,
  2359. IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS);
  2360. ts->resp = SAS_TASK_COMPLETE;
  2361. ts->stat = SAS_QUEUE_FULL;
  2362. pm8001_ccb_task_free(pm8001_ha, t, ccb, tag);
  2363. mb();/*ditto*/
  2364. spin_unlock_irq(&pm8001_ha->lock);
  2365. t->task_done(t);
  2366. spin_lock_irq(&pm8001_ha->lock);
  2367. return;
  2368. }
  2369. break;
  2370. case IO_OPEN_CNX_ERROR_BAD_DESTINATION:
  2371. PM8001_IO_DBG(pm8001_ha,
  2372. pm8001_printk("IO_OPEN_CNX_ERROR_BAD_DESTINATION\n"));
  2373. ts->resp = SAS_TASK_UNDELIVERED;
  2374. ts->stat = SAS_OPEN_REJECT;
  2375. ts->open_rej_reason = SAS_OREJ_BAD_DEST;
  2376. break;
  2377. case IO_OPEN_CNX_ERROR_CONNECTION_RATE_NOT_SUPPORTED:
  2378. PM8001_IO_DBG(pm8001_ha,
  2379. pm8001_printk("IO_OPEN_CNX_ERROR_CONNECTION_RATE_"
  2380. "NOT_SUPPORTED\n"));
  2381. ts->resp = SAS_TASK_COMPLETE;
  2382. ts->stat = SAS_OPEN_REJECT;
  2383. ts->open_rej_reason = SAS_OREJ_CONN_RATE;
  2384. break;
  2385. case IO_OPEN_CNX_ERROR_WRONG_DESTINATION:
  2386. PM8001_IO_DBG(pm8001_ha,
  2387. pm8001_printk("IO_OPEN_CNX_ERROR_WRONG_DESTINATION\n"));
  2388. ts->resp = SAS_TASK_COMPLETE;
  2389. ts->stat = SAS_OPEN_REJECT;
  2390. ts->open_rej_reason = SAS_OREJ_WRONG_DEST;
  2391. break;
  2392. case IO_XFER_ERROR_NAK_RECEIVED:
  2393. PM8001_IO_DBG(pm8001_ha,
  2394. pm8001_printk("IO_XFER_ERROR_NAK_RECEIVED\n"));
  2395. ts->resp = SAS_TASK_COMPLETE;
  2396. ts->stat = SAS_NAK_R_ERR;
  2397. break;
  2398. case IO_XFER_ERROR_PEER_ABORTED:
  2399. PM8001_IO_DBG(pm8001_ha,
  2400. pm8001_printk("IO_XFER_ERROR_PEER_ABORTED\n"));
  2401. ts->resp = SAS_TASK_COMPLETE;
  2402. ts->stat = SAS_NAK_R_ERR;
  2403. break;
  2404. case IO_XFER_ERROR_REJECTED_NCQ_MODE:
  2405. PM8001_IO_DBG(pm8001_ha,
  2406. pm8001_printk("IO_XFER_ERROR_REJECTED_NCQ_MODE\n"));
  2407. ts->resp = SAS_TASK_COMPLETE;
  2408. ts->stat = SAS_DATA_UNDERRUN;
  2409. break;
  2410. case IO_XFER_OPEN_RETRY_TIMEOUT:
  2411. PM8001_IO_DBG(pm8001_ha,
  2412. pm8001_printk("IO_XFER_OPEN_RETRY_TIMEOUT\n"));
  2413. ts->resp = SAS_TASK_COMPLETE;
  2414. ts->stat = SAS_OPEN_TO;
  2415. break;
  2416. case IO_XFER_ERROR_UNEXPECTED_PHASE:
  2417. PM8001_IO_DBG(pm8001_ha,
  2418. pm8001_printk("IO_XFER_ERROR_UNEXPECTED_PHASE\n"));
  2419. ts->resp = SAS_TASK_COMPLETE;
  2420. ts->stat = SAS_OPEN_TO;
  2421. break;
  2422. case IO_XFER_ERROR_XFER_RDY_OVERRUN:
  2423. PM8001_IO_DBG(pm8001_ha,
  2424. pm8001_printk("IO_XFER_ERROR_XFER_RDY_OVERRUN\n"));
  2425. ts->resp = SAS_TASK_COMPLETE;
  2426. ts->stat = SAS_OPEN_TO;
  2427. break;
  2428. case IO_XFER_ERROR_XFER_RDY_NOT_EXPECTED:
  2429. PM8001_IO_DBG(pm8001_ha,
  2430. pm8001_printk("IO_XFER_ERROR_XFER_RDY_NOT_EXPECTED\n"));
  2431. ts->resp = SAS_TASK_COMPLETE;
  2432. ts->stat = SAS_OPEN_TO;
  2433. break;
  2434. case IO_XFER_ERROR_OFFSET_MISMATCH:
  2435. PM8001_IO_DBG(pm8001_ha,
  2436. pm8001_printk("IO_XFER_ERROR_OFFSET_MISMATCH\n"));
  2437. ts->resp = SAS_TASK_COMPLETE;
  2438. ts->stat = SAS_OPEN_TO;
  2439. break;
  2440. case IO_XFER_ERROR_XFER_ZERO_DATA_LEN:
  2441. PM8001_IO_DBG(pm8001_ha,
  2442. pm8001_printk("IO_XFER_ERROR_XFER_ZERO_DATA_LEN\n"));
  2443. ts->resp = SAS_TASK_COMPLETE;
  2444. ts->stat = SAS_OPEN_TO;
  2445. break;
  2446. case IO_XFER_CMD_FRAME_ISSUED:
  2447. PM8001_IO_DBG(pm8001_ha,
  2448. pm8001_printk("IO_XFER_CMD_FRAME_ISSUED\n"));
  2449. break;
  2450. case IO_XFER_PIO_SETUP_ERROR:
  2451. PM8001_IO_DBG(pm8001_ha,
  2452. pm8001_printk("IO_XFER_PIO_SETUP_ERROR\n"));
  2453. ts->resp = SAS_TASK_COMPLETE;
  2454. ts->stat = SAS_OPEN_TO;
  2455. break;
  2456. default:
  2457. PM8001_IO_DBG(pm8001_ha,
  2458. pm8001_printk("Unknown status 0x%x\n", event));
  2459. /* not allowed case. Therefore, return failed status */
  2460. ts->resp = SAS_TASK_COMPLETE;
  2461. ts->stat = SAS_OPEN_TO;
  2462. break;
  2463. }
  2464. spin_lock_irqsave(&t->task_state_lock, flags);
  2465. t->task_state_flags &= ~SAS_TASK_STATE_PENDING;
  2466. t->task_state_flags &= ~SAS_TASK_AT_INITIATOR;
  2467. t->task_state_flags |= SAS_TASK_STATE_DONE;
  2468. if (unlikely((t->task_state_flags & SAS_TASK_STATE_ABORTED))) {
  2469. spin_unlock_irqrestore(&t->task_state_lock, flags);
  2470. PM8001_FAIL_DBG(pm8001_ha,
  2471. pm8001_printk("task 0x%p done with io_status 0x%x"
  2472. " resp 0x%x stat 0x%x but aborted by upper layer!\n",
  2473. t, event, ts->resp, ts->stat));
  2474. pm8001_ccb_task_free(pm8001_ha, t, ccb, tag);
  2475. } else if (t->uldd_task) {
  2476. spin_unlock_irqrestore(&t->task_state_lock, flags);
  2477. pm8001_ccb_task_free(pm8001_ha, t, ccb, tag);
  2478. mb();/* ditto */
  2479. spin_unlock_irq(&pm8001_ha->lock);
  2480. t->task_done(t);
  2481. spin_lock_irq(&pm8001_ha->lock);
  2482. } else if (!t->uldd_task) {
  2483. spin_unlock_irqrestore(&t->task_state_lock, flags);
  2484. pm8001_ccb_task_free(pm8001_ha, t, ccb, tag);
  2485. mb();/*ditto*/
  2486. spin_unlock_irq(&pm8001_ha->lock);
  2487. t->task_done(t);
  2488. spin_lock_irq(&pm8001_ha->lock);
  2489. }
  2490. }
  2491. /*See the comments for mpi_ssp_completion */
  2492. static void
  2493. mpi_smp_completion(struct pm8001_hba_info *pm8001_ha, void *piomb)
  2494. {
  2495. u32 param;
  2496. struct sas_task *t;
  2497. struct pm8001_ccb_info *ccb;
  2498. unsigned long flags;
  2499. u32 status;
  2500. u32 tag;
  2501. struct smp_completion_resp *psmpPayload;
  2502. struct task_status_struct *ts;
  2503. struct pm8001_device *pm8001_dev;
  2504. psmpPayload = (struct smp_completion_resp *)(piomb + 4);
  2505. status = le32_to_cpu(psmpPayload->status);
  2506. tag = le32_to_cpu(psmpPayload->tag);
  2507. ccb = &pm8001_ha->ccb_info[tag];
  2508. param = le32_to_cpu(psmpPayload->param);
  2509. t = ccb->task;
  2510. ts = &t->task_status;
  2511. pm8001_dev = ccb->device;
  2512. if (status)
  2513. PM8001_FAIL_DBG(pm8001_ha,
  2514. pm8001_printk("smp IO status 0x%x\n", status));
  2515. if (unlikely(!t || !t->lldd_task || !t->dev))
  2516. return;
  2517. switch (status) {
  2518. case IO_SUCCESS:
  2519. PM8001_IO_DBG(pm8001_ha, pm8001_printk("IO_SUCCESS\n"));
  2520. ts->resp = SAS_TASK_COMPLETE;
  2521. ts->stat = SAM_STAT_GOOD;
  2522. if (pm8001_dev)
  2523. pm8001_dev->running_req--;
  2524. break;
  2525. case IO_ABORTED:
  2526. PM8001_IO_DBG(pm8001_ha,
  2527. pm8001_printk("IO_ABORTED IOMB\n"));
  2528. ts->resp = SAS_TASK_COMPLETE;
  2529. ts->stat = SAS_ABORTED_TASK;
  2530. if (pm8001_dev)
  2531. pm8001_dev->running_req--;
  2532. break;
  2533. case IO_OVERFLOW:
  2534. PM8001_IO_DBG(pm8001_ha, pm8001_printk("IO_UNDERFLOW\n"));
  2535. ts->resp = SAS_TASK_COMPLETE;
  2536. ts->stat = SAS_DATA_OVERRUN;
  2537. ts->residual = 0;
  2538. if (pm8001_dev)
  2539. pm8001_dev->running_req--;
  2540. break;
  2541. case IO_NO_DEVICE:
  2542. PM8001_IO_DBG(pm8001_ha, pm8001_printk("IO_NO_DEVICE\n"));
  2543. ts->resp = SAS_TASK_COMPLETE;
  2544. ts->stat = SAS_PHY_DOWN;
  2545. break;
  2546. case IO_ERROR_HW_TIMEOUT:
  2547. PM8001_IO_DBG(pm8001_ha,
  2548. pm8001_printk("IO_ERROR_HW_TIMEOUT\n"));
  2549. ts->resp = SAS_TASK_COMPLETE;
  2550. ts->stat = SAM_STAT_BUSY;
  2551. break;
  2552. case IO_XFER_ERROR_BREAK:
  2553. PM8001_IO_DBG(pm8001_ha,
  2554. pm8001_printk("IO_XFER_ERROR_BREAK\n"));
  2555. ts->resp = SAS_TASK_COMPLETE;
  2556. ts->stat = SAM_STAT_BUSY;
  2557. break;
  2558. case IO_XFER_ERROR_PHY_NOT_READY:
  2559. PM8001_IO_DBG(pm8001_ha,
  2560. pm8001_printk("IO_XFER_ERROR_PHY_NOT_READY\n"));
  2561. ts->resp = SAS_TASK_COMPLETE;
  2562. ts->stat = SAM_STAT_BUSY;
  2563. break;
  2564. case IO_OPEN_CNX_ERROR_PROTOCOL_NOT_SUPPORTED:
  2565. PM8001_IO_DBG(pm8001_ha,
  2566. pm8001_printk("IO_OPEN_CNX_ERROR_PROTOCOL_NOT_SUPPORTED\n"));
  2567. ts->resp = SAS_TASK_COMPLETE;
  2568. ts->stat = SAS_OPEN_REJECT;
  2569. ts->open_rej_reason = SAS_OREJ_UNKNOWN;
  2570. break;
  2571. case IO_OPEN_CNX_ERROR_ZONE_VIOLATION:
  2572. PM8001_IO_DBG(pm8001_ha,
  2573. pm8001_printk("IO_OPEN_CNX_ERROR_ZONE_VIOLATION\n"));
  2574. ts->resp = SAS_TASK_COMPLETE;
  2575. ts->stat = SAS_OPEN_REJECT;
  2576. ts->open_rej_reason = SAS_OREJ_UNKNOWN;
  2577. break;
  2578. case IO_OPEN_CNX_ERROR_BREAK:
  2579. PM8001_IO_DBG(pm8001_ha,
  2580. pm8001_printk("IO_OPEN_CNX_ERROR_BREAK\n"));
  2581. ts->resp = SAS_TASK_COMPLETE;
  2582. ts->stat = SAS_OPEN_REJECT;
  2583. ts->open_rej_reason = SAS_OREJ_RSVD_CONT0;
  2584. break;
  2585. case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS:
  2586. PM8001_IO_DBG(pm8001_ha,
  2587. pm8001_printk("IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS\n"));
  2588. ts->resp = SAS_TASK_COMPLETE;
  2589. ts->stat = SAS_OPEN_REJECT;
  2590. ts->open_rej_reason = SAS_OREJ_UNKNOWN;
  2591. pm8001_handle_event(pm8001_ha,
  2592. pm8001_dev,
  2593. IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS);
  2594. break;
  2595. case IO_OPEN_CNX_ERROR_BAD_DESTINATION:
  2596. PM8001_IO_DBG(pm8001_ha,
  2597. pm8001_printk("IO_OPEN_CNX_ERROR_BAD_DESTINATION\n"));
  2598. ts->resp = SAS_TASK_COMPLETE;
  2599. ts->stat = SAS_OPEN_REJECT;
  2600. ts->open_rej_reason = SAS_OREJ_BAD_DEST;
  2601. break;
  2602. case IO_OPEN_CNX_ERROR_CONNECTION_RATE_NOT_SUPPORTED:
  2603. PM8001_IO_DBG(pm8001_ha,
  2604. pm8001_printk("IO_OPEN_CNX_ERROR_CONNECTION_RATE_"
  2605. "NOT_SUPPORTED\n"));
  2606. ts->resp = SAS_TASK_COMPLETE;
  2607. ts->stat = SAS_OPEN_REJECT;
  2608. ts->open_rej_reason = SAS_OREJ_CONN_RATE;
  2609. break;
  2610. case IO_OPEN_CNX_ERROR_WRONG_DESTINATION:
  2611. PM8001_IO_DBG(pm8001_ha,
  2612. pm8001_printk("IO_OPEN_CNX_ERROR_WRONG_DESTINATION\n"));
  2613. ts->resp = SAS_TASK_COMPLETE;
  2614. ts->stat = SAS_OPEN_REJECT;
  2615. ts->open_rej_reason = SAS_OREJ_WRONG_DEST;
  2616. break;
  2617. case IO_XFER_ERROR_RX_FRAME:
  2618. PM8001_IO_DBG(pm8001_ha,
  2619. pm8001_printk("IO_XFER_ERROR_RX_FRAME\n"));
  2620. ts->resp = SAS_TASK_COMPLETE;
  2621. ts->stat = SAS_DEV_NO_RESPONSE;
  2622. break;
  2623. case IO_XFER_OPEN_RETRY_TIMEOUT:
  2624. PM8001_IO_DBG(pm8001_ha,
  2625. pm8001_printk("IO_XFER_OPEN_RETRY_TIMEOUT\n"));
  2626. ts->resp = SAS_TASK_COMPLETE;
  2627. ts->stat = SAS_OPEN_REJECT;
  2628. ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
  2629. break;
  2630. case IO_ERROR_INTERNAL_SMP_RESOURCE:
  2631. PM8001_IO_DBG(pm8001_ha,
  2632. pm8001_printk("IO_ERROR_INTERNAL_SMP_RESOURCE\n"));
  2633. ts->resp = SAS_TASK_COMPLETE;
  2634. ts->stat = SAS_QUEUE_FULL;
  2635. break;
  2636. case IO_PORT_IN_RESET:
  2637. PM8001_IO_DBG(pm8001_ha,
  2638. pm8001_printk("IO_PORT_IN_RESET\n"));
  2639. ts->resp = SAS_TASK_COMPLETE;
  2640. ts->stat = SAS_OPEN_REJECT;
  2641. ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
  2642. break;
  2643. case IO_DS_NON_OPERATIONAL:
  2644. PM8001_IO_DBG(pm8001_ha,
  2645. pm8001_printk("IO_DS_NON_OPERATIONAL\n"));
  2646. ts->resp = SAS_TASK_COMPLETE;
  2647. ts->stat = SAS_DEV_NO_RESPONSE;
  2648. break;
  2649. case IO_DS_IN_RECOVERY:
  2650. PM8001_IO_DBG(pm8001_ha,
  2651. pm8001_printk("IO_DS_IN_RECOVERY\n"));
  2652. ts->resp = SAS_TASK_COMPLETE;
  2653. ts->stat = SAS_OPEN_REJECT;
  2654. ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
  2655. break;
  2656. case IO_OPEN_CNX_ERROR_HW_RESOURCE_BUSY:
  2657. PM8001_IO_DBG(pm8001_ha,
  2658. pm8001_printk("IO_OPEN_CNX_ERROR_HW_RESOURCE_BUSY\n"));
  2659. ts->resp = SAS_TASK_COMPLETE;
  2660. ts->stat = SAS_OPEN_REJECT;
  2661. ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
  2662. break;
  2663. default:
  2664. PM8001_IO_DBG(pm8001_ha,
  2665. pm8001_printk("Unknown status 0x%x\n", status));
  2666. ts->resp = SAS_TASK_COMPLETE;
  2667. ts->stat = SAS_DEV_NO_RESPONSE;
  2668. /* not allowed case. Therefore, return failed status */
  2669. break;
  2670. }
  2671. spin_lock_irqsave(&t->task_state_lock, flags);
  2672. t->task_state_flags &= ~SAS_TASK_STATE_PENDING;
  2673. t->task_state_flags &= ~SAS_TASK_AT_INITIATOR;
  2674. t->task_state_flags |= SAS_TASK_STATE_DONE;
  2675. if (unlikely((t->task_state_flags & SAS_TASK_STATE_ABORTED))) {
  2676. spin_unlock_irqrestore(&t->task_state_lock, flags);
  2677. PM8001_FAIL_DBG(pm8001_ha, pm8001_printk("task 0x%p done with"
  2678. " io_status 0x%x resp 0x%x "
  2679. "stat 0x%x but aborted by upper layer!\n",
  2680. t, status, ts->resp, ts->stat));
  2681. pm8001_ccb_task_free(pm8001_ha, t, ccb, tag);
  2682. } else {
  2683. spin_unlock_irqrestore(&t->task_state_lock, flags);
  2684. pm8001_ccb_task_free(pm8001_ha, t, ccb, tag);
  2685. mb();/* in order to force CPU ordering */
  2686. t->task_done(t);
  2687. }
  2688. }
  2689. static void
  2690. mpi_set_dev_state_resp(struct pm8001_hba_info *pm8001_ha, void *piomb)
  2691. {
  2692. struct set_dev_state_resp *pPayload =
  2693. (struct set_dev_state_resp *)(piomb + 4);
  2694. u32 tag = le32_to_cpu(pPayload->tag);
  2695. struct pm8001_ccb_info *ccb = &pm8001_ha->ccb_info[tag];
  2696. struct pm8001_device *pm8001_dev = ccb->device;
  2697. u32 status = le32_to_cpu(pPayload->status);
  2698. u32 device_id = le32_to_cpu(pPayload->device_id);
  2699. u8 pds = le32_to_cpu(pPayload->pds_nds) | PDS_BITS;
  2700. u8 nds = le32_to_cpu(pPayload->pds_nds) | NDS_BITS;
  2701. PM8001_MSG_DBG(pm8001_ha, pm8001_printk("Set device id = 0x%x state "
  2702. "from 0x%x to 0x%x status = 0x%x!\n",
  2703. device_id, pds, nds, status));
  2704. complete(pm8001_dev->setds_completion);
  2705. ccb->task = NULL;
  2706. ccb->ccb_tag = 0xFFFFFFFF;
  2707. pm8001_ccb_free(pm8001_ha, tag);
  2708. }
  2709. static void
  2710. mpi_set_nvmd_resp(struct pm8001_hba_info *pm8001_ha, void *piomb)
  2711. {
  2712. struct get_nvm_data_resp *pPayload =
  2713. (struct get_nvm_data_resp *)(piomb + 4);
  2714. u32 tag = le32_to_cpu(pPayload->tag);
  2715. struct pm8001_ccb_info *ccb = &pm8001_ha->ccb_info[tag];
  2716. u32 dlen_status = le32_to_cpu(pPayload->dlen_status);
  2717. complete(pm8001_ha->nvmd_completion);
  2718. PM8001_MSG_DBG(pm8001_ha, pm8001_printk("Set nvm data complete!\n"));
  2719. if ((dlen_status & NVMD_STAT) != 0) {
  2720. PM8001_FAIL_DBG(pm8001_ha,
  2721. pm8001_printk("Set nvm data error!\n"));
  2722. return;
  2723. }
  2724. ccb->task = NULL;
  2725. ccb->ccb_tag = 0xFFFFFFFF;
  2726. pm8001_ccb_free(pm8001_ha, tag);
  2727. }
  2728. static void
  2729. mpi_get_nvmd_resp(struct pm8001_hba_info *pm8001_ha, void *piomb)
  2730. {
  2731. struct fw_control_ex *fw_control_context;
  2732. struct get_nvm_data_resp *pPayload =
  2733. (struct get_nvm_data_resp *)(piomb + 4);
  2734. u32 tag = le32_to_cpu(pPayload->tag);
  2735. struct pm8001_ccb_info *ccb = &pm8001_ha->ccb_info[tag];
  2736. u32 dlen_status = le32_to_cpu(pPayload->dlen_status);
  2737. u32 ir_tds_bn_dps_das_nvm =
  2738. le32_to_cpu(pPayload->ir_tda_bn_dps_das_nvm);
  2739. void *virt_addr = pm8001_ha->memoryMap.region[NVMD].virt_ptr;
  2740. fw_control_context = ccb->fw_control_context;
  2741. PM8001_MSG_DBG(pm8001_ha, pm8001_printk("Get nvm data complete!\n"));
  2742. if ((dlen_status & NVMD_STAT) != 0) {
  2743. PM8001_FAIL_DBG(pm8001_ha,
  2744. pm8001_printk("Get nvm data error!\n"));
  2745. complete(pm8001_ha->nvmd_completion);
  2746. return;
  2747. }
  2748. if (ir_tds_bn_dps_das_nvm & IPMode) {
  2749. /* indirect mode - IR bit set */
  2750. PM8001_MSG_DBG(pm8001_ha,
  2751. pm8001_printk("Get NVMD success, IR=1\n"));
  2752. if ((ir_tds_bn_dps_das_nvm & NVMD_TYPE) == TWI_DEVICE) {
  2753. if (ir_tds_bn_dps_das_nvm == 0x80a80200) {
  2754. memcpy(pm8001_ha->sas_addr,
  2755. ((u8 *)virt_addr + 4),
  2756. SAS_ADDR_SIZE);
  2757. PM8001_MSG_DBG(pm8001_ha,
  2758. pm8001_printk("Get SAS address"
  2759. " from VPD successfully!\n"));
  2760. }
  2761. } else if (((ir_tds_bn_dps_das_nvm & NVMD_TYPE) == C_SEEPROM)
  2762. || ((ir_tds_bn_dps_das_nvm & NVMD_TYPE) == VPD_FLASH) ||
  2763. ((ir_tds_bn_dps_das_nvm & NVMD_TYPE) == EXPAN_ROM)) {
  2764. ;
  2765. } else if (((ir_tds_bn_dps_das_nvm & NVMD_TYPE) == AAP1_RDUMP)
  2766. || ((ir_tds_bn_dps_das_nvm & NVMD_TYPE) == IOP_RDUMP)) {
  2767. ;
  2768. } else {
  2769. /* Should not be happened*/
  2770. PM8001_MSG_DBG(pm8001_ha,
  2771. pm8001_printk("(IR=1)Wrong Device type 0x%x\n",
  2772. ir_tds_bn_dps_das_nvm));
  2773. }
  2774. } else /* direct mode */{
  2775. PM8001_MSG_DBG(pm8001_ha,
  2776. pm8001_printk("Get NVMD success, IR=0, dataLen=%d\n",
  2777. (dlen_status & NVMD_LEN) >> 24));
  2778. }
  2779. memcpy(fw_control_context->usrAddr,
  2780. pm8001_ha->memoryMap.region[NVMD].virt_ptr,
  2781. fw_control_context->len);
  2782. complete(pm8001_ha->nvmd_completion);
  2783. ccb->task = NULL;
  2784. ccb->ccb_tag = 0xFFFFFFFF;
  2785. pm8001_ccb_free(pm8001_ha, tag);
  2786. }
  2787. static int mpi_local_phy_ctl(struct pm8001_hba_info *pm8001_ha, void *piomb)
  2788. {
  2789. struct local_phy_ctl_resp *pPayload =
  2790. (struct local_phy_ctl_resp *)(piomb + 4);
  2791. u32 status = le32_to_cpu(pPayload->status);
  2792. u32 phy_id = le32_to_cpu(pPayload->phyop_phyid) & ID_BITS;
  2793. u32 phy_op = le32_to_cpu(pPayload->phyop_phyid) & OP_BITS;
  2794. if (status != 0) {
  2795. PM8001_MSG_DBG(pm8001_ha,
  2796. pm8001_printk("%x phy execute %x phy op failed!\n",
  2797. phy_id, phy_op));
  2798. } else
  2799. PM8001_MSG_DBG(pm8001_ha,
  2800. pm8001_printk("%x phy execute %x phy op success!\n",
  2801. phy_id, phy_op));
  2802. return 0;
  2803. }
  2804. /**
  2805. * pm8001_bytes_dmaed - one of the interface function communication with libsas
  2806. * @pm8001_ha: our hba card information
  2807. * @i: which phy that received the event.
  2808. *
  2809. * when HBA driver received the identify done event or initiate FIS received
  2810. * event(for SATA), it will invoke this function to notify the sas layer that
  2811. * the sas toplogy has formed, please discover the the whole sas domain,
  2812. * while receive a broadcast(change) primitive just tell the sas
  2813. * layer to discover the changed domain rather than the whole domain.
  2814. */
  2815. static void pm8001_bytes_dmaed(struct pm8001_hba_info *pm8001_ha, int i)
  2816. {
  2817. struct pm8001_phy *phy = &pm8001_ha->phy[i];
  2818. struct asd_sas_phy *sas_phy = &phy->sas_phy;
  2819. struct sas_ha_struct *sas_ha;
  2820. if (!phy->phy_attached)
  2821. return;
  2822. sas_ha = pm8001_ha->sas;
  2823. if (sas_phy->phy) {
  2824. struct sas_phy *sphy = sas_phy->phy;
  2825. sphy->negotiated_linkrate = sas_phy->linkrate;
  2826. sphy->minimum_linkrate = phy->minimum_linkrate;
  2827. sphy->minimum_linkrate_hw = SAS_LINK_RATE_1_5_GBPS;
  2828. sphy->maximum_linkrate = phy->maximum_linkrate;
  2829. sphy->maximum_linkrate_hw = phy->maximum_linkrate;
  2830. }
  2831. if (phy->phy_type & PORT_TYPE_SAS) {
  2832. struct sas_identify_frame *id;
  2833. id = (struct sas_identify_frame *)phy->frame_rcvd;
  2834. id->dev_type = phy->identify.device_type;
  2835. id->initiator_bits = SAS_PROTOCOL_ALL;
  2836. id->target_bits = phy->identify.target_port_protocols;
  2837. } else if (phy->phy_type & PORT_TYPE_SATA) {
  2838. /*Nothing*/
  2839. }
  2840. PM8001_MSG_DBG(pm8001_ha, pm8001_printk("phy %d byte dmaded.\n", i));
  2841. sas_phy->frame_rcvd_size = phy->frame_rcvd_size;
  2842. pm8001_ha->sas->notify_port_event(sas_phy, PORTE_BYTES_DMAED);
  2843. }
  2844. /* Get the link rate speed */
  2845. static void get_lrate_mode(struct pm8001_phy *phy, u8 link_rate)
  2846. {
  2847. struct sas_phy *sas_phy = phy->sas_phy.phy;
  2848. switch (link_rate) {
  2849. case PHY_SPEED_60:
  2850. phy->sas_phy.linkrate = SAS_LINK_RATE_6_0_GBPS;
  2851. phy->sas_phy.phy->negotiated_linkrate = SAS_LINK_RATE_6_0_GBPS;
  2852. break;
  2853. case PHY_SPEED_30:
  2854. phy->sas_phy.linkrate = SAS_LINK_RATE_3_0_GBPS;
  2855. phy->sas_phy.phy->negotiated_linkrate = SAS_LINK_RATE_3_0_GBPS;
  2856. break;
  2857. case PHY_SPEED_15:
  2858. phy->sas_phy.linkrate = SAS_LINK_RATE_1_5_GBPS;
  2859. phy->sas_phy.phy->negotiated_linkrate = SAS_LINK_RATE_1_5_GBPS;
  2860. break;
  2861. }
  2862. sas_phy->negotiated_linkrate = phy->sas_phy.linkrate;
  2863. sas_phy->maximum_linkrate_hw = SAS_LINK_RATE_6_0_GBPS;
  2864. sas_phy->minimum_linkrate_hw = SAS_LINK_RATE_1_5_GBPS;
  2865. sas_phy->maximum_linkrate = SAS_LINK_RATE_6_0_GBPS;
  2866. sas_phy->minimum_linkrate = SAS_LINK_RATE_1_5_GBPS;
  2867. }
  2868. /**
  2869. * asd_get_attached_sas_addr -- extract/generate attached SAS address
  2870. * @phy: pointer to asd_phy
  2871. * @sas_addr: pointer to buffer where the SAS address is to be written
  2872. *
  2873. * This function extracts the SAS address from an IDENTIFY frame
  2874. * received. If OOB is SATA, then a SAS address is generated from the
  2875. * HA tables.
  2876. *
  2877. * LOCKING: the frame_rcvd_lock needs to be held since this parses the frame
  2878. * buffer.
  2879. */
  2880. static void pm8001_get_attached_sas_addr(struct pm8001_phy *phy,
  2881. u8 *sas_addr)
  2882. {
  2883. if (phy->sas_phy.frame_rcvd[0] == 0x34
  2884. && phy->sas_phy.oob_mode == SATA_OOB_MODE) {
  2885. struct pm8001_hba_info *pm8001_ha = phy->sas_phy.ha->lldd_ha;
  2886. /* FIS device-to-host */
  2887. u64 addr = be64_to_cpu(*(__be64 *)pm8001_ha->sas_addr);
  2888. addr += phy->sas_phy.id;
  2889. *(__be64 *)sas_addr = cpu_to_be64(addr);
  2890. } else {
  2891. struct sas_identify_frame *idframe =
  2892. (void *) phy->sas_phy.frame_rcvd;
  2893. memcpy(sas_addr, idframe->sas_addr, SAS_ADDR_SIZE);
  2894. }
  2895. }
  2896. /**
  2897. * pm8001_hw_event_ack_req- For PM8001,some events need to acknowage to FW.
  2898. * @pm8001_ha: our hba card information
  2899. * @Qnum: the outbound queue message number.
  2900. * @SEA: source of event to ack
  2901. * @port_id: port id.
  2902. * @phyId: phy id.
  2903. * @param0: parameter 0.
  2904. * @param1: parameter 1.
  2905. */
  2906. static void pm8001_hw_event_ack_req(struct pm8001_hba_info *pm8001_ha,
  2907. u32 Qnum, u32 SEA, u32 port_id, u32 phyId, u32 param0, u32 param1)
  2908. {
  2909. struct hw_event_ack_req payload;
  2910. u32 opc = OPC_INB_SAS_HW_EVENT_ACK;
  2911. struct inbound_queue_table *circularQ;
  2912. memset((u8 *)&payload, 0, sizeof(payload));
  2913. circularQ = &pm8001_ha->inbnd_q_tbl[Qnum];
  2914. payload.tag = cpu_to_le32(1);
  2915. payload.sea_phyid_portid = cpu_to_le32(((SEA & 0xFFFF) << 8) |
  2916. ((phyId & 0x0F) << 4) | (port_id & 0x0F));
  2917. payload.param0 = cpu_to_le32(param0);
  2918. payload.param1 = cpu_to_le32(param1);
  2919. mpi_build_cmd(pm8001_ha, circularQ, opc, &payload);
  2920. }
  2921. static int pm8001_chip_phy_ctl_req(struct pm8001_hba_info *pm8001_ha,
  2922. u32 phyId, u32 phy_op);
  2923. /**
  2924. * hw_event_sas_phy_up -FW tells me a SAS phy up event.
  2925. * @pm8001_ha: our hba card information
  2926. * @piomb: IO message buffer
  2927. */
  2928. static void
  2929. hw_event_sas_phy_up(struct pm8001_hba_info *pm8001_ha, void *piomb)
  2930. {
  2931. struct hw_event_resp *pPayload =
  2932. (struct hw_event_resp *)(piomb + 4);
  2933. u32 lr_evt_status_phyid_portid =
  2934. le32_to_cpu(pPayload->lr_evt_status_phyid_portid);
  2935. u8 link_rate =
  2936. (u8)((lr_evt_status_phyid_portid & 0xF0000000) >> 28);
  2937. u8 port_id = (u8)(lr_evt_status_phyid_portid & 0x0000000F);
  2938. u8 phy_id =
  2939. (u8)((lr_evt_status_phyid_portid & 0x000000F0) >> 4);
  2940. u32 npip_portstate = le32_to_cpu(pPayload->npip_portstate);
  2941. u8 portstate = (u8)(npip_portstate & 0x0000000F);
  2942. struct pm8001_port *port = &pm8001_ha->port[port_id];
  2943. struct sas_ha_struct *sas_ha = pm8001_ha->sas;
  2944. struct pm8001_phy *phy = &pm8001_ha->phy[phy_id];
  2945. unsigned long flags;
  2946. u8 deviceType = pPayload->sas_identify.dev_type;
  2947. port->port_state = portstate;
  2948. PM8001_MSG_DBG(pm8001_ha,
  2949. pm8001_printk("HW_EVENT_SAS_PHY_UP port id = %d, phy id = %d\n",
  2950. port_id, phy_id));
  2951. switch (deviceType) {
  2952. case SAS_PHY_UNUSED:
  2953. PM8001_MSG_DBG(pm8001_ha,
  2954. pm8001_printk("device type no device.\n"));
  2955. break;
  2956. case SAS_END_DEVICE:
  2957. PM8001_MSG_DBG(pm8001_ha, pm8001_printk("end device.\n"));
  2958. pm8001_chip_phy_ctl_req(pm8001_ha, phy_id,
  2959. PHY_NOTIFY_ENABLE_SPINUP);
  2960. port->port_attached = 1;
  2961. get_lrate_mode(phy, link_rate);
  2962. break;
  2963. case SAS_EDGE_EXPANDER_DEVICE:
  2964. PM8001_MSG_DBG(pm8001_ha,
  2965. pm8001_printk("expander device.\n"));
  2966. port->port_attached = 1;
  2967. get_lrate_mode(phy, link_rate);
  2968. break;
  2969. case SAS_FANOUT_EXPANDER_DEVICE:
  2970. PM8001_MSG_DBG(pm8001_ha,
  2971. pm8001_printk("fanout expander device.\n"));
  2972. port->port_attached = 1;
  2973. get_lrate_mode(phy, link_rate);
  2974. break;
  2975. default:
  2976. PM8001_MSG_DBG(pm8001_ha,
  2977. pm8001_printk("unknown device type(%x)\n", deviceType));
  2978. break;
  2979. }
  2980. phy->phy_type |= PORT_TYPE_SAS;
  2981. phy->identify.device_type = deviceType;
  2982. phy->phy_attached = 1;
  2983. if (phy->identify.device_type == SAS_END_DEVICE)
  2984. phy->identify.target_port_protocols = SAS_PROTOCOL_SSP;
  2985. else if (phy->identify.device_type != SAS_PHY_UNUSED)
  2986. phy->identify.target_port_protocols = SAS_PROTOCOL_SMP;
  2987. phy->sas_phy.oob_mode = SAS_OOB_MODE;
  2988. sas_ha->notify_phy_event(&phy->sas_phy, PHYE_OOB_DONE);
  2989. spin_lock_irqsave(&phy->sas_phy.frame_rcvd_lock, flags);
  2990. memcpy(phy->frame_rcvd, &pPayload->sas_identify,
  2991. sizeof(struct sas_identify_frame)-4);
  2992. phy->frame_rcvd_size = sizeof(struct sas_identify_frame) - 4;
  2993. pm8001_get_attached_sas_addr(phy, phy->sas_phy.attached_sas_addr);
  2994. spin_unlock_irqrestore(&phy->sas_phy.frame_rcvd_lock, flags);
  2995. if (pm8001_ha->flags == PM8001F_RUN_TIME)
  2996. mdelay(200);/*delay a moment to wait disk to spinup*/
  2997. pm8001_bytes_dmaed(pm8001_ha, phy_id);
  2998. }
  2999. /**
  3000. * hw_event_sata_phy_up -FW tells me a SATA phy up event.
  3001. * @pm8001_ha: our hba card information
  3002. * @piomb: IO message buffer
  3003. */
  3004. static void
  3005. hw_event_sata_phy_up(struct pm8001_hba_info *pm8001_ha, void *piomb)
  3006. {
  3007. struct hw_event_resp *pPayload =
  3008. (struct hw_event_resp *)(piomb + 4);
  3009. u32 lr_evt_status_phyid_portid =
  3010. le32_to_cpu(pPayload->lr_evt_status_phyid_portid);
  3011. u8 link_rate =
  3012. (u8)((lr_evt_status_phyid_portid & 0xF0000000) >> 28);
  3013. u8 port_id = (u8)(lr_evt_status_phyid_portid & 0x0000000F);
  3014. u8 phy_id =
  3015. (u8)((lr_evt_status_phyid_portid & 0x000000F0) >> 4);
  3016. u32 npip_portstate = le32_to_cpu(pPayload->npip_portstate);
  3017. u8 portstate = (u8)(npip_portstate & 0x0000000F);
  3018. struct pm8001_port *port = &pm8001_ha->port[port_id];
  3019. struct sas_ha_struct *sas_ha = pm8001_ha->sas;
  3020. struct pm8001_phy *phy = &pm8001_ha->phy[phy_id];
  3021. unsigned long flags;
  3022. PM8001_MSG_DBG(pm8001_ha,
  3023. pm8001_printk("HW_EVENT_SATA_PHY_UP port id = %d,"
  3024. " phy id = %d\n", port_id, phy_id));
  3025. port->port_state = portstate;
  3026. port->port_attached = 1;
  3027. get_lrate_mode(phy, link_rate);
  3028. phy->phy_type |= PORT_TYPE_SATA;
  3029. phy->phy_attached = 1;
  3030. phy->sas_phy.oob_mode = SATA_OOB_MODE;
  3031. sas_ha->notify_phy_event(&phy->sas_phy, PHYE_OOB_DONE);
  3032. spin_lock_irqsave(&phy->sas_phy.frame_rcvd_lock, flags);
  3033. memcpy(phy->frame_rcvd, ((u8 *)&pPayload->sata_fis - 4),
  3034. sizeof(struct dev_to_host_fis));
  3035. phy->frame_rcvd_size = sizeof(struct dev_to_host_fis);
  3036. phy->identify.target_port_protocols = SAS_PROTOCOL_SATA;
  3037. phy->identify.device_type = SATA_DEV;
  3038. pm8001_get_attached_sas_addr(phy, phy->sas_phy.attached_sas_addr);
  3039. spin_unlock_irqrestore(&phy->sas_phy.frame_rcvd_lock, flags);
  3040. pm8001_bytes_dmaed(pm8001_ha, phy_id);
  3041. }
  3042. /**
  3043. * hw_event_phy_down -we should notify the libsas the phy is down.
  3044. * @pm8001_ha: our hba card information
  3045. * @piomb: IO message buffer
  3046. */
  3047. static void
  3048. hw_event_phy_down(struct pm8001_hba_info *pm8001_ha, void *piomb)
  3049. {
  3050. struct hw_event_resp *pPayload =
  3051. (struct hw_event_resp *)(piomb + 4);
  3052. u32 lr_evt_status_phyid_portid =
  3053. le32_to_cpu(pPayload->lr_evt_status_phyid_portid);
  3054. u8 port_id = (u8)(lr_evt_status_phyid_portid & 0x0000000F);
  3055. u8 phy_id =
  3056. (u8)((lr_evt_status_phyid_portid & 0x000000F0) >> 4);
  3057. u32 npip_portstate = le32_to_cpu(pPayload->npip_portstate);
  3058. u8 portstate = (u8)(npip_portstate & 0x0000000F);
  3059. struct pm8001_port *port = &pm8001_ha->port[port_id];
  3060. struct pm8001_phy *phy = &pm8001_ha->phy[phy_id];
  3061. port->port_state = portstate;
  3062. phy->phy_type = 0;
  3063. phy->identify.device_type = 0;
  3064. phy->phy_attached = 0;
  3065. memset(&phy->dev_sas_addr, 0, SAS_ADDR_SIZE);
  3066. switch (portstate) {
  3067. case PORT_VALID:
  3068. break;
  3069. case PORT_INVALID:
  3070. PM8001_MSG_DBG(pm8001_ha,
  3071. pm8001_printk(" PortInvalid portID %d\n", port_id));
  3072. PM8001_MSG_DBG(pm8001_ha,
  3073. pm8001_printk(" Last phy Down and port invalid\n"));
  3074. port->port_attached = 0;
  3075. pm8001_hw_event_ack_req(pm8001_ha, 0, HW_EVENT_PHY_DOWN,
  3076. port_id, phy_id, 0, 0);
  3077. break;
  3078. case PORT_IN_RESET:
  3079. PM8001_MSG_DBG(pm8001_ha,
  3080. pm8001_printk(" Port In Reset portID %d\n", port_id));
  3081. break;
  3082. case PORT_NOT_ESTABLISHED:
  3083. PM8001_MSG_DBG(pm8001_ha,
  3084. pm8001_printk(" phy Down and PORT_NOT_ESTABLISHED\n"));
  3085. port->port_attached = 0;
  3086. break;
  3087. case PORT_LOSTCOMM:
  3088. PM8001_MSG_DBG(pm8001_ha,
  3089. pm8001_printk(" phy Down and PORT_LOSTCOMM\n"));
  3090. PM8001_MSG_DBG(pm8001_ha,
  3091. pm8001_printk(" Last phy Down and port invalid\n"));
  3092. port->port_attached = 0;
  3093. pm8001_hw_event_ack_req(pm8001_ha, 0, HW_EVENT_PHY_DOWN,
  3094. port_id, phy_id, 0, 0);
  3095. break;
  3096. default:
  3097. port->port_attached = 0;
  3098. PM8001_MSG_DBG(pm8001_ha,
  3099. pm8001_printk(" phy Down and(default) = %x\n",
  3100. portstate));
  3101. break;
  3102. }
  3103. }
  3104. /**
  3105. * mpi_reg_resp -process register device ID response.
  3106. * @pm8001_ha: our hba card information
  3107. * @piomb: IO message buffer
  3108. *
  3109. * when sas layer find a device it will notify LLDD, then the driver register
  3110. * the domain device to FW, this event is the return device ID which the FW
  3111. * has assigned, from now,inter-communication with FW is no longer using the
  3112. * SAS address, use device ID which FW assigned.
  3113. */
  3114. static int mpi_reg_resp(struct pm8001_hba_info *pm8001_ha, void *piomb)
  3115. {
  3116. u32 status;
  3117. u32 device_id;
  3118. u32 htag;
  3119. struct pm8001_ccb_info *ccb;
  3120. struct pm8001_device *pm8001_dev;
  3121. struct dev_reg_resp *registerRespPayload =
  3122. (struct dev_reg_resp *)(piomb + 4);
  3123. htag = le32_to_cpu(registerRespPayload->tag);
  3124. ccb = &pm8001_ha->ccb_info[htag];
  3125. pm8001_dev = ccb->device;
  3126. status = le32_to_cpu(registerRespPayload->status);
  3127. device_id = le32_to_cpu(registerRespPayload->device_id);
  3128. PM8001_MSG_DBG(pm8001_ha,
  3129. pm8001_printk(" register device is status = %d\n", status));
  3130. switch (status) {
  3131. case DEVREG_SUCCESS:
  3132. PM8001_MSG_DBG(pm8001_ha, pm8001_printk("DEVREG_SUCCESS\n"));
  3133. pm8001_dev->device_id = device_id;
  3134. break;
  3135. case DEVREG_FAILURE_OUT_OF_RESOURCE:
  3136. PM8001_MSG_DBG(pm8001_ha,
  3137. pm8001_printk("DEVREG_FAILURE_OUT_OF_RESOURCE\n"));
  3138. break;
  3139. case DEVREG_FAILURE_DEVICE_ALREADY_REGISTERED:
  3140. PM8001_MSG_DBG(pm8001_ha,
  3141. pm8001_printk("DEVREG_FAILURE_DEVICE_ALREADY_REGISTERED\n"));
  3142. break;
  3143. case DEVREG_FAILURE_INVALID_PHY_ID:
  3144. PM8001_MSG_DBG(pm8001_ha,
  3145. pm8001_printk("DEVREG_FAILURE_INVALID_PHY_ID\n"));
  3146. break;
  3147. case DEVREG_FAILURE_PHY_ID_ALREADY_REGISTERED:
  3148. PM8001_MSG_DBG(pm8001_ha,
  3149. pm8001_printk("DEVREG_FAILURE_PHY_ID_ALREADY_REGISTERED\n"));
  3150. break;
  3151. case DEVREG_FAILURE_PORT_ID_OUT_OF_RANGE:
  3152. PM8001_MSG_DBG(pm8001_ha,
  3153. pm8001_printk("DEVREG_FAILURE_PORT_ID_OUT_OF_RANGE\n"));
  3154. break;
  3155. case DEVREG_FAILURE_PORT_NOT_VALID_STATE:
  3156. PM8001_MSG_DBG(pm8001_ha,
  3157. pm8001_printk("DEVREG_FAILURE_PORT_NOT_VALID_STATE\n"));
  3158. break;
  3159. case DEVREG_FAILURE_DEVICE_TYPE_NOT_VALID:
  3160. PM8001_MSG_DBG(pm8001_ha,
  3161. pm8001_printk("DEVREG_FAILURE_DEVICE_TYPE_NOT_VALID\n"));
  3162. break;
  3163. default:
  3164. PM8001_MSG_DBG(pm8001_ha,
  3165. pm8001_printk("DEVREG_FAILURE_DEVICE_TYPE_NOT_UNSORPORTED\n"));
  3166. break;
  3167. }
  3168. complete(pm8001_dev->dcompletion);
  3169. ccb->task = NULL;
  3170. ccb->ccb_tag = 0xFFFFFFFF;
  3171. pm8001_ccb_free(pm8001_ha, htag);
  3172. return 0;
  3173. }
  3174. static int mpi_dereg_resp(struct pm8001_hba_info *pm8001_ha, void *piomb)
  3175. {
  3176. u32 status;
  3177. u32 device_id;
  3178. struct dev_reg_resp *registerRespPayload =
  3179. (struct dev_reg_resp *)(piomb + 4);
  3180. status = le32_to_cpu(registerRespPayload->status);
  3181. device_id = le32_to_cpu(registerRespPayload->device_id);
  3182. if (status != 0)
  3183. PM8001_MSG_DBG(pm8001_ha,
  3184. pm8001_printk(" deregister device failed ,status = %x"
  3185. ", device_id = %x\n", status, device_id));
  3186. return 0;
  3187. }
  3188. static int
  3189. mpi_fw_flash_update_resp(struct pm8001_hba_info *pm8001_ha, void *piomb)
  3190. {
  3191. u32 status;
  3192. struct fw_control_ex fw_control_context;
  3193. struct fw_flash_Update_resp *ppayload =
  3194. (struct fw_flash_Update_resp *)(piomb + 4);
  3195. u32 tag = ppayload->tag;
  3196. struct pm8001_ccb_info *ccb = &pm8001_ha->ccb_info[tag];
  3197. status = le32_to_cpu(ppayload->status);
  3198. memcpy(&fw_control_context,
  3199. ccb->fw_control_context,
  3200. sizeof(fw_control_context));
  3201. switch (status) {
  3202. case FLASH_UPDATE_COMPLETE_PENDING_REBOOT:
  3203. PM8001_MSG_DBG(pm8001_ha,
  3204. pm8001_printk(": FLASH_UPDATE_COMPLETE_PENDING_REBOOT\n"));
  3205. break;
  3206. case FLASH_UPDATE_IN_PROGRESS:
  3207. PM8001_MSG_DBG(pm8001_ha,
  3208. pm8001_printk(": FLASH_UPDATE_IN_PROGRESS\n"));
  3209. break;
  3210. case FLASH_UPDATE_HDR_ERR:
  3211. PM8001_MSG_DBG(pm8001_ha,
  3212. pm8001_printk(": FLASH_UPDATE_HDR_ERR\n"));
  3213. break;
  3214. case FLASH_UPDATE_OFFSET_ERR:
  3215. PM8001_MSG_DBG(pm8001_ha,
  3216. pm8001_printk(": FLASH_UPDATE_OFFSET_ERR\n"));
  3217. break;
  3218. case FLASH_UPDATE_CRC_ERR:
  3219. PM8001_MSG_DBG(pm8001_ha,
  3220. pm8001_printk(": FLASH_UPDATE_CRC_ERR\n"));
  3221. break;
  3222. case FLASH_UPDATE_LENGTH_ERR:
  3223. PM8001_MSG_DBG(pm8001_ha,
  3224. pm8001_printk(": FLASH_UPDATE_LENGTH_ERR\n"));
  3225. break;
  3226. case FLASH_UPDATE_HW_ERR:
  3227. PM8001_MSG_DBG(pm8001_ha,
  3228. pm8001_printk(": FLASH_UPDATE_HW_ERR\n"));
  3229. break;
  3230. case FLASH_UPDATE_DNLD_NOT_SUPPORTED:
  3231. PM8001_MSG_DBG(pm8001_ha,
  3232. pm8001_printk(": FLASH_UPDATE_DNLD_NOT_SUPPORTED\n"));
  3233. break;
  3234. case FLASH_UPDATE_DISABLED:
  3235. PM8001_MSG_DBG(pm8001_ha,
  3236. pm8001_printk(": FLASH_UPDATE_DISABLED\n"));
  3237. break;
  3238. default:
  3239. PM8001_MSG_DBG(pm8001_ha,
  3240. pm8001_printk("No matched status = %d\n", status));
  3241. break;
  3242. }
  3243. ccb->fw_control_context->fw_control->retcode = status;
  3244. pci_free_consistent(pm8001_ha->pdev,
  3245. fw_control_context.len,
  3246. fw_control_context.virtAddr,
  3247. fw_control_context.phys_addr);
  3248. complete(pm8001_ha->nvmd_completion);
  3249. ccb->task = NULL;
  3250. ccb->ccb_tag = 0xFFFFFFFF;
  3251. pm8001_ccb_free(pm8001_ha, tag);
  3252. return 0;
  3253. }
  3254. static int
  3255. mpi_general_event(struct pm8001_hba_info *pm8001_ha , void *piomb)
  3256. {
  3257. u32 status;
  3258. int i;
  3259. struct general_event_resp *pPayload =
  3260. (struct general_event_resp *)(piomb + 4);
  3261. status = le32_to_cpu(pPayload->status);
  3262. PM8001_MSG_DBG(pm8001_ha,
  3263. pm8001_printk(" status = 0x%x\n", status));
  3264. for (i = 0; i < GENERAL_EVENT_PAYLOAD; i++)
  3265. PM8001_MSG_DBG(pm8001_ha,
  3266. pm8001_printk("inb_IOMB_payload[0x%x] 0x%x,\n", i,
  3267. pPayload->inb_IOMB_payload[i]));
  3268. return 0;
  3269. }
  3270. static int
  3271. mpi_task_abort_resp(struct pm8001_hba_info *pm8001_ha, void *piomb)
  3272. {
  3273. struct sas_task *t;
  3274. struct pm8001_ccb_info *ccb;
  3275. unsigned long flags;
  3276. u32 status ;
  3277. u32 tag, scp;
  3278. struct task_status_struct *ts;
  3279. struct task_abort_resp *pPayload =
  3280. (struct task_abort_resp *)(piomb + 4);
  3281. status = le32_to_cpu(pPayload->status);
  3282. tag = le32_to_cpu(pPayload->tag);
  3283. scp = le32_to_cpu(pPayload->scp);
  3284. ccb = &pm8001_ha->ccb_info[tag];
  3285. t = ccb->task;
  3286. PM8001_IO_DBG(pm8001_ha,
  3287. pm8001_printk(" status = 0x%x\n", status));
  3288. if (t == NULL)
  3289. return -1;
  3290. ts = &t->task_status;
  3291. if (status != 0)
  3292. PM8001_FAIL_DBG(pm8001_ha,
  3293. pm8001_printk("task abort failed status 0x%x ,"
  3294. "tag = 0x%x, scp= 0x%x\n", status, tag, scp));
  3295. switch (status) {
  3296. case IO_SUCCESS:
  3297. PM8001_EH_DBG(pm8001_ha, pm8001_printk("IO_SUCCESS\n"));
  3298. ts->resp = SAS_TASK_COMPLETE;
  3299. ts->stat = SAM_STAT_GOOD;
  3300. break;
  3301. case IO_NOT_VALID:
  3302. PM8001_EH_DBG(pm8001_ha, pm8001_printk("IO_NOT_VALID\n"));
  3303. ts->resp = TMF_RESP_FUNC_FAILED;
  3304. break;
  3305. }
  3306. spin_lock_irqsave(&t->task_state_lock, flags);
  3307. t->task_state_flags &= ~SAS_TASK_STATE_PENDING;
  3308. t->task_state_flags &= ~SAS_TASK_AT_INITIATOR;
  3309. t->task_state_flags |= SAS_TASK_STATE_DONE;
  3310. spin_unlock_irqrestore(&t->task_state_lock, flags);
  3311. pm8001_ccb_task_free(pm8001_ha, t, ccb, tag);
  3312. mb();
  3313. t->task_done(t);
  3314. return 0;
  3315. }
  3316. /**
  3317. * mpi_hw_event -The hw event has come.
  3318. * @pm8001_ha: our hba card information
  3319. * @piomb: IO message buffer
  3320. */
  3321. static int mpi_hw_event(struct pm8001_hba_info *pm8001_ha, void* piomb)
  3322. {
  3323. unsigned long flags;
  3324. struct hw_event_resp *pPayload =
  3325. (struct hw_event_resp *)(piomb + 4);
  3326. u32 lr_evt_status_phyid_portid =
  3327. le32_to_cpu(pPayload->lr_evt_status_phyid_portid);
  3328. u8 port_id = (u8)(lr_evt_status_phyid_portid & 0x0000000F);
  3329. u8 phy_id =
  3330. (u8)((lr_evt_status_phyid_portid & 0x000000F0) >> 4);
  3331. u16 eventType =
  3332. (u16)((lr_evt_status_phyid_portid & 0x00FFFF00) >> 8);
  3333. u8 status =
  3334. (u8)((lr_evt_status_phyid_portid & 0x0F000000) >> 24);
  3335. struct sas_ha_struct *sas_ha = pm8001_ha->sas;
  3336. struct pm8001_phy *phy = &pm8001_ha->phy[phy_id];
  3337. struct asd_sas_phy *sas_phy = sas_ha->sas_phy[phy_id];
  3338. PM8001_MSG_DBG(pm8001_ha,
  3339. pm8001_printk("outbound queue HW event & event type : "));
  3340. switch (eventType) {
  3341. case HW_EVENT_PHY_START_STATUS:
  3342. PM8001_MSG_DBG(pm8001_ha,
  3343. pm8001_printk("HW_EVENT_PHY_START_STATUS"
  3344. " status = %x\n", status));
  3345. if (status == 0) {
  3346. phy->phy_state = 1;
  3347. if (pm8001_ha->flags == PM8001F_RUN_TIME)
  3348. complete(phy->enable_completion);
  3349. }
  3350. break;
  3351. case HW_EVENT_SAS_PHY_UP:
  3352. PM8001_MSG_DBG(pm8001_ha,
  3353. pm8001_printk("HW_EVENT_PHY_START_STATUS\n"));
  3354. hw_event_sas_phy_up(pm8001_ha, piomb);
  3355. break;
  3356. case HW_EVENT_SATA_PHY_UP:
  3357. PM8001_MSG_DBG(pm8001_ha,
  3358. pm8001_printk("HW_EVENT_SATA_PHY_UP\n"));
  3359. hw_event_sata_phy_up(pm8001_ha, piomb);
  3360. break;
  3361. case HW_EVENT_PHY_STOP_STATUS:
  3362. PM8001_MSG_DBG(pm8001_ha,
  3363. pm8001_printk("HW_EVENT_PHY_STOP_STATUS "
  3364. "status = %x\n", status));
  3365. if (status == 0)
  3366. phy->phy_state = 0;
  3367. break;
  3368. case HW_EVENT_SATA_SPINUP_HOLD:
  3369. PM8001_MSG_DBG(pm8001_ha,
  3370. pm8001_printk("HW_EVENT_SATA_SPINUP_HOLD\n"));
  3371. sas_ha->notify_phy_event(&phy->sas_phy, PHYE_SPINUP_HOLD);
  3372. break;
  3373. case HW_EVENT_PHY_DOWN:
  3374. PM8001_MSG_DBG(pm8001_ha,
  3375. pm8001_printk("HW_EVENT_PHY_DOWN\n"));
  3376. sas_ha->notify_phy_event(&phy->sas_phy, PHYE_LOSS_OF_SIGNAL);
  3377. phy->phy_attached = 0;
  3378. phy->phy_state = 0;
  3379. hw_event_phy_down(pm8001_ha, piomb);
  3380. break;
  3381. case HW_EVENT_PORT_INVALID:
  3382. PM8001_MSG_DBG(pm8001_ha,
  3383. pm8001_printk("HW_EVENT_PORT_INVALID\n"));
  3384. sas_phy_disconnected(sas_phy);
  3385. phy->phy_attached = 0;
  3386. sas_ha->notify_port_event(sas_phy, PORTE_LINK_RESET_ERR);
  3387. break;
  3388. /* the broadcast change primitive received, tell the LIBSAS this event
  3389. to revalidate the sas domain*/
  3390. case HW_EVENT_BROADCAST_CHANGE:
  3391. PM8001_MSG_DBG(pm8001_ha,
  3392. pm8001_printk("HW_EVENT_BROADCAST_CHANGE\n"));
  3393. pm8001_hw_event_ack_req(pm8001_ha, 0, HW_EVENT_BROADCAST_CHANGE,
  3394. port_id, phy_id, 1, 0);
  3395. spin_lock_irqsave(&sas_phy->sas_prim_lock, flags);
  3396. sas_phy->sas_prim = HW_EVENT_BROADCAST_CHANGE;
  3397. spin_unlock_irqrestore(&sas_phy->sas_prim_lock, flags);
  3398. sas_ha->notify_port_event(sas_phy, PORTE_BROADCAST_RCVD);
  3399. break;
  3400. case HW_EVENT_PHY_ERROR:
  3401. PM8001_MSG_DBG(pm8001_ha,
  3402. pm8001_printk("HW_EVENT_PHY_ERROR\n"));
  3403. sas_phy_disconnected(&phy->sas_phy);
  3404. phy->phy_attached = 0;
  3405. sas_ha->notify_phy_event(&phy->sas_phy, PHYE_OOB_ERROR);
  3406. break;
  3407. case HW_EVENT_BROADCAST_EXP:
  3408. PM8001_MSG_DBG(pm8001_ha,
  3409. pm8001_printk("HW_EVENT_BROADCAST_EXP\n"));
  3410. spin_lock_irqsave(&sas_phy->sas_prim_lock, flags);
  3411. sas_phy->sas_prim = HW_EVENT_BROADCAST_EXP;
  3412. spin_unlock_irqrestore(&sas_phy->sas_prim_lock, flags);
  3413. sas_ha->notify_port_event(sas_phy, PORTE_BROADCAST_RCVD);
  3414. break;
  3415. case HW_EVENT_LINK_ERR_INVALID_DWORD:
  3416. PM8001_MSG_DBG(pm8001_ha,
  3417. pm8001_printk("HW_EVENT_LINK_ERR_INVALID_DWORD\n"));
  3418. pm8001_hw_event_ack_req(pm8001_ha, 0,
  3419. HW_EVENT_LINK_ERR_INVALID_DWORD, port_id, phy_id, 0, 0);
  3420. sas_phy_disconnected(sas_phy);
  3421. phy->phy_attached = 0;
  3422. sas_ha->notify_port_event(sas_phy, PORTE_LINK_RESET_ERR);
  3423. break;
  3424. case HW_EVENT_LINK_ERR_DISPARITY_ERROR:
  3425. PM8001_MSG_DBG(pm8001_ha,
  3426. pm8001_printk("HW_EVENT_LINK_ERR_DISPARITY_ERROR\n"));
  3427. pm8001_hw_event_ack_req(pm8001_ha, 0,
  3428. HW_EVENT_LINK_ERR_DISPARITY_ERROR,
  3429. port_id, phy_id, 0, 0);
  3430. sas_phy_disconnected(sas_phy);
  3431. phy->phy_attached = 0;
  3432. sas_ha->notify_port_event(sas_phy, PORTE_LINK_RESET_ERR);
  3433. break;
  3434. case HW_EVENT_LINK_ERR_CODE_VIOLATION:
  3435. PM8001_MSG_DBG(pm8001_ha,
  3436. pm8001_printk("HW_EVENT_LINK_ERR_CODE_VIOLATION\n"));
  3437. pm8001_hw_event_ack_req(pm8001_ha, 0,
  3438. HW_EVENT_LINK_ERR_CODE_VIOLATION,
  3439. port_id, phy_id, 0, 0);
  3440. sas_phy_disconnected(sas_phy);
  3441. phy->phy_attached = 0;
  3442. sas_ha->notify_port_event(sas_phy, PORTE_LINK_RESET_ERR);
  3443. break;
  3444. case HW_EVENT_LINK_ERR_LOSS_OF_DWORD_SYNCH:
  3445. PM8001_MSG_DBG(pm8001_ha,
  3446. pm8001_printk("HW_EVENT_LINK_ERR_LOSS_OF_DWORD_SYNCH\n"));
  3447. pm8001_hw_event_ack_req(pm8001_ha, 0,
  3448. HW_EVENT_LINK_ERR_LOSS_OF_DWORD_SYNCH,
  3449. port_id, phy_id, 0, 0);
  3450. sas_phy_disconnected(sas_phy);
  3451. phy->phy_attached = 0;
  3452. sas_ha->notify_port_event(sas_phy, PORTE_LINK_RESET_ERR);
  3453. break;
  3454. case HW_EVENT_MALFUNCTION:
  3455. PM8001_MSG_DBG(pm8001_ha,
  3456. pm8001_printk("HW_EVENT_MALFUNCTION\n"));
  3457. break;
  3458. case HW_EVENT_BROADCAST_SES:
  3459. PM8001_MSG_DBG(pm8001_ha,
  3460. pm8001_printk("HW_EVENT_BROADCAST_SES\n"));
  3461. spin_lock_irqsave(&sas_phy->sas_prim_lock, flags);
  3462. sas_phy->sas_prim = HW_EVENT_BROADCAST_SES;
  3463. spin_unlock_irqrestore(&sas_phy->sas_prim_lock, flags);
  3464. sas_ha->notify_port_event(sas_phy, PORTE_BROADCAST_RCVD);
  3465. break;
  3466. case HW_EVENT_INBOUND_CRC_ERROR:
  3467. PM8001_MSG_DBG(pm8001_ha,
  3468. pm8001_printk("HW_EVENT_INBOUND_CRC_ERROR\n"));
  3469. pm8001_hw_event_ack_req(pm8001_ha, 0,
  3470. HW_EVENT_INBOUND_CRC_ERROR,
  3471. port_id, phy_id, 0, 0);
  3472. break;
  3473. case HW_EVENT_HARD_RESET_RECEIVED:
  3474. PM8001_MSG_DBG(pm8001_ha,
  3475. pm8001_printk("HW_EVENT_HARD_RESET_RECEIVED\n"));
  3476. sas_ha->notify_port_event(sas_phy, PORTE_HARD_RESET);
  3477. break;
  3478. case HW_EVENT_ID_FRAME_TIMEOUT:
  3479. PM8001_MSG_DBG(pm8001_ha,
  3480. pm8001_printk("HW_EVENT_ID_FRAME_TIMEOUT\n"));
  3481. sas_phy_disconnected(sas_phy);
  3482. phy->phy_attached = 0;
  3483. sas_ha->notify_port_event(sas_phy, PORTE_LINK_RESET_ERR);
  3484. break;
  3485. case HW_EVENT_LINK_ERR_PHY_RESET_FAILED:
  3486. PM8001_MSG_DBG(pm8001_ha,
  3487. pm8001_printk("HW_EVENT_LINK_ERR_PHY_RESET_FAILED\n"));
  3488. pm8001_hw_event_ack_req(pm8001_ha, 0,
  3489. HW_EVENT_LINK_ERR_PHY_RESET_FAILED,
  3490. port_id, phy_id, 0, 0);
  3491. sas_phy_disconnected(sas_phy);
  3492. phy->phy_attached = 0;
  3493. sas_ha->notify_port_event(sas_phy, PORTE_LINK_RESET_ERR);
  3494. break;
  3495. case HW_EVENT_PORT_RESET_TIMER_TMO:
  3496. PM8001_MSG_DBG(pm8001_ha,
  3497. pm8001_printk("HW_EVENT_PORT_RESET_TIMER_TMO\n"));
  3498. sas_phy_disconnected(sas_phy);
  3499. phy->phy_attached = 0;
  3500. sas_ha->notify_port_event(sas_phy, PORTE_LINK_RESET_ERR);
  3501. break;
  3502. case HW_EVENT_PORT_RECOVERY_TIMER_TMO:
  3503. PM8001_MSG_DBG(pm8001_ha,
  3504. pm8001_printk("HW_EVENT_PORT_RECOVERY_TIMER_TMO\n"));
  3505. sas_phy_disconnected(sas_phy);
  3506. phy->phy_attached = 0;
  3507. sas_ha->notify_port_event(sas_phy, PORTE_LINK_RESET_ERR);
  3508. break;
  3509. case HW_EVENT_PORT_RECOVER:
  3510. PM8001_MSG_DBG(pm8001_ha,
  3511. pm8001_printk("HW_EVENT_PORT_RECOVER\n"));
  3512. break;
  3513. case HW_EVENT_PORT_RESET_COMPLETE:
  3514. PM8001_MSG_DBG(pm8001_ha,
  3515. pm8001_printk("HW_EVENT_PORT_RESET_COMPLETE\n"));
  3516. break;
  3517. case EVENT_BROADCAST_ASYNCH_EVENT:
  3518. PM8001_MSG_DBG(pm8001_ha,
  3519. pm8001_printk("EVENT_BROADCAST_ASYNCH_EVENT\n"));
  3520. break;
  3521. default:
  3522. PM8001_MSG_DBG(pm8001_ha,
  3523. pm8001_printk("Unknown event type = %x\n", eventType));
  3524. break;
  3525. }
  3526. return 0;
  3527. }
  3528. /**
  3529. * process_one_iomb - process one outbound Queue memory block
  3530. * @pm8001_ha: our hba card information
  3531. * @piomb: IO message buffer
  3532. */
  3533. static void process_one_iomb(struct pm8001_hba_info *pm8001_ha, void *piomb)
  3534. {
  3535. u32 pHeader = (u32)*(u32 *)piomb;
  3536. u8 opc = (u8)(pHeader & 0xFFF);
  3537. PM8001_MSG_DBG(pm8001_ha, pm8001_printk("process_one_iomb:"));
  3538. switch (opc) {
  3539. case OPC_OUB_ECHO:
  3540. PM8001_MSG_DBG(pm8001_ha, pm8001_printk("OPC_OUB_ECHO\n"));
  3541. break;
  3542. case OPC_OUB_HW_EVENT:
  3543. PM8001_MSG_DBG(pm8001_ha,
  3544. pm8001_printk("OPC_OUB_HW_EVENT\n"));
  3545. mpi_hw_event(pm8001_ha, piomb);
  3546. break;
  3547. case OPC_OUB_SSP_COMP:
  3548. PM8001_MSG_DBG(pm8001_ha,
  3549. pm8001_printk("OPC_OUB_SSP_COMP\n"));
  3550. mpi_ssp_completion(pm8001_ha, piomb);
  3551. break;
  3552. case OPC_OUB_SMP_COMP:
  3553. PM8001_MSG_DBG(pm8001_ha,
  3554. pm8001_printk("OPC_OUB_SMP_COMP\n"));
  3555. mpi_smp_completion(pm8001_ha, piomb);
  3556. break;
  3557. case OPC_OUB_LOCAL_PHY_CNTRL:
  3558. PM8001_MSG_DBG(pm8001_ha,
  3559. pm8001_printk("OPC_OUB_LOCAL_PHY_CNTRL\n"));
  3560. mpi_local_phy_ctl(pm8001_ha, piomb);
  3561. break;
  3562. case OPC_OUB_DEV_REGIST:
  3563. PM8001_MSG_DBG(pm8001_ha,
  3564. pm8001_printk("OPC_OUB_DEV_REGIST\n"));
  3565. mpi_reg_resp(pm8001_ha, piomb);
  3566. break;
  3567. case OPC_OUB_DEREG_DEV:
  3568. PM8001_MSG_DBG(pm8001_ha,
  3569. pm8001_printk("unregister the device\n"));
  3570. mpi_dereg_resp(pm8001_ha, piomb);
  3571. break;
  3572. case OPC_OUB_GET_DEV_HANDLE:
  3573. PM8001_MSG_DBG(pm8001_ha,
  3574. pm8001_printk("OPC_OUB_GET_DEV_HANDLE\n"));
  3575. break;
  3576. case OPC_OUB_SATA_COMP:
  3577. PM8001_MSG_DBG(pm8001_ha,
  3578. pm8001_printk("OPC_OUB_SATA_COMP\n"));
  3579. mpi_sata_completion(pm8001_ha, piomb);
  3580. break;
  3581. case OPC_OUB_SATA_EVENT:
  3582. PM8001_MSG_DBG(pm8001_ha,
  3583. pm8001_printk("OPC_OUB_SATA_EVENT\n"));
  3584. mpi_sata_event(pm8001_ha, piomb);
  3585. break;
  3586. case OPC_OUB_SSP_EVENT:
  3587. PM8001_MSG_DBG(pm8001_ha,
  3588. pm8001_printk("OPC_OUB_SSP_EVENT\n"));
  3589. mpi_ssp_event(pm8001_ha, piomb);
  3590. break;
  3591. case OPC_OUB_DEV_HANDLE_ARRIV:
  3592. PM8001_MSG_DBG(pm8001_ha,
  3593. pm8001_printk("OPC_OUB_DEV_HANDLE_ARRIV\n"));
  3594. /*This is for target*/
  3595. break;
  3596. case OPC_OUB_SSP_RECV_EVENT:
  3597. PM8001_MSG_DBG(pm8001_ha,
  3598. pm8001_printk("OPC_OUB_SSP_RECV_EVENT\n"));
  3599. /*This is for target*/
  3600. break;
  3601. case OPC_OUB_DEV_INFO:
  3602. PM8001_MSG_DBG(pm8001_ha,
  3603. pm8001_printk("OPC_OUB_DEV_INFO\n"));
  3604. break;
  3605. case OPC_OUB_FW_FLASH_UPDATE:
  3606. PM8001_MSG_DBG(pm8001_ha,
  3607. pm8001_printk("OPC_OUB_FW_FLASH_UPDATE\n"));
  3608. mpi_fw_flash_update_resp(pm8001_ha, piomb);
  3609. break;
  3610. case OPC_OUB_GPIO_RESPONSE:
  3611. PM8001_MSG_DBG(pm8001_ha,
  3612. pm8001_printk("OPC_OUB_GPIO_RESPONSE\n"));
  3613. break;
  3614. case OPC_OUB_GPIO_EVENT:
  3615. PM8001_MSG_DBG(pm8001_ha,
  3616. pm8001_printk("OPC_OUB_GPIO_EVENT\n"));
  3617. break;
  3618. case OPC_OUB_GENERAL_EVENT:
  3619. PM8001_MSG_DBG(pm8001_ha,
  3620. pm8001_printk("OPC_OUB_GENERAL_EVENT\n"));
  3621. mpi_general_event(pm8001_ha, piomb);
  3622. break;
  3623. case OPC_OUB_SSP_ABORT_RSP:
  3624. PM8001_MSG_DBG(pm8001_ha,
  3625. pm8001_printk("OPC_OUB_SSP_ABORT_RSP\n"));
  3626. mpi_task_abort_resp(pm8001_ha, piomb);
  3627. break;
  3628. case OPC_OUB_SATA_ABORT_RSP:
  3629. PM8001_MSG_DBG(pm8001_ha,
  3630. pm8001_printk("OPC_OUB_SATA_ABORT_RSP\n"));
  3631. mpi_task_abort_resp(pm8001_ha, piomb);
  3632. break;
  3633. case OPC_OUB_SAS_DIAG_MODE_START_END:
  3634. PM8001_MSG_DBG(pm8001_ha,
  3635. pm8001_printk("OPC_OUB_SAS_DIAG_MODE_START_END\n"));
  3636. break;
  3637. case OPC_OUB_SAS_DIAG_EXECUTE:
  3638. PM8001_MSG_DBG(pm8001_ha,
  3639. pm8001_printk("OPC_OUB_SAS_DIAG_EXECUTE\n"));
  3640. break;
  3641. case OPC_OUB_GET_TIME_STAMP:
  3642. PM8001_MSG_DBG(pm8001_ha,
  3643. pm8001_printk("OPC_OUB_GET_TIME_STAMP\n"));
  3644. break;
  3645. case OPC_OUB_SAS_HW_EVENT_ACK:
  3646. PM8001_MSG_DBG(pm8001_ha,
  3647. pm8001_printk("OPC_OUB_SAS_HW_EVENT_ACK\n"));
  3648. break;
  3649. case OPC_OUB_PORT_CONTROL:
  3650. PM8001_MSG_DBG(pm8001_ha,
  3651. pm8001_printk("OPC_OUB_PORT_CONTROL\n"));
  3652. break;
  3653. case OPC_OUB_SMP_ABORT_RSP:
  3654. PM8001_MSG_DBG(pm8001_ha,
  3655. pm8001_printk("OPC_OUB_SMP_ABORT_RSP\n"));
  3656. mpi_task_abort_resp(pm8001_ha, piomb);
  3657. break;
  3658. case OPC_OUB_GET_NVMD_DATA:
  3659. PM8001_MSG_DBG(pm8001_ha,
  3660. pm8001_printk("OPC_OUB_GET_NVMD_DATA\n"));
  3661. mpi_get_nvmd_resp(pm8001_ha, piomb);
  3662. break;
  3663. case OPC_OUB_SET_NVMD_DATA:
  3664. PM8001_MSG_DBG(pm8001_ha,
  3665. pm8001_printk("OPC_OUB_SET_NVMD_DATA\n"));
  3666. mpi_set_nvmd_resp(pm8001_ha, piomb);
  3667. break;
  3668. case OPC_OUB_DEVICE_HANDLE_REMOVAL:
  3669. PM8001_MSG_DBG(pm8001_ha,
  3670. pm8001_printk("OPC_OUB_DEVICE_HANDLE_REMOVAL\n"));
  3671. break;
  3672. case OPC_OUB_SET_DEVICE_STATE:
  3673. PM8001_MSG_DBG(pm8001_ha,
  3674. pm8001_printk("OPC_OUB_SET_DEVICE_STATE\n"));
  3675. mpi_set_dev_state_resp(pm8001_ha, piomb);
  3676. break;
  3677. case OPC_OUB_GET_DEVICE_STATE:
  3678. PM8001_MSG_DBG(pm8001_ha,
  3679. pm8001_printk("OPC_OUB_GET_DEVICE_STATE\n"));
  3680. break;
  3681. case OPC_OUB_SET_DEV_INFO:
  3682. PM8001_MSG_DBG(pm8001_ha,
  3683. pm8001_printk("OPC_OUB_SET_DEV_INFO\n"));
  3684. break;
  3685. case OPC_OUB_SAS_RE_INITIALIZE:
  3686. PM8001_MSG_DBG(pm8001_ha,
  3687. pm8001_printk("OPC_OUB_SAS_RE_INITIALIZE\n"));
  3688. break;
  3689. default:
  3690. PM8001_MSG_DBG(pm8001_ha,
  3691. pm8001_printk("Unknown outbound Queue IOMB OPC = %x\n",
  3692. opc));
  3693. break;
  3694. }
  3695. }
  3696. static int process_oq(struct pm8001_hba_info *pm8001_ha)
  3697. {
  3698. struct outbound_queue_table *circularQ;
  3699. void *pMsg1 = NULL;
  3700. u8 uninitialized_var(bc);
  3701. u32 ret = MPI_IO_STATUS_FAIL;
  3702. unsigned long flags;
  3703. spin_lock_irqsave(&pm8001_ha->lock, flags);
  3704. circularQ = &pm8001_ha->outbnd_q_tbl[0];
  3705. do {
  3706. ret = mpi_msg_consume(pm8001_ha, circularQ, &pMsg1, &bc);
  3707. if (MPI_IO_STATUS_SUCCESS == ret) {
  3708. /* process the outbound message */
  3709. process_one_iomb(pm8001_ha, (void *)(pMsg1 - 4));
  3710. /* free the message from the outbound circular buffer */
  3711. mpi_msg_free_set(pm8001_ha, pMsg1, circularQ, bc);
  3712. }
  3713. if (MPI_IO_STATUS_BUSY == ret) {
  3714. /* Update the producer index from SPC */
  3715. circularQ->producer_index =
  3716. cpu_to_le32(pm8001_read_32(circularQ->pi_virt));
  3717. if (le32_to_cpu(circularQ->producer_index) ==
  3718. circularQ->consumer_idx)
  3719. /* OQ is empty */
  3720. break;
  3721. }
  3722. } while (1);
  3723. spin_unlock_irqrestore(&pm8001_ha->lock, flags);
  3724. return ret;
  3725. }
  3726. /* PCI_DMA_... to our direction translation. */
  3727. static const u8 data_dir_flags[] = {
  3728. [PCI_DMA_BIDIRECTIONAL] = DATA_DIR_BYRECIPIENT,/* UNSPECIFIED */
  3729. [PCI_DMA_TODEVICE] = DATA_DIR_OUT,/* OUTBOUND */
  3730. [PCI_DMA_FROMDEVICE] = DATA_DIR_IN,/* INBOUND */
  3731. [PCI_DMA_NONE] = DATA_DIR_NONE,/* NO TRANSFER */
  3732. };
  3733. static void
  3734. pm8001_chip_make_sg(struct scatterlist *scatter, int nr, void *prd)
  3735. {
  3736. int i;
  3737. struct scatterlist *sg;
  3738. struct pm8001_prd *buf_prd = prd;
  3739. for_each_sg(scatter, sg, nr, i) {
  3740. buf_prd->addr = cpu_to_le64(sg_dma_address(sg));
  3741. buf_prd->im_len.len = cpu_to_le32(sg_dma_len(sg));
  3742. buf_prd->im_len.e = 0;
  3743. buf_prd++;
  3744. }
  3745. }
  3746. static void build_smp_cmd(u32 deviceID, __le32 hTag, struct smp_req *psmp_cmd)
  3747. {
  3748. psmp_cmd->tag = hTag;
  3749. psmp_cmd->device_id = cpu_to_le32(deviceID);
  3750. psmp_cmd->len_ip_ir = cpu_to_le32(1|(1 << 1));
  3751. }
  3752. /**
  3753. * pm8001_chip_smp_req - send a SMP task to FW
  3754. * @pm8001_ha: our hba card information.
  3755. * @ccb: the ccb information this request used.
  3756. */
  3757. static int pm8001_chip_smp_req(struct pm8001_hba_info *pm8001_ha,
  3758. struct pm8001_ccb_info *ccb)
  3759. {
  3760. int elem, rc;
  3761. struct sas_task *task = ccb->task;
  3762. struct domain_device *dev = task->dev;
  3763. struct pm8001_device *pm8001_dev = dev->lldd_dev;
  3764. struct scatterlist *sg_req, *sg_resp;
  3765. u32 req_len, resp_len;
  3766. struct smp_req smp_cmd;
  3767. u32 opc;
  3768. struct inbound_queue_table *circularQ;
  3769. memset(&smp_cmd, 0, sizeof(smp_cmd));
  3770. /*
  3771. * DMA-map SMP request, response buffers
  3772. */
  3773. sg_req = &task->smp_task.smp_req;
  3774. elem = dma_map_sg(pm8001_ha->dev, sg_req, 1, PCI_DMA_TODEVICE);
  3775. if (!elem)
  3776. return -ENOMEM;
  3777. req_len = sg_dma_len(sg_req);
  3778. sg_resp = &task->smp_task.smp_resp;
  3779. elem = dma_map_sg(pm8001_ha->dev, sg_resp, 1, PCI_DMA_FROMDEVICE);
  3780. if (!elem) {
  3781. rc = -ENOMEM;
  3782. goto err_out;
  3783. }
  3784. resp_len = sg_dma_len(sg_resp);
  3785. /* must be in dwords */
  3786. if ((req_len & 0x3) || (resp_len & 0x3)) {
  3787. rc = -EINVAL;
  3788. goto err_out_2;
  3789. }
  3790. opc = OPC_INB_SMP_REQUEST;
  3791. circularQ = &pm8001_ha->inbnd_q_tbl[0];
  3792. smp_cmd.tag = cpu_to_le32(ccb->ccb_tag);
  3793. smp_cmd.long_smp_req.long_req_addr =
  3794. cpu_to_le64((u64)sg_dma_address(&task->smp_task.smp_req));
  3795. smp_cmd.long_smp_req.long_req_size =
  3796. cpu_to_le32((u32)sg_dma_len(&task->smp_task.smp_req)-4);
  3797. smp_cmd.long_smp_req.long_resp_addr =
  3798. cpu_to_le64((u64)sg_dma_address(&task->smp_task.smp_resp));
  3799. smp_cmd.long_smp_req.long_resp_size =
  3800. cpu_to_le32((u32)sg_dma_len(&task->smp_task.smp_resp)-4);
  3801. build_smp_cmd(pm8001_dev->device_id, smp_cmd.tag, &smp_cmd);
  3802. mpi_build_cmd(pm8001_ha, circularQ, opc, (u32 *)&smp_cmd);
  3803. return 0;
  3804. err_out_2:
  3805. dma_unmap_sg(pm8001_ha->dev, &ccb->task->smp_task.smp_resp, 1,
  3806. PCI_DMA_FROMDEVICE);
  3807. err_out:
  3808. dma_unmap_sg(pm8001_ha->dev, &ccb->task->smp_task.smp_req, 1,
  3809. PCI_DMA_TODEVICE);
  3810. return rc;
  3811. }
  3812. /**
  3813. * pm8001_chip_ssp_io_req - send a SSP task to FW
  3814. * @pm8001_ha: our hba card information.
  3815. * @ccb: the ccb information this request used.
  3816. */
  3817. static int pm8001_chip_ssp_io_req(struct pm8001_hba_info *pm8001_ha,
  3818. struct pm8001_ccb_info *ccb)
  3819. {
  3820. struct sas_task *task = ccb->task;
  3821. struct domain_device *dev = task->dev;
  3822. struct pm8001_device *pm8001_dev = dev->lldd_dev;
  3823. struct ssp_ini_io_start_req ssp_cmd;
  3824. u32 tag = ccb->ccb_tag;
  3825. int ret;
  3826. u64 phys_addr;
  3827. struct inbound_queue_table *circularQ;
  3828. u32 opc = OPC_INB_SSPINIIOSTART;
  3829. memset(&ssp_cmd, 0, sizeof(ssp_cmd));
  3830. memcpy(ssp_cmd.ssp_iu.lun, task->ssp_task.LUN, 8);
  3831. ssp_cmd.dir_m_tlr =
  3832. cpu_to_le32(data_dir_flags[task->data_dir] << 8 | 0x0);/*0 for
  3833. SAS 1.1 compatible TLR*/
  3834. ssp_cmd.data_len = cpu_to_le32(task->total_xfer_len);
  3835. ssp_cmd.device_id = cpu_to_le32(pm8001_dev->device_id);
  3836. ssp_cmd.tag = cpu_to_le32(tag);
  3837. if (task->ssp_task.enable_first_burst)
  3838. ssp_cmd.ssp_iu.efb_prio_attr |= 0x80;
  3839. ssp_cmd.ssp_iu.efb_prio_attr |= (task->ssp_task.task_prio << 3);
  3840. ssp_cmd.ssp_iu.efb_prio_attr |= (task->ssp_task.task_attr & 7);
  3841. memcpy(ssp_cmd.ssp_iu.cdb, task->ssp_task.cdb, 16);
  3842. circularQ = &pm8001_ha->inbnd_q_tbl[0];
  3843. /* fill in PRD (scatter/gather) table, if any */
  3844. if (task->num_scatter > 1) {
  3845. pm8001_chip_make_sg(task->scatter, ccb->n_elem, ccb->buf_prd);
  3846. phys_addr = ccb->ccb_dma_handle +
  3847. offsetof(struct pm8001_ccb_info, buf_prd[0]);
  3848. ssp_cmd.addr_low = cpu_to_le32(lower_32_bits(phys_addr));
  3849. ssp_cmd.addr_high = cpu_to_le32(upper_32_bits(phys_addr));
  3850. ssp_cmd.esgl = cpu_to_le32(1<<31);
  3851. } else if (task->num_scatter == 1) {
  3852. u64 dma_addr = sg_dma_address(task->scatter);
  3853. ssp_cmd.addr_low = cpu_to_le32(lower_32_bits(dma_addr));
  3854. ssp_cmd.addr_high = cpu_to_le32(upper_32_bits(dma_addr));
  3855. ssp_cmd.len = cpu_to_le32(task->total_xfer_len);
  3856. ssp_cmd.esgl = 0;
  3857. } else if (task->num_scatter == 0) {
  3858. ssp_cmd.addr_low = 0;
  3859. ssp_cmd.addr_high = 0;
  3860. ssp_cmd.len = cpu_to_le32(task->total_xfer_len);
  3861. ssp_cmd.esgl = 0;
  3862. }
  3863. ret = mpi_build_cmd(pm8001_ha, circularQ, opc, &ssp_cmd);
  3864. return ret;
  3865. }
  3866. static int pm8001_chip_sata_req(struct pm8001_hba_info *pm8001_ha,
  3867. struct pm8001_ccb_info *ccb)
  3868. {
  3869. struct sas_task *task = ccb->task;
  3870. struct domain_device *dev = task->dev;
  3871. struct pm8001_device *pm8001_ha_dev = dev->lldd_dev;
  3872. u32 tag = ccb->ccb_tag;
  3873. int ret;
  3874. struct sata_start_req sata_cmd;
  3875. u32 hdr_tag, ncg_tag = 0;
  3876. u64 phys_addr;
  3877. u32 ATAP = 0x0;
  3878. u32 dir;
  3879. struct inbound_queue_table *circularQ;
  3880. u32 opc = OPC_INB_SATA_HOST_OPSTART;
  3881. memset(&sata_cmd, 0, sizeof(sata_cmd));
  3882. circularQ = &pm8001_ha->inbnd_q_tbl[0];
  3883. if (task->data_dir == PCI_DMA_NONE) {
  3884. ATAP = 0x04; /* no data*/
  3885. PM8001_IO_DBG(pm8001_ha, pm8001_printk("no data\n"));
  3886. } else if (likely(!task->ata_task.device_control_reg_update)) {
  3887. if (task->ata_task.dma_xfer) {
  3888. ATAP = 0x06; /* DMA */
  3889. PM8001_IO_DBG(pm8001_ha, pm8001_printk("DMA\n"));
  3890. } else {
  3891. ATAP = 0x05; /* PIO*/
  3892. PM8001_IO_DBG(pm8001_ha, pm8001_printk("PIO\n"));
  3893. }
  3894. if (task->ata_task.use_ncq &&
  3895. dev->sata_dev.command_set != ATAPI_COMMAND_SET) {
  3896. ATAP = 0x07; /* FPDMA */
  3897. PM8001_IO_DBG(pm8001_ha, pm8001_printk("FPDMA\n"));
  3898. }
  3899. }
  3900. if (task->ata_task.use_ncq && pm8001_get_ncq_tag(task, &hdr_tag))
  3901. ncg_tag = hdr_tag;
  3902. dir = data_dir_flags[task->data_dir] << 8;
  3903. sata_cmd.tag = cpu_to_le32(tag);
  3904. sata_cmd.device_id = cpu_to_le32(pm8001_ha_dev->device_id);
  3905. sata_cmd.data_len = cpu_to_le32(task->total_xfer_len);
  3906. sata_cmd.ncqtag_atap_dir_m =
  3907. cpu_to_le32(((ncg_tag & 0xff)<<16)|((ATAP & 0x3f) << 10) | dir);
  3908. sata_cmd.sata_fis = task->ata_task.fis;
  3909. if (likely(!task->ata_task.device_control_reg_update))
  3910. sata_cmd.sata_fis.flags |= 0x80;/* C=1: update ATA cmd reg */
  3911. sata_cmd.sata_fis.flags &= 0xF0;/* PM_PORT field shall be 0 */
  3912. /* fill in PRD (scatter/gather) table, if any */
  3913. if (task->num_scatter > 1) {
  3914. pm8001_chip_make_sg(task->scatter, ccb->n_elem, ccb->buf_prd);
  3915. phys_addr = ccb->ccb_dma_handle +
  3916. offsetof(struct pm8001_ccb_info, buf_prd[0]);
  3917. sata_cmd.addr_low = lower_32_bits(phys_addr);
  3918. sata_cmd.addr_high = upper_32_bits(phys_addr);
  3919. sata_cmd.esgl = cpu_to_le32(1 << 31);
  3920. } else if (task->num_scatter == 1) {
  3921. u64 dma_addr = sg_dma_address(task->scatter);
  3922. sata_cmd.addr_low = lower_32_bits(dma_addr);
  3923. sata_cmd.addr_high = upper_32_bits(dma_addr);
  3924. sata_cmd.len = cpu_to_le32(task->total_xfer_len);
  3925. sata_cmd.esgl = 0;
  3926. } else if (task->num_scatter == 0) {
  3927. sata_cmd.addr_low = 0;
  3928. sata_cmd.addr_high = 0;
  3929. sata_cmd.len = cpu_to_le32(task->total_xfer_len);
  3930. sata_cmd.esgl = 0;
  3931. }
  3932. ret = mpi_build_cmd(pm8001_ha, circularQ, opc, &sata_cmd);
  3933. return ret;
  3934. }
  3935. /**
  3936. * pm8001_chip_phy_start_req - start phy via PHY_START COMMAND
  3937. * @pm8001_ha: our hba card information.
  3938. * @num: the inbound queue number
  3939. * @phy_id: the phy id which we wanted to start up.
  3940. */
  3941. static int
  3942. pm8001_chip_phy_start_req(struct pm8001_hba_info *pm8001_ha, u8 phy_id)
  3943. {
  3944. struct phy_start_req payload;
  3945. struct inbound_queue_table *circularQ;
  3946. int ret;
  3947. u32 tag = 0x01;
  3948. u32 opcode = OPC_INB_PHYSTART;
  3949. circularQ = &pm8001_ha->inbnd_q_tbl[0];
  3950. memset(&payload, 0, sizeof(payload));
  3951. payload.tag = cpu_to_le32(tag);
  3952. /*
  3953. ** [0:7] PHY Identifier
  3954. ** [8:11] link rate 1.5G, 3G, 6G
  3955. ** [12:13] link mode 01b SAS mode; 10b SATA mode; 11b both
  3956. ** [14] 0b disable spin up hold; 1b enable spin up hold
  3957. */
  3958. payload.ase_sh_lm_slr_phyid = cpu_to_le32(SPINHOLD_DISABLE |
  3959. LINKMODE_AUTO | LINKRATE_15 |
  3960. LINKRATE_30 | LINKRATE_60 | phy_id);
  3961. payload.sas_identify.dev_type = SAS_END_DEV;
  3962. payload.sas_identify.initiator_bits = SAS_PROTOCOL_ALL;
  3963. memcpy(payload.sas_identify.sas_addr,
  3964. pm8001_ha->sas_addr, SAS_ADDR_SIZE);
  3965. payload.sas_identify.phy_id = phy_id;
  3966. ret = mpi_build_cmd(pm8001_ha, circularQ, opcode, &payload);
  3967. return ret;
  3968. }
  3969. /**
  3970. * pm8001_chip_phy_stop_req - start phy via PHY_STOP COMMAND
  3971. * @pm8001_ha: our hba card information.
  3972. * @num: the inbound queue number
  3973. * @phy_id: the phy id which we wanted to start up.
  3974. */
  3975. static int pm8001_chip_phy_stop_req(struct pm8001_hba_info *pm8001_ha,
  3976. u8 phy_id)
  3977. {
  3978. struct phy_stop_req payload;
  3979. struct inbound_queue_table *circularQ;
  3980. int ret;
  3981. u32 tag = 0x01;
  3982. u32 opcode = OPC_INB_PHYSTOP;
  3983. circularQ = &pm8001_ha->inbnd_q_tbl[0];
  3984. memset(&payload, 0, sizeof(payload));
  3985. payload.tag = cpu_to_le32(tag);
  3986. payload.phy_id = cpu_to_le32(phy_id);
  3987. ret = mpi_build_cmd(pm8001_ha, circularQ, opcode, &payload);
  3988. return ret;
  3989. }
  3990. /**
  3991. * see comments on mpi_reg_resp.
  3992. */
  3993. static int pm8001_chip_reg_dev_req(struct pm8001_hba_info *pm8001_ha,
  3994. struct pm8001_device *pm8001_dev, u32 flag)
  3995. {
  3996. struct reg_dev_req payload;
  3997. u32 opc;
  3998. u32 stp_sspsmp_sata = 0x4;
  3999. struct inbound_queue_table *circularQ;
  4000. u32 linkrate, phy_id;
  4001. int rc, tag = 0xdeadbeef;
  4002. struct pm8001_ccb_info *ccb;
  4003. u8 retryFlag = 0x1;
  4004. u16 firstBurstSize = 0;
  4005. u16 ITNT = 2000;
  4006. struct domain_device *dev = pm8001_dev->sas_device;
  4007. struct domain_device *parent_dev = dev->parent;
  4008. circularQ = &pm8001_ha->inbnd_q_tbl[0];
  4009. memset(&payload, 0, sizeof(payload));
  4010. rc = pm8001_tag_alloc(pm8001_ha, &tag);
  4011. if (rc)
  4012. return rc;
  4013. ccb = &pm8001_ha->ccb_info[tag];
  4014. ccb->device = pm8001_dev;
  4015. ccb->ccb_tag = tag;
  4016. payload.tag = cpu_to_le32(tag);
  4017. if (flag == 1)
  4018. stp_sspsmp_sata = 0x02; /*direct attached sata */
  4019. else {
  4020. if (pm8001_dev->dev_type == SATA_DEV)
  4021. stp_sspsmp_sata = 0x00; /* stp*/
  4022. else if (pm8001_dev->dev_type == SAS_END_DEV ||
  4023. pm8001_dev->dev_type == EDGE_DEV ||
  4024. pm8001_dev->dev_type == FANOUT_DEV)
  4025. stp_sspsmp_sata = 0x01; /*ssp or smp*/
  4026. }
  4027. if (parent_dev && DEV_IS_EXPANDER(parent_dev->dev_type))
  4028. phy_id = parent_dev->ex_dev.ex_phy->phy_id;
  4029. else
  4030. phy_id = pm8001_dev->attached_phy;
  4031. opc = OPC_INB_REG_DEV;
  4032. linkrate = (pm8001_dev->sas_device->linkrate < dev->port->linkrate) ?
  4033. pm8001_dev->sas_device->linkrate : dev->port->linkrate;
  4034. payload.phyid_portid =
  4035. cpu_to_le32(((pm8001_dev->sas_device->port->id) & 0x0F) |
  4036. ((phy_id & 0x0F) << 4));
  4037. payload.dtype_dlr_retry = cpu_to_le32((retryFlag & 0x01) |
  4038. ((linkrate & 0x0F) * 0x1000000) |
  4039. ((stp_sspsmp_sata & 0x03) * 0x10000000));
  4040. payload.firstburstsize_ITNexustimeout =
  4041. cpu_to_le32(ITNT | (firstBurstSize * 0x10000));
  4042. memcpy(payload.sas_addr, pm8001_dev->sas_device->sas_addr,
  4043. SAS_ADDR_SIZE);
  4044. rc = mpi_build_cmd(pm8001_ha, circularQ, opc, &payload);
  4045. return rc;
  4046. }
  4047. /**
  4048. * see comments on mpi_reg_resp.
  4049. */
  4050. static int pm8001_chip_dereg_dev_req(struct pm8001_hba_info *pm8001_ha,
  4051. u32 device_id)
  4052. {
  4053. struct dereg_dev_req payload;
  4054. u32 opc = OPC_INB_DEREG_DEV_HANDLE;
  4055. int ret;
  4056. struct inbound_queue_table *circularQ;
  4057. circularQ = &pm8001_ha->inbnd_q_tbl[0];
  4058. memset(&payload, 0, sizeof(payload));
  4059. payload.tag = cpu_to_le32(1);
  4060. payload.device_id = cpu_to_le32(device_id);
  4061. PM8001_MSG_DBG(pm8001_ha,
  4062. pm8001_printk("unregister device device_id = %d\n", device_id));
  4063. ret = mpi_build_cmd(pm8001_ha, circularQ, opc, &payload);
  4064. return ret;
  4065. }
  4066. /**
  4067. * pm8001_chip_phy_ctl_req - support the local phy operation
  4068. * @pm8001_ha: our hba card information.
  4069. * @num: the inbound queue number
  4070. * @phy_id: the phy id which we wanted to operate
  4071. * @phy_op:
  4072. */
  4073. static int pm8001_chip_phy_ctl_req(struct pm8001_hba_info *pm8001_ha,
  4074. u32 phyId, u32 phy_op)
  4075. {
  4076. struct local_phy_ctl_req payload;
  4077. struct inbound_queue_table *circularQ;
  4078. int ret;
  4079. u32 opc = OPC_INB_LOCAL_PHY_CONTROL;
  4080. memset(&payload, 0, sizeof(payload));
  4081. circularQ = &pm8001_ha->inbnd_q_tbl[0];
  4082. payload.tag = cpu_to_le32(1);
  4083. payload.phyop_phyid =
  4084. cpu_to_le32(((phy_op & 0xff) << 8) | (phyId & 0x0F));
  4085. ret = mpi_build_cmd(pm8001_ha, circularQ, opc, &payload);
  4086. return ret;
  4087. }
  4088. static u32 pm8001_chip_is_our_interupt(struct pm8001_hba_info *pm8001_ha)
  4089. {
  4090. u32 value;
  4091. #ifdef PM8001_USE_MSIX
  4092. return 1;
  4093. #endif
  4094. value = pm8001_cr32(pm8001_ha, 0, MSGU_ODR);
  4095. if (value)
  4096. return 1;
  4097. return 0;
  4098. }
  4099. /**
  4100. * pm8001_chip_isr - PM8001 isr handler.
  4101. * @pm8001_ha: our hba card information.
  4102. * @irq: irq number.
  4103. * @stat: stat.
  4104. */
  4105. static irqreturn_t
  4106. pm8001_chip_isr(struct pm8001_hba_info *pm8001_ha)
  4107. {
  4108. pm8001_chip_interrupt_disable(pm8001_ha);
  4109. process_oq(pm8001_ha);
  4110. pm8001_chip_interrupt_enable(pm8001_ha);
  4111. return IRQ_HANDLED;
  4112. }
  4113. static int send_task_abort(struct pm8001_hba_info *pm8001_ha, u32 opc,
  4114. u32 dev_id, u8 flag, u32 task_tag, u32 cmd_tag)
  4115. {
  4116. struct task_abort_req task_abort;
  4117. struct inbound_queue_table *circularQ;
  4118. int ret;
  4119. circularQ = &pm8001_ha->inbnd_q_tbl[0];
  4120. memset(&task_abort, 0, sizeof(task_abort));
  4121. if (ABORT_SINGLE == (flag & ABORT_MASK)) {
  4122. task_abort.abort_all = 0;
  4123. task_abort.device_id = cpu_to_le32(dev_id);
  4124. task_abort.tag_to_abort = cpu_to_le32(task_tag);
  4125. task_abort.tag = cpu_to_le32(cmd_tag);
  4126. } else if (ABORT_ALL == (flag & ABORT_MASK)) {
  4127. task_abort.abort_all = cpu_to_le32(1);
  4128. task_abort.device_id = cpu_to_le32(dev_id);
  4129. task_abort.tag = cpu_to_le32(cmd_tag);
  4130. }
  4131. ret = mpi_build_cmd(pm8001_ha, circularQ, opc, &task_abort);
  4132. return ret;
  4133. }
  4134. /**
  4135. * pm8001_chip_abort_task - SAS abort task when error or exception happened.
  4136. * @task: the task we wanted to aborted.
  4137. * @flag: the abort flag.
  4138. */
  4139. static int pm8001_chip_abort_task(struct pm8001_hba_info *pm8001_ha,
  4140. struct pm8001_device *pm8001_dev, u8 flag, u32 task_tag, u32 cmd_tag)
  4141. {
  4142. u32 opc, device_id;
  4143. int rc = TMF_RESP_FUNC_FAILED;
  4144. PM8001_EH_DBG(pm8001_ha, pm8001_printk("cmd_tag = %x, abort task tag"
  4145. " = %x", cmd_tag, task_tag));
  4146. if (pm8001_dev->dev_type == SAS_END_DEV)
  4147. opc = OPC_INB_SSP_ABORT;
  4148. else if (pm8001_dev->dev_type == SATA_DEV)
  4149. opc = OPC_INB_SATA_ABORT;
  4150. else
  4151. opc = OPC_INB_SMP_ABORT;/* SMP */
  4152. device_id = pm8001_dev->device_id;
  4153. rc = send_task_abort(pm8001_ha, opc, device_id, flag,
  4154. task_tag, cmd_tag);
  4155. if (rc != TMF_RESP_FUNC_COMPLETE)
  4156. PM8001_EH_DBG(pm8001_ha, pm8001_printk("rc= %d\n", rc));
  4157. return rc;
  4158. }
  4159. /**
  4160. * pm8001_chip_ssp_tm_req - built the task management command.
  4161. * @pm8001_ha: our hba card information.
  4162. * @ccb: the ccb information.
  4163. * @tmf: task management function.
  4164. */
  4165. static int pm8001_chip_ssp_tm_req(struct pm8001_hba_info *pm8001_ha,
  4166. struct pm8001_ccb_info *ccb, struct pm8001_tmf_task *tmf)
  4167. {
  4168. struct sas_task *task = ccb->task;
  4169. struct domain_device *dev = task->dev;
  4170. struct pm8001_device *pm8001_dev = dev->lldd_dev;
  4171. u32 opc = OPC_INB_SSPINITMSTART;
  4172. struct inbound_queue_table *circularQ;
  4173. struct ssp_ini_tm_start_req sspTMCmd;
  4174. int ret;
  4175. memset(&sspTMCmd, 0, sizeof(sspTMCmd));
  4176. sspTMCmd.device_id = cpu_to_le32(pm8001_dev->device_id);
  4177. sspTMCmd.relate_tag = cpu_to_le32(tmf->tag_of_task_to_be_managed);
  4178. sspTMCmd.tmf = cpu_to_le32(tmf->tmf);
  4179. memcpy(sspTMCmd.lun, task->ssp_task.LUN, 8);
  4180. sspTMCmd.tag = cpu_to_le32(ccb->ccb_tag);
  4181. circularQ = &pm8001_ha->inbnd_q_tbl[0];
  4182. ret = mpi_build_cmd(pm8001_ha, circularQ, opc, &sspTMCmd);
  4183. return ret;
  4184. }
  4185. static int pm8001_chip_get_nvmd_req(struct pm8001_hba_info *pm8001_ha,
  4186. void *payload)
  4187. {
  4188. u32 opc = OPC_INB_GET_NVMD_DATA;
  4189. u32 nvmd_type;
  4190. int rc;
  4191. u32 tag;
  4192. struct pm8001_ccb_info *ccb;
  4193. struct inbound_queue_table *circularQ;
  4194. struct get_nvm_data_req nvmd_req;
  4195. struct fw_control_ex *fw_control_context;
  4196. struct pm8001_ioctl_payload *ioctl_payload = payload;
  4197. nvmd_type = ioctl_payload->minor_function;
  4198. fw_control_context = kzalloc(sizeof(struct fw_control_ex), GFP_KERNEL);
  4199. if (!fw_control_context)
  4200. return -ENOMEM;
  4201. fw_control_context->usrAddr = (u8 *)&ioctl_payload->func_specific[0];
  4202. fw_control_context->len = ioctl_payload->length;
  4203. circularQ = &pm8001_ha->inbnd_q_tbl[0];
  4204. memset(&nvmd_req, 0, sizeof(nvmd_req));
  4205. rc = pm8001_tag_alloc(pm8001_ha, &tag);
  4206. if (rc) {
  4207. kfree(fw_control_context);
  4208. return rc;
  4209. }
  4210. ccb = &pm8001_ha->ccb_info[tag];
  4211. ccb->ccb_tag = tag;
  4212. ccb->fw_control_context = fw_control_context;
  4213. nvmd_req.tag = cpu_to_le32(tag);
  4214. switch (nvmd_type) {
  4215. case TWI_DEVICE: {
  4216. u32 twi_addr, twi_page_size;
  4217. twi_addr = 0xa8;
  4218. twi_page_size = 2;
  4219. nvmd_req.len_ir_vpdd = cpu_to_le32(IPMode | twi_addr << 16 |
  4220. twi_page_size << 8 | TWI_DEVICE);
  4221. nvmd_req.resp_len = cpu_to_le32(ioctl_payload->length);
  4222. nvmd_req.resp_addr_hi =
  4223. cpu_to_le32(pm8001_ha->memoryMap.region[NVMD].phys_addr_hi);
  4224. nvmd_req.resp_addr_lo =
  4225. cpu_to_le32(pm8001_ha->memoryMap.region[NVMD].phys_addr_lo);
  4226. break;
  4227. }
  4228. case C_SEEPROM: {
  4229. nvmd_req.len_ir_vpdd = cpu_to_le32(IPMode | C_SEEPROM);
  4230. nvmd_req.resp_len = cpu_to_le32(ioctl_payload->length);
  4231. nvmd_req.resp_addr_hi =
  4232. cpu_to_le32(pm8001_ha->memoryMap.region[NVMD].phys_addr_hi);
  4233. nvmd_req.resp_addr_lo =
  4234. cpu_to_le32(pm8001_ha->memoryMap.region[NVMD].phys_addr_lo);
  4235. break;
  4236. }
  4237. case VPD_FLASH: {
  4238. nvmd_req.len_ir_vpdd = cpu_to_le32(IPMode | VPD_FLASH);
  4239. nvmd_req.resp_len = cpu_to_le32(ioctl_payload->length);
  4240. nvmd_req.resp_addr_hi =
  4241. cpu_to_le32(pm8001_ha->memoryMap.region[NVMD].phys_addr_hi);
  4242. nvmd_req.resp_addr_lo =
  4243. cpu_to_le32(pm8001_ha->memoryMap.region[NVMD].phys_addr_lo);
  4244. break;
  4245. }
  4246. case EXPAN_ROM: {
  4247. nvmd_req.len_ir_vpdd = cpu_to_le32(IPMode | EXPAN_ROM);
  4248. nvmd_req.resp_len = cpu_to_le32(ioctl_payload->length);
  4249. nvmd_req.resp_addr_hi =
  4250. cpu_to_le32(pm8001_ha->memoryMap.region[NVMD].phys_addr_hi);
  4251. nvmd_req.resp_addr_lo =
  4252. cpu_to_le32(pm8001_ha->memoryMap.region[NVMD].phys_addr_lo);
  4253. break;
  4254. }
  4255. default:
  4256. break;
  4257. }
  4258. rc = mpi_build_cmd(pm8001_ha, circularQ, opc, &nvmd_req);
  4259. return rc;
  4260. }
  4261. static int pm8001_chip_set_nvmd_req(struct pm8001_hba_info *pm8001_ha,
  4262. void *payload)
  4263. {
  4264. u32 opc = OPC_INB_SET_NVMD_DATA;
  4265. u32 nvmd_type;
  4266. int rc;
  4267. u32 tag;
  4268. struct pm8001_ccb_info *ccb;
  4269. struct inbound_queue_table *circularQ;
  4270. struct set_nvm_data_req nvmd_req;
  4271. struct fw_control_ex *fw_control_context;
  4272. struct pm8001_ioctl_payload *ioctl_payload = payload;
  4273. nvmd_type = ioctl_payload->minor_function;
  4274. fw_control_context = kzalloc(sizeof(struct fw_control_ex), GFP_KERNEL);
  4275. if (!fw_control_context)
  4276. return -ENOMEM;
  4277. circularQ = &pm8001_ha->inbnd_q_tbl[0];
  4278. memcpy(pm8001_ha->memoryMap.region[NVMD].virt_ptr,
  4279. ioctl_payload->func_specific,
  4280. ioctl_payload->length);
  4281. memset(&nvmd_req, 0, sizeof(nvmd_req));
  4282. rc = pm8001_tag_alloc(pm8001_ha, &tag);
  4283. if (rc) {
  4284. kfree(fw_control_context);
  4285. return rc;
  4286. }
  4287. ccb = &pm8001_ha->ccb_info[tag];
  4288. ccb->fw_control_context = fw_control_context;
  4289. ccb->ccb_tag = tag;
  4290. nvmd_req.tag = cpu_to_le32(tag);
  4291. switch (nvmd_type) {
  4292. case TWI_DEVICE: {
  4293. u32 twi_addr, twi_page_size;
  4294. twi_addr = 0xa8;
  4295. twi_page_size = 2;
  4296. nvmd_req.reserved[0] = cpu_to_le32(0xFEDCBA98);
  4297. nvmd_req.len_ir_vpdd = cpu_to_le32(IPMode | twi_addr << 16 |
  4298. twi_page_size << 8 | TWI_DEVICE);
  4299. nvmd_req.resp_len = cpu_to_le32(ioctl_payload->length);
  4300. nvmd_req.resp_addr_hi =
  4301. cpu_to_le32(pm8001_ha->memoryMap.region[NVMD].phys_addr_hi);
  4302. nvmd_req.resp_addr_lo =
  4303. cpu_to_le32(pm8001_ha->memoryMap.region[NVMD].phys_addr_lo);
  4304. break;
  4305. }
  4306. case C_SEEPROM:
  4307. nvmd_req.len_ir_vpdd = cpu_to_le32(IPMode | C_SEEPROM);
  4308. nvmd_req.resp_len = cpu_to_le32(ioctl_payload->length);
  4309. nvmd_req.reserved[0] = cpu_to_le32(0xFEDCBA98);
  4310. nvmd_req.resp_addr_hi =
  4311. cpu_to_le32(pm8001_ha->memoryMap.region[NVMD].phys_addr_hi);
  4312. nvmd_req.resp_addr_lo =
  4313. cpu_to_le32(pm8001_ha->memoryMap.region[NVMD].phys_addr_lo);
  4314. break;
  4315. case VPD_FLASH:
  4316. nvmd_req.len_ir_vpdd = cpu_to_le32(IPMode | VPD_FLASH);
  4317. nvmd_req.resp_len = cpu_to_le32(ioctl_payload->length);
  4318. nvmd_req.reserved[0] = cpu_to_le32(0xFEDCBA98);
  4319. nvmd_req.resp_addr_hi =
  4320. cpu_to_le32(pm8001_ha->memoryMap.region[NVMD].phys_addr_hi);
  4321. nvmd_req.resp_addr_lo =
  4322. cpu_to_le32(pm8001_ha->memoryMap.region[NVMD].phys_addr_lo);
  4323. break;
  4324. case EXPAN_ROM:
  4325. nvmd_req.len_ir_vpdd = cpu_to_le32(IPMode | EXPAN_ROM);
  4326. nvmd_req.resp_len = cpu_to_le32(ioctl_payload->length);
  4327. nvmd_req.reserved[0] = cpu_to_le32(0xFEDCBA98);
  4328. nvmd_req.resp_addr_hi =
  4329. cpu_to_le32(pm8001_ha->memoryMap.region[NVMD].phys_addr_hi);
  4330. nvmd_req.resp_addr_lo =
  4331. cpu_to_le32(pm8001_ha->memoryMap.region[NVMD].phys_addr_lo);
  4332. break;
  4333. default:
  4334. break;
  4335. }
  4336. rc = mpi_build_cmd(pm8001_ha, circularQ, opc, &nvmd_req);
  4337. return rc;
  4338. }
  4339. /**
  4340. * pm8001_chip_fw_flash_update_build - support the firmware update operation
  4341. * @pm8001_ha: our hba card information.
  4342. * @fw_flash_updata_info: firmware flash update param
  4343. */
  4344. static int
  4345. pm8001_chip_fw_flash_update_build(struct pm8001_hba_info *pm8001_ha,
  4346. void *fw_flash_updata_info, u32 tag)
  4347. {
  4348. struct fw_flash_Update_req payload;
  4349. struct fw_flash_updata_info *info;
  4350. struct inbound_queue_table *circularQ;
  4351. int ret;
  4352. u32 opc = OPC_INB_FW_FLASH_UPDATE;
  4353. memset(&payload, 0, sizeof(struct fw_flash_Update_req));
  4354. circularQ = &pm8001_ha->inbnd_q_tbl[0];
  4355. info = fw_flash_updata_info;
  4356. payload.tag = cpu_to_le32(tag);
  4357. payload.cur_image_len = cpu_to_le32(info->cur_image_len);
  4358. payload.cur_image_offset = cpu_to_le32(info->cur_image_offset);
  4359. payload.total_image_len = cpu_to_le32(info->total_image_len);
  4360. payload.len = info->sgl.im_len.len ;
  4361. payload.sgl_addr_lo =
  4362. cpu_to_le32(lower_32_bits(le64_to_cpu(info->sgl.addr)));
  4363. payload.sgl_addr_hi =
  4364. cpu_to_le32(upper_32_bits(le64_to_cpu(info->sgl.addr)));
  4365. ret = mpi_build_cmd(pm8001_ha, circularQ, opc, &payload);
  4366. return ret;
  4367. }
  4368. static int
  4369. pm8001_chip_fw_flash_update_req(struct pm8001_hba_info *pm8001_ha,
  4370. void *payload)
  4371. {
  4372. struct fw_flash_updata_info flash_update_info;
  4373. struct fw_control_info *fw_control;
  4374. struct fw_control_ex *fw_control_context;
  4375. int rc;
  4376. u32 tag;
  4377. struct pm8001_ccb_info *ccb;
  4378. void *buffer = NULL;
  4379. dma_addr_t phys_addr;
  4380. u32 phys_addr_hi;
  4381. u32 phys_addr_lo;
  4382. struct pm8001_ioctl_payload *ioctl_payload = payload;
  4383. fw_control_context = kzalloc(sizeof(struct fw_control_ex), GFP_KERNEL);
  4384. if (!fw_control_context)
  4385. return -ENOMEM;
  4386. fw_control = (struct fw_control_info *)&ioctl_payload->func_specific[0];
  4387. if (fw_control->len != 0) {
  4388. if (pm8001_mem_alloc(pm8001_ha->pdev,
  4389. (void **)&buffer,
  4390. &phys_addr,
  4391. &phys_addr_hi,
  4392. &phys_addr_lo,
  4393. fw_control->len, 0) != 0) {
  4394. PM8001_FAIL_DBG(pm8001_ha,
  4395. pm8001_printk("Mem alloc failure\n"));
  4396. kfree(fw_control_context);
  4397. return -ENOMEM;
  4398. }
  4399. }
  4400. memcpy(buffer, fw_control->buffer, fw_control->len);
  4401. flash_update_info.sgl.addr = cpu_to_le64(phys_addr);
  4402. flash_update_info.sgl.im_len.len = cpu_to_le32(fw_control->len);
  4403. flash_update_info.sgl.im_len.e = 0;
  4404. flash_update_info.cur_image_offset = fw_control->offset;
  4405. flash_update_info.cur_image_len = fw_control->len;
  4406. flash_update_info.total_image_len = fw_control->size;
  4407. fw_control_context->fw_control = fw_control;
  4408. fw_control_context->virtAddr = buffer;
  4409. fw_control_context->len = fw_control->len;
  4410. rc = pm8001_tag_alloc(pm8001_ha, &tag);
  4411. if (rc) {
  4412. kfree(fw_control_context);
  4413. return rc;
  4414. }
  4415. ccb = &pm8001_ha->ccb_info[tag];
  4416. ccb->fw_control_context = fw_control_context;
  4417. ccb->ccb_tag = tag;
  4418. rc = pm8001_chip_fw_flash_update_build(pm8001_ha, &flash_update_info,
  4419. tag);
  4420. return rc;
  4421. }
  4422. static int
  4423. pm8001_chip_set_dev_state_req(struct pm8001_hba_info *pm8001_ha,
  4424. struct pm8001_device *pm8001_dev, u32 state)
  4425. {
  4426. struct set_dev_state_req payload;
  4427. struct inbound_queue_table *circularQ;
  4428. struct pm8001_ccb_info *ccb;
  4429. int rc;
  4430. u32 tag;
  4431. u32 opc = OPC_INB_SET_DEVICE_STATE;
  4432. memset(&payload, 0, sizeof(payload));
  4433. rc = pm8001_tag_alloc(pm8001_ha, &tag);
  4434. if (rc)
  4435. return -1;
  4436. ccb = &pm8001_ha->ccb_info[tag];
  4437. ccb->ccb_tag = tag;
  4438. ccb->device = pm8001_dev;
  4439. circularQ = &pm8001_ha->inbnd_q_tbl[0];
  4440. payload.tag = cpu_to_le32(tag);
  4441. payload.device_id = cpu_to_le32(pm8001_dev->device_id);
  4442. payload.nds = cpu_to_le32(state);
  4443. rc = mpi_build_cmd(pm8001_ha, circularQ, opc, &payload);
  4444. return rc;
  4445. }
  4446. static int
  4447. pm8001_chip_sas_re_initialization(struct pm8001_hba_info *pm8001_ha)
  4448. {
  4449. struct sas_re_initialization_req payload;
  4450. struct inbound_queue_table *circularQ;
  4451. struct pm8001_ccb_info *ccb;
  4452. int rc;
  4453. u32 tag;
  4454. u32 opc = OPC_INB_SAS_RE_INITIALIZE;
  4455. memset(&payload, 0, sizeof(payload));
  4456. rc = pm8001_tag_alloc(pm8001_ha, &tag);
  4457. if (rc)
  4458. return -1;
  4459. ccb = &pm8001_ha->ccb_info[tag];
  4460. ccb->ccb_tag = tag;
  4461. circularQ = &pm8001_ha->inbnd_q_tbl[0];
  4462. payload.tag = cpu_to_le32(tag);
  4463. payload.SSAHOLT = cpu_to_le32(0xd << 25);
  4464. payload.sata_hol_tmo = cpu_to_le32(80);
  4465. payload.open_reject_cmdretries_data_retries = cpu_to_le32(0xff00ff);
  4466. rc = mpi_build_cmd(pm8001_ha, circularQ, opc, &payload);
  4467. return rc;
  4468. }
  4469. const struct pm8001_dispatch pm8001_8001_dispatch = {
  4470. .name = "pmc8001",
  4471. .chip_init = pm8001_chip_init,
  4472. .chip_soft_rst = pm8001_chip_soft_rst,
  4473. .chip_rst = pm8001_hw_chip_rst,
  4474. .chip_iounmap = pm8001_chip_iounmap,
  4475. .isr = pm8001_chip_isr,
  4476. .is_our_interupt = pm8001_chip_is_our_interupt,
  4477. .isr_process_oq = process_oq,
  4478. .interrupt_enable = pm8001_chip_interrupt_enable,
  4479. .interrupt_disable = pm8001_chip_interrupt_disable,
  4480. .make_prd = pm8001_chip_make_sg,
  4481. .smp_req = pm8001_chip_smp_req,
  4482. .ssp_io_req = pm8001_chip_ssp_io_req,
  4483. .sata_req = pm8001_chip_sata_req,
  4484. .phy_start_req = pm8001_chip_phy_start_req,
  4485. .phy_stop_req = pm8001_chip_phy_stop_req,
  4486. .reg_dev_req = pm8001_chip_reg_dev_req,
  4487. .dereg_dev_req = pm8001_chip_dereg_dev_req,
  4488. .phy_ctl_req = pm8001_chip_phy_ctl_req,
  4489. .task_abort = pm8001_chip_abort_task,
  4490. .ssp_tm_req = pm8001_chip_ssp_tm_req,
  4491. .get_nvmd_req = pm8001_chip_get_nvmd_req,
  4492. .set_nvmd_req = pm8001_chip_set_nvmd_req,
  4493. .fw_flash_update_req = pm8001_chip_fw_flash_update_req,
  4494. .set_dev_state_req = pm8001_chip_set_dev_state_req,
  4495. .sas_re_init_req = pm8001_chip_sas_re_initialization,
  4496. };