ipr.c 167 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257
  1. /*
  2. * ipr.c -- driver for IBM Power Linux RAID adapters
  3. *
  4. * Written By: Brian King <brking@us.ibm.com>, IBM Corporation
  5. *
  6. * Copyright (C) 2003, 2004 IBM Corporation
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  21. *
  22. */
  23. /*
  24. * Notes:
  25. *
  26. * This driver is used to control the following SCSI adapters:
  27. *
  28. * IBM iSeries: 5702, 5703, 2780, 5709, 570A, 570B
  29. *
  30. * IBM pSeries: PCI-X Dual Channel Ultra 320 SCSI RAID Adapter
  31. * PCI-X Dual Channel Ultra 320 SCSI Adapter
  32. * PCI-X Dual Channel Ultra 320 SCSI RAID Enablement Card
  33. * Embedded SCSI adapter on p615 and p655 systems
  34. *
  35. * Supported Hardware Features:
  36. * - Ultra 320 SCSI controller
  37. * - PCI-X host interface
  38. * - Embedded PowerPC RISC Processor and Hardware XOR DMA Engine
  39. * - Non-Volatile Write Cache
  40. * - Supports attachment of non-RAID disks, tape, and optical devices
  41. * - RAID Levels 0, 5, 10
  42. * - Hot spare
  43. * - Background Parity Checking
  44. * - Background Data Scrubbing
  45. * - Ability to increase the capacity of an existing RAID 5 disk array
  46. * by adding disks
  47. *
  48. * Driver Features:
  49. * - Tagged command queuing
  50. * - Adapter microcode download
  51. * - PCI hot plug
  52. * - SCSI device hot plug
  53. *
  54. */
  55. #include <linux/config.h>
  56. #include <linux/fs.h>
  57. #include <linux/init.h>
  58. #include <linux/types.h>
  59. #include <linux/errno.h>
  60. #include <linux/kernel.h>
  61. #include <linux/ioport.h>
  62. #include <linux/delay.h>
  63. #include <linux/pci.h>
  64. #include <linux/wait.h>
  65. #include <linux/spinlock.h>
  66. #include <linux/sched.h>
  67. #include <linux/interrupt.h>
  68. #include <linux/blkdev.h>
  69. #include <linux/firmware.h>
  70. #include <linux/module.h>
  71. #include <linux/moduleparam.h>
  72. #include <asm/io.h>
  73. #include <asm/irq.h>
  74. #include <asm/processor.h>
  75. #include <scsi/scsi.h>
  76. #include <scsi/scsi_host.h>
  77. #include <scsi/scsi_tcq.h>
  78. #include <scsi/scsi_eh.h>
  79. #include <scsi/scsi_cmnd.h>
  80. #include <scsi/scsi_request.h>
  81. #include "ipr.h"
  82. /*
  83. * Global Data
  84. */
  85. static struct list_head ipr_ioa_head = LIST_HEAD_INIT(ipr_ioa_head);
  86. static unsigned int ipr_log_level = IPR_DEFAULT_LOG_LEVEL;
  87. static unsigned int ipr_max_speed = 1;
  88. static int ipr_testmode = 0;
  89. static unsigned int ipr_fastfail = 0;
  90. static unsigned int ipr_transop_timeout = IPR_OPERATIONAL_TIMEOUT;
  91. static unsigned int ipr_enable_cache = 1;
  92. static DEFINE_SPINLOCK(ipr_driver_lock);
  93. /* This table describes the differences between DMA controller chips */
  94. static const struct ipr_chip_cfg_t ipr_chip_cfg[] = {
  95. { /* Gemstone and Citrine */
  96. .mailbox = 0x0042C,
  97. .cache_line_size = 0x20,
  98. {
  99. .set_interrupt_mask_reg = 0x0022C,
  100. .clr_interrupt_mask_reg = 0x00230,
  101. .sense_interrupt_mask_reg = 0x0022C,
  102. .clr_interrupt_reg = 0x00228,
  103. .sense_interrupt_reg = 0x00224,
  104. .ioarrin_reg = 0x00404,
  105. .sense_uproc_interrupt_reg = 0x00214,
  106. .set_uproc_interrupt_reg = 0x00214,
  107. .clr_uproc_interrupt_reg = 0x00218
  108. }
  109. },
  110. { /* Snipe and Scamp */
  111. .mailbox = 0x0052C,
  112. .cache_line_size = 0x20,
  113. {
  114. .set_interrupt_mask_reg = 0x00288,
  115. .clr_interrupt_mask_reg = 0x0028C,
  116. .sense_interrupt_mask_reg = 0x00288,
  117. .clr_interrupt_reg = 0x00284,
  118. .sense_interrupt_reg = 0x00280,
  119. .ioarrin_reg = 0x00504,
  120. .sense_uproc_interrupt_reg = 0x00290,
  121. .set_uproc_interrupt_reg = 0x00290,
  122. .clr_uproc_interrupt_reg = 0x00294
  123. }
  124. },
  125. };
  126. static const struct ipr_chip_t ipr_chip[] = {
  127. { PCI_VENDOR_ID_MYLEX, PCI_DEVICE_ID_IBM_GEMSTONE, &ipr_chip_cfg[0] },
  128. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CITRINE, &ipr_chip_cfg[0] },
  129. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_SNIPE, &ipr_chip_cfg[1] },
  130. { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_SCAMP, &ipr_chip_cfg[1] }
  131. };
  132. static int ipr_max_bus_speeds [] = {
  133. IPR_80MBs_SCSI_RATE, IPR_U160_SCSI_RATE, IPR_U320_SCSI_RATE
  134. };
  135. MODULE_AUTHOR("Brian King <brking@us.ibm.com>");
  136. MODULE_DESCRIPTION("IBM Power RAID SCSI Adapter Driver");
  137. module_param_named(max_speed, ipr_max_speed, uint, 0);
  138. MODULE_PARM_DESC(max_speed, "Maximum bus speed (0-2). Default: 1=U160. Speeds: 0=80 MB/s, 1=U160, 2=U320");
  139. module_param_named(log_level, ipr_log_level, uint, 0);
  140. MODULE_PARM_DESC(log_level, "Set to 0 - 4 for increasing verbosity of device driver");
  141. module_param_named(testmode, ipr_testmode, int, 0);
  142. MODULE_PARM_DESC(testmode, "DANGEROUS!!! Allows unsupported configurations");
  143. module_param_named(fastfail, ipr_fastfail, int, 0);
  144. MODULE_PARM_DESC(fastfail, "Reduce timeouts and retries");
  145. module_param_named(transop_timeout, ipr_transop_timeout, int, 0);
  146. MODULE_PARM_DESC(transop_timeout, "Time in seconds to wait for adapter to come operational (default: 300)");
  147. module_param_named(enable_cache, ipr_enable_cache, int, 0);
  148. MODULE_PARM_DESC(enable_cache, "Enable adapter's non-volatile write cache (default: 1)");
  149. MODULE_LICENSE("GPL");
  150. MODULE_VERSION(IPR_DRIVER_VERSION);
  151. static const char *ipr_gpdd_dev_end_states[] = {
  152. "Command complete",
  153. "Terminated by host",
  154. "Terminated by device reset",
  155. "Terminated by bus reset",
  156. "Unknown",
  157. "Command not started"
  158. };
  159. static const char *ipr_gpdd_dev_bus_phases[] = {
  160. "Bus free",
  161. "Arbitration",
  162. "Selection",
  163. "Message out",
  164. "Command",
  165. "Message in",
  166. "Data out",
  167. "Data in",
  168. "Status",
  169. "Reselection",
  170. "Unknown"
  171. };
  172. /* A constant array of IOASCs/URCs/Error Messages */
  173. static const
  174. struct ipr_error_table_t ipr_error_table[] = {
  175. {0x00000000, 1, 1,
  176. "8155: An unknown error was received"},
  177. {0x00330000, 0, 0,
  178. "Soft underlength error"},
  179. {0x005A0000, 0, 0,
  180. "Command to be cancelled not found"},
  181. {0x00808000, 0, 0,
  182. "Qualified success"},
  183. {0x01080000, 1, 1,
  184. "FFFE: Soft device bus error recovered by the IOA"},
  185. {0x01170600, 0, 1,
  186. "FFF9: Device sector reassign successful"},
  187. {0x01170900, 0, 1,
  188. "FFF7: Media error recovered by device rewrite procedures"},
  189. {0x01180200, 0, 1,
  190. "7001: IOA sector reassignment successful"},
  191. {0x01180500, 0, 1,
  192. "FFF9: Soft media error. Sector reassignment recommended"},
  193. {0x01180600, 0, 1,
  194. "FFF7: Media error recovered by IOA rewrite procedures"},
  195. {0x01418000, 0, 1,
  196. "FF3D: Soft PCI bus error recovered by the IOA"},
  197. {0x01440000, 1, 1,
  198. "FFF6: Device hardware error recovered by the IOA"},
  199. {0x01448100, 0, 1,
  200. "FFF6: Device hardware error recovered by the device"},
  201. {0x01448200, 1, 1,
  202. "FF3D: Soft IOA error recovered by the IOA"},
  203. {0x01448300, 0, 1,
  204. "FFFA: Undefined device response recovered by the IOA"},
  205. {0x014A0000, 1, 1,
  206. "FFF6: Device bus error, message or command phase"},
  207. {0x015D0000, 0, 1,
  208. "FFF6: Failure prediction threshold exceeded"},
  209. {0x015D9200, 0, 1,
  210. "8009: Impending cache battery pack failure"},
  211. {0x02040400, 0, 0,
  212. "34FF: Disk device format in progress"},
  213. {0x023F0000, 0, 0,
  214. "Synchronization required"},
  215. {0x024E0000, 0, 0,
  216. "No ready, IOA shutdown"},
  217. {0x025A0000, 0, 0,
  218. "Not ready, IOA has been shutdown"},
  219. {0x02670100, 0, 1,
  220. "3020: Storage subsystem configuration error"},
  221. {0x03110B00, 0, 0,
  222. "FFF5: Medium error, data unreadable, recommend reassign"},
  223. {0x03110C00, 0, 0,
  224. "7000: Medium error, data unreadable, do not reassign"},
  225. {0x03310000, 0, 1,
  226. "FFF3: Disk media format bad"},
  227. {0x04050000, 0, 1,
  228. "3002: Addressed device failed to respond to selection"},
  229. {0x04080000, 1, 1,
  230. "3100: Device bus error"},
  231. {0x04080100, 0, 1,
  232. "3109: IOA timed out a device command"},
  233. {0x04088000, 0, 0,
  234. "3120: SCSI bus is not operational"},
  235. {0x04118000, 0, 1,
  236. "9000: IOA reserved area data check"},
  237. {0x04118100, 0, 1,
  238. "9001: IOA reserved area invalid data pattern"},
  239. {0x04118200, 0, 1,
  240. "9002: IOA reserved area LRC error"},
  241. {0x04320000, 0, 1,
  242. "102E: Out of alternate sectors for disk storage"},
  243. {0x04330000, 1, 1,
  244. "FFF4: Data transfer underlength error"},
  245. {0x04338000, 1, 1,
  246. "FFF4: Data transfer overlength error"},
  247. {0x043E0100, 0, 1,
  248. "3400: Logical unit failure"},
  249. {0x04408500, 0, 1,
  250. "FFF4: Device microcode is corrupt"},
  251. {0x04418000, 1, 1,
  252. "8150: PCI bus error"},
  253. {0x04430000, 1, 0,
  254. "Unsupported device bus message received"},
  255. {0x04440000, 1, 1,
  256. "FFF4: Disk device problem"},
  257. {0x04448200, 1, 1,
  258. "8150: Permanent IOA failure"},
  259. {0x04448300, 0, 1,
  260. "3010: Disk device returned wrong response to IOA"},
  261. {0x04448400, 0, 1,
  262. "8151: IOA microcode error"},
  263. {0x04448500, 0, 0,
  264. "Device bus status error"},
  265. {0x04448600, 0, 1,
  266. "8157: IOA error requiring IOA reset to recover"},
  267. {0x04490000, 0, 0,
  268. "Message reject received from the device"},
  269. {0x04449200, 0, 1,
  270. "8008: A permanent cache battery pack failure occurred"},
  271. {0x0444A000, 0, 1,
  272. "9090: Disk unit has been modified after the last known status"},
  273. {0x0444A200, 0, 1,
  274. "9081: IOA detected device error"},
  275. {0x0444A300, 0, 1,
  276. "9082: IOA detected device error"},
  277. {0x044A0000, 1, 1,
  278. "3110: Device bus error, message or command phase"},
  279. {0x04670400, 0, 1,
  280. "9091: Incorrect hardware configuration change has been detected"},
  281. {0x046E0000, 0, 1,
  282. "FFF4: Command to logical unit failed"},
  283. {0x05240000, 1, 0,
  284. "Illegal request, invalid request type or request packet"},
  285. {0x05250000, 0, 0,
  286. "Illegal request, invalid resource handle"},
  287. {0x05260000, 0, 0,
  288. "Illegal request, invalid field in parameter list"},
  289. {0x05260100, 0, 0,
  290. "Illegal request, parameter not supported"},
  291. {0x05260200, 0, 0,
  292. "Illegal request, parameter value invalid"},
  293. {0x052C0000, 0, 0,
  294. "Illegal request, command sequence error"},
  295. {0x06040500, 0, 1,
  296. "9031: Array protection temporarily suspended, protection resuming"},
  297. {0x06040600, 0, 1,
  298. "9040: Array protection temporarily suspended, protection resuming"},
  299. {0x06290000, 0, 1,
  300. "FFFB: SCSI bus was reset"},
  301. {0x06290500, 0, 0,
  302. "FFFE: SCSI bus transition to single ended"},
  303. {0x06290600, 0, 0,
  304. "FFFE: SCSI bus transition to LVD"},
  305. {0x06298000, 0, 1,
  306. "FFFB: SCSI bus was reset by another initiator"},
  307. {0x063F0300, 0, 1,
  308. "3029: A device replacement has occurred"},
  309. {0x064C8000, 0, 1,
  310. "9051: IOA cache data exists for a missing or failed device"},
  311. {0x06670100, 0, 1,
  312. "9025: Disk unit is not supported at its physical location"},
  313. {0x06670600, 0, 1,
  314. "3020: IOA detected a SCSI bus configuration error"},
  315. {0x06678000, 0, 1,
  316. "3150: SCSI bus configuration error"},
  317. {0x06690200, 0, 1,
  318. "9041: Array protection temporarily suspended"},
  319. {0x06698200, 0, 1,
  320. "9042: Corrupt array parity detected on specified device"},
  321. {0x066B0200, 0, 1,
  322. "9030: Array no longer protected due to missing or failed disk unit"},
  323. {0x066B8200, 0, 1,
  324. "9032: Array exposed but still protected"},
  325. {0x07270000, 0, 0,
  326. "Failure due to other device"},
  327. {0x07278000, 0, 1,
  328. "9008: IOA does not support functions expected by devices"},
  329. {0x07278100, 0, 1,
  330. "9010: Cache data associated with attached devices cannot be found"},
  331. {0x07278200, 0, 1,
  332. "9011: Cache data belongs to devices other than those attached"},
  333. {0x07278400, 0, 1,
  334. "9020: Array missing 2 or more devices with only 1 device present"},
  335. {0x07278500, 0, 1,
  336. "9021: Array missing 2 or more devices with 2 or more devices present"},
  337. {0x07278600, 0, 1,
  338. "9022: Exposed array is missing a required device"},
  339. {0x07278700, 0, 1,
  340. "9023: Array member(s) not at required physical locations"},
  341. {0x07278800, 0, 1,
  342. "9024: Array not functional due to present hardware configuration"},
  343. {0x07278900, 0, 1,
  344. "9026: Array not functional due to present hardware configuration"},
  345. {0x07278A00, 0, 1,
  346. "9027: Array is missing a device and parity is out of sync"},
  347. {0x07278B00, 0, 1,
  348. "9028: Maximum number of arrays already exist"},
  349. {0x07278C00, 0, 1,
  350. "9050: Required cache data cannot be located for a disk unit"},
  351. {0x07278D00, 0, 1,
  352. "9052: Cache data exists for a device that has been modified"},
  353. {0x07278F00, 0, 1,
  354. "9054: IOA resources not available due to previous problems"},
  355. {0x07279100, 0, 1,
  356. "9092: Disk unit requires initialization before use"},
  357. {0x07279200, 0, 1,
  358. "9029: Incorrect hardware configuration change has been detected"},
  359. {0x07279600, 0, 1,
  360. "9060: One or more disk pairs are missing from an array"},
  361. {0x07279700, 0, 1,
  362. "9061: One or more disks are missing from an array"},
  363. {0x07279800, 0, 1,
  364. "9062: One or more disks are missing from an array"},
  365. {0x07279900, 0, 1,
  366. "9063: Maximum number of functional arrays has been exceeded"},
  367. {0x0B260000, 0, 0,
  368. "Aborted command, invalid descriptor"},
  369. {0x0B5A0000, 0, 0,
  370. "Command terminated by host"}
  371. };
  372. static const struct ipr_ses_table_entry ipr_ses_table[] = {
  373. { "2104-DL1 ", "XXXXXXXXXXXXXXXX", 80 },
  374. { "2104-TL1 ", "XXXXXXXXXXXXXXXX", 80 },
  375. { "HSBP07M P U2SCSI", "XXXXXXXXXXXXXXXX", 80 }, /* Hidive 7 slot */
  376. { "HSBP05M P U2SCSI", "XXXXXXXXXXXXXXXX", 80 }, /* Hidive 5 slot */
  377. { "HSBP05M S U2SCSI", "XXXXXXXXXXXXXXXX", 80 }, /* Bowtie */
  378. { "HSBP06E ASU2SCSI", "XXXXXXXXXXXXXXXX", 80 }, /* MartinFenning */
  379. { "2104-DU3 ", "XXXXXXXXXXXXXXXX", 160 },
  380. { "2104-TU3 ", "XXXXXXXXXXXXXXXX", 160 },
  381. { "HSBP04C RSU2SCSI", "XXXXXXX*XXXXXXXX", 160 },
  382. { "HSBP06E RSU2SCSI", "XXXXXXX*XXXXXXXX", 160 },
  383. { "St V1S2 ", "XXXXXXXXXXXXXXXX", 160 },
  384. { "HSBPD4M PU3SCSI", "XXXXXXX*XXXXXXXX", 160 },
  385. { "VSBPD1H U3SCSI", "XXXXXXX*XXXXXXXX", 160 }
  386. };
  387. /*
  388. * Function Prototypes
  389. */
  390. static int ipr_reset_alert(struct ipr_cmnd *);
  391. static void ipr_process_ccn(struct ipr_cmnd *);
  392. static void ipr_process_error(struct ipr_cmnd *);
  393. static void ipr_reset_ioa_job(struct ipr_cmnd *);
  394. static void ipr_initiate_ioa_reset(struct ipr_ioa_cfg *,
  395. enum ipr_shutdown_type);
  396. #ifdef CONFIG_SCSI_IPR_TRACE
  397. /**
  398. * ipr_trc_hook - Add a trace entry to the driver trace
  399. * @ipr_cmd: ipr command struct
  400. * @type: trace type
  401. * @add_data: additional data
  402. *
  403. * Return value:
  404. * none
  405. **/
  406. static void ipr_trc_hook(struct ipr_cmnd *ipr_cmd,
  407. u8 type, u32 add_data)
  408. {
  409. struct ipr_trace_entry *trace_entry;
  410. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  411. trace_entry = &ioa_cfg->trace[ioa_cfg->trace_index++];
  412. trace_entry->time = jiffies;
  413. trace_entry->op_code = ipr_cmd->ioarcb.cmd_pkt.cdb[0];
  414. trace_entry->type = type;
  415. trace_entry->cmd_index = ipr_cmd->cmd_index;
  416. trace_entry->res_handle = ipr_cmd->ioarcb.res_handle;
  417. trace_entry->u.add_data = add_data;
  418. }
  419. #else
  420. #define ipr_trc_hook(ipr_cmd, type, add_data) do { } while(0)
  421. #endif
  422. /**
  423. * ipr_reinit_ipr_cmnd - Re-initialize an IPR Cmnd block for reuse
  424. * @ipr_cmd: ipr command struct
  425. *
  426. * Return value:
  427. * none
  428. **/
  429. static void ipr_reinit_ipr_cmnd(struct ipr_cmnd *ipr_cmd)
  430. {
  431. struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
  432. struct ipr_ioasa *ioasa = &ipr_cmd->ioasa;
  433. memset(&ioarcb->cmd_pkt, 0, sizeof(struct ipr_cmd_pkt));
  434. ioarcb->write_data_transfer_length = 0;
  435. ioarcb->read_data_transfer_length = 0;
  436. ioarcb->write_ioadl_len = 0;
  437. ioarcb->read_ioadl_len = 0;
  438. ioasa->ioasc = 0;
  439. ioasa->residual_data_len = 0;
  440. ipr_cmd->scsi_cmd = NULL;
  441. ipr_cmd->sense_buffer[0] = 0;
  442. ipr_cmd->dma_use_sg = 0;
  443. }
  444. /**
  445. * ipr_init_ipr_cmnd - Initialize an IPR Cmnd block
  446. * @ipr_cmd: ipr command struct
  447. *
  448. * Return value:
  449. * none
  450. **/
  451. static void ipr_init_ipr_cmnd(struct ipr_cmnd *ipr_cmd)
  452. {
  453. ipr_reinit_ipr_cmnd(ipr_cmd);
  454. ipr_cmd->u.scratch = 0;
  455. ipr_cmd->sibling = NULL;
  456. init_timer(&ipr_cmd->timer);
  457. }
  458. /**
  459. * ipr_get_free_ipr_cmnd - Get a free IPR Cmnd block
  460. * @ioa_cfg: ioa config struct
  461. *
  462. * Return value:
  463. * pointer to ipr command struct
  464. **/
  465. static
  466. struct ipr_cmnd *ipr_get_free_ipr_cmnd(struct ipr_ioa_cfg *ioa_cfg)
  467. {
  468. struct ipr_cmnd *ipr_cmd;
  469. ipr_cmd = list_entry(ioa_cfg->free_q.next, struct ipr_cmnd, queue);
  470. list_del(&ipr_cmd->queue);
  471. ipr_init_ipr_cmnd(ipr_cmd);
  472. return ipr_cmd;
  473. }
  474. /**
  475. * ipr_unmap_sglist - Unmap scatterlist if mapped
  476. * @ioa_cfg: ioa config struct
  477. * @ipr_cmd: ipr command struct
  478. *
  479. * Return value:
  480. * nothing
  481. **/
  482. static void ipr_unmap_sglist(struct ipr_ioa_cfg *ioa_cfg,
  483. struct ipr_cmnd *ipr_cmd)
  484. {
  485. struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
  486. if (ipr_cmd->dma_use_sg) {
  487. if (scsi_cmd->use_sg > 0) {
  488. pci_unmap_sg(ioa_cfg->pdev, scsi_cmd->request_buffer,
  489. scsi_cmd->use_sg,
  490. scsi_cmd->sc_data_direction);
  491. } else {
  492. pci_unmap_single(ioa_cfg->pdev, ipr_cmd->dma_handle,
  493. scsi_cmd->request_bufflen,
  494. scsi_cmd->sc_data_direction);
  495. }
  496. }
  497. }
  498. /**
  499. * ipr_mask_and_clear_interrupts - Mask all and clear specified interrupts
  500. * @ioa_cfg: ioa config struct
  501. * @clr_ints: interrupts to clear
  502. *
  503. * This function masks all interrupts on the adapter, then clears the
  504. * interrupts specified in the mask
  505. *
  506. * Return value:
  507. * none
  508. **/
  509. static void ipr_mask_and_clear_interrupts(struct ipr_ioa_cfg *ioa_cfg,
  510. u32 clr_ints)
  511. {
  512. volatile u32 int_reg;
  513. /* Stop new interrupts */
  514. ioa_cfg->allow_interrupts = 0;
  515. /* Set interrupt mask to stop all new interrupts */
  516. writel(~0, ioa_cfg->regs.set_interrupt_mask_reg);
  517. /* Clear any pending interrupts */
  518. writel(clr_ints, ioa_cfg->regs.clr_interrupt_reg);
  519. int_reg = readl(ioa_cfg->regs.sense_interrupt_reg);
  520. }
  521. /**
  522. * ipr_save_pcix_cmd_reg - Save PCI-X command register
  523. * @ioa_cfg: ioa config struct
  524. *
  525. * Return value:
  526. * 0 on success / -EIO on failure
  527. **/
  528. static int ipr_save_pcix_cmd_reg(struct ipr_ioa_cfg *ioa_cfg)
  529. {
  530. int pcix_cmd_reg = pci_find_capability(ioa_cfg->pdev, PCI_CAP_ID_PCIX);
  531. if (pcix_cmd_reg == 0) {
  532. dev_err(&ioa_cfg->pdev->dev, "Failed to save PCI-X command register\n");
  533. return -EIO;
  534. }
  535. if (pci_read_config_word(ioa_cfg->pdev, pcix_cmd_reg + PCI_X_CMD,
  536. &ioa_cfg->saved_pcix_cmd_reg) != PCIBIOS_SUCCESSFUL) {
  537. dev_err(&ioa_cfg->pdev->dev, "Failed to save PCI-X command register\n");
  538. return -EIO;
  539. }
  540. ioa_cfg->saved_pcix_cmd_reg |= PCI_X_CMD_DPERR_E | PCI_X_CMD_ERO;
  541. return 0;
  542. }
  543. /**
  544. * ipr_set_pcix_cmd_reg - Setup PCI-X command register
  545. * @ioa_cfg: ioa config struct
  546. *
  547. * Return value:
  548. * 0 on success / -EIO on failure
  549. **/
  550. static int ipr_set_pcix_cmd_reg(struct ipr_ioa_cfg *ioa_cfg)
  551. {
  552. int pcix_cmd_reg = pci_find_capability(ioa_cfg->pdev, PCI_CAP_ID_PCIX);
  553. if (pcix_cmd_reg) {
  554. if (pci_write_config_word(ioa_cfg->pdev, pcix_cmd_reg + PCI_X_CMD,
  555. ioa_cfg->saved_pcix_cmd_reg) != PCIBIOS_SUCCESSFUL) {
  556. dev_err(&ioa_cfg->pdev->dev, "Failed to setup PCI-X command register\n");
  557. return -EIO;
  558. }
  559. } else {
  560. dev_err(&ioa_cfg->pdev->dev,
  561. "Failed to setup PCI-X command register\n");
  562. return -EIO;
  563. }
  564. return 0;
  565. }
  566. /**
  567. * ipr_scsi_eh_done - mid-layer done function for aborted ops
  568. * @ipr_cmd: ipr command struct
  569. *
  570. * This function is invoked by the interrupt handler for
  571. * ops generated by the SCSI mid-layer which are being aborted.
  572. *
  573. * Return value:
  574. * none
  575. **/
  576. static void ipr_scsi_eh_done(struct ipr_cmnd *ipr_cmd)
  577. {
  578. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  579. struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
  580. scsi_cmd->result |= (DID_ERROR << 16);
  581. ipr_unmap_sglist(ioa_cfg, ipr_cmd);
  582. scsi_cmd->scsi_done(scsi_cmd);
  583. list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
  584. }
  585. /**
  586. * ipr_fail_all_ops - Fails all outstanding ops.
  587. * @ioa_cfg: ioa config struct
  588. *
  589. * This function fails all outstanding ops.
  590. *
  591. * Return value:
  592. * none
  593. **/
  594. static void ipr_fail_all_ops(struct ipr_ioa_cfg *ioa_cfg)
  595. {
  596. struct ipr_cmnd *ipr_cmd, *temp;
  597. ENTER;
  598. list_for_each_entry_safe(ipr_cmd, temp, &ioa_cfg->pending_q, queue) {
  599. list_del(&ipr_cmd->queue);
  600. ipr_cmd->ioasa.ioasc = cpu_to_be32(IPR_IOASC_IOA_WAS_RESET);
  601. ipr_cmd->ioasa.ilid = cpu_to_be32(IPR_DRIVER_ILID);
  602. if (ipr_cmd->scsi_cmd)
  603. ipr_cmd->done = ipr_scsi_eh_done;
  604. ipr_trc_hook(ipr_cmd, IPR_TRACE_FINISH, IPR_IOASC_IOA_WAS_RESET);
  605. del_timer(&ipr_cmd->timer);
  606. ipr_cmd->done(ipr_cmd);
  607. }
  608. LEAVE;
  609. }
  610. /**
  611. * ipr_do_req - Send driver initiated requests.
  612. * @ipr_cmd: ipr command struct
  613. * @done: done function
  614. * @timeout_func: timeout function
  615. * @timeout: timeout value
  616. *
  617. * This function sends the specified command to the adapter with the
  618. * timeout given. The done function is invoked on command completion.
  619. *
  620. * Return value:
  621. * none
  622. **/
  623. static void ipr_do_req(struct ipr_cmnd *ipr_cmd,
  624. void (*done) (struct ipr_cmnd *),
  625. void (*timeout_func) (struct ipr_cmnd *), u32 timeout)
  626. {
  627. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  628. list_add_tail(&ipr_cmd->queue, &ioa_cfg->pending_q);
  629. ipr_cmd->done = done;
  630. ipr_cmd->timer.data = (unsigned long) ipr_cmd;
  631. ipr_cmd->timer.expires = jiffies + timeout;
  632. ipr_cmd->timer.function = (void (*)(unsigned long))timeout_func;
  633. add_timer(&ipr_cmd->timer);
  634. ipr_trc_hook(ipr_cmd, IPR_TRACE_START, 0);
  635. mb();
  636. writel(be32_to_cpu(ipr_cmd->ioarcb.ioarcb_host_pci_addr),
  637. ioa_cfg->regs.ioarrin_reg);
  638. }
  639. /**
  640. * ipr_internal_cmd_done - Op done function for an internally generated op.
  641. * @ipr_cmd: ipr command struct
  642. *
  643. * This function is the op done function for an internally generated,
  644. * blocking op. It simply wakes the sleeping thread.
  645. *
  646. * Return value:
  647. * none
  648. **/
  649. static void ipr_internal_cmd_done(struct ipr_cmnd *ipr_cmd)
  650. {
  651. if (ipr_cmd->sibling)
  652. ipr_cmd->sibling = NULL;
  653. else
  654. complete(&ipr_cmd->completion);
  655. }
  656. /**
  657. * ipr_send_blocking_cmd - Send command and sleep on its completion.
  658. * @ipr_cmd: ipr command struct
  659. * @timeout_func: function to invoke if command times out
  660. * @timeout: timeout
  661. *
  662. * Return value:
  663. * none
  664. **/
  665. static void ipr_send_blocking_cmd(struct ipr_cmnd *ipr_cmd,
  666. void (*timeout_func) (struct ipr_cmnd *ipr_cmd),
  667. u32 timeout)
  668. {
  669. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  670. init_completion(&ipr_cmd->completion);
  671. ipr_do_req(ipr_cmd, ipr_internal_cmd_done, timeout_func, timeout);
  672. spin_unlock_irq(ioa_cfg->host->host_lock);
  673. wait_for_completion(&ipr_cmd->completion);
  674. spin_lock_irq(ioa_cfg->host->host_lock);
  675. }
  676. /**
  677. * ipr_send_hcam - Send an HCAM to the adapter.
  678. * @ioa_cfg: ioa config struct
  679. * @type: HCAM type
  680. * @hostrcb: hostrcb struct
  681. *
  682. * This function will send a Host Controlled Async command to the adapter.
  683. * If HCAMs are currently not allowed to be issued to the adapter, it will
  684. * place the hostrcb on the free queue.
  685. *
  686. * Return value:
  687. * none
  688. **/
  689. static void ipr_send_hcam(struct ipr_ioa_cfg *ioa_cfg, u8 type,
  690. struct ipr_hostrcb *hostrcb)
  691. {
  692. struct ipr_cmnd *ipr_cmd;
  693. struct ipr_ioarcb *ioarcb;
  694. if (ioa_cfg->allow_cmds) {
  695. ipr_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
  696. list_add_tail(&ipr_cmd->queue, &ioa_cfg->pending_q);
  697. list_add_tail(&hostrcb->queue, &ioa_cfg->hostrcb_pending_q);
  698. ipr_cmd->u.hostrcb = hostrcb;
  699. ioarcb = &ipr_cmd->ioarcb;
  700. ioarcb->res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
  701. ioarcb->cmd_pkt.request_type = IPR_RQTYPE_HCAM;
  702. ioarcb->cmd_pkt.cdb[0] = IPR_HOST_CONTROLLED_ASYNC;
  703. ioarcb->cmd_pkt.cdb[1] = type;
  704. ioarcb->cmd_pkt.cdb[7] = (sizeof(hostrcb->hcam) >> 8) & 0xff;
  705. ioarcb->cmd_pkt.cdb[8] = sizeof(hostrcb->hcam) & 0xff;
  706. ioarcb->read_data_transfer_length = cpu_to_be32(sizeof(hostrcb->hcam));
  707. ioarcb->read_ioadl_len = cpu_to_be32(sizeof(struct ipr_ioadl_desc));
  708. ipr_cmd->ioadl[0].flags_and_data_len =
  709. cpu_to_be32(IPR_IOADL_FLAGS_READ_LAST | sizeof(hostrcb->hcam));
  710. ipr_cmd->ioadl[0].address = cpu_to_be32(hostrcb->hostrcb_dma);
  711. if (type == IPR_HCAM_CDB_OP_CODE_CONFIG_CHANGE)
  712. ipr_cmd->done = ipr_process_ccn;
  713. else
  714. ipr_cmd->done = ipr_process_error;
  715. ipr_trc_hook(ipr_cmd, IPR_TRACE_START, IPR_IOA_RES_ADDR);
  716. mb();
  717. writel(be32_to_cpu(ipr_cmd->ioarcb.ioarcb_host_pci_addr),
  718. ioa_cfg->regs.ioarrin_reg);
  719. } else {
  720. list_add_tail(&hostrcb->queue, &ioa_cfg->hostrcb_free_q);
  721. }
  722. }
  723. /**
  724. * ipr_init_res_entry - Initialize a resource entry struct.
  725. * @res: resource entry struct
  726. *
  727. * Return value:
  728. * none
  729. **/
  730. static void ipr_init_res_entry(struct ipr_resource_entry *res)
  731. {
  732. res->needs_sync_complete = 1;
  733. res->in_erp = 0;
  734. res->add_to_ml = 0;
  735. res->del_from_ml = 0;
  736. res->resetting_device = 0;
  737. res->sdev = NULL;
  738. }
  739. /**
  740. * ipr_handle_config_change - Handle a config change from the adapter
  741. * @ioa_cfg: ioa config struct
  742. * @hostrcb: hostrcb
  743. *
  744. * Return value:
  745. * none
  746. **/
  747. static void ipr_handle_config_change(struct ipr_ioa_cfg *ioa_cfg,
  748. struct ipr_hostrcb *hostrcb)
  749. {
  750. struct ipr_resource_entry *res = NULL;
  751. struct ipr_config_table_entry *cfgte;
  752. u32 is_ndn = 1;
  753. cfgte = &hostrcb->hcam.u.ccn.cfgte;
  754. list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
  755. if (!memcmp(&res->cfgte.res_addr, &cfgte->res_addr,
  756. sizeof(cfgte->res_addr))) {
  757. is_ndn = 0;
  758. break;
  759. }
  760. }
  761. if (is_ndn) {
  762. if (list_empty(&ioa_cfg->free_res_q)) {
  763. ipr_send_hcam(ioa_cfg,
  764. IPR_HCAM_CDB_OP_CODE_CONFIG_CHANGE,
  765. hostrcb);
  766. return;
  767. }
  768. res = list_entry(ioa_cfg->free_res_q.next,
  769. struct ipr_resource_entry, queue);
  770. list_del(&res->queue);
  771. ipr_init_res_entry(res);
  772. list_add_tail(&res->queue, &ioa_cfg->used_res_q);
  773. }
  774. memcpy(&res->cfgte, cfgte, sizeof(struct ipr_config_table_entry));
  775. if (hostrcb->hcam.notify_type == IPR_HOST_RCB_NOTIF_TYPE_REM_ENTRY) {
  776. if (res->sdev) {
  777. res->sdev->hostdata = NULL;
  778. res->del_from_ml = 1;
  779. if (ioa_cfg->allow_ml_add_del)
  780. schedule_work(&ioa_cfg->work_q);
  781. } else
  782. list_move_tail(&res->queue, &ioa_cfg->free_res_q);
  783. } else if (!res->sdev) {
  784. res->add_to_ml = 1;
  785. if (ioa_cfg->allow_ml_add_del)
  786. schedule_work(&ioa_cfg->work_q);
  787. }
  788. ipr_send_hcam(ioa_cfg, IPR_HCAM_CDB_OP_CODE_CONFIG_CHANGE, hostrcb);
  789. }
  790. /**
  791. * ipr_process_ccn - Op done function for a CCN.
  792. * @ipr_cmd: ipr command struct
  793. *
  794. * This function is the op done function for a configuration
  795. * change notification host controlled async from the adapter.
  796. *
  797. * Return value:
  798. * none
  799. **/
  800. static void ipr_process_ccn(struct ipr_cmnd *ipr_cmd)
  801. {
  802. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  803. struct ipr_hostrcb *hostrcb = ipr_cmd->u.hostrcb;
  804. u32 ioasc = be32_to_cpu(ipr_cmd->ioasa.ioasc);
  805. list_del(&hostrcb->queue);
  806. list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
  807. if (ioasc) {
  808. if (ioasc != IPR_IOASC_IOA_WAS_RESET)
  809. dev_err(&ioa_cfg->pdev->dev,
  810. "Host RCB failed with IOASC: 0x%08X\n", ioasc);
  811. ipr_send_hcam(ioa_cfg, IPR_HCAM_CDB_OP_CODE_CONFIG_CHANGE, hostrcb);
  812. } else {
  813. ipr_handle_config_change(ioa_cfg, hostrcb);
  814. }
  815. }
  816. /**
  817. * ipr_log_vpd - Log the passed VPD to the error log.
  818. * @vpd: vendor/product id/sn struct
  819. *
  820. * Return value:
  821. * none
  822. **/
  823. static void ipr_log_vpd(struct ipr_vpd *vpd)
  824. {
  825. char buffer[IPR_VENDOR_ID_LEN + IPR_PROD_ID_LEN
  826. + IPR_SERIAL_NUM_LEN];
  827. memcpy(buffer, vpd->vpids.vendor_id, IPR_VENDOR_ID_LEN);
  828. memcpy(buffer + IPR_VENDOR_ID_LEN, vpd->vpids.product_id,
  829. IPR_PROD_ID_LEN);
  830. buffer[IPR_VENDOR_ID_LEN + IPR_PROD_ID_LEN] = '\0';
  831. ipr_err("Vendor/Product ID: %s\n", buffer);
  832. memcpy(buffer, vpd->sn, IPR_SERIAL_NUM_LEN);
  833. buffer[IPR_SERIAL_NUM_LEN] = '\0';
  834. ipr_err(" Serial Number: %s\n", buffer);
  835. }
  836. /**
  837. * ipr_log_cache_error - Log a cache error.
  838. * @ioa_cfg: ioa config struct
  839. * @hostrcb: hostrcb struct
  840. *
  841. * Return value:
  842. * none
  843. **/
  844. static void ipr_log_cache_error(struct ipr_ioa_cfg *ioa_cfg,
  845. struct ipr_hostrcb *hostrcb)
  846. {
  847. struct ipr_hostrcb_type_02_error *error =
  848. &hostrcb->hcam.u.error.u.type_02_error;
  849. ipr_err("-----Current Configuration-----\n");
  850. ipr_err("Cache Directory Card Information:\n");
  851. ipr_log_vpd(&error->ioa_vpd);
  852. ipr_err("Adapter Card Information:\n");
  853. ipr_log_vpd(&error->cfc_vpd);
  854. ipr_err("-----Expected Configuration-----\n");
  855. ipr_err("Cache Directory Card Information:\n");
  856. ipr_log_vpd(&error->ioa_last_attached_to_cfc_vpd);
  857. ipr_err("Adapter Card Information:\n");
  858. ipr_log_vpd(&error->cfc_last_attached_to_ioa_vpd);
  859. ipr_err("Additional IOA Data: %08X %08X %08X\n",
  860. be32_to_cpu(error->ioa_data[0]),
  861. be32_to_cpu(error->ioa_data[1]),
  862. be32_to_cpu(error->ioa_data[2]));
  863. }
  864. /**
  865. * ipr_log_config_error - Log a configuration error.
  866. * @ioa_cfg: ioa config struct
  867. * @hostrcb: hostrcb struct
  868. *
  869. * Return value:
  870. * none
  871. **/
  872. static void ipr_log_config_error(struct ipr_ioa_cfg *ioa_cfg,
  873. struct ipr_hostrcb *hostrcb)
  874. {
  875. int errors_logged, i;
  876. struct ipr_hostrcb_device_data_entry *dev_entry;
  877. struct ipr_hostrcb_type_03_error *error;
  878. error = &hostrcb->hcam.u.error.u.type_03_error;
  879. errors_logged = be32_to_cpu(error->errors_logged);
  880. ipr_err("Device Errors Detected/Logged: %d/%d\n",
  881. be32_to_cpu(error->errors_detected), errors_logged);
  882. dev_entry = error->dev;
  883. for (i = 0; i < errors_logged; i++, dev_entry++) {
  884. ipr_err_separator;
  885. ipr_phys_res_err(ioa_cfg, dev_entry->dev_res_addr, "Device %d", i + 1);
  886. ipr_log_vpd(&dev_entry->vpd);
  887. ipr_err("-----New Device Information-----\n");
  888. ipr_log_vpd(&dev_entry->new_vpd);
  889. ipr_err("Cache Directory Card Information:\n");
  890. ipr_log_vpd(&dev_entry->ioa_last_with_dev_vpd);
  891. ipr_err("Adapter Card Information:\n");
  892. ipr_log_vpd(&dev_entry->cfc_last_with_dev_vpd);
  893. ipr_err("Additional IOA Data: %08X %08X %08X %08X %08X\n",
  894. be32_to_cpu(dev_entry->ioa_data[0]),
  895. be32_to_cpu(dev_entry->ioa_data[1]),
  896. be32_to_cpu(dev_entry->ioa_data[2]),
  897. be32_to_cpu(dev_entry->ioa_data[3]),
  898. be32_to_cpu(dev_entry->ioa_data[4]));
  899. }
  900. }
  901. /**
  902. * ipr_log_array_error - Log an array configuration error.
  903. * @ioa_cfg: ioa config struct
  904. * @hostrcb: hostrcb struct
  905. *
  906. * Return value:
  907. * none
  908. **/
  909. static void ipr_log_array_error(struct ipr_ioa_cfg *ioa_cfg,
  910. struct ipr_hostrcb *hostrcb)
  911. {
  912. int i;
  913. struct ipr_hostrcb_type_04_error *error;
  914. struct ipr_hostrcb_array_data_entry *array_entry;
  915. const u8 zero_sn[IPR_SERIAL_NUM_LEN] = { [0 ... IPR_SERIAL_NUM_LEN-1] = '0' };
  916. error = &hostrcb->hcam.u.error.u.type_04_error;
  917. ipr_err_separator;
  918. ipr_err("RAID %s Array Configuration: %d:%d:%d:%d\n",
  919. error->protection_level,
  920. ioa_cfg->host->host_no,
  921. error->last_func_vset_res_addr.bus,
  922. error->last_func_vset_res_addr.target,
  923. error->last_func_vset_res_addr.lun);
  924. ipr_err_separator;
  925. array_entry = error->array_member;
  926. for (i = 0; i < 18; i++) {
  927. if (!memcmp(array_entry->vpd.sn, zero_sn, IPR_SERIAL_NUM_LEN))
  928. continue;
  929. if (be32_to_cpu(error->exposed_mode_adn) == i)
  930. ipr_err("Exposed Array Member %d:\n", i);
  931. else
  932. ipr_err("Array Member %d:\n", i);
  933. ipr_log_vpd(&array_entry->vpd);
  934. ipr_phys_res_err(ioa_cfg, array_entry->dev_res_addr, "Current Location");
  935. ipr_phys_res_err(ioa_cfg, array_entry->expected_dev_res_addr,
  936. "Expected Location");
  937. ipr_err_separator;
  938. if (i == 9)
  939. array_entry = error->array_member2;
  940. else
  941. array_entry++;
  942. }
  943. }
  944. /**
  945. * ipr_log_generic_error - Log an adapter error.
  946. * @ioa_cfg: ioa config struct
  947. * @hostrcb: hostrcb struct
  948. *
  949. * Return value:
  950. * none
  951. **/
  952. static void ipr_log_generic_error(struct ipr_ioa_cfg *ioa_cfg,
  953. struct ipr_hostrcb *hostrcb)
  954. {
  955. int i;
  956. int ioa_data_len = be32_to_cpu(hostrcb->hcam.length);
  957. if (ioa_data_len == 0)
  958. return;
  959. for (i = 0; i < ioa_data_len / 4; i += 4) {
  960. ipr_err("%08X: %08X %08X %08X %08X\n", i*4,
  961. be32_to_cpu(hostrcb->hcam.u.raw.data[i]),
  962. be32_to_cpu(hostrcb->hcam.u.raw.data[i+1]),
  963. be32_to_cpu(hostrcb->hcam.u.raw.data[i+2]),
  964. be32_to_cpu(hostrcb->hcam.u.raw.data[i+3]));
  965. }
  966. }
  967. /**
  968. * ipr_get_error - Find the specfied IOASC in the ipr_error_table.
  969. * @ioasc: IOASC
  970. *
  971. * This function will return the index of into the ipr_error_table
  972. * for the specified IOASC. If the IOASC is not in the table,
  973. * 0 will be returned, which points to the entry used for unknown errors.
  974. *
  975. * Return value:
  976. * index into the ipr_error_table
  977. **/
  978. static u32 ipr_get_error(u32 ioasc)
  979. {
  980. int i;
  981. for (i = 0; i < ARRAY_SIZE(ipr_error_table); i++)
  982. if (ipr_error_table[i].ioasc == ioasc)
  983. return i;
  984. return 0;
  985. }
  986. /**
  987. * ipr_handle_log_data - Log an adapter error.
  988. * @ioa_cfg: ioa config struct
  989. * @hostrcb: hostrcb struct
  990. *
  991. * This function logs an adapter error to the system.
  992. *
  993. * Return value:
  994. * none
  995. **/
  996. static void ipr_handle_log_data(struct ipr_ioa_cfg *ioa_cfg,
  997. struct ipr_hostrcb *hostrcb)
  998. {
  999. u32 ioasc;
  1000. int error_index;
  1001. if (hostrcb->hcam.notify_type != IPR_HOST_RCB_NOTIF_TYPE_ERROR_LOG_ENTRY)
  1002. return;
  1003. if (hostrcb->hcam.notifications_lost == IPR_HOST_RCB_NOTIFICATIONS_LOST)
  1004. dev_err(&ioa_cfg->pdev->dev, "Error notifications lost\n");
  1005. ioasc = be32_to_cpu(hostrcb->hcam.u.error.failing_dev_ioasc);
  1006. if (ioasc == IPR_IOASC_BUS_WAS_RESET ||
  1007. ioasc == IPR_IOASC_BUS_WAS_RESET_BY_OTHER) {
  1008. /* Tell the midlayer we had a bus reset so it will handle the UA properly */
  1009. scsi_report_bus_reset(ioa_cfg->host,
  1010. hostrcb->hcam.u.error.failing_dev_res_addr.bus);
  1011. }
  1012. error_index = ipr_get_error(ioasc);
  1013. if (!ipr_error_table[error_index].log_hcam)
  1014. return;
  1015. if (ipr_is_device(&hostrcb->hcam.u.error.failing_dev_res_addr)) {
  1016. ipr_res_err(ioa_cfg, hostrcb->hcam.u.error.failing_dev_res_addr,
  1017. "%s\n", ipr_error_table[error_index].error);
  1018. } else {
  1019. dev_err(&ioa_cfg->pdev->dev, "%s\n",
  1020. ipr_error_table[error_index].error);
  1021. }
  1022. /* Set indication we have logged an error */
  1023. ioa_cfg->errors_logged++;
  1024. if (ioa_cfg->log_level < IPR_DEFAULT_LOG_LEVEL)
  1025. return;
  1026. if (be32_to_cpu(hostrcb->hcam.length) > sizeof(hostrcb->hcam.u.raw))
  1027. hostrcb->hcam.length = cpu_to_be32(sizeof(hostrcb->hcam.u.raw));
  1028. switch (hostrcb->hcam.overlay_id) {
  1029. case IPR_HOST_RCB_OVERLAY_ID_2:
  1030. ipr_log_cache_error(ioa_cfg, hostrcb);
  1031. break;
  1032. case IPR_HOST_RCB_OVERLAY_ID_3:
  1033. ipr_log_config_error(ioa_cfg, hostrcb);
  1034. break;
  1035. case IPR_HOST_RCB_OVERLAY_ID_4:
  1036. case IPR_HOST_RCB_OVERLAY_ID_6:
  1037. ipr_log_array_error(ioa_cfg, hostrcb);
  1038. break;
  1039. case IPR_HOST_RCB_OVERLAY_ID_1:
  1040. case IPR_HOST_RCB_OVERLAY_ID_DEFAULT:
  1041. default:
  1042. ipr_log_generic_error(ioa_cfg, hostrcb);
  1043. break;
  1044. }
  1045. }
  1046. /**
  1047. * ipr_process_error - Op done function for an adapter error log.
  1048. * @ipr_cmd: ipr command struct
  1049. *
  1050. * This function is the op done function for an error log host
  1051. * controlled async from the adapter. It will log the error and
  1052. * send the HCAM back to the adapter.
  1053. *
  1054. * Return value:
  1055. * none
  1056. **/
  1057. static void ipr_process_error(struct ipr_cmnd *ipr_cmd)
  1058. {
  1059. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  1060. struct ipr_hostrcb *hostrcb = ipr_cmd->u.hostrcb;
  1061. u32 ioasc = be32_to_cpu(ipr_cmd->ioasa.ioasc);
  1062. list_del(&hostrcb->queue);
  1063. list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
  1064. if (!ioasc) {
  1065. ipr_handle_log_data(ioa_cfg, hostrcb);
  1066. } else if (ioasc != IPR_IOASC_IOA_WAS_RESET) {
  1067. dev_err(&ioa_cfg->pdev->dev,
  1068. "Host RCB failed with IOASC: 0x%08X\n", ioasc);
  1069. }
  1070. ipr_send_hcam(ioa_cfg, IPR_HCAM_CDB_OP_CODE_LOG_DATA, hostrcb);
  1071. }
  1072. /**
  1073. * ipr_timeout - An internally generated op has timed out.
  1074. * @ipr_cmd: ipr command struct
  1075. *
  1076. * This function blocks host requests and initiates an
  1077. * adapter reset.
  1078. *
  1079. * Return value:
  1080. * none
  1081. **/
  1082. static void ipr_timeout(struct ipr_cmnd *ipr_cmd)
  1083. {
  1084. unsigned long lock_flags = 0;
  1085. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  1086. ENTER;
  1087. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  1088. ioa_cfg->errors_logged++;
  1089. dev_err(&ioa_cfg->pdev->dev,
  1090. "Adapter being reset due to command timeout.\n");
  1091. if (WAIT_FOR_DUMP == ioa_cfg->sdt_state)
  1092. ioa_cfg->sdt_state = GET_DUMP;
  1093. if (!ioa_cfg->in_reset_reload || ioa_cfg->reset_cmd == ipr_cmd)
  1094. ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
  1095. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  1096. LEAVE;
  1097. }
  1098. /**
  1099. * ipr_oper_timeout - Adapter timed out transitioning to operational
  1100. * @ipr_cmd: ipr command struct
  1101. *
  1102. * This function blocks host requests and initiates an
  1103. * adapter reset.
  1104. *
  1105. * Return value:
  1106. * none
  1107. **/
  1108. static void ipr_oper_timeout(struct ipr_cmnd *ipr_cmd)
  1109. {
  1110. unsigned long lock_flags = 0;
  1111. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  1112. ENTER;
  1113. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  1114. ioa_cfg->errors_logged++;
  1115. dev_err(&ioa_cfg->pdev->dev,
  1116. "Adapter timed out transitioning to operational.\n");
  1117. if (WAIT_FOR_DUMP == ioa_cfg->sdt_state)
  1118. ioa_cfg->sdt_state = GET_DUMP;
  1119. if (!ioa_cfg->in_reset_reload || ioa_cfg->reset_cmd == ipr_cmd) {
  1120. if (ipr_fastfail)
  1121. ioa_cfg->reset_retries += IPR_NUM_RESET_RELOAD_RETRIES;
  1122. ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
  1123. }
  1124. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  1125. LEAVE;
  1126. }
  1127. /**
  1128. * ipr_reset_reload - Reset/Reload the IOA
  1129. * @ioa_cfg: ioa config struct
  1130. * @shutdown_type: shutdown type
  1131. *
  1132. * This function resets the adapter and re-initializes it.
  1133. * This function assumes that all new host commands have been stopped.
  1134. * Return value:
  1135. * SUCCESS / FAILED
  1136. **/
  1137. static int ipr_reset_reload(struct ipr_ioa_cfg *ioa_cfg,
  1138. enum ipr_shutdown_type shutdown_type)
  1139. {
  1140. if (!ioa_cfg->in_reset_reload)
  1141. ipr_initiate_ioa_reset(ioa_cfg, shutdown_type);
  1142. spin_unlock_irq(ioa_cfg->host->host_lock);
  1143. wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
  1144. spin_lock_irq(ioa_cfg->host->host_lock);
  1145. /* If we got hit with a host reset while we were already resetting
  1146. the adapter for some reason, and the reset failed. */
  1147. if (ioa_cfg->ioa_is_dead) {
  1148. ipr_trace;
  1149. return FAILED;
  1150. }
  1151. return SUCCESS;
  1152. }
  1153. /**
  1154. * ipr_find_ses_entry - Find matching SES in SES table
  1155. * @res: resource entry struct of SES
  1156. *
  1157. * Return value:
  1158. * pointer to SES table entry / NULL on failure
  1159. **/
  1160. static const struct ipr_ses_table_entry *
  1161. ipr_find_ses_entry(struct ipr_resource_entry *res)
  1162. {
  1163. int i, j, matches;
  1164. const struct ipr_ses_table_entry *ste = ipr_ses_table;
  1165. for (i = 0; i < ARRAY_SIZE(ipr_ses_table); i++, ste++) {
  1166. for (j = 0, matches = 0; j < IPR_PROD_ID_LEN; j++) {
  1167. if (ste->compare_product_id_byte[j] == 'X') {
  1168. if (res->cfgte.std_inq_data.vpids.product_id[j] == ste->product_id[j])
  1169. matches++;
  1170. else
  1171. break;
  1172. } else
  1173. matches++;
  1174. }
  1175. if (matches == IPR_PROD_ID_LEN)
  1176. return ste;
  1177. }
  1178. return NULL;
  1179. }
  1180. /**
  1181. * ipr_get_max_scsi_speed - Determine max SCSI speed for a given bus
  1182. * @ioa_cfg: ioa config struct
  1183. * @bus: SCSI bus
  1184. * @bus_width: bus width
  1185. *
  1186. * Return value:
  1187. * SCSI bus speed in units of 100KHz, 1600 is 160 MHz
  1188. * For a 2-byte wide SCSI bus, the maximum transfer speed is
  1189. * twice the maximum transfer rate (e.g. for a wide enabled bus,
  1190. * max 160MHz = max 320MB/sec).
  1191. **/
  1192. static u32 ipr_get_max_scsi_speed(struct ipr_ioa_cfg *ioa_cfg, u8 bus, u8 bus_width)
  1193. {
  1194. struct ipr_resource_entry *res;
  1195. const struct ipr_ses_table_entry *ste;
  1196. u32 max_xfer_rate = IPR_MAX_SCSI_RATE(bus_width);
  1197. /* Loop through each config table entry in the config table buffer */
  1198. list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
  1199. if (!(IPR_IS_SES_DEVICE(res->cfgte.std_inq_data)))
  1200. continue;
  1201. if (bus != res->cfgte.res_addr.bus)
  1202. continue;
  1203. if (!(ste = ipr_find_ses_entry(res)))
  1204. continue;
  1205. max_xfer_rate = (ste->max_bus_speed_limit * 10) / (bus_width / 8);
  1206. }
  1207. return max_xfer_rate;
  1208. }
  1209. /**
  1210. * ipr_wait_iodbg_ack - Wait for an IODEBUG ACK from the IOA
  1211. * @ioa_cfg: ioa config struct
  1212. * @max_delay: max delay in micro-seconds to wait
  1213. *
  1214. * Waits for an IODEBUG ACK from the IOA, doing busy looping.
  1215. *
  1216. * Return value:
  1217. * 0 on success / other on failure
  1218. **/
  1219. static int ipr_wait_iodbg_ack(struct ipr_ioa_cfg *ioa_cfg, int max_delay)
  1220. {
  1221. volatile u32 pcii_reg;
  1222. int delay = 1;
  1223. /* Read interrupt reg until IOA signals IO Debug Acknowledge */
  1224. while (delay < max_delay) {
  1225. pcii_reg = readl(ioa_cfg->regs.sense_interrupt_reg);
  1226. if (pcii_reg & IPR_PCII_IO_DEBUG_ACKNOWLEDGE)
  1227. return 0;
  1228. /* udelay cannot be used if delay is more than a few milliseconds */
  1229. if ((delay / 1000) > MAX_UDELAY_MS)
  1230. mdelay(delay / 1000);
  1231. else
  1232. udelay(delay);
  1233. delay += delay;
  1234. }
  1235. return -EIO;
  1236. }
  1237. /**
  1238. * ipr_get_ldump_data_section - Dump IOA memory
  1239. * @ioa_cfg: ioa config struct
  1240. * @start_addr: adapter address to dump
  1241. * @dest: destination kernel buffer
  1242. * @length_in_words: length to dump in 4 byte words
  1243. *
  1244. * Return value:
  1245. * 0 on success / -EIO on failure
  1246. **/
  1247. static int ipr_get_ldump_data_section(struct ipr_ioa_cfg *ioa_cfg,
  1248. u32 start_addr,
  1249. __be32 *dest, u32 length_in_words)
  1250. {
  1251. volatile u32 temp_pcii_reg;
  1252. int i, delay = 0;
  1253. /* Write IOA interrupt reg starting LDUMP state */
  1254. writel((IPR_UPROCI_RESET_ALERT | IPR_UPROCI_IO_DEBUG_ALERT),
  1255. ioa_cfg->regs.set_uproc_interrupt_reg);
  1256. /* Wait for IO debug acknowledge */
  1257. if (ipr_wait_iodbg_ack(ioa_cfg,
  1258. IPR_LDUMP_MAX_LONG_ACK_DELAY_IN_USEC)) {
  1259. dev_err(&ioa_cfg->pdev->dev,
  1260. "IOA dump long data transfer timeout\n");
  1261. return -EIO;
  1262. }
  1263. /* Signal LDUMP interlocked - clear IO debug ack */
  1264. writel(IPR_PCII_IO_DEBUG_ACKNOWLEDGE,
  1265. ioa_cfg->regs.clr_interrupt_reg);
  1266. /* Write Mailbox with starting address */
  1267. writel(start_addr, ioa_cfg->ioa_mailbox);
  1268. /* Signal address valid - clear IOA Reset alert */
  1269. writel(IPR_UPROCI_RESET_ALERT,
  1270. ioa_cfg->regs.clr_uproc_interrupt_reg);
  1271. for (i = 0; i < length_in_words; i++) {
  1272. /* Wait for IO debug acknowledge */
  1273. if (ipr_wait_iodbg_ack(ioa_cfg,
  1274. IPR_LDUMP_MAX_SHORT_ACK_DELAY_IN_USEC)) {
  1275. dev_err(&ioa_cfg->pdev->dev,
  1276. "IOA dump short data transfer timeout\n");
  1277. return -EIO;
  1278. }
  1279. /* Read data from mailbox and increment destination pointer */
  1280. *dest = cpu_to_be32(readl(ioa_cfg->ioa_mailbox));
  1281. dest++;
  1282. /* For all but the last word of data, signal data received */
  1283. if (i < (length_in_words - 1)) {
  1284. /* Signal dump data received - Clear IO debug Ack */
  1285. writel(IPR_PCII_IO_DEBUG_ACKNOWLEDGE,
  1286. ioa_cfg->regs.clr_interrupt_reg);
  1287. }
  1288. }
  1289. /* Signal end of block transfer. Set reset alert then clear IO debug ack */
  1290. writel(IPR_UPROCI_RESET_ALERT,
  1291. ioa_cfg->regs.set_uproc_interrupt_reg);
  1292. writel(IPR_UPROCI_IO_DEBUG_ALERT,
  1293. ioa_cfg->regs.clr_uproc_interrupt_reg);
  1294. /* Signal dump data received - Clear IO debug Ack */
  1295. writel(IPR_PCII_IO_DEBUG_ACKNOWLEDGE,
  1296. ioa_cfg->regs.clr_interrupt_reg);
  1297. /* Wait for IOA to signal LDUMP exit - IOA reset alert will be cleared */
  1298. while (delay < IPR_LDUMP_MAX_SHORT_ACK_DELAY_IN_USEC) {
  1299. temp_pcii_reg =
  1300. readl(ioa_cfg->regs.sense_uproc_interrupt_reg);
  1301. if (!(temp_pcii_reg & IPR_UPROCI_RESET_ALERT))
  1302. return 0;
  1303. udelay(10);
  1304. delay += 10;
  1305. }
  1306. return 0;
  1307. }
  1308. #ifdef CONFIG_SCSI_IPR_DUMP
  1309. /**
  1310. * ipr_sdt_copy - Copy Smart Dump Table to kernel buffer
  1311. * @ioa_cfg: ioa config struct
  1312. * @pci_address: adapter address
  1313. * @length: length of data to copy
  1314. *
  1315. * Copy data from PCI adapter to kernel buffer.
  1316. * Note: length MUST be a 4 byte multiple
  1317. * Return value:
  1318. * 0 on success / other on failure
  1319. **/
  1320. static int ipr_sdt_copy(struct ipr_ioa_cfg *ioa_cfg,
  1321. unsigned long pci_address, u32 length)
  1322. {
  1323. int bytes_copied = 0;
  1324. int cur_len, rc, rem_len, rem_page_len;
  1325. __be32 *page;
  1326. unsigned long lock_flags = 0;
  1327. struct ipr_ioa_dump *ioa_dump = &ioa_cfg->dump->ioa_dump;
  1328. while (bytes_copied < length &&
  1329. (ioa_dump->hdr.len + bytes_copied) < IPR_MAX_IOA_DUMP_SIZE) {
  1330. if (ioa_dump->page_offset >= PAGE_SIZE ||
  1331. ioa_dump->page_offset == 0) {
  1332. page = (__be32 *)__get_free_page(GFP_ATOMIC);
  1333. if (!page) {
  1334. ipr_trace;
  1335. return bytes_copied;
  1336. }
  1337. ioa_dump->page_offset = 0;
  1338. ioa_dump->ioa_data[ioa_dump->next_page_index] = page;
  1339. ioa_dump->next_page_index++;
  1340. } else
  1341. page = ioa_dump->ioa_data[ioa_dump->next_page_index - 1];
  1342. rem_len = length - bytes_copied;
  1343. rem_page_len = PAGE_SIZE - ioa_dump->page_offset;
  1344. cur_len = min(rem_len, rem_page_len);
  1345. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  1346. if (ioa_cfg->sdt_state == ABORT_DUMP) {
  1347. rc = -EIO;
  1348. } else {
  1349. rc = ipr_get_ldump_data_section(ioa_cfg,
  1350. pci_address + bytes_copied,
  1351. &page[ioa_dump->page_offset / 4],
  1352. (cur_len / sizeof(u32)));
  1353. }
  1354. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  1355. if (!rc) {
  1356. ioa_dump->page_offset += cur_len;
  1357. bytes_copied += cur_len;
  1358. } else {
  1359. ipr_trace;
  1360. break;
  1361. }
  1362. schedule();
  1363. }
  1364. return bytes_copied;
  1365. }
  1366. /**
  1367. * ipr_init_dump_entry_hdr - Initialize a dump entry header.
  1368. * @hdr: dump entry header struct
  1369. *
  1370. * Return value:
  1371. * nothing
  1372. **/
  1373. static void ipr_init_dump_entry_hdr(struct ipr_dump_entry_header *hdr)
  1374. {
  1375. hdr->eye_catcher = IPR_DUMP_EYE_CATCHER;
  1376. hdr->num_elems = 1;
  1377. hdr->offset = sizeof(*hdr);
  1378. hdr->status = IPR_DUMP_STATUS_SUCCESS;
  1379. }
  1380. /**
  1381. * ipr_dump_ioa_type_data - Fill in the adapter type in the dump.
  1382. * @ioa_cfg: ioa config struct
  1383. * @driver_dump: driver dump struct
  1384. *
  1385. * Return value:
  1386. * nothing
  1387. **/
  1388. static void ipr_dump_ioa_type_data(struct ipr_ioa_cfg *ioa_cfg,
  1389. struct ipr_driver_dump *driver_dump)
  1390. {
  1391. struct ipr_inquiry_page3 *ucode_vpd = &ioa_cfg->vpd_cbs->page3_data;
  1392. ipr_init_dump_entry_hdr(&driver_dump->ioa_type_entry.hdr);
  1393. driver_dump->ioa_type_entry.hdr.len =
  1394. sizeof(struct ipr_dump_ioa_type_entry) -
  1395. sizeof(struct ipr_dump_entry_header);
  1396. driver_dump->ioa_type_entry.hdr.data_type = IPR_DUMP_DATA_TYPE_BINARY;
  1397. driver_dump->ioa_type_entry.hdr.id = IPR_DUMP_DRIVER_TYPE_ID;
  1398. driver_dump->ioa_type_entry.type = ioa_cfg->type;
  1399. driver_dump->ioa_type_entry.fw_version = (ucode_vpd->major_release << 24) |
  1400. (ucode_vpd->card_type << 16) | (ucode_vpd->minor_release[0] << 8) |
  1401. ucode_vpd->minor_release[1];
  1402. driver_dump->hdr.num_entries++;
  1403. }
  1404. /**
  1405. * ipr_dump_version_data - Fill in the driver version in the dump.
  1406. * @ioa_cfg: ioa config struct
  1407. * @driver_dump: driver dump struct
  1408. *
  1409. * Return value:
  1410. * nothing
  1411. **/
  1412. static void ipr_dump_version_data(struct ipr_ioa_cfg *ioa_cfg,
  1413. struct ipr_driver_dump *driver_dump)
  1414. {
  1415. ipr_init_dump_entry_hdr(&driver_dump->version_entry.hdr);
  1416. driver_dump->version_entry.hdr.len =
  1417. sizeof(struct ipr_dump_version_entry) -
  1418. sizeof(struct ipr_dump_entry_header);
  1419. driver_dump->version_entry.hdr.data_type = IPR_DUMP_DATA_TYPE_ASCII;
  1420. driver_dump->version_entry.hdr.id = IPR_DUMP_DRIVER_VERSION_ID;
  1421. strcpy(driver_dump->version_entry.version, IPR_DRIVER_VERSION);
  1422. driver_dump->hdr.num_entries++;
  1423. }
  1424. /**
  1425. * ipr_dump_trace_data - Fill in the IOA trace in the dump.
  1426. * @ioa_cfg: ioa config struct
  1427. * @driver_dump: driver dump struct
  1428. *
  1429. * Return value:
  1430. * nothing
  1431. **/
  1432. static void ipr_dump_trace_data(struct ipr_ioa_cfg *ioa_cfg,
  1433. struct ipr_driver_dump *driver_dump)
  1434. {
  1435. ipr_init_dump_entry_hdr(&driver_dump->trace_entry.hdr);
  1436. driver_dump->trace_entry.hdr.len =
  1437. sizeof(struct ipr_dump_trace_entry) -
  1438. sizeof(struct ipr_dump_entry_header);
  1439. driver_dump->trace_entry.hdr.data_type = IPR_DUMP_DATA_TYPE_BINARY;
  1440. driver_dump->trace_entry.hdr.id = IPR_DUMP_TRACE_ID;
  1441. memcpy(driver_dump->trace_entry.trace, ioa_cfg->trace, IPR_TRACE_SIZE);
  1442. driver_dump->hdr.num_entries++;
  1443. }
  1444. /**
  1445. * ipr_dump_location_data - Fill in the IOA location in the dump.
  1446. * @ioa_cfg: ioa config struct
  1447. * @driver_dump: driver dump struct
  1448. *
  1449. * Return value:
  1450. * nothing
  1451. **/
  1452. static void ipr_dump_location_data(struct ipr_ioa_cfg *ioa_cfg,
  1453. struct ipr_driver_dump *driver_dump)
  1454. {
  1455. ipr_init_dump_entry_hdr(&driver_dump->location_entry.hdr);
  1456. driver_dump->location_entry.hdr.len =
  1457. sizeof(struct ipr_dump_location_entry) -
  1458. sizeof(struct ipr_dump_entry_header);
  1459. driver_dump->location_entry.hdr.data_type = IPR_DUMP_DATA_TYPE_ASCII;
  1460. driver_dump->location_entry.hdr.id = IPR_DUMP_LOCATION_ID;
  1461. strcpy(driver_dump->location_entry.location, ioa_cfg->pdev->dev.bus_id);
  1462. driver_dump->hdr.num_entries++;
  1463. }
  1464. /**
  1465. * ipr_get_ioa_dump - Perform a dump of the driver and adapter.
  1466. * @ioa_cfg: ioa config struct
  1467. * @dump: dump struct
  1468. *
  1469. * Return value:
  1470. * nothing
  1471. **/
  1472. static void ipr_get_ioa_dump(struct ipr_ioa_cfg *ioa_cfg, struct ipr_dump *dump)
  1473. {
  1474. unsigned long start_addr, sdt_word;
  1475. unsigned long lock_flags = 0;
  1476. struct ipr_driver_dump *driver_dump = &dump->driver_dump;
  1477. struct ipr_ioa_dump *ioa_dump = &dump->ioa_dump;
  1478. u32 num_entries, start_off, end_off;
  1479. u32 bytes_to_copy, bytes_copied, rc;
  1480. struct ipr_sdt *sdt;
  1481. int i;
  1482. ENTER;
  1483. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  1484. if (ioa_cfg->sdt_state != GET_DUMP) {
  1485. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  1486. return;
  1487. }
  1488. start_addr = readl(ioa_cfg->ioa_mailbox);
  1489. if (!ipr_sdt_is_fmt2(start_addr)) {
  1490. dev_err(&ioa_cfg->pdev->dev,
  1491. "Invalid dump table format: %lx\n", start_addr);
  1492. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  1493. return;
  1494. }
  1495. dev_err(&ioa_cfg->pdev->dev, "Dump of IOA initiated\n");
  1496. driver_dump->hdr.eye_catcher = IPR_DUMP_EYE_CATCHER;
  1497. /* Initialize the overall dump header */
  1498. driver_dump->hdr.len = sizeof(struct ipr_driver_dump);
  1499. driver_dump->hdr.num_entries = 1;
  1500. driver_dump->hdr.first_entry_offset = sizeof(struct ipr_dump_header);
  1501. driver_dump->hdr.status = IPR_DUMP_STATUS_SUCCESS;
  1502. driver_dump->hdr.os = IPR_DUMP_OS_LINUX;
  1503. driver_dump->hdr.driver_name = IPR_DUMP_DRIVER_NAME;
  1504. ipr_dump_version_data(ioa_cfg, driver_dump);
  1505. ipr_dump_location_data(ioa_cfg, driver_dump);
  1506. ipr_dump_ioa_type_data(ioa_cfg, driver_dump);
  1507. ipr_dump_trace_data(ioa_cfg, driver_dump);
  1508. /* Update dump_header */
  1509. driver_dump->hdr.len += sizeof(struct ipr_dump_entry_header);
  1510. /* IOA Dump entry */
  1511. ipr_init_dump_entry_hdr(&ioa_dump->hdr);
  1512. ioa_dump->format = IPR_SDT_FMT2;
  1513. ioa_dump->hdr.len = 0;
  1514. ioa_dump->hdr.data_type = IPR_DUMP_DATA_TYPE_BINARY;
  1515. ioa_dump->hdr.id = IPR_DUMP_IOA_DUMP_ID;
  1516. /* First entries in sdt are actually a list of dump addresses and
  1517. lengths to gather the real dump data. sdt represents the pointer
  1518. to the ioa generated dump table. Dump data will be extracted based
  1519. on entries in this table */
  1520. sdt = &ioa_dump->sdt;
  1521. rc = ipr_get_ldump_data_section(ioa_cfg, start_addr, (__be32 *)sdt,
  1522. sizeof(struct ipr_sdt) / sizeof(__be32));
  1523. /* Smart Dump table is ready to use and the first entry is valid */
  1524. if (rc || (be32_to_cpu(sdt->hdr.state) != IPR_FMT2_SDT_READY_TO_USE)) {
  1525. dev_err(&ioa_cfg->pdev->dev,
  1526. "Dump of IOA failed. Dump table not valid: %d, %X.\n",
  1527. rc, be32_to_cpu(sdt->hdr.state));
  1528. driver_dump->hdr.status = IPR_DUMP_STATUS_FAILED;
  1529. ioa_cfg->sdt_state = DUMP_OBTAINED;
  1530. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  1531. return;
  1532. }
  1533. num_entries = be32_to_cpu(sdt->hdr.num_entries_used);
  1534. if (num_entries > IPR_NUM_SDT_ENTRIES)
  1535. num_entries = IPR_NUM_SDT_ENTRIES;
  1536. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  1537. for (i = 0; i < num_entries; i++) {
  1538. if (ioa_dump->hdr.len > IPR_MAX_IOA_DUMP_SIZE) {
  1539. driver_dump->hdr.status = IPR_DUMP_STATUS_QUAL_SUCCESS;
  1540. break;
  1541. }
  1542. if (sdt->entry[i].flags & IPR_SDT_VALID_ENTRY) {
  1543. sdt_word = be32_to_cpu(sdt->entry[i].bar_str_offset);
  1544. start_off = sdt_word & IPR_FMT2_MBX_ADDR_MASK;
  1545. end_off = be32_to_cpu(sdt->entry[i].end_offset);
  1546. if (ipr_sdt_is_fmt2(sdt_word) && sdt_word) {
  1547. bytes_to_copy = end_off - start_off;
  1548. if (bytes_to_copy > IPR_MAX_IOA_DUMP_SIZE) {
  1549. sdt->entry[i].flags &= ~IPR_SDT_VALID_ENTRY;
  1550. continue;
  1551. }
  1552. /* Copy data from adapter to driver buffers */
  1553. bytes_copied = ipr_sdt_copy(ioa_cfg, sdt_word,
  1554. bytes_to_copy);
  1555. ioa_dump->hdr.len += bytes_copied;
  1556. if (bytes_copied != bytes_to_copy) {
  1557. driver_dump->hdr.status = IPR_DUMP_STATUS_QUAL_SUCCESS;
  1558. break;
  1559. }
  1560. }
  1561. }
  1562. }
  1563. dev_err(&ioa_cfg->pdev->dev, "Dump of IOA completed.\n");
  1564. /* Update dump_header */
  1565. driver_dump->hdr.len += ioa_dump->hdr.len;
  1566. wmb();
  1567. ioa_cfg->sdt_state = DUMP_OBTAINED;
  1568. LEAVE;
  1569. }
  1570. #else
  1571. #define ipr_get_ioa_dump(ioa_cfg, dump) do { } while(0)
  1572. #endif
  1573. /**
  1574. * ipr_release_dump - Free adapter dump memory
  1575. * @kref: kref struct
  1576. *
  1577. * Return value:
  1578. * nothing
  1579. **/
  1580. static void ipr_release_dump(struct kref *kref)
  1581. {
  1582. struct ipr_dump *dump = container_of(kref,struct ipr_dump,kref);
  1583. struct ipr_ioa_cfg *ioa_cfg = dump->ioa_cfg;
  1584. unsigned long lock_flags = 0;
  1585. int i;
  1586. ENTER;
  1587. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  1588. ioa_cfg->dump = NULL;
  1589. ioa_cfg->sdt_state = INACTIVE;
  1590. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  1591. for (i = 0; i < dump->ioa_dump.next_page_index; i++)
  1592. free_page((unsigned long) dump->ioa_dump.ioa_data[i]);
  1593. kfree(dump);
  1594. LEAVE;
  1595. }
  1596. /**
  1597. * ipr_worker_thread - Worker thread
  1598. * @data: ioa config struct
  1599. *
  1600. * Called at task level from a work thread. This function takes care
  1601. * of adding and removing device from the mid-layer as configuration
  1602. * changes are detected by the adapter.
  1603. *
  1604. * Return value:
  1605. * nothing
  1606. **/
  1607. static void ipr_worker_thread(void *data)
  1608. {
  1609. unsigned long lock_flags;
  1610. struct ipr_resource_entry *res;
  1611. struct scsi_device *sdev;
  1612. struct ipr_dump *dump;
  1613. struct ipr_ioa_cfg *ioa_cfg = data;
  1614. u8 bus, target, lun;
  1615. int did_work;
  1616. ENTER;
  1617. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  1618. if (ioa_cfg->sdt_state == GET_DUMP) {
  1619. dump = ioa_cfg->dump;
  1620. if (!dump) {
  1621. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  1622. return;
  1623. }
  1624. kref_get(&dump->kref);
  1625. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  1626. ipr_get_ioa_dump(ioa_cfg, dump);
  1627. kref_put(&dump->kref, ipr_release_dump);
  1628. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  1629. if (ioa_cfg->sdt_state == DUMP_OBTAINED)
  1630. ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
  1631. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  1632. return;
  1633. }
  1634. restart:
  1635. do {
  1636. did_work = 0;
  1637. if (!ioa_cfg->allow_cmds || !ioa_cfg->allow_ml_add_del) {
  1638. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  1639. return;
  1640. }
  1641. list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
  1642. if (res->del_from_ml && res->sdev) {
  1643. did_work = 1;
  1644. sdev = res->sdev;
  1645. if (!scsi_device_get(sdev)) {
  1646. res->sdev = NULL;
  1647. list_move_tail(&res->queue, &ioa_cfg->free_res_q);
  1648. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  1649. scsi_remove_device(sdev);
  1650. scsi_device_put(sdev);
  1651. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  1652. }
  1653. break;
  1654. }
  1655. }
  1656. } while(did_work);
  1657. list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
  1658. if (res->add_to_ml) {
  1659. bus = res->cfgte.res_addr.bus;
  1660. target = res->cfgte.res_addr.target;
  1661. lun = res->cfgte.res_addr.lun;
  1662. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  1663. scsi_add_device(ioa_cfg->host, bus, target, lun);
  1664. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  1665. goto restart;
  1666. }
  1667. }
  1668. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  1669. kobject_uevent(&ioa_cfg->host->shost_classdev.kobj, KOBJ_CHANGE, NULL);
  1670. LEAVE;
  1671. }
  1672. #ifdef CONFIG_SCSI_IPR_TRACE
  1673. /**
  1674. * ipr_read_trace - Dump the adapter trace
  1675. * @kobj: kobject struct
  1676. * @buf: buffer
  1677. * @off: offset
  1678. * @count: buffer size
  1679. *
  1680. * Return value:
  1681. * number of bytes printed to buffer
  1682. **/
  1683. static ssize_t ipr_read_trace(struct kobject *kobj, char *buf,
  1684. loff_t off, size_t count)
  1685. {
  1686. struct class_device *cdev = container_of(kobj,struct class_device,kobj);
  1687. struct Scsi_Host *shost = class_to_shost(cdev);
  1688. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
  1689. unsigned long lock_flags = 0;
  1690. int size = IPR_TRACE_SIZE;
  1691. char *src = (char *)ioa_cfg->trace;
  1692. if (off > size)
  1693. return 0;
  1694. if (off + count > size) {
  1695. size -= off;
  1696. count = size;
  1697. }
  1698. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  1699. memcpy(buf, &src[off], count);
  1700. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  1701. return count;
  1702. }
  1703. static struct bin_attribute ipr_trace_attr = {
  1704. .attr = {
  1705. .name = "trace",
  1706. .mode = S_IRUGO,
  1707. },
  1708. .size = 0,
  1709. .read = ipr_read_trace,
  1710. };
  1711. #endif
  1712. static const struct {
  1713. enum ipr_cache_state state;
  1714. char *name;
  1715. } cache_state [] = {
  1716. { CACHE_NONE, "none" },
  1717. { CACHE_DISABLED, "disabled" },
  1718. { CACHE_ENABLED, "enabled" }
  1719. };
  1720. /**
  1721. * ipr_show_write_caching - Show the write caching attribute
  1722. * @class_dev: class device struct
  1723. * @buf: buffer
  1724. *
  1725. * Return value:
  1726. * number of bytes printed to buffer
  1727. **/
  1728. static ssize_t ipr_show_write_caching(struct class_device *class_dev, char *buf)
  1729. {
  1730. struct Scsi_Host *shost = class_to_shost(class_dev);
  1731. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
  1732. unsigned long lock_flags = 0;
  1733. int i, len = 0;
  1734. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  1735. for (i = 0; i < ARRAY_SIZE(cache_state); i++) {
  1736. if (cache_state[i].state == ioa_cfg->cache_state) {
  1737. len = snprintf(buf, PAGE_SIZE, "%s\n", cache_state[i].name);
  1738. break;
  1739. }
  1740. }
  1741. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  1742. return len;
  1743. }
  1744. /**
  1745. * ipr_store_write_caching - Enable/disable adapter write cache
  1746. * @class_dev: class_device struct
  1747. * @buf: buffer
  1748. * @count: buffer size
  1749. *
  1750. * This function will enable/disable adapter write cache.
  1751. *
  1752. * Return value:
  1753. * count on success / other on failure
  1754. **/
  1755. static ssize_t ipr_store_write_caching(struct class_device *class_dev,
  1756. const char *buf, size_t count)
  1757. {
  1758. struct Scsi_Host *shost = class_to_shost(class_dev);
  1759. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
  1760. unsigned long lock_flags = 0;
  1761. enum ipr_cache_state new_state = CACHE_INVALID;
  1762. int i;
  1763. if (!capable(CAP_SYS_ADMIN))
  1764. return -EACCES;
  1765. if (ioa_cfg->cache_state == CACHE_NONE)
  1766. return -EINVAL;
  1767. for (i = 0; i < ARRAY_SIZE(cache_state); i++) {
  1768. if (!strncmp(cache_state[i].name, buf, strlen(cache_state[i].name))) {
  1769. new_state = cache_state[i].state;
  1770. break;
  1771. }
  1772. }
  1773. if (new_state != CACHE_DISABLED && new_state != CACHE_ENABLED)
  1774. return -EINVAL;
  1775. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  1776. if (ioa_cfg->cache_state == new_state) {
  1777. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  1778. return count;
  1779. }
  1780. ioa_cfg->cache_state = new_state;
  1781. dev_info(&ioa_cfg->pdev->dev, "%s adapter write cache.\n",
  1782. new_state == CACHE_ENABLED ? "Enabling" : "Disabling");
  1783. if (!ioa_cfg->in_reset_reload)
  1784. ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NORMAL);
  1785. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  1786. wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
  1787. return count;
  1788. }
  1789. static struct class_device_attribute ipr_ioa_cache_attr = {
  1790. .attr = {
  1791. .name = "write_cache",
  1792. .mode = S_IRUGO | S_IWUSR,
  1793. },
  1794. .show = ipr_show_write_caching,
  1795. .store = ipr_store_write_caching
  1796. };
  1797. /**
  1798. * ipr_show_fw_version - Show the firmware version
  1799. * @class_dev: class device struct
  1800. * @buf: buffer
  1801. *
  1802. * Return value:
  1803. * number of bytes printed to buffer
  1804. **/
  1805. static ssize_t ipr_show_fw_version(struct class_device *class_dev, char *buf)
  1806. {
  1807. struct Scsi_Host *shost = class_to_shost(class_dev);
  1808. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
  1809. struct ipr_inquiry_page3 *ucode_vpd = &ioa_cfg->vpd_cbs->page3_data;
  1810. unsigned long lock_flags = 0;
  1811. int len;
  1812. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  1813. len = snprintf(buf, PAGE_SIZE, "%02X%02X%02X%02X\n",
  1814. ucode_vpd->major_release, ucode_vpd->card_type,
  1815. ucode_vpd->minor_release[0],
  1816. ucode_vpd->minor_release[1]);
  1817. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  1818. return len;
  1819. }
  1820. static struct class_device_attribute ipr_fw_version_attr = {
  1821. .attr = {
  1822. .name = "fw_version",
  1823. .mode = S_IRUGO,
  1824. },
  1825. .show = ipr_show_fw_version,
  1826. };
  1827. /**
  1828. * ipr_show_log_level - Show the adapter's error logging level
  1829. * @class_dev: class device struct
  1830. * @buf: buffer
  1831. *
  1832. * Return value:
  1833. * number of bytes printed to buffer
  1834. **/
  1835. static ssize_t ipr_show_log_level(struct class_device *class_dev, char *buf)
  1836. {
  1837. struct Scsi_Host *shost = class_to_shost(class_dev);
  1838. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
  1839. unsigned long lock_flags = 0;
  1840. int len;
  1841. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  1842. len = snprintf(buf, PAGE_SIZE, "%d\n", ioa_cfg->log_level);
  1843. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  1844. return len;
  1845. }
  1846. /**
  1847. * ipr_store_log_level - Change the adapter's error logging level
  1848. * @class_dev: class device struct
  1849. * @buf: buffer
  1850. *
  1851. * Return value:
  1852. * number of bytes printed to buffer
  1853. **/
  1854. static ssize_t ipr_store_log_level(struct class_device *class_dev,
  1855. const char *buf, size_t count)
  1856. {
  1857. struct Scsi_Host *shost = class_to_shost(class_dev);
  1858. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
  1859. unsigned long lock_flags = 0;
  1860. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  1861. ioa_cfg->log_level = simple_strtoul(buf, NULL, 10);
  1862. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  1863. return strlen(buf);
  1864. }
  1865. static struct class_device_attribute ipr_log_level_attr = {
  1866. .attr = {
  1867. .name = "log_level",
  1868. .mode = S_IRUGO | S_IWUSR,
  1869. },
  1870. .show = ipr_show_log_level,
  1871. .store = ipr_store_log_level
  1872. };
  1873. /**
  1874. * ipr_store_diagnostics - IOA Diagnostics interface
  1875. * @class_dev: class_device struct
  1876. * @buf: buffer
  1877. * @count: buffer size
  1878. *
  1879. * This function will reset the adapter and wait a reasonable
  1880. * amount of time for any errors that the adapter might log.
  1881. *
  1882. * Return value:
  1883. * count on success / other on failure
  1884. **/
  1885. static ssize_t ipr_store_diagnostics(struct class_device *class_dev,
  1886. const char *buf, size_t count)
  1887. {
  1888. struct Scsi_Host *shost = class_to_shost(class_dev);
  1889. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
  1890. unsigned long lock_flags = 0;
  1891. int rc = count;
  1892. if (!capable(CAP_SYS_ADMIN))
  1893. return -EACCES;
  1894. wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
  1895. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  1896. ioa_cfg->errors_logged = 0;
  1897. ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NORMAL);
  1898. if (ioa_cfg->in_reset_reload) {
  1899. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  1900. wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
  1901. /* Wait for a second for any errors to be logged */
  1902. msleep(1000);
  1903. } else {
  1904. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  1905. return -EIO;
  1906. }
  1907. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  1908. if (ioa_cfg->in_reset_reload || ioa_cfg->errors_logged)
  1909. rc = -EIO;
  1910. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  1911. return rc;
  1912. }
  1913. static struct class_device_attribute ipr_diagnostics_attr = {
  1914. .attr = {
  1915. .name = "run_diagnostics",
  1916. .mode = S_IWUSR,
  1917. },
  1918. .store = ipr_store_diagnostics
  1919. };
  1920. /**
  1921. * ipr_store_reset_adapter - Reset the adapter
  1922. * @class_dev: class_device struct
  1923. * @buf: buffer
  1924. * @count: buffer size
  1925. *
  1926. * This function will reset the adapter.
  1927. *
  1928. * Return value:
  1929. * count on success / other on failure
  1930. **/
  1931. static ssize_t ipr_store_reset_adapter(struct class_device *class_dev,
  1932. const char *buf, size_t count)
  1933. {
  1934. struct Scsi_Host *shost = class_to_shost(class_dev);
  1935. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
  1936. unsigned long lock_flags;
  1937. int result = count;
  1938. if (!capable(CAP_SYS_ADMIN))
  1939. return -EACCES;
  1940. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  1941. if (!ioa_cfg->in_reset_reload)
  1942. ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NORMAL);
  1943. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  1944. wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
  1945. return result;
  1946. }
  1947. static struct class_device_attribute ipr_ioa_reset_attr = {
  1948. .attr = {
  1949. .name = "reset_host",
  1950. .mode = S_IWUSR,
  1951. },
  1952. .store = ipr_store_reset_adapter
  1953. };
  1954. /**
  1955. * ipr_alloc_ucode_buffer - Allocates a microcode download buffer
  1956. * @buf_len: buffer length
  1957. *
  1958. * Allocates a DMA'able buffer in chunks and assembles a scatter/gather
  1959. * list to use for microcode download
  1960. *
  1961. * Return value:
  1962. * pointer to sglist / NULL on failure
  1963. **/
  1964. static struct ipr_sglist *ipr_alloc_ucode_buffer(int buf_len)
  1965. {
  1966. int sg_size, order, bsize_elem, num_elem, i, j;
  1967. struct ipr_sglist *sglist;
  1968. struct scatterlist *scatterlist;
  1969. struct page *page;
  1970. /* Get the minimum size per scatter/gather element */
  1971. sg_size = buf_len / (IPR_MAX_SGLIST - 1);
  1972. /* Get the actual size per element */
  1973. order = get_order(sg_size);
  1974. /* Determine the actual number of bytes per element */
  1975. bsize_elem = PAGE_SIZE * (1 << order);
  1976. /* Determine the actual number of sg entries needed */
  1977. if (buf_len % bsize_elem)
  1978. num_elem = (buf_len / bsize_elem) + 1;
  1979. else
  1980. num_elem = buf_len / bsize_elem;
  1981. /* Allocate a scatter/gather list for the DMA */
  1982. sglist = kmalloc(sizeof(struct ipr_sglist) +
  1983. (sizeof(struct scatterlist) * (num_elem - 1)),
  1984. GFP_KERNEL);
  1985. if (sglist == NULL) {
  1986. ipr_trace;
  1987. return NULL;
  1988. }
  1989. memset(sglist, 0, sizeof(struct ipr_sglist) +
  1990. (sizeof(struct scatterlist) * (num_elem - 1)));
  1991. scatterlist = sglist->scatterlist;
  1992. sglist->order = order;
  1993. sglist->num_sg = num_elem;
  1994. /* Allocate a bunch of sg elements */
  1995. for (i = 0; i < num_elem; i++) {
  1996. page = alloc_pages(GFP_KERNEL, order);
  1997. if (!page) {
  1998. ipr_trace;
  1999. /* Free up what we already allocated */
  2000. for (j = i - 1; j >= 0; j--)
  2001. __free_pages(scatterlist[j].page, order);
  2002. kfree(sglist);
  2003. return NULL;
  2004. }
  2005. scatterlist[i].page = page;
  2006. }
  2007. return sglist;
  2008. }
  2009. /**
  2010. * ipr_free_ucode_buffer - Frees a microcode download buffer
  2011. * @p_dnld: scatter/gather list pointer
  2012. *
  2013. * Free a DMA'able ucode download buffer previously allocated with
  2014. * ipr_alloc_ucode_buffer
  2015. *
  2016. * Return value:
  2017. * nothing
  2018. **/
  2019. static void ipr_free_ucode_buffer(struct ipr_sglist *sglist)
  2020. {
  2021. int i;
  2022. for (i = 0; i < sglist->num_sg; i++)
  2023. __free_pages(sglist->scatterlist[i].page, sglist->order);
  2024. kfree(sglist);
  2025. }
  2026. /**
  2027. * ipr_copy_ucode_buffer - Copy user buffer to kernel buffer
  2028. * @sglist: scatter/gather list pointer
  2029. * @buffer: buffer pointer
  2030. * @len: buffer length
  2031. *
  2032. * Copy a microcode image from a user buffer into a buffer allocated by
  2033. * ipr_alloc_ucode_buffer
  2034. *
  2035. * Return value:
  2036. * 0 on success / other on failure
  2037. **/
  2038. static int ipr_copy_ucode_buffer(struct ipr_sglist *sglist,
  2039. u8 *buffer, u32 len)
  2040. {
  2041. int bsize_elem, i, result = 0;
  2042. struct scatterlist *scatterlist;
  2043. void *kaddr;
  2044. /* Determine the actual number of bytes per element */
  2045. bsize_elem = PAGE_SIZE * (1 << sglist->order);
  2046. scatterlist = sglist->scatterlist;
  2047. for (i = 0; i < (len / bsize_elem); i++, buffer += bsize_elem) {
  2048. kaddr = kmap(scatterlist[i].page);
  2049. memcpy(kaddr, buffer, bsize_elem);
  2050. kunmap(scatterlist[i].page);
  2051. scatterlist[i].length = bsize_elem;
  2052. if (result != 0) {
  2053. ipr_trace;
  2054. return result;
  2055. }
  2056. }
  2057. if (len % bsize_elem) {
  2058. kaddr = kmap(scatterlist[i].page);
  2059. memcpy(kaddr, buffer, len % bsize_elem);
  2060. kunmap(scatterlist[i].page);
  2061. scatterlist[i].length = len % bsize_elem;
  2062. }
  2063. sglist->buffer_len = len;
  2064. return result;
  2065. }
  2066. /**
  2067. * ipr_map_ucode_buffer - Map a microcode download buffer
  2068. * @ipr_cmd: ipr command struct
  2069. * @sglist: scatter/gather list
  2070. * @len: total length of download buffer
  2071. *
  2072. * Maps a microcode download scatter/gather list for DMA and
  2073. * builds the IOADL.
  2074. *
  2075. * Return value:
  2076. * 0 on success / -EIO on failure
  2077. **/
  2078. static int ipr_map_ucode_buffer(struct ipr_cmnd *ipr_cmd,
  2079. struct ipr_sglist *sglist, int len)
  2080. {
  2081. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  2082. struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
  2083. struct ipr_ioadl_desc *ioadl = ipr_cmd->ioadl;
  2084. struct scatterlist *scatterlist = sglist->scatterlist;
  2085. int i;
  2086. ipr_cmd->dma_use_sg = pci_map_sg(ioa_cfg->pdev, scatterlist,
  2087. sglist->num_sg, DMA_TO_DEVICE);
  2088. ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
  2089. ioarcb->write_data_transfer_length = cpu_to_be32(len);
  2090. ioarcb->write_ioadl_len =
  2091. cpu_to_be32(sizeof(struct ipr_ioadl_desc) * ipr_cmd->dma_use_sg);
  2092. for (i = 0; i < ipr_cmd->dma_use_sg; i++) {
  2093. ioadl[i].flags_and_data_len =
  2094. cpu_to_be32(IPR_IOADL_FLAGS_WRITE | sg_dma_len(&scatterlist[i]));
  2095. ioadl[i].address =
  2096. cpu_to_be32(sg_dma_address(&scatterlist[i]));
  2097. }
  2098. if (likely(ipr_cmd->dma_use_sg)) {
  2099. ioadl[i-1].flags_and_data_len |=
  2100. cpu_to_be32(IPR_IOADL_FLAGS_LAST);
  2101. }
  2102. else {
  2103. dev_err(&ioa_cfg->pdev->dev, "pci_map_sg failed!\n");
  2104. return -EIO;
  2105. }
  2106. return 0;
  2107. }
  2108. /**
  2109. * ipr_store_update_fw - Update the firmware on the adapter
  2110. * @class_dev: class_device struct
  2111. * @buf: buffer
  2112. * @count: buffer size
  2113. *
  2114. * This function will update the firmware on the adapter.
  2115. *
  2116. * Return value:
  2117. * count on success / other on failure
  2118. **/
  2119. static ssize_t ipr_store_update_fw(struct class_device *class_dev,
  2120. const char *buf, size_t count)
  2121. {
  2122. struct Scsi_Host *shost = class_to_shost(class_dev);
  2123. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
  2124. struct ipr_ucode_image_header *image_hdr;
  2125. const struct firmware *fw_entry;
  2126. struct ipr_sglist *sglist;
  2127. unsigned long lock_flags;
  2128. char fname[100];
  2129. char *src;
  2130. int len, result, dnld_size;
  2131. if (!capable(CAP_SYS_ADMIN))
  2132. return -EACCES;
  2133. len = snprintf(fname, 99, "%s", buf);
  2134. fname[len-1] = '\0';
  2135. if(request_firmware(&fw_entry, fname, &ioa_cfg->pdev->dev)) {
  2136. dev_err(&ioa_cfg->pdev->dev, "Firmware file %s not found\n", fname);
  2137. return -EIO;
  2138. }
  2139. image_hdr = (struct ipr_ucode_image_header *)fw_entry->data;
  2140. if (be32_to_cpu(image_hdr->header_length) > fw_entry->size ||
  2141. (ioa_cfg->vpd_cbs->page3_data.card_type &&
  2142. ioa_cfg->vpd_cbs->page3_data.card_type != image_hdr->card_type)) {
  2143. dev_err(&ioa_cfg->pdev->dev, "Invalid microcode buffer\n");
  2144. release_firmware(fw_entry);
  2145. return -EINVAL;
  2146. }
  2147. src = (u8 *)image_hdr + be32_to_cpu(image_hdr->header_length);
  2148. dnld_size = fw_entry->size - be32_to_cpu(image_hdr->header_length);
  2149. sglist = ipr_alloc_ucode_buffer(dnld_size);
  2150. if (!sglist) {
  2151. dev_err(&ioa_cfg->pdev->dev, "Microcode buffer allocation failed\n");
  2152. release_firmware(fw_entry);
  2153. return -ENOMEM;
  2154. }
  2155. result = ipr_copy_ucode_buffer(sglist, src, dnld_size);
  2156. if (result) {
  2157. dev_err(&ioa_cfg->pdev->dev,
  2158. "Microcode buffer copy to DMA buffer failed\n");
  2159. ipr_free_ucode_buffer(sglist);
  2160. release_firmware(fw_entry);
  2161. return result;
  2162. }
  2163. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  2164. if (ioa_cfg->ucode_sglist) {
  2165. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2166. dev_err(&ioa_cfg->pdev->dev,
  2167. "Microcode download already in progress\n");
  2168. ipr_free_ucode_buffer(sglist);
  2169. release_firmware(fw_entry);
  2170. return -EIO;
  2171. }
  2172. ioa_cfg->ucode_sglist = sglist;
  2173. ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NORMAL);
  2174. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2175. wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
  2176. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  2177. ioa_cfg->ucode_sglist = NULL;
  2178. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2179. ipr_free_ucode_buffer(sglist);
  2180. release_firmware(fw_entry);
  2181. return count;
  2182. }
  2183. static struct class_device_attribute ipr_update_fw_attr = {
  2184. .attr = {
  2185. .name = "update_fw",
  2186. .mode = S_IWUSR,
  2187. },
  2188. .store = ipr_store_update_fw
  2189. };
  2190. static struct class_device_attribute *ipr_ioa_attrs[] = {
  2191. &ipr_fw_version_attr,
  2192. &ipr_log_level_attr,
  2193. &ipr_diagnostics_attr,
  2194. &ipr_ioa_reset_attr,
  2195. &ipr_update_fw_attr,
  2196. &ipr_ioa_cache_attr,
  2197. NULL,
  2198. };
  2199. #ifdef CONFIG_SCSI_IPR_DUMP
  2200. /**
  2201. * ipr_read_dump - Dump the adapter
  2202. * @kobj: kobject struct
  2203. * @buf: buffer
  2204. * @off: offset
  2205. * @count: buffer size
  2206. *
  2207. * Return value:
  2208. * number of bytes printed to buffer
  2209. **/
  2210. static ssize_t ipr_read_dump(struct kobject *kobj, char *buf,
  2211. loff_t off, size_t count)
  2212. {
  2213. struct class_device *cdev = container_of(kobj,struct class_device,kobj);
  2214. struct Scsi_Host *shost = class_to_shost(cdev);
  2215. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
  2216. struct ipr_dump *dump;
  2217. unsigned long lock_flags = 0;
  2218. char *src;
  2219. int len;
  2220. size_t rc = count;
  2221. if (!capable(CAP_SYS_ADMIN))
  2222. return -EACCES;
  2223. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  2224. dump = ioa_cfg->dump;
  2225. if (ioa_cfg->sdt_state != DUMP_OBTAINED || !dump) {
  2226. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2227. return 0;
  2228. }
  2229. kref_get(&dump->kref);
  2230. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2231. if (off > dump->driver_dump.hdr.len) {
  2232. kref_put(&dump->kref, ipr_release_dump);
  2233. return 0;
  2234. }
  2235. if (off + count > dump->driver_dump.hdr.len) {
  2236. count = dump->driver_dump.hdr.len - off;
  2237. rc = count;
  2238. }
  2239. if (count && off < sizeof(dump->driver_dump)) {
  2240. if (off + count > sizeof(dump->driver_dump))
  2241. len = sizeof(dump->driver_dump) - off;
  2242. else
  2243. len = count;
  2244. src = (u8 *)&dump->driver_dump + off;
  2245. memcpy(buf, src, len);
  2246. buf += len;
  2247. off += len;
  2248. count -= len;
  2249. }
  2250. off -= sizeof(dump->driver_dump);
  2251. if (count && off < offsetof(struct ipr_ioa_dump, ioa_data)) {
  2252. if (off + count > offsetof(struct ipr_ioa_dump, ioa_data))
  2253. len = offsetof(struct ipr_ioa_dump, ioa_data) - off;
  2254. else
  2255. len = count;
  2256. src = (u8 *)&dump->ioa_dump + off;
  2257. memcpy(buf, src, len);
  2258. buf += len;
  2259. off += len;
  2260. count -= len;
  2261. }
  2262. off -= offsetof(struct ipr_ioa_dump, ioa_data);
  2263. while (count) {
  2264. if ((off & PAGE_MASK) != ((off + count) & PAGE_MASK))
  2265. len = PAGE_ALIGN(off) - off;
  2266. else
  2267. len = count;
  2268. src = (u8 *)dump->ioa_dump.ioa_data[(off & PAGE_MASK) >> PAGE_SHIFT];
  2269. src += off & ~PAGE_MASK;
  2270. memcpy(buf, src, len);
  2271. buf += len;
  2272. off += len;
  2273. count -= len;
  2274. }
  2275. kref_put(&dump->kref, ipr_release_dump);
  2276. return rc;
  2277. }
  2278. /**
  2279. * ipr_alloc_dump - Prepare for adapter dump
  2280. * @ioa_cfg: ioa config struct
  2281. *
  2282. * Return value:
  2283. * 0 on success / other on failure
  2284. **/
  2285. static int ipr_alloc_dump(struct ipr_ioa_cfg *ioa_cfg)
  2286. {
  2287. struct ipr_dump *dump;
  2288. unsigned long lock_flags = 0;
  2289. ENTER;
  2290. dump = kmalloc(sizeof(struct ipr_dump), GFP_KERNEL);
  2291. if (!dump) {
  2292. ipr_err("Dump memory allocation failed\n");
  2293. return -ENOMEM;
  2294. }
  2295. memset(dump, 0, sizeof(struct ipr_dump));
  2296. kref_init(&dump->kref);
  2297. dump->ioa_cfg = ioa_cfg;
  2298. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  2299. if (INACTIVE != ioa_cfg->sdt_state) {
  2300. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2301. kfree(dump);
  2302. return 0;
  2303. }
  2304. ioa_cfg->dump = dump;
  2305. ioa_cfg->sdt_state = WAIT_FOR_DUMP;
  2306. if (ioa_cfg->ioa_is_dead && !ioa_cfg->dump_taken) {
  2307. ioa_cfg->dump_taken = 1;
  2308. schedule_work(&ioa_cfg->work_q);
  2309. }
  2310. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2311. LEAVE;
  2312. return 0;
  2313. }
  2314. /**
  2315. * ipr_free_dump - Free adapter dump memory
  2316. * @ioa_cfg: ioa config struct
  2317. *
  2318. * Return value:
  2319. * 0 on success / other on failure
  2320. **/
  2321. static int ipr_free_dump(struct ipr_ioa_cfg *ioa_cfg)
  2322. {
  2323. struct ipr_dump *dump;
  2324. unsigned long lock_flags = 0;
  2325. ENTER;
  2326. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  2327. dump = ioa_cfg->dump;
  2328. if (!dump) {
  2329. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2330. return 0;
  2331. }
  2332. ioa_cfg->dump = NULL;
  2333. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2334. kref_put(&dump->kref, ipr_release_dump);
  2335. LEAVE;
  2336. return 0;
  2337. }
  2338. /**
  2339. * ipr_write_dump - Setup dump state of adapter
  2340. * @kobj: kobject struct
  2341. * @buf: buffer
  2342. * @off: offset
  2343. * @count: buffer size
  2344. *
  2345. * Return value:
  2346. * number of bytes printed to buffer
  2347. **/
  2348. static ssize_t ipr_write_dump(struct kobject *kobj, char *buf,
  2349. loff_t off, size_t count)
  2350. {
  2351. struct class_device *cdev = container_of(kobj,struct class_device,kobj);
  2352. struct Scsi_Host *shost = class_to_shost(cdev);
  2353. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
  2354. int rc;
  2355. if (!capable(CAP_SYS_ADMIN))
  2356. return -EACCES;
  2357. if (buf[0] == '1')
  2358. rc = ipr_alloc_dump(ioa_cfg);
  2359. else if (buf[0] == '0')
  2360. rc = ipr_free_dump(ioa_cfg);
  2361. else
  2362. return -EINVAL;
  2363. if (rc)
  2364. return rc;
  2365. else
  2366. return count;
  2367. }
  2368. static struct bin_attribute ipr_dump_attr = {
  2369. .attr = {
  2370. .name = "dump",
  2371. .mode = S_IRUSR | S_IWUSR,
  2372. },
  2373. .size = 0,
  2374. .read = ipr_read_dump,
  2375. .write = ipr_write_dump
  2376. };
  2377. #else
  2378. static int ipr_free_dump(struct ipr_ioa_cfg *ioa_cfg) { return 0; };
  2379. #endif
  2380. /**
  2381. * ipr_change_queue_depth - Change the device's queue depth
  2382. * @sdev: scsi device struct
  2383. * @qdepth: depth to set
  2384. *
  2385. * Return value:
  2386. * actual depth set
  2387. **/
  2388. static int ipr_change_queue_depth(struct scsi_device *sdev, int qdepth)
  2389. {
  2390. scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), qdepth);
  2391. return sdev->queue_depth;
  2392. }
  2393. /**
  2394. * ipr_change_queue_type - Change the device's queue type
  2395. * @dsev: scsi device struct
  2396. * @tag_type: type of tags to use
  2397. *
  2398. * Return value:
  2399. * actual queue type set
  2400. **/
  2401. static int ipr_change_queue_type(struct scsi_device *sdev, int tag_type)
  2402. {
  2403. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)sdev->host->hostdata;
  2404. struct ipr_resource_entry *res;
  2405. unsigned long lock_flags = 0;
  2406. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  2407. res = (struct ipr_resource_entry *)sdev->hostdata;
  2408. if (res) {
  2409. if (ipr_is_gscsi(res) && sdev->tagged_supported) {
  2410. /*
  2411. * We don't bother quiescing the device here since the
  2412. * adapter firmware does it for us.
  2413. */
  2414. scsi_set_tag_type(sdev, tag_type);
  2415. if (tag_type)
  2416. scsi_activate_tcq(sdev, sdev->queue_depth);
  2417. else
  2418. scsi_deactivate_tcq(sdev, sdev->queue_depth);
  2419. } else
  2420. tag_type = 0;
  2421. } else
  2422. tag_type = 0;
  2423. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2424. return tag_type;
  2425. }
  2426. /**
  2427. * ipr_show_adapter_handle - Show the adapter's resource handle for this device
  2428. * @dev: device struct
  2429. * @buf: buffer
  2430. *
  2431. * Return value:
  2432. * number of bytes printed to buffer
  2433. **/
  2434. static ssize_t ipr_show_adapter_handle(struct device *dev, struct device_attribute *attr, char *buf)
  2435. {
  2436. struct scsi_device *sdev = to_scsi_device(dev);
  2437. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)sdev->host->hostdata;
  2438. struct ipr_resource_entry *res;
  2439. unsigned long lock_flags = 0;
  2440. ssize_t len = -ENXIO;
  2441. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  2442. res = (struct ipr_resource_entry *)sdev->hostdata;
  2443. if (res)
  2444. len = snprintf(buf, PAGE_SIZE, "%08X\n", res->cfgte.res_handle);
  2445. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2446. return len;
  2447. }
  2448. static struct device_attribute ipr_adapter_handle_attr = {
  2449. .attr = {
  2450. .name = "adapter_handle",
  2451. .mode = S_IRUSR,
  2452. },
  2453. .show = ipr_show_adapter_handle
  2454. };
  2455. static struct device_attribute *ipr_dev_attrs[] = {
  2456. &ipr_adapter_handle_attr,
  2457. NULL,
  2458. };
  2459. /**
  2460. * ipr_biosparam - Return the HSC mapping
  2461. * @sdev: scsi device struct
  2462. * @block_device: block device pointer
  2463. * @capacity: capacity of the device
  2464. * @parm: Array containing returned HSC values.
  2465. *
  2466. * This function generates the HSC parms that fdisk uses.
  2467. * We want to make sure we return something that places partitions
  2468. * on 4k boundaries for best performance with the IOA.
  2469. *
  2470. * Return value:
  2471. * 0 on success
  2472. **/
  2473. static int ipr_biosparam(struct scsi_device *sdev,
  2474. struct block_device *block_device,
  2475. sector_t capacity, int *parm)
  2476. {
  2477. int heads, sectors;
  2478. sector_t cylinders;
  2479. heads = 128;
  2480. sectors = 32;
  2481. cylinders = capacity;
  2482. sector_div(cylinders, (128 * 32));
  2483. /* return result */
  2484. parm[0] = heads;
  2485. parm[1] = sectors;
  2486. parm[2] = cylinders;
  2487. return 0;
  2488. }
  2489. /**
  2490. * ipr_slave_destroy - Unconfigure a SCSI device
  2491. * @sdev: scsi device struct
  2492. *
  2493. * Return value:
  2494. * nothing
  2495. **/
  2496. static void ipr_slave_destroy(struct scsi_device *sdev)
  2497. {
  2498. struct ipr_resource_entry *res;
  2499. struct ipr_ioa_cfg *ioa_cfg;
  2500. unsigned long lock_flags = 0;
  2501. ioa_cfg = (struct ipr_ioa_cfg *) sdev->host->hostdata;
  2502. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  2503. res = (struct ipr_resource_entry *) sdev->hostdata;
  2504. if (res) {
  2505. sdev->hostdata = NULL;
  2506. res->sdev = NULL;
  2507. }
  2508. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2509. }
  2510. /**
  2511. * ipr_slave_configure - Configure a SCSI device
  2512. * @sdev: scsi device struct
  2513. *
  2514. * This function configures the specified scsi device.
  2515. *
  2516. * Return value:
  2517. * 0 on success
  2518. **/
  2519. static int ipr_slave_configure(struct scsi_device *sdev)
  2520. {
  2521. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *) sdev->host->hostdata;
  2522. struct ipr_resource_entry *res;
  2523. unsigned long lock_flags = 0;
  2524. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  2525. res = sdev->hostdata;
  2526. if (res) {
  2527. if (ipr_is_af_dasd_device(res))
  2528. sdev->type = TYPE_RAID;
  2529. if (ipr_is_af_dasd_device(res) || ipr_is_ioa_resource(res)) {
  2530. sdev->scsi_level = 4;
  2531. sdev->no_uld_attach = 1;
  2532. }
  2533. if (ipr_is_vset_device(res)) {
  2534. sdev->timeout = IPR_VSET_RW_TIMEOUT;
  2535. blk_queue_max_sectors(sdev->request_queue, IPR_VSET_MAX_SECTORS);
  2536. }
  2537. if (IPR_IS_DASD_DEVICE(res->cfgte.std_inq_data))
  2538. sdev->allow_restart = 1;
  2539. scsi_adjust_queue_depth(sdev, 0, sdev->host->cmd_per_lun);
  2540. }
  2541. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2542. return 0;
  2543. }
  2544. /**
  2545. * ipr_slave_alloc - Prepare for commands to a device.
  2546. * @sdev: scsi device struct
  2547. *
  2548. * This function saves a pointer to the resource entry
  2549. * in the scsi device struct if the device exists. We
  2550. * can then use this pointer in ipr_queuecommand when
  2551. * handling new commands.
  2552. *
  2553. * Return value:
  2554. * 0 on success / -ENXIO if device does not exist
  2555. **/
  2556. static int ipr_slave_alloc(struct scsi_device *sdev)
  2557. {
  2558. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *) sdev->host->hostdata;
  2559. struct ipr_resource_entry *res;
  2560. unsigned long lock_flags;
  2561. int rc = -ENXIO;
  2562. sdev->hostdata = NULL;
  2563. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  2564. list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
  2565. if ((res->cfgte.res_addr.bus == sdev->channel) &&
  2566. (res->cfgte.res_addr.target == sdev->id) &&
  2567. (res->cfgte.res_addr.lun == sdev->lun)) {
  2568. res->sdev = sdev;
  2569. res->add_to_ml = 0;
  2570. res->in_erp = 0;
  2571. sdev->hostdata = res;
  2572. res->needs_sync_complete = 1;
  2573. rc = 0;
  2574. break;
  2575. }
  2576. }
  2577. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2578. return rc;
  2579. }
  2580. /**
  2581. * ipr_eh_host_reset - Reset the host adapter
  2582. * @scsi_cmd: scsi command struct
  2583. *
  2584. * Return value:
  2585. * SUCCESS / FAILED
  2586. **/
  2587. static int __ipr_eh_host_reset(struct scsi_cmnd * scsi_cmd)
  2588. {
  2589. struct ipr_ioa_cfg *ioa_cfg;
  2590. int rc;
  2591. ENTER;
  2592. ioa_cfg = (struct ipr_ioa_cfg *) scsi_cmd->device->host->hostdata;
  2593. dev_err(&ioa_cfg->pdev->dev,
  2594. "Adapter being reset as a result of error recovery.\n");
  2595. if (WAIT_FOR_DUMP == ioa_cfg->sdt_state)
  2596. ioa_cfg->sdt_state = GET_DUMP;
  2597. rc = ipr_reset_reload(ioa_cfg, IPR_SHUTDOWN_ABBREV);
  2598. LEAVE;
  2599. return rc;
  2600. }
  2601. static int ipr_eh_host_reset(struct scsi_cmnd * cmd)
  2602. {
  2603. int rc;
  2604. spin_lock_irq(cmd->device->host->host_lock);
  2605. rc = __ipr_eh_host_reset(cmd);
  2606. spin_unlock_irq(cmd->device->host->host_lock);
  2607. return rc;
  2608. }
  2609. /**
  2610. * ipr_eh_dev_reset - Reset the device
  2611. * @scsi_cmd: scsi command struct
  2612. *
  2613. * This function issues a device reset to the affected device.
  2614. * A LUN reset will be sent to the device first. If that does
  2615. * not work, a target reset will be sent.
  2616. *
  2617. * Return value:
  2618. * SUCCESS / FAILED
  2619. **/
  2620. static int __ipr_eh_dev_reset(struct scsi_cmnd * scsi_cmd)
  2621. {
  2622. struct ipr_cmnd *ipr_cmd;
  2623. struct ipr_ioa_cfg *ioa_cfg;
  2624. struct ipr_resource_entry *res;
  2625. struct ipr_cmd_pkt *cmd_pkt;
  2626. u32 ioasc;
  2627. ENTER;
  2628. ioa_cfg = (struct ipr_ioa_cfg *) scsi_cmd->device->host->hostdata;
  2629. res = scsi_cmd->device->hostdata;
  2630. if (!res || (!ipr_is_gscsi(res) && !ipr_is_vset_device(res)))
  2631. return FAILED;
  2632. /*
  2633. * If we are currently going through reset/reload, return failed. This will force the
  2634. * mid-layer to call ipr_eh_host_reset, which will then go to sleep and wait for the
  2635. * reset to complete
  2636. */
  2637. if (ioa_cfg->in_reset_reload)
  2638. return FAILED;
  2639. if (ioa_cfg->ioa_is_dead)
  2640. return FAILED;
  2641. list_for_each_entry(ipr_cmd, &ioa_cfg->pending_q, queue) {
  2642. if (ipr_cmd->ioarcb.res_handle == res->cfgte.res_handle) {
  2643. if (ipr_cmd->scsi_cmd)
  2644. ipr_cmd->done = ipr_scsi_eh_done;
  2645. }
  2646. }
  2647. res->resetting_device = 1;
  2648. ipr_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
  2649. ipr_cmd->ioarcb.res_handle = res->cfgte.res_handle;
  2650. cmd_pkt = &ipr_cmd->ioarcb.cmd_pkt;
  2651. cmd_pkt->request_type = IPR_RQTYPE_IOACMD;
  2652. cmd_pkt->cdb[0] = IPR_RESET_DEVICE;
  2653. ipr_sdev_err(scsi_cmd->device, "Resetting device\n");
  2654. ipr_send_blocking_cmd(ipr_cmd, ipr_timeout, IPR_DEVICE_RESET_TIMEOUT);
  2655. ioasc = be32_to_cpu(ipr_cmd->ioasa.ioasc);
  2656. res->resetting_device = 0;
  2657. list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
  2658. LEAVE;
  2659. return (IPR_IOASC_SENSE_KEY(ioasc) ? FAILED : SUCCESS);
  2660. }
  2661. static int ipr_eh_dev_reset(struct scsi_cmnd * cmd)
  2662. {
  2663. int rc;
  2664. spin_lock_irq(cmd->device->host->host_lock);
  2665. rc = __ipr_eh_dev_reset(cmd);
  2666. spin_unlock_irq(cmd->device->host->host_lock);
  2667. return rc;
  2668. }
  2669. /**
  2670. * ipr_bus_reset_done - Op done function for bus reset.
  2671. * @ipr_cmd: ipr command struct
  2672. *
  2673. * This function is the op done function for a bus reset
  2674. *
  2675. * Return value:
  2676. * none
  2677. **/
  2678. static void ipr_bus_reset_done(struct ipr_cmnd *ipr_cmd)
  2679. {
  2680. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  2681. struct ipr_resource_entry *res;
  2682. ENTER;
  2683. list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
  2684. if (!memcmp(&res->cfgte.res_handle, &ipr_cmd->ioarcb.res_handle,
  2685. sizeof(res->cfgte.res_handle))) {
  2686. scsi_report_bus_reset(ioa_cfg->host, res->cfgte.res_addr.bus);
  2687. break;
  2688. }
  2689. }
  2690. /*
  2691. * If abort has not completed, indicate the reset has, else call the
  2692. * abort's done function to wake the sleeping eh thread
  2693. */
  2694. if (ipr_cmd->sibling->sibling)
  2695. ipr_cmd->sibling->sibling = NULL;
  2696. else
  2697. ipr_cmd->sibling->done(ipr_cmd->sibling);
  2698. list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
  2699. LEAVE;
  2700. }
  2701. /**
  2702. * ipr_abort_timeout - An abort task has timed out
  2703. * @ipr_cmd: ipr command struct
  2704. *
  2705. * This function handles when an abort task times out. If this
  2706. * happens we issue a bus reset since we have resources tied
  2707. * up that must be freed before returning to the midlayer.
  2708. *
  2709. * Return value:
  2710. * none
  2711. **/
  2712. static void ipr_abort_timeout(struct ipr_cmnd *ipr_cmd)
  2713. {
  2714. struct ipr_cmnd *reset_cmd;
  2715. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  2716. struct ipr_cmd_pkt *cmd_pkt;
  2717. unsigned long lock_flags = 0;
  2718. ENTER;
  2719. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  2720. if (ipr_cmd->completion.done || ioa_cfg->in_reset_reload) {
  2721. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2722. return;
  2723. }
  2724. ipr_sdev_err(ipr_cmd->u.sdev, "Abort timed out. Resetting bus\n");
  2725. reset_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
  2726. ipr_cmd->sibling = reset_cmd;
  2727. reset_cmd->sibling = ipr_cmd;
  2728. reset_cmd->ioarcb.res_handle = ipr_cmd->ioarcb.res_handle;
  2729. cmd_pkt = &reset_cmd->ioarcb.cmd_pkt;
  2730. cmd_pkt->request_type = IPR_RQTYPE_IOACMD;
  2731. cmd_pkt->cdb[0] = IPR_RESET_DEVICE;
  2732. cmd_pkt->cdb[2] = IPR_RESET_TYPE_SELECT | IPR_BUS_RESET;
  2733. ipr_do_req(reset_cmd, ipr_bus_reset_done, ipr_timeout, IPR_DEVICE_RESET_TIMEOUT);
  2734. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2735. LEAVE;
  2736. }
  2737. /**
  2738. * ipr_cancel_op - Cancel specified op
  2739. * @scsi_cmd: scsi command struct
  2740. *
  2741. * This function cancels specified op.
  2742. *
  2743. * Return value:
  2744. * SUCCESS / FAILED
  2745. **/
  2746. static int ipr_cancel_op(struct scsi_cmnd * scsi_cmd)
  2747. {
  2748. struct ipr_cmnd *ipr_cmd;
  2749. struct ipr_ioa_cfg *ioa_cfg;
  2750. struct ipr_resource_entry *res;
  2751. struct ipr_cmd_pkt *cmd_pkt;
  2752. u32 ioasc;
  2753. int op_found = 0;
  2754. ENTER;
  2755. ioa_cfg = (struct ipr_ioa_cfg *)scsi_cmd->device->host->hostdata;
  2756. res = scsi_cmd->device->hostdata;
  2757. /* If we are currently going through reset/reload, return failed.
  2758. * This will force the mid-layer to call ipr_eh_host_reset,
  2759. * which will then go to sleep and wait for the reset to complete
  2760. */
  2761. if (ioa_cfg->in_reset_reload || ioa_cfg->ioa_is_dead)
  2762. return FAILED;
  2763. if (!res || (!ipr_is_gscsi(res) && !ipr_is_vset_device(res)))
  2764. return FAILED;
  2765. list_for_each_entry(ipr_cmd, &ioa_cfg->pending_q, queue) {
  2766. if (ipr_cmd->scsi_cmd == scsi_cmd) {
  2767. ipr_cmd->done = ipr_scsi_eh_done;
  2768. op_found = 1;
  2769. break;
  2770. }
  2771. }
  2772. if (!op_found)
  2773. return SUCCESS;
  2774. ipr_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
  2775. ipr_cmd->ioarcb.res_handle = res->cfgte.res_handle;
  2776. cmd_pkt = &ipr_cmd->ioarcb.cmd_pkt;
  2777. cmd_pkt->request_type = IPR_RQTYPE_IOACMD;
  2778. cmd_pkt->cdb[0] = IPR_CANCEL_ALL_REQUESTS;
  2779. ipr_cmd->u.sdev = scsi_cmd->device;
  2780. ipr_sdev_err(scsi_cmd->device, "Aborting command: %02X\n", scsi_cmd->cmnd[0]);
  2781. ipr_send_blocking_cmd(ipr_cmd, ipr_abort_timeout, IPR_CANCEL_ALL_TIMEOUT);
  2782. ioasc = be32_to_cpu(ipr_cmd->ioasa.ioasc);
  2783. /*
  2784. * If the abort task timed out and we sent a bus reset, we will get
  2785. * one the following responses to the abort
  2786. */
  2787. if (ioasc == IPR_IOASC_BUS_WAS_RESET || ioasc == IPR_IOASC_SYNC_REQUIRED) {
  2788. ioasc = 0;
  2789. ipr_trace;
  2790. }
  2791. list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
  2792. res->needs_sync_complete = 1;
  2793. LEAVE;
  2794. return (IPR_IOASC_SENSE_KEY(ioasc) ? FAILED : SUCCESS);
  2795. }
  2796. /**
  2797. * ipr_eh_abort - Abort a single op
  2798. * @scsi_cmd: scsi command struct
  2799. *
  2800. * Return value:
  2801. * SUCCESS / FAILED
  2802. **/
  2803. static int ipr_eh_abort(struct scsi_cmnd * scsi_cmd)
  2804. {
  2805. unsigned long flags;
  2806. int rc;
  2807. ENTER;
  2808. spin_lock_irqsave(scsi_cmd->device->host->host_lock, flags);
  2809. rc = ipr_cancel_op(scsi_cmd);
  2810. spin_unlock_irqrestore(scsi_cmd->device->host->host_lock, flags);
  2811. LEAVE;
  2812. return rc;
  2813. }
  2814. /**
  2815. * ipr_handle_other_interrupt - Handle "other" interrupts
  2816. * @ioa_cfg: ioa config struct
  2817. * @int_reg: interrupt register
  2818. *
  2819. * Return value:
  2820. * IRQ_NONE / IRQ_HANDLED
  2821. **/
  2822. static irqreturn_t ipr_handle_other_interrupt(struct ipr_ioa_cfg *ioa_cfg,
  2823. volatile u32 int_reg)
  2824. {
  2825. irqreturn_t rc = IRQ_HANDLED;
  2826. if (int_reg & IPR_PCII_IOA_TRANS_TO_OPER) {
  2827. /* Mask the interrupt */
  2828. writel(IPR_PCII_IOA_TRANS_TO_OPER, ioa_cfg->regs.set_interrupt_mask_reg);
  2829. /* Clear the interrupt */
  2830. writel(IPR_PCII_IOA_TRANS_TO_OPER, ioa_cfg->regs.clr_interrupt_reg);
  2831. int_reg = readl(ioa_cfg->regs.sense_interrupt_reg);
  2832. list_del(&ioa_cfg->reset_cmd->queue);
  2833. del_timer(&ioa_cfg->reset_cmd->timer);
  2834. ipr_reset_ioa_job(ioa_cfg->reset_cmd);
  2835. } else {
  2836. if (int_reg & IPR_PCII_IOA_UNIT_CHECKED)
  2837. ioa_cfg->ioa_unit_checked = 1;
  2838. else
  2839. dev_err(&ioa_cfg->pdev->dev,
  2840. "Permanent IOA failure. 0x%08X\n", int_reg);
  2841. if (WAIT_FOR_DUMP == ioa_cfg->sdt_state)
  2842. ioa_cfg->sdt_state = GET_DUMP;
  2843. ipr_mask_and_clear_interrupts(ioa_cfg, ~0);
  2844. ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
  2845. }
  2846. return rc;
  2847. }
  2848. /**
  2849. * ipr_isr - Interrupt service routine
  2850. * @irq: irq number
  2851. * @devp: pointer to ioa config struct
  2852. * @regs: pt_regs struct
  2853. *
  2854. * Return value:
  2855. * IRQ_NONE / IRQ_HANDLED
  2856. **/
  2857. static irqreturn_t ipr_isr(int irq, void *devp, struct pt_regs *regs)
  2858. {
  2859. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)devp;
  2860. unsigned long lock_flags = 0;
  2861. volatile u32 int_reg, int_mask_reg;
  2862. u32 ioasc;
  2863. u16 cmd_index;
  2864. struct ipr_cmnd *ipr_cmd;
  2865. irqreturn_t rc = IRQ_NONE;
  2866. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  2867. /* If interrupts are disabled, ignore the interrupt */
  2868. if (!ioa_cfg->allow_interrupts) {
  2869. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2870. return IRQ_NONE;
  2871. }
  2872. int_mask_reg = readl(ioa_cfg->regs.sense_interrupt_mask_reg);
  2873. int_reg = readl(ioa_cfg->regs.sense_interrupt_reg) & ~int_mask_reg;
  2874. /* If an interrupt on the adapter did not occur, ignore it */
  2875. if (unlikely((int_reg & IPR_PCII_OPER_INTERRUPTS) == 0)) {
  2876. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2877. return IRQ_NONE;
  2878. }
  2879. while (1) {
  2880. ipr_cmd = NULL;
  2881. while ((be32_to_cpu(*ioa_cfg->hrrq_curr) & IPR_HRRQ_TOGGLE_BIT) ==
  2882. ioa_cfg->toggle_bit) {
  2883. cmd_index = (be32_to_cpu(*ioa_cfg->hrrq_curr) &
  2884. IPR_HRRQ_REQ_RESP_HANDLE_MASK) >> IPR_HRRQ_REQ_RESP_HANDLE_SHIFT;
  2885. if (unlikely(cmd_index >= IPR_NUM_CMD_BLKS)) {
  2886. ioa_cfg->errors_logged++;
  2887. dev_err(&ioa_cfg->pdev->dev, "Invalid response handle from IOA\n");
  2888. if (WAIT_FOR_DUMP == ioa_cfg->sdt_state)
  2889. ioa_cfg->sdt_state = GET_DUMP;
  2890. ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
  2891. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2892. return IRQ_HANDLED;
  2893. }
  2894. ipr_cmd = ioa_cfg->ipr_cmnd_list[cmd_index];
  2895. ioasc = be32_to_cpu(ipr_cmd->ioasa.ioasc);
  2896. ipr_trc_hook(ipr_cmd, IPR_TRACE_FINISH, ioasc);
  2897. list_del(&ipr_cmd->queue);
  2898. del_timer(&ipr_cmd->timer);
  2899. ipr_cmd->done(ipr_cmd);
  2900. rc = IRQ_HANDLED;
  2901. if (ioa_cfg->hrrq_curr < ioa_cfg->hrrq_end) {
  2902. ioa_cfg->hrrq_curr++;
  2903. } else {
  2904. ioa_cfg->hrrq_curr = ioa_cfg->hrrq_start;
  2905. ioa_cfg->toggle_bit ^= 1u;
  2906. }
  2907. }
  2908. if (ipr_cmd != NULL) {
  2909. /* Clear the PCI interrupt */
  2910. writel(IPR_PCII_HRRQ_UPDATED, ioa_cfg->regs.clr_interrupt_reg);
  2911. int_reg = readl(ioa_cfg->regs.sense_interrupt_reg) & ~int_mask_reg;
  2912. } else
  2913. break;
  2914. }
  2915. if (unlikely(rc == IRQ_NONE))
  2916. rc = ipr_handle_other_interrupt(ioa_cfg, int_reg);
  2917. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2918. return rc;
  2919. }
  2920. /**
  2921. * ipr_build_ioadl - Build a scatter/gather list and map the buffer
  2922. * @ioa_cfg: ioa config struct
  2923. * @ipr_cmd: ipr command struct
  2924. *
  2925. * Return value:
  2926. * 0 on success / -1 on failure
  2927. **/
  2928. static int ipr_build_ioadl(struct ipr_ioa_cfg *ioa_cfg,
  2929. struct ipr_cmnd *ipr_cmd)
  2930. {
  2931. int i;
  2932. struct scatterlist *sglist;
  2933. u32 length;
  2934. u32 ioadl_flags = 0;
  2935. struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
  2936. struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
  2937. struct ipr_ioadl_desc *ioadl = ipr_cmd->ioadl;
  2938. length = scsi_cmd->request_bufflen;
  2939. if (length == 0)
  2940. return 0;
  2941. if (scsi_cmd->use_sg) {
  2942. ipr_cmd->dma_use_sg = pci_map_sg(ioa_cfg->pdev,
  2943. scsi_cmd->request_buffer,
  2944. scsi_cmd->use_sg,
  2945. scsi_cmd->sc_data_direction);
  2946. if (scsi_cmd->sc_data_direction == DMA_TO_DEVICE) {
  2947. ioadl_flags = IPR_IOADL_FLAGS_WRITE;
  2948. ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
  2949. ioarcb->write_data_transfer_length = cpu_to_be32(length);
  2950. ioarcb->write_ioadl_len =
  2951. cpu_to_be32(sizeof(struct ipr_ioadl_desc) * ipr_cmd->dma_use_sg);
  2952. } else if (scsi_cmd->sc_data_direction == DMA_FROM_DEVICE) {
  2953. ioadl_flags = IPR_IOADL_FLAGS_READ;
  2954. ioarcb->read_data_transfer_length = cpu_to_be32(length);
  2955. ioarcb->read_ioadl_len =
  2956. cpu_to_be32(sizeof(struct ipr_ioadl_desc) * ipr_cmd->dma_use_sg);
  2957. }
  2958. sglist = scsi_cmd->request_buffer;
  2959. for (i = 0; i < ipr_cmd->dma_use_sg; i++) {
  2960. ioadl[i].flags_and_data_len =
  2961. cpu_to_be32(ioadl_flags | sg_dma_len(&sglist[i]));
  2962. ioadl[i].address =
  2963. cpu_to_be32(sg_dma_address(&sglist[i]));
  2964. }
  2965. if (likely(ipr_cmd->dma_use_sg)) {
  2966. ioadl[i-1].flags_and_data_len |=
  2967. cpu_to_be32(IPR_IOADL_FLAGS_LAST);
  2968. return 0;
  2969. } else
  2970. dev_err(&ioa_cfg->pdev->dev, "pci_map_sg failed!\n");
  2971. } else {
  2972. if (scsi_cmd->sc_data_direction == DMA_TO_DEVICE) {
  2973. ioadl_flags = IPR_IOADL_FLAGS_WRITE;
  2974. ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
  2975. ioarcb->write_data_transfer_length = cpu_to_be32(length);
  2976. ioarcb->write_ioadl_len = cpu_to_be32(sizeof(struct ipr_ioadl_desc));
  2977. } else if (scsi_cmd->sc_data_direction == DMA_FROM_DEVICE) {
  2978. ioadl_flags = IPR_IOADL_FLAGS_READ;
  2979. ioarcb->read_data_transfer_length = cpu_to_be32(length);
  2980. ioarcb->read_ioadl_len = cpu_to_be32(sizeof(struct ipr_ioadl_desc));
  2981. }
  2982. ipr_cmd->dma_handle = pci_map_single(ioa_cfg->pdev,
  2983. scsi_cmd->request_buffer, length,
  2984. scsi_cmd->sc_data_direction);
  2985. if (likely(!pci_dma_mapping_error(ipr_cmd->dma_handle))) {
  2986. ipr_cmd->dma_use_sg = 1;
  2987. ioadl[0].flags_and_data_len =
  2988. cpu_to_be32(ioadl_flags | length | IPR_IOADL_FLAGS_LAST);
  2989. ioadl[0].address = cpu_to_be32(ipr_cmd->dma_handle);
  2990. return 0;
  2991. } else
  2992. dev_err(&ioa_cfg->pdev->dev, "pci_map_single failed!\n");
  2993. }
  2994. return -1;
  2995. }
  2996. /**
  2997. * ipr_get_task_attributes - Translate SPI Q-Tag to task attributes
  2998. * @scsi_cmd: scsi command struct
  2999. *
  3000. * Return value:
  3001. * task attributes
  3002. **/
  3003. static u8 ipr_get_task_attributes(struct scsi_cmnd *scsi_cmd)
  3004. {
  3005. u8 tag[2];
  3006. u8 rc = IPR_FLAGS_LO_UNTAGGED_TASK;
  3007. if (scsi_populate_tag_msg(scsi_cmd, tag)) {
  3008. switch (tag[0]) {
  3009. case MSG_SIMPLE_TAG:
  3010. rc = IPR_FLAGS_LO_SIMPLE_TASK;
  3011. break;
  3012. case MSG_HEAD_TAG:
  3013. rc = IPR_FLAGS_LO_HEAD_OF_Q_TASK;
  3014. break;
  3015. case MSG_ORDERED_TAG:
  3016. rc = IPR_FLAGS_LO_ORDERED_TASK;
  3017. break;
  3018. };
  3019. }
  3020. return rc;
  3021. }
  3022. /**
  3023. * ipr_erp_done - Process completion of ERP for a device
  3024. * @ipr_cmd: ipr command struct
  3025. *
  3026. * This function copies the sense buffer into the scsi_cmd
  3027. * struct and pushes the scsi_done function.
  3028. *
  3029. * Return value:
  3030. * nothing
  3031. **/
  3032. static void ipr_erp_done(struct ipr_cmnd *ipr_cmd)
  3033. {
  3034. struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
  3035. struct ipr_resource_entry *res = scsi_cmd->device->hostdata;
  3036. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  3037. u32 ioasc = be32_to_cpu(ipr_cmd->ioasa.ioasc);
  3038. if (IPR_IOASC_SENSE_KEY(ioasc) > 0) {
  3039. scsi_cmd->result |= (DID_ERROR << 16);
  3040. ipr_sdev_err(scsi_cmd->device,
  3041. "Request Sense failed with IOASC: 0x%08X\n", ioasc);
  3042. } else {
  3043. memcpy(scsi_cmd->sense_buffer, ipr_cmd->sense_buffer,
  3044. SCSI_SENSE_BUFFERSIZE);
  3045. }
  3046. if (res) {
  3047. res->needs_sync_complete = 1;
  3048. res->in_erp = 0;
  3049. }
  3050. ipr_unmap_sglist(ioa_cfg, ipr_cmd);
  3051. list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
  3052. scsi_cmd->scsi_done(scsi_cmd);
  3053. }
  3054. /**
  3055. * ipr_reinit_ipr_cmnd_for_erp - Re-initialize a cmnd block to be used for ERP
  3056. * @ipr_cmd: ipr command struct
  3057. *
  3058. * Return value:
  3059. * none
  3060. **/
  3061. static void ipr_reinit_ipr_cmnd_for_erp(struct ipr_cmnd *ipr_cmd)
  3062. {
  3063. struct ipr_ioarcb *ioarcb;
  3064. struct ipr_ioasa *ioasa;
  3065. ioarcb = &ipr_cmd->ioarcb;
  3066. ioasa = &ipr_cmd->ioasa;
  3067. memset(&ioarcb->cmd_pkt, 0, sizeof(struct ipr_cmd_pkt));
  3068. ioarcb->write_data_transfer_length = 0;
  3069. ioarcb->read_data_transfer_length = 0;
  3070. ioarcb->write_ioadl_len = 0;
  3071. ioarcb->read_ioadl_len = 0;
  3072. ioasa->ioasc = 0;
  3073. ioasa->residual_data_len = 0;
  3074. }
  3075. /**
  3076. * ipr_erp_request_sense - Send request sense to a device
  3077. * @ipr_cmd: ipr command struct
  3078. *
  3079. * This function sends a request sense to a device as a result
  3080. * of a check condition.
  3081. *
  3082. * Return value:
  3083. * nothing
  3084. **/
  3085. static void ipr_erp_request_sense(struct ipr_cmnd *ipr_cmd)
  3086. {
  3087. struct ipr_cmd_pkt *cmd_pkt = &ipr_cmd->ioarcb.cmd_pkt;
  3088. u32 ioasc = be32_to_cpu(ipr_cmd->ioasa.ioasc);
  3089. if (IPR_IOASC_SENSE_KEY(ioasc) > 0) {
  3090. ipr_erp_done(ipr_cmd);
  3091. return;
  3092. }
  3093. ipr_reinit_ipr_cmnd_for_erp(ipr_cmd);
  3094. cmd_pkt->request_type = IPR_RQTYPE_SCSICDB;
  3095. cmd_pkt->cdb[0] = REQUEST_SENSE;
  3096. cmd_pkt->cdb[4] = SCSI_SENSE_BUFFERSIZE;
  3097. cmd_pkt->flags_hi |= IPR_FLAGS_HI_SYNC_OVERRIDE;
  3098. cmd_pkt->flags_hi |= IPR_FLAGS_HI_NO_ULEN_CHK;
  3099. cmd_pkt->timeout = cpu_to_be16(IPR_REQUEST_SENSE_TIMEOUT / HZ);
  3100. ipr_cmd->ioadl[0].flags_and_data_len =
  3101. cpu_to_be32(IPR_IOADL_FLAGS_READ_LAST | SCSI_SENSE_BUFFERSIZE);
  3102. ipr_cmd->ioadl[0].address =
  3103. cpu_to_be32(ipr_cmd->sense_buffer_dma);
  3104. ipr_cmd->ioarcb.read_ioadl_len =
  3105. cpu_to_be32(sizeof(struct ipr_ioadl_desc));
  3106. ipr_cmd->ioarcb.read_data_transfer_length =
  3107. cpu_to_be32(SCSI_SENSE_BUFFERSIZE);
  3108. ipr_do_req(ipr_cmd, ipr_erp_done, ipr_timeout,
  3109. IPR_REQUEST_SENSE_TIMEOUT * 2);
  3110. }
  3111. /**
  3112. * ipr_erp_cancel_all - Send cancel all to a device
  3113. * @ipr_cmd: ipr command struct
  3114. *
  3115. * This function sends a cancel all to a device to clear the
  3116. * queue. If we are running TCQ on the device, QERR is set to 1,
  3117. * which means all outstanding ops have been dropped on the floor.
  3118. * Cancel all will return them to us.
  3119. *
  3120. * Return value:
  3121. * nothing
  3122. **/
  3123. static void ipr_erp_cancel_all(struct ipr_cmnd *ipr_cmd)
  3124. {
  3125. struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
  3126. struct ipr_resource_entry *res = scsi_cmd->device->hostdata;
  3127. struct ipr_cmd_pkt *cmd_pkt;
  3128. res->in_erp = 1;
  3129. ipr_reinit_ipr_cmnd_for_erp(ipr_cmd);
  3130. if (!scsi_get_tag_type(scsi_cmd->device)) {
  3131. ipr_erp_request_sense(ipr_cmd);
  3132. return;
  3133. }
  3134. cmd_pkt = &ipr_cmd->ioarcb.cmd_pkt;
  3135. cmd_pkt->request_type = IPR_RQTYPE_IOACMD;
  3136. cmd_pkt->cdb[0] = IPR_CANCEL_ALL_REQUESTS;
  3137. ipr_do_req(ipr_cmd, ipr_erp_request_sense, ipr_timeout,
  3138. IPR_CANCEL_ALL_TIMEOUT);
  3139. }
  3140. /**
  3141. * ipr_dump_ioasa - Dump contents of IOASA
  3142. * @ioa_cfg: ioa config struct
  3143. * @ipr_cmd: ipr command struct
  3144. *
  3145. * This function is invoked by the interrupt handler when ops
  3146. * fail. It will log the IOASA if appropriate. Only called
  3147. * for GPDD ops.
  3148. *
  3149. * Return value:
  3150. * none
  3151. **/
  3152. static void ipr_dump_ioasa(struct ipr_ioa_cfg *ioa_cfg,
  3153. struct ipr_cmnd *ipr_cmd)
  3154. {
  3155. int i;
  3156. u16 data_len;
  3157. u32 ioasc;
  3158. struct ipr_ioasa *ioasa = &ipr_cmd->ioasa;
  3159. __be32 *ioasa_data = (__be32 *)ioasa;
  3160. int error_index;
  3161. ioasc = be32_to_cpu(ioasa->ioasc) & IPR_IOASC_IOASC_MASK;
  3162. if (0 == ioasc)
  3163. return;
  3164. if (ioa_cfg->log_level < IPR_DEFAULT_LOG_LEVEL)
  3165. return;
  3166. error_index = ipr_get_error(ioasc);
  3167. if (ioa_cfg->log_level < IPR_MAX_LOG_LEVEL) {
  3168. /* Don't log an error if the IOA already logged one */
  3169. if (ioasa->ilid != 0)
  3170. return;
  3171. if (ipr_error_table[error_index].log_ioasa == 0)
  3172. return;
  3173. }
  3174. ipr_sdev_err(ipr_cmd->scsi_cmd->device, "%s\n",
  3175. ipr_error_table[error_index].error);
  3176. if ((ioasa->u.gpdd.end_state <= ARRAY_SIZE(ipr_gpdd_dev_end_states)) &&
  3177. (ioasa->u.gpdd.bus_phase <= ARRAY_SIZE(ipr_gpdd_dev_bus_phases))) {
  3178. ipr_sdev_err(ipr_cmd->scsi_cmd->device,
  3179. "Device End state: %s Phase: %s\n",
  3180. ipr_gpdd_dev_end_states[ioasa->u.gpdd.end_state],
  3181. ipr_gpdd_dev_bus_phases[ioasa->u.gpdd.bus_phase]);
  3182. }
  3183. if (sizeof(struct ipr_ioasa) < be16_to_cpu(ioasa->ret_stat_len))
  3184. data_len = sizeof(struct ipr_ioasa);
  3185. else
  3186. data_len = be16_to_cpu(ioasa->ret_stat_len);
  3187. ipr_err("IOASA Dump:\n");
  3188. for (i = 0; i < data_len / 4; i += 4) {
  3189. ipr_err("%08X: %08X %08X %08X %08X\n", i*4,
  3190. be32_to_cpu(ioasa_data[i]),
  3191. be32_to_cpu(ioasa_data[i+1]),
  3192. be32_to_cpu(ioasa_data[i+2]),
  3193. be32_to_cpu(ioasa_data[i+3]));
  3194. }
  3195. }
  3196. /**
  3197. * ipr_gen_sense - Generate SCSI sense data from an IOASA
  3198. * @ioasa: IOASA
  3199. * @sense_buf: sense data buffer
  3200. *
  3201. * Return value:
  3202. * none
  3203. **/
  3204. static void ipr_gen_sense(struct ipr_cmnd *ipr_cmd)
  3205. {
  3206. u32 failing_lba;
  3207. u8 *sense_buf = ipr_cmd->scsi_cmd->sense_buffer;
  3208. struct ipr_resource_entry *res = ipr_cmd->scsi_cmd->device->hostdata;
  3209. struct ipr_ioasa *ioasa = &ipr_cmd->ioasa;
  3210. u32 ioasc = be32_to_cpu(ioasa->ioasc);
  3211. memset(sense_buf, 0, SCSI_SENSE_BUFFERSIZE);
  3212. if (ioasc >= IPR_FIRST_DRIVER_IOASC)
  3213. return;
  3214. ipr_cmd->scsi_cmd->result = SAM_STAT_CHECK_CONDITION;
  3215. if (ipr_is_vset_device(res) &&
  3216. ioasc == IPR_IOASC_MED_DO_NOT_REALLOC &&
  3217. ioasa->u.vset.failing_lba_hi != 0) {
  3218. sense_buf[0] = 0x72;
  3219. sense_buf[1] = IPR_IOASC_SENSE_KEY(ioasc);
  3220. sense_buf[2] = IPR_IOASC_SENSE_CODE(ioasc);
  3221. sense_buf[3] = IPR_IOASC_SENSE_QUAL(ioasc);
  3222. sense_buf[7] = 12;
  3223. sense_buf[8] = 0;
  3224. sense_buf[9] = 0x0A;
  3225. sense_buf[10] = 0x80;
  3226. failing_lba = be32_to_cpu(ioasa->u.vset.failing_lba_hi);
  3227. sense_buf[12] = (failing_lba & 0xff000000) >> 24;
  3228. sense_buf[13] = (failing_lba & 0x00ff0000) >> 16;
  3229. sense_buf[14] = (failing_lba & 0x0000ff00) >> 8;
  3230. sense_buf[15] = failing_lba & 0x000000ff;
  3231. failing_lba = be32_to_cpu(ioasa->u.vset.failing_lba_lo);
  3232. sense_buf[16] = (failing_lba & 0xff000000) >> 24;
  3233. sense_buf[17] = (failing_lba & 0x00ff0000) >> 16;
  3234. sense_buf[18] = (failing_lba & 0x0000ff00) >> 8;
  3235. sense_buf[19] = failing_lba & 0x000000ff;
  3236. } else {
  3237. sense_buf[0] = 0x70;
  3238. sense_buf[2] = IPR_IOASC_SENSE_KEY(ioasc);
  3239. sense_buf[12] = IPR_IOASC_SENSE_CODE(ioasc);
  3240. sense_buf[13] = IPR_IOASC_SENSE_QUAL(ioasc);
  3241. /* Illegal request */
  3242. if ((IPR_IOASC_SENSE_KEY(ioasc) == 0x05) &&
  3243. (be32_to_cpu(ioasa->ioasc_specific) & IPR_FIELD_POINTER_VALID)) {
  3244. sense_buf[7] = 10; /* additional length */
  3245. /* IOARCB was in error */
  3246. if (IPR_IOASC_SENSE_CODE(ioasc) == 0x24)
  3247. sense_buf[15] = 0xC0;
  3248. else /* Parameter data was invalid */
  3249. sense_buf[15] = 0x80;
  3250. sense_buf[16] =
  3251. ((IPR_FIELD_POINTER_MASK &
  3252. be32_to_cpu(ioasa->ioasc_specific)) >> 8) & 0xff;
  3253. sense_buf[17] =
  3254. (IPR_FIELD_POINTER_MASK &
  3255. be32_to_cpu(ioasa->ioasc_specific)) & 0xff;
  3256. } else {
  3257. if (ioasc == IPR_IOASC_MED_DO_NOT_REALLOC) {
  3258. if (ipr_is_vset_device(res))
  3259. failing_lba = be32_to_cpu(ioasa->u.vset.failing_lba_lo);
  3260. else
  3261. failing_lba = be32_to_cpu(ioasa->u.dasd.failing_lba);
  3262. sense_buf[0] |= 0x80; /* Or in the Valid bit */
  3263. sense_buf[3] = (failing_lba & 0xff000000) >> 24;
  3264. sense_buf[4] = (failing_lba & 0x00ff0000) >> 16;
  3265. sense_buf[5] = (failing_lba & 0x0000ff00) >> 8;
  3266. sense_buf[6] = failing_lba & 0x000000ff;
  3267. }
  3268. sense_buf[7] = 6; /* additional length */
  3269. }
  3270. }
  3271. }
  3272. /**
  3273. * ipr_erp_start - Process an error response for a SCSI op
  3274. * @ioa_cfg: ioa config struct
  3275. * @ipr_cmd: ipr command struct
  3276. *
  3277. * This function determines whether or not to initiate ERP
  3278. * on the affected device.
  3279. *
  3280. * Return value:
  3281. * nothing
  3282. **/
  3283. static void ipr_erp_start(struct ipr_ioa_cfg *ioa_cfg,
  3284. struct ipr_cmnd *ipr_cmd)
  3285. {
  3286. struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
  3287. struct ipr_resource_entry *res = scsi_cmd->device->hostdata;
  3288. u32 ioasc = be32_to_cpu(ipr_cmd->ioasa.ioasc);
  3289. if (!res) {
  3290. ipr_scsi_eh_done(ipr_cmd);
  3291. return;
  3292. }
  3293. if (ipr_is_gscsi(res))
  3294. ipr_dump_ioasa(ioa_cfg, ipr_cmd);
  3295. else
  3296. ipr_gen_sense(ipr_cmd);
  3297. switch (ioasc & IPR_IOASC_IOASC_MASK) {
  3298. case IPR_IOASC_ABORTED_CMD_TERM_BY_HOST:
  3299. scsi_cmd->result |= (DID_IMM_RETRY << 16);
  3300. break;
  3301. case IPR_IOASC_IR_RESOURCE_HANDLE:
  3302. scsi_cmd->result |= (DID_NO_CONNECT << 16);
  3303. break;
  3304. case IPR_IOASC_HW_SEL_TIMEOUT:
  3305. scsi_cmd->result |= (DID_NO_CONNECT << 16);
  3306. res->needs_sync_complete = 1;
  3307. break;
  3308. case IPR_IOASC_SYNC_REQUIRED:
  3309. if (!res->in_erp)
  3310. res->needs_sync_complete = 1;
  3311. scsi_cmd->result |= (DID_IMM_RETRY << 16);
  3312. break;
  3313. case IPR_IOASC_MED_DO_NOT_REALLOC: /* prevent retries */
  3314. scsi_cmd->result |= (DID_PASSTHROUGH << 16);
  3315. break;
  3316. case IPR_IOASC_BUS_WAS_RESET:
  3317. case IPR_IOASC_BUS_WAS_RESET_BY_OTHER:
  3318. /*
  3319. * Report the bus reset and ask for a retry. The device
  3320. * will give CC/UA the next command.
  3321. */
  3322. if (!res->resetting_device)
  3323. scsi_report_bus_reset(ioa_cfg->host, scsi_cmd->device->channel);
  3324. scsi_cmd->result |= (DID_ERROR << 16);
  3325. res->needs_sync_complete = 1;
  3326. break;
  3327. case IPR_IOASC_HW_DEV_BUS_STATUS:
  3328. scsi_cmd->result |= IPR_IOASC_SENSE_STATUS(ioasc);
  3329. if (IPR_IOASC_SENSE_STATUS(ioasc) == SAM_STAT_CHECK_CONDITION) {
  3330. ipr_erp_cancel_all(ipr_cmd);
  3331. return;
  3332. }
  3333. res->needs_sync_complete = 1;
  3334. break;
  3335. case IPR_IOASC_NR_INIT_CMD_REQUIRED:
  3336. break;
  3337. default:
  3338. scsi_cmd->result |= (DID_ERROR << 16);
  3339. if (!ipr_is_vset_device(res))
  3340. res->needs_sync_complete = 1;
  3341. break;
  3342. }
  3343. ipr_unmap_sglist(ioa_cfg, ipr_cmd);
  3344. list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
  3345. scsi_cmd->scsi_done(scsi_cmd);
  3346. }
  3347. /**
  3348. * ipr_scsi_done - mid-layer done function
  3349. * @ipr_cmd: ipr command struct
  3350. *
  3351. * This function is invoked by the interrupt handler for
  3352. * ops generated by the SCSI mid-layer
  3353. *
  3354. * Return value:
  3355. * none
  3356. **/
  3357. static void ipr_scsi_done(struct ipr_cmnd *ipr_cmd)
  3358. {
  3359. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  3360. struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
  3361. u32 ioasc = be32_to_cpu(ipr_cmd->ioasa.ioasc);
  3362. scsi_cmd->resid = be32_to_cpu(ipr_cmd->ioasa.residual_data_len);
  3363. if (likely(IPR_IOASC_SENSE_KEY(ioasc) == 0)) {
  3364. ipr_unmap_sglist(ioa_cfg, ipr_cmd);
  3365. list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
  3366. scsi_cmd->scsi_done(scsi_cmd);
  3367. } else
  3368. ipr_erp_start(ioa_cfg, ipr_cmd);
  3369. }
  3370. /**
  3371. * ipr_save_ioafp_mode_select - Save adapters mode select data
  3372. * @ioa_cfg: ioa config struct
  3373. * @scsi_cmd: scsi command struct
  3374. *
  3375. * This function saves mode select data for the adapter to
  3376. * use following an adapter reset.
  3377. *
  3378. * Return value:
  3379. * 0 on success / SCSI_MLQUEUE_HOST_BUSY on failure
  3380. **/
  3381. static int ipr_save_ioafp_mode_select(struct ipr_ioa_cfg *ioa_cfg,
  3382. struct scsi_cmnd *scsi_cmd)
  3383. {
  3384. if (!ioa_cfg->saved_mode_pages) {
  3385. ioa_cfg->saved_mode_pages = kmalloc(sizeof(struct ipr_mode_pages),
  3386. GFP_ATOMIC);
  3387. if (!ioa_cfg->saved_mode_pages) {
  3388. dev_err(&ioa_cfg->pdev->dev,
  3389. "IOA mode select buffer allocation failed\n");
  3390. return SCSI_MLQUEUE_HOST_BUSY;
  3391. }
  3392. }
  3393. memcpy(ioa_cfg->saved_mode_pages, scsi_cmd->buffer, scsi_cmd->cmnd[4]);
  3394. ioa_cfg->saved_mode_page_len = scsi_cmd->cmnd[4];
  3395. return 0;
  3396. }
  3397. /**
  3398. * ipr_queuecommand - Queue a mid-layer request
  3399. * @scsi_cmd: scsi command struct
  3400. * @done: done function
  3401. *
  3402. * This function queues a request generated by the mid-layer.
  3403. *
  3404. * Return value:
  3405. * 0 on success
  3406. * SCSI_MLQUEUE_DEVICE_BUSY if device is busy
  3407. * SCSI_MLQUEUE_HOST_BUSY if host is busy
  3408. **/
  3409. static int ipr_queuecommand(struct scsi_cmnd *scsi_cmd,
  3410. void (*done) (struct scsi_cmnd *))
  3411. {
  3412. struct ipr_ioa_cfg *ioa_cfg;
  3413. struct ipr_resource_entry *res;
  3414. struct ipr_ioarcb *ioarcb;
  3415. struct ipr_cmnd *ipr_cmd;
  3416. int rc = 0;
  3417. scsi_cmd->scsi_done = done;
  3418. ioa_cfg = (struct ipr_ioa_cfg *)scsi_cmd->device->host->hostdata;
  3419. res = scsi_cmd->device->hostdata;
  3420. scsi_cmd->result = (DID_OK << 16);
  3421. /*
  3422. * We are currently blocking all devices due to a host reset
  3423. * We have told the host to stop giving us new requests, but
  3424. * ERP ops don't count. FIXME
  3425. */
  3426. if (unlikely(!ioa_cfg->allow_cmds && !ioa_cfg->ioa_is_dead))
  3427. return SCSI_MLQUEUE_HOST_BUSY;
  3428. /*
  3429. * FIXME - Create scsi_set_host_offline interface
  3430. * and the ioa_is_dead check can be removed
  3431. */
  3432. if (unlikely(ioa_cfg->ioa_is_dead || !res)) {
  3433. memset(scsi_cmd->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE);
  3434. scsi_cmd->result = (DID_NO_CONNECT << 16);
  3435. scsi_cmd->scsi_done(scsi_cmd);
  3436. return 0;
  3437. }
  3438. ipr_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
  3439. ioarcb = &ipr_cmd->ioarcb;
  3440. list_add_tail(&ipr_cmd->queue, &ioa_cfg->pending_q);
  3441. memcpy(ioarcb->cmd_pkt.cdb, scsi_cmd->cmnd, scsi_cmd->cmd_len);
  3442. ipr_cmd->scsi_cmd = scsi_cmd;
  3443. ioarcb->res_handle = res->cfgte.res_handle;
  3444. ipr_cmd->done = ipr_scsi_done;
  3445. ipr_trc_hook(ipr_cmd, IPR_TRACE_START, IPR_GET_PHYS_LOC(res->cfgte.res_addr));
  3446. if (ipr_is_gscsi(res) || ipr_is_vset_device(res)) {
  3447. if (scsi_cmd->underflow == 0)
  3448. ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_NO_ULEN_CHK;
  3449. if (res->needs_sync_complete) {
  3450. ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_SYNC_COMPLETE;
  3451. res->needs_sync_complete = 0;
  3452. }
  3453. ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_NO_LINK_DESC;
  3454. ioarcb->cmd_pkt.flags_lo |= IPR_FLAGS_LO_DELAY_AFTER_RST;
  3455. ioarcb->cmd_pkt.flags_lo |= IPR_FLAGS_LO_ALIGNED_BFR;
  3456. ioarcb->cmd_pkt.flags_lo |= ipr_get_task_attributes(scsi_cmd);
  3457. }
  3458. if (scsi_cmd->cmnd[0] >= 0xC0 &&
  3459. (!ipr_is_gscsi(res) || scsi_cmd->cmnd[0] == IPR_QUERY_RSRC_STATE))
  3460. ioarcb->cmd_pkt.request_type = IPR_RQTYPE_IOACMD;
  3461. if (ipr_is_ioa_resource(res) && scsi_cmd->cmnd[0] == MODE_SELECT)
  3462. rc = ipr_save_ioafp_mode_select(ioa_cfg, scsi_cmd);
  3463. if (likely(rc == 0))
  3464. rc = ipr_build_ioadl(ioa_cfg, ipr_cmd);
  3465. if (likely(rc == 0)) {
  3466. mb();
  3467. writel(be32_to_cpu(ipr_cmd->ioarcb.ioarcb_host_pci_addr),
  3468. ioa_cfg->regs.ioarrin_reg);
  3469. } else {
  3470. list_move_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
  3471. return SCSI_MLQUEUE_HOST_BUSY;
  3472. }
  3473. return 0;
  3474. }
  3475. /**
  3476. * ipr_info - Get information about the card/driver
  3477. * @scsi_host: scsi host struct
  3478. *
  3479. * Return value:
  3480. * pointer to buffer with description string
  3481. **/
  3482. static const char * ipr_ioa_info(struct Scsi_Host *host)
  3483. {
  3484. static char buffer[512];
  3485. struct ipr_ioa_cfg *ioa_cfg;
  3486. unsigned long lock_flags = 0;
  3487. ioa_cfg = (struct ipr_ioa_cfg *) host->hostdata;
  3488. spin_lock_irqsave(host->host_lock, lock_flags);
  3489. sprintf(buffer, "IBM %X Storage Adapter", ioa_cfg->type);
  3490. spin_unlock_irqrestore(host->host_lock, lock_flags);
  3491. return buffer;
  3492. }
  3493. static struct scsi_host_template driver_template = {
  3494. .module = THIS_MODULE,
  3495. .name = "IPR",
  3496. .info = ipr_ioa_info,
  3497. .queuecommand = ipr_queuecommand,
  3498. .eh_abort_handler = ipr_eh_abort,
  3499. .eh_device_reset_handler = ipr_eh_dev_reset,
  3500. .eh_host_reset_handler = ipr_eh_host_reset,
  3501. .slave_alloc = ipr_slave_alloc,
  3502. .slave_configure = ipr_slave_configure,
  3503. .slave_destroy = ipr_slave_destroy,
  3504. .change_queue_depth = ipr_change_queue_depth,
  3505. .change_queue_type = ipr_change_queue_type,
  3506. .bios_param = ipr_biosparam,
  3507. .can_queue = IPR_MAX_COMMANDS,
  3508. .this_id = -1,
  3509. .sg_tablesize = IPR_MAX_SGLIST,
  3510. .max_sectors = IPR_IOA_MAX_SECTORS,
  3511. .cmd_per_lun = IPR_MAX_CMD_PER_LUN,
  3512. .use_clustering = ENABLE_CLUSTERING,
  3513. .shost_attrs = ipr_ioa_attrs,
  3514. .sdev_attrs = ipr_dev_attrs,
  3515. .proc_name = IPR_NAME
  3516. };
  3517. #ifdef CONFIG_PPC_PSERIES
  3518. static const u16 ipr_blocked_processors[] = {
  3519. PV_NORTHSTAR,
  3520. PV_PULSAR,
  3521. PV_POWER4,
  3522. PV_ICESTAR,
  3523. PV_SSTAR,
  3524. PV_POWER4p,
  3525. PV_630,
  3526. PV_630p
  3527. };
  3528. /**
  3529. * ipr_invalid_adapter - Determine if this adapter is supported on this hardware
  3530. * @ioa_cfg: ioa cfg struct
  3531. *
  3532. * Adapters that use Gemstone revision < 3.1 do not work reliably on
  3533. * certain pSeries hardware. This function determines if the given
  3534. * adapter is in one of these confgurations or not.
  3535. *
  3536. * Return value:
  3537. * 1 if adapter is not supported / 0 if adapter is supported
  3538. **/
  3539. static int ipr_invalid_adapter(struct ipr_ioa_cfg *ioa_cfg)
  3540. {
  3541. u8 rev_id;
  3542. int i;
  3543. if (ioa_cfg->type == 0x5702) {
  3544. if (pci_read_config_byte(ioa_cfg->pdev, PCI_REVISION_ID,
  3545. &rev_id) == PCIBIOS_SUCCESSFUL) {
  3546. if (rev_id < 4) {
  3547. for (i = 0; i < ARRAY_SIZE(ipr_blocked_processors); i++){
  3548. if (__is_processor(ipr_blocked_processors[i]))
  3549. return 1;
  3550. }
  3551. }
  3552. }
  3553. }
  3554. return 0;
  3555. }
  3556. #else
  3557. #define ipr_invalid_adapter(ioa_cfg) 0
  3558. #endif
  3559. /**
  3560. * ipr_ioa_bringdown_done - IOA bring down completion.
  3561. * @ipr_cmd: ipr command struct
  3562. *
  3563. * This function processes the completion of an adapter bring down.
  3564. * It wakes any reset sleepers.
  3565. *
  3566. * Return value:
  3567. * IPR_RC_JOB_RETURN
  3568. **/
  3569. static int ipr_ioa_bringdown_done(struct ipr_cmnd *ipr_cmd)
  3570. {
  3571. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  3572. ENTER;
  3573. ioa_cfg->in_reset_reload = 0;
  3574. ioa_cfg->reset_retries = 0;
  3575. list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
  3576. wake_up_all(&ioa_cfg->reset_wait_q);
  3577. spin_unlock_irq(ioa_cfg->host->host_lock);
  3578. scsi_unblock_requests(ioa_cfg->host);
  3579. spin_lock_irq(ioa_cfg->host->host_lock);
  3580. LEAVE;
  3581. return IPR_RC_JOB_RETURN;
  3582. }
  3583. /**
  3584. * ipr_ioa_reset_done - IOA reset completion.
  3585. * @ipr_cmd: ipr command struct
  3586. *
  3587. * This function processes the completion of an adapter reset.
  3588. * It schedules any necessary mid-layer add/removes and
  3589. * wakes any reset sleepers.
  3590. *
  3591. * Return value:
  3592. * IPR_RC_JOB_RETURN
  3593. **/
  3594. static int ipr_ioa_reset_done(struct ipr_cmnd *ipr_cmd)
  3595. {
  3596. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  3597. struct ipr_resource_entry *res;
  3598. struct ipr_hostrcb *hostrcb, *temp;
  3599. int i = 0;
  3600. ENTER;
  3601. ioa_cfg->in_reset_reload = 0;
  3602. ioa_cfg->allow_cmds = 1;
  3603. ioa_cfg->reset_cmd = NULL;
  3604. list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
  3605. if (ioa_cfg->allow_ml_add_del && (res->add_to_ml || res->del_from_ml)) {
  3606. ipr_trace;
  3607. break;
  3608. }
  3609. }
  3610. schedule_work(&ioa_cfg->work_q);
  3611. list_for_each_entry_safe(hostrcb, temp, &ioa_cfg->hostrcb_free_q, queue) {
  3612. list_del(&hostrcb->queue);
  3613. if (i++ < IPR_NUM_LOG_HCAMS)
  3614. ipr_send_hcam(ioa_cfg, IPR_HCAM_CDB_OP_CODE_LOG_DATA, hostrcb);
  3615. else
  3616. ipr_send_hcam(ioa_cfg, IPR_HCAM_CDB_OP_CODE_CONFIG_CHANGE, hostrcb);
  3617. }
  3618. dev_info(&ioa_cfg->pdev->dev, "IOA initialized.\n");
  3619. ioa_cfg->reset_retries = 0;
  3620. list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
  3621. wake_up_all(&ioa_cfg->reset_wait_q);
  3622. spin_unlock_irq(ioa_cfg->host->host_lock);
  3623. scsi_unblock_requests(ioa_cfg->host);
  3624. spin_lock_irq(ioa_cfg->host->host_lock);
  3625. if (!ioa_cfg->allow_cmds)
  3626. scsi_block_requests(ioa_cfg->host);
  3627. LEAVE;
  3628. return IPR_RC_JOB_RETURN;
  3629. }
  3630. /**
  3631. * ipr_set_sup_dev_dflt - Initialize a Set Supported Device buffer
  3632. * @supported_dev: supported device struct
  3633. * @vpids: vendor product id struct
  3634. *
  3635. * Return value:
  3636. * none
  3637. **/
  3638. static void ipr_set_sup_dev_dflt(struct ipr_supported_device *supported_dev,
  3639. struct ipr_std_inq_vpids *vpids)
  3640. {
  3641. memset(supported_dev, 0, sizeof(struct ipr_supported_device));
  3642. memcpy(&supported_dev->vpids, vpids, sizeof(struct ipr_std_inq_vpids));
  3643. supported_dev->num_records = 1;
  3644. supported_dev->data_length =
  3645. cpu_to_be16(sizeof(struct ipr_supported_device));
  3646. supported_dev->reserved = 0;
  3647. }
  3648. /**
  3649. * ipr_set_supported_devs - Send Set Supported Devices for a device
  3650. * @ipr_cmd: ipr command struct
  3651. *
  3652. * This function send a Set Supported Devices to the adapter
  3653. *
  3654. * Return value:
  3655. * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
  3656. **/
  3657. static int ipr_set_supported_devs(struct ipr_cmnd *ipr_cmd)
  3658. {
  3659. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  3660. struct ipr_supported_device *supp_dev = &ioa_cfg->vpd_cbs->supp_dev;
  3661. struct ipr_ioadl_desc *ioadl = ipr_cmd->ioadl;
  3662. struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
  3663. struct ipr_resource_entry *res = ipr_cmd->u.res;
  3664. ipr_cmd->job_step = ipr_ioa_reset_done;
  3665. list_for_each_entry_continue(res, &ioa_cfg->used_res_q, queue) {
  3666. if (!IPR_IS_DASD_DEVICE(res->cfgte.std_inq_data))
  3667. continue;
  3668. ipr_cmd->u.res = res;
  3669. ipr_set_sup_dev_dflt(supp_dev, &res->cfgte.std_inq_data.vpids);
  3670. ioarcb->res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
  3671. ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
  3672. ioarcb->cmd_pkt.request_type = IPR_RQTYPE_IOACMD;
  3673. ioarcb->cmd_pkt.cdb[0] = IPR_SET_SUPPORTED_DEVICES;
  3674. ioarcb->cmd_pkt.cdb[7] = (sizeof(struct ipr_supported_device) >> 8) & 0xff;
  3675. ioarcb->cmd_pkt.cdb[8] = sizeof(struct ipr_supported_device) & 0xff;
  3676. ioadl->flags_and_data_len = cpu_to_be32(IPR_IOADL_FLAGS_WRITE_LAST |
  3677. sizeof(struct ipr_supported_device));
  3678. ioadl->address = cpu_to_be32(ioa_cfg->vpd_cbs_dma +
  3679. offsetof(struct ipr_misc_cbs, supp_dev));
  3680. ioarcb->write_ioadl_len = cpu_to_be32(sizeof(struct ipr_ioadl_desc));
  3681. ioarcb->write_data_transfer_length =
  3682. cpu_to_be32(sizeof(struct ipr_supported_device));
  3683. ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout,
  3684. IPR_SET_SUP_DEVICE_TIMEOUT);
  3685. ipr_cmd->job_step = ipr_set_supported_devs;
  3686. return IPR_RC_JOB_RETURN;
  3687. }
  3688. return IPR_RC_JOB_CONTINUE;
  3689. }
  3690. /**
  3691. * ipr_setup_write_cache - Disable write cache if needed
  3692. * @ipr_cmd: ipr command struct
  3693. *
  3694. * This function sets up adapters write cache to desired setting
  3695. *
  3696. * Return value:
  3697. * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
  3698. **/
  3699. static int ipr_setup_write_cache(struct ipr_cmnd *ipr_cmd)
  3700. {
  3701. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  3702. ipr_cmd->job_step = ipr_set_supported_devs;
  3703. ipr_cmd->u.res = list_entry(ioa_cfg->used_res_q.next,
  3704. struct ipr_resource_entry, queue);
  3705. if (ioa_cfg->cache_state != CACHE_DISABLED)
  3706. return IPR_RC_JOB_CONTINUE;
  3707. ipr_cmd->ioarcb.res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
  3708. ipr_cmd->ioarcb.cmd_pkt.request_type = IPR_RQTYPE_IOACMD;
  3709. ipr_cmd->ioarcb.cmd_pkt.cdb[0] = IPR_IOA_SHUTDOWN;
  3710. ipr_cmd->ioarcb.cmd_pkt.cdb[1] = IPR_SHUTDOWN_PREPARE_FOR_NORMAL;
  3711. ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, IPR_INTERNAL_TIMEOUT);
  3712. return IPR_RC_JOB_RETURN;
  3713. }
  3714. /**
  3715. * ipr_get_mode_page - Locate specified mode page
  3716. * @mode_pages: mode page buffer
  3717. * @page_code: page code to find
  3718. * @len: minimum required length for mode page
  3719. *
  3720. * Return value:
  3721. * pointer to mode page / NULL on failure
  3722. **/
  3723. static void *ipr_get_mode_page(struct ipr_mode_pages *mode_pages,
  3724. u32 page_code, u32 len)
  3725. {
  3726. struct ipr_mode_page_hdr *mode_hdr;
  3727. u32 page_length;
  3728. u32 length;
  3729. if (!mode_pages || (mode_pages->hdr.length == 0))
  3730. return NULL;
  3731. length = (mode_pages->hdr.length + 1) - 4 - mode_pages->hdr.block_desc_len;
  3732. mode_hdr = (struct ipr_mode_page_hdr *)
  3733. (mode_pages->data + mode_pages->hdr.block_desc_len);
  3734. while (length) {
  3735. if (IPR_GET_MODE_PAGE_CODE(mode_hdr) == page_code) {
  3736. if (mode_hdr->page_length >= (len - sizeof(struct ipr_mode_page_hdr)))
  3737. return mode_hdr;
  3738. break;
  3739. } else {
  3740. page_length = (sizeof(struct ipr_mode_page_hdr) +
  3741. mode_hdr->page_length);
  3742. length -= page_length;
  3743. mode_hdr = (struct ipr_mode_page_hdr *)
  3744. ((unsigned long)mode_hdr + page_length);
  3745. }
  3746. }
  3747. return NULL;
  3748. }
  3749. /**
  3750. * ipr_check_term_power - Check for term power errors
  3751. * @ioa_cfg: ioa config struct
  3752. * @mode_pages: IOAFP mode pages buffer
  3753. *
  3754. * Check the IOAFP's mode page 28 for term power errors
  3755. *
  3756. * Return value:
  3757. * nothing
  3758. **/
  3759. static void ipr_check_term_power(struct ipr_ioa_cfg *ioa_cfg,
  3760. struct ipr_mode_pages *mode_pages)
  3761. {
  3762. int i;
  3763. int entry_length;
  3764. struct ipr_dev_bus_entry *bus;
  3765. struct ipr_mode_page28 *mode_page;
  3766. mode_page = ipr_get_mode_page(mode_pages, 0x28,
  3767. sizeof(struct ipr_mode_page28));
  3768. entry_length = mode_page->entry_length;
  3769. bus = mode_page->bus;
  3770. for (i = 0; i < mode_page->num_entries; i++) {
  3771. if (bus->flags & IPR_SCSI_ATTR_NO_TERM_PWR) {
  3772. dev_err(&ioa_cfg->pdev->dev,
  3773. "Term power is absent on scsi bus %d\n",
  3774. bus->res_addr.bus);
  3775. }
  3776. bus = (struct ipr_dev_bus_entry *)((char *)bus + entry_length);
  3777. }
  3778. }
  3779. /**
  3780. * ipr_scsi_bus_speed_limit - Limit the SCSI speed based on SES table
  3781. * @ioa_cfg: ioa config struct
  3782. *
  3783. * Looks through the config table checking for SES devices. If
  3784. * the SES device is in the SES table indicating a maximum SCSI
  3785. * bus speed, the speed is limited for the bus.
  3786. *
  3787. * Return value:
  3788. * none
  3789. **/
  3790. static void ipr_scsi_bus_speed_limit(struct ipr_ioa_cfg *ioa_cfg)
  3791. {
  3792. u32 max_xfer_rate;
  3793. int i;
  3794. for (i = 0; i < IPR_MAX_NUM_BUSES; i++) {
  3795. max_xfer_rate = ipr_get_max_scsi_speed(ioa_cfg, i,
  3796. ioa_cfg->bus_attr[i].bus_width);
  3797. if (max_xfer_rate < ioa_cfg->bus_attr[i].max_xfer_rate)
  3798. ioa_cfg->bus_attr[i].max_xfer_rate = max_xfer_rate;
  3799. }
  3800. }
  3801. /**
  3802. * ipr_modify_ioafp_mode_page_28 - Modify IOAFP Mode Page 28
  3803. * @ioa_cfg: ioa config struct
  3804. * @mode_pages: mode page 28 buffer
  3805. *
  3806. * Updates mode page 28 based on driver configuration
  3807. *
  3808. * Return value:
  3809. * none
  3810. **/
  3811. static void ipr_modify_ioafp_mode_page_28(struct ipr_ioa_cfg *ioa_cfg,
  3812. struct ipr_mode_pages *mode_pages)
  3813. {
  3814. int i, entry_length;
  3815. struct ipr_dev_bus_entry *bus;
  3816. struct ipr_bus_attributes *bus_attr;
  3817. struct ipr_mode_page28 *mode_page;
  3818. mode_page = ipr_get_mode_page(mode_pages, 0x28,
  3819. sizeof(struct ipr_mode_page28));
  3820. entry_length = mode_page->entry_length;
  3821. /* Loop for each device bus entry */
  3822. for (i = 0, bus = mode_page->bus;
  3823. i < mode_page->num_entries;
  3824. i++, bus = (struct ipr_dev_bus_entry *)((u8 *)bus + entry_length)) {
  3825. if (bus->res_addr.bus > IPR_MAX_NUM_BUSES) {
  3826. dev_err(&ioa_cfg->pdev->dev,
  3827. "Invalid resource address reported: 0x%08X\n",
  3828. IPR_GET_PHYS_LOC(bus->res_addr));
  3829. continue;
  3830. }
  3831. bus_attr = &ioa_cfg->bus_attr[i];
  3832. bus->extended_reset_delay = IPR_EXTENDED_RESET_DELAY;
  3833. bus->bus_width = bus_attr->bus_width;
  3834. bus->max_xfer_rate = cpu_to_be32(bus_attr->max_xfer_rate);
  3835. bus->flags &= ~IPR_SCSI_ATTR_QAS_MASK;
  3836. if (bus_attr->qas_enabled)
  3837. bus->flags |= IPR_SCSI_ATTR_ENABLE_QAS;
  3838. else
  3839. bus->flags |= IPR_SCSI_ATTR_DISABLE_QAS;
  3840. }
  3841. }
  3842. /**
  3843. * ipr_build_mode_select - Build a mode select command
  3844. * @ipr_cmd: ipr command struct
  3845. * @res_handle: resource handle to send command to
  3846. * @parm: Byte 2 of Mode Sense command
  3847. * @dma_addr: DMA buffer address
  3848. * @xfer_len: data transfer length
  3849. *
  3850. * Return value:
  3851. * none
  3852. **/
  3853. static void ipr_build_mode_select(struct ipr_cmnd *ipr_cmd,
  3854. __be32 res_handle, u8 parm, u32 dma_addr,
  3855. u8 xfer_len)
  3856. {
  3857. struct ipr_ioadl_desc *ioadl = ipr_cmd->ioadl;
  3858. struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
  3859. ioarcb->res_handle = res_handle;
  3860. ioarcb->cmd_pkt.request_type = IPR_RQTYPE_SCSICDB;
  3861. ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
  3862. ioarcb->cmd_pkt.cdb[0] = MODE_SELECT;
  3863. ioarcb->cmd_pkt.cdb[1] = parm;
  3864. ioarcb->cmd_pkt.cdb[4] = xfer_len;
  3865. ioadl->flags_and_data_len =
  3866. cpu_to_be32(IPR_IOADL_FLAGS_WRITE_LAST | xfer_len);
  3867. ioadl->address = cpu_to_be32(dma_addr);
  3868. ioarcb->write_ioadl_len = cpu_to_be32(sizeof(struct ipr_ioadl_desc));
  3869. ioarcb->write_data_transfer_length = cpu_to_be32(xfer_len);
  3870. }
  3871. /**
  3872. * ipr_ioafp_mode_select_page28 - Issue Mode Select Page 28 to IOA
  3873. * @ipr_cmd: ipr command struct
  3874. *
  3875. * This function sets up the SCSI bus attributes and sends
  3876. * a Mode Select for Page 28 to activate them.
  3877. *
  3878. * Return value:
  3879. * IPR_RC_JOB_RETURN
  3880. **/
  3881. static int ipr_ioafp_mode_select_page28(struct ipr_cmnd *ipr_cmd)
  3882. {
  3883. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  3884. struct ipr_mode_pages *mode_pages = &ioa_cfg->vpd_cbs->mode_pages;
  3885. int length;
  3886. ENTER;
  3887. if (ioa_cfg->saved_mode_pages) {
  3888. memcpy(mode_pages, ioa_cfg->saved_mode_pages,
  3889. ioa_cfg->saved_mode_page_len);
  3890. length = ioa_cfg->saved_mode_page_len;
  3891. } else {
  3892. ipr_scsi_bus_speed_limit(ioa_cfg);
  3893. ipr_check_term_power(ioa_cfg, mode_pages);
  3894. ipr_modify_ioafp_mode_page_28(ioa_cfg, mode_pages);
  3895. length = mode_pages->hdr.length + 1;
  3896. mode_pages->hdr.length = 0;
  3897. }
  3898. ipr_build_mode_select(ipr_cmd, cpu_to_be32(IPR_IOA_RES_HANDLE), 0x11,
  3899. ioa_cfg->vpd_cbs_dma + offsetof(struct ipr_misc_cbs, mode_pages),
  3900. length);
  3901. ipr_cmd->job_step = ipr_setup_write_cache;
  3902. ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, IPR_INTERNAL_TIMEOUT);
  3903. LEAVE;
  3904. return IPR_RC_JOB_RETURN;
  3905. }
  3906. /**
  3907. * ipr_build_mode_sense - Builds a mode sense command
  3908. * @ipr_cmd: ipr command struct
  3909. * @res: resource entry struct
  3910. * @parm: Byte 2 of mode sense command
  3911. * @dma_addr: DMA address of mode sense buffer
  3912. * @xfer_len: Size of DMA buffer
  3913. *
  3914. * Return value:
  3915. * none
  3916. **/
  3917. static void ipr_build_mode_sense(struct ipr_cmnd *ipr_cmd,
  3918. __be32 res_handle,
  3919. u8 parm, u32 dma_addr, u8 xfer_len)
  3920. {
  3921. struct ipr_ioadl_desc *ioadl = ipr_cmd->ioadl;
  3922. struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
  3923. ioarcb->res_handle = res_handle;
  3924. ioarcb->cmd_pkt.cdb[0] = MODE_SENSE;
  3925. ioarcb->cmd_pkt.cdb[2] = parm;
  3926. ioarcb->cmd_pkt.cdb[4] = xfer_len;
  3927. ioarcb->cmd_pkt.request_type = IPR_RQTYPE_SCSICDB;
  3928. ioadl->flags_and_data_len =
  3929. cpu_to_be32(IPR_IOADL_FLAGS_READ_LAST | xfer_len);
  3930. ioadl->address = cpu_to_be32(dma_addr);
  3931. ioarcb->read_ioadl_len = cpu_to_be32(sizeof(struct ipr_ioadl_desc));
  3932. ioarcb->read_data_transfer_length = cpu_to_be32(xfer_len);
  3933. }
  3934. /**
  3935. * ipr_ioafp_mode_sense_page28 - Issue Mode Sense Page 28 to IOA
  3936. * @ipr_cmd: ipr command struct
  3937. *
  3938. * This function send a Page 28 mode sense to the IOA to
  3939. * retrieve SCSI bus attributes.
  3940. *
  3941. * Return value:
  3942. * IPR_RC_JOB_RETURN
  3943. **/
  3944. static int ipr_ioafp_mode_sense_page28(struct ipr_cmnd *ipr_cmd)
  3945. {
  3946. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  3947. ENTER;
  3948. ipr_build_mode_sense(ipr_cmd, cpu_to_be32(IPR_IOA_RES_HANDLE),
  3949. 0x28, ioa_cfg->vpd_cbs_dma +
  3950. offsetof(struct ipr_misc_cbs, mode_pages),
  3951. sizeof(struct ipr_mode_pages));
  3952. ipr_cmd->job_step = ipr_ioafp_mode_select_page28;
  3953. ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, IPR_INTERNAL_TIMEOUT);
  3954. LEAVE;
  3955. return IPR_RC_JOB_RETURN;
  3956. }
  3957. /**
  3958. * ipr_init_res_table - Initialize the resource table
  3959. * @ipr_cmd: ipr command struct
  3960. *
  3961. * This function looks through the existing resource table, comparing
  3962. * it with the config table. This function will take care of old/new
  3963. * devices and schedule adding/removing them from the mid-layer
  3964. * as appropriate.
  3965. *
  3966. * Return value:
  3967. * IPR_RC_JOB_CONTINUE
  3968. **/
  3969. static int ipr_init_res_table(struct ipr_cmnd *ipr_cmd)
  3970. {
  3971. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  3972. struct ipr_resource_entry *res, *temp;
  3973. struct ipr_config_table_entry *cfgte;
  3974. int found, i;
  3975. LIST_HEAD(old_res);
  3976. ENTER;
  3977. if (ioa_cfg->cfg_table->hdr.flags & IPR_UCODE_DOWNLOAD_REQ)
  3978. dev_err(&ioa_cfg->pdev->dev, "Microcode download required\n");
  3979. list_for_each_entry_safe(res, temp, &ioa_cfg->used_res_q, queue)
  3980. list_move_tail(&res->queue, &old_res);
  3981. for (i = 0; i < ioa_cfg->cfg_table->hdr.num_entries; i++) {
  3982. cfgte = &ioa_cfg->cfg_table->dev[i];
  3983. found = 0;
  3984. list_for_each_entry_safe(res, temp, &old_res, queue) {
  3985. if (!memcmp(&res->cfgte.res_addr,
  3986. &cfgte->res_addr, sizeof(cfgte->res_addr))) {
  3987. list_move_tail(&res->queue, &ioa_cfg->used_res_q);
  3988. found = 1;
  3989. break;
  3990. }
  3991. }
  3992. if (!found) {
  3993. if (list_empty(&ioa_cfg->free_res_q)) {
  3994. dev_err(&ioa_cfg->pdev->dev, "Too many devices attached\n");
  3995. break;
  3996. }
  3997. found = 1;
  3998. res = list_entry(ioa_cfg->free_res_q.next,
  3999. struct ipr_resource_entry, queue);
  4000. list_move_tail(&res->queue, &ioa_cfg->used_res_q);
  4001. ipr_init_res_entry(res);
  4002. res->add_to_ml = 1;
  4003. }
  4004. if (found)
  4005. memcpy(&res->cfgte, cfgte, sizeof(struct ipr_config_table_entry));
  4006. }
  4007. list_for_each_entry_safe(res, temp, &old_res, queue) {
  4008. if (res->sdev) {
  4009. res->del_from_ml = 1;
  4010. res->sdev->hostdata = NULL;
  4011. list_move_tail(&res->queue, &ioa_cfg->used_res_q);
  4012. } else {
  4013. list_move_tail(&res->queue, &ioa_cfg->free_res_q);
  4014. }
  4015. }
  4016. ipr_cmd->job_step = ipr_ioafp_mode_sense_page28;
  4017. LEAVE;
  4018. return IPR_RC_JOB_CONTINUE;
  4019. }
  4020. /**
  4021. * ipr_ioafp_query_ioa_cfg - Send a Query IOA Config to the adapter.
  4022. * @ipr_cmd: ipr command struct
  4023. *
  4024. * This function sends a Query IOA Configuration command
  4025. * to the adapter to retrieve the IOA configuration table.
  4026. *
  4027. * Return value:
  4028. * IPR_RC_JOB_RETURN
  4029. **/
  4030. static int ipr_ioafp_query_ioa_cfg(struct ipr_cmnd *ipr_cmd)
  4031. {
  4032. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  4033. struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
  4034. struct ipr_ioadl_desc *ioadl = ipr_cmd->ioadl;
  4035. struct ipr_inquiry_page3 *ucode_vpd = &ioa_cfg->vpd_cbs->page3_data;
  4036. ENTER;
  4037. dev_info(&ioa_cfg->pdev->dev, "Adapter firmware version: %02X%02X%02X%02X\n",
  4038. ucode_vpd->major_release, ucode_vpd->card_type,
  4039. ucode_vpd->minor_release[0], ucode_vpd->minor_release[1]);
  4040. ioarcb->cmd_pkt.request_type = IPR_RQTYPE_IOACMD;
  4041. ioarcb->res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
  4042. ioarcb->cmd_pkt.cdb[0] = IPR_QUERY_IOA_CONFIG;
  4043. ioarcb->cmd_pkt.cdb[7] = (sizeof(struct ipr_config_table) >> 8) & 0xff;
  4044. ioarcb->cmd_pkt.cdb[8] = sizeof(struct ipr_config_table) & 0xff;
  4045. ioarcb->read_ioadl_len = cpu_to_be32(sizeof(struct ipr_ioadl_desc));
  4046. ioarcb->read_data_transfer_length =
  4047. cpu_to_be32(sizeof(struct ipr_config_table));
  4048. ioadl->address = cpu_to_be32(ioa_cfg->cfg_table_dma);
  4049. ioadl->flags_and_data_len =
  4050. cpu_to_be32(IPR_IOADL_FLAGS_READ_LAST | sizeof(struct ipr_config_table));
  4051. ipr_cmd->job_step = ipr_init_res_table;
  4052. ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, IPR_INTERNAL_TIMEOUT);
  4053. LEAVE;
  4054. return IPR_RC_JOB_RETURN;
  4055. }
  4056. /**
  4057. * ipr_ioafp_inquiry - Send an Inquiry to the adapter.
  4058. * @ipr_cmd: ipr command struct
  4059. *
  4060. * This utility function sends an inquiry to the adapter.
  4061. *
  4062. * Return value:
  4063. * none
  4064. **/
  4065. static void ipr_ioafp_inquiry(struct ipr_cmnd *ipr_cmd, u8 flags, u8 page,
  4066. u32 dma_addr, u8 xfer_len)
  4067. {
  4068. struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
  4069. struct ipr_ioadl_desc *ioadl = ipr_cmd->ioadl;
  4070. ENTER;
  4071. ioarcb->cmd_pkt.request_type = IPR_RQTYPE_SCSICDB;
  4072. ioarcb->res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
  4073. ioarcb->cmd_pkt.cdb[0] = INQUIRY;
  4074. ioarcb->cmd_pkt.cdb[1] = flags;
  4075. ioarcb->cmd_pkt.cdb[2] = page;
  4076. ioarcb->cmd_pkt.cdb[4] = xfer_len;
  4077. ioarcb->read_ioadl_len = cpu_to_be32(sizeof(struct ipr_ioadl_desc));
  4078. ioarcb->read_data_transfer_length = cpu_to_be32(xfer_len);
  4079. ioadl->address = cpu_to_be32(dma_addr);
  4080. ioadl->flags_and_data_len =
  4081. cpu_to_be32(IPR_IOADL_FLAGS_READ_LAST | xfer_len);
  4082. ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, IPR_INTERNAL_TIMEOUT);
  4083. LEAVE;
  4084. }
  4085. /**
  4086. * ipr_inquiry_page_supported - Is the given inquiry page supported
  4087. * @page0: inquiry page 0 buffer
  4088. * @page: page code.
  4089. *
  4090. * This function determines if the specified inquiry page is supported.
  4091. *
  4092. * Return value:
  4093. * 1 if page is supported / 0 if not
  4094. **/
  4095. static int ipr_inquiry_page_supported(struct ipr_inquiry_page0 *page0, u8 page)
  4096. {
  4097. int i;
  4098. for (i = 0; i < min_t(u8, page0->len, IPR_INQUIRY_PAGE0_ENTRIES); i++)
  4099. if (page0->page[i] == page)
  4100. return 1;
  4101. return 0;
  4102. }
  4103. /**
  4104. * ipr_ioafp_page3_inquiry - Send a Page 3 Inquiry to the adapter.
  4105. * @ipr_cmd: ipr command struct
  4106. *
  4107. * This function sends a Page 3 inquiry to the adapter
  4108. * to retrieve software VPD information.
  4109. *
  4110. * Return value:
  4111. * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
  4112. **/
  4113. static int ipr_ioafp_page3_inquiry(struct ipr_cmnd *ipr_cmd)
  4114. {
  4115. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  4116. struct ipr_inquiry_page0 *page0 = &ioa_cfg->vpd_cbs->page0_data;
  4117. ENTER;
  4118. if (!ipr_inquiry_page_supported(page0, 1))
  4119. ioa_cfg->cache_state = CACHE_NONE;
  4120. ipr_cmd->job_step = ipr_ioafp_query_ioa_cfg;
  4121. ipr_ioafp_inquiry(ipr_cmd, 1, 3,
  4122. ioa_cfg->vpd_cbs_dma + offsetof(struct ipr_misc_cbs, page3_data),
  4123. sizeof(struct ipr_inquiry_page3));
  4124. LEAVE;
  4125. return IPR_RC_JOB_RETURN;
  4126. }
  4127. /**
  4128. * ipr_ioafp_page0_inquiry - Send a Page 0 Inquiry to the adapter.
  4129. * @ipr_cmd: ipr command struct
  4130. *
  4131. * This function sends a Page 0 inquiry to the adapter
  4132. * to retrieve supported inquiry pages.
  4133. *
  4134. * Return value:
  4135. * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
  4136. **/
  4137. static int ipr_ioafp_page0_inquiry(struct ipr_cmnd *ipr_cmd)
  4138. {
  4139. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  4140. char type[5];
  4141. ENTER;
  4142. /* Grab the type out of the VPD and store it away */
  4143. memcpy(type, ioa_cfg->vpd_cbs->ioa_vpd.std_inq_data.vpids.product_id, 4);
  4144. type[4] = '\0';
  4145. ioa_cfg->type = simple_strtoul((char *)type, NULL, 16);
  4146. ipr_cmd->job_step = ipr_ioafp_page3_inquiry;
  4147. ipr_ioafp_inquiry(ipr_cmd, 1, 0,
  4148. ioa_cfg->vpd_cbs_dma + offsetof(struct ipr_misc_cbs, page0_data),
  4149. sizeof(struct ipr_inquiry_page0));
  4150. LEAVE;
  4151. return IPR_RC_JOB_RETURN;
  4152. }
  4153. /**
  4154. * ipr_ioafp_std_inquiry - Send a Standard Inquiry to the adapter.
  4155. * @ipr_cmd: ipr command struct
  4156. *
  4157. * This function sends a standard inquiry to the adapter.
  4158. *
  4159. * Return value:
  4160. * IPR_RC_JOB_RETURN
  4161. **/
  4162. static int ipr_ioafp_std_inquiry(struct ipr_cmnd *ipr_cmd)
  4163. {
  4164. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  4165. ENTER;
  4166. ipr_cmd->job_step = ipr_ioafp_page0_inquiry;
  4167. ipr_ioafp_inquiry(ipr_cmd, 0, 0,
  4168. ioa_cfg->vpd_cbs_dma + offsetof(struct ipr_misc_cbs, ioa_vpd),
  4169. sizeof(struct ipr_ioa_vpd));
  4170. LEAVE;
  4171. return IPR_RC_JOB_RETURN;
  4172. }
  4173. /**
  4174. * ipr_ioafp_indentify_hrrq - Send Identify Host RRQ.
  4175. * @ipr_cmd: ipr command struct
  4176. *
  4177. * This function send an Identify Host Request Response Queue
  4178. * command to establish the HRRQ with the adapter.
  4179. *
  4180. * Return value:
  4181. * IPR_RC_JOB_RETURN
  4182. **/
  4183. static int ipr_ioafp_indentify_hrrq(struct ipr_cmnd *ipr_cmd)
  4184. {
  4185. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  4186. struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
  4187. ENTER;
  4188. dev_info(&ioa_cfg->pdev->dev, "Starting IOA initialization sequence.\n");
  4189. ioarcb->cmd_pkt.cdb[0] = IPR_ID_HOST_RR_Q;
  4190. ioarcb->res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
  4191. ioarcb->cmd_pkt.request_type = IPR_RQTYPE_IOACMD;
  4192. ioarcb->cmd_pkt.cdb[2] =
  4193. ((u32) ioa_cfg->host_rrq_dma >> 24) & 0xff;
  4194. ioarcb->cmd_pkt.cdb[3] =
  4195. ((u32) ioa_cfg->host_rrq_dma >> 16) & 0xff;
  4196. ioarcb->cmd_pkt.cdb[4] =
  4197. ((u32) ioa_cfg->host_rrq_dma >> 8) & 0xff;
  4198. ioarcb->cmd_pkt.cdb[5] =
  4199. ((u32) ioa_cfg->host_rrq_dma) & 0xff;
  4200. ioarcb->cmd_pkt.cdb[7] =
  4201. ((sizeof(u32) * IPR_NUM_CMD_BLKS) >> 8) & 0xff;
  4202. ioarcb->cmd_pkt.cdb[8] =
  4203. (sizeof(u32) * IPR_NUM_CMD_BLKS) & 0xff;
  4204. ipr_cmd->job_step = ipr_ioafp_std_inquiry;
  4205. ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, IPR_INTERNAL_TIMEOUT);
  4206. LEAVE;
  4207. return IPR_RC_JOB_RETURN;
  4208. }
  4209. /**
  4210. * ipr_reset_timer_done - Adapter reset timer function
  4211. * @ipr_cmd: ipr command struct
  4212. *
  4213. * Description: This function is used in adapter reset processing
  4214. * for timing events. If the reset_cmd pointer in the IOA
  4215. * config struct is not this adapter's we are doing nested
  4216. * resets and fail_all_ops will take care of freeing the
  4217. * command block.
  4218. *
  4219. * Return value:
  4220. * none
  4221. **/
  4222. static void ipr_reset_timer_done(struct ipr_cmnd *ipr_cmd)
  4223. {
  4224. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  4225. unsigned long lock_flags = 0;
  4226. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  4227. if (ioa_cfg->reset_cmd == ipr_cmd) {
  4228. list_del(&ipr_cmd->queue);
  4229. ipr_cmd->done(ipr_cmd);
  4230. }
  4231. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  4232. }
  4233. /**
  4234. * ipr_reset_start_timer - Start a timer for adapter reset job
  4235. * @ipr_cmd: ipr command struct
  4236. * @timeout: timeout value
  4237. *
  4238. * Description: This function is used in adapter reset processing
  4239. * for timing events. If the reset_cmd pointer in the IOA
  4240. * config struct is not this adapter's we are doing nested
  4241. * resets and fail_all_ops will take care of freeing the
  4242. * command block.
  4243. *
  4244. * Return value:
  4245. * none
  4246. **/
  4247. static void ipr_reset_start_timer(struct ipr_cmnd *ipr_cmd,
  4248. unsigned long timeout)
  4249. {
  4250. list_add_tail(&ipr_cmd->queue, &ipr_cmd->ioa_cfg->pending_q);
  4251. ipr_cmd->done = ipr_reset_ioa_job;
  4252. ipr_cmd->timer.data = (unsigned long) ipr_cmd;
  4253. ipr_cmd->timer.expires = jiffies + timeout;
  4254. ipr_cmd->timer.function = (void (*)(unsigned long))ipr_reset_timer_done;
  4255. add_timer(&ipr_cmd->timer);
  4256. }
  4257. /**
  4258. * ipr_init_ioa_mem - Initialize ioa_cfg control block
  4259. * @ioa_cfg: ioa cfg struct
  4260. *
  4261. * Return value:
  4262. * nothing
  4263. **/
  4264. static void ipr_init_ioa_mem(struct ipr_ioa_cfg *ioa_cfg)
  4265. {
  4266. memset(ioa_cfg->host_rrq, 0, sizeof(u32) * IPR_NUM_CMD_BLKS);
  4267. /* Initialize Host RRQ pointers */
  4268. ioa_cfg->hrrq_start = ioa_cfg->host_rrq;
  4269. ioa_cfg->hrrq_end = &ioa_cfg->host_rrq[IPR_NUM_CMD_BLKS - 1];
  4270. ioa_cfg->hrrq_curr = ioa_cfg->hrrq_start;
  4271. ioa_cfg->toggle_bit = 1;
  4272. /* Zero out config table */
  4273. memset(ioa_cfg->cfg_table, 0, sizeof(struct ipr_config_table));
  4274. }
  4275. /**
  4276. * ipr_reset_enable_ioa - Enable the IOA following a reset.
  4277. * @ipr_cmd: ipr command struct
  4278. *
  4279. * This function reinitializes some control blocks and
  4280. * enables destructive diagnostics on the adapter.
  4281. *
  4282. * Return value:
  4283. * IPR_RC_JOB_RETURN
  4284. **/
  4285. static int ipr_reset_enable_ioa(struct ipr_cmnd *ipr_cmd)
  4286. {
  4287. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  4288. volatile u32 int_reg;
  4289. ENTER;
  4290. ipr_cmd->job_step = ipr_ioafp_indentify_hrrq;
  4291. ipr_init_ioa_mem(ioa_cfg);
  4292. ioa_cfg->allow_interrupts = 1;
  4293. int_reg = readl(ioa_cfg->regs.sense_interrupt_reg);
  4294. if (int_reg & IPR_PCII_IOA_TRANS_TO_OPER) {
  4295. writel((IPR_PCII_ERROR_INTERRUPTS | IPR_PCII_HRRQ_UPDATED),
  4296. ioa_cfg->regs.clr_interrupt_mask_reg);
  4297. int_reg = readl(ioa_cfg->regs.sense_interrupt_mask_reg);
  4298. return IPR_RC_JOB_CONTINUE;
  4299. }
  4300. /* Enable destructive diagnostics on IOA */
  4301. writel(IPR_DOORBELL, ioa_cfg->regs.set_uproc_interrupt_reg);
  4302. writel(IPR_PCII_OPER_INTERRUPTS, ioa_cfg->regs.clr_interrupt_mask_reg);
  4303. int_reg = readl(ioa_cfg->regs.sense_interrupt_mask_reg);
  4304. dev_info(&ioa_cfg->pdev->dev, "Initializing IOA.\n");
  4305. ipr_cmd->timer.data = (unsigned long) ipr_cmd;
  4306. ipr_cmd->timer.expires = jiffies + (ipr_transop_timeout * HZ);
  4307. ipr_cmd->timer.function = (void (*)(unsigned long))ipr_oper_timeout;
  4308. ipr_cmd->done = ipr_reset_ioa_job;
  4309. add_timer(&ipr_cmd->timer);
  4310. list_add_tail(&ipr_cmd->queue, &ioa_cfg->pending_q);
  4311. LEAVE;
  4312. return IPR_RC_JOB_RETURN;
  4313. }
  4314. /**
  4315. * ipr_reset_wait_for_dump - Wait for a dump to timeout.
  4316. * @ipr_cmd: ipr command struct
  4317. *
  4318. * This function is invoked when an adapter dump has run out
  4319. * of processing time.
  4320. *
  4321. * Return value:
  4322. * IPR_RC_JOB_CONTINUE
  4323. **/
  4324. static int ipr_reset_wait_for_dump(struct ipr_cmnd *ipr_cmd)
  4325. {
  4326. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  4327. if (ioa_cfg->sdt_state == GET_DUMP)
  4328. ioa_cfg->sdt_state = ABORT_DUMP;
  4329. ipr_cmd->job_step = ipr_reset_alert;
  4330. return IPR_RC_JOB_CONTINUE;
  4331. }
  4332. /**
  4333. * ipr_unit_check_no_data - Log a unit check/no data error log
  4334. * @ioa_cfg: ioa config struct
  4335. *
  4336. * Logs an error indicating the adapter unit checked, but for some
  4337. * reason, we were unable to fetch the unit check buffer.
  4338. *
  4339. * Return value:
  4340. * nothing
  4341. **/
  4342. static void ipr_unit_check_no_data(struct ipr_ioa_cfg *ioa_cfg)
  4343. {
  4344. ioa_cfg->errors_logged++;
  4345. dev_err(&ioa_cfg->pdev->dev, "IOA unit check with no data\n");
  4346. }
  4347. /**
  4348. * ipr_get_unit_check_buffer - Get the unit check buffer from the IOA
  4349. * @ioa_cfg: ioa config struct
  4350. *
  4351. * Fetches the unit check buffer from the adapter by clocking the data
  4352. * through the mailbox register.
  4353. *
  4354. * Return value:
  4355. * nothing
  4356. **/
  4357. static void ipr_get_unit_check_buffer(struct ipr_ioa_cfg *ioa_cfg)
  4358. {
  4359. unsigned long mailbox;
  4360. struct ipr_hostrcb *hostrcb;
  4361. struct ipr_uc_sdt sdt;
  4362. int rc, length;
  4363. mailbox = readl(ioa_cfg->ioa_mailbox);
  4364. if (!ipr_sdt_is_fmt2(mailbox)) {
  4365. ipr_unit_check_no_data(ioa_cfg);
  4366. return;
  4367. }
  4368. memset(&sdt, 0, sizeof(struct ipr_uc_sdt));
  4369. rc = ipr_get_ldump_data_section(ioa_cfg, mailbox, (__be32 *) &sdt,
  4370. (sizeof(struct ipr_uc_sdt)) / sizeof(__be32));
  4371. if (rc || (be32_to_cpu(sdt.hdr.state) != IPR_FMT2_SDT_READY_TO_USE) ||
  4372. !(sdt.entry[0].flags & IPR_SDT_VALID_ENTRY)) {
  4373. ipr_unit_check_no_data(ioa_cfg);
  4374. return;
  4375. }
  4376. /* Find length of the first sdt entry (UC buffer) */
  4377. length = (be32_to_cpu(sdt.entry[0].end_offset) -
  4378. be32_to_cpu(sdt.entry[0].bar_str_offset)) & IPR_FMT2_MBX_ADDR_MASK;
  4379. hostrcb = list_entry(ioa_cfg->hostrcb_free_q.next,
  4380. struct ipr_hostrcb, queue);
  4381. list_del(&hostrcb->queue);
  4382. memset(&hostrcb->hcam, 0, sizeof(hostrcb->hcam));
  4383. rc = ipr_get_ldump_data_section(ioa_cfg,
  4384. be32_to_cpu(sdt.entry[0].bar_str_offset),
  4385. (__be32 *)&hostrcb->hcam,
  4386. min(length, (int)sizeof(hostrcb->hcam)) / sizeof(__be32));
  4387. if (!rc)
  4388. ipr_handle_log_data(ioa_cfg, hostrcb);
  4389. else
  4390. ipr_unit_check_no_data(ioa_cfg);
  4391. list_add_tail(&hostrcb->queue, &ioa_cfg->hostrcb_free_q);
  4392. }
  4393. /**
  4394. * ipr_reset_restore_cfg_space - Restore PCI config space.
  4395. * @ipr_cmd: ipr command struct
  4396. *
  4397. * Description: This function restores the saved PCI config space of
  4398. * the adapter, fails all outstanding ops back to the callers, and
  4399. * fetches the dump/unit check if applicable to this reset.
  4400. *
  4401. * Return value:
  4402. * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
  4403. **/
  4404. static int ipr_reset_restore_cfg_space(struct ipr_cmnd *ipr_cmd)
  4405. {
  4406. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  4407. int rc;
  4408. ENTER;
  4409. pci_unblock_user_cfg_access(ioa_cfg->pdev);
  4410. rc = pci_restore_state(ioa_cfg->pdev);
  4411. if (rc != PCIBIOS_SUCCESSFUL) {
  4412. ipr_cmd->ioasa.ioasc = cpu_to_be32(IPR_IOASC_PCI_ACCESS_ERROR);
  4413. return IPR_RC_JOB_CONTINUE;
  4414. }
  4415. if (ipr_set_pcix_cmd_reg(ioa_cfg)) {
  4416. ipr_cmd->ioasa.ioasc = cpu_to_be32(IPR_IOASC_PCI_ACCESS_ERROR);
  4417. return IPR_RC_JOB_CONTINUE;
  4418. }
  4419. ipr_fail_all_ops(ioa_cfg);
  4420. if (ioa_cfg->ioa_unit_checked) {
  4421. ioa_cfg->ioa_unit_checked = 0;
  4422. ipr_get_unit_check_buffer(ioa_cfg);
  4423. ipr_cmd->job_step = ipr_reset_alert;
  4424. ipr_reset_start_timer(ipr_cmd, 0);
  4425. return IPR_RC_JOB_RETURN;
  4426. }
  4427. if (ioa_cfg->in_ioa_bringdown) {
  4428. ipr_cmd->job_step = ipr_ioa_bringdown_done;
  4429. } else {
  4430. ipr_cmd->job_step = ipr_reset_enable_ioa;
  4431. if (GET_DUMP == ioa_cfg->sdt_state) {
  4432. ipr_reset_start_timer(ipr_cmd, IPR_DUMP_TIMEOUT);
  4433. ipr_cmd->job_step = ipr_reset_wait_for_dump;
  4434. schedule_work(&ioa_cfg->work_q);
  4435. return IPR_RC_JOB_RETURN;
  4436. }
  4437. }
  4438. ENTER;
  4439. return IPR_RC_JOB_CONTINUE;
  4440. }
  4441. /**
  4442. * ipr_reset_start_bist - Run BIST on the adapter.
  4443. * @ipr_cmd: ipr command struct
  4444. *
  4445. * Description: This function runs BIST on the adapter, then delays 2 seconds.
  4446. *
  4447. * Return value:
  4448. * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
  4449. **/
  4450. static int ipr_reset_start_bist(struct ipr_cmnd *ipr_cmd)
  4451. {
  4452. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  4453. int rc;
  4454. ENTER;
  4455. pci_block_user_cfg_access(ioa_cfg->pdev);
  4456. rc = pci_write_config_byte(ioa_cfg->pdev, PCI_BIST, PCI_BIST_START);
  4457. if (rc != PCIBIOS_SUCCESSFUL) {
  4458. ipr_cmd->ioasa.ioasc = cpu_to_be32(IPR_IOASC_PCI_ACCESS_ERROR);
  4459. rc = IPR_RC_JOB_CONTINUE;
  4460. } else {
  4461. ipr_cmd->job_step = ipr_reset_restore_cfg_space;
  4462. ipr_reset_start_timer(ipr_cmd, IPR_WAIT_FOR_BIST_TIMEOUT);
  4463. rc = IPR_RC_JOB_RETURN;
  4464. }
  4465. LEAVE;
  4466. return rc;
  4467. }
  4468. /**
  4469. * ipr_reset_allowed - Query whether or not IOA can be reset
  4470. * @ioa_cfg: ioa config struct
  4471. *
  4472. * Return value:
  4473. * 0 if reset not allowed / non-zero if reset is allowed
  4474. **/
  4475. static int ipr_reset_allowed(struct ipr_ioa_cfg *ioa_cfg)
  4476. {
  4477. volatile u32 temp_reg;
  4478. temp_reg = readl(ioa_cfg->regs.sense_interrupt_reg);
  4479. return ((temp_reg & IPR_PCII_CRITICAL_OPERATION) == 0);
  4480. }
  4481. /**
  4482. * ipr_reset_wait_to_start_bist - Wait for permission to reset IOA.
  4483. * @ipr_cmd: ipr command struct
  4484. *
  4485. * Description: This function waits for adapter permission to run BIST,
  4486. * then runs BIST. If the adapter does not give permission after a
  4487. * reasonable time, we will reset the adapter anyway. The impact of
  4488. * resetting the adapter without warning the adapter is the risk of
  4489. * losing the persistent error log on the adapter. If the adapter is
  4490. * reset while it is writing to the flash on the adapter, the flash
  4491. * segment will have bad ECC and be zeroed.
  4492. *
  4493. * Return value:
  4494. * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
  4495. **/
  4496. static int ipr_reset_wait_to_start_bist(struct ipr_cmnd *ipr_cmd)
  4497. {
  4498. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  4499. int rc = IPR_RC_JOB_RETURN;
  4500. if (!ipr_reset_allowed(ioa_cfg) && ipr_cmd->u.time_left) {
  4501. ipr_cmd->u.time_left -= IPR_CHECK_FOR_RESET_TIMEOUT;
  4502. ipr_reset_start_timer(ipr_cmd, IPR_CHECK_FOR_RESET_TIMEOUT);
  4503. } else {
  4504. ipr_cmd->job_step = ipr_reset_start_bist;
  4505. rc = IPR_RC_JOB_CONTINUE;
  4506. }
  4507. return rc;
  4508. }
  4509. /**
  4510. * ipr_reset_alert_part2 - Alert the adapter of a pending reset
  4511. * @ipr_cmd: ipr command struct
  4512. *
  4513. * Description: This function alerts the adapter that it will be reset.
  4514. * If memory space is not currently enabled, proceed directly
  4515. * to running BIST on the adapter. The timer must always be started
  4516. * so we guarantee we do not run BIST from ipr_isr.
  4517. *
  4518. * Return value:
  4519. * IPR_RC_JOB_RETURN
  4520. **/
  4521. static int ipr_reset_alert(struct ipr_cmnd *ipr_cmd)
  4522. {
  4523. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  4524. u16 cmd_reg;
  4525. int rc;
  4526. ENTER;
  4527. rc = pci_read_config_word(ioa_cfg->pdev, PCI_COMMAND, &cmd_reg);
  4528. if ((rc == PCIBIOS_SUCCESSFUL) && (cmd_reg & PCI_COMMAND_MEMORY)) {
  4529. ipr_mask_and_clear_interrupts(ioa_cfg, ~0);
  4530. writel(IPR_UPROCI_RESET_ALERT, ioa_cfg->regs.set_uproc_interrupt_reg);
  4531. ipr_cmd->job_step = ipr_reset_wait_to_start_bist;
  4532. } else {
  4533. ipr_cmd->job_step = ipr_reset_start_bist;
  4534. }
  4535. ipr_cmd->u.time_left = IPR_WAIT_FOR_RESET_TIMEOUT;
  4536. ipr_reset_start_timer(ipr_cmd, IPR_CHECK_FOR_RESET_TIMEOUT);
  4537. LEAVE;
  4538. return IPR_RC_JOB_RETURN;
  4539. }
  4540. /**
  4541. * ipr_reset_ucode_download_done - Microcode download completion
  4542. * @ipr_cmd: ipr command struct
  4543. *
  4544. * Description: This function unmaps the microcode download buffer.
  4545. *
  4546. * Return value:
  4547. * IPR_RC_JOB_CONTINUE
  4548. **/
  4549. static int ipr_reset_ucode_download_done(struct ipr_cmnd *ipr_cmd)
  4550. {
  4551. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  4552. struct ipr_sglist *sglist = ioa_cfg->ucode_sglist;
  4553. pci_unmap_sg(ioa_cfg->pdev, sglist->scatterlist,
  4554. sglist->num_sg, DMA_TO_DEVICE);
  4555. ipr_cmd->job_step = ipr_reset_alert;
  4556. return IPR_RC_JOB_CONTINUE;
  4557. }
  4558. /**
  4559. * ipr_reset_ucode_download - Download microcode to the adapter
  4560. * @ipr_cmd: ipr command struct
  4561. *
  4562. * Description: This function checks to see if it there is microcode
  4563. * to download to the adapter. If there is, a download is performed.
  4564. *
  4565. * Return value:
  4566. * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
  4567. **/
  4568. static int ipr_reset_ucode_download(struct ipr_cmnd *ipr_cmd)
  4569. {
  4570. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  4571. struct ipr_sglist *sglist = ioa_cfg->ucode_sglist;
  4572. ENTER;
  4573. ipr_cmd->job_step = ipr_reset_alert;
  4574. if (!sglist)
  4575. return IPR_RC_JOB_CONTINUE;
  4576. ipr_cmd->ioarcb.res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
  4577. ipr_cmd->ioarcb.cmd_pkt.request_type = IPR_RQTYPE_SCSICDB;
  4578. ipr_cmd->ioarcb.cmd_pkt.cdb[0] = WRITE_BUFFER;
  4579. ipr_cmd->ioarcb.cmd_pkt.cdb[1] = IPR_WR_BUF_DOWNLOAD_AND_SAVE;
  4580. ipr_cmd->ioarcb.cmd_pkt.cdb[6] = (sglist->buffer_len & 0xff0000) >> 16;
  4581. ipr_cmd->ioarcb.cmd_pkt.cdb[7] = (sglist->buffer_len & 0x00ff00) >> 8;
  4582. ipr_cmd->ioarcb.cmd_pkt.cdb[8] = sglist->buffer_len & 0x0000ff;
  4583. if (ipr_map_ucode_buffer(ipr_cmd, sglist, sglist->buffer_len)) {
  4584. dev_err(&ioa_cfg->pdev->dev,
  4585. "Failed to map microcode download buffer\n");
  4586. return IPR_RC_JOB_CONTINUE;
  4587. }
  4588. ipr_cmd->job_step = ipr_reset_ucode_download_done;
  4589. ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout,
  4590. IPR_WRITE_BUFFER_TIMEOUT);
  4591. LEAVE;
  4592. return IPR_RC_JOB_RETURN;
  4593. }
  4594. /**
  4595. * ipr_reset_shutdown_ioa - Shutdown the adapter
  4596. * @ipr_cmd: ipr command struct
  4597. *
  4598. * Description: This function issues an adapter shutdown of the
  4599. * specified type to the specified adapter as part of the
  4600. * adapter reset job.
  4601. *
  4602. * Return value:
  4603. * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
  4604. **/
  4605. static int ipr_reset_shutdown_ioa(struct ipr_cmnd *ipr_cmd)
  4606. {
  4607. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  4608. enum ipr_shutdown_type shutdown_type = ipr_cmd->u.shutdown_type;
  4609. unsigned long timeout;
  4610. int rc = IPR_RC_JOB_CONTINUE;
  4611. ENTER;
  4612. if (shutdown_type != IPR_SHUTDOWN_NONE && !ioa_cfg->ioa_is_dead) {
  4613. ipr_cmd->ioarcb.res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
  4614. ipr_cmd->ioarcb.cmd_pkt.request_type = IPR_RQTYPE_IOACMD;
  4615. ipr_cmd->ioarcb.cmd_pkt.cdb[0] = IPR_IOA_SHUTDOWN;
  4616. ipr_cmd->ioarcb.cmd_pkt.cdb[1] = shutdown_type;
  4617. if (shutdown_type == IPR_SHUTDOWN_ABBREV)
  4618. timeout = IPR_ABBREV_SHUTDOWN_TIMEOUT;
  4619. else if (shutdown_type == IPR_SHUTDOWN_PREPARE_FOR_NORMAL)
  4620. timeout = IPR_INTERNAL_TIMEOUT;
  4621. else
  4622. timeout = IPR_SHUTDOWN_TIMEOUT;
  4623. ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, timeout);
  4624. rc = IPR_RC_JOB_RETURN;
  4625. ipr_cmd->job_step = ipr_reset_ucode_download;
  4626. } else
  4627. ipr_cmd->job_step = ipr_reset_alert;
  4628. LEAVE;
  4629. return rc;
  4630. }
  4631. /**
  4632. * ipr_reset_ioa_job - Adapter reset job
  4633. * @ipr_cmd: ipr command struct
  4634. *
  4635. * Description: This function is the job router for the adapter reset job.
  4636. *
  4637. * Return value:
  4638. * none
  4639. **/
  4640. static void ipr_reset_ioa_job(struct ipr_cmnd *ipr_cmd)
  4641. {
  4642. u32 rc, ioasc;
  4643. unsigned long scratch = ipr_cmd->u.scratch;
  4644. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  4645. do {
  4646. ioasc = be32_to_cpu(ipr_cmd->ioasa.ioasc);
  4647. if (ioa_cfg->reset_cmd != ipr_cmd) {
  4648. /*
  4649. * We are doing nested adapter resets and this is
  4650. * not the current reset job.
  4651. */
  4652. list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
  4653. return;
  4654. }
  4655. if (IPR_IOASC_SENSE_KEY(ioasc)) {
  4656. dev_err(&ioa_cfg->pdev->dev,
  4657. "0x%02X failed with IOASC: 0x%08X\n",
  4658. ipr_cmd->ioarcb.cmd_pkt.cdb[0], ioasc);
  4659. ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
  4660. list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
  4661. return;
  4662. }
  4663. ipr_reinit_ipr_cmnd(ipr_cmd);
  4664. ipr_cmd->u.scratch = scratch;
  4665. rc = ipr_cmd->job_step(ipr_cmd);
  4666. } while(rc == IPR_RC_JOB_CONTINUE);
  4667. }
  4668. /**
  4669. * _ipr_initiate_ioa_reset - Initiate an adapter reset
  4670. * @ioa_cfg: ioa config struct
  4671. * @job_step: first job step of reset job
  4672. * @shutdown_type: shutdown type
  4673. *
  4674. * Description: This function will initiate the reset of the given adapter
  4675. * starting at the selected job step.
  4676. * If the caller needs to wait on the completion of the reset,
  4677. * the caller must sleep on the reset_wait_q.
  4678. *
  4679. * Return value:
  4680. * none
  4681. **/
  4682. static void _ipr_initiate_ioa_reset(struct ipr_ioa_cfg *ioa_cfg,
  4683. int (*job_step) (struct ipr_cmnd *),
  4684. enum ipr_shutdown_type shutdown_type)
  4685. {
  4686. struct ipr_cmnd *ipr_cmd;
  4687. ioa_cfg->in_reset_reload = 1;
  4688. ioa_cfg->allow_cmds = 0;
  4689. scsi_block_requests(ioa_cfg->host);
  4690. ipr_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
  4691. ioa_cfg->reset_cmd = ipr_cmd;
  4692. ipr_cmd->job_step = job_step;
  4693. ipr_cmd->u.shutdown_type = shutdown_type;
  4694. ipr_reset_ioa_job(ipr_cmd);
  4695. }
  4696. /**
  4697. * ipr_initiate_ioa_reset - Initiate an adapter reset
  4698. * @ioa_cfg: ioa config struct
  4699. * @shutdown_type: shutdown type
  4700. *
  4701. * Description: This function will initiate the reset of the given adapter.
  4702. * If the caller needs to wait on the completion of the reset,
  4703. * the caller must sleep on the reset_wait_q.
  4704. *
  4705. * Return value:
  4706. * none
  4707. **/
  4708. static void ipr_initiate_ioa_reset(struct ipr_ioa_cfg *ioa_cfg,
  4709. enum ipr_shutdown_type shutdown_type)
  4710. {
  4711. if (ioa_cfg->ioa_is_dead)
  4712. return;
  4713. if (ioa_cfg->in_reset_reload && ioa_cfg->sdt_state == GET_DUMP)
  4714. ioa_cfg->sdt_state = ABORT_DUMP;
  4715. if (ioa_cfg->reset_retries++ >= IPR_NUM_RESET_RELOAD_RETRIES) {
  4716. dev_err(&ioa_cfg->pdev->dev,
  4717. "IOA taken offline - error recovery failed\n");
  4718. ioa_cfg->reset_retries = 0;
  4719. ioa_cfg->ioa_is_dead = 1;
  4720. if (ioa_cfg->in_ioa_bringdown) {
  4721. ioa_cfg->reset_cmd = NULL;
  4722. ioa_cfg->in_reset_reload = 0;
  4723. ipr_fail_all_ops(ioa_cfg);
  4724. wake_up_all(&ioa_cfg->reset_wait_q);
  4725. spin_unlock_irq(ioa_cfg->host->host_lock);
  4726. scsi_unblock_requests(ioa_cfg->host);
  4727. spin_lock_irq(ioa_cfg->host->host_lock);
  4728. return;
  4729. } else {
  4730. ioa_cfg->in_ioa_bringdown = 1;
  4731. shutdown_type = IPR_SHUTDOWN_NONE;
  4732. }
  4733. }
  4734. _ipr_initiate_ioa_reset(ioa_cfg, ipr_reset_shutdown_ioa,
  4735. shutdown_type);
  4736. }
  4737. /**
  4738. * ipr_probe_ioa_part2 - Initializes IOAs found in ipr_probe_ioa(..)
  4739. * @ioa_cfg: ioa cfg struct
  4740. *
  4741. * Description: This is the second phase of adapter intialization
  4742. * This function takes care of initilizing the adapter to the point
  4743. * where it can accept new commands.
  4744. * Return value:
  4745. * 0 on sucess / -EIO on failure
  4746. **/
  4747. static int __devinit ipr_probe_ioa_part2(struct ipr_ioa_cfg *ioa_cfg)
  4748. {
  4749. int rc = 0;
  4750. unsigned long host_lock_flags = 0;
  4751. ENTER;
  4752. spin_lock_irqsave(ioa_cfg->host->host_lock, host_lock_flags);
  4753. dev_dbg(&ioa_cfg->pdev->dev, "ioa_cfg adx: 0x%p\n", ioa_cfg);
  4754. _ipr_initiate_ioa_reset(ioa_cfg, ipr_reset_enable_ioa, IPR_SHUTDOWN_NONE);
  4755. spin_unlock_irqrestore(ioa_cfg->host->host_lock, host_lock_flags);
  4756. wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
  4757. spin_lock_irqsave(ioa_cfg->host->host_lock, host_lock_flags);
  4758. if (ioa_cfg->ioa_is_dead) {
  4759. rc = -EIO;
  4760. } else if (ipr_invalid_adapter(ioa_cfg)) {
  4761. if (!ipr_testmode)
  4762. rc = -EIO;
  4763. dev_err(&ioa_cfg->pdev->dev,
  4764. "Adapter not supported in this hardware configuration.\n");
  4765. }
  4766. spin_unlock_irqrestore(ioa_cfg->host->host_lock, host_lock_flags);
  4767. LEAVE;
  4768. return rc;
  4769. }
  4770. /**
  4771. * ipr_free_cmd_blks - Frees command blocks allocated for an adapter
  4772. * @ioa_cfg: ioa config struct
  4773. *
  4774. * Return value:
  4775. * none
  4776. **/
  4777. static void ipr_free_cmd_blks(struct ipr_ioa_cfg *ioa_cfg)
  4778. {
  4779. int i;
  4780. for (i = 0; i < IPR_NUM_CMD_BLKS; i++) {
  4781. if (ioa_cfg->ipr_cmnd_list[i])
  4782. pci_pool_free(ioa_cfg->ipr_cmd_pool,
  4783. ioa_cfg->ipr_cmnd_list[i],
  4784. ioa_cfg->ipr_cmnd_list_dma[i]);
  4785. ioa_cfg->ipr_cmnd_list[i] = NULL;
  4786. }
  4787. if (ioa_cfg->ipr_cmd_pool)
  4788. pci_pool_destroy (ioa_cfg->ipr_cmd_pool);
  4789. ioa_cfg->ipr_cmd_pool = NULL;
  4790. }
  4791. /**
  4792. * ipr_free_mem - Frees memory allocated for an adapter
  4793. * @ioa_cfg: ioa cfg struct
  4794. *
  4795. * Return value:
  4796. * nothing
  4797. **/
  4798. static void ipr_free_mem(struct ipr_ioa_cfg *ioa_cfg)
  4799. {
  4800. int i;
  4801. kfree(ioa_cfg->res_entries);
  4802. pci_free_consistent(ioa_cfg->pdev, sizeof(struct ipr_misc_cbs),
  4803. ioa_cfg->vpd_cbs, ioa_cfg->vpd_cbs_dma);
  4804. ipr_free_cmd_blks(ioa_cfg);
  4805. pci_free_consistent(ioa_cfg->pdev, sizeof(u32) * IPR_NUM_CMD_BLKS,
  4806. ioa_cfg->host_rrq, ioa_cfg->host_rrq_dma);
  4807. pci_free_consistent(ioa_cfg->pdev, sizeof(struct ipr_config_table),
  4808. ioa_cfg->cfg_table,
  4809. ioa_cfg->cfg_table_dma);
  4810. for (i = 0; i < IPR_NUM_HCAMS; i++) {
  4811. pci_free_consistent(ioa_cfg->pdev,
  4812. sizeof(struct ipr_hostrcb),
  4813. ioa_cfg->hostrcb[i],
  4814. ioa_cfg->hostrcb_dma[i]);
  4815. }
  4816. ipr_free_dump(ioa_cfg);
  4817. kfree(ioa_cfg->saved_mode_pages);
  4818. kfree(ioa_cfg->trace);
  4819. }
  4820. /**
  4821. * ipr_free_all_resources - Free all allocated resources for an adapter.
  4822. * @ipr_cmd: ipr command struct
  4823. *
  4824. * This function frees all allocated resources for the
  4825. * specified adapter.
  4826. *
  4827. * Return value:
  4828. * none
  4829. **/
  4830. static void ipr_free_all_resources(struct ipr_ioa_cfg *ioa_cfg)
  4831. {
  4832. struct pci_dev *pdev = ioa_cfg->pdev;
  4833. ENTER;
  4834. free_irq(pdev->irq, ioa_cfg);
  4835. iounmap(ioa_cfg->hdw_dma_regs);
  4836. pci_release_regions(pdev);
  4837. ipr_free_mem(ioa_cfg);
  4838. scsi_host_put(ioa_cfg->host);
  4839. pci_disable_device(pdev);
  4840. LEAVE;
  4841. }
  4842. /**
  4843. * ipr_alloc_cmd_blks - Allocate command blocks for an adapter
  4844. * @ioa_cfg: ioa config struct
  4845. *
  4846. * Return value:
  4847. * 0 on success / -ENOMEM on allocation failure
  4848. **/
  4849. static int __devinit ipr_alloc_cmd_blks(struct ipr_ioa_cfg *ioa_cfg)
  4850. {
  4851. struct ipr_cmnd *ipr_cmd;
  4852. struct ipr_ioarcb *ioarcb;
  4853. dma_addr_t dma_addr;
  4854. int i;
  4855. ioa_cfg->ipr_cmd_pool = pci_pool_create (IPR_NAME, ioa_cfg->pdev,
  4856. sizeof(struct ipr_cmnd), 8, 0);
  4857. if (!ioa_cfg->ipr_cmd_pool)
  4858. return -ENOMEM;
  4859. for (i = 0; i < IPR_NUM_CMD_BLKS; i++) {
  4860. ipr_cmd = pci_pool_alloc (ioa_cfg->ipr_cmd_pool, SLAB_KERNEL, &dma_addr);
  4861. if (!ipr_cmd) {
  4862. ipr_free_cmd_blks(ioa_cfg);
  4863. return -ENOMEM;
  4864. }
  4865. memset(ipr_cmd, 0, sizeof(*ipr_cmd));
  4866. ioa_cfg->ipr_cmnd_list[i] = ipr_cmd;
  4867. ioa_cfg->ipr_cmnd_list_dma[i] = dma_addr;
  4868. ioarcb = &ipr_cmd->ioarcb;
  4869. ioarcb->ioarcb_host_pci_addr = cpu_to_be32(dma_addr);
  4870. ioarcb->host_response_handle = cpu_to_be32(i << 2);
  4871. ioarcb->write_ioadl_addr =
  4872. cpu_to_be32(dma_addr + offsetof(struct ipr_cmnd, ioadl));
  4873. ioarcb->read_ioadl_addr = ioarcb->write_ioadl_addr;
  4874. ioarcb->ioasa_host_pci_addr =
  4875. cpu_to_be32(dma_addr + offsetof(struct ipr_cmnd, ioasa));
  4876. ioarcb->ioasa_len = cpu_to_be16(sizeof(struct ipr_ioasa));
  4877. ipr_cmd->cmd_index = i;
  4878. ipr_cmd->ioa_cfg = ioa_cfg;
  4879. ipr_cmd->sense_buffer_dma = dma_addr +
  4880. offsetof(struct ipr_cmnd, sense_buffer);
  4881. list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
  4882. }
  4883. return 0;
  4884. }
  4885. /**
  4886. * ipr_alloc_mem - Allocate memory for an adapter
  4887. * @ioa_cfg: ioa config struct
  4888. *
  4889. * Return value:
  4890. * 0 on success / non-zero for error
  4891. **/
  4892. static int __devinit ipr_alloc_mem(struct ipr_ioa_cfg *ioa_cfg)
  4893. {
  4894. struct pci_dev *pdev = ioa_cfg->pdev;
  4895. int i, rc = -ENOMEM;
  4896. ENTER;
  4897. ioa_cfg->res_entries = kmalloc(sizeof(struct ipr_resource_entry) *
  4898. IPR_MAX_PHYSICAL_DEVS, GFP_KERNEL);
  4899. if (!ioa_cfg->res_entries)
  4900. goto out;
  4901. memset(ioa_cfg->res_entries, 0,
  4902. sizeof(struct ipr_resource_entry) * IPR_MAX_PHYSICAL_DEVS);
  4903. for (i = 0; i < IPR_MAX_PHYSICAL_DEVS; i++)
  4904. list_add_tail(&ioa_cfg->res_entries[i].queue, &ioa_cfg->free_res_q);
  4905. ioa_cfg->vpd_cbs = pci_alloc_consistent(ioa_cfg->pdev,
  4906. sizeof(struct ipr_misc_cbs),
  4907. &ioa_cfg->vpd_cbs_dma);
  4908. if (!ioa_cfg->vpd_cbs)
  4909. goto out_free_res_entries;
  4910. if (ipr_alloc_cmd_blks(ioa_cfg))
  4911. goto out_free_vpd_cbs;
  4912. ioa_cfg->host_rrq = pci_alloc_consistent(ioa_cfg->pdev,
  4913. sizeof(u32) * IPR_NUM_CMD_BLKS,
  4914. &ioa_cfg->host_rrq_dma);
  4915. if (!ioa_cfg->host_rrq)
  4916. goto out_ipr_free_cmd_blocks;
  4917. ioa_cfg->cfg_table = pci_alloc_consistent(ioa_cfg->pdev,
  4918. sizeof(struct ipr_config_table),
  4919. &ioa_cfg->cfg_table_dma);
  4920. if (!ioa_cfg->cfg_table)
  4921. goto out_free_host_rrq;
  4922. for (i = 0; i < IPR_NUM_HCAMS; i++) {
  4923. ioa_cfg->hostrcb[i] = pci_alloc_consistent(ioa_cfg->pdev,
  4924. sizeof(struct ipr_hostrcb),
  4925. &ioa_cfg->hostrcb_dma[i]);
  4926. if (!ioa_cfg->hostrcb[i])
  4927. goto out_free_hostrcb_dma;
  4928. ioa_cfg->hostrcb[i]->hostrcb_dma =
  4929. ioa_cfg->hostrcb_dma[i] + offsetof(struct ipr_hostrcb, hcam);
  4930. list_add_tail(&ioa_cfg->hostrcb[i]->queue, &ioa_cfg->hostrcb_free_q);
  4931. }
  4932. ioa_cfg->trace = kmalloc(sizeof(struct ipr_trace_entry) *
  4933. IPR_NUM_TRACE_ENTRIES, GFP_KERNEL);
  4934. if (!ioa_cfg->trace)
  4935. goto out_free_hostrcb_dma;
  4936. memset(ioa_cfg->trace, 0,
  4937. sizeof(struct ipr_trace_entry) * IPR_NUM_TRACE_ENTRIES);
  4938. rc = 0;
  4939. out:
  4940. LEAVE;
  4941. return rc;
  4942. out_free_hostrcb_dma:
  4943. while (i-- > 0) {
  4944. pci_free_consistent(pdev, sizeof(struct ipr_hostrcb),
  4945. ioa_cfg->hostrcb[i],
  4946. ioa_cfg->hostrcb_dma[i]);
  4947. }
  4948. pci_free_consistent(pdev, sizeof(struct ipr_config_table),
  4949. ioa_cfg->cfg_table, ioa_cfg->cfg_table_dma);
  4950. out_free_host_rrq:
  4951. pci_free_consistent(pdev, sizeof(u32) * IPR_NUM_CMD_BLKS,
  4952. ioa_cfg->host_rrq, ioa_cfg->host_rrq_dma);
  4953. out_ipr_free_cmd_blocks:
  4954. ipr_free_cmd_blks(ioa_cfg);
  4955. out_free_vpd_cbs:
  4956. pci_free_consistent(pdev, sizeof(struct ipr_misc_cbs),
  4957. ioa_cfg->vpd_cbs, ioa_cfg->vpd_cbs_dma);
  4958. out_free_res_entries:
  4959. kfree(ioa_cfg->res_entries);
  4960. goto out;
  4961. }
  4962. /**
  4963. * ipr_initialize_bus_attr - Initialize SCSI bus attributes to default values
  4964. * @ioa_cfg: ioa config struct
  4965. *
  4966. * Return value:
  4967. * none
  4968. **/
  4969. static void __devinit ipr_initialize_bus_attr(struct ipr_ioa_cfg *ioa_cfg)
  4970. {
  4971. int i;
  4972. for (i = 0; i < IPR_MAX_NUM_BUSES; i++) {
  4973. ioa_cfg->bus_attr[i].bus = i;
  4974. ioa_cfg->bus_attr[i].qas_enabled = 0;
  4975. ioa_cfg->bus_attr[i].bus_width = IPR_DEFAULT_BUS_WIDTH;
  4976. if (ipr_max_speed < ARRAY_SIZE(ipr_max_bus_speeds))
  4977. ioa_cfg->bus_attr[i].max_xfer_rate = ipr_max_bus_speeds[ipr_max_speed];
  4978. else
  4979. ioa_cfg->bus_attr[i].max_xfer_rate = IPR_U160_SCSI_RATE;
  4980. }
  4981. }
  4982. /**
  4983. * ipr_init_ioa_cfg - Initialize IOA config struct
  4984. * @ioa_cfg: ioa config struct
  4985. * @host: scsi host struct
  4986. * @pdev: PCI dev struct
  4987. *
  4988. * Return value:
  4989. * none
  4990. **/
  4991. static void __devinit ipr_init_ioa_cfg(struct ipr_ioa_cfg *ioa_cfg,
  4992. struct Scsi_Host *host, struct pci_dev *pdev)
  4993. {
  4994. const struct ipr_interrupt_offsets *p;
  4995. struct ipr_interrupts *t;
  4996. void __iomem *base;
  4997. ioa_cfg->host = host;
  4998. ioa_cfg->pdev = pdev;
  4999. ioa_cfg->log_level = ipr_log_level;
  5000. sprintf(ioa_cfg->eye_catcher, IPR_EYECATCHER);
  5001. sprintf(ioa_cfg->trace_start, IPR_TRACE_START_LABEL);
  5002. sprintf(ioa_cfg->ipr_free_label, IPR_FREEQ_LABEL);
  5003. sprintf(ioa_cfg->ipr_pending_label, IPR_PENDQ_LABEL);
  5004. sprintf(ioa_cfg->cfg_table_start, IPR_CFG_TBL_START);
  5005. sprintf(ioa_cfg->resource_table_label, IPR_RES_TABLE_LABEL);
  5006. sprintf(ioa_cfg->ipr_hcam_label, IPR_HCAM_LABEL);
  5007. sprintf(ioa_cfg->ipr_cmd_label, IPR_CMD_LABEL);
  5008. INIT_LIST_HEAD(&ioa_cfg->free_q);
  5009. INIT_LIST_HEAD(&ioa_cfg->pending_q);
  5010. INIT_LIST_HEAD(&ioa_cfg->hostrcb_free_q);
  5011. INIT_LIST_HEAD(&ioa_cfg->hostrcb_pending_q);
  5012. INIT_LIST_HEAD(&ioa_cfg->free_res_q);
  5013. INIT_LIST_HEAD(&ioa_cfg->used_res_q);
  5014. INIT_WORK(&ioa_cfg->work_q, ipr_worker_thread, ioa_cfg);
  5015. init_waitqueue_head(&ioa_cfg->reset_wait_q);
  5016. ioa_cfg->sdt_state = INACTIVE;
  5017. if (ipr_enable_cache)
  5018. ioa_cfg->cache_state = CACHE_ENABLED;
  5019. else
  5020. ioa_cfg->cache_state = CACHE_DISABLED;
  5021. ipr_initialize_bus_attr(ioa_cfg);
  5022. host->max_id = IPR_MAX_NUM_TARGETS_PER_BUS;
  5023. host->max_lun = IPR_MAX_NUM_LUNS_PER_TARGET;
  5024. host->max_channel = IPR_MAX_BUS_TO_SCAN;
  5025. host->unique_id = host->host_no;
  5026. host->max_cmd_len = IPR_MAX_CDB_LEN;
  5027. pci_set_drvdata(pdev, ioa_cfg);
  5028. p = &ioa_cfg->chip_cfg->regs;
  5029. t = &ioa_cfg->regs;
  5030. base = ioa_cfg->hdw_dma_regs;
  5031. t->set_interrupt_mask_reg = base + p->set_interrupt_mask_reg;
  5032. t->clr_interrupt_mask_reg = base + p->clr_interrupt_mask_reg;
  5033. t->sense_interrupt_mask_reg = base + p->sense_interrupt_mask_reg;
  5034. t->clr_interrupt_reg = base + p->clr_interrupt_reg;
  5035. t->sense_interrupt_reg = base + p->sense_interrupt_reg;
  5036. t->ioarrin_reg = base + p->ioarrin_reg;
  5037. t->sense_uproc_interrupt_reg = base + p->sense_uproc_interrupt_reg;
  5038. t->set_uproc_interrupt_reg = base + p->set_uproc_interrupt_reg;
  5039. t->clr_uproc_interrupt_reg = base + p->clr_uproc_interrupt_reg;
  5040. }
  5041. /**
  5042. * ipr_get_chip_cfg - Find adapter chip configuration
  5043. * @dev_id: PCI device id struct
  5044. *
  5045. * Return value:
  5046. * ptr to chip config on success / NULL on failure
  5047. **/
  5048. static const struct ipr_chip_cfg_t * __devinit
  5049. ipr_get_chip_cfg(const struct pci_device_id *dev_id)
  5050. {
  5051. int i;
  5052. if (dev_id->driver_data)
  5053. return (const struct ipr_chip_cfg_t *)dev_id->driver_data;
  5054. for (i = 0; i < ARRAY_SIZE(ipr_chip); i++)
  5055. if (ipr_chip[i].vendor == dev_id->vendor &&
  5056. ipr_chip[i].device == dev_id->device)
  5057. return ipr_chip[i].cfg;
  5058. return NULL;
  5059. }
  5060. /**
  5061. * ipr_probe_ioa - Allocates memory and does first stage of initialization
  5062. * @pdev: PCI device struct
  5063. * @dev_id: PCI device id struct
  5064. *
  5065. * Return value:
  5066. * 0 on success / non-zero on failure
  5067. **/
  5068. static int __devinit ipr_probe_ioa(struct pci_dev *pdev,
  5069. const struct pci_device_id *dev_id)
  5070. {
  5071. struct ipr_ioa_cfg *ioa_cfg;
  5072. struct Scsi_Host *host;
  5073. unsigned long ipr_regs_pci;
  5074. void __iomem *ipr_regs;
  5075. u32 rc = PCIBIOS_SUCCESSFUL;
  5076. ENTER;
  5077. if ((rc = pci_enable_device(pdev))) {
  5078. dev_err(&pdev->dev, "Cannot enable adapter\n");
  5079. goto out;
  5080. }
  5081. dev_info(&pdev->dev, "Found IOA with IRQ: %d\n", pdev->irq);
  5082. host = scsi_host_alloc(&driver_template, sizeof(*ioa_cfg));
  5083. if (!host) {
  5084. dev_err(&pdev->dev, "call to scsi_host_alloc failed!\n");
  5085. rc = -ENOMEM;
  5086. goto out_disable;
  5087. }
  5088. ioa_cfg = (struct ipr_ioa_cfg *)host->hostdata;
  5089. memset(ioa_cfg, 0, sizeof(struct ipr_ioa_cfg));
  5090. ioa_cfg->chip_cfg = ipr_get_chip_cfg(dev_id);
  5091. if (!ioa_cfg->chip_cfg) {
  5092. dev_err(&pdev->dev, "Unknown adapter chipset 0x%04X 0x%04X\n",
  5093. dev_id->vendor, dev_id->device);
  5094. goto out_scsi_host_put;
  5095. }
  5096. ipr_regs_pci = pci_resource_start(pdev, 0);
  5097. rc = pci_request_regions(pdev, IPR_NAME);
  5098. if (rc < 0) {
  5099. dev_err(&pdev->dev,
  5100. "Couldn't register memory range of registers\n");
  5101. goto out_scsi_host_put;
  5102. }
  5103. ipr_regs = ioremap(ipr_regs_pci, pci_resource_len(pdev, 0));
  5104. if (!ipr_regs) {
  5105. dev_err(&pdev->dev,
  5106. "Couldn't map memory range of registers\n");
  5107. rc = -ENOMEM;
  5108. goto out_release_regions;
  5109. }
  5110. ioa_cfg->hdw_dma_regs = ipr_regs;
  5111. ioa_cfg->hdw_dma_regs_pci = ipr_regs_pci;
  5112. ioa_cfg->ioa_mailbox = ioa_cfg->chip_cfg->mailbox + ipr_regs;
  5113. ipr_init_ioa_cfg(ioa_cfg, host, pdev);
  5114. pci_set_master(pdev);
  5115. rc = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
  5116. if (rc < 0) {
  5117. dev_err(&pdev->dev, "Failed to set PCI DMA mask\n");
  5118. goto cleanup_nomem;
  5119. }
  5120. rc = pci_write_config_byte(pdev, PCI_CACHE_LINE_SIZE,
  5121. ioa_cfg->chip_cfg->cache_line_size);
  5122. if (rc != PCIBIOS_SUCCESSFUL) {
  5123. dev_err(&pdev->dev, "Write of cache line size failed\n");
  5124. rc = -EIO;
  5125. goto cleanup_nomem;
  5126. }
  5127. /* Save away PCI config space for use following IOA reset */
  5128. rc = pci_save_state(pdev);
  5129. if (rc != PCIBIOS_SUCCESSFUL) {
  5130. dev_err(&pdev->dev, "Failed to save PCI config space\n");
  5131. rc = -EIO;
  5132. goto cleanup_nomem;
  5133. }
  5134. if ((rc = ipr_save_pcix_cmd_reg(ioa_cfg)))
  5135. goto cleanup_nomem;
  5136. if ((rc = ipr_set_pcix_cmd_reg(ioa_cfg)))
  5137. goto cleanup_nomem;
  5138. rc = ipr_alloc_mem(ioa_cfg);
  5139. if (rc < 0) {
  5140. dev_err(&pdev->dev,
  5141. "Couldn't allocate enough memory for device driver!\n");
  5142. goto cleanup_nomem;
  5143. }
  5144. ipr_mask_and_clear_interrupts(ioa_cfg, ~IPR_PCII_IOA_TRANS_TO_OPER);
  5145. rc = request_irq(pdev->irq, ipr_isr, SA_SHIRQ, IPR_NAME, ioa_cfg);
  5146. if (rc) {
  5147. dev_err(&pdev->dev, "Couldn't register IRQ %d! rc=%d\n",
  5148. pdev->irq, rc);
  5149. goto cleanup_nolog;
  5150. }
  5151. spin_lock(&ipr_driver_lock);
  5152. list_add_tail(&ioa_cfg->queue, &ipr_ioa_head);
  5153. spin_unlock(&ipr_driver_lock);
  5154. LEAVE;
  5155. out:
  5156. return rc;
  5157. cleanup_nolog:
  5158. ipr_free_mem(ioa_cfg);
  5159. cleanup_nomem:
  5160. iounmap(ipr_regs);
  5161. out_release_regions:
  5162. pci_release_regions(pdev);
  5163. out_scsi_host_put:
  5164. scsi_host_put(host);
  5165. out_disable:
  5166. pci_disable_device(pdev);
  5167. goto out;
  5168. }
  5169. /**
  5170. * ipr_scan_vsets - Scans for VSET devices
  5171. * @ioa_cfg: ioa config struct
  5172. *
  5173. * Description: Since the VSET resources do not follow SAM in that we can have
  5174. * sparse LUNs with no LUN 0, we have to scan for these ourselves.
  5175. *
  5176. * Return value:
  5177. * none
  5178. **/
  5179. static void ipr_scan_vsets(struct ipr_ioa_cfg *ioa_cfg)
  5180. {
  5181. int target, lun;
  5182. for (target = 0; target < IPR_MAX_NUM_TARGETS_PER_BUS; target++)
  5183. for (lun = 0; lun < IPR_MAX_NUM_VSET_LUNS_PER_TARGET; lun++ )
  5184. scsi_add_device(ioa_cfg->host, IPR_VSET_BUS, target, lun);
  5185. }
  5186. /**
  5187. * ipr_initiate_ioa_bringdown - Bring down an adapter
  5188. * @ioa_cfg: ioa config struct
  5189. * @shutdown_type: shutdown type
  5190. *
  5191. * Description: This function will initiate bringing down the adapter.
  5192. * This consists of issuing an IOA shutdown to the adapter
  5193. * to flush the cache, and running BIST.
  5194. * If the caller needs to wait on the completion of the reset,
  5195. * the caller must sleep on the reset_wait_q.
  5196. *
  5197. * Return value:
  5198. * none
  5199. **/
  5200. static void ipr_initiate_ioa_bringdown(struct ipr_ioa_cfg *ioa_cfg,
  5201. enum ipr_shutdown_type shutdown_type)
  5202. {
  5203. ENTER;
  5204. if (ioa_cfg->sdt_state == WAIT_FOR_DUMP)
  5205. ioa_cfg->sdt_state = ABORT_DUMP;
  5206. ioa_cfg->reset_retries = 0;
  5207. ioa_cfg->in_ioa_bringdown = 1;
  5208. ipr_initiate_ioa_reset(ioa_cfg, shutdown_type);
  5209. LEAVE;
  5210. }
  5211. /**
  5212. * __ipr_remove - Remove a single adapter
  5213. * @pdev: pci device struct
  5214. *
  5215. * Adapter hot plug remove entry point.
  5216. *
  5217. * Return value:
  5218. * none
  5219. **/
  5220. static void __ipr_remove(struct pci_dev *pdev)
  5221. {
  5222. unsigned long host_lock_flags = 0;
  5223. struct ipr_ioa_cfg *ioa_cfg = pci_get_drvdata(pdev);
  5224. ENTER;
  5225. spin_lock_irqsave(ioa_cfg->host->host_lock, host_lock_flags);
  5226. ipr_initiate_ioa_bringdown(ioa_cfg, IPR_SHUTDOWN_NORMAL);
  5227. spin_unlock_irqrestore(ioa_cfg->host->host_lock, host_lock_flags);
  5228. wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
  5229. flush_scheduled_work();
  5230. spin_lock_irqsave(ioa_cfg->host->host_lock, host_lock_flags);
  5231. spin_lock(&ipr_driver_lock);
  5232. list_del(&ioa_cfg->queue);
  5233. spin_unlock(&ipr_driver_lock);
  5234. if (ioa_cfg->sdt_state == ABORT_DUMP)
  5235. ioa_cfg->sdt_state = WAIT_FOR_DUMP;
  5236. spin_unlock_irqrestore(ioa_cfg->host->host_lock, host_lock_flags);
  5237. ipr_free_all_resources(ioa_cfg);
  5238. LEAVE;
  5239. }
  5240. /**
  5241. * ipr_remove - IOA hot plug remove entry point
  5242. * @pdev: pci device struct
  5243. *
  5244. * Adapter hot plug remove entry point.
  5245. *
  5246. * Return value:
  5247. * none
  5248. **/
  5249. static void ipr_remove(struct pci_dev *pdev)
  5250. {
  5251. struct ipr_ioa_cfg *ioa_cfg = pci_get_drvdata(pdev);
  5252. ENTER;
  5253. ipr_remove_trace_file(&ioa_cfg->host->shost_classdev.kobj,
  5254. &ipr_trace_attr);
  5255. ipr_remove_dump_file(&ioa_cfg->host->shost_classdev.kobj,
  5256. &ipr_dump_attr);
  5257. scsi_remove_host(ioa_cfg->host);
  5258. __ipr_remove(pdev);
  5259. LEAVE;
  5260. }
  5261. /**
  5262. * ipr_probe - Adapter hot plug add entry point
  5263. *
  5264. * Return value:
  5265. * 0 on success / non-zero on failure
  5266. **/
  5267. static int __devinit ipr_probe(struct pci_dev *pdev,
  5268. const struct pci_device_id *dev_id)
  5269. {
  5270. struct ipr_ioa_cfg *ioa_cfg;
  5271. int rc;
  5272. rc = ipr_probe_ioa(pdev, dev_id);
  5273. if (rc)
  5274. return rc;
  5275. ioa_cfg = pci_get_drvdata(pdev);
  5276. rc = ipr_probe_ioa_part2(ioa_cfg);
  5277. if (rc) {
  5278. __ipr_remove(pdev);
  5279. return rc;
  5280. }
  5281. rc = scsi_add_host(ioa_cfg->host, &pdev->dev);
  5282. if (rc) {
  5283. __ipr_remove(pdev);
  5284. return rc;
  5285. }
  5286. rc = ipr_create_trace_file(&ioa_cfg->host->shost_classdev.kobj,
  5287. &ipr_trace_attr);
  5288. if (rc) {
  5289. scsi_remove_host(ioa_cfg->host);
  5290. __ipr_remove(pdev);
  5291. return rc;
  5292. }
  5293. rc = ipr_create_dump_file(&ioa_cfg->host->shost_classdev.kobj,
  5294. &ipr_dump_attr);
  5295. if (rc) {
  5296. ipr_remove_trace_file(&ioa_cfg->host->shost_classdev.kobj,
  5297. &ipr_trace_attr);
  5298. scsi_remove_host(ioa_cfg->host);
  5299. __ipr_remove(pdev);
  5300. return rc;
  5301. }
  5302. scsi_scan_host(ioa_cfg->host);
  5303. ipr_scan_vsets(ioa_cfg);
  5304. scsi_add_device(ioa_cfg->host, IPR_IOA_BUS, IPR_IOA_TARGET, IPR_IOA_LUN);
  5305. ioa_cfg->allow_ml_add_del = 1;
  5306. ioa_cfg->host->max_channel = IPR_VSET_BUS;
  5307. schedule_work(&ioa_cfg->work_q);
  5308. return 0;
  5309. }
  5310. /**
  5311. * ipr_shutdown - Shutdown handler.
  5312. * @pdev: pci device struct
  5313. *
  5314. * This function is invoked upon system shutdown/reboot. It will issue
  5315. * an adapter shutdown to the adapter to flush the write cache.
  5316. *
  5317. * Return value:
  5318. * none
  5319. **/
  5320. static void ipr_shutdown(struct pci_dev *pdev)
  5321. {
  5322. struct ipr_ioa_cfg *ioa_cfg = pci_get_drvdata(pdev);
  5323. unsigned long lock_flags = 0;
  5324. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  5325. ipr_initiate_ioa_bringdown(ioa_cfg, IPR_SHUTDOWN_NORMAL);
  5326. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  5327. wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
  5328. }
  5329. static struct pci_device_id ipr_pci_table[] __devinitdata = {
  5330. { PCI_VENDOR_ID_MYLEX, PCI_DEVICE_ID_IBM_GEMSTONE,
  5331. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_5702,
  5332. 0, 0, (kernel_ulong_t)&ipr_chip_cfg[0] },
  5333. { PCI_VENDOR_ID_MYLEX, PCI_DEVICE_ID_IBM_GEMSTONE,
  5334. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_5703,
  5335. 0, 0, (kernel_ulong_t)&ipr_chip_cfg[0] },
  5336. { PCI_VENDOR_ID_MYLEX, PCI_DEVICE_ID_IBM_GEMSTONE,
  5337. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_573D,
  5338. 0, 0, (kernel_ulong_t)&ipr_chip_cfg[0] },
  5339. { PCI_VENDOR_ID_MYLEX, PCI_DEVICE_ID_IBM_GEMSTONE,
  5340. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_573E,
  5341. 0, 0, (kernel_ulong_t)&ipr_chip_cfg[0] },
  5342. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CITRINE,
  5343. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_571B,
  5344. 0, 0, (kernel_ulong_t)&ipr_chip_cfg[0] },
  5345. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CITRINE,
  5346. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_572E,
  5347. 0, 0, (kernel_ulong_t)&ipr_chip_cfg[0] },
  5348. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CITRINE,
  5349. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_571A,
  5350. 0, 0, (kernel_ulong_t)&ipr_chip_cfg[0] },
  5351. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_SNIPE,
  5352. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_2780,
  5353. 0, 0, (kernel_ulong_t)&ipr_chip_cfg[1] },
  5354. { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_SCAMP,
  5355. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_571E,
  5356. 0, 0, (kernel_ulong_t)&ipr_chip_cfg[1] },
  5357. { }
  5358. };
  5359. MODULE_DEVICE_TABLE(pci, ipr_pci_table);
  5360. static struct pci_driver ipr_driver = {
  5361. .name = IPR_NAME,
  5362. .id_table = ipr_pci_table,
  5363. .probe = ipr_probe,
  5364. .remove = ipr_remove,
  5365. .shutdown = ipr_shutdown,
  5366. };
  5367. /**
  5368. * ipr_init - Module entry point
  5369. *
  5370. * Return value:
  5371. * 0 on success / negative value on failure
  5372. **/
  5373. static int __init ipr_init(void)
  5374. {
  5375. ipr_info("IBM Power RAID SCSI Device Driver version: %s %s\n",
  5376. IPR_DRIVER_VERSION, IPR_DRIVER_DATE);
  5377. return pci_module_init(&ipr_driver);
  5378. }
  5379. /**
  5380. * ipr_exit - Module unload
  5381. *
  5382. * Module unload entry point.
  5383. *
  5384. * Return value:
  5385. * none
  5386. **/
  5387. static void __exit ipr_exit(void)
  5388. {
  5389. pci_unregister_driver(&ipr_driver);
  5390. }
  5391. module_init(ipr_init);
  5392. module_exit(ipr_exit);