pm80xx_hwi.c 147 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640
  1. /*
  2. * PMC-Sierra SPCv/ve 8088/8089 SAS/SATA based host adapters driver
  3. *
  4. * Copyright (c) 2008-2009 PMC-Sierra, Inc.,
  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 "pm80xx_hwi.h"
  43. #include "pm8001_chips.h"
  44. #include "pm8001_ctl.h"
  45. #define SMP_DIRECT 1
  46. #define SMP_INDIRECT 2
  47. int pm80xx_bar4_shift(struct pm8001_hba_info *pm8001_ha, u32 shift_value)
  48. {
  49. u32 reg_val;
  50. unsigned long start;
  51. pm8001_cw32(pm8001_ha, 0, MEMBASE_II_SHIFT_REGISTER, shift_value);
  52. /* confirm the setting is written */
  53. start = jiffies + HZ; /* 1 sec */
  54. do {
  55. reg_val = pm8001_cr32(pm8001_ha, 0, MEMBASE_II_SHIFT_REGISTER);
  56. } while ((reg_val != shift_value) && time_before(jiffies, start));
  57. if (reg_val != shift_value) {
  58. PM8001_FAIL_DBG(pm8001_ha,
  59. pm8001_printk("TIMEOUT:MEMBASE_II_SHIFT_REGISTER"
  60. " = 0x%x\n", reg_val));
  61. return -1;
  62. }
  63. return 0;
  64. }
  65. void pm80xx_pci_mem_copy(struct pm8001_hba_info *pm8001_ha, u32 soffset,
  66. const void *destination,
  67. u32 dw_count, u32 bus_base_number)
  68. {
  69. u32 index, value, offset;
  70. u32 *destination1;
  71. destination1 = (u32 *)destination;
  72. for (index = 0; index < dw_count; index += 4, destination1++) {
  73. offset = (soffset + index / 4);
  74. if (offset < (64 * 1024)) {
  75. value = pm8001_cr32(pm8001_ha, bus_base_number, offset);
  76. *destination1 = cpu_to_le32(value);
  77. }
  78. }
  79. return;
  80. }
  81. ssize_t pm80xx_get_fatal_dump(struct device *cdev,
  82. struct device_attribute *attr, char *buf)
  83. {
  84. struct Scsi_Host *shost = class_to_shost(cdev);
  85. struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
  86. struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
  87. void __iomem *fatal_table_address = pm8001_ha->fatal_tbl_addr;
  88. u32 accum_len , reg_val, index, *temp;
  89. unsigned long start;
  90. u8 *direct_data;
  91. char *fatal_error_data = buf;
  92. pm8001_ha->forensic_info.data_buf.direct_data = buf;
  93. if (pm8001_ha->chip_id == chip_8001) {
  94. pm8001_ha->forensic_info.data_buf.direct_data +=
  95. sprintf(pm8001_ha->forensic_info.data_buf.direct_data,
  96. "Not supported for SPC controller");
  97. return (char *)pm8001_ha->forensic_info.data_buf.direct_data -
  98. (char *)buf;
  99. }
  100. if (pm8001_ha->forensic_info.data_buf.direct_offset == 0) {
  101. PM8001_IO_DBG(pm8001_ha,
  102. pm8001_printk("forensic_info TYPE_NON_FATAL..............\n"));
  103. direct_data = (u8 *)fatal_error_data;
  104. pm8001_ha->forensic_info.data_type = TYPE_NON_FATAL;
  105. pm8001_ha->forensic_info.data_buf.direct_len = SYSFS_OFFSET;
  106. pm8001_ha->forensic_info.data_buf.read_len = 0;
  107. pm8001_ha->forensic_info.data_buf.direct_data = direct_data;
  108. /* start to get data */
  109. /* Program the MEMBASE II Shifting Register with 0x00.*/
  110. pm8001_cw32(pm8001_ha, 0, MEMBASE_II_SHIFT_REGISTER,
  111. pm8001_ha->fatal_forensic_shift_offset);
  112. pm8001_ha->forensic_last_offset = 0;
  113. pm8001_ha->forensic_fatal_step = 0;
  114. pm8001_ha->fatal_bar_loc = 0;
  115. }
  116. /* Read until accum_len is retrived */
  117. accum_len = pm8001_mr32(fatal_table_address,
  118. MPI_FATAL_EDUMP_TABLE_ACCUM_LEN);
  119. PM8001_IO_DBG(pm8001_ha, pm8001_printk("accum_len 0x%x\n",
  120. accum_len));
  121. if (accum_len == 0xFFFFFFFF) {
  122. PM8001_IO_DBG(pm8001_ha,
  123. pm8001_printk("Possible PCI issue 0x%x not expected\n",
  124. accum_len));
  125. return -EIO;
  126. }
  127. if (accum_len == 0 || accum_len >= 0x100000) {
  128. pm8001_ha->forensic_info.data_buf.direct_data +=
  129. sprintf(pm8001_ha->forensic_info.data_buf.direct_data,
  130. "%08x ", 0xFFFFFFFF);
  131. return (char *)pm8001_ha->forensic_info.data_buf.direct_data -
  132. (char *)buf;
  133. }
  134. temp = (u32 *)pm8001_ha->memoryMap.region[FORENSIC_MEM].virt_ptr;
  135. if (pm8001_ha->forensic_fatal_step == 0) {
  136. moreData:
  137. if (pm8001_ha->forensic_info.data_buf.direct_data) {
  138. /* Data is in bar, copy to host memory */
  139. pm80xx_pci_mem_copy(pm8001_ha, pm8001_ha->fatal_bar_loc,
  140. pm8001_ha->memoryMap.region[FORENSIC_MEM].virt_ptr,
  141. pm8001_ha->forensic_info.data_buf.direct_len ,
  142. 1);
  143. }
  144. pm8001_ha->fatal_bar_loc +=
  145. pm8001_ha->forensic_info.data_buf.direct_len;
  146. pm8001_ha->forensic_info.data_buf.direct_offset +=
  147. pm8001_ha->forensic_info.data_buf.direct_len;
  148. pm8001_ha->forensic_last_offset +=
  149. pm8001_ha->forensic_info.data_buf.direct_len;
  150. pm8001_ha->forensic_info.data_buf.read_len =
  151. pm8001_ha->forensic_info.data_buf.direct_len;
  152. if (pm8001_ha->forensic_last_offset >= accum_len) {
  153. pm8001_ha->forensic_info.data_buf.direct_data +=
  154. sprintf(pm8001_ha->forensic_info.data_buf.direct_data,
  155. "%08x ", 3);
  156. for (index = 0; index < (SYSFS_OFFSET / 4); index++) {
  157. pm8001_ha->forensic_info.data_buf.direct_data +=
  158. sprintf(pm8001_ha->
  159. forensic_info.data_buf.direct_data,
  160. "%08x ", *(temp + index));
  161. }
  162. pm8001_ha->fatal_bar_loc = 0;
  163. pm8001_ha->forensic_fatal_step = 1;
  164. pm8001_ha->fatal_forensic_shift_offset = 0;
  165. pm8001_ha->forensic_last_offset = 0;
  166. return (char *)pm8001_ha->
  167. forensic_info.data_buf.direct_data -
  168. (char *)buf;
  169. }
  170. if (pm8001_ha->fatal_bar_loc < (64 * 1024)) {
  171. pm8001_ha->forensic_info.data_buf.direct_data +=
  172. sprintf(pm8001_ha->
  173. forensic_info.data_buf.direct_data,
  174. "%08x ", 2);
  175. for (index = 0; index < (SYSFS_OFFSET / 4); index++) {
  176. pm8001_ha->forensic_info.data_buf.direct_data +=
  177. sprintf(pm8001_ha->
  178. forensic_info.data_buf.direct_data,
  179. "%08x ", *(temp + index));
  180. }
  181. return (char *)pm8001_ha->
  182. forensic_info.data_buf.direct_data -
  183. (char *)buf;
  184. }
  185. /* Increment the MEMBASE II Shifting Register value by 0x100.*/
  186. pm8001_ha->forensic_info.data_buf.direct_data +=
  187. sprintf(pm8001_ha->forensic_info.data_buf.direct_data,
  188. "%08x ", 2);
  189. for (index = 0; index < 256; index++) {
  190. pm8001_ha->forensic_info.data_buf.direct_data +=
  191. sprintf(pm8001_ha->
  192. forensic_info.data_buf.direct_data,
  193. "%08x ", *(temp + index));
  194. }
  195. pm8001_ha->fatal_forensic_shift_offset += 0x100;
  196. pm8001_cw32(pm8001_ha, 0, MEMBASE_II_SHIFT_REGISTER,
  197. pm8001_ha->fatal_forensic_shift_offset);
  198. pm8001_ha->fatal_bar_loc = 0;
  199. return (char *)pm8001_ha->forensic_info.data_buf.direct_data -
  200. (char *)buf;
  201. }
  202. if (pm8001_ha->forensic_fatal_step == 1) {
  203. pm8001_ha->fatal_forensic_shift_offset = 0;
  204. /* Read 64K of the debug data. */
  205. pm8001_cw32(pm8001_ha, 0, MEMBASE_II_SHIFT_REGISTER,
  206. pm8001_ha->fatal_forensic_shift_offset);
  207. pm8001_mw32(fatal_table_address,
  208. MPI_FATAL_EDUMP_TABLE_HANDSHAKE,
  209. MPI_FATAL_EDUMP_HANDSHAKE_RDY);
  210. /* Poll FDDHSHK until clear */
  211. start = jiffies + (2 * HZ); /* 2 sec */
  212. do {
  213. reg_val = pm8001_mr32(fatal_table_address,
  214. MPI_FATAL_EDUMP_TABLE_HANDSHAKE);
  215. } while ((reg_val) && time_before(jiffies, start));
  216. if (reg_val != 0) {
  217. PM8001_FAIL_DBG(pm8001_ha,
  218. pm8001_printk("TIMEOUT:MEMBASE_II_SHIFT_REGISTER"
  219. " = 0x%x\n", reg_val));
  220. return -EIO;
  221. }
  222. /* Read the next 64K of the debug data. */
  223. pm8001_ha->forensic_fatal_step = 0;
  224. if (pm8001_mr32(fatal_table_address,
  225. MPI_FATAL_EDUMP_TABLE_STATUS) !=
  226. MPI_FATAL_EDUMP_TABLE_STAT_NF_SUCCESS_DONE) {
  227. pm8001_mw32(fatal_table_address,
  228. MPI_FATAL_EDUMP_TABLE_HANDSHAKE, 0);
  229. goto moreData;
  230. } else {
  231. pm8001_ha->forensic_info.data_buf.direct_data +=
  232. sprintf(pm8001_ha->
  233. forensic_info.data_buf.direct_data,
  234. "%08x ", 4);
  235. pm8001_ha->forensic_info.data_buf.read_len = 0xFFFFFFFF;
  236. pm8001_ha->forensic_info.data_buf.direct_len = 0;
  237. pm8001_ha->forensic_info.data_buf.direct_offset = 0;
  238. pm8001_ha->forensic_info.data_buf.read_len = 0;
  239. }
  240. }
  241. return (char *)pm8001_ha->forensic_info.data_buf.direct_data -
  242. (char *)buf;
  243. }
  244. /**
  245. * read_main_config_table - read the configure table and save it.
  246. * @pm8001_ha: our hba card information
  247. */
  248. static void read_main_config_table(struct pm8001_hba_info *pm8001_ha)
  249. {
  250. void __iomem *address = pm8001_ha->main_cfg_tbl_addr;
  251. pm8001_ha->main_cfg_tbl.pm80xx_tbl.signature =
  252. pm8001_mr32(address, MAIN_SIGNATURE_OFFSET);
  253. pm8001_ha->main_cfg_tbl.pm80xx_tbl.interface_rev =
  254. pm8001_mr32(address, MAIN_INTERFACE_REVISION);
  255. pm8001_ha->main_cfg_tbl.pm80xx_tbl.firmware_rev =
  256. pm8001_mr32(address, MAIN_FW_REVISION);
  257. pm8001_ha->main_cfg_tbl.pm80xx_tbl.max_out_io =
  258. pm8001_mr32(address, MAIN_MAX_OUTSTANDING_IO_OFFSET);
  259. pm8001_ha->main_cfg_tbl.pm80xx_tbl.max_sgl =
  260. pm8001_mr32(address, MAIN_MAX_SGL_OFFSET);
  261. pm8001_ha->main_cfg_tbl.pm80xx_tbl.ctrl_cap_flag =
  262. pm8001_mr32(address, MAIN_CNTRL_CAP_OFFSET);
  263. pm8001_ha->main_cfg_tbl.pm80xx_tbl.gst_offset =
  264. pm8001_mr32(address, MAIN_GST_OFFSET);
  265. pm8001_ha->main_cfg_tbl.pm80xx_tbl.inbound_queue_offset =
  266. pm8001_mr32(address, MAIN_IBQ_OFFSET);
  267. pm8001_ha->main_cfg_tbl.pm80xx_tbl.outbound_queue_offset =
  268. pm8001_mr32(address, MAIN_OBQ_OFFSET);
  269. /* read Error Dump Offset and Length */
  270. pm8001_ha->main_cfg_tbl.pm80xx_tbl.fatal_err_dump_offset0 =
  271. pm8001_mr32(address, MAIN_FATAL_ERROR_RDUMP0_OFFSET);
  272. pm8001_ha->main_cfg_tbl.pm80xx_tbl.fatal_err_dump_length0 =
  273. pm8001_mr32(address, MAIN_FATAL_ERROR_RDUMP0_LENGTH);
  274. pm8001_ha->main_cfg_tbl.pm80xx_tbl.fatal_err_dump_offset1 =
  275. pm8001_mr32(address, MAIN_FATAL_ERROR_RDUMP1_OFFSET);
  276. pm8001_ha->main_cfg_tbl.pm80xx_tbl.fatal_err_dump_length1 =
  277. pm8001_mr32(address, MAIN_FATAL_ERROR_RDUMP1_LENGTH);
  278. /* read GPIO LED settings from the configuration table */
  279. pm8001_ha->main_cfg_tbl.pm80xx_tbl.gpio_led_mapping =
  280. pm8001_mr32(address, MAIN_GPIO_LED_FLAGS_OFFSET);
  281. /* read analog Setting offset from the configuration table */
  282. pm8001_ha->main_cfg_tbl.pm80xx_tbl.analog_setup_table_offset =
  283. pm8001_mr32(address, MAIN_ANALOG_SETUP_OFFSET);
  284. pm8001_ha->main_cfg_tbl.pm80xx_tbl.int_vec_table_offset =
  285. pm8001_mr32(address, MAIN_INT_VECTOR_TABLE_OFFSET);
  286. pm8001_ha->main_cfg_tbl.pm80xx_tbl.phy_attr_table_offset =
  287. pm8001_mr32(address, MAIN_SAS_PHY_ATTR_TABLE_OFFSET);
  288. /* read port recover and reset timeout */
  289. pm8001_ha->main_cfg_tbl.pm80xx_tbl.port_recovery_timer =
  290. pm8001_mr32(address, MAIN_PORT_RECOVERY_TIMER);
  291. }
  292. /**
  293. * read_general_status_table - read the general status table and save it.
  294. * @pm8001_ha: our hba card information
  295. */
  296. static void read_general_status_table(struct pm8001_hba_info *pm8001_ha)
  297. {
  298. void __iomem *address = pm8001_ha->general_stat_tbl_addr;
  299. pm8001_ha->gs_tbl.pm80xx_tbl.gst_len_mpistate =
  300. pm8001_mr32(address, GST_GSTLEN_MPIS_OFFSET);
  301. pm8001_ha->gs_tbl.pm80xx_tbl.iq_freeze_state0 =
  302. pm8001_mr32(address, GST_IQ_FREEZE_STATE0_OFFSET);
  303. pm8001_ha->gs_tbl.pm80xx_tbl.iq_freeze_state1 =
  304. pm8001_mr32(address, GST_IQ_FREEZE_STATE1_OFFSET);
  305. pm8001_ha->gs_tbl.pm80xx_tbl.msgu_tcnt =
  306. pm8001_mr32(address, GST_MSGUTCNT_OFFSET);
  307. pm8001_ha->gs_tbl.pm80xx_tbl.iop_tcnt =
  308. pm8001_mr32(address, GST_IOPTCNT_OFFSET);
  309. pm8001_ha->gs_tbl.pm80xx_tbl.gpio_input_val =
  310. pm8001_mr32(address, GST_GPIO_INPUT_VAL);
  311. pm8001_ha->gs_tbl.pm80xx_tbl.recover_err_info[0] =
  312. pm8001_mr32(address, GST_RERRINFO_OFFSET0);
  313. pm8001_ha->gs_tbl.pm80xx_tbl.recover_err_info[1] =
  314. pm8001_mr32(address, GST_RERRINFO_OFFSET1);
  315. pm8001_ha->gs_tbl.pm80xx_tbl.recover_err_info[2] =
  316. pm8001_mr32(address, GST_RERRINFO_OFFSET2);
  317. pm8001_ha->gs_tbl.pm80xx_tbl.recover_err_info[3] =
  318. pm8001_mr32(address, GST_RERRINFO_OFFSET3);
  319. pm8001_ha->gs_tbl.pm80xx_tbl.recover_err_info[4] =
  320. pm8001_mr32(address, GST_RERRINFO_OFFSET4);
  321. pm8001_ha->gs_tbl.pm80xx_tbl.recover_err_info[5] =
  322. pm8001_mr32(address, GST_RERRINFO_OFFSET5);
  323. pm8001_ha->gs_tbl.pm80xx_tbl.recover_err_info[6] =
  324. pm8001_mr32(address, GST_RERRINFO_OFFSET6);
  325. pm8001_ha->gs_tbl.pm80xx_tbl.recover_err_info[7] =
  326. pm8001_mr32(address, GST_RERRINFO_OFFSET7);
  327. }
  328. /**
  329. * read_phy_attr_table - read the phy attribute table and save it.
  330. * @pm8001_ha: our hba card information
  331. */
  332. static void read_phy_attr_table(struct pm8001_hba_info *pm8001_ha)
  333. {
  334. void __iomem *address = pm8001_ha->pspa_q_tbl_addr;
  335. pm8001_ha->phy_attr_table.phystart1_16[0] =
  336. pm8001_mr32(address, PSPA_PHYSTATE0_OFFSET);
  337. pm8001_ha->phy_attr_table.phystart1_16[1] =
  338. pm8001_mr32(address, PSPA_PHYSTATE1_OFFSET);
  339. pm8001_ha->phy_attr_table.phystart1_16[2] =
  340. pm8001_mr32(address, PSPA_PHYSTATE2_OFFSET);
  341. pm8001_ha->phy_attr_table.phystart1_16[3] =
  342. pm8001_mr32(address, PSPA_PHYSTATE3_OFFSET);
  343. pm8001_ha->phy_attr_table.phystart1_16[4] =
  344. pm8001_mr32(address, PSPA_PHYSTATE4_OFFSET);
  345. pm8001_ha->phy_attr_table.phystart1_16[5] =
  346. pm8001_mr32(address, PSPA_PHYSTATE5_OFFSET);
  347. pm8001_ha->phy_attr_table.phystart1_16[6] =
  348. pm8001_mr32(address, PSPA_PHYSTATE6_OFFSET);
  349. pm8001_ha->phy_attr_table.phystart1_16[7] =
  350. pm8001_mr32(address, PSPA_PHYSTATE7_OFFSET);
  351. pm8001_ha->phy_attr_table.phystart1_16[8] =
  352. pm8001_mr32(address, PSPA_PHYSTATE8_OFFSET);
  353. pm8001_ha->phy_attr_table.phystart1_16[9] =
  354. pm8001_mr32(address, PSPA_PHYSTATE9_OFFSET);
  355. pm8001_ha->phy_attr_table.phystart1_16[10] =
  356. pm8001_mr32(address, PSPA_PHYSTATE10_OFFSET);
  357. pm8001_ha->phy_attr_table.phystart1_16[11] =
  358. pm8001_mr32(address, PSPA_PHYSTATE11_OFFSET);
  359. pm8001_ha->phy_attr_table.phystart1_16[12] =
  360. pm8001_mr32(address, PSPA_PHYSTATE12_OFFSET);
  361. pm8001_ha->phy_attr_table.phystart1_16[13] =
  362. pm8001_mr32(address, PSPA_PHYSTATE13_OFFSET);
  363. pm8001_ha->phy_attr_table.phystart1_16[14] =
  364. pm8001_mr32(address, PSPA_PHYSTATE14_OFFSET);
  365. pm8001_ha->phy_attr_table.phystart1_16[15] =
  366. pm8001_mr32(address, PSPA_PHYSTATE15_OFFSET);
  367. pm8001_ha->phy_attr_table.outbound_hw_event_pid1_16[0] =
  368. pm8001_mr32(address, PSPA_OB_HW_EVENT_PID0_OFFSET);
  369. pm8001_ha->phy_attr_table.outbound_hw_event_pid1_16[1] =
  370. pm8001_mr32(address, PSPA_OB_HW_EVENT_PID1_OFFSET);
  371. pm8001_ha->phy_attr_table.outbound_hw_event_pid1_16[2] =
  372. pm8001_mr32(address, PSPA_OB_HW_EVENT_PID2_OFFSET);
  373. pm8001_ha->phy_attr_table.outbound_hw_event_pid1_16[3] =
  374. pm8001_mr32(address, PSPA_OB_HW_EVENT_PID3_OFFSET);
  375. pm8001_ha->phy_attr_table.outbound_hw_event_pid1_16[4] =
  376. pm8001_mr32(address, PSPA_OB_HW_EVENT_PID4_OFFSET);
  377. pm8001_ha->phy_attr_table.outbound_hw_event_pid1_16[5] =
  378. pm8001_mr32(address, PSPA_OB_HW_EVENT_PID5_OFFSET);
  379. pm8001_ha->phy_attr_table.outbound_hw_event_pid1_16[6] =
  380. pm8001_mr32(address, PSPA_OB_HW_EVENT_PID6_OFFSET);
  381. pm8001_ha->phy_attr_table.outbound_hw_event_pid1_16[7] =
  382. pm8001_mr32(address, PSPA_OB_HW_EVENT_PID7_OFFSET);
  383. pm8001_ha->phy_attr_table.outbound_hw_event_pid1_16[8] =
  384. pm8001_mr32(address, PSPA_OB_HW_EVENT_PID8_OFFSET);
  385. pm8001_ha->phy_attr_table.outbound_hw_event_pid1_16[9] =
  386. pm8001_mr32(address, PSPA_OB_HW_EVENT_PID9_OFFSET);
  387. pm8001_ha->phy_attr_table.outbound_hw_event_pid1_16[10] =
  388. pm8001_mr32(address, PSPA_OB_HW_EVENT_PID10_OFFSET);
  389. pm8001_ha->phy_attr_table.outbound_hw_event_pid1_16[11] =
  390. pm8001_mr32(address, PSPA_OB_HW_EVENT_PID11_OFFSET);
  391. pm8001_ha->phy_attr_table.outbound_hw_event_pid1_16[12] =
  392. pm8001_mr32(address, PSPA_OB_HW_EVENT_PID12_OFFSET);
  393. pm8001_ha->phy_attr_table.outbound_hw_event_pid1_16[13] =
  394. pm8001_mr32(address, PSPA_OB_HW_EVENT_PID13_OFFSET);
  395. pm8001_ha->phy_attr_table.outbound_hw_event_pid1_16[14] =
  396. pm8001_mr32(address, PSPA_OB_HW_EVENT_PID14_OFFSET);
  397. pm8001_ha->phy_attr_table.outbound_hw_event_pid1_16[15] =
  398. pm8001_mr32(address, PSPA_OB_HW_EVENT_PID15_OFFSET);
  399. }
  400. /**
  401. * read_inbnd_queue_table - read the inbound queue table and save it.
  402. * @pm8001_ha: our hba card information
  403. */
  404. static void read_inbnd_queue_table(struct pm8001_hba_info *pm8001_ha)
  405. {
  406. int i;
  407. void __iomem *address = pm8001_ha->inbnd_q_tbl_addr;
  408. for (i = 0; i < PM8001_MAX_SPCV_INB_NUM; i++) {
  409. u32 offset = i * 0x20;
  410. pm8001_ha->inbnd_q_tbl[i].pi_pci_bar =
  411. get_pci_bar_index(pm8001_mr32(address,
  412. (offset + IB_PIPCI_BAR)));
  413. pm8001_ha->inbnd_q_tbl[i].pi_offset =
  414. pm8001_mr32(address, (offset + IB_PIPCI_BAR_OFFSET));
  415. }
  416. }
  417. /**
  418. * read_outbnd_queue_table - read the outbound queue table and save it.
  419. * @pm8001_ha: our hba card information
  420. */
  421. static void read_outbnd_queue_table(struct pm8001_hba_info *pm8001_ha)
  422. {
  423. int i;
  424. void __iomem *address = pm8001_ha->outbnd_q_tbl_addr;
  425. for (i = 0; i < PM8001_MAX_SPCV_OUTB_NUM; i++) {
  426. u32 offset = i * 0x24;
  427. pm8001_ha->outbnd_q_tbl[i].ci_pci_bar =
  428. get_pci_bar_index(pm8001_mr32(address,
  429. (offset + OB_CIPCI_BAR)));
  430. pm8001_ha->outbnd_q_tbl[i].ci_offset =
  431. pm8001_mr32(address, (offset + OB_CIPCI_BAR_OFFSET));
  432. }
  433. }
  434. /**
  435. * init_default_table_values - init the default table.
  436. * @pm8001_ha: our hba card information
  437. */
  438. static void init_default_table_values(struct pm8001_hba_info *pm8001_ha)
  439. {
  440. int i;
  441. u32 offsetib, offsetob;
  442. void __iomem *addressib = pm8001_ha->inbnd_q_tbl_addr;
  443. void __iomem *addressob = pm8001_ha->outbnd_q_tbl_addr;
  444. pm8001_ha->main_cfg_tbl.pm80xx_tbl.upper_event_log_addr =
  445. pm8001_ha->memoryMap.region[AAP1].phys_addr_hi;
  446. pm8001_ha->main_cfg_tbl.pm80xx_tbl.lower_event_log_addr =
  447. pm8001_ha->memoryMap.region[AAP1].phys_addr_lo;
  448. pm8001_ha->main_cfg_tbl.pm80xx_tbl.event_log_size =
  449. PM8001_EVENT_LOG_SIZE;
  450. pm8001_ha->main_cfg_tbl.pm80xx_tbl.event_log_severity = 0x01;
  451. pm8001_ha->main_cfg_tbl.pm80xx_tbl.upper_pcs_event_log_addr =
  452. pm8001_ha->memoryMap.region[IOP].phys_addr_hi;
  453. pm8001_ha->main_cfg_tbl.pm80xx_tbl.lower_pcs_event_log_addr =
  454. pm8001_ha->memoryMap.region[IOP].phys_addr_lo;
  455. pm8001_ha->main_cfg_tbl.pm80xx_tbl.pcs_event_log_size =
  456. PM8001_EVENT_LOG_SIZE;
  457. pm8001_ha->main_cfg_tbl.pm80xx_tbl.pcs_event_log_severity = 0x01;
  458. pm8001_ha->main_cfg_tbl.pm80xx_tbl.fatal_err_interrupt = 0x01;
  459. /* Disable end to end CRC checking */
  460. pm8001_ha->main_cfg_tbl.pm80xx_tbl.crc_core_dump = (0x1 << 16);
  461. for (i = 0; i < PM8001_MAX_SPCV_INB_NUM; i++) {
  462. pm8001_ha->inbnd_q_tbl[i].element_pri_size_cnt =
  463. PM8001_MPI_QUEUE | (pm8001_ha->iomb_size << 16) | (0x00<<30);
  464. pm8001_ha->inbnd_q_tbl[i].upper_base_addr =
  465. pm8001_ha->memoryMap.region[IB + i].phys_addr_hi;
  466. pm8001_ha->inbnd_q_tbl[i].lower_base_addr =
  467. pm8001_ha->memoryMap.region[IB + i].phys_addr_lo;
  468. pm8001_ha->inbnd_q_tbl[i].base_virt =
  469. (u8 *)pm8001_ha->memoryMap.region[IB + i].virt_ptr;
  470. pm8001_ha->inbnd_q_tbl[i].total_length =
  471. pm8001_ha->memoryMap.region[IB + i].total_len;
  472. pm8001_ha->inbnd_q_tbl[i].ci_upper_base_addr =
  473. pm8001_ha->memoryMap.region[CI + i].phys_addr_hi;
  474. pm8001_ha->inbnd_q_tbl[i].ci_lower_base_addr =
  475. pm8001_ha->memoryMap.region[CI + i].phys_addr_lo;
  476. pm8001_ha->inbnd_q_tbl[i].ci_virt =
  477. pm8001_ha->memoryMap.region[CI + i].virt_ptr;
  478. offsetib = i * 0x20;
  479. pm8001_ha->inbnd_q_tbl[i].pi_pci_bar =
  480. get_pci_bar_index(pm8001_mr32(addressib,
  481. (offsetib + 0x14)));
  482. pm8001_ha->inbnd_q_tbl[i].pi_offset =
  483. pm8001_mr32(addressib, (offsetib + 0x18));
  484. pm8001_ha->inbnd_q_tbl[i].producer_idx = 0;
  485. pm8001_ha->inbnd_q_tbl[i].consumer_index = 0;
  486. }
  487. for (i = 0; i < PM8001_MAX_SPCV_OUTB_NUM; i++) {
  488. pm8001_ha->outbnd_q_tbl[i].element_size_cnt =
  489. PM8001_MPI_QUEUE | (pm8001_ha->iomb_size << 16) | (0x01<<30);
  490. pm8001_ha->outbnd_q_tbl[i].upper_base_addr =
  491. pm8001_ha->memoryMap.region[OB + i].phys_addr_hi;
  492. pm8001_ha->outbnd_q_tbl[i].lower_base_addr =
  493. pm8001_ha->memoryMap.region[OB + i].phys_addr_lo;
  494. pm8001_ha->outbnd_q_tbl[i].base_virt =
  495. (u8 *)pm8001_ha->memoryMap.region[OB + i].virt_ptr;
  496. pm8001_ha->outbnd_q_tbl[i].total_length =
  497. pm8001_ha->memoryMap.region[OB + i].total_len;
  498. pm8001_ha->outbnd_q_tbl[i].pi_upper_base_addr =
  499. pm8001_ha->memoryMap.region[PI + i].phys_addr_hi;
  500. pm8001_ha->outbnd_q_tbl[i].pi_lower_base_addr =
  501. pm8001_ha->memoryMap.region[PI + i].phys_addr_lo;
  502. /* interrupt vector based on oq */
  503. pm8001_ha->outbnd_q_tbl[i].interrup_vec_cnt_delay = (i << 24);
  504. pm8001_ha->outbnd_q_tbl[i].pi_virt =
  505. pm8001_ha->memoryMap.region[PI + i].virt_ptr;
  506. offsetob = i * 0x24;
  507. pm8001_ha->outbnd_q_tbl[i].ci_pci_bar =
  508. get_pci_bar_index(pm8001_mr32(addressob,
  509. offsetob + 0x14));
  510. pm8001_ha->outbnd_q_tbl[i].ci_offset =
  511. pm8001_mr32(addressob, (offsetob + 0x18));
  512. pm8001_ha->outbnd_q_tbl[i].consumer_idx = 0;
  513. pm8001_ha->outbnd_q_tbl[i].producer_index = 0;
  514. }
  515. }
  516. /**
  517. * update_main_config_table - update the main default table to the HBA.
  518. * @pm8001_ha: our hba card information
  519. */
  520. static void update_main_config_table(struct pm8001_hba_info *pm8001_ha)
  521. {
  522. void __iomem *address = pm8001_ha->main_cfg_tbl_addr;
  523. pm8001_mw32(address, MAIN_IQNPPD_HPPD_OFFSET,
  524. pm8001_ha->main_cfg_tbl.pm80xx_tbl.inbound_q_nppd_hppd);
  525. pm8001_mw32(address, MAIN_EVENT_LOG_ADDR_HI,
  526. pm8001_ha->main_cfg_tbl.pm80xx_tbl.upper_event_log_addr);
  527. pm8001_mw32(address, MAIN_EVENT_LOG_ADDR_LO,
  528. pm8001_ha->main_cfg_tbl.pm80xx_tbl.lower_event_log_addr);
  529. pm8001_mw32(address, MAIN_EVENT_LOG_BUFF_SIZE,
  530. pm8001_ha->main_cfg_tbl.pm80xx_tbl.event_log_size);
  531. pm8001_mw32(address, MAIN_EVENT_LOG_OPTION,
  532. pm8001_ha->main_cfg_tbl.pm80xx_tbl.event_log_severity);
  533. pm8001_mw32(address, MAIN_PCS_EVENT_LOG_ADDR_HI,
  534. pm8001_ha->main_cfg_tbl.pm80xx_tbl.upper_pcs_event_log_addr);
  535. pm8001_mw32(address, MAIN_PCS_EVENT_LOG_ADDR_LO,
  536. pm8001_ha->main_cfg_tbl.pm80xx_tbl.lower_pcs_event_log_addr);
  537. pm8001_mw32(address, MAIN_PCS_EVENT_LOG_BUFF_SIZE,
  538. pm8001_ha->main_cfg_tbl.pm80xx_tbl.pcs_event_log_size);
  539. pm8001_mw32(address, MAIN_PCS_EVENT_LOG_OPTION,
  540. pm8001_ha->main_cfg_tbl.pm80xx_tbl.pcs_event_log_severity);
  541. pm8001_mw32(address, MAIN_FATAL_ERROR_INTERRUPT,
  542. pm8001_ha->main_cfg_tbl.pm80xx_tbl.fatal_err_interrupt);
  543. pm8001_mw32(address, MAIN_EVENT_CRC_CHECK,
  544. pm8001_ha->main_cfg_tbl.pm80xx_tbl.crc_core_dump);
  545. /* SPCv specific */
  546. pm8001_ha->main_cfg_tbl.pm80xx_tbl.gpio_led_mapping &= 0xCFFFFFFF;
  547. /* Set GPIOLED to 0x2 for LED indicator */
  548. pm8001_ha->main_cfg_tbl.pm80xx_tbl.gpio_led_mapping |= 0x20000000;
  549. pm8001_mw32(address, MAIN_GPIO_LED_FLAGS_OFFSET,
  550. pm8001_ha->main_cfg_tbl.pm80xx_tbl.gpio_led_mapping);
  551. pm8001_mw32(address, MAIN_PORT_RECOVERY_TIMER,
  552. pm8001_ha->main_cfg_tbl.pm80xx_tbl.port_recovery_timer);
  553. pm8001_mw32(address, MAIN_INT_REASSERTION_DELAY,
  554. pm8001_ha->main_cfg_tbl.pm80xx_tbl.interrupt_reassertion_delay);
  555. pm8001_ha->main_cfg_tbl.pm80xx_tbl.port_recovery_timer &= 0xffff0000;
  556. pm8001_ha->main_cfg_tbl.pm80xx_tbl.port_recovery_timer |=
  557. PORT_RECOVERY_TIMEOUT;
  558. pm8001_mw32(address, MAIN_PORT_RECOVERY_TIMER,
  559. pm8001_ha->main_cfg_tbl.pm80xx_tbl.port_recovery_timer);
  560. }
  561. /**
  562. * update_inbnd_queue_table - update the inbound queue table to the HBA.
  563. * @pm8001_ha: our hba card information
  564. */
  565. static void update_inbnd_queue_table(struct pm8001_hba_info *pm8001_ha,
  566. int number)
  567. {
  568. void __iomem *address = pm8001_ha->inbnd_q_tbl_addr;
  569. u16 offset = number * 0x20;
  570. pm8001_mw32(address, offset + IB_PROPERITY_OFFSET,
  571. pm8001_ha->inbnd_q_tbl[number].element_pri_size_cnt);
  572. pm8001_mw32(address, offset + IB_BASE_ADDR_HI_OFFSET,
  573. pm8001_ha->inbnd_q_tbl[number].upper_base_addr);
  574. pm8001_mw32(address, offset + IB_BASE_ADDR_LO_OFFSET,
  575. pm8001_ha->inbnd_q_tbl[number].lower_base_addr);
  576. pm8001_mw32(address, offset + IB_CI_BASE_ADDR_HI_OFFSET,
  577. pm8001_ha->inbnd_q_tbl[number].ci_upper_base_addr);
  578. pm8001_mw32(address, offset + IB_CI_BASE_ADDR_LO_OFFSET,
  579. pm8001_ha->inbnd_q_tbl[number].ci_lower_base_addr);
  580. }
  581. /**
  582. * update_outbnd_queue_table - update the outbound queue table to the HBA.
  583. * @pm8001_ha: our hba card information
  584. */
  585. static void update_outbnd_queue_table(struct pm8001_hba_info *pm8001_ha,
  586. int number)
  587. {
  588. void __iomem *address = pm8001_ha->outbnd_q_tbl_addr;
  589. u16 offset = number * 0x24;
  590. pm8001_mw32(address, offset + OB_PROPERITY_OFFSET,
  591. pm8001_ha->outbnd_q_tbl[number].element_size_cnt);
  592. pm8001_mw32(address, offset + OB_BASE_ADDR_HI_OFFSET,
  593. pm8001_ha->outbnd_q_tbl[number].upper_base_addr);
  594. pm8001_mw32(address, offset + OB_BASE_ADDR_LO_OFFSET,
  595. pm8001_ha->outbnd_q_tbl[number].lower_base_addr);
  596. pm8001_mw32(address, offset + OB_PI_BASE_ADDR_HI_OFFSET,
  597. pm8001_ha->outbnd_q_tbl[number].pi_upper_base_addr);
  598. pm8001_mw32(address, offset + OB_PI_BASE_ADDR_LO_OFFSET,
  599. pm8001_ha->outbnd_q_tbl[number].pi_lower_base_addr);
  600. pm8001_mw32(address, offset + OB_INTERRUPT_COALES_OFFSET,
  601. pm8001_ha->outbnd_q_tbl[number].interrup_vec_cnt_delay);
  602. }
  603. /**
  604. * mpi_init_check - check firmware initialization status.
  605. * @pm8001_ha: our hba card information
  606. */
  607. static int mpi_init_check(struct pm8001_hba_info *pm8001_ha)
  608. {
  609. u32 max_wait_count;
  610. u32 value;
  611. u32 gst_len_mpistate;
  612. /* Write bit0=1 to Inbound DoorBell Register to tell the SPC FW the
  613. table is updated */
  614. pm8001_cw32(pm8001_ha, 0, MSGU_IBDB_SET, SPCv_MSGU_CFG_TABLE_UPDATE);
  615. /* wait until Inbound DoorBell Clear Register toggled */
  616. if (IS_SPCV_12G(pm8001_ha->pdev)) {
  617. max_wait_count = 4 * 1000 * 1000;/* 4 sec */
  618. } else {
  619. max_wait_count = 2 * 1000 * 1000;/* 2 sec */
  620. }
  621. do {
  622. udelay(1);
  623. value = pm8001_cr32(pm8001_ha, 0, MSGU_IBDB_SET);
  624. value &= SPCv_MSGU_CFG_TABLE_UPDATE;
  625. } while ((value != 0) && (--max_wait_count));
  626. if (!max_wait_count)
  627. return -1;
  628. /* check the MPI-State for initialization upto 100ms*/
  629. max_wait_count = 100 * 1000;/* 100 msec */
  630. do {
  631. udelay(1);
  632. gst_len_mpistate =
  633. pm8001_mr32(pm8001_ha->general_stat_tbl_addr,
  634. GST_GSTLEN_MPIS_OFFSET);
  635. } while ((GST_MPI_STATE_INIT !=
  636. (gst_len_mpistate & GST_MPI_STATE_MASK)) && (--max_wait_count));
  637. if (!max_wait_count)
  638. return -1;
  639. /* check MPI Initialization error */
  640. gst_len_mpistate = gst_len_mpistate >> 16;
  641. if (0x0000 != gst_len_mpistate)
  642. return -1;
  643. return 0;
  644. }
  645. /**
  646. * check_fw_ready - The LLDD check if the FW is ready, if not, return error.
  647. * @pm8001_ha: our hba card information
  648. */
  649. static int check_fw_ready(struct pm8001_hba_info *pm8001_ha)
  650. {
  651. u32 value;
  652. u32 max_wait_count;
  653. u32 max_wait_time;
  654. int ret = 0;
  655. /* reset / PCIe ready */
  656. max_wait_time = max_wait_count = 100 * 1000; /* 100 milli sec */
  657. do {
  658. udelay(1);
  659. value = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_1);
  660. } while ((value == 0xFFFFFFFF) && (--max_wait_count));
  661. /* check ila status */
  662. max_wait_time = max_wait_count = 1000 * 1000; /* 1000 milli sec */
  663. do {
  664. udelay(1);
  665. value = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_1);
  666. } while (((value & SCRATCH_PAD_ILA_READY) !=
  667. SCRATCH_PAD_ILA_READY) && (--max_wait_count));
  668. if (!max_wait_count)
  669. ret = -1;
  670. else {
  671. PM8001_MSG_DBG(pm8001_ha,
  672. pm8001_printk(" ila ready status in %d millisec\n",
  673. (max_wait_time - max_wait_count)));
  674. }
  675. /* check RAAE status */
  676. max_wait_time = max_wait_count = 1800 * 1000; /* 1800 milli sec */
  677. do {
  678. udelay(1);
  679. value = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_1);
  680. } while (((value & SCRATCH_PAD_RAAE_READY) !=
  681. SCRATCH_PAD_RAAE_READY) && (--max_wait_count));
  682. if (!max_wait_count)
  683. ret = -1;
  684. else {
  685. PM8001_MSG_DBG(pm8001_ha,
  686. pm8001_printk(" raae ready status in %d millisec\n",
  687. (max_wait_time - max_wait_count)));
  688. }
  689. /* check iop0 status */
  690. max_wait_time = max_wait_count = 600 * 1000; /* 600 milli sec */
  691. do {
  692. udelay(1);
  693. value = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_1);
  694. } while (((value & SCRATCH_PAD_IOP0_READY) != SCRATCH_PAD_IOP0_READY) &&
  695. (--max_wait_count));
  696. if (!max_wait_count)
  697. ret = -1;
  698. else {
  699. PM8001_MSG_DBG(pm8001_ha,
  700. pm8001_printk(" iop0 ready status in %d millisec\n",
  701. (max_wait_time - max_wait_count)));
  702. }
  703. /* check iop1 status only for 16 port controllers */
  704. if ((pm8001_ha->chip_id != chip_8008) &&
  705. (pm8001_ha->chip_id != chip_8009)) {
  706. /* 200 milli sec */
  707. max_wait_time = max_wait_count = 200 * 1000;
  708. do {
  709. udelay(1);
  710. value = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_1);
  711. } while (((value & SCRATCH_PAD_IOP1_READY) !=
  712. SCRATCH_PAD_IOP1_READY) && (--max_wait_count));
  713. if (!max_wait_count)
  714. ret = -1;
  715. else {
  716. PM8001_MSG_DBG(pm8001_ha, pm8001_printk(
  717. "iop1 ready status in %d millisec\n",
  718. (max_wait_time - max_wait_count)));
  719. }
  720. }
  721. return ret;
  722. }
  723. static void init_pci_device_addresses(struct pm8001_hba_info *pm8001_ha)
  724. {
  725. void __iomem *base_addr;
  726. u32 value;
  727. u32 offset;
  728. u32 pcibar;
  729. u32 pcilogic;
  730. value = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_0);
  731. offset = value & 0x03FFFFFF; /* scratch pad 0 TBL address */
  732. PM8001_INIT_DBG(pm8001_ha,
  733. pm8001_printk("Scratchpad 0 Offset: 0x%x value 0x%x\n",
  734. offset, value));
  735. pcilogic = (value & 0xFC000000) >> 26;
  736. pcibar = get_pci_bar_index(pcilogic);
  737. PM8001_INIT_DBG(pm8001_ha,
  738. pm8001_printk("Scratchpad 0 PCI BAR: %d\n", pcibar));
  739. pm8001_ha->main_cfg_tbl_addr = base_addr =
  740. pm8001_ha->io_mem[pcibar].memvirtaddr + offset;
  741. pm8001_ha->general_stat_tbl_addr =
  742. base_addr + (pm8001_cr32(pm8001_ha, pcibar, offset + 0x18) &
  743. 0xFFFFFF);
  744. pm8001_ha->inbnd_q_tbl_addr =
  745. base_addr + (pm8001_cr32(pm8001_ha, pcibar, offset + 0x1C) &
  746. 0xFFFFFF);
  747. pm8001_ha->outbnd_q_tbl_addr =
  748. base_addr + (pm8001_cr32(pm8001_ha, pcibar, offset + 0x20) &
  749. 0xFFFFFF);
  750. pm8001_ha->ivt_tbl_addr =
  751. base_addr + (pm8001_cr32(pm8001_ha, pcibar, offset + 0x8C) &
  752. 0xFFFFFF);
  753. pm8001_ha->pspa_q_tbl_addr =
  754. base_addr + (pm8001_cr32(pm8001_ha, pcibar, offset + 0x90) &
  755. 0xFFFFFF);
  756. pm8001_ha->fatal_tbl_addr =
  757. base_addr + (pm8001_cr32(pm8001_ha, pcibar, offset + 0xA0) &
  758. 0xFFFFFF);
  759. PM8001_INIT_DBG(pm8001_ha,
  760. pm8001_printk("GST OFFSET 0x%x\n",
  761. pm8001_cr32(pm8001_ha, pcibar, offset + 0x18)));
  762. PM8001_INIT_DBG(pm8001_ha,
  763. pm8001_printk("INBND OFFSET 0x%x\n",
  764. pm8001_cr32(pm8001_ha, pcibar, offset + 0x1C)));
  765. PM8001_INIT_DBG(pm8001_ha,
  766. pm8001_printk("OBND OFFSET 0x%x\n",
  767. pm8001_cr32(pm8001_ha, pcibar, offset + 0x20)));
  768. PM8001_INIT_DBG(pm8001_ha,
  769. pm8001_printk("IVT OFFSET 0x%x\n",
  770. pm8001_cr32(pm8001_ha, pcibar, offset + 0x8C)));
  771. PM8001_INIT_DBG(pm8001_ha,
  772. pm8001_printk("PSPA OFFSET 0x%x\n",
  773. pm8001_cr32(pm8001_ha, pcibar, offset + 0x90)));
  774. PM8001_INIT_DBG(pm8001_ha,
  775. pm8001_printk("addr - main cfg %p general status %p\n",
  776. pm8001_ha->main_cfg_tbl_addr,
  777. pm8001_ha->general_stat_tbl_addr));
  778. PM8001_INIT_DBG(pm8001_ha,
  779. pm8001_printk("addr - inbnd %p obnd %p\n",
  780. pm8001_ha->inbnd_q_tbl_addr,
  781. pm8001_ha->outbnd_q_tbl_addr));
  782. PM8001_INIT_DBG(pm8001_ha,
  783. pm8001_printk("addr - pspa %p ivt %p\n",
  784. pm8001_ha->pspa_q_tbl_addr,
  785. pm8001_ha->ivt_tbl_addr));
  786. }
  787. /**
  788. * pm80xx_set_thermal_config - support the thermal configuration
  789. * @pm8001_ha: our hba card information.
  790. */
  791. int
  792. pm80xx_set_thermal_config(struct pm8001_hba_info *pm8001_ha)
  793. {
  794. struct set_ctrl_cfg_req payload;
  795. struct inbound_queue_table *circularQ;
  796. int rc;
  797. u32 tag;
  798. u32 opc = OPC_INB_SET_CONTROLLER_CONFIG;
  799. u32 page_code;
  800. memset(&payload, 0, sizeof(struct set_ctrl_cfg_req));
  801. rc = pm8001_tag_alloc(pm8001_ha, &tag);
  802. if (rc)
  803. return -1;
  804. circularQ = &pm8001_ha->inbnd_q_tbl[0];
  805. payload.tag = cpu_to_le32(tag);
  806. if (IS_SPCV_12G(pm8001_ha->pdev))
  807. page_code = THERMAL_PAGE_CODE_7H;
  808. else
  809. page_code = THERMAL_PAGE_CODE_8H;
  810. payload.cfg_pg[0] = (THERMAL_LOG_ENABLE << 9) |
  811. (THERMAL_ENABLE << 8) | page_code;
  812. payload.cfg_pg[1] = (LTEMPHIL << 24) | (RTEMPHIL << 8);
  813. rc = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc, &payload, 0);
  814. if (rc)
  815. pm8001_tag_free(pm8001_ha, tag);
  816. return rc;
  817. }
  818. /**
  819. * pm80xx_set_sas_protocol_timer_config - support the SAS Protocol
  820. * Timer configuration page
  821. * @pm8001_ha: our hba card information.
  822. */
  823. static int
  824. pm80xx_set_sas_protocol_timer_config(struct pm8001_hba_info *pm8001_ha)
  825. {
  826. struct set_ctrl_cfg_req payload;
  827. struct inbound_queue_table *circularQ;
  828. SASProtocolTimerConfig_t SASConfigPage;
  829. int rc;
  830. u32 tag;
  831. u32 opc = OPC_INB_SET_CONTROLLER_CONFIG;
  832. memset(&payload, 0, sizeof(struct set_ctrl_cfg_req));
  833. memset(&SASConfigPage, 0, sizeof(SASProtocolTimerConfig_t));
  834. rc = pm8001_tag_alloc(pm8001_ha, &tag);
  835. if (rc)
  836. return -1;
  837. circularQ = &pm8001_ha->inbnd_q_tbl[0];
  838. payload.tag = cpu_to_le32(tag);
  839. SASConfigPage.pageCode = SAS_PROTOCOL_TIMER_CONFIG_PAGE;
  840. SASConfigPage.MST_MSI = 3 << 15;
  841. SASConfigPage.STP_SSP_MCT_TMO = (STP_MCT_TMO << 16) | SSP_MCT_TMO;
  842. SASConfigPage.STP_FRM_TMO = (SAS_MAX_OPEN_TIME << 24) |
  843. (SMP_MAX_CONN_TIMER << 16) | STP_FRM_TIMER;
  844. SASConfigPage.STP_IDLE_TMO = STP_IDLE_TIME;
  845. if (SASConfigPage.STP_IDLE_TMO > 0x3FFFFFF)
  846. SASConfigPage.STP_IDLE_TMO = 0x3FFFFFF;
  847. SASConfigPage.OPNRJT_RTRY_INTVL = (SAS_MFD << 16) |
  848. SAS_OPNRJT_RTRY_INTVL;
  849. SASConfigPage.Data_Cmd_OPNRJT_RTRY_TMO = (SAS_DOPNRJT_RTRY_TMO << 16)
  850. | SAS_COPNRJT_RTRY_TMO;
  851. SASConfigPage.Data_Cmd_OPNRJT_RTRY_THR = (SAS_DOPNRJT_RTRY_THR << 16)
  852. | SAS_COPNRJT_RTRY_THR;
  853. SASConfigPage.MAX_AIP = SAS_MAX_AIP;
  854. PM8001_INIT_DBG(pm8001_ha,
  855. pm8001_printk("SASConfigPage.pageCode "
  856. "0x%08x\n", SASConfigPage.pageCode));
  857. PM8001_INIT_DBG(pm8001_ha,
  858. pm8001_printk("SASConfigPage.MST_MSI "
  859. " 0x%08x\n", SASConfigPage.MST_MSI));
  860. PM8001_INIT_DBG(pm8001_ha,
  861. pm8001_printk("SASConfigPage.STP_SSP_MCT_TMO "
  862. " 0x%08x\n", SASConfigPage.STP_SSP_MCT_TMO));
  863. PM8001_INIT_DBG(pm8001_ha,
  864. pm8001_printk("SASConfigPage.STP_FRM_TMO "
  865. " 0x%08x\n", SASConfigPage.STP_FRM_TMO));
  866. PM8001_INIT_DBG(pm8001_ha,
  867. pm8001_printk("SASConfigPage.STP_IDLE_TMO "
  868. " 0x%08x\n", SASConfigPage.STP_IDLE_TMO));
  869. PM8001_INIT_DBG(pm8001_ha,
  870. pm8001_printk("SASConfigPage.OPNRJT_RTRY_INTVL "
  871. " 0x%08x\n", SASConfigPage.OPNRJT_RTRY_INTVL));
  872. PM8001_INIT_DBG(pm8001_ha,
  873. pm8001_printk("SASConfigPage.Data_Cmd_OPNRJT_RTRY_TMO "
  874. " 0x%08x\n", SASConfigPage.Data_Cmd_OPNRJT_RTRY_TMO));
  875. PM8001_INIT_DBG(pm8001_ha,
  876. pm8001_printk("SASConfigPage.Data_Cmd_OPNRJT_RTRY_THR "
  877. " 0x%08x\n", SASConfigPage.Data_Cmd_OPNRJT_RTRY_THR));
  878. PM8001_INIT_DBG(pm8001_ha, pm8001_printk("SASConfigPage.MAX_AIP "
  879. " 0x%08x\n", SASConfigPage.MAX_AIP));
  880. memcpy(&payload.cfg_pg, &SASConfigPage,
  881. sizeof(SASProtocolTimerConfig_t));
  882. rc = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc, &payload, 0);
  883. if (rc)
  884. pm8001_tag_free(pm8001_ha, tag);
  885. return rc;
  886. }
  887. /**
  888. * pm80xx_get_encrypt_info - Check for encryption
  889. * @pm8001_ha: our hba card information.
  890. */
  891. static int
  892. pm80xx_get_encrypt_info(struct pm8001_hba_info *pm8001_ha)
  893. {
  894. u32 scratch3_value;
  895. int ret = -1;
  896. /* Read encryption status from SCRATCH PAD 3 */
  897. scratch3_value = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_3);
  898. if ((scratch3_value & SCRATCH_PAD3_ENC_MASK) ==
  899. SCRATCH_PAD3_ENC_READY) {
  900. if (scratch3_value & SCRATCH_PAD3_XTS_ENABLED)
  901. pm8001_ha->encrypt_info.cipher_mode = CIPHER_MODE_XTS;
  902. if ((scratch3_value & SCRATCH_PAD3_SM_MASK) ==
  903. SCRATCH_PAD3_SMF_ENABLED)
  904. pm8001_ha->encrypt_info.sec_mode = SEC_MODE_SMF;
  905. if ((scratch3_value & SCRATCH_PAD3_SM_MASK) ==
  906. SCRATCH_PAD3_SMA_ENABLED)
  907. pm8001_ha->encrypt_info.sec_mode = SEC_MODE_SMA;
  908. if ((scratch3_value & SCRATCH_PAD3_SM_MASK) ==
  909. SCRATCH_PAD3_SMB_ENABLED)
  910. pm8001_ha->encrypt_info.sec_mode = SEC_MODE_SMB;
  911. pm8001_ha->encrypt_info.status = 0;
  912. PM8001_INIT_DBG(pm8001_ha, pm8001_printk(
  913. "Encryption: SCRATCH_PAD3_ENC_READY 0x%08X."
  914. "Cipher mode 0x%x Sec mode 0x%x status 0x%x\n",
  915. scratch3_value, pm8001_ha->encrypt_info.cipher_mode,
  916. pm8001_ha->encrypt_info.sec_mode,
  917. pm8001_ha->encrypt_info.status));
  918. ret = 0;
  919. } else if ((scratch3_value & SCRATCH_PAD3_ENC_READY) ==
  920. SCRATCH_PAD3_ENC_DISABLED) {
  921. PM8001_INIT_DBG(pm8001_ha, pm8001_printk(
  922. "Encryption: SCRATCH_PAD3_ENC_DISABLED 0x%08X\n",
  923. scratch3_value));
  924. pm8001_ha->encrypt_info.status = 0xFFFFFFFF;
  925. pm8001_ha->encrypt_info.cipher_mode = 0;
  926. pm8001_ha->encrypt_info.sec_mode = 0;
  927. ret = 0;
  928. } else if ((scratch3_value & SCRATCH_PAD3_ENC_MASK) ==
  929. SCRATCH_PAD3_ENC_DIS_ERR) {
  930. pm8001_ha->encrypt_info.status =
  931. (scratch3_value & SCRATCH_PAD3_ERR_CODE) >> 16;
  932. if (scratch3_value & SCRATCH_PAD3_XTS_ENABLED)
  933. pm8001_ha->encrypt_info.cipher_mode = CIPHER_MODE_XTS;
  934. if ((scratch3_value & SCRATCH_PAD3_SM_MASK) ==
  935. SCRATCH_PAD3_SMF_ENABLED)
  936. pm8001_ha->encrypt_info.sec_mode = SEC_MODE_SMF;
  937. if ((scratch3_value & SCRATCH_PAD3_SM_MASK) ==
  938. SCRATCH_PAD3_SMA_ENABLED)
  939. pm8001_ha->encrypt_info.sec_mode = SEC_MODE_SMA;
  940. if ((scratch3_value & SCRATCH_PAD3_SM_MASK) ==
  941. SCRATCH_PAD3_SMB_ENABLED)
  942. pm8001_ha->encrypt_info.sec_mode = SEC_MODE_SMB;
  943. PM8001_INIT_DBG(pm8001_ha, pm8001_printk(
  944. "Encryption: SCRATCH_PAD3_DIS_ERR 0x%08X."
  945. "Cipher mode 0x%x sec mode 0x%x status 0x%x\n",
  946. scratch3_value, pm8001_ha->encrypt_info.cipher_mode,
  947. pm8001_ha->encrypt_info.sec_mode,
  948. pm8001_ha->encrypt_info.status));
  949. } else if ((scratch3_value & SCRATCH_PAD3_ENC_MASK) ==
  950. SCRATCH_PAD3_ENC_ENA_ERR) {
  951. pm8001_ha->encrypt_info.status =
  952. (scratch3_value & SCRATCH_PAD3_ERR_CODE) >> 16;
  953. if (scratch3_value & SCRATCH_PAD3_XTS_ENABLED)
  954. pm8001_ha->encrypt_info.cipher_mode = CIPHER_MODE_XTS;
  955. if ((scratch3_value & SCRATCH_PAD3_SM_MASK) ==
  956. SCRATCH_PAD3_SMF_ENABLED)
  957. pm8001_ha->encrypt_info.sec_mode = SEC_MODE_SMF;
  958. if ((scratch3_value & SCRATCH_PAD3_SM_MASK) ==
  959. SCRATCH_PAD3_SMA_ENABLED)
  960. pm8001_ha->encrypt_info.sec_mode = SEC_MODE_SMA;
  961. if ((scratch3_value & SCRATCH_PAD3_SM_MASK) ==
  962. SCRATCH_PAD3_SMB_ENABLED)
  963. pm8001_ha->encrypt_info.sec_mode = SEC_MODE_SMB;
  964. PM8001_INIT_DBG(pm8001_ha, pm8001_printk(
  965. "Encryption: SCRATCH_PAD3_ENA_ERR 0x%08X."
  966. "Cipher mode 0x%x sec mode 0x%x status 0x%x\n",
  967. scratch3_value, pm8001_ha->encrypt_info.cipher_mode,
  968. pm8001_ha->encrypt_info.sec_mode,
  969. pm8001_ha->encrypt_info.status));
  970. }
  971. return ret;
  972. }
  973. /**
  974. * pm80xx_encrypt_update - update flash with encryption informtion
  975. * @pm8001_ha: our hba card information.
  976. */
  977. static int pm80xx_encrypt_update(struct pm8001_hba_info *pm8001_ha)
  978. {
  979. struct kek_mgmt_req payload;
  980. struct inbound_queue_table *circularQ;
  981. int rc;
  982. u32 tag;
  983. u32 opc = OPC_INB_KEK_MANAGEMENT;
  984. memset(&payload, 0, sizeof(struct kek_mgmt_req));
  985. rc = pm8001_tag_alloc(pm8001_ha, &tag);
  986. if (rc)
  987. return -1;
  988. circularQ = &pm8001_ha->inbnd_q_tbl[0];
  989. payload.tag = cpu_to_le32(tag);
  990. /* Currently only one key is used. New KEK index is 1.
  991. * Current KEK index is 1. Store KEK to NVRAM is 1.
  992. */
  993. payload.new_curidx_ksop = ((1 << 24) | (1 << 16) | (1 << 8) |
  994. KEK_MGMT_SUBOP_KEYCARDUPDATE);
  995. rc = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc, &payload, 0);
  996. if (rc)
  997. pm8001_tag_free(pm8001_ha, tag);
  998. return rc;
  999. }
  1000. /**
  1001. * pm8001_chip_init - the main init function that initialize whole PM8001 chip.
  1002. * @pm8001_ha: our hba card information
  1003. */
  1004. static int pm80xx_chip_init(struct pm8001_hba_info *pm8001_ha)
  1005. {
  1006. int ret;
  1007. u8 i = 0;
  1008. /* check the firmware status */
  1009. if (-1 == check_fw_ready(pm8001_ha)) {
  1010. PM8001_FAIL_DBG(pm8001_ha,
  1011. pm8001_printk("Firmware is not ready!\n"));
  1012. return -EBUSY;
  1013. }
  1014. /* Initialize pci space address eg: mpi offset */
  1015. init_pci_device_addresses(pm8001_ha);
  1016. init_default_table_values(pm8001_ha);
  1017. read_main_config_table(pm8001_ha);
  1018. read_general_status_table(pm8001_ha);
  1019. read_inbnd_queue_table(pm8001_ha);
  1020. read_outbnd_queue_table(pm8001_ha);
  1021. read_phy_attr_table(pm8001_ha);
  1022. /* update main config table ,inbound table and outbound table */
  1023. update_main_config_table(pm8001_ha);
  1024. for (i = 0; i < PM8001_MAX_SPCV_INB_NUM; i++)
  1025. update_inbnd_queue_table(pm8001_ha, i);
  1026. for (i = 0; i < PM8001_MAX_SPCV_OUTB_NUM; i++)
  1027. update_outbnd_queue_table(pm8001_ha, i);
  1028. /* notify firmware update finished and check initialization status */
  1029. if (0 == mpi_init_check(pm8001_ha)) {
  1030. PM8001_INIT_DBG(pm8001_ha,
  1031. pm8001_printk("MPI initialize successful!\n"));
  1032. } else
  1033. return -EBUSY;
  1034. /* send SAS protocol timer configuration page to FW */
  1035. ret = pm80xx_set_sas_protocol_timer_config(pm8001_ha);
  1036. /* Check for encryption */
  1037. if (pm8001_ha->chip->encrypt) {
  1038. PM8001_INIT_DBG(pm8001_ha,
  1039. pm8001_printk("Checking for encryption\n"));
  1040. ret = pm80xx_get_encrypt_info(pm8001_ha);
  1041. if (ret == -1) {
  1042. PM8001_INIT_DBG(pm8001_ha,
  1043. pm8001_printk("Encryption error !!\n"));
  1044. if (pm8001_ha->encrypt_info.status == 0x81) {
  1045. PM8001_INIT_DBG(pm8001_ha, pm8001_printk(
  1046. "Encryption enabled with error."
  1047. "Saving encryption key to flash\n"));
  1048. pm80xx_encrypt_update(pm8001_ha);
  1049. }
  1050. }
  1051. }
  1052. return 0;
  1053. }
  1054. static int mpi_uninit_check(struct pm8001_hba_info *pm8001_ha)
  1055. {
  1056. u32 max_wait_count;
  1057. u32 value;
  1058. u32 gst_len_mpistate;
  1059. init_pci_device_addresses(pm8001_ha);
  1060. /* Write bit1=1 to Inbound DoorBell Register to tell the SPC FW the
  1061. table is stop */
  1062. pm8001_cw32(pm8001_ha, 0, MSGU_IBDB_SET, SPCv_MSGU_CFG_TABLE_RESET);
  1063. /* wait until Inbound DoorBell Clear Register toggled */
  1064. if (IS_SPCV_12G(pm8001_ha->pdev)) {
  1065. max_wait_count = 4 * 1000 * 1000;/* 4 sec */
  1066. } else {
  1067. max_wait_count = 2 * 1000 * 1000;/* 2 sec */
  1068. }
  1069. do {
  1070. udelay(1);
  1071. value = pm8001_cr32(pm8001_ha, 0, MSGU_IBDB_SET);
  1072. value &= SPCv_MSGU_CFG_TABLE_RESET;
  1073. } while ((value != 0) && (--max_wait_count));
  1074. if (!max_wait_count) {
  1075. PM8001_FAIL_DBG(pm8001_ha,
  1076. pm8001_printk("TIMEOUT:IBDB value/=%x\n", value));
  1077. return -1;
  1078. }
  1079. /* check the MPI-State for termination in progress */
  1080. /* wait until Inbound DoorBell Clear Register toggled */
  1081. max_wait_count = 2 * 1000 * 1000; /* 2 sec for spcv/ve */
  1082. do {
  1083. udelay(1);
  1084. gst_len_mpistate =
  1085. pm8001_mr32(pm8001_ha->general_stat_tbl_addr,
  1086. GST_GSTLEN_MPIS_OFFSET);
  1087. if (GST_MPI_STATE_UNINIT ==
  1088. (gst_len_mpistate & GST_MPI_STATE_MASK))
  1089. break;
  1090. } while (--max_wait_count);
  1091. if (!max_wait_count) {
  1092. PM8001_FAIL_DBG(pm8001_ha,
  1093. pm8001_printk(" TIME OUT MPI State = 0x%x\n",
  1094. gst_len_mpistate & GST_MPI_STATE_MASK));
  1095. return -1;
  1096. }
  1097. return 0;
  1098. }
  1099. /**
  1100. * pm8001_chip_soft_rst - soft reset the PM8001 chip, so that the clear all
  1101. * the FW register status to the originated status.
  1102. * @pm8001_ha: our hba card information
  1103. */
  1104. static int
  1105. pm80xx_chip_soft_rst(struct pm8001_hba_info *pm8001_ha)
  1106. {
  1107. u32 regval;
  1108. u32 bootloader_state;
  1109. u32 ibutton0, ibutton1;
  1110. /* Check if MPI is in ready state to reset */
  1111. if (mpi_uninit_check(pm8001_ha) != 0) {
  1112. PM8001_FAIL_DBG(pm8001_ha,
  1113. pm8001_printk("MPI state is not ready\n"));
  1114. return -1;
  1115. }
  1116. /* checked for reset register normal state; 0x0 */
  1117. regval = pm8001_cr32(pm8001_ha, 0, SPC_REG_SOFT_RESET);
  1118. PM8001_INIT_DBG(pm8001_ha,
  1119. pm8001_printk("reset register before write : 0x%x\n", regval));
  1120. pm8001_cw32(pm8001_ha, 0, SPC_REG_SOFT_RESET, SPCv_NORMAL_RESET_VALUE);
  1121. mdelay(500);
  1122. regval = pm8001_cr32(pm8001_ha, 0, SPC_REG_SOFT_RESET);
  1123. PM8001_INIT_DBG(pm8001_ha,
  1124. pm8001_printk("reset register after write 0x%x\n", regval));
  1125. if ((regval & SPCv_SOFT_RESET_READ_MASK) ==
  1126. SPCv_SOFT_RESET_NORMAL_RESET_OCCURED) {
  1127. PM8001_MSG_DBG(pm8001_ha,
  1128. pm8001_printk(" soft reset successful [regval: 0x%x]\n",
  1129. regval));
  1130. } else {
  1131. PM8001_MSG_DBG(pm8001_ha,
  1132. pm8001_printk(" soft reset failed [regval: 0x%x]\n",
  1133. regval));
  1134. /* check bootloader is successfully executed or in HDA mode */
  1135. bootloader_state =
  1136. pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_1) &
  1137. SCRATCH_PAD1_BOOTSTATE_MASK;
  1138. if (bootloader_state == SCRATCH_PAD1_BOOTSTATE_HDA_SEEPROM) {
  1139. PM8001_MSG_DBG(pm8001_ha, pm8001_printk(
  1140. "Bootloader state - HDA mode SEEPROM\n"));
  1141. } else if (bootloader_state ==
  1142. SCRATCH_PAD1_BOOTSTATE_HDA_BOOTSTRAP) {
  1143. PM8001_MSG_DBG(pm8001_ha, pm8001_printk(
  1144. "Bootloader state - HDA mode Bootstrap Pin\n"));
  1145. } else if (bootloader_state ==
  1146. SCRATCH_PAD1_BOOTSTATE_HDA_SOFTRESET) {
  1147. PM8001_MSG_DBG(pm8001_ha, pm8001_printk(
  1148. "Bootloader state - HDA mode soft reset\n"));
  1149. } else if (bootloader_state ==
  1150. SCRATCH_PAD1_BOOTSTATE_CRIT_ERROR) {
  1151. PM8001_MSG_DBG(pm8001_ha, pm8001_printk(
  1152. "Bootloader state-HDA mode critical error\n"));
  1153. }
  1154. return -EBUSY;
  1155. }
  1156. /* check the firmware status after reset */
  1157. if (-1 == check_fw_ready(pm8001_ha)) {
  1158. PM8001_FAIL_DBG(pm8001_ha,
  1159. pm8001_printk("Firmware is not ready!\n"));
  1160. /* check iButton feature support for motherboard controller */
  1161. if (pm8001_ha->pdev->subsystem_vendor !=
  1162. PCI_VENDOR_ID_ADAPTEC2 &&
  1163. pm8001_ha->pdev->subsystem_vendor !=
  1164. PCI_VENDOR_ID_ATTO &&
  1165. pm8001_ha->pdev->subsystem_vendor != 0) {
  1166. ibutton0 = pm8001_cr32(pm8001_ha, 0,
  1167. MSGU_HOST_SCRATCH_PAD_6);
  1168. ibutton1 = pm8001_cr32(pm8001_ha, 0,
  1169. MSGU_HOST_SCRATCH_PAD_7);
  1170. if (!ibutton0 && !ibutton1) {
  1171. PM8001_FAIL_DBG(pm8001_ha,
  1172. pm8001_printk("iButton Feature is"
  1173. " not Available!!!\n"));
  1174. return -EBUSY;
  1175. }
  1176. if (ibutton0 == 0xdeadbeef && ibutton1 == 0xdeadbeef) {
  1177. PM8001_FAIL_DBG(pm8001_ha,
  1178. pm8001_printk("CRC Check for iButton"
  1179. " Feature Failed!!!\n"));
  1180. return -EBUSY;
  1181. }
  1182. }
  1183. }
  1184. PM8001_INIT_DBG(pm8001_ha,
  1185. pm8001_printk("SPCv soft reset Complete\n"));
  1186. return 0;
  1187. }
  1188. static void pm80xx_hw_chip_rst(struct pm8001_hba_info *pm8001_ha)
  1189. {
  1190. u32 i;
  1191. PM8001_INIT_DBG(pm8001_ha,
  1192. pm8001_printk("chip reset start\n"));
  1193. /* do SPCv chip reset. */
  1194. pm8001_cw32(pm8001_ha, 0, SPC_REG_SOFT_RESET, 0x11);
  1195. PM8001_INIT_DBG(pm8001_ha,
  1196. pm8001_printk("SPC soft reset Complete\n"));
  1197. /* Check this ..whether delay is required or no */
  1198. /* delay 10 usec */
  1199. udelay(10);
  1200. /* wait for 20 msec until the firmware gets reloaded */
  1201. i = 20;
  1202. do {
  1203. mdelay(1);
  1204. } while ((--i) != 0);
  1205. PM8001_INIT_DBG(pm8001_ha,
  1206. pm8001_printk("chip reset finished\n"));
  1207. }
  1208. /**
  1209. * pm8001_chip_interrupt_enable - enable PM8001 chip interrupt
  1210. * @pm8001_ha: our hba card information
  1211. */
  1212. static void
  1213. pm80xx_chip_intx_interrupt_enable(struct pm8001_hba_info *pm8001_ha)
  1214. {
  1215. pm8001_cw32(pm8001_ha, 0, MSGU_ODMR, ODMR_CLEAR_ALL);
  1216. pm8001_cw32(pm8001_ha, 0, MSGU_ODCR, ODCR_CLEAR_ALL);
  1217. }
  1218. /**
  1219. * pm8001_chip_intx_interrupt_disable- disable PM8001 chip interrupt
  1220. * @pm8001_ha: our hba card information
  1221. */
  1222. static void
  1223. pm80xx_chip_intx_interrupt_disable(struct pm8001_hba_info *pm8001_ha)
  1224. {
  1225. pm8001_cw32(pm8001_ha, 0, MSGU_ODMR_CLR, ODMR_MASK_ALL);
  1226. }
  1227. /**
  1228. * pm8001_chip_interrupt_enable - enable PM8001 chip interrupt
  1229. * @pm8001_ha: our hba card information
  1230. */
  1231. static void
  1232. pm80xx_chip_interrupt_enable(struct pm8001_hba_info *pm8001_ha, u8 vec)
  1233. {
  1234. #ifdef PM8001_USE_MSIX
  1235. u32 mask;
  1236. mask = (u32)(1 << vec);
  1237. pm8001_cw32(pm8001_ha, 0, MSGU_ODMR_CLR, (u32)(mask & 0xFFFFFFFF));
  1238. return;
  1239. #endif
  1240. pm80xx_chip_intx_interrupt_enable(pm8001_ha);
  1241. }
  1242. /**
  1243. * pm8001_chip_interrupt_disable- disable PM8001 chip interrupt
  1244. * @pm8001_ha: our hba card information
  1245. */
  1246. static void
  1247. pm80xx_chip_interrupt_disable(struct pm8001_hba_info *pm8001_ha, u8 vec)
  1248. {
  1249. #ifdef PM8001_USE_MSIX
  1250. u32 mask;
  1251. if (vec == 0xFF)
  1252. mask = 0xFFFFFFFF;
  1253. else
  1254. mask = (u32)(1 << vec);
  1255. pm8001_cw32(pm8001_ha, 0, MSGU_ODMR, (u32)(mask & 0xFFFFFFFF));
  1256. return;
  1257. #endif
  1258. pm80xx_chip_intx_interrupt_disable(pm8001_ha);
  1259. }
  1260. static void pm80xx_send_abort_all(struct pm8001_hba_info *pm8001_ha,
  1261. struct pm8001_device *pm8001_ha_dev)
  1262. {
  1263. int res;
  1264. u32 ccb_tag;
  1265. struct pm8001_ccb_info *ccb;
  1266. struct sas_task *task = NULL;
  1267. struct task_abort_req task_abort;
  1268. struct inbound_queue_table *circularQ;
  1269. u32 opc = OPC_INB_SATA_ABORT;
  1270. int ret;
  1271. if (!pm8001_ha_dev) {
  1272. PM8001_FAIL_DBG(pm8001_ha, pm8001_printk("dev is null\n"));
  1273. return;
  1274. }
  1275. task = sas_alloc_slow_task(GFP_ATOMIC);
  1276. if (!task) {
  1277. PM8001_FAIL_DBG(pm8001_ha, pm8001_printk("cannot "
  1278. "allocate task\n"));
  1279. return;
  1280. }
  1281. task->task_done = pm8001_task_done;
  1282. res = pm8001_tag_alloc(pm8001_ha, &ccb_tag);
  1283. if (res) {
  1284. sas_free_task(task);
  1285. return;
  1286. }
  1287. ccb = &pm8001_ha->ccb_info[ccb_tag];
  1288. ccb->device = pm8001_ha_dev;
  1289. ccb->ccb_tag = ccb_tag;
  1290. ccb->task = task;
  1291. circularQ = &pm8001_ha->inbnd_q_tbl[0];
  1292. memset(&task_abort, 0, sizeof(task_abort));
  1293. task_abort.abort_all = cpu_to_le32(1);
  1294. task_abort.device_id = cpu_to_le32(pm8001_ha_dev->device_id);
  1295. task_abort.tag = cpu_to_le32(ccb_tag);
  1296. ret = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc, &task_abort, 0);
  1297. if (ret) {
  1298. sas_free_task(task);
  1299. pm8001_tag_free(pm8001_ha, ccb_tag);
  1300. }
  1301. }
  1302. static void pm80xx_send_read_log(struct pm8001_hba_info *pm8001_ha,
  1303. struct pm8001_device *pm8001_ha_dev)
  1304. {
  1305. struct sata_start_req sata_cmd;
  1306. int res;
  1307. u32 ccb_tag;
  1308. struct pm8001_ccb_info *ccb;
  1309. struct sas_task *task = NULL;
  1310. struct host_to_dev_fis fis;
  1311. struct domain_device *dev;
  1312. struct inbound_queue_table *circularQ;
  1313. u32 opc = OPC_INB_SATA_HOST_OPSTART;
  1314. task = sas_alloc_slow_task(GFP_ATOMIC);
  1315. if (!task) {
  1316. PM8001_FAIL_DBG(pm8001_ha,
  1317. pm8001_printk("cannot allocate task !!!\n"));
  1318. return;
  1319. }
  1320. task->task_done = pm8001_task_done;
  1321. res = pm8001_tag_alloc(pm8001_ha, &ccb_tag);
  1322. if (res) {
  1323. sas_free_task(task);
  1324. PM8001_FAIL_DBG(pm8001_ha,
  1325. pm8001_printk("cannot allocate tag !!!\n"));
  1326. return;
  1327. }
  1328. /* allocate domain device by ourselves as libsas
  1329. * is not going to provide any
  1330. */
  1331. dev = kzalloc(sizeof(struct domain_device), GFP_ATOMIC);
  1332. if (!dev) {
  1333. sas_free_task(task);
  1334. pm8001_tag_free(pm8001_ha, ccb_tag);
  1335. PM8001_FAIL_DBG(pm8001_ha,
  1336. pm8001_printk("Domain device cannot be allocated\n"));
  1337. return;
  1338. }
  1339. task->dev = dev;
  1340. task->dev->lldd_dev = pm8001_ha_dev;
  1341. ccb = &pm8001_ha->ccb_info[ccb_tag];
  1342. ccb->device = pm8001_ha_dev;
  1343. ccb->ccb_tag = ccb_tag;
  1344. ccb->task = task;
  1345. pm8001_ha_dev->id |= NCQ_READ_LOG_FLAG;
  1346. pm8001_ha_dev->id |= NCQ_2ND_RLE_FLAG;
  1347. memset(&sata_cmd, 0, sizeof(sata_cmd));
  1348. circularQ = &pm8001_ha->inbnd_q_tbl[0];
  1349. /* construct read log FIS */
  1350. memset(&fis, 0, sizeof(struct host_to_dev_fis));
  1351. fis.fis_type = 0x27;
  1352. fis.flags = 0x80;
  1353. fis.command = ATA_CMD_READ_LOG_EXT;
  1354. fis.lbal = 0x10;
  1355. fis.sector_count = 0x1;
  1356. sata_cmd.tag = cpu_to_le32(ccb_tag);
  1357. sata_cmd.device_id = cpu_to_le32(pm8001_ha_dev->device_id);
  1358. sata_cmd.ncqtag_atap_dir_m_dad |= ((0x1 << 7) | (0x5 << 9));
  1359. memcpy(&sata_cmd.sata_fis, &fis, sizeof(struct host_to_dev_fis));
  1360. res = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc, &sata_cmd, 0);
  1361. if (res) {
  1362. sas_free_task(task);
  1363. pm8001_tag_free(pm8001_ha, ccb_tag);
  1364. kfree(dev);
  1365. }
  1366. }
  1367. /**
  1368. * mpi_ssp_completion- process the event that FW response to the SSP request.
  1369. * @pm8001_ha: our hba card information
  1370. * @piomb: the message contents of this outbound message.
  1371. *
  1372. * When FW has completed a ssp request for example a IO request, after it has
  1373. * filled the SG data with the data, it will trigger this event represent
  1374. * that he has finished the job,please check the coresponding buffer.
  1375. * So we will tell the caller who maybe waiting the result to tell upper layer
  1376. * that the task has been finished.
  1377. */
  1378. static void
  1379. mpi_ssp_completion(struct pm8001_hba_info *pm8001_ha , void *piomb)
  1380. {
  1381. struct sas_task *t;
  1382. struct pm8001_ccb_info *ccb;
  1383. unsigned long flags;
  1384. u32 status;
  1385. u32 param;
  1386. u32 tag;
  1387. struct ssp_completion_resp *psspPayload;
  1388. struct task_status_struct *ts;
  1389. struct ssp_response_iu *iu;
  1390. struct pm8001_device *pm8001_dev;
  1391. psspPayload = (struct ssp_completion_resp *)(piomb + 4);
  1392. status = le32_to_cpu(psspPayload->status);
  1393. tag = le32_to_cpu(psspPayload->tag);
  1394. ccb = &pm8001_ha->ccb_info[tag];
  1395. if ((status == IO_ABORTED) && ccb->open_retry) {
  1396. /* Being completed by another */
  1397. ccb->open_retry = 0;
  1398. return;
  1399. }
  1400. pm8001_dev = ccb->device;
  1401. param = le32_to_cpu(psspPayload->param);
  1402. t = ccb->task;
  1403. if (status && status != IO_UNDERFLOW)
  1404. PM8001_FAIL_DBG(pm8001_ha,
  1405. pm8001_printk("sas IO status 0x%x\n", status));
  1406. if (unlikely(!t || !t->lldd_task || !t->dev))
  1407. return;
  1408. ts = &t->task_status;
  1409. /* Print sas address of IO failed device */
  1410. if ((status != IO_SUCCESS) && (status != IO_OVERFLOW) &&
  1411. (status != IO_UNDERFLOW))
  1412. PM8001_FAIL_DBG(pm8001_ha,
  1413. pm8001_printk("SAS Address of IO Failure Drive"
  1414. ":%016llx", SAS_ADDR(t->dev->sas_addr)));
  1415. switch (status) {
  1416. case IO_SUCCESS:
  1417. PM8001_IO_DBG(pm8001_ha,
  1418. pm8001_printk("IO_SUCCESS ,param = 0x%x\n",
  1419. param));
  1420. if (param == 0) {
  1421. ts->resp = SAS_TASK_COMPLETE;
  1422. ts->stat = SAM_STAT_GOOD;
  1423. } else {
  1424. ts->resp = SAS_TASK_COMPLETE;
  1425. ts->stat = SAS_PROTO_RESPONSE;
  1426. ts->residual = param;
  1427. iu = &psspPayload->ssp_resp_iu;
  1428. sas_ssp_task_response(pm8001_ha->dev, t, iu);
  1429. }
  1430. if (pm8001_dev)
  1431. pm8001_dev->running_req--;
  1432. break;
  1433. case IO_ABORTED:
  1434. PM8001_IO_DBG(pm8001_ha,
  1435. pm8001_printk("IO_ABORTED IOMB Tag\n"));
  1436. ts->resp = SAS_TASK_COMPLETE;
  1437. ts->stat = SAS_ABORTED_TASK;
  1438. break;
  1439. case IO_UNDERFLOW:
  1440. /* SSP Completion with error */
  1441. PM8001_IO_DBG(pm8001_ha,
  1442. pm8001_printk("IO_UNDERFLOW ,param = 0x%x\n",
  1443. param));
  1444. ts->resp = SAS_TASK_COMPLETE;
  1445. ts->stat = SAS_DATA_UNDERRUN;
  1446. ts->residual = param;
  1447. if (pm8001_dev)
  1448. pm8001_dev->running_req--;
  1449. break;
  1450. case IO_NO_DEVICE:
  1451. PM8001_IO_DBG(pm8001_ha,
  1452. pm8001_printk("IO_NO_DEVICE\n"));
  1453. ts->resp = SAS_TASK_UNDELIVERED;
  1454. ts->stat = SAS_PHY_DOWN;
  1455. break;
  1456. case IO_XFER_ERROR_BREAK:
  1457. PM8001_IO_DBG(pm8001_ha,
  1458. pm8001_printk("IO_XFER_ERROR_BREAK\n"));
  1459. ts->resp = SAS_TASK_COMPLETE;
  1460. ts->stat = SAS_OPEN_REJECT;
  1461. /* Force the midlayer to retry */
  1462. ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
  1463. break;
  1464. case IO_XFER_ERROR_PHY_NOT_READY:
  1465. PM8001_IO_DBG(pm8001_ha,
  1466. pm8001_printk("IO_XFER_ERROR_PHY_NOT_READY\n"));
  1467. ts->resp = SAS_TASK_COMPLETE;
  1468. ts->stat = SAS_OPEN_REJECT;
  1469. ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
  1470. break;
  1471. case IO_XFER_ERROR_INVALID_SSP_RSP_FRAME:
  1472. PM8001_IO_DBG(pm8001_ha,
  1473. pm8001_printk("IO_XFER_ERROR_INVALID_SSP_RSP_FRAME\n"));
  1474. ts->resp = SAS_TASK_COMPLETE;
  1475. ts->stat = SAS_OPEN_REJECT;
  1476. ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
  1477. break;
  1478. case IO_OPEN_CNX_ERROR_PROTOCOL_NOT_SUPPORTED:
  1479. PM8001_IO_DBG(pm8001_ha,
  1480. pm8001_printk("IO_OPEN_CNX_ERROR_PROTOCOL_NOT_SUPPORTED\n"));
  1481. ts->resp = SAS_TASK_COMPLETE;
  1482. ts->stat = SAS_OPEN_REJECT;
  1483. ts->open_rej_reason = SAS_OREJ_EPROTO;
  1484. break;
  1485. case IO_OPEN_CNX_ERROR_ZONE_VIOLATION:
  1486. PM8001_IO_DBG(pm8001_ha,
  1487. pm8001_printk("IO_OPEN_CNX_ERROR_ZONE_VIOLATION\n"));
  1488. ts->resp = SAS_TASK_COMPLETE;
  1489. ts->stat = SAS_OPEN_REJECT;
  1490. ts->open_rej_reason = SAS_OREJ_UNKNOWN;
  1491. break;
  1492. case IO_OPEN_CNX_ERROR_BREAK:
  1493. PM8001_IO_DBG(pm8001_ha,
  1494. pm8001_printk("IO_OPEN_CNX_ERROR_BREAK\n"));
  1495. ts->resp = SAS_TASK_COMPLETE;
  1496. ts->stat = SAS_OPEN_REJECT;
  1497. ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
  1498. break;
  1499. case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS:
  1500. case IO_XFER_OPEN_RETRY_BACKOFF_THRESHOLD_REACHED:
  1501. case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_OPEN_TMO:
  1502. case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_NO_DEST:
  1503. case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_OPEN_COLLIDE:
  1504. case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_PATHWAY_BLOCKED:
  1505. PM8001_IO_DBG(pm8001_ha,
  1506. pm8001_printk("IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS\n"));
  1507. ts->resp = SAS_TASK_COMPLETE;
  1508. ts->stat = SAS_OPEN_REJECT;
  1509. ts->open_rej_reason = SAS_OREJ_UNKNOWN;
  1510. if (!t->uldd_task)
  1511. pm8001_handle_event(pm8001_ha,
  1512. pm8001_dev,
  1513. IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS);
  1514. break;
  1515. case IO_OPEN_CNX_ERROR_BAD_DESTINATION:
  1516. PM8001_IO_DBG(pm8001_ha,
  1517. pm8001_printk("IO_OPEN_CNX_ERROR_BAD_DESTINATION\n"));
  1518. ts->resp = SAS_TASK_COMPLETE;
  1519. ts->stat = SAS_OPEN_REJECT;
  1520. ts->open_rej_reason = SAS_OREJ_BAD_DEST;
  1521. break;
  1522. case IO_OPEN_CNX_ERROR_CONNECTION_RATE_NOT_SUPPORTED:
  1523. PM8001_IO_DBG(pm8001_ha, pm8001_printk(
  1524. "IO_OPEN_CNX_ERROR_CONNECTION_RATE_NOT_SUPPORTED\n"));
  1525. ts->resp = SAS_TASK_COMPLETE;
  1526. ts->stat = SAS_OPEN_REJECT;
  1527. ts->open_rej_reason = SAS_OREJ_CONN_RATE;
  1528. break;
  1529. case IO_OPEN_CNX_ERROR_WRONG_DESTINATION:
  1530. PM8001_IO_DBG(pm8001_ha,
  1531. pm8001_printk("IO_OPEN_CNX_ERROR_WRONG_DESTINATION\n"));
  1532. ts->resp = SAS_TASK_UNDELIVERED;
  1533. ts->stat = SAS_OPEN_REJECT;
  1534. ts->open_rej_reason = SAS_OREJ_WRONG_DEST;
  1535. break;
  1536. case IO_XFER_ERROR_NAK_RECEIVED:
  1537. PM8001_IO_DBG(pm8001_ha,
  1538. pm8001_printk("IO_XFER_ERROR_NAK_RECEIVED\n"));
  1539. ts->resp = SAS_TASK_COMPLETE;
  1540. ts->stat = SAS_OPEN_REJECT;
  1541. ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
  1542. break;
  1543. case IO_XFER_ERROR_ACK_NAK_TIMEOUT:
  1544. PM8001_IO_DBG(pm8001_ha,
  1545. pm8001_printk("IO_XFER_ERROR_ACK_NAK_TIMEOUT\n"));
  1546. ts->resp = SAS_TASK_COMPLETE;
  1547. ts->stat = SAS_NAK_R_ERR;
  1548. break;
  1549. case IO_XFER_ERROR_DMA:
  1550. PM8001_IO_DBG(pm8001_ha,
  1551. pm8001_printk("IO_XFER_ERROR_DMA\n"));
  1552. ts->resp = SAS_TASK_COMPLETE;
  1553. ts->stat = SAS_OPEN_REJECT;
  1554. break;
  1555. case IO_XFER_OPEN_RETRY_TIMEOUT:
  1556. PM8001_IO_DBG(pm8001_ha,
  1557. pm8001_printk("IO_XFER_OPEN_RETRY_TIMEOUT\n"));
  1558. ts->resp = SAS_TASK_COMPLETE;
  1559. ts->stat = SAS_OPEN_REJECT;
  1560. ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
  1561. break;
  1562. case IO_XFER_ERROR_OFFSET_MISMATCH:
  1563. PM8001_IO_DBG(pm8001_ha,
  1564. pm8001_printk("IO_XFER_ERROR_OFFSET_MISMATCH\n"));
  1565. ts->resp = SAS_TASK_COMPLETE;
  1566. ts->stat = SAS_OPEN_REJECT;
  1567. break;
  1568. case IO_PORT_IN_RESET:
  1569. PM8001_IO_DBG(pm8001_ha,
  1570. pm8001_printk("IO_PORT_IN_RESET\n"));
  1571. ts->resp = SAS_TASK_COMPLETE;
  1572. ts->stat = SAS_OPEN_REJECT;
  1573. break;
  1574. case IO_DS_NON_OPERATIONAL:
  1575. PM8001_IO_DBG(pm8001_ha,
  1576. pm8001_printk("IO_DS_NON_OPERATIONAL\n"));
  1577. ts->resp = SAS_TASK_COMPLETE;
  1578. ts->stat = SAS_OPEN_REJECT;
  1579. if (!t->uldd_task)
  1580. pm8001_handle_event(pm8001_ha,
  1581. pm8001_dev,
  1582. IO_DS_NON_OPERATIONAL);
  1583. break;
  1584. case IO_DS_IN_RECOVERY:
  1585. PM8001_IO_DBG(pm8001_ha,
  1586. pm8001_printk("IO_DS_IN_RECOVERY\n"));
  1587. ts->resp = SAS_TASK_COMPLETE;
  1588. ts->stat = SAS_OPEN_REJECT;
  1589. break;
  1590. case IO_TM_TAG_NOT_FOUND:
  1591. PM8001_IO_DBG(pm8001_ha,
  1592. pm8001_printk("IO_TM_TAG_NOT_FOUND\n"));
  1593. ts->resp = SAS_TASK_COMPLETE;
  1594. ts->stat = SAS_OPEN_REJECT;
  1595. break;
  1596. case IO_SSP_EXT_IU_ZERO_LEN_ERROR:
  1597. PM8001_IO_DBG(pm8001_ha,
  1598. pm8001_printk("IO_SSP_EXT_IU_ZERO_LEN_ERROR\n"));
  1599. ts->resp = SAS_TASK_COMPLETE;
  1600. ts->stat = SAS_OPEN_REJECT;
  1601. break;
  1602. case IO_OPEN_CNX_ERROR_HW_RESOURCE_BUSY:
  1603. PM8001_IO_DBG(pm8001_ha,
  1604. pm8001_printk("IO_OPEN_CNX_ERROR_HW_RESOURCE_BUSY\n"));
  1605. ts->resp = SAS_TASK_COMPLETE;
  1606. ts->stat = SAS_OPEN_REJECT;
  1607. ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
  1608. break;
  1609. default:
  1610. PM8001_IO_DBG(pm8001_ha,
  1611. pm8001_printk("Unknown status 0x%x\n", status));
  1612. /* not allowed case. Therefore, return failed status */
  1613. ts->resp = SAS_TASK_COMPLETE;
  1614. ts->stat = SAS_OPEN_REJECT;
  1615. break;
  1616. }
  1617. PM8001_IO_DBG(pm8001_ha,
  1618. pm8001_printk("scsi_status = 0x%x\n ",
  1619. psspPayload->ssp_resp_iu.status));
  1620. spin_lock_irqsave(&t->task_state_lock, flags);
  1621. t->task_state_flags &= ~SAS_TASK_STATE_PENDING;
  1622. t->task_state_flags &= ~SAS_TASK_AT_INITIATOR;
  1623. t->task_state_flags |= SAS_TASK_STATE_DONE;
  1624. if (unlikely((t->task_state_flags & SAS_TASK_STATE_ABORTED))) {
  1625. spin_unlock_irqrestore(&t->task_state_lock, flags);
  1626. PM8001_FAIL_DBG(pm8001_ha, pm8001_printk(
  1627. "task 0x%p done with io_status 0x%x resp 0x%x "
  1628. "stat 0x%x but aborted by upper layer!\n",
  1629. t, status, ts->resp, ts->stat));
  1630. pm8001_ccb_task_free(pm8001_ha, t, ccb, tag);
  1631. } else {
  1632. spin_unlock_irqrestore(&t->task_state_lock, flags);
  1633. pm8001_ccb_task_free(pm8001_ha, t, ccb, tag);
  1634. mb();/* in order to force CPU ordering */
  1635. t->task_done(t);
  1636. }
  1637. }
  1638. /*See the comments for mpi_ssp_completion */
  1639. static void mpi_ssp_event(struct pm8001_hba_info *pm8001_ha , void *piomb)
  1640. {
  1641. struct sas_task *t;
  1642. unsigned long flags;
  1643. struct task_status_struct *ts;
  1644. struct pm8001_ccb_info *ccb;
  1645. struct pm8001_device *pm8001_dev;
  1646. struct ssp_event_resp *psspPayload =
  1647. (struct ssp_event_resp *)(piomb + 4);
  1648. u32 event = le32_to_cpu(psspPayload->event);
  1649. u32 tag = le32_to_cpu(psspPayload->tag);
  1650. u32 port_id = le32_to_cpu(psspPayload->port_id);
  1651. ccb = &pm8001_ha->ccb_info[tag];
  1652. t = ccb->task;
  1653. pm8001_dev = ccb->device;
  1654. if (event)
  1655. PM8001_FAIL_DBG(pm8001_ha,
  1656. pm8001_printk("sas IO status 0x%x\n", event));
  1657. if (unlikely(!t || !t->lldd_task || !t->dev))
  1658. return;
  1659. ts = &t->task_status;
  1660. PM8001_IO_DBG(pm8001_ha,
  1661. pm8001_printk("port_id:0x%x, tag:0x%x, event:0x%x\n",
  1662. port_id, tag, event));
  1663. switch (event) {
  1664. case IO_OVERFLOW:
  1665. PM8001_IO_DBG(pm8001_ha, pm8001_printk("IO_UNDERFLOW\n");)
  1666. ts->resp = SAS_TASK_COMPLETE;
  1667. ts->stat = SAS_DATA_OVERRUN;
  1668. ts->residual = 0;
  1669. if (pm8001_dev)
  1670. pm8001_dev->running_req--;
  1671. break;
  1672. case IO_XFER_ERROR_BREAK:
  1673. PM8001_IO_DBG(pm8001_ha,
  1674. pm8001_printk("IO_XFER_ERROR_BREAK\n"));
  1675. pm8001_handle_event(pm8001_ha, t, IO_XFER_ERROR_BREAK);
  1676. return;
  1677. case IO_XFER_ERROR_PHY_NOT_READY:
  1678. PM8001_IO_DBG(pm8001_ha,
  1679. pm8001_printk("IO_XFER_ERROR_PHY_NOT_READY\n"));
  1680. ts->resp = SAS_TASK_COMPLETE;
  1681. ts->stat = SAS_OPEN_REJECT;
  1682. ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
  1683. break;
  1684. case IO_OPEN_CNX_ERROR_PROTOCOL_NOT_SUPPORTED:
  1685. PM8001_IO_DBG(pm8001_ha, pm8001_printk(
  1686. "IO_OPEN_CNX_ERROR_PROTOCOL_NOT_SUPPORTED\n"));
  1687. ts->resp = SAS_TASK_COMPLETE;
  1688. ts->stat = SAS_OPEN_REJECT;
  1689. ts->open_rej_reason = SAS_OREJ_EPROTO;
  1690. break;
  1691. case IO_OPEN_CNX_ERROR_ZONE_VIOLATION:
  1692. PM8001_IO_DBG(pm8001_ha,
  1693. pm8001_printk("IO_OPEN_CNX_ERROR_ZONE_VIOLATION\n"));
  1694. ts->resp = SAS_TASK_COMPLETE;
  1695. ts->stat = SAS_OPEN_REJECT;
  1696. ts->open_rej_reason = SAS_OREJ_UNKNOWN;
  1697. break;
  1698. case IO_OPEN_CNX_ERROR_BREAK:
  1699. PM8001_IO_DBG(pm8001_ha,
  1700. pm8001_printk("IO_OPEN_CNX_ERROR_BREAK\n"));
  1701. ts->resp = SAS_TASK_COMPLETE;
  1702. ts->stat = SAS_OPEN_REJECT;
  1703. ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
  1704. break;
  1705. case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS:
  1706. case IO_XFER_OPEN_RETRY_BACKOFF_THRESHOLD_REACHED:
  1707. case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_OPEN_TMO:
  1708. case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_NO_DEST:
  1709. case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_OPEN_COLLIDE:
  1710. case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_PATHWAY_BLOCKED:
  1711. PM8001_IO_DBG(pm8001_ha,
  1712. pm8001_printk("IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS\n"));
  1713. ts->resp = SAS_TASK_COMPLETE;
  1714. ts->stat = SAS_OPEN_REJECT;
  1715. ts->open_rej_reason = SAS_OREJ_UNKNOWN;
  1716. if (!t->uldd_task)
  1717. pm8001_handle_event(pm8001_ha,
  1718. pm8001_dev,
  1719. IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS);
  1720. break;
  1721. case IO_OPEN_CNX_ERROR_BAD_DESTINATION:
  1722. PM8001_IO_DBG(pm8001_ha,
  1723. pm8001_printk("IO_OPEN_CNX_ERROR_BAD_DESTINATION\n"));
  1724. ts->resp = SAS_TASK_COMPLETE;
  1725. ts->stat = SAS_OPEN_REJECT;
  1726. ts->open_rej_reason = SAS_OREJ_BAD_DEST;
  1727. break;
  1728. case IO_OPEN_CNX_ERROR_CONNECTION_RATE_NOT_SUPPORTED:
  1729. PM8001_IO_DBG(pm8001_ha, pm8001_printk(
  1730. "IO_OPEN_CNX_ERROR_CONNECTION_RATE_NOT_SUPPORTED\n"));
  1731. ts->resp = SAS_TASK_COMPLETE;
  1732. ts->stat = SAS_OPEN_REJECT;
  1733. ts->open_rej_reason = SAS_OREJ_CONN_RATE;
  1734. break;
  1735. case IO_OPEN_CNX_ERROR_WRONG_DESTINATION:
  1736. PM8001_IO_DBG(pm8001_ha,
  1737. pm8001_printk("IO_OPEN_CNX_ERROR_WRONG_DESTINATION\n"));
  1738. ts->resp = SAS_TASK_COMPLETE;
  1739. ts->stat = SAS_OPEN_REJECT;
  1740. ts->open_rej_reason = SAS_OREJ_WRONG_DEST;
  1741. break;
  1742. case IO_XFER_ERROR_NAK_RECEIVED:
  1743. PM8001_IO_DBG(pm8001_ha,
  1744. pm8001_printk("IO_XFER_ERROR_NAK_RECEIVED\n"));
  1745. ts->resp = SAS_TASK_COMPLETE;
  1746. ts->stat = SAS_OPEN_REJECT;
  1747. ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
  1748. break;
  1749. case IO_XFER_ERROR_ACK_NAK_TIMEOUT:
  1750. PM8001_IO_DBG(pm8001_ha,
  1751. pm8001_printk("IO_XFER_ERROR_ACK_NAK_TIMEOUT\n"));
  1752. ts->resp = SAS_TASK_COMPLETE;
  1753. ts->stat = SAS_NAK_R_ERR;
  1754. break;
  1755. case IO_XFER_OPEN_RETRY_TIMEOUT:
  1756. PM8001_IO_DBG(pm8001_ha,
  1757. pm8001_printk("IO_XFER_OPEN_RETRY_TIMEOUT\n"));
  1758. pm8001_handle_event(pm8001_ha, t, IO_XFER_OPEN_RETRY_TIMEOUT);
  1759. return;
  1760. case IO_XFER_ERROR_UNEXPECTED_PHASE:
  1761. PM8001_IO_DBG(pm8001_ha,
  1762. pm8001_printk("IO_XFER_ERROR_UNEXPECTED_PHASE\n"));
  1763. ts->resp = SAS_TASK_COMPLETE;
  1764. ts->stat = SAS_DATA_OVERRUN;
  1765. break;
  1766. case IO_XFER_ERROR_XFER_RDY_OVERRUN:
  1767. PM8001_IO_DBG(pm8001_ha,
  1768. pm8001_printk("IO_XFER_ERROR_XFER_RDY_OVERRUN\n"));
  1769. ts->resp = SAS_TASK_COMPLETE;
  1770. ts->stat = SAS_DATA_OVERRUN;
  1771. break;
  1772. case IO_XFER_ERROR_XFER_RDY_NOT_EXPECTED:
  1773. PM8001_IO_DBG(pm8001_ha,
  1774. pm8001_printk("IO_XFER_ERROR_XFER_RDY_NOT_EXPECTED\n"));
  1775. ts->resp = SAS_TASK_COMPLETE;
  1776. ts->stat = SAS_DATA_OVERRUN;
  1777. break;
  1778. case IO_XFER_ERROR_CMD_ISSUE_ACK_NAK_TIMEOUT:
  1779. PM8001_IO_DBG(pm8001_ha,
  1780. pm8001_printk("IO_XFER_ERROR_CMD_ISSUE_ACK_NAK_TIMEOUT\n"));
  1781. ts->resp = SAS_TASK_COMPLETE;
  1782. ts->stat = SAS_DATA_OVERRUN;
  1783. break;
  1784. case IO_XFER_ERROR_OFFSET_MISMATCH:
  1785. PM8001_IO_DBG(pm8001_ha,
  1786. pm8001_printk("IO_XFER_ERROR_OFFSET_MISMATCH\n"));
  1787. ts->resp = SAS_TASK_COMPLETE;
  1788. ts->stat = SAS_DATA_OVERRUN;
  1789. break;
  1790. case IO_XFER_ERROR_XFER_ZERO_DATA_LEN:
  1791. PM8001_IO_DBG(pm8001_ha,
  1792. pm8001_printk("IO_XFER_ERROR_XFER_ZERO_DATA_LEN\n"));
  1793. ts->resp = SAS_TASK_COMPLETE;
  1794. ts->stat = SAS_DATA_OVERRUN;
  1795. break;
  1796. case IO_XFER_ERROR_INTERNAL_CRC_ERROR:
  1797. PM8001_IO_DBG(pm8001_ha,
  1798. pm8001_printk("IO_XFR_ERROR_INTERNAL_CRC_ERROR\n"));
  1799. /* TBC: used default set values */
  1800. ts->resp = SAS_TASK_COMPLETE;
  1801. ts->stat = SAS_DATA_OVERRUN;
  1802. break;
  1803. case IO_XFER_CMD_FRAME_ISSUED:
  1804. PM8001_IO_DBG(pm8001_ha,
  1805. pm8001_printk("IO_XFER_CMD_FRAME_ISSUED\n"));
  1806. return;
  1807. default:
  1808. PM8001_IO_DBG(pm8001_ha,
  1809. pm8001_printk("Unknown status 0x%x\n", event));
  1810. /* not allowed case. Therefore, return failed status */
  1811. ts->resp = SAS_TASK_COMPLETE;
  1812. ts->stat = SAS_DATA_OVERRUN;
  1813. break;
  1814. }
  1815. spin_lock_irqsave(&t->task_state_lock, flags);
  1816. t->task_state_flags &= ~SAS_TASK_STATE_PENDING;
  1817. t->task_state_flags &= ~SAS_TASK_AT_INITIATOR;
  1818. t->task_state_flags |= SAS_TASK_STATE_DONE;
  1819. if (unlikely((t->task_state_flags & SAS_TASK_STATE_ABORTED))) {
  1820. spin_unlock_irqrestore(&t->task_state_lock, flags);
  1821. PM8001_FAIL_DBG(pm8001_ha, pm8001_printk(
  1822. "task 0x%p done with event 0x%x resp 0x%x "
  1823. "stat 0x%x but aborted by upper layer!\n",
  1824. t, event, ts->resp, ts->stat));
  1825. pm8001_ccb_task_free(pm8001_ha, t, ccb, tag);
  1826. } else {
  1827. spin_unlock_irqrestore(&t->task_state_lock, flags);
  1828. pm8001_ccb_task_free(pm8001_ha, t, ccb, tag);
  1829. mb();/* in order to force CPU ordering */
  1830. t->task_done(t);
  1831. }
  1832. }
  1833. /*See the comments for mpi_ssp_completion */
  1834. static void
  1835. mpi_sata_completion(struct pm8001_hba_info *pm8001_ha, void *piomb)
  1836. {
  1837. struct sas_task *t;
  1838. struct pm8001_ccb_info *ccb;
  1839. u32 param;
  1840. u32 status;
  1841. u32 tag;
  1842. int i, j;
  1843. u8 sata_addr_low[4];
  1844. u32 temp_sata_addr_low, temp_sata_addr_hi;
  1845. u8 sata_addr_hi[4];
  1846. struct sata_completion_resp *psataPayload;
  1847. struct task_status_struct *ts;
  1848. struct ata_task_resp *resp ;
  1849. u32 *sata_resp;
  1850. struct pm8001_device *pm8001_dev;
  1851. unsigned long flags;
  1852. psataPayload = (struct sata_completion_resp *)(piomb + 4);
  1853. status = le32_to_cpu(psataPayload->status);
  1854. tag = le32_to_cpu(psataPayload->tag);
  1855. if (!tag) {
  1856. PM8001_FAIL_DBG(pm8001_ha,
  1857. pm8001_printk("tag null\n"));
  1858. return;
  1859. }
  1860. ccb = &pm8001_ha->ccb_info[tag];
  1861. param = le32_to_cpu(psataPayload->param);
  1862. if (ccb) {
  1863. t = ccb->task;
  1864. pm8001_dev = ccb->device;
  1865. } else {
  1866. PM8001_FAIL_DBG(pm8001_ha,
  1867. pm8001_printk("ccb null\n"));
  1868. return;
  1869. }
  1870. if (t) {
  1871. if (t->dev && (t->dev->lldd_dev))
  1872. pm8001_dev = t->dev->lldd_dev;
  1873. } else {
  1874. PM8001_FAIL_DBG(pm8001_ha,
  1875. pm8001_printk("task null\n"));
  1876. return;
  1877. }
  1878. if ((pm8001_dev && !(pm8001_dev->id & NCQ_READ_LOG_FLAG))
  1879. && unlikely(!t || !t->lldd_task || !t->dev)) {
  1880. PM8001_FAIL_DBG(pm8001_ha,
  1881. pm8001_printk("task or dev null\n"));
  1882. return;
  1883. }
  1884. ts = &t->task_status;
  1885. if (!ts) {
  1886. PM8001_FAIL_DBG(pm8001_ha,
  1887. pm8001_printk("ts null\n"));
  1888. return;
  1889. }
  1890. /* Print sas address of IO failed device */
  1891. if ((status != IO_SUCCESS) && (status != IO_OVERFLOW) &&
  1892. (status != IO_UNDERFLOW)) {
  1893. if (!((t->dev->parent) &&
  1894. (DEV_IS_EXPANDER(t->dev->parent->dev_type)))) {
  1895. for (i = 0 , j = 4; i <= 3 && j <= 7; i++ , j++)
  1896. sata_addr_low[i] = pm8001_ha->sas_addr[j];
  1897. for (i = 0 , j = 0; i <= 3 && j <= 3; i++ , j++)
  1898. sata_addr_hi[i] = pm8001_ha->sas_addr[j];
  1899. memcpy(&temp_sata_addr_low, sata_addr_low,
  1900. sizeof(sata_addr_low));
  1901. memcpy(&temp_sata_addr_hi, sata_addr_hi,
  1902. sizeof(sata_addr_hi));
  1903. temp_sata_addr_hi = (((temp_sata_addr_hi >> 24) & 0xff)
  1904. |((temp_sata_addr_hi << 8) &
  1905. 0xff0000) |
  1906. ((temp_sata_addr_hi >> 8)
  1907. & 0xff00) |
  1908. ((temp_sata_addr_hi << 24) &
  1909. 0xff000000));
  1910. temp_sata_addr_low = ((((temp_sata_addr_low >> 24)
  1911. & 0xff) |
  1912. ((temp_sata_addr_low << 8)
  1913. & 0xff0000) |
  1914. ((temp_sata_addr_low >> 8)
  1915. & 0xff00) |
  1916. ((temp_sata_addr_low << 24)
  1917. & 0xff000000)) +
  1918. pm8001_dev->attached_phy +
  1919. 0x10);
  1920. PM8001_FAIL_DBG(pm8001_ha,
  1921. pm8001_printk("SAS Address of IO Failure Drive:"
  1922. "%08x%08x", temp_sata_addr_hi,
  1923. temp_sata_addr_low));
  1924. } else {
  1925. PM8001_FAIL_DBG(pm8001_ha,
  1926. pm8001_printk("SAS Address of IO Failure Drive:"
  1927. "%016llx", SAS_ADDR(t->dev->sas_addr)));
  1928. }
  1929. }
  1930. switch (status) {
  1931. case IO_SUCCESS:
  1932. PM8001_IO_DBG(pm8001_ha, pm8001_printk("IO_SUCCESS\n"));
  1933. if (param == 0) {
  1934. ts->resp = SAS_TASK_COMPLETE;
  1935. ts->stat = SAM_STAT_GOOD;
  1936. /* check if response is for SEND READ LOG */
  1937. if (pm8001_dev &&
  1938. (pm8001_dev->id & NCQ_READ_LOG_FLAG)) {
  1939. /* set new bit for abort_all */
  1940. pm8001_dev->id |= NCQ_ABORT_ALL_FLAG;
  1941. /* clear bit for read log */
  1942. pm8001_dev->id = pm8001_dev->id & 0x7FFFFFFF;
  1943. pm80xx_send_abort_all(pm8001_ha, pm8001_dev);
  1944. /* Free the tag */
  1945. pm8001_tag_free(pm8001_ha, tag);
  1946. sas_free_task(t);
  1947. return;
  1948. }
  1949. } else {
  1950. u8 len;
  1951. ts->resp = SAS_TASK_COMPLETE;
  1952. ts->stat = SAS_PROTO_RESPONSE;
  1953. ts->residual = param;
  1954. PM8001_IO_DBG(pm8001_ha,
  1955. pm8001_printk("SAS_PROTO_RESPONSE len = %d\n",
  1956. param));
  1957. sata_resp = &psataPayload->sata_resp[0];
  1958. resp = (struct ata_task_resp *)ts->buf;
  1959. if (t->ata_task.dma_xfer == 0 &&
  1960. t->data_dir == PCI_DMA_FROMDEVICE) {
  1961. len = sizeof(struct pio_setup_fis);
  1962. PM8001_IO_DBG(pm8001_ha,
  1963. pm8001_printk("PIO read len = %d\n", len));
  1964. } else if (t->ata_task.use_ncq) {
  1965. len = sizeof(struct set_dev_bits_fis);
  1966. PM8001_IO_DBG(pm8001_ha,
  1967. pm8001_printk("FPDMA len = %d\n", len));
  1968. } else {
  1969. len = sizeof(struct dev_to_host_fis);
  1970. PM8001_IO_DBG(pm8001_ha,
  1971. pm8001_printk("other len = %d\n", len));
  1972. }
  1973. if (SAS_STATUS_BUF_SIZE >= sizeof(*resp)) {
  1974. resp->frame_len = len;
  1975. memcpy(&resp->ending_fis[0], sata_resp, len);
  1976. ts->buf_valid_size = sizeof(*resp);
  1977. } else
  1978. PM8001_IO_DBG(pm8001_ha,
  1979. pm8001_printk("response to large\n"));
  1980. }
  1981. if (pm8001_dev)
  1982. pm8001_dev->running_req--;
  1983. break;
  1984. case IO_ABORTED:
  1985. PM8001_IO_DBG(pm8001_ha,
  1986. pm8001_printk("IO_ABORTED IOMB Tag\n"));
  1987. ts->resp = SAS_TASK_COMPLETE;
  1988. ts->stat = SAS_ABORTED_TASK;
  1989. if (pm8001_dev)
  1990. pm8001_dev->running_req--;
  1991. break;
  1992. /* following cases are to do cases */
  1993. case IO_UNDERFLOW:
  1994. /* SATA Completion with error */
  1995. PM8001_IO_DBG(pm8001_ha,
  1996. pm8001_printk("IO_UNDERFLOW param = %d\n", param));
  1997. ts->resp = SAS_TASK_COMPLETE;
  1998. ts->stat = SAS_DATA_UNDERRUN;
  1999. ts->residual = param;
  2000. if (pm8001_dev)
  2001. pm8001_dev->running_req--;
  2002. break;
  2003. case IO_NO_DEVICE:
  2004. PM8001_IO_DBG(pm8001_ha,
  2005. pm8001_printk("IO_NO_DEVICE\n"));
  2006. ts->resp = SAS_TASK_UNDELIVERED;
  2007. ts->stat = SAS_PHY_DOWN;
  2008. break;
  2009. case IO_XFER_ERROR_BREAK:
  2010. PM8001_IO_DBG(pm8001_ha,
  2011. pm8001_printk("IO_XFER_ERROR_BREAK\n"));
  2012. ts->resp = SAS_TASK_COMPLETE;
  2013. ts->stat = SAS_INTERRUPTED;
  2014. break;
  2015. case IO_XFER_ERROR_PHY_NOT_READY:
  2016. PM8001_IO_DBG(pm8001_ha,
  2017. pm8001_printk("IO_XFER_ERROR_PHY_NOT_READY\n"));
  2018. ts->resp = SAS_TASK_COMPLETE;
  2019. ts->stat = SAS_OPEN_REJECT;
  2020. ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
  2021. break;
  2022. case IO_OPEN_CNX_ERROR_PROTOCOL_NOT_SUPPORTED:
  2023. PM8001_IO_DBG(pm8001_ha, pm8001_printk(
  2024. "IO_OPEN_CNX_ERROR_PROTOCOL_NOT_SUPPORTED\n"));
  2025. ts->resp = SAS_TASK_COMPLETE;
  2026. ts->stat = SAS_OPEN_REJECT;
  2027. ts->open_rej_reason = SAS_OREJ_EPROTO;
  2028. break;
  2029. case IO_OPEN_CNX_ERROR_ZONE_VIOLATION:
  2030. PM8001_IO_DBG(pm8001_ha,
  2031. pm8001_printk("IO_OPEN_CNX_ERROR_ZONE_VIOLATION\n"));
  2032. ts->resp = SAS_TASK_COMPLETE;
  2033. ts->stat = SAS_OPEN_REJECT;
  2034. ts->open_rej_reason = SAS_OREJ_UNKNOWN;
  2035. break;
  2036. case IO_OPEN_CNX_ERROR_BREAK:
  2037. PM8001_IO_DBG(pm8001_ha,
  2038. pm8001_printk("IO_OPEN_CNX_ERROR_BREAK\n"));
  2039. ts->resp = SAS_TASK_COMPLETE;
  2040. ts->stat = SAS_OPEN_REJECT;
  2041. ts->open_rej_reason = SAS_OREJ_RSVD_CONT0;
  2042. break;
  2043. case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS:
  2044. case IO_XFER_OPEN_RETRY_BACKOFF_THRESHOLD_REACHED:
  2045. case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_OPEN_TMO:
  2046. case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_NO_DEST:
  2047. case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_OPEN_COLLIDE:
  2048. case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_PATHWAY_BLOCKED:
  2049. PM8001_IO_DBG(pm8001_ha,
  2050. pm8001_printk("IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS\n"));
  2051. ts->resp = SAS_TASK_COMPLETE;
  2052. ts->stat = SAS_DEV_NO_RESPONSE;
  2053. if (!t->uldd_task) {
  2054. pm8001_handle_event(pm8001_ha,
  2055. pm8001_dev,
  2056. IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS);
  2057. ts->resp = SAS_TASK_UNDELIVERED;
  2058. ts->stat = SAS_QUEUE_FULL;
  2059. pm8001_ccb_task_free_done(pm8001_ha, t, ccb, tag);
  2060. return;
  2061. }
  2062. break;
  2063. case IO_OPEN_CNX_ERROR_BAD_DESTINATION:
  2064. PM8001_IO_DBG(pm8001_ha,
  2065. pm8001_printk("IO_OPEN_CNX_ERROR_BAD_DESTINATION\n"));
  2066. ts->resp = SAS_TASK_UNDELIVERED;
  2067. ts->stat = SAS_OPEN_REJECT;
  2068. ts->open_rej_reason = SAS_OREJ_BAD_DEST;
  2069. if (!t->uldd_task) {
  2070. pm8001_handle_event(pm8001_ha,
  2071. pm8001_dev,
  2072. IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS);
  2073. ts->resp = SAS_TASK_UNDELIVERED;
  2074. ts->stat = SAS_QUEUE_FULL;
  2075. pm8001_ccb_task_free_done(pm8001_ha, t, ccb, tag);
  2076. return;
  2077. }
  2078. break;
  2079. case IO_OPEN_CNX_ERROR_CONNECTION_RATE_NOT_SUPPORTED:
  2080. PM8001_IO_DBG(pm8001_ha, pm8001_printk(
  2081. "IO_OPEN_CNX_ERROR_CONNECTION_RATE_NOT_SUPPORTED\n"));
  2082. ts->resp = SAS_TASK_COMPLETE;
  2083. ts->stat = SAS_OPEN_REJECT;
  2084. ts->open_rej_reason = SAS_OREJ_CONN_RATE;
  2085. break;
  2086. case IO_OPEN_CNX_ERROR_STP_RESOURCES_BUSY:
  2087. PM8001_IO_DBG(pm8001_ha, pm8001_printk(
  2088. "IO_OPEN_CNX_ERROR_STP_RESOURCES_BUSY\n"));
  2089. ts->resp = SAS_TASK_COMPLETE;
  2090. ts->stat = SAS_DEV_NO_RESPONSE;
  2091. if (!t->uldd_task) {
  2092. pm8001_handle_event(pm8001_ha,
  2093. pm8001_dev,
  2094. IO_OPEN_CNX_ERROR_STP_RESOURCES_BUSY);
  2095. ts->resp = SAS_TASK_UNDELIVERED;
  2096. ts->stat = SAS_QUEUE_FULL;
  2097. pm8001_ccb_task_free_done(pm8001_ha, t, ccb, tag);
  2098. return;
  2099. }
  2100. break;
  2101. case IO_OPEN_CNX_ERROR_WRONG_DESTINATION:
  2102. PM8001_IO_DBG(pm8001_ha,
  2103. pm8001_printk("IO_OPEN_CNX_ERROR_WRONG_DESTINATION\n"));
  2104. ts->resp = SAS_TASK_COMPLETE;
  2105. ts->stat = SAS_OPEN_REJECT;
  2106. ts->open_rej_reason = SAS_OREJ_WRONG_DEST;
  2107. break;
  2108. case IO_XFER_ERROR_NAK_RECEIVED:
  2109. PM8001_IO_DBG(pm8001_ha,
  2110. pm8001_printk("IO_XFER_ERROR_NAK_RECEIVED\n"));
  2111. ts->resp = SAS_TASK_COMPLETE;
  2112. ts->stat = SAS_NAK_R_ERR;
  2113. break;
  2114. case IO_XFER_ERROR_ACK_NAK_TIMEOUT:
  2115. PM8001_IO_DBG(pm8001_ha,
  2116. pm8001_printk("IO_XFER_ERROR_ACK_NAK_TIMEOUT\n"));
  2117. ts->resp = SAS_TASK_COMPLETE;
  2118. ts->stat = SAS_NAK_R_ERR;
  2119. break;
  2120. case IO_XFER_ERROR_DMA:
  2121. PM8001_IO_DBG(pm8001_ha,
  2122. pm8001_printk("IO_XFER_ERROR_DMA\n"));
  2123. ts->resp = SAS_TASK_COMPLETE;
  2124. ts->stat = SAS_ABORTED_TASK;
  2125. break;
  2126. case IO_XFER_ERROR_SATA_LINK_TIMEOUT:
  2127. PM8001_IO_DBG(pm8001_ha,
  2128. pm8001_printk("IO_XFER_ERROR_SATA_LINK_TIMEOUT\n"));
  2129. ts->resp = SAS_TASK_UNDELIVERED;
  2130. ts->stat = SAS_DEV_NO_RESPONSE;
  2131. break;
  2132. case IO_XFER_ERROR_REJECTED_NCQ_MODE:
  2133. PM8001_IO_DBG(pm8001_ha,
  2134. pm8001_printk("IO_XFER_ERROR_REJECTED_NCQ_MODE\n"));
  2135. ts->resp = SAS_TASK_COMPLETE;
  2136. ts->stat = SAS_DATA_UNDERRUN;
  2137. break;
  2138. case IO_XFER_OPEN_RETRY_TIMEOUT:
  2139. PM8001_IO_DBG(pm8001_ha,
  2140. pm8001_printk("IO_XFER_OPEN_RETRY_TIMEOUT\n"));
  2141. ts->resp = SAS_TASK_COMPLETE;
  2142. ts->stat = SAS_OPEN_TO;
  2143. break;
  2144. case IO_PORT_IN_RESET:
  2145. PM8001_IO_DBG(pm8001_ha,
  2146. pm8001_printk("IO_PORT_IN_RESET\n"));
  2147. ts->resp = SAS_TASK_COMPLETE;
  2148. ts->stat = SAS_DEV_NO_RESPONSE;
  2149. break;
  2150. case IO_DS_NON_OPERATIONAL:
  2151. PM8001_IO_DBG(pm8001_ha,
  2152. pm8001_printk("IO_DS_NON_OPERATIONAL\n"));
  2153. ts->resp = SAS_TASK_COMPLETE;
  2154. ts->stat = SAS_DEV_NO_RESPONSE;
  2155. if (!t->uldd_task) {
  2156. pm8001_handle_event(pm8001_ha, pm8001_dev,
  2157. IO_DS_NON_OPERATIONAL);
  2158. ts->resp = SAS_TASK_UNDELIVERED;
  2159. ts->stat = SAS_QUEUE_FULL;
  2160. pm8001_ccb_task_free_done(pm8001_ha, t, ccb, tag);
  2161. return;
  2162. }
  2163. break;
  2164. case IO_DS_IN_RECOVERY:
  2165. PM8001_IO_DBG(pm8001_ha,
  2166. pm8001_printk("IO_DS_IN_RECOVERY\n"));
  2167. ts->resp = SAS_TASK_COMPLETE;
  2168. ts->stat = SAS_DEV_NO_RESPONSE;
  2169. break;
  2170. case IO_DS_IN_ERROR:
  2171. PM8001_IO_DBG(pm8001_ha,
  2172. pm8001_printk("IO_DS_IN_ERROR\n"));
  2173. ts->resp = SAS_TASK_COMPLETE;
  2174. ts->stat = SAS_DEV_NO_RESPONSE;
  2175. if (!t->uldd_task) {
  2176. pm8001_handle_event(pm8001_ha, pm8001_dev,
  2177. IO_DS_IN_ERROR);
  2178. ts->resp = SAS_TASK_UNDELIVERED;
  2179. ts->stat = SAS_QUEUE_FULL;
  2180. pm8001_ccb_task_free_done(pm8001_ha, t, ccb, tag);
  2181. return;
  2182. }
  2183. break;
  2184. case IO_OPEN_CNX_ERROR_HW_RESOURCE_BUSY:
  2185. PM8001_IO_DBG(pm8001_ha,
  2186. pm8001_printk("IO_OPEN_CNX_ERROR_HW_RESOURCE_BUSY\n"));
  2187. ts->resp = SAS_TASK_COMPLETE;
  2188. ts->stat = SAS_OPEN_REJECT;
  2189. ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
  2190. break;
  2191. default:
  2192. PM8001_IO_DBG(pm8001_ha,
  2193. pm8001_printk("Unknown status 0x%x\n", status));
  2194. /* not allowed case. Therefore, return failed status */
  2195. ts->resp = SAS_TASK_COMPLETE;
  2196. ts->stat = SAS_DEV_NO_RESPONSE;
  2197. break;
  2198. }
  2199. spin_lock_irqsave(&t->task_state_lock, flags);
  2200. t->task_state_flags &= ~SAS_TASK_STATE_PENDING;
  2201. t->task_state_flags &= ~SAS_TASK_AT_INITIATOR;
  2202. t->task_state_flags |= SAS_TASK_STATE_DONE;
  2203. if (unlikely((t->task_state_flags & SAS_TASK_STATE_ABORTED))) {
  2204. spin_unlock_irqrestore(&t->task_state_lock, flags);
  2205. PM8001_FAIL_DBG(pm8001_ha,
  2206. pm8001_printk("task 0x%p done with io_status 0x%x"
  2207. " resp 0x%x stat 0x%x but aborted by upper layer!\n",
  2208. t, status, ts->resp, ts->stat));
  2209. pm8001_ccb_task_free(pm8001_ha, t, ccb, tag);
  2210. } else {
  2211. spin_unlock_irqrestore(&t->task_state_lock, flags);
  2212. pm8001_ccb_task_free_done(pm8001_ha, t, ccb, tag);
  2213. }
  2214. }
  2215. /*See the comments for mpi_ssp_completion */
  2216. static void mpi_sata_event(struct pm8001_hba_info *pm8001_ha , void *piomb)
  2217. {
  2218. struct sas_task *t;
  2219. struct task_status_struct *ts;
  2220. struct pm8001_ccb_info *ccb;
  2221. struct pm8001_device *pm8001_dev;
  2222. struct sata_event_resp *psataPayload =
  2223. (struct sata_event_resp *)(piomb + 4);
  2224. u32 event = le32_to_cpu(psataPayload->event);
  2225. u32 tag = le32_to_cpu(psataPayload->tag);
  2226. u32 port_id = le32_to_cpu(psataPayload->port_id);
  2227. u32 dev_id = le32_to_cpu(psataPayload->device_id);
  2228. unsigned long flags;
  2229. ccb = &pm8001_ha->ccb_info[tag];
  2230. if (ccb) {
  2231. t = ccb->task;
  2232. pm8001_dev = ccb->device;
  2233. } else {
  2234. PM8001_FAIL_DBG(pm8001_ha,
  2235. pm8001_printk("No CCB !!!. returning\n"));
  2236. return;
  2237. }
  2238. if (event)
  2239. PM8001_FAIL_DBG(pm8001_ha,
  2240. pm8001_printk("SATA EVENT 0x%x\n", event));
  2241. /* Check if this is NCQ error */
  2242. if (event == IO_XFER_ERROR_ABORTED_NCQ_MODE) {
  2243. /* find device using device id */
  2244. pm8001_dev = pm8001_find_dev(pm8001_ha, dev_id);
  2245. /* send read log extension */
  2246. if (pm8001_dev)
  2247. pm80xx_send_read_log(pm8001_ha, pm8001_dev);
  2248. return;
  2249. }
  2250. if (unlikely(!t || !t->lldd_task || !t->dev)) {
  2251. PM8001_FAIL_DBG(pm8001_ha,
  2252. pm8001_printk("task or dev null\n"));
  2253. return;
  2254. }
  2255. ts = &t->task_status;
  2256. PM8001_IO_DBG(pm8001_ha,
  2257. pm8001_printk("port_id:0x%x, tag:0x%x, event:0x%x\n",
  2258. port_id, tag, event));
  2259. switch (event) {
  2260. case IO_OVERFLOW:
  2261. PM8001_IO_DBG(pm8001_ha, pm8001_printk("IO_UNDERFLOW\n"));
  2262. ts->resp = SAS_TASK_COMPLETE;
  2263. ts->stat = SAS_DATA_OVERRUN;
  2264. ts->residual = 0;
  2265. if (pm8001_dev)
  2266. pm8001_dev->running_req--;
  2267. break;
  2268. case IO_XFER_ERROR_BREAK:
  2269. PM8001_IO_DBG(pm8001_ha,
  2270. pm8001_printk("IO_XFER_ERROR_BREAK\n"));
  2271. ts->resp = SAS_TASK_COMPLETE;
  2272. ts->stat = SAS_INTERRUPTED;
  2273. break;
  2274. case IO_XFER_ERROR_PHY_NOT_READY:
  2275. PM8001_IO_DBG(pm8001_ha,
  2276. pm8001_printk("IO_XFER_ERROR_PHY_NOT_READY\n"));
  2277. ts->resp = SAS_TASK_COMPLETE;
  2278. ts->stat = SAS_OPEN_REJECT;
  2279. ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
  2280. break;
  2281. case IO_OPEN_CNX_ERROR_PROTOCOL_NOT_SUPPORTED:
  2282. PM8001_IO_DBG(pm8001_ha, pm8001_printk(
  2283. "IO_OPEN_CNX_ERROR_PROTOCOL_NOT_SUPPORTED\n"));
  2284. ts->resp = SAS_TASK_COMPLETE;
  2285. ts->stat = SAS_OPEN_REJECT;
  2286. ts->open_rej_reason = SAS_OREJ_EPROTO;
  2287. break;
  2288. case IO_OPEN_CNX_ERROR_ZONE_VIOLATION:
  2289. PM8001_IO_DBG(pm8001_ha,
  2290. pm8001_printk("IO_OPEN_CNX_ERROR_ZONE_VIOLATION\n"));
  2291. ts->resp = SAS_TASK_COMPLETE;
  2292. ts->stat = SAS_OPEN_REJECT;
  2293. ts->open_rej_reason = SAS_OREJ_UNKNOWN;
  2294. break;
  2295. case IO_OPEN_CNX_ERROR_BREAK:
  2296. PM8001_IO_DBG(pm8001_ha,
  2297. pm8001_printk("IO_OPEN_CNX_ERROR_BREAK\n"));
  2298. ts->resp = SAS_TASK_COMPLETE;
  2299. ts->stat = SAS_OPEN_REJECT;
  2300. ts->open_rej_reason = SAS_OREJ_RSVD_CONT0;
  2301. break;
  2302. case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS:
  2303. case IO_XFER_OPEN_RETRY_BACKOFF_THRESHOLD_REACHED:
  2304. case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_OPEN_TMO:
  2305. case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_NO_DEST:
  2306. case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_OPEN_COLLIDE:
  2307. case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_PATHWAY_BLOCKED:
  2308. PM8001_FAIL_DBG(pm8001_ha,
  2309. pm8001_printk("IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS\n"));
  2310. ts->resp = SAS_TASK_UNDELIVERED;
  2311. ts->stat = SAS_DEV_NO_RESPONSE;
  2312. if (!t->uldd_task) {
  2313. pm8001_handle_event(pm8001_ha,
  2314. pm8001_dev,
  2315. IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS);
  2316. ts->resp = SAS_TASK_COMPLETE;
  2317. ts->stat = SAS_QUEUE_FULL;
  2318. pm8001_ccb_task_free_done(pm8001_ha, t, ccb, tag);
  2319. return;
  2320. }
  2321. break;
  2322. case IO_OPEN_CNX_ERROR_BAD_DESTINATION:
  2323. PM8001_IO_DBG(pm8001_ha,
  2324. pm8001_printk("IO_OPEN_CNX_ERROR_BAD_DESTINATION\n"));
  2325. ts->resp = SAS_TASK_UNDELIVERED;
  2326. ts->stat = SAS_OPEN_REJECT;
  2327. ts->open_rej_reason = SAS_OREJ_BAD_DEST;
  2328. break;
  2329. case IO_OPEN_CNX_ERROR_CONNECTION_RATE_NOT_SUPPORTED:
  2330. PM8001_IO_DBG(pm8001_ha, pm8001_printk(
  2331. "IO_OPEN_CNX_ERROR_CONNECTION_RATE_NOT_SUPPORTED\n"));
  2332. ts->resp = SAS_TASK_COMPLETE;
  2333. ts->stat = SAS_OPEN_REJECT;
  2334. ts->open_rej_reason = SAS_OREJ_CONN_RATE;
  2335. break;
  2336. case IO_OPEN_CNX_ERROR_WRONG_DESTINATION:
  2337. PM8001_IO_DBG(pm8001_ha,
  2338. pm8001_printk("IO_OPEN_CNX_ERROR_WRONG_DESTINATION\n"));
  2339. ts->resp = SAS_TASK_COMPLETE;
  2340. ts->stat = SAS_OPEN_REJECT;
  2341. ts->open_rej_reason = SAS_OREJ_WRONG_DEST;
  2342. break;
  2343. case IO_XFER_ERROR_NAK_RECEIVED:
  2344. PM8001_IO_DBG(pm8001_ha,
  2345. pm8001_printk("IO_XFER_ERROR_NAK_RECEIVED\n"));
  2346. ts->resp = SAS_TASK_COMPLETE;
  2347. ts->stat = SAS_NAK_R_ERR;
  2348. break;
  2349. case IO_XFER_ERROR_PEER_ABORTED:
  2350. PM8001_IO_DBG(pm8001_ha,
  2351. pm8001_printk("IO_XFER_ERROR_PEER_ABORTED\n"));
  2352. ts->resp = SAS_TASK_COMPLETE;
  2353. ts->stat = SAS_NAK_R_ERR;
  2354. break;
  2355. case IO_XFER_ERROR_REJECTED_NCQ_MODE:
  2356. PM8001_IO_DBG(pm8001_ha,
  2357. pm8001_printk("IO_XFER_ERROR_REJECTED_NCQ_MODE\n"));
  2358. ts->resp = SAS_TASK_COMPLETE;
  2359. ts->stat = SAS_DATA_UNDERRUN;
  2360. break;
  2361. case IO_XFER_OPEN_RETRY_TIMEOUT:
  2362. PM8001_IO_DBG(pm8001_ha,
  2363. pm8001_printk("IO_XFER_OPEN_RETRY_TIMEOUT\n"));
  2364. ts->resp = SAS_TASK_COMPLETE;
  2365. ts->stat = SAS_OPEN_TO;
  2366. break;
  2367. case IO_XFER_ERROR_UNEXPECTED_PHASE:
  2368. PM8001_IO_DBG(pm8001_ha,
  2369. pm8001_printk("IO_XFER_ERROR_UNEXPECTED_PHASE\n"));
  2370. ts->resp = SAS_TASK_COMPLETE;
  2371. ts->stat = SAS_OPEN_TO;
  2372. break;
  2373. case IO_XFER_ERROR_XFER_RDY_OVERRUN:
  2374. PM8001_IO_DBG(pm8001_ha,
  2375. pm8001_printk("IO_XFER_ERROR_XFER_RDY_OVERRUN\n"));
  2376. ts->resp = SAS_TASK_COMPLETE;
  2377. ts->stat = SAS_OPEN_TO;
  2378. break;
  2379. case IO_XFER_ERROR_XFER_RDY_NOT_EXPECTED:
  2380. PM8001_IO_DBG(pm8001_ha,
  2381. pm8001_printk("IO_XFER_ERROR_XFER_RDY_NOT_EXPECTED\n"));
  2382. ts->resp = SAS_TASK_COMPLETE;
  2383. ts->stat = SAS_OPEN_TO;
  2384. break;
  2385. case IO_XFER_ERROR_OFFSET_MISMATCH:
  2386. PM8001_IO_DBG(pm8001_ha,
  2387. pm8001_printk("IO_XFER_ERROR_OFFSET_MISMATCH\n"));
  2388. ts->resp = SAS_TASK_COMPLETE;
  2389. ts->stat = SAS_OPEN_TO;
  2390. break;
  2391. case IO_XFER_ERROR_XFER_ZERO_DATA_LEN:
  2392. PM8001_IO_DBG(pm8001_ha,
  2393. pm8001_printk("IO_XFER_ERROR_XFER_ZERO_DATA_LEN\n"));
  2394. ts->resp = SAS_TASK_COMPLETE;
  2395. ts->stat = SAS_OPEN_TO;
  2396. break;
  2397. case IO_XFER_CMD_FRAME_ISSUED:
  2398. PM8001_IO_DBG(pm8001_ha,
  2399. pm8001_printk("IO_XFER_CMD_FRAME_ISSUED\n"));
  2400. break;
  2401. case IO_XFER_PIO_SETUP_ERROR:
  2402. PM8001_IO_DBG(pm8001_ha,
  2403. pm8001_printk("IO_XFER_PIO_SETUP_ERROR\n"));
  2404. ts->resp = SAS_TASK_COMPLETE;
  2405. ts->stat = SAS_OPEN_TO;
  2406. break;
  2407. case IO_XFER_ERROR_INTERNAL_CRC_ERROR:
  2408. PM8001_FAIL_DBG(pm8001_ha,
  2409. pm8001_printk("IO_XFR_ERROR_INTERNAL_CRC_ERROR\n"));
  2410. /* TBC: used default set values */
  2411. ts->resp = SAS_TASK_COMPLETE;
  2412. ts->stat = SAS_OPEN_TO;
  2413. break;
  2414. case IO_XFER_DMA_ACTIVATE_TIMEOUT:
  2415. PM8001_FAIL_DBG(pm8001_ha,
  2416. pm8001_printk("IO_XFR_DMA_ACTIVATE_TIMEOUT\n"));
  2417. /* TBC: used default set values */
  2418. ts->resp = SAS_TASK_COMPLETE;
  2419. ts->stat = SAS_OPEN_TO;
  2420. break;
  2421. default:
  2422. PM8001_IO_DBG(pm8001_ha,
  2423. pm8001_printk("Unknown status 0x%x\n", event));
  2424. /* not allowed case. Therefore, return failed status */
  2425. ts->resp = SAS_TASK_COMPLETE;
  2426. ts->stat = SAS_OPEN_TO;
  2427. break;
  2428. }
  2429. spin_lock_irqsave(&t->task_state_lock, flags);
  2430. t->task_state_flags &= ~SAS_TASK_STATE_PENDING;
  2431. t->task_state_flags &= ~SAS_TASK_AT_INITIATOR;
  2432. t->task_state_flags |= SAS_TASK_STATE_DONE;
  2433. if (unlikely((t->task_state_flags & SAS_TASK_STATE_ABORTED))) {
  2434. spin_unlock_irqrestore(&t->task_state_lock, flags);
  2435. PM8001_FAIL_DBG(pm8001_ha,
  2436. pm8001_printk("task 0x%p done with io_status 0x%x"
  2437. " resp 0x%x stat 0x%x but aborted by upper layer!\n",
  2438. t, event, ts->resp, ts->stat));
  2439. pm8001_ccb_task_free(pm8001_ha, t, ccb, tag);
  2440. } else {
  2441. spin_unlock_irqrestore(&t->task_state_lock, flags);
  2442. pm8001_ccb_task_free_done(pm8001_ha, t, ccb, tag);
  2443. }
  2444. }
  2445. /*See the comments for mpi_ssp_completion */
  2446. static void
  2447. mpi_smp_completion(struct pm8001_hba_info *pm8001_ha, void *piomb)
  2448. {
  2449. u32 param, i;
  2450. struct sas_task *t;
  2451. struct pm8001_ccb_info *ccb;
  2452. unsigned long flags;
  2453. u32 status;
  2454. u32 tag;
  2455. struct smp_completion_resp *psmpPayload;
  2456. struct task_status_struct *ts;
  2457. struct pm8001_device *pm8001_dev;
  2458. char *pdma_respaddr = NULL;
  2459. psmpPayload = (struct smp_completion_resp *)(piomb + 4);
  2460. status = le32_to_cpu(psmpPayload->status);
  2461. tag = le32_to_cpu(psmpPayload->tag);
  2462. ccb = &pm8001_ha->ccb_info[tag];
  2463. param = le32_to_cpu(psmpPayload->param);
  2464. t = ccb->task;
  2465. ts = &t->task_status;
  2466. pm8001_dev = ccb->device;
  2467. if (status)
  2468. PM8001_FAIL_DBG(pm8001_ha,
  2469. pm8001_printk("smp IO status 0x%x\n", status));
  2470. if (unlikely(!t || !t->lldd_task || !t->dev))
  2471. return;
  2472. switch (status) {
  2473. case IO_SUCCESS:
  2474. PM8001_IO_DBG(pm8001_ha, pm8001_printk("IO_SUCCESS\n"));
  2475. ts->resp = SAS_TASK_COMPLETE;
  2476. ts->stat = SAM_STAT_GOOD;
  2477. if (pm8001_dev)
  2478. pm8001_dev->running_req--;
  2479. if (pm8001_ha->smp_exp_mode == SMP_DIRECT) {
  2480. PM8001_IO_DBG(pm8001_ha,
  2481. pm8001_printk("DIRECT RESPONSE Length:%d\n",
  2482. param));
  2483. pdma_respaddr = (char *)(phys_to_virt(cpu_to_le64
  2484. ((u64)sg_dma_address
  2485. (&t->smp_task.smp_resp))));
  2486. for (i = 0; i < param; i++) {
  2487. *(pdma_respaddr+i) = psmpPayload->_r_a[i];
  2488. PM8001_IO_DBG(pm8001_ha, pm8001_printk(
  2489. "SMP Byte%d DMA data 0x%x psmp 0x%x\n",
  2490. i, *(pdma_respaddr+i),
  2491. psmpPayload->_r_a[i]));
  2492. }
  2493. }
  2494. break;
  2495. case IO_ABORTED:
  2496. PM8001_IO_DBG(pm8001_ha,
  2497. pm8001_printk("IO_ABORTED IOMB\n"));
  2498. ts->resp = SAS_TASK_COMPLETE;
  2499. ts->stat = SAS_ABORTED_TASK;
  2500. if (pm8001_dev)
  2501. pm8001_dev->running_req--;
  2502. break;
  2503. case IO_OVERFLOW:
  2504. PM8001_IO_DBG(pm8001_ha, pm8001_printk("IO_UNDERFLOW\n"));
  2505. ts->resp = SAS_TASK_COMPLETE;
  2506. ts->stat = SAS_DATA_OVERRUN;
  2507. ts->residual = 0;
  2508. if (pm8001_dev)
  2509. pm8001_dev->running_req--;
  2510. break;
  2511. case IO_NO_DEVICE:
  2512. PM8001_IO_DBG(pm8001_ha, pm8001_printk("IO_NO_DEVICE\n"));
  2513. ts->resp = SAS_TASK_COMPLETE;
  2514. ts->stat = SAS_PHY_DOWN;
  2515. break;
  2516. case IO_ERROR_HW_TIMEOUT:
  2517. PM8001_IO_DBG(pm8001_ha,
  2518. pm8001_printk("IO_ERROR_HW_TIMEOUT\n"));
  2519. ts->resp = SAS_TASK_COMPLETE;
  2520. ts->stat = SAM_STAT_BUSY;
  2521. break;
  2522. case IO_XFER_ERROR_BREAK:
  2523. PM8001_IO_DBG(pm8001_ha,
  2524. pm8001_printk("IO_XFER_ERROR_BREAK\n"));
  2525. ts->resp = SAS_TASK_COMPLETE;
  2526. ts->stat = SAM_STAT_BUSY;
  2527. break;
  2528. case IO_XFER_ERROR_PHY_NOT_READY:
  2529. PM8001_IO_DBG(pm8001_ha,
  2530. pm8001_printk("IO_XFER_ERROR_PHY_NOT_READY\n"));
  2531. ts->resp = SAS_TASK_COMPLETE;
  2532. ts->stat = SAM_STAT_BUSY;
  2533. break;
  2534. case IO_OPEN_CNX_ERROR_PROTOCOL_NOT_SUPPORTED:
  2535. PM8001_IO_DBG(pm8001_ha,
  2536. pm8001_printk("IO_OPEN_CNX_ERROR_PROTOCOL_NOT_SUPPORTED\n"));
  2537. ts->resp = SAS_TASK_COMPLETE;
  2538. ts->stat = SAS_OPEN_REJECT;
  2539. ts->open_rej_reason = SAS_OREJ_UNKNOWN;
  2540. break;
  2541. case IO_OPEN_CNX_ERROR_ZONE_VIOLATION:
  2542. PM8001_IO_DBG(pm8001_ha,
  2543. pm8001_printk("IO_OPEN_CNX_ERROR_ZONE_VIOLATION\n"));
  2544. ts->resp = SAS_TASK_COMPLETE;
  2545. ts->stat = SAS_OPEN_REJECT;
  2546. ts->open_rej_reason = SAS_OREJ_UNKNOWN;
  2547. break;
  2548. case IO_OPEN_CNX_ERROR_BREAK:
  2549. PM8001_IO_DBG(pm8001_ha,
  2550. pm8001_printk("IO_OPEN_CNX_ERROR_BREAK\n"));
  2551. ts->resp = SAS_TASK_COMPLETE;
  2552. ts->stat = SAS_OPEN_REJECT;
  2553. ts->open_rej_reason = SAS_OREJ_RSVD_CONT0;
  2554. break;
  2555. case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS:
  2556. case IO_XFER_OPEN_RETRY_BACKOFF_THRESHOLD_REACHED:
  2557. case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_OPEN_TMO:
  2558. case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_NO_DEST:
  2559. case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_OPEN_COLLIDE:
  2560. case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_PATHWAY_BLOCKED:
  2561. PM8001_IO_DBG(pm8001_ha,
  2562. pm8001_printk("IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS\n"));
  2563. ts->resp = SAS_TASK_COMPLETE;
  2564. ts->stat = SAS_OPEN_REJECT;
  2565. ts->open_rej_reason = SAS_OREJ_UNKNOWN;
  2566. pm8001_handle_event(pm8001_ha,
  2567. pm8001_dev,
  2568. IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS);
  2569. break;
  2570. case IO_OPEN_CNX_ERROR_BAD_DESTINATION:
  2571. PM8001_IO_DBG(pm8001_ha,
  2572. pm8001_printk("IO_OPEN_CNX_ERROR_BAD_DESTINATION\n"));
  2573. ts->resp = SAS_TASK_COMPLETE;
  2574. ts->stat = SAS_OPEN_REJECT;
  2575. ts->open_rej_reason = SAS_OREJ_BAD_DEST;
  2576. break;
  2577. case IO_OPEN_CNX_ERROR_CONNECTION_RATE_NOT_SUPPORTED:
  2578. PM8001_IO_DBG(pm8001_ha, pm8001_printk(\
  2579. "IO_OPEN_CNX_ERROR_CONNECTION_RATE_NOT_SUPPORTED\n"));
  2580. ts->resp = SAS_TASK_COMPLETE;
  2581. ts->stat = SAS_OPEN_REJECT;
  2582. ts->open_rej_reason = SAS_OREJ_CONN_RATE;
  2583. break;
  2584. case IO_OPEN_CNX_ERROR_WRONG_DESTINATION:
  2585. PM8001_IO_DBG(pm8001_ha,
  2586. pm8001_printk("IO_OPEN_CNX_ERROR_WRONG_DESTINATION\n"));
  2587. ts->resp = SAS_TASK_COMPLETE;
  2588. ts->stat = SAS_OPEN_REJECT;
  2589. ts->open_rej_reason = SAS_OREJ_WRONG_DEST;
  2590. break;
  2591. case IO_XFER_ERROR_RX_FRAME:
  2592. PM8001_IO_DBG(pm8001_ha,
  2593. pm8001_printk("IO_XFER_ERROR_RX_FRAME\n"));
  2594. ts->resp = SAS_TASK_COMPLETE;
  2595. ts->stat = SAS_DEV_NO_RESPONSE;
  2596. break;
  2597. case IO_XFER_OPEN_RETRY_TIMEOUT:
  2598. PM8001_IO_DBG(pm8001_ha,
  2599. pm8001_printk("IO_XFER_OPEN_RETRY_TIMEOUT\n"));
  2600. ts->resp = SAS_TASK_COMPLETE;
  2601. ts->stat = SAS_OPEN_REJECT;
  2602. ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
  2603. break;
  2604. case IO_ERROR_INTERNAL_SMP_RESOURCE:
  2605. PM8001_IO_DBG(pm8001_ha,
  2606. pm8001_printk("IO_ERROR_INTERNAL_SMP_RESOURCE\n"));
  2607. ts->resp = SAS_TASK_COMPLETE;
  2608. ts->stat = SAS_QUEUE_FULL;
  2609. break;
  2610. case IO_PORT_IN_RESET:
  2611. PM8001_IO_DBG(pm8001_ha,
  2612. pm8001_printk("IO_PORT_IN_RESET\n"));
  2613. ts->resp = SAS_TASK_COMPLETE;
  2614. ts->stat = SAS_OPEN_REJECT;
  2615. ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
  2616. break;
  2617. case IO_DS_NON_OPERATIONAL:
  2618. PM8001_IO_DBG(pm8001_ha,
  2619. pm8001_printk("IO_DS_NON_OPERATIONAL\n"));
  2620. ts->resp = SAS_TASK_COMPLETE;
  2621. ts->stat = SAS_DEV_NO_RESPONSE;
  2622. break;
  2623. case IO_DS_IN_RECOVERY:
  2624. PM8001_IO_DBG(pm8001_ha,
  2625. pm8001_printk("IO_DS_IN_RECOVERY\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_OPEN_CNX_ERROR_HW_RESOURCE_BUSY:
  2631. PM8001_IO_DBG(pm8001_ha,
  2632. pm8001_printk("IO_OPEN_CNX_ERROR_HW_RESOURCE_BUSY\n"));
  2633. ts->resp = SAS_TASK_COMPLETE;
  2634. ts->stat = SAS_OPEN_REJECT;
  2635. ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
  2636. break;
  2637. default:
  2638. PM8001_IO_DBG(pm8001_ha,
  2639. pm8001_printk("Unknown status 0x%x\n", status));
  2640. ts->resp = SAS_TASK_COMPLETE;
  2641. ts->stat = SAS_DEV_NO_RESPONSE;
  2642. /* not allowed case. Therefore, return failed status */
  2643. break;
  2644. }
  2645. spin_lock_irqsave(&t->task_state_lock, flags);
  2646. t->task_state_flags &= ~SAS_TASK_STATE_PENDING;
  2647. t->task_state_flags &= ~SAS_TASK_AT_INITIATOR;
  2648. t->task_state_flags |= SAS_TASK_STATE_DONE;
  2649. if (unlikely((t->task_state_flags & SAS_TASK_STATE_ABORTED))) {
  2650. spin_unlock_irqrestore(&t->task_state_lock, flags);
  2651. PM8001_FAIL_DBG(pm8001_ha, pm8001_printk(
  2652. "task 0x%p done with io_status 0x%x resp 0x%x"
  2653. "stat 0x%x but aborted by upper layer!\n",
  2654. t, status, ts->resp, ts->stat));
  2655. pm8001_ccb_task_free(pm8001_ha, t, ccb, tag);
  2656. } else {
  2657. spin_unlock_irqrestore(&t->task_state_lock, flags);
  2658. pm8001_ccb_task_free(pm8001_ha, t, ccb, tag);
  2659. mb();/* in order to force CPU ordering */
  2660. t->task_done(t);
  2661. }
  2662. }
  2663. /**
  2664. * pm80xx_hw_event_ack_req- For PM8001,some events need to acknowage to FW.
  2665. * @pm8001_ha: our hba card information
  2666. * @Qnum: the outbound queue message number.
  2667. * @SEA: source of event to ack
  2668. * @port_id: port id.
  2669. * @phyId: phy id.
  2670. * @param0: parameter 0.
  2671. * @param1: parameter 1.
  2672. */
  2673. static void pm80xx_hw_event_ack_req(struct pm8001_hba_info *pm8001_ha,
  2674. u32 Qnum, u32 SEA, u32 port_id, u32 phyId, u32 param0, u32 param1)
  2675. {
  2676. struct hw_event_ack_req payload;
  2677. u32 opc = OPC_INB_SAS_HW_EVENT_ACK;
  2678. struct inbound_queue_table *circularQ;
  2679. memset((u8 *)&payload, 0, sizeof(payload));
  2680. circularQ = &pm8001_ha->inbnd_q_tbl[Qnum];
  2681. payload.tag = cpu_to_le32(1);
  2682. payload.phyid_sea_portid = cpu_to_le32(((SEA & 0xFFFF) << 8) |
  2683. ((phyId & 0xFF) << 24) | (port_id & 0xFF));
  2684. payload.param0 = cpu_to_le32(param0);
  2685. payload.param1 = cpu_to_le32(param1);
  2686. pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc, &payload, 0);
  2687. }
  2688. static int pm80xx_chip_phy_ctl_req(struct pm8001_hba_info *pm8001_ha,
  2689. u32 phyId, u32 phy_op);
  2690. static void hw_event_port_recover(struct pm8001_hba_info *pm8001_ha,
  2691. void *piomb)
  2692. {
  2693. struct hw_event_resp *pPayload = (struct hw_event_resp *)(piomb + 4);
  2694. u32 phyid_npip_portstate = le32_to_cpu(pPayload->phyid_npip_portstate);
  2695. u8 phy_id = (u8)((phyid_npip_portstate & 0xFF0000) >> 16);
  2696. u32 lr_status_evt_portid =
  2697. le32_to_cpu(pPayload->lr_status_evt_portid);
  2698. u8 deviceType = pPayload->sas_identify.dev_type;
  2699. u8 link_rate = (u8)((lr_status_evt_portid & 0xF0000000) >> 28);
  2700. struct pm8001_phy *phy = &pm8001_ha->phy[phy_id];
  2701. u8 port_id = (u8)(lr_status_evt_portid & 0x000000FF);
  2702. struct pm8001_port *port = &pm8001_ha->port[port_id];
  2703. if (deviceType == SAS_END_DEVICE) {
  2704. pm80xx_chip_phy_ctl_req(pm8001_ha, phy_id,
  2705. PHY_NOTIFY_ENABLE_SPINUP);
  2706. }
  2707. port->wide_port_phymap |= (1U << phy_id);
  2708. pm8001_get_lrate_mode(phy, link_rate);
  2709. phy->sas_phy.oob_mode = SAS_OOB_MODE;
  2710. phy->phy_state = PHY_STATE_LINK_UP_SPCV;
  2711. phy->phy_attached = 1;
  2712. }
  2713. /**
  2714. * hw_event_sas_phy_up -FW tells me a SAS phy up event.
  2715. * @pm8001_ha: our hba card information
  2716. * @piomb: IO message buffer
  2717. */
  2718. static void
  2719. hw_event_sas_phy_up(struct pm8001_hba_info *pm8001_ha, void *piomb)
  2720. {
  2721. struct hw_event_resp *pPayload =
  2722. (struct hw_event_resp *)(piomb + 4);
  2723. u32 lr_status_evt_portid =
  2724. le32_to_cpu(pPayload->lr_status_evt_portid);
  2725. u32 phyid_npip_portstate = le32_to_cpu(pPayload->phyid_npip_portstate);
  2726. u8 link_rate =
  2727. (u8)((lr_status_evt_portid & 0xF0000000) >> 28);
  2728. u8 port_id = (u8)(lr_status_evt_portid & 0x000000FF);
  2729. u8 phy_id =
  2730. (u8)((phyid_npip_portstate & 0xFF0000) >> 16);
  2731. u8 portstate = (u8)(phyid_npip_portstate & 0x0000000F);
  2732. struct pm8001_port *port = &pm8001_ha->port[port_id];
  2733. struct sas_ha_struct *sas_ha = pm8001_ha->sas;
  2734. struct pm8001_phy *phy = &pm8001_ha->phy[phy_id];
  2735. unsigned long flags;
  2736. u8 deviceType = pPayload->sas_identify.dev_type;
  2737. port->port_state = portstate;
  2738. port->wide_port_phymap |= (1U << phy_id);
  2739. phy->phy_state = PHY_STATE_LINK_UP_SPCV;
  2740. PM8001_MSG_DBG(pm8001_ha, pm8001_printk(
  2741. "portid:%d; phyid:%d; linkrate:%d; "
  2742. "portstate:%x; devicetype:%x\n",
  2743. port_id, phy_id, link_rate, portstate, deviceType));
  2744. switch (deviceType) {
  2745. case SAS_PHY_UNUSED:
  2746. PM8001_MSG_DBG(pm8001_ha,
  2747. pm8001_printk("device type no device.\n"));
  2748. break;
  2749. case SAS_END_DEVICE:
  2750. PM8001_MSG_DBG(pm8001_ha, pm8001_printk("end device.\n"));
  2751. pm80xx_chip_phy_ctl_req(pm8001_ha, phy_id,
  2752. PHY_NOTIFY_ENABLE_SPINUP);
  2753. port->port_attached = 1;
  2754. pm8001_get_lrate_mode(phy, link_rate);
  2755. break;
  2756. case SAS_EDGE_EXPANDER_DEVICE:
  2757. PM8001_MSG_DBG(pm8001_ha,
  2758. pm8001_printk("expander device.\n"));
  2759. port->port_attached = 1;
  2760. pm8001_get_lrate_mode(phy, link_rate);
  2761. break;
  2762. case SAS_FANOUT_EXPANDER_DEVICE:
  2763. PM8001_MSG_DBG(pm8001_ha,
  2764. pm8001_printk("fanout expander device.\n"));
  2765. port->port_attached = 1;
  2766. pm8001_get_lrate_mode(phy, link_rate);
  2767. break;
  2768. default:
  2769. PM8001_MSG_DBG(pm8001_ha,
  2770. pm8001_printk("unknown device type(%x)\n", deviceType));
  2771. break;
  2772. }
  2773. phy->phy_type |= PORT_TYPE_SAS;
  2774. phy->identify.device_type = deviceType;
  2775. phy->phy_attached = 1;
  2776. if (phy->identify.device_type == SAS_END_DEVICE)
  2777. phy->identify.target_port_protocols = SAS_PROTOCOL_SSP;
  2778. else if (phy->identify.device_type != SAS_PHY_UNUSED)
  2779. phy->identify.target_port_protocols = SAS_PROTOCOL_SMP;
  2780. phy->sas_phy.oob_mode = SAS_OOB_MODE;
  2781. sas_ha->notify_phy_event(&phy->sas_phy, PHYE_OOB_DONE);
  2782. spin_lock_irqsave(&phy->sas_phy.frame_rcvd_lock, flags);
  2783. memcpy(phy->frame_rcvd, &pPayload->sas_identify,
  2784. sizeof(struct sas_identify_frame)-4);
  2785. phy->frame_rcvd_size = sizeof(struct sas_identify_frame) - 4;
  2786. pm8001_get_attached_sas_addr(phy, phy->sas_phy.attached_sas_addr);
  2787. spin_unlock_irqrestore(&phy->sas_phy.frame_rcvd_lock, flags);
  2788. if (pm8001_ha->flags == PM8001F_RUN_TIME)
  2789. mdelay(200);/*delay a moment to wait disk to spinup*/
  2790. pm8001_bytes_dmaed(pm8001_ha, phy_id);
  2791. }
  2792. /**
  2793. * hw_event_sata_phy_up -FW tells me a SATA phy up event.
  2794. * @pm8001_ha: our hba card information
  2795. * @piomb: IO message buffer
  2796. */
  2797. static void
  2798. hw_event_sata_phy_up(struct pm8001_hba_info *pm8001_ha, void *piomb)
  2799. {
  2800. struct hw_event_resp *pPayload =
  2801. (struct hw_event_resp *)(piomb + 4);
  2802. u32 phyid_npip_portstate = le32_to_cpu(pPayload->phyid_npip_portstate);
  2803. u32 lr_status_evt_portid =
  2804. le32_to_cpu(pPayload->lr_status_evt_portid);
  2805. u8 link_rate =
  2806. (u8)((lr_status_evt_portid & 0xF0000000) >> 28);
  2807. u8 port_id = (u8)(lr_status_evt_portid & 0x000000FF);
  2808. u8 phy_id =
  2809. (u8)((phyid_npip_portstate & 0xFF0000) >> 16);
  2810. u8 portstate = (u8)(phyid_npip_portstate & 0x0000000F);
  2811. struct pm8001_port *port = &pm8001_ha->port[port_id];
  2812. struct sas_ha_struct *sas_ha = pm8001_ha->sas;
  2813. struct pm8001_phy *phy = &pm8001_ha->phy[phy_id];
  2814. unsigned long flags;
  2815. PM8001_MSG_DBG(pm8001_ha, pm8001_printk(
  2816. "port id %d, phy id %d link_rate %d portstate 0x%x\n",
  2817. port_id, phy_id, link_rate, portstate));
  2818. port->port_state = portstate;
  2819. phy->phy_state = PHY_STATE_LINK_UP_SPCV;
  2820. port->port_attached = 1;
  2821. pm8001_get_lrate_mode(phy, link_rate);
  2822. phy->phy_type |= PORT_TYPE_SATA;
  2823. phy->phy_attached = 1;
  2824. phy->sas_phy.oob_mode = SATA_OOB_MODE;
  2825. sas_ha->notify_phy_event(&phy->sas_phy, PHYE_OOB_DONE);
  2826. spin_lock_irqsave(&phy->sas_phy.frame_rcvd_lock, flags);
  2827. memcpy(phy->frame_rcvd, ((u8 *)&pPayload->sata_fis - 4),
  2828. sizeof(struct dev_to_host_fis));
  2829. phy->frame_rcvd_size = sizeof(struct dev_to_host_fis);
  2830. phy->identify.target_port_protocols = SAS_PROTOCOL_SATA;
  2831. phy->identify.device_type = SAS_SATA_DEV;
  2832. pm8001_get_attached_sas_addr(phy, phy->sas_phy.attached_sas_addr);
  2833. spin_unlock_irqrestore(&phy->sas_phy.frame_rcvd_lock, flags);
  2834. pm8001_bytes_dmaed(pm8001_ha, phy_id);
  2835. }
  2836. /**
  2837. * hw_event_phy_down -we should notify the libsas the phy is down.
  2838. * @pm8001_ha: our hba card information
  2839. * @piomb: IO message buffer
  2840. */
  2841. static void
  2842. hw_event_phy_down(struct pm8001_hba_info *pm8001_ha, void *piomb)
  2843. {
  2844. struct hw_event_resp *pPayload =
  2845. (struct hw_event_resp *)(piomb + 4);
  2846. u32 lr_status_evt_portid =
  2847. le32_to_cpu(pPayload->lr_status_evt_portid);
  2848. u8 port_id = (u8)(lr_status_evt_portid & 0x000000FF);
  2849. u32 phyid_npip_portstate = le32_to_cpu(pPayload->phyid_npip_portstate);
  2850. u8 phy_id =
  2851. (u8)((phyid_npip_portstate & 0xFF0000) >> 16);
  2852. u8 portstate = (u8)(phyid_npip_portstate & 0x0000000F);
  2853. struct pm8001_port *port = &pm8001_ha->port[port_id];
  2854. struct pm8001_phy *phy = &pm8001_ha->phy[phy_id];
  2855. port->port_state = portstate;
  2856. phy->identify.device_type = 0;
  2857. phy->phy_attached = 0;
  2858. memset(&phy->dev_sas_addr, 0, SAS_ADDR_SIZE);
  2859. switch (portstate) {
  2860. case PORT_VALID:
  2861. break;
  2862. case PORT_INVALID:
  2863. PM8001_MSG_DBG(pm8001_ha,
  2864. pm8001_printk(" PortInvalid portID %d\n", port_id));
  2865. PM8001_MSG_DBG(pm8001_ha,
  2866. pm8001_printk(" Last phy Down and port invalid\n"));
  2867. if (phy->phy_type & PORT_TYPE_SATA) {
  2868. phy->phy_type = 0;
  2869. port->port_attached = 0;
  2870. pm80xx_hw_event_ack_req(pm8001_ha, 0, HW_EVENT_PHY_DOWN,
  2871. port_id, phy_id, 0, 0);
  2872. }
  2873. sas_phy_disconnected(&phy->sas_phy);
  2874. break;
  2875. case PORT_IN_RESET:
  2876. PM8001_MSG_DBG(pm8001_ha,
  2877. pm8001_printk(" Port In Reset portID %d\n", port_id));
  2878. break;
  2879. case PORT_NOT_ESTABLISHED:
  2880. PM8001_MSG_DBG(pm8001_ha,
  2881. pm8001_printk(" Phy Down and PORT_NOT_ESTABLISHED\n"));
  2882. port->port_attached = 0;
  2883. break;
  2884. case PORT_LOSTCOMM:
  2885. PM8001_MSG_DBG(pm8001_ha,
  2886. pm8001_printk(" Phy Down and PORT_LOSTCOMM\n"));
  2887. PM8001_MSG_DBG(pm8001_ha,
  2888. pm8001_printk(" Last phy Down and port invalid\n"));
  2889. if (phy->phy_type & PORT_TYPE_SATA) {
  2890. port->port_attached = 0;
  2891. phy->phy_type = 0;
  2892. pm80xx_hw_event_ack_req(pm8001_ha, 0, HW_EVENT_PHY_DOWN,
  2893. port_id, phy_id, 0, 0);
  2894. }
  2895. sas_phy_disconnected(&phy->sas_phy);
  2896. break;
  2897. default:
  2898. port->port_attached = 0;
  2899. PM8001_MSG_DBG(pm8001_ha,
  2900. pm8001_printk(" Phy Down and(default) = 0x%x\n",
  2901. portstate));
  2902. break;
  2903. }
  2904. }
  2905. static int mpi_phy_start_resp(struct pm8001_hba_info *pm8001_ha, void *piomb)
  2906. {
  2907. struct phy_start_resp *pPayload =
  2908. (struct phy_start_resp *)(piomb + 4);
  2909. u32 status =
  2910. le32_to_cpu(pPayload->status);
  2911. u32 phy_id =
  2912. le32_to_cpu(pPayload->phyid);
  2913. struct pm8001_phy *phy = &pm8001_ha->phy[phy_id];
  2914. PM8001_INIT_DBG(pm8001_ha,
  2915. pm8001_printk("phy start resp status:0x%x, phyid:0x%x\n",
  2916. status, phy_id));
  2917. if (status == 0) {
  2918. phy->phy_state = 1;
  2919. if (pm8001_ha->flags == PM8001F_RUN_TIME)
  2920. complete(phy->enable_completion);
  2921. }
  2922. return 0;
  2923. }
  2924. /**
  2925. * mpi_thermal_hw_event -The hw event has come.
  2926. * @pm8001_ha: our hba card information
  2927. * @piomb: IO message buffer
  2928. */
  2929. static int mpi_thermal_hw_event(struct pm8001_hba_info *pm8001_ha, void *piomb)
  2930. {
  2931. struct thermal_hw_event *pPayload =
  2932. (struct thermal_hw_event *)(piomb + 4);
  2933. u32 thermal_event = le32_to_cpu(pPayload->thermal_event);
  2934. u32 rht_lht = le32_to_cpu(pPayload->rht_lht);
  2935. if (thermal_event & 0x40) {
  2936. PM8001_IO_DBG(pm8001_ha, pm8001_printk(
  2937. "Thermal Event: Local high temperature violated!\n"));
  2938. PM8001_IO_DBG(pm8001_ha, pm8001_printk(
  2939. "Thermal Event: Measured local high temperature %d\n",
  2940. ((rht_lht & 0xFF00) >> 8)));
  2941. }
  2942. if (thermal_event & 0x10) {
  2943. PM8001_IO_DBG(pm8001_ha, pm8001_printk(
  2944. "Thermal Event: Remote high temperature violated!\n"));
  2945. PM8001_IO_DBG(pm8001_ha, pm8001_printk(
  2946. "Thermal Event: Measured remote high temperature %d\n",
  2947. ((rht_lht & 0xFF000000) >> 24)));
  2948. }
  2949. return 0;
  2950. }
  2951. /**
  2952. * mpi_hw_event -The hw event has come.
  2953. * @pm8001_ha: our hba card information
  2954. * @piomb: IO message buffer
  2955. */
  2956. static int mpi_hw_event(struct pm8001_hba_info *pm8001_ha, void *piomb)
  2957. {
  2958. unsigned long flags, i;
  2959. struct hw_event_resp *pPayload =
  2960. (struct hw_event_resp *)(piomb + 4);
  2961. u32 lr_status_evt_portid =
  2962. le32_to_cpu(pPayload->lr_status_evt_portid);
  2963. u32 phyid_npip_portstate = le32_to_cpu(pPayload->phyid_npip_portstate);
  2964. u8 port_id = (u8)(lr_status_evt_portid & 0x000000FF);
  2965. u8 phy_id =
  2966. (u8)((phyid_npip_portstate & 0xFF0000) >> 16);
  2967. u16 eventType =
  2968. (u16)((lr_status_evt_portid & 0x00FFFF00) >> 8);
  2969. u8 status =
  2970. (u8)((lr_status_evt_portid & 0x0F000000) >> 24);
  2971. struct sas_ha_struct *sas_ha = pm8001_ha->sas;
  2972. struct pm8001_phy *phy = &pm8001_ha->phy[phy_id];
  2973. struct pm8001_port *port = &pm8001_ha->port[port_id];
  2974. struct asd_sas_phy *sas_phy = sas_ha->sas_phy[phy_id];
  2975. PM8001_MSG_DBG(pm8001_ha,
  2976. pm8001_printk("portid:%d phyid:%d event:0x%x status:0x%x\n",
  2977. port_id, phy_id, eventType, status));
  2978. switch (eventType) {
  2979. case HW_EVENT_SAS_PHY_UP:
  2980. PM8001_MSG_DBG(pm8001_ha,
  2981. pm8001_printk("HW_EVENT_PHY_START_STATUS\n"));
  2982. hw_event_sas_phy_up(pm8001_ha, piomb);
  2983. break;
  2984. case HW_EVENT_SATA_PHY_UP:
  2985. PM8001_MSG_DBG(pm8001_ha,
  2986. pm8001_printk("HW_EVENT_SATA_PHY_UP\n"));
  2987. hw_event_sata_phy_up(pm8001_ha, piomb);
  2988. break;
  2989. case HW_EVENT_SATA_SPINUP_HOLD:
  2990. PM8001_MSG_DBG(pm8001_ha,
  2991. pm8001_printk("HW_EVENT_SATA_SPINUP_HOLD\n"));
  2992. sas_ha->notify_phy_event(&phy->sas_phy, PHYE_SPINUP_HOLD);
  2993. break;
  2994. case HW_EVENT_PHY_DOWN:
  2995. PM8001_MSG_DBG(pm8001_ha,
  2996. pm8001_printk("HW_EVENT_PHY_DOWN\n"));
  2997. if (phy->phy_type & PORT_TYPE_SATA)
  2998. sas_ha->notify_phy_event(&phy->sas_phy,
  2999. PHYE_LOSS_OF_SIGNAL);
  3000. phy->phy_attached = 0;
  3001. phy->phy_state = 0;
  3002. hw_event_phy_down(pm8001_ha, piomb);
  3003. break;
  3004. case HW_EVENT_PORT_INVALID:
  3005. PM8001_MSG_DBG(pm8001_ha,
  3006. pm8001_printk("HW_EVENT_PORT_INVALID\n"));
  3007. sas_phy_disconnected(sas_phy);
  3008. phy->phy_attached = 0;
  3009. sas_ha->notify_port_event(sas_phy, PORTE_LINK_RESET_ERR);
  3010. break;
  3011. /* the broadcast change primitive received, tell the LIBSAS this event
  3012. to revalidate the sas domain*/
  3013. case HW_EVENT_BROADCAST_CHANGE:
  3014. PM8001_MSG_DBG(pm8001_ha,
  3015. pm8001_printk("HW_EVENT_BROADCAST_CHANGE\n"));
  3016. pm80xx_hw_event_ack_req(pm8001_ha, 0, HW_EVENT_BROADCAST_CHANGE,
  3017. port_id, phy_id, 1, 0);
  3018. spin_lock_irqsave(&sas_phy->sas_prim_lock, flags);
  3019. sas_phy->sas_prim = HW_EVENT_BROADCAST_CHANGE;
  3020. spin_unlock_irqrestore(&sas_phy->sas_prim_lock, flags);
  3021. sas_ha->notify_port_event(sas_phy, PORTE_BROADCAST_RCVD);
  3022. break;
  3023. case HW_EVENT_PHY_ERROR:
  3024. PM8001_MSG_DBG(pm8001_ha,
  3025. pm8001_printk("HW_EVENT_PHY_ERROR\n"));
  3026. sas_phy_disconnected(&phy->sas_phy);
  3027. phy->phy_attached = 0;
  3028. sas_ha->notify_phy_event(&phy->sas_phy, PHYE_OOB_ERROR);
  3029. break;
  3030. case HW_EVENT_BROADCAST_EXP:
  3031. PM8001_MSG_DBG(pm8001_ha,
  3032. pm8001_printk("HW_EVENT_BROADCAST_EXP\n"));
  3033. spin_lock_irqsave(&sas_phy->sas_prim_lock, flags);
  3034. sas_phy->sas_prim = HW_EVENT_BROADCAST_EXP;
  3035. spin_unlock_irqrestore(&sas_phy->sas_prim_lock, flags);
  3036. sas_ha->notify_port_event(sas_phy, PORTE_BROADCAST_RCVD);
  3037. break;
  3038. case HW_EVENT_LINK_ERR_INVALID_DWORD:
  3039. PM8001_MSG_DBG(pm8001_ha,
  3040. pm8001_printk("HW_EVENT_LINK_ERR_INVALID_DWORD\n"));
  3041. pm80xx_hw_event_ack_req(pm8001_ha, 0,
  3042. HW_EVENT_LINK_ERR_INVALID_DWORD, port_id, phy_id, 0, 0);
  3043. break;
  3044. case HW_EVENT_LINK_ERR_DISPARITY_ERROR:
  3045. PM8001_MSG_DBG(pm8001_ha,
  3046. pm8001_printk("HW_EVENT_LINK_ERR_DISPARITY_ERROR\n"));
  3047. pm80xx_hw_event_ack_req(pm8001_ha, 0,
  3048. HW_EVENT_LINK_ERR_DISPARITY_ERROR,
  3049. port_id, phy_id, 0, 0);
  3050. break;
  3051. case HW_EVENT_LINK_ERR_CODE_VIOLATION:
  3052. PM8001_MSG_DBG(pm8001_ha,
  3053. pm8001_printk("HW_EVENT_LINK_ERR_CODE_VIOLATION\n"));
  3054. pm80xx_hw_event_ack_req(pm8001_ha, 0,
  3055. HW_EVENT_LINK_ERR_CODE_VIOLATION,
  3056. port_id, phy_id, 0, 0);
  3057. break;
  3058. case HW_EVENT_LINK_ERR_LOSS_OF_DWORD_SYNCH:
  3059. PM8001_MSG_DBG(pm8001_ha, pm8001_printk(
  3060. "HW_EVENT_LINK_ERR_LOSS_OF_DWORD_SYNCH\n"));
  3061. pm80xx_hw_event_ack_req(pm8001_ha, 0,
  3062. HW_EVENT_LINK_ERR_LOSS_OF_DWORD_SYNCH,
  3063. port_id, phy_id, 0, 0);
  3064. break;
  3065. case HW_EVENT_MALFUNCTION:
  3066. PM8001_MSG_DBG(pm8001_ha,
  3067. pm8001_printk("HW_EVENT_MALFUNCTION\n"));
  3068. break;
  3069. case HW_EVENT_BROADCAST_SES:
  3070. PM8001_MSG_DBG(pm8001_ha,
  3071. pm8001_printk("HW_EVENT_BROADCAST_SES\n"));
  3072. spin_lock_irqsave(&sas_phy->sas_prim_lock, flags);
  3073. sas_phy->sas_prim = HW_EVENT_BROADCAST_SES;
  3074. spin_unlock_irqrestore(&sas_phy->sas_prim_lock, flags);
  3075. sas_ha->notify_port_event(sas_phy, PORTE_BROADCAST_RCVD);
  3076. break;
  3077. case HW_EVENT_INBOUND_CRC_ERROR:
  3078. PM8001_MSG_DBG(pm8001_ha,
  3079. pm8001_printk("HW_EVENT_INBOUND_CRC_ERROR\n"));
  3080. pm80xx_hw_event_ack_req(pm8001_ha, 0,
  3081. HW_EVENT_INBOUND_CRC_ERROR,
  3082. port_id, phy_id, 0, 0);
  3083. break;
  3084. case HW_EVENT_HARD_RESET_RECEIVED:
  3085. PM8001_MSG_DBG(pm8001_ha,
  3086. pm8001_printk("HW_EVENT_HARD_RESET_RECEIVED\n"));
  3087. sas_ha->notify_port_event(sas_phy, PORTE_HARD_RESET);
  3088. break;
  3089. case HW_EVENT_ID_FRAME_TIMEOUT:
  3090. PM8001_MSG_DBG(pm8001_ha,
  3091. pm8001_printk("HW_EVENT_ID_FRAME_TIMEOUT\n"));
  3092. sas_phy_disconnected(sas_phy);
  3093. phy->phy_attached = 0;
  3094. sas_ha->notify_port_event(sas_phy, PORTE_LINK_RESET_ERR);
  3095. break;
  3096. case HW_EVENT_LINK_ERR_PHY_RESET_FAILED:
  3097. PM8001_MSG_DBG(pm8001_ha,
  3098. pm8001_printk("HW_EVENT_LINK_ERR_PHY_RESET_FAILED\n"));
  3099. pm80xx_hw_event_ack_req(pm8001_ha, 0,
  3100. HW_EVENT_LINK_ERR_PHY_RESET_FAILED,
  3101. port_id, phy_id, 0, 0);
  3102. sas_phy_disconnected(sas_phy);
  3103. phy->phy_attached = 0;
  3104. sas_ha->notify_port_event(sas_phy, PORTE_LINK_RESET_ERR);
  3105. break;
  3106. case HW_EVENT_PORT_RESET_TIMER_TMO:
  3107. PM8001_MSG_DBG(pm8001_ha,
  3108. pm8001_printk("HW_EVENT_PORT_RESET_TIMER_TMO\n"));
  3109. sas_phy_disconnected(sas_phy);
  3110. phy->phy_attached = 0;
  3111. sas_ha->notify_port_event(sas_phy, PORTE_LINK_RESET_ERR);
  3112. break;
  3113. case HW_EVENT_PORT_RECOVERY_TIMER_TMO:
  3114. PM8001_MSG_DBG(pm8001_ha,
  3115. pm8001_printk("HW_EVENT_PORT_RECOVERY_TIMER_TMO\n"));
  3116. pm80xx_hw_event_ack_req(pm8001_ha, 0,
  3117. HW_EVENT_PORT_RECOVERY_TIMER_TMO,
  3118. port_id, phy_id, 0, 0);
  3119. for (i = 0; i < pm8001_ha->chip->n_phy; i++) {
  3120. if (port->wide_port_phymap & (1 << i)) {
  3121. phy = &pm8001_ha->phy[i];
  3122. sas_ha->notify_phy_event(&phy->sas_phy,
  3123. PHYE_LOSS_OF_SIGNAL);
  3124. port->wide_port_phymap &= ~(1 << i);
  3125. }
  3126. }
  3127. break;
  3128. case HW_EVENT_PORT_RECOVER:
  3129. PM8001_MSG_DBG(pm8001_ha,
  3130. pm8001_printk("HW_EVENT_PORT_RECOVER\n"));
  3131. hw_event_port_recover(pm8001_ha, piomb);
  3132. break;
  3133. case HW_EVENT_PORT_RESET_COMPLETE:
  3134. PM8001_MSG_DBG(pm8001_ha,
  3135. pm8001_printk("HW_EVENT_PORT_RESET_COMPLETE\n"));
  3136. break;
  3137. case EVENT_BROADCAST_ASYNCH_EVENT:
  3138. PM8001_MSG_DBG(pm8001_ha,
  3139. pm8001_printk("EVENT_BROADCAST_ASYNCH_EVENT\n"));
  3140. break;
  3141. default:
  3142. PM8001_MSG_DBG(pm8001_ha,
  3143. pm8001_printk("Unknown event type 0x%x\n", eventType));
  3144. break;
  3145. }
  3146. return 0;
  3147. }
  3148. /**
  3149. * mpi_phy_stop_resp - SPCv specific
  3150. * @pm8001_ha: our hba card information
  3151. * @piomb: IO message buffer
  3152. */
  3153. static int mpi_phy_stop_resp(struct pm8001_hba_info *pm8001_ha, void *piomb)
  3154. {
  3155. struct phy_stop_resp *pPayload =
  3156. (struct phy_stop_resp *)(piomb + 4);
  3157. u32 status =
  3158. le32_to_cpu(pPayload->status);
  3159. u32 phyid =
  3160. le32_to_cpu(pPayload->phyid);
  3161. struct pm8001_phy *phy = &pm8001_ha->phy[phyid];
  3162. PM8001_MSG_DBG(pm8001_ha,
  3163. pm8001_printk("phy:0x%x status:0x%x\n",
  3164. phyid, status));
  3165. if (status == 0)
  3166. phy->phy_state = 0;
  3167. return 0;
  3168. }
  3169. /**
  3170. * mpi_set_controller_config_resp - SPCv specific
  3171. * @pm8001_ha: our hba card information
  3172. * @piomb: IO message buffer
  3173. */
  3174. static int mpi_set_controller_config_resp(struct pm8001_hba_info *pm8001_ha,
  3175. void *piomb)
  3176. {
  3177. struct set_ctrl_cfg_resp *pPayload =
  3178. (struct set_ctrl_cfg_resp *)(piomb + 4);
  3179. u32 status = le32_to_cpu(pPayload->status);
  3180. u32 err_qlfr_pgcd = le32_to_cpu(pPayload->err_qlfr_pgcd);
  3181. PM8001_MSG_DBG(pm8001_ha, pm8001_printk(
  3182. "SET CONTROLLER RESP: status 0x%x qlfr_pgcd 0x%x\n",
  3183. status, err_qlfr_pgcd));
  3184. return 0;
  3185. }
  3186. /**
  3187. * mpi_get_controller_config_resp - SPCv specific
  3188. * @pm8001_ha: our hba card information
  3189. * @piomb: IO message buffer
  3190. */
  3191. static int mpi_get_controller_config_resp(struct pm8001_hba_info *pm8001_ha,
  3192. void *piomb)
  3193. {
  3194. PM8001_MSG_DBG(pm8001_ha,
  3195. pm8001_printk(" pm80xx_addition_functionality\n"));
  3196. return 0;
  3197. }
  3198. /**
  3199. * mpi_get_phy_profile_resp - SPCv specific
  3200. * @pm8001_ha: our hba card information
  3201. * @piomb: IO message buffer
  3202. */
  3203. static int mpi_get_phy_profile_resp(struct pm8001_hba_info *pm8001_ha,
  3204. void *piomb)
  3205. {
  3206. PM8001_MSG_DBG(pm8001_ha,
  3207. pm8001_printk(" pm80xx_addition_functionality\n"));
  3208. return 0;
  3209. }
  3210. /**
  3211. * mpi_flash_op_ext_resp - SPCv specific
  3212. * @pm8001_ha: our hba card information
  3213. * @piomb: IO message buffer
  3214. */
  3215. static int mpi_flash_op_ext_resp(struct pm8001_hba_info *pm8001_ha, void *piomb)
  3216. {
  3217. PM8001_MSG_DBG(pm8001_ha,
  3218. pm8001_printk(" pm80xx_addition_functionality\n"));
  3219. return 0;
  3220. }
  3221. /**
  3222. * mpi_set_phy_profile_resp - SPCv specific
  3223. * @pm8001_ha: our hba card information
  3224. * @piomb: IO message buffer
  3225. */
  3226. static int mpi_set_phy_profile_resp(struct pm8001_hba_info *pm8001_ha,
  3227. void *piomb)
  3228. {
  3229. u8 page_code;
  3230. struct set_phy_profile_resp *pPayload =
  3231. (struct set_phy_profile_resp *)(piomb + 4);
  3232. u32 ppc_phyid = le32_to_cpu(pPayload->ppc_phyid);
  3233. u32 status = le32_to_cpu(pPayload->status);
  3234. page_code = (u8)((ppc_phyid & 0xFF00) >> 8);
  3235. if (status) {
  3236. /* status is FAILED */
  3237. PM8001_FAIL_DBG(pm8001_ha,
  3238. pm8001_printk("PhyProfile command failed with status "
  3239. "0x%08X \n", status));
  3240. return -1;
  3241. } else {
  3242. if (page_code != SAS_PHY_ANALOG_SETTINGS_PAGE) {
  3243. PM8001_FAIL_DBG(pm8001_ha,
  3244. pm8001_printk("Invalid page code 0x%X\n",
  3245. page_code));
  3246. return -1;
  3247. }
  3248. }
  3249. return 0;
  3250. }
  3251. /**
  3252. * mpi_kek_management_resp - SPCv specific
  3253. * @pm8001_ha: our hba card information
  3254. * @piomb: IO message buffer
  3255. */
  3256. static int mpi_kek_management_resp(struct pm8001_hba_info *pm8001_ha,
  3257. void *piomb)
  3258. {
  3259. struct kek_mgmt_resp *pPayload = (struct kek_mgmt_resp *)(piomb + 4);
  3260. u32 status = le32_to_cpu(pPayload->status);
  3261. u32 kidx_new_curr_ksop = le32_to_cpu(pPayload->kidx_new_curr_ksop);
  3262. u32 err_qlfr = le32_to_cpu(pPayload->err_qlfr);
  3263. PM8001_MSG_DBG(pm8001_ha, pm8001_printk(
  3264. "KEK MGMT RESP. Status 0x%x idx_ksop 0x%x err_qlfr 0x%x\n",
  3265. status, kidx_new_curr_ksop, err_qlfr));
  3266. return 0;
  3267. }
  3268. /**
  3269. * mpi_dek_management_resp - SPCv specific
  3270. * @pm8001_ha: our hba card information
  3271. * @piomb: IO message buffer
  3272. */
  3273. static int mpi_dek_management_resp(struct pm8001_hba_info *pm8001_ha,
  3274. void *piomb)
  3275. {
  3276. PM8001_MSG_DBG(pm8001_ha,
  3277. pm8001_printk(" pm80xx_addition_functionality\n"));
  3278. return 0;
  3279. }
  3280. /**
  3281. * ssp_coalesced_comp_resp - SPCv specific
  3282. * @pm8001_ha: our hba card information
  3283. * @piomb: IO message buffer
  3284. */
  3285. static int ssp_coalesced_comp_resp(struct pm8001_hba_info *pm8001_ha,
  3286. void *piomb)
  3287. {
  3288. PM8001_MSG_DBG(pm8001_ha,
  3289. pm8001_printk(" pm80xx_addition_functionality\n"));
  3290. return 0;
  3291. }
  3292. /**
  3293. * process_one_iomb - process one outbound Queue memory block
  3294. * @pm8001_ha: our hba card information
  3295. * @piomb: IO message buffer
  3296. */
  3297. static void process_one_iomb(struct pm8001_hba_info *pm8001_ha, void *piomb)
  3298. {
  3299. __le32 pHeader = *(__le32 *)piomb;
  3300. u32 opc = (u32)((le32_to_cpu(pHeader)) & 0xFFF);
  3301. switch (opc) {
  3302. case OPC_OUB_ECHO:
  3303. PM8001_MSG_DBG(pm8001_ha, pm8001_printk("OPC_OUB_ECHO\n"));
  3304. break;
  3305. case OPC_OUB_HW_EVENT:
  3306. PM8001_MSG_DBG(pm8001_ha,
  3307. pm8001_printk("OPC_OUB_HW_EVENT\n"));
  3308. mpi_hw_event(pm8001_ha, piomb);
  3309. break;
  3310. case OPC_OUB_THERM_HW_EVENT:
  3311. PM8001_MSG_DBG(pm8001_ha,
  3312. pm8001_printk("OPC_OUB_THERMAL_EVENT\n"));
  3313. mpi_thermal_hw_event(pm8001_ha, piomb);
  3314. break;
  3315. case OPC_OUB_SSP_COMP:
  3316. PM8001_MSG_DBG(pm8001_ha,
  3317. pm8001_printk("OPC_OUB_SSP_COMP\n"));
  3318. mpi_ssp_completion(pm8001_ha, piomb);
  3319. break;
  3320. case OPC_OUB_SMP_COMP:
  3321. PM8001_MSG_DBG(pm8001_ha,
  3322. pm8001_printk("OPC_OUB_SMP_COMP\n"));
  3323. mpi_smp_completion(pm8001_ha, piomb);
  3324. break;
  3325. case OPC_OUB_LOCAL_PHY_CNTRL:
  3326. PM8001_MSG_DBG(pm8001_ha,
  3327. pm8001_printk("OPC_OUB_LOCAL_PHY_CNTRL\n"));
  3328. pm8001_mpi_local_phy_ctl(pm8001_ha, piomb);
  3329. break;
  3330. case OPC_OUB_DEV_REGIST:
  3331. PM8001_MSG_DBG(pm8001_ha,
  3332. pm8001_printk("OPC_OUB_DEV_REGIST\n"));
  3333. pm8001_mpi_reg_resp(pm8001_ha, piomb);
  3334. break;
  3335. case OPC_OUB_DEREG_DEV:
  3336. PM8001_MSG_DBG(pm8001_ha,
  3337. pm8001_printk("unregister the device\n"));
  3338. pm8001_mpi_dereg_resp(pm8001_ha, piomb);
  3339. break;
  3340. case OPC_OUB_GET_DEV_HANDLE:
  3341. PM8001_MSG_DBG(pm8001_ha,
  3342. pm8001_printk("OPC_OUB_GET_DEV_HANDLE\n"));
  3343. break;
  3344. case OPC_OUB_SATA_COMP:
  3345. PM8001_MSG_DBG(pm8001_ha,
  3346. pm8001_printk("OPC_OUB_SATA_COMP\n"));
  3347. mpi_sata_completion(pm8001_ha, piomb);
  3348. break;
  3349. case OPC_OUB_SATA_EVENT:
  3350. PM8001_MSG_DBG(pm8001_ha,
  3351. pm8001_printk("OPC_OUB_SATA_EVENT\n"));
  3352. mpi_sata_event(pm8001_ha, piomb);
  3353. break;
  3354. case OPC_OUB_SSP_EVENT:
  3355. PM8001_MSG_DBG(pm8001_ha,
  3356. pm8001_printk("OPC_OUB_SSP_EVENT\n"));
  3357. mpi_ssp_event(pm8001_ha, piomb);
  3358. break;
  3359. case OPC_OUB_DEV_HANDLE_ARRIV:
  3360. PM8001_MSG_DBG(pm8001_ha,
  3361. pm8001_printk("OPC_OUB_DEV_HANDLE_ARRIV\n"));
  3362. /*This is for target*/
  3363. break;
  3364. case OPC_OUB_SSP_RECV_EVENT:
  3365. PM8001_MSG_DBG(pm8001_ha,
  3366. pm8001_printk("OPC_OUB_SSP_RECV_EVENT\n"));
  3367. /*This is for target*/
  3368. break;
  3369. case OPC_OUB_FW_FLASH_UPDATE:
  3370. PM8001_MSG_DBG(pm8001_ha,
  3371. pm8001_printk("OPC_OUB_FW_FLASH_UPDATE\n"));
  3372. pm8001_mpi_fw_flash_update_resp(pm8001_ha, piomb);
  3373. break;
  3374. case OPC_OUB_GPIO_RESPONSE:
  3375. PM8001_MSG_DBG(pm8001_ha,
  3376. pm8001_printk("OPC_OUB_GPIO_RESPONSE\n"));
  3377. break;
  3378. case OPC_OUB_GPIO_EVENT:
  3379. PM8001_MSG_DBG(pm8001_ha,
  3380. pm8001_printk("OPC_OUB_GPIO_EVENT\n"));
  3381. break;
  3382. case OPC_OUB_GENERAL_EVENT:
  3383. PM8001_MSG_DBG(pm8001_ha,
  3384. pm8001_printk("OPC_OUB_GENERAL_EVENT\n"));
  3385. pm8001_mpi_general_event(pm8001_ha, piomb);
  3386. break;
  3387. case OPC_OUB_SSP_ABORT_RSP:
  3388. PM8001_MSG_DBG(pm8001_ha,
  3389. pm8001_printk("OPC_OUB_SSP_ABORT_RSP\n"));
  3390. pm8001_mpi_task_abort_resp(pm8001_ha, piomb);
  3391. break;
  3392. case OPC_OUB_SATA_ABORT_RSP:
  3393. PM8001_MSG_DBG(pm8001_ha,
  3394. pm8001_printk("OPC_OUB_SATA_ABORT_RSP\n"));
  3395. pm8001_mpi_task_abort_resp(pm8001_ha, piomb);
  3396. break;
  3397. case OPC_OUB_SAS_DIAG_MODE_START_END:
  3398. PM8001_MSG_DBG(pm8001_ha,
  3399. pm8001_printk("OPC_OUB_SAS_DIAG_MODE_START_END\n"));
  3400. break;
  3401. case OPC_OUB_SAS_DIAG_EXECUTE:
  3402. PM8001_MSG_DBG(pm8001_ha,
  3403. pm8001_printk("OPC_OUB_SAS_DIAG_EXECUTE\n"));
  3404. break;
  3405. case OPC_OUB_GET_TIME_STAMP:
  3406. PM8001_MSG_DBG(pm8001_ha,
  3407. pm8001_printk("OPC_OUB_GET_TIME_STAMP\n"));
  3408. break;
  3409. case OPC_OUB_SAS_HW_EVENT_ACK:
  3410. PM8001_MSG_DBG(pm8001_ha,
  3411. pm8001_printk("OPC_OUB_SAS_HW_EVENT_ACK\n"));
  3412. break;
  3413. case OPC_OUB_PORT_CONTROL:
  3414. PM8001_MSG_DBG(pm8001_ha,
  3415. pm8001_printk("OPC_OUB_PORT_CONTROL\n"));
  3416. break;
  3417. case OPC_OUB_SMP_ABORT_RSP:
  3418. PM8001_MSG_DBG(pm8001_ha,
  3419. pm8001_printk("OPC_OUB_SMP_ABORT_RSP\n"));
  3420. pm8001_mpi_task_abort_resp(pm8001_ha, piomb);
  3421. break;
  3422. case OPC_OUB_GET_NVMD_DATA:
  3423. PM8001_MSG_DBG(pm8001_ha,
  3424. pm8001_printk("OPC_OUB_GET_NVMD_DATA\n"));
  3425. pm8001_mpi_get_nvmd_resp(pm8001_ha, piomb);
  3426. break;
  3427. case OPC_OUB_SET_NVMD_DATA:
  3428. PM8001_MSG_DBG(pm8001_ha,
  3429. pm8001_printk("OPC_OUB_SET_NVMD_DATA\n"));
  3430. pm8001_mpi_set_nvmd_resp(pm8001_ha, piomb);
  3431. break;
  3432. case OPC_OUB_DEVICE_HANDLE_REMOVAL:
  3433. PM8001_MSG_DBG(pm8001_ha,
  3434. pm8001_printk("OPC_OUB_DEVICE_HANDLE_REMOVAL\n"));
  3435. break;
  3436. case OPC_OUB_SET_DEVICE_STATE:
  3437. PM8001_MSG_DBG(pm8001_ha,
  3438. pm8001_printk("OPC_OUB_SET_DEVICE_STATE\n"));
  3439. pm8001_mpi_set_dev_state_resp(pm8001_ha, piomb);
  3440. break;
  3441. case OPC_OUB_GET_DEVICE_STATE:
  3442. PM8001_MSG_DBG(pm8001_ha,
  3443. pm8001_printk("OPC_OUB_GET_DEVICE_STATE\n"));
  3444. break;
  3445. case OPC_OUB_SET_DEV_INFO:
  3446. PM8001_MSG_DBG(pm8001_ha,
  3447. pm8001_printk("OPC_OUB_SET_DEV_INFO\n"));
  3448. break;
  3449. /* spcv specifc commands */
  3450. case OPC_OUB_PHY_START_RESP:
  3451. PM8001_MSG_DBG(pm8001_ha, pm8001_printk(
  3452. "OPC_OUB_PHY_START_RESP opcode:%x\n", opc));
  3453. mpi_phy_start_resp(pm8001_ha, piomb);
  3454. break;
  3455. case OPC_OUB_PHY_STOP_RESP:
  3456. PM8001_MSG_DBG(pm8001_ha, pm8001_printk(
  3457. "OPC_OUB_PHY_STOP_RESP opcode:%x\n", opc));
  3458. mpi_phy_stop_resp(pm8001_ha, piomb);
  3459. break;
  3460. case OPC_OUB_SET_CONTROLLER_CONFIG:
  3461. PM8001_MSG_DBG(pm8001_ha, pm8001_printk(
  3462. "OPC_OUB_SET_CONTROLLER_CONFIG opcode:%x\n", opc));
  3463. mpi_set_controller_config_resp(pm8001_ha, piomb);
  3464. break;
  3465. case OPC_OUB_GET_CONTROLLER_CONFIG:
  3466. PM8001_MSG_DBG(pm8001_ha, pm8001_printk(
  3467. "OPC_OUB_GET_CONTROLLER_CONFIG opcode:%x\n", opc));
  3468. mpi_get_controller_config_resp(pm8001_ha, piomb);
  3469. break;
  3470. case OPC_OUB_GET_PHY_PROFILE:
  3471. PM8001_MSG_DBG(pm8001_ha, pm8001_printk(
  3472. "OPC_OUB_GET_PHY_PROFILE opcode:%x\n", opc));
  3473. mpi_get_phy_profile_resp(pm8001_ha, piomb);
  3474. break;
  3475. case OPC_OUB_FLASH_OP_EXT:
  3476. PM8001_MSG_DBG(pm8001_ha, pm8001_printk(
  3477. "OPC_OUB_FLASH_OP_EXT opcode:%x\n", opc));
  3478. mpi_flash_op_ext_resp(pm8001_ha, piomb);
  3479. break;
  3480. case OPC_OUB_SET_PHY_PROFILE:
  3481. PM8001_MSG_DBG(pm8001_ha, pm8001_printk(
  3482. "OPC_OUB_SET_PHY_PROFILE opcode:%x\n", opc));
  3483. mpi_set_phy_profile_resp(pm8001_ha, piomb);
  3484. break;
  3485. case OPC_OUB_KEK_MANAGEMENT_RESP:
  3486. PM8001_MSG_DBG(pm8001_ha, pm8001_printk(
  3487. "OPC_OUB_KEK_MANAGEMENT_RESP opcode:%x\n", opc));
  3488. mpi_kek_management_resp(pm8001_ha, piomb);
  3489. break;
  3490. case OPC_OUB_DEK_MANAGEMENT_RESP:
  3491. PM8001_MSG_DBG(pm8001_ha, pm8001_printk(
  3492. "OPC_OUB_DEK_MANAGEMENT_RESP opcode:%x\n", opc));
  3493. mpi_dek_management_resp(pm8001_ha, piomb);
  3494. break;
  3495. case OPC_OUB_SSP_COALESCED_COMP_RESP:
  3496. PM8001_MSG_DBG(pm8001_ha, pm8001_printk(
  3497. "OPC_OUB_SSP_COALESCED_COMP_RESP opcode:%x\n", opc));
  3498. ssp_coalesced_comp_resp(pm8001_ha, piomb);
  3499. break;
  3500. default:
  3501. PM8001_MSG_DBG(pm8001_ha, pm8001_printk(
  3502. "Unknown outbound Queue IOMB OPC = 0x%x\n", opc));
  3503. break;
  3504. }
  3505. }
  3506. static int process_oq(struct pm8001_hba_info *pm8001_ha, u8 vec)
  3507. {
  3508. struct outbound_queue_table *circularQ;
  3509. void *pMsg1 = NULL;
  3510. u8 uninitialized_var(bc);
  3511. u32 ret = MPI_IO_STATUS_FAIL;
  3512. unsigned long flags;
  3513. spin_lock_irqsave(&pm8001_ha->lock, flags);
  3514. circularQ = &pm8001_ha->outbnd_q_tbl[vec];
  3515. do {
  3516. ret = pm8001_mpi_msg_consume(pm8001_ha, circularQ, &pMsg1, &bc);
  3517. if (MPI_IO_STATUS_SUCCESS == ret) {
  3518. /* process the outbound message */
  3519. process_one_iomb(pm8001_ha, (void *)(pMsg1 - 4));
  3520. /* free the message from the outbound circular buffer */
  3521. pm8001_mpi_msg_free_set(pm8001_ha, pMsg1,
  3522. circularQ, bc);
  3523. }
  3524. if (MPI_IO_STATUS_BUSY == ret) {
  3525. /* Update the producer index from SPC */
  3526. circularQ->producer_index =
  3527. cpu_to_le32(pm8001_read_32(circularQ->pi_virt));
  3528. if (le32_to_cpu(circularQ->producer_index) ==
  3529. circularQ->consumer_idx)
  3530. /* OQ is empty */
  3531. break;
  3532. }
  3533. } while (1);
  3534. spin_unlock_irqrestore(&pm8001_ha->lock, flags);
  3535. return ret;
  3536. }
  3537. /* PCI_DMA_... to our direction translation. */
  3538. static const u8 data_dir_flags[] = {
  3539. [PCI_DMA_BIDIRECTIONAL] = DATA_DIR_BYRECIPIENT,/* UNSPECIFIED */
  3540. [PCI_DMA_TODEVICE] = DATA_DIR_OUT,/* OUTBOUND */
  3541. [PCI_DMA_FROMDEVICE] = DATA_DIR_IN,/* INBOUND */
  3542. [PCI_DMA_NONE] = DATA_DIR_NONE,/* NO TRANSFER */
  3543. };
  3544. static void build_smp_cmd(u32 deviceID, __le32 hTag,
  3545. struct smp_req *psmp_cmd, int mode, int length)
  3546. {
  3547. psmp_cmd->tag = hTag;
  3548. psmp_cmd->device_id = cpu_to_le32(deviceID);
  3549. if (mode == SMP_DIRECT) {
  3550. length = length - 4; /* subtract crc */
  3551. psmp_cmd->len_ip_ir = cpu_to_le32(length << 16);
  3552. } else {
  3553. psmp_cmd->len_ip_ir = cpu_to_le32(1|(1 << 1));
  3554. }
  3555. }
  3556. /**
  3557. * pm8001_chip_smp_req - send a SMP task to FW
  3558. * @pm8001_ha: our hba card information.
  3559. * @ccb: the ccb information this request used.
  3560. */
  3561. static int pm80xx_chip_smp_req(struct pm8001_hba_info *pm8001_ha,
  3562. struct pm8001_ccb_info *ccb)
  3563. {
  3564. int elem, rc;
  3565. struct sas_task *task = ccb->task;
  3566. struct domain_device *dev = task->dev;
  3567. struct pm8001_device *pm8001_dev = dev->lldd_dev;
  3568. struct scatterlist *sg_req, *sg_resp;
  3569. u32 req_len, resp_len;
  3570. struct smp_req smp_cmd;
  3571. u32 opc;
  3572. struct inbound_queue_table *circularQ;
  3573. char *preq_dma_addr = NULL;
  3574. __le64 tmp_addr;
  3575. u32 i, length;
  3576. memset(&smp_cmd, 0, sizeof(smp_cmd));
  3577. /*
  3578. * DMA-map SMP request, response buffers
  3579. */
  3580. sg_req = &task->smp_task.smp_req;
  3581. elem = dma_map_sg(pm8001_ha->dev, sg_req, 1, PCI_DMA_TODEVICE);
  3582. if (!elem)
  3583. return -ENOMEM;
  3584. req_len = sg_dma_len(sg_req);
  3585. sg_resp = &task->smp_task.smp_resp;
  3586. elem = dma_map_sg(pm8001_ha->dev, sg_resp, 1, PCI_DMA_FROMDEVICE);
  3587. if (!elem) {
  3588. rc = -ENOMEM;
  3589. goto err_out;
  3590. }
  3591. resp_len = sg_dma_len(sg_resp);
  3592. /* must be in dwords */
  3593. if ((req_len & 0x3) || (resp_len & 0x3)) {
  3594. rc = -EINVAL;
  3595. goto err_out_2;
  3596. }
  3597. opc = OPC_INB_SMP_REQUEST;
  3598. circularQ = &pm8001_ha->inbnd_q_tbl[0];
  3599. smp_cmd.tag = cpu_to_le32(ccb->ccb_tag);
  3600. length = sg_req->length;
  3601. PM8001_IO_DBG(pm8001_ha,
  3602. pm8001_printk("SMP Frame Length %d\n", sg_req->length));
  3603. if (!(length - 8))
  3604. pm8001_ha->smp_exp_mode = SMP_DIRECT;
  3605. else
  3606. pm8001_ha->smp_exp_mode = SMP_INDIRECT;
  3607. tmp_addr = cpu_to_le64((u64)sg_dma_address(&task->smp_task.smp_req));
  3608. preq_dma_addr = (char *)phys_to_virt(tmp_addr);
  3609. /* INDIRECT MODE command settings. Use DMA */
  3610. if (pm8001_ha->smp_exp_mode == SMP_INDIRECT) {
  3611. PM8001_IO_DBG(pm8001_ha,
  3612. pm8001_printk("SMP REQUEST INDIRECT MODE\n"));
  3613. /* for SPCv indirect mode. Place the top 4 bytes of
  3614. * SMP Request header here. */
  3615. for (i = 0; i < 4; i++)
  3616. smp_cmd.smp_req16[i] = *(preq_dma_addr + i);
  3617. /* exclude top 4 bytes for SMP req header */
  3618. smp_cmd.long_smp_req.long_req_addr =
  3619. cpu_to_le64((u64)sg_dma_address
  3620. (&task->smp_task.smp_req) + 4);
  3621. /* exclude 4 bytes for SMP req header and CRC */
  3622. smp_cmd.long_smp_req.long_req_size =
  3623. cpu_to_le32((u32)sg_dma_len(&task->smp_task.smp_req)-8);
  3624. smp_cmd.long_smp_req.long_resp_addr =
  3625. cpu_to_le64((u64)sg_dma_address
  3626. (&task->smp_task.smp_resp));
  3627. smp_cmd.long_smp_req.long_resp_size =
  3628. cpu_to_le32((u32)sg_dma_len
  3629. (&task->smp_task.smp_resp)-4);
  3630. } else { /* DIRECT MODE */
  3631. smp_cmd.long_smp_req.long_req_addr =
  3632. cpu_to_le64((u64)sg_dma_address
  3633. (&task->smp_task.smp_req));
  3634. smp_cmd.long_smp_req.long_req_size =
  3635. cpu_to_le32((u32)sg_dma_len(&task->smp_task.smp_req)-4);
  3636. smp_cmd.long_smp_req.long_resp_addr =
  3637. cpu_to_le64((u64)sg_dma_address
  3638. (&task->smp_task.smp_resp));
  3639. smp_cmd.long_smp_req.long_resp_size =
  3640. cpu_to_le32
  3641. ((u32)sg_dma_len(&task->smp_task.smp_resp)-4);
  3642. }
  3643. if (pm8001_ha->smp_exp_mode == SMP_DIRECT) {
  3644. PM8001_IO_DBG(pm8001_ha,
  3645. pm8001_printk("SMP REQUEST DIRECT MODE\n"));
  3646. for (i = 0; i < length; i++)
  3647. if (i < 16) {
  3648. smp_cmd.smp_req16[i] = *(preq_dma_addr+i);
  3649. PM8001_IO_DBG(pm8001_ha, pm8001_printk(
  3650. "Byte[%d]:%x (DMA data:%x)\n",
  3651. i, smp_cmd.smp_req16[i],
  3652. *(preq_dma_addr)));
  3653. } else {
  3654. smp_cmd.smp_req[i] = *(preq_dma_addr+i);
  3655. PM8001_IO_DBG(pm8001_ha, pm8001_printk(
  3656. "Byte[%d]:%x (DMA data:%x)\n",
  3657. i, smp_cmd.smp_req[i],
  3658. *(preq_dma_addr)));
  3659. }
  3660. }
  3661. build_smp_cmd(pm8001_dev->device_id, smp_cmd.tag,
  3662. &smp_cmd, pm8001_ha->smp_exp_mode, length);
  3663. rc = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc,
  3664. (u32 *)&smp_cmd, 0);
  3665. if (rc)
  3666. goto err_out_2;
  3667. return 0;
  3668. err_out_2:
  3669. dma_unmap_sg(pm8001_ha->dev, &ccb->task->smp_task.smp_resp, 1,
  3670. PCI_DMA_FROMDEVICE);
  3671. err_out:
  3672. dma_unmap_sg(pm8001_ha->dev, &ccb->task->smp_task.smp_req, 1,
  3673. PCI_DMA_TODEVICE);
  3674. return rc;
  3675. }
  3676. static int check_enc_sas_cmd(struct sas_task *task)
  3677. {
  3678. u8 cmd = task->ssp_task.cmd->cmnd[0];
  3679. if (cmd == READ_10 || cmd == WRITE_10 || cmd == WRITE_VERIFY)
  3680. return 1;
  3681. else
  3682. return 0;
  3683. }
  3684. static int check_enc_sat_cmd(struct sas_task *task)
  3685. {
  3686. int ret = 0;
  3687. switch (task->ata_task.fis.command) {
  3688. case ATA_CMD_FPDMA_READ:
  3689. case ATA_CMD_READ_EXT:
  3690. case ATA_CMD_READ:
  3691. case ATA_CMD_FPDMA_WRITE:
  3692. case ATA_CMD_WRITE_EXT:
  3693. case ATA_CMD_WRITE:
  3694. case ATA_CMD_PIO_READ:
  3695. case ATA_CMD_PIO_READ_EXT:
  3696. case ATA_CMD_PIO_WRITE:
  3697. case ATA_CMD_PIO_WRITE_EXT:
  3698. ret = 1;
  3699. break;
  3700. default:
  3701. ret = 0;
  3702. break;
  3703. }
  3704. return ret;
  3705. }
  3706. /**
  3707. * pm80xx_chip_ssp_io_req - send a SSP task to FW
  3708. * @pm8001_ha: our hba card information.
  3709. * @ccb: the ccb information this request used.
  3710. */
  3711. static int pm80xx_chip_ssp_io_req(struct pm8001_hba_info *pm8001_ha,
  3712. struct pm8001_ccb_info *ccb)
  3713. {
  3714. struct sas_task *task = ccb->task;
  3715. struct domain_device *dev = task->dev;
  3716. struct pm8001_device *pm8001_dev = dev->lldd_dev;
  3717. struct ssp_ini_io_start_req ssp_cmd;
  3718. u32 tag = ccb->ccb_tag;
  3719. int ret;
  3720. u64 phys_addr, start_addr, end_addr;
  3721. u32 end_addr_high, end_addr_low;
  3722. struct inbound_queue_table *circularQ;
  3723. u32 q_index;
  3724. u32 opc = OPC_INB_SSPINIIOSTART;
  3725. memset(&ssp_cmd, 0, sizeof(ssp_cmd));
  3726. memcpy(ssp_cmd.ssp_iu.lun, task->ssp_task.LUN, 8);
  3727. /* data address domain added for spcv; set to 0 by host,
  3728. * used internally by controller
  3729. * 0 for SAS 1.1 and SAS 2.0 compatible TLR
  3730. */
  3731. ssp_cmd.dad_dir_m_tlr =
  3732. cpu_to_le32(data_dir_flags[task->data_dir] << 8 | 0x0);
  3733. ssp_cmd.data_len = cpu_to_le32(task->total_xfer_len);
  3734. ssp_cmd.device_id = cpu_to_le32(pm8001_dev->device_id);
  3735. ssp_cmd.tag = cpu_to_le32(tag);
  3736. if (task->ssp_task.enable_first_burst)
  3737. ssp_cmd.ssp_iu.efb_prio_attr |= 0x80;
  3738. ssp_cmd.ssp_iu.efb_prio_attr |= (task->ssp_task.task_prio << 3);
  3739. ssp_cmd.ssp_iu.efb_prio_attr |= (task->ssp_task.task_attr & 7);
  3740. memcpy(ssp_cmd.ssp_iu.cdb, task->ssp_task.cmd->cmnd,
  3741. task->ssp_task.cmd->cmd_len);
  3742. q_index = (u32) (pm8001_dev->id & 0x00ffffff) % PM8001_MAX_INB_NUM;
  3743. circularQ = &pm8001_ha->inbnd_q_tbl[q_index];
  3744. /* Check if encryption is set */
  3745. if (pm8001_ha->chip->encrypt &&
  3746. !(pm8001_ha->encrypt_info.status) && check_enc_sas_cmd(task)) {
  3747. PM8001_IO_DBG(pm8001_ha, pm8001_printk(
  3748. "Encryption enabled.Sending Encrypt SAS command 0x%x\n",
  3749. task->ssp_task.cmd->cmnd[0]));
  3750. opc = OPC_INB_SSP_INI_DIF_ENC_IO;
  3751. /* enable encryption. 0 for SAS 1.1 and SAS 2.0 compatible TLR*/
  3752. ssp_cmd.dad_dir_m_tlr = cpu_to_le32
  3753. ((data_dir_flags[task->data_dir] << 8) | 0x20 | 0x0);
  3754. /* fill in PRD (scatter/gather) table, if any */
  3755. if (task->num_scatter > 1) {
  3756. pm8001_chip_make_sg(task->scatter,
  3757. ccb->n_elem, ccb->buf_prd);
  3758. phys_addr = ccb->ccb_dma_handle +
  3759. offsetof(struct pm8001_ccb_info, buf_prd[0]);
  3760. ssp_cmd.enc_addr_low =
  3761. cpu_to_le32(lower_32_bits(phys_addr));
  3762. ssp_cmd.enc_addr_high =
  3763. cpu_to_le32(upper_32_bits(phys_addr));
  3764. ssp_cmd.enc_esgl = cpu_to_le32(1<<31);
  3765. } else if (task->num_scatter == 1) {
  3766. u64 dma_addr = sg_dma_address(task->scatter);
  3767. ssp_cmd.enc_addr_low =
  3768. cpu_to_le32(lower_32_bits(dma_addr));
  3769. ssp_cmd.enc_addr_high =
  3770. cpu_to_le32(upper_32_bits(dma_addr));
  3771. ssp_cmd.enc_len = cpu_to_le32(task->total_xfer_len);
  3772. ssp_cmd.enc_esgl = 0;
  3773. /* Check 4G Boundary */
  3774. start_addr = cpu_to_le64(dma_addr);
  3775. end_addr = (start_addr + ssp_cmd.enc_len) - 1;
  3776. end_addr_low = cpu_to_le32(lower_32_bits(end_addr));
  3777. end_addr_high = cpu_to_le32(upper_32_bits(end_addr));
  3778. if (end_addr_high != ssp_cmd.enc_addr_high) {
  3779. PM8001_FAIL_DBG(pm8001_ha,
  3780. pm8001_printk("The sg list address "
  3781. "start_addr=0x%016llx data_len=0x%x "
  3782. "end_addr_high=0x%08x end_addr_low="
  3783. "0x%08x has crossed 4G boundary\n",
  3784. start_addr, ssp_cmd.enc_len,
  3785. end_addr_high, end_addr_low));
  3786. pm8001_chip_make_sg(task->scatter, 1,
  3787. ccb->buf_prd);
  3788. phys_addr = ccb->ccb_dma_handle +
  3789. offsetof(struct pm8001_ccb_info,
  3790. buf_prd[0]);
  3791. ssp_cmd.enc_addr_low =
  3792. cpu_to_le32(lower_32_bits(phys_addr));
  3793. ssp_cmd.enc_addr_high =
  3794. cpu_to_le32(upper_32_bits(phys_addr));
  3795. ssp_cmd.enc_esgl = cpu_to_le32(1<<31);
  3796. }
  3797. } else if (task->num_scatter == 0) {
  3798. ssp_cmd.enc_addr_low = 0;
  3799. ssp_cmd.enc_addr_high = 0;
  3800. ssp_cmd.enc_len = cpu_to_le32(task->total_xfer_len);
  3801. ssp_cmd.enc_esgl = 0;
  3802. }
  3803. /* XTS mode. All other fields are 0 */
  3804. ssp_cmd.key_cmode = 0x6 << 4;
  3805. /* set tweak values. Should be the start lba */
  3806. ssp_cmd.twk_val0 = cpu_to_le32((task->ssp_task.cmd->cmnd[2] << 24) |
  3807. (task->ssp_task.cmd->cmnd[3] << 16) |
  3808. (task->ssp_task.cmd->cmnd[4] << 8) |
  3809. (task->ssp_task.cmd->cmnd[5]));
  3810. } else {
  3811. PM8001_IO_DBG(pm8001_ha, pm8001_printk(
  3812. "Sending Normal SAS command 0x%x inb q %x\n",
  3813. task->ssp_task.cmd->cmnd[0], q_index));
  3814. /* fill in PRD (scatter/gather) table, if any */
  3815. if (task->num_scatter > 1) {
  3816. pm8001_chip_make_sg(task->scatter, ccb->n_elem,
  3817. ccb->buf_prd);
  3818. phys_addr = ccb->ccb_dma_handle +
  3819. offsetof(struct pm8001_ccb_info, buf_prd[0]);
  3820. ssp_cmd.addr_low =
  3821. cpu_to_le32(lower_32_bits(phys_addr));
  3822. ssp_cmd.addr_high =
  3823. cpu_to_le32(upper_32_bits(phys_addr));
  3824. ssp_cmd.esgl = cpu_to_le32(1<<31);
  3825. } else if (task->num_scatter == 1) {
  3826. u64 dma_addr = sg_dma_address(task->scatter);
  3827. ssp_cmd.addr_low = cpu_to_le32(lower_32_bits(dma_addr));
  3828. ssp_cmd.addr_high =
  3829. cpu_to_le32(upper_32_bits(dma_addr));
  3830. ssp_cmd.len = cpu_to_le32(task->total_xfer_len);
  3831. ssp_cmd.esgl = 0;
  3832. /* Check 4G Boundary */
  3833. start_addr = cpu_to_le64(dma_addr);
  3834. end_addr = (start_addr + ssp_cmd.len) - 1;
  3835. end_addr_low = cpu_to_le32(lower_32_bits(end_addr));
  3836. end_addr_high = cpu_to_le32(upper_32_bits(end_addr));
  3837. if (end_addr_high != ssp_cmd.addr_high) {
  3838. PM8001_FAIL_DBG(pm8001_ha,
  3839. pm8001_printk("The sg list address "
  3840. "start_addr=0x%016llx data_len=0x%x "
  3841. "end_addr_high=0x%08x end_addr_low="
  3842. "0x%08x has crossed 4G boundary\n",
  3843. start_addr, ssp_cmd.len,
  3844. end_addr_high, end_addr_low));
  3845. pm8001_chip_make_sg(task->scatter, 1,
  3846. ccb->buf_prd);
  3847. phys_addr = ccb->ccb_dma_handle +
  3848. offsetof(struct pm8001_ccb_info,
  3849. buf_prd[0]);
  3850. ssp_cmd.addr_low =
  3851. cpu_to_le32(lower_32_bits(phys_addr));
  3852. ssp_cmd.addr_high =
  3853. cpu_to_le32(upper_32_bits(phys_addr));
  3854. ssp_cmd.esgl = cpu_to_le32(1<<31);
  3855. }
  3856. } else if (task->num_scatter == 0) {
  3857. ssp_cmd.addr_low = 0;
  3858. ssp_cmd.addr_high = 0;
  3859. ssp_cmd.len = cpu_to_le32(task->total_xfer_len);
  3860. ssp_cmd.esgl = 0;
  3861. }
  3862. }
  3863. q_index = (u32) (pm8001_dev->id & 0x00ffffff) % PM8001_MAX_OUTB_NUM;
  3864. ret = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc,
  3865. &ssp_cmd, q_index);
  3866. return ret;
  3867. }
  3868. static int pm80xx_chip_sata_req(struct pm8001_hba_info *pm8001_ha,
  3869. struct pm8001_ccb_info *ccb)
  3870. {
  3871. struct sas_task *task = ccb->task;
  3872. struct domain_device *dev = task->dev;
  3873. struct pm8001_device *pm8001_ha_dev = dev->lldd_dev;
  3874. u32 tag = ccb->ccb_tag;
  3875. int ret;
  3876. u32 q_index;
  3877. struct sata_start_req sata_cmd;
  3878. u32 hdr_tag, ncg_tag = 0;
  3879. u64 phys_addr, start_addr, end_addr;
  3880. u32 end_addr_high, end_addr_low;
  3881. u32 ATAP = 0x0;
  3882. u32 dir;
  3883. struct inbound_queue_table *circularQ;
  3884. unsigned long flags;
  3885. u32 opc = OPC_INB_SATA_HOST_OPSTART;
  3886. memset(&sata_cmd, 0, sizeof(sata_cmd));
  3887. q_index = (u32) (pm8001_ha_dev->id & 0x00ffffff) % PM8001_MAX_INB_NUM;
  3888. circularQ = &pm8001_ha->inbnd_q_tbl[q_index];
  3889. if (task->data_dir == PCI_DMA_NONE) {
  3890. ATAP = 0x04; /* no data*/
  3891. PM8001_IO_DBG(pm8001_ha, pm8001_printk("no data\n"));
  3892. } else if (likely(!task->ata_task.device_control_reg_update)) {
  3893. if (task->ata_task.dma_xfer) {
  3894. ATAP = 0x06; /* DMA */
  3895. PM8001_IO_DBG(pm8001_ha, pm8001_printk("DMA\n"));
  3896. } else {
  3897. ATAP = 0x05; /* PIO*/
  3898. PM8001_IO_DBG(pm8001_ha, pm8001_printk("PIO\n"));
  3899. }
  3900. if (task->ata_task.use_ncq &&
  3901. dev->sata_dev.class != ATA_DEV_ATAPI) {
  3902. ATAP = 0x07; /* FPDMA */
  3903. PM8001_IO_DBG(pm8001_ha, pm8001_printk("FPDMA\n"));
  3904. }
  3905. }
  3906. if (task->ata_task.use_ncq && pm8001_get_ncq_tag(task, &hdr_tag)) {
  3907. task->ata_task.fis.sector_count |= (u8) (hdr_tag << 3);
  3908. ncg_tag = hdr_tag;
  3909. }
  3910. dir = data_dir_flags[task->data_dir] << 8;
  3911. sata_cmd.tag = cpu_to_le32(tag);
  3912. sata_cmd.device_id = cpu_to_le32(pm8001_ha_dev->device_id);
  3913. sata_cmd.data_len = cpu_to_le32(task->total_xfer_len);
  3914. sata_cmd.sata_fis = task->ata_task.fis;
  3915. if (likely(!task->ata_task.device_control_reg_update))
  3916. sata_cmd.sata_fis.flags |= 0x80;/* C=1: update ATA cmd reg */
  3917. sata_cmd.sata_fis.flags &= 0xF0;/* PM_PORT field shall be 0 */
  3918. /* Check if encryption is set */
  3919. if (pm8001_ha->chip->encrypt &&
  3920. !(pm8001_ha->encrypt_info.status) && check_enc_sat_cmd(task)) {
  3921. PM8001_IO_DBG(pm8001_ha, pm8001_printk(
  3922. "Encryption enabled.Sending Encrypt SATA cmd 0x%x\n",
  3923. sata_cmd.sata_fis.command));
  3924. opc = OPC_INB_SATA_DIF_ENC_IO;
  3925. /* set encryption bit */
  3926. sata_cmd.ncqtag_atap_dir_m_dad =
  3927. cpu_to_le32(((ncg_tag & 0xff)<<16)|
  3928. ((ATAP & 0x3f) << 10) | 0x20 | dir);
  3929. /* dad (bit 0-1) is 0 */
  3930. /* fill in PRD (scatter/gather) table, if any */
  3931. if (task->num_scatter > 1) {
  3932. pm8001_chip_make_sg(task->scatter,
  3933. ccb->n_elem, ccb->buf_prd);
  3934. phys_addr = ccb->ccb_dma_handle +
  3935. offsetof(struct pm8001_ccb_info, buf_prd[0]);
  3936. sata_cmd.enc_addr_low = lower_32_bits(phys_addr);
  3937. sata_cmd.enc_addr_high = upper_32_bits(phys_addr);
  3938. sata_cmd.enc_esgl = cpu_to_le32(1 << 31);
  3939. } else if (task->num_scatter == 1) {
  3940. u64 dma_addr = sg_dma_address(task->scatter);
  3941. sata_cmd.enc_addr_low = lower_32_bits(dma_addr);
  3942. sata_cmd.enc_addr_high = upper_32_bits(dma_addr);
  3943. sata_cmd.enc_len = cpu_to_le32(task->total_xfer_len);
  3944. sata_cmd.enc_esgl = 0;
  3945. /* Check 4G Boundary */
  3946. start_addr = cpu_to_le64(dma_addr);
  3947. end_addr = (start_addr + sata_cmd.enc_len) - 1;
  3948. end_addr_low = cpu_to_le32(lower_32_bits(end_addr));
  3949. end_addr_high = cpu_to_le32(upper_32_bits(end_addr));
  3950. if (end_addr_high != sata_cmd.enc_addr_high) {
  3951. PM8001_FAIL_DBG(pm8001_ha,
  3952. pm8001_printk("The sg list address "
  3953. "start_addr=0x%016llx data_len=0x%x "
  3954. "end_addr_high=0x%08x end_addr_low"
  3955. "=0x%08x has crossed 4G boundary\n",
  3956. start_addr, sata_cmd.enc_len,
  3957. end_addr_high, end_addr_low));
  3958. pm8001_chip_make_sg(task->scatter, 1,
  3959. ccb->buf_prd);
  3960. phys_addr = ccb->ccb_dma_handle +
  3961. offsetof(struct pm8001_ccb_info,
  3962. buf_prd[0]);
  3963. sata_cmd.enc_addr_low =
  3964. lower_32_bits(phys_addr);
  3965. sata_cmd.enc_addr_high =
  3966. upper_32_bits(phys_addr);
  3967. sata_cmd.enc_esgl =
  3968. cpu_to_le32(1 << 31);
  3969. }
  3970. } else if (task->num_scatter == 0) {
  3971. sata_cmd.enc_addr_low = 0;
  3972. sata_cmd.enc_addr_high = 0;
  3973. sata_cmd.enc_len = cpu_to_le32(task->total_xfer_len);
  3974. sata_cmd.enc_esgl = 0;
  3975. }
  3976. /* XTS mode. All other fields are 0 */
  3977. sata_cmd.key_index_mode = 0x6 << 4;
  3978. /* set tweak values. Should be the start lba */
  3979. sata_cmd.twk_val0 =
  3980. cpu_to_le32((sata_cmd.sata_fis.lbal_exp << 24) |
  3981. (sata_cmd.sata_fis.lbah << 16) |
  3982. (sata_cmd.sata_fis.lbam << 8) |
  3983. (sata_cmd.sata_fis.lbal));
  3984. sata_cmd.twk_val1 =
  3985. cpu_to_le32((sata_cmd.sata_fis.lbah_exp << 8) |
  3986. (sata_cmd.sata_fis.lbam_exp));
  3987. } else {
  3988. PM8001_IO_DBG(pm8001_ha, pm8001_printk(
  3989. "Sending Normal SATA command 0x%x inb %x\n",
  3990. sata_cmd.sata_fis.command, q_index));
  3991. /* dad (bit 0-1) is 0 */
  3992. sata_cmd.ncqtag_atap_dir_m_dad =
  3993. cpu_to_le32(((ncg_tag & 0xff)<<16) |
  3994. ((ATAP & 0x3f) << 10) | dir);
  3995. /* fill in PRD (scatter/gather) table, if any */
  3996. if (task->num_scatter > 1) {
  3997. pm8001_chip_make_sg(task->scatter,
  3998. ccb->n_elem, ccb->buf_prd);
  3999. phys_addr = ccb->ccb_dma_handle +
  4000. offsetof(struct pm8001_ccb_info, buf_prd[0]);
  4001. sata_cmd.addr_low = lower_32_bits(phys_addr);
  4002. sata_cmd.addr_high = upper_32_bits(phys_addr);
  4003. sata_cmd.esgl = cpu_to_le32(1 << 31);
  4004. } else if (task->num_scatter == 1) {
  4005. u64 dma_addr = sg_dma_address(task->scatter);
  4006. sata_cmd.addr_low = lower_32_bits(dma_addr);
  4007. sata_cmd.addr_high = upper_32_bits(dma_addr);
  4008. sata_cmd.len = cpu_to_le32(task->total_xfer_len);
  4009. sata_cmd.esgl = 0;
  4010. /* Check 4G Boundary */
  4011. start_addr = cpu_to_le64(dma_addr);
  4012. end_addr = (start_addr + sata_cmd.len) - 1;
  4013. end_addr_low = cpu_to_le32(lower_32_bits(end_addr));
  4014. end_addr_high = cpu_to_le32(upper_32_bits(end_addr));
  4015. if (end_addr_high != sata_cmd.addr_high) {
  4016. PM8001_FAIL_DBG(pm8001_ha,
  4017. pm8001_printk("The sg list address "
  4018. "start_addr=0x%016llx data_len=0x%x"
  4019. "end_addr_high=0x%08x end_addr_low="
  4020. "0x%08x has crossed 4G boundary\n",
  4021. start_addr, sata_cmd.len,
  4022. end_addr_high, end_addr_low));
  4023. pm8001_chip_make_sg(task->scatter, 1,
  4024. ccb->buf_prd);
  4025. phys_addr = ccb->ccb_dma_handle +
  4026. offsetof(struct pm8001_ccb_info,
  4027. buf_prd[0]);
  4028. sata_cmd.addr_low =
  4029. lower_32_bits(phys_addr);
  4030. sata_cmd.addr_high =
  4031. upper_32_bits(phys_addr);
  4032. sata_cmd.esgl = cpu_to_le32(1 << 31);
  4033. }
  4034. } else if (task->num_scatter == 0) {
  4035. sata_cmd.addr_low = 0;
  4036. sata_cmd.addr_high = 0;
  4037. sata_cmd.len = cpu_to_le32(task->total_xfer_len);
  4038. sata_cmd.esgl = 0;
  4039. }
  4040. /* scsi cdb */
  4041. sata_cmd.atapi_scsi_cdb[0] =
  4042. cpu_to_le32(((task->ata_task.atapi_packet[0]) |
  4043. (task->ata_task.atapi_packet[1] << 8) |
  4044. (task->ata_task.atapi_packet[2] << 16) |
  4045. (task->ata_task.atapi_packet[3] << 24)));
  4046. sata_cmd.atapi_scsi_cdb[1] =
  4047. cpu_to_le32(((task->ata_task.atapi_packet[4]) |
  4048. (task->ata_task.atapi_packet[5] << 8) |
  4049. (task->ata_task.atapi_packet[6] << 16) |
  4050. (task->ata_task.atapi_packet[7] << 24)));
  4051. sata_cmd.atapi_scsi_cdb[2] =
  4052. cpu_to_le32(((task->ata_task.atapi_packet[8]) |
  4053. (task->ata_task.atapi_packet[9] << 8) |
  4054. (task->ata_task.atapi_packet[10] << 16) |
  4055. (task->ata_task.atapi_packet[11] << 24)));
  4056. sata_cmd.atapi_scsi_cdb[3] =
  4057. cpu_to_le32(((task->ata_task.atapi_packet[12]) |
  4058. (task->ata_task.atapi_packet[13] << 8) |
  4059. (task->ata_task.atapi_packet[14] << 16) |
  4060. (task->ata_task.atapi_packet[15] << 24)));
  4061. }
  4062. /* Check for read log for failed drive and return */
  4063. if (sata_cmd.sata_fis.command == 0x2f) {
  4064. if (pm8001_ha_dev && ((pm8001_ha_dev->id & NCQ_READ_LOG_FLAG) ||
  4065. (pm8001_ha_dev->id & NCQ_ABORT_ALL_FLAG) ||
  4066. (pm8001_ha_dev->id & NCQ_2ND_RLE_FLAG))) {
  4067. struct task_status_struct *ts;
  4068. pm8001_ha_dev->id &= 0xDFFFFFFF;
  4069. ts = &task->task_status;
  4070. spin_lock_irqsave(&task->task_state_lock, flags);
  4071. ts->resp = SAS_TASK_COMPLETE;
  4072. ts->stat = SAM_STAT_GOOD;
  4073. task->task_state_flags &= ~SAS_TASK_STATE_PENDING;
  4074. task->task_state_flags &= ~SAS_TASK_AT_INITIATOR;
  4075. task->task_state_flags |= SAS_TASK_STATE_DONE;
  4076. if (unlikely((task->task_state_flags &
  4077. SAS_TASK_STATE_ABORTED))) {
  4078. spin_unlock_irqrestore(&task->task_state_lock,
  4079. flags);
  4080. PM8001_FAIL_DBG(pm8001_ha,
  4081. pm8001_printk("task 0x%p resp 0x%x "
  4082. " stat 0x%x but aborted by upper layer "
  4083. "\n", task, ts->resp, ts->stat));
  4084. pm8001_ccb_task_free(pm8001_ha, task, ccb, tag);
  4085. return 0;
  4086. } else {
  4087. spin_unlock_irqrestore(&task->task_state_lock,
  4088. flags);
  4089. pm8001_ccb_task_free_done(pm8001_ha, task,
  4090. ccb, tag);
  4091. return 0;
  4092. }
  4093. }
  4094. }
  4095. q_index = (u32) (pm8001_ha_dev->id & 0x00ffffff) % PM8001_MAX_OUTB_NUM;
  4096. ret = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc,
  4097. &sata_cmd, q_index);
  4098. return ret;
  4099. }
  4100. /**
  4101. * pm80xx_chip_phy_start_req - start phy via PHY_START COMMAND
  4102. * @pm8001_ha: our hba card information.
  4103. * @num: the inbound queue number
  4104. * @phy_id: the phy id which we wanted to start up.
  4105. */
  4106. static int
  4107. pm80xx_chip_phy_start_req(struct pm8001_hba_info *pm8001_ha, u8 phy_id)
  4108. {
  4109. struct phy_start_req payload;
  4110. struct inbound_queue_table *circularQ;
  4111. int ret;
  4112. u32 tag = 0x01;
  4113. u32 opcode = OPC_INB_PHYSTART;
  4114. circularQ = &pm8001_ha->inbnd_q_tbl[0];
  4115. memset(&payload, 0, sizeof(payload));
  4116. payload.tag = cpu_to_le32(tag);
  4117. PM8001_INIT_DBG(pm8001_ha,
  4118. pm8001_printk("PHY START REQ for phy_id %d\n", phy_id));
  4119. /*
  4120. ** [0:7] PHY Identifier
  4121. ** [8:11] link rate 1.5G, 3G, 6G
  4122. ** [12:13] link mode 01b SAS mode; 10b SATA mode; 11b Auto mode
  4123. ** [14] 0b disable spin up hold; 1b enable spin up hold
  4124. ** [15] ob no change in current PHY analig setup 1b enable using SPAST
  4125. */
  4126. if (!IS_SPCV_12G(pm8001_ha->pdev))
  4127. payload.ase_sh_lm_slr_phyid = cpu_to_le32(SPINHOLD_DISABLE |
  4128. LINKMODE_AUTO | LINKRATE_15 |
  4129. LINKRATE_30 | LINKRATE_60 | phy_id);
  4130. else
  4131. payload.ase_sh_lm_slr_phyid = cpu_to_le32(SPINHOLD_DISABLE |
  4132. LINKMODE_AUTO | LINKRATE_15 |
  4133. LINKRATE_30 | LINKRATE_60 | LINKRATE_120 |
  4134. phy_id);
  4135. /* SSC Disable and SAS Analog ST configuration */
  4136. /**
  4137. payload.ase_sh_lm_slr_phyid =
  4138. cpu_to_le32(SSC_DISABLE_30 | SAS_ASE | SPINHOLD_DISABLE |
  4139. LINKMODE_AUTO | LINKRATE_15 | LINKRATE_30 | LINKRATE_60 |
  4140. phy_id);
  4141. Have to add "SAS PHY Analog Setup SPASTI 1 Byte" Based on need
  4142. **/
  4143. payload.sas_identify.dev_type = SAS_END_DEVICE;
  4144. payload.sas_identify.initiator_bits = SAS_PROTOCOL_ALL;
  4145. memcpy(payload.sas_identify.sas_addr,
  4146. pm8001_ha->sas_addr, SAS_ADDR_SIZE);
  4147. payload.sas_identify.phy_id = phy_id;
  4148. ret = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opcode, &payload, 0);
  4149. return ret;
  4150. }
  4151. /**
  4152. * pm8001_chip_phy_stop_req - start phy via PHY_STOP COMMAND
  4153. * @pm8001_ha: our hba card information.
  4154. * @num: the inbound queue number
  4155. * @phy_id: the phy id which we wanted to start up.
  4156. */
  4157. static int pm80xx_chip_phy_stop_req(struct pm8001_hba_info *pm8001_ha,
  4158. u8 phy_id)
  4159. {
  4160. struct phy_stop_req payload;
  4161. struct inbound_queue_table *circularQ;
  4162. int ret;
  4163. u32 tag = 0x01;
  4164. u32 opcode = OPC_INB_PHYSTOP;
  4165. circularQ = &pm8001_ha->inbnd_q_tbl[0];
  4166. memset(&payload, 0, sizeof(payload));
  4167. payload.tag = cpu_to_le32(tag);
  4168. payload.phy_id = cpu_to_le32(phy_id);
  4169. ret = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opcode, &payload, 0);
  4170. return ret;
  4171. }
  4172. /**
  4173. * see comments on pm8001_mpi_reg_resp.
  4174. */
  4175. static int pm80xx_chip_reg_dev_req(struct pm8001_hba_info *pm8001_ha,
  4176. struct pm8001_device *pm8001_dev, u32 flag)
  4177. {
  4178. struct reg_dev_req payload;
  4179. u32 opc;
  4180. u32 stp_sspsmp_sata = 0x4;
  4181. struct inbound_queue_table *circularQ;
  4182. u32 linkrate, phy_id;
  4183. int rc, tag = 0xdeadbeef;
  4184. struct pm8001_ccb_info *ccb;
  4185. u8 retryFlag = 0x1;
  4186. u16 firstBurstSize = 0;
  4187. u16 ITNT = 2000;
  4188. struct domain_device *dev = pm8001_dev->sas_device;
  4189. struct domain_device *parent_dev = dev->parent;
  4190. circularQ = &pm8001_ha->inbnd_q_tbl[0];
  4191. memset(&payload, 0, sizeof(payload));
  4192. rc = pm8001_tag_alloc(pm8001_ha, &tag);
  4193. if (rc)
  4194. return rc;
  4195. ccb = &pm8001_ha->ccb_info[tag];
  4196. ccb->device = pm8001_dev;
  4197. ccb->ccb_tag = tag;
  4198. payload.tag = cpu_to_le32(tag);
  4199. if (flag == 1) {
  4200. stp_sspsmp_sata = 0x02; /*direct attached sata */
  4201. } else {
  4202. if (pm8001_dev->dev_type == SAS_SATA_DEV)
  4203. stp_sspsmp_sata = 0x00; /* stp*/
  4204. else if (pm8001_dev->dev_type == SAS_END_DEVICE ||
  4205. pm8001_dev->dev_type == SAS_EDGE_EXPANDER_DEVICE ||
  4206. pm8001_dev->dev_type == SAS_FANOUT_EXPANDER_DEVICE)
  4207. stp_sspsmp_sata = 0x01; /*ssp or smp*/
  4208. }
  4209. if (parent_dev && DEV_IS_EXPANDER(parent_dev->dev_type))
  4210. phy_id = parent_dev->ex_dev.ex_phy->phy_id;
  4211. else
  4212. phy_id = pm8001_dev->attached_phy;
  4213. opc = OPC_INB_REG_DEV;
  4214. linkrate = (pm8001_dev->sas_device->linkrate < dev->port->linkrate) ?
  4215. pm8001_dev->sas_device->linkrate : dev->port->linkrate;
  4216. payload.phyid_portid =
  4217. cpu_to_le32(((pm8001_dev->sas_device->port->id) & 0xFF) |
  4218. ((phy_id & 0xFF) << 8));
  4219. payload.dtype_dlr_mcn_ir_retry = cpu_to_le32((retryFlag & 0x01) |
  4220. ((linkrate & 0x0F) << 24) |
  4221. ((stp_sspsmp_sata & 0x03) << 28));
  4222. payload.firstburstsize_ITNexustimeout =
  4223. cpu_to_le32(ITNT | (firstBurstSize * 0x10000));
  4224. memcpy(payload.sas_addr, pm8001_dev->sas_device->sas_addr,
  4225. SAS_ADDR_SIZE);
  4226. rc = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc, &payload, 0);
  4227. if (rc)
  4228. pm8001_tag_free(pm8001_ha, tag);
  4229. return rc;
  4230. }
  4231. /**
  4232. * pm80xx_chip_phy_ctl_req - support the local phy operation
  4233. * @pm8001_ha: our hba card information.
  4234. * @num: the inbound queue number
  4235. * @phy_id: the phy id which we wanted to operate
  4236. * @phy_op:
  4237. */
  4238. static int pm80xx_chip_phy_ctl_req(struct pm8001_hba_info *pm8001_ha,
  4239. u32 phyId, u32 phy_op)
  4240. {
  4241. struct local_phy_ctl_req payload;
  4242. struct inbound_queue_table *circularQ;
  4243. int ret;
  4244. u32 opc = OPC_INB_LOCAL_PHY_CONTROL;
  4245. memset(&payload, 0, sizeof(payload));
  4246. circularQ = &pm8001_ha->inbnd_q_tbl[0];
  4247. payload.tag = cpu_to_le32(1);
  4248. payload.phyop_phyid =
  4249. cpu_to_le32(((phy_op & 0xFF) << 8) | (phyId & 0xFF));
  4250. ret = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc, &payload, 0);
  4251. return ret;
  4252. }
  4253. static u32 pm80xx_chip_is_our_interupt(struct pm8001_hba_info *pm8001_ha)
  4254. {
  4255. u32 value;
  4256. #ifdef PM8001_USE_MSIX
  4257. return 1;
  4258. #endif
  4259. value = pm8001_cr32(pm8001_ha, 0, MSGU_ODR);
  4260. if (value)
  4261. return 1;
  4262. return 0;
  4263. }
  4264. /**
  4265. * pm8001_chip_isr - PM8001 isr handler.
  4266. * @pm8001_ha: our hba card information.
  4267. * @irq: irq number.
  4268. * @stat: stat.
  4269. */
  4270. static irqreturn_t
  4271. pm80xx_chip_isr(struct pm8001_hba_info *pm8001_ha, u8 vec)
  4272. {
  4273. pm80xx_chip_interrupt_disable(pm8001_ha, vec);
  4274. process_oq(pm8001_ha, vec);
  4275. pm80xx_chip_interrupt_enable(pm8001_ha, vec);
  4276. return IRQ_HANDLED;
  4277. }
  4278. void mpi_set_phy_profile_req(struct pm8001_hba_info *pm8001_ha,
  4279. u32 operation, u32 phyid, u32 length, u32 *buf)
  4280. {
  4281. u32 tag , i, j = 0;
  4282. int rc;
  4283. struct set_phy_profile_req payload;
  4284. struct inbound_queue_table *circularQ;
  4285. u32 opc = OPC_INB_SET_PHY_PROFILE;
  4286. memset(&payload, 0, sizeof(payload));
  4287. rc = pm8001_tag_alloc(pm8001_ha, &tag);
  4288. if (rc)
  4289. PM8001_FAIL_DBG(pm8001_ha, pm8001_printk("Invalid tag\n"));
  4290. circularQ = &pm8001_ha->inbnd_q_tbl[0];
  4291. payload.tag = cpu_to_le32(tag);
  4292. payload.ppc_phyid = (((operation & 0xF) << 8) | (phyid & 0xFF));
  4293. PM8001_INIT_DBG(pm8001_ha,
  4294. pm8001_printk(" phy profile command for phy %x ,length is %d\n",
  4295. payload.ppc_phyid, length));
  4296. for (i = length; i < (length + PHY_DWORD_LENGTH - 1); i++) {
  4297. payload.reserved[j] = cpu_to_le32(*((u32 *)buf + i));
  4298. j++;
  4299. }
  4300. rc = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc, &payload, 0);
  4301. if (rc)
  4302. pm8001_tag_free(pm8001_ha, tag);
  4303. }
  4304. void pm8001_set_phy_profile(struct pm8001_hba_info *pm8001_ha,
  4305. u32 length, u8 *buf)
  4306. {
  4307. u32 page_code, i;
  4308. page_code = SAS_PHY_ANALOG_SETTINGS_PAGE;
  4309. for (i = 0; i < pm8001_ha->chip->n_phy; i++) {
  4310. mpi_set_phy_profile_req(pm8001_ha,
  4311. SAS_PHY_ANALOG_SETTINGS_PAGE, i, length, (u32 *)buf);
  4312. length = length + PHY_DWORD_LENGTH;
  4313. }
  4314. PM8001_INIT_DBG(pm8001_ha, pm8001_printk("phy settings completed\n"));
  4315. }
  4316. void pm8001_set_phy_profile_single(struct pm8001_hba_info *pm8001_ha,
  4317. u32 phy, u32 length, u32 *buf)
  4318. {
  4319. u32 tag, opc;
  4320. int rc, i;
  4321. struct set_phy_profile_req payload;
  4322. struct inbound_queue_table *circularQ;
  4323. memset(&payload, 0, sizeof(payload));
  4324. rc = pm8001_tag_alloc(pm8001_ha, &tag);
  4325. if (rc)
  4326. PM8001_INIT_DBG(pm8001_ha, pm8001_printk("Invalid tag"));
  4327. circularQ = &pm8001_ha->inbnd_q_tbl[0];
  4328. opc = OPC_INB_SET_PHY_PROFILE;
  4329. payload.tag = cpu_to_le32(tag);
  4330. payload.ppc_phyid = (((SAS_PHY_ANALOG_SETTINGS_PAGE & 0xF) << 8)
  4331. | (phy & 0xFF));
  4332. for (i = 0; i < length; i++)
  4333. payload.reserved[i] = cpu_to_le32(*(buf + i));
  4334. rc = pm8001_mpi_build_cmd(pm8001_ha, circularQ, opc, &payload, 0);
  4335. if (rc)
  4336. pm8001_tag_free(pm8001_ha, tag);
  4337. PM8001_INIT_DBG(pm8001_ha,
  4338. pm8001_printk("PHY %d settings applied", phy));
  4339. }
  4340. const struct pm8001_dispatch pm8001_80xx_dispatch = {
  4341. .name = "pmc80xx",
  4342. .chip_init = pm80xx_chip_init,
  4343. .chip_soft_rst = pm80xx_chip_soft_rst,
  4344. .chip_rst = pm80xx_hw_chip_rst,
  4345. .chip_iounmap = pm8001_chip_iounmap,
  4346. .isr = pm80xx_chip_isr,
  4347. .is_our_interupt = pm80xx_chip_is_our_interupt,
  4348. .isr_process_oq = process_oq,
  4349. .interrupt_enable = pm80xx_chip_interrupt_enable,
  4350. .interrupt_disable = pm80xx_chip_interrupt_disable,
  4351. .make_prd = pm8001_chip_make_sg,
  4352. .smp_req = pm80xx_chip_smp_req,
  4353. .ssp_io_req = pm80xx_chip_ssp_io_req,
  4354. .sata_req = pm80xx_chip_sata_req,
  4355. .phy_start_req = pm80xx_chip_phy_start_req,
  4356. .phy_stop_req = pm80xx_chip_phy_stop_req,
  4357. .reg_dev_req = pm80xx_chip_reg_dev_req,
  4358. .dereg_dev_req = pm8001_chip_dereg_dev_req,
  4359. .phy_ctl_req = pm80xx_chip_phy_ctl_req,
  4360. .task_abort = pm8001_chip_abort_task,
  4361. .ssp_tm_req = pm8001_chip_ssp_tm_req,
  4362. .get_nvmd_req = pm8001_chip_get_nvmd_req,
  4363. .set_nvmd_req = pm8001_chip_set_nvmd_req,
  4364. .fw_flash_update_req = pm8001_chip_fw_flash_update_req,
  4365. .set_dev_state_req = pm8001_chip_set_dev_state_req,
  4366. };