ipr.c 302 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879
  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/fs.h>
  56. #include <linux/init.h>
  57. #include <linux/types.h>
  58. #include <linux/errno.h>
  59. #include <linux/kernel.h>
  60. #include <linux/slab.h>
  61. #include <linux/vmalloc.h>
  62. #include <linux/ioport.h>
  63. #include <linux/delay.h>
  64. #include <linux/pci.h>
  65. #include <linux/wait.h>
  66. #include <linux/spinlock.h>
  67. #include <linux/sched.h>
  68. #include <linux/interrupt.h>
  69. #include <linux/blkdev.h>
  70. #include <linux/firmware.h>
  71. #include <linux/module.h>
  72. #include <linux/moduleparam.h>
  73. #include <linux/libata.h>
  74. #include <linux/hdreg.h>
  75. #include <linux/reboot.h>
  76. #include <linux/stringify.h>
  77. #include <asm/io.h>
  78. #include <asm/irq.h>
  79. #include <asm/processor.h>
  80. #include <scsi/scsi.h>
  81. #include <scsi/scsi_host.h>
  82. #include <scsi/scsi_tcq.h>
  83. #include <scsi/scsi_eh.h>
  84. #include <scsi/scsi_cmnd.h>
  85. #include "ipr.h"
  86. /*
  87. * Global Data
  88. */
  89. static LIST_HEAD(ipr_ioa_head);
  90. static unsigned int ipr_log_level = IPR_DEFAULT_LOG_LEVEL;
  91. static unsigned int ipr_max_speed = 1;
  92. static int ipr_testmode = 0;
  93. static unsigned int ipr_fastfail = 0;
  94. static unsigned int ipr_transop_timeout = 0;
  95. static unsigned int ipr_debug = 0;
  96. static unsigned int ipr_max_devs = IPR_DEFAULT_SIS64_DEVS;
  97. static unsigned int ipr_dual_ioa_raid = 1;
  98. static unsigned int ipr_number_of_msix = 16;
  99. static unsigned int ipr_fast_reboot;
  100. static DEFINE_SPINLOCK(ipr_driver_lock);
  101. /* This table describes the differences between DMA controller chips */
  102. static const struct ipr_chip_cfg_t ipr_chip_cfg[] = {
  103. { /* Gemstone, Citrine, Obsidian, and Obsidian-E */
  104. .mailbox = 0x0042C,
  105. .max_cmds = 100,
  106. .cache_line_size = 0x20,
  107. .clear_isr = 1,
  108. .iopoll_weight = 0,
  109. {
  110. .set_interrupt_mask_reg = 0x0022C,
  111. .clr_interrupt_mask_reg = 0x00230,
  112. .clr_interrupt_mask_reg32 = 0x00230,
  113. .sense_interrupt_mask_reg = 0x0022C,
  114. .sense_interrupt_mask_reg32 = 0x0022C,
  115. .clr_interrupt_reg = 0x00228,
  116. .clr_interrupt_reg32 = 0x00228,
  117. .sense_interrupt_reg = 0x00224,
  118. .sense_interrupt_reg32 = 0x00224,
  119. .ioarrin_reg = 0x00404,
  120. .sense_uproc_interrupt_reg = 0x00214,
  121. .sense_uproc_interrupt_reg32 = 0x00214,
  122. .set_uproc_interrupt_reg = 0x00214,
  123. .set_uproc_interrupt_reg32 = 0x00214,
  124. .clr_uproc_interrupt_reg = 0x00218,
  125. .clr_uproc_interrupt_reg32 = 0x00218
  126. }
  127. },
  128. { /* Snipe and Scamp */
  129. .mailbox = 0x0052C,
  130. .max_cmds = 100,
  131. .cache_line_size = 0x20,
  132. .clear_isr = 1,
  133. .iopoll_weight = 0,
  134. {
  135. .set_interrupt_mask_reg = 0x00288,
  136. .clr_interrupt_mask_reg = 0x0028C,
  137. .clr_interrupt_mask_reg32 = 0x0028C,
  138. .sense_interrupt_mask_reg = 0x00288,
  139. .sense_interrupt_mask_reg32 = 0x00288,
  140. .clr_interrupt_reg = 0x00284,
  141. .clr_interrupt_reg32 = 0x00284,
  142. .sense_interrupt_reg = 0x00280,
  143. .sense_interrupt_reg32 = 0x00280,
  144. .ioarrin_reg = 0x00504,
  145. .sense_uproc_interrupt_reg = 0x00290,
  146. .sense_uproc_interrupt_reg32 = 0x00290,
  147. .set_uproc_interrupt_reg = 0x00290,
  148. .set_uproc_interrupt_reg32 = 0x00290,
  149. .clr_uproc_interrupt_reg = 0x00294,
  150. .clr_uproc_interrupt_reg32 = 0x00294
  151. }
  152. },
  153. { /* CRoC */
  154. .mailbox = 0x00044,
  155. .max_cmds = 1000,
  156. .cache_line_size = 0x20,
  157. .clear_isr = 0,
  158. .iopoll_weight = 64,
  159. {
  160. .set_interrupt_mask_reg = 0x00010,
  161. .clr_interrupt_mask_reg = 0x00018,
  162. .clr_interrupt_mask_reg32 = 0x0001C,
  163. .sense_interrupt_mask_reg = 0x00010,
  164. .sense_interrupt_mask_reg32 = 0x00014,
  165. .clr_interrupt_reg = 0x00008,
  166. .clr_interrupt_reg32 = 0x0000C,
  167. .sense_interrupt_reg = 0x00000,
  168. .sense_interrupt_reg32 = 0x00004,
  169. .ioarrin_reg = 0x00070,
  170. .sense_uproc_interrupt_reg = 0x00020,
  171. .sense_uproc_interrupt_reg32 = 0x00024,
  172. .set_uproc_interrupt_reg = 0x00020,
  173. .set_uproc_interrupt_reg32 = 0x00024,
  174. .clr_uproc_interrupt_reg = 0x00028,
  175. .clr_uproc_interrupt_reg32 = 0x0002C,
  176. .init_feedback_reg = 0x0005C,
  177. .dump_addr_reg = 0x00064,
  178. .dump_data_reg = 0x00068,
  179. .endian_swap_reg = 0x00084
  180. }
  181. },
  182. };
  183. static const struct ipr_chip_t ipr_chip[] = {
  184. { PCI_VENDOR_ID_MYLEX, PCI_DEVICE_ID_IBM_GEMSTONE, false, IPR_SIS32, IPR_PCI_CFG, &ipr_chip_cfg[0] },
  185. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CITRINE, false, IPR_SIS32, IPR_PCI_CFG, &ipr_chip_cfg[0] },
  186. { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_OBSIDIAN, false, IPR_SIS32, IPR_PCI_CFG, &ipr_chip_cfg[0] },
  187. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN, false, IPR_SIS32, IPR_PCI_CFG, &ipr_chip_cfg[0] },
  188. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN_E, true, IPR_SIS32, IPR_PCI_CFG, &ipr_chip_cfg[0] },
  189. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_SNIPE, false, IPR_SIS32, IPR_PCI_CFG, &ipr_chip_cfg[1] },
  190. { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_SCAMP, false, IPR_SIS32, IPR_PCI_CFG, &ipr_chip_cfg[1] },
  191. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROC_FPGA_E2, true, IPR_SIS64, IPR_MMIO, &ipr_chip_cfg[2] },
  192. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE, true, IPR_SIS64, IPR_MMIO, &ipr_chip_cfg[2] },
  193. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_RATTLESNAKE, true, IPR_SIS64, IPR_MMIO, &ipr_chip_cfg[2] }
  194. };
  195. static int ipr_max_bus_speeds[] = {
  196. IPR_80MBs_SCSI_RATE, IPR_U160_SCSI_RATE, IPR_U320_SCSI_RATE
  197. };
  198. MODULE_AUTHOR("Brian King <brking@us.ibm.com>");
  199. MODULE_DESCRIPTION("IBM Power RAID SCSI Adapter Driver");
  200. module_param_named(max_speed, ipr_max_speed, uint, 0);
  201. MODULE_PARM_DESC(max_speed, "Maximum bus speed (0-2). Default: 1=U160. Speeds: 0=80 MB/s, 1=U160, 2=U320");
  202. module_param_named(log_level, ipr_log_level, uint, 0);
  203. MODULE_PARM_DESC(log_level, "Set to 0 - 4 for increasing verbosity of device driver");
  204. module_param_named(testmode, ipr_testmode, int, 0);
  205. MODULE_PARM_DESC(testmode, "DANGEROUS!!! Allows unsupported configurations");
  206. module_param_named(fastfail, ipr_fastfail, int, S_IRUGO | S_IWUSR);
  207. MODULE_PARM_DESC(fastfail, "Reduce timeouts and retries");
  208. module_param_named(transop_timeout, ipr_transop_timeout, int, 0);
  209. MODULE_PARM_DESC(transop_timeout, "Time in seconds to wait for adapter to come operational (default: 300)");
  210. module_param_named(debug, ipr_debug, int, S_IRUGO | S_IWUSR);
  211. MODULE_PARM_DESC(debug, "Enable device driver debugging logging. Set to 1 to enable. (default: 0)");
  212. module_param_named(dual_ioa_raid, ipr_dual_ioa_raid, int, 0);
  213. MODULE_PARM_DESC(dual_ioa_raid, "Enable dual adapter RAID support. Set to 1 to enable. (default: 1)");
  214. module_param_named(max_devs, ipr_max_devs, int, 0);
  215. MODULE_PARM_DESC(max_devs, "Specify the maximum number of physical devices. "
  216. "[Default=" __stringify(IPR_DEFAULT_SIS64_DEVS) "]");
  217. module_param_named(number_of_msix, ipr_number_of_msix, int, 0);
  218. MODULE_PARM_DESC(number_of_msix, "Specify the number of MSIX interrupts to use on capable adapters (1 - 16). (default:16)");
  219. module_param_named(fast_reboot, ipr_fast_reboot, int, S_IRUGO | S_IWUSR);
  220. MODULE_PARM_DESC(fast_reboot, "Skip adapter shutdown during reboot. Set to 1 to enable. (default: 0)");
  221. MODULE_LICENSE("GPL");
  222. MODULE_VERSION(IPR_DRIVER_VERSION);
  223. /* A constant array of IOASCs/URCs/Error Messages */
  224. static const
  225. struct ipr_error_table_t ipr_error_table[] = {
  226. {0x00000000, 1, IPR_DEFAULT_LOG_LEVEL,
  227. "8155: An unknown error was received"},
  228. {0x00330000, 0, 0,
  229. "Soft underlength error"},
  230. {0x005A0000, 0, 0,
  231. "Command to be cancelled not found"},
  232. {0x00808000, 0, 0,
  233. "Qualified success"},
  234. {0x01080000, 1, IPR_DEFAULT_LOG_LEVEL,
  235. "FFFE: Soft device bus error recovered by the IOA"},
  236. {0x01088100, 0, IPR_DEFAULT_LOG_LEVEL,
  237. "4101: Soft device bus fabric error"},
  238. {0x01100100, 0, IPR_DEFAULT_LOG_LEVEL,
  239. "FFFC: Logical block guard error recovered by the device"},
  240. {0x01100300, 0, IPR_DEFAULT_LOG_LEVEL,
  241. "FFFC: Logical block reference tag error recovered by the device"},
  242. {0x01108300, 0, IPR_DEFAULT_LOG_LEVEL,
  243. "4171: Recovered scatter list tag / sequence number error"},
  244. {0x01109000, 0, IPR_DEFAULT_LOG_LEVEL,
  245. "FF3D: Recovered logical block CRC error on IOA to Host transfer"},
  246. {0x01109200, 0, IPR_DEFAULT_LOG_LEVEL,
  247. "4171: Recovered logical block sequence number error on IOA to Host transfer"},
  248. {0x0110A000, 0, IPR_DEFAULT_LOG_LEVEL,
  249. "FFFD: Recovered logical block reference tag error detected by the IOA"},
  250. {0x0110A100, 0, IPR_DEFAULT_LOG_LEVEL,
  251. "FFFD: Logical block guard error recovered by the IOA"},
  252. {0x01170600, 0, IPR_DEFAULT_LOG_LEVEL,
  253. "FFF9: Device sector reassign successful"},
  254. {0x01170900, 0, IPR_DEFAULT_LOG_LEVEL,
  255. "FFF7: Media error recovered by device rewrite procedures"},
  256. {0x01180200, 0, IPR_DEFAULT_LOG_LEVEL,
  257. "7001: IOA sector reassignment successful"},
  258. {0x01180500, 0, IPR_DEFAULT_LOG_LEVEL,
  259. "FFF9: Soft media error. Sector reassignment recommended"},
  260. {0x01180600, 0, IPR_DEFAULT_LOG_LEVEL,
  261. "FFF7: Media error recovered by IOA rewrite procedures"},
  262. {0x01418000, 0, IPR_DEFAULT_LOG_LEVEL,
  263. "FF3D: Soft PCI bus error recovered by the IOA"},
  264. {0x01440000, 1, IPR_DEFAULT_LOG_LEVEL,
  265. "FFF6: Device hardware error recovered by the IOA"},
  266. {0x01448100, 0, IPR_DEFAULT_LOG_LEVEL,
  267. "FFF6: Device hardware error recovered by the device"},
  268. {0x01448200, 1, IPR_DEFAULT_LOG_LEVEL,
  269. "FF3D: Soft IOA error recovered by the IOA"},
  270. {0x01448300, 0, IPR_DEFAULT_LOG_LEVEL,
  271. "FFFA: Undefined device response recovered by the IOA"},
  272. {0x014A0000, 1, IPR_DEFAULT_LOG_LEVEL,
  273. "FFF6: Device bus error, message or command phase"},
  274. {0x014A8000, 0, IPR_DEFAULT_LOG_LEVEL,
  275. "FFFE: Task Management Function failed"},
  276. {0x015D0000, 0, IPR_DEFAULT_LOG_LEVEL,
  277. "FFF6: Failure prediction threshold exceeded"},
  278. {0x015D9200, 0, IPR_DEFAULT_LOG_LEVEL,
  279. "8009: Impending cache battery pack failure"},
  280. {0x02040100, 0, 0,
  281. "Logical Unit in process of becoming ready"},
  282. {0x02040200, 0, 0,
  283. "Initializing command required"},
  284. {0x02040400, 0, 0,
  285. "34FF: Disk device format in progress"},
  286. {0x02040C00, 0, 0,
  287. "Logical unit not accessible, target port in unavailable state"},
  288. {0x02048000, 0, IPR_DEFAULT_LOG_LEVEL,
  289. "9070: IOA requested reset"},
  290. {0x023F0000, 0, 0,
  291. "Synchronization required"},
  292. {0x02408500, 0, 0,
  293. "IOA microcode download required"},
  294. {0x02408600, 0, 0,
  295. "Device bus connection is prohibited by host"},
  296. {0x024E0000, 0, 0,
  297. "No ready, IOA shutdown"},
  298. {0x025A0000, 0, 0,
  299. "Not ready, IOA has been shutdown"},
  300. {0x02670100, 0, IPR_DEFAULT_LOG_LEVEL,
  301. "3020: Storage subsystem configuration error"},
  302. {0x03110B00, 0, 0,
  303. "FFF5: Medium error, data unreadable, recommend reassign"},
  304. {0x03110C00, 0, 0,
  305. "7000: Medium error, data unreadable, do not reassign"},
  306. {0x03310000, 0, IPR_DEFAULT_LOG_LEVEL,
  307. "FFF3: Disk media format bad"},
  308. {0x04050000, 0, IPR_DEFAULT_LOG_LEVEL,
  309. "3002: Addressed device failed to respond to selection"},
  310. {0x04080000, 1, IPR_DEFAULT_LOG_LEVEL,
  311. "3100: Device bus error"},
  312. {0x04080100, 0, IPR_DEFAULT_LOG_LEVEL,
  313. "3109: IOA timed out a device command"},
  314. {0x04088000, 0, 0,
  315. "3120: SCSI bus is not operational"},
  316. {0x04088100, 0, IPR_DEFAULT_LOG_LEVEL,
  317. "4100: Hard device bus fabric error"},
  318. {0x04100100, 0, IPR_DEFAULT_LOG_LEVEL,
  319. "310C: Logical block guard error detected by the device"},
  320. {0x04100300, 0, IPR_DEFAULT_LOG_LEVEL,
  321. "310C: Logical block reference tag error detected by the device"},
  322. {0x04108300, 1, IPR_DEFAULT_LOG_LEVEL,
  323. "4170: Scatter list tag / sequence number error"},
  324. {0x04109000, 1, IPR_DEFAULT_LOG_LEVEL,
  325. "8150: Logical block CRC error on IOA to Host transfer"},
  326. {0x04109200, 1, IPR_DEFAULT_LOG_LEVEL,
  327. "4170: Logical block sequence number error on IOA to Host transfer"},
  328. {0x0410A000, 0, IPR_DEFAULT_LOG_LEVEL,
  329. "310D: Logical block reference tag error detected by the IOA"},
  330. {0x0410A100, 0, IPR_DEFAULT_LOG_LEVEL,
  331. "310D: Logical block guard error detected by the IOA"},
  332. {0x04118000, 0, IPR_DEFAULT_LOG_LEVEL,
  333. "9000: IOA reserved area data check"},
  334. {0x04118100, 0, IPR_DEFAULT_LOG_LEVEL,
  335. "9001: IOA reserved area invalid data pattern"},
  336. {0x04118200, 0, IPR_DEFAULT_LOG_LEVEL,
  337. "9002: IOA reserved area LRC error"},
  338. {0x04118300, 1, IPR_DEFAULT_LOG_LEVEL,
  339. "Hardware Error, IOA metadata access error"},
  340. {0x04320000, 0, IPR_DEFAULT_LOG_LEVEL,
  341. "102E: Out of alternate sectors for disk storage"},
  342. {0x04330000, 1, IPR_DEFAULT_LOG_LEVEL,
  343. "FFF4: Data transfer underlength error"},
  344. {0x04338000, 1, IPR_DEFAULT_LOG_LEVEL,
  345. "FFF4: Data transfer overlength error"},
  346. {0x043E0100, 0, IPR_DEFAULT_LOG_LEVEL,
  347. "3400: Logical unit failure"},
  348. {0x04408500, 0, IPR_DEFAULT_LOG_LEVEL,
  349. "FFF4: Device microcode is corrupt"},
  350. {0x04418000, 1, IPR_DEFAULT_LOG_LEVEL,
  351. "8150: PCI bus error"},
  352. {0x04430000, 1, 0,
  353. "Unsupported device bus message received"},
  354. {0x04440000, 1, IPR_DEFAULT_LOG_LEVEL,
  355. "FFF4: Disk device problem"},
  356. {0x04448200, 1, IPR_DEFAULT_LOG_LEVEL,
  357. "8150: Permanent IOA failure"},
  358. {0x04448300, 0, IPR_DEFAULT_LOG_LEVEL,
  359. "3010: Disk device returned wrong response to IOA"},
  360. {0x04448400, 0, IPR_DEFAULT_LOG_LEVEL,
  361. "8151: IOA microcode error"},
  362. {0x04448500, 0, 0,
  363. "Device bus status error"},
  364. {0x04448600, 0, IPR_DEFAULT_LOG_LEVEL,
  365. "8157: IOA error requiring IOA reset to recover"},
  366. {0x04448700, 0, 0,
  367. "ATA device status error"},
  368. {0x04490000, 0, 0,
  369. "Message reject received from the device"},
  370. {0x04449200, 0, IPR_DEFAULT_LOG_LEVEL,
  371. "8008: A permanent cache battery pack failure occurred"},
  372. {0x0444A000, 0, IPR_DEFAULT_LOG_LEVEL,
  373. "9090: Disk unit has been modified after the last known status"},
  374. {0x0444A200, 0, IPR_DEFAULT_LOG_LEVEL,
  375. "9081: IOA detected device error"},
  376. {0x0444A300, 0, IPR_DEFAULT_LOG_LEVEL,
  377. "9082: IOA detected device error"},
  378. {0x044A0000, 1, IPR_DEFAULT_LOG_LEVEL,
  379. "3110: Device bus error, message or command phase"},
  380. {0x044A8000, 1, IPR_DEFAULT_LOG_LEVEL,
  381. "3110: SAS Command / Task Management Function failed"},
  382. {0x04670400, 0, IPR_DEFAULT_LOG_LEVEL,
  383. "9091: Incorrect hardware configuration change has been detected"},
  384. {0x04678000, 0, IPR_DEFAULT_LOG_LEVEL,
  385. "9073: Invalid multi-adapter configuration"},
  386. {0x04678100, 0, IPR_DEFAULT_LOG_LEVEL,
  387. "4010: Incorrect connection between cascaded expanders"},
  388. {0x04678200, 0, IPR_DEFAULT_LOG_LEVEL,
  389. "4020: Connections exceed IOA design limits"},
  390. {0x04678300, 0, IPR_DEFAULT_LOG_LEVEL,
  391. "4030: Incorrect multipath connection"},
  392. {0x04679000, 0, IPR_DEFAULT_LOG_LEVEL,
  393. "4110: Unsupported enclosure function"},
  394. {0x04679800, 0, IPR_DEFAULT_LOG_LEVEL,
  395. "4120: SAS cable VPD cannot be read"},
  396. {0x046E0000, 0, IPR_DEFAULT_LOG_LEVEL,
  397. "FFF4: Command to logical unit failed"},
  398. {0x05240000, 1, 0,
  399. "Illegal request, invalid request type or request packet"},
  400. {0x05250000, 0, 0,
  401. "Illegal request, invalid resource handle"},
  402. {0x05258000, 0, 0,
  403. "Illegal request, commands not allowed to this device"},
  404. {0x05258100, 0, 0,
  405. "Illegal request, command not allowed to a secondary adapter"},
  406. {0x05258200, 0, 0,
  407. "Illegal request, command not allowed to a non-optimized resource"},
  408. {0x05260000, 0, 0,
  409. "Illegal request, invalid field in parameter list"},
  410. {0x05260100, 0, 0,
  411. "Illegal request, parameter not supported"},
  412. {0x05260200, 0, 0,
  413. "Illegal request, parameter value invalid"},
  414. {0x052C0000, 0, 0,
  415. "Illegal request, command sequence error"},
  416. {0x052C8000, 1, 0,
  417. "Illegal request, dual adapter support not enabled"},
  418. {0x052C8100, 1, 0,
  419. "Illegal request, another cable connector was physically disabled"},
  420. {0x054E8000, 1, 0,
  421. "Illegal request, inconsistent group id/group count"},
  422. {0x06040500, 0, IPR_DEFAULT_LOG_LEVEL,
  423. "9031: Array protection temporarily suspended, protection resuming"},
  424. {0x06040600, 0, IPR_DEFAULT_LOG_LEVEL,
  425. "9040: Array protection temporarily suspended, protection resuming"},
  426. {0x060B0100, 0, IPR_DEFAULT_LOG_LEVEL,
  427. "4080: IOA exceeded maximum operating temperature"},
  428. {0x060B8000, 0, IPR_DEFAULT_LOG_LEVEL,
  429. "4085: Service required"},
  430. {0x060B8100, 0, IPR_DEFAULT_LOG_LEVEL,
  431. "4086: SAS Adapter Hardware Configuration Error"},
  432. {0x06288000, 0, IPR_DEFAULT_LOG_LEVEL,
  433. "3140: Device bus not ready to ready transition"},
  434. {0x06290000, 0, IPR_DEFAULT_LOG_LEVEL,
  435. "FFFB: SCSI bus was reset"},
  436. {0x06290500, 0, 0,
  437. "FFFE: SCSI bus transition to single ended"},
  438. {0x06290600, 0, 0,
  439. "FFFE: SCSI bus transition to LVD"},
  440. {0x06298000, 0, IPR_DEFAULT_LOG_LEVEL,
  441. "FFFB: SCSI bus was reset by another initiator"},
  442. {0x063F0300, 0, IPR_DEFAULT_LOG_LEVEL,
  443. "3029: A device replacement has occurred"},
  444. {0x063F8300, 0, IPR_DEFAULT_LOG_LEVEL,
  445. "4102: Device bus fabric performance degradation"},
  446. {0x064C8000, 0, IPR_DEFAULT_LOG_LEVEL,
  447. "9051: IOA cache data exists for a missing or failed device"},
  448. {0x064C8100, 0, IPR_DEFAULT_LOG_LEVEL,
  449. "9055: Auxiliary cache IOA contains cache data needed by the primary IOA"},
  450. {0x06670100, 0, IPR_DEFAULT_LOG_LEVEL,
  451. "9025: Disk unit is not supported at its physical location"},
  452. {0x06670600, 0, IPR_DEFAULT_LOG_LEVEL,
  453. "3020: IOA detected a SCSI bus configuration error"},
  454. {0x06678000, 0, IPR_DEFAULT_LOG_LEVEL,
  455. "3150: SCSI bus configuration error"},
  456. {0x06678100, 0, IPR_DEFAULT_LOG_LEVEL,
  457. "9074: Asymmetric advanced function disk configuration"},
  458. {0x06678300, 0, IPR_DEFAULT_LOG_LEVEL,
  459. "4040: Incomplete multipath connection between IOA and enclosure"},
  460. {0x06678400, 0, IPR_DEFAULT_LOG_LEVEL,
  461. "4041: Incomplete multipath connection between enclosure and device"},
  462. {0x06678500, 0, IPR_DEFAULT_LOG_LEVEL,
  463. "9075: Incomplete multipath connection between IOA and remote IOA"},
  464. {0x06678600, 0, IPR_DEFAULT_LOG_LEVEL,
  465. "9076: Configuration error, missing remote IOA"},
  466. {0x06679100, 0, IPR_DEFAULT_LOG_LEVEL,
  467. "4050: Enclosure does not support a required multipath function"},
  468. {0x06679800, 0, IPR_DEFAULT_LOG_LEVEL,
  469. "4121: Configuration error, required cable is missing"},
  470. {0x06679900, 0, IPR_DEFAULT_LOG_LEVEL,
  471. "4122: Cable is not plugged into the correct location on remote IOA"},
  472. {0x06679A00, 0, IPR_DEFAULT_LOG_LEVEL,
  473. "4123: Configuration error, invalid cable vital product data"},
  474. {0x06679B00, 0, IPR_DEFAULT_LOG_LEVEL,
  475. "4124: Configuration error, both cable ends are plugged into the same IOA"},
  476. {0x06690000, 0, IPR_DEFAULT_LOG_LEVEL,
  477. "4070: Logically bad block written on device"},
  478. {0x06690200, 0, IPR_DEFAULT_LOG_LEVEL,
  479. "9041: Array protection temporarily suspended"},
  480. {0x06698200, 0, IPR_DEFAULT_LOG_LEVEL,
  481. "9042: Corrupt array parity detected on specified device"},
  482. {0x066B0200, 0, IPR_DEFAULT_LOG_LEVEL,
  483. "9030: Array no longer protected due to missing or failed disk unit"},
  484. {0x066B8000, 0, IPR_DEFAULT_LOG_LEVEL,
  485. "9071: Link operational transition"},
  486. {0x066B8100, 0, IPR_DEFAULT_LOG_LEVEL,
  487. "9072: Link not operational transition"},
  488. {0x066B8200, 0, IPR_DEFAULT_LOG_LEVEL,
  489. "9032: Array exposed but still protected"},
  490. {0x066B8300, 0, IPR_DEBUG_LOG_LEVEL,
  491. "70DD: Device forced failed by disrupt device command"},
  492. {0x066B9100, 0, IPR_DEFAULT_LOG_LEVEL,
  493. "4061: Multipath redundancy level got better"},
  494. {0x066B9200, 0, IPR_DEFAULT_LOG_LEVEL,
  495. "4060: Multipath redundancy level got worse"},
  496. {0x06808100, 0, IPR_DEBUG_LOG_LEVEL,
  497. "9083: Device raw mode enabled"},
  498. {0x06808200, 0, IPR_DEBUG_LOG_LEVEL,
  499. "9084: Device raw mode disabled"},
  500. {0x07270000, 0, 0,
  501. "Failure due to other device"},
  502. {0x07278000, 0, IPR_DEFAULT_LOG_LEVEL,
  503. "9008: IOA does not support functions expected by devices"},
  504. {0x07278100, 0, IPR_DEFAULT_LOG_LEVEL,
  505. "9010: Cache data associated with attached devices cannot be found"},
  506. {0x07278200, 0, IPR_DEFAULT_LOG_LEVEL,
  507. "9011: Cache data belongs to devices other than those attached"},
  508. {0x07278400, 0, IPR_DEFAULT_LOG_LEVEL,
  509. "9020: Array missing 2 or more devices with only 1 device present"},
  510. {0x07278500, 0, IPR_DEFAULT_LOG_LEVEL,
  511. "9021: Array missing 2 or more devices with 2 or more devices present"},
  512. {0x07278600, 0, IPR_DEFAULT_LOG_LEVEL,
  513. "9022: Exposed array is missing a required device"},
  514. {0x07278700, 0, IPR_DEFAULT_LOG_LEVEL,
  515. "9023: Array member(s) not at required physical locations"},
  516. {0x07278800, 0, IPR_DEFAULT_LOG_LEVEL,
  517. "9024: Array not functional due to present hardware configuration"},
  518. {0x07278900, 0, IPR_DEFAULT_LOG_LEVEL,
  519. "9026: Array not functional due to present hardware configuration"},
  520. {0x07278A00, 0, IPR_DEFAULT_LOG_LEVEL,
  521. "9027: Array is missing a device and parity is out of sync"},
  522. {0x07278B00, 0, IPR_DEFAULT_LOG_LEVEL,
  523. "9028: Maximum number of arrays already exist"},
  524. {0x07278C00, 0, IPR_DEFAULT_LOG_LEVEL,
  525. "9050: Required cache data cannot be located for a disk unit"},
  526. {0x07278D00, 0, IPR_DEFAULT_LOG_LEVEL,
  527. "9052: Cache data exists for a device that has been modified"},
  528. {0x07278F00, 0, IPR_DEFAULT_LOG_LEVEL,
  529. "9054: IOA resources not available due to previous problems"},
  530. {0x07279100, 0, IPR_DEFAULT_LOG_LEVEL,
  531. "9092: Disk unit requires initialization before use"},
  532. {0x07279200, 0, IPR_DEFAULT_LOG_LEVEL,
  533. "9029: Incorrect hardware configuration change has been detected"},
  534. {0x07279600, 0, IPR_DEFAULT_LOG_LEVEL,
  535. "9060: One or more disk pairs are missing from an array"},
  536. {0x07279700, 0, IPR_DEFAULT_LOG_LEVEL,
  537. "9061: One or more disks are missing from an array"},
  538. {0x07279800, 0, IPR_DEFAULT_LOG_LEVEL,
  539. "9062: One or more disks are missing from an array"},
  540. {0x07279900, 0, IPR_DEFAULT_LOG_LEVEL,
  541. "9063: Maximum number of functional arrays has been exceeded"},
  542. {0x07279A00, 0, 0,
  543. "Data protect, other volume set problem"},
  544. {0x0B260000, 0, 0,
  545. "Aborted command, invalid descriptor"},
  546. {0x0B3F9000, 0, 0,
  547. "Target operating conditions have changed, dual adapter takeover"},
  548. {0x0B530200, 0, 0,
  549. "Aborted command, medium removal prevented"},
  550. {0x0B5A0000, 0, 0,
  551. "Command terminated by host"},
  552. {0x0B5B8000, 0, 0,
  553. "Aborted command, command terminated by host"}
  554. };
  555. static const struct ipr_ses_table_entry ipr_ses_table[] = {
  556. { "2104-DL1 ", "XXXXXXXXXXXXXXXX", 80 },
  557. { "2104-TL1 ", "XXXXXXXXXXXXXXXX", 80 },
  558. { "HSBP07M P U2SCSI", "XXXXXXXXXXXXXXXX", 80 }, /* Hidive 7 slot */
  559. { "HSBP05M P U2SCSI", "XXXXXXXXXXXXXXXX", 80 }, /* Hidive 5 slot */
  560. { "HSBP05M S U2SCSI", "XXXXXXXXXXXXXXXX", 80 }, /* Bowtie */
  561. { "HSBP06E ASU2SCSI", "XXXXXXXXXXXXXXXX", 80 }, /* MartinFenning */
  562. { "2104-DU3 ", "XXXXXXXXXXXXXXXX", 160 },
  563. { "2104-TU3 ", "XXXXXXXXXXXXXXXX", 160 },
  564. { "HSBP04C RSU2SCSI", "XXXXXXX*XXXXXXXX", 160 },
  565. { "HSBP06E RSU2SCSI", "XXXXXXX*XXXXXXXX", 160 },
  566. { "St V1S2 ", "XXXXXXXXXXXXXXXX", 160 },
  567. { "HSBPD4M PU3SCSI", "XXXXXXX*XXXXXXXX", 160 },
  568. { "VSBPD1H U3SCSI", "XXXXXXX*XXXXXXXX", 160 }
  569. };
  570. /*
  571. * Function Prototypes
  572. */
  573. static int ipr_reset_alert(struct ipr_cmnd *);
  574. static void ipr_process_ccn(struct ipr_cmnd *);
  575. static void ipr_process_error(struct ipr_cmnd *);
  576. static void ipr_reset_ioa_job(struct ipr_cmnd *);
  577. static void ipr_initiate_ioa_reset(struct ipr_ioa_cfg *,
  578. enum ipr_shutdown_type);
  579. #ifdef CONFIG_SCSI_IPR_TRACE
  580. /**
  581. * ipr_trc_hook - Add a trace entry to the driver trace
  582. * @ipr_cmd: ipr command struct
  583. * @type: trace type
  584. * @add_data: additional data
  585. *
  586. * Return value:
  587. * none
  588. **/
  589. static void ipr_trc_hook(struct ipr_cmnd *ipr_cmd,
  590. u8 type, u32 add_data)
  591. {
  592. struct ipr_trace_entry *trace_entry;
  593. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  594. unsigned int trace_index;
  595. trace_index = atomic_add_return(1, &ioa_cfg->trace_index) & IPR_TRACE_INDEX_MASK;
  596. trace_entry = &ioa_cfg->trace[trace_index];
  597. trace_entry->time = jiffies;
  598. trace_entry->op_code = ipr_cmd->ioarcb.cmd_pkt.cdb[0];
  599. trace_entry->type = type;
  600. if (ipr_cmd->ioa_cfg->sis64)
  601. trace_entry->ata_op_code = ipr_cmd->i.ata_ioadl.regs.command;
  602. else
  603. trace_entry->ata_op_code = ipr_cmd->ioarcb.u.add_data.u.regs.command;
  604. trace_entry->cmd_index = ipr_cmd->cmd_index & 0xff;
  605. trace_entry->res_handle = ipr_cmd->ioarcb.res_handle;
  606. trace_entry->u.add_data = add_data;
  607. wmb();
  608. }
  609. #else
  610. #define ipr_trc_hook(ipr_cmd, type, add_data) do { } while (0)
  611. #endif
  612. /**
  613. * ipr_lock_and_done - Acquire lock and complete command
  614. * @ipr_cmd: ipr command struct
  615. *
  616. * Return value:
  617. * none
  618. **/
  619. static void ipr_lock_and_done(struct ipr_cmnd *ipr_cmd)
  620. {
  621. unsigned long lock_flags;
  622. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  623. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  624. ipr_cmd->done(ipr_cmd);
  625. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  626. }
  627. /**
  628. * ipr_reinit_ipr_cmnd - Re-initialize an IPR Cmnd block for reuse
  629. * @ipr_cmd: ipr command struct
  630. *
  631. * Return value:
  632. * none
  633. **/
  634. static void ipr_reinit_ipr_cmnd(struct ipr_cmnd *ipr_cmd)
  635. {
  636. struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
  637. struct ipr_ioasa *ioasa = &ipr_cmd->s.ioasa;
  638. struct ipr_ioasa64 *ioasa64 = &ipr_cmd->s.ioasa64;
  639. dma_addr_t dma_addr = ipr_cmd->dma_addr;
  640. int hrrq_id;
  641. hrrq_id = ioarcb->cmd_pkt.hrrq_id;
  642. memset(&ioarcb->cmd_pkt, 0, sizeof(struct ipr_cmd_pkt));
  643. ioarcb->cmd_pkt.hrrq_id = hrrq_id;
  644. ioarcb->data_transfer_length = 0;
  645. ioarcb->read_data_transfer_length = 0;
  646. ioarcb->ioadl_len = 0;
  647. ioarcb->read_ioadl_len = 0;
  648. if (ipr_cmd->ioa_cfg->sis64) {
  649. ioarcb->u.sis64_addr_data.data_ioadl_addr =
  650. cpu_to_be64(dma_addr + offsetof(struct ipr_cmnd, i.ioadl64));
  651. ioasa64->u.gata.status = 0;
  652. } else {
  653. ioarcb->write_ioadl_addr =
  654. cpu_to_be32(dma_addr + offsetof(struct ipr_cmnd, i.ioadl));
  655. ioarcb->read_ioadl_addr = ioarcb->write_ioadl_addr;
  656. ioasa->u.gata.status = 0;
  657. }
  658. ioasa->hdr.ioasc = 0;
  659. ioasa->hdr.residual_data_len = 0;
  660. ipr_cmd->scsi_cmd = NULL;
  661. ipr_cmd->qc = NULL;
  662. ipr_cmd->sense_buffer[0] = 0;
  663. ipr_cmd->dma_use_sg = 0;
  664. }
  665. /**
  666. * ipr_init_ipr_cmnd - Initialize an IPR Cmnd block
  667. * @ipr_cmd: ipr command struct
  668. *
  669. * Return value:
  670. * none
  671. **/
  672. static void ipr_init_ipr_cmnd(struct ipr_cmnd *ipr_cmd,
  673. void (*fast_done) (struct ipr_cmnd *))
  674. {
  675. ipr_reinit_ipr_cmnd(ipr_cmd);
  676. ipr_cmd->u.scratch = 0;
  677. ipr_cmd->sibling = NULL;
  678. ipr_cmd->eh_comp = NULL;
  679. ipr_cmd->fast_done = fast_done;
  680. timer_setup(&ipr_cmd->timer, NULL, 0);
  681. }
  682. /**
  683. * __ipr_get_free_ipr_cmnd - Get a free IPR Cmnd block
  684. * @ioa_cfg: ioa config struct
  685. *
  686. * Return value:
  687. * pointer to ipr command struct
  688. **/
  689. static
  690. struct ipr_cmnd *__ipr_get_free_ipr_cmnd(struct ipr_hrr_queue *hrrq)
  691. {
  692. struct ipr_cmnd *ipr_cmd = NULL;
  693. if (likely(!list_empty(&hrrq->hrrq_free_q))) {
  694. ipr_cmd = list_entry(hrrq->hrrq_free_q.next,
  695. struct ipr_cmnd, queue);
  696. list_del(&ipr_cmd->queue);
  697. }
  698. return ipr_cmd;
  699. }
  700. /**
  701. * ipr_get_free_ipr_cmnd - Get a free IPR Cmnd block and initialize it
  702. * @ioa_cfg: ioa config struct
  703. *
  704. * Return value:
  705. * pointer to ipr command struct
  706. **/
  707. static
  708. struct ipr_cmnd *ipr_get_free_ipr_cmnd(struct ipr_ioa_cfg *ioa_cfg)
  709. {
  710. struct ipr_cmnd *ipr_cmd =
  711. __ipr_get_free_ipr_cmnd(&ioa_cfg->hrrq[IPR_INIT_HRRQ]);
  712. ipr_init_ipr_cmnd(ipr_cmd, ipr_lock_and_done);
  713. return ipr_cmd;
  714. }
  715. /**
  716. * ipr_mask_and_clear_interrupts - Mask all and clear specified interrupts
  717. * @ioa_cfg: ioa config struct
  718. * @clr_ints: interrupts to clear
  719. *
  720. * This function masks all interrupts on the adapter, then clears the
  721. * interrupts specified in the mask
  722. *
  723. * Return value:
  724. * none
  725. **/
  726. static void ipr_mask_and_clear_interrupts(struct ipr_ioa_cfg *ioa_cfg,
  727. u32 clr_ints)
  728. {
  729. volatile u32 int_reg;
  730. int i;
  731. /* Stop new interrupts */
  732. for (i = 0; i < ioa_cfg->hrrq_num; i++) {
  733. spin_lock(&ioa_cfg->hrrq[i]._lock);
  734. ioa_cfg->hrrq[i].allow_interrupts = 0;
  735. spin_unlock(&ioa_cfg->hrrq[i]._lock);
  736. }
  737. /* Set interrupt mask to stop all new interrupts */
  738. if (ioa_cfg->sis64)
  739. writeq(~0, ioa_cfg->regs.set_interrupt_mask_reg);
  740. else
  741. writel(~0, ioa_cfg->regs.set_interrupt_mask_reg);
  742. /* Clear any pending interrupts */
  743. if (ioa_cfg->sis64)
  744. writel(~0, ioa_cfg->regs.clr_interrupt_reg);
  745. writel(clr_ints, ioa_cfg->regs.clr_interrupt_reg32);
  746. int_reg = readl(ioa_cfg->regs.sense_interrupt_reg);
  747. }
  748. /**
  749. * ipr_save_pcix_cmd_reg - Save PCI-X command register
  750. * @ioa_cfg: ioa config struct
  751. *
  752. * Return value:
  753. * 0 on success / -EIO on failure
  754. **/
  755. static int ipr_save_pcix_cmd_reg(struct ipr_ioa_cfg *ioa_cfg)
  756. {
  757. int pcix_cmd_reg = pci_find_capability(ioa_cfg->pdev, PCI_CAP_ID_PCIX);
  758. if (pcix_cmd_reg == 0)
  759. return 0;
  760. if (pci_read_config_word(ioa_cfg->pdev, pcix_cmd_reg + PCI_X_CMD,
  761. &ioa_cfg->saved_pcix_cmd_reg) != PCIBIOS_SUCCESSFUL) {
  762. dev_err(&ioa_cfg->pdev->dev, "Failed to save PCI-X command register\n");
  763. return -EIO;
  764. }
  765. ioa_cfg->saved_pcix_cmd_reg |= PCI_X_CMD_DPERR_E | PCI_X_CMD_ERO;
  766. return 0;
  767. }
  768. /**
  769. * ipr_set_pcix_cmd_reg - Setup PCI-X command register
  770. * @ioa_cfg: ioa config struct
  771. *
  772. * Return value:
  773. * 0 on success / -EIO on failure
  774. **/
  775. static int ipr_set_pcix_cmd_reg(struct ipr_ioa_cfg *ioa_cfg)
  776. {
  777. int pcix_cmd_reg = pci_find_capability(ioa_cfg->pdev, PCI_CAP_ID_PCIX);
  778. if (pcix_cmd_reg) {
  779. if (pci_write_config_word(ioa_cfg->pdev, pcix_cmd_reg + PCI_X_CMD,
  780. ioa_cfg->saved_pcix_cmd_reg) != PCIBIOS_SUCCESSFUL) {
  781. dev_err(&ioa_cfg->pdev->dev, "Failed to setup PCI-X command register\n");
  782. return -EIO;
  783. }
  784. }
  785. return 0;
  786. }
  787. /**
  788. * __ipr_sata_eh_done - done function for aborted SATA commands
  789. * @ipr_cmd: ipr command struct
  790. *
  791. * This function is invoked for ops generated to SATA
  792. * devices which are being aborted.
  793. *
  794. * Return value:
  795. * none
  796. **/
  797. static void __ipr_sata_eh_done(struct ipr_cmnd *ipr_cmd)
  798. {
  799. struct ata_queued_cmd *qc = ipr_cmd->qc;
  800. struct ipr_sata_port *sata_port = qc->ap->private_data;
  801. qc->err_mask |= AC_ERR_OTHER;
  802. sata_port->ioasa.status |= ATA_BUSY;
  803. ata_qc_complete(qc);
  804. if (ipr_cmd->eh_comp)
  805. complete(ipr_cmd->eh_comp);
  806. list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_free_q);
  807. }
  808. /**
  809. * ipr_sata_eh_done - done function for aborted SATA commands
  810. * @ipr_cmd: ipr command struct
  811. *
  812. * This function is invoked for ops generated to SATA
  813. * devices which are being aborted.
  814. *
  815. * Return value:
  816. * none
  817. **/
  818. static void ipr_sata_eh_done(struct ipr_cmnd *ipr_cmd)
  819. {
  820. struct ipr_hrr_queue *hrrq = ipr_cmd->hrrq;
  821. unsigned long hrrq_flags;
  822. spin_lock_irqsave(&hrrq->_lock, hrrq_flags);
  823. __ipr_sata_eh_done(ipr_cmd);
  824. spin_unlock_irqrestore(&hrrq->_lock, hrrq_flags);
  825. }
  826. /**
  827. * __ipr_scsi_eh_done - mid-layer done function for aborted ops
  828. * @ipr_cmd: ipr command struct
  829. *
  830. * This function is invoked by the interrupt handler for
  831. * ops generated by the SCSI mid-layer which are being aborted.
  832. *
  833. * Return value:
  834. * none
  835. **/
  836. static void __ipr_scsi_eh_done(struct ipr_cmnd *ipr_cmd)
  837. {
  838. struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
  839. scsi_cmd->result |= (DID_ERROR << 16);
  840. scsi_dma_unmap(ipr_cmd->scsi_cmd);
  841. scsi_cmd->scsi_done(scsi_cmd);
  842. if (ipr_cmd->eh_comp)
  843. complete(ipr_cmd->eh_comp);
  844. list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_free_q);
  845. }
  846. /**
  847. * ipr_scsi_eh_done - mid-layer done function for aborted ops
  848. * @ipr_cmd: ipr command struct
  849. *
  850. * This function is invoked by the interrupt handler for
  851. * ops generated by the SCSI mid-layer which are being aborted.
  852. *
  853. * Return value:
  854. * none
  855. **/
  856. static void ipr_scsi_eh_done(struct ipr_cmnd *ipr_cmd)
  857. {
  858. unsigned long hrrq_flags;
  859. struct ipr_hrr_queue *hrrq = ipr_cmd->hrrq;
  860. spin_lock_irqsave(&hrrq->_lock, hrrq_flags);
  861. __ipr_scsi_eh_done(ipr_cmd);
  862. spin_unlock_irqrestore(&hrrq->_lock, hrrq_flags);
  863. }
  864. /**
  865. * ipr_fail_all_ops - Fails all outstanding ops.
  866. * @ioa_cfg: ioa config struct
  867. *
  868. * This function fails all outstanding ops.
  869. *
  870. * Return value:
  871. * none
  872. **/
  873. static void ipr_fail_all_ops(struct ipr_ioa_cfg *ioa_cfg)
  874. {
  875. struct ipr_cmnd *ipr_cmd, *temp;
  876. struct ipr_hrr_queue *hrrq;
  877. ENTER;
  878. for_each_hrrq(hrrq, ioa_cfg) {
  879. spin_lock(&hrrq->_lock);
  880. list_for_each_entry_safe(ipr_cmd,
  881. temp, &hrrq->hrrq_pending_q, queue) {
  882. list_del(&ipr_cmd->queue);
  883. ipr_cmd->s.ioasa.hdr.ioasc =
  884. cpu_to_be32(IPR_IOASC_IOA_WAS_RESET);
  885. ipr_cmd->s.ioasa.hdr.ilid =
  886. cpu_to_be32(IPR_DRIVER_ILID);
  887. if (ipr_cmd->scsi_cmd)
  888. ipr_cmd->done = __ipr_scsi_eh_done;
  889. else if (ipr_cmd->qc)
  890. ipr_cmd->done = __ipr_sata_eh_done;
  891. ipr_trc_hook(ipr_cmd, IPR_TRACE_FINISH,
  892. IPR_IOASC_IOA_WAS_RESET);
  893. del_timer(&ipr_cmd->timer);
  894. ipr_cmd->done(ipr_cmd);
  895. }
  896. spin_unlock(&hrrq->_lock);
  897. }
  898. LEAVE;
  899. }
  900. /**
  901. * ipr_send_command - Send driver initiated requests.
  902. * @ipr_cmd: ipr command struct
  903. *
  904. * This function sends a command to the adapter using the correct write call.
  905. * In the case of sis64, calculate the ioarcb size required. Then or in the
  906. * appropriate bits.
  907. *
  908. * Return value:
  909. * none
  910. **/
  911. static void ipr_send_command(struct ipr_cmnd *ipr_cmd)
  912. {
  913. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  914. dma_addr_t send_dma_addr = ipr_cmd->dma_addr;
  915. if (ioa_cfg->sis64) {
  916. /* The default size is 256 bytes */
  917. send_dma_addr |= 0x1;
  918. /* If the number of ioadls * size of ioadl > 128 bytes,
  919. then use a 512 byte ioarcb */
  920. if (ipr_cmd->dma_use_sg * sizeof(struct ipr_ioadl64_desc) > 128 )
  921. send_dma_addr |= 0x4;
  922. writeq(send_dma_addr, ioa_cfg->regs.ioarrin_reg);
  923. } else
  924. writel(send_dma_addr, ioa_cfg->regs.ioarrin_reg);
  925. }
  926. /**
  927. * ipr_do_req - Send driver initiated requests.
  928. * @ipr_cmd: ipr command struct
  929. * @done: done function
  930. * @timeout_func: timeout function
  931. * @timeout: timeout value
  932. *
  933. * This function sends the specified command to the adapter with the
  934. * timeout given. The done function is invoked on command completion.
  935. *
  936. * Return value:
  937. * none
  938. **/
  939. static void ipr_do_req(struct ipr_cmnd *ipr_cmd,
  940. void (*done) (struct ipr_cmnd *),
  941. void (*timeout_func) (struct timer_list *), u32 timeout)
  942. {
  943. list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_pending_q);
  944. ipr_cmd->done = done;
  945. ipr_cmd->timer.expires = jiffies + timeout;
  946. ipr_cmd->timer.function = timeout_func;
  947. add_timer(&ipr_cmd->timer);
  948. ipr_trc_hook(ipr_cmd, IPR_TRACE_START, 0);
  949. ipr_send_command(ipr_cmd);
  950. }
  951. /**
  952. * ipr_internal_cmd_done - Op done function for an internally generated op.
  953. * @ipr_cmd: ipr command struct
  954. *
  955. * This function is the op done function for an internally generated,
  956. * blocking op. It simply wakes the sleeping thread.
  957. *
  958. * Return value:
  959. * none
  960. **/
  961. static void ipr_internal_cmd_done(struct ipr_cmnd *ipr_cmd)
  962. {
  963. if (ipr_cmd->sibling)
  964. ipr_cmd->sibling = NULL;
  965. else
  966. complete(&ipr_cmd->completion);
  967. }
  968. /**
  969. * ipr_init_ioadl - initialize the ioadl for the correct SIS type
  970. * @ipr_cmd: ipr command struct
  971. * @dma_addr: dma address
  972. * @len: transfer length
  973. * @flags: ioadl flag value
  974. *
  975. * This function initializes an ioadl in the case where there is only a single
  976. * descriptor.
  977. *
  978. * Return value:
  979. * nothing
  980. **/
  981. static void ipr_init_ioadl(struct ipr_cmnd *ipr_cmd, dma_addr_t dma_addr,
  982. u32 len, int flags)
  983. {
  984. struct ipr_ioadl_desc *ioadl = ipr_cmd->i.ioadl;
  985. struct ipr_ioadl64_desc *ioadl64 = ipr_cmd->i.ioadl64;
  986. ipr_cmd->dma_use_sg = 1;
  987. if (ipr_cmd->ioa_cfg->sis64) {
  988. ioadl64->flags = cpu_to_be32(flags);
  989. ioadl64->data_len = cpu_to_be32(len);
  990. ioadl64->address = cpu_to_be64(dma_addr);
  991. ipr_cmd->ioarcb.ioadl_len =
  992. cpu_to_be32(sizeof(struct ipr_ioadl64_desc));
  993. ipr_cmd->ioarcb.data_transfer_length = cpu_to_be32(len);
  994. } else {
  995. ioadl->flags_and_data_len = cpu_to_be32(flags | len);
  996. ioadl->address = cpu_to_be32(dma_addr);
  997. if (flags == IPR_IOADL_FLAGS_READ_LAST) {
  998. ipr_cmd->ioarcb.read_ioadl_len =
  999. cpu_to_be32(sizeof(struct ipr_ioadl_desc));
  1000. ipr_cmd->ioarcb.read_data_transfer_length = cpu_to_be32(len);
  1001. } else {
  1002. ipr_cmd->ioarcb.ioadl_len =
  1003. cpu_to_be32(sizeof(struct ipr_ioadl_desc));
  1004. ipr_cmd->ioarcb.data_transfer_length = cpu_to_be32(len);
  1005. }
  1006. }
  1007. }
  1008. /**
  1009. * ipr_send_blocking_cmd - Send command and sleep on its completion.
  1010. * @ipr_cmd: ipr command struct
  1011. * @timeout_func: function to invoke if command times out
  1012. * @timeout: timeout
  1013. *
  1014. * Return value:
  1015. * none
  1016. **/
  1017. static void ipr_send_blocking_cmd(struct ipr_cmnd *ipr_cmd,
  1018. void (*timeout_func) (struct timer_list *),
  1019. u32 timeout)
  1020. {
  1021. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  1022. init_completion(&ipr_cmd->completion);
  1023. ipr_do_req(ipr_cmd, ipr_internal_cmd_done, timeout_func, timeout);
  1024. spin_unlock_irq(ioa_cfg->host->host_lock);
  1025. wait_for_completion(&ipr_cmd->completion);
  1026. spin_lock_irq(ioa_cfg->host->host_lock);
  1027. }
  1028. static int ipr_get_hrrq_index(struct ipr_ioa_cfg *ioa_cfg)
  1029. {
  1030. unsigned int hrrq;
  1031. if (ioa_cfg->hrrq_num == 1)
  1032. hrrq = 0;
  1033. else {
  1034. hrrq = atomic_add_return(1, &ioa_cfg->hrrq_index);
  1035. hrrq = (hrrq % (ioa_cfg->hrrq_num - 1)) + 1;
  1036. }
  1037. return hrrq;
  1038. }
  1039. /**
  1040. * ipr_send_hcam - Send an HCAM to the adapter.
  1041. * @ioa_cfg: ioa config struct
  1042. * @type: HCAM type
  1043. * @hostrcb: hostrcb struct
  1044. *
  1045. * This function will send a Host Controlled Async command to the adapter.
  1046. * If HCAMs are currently not allowed to be issued to the adapter, it will
  1047. * place the hostrcb on the free queue.
  1048. *
  1049. * Return value:
  1050. * none
  1051. **/
  1052. static void ipr_send_hcam(struct ipr_ioa_cfg *ioa_cfg, u8 type,
  1053. struct ipr_hostrcb *hostrcb)
  1054. {
  1055. struct ipr_cmnd *ipr_cmd;
  1056. struct ipr_ioarcb *ioarcb;
  1057. if (ioa_cfg->hrrq[IPR_INIT_HRRQ].allow_cmds) {
  1058. ipr_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
  1059. list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_pending_q);
  1060. list_add_tail(&hostrcb->queue, &ioa_cfg->hostrcb_pending_q);
  1061. ipr_cmd->u.hostrcb = hostrcb;
  1062. ioarcb = &ipr_cmd->ioarcb;
  1063. ioarcb->res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
  1064. ioarcb->cmd_pkt.request_type = IPR_RQTYPE_HCAM;
  1065. ioarcb->cmd_pkt.cdb[0] = IPR_HOST_CONTROLLED_ASYNC;
  1066. ioarcb->cmd_pkt.cdb[1] = type;
  1067. ioarcb->cmd_pkt.cdb[7] = (sizeof(hostrcb->hcam) >> 8) & 0xff;
  1068. ioarcb->cmd_pkt.cdb[8] = sizeof(hostrcb->hcam) & 0xff;
  1069. ipr_init_ioadl(ipr_cmd, hostrcb->hostrcb_dma,
  1070. sizeof(hostrcb->hcam), IPR_IOADL_FLAGS_READ_LAST);
  1071. if (type == IPR_HCAM_CDB_OP_CODE_CONFIG_CHANGE)
  1072. ipr_cmd->done = ipr_process_ccn;
  1073. else
  1074. ipr_cmd->done = ipr_process_error;
  1075. ipr_trc_hook(ipr_cmd, IPR_TRACE_START, IPR_IOA_RES_ADDR);
  1076. ipr_send_command(ipr_cmd);
  1077. } else {
  1078. list_add_tail(&hostrcb->queue, &ioa_cfg->hostrcb_free_q);
  1079. }
  1080. }
  1081. /**
  1082. * ipr_update_ata_class - Update the ata class in the resource entry
  1083. * @res: resource entry struct
  1084. * @proto: cfgte device bus protocol value
  1085. *
  1086. * Return value:
  1087. * none
  1088. **/
  1089. static void ipr_update_ata_class(struct ipr_resource_entry *res, unsigned int proto)
  1090. {
  1091. switch (proto) {
  1092. case IPR_PROTO_SATA:
  1093. case IPR_PROTO_SAS_STP:
  1094. res->ata_class = ATA_DEV_ATA;
  1095. break;
  1096. case IPR_PROTO_SATA_ATAPI:
  1097. case IPR_PROTO_SAS_STP_ATAPI:
  1098. res->ata_class = ATA_DEV_ATAPI;
  1099. break;
  1100. default:
  1101. res->ata_class = ATA_DEV_UNKNOWN;
  1102. break;
  1103. };
  1104. }
  1105. /**
  1106. * ipr_init_res_entry - Initialize a resource entry struct.
  1107. * @res: resource entry struct
  1108. * @cfgtew: config table entry wrapper struct
  1109. *
  1110. * Return value:
  1111. * none
  1112. **/
  1113. static void ipr_init_res_entry(struct ipr_resource_entry *res,
  1114. struct ipr_config_table_entry_wrapper *cfgtew)
  1115. {
  1116. int found = 0;
  1117. unsigned int proto;
  1118. struct ipr_ioa_cfg *ioa_cfg = res->ioa_cfg;
  1119. struct ipr_resource_entry *gscsi_res = NULL;
  1120. res->needs_sync_complete = 0;
  1121. res->in_erp = 0;
  1122. res->add_to_ml = 0;
  1123. res->del_from_ml = 0;
  1124. res->resetting_device = 0;
  1125. res->reset_occurred = 0;
  1126. res->sdev = NULL;
  1127. res->sata_port = NULL;
  1128. if (ioa_cfg->sis64) {
  1129. proto = cfgtew->u.cfgte64->proto;
  1130. res->flags = be16_to_cpu(cfgtew->u.cfgte64->flags);
  1131. res->res_flags = be16_to_cpu(cfgtew->u.cfgte64->res_flags);
  1132. res->qmodel = IPR_QUEUEING_MODEL64(res);
  1133. res->type = cfgtew->u.cfgte64->res_type;
  1134. memcpy(res->res_path, &cfgtew->u.cfgte64->res_path,
  1135. sizeof(res->res_path));
  1136. res->bus = 0;
  1137. memcpy(&res->dev_lun.scsi_lun, &cfgtew->u.cfgte64->lun,
  1138. sizeof(res->dev_lun.scsi_lun));
  1139. res->lun = scsilun_to_int(&res->dev_lun);
  1140. if (res->type == IPR_RES_TYPE_GENERIC_SCSI) {
  1141. list_for_each_entry(gscsi_res, &ioa_cfg->used_res_q, queue) {
  1142. if (gscsi_res->dev_id == cfgtew->u.cfgte64->dev_id) {
  1143. found = 1;
  1144. res->target = gscsi_res->target;
  1145. break;
  1146. }
  1147. }
  1148. if (!found) {
  1149. res->target = find_first_zero_bit(ioa_cfg->target_ids,
  1150. ioa_cfg->max_devs_supported);
  1151. set_bit(res->target, ioa_cfg->target_ids);
  1152. }
  1153. } else if (res->type == IPR_RES_TYPE_IOAFP) {
  1154. res->bus = IPR_IOAFP_VIRTUAL_BUS;
  1155. res->target = 0;
  1156. } else if (res->type == IPR_RES_TYPE_ARRAY) {
  1157. res->bus = IPR_ARRAY_VIRTUAL_BUS;
  1158. res->target = find_first_zero_bit(ioa_cfg->array_ids,
  1159. ioa_cfg->max_devs_supported);
  1160. set_bit(res->target, ioa_cfg->array_ids);
  1161. } else if (res->type == IPR_RES_TYPE_VOLUME_SET) {
  1162. res->bus = IPR_VSET_VIRTUAL_BUS;
  1163. res->target = find_first_zero_bit(ioa_cfg->vset_ids,
  1164. ioa_cfg->max_devs_supported);
  1165. set_bit(res->target, ioa_cfg->vset_ids);
  1166. } else {
  1167. res->target = find_first_zero_bit(ioa_cfg->target_ids,
  1168. ioa_cfg->max_devs_supported);
  1169. set_bit(res->target, ioa_cfg->target_ids);
  1170. }
  1171. } else {
  1172. proto = cfgtew->u.cfgte->proto;
  1173. res->qmodel = IPR_QUEUEING_MODEL(res);
  1174. res->flags = cfgtew->u.cfgte->flags;
  1175. if (res->flags & IPR_IS_IOA_RESOURCE)
  1176. res->type = IPR_RES_TYPE_IOAFP;
  1177. else
  1178. res->type = cfgtew->u.cfgte->rsvd_subtype & 0x0f;
  1179. res->bus = cfgtew->u.cfgte->res_addr.bus;
  1180. res->target = cfgtew->u.cfgte->res_addr.target;
  1181. res->lun = cfgtew->u.cfgte->res_addr.lun;
  1182. res->lun_wwn = get_unaligned_be64(cfgtew->u.cfgte->lun_wwn);
  1183. }
  1184. ipr_update_ata_class(res, proto);
  1185. }
  1186. /**
  1187. * ipr_is_same_device - Determine if two devices are the same.
  1188. * @res: resource entry struct
  1189. * @cfgtew: config table entry wrapper struct
  1190. *
  1191. * Return value:
  1192. * 1 if the devices are the same / 0 otherwise
  1193. **/
  1194. static int ipr_is_same_device(struct ipr_resource_entry *res,
  1195. struct ipr_config_table_entry_wrapper *cfgtew)
  1196. {
  1197. if (res->ioa_cfg->sis64) {
  1198. if (!memcmp(&res->dev_id, &cfgtew->u.cfgte64->dev_id,
  1199. sizeof(cfgtew->u.cfgte64->dev_id)) &&
  1200. !memcmp(&res->dev_lun.scsi_lun, &cfgtew->u.cfgte64->lun,
  1201. sizeof(cfgtew->u.cfgte64->lun))) {
  1202. return 1;
  1203. }
  1204. } else {
  1205. if (res->bus == cfgtew->u.cfgte->res_addr.bus &&
  1206. res->target == cfgtew->u.cfgte->res_addr.target &&
  1207. res->lun == cfgtew->u.cfgte->res_addr.lun)
  1208. return 1;
  1209. }
  1210. return 0;
  1211. }
  1212. /**
  1213. * __ipr_format_res_path - Format the resource path for printing.
  1214. * @res_path: resource path
  1215. * @buf: buffer
  1216. * @len: length of buffer provided
  1217. *
  1218. * Return value:
  1219. * pointer to buffer
  1220. **/
  1221. static char *__ipr_format_res_path(u8 *res_path, char *buffer, int len)
  1222. {
  1223. int i;
  1224. char *p = buffer;
  1225. *p = '\0';
  1226. p += snprintf(p, buffer + len - p, "%02X", res_path[0]);
  1227. for (i = 1; res_path[i] != 0xff && ((i * 3) < len); i++)
  1228. p += snprintf(p, buffer + len - p, "-%02X", res_path[i]);
  1229. return buffer;
  1230. }
  1231. /**
  1232. * ipr_format_res_path - Format the resource path for printing.
  1233. * @ioa_cfg: ioa config struct
  1234. * @res_path: resource path
  1235. * @buf: buffer
  1236. * @len: length of buffer provided
  1237. *
  1238. * Return value:
  1239. * pointer to buffer
  1240. **/
  1241. static char *ipr_format_res_path(struct ipr_ioa_cfg *ioa_cfg,
  1242. u8 *res_path, char *buffer, int len)
  1243. {
  1244. char *p = buffer;
  1245. *p = '\0';
  1246. p += snprintf(p, buffer + len - p, "%d/", ioa_cfg->host->host_no);
  1247. __ipr_format_res_path(res_path, p, len - (buffer - p));
  1248. return buffer;
  1249. }
  1250. /**
  1251. * ipr_update_res_entry - Update the resource entry.
  1252. * @res: resource entry struct
  1253. * @cfgtew: config table entry wrapper struct
  1254. *
  1255. * Return value:
  1256. * none
  1257. **/
  1258. static void ipr_update_res_entry(struct ipr_resource_entry *res,
  1259. struct ipr_config_table_entry_wrapper *cfgtew)
  1260. {
  1261. char buffer[IPR_MAX_RES_PATH_LENGTH];
  1262. unsigned int proto;
  1263. int new_path = 0;
  1264. if (res->ioa_cfg->sis64) {
  1265. res->flags = be16_to_cpu(cfgtew->u.cfgte64->flags);
  1266. res->res_flags = be16_to_cpu(cfgtew->u.cfgte64->res_flags);
  1267. res->type = cfgtew->u.cfgte64->res_type;
  1268. memcpy(&res->std_inq_data, &cfgtew->u.cfgte64->std_inq_data,
  1269. sizeof(struct ipr_std_inq_data));
  1270. res->qmodel = IPR_QUEUEING_MODEL64(res);
  1271. proto = cfgtew->u.cfgte64->proto;
  1272. res->res_handle = cfgtew->u.cfgte64->res_handle;
  1273. res->dev_id = cfgtew->u.cfgte64->dev_id;
  1274. memcpy(&res->dev_lun.scsi_lun, &cfgtew->u.cfgte64->lun,
  1275. sizeof(res->dev_lun.scsi_lun));
  1276. if (memcmp(res->res_path, &cfgtew->u.cfgte64->res_path,
  1277. sizeof(res->res_path))) {
  1278. memcpy(res->res_path, &cfgtew->u.cfgte64->res_path,
  1279. sizeof(res->res_path));
  1280. new_path = 1;
  1281. }
  1282. if (res->sdev && new_path)
  1283. sdev_printk(KERN_INFO, res->sdev, "Resource path: %s\n",
  1284. ipr_format_res_path(res->ioa_cfg,
  1285. res->res_path, buffer, sizeof(buffer)));
  1286. } else {
  1287. res->flags = cfgtew->u.cfgte->flags;
  1288. if (res->flags & IPR_IS_IOA_RESOURCE)
  1289. res->type = IPR_RES_TYPE_IOAFP;
  1290. else
  1291. res->type = cfgtew->u.cfgte->rsvd_subtype & 0x0f;
  1292. memcpy(&res->std_inq_data, &cfgtew->u.cfgte->std_inq_data,
  1293. sizeof(struct ipr_std_inq_data));
  1294. res->qmodel = IPR_QUEUEING_MODEL(res);
  1295. proto = cfgtew->u.cfgte->proto;
  1296. res->res_handle = cfgtew->u.cfgte->res_handle;
  1297. }
  1298. ipr_update_ata_class(res, proto);
  1299. }
  1300. /**
  1301. * ipr_clear_res_target - Clear the bit in the bit map representing the target
  1302. * for the resource.
  1303. * @res: resource entry struct
  1304. * @cfgtew: config table entry wrapper struct
  1305. *
  1306. * Return value:
  1307. * none
  1308. **/
  1309. static void ipr_clear_res_target(struct ipr_resource_entry *res)
  1310. {
  1311. struct ipr_resource_entry *gscsi_res = NULL;
  1312. struct ipr_ioa_cfg *ioa_cfg = res->ioa_cfg;
  1313. if (!ioa_cfg->sis64)
  1314. return;
  1315. if (res->bus == IPR_ARRAY_VIRTUAL_BUS)
  1316. clear_bit(res->target, ioa_cfg->array_ids);
  1317. else if (res->bus == IPR_VSET_VIRTUAL_BUS)
  1318. clear_bit(res->target, ioa_cfg->vset_ids);
  1319. else if (res->bus == 0 && res->type == IPR_RES_TYPE_GENERIC_SCSI) {
  1320. list_for_each_entry(gscsi_res, &ioa_cfg->used_res_q, queue)
  1321. if (gscsi_res->dev_id == res->dev_id && gscsi_res != res)
  1322. return;
  1323. clear_bit(res->target, ioa_cfg->target_ids);
  1324. } else if (res->bus == 0)
  1325. clear_bit(res->target, ioa_cfg->target_ids);
  1326. }
  1327. /**
  1328. * ipr_handle_config_change - Handle a config change from the adapter
  1329. * @ioa_cfg: ioa config struct
  1330. * @hostrcb: hostrcb
  1331. *
  1332. * Return value:
  1333. * none
  1334. **/
  1335. static void ipr_handle_config_change(struct ipr_ioa_cfg *ioa_cfg,
  1336. struct ipr_hostrcb *hostrcb)
  1337. {
  1338. struct ipr_resource_entry *res = NULL;
  1339. struct ipr_config_table_entry_wrapper cfgtew;
  1340. __be32 cc_res_handle;
  1341. u32 is_ndn = 1;
  1342. if (ioa_cfg->sis64) {
  1343. cfgtew.u.cfgte64 = &hostrcb->hcam.u.ccn.u.cfgte64;
  1344. cc_res_handle = cfgtew.u.cfgte64->res_handle;
  1345. } else {
  1346. cfgtew.u.cfgte = &hostrcb->hcam.u.ccn.u.cfgte;
  1347. cc_res_handle = cfgtew.u.cfgte->res_handle;
  1348. }
  1349. list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
  1350. if (res->res_handle == cc_res_handle) {
  1351. is_ndn = 0;
  1352. break;
  1353. }
  1354. }
  1355. if (is_ndn) {
  1356. if (list_empty(&ioa_cfg->free_res_q)) {
  1357. ipr_send_hcam(ioa_cfg,
  1358. IPR_HCAM_CDB_OP_CODE_CONFIG_CHANGE,
  1359. hostrcb);
  1360. return;
  1361. }
  1362. res = list_entry(ioa_cfg->free_res_q.next,
  1363. struct ipr_resource_entry, queue);
  1364. list_del(&res->queue);
  1365. ipr_init_res_entry(res, &cfgtew);
  1366. list_add_tail(&res->queue, &ioa_cfg->used_res_q);
  1367. }
  1368. ipr_update_res_entry(res, &cfgtew);
  1369. if (hostrcb->hcam.notify_type == IPR_HOST_RCB_NOTIF_TYPE_REM_ENTRY) {
  1370. if (res->sdev) {
  1371. res->del_from_ml = 1;
  1372. res->res_handle = IPR_INVALID_RES_HANDLE;
  1373. schedule_work(&ioa_cfg->work_q);
  1374. } else {
  1375. ipr_clear_res_target(res);
  1376. list_move_tail(&res->queue, &ioa_cfg->free_res_q);
  1377. }
  1378. } else if (!res->sdev || res->del_from_ml) {
  1379. res->add_to_ml = 1;
  1380. schedule_work(&ioa_cfg->work_q);
  1381. }
  1382. ipr_send_hcam(ioa_cfg, IPR_HCAM_CDB_OP_CODE_CONFIG_CHANGE, hostrcb);
  1383. }
  1384. /**
  1385. * ipr_process_ccn - Op done function for a CCN.
  1386. * @ipr_cmd: ipr command struct
  1387. *
  1388. * This function is the op done function for a configuration
  1389. * change notification host controlled async from the adapter.
  1390. *
  1391. * Return value:
  1392. * none
  1393. **/
  1394. static void ipr_process_ccn(struct ipr_cmnd *ipr_cmd)
  1395. {
  1396. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  1397. struct ipr_hostrcb *hostrcb = ipr_cmd->u.hostrcb;
  1398. u32 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
  1399. list_del_init(&hostrcb->queue);
  1400. list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_free_q);
  1401. if (ioasc) {
  1402. if (ioasc != IPR_IOASC_IOA_WAS_RESET &&
  1403. ioasc != IPR_IOASC_ABORTED_CMD_TERM_BY_HOST)
  1404. dev_err(&ioa_cfg->pdev->dev,
  1405. "Host RCB failed with IOASC: 0x%08X\n", ioasc);
  1406. ipr_send_hcam(ioa_cfg, IPR_HCAM_CDB_OP_CODE_CONFIG_CHANGE, hostrcb);
  1407. } else {
  1408. ipr_handle_config_change(ioa_cfg, hostrcb);
  1409. }
  1410. }
  1411. /**
  1412. * strip_and_pad_whitespace - Strip and pad trailing whitespace.
  1413. * @i: index into buffer
  1414. * @buf: string to modify
  1415. *
  1416. * This function will strip all trailing whitespace, pad the end
  1417. * of the string with a single space, and NULL terminate the string.
  1418. *
  1419. * Return value:
  1420. * new length of string
  1421. **/
  1422. static int strip_and_pad_whitespace(int i, char *buf)
  1423. {
  1424. while (i && buf[i] == ' ')
  1425. i--;
  1426. buf[i+1] = ' ';
  1427. buf[i+2] = '\0';
  1428. return i + 2;
  1429. }
  1430. /**
  1431. * ipr_log_vpd_compact - Log the passed extended VPD compactly.
  1432. * @prefix: string to print at start of printk
  1433. * @hostrcb: hostrcb pointer
  1434. * @vpd: vendor/product id/sn struct
  1435. *
  1436. * Return value:
  1437. * none
  1438. **/
  1439. static void ipr_log_vpd_compact(char *prefix, struct ipr_hostrcb *hostrcb,
  1440. struct ipr_vpd *vpd)
  1441. {
  1442. char buffer[IPR_VENDOR_ID_LEN + IPR_PROD_ID_LEN + IPR_SERIAL_NUM_LEN + 3];
  1443. int i = 0;
  1444. memcpy(buffer, vpd->vpids.vendor_id, IPR_VENDOR_ID_LEN);
  1445. i = strip_and_pad_whitespace(IPR_VENDOR_ID_LEN - 1, buffer);
  1446. memcpy(&buffer[i], vpd->vpids.product_id, IPR_PROD_ID_LEN);
  1447. i = strip_and_pad_whitespace(i + IPR_PROD_ID_LEN - 1, buffer);
  1448. memcpy(&buffer[i], vpd->sn, IPR_SERIAL_NUM_LEN);
  1449. buffer[IPR_SERIAL_NUM_LEN + i] = '\0';
  1450. ipr_hcam_err(hostrcb, "%s VPID/SN: %s\n", prefix, buffer);
  1451. }
  1452. /**
  1453. * ipr_log_vpd - Log the passed VPD to the error log.
  1454. * @vpd: vendor/product id/sn struct
  1455. *
  1456. * Return value:
  1457. * none
  1458. **/
  1459. static void ipr_log_vpd(struct ipr_vpd *vpd)
  1460. {
  1461. char buffer[IPR_VENDOR_ID_LEN + IPR_PROD_ID_LEN
  1462. + IPR_SERIAL_NUM_LEN];
  1463. memcpy(buffer, vpd->vpids.vendor_id, IPR_VENDOR_ID_LEN);
  1464. memcpy(buffer + IPR_VENDOR_ID_LEN, vpd->vpids.product_id,
  1465. IPR_PROD_ID_LEN);
  1466. buffer[IPR_VENDOR_ID_LEN + IPR_PROD_ID_LEN] = '\0';
  1467. ipr_err("Vendor/Product ID: %s\n", buffer);
  1468. memcpy(buffer, vpd->sn, IPR_SERIAL_NUM_LEN);
  1469. buffer[IPR_SERIAL_NUM_LEN] = '\0';
  1470. ipr_err(" Serial Number: %s\n", buffer);
  1471. }
  1472. /**
  1473. * ipr_log_ext_vpd_compact - Log the passed extended VPD compactly.
  1474. * @prefix: string to print at start of printk
  1475. * @hostrcb: hostrcb pointer
  1476. * @vpd: vendor/product id/sn/wwn struct
  1477. *
  1478. * Return value:
  1479. * none
  1480. **/
  1481. static void ipr_log_ext_vpd_compact(char *prefix, struct ipr_hostrcb *hostrcb,
  1482. struct ipr_ext_vpd *vpd)
  1483. {
  1484. ipr_log_vpd_compact(prefix, hostrcb, &vpd->vpd);
  1485. ipr_hcam_err(hostrcb, "%s WWN: %08X%08X\n", prefix,
  1486. be32_to_cpu(vpd->wwid[0]), be32_to_cpu(vpd->wwid[1]));
  1487. }
  1488. /**
  1489. * ipr_log_ext_vpd - Log the passed extended VPD to the error log.
  1490. * @vpd: vendor/product id/sn/wwn struct
  1491. *
  1492. * Return value:
  1493. * none
  1494. **/
  1495. static void ipr_log_ext_vpd(struct ipr_ext_vpd *vpd)
  1496. {
  1497. ipr_log_vpd(&vpd->vpd);
  1498. ipr_err(" WWN: %08X%08X\n", be32_to_cpu(vpd->wwid[0]),
  1499. be32_to_cpu(vpd->wwid[1]));
  1500. }
  1501. /**
  1502. * ipr_log_enhanced_cache_error - Log a cache error.
  1503. * @ioa_cfg: ioa config struct
  1504. * @hostrcb: hostrcb struct
  1505. *
  1506. * Return value:
  1507. * none
  1508. **/
  1509. static void ipr_log_enhanced_cache_error(struct ipr_ioa_cfg *ioa_cfg,
  1510. struct ipr_hostrcb *hostrcb)
  1511. {
  1512. struct ipr_hostrcb_type_12_error *error;
  1513. if (ioa_cfg->sis64)
  1514. error = &hostrcb->hcam.u.error64.u.type_12_error;
  1515. else
  1516. error = &hostrcb->hcam.u.error.u.type_12_error;
  1517. ipr_err("-----Current Configuration-----\n");
  1518. ipr_err("Cache Directory Card Information:\n");
  1519. ipr_log_ext_vpd(&error->ioa_vpd);
  1520. ipr_err("Adapter Card Information:\n");
  1521. ipr_log_ext_vpd(&error->cfc_vpd);
  1522. ipr_err("-----Expected Configuration-----\n");
  1523. ipr_err("Cache Directory Card Information:\n");
  1524. ipr_log_ext_vpd(&error->ioa_last_attached_to_cfc_vpd);
  1525. ipr_err("Adapter Card Information:\n");
  1526. ipr_log_ext_vpd(&error->cfc_last_attached_to_ioa_vpd);
  1527. ipr_err("Additional IOA Data: %08X %08X %08X\n",
  1528. be32_to_cpu(error->ioa_data[0]),
  1529. be32_to_cpu(error->ioa_data[1]),
  1530. be32_to_cpu(error->ioa_data[2]));
  1531. }
  1532. /**
  1533. * ipr_log_cache_error - Log a cache error.
  1534. * @ioa_cfg: ioa config struct
  1535. * @hostrcb: hostrcb struct
  1536. *
  1537. * Return value:
  1538. * none
  1539. **/
  1540. static void ipr_log_cache_error(struct ipr_ioa_cfg *ioa_cfg,
  1541. struct ipr_hostrcb *hostrcb)
  1542. {
  1543. struct ipr_hostrcb_type_02_error *error =
  1544. &hostrcb->hcam.u.error.u.type_02_error;
  1545. ipr_err("-----Current Configuration-----\n");
  1546. ipr_err("Cache Directory Card Information:\n");
  1547. ipr_log_vpd(&error->ioa_vpd);
  1548. ipr_err("Adapter Card Information:\n");
  1549. ipr_log_vpd(&error->cfc_vpd);
  1550. ipr_err("-----Expected Configuration-----\n");
  1551. ipr_err("Cache Directory Card Information:\n");
  1552. ipr_log_vpd(&error->ioa_last_attached_to_cfc_vpd);
  1553. ipr_err("Adapter Card Information:\n");
  1554. ipr_log_vpd(&error->cfc_last_attached_to_ioa_vpd);
  1555. ipr_err("Additional IOA Data: %08X %08X %08X\n",
  1556. be32_to_cpu(error->ioa_data[0]),
  1557. be32_to_cpu(error->ioa_data[1]),
  1558. be32_to_cpu(error->ioa_data[2]));
  1559. }
  1560. /**
  1561. * ipr_log_enhanced_config_error - Log a configuration error.
  1562. * @ioa_cfg: ioa config struct
  1563. * @hostrcb: hostrcb struct
  1564. *
  1565. * Return value:
  1566. * none
  1567. **/
  1568. static void ipr_log_enhanced_config_error(struct ipr_ioa_cfg *ioa_cfg,
  1569. struct ipr_hostrcb *hostrcb)
  1570. {
  1571. int errors_logged, i;
  1572. struct ipr_hostrcb_device_data_entry_enhanced *dev_entry;
  1573. struct ipr_hostrcb_type_13_error *error;
  1574. error = &hostrcb->hcam.u.error.u.type_13_error;
  1575. errors_logged = be32_to_cpu(error->errors_logged);
  1576. ipr_err("Device Errors Detected/Logged: %d/%d\n",
  1577. be32_to_cpu(error->errors_detected), errors_logged);
  1578. dev_entry = error->dev;
  1579. for (i = 0; i < errors_logged; i++, dev_entry++) {
  1580. ipr_err_separator;
  1581. ipr_phys_res_err(ioa_cfg, dev_entry->dev_res_addr, "Device %d", i + 1);
  1582. ipr_log_ext_vpd(&dev_entry->vpd);
  1583. ipr_err("-----New Device Information-----\n");
  1584. ipr_log_ext_vpd(&dev_entry->new_vpd);
  1585. ipr_err("Cache Directory Card Information:\n");
  1586. ipr_log_ext_vpd(&dev_entry->ioa_last_with_dev_vpd);
  1587. ipr_err("Adapter Card Information:\n");
  1588. ipr_log_ext_vpd(&dev_entry->cfc_last_with_dev_vpd);
  1589. }
  1590. }
  1591. /**
  1592. * ipr_log_sis64_config_error - Log a device error.
  1593. * @ioa_cfg: ioa config struct
  1594. * @hostrcb: hostrcb struct
  1595. *
  1596. * Return value:
  1597. * none
  1598. **/
  1599. static void ipr_log_sis64_config_error(struct ipr_ioa_cfg *ioa_cfg,
  1600. struct ipr_hostrcb *hostrcb)
  1601. {
  1602. int errors_logged, i;
  1603. struct ipr_hostrcb64_device_data_entry_enhanced *dev_entry;
  1604. struct ipr_hostrcb_type_23_error *error;
  1605. char buffer[IPR_MAX_RES_PATH_LENGTH];
  1606. error = &hostrcb->hcam.u.error64.u.type_23_error;
  1607. errors_logged = be32_to_cpu(error->errors_logged);
  1608. ipr_err("Device Errors Detected/Logged: %d/%d\n",
  1609. be32_to_cpu(error->errors_detected), errors_logged);
  1610. dev_entry = error->dev;
  1611. for (i = 0; i < errors_logged; i++, dev_entry++) {
  1612. ipr_err_separator;
  1613. ipr_err("Device %d : %s", i + 1,
  1614. __ipr_format_res_path(dev_entry->res_path,
  1615. buffer, sizeof(buffer)));
  1616. ipr_log_ext_vpd(&dev_entry->vpd);
  1617. ipr_err("-----New Device Information-----\n");
  1618. ipr_log_ext_vpd(&dev_entry->new_vpd);
  1619. ipr_err("Cache Directory Card Information:\n");
  1620. ipr_log_ext_vpd(&dev_entry->ioa_last_with_dev_vpd);
  1621. ipr_err("Adapter Card Information:\n");
  1622. ipr_log_ext_vpd(&dev_entry->cfc_last_with_dev_vpd);
  1623. }
  1624. }
  1625. /**
  1626. * ipr_log_config_error - Log a configuration error.
  1627. * @ioa_cfg: ioa config struct
  1628. * @hostrcb: hostrcb struct
  1629. *
  1630. * Return value:
  1631. * none
  1632. **/
  1633. static void ipr_log_config_error(struct ipr_ioa_cfg *ioa_cfg,
  1634. struct ipr_hostrcb *hostrcb)
  1635. {
  1636. int errors_logged, i;
  1637. struct ipr_hostrcb_device_data_entry *dev_entry;
  1638. struct ipr_hostrcb_type_03_error *error;
  1639. error = &hostrcb->hcam.u.error.u.type_03_error;
  1640. errors_logged = be32_to_cpu(error->errors_logged);
  1641. ipr_err("Device Errors Detected/Logged: %d/%d\n",
  1642. be32_to_cpu(error->errors_detected), errors_logged);
  1643. dev_entry = error->dev;
  1644. for (i = 0; i < errors_logged; i++, dev_entry++) {
  1645. ipr_err_separator;
  1646. ipr_phys_res_err(ioa_cfg, dev_entry->dev_res_addr, "Device %d", i + 1);
  1647. ipr_log_vpd(&dev_entry->vpd);
  1648. ipr_err("-----New Device Information-----\n");
  1649. ipr_log_vpd(&dev_entry->new_vpd);
  1650. ipr_err("Cache Directory Card Information:\n");
  1651. ipr_log_vpd(&dev_entry->ioa_last_with_dev_vpd);
  1652. ipr_err("Adapter Card Information:\n");
  1653. ipr_log_vpd(&dev_entry->cfc_last_with_dev_vpd);
  1654. ipr_err("Additional IOA Data: %08X %08X %08X %08X %08X\n",
  1655. be32_to_cpu(dev_entry->ioa_data[0]),
  1656. be32_to_cpu(dev_entry->ioa_data[1]),
  1657. be32_to_cpu(dev_entry->ioa_data[2]),
  1658. be32_to_cpu(dev_entry->ioa_data[3]),
  1659. be32_to_cpu(dev_entry->ioa_data[4]));
  1660. }
  1661. }
  1662. /**
  1663. * ipr_log_enhanced_array_error - Log an array configuration error.
  1664. * @ioa_cfg: ioa config struct
  1665. * @hostrcb: hostrcb struct
  1666. *
  1667. * Return value:
  1668. * none
  1669. **/
  1670. static void ipr_log_enhanced_array_error(struct ipr_ioa_cfg *ioa_cfg,
  1671. struct ipr_hostrcb *hostrcb)
  1672. {
  1673. int i, num_entries;
  1674. struct ipr_hostrcb_type_14_error *error;
  1675. struct ipr_hostrcb_array_data_entry_enhanced *array_entry;
  1676. const u8 zero_sn[IPR_SERIAL_NUM_LEN] = { [0 ... IPR_SERIAL_NUM_LEN-1] = '0' };
  1677. error = &hostrcb->hcam.u.error.u.type_14_error;
  1678. ipr_err_separator;
  1679. ipr_err("RAID %s Array Configuration: %d:%d:%d:%d\n",
  1680. error->protection_level,
  1681. ioa_cfg->host->host_no,
  1682. error->last_func_vset_res_addr.bus,
  1683. error->last_func_vset_res_addr.target,
  1684. error->last_func_vset_res_addr.lun);
  1685. ipr_err_separator;
  1686. array_entry = error->array_member;
  1687. num_entries = min_t(u32, be32_to_cpu(error->num_entries),
  1688. ARRAY_SIZE(error->array_member));
  1689. for (i = 0; i < num_entries; i++, array_entry++) {
  1690. if (!memcmp(array_entry->vpd.vpd.sn, zero_sn, IPR_SERIAL_NUM_LEN))
  1691. continue;
  1692. if (be32_to_cpu(error->exposed_mode_adn) == i)
  1693. ipr_err("Exposed Array Member %d:\n", i);
  1694. else
  1695. ipr_err("Array Member %d:\n", i);
  1696. ipr_log_ext_vpd(&array_entry->vpd);
  1697. ipr_phys_res_err(ioa_cfg, array_entry->dev_res_addr, "Current Location");
  1698. ipr_phys_res_err(ioa_cfg, array_entry->expected_dev_res_addr,
  1699. "Expected Location");
  1700. ipr_err_separator;
  1701. }
  1702. }
  1703. /**
  1704. * ipr_log_array_error - Log an array configuration error.
  1705. * @ioa_cfg: ioa config struct
  1706. * @hostrcb: hostrcb struct
  1707. *
  1708. * Return value:
  1709. * none
  1710. **/
  1711. static void ipr_log_array_error(struct ipr_ioa_cfg *ioa_cfg,
  1712. struct ipr_hostrcb *hostrcb)
  1713. {
  1714. int i;
  1715. struct ipr_hostrcb_type_04_error *error;
  1716. struct ipr_hostrcb_array_data_entry *array_entry;
  1717. const u8 zero_sn[IPR_SERIAL_NUM_LEN] = { [0 ... IPR_SERIAL_NUM_LEN-1] = '0' };
  1718. error = &hostrcb->hcam.u.error.u.type_04_error;
  1719. ipr_err_separator;
  1720. ipr_err("RAID %s Array Configuration: %d:%d:%d:%d\n",
  1721. error->protection_level,
  1722. ioa_cfg->host->host_no,
  1723. error->last_func_vset_res_addr.bus,
  1724. error->last_func_vset_res_addr.target,
  1725. error->last_func_vset_res_addr.lun);
  1726. ipr_err_separator;
  1727. array_entry = error->array_member;
  1728. for (i = 0; i < 18; i++) {
  1729. if (!memcmp(array_entry->vpd.sn, zero_sn, IPR_SERIAL_NUM_LEN))
  1730. continue;
  1731. if (be32_to_cpu(error->exposed_mode_adn) == i)
  1732. ipr_err("Exposed Array Member %d:\n", i);
  1733. else
  1734. ipr_err("Array Member %d:\n", i);
  1735. ipr_log_vpd(&array_entry->vpd);
  1736. ipr_phys_res_err(ioa_cfg, array_entry->dev_res_addr, "Current Location");
  1737. ipr_phys_res_err(ioa_cfg, array_entry->expected_dev_res_addr,
  1738. "Expected Location");
  1739. ipr_err_separator;
  1740. if (i == 9)
  1741. array_entry = error->array_member2;
  1742. else
  1743. array_entry++;
  1744. }
  1745. }
  1746. /**
  1747. * ipr_log_hex_data - Log additional hex IOA error data.
  1748. * @ioa_cfg: ioa config struct
  1749. * @data: IOA error data
  1750. * @len: data length
  1751. *
  1752. * Return value:
  1753. * none
  1754. **/
  1755. static void ipr_log_hex_data(struct ipr_ioa_cfg *ioa_cfg, __be32 *data, int len)
  1756. {
  1757. int i;
  1758. if (len == 0)
  1759. return;
  1760. if (ioa_cfg->log_level <= IPR_DEFAULT_LOG_LEVEL)
  1761. len = min_t(int, len, IPR_DEFAULT_MAX_ERROR_DUMP);
  1762. for (i = 0; i < len / 4; i += 4) {
  1763. ipr_err("%08X: %08X %08X %08X %08X\n", i*4,
  1764. be32_to_cpu(data[i]),
  1765. be32_to_cpu(data[i+1]),
  1766. be32_to_cpu(data[i+2]),
  1767. be32_to_cpu(data[i+3]));
  1768. }
  1769. }
  1770. /**
  1771. * ipr_log_enhanced_dual_ioa_error - Log an enhanced dual adapter error.
  1772. * @ioa_cfg: ioa config struct
  1773. * @hostrcb: hostrcb struct
  1774. *
  1775. * Return value:
  1776. * none
  1777. **/
  1778. static void ipr_log_enhanced_dual_ioa_error(struct ipr_ioa_cfg *ioa_cfg,
  1779. struct ipr_hostrcb *hostrcb)
  1780. {
  1781. struct ipr_hostrcb_type_17_error *error;
  1782. if (ioa_cfg->sis64)
  1783. error = &hostrcb->hcam.u.error64.u.type_17_error;
  1784. else
  1785. error = &hostrcb->hcam.u.error.u.type_17_error;
  1786. error->failure_reason[sizeof(error->failure_reason) - 1] = '\0';
  1787. strim(error->failure_reason);
  1788. ipr_hcam_err(hostrcb, "%s [PRC: %08X]\n", error->failure_reason,
  1789. be32_to_cpu(hostrcb->hcam.u.error.prc));
  1790. ipr_log_ext_vpd_compact("Remote IOA", hostrcb, &error->vpd);
  1791. ipr_log_hex_data(ioa_cfg, error->data,
  1792. be32_to_cpu(hostrcb->hcam.length) -
  1793. (offsetof(struct ipr_hostrcb_error, u) +
  1794. offsetof(struct ipr_hostrcb_type_17_error, data)));
  1795. }
  1796. /**
  1797. * ipr_log_dual_ioa_error - Log a dual adapter error.
  1798. * @ioa_cfg: ioa config struct
  1799. * @hostrcb: hostrcb struct
  1800. *
  1801. * Return value:
  1802. * none
  1803. **/
  1804. static void ipr_log_dual_ioa_error(struct ipr_ioa_cfg *ioa_cfg,
  1805. struct ipr_hostrcb *hostrcb)
  1806. {
  1807. struct ipr_hostrcb_type_07_error *error;
  1808. error = &hostrcb->hcam.u.error.u.type_07_error;
  1809. error->failure_reason[sizeof(error->failure_reason) - 1] = '\0';
  1810. strim(error->failure_reason);
  1811. ipr_hcam_err(hostrcb, "%s [PRC: %08X]\n", error->failure_reason,
  1812. be32_to_cpu(hostrcb->hcam.u.error.prc));
  1813. ipr_log_vpd_compact("Remote IOA", hostrcb, &error->vpd);
  1814. ipr_log_hex_data(ioa_cfg, error->data,
  1815. be32_to_cpu(hostrcb->hcam.length) -
  1816. (offsetof(struct ipr_hostrcb_error, u) +
  1817. offsetof(struct ipr_hostrcb_type_07_error, data)));
  1818. }
  1819. static const struct {
  1820. u8 active;
  1821. char *desc;
  1822. } path_active_desc[] = {
  1823. { IPR_PATH_NO_INFO, "Path" },
  1824. { IPR_PATH_ACTIVE, "Active path" },
  1825. { IPR_PATH_NOT_ACTIVE, "Inactive path" }
  1826. };
  1827. static const struct {
  1828. u8 state;
  1829. char *desc;
  1830. } path_state_desc[] = {
  1831. { IPR_PATH_STATE_NO_INFO, "has no path state information available" },
  1832. { IPR_PATH_HEALTHY, "is healthy" },
  1833. { IPR_PATH_DEGRADED, "is degraded" },
  1834. { IPR_PATH_FAILED, "is failed" }
  1835. };
  1836. /**
  1837. * ipr_log_fabric_path - Log a fabric path error
  1838. * @hostrcb: hostrcb struct
  1839. * @fabric: fabric descriptor
  1840. *
  1841. * Return value:
  1842. * none
  1843. **/
  1844. static void ipr_log_fabric_path(struct ipr_hostrcb *hostrcb,
  1845. struct ipr_hostrcb_fabric_desc *fabric)
  1846. {
  1847. int i, j;
  1848. u8 path_state = fabric->path_state;
  1849. u8 active = path_state & IPR_PATH_ACTIVE_MASK;
  1850. u8 state = path_state & IPR_PATH_STATE_MASK;
  1851. for (i = 0; i < ARRAY_SIZE(path_active_desc); i++) {
  1852. if (path_active_desc[i].active != active)
  1853. continue;
  1854. for (j = 0; j < ARRAY_SIZE(path_state_desc); j++) {
  1855. if (path_state_desc[j].state != state)
  1856. continue;
  1857. if (fabric->cascaded_expander == 0xff && fabric->phy == 0xff) {
  1858. ipr_hcam_err(hostrcb, "%s %s: IOA Port=%d\n",
  1859. path_active_desc[i].desc, path_state_desc[j].desc,
  1860. fabric->ioa_port);
  1861. } else if (fabric->cascaded_expander == 0xff) {
  1862. ipr_hcam_err(hostrcb, "%s %s: IOA Port=%d, Phy=%d\n",
  1863. path_active_desc[i].desc, path_state_desc[j].desc,
  1864. fabric->ioa_port, fabric->phy);
  1865. } else if (fabric->phy == 0xff) {
  1866. ipr_hcam_err(hostrcb, "%s %s: IOA Port=%d, Cascade=%d\n",
  1867. path_active_desc[i].desc, path_state_desc[j].desc,
  1868. fabric->ioa_port, fabric->cascaded_expander);
  1869. } else {
  1870. ipr_hcam_err(hostrcb, "%s %s: IOA Port=%d, Cascade=%d, Phy=%d\n",
  1871. path_active_desc[i].desc, path_state_desc[j].desc,
  1872. fabric->ioa_port, fabric->cascaded_expander, fabric->phy);
  1873. }
  1874. return;
  1875. }
  1876. }
  1877. ipr_err("Path state=%02X IOA Port=%d Cascade=%d Phy=%d\n", path_state,
  1878. fabric->ioa_port, fabric->cascaded_expander, fabric->phy);
  1879. }
  1880. /**
  1881. * ipr_log64_fabric_path - Log a fabric path error
  1882. * @hostrcb: hostrcb struct
  1883. * @fabric: fabric descriptor
  1884. *
  1885. * Return value:
  1886. * none
  1887. **/
  1888. static void ipr_log64_fabric_path(struct ipr_hostrcb *hostrcb,
  1889. struct ipr_hostrcb64_fabric_desc *fabric)
  1890. {
  1891. int i, j;
  1892. u8 path_state = fabric->path_state;
  1893. u8 active = path_state & IPR_PATH_ACTIVE_MASK;
  1894. u8 state = path_state & IPR_PATH_STATE_MASK;
  1895. char buffer[IPR_MAX_RES_PATH_LENGTH];
  1896. for (i = 0; i < ARRAY_SIZE(path_active_desc); i++) {
  1897. if (path_active_desc[i].active != active)
  1898. continue;
  1899. for (j = 0; j < ARRAY_SIZE(path_state_desc); j++) {
  1900. if (path_state_desc[j].state != state)
  1901. continue;
  1902. ipr_hcam_err(hostrcb, "%s %s: Resource Path=%s\n",
  1903. path_active_desc[i].desc, path_state_desc[j].desc,
  1904. ipr_format_res_path(hostrcb->ioa_cfg,
  1905. fabric->res_path,
  1906. buffer, sizeof(buffer)));
  1907. return;
  1908. }
  1909. }
  1910. ipr_err("Path state=%02X Resource Path=%s\n", path_state,
  1911. ipr_format_res_path(hostrcb->ioa_cfg, fabric->res_path,
  1912. buffer, sizeof(buffer)));
  1913. }
  1914. static const struct {
  1915. u8 type;
  1916. char *desc;
  1917. } path_type_desc[] = {
  1918. { IPR_PATH_CFG_IOA_PORT, "IOA port" },
  1919. { IPR_PATH_CFG_EXP_PORT, "Expander port" },
  1920. { IPR_PATH_CFG_DEVICE_PORT, "Device port" },
  1921. { IPR_PATH_CFG_DEVICE_LUN, "Device LUN" }
  1922. };
  1923. static const struct {
  1924. u8 status;
  1925. char *desc;
  1926. } path_status_desc[] = {
  1927. { IPR_PATH_CFG_NO_PROB, "Functional" },
  1928. { IPR_PATH_CFG_DEGRADED, "Degraded" },
  1929. { IPR_PATH_CFG_FAILED, "Failed" },
  1930. { IPR_PATH_CFG_SUSPECT, "Suspect" },
  1931. { IPR_PATH_NOT_DETECTED, "Missing" },
  1932. { IPR_PATH_INCORRECT_CONN, "Incorrectly connected" }
  1933. };
  1934. static const char *link_rate[] = {
  1935. "unknown",
  1936. "disabled",
  1937. "phy reset problem",
  1938. "spinup hold",
  1939. "port selector",
  1940. "unknown",
  1941. "unknown",
  1942. "unknown",
  1943. "1.5Gbps",
  1944. "3.0Gbps",
  1945. "unknown",
  1946. "unknown",
  1947. "unknown",
  1948. "unknown",
  1949. "unknown",
  1950. "unknown"
  1951. };
  1952. /**
  1953. * ipr_log_path_elem - Log a fabric path element.
  1954. * @hostrcb: hostrcb struct
  1955. * @cfg: fabric path element struct
  1956. *
  1957. * Return value:
  1958. * none
  1959. **/
  1960. static void ipr_log_path_elem(struct ipr_hostrcb *hostrcb,
  1961. struct ipr_hostrcb_config_element *cfg)
  1962. {
  1963. int i, j;
  1964. u8 type = cfg->type_status & IPR_PATH_CFG_TYPE_MASK;
  1965. u8 status = cfg->type_status & IPR_PATH_CFG_STATUS_MASK;
  1966. if (type == IPR_PATH_CFG_NOT_EXIST)
  1967. return;
  1968. for (i = 0; i < ARRAY_SIZE(path_type_desc); i++) {
  1969. if (path_type_desc[i].type != type)
  1970. continue;
  1971. for (j = 0; j < ARRAY_SIZE(path_status_desc); j++) {
  1972. if (path_status_desc[j].status != status)
  1973. continue;
  1974. if (type == IPR_PATH_CFG_IOA_PORT) {
  1975. ipr_hcam_err(hostrcb, "%s %s: Phy=%d, Link rate=%s, WWN=%08X%08X\n",
  1976. path_status_desc[j].desc, path_type_desc[i].desc,
  1977. cfg->phy, link_rate[cfg->link_rate & IPR_PHY_LINK_RATE_MASK],
  1978. be32_to_cpu(cfg->wwid[0]), be32_to_cpu(cfg->wwid[1]));
  1979. } else {
  1980. if (cfg->cascaded_expander == 0xff && cfg->phy == 0xff) {
  1981. ipr_hcam_err(hostrcb, "%s %s: Link rate=%s, WWN=%08X%08X\n",
  1982. path_status_desc[j].desc, path_type_desc[i].desc,
  1983. link_rate[cfg->link_rate & IPR_PHY_LINK_RATE_MASK],
  1984. be32_to_cpu(cfg->wwid[0]), be32_to_cpu(cfg->wwid[1]));
  1985. } else if (cfg->cascaded_expander == 0xff) {
  1986. ipr_hcam_err(hostrcb, "%s %s: Phy=%d, Link rate=%s, "
  1987. "WWN=%08X%08X\n", path_status_desc[j].desc,
  1988. path_type_desc[i].desc, cfg->phy,
  1989. link_rate[cfg->link_rate & IPR_PHY_LINK_RATE_MASK],
  1990. be32_to_cpu(cfg->wwid[0]), be32_to_cpu(cfg->wwid[1]));
  1991. } else if (cfg->phy == 0xff) {
  1992. ipr_hcam_err(hostrcb, "%s %s: Cascade=%d, Link rate=%s, "
  1993. "WWN=%08X%08X\n", path_status_desc[j].desc,
  1994. path_type_desc[i].desc, cfg->cascaded_expander,
  1995. link_rate[cfg->link_rate & IPR_PHY_LINK_RATE_MASK],
  1996. be32_to_cpu(cfg->wwid[0]), be32_to_cpu(cfg->wwid[1]));
  1997. } else {
  1998. ipr_hcam_err(hostrcb, "%s %s: Cascade=%d, Phy=%d, Link rate=%s "
  1999. "WWN=%08X%08X\n", path_status_desc[j].desc,
  2000. path_type_desc[i].desc, cfg->cascaded_expander, cfg->phy,
  2001. link_rate[cfg->link_rate & IPR_PHY_LINK_RATE_MASK],
  2002. be32_to_cpu(cfg->wwid[0]), be32_to_cpu(cfg->wwid[1]));
  2003. }
  2004. }
  2005. return;
  2006. }
  2007. }
  2008. ipr_hcam_err(hostrcb, "Path element=%02X: Cascade=%d Phy=%d Link rate=%s "
  2009. "WWN=%08X%08X\n", cfg->type_status, cfg->cascaded_expander, cfg->phy,
  2010. link_rate[cfg->link_rate & IPR_PHY_LINK_RATE_MASK],
  2011. be32_to_cpu(cfg->wwid[0]), be32_to_cpu(cfg->wwid[1]));
  2012. }
  2013. /**
  2014. * ipr_log64_path_elem - Log a fabric path element.
  2015. * @hostrcb: hostrcb struct
  2016. * @cfg: fabric path element struct
  2017. *
  2018. * Return value:
  2019. * none
  2020. **/
  2021. static void ipr_log64_path_elem(struct ipr_hostrcb *hostrcb,
  2022. struct ipr_hostrcb64_config_element *cfg)
  2023. {
  2024. int i, j;
  2025. u8 desc_id = cfg->descriptor_id & IPR_DESCRIPTOR_MASK;
  2026. u8 type = cfg->type_status & IPR_PATH_CFG_TYPE_MASK;
  2027. u8 status = cfg->type_status & IPR_PATH_CFG_STATUS_MASK;
  2028. char buffer[IPR_MAX_RES_PATH_LENGTH];
  2029. if (type == IPR_PATH_CFG_NOT_EXIST || desc_id != IPR_DESCRIPTOR_SIS64)
  2030. return;
  2031. for (i = 0; i < ARRAY_SIZE(path_type_desc); i++) {
  2032. if (path_type_desc[i].type != type)
  2033. continue;
  2034. for (j = 0; j < ARRAY_SIZE(path_status_desc); j++) {
  2035. if (path_status_desc[j].status != status)
  2036. continue;
  2037. ipr_hcam_err(hostrcb, "%s %s: Resource Path=%s, Link rate=%s, WWN=%08X%08X\n",
  2038. path_status_desc[j].desc, path_type_desc[i].desc,
  2039. ipr_format_res_path(hostrcb->ioa_cfg,
  2040. cfg->res_path, buffer, sizeof(buffer)),
  2041. link_rate[cfg->link_rate & IPR_PHY_LINK_RATE_MASK],
  2042. be32_to_cpu(cfg->wwid[0]),
  2043. be32_to_cpu(cfg->wwid[1]));
  2044. return;
  2045. }
  2046. }
  2047. ipr_hcam_err(hostrcb, "Path element=%02X: Resource Path=%s, Link rate=%s "
  2048. "WWN=%08X%08X\n", cfg->type_status,
  2049. ipr_format_res_path(hostrcb->ioa_cfg,
  2050. cfg->res_path, buffer, sizeof(buffer)),
  2051. link_rate[cfg->link_rate & IPR_PHY_LINK_RATE_MASK],
  2052. be32_to_cpu(cfg->wwid[0]), be32_to_cpu(cfg->wwid[1]));
  2053. }
  2054. /**
  2055. * ipr_log_fabric_error - Log a fabric error.
  2056. * @ioa_cfg: ioa config struct
  2057. * @hostrcb: hostrcb struct
  2058. *
  2059. * Return value:
  2060. * none
  2061. **/
  2062. static void ipr_log_fabric_error(struct ipr_ioa_cfg *ioa_cfg,
  2063. struct ipr_hostrcb *hostrcb)
  2064. {
  2065. struct ipr_hostrcb_type_20_error *error;
  2066. struct ipr_hostrcb_fabric_desc *fabric;
  2067. struct ipr_hostrcb_config_element *cfg;
  2068. int i, add_len;
  2069. error = &hostrcb->hcam.u.error.u.type_20_error;
  2070. error->failure_reason[sizeof(error->failure_reason) - 1] = '\0';
  2071. ipr_hcam_err(hostrcb, "%s\n", error->failure_reason);
  2072. add_len = be32_to_cpu(hostrcb->hcam.length) -
  2073. (offsetof(struct ipr_hostrcb_error, u) +
  2074. offsetof(struct ipr_hostrcb_type_20_error, desc));
  2075. for (i = 0, fabric = error->desc; i < error->num_entries; i++) {
  2076. ipr_log_fabric_path(hostrcb, fabric);
  2077. for_each_fabric_cfg(fabric, cfg)
  2078. ipr_log_path_elem(hostrcb, cfg);
  2079. add_len -= be16_to_cpu(fabric->length);
  2080. fabric = (struct ipr_hostrcb_fabric_desc *)
  2081. ((unsigned long)fabric + be16_to_cpu(fabric->length));
  2082. }
  2083. ipr_log_hex_data(ioa_cfg, (__be32 *)fabric, add_len);
  2084. }
  2085. /**
  2086. * ipr_log_sis64_array_error - Log a sis64 array error.
  2087. * @ioa_cfg: ioa config struct
  2088. * @hostrcb: hostrcb struct
  2089. *
  2090. * Return value:
  2091. * none
  2092. **/
  2093. static void ipr_log_sis64_array_error(struct ipr_ioa_cfg *ioa_cfg,
  2094. struct ipr_hostrcb *hostrcb)
  2095. {
  2096. int i, num_entries;
  2097. struct ipr_hostrcb_type_24_error *error;
  2098. struct ipr_hostrcb64_array_data_entry *array_entry;
  2099. char buffer[IPR_MAX_RES_PATH_LENGTH];
  2100. const u8 zero_sn[IPR_SERIAL_NUM_LEN] = { [0 ... IPR_SERIAL_NUM_LEN-1] = '0' };
  2101. error = &hostrcb->hcam.u.error64.u.type_24_error;
  2102. ipr_err_separator;
  2103. ipr_err("RAID %s Array Configuration: %s\n",
  2104. error->protection_level,
  2105. ipr_format_res_path(ioa_cfg, error->last_res_path,
  2106. buffer, sizeof(buffer)));
  2107. ipr_err_separator;
  2108. array_entry = error->array_member;
  2109. num_entries = min_t(u32, error->num_entries,
  2110. ARRAY_SIZE(error->array_member));
  2111. for (i = 0; i < num_entries; i++, array_entry++) {
  2112. if (!memcmp(array_entry->vpd.vpd.sn, zero_sn, IPR_SERIAL_NUM_LEN))
  2113. continue;
  2114. if (error->exposed_mode_adn == i)
  2115. ipr_err("Exposed Array Member %d:\n", i);
  2116. else
  2117. ipr_err("Array Member %d:\n", i);
  2118. ipr_err("Array Member %d:\n", i);
  2119. ipr_log_ext_vpd(&array_entry->vpd);
  2120. ipr_err("Current Location: %s\n",
  2121. ipr_format_res_path(ioa_cfg, array_entry->res_path,
  2122. buffer, sizeof(buffer)));
  2123. ipr_err("Expected Location: %s\n",
  2124. ipr_format_res_path(ioa_cfg,
  2125. array_entry->expected_res_path,
  2126. buffer, sizeof(buffer)));
  2127. ipr_err_separator;
  2128. }
  2129. }
  2130. /**
  2131. * ipr_log_sis64_fabric_error - Log a sis64 fabric error.
  2132. * @ioa_cfg: ioa config struct
  2133. * @hostrcb: hostrcb struct
  2134. *
  2135. * Return value:
  2136. * none
  2137. **/
  2138. static void ipr_log_sis64_fabric_error(struct ipr_ioa_cfg *ioa_cfg,
  2139. struct ipr_hostrcb *hostrcb)
  2140. {
  2141. struct ipr_hostrcb_type_30_error *error;
  2142. struct ipr_hostrcb64_fabric_desc *fabric;
  2143. struct ipr_hostrcb64_config_element *cfg;
  2144. int i, add_len;
  2145. error = &hostrcb->hcam.u.error64.u.type_30_error;
  2146. error->failure_reason[sizeof(error->failure_reason) - 1] = '\0';
  2147. ipr_hcam_err(hostrcb, "%s\n", error->failure_reason);
  2148. add_len = be32_to_cpu(hostrcb->hcam.length) -
  2149. (offsetof(struct ipr_hostrcb64_error, u) +
  2150. offsetof(struct ipr_hostrcb_type_30_error, desc));
  2151. for (i = 0, fabric = error->desc; i < error->num_entries; i++) {
  2152. ipr_log64_fabric_path(hostrcb, fabric);
  2153. for_each_fabric_cfg(fabric, cfg)
  2154. ipr_log64_path_elem(hostrcb, cfg);
  2155. add_len -= be16_to_cpu(fabric->length);
  2156. fabric = (struct ipr_hostrcb64_fabric_desc *)
  2157. ((unsigned long)fabric + be16_to_cpu(fabric->length));
  2158. }
  2159. ipr_log_hex_data(ioa_cfg, (__be32 *)fabric, add_len);
  2160. }
  2161. /**
  2162. * ipr_log_sis64_service_required_error - Log a sis64 service required error.
  2163. * @ioa_cfg: ioa config struct
  2164. * @hostrcb: hostrcb struct
  2165. *
  2166. * Return value:
  2167. * none
  2168. **/
  2169. static void ipr_log_sis64_service_required_error(struct ipr_ioa_cfg *ioa_cfg,
  2170. struct ipr_hostrcb *hostrcb)
  2171. {
  2172. struct ipr_hostrcb_type_41_error *error;
  2173. error = &hostrcb->hcam.u.error64.u.type_41_error;
  2174. error->failure_reason[sizeof(error->failure_reason) - 1] = '\0';
  2175. ipr_err("Primary Failure Reason: %s\n", error->failure_reason);
  2176. ipr_log_hex_data(ioa_cfg, error->data,
  2177. be32_to_cpu(hostrcb->hcam.length) -
  2178. (offsetof(struct ipr_hostrcb_error, u) +
  2179. offsetof(struct ipr_hostrcb_type_41_error, data)));
  2180. }
  2181. /**
  2182. * ipr_log_generic_error - Log an adapter error.
  2183. * @ioa_cfg: ioa config struct
  2184. * @hostrcb: hostrcb struct
  2185. *
  2186. * Return value:
  2187. * none
  2188. **/
  2189. static void ipr_log_generic_error(struct ipr_ioa_cfg *ioa_cfg,
  2190. struct ipr_hostrcb *hostrcb)
  2191. {
  2192. ipr_log_hex_data(ioa_cfg, hostrcb->hcam.u.raw.data,
  2193. be32_to_cpu(hostrcb->hcam.length));
  2194. }
  2195. /**
  2196. * ipr_log_sis64_device_error - Log a cache error.
  2197. * @ioa_cfg: ioa config struct
  2198. * @hostrcb: hostrcb struct
  2199. *
  2200. * Return value:
  2201. * none
  2202. **/
  2203. static void ipr_log_sis64_device_error(struct ipr_ioa_cfg *ioa_cfg,
  2204. struct ipr_hostrcb *hostrcb)
  2205. {
  2206. struct ipr_hostrcb_type_21_error *error;
  2207. char buffer[IPR_MAX_RES_PATH_LENGTH];
  2208. error = &hostrcb->hcam.u.error64.u.type_21_error;
  2209. ipr_err("-----Failing Device Information-----\n");
  2210. ipr_err("World Wide Unique ID: %08X%08X%08X%08X\n",
  2211. be32_to_cpu(error->wwn[0]), be32_to_cpu(error->wwn[1]),
  2212. be32_to_cpu(error->wwn[2]), be32_to_cpu(error->wwn[3]));
  2213. ipr_err("Device Resource Path: %s\n",
  2214. __ipr_format_res_path(error->res_path,
  2215. buffer, sizeof(buffer)));
  2216. error->primary_problem_desc[sizeof(error->primary_problem_desc) - 1] = '\0';
  2217. error->second_problem_desc[sizeof(error->second_problem_desc) - 1] = '\0';
  2218. ipr_err("Primary Problem Description: %s\n", error->primary_problem_desc);
  2219. ipr_err("Secondary Problem Description: %s\n", error->second_problem_desc);
  2220. ipr_err("SCSI Sense Data:\n");
  2221. ipr_log_hex_data(ioa_cfg, error->sense_data, sizeof(error->sense_data));
  2222. ipr_err("SCSI Command Descriptor Block: \n");
  2223. ipr_log_hex_data(ioa_cfg, error->cdb, sizeof(error->cdb));
  2224. ipr_err("Additional IOA Data:\n");
  2225. ipr_log_hex_data(ioa_cfg, error->ioa_data, be32_to_cpu(error->length_of_error));
  2226. }
  2227. /**
  2228. * ipr_get_error - Find the specfied IOASC in the ipr_error_table.
  2229. * @ioasc: IOASC
  2230. *
  2231. * This function will return the index of into the ipr_error_table
  2232. * for the specified IOASC. If the IOASC is not in the table,
  2233. * 0 will be returned, which points to the entry used for unknown errors.
  2234. *
  2235. * Return value:
  2236. * index into the ipr_error_table
  2237. **/
  2238. static u32 ipr_get_error(u32 ioasc)
  2239. {
  2240. int i;
  2241. for (i = 0; i < ARRAY_SIZE(ipr_error_table); i++)
  2242. if (ipr_error_table[i].ioasc == (ioasc & IPR_IOASC_IOASC_MASK))
  2243. return i;
  2244. return 0;
  2245. }
  2246. /**
  2247. * ipr_handle_log_data - Log an adapter error.
  2248. * @ioa_cfg: ioa config struct
  2249. * @hostrcb: hostrcb struct
  2250. *
  2251. * This function logs an adapter error to the system.
  2252. *
  2253. * Return value:
  2254. * none
  2255. **/
  2256. static void ipr_handle_log_data(struct ipr_ioa_cfg *ioa_cfg,
  2257. struct ipr_hostrcb *hostrcb)
  2258. {
  2259. u32 ioasc;
  2260. int error_index;
  2261. struct ipr_hostrcb_type_21_error *error;
  2262. if (hostrcb->hcam.notify_type != IPR_HOST_RCB_NOTIF_TYPE_ERROR_LOG_ENTRY)
  2263. return;
  2264. if (hostrcb->hcam.notifications_lost == IPR_HOST_RCB_NOTIFICATIONS_LOST)
  2265. dev_err(&ioa_cfg->pdev->dev, "Error notifications lost\n");
  2266. if (ioa_cfg->sis64)
  2267. ioasc = be32_to_cpu(hostrcb->hcam.u.error64.fd_ioasc);
  2268. else
  2269. ioasc = be32_to_cpu(hostrcb->hcam.u.error.fd_ioasc);
  2270. if (!ioa_cfg->sis64 && (ioasc == IPR_IOASC_BUS_WAS_RESET ||
  2271. ioasc == IPR_IOASC_BUS_WAS_RESET_BY_OTHER)) {
  2272. /* Tell the midlayer we had a bus reset so it will handle the UA properly */
  2273. scsi_report_bus_reset(ioa_cfg->host,
  2274. hostrcb->hcam.u.error.fd_res_addr.bus);
  2275. }
  2276. error_index = ipr_get_error(ioasc);
  2277. if (!ipr_error_table[error_index].log_hcam)
  2278. return;
  2279. if (ioasc == IPR_IOASC_HW_CMD_FAILED &&
  2280. hostrcb->hcam.overlay_id == IPR_HOST_RCB_OVERLAY_ID_21) {
  2281. error = &hostrcb->hcam.u.error64.u.type_21_error;
  2282. if (((be32_to_cpu(error->sense_data[0]) & 0x0000ff00) >> 8) == ILLEGAL_REQUEST &&
  2283. ioa_cfg->log_level <= IPR_DEFAULT_LOG_LEVEL)
  2284. return;
  2285. }
  2286. ipr_hcam_err(hostrcb, "%s\n", ipr_error_table[error_index].error);
  2287. /* Set indication we have logged an error */
  2288. ioa_cfg->errors_logged++;
  2289. if (ioa_cfg->log_level < ipr_error_table[error_index].log_hcam)
  2290. return;
  2291. if (be32_to_cpu(hostrcb->hcam.length) > sizeof(hostrcb->hcam.u.raw))
  2292. hostrcb->hcam.length = cpu_to_be32(sizeof(hostrcb->hcam.u.raw));
  2293. switch (hostrcb->hcam.overlay_id) {
  2294. case IPR_HOST_RCB_OVERLAY_ID_2:
  2295. ipr_log_cache_error(ioa_cfg, hostrcb);
  2296. break;
  2297. case IPR_HOST_RCB_OVERLAY_ID_3:
  2298. ipr_log_config_error(ioa_cfg, hostrcb);
  2299. break;
  2300. case IPR_HOST_RCB_OVERLAY_ID_4:
  2301. case IPR_HOST_RCB_OVERLAY_ID_6:
  2302. ipr_log_array_error(ioa_cfg, hostrcb);
  2303. break;
  2304. case IPR_HOST_RCB_OVERLAY_ID_7:
  2305. ipr_log_dual_ioa_error(ioa_cfg, hostrcb);
  2306. break;
  2307. case IPR_HOST_RCB_OVERLAY_ID_12:
  2308. ipr_log_enhanced_cache_error(ioa_cfg, hostrcb);
  2309. break;
  2310. case IPR_HOST_RCB_OVERLAY_ID_13:
  2311. ipr_log_enhanced_config_error(ioa_cfg, hostrcb);
  2312. break;
  2313. case IPR_HOST_RCB_OVERLAY_ID_14:
  2314. case IPR_HOST_RCB_OVERLAY_ID_16:
  2315. ipr_log_enhanced_array_error(ioa_cfg, hostrcb);
  2316. break;
  2317. case IPR_HOST_RCB_OVERLAY_ID_17:
  2318. ipr_log_enhanced_dual_ioa_error(ioa_cfg, hostrcb);
  2319. break;
  2320. case IPR_HOST_RCB_OVERLAY_ID_20:
  2321. ipr_log_fabric_error(ioa_cfg, hostrcb);
  2322. break;
  2323. case IPR_HOST_RCB_OVERLAY_ID_21:
  2324. ipr_log_sis64_device_error(ioa_cfg, hostrcb);
  2325. break;
  2326. case IPR_HOST_RCB_OVERLAY_ID_23:
  2327. ipr_log_sis64_config_error(ioa_cfg, hostrcb);
  2328. break;
  2329. case IPR_HOST_RCB_OVERLAY_ID_24:
  2330. case IPR_HOST_RCB_OVERLAY_ID_26:
  2331. ipr_log_sis64_array_error(ioa_cfg, hostrcb);
  2332. break;
  2333. case IPR_HOST_RCB_OVERLAY_ID_30:
  2334. ipr_log_sis64_fabric_error(ioa_cfg, hostrcb);
  2335. break;
  2336. case IPR_HOST_RCB_OVERLAY_ID_41:
  2337. ipr_log_sis64_service_required_error(ioa_cfg, hostrcb);
  2338. break;
  2339. case IPR_HOST_RCB_OVERLAY_ID_1:
  2340. case IPR_HOST_RCB_OVERLAY_ID_DEFAULT:
  2341. default:
  2342. ipr_log_generic_error(ioa_cfg, hostrcb);
  2343. break;
  2344. }
  2345. }
  2346. static struct ipr_hostrcb *ipr_get_free_hostrcb(struct ipr_ioa_cfg *ioa)
  2347. {
  2348. struct ipr_hostrcb *hostrcb;
  2349. hostrcb = list_first_entry_or_null(&ioa->hostrcb_free_q,
  2350. struct ipr_hostrcb, queue);
  2351. if (unlikely(!hostrcb)) {
  2352. dev_info(&ioa->pdev->dev, "Reclaiming async error buffers.");
  2353. hostrcb = list_first_entry_or_null(&ioa->hostrcb_report_q,
  2354. struct ipr_hostrcb, queue);
  2355. }
  2356. list_del_init(&hostrcb->queue);
  2357. return hostrcb;
  2358. }
  2359. /**
  2360. * ipr_process_error - Op done function for an adapter error log.
  2361. * @ipr_cmd: ipr command struct
  2362. *
  2363. * This function is the op done function for an error log host
  2364. * controlled async from the adapter. It will log the error and
  2365. * send the HCAM back to the adapter.
  2366. *
  2367. * Return value:
  2368. * none
  2369. **/
  2370. static void ipr_process_error(struct ipr_cmnd *ipr_cmd)
  2371. {
  2372. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  2373. struct ipr_hostrcb *hostrcb = ipr_cmd->u.hostrcb;
  2374. u32 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
  2375. u32 fd_ioasc;
  2376. if (ioa_cfg->sis64)
  2377. fd_ioasc = be32_to_cpu(hostrcb->hcam.u.error64.fd_ioasc);
  2378. else
  2379. fd_ioasc = be32_to_cpu(hostrcb->hcam.u.error.fd_ioasc);
  2380. list_del_init(&hostrcb->queue);
  2381. list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_free_q);
  2382. if (!ioasc) {
  2383. ipr_handle_log_data(ioa_cfg, hostrcb);
  2384. if (fd_ioasc == IPR_IOASC_NR_IOA_RESET_REQUIRED)
  2385. ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_ABBREV);
  2386. } else if (ioasc != IPR_IOASC_IOA_WAS_RESET &&
  2387. ioasc != IPR_IOASC_ABORTED_CMD_TERM_BY_HOST) {
  2388. dev_err(&ioa_cfg->pdev->dev,
  2389. "Host RCB failed with IOASC: 0x%08X\n", ioasc);
  2390. }
  2391. list_add_tail(&hostrcb->queue, &ioa_cfg->hostrcb_report_q);
  2392. schedule_work(&ioa_cfg->work_q);
  2393. hostrcb = ipr_get_free_hostrcb(ioa_cfg);
  2394. ipr_send_hcam(ioa_cfg, IPR_HCAM_CDB_OP_CODE_LOG_DATA, hostrcb);
  2395. }
  2396. /**
  2397. * ipr_timeout - An internally generated op has timed out.
  2398. * @ipr_cmd: ipr command struct
  2399. *
  2400. * This function blocks host requests and initiates an
  2401. * adapter reset.
  2402. *
  2403. * Return value:
  2404. * none
  2405. **/
  2406. static void ipr_timeout(struct timer_list *t)
  2407. {
  2408. struct ipr_cmnd *ipr_cmd = from_timer(ipr_cmd, t, timer);
  2409. unsigned long lock_flags = 0;
  2410. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  2411. ENTER;
  2412. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  2413. ioa_cfg->errors_logged++;
  2414. dev_err(&ioa_cfg->pdev->dev,
  2415. "Adapter being reset due to command timeout.\n");
  2416. if (WAIT_FOR_DUMP == ioa_cfg->sdt_state)
  2417. ioa_cfg->sdt_state = GET_DUMP;
  2418. if (!ioa_cfg->in_reset_reload || ioa_cfg->reset_cmd == ipr_cmd)
  2419. ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
  2420. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2421. LEAVE;
  2422. }
  2423. /**
  2424. * ipr_oper_timeout - Adapter timed out transitioning to operational
  2425. * @ipr_cmd: ipr command struct
  2426. *
  2427. * This function blocks host requests and initiates an
  2428. * adapter reset.
  2429. *
  2430. * Return value:
  2431. * none
  2432. **/
  2433. static void ipr_oper_timeout(struct timer_list *t)
  2434. {
  2435. struct ipr_cmnd *ipr_cmd = from_timer(ipr_cmd, t, timer);
  2436. unsigned long lock_flags = 0;
  2437. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  2438. ENTER;
  2439. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  2440. ioa_cfg->errors_logged++;
  2441. dev_err(&ioa_cfg->pdev->dev,
  2442. "Adapter timed out transitioning to operational.\n");
  2443. if (WAIT_FOR_DUMP == ioa_cfg->sdt_state)
  2444. ioa_cfg->sdt_state = GET_DUMP;
  2445. if (!ioa_cfg->in_reset_reload || ioa_cfg->reset_cmd == ipr_cmd) {
  2446. if (ipr_fastfail)
  2447. ioa_cfg->reset_retries += IPR_NUM_RESET_RELOAD_RETRIES;
  2448. ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
  2449. }
  2450. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2451. LEAVE;
  2452. }
  2453. /**
  2454. * ipr_find_ses_entry - Find matching SES in SES table
  2455. * @res: resource entry struct of SES
  2456. *
  2457. * Return value:
  2458. * pointer to SES table entry / NULL on failure
  2459. **/
  2460. static const struct ipr_ses_table_entry *
  2461. ipr_find_ses_entry(struct ipr_resource_entry *res)
  2462. {
  2463. int i, j, matches;
  2464. struct ipr_std_inq_vpids *vpids;
  2465. const struct ipr_ses_table_entry *ste = ipr_ses_table;
  2466. for (i = 0; i < ARRAY_SIZE(ipr_ses_table); i++, ste++) {
  2467. for (j = 0, matches = 0; j < IPR_PROD_ID_LEN; j++) {
  2468. if (ste->compare_product_id_byte[j] == 'X') {
  2469. vpids = &res->std_inq_data.vpids;
  2470. if (vpids->product_id[j] == ste->product_id[j])
  2471. matches++;
  2472. else
  2473. break;
  2474. } else
  2475. matches++;
  2476. }
  2477. if (matches == IPR_PROD_ID_LEN)
  2478. return ste;
  2479. }
  2480. return NULL;
  2481. }
  2482. /**
  2483. * ipr_get_max_scsi_speed - Determine max SCSI speed for a given bus
  2484. * @ioa_cfg: ioa config struct
  2485. * @bus: SCSI bus
  2486. * @bus_width: bus width
  2487. *
  2488. * Return value:
  2489. * SCSI bus speed in units of 100KHz, 1600 is 160 MHz
  2490. * For a 2-byte wide SCSI bus, the maximum transfer speed is
  2491. * twice the maximum transfer rate (e.g. for a wide enabled bus,
  2492. * max 160MHz = max 320MB/sec).
  2493. **/
  2494. static u32 ipr_get_max_scsi_speed(struct ipr_ioa_cfg *ioa_cfg, u8 bus, u8 bus_width)
  2495. {
  2496. struct ipr_resource_entry *res;
  2497. const struct ipr_ses_table_entry *ste;
  2498. u32 max_xfer_rate = IPR_MAX_SCSI_RATE(bus_width);
  2499. /* Loop through each config table entry in the config table buffer */
  2500. list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
  2501. if (!(IPR_IS_SES_DEVICE(res->std_inq_data)))
  2502. continue;
  2503. if (bus != res->bus)
  2504. continue;
  2505. if (!(ste = ipr_find_ses_entry(res)))
  2506. continue;
  2507. max_xfer_rate = (ste->max_bus_speed_limit * 10) / (bus_width / 8);
  2508. }
  2509. return max_xfer_rate;
  2510. }
  2511. /**
  2512. * ipr_wait_iodbg_ack - Wait for an IODEBUG ACK from the IOA
  2513. * @ioa_cfg: ioa config struct
  2514. * @max_delay: max delay in micro-seconds to wait
  2515. *
  2516. * Waits for an IODEBUG ACK from the IOA, doing busy looping.
  2517. *
  2518. * Return value:
  2519. * 0 on success / other on failure
  2520. **/
  2521. static int ipr_wait_iodbg_ack(struct ipr_ioa_cfg *ioa_cfg, int max_delay)
  2522. {
  2523. volatile u32 pcii_reg;
  2524. int delay = 1;
  2525. /* Read interrupt reg until IOA signals IO Debug Acknowledge */
  2526. while (delay < max_delay) {
  2527. pcii_reg = readl(ioa_cfg->regs.sense_interrupt_reg);
  2528. if (pcii_reg & IPR_PCII_IO_DEBUG_ACKNOWLEDGE)
  2529. return 0;
  2530. /* udelay cannot be used if delay is more than a few milliseconds */
  2531. if ((delay / 1000) > MAX_UDELAY_MS)
  2532. mdelay(delay / 1000);
  2533. else
  2534. udelay(delay);
  2535. delay += delay;
  2536. }
  2537. return -EIO;
  2538. }
  2539. /**
  2540. * ipr_get_sis64_dump_data_section - Dump IOA memory
  2541. * @ioa_cfg: ioa config struct
  2542. * @start_addr: adapter address to dump
  2543. * @dest: destination kernel buffer
  2544. * @length_in_words: length to dump in 4 byte words
  2545. *
  2546. * Return value:
  2547. * 0 on success
  2548. **/
  2549. static int ipr_get_sis64_dump_data_section(struct ipr_ioa_cfg *ioa_cfg,
  2550. u32 start_addr,
  2551. __be32 *dest, u32 length_in_words)
  2552. {
  2553. int i;
  2554. for (i = 0; i < length_in_words; i++) {
  2555. writel(start_addr+(i*4), ioa_cfg->regs.dump_addr_reg);
  2556. *dest = cpu_to_be32(readl(ioa_cfg->regs.dump_data_reg));
  2557. dest++;
  2558. }
  2559. return 0;
  2560. }
  2561. /**
  2562. * ipr_get_ldump_data_section - Dump IOA memory
  2563. * @ioa_cfg: ioa config struct
  2564. * @start_addr: adapter address to dump
  2565. * @dest: destination kernel buffer
  2566. * @length_in_words: length to dump in 4 byte words
  2567. *
  2568. * Return value:
  2569. * 0 on success / -EIO on failure
  2570. **/
  2571. static int ipr_get_ldump_data_section(struct ipr_ioa_cfg *ioa_cfg,
  2572. u32 start_addr,
  2573. __be32 *dest, u32 length_in_words)
  2574. {
  2575. volatile u32 temp_pcii_reg;
  2576. int i, delay = 0;
  2577. if (ioa_cfg->sis64)
  2578. return ipr_get_sis64_dump_data_section(ioa_cfg, start_addr,
  2579. dest, length_in_words);
  2580. /* Write IOA interrupt reg starting LDUMP state */
  2581. writel((IPR_UPROCI_RESET_ALERT | IPR_UPROCI_IO_DEBUG_ALERT),
  2582. ioa_cfg->regs.set_uproc_interrupt_reg32);
  2583. /* Wait for IO debug acknowledge */
  2584. if (ipr_wait_iodbg_ack(ioa_cfg,
  2585. IPR_LDUMP_MAX_LONG_ACK_DELAY_IN_USEC)) {
  2586. dev_err(&ioa_cfg->pdev->dev,
  2587. "IOA dump long data transfer timeout\n");
  2588. return -EIO;
  2589. }
  2590. /* Signal LDUMP interlocked - clear IO debug ack */
  2591. writel(IPR_PCII_IO_DEBUG_ACKNOWLEDGE,
  2592. ioa_cfg->regs.clr_interrupt_reg);
  2593. /* Write Mailbox with starting address */
  2594. writel(start_addr, ioa_cfg->ioa_mailbox);
  2595. /* Signal address valid - clear IOA Reset alert */
  2596. writel(IPR_UPROCI_RESET_ALERT,
  2597. ioa_cfg->regs.clr_uproc_interrupt_reg32);
  2598. for (i = 0; i < length_in_words; i++) {
  2599. /* Wait for IO debug acknowledge */
  2600. if (ipr_wait_iodbg_ack(ioa_cfg,
  2601. IPR_LDUMP_MAX_SHORT_ACK_DELAY_IN_USEC)) {
  2602. dev_err(&ioa_cfg->pdev->dev,
  2603. "IOA dump short data transfer timeout\n");
  2604. return -EIO;
  2605. }
  2606. /* Read data from mailbox and increment destination pointer */
  2607. *dest = cpu_to_be32(readl(ioa_cfg->ioa_mailbox));
  2608. dest++;
  2609. /* For all but the last word of data, signal data received */
  2610. if (i < (length_in_words - 1)) {
  2611. /* Signal dump data received - Clear IO debug Ack */
  2612. writel(IPR_PCII_IO_DEBUG_ACKNOWLEDGE,
  2613. ioa_cfg->regs.clr_interrupt_reg);
  2614. }
  2615. }
  2616. /* Signal end of block transfer. Set reset alert then clear IO debug ack */
  2617. writel(IPR_UPROCI_RESET_ALERT,
  2618. ioa_cfg->regs.set_uproc_interrupt_reg32);
  2619. writel(IPR_UPROCI_IO_DEBUG_ALERT,
  2620. ioa_cfg->regs.clr_uproc_interrupt_reg32);
  2621. /* Signal dump data received - Clear IO debug Ack */
  2622. writel(IPR_PCII_IO_DEBUG_ACKNOWLEDGE,
  2623. ioa_cfg->regs.clr_interrupt_reg);
  2624. /* Wait for IOA to signal LDUMP exit - IOA reset alert will be cleared */
  2625. while (delay < IPR_LDUMP_MAX_SHORT_ACK_DELAY_IN_USEC) {
  2626. temp_pcii_reg =
  2627. readl(ioa_cfg->regs.sense_uproc_interrupt_reg32);
  2628. if (!(temp_pcii_reg & IPR_UPROCI_RESET_ALERT))
  2629. return 0;
  2630. udelay(10);
  2631. delay += 10;
  2632. }
  2633. return 0;
  2634. }
  2635. #ifdef CONFIG_SCSI_IPR_DUMP
  2636. /**
  2637. * ipr_sdt_copy - Copy Smart Dump Table to kernel buffer
  2638. * @ioa_cfg: ioa config struct
  2639. * @pci_address: adapter address
  2640. * @length: length of data to copy
  2641. *
  2642. * Copy data from PCI adapter to kernel buffer.
  2643. * Note: length MUST be a 4 byte multiple
  2644. * Return value:
  2645. * 0 on success / other on failure
  2646. **/
  2647. static int ipr_sdt_copy(struct ipr_ioa_cfg *ioa_cfg,
  2648. unsigned long pci_address, u32 length)
  2649. {
  2650. int bytes_copied = 0;
  2651. int cur_len, rc, rem_len, rem_page_len, max_dump_size;
  2652. __be32 *page;
  2653. unsigned long lock_flags = 0;
  2654. struct ipr_ioa_dump *ioa_dump = &ioa_cfg->dump->ioa_dump;
  2655. if (ioa_cfg->sis64)
  2656. max_dump_size = IPR_FMT3_MAX_IOA_DUMP_SIZE;
  2657. else
  2658. max_dump_size = IPR_FMT2_MAX_IOA_DUMP_SIZE;
  2659. while (bytes_copied < length &&
  2660. (ioa_dump->hdr.len + bytes_copied) < max_dump_size) {
  2661. if (ioa_dump->page_offset >= PAGE_SIZE ||
  2662. ioa_dump->page_offset == 0) {
  2663. page = (__be32 *)__get_free_page(GFP_ATOMIC);
  2664. if (!page) {
  2665. ipr_trace;
  2666. return bytes_copied;
  2667. }
  2668. ioa_dump->page_offset = 0;
  2669. ioa_dump->ioa_data[ioa_dump->next_page_index] = page;
  2670. ioa_dump->next_page_index++;
  2671. } else
  2672. page = ioa_dump->ioa_data[ioa_dump->next_page_index - 1];
  2673. rem_len = length - bytes_copied;
  2674. rem_page_len = PAGE_SIZE - ioa_dump->page_offset;
  2675. cur_len = min(rem_len, rem_page_len);
  2676. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  2677. if (ioa_cfg->sdt_state == ABORT_DUMP) {
  2678. rc = -EIO;
  2679. } else {
  2680. rc = ipr_get_ldump_data_section(ioa_cfg,
  2681. pci_address + bytes_copied,
  2682. &page[ioa_dump->page_offset / 4],
  2683. (cur_len / sizeof(u32)));
  2684. }
  2685. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2686. if (!rc) {
  2687. ioa_dump->page_offset += cur_len;
  2688. bytes_copied += cur_len;
  2689. } else {
  2690. ipr_trace;
  2691. break;
  2692. }
  2693. schedule();
  2694. }
  2695. return bytes_copied;
  2696. }
  2697. /**
  2698. * ipr_init_dump_entry_hdr - Initialize a dump entry header.
  2699. * @hdr: dump entry header struct
  2700. *
  2701. * Return value:
  2702. * nothing
  2703. **/
  2704. static void ipr_init_dump_entry_hdr(struct ipr_dump_entry_header *hdr)
  2705. {
  2706. hdr->eye_catcher = IPR_DUMP_EYE_CATCHER;
  2707. hdr->num_elems = 1;
  2708. hdr->offset = sizeof(*hdr);
  2709. hdr->status = IPR_DUMP_STATUS_SUCCESS;
  2710. }
  2711. /**
  2712. * ipr_dump_ioa_type_data - Fill in the adapter type in the dump.
  2713. * @ioa_cfg: ioa config struct
  2714. * @driver_dump: driver dump struct
  2715. *
  2716. * Return value:
  2717. * nothing
  2718. **/
  2719. static void ipr_dump_ioa_type_data(struct ipr_ioa_cfg *ioa_cfg,
  2720. struct ipr_driver_dump *driver_dump)
  2721. {
  2722. struct ipr_inquiry_page3 *ucode_vpd = &ioa_cfg->vpd_cbs->page3_data;
  2723. ipr_init_dump_entry_hdr(&driver_dump->ioa_type_entry.hdr);
  2724. driver_dump->ioa_type_entry.hdr.len =
  2725. sizeof(struct ipr_dump_ioa_type_entry) -
  2726. sizeof(struct ipr_dump_entry_header);
  2727. driver_dump->ioa_type_entry.hdr.data_type = IPR_DUMP_DATA_TYPE_BINARY;
  2728. driver_dump->ioa_type_entry.hdr.id = IPR_DUMP_DRIVER_TYPE_ID;
  2729. driver_dump->ioa_type_entry.type = ioa_cfg->type;
  2730. driver_dump->ioa_type_entry.fw_version = (ucode_vpd->major_release << 24) |
  2731. (ucode_vpd->card_type << 16) | (ucode_vpd->minor_release[0] << 8) |
  2732. ucode_vpd->minor_release[1];
  2733. driver_dump->hdr.num_entries++;
  2734. }
  2735. /**
  2736. * ipr_dump_version_data - Fill in the driver version in the dump.
  2737. * @ioa_cfg: ioa config struct
  2738. * @driver_dump: driver dump struct
  2739. *
  2740. * Return value:
  2741. * nothing
  2742. **/
  2743. static void ipr_dump_version_data(struct ipr_ioa_cfg *ioa_cfg,
  2744. struct ipr_driver_dump *driver_dump)
  2745. {
  2746. ipr_init_dump_entry_hdr(&driver_dump->version_entry.hdr);
  2747. driver_dump->version_entry.hdr.len =
  2748. sizeof(struct ipr_dump_version_entry) -
  2749. sizeof(struct ipr_dump_entry_header);
  2750. driver_dump->version_entry.hdr.data_type = IPR_DUMP_DATA_TYPE_ASCII;
  2751. driver_dump->version_entry.hdr.id = IPR_DUMP_DRIVER_VERSION_ID;
  2752. strcpy(driver_dump->version_entry.version, IPR_DRIVER_VERSION);
  2753. driver_dump->hdr.num_entries++;
  2754. }
  2755. /**
  2756. * ipr_dump_trace_data - Fill in the IOA trace in the dump.
  2757. * @ioa_cfg: ioa config struct
  2758. * @driver_dump: driver dump struct
  2759. *
  2760. * Return value:
  2761. * nothing
  2762. **/
  2763. static void ipr_dump_trace_data(struct ipr_ioa_cfg *ioa_cfg,
  2764. struct ipr_driver_dump *driver_dump)
  2765. {
  2766. ipr_init_dump_entry_hdr(&driver_dump->trace_entry.hdr);
  2767. driver_dump->trace_entry.hdr.len =
  2768. sizeof(struct ipr_dump_trace_entry) -
  2769. sizeof(struct ipr_dump_entry_header);
  2770. driver_dump->trace_entry.hdr.data_type = IPR_DUMP_DATA_TYPE_BINARY;
  2771. driver_dump->trace_entry.hdr.id = IPR_DUMP_TRACE_ID;
  2772. memcpy(driver_dump->trace_entry.trace, ioa_cfg->trace, IPR_TRACE_SIZE);
  2773. driver_dump->hdr.num_entries++;
  2774. }
  2775. /**
  2776. * ipr_dump_location_data - Fill in the IOA location in the dump.
  2777. * @ioa_cfg: ioa config struct
  2778. * @driver_dump: driver dump struct
  2779. *
  2780. * Return value:
  2781. * nothing
  2782. **/
  2783. static void ipr_dump_location_data(struct ipr_ioa_cfg *ioa_cfg,
  2784. struct ipr_driver_dump *driver_dump)
  2785. {
  2786. ipr_init_dump_entry_hdr(&driver_dump->location_entry.hdr);
  2787. driver_dump->location_entry.hdr.len =
  2788. sizeof(struct ipr_dump_location_entry) -
  2789. sizeof(struct ipr_dump_entry_header);
  2790. driver_dump->location_entry.hdr.data_type = IPR_DUMP_DATA_TYPE_ASCII;
  2791. driver_dump->location_entry.hdr.id = IPR_DUMP_LOCATION_ID;
  2792. strcpy(driver_dump->location_entry.location, dev_name(&ioa_cfg->pdev->dev));
  2793. driver_dump->hdr.num_entries++;
  2794. }
  2795. /**
  2796. * ipr_get_ioa_dump - Perform a dump of the driver and adapter.
  2797. * @ioa_cfg: ioa config struct
  2798. * @dump: dump struct
  2799. *
  2800. * Return value:
  2801. * nothing
  2802. **/
  2803. static void ipr_get_ioa_dump(struct ipr_ioa_cfg *ioa_cfg, struct ipr_dump *dump)
  2804. {
  2805. unsigned long start_addr, sdt_word;
  2806. unsigned long lock_flags = 0;
  2807. struct ipr_driver_dump *driver_dump = &dump->driver_dump;
  2808. struct ipr_ioa_dump *ioa_dump = &dump->ioa_dump;
  2809. u32 num_entries, max_num_entries, start_off, end_off;
  2810. u32 max_dump_size, bytes_to_copy, bytes_copied, rc;
  2811. struct ipr_sdt *sdt;
  2812. int valid = 1;
  2813. int i;
  2814. ENTER;
  2815. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  2816. if (ioa_cfg->sdt_state != READ_DUMP) {
  2817. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2818. return;
  2819. }
  2820. if (ioa_cfg->sis64) {
  2821. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2822. ssleep(IPR_DUMP_DELAY_SECONDS);
  2823. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  2824. }
  2825. start_addr = readl(ioa_cfg->ioa_mailbox);
  2826. if (!ioa_cfg->sis64 && !ipr_sdt_is_fmt2(start_addr)) {
  2827. dev_err(&ioa_cfg->pdev->dev,
  2828. "Invalid dump table format: %lx\n", start_addr);
  2829. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2830. return;
  2831. }
  2832. dev_err(&ioa_cfg->pdev->dev, "Dump of IOA initiated\n");
  2833. driver_dump->hdr.eye_catcher = IPR_DUMP_EYE_CATCHER;
  2834. /* Initialize the overall dump header */
  2835. driver_dump->hdr.len = sizeof(struct ipr_driver_dump);
  2836. driver_dump->hdr.num_entries = 1;
  2837. driver_dump->hdr.first_entry_offset = sizeof(struct ipr_dump_header);
  2838. driver_dump->hdr.status = IPR_DUMP_STATUS_SUCCESS;
  2839. driver_dump->hdr.os = IPR_DUMP_OS_LINUX;
  2840. driver_dump->hdr.driver_name = IPR_DUMP_DRIVER_NAME;
  2841. ipr_dump_version_data(ioa_cfg, driver_dump);
  2842. ipr_dump_location_data(ioa_cfg, driver_dump);
  2843. ipr_dump_ioa_type_data(ioa_cfg, driver_dump);
  2844. ipr_dump_trace_data(ioa_cfg, driver_dump);
  2845. /* Update dump_header */
  2846. driver_dump->hdr.len += sizeof(struct ipr_dump_entry_header);
  2847. /* IOA Dump entry */
  2848. ipr_init_dump_entry_hdr(&ioa_dump->hdr);
  2849. ioa_dump->hdr.len = 0;
  2850. ioa_dump->hdr.data_type = IPR_DUMP_DATA_TYPE_BINARY;
  2851. ioa_dump->hdr.id = IPR_DUMP_IOA_DUMP_ID;
  2852. /* First entries in sdt are actually a list of dump addresses and
  2853. lengths to gather the real dump data. sdt represents the pointer
  2854. to the ioa generated dump table. Dump data will be extracted based
  2855. on entries in this table */
  2856. sdt = &ioa_dump->sdt;
  2857. if (ioa_cfg->sis64) {
  2858. max_num_entries = IPR_FMT3_NUM_SDT_ENTRIES;
  2859. max_dump_size = IPR_FMT3_MAX_IOA_DUMP_SIZE;
  2860. } else {
  2861. max_num_entries = IPR_FMT2_NUM_SDT_ENTRIES;
  2862. max_dump_size = IPR_FMT2_MAX_IOA_DUMP_SIZE;
  2863. }
  2864. bytes_to_copy = offsetof(struct ipr_sdt, entry) +
  2865. (max_num_entries * sizeof(struct ipr_sdt_entry));
  2866. rc = ipr_get_ldump_data_section(ioa_cfg, start_addr, (__be32 *)sdt,
  2867. bytes_to_copy / sizeof(__be32));
  2868. /* Smart Dump table is ready to use and the first entry is valid */
  2869. if (rc || ((be32_to_cpu(sdt->hdr.state) != IPR_FMT3_SDT_READY_TO_USE) &&
  2870. (be32_to_cpu(sdt->hdr.state) != IPR_FMT2_SDT_READY_TO_USE))) {
  2871. dev_err(&ioa_cfg->pdev->dev,
  2872. "Dump of IOA failed. Dump table not valid: %d, %X.\n",
  2873. rc, be32_to_cpu(sdt->hdr.state));
  2874. driver_dump->hdr.status = IPR_DUMP_STATUS_FAILED;
  2875. ioa_cfg->sdt_state = DUMP_OBTAINED;
  2876. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2877. return;
  2878. }
  2879. num_entries = be32_to_cpu(sdt->hdr.num_entries_used);
  2880. if (num_entries > max_num_entries)
  2881. num_entries = max_num_entries;
  2882. /* Update dump length to the actual data to be copied */
  2883. dump->driver_dump.hdr.len += sizeof(struct ipr_sdt_header);
  2884. if (ioa_cfg->sis64)
  2885. dump->driver_dump.hdr.len += num_entries * sizeof(struct ipr_sdt_entry);
  2886. else
  2887. dump->driver_dump.hdr.len += max_num_entries * sizeof(struct ipr_sdt_entry);
  2888. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2889. for (i = 0; i < num_entries; i++) {
  2890. if (ioa_dump->hdr.len > max_dump_size) {
  2891. driver_dump->hdr.status = IPR_DUMP_STATUS_QUAL_SUCCESS;
  2892. break;
  2893. }
  2894. if (sdt->entry[i].flags & IPR_SDT_VALID_ENTRY) {
  2895. sdt_word = be32_to_cpu(sdt->entry[i].start_token);
  2896. if (ioa_cfg->sis64)
  2897. bytes_to_copy = be32_to_cpu(sdt->entry[i].end_token);
  2898. else {
  2899. start_off = sdt_word & IPR_FMT2_MBX_ADDR_MASK;
  2900. end_off = be32_to_cpu(sdt->entry[i].end_token);
  2901. if (ipr_sdt_is_fmt2(sdt_word) && sdt_word)
  2902. bytes_to_copy = end_off - start_off;
  2903. else
  2904. valid = 0;
  2905. }
  2906. if (valid) {
  2907. if (bytes_to_copy > max_dump_size) {
  2908. sdt->entry[i].flags &= ~IPR_SDT_VALID_ENTRY;
  2909. continue;
  2910. }
  2911. /* Copy data from adapter to driver buffers */
  2912. bytes_copied = ipr_sdt_copy(ioa_cfg, sdt_word,
  2913. bytes_to_copy);
  2914. ioa_dump->hdr.len += bytes_copied;
  2915. if (bytes_copied != bytes_to_copy) {
  2916. driver_dump->hdr.status = IPR_DUMP_STATUS_QUAL_SUCCESS;
  2917. break;
  2918. }
  2919. }
  2920. }
  2921. }
  2922. dev_err(&ioa_cfg->pdev->dev, "Dump of IOA completed.\n");
  2923. /* Update dump_header */
  2924. driver_dump->hdr.len += ioa_dump->hdr.len;
  2925. wmb();
  2926. ioa_cfg->sdt_state = DUMP_OBTAINED;
  2927. LEAVE;
  2928. }
  2929. #else
  2930. #define ipr_get_ioa_dump(ioa_cfg, dump) do { } while (0)
  2931. #endif
  2932. /**
  2933. * ipr_release_dump - Free adapter dump memory
  2934. * @kref: kref struct
  2935. *
  2936. * Return value:
  2937. * nothing
  2938. **/
  2939. static void ipr_release_dump(struct kref *kref)
  2940. {
  2941. struct ipr_dump *dump = container_of(kref, struct ipr_dump, kref);
  2942. struct ipr_ioa_cfg *ioa_cfg = dump->ioa_cfg;
  2943. unsigned long lock_flags = 0;
  2944. int i;
  2945. ENTER;
  2946. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  2947. ioa_cfg->dump = NULL;
  2948. ioa_cfg->sdt_state = INACTIVE;
  2949. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2950. for (i = 0; i < dump->ioa_dump.next_page_index; i++)
  2951. free_page((unsigned long) dump->ioa_dump.ioa_data[i]);
  2952. vfree(dump->ioa_dump.ioa_data);
  2953. kfree(dump);
  2954. LEAVE;
  2955. }
  2956. static void ipr_add_remove_thread(struct work_struct *work)
  2957. {
  2958. unsigned long lock_flags;
  2959. struct ipr_resource_entry *res;
  2960. struct scsi_device *sdev;
  2961. struct ipr_ioa_cfg *ioa_cfg =
  2962. container_of(work, struct ipr_ioa_cfg, scsi_add_work_q);
  2963. u8 bus, target, lun;
  2964. int did_work;
  2965. ENTER;
  2966. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  2967. restart:
  2968. do {
  2969. did_work = 0;
  2970. if (!ioa_cfg->hrrq[IPR_INIT_HRRQ].allow_cmds) {
  2971. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2972. return;
  2973. }
  2974. list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
  2975. if (res->del_from_ml && res->sdev) {
  2976. did_work = 1;
  2977. sdev = res->sdev;
  2978. if (!scsi_device_get(sdev)) {
  2979. if (!res->add_to_ml)
  2980. list_move_tail(&res->queue, &ioa_cfg->free_res_q);
  2981. else
  2982. res->del_from_ml = 0;
  2983. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2984. scsi_remove_device(sdev);
  2985. scsi_device_put(sdev);
  2986. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  2987. }
  2988. break;
  2989. }
  2990. }
  2991. } while (did_work);
  2992. list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
  2993. if (res->add_to_ml) {
  2994. bus = res->bus;
  2995. target = res->target;
  2996. lun = res->lun;
  2997. res->add_to_ml = 0;
  2998. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2999. scsi_add_device(ioa_cfg->host, bus, target, lun);
  3000. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  3001. goto restart;
  3002. }
  3003. }
  3004. ioa_cfg->scan_done = 1;
  3005. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  3006. kobject_uevent(&ioa_cfg->host->shost_dev.kobj, KOBJ_CHANGE);
  3007. LEAVE;
  3008. }
  3009. /**
  3010. * ipr_worker_thread - Worker thread
  3011. * @work: ioa config struct
  3012. *
  3013. * Called at task level from a work thread. This function takes care
  3014. * of adding and removing device from the mid-layer as configuration
  3015. * changes are detected by the adapter.
  3016. *
  3017. * Return value:
  3018. * nothing
  3019. **/
  3020. static void ipr_worker_thread(struct work_struct *work)
  3021. {
  3022. unsigned long lock_flags;
  3023. struct ipr_dump *dump;
  3024. struct ipr_ioa_cfg *ioa_cfg =
  3025. container_of(work, struct ipr_ioa_cfg, work_q);
  3026. ENTER;
  3027. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  3028. if (ioa_cfg->sdt_state == READ_DUMP) {
  3029. dump = ioa_cfg->dump;
  3030. if (!dump) {
  3031. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  3032. return;
  3033. }
  3034. kref_get(&dump->kref);
  3035. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  3036. ipr_get_ioa_dump(ioa_cfg, dump);
  3037. kref_put(&dump->kref, ipr_release_dump);
  3038. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  3039. if (ioa_cfg->sdt_state == DUMP_OBTAINED && !ioa_cfg->dump_timeout)
  3040. ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
  3041. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  3042. return;
  3043. }
  3044. if (ioa_cfg->scsi_unblock) {
  3045. ioa_cfg->scsi_unblock = 0;
  3046. ioa_cfg->scsi_blocked = 0;
  3047. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  3048. scsi_unblock_requests(ioa_cfg->host);
  3049. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  3050. if (ioa_cfg->scsi_blocked)
  3051. scsi_block_requests(ioa_cfg->host);
  3052. }
  3053. if (!ioa_cfg->scan_enabled) {
  3054. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  3055. return;
  3056. }
  3057. schedule_work(&ioa_cfg->scsi_add_work_q);
  3058. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  3059. LEAVE;
  3060. }
  3061. #ifdef CONFIG_SCSI_IPR_TRACE
  3062. /**
  3063. * ipr_read_trace - Dump the adapter trace
  3064. * @filp: open sysfs file
  3065. * @kobj: kobject struct
  3066. * @bin_attr: bin_attribute struct
  3067. * @buf: buffer
  3068. * @off: offset
  3069. * @count: buffer size
  3070. *
  3071. * Return value:
  3072. * number of bytes printed to buffer
  3073. **/
  3074. static ssize_t ipr_read_trace(struct file *filp, struct kobject *kobj,
  3075. struct bin_attribute *bin_attr,
  3076. char *buf, loff_t off, size_t count)
  3077. {
  3078. struct device *dev = container_of(kobj, struct device, kobj);
  3079. struct Scsi_Host *shost = class_to_shost(dev);
  3080. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
  3081. unsigned long lock_flags = 0;
  3082. ssize_t ret;
  3083. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  3084. ret = memory_read_from_buffer(buf, count, &off, ioa_cfg->trace,
  3085. IPR_TRACE_SIZE);
  3086. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  3087. return ret;
  3088. }
  3089. static struct bin_attribute ipr_trace_attr = {
  3090. .attr = {
  3091. .name = "trace",
  3092. .mode = S_IRUGO,
  3093. },
  3094. .size = 0,
  3095. .read = ipr_read_trace,
  3096. };
  3097. #endif
  3098. /**
  3099. * ipr_show_fw_version - Show the firmware version
  3100. * @dev: class device struct
  3101. * @buf: buffer
  3102. *
  3103. * Return value:
  3104. * number of bytes printed to buffer
  3105. **/
  3106. static ssize_t ipr_show_fw_version(struct device *dev,
  3107. struct device_attribute *attr, char *buf)
  3108. {
  3109. struct Scsi_Host *shost = class_to_shost(dev);
  3110. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
  3111. struct ipr_inquiry_page3 *ucode_vpd = &ioa_cfg->vpd_cbs->page3_data;
  3112. unsigned long lock_flags = 0;
  3113. int len;
  3114. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  3115. len = snprintf(buf, PAGE_SIZE, "%02X%02X%02X%02X\n",
  3116. ucode_vpd->major_release, ucode_vpd->card_type,
  3117. ucode_vpd->minor_release[0],
  3118. ucode_vpd->minor_release[1]);
  3119. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  3120. return len;
  3121. }
  3122. static struct device_attribute ipr_fw_version_attr = {
  3123. .attr = {
  3124. .name = "fw_version",
  3125. .mode = S_IRUGO,
  3126. },
  3127. .show = ipr_show_fw_version,
  3128. };
  3129. /**
  3130. * ipr_show_log_level - Show the adapter's error logging level
  3131. * @dev: class device struct
  3132. * @buf: buffer
  3133. *
  3134. * Return value:
  3135. * number of bytes printed to buffer
  3136. **/
  3137. static ssize_t ipr_show_log_level(struct device *dev,
  3138. struct device_attribute *attr, char *buf)
  3139. {
  3140. struct Scsi_Host *shost = class_to_shost(dev);
  3141. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
  3142. unsigned long lock_flags = 0;
  3143. int len;
  3144. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  3145. len = snprintf(buf, PAGE_SIZE, "%d\n", ioa_cfg->log_level);
  3146. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  3147. return len;
  3148. }
  3149. /**
  3150. * ipr_store_log_level - Change the adapter's error logging level
  3151. * @dev: class device struct
  3152. * @buf: buffer
  3153. *
  3154. * Return value:
  3155. * number of bytes printed to buffer
  3156. **/
  3157. static ssize_t ipr_store_log_level(struct device *dev,
  3158. struct device_attribute *attr,
  3159. const char *buf, size_t count)
  3160. {
  3161. struct Scsi_Host *shost = class_to_shost(dev);
  3162. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
  3163. unsigned long lock_flags = 0;
  3164. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  3165. ioa_cfg->log_level = simple_strtoul(buf, NULL, 10);
  3166. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  3167. return strlen(buf);
  3168. }
  3169. static struct device_attribute ipr_log_level_attr = {
  3170. .attr = {
  3171. .name = "log_level",
  3172. .mode = S_IRUGO | S_IWUSR,
  3173. },
  3174. .show = ipr_show_log_level,
  3175. .store = ipr_store_log_level
  3176. };
  3177. /**
  3178. * ipr_store_diagnostics - IOA Diagnostics interface
  3179. * @dev: device struct
  3180. * @buf: buffer
  3181. * @count: buffer size
  3182. *
  3183. * This function will reset the adapter and wait a reasonable
  3184. * amount of time for any errors that the adapter might log.
  3185. *
  3186. * Return value:
  3187. * count on success / other on failure
  3188. **/
  3189. static ssize_t ipr_store_diagnostics(struct device *dev,
  3190. struct device_attribute *attr,
  3191. const char *buf, size_t count)
  3192. {
  3193. struct Scsi_Host *shost = class_to_shost(dev);
  3194. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
  3195. unsigned long lock_flags = 0;
  3196. int rc = count;
  3197. if (!capable(CAP_SYS_ADMIN))
  3198. return -EACCES;
  3199. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  3200. while (ioa_cfg->in_reset_reload) {
  3201. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  3202. wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
  3203. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  3204. }
  3205. ioa_cfg->errors_logged = 0;
  3206. ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NORMAL);
  3207. if (ioa_cfg->in_reset_reload) {
  3208. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  3209. wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
  3210. /* Wait for a second for any errors to be logged */
  3211. msleep(1000);
  3212. } else {
  3213. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  3214. return -EIO;
  3215. }
  3216. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  3217. if (ioa_cfg->in_reset_reload || ioa_cfg->errors_logged)
  3218. rc = -EIO;
  3219. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  3220. return rc;
  3221. }
  3222. static struct device_attribute ipr_diagnostics_attr = {
  3223. .attr = {
  3224. .name = "run_diagnostics",
  3225. .mode = S_IWUSR,
  3226. },
  3227. .store = ipr_store_diagnostics
  3228. };
  3229. /**
  3230. * ipr_show_adapter_state - Show the adapter's state
  3231. * @class_dev: device struct
  3232. * @buf: buffer
  3233. *
  3234. * Return value:
  3235. * number of bytes printed to buffer
  3236. **/
  3237. static ssize_t ipr_show_adapter_state(struct device *dev,
  3238. struct device_attribute *attr, char *buf)
  3239. {
  3240. struct Scsi_Host *shost = class_to_shost(dev);
  3241. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
  3242. unsigned long lock_flags = 0;
  3243. int len;
  3244. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  3245. if (ioa_cfg->hrrq[IPR_INIT_HRRQ].ioa_is_dead)
  3246. len = snprintf(buf, PAGE_SIZE, "offline\n");
  3247. else
  3248. len = snprintf(buf, PAGE_SIZE, "online\n");
  3249. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  3250. return len;
  3251. }
  3252. /**
  3253. * ipr_store_adapter_state - Change adapter state
  3254. * @dev: device struct
  3255. * @buf: buffer
  3256. * @count: buffer size
  3257. *
  3258. * This function will change the adapter's state.
  3259. *
  3260. * Return value:
  3261. * count on success / other on failure
  3262. **/
  3263. static ssize_t ipr_store_adapter_state(struct device *dev,
  3264. struct device_attribute *attr,
  3265. const char *buf, size_t count)
  3266. {
  3267. struct Scsi_Host *shost = class_to_shost(dev);
  3268. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
  3269. unsigned long lock_flags;
  3270. int result = count, i;
  3271. if (!capable(CAP_SYS_ADMIN))
  3272. return -EACCES;
  3273. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  3274. if (ioa_cfg->hrrq[IPR_INIT_HRRQ].ioa_is_dead &&
  3275. !strncmp(buf, "online", 6)) {
  3276. for (i = 0; i < ioa_cfg->hrrq_num; i++) {
  3277. spin_lock(&ioa_cfg->hrrq[i]._lock);
  3278. ioa_cfg->hrrq[i].ioa_is_dead = 0;
  3279. spin_unlock(&ioa_cfg->hrrq[i]._lock);
  3280. }
  3281. wmb();
  3282. ioa_cfg->reset_retries = 0;
  3283. ioa_cfg->in_ioa_bringdown = 0;
  3284. ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
  3285. }
  3286. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  3287. wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
  3288. return result;
  3289. }
  3290. static struct device_attribute ipr_ioa_state_attr = {
  3291. .attr = {
  3292. .name = "online_state",
  3293. .mode = S_IRUGO | S_IWUSR,
  3294. },
  3295. .show = ipr_show_adapter_state,
  3296. .store = ipr_store_adapter_state
  3297. };
  3298. /**
  3299. * ipr_store_reset_adapter - Reset the adapter
  3300. * @dev: device struct
  3301. * @buf: buffer
  3302. * @count: buffer size
  3303. *
  3304. * This function will reset the adapter.
  3305. *
  3306. * Return value:
  3307. * count on success / other on failure
  3308. **/
  3309. static ssize_t ipr_store_reset_adapter(struct device *dev,
  3310. struct device_attribute *attr,
  3311. const char *buf, size_t count)
  3312. {
  3313. struct Scsi_Host *shost = class_to_shost(dev);
  3314. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
  3315. unsigned long lock_flags;
  3316. int result = count;
  3317. if (!capable(CAP_SYS_ADMIN))
  3318. return -EACCES;
  3319. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  3320. if (!ioa_cfg->in_reset_reload)
  3321. ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NORMAL);
  3322. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  3323. wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
  3324. return result;
  3325. }
  3326. static struct device_attribute ipr_ioa_reset_attr = {
  3327. .attr = {
  3328. .name = "reset_host",
  3329. .mode = S_IWUSR,
  3330. },
  3331. .store = ipr_store_reset_adapter
  3332. };
  3333. static int ipr_iopoll(struct irq_poll *iop, int budget);
  3334. /**
  3335. * ipr_show_iopoll_weight - Show ipr polling mode
  3336. * @dev: class device struct
  3337. * @buf: buffer
  3338. *
  3339. * Return value:
  3340. * number of bytes printed to buffer
  3341. **/
  3342. static ssize_t ipr_show_iopoll_weight(struct device *dev,
  3343. struct device_attribute *attr, char *buf)
  3344. {
  3345. struct Scsi_Host *shost = class_to_shost(dev);
  3346. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
  3347. unsigned long lock_flags = 0;
  3348. int len;
  3349. spin_lock_irqsave(shost->host_lock, lock_flags);
  3350. len = snprintf(buf, PAGE_SIZE, "%d\n", ioa_cfg->iopoll_weight);
  3351. spin_unlock_irqrestore(shost->host_lock, lock_flags);
  3352. return len;
  3353. }
  3354. /**
  3355. * ipr_store_iopoll_weight - Change the adapter's polling mode
  3356. * @dev: class device struct
  3357. * @buf: buffer
  3358. *
  3359. * Return value:
  3360. * number of bytes printed to buffer
  3361. **/
  3362. static ssize_t ipr_store_iopoll_weight(struct device *dev,
  3363. struct device_attribute *attr,
  3364. const char *buf, size_t count)
  3365. {
  3366. struct Scsi_Host *shost = class_to_shost(dev);
  3367. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
  3368. unsigned long user_iopoll_weight;
  3369. unsigned long lock_flags = 0;
  3370. int i;
  3371. if (!ioa_cfg->sis64) {
  3372. dev_info(&ioa_cfg->pdev->dev, "irq_poll not supported on this adapter\n");
  3373. return -EINVAL;
  3374. }
  3375. if (kstrtoul(buf, 10, &user_iopoll_weight))
  3376. return -EINVAL;
  3377. if (user_iopoll_weight > 256) {
  3378. dev_info(&ioa_cfg->pdev->dev, "Invalid irq_poll weight. It must be less than 256\n");
  3379. return -EINVAL;
  3380. }
  3381. if (user_iopoll_weight == ioa_cfg->iopoll_weight) {
  3382. dev_info(&ioa_cfg->pdev->dev, "Current irq_poll weight has the same weight\n");
  3383. return strlen(buf);
  3384. }
  3385. if (ioa_cfg->iopoll_weight && ioa_cfg->sis64 && ioa_cfg->nvectors > 1) {
  3386. for (i = 1; i < ioa_cfg->hrrq_num; i++)
  3387. irq_poll_disable(&ioa_cfg->hrrq[i].iopoll);
  3388. }
  3389. spin_lock_irqsave(shost->host_lock, lock_flags);
  3390. ioa_cfg->iopoll_weight = user_iopoll_weight;
  3391. if (ioa_cfg->iopoll_weight && ioa_cfg->sis64 && ioa_cfg->nvectors > 1) {
  3392. for (i = 1; i < ioa_cfg->hrrq_num; i++) {
  3393. irq_poll_init(&ioa_cfg->hrrq[i].iopoll,
  3394. ioa_cfg->iopoll_weight, ipr_iopoll);
  3395. }
  3396. }
  3397. spin_unlock_irqrestore(shost->host_lock, lock_flags);
  3398. return strlen(buf);
  3399. }
  3400. static struct device_attribute ipr_iopoll_weight_attr = {
  3401. .attr = {
  3402. .name = "iopoll_weight",
  3403. .mode = S_IRUGO | S_IWUSR,
  3404. },
  3405. .show = ipr_show_iopoll_weight,
  3406. .store = ipr_store_iopoll_weight
  3407. };
  3408. /**
  3409. * ipr_alloc_ucode_buffer - Allocates a microcode download buffer
  3410. * @buf_len: buffer length
  3411. *
  3412. * Allocates a DMA'able buffer in chunks and assembles a scatter/gather
  3413. * list to use for microcode download
  3414. *
  3415. * Return value:
  3416. * pointer to sglist / NULL on failure
  3417. **/
  3418. static struct ipr_sglist *ipr_alloc_ucode_buffer(int buf_len)
  3419. {
  3420. int sg_size, order;
  3421. struct ipr_sglist *sglist;
  3422. /* Get the minimum size per scatter/gather element */
  3423. sg_size = buf_len / (IPR_MAX_SGLIST - 1);
  3424. /* Get the actual size per element */
  3425. order = get_order(sg_size);
  3426. /* Allocate a scatter/gather list for the DMA */
  3427. sglist = kzalloc(sizeof(struct ipr_sglist), GFP_KERNEL);
  3428. if (sglist == NULL) {
  3429. ipr_trace;
  3430. return NULL;
  3431. }
  3432. sglist->order = order;
  3433. sglist->scatterlist = sgl_alloc_order(buf_len, order, false, GFP_KERNEL,
  3434. &sglist->num_sg);
  3435. if (!sglist->scatterlist) {
  3436. kfree(sglist);
  3437. return NULL;
  3438. }
  3439. return sglist;
  3440. }
  3441. /**
  3442. * ipr_free_ucode_buffer - Frees a microcode download buffer
  3443. * @p_dnld: scatter/gather list pointer
  3444. *
  3445. * Free a DMA'able ucode download buffer previously allocated with
  3446. * ipr_alloc_ucode_buffer
  3447. *
  3448. * Return value:
  3449. * nothing
  3450. **/
  3451. static void ipr_free_ucode_buffer(struct ipr_sglist *sglist)
  3452. {
  3453. sgl_free_order(sglist->scatterlist, sglist->order);
  3454. kfree(sglist);
  3455. }
  3456. /**
  3457. * ipr_copy_ucode_buffer - Copy user buffer to kernel buffer
  3458. * @sglist: scatter/gather list pointer
  3459. * @buffer: buffer pointer
  3460. * @len: buffer length
  3461. *
  3462. * Copy a microcode image from a user buffer into a buffer allocated by
  3463. * ipr_alloc_ucode_buffer
  3464. *
  3465. * Return value:
  3466. * 0 on success / other on failure
  3467. **/
  3468. static int ipr_copy_ucode_buffer(struct ipr_sglist *sglist,
  3469. u8 *buffer, u32 len)
  3470. {
  3471. int bsize_elem, i, result = 0;
  3472. struct scatterlist *scatterlist;
  3473. void *kaddr;
  3474. /* Determine the actual number of bytes per element */
  3475. bsize_elem = PAGE_SIZE * (1 << sglist->order);
  3476. scatterlist = sglist->scatterlist;
  3477. for (i = 0; i < (len / bsize_elem); i++, buffer += bsize_elem) {
  3478. struct page *page = sg_page(&scatterlist[i]);
  3479. kaddr = kmap(page);
  3480. memcpy(kaddr, buffer, bsize_elem);
  3481. kunmap(page);
  3482. scatterlist[i].length = bsize_elem;
  3483. if (result != 0) {
  3484. ipr_trace;
  3485. return result;
  3486. }
  3487. }
  3488. if (len % bsize_elem) {
  3489. struct page *page = sg_page(&scatterlist[i]);
  3490. kaddr = kmap(page);
  3491. memcpy(kaddr, buffer, len % bsize_elem);
  3492. kunmap(page);
  3493. scatterlist[i].length = len % bsize_elem;
  3494. }
  3495. sglist->buffer_len = len;
  3496. return result;
  3497. }
  3498. /**
  3499. * ipr_build_ucode_ioadl64 - Build a microcode download IOADL
  3500. * @ipr_cmd: ipr command struct
  3501. * @sglist: scatter/gather list
  3502. *
  3503. * Builds a microcode download IOA data list (IOADL).
  3504. *
  3505. **/
  3506. static void ipr_build_ucode_ioadl64(struct ipr_cmnd *ipr_cmd,
  3507. struct ipr_sglist *sglist)
  3508. {
  3509. struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
  3510. struct ipr_ioadl64_desc *ioadl64 = ipr_cmd->i.ioadl64;
  3511. struct scatterlist *scatterlist = sglist->scatterlist;
  3512. int i;
  3513. ipr_cmd->dma_use_sg = sglist->num_dma_sg;
  3514. ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
  3515. ioarcb->data_transfer_length = cpu_to_be32(sglist->buffer_len);
  3516. ioarcb->ioadl_len =
  3517. cpu_to_be32(sizeof(struct ipr_ioadl64_desc) * ipr_cmd->dma_use_sg);
  3518. for (i = 0; i < ipr_cmd->dma_use_sg; i++) {
  3519. ioadl64[i].flags = cpu_to_be32(IPR_IOADL_FLAGS_WRITE);
  3520. ioadl64[i].data_len = cpu_to_be32(sg_dma_len(&scatterlist[i]));
  3521. ioadl64[i].address = cpu_to_be64(sg_dma_address(&scatterlist[i]));
  3522. }
  3523. ioadl64[i-1].flags |= cpu_to_be32(IPR_IOADL_FLAGS_LAST);
  3524. }
  3525. /**
  3526. * ipr_build_ucode_ioadl - Build a microcode download IOADL
  3527. * @ipr_cmd: ipr command struct
  3528. * @sglist: scatter/gather list
  3529. *
  3530. * Builds a microcode download IOA data list (IOADL).
  3531. *
  3532. **/
  3533. static void ipr_build_ucode_ioadl(struct ipr_cmnd *ipr_cmd,
  3534. struct ipr_sglist *sglist)
  3535. {
  3536. struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
  3537. struct ipr_ioadl_desc *ioadl = ipr_cmd->i.ioadl;
  3538. struct scatterlist *scatterlist = sglist->scatterlist;
  3539. int i;
  3540. ipr_cmd->dma_use_sg = sglist->num_dma_sg;
  3541. ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
  3542. ioarcb->data_transfer_length = cpu_to_be32(sglist->buffer_len);
  3543. ioarcb->ioadl_len =
  3544. cpu_to_be32(sizeof(struct ipr_ioadl_desc) * ipr_cmd->dma_use_sg);
  3545. for (i = 0; i < ipr_cmd->dma_use_sg; i++) {
  3546. ioadl[i].flags_and_data_len =
  3547. cpu_to_be32(IPR_IOADL_FLAGS_WRITE | sg_dma_len(&scatterlist[i]));
  3548. ioadl[i].address =
  3549. cpu_to_be32(sg_dma_address(&scatterlist[i]));
  3550. }
  3551. ioadl[i-1].flags_and_data_len |=
  3552. cpu_to_be32(IPR_IOADL_FLAGS_LAST);
  3553. }
  3554. /**
  3555. * ipr_update_ioa_ucode - Update IOA's microcode
  3556. * @ioa_cfg: ioa config struct
  3557. * @sglist: scatter/gather list
  3558. *
  3559. * Initiate an adapter reset to update the IOA's microcode
  3560. *
  3561. * Return value:
  3562. * 0 on success / -EIO on failure
  3563. **/
  3564. static int ipr_update_ioa_ucode(struct ipr_ioa_cfg *ioa_cfg,
  3565. struct ipr_sglist *sglist)
  3566. {
  3567. unsigned long lock_flags;
  3568. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  3569. while (ioa_cfg->in_reset_reload) {
  3570. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  3571. wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
  3572. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  3573. }
  3574. if (ioa_cfg->ucode_sglist) {
  3575. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  3576. dev_err(&ioa_cfg->pdev->dev,
  3577. "Microcode download already in progress\n");
  3578. return -EIO;
  3579. }
  3580. sglist->num_dma_sg = dma_map_sg(&ioa_cfg->pdev->dev,
  3581. sglist->scatterlist, sglist->num_sg,
  3582. DMA_TO_DEVICE);
  3583. if (!sglist->num_dma_sg) {
  3584. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  3585. dev_err(&ioa_cfg->pdev->dev,
  3586. "Failed to map microcode download buffer!\n");
  3587. return -EIO;
  3588. }
  3589. ioa_cfg->ucode_sglist = sglist;
  3590. ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NORMAL);
  3591. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  3592. wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
  3593. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  3594. ioa_cfg->ucode_sglist = NULL;
  3595. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  3596. return 0;
  3597. }
  3598. /**
  3599. * ipr_store_update_fw - Update the firmware on the adapter
  3600. * @class_dev: device struct
  3601. * @buf: buffer
  3602. * @count: buffer size
  3603. *
  3604. * This function will update the firmware on the adapter.
  3605. *
  3606. * Return value:
  3607. * count on success / other on failure
  3608. **/
  3609. static ssize_t ipr_store_update_fw(struct device *dev,
  3610. struct device_attribute *attr,
  3611. const char *buf, size_t count)
  3612. {
  3613. struct Scsi_Host *shost = class_to_shost(dev);
  3614. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
  3615. struct ipr_ucode_image_header *image_hdr;
  3616. const struct firmware *fw_entry;
  3617. struct ipr_sglist *sglist;
  3618. char fname[100];
  3619. char *src;
  3620. char *endline;
  3621. int result, dnld_size;
  3622. if (!capable(CAP_SYS_ADMIN))
  3623. return -EACCES;
  3624. snprintf(fname, sizeof(fname), "%s", buf);
  3625. endline = strchr(fname, '\n');
  3626. if (endline)
  3627. *endline = '\0';
  3628. if (request_firmware(&fw_entry, fname, &ioa_cfg->pdev->dev)) {
  3629. dev_err(&ioa_cfg->pdev->dev, "Firmware file %s not found\n", fname);
  3630. return -EIO;
  3631. }
  3632. image_hdr = (struct ipr_ucode_image_header *)fw_entry->data;
  3633. src = (u8 *)image_hdr + be32_to_cpu(image_hdr->header_length);
  3634. dnld_size = fw_entry->size - be32_to_cpu(image_hdr->header_length);
  3635. sglist = ipr_alloc_ucode_buffer(dnld_size);
  3636. if (!sglist) {
  3637. dev_err(&ioa_cfg->pdev->dev, "Microcode buffer allocation failed\n");
  3638. release_firmware(fw_entry);
  3639. return -ENOMEM;
  3640. }
  3641. result = ipr_copy_ucode_buffer(sglist, src, dnld_size);
  3642. if (result) {
  3643. dev_err(&ioa_cfg->pdev->dev,
  3644. "Microcode buffer copy to DMA buffer failed\n");
  3645. goto out;
  3646. }
  3647. ipr_info("Updating microcode, please be patient. This may take up to 30 minutes.\n");
  3648. result = ipr_update_ioa_ucode(ioa_cfg, sglist);
  3649. if (!result)
  3650. result = count;
  3651. out:
  3652. ipr_free_ucode_buffer(sglist);
  3653. release_firmware(fw_entry);
  3654. return result;
  3655. }
  3656. static struct device_attribute ipr_update_fw_attr = {
  3657. .attr = {
  3658. .name = "update_fw",
  3659. .mode = S_IWUSR,
  3660. },
  3661. .store = ipr_store_update_fw
  3662. };
  3663. /**
  3664. * ipr_show_fw_type - Show the adapter's firmware type.
  3665. * @dev: class device struct
  3666. * @buf: buffer
  3667. *
  3668. * Return value:
  3669. * number of bytes printed to buffer
  3670. **/
  3671. static ssize_t ipr_show_fw_type(struct device *dev,
  3672. struct device_attribute *attr, char *buf)
  3673. {
  3674. struct Scsi_Host *shost = class_to_shost(dev);
  3675. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
  3676. unsigned long lock_flags = 0;
  3677. int len;
  3678. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  3679. len = snprintf(buf, PAGE_SIZE, "%d\n", ioa_cfg->sis64);
  3680. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  3681. return len;
  3682. }
  3683. static struct device_attribute ipr_ioa_fw_type_attr = {
  3684. .attr = {
  3685. .name = "fw_type",
  3686. .mode = S_IRUGO,
  3687. },
  3688. .show = ipr_show_fw_type
  3689. };
  3690. static ssize_t ipr_read_async_err_log(struct file *filep, struct kobject *kobj,
  3691. struct bin_attribute *bin_attr, char *buf,
  3692. loff_t off, size_t count)
  3693. {
  3694. struct device *cdev = container_of(kobj, struct device, kobj);
  3695. struct Scsi_Host *shost = class_to_shost(cdev);
  3696. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
  3697. struct ipr_hostrcb *hostrcb;
  3698. unsigned long lock_flags = 0;
  3699. int ret;
  3700. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  3701. hostrcb = list_first_entry_or_null(&ioa_cfg->hostrcb_report_q,
  3702. struct ipr_hostrcb, queue);
  3703. if (!hostrcb) {
  3704. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  3705. return 0;
  3706. }
  3707. ret = memory_read_from_buffer(buf, count, &off, &hostrcb->hcam,
  3708. sizeof(hostrcb->hcam));
  3709. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  3710. return ret;
  3711. }
  3712. static ssize_t ipr_next_async_err_log(struct file *filep, struct kobject *kobj,
  3713. struct bin_attribute *bin_attr, char *buf,
  3714. loff_t off, size_t count)
  3715. {
  3716. struct device *cdev = container_of(kobj, struct device, kobj);
  3717. struct Scsi_Host *shost = class_to_shost(cdev);
  3718. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
  3719. struct ipr_hostrcb *hostrcb;
  3720. unsigned long lock_flags = 0;
  3721. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  3722. hostrcb = list_first_entry_or_null(&ioa_cfg->hostrcb_report_q,
  3723. struct ipr_hostrcb, queue);
  3724. if (!hostrcb) {
  3725. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  3726. return count;
  3727. }
  3728. /* Reclaim hostrcb before exit */
  3729. list_move_tail(&hostrcb->queue, &ioa_cfg->hostrcb_free_q);
  3730. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  3731. return count;
  3732. }
  3733. static struct bin_attribute ipr_ioa_async_err_log = {
  3734. .attr = {
  3735. .name = "async_err_log",
  3736. .mode = S_IRUGO | S_IWUSR,
  3737. },
  3738. .size = 0,
  3739. .read = ipr_read_async_err_log,
  3740. .write = ipr_next_async_err_log
  3741. };
  3742. static struct device_attribute *ipr_ioa_attrs[] = {
  3743. &ipr_fw_version_attr,
  3744. &ipr_log_level_attr,
  3745. &ipr_diagnostics_attr,
  3746. &ipr_ioa_state_attr,
  3747. &ipr_ioa_reset_attr,
  3748. &ipr_update_fw_attr,
  3749. &ipr_ioa_fw_type_attr,
  3750. &ipr_iopoll_weight_attr,
  3751. NULL,
  3752. };
  3753. #ifdef CONFIG_SCSI_IPR_DUMP
  3754. /**
  3755. * ipr_read_dump - Dump the adapter
  3756. * @filp: open sysfs file
  3757. * @kobj: kobject struct
  3758. * @bin_attr: bin_attribute struct
  3759. * @buf: buffer
  3760. * @off: offset
  3761. * @count: buffer size
  3762. *
  3763. * Return value:
  3764. * number of bytes printed to buffer
  3765. **/
  3766. static ssize_t ipr_read_dump(struct file *filp, struct kobject *kobj,
  3767. struct bin_attribute *bin_attr,
  3768. char *buf, loff_t off, size_t count)
  3769. {
  3770. struct device *cdev = container_of(kobj, struct device, kobj);
  3771. struct Scsi_Host *shost = class_to_shost(cdev);
  3772. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
  3773. struct ipr_dump *dump;
  3774. unsigned long lock_flags = 0;
  3775. char *src;
  3776. int len, sdt_end;
  3777. size_t rc = count;
  3778. if (!capable(CAP_SYS_ADMIN))
  3779. return -EACCES;
  3780. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  3781. dump = ioa_cfg->dump;
  3782. if (ioa_cfg->sdt_state != DUMP_OBTAINED || !dump) {
  3783. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  3784. return 0;
  3785. }
  3786. kref_get(&dump->kref);
  3787. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  3788. if (off > dump->driver_dump.hdr.len) {
  3789. kref_put(&dump->kref, ipr_release_dump);
  3790. return 0;
  3791. }
  3792. if (off + count > dump->driver_dump.hdr.len) {
  3793. count = dump->driver_dump.hdr.len - off;
  3794. rc = count;
  3795. }
  3796. if (count && off < sizeof(dump->driver_dump)) {
  3797. if (off + count > sizeof(dump->driver_dump))
  3798. len = sizeof(dump->driver_dump) - off;
  3799. else
  3800. len = count;
  3801. src = (u8 *)&dump->driver_dump + off;
  3802. memcpy(buf, src, len);
  3803. buf += len;
  3804. off += len;
  3805. count -= len;
  3806. }
  3807. off -= sizeof(dump->driver_dump);
  3808. if (ioa_cfg->sis64)
  3809. sdt_end = offsetof(struct ipr_ioa_dump, sdt.entry) +
  3810. (be32_to_cpu(dump->ioa_dump.sdt.hdr.num_entries_used) *
  3811. sizeof(struct ipr_sdt_entry));
  3812. else
  3813. sdt_end = offsetof(struct ipr_ioa_dump, sdt.entry) +
  3814. (IPR_FMT2_NUM_SDT_ENTRIES * sizeof(struct ipr_sdt_entry));
  3815. if (count && off < sdt_end) {
  3816. if (off + count > sdt_end)
  3817. len = sdt_end - off;
  3818. else
  3819. len = count;
  3820. src = (u8 *)&dump->ioa_dump + off;
  3821. memcpy(buf, src, len);
  3822. buf += len;
  3823. off += len;
  3824. count -= len;
  3825. }
  3826. off -= sdt_end;
  3827. while (count) {
  3828. if ((off & PAGE_MASK) != ((off + count) & PAGE_MASK))
  3829. len = PAGE_ALIGN(off) - off;
  3830. else
  3831. len = count;
  3832. src = (u8 *)dump->ioa_dump.ioa_data[(off & PAGE_MASK) >> PAGE_SHIFT];
  3833. src += off & ~PAGE_MASK;
  3834. memcpy(buf, src, len);
  3835. buf += len;
  3836. off += len;
  3837. count -= len;
  3838. }
  3839. kref_put(&dump->kref, ipr_release_dump);
  3840. return rc;
  3841. }
  3842. /**
  3843. * ipr_alloc_dump - Prepare for adapter dump
  3844. * @ioa_cfg: ioa config struct
  3845. *
  3846. * Return value:
  3847. * 0 on success / other on failure
  3848. **/
  3849. static int ipr_alloc_dump(struct ipr_ioa_cfg *ioa_cfg)
  3850. {
  3851. struct ipr_dump *dump;
  3852. __be32 **ioa_data;
  3853. unsigned long lock_flags = 0;
  3854. dump = kzalloc(sizeof(struct ipr_dump), GFP_KERNEL);
  3855. if (!dump) {
  3856. ipr_err("Dump memory allocation failed\n");
  3857. return -ENOMEM;
  3858. }
  3859. if (ioa_cfg->sis64)
  3860. ioa_data = vmalloc(array_size(IPR_FMT3_MAX_NUM_DUMP_PAGES,
  3861. sizeof(__be32 *)));
  3862. else
  3863. ioa_data = vmalloc(array_size(IPR_FMT2_MAX_NUM_DUMP_PAGES,
  3864. sizeof(__be32 *)));
  3865. if (!ioa_data) {
  3866. ipr_err("Dump memory allocation failed\n");
  3867. kfree(dump);
  3868. return -ENOMEM;
  3869. }
  3870. dump->ioa_dump.ioa_data = ioa_data;
  3871. kref_init(&dump->kref);
  3872. dump->ioa_cfg = ioa_cfg;
  3873. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  3874. if (INACTIVE != ioa_cfg->sdt_state) {
  3875. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  3876. vfree(dump->ioa_dump.ioa_data);
  3877. kfree(dump);
  3878. return 0;
  3879. }
  3880. ioa_cfg->dump = dump;
  3881. ioa_cfg->sdt_state = WAIT_FOR_DUMP;
  3882. if (ioa_cfg->hrrq[IPR_INIT_HRRQ].ioa_is_dead && !ioa_cfg->dump_taken) {
  3883. ioa_cfg->dump_taken = 1;
  3884. schedule_work(&ioa_cfg->work_q);
  3885. }
  3886. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  3887. return 0;
  3888. }
  3889. /**
  3890. * ipr_free_dump - Free adapter dump memory
  3891. * @ioa_cfg: ioa config struct
  3892. *
  3893. * Return value:
  3894. * 0 on success / other on failure
  3895. **/
  3896. static int ipr_free_dump(struct ipr_ioa_cfg *ioa_cfg)
  3897. {
  3898. struct ipr_dump *dump;
  3899. unsigned long lock_flags = 0;
  3900. ENTER;
  3901. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  3902. dump = ioa_cfg->dump;
  3903. if (!dump) {
  3904. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  3905. return 0;
  3906. }
  3907. ioa_cfg->dump = NULL;
  3908. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  3909. kref_put(&dump->kref, ipr_release_dump);
  3910. LEAVE;
  3911. return 0;
  3912. }
  3913. /**
  3914. * ipr_write_dump - Setup dump state of adapter
  3915. * @filp: open sysfs file
  3916. * @kobj: kobject struct
  3917. * @bin_attr: bin_attribute struct
  3918. * @buf: buffer
  3919. * @off: offset
  3920. * @count: buffer size
  3921. *
  3922. * Return value:
  3923. * number of bytes printed to buffer
  3924. **/
  3925. static ssize_t ipr_write_dump(struct file *filp, struct kobject *kobj,
  3926. struct bin_attribute *bin_attr,
  3927. char *buf, loff_t off, size_t count)
  3928. {
  3929. struct device *cdev = container_of(kobj, struct device, kobj);
  3930. struct Scsi_Host *shost = class_to_shost(cdev);
  3931. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
  3932. int rc;
  3933. if (!capable(CAP_SYS_ADMIN))
  3934. return -EACCES;
  3935. if (buf[0] == '1')
  3936. rc = ipr_alloc_dump(ioa_cfg);
  3937. else if (buf[0] == '0')
  3938. rc = ipr_free_dump(ioa_cfg);
  3939. else
  3940. return -EINVAL;
  3941. if (rc)
  3942. return rc;
  3943. else
  3944. return count;
  3945. }
  3946. static struct bin_attribute ipr_dump_attr = {
  3947. .attr = {
  3948. .name = "dump",
  3949. .mode = S_IRUSR | S_IWUSR,
  3950. },
  3951. .size = 0,
  3952. .read = ipr_read_dump,
  3953. .write = ipr_write_dump
  3954. };
  3955. #else
  3956. static int ipr_free_dump(struct ipr_ioa_cfg *ioa_cfg) { return 0; };
  3957. #endif
  3958. /**
  3959. * ipr_change_queue_depth - Change the device's queue depth
  3960. * @sdev: scsi device struct
  3961. * @qdepth: depth to set
  3962. * @reason: calling context
  3963. *
  3964. * Return value:
  3965. * actual depth set
  3966. **/
  3967. static int ipr_change_queue_depth(struct scsi_device *sdev, int qdepth)
  3968. {
  3969. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)sdev->host->hostdata;
  3970. struct ipr_resource_entry *res;
  3971. unsigned long lock_flags = 0;
  3972. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  3973. res = (struct ipr_resource_entry *)sdev->hostdata;
  3974. if (res && ipr_is_gata(res) && qdepth > IPR_MAX_CMD_PER_ATA_LUN)
  3975. qdepth = IPR_MAX_CMD_PER_ATA_LUN;
  3976. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  3977. scsi_change_queue_depth(sdev, qdepth);
  3978. return sdev->queue_depth;
  3979. }
  3980. /**
  3981. * ipr_show_adapter_handle - Show the adapter's resource handle for this device
  3982. * @dev: device struct
  3983. * @attr: device attribute structure
  3984. * @buf: buffer
  3985. *
  3986. * Return value:
  3987. * number of bytes printed to buffer
  3988. **/
  3989. static ssize_t ipr_show_adapter_handle(struct device *dev, struct device_attribute *attr, char *buf)
  3990. {
  3991. struct scsi_device *sdev = to_scsi_device(dev);
  3992. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)sdev->host->hostdata;
  3993. struct ipr_resource_entry *res;
  3994. unsigned long lock_flags = 0;
  3995. ssize_t len = -ENXIO;
  3996. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  3997. res = (struct ipr_resource_entry *)sdev->hostdata;
  3998. if (res)
  3999. len = snprintf(buf, PAGE_SIZE, "%08X\n", res->res_handle);
  4000. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  4001. return len;
  4002. }
  4003. static struct device_attribute ipr_adapter_handle_attr = {
  4004. .attr = {
  4005. .name = "adapter_handle",
  4006. .mode = S_IRUSR,
  4007. },
  4008. .show = ipr_show_adapter_handle
  4009. };
  4010. /**
  4011. * ipr_show_resource_path - Show the resource path or the resource address for
  4012. * this device.
  4013. * @dev: device struct
  4014. * @attr: device attribute structure
  4015. * @buf: buffer
  4016. *
  4017. * Return value:
  4018. * number of bytes printed to buffer
  4019. **/
  4020. static ssize_t ipr_show_resource_path(struct device *dev, struct device_attribute *attr, char *buf)
  4021. {
  4022. struct scsi_device *sdev = to_scsi_device(dev);
  4023. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)sdev->host->hostdata;
  4024. struct ipr_resource_entry *res;
  4025. unsigned long lock_flags = 0;
  4026. ssize_t len = -ENXIO;
  4027. char buffer[IPR_MAX_RES_PATH_LENGTH];
  4028. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  4029. res = (struct ipr_resource_entry *)sdev->hostdata;
  4030. if (res && ioa_cfg->sis64)
  4031. len = snprintf(buf, PAGE_SIZE, "%s\n",
  4032. __ipr_format_res_path(res->res_path, buffer,
  4033. sizeof(buffer)));
  4034. else if (res)
  4035. len = snprintf(buf, PAGE_SIZE, "%d:%d:%d:%d\n", ioa_cfg->host->host_no,
  4036. res->bus, res->target, res->lun);
  4037. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  4038. return len;
  4039. }
  4040. static struct device_attribute ipr_resource_path_attr = {
  4041. .attr = {
  4042. .name = "resource_path",
  4043. .mode = S_IRUGO,
  4044. },
  4045. .show = ipr_show_resource_path
  4046. };
  4047. /**
  4048. * ipr_show_device_id - Show the device_id for this device.
  4049. * @dev: device struct
  4050. * @attr: device attribute structure
  4051. * @buf: buffer
  4052. *
  4053. * Return value:
  4054. * number of bytes printed to buffer
  4055. **/
  4056. static ssize_t ipr_show_device_id(struct device *dev, struct device_attribute *attr, char *buf)
  4057. {
  4058. struct scsi_device *sdev = to_scsi_device(dev);
  4059. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)sdev->host->hostdata;
  4060. struct ipr_resource_entry *res;
  4061. unsigned long lock_flags = 0;
  4062. ssize_t len = -ENXIO;
  4063. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  4064. res = (struct ipr_resource_entry *)sdev->hostdata;
  4065. if (res && ioa_cfg->sis64)
  4066. len = snprintf(buf, PAGE_SIZE, "0x%llx\n", be64_to_cpu(res->dev_id));
  4067. else if (res)
  4068. len = snprintf(buf, PAGE_SIZE, "0x%llx\n", res->lun_wwn);
  4069. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  4070. return len;
  4071. }
  4072. static struct device_attribute ipr_device_id_attr = {
  4073. .attr = {
  4074. .name = "device_id",
  4075. .mode = S_IRUGO,
  4076. },
  4077. .show = ipr_show_device_id
  4078. };
  4079. /**
  4080. * ipr_show_resource_type - Show the resource type for this device.
  4081. * @dev: device struct
  4082. * @attr: device attribute structure
  4083. * @buf: buffer
  4084. *
  4085. * Return value:
  4086. * number of bytes printed to buffer
  4087. **/
  4088. static ssize_t ipr_show_resource_type(struct device *dev, struct device_attribute *attr, char *buf)
  4089. {
  4090. struct scsi_device *sdev = to_scsi_device(dev);
  4091. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)sdev->host->hostdata;
  4092. struct ipr_resource_entry *res;
  4093. unsigned long lock_flags = 0;
  4094. ssize_t len = -ENXIO;
  4095. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  4096. res = (struct ipr_resource_entry *)sdev->hostdata;
  4097. if (res)
  4098. len = snprintf(buf, PAGE_SIZE, "%x\n", res->type);
  4099. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  4100. return len;
  4101. }
  4102. static struct device_attribute ipr_resource_type_attr = {
  4103. .attr = {
  4104. .name = "resource_type",
  4105. .mode = S_IRUGO,
  4106. },
  4107. .show = ipr_show_resource_type
  4108. };
  4109. /**
  4110. * ipr_show_raw_mode - Show the adapter's raw mode
  4111. * @dev: class device struct
  4112. * @buf: buffer
  4113. *
  4114. * Return value:
  4115. * number of bytes printed to buffer
  4116. **/
  4117. static ssize_t ipr_show_raw_mode(struct device *dev,
  4118. struct device_attribute *attr, char *buf)
  4119. {
  4120. struct scsi_device *sdev = to_scsi_device(dev);
  4121. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)sdev->host->hostdata;
  4122. struct ipr_resource_entry *res;
  4123. unsigned long lock_flags = 0;
  4124. ssize_t len;
  4125. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  4126. res = (struct ipr_resource_entry *)sdev->hostdata;
  4127. if (res)
  4128. len = snprintf(buf, PAGE_SIZE, "%d\n", res->raw_mode);
  4129. else
  4130. len = -ENXIO;
  4131. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  4132. return len;
  4133. }
  4134. /**
  4135. * ipr_store_raw_mode - Change the adapter's raw mode
  4136. * @dev: class device struct
  4137. * @buf: buffer
  4138. *
  4139. * Return value:
  4140. * number of bytes printed to buffer
  4141. **/
  4142. static ssize_t ipr_store_raw_mode(struct device *dev,
  4143. struct device_attribute *attr,
  4144. const char *buf, size_t count)
  4145. {
  4146. struct scsi_device *sdev = to_scsi_device(dev);
  4147. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)sdev->host->hostdata;
  4148. struct ipr_resource_entry *res;
  4149. unsigned long lock_flags = 0;
  4150. ssize_t len;
  4151. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  4152. res = (struct ipr_resource_entry *)sdev->hostdata;
  4153. if (res) {
  4154. if (ipr_is_af_dasd_device(res)) {
  4155. res->raw_mode = simple_strtoul(buf, NULL, 10);
  4156. len = strlen(buf);
  4157. if (res->sdev)
  4158. sdev_printk(KERN_INFO, res->sdev, "raw mode is %s\n",
  4159. res->raw_mode ? "enabled" : "disabled");
  4160. } else
  4161. len = -EINVAL;
  4162. } else
  4163. len = -ENXIO;
  4164. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  4165. return len;
  4166. }
  4167. static struct device_attribute ipr_raw_mode_attr = {
  4168. .attr = {
  4169. .name = "raw_mode",
  4170. .mode = S_IRUGO | S_IWUSR,
  4171. },
  4172. .show = ipr_show_raw_mode,
  4173. .store = ipr_store_raw_mode
  4174. };
  4175. static struct device_attribute *ipr_dev_attrs[] = {
  4176. &ipr_adapter_handle_attr,
  4177. &ipr_resource_path_attr,
  4178. &ipr_device_id_attr,
  4179. &ipr_resource_type_attr,
  4180. &ipr_raw_mode_attr,
  4181. NULL,
  4182. };
  4183. /**
  4184. * ipr_biosparam - Return the HSC mapping
  4185. * @sdev: scsi device struct
  4186. * @block_device: block device pointer
  4187. * @capacity: capacity of the device
  4188. * @parm: Array containing returned HSC values.
  4189. *
  4190. * This function generates the HSC parms that fdisk uses.
  4191. * We want to make sure we return something that places partitions
  4192. * on 4k boundaries for best performance with the IOA.
  4193. *
  4194. * Return value:
  4195. * 0 on success
  4196. **/
  4197. static int ipr_biosparam(struct scsi_device *sdev,
  4198. struct block_device *block_device,
  4199. sector_t capacity, int *parm)
  4200. {
  4201. int heads, sectors;
  4202. sector_t cylinders;
  4203. heads = 128;
  4204. sectors = 32;
  4205. cylinders = capacity;
  4206. sector_div(cylinders, (128 * 32));
  4207. /* return result */
  4208. parm[0] = heads;
  4209. parm[1] = sectors;
  4210. parm[2] = cylinders;
  4211. return 0;
  4212. }
  4213. /**
  4214. * ipr_find_starget - Find target based on bus/target.
  4215. * @starget: scsi target struct
  4216. *
  4217. * Return value:
  4218. * resource entry pointer if found / NULL if not found
  4219. **/
  4220. static struct ipr_resource_entry *ipr_find_starget(struct scsi_target *starget)
  4221. {
  4222. struct Scsi_Host *shost = dev_to_shost(&starget->dev);
  4223. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *) shost->hostdata;
  4224. struct ipr_resource_entry *res;
  4225. list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
  4226. if ((res->bus == starget->channel) &&
  4227. (res->target == starget->id)) {
  4228. return res;
  4229. }
  4230. }
  4231. return NULL;
  4232. }
  4233. static struct ata_port_info sata_port_info;
  4234. /**
  4235. * ipr_target_alloc - Prepare for commands to a SCSI target
  4236. * @starget: scsi target struct
  4237. *
  4238. * If the device is a SATA device, this function allocates an
  4239. * ATA port with libata, else it does nothing.
  4240. *
  4241. * Return value:
  4242. * 0 on success / non-0 on failure
  4243. **/
  4244. static int ipr_target_alloc(struct scsi_target *starget)
  4245. {
  4246. struct Scsi_Host *shost = dev_to_shost(&starget->dev);
  4247. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *) shost->hostdata;
  4248. struct ipr_sata_port *sata_port;
  4249. struct ata_port *ap;
  4250. struct ipr_resource_entry *res;
  4251. unsigned long lock_flags;
  4252. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  4253. res = ipr_find_starget(starget);
  4254. starget->hostdata = NULL;
  4255. if (res && ipr_is_gata(res)) {
  4256. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  4257. sata_port = kzalloc(sizeof(*sata_port), GFP_KERNEL);
  4258. if (!sata_port)
  4259. return -ENOMEM;
  4260. ap = ata_sas_port_alloc(&ioa_cfg->ata_host, &sata_port_info, shost);
  4261. if (ap) {
  4262. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  4263. sata_port->ioa_cfg = ioa_cfg;
  4264. sata_port->ap = ap;
  4265. sata_port->res = res;
  4266. res->sata_port = sata_port;
  4267. ap->private_data = sata_port;
  4268. starget->hostdata = sata_port;
  4269. } else {
  4270. kfree(sata_port);
  4271. return -ENOMEM;
  4272. }
  4273. }
  4274. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  4275. return 0;
  4276. }
  4277. /**
  4278. * ipr_target_destroy - Destroy a SCSI target
  4279. * @starget: scsi target struct
  4280. *
  4281. * If the device was a SATA device, this function frees the libata
  4282. * ATA port, else it does nothing.
  4283. *
  4284. **/
  4285. static void ipr_target_destroy(struct scsi_target *starget)
  4286. {
  4287. struct ipr_sata_port *sata_port = starget->hostdata;
  4288. struct Scsi_Host *shost = dev_to_shost(&starget->dev);
  4289. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *) shost->hostdata;
  4290. if (ioa_cfg->sis64) {
  4291. if (!ipr_find_starget(starget)) {
  4292. if (starget->channel == IPR_ARRAY_VIRTUAL_BUS)
  4293. clear_bit(starget->id, ioa_cfg->array_ids);
  4294. else if (starget->channel == IPR_VSET_VIRTUAL_BUS)
  4295. clear_bit(starget->id, ioa_cfg->vset_ids);
  4296. else if (starget->channel == 0)
  4297. clear_bit(starget->id, ioa_cfg->target_ids);
  4298. }
  4299. }
  4300. if (sata_port) {
  4301. starget->hostdata = NULL;
  4302. ata_sas_port_destroy(sata_port->ap);
  4303. kfree(sata_port);
  4304. }
  4305. }
  4306. /**
  4307. * ipr_find_sdev - Find device based on bus/target/lun.
  4308. * @sdev: scsi device struct
  4309. *
  4310. * Return value:
  4311. * resource entry pointer if found / NULL if not found
  4312. **/
  4313. static struct ipr_resource_entry *ipr_find_sdev(struct scsi_device *sdev)
  4314. {
  4315. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *) sdev->host->hostdata;
  4316. struct ipr_resource_entry *res;
  4317. list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
  4318. if ((res->bus == sdev->channel) &&
  4319. (res->target == sdev->id) &&
  4320. (res->lun == sdev->lun))
  4321. return res;
  4322. }
  4323. return NULL;
  4324. }
  4325. /**
  4326. * ipr_slave_destroy - Unconfigure a SCSI device
  4327. * @sdev: scsi device struct
  4328. *
  4329. * Return value:
  4330. * nothing
  4331. **/
  4332. static void ipr_slave_destroy(struct scsi_device *sdev)
  4333. {
  4334. struct ipr_resource_entry *res;
  4335. struct ipr_ioa_cfg *ioa_cfg;
  4336. unsigned long lock_flags = 0;
  4337. ioa_cfg = (struct ipr_ioa_cfg *) sdev->host->hostdata;
  4338. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  4339. res = (struct ipr_resource_entry *) sdev->hostdata;
  4340. if (res) {
  4341. if (res->sata_port)
  4342. res->sata_port->ap->link.device[0].class = ATA_DEV_NONE;
  4343. sdev->hostdata = NULL;
  4344. res->sdev = NULL;
  4345. res->sata_port = NULL;
  4346. }
  4347. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  4348. }
  4349. /**
  4350. * ipr_slave_configure - Configure a SCSI device
  4351. * @sdev: scsi device struct
  4352. *
  4353. * This function configures the specified scsi device.
  4354. *
  4355. * Return value:
  4356. * 0 on success
  4357. **/
  4358. static int ipr_slave_configure(struct scsi_device *sdev)
  4359. {
  4360. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *) sdev->host->hostdata;
  4361. struct ipr_resource_entry *res;
  4362. struct ata_port *ap = NULL;
  4363. unsigned long lock_flags = 0;
  4364. char buffer[IPR_MAX_RES_PATH_LENGTH];
  4365. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  4366. res = sdev->hostdata;
  4367. if (res) {
  4368. if (ipr_is_af_dasd_device(res))
  4369. sdev->type = TYPE_RAID;
  4370. if (ipr_is_af_dasd_device(res) || ipr_is_ioa_resource(res)) {
  4371. sdev->scsi_level = 4;
  4372. sdev->no_uld_attach = 1;
  4373. }
  4374. if (ipr_is_vset_device(res)) {
  4375. sdev->scsi_level = SCSI_SPC_3;
  4376. sdev->no_report_opcodes = 1;
  4377. blk_queue_rq_timeout(sdev->request_queue,
  4378. IPR_VSET_RW_TIMEOUT);
  4379. blk_queue_max_hw_sectors(sdev->request_queue, IPR_VSET_MAX_SECTORS);
  4380. }
  4381. if (ipr_is_gata(res) && res->sata_port)
  4382. ap = res->sata_port->ap;
  4383. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  4384. if (ap) {
  4385. scsi_change_queue_depth(sdev, IPR_MAX_CMD_PER_ATA_LUN);
  4386. ata_sas_slave_configure(sdev, ap);
  4387. }
  4388. if (ioa_cfg->sis64)
  4389. sdev_printk(KERN_INFO, sdev, "Resource path: %s\n",
  4390. ipr_format_res_path(ioa_cfg,
  4391. res->res_path, buffer, sizeof(buffer)));
  4392. return 0;
  4393. }
  4394. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  4395. return 0;
  4396. }
  4397. /**
  4398. * ipr_ata_slave_alloc - Prepare for commands to a SATA device
  4399. * @sdev: scsi device struct
  4400. *
  4401. * This function initializes an ATA port so that future commands
  4402. * sent through queuecommand will work.
  4403. *
  4404. * Return value:
  4405. * 0 on success
  4406. **/
  4407. static int ipr_ata_slave_alloc(struct scsi_device *sdev)
  4408. {
  4409. struct ipr_sata_port *sata_port = NULL;
  4410. int rc = -ENXIO;
  4411. ENTER;
  4412. if (sdev->sdev_target)
  4413. sata_port = sdev->sdev_target->hostdata;
  4414. if (sata_port) {
  4415. rc = ata_sas_port_init(sata_port->ap);
  4416. if (rc == 0)
  4417. rc = ata_sas_sync_probe(sata_port->ap);
  4418. }
  4419. if (rc)
  4420. ipr_slave_destroy(sdev);
  4421. LEAVE;
  4422. return rc;
  4423. }
  4424. /**
  4425. * ipr_slave_alloc - Prepare for commands to a device.
  4426. * @sdev: scsi device struct
  4427. *
  4428. * This function saves a pointer to the resource entry
  4429. * in the scsi device struct if the device exists. We
  4430. * can then use this pointer in ipr_queuecommand when
  4431. * handling new commands.
  4432. *
  4433. * Return value:
  4434. * 0 on success / -ENXIO if device does not exist
  4435. **/
  4436. static int ipr_slave_alloc(struct scsi_device *sdev)
  4437. {
  4438. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *) sdev->host->hostdata;
  4439. struct ipr_resource_entry *res;
  4440. unsigned long lock_flags;
  4441. int rc = -ENXIO;
  4442. sdev->hostdata = NULL;
  4443. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  4444. res = ipr_find_sdev(sdev);
  4445. if (res) {
  4446. res->sdev = sdev;
  4447. res->add_to_ml = 0;
  4448. res->in_erp = 0;
  4449. sdev->hostdata = res;
  4450. if (!ipr_is_naca_model(res))
  4451. res->needs_sync_complete = 1;
  4452. rc = 0;
  4453. if (ipr_is_gata(res)) {
  4454. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  4455. return ipr_ata_slave_alloc(sdev);
  4456. }
  4457. }
  4458. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  4459. return rc;
  4460. }
  4461. /**
  4462. * ipr_match_lun - Match function for specified LUN
  4463. * @ipr_cmd: ipr command struct
  4464. * @device: device to match (sdev)
  4465. *
  4466. * Returns:
  4467. * 1 if command matches sdev / 0 if command does not match sdev
  4468. **/
  4469. static int ipr_match_lun(struct ipr_cmnd *ipr_cmd, void *device)
  4470. {
  4471. if (ipr_cmd->scsi_cmd && ipr_cmd->scsi_cmd->device == device)
  4472. return 1;
  4473. return 0;
  4474. }
  4475. /**
  4476. * ipr_cmnd_is_free - Check if a command is free or not
  4477. * @ipr_cmd ipr command struct
  4478. *
  4479. * Returns:
  4480. * true / false
  4481. **/
  4482. static bool ipr_cmnd_is_free(struct ipr_cmnd *ipr_cmd)
  4483. {
  4484. struct ipr_cmnd *loop_cmd;
  4485. list_for_each_entry(loop_cmd, &ipr_cmd->hrrq->hrrq_free_q, queue) {
  4486. if (loop_cmd == ipr_cmd)
  4487. return true;
  4488. }
  4489. return false;
  4490. }
  4491. /**
  4492. * ipr_match_res - Match function for specified resource entry
  4493. * @ipr_cmd: ipr command struct
  4494. * @resource: resource entry to match
  4495. *
  4496. * Returns:
  4497. * 1 if command matches sdev / 0 if command does not match sdev
  4498. **/
  4499. static int ipr_match_res(struct ipr_cmnd *ipr_cmd, void *resource)
  4500. {
  4501. struct ipr_resource_entry *res = resource;
  4502. if (res && ipr_cmd->ioarcb.res_handle == res->res_handle)
  4503. return 1;
  4504. return 0;
  4505. }
  4506. /**
  4507. * ipr_wait_for_ops - Wait for matching commands to complete
  4508. * @ipr_cmd: ipr command struct
  4509. * @device: device to match (sdev)
  4510. * @match: match function to use
  4511. *
  4512. * Returns:
  4513. * SUCCESS / FAILED
  4514. **/
  4515. static int ipr_wait_for_ops(struct ipr_ioa_cfg *ioa_cfg, void *device,
  4516. int (*match)(struct ipr_cmnd *, void *))
  4517. {
  4518. struct ipr_cmnd *ipr_cmd;
  4519. int wait, i;
  4520. unsigned long flags;
  4521. struct ipr_hrr_queue *hrrq;
  4522. signed long timeout = IPR_ABORT_TASK_TIMEOUT;
  4523. DECLARE_COMPLETION_ONSTACK(comp);
  4524. ENTER;
  4525. do {
  4526. wait = 0;
  4527. for_each_hrrq(hrrq, ioa_cfg) {
  4528. spin_lock_irqsave(hrrq->lock, flags);
  4529. for (i = hrrq->min_cmd_id; i <= hrrq->max_cmd_id; i++) {
  4530. ipr_cmd = ioa_cfg->ipr_cmnd_list[i];
  4531. if (!ipr_cmnd_is_free(ipr_cmd)) {
  4532. if (match(ipr_cmd, device)) {
  4533. ipr_cmd->eh_comp = &comp;
  4534. wait++;
  4535. }
  4536. }
  4537. }
  4538. spin_unlock_irqrestore(hrrq->lock, flags);
  4539. }
  4540. if (wait) {
  4541. timeout = wait_for_completion_timeout(&comp, timeout);
  4542. if (!timeout) {
  4543. wait = 0;
  4544. for_each_hrrq(hrrq, ioa_cfg) {
  4545. spin_lock_irqsave(hrrq->lock, flags);
  4546. for (i = hrrq->min_cmd_id; i <= hrrq->max_cmd_id; i++) {
  4547. ipr_cmd = ioa_cfg->ipr_cmnd_list[i];
  4548. if (!ipr_cmnd_is_free(ipr_cmd)) {
  4549. if (match(ipr_cmd, device)) {
  4550. ipr_cmd->eh_comp = NULL;
  4551. wait++;
  4552. }
  4553. }
  4554. }
  4555. spin_unlock_irqrestore(hrrq->lock, flags);
  4556. }
  4557. if (wait)
  4558. dev_err(&ioa_cfg->pdev->dev, "Timed out waiting for aborted commands\n");
  4559. LEAVE;
  4560. return wait ? FAILED : SUCCESS;
  4561. }
  4562. }
  4563. } while (wait);
  4564. LEAVE;
  4565. return SUCCESS;
  4566. }
  4567. static int ipr_eh_host_reset(struct scsi_cmnd *cmd)
  4568. {
  4569. struct ipr_ioa_cfg *ioa_cfg;
  4570. unsigned long lock_flags = 0;
  4571. int rc = SUCCESS;
  4572. ENTER;
  4573. ioa_cfg = (struct ipr_ioa_cfg *) cmd->device->host->hostdata;
  4574. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  4575. if (!ioa_cfg->in_reset_reload && !ioa_cfg->hrrq[IPR_INIT_HRRQ].ioa_is_dead) {
  4576. ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_ABBREV);
  4577. dev_err(&ioa_cfg->pdev->dev,
  4578. "Adapter being reset as a result of error recovery.\n");
  4579. if (WAIT_FOR_DUMP == ioa_cfg->sdt_state)
  4580. ioa_cfg->sdt_state = GET_DUMP;
  4581. }
  4582. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  4583. wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
  4584. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  4585. /* If we got hit with a host reset while we were already resetting
  4586. the adapter for some reason, and the reset failed. */
  4587. if (ioa_cfg->hrrq[IPR_INIT_HRRQ].ioa_is_dead) {
  4588. ipr_trace;
  4589. rc = FAILED;
  4590. }
  4591. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  4592. LEAVE;
  4593. return rc;
  4594. }
  4595. /**
  4596. * ipr_device_reset - Reset the device
  4597. * @ioa_cfg: ioa config struct
  4598. * @res: resource entry struct
  4599. *
  4600. * This function issues a device reset to the affected device.
  4601. * If the device is a SCSI device, a LUN reset will be sent
  4602. * to the device first. If that does not work, a target reset
  4603. * will be sent. If the device is a SATA device, a PHY reset will
  4604. * be sent.
  4605. *
  4606. * Return value:
  4607. * 0 on success / non-zero on failure
  4608. **/
  4609. static int ipr_device_reset(struct ipr_ioa_cfg *ioa_cfg,
  4610. struct ipr_resource_entry *res)
  4611. {
  4612. struct ipr_cmnd *ipr_cmd;
  4613. struct ipr_ioarcb *ioarcb;
  4614. struct ipr_cmd_pkt *cmd_pkt;
  4615. struct ipr_ioarcb_ata_regs *regs;
  4616. u32 ioasc;
  4617. ENTER;
  4618. ipr_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
  4619. ioarcb = &ipr_cmd->ioarcb;
  4620. cmd_pkt = &ioarcb->cmd_pkt;
  4621. if (ipr_cmd->ioa_cfg->sis64) {
  4622. regs = &ipr_cmd->i.ata_ioadl.regs;
  4623. ioarcb->add_cmd_parms_offset = cpu_to_be16(sizeof(*ioarcb));
  4624. } else
  4625. regs = &ioarcb->u.add_data.u.regs;
  4626. ioarcb->res_handle = res->res_handle;
  4627. cmd_pkt->request_type = IPR_RQTYPE_IOACMD;
  4628. cmd_pkt->cdb[0] = IPR_RESET_DEVICE;
  4629. if (ipr_is_gata(res)) {
  4630. cmd_pkt->cdb[2] = IPR_ATA_PHY_RESET;
  4631. ioarcb->add_cmd_parms_len = cpu_to_be16(sizeof(regs->flags));
  4632. regs->flags |= IPR_ATA_FLAG_STATUS_ON_GOOD_COMPLETION;
  4633. }
  4634. ipr_send_blocking_cmd(ipr_cmd, ipr_timeout, IPR_DEVICE_RESET_TIMEOUT);
  4635. ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
  4636. list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_free_q);
  4637. if (ipr_is_gata(res) && res->sata_port && ioasc != IPR_IOASC_IOA_WAS_RESET) {
  4638. if (ipr_cmd->ioa_cfg->sis64)
  4639. memcpy(&res->sata_port->ioasa, &ipr_cmd->s.ioasa64.u.gata,
  4640. sizeof(struct ipr_ioasa_gata));
  4641. else
  4642. memcpy(&res->sata_port->ioasa, &ipr_cmd->s.ioasa.u.gata,
  4643. sizeof(struct ipr_ioasa_gata));
  4644. }
  4645. LEAVE;
  4646. return IPR_IOASC_SENSE_KEY(ioasc) ? -EIO : 0;
  4647. }
  4648. /**
  4649. * ipr_sata_reset - Reset the SATA port
  4650. * @link: SATA link to reset
  4651. * @classes: class of the attached device
  4652. *
  4653. * This function issues a SATA phy reset to the affected ATA link.
  4654. *
  4655. * Return value:
  4656. * 0 on success / non-zero on failure
  4657. **/
  4658. static int ipr_sata_reset(struct ata_link *link, unsigned int *classes,
  4659. unsigned long deadline)
  4660. {
  4661. struct ipr_sata_port *sata_port = link->ap->private_data;
  4662. struct ipr_ioa_cfg *ioa_cfg = sata_port->ioa_cfg;
  4663. struct ipr_resource_entry *res;
  4664. unsigned long lock_flags = 0;
  4665. int rc = -ENXIO, ret;
  4666. ENTER;
  4667. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  4668. while (ioa_cfg->in_reset_reload) {
  4669. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  4670. wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
  4671. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  4672. }
  4673. res = sata_port->res;
  4674. if (res) {
  4675. rc = ipr_device_reset(ioa_cfg, res);
  4676. *classes = res->ata_class;
  4677. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  4678. ret = ipr_wait_for_ops(ioa_cfg, res, ipr_match_res);
  4679. if (ret != SUCCESS) {
  4680. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  4681. ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_ABBREV);
  4682. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  4683. wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
  4684. }
  4685. } else
  4686. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  4687. LEAVE;
  4688. return rc;
  4689. }
  4690. /**
  4691. * ipr_eh_dev_reset - Reset the device
  4692. * @scsi_cmd: scsi command struct
  4693. *
  4694. * This function issues a device reset to the affected device.
  4695. * A LUN reset will be sent to the device first. If that does
  4696. * not work, a target reset will be sent.
  4697. *
  4698. * Return value:
  4699. * SUCCESS / FAILED
  4700. **/
  4701. static int __ipr_eh_dev_reset(struct scsi_cmnd *scsi_cmd)
  4702. {
  4703. struct ipr_cmnd *ipr_cmd;
  4704. struct ipr_ioa_cfg *ioa_cfg;
  4705. struct ipr_resource_entry *res;
  4706. struct ata_port *ap;
  4707. int rc = 0, i;
  4708. struct ipr_hrr_queue *hrrq;
  4709. ENTER;
  4710. ioa_cfg = (struct ipr_ioa_cfg *) scsi_cmd->device->host->hostdata;
  4711. res = scsi_cmd->device->hostdata;
  4712. /*
  4713. * If we are currently going through reset/reload, return failed. This will force the
  4714. * mid-layer to call ipr_eh_host_reset, which will then go to sleep and wait for the
  4715. * reset to complete
  4716. */
  4717. if (ioa_cfg->in_reset_reload)
  4718. return FAILED;
  4719. if (ioa_cfg->hrrq[IPR_INIT_HRRQ].ioa_is_dead)
  4720. return FAILED;
  4721. for_each_hrrq(hrrq, ioa_cfg) {
  4722. spin_lock(&hrrq->_lock);
  4723. for (i = hrrq->min_cmd_id; i <= hrrq->max_cmd_id; i++) {
  4724. ipr_cmd = ioa_cfg->ipr_cmnd_list[i];
  4725. if (ipr_cmd->ioarcb.res_handle == res->res_handle) {
  4726. if (!ipr_cmd->qc)
  4727. continue;
  4728. if (ipr_cmnd_is_free(ipr_cmd))
  4729. continue;
  4730. ipr_cmd->done = ipr_sata_eh_done;
  4731. if (!(ipr_cmd->qc->flags & ATA_QCFLAG_FAILED)) {
  4732. ipr_cmd->qc->err_mask |= AC_ERR_TIMEOUT;
  4733. ipr_cmd->qc->flags |= ATA_QCFLAG_FAILED;
  4734. }
  4735. }
  4736. }
  4737. spin_unlock(&hrrq->_lock);
  4738. }
  4739. res->resetting_device = 1;
  4740. scmd_printk(KERN_ERR, scsi_cmd, "Resetting device\n");
  4741. if (ipr_is_gata(res) && res->sata_port) {
  4742. ap = res->sata_port->ap;
  4743. spin_unlock_irq(scsi_cmd->device->host->host_lock);
  4744. ata_std_error_handler(ap);
  4745. spin_lock_irq(scsi_cmd->device->host->host_lock);
  4746. } else
  4747. rc = ipr_device_reset(ioa_cfg, res);
  4748. res->resetting_device = 0;
  4749. res->reset_occurred = 1;
  4750. LEAVE;
  4751. return rc ? FAILED : SUCCESS;
  4752. }
  4753. static int ipr_eh_dev_reset(struct scsi_cmnd *cmd)
  4754. {
  4755. int rc;
  4756. struct ipr_ioa_cfg *ioa_cfg;
  4757. struct ipr_resource_entry *res;
  4758. ioa_cfg = (struct ipr_ioa_cfg *) cmd->device->host->hostdata;
  4759. res = cmd->device->hostdata;
  4760. if (!res)
  4761. return FAILED;
  4762. spin_lock_irq(cmd->device->host->host_lock);
  4763. rc = __ipr_eh_dev_reset(cmd);
  4764. spin_unlock_irq(cmd->device->host->host_lock);
  4765. if (rc == SUCCESS) {
  4766. if (ipr_is_gata(res) && res->sata_port)
  4767. rc = ipr_wait_for_ops(ioa_cfg, res, ipr_match_res);
  4768. else
  4769. rc = ipr_wait_for_ops(ioa_cfg, cmd->device, ipr_match_lun);
  4770. }
  4771. return rc;
  4772. }
  4773. /**
  4774. * ipr_bus_reset_done - Op done function for bus reset.
  4775. * @ipr_cmd: ipr command struct
  4776. *
  4777. * This function is the op done function for a bus reset
  4778. *
  4779. * Return value:
  4780. * none
  4781. **/
  4782. static void ipr_bus_reset_done(struct ipr_cmnd *ipr_cmd)
  4783. {
  4784. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  4785. struct ipr_resource_entry *res;
  4786. ENTER;
  4787. if (!ioa_cfg->sis64)
  4788. list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
  4789. if (res->res_handle == ipr_cmd->ioarcb.res_handle) {
  4790. scsi_report_bus_reset(ioa_cfg->host, res->bus);
  4791. break;
  4792. }
  4793. }
  4794. /*
  4795. * If abort has not completed, indicate the reset has, else call the
  4796. * abort's done function to wake the sleeping eh thread
  4797. */
  4798. if (ipr_cmd->sibling->sibling)
  4799. ipr_cmd->sibling->sibling = NULL;
  4800. else
  4801. ipr_cmd->sibling->done(ipr_cmd->sibling);
  4802. list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_free_q);
  4803. LEAVE;
  4804. }
  4805. /**
  4806. * ipr_abort_timeout - An abort task has timed out
  4807. * @ipr_cmd: ipr command struct
  4808. *
  4809. * This function handles when an abort task times out. If this
  4810. * happens we issue a bus reset since we have resources tied
  4811. * up that must be freed before returning to the midlayer.
  4812. *
  4813. * Return value:
  4814. * none
  4815. **/
  4816. static void ipr_abort_timeout(struct timer_list *t)
  4817. {
  4818. struct ipr_cmnd *ipr_cmd = from_timer(ipr_cmd, t, timer);
  4819. struct ipr_cmnd *reset_cmd;
  4820. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  4821. struct ipr_cmd_pkt *cmd_pkt;
  4822. unsigned long lock_flags = 0;
  4823. ENTER;
  4824. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  4825. if (ipr_cmd->completion.done || ioa_cfg->in_reset_reload) {
  4826. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  4827. return;
  4828. }
  4829. sdev_printk(KERN_ERR, ipr_cmd->u.sdev, "Abort timed out. Resetting bus.\n");
  4830. reset_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
  4831. ipr_cmd->sibling = reset_cmd;
  4832. reset_cmd->sibling = ipr_cmd;
  4833. reset_cmd->ioarcb.res_handle = ipr_cmd->ioarcb.res_handle;
  4834. cmd_pkt = &reset_cmd->ioarcb.cmd_pkt;
  4835. cmd_pkt->request_type = IPR_RQTYPE_IOACMD;
  4836. cmd_pkt->cdb[0] = IPR_RESET_DEVICE;
  4837. cmd_pkt->cdb[2] = IPR_RESET_TYPE_SELECT | IPR_BUS_RESET;
  4838. ipr_do_req(reset_cmd, ipr_bus_reset_done, ipr_timeout, IPR_DEVICE_RESET_TIMEOUT);
  4839. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  4840. LEAVE;
  4841. }
  4842. /**
  4843. * ipr_cancel_op - Cancel specified op
  4844. * @scsi_cmd: scsi command struct
  4845. *
  4846. * This function cancels specified op.
  4847. *
  4848. * Return value:
  4849. * SUCCESS / FAILED
  4850. **/
  4851. static int ipr_cancel_op(struct scsi_cmnd *scsi_cmd)
  4852. {
  4853. struct ipr_cmnd *ipr_cmd;
  4854. struct ipr_ioa_cfg *ioa_cfg;
  4855. struct ipr_resource_entry *res;
  4856. struct ipr_cmd_pkt *cmd_pkt;
  4857. u32 ioasc, int_reg;
  4858. int i, op_found = 0;
  4859. struct ipr_hrr_queue *hrrq;
  4860. ENTER;
  4861. ioa_cfg = (struct ipr_ioa_cfg *)scsi_cmd->device->host->hostdata;
  4862. res = scsi_cmd->device->hostdata;
  4863. /* If we are currently going through reset/reload, return failed.
  4864. * This will force the mid-layer to call ipr_eh_host_reset,
  4865. * which will then go to sleep and wait for the reset to complete
  4866. */
  4867. if (ioa_cfg->in_reset_reload ||
  4868. ioa_cfg->hrrq[IPR_INIT_HRRQ].ioa_is_dead)
  4869. return FAILED;
  4870. if (!res)
  4871. return FAILED;
  4872. /*
  4873. * If we are aborting a timed out op, chances are that the timeout was caused
  4874. * by a still not detected EEH error. In such cases, reading a register will
  4875. * trigger the EEH recovery infrastructure.
  4876. */
  4877. int_reg = readl(ioa_cfg->regs.sense_interrupt_reg);
  4878. if (!ipr_is_gscsi(res))
  4879. return FAILED;
  4880. for_each_hrrq(hrrq, ioa_cfg) {
  4881. spin_lock(&hrrq->_lock);
  4882. for (i = hrrq->min_cmd_id; i <= hrrq->max_cmd_id; i++) {
  4883. if (ioa_cfg->ipr_cmnd_list[i]->scsi_cmd == scsi_cmd) {
  4884. if (!ipr_cmnd_is_free(ioa_cfg->ipr_cmnd_list[i])) {
  4885. op_found = 1;
  4886. break;
  4887. }
  4888. }
  4889. }
  4890. spin_unlock(&hrrq->_lock);
  4891. }
  4892. if (!op_found)
  4893. return SUCCESS;
  4894. ipr_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
  4895. ipr_cmd->ioarcb.res_handle = res->res_handle;
  4896. cmd_pkt = &ipr_cmd->ioarcb.cmd_pkt;
  4897. cmd_pkt->request_type = IPR_RQTYPE_IOACMD;
  4898. cmd_pkt->cdb[0] = IPR_CANCEL_ALL_REQUESTS;
  4899. ipr_cmd->u.sdev = scsi_cmd->device;
  4900. scmd_printk(KERN_ERR, scsi_cmd, "Aborting command: %02X\n",
  4901. scsi_cmd->cmnd[0]);
  4902. ipr_send_blocking_cmd(ipr_cmd, ipr_abort_timeout, IPR_CANCEL_ALL_TIMEOUT);
  4903. ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
  4904. /*
  4905. * If the abort task timed out and we sent a bus reset, we will get
  4906. * one the following responses to the abort
  4907. */
  4908. if (ioasc == IPR_IOASC_BUS_WAS_RESET || ioasc == IPR_IOASC_SYNC_REQUIRED) {
  4909. ioasc = 0;
  4910. ipr_trace;
  4911. }
  4912. list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_free_q);
  4913. if (!ipr_is_naca_model(res))
  4914. res->needs_sync_complete = 1;
  4915. LEAVE;
  4916. return IPR_IOASC_SENSE_KEY(ioasc) ? FAILED : SUCCESS;
  4917. }
  4918. /**
  4919. * ipr_eh_abort - Abort a single op
  4920. * @scsi_cmd: scsi command struct
  4921. *
  4922. * Return value:
  4923. * 0 if scan in progress / 1 if scan is complete
  4924. **/
  4925. static int ipr_scan_finished(struct Scsi_Host *shost, unsigned long elapsed_time)
  4926. {
  4927. unsigned long lock_flags;
  4928. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *) shost->hostdata;
  4929. int rc = 0;
  4930. spin_lock_irqsave(shost->host_lock, lock_flags);
  4931. if (ioa_cfg->hrrq[IPR_INIT_HRRQ].ioa_is_dead || ioa_cfg->scan_done)
  4932. rc = 1;
  4933. if ((elapsed_time/HZ) > (ioa_cfg->transop_timeout * 2))
  4934. rc = 1;
  4935. spin_unlock_irqrestore(shost->host_lock, lock_flags);
  4936. return rc;
  4937. }
  4938. /**
  4939. * ipr_eh_host_reset - Reset the host adapter
  4940. * @scsi_cmd: scsi command struct
  4941. *
  4942. * Return value:
  4943. * SUCCESS / FAILED
  4944. **/
  4945. static int ipr_eh_abort(struct scsi_cmnd *scsi_cmd)
  4946. {
  4947. unsigned long flags;
  4948. int rc;
  4949. struct ipr_ioa_cfg *ioa_cfg;
  4950. ENTER;
  4951. ioa_cfg = (struct ipr_ioa_cfg *) scsi_cmd->device->host->hostdata;
  4952. spin_lock_irqsave(scsi_cmd->device->host->host_lock, flags);
  4953. rc = ipr_cancel_op(scsi_cmd);
  4954. spin_unlock_irqrestore(scsi_cmd->device->host->host_lock, flags);
  4955. if (rc == SUCCESS)
  4956. rc = ipr_wait_for_ops(ioa_cfg, scsi_cmd->device, ipr_match_lun);
  4957. LEAVE;
  4958. return rc;
  4959. }
  4960. /**
  4961. * ipr_handle_other_interrupt - Handle "other" interrupts
  4962. * @ioa_cfg: ioa config struct
  4963. * @int_reg: interrupt register
  4964. *
  4965. * Return value:
  4966. * IRQ_NONE / IRQ_HANDLED
  4967. **/
  4968. static irqreturn_t ipr_handle_other_interrupt(struct ipr_ioa_cfg *ioa_cfg,
  4969. u32 int_reg)
  4970. {
  4971. irqreturn_t rc = IRQ_HANDLED;
  4972. u32 int_mask_reg;
  4973. int_mask_reg = readl(ioa_cfg->regs.sense_interrupt_mask_reg32);
  4974. int_reg &= ~int_mask_reg;
  4975. /* If an interrupt on the adapter did not occur, ignore it.
  4976. * Or in the case of SIS 64, check for a stage change interrupt.
  4977. */
  4978. if ((int_reg & IPR_PCII_OPER_INTERRUPTS) == 0) {
  4979. if (ioa_cfg->sis64) {
  4980. int_mask_reg = readl(ioa_cfg->regs.sense_interrupt_mask_reg);
  4981. int_reg = readl(ioa_cfg->regs.sense_interrupt_reg) & ~int_mask_reg;
  4982. if (int_reg & IPR_PCII_IPL_STAGE_CHANGE) {
  4983. /* clear stage change */
  4984. writel(IPR_PCII_IPL_STAGE_CHANGE, ioa_cfg->regs.clr_interrupt_reg);
  4985. int_reg = readl(ioa_cfg->regs.sense_interrupt_reg) & ~int_mask_reg;
  4986. list_del(&ioa_cfg->reset_cmd->queue);
  4987. del_timer(&ioa_cfg->reset_cmd->timer);
  4988. ipr_reset_ioa_job(ioa_cfg->reset_cmd);
  4989. return IRQ_HANDLED;
  4990. }
  4991. }
  4992. return IRQ_NONE;
  4993. }
  4994. if (int_reg & IPR_PCII_IOA_TRANS_TO_OPER) {
  4995. /* Mask the interrupt */
  4996. writel(IPR_PCII_IOA_TRANS_TO_OPER, ioa_cfg->regs.set_interrupt_mask_reg);
  4997. int_reg = readl(ioa_cfg->regs.sense_interrupt_reg);
  4998. list_del(&ioa_cfg->reset_cmd->queue);
  4999. del_timer(&ioa_cfg->reset_cmd->timer);
  5000. ipr_reset_ioa_job(ioa_cfg->reset_cmd);
  5001. } else if ((int_reg & IPR_PCII_HRRQ_UPDATED) == int_reg) {
  5002. if (ioa_cfg->clear_isr) {
  5003. if (ipr_debug && printk_ratelimit())
  5004. dev_err(&ioa_cfg->pdev->dev,
  5005. "Spurious interrupt detected. 0x%08X\n", int_reg);
  5006. writel(IPR_PCII_HRRQ_UPDATED, ioa_cfg->regs.clr_interrupt_reg32);
  5007. int_reg = readl(ioa_cfg->regs.sense_interrupt_reg32);
  5008. return IRQ_NONE;
  5009. }
  5010. } else {
  5011. if (int_reg & IPR_PCII_IOA_UNIT_CHECKED)
  5012. ioa_cfg->ioa_unit_checked = 1;
  5013. else if (int_reg & IPR_PCII_NO_HOST_RRQ)
  5014. dev_err(&ioa_cfg->pdev->dev,
  5015. "No Host RRQ. 0x%08X\n", int_reg);
  5016. else
  5017. dev_err(&ioa_cfg->pdev->dev,
  5018. "Permanent IOA failure. 0x%08X\n", int_reg);
  5019. if (WAIT_FOR_DUMP == ioa_cfg->sdt_state)
  5020. ioa_cfg->sdt_state = GET_DUMP;
  5021. ipr_mask_and_clear_interrupts(ioa_cfg, ~0);
  5022. ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
  5023. }
  5024. return rc;
  5025. }
  5026. /**
  5027. * ipr_isr_eh - Interrupt service routine error handler
  5028. * @ioa_cfg: ioa config struct
  5029. * @msg: message to log
  5030. *
  5031. * Return value:
  5032. * none
  5033. **/
  5034. static void ipr_isr_eh(struct ipr_ioa_cfg *ioa_cfg, char *msg, u16 number)
  5035. {
  5036. ioa_cfg->errors_logged++;
  5037. dev_err(&ioa_cfg->pdev->dev, "%s %d\n", msg, number);
  5038. if (WAIT_FOR_DUMP == ioa_cfg->sdt_state)
  5039. ioa_cfg->sdt_state = GET_DUMP;
  5040. ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
  5041. }
  5042. static int ipr_process_hrrq(struct ipr_hrr_queue *hrr_queue, int budget,
  5043. struct list_head *doneq)
  5044. {
  5045. u32 ioasc;
  5046. u16 cmd_index;
  5047. struct ipr_cmnd *ipr_cmd;
  5048. struct ipr_ioa_cfg *ioa_cfg = hrr_queue->ioa_cfg;
  5049. int num_hrrq = 0;
  5050. /* If interrupts are disabled, ignore the interrupt */
  5051. if (!hrr_queue->allow_interrupts)
  5052. return 0;
  5053. while ((be32_to_cpu(*hrr_queue->hrrq_curr) & IPR_HRRQ_TOGGLE_BIT) ==
  5054. hrr_queue->toggle_bit) {
  5055. cmd_index = (be32_to_cpu(*hrr_queue->hrrq_curr) &
  5056. IPR_HRRQ_REQ_RESP_HANDLE_MASK) >>
  5057. IPR_HRRQ_REQ_RESP_HANDLE_SHIFT;
  5058. if (unlikely(cmd_index > hrr_queue->max_cmd_id ||
  5059. cmd_index < hrr_queue->min_cmd_id)) {
  5060. ipr_isr_eh(ioa_cfg,
  5061. "Invalid response handle from IOA: ",
  5062. cmd_index);
  5063. break;
  5064. }
  5065. ipr_cmd = ioa_cfg->ipr_cmnd_list[cmd_index];
  5066. ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
  5067. ipr_trc_hook(ipr_cmd, IPR_TRACE_FINISH, ioasc);
  5068. list_move_tail(&ipr_cmd->queue, doneq);
  5069. if (hrr_queue->hrrq_curr < hrr_queue->hrrq_end) {
  5070. hrr_queue->hrrq_curr++;
  5071. } else {
  5072. hrr_queue->hrrq_curr = hrr_queue->hrrq_start;
  5073. hrr_queue->toggle_bit ^= 1u;
  5074. }
  5075. num_hrrq++;
  5076. if (budget > 0 && num_hrrq >= budget)
  5077. break;
  5078. }
  5079. return num_hrrq;
  5080. }
  5081. static int ipr_iopoll(struct irq_poll *iop, int budget)
  5082. {
  5083. struct ipr_ioa_cfg *ioa_cfg;
  5084. struct ipr_hrr_queue *hrrq;
  5085. struct ipr_cmnd *ipr_cmd, *temp;
  5086. unsigned long hrrq_flags;
  5087. int completed_ops;
  5088. LIST_HEAD(doneq);
  5089. hrrq = container_of(iop, struct ipr_hrr_queue, iopoll);
  5090. ioa_cfg = hrrq->ioa_cfg;
  5091. spin_lock_irqsave(hrrq->lock, hrrq_flags);
  5092. completed_ops = ipr_process_hrrq(hrrq, budget, &doneq);
  5093. if (completed_ops < budget)
  5094. irq_poll_complete(iop);
  5095. spin_unlock_irqrestore(hrrq->lock, hrrq_flags);
  5096. list_for_each_entry_safe(ipr_cmd, temp, &doneq, queue) {
  5097. list_del(&ipr_cmd->queue);
  5098. del_timer(&ipr_cmd->timer);
  5099. ipr_cmd->fast_done(ipr_cmd);
  5100. }
  5101. return completed_ops;
  5102. }
  5103. /**
  5104. * ipr_isr - Interrupt service routine
  5105. * @irq: irq number
  5106. * @devp: pointer to ioa config struct
  5107. *
  5108. * Return value:
  5109. * IRQ_NONE / IRQ_HANDLED
  5110. **/
  5111. static irqreturn_t ipr_isr(int irq, void *devp)
  5112. {
  5113. struct ipr_hrr_queue *hrrq = (struct ipr_hrr_queue *)devp;
  5114. struct ipr_ioa_cfg *ioa_cfg = hrrq->ioa_cfg;
  5115. unsigned long hrrq_flags = 0;
  5116. u32 int_reg = 0;
  5117. int num_hrrq = 0;
  5118. int irq_none = 0;
  5119. struct ipr_cmnd *ipr_cmd, *temp;
  5120. irqreturn_t rc = IRQ_NONE;
  5121. LIST_HEAD(doneq);
  5122. spin_lock_irqsave(hrrq->lock, hrrq_flags);
  5123. /* If interrupts are disabled, ignore the interrupt */
  5124. if (!hrrq->allow_interrupts) {
  5125. spin_unlock_irqrestore(hrrq->lock, hrrq_flags);
  5126. return IRQ_NONE;
  5127. }
  5128. while (1) {
  5129. if (ipr_process_hrrq(hrrq, -1, &doneq)) {
  5130. rc = IRQ_HANDLED;
  5131. if (!ioa_cfg->clear_isr)
  5132. break;
  5133. /* Clear the PCI interrupt */
  5134. num_hrrq = 0;
  5135. do {
  5136. writel(IPR_PCII_HRRQ_UPDATED,
  5137. ioa_cfg->regs.clr_interrupt_reg32);
  5138. int_reg = readl(ioa_cfg->regs.sense_interrupt_reg32);
  5139. } while (int_reg & IPR_PCII_HRRQ_UPDATED &&
  5140. num_hrrq++ < IPR_MAX_HRRQ_RETRIES);
  5141. } else if (rc == IRQ_NONE && irq_none == 0) {
  5142. int_reg = readl(ioa_cfg->regs.sense_interrupt_reg32);
  5143. irq_none++;
  5144. } else if (num_hrrq == IPR_MAX_HRRQ_RETRIES &&
  5145. int_reg & IPR_PCII_HRRQ_UPDATED) {
  5146. ipr_isr_eh(ioa_cfg,
  5147. "Error clearing HRRQ: ", num_hrrq);
  5148. rc = IRQ_HANDLED;
  5149. break;
  5150. } else
  5151. break;
  5152. }
  5153. if (unlikely(rc == IRQ_NONE))
  5154. rc = ipr_handle_other_interrupt(ioa_cfg, int_reg);
  5155. spin_unlock_irqrestore(hrrq->lock, hrrq_flags);
  5156. list_for_each_entry_safe(ipr_cmd, temp, &doneq, queue) {
  5157. list_del(&ipr_cmd->queue);
  5158. del_timer(&ipr_cmd->timer);
  5159. ipr_cmd->fast_done(ipr_cmd);
  5160. }
  5161. return rc;
  5162. }
  5163. /**
  5164. * ipr_isr_mhrrq - Interrupt service routine
  5165. * @irq: irq number
  5166. * @devp: pointer to ioa config struct
  5167. *
  5168. * Return value:
  5169. * IRQ_NONE / IRQ_HANDLED
  5170. **/
  5171. static irqreturn_t ipr_isr_mhrrq(int irq, void *devp)
  5172. {
  5173. struct ipr_hrr_queue *hrrq = (struct ipr_hrr_queue *)devp;
  5174. struct ipr_ioa_cfg *ioa_cfg = hrrq->ioa_cfg;
  5175. unsigned long hrrq_flags = 0;
  5176. struct ipr_cmnd *ipr_cmd, *temp;
  5177. irqreturn_t rc = IRQ_NONE;
  5178. LIST_HEAD(doneq);
  5179. spin_lock_irqsave(hrrq->lock, hrrq_flags);
  5180. /* If interrupts are disabled, ignore the interrupt */
  5181. if (!hrrq->allow_interrupts) {
  5182. spin_unlock_irqrestore(hrrq->lock, hrrq_flags);
  5183. return IRQ_NONE;
  5184. }
  5185. if (ioa_cfg->iopoll_weight && ioa_cfg->sis64 && ioa_cfg->nvectors > 1) {
  5186. if ((be32_to_cpu(*hrrq->hrrq_curr) & IPR_HRRQ_TOGGLE_BIT) ==
  5187. hrrq->toggle_bit) {
  5188. irq_poll_sched(&hrrq->iopoll);
  5189. spin_unlock_irqrestore(hrrq->lock, hrrq_flags);
  5190. return IRQ_HANDLED;
  5191. }
  5192. } else {
  5193. if ((be32_to_cpu(*hrrq->hrrq_curr) & IPR_HRRQ_TOGGLE_BIT) ==
  5194. hrrq->toggle_bit)
  5195. if (ipr_process_hrrq(hrrq, -1, &doneq))
  5196. rc = IRQ_HANDLED;
  5197. }
  5198. spin_unlock_irqrestore(hrrq->lock, hrrq_flags);
  5199. list_for_each_entry_safe(ipr_cmd, temp, &doneq, queue) {
  5200. list_del(&ipr_cmd->queue);
  5201. del_timer(&ipr_cmd->timer);
  5202. ipr_cmd->fast_done(ipr_cmd);
  5203. }
  5204. return rc;
  5205. }
  5206. /**
  5207. * ipr_build_ioadl64 - Build a scatter/gather list and map the buffer
  5208. * @ioa_cfg: ioa config struct
  5209. * @ipr_cmd: ipr command struct
  5210. *
  5211. * Return value:
  5212. * 0 on success / -1 on failure
  5213. **/
  5214. static int ipr_build_ioadl64(struct ipr_ioa_cfg *ioa_cfg,
  5215. struct ipr_cmnd *ipr_cmd)
  5216. {
  5217. int i, nseg;
  5218. struct scatterlist *sg;
  5219. u32 length;
  5220. u32 ioadl_flags = 0;
  5221. struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
  5222. struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
  5223. struct ipr_ioadl64_desc *ioadl64 = ipr_cmd->i.ioadl64;
  5224. length = scsi_bufflen(scsi_cmd);
  5225. if (!length)
  5226. return 0;
  5227. nseg = scsi_dma_map(scsi_cmd);
  5228. if (nseg < 0) {
  5229. if (printk_ratelimit())
  5230. dev_err(&ioa_cfg->pdev->dev, "scsi_dma_map failed!\n");
  5231. return -1;
  5232. }
  5233. ipr_cmd->dma_use_sg = nseg;
  5234. ioarcb->data_transfer_length = cpu_to_be32(length);
  5235. ioarcb->ioadl_len =
  5236. cpu_to_be32(sizeof(struct ipr_ioadl64_desc) * ipr_cmd->dma_use_sg);
  5237. if (scsi_cmd->sc_data_direction == DMA_TO_DEVICE) {
  5238. ioadl_flags = IPR_IOADL_FLAGS_WRITE;
  5239. ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
  5240. } else if (scsi_cmd->sc_data_direction == DMA_FROM_DEVICE)
  5241. ioadl_flags = IPR_IOADL_FLAGS_READ;
  5242. scsi_for_each_sg(scsi_cmd, sg, ipr_cmd->dma_use_sg, i) {
  5243. ioadl64[i].flags = cpu_to_be32(ioadl_flags);
  5244. ioadl64[i].data_len = cpu_to_be32(sg_dma_len(sg));
  5245. ioadl64[i].address = cpu_to_be64(sg_dma_address(sg));
  5246. }
  5247. ioadl64[i-1].flags |= cpu_to_be32(IPR_IOADL_FLAGS_LAST);
  5248. return 0;
  5249. }
  5250. /**
  5251. * ipr_build_ioadl - Build a scatter/gather list and map the buffer
  5252. * @ioa_cfg: ioa config struct
  5253. * @ipr_cmd: ipr command struct
  5254. *
  5255. * Return value:
  5256. * 0 on success / -1 on failure
  5257. **/
  5258. static int ipr_build_ioadl(struct ipr_ioa_cfg *ioa_cfg,
  5259. struct ipr_cmnd *ipr_cmd)
  5260. {
  5261. int i, nseg;
  5262. struct scatterlist *sg;
  5263. u32 length;
  5264. u32 ioadl_flags = 0;
  5265. struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
  5266. struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
  5267. struct ipr_ioadl_desc *ioadl = ipr_cmd->i.ioadl;
  5268. length = scsi_bufflen(scsi_cmd);
  5269. if (!length)
  5270. return 0;
  5271. nseg = scsi_dma_map(scsi_cmd);
  5272. if (nseg < 0) {
  5273. dev_err(&ioa_cfg->pdev->dev, "scsi_dma_map failed!\n");
  5274. return -1;
  5275. }
  5276. ipr_cmd->dma_use_sg = nseg;
  5277. if (scsi_cmd->sc_data_direction == DMA_TO_DEVICE) {
  5278. ioadl_flags = IPR_IOADL_FLAGS_WRITE;
  5279. ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
  5280. ioarcb->data_transfer_length = cpu_to_be32(length);
  5281. ioarcb->ioadl_len =
  5282. cpu_to_be32(sizeof(struct ipr_ioadl_desc) * ipr_cmd->dma_use_sg);
  5283. } else if (scsi_cmd->sc_data_direction == DMA_FROM_DEVICE) {
  5284. ioadl_flags = IPR_IOADL_FLAGS_READ;
  5285. ioarcb->read_data_transfer_length = cpu_to_be32(length);
  5286. ioarcb->read_ioadl_len =
  5287. cpu_to_be32(sizeof(struct ipr_ioadl_desc) * ipr_cmd->dma_use_sg);
  5288. }
  5289. if (ipr_cmd->dma_use_sg <= ARRAY_SIZE(ioarcb->u.add_data.u.ioadl)) {
  5290. ioadl = ioarcb->u.add_data.u.ioadl;
  5291. ioarcb->write_ioadl_addr = cpu_to_be32((ipr_cmd->dma_addr) +
  5292. offsetof(struct ipr_ioarcb, u.add_data));
  5293. ioarcb->read_ioadl_addr = ioarcb->write_ioadl_addr;
  5294. }
  5295. scsi_for_each_sg(scsi_cmd, sg, ipr_cmd->dma_use_sg, i) {
  5296. ioadl[i].flags_and_data_len =
  5297. cpu_to_be32(ioadl_flags | sg_dma_len(sg));
  5298. ioadl[i].address = cpu_to_be32(sg_dma_address(sg));
  5299. }
  5300. ioadl[i-1].flags_and_data_len |= cpu_to_be32(IPR_IOADL_FLAGS_LAST);
  5301. return 0;
  5302. }
  5303. /**
  5304. * __ipr_erp_done - Process completion of ERP for a device
  5305. * @ipr_cmd: ipr command struct
  5306. *
  5307. * This function copies the sense buffer into the scsi_cmd
  5308. * struct and pushes the scsi_done function.
  5309. *
  5310. * Return value:
  5311. * nothing
  5312. **/
  5313. static void __ipr_erp_done(struct ipr_cmnd *ipr_cmd)
  5314. {
  5315. struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
  5316. struct ipr_resource_entry *res = scsi_cmd->device->hostdata;
  5317. u32 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
  5318. if (IPR_IOASC_SENSE_KEY(ioasc) > 0) {
  5319. scsi_cmd->result |= (DID_ERROR << 16);
  5320. scmd_printk(KERN_ERR, scsi_cmd,
  5321. "Request Sense failed with IOASC: 0x%08X\n", ioasc);
  5322. } else {
  5323. memcpy(scsi_cmd->sense_buffer, ipr_cmd->sense_buffer,
  5324. SCSI_SENSE_BUFFERSIZE);
  5325. }
  5326. if (res) {
  5327. if (!ipr_is_naca_model(res))
  5328. res->needs_sync_complete = 1;
  5329. res->in_erp = 0;
  5330. }
  5331. scsi_dma_unmap(ipr_cmd->scsi_cmd);
  5332. scsi_cmd->scsi_done(scsi_cmd);
  5333. if (ipr_cmd->eh_comp)
  5334. complete(ipr_cmd->eh_comp);
  5335. list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_free_q);
  5336. }
  5337. /**
  5338. * ipr_erp_done - Process completion of ERP for a device
  5339. * @ipr_cmd: ipr command struct
  5340. *
  5341. * This function copies the sense buffer into the scsi_cmd
  5342. * struct and pushes the scsi_done function.
  5343. *
  5344. * Return value:
  5345. * nothing
  5346. **/
  5347. static void ipr_erp_done(struct ipr_cmnd *ipr_cmd)
  5348. {
  5349. struct ipr_hrr_queue *hrrq = ipr_cmd->hrrq;
  5350. unsigned long hrrq_flags;
  5351. spin_lock_irqsave(&hrrq->_lock, hrrq_flags);
  5352. __ipr_erp_done(ipr_cmd);
  5353. spin_unlock_irqrestore(&hrrq->_lock, hrrq_flags);
  5354. }
  5355. /**
  5356. * ipr_reinit_ipr_cmnd_for_erp - Re-initialize a cmnd block to be used for ERP
  5357. * @ipr_cmd: ipr command struct
  5358. *
  5359. * Return value:
  5360. * none
  5361. **/
  5362. static void ipr_reinit_ipr_cmnd_for_erp(struct ipr_cmnd *ipr_cmd)
  5363. {
  5364. struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
  5365. struct ipr_ioasa *ioasa = &ipr_cmd->s.ioasa;
  5366. dma_addr_t dma_addr = ipr_cmd->dma_addr;
  5367. memset(&ioarcb->cmd_pkt, 0, sizeof(struct ipr_cmd_pkt));
  5368. ioarcb->data_transfer_length = 0;
  5369. ioarcb->read_data_transfer_length = 0;
  5370. ioarcb->ioadl_len = 0;
  5371. ioarcb->read_ioadl_len = 0;
  5372. ioasa->hdr.ioasc = 0;
  5373. ioasa->hdr.residual_data_len = 0;
  5374. if (ipr_cmd->ioa_cfg->sis64)
  5375. ioarcb->u.sis64_addr_data.data_ioadl_addr =
  5376. cpu_to_be64(dma_addr + offsetof(struct ipr_cmnd, i.ioadl64));
  5377. else {
  5378. ioarcb->write_ioadl_addr =
  5379. cpu_to_be32(dma_addr + offsetof(struct ipr_cmnd, i.ioadl));
  5380. ioarcb->read_ioadl_addr = ioarcb->write_ioadl_addr;
  5381. }
  5382. }
  5383. /**
  5384. * __ipr_erp_request_sense - Send request sense to a device
  5385. * @ipr_cmd: ipr command struct
  5386. *
  5387. * This function sends a request sense to a device as a result
  5388. * of a check condition.
  5389. *
  5390. * Return value:
  5391. * nothing
  5392. **/
  5393. static void __ipr_erp_request_sense(struct ipr_cmnd *ipr_cmd)
  5394. {
  5395. struct ipr_cmd_pkt *cmd_pkt = &ipr_cmd->ioarcb.cmd_pkt;
  5396. u32 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
  5397. if (IPR_IOASC_SENSE_KEY(ioasc) > 0) {
  5398. __ipr_erp_done(ipr_cmd);
  5399. return;
  5400. }
  5401. ipr_reinit_ipr_cmnd_for_erp(ipr_cmd);
  5402. cmd_pkt->request_type = IPR_RQTYPE_SCSICDB;
  5403. cmd_pkt->cdb[0] = REQUEST_SENSE;
  5404. cmd_pkt->cdb[4] = SCSI_SENSE_BUFFERSIZE;
  5405. cmd_pkt->flags_hi |= IPR_FLAGS_HI_SYNC_OVERRIDE;
  5406. cmd_pkt->flags_hi |= IPR_FLAGS_HI_NO_ULEN_CHK;
  5407. cmd_pkt->timeout = cpu_to_be16(IPR_REQUEST_SENSE_TIMEOUT / HZ);
  5408. ipr_init_ioadl(ipr_cmd, ipr_cmd->sense_buffer_dma,
  5409. SCSI_SENSE_BUFFERSIZE, IPR_IOADL_FLAGS_READ_LAST);
  5410. ipr_do_req(ipr_cmd, ipr_erp_done, ipr_timeout,
  5411. IPR_REQUEST_SENSE_TIMEOUT * 2);
  5412. }
  5413. /**
  5414. * ipr_erp_request_sense - Send request sense to a device
  5415. * @ipr_cmd: ipr command struct
  5416. *
  5417. * This function sends a request sense to a device as a result
  5418. * of a check condition.
  5419. *
  5420. * Return value:
  5421. * nothing
  5422. **/
  5423. static void ipr_erp_request_sense(struct ipr_cmnd *ipr_cmd)
  5424. {
  5425. struct ipr_hrr_queue *hrrq = ipr_cmd->hrrq;
  5426. unsigned long hrrq_flags;
  5427. spin_lock_irqsave(&hrrq->_lock, hrrq_flags);
  5428. __ipr_erp_request_sense(ipr_cmd);
  5429. spin_unlock_irqrestore(&hrrq->_lock, hrrq_flags);
  5430. }
  5431. /**
  5432. * ipr_erp_cancel_all - Send cancel all to a device
  5433. * @ipr_cmd: ipr command struct
  5434. *
  5435. * This function sends a cancel all to a device to clear the
  5436. * queue. If we are running TCQ on the device, QERR is set to 1,
  5437. * which means all outstanding ops have been dropped on the floor.
  5438. * Cancel all will return them to us.
  5439. *
  5440. * Return value:
  5441. * nothing
  5442. **/
  5443. static void ipr_erp_cancel_all(struct ipr_cmnd *ipr_cmd)
  5444. {
  5445. struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
  5446. struct ipr_resource_entry *res = scsi_cmd->device->hostdata;
  5447. struct ipr_cmd_pkt *cmd_pkt;
  5448. res->in_erp = 1;
  5449. ipr_reinit_ipr_cmnd_for_erp(ipr_cmd);
  5450. if (!scsi_cmd->device->simple_tags) {
  5451. __ipr_erp_request_sense(ipr_cmd);
  5452. return;
  5453. }
  5454. cmd_pkt = &ipr_cmd->ioarcb.cmd_pkt;
  5455. cmd_pkt->request_type = IPR_RQTYPE_IOACMD;
  5456. cmd_pkt->cdb[0] = IPR_CANCEL_ALL_REQUESTS;
  5457. ipr_do_req(ipr_cmd, ipr_erp_request_sense, ipr_timeout,
  5458. IPR_CANCEL_ALL_TIMEOUT);
  5459. }
  5460. /**
  5461. * ipr_dump_ioasa - Dump contents of IOASA
  5462. * @ioa_cfg: ioa config struct
  5463. * @ipr_cmd: ipr command struct
  5464. * @res: resource entry struct
  5465. *
  5466. * This function is invoked by the interrupt handler when ops
  5467. * fail. It will log the IOASA if appropriate. Only called
  5468. * for GPDD ops.
  5469. *
  5470. * Return value:
  5471. * none
  5472. **/
  5473. static void ipr_dump_ioasa(struct ipr_ioa_cfg *ioa_cfg,
  5474. struct ipr_cmnd *ipr_cmd, struct ipr_resource_entry *res)
  5475. {
  5476. int i;
  5477. u16 data_len;
  5478. u32 ioasc, fd_ioasc;
  5479. struct ipr_ioasa *ioasa = &ipr_cmd->s.ioasa;
  5480. __be32 *ioasa_data = (__be32 *)ioasa;
  5481. int error_index;
  5482. ioasc = be32_to_cpu(ioasa->hdr.ioasc) & IPR_IOASC_IOASC_MASK;
  5483. fd_ioasc = be32_to_cpu(ioasa->hdr.fd_ioasc) & IPR_IOASC_IOASC_MASK;
  5484. if (0 == ioasc)
  5485. return;
  5486. if (ioa_cfg->log_level < IPR_DEFAULT_LOG_LEVEL)
  5487. return;
  5488. if (ioasc == IPR_IOASC_BUS_WAS_RESET && fd_ioasc)
  5489. error_index = ipr_get_error(fd_ioasc);
  5490. else
  5491. error_index = ipr_get_error(ioasc);
  5492. if (ioa_cfg->log_level < IPR_MAX_LOG_LEVEL) {
  5493. /* Don't log an error if the IOA already logged one */
  5494. if (ioasa->hdr.ilid != 0)
  5495. return;
  5496. if (!ipr_is_gscsi(res))
  5497. return;
  5498. if (ipr_error_table[error_index].log_ioasa == 0)
  5499. return;
  5500. }
  5501. ipr_res_err(ioa_cfg, res, "%s\n", ipr_error_table[error_index].error);
  5502. data_len = be16_to_cpu(ioasa->hdr.ret_stat_len);
  5503. if (ioa_cfg->sis64 && sizeof(struct ipr_ioasa64) < data_len)
  5504. data_len = sizeof(struct ipr_ioasa64);
  5505. else if (!ioa_cfg->sis64 && sizeof(struct ipr_ioasa) < data_len)
  5506. data_len = sizeof(struct ipr_ioasa);
  5507. ipr_err("IOASA Dump:\n");
  5508. for (i = 0; i < data_len / 4; i += 4) {
  5509. ipr_err("%08X: %08X %08X %08X %08X\n", i*4,
  5510. be32_to_cpu(ioasa_data[i]),
  5511. be32_to_cpu(ioasa_data[i+1]),
  5512. be32_to_cpu(ioasa_data[i+2]),
  5513. be32_to_cpu(ioasa_data[i+3]));
  5514. }
  5515. }
  5516. /**
  5517. * ipr_gen_sense - Generate SCSI sense data from an IOASA
  5518. * @ioasa: IOASA
  5519. * @sense_buf: sense data buffer
  5520. *
  5521. * Return value:
  5522. * none
  5523. **/
  5524. static void ipr_gen_sense(struct ipr_cmnd *ipr_cmd)
  5525. {
  5526. u32 failing_lba;
  5527. u8 *sense_buf = ipr_cmd->scsi_cmd->sense_buffer;
  5528. struct ipr_resource_entry *res = ipr_cmd->scsi_cmd->device->hostdata;
  5529. struct ipr_ioasa *ioasa = &ipr_cmd->s.ioasa;
  5530. u32 ioasc = be32_to_cpu(ioasa->hdr.ioasc);
  5531. memset(sense_buf, 0, SCSI_SENSE_BUFFERSIZE);
  5532. if (ioasc >= IPR_FIRST_DRIVER_IOASC)
  5533. return;
  5534. ipr_cmd->scsi_cmd->result = SAM_STAT_CHECK_CONDITION;
  5535. if (ipr_is_vset_device(res) &&
  5536. ioasc == IPR_IOASC_MED_DO_NOT_REALLOC &&
  5537. ioasa->u.vset.failing_lba_hi != 0) {
  5538. sense_buf[0] = 0x72;
  5539. sense_buf[1] = IPR_IOASC_SENSE_KEY(ioasc);
  5540. sense_buf[2] = IPR_IOASC_SENSE_CODE(ioasc);
  5541. sense_buf[3] = IPR_IOASC_SENSE_QUAL(ioasc);
  5542. sense_buf[7] = 12;
  5543. sense_buf[8] = 0;
  5544. sense_buf[9] = 0x0A;
  5545. sense_buf[10] = 0x80;
  5546. failing_lba = be32_to_cpu(ioasa->u.vset.failing_lba_hi);
  5547. sense_buf[12] = (failing_lba & 0xff000000) >> 24;
  5548. sense_buf[13] = (failing_lba & 0x00ff0000) >> 16;
  5549. sense_buf[14] = (failing_lba & 0x0000ff00) >> 8;
  5550. sense_buf[15] = failing_lba & 0x000000ff;
  5551. failing_lba = be32_to_cpu(ioasa->u.vset.failing_lba_lo);
  5552. sense_buf[16] = (failing_lba & 0xff000000) >> 24;
  5553. sense_buf[17] = (failing_lba & 0x00ff0000) >> 16;
  5554. sense_buf[18] = (failing_lba & 0x0000ff00) >> 8;
  5555. sense_buf[19] = failing_lba & 0x000000ff;
  5556. } else {
  5557. sense_buf[0] = 0x70;
  5558. sense_buf[2] = IPR_IOASC_SENSE_KEY(ioasc);
  5559. sense_buf[12] = IPR_IOASC_SENSE_CODE(ioasc);
  5560. sense_buf[13] = IPR_IOASC_SENSE_QUAL(ioasc);
  5561. /* Illegal request */
  5562. if ((IPR_IOASC_SENSE_KEY(ioasc) == 0x05) &&
  5563. (be32_to_cpu(ioasa->hdr.ioasc_specific) & IPR_FIELD_POINTER_VALID)) {
  5564. sense_buf[7] = 10; /* additional length */
  5565. /* IOARCB was in error */
  5566. if (IPR_IOASC_SENSE_CODE(ioasc) == 0x24)
  5567. sense_buf[15] = 0xC0;
  5568. else /* Parameter data was invalid */
  5569. sense_buf[15] = 0x80;
  5570. sense_buf[16] =
  5571. ((IPR_FIELD_POINTER_MASK &
  5572. be32_to_cpu(ioasa->hdr.ioasc_specific)) >> 8) & 0xff;
  5573. sense_buf[17] =
  5574. (IPR_FIELD_POINTER_MASK &
  5575. be32_to_cpu(ioasa->hdr.ioasc_specific)) & 0xff;
  5576. } else {
  5577. if (ioasc == IPR_IOASC_MED_DO_NOT_REALLOC) {
  5578. if (ipr_is_vset_device(res))
  5579. failing_lba = be32_to_cpu(ioasa->u.vset.failing_lba_lo);
  5580. else
  5581. failing_lba = be32_to_cpu(ioasa->u.dasd.failing_lba);
  5582. sense_buf[0] |= 0x80; /* Or in the Valid bit */
  5583. sense_buf[3] = (failing_lba & 0xff000000) >> 24;
  5584. sense_buf[4] = (failing_lba & 0x00ff0000) >> 16;
  5585. sense_buf[5] = (failing_lba & 0x0000ff00) >> 8;
  5586. sense_buf[6] = failing_lba & 0x000000ff;
  5587. }
  5588. sense_buf[7] = 6; /* additional length */
  5589. }
  5590. }
  5591. }
  5592. /**
  5593. * ipr_get_autosense - Copy autosense data to sense buffer
  5594. * @ipr_cmd: ipr command struct
  5595. *
  5596. * This function copies the autosense buffer to the buffer
  5597. * in the scsi_cmd, if there is autosense available.
  5598. *
  5599. * Return value:
  5600. * 1 if autosense was available / 0 if not
  5601. **/
  5602. static int ipr_get_autosense(struct ipr_cmnd *ipr_cmd)
  5603. {
  5604. struct ipr_ioasa *ioasa = &ipr_cmd->s.ioasa;
  5605. struct ipr_ioasa64 *ioasa64 = &ipr_cmd->s.ioasa64;
  5606. if ((be32_to_cpu(ioasa->hdr.ioasc_specific) & IPR_AUTOSENSE_VALID) == 0)
  5607. return 0;
  5608. if (ipr_cmd->ioa_cfg->sis64)
  5609. memcpy(ipr_cmd->scsi_cmd->sense_buffer, ioasa64->auto_sense.data,
  5610. min_t(u16, be16_to_cpu(ioasa64->auto_sense.auto_sense_len),
  5611. SCSI_SENSE_BUFFERSIZE));
  5612. else
  5613. memcpy(ipr_cmd->scsi_cmd->sense_buffer, ioasa->auto_sense.data,
  5614. min_t(u16, be16_to_cpu(ioasa->auto_sense.auto_sense_len),
  5615. SCSI_SENSE_BUFFERSIZE));
  5616. return 1;
  5617. }
  5618. /**
  5619. * ipr_erp_start - Process an error response for a SCSI op
  5620. * @ioa_cfg: ioa config struct
  5621. * @ipr_cmd: ipr command struct
  5622. *
  5623. * This function determines whether or not to initiate ERP
  5624. * on the affected device.
  5625. *
  5626. * Return value:
  5627. * nothing
  5628. **/
  5629. static void ipr_erp_start(struct ipr_ioa_cfg *ioa_cfg,
  5630. struct ipr_cmnd *ipr_cmd)
  5631. {
  5632. struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
  5633. struct ipr_resource_entry *res = scsi_cmd->device->hostdata;
  5634. u32 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
  5635. u32 masked_ioasc = ioasc & IPR_IOASC_IOASC_MASK;
  5636. if (!res) {
  5637. __ipr_scsi_eh_done(ipr_cmd);
  5638. return;
  5639. }
  5640. if (!ipr_is_gscsi(res) && masked_ioasc != IPR_IOASC_HW_DEV_BUS_STATUS)
  5641. ipr_gen_sense(ipr_cmd);
  5642. ipr_dump_ioasa(ioa_cfg, ipr_cmd, res);
  5643. switch (masked_ioasc) {
  5644. case IPR_IOASC_ABORTED_CMD_TERM_BY_HOST:
  5645. if (ipr_is_naca_model(res))
  5646. scsi_cmd->result |= (DID_ABORT << 16);
  5647. else
  5648. scsi_cmd->result |= (DID_IMM_RETRY << 16);
  5649. break;
  5650. case IPR_IOASC_IR_RESOURCE_HANDLE:
  5651. case IPR_IOASC_IR_NO_CMDS_TO_2ND_IOA:
  5652. scsi_cmd->result |= (DID_NO_CONNECT << 16);
  5653. break;
  5654. case IPR_IOASC_HW_SEL_TIMEOUT:
  5655. scsi_cmd->result |= (DID_NO_CONNECT << 16);
  5656. if (!ipr_is_naca_model(res))
  5657. res->needs_sync_complete = 1;
  5658. break;
  5659. case IPR_IOASC_SYNC_REQUIRED:
  5660. if (!res->in_erp)
  5661. res->needs_sync_complete = 1;
  5662. scsi_cmd->result |= (DID_IMM_RETRY << 16);
  5663. break;
  5664. case IPR_IOASC_MED_DO_NOT_REALLOC: /* prevent retries */
  5665. case IPR_IOASA_IR_DUAL_IOA_DISABLED:
  5666. /*
  5667. * exception: do not set DID_PASSTHROUGH on CHECK CONDITION
  5668. * so SCSI mid-layer and upper layers handle it accordingly.
  5669. */
  5670. if (scsi_cmd->result != SAM_STAT_CHECK_CONDITION)
  5671. scsi_cmd->result |= (DID_PASSTHROUGH << 16);
  5672. break;
  5673. case IPR_IOASC_BUS_WAS_RESET:
  5674. case IPR_IOASC_BUS_WAS_RESET_BY_OTHER:
  5675. /*
  5676. * Report the bus reset and ask for a retry. The device
  5677. * will give CC/UA the next command.
  5678. */
  5679. if (!res->resetting_device)
  5680. scsi_report_bus_reset(ioa_cfg->host, scsi_cmd->device->channel);
  5681. scsi_cmd->result |= (DID_ERROR << 16);
  5682. if (!ipr_is_naca_model(res))
  5683. res->needs_sync_complete = 1;
  5684. break;
  5685. case IPR_IOASC_HW_DEV_BUS_STATUS:
  5686. scsi_cmd->result |= IPR_IOASC_SENSE_STATUS(ioasc);
  5687. if (IPR_IOASC_SENSE_STATUS(ioasc) == SAM_STAT_CHECK_CONDITION) {
  5688. if (!ipr_get_autosense(ipr_cmd)) {
  5689. if (!ipr_is_naca_model(res)) {
  5690. ipr_erp_cancel_all(ipr_cmd);
  5691. return;
  5692. }
  5693. }
  5694. }
  5695. if (!ipr_is_naca_model(res))
  5696. res->needs_sync_complete = 1;
  5697. break;
  5698. case IPR_IOASC_NR_INIT_CMD_REQUIRED:
  5699. break;
  5700. case IPR_IOASC_IR_NON_OPTIMIZED:
  5701. if (res->raw_mode) {
  5702. res->raw_mode = 0;
  5703. scsi_cmd->result |= (DID_IMM_RETRY << 16);
  5704. } else
  5705. scsi_cmd->result |= (DID_ERROR << 16);
  5706. break;
  5707. default:
  5708. if (IPR_IOASC_SENSE_KEY(ioasc) > RECOVERED_ERROR)
  5709. scsi_cmd->result |= (DID_ERROR << 16);
  5710. if (!ipr_is_vset_device(res) && !ipr_is_naca_model(res))
  5711. res->needs_sync_complete = 1;
  5712. break;
  5713. }
  5714. scsi_dma_unmap(ipr_cmd->scsi_cmd);
  5715. scsi_cmd->scsi_done(scsi_cmd);
  5716. if (ipr_cmd->eh_comp)
  5717. complete(ipr_cmd->eh_comp);
  5718. list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_free_q);
  5719. }
  5720. /**
  5721. * ipr_scsi_done - mid-layer done function
  5722. * @ipr_cmd: ipr command struct
  5723. *
  5724. * This function is invoked by the interrupt handler for
  5725. * ops generated by the SCSI mid-layer
  5726. *
  5727. * Return value:
  5728. * none
  5729. **/
  5730. static void ipr_scsi_done(struct ipr_cmnd *ipr_cmd)
  5731. {
  5732. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  5733. struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
  5734. u32 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
  5735. unsigned long lock_flags;
  5736. scsi_set_resid(scsi_cmd, be32_to_cpu(ipr_cmd->s.ioasa.hdr.residual_data_len));
  5737. if (likely(IPR_IOASC_SENSE_KEY(ioasc) == 0)) {
  5738. scsi_dma_unmap(scsi_cmd);
  5739. spin_lock_irqsave(ipr_cmd->hrrq->lock, lock_flags);
  5740. scsi_cmd->scsi_done(scsi_cmd);
  5741. if (ipr_cmd->eh_comp)
  5742. complete(ipr_cmd->eh_comp);
  5743. list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_free_q);
  5744. spin_unlock_irqrestore(ipr_cmd->hrrq->lock, lock_flags);
  5745. } else {
  5746. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  5747. spin_lock(&ipr_cmd->hrrq->_lock);
  5748. ipr_erp_start(ioa_cfg, ipr_cmd);
  5749. spin_unlock(&ipr_cmd->hrrq->_lock);
  5750. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  5751. }
  5752. }
  5753. /**
  5754. * ipr_queuecommand - Queue a mid-layer request
  5755. * @shost: scsi host struct
  5756. * @scsi_cmd: scsi command struct
  5757. *
  5758. * This function queues a request generated by the mid-layer.
  5759. *
  5760. * Return value:
  5761. * 0 on success
  5762. * SCSI_MLQUEUE_DEVICE_BUSY if device is busy
  5763. * SCSI_MLQUEUE_HOST_BUSY if host is busy
  5764. **/
  5765. static int ipr_queuecommand(struct Scsi_Host *shost,
  5766. struct scsi_cmnd *scsi_cmd)
  5767. {
  5768. struct ipr_ioa_cfg *ioa_cfg;
  5769. struct ipr_resource_entry *res;
  5770. struct ipr_ioarcb *ioarcb;
  5771. struct ipr_cmnd *ipr_cmd;
  5772. unsigned long hrrq_flags, lock_flags;
  5773. int rc;
  5774. struct ipr_hrr_queue *hrrq;
  5775. int hrrq_id;
  5776. ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
  5777. scsi_cmd->result = (DID_OK << 16);
  5778. res = scsi_cmd->device->hostdata;
  5779. if (ipr_is_gata(res) && res->sata_port) {
  5780. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  5781. rc = ata_sas_queuecmd(scsi_cmd, res->sata_port->ap);
  5782. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  5783. return rc;
  5784. }
  5785. hrrq_id = ipr_get_hrrq_index(ioa_cfg);
  5786. hrrq = &ioa_cfg->hrrq[hrrq_id];
  5787. spin_lock_irqsave(hrrq->lock, hrrq_flags);
  5788. /*
  5789. * We are currently blocking all devices due to a host reset
  5790. * We have told the host to stop giving us new requests, but
  5791. * ERP ops don't count. FIXME
  5792. */
  5793. if (unlikely(!hrrq->allow_cmds && !hrrq->ioa_is_dead && !hrrq->removing_ioa)) {
  5794. spin_unlock_irqrestore(hrrq->lock, hrrq_flags);
  5795. return SCSI_MLQUEUE_HOST_BUSY;
  5796. }
  5797. /*
  5798. * FIXME - Create scsi_set_host_offline interface
  5799. * and the ioa_is_dead check can be removed
  5800. */
  5801. if (unlikely(hrrq->ioa_is_dead || hrrq->removing_ioa || !res)) {
  5802. spin_unlock_irqrestore(hrrq->lock, hrrq_flags);
  5803. goto err_nodev;
  5804. }
  5805. ipr_cmd = __ipr_get_free_ipr_cmnd(hrrq);
  5806. if (ipr_cmd == NULL) {
  5807. spin_unlock_irqrestore(hrrq->lock, hrrq_flags);
  5808. return SCSI_MLQUEUE_HOST_BUSY;
  5809. }
  5810. spin_unlock_irqrestore(hrrq->lock, hrrq_flags);
  5811. ipr_init_ipr_cmnd(ipr_cmd, ipr_scsi_done);
  5812. ioarcb = &ipr_cmd->ioarcb;
  5813. memcpy(ioarcb->cmd_pkt.cdb, scsi_cmd->cmnd, scsi_cmd->cmd_len);
  5814. ipr_cmd->scsi_cmd = scsi_cmd;
  5815. ipr_cmd->done = ipr_scsi_eh_done;
  5816. if (ipr_is_gscsi(res)) {
  5817. if (scsi_cmd->underflow == 0)
  5818. ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_NO_ULEN_CHK;
  5819. if (res->reset_occurred) {
  5820. res->reset_occurred = 0;
  5821. ioarcb->cmd_pkt.flags_lo |= IPR_FLAGS_LO_DELAY_AFTER_RST;
  5822. }
  5823. }
  5824. if (ipr_is_gscsi(res) || ipr_is_vset_device(res)) {
  5825. ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_NO_LINK_DESC;
  5826. ioarcb->cmd_pkt.flags_lo |= IPR_FLAGS_LO_ALIGNED_BFR;
  5827. if (scsi_cmd->flags & SCMD_TAGGED)
  5828. ioarcb->cmd_pkt.flags_lo |= IPR_FLAGS_LO_SIMPLE_TASK;
  5829. else
  5830. ioarcb->cmd_pkt.flags_lo |= IPR_FLAGS_LO_UNTAGGED_TASK;
  5831. }
  5832. if (scsi_cmd->cmnd[0] >= 0xC0 &&
  5833. (!ipr_is_gscsi(res) || scsi_cmd->cmnd[0] == IPR_QUERY_RSRC_STATE)) {
  5834. ioarcb->cmd_pkt.request_type = IPR_RQTYPE_IOACMD;
  5835. }
  5836. if (res->raw_mode && ipr_is_af_dasd_device(res)) {
  5837. ioarcb->cmd_pkt.request_type = IPR_RQTYPE_PIPE;
  5838. if (scsi_cmd->underflow == 0)
  5839. ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_NO_ULEN_CHK;
  5840. }
  5841. if (ioa_cfg->sis64)
  5842. rc = ipr_build_ioadl64(ioa_cfg, ipr_cmd);
  5843. else
  5844. rc = ipr_build_ioadl(ioa_cfg, ipr_cmd);
  5845. spin_lock_irqsave(hrrq->lock, hrrq_flags);
  5846. if (unlikely(rc || (!hrrq->allow_cmds && !hrrq->ioa_is_dead))) {
  5847. list_add_tail(&ipr_cmd->queue, &hrrq->hrrq_free_q);
  5848. spin_unlock_irqrestore(hrrq->lock, hrrq_flags);
  5849. if (!rc)
  5850. scsi_dma_unmap(scsi_cmd);
  5851. return SCSI_MLQUEUE_HOST_BUSY;
  5852. }
  5853. if (unlikely(hrrq->ioa_is_dead)) {
  5854. list_add_tail(&ipr_cmd->queue, &hrrq->hrrq_free_q);
  5855. spin_unlock_irqrestore(hrrq->lock, hrrq_flags);
  5856. scsi_dma_unmap(scsi_cmd);
  5857. goto err_nodev;
  5858. }
  5859. ioarcb->res_handle = res->res_handle;
  5860. if (res->needs_sync_complete) {
  5861. ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_SYNC_COMPLETE;
  5862. res->needs_sync_complete = 0;
  5863. }
  5864. list_add_tail(&ipr_cmd->queue, &hrrq->hrrq_pending_q);
  5865. ipr_trc_hook(ipr_cmd, IPR_TRACE_START, IPR_GET_RES_PHYS_LOC(res));
  5866. ipr_send_command(ipr_cmd);
  5867. spin_unlock_irqrestore(hrrq->lock, hrrq_flags);
  5868. return 0;
  5869. err_nodev:
  5870. spin_lock_irqsave(hrrq->lock, hrrq_flags);
  5871. memset(scsi_cmd->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE);
  5872. scsi_cmd->result = (DID_NO_CONNECT << 16);
  5873. scsi_cmd->scsi_done(scsi_cmd);
  5874. spin_unlock_irqrestore(hrrq->lock, hrrq_flags);
  5875. return 0;
  5876. }
  5877. /**
  5878. * ipr_ioctl - IOCTL handler
  5879. * @sdev: scsi device struct
  5880. * @cmd: IOCTL cmd
  5881. * @arg: IOCTL arg
  5882. *
  5883. * Return value:
  5884. * 0 on success / other on failure
  5885. **/
  5886. static int ipr_ioctl(struct scsi_device *sdev, int cmd, void __user *arg)
  5887. {
  5888. struct ipr_resource_entry *res;
  5889. res = (struct ipr_resource_entry *)sdev->hostdata;
  5890. if (res && ipr_is_gata(res)) {
  5891. if (cmd == HDIO_GET_IDENTITY)
  5892. return -ENOTTY;
  5893. return ata_sas_scsi_ioctl(res->sata_port->ap, sdev, cmd, arg);
  5894. }
  5895. return -EINVAL;
  5896. }
  5897. /**
  5898. * ipr_info - Get information about the card/driver
  5899. * @scsi_host: scsi host struct
  5900. *
  5901. * Return value:
  5902. * pointer to buffer with description string
  5903. **/
  5904. static const char *ipr_ioa_info(struct Scsi_Host *host)
  5905. {
  5906. static char buffer[512];
  5907. struct ipr_ioa_cfg *ioa_cfg;
  5908. unsigned long lock_flags = 0;
  5909. ioa_cfg = (struct ipr_ioa_cfg *) host->hostdata;
  5910. spin_lock_irqsave(host->host_lock, lock_flags);
  5911. sprintf(buffer, "IBM %X Storage Adapter", ioa_cfg->type);
  5912. spin_unlock_irqrestore(host->host_lock, lock_flags);
  5913. return buffer;
  5914. }
  5915. static struct scsi_host_template driver_template = {
  5916. .module = THIS_MODULE,
  5917. .name = "IPR",
  5918. .info = ipr_ioa_info,
  5919. .ioctl = ipr_ioctl,
  5920. .queuecommand = ipr_queuecommand,
  5921. .eh_abort_handler = ipr_eh_abort,
  5922. .eh_device_reset_handler = ipr_eh_dev_reset,
  5923. .eh_host_reset_handler = ipr_eh_host_reset,
  5924. .slave_alloc = ipr_slave_alloc,
  5925. .slave_configure = ipr_slave_configure,
  5926. .slave_destroy = ipr_slave_destroy,
  5927. .scan_finished = ipr_scan_finished,
  5928. .target_alloc = ipr_target_alloc,
  5929. .target_destroy = ipr_target_destroy,
  5930. .change_queue_depth = ipr_change_queue_depth,
  5931. .bios_param = ipr_biosparam,
  5932. .can_queue = IPR_MAX_COMMANDS,
  5933. .this_id = -1,
  5934. .sg_tablesize = IPR_MAX_SGLIST,
  5935. .max_sectors = IPR_IOA_MAX_SECTORS,
  5936. .cmd_per_lun = IPR_MAX_CMD_PER_LUN,
  5937. .use_clustering = ENABLE_CLUSTERING,
  5938. .shost_attrs = ipr_ioa_attrs,
  5939. .sdev_attrs = ipr_dev_attrs,
  5940. .proc_name = IPR_NAME,
  5941. };
  5942. /**
  5943. * ipr_ata_phy_reset - libata phy_reset handler
  5944. * @ap: ata port to reset
  5945. *
  5946. **/
  5947. static void ipr_ata_phy_reset(struct ata_port *ap)
  5948. {
  5949. unsigned long flags;
  5950. struct ipr_sata_port *sata_port = ap->private_data;
  5951. struct ipr_resource_entry *res = sata_port->res;
  5952. struct ipr_ioa_cfg *ioa_cfg = sata_port->ioa_cfg;
  5953. int rc;
  5954. ENTER;
  5955. spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
  5956. while (ioa_cfg->in_reset_reload) {
  5957. spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
  5958. wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
  5959. spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
  5960. }
  5961. if (!ioa_cfg->hrrq[IPR_INIT_HRRQ].allow_cmds)
  5962. goto out_unlock;
  5963. rc = ipr_device_reset(ioa_cfg, res);
  5964. if (rc) {
  5965. ap->link.device[0].class = ATA_DEV_NONE;
  5966. goto out_unlock;
  5967. }
  5968. ap->link.device[0].class = res->ata_class;
  5969. if (ap->link.device[0].class == ATA_DEV_UNKNOWN)
  5970. ap->link.device[0].class = ATA_DEV_NONE;
  5971. out_unlock:
  5972. spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
  5973. LEAVE;
  5974. }
  5975. /**
  5976. * ipr_ata_post_internal - Cleanup after an internal command
  5977. * @qc: ATA queued command
  5978. *
  5979. * Return value:
  5980. * none
  5981. **/
  5982. static void ipr_ata_post_internal(struct ata_queued_cmd *qc)
  5983. {
  5984. struct ipr_sata_port *sata_port = qc->ap->private_data;
  5985. struct ipr_ioa_cfg *ioa_cfg = sata_port->ioa_cfg;
  5986. struct ipr_cmnd *ipr_cmd;
  5987. struct ipr_hrr_queue *hrrq;
  5988. unsigned long flags;
  5989. spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
  5990. while (ioa_cfg->in_reset_reload) {
  5991. spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
  5992. wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
  5993. spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
  5994. }
  5995. for_each_hrrq(hrrq, ioa_cfg) {
  5996. spin_lock(&hrrq->_lock);
  5997. list_for_each_entry(ipr_cmd, &hrrq->hrrq_pending_q, queue) {
  5998. if (ipr_cmd->qc == qc) {
  5999. ipr_device_reset(ioa_cfg, sata_port->res);
  6000. break;
  6001. }
  6002. }
  6003. spin_unlock(&hrrq->_lock);
  6004. }
  6005. spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
  6006. }
  6007. /**
  6008. * ipr_copy_sata_tf - Copy a SATA taskfile to an IOA data structure
  6009. * @regs: destination
  6010. * @tf: source ATA taskfile
  6011. *
  6012. * Return value:
  6013. * none
  6014. **/
  6015. static void ipr_copy_sata_tf(struct ipr_ioarcb_ata_regs *regs,
  6016. struct ata_taskfile *tf)
  6017. {
  6018. regs->feature = tf->feature;
  6019. regs->nsect = tf->nsect;
  6020. regs->lbal = tf->lbal;
  6021. regs->lbam = tf->lbam;
  6022. regs->lbah = tf->lbah;
  6023. regs->device = tf->device;
  6024. regs->command = tf->command;
  6025. regs->hob_feature = tf->hob_feature;
  6026. regs->hob_nsect = tf->hob_nsect;
  6027. regs->hob_lbal = tf->hob_lbal;
  6028. regs->hob_lbam = tf->hob_lbam;
  6029. regs->hob_lbah = tf->hob_lbah;
  6030. regs->ctl = tf->ctl;
  6031. }
  6032. /**
  6033. * ipr_sata_done - done function for SATA commands
  6034. * @ipr_cmd: ipr command struct
  6035. *
  6036. * This function is invoked by the interrupt handler for
  6037. * ops generated by the SCSI mid-layer to SATA devices
  6038. *
  6039. * Return value:
  6040. * none
  6041. **/
  6042. static void ipr_sata_done(struct ipr_cmnd *ipr_cmd)
  6043. {
  6044. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  6045. struct ata_queued_cmd *qc = ipr_cmd->qc;
  6046. struct ipr_sata_port *sata_port = qc->ap->private_data;
  6047. struct ipr_resource_entry *res = sata_port->res;
  6048. u32 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
  6049. spin_lock(&ipr_cmd->hrrq->_lock);
  6050. if (ipr_cmd->ioa_cfg->sis64)
  6051. memcpy(&sata_port->ioasa, &ipr_cmd->s.ioasa64.u.gata,
  6052. sizeof(struct ipr_ioasa_gata));
  6053. else
  6054. memcpy(&sata_port->ioasa, &ipr_cmd->s.ioasa.u.gata,
  6055. sizeof(struct ipr_ioasa_gata));
  6056. ipr_dump_ioasa(ioa_cfg, ipr_cmd, res);
  6057. if (be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc_specific) & IPR_ATA_DEVICE_WAS_RESET)
  6058. scsi_report_device_reset(ioa_cfg->host, res->bus, res->target);
  6059. if (IPR_IOASC_SENSE_KEY(ioasc) > RECOVERED_ERROR)
  6060. qc->err_mask |= __ac_err_mask(sata_port->ioasa.status);
  6061. else
  6062. qc->err_mask |= ac_err_mask(sata_port->ioasa.status);
  6063. list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_free_q);
  6064. spin_unlock(&ipr_cmd->hrrq->_lock);
  6065. ata_qc_complete(qc);
  6066. }
  6067. /**
  6068. * ipr_build_ata_ioadl64 - Build an ATA scatter/gather list
  6069. * @ipr_cmd: ipr command struct
  6070. * @qc: ATA queued command
  6071. *
  6072. **/
  6073. static void ipr_build_ata_ioadl64(struct ipr_cmnd *ipr_cmd,
  6074. struct ata_queued_cmd *qc)
  6075. {
  6076. u32 ioadl_flags = 0;
  6077. struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
  6078. struct ipr_ioadl64_desc *ioadl64 = ipr_cmd->i.ata_ioadl.ioadl64;
  6079. struct ipr_ioadl64_desc *last_ioadl64 = NULL;
  6080. int len = qc->nbytes;
  6081. struct scatterlist *sg;
  6082. unsigned int si;
  6083. dma_addr_t dma_addr = ipr_cmd->dma_addr;
  6084. if (len == 0)
  6085. return;
  6086. if (qc->dma_dir == DMA_TO_DEVICE) {
  6087. ioadl_flags = IPR_IOADL_FLAGS_WRITE;
  6088. ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
  6089. } else if (qc->dma_dir == DMA_FROM_DEVICE)
  6090. ioadl_flags = IPR_IOADL_FLAGS_READ;
  6091. ioarcb->data_transfer_length = cpu_to_be32(len);
  6092. ioarcb->ioadl_len =
  6093. cpu_to_be32(sizeof(struct ipr_ioadl64_desc) * ipr_cmd->dma_use_sg);
  6094. ioarcb->u.sis64_addr_data.data_ioadl_addr =
  6095. cpu_to_be64(dma_addr + offsetof(struct ipr_cmnd, i.ata_ioadl.ioadl64));
  6096. for_each_sg(qc->sg, sg, qc->n_elem, si) {
  6097. ioadl64->flags = cpu_to_be32(ioadl_flags);
  6098. ioadl64->data_len = cpu_to_be32(sg_dma_len(sg));
  6099. ioadl64->address = cpu_to_be64(sg_dma_address(sg));
  6100. last_ioadl64 = ioadl64;
  6101. ioadl64++;
  6102. }
  6103. if (likely(last_ioadl64))
  6104. last_ioadl64->flags |= cpu_to_be32(IPR_IOADL_FLAGS_LAST);
  6105. }
  6106. /**
  6107. * ipr_build_ata_ioadl - Build an ATA scatter/gather list
  6108. * @ipr_cmd: ipr command struct
  6109. * @qc: ATA queued command
  6110. *
  6111. **/
  6112. static void ipr_build_ata_ioadl(struct ipr_cmnd *ipr_cmd,
  6113. struct ata_queued_cmd *qc)
  6114. {
  6115. u32 ioadl_flags = 0;
  6116. struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
  6117. struct ipr_ioadl_desc *ioadl = ipr_cmd->i.ioadl;
  6118. struct ipr_ioadl_desc *last_ioadl = NULL;
  6119. int len = qc->nbytes;
  6120. struct scatterlist *sg;
  6121. unsigned int si;
  6122. if (len == 0)
  6123. return;
  6124. if (qc->dma_dir == DMA_TO_DEVICE) {
  6125. ioadl_flags = IPR_IOADL_FLAGS_WRITE;
  6126. ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
  6127. ioarcb->data_transfer_length = cpu_to_be32(len);
  6128. ioarcb->ioadl_len =
  6129. cpu_to_be32(sizeof(struct ipr_ioadl_desc) * ipr_cmd->dma_use_sg);
  6130. } else if (qc->dma_dir == DMA_FROM_DEVICE) {
  6131. ioadl_flags = IPR_IOADL_FLAGS_READ;
  6132. ioarcb->read_data_transfer_length = cpu_to_be32(len);
  6133. ioarcb->read_ioadl_len =
  6134. cpu_to_be32(sizeof(struct ipr_ioadl_desc) * ipr_cmd->dma_use_sg);
  6135. }
  6136. for_each_sg(qc->sg, sg, qc->n_elem, si) {
  6137. ioadl->flags_and_data_len = cpu_to_be32(ioadl_flags | sg_dma_len(sg));
  6138. ioadl->address = cpu_to_be32(sg_dma_address(sg));
  6139. last_ioadl = ioadl;
  6140. ioadl++;
  6141. }
  6142. if (likely(last_ioadl))
  6143. last_ioadl->flags_and_data_len |= cpu_to_be32(IPR_IOADL_FLAGS_LAST);
  6144. }
  6145. /**
  6146. * ipr_qc_defer - Get a free ipr_cmd
  6147. * @qc: queued command
  6148. *
  6149. * Return value:
  6150. * 0 if success
  6151. **/
  6152. static int ipr_qc_defer(struct ata_queued_cmd *qc)
  6153. {
  6154. struct ata_port *ap = qc->ap;
  6155. struct ipr_sata_port *sata_port = ap->private_data;
  6156. struct ipr_ioa_cfg *ioa_cfg = sata_port->ioa_cfg;
  6157. struct ipr_cmnd *ipr_cmd;
  6158. struct ipr_hrr_queue *hrrq;
  6159. int hrrq_id;
  6160. hrrq_id = ipr_get_hrrq_index(ioa_cfg);
  6161. hrrq = &ioa_cfg->hrrq[hrrq_id];
  6162. qc->lldd_task = NULL;
  6163. spin_lock(&hrrq->_lock);
  6164. if (unlikely(hrrq->ioa_is_dead)) {
  6165. spin_unlock(&hrrq->_lock);
  6166. return 0;
  6167. }
  6168. if (unlikely(!hrrq->allow_cmds)) {
  6169. spin_unlock(&hrrq->_lock);
  6170. return ATA_DEFER_LINK;
  6171. }
  6172. ipr_cmd = __ipr_get_free_ipr_cmnd(hrrq);
  6173. if (ipr_cmd == NULL) {
  6174. spin_unlock(&hrrq->_lock);
  6175. return ATA_DEFER_LINK;
  6176. }
  6177. qc->lldd_task = ipr_cmd;
  6178. spin_unlock(&hrrq->_lock);
  6179. return 0;
  6180. }
  6181. /**
  6182. * ipr_qc_issue - Issue a SATA qc to a device
  6183. * @qc: queued command
  6184. *
  6185. * Return value:
  6186. * 0 if success
  6187. **/
  6188. static unsigned int ipr_qc_issue(struct ata_queued_cmd *qc)
  6189. {
  6190. struct ata_port *ap = qc->ap;
  6191. struct ipr_sata_port *sata_port = ap->private_data;
  6192. struct ipr_resource_entry *res = sata_port->res;
  6193. struct ipr_ioa_cfg *ioa_cfg = sata_port->ioa_cfg;
  6194. struct ipr_cmnd *ipr_cmd;
  6195. struct ipr_ioarcb *ioarcb;
  6196. struct ipr_ioarcb_ata_regs *regs;
  6197. if (qc->lldd_task == NULL)
  6198. ipr_qc_defer(qc);
  6199. ipr_cmd = qc->lldd_task;
  6200. if (ipr_cmd == NULL)
  6201. return AC_ERR_SYSTEM;
  6202. qc->lldd_task = NULL;
  6203. spin_lock(&ipr_cmd->hrrq->_lock);
  6204. if (unlikely(!ipr_cmd->hrrq->allow_cmds ||
  6205. ipr_cmd->hrrq->ioa_is_dead)) {
  6206. list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_free_q);
  6207. spin_unlock(&ipr_cmd->hrrq->_lock);
  6208. return AC_ERR_SYSTEM;
  6209. }
  6210. ipr_init_ipr_cmnd(ipr_cmd, ipr_lock_and_done);
  6211. ioarcb = &ipr_cmd->ioarcb;
  6212. if (ioa_cfg->sis64) {
  6213. regs = &ipr_cmd->i.ata_ioadl.regs;
  6214. ioarcb->add_cmd_parms_offset = cpu_to_be16(sizeof(*ioarcb));
  6215. } else
  6216. regs = &ioarcb->u.add_data.u.regs;
  6217. memset(regs, 0, sizeof(*regs));
  6218. ioarcb->add_cmd_parms_len = cpu_to_be16(sizeof(*regs));
  6219. list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_pending_q);
  6220. ipr_cmd->qc = qc;
  6221. ipr_cmd->done = ipr_sata_done;
  6222. ipr_cmd->ioarcb.res_handle = res->res_handle;
  6223. ioarcb->cmd_pkt.request_type = IPR_RQTYPE_ATA_PASSTHRU;
  6224. ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_NO_LINK_DESC;
  6225. ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_NO_ULEN_CHK;
  6226. ipr_cmd->dma_use_sg = qc->n_elem;
  6227. if (ioa_cfg->sis64)
  6228. ipr_build_ata_ioadl64(ipr_cmd, qc);
  6229. else
  6230. ipr_build_ata_ioadl(ipr_cmd, qc);
  6231. regs->flags |= IPR_ATA_FLAG_STATUS_ON_GOOD_COMPLETION;
  6232. ipr_copy_sata_tf(regs, &qc->tf);
  6233. memcpy(ioarcb->cmd_pkt.cdb, qc->cdb, IPR_MAX_CDB_LEN);
  6234. ipr_trc_hook(ipr_cmd, IPR_TRACE_START, IPR_GET_RES_PHYS_LOC(res));
  6235. switch (qc->tf.protocol) {
  6236. case ATA_PROT_NODATA:
  6237. case ATA_PROT_PIO:
  6238. break;
  6239. case ATA_PROT_DMA:
  6240. regs->flags |= IPR_ATA_FLAG_XFER_TYPE_DMA;
  6241. break;
  6242. case ATAPI_PROT_PIO:
  6243. case ATAPI_PROT_NODATA:
  6244. regs->flags |= IPR_ATA_FLAG_PACKET_CMD;
  6245. break;
  6246. case ATAPI_PROT_DMA:
  6247. regs->flags |= IPR_ATA_FLAG_PACKET_CMD;
  6248. regs->flags |= IPR_ATA_FLAG_XFER_TYPE_DMA;
  6249. break;
  6250. default:
  6251. WARN_ON(1);
  6252. spin_unlock(&ipr_cmd->hrrq->_lock);
  6253. return AC_ERR_INVALID;
  6254. }
  6255. ipr_send_command(ipr_cmd);
  6256. spin_unlock(&ipr_cmd->hrrq->_lock);
  6257. return 0;
  6258. }
  6259. /**
  6260. * ipr_qc_fill_rtf - Read result TF
  6261. * @qc: ATA queued command
  6262. *
  6263. * Return value:
  6264. * true
  6265. **/
  6266. static bool ipr_qc_fill_rtf(struct ata_queued_cmd *qc)
  6267. {
  6268. struct ipr_sata_port *sata_port = qc->ap->private_data;
  6269. struct ipr_ioasa_gata *g = &sata_port->ioasa;
  6270. struct ata_taskfile *tf = &qc->result_tf;
  6271. tf->feature = g->error;
  6272. tf->nsect = g->nsect;
  6273. tf->lbal = g->lbal;
  6274. tf->lbam = g->lbam;
  6275. tf->lbah = g->lbah;
  6276. tf->device = g->device;
  6277. tf->command = g->status;
  6278. tf->hob_nsect = g->hob_nsect;
  6279. tf->hob_lbal = g->hob_lbal;
  6280. tf->hob_lbam = g->hob_lbam;
  6281. tf->hob_lbah = g->hob_lbah;
  6282. return true;
  6283. }
  6284. static struct ata_port_operations ipr_sata_ops = {
  6285. .phy_reset = ipr_ata_phy_reset,
  6286. .hardreset = ipr_sata_reset,
  6287. .post_internal_cmd = ipr_ata_post_internal,
  6288. .qc_prep = ata_noop_qc_prep,
  6289. .qc_defer = ipr_qc_defer,
  6290. .qc_issue = ipr_qc_issue,
  6291. .qc_fill_rtf = ipr_qc_fill_rtf,
  6292. .port_start = ata_sas_port_start,
  6293. .port_stop = ata_sas_port_stop
  6294. };
  6295. static struct ata_port_info sata_port_info = {
  6296. .flags = ATA_FLAG_SATA | ATA_FLAG_PIO_DMA |
  6297. ATA_FLAG_SAS_HOST,
  6298. .pio_mask = ATA_PIO4_ONLY,
  6299. .mwdma_mask = ATA_MWDMA2,
  6300. .udma_mask = ATA_UDMA6,
  6301. .port_ops = &ipr_sata_ops
  6302. };
  6303. #ifdef CONFIG_PPC_PSERIES
  6304. static const u16 ipr_blocked_processors[] = {
  6305. PVR_NORTHSTAR,
  6306. PVR_PULSAR,
  6307. PVR_POWER4,
  6308. PVR_ICESTAR,
  6309. PVR_SSTAR,
  6310. PVR_POWER4p,
  6311. PVR_630,
  6312. PVR_630p
  6313. };
  6314. /**
  6315. * ipr_invalid_adapter - Determine if this adapter is supported on this hardware
  6316. * @ioa_cfg: ioa cfg struct
  6317. *
  6318. * Adapters that use Gemstone revision < 3.1 do not work reliably on
  6319. * certain pSeries hardware. This function determines if the given
  6320. * adapter is in one of these confgurations or not.
  6321. *
  6322. * Return value:
  6323. * 1 if adapter is not supported / 0 if adapter is supported
  6324. **/
  6325. static int ipr_invalid_adapter(struct ipr_ioa_cfg *ioa_cfg)
  6326. {
  6327. int i;
  6328. if ((ioa_cfg->type == 0x5702) && (ioa_cfg->pdev->revision < 4)) {
  6329. for (i = 0; i < ARRAY_SIZE(ipr_blocked_processors); i++) {
  6330. if (pvr_version_is(ipr_blocked_processors[i]))
  6331. return 1;
  6332. }
  6333. }
  6334. return 0;
  6335. }
  6336. #else
  6337. #define ipr_invalid_adapter(ioa_cfg) 0
  6338. #endif
  6339. /**
  6340. * ipr_ioa_bringdown_done - IOA bring down completion.
  6341. * @ipr_cmd: ipr command struct
  6342. *
  6343. * This function processes the completion of an adapter bring down.
  6344. * It wakes any reset sleepers.
  6345. *
  6346. * Return value:
  6347. * IPR_RC_JOB_RETURN
  6348. **/
  6349. static int ipr_ioa_bringdown_done(struct ipr_cmnd *ipr_cmd)
  6350. {
  6351. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  6352. int i;
  6353. ENTER;
  6354. if (!ioa_cfg->hrrq[IPR_INIT_HRRQ].removing_ioa) {
  6355. ipr_trace;
  6356. ioa_cfg->scsi_unblock = 1;
  6357. schedule_work(&ioa_cfg->work_q);
  6358. }
  6359. ioa_cfg->in_reset_reload = 0;
  6360. ioa_cfg->reset_retries = 0;
  6361. for (i = 0; i < ioa_cfg->hrrq_num; i++) {
  6362. spin_lock(&ioa_cfg->hrrq[i]._lock);
  6363. ioa_cfg->hrrq[i].ioa_is_dead = 1;
  6364. spin_unlock(&ioa_cfg->hrrq[i]._lock);
  6365. }
  6366. wmb();
  6367. list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_free_q);
  6368. wake_up_all(&ioa_cfg->reset_wait_q);
  6369. LEAVE;
  6370. return IPR_RC_JOB_RETURN;
  6371. }
  6372. /**
  6373. * ipr_ioa_reset_done - IOA reset completion.
  6374. * @ipr_cmd: ipr command struct
  6375. *
  6376. * This function processes the completion of an adapter reset.
  6377. * It schedules any necessary mid-layer add/removes and
  6378. * wakes any reset sleepers.
  6379. *
  6380. * Return value:
  6381. * IPR_RC_JOB_RETURN
  6382. **/
  6383. static int ipr_ioa_reset_done(struct ipr_cmnd *ipr_cmd)
  6384. {
  6385. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  6386. struct ipr_resource_entry *res;
  6387. int j;
  6388. ENTER;
  6389. ioa_cfg->in_reset_reload = 0;
  6390. for (j = 0; j < ioa_cfg->hrrq_num; j++) {
  6391. spin_lock(&ioa_cfg->hrrq[j]._lock);
  6392. ioa_cfg->hrrq[j].allow_cmds = 1;
  6393. spin_unlock(&ioa_cfg->hrrq[j]._lock);
  6394. }
  6395. wmb();
  6396. ioa_cfg->reset_cmd = NULL;
  6397. ioa_cfg->doorbell |= IPR_RUNTIME_RESET;
  6398. list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
  6399. if (res->add_to_ml || res->del_from_ml) {
  6400. ipr_trace;
  6401. break;
  6402. }
  6403. }
  6404. schedule_work(&ioa_cfg->work_q);
  6405. for (j = 0; j < IPR_NUM_HCAMS; j++) {
  6406. list_del_init(&ioa_cfg->hostrcb[j]->queue);
  6407. if (j < IPR_NUM_LOG_HCAMS)
  6408. ipr_send_hcam(ioa_cfg,
  6409. IPR_HCAM_CDB_OP_CODE_LOG_DATA,
  6410. ioa_cfg->hostrcb[j]);
  6411. else
  6412. ipr_send_hcam(ioa_cfg,
  6413. IPR_HCAM_CDB_OP_CODE_CONFIG_CHANGE,
  6414. ioa_cfg->hostrcb[j]);
  6415. }
  6416. scsi_report_bus_reset(ioa_cfg->host, IPR_VSET_BUS);
  6417. dev_info(&ioa_cfg->pdev->dev, "IOA initialized.\n");
  6418. ioa_cfg->reset_retries = 0;
  6419. list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_free_q);
  6420. wake_up_all(&ioa_cfg->reset_wait_q);
  6421. ioa_cfg->scsi_unblock = 1;
  6422. schedule_work(&ioa_cfg->work_q);
  6423. LEAVE;
  6424. return IPR_RC_JOB_RETURN;
  6425. }
  6426. /**
  6427. * ipr_set_sup_dev_dflt - Initialize a Set Supported Device buffer
  6428. * @supported_dev: supported device struct
  6429. * @vpids: vendor product id struct
  6430. *
  6431. * Return value:
  6432. * none
  6433. **/
  6434. static void ipr_set_sup_dev_dflt(struct ipr_supported_device *supported_dev,
  6435. struct ipr_std_inq_vpids *vpids)
  6436. {
  6437. memset(supported_dev, 0, sizeof(struct ipr_supported_device));
  6438. memcpy(&supported_dev->vpids, vpids, sizeof(struct ipr_std_inq_vpids));
  6439. supported_dev->num_records = 1;
  6440. supported_dev->data_length =
  6441. cpu_to_be16(sizeof(struct ipr_supported_device));
  6442. supported_dev->reserved = 0;
  6443. }
  6444. /**
  6445. * ipr_set_supported_devs - Send Set Supported Devices for a device
  6446. * @ipr_cmd: ipr command struct
  6447. *
  6448. * This function sends a Set Supported Devices to the adapter
  6449. *
  6450. * Return value:
  6451. * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
  6452. **/
  6453. static int ipr_set_supported_devs(struct ipr_cmnd *ipr_cmd)
  6454. {
  6455. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  6456. struct ipr_supported_device *supp_dev = &ioa_cfg->vpd_cbs->supp_dev;
  6457. struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
  6458. struct ipr_resource_entry *res = ipr_cmd->u.res;
  6459. ipr_cmd->job_step = ipr_ioa_reset_done;
  6460. list_for_each_entry_continue(res, &ioa_cfg->used_res_q, queue) {
  6461. if (!ipr_is_scsi_disk(res))
  6462. continue;
  6463. ipr_cmd->u.res = res;
  6464. ipr_set_sup_dev_dflt(supp_dev, &res->std_inq_data.vpids);
  6465. ioarcb->res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
  6466. ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
  6467. ioarcb->cmd_pkt.request_type = IPR_RQTYPE_IOACMD;
  6468. ioarcb->cmd_pkt.cdb[0] = IPR_SET_SUPPORTED_DEVICES;
  6469. ioarcb->cmd_pkt.cdb[1] = IPR_SET_ALL_SUPPORTED_DEVICES;
  6470. ioarcb->cmd_pkt.cdb[7] = (sizeof(struct ipr_supported_device) >> 8) & 0xff;
  6471. ioarcb->cmd_pkt.cdb[8] = sizeof(struct ipr_supported_device) & 0xff;
  6472. ipr_init_ioadl(ipr_cmd,
  6473. ioa_cfg->vpd_cbs_dma +
  6474. offsetof(struct ipr_misc_cbs, supp_dev),
  6475. sizeof(struct ipr_supported_device),
  6476. IPR_IOADL_FLAGS_WRITE_LAST);
  6477. ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout,
  6478. IPR_SET_SUP_DEVICE_TIMEOUT);
  6479. if (!ioa_cfg->sis64)
  6480. ipr_cmd->job_step = ipr_set_supported_devs;
  6481. LEAVE;
  6482. return IPR_RC_JOB_RETURN;
  6483. }
  6484. LEAVE;
  6485. return IPR_RC_JOB_CONTINUE;
  6486. }
  6487. /**
  6488. * ipr_get_mode_page - Locate specified mode page
  6489. * @mode_pages: mode page buffer
  6490. * @page_code: page code to find
  6491. * @len: minimum required length for mode page
  6492. *
  6493. * Return value:
  6494. * pointer to mode page / NULL on failure
  6495. **/
  6496. static void *ipr_get_mode_page(struct ipr_mode_pages *mode_pages,
  6497. u32 page_code, u32 len)
  6498. {
  6499. struct ipr_mode_page_hdr *mode_hdr;
  6500. u32 page_length;
  6501. u32 length;
  6502. if (!mode_pages || (mode_pages->hdr.length == 0))
  6503. return NULL;
  6504. length = (mode_pages->hdr.length + 1) - 4 - mode_pages->hdr.block_desc_len;
  6505. mode_hdr = (struct ipr_mode_page_hdr *)
  6506. (mode_pages->data + mode_pages->hdr.block_desc_len);
  6507. while (length) {
  6508. if (IPR_GET_MODE_PAGE_CODE(mode_hdr) == page_code) {
  6509. if (mode_hdr->page_length >= (len - sizeof(struct ipr_mode_page_hdr)))
  6510. return mode_hdr;
  6511. break;
  6512. } else {
  6513. page_length = (sizeof(struct ipr_mode_page_hdr) +
  6514. mode_hdr->page_length);
  6515. length -= page_length;
  6516. mode_hdr = (struct ipr_mode_page_hdr *)
  6517. ((unsigned long)mode_hdr + page_length);
  6518. }
  6519. }
  6520. return NULL;
  6521. }
  6522. /**
  6523. * ipr_check_term_power - Check for term power errors
  6524. * @ioa_cfg: ioa config struct
  6525. * @mode_pages: IOAFP mode pages buffer
  6526. *
  6527. * Check the IOAFP's mode page 28 for term power errors
  6528. *
  6529. * Return value:
  6530. * nothing
  6531. **/
  6532. static void ipr_check_term_power(struct ipr_ioa_cfg *ioa_cfg,
  6533. struct ipr_mode_pages *mode_pages)
  6534. {
  6535. int i;
  6536. int entry_length;
  6537. struct ipr_dev_bus_entry *bus;
  6538. struct ipr_mode_page28 *mode_page;
  6539. mode_page = ipr_get_mode_page(mode_pages, 0x28,
  6540. sizeof(struct ipr_mode_page28));
  6541. entry_length = mode_page->entry_length;
  6542. bus = mode_page->bus;
  6543. for (i = 0; i < mode_page->num_entries; i++) {
  6544. if (bus->flags & IPR_SCSI_ATTR_NO_TERM_PWR) {
  6545. dev_err(&ioa_cfg->pdev->dev,
  6546. "Term power is absent on scsi bus %d\n",
  6547. bus->res_addr.bus);
  6548. }
  6549. bus = (struct ipr_dev_bus_entry *)((char *)bus + entry_length);
  6550. }
  6551. }
  6552. /**
  6553. * ipr_scsi_bus_speed_limit - Limit the SCSI speed based on SES table
  6554. * @ioa_cfg: ioa config struct
  6555. *
  6556. * Looks through the config table checking for SES devices. If
  6557. * the SES device is in the SES table indicating a maximum SCSI
  6558. * bus speed, the speed is limited for the bus.
  6559. *
  6560. * Return value:
  6561. * none
  6562. **/
  6563. static void ipr_scsi_bus_speed_limit(struct ipr_ioa_cfg *ioa_cfg)
  6564. {
  6565. u32 max_xfer_rate;
  6566. int i;
  6567. for (i = 0; i < IPR_MAX_NUM_BUSES; i++) {
  6568. max_xfer_rate = ipr_get_max_scsi_speed(ioa_cfg, i,
  6569. ioa_cfg->bus_attr[i].bus_width);
  6570. if (max_xfer_rate < ioa_cfg->bus_attr[i].max_xfer_rate)
  6571. ioa_cfg->bus_attr[i].max_xfer_rate = max_xfer_rate;
  6572. }
  6573. }
  6574. /**
  6575. * ipr_modify_ioafp_mode_page_28 - Modify IOAFP Mode Page 28
  6576. * @ioa_cfg: ioa config struct
  6577. * @mode_pages: mode page 28 buffer
  6578. *
  6579. * Updates mode page 28 based on driver configuration
  6580. *
  6581. * Return value:
  6582. * none
  6583. **/
  6584. static void ipr_modify_ioafp_mode_page_28(struct ipr_ioa_cfg *ioa_cfg,
  6585. struct ipr_mode_pages *mode_pages)
  6586. {
  6587. int i, entry_length;
  6588. struct ipr_dev_bus_entry *bus;
  6589. struct ipr_bus_attributes *bus_attr;
  6590. struct ipr_mode_page28 *mode_page;
  6591. mode_page = ipr_get_mode_page(mode_pages, 0x28,
  6592. sizeof(struct ipr_mode_page28));
  6593. entry_length = mode_page->entry_length;
  6594. /* Loop for each device bus entry */
  6595. for (i = 0, bus = mode_page->bus;
  6596. i < mode_page->num_entries;
  6597. i++, bus = (struct ipr_dev_bus_entry *)((u8 *)bus + entry_length)) {
  6598. if (bus->res_addr.bus > IPR_MAX_NUM_BUSES) {
  6599. dev_err(&ioa_cfg->pdev->dev,
  6600. "Invalid resource address reported: 0x%08X\n",
  6601. IPR_GET_PHYS_LOC(bus->res_addr));
  6602. continue;
  6603. }
  6604. bus_attr = &ioa_cfg->bus_attr[i];
  6605. bus->extended_reset_delay = IPR_EXTENDED_RESET_DELAY;
  6606. bus->bus_width = bus_attr->bus_width;
  6607. bus->max_xfer_rate = cpu_to_be32(bus_attr->max_xfer_rate);
  6608. bus->flags &= ~IPR_SCSI_ATTR_QAS_MASK;
  6609. if (bus_attr->qas_enabled)
  6610. bus->flags |= IPR_SCSI_ATTR_ENABLE_QAS;
  6611. else
  6612. bus->flags |= IPR_SCSI_ATTR_DISABLE_QAS;
  6613. }
  6614. }
  6615. /**
  6616. * ipr_build_mode_select - Build a mode select command
  6617. * @ipr_cmd: ipr command struct
  6618. * @res_handle: resource handle to send command to
  6619. * @parm: Byte 2 of Mode Sense command
  6620. * @dma_addr: DMA buffer address
  6621. * @xfer_len: data transfer length
  6622. *
  6623. * Return value:
  6624. * none
  6625. **/
  6626. static void ipr_build_mode_select(struct ipr_cmnd *ipr_cmd,
  6627. __be32 res_handle, u8 parm,
  6628. dma_addr_t dma_addr, u8 xfer_len)
  6629. {
  6630. struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
  6631. ioarcb->res_handle = res_handle;
  6632. ioarcb->cmd_pkt.request_type = IPR_RQTYPE_SCSICDB;
  6633. ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
  6634. ioarcb->cmd_pkt.cdb[0] = MODE_SELECT;
  6635. ioarcb->cmd_pkt.cdb[1] = parm;
  6636. ioarcb->cmd_pkt.cdb[4] = xfer_len;
  6637. ipr_init_ioadl(ipr_cmd, dma_addr, xfer_len, IPR_IOADL_FLAGS_WRITE_LAST);
  6638. }
  6639. /**
  6640. * ipr_ioafp_mode_select_page28 - Issue Mode Select Page 28 to IOA
  6641. * @ipr_cmd: ipr command struct
  6642. *
  6643. * This function sets up the SCSI bus attributes and sends
  6644. * a Mode Select for Page 28 to activate them.
  6645. *
  6646. * Return value:
  6647. * IPR_RC_JOB_RETURN
  6648. **/
  6649. static int ipr_ioafp_mode_select_page28(struct ipr_cmnd *ipr_cmd)
  6650. {
  6651. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  6652. struct ipr_mode_pages *mode_pages = &ioa_cfg->vpd_cbs->mode_pages;
  6653. int length;
  6654. ENTER;
  6655. ipr_scsi_bus_speed_limit(ioa_cfg);
  6656. ipr_check_term_power(ioa_cfg, mode_pages);
  6657. ipr_modify_ioafp_mode_page_28(ioa_cfg, mode_pages);
  6658. length = mode_pages->hdr.length + 1;
  6659. mode_pages->hdr.length = 0;
  6660. ipr_build_mode_select(ipr_cmd, cpu_to_be32(IPR_IOA_RES_HANDLE), 0x11,
  6661. ioa_cfg->vpd_cbs_dma + offsetof(struct ipr_misc_cbs, mode_pages),
  6662. length);
  6663. ipr_cmd->job_step = ipr_set_supported_devs;
  6664. ipr_cmd->u.res = list_entry(ioa_cfg->used_res_q.next,
  6665. struct ipr_resource_entry, queue);
  6666. ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, IPR_INTERNAL_TIMEOUT);
  6667. LEAVE;
  6668. return IPR_RC_JOB_RETURN;
  6669. }
  6670. /**
  6671. * ipr_build_mode_sense - Builds a mode sense command
  6672. * @ipr_cmd: ipr command struct
  6673. * @res: resource entry struct
  6674. * @parm: Byte 2 of mode sense command
  6675. * @dma_addr: DMA address of mode sense buffer
  6676. * @xfer_len: Size of DMA buffer
  6677. *
  6678. * Return value:
  6679. * none
  6680. **/
  6681. static void ipr_build_mode_sense(struct ipr_cmnd *ipr_cmd,
  6682. __be32 res_handle,
  6683. u8 parm, dma_addr_t dma_addr, u8 xfer_len)
  6684. {
  6685. struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
  6686. ioarcb->res_handle = res_handle;
  6687. ioarcb->cmd_pkt.cdb[0] = MODE_SENSE;
  6688. ioarcb->cmd_pkt.cdb[2] = parm;
  6689. ioarcb->cmd_pkt.cdb[4] = xfer_len;
  6690. ioarcb->cmd_pkt.request_type = IPR_RQTYPE_SCSICDB;
  6691. ipr_init_ioadl(ipr_cmd, dma_addr, xfer_len, IPR_IOADL_FLAGS_READ_LAST);
  6692. }
  6693. /**
  6694. * ipr_reset_cmd_failed - Handle failure of IOA reset command
  6695. * @ipr_cmd: ipr command struct
  6696. *
  6697. * This function handles the failure of an IOA bringup command.
  6698. *
  6699. * Return value:
  6700. * IPR_RC_JOB_RETURN
  6701. **/
  6702. static int ipr_reset_cmd_failed(struct ipr_cmnd *ipr_cmd)
  6703. {
  6704. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  6705. u32 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
  6706. dev_err(&ioa_cfg->pdev->dev,
  6707. "0x%02X failed with IOASC: 0x%08X\n",
  6708. ipr_cmd->ioarcb.cmd_pkt.cdb[0], ioasc);
  6709. ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
  6710. list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_free_q);
  6711. return IPR_RC_JOB_RETURN;
  6712. }
  6713. /**
  6714. * ipr_reset_mode_sense_failed - Handle failure of IOAFP mode sense
  6715. * @ipr_cmd: ipr command struct
  6716. *
  6717. * This function handles the failure of a Mode Sense to the IOAFP.
  6718. * Some adapters do not handle all mode pages.
  6719. *
  6720. * Return value:
  6721. * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
  6722. **/
  6723. static int ipr_reset_mode_sense_failed(struct ipr_cmnd *ipr_cmd)
  6724. {
  6725. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  6726. u32 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
  6727. if (ioasc == IPR_IOASC_IR_INVALID_REQ_TYPE_OR_PKT) {
  6728. ipr_cmd->job_step = ipr_set_supported_devs;
  6729. ipr_cmd->u.res = list_entry(ioa_cfg->used_res_q.next,
  6730. struct ipr_resource_entry, queue);
  6731. return IPR_RC_JOB_CONTINUE;
  6732. }
  6733. return ipr_reset_cmd_failed(ipr_cmd);
  6734. }
  6735. /**
  6736. * ipr_ioafp_mode_sense_page28 - Issue Mode Sense Page 28 to IOA
  6737. * @ipr_cmd: ipr command struct
  6738. *
  6739. * This function send a Page 28 mode sense to the IOA to
  6740. * retrieve SCSI bus attributes.
  6741. *
  6742. * Return value:
  6743. * IPR_RC_JOB_RETURN
  6744. **/
  6745. static int ipr_ioafp_mode_sense_page28(struct ipr_cmnd *ipr_cmd)
  6746. {
  6747. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  6748. ENTER;
  6749. ipr_build_mode_sense(ipr_cmd, cpu_to_be32(IPR_IOA_RES_HANDLE),
  6750. 0x28, ioa_cfg->vpd_cbs_dma +
  6751. offsetof(struct ipr_misc_cbs, mode_pages),
  6752. sizeof(struct ipr_mode_pages));
  6753. ipr_cmd->job_step = ipr_ioafp_mode_select_page28;
  6754. ipr_cmd->job_step_failed = ipr_reset_mode_sense_failed;
  6755. ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, IPR_INTERNAL_TIMEOUT);
  6756. LEAVE;
  6757. return IPR_RC_JOB_RETURN;
  6758. }
  6759. /**
  6760. * ipr_ioafp_mode_select_page24 - Issue Mode Select to IOA
  6761. * @ipr_cmd: ipr command struct
  6762. *
  6763. * This function enables dual IOA RAID support if possible.
  6764. *
  6765. * Return value:
  6766. * IPR_RC_JOB_RETURN
  6767. **/
  6768. static int ipr_ioafp_mode_select_page24(struct ipr_cmnd *ipr_cmd)
  6769. {
  6770. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  6771. struct ipr_mode_pages *mode_pages = &ioa_cfg->vpd_cbs->mode_pages;
  6772. struct ipr_mode_page24 *mode_page;
  6773. int length;
  6774. ENTER;
  6775. mode_page = ipr_get_mode_page(mode_pages, 0x24,
  6776. sizeof(struct ipr_mode_page24));
  6777. if (mode_page)
  6778. mode_page->flags |= IPR_ENABLE_DUAL_IOA_AF;
  6779. length = mode_pages->hdr.length + 1;
  6780. mode_pages->hdr.length = 0;
  6781. ipr_build_mode_select(ipr_cmd, cpu_to_be32(IPR_IOA_RES_HANDLE), 0x11,
  6782. ioa_cfg->vpd_cbs_dma + offsetof(struct ipr_misc_cbs, mode_pages),
  6783. length);
  6784. ipr_cmd->job_step = ipr_ioafp_mode_sense_page28;
  6785. ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, IPR_INTERNAL_TIMEOUT);
  6786. LEAVE;
  6787. return IPR_RC_JOB_RETURN;
  6788. }
  6789. /**
  6790. * ipr_reset_mode_sense_page24_failed - Handle failure of IOAFP mode sense
  6791. * @ipr_cmd: ipr command struct
  6792. *
  6793. * This function handles the failure of a Mode Sense to the IOAFP.
  6794. * Some adapters do not handle all mode pages.
  6795. *
  6796. * Return value:
  6797. * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
  6798. **/
  6799. static int ipr_reset_mode_sense_page24_failed(struct ipr_cmnd *ipr_cmd)
  6800. {
  6801. u32 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
  6802. if (ioasc == IPR_IOASC_IR_INVALID_REQ_TYPE_OR_PKT) {
  6803. ipr_cmd->job_step = ipr_ioafp_mode_sense_page28;
  6804. return IPR_RC_JOB_CONTINUE;
  6805. }
  6806. return ipr_reset_cmd_failed(ipr_cmd);
  6807. }
  6808. /**
  6809. * ipr_ioafp_mode_sense_page24 - Issue Page 24 Mode Sense to IOA
  6810. * @ipr_cmd: ipr command struct
  6811. *
  6812. * This function send a mode sense to the IOA to retrieve
  6813. * the IOA Advanced Function Control mode page.
  6814. *
  6815. * Return value:
  6816. * IPR_RC_JOB_RETURN
  6817. **/
  6818. static int ipr_ioafp_mode_sense_page24(struct ipr_cmnd *ipr_cmd)
  6819. {
  6820. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  6821. ENTER;
  6822. ipr_build_mode_sense(ipr_cmd, cpu_to_be32(IPR_IOA_RES_HANDLE),
  6823. 0x24, ioa_cfg->vpd_cbs_dma +
  6824. offsetof(struct ipr_misc_cbs, mode_pages),
  6825. sizeof(struct ipr_mode_pages));
  6826. ipr_cmd->job_step = ipr_ioafp_mode_select_page24;
  6827. ipr_cmd->job_step_failed = ipr_reset_mode_sense_page24_failed;
  6828. ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, IPR_INTERNAL_TIMEOUT);
  6829. LEAVE;
  6830. return IPR_RC_JOB_RETURN;
  6831. }
  6832. /**
  6833. * ipr_init_res_table - Initialize the resource table
  6834. * @ipr_cmd: ipr command struct
  6835. *
  6836. * This function looks through the existing resource table, comparing
  6837. * it with the config table. This function will take care of old/new
  6838. * devices and schedule adding/removing them from the mid-layer
  6839. * as appropriate.
  6840. *
  6841. * Return value:
  6842. * IPR_RC_JOB_CONTINUE
  6843. **/
  6844. static int ipr_init_res_table(struct ipr_cmnd *ipr_cmd)
  6845. {
  6846. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  6847. struct ipr_resource_entry *res, *temp;
  6848. struct ipr_config_table_entry_wrapper cfgtew;
  6849. int entries, found, flag, i;
  6850. LIST_HEAD(old_res);
  6851. ENTER;
  6852. if (ioa_cfg->sis64)
  6853. flag = ioa_cfg->u.cfg_table64->hdr64.flags;
  6854. else
  6855. flag = ioa_cfg->u.cfg_table->hdr.flags;
  6856. if (flag & IPR_UCODE_DOWNLOAD_REQ)
  6857. dev_err(&ioa_cfg->pdev->dev, "Microcode download required\n");
  6858. list_for_each_entry_safe(res, temp, &ioa_cfg->used_res_q, queue)
  6859. list_move_tail(&res->queue, &old_res);
  6860. if (ioa_cfg->sis64)
  6861. entries = be16_to_cpu(ioa_cfg->u.cfg_table64->hdr64.num_entries);
  6862. else
  6863. entries = ioa_cfg->u.cfg_table->hdr.num_entries;
  6864. for (i = 0; i < entries; i++) {
  6865. if (ioa_cfg->sis64)
  6866. cfgtew.u.cfgte64 = &ioa_cfg->u.cfg_table64->dev[i];
  6867. else
  6868. cfgtew.u.cfgte = &ioa_cfg->u.cfg_table->dev[i];
  6869. found = 0;
  6870. list_for_each_entry_safe(res, temp, &old_res, queue) {
  6871. if (ipr_is_same_device(res, &cfgtew)) {
  6872. list_move_tail(&res->queue, &ioa_cfg->used_res_q);
  6873. found = 1;
  6874. break;
  6875. }
  6876. }
  6877. if (!found) {
  6878. if (list_empty(&ioa_cfg->free_res_q)) {
  6879. dev_err(&ioa_cfg->pdev->dev, "Too many devices attached\n");
  6880. break;
  6881. }
  6882. found = 1;
  6883. res = list_entry(ioa_cfg->free_res_q.next,
  6884. struct ipr_resource_entry, queue);
  6885. list_move_tail(&res->queue, &ioa_cfg->used_res_q);
  6886. ipr_init_res_entry(res, &cfgtew);
  6887. res->add_to_ml = 1;
  6888. } else if (res->sdev && (ipr_is_vset_device(res) || ipr_is_scsi_disk(res)))
  6889. res->sdev->allow_restart = 1;
  6890. if (found)
  6891. ipr_update_res_entry(res, &cfgtew);
  6892. }
  6893. list_for_each_entry_safe(res, temp, &old_res, queue) {
  6894. if (res->sdev) {
  6895. res->del_from_ml = 1;
  6896. res->res_handle = IPR_INVALID_RES_HANDLE;
  6897. list_move_tail(&res->queue, &ioa_cfg->used_res_q);
  6898. }
  6899. }
  6900. list_for_each_entry_safe(res, temp, &old_res, queue) {
  6901. ipr_clear_res_target(res);
  6902. list_move_tail(&res->queue, &ioa_cfg->free_res_q);
  6903. }
  6904. if (ioa_cfg->dual_raid && ipr_dual_ioa_raid)
  6905. ipr_cmd->job_step = ipr_ioafp_mode_sense_page24;
  6906. else
  6907. ipr_cmd->job_step = ipr_ioafp_mode_sense_page28;
  6908. LEAVE;
  6909. return IPR_RC_JOB_CONTINUE;
  6910. }
  6911. /**
  6912. * ipr_ioafp_query_ioa_cfg - Send a Query IOA Config to the adapter.
  6913. * @ipr_cmd: ipr command struct
  6914. *
  6915. * This function sends a Query IOA Configuration command
  6916. * to the adapter to retrieve the IOA configuration table.
  6917. *
  6918. * Return value:
  6919. * IPR_RC_JOB_RETURN
  6920. **/
  6921. static int ipr_ioafp_query_ioa_cfg(struct ipr_cmnd *ipr_cmd)
  6922. {
  6923. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  6924. struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
  6925. struct ipr_inquiry_page3 *ucode_vpd = &ioa_cfg->vpd_cbs->page3_data;
  6926. struct ipr_inquiry_cap *cap = &ioa_cfg->vpd_cbs->cap;
  6927. ENTER;
  6928. if (cap->cap & IPR_CAP_DUAL_IOA_RAID)
  6929. ioa_cfg->dual_raid = 1;
  6930. dev_info(&ioa_cfg->pdev->dev, "Adapter firmware version: %02X%02X%02X%02X\n",
  6931. ucode_vpd->major_release, ucode_vpd->card_type,
  6932. ucode_vpd->minor_release[0], ucode_vpd->minor_release[1]);
  6933. ioarcb->cmd_pkt.request_type = IPR_RQTYPE_IOACMD;
  6934. ioarcb->res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
  6935. ioarcb->cmd_pkt.cdb[0] = IPR_QUERY_IOA_CONFIG;
  6936. ioarcb->cmd_pkt.cdb[6] = (ioa_cfg->cfg_table_size >> 16) & 0xff;
  6937. ioarcb->cmd_pkt.cdb[7] = (ioa_cfg->cfg_table_size >> 8) & 0xff;
  6938. ioarcb->cmd_pkt.cdb[8] = ioa_cfg->cfg_table_size & 0xff;
  6939. ipr_init_ioadl(ipr_cmd, ioa_cfg->cfg_table_dma, ioa_cfg->cfg_table_size,
  6940. IPR_IOADL_FLAGS_READ_LAST);
  6941. ipr_cmd->job_step = ipr_init_res_table;
  6942. ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, IPR_INTERNAL_TIMEOUT);
  6943. LEAVE;
  6944. return IPR_RC_JOB_RETURN;
  6945. }
  6946. static int ipr_ioa_service_action_failed(struct ipr_cmnd *ipr_cmd)
  6947. {
  6948. u32 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
  6949. if (ioasc == IPR_IOASC_IR_INVALID_REQ_TYPE_OR_PKT)
  6950. return IPR_RC_JOB_CONTINUE;
  6951. return ipr_reset_cmd_failed(ipr_cmd);
  6952. }
  6953. static void ipr_build_ioa_service_action(struct ipr_cmnd *ipr_cmd,
  6954. __be32 res_handle, u8 sa_code)
  6955. {
  6956. struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
  6957. ioarcb->res_handle = res_handle;
  6958. ioarcb->cmd_pkt.cdb[0] = IPR_IOA_SERVICE_ACTION;
  6959. ioarcb->cmd_pkt.cdb[1] = sa_code;
  6960. ioarcb->cmd_pkt.request_type = IPR_RQTYPE_IOACMD;
  6961. }
  6962. /**
  6963. * ipr_ioafp_set_caching_parameters - Issue Set Cache parameters service
  6964. * action
  6965. *
  6966. * Return value:
  6967. * none
  6968. **/
  6969. static int ipr_ioafp_set_caching_parameters(struct ipr_cmnd *ipr_cmd)
  6970. {
  6971. struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
  6972. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  6973. struct ipr_inquiry_pageC4 *pageC4 = &ioa_cfg->vpd_cbs->pageC4_data;
  6974. ENTER;
  6975. ipr_cmd->job_step = ipr_ioafp_query_ioa_cfg;
  6976. if (pageC4->cache_cap[0] & IPR_CAP_SYNC_CACHE) {
  6977. ipr_build_ioa_service_action(ipr_cmd,
  6978. cpu_to_be32(IPR_IOA_RES_HANDLE),
  6979. IPR_IOA_SA_CHANGE_CACHE_PARAMS);
  6980. ioarcb->cmd_pkt.cdb[2] = 0x40;
  6981. ipr_cmd->job_step_failed = ipr_ioa_service_action_failed;
  6982. ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout,
  6983. IPR_SET_SUP_DEVICE_TIMEOUT);
  6984. LEAVE;
  6985. return IPR_RC_JOB_RETURN;
  6986. }
  6987. LEAVE;
  6988. return IPR_RC_JOB_CONTINUE;
  6989. }
  6990. /**
  6991. * ipr_ioafp_inquiry - Send an Inquiry to the adapter.
  6992. * @ipr_cmd: ipr command struct
  6993. *
  6994. * This utility function sends an inquiry to the adapter.
  6995. *
  6996. * Return value:
  6997. * none
  6998. **/
  6999. static void ipr_ioafp_inquiry(struct ipr_cmnd *ipr_cmd, u8 flags, u8 page,
  7000. dma_addr_t dma_addr, u8 xfer_len)
  7001. {
  7002. struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
  7003. ENTER;
  7004. ioarcb->cmd_pkt.request_type = IPR_RQTYPE_SCSICDB;
  7005. ioarcb->res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
  7006. ioarcb->cmd_pkt.cdb[0] = INQUIRY;
  7007. ioarcb->cmd_pkt.cdb[1] = flags;
  7008. ioarcb->cmd_pkt.cdb[2] = page;
  7009. ioarcb->cmd_pkt.cdb[4] = xfer_len;
  7010. ipr_init_ioadl(ipr_cmd, dma_addr, xfer_len, IPR_IOADL_FLAGS_READ_LAST);
  7011. ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, IPR_INTERNAL_TIMEOUT);
  7012. LEAVE;
  7013. }
  7014. /**
  7015. * ipr_inquiry_page_supported - Is the given inquiry page supported
  7016. * @page0: inquiry page 0 buffer
  7017. * @page: page code.
  7018. *
  7019. * This function determines if the specified inquiry page is supported.
  7020. *
  7021. * Return value:
  7022. * 1 if page is supported / 0 if not
  7023. **/
  7024. static int ipr_inquiry_page_supported(struct ipr_inquiry_page0 *page0, u8 page)
  7025. {
  7026. int i;
  7027. for (i = 0; i < min_t(u8, page0->len, IPR_INQUIRY_PAGE0_ENTRIES); i++)
  7028. if (page0->page[i] == page)
  7029. return 1;
  7030. return 0;
  7031. }
  7032. /**
  7033. * ipr_ioafp_pageC4_inquiry - Send a Page 0xC4 Inquiry to the adapter.
  7034. * @ipr_cmd: ipr command struct
  7035. *
  7036. * This function sends a Page 0xC4 inquiry to the adapter
  7037. * to retrieve software VPD information.
  7038. *
  7039. * Return value:
  7040. * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
  7041. **/
  7042. static int ipr_ioafp_pageC4_inquiry(struct ipr_cmnd *ipr_cmd)
  7043. {
  7044. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  7045. struct ipr_inquiry_page0 *page0 = &ioa_cfg->vpd_cbs->page0_data;
  7046. struct ipr_inquiry_pageC4 *pageC4 = &ioa_cfg->vpd_cbs->pageC4_data;
  7047. ENTER;
  7048. ipr_cmd->job_step = ipr_ioafp_set_caching_parameters;
  7049. memset(pageC4, 0, sizeof(*pageC4));
  7050. if (ipr_inquiry_page_supported(page0, 0xC4)) {
  7051. ipr_ioafp_inquiry(ipr_cmd, 1, 0xC4,
  7052. (ioa_cfg->vpd_cbs_dma
  7053. + offsetof(struct ipr_misc_cbs,
  7054. pageC4_data)),
  7055. sizeof(struct ipr_inquiry_pageC4));
  7056. return IPR_RC_JOB_RETURN;
  7057. }
  7058. LEAVE;
  7059. return IPR_RC_JOB_CONTINUE;
  7060. }
  7061. /**
  7062. * ipr_ioafp_cap_inquiry - Send a Page 0xD0 Inquiry to the adapter.
  7063. * @ipr_cmd: ipr command struct
  7064. *
  7065. * This function sends a Page 0xD0 inquiry to the adapter
  7066. * to retrieve adapter capabilities.
  7067. *
  7068. * Return value:
  7069. * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
  7070. **/
  7071. static int ipr_ioafp_cap_inquiry(struct ipr_cmnd *ipr_cmd)
  7072. {
  7073. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  7074. struct ipr_inquiry_page0 *page0 = &ioa_cfg->vpd_cbs->page0_data;
  7075. struct ipr_inquiry_cap *cap = &ioa_cfg->vpd_cbs->cap;
  7076. ENTER;
  7077. ipr_cmd->job_step = ipr_ioafp_pageC4_inquiry;
  7078. memset(cap, 0, sizeof(*cap));
  7079. if (ipr_inquiry_page_supported(page0, 0xD0)) {
  7080. ipr_ioafp_inquiry(ipr_cmd, 1, 0xD0,
  7081. ioa_cfg->vpd_cbs_dma + offsetof(struct ipr_misc_cbs, cap),
  7082. sizeof(struct ipr_inquiry_cap));
  7083. return IPR_RC_JOB_RETURN;
  7084. }
  7085. LEAVE;
  7086. return IPR_RC_JOB_CONTINUE;
  7087. }
  7088. /**
  7089. * ipr_ioafp_page3_inquiry - Send a Page 3 Inquiry to the adapter.
  7090. * @ipr_cmd: ipr command struct
  7091. *
  7092. * This function sends a Page 3 inquiry to the adapter
  7093. * to retrieve software VPD information.
  7094. *
  7095. * Return value:
  7096. * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
  7097. **/
  7098. static int ipr_ioafp_page3_inquiry(struct ipr_cmnd *ipr_cmd)
  7099. {
  7100. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  7101. ENTER;
  7102. ipr_cmd->job_step = ipr_ioafp_cap_inquiry;
  7103. ipr_ioafp_inquiry(ipr_cmd, 1, 3,
  7104. ioa_cfg->vpd_cbs_dma + offsetof(struct ipr_misc_cbs, page3_data),
  7105. sizeof(struct ipr_inquiry_page3));
  7106. LEAVE;
  7107. return IPR_RC_JOB_RETURN;
  7108. }
  7109. /**
  7110. * ipr_ioafp_page0_inquiry - Send a Page 0 Inquiry to the adapter.
  7111. * @ipr_cmd: ipr command struct
  7112. *
  7113. * This function sends a Page 0 inquiry to the adapter
  7114. * to retrieve supported inquiry pages.
  7115. *
  7116. * Return value:
  7117. * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
  7118. **/
  7119. static int ipr_ioafp_page0_inquiry(struct ipr_cmnd *ipr_cmd)
  7120. {
  7121. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  7122. char type[5];
  7123. ENTER;
  7124. /* Grab the type out of the VPD and store it away */
  7125. memcpy(type, ioa_cfg->vpd_cbs->ioa_vpd.std_inq_data.vpids.product_id, 4);
  7126. type[4] = '\0';
  7127. ioa_cfg->type = simple_strtoul((char *)type, NULL, 16);
  7128. if (ipr_invalid_adapter(ioa_cfg)) {
  7129. dev_err(&ioa_cfg->pdev->dev,
  7130. "Adapter not supported in this hardware configuration.\n");
  7131. if (!ipr_testmode) {
  7132. ioa_cfg->reset_retries += IPR_NUM_RESET_RELOAD_RETRIES;
  7133. ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
  7134. list_add_tail(&ipr_cmd->queue,
  7135. &ioa_cfg->hrrq->hrrq_free_q);
  7136. return IPR_RC_JOB_RETURN;
  7137. }
  7138. }
  7139. ipr_cmd->job_step = ipr_ioafp_page3_inquiry;
  7140. ipr_ioafp_inquiry(ipr_cmd, 1, 0,
  7141. ioa_cfg->vpd_cbs_dma + offsetof(struct ipr_misc_cbs, page0_data),
  7142. sizeof(struct ipr_inquiry_page0));
  7143. LEAVE;
  7144. return IPR_RC_JOB_RETURN;
  7145. }
  7146. /**
  7147. * ipr_ioafp_std_inquiry - Send a Standard Inquiry to the adapter.
  7148. * @ipr_cmd: ipr command struct
  7149. *
  7150. * This function sends a standard inquiry to the adapter.
  7151. *
  7152. * Return value:
  7153. * IPR_RC_JOB_RETURN
  7154. **/
  7155. static int ipr_ioafp_std_inquiry(struct ipr_cmnd *ipr_cmd)
  7156. {
  7157. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  7158. ENTER;
  7159. ipr_cmd->job_step = ipr_ioafp_page0_inquiry;
  7160. ipr_ioafp_inquiry(ipr_cmd, 0, 0,
  7161. ioa_cfg->vpd_cbs_dma + offsetof(struct ipr_misc_cbs, ioa_vpd),
  7162. sizeof(struct ipr_ioa_vpd));
  7163. LEAVE;
  7164. return IPR_RC_JOB_RETURN;
  7165. }
  7166. /**
  7167. * ipr_ioafp_identify_hrrq - Send Identify Host RRQ.
  7168. * @ipr_cmd: ipr command struct
  7169. *
  7170. * This function send an Identify Host Request Response Queue
  7171. * command to establish the HRRQ with the adapter.
  7172. *
  7173. * Return value:
  7174. * IPR_RC_JOB_RETURN
  7175. **/
  7176. static int ipr_ioafp_identify_hrrq(struct ipr_cmnd *ipr_cmd)
  7177. {
  7178. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  7179. struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
  7180. struct ipr_hrr_queue *hrrq;
  7181. ENTER;
  7182. ipr_cmd->job_step = ipr_ioafp_std_inquiry;
  7183. if (ioa_cfg->identify_hrrq_index == 0)
  7184. dev_info(&ioa_cfg->pdev->dev, "Starting IOA initialization sequence.\n");
  7185. if (ioa_cfg->identify_hrrq_index < ioa_cfg->hrrq_num) {
  7186. hrrq = &ioa_cfg->hrrq[ioa_cfg->identify_hrrq_index];
  7187. ioarcb->cmd_pkt.cdb[0] = IPR_ID_HOST_RR_Q;
  7188. ioarcb->res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
  7189. ioarcb->cmd_pkt.request_type = IPR_RQTYPE_IOACMD;
  7190. if (ioa_cfg->sis64)
  7191. ioarcb->cmd_pkt.cdb[1] = 0x1;
  7192. if (ioa_cfg->nvectors == 1)
  7193. ioarcb->cmd_pkt.cdb[1] &= ~IPR_ID_HRRQ_SELE_ENABLE;
  7194. else
  7195. ioarcb->cmd_pkt.cdb[1] |= IPR_ID_HRRQ_SELE_ENABLE;
  7196. ioarcb->cmd_pkt.cdb[2] =
  7197. ((u64) hrrq->host_rrq_dma >> 24) & 0xff;
  7198. ioarcb->cmd_pkt.cdb[3] =
  7199. ((u64) hrrq->host_rrq_dma >> 16) & 0xff;
  7200. ioarcb->cmd_pkt.cdb[4] =
  7201. ((u64) hrrq->host_rrq_dma >> 8) & 0xff;
  7202. ioarcb->cmd_pkt.cdb[5] =
  7203. ((u64) hrrq->host_rrq_dma) & 0xff;
  7204. ioarcb->cmd_pkt.cdb[7] =
  7205. ((sizeof(u32) * hrrq->size) >> 8) & 0xff;
  7206. ioarcb->cmd_pkt.cdb[8] =
  7207. (sizeof(u32) * hrrq->size) & 0xff;
  7208. if (ioarcb->cmd_pkt.cdb[1] & IPR_ID_HRRQ_SELE_ENABLE)
  7209. ioarcb->cmd_pkt.cdb[9] =
  7210. ioa_cfg->identify_hrrq_index;
  7211. if (ioa_cfg->sis64) {
  7212. ioarcb->cmd_pkt.cdb[10] =
  7213. ((u64) hrrq->host_rrq_dma >> 56) & 0xff;
  7214. ioarcb->cmd_pkt.cdb[11] =
  7215. ((u64) hrrq->host_rrq_dma >> 48) & 0xff;
  7216. ioarcb->cmd_pkt.cdb[12] =
  7217. ((u64) hrrq->host_rrq_dma >> 40) & 0xff;
  7218. ioarcb->cmd_pkt.cdb[13] =
  7219. ((u64) hrrq->host_rrq_dma >> 32) & 0xff;
  7220. }
  7221. if (ioarcb->cmd_pkt.cdb[1] & IPR_ID_HRRQ_SELE_ENABLE)
  7222. ioarcb->cmd_pkt.cdb[14] =
  7223. ioa_cfg->identify_hrrq_index;
  7224. ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout,
  7225. IPR_INTERNAL_TIMEOUT);
  7226. if (++ioa_cfg->identify_hrrq_index < ioa_cfg->hrrq_num)
  7227. ipr_cmd->job_step = ipr_ioafp_identify_hrrq;
  7228. LEAVE;
  7229. return IPR_RC_JOB_RETURN;
  7230. }
  7231. LEAVE;
  7232. return IPR_RC_JOB_CONTINUE;
  7233. }
  7234. /**
  7235. * ipr_reset_timer_done - Adapter reset timer function
  7236. * @ipr_cmd: ipr command struct
  7237. *
  7238. * Description: This function is used in adapter reset processing
  7239. * for timing events. If the reset_cmd pointer in the IOA
  7240. * config struct is not this adapter's we are doing nested
  7241. * resets and fail_all_ops will take care of freeing the
  7242. * command block.
  7243. *
  7244. * Return value:
  7245. * none
  7246. **/
  7247. static void ipr_reset_timer_done(struct timer_list *t)
  7248. {
  7249. struct ipr_cmnd *ipr_cmd = from_timer(ipr_cmd, t, timer);
  7250. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  7251. unsigned long lock_flags = 0;
  7252. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  7253. if (ioa_cfg->reset_cmd == ipr_cmd) {
  7254. list_del(&ipr_cmd->queue);
  7255. ipr_cmd->done(ipr_cmd);
  7256. }
  7257. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  7258. }
  7259. /**
  7260. * ipr_reset_start_timer - Start a timer for adapter reset job
  7261. * @ipr_cmd: ipr command struct
  7262. * @timeout: timeout value
  7263. *
  7264. * Description: This function is used in adapter reset processing
  7265. * for timing events. If the reset_cmd pointer in the IOA
  7266. * config struct is not this adapter's we are doing nested
  7267. * resets and fail_all_ops will take care of freeing the
  7268. * command block.
  7269. *
  7270. * Return value:
  7271. * none
  7272. **/
  7273. static void ipr_reset_start_timer(struct ipr_cmnd *ipr_cmd,
  7274. unsigned long timeout)
  7275. {
  7276. ENTER;
  7277. list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_pending_q);
  7278. ipr_cmd->done = ipr_reset_ioa_job;
  7279. ipr_cmd->timer.expires = jiffies + timeout;
  7280. ipr_cmd->timer.function = ipr_reset_timer_done;
  7281. add_timer(&ipr_cmd->timer);
  7282. }
  7283. /**
  7284. * ipr_init_ioa_mem - Initialize ioa_cfg control block
  7285. * @ioa_cfg: ioa cfg struct
  7286. *
  7287. * Return value:
  7288. * nothing
  7289. **/
  7290. static void ipr_init_ioa_mem(struct ipr_ioa_cfg *ioa_cfg)
  7291. {
  7292. struct ipr_hrr_queue *hrrq;
  7293. for_each_hrrq(hrrq, ioa_cfg) {
  7294. spin_lock(&hrrq->_lock);
  7295. memset(hrrq->host_rrq, 0, sizeof(u32) * hrrq->size);
  7296. /* Initialize Host RRQ pointers */
  7297. hrrq->hrrq_start = hrrq->host_rrq;
  7298. hrrq->hrrq_end = &hrrq->host_rrq[hrrq->size - 1];
  7299. hrrq->hrrq_curr = hrrq->hrrq_start;
  7300. hrrq->toggle_bit = 1;
  7301. spin_unlock(&hrrq->_lock);
  7302. }
  7303. wmb();
  7304. ioa_cfg->identify_hrrq_index = 0;
  7305. if (ioa_cfg->hrrq_num == 1)
  7306. atomic_set(&ioa_cfg->hrrq_index, 0);
  7307. else
  7308. atomic_set(&ioa_cfg->hrrq_index, 1);
  7309. /* Zero out config table */
  7310. memset(ioa_cfg->u.cfg_table, 0, ioa_cfg->cfg_table_size);
  7311. }
  7312. /**
  7313. * ipr_reset_next_stage - Process IPL stage change based on feedback register.
  7314. * @ipr_cmd: ipr command struct
  7315. *
  7316. * Return value:
  7317. * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
  7318. **/
  7319. static int ipr_reset_next_stage(struct ipr_cmnd *ipr_cmd)
  7320. {
  7321. unsigned long stage, stage_time;
  7322. u32 feedback;
  7323. volatile u32 int_reg;
  7324. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  7325. u64 maskval = 0;
  7326. feedback = readl(ioa_cfg->regs.init_feedback_reg);
  7327. stage = feedback & IPR_IPL_INIT_STAGE_MASK;
  7328. stage_time = feedback & IPR_IPL_INIT_STAGE_TIME_MASK;
  7329. ipr_dbg("IPL stage = 0x%lx, IPL stage time = %ld\n", stage, stage_time);
  7330. /* sanity check the stage_time value */
  7331. if (stage_time == 0)
  7332. stage_time = IPR_IPL_INIT_DEFAULT_STAGE_TIME;
  7333. else if (stage_time < IPR_IPL_INIT_MIN_STAGE_TIME)
  7334. stage_time = IPR_IPL_INIT_MIN_STAGE_TIME;
  7335. else if (stage_time > IPR_LONG_OPERATIONAL_TIMEOUT)
  7336. stage_time = IPR_LONG_OPERATIONAL_TIMEOUT;
  7337. if (stage == IPR_IPL_INIT_STAGE_UNKNOWN) {
  7338. writel(IPR_PCII_IPL_STAGE_CHANGE, ioa_cfg->regs.set_interrupt_mask_reg);
  7339. int_reg = readl(ioa_cfg->regs.sense_interrupt_mask_reg);
  7340. stage_time = ioa_cfg->transop_timeout;
  7341. ipr_cmd->job_step = ipr_ioafp_identify_hrrq;
  7342. } else if (stage == IPR_IPL_INIT_STAGE_TRANSOP) {
  7343. int_reg = readl(ioa_cfg->regs.sense_interrupt_reg32);
  7344. if (int_reg & IPR_PCII_IOA_TRANS_TO_OPER) {
  7345. ipr_cmd->job_step = ipr_ioafp_identify_hrrq;
  7346. maskval = IPR_PCII_IPL_STAGE_CHANGE;
  7347. maskval = (maskval << 32) | IPR_PCII_IOA_TRANS_TO_OPER;
  7348. writeq(maskval, ioa_cfg->regs.set_interrupt_mask_reg);
  7349. int_reg = readl(ioa_cfg->regs.sense_interrupt_mask_reg);
  7350. return IPR_RC_JOB_CONTINUE;
  7351. }
  7352. }
  7353. ipr_cmd->timer.expires = jiffies + stage_time * HZ;
  7354. ipr_cmd->timer.function = ipr_oper_timeout;
  7355. ipr_cmd->done = ipr_reset_ioa_job;
  7356. add_timer(&ipr_cmd->timer);
  7357. list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_pending_q);
  7358. return IPR_RC_JOB_RETURN;
  7359. }
  7360. /**
  7361. * ipr_reset_enable_ioa - Enable the IOA following a reset.
  7362. * @ipr_cmd: ipr command struct
  7363. *
  7364. * This function reinitializes some control blocks and
  7365. * enables destructive diagnostics on the adapter.
  7366. *
  7367. * Return value:
  7368. * IPR_RC_JOB_RETURN
  7369. **/
  7370. static int ipr_reset_enable_ioa(struct ipr_cmnd *ipr_cmd)
  7371. {
  7372. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  7373. volatile u32 int_reg;
  7374. volatile u64 maskval;
  7375. int i;
  7376. ENTER;
  7377. ipr_cmd->job_step = ipr_ioafp_identify_hrrq;
  7378. ipr_init_ioa_mem(ioa_cfg);
  7379. for (i = 0; i < ioa_cfg->hrrq_num; i++) {
  7380. spin_lock(&ioa_cfg->hrrq[i]._lock);
  7381. ioa_cfg->hrrq[i].allow_interrupts = 1;
  7382. spin_unlock(&ioa_cfg->hrrq[i]._lock);
  7383. }
  7384. if (ioa_cfg->sis64) {
  7385. /* Set the adapter to the correct endian mode. */
  7386. writel(IPR_ENDIAN_SWAP_KEY, ioa_cfg->regs.endian_swap_reg);
  7387. int_reg = readl(ioa_cfg->regs.endian_swap_reg);
  7388. }
  7389. int_reg = readl(ioa_cfg->regs.sense_interrupt_reg32);
  7390. if (int_reg & IPR_PCII_IOA_TRANS_TO_OPER) {
  7391. writel((IPR_PCII_ERROR_INTERRUPTS | IPR_PCII_HRRQ_UPDATED),
  7392. ioa_cfg->regs.clr_interrupt_mask_reg32);
  7393. int_reg = readl(ioa_cfg->regs.sense_interrupt_mask_reg);
  7394. return IPR_RC_JOB_CONTINUE;
  7395. }
  7396. /* Enable destructive diagnostics on IOA */
  7397. writel(ioa_cfg->doorbell, ioa_cfg->regs.set_uproc_interrupt_reg32);
  7398. if (ioa_cfg->sis64) {
  7399. maskval = IPR_PCII_IPL_STAGE_CHANGE;
  7400. maskval = (maskval << 32) | IPR_PCII_OPER_INTERRUPTS;
  7401. writeq(maskval, ioa_cfg->regs.clr_interrupt_mask_reg);
  7402. } else
  7403. writel(IPR_PCII_OPER_INTERRUPTS, ioa_cfg->regs.clr_interrupt_mask_reg32);
  7404. int_reg = readl(ioa_cfg->regs.sense_interrupt_mask_reg);
  7405. dev_info(&ioa_cfg->pdev->dev, "Initializing IOA.\n");
  7406. if (ioa_cfg->sis64) {
  7407. ipr_cmd->job_step = ipr_reset_next_stage;
  7408. return IPR_RC_JOB_CONTINUE;
  7409. }
  7410. ipr_cmd->timer.expires = jiffies + (ioa_cfg->transop_timeout * HZ);
  7411. ipr_cmd->timer.function = ipr_oper_timeout;
  7412. ipr_cmd->done = ipr_reset_ioa_job;
  7413. add_timer(&ipr_cmd->timer);
  7414. list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_pending_q);
  7415. LEAVE;
  7416. return IPR_RC_JOB_RETURN;
  7417. }
  7418. /**
  7419. * ipr_reset_wait_for_dump - Wait for a dump to timeout.
  7420. * @ipr_cmd: ipr command struct
  7421. *
  7422. * This function is invoked when an adapter dump has run out
  7423. * of processing time.
  7424. *
  7425. * Return value:
  7426. * IPR_RC_JOB_CONTINUE
  7427. **/
  7428. static int ipr_reset_wait_for_dump(struct ipr_cmnd *ipr_cmd)
  7429. {
  7430. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  7431. if (ioa_cfg->sdt_state == GET_DUMP)
  7432. ioa_cfg->sdt_state = WAIT_FOR_DUMP;
  7433. else if (ioa_cfg->sdt_state == READ_DUMP)
  7434. ioa_cfg->sdt_state = ABORT_DUMP;
  7435. ioa_cfg->dump_timeout = 1;
  7436. ipr_cmd->job_step = ipr_reset_alert;
  7437. return IPR_RC_JOB_CONTINUE;
  7438. }
  7439. /**
  7440. * ipr_unit_check_no_data - Log a unit check/no data error log
  7441. * @ioa_cfg: ioa config struct
  7442. *
  7443. * Logs an error indicating the adapter unit checked, but for some
  7444. * reason, we were unable to fetch the unit check buffer.
  7445. *
  7446. * Return value:
  7447. * nothing
  7448. **/
  7449. static void ipr_unit_check_no_data(struct ipr_ioa_cfg *ioa_cfg)
  7450. {
  7451. ioa_cfg->errors_logged++;
  7452. dev_err(&ioa_cfg->pdev->dev, "IOA unit check with no data\n");
  7453. }
  7454. /**
  7455. * ipr_get_unit_check_buffer - Get the unit check buffer from the IOA
  7456. * @ioa_cfg: ioa config struct
  7457. *
  7458. * Fetches the unit check buffer from the adapter by clocking the data
  7459. * through the mailbox register.
  7460. *
  7461. * Return value:
  7462. * nothing
  7463. **/
  7464. static void ipr_get_unit_check_buffer(struct ipr_ioa_cfg *ioa_cfg)
  7465. {
  7466. unsigned long mailbox;
  7467. struct ipr_hostrcb *hostrcb;
  7468. struct ipr_uc_sdt sdt;
  7469. int rc, length;
  7470. u32 ioasc;
  7471. mailbox = readl(ioa_cfg->ioa_mailbox);
  7472. if (!ioa_cfg->sis64 && !ipr_sdt_is_fmt2(mailbox)) {
  7473. ipr_unit_check_no_data(ioa_cfg);
  7474. return;
  7475. }
  7476. memset(&sdt, 0, sizeof(struct ipr_uc_sdt));
  7477. rc = ipr_get_ldump_data_section(ioa_cfg, mailbox, (__be32 *) &sdt,
  7478. (sizeof(struct ipr_uc_sdt)) / sizeof(__be32));
  7479. if (rc || !(sdt.entry[0].flags & IPR_SDT_VALID_ENTRY) ||
  7480. ((be32_to_cpu(sdt.hdr.state) != IPR_FMT3_SDT_READY_TO_USE) &&
  7481. (be32_to_cpu(sdt.hdr.state) != IPR_FMT2_SDT_READY_TO_USE))) {
  7482. ipr_unit_check_no_data(ioa_cfg);
  7483. return;
  7484. }
  7485. /* Find length of the first sdt entry (UC buffer) */
  7486. if (be32_to_cpu(sdt.hdr.state) == IPR_FMT3_SDT_READY_TO_USE)
  7487. length = be32_to_cpu(sdt.entry[0].end_token);
  7488. else
  7489. length = (be32_to_cpu(sdt.entry[0].end_token) -
  7490. be32_to_cpu(sdt.entry[0].start_token)) &
  7491. IPR_FMT2_MBX_ADDR_MASK;
  7492. hostrcb = list_entry(ioa_cfg->hostrcb_free_q.next,
  7493. struct ipr_hostrcb, queue);
  7494. list_del_init(&hostrcb->queue);
  7495. memset(&hostrcb->hcam, 0, sizeof(hostrcb->hcam));
  7496. rc = ipr_get_ldump_data_section(ioa_cfg,
  7497. be32_to_cpu(sdt.entry[0].start_token),
  7498. (__be32 *)&hostrcb->hcam,
  7499. min(length, (int)sizeof(hostrcb->hcam)) / sizeof(__be32));
  7500. if (!rc) {
  7501. ipr_handle_log_data(ioa_cfg, hostrcb);
  7502. ioasc = be32_to_cpu(hostrcb->hcam.u.error.fd_ioasc);
  7503. if (ioasc == IPR_IOASC_NR_IOA_RESET_REQUIRED &&
  7504. ioa_cfg->sdt_state == GET_DUMP)
  7505. ioa_cfg->sdt_state = WAIT_FOR_DUMP;
  7506. } else
  7507. ipr_unit_check_no_data(ioa_cfg);
  7508. list_add_tail(&hostrcb->queue, &ioa_cfg->hostrcb_free_q);
  7509. }
  7510. /**
  7511. * ipr_reset_get_unit_check_job - Call to get the unit check buffer.
  7512. * @ipr_cmd: ipr command struct
  7513. *
  7514. * Description: This function will call to get the unit check buffer.
  7515. *
  7516. * Return value:
  7517. * IPR_RC_JOB_RETURN
  7518. **/
  7519. static int ipr_reset_get_unit_check_job(struct ipr_cmnd *ipr_cmd)
  7520. {
  7521. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  7522. ENTER;
  7523. ioa_cfg->ioa_unit_checked = 0;
  7524. ipr_get_unit_check_buffer(ioa_cfg);
  7525. ipr_cmd->job_step = ipr_reset_alert;
  7526. ipr_reset_start_timer(ipr_cmd, 0);
  7527. LEAVE;
  7528. return IPR_RC_JOB_RETURN;
  7529. }
  7530. static int ipr_dump_mailbox_wait(struct ipr_cmnd *ipr_cmd)
  7531. {
  7532. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  7533. ENTER;
  7534. if (ioa_cfg->sdt_state != GET_DUMP)
  7535. return IPR_RC_JOB_RETURN;
  7536. if (!ioa_cfg->sis64 || !ipr_cmd->u.time_left ||
  7537. (readl(ioa_cfg->regs.sense_interrupt_reg) &
  7538. IPR_PCII_MAILBOX_STABLE)) {
  7539. if (!ipr_cmd->u.time_left)
  7540. dev_err(&ioa_cfg->pdev->dev,
  7541. "Timed out waiting for Mailbox register.\n");
  7542. ioa_cfg->sdt_state = READ_DUMP;
  7543. ioa_cfg->dump_timeout = 0;
  7544. if (ioa_cfg->sis64)
  7545. ipr_reset_start_timer(ipr_cmd, IPR_SIS64_DUMP_TIMEOUT);
  7546. else
  7547. ipr_reset_start_timer(ipr_cmd, IPR_SIS32_DUMP_TIMEOUT);
  7548. ipr_cmd->job_step = ipr_reset_wait_for_dump;
  7549. schedule_work(&ioa_cfg->work_q);
  7550. } else {
  7551. ipr_cmd->u.time_left -= IPR_CHECK_FOR_RESET_TIMEOUT;
  7552. ipr_reset_start_timer(ipr_cmd,
  7553. IPR_CHECK_FOR_RESET_TIMEOUT);
  7554. }
  7555. LEAVE;
  7556. return IPR_RC_JOB_RETURN;
  7557. }
  7558. /**
  7559. * ipr_reset_restore_cfg_space - Restore PCI config space.
  7560. * @ipr_cmd: ipr command struct
  7561. *
  7562. * Description: This function restores the saved PCI config space of
  7563. * the adapter, fails all outstanding ops back to the callers, and
  7564. * fetches the dump/unit check if applicable to this reset.
  7565. *
  7566. * Return value:
  7567. * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
  7568. **/
  7569. static int ipr_reset_restore_cfg_space(struct ipr_cmnd *ipr_cmd)
  7570. {
  7571. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  7572. u32 int_reg;
  7573. ENTER;
  7574. ioa_cfg->pdev->state_saved = true;
  7575. pci_restore_state(ioa_cfg->pdev);
  7576. if (ipr_set_pcix_cmd_reg(ioa_cfg)) {
  7577. ipr_cmd->s.ioasa.hdr.ioasc = cpu_to_be32(IPR_IOASC_PCI_ACCESS_ERROR);
  7578. return IPR_RC_JOB_CONTINUE;
  7579. }
  7580. ipr_fail_all_ops(ioa_cfg);
  7581. if (ioa_cfg->sis64) {
  7582. /* Set the adapter to the correct endian mode. */
  7583. writel(IPR_ENDIAN_SWAP_KEY, ioa_cfg->regs.endian_swap_reg);
  7584. int_reg = readl(ioa_cfg->regs.endian_swap_reg);
  7585. }
  7586. if (ioa_cfg->ioa_unit_checked) {
  7587. if (ioa_cfg->sis64) {
  7588. ipr_cmd->job_step = ipr_reset_get_unit_check_job;
  7589. ipr_reset_start_timer(ipr_cmd, IPR_DUMP_DELAY_TIMEOUT);
  7590. return IPR_RC_JOB_RETURN;
  7591. } else {
  7592. ioa_cfg->ioa_unit_checked = 0;
  7593. ipr_get_unit_check_buffer(ioa_cfg);
  7594. ipr_cmd->job_step = ipr_reset_alert;
  7595. ipr_reset_start_timer(ipr_cmd, 0);
  7596. return IPR_RC_JOB_RETURN;
  7597. }
  7598. }
  7599. if (ioa_cfg->in_ioa_bringdown) {
  7600. ipr_cmd->job_step = ipr_ioa_bringdown_done;
  7601. } else if (ioa_cfg->sdt_state == GET_DUMP) {
  7602. ipr_cmd->job_step = ipr_dump_mailbox_wait;
  7603. ipr_cmd->u.time_left = IPR_WAIT_FOR_MAILBOX;
  7604. } else {
  7605. ipr_cmd->job_step = ipr_reset_enable_ioa;
  7606. }
  7607. LEAVE;
  7608. return IPR_RC_JOB_CONTINUE;
  7609. }
  7610. /**
  7611. * ipr_reset_bist_done - BIST has completed on the adapter.
  7612. * @ipr_cmd: ipr command struct
  7613. *
  7614. * Description: Unblock config space and resume the reset process.
  7615. *
  7616. * Return value:
  7617. * IPR_RC_JOB_CONTINUE
  7618. **/
  7619. static int ipr_reset_bist_done(struct ipr_cmnd *ipr_cmd)
  7620. {
  7621. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  7622. ENTER;
  7623. if (ioa_cfg->cfg_locked)
  7624. pci_cfg_access_unlock(ioa_cfg->pdev);
  7625. ioa_cfg->cfg_locked = 0;
  7626. ipr_cmd->job_step = ipr_reset_restore_cfg_space;
  7627. LEAVE;
  7628. return IPR_RC_JOB_CONTINUE;
  7629. }
  7630. /**
  7631. * ipr_reset_start_bist - Run BIST on the adapter.
  7632. * @ipr_cmd: ipr command struct
  7633. *
  7634. * Description: This function runs BIST on the adapter, then delays 2 seconds.
  7635. *
  7636. * Return value:
  7637. * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
  7638. **/
  7639. static int ipr_reset_start_bist(struct ipr_cmnd *ipr_cmd)
  7640. {
  7641. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  7642. int rc = PCIBIOS_SUCCESSFUL;
  7643. ENTER;
  7644. if (ioa_cfg->ipr_chip->bist_method == IPR_MMIO)
  7645. writel(IPR_UPROCI_SIS64_START_BIST,
  7646. ioa_cfg->regs.set_uproc_interrupt_reg32);
  7647. else
  7648. rc = pci_write_config_byte(ioa_cfg->pdev, PCI_BIST, PCI_BIST_START);
  7649. if (rc == PCIBIOS_SUCCESSFUL) {
  7650. ipr_cmd->job_step = ipr_reset_bist_done;
  7651. ipr_reset_start_timer(ipr_cmd, IPR_WAIT_FOR_BIST_TIMEOUT);
  7652. rc = IPR_RC_JOB_RETURN;
  7653. } else {
  7654. if (ioa_cfg->cfg_locked)
  7655. pci_cfg_access_unlock(ipr_cmd->ioa_cfg->pdev);
  7656. ioa_cfg->cfg_locked = 0;
  7657. ipr_cmd->s.ioasa.hdr.ioasc = cpu_to_be32(IPR_IOASC_PCI_ACCESS_ERROR);
  7658. rc = IPR_RC_JOB_CONTINUE;
  7659. }
  7660. LEAVE;
  7661. return rc;
  7662. }
  7663. /**
  7664. * ipr_reset_slot_reset_done - Clear PCI reset to the adapter
  7665. * @ipr_cmd: ipr command struct
  7666. *
  7667. * Description: This clears PCI reset to the adapter and delays two seconds.
  7668. *
  7669. * Return value:
  7670. * IPR_RC_JOB_RETURN
  7671. **/
  7672. static int ipr_reset_slot_reset_done(struct ipr_cmnd *ipr_cmd)
  7673. {
  7674. ENTER;
  7675. ipr_cmd->job_step = ipr_reset_bist_done;
  7676. ipr_reset_start_timer(ipr_cmd, IPR_WAIT_FOR_BIST_TIMEOUT);
  7677. LEAVE;
  7678. return IPR_RC_JOB_RETURN;
  7679. }
  7680. /**
  7681. * ipr_reset_reset_work - Pulse a PCIe fundamental reset
  7682. * @work: work struct
  7683. *
  7684. * Description: This pulses warm reset to a slot.
  7685. *
  7686. **/
  7687. static void ipr_reset_reset_work(struct work_struct *work)
  7688. {
  7689. struct ipr_cmnd *ipr_cmd = container_of(work, struct ipr_cmnd, work);
  7690. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  7691. struct pci_dev *pdev = ioa_cfg->pdev;
  7692. unsigned long lock_flags = 0;
  7693. ENTER;
  7694. pci_set_pcie_reset_state(pdev, pcie_warm_reset);
  7695. msleep(jiffies_to_msecs(IPR_PCI_RESET_TIMEOUT));
  7696. pci_set_pcie_reset_state(pdev, pcie_deassert_reset);
  7697. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  7698. if (ioa_cfg->reset_cmd == ipr_cmd)
  7699. ipr_reset_ioa_job(ipr_cmd);
  7700. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  7701. LEAVE;
  7702. }
  7703. /**
  7704. * ipr_reset_slot_reset - Reset the PCI slot of the adapter.
  7705. * @ipr_cmd: ipr command struct
  7706. *
  7707. * Description: This asserts PCI reset to the adapter.
  7708. *
  7709. * Return value:
  7710. * IPR_RC_JOB_RETURN
  7711. **/
  7712. static int ipr_reset_slot_reset(struct ipr_cmnd *ipr_cmd)
  7713. {
  7714. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  7715. ENTER;
  7716. INIT_WORK(&ipr_cmd->work, ipr_reset_reset_work);
  7717. queue_work(ioa_cfg->reset_work_q, &ipr_cmd->work);
  7718. ipr_cmd->job_step = ipr_reset_slot_reset_done;
  7719. LEAVE;
  7720. return IPR_RC_JOB_RETURN;
  7721. }
  7722. /**
  7723. * ipr_reset_block_config_access_wait - Wait for permission to block config access
  7724. * @ipr_cmd: ipr command struct
  7725. *
  7726. * Description: This attempts to block config access to the IOA.
  7727. *
  7728. * Return value:
  7729. * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
  7730. **/
  7731. static int ipr_reset_block_config_access_wait(struct ipr_cmnd *ipr_cmd)
  7732. {
  7733. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  7734. int rc = IPR_RC_JOB_CONTINUE;
  7735. if (pci_cfg_access_trylock(ioa_cfg->pdev)) {
  7736. ioa_cfg->cfg_locked = 1;
  7737. ipr_cmd->job_step = ioa_cfg->reset;
  7738. } else {
  7739. if (ipr_cmd->u.time_left) {
  7740. rc = IPR_RC_JOB_RETURN;
  7741. ipr_cmd->u.time_left -= IPR_CHECK_FOR_RESET_TIMEOUT;
  7742. ipr_reset_start_timer(ipr_cmd,
  7743. IPR_CHECK_FOR_RESET_TIMEOUT);
  7744. } else {
  7745. ipr_cmd->job_step = ioa_cfg->reset;
  7746. dev_err(&ioa_cfg->pdev->dev,
  7747. "Timed out waiting to lock config access. Resetting anyway.\n");
  7748. }
  7749. }
  7750. return rc;
  7751. }
  7752. /**
  7753. * ipr_reset_block_config_access - Block config access to the IOA
  7754. * @ipr_cmd: ipr command struct
  7755. *
  7756. * Description: This attempts to block config access to the IOA
  7757. *
  7758. * Return value:
  7759. * IPR_RC_JOB_CONTINUE
  7760. **/
  7761. static int ipr_reset_block_config_access(struct ipr_cmnd *ipr_cmd)
  7762. {
  7763. ipr_cmd->ioa_cfg->cfg_locked = 0;
  7764. ipr_cmd->job_step = ipr_reset_block_config_access_wait;
  7765. ipr_cmd->u.time_left = IPR_WAIT_FOR_RESET_TIMEOUT;
  7766. return IPR_RC_JOB_CONTINUE;
  7767. }
  7768. /**
  7769. * ipr_reset_allowed - Query whether or not IOA can be reset
  7770. * @ioa_cfg: ioa config struct
  7771. *
  7772. * Return value:
  7773. * 0 if reset not allowed / non-zero if reset is allowed
  7774. **/
  7775. static int ipr_reset_allowed(struct ipr_ioa_cfg *ioa_cfg)
  7776. {
  7777. volatile u32 temp_reg;
  7778. temp_reg = readl(ioa_cfg->regs.sense_interrupt_reg);
  7779. return ((temp_reg & IPR_PCII_CRITICAL_OPERATION) == 0);
  7780. }
  7781. /**
  7782. * ipr_reset_wait_to_start_bist - Wait for permission to reset IOA.
  7783. * @ipr_cmd: ipr command struct
  7784. *
  7785. * Description: This function waits for adapter permission to run BIST,
  7786. * then runs BIST. If the adapter does not give permission after a
  7787. * reasonable time, we will reset the adapter anyway. The impact of
  7788. * resetting the adapter without warning the adapter is the risk of
  7789. * losing the persistent error log on the adapter. If the adapter is
  7790. * reset while it is writing to the flash on the adapter, the flash
  7791. * segment will have bad ECC and be zeroed.
  7792. *
  7793. * Return value:
  7794. * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
  7795. **/
  7796. static int ipr_reset_wait_to_start_bist(struct ipr_cmnd *ipr_cmd)
  7797. {
  7798. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  7799. int rc = IPR_RC_JOB_RETURN;
  7800. if (!ipr_reset_allowed(ioa_cfg) && ipr_cmd->u.time_left) {
  7801. ipr_cmd->u.time_left -= IPR_CHECK_FOR_RESET_TIMEOUT;
  7802. ipr_reset_start_timer(ipr_cmd, IPR_CHECK_FOR_RESET_TIMEOUT);
  7803. } else {
  7804. ipr_cmd->job_step = ipr_reset_block_config_access;
  7805. rc = IPR_RC_JOB_CONTINUE;
  7806. }
  7807. return rc;
  7808. }
  7809. /**
  7810. * ipr_reset_alert - Alert the adapter of a pending reset
  7811. * @ipr_cmd: ipr command struct
  7812. *
  7813. * Description: This function alerts the adapter that it will be reset.
  7814. * If memory space is not currently enabled, proceed directly
  7815. * to running BIST on the adapter. The timer must always be started
  7816. * so we guarantee we do not run BIST from ipr_isr.
  7817. *
  7818. * Return value:
  7819. * IPR_RC_JOB_RETURN
  7820. **/
  7821. static int ipr_reset_alert(struct ipr_cmnd *ipr_cmd)
  7822. {
  7823. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  7824. u16 cmd_reg;
  7825. int rc;
  7826. ENTER;
  7827. rc = pci_read_config_word(ioa_cfg->pdev, PCI_COMMAND, &cmd_reg);
  7828. if ((rc == PCIBIOS_SUCCESSFUL) && (cmd_reg & PCI_COMMAND_MEMORY)) {
  7829. ipr_mask_and_clear_interrupts(ioa_cfg, ~0);
  7830. writel(IPR_UPROCI_RESET_ALERT, ioa_cfg->regs.set_uproc_interrupt_reg32);
  7831. ipr_cmd->job_step = ipr_reset_wait_to_start_bist;
  7832. } else {
  7833. ipr_cmd->job_step = ipr_reset_block_config_access;
  7834. }
  7835. ipr_cmd->u.time_left = IPR_WAIT_FOR_RESET_TIMEOUT;
  7836. ipr_reset_start_timer(ipr_cmd, IPR_CHECK_FOR_RESET_TIMEOUT);
  7837. LEAVE;
  7838. return IPR_RC_JOB_RETURN;
  7839. }
  7840. /**
  7841. * ipr_reset_quiesce_done - Complete IOA disconnect
  7842. * @ipr_cmd: ipr command struct
  7843. *
  7844. * Description: Freeze the adapter to complete quiesce processing
  7845. *
  7846. * Return value:
  7847. * IPR_RC_JOB_CONTINUE
  7848. **/
  7849. static int ipr_reset_quiesce_done(struct ipr_cmnd *ipr_cmd)
  7850. {
  7851. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  7852. ENTER;
  7853. ipr_cmd->job_step = ipr_ioa_bringdown_done;
  7854. ipr_mask_and_clear_interrupts(ioa_cfg, ~IPR_PCII_IOA_TRANS_TO_OPER);
  7855. LEAVE;
  7856. return IPR_RC_JOB_CONTINUE;
  7857. }
  7858. /**
  7859. * ipr_reset_cancel_hcam_done - Check for outstanding commands
  7860. * @ipr_cmd: ipr command struct
  7861. *
  7862. * Description: Ensure nothing is outstanding to the IOA and
  7863. * proceed with IOA disconnect. Otherwise reset the IOA.
  7864. *
  7865. * Return value:
  7866. * IPR_RC_JOB_RETURN / IPR_RC_JOB_CONTINUE
  7867. **/
  7868. static int ipr_reset_cancel_hcam_done(struct ipr_cmnd *ipr_cmd)
  7869. {
  7870. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  7871. struct ipr_cmnd *loop_cmd;
  7872. struct ipr_hrr_queue *hrrq;
  7873. int rc = IPR_RC_JOB_CONTINUE;
  7874. int count = 0;
  7875. ENTER;
  7876. ipr_cmd->job_step = ipr_reset_quiesce_done;
  7877. for_each_hrrq(hrrq, ioa_cfg) {
  7878. spin_lock(&hrrq->_lock);
  7879. list_for_each_entry(loop_cmd, &hrrq->hrrq_pending_q, queue) {
  7880. count++;
  7881. ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
  7882. list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_free_q);
  7883. rc = IPR_RC_JOB_RETURN;
  7884. break;
  7885. }
  7886. spin_unlock(&hrrq->_lock);
  7887. if (count)
  7888. break;
  7889. }
  7890. LEAVE;
  7891. return rc;
  7892. }
  7893. /**
  7894. * ipr_reset_cancel_hcam - Cancel outstanding HCAMs
  7895. * @ipr_cmd: ipr command struct
  7896. *
  7897. * Description: Cancel any oustanding HCAMs to the IOA.
  7898. *
  7899. * Return value:
  7900. * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
  7901. **/
  7902. static int ipr_reset_cancel_hcam(struct ipr_cmnd *ipr_cmd)
  7903. {
  7904. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  7905. int rc = IPR_RC_JOB_CONTINUE;
  7906. struct ipr_cmd_pkt *cmd_pkt;
  7907. struct ipr_cmnd *hcam_cmd;
  7908. struct ipr_hrr_queue *hrrq = &ioa_cfg->hrrq[IPR_INIT_HRRQ];
  7909. ENTER;
  7910. ipr_cmd->job_step = ipr_reset_cancel_hcam_done;
  7911. if (!hrrq->ioa_is_dead) {
  7912. if (!list_empty(&ioa_cfg->hostrcb_pending_q)) {
  7913. list_for_each_entry(hcam_cmd, &hrrq->hrrq_pending_q, queue) {
  7914. if (hcam_cmd->ioarcb.cmd_pkt.cdb[0] != IPR_HOST_CONTROLLED_ASYNC)
  7915. continue;
  7916. ipr_cmd->ioarcb.res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
  7917. ipr_cmd->ioarcb.cmd_pkt.request_type = IPR_RQTYPE_IOACMD;
  7918. cmd_pkt = &ipr_cmd->ioarcb.cmd_pkt;
  7919. cmd_pkt->request_type = IPR_RQTYPE_IOACMD;
  7920. cmd_pkt->cdb[0] = IPR_CANCEL_REQUEST;
  7921. cmd_pkt->cdb[1] = IPR_CANCEL_64BIT_IOARCB;
  7922. cmd_pkt->cdb[10] = ((u64) hcam_cmd->dma_addr >> 56) & 0xff;
  7923. cmd_pkt->cdb[11] = ((u64) hcam_cmd->dma_addr >> 48) & 0xff;
  7924. cmd_pkt->cdb[12] = ((u64) hcam_cmd->dma_addr >> 40) & 0xff;
  7925. cmd_pkt->cdb[13] = ((u64) hcam_cmd->dma_addr >> 32) & 0xff;
  7926. cmd_pkt->cdb[2] = ((u64) hcam_cmd->dma_addr >> 24) & 0xff;
  7927. cmd_pkt->cdb[3] = ((u64) hcam_cmd->dma_addr >> 16) & 0xff;
  7928. cmd_pkt->cdb[4] = ((u64) hcam_cmd->dma_addr >> 8) & 0xff;
  7929. cmd_pkt->cdb[5] = ((u64) hcam_cmd->dma_addr) & 0xff;
  7930. ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout,
  7931. IPR_CANCEL_TIMEOUT);
  7932. rc = IPR_RC_JOB_RETURN;
  7933. ipr_cmd->job_step = ipr_reset_cancel_hcam;
  7934. break;
  7935. }
  7936. }
  7937. } else
  7938. ipr_cmd->job_step = ipr_reset_alert;
  7939. LEAVE;
  7940. return rc;
  7941. }
  7942. /**
  7943. * ipr_reset_ucode_download_done - Microcode download completion
  7944. * @ipr_cmd: ipr command struct
  7945. *
  7946. * Description: This function unmaps the microcode download buffer.
  7947. *
  7948. * Return value:
  7949. * IPR_RC_JOB_CONTINUE
  7950. **/
  7951. static int ipr_reset_ucode_download_done(struct ipr_cmnd *ipr_cmd)
  7952. {
  7953. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  7954. struct ipr_sglist *sglist = ioa_cfg->ucode_sglist;
  7955. dma_unmap_sg(&ioa_cfg->pdev->dev, sglist->scatterlist,
  7956. sglist->num_sg, DMA_TO_DEVICE);
  7957. ipr_cmd->job_step = ipr_reset_alert;
  7958. return IPR_RC_JOB_CONTINUE;
  7959. }
  7960. /**
  7961. * ipr_reset_ucode_download - Download microcode to the adapter
  7962. * @ipr_cmd: ipr command struct
  7963. *
  7964. * Description: This function checks to see if it there is microcode
  7965. * to download to the adapter. If there is, a download is performed.
  7966. *
  7967. * Return value:
  7968. * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
  7969. **/
  7970. static int ipr_reset_ucode_download(struct ipr_cmnd *ipr_cmd)
  7971. {
  7972. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  7973. struct ipr_sglist *sglist = ioa_cfg->ucode_sglist;
  7974. ENTER;
  7975. ipr_cmd->job_step = ipr_reset_alert;
  7976. if (!sglist)
  7977. return IPR_RC_JOB_CONTINUE;
  7978. ipr_cmd->ioarcb.res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
  7979. ipr_cmd->ioarcb.cmd_pkt.request_type = IPR_RQTYPE_SCSICDB;
  7980. ipr_cmd->ioarcb.cmd_pkt.cdb[0] = WRITE_BUFFER;
  7981. ipr_cmd->ioarcb.cmd_pkt.cdb[1] = IPR_WR_BUF_DOWNLOAD_AND_SAVE;
  7982. ipr_cmd->ioarcb.cmd_pkt.cdb[6] = (sglist->buffer_len & 0xff0000) >> 16;
  7983. ipr_cmd->ioarcb.cmd_pkt.cdb[7] = (sglist->buffer_len & 0x00ff00) >> 8;
  7984. ipr_cmd->ioarcb.cmd_pkt.cdb[8] = sglist->buffer_len & 0x0000ff;
  7985. if (ioa_cfg->sis64)
  7986. ipr_build_ucode_ioadl64(ipr_cmd, sglist);
  7987. else
  7988. ipr_build_ucode_ioadl(ipr_cmd, sglist);
  7989. ipr_cmd->job_step = ipr_reset_ucode_download_done;
  7990. ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout,
  7991. IPR_WRITE_BUFFER_TIMEOUT);
  7992. LEAVE;
  7993. return IPR_RC_JOB_RETURN;
  7994. }
  7995. /**
  7996. * ipr_reset_shutdown_ioa - Shutdown the adapter
  7997. * @ipr_cmd: ipr command struct
  7998. *
  7999. * Description: This function issues an adapter shutdown of the
  8000. * specified type to the specified adapter as part of the
  8001. * adapter reset job.
  8002. *
  8003. * Return value:
  8004. * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
  8005. **/
  8006. static int ipr_reset_shutdown_ioa(struct ipr_cmnd *ipr_cmd)
  8007. {
  8008. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  8009. enum ipr_shutdown_type shutdown_type = ipr_cmd->u.shutdown_type;
  8010. unsigned long timeout;
  8011. int rc = IPR_RC_JOB_CONTINUE;
  8012. ENTER;
  8013. if (shutdown_type == IPR_SHUTDOWN_QUIESCE)
  8014. ipr_cmd->job_step = ipr_reset_cancel_hcam;
  8015. else if (shutdown_type != IPR_SHUTDOWN_NONE &&
  8016. !ioa_cfg->hrrq[IPR_INIT_HRRQ].ioa_is_dead) {
  8017. ipr_cmd->ioarcb.res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
  8018. ipr_cmd->ioarcb.cmd_pkt.request_type = IPR_RQTYPE_IOACMD;
  8019. ipr_cmd->ioarcb.cmd_pkt.cdb[0] = IPR_IOA_SHUTDOWN;
  8020. ipr_cmd->ioarcb.cmd_pkt.cdb[1] = shutdown_type;
  8021. if (shutdown_type == IPR_SHUTDOWN_NORMAL)
  8022. timeout = IPR_SHUTDOWN_TIMEOUT;
  8023. else if (shutdown_type == IPR_SHUTDOWN_PREPARE_FOR_NORMAL)
  8024. timeout = IPR_INTERNAL_TIMEOUT;
  8025. else if (ioa_cfg->dual_raid && ipr_dual_ioa_raid)
  8026. timeout = IPR_DUAL_IOA_ABBR_SHUTDOWN_TO;
  8027. else
  8028. timeout = IPR_ABBREV_SHUTDOWN_TIMEOUT;
  8029. ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, timeout);
  8030. rc = IPR_RC_JOB_RETURN;
  8031. ipr_cmd->job_step = ipr_reset_ucode_download;
  8032. } else
  8033. ipr_cmd->job_step = ipr_reset_alert;
  8034. LEAVE;
  8035. return rc;
  8036. }
  8037. /**
  8038. * ipr_reset_ioa_job - Adapter reset job
  8039. * @ipr_cmd: ipr command struct
  8040. *
  8041. * Description: This function is the job router for the adapter reset job.
  8042. *
  8043. * Return value:
  8044. * none
  8045. **/
  8046. static void ipr_reset_ioa_job(struct ipr_cmnd *ipr_cmd)
  8047. {
  8048. u32 rc, ioasc;
  8049. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  8050. do {
  8051. ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
  8052. if (ioa_cfg->reset_cmd != ipr_cmd) {
  8053. /*
  8054. * We are doing nested adapter resets and this is
  8055. * not the current reset job.
  8056. */
  8057. list_add_tail(&ipr_cmd->queue,
  8058. &ipr_cmd->hrrq->hrrq_free_q);
  8059. return;
  8060. }
  8061. if (IPR_IOASC_SENSE_KEY(ioasc)) {
  8062. rc = ipr_cmd->job_step_failed(ipr_cmd);
  8063. if (rc == IPR_RC_JOB_RETURN)
  8064. return;
  8065. }
  8066. ipr_reinit_ipr_cmnd(ipr_cmd);
  8067. ipr_cmd->job_step_failed = ipr_reset_cmd_failed;
  8068. rc = ipr_cmd->job_step(ipr_cmd);
  8069. } while (rc == IPR_RC_JOB_CONTINUE);
  8070. }
  8071. /**
  8072. * _ipr_initiate_ioa_reset - Initiate an adapter reset
  8073. * @ioa_cfg: ioa config struct
  8074. * @job_step: first job step of reset job
  8075. * @shutdown_type: shutdown type
  8076. *
  8077. * Description: This function will initiate the reset of the given adapter
  8078. * starting at the selected job step.
  8079. * If the caller needs to wait on the completion of the reset,
  8080. * the caller must sleep on the reset_wait_q.
  8081. *
  8082. * Return value:
  8083. * none
  8084. **/
  8085. static void _ipr_initiate_ioa_reset(struct ipr_ioa_cfg *ioa_cfg,
  8086. int (*job_step) (struct ipr_cmnd *),
  8087. enum ipr_shutdown_type shutdown_type)
  8088. {
  8089. struct ipr_cmnd *ipr_cmd;
  8090. int i;
  8091. ioa_cfg->in_reset_reload = 1;
  8092. for (i = 0; i < ioa_cfg->hrrq_num; i++) {
  8093. spin_lock(&ioa_cfg->hrrq[i]._lock);
  8094. ioa_cfg->hrrq[i].allow_cmds = 0;
  8095. spin_unlock(&ioa_cfg->hrrq[i]._lock);
  8096. }
  8097. wmb();
  8098. if (!ioa_cfg->hrrq[IPR_INIT_HRRQ].removing_ioa) {
  8099. ioa_cfg->scsi_unblock = 0;
  8100. ioa_cfg->scsi_blocked = 1;
  8101. scsi_block_requests(ioa_cfg->host);
  8102. }
  8103. ipr_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
  8104. ioa_cfg->reset_cmd = ipr_cmd;
  8105. ipr_cmd->job_step = job_step;
  8106. ipr_cmd->u.shutdown_type = shutdown_type;
  8107. ipr_reset_ioa_job(ipr_cmd);
  8108. }
  8109. /**
  8110. * ipr_initiate_ioa_reset - Initiate an adapter reset
  8111. * @ioa_cfg: ioa config struct
  8112. * @shutdown_type: shutdown type
  8113. *
  8114. * Description: This function will initiate the reset of the given adapter.
  8115. * If the caller needs to wait on the completion of the reset,
  8116. * the caller must sleep on the reset_wait_q.
  8117. *
  8118. * Return value:
  8119. * none
  8120. **/
  8121. static void ipr_initiate_ioa_reset(struct ipr_ioa_cfg *ioa_cfg,
  8122. enum ipr_shutdown_type shutdown_type)
  8123. {
  8124. int i;
  8125. if (ioa_cfg->hrrq[IPR_INIT_HRRQ].ioa_is_dead)
  8126. return;
  8127. if (ioa_cfg->in_reset_reload) {
  8128. if (ioa_cfg->sdt_state == GET_DUMP)
  8129. ioa_cfg->sdt_state = WAIT_FOR_DUMP;
  8130. else if (ioa_cfg->sdt_state == READ_DUMP)
  8131. ioa_cfg->sdt_state = ABORT_DUMP;
  8132. }
  8133. if (ioa_cfg->reset_retries++ >= IPR_NUM_RESET_RELOAD_RETRIES) {
  8134. dev_err(&ioa_cfg->pdev->dev,
  8135. "IOA taken offline - error recovery failed\n");
  8136. ioa_cfg->reset_retries = 0;
  8137. for (i = 0; i < ioa_cfg->hrrq_num; i++) {
  8138. spin_lock(&ioa_cfg->hrrq[i]._lock);
  8139. ioa_cfg->hrrq[i].ioa_is_dead = 1;
  8140. spin_unlock(&ioa_cfg->hrrq[i]._lock);
  8141. }
  8142. wmb();
  8143. if (ioa_cfg->in_ioa_bringdown) {
  8144. ioa_cfg->reset_cmd = NULL;
  8145. ioa_cfg->in_reset_reload = 0;
  8146. ipr_fail_all_ops(ioa_cfg);
  8147. wake_up_all(&ioa_cfg->reset_wait_q);
  8148. if (!ioa_cfg->hrrq[IPR_INIT_HRRQ].removing_ioa) {
  8149. ioa_cfg->scsi_unblock = 1;
  8150. schedule_work(&ioa_cfg->work_q);
  8151. }
  8152. return;
  8153. } else {
  8154. ioa_cfg->in_ioa_bringdown = 1;
  8155. shutdown_type = IPR_SHUTDOWN_NONE;
  8156. }
  8157. }
  8158. _ipr_initiate_ioa_reset(ioa_cfg, ipr_reset_shutdown_ioa,
  8159. shutdown_type);
  8160. }
  8161. /**
  8162. * ipr_reset_freeze - Hold off all I/O activity
  8163. * @ipr_cmd: ipr command struct
  8164. *
  8165. * Description: If the PCI slot is frozen, hold off all I/O
  8166. * activity; then, as soon as the slot is available again,
  8167. * initiate an adapter reset.
  8168. */
  8169. static int ipr_reset_freeze(struct ipr_cmnd *ipr_cmd)
  8170. {
  8171. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  8172. int i;
  8173. /* Disallow new interrupts, avoid loop */
  8174. for (i = 0; i < ioa_cfg->hrrq_num; i++) {
  8175. spin_lock(&ioa_cfg->hrrq[i]._lock);
  8176. ioa_cfg->hrrq[i].allow_interrupts = 0;
  8177. spin_unlock(&ioa_cfg->hrrq[i]._lock);
  8178. }
  8179. wmb();
  8180. list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_pending_q);
  8181. ipr_cmd->done = ipr_reset_ioa_job;
  8182. return IPR_RC_JOB_RETURN;
  8183. }
  8184. /**
  8185. * ipr_pci_mmio_enabled - Called when MMIO has been re-enabled
  8186. * @pdev: PCI device struct
  8187. *
  8188. * Description: This routine is called to tell us that the MMIO
  8189. * access to the IOA has been restored
  8190. */
  8191. static pci_ers_result_t ipr_pci_mmio_enabled(struct pci_dev *pdev)
  8192. {
  8193. unsigned long flags = 0;
  8194. struct ipr_ioa_cfg *ioa_cfg = pci_get_drvdata(pdev);
  8195. spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
  8196. if (!ioa_cfg->probe_done)
  8197. pci_save_state(pdev);
  8198. spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
  8199. return PCI_ERS_RESULT_NEED_RESET;
  8200. }
  8201. /**
  8202. * ipr_pci_frozen - Called when slot has experienced a PCI bus error.
  8203. * @pdev: PCI device struct
  8204. *
  8205. * Description: This routine is called to tell us that the PCI bus
  8206. * is down. Can't do anything here, except put the device driver
  8207. * into a holding pattern, waiting for the PCI bus to come back.
  8208. */
  8209. static void ipr_pci_frozen(struct pci_dev *pdev)
  8210. {
  8211. unsigned long flags = 0;
  8212. struct ipr_ioa_cfg *ioa_cfg = pci_get_drvdata(pdev);
  8213. spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
  8214. if (ioa_cfg->probe_done)
  8215. _ipr_initiate_ioa_reset(ioa_cfg, ipr_reset_freeze, IPR_SHUTDOWN_NONE);
  8216. spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
  8217. }
  8218. /**
  8219. * ipr_pci_slot_reset - Called when PCI slot has been reset.
  8220. * @pdev: PCI device struct
  8221. *
  8222. * Description: This routine is called by the pci error recovery
  8223. * code after the PCI slot has been reset, just before we
  8224. * should resume normal operations.
  8225. */
  8226. static pci_ers_result_t ipr_pci_slot_reset(struct pci_dev *pdev)
  8227. {
  8228. unsigned long flags = 0;
  8229. struct ipr_ioa_cfg *ioa_cfg = pci_get_drvdata(pdev);
  8230. spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
  8231. if (ioa_cfg->probe_done) {
  8232. if (ioa_cfg->needs_warm_reset)
  8233. ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
  8234. else
  8235. _ipr_initiate_ioa_reset(ioa_cfg, ipr_reset_restore_cfg_space,
  8236. IPR_SHUTDOWN_NONE);
  8237. } else
  8238. wake_up_all(&ioa_cfg->eeh_wait_q);
  8239. spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
  8240. return PCI_ERS_RESULT_RECOVERED;
  8241. }
  8242. /**
  8243. * ipr_pci_perm_failure - Called when PCI slot is dead for good.
  8244. * @pdev: PCI device struct
  8245. *
  8246. * Description: This routine is called when the PCI bus has
  8247. * permanently failed.
  8248. */
  8249. static void ipr_pci_perm_failure(struct pci_dev *pdev)
  8250. {
  8251. unsigned long flags = 0;
  8252. struct ipr_ioa_cfg *ioa_cfg = pci_get_drvdata(pdev);
  8253. int i;
  8254. spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
  8255. if (ioa_cfg->probe_done) {
  8256. if (ioa_cfg->sdt_state == WAIT_FOR_DUMP)
  8257. ioa_cfg->sdt_state = ABORT_DUMP;
  8258. ioa_cfg->reset_retries = IPR_NUM_RESET_RELOAD_RETRIES - 1;
  8259. ioa_cfg->in_ioa_bringdown = 1;
  8260. for (i = 0; i < ioa_cfg->hrrq_num; i++) {
  8261. spin_lock(&ioa_cfg->hrrq[i]._lock);
  8262. ioa_cfg->hrrq[i].allow_cmds = 0;
  8263. spin_unlock(&ioa_cfg->hrrq[i]._lock);
  8264. }
  8265. wmb();
  8266. ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
  8267. } else
  8268. wake_up_all(&ioa_cfg->eeh_wait_q);
  8269. spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
  8270. }
  8271. /**
  8272. * ipr_pci_error_detected - Called when a PCI error is detected.
  8273. * @pdev: PCI device struct
  8274. * @state: PCI channel state
  8275. *
  8276. * Description: Called when a PCI error is detected.
  8277. *
  8278. * Return value:
  8279. * PCI_ERS_RESULT_NEED_RESET or PCI_ERS_RESULT_DISCONNECT
  8280. */
  8281. static pci_ers_result_t ipr_pci_error_detected(struct pci_dev *pdev,
  8282. pci_channel_state_t state)
  8283. {
  8284. switch (state) {
  8285. case pci_channel_io_frozen:
  8286. ipr_pci_frozen(pdev);
  8287. return PCI_ERS_RESULT_CAN_RECOVER;
  8288. case pci_channel_io_perm_failure:
  8289. ipr_pci_perm_failure(pdev);
  8290. return PCI_ERS_RESULT_DISCONNECT;
  8291. break;
  8292. default:
  8293. break;
  8294. }
  8295. return PCI_ERS_RESULT_NEED_RESET;
  8296. }
  8297. /**
  8298. * ipr_probe_ioa_part2 - Initializes IOAs found in ipr_probe_ioa(..)
  8299. * @ioa_cfg: ioa cfg struct
  8300. *
  8301. * Description: This is the second phase of adapter initialization
  8302. * This function takes care of initilizing the adapter to the point
  8303. * where it can accept new commands.
  8304. * Return value:
  8305. * 0 on success / -EIO on failure
  8306. **/
  8307. static int ipr_probe_ioa_part2(struct ipr_ioa_cfg *ioa_cfg)
  8308. {
  8309. int rc = 0;
  8310. unsigned long host_lock_flags = 0;
  8311. ENTER;
  8312. spin_lock_irqsave(ioa_cfg->host->host_lock, host_lock_flags);
  8313. dev_dbg(&ioa_cfg->pdev->dev, "ioa_cfg adx: 0x%p\n", ioa_cfg);
  8314. ioa_cfg->probe_done = 1;
  8315. if (ioa_cfg->needs_hard_reset) {
  8316. ioa_cfg->needs_hard_reset = 0;
  8317. ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
  8318. } else
  8319. _ipr_initiate_ioa_reset(ioa_cfg, ipr_reset_enable_ioa,
  8320. IPR_SHUTDOWN_NONE);
  8321. spin_unlock_irqrestore(ioa_cfg->host->host_lock, host_lock_flags);
  8322. LEAVE;
  8323. return rc;
  8324. }
  8325. /**
  8326. * ipr_free_cmd_blks - Frees command blocks allocated for an adapter
  8327. * @ioa_cfg: ioa config struct
  8328. *
  8329. * Return value:
  8330. * none
  8331. **/
  8332. static void ipr_free_cmd_blks(struct ipr_ioa_cfg *ioa_cfg)
  8333. {
  8334. int i;
  8335. if (ioa_cfg->ipr_cmnd_list) {
  8336. for (i = 0; i < IPR_NUM_CMD_BLKS; i++) {
  8337. if (ioa_cfg->ipr_cmnd_list[i])
  8338. dma_pool_free(ioa_cfg->ipr_cmd_pool,
  8339. ioa_cfg->ipr_cmnd_list[i],
  8340. ioa_cfg->ipr_cmnd_list_dma[i]);
  8341. ioa_cfg->ipr_cmnd_list[i] = NULL;
  8342. }
  8343. }
  8344. if (ioa_cfg->ipr_cmd_pool)
  8345. dma_pool_destroy(ioa_cfg->ipr_cmd_pool);
  8346. kfree(ioa_cfg->ipr_cmnd_list);
  8347. kfree(ioa_cfg->ipr_cmnd_list_dma);
  8348. ioa_cfg->ipr_cmnd_list = NULL;
  8349. ioa_cfg->ipr_cmnd_list_dma = NULL;
  8350. ioa_cfg->ipr_cmd_pool = NULL;
  8351. }
  8352. /**
  8353. * ipr_free_mem - Frees memory allocated for an adapter
  8354. * @ioa_cfg: ioa cfg struct
  8355. *
  8356. * Return value:
  8357. * nothing
  8358. **/
  8359. static void ipr_free_mem(struct ipr_ioa_cfg *ioa_cfg)
  8360. {
  8361. int i;
  8362. kfree(ioa_cfg->res_entries);
  8363. dma_free_coherent(&ioa_cfg->pdev->dev, sizeof(struct ipr_misc_cbs),
  8364. ioa_cfg->vpd_cbs, ioa_cfg->vpd_cbs_dma);
  8365. ipr_free_cmd_blks(ioa_cfg);
  8366. for (i = 0; i < ioa_cfg->hrrq_num; i++)
  8367. dma_free_coherent(&ioa_cfg->pdev->dev,
  8368. sizeof(u32) * ioa_cfg->hrrq[i].size,
  8369. ioa_cfg->hrrq[i].host_rrq,
  8370. ioa_cfg->hrrq[i].host_rrq_dma);
  8371. dma_free_coherent(&ioa_cfg->pdev->dev, ioa_cfg->cfg_table_size,
  8372. ioa_cfg->u.cfg_table, ioa_cfg->cfg_table_dma);
  8373. for (i = 0; i < IPR_MAX_HCAMS; i++) {
  8374. dma_free_coherent(&ioa_cfg->pdev->dev,
  8375. sizeof(struct ipr_hostrcb),
  8376. ioa_cfg->hostrcb[i],
  8377. ioa_cfg->hostrcb_dma[i]);
  8378. }
  8379. ipr_free_dump(ioa_cfg);
  8380. kfree(ioa_cfg->trace);
  8381. }
  8382. /**
  8383. * ipr_free_irqs - Free all allocated IRQs for the adapter.
  8384. * @ioa_cfg: ipr cfg struct
  8385. *
  8386. * This function frees all allocated IRQs for the
  8387. * specified adapter.
  8388. *
  8389. * Return value:
  8390. * none
  8391. **/
  8392. static void ipr_free_irqs(struct ipr_ioa_cfg *ioa_cfg)
  8393. {
  8394. struct pci_dev *pdev = ioa_cfg->pdev;
  8395. int i;
  8396. for (i = 0; i < ioa_cfg->nvectors; i++)
  8397. free_irq(pci_irq_vector(pdev, i), &ioa_cfg->hrrq[i]);
  8398. pci_free_irq_vectors(pdev);
  8399. }
  8400. /**
  8401. * ipr_free_all_resources - Free all allocated resources for an adapter.
  8402. * @ipr_cmd: ipr command struct
  8403. *
  8404. * This function frees all allocated resources for the
  8405. * specified adapter.
  8406. *
  8407. * Return value:
  8408. * none
  8409. **/
  8410. static void ipr_free_all_resources(struct ipr_ioa_cfg *ioa_cfg)
  8411. {
  8412. struct pci_dev *pdev = ioa_cfg->pdev;
  8413. ENTER;
  8414. ipr_free_irqs(ioa_cfg);
  8415. if (ioa_cfg->reset_work_q)
  8416. destroy_workqueue(ioa_cfg->reset_work_q);
  8417. iounmap(ioa_cfg->hdw_dma_regs);
  8418. pci_release_regions(pdev);
  8419. ipr_free_mem(ioa_cfg);
  8420. scsi_host_put(ioa_cfg->host);
  8421. pci_disable_device(pdev);
  8422. LEAVE;
  8423. }
  8424. /**
  8425. * ipr_alloc_cmd_blks - Allocate command blocks for an adapter
  8426. * @ioa_cfg: ioa config struct
  8427. *
  8428. * Return value:
  8429. * 0 on success / -ENOMEM on allocation failure
  8430. **/
  8431. static int ipr_alloc_cmd_blks(struct ipr_ioa_cfg *ioa_cfg)
  8432. {
  8433. struct ipr_cmnd *ipr_cmd;
  8434. struct ipr_ioarcb *ioarcb;
  8435. dma_addr_t dma_addr;
  8436. int i, entries_each_hrrq, hrrq_id = 0;
  8437. ioa_cfg->ipr_cmd_pool = dma_pool_create(IPR_NAME, &ioa_cfg->pdev->dev,
  8438. sizeof(struct ipr_cmnd), 512, 0);
  8439. if (!ioa_cfg->ipr_cmd_pool)
  8440. return -ENOMEM;
  8441. ioa_cfg->ipr_cmnd_list = kcalloc(IPR_NUM_CMD_BLKS, sizeof(struct ipr_cmnd *), GFP_KERNEL);
  8442. ioa_cfg->ipr_cmnd_list_dma = kcalloc(IPR_NUM_CMD_BLKS, sizeof(dma_addr_t), GFP_KERNEL);
  8443. if (!ioa_cfg->ipr_cmnd_list || !ioa_cfg->ipr_cmnd_list_dma) {
  8444. ipr_free_cmd_blks(ioa_cfg);
  8445. return -ENOMEM;
  8446. }
  8447. for (i = 0; i < ioa_cfg->hrrq_num; i++) {
  8448. if (ioa_cfg->hrrq_num > 1) {
  8449. if (i == 0) {
  8450. entries_each_hrrq = IPR_NUM_INTERNAL_CMD_BLKS;
  8451. ioa_cfg->hrrq[i].min_cmd_id = 0;
  8452. ioa_cfg->hrrq[i].max_cmd_id =
  8453. (entries_each_hrrq - 1);
  8454. } else {
  8455. entries_each_hrrq =
  8456. IPR_NUM_BASE_CMD_BLKS/
  8457. (ioa_cfg->hrrq_num - 1);
  8458. ioa_cfg->hrrq[i].min_cmd_id =
  8459. IPR_NUM_INTERNAL_CMD_BLKS +
  8460. (i - 1) * entries_each_hrrq;
  8461. ioa_cfg->hrrq[i].max_cmd_id =
  8462. (IPR_NUM_INTERNAL_CMD_BLKS +
  8463. i * entries_each_hrrq - 1);
  8464. }
  8465. } else {
  8466. entries_each_hrrq = IPR_NUM_CMD_BLKS;
  8467. ioa_cfg->hrrq[i].min_cmd_id = 0;
  8468. ioa_cfg->hrrq[i].max_cmd_id = (entries_each_hrrq - 1);
  8469. }
  8470. ioa_cfg->hrrq[i].size = entries_each_hrrq;
  8471. }
  8472. BUG_ON(ioa_cfg->hrrq_num == 0);
  8473. i = IPR_NUM_CMD_BLKS -
  8474. ioa_cfg->hrrq[ioa_cfg->hrrq_num - 1].max_cmd_id - 1;
  8475. if (i > 0) {
  8476. ioa_cfg->hrrq[ioa_cfg->hrrq_num - 1].size += i;
  8477. ioa_cfg->hrrq[ioa_cfg->hrrq_num - 1].max_cmd_id += i;
  8478. }
  8479. for (i = 0; i < IPR_NUM_CMD_BLKS; i++) {
  8480. ipr_cmd = dma_pool_zalloc(ioa_cfg->ipr_cmd_pool,
  8481. GFP_KERNEL, &dma_addr);
  8482. if (!ipr_cmd) {
  8483. ipr_free_cmd_blks(ioa_cfg);
  8484. return -ENOMEM;
  8485. }
  8486. ioa_cfg->ipr_cmnd_list[i] = ipr_cmd;
  8487. ioa_cfg->ipr_cmnd_list_dma[i] = dma_addr;
  8488. ioarcb = &ipr_cmd->ioarcb;
  8489. ipr_cmd->dma_addr = dma_addr;
  8490. if (ioa_cfg->sis64)
  8491. ioarcb->a.ioarcb_host_pci_addr64 = cpu_to_be64(dma_addr);
  8492. else
  8493. ioarcb->a.ioarcb_host_pci_addr = cpu_to_be32(dma_addr);
  8494. ioarcb->host_response_handle = cpu_to_be32(i << 2);
  8495. if (ioa_cfg->sis64) {
  8496. ioarcb->u.sis64_addr_data.data_ioadl_addr =
  8497. cpu_to_be64(dma_addr + offsetof(struct ipr_cmnd, i.ioadl64));
  8498. ioarcb->u.sis64_addr_data.ioasa_host_pci_addr =
  8499. cpu_to_be64(dma_addr + offsetof(struct ipr_cmnd, s.ioasa64));
  8500. } else {
  8501. ioarcb->write_ioadl_addr =
  8502. cpu_to_be32(dma_addr + offsetof(struct ipr_cmnd, i.ioadl));
  8503. ioarcb->read_ioadl_addr = ioarcb->write_ioadl_addr;
  8504. ioarcb->ioasa_host_pci_addr =
  8505. cpu_to_be32(dma_addr + offsetof(struct ipr_cmnd, s.ioasa));
  8506. }
  8507. ioarcb->ioasa_len = cpu_to_be16(sizeof(struct ipr_ioasa));
  8508. ipr_cmd->cmd_index = i;
  8509. ipr_cmd->ioa_cfg = ioa_cfg;
  8510. ipr_cmd->sense_buffer_dma = dma_addr +
  8511. offsetof(struct ipr_cmnd, sense_buffer);
  8512. ipr_cmd->ioarcb.cmd_pkt.hrrq_id = hrrq_id;
  8513. ipr_cmd->hrrq = &ioa_cfg->hrrq[hrrq_id];
  8514. list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_free_q);
  8515. if (i >= ioa_cfg->hrrq[hrrq_id].max_cmd_id)
  8516. hrrq_id++;
  8517. }
  8518. return 0;
  8519. }
  8520. /**
  8521. * ipr_alloc_mem - Allocate memory for an adapter
  8522. * @ioa_cfg: ioa config struct
  8523. *
  8524. * Return value:
  8525. * 0 on success / non-zero for error
  8526. **/
  8527. static int ipr_alloc_mem(struct ipr_ioa_cfg *ioa_cfg)
  8528. {
  8529. struct pci_dev *pdev = ioa_cfg->pdev;
  8530. int i, rc = -ENOMEM;
  8531. ENTER;
  8532. ioa_cfg->res_entries = kcalloc(ioa_cfg->max_devs_supported,
  8533. sizeof(struct ipr_resource_entry),
  8534. GFP_KERNEL);
  8535. if (!ioa_cfg->res_entries)
  8536. goto out;
  8537. for (i = 0; i < ioa_cfg->max_devs_supported; i++) {
  8538. list_add_tail(&ioa_cfg->res_entries[i].queue, &ioa_cfg->free_res_q);
  8539. ioa_cfg->res_entries[i].ioa_cfg = ioa_cfg;
  8540. }
  8541. ioa_cfg->vpd_cbs = dma_alloc_coherent(&pdev->dev,
  8542. sizeof(struct ipr_misc_cbs),
  8543. &ioa_cfg->vpd_cbs_dma,
  8544. GFP_KERNEL);
  8545. if (!ioa_cfg->vpd_cbs)
  8546. goto out_free_res_entries;
  8547. if (ipr_alloc_cmd_blks(ioa_cfg))
  8548. goto out_free_vpd_cbs;
  8549. for (i = 0; i < ioa_cfg->hrrq_num; i++) {
  8550. ioa_cfg->hrrq[i].host_rrq = dma_alloc_coherent(&pdev->dev,
  8551. sizeof(u32) * ioa_cfg->hrrq[i].size,
  8552. &ioa_cfg->hrrq[i].host_rrq_dma,
  8553. GFP_KERNEL);
  8554. if (!ioa_cfg->hrrq[i].host_rrq) {
  8555. while (--i > 0)
  8556. dma_free_coherent(&pdev->dev,
  8557. sizeof(u32) * ioa_cfg->hrrq[i].size,
  8558. ioa_cfg->hrrq[i].host_rrq,
  8559. ioa_cfg->hrrq[i].host_rrq_dma);
  8560. goto out_ipr_free_cmd_blocks;
  8561. }
  8562. ioa_cfg->hrrq[i].ioa_cfg = ioa_cfg;
  8563. }
  8564. ioa_cfg->u.cfg_table = dma_alloc_coherent(&pdev->dev,
  8565. ioa_cfg->cfg_table_size,
  8566. &ioa_cfg->cfg_table_dma,
  8567. GFP_KERNEL);
  8568. if (!ioa_cfg->u.cfg_table)
  8569. goto out_free_host_rrq;
  8570. for (i = 0; i < IPR_MAX_HCAMS; i++) {
  8571. ioa_cfg->hostrcb[i] = dma_alloc_coherent(&pdev->dev,
  8572. sizeof(struct ipr_hostrcb),
  8573. &ioa_cfg->hostrcb_dma[i],
  8574. GFP_KERNEL);
  8575. if (!ioa_cfg->hostrcb[i])
  8576. goto out_free_hostrcb_dma;
  8577. ioa_cfg->hostrcb[i]->hostrcb_dma =
  8578. ioa_cfg->hostrcb_dma[i] + offsetof(struct ipr_hostrcb, hcam);
  8579. ioa_cfg->hostrcb[i]->ioa_cfg = ioa_cfg;
  8580. list_add_tail(&ioa_cfg->hostrcb[i]->queue, &ioa_cfg->hostrcb_free_q);
  8581. }
  8582. ioa_cfg->trace = kcalloc(IPR_NUM_TRACE_ENTRIES,
  8583. sizeof(struct ipr_trace_entry),
  8584. GFP_KERNEL);
  8585. if (!ioa_cfg->trace)
  8586. goto out_free_hostrcb_dma;
  8587. rc = 0;
  8588. out:
  8589. LEAVE;
  8590. return rc;
  8591. out_free_hostrcb_dma:
  8592. while (i-- > 0) {
  8593. dma_free_coherent(&pdev->dev, sizeof(struct ipr_hostrcb),
  8594. ioa_cfg->hostrcb[i],
  8595. ioa_cfg->hostrcb_dma[i]);
  8596. }
  8597. dma_free_coherent(&pdev->dev, ioa_cfg->cfg_table_size,
  8598. ioa_cfg->u.cfg_table, ioa_cfg->cfg_table_dma);
  8599. out_free_host_rrq:
  8600. for (i = 0; i < ioa_cfg->hrrq_num; i++) {
  8601. dma_free_coherent(&pdev->dev,
  8602. sizeof(u32) * ioa_cfg->hrrq[i].size,
  8603. ioa_cfg->hrrq[i].host_rrq,
  8604. ioa_cfg->hrrq[i].host_rrq_dma);
  8605. }
  8606. out_ipr_free_cmd_blocks:
  8607. ipr_free_cmd_blks(ioa_cfg);
  8608. out_free_vpd_cbs:
  8609. dma_free_coherent(&pdev->dev, sizeof(struct ipr_misc_cbs),
  8610. ioa_cfg->vpd_cbs, ioa_cfg->vpd_cbs_dma);
  8611. out_free_res_entries:
  8612. kfree(ioa_cfg->res_entries);
  8613. goto out;
  8614. }
  8615. /**
  8616. * ipr_initialize_bus_attr - Initialize SCSI bus attributes to default values
  8617. * @ioa_cfg: ioa config struct
  8618. *
  8619. * Return value:
  8620. * none
  8621. **/
  8622. static void ipr_initialize_bus_attr(struct ipr_ioa_cfg *ioa_cfg)
  8623. {
  8624. int i;
  8625. for (i = 0; i < IPR_MAX_NUM_BUSES; i++) {
  8626. ioa_cfg->bus_attr[i].bus = i;
  8627. ioa_cfg->bus_attr[i].qas_enabled = 0;
  8628. ioa_cfg->bus_attr[i].bus_width = IPR_DEFAULT_BUS_WIDTH;
  8629. if (ipr_max_speed < ARRAY_SIZE(ipr_max_bus_speeds))
  8630. ioa_cfg->bus_attr[i].max_xfer_rate = ipr_max_bus_speeds[ipr_max_speed];
  8631. else
  8632. ioa_cfg->bus_attr[i].max_xfer_rate = IPR_U160_SCSI_RATE;
  8633. }
  8634. }
  8635. /**
  8636. * ipr_init_regs - Initialize IOA registers
  8637. * @ioa_cfg: ioa config struct
  8638. *
  8639. * Return value:
  8640. * none
  8641. **/
  8642. static void ipr_init_regs(struct ipr_ioa_cfg *ioa_cfg)
  8643. {
  8644. const struct ipr_interrupt_offsets *p;
  8645. struct ipr_interrupts *t;
  8646. void __iomem *base;
  8647. p = &ioa_cfg->chip_cfg->regs;
  8648. t = &ioa_cfg->regs;
  8649. base = ioa_cfg->hdw_dma_regs;
  8650. t->set_interrupt_mask_reg = base + p->set_interrupt_mask_reg;
  8651. t->clr_interrupt_mask_reg = base + p->clr_interrupt_mask_reg;
  8652. t->clr_interrupt_mask_reg32 = base + p->clr_interrupt_mask_reg32;
  8653. t->sense_interrupt_mask_reg = base + p->sense_interrupt_mask_reg;
  8654. t->sense_interrupt_mask_reg32 = base + p->sense_interrupt_mask_reg32;
  8655. t->clr_interrupt_reg = base + p->clr_interrupt_reg;
  8656. t->clr_interrupt_reg32 = base + p->clr_interrupt_reg32;
  8657. t->sense_interrupt_reg = base + p->sense_interrupt_reg;
  8658. t->sense_interrupt_reg32 = base + p->sense_interrupt_reg32;
  8659. t->ioarrin_reg = base + p->ioarrin_reg;
  8660. t->sense_uproc_interrupt_reg = base + p->sense_uproc_interrupt_reg;
  8661. t->sense_uproc_interrupt_reg32 = base + p->sense_uproc_interrupt_reg32;
  8662. t->set_uproc_interrupt_reg = base + p->set_uproc_interrupt_reg;
  8663. t->set_uproc_interrupt_reg32 = base + p->set_uproc_interrupt_reg32;
  8664. t->clr_uproc_interrupt_reg = base + p->clr_uproc_interrupt_reg;
  8665. t->clr_uproc_interrupt_reg32 = base + p->clr_uproc_interrupt_reg32;
  8666. if (ioa_cfg->sis64) {
  8667. t->init_feedback_reg = base + p->init_feedback_reg;
  8668. t->dump_addr_reg = base + p->dump_addr_reg;
  8669. t->dump_data_reg = base + p->dump_data_reg;
  8670. t->endian_swap_reg = base + p->endian_swap_reg;
  8671. }
  8672. }
  8673. /**
  8674. * ipr_init_ioa_cfg - Initialize IOA config struct
  8675. * @ioa_cfg: ioa config struct
  8676. * @host: scsi host struct
  8677. * @pdev: PCI dev struct
  8678. *
  8679. * Return value:
  8680. * none
  8681. **/
  8682. static void ipr_init_ioa_cfg(struct ipr_ioa_cfg *ioa_cfg,
  8683. struct Scsi_Host *host, struct pci_dev *pdev)
  8684. {
  8685. int i;
  8686. ioa_cfg->host = host;
  8687. ioa_cfg->pdev = pdev;
  8688. ioa_cfg->log_level = ipr_log_level;
  8689. ioa_cfg->doorbell = IPR_DOORBELL;
  8690. sprintf(ioa_cfg->eye_catcher, IPR_EYECATCHER);
  8691. sprintf(ioa_cfg->trace_start, IPR_TRACE_START_LABEL);
  8692. sprintf(ioa_cfg->cfg_table_start, IPR_CFG_TBL_START);
  8693. sprintf(ioa_cfg->resource_table_label, IPR_RES_TABLE_LABEL);
  8694. sprintf(ioa_cfg->ipr_hcam_label, IPR_HCAM_LABEL);
  8695. sprintf(ioa_cfg->ipr_cmd_label, IPR_CMD_LABEL);
  8696. INIT_LIST_HEAD(&ioa_cfg->hostrcb_free_q);
  8697. INIT_LIST_HEAD(&ioa_cfg->hostrcb_pending_q);
  8698. INIT_LIST_HEAD(&ioa_cfg->hostrcb_report_q);
  8699. INIT_LIST_HEAD(&ioa_cfg->free_res_q);
  8700. INIT_LIST_HEAD(&ioa_cfg->used_res_q);
  8701. INIT_WORK(&ioa_cfg->work_q, ipr_worker_thread);
  8702. INIT_WORK(&ioa_cfg->scsi_add_work_q, ipr_add_remove_thread);
  8703. init_waitqueue_head(&ioa_cfg->reset_wait_q);
  8704. init_waitqueue_head(&ioa_cfg->msi_wait_q);
  8705. init_waitqueue_head(&ioa_cfg->eeh_wait_q);
  8706. ioa_cfg->sdt_state = INACTIVE;
  8707. ipr_initialize_bus_attr(ioa_cfg);
  8708. ioa_cfg->max_devs_supported = ipr_max_devs;
  8709. if (ioa_cfg->sis64) {
  8710. host->max_channel = IPR_MAX_SIS64_BUSES;
  8711. host->max_id = IPR_MAX_SIS64_TARGETS_PER_BUS;
  8712. host->max_lun = IPR_MAX_SIS64_LUNS_PER_TARGET;
  8713. if (ipr_max_devs > IPR_MAX_SIS64_DEVS)
  8714. ioa_cfg->max_devs_supported = IPR_MAX_SIS64_DEVS;
  8715. ioa_cfg->cfg_table_size = (sizeof(struct ipr_config_table_hdr64)
  8716. + ((sizeof(struct ipr_config_table_entry64)
  8717. * ioa_cfg->max_devs_supported)));
  8718. } else {
  8719. host->max_channel = IPR_VSET_BUS;
  8720. host->max_id = IPR_MAX_NUM_TARGETS_PER_BUS;
  8721. host->max_lun = IPR_MAX_NUM_LUNS_PER_TARGET;
  8722. if (ipr_max_devs > IPR_MAX_PHYSICAL_DEVS)
  8723. ioa_cfg->max_devs_supported = IPR_MAX_PHYSICAL_DEVS;
  8724. ioa_cfg->cfg_table_size = (sizeof(struct ipr_config_table_hdr)
  8725. + ((sizeof(struct ipr_config_table_entry)
  8726. * ioa_cfg->max_devs_supported)));
  8727. }
  8728. host->unique_id = host->host_no;
  8729. host->max_cmd_len = IPR_MAX_CDB_LEN;
  8730. host->can_queue = ioa_cfg->max_cmds;
  8731. pci_set_drvdata(pdev, ioa_cfg);
  8732. for (i = 0; i < ARRAY_SIZE(ioa_cfg->hrrq); i++) {
  8733. INIT_LIST_HEAD(&ioa_cfg->hrrq[i].hrrq_free_q);
  8734. INIT_LIST_HEAD(&ioa_cfg->hrrq[i].hrrq_pending_q);
  8735. spin_lock_init(&ioa_cfg->hrrq[i]._lock);
  8736. if (i == 0)
  8737. ioa_cfg->hrrq[i].lock = ioa_cfg->host->host_lock;
  8738. else
  8739. ioa_cfg->hrrq[i].lock = &ioa_cfg->hrrq[i]._lock;
  8740. }
  8741. }
  8742. /**
  8743. * ipr_get_chip_info - Find adapter chip information
  8744. * @dev_id: PCI device id struct
  8745. *
  8746. * Return value:
  8747. * ptr to chip information on success / NULL on failure
  8748. **/
  8749. static const struct ipr_chip_t *
  8750. ipr_get_chip_info(const struct pci_device_id *dev_id)
  8751. {
  8752. int i;
  8753. for (i = 0; i < ARRAY_SIZE(ipr_chip); i++)
  8754. if (ipr_chip[i].vendor == dev_id->vendor &&
  8755. ipr_chip[i].device == dev_id->device)
  8756. return &ipr_chip[i];
  8757. return NULL;
  8758. }
  8759. /**
  8760. * ipr_wait_for_pci_err_recovery - Wait for any PCI error recovery to complete
  8761. * during probe time
  8762. * @ioa_cfg: ioa config struct
  8763. *
  8764. * Return value:
  8765. * None
  8766. **/
  8767. static void ipr_wait_for_pci_err_recovery(struct ipr_ioa_cfg *ioa_cfg)
  8768. {
  8769. struct pci_dev *pdev = ioa_cfg->pdev;
  8770. if (pci_channel_offline(pdev)) {
  8771. wait_event_timeout(ioa_cfg->eeh_wait_q,
  8772. !pci_channel_offline(pdev),
  8773. IPR_PCI_ERROR_RECOVERY_TIMEOUT);
  8774. pci_restore_state(pdev);
  8775. }
  8776. }
  8777. static void name_msi_vectors(struct ipr_ioa_cfg *ioa_cfg)
  8778. {
  8779. int vec_idx, n = sizeof(ioa_cfg->vectors_info[0].desc) - 1;
  8780. for (vec_idx = 0; vec_idx < ioa_cfg->nvectors; vec_idx++) {
  8781. snprintf(ioa_cfg->vectors_info[vec_idx].desc, n,
  8782. "host%d-%d", ioa_cfg->host->host_no, vec_idx);
  8783. ioa_cfg->vectors_info[vec_idx].
  8784. desc[strlen(ioa_cfg->vectors_info[vec_idx].desc)] = 0;
  8785. }
  8786. }
  8787. static int ipr_request_other_msi_irqs(struct ipr_ioa_cfg *ioa_cfg,
  8788. struct pci_dev *pdev)
  8789. {
  8790. int i, rc;
  8791. for (i = 1; i < ioa_cfg->nvectors; i++) {
  8792. rc = request_irq(pci_irq_vector(pdev, i),
  8793. ipr_isr_mhrrq,
  8794. 0,
  8795. ioa_cfg->vectors_info[i].desc,
  8796. &ioa_cfg->hrrq[i]);
  8797. if (rc) {
  8798. while (--i >= 0)
  8799. free_irq(pci_irq_vector(pdev, i),
  8800. &ioa_cfg->hrrq[i]);
  8801. return rc;
  8802. }
  8803. }
  8804. return 0;
  8805. }
  8806. /**
  8807. * ipr_test_intr - Handle the interrupt generated in ipr_test_msi().
  8808. * @pdev: PCI device struct
  8809. *
  8810. * Description: Simply set the msi_received flag to 1 indicating that
  8811. * Message Signaled Interrupts are supported.
  8812. *
  8813. * Return value:
  8814. * 0 on success / non-zero on failure
  8815. **/
  8816. static irqreturn_t ipr_test_intr(int irq, void *devp)
  8817. {
  8818. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)devp;
  8819. unsigned long lock_flags = 0;
  8820. irqreturn_t rc = IRQ_HANDLED;
  8821. dev_info(&ioa_cfg->pdev->dev, "Received IRQ : %d\n", irq);
  8822. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  8823. ioa_cfg->msi_received = 1;
  8824. wake_up(&ioa_cfg->msi_wait_q);
  8825. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  8826. return rc;
  8827. }
  8828. /**
  8829. * ipr_test_msi - Test for Message Signaled Interrupt (MSI) support.
  8830. * @pdev: PCI device struct
  8831. *
  8832. * Description: This routine sets up and initiates a test interrupt to determine
  8833. * if the interrupt is received via the ipr_test_intr() service routine.
  8834. * If the tests fails, the driver will fall back to LSI.
  8835. *
  8836. * Return value:
  8837. * 0 on success / non-zero on failure
  8838. **/
  8839. static int ipr_test_msi(struct ipr_ioa_cfg *ioa_cfg, struct pci_dev *pdev)
  8840. {
  8841. int rc;
  8842. volatile u32 int_reg;
  8843. unsigned long lock_flags = 0;
  8844. int irq = pci_irq_vector(pdev, 0);
  8845. ENTER;
  8846. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  8847. init_waitqueue_head(&ioa_cfg->msi_wait_q);
  8848. ioa_cfg->msi_received = 0;
  8849. ipr_mask_and_clear_interrupts(ioa_cfg, ~IPR_PCII_IOA_TRANS_TO_OPER);
  8850. writel(IPR_PCII_IO_DEBUG_ACKNOWLEDGE, ioa_cfg->regs.clr_interrupt_mask_reg32);
  8851. int_reg = readl(ioa_cfg->regs.sense_interrupt_mask_reg);
  8852. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  8853. rc = request_irq(irq, ipr_test_intr, 0, IPR_NAME, ioa_cfg);
  8854. if (rc) {
  8855. dev_err(&pdev->dev, "Can not assign irq %d\n", irq);
  8856. return rc;
  8857. } else if (ipr_debug)
  8858. dev_info(&pdev->dev, "IRQ assigned: %d\n", irq);
  8859. writel(IPR_PCII_IO_DEBUG_ACKNOWLEDGE, ioa_cfg->regs.sense_interrupt_reg32);
  8860. int_reg = readl(ioa_cfg->regs.sense_interrupt_reg);
  8861. wait_event_timeout(ioa_cfg->msi_wait_q, ioa_cfg->msi_received, HZ);
  8862. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  8863. ipr_mask_and_clear_interrupts(ioa_cfg, ~IPR_PCII_IOA_TRANS_TO_OPER);
  8864. if (!ioa_cfg->msi_received) {
  8865. /* MSI test failed */
  8866. dev_info(&pdev->dev, "MSI test failed. Falling back to LSI.\n");
  8867. rc = -EOPNOTSUPP;
  8868. } else if (ipr_debug)
  8869. dev_info(&pdev->dev, "MSI test succeeded.\n");
  8870. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  8871. free_irq(irq, ioa_cfg);
  8872. LEAVE;
  8873. return rc;
  8874. }
  8875. /* ipr_probe_ioa - Allocates memory and does first stage of initialization
  8876. * @pdev: PCI device struct
  8877. * @dev_id: PCI device id struct
  8878. *
  8879. * Return value:
  8880. * 0 on success / non-zero on failure
  8881. **/
  8882. static int ipr_probe_ioa(struct pci_dev *pdev,
  8883. const struct pci_device_id *dev_id)
  8884. {
  8885. struct ipr_ioa_cfg *ioa_cfg;
  8886. struct Scsi_Host *host;
  8887. unsigned long ipr_regs_pci;
  8888. void __iomem *ipr_regs;
  8889. int rc = PCIBIOS_SUCCESSFUL;
  8890. volatile u32 mask, uproc, interrupts;
  8891. unsigned long lock_flags, driver_lock_flags;
  8892. unsigned int irq_flag;
  8893. ENTER;
  8894. dev_info(&pdev->dev, "Found IOA with IRQ: %d\n", pdev->irq);
  8895. host = scsi_host_alloc(&driver_template, sizeof(*ioa_cfg));
  8896. if (!host) {
  8897. dev_err(&pdev->dev, "call to scsi_host_alloc failed!\n");
  8898. rc = -ENOMEM;
  8899. goto out;
  8900. }
  8901. ioa_cfg = (struct ipr_ioa_cfg *)host->hostdata;
  8902. memset(ioa_cfg, 0, sizeof(struct ipr_ioa_cfg));
  8903. ata_host_init(&ioa_cfg->ata_host, &pdev->dev, &ipr_sata_ops);
  8904. ioa_cfg->ipr_chip = ipr_get_chip_info(dev_id);
  8905. if (!ioa_cfg->ipr_chip) {
  8906. dev_err(&pdev->dev, "Unknown adapter chipset 0x%04X 0x%04X\n",
  8907. dev_id->vendor, dev_id->device);
  8908. goto out_scsi_host_put;
  8909. }
  8910. /* set SIS 32 or SIS 64 */
  8911. ioa_cfg->sis64 = ioa_cfg->ipr_chip->sis_type == IPR_SIS64 ? 1 : 0;
  8912. ioa_cfg->chip_cfg = ioa_cfg->ipr_chip->cfg;
  8913. ioa_cfg->clear_isr = ioa_cfg->chip_cfg->clear_isr;
  8914. ioa_cfg->max_cmds = ioa_cfg->chip_cfg->max_cmds;
  8915. if (ipr_transop_timeout)
  8916. ioa_cfg->transop_timeout = ipr_transop_timeout;
  8917. else if (dev_id->driver_data & IPR_USE_LONG_TRANSOP_TIMEOUT)
  8918. ioa_cfg->transop_timeout = IPR_LONG_OPERATIONAL_TIMEOUT;
  8919. else
  8920. ioa_cfg->transop_timeout = IPR_OPERATIONAL_TIMEOUT;
  8921. ioa_cfg->revid = pdev->revision;
  8922. ipr_init_ioa_cfg(ioa_cfg, host, pdev);
  8923. ipr_regs_pci = pci_resource_start(pdev, 0);
  8924. rc = pci_request_regions(pdev, IPR_NAME);
  8925. if (rc < 0) {
  8926. dev_err(&pdev->dev,
  8927. "Couldn't register memory range of registers\n");
  8928. goto out_scsi_host_put;
  8929. }
  8930. rc = pci_enable_device(pdev);
  8931. if (rc || pci_channel_offline(pdev)) {
  8932. if (pci_channel_offline(pdev)) {
  8933. ipr_wait_for_pci_err_recovery(ioa_cfg);
  8934. rc = pci_enable_device(pdev);
  8935. }
  8936. if (rc) {
  8937. dev_err(&pdev->dev, "Cannot enable adapter\n");
  8938. ipr_wait_for_pci_err_recovery(ioa_cfg);
  8939. goto out_release_regions;
  8940. }
  8941. }
  8942. ipr_regs = pci_ioremap_bar(pdev, 0);
  8943. if (!ipr_regs) {
  8944. dev_err(&pdev->dev,
  8945. "Couldn't map memory range of registers\n");
  8946. rc = -ENOMEM;
  8947. goto out_disable;
  8948. }
  8949. ioa_cfg->hdw_dma_regs = ipr_regs;
  8950. ioa_cfg->hdw_dma_regs_pci = ipr_regs_pci;
  8951. ioa_cfg->ioa_mailbox = ioa_cfg->chip_cfg->mailbox + ipr_regs;
  8952. ipr_init_regs(ioa_cfg);
  8953. if (ioa_cfg->sis64) {
  8954. rc = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
  8955. if (rc < 0) {
  8956. dev_dbg(&pdev->dev, "Failed to set 64 bit DMA mask\n");
  8957. rc = dma_set_mask_and_coherent(&pdev->dev,
  8958. DMA_BIT_MASK(32));
  8959. }
  8960. } else
  8961. rc = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
  8962. if (rc < 0) {
  8963. dev_err(&pdev->dev, "Failed to set DMA mask\n");
  8964. goto cleanup_nomem;
  8965. }
  8966. rc = pci_write_config_byte(pdev, PCI_CACHE_LINE_SIZE,
  8967. ioa_cfg->chip_cfg->cache_line_size);
  8968. if (rc != PCIBIOS_SUCCESSFUL) {
  8969. dev_err(&pdev->dev, "Write of cache line size failed\n");
  8970. ipr_wait_for_pci_err_recovery(ioa_cfg);
  8971. rc = -EIO;
  8972. goto cleanup_nomem;
  8973. }
  8974. /* Issue MMIO read to ensure card is not in EEH */
  8975. interrupts = readl(ioa_cfg->regs.sense_interrupt_reg);
  8976. ipr_wait_for_pci_err_recovery(ioa_cfg);
  8977. if (ipr_number_of_msix > IPR_MAX_MSIX_VECTORS) {
  8978. dev_err(&pdev->dev, "The max number of MSIX is %d\n",
  8979. IPR_MAX_MSIX_VECTORS);
  8980. ipr_number_of_msix = IPR_MAX_MSIX_VECTORS;
  8981. }
  8982. irq_flag = PCI_IRQ_LEGACY;
  8983. if (ioa_cfg->ipr_chip->has_msi)
  8984. irq_flag |= PCI_IRQ_MSI | PCI_IRQ_MSIX;
  8985. rc = pci_alloc_irq_vectors(pdev, 1, ipr_number_of_msix, irq_flag);
  8986. if (rc < 0) {
  8987. ipr_wait_for_pci_err_recovery(ioa_cfg);
  8988. goto cleanup_nomem;
  8989. }
  8990. ioa_cfg->nvectors = rc;
  8991. if (!pdev->msi_enabled && !pdev->msix_enabled)
  8992. ioa_cfg->clear_isr = 1;
  8993. pci_set_master(pdev);
  8994. if (pci_channel_offline(pdev)) {
  8995. ipr_wait_for_pci_err_recovery(ioa_cfg);
  8996. pci_set_master(pdev);
  8997. if (pci_channel_offline(pdev)) {
  8998. rc = -EIO;
  8999. goto out_msi_disable;
  9000. }
  9001. }
  9002. if (pdev->msi_enabled || pdev->msix_enabled) {
  9003. rc = ipr_test_msi(ioa_cfg, pdev);
  9004. switch (rc) {
  9005. case 0:
  9006. dev_info(&pdev->dev,
  9007. "Request for %d MSI%ss succeeded.", ioa_cfg->nvectors,
  9008. pdev->msix_enabled ? "-X" : "");
  9009. break;
  9010. case -EOPNOTSUPP:
  9011. ipr_wait_for_pci_err_recovery(ioa_cfg);
  9012. pci_free_irq_vectors(pdev);
  9013. ioa_cfg->nvectors = 1;
  9014. ioa_cfg->clear_isr = 1;
  9015. break;
  9016. default:
  9017. goto out_msi_disable;
  9018. }
  9019. }
  9020. ioa_cfg->hrrq_num = min3(ioa_cfg->nvectors,
  9021. (unsigned int)num_online_cpus(),
  9022. (unsigned int)IPR_MAX_HRRQ_NUM);
  9023. if ((rc = ipr_save_pcix_cmd_reg(ioa_cfg)))
  9024. goto out_msi_disable;
  9025. if ((rc = ipr_set_pcix_cmd_reg(ioa_cfg)))
  9026. goto out_msi_disable;
  9027. rc = ipr_alloc_mem(ioa_cfg);
  9028. if (rc < 0) {
  9029. dev_err(&pdev->dev,
  9030. "Couldn't allocate enough memory for device driver!\n");
  9031. goto out_msi_disable;
  9032. }
  9033. /* Save away PCI config space for use following IOA reset */
  9034. rc = pci_save_state(pdev);
  9035. if (rc != PCIBIOS_SUCCESSFUL) {
  9036. dev_err(&pdev->dev, "Failed to save PCI config space\n");
  9037. rc = -EIO;
  9038. goto cleanup_nolog;
  9039. }
  9040. /*
  9041. * If HRRQ updated interrupt is not masked, or reset alert is set,
  9042. * the card is in an unknown state and needs a hard reset
  9043. */
  9044. mask = readl(ioa_cfg->regs.sense_interrupt_mask_reg32);
  9045. interrupts = readl(ioa_cfg->regs.sense_interrupt_reg32);
  9046. uproc = readl(ioa_cfg->regs.sense_uproc_interrupt_reg32);
  9047. if ((mask & IPR_PCII_HRRQ_UPDATED) == 0 || (uproc & IPR_UPROCI_RESET_ALERT))
  9048. ioa_cfg->needs_hard_reset = 1;
  9049. if ((interrupts & IPR_PCII_ERROR_INTERRUPTS) || reset_devices)
  9050. ioa_cfg->needs_hard_reset = 1;
  9051. if (interrupts & IPR_PCII_IOA_UNIT_CHECKED)
  9052. ioa_cfg->ioa_unit_checked = 1;
  9053. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  9054. ipr_mask_and_clear_interrupts(ioa_cfg, ~IPR_PCII_IOA_TRANS_TO_OPER);
  9055. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  9056. if (pdev->msi_enabled || pdev->msix_enabled) {
  9057. name_msi_vectors(ioa_cfg);
  9058. rc = request_irq(pci_irq_vector(pdev, 0), ipr_isr, 0,
  9059. ioa_cfg->vectors_info[0].desc,
  9060. &ioa_cfg->hrrq[0]);
  9061. if (!rc)
  9062. rc = ipr_request_other_msi_irqs(ioa_cfg, pdev);
  9063. } else {
  9064. rc = request_irq(pdev->irq, ipr_isr,
  9065. IRQF_SHARED,
  9066. IPR_NAME, &ioa_cfg->hrrq[0]);
  9067. }
  9068. if (rc) {
  9069. dev_err(&pdev->dev, "Couldn't register IRQ %d! rc=%d\n",
  9070. pdev->irq, rc);
  9071. goto cleanup_nolog;
  9072. }
  9073. if ((dev_id->driver_data & IPR_USE_PCI_WARM_RESET) ||
  9074. (dev_id->device == PCI_DEVICE_ID_IBM_OBSIDIAN_E && !ioa_cfg->revid)) {
  9075. ioa_cfg->needs_warm_reset = 1;
  9076. ioa_cfg->reset = ipr_reset_slot_reset;
  9077. ioa_cfg->reset_work_q = alloc_ordered_workqueue("ipr_reset_%d",
  9078. WQ_MEM_RECLAIM, host->host_no);
  9079. if (!ioa_cfg->reset_work_q) {
  9080. dev_err(&pdev->dev, "Couldn't register reset workqueue\n");
  9081. rc = -ENOMEM;
  9082. goto out_free_irq;
  9083. }
  9084. } else
  9085. ioa_cfg->reset = ipr_reset_start_bist;
  9086. spin_lock_irqsave(&ipr_driver_lock, driver_lock_flags);
  9087. list_add_tail(&ioa_cfg->queue, &ipr_ioa_head);
  9088. spin_unlock_irqrestore(&ipr_driver_lock, driver_lock_flags);
  9089. LEAVE;
  9090. out:
  9091. return rc;
  9092. out_free_irq:
  9093. ipr_free_irqs(ioa_cfg);
  9094. cleanup_nolog:
  9095. ipr_free_mem(ioa_cfg);
  9096. out_msi_disable:
  9097. ipr_wait_for_pci_err_recovery(ioa_cfg);
  9098. pci_free_irq_vectors(pdev);
  9099. cleanup_nomem:
  9100. iounmap(ipr_regs);
  9101. out_disable:
  9102. pci_disable_device(pdev);
  9103. out_release_regions:
  9104. pci_release_regions(pdev);
  9105. out_scsi_host_put:
  9106. scsi_host_put(host);
  9107. goto out;
  9108. }
  9109. /**
  9110. * ipr_initiate_ioa_bringdown - Bring down an adapter
  9111. * @ioa_cfg: ioa config struct
  9112. * @shutdown_type: shutdown type
  9113. *
  9114. * Description: This function will initiate bringing down the adapter.
  9115. * This consists of issuing an IOA shutdown to the adapter
  9116. * to flush the cache, and running BIST.
  9117. * If the caller needs to wait on the completion of the reset,
  9118. * the caller must sleep on the reset_wait_q.
  9119. *
  9120. * Return value:
  9121. * none
  9122. **/
  9123. static void ipr_initiate_ioa_bringdown(struct ipr_ioa_cfg *ioa_cfg,
  9124. enum ipr_shutdown_type shutdown_type)
  9125. {
  9126. ENTER;
  9127. if (ioa_cfg->sdt_state == WAIT_FOR_DUMP)
  9128. ioa_cfg->sdt_state = ABORT_DUMP;
  9129. ioa_cfg->reset_retries = 0;
  9130. ioa_cfg->in_ioa_bringdown = 1;
  9131. ipr_initiate_ioa_reset(ioa_cfg, shutdown_type);
  9132. LEAVE;
  9133. }
  9134. /**
  9135. * __ipr_remove - Remove a single adapter
  9136. * @pdev: pci device struct
  9137. *
  9138. * Adapter hot plug remove entry point.
  9139. *
  9140. * Return value:
  9141. * none
  9142. **/
  9143. static void __ipr_remove(struct pci_dev *pdev)
  9144. {
  9145. unsigned long host_lock_flags = 0;
  9146. struct ipr_ioa_cfg *ioa_cfg = pci_get_drvdata(pdev);
  9147. int i;
  9148. unsigned long driver_lock_flags;
  9149. ENTER;
  9150. spin_lock_irqsave(ioa_cfg->host->host_lock, host_lock_flags);
  9151. while (ioa_cfg->in_reset_reload) {
  9152. spin_unlock_irqrestore(ioa_cfg->host->host_lock, host_lock_flags);
  9153. wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
  9154. spin_lock_irqsave(ioa_cfg->host->host_lock, host_lock_flags);
  9155. }
  9156. for (i = 0; i < ioa_cfg->hrrq_num; i++) {
  9157. spin_lock(&ioa_cfg->hrrq[i]._lock);
  9158. ioa_cfg->hrrq[i].removing_ioa = 1;
  9159. spin_unlock(&ioa_cfg->hrrq[i]._lock);
  9160. }
  9161. wmb();
  9162. ipr_initiate_ioa_bringdown(ioa_cfg, IPR_SHUTDOWN_NORMAL);
  9163. spin_unlock_irqrestore(ioa_cfg->host->host_lock, host_lock_flags);
  9164. wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
  9165. flush_work(&ioa_cfg->work_q);
  9166. if (ioa_cfg->reset_work_q)
  9167. flush_workqueue(ioa_cfg->reset_work_q);
  9168. INIT_LIST_HEAD(&ioa_cfg->used_res_q);
  9169. spin_lock_irqsave(ioa_cfg->host->host_lock, host_lock_flags);
  9170. spin_lock_irqsave(&ipr_driver_lock, driver_lock_flags);
  9171. list_del(&ioa_cfg->queue);
  9172. spin_unlock_irqrestore(&ipr_driver_lock, driver_lock_flags);
  9173. if (ioa_cfg->sdt_state == ABORT_DUMP)
  9174. ioa_cfg->sdt_state = WAIT_FOR_DUMP;
  9175. spin_unlock_irqrestore(ioa_cfg->host->host_lock, host_lock_flags);
  9176. ipr_free_all_resources(ioa_cfg);
  9177. LEAVE;
  9178. }
  9179. /**
  9180. * ipr_remove - IOA hot plug remove entry point
  9181. * @pdev: pci device struct
  9182. *
  9183. * Adapter hot plug remove entry point.
  9184. *
  9185. * Return value:
  9186. * none
  9187. **/
  9188. static void ipr_remove(struct pci_dev *pdev)
  9189. {
  9190. struct ipr_ioa_cfg *ioa_cfg = pci_get_drvdata(pdev);
  9191. ENTER;
  9192. ipr_remove_trace_file(&ioa_cfg->host->shost_dev.kobj,
  9193. &ipr_trace_attr);
  9194. ipr_remove_dump_file(&ioa_cfg->host->shost_dev.kobj,
  9195. &ipr_dump_attr);
  9196. sysfs_remove_bin_file(&ioa_cfg->host->shost_dev.kobj,
  9197. &ipr_ioa_async_err_log);
  9198. scsi_remove_host(ioa_cfg->host);
  9199. __ipr_remove(pdev);
  9200. LEAVE;
  9201. }
  9202. /**
  9203. * ipr_probe - Adapter hot plug add entry point
  9204. *
  9205. * Return value:
  9206. * 0 on success / non-zero on failure
  9207. **/
  9208. static int ipr_probe(struct pci_dev *pdev, const struct pci_device_id *dev_id)
  9209. {
  9210. struct ipr_ioa_cfg *ioa_cfg;
  9211. unsigned long flags;
  9212. int rc, i;
  9213. rc = ipr_probe_ioa(pdev, dev_id);
  9214. if (rc)
  9215. return rc;
  9216. ioa_cfg = pci_get_drvdata(pdev);
  9217. rc = ipr_probe_ioa_part2(ioa_cfg);
  9218. if (rc) {
  9219. __ipr_remove(pdev);
  9220. return rc;
  9221. }
  9222. rc = scsi_add_host(ioa_cfg->host, &pdev->dev);
  9223. if (rc) {
  9224. __ipr_remove(pdev);
  9225. return rc;
  9226. }
  9227. rc = ipr_create_trace_file(&ioa_cfg->host->shost_dev.kobj,
  9228. &ipr_trace_attr);
  9229. if (rc) {
  9230. scsi_remove_host(ioa_cfg->host);
  9231. __ipr_remove(pdev);
  9232. return rc;
  9233. }
  9234. rc = sysfs_create_bin_file(&ioa_cfg->host->shost_dev.kobj,
  9235. &ipr_ioa_async_err_log);
  9236. if (rc) {
  9237. ipr_remove_dump_file(&ioa_cfg->host->shost_dev.kobj,
  9238. &ipr_dump_attr);
  9239. ipr_remove_trace_file(&ioa_cfg->host->shost_dev.kobj,
  9240. &ipr_trace_attr);
  9241. scsi_remove_host(ioa_cfg->host);
  9242. __ipr_remove(pdev);
  9243. return rc;
  9244. }
  9245. rc = ipr_create_dump_file(&ioa_cfg->host->shost_dev.kobj,
  9246. &ipr_dump_attr);
  9247. if (rc) {
  9248. sysfs_remove_bin_file(&ioa_cfg->host->shost_dev.kobj,
  9249. &ipr_ioa_async_err_log);
  9250. ipr_remove_trace_file(&ioa_cfg->host->shost_dev.kobj,
  9251. &ipr_trace_attr);
  9252. scsi_remove_host(ioa_cfg->host);
  9253. __ipr_remove(pdev);
  9254. return rc;
  9255. }
  9256. spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
  9257. ioa_cfg->scan_enabled = 1;
  9258. schedule_work(&ioa_cfg->work_q);
  9259. spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
  9260. ioa_cfg->iopoll_weight = ioa_cfg->chip_cfg->iopoll_weight;
  9261. if (ioa_cfg->iopoll_weight && ioa_cfg->sis64 && ioa_cfg->nvectors > 1) {
  9262. for (i = 1; i < ioa_cfg->hrrq_num; i++) {
  9263. irq_poll_init(&ioa_cfg->hrrq[i].iopoll,
  9264. ioa_cfg->iopoll_weight, ipr_iopoll);
  9265. }
  9266. }
  9267. scsi_scan_host(ioa_cfg->host);
  9268. return 0;
  9269. }
  9270. /**
  9271. * ipr_shutdown - Shutdown handler.
  9272. * @pdev: pci device struct
  9273. *
  9274. * This function is invoked upon system shutdown/reboot. It will issue
  9275. * an adapter shutdown to the adapter to flush the write cache.
  9276. *
  9277. * Return value:
  9278. * none
  9279. **/
  9280. static void ipr_shutdown(struct pci_dev *pdev)
  9281. {
  9282. struct ipr_ioa_cfg *ioa_cfg = pci_get_drvdata(pdev);
  9283. unsigned long lock_flags = 0;
  9284. enum ipr_shutdown_type shutdown_type = IPR_SHUTDOWN_NORMAL;
  9285. int i;
  9286. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  9287. if (ioa_cfg->iopoll_weight && ioa_cfg->sis64 && ioa_cfg->nvectors > 1) {
  9288. ioa_cfg->iopoll_weight = 0;
  9289. for (i = 1; i < ioa_cfg->hrrq_num; i++)
  9290. irq_poll_disable(&ioa_cfg->hrrq[i].iopoll);
  9291. }
  9292. while (ioa_cfg->in_reset_reload) {
  9293. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  9294. wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
  9295. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  9296. }
  9297. if (ipr_fast_reboot && system_state == SYSTEM_RESTART && ioa_cfg->sis64)
  9298. shutdown_type = IPR_SHUTDOWN_QUIESCE;
  9299. ipr_initiate_ioa_bringdown(ioa_cfg, shutdown_type);
  9300. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  9301. wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
  9302. if (ipr_fast_reboot && system_state == SYSTEM_RESTART && ioa_cfg->sis64) {
  9303. ipr_free_irqs(ioa_cfg);
  9304. pci_disable_device(ioa_cfg->pdev);
  9305. }
  9306. }
  9307. static struct pci_device_id ipr_pci_table[] = {
  9308. { PCI_VENDOR_ID_MYLEX, PCI_DEVICE_ID_IBM_GEMSTONE,
  9309. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_5702, 0, 0, 0 },
  9310. { PCI_VENDOR_ID_MYLEX, PCI_DEVICE_ID_IBM_GEMSTONE,
  9311. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_5703, 0, 0, 0 },
  9312. { PCI_VENDOR_ID_MYLEX, PCI_DEVICE_ID_IBM_GEMSTONE,
  9313. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_573D, 0, 0, 0 },
  9314. { PCI_VENDOR_ID_MYLEX, PCI_DEVICE_ID_IBM_GEMSTONE,
  9315. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_573E, 0, 0, 0 },
  9316. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CITRINE,
  9317. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_571B, 0, 0, 0 },
  9318. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CITRINE,
  9319. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_572E, 0, 0, 0 },
  9320. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CITRINE,
  9321. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_571A, 0, 0, 0 },
  9322. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CITRINE,
  9323. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_575B, 0, 0,
  9324. IPR_USE_LONG_TRANSOP_TIMEOUT },
  9325. { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_OBSIDIAN,
  9326. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_572A, 0, 0, 0 },
  9327. { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_OBSIDIAN,
  9328. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_572B, 0, 0,
  9329. IPR_USE_LONG_TRANSOP_TIMEOUT },
  9330. { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_OBSIDIAN,
  9331. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_575C, 0, 0,
  9332. IPR_USE_LONG_TRANSOP_TIMEOUT },
  9333. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN,
  9334. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_572A, 0, 0, 0 },
  9335. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN,
  9336. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_572B, 0, 0,
  9337. IPR_USE_LONG_TRANSOP_TIMEOUT},
  9338. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN,
  9339. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_575C, 0, 0,
  9340. IPR_USE_LONG_TRANSOP_TIMEOUT },
  9341. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN_E,
  9342. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_574E, 0, 0,
  9343. IPR_USE_LONG_TRANSOP_TIMEOUT },
  9344. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN_E,
  9345. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57B3, 0, 0, 0 },
  9346. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN_E,
  9347. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57CC, 0, 0, 0 },
  9348. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN_E,
  9349. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57B7, 0, 0,
  9350. IPR_USE_LONG_TRANSOP_TIMEOUT | IPR_USE_PCI_WARM_RESET },
  9351. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_SNIPE,
  9352. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_2780, 0, 0, 0 },
  9353. { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_SCAMP,
  9354. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_571E, 0, 0, 0 },
  9355. { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_SCAMP,
  9356. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_571F, 0, 0,
  9357. IPR_USE_LONG_TRANSOP_TIMEOUT },
  9358. { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_SCAMP,
  9359. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_572F, 0, 0,
  9360. IPR_USE_LONG_TRANSOP_TIMEOUT },
  9361. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROC_FPGA_E2,
  9362. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57B5, 0, 0, 0 },
  9363. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROC_FPGA_E2,
  9364. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_574D, 0, 0, 0 },
  9365. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROC_FPGA_E2,
  9366. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57B2, 0, 0, 0 },
  9367. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROC_FPGA_E2,
  9368. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57C0, 0, 0, 0 },
  9369. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROC_FPGA_E2,
  9370. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57C3, 0, 0, 0 },
  9371. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROC_FPGA_E2,
  9372. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57C4, 0, 0, 0 },
  9373. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
  9374. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57B4, 0, 0, 0 },
  9375. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
  9376. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57B1, 0, 0, 0 },
  9377. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
  9378. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57C6, 0, 0, 0 },
  9379. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
  9380. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57C8, 0, 0, 0 },
  9381. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
  9382. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57CE, 0, 0, 0 },
  9383. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
  9384. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57D5, 0, 0, 0 },
  9385. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
  9386. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57D6, 0, 0, 0 },
  9387. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
  9388. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57D7, 0, 0, 0 },
  9389. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
  9390. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57D8, 0, 0, 0 },
  9391. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
  9392. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57D9, 0, 0, 0 },
  9393. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
  9394. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57DA, 0, 0, 0 },
  9395. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
  9396. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57EB, 0, 0, 0 },
  9397. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
  9398. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57EC, 0, 0, 0 },
  9399. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
  9400. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57ED, 0, 0, 0 },
  9401. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
  9402. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57EE, 0, 0, 0 },
  9403. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
  9404. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57EF, 0, 0, 0 },
  9405. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
  9406. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57F0, 0, 0, 0 },
  9407. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
  9408. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_2CCA, 0, 0, 0 },
  9409. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
  9410. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_2CD2, 0, 0, 0 },
  9411. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
  9412. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_2CCD, 0, 0, 0 },
  9413. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_RATTLESNAKE,
  9414. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_580A, 0, 0, 0 },
  9415. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_RATTLESNAKE,
  9416. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_580B, 0, 0, 0 },
  9417. { }
  9418. };
  9419. MODULE_DEVICE_TABLE(pci, ipr_pci_table);
  9420. static const struct pci_error_handlers ipr_err_handler = {
  9421. .error_detected = ipr_pci_error_detected,
  9422. .mmio_enabled = ipr_pci_mmio_enabled,
  9423. .slot_reset = ipr_pci_slot_reset,
  9424. };
  9425. static struct pci_driver ipr_driver = {
  9426. .name = IPR_NAME,
  9427. .id_table = ipr_pci_table,
  9428. .probe = ipr_probe,
  9429. .remove = ipr_remove,
  9430. .shutdown = ipr_shutdown,
  9431. .err_handler = &ipr_err_handler,
  9432. };
  9433. /**
  9434. * ipr_halt_done - Shutdown prepare completion
  9435. *
  9436. * Return value:
  9437. * none
  9438. **/
  9439. static void ipr_halt_done(struct ipr_cmnd *ipr_cmd)
  9440. {
  9441. list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_free_q);
  9442. }
  9443. /**
  9444. * ipr_halt - Issue shutdown prepare to all adapters
  9445. *
  9446. * Return value:
  9447. * NOTIFY_OK on success / NOTIFY_DONE on failure
  9448. **/
  9449. static int ipr_halt(struct notifier_block *nb, ulong event, void *buf)
  9450. {
  9451. struct ipr_cmnd *ipr_cmd;
  9452. struct ipr_ioa_cfg *ioa_cfg;
  9453. unsigned long flags = 0, driver_lock_flags;
  9454. if (event != SYS_RESTART && event != SYS_HALT && event != SYS_POWER_OFF)
  9455. return NOTIFY_DONE;
  9456. spin_lock_irqsave(&ipr_driver_lock, driver_lock_flags);
  9457. list_for_each_entry(ioa_cfg, &ipr_ioa_head, queue) {
  9458. spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
  9459. if (!ioa_cfg->hrrq[IPR_INIT_HRRQ].allow_cmds ||
  9460. (ipr_fast_reboot && event == SYS_RESTART && ioa_cfg->sis64)) {
  9461. spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
  9462. continue;
  9463. }
  9464. ipr_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
  9465. ipr_cmd->ioarcb.res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
  9466. ipr_cmd->ioarcb.cmd_pkt.request_type = IPR_RQTYPE_IOACMD;
  9467. ipr_cmd->ioarcb.cmd_pkt.cdb[0] = IPR_IOA_SHUTDOWN;
  9468. ipr_cmd->ioarcb.cmd_pkt.cdb[1] = IPR_SHUTDOWN_PREPARE_FOR_NORMAL;
  9469. ipr_do_req(ipr_cmd, ipr_halt_done, ipr_timeout, IPR_DEVICE_RESET_TIMEOUT);
  9470. spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
  9471. }
  9472. spin_unlock_irqrestore(&ipr_driver_lock, driver_lock_flags);
  9473. return NOTIFY_OK;
  9474. }
  9475. static struct notifier_block ipr_notifier = {
  9476. ipr_halt, NULL, 0
  9477. };
  9478. /**
  9479. * ipr_init - Module entry point
  9480. *
  9481. * Return value:
  9482. * 0 on success / negative value on failure
  9483. **/
  9484. static int __init ipr_init(void)
  9485. {
  9486. ipr_info("IBM Power RAID SCSI Device Driver version: %s %s\n",
  9487. IPR_DRIVER_VERSION, IPR_DRIVER_DATE);
  9488. register_reboot_notifier(&ipr_notifier);
  9489. return pci_register_driver(&ipr_driver);
  9490. }
  9491. /**
  9492. * ipr_exit - Module unload
  9493. *
  9494. * Module unload entry point.
  9495. *
  9496. * Return value:
  9497. * none
  9498. **/
  9499. static void __exit ipr_exit(void)
  9500. {
  9501. unregister_reboot_notifier(&ipr_notifier);
  9502. pci_unregister_driver(&ipr_driver);
  9503. }
  9504. module_init(ipr_init);
  9505. module_exit(ipr_exit);