ipr.c 293 KB

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