ipr.c 216 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886
  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/ioport.h>
  61. #include <linux/delay.h>
  62. #include <linux/pci.h>
  63. #include <linux/wait.h>
  64. #include <linux/spinlock.h>
  65. #include <linux/sched.h>
  66. #include <linux/interrupt.h>
  67. #include <linux/blkdev.h>
  68. #include <linux/firmware.h>
  69. #include <linux/module.h>
  70. #include <linux/moduleparam.h>
  71. #include <linux/libata.h>
  72. #include <linux/hdreg.h>
  73. #include <asm/io.h>
  74. #include <asm/irq.h>
  75. #include <asm/processor.h>
  76. #include <scsi/scsi.h>
  77. #include <scsi/scsi_host.h>
  78. #include <scsi/scsi_tcq.h>
  79. #include <scsi/scsi_eh.h>
  80. #include <scsi/scsi_cmnd.h>
  81. #include "ipr.h"
  82. /*
  83. * Global Data
  84. */
  85. static LIST_HEAD(ipr_ioa_head);
  86. static unsigned int ipr_log_level = IPR_DEFAULT_LOG_LEVEL;
  87. static unsigned int ipr_max_speed = 1;
  88. static int ipr_testmode = 0;
  89. static unsigned int ipr_fastfail = 0;
  90. static unsigned int ipr_transop_timeout = 0;
  91. static unsigned int ipr_enable_cache = 1;
  92. static unsigned int ipr_debug = 0;
  93. static unsigned int ipr_dual_ioa_raid = 1;
  94. static DEFINE_SPINLOCK(ipr_driver_lock);
  95. /* This table describes the differences between DMA controller chips */
  96. static const struct ipr_chip_cfg_t ipr_chip_cfg[] = {
  97. { /* Gemstone, Citrine, Obsidian, and Obsidian-E */
  98. .mailbox = 0x0042C,
  99. .cache_line_size = 0x20,
  100. {
  101. .set_interrupt_mask_reg = 0x0022C,
  102. .clr_interrupt_mask_reg = 0x00230,
  103. .sense_interrupt_mask_reg = 0x0022C,
  104. .clr_interrupt_reg = 0x00228,
  105. .sense_interrupt_reg = 0x00224,
  106. .ioarrin_reg = 0x00404,
  107. .sense_uproc_interrupt_reg = 0x00214,
  108. .set_uproc_interrupt_reg = 0x00214,
  109. .clr_uproc_interrupt_reg = 0x00218
  110. }
  111. },
  112. { /* Snipe and Scamp */
  113. .mailbox = 0x0052C,
  114. .cache_line_size = 0x20,
  115. {
  116. .set_interrupt_mask_reg = 0x00288,
  117. .clr_interrupt_mask_reg = 0x0028C,
  118. .sense_interrupt_mask_reg = 0x00288,
  119. .clr_interrupt_reg = 0x00284,
  120. .sense_interrupt_reg = 0x00280,
  121. .ioarrin_reg = 0x00504,
  122. .sense_uproc_interrupt_reg = 0x00290,
  123. .set_uproc_interrupt_reg = 0x00290,
  124. .clr_uproc_interrupt_reg = 0x00294
  125. }
  126. },
  127. };
  128. static const struct ipr_chip_t ipr_chip[] = {
  129. { PCI_VENDOR_ID_MYLEX, PCI_DEVICE_ID_IBM_GEMSTONE, &ipr_chip_cfg[0] },
  130. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CITRINE, &ipr_chip_cfg[0] },
  131. { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_OBSIDIAN, &ipr_chip_cfg[0] },
  132. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN, &ipr_chip_cfg[0] },
  133. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN_E, &ipr_chip_cfg[0] },
  134. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_SNIPE, &ipr_chip_cfg[1] },
  135. { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_SCAMP, &ipr_chip_cfg[1] }
  136. };
  137. static int ipr_max_bus_speeds [] = {
  138. IPR_80MBs_SCSI_RATE, IPR_U160_SCSI_RATE, IPR_U320_SCSI_RATE
  139. };
  140. MODULE_AUTHOR("Brian King <brking@us.ibm.com>");
  141. MODULE_DESCRIPTION("IBM Power RAID SCSI Adapter Driver");
  142. module_param_named(max_speed, ipr_max_speed, uint, 0);
  143. MODULE_PARM_DESC(max_speed, "Maximum bus speed (0-2). Default: 1=U160. Speeds: 0=80 MB/s, 1=U160, 2=U320");
  144. module_param_named(log_level, ipr_log_level, uint, 0);
  145. MODULE_PARM_DESC(log_level, "Set to 0 - 4 for increasing verbosity of device driver");
  146. module_param_named(testmode, ipr_testmode, int, 0);
  147. MODULE_PARM_DESC(testmode, "DANGEROUS!!! Allows unsupported configurations");
  148. module_param_named(fastfail, ipr_fastfail, int, 0);
  149. MODULE_PARM_DESC(fastfail, "Reduce timeouts and retries");
  150. module_param_named(transop_timeout, ipr_transop_timeout, int, 0);
  151. MODULE_PARM_DESC(transop_timeout, "Time in seconds to wait for adapter to come operational (default: 300)");
  152. module_param_named(enable_cache, ipr_enable_cache, int, 0);
  153. MODULE_PARM_DESC(enable_cache, "Enable adapter's non-volatile write cache (default: 1)");
  154. module_param_named(debug, ipr_debug, int, 0);
  155. MODULE_PARM_DESC(debug, "Enable device driver debugging logging. Set to 1 to enable. (default: 0)");
  156. module_param_named(dual_ioa_raid, ipr_dual_ioa_raid, int, 0);
  157. MODULE_PARM_DESC(dual_ioa_raid, "Enable dual adapter RAID support. Set to 1 to enable. (default: 1)");
  158. MODULE_LICENSE("GPL");
  159. MODULE_VERSION(IPR_DRIVER_VERSION);
  160. /* A constant array of IOASCs/URCs/Error Messages */
  161. static const
  162. struct ipr_error_table_t ipr_error_table[] = {
  163. {0x00000000, 1, IPR_DEFAULT_LOG_LEVEL,
  164. "8155: An unknown error was received"},
  165. {0x00330000, 0, 0,
  166. "Soft underlength error"},
  167. {0x005A0000, 0, 0,
  168. "Command to be cancelled not found"},
  169. {0x00808000, 0, 0,
  170. "Qualified success"},
  171. {0x01080000, 1, IPR_DEFAULT_LOG_LEVEL,
  172. "FFFE: Soft device bus error recovered by the IOA"},
  173. {0x01088100, 0, IPR_DEFAULT_LOG_LEVEL,
  174. "4101: Soft device bus fabric error"},
  175. {0x01170600, 0, IPR_DEFAULT_LOG_LEVEL,
  176. "FFF9: Device sector reassign successful"},
  177. {0x01170900, 0, IPR_DEFAULT_LOG_LEVEL,
  178. "FFF7: Media error recovered by device rewrite procedures"},
  179. {0x01180200, 0, IPR_DEFAULT_LOG_LEVEL,
  180. "7001: IOA sector reassignment successful"},
  181. {0x01180500, 0, IPR_DEFAULT_LOG_LEVEL,
  182. "FFF9: Soft media error. Sector reassignment recommended"},
  183. {0x01180600, 0, IPR_DEFAULT_LOG_LEVEL,
  184. "FFF7: Media error recovered by IOA rewrite procedures"},
  185. {0x01418000, 0, IPR_DEFAULT_LOG_LEVEL,
  186. "FF3D: Soft PCI bus error recovered by the IOA"},
  187. {0x01440000, 1, IPR_DEFAULT_LOG_LEVEL,
  188. "FFF6: Device hardware error recovered by the IOA"},
  189. {0x01448100, 0, IPR_DEFAULT_LOG_LEVEL,
  190. "FFF6: Device hardware error recovered by the device"},
  191. {0x01448200, 1, IPR_DEFAULT_LOG_LEVEL,
  192. "FF3D: Soft IOA error recovered by the IOA"},
  193. {0x01448300, 0, IPR_DEFAULT_LOG_LEVEL,
  194. "FFFA: Undefined device response recovered by the IOA"},
  195. {0x014A0000, 1, IPR_DEFAULT_LOG_LEVEL,
  196. "FFF6: Device bus error, message or command phase"},
  197. {0x014A8000, 0, IPR_DEFAULT_LOG_LEVEL,
  198. "FFFE: Task Management Function failed"},
  199. {0x015D0000, 0, IPR_DEFAULT_LOG_LEVEL,
  200. "FFF6: Failure prediction threshold exceeded"},
  201. {0x015D9200, 0, IPR_DEFAULT_LOG_LEVEL,
  202. "8009: Impending cache battery pack failure"},
  203. {0x02040400, 0, 0,
  204. "34FF: Disk device format in progress"},
  205. {0x02048000, 0, IPR_DEFAULT_LOG_LEVEL,
  206. "9070: IOA requested reset"},
  207. {0x023F0000, 0, 0,
  208. "Synchronization required"},
  209. {0x024E0000, 0, 0,
  210. "No ready, IOA shutdown"},
  211. {0x025A0000, 0, 0,
  212. "Not ready, IOA has been shutdown"},
  213. {0x02670100, 0, IPR_DEFAULT_LOG_LEVEL,
  214. "3020: Storage subsystem configuration error"},
  215. {0x03110B00, 0, 0,
  216. "FFF5: Medium error, data unreadable, recommend reassign"},
  217. {0x03110C00, 0, 0,
  218. "7000: Medium error, data unreadable, do not reassign"},
  219. {0x03310000, 0, IPR_DEFAULT_LOG_LEVEL,
  220. "FFF3: Disk media format bad"},
  221. {0x04050000, 0, IPR_DEFAULT_LOG_LEVEL,
  222. "3002: Addressed device failed to respond to selection"},
  223. {0x04080000, 1, IPR_DEFAULT_LOG_LEVEL,
  224. "3100: Device bus error"},
  225. {0x04080100, 0, IPR_DEFAULT_LOG_LEVEL,
  226. "3109: IOA timed out a device command"},
  227. {0x04088000, 0, 0,
  228. "3120: SCSI bus is not operational"},
  229. {0x04088100, 0, IPR_DEFAULT_LOG_LEVEL,
  230. "4100: Hard device bus fabric error"},
  231. {0x04118000, 0, IPR_DEFAULT_LOG_LEVEL,
  232. "9000: IOA reserved area data check"},
  233. {0x04118100, 0, IPR_DEFAULT_LOG_LEVEL,
  234. "9001: IOA reserved area invalid data pattern"},
  235. {0x04118200, 0, IPR_DEFAULT_LOG_LEVEL,
  236. "9002: IOA reserved area LRC error"},
  237. {0x04320000, 0, IPR_DEFAULT_LOG_LEVEL,
  238. "102E: Out of alternate sectors for disk storage"},
  239. {0x04330000, 1, IPR_DEFAULT_LOG_LEVEL,
  240. "FFF4: Data transfer underlength error"},
  241. {0x04338000, 1, IPR_DEFAULT_LOG_LEVEL,
  242. "FFF4: Data transfer overlength error"},
  243. {0x043E0100, 0, IPR_DEFAULT_LOG_LEVEL,
  244. "3400: Logical unit failure"},
  245. {0x04408500, 0, IPR_DEFAULT_LOG_LEVEL,
  246. "FFF4: Device microcode is corrupt"},
  247. {0x04418000, 1, IPR_DEFAULT_LOG_LEVEL,
  248. "8150: PCI bus error"},
  249. {0x04430000, 1, 0,
  250. "Unsupported device bus message received"},
  251. {0x04440000, 1, IPR_DEFAULT_LOG_LEVEL,
  252. "FFF4: Disk device problem"},
  253. {0x04448200, 1, IPR_DEFAULT_LOG_LEVEL,
  254. "8150: Permanent IOA failure"},
  255. {0x04448300, 0, IPR_DEFAULT_LOG_LEVEL,
  256. "3010: Disk device returned wrong response to IOA"},
  257. {0x04448400, 0, IPR_DEFAULT_LOG_LEVEL,
  258. "8151: IOA microcode error"},
  259. {0x04448500, 0, 0,
  260. "Device bus status error"},
  261. {0x04448600, 0, IPR_DEFAULT_LOG_LEVEL,
  262. "8157: IOA error requiring IOA reset to recover"},
  263. {0x04448700, 0, 0,
  264. "ATA device status error"},
  265. {0x04490000, 0, 0,
  266. "Message reject received from the device"},
  267. {0x04449200, 0, IPR_DEFAULT_LOG_LEVEL,
  268. "8008: A permanent cache battery pack failure occurred"},
  269. {0x0444A000, 0, IPR_DEFAULT_LOG_LEVEL,
  270. "9090: Disk unit has been modified after the last known status"},
  271. {0x0444A200, 0, IPR_DEFAULT_LOG_LEVEL,
  272. "9081: IOA detected device error"},
  273. {0x0444A300, 0, IPR_DEFAULT_LOG_LEVEL,
  274. "9082: IOA detected device error"},
  275. {0x044A0000, 1, IPR_DEFAULT_LOG_LEVEL,
  276. "3110: Device bus error, message or command phase"},
  277. {0x044A8000, 1, IPR_DEFAULT_LOG_LEVEL,
  278. "3110: SAS Command / Task Management Function failed"},
  279. {0x04670400, 0, IPR_DEFAULT_LOG_LEVEL,
  280. "9091: Incorrect hardware configuration change has been detected"},
  281. {0x04678000, 0, IPR_DEFAULT_LOG_LEVEL,
  282. "9073: Invalid multi-adapter configuration"},
  283. {0x04678100, 0, IPR_DEFAULT_LOG_LEVEL,
  284. "4010: Incorrect connection between cascaded expanders"},
  285. {0x04678200, 0, IPR_DEFAULT_LOG_LEVEL,
  286. "4020: Connections exceed IOA design limits"},
  287. {0x04678300, 0, IPR_DEFAULT_LOG_LEVEL,
  288. "4030: Incorrect multipath connection"},
  289. {0x04679000, 0, IPR_DEFAULT_LOG_LEVEL,
  290. "4110: Unsupported enclosure function"},
  291. {0x046E0000, 0, IPR_DEFAULT_LOG_LEVEL,
  292. "FFF4: Command to logical unit failed"},
  293. {0x05240000, 1, 0,
  294. "Illegal request, invalid request type or request packet"},
  295. {0x05250000, 0, 0,
  296. "Illegal request, invalid resource handle"},
  297. {0x05258000, 0, 0,
  298. "Illegal request, commands not allowed to this device"},
  299. {0x05258100, 0, 0,
  300. "Illegal request, command not allowed to a secondary adapter"},
  301. {0x05260000, 0, 0,
  302. "Illegal request, invalid field in parameter list"},
  303. {0x05260100, 0, 0,
  304. "Illegal request, parameter not supported"},
  305. {0x05260200, 0, 0,
  306. "Illegal request, parameter value invalid"},
  307. {0x052C0000, 0, 0,
  308. "Illegal request, command sequence error"},
  309. {0x052C8000, 1, 0,
  310. "Illegal request, dual adapter support not enabled"},
  311. {0x06040500, 0, IPR_DEFAULT_LOG_LEVEL,
  312. "9031: Array protection temporarily suspended, protection resuming"},
  313. {0x06040600, 0, IPR_DEFAULT_LOG_LEVEL,
  314. "9040: Array protection temporarily suspended, protection resuming"},
  315. {0x06288000, 0, IPR_DEFAULT_LOG_LEVEL,
  316. "3140: Device bus not ready to ready transition"},
  317. {0x06290000, 0, IPR_DEFAULT_LOG_LEVEL,
  318. "FFFB: SCSI bus was reset"},
  319. {0x06290500, 0, 0,
  320. "FFFE: SCSI bus transition to single ended"},
  321. {0x06290600, 0, 0,
  322. "FFFE: SCSI bus transition to LVD"},
  323. {0x06298000, 0, IPR_DEFAULT_LOG_LEVEL,
  324. "FFFB: SCSI bus was reset by another initiator"},
  325. {0x063F0300, 0, IPR_DEFAULT_LOG_LEVEL,
  326. "3029: A device replacement has occurred"},
  327. {0x064C8000, 0, IPR_DEFAULT_LOG_LEVEL,
  328. "9051: IOA cache data exists for a missing or failed device"},
  329. {0x064C8100, 0, IPR_DEFAULT_LOG_LEVEL,
  330. "9055: Auxiliary cache IOA contains cache data needed by the primary IOA"},
  331. {0x06670100, 0, IPR_DEFAULT_LOG_LEVEL,
  332. "9025: Disk unit is not supported at its physical location"},
  333. {0x06670600, 0, IPR_DEFAULT_LOG_LEVEL,
  334. "3020: IOA detected a SCSI bus configuration error"},
  335. {0x06678000, 0, IPR_DEFAULT_LOG_LEVEL,
  336. "3150: SCSI bus configuration error"},
  337. {0x06678100, 0, IPR_DEFAULT_LOG_LEVEL,
  338. "9074: Asymmetric advanced function disk configuration"},
  339. {0x06678300, 0, IPR_DEFAULT_LOG_LEVEL,
  340. "4040: Incomplete multipath connection between IOA and enclosure"},
  341. {0x06678400, 0, IPR_DEFAULT_LOG_LEVEL,
  342. "4041: Incomplete multipath connection between enclosure and device"},
  343. {0x06678500, 0, IPR_DEFAULT_LOG_LEVEL,
  344. "9075: Incomplete multipath connection between IOA and remote IOA"},
  345. {0x06678600, 0, IPR_DEFAULT_LOG_LEVEL,
  346. "9076: Configuration error, missing remote IOA"},
  347. {0x06679100, 0, IPR_DEFAULT_LOG_LEVEL,
  348. "4050: Enclosure does not support a required multipath function"},
  349. {0x06690200, 0, IPR_DEFAULT_LOG_LEVEL,
  350. "9041: Array protection temporarily suspended"},
  351. {0x06698200, 0, IPR_DEFAULT_LOG_LEVEL,
  352. "9042: Corrupt array parity detected on specified device"},
  353. {0x066B0200, 0, IPR_DEFAULT_LOG_LEVEL,
  354. "9030: Array no longer protected due to missing or failed disk unit"},
  355. {0x066B8000, 0, IPR_DEFAULT_LOG_LEVEL,
  356. "9071: Link operational transition"},
  357. {0x066B8100, 0, IPR_DEFAULT_LOG_LEVEL,
  358. "9072: Link not operational transition"},
  359. {0x066B8200, 0, IPR_DEFAULT_LOG_LEVEL,
  360. "9032: Array exposed but still protected"},
  361. {0x066B8300, 0, IPR_DEFAULT_LOG_LEVEL + 1,
  362. "70DD: Device forced failed by disrupt device command"},
  363. {0x066B9100, 0, IPR_DEFAULT_LOG_LEVEL,
  364. "4061: Multipath redundancy level got better"},
  365. {0x066B9200, 0, IPR_DEFAULT_LOG_LEVEL,
  366. "4060: Multipath redundancy level got worse"},
  367. {0x07270000, 0, 0,
  368. "Failure due to other device"},
  369. {0x07278000, 0, IPR_DEFAULT_LOG_LEVEL,
  370. "9008: IOA does not support functions expected by devices"},
  371. {0x07278100, 0, IPR_DEFAULT_LOG_LEVEL,
  372. "9010: Cache data associated with attached devices cannot be found"},
  373. {0x07278200, 0, IPR_DEFAULT_LOG_LEVEL,
  374. "9011: Cache data belongs to devices other than those attached"},
  375. {0x07278400, 0, IPR_DEFAULT_LOG_LEVEL,
  376. "9020: Array missing 2 or more devices with only 1 device present"},
  377. {0x07278500, 0, IPR_DEFAULT_LOG_LEVEL,
  378. "9021: Array missing 2 or more devices with 2 or more devices present"},
  379. {0x07278600, 0, IPR_DEFAULT_LOG_LEVEL,
  380. "9022: Exposed array is missing a required device"},
  381. {0x07278700, 0, IPR_DEFAULT_LOG_LEVEL,
  382. "9023: Array member(s) not at required physical locations"},
  383. {0x07278800, 0, IPR_DEFAULT_LOG_LEVEL,
  384. "9024: Array not functional due to present hardware configuration"},
  385. {0x07278900, 0, IPR_DEFAULT_LOG_LEVEL,
  386. "9026: Array not functional due to present hardware configuration"},
  387. {0x07278A00, 0, IPR_DEFAULT_LOG_LEVEL,
  388. "9027: Array is missing a device and parity is out of sync"},
  389. {0x07278B00, 0, IPR_DEFAULT_LOG_LEVEL,
  390. "9028: Maximum number of arrays already exist"},
  391. {0x07278C00, 0, IPR_DEFAULT_LOG_LEVEL,
  392. "9050: Required cache data cannot be located for a disk unit"},
  393. {0x07278D00, 0, IPR_DEFAULT_LOG_LEVEL,
  394. "9052: Cache data exists for a device that has been modified"},
  395. {0x07278F00, 0, IPR_DEFAULT_LOG_LEVEL,
  396. "9054: IOA resources not available due to previous problems"},
  397. {0x07279100, 0, IPR_DEFAULT_LOG_LEVEL,
  398. "9092: Disk unit requires initialization before use"},
  399. {0x07279200, 0, IPR_DEFAULT_LOG_LEVEL,
  400. "9029: Incorrect hardware configuration change has been detected"},
  401. {0x07279600, 0, IPR_DEFAULT_LOG_LEVEL,
  402. "9060: One or more disk pairs are missing from an array"},
  403. {0x07279700, 0, IPR_DEFAULT_LOG_LEVEL,
  404. "9061: One or more disks are missing from an array"},
  405. {0x07279800, 0, IPR_DEFAULT_LOG_LEVEL,
  406. "9062: One or more disks are missing from an array"},
  407. {0x07279900, 0, IPR_DEFAULT_LOG_LEVEL,
  408. "9063: Maximum number of functional arrays has been exceeded"},
  409. {0x0B260000, 0, 0,
  410. "Aborted command, invalid descriptor"},
  411. {0x0B5A0000, 0, 0,
  412. "Command terminated by host"}
  413. };
  414. static const struct ipr_ses_table_entry ipr_ses_table[] = {
  415. { "2104-DL1 ", "XXXXXXXXXXXXXXXX", 80 },
  416. { "2104-TL1 ", "XXXXXXXXXXXXXXXX", 80 },
  417. { "HSBP07M P U2SCSI", "XXXXXXXXXXXXXXXX", 80 }, /* Hidive 7 slot */
  418. { "HSBP05M P U2SCSI", "XXXXXXXXXXXXXXXX", 80 }, /* Hidive 5 slot */
  419. { "HSBP05M S U2SCSI", "XXXXXXXXXXXXXXXX", 80 }, /* Bowtie */
  420. { "HSBP06E ASU2SCSI", "XXXXXXXXXXXXXXXX", 80 }, /* MartinFenning */
  421. { "2104-DU3 ", "XXXXXXXXXXXXXXXX", 160 },
  422. { "2104-TU3 ", "XXXXXXXXXXXXXXXX", 160 },
  423. { "HSBP04C RSU2SCSI", "XXXXXXX*XXXXXXXX", 160 },
  424. { "HSBP06E RSU2SCSI", "XXXXXXX*XXXXXXXX", 160 },
  425. { "St V1S2 ", "XXXXXXXXXXXXXXXX", 160 },
  426. { "HSBPD4M PU3SCSI", "XXXXXXX*XXXXXXXX", 160 },
  427. { "VSBPD1H U3SCSI", "XXXXXXX*XXXXXXXX", 160 }
  428. };
  429. /*
  430. * Function Prototypes
  431. */
  432. static int ipr_reset_alert(struct ipr_cmnd *);
  433. static void ipr_process_ccn(struct ipr_cmnd *);
  434. static void ipr_process_error(struct ipr_cmnd *);
  435. static void ipr_reset_ioa_job(struct ipr_cmnd *);
  436. static void ipr_initiate_ioa_reset(struct ipr_ioa_cfg *,
  437. enum ipr_shutdown_type);
  438. #ifdef CONFIG_SCSI_IPR_TRACE
  439. /**
  440. * ipr_trc_hook - Add a trace entry to the driver trace
  441. * @ipr_cmd: ipr command struct
  442. * @type: trace type
  443. * @add_data: additional data
  444. *
  445. * Return value:
  446. * none
  447. **/
  448. static void ipr_trc_hook(struct ipr_cmnd *ipr_cmd,
  449. u8 type, u32 add_data)
  450. {
  451. struct ipr_trace_entry *trace_entry;
  452. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  453. trace_entry = &ioa_cfg->trace[ioa_cfg->trace_index++];
  454. trace_entry->time = jiffies;
  455. trace_entry->op_code = ipr_cmd->ioarcb.cmd_pkt.cdb[0];
  456. trace_entry->type = type;
  457. trace_entry->ata_op_code = ipr_cmd->ioarcb.add_data.u.regs.command;
  458. trace_entry->cmd_index = ipr_cmd->cmd_index & 0xff;
  459. trace_entry->res_handle = ipr_cmd->ioarcb.res_handle;
  460. trace_entry->u.add_data = add_data;
  461. }
  462. #else
  463. #define ipr_trc_hook(ipr_cmd, type, add_data) do { } while(0)
  464. #endif
  465. /**
  466. * ipr_reinit_ipr_cmnd - Re-initialize an IPR Cmnd block for reuse
  467. * @ipr_cmd: ipr command struct
  468. *
  469. * Return value:
  470. * none
  471. **/
  472. static void ipr_reinit_ipr_cmnd(struct ipr_cmnd *ipr_cmd)
  473. {
  474. struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
  475. struct ipr_ioasa *ioasa = &ipr_cmd->ioasa;
  476. dma_addr_t dma_addr = be32_to_cpu(ioarcb->ioarcb_host_pci_addr);
  477. memset(&ioarcb->cmd_pkt, 0, sizeof(struct ipr_cmd_pkt));
  478. ioarcb->write_data_transfer_length = 0;
  479. ioarcb->read_data_transfer_length = 0;
  480. ioarcb->write_ioadl_len = 0;
  481. ioarcb->read_ioadl_len = 0;
  482. ioarcb->write_ioadl_addr =
  483. cpu_to_be32(dma_addr + offsetof(struct ipr_cmnd, ioadl));
  484. ioarcb->read_ioadl_addr = ioarcb->write_ioadl_addr;
  485. ioasa->ioasc = 0;
  486. ioasa->residual_data_len = 0;
  487. ioasa->u.gata.status = 0;
  488. ipr_cmd->scsi_cmd = NULL;
  489. ipr_cmd->qc = NULL;
  490. ipr_cmd->sense_buffer[0] = 0;
  491. ipr_cmd->dma_use_sg = 0;
  492. }
  493. /**
  494. * ipr_init_ipr_cmnd - Initialize an IPR Cmnd block
  495. * @ipr_cmd: ipr command struct
  496. *
  497. * Return value:
  498. * none
  499. **/
  500. static void ipr_init_ipr_cmnd(struct ipr_cmnd *ipr_cmd)
  501. {
  502. ipr_reinit_ipr_cmnd(ipr_cmd);
  503. ipr_cmd->u.scratch = 0;
  504. ipr_cmd->sibling = NULL;
  505. init_timer(&ipr_cmd->timer);
  506. }
  507. /**
  508. * ipr_get_free_ipr_cmnd - Get a free IPR Cmnd block
  509. * @ioa_cfg: ioa config struct
  510. *
  511. * Return value:
  512. * pointer to ipr command struct
  513. **/
  514. static
  515. struct ipr_cmnd *ipr_get_free_ipr_cmnd(struct ipr_ioa_cfg *ioa_cfg)
  516. {
  517. struct ipr_cmnd *ipr_cmd;
  518. ipr_cmd = list_entry(ioa_cfg->free_q.next, struct ipr_cmnd, queue);
  519. list_del(&ipr_cmd->queue);
  520. ipr_init_ipr_cmnd(ipr_cmd);
  521. return ipr_cmd;
  522. }
  523. /**
  524. * ipr_mask_and_clear_interrupts - Mask all and clear specified interrupts
  525. * @ioa_cfg: ioa config struct
  526. * @clr_ints: interrupts to clear
  527. *
  528. * This function masks all interrupts on the adapter, then clears the
  529. * interrupts specified in the mask
  530. *
  531. * Return value:
  532. * none
  533. **/
  534. static void ipr_mask_and_clear_interrupts(struct ipr_ioa_cfg *ioa_cfg,
  535. u32 clr_ints)
  536. {
  537. volatile u32 int_reg;
  538. /* Stop new interrupts */
  539. ioa_cfg->allow_interrupts = 0;
  540. /* Set interrupt mask to stop all new interrupts */
  541. writel(~0, ioa_cfg->regs.set_interrupt_mask_reg);
  542. /* Clear any pending interrupts */
  543. writel(clr_ints, ioa_cfg->regs.clr_interrupt_reg);
  544. int_reg = readl(ioa_cfg->regs.sense_interrupt_reg);
  545. }
  546. /**
  547. * ipr_save_pcix_cmd_reg - Save PCI-X command register
  548. * @ioa_cfg: ioa config struct
  549. *
  550. * Return value:
  551. * 0 on success / -EIO on failure
  552. **/
  553. static int ipr_save_pcix_cmd_reg(struct ipr_ioa_cfg *ioa_cfg)
  554. {
  555. int pcix_cmd_reg = pci_find_capability(ioa_cfg->pdev, PCI_CAP_ID_PCIX);
  556. if (pcix_cmd_reg == 0)
  557. return 0;
  558. if (pci_read_config_word(ioa_cfg->pdev, pcix_cmd_reg + PCI_X_CMD,
  559. &ioa_cfg->saved_pcix_cmd_reg) != PCIBIOS_SUCCESSFUL) {
  560. dev_err(&ioa_cfg->pdev->dev, "Failed to save PCI-X command register\n");
  561. return -EIO;
  562. }
  563. ioa_cfg->saved_pcix_cmd_reg |= PCI_X_CMD_DPERR_E | PCI_X_CMD_ERO;
  564. return 0;
  565. }
  566. /**
  567. * ipr_set_pcix_cmd_reg - Setup PCI-X command register
  568. * @ioa_cfg: ioa config struct
  569. *
  570. * Return value:
  571. * 0 on success / -EIO on failure
  572. **/
  573. static int ipr_set_pcix_cmd_reg(struct ipr_ioa_cfg *ioa_cfg)
  574. {
  575. int pcix_cmd_reg = pci_find_capability(ioa_cfg->pdev, PCI_CAP_ID_PCIX);
  576. if (pcix_cmd_reg) {
  577. if (pci_write_config_word(ioa_cfg->pdev, pcix_cmd_reg + PCI_X_CMD,
  578. ioa_cfg->saved_pcix_cmd_reg) != PCIBIOS_SUCCESSFUL) {
  579. dev_err(&ioa_cfg->pdev->dev, "Failed to setup PCI-X command register\n");
  580. return -EIO;
  581. }
  582. }
  583. return 0;
  584. }
  585. /**
  586. * ipr_sata_eh_done - done function for aborted SATA commands
  587. * @ipr_cmd: ipr command struct
  588. *
  589. * This function is invoked for ops generated to SATA
  590. * devices which are being aborted.
  591. *
  592. * Return value:
  593. * none
  594. **/
  595. static void ipr_sata_eh_done(struct ipr_cmnd *ipr_cmd)
  596. {
  597. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  598. struct ata_queued_cmd *qc = ipr_cmd->qc;
  599. struct ipr_sata_port *sata_port = qc->ap->private_data;
  600. qc->err_mask |= AC_ERR_OTHER;
  601. sata_port->ioasa.status |= ATA_BUSY;
  602. list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
  603. ata_qc_complete(qc);
  604. }
  605. /**
  606. * ipr_scsi_eh_done - mid-layer done function for aborted ops
  607. * @ipr_cmd: ipr command struct
  608. *
  609. * This function is invoked by the interrupt handler for
  610. * ops generated by the SCSI mid-layer which are being aborted.
  611. *
  612. * Return value:
  613. * none
  614. **/
  615. static void ipr_scsi_eh_done(struct ipr_cmnd *ipr_cmd)
  616. {
  617. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  618. struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
  619. scsi_cmd->result |= (DID_ERROR << 16);
  620. scsi_dma_unmap(ipr_cmd->scsi_cmd);
  621. scsi_cmd->scsi_done(scsi_cmd);
  622. list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
  623. }
  624. /**
  625. * ipr_fail_all_ops - Fails all outstanding ops.
  626. * @ioa_cfg: ioa config struct
  627. *
  628. * This function fails all outstanding ops.
  629. *
  630. * Return value:
  631. * none
  632. **/
  633. static void ipr_fail_all_ops(struct ipr_ioa_cfg *ioa_cfg)
  634. {
  635. struct ipr_cmnd *ipr_cmd, *temp;
  636. ENTER;
  637. list_for_each_entry_safe(ipr_cmd, temp, &ioa_cfg->pending_q, queue) {
  638. list_del(&ipr_cmd->queue);
  639. ipr_cmd->ioasa.ioasc = cpu_to_be32(IPR_IOASC_IOA_WAS_RESET);
  640. ipr_cmd->ioasa.ilid = cpu_to_be32(IPR_DRIVER_ILID);
  641. if (ipr_cmd->scsi_cmd)
  642. ipr_cmd->done = ipr_scsi_eh_done;
  643. else if (ipr_cmd->qc)
  644. ipr_cmd->done = ipr_sata_eh_done;
  645. ipr_trc_hook(ipr_cmd, IPR_TRACE_FINISH, IPR_IOASC_IOA_WAS_RESET);
  646. del_timer(&ipr_cmd->timer);
  647. ipr_cmd->done(ipr_cmd);
  648. }
  649. LEAVE;
  650. }
  651. /**
  652. * ipr_do_req - Send driver initiated requests.
  653. * @ipr_cmd: ipr command struct
  654. * @done: done function
  655. * @timeout_func: timeout function
  656. * @timeout: timeout value
  657. *
  658. * This function sends the specified command to the adapter with the
  659. * timeout given. The done function is invoked on command completion.
  660. *
  661. * Return value:
  662. * none
  663. **/
  664. static void ipr_do_req(struct ipr_cmnd *ipr_cmd,
  665. void (*done) (struct ipr_cmnd *),
  666. void (*timeout_func) (struct ipr_cmnd *), u32 timeout)
  667. {
  668. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  669. list_add_tail(&ipr_cmd->queue, &ioa_cfg->pending_q);
  670. ipr_cmd->done = done;
  671. ipr_cmd->timer.data = (unsigned long) ipr_cmd;
  672. ipr_cmd->timer.expires = jiffies + timeout;
  673. ipr_cmd->timer.function = (void (*)(unsigned long))timeout_func;
  674. add_timer(&ipr_cmd->timer);
  675. ipr_trc_hook(ipr_cmd, IPR_TRACE_START, 0);
  676. mb();
  677. writel(be32_to_cpu(ipr_cmd->ioarcb.ioarcb_host_pci_addr),
  678. ioa_cfg->regs.ioarrin_reg);
  679. }
  680. /**
  681. * ipr_internal_cmd_done - Op done function for an internally generated op.
  682. * @ipr_cmd: ipr command struct
  683. *
  684. * This function is the op done function for an internally generated,
  685. * blocking op. It simply wakes the sleeping thread.
  686. *
  687. * Return value:
  688. * none
  689. **/
  690. static void ipr_internal_cmd_done(struct ipr_cmnd *ipr_cmd)
  691. {
  692. if (ipr_cmd->sibling)
  693. ipr_cmd->sibling = NULL;
  694. else
  695. complete(&ipr_cmd->completion);
  696. }
  697. /**
  698. * ipr_send_blocking_cmd - Send command and sleep on its completion.
  699. * @ipr_cmd: ipr command struct
  700. * @timeout_func: function to invoke if command times out
  701. * @timeout: timeout
  702. *
  703. * Return value:
  704. * none
  705. **/
  706. static void ipr_send_blocking_cmd(struct ipr_cmnd *ipr_cmd,
  707. void (*timeout_func) (struct ipr_cmnd *ipr_cmd),
  708. u32 timeout)
  709. {
  710. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  711. init_completion(&ipr_cmd->completion);
  712. ipr_do_req(ipr_cmd, ipr_internal_cmd_done, timeout_func, timeout);
  713. spin_unlock_irq(ioa_cfg->host->host_lock);
  714. wait_for_completion(&ipr_cmd->completion);
  715. spin_lock_irq(ioa_cfg->host->host_lock);
  716. }
  717. /**
  718. * ipr_send_hcam - Send an HCAM to the adapter.
  719. * @ioa_cfg: ioa config struct
  720. * @type: HCAM type
  721. * @hostrcb: hostrcb struct
  722. *
  723. * This function will send a Host Controlled Async command to the adapter.
  724. * If HCAMs are currently not allowed to be issued to the adapter, it will
  725. * place the hostrcb on the free queue.
  726. *
  727. * Return value:
  728. * none
  729. **/
  730. static void ipr_send_hcam(struct ipr_ioa_cfg *ioa_cfg, u8 type,
  731. struct ipr_hostrcb *hostrcb)
  732. {
  733. struct ipr_cmnd *ipr_cmd;
  734. struct ipr_ioarcb *ioarcb;
  735. if (ioa_cfg->allow_cmds) {
  736. ipr_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
  737. list_add_tail(&ipr_cmd->queue, &ioa_cfg->pending_q);
  738. list_add_tail(&hostrcb->queue, &ioa_cfg->hostrcb_pending_q);
  739. ipr_cmd->u.hostrcb = hostrcb;
  740. ioarcb = &ipr_cmd->ioarcb;
  741. ioarcb->res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
  742. ioarcb->cmd_pkt.request_type = IPR_RQTYPE_HCAM;
  743. ioarcb->cmd_pkt.cdb[0] = IPR_HOST_CONTROLLED_ASYNC;
  744. ioarcb->cmd_pkt.cdb[1] = type;
  745. ioarcb->cmd_pkt.cdb[7] = (sizeof(hostrcb->hcam) >> 8) & 0xff;
  746. ioarcb->cmd_pkt.cdb[8] = sizeof(hostrcb->hcam) & 0xff;
  747. ioarcb->read_data_transfer_length = cpu_to_be32(sizeof(hostrcb->hcam));
  748. ioarcb->read_ioadl_len = cpu_to_be32(sizeof(struct ipr_ioadl_desc));
  749. ipr_cmd->ioadl[0].flags_and_data_len =
  750. cpu_to_be32(IPR_IOADL_FLAGS_READ_LAST | sizeof(hostrcb->hcam));
  751. ipr_cmd->ioadl[0].address = cpu_to_be32(hostrcb->hostrcb_dma);
  752. if (type == IPR_HCAM_CDB_OP_CODE_CONFIG_CHANGE)
  753. ipr_cmd->done = ipr_process_ccn;
  754. else
  755. ipr_cmd->done = ipr_process_error;
  756. ipr_trc_hook(ipr_cmd, IPR_TRACE_START, IPR_IOA_RES_ADDR);
  757. mb();
  758. writel(be32_to_cpu(ipr_cmd->ioarcb.ioarcb_host_pci_addr),
  759. ioa_cfg->regs.ioarrin_reg);
  760. } else {
  761. list_add_tail(&hostrcb->queue, &ioa_cfg->hostrcb_free_q);
  762. }
  763. }
  764. /**
  765. * ipr_init_res_entry - Initialize a resource entry struct.
  766. * @res: resource entry struct
  767. *
  768. * Return value:
  769. * none
  770. **/
  771. static void ipr_init_res_entry(struct ipr_resource_entry *res)
  772. {
  773. res->needs_sync_complete = 0;
  774. res->in_erp = 0;
  775. res->add_to_ml = 0;
  776. res->del_from_ml = 0;
  777. res->resetting_device = 0;
  778. res->sdev = NULL;
  779. res->sata_port = NULL;
  780. }
  781. /**
  782. * ipr_handle_config_change - Handle a config change from the adapter
  783. * @ioa_cfg: ioa config struct
  784. * @hostrcb: hostrcb
  785. *
  786. * Return value:
  787. * none
  788. **/
  789. static void ipr_handle_config_change(struct ipr_ioa_cfg *ioa_cfg,
  790. struct ipr_hostrcb *hostrcb)
  791. {
  792. struct ipr_resource_entry *res = NULL;
  793. struct ipr_config_table_entry *cfgte;
  794. u32 is_ndn = 1;
  795. cfgte = &hostrcb->hcam.u.ccn.cfgte;
  796. list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
  797. if (!memcmp(&res->cfgte.res_addr, &cfgte->res_addr,
  798. sizeof(cfgte->res_addr))) {
  799. is_ndn = 0;
  800. break;
  801. }
  802. }
  803. if (is_ndn) {
  804. if (list_empty(&ioa_cfg->free_res_q)) {
  805. ipr_send_hcam(ioa_cfg,
  806. IPR_HCAM_CDB_OP_CODE_CONFIG_CHANGE,
  807. hostrcb);
  808. return;
  809. }
  810. res = list_entry(ioa_cfg->free_res_q.next,
  811. struct ipr_resource_entry, queue);
  812. list_del(&res->queue);
  813. ipr_init_res_entry(res);
  814. list_add_tail(&res->queue, &ioa_cfg->used_res_q);
  815. }
  816. memcpy(&res->cfgte, cfgte, sizeof(struct ipr_config_table_entry));
  817. if (hostrcb->hcam.notify_type == IPR_HOST_RCB_NOTIF_TYPE_REM_ENTRY) {
  818. if (res->sdev) {
  819. res->del_from_ml = 1;
  820. res->cfgte.res_handle = IPR_INVALID_RES_HANDLE;
  821. if (ioa_cfg->allow_ml_add_del)
  822. schedule_work(&ioa_cfg->work_q);
  823. } else
  824. list_move_tail(&res->queue, &ioa_cfg->free_res_q);
  825. } else if (!res->sdev) {
  826. res->add_to_ml = 1;
  827. if (ioa_cfg->allow_ml_add_del)
  828. schedule_work(&ioa_cfg->work_q);
  829. }
  830. ipr_send_hcam(ioa_cfg, IPR_HCAM_CDB_OP_CODE_CONFIG_CHANGE, hostrcb);
  831. }
  832. /**
  833. * ipr_process_ccn - Op done function for a CCN.
  834. * @ipr_cmd: ipr command struct
  835. *
  836. * This function is the op done function for a configuration
  837. * change notification host controlled async from the adapter.
  838. *
  839. * Return value:
  840. * none
  841. **/
  842. static void ipr_process_ccn(struct ipr_cmnd *ipr_cmd)
  843. {
  844. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  845. struct ipr_hostrcb *hostrcb = ipr_cmd->u.hostrcb;
  846. u32 ioasc = be32_to_cpu(ipr_cmd->ioasa.ioasc);
  847. list_del(&hostrcb->queue);
  848. list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
  849. if (ioasc) {
  850. if (ioasc != IPR_IOASC_IOA_WAS_RESET)
  851. dev_err(&ioa_cfg->pdev->dev,
  852. "Host RCB failed with IOASC: 0x%08X\n", ioasc);
  853. ipr_send_hcam(ioa_cfg, IPR_HCAM_CDB_OP_CODE_CONFIG_CHANGE, hostrcb);
  854. } else {
  855. ipr_handle_config_change(ioa_cfg, hostrcb);
  856. }
  857. }
  858. /**
  859. * strip_and_pad_whitespace - Strip and pad trailing whitespace.
  860. * @i: index into buffer
  861. * @buf: string to modify
  862. *
  863. * This function will strip all trailing whitespace, pad the end
  864. * of the string with a single space, and NULL terminate the string.
  865. *
  866. * Return value:
  867. * new length of string
  868. **/
  869. static int strip_and_pad_whitespace(int i, char *buf)
  870. {
  871. while (i && buf[i] == ' ')
  872. i--;
  873. buf[i+1] = ' ';
  874. buf[i+2] = '\0';
  875. return i + 2;
  876. }
  877. /**
  878. * ipr_log_vpd_compact - Log the passed extended VPD compactly.
  879. * @prefix: string to print at start of printk
  880. * @hostrcb: hostrcb pointer
  881. * @vpd: vendor/product id/sn struct
  882. *
  883. * Return value:
  884. * none
  885. **/
  886. static void ipr_log_vpd_compact(char *prefix, struct ipr_hostrcb *hostrcb,
  887. struct ipr_vpd *vpd)
  888. {
  889. char buffer[IPR_VENDOR_ID_LEN + IPR_PROD_ID_LEN + IPR_SERIAL_NUM_LEN + 3];
  890. int i = 0;
  891. memcpy(buffer, vpd->vpids.vendor_id, IPR_VENDOR_ID_LEN);
  892. i = strip_and_pad_whitespace(IPR_VENDOR_ID_LEN - 1, buffer);
  893. memcpy(&buffer[i], vpd->vpids.product_id, IPR_PROD_ID_LEN);
  894. i = strip_and_pad_whitespace(i + IPR_PROD_ID_LEN - 1, buffer);
  895. memcpy(&buffer[i], vpd->sn, IPR_SERIAL_NUM_LEN);
  896. buffer[IPR_SERIAL_NUM_LEN + i] = '\0';
  897. ipr_hcam_err(hostrcb, "%s VPID/SN: %s\n", prefix, buffer);
  898. }
  899. /**
  900. * ipr_log_vpd - Log the passed VPD to the error log.
  901. * @vpd: vendor/product id/sn struct
  902. *
  903. * Return value:
  904. * none
  905. **/
  906. static void ipr_log_vpd(struct ipr_vpd *vpd)
  907. {
  908. char buffer[IPR_VENDOR_ID_LEN + IPR_PROD_ID_LEN
  909. + IPR_SERIAL_NUM_LEN];
  910. memcpy(buffer, vpd->vpids.vendor_id, IPR_VENDOR_ID_LEN);
  911. memcpy(buffer + IPR_VENDOR_ID_LEN, vpd->vpids.product_id,
  912. IPR_PROD_ID_LEN);
  913. buffer[IPR_VENDOR_ID_LEN + IPR_PROD_ID_LEN] = '\0';
  914. ipr_err("Vendor/Product ID: %s\n", buffer);
  915. memcpy(buffer, vpd->sn, IPR_SERIAL_NUM_LEN);
  916. buffer[IPR_SERIAL_NUM_LEN] = '\0';
  917. ipr_err(" Serial Number: %s\n", buffer);
  918. }
  919. /**
  920. * ipr_log_ext_vpd_compact - Log the passed extended VPD compactly.
  921. * @prefix: string to print at start of printk
  922. * @hostrcb: hostrcb pointer
  923. * @vpd: vendor/product id/sn/wwn struct
  924. *
  925. * Return value:
  926. * none
  927. **/
  928. static void ipr_log_ext_vpd_compact(char *prefix, struct ipr_hostrcb *hostrcb,
  929. struct ipr_ext_vpd *vpd)
  930. {
  931. ipr_log_vpd_compact(prefix, hostrcb, &vpd->vpd);
  932. ipr_hcam_err(hostrcb, "%s WWN: %08X%08X\n", prefix,
  933. be32_to_cpu(vpd->wwid[0]), be32_to_cpu(vpd->wwid[1]));
  934. }
  935. /**
  936. * ipr_log_ext_vpd - Log the passed extended VPD to the error log.
  937. * @vpd: vendor/product id/sn/wwn struct
  938. *
  939. * Return value:
  940. * none
  941. **/
  942. static void ipr_log_ext_vpd(struct ipr_ext_vpd *vpd)
  943. {
  944. ipr_log_vpd(&vpd->vpd);
  945. ipr_err(" WWN: %08X%08X\n", be32_to_cpu(vpd->wwid[0]),
  946. be32_to_cpu(vpd->wwid[1]));
  947. }
  948. /**
  949. * ipr_log_enhanced_cache_error - Log a cache error.
  950. * @ioa_cfg: ioa config struct
  951. * @hostrcb: hostrcb struct
  952. *
  953. * Return value:
  954. * none
  955. **/
  956. static void ipr_log_enhanced_cache_error(struct ipr_ioa_cfg *ioa_cfg,
  957. struct ipr_hostrcb *hostrcb)
  958. {
  959. struct ipr_hostrcb_type_12_error *error =
  960. &hostrcb->hcam.u.error.u.type_12_error;
  961. ipr_err("-----Current Configuration-----\n");
  962. ipr_err("Cache Directory Card Information:\n");
  963. ipr_log_ext_vpd(&error->ioa_vpd);
  964. ipr_err("Adapter Card Information:\n");
  965. ipr_log_ext_vpd(&error->cfc_vpd);
  966. ipr_err("-----Expected Configuration-----\n");
  967. ipr_err("Cache Directory Card Information:\n");
  968. ipr_log_ext_vpd(&error->ioa_last_attached_to_cfc_vpd);
  969. ipr_err("Adapter Card Information:\n");
  970. ipr_log_ext_vpd(&error->cfc_last_attached_to_ioa_vpd);
  971. ipr_err("Additional IOA Data: %08X %08X %08X\n",
  972. be32_to_cpu(error->ioa_data[0]),
  973. be32_to_cpu(error->ioa_data[1]),
  974. be32_to_cpu(error->ioa_data[2]));
  975. }
  976. /**
  977. * ipr_log_cache_error - Log a cache error.
  978. * @ioa_cfg: ioa config struct
  979. * @hostrcb: hostrcb struct
  980. *
  981. * Return value:
  982. * none
  983. **/
  984. static void ipr_log_cache_error(struct ipr_ioa_cfg *ioa_cfg,
  985. struct ipr_hostrcb *hostrcb)
  986. {
  987. struct ipr_hostrcb_type_02_error *error =
  988. &hostrcb->hcam.u.error.u.type_02_error;
  989. ipr_err("-----Current Configuration-----\n");
  990. ipr_err("Cache Directory Card Information:\n");
  991. ipr_log_vpd(&error->ioa_vpd);
  992. ipr_err("Adapter Card Information:\n");
  993. ipr_log_vpd(&error->cfc_vpd);
  994. ipr_err("-----Expected Configuration-----\n");
  995. ipr_err("Cache Directory Card Information:\n");
  996. ipr_log_vpd(&error->ioa_last_attached_to_cfc_vpd);
  997. ipr_err("Adapter Card Information:\n");
  998. ipr_log_vpd(&error->cfc_last_attached_to_ioa_vpd);
  999. ipr_err("Additional IOA Data: %08X %08X %08X\n",
  1000. be32_to_cpu(error->ioa_data[0]),
  1001. be32_to_cpu(error->ioa_data[1]),
  1002. be32_to_cpu(error->ioa_data[2]));
  1003. }
  1004. /**
  1005. * ipr_log_enhanced_config_error - Log a configuration error.
  1006. * @ioa_cfg: ioa config struct
  1007. * @hostrcb: hostrcb struct
  1008. *
  1009. * Return value:
  1010. * none
  1011. **/
  1012. static void ipr_log_enhanced_config_error(struct ipr_ioa_cfg *ioa_cfg,
  1013. struct ipr_hostrcb *hostrcb)
  1014. {
  1015. int errors_logged, i;
  1016. struct ipr_hostrcb_device_data_entry_enhanced *dev_entry;
  1017. struct ipr_hostrcb_type_13_error *error;
  1018. error = &hostrcb->hcam.u.error.u.type_13_error;
  1019. errors_logged = be32_to_cpu(error->errors_logged);
  1020. ipr_err("Device Errors Detected/Logged: %d/%d\n",
  1021. be32_to_cpu(error->errors_detected), errors_logged);
  1022. dev_entry = error->dev;
  1023. for (i = 0; i < errors_logged; i++, dev_entry++) {
  1024. ipr_err_separator;
  1025. ipr_phys_res_err(ioa_cfg, dev_entry->dev_res_addr, "Device %d", i + 1);
  1026. ipr_log_ext_vpd(&dev_entry->vpd);
  1027. ipr_err("-----New Device Information-----\n");
  1028. ipr_log_ext_vpd(&dev_entry->new_vpd);
  1029. ipr_err("Cache Directory Card Information:\n");
  1030. ipr_log_ext_vpd(&dev_entry->ioa_last_with_dev_vpd);
  1031. ipr_err("Adapter Card Information:\n");
  1032. ipr_log_ext_vpd(&dev_entry->cfc_last_with_dev_vpd);
  1033. }
  1034. }
  1035. /**
  1036. * ipr_log_config_error - Log a configuration error.
  1037. * @ioa_cfg: ioa config struct
  1038. * @hostrcb: hostrcb struct
  1039. *
  1040. * Return value:
  1041. * none
  1042. **/
  1043. static void ipr_log_config_error(struct ipr_ioa_cfg *ioa_cfg,
  1044. struct ipr_hostrcb *hostrcb)
  1045. {
  1046. int errors_logged, i;
  1047. struct ipr_hostrcb_device_data_entry *dev_entry;
  1048. struct ipr_hostrcb_type_03_error *error;
  1049. error = &hostrcb->hcam.u.error.u.type_03_error;
  1050. errors_logged = be32_to_cpu(error->errors_logged);
  1051. ipr_err("Device Errors Detected/Logged: %d/%d\n",
  1052. be32_to_cpu(error->errors_detected), errors_logged);
  1053. dev_entry = error->dev;
  1054. for (i = 0; i < errors_logged; i++, dev_entry++) {
  1055. ipr_err_separator;
  1056. ipr_phys_res_err(ioa_cfg, dev_entry->dev_res_addr, "Device %d", i + 1);
  1057. ipr_log_vpd(&dev_entry->vpd);
  1058. ipr_err("-----New Device Information-----\n");
  1059. ipr_log_vpd(&dev_entry->new_vpd);
  1060. ipr_err("Cache Directory Card Information:\n");
  1061. ipr_log_vpd(&dev_entry->ioa_last_with_dev_vpd);
  1062. ipr_err("Adapter Card Information:\n");
  1063. ipr_log_vpd(&dev_entry->cfc_last_with_dev_vpd);
  1064. ipr_err("Additional IOA Data: %08X %08X %08X %08X %08X\n",
  1065. be32_to_cpu(dev_entry->ioa_data[0]),
  1066. be32_to_cpu(dev_entry->ioa_data[1]),
  1067. be32_to_cpu(dev_entry->ioa_data[2]),
  1068. be32_to_cpu(dev_entry->ioa_data[3]),
  1069. be32_to_cpu(dev_entry->ioa_data[4]));
  1070. }
  1071. }
  1072. /**
  1073. * ipr_log_enhanced_array_error - Log an array configuration error.
  1074. * @ioa_cfg: ioa config struct
  1075. * @hostrcb: hostrcb struct
  1076. *
  1077. * Return value:
  1078. * none
  1079. **/
  1080. static void ipr_log_enhanced_array_error(struct ipr_ioa_cfg *ioa_cfg,
  1081. struct ipr_hostrcb *hostrcb)
  1082. {
  1083. int i, num_entries;
  1084. struct ipr_hostrcb_type_14_error *error;
  1085. struct ipr_hostrcb_array_data_entry_enhanced *array_entry;
  1086. const u8 zero_sn[IPR_SERIAL_NUM_LEN] = { [0 ... IPR_SERIAL_NUM_LEN-1] = '0' };
  1087. error = &hostrcb->hcam.u.error.u.type_14_error;
  1088. ipr_err_separator;
  1089. ipr_err("RAID %s Array Configuration: %d:%d:%d:%d\n",
  1090. error->protection_level,
  1091. ioa_cfg->host->host_no,
  1092. error->last_func_vset_res_addr.bus,
  1093. error->last_func_vset_res_addr.target,
  1094. error->last_func_vset_res_addr.lun);
  1095. ipr_err_separator;
  1096. array_entry = error->array_member;
  1097. num_entries = min_t(u32, be32_to_cpu(error->num_entries),
  1098. sizeof(error->array_member));
  1099. for (i = 0; i < num_entries; i++, array_entry++) {
  1100. if (!memcmp(array_entry->vpd.vpd.sn, zero_sn, IPR_SERIAL_NUM_LEN))
  1101. continue;
  1102. if (be32_to_cpu(error->exposed_mode_adn) == i)
  1103. ipr_err("Exposed Array Member %d:\n", i);
  1104. else
  1105. ipr_err("Array Member %d:\n", i);
  1106. ipr_log_ext_vpd(&array_entry->vpd);
  1107. ipr_phys_res_err(ioa_cfg, array_entry->dev_res_addr, "Current Location");
  1108. ipr_phys_res_err(ioa_cfg, array_entry->expected_dev_res_addr,
  1109. "Expected Location");
  1110. ipr_err_separator;
  1111. }
  1112. }
  1113. /**
  1114. * ipr_log_array_error - Log an array configuration error.
  1115. * @ioa_cfg: ioa config struct
  1116. * @hostrcb: hostrcb struct
  1117. *
  1118. * Return value:
  1119. * none
  1120. **/
  1121. static void ipr_log_array_error(struct ipr_ioa_cfg *ioa_cfg,
  1122. struct ipr_hostrcb *hostrcb)
  1123. {
  1124. int i;
  1125. struct ipr_hostrcb_type_04_error *error;
  1126. struct ipr_hostrcb_array_data_entry *array_entry;
  1127. const u8 zero_sn[IPR_SERIAL_NUM_LEN] = { [0 ... IPR_SERIAL_NUM_LEN-1] = '0' };
  1128. error = &hostrcb->hcam.u.error.u.type_04_error;
  1129. ipr_err_separator;
  1130. ipr_err("RAID %s Array Configuration: %d:%d:%d:%d\n",
  1131. error->protection_level,
  1132. ioa_cfg->host->host_no,
  1133. error->last_func_vset_res_addr.bus,
  1134. error->last_func_vset_res_addr.target,
  1135. error->last_func_vset_res_addr.lun);
  1136. ipr_err_separator;
  1137. array_entry = error->array_member;
  1138. for (i = 0; i < 18; i++) {
  1139. if (!memcmp(array_entry->vpd.sn, zero_sn, IPR_SERIAL_NUM_LEN))
  1140. continue;
  1141. if (be32_to_cpu(error->exposed_mode_adn) == i)
  1142. ipr_err("Exposed Array Member %d:\n", i);
  1143. else
  1144. ipr_err("Array Member %d:\n", i);
  1145. ipr_log_vpd(&array_entry->vpd);
  1146. ipr_phys_res_err(ioa_cfg, array_entry->dev_res_addr, "Current Location");
  1147. ipr_phys_res_err(ioa_cfg, array_entry->expected_dev_res_addr,
  1148. "Expected Location");
  1149. ipr_err_separator;
  1150. if (i == 9)
  1151. array_entry = error->array_member2;
  1152. else
  1153. array_entry++;
  1154. }
  1155. }
  1156. /**
  1157. * ipr_log_hex_data - Log additional hex IOA error data.
  1158. * @ioa_cfg: ioa config struct
  1159. * @data: IOA error data
  1160. * @len: data length
  1161. *
  1162. * Return value:
  1163. * none
  1164. **/
  1165. static void ipr_log_hex_data(struct ipr_ioa_cfg *ioa_cfg, u32 *data, int len)
  1166. {
  1167. int i;
  1168. if (len == 0)
  1169. return;
  1170. if (ioa_cfg->log_level <= IPR_DEFAULT_LOG_LEVEL)
  1171. len = min_t(int, len, IPR_DEFAULT_MAX_ERROR_DUMP);
  1172. for (i = 0; i < len / 4; i += 4) {
  1173. ipr_err("%08X: %08X %08X %08X %08X\n", i*4,
  1174. be32_to_cpu(data[i]),
  1175. be32_to_cpu(data[i+1]),
  1176. be32_to_cpu(data[i+2]),
  1177. be32_to_cpu(data[i+3]));
  1178. }
  1179. }
  1180. /**
  1181. * ipr_log_enhanced_dual_ioa_error - Log an enhanced dual adapter error.
  1182. * @ioa_cfg: ioa config struct
  1183. * @hostrcb: hostrcb struct
  1184. *
  1185. * Return value:
  1186. * none
  1187. **/
  1188. static void ipr_log_enhanced_dual_ioa_error(struct ipr_ioa_cfg *ioa_cfg,
  1189. struct ipr_hostrcb *hostrcb)
  1190. {
  1191. struct ipr_hostrcb_type_17_error *error;
  1192. error = &hostrcb->hcam.u.error.u.type_17_error;
  1193. error->failure_reason[sizeof(error->failure_reason) - 1] = '\0';
  1194. strstrip(error->failure_reason);
  1195. ipr_hcam_err(hostrcb, "%s [PRC: %08X]\n", error->failure_reason,
  1196. be32_to_cpu(hostrcb->hcam.u.error.prc));
  1197. ipr_log_ext_vpd_compact("Remote IOA", hostrcb, &error->vpd);
  1198. ipr_log_hex_data(ioa_cfg, error->data,
  1199. be32_to_cpu(hostrcb->hcam.length) -
  1200. (offsetof(struct ipr_hostrcb_error, u) +
  1201. offsetof(struct ipr_hostrcb_type_17_error, data)));
  1202. }
  1203. /**
  1204. * ipr_log_dual_ioa_error - Log a dual adapter error.
  1205. * @ioa_cfg: ioa config struct
  1206. * @hostrcb: hostrcb struct
  1207. *
  1208. * Return value:
  1209. * none
  1210. **/
  1211. static void ipr_log_dual_ioa_error(struct ipr_ioa_cfg *ioa_cfg,
  1212. struct ipr_hostrcb *hostrcb)
  1213. {
  1214. struct ipr_hostrcb_type_07_error *error;
  1215. error = &hostrcb->hcam.u.error.u.type_07_error;
  1216. error->failure_reason[sizeof(error->failure_reason) - 1] = '\0';
  1217. strstrip(error->failure_reason);
  1218. ipr_hcam_err(hostrcb, "%s [PRC: %08X]\n", error->failure_reason,
  1219. be32_to_cpu(hostrcb->hcam.u.error.prc));
  1220. ipr_log_vpd_compact("Remote IOA", hostrcb, &error->vpd);
  1221. ipr_log_hex_data(ioa_cfg, error->data,
  1222. be32_to_cpu(hostrcb->hcam.length) -
  1223. (offsetof(struct ipr_hostrcb_error, u) +
  1224. offsetof(struct ipr_hostrcb_type_07_error, data)));
  1225. }
  1226. static const struct {
  1227. u8 active;
  1228. char *desc;
  1229. } path_active_desc[] = {
  1230. { IPR_PATH_NO_INFO, "Path" },
  1231. { IPR_PATH_ACTIVE, "Active path" },
  1232. { IPR_PATH_NOT_ACTIVE, "Inactive path" }
  1233. };
  1234. static const struct {
  1235. u8 state;
  1236. char *desc;
  1237. } path_state_desc[] = {
  1238. { IPR_PATH_STATE_NO_INFO, "has no path state information available" },
  1239. { IPR_PATH_HEALTHY, "is healthy" },
  1240. { IPR_PATH_DEGRADED, "is degraded" },
  1241. { IPR_PATH_FAILED, "is failed" }
  1242. };
  1243. /**
  1244. * ipr_log_fabric_path - Log a fabric path error
  1245. * @hostrcb: hostrcb struct
  1246. * @fabric: fabric descriptor
  1247. *
  1248. * Return value:
  1249. * none
  1250. **/
  1251. static void ipr_log_fabric_path(struct ipr_hostrcb *hostrcb,
  1252. struct ipr_hostrcb_fabric_desc *fabric)
  1253. {
  1254. int i, j;
  1255. u8 path_state = fabric->path_state;
  1256. u8 active = path_state & IPR_PATH_ACTIVE_MASK;
  1257. u8 state = path_state & IPR_PATH_STATE_MASK;
  1258. for (i = 0; i < ARRAY_SIZE(path_active_desc); i++) {
  1259. if (path_active_desc[i].active != active)
  1260. continue;
  1261. for (j = 0; j < ARRAY_SIZE(path_state_desc); j++) {
  1262. if (path_state_desc[j].state != state)
  1263. continue;
  1264. if (fabric->cascaded_expander == 0xff && fabric->phy == 0xff) {
  1265. ipr_hcam_err(hostrcb, "%s %s: IOA Port=%d\n",
  1266. path_active_desc[i].desc, path_state_desc[j].desc,
  1267. fabric->ioa_port);
  1268. } else if (fabric->cascaded_expander == 0xff) {
  1269. ipr_hcam_err(hostrcb, "%s %s: IOA Port=%d, Phy=%d\n",
  1270. path_active_desc[i].desc, path_state_desc[j].desc,
  1271. fabric->ioa_port, fabric->phy);
  1272. } else if (fabric->phy == 0xff) {
  1273. ipr_hcam_err(hostrcb, "%s %s: IOA Port=%d, Cascade=%d\n",
  1274. path_active_desc[i].desc, path_state_desc[j].desc,
  1275. fabric->ioa_port, fabric->cascaded_expander);
  1276. } else {
  1277. ipr_hcam_err(hostrcb, "%s %s: IOA Port=%d, Cascade=%d, Phy=%d\n",
  1278. path_active_desc[i].desc, path_state_desc[j].desc,
  1279. fabric->ioa_port, fabric->cascaded_expander, fabric->phy);
  1280. }
  1281. return;
  1282. }
  1283. }
  1284. ipr_err("Path state=%02X IOA Port=%d Cascade=%d Phy=%d\n", path_state,
  1285. fabric->ioa_port, fabric->cascaded_expander, fabric->phy);
  1286. }
  1287. static const struct {
  1288. u8 type;
  1289. char *desc;
  1290. } path_type_desc[] = {
  1291. { IPR_PATH_CFG_IOA_PORT, "IOA port" },
  1292. { IPR_PATH_CFG_EXP_PORT, "Expander port" },
  1293. { IPR_PATH_CFG_DEVICE_PORT, "Device port" },
  1294. { IPR_PATH_CFG_DEVICE_LUN, "Device LUN" }
  1295. };
  1296. static const struct {
  1297. u8 status;
  1298. char *desc;
  1299. } path_status_desc[] = {
  1300. { IPR_PATH_CFG_NO_PROB, "Functional" },
  1301. { IPR_PATH_CFG_DEGRADED, "Degraded" },
  1302. { IPR_PATH_CFG_FAILED, "Failed" },
  1303. { IPR_PATH_CFG_SUSPECT, "Suspect" },
  1304. { IPR_PATH_NOT_DETECTED, "Missing" },
  1305. { IPR_PATH_INCORRECT_CONN, "Incorrectly connected" }
  1306. };
  1307. static const char *link_rate[] = {
  1308. "unknown",
  1309. "disabled",
  1310. "phy reset problem",
  1311. "spinup hold",
  1312. "port selector",
  1313. "unknown",
  1314. "unknown",
  1315. "unknown",
  1316. "1.5Gbps",
  1317. "3.0Gbps",
  1318. "unknown",
  1319. "unknown",
  1320. "unknown",
  1321. "unknown",
  1322. "unknown",
  1323. "unknown"
  1324. };
  1325. /**
  1326. * ipr_log_path_elem - Log a fabric path element.
  1327. * @hostrcb: hostrcb struct
  1328. * @cfg: fabric path element struct
  1329. *
  1330. * Return value:
  1331. * none
  1332. **/
  1333. static void ipr_log_path_elem(struct ipr_hostrcb *hostrcb,
  1334. struct ipr_hostrcb_config_element *cfg)
  1335. {
  1336. int i, j;
  1337. u8 type = cfg->type_status & IPR_PATH_CFG_TYPE_MASK;
  1338. u8 status = cfg->type_status & IPR_PATH_CFG_STATUS_MASK;
  1339. if (type == IPR_PATH_CFG_NOT_EXIST)
  1340. return;
  1341. for (i = 0; i < ARRAY_SIZE(path_type_desc); i++) {
  1342. if (path_type_desc[i].type != type)
  1343. continue;
  1344. for (j = 0; j < ARRAY_SIZE(path_status_desc); j++) {
  1345. if (path_status_desc[j].status != status)
  1346. continue;
  1347. if (type == IPR_PATH_CFG_IOA_PORT) {
  1348. ipr_hcam_err(hostrcb, "%s %s: Phy=%d, Link rate=%s, WWN=%08X%08X\n",
  1349. path_status_desc[j].desc, path_type_desc[i].desc,
  1350. cfg->phy, link_rate[cfg->link_rate & IPR_PHY_LINK_RATE_MASK],
  1351. be32_to_cpu(cfg->wwid[0]), be32_to_cpu(cfg->wwid[1]));
  1352. } else {
  1353. if (cfg->cascaded_expander == 0xff && cfg->phy == 0xff) {
  1354. ipr_hcam_err(hostrcb, "%s %s: Link rate=%s, WWN=%08X%08X\n",
  1355. path_status_desc[j].desc, path_type_desc[i].desc,
  1356. link_rate[cfg->link_rate & IPR_PHY_LINK_RATE_MASK],
  1357. be32_to_cpu(cfg->wwid[0]), be32_to_cpu(cfg->wwid[1]));
  1358. } else if (cfg->cascaded_expander == 0xff) {
  1359. ipr_hcam_err(hostrcb, "%s %s: Phy=%d, Link rate=%s, "
  1360. "WWN=%08X%08X\n", path_status_desc[j].desc,
  1361. path_type_desc[i].desc, cfg->phy,
  1362. link_rate[cfg->link_rate & IPR_PHY_LINK_RATE_MASK],
  1363. be32_to_cpu(cfg->wwid[0]), be32_to_cpu(cfg->wwid[1]));
  1364. } else if (cfg->phy == 0xff) {
  1365. ipr_hcam_err(hostrcb, "%s %s: Cascade=%d, Link rate=%s, "
  1366. "WWN=%08X%08X\n", path_status_desc[j].desc,
  1367. path_type_desc[i].desc, cfg->cascaded_expander,
  1368. link_rate[cfg->link_rate & IPR_PHY_LINK_RATE_MASK],
  1369. be32_to_cpu(cfg->wwid[0]), be32_to_cpu(cfg->wwid[1]));
  1370. } else {
  1371. ipr_hcam_err(hostrcb, "%s %s: Cascade=%d, Phy=%d, Link rate=%s "
  1372. "WWN=%08X%08X\n", path_status_desc[j].desc,
  1373. path_type_desc[i].desc, cfg->cascaded_expander, cfg->phy,
  1374. link_rate[cfg->link_rate & IPR_PHY_LINK_RATE_MASK],
  1375. be32_to_cpu(cfg->wwid[0]), be32_to_cpu(cfg->wwid[1]));
  1376. }
  1377. }
  1378. return;
  1379. }
  1380. }
  1381. ipr_hcam_err(hostrcb, "Path element=%02X: Cascade=%d Phy=%d Link rate=%s "
  1382. "WWN=%08X%08X\n", cfg->type_status, cfg->cascaded_expander, cfg->phy,
  1383. link_rate[cfg->link_rate & IPR_PHY_LINK_RATE_MASK],
  1384. be32_to_cpu(cfg->wwid[0]), be32_to_cpu(cfg->wwid[1]));
  1385. }
  1386. /**
  1387. * ipr_log_fabric_error - Log a fabric error.
  1388. * @ioa_cfg: ioa config struct
  1389. * @hostrcb: hostrcb struct
  1390. *
  1391. * Return value:
  1392. * none
  1393. **/
  1394. static void ipr_log_fabric_error(struct ipr_ioa_cfg *ioa_cfg,
  1395. struct ipr_hostrcb *hostrcb)
  1396. {
  1397. struct ipr_hostrcb_type_20_error *error;
  1398. struct ipr_hostrcb_fabric_desc *fabric;
  1399. struct ipr_hostrcb_config_element *cfg;
  1400. int i, add_len;
  1401. error = &hostrcb->hcam.u.error.u.type_20_error;
  1402. error->failure_reason[sizeof(error->failure_reason) - 1] = '\0';
  1403. ipr_hcam_err(hostrcb, "%s\n", error->failure_reason);
  1404. add_len = be32_to_cpu(hostrcb->hcam.length) -
  1405. (offsetof(struct ipr_hostrcb_error, u) +
  1406. offsetof(struct ipr_hostrcb_type_20_error, desc));
  1407. for (i = 0, fabric = error->desc; i < error->num_entries; i++) {
  1408. ipr_log_fabric_path(hostrcb, fabric);
  1409. for_each_fabric_cfg(fabric, cfg)
  1410. ipr_log_path_elem(hostrcb, cfg);
  1411. add_len -= be16_to_cpu(fabric->length);
  1412. fabric = (struct ipr_hostrcb_fabric_desc *)
  1413. ((unsigned long)fabric + be16_to_cpu(fabric->length));
  1414. }
  1415. ipr_log_hex_data(ioa_cfg, (u32 *)fabric, add_len);
  1416. }
  1417. /**
  1418. * ipr_log_generic_error - Log an adapter error.
  1419. * @ioa_cfg: ioa config struct
  1420. * @hostrcb: hostrcb struct
  1421. *
  1422. * Return value:
  1423. * none
  1424. **/
  1425. static void ipr_log_generic_error(struct ipr_ioa_cfg *ioa_cfg,
  1426. struct ipr_hostrcb *hostrcb)
  1427. {
  1428. ipr_log_hex_data(ioa_cfg, hostrcb->hcam.u.raw.data,
  1429. be32_to_cpu(hostrcb->hcam.length));
  1430. }
  1431. /**
  1432. * ipr_get_error - Find the specfied IOASC in the ipr_error_table.
  1433. * @ioasc: IOASC
  1434. *
  1435. * This function will return the index of into the ipr_error_table
  1436. * for the specified IOASC. If the IOASC is not in the table,
  1437. * 0 will be returned, which points to the entry used for unknown errors.
  1438. *
  1439. * Return value:
  1440. * index into the ipr_error_table
  1441. **/
  1442. static u32 ipr_get_error(u32 ioasc)
  1443. {
  1444. int i;
  1445. for (i = 0; i < ARRAY_SIZE(ipr_error_table); i++)
  1446. if (ipr_error_table[i].ioasc == (ioasc & IPR_IOASC_IOASC_MASK))
  1447. return i;
  1448. return 0;
  1449. }
  1450. /**
  1451. * ipr_handle_log_data - Log an adapter error.
  1452. * @ioa_cfg: ioa config struct
  1453. * @hostrcb: hostrcb struct
  1454. *
  1455. * This function logs an adapter error to the system.
  1456. *
  1457. * Return value:
  1458. * none
  1459. **/
  1460. static void ipr_handle_log_data(struct ipr_ioa_cfg *ioa_cfg,
  1461. struct ipr_hostrcb *hostrcb)
  1462. {
  1463. u32 ioasc;
  1464. int error_index;
  1465. if (hostrcb->hcam.notify_type != IPR_HOST_RCB_NOTIF_TYPE_ERROR_LOG_ENTRY)
  1466. return;
  1467. if (hostrcb->hcam.notifications_lost == IPR_HOST_RCB_NOTIFICATIONS_LOST)
  1468. dev_err(&ioa_cfg->pdev->dev, "Error notifications lost\n");
  1469. ioasc = be32_to_cpu(hostrcb->hcam.u.error.failing_dev_ioasc);
  1470. if (ioasc == IPR_IOASC_BUS_WAS_RESET ||
  1471. ioasc == IPR_IOASC_BUS_WAS_RESET_BY_OTHER) {
  1472. /* Tell the midlayer we had a bus reset so it will handle the UA properly */
  1473. scsi_report_bus_reset(ioa_cfg->host,
  1474. hostrcb->hcam.u.error.failing_dev_res_addr.bus);
  1475. }
  1476. error_index = ipr_get_error(ioasc);
  1477. if (!ipr_error_table[error_index].log_hcam)
  1478. return;
  1479. ipr_hcam_err(hostrcb, "%s\n", ipr_error_table[error_index].error);
  1480. /* Set indication we have logged an error */
  1481. ioa_cfg->errors_logged++;
  1482. if (ioa_cfg->log_level < ipr_error_table[error_index].log_hcam)
  1483. return;
  1484. if (be32_to_cpu(hostrcb->hcam.length) > sizeof(hostrcb->hcam.u.raw))
  1485. hostrcb->hcam.length = cpu_to_be32(sizeof(hostrcb->hcam.u.raw));
  1486. switch (hostrcb->hcam.overlay_id) {
  1487. case IPR_HOST_RCB_OVERLAY_ID_2:
  1488. ipr_log_cache_error(ioa_cfg, hostrcb);
  1489. break;
  1490. case IPR_HOST_RCB_OVERLAY_ID_3:
  1491. ipr_log_config_error(ioa_cfg, hostrcb);
  1492. break;
  1493. case IPR_HOST_RCB_OVERLAY_ID_4:
  1494. case IPR_HOST_RCB_OVERLAY_ID_6:
  1495. ipr_log_array_error(ioa_cfg, hostrcb);
  1496. break;
  1497. case IPR_HOST_RCB_OVERLAY_ID_7:
  1498. ipr_log_dual_ioa_error(ioa_cfg, hostrcb);
  1499. break;
  1500. case IPR_HOST_RCB_OVERLAY_ID_12:
  1501. ipr_log_enhanced_cache_error(ioa_cfg, hostrcb);
  1502. break;
  1503. case IPR_HOST_RCB_OVERLAY_ID_13:
  1504. ipr_log_enhanced_config_error(ioa_cfg, hostrcb);
  1505. break;
  1506. case IPR_HOST_RCB_OVERLAY_ID_14:
  1507. case IPR_HOST_RCB_OVERLAY_ID_16:
  1508. ipr_log_enhanced_array_error(ioa_cfg, hostrcb);
  1509. break;
  1510. case IPR_HOST_RCB_OVERLAY_ID_17:
  1511. ipr_log_enhanced_dual_ioa_error(ioa_cfg, hostrcb);
  1512. break;
  1513. case IPR_HOST_RCB_OVERLAY_ID_20:
  1514. ipr_log_fabric_error(ioa_cfg, hostrcb);
  1515. break;
  1516. case IPR_HOST_RCB_OVERLAY_ID_1:
  1517. case IPR_HOST_RCB_OVERLAY_ID_DEFAULT:
  1518. default:
  1519. ipr_log_generic_error(ioa_cfg, hostrcb);
  1520. break;
  1521. }
  1522. }
  1523. /**
  1524. * ipr_process_error - Op done function for an adapter error log.
  1525. * @ipr_cmd: ipr command struct
  1526. *
  1527. * This function is the op done function for an error log host
  1528. * controlled async from the adapter. It will log the error and
  1529. * send the HCAM back to the adapter.
  1530. *
  1531. * Return value:
  1532. * none
  1533. **/
  1534. static void ipr_process_error(struct ipr_cmnd *ipr_cmd)
  1535. {
  1536. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  1537. struct ipr_hostrcb *hostrcb = ipr_cmd->u.hostrcb;
  1538. u32 ioasc = be32_to_cpu(ipr_cmd->ioasa.ioasc);
  1539. u32 fd_ioasc = be32_to_cpu(hostrcb->hcam.u.error.failing_dev_ioasc);
  1540. list_del(&hostrcb->queue);
  1541. list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
  1542. if (!ioasc) {
  1543. ipr_handle_log_data(ioa_cfg, hostrcb);
  1544. if (fd_ioasc == IPR_IOASC_NR_IOA_RESET_REQUIRED)
  1545. ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_ABBREV);
  1546. } else if (ioasc != IPR_IOASC_IOA_WAS_RESET) {
  1547. dev_err(&ioa_cfg->pdev->dev,
  1548. "Host RCB failed with IOASC: 0x%08X\n", ioasc);
  1549. }
  1550. ipr_send_hcam(ioa_cfg, IPR_HCAM_CDB_OP_CODE_LOG_DATA, hostrcb);
  1551. }
  1552. /**
  1553. * ipr_timeout - An internally generated op has timed out.
  1554. * @ipr_cmd: ipr command struct
  1555. *
  1556. * This function blocks host requests and initiates an
  1557. * adapter reset.
  1558. *
  1559. * Return value:
  1560. * none
  1561. **/
  1562. static void ipr_timeout(struct ipr_cmnd *ipr_cmd)
  1563. {
  1564. unsigned long lock_flags = 0;
  1565. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  1566. ENTER;
  1567. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  1568. ioa_cfg->errors_logged++;
  1569. dev_err(&ioa_cfg->pdev->dev,
  1570. "Adapter being reset due to command timeout.\n");
  1571. if (WAIT_FOR_DUMP == ioa_cfg->sdt_state)
  1572. ioa_cfg->sdt_state = GET_DUMP;
  1573. if (!ioa_cfg->in_reset_reload || ioa_cfg->reset_cmd == ipr_cmd)
  1574. ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
  1575. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  1576. LEAVE;
  1577. }
  1578. /**
  1579. * ipr_oper_timeout - Adapter timed out transitioning to operational
  1580. * @ipr_cmd: ipr command struct
  1581. *
  1582. * This function blocks host requests and initiates an
  1583. * adapter reset.
  1584. *
  1585. * Return value:
  1586. * none
  1587. **/
  1588. static void ipr_oper_timeout(struct ipr_cmnd *ipr_cmd)
  1589. {
  1590. unsigned long lock_flags = 0;
  1591. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  1592. ENTER;
  1593. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  1594. ioa_cfg->errors_logged++;
  1595. dev_err(&ioa_cfg->pdev->dev,
  1596. "Adapter timed out transitioning to operational.\n");
  1597. if (WAIT_FOR_DUMP == ioa_cfg->sdt_state)
  1598. ioa_cfg->sdt_state = GET_DUMP;
  1599. if (!ioa_cfg->in_reset_reload || ioa_cfg->reset_cmd == ipr_cmd) {
  1600. if (ipr_fastfail)
  1601. ioa_cfg->reset_retries += IPR_NUM_RESET_RELOAD_RETRIES;
  1602. ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
  1603. }
  1604. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  1605. LEAVE;
  1606. }
  1607. /**
  1608. * ipr_reset_reload - Reset/Reload the IOA
  1609. * @ioa_cfg: ioa config struct
  1610. * @shutdown_type: shutdown type
  1611. *
  1612. * This function resets the adapter and re-initializes it.
  1613. * This function assumes that all new host commands have been stopped.
  1614. * Return value:
  1615. * SUCCESS / FAILED
  1616. **/
  1617. static int ipr_reset_reload(struct ipr_ioa_cfg *ioa_cfg,
  1618. enum ipr_shutdown_type shutdown_type)
  1619. {
  1620. if (!ioa_cfg->in_reset_reload)
  1621. ipr_initiate_ioa_reset(ioa_cfg, shutdown_type);
  1622. spin_unlock_irq(ioa_cfg->host->host_lock);
  1623. wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
  1624. spin_lock_irq(ioa_cfg->host->host_lock);
  1625. /* If we got hit with a host reset while we were already resetting
  1626. the adapter for some reason, and the reset failed. */
  1627. if (ioa_cfg->ioa_is_dead) {
  1628. ipr_trace;
  1629. return FAILED;
  1630. }
  1631. return SUCCESS;
  1632. }
  1633. /**
  1634. * ipr_find_ses_entry - Find matching SES in SES table
  1635. * @res: resource entry struct of SES
  1636. *
  1637. * Return value:
  1638. * pointer to SES table entry / NULL on failure
  1639. **/
  1640. static const struct ipr_ses_table_entry *
  1641. ipr_find_ses_entry(struct ipr_resource_entry *res)
  1642. {
  1643. int i, j, matches;
  1644. const struct ipr_ses_table_entry *ste = ipr_ses_table;
  1645. for (i = 0; i < ARRAY_SIZE(ipr_ses_table); i++, ste++) {
  1646. for (j = 0, matches = 0; j < IPR_PROD_ID_LEN; j++) {
  1647. if (ste->compare_product_id_byte[j] == 'X') {
  1648. if (res->cfgte.std_inq_data.vpids.product_id[j] == ste->product_id[j])
  1649. matches++;
  1650. else
  1651. break;
  1652. } else
  1653. matches++;
  1654. }
  1655. if (matches == IPR_PROD_ID_LEN)
  1656. return ste;
  1657. }
  1658. return NULL;
  1659. }
  1660. /**
  1661. * ipr_get_max_scsi_speed - Determine max SCSI speed for a given bus
  1662. * @ioa_cfg: ioa config struct
  1663. * @bus: SCSI bus
  1664. * @bus_width: bus width
  1665. *
  1666. * Return value:
  1667. * SCSI bus speed in units of 100KHz, 1600 is 160 MHz
  1668. * For a 2-byte wide SCSI bus, the maximum transfer speed is
  1669. * twice the maximum transfer rate (e.g. for a wide enabled bus,
  1670. * max 160MHz = max 320MB/sec).
  1671. **/
  1672. static u32 ipr_get_max_scsi_speed(struct ipr_ioa_cfg *ioa_cfg, u8 bus, u8 bus_width)
  1673. {
  1674. struct ipr_resource_entry *res;
  1675. const struct ipr_ses_table_entry *ste;
  1676. u32 max_xfer_rate = IPR_MAX_SCSI_RATE(bus_width);
  1677. /* Loop through each config table entry in the config table buffer */
  1678. list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
  1679. if (!(IPR_IS_SES_DEVICE(res->cfgte.std_inq_data)))
  1680. continue;
  1681. if (bus != res->cfgte.res_addr.bus)
  1682. continue;
  1683. if (!(ste = ipr_find_ses_entry(res)))
  1684. continue;
  1685. max_xfer_rate = (ste->max_bus_speed_limit * 10) / (bus_width / 8);
  1686. }
  1687. return max_xfer_rate;
  1688. }
  1689. /**
  1690. * ipr_wait_iodbg_ack - Wait for an IODEBUG ACK from the IOA
  1691. * @ioa_cfg: ioa config struct
  1692. * @max_delay: max delay in micro-seconds to wait
  1693. *
  1694. * Waits for an IODEBUG ACK from the IOA, doing busy looping.
  1695. *
  1696. * Return value:
  1697. * 0 on success / other on failure
  1698. **/
  1699. static int ipr_wait_iodbg_ack(struct ipr_ioa_cfg *ioa_cfg, int max_delay)
  1700. {
  1701. volatile u32 pcii_reg;
  1702. int delay = 1;
  1703. /* Read interrupt reg until IOA signals IO Debug Acknowledge */
  1704. while (delay < max_delay) {
  1705. pcii_reg = readl(ioa_cfg->regs.sense_interrupt_reg);
  1706. if (pcii_reg & IPR_PCII_IO_DEBUG_ACKNOWLEDGE)
  1707. return 0;
  1708. /* udelay cannot be used if delay is more than a few milliseconds */
  1709. if ((delay / 1000) > MAX_UDELAY_MS)
  1710. mdelay(delay / 1000);
  1711. else
  1712. udelay(delay);
  1713. delay += delay;
  1714. }
  1715. return -EIO;
  1716. }
  1717. /**
  1718. * ipr_get_ldump_data_section - Dump IOA memory
  1719. * @ioa_cfg: ioa config struct
  1720. * @start_addr: adapter address to dump
  1721. * @dest: destination kernel buffer
  1722. * @length_in_words: length to dump in 4 byte words
  1723. *
  1724. * Return value:
  1725. * 0 on success / -EIO on failure
  1726. **/
  1727. static int ipr_get_ldump_data_section(struct ipr_ioa_cfg *ioa_cfg,
  1728. u32 start_addr,
  1729. __be32 *dest, u32 length_in_words)
  1730. {
  1731. volatile u32 temp_pcii_reg;
  1732. int i, delay = 0;
  1733. /* Write IOA interrupt reg starting LDUMP state */
  1734. writel((IPR_UPROCI_RESET_ALERT | IPR_UPROCI_IO_DEBUG_ALERT),
  1735. ioa_cfg->regs.set_uproc_interrupt_reg);
  1736. /* Wait for IO debug acknowledge */
  1737. if (ipr_wait_iodbg_ack(ioa_cfg,
  1738. IPR_LDUMP_MAX_LONG_ACK_DELAY_IN_USEC)) {
  1739. dev_err(&ioa_cfg->pdev->dev,
  1740. "IOA dump long data transfer timeout\n");
  1741. return -EIO;
  1742. }
  1743. /* Signal LDUMP interlocked - clear IO debug ack */
  1744. writel(IPR_PCII_IO_DEBUG_ACKNOWLEDGE,
  1745. ioa_cfg->regs.clr_interrupt_reg);
  1746. /* Write Mailbox with starting address */
  1747. writel(start_addr, ioa_cfg->ioa_mailbox);
  1748. /* Signal address valid - clear IOA Reset alert */
  1749. writel(IPR_UPROCI_RESET_ALERT,
  1750. ioa_cfg->regs.clr_uproc_interrupt_reg);
  1751. for (i = 0; i < length_in_words; i++) {
  1752. /* Wait for IO debug acknowledge */
  1753. if (ipr_wait_iodbg_ack(ioa_cfg,
  1754. IPR_LDUMP_MAX_SHORT_ACK_DELAY_IN_USEC)) {
  1755. dev_err(&ioa_cfg->pdev->dev,
  1756. "IOA dump short data transfer timeout\n");
  1757. return -EIO;
  1758. }
  1759. /* Read data from mailbox and increment destination pointer */
  1760. *dest = cpu_to_be32(readl(ioa_cfg->ioa_mailbox));
  1761. dest++;
  1762. /* For all but the last word of data, signal data received */
  1763. if (i < (length_in_words - 1)) {
  1764. /* Signal dump data received - Clear IO debug Ack */
  1765. writel(IPR_PCII_IO_DEBUG_ACKNOWLEDGE,
  1766. ioa_cfg->regs.clr_interrupt_reg);
  1767. }
  1768. }
  1769. /* Signal end of block transfer. Set reset alert then clear IO debug ack */
  1770. writel(IPR_UPROCI_RESET_ALERT,
  1771. ioa_cfg->regs.set_uproc_interrupt_reg);
  1772. writel(IPR_UPROCI_IO_DEBUG_ALERT,
  1773. ioa_cfg->regs.clr_uproc_interrupt_reg);
  1774. /* Signal dump data received - Clear IO debug Ack */
  1775. writel(IPR_PCII_IO_DEBUG_ACKNOWLEDGE,
  1776. ioa_cfg->regs.clr_interrupt_reg);
  1777. /* Wait for IOA to signal LDUMP exit - IOA reset alert will be cleared */
  1778. while (delay < IPR_LDUMP_MAX_SHORT_ACK_DELAY_IN_USEC) {
  1779. temp_pcii_reg =
  1780. readl(ioa_cfg->regs.sense_uproc_interrupt_reg);
  1781. if (!(temp_pcii_reg & IPR_UPROCI_RESET_ALERT))
  1782. return 0;
  1783. udelay(10);
  1784. delay += 10;
  1785. }
  1786. return 0;
  1787. }
  1788. #ifdef CONFIG_SCSI_IPR_DUMP
  1789. /**
  1790. * ipr_sdt_copy - Copy Smart Dump Table to kernel buffer
  1791. * @ioa_cfg: ioa config struct
  1792. * @pci_address: adapter address
  1793. * @length: length of data to copy
  1794. *
  1795. * Copy data from PCI adapter to kernel buffer.
  1796. * Note: length MUST be a 4 byte multiple
  1797. * Return value:
  1798. * 0 on success / other on failure
  1799. **/
  1800. static int ipr_sdt_copy(struct ipr_ioa_cfg *ioa_cfg,
  1801. unsigned long pci_address, u32 length)
  1802. {
  1803. int bytes_copied = 0;
  1804. int cur_len, rc, rem_len, rem_page_len;
  1805. __be32 *page;
  1806. unsigned long lock_flags = 0;
  1807. struct ipr_ioa_dump *ioa_dump = &ioa_cfg->dump->ioa_dump;
  1808. while (bytes_copied < length &&
  1809. (ioa_dump->hdr.len + bytes_copied) < IPR_MAX_IOA_DUMP_SIZE) {
  1810. if (ioa_dump->page_offset >= PAGE_SIZE ||
  1811. ioa_dump->page_offset == 0) {
  1812. page = (__be32 *)__get_free_page(GFP_ATOMIC);
  1813. if (!page) {
  1814. ipr_trace;
  1815. return bytes_copied;
  1816. }
  1817. ioa_dump->page_offset = 0;
  1818. ioa_dump->ioa_data[ioa_dump->next_page_index] = page;
  1819. ioa_dump->next_page_index++;
  1820. } else
  1821. page = ioa_dump->ioa_data[ioa_dump->next_page_index - 1];
  1822. rem_len = length - bytes_copied;
  1823. rem_page_len = PAGE_SIZE - ioa_dump->page_offset;
  1824. cur_len = min(rem_len, rem_page_len);
  1825. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  1826. if (ioa_cfg->sdt_state == ABORT_DUMP) {
  1827. rc = -EIO;
  1828. } else {
  1829. rc = ipr_get_ldump_data_section(ioa_cfg,
  1830. pci_address + bytes_copied,
  1831. &page[ioa_dump->page_offset / 4],
  1832. (cur_len / sizeof(u32)));
  1833. }
  1834. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  1835. if (!rc) {
  1836. ioa_dump->page_offset += cur_len;
  1837. bytes_copied += cur_len;
  1838. } else {
  1839. ipr_trace;
  1840. break;
  1841. }
  1842. schedule();
  1843. }
  1844. return bytes_copied;
  1845. }
  1846. /**
  1847. * ipr_init_dump_entry_hdr - Initialize a dump entry header.
  1848. * @hdr: dump entry header struct
  1849. *
  1850. * Return value:
  1851. * nothing
  1852. **/
  1853. static void ipr_init_dump_entry_hdr(struct ipr_dump_entry_header *hdr)
  1854. {
  1855. hdr->eye_catcher = IPR_DUMP_EYE_CATCHER;
  1856. hdr->num_elems = 1;
  1857. hdr->offset = sizeof(*hdr);
  1858. hdr->status = IPR_DUMP_STATUS_SUCCESS;
  1859. }
  1860. /**
  1861. * ipr_dump_ioa_type_data - Fill in the adapter type in the dump.
  1862. * @ioa_cfg: ioa config struct
  1863. * @driver_dump: driver dump struct
  1864. *
  1865. * Return value:
  1866. * nothing
  1867. **/
  1868. static void ipr_dump_ioa_type_data(struct ipr_ioa_cfg *ioa_cfg,
  1869. struct ipr_driver_dump *driver_dump)
  1870. {
  1871. struct ipr_inquiry_page3 *ucode_vpd = &ioa_cfg->vpd_cbs->page3_data;
  1872. ipr_init_dump_entry_hdr(&driver_dump->ioa_type_entry.hdr);
  1873. driver_dump->ioa_type_entry.hdr.len =
  1874. sizeof(struct ipr_dump_ioa_type_entry) -
  1875. sizeof(struct ipr_dump_entry_header);
  1876. driver_dump->ioa_type_entry.hdr.data_type = IPR_DUMP_DATA_TYPE_BINARY;
  1877. driver_dump->ioa_type_entry.hdr.id = IPR_DUMP_DRIVER_TYPE_ID;
  1878. driver_dump->ioa_type_entry.type = ioa_cfg->type;
  1879. driver_dump->ioa_type_entry.fw_version = (ucode_vpd->major_release << 24) |
  1880. (ucode_vpd->card_type << 16) | (ucode_vpd->minor_release[0] << 8) |
  1881. ucode_vpd->minor_release[1];
  1882. driver_dump->hdr.num_entries++;
  1883. }
  1884. /**
  1885. * ipr_dump_version_data - Fill in the driver version in the dump.
  1886. * @ioa_cfg: ioa config struct
  1887. * @driver_dump: driver dump struct
  1888. *
  1889. * Return value:
  1890. * nothing
  1891. **/
  1892. static void ipr_dump_version_data(struct ipr_ioa_cfg *ioa_cfg,
  1893. struct ipr_driver_dump *driver_dump)
  1894. {
  1895. ipr_init_dump_entry_hdr(&driver_dump->version_entry.hdr);
  1896. driver_dump->version_entry.hdr.len =
  1897. sizeof(struct ipr_dump_version_entry) -
  1898. sizeof(struct ipr_dump_entry_header);
  1899. driver_dump->version_entry.hdr.data_type = IPR_DUMP_DATA_TYPE_ASCII;
  1900. driver_dump->version_entry.hdr.id = IPR_DUMP_DRIVER_VERSION_ID;
  1901. strcpy(driver_dump->version_entry.version, IPR_DRIVER_VERSION);
  1902. driver_dump->hdr.num_entries++;
  1903. }
  1904. /**
  1905. * ipr_dump_trace_data - Fill in the IOA trace in the dump.
  1906. * @ioa_cfg: ioa config struct
  1907. * @driver_dump: driver dump struct
  1908. *
  1909. * Return value:
  1910. * nothing
  1911. **/
  1912. static void ipr_dump_trace_data(struct ipr_ioa_cfg *ioa_cfg,
  1913. struct ipr_driver_dump *driver_dump)
  1914. {
  1915. ipr_init_dump_entry_hdr(&driver_dump->trace_entry.hdr);
  1916. driver_dump->trace_entry.hdr.len =
  1917. sizeof(struct ipr_dump_trace_entry) -
  1918. sizeof(struct ipr_dump_entry_header);
  1919. driver_dump->trace_entry.hdr.data_type = IPR_DUMP_DATA_TYPE_BINARY;
  1920. driver_dump->trace_entry.hdr.id = IPR_DUMP_TRACE_ID;
  1921. memcpy(driver_dump->trace_entry.trace, ioa_cfg->trace, IPR_TRACE_SIZE);
  1922. driver_dump->hdr.num_entries++;
  1923. }
  1924. /**
  1925. * ipr_dump_location_data - Fill in the IOA location in the dump.
  1926. * @ioa_cfg: ioa config struct
  1927. * @driver_dump: driver dump struct
  1928. *
  1929. * Return value:
  1930. * nothing
  1931. **/
  1932. static void ipr_dump_location_data(struct ipr_ioa_cfg *ioa_cfg,
  1933. struct ipr_driver_dump *driver_dump)
  1934. {
  1935. ipr_init_dump_entry_hdr(&driver_dump->location_entry.hdr);
  1936. driver_dump->location_entry.hdr.len =
  1937. sizeof(struct ipr_dump_location_entry) -
  1938. sizeof(struct ipr_dump_entry_header);
  1939. driver_dump->location_entry.hdr.data_type = IPR_DUMP_DATA_TYPE_ASCII;
  1940. driver_dump->location_entry.hdr.id = IPR_DUMP_LOCATION_ID;
  1941. strcpy(driver_dump->location_entry.location, ioa_cfg->pdev->dev.bus_id);
  1942. driver_dump->hdr.num_entries++;
  1943. }
  1944. /**
  1945. * ipr_get_ioa_dump - Perform a dump of the driver and adapter.
  1946. * @ioa_cfg: ioa config struct
  1947. * @dump: dump struct
  1948. *
  1949. * Return value:
  1950. * nothing
  1951. **/
  1952. static void ipr_get_ioa_dump(struct ipr_ioa_cfg *ioa_cfg, struct ipr_dump *dump)
  1953. {
  1954. unsigned long start_addr, sdt_word;
  1955. unsigned long lock_flags = 0;
  1956. struct ipr_driver_dump *driver_dump = &dump->driver_dump;
  1957. struct ipr_ioa_dump *ioa_dump = &dump->ioa_dump;
  1958. u32 num_entries, start_off, end_off;
  1959. u32 bytes_to_copy, bytes_copied, rc;
  1960. struct ipr_sdt *sdt;
  1961. int i;
  1962. ENTER;
  1963. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  1964. if (ioa_cfg->sdt_state != GET_DUMP) {
  1965. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  1966. return;
  1967. }
  1968. start_addr = readl(ioa_cfg->ioa_mailbox);
  1969. if (!ipr_sdt_is_fmt2(start_addr)) {
  1970. dev_err(&ioa_cfg->pdev->dev,
  1971. "Invalid dump table format: %lx\n", start_addr);
  1972. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  1973. return;
  1974. }
  1975. dev_err(&ioa_cfg->pdev->dev, "Dump of IOA initiated\n");
  1976. driver_dump->hdr.eye_catcher = IPR_DUMP_EYE_CATCHER;
  1977. /* Initialize the overall dump header */
  1978. driver_dump->hdr.len = sizeof(struct ipr_driver_dump);
  1979. driver_dump->hdr.num_entries = 1;
  1980. driver_dump->hdr.first_entry_offset = sizeof(struct ipr_dump_header);
  1981. driver_dump->hdr.status = IPR_DUMP_STATUS_SUCCESS;
  1982. driver_dump->hdr.os = IPR_DUMP_OS_LINUX;
  1983. driver_dump->hdr.driver_name = IPR_DUMP_DRIVER_NAME;
  1984. ipr_dump_version_data(ioa_cfg, driver_dump);
  1985. ipr_dump_location_data(ioa_cfg, driver_dump);
  1986. ipr_dump_ioa_type_data(ioa_cfg, driver_dump);
  1987. ipr_dump_trace_data(ioa_cfg, driver_dump);
  1988. /* Update dump_header */
  1989. driver_dump->hdr.len += sizeof(struct ipr_dump_entry_header);
  1990. /* IOA Dump entry */
  1991. ipr_init_dump_entry_hdr(&ioa_dump->hdr);
  1992. ioa_dump->format = IPR_SDT_FMT2;
  1993. ioa_dump->hdr.len = 0;
  1994. ioa_dump->hdr.data_type = IPR_DUMP_DATA_TYPE_BINARY;
  1995. ioa_dump->hdr.id = IPR_DUMP_IOA_DUMP_ID;
  1996. /* First entries in sdt are actually a list of dump addresses and
  1997. lengths to gather the real dump data. sdt represents the pointer
  1998. to the ioa generated dump table. Dump data will be extracted based
  1999. on entries in this table */
  2000. sdt = &ioa_dump->sdt;
  2001. rc = ipr_get_ldump_data_section(ioa_cfg, start_addr, (__be32 *)sdt,
  2002. sizeof(struct ipr_sdt) / sizeof(__be32));
  2003. /* Smart Dump table is ready to use and the first entry is valid */
  2004. if (rc || (be32_to_cpu(sdt->hdr.state) != IPR_FMT2_SDT_READY_TO_USE)) {
  2005. dev_err(&ioa_cfg->pdev->dev,
  2006. "Dump of IOA failed. Dump table not valid: %d, %X.\n",
  2007. rc, be32_to_cpu(sdt->hdr.state));
  2008. driver_dump->hdr.status = IPR_DUMP_STATUS_FAILED;
  2009. ioa_cfg->sdt_state = DUMP_OBTAINED;
  2010. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2011. return;
  2012. }
  2013. num_entries = be32_to_cpu(sdt->hdr.num_entries_used);
  2014. if (num_entries > IPR_NUM_SDT_ENTRIES)
  2015. num_entries = IPR_NUM_SDT_ENTRIES;
  2016. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2017. for (i = 0; i < num_entries; i++) {
  2018. if (ioa_dump->hdr.len > IPR_MAX_IOA_DUMP_SIZE) {
  2019. driver_dump->hdr.status = IPR_DUMP_STATUS_QUAL_SUCCESS;
  2020. break;
  2021. }
  2022. if (sdt->entry[i].flags & IPR_SDT_VALID_ENTRY) {
  2023. sdt_word = be32_to_cpu(sdt->entry[i].bar_str_offset);
  2024. start_off = sdt_word & IPR_FMT2_MBX_ADDR_MASK;
  2025. end_off = be32_to_cpu(sdt->entry[i].end_offset);
  2026. if (ipr_sdt_is_fmt2(sdt_word) && sdt_word) {
  2027. bytes_to_copy = end_off - start_off;
  2028. if (bytes_to_copy > IPR_MAX_IOA_DUMP_SIZE) {
  2029. sdt->entry[i].flags &= ~IPR_SDT_VALID_ENTRY;
  2030. continue;
  2031. }
  2032. /* Copy data from adapter to driver buffers */
  2033. bytes_copied = ipr_sdt_copy(ioa_cfg, sdt_word,
  2034. bytes_to_copy);
  2035. ioa_dump->hdr.len += bytes_copied;
  2036. if (bytes_copied != bytes_to_copy) {
  2037. driver_dump->hdr.status = IPR_DUMP_STATUS_QUAL_SUCCESS;
  2038. break;
  2039. }
  2040. }
  2041. }
  2042. }
  2043. dev_err(&ioa_cfg->pdev->dev, "Dump of IOA completed.\n");
  2044. /* Update dump_header */
  2045. driver_dump->hdr.len += ioa_dump->hdr.len;
  2046. wmb();
  2047. ioa_cfg->sdt_state = DUMP_OBTAINED;
  2048. LEAVE;
  2049. }
  2050. #else
  2051. #define ipr_get_ioa_dump(ioa_cfg, dump) do { } while(0)
  2052. #endif
  2053. /**
  2054. * ipr_release_dump - Free adapter dump memory
  2055. * @kref: kref struct
  2056. *
  2057. * Return value:
  2058. * nothing
  2059. **/
  2060. static void ipr_release_dump(struct kref *kref)
  2061. {
  2062. struct ipr_dump *dump = container_of(kref,struct ipr_dump,kref);
  2063. struct ipr_ioa_cfg *ioa_cfg = dump->ioa_cfg;
  2064. unsigned long lock_flags = 0;
  2065. int i;
  2066. ENTER;
  2067. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  2068. ioa_cfg->dump = NULL;
  2069. ioa_cfg->sdt_state = INACTIVE;
  2070. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2071. for (i = 0; i < dump->ioa_dump.next_page_index; i++)
  2072. free_page((unsigned long) dump->ioa_dump.ioa_data[i]);
  2073. kfree(dump);
  2074. LEAVE;
  2075. }
  2076. /**
  2077. * ipr_worker_thread - Worker thread
  2078. * @work: ioa config struct
  2079. *
  2080. * Called at task level from a work thread. This function takes care
  2081. * of adding and removing device from the mid-layer as configuration
  2082. * changes are detected by the adapter.
  2083. *
  2084. * Return value:
  2085. * nothing
  2086. **/
  2087. static void ipr_worker_thread(struct work_struct *work)
  2088. {
  2089. unsigned long lock_flags;
  2090. struct ipr_resource_entry *res;
  2091. struct scsi_device *sdev;
  2092. struct ipr_dump *dump;
  2093. struct ipr_ioa_cfg *ioa_cfg =
  2094. container_of(work, struct ipr_ioa_cfg, work_q);
  2095. u8 bus, target, lun;
  2096. int did_work;
  2097. ENTER;
  2098. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  2099. if (ioa_cfg->sdt_state == GET_DUMP) {
  2100. dump = ioa_cfg->dump;
  2101. if (!dump) {
  2102. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2103. return;
  2104. }
  2105. kref_get(&dump->kref);
  2106. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2107. ipr_get_ioa_dump(ioa_cfg, dump);
  2108. kref_put(&dump->kref, ipr_release_dump);
  2109. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  2110. if (ioa_cfg->sdt_state == DUMP_OBTAINED)
  2111. ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
  2112. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2113. return;
  2114. }
  2115. restart:
  2116. do {
  2117. did_work = 0;
  2118. if (!ioa_cfg->allow_cmds || !ioa_cfg->allow_ml_add_del) {
  2119. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2120. return;
  2121. }
  2122. list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
  2123. if (res->del_from_ml && res->sdev) {
  2124. did_work = 1;
  2125. sdev = res->sdev;
  2126. if (!scsi_device_get(sdev)) {
  2127. list_move_tail(&res->queue, &ioa_cfg->free_res_q);
  2128. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2129. scsi_remove_device(sdev);
  2130. scsi_device_put(sdev);
  2131. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  2132. }
  2133. break;
  2134. }
  2135. }
  2136. } while(did_work);
  2137. list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
  2138. if (res->add_to_ml) {
  2139. bus = res->cfgte.res_addr.bus;
  2140. target = res->cfgte.res_addr.target;
  2141. lun = res->cfgte.res_addr.lun;
  2142. res->add_to_ml = 0;
  2143. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2144. scsi_add_device(ioa_cfg->host, bus, target, lun);
  2145. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  2146. goto restart;
  2147. }
  2148. }
  2149. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2150. kobject_uevent(&ioa_cfg->host->shost_dev.kobj, KOBJ_CHANGE);
  2151. LEAVE;
  2152. }
  2153. #ifdef CONFIG_SCSI_IPR_TRACE
  2154. /**
  2155. * ipr_read_trace - Dump the adapter trace
  2156. * @kobj: kobject struct
  2157. * @bin_attr: bin_attribute struct
  2158. * @buf: buffer
  2159. * @off: offset
  2160. * @count: buffer size
  2161. *
  2162. * Return value:
  2163. * number of bytes printed to buffer
  2164. **/
  2165. static ssize_t ipr_read_trace(struct kobject *kobj,
  2166. struct bin_attribute *bin_attr,
  2167. char *buf, loff_t off, size_t count)
  2168. {
  2169. struct device *dev = container_of(kobj, struct device, kobj);
  2170. struct Scsi_Host *shost = class_to_shost(dev);
  2171. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
  2172. unsigned long lock_flags = 0;
  2173. ssize_t ret;
  2174. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  2175. ret = memory_read_from_buffer(buf, count, &off, ioa_cfg->trace,
  2176. IPR_TRACE_SIZE);
  2177. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2178. return ret;
  2179. }
  2180. static struct bin_attribute ipr_trace_attr = {
  2181. .attr = {
  2182. .name = "trace",
  2183. .mode = S_IRUGO,
  2184. },
  2185. .size = 0,
  2186. .read = ipr_read_trace,
  2187. };
  2188. #endif
  2189. static const struct {
  2190. enum ipr_cache_state state;
  2191. char *name;
  2192. } cache_state [] = {
  2193. { CACHE_NONE, "none" },
  2194. { CACHE_DISABLED, "disabled" },
  2195. { CACHE_ENABLED, "enabled" }
  2196. };
  2197. /**
  2198. * ipr_show_write_caching - Show the write caching attribute
  2199. * @dev: device struct
  2200. * @buf: buffer
  2201. *
  2202. * Return value:
  2203. * number of bytes printed to buffer
  2204. **/
  2205. static ssize_t ipr_show_write_caching(struct device *dev,
  2206. struct device_attribute *attr, char *buf)
  2207. {
  2208. struct Scsi_Host *shost = class_to_shost(dev);
  2209. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
  2210. unsigned long lock_flags = 0;
  2211. int i, len = 0;
  2212. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  2213. for (i = 0; i < ARRAY_SIZE(cache_state); i++) {
  2214. if (cache_state[i].state == ioa_cfg->cache_state) {
  2215. len = snprintf(buf, PAGE_SIZE, "%s\n", cache_state[i].name);
  2216. break;
  2217. }
  2218. }
  2219. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2220. return len;
  2221. }
  2222. /**
  2223. * ipr_store_write_caching - Enable/disable adapter write cache
  2224. * @dev: device struct
  2225. * @buf: buffer
  2226. * @count: buffer size
  2227. *
  2228. * This function will enable/disable adapter write cache.
  2229. *
  2230. * Return value:
  2231. * count on success / other on failure
  2232. **/
  2233. static ssize_t ipr_store_write_caching(struct device *dev,
  2234. struct device_attribute *attr,
  2235. const char *buf, size_t count)
  2236. {
  2237. struct Scsi_Host *shost = class_to_shost(dev);
  2238. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
  2239. unsigned long lock_flags = 0;
  2240. enum ipr_cache_state new_state = CACHE_INVALID;
  2241. int i;
  2242. if (!capable(CAP_SYS_ADMIN))
  2243. return -EACCES;
  2244. if (ioa_cfg->cache_state == CACHE_NONE)
  2245. return -EINVAL;
  2246. for (i = 0; i < ARRAY_SIZE(cache_state); i++) {
  2247. if (!strncmp(cache_state[i].name, buf, strlen(cache_state[i].name))) {
  2248. new_state = cache_state[i].state;
  2249. break;
  2250. }
  2251. }
  2252. if (new_state != CACHE_DISABLED && new_state != CACHE_ENABLED)
  2253. return -EINVAL;
  2254. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  2255. if (ioa_cfg->cache_state == new_state) {
  2256. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2257. return count;
  2258. }
  2259. ioa_cfg->cache_state = new_state;
  2260. dev_info(&ioa_cfg->pdev->dev, "%s adapter write cache.\n",
  2261. new_state == CACHE_ENABLED ? "Enabling" : "Disabling");
  2262. if (!ioa_cfg->in_reset_reload)
  2263. ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NORMAL);
  2264. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2265. wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
  2266. return count;
  2267. }
  2268. static struct device_attribute ipr_ioa_cache_attr = {
  2269. .attr = {
  2270. .name = "write_cache",
  2271. .mode = S_IRUGO | S_IWUSR,
  2272. },
  2273. .show = ipr_show_write_caching,
  2274. .store = ipr_store_write_caching
  2275. };
  2276. /**
  2277. * ipr_show_fw_version - Show the firmware version
  2278. * @dev: class device struct
  2279. * @buf: buffer
  2280. *
  2281. * Return value:
  2282. * number of bytes printed to buffer
  2283. **/
  2284. static ssize_t ipr_show_fw_version(struct device *dev,
  2285. struct device_attribute *attr, char *buf)
  2286. {
  2287. struct Scsi_Host *shost = class_to_shost(dev);
  2288. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
  2289. struct ipr_inquiry_page3 *ucode_vpd = &ioa_cfg->vpd_cbs->page3_data;
  2290. unsigned long lock_flags = 0;
  2291. int len;
  2292. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  2293. len = snprintf(buf, PAGE_SIZE, "%02X%02X%02X%02X\n",
  2294. ucode_vpd->major_release, ucode_vpd->card_type,
  2295. ucode_vpd->minor_release[0],
  2296. ucode_vpd->minor_release[1]);
  2297. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2298. return len;
  2299. }
  2300. static struct device_attribute ipr_fw_version_attr = {
  2301. .attr = {
  2302. .name = "fw_version",
  2303. .mode = S_IRUGO,
  2304. },
  2305. .show = ipr_show_fw_version,
  2306. };
  2307. /**
  2308. * ipr_show_log_level - Show the adapter's error logging level
  2309. * @dev: class device struct
  2310. * @buf: buffer
  2311. *
  2312. * Return value:
  2313. * number of bytes printed to buffer
  2314. **/
  2315. static ssize_t ipr_show_log_level(struct device *dev,
  2316. struct device_attribute *attr, char *buf)
  2317. {
  2318. struct Scsi_Host *shost = class_to_shost(dev);
  2319. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
  2320. unsigned long lock_flags = 0;
  2321. int len;
  2322. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  2323. len = snprintf(buf, PAGE_SIZE, "%d\n", ioa_cfg->log_level);
  2324. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2325. return len;
  2326. }
  2327. /**
  2328. * ipr_store_log_level - Change the adapter's error logging level
  2329. * @dev: class device struct
  2330. * @buf: buffer
  2331. *
  2332. * Return value:
  2333. * number of bytes printed to buffer
  2334. **/
  2335. static ssize_t ipr_store_log_level(struct device *dev,
  2336. struct device_attribute *attr,
  2337. const char *buf, size_t count)
  2338. {
  2339. struct Scsi_Host *shost = class_to_shost(dev);
  2340. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
  2341. unsigned long lock_flags = 0;
  2342. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  2343. ioa_cfg->log_level = simple_strtoul(buf, NULL, 10);
  2344. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2345. return strlen(buf);
  2346. }
  2347. static struct device_attribute ipr_log_level_attr = {
  2348. .attr = {
  2349. .name = "log_level",
  2350. .mode = S_IRUGO | S_IWUSR,
  2351. },
  2352. .show = ipr_show_log_level,
  2353. .store = ipr_store_log_level
  2354. };
  2355. /**
  2356. * ipr_store_diagnostics - IOA Diagnostics interface
  2357. * @dev: device struct
  2358. * @buf: buffer
  2359. * @count: buffer size
  2360. *
  2361. * This function will reset the adapter and wait a reasonable
  2362. * amount of time for any errors that the adapter might log.
  2363. *
  2364. * Return value:
  2365. * count on success / other on failure
  2366. **/
  2367. static ssize_t ipr_store_diagnostics(struct device *dev,
  2368. struct device_attribute *attr,
  2369. const char *buf, size_t count)
  2370. {
  2371. struct Scsi_Host *shost = class_to_shost(dev);
  2372. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
  2373. unsigned long lock_flags = 0;
  2374. int rc = count;
  2375. if (!capable(CAP_SYS_ADMIN))
  2376. return -EACCES;
  2377. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  2378. while(ioa_cfg->in_reset_reload) {
  2379. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2380. wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
  2381. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  2382. }
  2383. ioa_cfg->errors_logged = 0;
  2384. ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NORMAL);
  2385. if (ioa_cfg->in_reset_reload) {
  2386. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2387. wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
  2388. /* Wait for a second for any errors to be logged */
  2389. msleep(1000);
  2390. } else {
  2391. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2392. return -EIO;
  2393. }
  2394. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  2395. if (ioa_cfg->in_reset_reload || ioa_cfg->errors_logged)
  2396. rc = -EIO;
  2397. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2398. return rc;
  2399. }
  2400. static struct device_attribute ipr_diagnostics_attr = {
  2401. .attr = {
  2402. .name = "run_diagnostics",
  2403. .mode = S_IWUSR,
  2404. },
  2405. .store = ipr_store_diagnostics
  2406. };
  2407. /**
  2408. * ipr_show_adapter_state - Show the adapter's state
  2409. * @class_dev: device struct
  2410. * @buf: buffer
  2411. *
  2412. * Return value:
  2413. * number of bytes printed to buffer
  2414. **/
  2415. static ssize_t ipr_show_adapter_state(struct device *dev,
  2416. struct device_attribute *attr, char *buf)
  2417. {
  2418. struct Scsi_Host *shost = class_to_shost(dev);
  2419. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
  2420. unsigned long lock_flags = 0;
  2421. int len;
  2422. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  2423. if (ioa_cfg->ioa_is_dead)
  2424. len = snprintf(buf, PAGE_SIZE, "offline\n");
  2425. else
  2426. len = snprintf(buf, PAGE_SIZE, "online\n");
  2427. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2428. return len;
  2429. }
  2430. /**
  2431. * ipr_store_adapter_state - Change adapter state
  2432. * @dev: device struct
  2433. * @buf: buffer
  2434. * @count: buffer size
  2435. *
  2436. * This function will change the adapter's state.
  2437. *
  2438. * Return value:
  2439. * count on success / other on failure
  2440. **/
  2441. static ssize_t ipr_store_adapter_state(struct device *dev,
  2442. struct device_attribute *attr,
  2443. const char *buf, size_t count)
  2444. {
  2445. struct Scsi_Host *shost = class_to_shost(dev);
  2446. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
  2447. unsigned long lock_flags;
  2448. int result = count;
  2449. if (!capable(CAP_SYS_ADMIN))
  2450. return -EACCES;
  2451. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  2452. if (ioa_cfg->ioa_is_dead && !strncmp(buf, "online", 6)) {
  2453. ioa_cfg->ioa_is_dead = 0;
  2454. ioa_cfg->reset_retries = 0;
  2455. ioa_cfg->in_ioa_bringdown = 0;
  2456. ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
  2457. }
  2458. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2459. wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
  2460. return result;
  2461. }
  2462. static struct device_attribute ipr_ioa_state_attr = {
  2463. .attr = {
  2464. .name = "online_state",
  2465. .mode = S_IRUGO | S_IWUSR,
  2466. },
  2467. .show = ipr_show_adapter_state,
  2468. .store = ipr_store_adapter_state
  2469. };
  2470. /**
  2471. * ipr_store_reset_adapter - Reset the adapter
  2472. * @dev: device struct
  2473. * @buf: buffer
  2474. * @count: buffer size
  2475. *
  2476. * This function will reset the adapter.
  2477. *
  2478. * Return value:
  2479. * count on success / other on failure
  2480. **/
  2481. static ssize_t ipr_store_reset_adapter(struct device *dev,
  2482. struct device_attribute *attr,
  2483. const char *buf, size_t count)
  2484. {
  2485. struct Scsi_Host *shost = class_to_shost(dev);
  2486. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
  2487. unsigned long lock_flags;
  2488. int result = count;
  2489. if (!capable(CAP_SYS_ADMIN))
  2490. return -EACCES;
  2491. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  2492. if (!ioa_cfg->in_reset_reload)
  2493. ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NORMAL);
  2494. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2495. wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
  2496. return result;
  2497. }
  2498. static struct device_attribute ipr_ioa_reset_attr = {
  2499. .attr = {
  2500. .name = "reset_host",
  2501. .mode = S_IWUSR,
  2502. },
  2503. .store = ipr_store_reset_adapter
  2504. };
  2505. /**
  2506. * ipr_alloc_ucode_buffer - Allocates a microcode download buffer
  2507. * @buf_len: buffer length
  2508. *
  2509. * Allocates a DMA'able buffer in chunks and assembles a scatter/gather
  2510. * list to use for microcode download
  2511. *
  2512. * Return value:
  2513. * pointer to sglist / NULL on failure
  2514. **/
  2515. static struct ipr_sglist *ipr_alloc_ucode_buffer(int buf_len)
  2516. {
  2517. int sg_size, order, bsize_elem, num_elem, i, j;
  2518. struct ipr_sglist *sglist;
  2519. struct scatterlist *scatterlist;
  2520. struct page *page;
  2521. /* Get the minimum size per scatter/gather element */
  2522. sg_size = buf_len / (IPR_MAX_SGLIST - 1);
  2523. /* Get the actual size per element */
  2524. order = get_order(sg_size);
  2525. /* Determine the actual number of bytes per element */
  2526. bsize_elem = PAGE_SIZE * (1 << order);
  2527. /* Determine the actual number of sg entries needed */
  2528. if (buf_len % bsize_elem)
  2529. num_elem = (buf_len / bsize_elem) + 1;
  2530. else
  2531. num_elem = buf_len / bsize_elem;
  2532. /* Allocate a scatter/gather list for the DMA */
  2533. sglist = kzalloc(sizeof(struct ipr_sglist) +
  2534. (sizeof(struct scatterlist) * (num_elem - 1)),
  2535. GFP_KERNEL);
  2536. if (sglist == NULL) {
  2537. ipr_trace;
  2538. return NULL;
  2539. }
  2540. scatterlist = sglist->scatterlist;
  2541. sg_init_table(scatterlist, num_elem);
  2542. sglist->order = order;
  2543. sglist->num_sg = num_elem;
  2544. /* Allocate a bunch of sg elements */
  2545. for (i = 0; i < num_elem; i++) {
  2546. page = alloc_pages(GFP_KERNEL, order);
  2547. if (!page) {
  2548. ipr_trace;
  2549. /* Free up what we already allocated */
  2550. for (j = i - 1; j >= 0; j--)
  2551. __free_pages(sg_page(&scatterlist[j]), order);
  2552. kfree(sglist);
  2553. return NULL;
  2554. }
  2555. sg_set_page(&scatterlist[i], page, 0, 0);
  2556. }
  2557. return sglist;
  2558. }
  2559. /**
  2560. * ipr_free_ucode_buffer - Frees a microcode download buffer
  2561. * @p_dnld: scatter/gather list pointer
  2562. *
  2563. * Free a DMA'able ucode download buffer previously allocated with
  2564. * ipr_alloc_ucode_buffer
  2565. *
  2566. * Return value:
  2567. * nothing
  2568. **/
  2569. static void ipr_free_ucode_buffer(struct ipr_sglist *sglist)
  2570. {
  2571. int i;
  2572. for (i = 0; i < sglist->num_sg; i++)
  2573. __free_pages(sg_page(&sglist->scatterlist[i]), sglist->order);
  2574. kfree(sglist);
  2575. }
  2576. /**
  2577. * ipr_copy_ucode_buffer - Copy user buffer to kernel buffer
  2578. * @sglist: scatter/gather list pointer
  2579. * @buffer: buffer pointer
  2580. * @len: buffer length
  2581. *
  2582. * Copy a microcode image from a user buffer into a buffer allocated by
  2583. * ipr_alloc_ucode_buffer
  2584. *
  2585. * Return value:
  2586. * 0 on success / other on failure
  2587. **/
  2588. static int ipr_copy_ucode_buffer(struct ipr_sglist *sglist,
  2589. u8 *buffer, u32 len)
  2590. {
  2591. int bsize_elem, i, result = 0;
  2592. struct scatterlist *scatterlist;
  2593. void *kaddr;
  2594. /* Determine the actual number of bytes per element */
  2595. bsize_elem = PAGE_SIZE * (1 << sglist->order);
  2596. scatterlist = sglist->scatterlist;
  2597. for (i = 0; i < (len / bsize_elem); i++, buffer += bsize_elem) {
  2598. struct page *page = sg_page(&scatterlist[i]);
  2599. kaddr = kmap(page);
  2600. memcpy(kaddr, buffer, bsize_elem);
  2601. kunmap(page);
  2602. scatterlist[i].length = bsize_elem;
  2603. if (result != 0) {
  2604. ipr_trace;
  2605. return result;
  2606. }
  2607. }
  2608. if (len % bsize_elem) {
  2609. struct page *page = sg_page(&scatterlist[i]);
  2610. kaddr = kmap(page);
  2611. memcpy(kaddr, buffer, len % bsize_elem);
  2612. kunmap(page);
  2613. scatterlist[i].length = len % bsize_elem;
  2614. }
  2615. sglist->buffer_len = len;
  2616. return result;
  2617. }
  2618. /**
  2619. * ipr_build_ucode_ioadl - Build a microcode download IOADL
  2620. * @ipr_cmd: ipr command struct
  2621. * @sglist: scatter/gather list
  2622. *
  2623. * Builds a microcode download IOA data list (IOADL).
  2624. *
  2625. **/
  2626. static void ipr_build_ucode_ioadl(struct ipr_cmnd *ipr_cmd,
  2627. struct ipr_sglist *sglist)
  2628. {
  2629. struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
  2630. struct ipr_ioadl_desc *ioadl = ipr_cmd->ioadl;
  2631. struct scatterlist *scatterlist = sglist->scatterlist;
  2632. int i;
  2633. ipr_cmd->dma_use_sg = sglist->num_dma_sg;
  2634. ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
  2635. ioarcb->write_data_transfer_length = cpu_to_be32(sglist->buffer_len);
  2636. ioarcb->write_ioadl_len =
  2637. cpu_to_be32(sizeof(struct ipr_ioadl_desc) * ipr_cmd->dma_use_sg);
  2638. for (i = 0; i < ipr_cmd->dma_use_sg; i++) {
  2639. ioadl[i].flags_and_data_len =
  2640. cpu_to_be32(IPR_IOADL_FLAGS_WRITE | sg_dma_len(&scatterlist[i]));
  2641. ioadl[i].address =
  2642. cpu_to_be32(sg_dma_address(&scatterlist[i]));
  2643. }
  2644. ioadl[i-1].flags_and_data_len |=
  2645. cpu_to_be32(IPR_IOADL_FLAGS_LAST);
  2646. }
  2647. /**
  2648. * ipr_update_ioa_ucode - Update IOA's microcode
  2649. * @ioa_cfg: ioa config struct
  2650. * @sglist: scatter/gather list
  2651. *
  2652. * Initiate an adapter reset to update the IOA's microcode
  2653. *
  2654. * Return value:
  2655. * 0 on success / -EIO on failure
  2656. **/
  2657. static int ipr_update_ioa_ucode(struct ipr_ioa_cfg *ioa_cfg,
  2658. struct ipr_sglist *sglist)
  2659. {
  2660. unsigned long lock_flags;
  2661. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  2662. while(ioa_cfg->in_reset_reload) {
  2663. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2664. wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
  2665. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  2666. }
  2667. if (ioa_cfg->ucode_sglist) {
  2668. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2669. dev_err(&ioa_cfg->pdev->dev,
  2670. "Microcode download already in progress\n");
  2671. return -EIO;
  2672. }
  2673. sglist->num_dma_sg = pci_map_sg(ioa_cfg->pdev, sglist->scatterlist,
  2674. sglist->num_sg, DMA_TO_DEVICE);
  2675. if (!sglist->num_dma_sg) {
  2676. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2677. dev_err(&ioa_cfg->pdev->dev,
  2678. "Failed to map microcode download buffer!\n");
  2679. return -EIO;
  2680. }
  2681. ioa_cfg->ucode_sglist = sglist;
  2682. ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NORMAL);
  2683. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2684. wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
  2685. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  2686. ioa_cfg->ucode_sglist = NULL;
  2687. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2688. return 0;
  2689. }
  2690. /**
  2691. * ipr_store_update_fw - Update the firmware on the adapter
  2692. * @class_dev: device struct
  2693. * @buf: buffer
  2694. * @count: buffer size
  2695. *
  2696. * This function will update the firmware on the adapter.
  2697. *
  2698. * Return value:
  2699. * count on success / other on failure
  2700. **/
  2701. static ssize_t ipr_store_update_fw(struct device *dev,
  2702. struct device_attribute *attr,
  2703. const char *buf, size_t count)
  2704. {
  2705. struct Scsi_Host *shost = class_to_shost(dev);
  2706. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
  2707. struct ipr_ucode_image_header *image_hdr;
  2708. const struct firmware *fw_entry;
  2709. struct ipr_sglist *sglist;
  2710. char fname[100];
  2711. char *src;
  2712. int len, result, dnld_size;
  2713. if (!capable(CAP_SYS_ADMIN))
  2714. return -EACCES;
  2715. len = snprintf(fname, 99, "%s", buf);
  2716. fname[len-1] = '\0';
  2717. if(request_firmware(&fw_entry, fname, &ioa_cfg->pdev->dev)) {
  2718. dev_err(&ioa_cfg->pdev->dev, "Firmware file %s not found\n", fname);
  2719. return -EIO;
  2720. }
  2721. image_hdr = (struct ipr_ucode_image_header *)fw_entry->data;
  2722. if (be32_to_cpu(image_hdr->header_length) > fw_entry->size ||
  2723. (ioa_cfg->vpd_cbs->page3_data.card_type &&
  2724. ioa_cfg->vpd_cbs->page3_data.card_type != image_hdr->card_type)) {
  2725. dev_err(&ioa_cfg->pdev->dev, "Invalid microcode buffer\n");
  2726. release_firmware(fw_entry);
  2727. return -EINVAL;
  2728. }
  2729. src = (u8 *)image_hdr + be32_to_cpu(image_hdr->header_length);
  2730. dnld_size = fw_entry->size - be32_to_cpu(image_hdr->header_length);
  2731. sglist = ipr_alloc_ucode_buffer(dnld_size);
  2732. if (!sglist) {
  2733. dev_err(&ioa_cfg->pdev->dev, "Microcode buffer allocation failed\n");
  2734. release_firmware(fw_entry);
  2735. return -ENOMEM;
  2736. }
  2737. result = ipr_copy_ucode_buffer(sglist, src, dnld_size);
  2738. if (result) {
  2739. dev_err(&ioa_cfg->pdev->dev,
  2740. "Microcode buffer copy to DMA buffer failed\n");
  2741. goto out;
  2742. }
  2743. result = ipr_update_ioa_ucode(ioa_cfg, sglist);
  2744. if (!result)
  2745. result = count;
  2746. out:
  2747. ipr_free_ucode_buffer(sglist);
  2748. release_firmware(fw_entry);
  2749. return result;
  2750. }
  2751. static struct device_attribute ipr_update_fw_attr = {
  2752. .attr = {
  2753. .name = "update_fw",
  2754. .mode = S_IWUSR,
  2755. },
  2756. .store = ipr_store_update_fw
  2757. };
  2758. static struct device_attribute *ipr_ioa_attrs[] = {
  2759. &ipr_fw_version_attr,
  2760. &ipr_log_level_attr,
  2761. &ipr_diagnostics_attr,
  2762. &ipr_ioa_state_attr,
  2763. &ipr_ioa_reset_attr,
  2764. &ipr_update_fw_attr,
  2765. &ipr_ioa_cache_attr,
  2766. NULL,
  2767. };
  2768. #ifdef CONFIG_SCSI_IPR_DUMP
  2769. /**
  2770. * ipr_read_dump - Dump the adapter
  2771. * @kobj: kobject struct
  2772. * @bin_attr: bin_attribute struct
  2773. * @buf: buffer
  2774. * @off: offset
  2775. * @count: buffer size
  2776. *
  2777. * Return value:
  2778. * number of bytes printed to buffer
  2779. **/
  2780. static ssize_t ipr_read_dump(struct kobject *kobj,
  2781. struct bin_attribute *bin_attr,
  2782. char *buf, loff_t off, size_t count)
  2783. {
  2784. struct device *cdev = container_of(kobj, struct device, kobj);
  2785. struct Scsi_Host *shost = class_to_shost(cdev);
  2786. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
  2787. struct ipr_dump *dump;
  2788. unsigned long lock_flags = 0;
  2789. char *src;
  2790. int len;
  2791. size_t rc = count;
  2792. if (!capable(CAP_SYS_ADMIN))
  2793. return -EACCES;
  2794. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  2795. dump = ioa_cfg->dump;
  2796. if (ioa_cfg->sdt_state != DUMP_OBTAINED || !dump) {
  2797. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2798. return 0;
  2799. }
  2800. kref_get(&dump->kref);
  2801. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2802. if (off > dump->driver_dump.hdr.len) {
  2803. kref_put(&dump->kref, ipr_release_dump);
  2804. return 0;
  2805. }
  2806. if (off + count > dump->driver_dump.hdr.len) {
  2807. count = dump->driver_dump.hdr.len - off;
  2808. rc = count;
  2809. }
  2810. if (count && off < sizeof(dump->driver_dump)) {
  2811. if (off + count > sizeof(dump->driver_dump))
  2812. len = sizeof(dump->driver_dump) - off;
  2813. else
  2814. len = count;
  2815. src = (u8 *)&dump->driver_dump + off;
  2816. memcpy(buf, src, len);
  2817. buf += len;
  2818. off += len;
  2819. count -= len;
  2820. }
  2821. off -= sizeof(dump->driver_dump);
  2822. if (count && off < offsetof(struct ipr_ioa_dump, ioa_data)) {
  2823. if (off + count > offsetof(struct ipr_ioa_dump, ioa_data))
  2824. len = offsetof(struct ipr_ioa_dump, ioa_data) - off;
  2825. else
  2826. len = count;
  2827. src = (u8 *)&dump->ioa_dump + off;
  2828. memcpy(buf, src, len);
  2829. buf += len;
  2830. off += len;
  2831. count -= len;
  2832. }
  2833. off -= offsetof(struct ipr_ioa_dump, ioa_data);
  2834. while (count) {
  2835. if ((off & PAGE_MASK) != ((off + count) & PAGE_MASK))
  2836. len = PAGE_ALIGN(off) - off;
  2837. else
  2838. len = count;
  2839. src = (u8 *)dump->ioa_dump.ioa_data[(off & PAGE_MASK) >> PAGE_SHIFT];
  2840. src += off & ~PAGE_MASK;
  2841. memcpy(buf, src, len);
  2842. buf += len;
  2843. off += len;
  2844. count -= len;
  2845. }
  2846. kref_put(&dump->kref, ipr_release_dump);
  2847. return rc;
  2848. }
  2849. /**
  2850. * ipr_alloc_dump - Prepare for adapter dump
  2851. * @ioa_cfg: ioa config struct
  2852. *
  2853. * Return value:
  2854. * 0 on success / other on failure
  2855. **/
  2856. static int ipr_alloc_dump(struct ipr_ioa_cfg *ioa_cfg)
  2857. {
  2858. struct ipr_dump *dump;
  2859. unsigned long lock_flags = 0;
  2860. dump = kzalloc(sizeof(struct ipr_dump), GFP_KERNEL);
  2861. if (!dump) {
  2862. ipr_err("Dump memory allocation failed\n");
  2863. return -ENOMEM;
  2864. }
  2865. kref_init(&dump->kref);
  2866. dump->ioa_cfg = ioa_cfg;
  2867. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  2868. if (INACTIVE != ioa_cfg->sdt_state) {
  2869. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2870. kfree(dump);
  2871. return 0;
  2872. }
  2873. ioa_cfg->dump = dump;
  2874. ioa_cfg->sdt_state = WAIT_FOR_DUMP;
  2875. if (ioa_cfg->ioa_is_dead && !ioa_cfg->dump_taken) {
  2876. ioa_cfg->dump_taken = 1;
  2877. schedule_work(&ioa_cfg->work_q);
  2878. }
  2879. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2880. return 0;
  2881. }
  2882. /**
  2883. * ipr_free_dump - Free adapter dump memory
  2884. * @ioa_cfg: ioa config struct
  2885. *
  2886. * Return value:
  2887. * 0 on success / other on failure
  2888. **/
  2889. static int ipr_free_dump(struct ipr_ioa_cfg *ioa_cfg)
  2890. {
  2891. struct ipr_dump *dump;
  2892. unsigned long lock_flags = 0;
  2893. ENTER;
  2894. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  2895. dump = ioa_cfg->dump;
  2896. if (!dump) {
  2897. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2898. return 0;
  2899. }
  2900. ioa_cfg->dump = NULL;
  2901. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2902. kref_put(&dump->kref, ipr_release_dump);
  2903. LEAVE;
  2904. return 0;
  2905. }
  2906. /**
  2907. * ipr_write_dump - Setup dump state of adapter
  2908. * @kobj: kobject struct
  2909. * @bin_attr: bin_attribute struct
  2910. * @buf: buffer
  2911. * @off: offset
  2912. * @count: buffer size
  2913. *
  2914. * Return value:
  2915. * number of bytes printed to buffer
  2916. **/
  2917. static ssize_t ipr_write_dump(struct kobject *kobj,
  2918. struct bin_attribute *bin_attr,
  2919. char *buf, loff_t off, size_t count)
  2920. {
  2921. struct device *cdev = container_of(kobj, struct device, kobj);
  2922. struct Scsi_Host *shost = class_to_shost(cdev);
  2923. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
  2924. int rc;
  2925. if (!capable(CAP_SYS_ADMIN))
  2926. return -EACCES;
  2927. if (buf[0] == '1')
  2928. rc = ipr_alloc_dump(ioa_cfg);
  2929. else if (buf[0] == '0')
  2930. rc = ipr_free_dump(ioa_cfg);
  2931. else
  2932. return -EINVAL;
  2933. if (rc)
  2934. return rc;
  2935. else
  2936. return count;
  2937. }
  2938. static struct bin_attribute ipr_dump_attr = {
  2939. .attr = {
  2940. .name = "dump",
  2941. .mode = S_IRUSR | S_IWUSR,
  2942. },
  2943. .size = 0,
  2944. .read = ipr_read_dump,
  2945. .write = ipr_write_dump
  2946. };
  2947. #else
  2948. static int ipr_free_dump(struct ipr_ioa_cfg *ioa_cfg) { return 0; };
  2949. #endif
  2950. /**
  2951. * ipr_change_queue_depth - Change the device's queue depth
  2952. * @sdev: scsi device struct
  2953. * @qdepth: depth to set
  2954. *
  2955. * Return value:
  2956. * actual depth set
  2957. **/
  2958. static int ipr_change_queue_depth(struct scsi_device *sdev, int qdepth)
  2959. {
  2960. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)sdev->host->hostdata;
  2961. struct ipr_resource_entry *res;
  2962. unsigned long lock_flags = 0;
  2963. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  2964. res = (struct ipr_resource_entry *)sdev->hostdata;
  2965. if (res && ipr_is_gata(res) && qdepth > IPR_MAX_CMD_PER_ATA_LUN)
  2966. qdepth = IPR_MAX_CMD_PER_ATA_LUN;
  2967. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2968. scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), qdepth);
  2969. return sdev->queue_depth;
  2970. }
  2971. /**
  2972. * ipr_change_queue_type - Change the device's queue type
  2973. * @dsev: scsi device struct
  2974. * @tag_type: type of tags to use
  2975. *
  2976. * Return value:
  2977. * actual queue type set
  2978. **/
  2979. static int ipr_change_queue_type(struct scsi_device *sdev, int tag_type)
  2980. {
  2981. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)sdev->host->hostdata;
  2982. struct ipr_resource_entry *res;
  2983. unsigned long lock_flags = 0;
  2984. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  2985. res = (struct ipr_resource_entry *)sdev->hostdata;
  2986. if (res) {
  2987. if (ipr_is_gscsi(res) && sdev->tagged_supported) {
  2988. /*
  2989. * We don't bother quiescing the device here since the
  2990. * adapter firmware does it for us.
  2991. */
  2992. scsi_set_tag_type(sdev, tag_type);
  2993. if (tag_type)
  2994. scsi_activate_tcq(sdev, sdev->queue_depth);
  2995. else
  2996. scsi_deactivate_tcq(sdev, sdev->queue_depth);
  2997. } else
  2998. tag_type = 0;
  2999. } else
  3000. tag_type = 0;
  3001. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  3002. return tag_type;
  3003. }
  3004. /**
  3005. * ipr_show_adapter_handle - Show the adapter's resource handle for this device
  3006. * @dev: device struct
  3007. * @buf: buffer
  3008. *
  3009. * Return value:
  3010. * number of bytes printed to buffer
  3011. **/
  3012. static ssize_t ipr_show_adapter_handle(struct device *dev, struct device_attribute *attr, char *buf)
  3013. {
  3014. struct scsi_device *sdev = to_scsi_device(dev);
  3015. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)sdev->host->hostdata;
  3016. struct ipr_resource_entry *res;
  3017. unsigned long lock_flags = 0;
  3018. ssize_t len = -ENXIO;
  3019. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  3020. res = (struct ipr_resource_entry *)sdev->hostdata;
  3021. if (res)
  3022. len = snprintf(buf, PAGE_SIZE, "%08X\n", res->cfgte.res_handle);
  3023. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  3024. return len;
  3025. }
  3026. static struct device_attribute ipr_adapter_handle_attr = {
  3027. .attr = {
  3028. .name = "adapter_handle",
  3029. .mode = S_IRUSR,
  3030. },
  3031. .show = ipr_show_adapter_handle
  3032. };
  3033. static struct device_attribute *ipr_dev_attrs[] = {
  3034. &ipr_adapter_handle_attr,
  3035. NULL,
  3036. };
  3037. /**
  3038. * ipr_biosparam - Return the HSC mapping
  3039. * @sdev: scsi device struct
  3040. * @block_device: block device pointer
  3041. * @capacity: capacity of the device
  3042. * @parm: Array containing returned HSC values.
  3043. *
  3044. * This function generates the HSC parms that fdisk uses.
  3045. * We want to make sure we return something that places partitions
  3046. * on 4k boundaries for best performance with the IOA.
  3047. *
  3048. * Return value:
  3049. * 0 on success
  3050. **/
  3051. static int ipr_biosparam(struct scsi_device *sdev,
  3052. struct block_device *block_device,
  3053. sector_t capacity, int *parm)
  3054. {
  3055. int heads, sectors;
  3056. sector_t cylinders;
  3057. heads = 128;
  3058. sectors = 32;
  3059. cylinders = capacity;
  3060. sector_div(cylinders, (128 * 32));
  3061. /* return result */
  3062. parm[0] = heads;
  3063. parm[1] = sectors;
  3064. parm[2] = cylinders;
  3065. return 0;
  3066. }
  3067. /**
  3068. * ipr_find_starget - Find target based on bus/target.
  3069. * @starget: scsi target struct
  3070. *
  3071. * Return value:
  3072. * resource entry pointer if found / NULL if not found
  3073. **/
  3074. static struct ipr_resource_entry *ipr_find_starget(struct scsi_target *starget)
  3075. {
  3076. struct Scsi_Host *shost = dev_to_shost(&starget->dev);
  3077. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *) shost->hostdata;
  3078. struct ipr_resource_entry *res;
  3079. list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
  3080. if ((res->cfgte.res_addr.bus == starget->channel) &&
  3081. (res->cfgte.res_addr.target == starget->id) &&
  3082. (res->cfgte.res_addr.lun == 0)) {
  3083. return res;
  3084. }
  3085. }
  3086. return NULL;
  3087. }
  3088. static struct ata_port_info sata_port_info;
  3089. /**
  3090. * ipr_target_alloc - Prepare for commands to a SCSI target
  3091. * @starget: scsi target struct
  3092. *
  3093. * If the device is a SATA device, this function allocates an
  3094. * ATA port with libata, else it does nothing.
  3095. *
  3096. * Return value:
  3097. * 0 on success / non-0 on failure
  3098. **/
  3099. static int ipr_target_alloc(struct scsi_target *starget)
  3100. {
  3101. struct Scsi_Host *shost = dev_to_shost(&starget->dev);
  3102. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *) shost->hostdata;
  3103. struct ipr_sata_port *sata_port;
  3104. struct ata_port *ap;
  3105. struct ipr_resource_entry *res;
  3106. unsigned long lock_flags;
  3107. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  3108. res = ipr_find_starget(starget);
  3109. starget->hostdata = NULL;
  3110. if (res && ipr_is_gata(res)) {
  3111. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  3112. sata_port = kzalloc(sizeof(*sata_port), GFP_KERNEL);
  3113. if (!sata_port)
  3114. return -ENOMEM;
  3115. ap = ata_sas_port_alloc(&ioa_cfg->ata_host, &sata_port_info, shost);
  3116. if (ap) {
  3117. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  3118. sata_port->ioa_cfg = ioa_cfg;
  3119. sata_port->ap = ap;
  3120. sata_port->res = res;
  3121. res->sata_port = sata_port;
  3122. ap->private_data = sata_port;
  3123. starget->hostdata = sata_port;
  3124. } else {
  3125. kfree(sata_port);
  3126. return -ENOMEM;
  3127. }
  3128. }
  3129. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  3130. return 0;
  3131. }
  3132. /**
  3133. * ipr_target_destroy - Destroy a SCSI target
  3134. * @starget: scsi target struct
  3135. *
  3136. * If the device was a SATA device, this function frees the libata
  3137. * ATA port, else it does nothing.
  3138. *
  3139. **/
  3140. static void ipr_target_destroy(struct scsi_target *starget)
  3141. {
  3142. struct ipr_sata_port *sata_port = starget->hostdata;
  3143. if (sata_port) {
  3144. starget->hostdata = NULL;
  3145. ata_sas_port_destroy(sata_port->ap);
  3146. kfree(sata_port);
  3147. }
  3148. }
  3149. /**
  3150. * ipr_find_sdev - Find device based on bus/target/lun.
  3151. * @sdev: scsi device struct
  3152. *
  3153. * Return value:
  3154. * resource entry pointer if found / NULL if not found
  3155. **/
  3156. static struct ipr_resource_entry *ipr_find_sdev(struct scsi_device *sdev)
  3157. {
  3158. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *) sdev->host->hostdata;
  3159. struct ipr_resource_entry *res;
  3160. list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
  3161. if ((res->cfgte.res_addr.bus == sdev->channel) &&
  3162. (res->cfgte.res_addr.target == sdev->id) &&
  3163. (res->cfgte.res_addr.lun == sdev->lun))
  3164. return res;
  3165. }
  3166. return NULL;
  3167. }
  3168. /**
  3169. * ipr_slave_destroy - Unconfigure a SCSI device
  3170. * @sdev: scsi device struct
  3171. *
  3172. * Return value:
  3173. * nothing
  3174. **/
  3175. static void ipr_slave_destroy(struct scsi_device *sdev)
  3176. {
  3177. struct ipr_resource_entry *res;
  3178. struct ipr_ioa_cfg *ioa_cfg;
  3179. unsigned long lock_flags = 0;
  3180. ioa_cfg = (struct ipr_ioa_cfg *) sdev->host->hostdata;
  3181. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  3182. res = (struct ipr_resource_entry *) sdev->hostdata;
  3183. if (res) {
  3184. if (res->sata_port)
  3185. ata_port_disable(res->sata_port->ap);
  3186. sdev->hostdata = NULL;
  3187. res->sdev = NULL;
  3188. res->sata_port = NULL;
  3189. }
  3190. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  3191. }
  3192. /**
  3193. * ipr_slave_configure - Configure a SCSI device
  3194. * @sdev: scsi device struct
  3195. *
  3196. * This function configures the specified scsi device.
  3197. *
  3198. * Return value:
  3199. * 0 on success
  3200. **/
  3201. static int ipr_slave_configure(struct scsi_device *sdev)
  3202. {
  3203. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *) sdev->host->hostdata;
  3204. struct ipr_resource_entry *res;
  3205. unsigned long lock_flags = 0;
  3206. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  3207. res = sdev->hostdata;
  3208. if (res) {
  3209. if (ipr_is_af_dasd_device(res))
  3210. sdev->type = TYPE_RAID;
  3211. if (ipr_is_af_dasd_device(res) || ipr_is_ioa_resource(res)) {
  3212. sdev->scsi_level = 4;
  3213. sdev->no_uld_attach = 1;
  3214. }
  3215. if (ipr_is_vset_device(res)) {
  3216. blk_queue_rq_timeout(sdev->request_queue,
  3217. IPR_VSET_RW_TIMEOUT);
  3218. blk_queue_max_sectors(sdev->request_queue, IPR_VSET_MAX_SECTORS);
  3219. }
  3220. if (ipr_is_vset_device(res) || ipr_is_scsi_disk(res))
  3221. sdev->allow_restart = 1;
  3222. if (ipr_is_gata(res) && res->sata_port) {
  3223. scsi_adjust_queue_depth(sdev, 0, IPR_MAX_CMD_PER_ATA_LUN);
  3224. ata_sas_slave_configure(sdev, res->sata_port->ap);
  3225. } else {
  3226. scsi_adjust_queue_depth(sdev, 0, sdev->host->cmd_per_lun);
  3227. }
  3228. }
  3229. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  3230. return 0;
  3231. }
  3232. /**
  3233. * ipr_ata_slave_alloc - Prepare for commands to a SATA device
  3234. * @sdev: scsi device struct
  3235. *
  3236. * This function initializes an ATA port so that future commands
  3237. * sent through queuecommand will work.
  3238. *
  3239. * Return value:
  3240. * 0 on success
  3241. **/
  3242. static int ipr_ata_slave_alloc(struct scsi_device *sdev)
  3243. {
  3244. struct ipr_sata_port *sata_port = NULL;
  3245. int rc = -ENXIO;
  3246. ENTER;
  3247. if (sdev->sdev_target)
  3248. sata_port = sdev->sdev_target->hostdata;
  3249. if (sata_port)
  3250. rc = ata_sas_port_init(sata_port->ap);
  3251. if (rc)
  3252. ipr_slave_destroy(sdev);
  3253. LEAVE;
  3254. return rc;
  3255. }
  3256. /**
  3257. * ipr_slave_alloc - Prepare for commands to a device.
  3258. * @sdev: scsi device struct
  3259. *
  3260. * This function saves a pointer to the resource entry
  3261. * in the scsi device struct if the device exists. We
  3262. * can then use this pointer in ipr_queuecommand when
  3263. * handling new commands.
  3264. *
  3265. * Return value:
  3266. * 0 on success / -ENXIO if device does not exist
  3267. **/
  3268. static int ipr_slave_alloc(struct scsi_device *sdev)
  3269. {
  3270. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *) sdev->host->hostdata;
  3271. struct ipr_resource_entry *res;
  3272. unsigned long lock_flags;
  3273. int rc = -ENXIO;
  3274. sdev->hostdata = NULL;
  3275. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  3276. res = ipr_find_sdev(sdev);
  3277. if (res) {
  3278. res->sdev = sdev;
  3279. res->add_to_ml = 0;
  3280. res->in_erp = 0;
  3281. sdev->hostdata = res;
  3282. if (!ipr_is_naca_model(res))
  3283. res->needs_sync_complete = 1;
  3284. rc = 0;
  3285. if (ipr_is_gata(res)) {
  3286. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  3287. return ipr_ata_slave_alloc(sdev);
  3288. }
  3289. }
  3290. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  3291. return rc;
  3292. }
  3293. /**
  3294. * ipr_eh_host_reset - Reset the host adapter
  3295. * @scsi_cmd: scsi command struct
  3296. *
  3297. * Return value:
  3298. * SUCCESS / FAILED
  3299. **/
  3300. static int __ipr_eh_host_reset(struct scsi_cmnd * scsi_cmd)
  3301. {
  3302. struct ipr_ioa_cfg *ioa_cfg;
  3303. int rc;
  3304. ENTER;
  3305. ioa_cfg = (struct ipr_ioa_cfg *) scsi_cmd->device->host->hostdata;
  3306. dev_err(&ioa_cfg->pdev->dev,
  3307. "Adapter being reset as a result of error recovery.\n");
  3308. if (WAIT_FOR_DUMP == ioa_cfg->sdt_state)
  3309. ioa_cfg->sdt_state = GET_DUMP;
  3310. rc = ipr_reset_reload(ioa_cfg, IPR_SHUTDOWN_ABBREV);
  3311. LEAVE;
  3312. return rc;
  3313. }
  3314. static int ipr_eh_host_reset(struct scsi_cmnd * cmd)
  3315. {
  3316. int rc;
  3317. spin_lock_irq(cmd->device->host->host_lock);
  3318. rc = __ipr_eh_host_reset(cmd);
  3319. spin_unlock_irq(cmd->device->host->host_lock);
  3320. return rc;
  3321. }
  3322. /**
  3323. * ipr_device_reset - Reset the device
  3324. * @ioa_cfg: ioa config struct
  3325. * @res: resource entry struct
  3326. *
  3327. * This function issues a device reset to the affected device.
  3328. * If the device is a SCSI device, a LUN reset will be sent
  3329. * to the device first. If that does not work, a target reset
  3330. * will be sent. If the device is a SATA device, a PHY reset will
  3331. * be sent.
  3332. *
  3333. * Return value:
  3334. * 0 on success / non-zero on failure
  3335. **/
  3336. static int ipr_device_reset(struct ipr_ioa_cfg *ioa_cfg,
  3337. struct ipr_resource_entry *res)
  3338. {
  3339. struct ipr_cmnd *ipr_cmd;
  3340. struct ipr_ioarcb *ioarcb;
  3341. struct ipr_cmd_pkt *cmd_pkt;
  3342. struct ipr_ioarcb_ata_regs *regs;
  3343. u32 ioasc;
  3344. ENTER;
  3345. ipr_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
  3346. ioarcb = &ipr_cmd->ioarcb;
  3347. cmd_pkt = &ioarcb->cmd_pkt;
  3348. regs = &ioarcb->add_data.u.regs;
  3349. ioarcb->res_handle = res->cfgte.res_handle;
  3350. cmd_pkt->request_type = IPR_RQTYPE_IOACMD;
  3351. cmd_pkt->cdb[0] = IPR_RESET_DEVICE;
  3352. if (ipr_is_gata(res)) {
  3353. cmd_pkt->cdb[2] = IPR_ATA_PHY_RESET;
  3354. ioarcb->add_cmd_parms_len = cpu_to_be32(sizeof(regs->flags));
  3355. regs->flags |= IPR_ATA_FLAG_STATUS_ON_GOOD_COMPLETION;
  3356. }
  3357. ipr_send_blocking_cmd(ipr_cmd, ipr_timeout, IPR_DEVICE_RESET_TIMEOUT);
  3358. ioasc = be32_to_cpu(ipr_cmd->ioasa.ioasc);
  3359. list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
  3360. if (ipr_is_gata(res) && res->sata_port && ioasc != IPR_IOASC_IOA_WAS_RESET)
  3361. memcpy(&res->sata_port->ioasa, &ipr_cmd->ioasa.u.gata,
  3362. sizeof(struct ipr_ioasa_gata));
  3363. LEAVE;
  3364. return (IPR_IOASC_SENSE_KEY(ioasc) ? -EIO : 0);
  3365. }
  3366. /**
  3367. * ipr_sata_reset - Reset the SATA port
  3368. * @link: SATA link to reset
  3369. * @classes: class of the attached device
  3370. *
  3371. * This function issues a SATA phy reset to the affected ATA link.
  3372. *
  3373. * Return value:
  3374. * 0 on success / non-zero on failure
  3375. **/
  3376. static int ipr_sata_reset(struct ata_link *link, unsigned int *classes,
  3377. unsigned long deadline)
  3378. {
  3379. struct ipr_sata_port *sata_port = link->ap->private_data;
  3380. struct ipr_ioa_cfg *ioa_cfg = sata_port->ioa_cfg;
  3381. struct ipr_resource_entry *res;
  3382. unsigned long lock_flags = 0;
  3383. int rc = -ENXIO;
  3384. ENTER;
  3385. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  3386. while(ioa_cfg->in_reset_reload) {
  3387. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  3388. wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
  3389. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  3390. }
  3391. res = sata_port->res;
  3392. if (res) {
  3393. rc = ipr_device_reset(ioa_cfg, res);
  3394. switch(res->cfgte.proto) {
  3395. case IPR_PROTO_SATA:
  3396. case IPR_PROTO_SAS_STP:
  3397. *classes = ATA_DEV_ATA;
  3398. break;
  3399. case IPR_PROTO_SATA_ATAPI:
  3400. case IPR_PROTO_SAS_STP_ATAPI:
  3401. *classes = ATA_DEV_ATAPI;
  3402. break;
  3403. default:
  3404. *classes = ATA_DEV_UNKNOWN;
  3405. break;
  3406. };
  3407. }
  3408. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  3409. LEAVE;
  3410. return rc;
  3411. }
  3412. /**
  3413. * ipr_eh_dev_reset - Reset the device
  3414. * @scsi_cmd: scsi command struct
  3415. *
  3416. * This function issues a device reset to the affected device.
  3417. * A LUN reset will be sent to the device first. If that does
  3418. * not work, a target reset will be sent.
  3419. *
  3420. * Return value:
  3421. * SUCCESS / FAILED
  3422. **/
  3423. static int __ipr_eh_dev_reset(struct scsi_cmnd * scsi_cmd)
  3424. {
  3425. struct ipr_cmnd *ipr_cmd;
  3426. struct ipr_ioa_cfg *ioa_cfg;
  3427. struct ipr_resource_entry *res;
  3428. struct ata_port *ap;
  3429. int rc = 0;
  3430. ENTER;
  3431. ioa_cfg = (struct ipr_ioa_cfg *) scsi_cmd->device->host->hostdata;
  3432. res = scsi_cmd->device->hostdata;
  3433. if (!res)
  3434. return FAILED;
  3435. /*
  3436. * If we are currently going through reset/reload, return failed. This will force the
  3437. * mid-layer to call ipr_eh_host_reset, which will then go to sleep and wait for the
  3438. * reset to complete
  3439. */
  3440. if (ioa_cfg->in_reset_reload)
  3441. return FAILED;
  3442. if (ioa_cfg->ioa_is_dead)
  3443. return FAILED;
  3444. list_for_each_entry(ipr_cmd, &ioa_cfg->pending_q, queue) {
  3445. if (ipr_cmd->ioarcb.res_handle == res->cfgte.res_handle) {
  3446. if (ipr_cmd->scsi_cmd)
  3447. ipr_cmd->done = ipr_scsi_eh_done;
  3448. if (ipr_cmd->qc)
  3449. ipr_cmd->done = ipr_sata_eh_done;
  3450. if (ipr_cmd->qc && !(ipr_cmd->qc->flags & ATA_QCFLAG_FAILED)) {
  3451. ipr_cmd->qc->err_mask |= AC_ERR_TIMEOUT;
  3452. ipr_cmd->qc->flags |= ATA_QCFLAG_FAILED;
  3453. }
  3454. }
  3455. }
  3456. res->resetting_device = 1;
  3457. scmd_printk(KERN_ERR, scsi_cmd, "Resetting device\n");
  3458. if (ipr_is_gata(res) && res->sata_port) {
  3459. ap = res->sata_port->ap;
  3460. spin_unlock_irq(scsi_cmd->device->host->host_lock);
  3461. ata_std_error_handler(ap);
  3462. spin_lock_irq(scsi_cmd->device->host->host_lock);
  3463. list_for_each_entry(ipr_cmd, &ioa_cfg->pending_q, queue) {
  3464. if (ipr_cmd->ioarcb.res_handle == res->cfgte.res_handle) {
  3465. rc = -EIO;
  3466. break;
  3467. }
  3468. }
  3469. } else
  3470. rc = ipr_device_reset(ioa_cfg, res);
  3471. res->resetting_device = 0;
  3472. LEAVE;
  3473. return (rc ? FAILED : SUCCESS);
  3474. }
  3475. static int ipr_eh_dev_reset(struct scsi_cmnd * cmd)
  3476. {
  3477. int rc;
  3478. spin_lock_irq(cmd->device->host->host_lock);
  3479. rc = __ipr_eh_dev_reset(cmd);
  3480. spin_unlock_irq(cmd->device->host->host_lock);
  3481. return rc;
  3482. }
  3483. /**
  3484. * ipr_bus_reset_done - Op done function for bus reset.
  3485. * @ipr_cmd: ipr command struct
  3486. *
  3487. * This function is the op done function for a bus reset
  3488. *
  3489. * Return value:
  3490. * none
  3491. **/
  3492. static void ipr_bus_reset_done(struct ipr_cmnd *ipr_cmd)
  3493. {
  3494. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  3495. struct ipr_resource_entry *res;
  3496. ENTER;
  3497. list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
  3498. if (!memcmp(&res->cfgte.res_handle, &ipr_cmd->ioarcb.res_handle,
  3499. sizeof(res->cfgte.res_handle))) {
  3500. scsi_report_bus_reset(ioa_cfg->host, res->cfgte.res_addr.bus);
  3501. break;
  3502. }
  3503. }
  3504. /*
  3505. * If abort has not completed, indicate the reset has, else call the
  3506. * abort's done function to wake the sleeping eh thread
  3507. */
  3508. if (ipr_cmd->sibling->sibling)
  3509. ipr_cmd->sibling->sibling = NULL;
  3510. else
  3511. ipr_cmd->sibling->done(ipr_cmd->sibling);
  3512. list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
  3513. LEAVE;
  3514. }
  3515. /**
  3516. * ipr_abort_timeout - An abort task has timed out
  3517. * @ipr_cmd: ipr command struct
  3518. *
  3519. * This function handles when an abort task times out. If this
  3520. * happens we issue a bus reset since we have resources tied
  3521. * up that must be freed before returning to the midlayer.
  3522. *
  3523. * Return value:
  3524. * none
  3525. **/
  3526. static void ipr_abort_timeout(struct ipr_cmnd *ipr_cmd)
  3527. {
  3528. struct ipr_cmnd *reset_cmd;
  3529. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  3530. struct ipr_cmd_pkt *cmd_pkt;
  3531. unsigned long lock_flags = 0;
  3532. ENTER;
  3533. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  3534. if (ipr_cmd->completion.done || ioa_cfg->in_reset_reload) {
  3535. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  3536. return;
  3537. }
  3538. sdev_printk(KERN_ERR, ipr_cmd->u.sdev, "Abort timed out. Resetting bus.\n");
  3539. reset_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
  3540. ipr_cmd->sibling = reset_cmd;
  3541. reset_cmd->sibling = ipr_cmd;
  3542. reset_cmd->ioarcb.res_handle = ipr_cmd->ioarcb.res_handle;
  3543. cmd_pkt = &reset_cmd->ioarcb.cmd_pkt;
  3544. cmd_pkt->request_type = IPR_RQTYPE_IOACMD;
  3545. cmd_pkt->cdb[0] = IPR_RESET_DEVICE;
  3546. cmd_pkt->cdb[2] = IPR_RESET_TYPE_SELECT | IPR_BUS_RESET;
  3547. ipr_do_req(reset_cmd, ipr_bus_reset_done, ipr_timeout, IPR_DEVICE_RESET_TIMEOUT);
  3548. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  3549. LEAVE;
  3550. }
  3551. /**
  3552. * ipr_cancel_op - Cancel specified op
  3553. * @scsi_cmd: scsi command struct
  3554. *
  3555. * This function cancels specified op.
  3556. *
  3557. * Return value:
  3558. * SUCCESS / FAILED
  3559. **/
  3560. static int ipr_cancel_op(struct scsi_cmnd * scsi_cmd)
  3561. {
  3562. struct ipr_cmnd *ipr_cmd;
  3563. struct ipr_ioa_cfg *ioa_cfg;
  3564. struct ipr_resource_entry *res;
  3565. struct ipr_cmd_pkt *cmd_pkt;
  3566. u32 ioasc;
  3567. int op_found = 0;
  3568. ENTER;
  3569. ioa_cfg = (struct ipr_ioa_cfg *)scsi_cmd->device->host->hostdata;
  3570. res = scsi_cmd->device->hostdata;
  3571. /* If we are currently going through reset/reload, return failed.
  3572. * This will force the mid-layer to call ipr_eh_host_reset,
  3573. * which will then go to sleep and wait for the reset to complete
  3574. */
  3575. if (ioa_cfg->in_reset_reload || ioa_cfg->ioa_is_dead)
  3576. return FAILED;
  3577. if (!res || !ipr_is_gscsi(res))
  3578. return FAILED;
  3579. list_for_each_entry(ipr_cmd, &ioa_cfg->pending_q, queue) {
  3580. if (ipr_cmd->scsi_cmd == scsi_cmd) {
  3581. ipr_cmd->done = ipr_scsi_eh_done;
  3582. op_found = 1;
  3583. break;
  3584. }
  3585. }
  3586. if (!op_found)
  3587. return SUCCESS;
  3588. ipr_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
  3589. ipr_cmd->ioarcb.res_handle = res->cfgte.res_handle;
  3590. cmd_pkt = &ipr_cmd->ioarcb.cmd_pkt;
  3591. cmd_pkt->request_type = IPR_RQTYPE_IOACMD;
  3592. cmd_pkt->cdb[0] = IPR_CANCEL_ALL_REQUESTS;
  3593. ipr_cmd->u.sdev = scsi_cmd->device;
  3594. scmd_printk(KERN_ERR, scsi_cmd, "Aborting command: %02X\n",
  3595. scsi_cmd->cmnd[0]);
  3596. ipr_send_blocking_cmd(ipr_cmd, ipr_abort_timeout, IPR_CANCEL_ALL_TIMEOUT);
  3597. ioasc = be32_to_cpu(ipr_cmd->ioasa.ioasc);
  3598. /*
  3599. * If the abort task timed out and we sent a bus reset, we will get
  3600. * one the following responses to the abort
  3601. */
  3602. if (ioasc == IPR_IOASC_BUS_WAS_RESET || ioasc == IPR_IOASC_SYNC_REQUIRED) {
  3603. ioasc = 0;
  3604. ipr_trace;
  3605. }
  3606. list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
  3607. if (!ipr_is_naca_model(res))
  3608. res->needs_sync_complete = 1;
  3609. LEAVE;
  3610. return (IPR_IOASC_SENSE_KEY(ioasc) ? FAILED : SUCCESS);
  3611. }
  3612. /**
  3613. * ipr_eh_abort - Abort a single op
  3614. * @scsi_cmd: scsi command struct
  3615. *
  3616. * Return value:
  3617. * SUCCESS / FAILED
  3618. **/
  3619. static int ipr_eh_abort(struct scsi_cmnd * scsi_cmd)
  3620. {
  3621. unsigned long flags;
  3622. int rc;
  3623. ENTER;
  3624. spin_lock_irqsave(scsi_cmd->device->host->host_lock, flags);
  3625. rc = ipr_cancel_op(scsi_cmd);
  3626. spin_unlock_irqrestore(scsi_cmd->device->host->host_lock, flags);
  3627. LEAVE;
  3628. return rc;
  3629. }
  3630. /**
  3631. * ipr_handle_other_interrupt - Handle "other" interrupts
  3632. * @ioa_cfg: ioa config struct
  3633. * @int_reg: interrupt register
  3634. *
  3635. * Return value:
  3636. * IRQ_NONE / IRQ_HANDLED
  3637. **/
  3638. static irqreturn_t ipr_handle_other_interrupt(struct ipr_ioa_cfg *ioa_cfg,
  3639. volatile u32 int_reg)
  3640. {
  3641. irqreturn_t rc = IRQ_HANDLED;
  3642. if (int_reg & IPR_PCII_IOA_TRANS_TO_OPER) {
  3643. /* Mask the interrupt */
  3644. writel(IPR_PCII_IOA_TRANS_TO_OPER, ioa_cfg->regs.set_interrupt_mask_reg);
  3645. /* Clear the interrupt */
  3646. writel(IPR_PCII_IOA_TRANS_TO_OPER, ioa_cfg->regs.clr_interrupt_reg);
  3647. int_reg = readl(ioa_cfg->regs.sense_interrupt_reg);
  3648. list_del(&ioa_cfg->reset_cmd->queue);
  3649. del_timer(&ioa_cfg->reset_cmd->timer);
  3650. ipr_reset_ioa_job(ioa_cfg->reset_cmd);
  3651. } else {
  3652. if (int_reg & IPR_PCII_IOA_UNIT_CHECKED)
  3653. ioa_cfg->ioa_unit_checked = 1;
  3654. else
  3655. dev_err(&ioa_cfg->pdev->dev,
  3656. "Permanent IOA failure. 0x%08X\n", int_reg);
  3657. if (WAIT_FOR_DUMP == ioa_cfg->sdt_state)
  3658. ioa_cfg->sdt_state = GET_DUMP;
  3659. ipr_mask_and_clear_interrupts(ioa_cfg, ~0);
  3660. ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
  3661. }
  3662. return rc;
  3663. }
  3664. /**
  3665. * ipr_isr - Interrupt service routine
  3666. * @irq: irq number
  3667. * @devp: pointer to ioa config struct
  3668. *
  3669. * Return value:
  3670. * IRQ_NONE / IRQ_HANDLED
  3671. **/
  3672. static irqreturn_t ipr_isr(int irq, void *devp)
  3673. {
  3674. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)devp;
  3675. unsigned long lock_flags = 0;
  3676. volatile u32 int_reg, int_mask_reg;
  3677. u32 ioasc;
  3678. u16 cmd_index;
  3679. struct ipr_cmnd *ipr_cmd;
  3680. irqreturn_t rc = IRQ_NONE;
  3681. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  3682. /* If interrupts are disabled, ignore the interrupt */
  3683. if (!ioa_cfg->allow_interrupts) {
  3684. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  3685. return IRQ_NONE;
  3686. }
  3687. int_mask_reg = readl(ioa_cfg->regs.sense_interrupt_mask_reg);
  3688. int_reg = readl(ioa_cfg->regs.sense_interrupt_reg) & ~int_mask_reg;
  3689. /* If an interrupt on the adapter did not occur, ignore it */
  3690. if (unlikely((int_reg & IPR_PCII_OPER_INTERRUPTS) == 0)) {
  3691. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  3692. return IRQ_NONE;
  3693. }
  3694. while (1) {
  3695. ipr_cmd = NULL;
  3696. while ((be32_to_cpu(*ioa_cfg->hrrq_curr) & IPR_HRRQ_TOGGLE_BIT) ==
  3697. ioa_cfg->toggle_bit) {
  3698. cmd_index = (be32_to_cpu(*ioa_cfg->hrrq_curr) &
  3699. IPR_HRRQ_REQ_RESP_HANDLE_MASK) >> IPR_HRRQ_REQ_RESP_HANDLE_SHIFT;
  3700. if (unlikely(cmd_index >= IPR_NUM_CMD_BLKS)) {
  3701. ioa_cfg->errors_logged++;
  3702. dev_err(&ioa_cfg->pdev->dev, "Invalid response handle from IOA\n");
  3703. if (WAIT_FOR_DUMP == ioa_cfg->sdt_state)
  3704. ioa_cfg->sdt_state = GET_DUMP;
  3705. ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
  3706. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  3707. return IRQ_HANDLED;
  3708. }
  3709. ipr_cmd = ioa_cfg->ipr_cmnd_list[cmd_index];
  3710. ioasc = be32_to_cpu(ipr_cmd->ioasa.ioasc);
  3711. ipr_trc_hook(ipr_cmd, IPR_TRACE_FINISH, ioasc);
  3712. list_del(&ipr_cmd->queue);
  3713. del_timer(&ipr_cmd->timer);
  3714. ipr_cmd->done(ipr_cmd);
  3715. rc = IRQ_HANDLED;
  3716. if (ioa_cfg->hrrq_curr < ioa_cfg->hrrq_end) {
  3717. ioa_cfg->hrrq_curr++;
  3718. } else {
  3719. ioa_cfg->hrrq_curr = ioa_cfg->hrrq_start;
  3720. ioa_cfg->toggle_bit ^= 1u;
  3721. }
  3722. }
  3723. if (ipr_cmd != NULL) {
  3724. /* Clear the PCI interrupt */
  3725. writel(IPR_PCII_HRRQ_UPDATED, ioa_cfg->regs.clr_interrupt_reg);
  3726. int_reg = readl(ioa_cfg->regs.sense_interrupt_reg) & ~int_mask_reg;
  3727. } else
  3728. break;
  3729. }
  3730. if (unlikely(rc == IRQ_NONE))
  3731. rc = ipr_handle_other_interrupt(ioa_cfg, int_reg);
  3732. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  3733. return rc;
  3734. }
  3735. /**
  3736. * ipr_build_ioadl - Build a scatter/gather list and map the buffer
  3737. * @ioa_cfg: ioa config struct
  3738. * @ipr_cmd: ipr command struct
  3739. *
  3740. * Return value:
  3741. * 0 on success / -1 on failure
  3742. **/
  3743. static int ipr_build_ioadl(struct ipr_ioa_cfg *ioa_cfg,
  3744. struct ipr_cmnd *ipr_cmd)
  3745. {
  3746. int i, nseg;
  3747. struct scatterlist *sg;
  3748. u32 length;
  3749. u32 ioadl_flags = 0;
  3750. struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
  3751. struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
  3752. struct ipr_ioadl_desc *ioadl = ipr_cmd->ioadl;
  3753. length = scsi_bufflen(scsi_cmd);
  3754. if (!length)
  3755. return 0;
  3756. nseg = scsi_dma_map(scsi_cmd);
  3757. if (nseg < 0) {
  3758. dev_err(&ioa_cfg->pdev->dev, "pci_map_sg failed!\n");
  3759. return -1;
  3760. }
  3761. ipr_cmd->dma_use_sg = nseg;
  3762. if (scsi_cmd->sc_data_direction == DMA_TO_DEVICE) {
  3763. ioadl_flags = IPR_IOADL_FLAGS_WRITE;
  3764. ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
  3765. ioarcb->write_data_transfer_length = cpu_to_be32(length);
  3766. ioarcb->write_ioadl_len =
  3767. cpu_to_be32(sizeof(struct ipr_ioadl_desc) * ipr_cmd->dma_use_sg);
  3768. } else if (scsi_cmd->sc_data_direction == DMA_FROM_DEVICE) {
  3769. ioadl_flags = IPR_IOADL_FLAGS_READ;
  3770. ioarcb->read_data_transfer_length = cpu_to_be32(length);
  3771. ioarcb->read_ioadl_len =
  3772. cpu_to_be32(sizeof(struct ipr_ioadl_desc) * ipr_cmd->dma_use_sg);
  3773. }
  3774. if (ipr_cmd->dma_use_sg <= ARRAY_SIZE(ioarcb->add_data.u.ioadl)) {
  3775. ioadl = ioarcb->add_data.u.ioadl;
  3776. ioarcb->write_ioadl_addr =
  3777. cpu_to_be32(be32_to_cpu(ioarcb->ioarcb_host_pci_addr) +
  3778. offsetof(struct ipr_ioarcb, add_data));
  3779. ioarcb->read_ioadl_addr = ioarcb->write_ioadl_addr;
  3780. }
  3781. scsi_for_each_sg(scsi_cmd, sg, ipr_cmd->dma_use_sg, i) {
  3782. ioadl[i].flags_and_data_len =
  3783. cpu_to_be32(ioadl_flags | sg_dma_len(sg));
  3784. ioadl[i].address = cpu_to_be32(sg_dma_address(sg));
  3785. }
  3786. ioadl[i-1].flags_and_data_len |= cpu_to_be32(IPR_IOADL_FLAGS_LAST);
  3787. return 0;
  3788. }
  3789. /**
  3790. * ipr_get_task_attributes - Translate SPI Q-Tag to task attributes
  3791. * @scsi_cmd: scsi command struct
  3792. *
  3793. * Return value:
  3794. * task attributes
  3795. **/
  3796. static u8 ipr_get_task_attributes(struct scsi_cmnd *scsi_cmd)
  3797. {
  3798. u8 tag[2];
  3799. u8 rc = IPR_FLAGS_LO_UNTAGGED_TASK;
  3800. if (scsi_populate_tag_msg(scsi_cmd, tag)) {
  3801. switch (tag[0]) {
  3802. case MSG_SIMPLE_TAG:
  3803. rc = IPR_FLAGS_LO_SIMPLE_TASK;
  3804. break;
  3805. case MSG_HEAD_TAG:
  3806. rc = IPR_FLAGS_LO_HEAD_OF_Q_TASK;
  3807. break;
  3808. case MSG_ORDERED_TAG:
  3809. rc = IPR_FLAGS_LO_ORDERED_TASK;
  3810. break;
  3811. };
  3812. }
  3813. return rc;
  3814. }
  3815. /**
  3816. * ipr_erp_done - Process completion of ERP for a device
  3817. * @ipr_cmd: ipr command struct
  3818. *
  3819. * This function copies the sense buffer into the scsi_cmd
  3820. * struct and pushes the scsi_done function.
  3821. *
  3822. * Return value:
  3823. * nothing
  3824. **/
  3825. static void ipr_erp_done(struct ipr_cmnd *ipr_cmd)
  3826. {
  3827. struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
  3828. struct ipr_resource_entry *res = scsi_cmd->device->hostdata;
  3829. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  3830. u32 ioasc = be32_to_cpu(ipr_cmd->ioasa.ioasc);
  3831. if (IPR_IOASC_SENSE_KEY(ioasc) > 0) {
  3832. scsi_cmd->result |= (DID_ERROR << 16);
  3833. scmd_printk(KERN_ERR, scsi_cmd,
  3834. "Request Sense failed with IOASC: 0x%08X\n", ioasc);
  3835. } else {
  3836. memcpy(scsi_cmd->sense_buffer, ipr_cmd->sense_buffer,
  3837. SCSI_SENSE_BUFFERSIZE);
  3838. }
  3839. if (res) {
  3840. if (!ipr_is_naca_model(res))
  3841. res->needs_sync_complete = 1;
  3842. res->in_erp = 0;
  3843. }
  3844. scsi_dma_unmap(ipr_cmd->scsi_cmd);
  3845. list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
  3846. scsi_cmd->scsi_done(scsi_cmd);
  3847. }
  3848. /**
  3849. * ipr_reinit_ipr_cmnd_for_erp - Re-initialize a cmnd block to be used for ERP
  3850. * @ipr_cmd: ipr command struct
  3851. *
  3852. * Return value:
  3853. * none
  3854. **/
  3855. static void ipr_reinit_ipr_cmnd_for_erp(struct ipr_cmnd *ipr_cmd)
  3856. {
  3857. struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
  3858. struct ipr_ioasa *ioasa = &ipr_cmd->ioasa;
  3859. dma_addr_t dma_addr = be32_to_cpu(ioarcb->ioarcb_host_pci_addr);
  3860. memset(&ioarcb->cmd_pkt, 0, sizeof(struct ipr_cmd_pkt));
  3861. ioarcb->write_data_transfer_length = 0;
  3862. ioarcb->read_data_transfer_length = 0;
  3863. ioarcb->write_ioadl_len = 0;
  3864. ioarcb->read_ioadl_len = 0;
  3865. ioasa->ioasc = 0;
  3866. ioasa->residual_data_len = 0;
  3867. ioarcb->write_ioadl_addr =
  3868. cpu_to_be32(dma_addr + offsetof(struct ipr_cmnd, ioadl));
  3869. ioarcb->read_ioadl_addr = ioarcb->write_ioadl_addr;
  3870. }
  3871. /**
  3872. * ipr_erp_request_sense - Send request sense to a device
  3873. * @ipr_cmd: ipr command struct
  3874. *
  3875. * This function sends a request sense to a device as a result
  3876. * of a check condition.
  3877. *
  3878. * Return value:
  3879. * nothing
  3880. **/
  3881. static void ipr_erp_request_sense(struct ipr_cmnd *ipr_cmd)
  3882. {
  3883. struct ipr_cmd_pkt *cmd_pkt = &ipr_cmd->ioarcb.cmd_pkt;
  3884. u32 ioasc = be32_to_cpu(ipr_cmd->ioasa.ioasc);
  3885. if (IPR_IOASC_SENSE_KEY(ioasc) > 0) {
  3886. ipr_erp_done(ipr_cmd);
  3887. return;
  3888. }
  3889. ipr_reinit_ipr_cmnd_for_erp(ipr_cmd);
  3890. cmd_pkt->request_type = IPR_RQTYPE_SCSICDB;
  3891. cmd_pkt->cdb[0] = REQUEST_SENSE;
  3892. cmd_pkt->cdb[4] = SCSI_SENSE_BUFFERSIZE;
  3893. cmd_pkt->flags_hi |= IPR_FLAGS_HI_SYNC_OVERRIDE;
  3894. cmd_pkt->flags_hi |= IPR_FLAGS_HI_NO_ULEN_CHK;
  3895. cmd_pkt->timeout = cpu_to_be16(IPR_REQUEST_SENSE_TIMEOUT / HZ);
  3896. ipr_cmd->ioadl[0].flags_and_data_len =
  3897. cpu_to_be32(IPR_IOADL_FLAGS_READ_LAST | SCSI_SENSE_BUFFERSIZE);
  3898. ipr_cmd->ioadl[0].address =
  3899. cpu_to_be32(ipr_cmd->sense_buffer_dma);
  3900. ipr_cmd->ioarcb.read_ioadl_len =
  3901. cpu_to_be32(sizeof(struct ipr_ioadl_desc));
  3902. ipr_cmd->ioarcb.read_data_transfer_length =
  3903. cpu_to_be32(SCSI_SENSE_BUFFERSIZE);
  3904. ipr_do_req(ipr_cmd, ipr_erp_done, ipr_timeout,
  3905. IPR_REQUEST_SENSE_TIMEOUT * 2);
  3906. }
  3907. /**
  3908. * ipr_erp_cancel_all - Send cancel all to a device
  3909. * @ipr_cmd: ipr command struct
  3910. *
  3911. * This function sends a cancel all to a device to clear the
  3912. * queue. If we are running TCQ on the device, QERR is set to 1,
  3913. * which means all outstanding ops have been dropped on the floor.
  3914. * Cancel all will return them to us.
  3915. *
  3916. * Return value:
  3917. * nothing
  3918. **/
  3919. static void ipr_erp_cancel_all(struct ipr_cmnd *ipr_cmd)
  3920. {
  3921. struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
  3922. struct ipr_resource_entry *res = scsi_cmd->device->hostdata;
  3923. struct ipr_cmd_pkt *cmd_pkt;
  3924. res->in_erp = 1;
  3925. ipr_reinit_ipr_cmnd_for_erp(ipr_cmd);
  3926. if (!scsi_get_tag_type(scsi_cmd->device)) {
  3927. ipr_erp_request_sense(ipr_cmd);
  3928. return;
  3929. }
  3930. cmd_pkt = &ipr_cmd->ioarcb.cmd_pkt;
  3931. cmd_pkt->request_type = IPR_RQTYPE_IOACMD;
  3932. cmd_pkt->cdb[0] = IPR_CANCEL_ALL_REQUESTS;
  3933. ipr_do_req(ipr_cmd, ipr_erp_request_sense, ipr_timeout,
  3934. IPR_CANCEL_ALL_TIMEOUT);
  3935. }
  3936. /**
  3937. * ipr_dump_ioasa - Dump contents of IOASA
  3938. * @ioa_cfg: ioa config struct
  3939. * @ipr_cmd: ipr command struct
  3940. * @res: resource entry struct
  3941. *
  3942. * This function is invoked by the interrupt handler when ops
  3943. * fail. It will log the IOASA if appropriate. Only called
  3944. * for GPDD ops.
  3945. *
  3946. * Return value:
  3947. * none
  3948. **/
  3949. static void ipr_dump_ioasa(struct ipr_ioa_cfg *ioa_cfg,
  3950. struct ipr_cmnd *ipr_cmd, struct ipr_resource_entry *res)
  3951. {
  3952. int i;
  3953. u16 data_len;
  3954. u32 ioasc, fd_ioasc;
  3955. struct ipr_ioasa *ioasa = &ipr_cmd->ioasa;
  3956. __be32 *ioasa_data = (__be32 *)ioasa;
  3957. int error_index;
  3958. ioasc = be32_to_cpu(ioasa->ioasc) & IPR_IOASC_IOASC_MASK;
  3959. fd_ioasc = be32_to_cpu(ioasa->fd_ioasc) & IPR_IOASC_IOASC_MASK;
  3960. if (0 == ioasc)
  3961. return;
  3962. if (ioa_cfg->log_level < IPR_DEFAULT_LOG_LEVEL)
  3963. return;
  3964. if (ioasc == IPR_IOASC_BUS_WAS_RESET && fd_ioasc)
  3965. error_index = ipr_get_error(fd_ioasc);
  3966. else
  3967. error_index = ipr_get_error(ioasc);
  3968. if (ioa_cfg->log_level < IPR_MAX_LOG_LEVEL) {
  3969. /* Don't log an error if the IOA already logged one */
  3970. if (ioasa->ilid != 0)
  3971. return;
  3972. if (!ipr_is_gscsi(res))
  3973. return;
  3974. if (ipr_error_table[error_index].log_ioasa == 0)
  3975. return;
  3976. }
  3977. ipr_res_err(ioa_cfg, res, "%s\n", ipr_error_table[error_index].error);
  3978. if (sizeof(struct ipr_ioasa) < be16_to_cpu(ioasa->ret_stat_len))
  3979. data_len = sizeof(struct ipr_ioasa);
  3980. else
  3981. data_len = be16_to_cpu(ioasa->ret_stat_len);
  3982. ipr_err("IOASA Dump:\n");
  3983. for (i = 0; i < data_len / 4; i += 4) {
  3984. ipr_err("%08X: %08X %08X %08X %08X\n", i*4,
  3985. be32_to_cpu(ioasa_data[i]),
  3986. be32_to_cpu(ioasa_data[i+1]),
  3987. be32_to_cpu(ioasa_data[i+2]),
  3988. be32_to_cpu(ioasa_data[i+3]));
  3989. }
  3990. }
  3991. /**
  3992. * ipr_gen_sense - Generate SCSI sense data from an IOASA
  3993. * @ioasa: IOASA
  3994. * @sense_buf: sense data buffer
  3995. *
  3996. * Return value:
  3997. * none
  3998. **/
  3999. static void ipr_gen_sense(struct ipr_cmnd *ipr_cmd)
  4000. {
  4001. u32 failing_lba;
  4002. u8 *sense_buf = ipr_cmd->scsi_cmd->sense_buffer;
  4003. struct ipr_resource_entry *res = ipr_cmd->scsi_cmd->device->hostdata;
  4004. struct ipr_ioasa *ioasa = &ipr_cmd->ioasa;
  4005. u32 ioasc = be32_to_cpu(ioasa->ioasc);
  4006. memset(sense_buf, 0, SCSI_SENSE_BUFFERSIZE);
  4007. if (ioasc >= IPR_FIRST_DRIVER_IOASC)
  4008. return;
  4009. ipr_cmd->scsi_cmd->result = SAM_STAT_CHECK_CONDITION;
  4010. if (ipr_is_vset_device(res) &&
  4011. ioasc == IPR_IOASC_MED_DO_NOT_REALLOC &&
  4012. ioasa->u.vset.failing_lba_hi != 0) {
  4013. sense_buf[0] = 0x72;
  4014. sense_buf[1] = IPR_IOASC_SENSE_KEY(ioasc);
  4015. sense_buf[2] = IPR_IOASC_SENSE_CODE(ioasc);
  4016. sense_buf[3] = IPR_IOASC_SENSE_QUAL(ioasc);
  4017. sense_buf[7] = 12;
  4018. sense_buf[8] = 0;
  4019. sense_buf[9] = 0x0A;
  4020. sense_buf[10] = 0x80;
  4021. failing_lba = be32_to_cpu(ioasa->u.vset.failing_lba_hi);
  4022. sense_buf[12] = (failing_lba & 0xff000000) >> 24;
  4023. sense_buf[13] = (failing_lba & 0x00ff0000) >> 16;
  4024. sense_buf[14] = (failing_lba & 0x0000ff00) >> 8;
  4025. sense_buf[15] = failing_lba & 0x000000ff;
  4026. failing_lba = be32_to_cpu(ioasa->u.vset.failing_lba_lo);
  4027. sense_buf[16] = (failing_lba & 0xff000000) >> 24;
  4028. sense_buf[17] = (failing_lba & 0x00ff0000) >> 16;
  4029. sense_buf[18] = (failing_lba & 0x0000ff00) >> 8;
  4030. sense_buf[19] = failing_lba & 0x000000ff;
  4031. } else {
  4032. sense_buf[0] = 0x70;
  4033. sense_buf[2] = IPR_IOASC_SENSE_KEY(ioasc);
  4034. sense_buf[12] = IPR_IOASC_SENSE_CODE(ioasc);
  4035. sense_buf[13] = IPR_IOASC_SENSE_QUAL(ioasc);
  4036. /* Illegal request */
  4037. if ((IPR_IOASC_SENSE_KEY(ioasc) == 0x05) &&
  4038. (be32_to_cpu(ioasa->ioasc_specific) & IPR_FIELD_POINTER_VALID)) {
  4039. sense_buf[7] = 10; /* additional length */
  4040. /* IOARCB was in error */
  4041. if (IPR_IOASC_SENSE_CODE(ioasc) == 0x24)
  4042. sense_buf[15] = 0xC0;
  4043. else /* Parameter data was invalid */
  4044. sense_buf[15] = 0x80;
  4045. sense_buf[16] =
  4046. ((IPR_FIELD_POINTER_MASK &
  4047. be32_to_cpu(ioasa->ioasc_specific)) >> 8) & 0xff;
  4048. sense_buf[17] =
  4049. (IPR_FIELD_POINTER_MASK &
  4050. be32_to_cpu(ioasa->ioasc_specific)) & 0xff;
  4051. } else {
  4052. if (ioasc == IPR_IOASC_MED_DO_NOT_REALLOC) {
  4053. if (ipr_is_vset_device(res))
  4054. failing_lba = be32_to_cpu(ioasa->u.vset.failing_lba_lo);
  4055. else
  4056. failing_lba = be32_to_cpu(ioasa->u.dasd.failing_lba);
  4057. sense_buf[0] |= 0x80; /* Or in the Valid bit */
  4058. sense_buf[3] = (failing_lba & 0xff000000) >> 24;
  4059. sense_buf[4] = (failing_lba & 0x00ff0000) >> 16;
  4060. sense_buf[5] = (failing_lba & 0x0000ff00) >> 8;
  4061. sense_buf[6] = failing_lba & 0x000000ff;
  4062. }
  4063. sense_buf[7] = 6; /* additional length */
  4064. }
  4065. }
  4066. }
  4067. /**
  4068. * ipr_get_autosense - Copy autosense data to sense buffer
  4069. * @ipr_cmd: ipr command struct
  4070. *
  4071. * This function copies the autosense buffer to the buffer
  4072. * in the scsi_cmd, if there is autosense available.
  4073. *
  4074. * Return value:
  4075. * 1 if autosense was available / 0 if not
  4076. **/
  4077. static int ipr_get_autosense(struct ipr_cmnd *ipr_cmd)
  4078. {
  4079. struct ipr_ioasa *ioasa = &ipr_cmd->ioasa;
  4080. if ((be32_to_cpu(ioasa->ioasc_specific) & IPR_AUTOSENSE_VALID) == 0)
  4081. return 0;
  4082. memcpy(ipr_cmd->scsi_cmd->sense_buffer, ioasa->auto_sense.data,
  4083. min_t(u16, be16_to_cpu(ioasa->auto_sense.auto_sense_len),
  4084. SCSI_SENSE_BUFFERSIZE));
  4085. return 1;
  4086. }
  4087. /**
  4088. * ipr_erp_start - Process an error response for a SCSI op
  4089. * @ioa_cfg: ioa config struct
  4090. * @ipr_cmd: ipr command struct
  4091. *
  4092. * This function determines whether or not to initiate ERP
  4093. * on the affected device.
  4094. *
  4095. * Return value:
  4096. * nothing
  4097. **/
  4098. static void ipr_erp_start(struct ipr_ioa_cfg *ioa_cfg,
  4099. struct ipr_cmnd *ipr_cmd)
  4100. {
  4101. struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
  4102. struct ipr_resource_entry *res = scsi_cmd->device->hostdata;
  4103. u32 ioasc = be32_to_cpu(ipr_cmd->ioasa.ioasc);
  4104. u32 masked_ioasc = ioasc & IPR_IOASC_IOASC_MASK;
  4105. if (!res) {
  4106. ipr_scsi_eh_done(ipr_cmd);
  4107. return;
  4108. }
  4109. if (!ipr_is_gscsi(res) && masked_ioasc != IPR_IOASC_HW_DEV_BUS_STATUS)
  4110. ipr_gen_sense(ipr_cmd);
  4111. ipr_dump_ioasa(ioa_cfg, ipr_cmd, res);
  4112. switch (masked_ioasc) {
  4113. case IPR_IOASC_ABORTED_CMD_TERM_BY_HOST:
  4114. if (ipr_is_naca_model(res))
  4115. scsi_cmd->result |= (DID_ABORT << 16);
  4116. else
  4117. scsi_cmd->result |= (DID_IMM_RETRY << 16);
  4118. break;
  4119. case IPR_IOASC_IR_RESOURCE_HANDLE:
  4120. case IPR_IOASC_IR_NO_CMDS_TO_2ND_IOA:
  4121. scsi_cmd->result |= (DID_NO_CONNECT << 16);
  4122. break;
  4123. case IPR_IOASC_HW_SEL_TIMEOUT:
  4124. scsi_cmd->result |= (DID_NO_CONNECT << 16);
  4125. if (!ipr_is_naca_model(res))
  4126. res->needs_sync_complete = 1;
  4127. break;
  4128. case IPR_IOASC_SYNC_REQUIRED:
  4129. if (!res->in_erp)
  4130. res->needs_sync_complete = 1;
  4131. scsi_cmd->result |= (DID_IMM_RETRY << 16);
  4132. break;
  4133. case IPR_IOASC_MED_DO_NOT_REALLOC: /* prevent retries */
  4134. case IPR_IOASA_IR_DUAL_IOA_DISABLED:
  4135. scsi_cmd->result |= (DID_PASSTHROUGH << 16);
  4136. break;
  4137. case IPR_IOASC_BUS_WAS_RESET:
  4138. case IPR_IOASC_BUS_WAS_RESET_BY_OTHER:
  4139. /*
  4140. * Report the bus reset and ask for a retry. The device
  4141. * will give CC/UA the next command.
  4142. */
  4143. if (!res->resetting_device)
  4144. scsi_report_bus_reset(ioa_cfg->host, scsi_cmd->device->channel);
  4145. scsi_cmd->result |= (DID_ERROR << 16);
  4146. if (!ipr_is_naca_model(res))
  4147. res->needs_sync_complete = 1;
  4148. break;
  4149. case IPR_IOASC_HW_DEV_BUS_STATUS:
  4150. scsi_cmd->result |= IPR_IOASC_SENSE_STATUS(ioasc);
  4151. if (IPR_IOASC_SENSE_STATUS(ioasc) == SAM_STAT_CHECK_CONDITION) {
  4152. if (!ipr_get_autosense(ipr_cmd)) {
  4153. if (!ipr_is_naca_model(res)) {
  4154. ipr_erp_cancel_all(ipr_cmd);
  4155. return;
  4156. }
  4157. }
  4158. }
  4159. if (!ipr_is_naca_model(res))
  4160. res->needs_sync_complete = 1;
  4161. break;
  4162. case IPR_IOASC_NR_INIT_CMD_REQUIRED:
  4163. break;
  4164. default:
  4165. if (IPR_IOASC_SENSE_KEY(ioasc) > RECOVERED_ERROR)
  4166. scsi_cmd->result |= (DID_ERROR << 16);
  4167. if (!ipr_is_vset_device(res) && !ipr_is_naca_model(res))
  4168. res->needs_sync_complete = 1;
  4169. break;
  4170. }
  4171. scsi_dma_unmap(ipr_cmd->scsi_cmd);
  4172. list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
  4173. scsi_cmd->scsi_done(scsi_cmd);
  4174. }
  4175. /**
  4176. * ipr_scsi_done - mid-layer done function
  4177. * @ipr_cmd: ipr command struct
  4178. *
  4179. * This function is invoked by the interrupt handler for
  4180. * ops generated by the SCSI mid-layer
  4181. *
  4182. * Return value:
  4183. * none
  4184. **/
  4185. static void ipr_scsi_done(struct ipr_cmnd *ipr_cmd)
  4186. {
  4187. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  4188. struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
  4189. u32 ioasc = be32_to_cpu(ipr_cmd->ioasa.ioasc);
  4190. scsi_set_resid(scsi_cmd, be32_to_cpu(ipr_cmd->ioasa.residual_data_len));
  4191. if (likely(IPR_IOASC_SENSE_KEY(ioasc) == 0)) {
  4192. scsi_dma_unmap(ipr_cmd->scsi_cmd);
  4193. list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
  4194. scsi_cmd->scsi_done(scsi_cmd);
  4195. } else
  4196. ipr_erp_start(ioa_cfg, ipr_cmd);
  4197. }
  4198. /**
  4199. * ipr_queuecommand - Queue a mid-layer request
  4200. * @scsi_cmd: scsi command struct
  4201. * @done: done function
  4202. *
  4203. * This function queues a request generated by the mid-layer.
  4204. *
  4205. * Return value:
  4206. * 0 on success
  4207. * SCSI_MLQUEUE_DEVICE_BUSY if device is busy
  4208. * SCSI_MLQUEUE_HOST_BUSY if host is busy
  4209. **/
  4210. static int ipr_queuecommand(struct scsi_cmnd *scsi_cmd,
  4211. void (*done) (struct scsi_cmnd *))
  4212. {
  4213. struct ipr_ioa_cfg *ioa_cfg;
  4214. struct ipr_resource_entry *res;
  4215. struct ipr_ioarcb *ioarcb;
  4216. struct ipr_cmnd *ipr_cmd;
  4217. int rc = 0;
  4218. scsi_cmd->scsi_done = done;
  4219. ioa_cfg = (struct ipr_ioa_cfg *)scsi_cmd->device->host->hostdata;
  4220. res = scsi_cmd->device->hostdata;
  4221. scsi_cmd->result = (DID_OK << 16);
  4222. /*
  4223. * We are currently blocking all devices due to a host reset
  4224. * We have told the host to stop giving us new requests, but
  4225. * ERP ops don't count. FIXME
  4226. */
  4227. if (unlikely(!ioa_cfg->allow_cmds && !ioa_cfg->ioa_is_dead))
  4228. return SCSI_MLQUEUE_HOST_BUSY;
  4229. /*
  4230. * FIXME - Create scsi_set_host_offline interface
  4231. * and the ioa_is_dead check can be removed
  4232. */
  4233. if (unlikely(ioa_cfg->ioa_is_dead || !res)) {
  4234. memset(scsi_cmd->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE);
  4235. scsi_cmd->result = (DID_NO_CONNECT << 16);
  4236. scsi_cmd->scsi_done(scsi_cmd);
  4237. return 0;
  4238. }
  4239. if (ipr_is_gata(res) && res->sata_port)
  4240. return ata_sas_queuecmd(scsi_cmd, done, res->sata_port->ap);
  4241. ipr_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
  4242. ioarcb = &ipr_cmd->ioarcb;
  4243. list_add_tail(&ipr_cmd->queue, &ioa_cfg->pending_q);
  4244. memcpy(ioarcb->cmd_pkt.cdb, scsi_cmd->cmnd, scsi_cmd->cmd_len);
  4245. ipr_cmd->scsi_cmd = scsi_cmd;
  4246. ioarcb->res_handle = res->cfgte.res_handle;
  4247. ipr_cmd->done = ipr_scsi_done;
  4248. ipr_trc_hook(ipr_cmd, IPR_TRACE_START, IPR_GET_PHYS_LOC(res->cfgte.res_addr));
  4249. if (ipr_is_gscsi(res) || ipr_is_vset_device(res)) {
  4250. if (scsi_cmd->underflow == 0)
  4251. ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_NO_ULEN_CHK;
  4252. if (res->needs_sync_complete) {
  4253. ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_SYNC_COMPLETE;
  4254. res->needs_sync_complete = 0;
  4255. }
  4256. ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_NO_LINK_DESC;
  4257. ioarcb->cmd_pkt.flags_lo |= IPR_FLAGS_LO_DELAY_AFTER_RST;
  4258. ioarcb->cmd_pkt.flags_lo |= IPR_FLAGS_LO_ALIGNED_BFR;
  4259. ioarcb->cmd_pkt.flags_lo |= ipr_get_task_attributes(scsi_cmd);
  4260. }
  4261. if (scsi_cmd->cmnd[0] >= 0xC0 &&
  4262. (!ipr_is_gscsi(res) || scsi_cmd->cmnd[0] == IPR_QUERY_RSRC_STATE))
  4263. ioarcb->cmd_pkt.request_type = IPR_RQTYPE_IOACMD;
  4264. if (likely(rc == 0))
  4265. rc = ipr_build_ioadl(ioa_cfg, ipr_cmd);
  4266. if (likely(rc == 0)) {
  4267. mb();
  4268. writel(be32_to_cpu(ipr_cmd->ioarcb.ioarcb_host_pci_addr),
  4269. ioa_cfg->regs.ioarrin_reg);
  4270. } else {
  4271. list_move_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
  4272. return SCSI_MLQUEUE_HOST_BUSY;
  4273. }
  4274. return 0;
  4275. }
  4276. /**
  4277. * ipr_ioctl - IOCTL handler
  4278. * @sdev: scsi device struct
  4279. * @cmd: IOCTL cmd
  4280. * @arg: IOCTL arg
  4281. *
  4282. * Return value:
  4283. * 0 on success / other on failure
  4284. **/
  4285. static int ipr_ioctl(struct scsi_device *sdev, int cmd, void __user *arg)
  4286. {
  4287. struct ipr_resource_entry *res;
  4288. res = (struct ipr_resource_entry *)sdev->hostdata;
  4289. if (res && ipr_is_gata(res)) {
  4290. if (cmd == HDIO_GET_IDENTITY)
  4291. return -ENOTTY;
  4292. return ata_scsi_ioctl(sdev, cmd, arg);
  4293. }
  4294. return -EINVAL;
  4295. }
  4296. /**
  4297. * ipr_info - Get information about the card/driver
  4298. * @scsi_host: scsi host struct
  4299. *
  4300. * Return value:
  4301. * pointer to buffer with description string
  4302. **/
  4303. static const char * ipr_ioa_info(struct Scsi_Host *host)
  4304. {
  4305. static char buffer[512];
  4306. struct ipr_ioa_cfg *ioa_cfg;
  4307. unsigned long lock_flags = 0;
  4308. ioa_cfg = (struct ipr_ioa_cfg *) host->hostdata;
  4309. spin_lock_irqsave(host->host_lock, lock_flags);
  4310. sprintf(buffer, "IBM %X Storage Adapter", ioa_cfg->type);
  4311. spin_unlock_irqrestore(host->host_lock, lock_flags);
  4312. return buffer;
  4313. }
  4314. static struct scsi_host_template driver_template = {
  4315. .module = THIS_MODULE,
  4316. .name = "IPR",
  4317. .info = ipr_ioa_info,
  4318. .ioctl = ipr_ioctl,
  4319. .queuecommand = ipr_queuecommand,
  4320. .eh_abort_handler = ipr_eh_abort,
  4321. .eh_device_reset_handler = ipr_eh_dev_reset,
  4322. .eh_host_reset_handler = ipr_eh_host_reset,
  4323. .slave_alloc = ipr_slave_alloc,
  4324. .slave_configure = ipr_slave_configure,
  4325. .slave_destroy = ipr_slave_destroy,
  4326. .target_alloc = ipr_target_alloc,
  4327. .target_destroy = ipr_target_destroy,
  4328. .change_queue_depth = ipr_change_queue_depth,
  4329. .change_queue_type = ipr_change_queue_type,
  4330. .bios_param = ipr_biosparam,
  4331. .can_queue = IPR_MAX_COMMANDS,
  4332. .this_id = -1,
  4333. .sg_tablesize = IPR_MAX_SGLIST,
  4334. .max_sectors = IPR_IOA_MAX_SECTORS,
  4335. .cmd_per_lun = IPR_MAX_CMD_PER_LUN,
  4336. .use_clustering = ENABLE_CLUSTERING,
  4337. .shost_attrs = ipr_ioa_attrs,
  4338. .sdev_attrs = ipr_dev_attrs,
  4339. .proc_name = IPR_NAME
  4340. };
  4341. /**
  4342. * ipr_ata_phy_reset - libata phy_reset handler
  4343. * @ap: ata port to reset
  4344. *
  4345. **/
  4346. static void ipr_ata_phy_reset(struct ata_port *ap)
  4347. {
  4348. unsigned long flags;
  4349. struct ipr_sata_port *sata_port = ap->private_data;
  4350. struct ipr_resource_entry *res = sata_port->res;
  4351. struct ipr_ioa_cfg *ioa_cfg = sata_port->ioa_cfg;
  4352. int rc;
  4353. ENTER;
  4354. spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
  4355. while(ioa_cfg->in_reset_reload) {
  4356. spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
  4357. wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
  4358. spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
  4359. }
  4360. if (!ioa_cfg->allow_cmds)
  4361. goto out_unlock;
  4362. rc = ipr_device_reset(ioa_cfg, res);
  4363. if (rc) {
  4364. ata_port_disable(ap);
  4365. goto out_unlock;
  4366. }
  4367. switch(res->cfgte.proto) {
  4368. case IPR_PROTO_SATA:
  4369. case IPR_PROTO_SAS_STP:
  4370. ap->link.device[0].class = ATA_DEV_ATA;
  4371. break;
  4372. case IPR_PROTO_SATA_ATAPI:
  4373. case IPR_PROTO_SAS_STP_ATAPI:
  4374. ap->link.device[0].class = ATA_DEV_ATAPI;
  4375. break;
  4376. default:
  4377. ap->link.device[0].class = ATA_DEV_UNKNOWN;
  4378. ata_port_disable(ap);
  4379. break;
  4380. };
  4381. out_unlock:
  4382. spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
  4383. LEAVE;
  4384. }
  4385. /**
  4386. * ipr_ata_post_internal - Cleanup after an internal command
  4387. * @qc: ATA queued command
  4388. *
  4389. * Return value:
  4390. * none
  4391. **/
  4392. static void ipr_ata_post_internal(struct ata_queued_cmd *qc)
  4393. {
  4394. struct ipr_sata_port *sata_port = qc->ap->private_data;
  4395. struct ipr_ioa_cfg *ioa_cfg = sata_port->ioa_cfg;
  4396. struct ipr_cmnd *ipr_cmd;
  4397. unsigned long flags;
  4398. spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
  4399. while(ioa_cfg->in_reset_reload) {
  4400. spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
  4401. wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
  4402. spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
  4403. }
  4404. list_for_each_entry(ipr_cmd, &ioa_cfg->pending_q, queue) {
  4405. if (ipr_cmd->qc == qc) {
  4406. ipr_device_reset(ioa_cfg, sata_port->res);
  4407. break;
  4408. }
  4409. }
  4410. spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
  4411. }
  4412. /**
  4413. * ipr_copy_sata_tf - Copy a SATA taskfile to an IOA data structure
  4414. * @regs: destination
  4415. * @tf: source ATA taskfile
  4416. *
  4417. * Return value:
  4418. * none
  4419. **/
  4420. static void ipr_copy_sata_tf(struct ipr_ioarcb_ata_regs *regs,
  4421. struct ata_taskfile *tf)
  4422. {
  4423. regs->feature = tf->feature;
  4424. regs->nsect = tf->nsect;
  4425. regs->lbal = tf->lbal;
  4426. regs->lbam = tf->lbam;
  4427. regs->lbah = tf->lbah;
  4428. regs->device = tf->device;
  4429. regs->command = tf->command;
  4430. regs->hob_feature = tf->hob_feature;
  4431. regs->hob_nsect = tf->hob_nsect;
  4432. regs->hob_lbal = tf->hob_lbal;
  4433. regs->hob_lbam = tf->hob_lbam;
  4434. regs->hob_lbah = tf->hob_lbah;
  4435. regs->ctl = tf->ctl;
  4436. }
  4437. /**
  4438. * ipr_sata_done - done function for SATA commands
  4439. * @ipr_cmd: ipr command struct
  4440. *
  4441. * This function is invoked by the interrupt handler for
  4442. * ops generated by the SCSI mid-layer to SATA devices
  4443. *
  4444. * Return value:
  4445. * none
  4446. **/
  4447. static void ipr_sata_done(struct ipr_cmnd *ipr_cmd)
  4448. {
  4449. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  4450. struct ata_queued_cmd *qc = ipr_cmd->qc;
  4451. struct ipr_sata_port *sata_port = qc->ap->private_data;
  4452. struct ipr_resource_entry *res = sata_port->res;
  4453. u32 ioasc = be32_to_cpu(ipr_cmd->ioasa.ioasc);
  4454. memcpy(&sata_port->ioasa, &ipr_cmd->ioasa.u.gata,
  4455. sizeof(struct ipr_ioasa_gata));
  4456. ipr_dump_ioasa(ioa_cfg, ipr_cmd, res);
  4457. if (be32_to_cpu(ipr_cmd->ioasa.ioasc_specific) & IPR_ATA_DEVICE_WAS_RESET)
  4458. scsi_report_device_reset(ioa_cfg->host, res->cfgte.res_addr.bus,
  4459. res->cfgte.res_addr.target);
  4460. if (IPR_IOASC_SENSE_KEY(ioasc) > RECOVERED_ERROR)
  4461. qc->err_mask |= __ac_err_mask(ipr_cmd->ioasa.u.gata.status);
  4462. else
  4463. qc->err_mask |= ac_err_mask(ipr_cmd->ioasa.u.gata.status);
  4464. list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
  4465. ata_qc_complete(qc);
  4466. }
  4467. /**
  4468. * ipr_build_ata_ioadl - Build an ATA scatter/gather list
  4469. * @ipr_cmd: ipr command struct
  4470. * @qc: ATA queued command
  4471. *
  4472. **/
  4473. static void ipr_build_ata_ioadl(struct ipr_cmnd *ipr_cmd,
  4474. struct ata_queued_cmd *qc)
  4475. {
  4476. u32 ioadl_flags = 0;
  4477. struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
  4478. struct ipr_ioadl_desc *ioadl = ipr_cmd->ioadl;
  4479. struct ipr_ioadl_desc *last_ioadl = NULL;
  4480. int len = qc->nbytes;
  4481. struct scatterlist *sg;
  4482. unsigned int si;
  4483. if (len == 0)
  4484. return;
  4485. if (qc->dma_dir == DMA_TO_DEVICE) {
  4486. ioadl_flags = IPR_IOADL_FLAGS_WRITE;
  4487. ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
  4488. ioarcb->write_data_transfer_length = cpu_to_be32(len);
  4489. ioarcb->write_ioadl_len =
  4490. cpu_to_be32(sizeof(struct ipr_ioadl_desc) * ipr_cmd->dma_use_sg);
  4491. } else if (qc->dma_dir == DMA_FROM_DEVICE) {
  4492. ioadl_flags = IPR_IOADL_FLAGS_READ;
  4493. ioarcb->read_data_transfer_length = cpu_to_be32(len);
  4494. ioarcb->read_ioadl_len =
  4495. cpu_to_be32(sizeof(struct ipr_ioadl_desc) * ipr_cmd->dma_use_sg);
  4496. }
  4497. for_each_sg(qc->sg, sg, qc->n_elem, si) {
  4498. ioadl->flags_and_data_len = cpu_to_be32(ioadl_flags | sg_dma_len(sg));
  4499. ioadl->address = cpu_to_be32(sg_dma_address(sg));
  4500. last_ioadl = ioadl;
  4501. ioadl++;
  4502. }
  4503. if (likely(last_ioadl))
  4504. last_ioadl->flags_and_data_len |= cpu_to_be32(IPR_IOADL_FLAGS_LAST);
  4505. }
  4506. /**
  4507. * ipr_qc_issue - Issue a SATA qc to a device
  4508. * @qc: queued command
  4509. *
  4510. * Return value:
  4511. * 0 if success
  4512. **/
  4513. static unsigned int ipr_qc_issue(struct ata_queued_cmd *qc)
  4514. {
  4515. struct ata_port *ap = qc->ap;
  4516. struct ipr_sata_port *sata_port = ap->private_data;
  4517. struct ipr_resource_entry *res = sata_port->res;
  4518. struct ipr_ioa_cfg *ioa_cfg = sata_port->ioa_cfg;
  4519. struct ipr_cmnd *ipr_cmd;
  4520. struct ipr_ioarcb *ioarcb;
  4521. struct ipr_ioarcb_ata_regs *regs;
  4522. if (unlikely(!ioa_cfg->allow_cmds || ioa_cfg->ioa_is_dead))
  4523. return AC_ERR_SYSTEM;
  4524. ipr_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
  4525. ioarcb = &ipr_cmd->ioarcb;
  4526. regs = &ioarcb->add_data.u.regs;
  4527. memset(&ioarcb->add_data, 0, sizeof(ioarcb->add_data));
  4528. ioarcb->add_cmd_parms_len = cpu_to_be32(sizeof(ioarcb->add_data.u.regs));
  4529. list_add_tail(&ipr_cmd->queue, &ioa_cfg->pending_q);
  4530. ipr_cmd->qc = qc;
  4531. ipr_cmd->done = ipr_sata_done;
  4532. ipr_cmd->ioarcb.res_handle = res->cfgte.res_handle;
  4533. ioarcb->cmd_pkt.request_type = IPR_RQTYPE_ATA_PASSTHRU;
  4534. ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_NO_LINK_DESC;
  4535. ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_NO_ULEN_CHK;
  4536. ipr_cmd->dma_use_sg = qc->n_elem;
  4537. ipr_build_ata_ioadl(ipr_cmd, qc);
  4538. regs->flags |= IPR_ATA_FLAG_STATUS_ON_GOOD_COMPLETION;
  4539. ipr_copy_sata_tf(regs, &qc->tf);
  4540. memcpy(ioarcb->cmd_pkt.cdb, qc->cdb, IPR_MAX_CDB_LEN);
  4541. ipr_trc_hook(ipr_cmd, IPR_TRACE_START, IPR_GET_PHYS_LOC(res->cfgte.res_addr));
  4542. switch (qc->tf.protocol) {
  4543. case ATA_PROT_NODATA:
  4544. case ATA_PROT_PIO:
  4545. break;
  4546. case ATA_PROT_DMA:
  4547. regs->flags |= IPR_ATA_FLAG_XFER_TYPE_DMA;
  4548. break;
  4549. case ATAPI_PROT_PIO:
  4550. case ATAPI_PROT_NODATA:
  4551. regs->flags |= IPR_ATA_FLAG_PACKET_CMD;
  4552. break;
  4553. case ATAPI_PROT_DMA:
  4554. regs->flags |= IPR_ATA_FLAG_PACKET_CMD;
  4555. regs->flags |= IPR_ATA_FLAG_XFER_TYPE_DMA;
  4556. break;
  4557. default:
  4558. WARN_ON(1);
  4559. return AC_ERR_INVALID;
  4560. }
  4561. mb();
  4562. writel(be32_to_cpu(ioarcb->ioarcb_host_pci_addr),
  4563. ioa_cfg->regs.ioarrin_reg);
  4564. return 0;
  4565. }
  4566. /**
  4567. * ipr_qc_fill_rtf - Read result TF
  4568. * @qc: ATA queued command
  4569. *
  4570. * Return value:
  4571. * true
  4572. **/
  4573. static bool ipr_qc_fill_rtf(struct ata_queued_cmd *qc)
  4574. {
  4575. struct ipr_sata_port *sata_port = qc->ap->private_data;
  4576. struct ipr_ioasa_gata *g = &sata_port->ioasa;
  4577. struct ata_taskfile *tf = &qc->result_tf;
  4578. tf->feature = g->error;
  4579. tf->nsect = g->nsect;
  4580. tf->lbal = g->lbal;
  4581. tf->lbam = g->lbam;
  4582. tf->lbah = g->lbah;
  4583. tf->device = g->device;
  4584. tf->command = g->status;
  4585. tf->hob_nsect = g->hob_nsect;
  4586. tf->hob_lbal = g->hob_lbal;
  4587. tf->hob_lbam = g->hob_lbam;
  4588. tf->hob_lbah = g->hob_lbah;
  4589. tf->ctl = g->alt_status;
  4590. return true;
  4591. }
  4592. static struct ata_port_operations ipr_sata_ops = {
  4593. .phy_reset = ipr_ata_phy_reset,
  4594. .hardreset = ipr_sata_reset,
  4595. .post_internal_cmd = ipr_ata_post_internal,
  4596. .qc_prep = ata_noop_qc_prep,
  4597. .qc_issue = ipr_qc_issue,
  4598. .qc_fill_rtf = ipr_qc_fill_rtf,
  4599. .port_start = ata_sas_port_start,
  4600. .port_stop = ata_sas_port_stop
  4601. };
  4602. static struct ata_port_info sata_port_info = {
  4603. .flags = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY | ATA_FLAG_SATA_RESET |
  4604. ATA_FLAG_MMIO | ATA_FLAG_PIO_DMA,
  4605. .pio_mask = 0x10, /* pio4 */
  4606. .mwdma_mask = 0x07,
  4607. .udma_mask = 0x7f, /* udma0-6 */
  4608. .port_ops = &ipr_sata_ops
  4609. };
  4610. #ifdef CONFIG_PPC_PSERIES
  4611. static const u16 ipr_blocked_processors[] = {
  4612. PV_NORTHSTAR,
  4613. PV_PULSAR,
  4614. PV_POWER4,
  4615. PV_ICESTAR,
  4616. PV_SSTAR,
  4617. PV_POWER4p,
  4618. PV_630,
  4619. PV_630p
  4620. };
  4621. /**
  4622. * ipr_invalid_adapter - Determine if this adapter is supported on this hardware
  4623. * @ioa_cfg: ioa cfg struct
  4624. *
  4625. * Adapters that use Gemstone revision < 3.1 do not work reliably on
  4626. * certain pSeries hardware. This function determines if the given
  4627. * adapter is in one of these confgurations or not.
  4628. *
  4629. * Return value:
  4630. * 1 if adapter is not supported / 0 if adapter is supported
  4631. **/
  4632. static int ipr_invalid_adapter(struct ipr_ioa_cfg *ioa_cfg)
  4633. {
  4634. int i;
  4635. if ((ioa_cfg->type == 0x5702) && (ioa_cfg->pdev->revision < 4)) {
  4636. for (i = 0; i < ARRAY_SIZE(ipr_blocked_processors); i++){
  4637. if (__is_processor(ipr_blocked_processors[i]))
  4638. return 1;
  4639. }
  4640. }
  4641. return 0;
  4642. }
  4643. #else
  4644. #define ipr_invalid_adapter(ioa_cfg) 0
  4645. #endif
  4646. /**
  4647. * ipr_ioa_bringdown_done - IOA bring down completion.
  4648. * @ipr_cmd: ipr command struct
  4649. *
  4650. * This function processes the completion of an adapter bring down.
  4651. * It wakes any reset sleepers.
  4652. *
  4653. * Return value:
  4654. * IPR_RC_JOB_RETURN
  4655. **/
  4656. static int ipr_ioa_bringdown_done(struct ipr_cmnd *ipr_cmd)
  4657. {
  4658. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  4659. ENTER;
  4660. ioa_cfg->in_reset_reload = 0;
  4661. ioa_cfg->reset_retries = 0;
  4662. list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
  4663. wake_up_all(&ioa_cfg->reset_wait_q);
  4664. spin_unlock_irq(ioa_cfg->host->host_lock);
  4665. scsi_unblock_requests(ioa_cfg->host);
  4666. spin_lock_irq(ioa_cfg->host->host_lock);
  4667. LEAVE;
  4668. return IPR_RC_JOB_RETURN;
  4669. }
  4670. /**
  4671. * ipr_ioa_reset_done - IOA reset completion.
  4672. * @ipr_cmd: ipr command struct
  4673. *
  4674. * This function processes the completion of an adapter reset.
  4675. * It schedules any necessary mid-layer add/removes and
  4676. * wakes any reset sleepers.
  4677. *
  4678. * Return value:
  4679. * IPR_RC_JOB_RETURN
  4680. **/
  4681. static int ipr_ioa_reset_done(struct ipr_cmnd *ipr_cmd)
  4682. {
  4683. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  4684. struct ipr_resource_entry *res;
  4685. struct ipr_hostrcb *hostrcb, *temp;
  4686. int i = 0;
  4687. ENTER;
  4688. ioa_cfg->in_reset_reload = 0;
  4689. ioa_cfg->allow_cmds = 1;
  4690. ioa_cfg->reset_cmd = NULL;
  4691. ioa_cfg->doorbell |= IPR_RUNTIME_RESET;
  4692. list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
  4693. if (ioa_cfg->allow_ml_add_del && (res->add_to_ml || res->del_from_ml)) {
  4694. ipr_trace;
  4695. break;
  4696. }
  4697. }
  4698. schedule_work(&ioa_cfg->work_q);
  4699. list_for_each_entry_safe(hostrcb, temp, &ioa_cfg->hostrcb_free_q, queue) {
  4700. list_del(&hostrcb->queue);
  4701. if (i++ < IPR_NUM_LOG_HCAMS)
  4702. ipr_send_hcam(ioa_cfg, IPR_HCAM_CDB_OP_CODE_LOG_DATA, hostrcb);
  4703. else
  4704. ipr_send_hcam(ioa_cfg, IPR_HCAM_CDB_OP_CODE_CONFIG_CHANGE, hostrcb);
  4705. }
  4706. scsi_report_bus_reset(ioa_cfg->host, IPR_VSET_BUS);
  4707. dev_info(&ioa_cfg->pdev->dev, "IOA initialized.\n");
  4708. ioa_cfg->reset_retries = 0;
  4709. list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
  4710. wake_up_all(&ioa_cfg->reset_wait_q);
  4711. spin_unlock(ioa_cfg->host->host_lock);
  4712. scsi_unblock_requests(ioa_cfg->host);
  4713. spin_lock(ioa_cfg->host->host_lock);
  4714. if (!ioa_cfg->allow_cmds)
  4715. scsi_block_requests(ioa_cfg->host);
  4716. LEAVE;
  4717. return IPR_RC_JOB_RETURN;
  4718. }
  4719. /**
  4720. * ipr_set_sup_dev_dflt - Initialize a Set Supported Device buffer
  4721. * @supported_dev: supported device struct
  4722. * @vpids: vendor product id struct
  4723. *
  4724. * Return value:
  4725. * none
  4726. **/
  4727. static void ipr_set_sup_dev_dflt(struct ipr_supported_device *supported_dev,
  4728. struct ipr_std_inq_vpids *vpids)
  4729. {
  4730. memset(supported_dev, 0, sizeof(struct ipr_supported_device));
  4731. memcpy(&supported_dev->vpids, vpids, sizeof(struct ipr_std_inq_vpids));
  4732. supported_dev->num_records = 1;
  4733. supported_dev->data_length =
  4734. cpu_to_be16(sizeof(struct ipr_supported_device));
  4735. supported_dev->reserved = 0;
  4736. }
  4737. /**
  4738. * ipr_set_supported_devs - Send Set Supported Devices for a device
  4739. * @ipr_cmd: ipr command struct
  4740. *
  4741. * This function send a Set Supported Devices to the adapter
  4742. *
  4743. * Return value:
  4744. * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
  4745. **/
  4746. static int ipr_set_supported_devs(struct ipr_cmnd *ipr_cmd)
  4747. {
  4748. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  4749. struct ipr_supported_device *supp_dev = &ioa_cfg->vpd_cbs->supp_dev;
  4750. struct ipr_ioadl_desc *ioadl = ipr_cmd->ioadl;
  4751. struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
  4752. struct ipr_resource_entry *res = ipr_cmd->u.res;
  4753. ipr_cmd->job_step = ipr_ioa_reset_done;
  4754. list_for_each_entry_continue(res, &ioa_cfg->used_res_q, queue) {
  4755. if (!ipr_is_scsi_disk(res))
  4756. continue;
  4757. ipr_cmd->u.res = res;
  4758. ipr_set_sup_dev_dflt(supp_dev, &res->cfgte.std_inq_data.vpids);
  4759. ioarcb->res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
  4760. ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
  4761. ioarcb->cmd_pkt.request_type = IPR_RQTYPE_IOACMD;
  4762. ioarcb->cmd_pkt.cdb[0] = IPR_SET_SUPPORTED_DEVICES;
  4763. ioarcb->cmd_pkt.cdb[7] = (sizeof(struct ipr_supported_device) >> 8) & 0xff;
  4764. ioarcb->cmd_pkt.cdb[8] = sizeof(struct ipr_supported_device) & 0xff;
  4765. ioadl->flags_and_data_len = cpu_to_be32(IPR_IOADL_FLAGS_WRITE_LAST |
  4766. sizeof(struct ipr_supported_device));
  4767. ioadl->address = cpu_to_be32(ioa_cfg->vpd_cbs_dma +
  4768. offsetof(struct ipr_misc_cbs, supp_dev));
  4769. ioarcb->write_ioadl_len = cpu_to_be32(sizeof(struct ipr_ioadl_desc));
  4770. ioarcb->write_data_transfer_length =
  4771. cpu_to_be32(sizeof(struct ipr_supported_device));
  4772. ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout,
  4773. IPR_SET_SUP_DEVICE_TIMEOUT);
  4774. ipr_cmd->job_step = ipr_set_supported_devs;
  4775. return IPR_RC_JOB_RETURN;
  4776. }
  4777. return IPR_RC_JOB_CONTINUE;
  4778. }
  4779. /**
  4780. * ipr_setup_write_cache - Disable write cache if needed
  4781. * @ipr_cmd: ipr command struct
  4782. *
  4783. * This function sets up adapters write cache to desired setting
  4784. *
  4785. * Return value:
  4786. * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
  4787. **/
  4788. static int ipr_setup_write_cache(struct ipr_cmnd *ipr_cmd)
  4789. {
  4790. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  4791. ipr_cmd->job_step = ipr_set_supported_devs;
  4792. ipr_cmd->u.res = list_entry(ioa_cfg->used_res_q.next,
  4793. struct ipr_resource_entry, queue);
  4794. if (ioa_cfg->cache_state != CACHE_DISABLED)
  4795. return IPR_RC_JOB_CONTINUE;
  4796. ipr_cmd->ioarcb.res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
  4797. ipr_cmd->ioarcb.cmd_pkt.request_type = IPR_RQTYPE_IOACMD;
  4798. ipr_cmd->ioarcb.cmd_pkt.cdb[0] = IPR_IOA_SHUTDOWN;
  4799. ipr_cmd->ioarcb.cmd_pkt.cdb[1] = IPR_SHUTDOWN_PREPARE_FOR_NORMAL;
  4800. ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, IPR_INTERNAL_TIMEOUT);
  4801. return IPR_RC_JOB_RETURN;
  4802. }
  4803. /**
  4804. * ipr_get_mode_page - Locate specified mode page
  4805. * @mode_pages: mode page buffer
  4806. * @page_code: page code to find
  4807. * @len: minimum required length for mode page
  4808. *
  4809. * Return value:
  4810. * pointer to mode page / NULL on failure
  4811. **/
  4812. static void *ipr_get_mode_page(struct ipr_mode_pages *mode_pages,
  4813. u32 page_code, u32 len)
  4814. {
  4815. struct ipr_mode_page_hdr *mode_hdr;
  4816. u32 page_length;
  4817. u32 length;
  4818. if (!mode_pages || (mode_pages->hdr.length == 0))
  4819. return NULL;
  4820. length = (mode_pages->hdr.length + 1) - 4 - mode_pages->hdr.block_desc_len;
  4821. mode_hdr = (struct ipr_mode_page_hdr *)
  4822. (mode_pages->data + mode_pages->hdr.block_desc_len);
  4823. while (length) {
  4824. if (IPR_GET_MODE_PAGE_CODE(mode_hdr) == page_code) {
  4825. if (mode_hdr->page_length >= (len - sizeof(struct ipr_mode_page_hdr)))
  4826. return mode_hdr;
  4827. break;
  4828. } else {
  4829. page_length = (sizeof(struct ipr_mode_page_hdr) +
  4830. mode_hdr->page_length);
  4831. length -= page_length;
  4832. mode_hdr = (struct ipr_mode_page_hdr *)
  4833. ((unsigned long)mode_hdr + page_length);
  4834. }
  4835. }
  4836. return NULL;
  4837. }
  4838. /**
  4839. * ipr_check_term_power - Check for term power errors
  4840. * @ioa_cfg: ioa config struct
  4841. * @mode_pages: IOAFP mode pages buffer
  4842. *
  4843. * Check the IOAFP's mode page 28 for term power errors
  4844. *
  4845. * Return value:
  4846. * nothing
  4847. **/
  4848. static void ipr_check_term_power(struct ipr_ioa_cfg *ioa_cfg,
  4849. struct ipr_mode_pages *mode_pages)
  4850. {
  4851. int i;
  4852. int entry_length;
  4853. struct ipr_dev_bus_entry *bus;
  4854. struct ipr_mode_page28 *mode_page;
  4855. mode_page = ipr_get_mode_page(mode_pages, 0x28,
  4856. sizeof(struct ipr_mode_page28));
  4857. entry_length = mode_page->entry_length;
  4858. bus = mode_page->bus;
  4859. for (i = 0; i < mode_page->num_entries; i++) {
  4860. if (bus->flags & IPR_SCSI_ATTR_NO_TERM_PWR) {
  4861. dev_err(&ioa_cfg->pdev->dev,
  4862. "Term power is absent on scsi bus %d\n",
  4863. bus->res_addr.bus);
  4864. }
  4865. bus = (struct ipr_dev_bus_entry *)((char *)bus + entry_length);
  4866. }
  4867. }
  4868. /**
  4869. * ipr_scsi_bus_speed_limit - Limit the SCSI speed based on SES table
  4870. * @ioa_cfg: ioa config struct
  4871. *
  4872. * Looks through the config table checking for SES devices. If
  4873. * the SES device is in the SES table indicating a maximum SCSI
  4874. * bus speed, the speed is limited for the bus.
  4875. *
  4876. * Return value:
  4877. * none
  4878. **/
  4879. static void ipr_scsi_bus_speed_limit(struct ipr_ioa_cfg *ioa_cfg)
  4880. {
  4881. u32 max_xfer_rate;
  4882. int i;
  4883. for (i = 0; i < IPR_MAX_NUM_BUSES; i++) {
  4884. max_xfer_rate = ipr_get_max_scsi_speed(ioa_cfg, i,
  4885. ioa_cfg->bus_attr[i].bus_width);
  4886. if (max_xfer_rate < ioa_cfg->bus_attr[i].max_xfer_rate)
  4887. ioa_cfg->bus_attr[i].max_xfer_rate = max_xfer_rate;
  4888. }
  4889. }
  4890. /**
  4891. * ipr_modify_ioafp_mode_page_28 - Modify IOAFP Mode Page 28
  4892. * @ioa_cfg: ioa config struct
  4893. * @mode_pages: mode page 28 buffer
  4894. *
  4895. * Updates mode page 28 based on driver configuration
  4896. *
  4897. * Return value:
  4898. * none
  4899. **/
  4900. static void ipr_modify_ioafp_mode_page_28(struct ipr_ioa_cfg *ioa_cfg,
  4901. struct ipr_mode_pages *mode_pages)
  4902. {
  4903. int i, entry_length;
  4904. struct ipr_dev_bus_entry *bus;
  4905. struct ipr_bus_attributes *bus_attr;
  4906. struct ipr_mode_page28 *mode_page;
  4907. mode_page = ipr_get_mode_page(mode_pages, 0x28,
  4908. sizeof(struct ipr_mode_page28));
  4909. entry_length = mode_page->entry_length;
  4910. /* Loop for each device bus entry */
  4911. for (i = 0, bus = mode_page->bus;
  4912. i < mode_page->num_entries;
  4913. i++, bus = (struct ipr_dev_bus_entry *)((u8 *)bus + entry_length)) {
  4914. if (bus->res_addr.bus > IPR_MAX_NUM_BUSES) {
  4915. dev_err(&ioa_cfg->pdev->dev,
  4916. "Invalid resource address reported: 0x%08X\n",
  4917. IPR_GET_PHYS_LOC(bus->res_addr));
  4918. continue;
  4919. }
  4920. bus_attr = &ioa_cfg->bus_attr[i];
  4921. bus->extended_reset_delay = IPR_EXTENDED_RESET_DELAY;
  4922. bus->bus_width = bus_attr->bus_width;
  4923. bus->max_xfer_rate = cpu_to_be32(bus_attr->max_xfer_rate);
  4924. bus->flags &= ~IPR_SCSI_ATTR_QAS_MASK;
  4925. if (bus_attr->qas_enabled)
  4926. bus->flags |= IPR_SCSI_ATTR_ENABLE_QAS;
  4927. else
  4928. bus->flags |= IPR_SCSI_ATTR_DISABLE_QAS;
  4929. }
  4930. }
  4931. /**
  4932. * ipr_build_mode_select - Build a mode select command
  4933. * @ipr_cmd: ipr command struct
  4934. * @res_handle: resource handle to send command to
  4935. * @parm: Byte 2 of Mode Sense command
  4936. * @dma_addr: DMA buffer address
  4937. * @xfer_len: data transfer length
  4938. *
  4939. * Return value:
  4940. * none
  4941. **/
  4942. static void ipr_build_mode_select(struct ipr_cmnd *ipr_cmd,
  4943. __be32 res_handle, u8 parm, u32 dma_addr,
  4944. u8 xfer_len)
  4945. {
  4946. struct ipr_ioadl_desc *ioadl = ipr_cmd->ioadl;
  4947. struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
  4948. ioarcb->res_handle = res_handle;
  4949. ioarcb->cmd_pkt.request_type = IPR_RQTYPE_SCSICDB;
  4950. ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
  4951. ioarcb->cmd_pkt.cdb[0] = MODE_SELECT;
  4952. ioarcb->cmd_pkt.cdb[1] = parm;
  4953. ioarcb->cmd_pkt.cdb[4] = xfer_len;
  4954. ioadl->flags_and_data_len =
  4955. cpu_to_be32(IPR_IOADL_FLAGS_WRITE_LAST | xfer_len);
  4956. ioadl->address = cpu_to_be32(dma_addr);
  4957. ioarcb->write_ioadl_len = cpu_to_be32(sizeof(struct ipr_ioadl_desc));
  4958. ioarcb->write_data_transfer_length = cpu_to_be32(xfer_len);
  4959. }
  4960. /**
  4961. * ipr_ioafp_mode_select_page28 - Issue Mode Select Page 28 to IOA
  4962. * @ipr_cmd: ipr command struct
  4963. *
  4964. * This function sets up the SCSI bus attributes and sends
  4965. * a Mode Select for Page 28 to activate them.
  4966. *
  4967. * Return value:
  4968. * IPR_RC_JOB_RETURN
  4969. **/
  4970. static int ipr_ioafp_mode_select_page28(struct ipr_cmnd *ipr_cmd)
  4971. {
  4972. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  4973. struct ipr_mode_pages *mode_pages = &ioa_cfg->vpd_cbs->mode_pages;
  4974. int length;
  4975. ENTER;
  4976. ipr_scsi_bus_speed_limit(ioa_cfg);
  4977. ipr_check_term_power(ioa_cfg, mode_pages);
  4978. ipr_modify_ioafp_mode_page_28(ioa_cfg, mode_pages);
  4979. length = mode_pages->hdr.length + 1;
  4980. mode_pages->hdr.length = 0;
  4981. ipr_build_mode_select(ipr_cmd, cpu_to_be32(IPR_IOA_RES_HANDLE), 0x11,
  4982. ioa_cfg->vpd_cbs_dma + offsetof(struct ipr_misc_cbs, mode_pages),
  4983. length);
  4984. ipr_cmd->job_step = ipr_setup_write_cache;
  4985. ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, IPR_INTERNAL_TIMEOUT);
  4986. LEAVE;
  4987. return IPR_RC_JOB_RETURN;
  4988. }
  4989. /**
  4990. * ipr_build_mode_sense - Builds a mode sense command
  4991. * @ipr_cmd: ipr command struct
  4992. * @res: resource entry struct
  4993. * @parm: Byte 2 of mode sense command
  4994. * @dma_addr: DMA address of mode sense buffer
  4995. * @xfer_len: Size of DMA buffer
  4996. *
  4997. * Return value:
  4998. * none
  4999. **/
  5000. static void ipr_build_mode_sense(struct ipr_cmnd *ipr_cmd,
  5001. __be32 res_handle,
  5002. u8 parm, u32 dma_addr, u8 xfer_len)
  5003. {
  5004. struct ipr_ioadl_desc *ioadl = ipr_cmd->ioadl;
  5005. struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
  5006. ioarcb->res_handle = res_handle;
  5007. ioarcb->cmd_pkt.cdb[0] = MODE_SENSE;
  5008. ioarcb->cmd_pkt.cdb[2] = parm;
  5009. ioarcb->cmd_pkt.cdb[4] = xfer_len;
  5010. ioarcb->cmd_pkt.request_type = IPR_RQTYPE_SCSICDB;
  5011. ioadl->flags_and_data_len =
  5012. cpu_to_be32(IPR_IOADL_FLAGS_READ_LAST | xfer_len);
  5013. ioadl->address = cpu_to_be32(dma_addr);
  5014. ioarcb->read_ioadl_len = cpu_to_be32(sizeof(struct ipr_ioadl_desc));
  5015. ioarcb->read_data_transfer_length = cpu_to_be32(xfer_len);
  5016. }
  5017. /**
  5018. * ipr_reset_cmd_failed - Handle failure of IOA reset command
  5019. * @ipr_cmd: ipr command struct
  5020. *
  5021. * This function handles the failure of an IOA bringup command.
  5022. *
  5023. * Return value:
  5024. * IPR_RC_JOB_RETURN
  5025. **/
  5026. static int ipr_reset_cmd_failed(struct ipr_cmnd *ipr_cmd)
  5027. {
  5028. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  5029. u32 ioasc = be32_to_cpu(ipr_cmd->ioasa.ioasc);
  5030. dev_err(&ioa_cfg->pdev->dev,
  5031. "0x%02X failed with IOASC: 0x%08X\n",
  5032. ipr_cmd->ioarcb.cmd_pkt.cdb[0], ioasc);
  5033. ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
  5034. list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
  5035. return IPR_RC_JOB_RETURN;
  5036. }
  5037. /**
  5038. * ipr_reset_mode_sense_failed - Handle failure of IOAFP mode sense
  5039. * @ipr_cmd: ipr command struct
  5040. *
  5041. * This function handles the failure of a Mode Sense to the IOAFP.
  5042. * Some adapters do not handle all mode pages.
  5043. *
  5044. * Return value:
  5045. * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
  5046. **/
  5047. static int ipr_reset_mode_sense_failed(struct ipr_cmnd *ipr_cmd)
  5048. {
  5049. u32 ioasc = be32_to_cpu(ipr_cmd->ioasa.ioasc);
  5050. if (ioasc == IPR_IOASC_IR_INVALID_REQ_TYPE_OR_PKT) {
  5051. ipr_cmd->job_step = ipr_setup_write_cache;
  5052. return IPR_RC_JOB_CONTINUE;
  5053. }
  5054. return ipr_reset_cmd_failed(ipr_cmd);
  5055. }
  5056. /**
  5057. * ipr_ioafp_mode_sense_page28 - Issue Mode Sense Page 28 to IOA
  5058. * @ipr_cmd: ipr command struct
  5059. *
  5060. * This function send a Page 28 mode sense to the IOA to
  5061. * retrieve SCSI bus attributes.
  5062. *
  5063. * Return value:
  5064. * IPR_RC_JOB_RETURN
  5065. **/
  5066. static int ipr_ioafp_mode_sense_page28(struct ipr_cmnd *ipr_cmd)
  5067. {
  5068. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  5069. ENTER;
  5070. ipr_build_mode_sense(ipr_cmd, cpu_to_be32(IPR_IOA_RES_HANDLE),
  5071. 0x28, ioa_cfg->vpd_cbs_dma +
  5072. offsetof(struct ipr_misc_cbs, mode_pages),
  5073. sizeof(struct ipr_mode_pages));
  5074. ipr_cmd->job_step = ipr_ioafp_mode_select_page28;
  5075. ipr_cmd->job_step_failed = ipr_reset_mode_sense_failed;
  5076. ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, IPR_INTERNAL_TIMEOUT);
  5077. LEAVE;
  5078. return IPR_RC_JOB_RETURN;
  5079. }
  5080. /**
  5081. * ipr_ioafp_mode_select_page24 - Issue Mode Select to IOA
  5082. * @ipr_cmd: ipr command struct
  5083. *
  5084. * This function enables dual IOA RAID support if possible.
  5085. *
  5086. * Return value:
  5087. * IPR_RC_JOB_RETURN
  5088. **/
  5089. static int ipr_ioafp_mode_select_page24(struct ipr_cmnd *ipr_cmd)
  5090. {
  5091. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  5092. struct ipr_mode_pages *mode_pages = &ioa_cfg->vpd_cbs->mode_pages;
  5093. struct ipr_mode_page24 *mode_page;
  5094. int length;
  5095. ENTER;
  5096. mode_page = ipr_get_mode_page(mode_pages, 0x24,
  5097. sizeof(struct ipr_mode_page24));
  5098. if (mode_page)
  5099. mode_page->flags |= IPR_ENABLE_DUAL_IOA_AF;
  5100. length = mode_pages->hdr.length + 1;
  5101. mode_pages->hdr.length = 0;
  5102. ipr_build_mode_select(ipr_cmd, cpu_to_be32(IPR_IOA_RES_HANDLE), 0x11,
  5103. ioa_cfg->vpd_cbs_dma + offsetof(struct ipr_misc_cbs, mode_pages),
  5104. length);
  5105. ipr_cmd->job_step = ipr_ioafp_mode_sense_page28;
  5106. ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, IPR_INTERNAL_TIMEOUT);
  5107. LEAVE;
  5108. return IPR_RC_JOB_RETURN;
  5109. }
  5110. /**
  5111. * ipr_reset_mode_sense_page24_failed - Handle failure of IOAFP mode sense
  5112. * @ipr_cmd: ipr command struct
  5113. *
  5114. * This function handles the failure of a Mode Sense to the IOAFP.
  5115. * Some adapters do not handle all mode pages.
  5116. *
  5117. * Return value:
  5118. * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
  5119. **/
  5120. static int ipr_reset_mode_sense_page24_failed(struct ipr_cmnd *ipr_cmd)
  5121. {
  5122. u32 ioasc = be32_to_cpu(ipr_cmd->ioasa.ioasc);
  5123. if (ioasc == IPR_IOASC_IR_INVALID_REQ_TYPE_OR_PKT) {
  5124. ipr_cmd->job_step = ipr_ioafp_mode_sense_page28;
  5125. return IPR_RC_JOB_CONTINUE;
  5126. }
  5127. return ipr_reset_cmd_failed(ipr_cmd);
  5128. }
  5129. /**
  5130. * ipr_ioafp_mode_sense_page24 - Issue Page 24 Mode Sense to IOA
  5131. * @ipr_cmd: ipr command struct
  5132. *
  5133. * This function send a mode sense to the IOA to retrieve
  5134. * the IOA Advanced Function Control mode page.
  5135. *
  5136. * Return value:
  5137. * IPR_RC_JOB_RETURN
  5138. **/
  5139. static int ipr_ioafp_mode_sense_page24(struct ipr_cmnd *ipr_cmd)
  5140. {
  5141. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  5142. ENTER;
  5143. ipr_build_mode_sense(ipr_cmd, cpu_to_be32(IPR_IOA_RES_HANDLE),
  5144. 0x24, ioa_cfg->vpd_cbs_dma +
  5145. offsetof(struct ipr_misc_cbs, mode_pages),
  5146. sizeof(struct ipr_mode_pages));
  5147. ipr_cmd->job_step = ipr_ioafp_mode_select_page24;
  5148. ipr_cmd->job_step_failed = ipr_reset_mode_sense_page24_failed;
  5149. ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, IPR_INTERNAL_TIMEOUT);
  5150. LEAVE;
  5151. return IPR_RC_JOB_RETURN;
  5152. }
  5153. /**
  5154. * ipr_init_res_table - Initialize the resource table
  5155. * @ipr_cmd: ipr command struct
  5156. *
  5157. * This function looks through the existing resource table, comparing
  5158. * it with the config table. This function will take care of old/new
  5159. * devices and schedule adding/removing them from the mid-layer
  5160. * as appropriate.
  5161. *
  5162. * Return value:
  5163. * IPR_RC_JOB_CONTINUE
  5164. **/
  5165. static int ipr_init_res_table(struct ipr_cmnd *ipr_cmd)
  5166. {
  5167. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  5168. struct ipr_resource_entry *res, *temp;
  5169. struct ipr_config_table_entry *cfgte;
  5170. int found, i;
  5171. LIST_HEAD(old_res);
  5172. ENTER;
  5173. if (ioa_cfg->cfg_table->hdr.flags & IPR_UCODE_DOWNLOAD_REQ)
  5174. dev_err(&ioa_cfg->pdev->dev, "Microcode download required\n");
  5175. list_for_each_entry_safe(res, temp, &ioa_cfg->used_res_q, queue)
  5176. list_move_tail(&res->queue, &old_res);
  5177. for (i = 0; i < ioa_cfg->cfg_table->hdr.num_entries; i++) {
  5178. cfgte = &ioa_cfg->cfg_table->dev[i];
  5179. found = 0;
  5180. list_for_each_entry_safe(res, temp, &old_res, queue) {
  5181. if (!memcmp(&res->cfgte.res_addr,
  5182. &cfgte->res_addr, sizeof(cfgte->res_addr))) {
  5183. list_move_tail(&res->queue, &ioa_cfg->used_res_q);
  5184. found = 1;
  5185. break;
  5186. }
  5187. }
  5188. if (!found) {
  5189. if (list_empty(&ioa_cfg->free_res_q)) {
  5190. dev_err(&ioa_cfg->pdev->dev, "Too many devices attached\n");
  5191. break;
  5192. }
  5193. found = 1;
  5194. res = list_entry(ioa_cfg->free_res_q.next,
  5195. struct ipr_resource_entry, queue);
  5196. list_move_tail(&res->queue, &ioa_cfg->used_res_q);
  5197. ipr_init_res_entry(res);
  5198. res->add_to_ml = 1;
  5199. }
  5200. if (found)
  5201. memcpy(&res->cfgte, cfgte, sizeof(struct ipr_config_table_entry));
  5202. }
  5203. list_for_each_entry_safe(res, temp, &old_res, queue) {
  5204. if (res->sdev) {
  5205. res->del_from_ml = 1;
  5206. res->cfgte.res_handle = IPR_INVALID_RES_HANDLE;
  5207. list_move_tail(&res->queue, &ioa_cfg->used_res_q);
  5208. } else {
  5209. list_move_tail(&res->queue, &ioa_cfg->free_res_q);
  5210. }
  5211. }
  5212. if (ioa_cfg->dual_raid && ipr_dual_ioa_raid)
  5213. ipr_cmd->job_step = ipr_ioafp_mode_sense_page24;
  5214. else
  5215. ipr_cmd->job_step = ipr_ioafp_mode_sense_page28;
  5216. LEAVE;
  5217. return IPR_RC_JOB_CONTINUE;
  5218. }
  5219. /**
  5220. * ipr_ioafp_query_ioa_cfg - Send a Query IOA Config to the adapter.
  5221. * @ipr_cmd: ipr command struct
  5222. *
  5223. * This function sends a Query IOA Configuration command
  5224. * to the adapter to retrieve the IOA configuration table.
  5225. *
  5226. * Return value:
  5227. * IPR_RC_JOB_RETURN
  5228. **/
  5229. static int ipr_ioafp_query_ioa_cfg(struct ipr_cmnd *ipr_cmd)
  5230. {
  5231. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  5232. struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
  5233. struct ipr_ioadl_desc *ioadl = ipr_cmd->ioadl;
  5234. struct ipr_inquiry_page3 *ucode_vpd = &ioa_cfg->vpd_cbs->page3_data;
  5235. struct ipr_inquiry_cap *cap = &ioa_cfg->vpd_cbs->cap;
  5236. ENTER;
  5237. if (cap->cap & IPR_CAP_DUAL_IOA_RAID)
  5238. ioa_cfg->dual_raid = 1;
  5239. dev_info(&ioa_cfg->pdev->dev, "Adapter firmware version: %02X%02X%02X%02X\n",
  5240. ucode_vpd->major_release, ucode_vpd->card_type,
  5241. ucode_vpd->minor_release[0], ucode_vpd->minor_release[1]);
  5242. ioarcb->cmd_pkt.request_type = IPR_RQTYPE_IOACMD;
  5243. ioarcb->res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
  5244. ioarcb->cmd_pkt.cdb[0] = IPR_QUERY_IOA_CONFIG;
  5245. ioarcb->cmd_pkt.cdb[7] = (sizeof(struct ipr_config_table) >> 8) & 0xff;
  5246. ioarcb->cmd_pkt.cdb[8] = sizeof(struct ipr_config_table) & 0xff;
  5247. ioarcb->read_ioadl_len = cpu_to_be32(sizeof(struct ipr_ioadl_desc));
  5248. ioarcb->read_data_transfer_length =
  5249. cpu_to_be32(sizeof(struct ipr_config_table));
  5250. ioadl->address = cpu_to_be32(ioa_cfg->cfg_table_dma);
  5251. ioadl->flags_and_data_len =
  5252. cpu_to_be32(IPR_IOADL_FLAGS_READ_LAST | sizeof(struct ipr_config_table));
  5253. ipr_cmd->job_step = ipr_init_res_table;
  5254. ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, IPR_INTERNAL_TIMEOUT);
  5255. LEAVE;
  5256. return IPR_RC_JOB_RETURN;
  5257. }
  5258. /**
  5259. * ipr_ioafp_inquiry - Send an Inquiry to the adapter.
  5260. * @ipr_cmd: ipr command struct
  5261. *
  5262. * This utility function sends an inquiry to the adapter.
  5263. *
  5264. * Return value:
  5265. * none
  5266. **/
  5267. static void ipr_ioafp_inquiry(struct ipr_cmnd *ipr_cmd, u8 flags, u8 page,
  5268. u32 dma_addr, u8 xfer_len)
  5269. {
  5270. struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
  5271. struct ipr_ioadl_desc *ioadl = ipr_cmd->ioadl;
  5272. ENTER;
  5273. ioarcb->cmd_pkt.request_type = IPR_RQTYPE_SCSICDB;
  5274. ioarcb->res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
  5275. ioarcb->cmd_pkt.cdb[0] = INQUIRY;
  5276. ioarcb->cmd_pkt.cdb[1] = flags;
  5277. ioarcb->cmd_pkt.cdb[2] = page;
  5278. ioarcb->cmd_pkt.cdb[4] = xfer_len;
  5279. ioarcb->read_ioadl_len = cpu_to_be32(sizeof(struct ipr_ioadl_desc));
  5280. ioarcb->read_data_transfer_length = cpu_to_be32(xfer_len);
  5281. ioadl->address = cpu_to_be32(dma_addr);
  5282. ioadl->flags_and_data_len =
  5283. cpu_to_be32(IPR_IOADL_FLAGS_READ_LAST | xfer_len);
  5284. ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, IPR_INTERNAL_TIMEOUT);
  5285. LEAVE;
  5286. }
  5287. /**
  5288. * ipr_inquiry_page_supported - Is the given inquiry page supported
  5289. * @page0: inquiry page 0 buffer
  5290. * @page: page code.
  5291. *
  5292. * This function determines if the specified inquiry page is supported.
  5293. *
  5294. * Return value:
  5295. * 1 if page is supported / 0 if not
  5296. **/
  5297. static int ipr_inquiry_page_supported(struct ipr_inquiry_page0 *page0, u8 page)
  5298. {
  5299. int i;
  5300. for (i = 0; i < min_t(u8, page0->len, IPR_INQUIRY_PAGE0_ENTRIES); i++)
  5301. if (page0->page[i] == page)
  5302. return 1;
  5303. return 0;
  5304. }
  5305. /**
  5306. * ipr_ioafp_cap_inquiry - Send a Page 0xD0 Inquiry to the adapter.
  5307. * @ipr_cmd: ipr command struct
  5308. *
  5309. * This function sends a Page 0xD0 inquiry to the adapter
  5310. * to retrieve adapter capabilities.
  5311. *
  5312. * Return value:
  5313. * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
  5314. **/
  5315. static int ipr_ioafp_cap_inquiry(struct ipr_cmnd *ipr_cmd)
  5316. {
  5317. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  5318. struct ipr_inquiry_page0 *page0 = &ioa_cfg->vpd_cbs->page0_data;
  5319. struct ipr_inquiry_cap *cap = &ioa_cfg->vpd_cbs->cap;
  5320. ENTER;
  5321. ipr_cmd->job_step = ipr_ioafp_query_ioa_cfg;
  5322. memset(cap, 0, sizeof(*cap));
  5323. if (ipr_inquiry_page_supported(page0, 0xD0)) {
  5324. ipr_ioafp_inquiry(ipr_cmd, 1, 0xD0,
  5325. ioa_cfg->vpd_cbs_dma + offsetof(struct ipr_misc_cbs, cap),
  5326. sizeof(struct ipr_inquiry_cap));
  5327. return IPR_RC_JOB_RETURN;
  5328. }
  5329. LEAVE;
  5330. return IPR_RC_JOB_CONTINUE;
  5331. }
  5332. /**
  5333. * ipr_ioafp_page3_inquiry - Send a Page 3 Inquiry to the adapter.
  5334. * @ipr_cmd: ipr command struct
  5335. *
  5336. * This function sends a Page 3 inquiry to the adapter
  5337. * to retrieve software VPD information.
  5338. *
  5339. * Return value:
  5340. * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
  5341. **/
  5342. static int ipr_ioafp_page3_inquiry(struct ipr_cmnd *ipr_cmd)
  5343. {
  5344. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  5345. struct ipr_inquiry_page0 *page0 = &ioa_cfg->vpd_cbs->page0_data;
  5346. ENTER;
  5347. if (!ipr_inquiry_page_supported(page0, 1))
  5348. ioa_cfg->cache_state = CACHE_NONE;
  5349. ipr_cmd->job_step = ipr_ioafp_cap_inquiry;
  5350. ipr_ioafp_inquiry(ipr_cmd, 1, 3,
  5351. ioa_cfg->vpd_cbs_dma + offsetof(struct ipr_misc_cbs, page3_data),
  5352. sizeof(struct ipr_inquiry_page3));
  5353. LEAVE;
  5354. return IPR_RC_JOB_RETURN;
  5355. }
  5356. /**
  5357. * ipr_ioafp_page0_inquiry - Send a Page 0 Inquiry to the adapter.
  5358. * @ipr_cmd: ipr command struct
  5359. *
  5360. * This function sends a Page 0 inquiry to the adapter
  5361. * to retrieve supported inquiry pages.
  5362. *
  5363. * Return value:
  5364. * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
  5365. **/
  5366. static int ipr_ioafp_page0_inquiry(struct ipr_cmnd *ipr_cmd)
  5367. {
  5368. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  5369. char type[5];
  5370. ENTER;
  5371. /* Grab the type out of the VPD and store it away */
  5372. memcpy(type, ioa_cfg->vpd_cbs->ioa_vpd.std_inq_data.vpids.product_id, 4);
  5373. type[4] = '\0';
  5374. ioa_cfg->type = simple_strtoul((char *)type, NULL, 16);
  5375. ipr_cmd->job_step = ipr_ioafp_page3_inquiry;
  5376. ipr_ioafp_inquiry(ipr_cmd, 1, 0,
  5377. ioa_cfg->vpd_cbs_dma + offsetof(struct ipr_misc_cbs, page0_data),
  5378. sizeof(struct ipr_inquiry_page0));
  5379. LEAVE;
  5380. return IPR_RC_JOB_RETURN;
  5381. }
  5382. /**
  5383. * ipr_ioafp_std_inquiry - Send a Standard Inquiry to the adapter.
  5384. * @ipr_cmd: ipr command struct
  5385. *
  5386. * This function sends a standard inquiry to the adapter.
  5387. *
  5388. * Return value:
  5389. * IPR_RC_JOB_RETURN
  5390. **/
  5391. static int ipr_ioafp_std_inquiry(struct ipr_cmnd *ipr_cmd)
  5392. {
  5393. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  5394. ENTER;
  5395. ipr_cmd->job_step = ipr_ioafp_page0_inquiry;
  5396. ipr_ioafp_inquiry(ipr_cmd, 0, 0,
  5397. ioa_cfg->vpd_cbs_dma + offsetof(struct ipr_misc_cbs, ioa_vpd),
  5398. sizeof(struct ipr_ioa_vpd));
  5399. LEAVE;
  5400. return IPR_RC_JOB_RETURN;
  5401. }
  5402. /**
  5403. * ipr_ioafp_indentify_hrrq - Send Identify Host RRQ.
  5404. * @ipr_cmd: ipr command struct
  5405. *
  5406. * This function send an Identify Host Request Response Queue
  5407. * command to establish the HRRQ with the adapter.
  5408. *
  5409. * Return value:
  5410. * IPR_RC_JOB_RETURN
  5411. **/
  5412. static int ipr_ioafp_indentify_hrrq(struct ipr_cmnd *ipr_cmd)
  5413. {
  5414. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  5415. struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
  5416. ENTER;
  5417. dev_info(&ioa_cfg->pdev->dev, "Starting IOA initialization sequence.\n");
  5418. ioarcb->cmd_pkt.cdb[0] = IPR_ID_HOST_RR_Q;
  5419. ioarcb->res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
  5420. ioarcb->cmd_pkt.request_type = IPR_RQTYPE_IOACMD;
  5421. ioarcb->cmd_pkt.cdb[2] =
  5422. ((u32) ioa_cfg->host_rrq_dma >> 24) & 0xff;
  5423. ioarcb->cmd_pkt.cdb[3] =
  5424. ((u32) ioa_cfg->host_rrq_dma >> 16) & 0xff;
  5425. ioarcb->cmd_pkt.cdb[4] =
  5426. ((u32) ioa_cfg->host_rrq_dma >> 8) & 0xff;
  5427. ioarcb->cmd_pkt.cdb[5] =
  5428. ((u32) ioa_cfg->host_rrq_dma) & 0xff;
  5429. ioarcb->cmd_pkt.cdb[7] =
  5430. ((sizeof(u32) * IPR_NUM_CMD_BLKS) >> 8) & 0xff;
  5431. ioarcb->cmd_pkt.cdb[8] =
  5432. (sizeof(u32) * IPR_NUM_CMD_BLKS) & 0xff;
  5433. ipr_cmd->job_step = ipr_ioafp_std_inquiry;
  5434. ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, IPR_INTERNAL_TIMEOUT);
  5435. LEAVE;
  5436. return IPR_RC_JOB_RETURN;
  5437. }
  5438. /**
  5439. * ipr_reset_timer_done - Adapter reset timer function
  5440. * @ipr_cmd: ipr command struct
  5441. *
  5442. * Description: This function is used in adapter reset processing
  5443. * for timing events. If the reset_cmd pointer in the IOA
  5444. * config struct is not this adapter's we are doing nested
  5445. * resets and fail_all_ops will take care of freeing the
  5446. * command block.
  5447. *
  5448. * Return value:
  5449. * none
  5450. **/
  5451. static void ipr_reset_timer_done(struct ipr_cmnd *ipr_cmd)
  5452. {
  5453. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  5454. unsigned long lock_flags = 0;
  5455. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  5456. if (ioa_cfg->reset_cmd == ipr_cmd) {
  5457. list_del(&ipr_cmd->queue);
  5458. ipr_cmd->done(ipr_cmd);
  5459. }
  5460. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  5461. }
  5462. /**
  5463. * ipr_reset_start_timer - Start a timer for adapter reset job
  5464. * @ipr_cmd: ipr command struct
  5465. * @timeout: timeout value
  5466. *
  5467. * Description: This function is used in adapter reset processing
  5468. * for timing events. If the reset_cmd pointer in the IOA
  5469. * config struct is not this adapter's we are doing nested
  5470. * resets and fail_all_ops will take care of freeing the
  5471. * command block.
  5472. *
  5473. * Return value:
  5474. * none
  5475. **/
  5476. static void ipr_reset_start_timer(struct ipr_cmnd *ipr_cmd,
  5477. unsigned long timeout)
  5478. {
  5479. list_add_tail(&ipr_cmd->queue, &ipr_cmd->ioa_cfg->pending_q);
  5480. ipr_cmd->done = ipr_reset_ioa_job;
  5481. ipr_cmd->timer.data = (unsigned long) ipr_cmd;
  5482. ipr_cmd->timer.expires = jiffies + timeout;
  5483. ipr_cmd->timer.function = (void (*)(unsigned long))ipr_reset_timer_done;
  5484. add_timer(&ipr_cmd->timer);
  5485. }
  5486. /**
  5487. * ipr_init_ioa_mem - Initialize ioa_cfg control block
  5488. * @ioa_cfg: ioa cfg struct
  5489. *
  5490. * Return value:
  5491. * nothing
  5492. **/
  5493. static void ipr_init_ioa_mem(struct ipr_ioa_cfg *ioa_cfg)
  5494. {
  5495. memset(ioa_cfg->host_rrq, 0, sizeof(u32) * IPR_NUM_CMD_BLKS);
  5496. /* Initialize Host RRQ pointers */
  5497. ioa_cfg->hrrq_start = ioa_cfg->host_rrq;
  5498. ioa_cfg->hrrq_end = &ioa_cfg->host_rrq[IPR_NUM_CMD_BLKS - 1];
  5499. ioa_cfg->hrrq_curr = ioa_cfg->hrrq_start;
  5500. ioa_cfg->toggle_bit = 1;
  5501. /* Zero out config table */
  5502. memset(ioa_cfg->cfg_table, 0, sizeof(struct ipr_config_table));
  5503. }
  5504. /**
  5505. * ipr_reset_enable_ioa - Enable the IOA following a reset.
  5506. * @ipr_cmd: ipr command struct
  5507. *
  5508. * This function reinitializes some control blocks and
  5509. * enables destructive diagnostics on the adapter.
  5510. *
  5511. * Return value:
  5512. * IPR_RC_JOB_RETURN
  5513. **/
  5514. static int ipr_reset_enable_ioa(struct ipr_cmnd *ipr_cmd)
  5515. {
  5516. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  5517. volatile u32 int_reg;
  5518. ENTER;
  5519. ipr_cmd->job_step = ipr_ioafp_indentify_hrrq;
  5520. ipr_init_ioa_mem(ioa_cfg);
  5521. ioa_cfg->allow_interrupts = 1;
  5522. int_reg = readl(ioa_cfg->regs.sense_interrupt_reg);
  5523. if (int_reg & IPR_PCII_IOA_TRANS_TO_OPER) {
  5524. writel((IPR_PCII_ERROR_INTERRUPTS | IPR_PCII_HRRQ_UPDATED),
  5525. ioa_cfg->regs.clr_interrupt_mask_reg);
  5526. int_reg = readl(ioa_cfg->regs.sense_interrupt_mask_reg);
  5527. return IPR_RC_JOB_CONTINUE;
  5528. }
  5529. /* Enable destructive diagnostics on IOA */
  5530. writel(ioa_cfg->doorbell, ioa_cfg->regs.set_uproc_interrupt_reg);
  5531. writel(IPR_PCII_OPER_INTERRUPTS, ioa_cfg->regs.clr_interrupt_mask_reg);
  5532. int_reg = readl(ioa_cfg->regs.sense_interrupt_mask_reg);
  5533. dev_info(&ioa_cfg->pdev->dev, "Initializing IOA.\n");
  5534. ipr_cmd->timer.data = (unsigned long) ipr_cmd;
  5535. ipr_cmd->timer.expires = jiffies + (ioa_cfg->transop_timeout * HZ);
  5536. ipr_cmd->timer.function = (void (*)(unsigned long))ipr_oper_timeout;
  5537. ipr_cmd->done = ipr_reset_ioa_job;
  5538. add_timer(&ipr_cmd->timer);
  5539. list_add_tail(&ipr_cmd->queue, &ioa_cfg->pending_q);
  5540. LEAVE;
  5541. return IPR_RC_JOB_RETURN;
  5542. }
  5543. /**
  5544. * ipr_reset_wait_for_dump - Wait for a dump to timeout.
  5545. * @ipr_cmd: ipr command struct
  5546. *
  5547. * This function is invoked when an adapter dump has run out
  5548. * of processing time.
  5549. *
  5550. * Return value:
  5551. * IPR_RC_JOB_CONTINUE
  5552. **/
  5553. static int ipr_reset_wait_for_dump(struct ipr_cmnd *ipr_cmd)
  5554. {
  5555. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  5556. if (ioa_cfg->sdt_state == GET_DUMP)
  5557. ioa_cfg->sdt_state = ABORT_DUMP;
  5558. ipr_cmd->job_step = ipr_reset_alert;
  5559. return IPR_RC_JOB_CONTINUE;
  5560. }
  5561. /**
  5562. * ipr_unit_check_no_data - Log a unit check/no data error log
  5563. * @ioa_cfg: ioa config struct
  5564. *
  5565. * Logs an error indicating the adapter unit checked, but for some
  5566. * reason, we were unable to fetch the unit check buffer.
  5567. *
  5568. * Return value:
  5569. * nothing
  5570. **/
  5571. static void ipr_unit_check_no_data(struct ipr_ioa_cfg *ioa_cfg)
  5572. {
  5573. ioa_cfg->errors_logged++;
  5574. dev_err(&ioa_cfg->pdev->dev, "IOA unit check with no data\n");
  5575. }
  5576. /**
  5577. * ipr_get_unit_check_buffer - Get the unit check buffer from the IOA
  5578. * @ioa_cfg: ioa config struct
  5579. *
  5580. * Fetches the unit check buffer from the adapter by clocking the data
  5581. * through the mailbox register.
  5582. *
  5583. * Return value:
  5584. * nothing
  5585. **/
  5586. static void ipr_get_unit_check_buffer(struct ipr_ioa_cfg *ioa_cfg)
  5587. {
  5588. unsigned long mailbox;
  5589. struct ipr_hostrcb *hostrcb;
  5590. struct ipr_uc_sdt sdt;
  5591. int rc, length;
  5592. u32 ioasc;
  5593. mailbox = readl(ioa_cfg->ioa_mailbox);
  5594. if (!ipr_sdt_is_fmt2(mailbox)) {
  5595. ipr_unit_check_no_data(ioa_cfg);
  5596. return;
  5597. }
  5598. memset(&sdt, 0, sizeof(struct ipr_uc_sdt));
  5599. rc = ipr_get_ldump_data_section(ioa_cfg, mailbox, (__be32 *) &sdt,
  5600. (sizeof(struct ipr_uc_sdt)) / sizeof(__be32));
  5601. if (rc || (be32_to_cpu(sdt.hdr.state) != IPR_FMT2_SDT_READY_TO_USE) ||
  5602. !(sdt.entry[0].flags & IPR_SDT_VALID_ENTRY)) {
  5603. ipr_unit_check_no_data(ioa_cfg);
  5604. return;
  5605. }
  5606. /* Find length of the first sdt entry (UC buffer) */
  5607. length = (be32_to_cpu(sdt.entry[0].end_offset) -
  5608. be32_to_cpu(sdt.entry[0].bar_str_offset)) & IPR_FMT2_MBX_ADDR_MASK;
  5609. hostrcb = list_entry(ioa_cfg->hostrcb_free_q.next,
  5610. struct ipr_hostrcb, queue);
  5611. list_del(&hostrcb->queue);
  5612. memset(&hostrcb->hcam, 0, sizeof(hostrcb->hcam));
  5613. rc = ipr_get_ldump_data_section(ioa_cfg,
  5614. be32_to_cpu(sdt.entry[0].bar_str_offset),
  5615. (__be32 *)&hostrcb->hcam,
  5616. min(length, (int)sizeof(hostrcb->hcam)) / sizeof(__be32));
  5617. if (!rc) {
  5618. ipr_handle_log_data(ioa_cfg, hostrcb);
  5619. ioasc = be32_to_cpu(hostrcb->hcam.u.error.failing_dev_ioasc);
  5620. if (ioasc == IPR_IOASC_NR_IOA_RESET_REQUIRED &&
  5621. ioa_cfg->sdt_state == GET_DUMP)
  5622. ioa_cfg->sdt_state = WAIT_FOR_DUMP;
  5623. } else
  5624. ipr_unit_check_no_data(ioa_cfg);
  5625. list_add_tail(&hostrcb->queue, &ioa_cfg->hostrcb_free_q);
  5626. }
  5627. /**
  5628. * ipr_reset_restore_cfg_space - Restore PCI config space.
  5629. * @ipr_cmd: ipr command struct
  5630. *
  5631. * Description: This function restores the saved PCI config space of
  5632. * the adapter, fails all outstanding ops back to the callers, and
  5633. * fetches the dump/unit check if applicable to this reset.
  5634. *
  5635. * Return value:
  5636. * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
  5637. **/
  5638. static int ipr_reset_restore_cfg_space(struct ipr_cmnd *ipr_cmd)
  5639. {
  5640. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  5641. int rc;
  5642. ENTER;
  5643. rc = pci_restore_state(ioa_cfg->pdev);
  5644. if (rc != PCIBIOS_SUCCESSFUL) {
  5645. ipr_cmd->ioasa.ioasc = cpu_to_be32(IPR_IOASC_PCI_ACCESS_ERROR);
  5646. return IPR_RC_JOB_CONTINUE;
  5647. }
  5648. if (ipr_set_pcix_cmd_reg(ioa_cfg)) {
  5649. ipr_cmd->ioasa.ioasc = cpu_to_be32(IPR_IOASC_PCI_ACCESS_ERROR);
  5650. return IPR_RC_JOB_CONTINUE;
  5651. }
  5652. ipr_fail_all_ops(ioa_cfg);
  5653. if (ioa_cfg->ioa_unit_checked) {
  5654. ioa_cfg->ioa_unit_checked = 0;
  5655. ipr_get_unit_check_buffer(ioa_cfg);
  5656. ipr_cmd->job_step = ipr_reset_alert;
  5657. ipr_reset_start_timer(ipr_cmd, 0);
  5658. return IPR_RC_JOB_RETURN;
  5659. }
  5660. if (ioa_cfg->in_ioa_bringdown) {
  5661. ipr_cmd->job_step = ipr_ioa_bringdown_done;
  5662. } else {
  5663. ipr_cmd->job_step = ipr_reset_enable_ioa;
  5664. if (GET_DUMP == ioa_cfg->sdt_state) {
  5665. ipr_reset_start_timer(ipr_cmd, IPR_DUMP_TIMEOUT);
  5666. ipr_cmd->job_step = ipr_reset_wait_for_dump;
  5667. schedule_work(&ioa_cfg->work_q);
  5668. return IPR_RC_JOB_RETURN;
  5669. }
  5670. }
  5671. ENTER;
  5672. return IPR_RC_JOB_CONTINUE;
  5673. }
  5674. /**
  5675. * ipr_reset_bist_done - BIST has completed on the adapter.
  5676. * @ipr_cmd: ipr command struct
  5677. *
  5678. * Description: Unblock config space and resume the reset process.
  5679. *
  5680. * Return value:
  5681. * IPR_RC_JOB_CONTINUE
  5682. **/
  5683. static int ipr_reset_bist_done(struct ipr_cmnd *ipr_cmd)
  5684. {
  5685. ENTER;
  5686. pci_unblock_user_cfg_access(ipr_cmd->ioa_cfg->pdev);
  5687. ipr_cmd->job_step = ipr_reset_restore_cfg_space;
  5688. LEAVE;
  5689. return IPR_RC_JOB_CONTINUE;
  5690. }
  5691. /**
  5692. * ipr_reset_start_bist - Run BIST on the adapter.
  5693. * @ipr_cmd: ipr command struct
  5694. *
  5695. * Description: This function runs BIST on the adapter, then delays 2 seconds.
  5696. *
  5697. * Return value:
  5698. * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
  5699. **/
  5700. static int ipr_reset_start_bist(struct ipr_cmnd *ipr_cmd)
  5701. {
  5702. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  5703. int rc;
  5704. ENTER;
  5705. pci_block_user_cfg_access(ioa_cfg->pdev);
  5706. rc = pci_write_config_byte(ioa_cfg->pdev, PCI_BIST, PCI_BIST_START);
  5707. if (rc != PCIBIOS_SUCCESSFUL) {
  5708. pci_unblock_user_cfg_access(ipr_cmd->ioa_cfg->pdev);
  5709. ipr_cmd->ioasa.ioasc = cpu_to_be32(IPR_IOASC_PCI_ACCESS_ERROR);
  5710. rc = IPR_RC_JOB_CONTINUE;
  5711. } else {
  5712. ipr_cmd->job_step = ipr_reset_bist_done;
  5713. ipr_reset_start_timer(ipr_cmd, IPR_WAIT_FOR_BIST_TIMEOUT);
  5714. rc = IPR_RC_JOB_RETURN;
  5715. }
  5716. LEAVE;
  5717. return rc;
  5718. }
  5719. /**
  5720. * ipr_reset_slot_reset_done - Clear PCI reset to the adapter
  5721. * @ipr_cmd: ipr command struct
  5722. *
  5723. * Description: This clears PCI reset to the adapter and delays two seconds.
  5724. *
  5725. * Return value:
  5726. * IPR_RC_JOB_RETURN
  5727. **/
  5728. static int ipr_reset_slot_reset_done(struct ipr_cmnd *ipr_cmd)
  5729. {
  5730. ENTER;
  5731. pci_set_pcie_reset_state(ipr_cmd->ioa_cfg->pdev, pcie_deassert_reset);
  5732. ipr_cmd->job_step = ipr_reset_bist_done;
  5733. ipr_reset_start_timer(ipr_cmd, IPR_WAIT_FOR_BIST_TIMEOUT);
  5734. LEAVE;
  5735. return IPR_RC_JOB_RETURN;
  5736. }
  5737. /**
  5738. * ipr_reset_slot_reset - Reset the PCI slot of the adapter.
  5739. * @ipr_cmd: ipr command struct
  5740. *
  5741. * Description: This asserts PCI reset to the adapter.
  5742. *
  5743. * Return value:
  5744. * IPR_RC_JOB_RETURN
  5745. **/
  5746. static int ipr_reset_slot_reset(struct ipr_cmnd *ipr_cmd)
  5747. {
  5748. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  5749. struct pci_dev *pdev = ioa_cfg->pdev;
  5750. ENTER;
  5751. pci_block_user_cfg_access(pdev);
  5752. pci_set_pcie_reset_state(pdev, pcie_warm_reset);
  5753. ipr_cmd->job_step = ipr_reset_slot_reset_done;
  5754. ipr_reset_start_timer(ipr_cmd, IPR_PCI_RESET_TIMEOUT);
  5755. LEAVE;
  5756. return IPR_RC_JOB_RETURN;
  5757. }
  5758. /**
  5759. * ipr_reset_allowed - Query whether or not IOA can be reset
  5760. * @ioa_cfg: ioa config struct
  5761. *
  5762. * Return value:
  5763. * 0 if reset not allowed / non-zero if reset is allowed
  5764. **/
  5765. static int ipr_reset_allowed(struct ipr_ioa_cfg *ioa_cfg)
  5766. {
  5767. volatile u32 temp_reg;
  5768. temp_reg = readl(ioa_cfg->regs.sense_interrupt_reg);
  5769. return ((temp_reg & IPR_PCII_CRITICAL_OPERATION) == 0);
  5770. }
  5771. /**
  5772. * ipr_reset_wait_to_start_bist - Wait for permission to reset IOA.
  5773. * @ipr_cmd: ipr command struct
  5774. *
  5775. * Description: This function waits for adapter permission to run BIST,
  5776. * then runs BIST. If the adapter does not give permission after a
  5777. * reasonable time, we will reset the adapter anyway. The impact of
  5778. * resetting the adapter without warning the adapter is the risk of
  5779. * losing the persistent error log on the adapter. If the adapter is
  5780. * reset while it is writing to the flash on the adapter, the flash
  5781. * segment will have bad ECC and be zeroed.
  5782. *
  5783. * Return value:
  5784. * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
  5785. **/
  5786. static int ipr_reset_wait_to_start_bist(struct ipr_cmnd *ipr_cmd)
  5787. {
  5788. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  5789. int rc = IPR_RC_JOB_RETURN;
  5790. if (!ipr_reset_allowed(ioa_cfg) && ipr_cmd->u.time_left) {
  5791. ipr_cmd->u.time_left -= IPR_CHECK_FOR_RESET_TIMEOUT;
  5792. ipr_reset_start_timer(ipr_cmd, IPR_CHECK_FOR_RESET_TIMEOUT);
  5793. } else {
  5794. ipr_cmd->job_step = ioa_cfg->reset;
  5795. rc = IPR_RC_JOB_CONTINUE;
  5796. }
  5797. return rc;
  5798. }
  5799. /**
  5800. * ipr_reset_alert_part2 - Alert the adapter of a pending reset
  5801. * @ipr_cmd: ipr command struct
  5802. *
  5803. * Description: This function alerts the adapter that it will be reset.
  5804. * If memory space is not currently enabled, proceed directly
  5805. * to running BIST on the adapter. The timer must always be started
  5806. * so we guarantee we do not run BIST from ipr_isr.
  5807. *
  5808. * Return value:
  5809. * IPR_RC_JOB_RETURN
  5810. **/
  5811. static int ipr_reset_alert(struct ipr_cmnd *ipr_cmd)
  5812. {
  5813. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  5814. u16 cmd_reg;
  5815. int rc;
  5816. ENTER;
  5817. rc = pci_read_config_word(ioa_cfg->pdev, PCI_COMMAND, &cmd_reg);
  5818. if ((rc == PCIBIOS_SUCCESSFUL) && (cmd_reg & PCI_COMMAND_MEMORY)) {
  5819. ipr_mask_and_clear_interrupts(ioa_cfg, ~0);
  5820. writel(IPR_UPROCI_RESET_ALERT, ioa_cfg->regs.set_uproc_interrupt_reg);
  5821. ipr_cmd->job_step = ipr_reset_wait_to_start_bist;
  5822. } else {
  5823. ipr_cmd->job_step = ioa_cfg->reset;
  5824. }
  5825. ipr_cmd->u.time_left = IPR_WAIT_FOR_RESET_TIMEOUT;
  5826. ipr_reset_start_timer(ipr_cmd, IPR_CHECK_FOR_RESET_TIMEOUT);
  5827. LEAVE;
  5828. return IPR_RC_JOB_RETURN;
  5829. }
  5830. /**
  5831. * ipr_reset_ucode_download_done - Microcode download completion
  5832. * @ipr_cmd: ipr command struct
  5833. *
  5834. * Description: This function unmaps the microcode download buffer.
  5835. *
  5836. * Return value:
  5837. * IPR_RC_JOB_CONTINUE
  5838. **/
  5839. static int ipr_reset_ucode_download_done(struct ipr_cmnd *ipr_cmd)
  5840. {
  5841. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  5842. struct ipr_sglist *sglist = ioa_cfg->ucode_sglist;
  5843. pci_unmap_sg(ioa_cfg->pdev, sglist->scatterlist,
  5844. sglist->num_sg, DMA_TO_DEVICE);
  5845. ipr_cmd->job_step = ipr_reset_alert;
  5846. return IPR_RC_JOB_CONTINUE;
  5847. }
  5848. /**
  5849. * ipr_reset_ucode_download - Download microcode to the adapter
  5850. * @ipr_cmd: ipr command struct
  5851. *
  5852. * Description: This function checks to see if it there is microcode
  5853. * to download to the adapter. If there is, a download is performed.
  5854. *
  5855. * Return value:
  5856. * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
  5857. **/
  5858. static int ipr_reset_ucode_download(struct ipr_cmnd *ipr_cmd)
  5859. {
  5860. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  5861. struct ipr_sglist *sglist = ioa_cfg->ucode_sglist;
  5862. ENTER;
  5863. ipr_cmd->job_step = ipr_reset_alert;
  5864. if (!sglist)
  5865. return IPR_RC_JOB_CONTINUE;
  5866. ipr_cmd->ioarcb.res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
  5867. ipr_cmd->ioarcb.cmd_pkt.request_type = IPR_RQTYPE_SCSICDB;
  5868. ipr_cmd->ioarcb.cmd_pkt.cdb[0] = WRITE_BUFFER;
  5869. ipr_cmd->ioarcb.cmd_pkt.cdb[1] = IPR_WR_BUF_DOWNLOAD_AND_SAVE;
  5870. ipr_cmd->ioarcb.cmd_pkt.cdb[6] = (sglist->buffer_len & 0xff0000) >> 16;
  5871. ipr_cmd->ioarcb.cmd_pkt.cdb[7] = (sglist->buffer_len & 0x00ff00) >> 8;
  5872. ipr_cmd->ioarcb.cmd_pkt.cdb[8] = sglist->buffer_len & 0x0000ff;
  5873. ipr_build_ucode_ioadl(ipr_cmd, sglist);
  5874. ipr_cmd->job_step = ipr_reset_ucode_download_done;
  5875. ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout,
  5876. IPR_WRITE_BUFFER_TIMEOUT);
  5877. LEAVE;
  5878. return IPR_RC_JOB_RETURN;
  5879. }
  5880. /**
  5881. * ipr_reset_shutdown_ioa - Shutdown the adapter
  5882. * @ipr_cmd: ipr command struct
  5883. *
  5884. * Description: This function issues an adapter shutdown of the
  5885. * specified type to the specified adapter as part of the
  5886. * adapter reset job.
  5887. *
  5888. * Return value:
  5889. * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
  5890. **/
  5891. static int ipr_reset_shutdown_ioa(struct ipr_cmnd *ipr_cmd)
  5892. {
  5893. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  5894. enum ipr_shutdown_type shutdown_type = ipr_cmd->u.shutdown_type;
  5895. unsigned long timeout;
  5896. int rc = IPR_RC_JOB_CONTINUE;
  5897. ENTER;
  5898. if (shutdown_type != IPR_SHUTDOWN_NONE && !ioa_cfg->ioa_is_dead) {
  5899. ipr_cmd->ioarcb.res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
  5900. ipr_cmd->ioarcb.cmd_pkt.request_type = IPR_RQTYPE_IOACMD;
  5901. ipr_cmd->ioarcb.cmd_pkt.cdb[0] = IPR_IOA_SHUTDOWN;
  5902. ipr_cmd->ioarcb.cmd_pkt.cdb[1] = shutdown_type;
  5903. if (shutdown_type == IPR_SHUTDOWN_NORMAL)
  5904. timeout = IPR_SHUTDOWN_TIMEOUT;
  5905. else if (shutdown_type == IPR_SHUTDOWN_PREPARE_FOR_NORMAL)
  5906. timeout = IPR_INTERNAL_TIMEOUT;
  5907. else if (ioa_cfg->dual_raid && ipr_dual_ioa_raid)
  5908. timeout = IPR_DUAL_IOA_ABBR_SHUTDOWN_TO;
  5909. else
  5910. timeout = IPR_ABBREV_SHUTDOWN_TIMEOUT;
  5911. ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, timeout);
  5912. rc = IPR_RC_JOB_RETURN;
  5913. ipr_cmd->job_step = ipr_reset_ucode_download;
  5914. } else
  5915. ipr_cmd->job_step = ipr_reset_alert;
  5916. LEAVE;
  5917. return rc;
  5918. }
  5919. /**
  5920. * ipr_reset_ioa_job - Adapter reset job
  5921. * @ipr_cmd: ipr command struct
  5922. *
  5923. * Description: This function is the job router for the adapter reset job.
  5924. *
  5925. * Return value:
  5926. * none
  5927. **/
  5928. static void ipr_reset_ioa_job(struct ipr_cmnd *ipr_cmd)
  5929. {
  5930. u32 rc, ioasc;
  5931. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  5932. do {
  5933. ioasc = be32_to_cpu(ipr_cmd->ioasa.ioasc);
  5934. if (ioa_cfg->reset_cmd != ipr_cmd) {
  5935. /*
  5936. * We are doing nested adapter resets and this is
  5937. * not the current reset job.
  5938. */
  5939. list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
  5940. return;
  5941. }
  5942. if (IPR_IOASC_SENSE_KEY(ioasc)) {
  5943. rc = ipr_cmd->job_step_failed(ipr_cmd);
  5944. if (rc == IPR_RC_JOB_RETURN)
  5945. return;
  5946. }
  5947. ipr_reinit_ipr_cmnd(ipr_cmd);
  5948. ipr_cmd->job_step_failed = ipr_reset_cmd_failed;
  5949. rc = ipr_cmd->job_step(ipr_cmd);
  5950. } while(rc == IPR_RC_JOB_CONTINUE);
  5951. }
  5952. /**
  5953. * _ipr_initiate_ioa_reset - Initiate an adapter reset
  5954. * @ioa_cfg: ioa config struct
  5955. * @job_step: first job step of reset job
  5956. * @shutdown_type: shutdown type
  5957. *
  5958. * Description: This function will initiate the reset of the given adapter
  5959. * starting at the selected job step.
  5960. * If the caller needs to wait on the completion of the reset,
  5961. * the caller must sleep on the reset_wait_q.
  5962. *
  5963. * Return value:
  5964. * none
  5965. **/
  5966. static void _ipr_initiate_ioa_reset(struct ipr_ioa_cfg *ioa_cfg,
  5967. int (*job_step) (struct ipr_cmnd *),
  5968. enum ipr_shutdown_type shutdown_type)
  5969. {
  5970. struct ipr_cmnd *ipr_cmd;
  5971. ioa_cfg->in_reset_reload = 1;
  5972. ioa_cfg->allow_cmds = 0;
  5973. scsi_block_requests(ioa_cfg->host);
  5974. ipr_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
  5975. ioa_cfg->reset_cmd = ipr_cmd;
  5976. ipr_cmd->job_step = job_step;
  5977. ipr_cmd->u.shutdown_type = shutdown_type;
  5978. ipr_reset_ioa_job(ipr_cmd);
  5979. }
  5980. /**
  5981. * ipr_initiate_ioa_reset - Initiate an adapter reset
  5982. * @ioa_cfg: ioa config struct
  5983. * @shutdown_type: shutdown type
  5984. *
  5985. * Description: This function will initiate the reset of the given adapter.
  5986. * If the caller needs to wait on the completion of the reset,
  5987. * the caller must sleep on the reset_wait_q.
  5988. *
  5989. * Return value:
  5990. * none
  5991. **/
  5992. static void ipr_initiate_ioa_reset(struct ipr_ioa_cfg *ioa_cfg,
  5993. enum ipr_shutdown_type shutdown_type)
  5994. {
  5995. if (ioa_cfg->ioa_is_dead)
  5996. return;
  5997. if (ioa_cfg->in_reset_reload && ioa_cfg->sdt_state == GET_DUMP)
  5998. ioa_cfg->sdt_state = ABORT_DUMP;
  5999. if (ioa_cfg->reset_retries++ >= IPR_NUM_RESET_RELOAD_RETRIES) {
  6000. dev_err(&ioa_cfg->pdev->dev,
  6001. "IOA taken offline - error recovery failed\n");
  6002. ioa_cfg->reset_retries = 0;
  6003. ioa_cfg->ioa_is_dead = 1;
  6004. if (ioa_cfg->in_ioa_bringdown) {
  6005. ioa_cfg->reset_cmd = NULL;
  6006. ioa_cfg->in_reset_reload = 0;
  6007. ipr_fail_all_ops(ioa_cfg);
  6008. wake_up_all(&ioa_cfg->reset_wait_q);
  6009. spin_unlock_irq(ioa_cfg->host->host_lock);
  6010. scsi_unblock_requests(ioa_cfg->host);
  6011. spin_lock_irq(ioa_cfg->host->host_lock);
  6012. return;
  6013. } else {
  6014. ioa_cfg->in_ioa_bringdown = 1;
  6015. shutdown_type = IPR_SHUTDOWN_NONE;
  6016. }
  6017. }
  6018. _ipr_initiate_ioa_reset(ioa_cfg, ipr_reset_shutdown_ioa,
  6019. shutdown_type);
  6020. }
  6021. /**
  6022. * ipr_reset_freeze - Hold off all I/O activity
  6023. * @ipr_cmd: ipr command struct
  6024. *
  6025. * Description: If the PCI slot is frozen, hold off all I/O
  6026. * activity; then, as soon as the slot is available again,
  6027. * initiate an adapter reset.
  6028. */
  6029. static int ipr_reset_freeze(struct ipr_cmnd *ipr_cmd)
  6030. {
  6031. /* Disallow new interrupts, avoid loop */
  6032. ipr_cmd->ioa_cfg->allow_interrupts = 0;
  6033. list_add_tail(&ipr_cmd->queue, &ipr_cmd->ioa_cfg->pending_q);
  6034. ipr_cmd->done = ipr_reset_ioa_job;
  6035. return IPR_RC_JOB_RETURN;
  6036. }
  6037. /**
  6038. * ipr_pci_frozen - Called when slot has experienced a PCI bus error.
  6039. * @pdev: PCI device struct
  6040. *
  6041. * Description: This routine is called to tell us that the PCI bus
  6042. * is down. Can't do anything here, except put the device driver
  6043. * into a holding pattern, waiting for the PCI bus to come back.
  6044. */
  6045. static void ipr_pci_frozen(struct pci_dev *pdev)
  6046. {
  6047. unsigned long flags = 0;
  6048. struct ipr_ioa_cfg *ioa_cfg = pci_get_drvdata(pdev);
  6049. spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
  6050. _ipr_initiate_ioa_reset(ioa_cfg, ipr_reset_freeze, IPR_SHUTDOWN_NONE);
  6051. spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
  6052. }
  6053. /**
  6054. * ipr_pci_slot_reset - Called when PCI slot has been reset.
  6055. * @pdev: PCI device struct
  6056. *
  6057. * Description: This routine is called by the pci error recovery
  6058. * code after the PCI slot has been reset, just before we
  6059. * should resume normal operations.
  6060. */
  6061. static pci_ers_result_t ipr_pci_slot_reset(struct pci_dev *pdev)
  6062. {
  6063. unsigned long flags = 0;
  6064. struct ipr_ioa_cfg *ioa_cfg = pci_get_drvdata(pdev);
  6065. spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
  6066. if (ioa_cfg->needs_warm_reset)
  6067. ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
  6068. else
  6069. _ipr_initiate_ioa_reset(ioa_cfg, ipr_reset_restore_cfg_space,
  6070. IPR_SHUTDOWN_NONE);
  6071. spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
  6072. return PCI_ERS_RESULT_RECOVERED;
  6073. }
  6074. /**
  6075. * ipr_pci_perm_failure - Called when PCI slot is dead for good.
  6076. * @pdev: PCI device struct
  6077. *
  6078. * Description: This routine is called when the PCI bus has
  6079. * permanently failed.
  6080. */
  6081. static void ipr_pci_perm_failure(struct pci_dev *pdev)
  6082. {
  6083. unsigned long flags = 0;
  6084. struct ipr_ioa_cfg *ioa_cfg = pci_get_drvdata(pdev);
  6085. spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
  6086. if (ioa_cfg->sdt_state == WAIT_FOR_DUMP)
  6087. ioa_cfg->sdt_state = ABORT_DUMP;
  6088. ioa_cfg->reset_retries = IPR_NUM_RESET_RELOAD_RETRIES;
  6089. ioa_cfg->in_ioa_bringdown = 1;
  6090. ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
  6091. spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
  6092. }
  6093. /**
  6094. * ipr_pci_error_detected - Called when a PCI error is detected.
  6095. * @pdev: PCI device struct
  6096. * @state: PCI channel state
  6097. *
  6098. * Description: Called when a PCI error is detected.
  6099. *
  6100. * Return value:
  6101. * PCI_ERS_RESULT_NEED_RESET or PCI_ERS_RESULT_DISCONNECT
  6102. */
  6103. static pci_ers_result_t ipr_pci_error_detected(struct pci_dev *pdev,
  6104. pci_channel_state_t state)
  6105. {
  6106. switch (state) {
  6107. case pci_channel_io_frozen:
  6108. ipr_pci_frozen(pdev);
  6109. return PCI_ERS_RESULT_NEED_RESET;
  6110. case pci_channel_io_perm_failure:
  6111. ipr_pci_perm_failure(pdev);
  6112. return PCI_ERS_RESULT_DISCONNECT;
  6113. break;
  6114. default:
  6115. break;
  6116. }
  6117. return PCI_ERS_RESULT_NEED_RESET;
  6118. }
  6119. /**
  6120. * ipr_probe_ioa_part2 - Initializes IOAs found in ipr_probe_ioa(..)
  6121. * @ioa_cfg: ioa cfg struct
  6122. *
  6123. * Description: This is the second phase of adapter intialization
  6124. * This function takes care of initilizing the adapter to the point
  6125. * where it can accept new commands.
  6126. * Return value:
  6127. * 0 on success / -EIO on failure
  6128. **/
  6129. static int __devinit ipr_probe_ioa_part2(struct ipr_ioa_cfg *ioa_cfg)
  6130. {
  6131. int rc = 0;
  6132. unsigned long host_lock_flags = 0;
  6133. ENTER;
  6134. spin_lock_irqsave(ioa_cfg->host->host_lock, host_lock_flags);
  6135. dev_dbg(&ioa_cfg->pdev->dev, "ioa_cfg adx: 0x%p\n", ioa_cfg);
  6136. if (ioa_cfg->needs_hard_reset) {
  6137. ioa_cfg->needs_hard_reset = 0;
  6138. ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
  6139. } else
  6140. _ipr_initiate_ioa_reset(ioa_cfg, ipr_reset_enable_ioa,
  6141. IPR_SHUTDOWN_NONE);
  6142. spin_unlock_irqrestore(ioa_cfg->host->host_lock, host_lock_flags);
  6143. wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
  6144. spin_lock_irqsave(ioa_cfg->host->host_lock, host_lock_flags);
  6145. if (ioa_cfg->ioa_is_dead) {
  6146. rc = -EIO;
  6147. } else if (ipr_invalid_adapter(ioa_cfg)) {
  6148. if (!ipr_testmode)
  6149. rc = -EIO;
  6150. dev_err(&ioa_cfg->pdev->dev,
  6151. "Adapter not supported in this hardware configuration.\n");
  6152. }
  6153. spin_unlock_irqrestore(ioa_cfg->host->host_lock, host_lock_flags);
  6154. LEAVE;
  6155. return rc;
  6156. }
  6157. /**
  6158. * ipr_free_cmd_blks - Frees command blocks allocated for an adapter
  6159. * @ioa_cfg: ioa config struct
  6160. *
  6161. * Return value:
  6162. * none
  6163. **/
  6164. static void ipr_free_cmd_blks(struct ipr_ioa_cfg *ioa_cfg)
  6165. {
  6166. int i;
  6167. for (i = 0; i < IPR_NUM_CMD_BLKS; i++) {
  6168. if (ioa_cfg->ipr_cmnd_list[i])
  6169. pci_pool_free(ioa_cfg->ipr_cmd_pool,
  6170. ioa_cfg->ipr_cmnd_list[i],
  6171. ioa_cfg->ipr_cmnd_list_dma[i]);
  6172. ioa_cfg->ipr_cmnd_list[i] = NULL;
  6173. }
  6174. if (ioa_cfg->ipr_cmd_pool)
  6175. pci_pool_destroy (ioa_cfg->ipr_cmd_pool);
  6176. ioa_cfg->ipr_cmd_pool = NULL;
  6177. }
  6178. /**
  6179. * ipr_free_mem - Frees memory allocated for an adapter
  6180. * @ioa_cfg: ioa cfg struct
  6181. *
  6182. * Return value:
  6183. * nothing
  6184. **/
  6185. static void ipr_free_mem(struct ipr_ioa_cfg *ioa_cfg)
  6186. {
  6187. int i;
  6188. kfree(ioa_cfg->res_entries);
  6189. pci_free_consistent(ioa_cfg->pdev, sizeof(struct ipr_misc_cbs),
  6190. ioa_cfg->vpd_cbs, ioa_cfg->vpd_cbs_dma);
  6191. ipr_free_cmd_blks(ioa_cfg);
  6192. pci_free_consistent(ioa_cfg->pdev, sizeof(u32) * IPR_NUM_CMD_BLKS,
  6193. ioa_cfg->host_rrq, ioa_cfg->host_rrq_dma);
  6194. pci_free_consistent(ioa_cfg->pdev, sizeof(struct ipr_config_table),
  6195. ioa_cfg->cfg_table,
  6196. ioa_cfg->cfg_table_dma);
  6197. for (i = 0; i < IPR_NUM_HCAMS; i++) {
  6198. pci_free_consistent(ioa_cfg->pdev,
  6199. sizeof(struct ipr_hostrcb),
  6200. ioa_cfg->hostrcb[i],
  6201. ioa_cfg->hostrcb_dma[i]);
  6202. }
  6203. ipr_free_dump(ioa_cfg);
  6204. kfree(ioa_cfg->trace);
  6205. }
  6206. /**
  6207. * ipr_free_all_resources - Free all allocated resources for an adapter.
  6208. * @ipr_cmd: ipr command struct
  6209. *
  6210. * This function frees all allocated resources for the
  6211. * specified adapter.
  6212. *
  6213. * Return value:
  6214. * none
  6215. **/
  6216. static void ipr_free_all_resources(struct ipr_ioa_cfg *ioa_cfg)
  6217. {
  6218. struct pci_dev *pdev = ioa_cfg->pdev;
  6219. ENTER;
  6220. free_irq(pdev->irq, ioa_cfg);
  6221. iounmap(ioa_cfg->hdw_dma_regs);
  6222. pci_release_regions(pdev);
  6223. ipr_free_mem(ioa_cfg);
  6224. scsi_host_put(ioa_cfg->host);
  6225. pci_disable_device(pdev);
  6226. LEAVE;
  6227. }
  6228. /**
  6229. * ipr_alloc_cmd_blks - Allocate command blocks for an adapter
  6230. * @ioa_cfg: ioa config struct
  6231. *
  6232. * Return value:
  6233. * 0 on success / -ENOMEM on allocation failure
  6234. **/
  6235. static int __devinit ipr_alloc_cmd_blks(struct ipr_ioa_cfg *ioa_cfg)
  6236. {
  6237. struct ipr_cmnd *ipr_cmd;
  6238. struct ipr_ioarcb *ioarcb;
  6239. dma_addr_t dma_addr;
  6240. int i;
  6241. ioa_cfg->ipr_cmd_pool = pci_pool_create (IPR_NAME, ioa_cfg->pdev,
  6242. sizeof(struct ipr_cmnd), 8, 0);
  6243. if (!ioa_cfg->ipr_cmd_pool)
  6244. return -ENOMEM;
  6245. for (i = 0; i < IPR_NUM_CMD_BLKS; i++) {
  6246. ipr_cmd = pci_pool_alloc (ioa_cfg->ipr_cmd_pool, GFP_KERNEL, &dma_addr);
  6247. if (!ipr_cmd) {
  6248. ipr_free_cmd_blks(ioa_cfg);
  6249. return -ENOMEM;
  6250. }
  6251. memset(ipr_cmd, 0, sizeof(*ipr_cmd));
  6252. ioa_cfg->ipr_cmnd_list[i] = ipr_cmd;
  6253. ioa_cfg->ipr_cmnd_list_dma[i] = dma_addr;
  6254. ioarcb = &ipr_cmd->ioarcb;
  6255. ioarcb->ioarcb_host_pci_addr = cpu_to_be32(dma_addr);
  6256. ioarcb->host_response_handle = cpu_to_be32(i << 2);
  6257. ioarcb->write_ioadl_addr =
  6258. cpu_to_be32(dma_addr + offsetof(struct ipr_cmnd, ioadl));
  6259. ioarcb->read_ioadl_addr = ioarcb->write_ioadl_addr;
  6260. ioarcb->ioasa_host_pci_addr =
  6261. cpu_to_be32(dma_addr + offsetof(struct ipr_cmnd, ioasa));
  6262. ioarcb->ioasa_len = cpu_to_be16(sizeof(struct ipr_ioasa));
  6263. ipr_cmd->cmd_index = i;
  6264. ipr_cmd->ioa_cfg = ioa_cfg;
  6265. ipr_cmd->sense_buffer_dma = dma_addr +
  6266. offsetof(struct ipr_cmnd, sense_buffer);
  6267. list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
  6268. }
  6269. return 0;
  6270. }
  6271. /**
  6272. * ipr_alloc_mem - Allocate memory for an adapter
  6273. * @ioa_cfg: ioa config struct
  6274. *
  6275. * Return value:
  6276. * 0 on success / non-zero for error
  6277. **/
  6278. static int __devinit ipr_alloc_mem(struct ipr_ioa_cfg *ioa_cfg)
  6279. {
  6280. struct pci_dev *pdev = ioa_cfg->pdev;
  6281. int i, rc = -ENOMEM;
  6282. ENTER;
  6283. ioa_cfg->res_entries = kzalloc(sizeof(struct ipr_resource_entry) *
  6284. IPR_MAX_PHYSICAL_DEVS, GFP_KERNEL);
  6285. if (!ioa_cfg->res_entries)
  6286. goto out;
  6287. for (i = 0; i < IPR_MAX_PHYSICAL_DEVS; i++)
  6288. list_add_tail(&ioa_cfg->res_entries[i].queue, &ioa_cfg->free_res_q);
  6289. ioa_cfg->vpd_cbs = pci_alloc_consistent(ioa_cfg->pdev,
  6290. sizeof(struct ipr_misc_cbs),
  6291. &ioa_cfg->vpd_cbs_dma);
  6292. if (!ioa_cfg->vpd_cbs)
  6293. goto out_free_res_entries;
  6294. if (ipr_alloc_cmd_blks(ioa_cfg))
  6295. goto out_free_vpd_cbs;
  6296. ioa_cfg->host_rrq = pci_alloc_consistent(ioa_cfg->pdev,
  6297. sizeof(u32) * IPR_NUM_CMD_BLKS,
  6298. &ioa_cfg->host_rrq_dma);
  6299. if (!ioa_cfg->host_rrq)
  6300. goto out_ipr_free_cmd_blocks;
  6301. ioa_cfg->cfg_table = pci_alloc_consistent(ioa_cfg->pdev,
  6302. sizeof(struct ipr_config_table),
  6303. &ioa_cfg->cfg_table_dma);
  6304. if (!ioa_cfg->cfg_table)
  6305. goto out_free_host_rrq;
  6306. for (i = 0; i < IPR_NUM_HCAMS; i++) {
  6307. ioa_cfg->hostrcb[i] = pci_alloc_consistent(ioa_cfg->pdev,
  6308. sizeof(struct ipr_hostrcb),
  6309. &ioa_cfg->hostrcb_dma[i]);
  6310. if (!ioa_cfg->hostrcb[i])
  6311. goto out_free_hostrcb_dma;
  6312. ioa_cfg->hostrcb[i]->hostrcb_dma =
  6313. ioa_cfg->hostrcb_dma[i] + offsetof(struct ipr_hostrcb, hcam);
  6314. ioa_cfg->hostrcb[i]->ioa_cfg = ioa_cfg;
  6315. list_add_tail(&ioa_cfg->hostrcb[i]->queue, &ioa_cfg->hostrcb_free_q);
  6316. }
  6317. ioa_cfg->trace = kzalloc(sizeof(struct ipr_trace_entry) *
  6318. IPR_NUM_TRACE_ENTRIES, GFP_KERNEL);
  6319. if (!ioa_cfg->trace)
  6320. goto out_free_hostrcb_dma;
  6321. rc = 0;
  6322. out:
  6323. LEAVE;
  6324. return rc;
  6325. out_free_hostrcb_dma:
  6326. while (i-- > 0) {
  6327. pci_free_consistent(pdev, sizeof(struct ipr_hostrcb),
  6328. ioa_cfg->hostrcb[i],
  6329. ioa_cfg->hostrcb_dma[i]);
  6330. }
  6331. pci_free_consistent(pdev, sizeof(struct ipr_config_table),
  6332. ioa_cfg->cfg_table, ioa_cfg->cfg_table_dma);
  6333. out_free_host_rrq:
  6334. pci_free_consistent(pdev, sizeof(u32) * IPR_NUM_CMD_BLKS,
  6335. ioa_cfg->host_rrq, ioa_cfg->host_rrq_dma);
  6336. out_ipr_free_cmd_blocks:
  6337. ipr_free_cmd_blks(ioa_cfg);
  6338. out_free_vpd_cbs:
  6339. pci_free_consistent(pdev, sizeof(struct ipr_misc_cbs),
  6340. ioa_cfg->vpd_cbs, ioa_cfg->vpd_cbs_dma);
  6341. out_free_res_entries:
  6342. kfree(ioa_cfg->res_entries);
  6343. goto out;
  6344. }
  6345. /**
  6346. * ipr_initialize_bus_attr - Initialize SCSI bus attributes to default values
  6347. * @ioa_cfg: ioa config struct
  6348. *
  6349. * Return value:
  6350. * none
  6351. **/
  6352. static void __devinit ipr_initialize_bus_attr(struct ipr_ioa_cfg *ioa_cfg)
  6353. {
  6354. int i;
  6355. for (i = 0; i < IPR_MAX_NUM_BUSES; i++) {
  6356. ioa_cfg->bus_attr[i].bus = i;
  6357. ioa_cfg->bus_attr[i].qas_enabled = 0;
  6358. ioa_cfg->bus_attr[i].bus_width = IPR_DEFAULT_BUS_WIDTH;
  6359. if (ipr_max_speed < ARRAY_SIZE(ipr_max_bus_speeds))
  6360. ioa_cfg->bus_attr[i].max_xfer_rate = ipr_max_bus_speeds[ipr_max_speed];
  6361. else
  6362. ioa_cfg->bus_attr[i].max_xfer_rate = IPR_U160_SCSI_RATE;
  6363. }
  6364. }
  6365. /**
  6366. * ipr_init_ioa_cfg - Initialize IOA config struct
  6367. * @ioa_cfg: ioa config struct
  6368. * @host: scsi host struct
  6369. * @pdev: PCI dev struct
  6370. *
  6371. * Return value:
  6372. * none
  6373. **/
  6374. static void __devinit ipr_init_ioa_cfg(struct ipr_ioa_cfg *ioa_cfg,
  6375. struct Scsi_Host *host, struct pci_dev *pdev)
  6376. {
  6377. const struct ipr_interrupt_offsets *p;
  6378. struct ipr_interrupts *t;
  6379. void __iomem *base;
  6380. ioa_cfg->host = host;
  6381. ioa_cfg->pdev = pdev;
  6382. ioa_cfg->log_level = ipr_log_level;
  6383. ioa_cfg->doorbell = IPR_DOORBELL;
  6384. sprintf(ioa_cfg->eye_catcher, IPR_EYECATCHER);
  6385. sprintf(ioa_cfg->trace_start, IPR_TRACE_START_LABEL);
  6386. sprintf(ioa_cfg->ipr_free_label, IPR_FREEQ_LABEL);
  6387. sprintf(ioa_cfg->ipr_pending_label, IPR_PENDQ_LABEL);
  6388. sprintf(ioa_cfg->cfg_table_start, IPR_CFG_TBL_START);
  6389. sprintf(ioa_cfg->resource_table_label, IPR_RES_TABLE_LABEL);
  6390. sprintf(ioa_cfg->ipr_hcam_label, IPR_HCAM_LABEL);
  6391. sprintf(ioa_cfg->ipr_cmd_label, IPR_CMD_LABEL);
  6392. INIT_LIST_HEAD(&ioa_cfg->free_q);
  6393. INIT_LIST_HEAD(&ioa_cfg->pending_q);
  6394. INIT_LIST_HEAD(&ioa_cfg->hostrcb_free_q);
  6395. INIT_LIST_HEAD(&ioa_cfg->hostrcb_pending_q);
  6396. INIT_LIST_HEAD(&ioa_cfg->free_res_q);
  6397. INIT_LIST_HEAD(&ioa_cfg->used_res_q);
  6398. INIT_WORK(&ioa_cfg->work_q, ipr_worker_thread);
  6399. init_waitqueue_head(&ioa_cfg->reset_wait_q);
  6400. ioa_cfg->sdt_state = INACTIVE;
  6401. if (ipr_enable_cache)
  6402. ioa_cfg->cache_state = CACHE_ENABLED;
  6403. else
  6404. ioa_cfg->cache_state = CACHE_DISABLED;
  6405. ipr_initialize_bus_attr(ioa_cfg);
  6406. host->max_id = IPR_MAX_NUM_TARGETS_PER_BUS;
  6407. host->max_lun = IPR_MAX_NUM_LUNS_PER_TARGET;
  6408. host->max_channel = IPR_MAX_BUS_TO_SCAN;
  6409. host->unique_id = host->host_no;
  6410. host->max_cmd_len = IPR_MAX_CDB_LEN;
  6411. pci_set_drvdata(pdev, ioa_cfg);
  6412. p = &ioa_cfg->chip_cfg->regs;
  6413. t = &ioa_cfg->regs;
  6414. base = ioa_cfg->hdw_dma_regs;
  6415. t->set_interrupt_mask_reg = base + p->set_interrupt_mask_reg;
  6416. t->clr_interrupt_mask_reg = base + p->clr_interrupt_mask_reg;
  6417. t->sense_interrupt_mask_reg = base + p->sense_interrupt_mask_reg;
  6418. t->clr_interrupt_reg = base + p->clr_interrupt_reg;
  6419. t->sense_interrupt_reg = base + p->sense_interrupt_reg;
  6420. t->ioarrin_reg = base + p->ioarrin_reg;
  6421. t->sense_uproc_interrupt_reg = base + p->sense_uproc_interrupt_reg;
  6422. t->set_uproc_interrupt_reg = base + p->set_uproc_interrupt_reg;
  6423. t->clr_uproc_interrupt_reg = base + p->clr_uproc_interrupt_reg;
  6424. }
  6425. /**
  6426. * ipr_get_chip_cfg - Find adapter chip configuration
  6427. * @dev_id: PCI device id struct
  6428. *
  6429. * Return value:
  6430. * ptr to chip config on success / NULL on failure
  6431. **/
  6432. static const struct ipr_chip_cfg_t * __devinit
  6433. ipr_get_chip_cfg(const struct pci_device_id *dev_id)
  6434. {
  6435. int i;
  6436. for (i = 0; i < ARRAY_SIZE(ipr_chip); i++)
  6437. if (ipr_chip[i].vendor == dev_id->vendor &&
  6438. ipr_chip[i].device == dev_id->device)
  6439. return ipr_chip[i].cfg;
  6440. return NULL;
  6441. }
  6442. /**
  6443. * ipr_probe_ioa - Allocates memory and does first stage of initialization
  6444. * @pdev: PCI device struct
  6445. * @dev_id: PCI device id struct
  6446. *
  6447. * Return value:
  6448. * 0 on success / non-zero on failure
  6449. **/
  6450. static int __devinit ipr_probe_ioa(struct pci_dev *pdev,
  6451. const struct pci_device_id *dev_id)
  6452. {
  6453. struct ipr_ioa_cfg *ioa_cfg;
  6454. struct Scsi_Host *host;
  6455. unsigned long ipr_regs_pci;
  6456. void __iomem *ipr_regs;
  6457. int rc = PCIBIOS_SUCCESSFUL;
  6458. volatile u32 mask, uproc, interrupts;
  6459. ENTER;
  6460. if ((rc = pci_enable_device(pdev))) {
  6461. dev_err(&pdev->dev, "Cannot enable adapter\n");
  6462. goto out;
  6463. }
  6464. dev_info(&pdev->dev, "Found IOA with IRQ: %d\n", pdev->irq);
  6465. host = scsi_host_alloc(&driver_template, sizeof(*ioa_cfg));
  6466. if (!host) {
  6467. dev_err(&pdev->dev, "call to scsi_host_alloc failed!\n");
  6468. rc = -ENOMEM;
  6469. goto out_disable;
  6470. }
  6471. ioa_cfg = (struct ipr_ioa_cfg *)host->hostdata;
  6472. memset(ioa_cfg, 0, sizeof(struct ipr_ioa_cfg));
  6473. ata_host_init(&ioa_cfg->ata_host, &pdev->dev,
  6474. sata_port_info.flags, &ipr_sata_ops);
  6475. ioa_cfg->chip_cfg = ipr_get_chip_cfg(dev_id);
  6476. if (!ioa_cfg->chip_cfg) {
  6477. dev_err(&pdev->dev, "Unknown adapter chipset 0x%04X 0x%04X\n",
  6478. dev_id->vendor, dev_id->device);
  6479. goto out_scsi_host_put;
  6480. }
  6481. if (ipr_transop_timeout)
  6482. ioa_cfg->transop_timeout = ipr_transop_timeout;
  6483. else if (dev_id->driver_data & IPR_USE_LONG_TRANSOP_TIMEOUT)
  6484. ioa_cfg->transop_timeout = IPR_LONG_OPERATIONAL_TIMEOUT;
  6485. else
  6486. ioa_cfg->transop_timeout = IPR_OPERATIONAL_TIMEOUT;
  6487. ioa_cfg->revid = pdev->revision;
  6488. ipr_regs_pci = pci_resource_start(pdev, 0);
  6489. rc = pci_request_regions(pdev, IPR_NAME);
  6490. if (rc < 0) {
  6491. dev_err(&pdev->dev,
  6492. "Couldn't register memory range of registers\n");
  6493. goto out_scsi_host_put;
  6494. }
  6495. ipr_regs = pci_ioremap_bar(pdev, 0);
  6496. if (!ipr_regs) {
  6497. dev_err(&pdev->dev,
  6498. "Couldn't map memory range of registers\n");
  6499. rc = -ENOMEM;
  6500. goto out_release_regions;
  6501. }
  6502. ioa_cfg->hdw_dma_regs = ipr_regs;
  6503. ioa_cfg->hdw_dma_regs_pci = ipr_regs_pci;
  6504. ioa_cfg->ioa_mailbox = ioa_cfg->chip_cfg->mailbox + ipr_regs;
  6505. ipr_init_ioa_cfg(ioa_cfg, host, pdev);
  6506. pci_set_master(pdev);
  6507. rc = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
  6508. if (rc < 0) {
  6509. dev_err(&pdev->dev, "Failed to set PCI DMA mask\n");
  6510. goto cleanup_nomem;
  6511. }
  6512. rc = pci_write_config_byte(pdev, PCI_CACHE_LINE_SIZE,
  6513. ioa_cfg->chip_cfg->cache_line_size);
  6514. if (rc != PCIBIOS_SUCCESSFUL) {
  6515. dev_err(&pdev->dev, "Write of cache line size failed\n");
  6516. rc = -EIO;
  6517. goto cleanup_nomem;
  6518. }
  6519. /* Save away PCI config space for use following IOA reset */
  6520. rc = pci_save_state(pdev);
  6521. if (rc != PCIBIOS_SUCCESSFUL) {
  6522. dev_err(&pdev->dev, "Failed to save PCI config space\n");
  6523. rc = -EIO;
  6524. goto cleanup_nomem;
  6525. }
  6526. if ((rc = ipr_save_pcix_cmd_reg(ioa_cfg)))
  6527. goto cleanup_nomem;
  6528. if ((rc = ipr_set_pcix_cmd_reg(ioa_cfg)))
  6529. goto cleanup_nomem;
  6530. rc = ipr_alloc_mem(ioa_cfg);
  6531. if (rc < 0) {
  6532. dev_err(&pdev->dev,
  6533. "Couldn't allocate enough memory for device driver!\n");
  6534. goto cleanup_nomem;
  6535. }
  6536. /*
  6537. * If HRRQ updated interrupt is not masked, or reset alert is set,
  6538. * the card is in an unknown state and needs a hard reset
  6539. */
  6540. mask = readl(ioa_cfg->regs.sense_interrupt_mask_reg);
  6541. interrupts = readl(ioa_cfg->regs.sense_interrupt_reg);
  6542. uproc = readl(ioa_cfg->regs.sense_uproc_interrupt_reg);
  6543. if ((mask & IPR_PCII_HRRQ_UPDATED) == 0 || (uproc & IPR_UPROCI_RESET_ALERT))
  6544. ioa_cfg->needs_hard_reset = 1;
  6545. if (interrupts & IPR_PCII_ERROR_INTERRUPTS)
  6546. ioa_cfg->needs_hard_reset = 1;
  6547. if (interrupts & IPR_PCII_IOA_UNIT_CHECKED)
  6548. ioa_cfg->ioa_unit_checked = 1;
  6549. ipr_mask_and_clear_interrupts(ioa_cfg, ~IPR_PCII_IOA_TRANS_TO_OPER);
  6550. rc = request_irq(pdev->irq, ipr_isr, IRQF_SHARED, IPR_NAME, ioa_cfg);
  6551. if (rc) {
  6552. dev_err(&pdev->dev, "Couldn't register IRQ %d! rc=%d\n",
  6553. pdev->irq, rc);
  6554. goto cleanup_nolog;
  6555. }
  6556. if ((dev_id->driver_data & IPR_USE_PCI_WARM_RESET) ||
  6557. (dev_id->device == PCI_DEVICE_ID_IBM_OBSIDIAN_E && !ioa_cfg->revid)) {
  6558. ioa_cfg->needs_warm_reset = 1;
  6559. ioa_cfg->reset = ipr_reset_slot_reset;
  6560. } else
  6561. ioa_cfg->reset = ipr_reset_start_bist;
  6562. spin_lock(&ipr_driver_lock);
  6563. list_add_tail(&ioa_cfg->queue, &ipr_ioa_head);
  6564. spin_unlock(&ipr_driver_lock);
  6565. LEAVE;
  6566. out:
  6567. return rc;
  6568. cleanup_nolog:
  6569. ipr_free_mem(ioa_cfg);
  6570. cleanup_nomem:
  6571. iounmap(ipr_regs);
  6572. out_release_regions:
  6573. pci_release_regions(pdev);
  6574. out_scsi_host_put:
  6575. scsi_host_put(host);
  6576. out_disable:
  6577. pci_disable_device(pdev);
  6578. goto out;
  6579. }
  6580. /**
  6581. * ipr_scan_vsets - Scans for VSET devices
  6582. * @ioa_cfg: ioa config struct
  6583. *
  6584. * Description: Since the VSET resources do not follow SAM in that we can have
  6585. * sparse LUNs with no LUN 0, we have to scan for these ourselves.
  6586. *
  6587. * Return value:
  6588. * none
  6589. **/
  6590. static void ipr_scan_vsets(struct ipr_ioa_cfg *ioa_cfg)
  6591. {
  6592. int target, lun;
  6593. for (target = 0; target < IPR_MAX_NUM_TARGETS_PER_BUS; target++)
  6594. for (lun = 0; lun < IPR_MAX_NUM_VSET_LUNS_PER_TARGET; lun++ )
  6595. scsi_add_device(ioa_cfg->host, IPR_VSET_BUS, target, lun);
  6596. }
  6597. /**
  6598. * ipr_initiate_ioa_bringdown - Bring down an adapter
  6599. * @ioa_cfg: ioa config struct
  6600. * @shutdown_type: shutdown type
  6601. *
  6602. * Description: This function will initiate bringing down the adapter.
  6603. * This consists of issuing an IOA shutdown to the adapter
  6604. * to flush the cache, and running BIST.
  6605. * If the caller needs to wait on the completion of the reset,
  6606. * the caller must sleep on the reset_wait_q.
  6607. *
  6608. * Return value:
  6609. * none
  6610. **/
  6611. static void ipr_initiate_ioa_bringdown(struct ipr_ioa_cfg *ioa_cfg,
  6612. enum ipr_shutdown_type shutdown_type)
  6613. {
  6614. ENTER;
  6615. if (ioa_cfg->sdt_state == WAIT_FOR_DUMP)
  6616. ioa_cfg->sdt_state = ABORT_DUMP;
  6617. ioa_cfg->reset_retries = 0;
  6618. ioa_cfg->in_ioa_bringdown = 1;
  6619. ipr_initiate_ioa_reset(ioa_cfg, shutdown_type);
  6620. LEAVE;
  6621. }
  6622. /**
  6623. * __ipr_remove - Remove a single adapter
  6624. * @pdev: pci device struct
  6625. *
  6626. * Adapter hot plug remove entry point.
  6627. *
  6628. * Return value:
  6629. * none
  6630. **/
  6631. static void __ipr_remove(struct pci_dev *pdev)
  6632. {
  6633. unsigned long host_lock_flags = 0;
  6634. struct ipr_ioa_cfg *ioa_cfg = pci_get_drvdata(pdev);
  6635. ENTER;
  6636. spin_lock_irqsave(ioa_cfg->host->host_lock, host_lock_flags);
  6637. while(ioa_cfg->in_reset_reload) {
  6638. spin_unlock_irqrestore(ioa_cfg->host->host_lock, host_lock_flags);
  6639. wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
  6640. spin_lock_irqsave(ioa_cfg->host->host_lock, host_lock_flags);
  6641. }
  6642. ipr_initiate_ioa_bringdown(ioa_cfg, IPR_SHUTDOWN_NORMAL);
  6643. spin_unlock_irqrestore(ioa_cfg->host->host_lock, host_lock_flags);
  6644. wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
  6645. flush_scheduled_work();
  6646. spin_lock_irqsave(ioa_cfg->host->host_lock, host_lock_flags);
  6647. spin_lock(&ipr_driver_lock);
  6648. list_del(&ioa_cfg->queue);
  6649. spin_unlock(&ipr_driver_lock);
  6650. if (ioa_cfg->sdt_state == ABORT_DUMP)
  6651. ioa_cfg->sdt_state = WAIT_FOR_DUMP;
  6652. spin_unlock_irqrestore(ioa_cfg->host->host_lock, host_lock_flags);
  6653. ipr_free_all_resources(ioa_cfg);
  6654. LEAVE;
  6655. }
  6656. /**
  6657. * ipr_remove - IOA hot plug remove entry point
  6658. * @pdev: pci device struct
  6659. *
  6660. * Adapter hot plug remove entry point.
  6661. *
  6662. * Return value:
  6663. * none
  6664. **/
  6665. static void ipr_remove(struct pci_dev *pdev)
  6666. {
  6667. struct ipr_ioa_cfg *ioa_cfg = pci_get_drvdata(pdev);
  6668. ENTER;
  6669. ipr_remove_trace_file(&ioa_cfg->host->shost_dev.kobj,
  6670. &ipr_trace_attr);
  6671. ipr_remove_dump_file(&ioa_cfg->host->shost_dev.kobj,
  6672. &ipr_dump_attr);
  6673. scsi_remove_host(ioa_cfg->host);
  6674. __ipr_remove(pdev);
  6675. LEAVE;
  6676. }
  6677. /**
  6678. * ipr_probe - Adapter hot plug add entry point
  6679. *
  6680. * Return value:
  6681. * 0 on success / non-zero on failure
  6682. **/
  6683. static int __devinit ipr_probe(struct pci_dev *pdev,
  6684. const struct pci_device_id *dev_id)
  6685. {
  6686. struct ipr_ioa_cfg *ioa_cfg;
  6687. int rc;
  6688. rc = ipr_probe_ioa(pdev, dev_id);
  6689. if (rc)
  6690. return rc;
  6691. ioa_cfg = pci_get_drvdata(pdev);
  6692. rc = ipr_probe_ioa_part2(ioa_cfg);
  6693. if (rc) {
  6694. __ipr_remove(pdev);
  6695. return rc;
  6696. }
  6697. rc = scsi_add_host(ioa_cfg->host, &pdev->dev);
  6698. if (rc) {
  6699. __ipr_remove(pdev);
  6700. return rc;
  6701. }
  6702. rc = ipr_create_trace_file(&ioa_cfg->host->shost_dev.kobj,
  6703. &ipr_trace_attr);
  6704. if (rc) {
  6705. scsi_remove_host(ioa_cfg->host);
  6706. __ipr_remove(pdev);
  6707. return rc;
  6708. }
  6709. rc = ipr_create_dump_file(&ioa_cfg->host->shost_dev.kobj,
  6710. &ipr_dump_attr);
  6711. if (rc) {
  6712. ipr_remove_trace_file(&ioa_cfg->host->shost_dev.kobj,
  6713. &ipr_trace_attr);
  6714. scsi_remove_host(ioa_cfg->host);
  6715. __ipr_remove(pdev);
  6716. return rc;
  6717. }
  6718. scsi_scan_host(ioa_cfg->host);
  6719. ipr_scan_vsets(ioa_cfg);
  6720. scsi_add_device(ioa_cfg->host, IPR_IOA_BUS, IPR_IOA_TARGET, IPR_IOA_LUN);
  6721. ioa_cfg->allow_ml_add_del = 1;
  6722. ioa_cfg->host->max_channel = IPR_VSET_BUS;
  6723. schedule_work(&ioa_cfg->work_q);
  6724. return 0;
  6725. }
  6726. /**
  6727. * ipr_shutdown - Shutdown handler.
  6728. * @pdev: pci device struct
  6729. *
  6730. * This function is invoked upon system shutdown/reboot. It will issue
  6731. * an adapter shutdown to the adapter to flush the write cache.
  6732. *
  6733. * Return value:
  6734. * none
  6735. **/
  6736. static void ipr_shutdown(struct pci_dev *pdev)
  6737. {
  6738. struct ipr_ioa_cfg *ioa_cfg = pci_get_drvdata(pdev);
  6739. unsigned long lock_flags = 0;
  6740. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  6741. while(ioa_cfg->in_reset_reload) {
  6742. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  6743. wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
  6744. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  6745. }
  6746. ipr_initiate_ioa_bringdown(ioa_cfg, IPR_SHUTDOWN_NORMAL);
  6747. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  6748. wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
  6749. }
  6750. static struct pci_device_id ipr_pci_table[] __devinitdata = {
  6751. { PCI_VENDOR_ID_MYLEX, PCI_DEVICE_ID_IBM_GEMSTONE,
  6752. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_5702, 0, 0, 0 },
  6753. { PCI_VENDOR_ID_MYLEX, PCI_DEVICE_ID_IBM_GEMSTONE,
  6754. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_5703, 0, 0, 0 },
  6755. { PCI_VENDOR_ID_MYLEX, PCI_DEVICE_ID_IBM_GEMSTONE,
  6756. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_573D, 0, 0, 0 },
  6757. { PCI_VENDOR_ID_MYLEX, PCI_DEVICE_ID_IBM_GEMSTONE,
  6758. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_573E, 0, 0, 0 },
  6759. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CITRINE,
  6760. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_571B, 0, 0, 0 },
  6761. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CITRINE,
  6762. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_572E, 0, 0, 0 },
  6763. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CITRINE,
  6764. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_571A, 0, 0, 0 },
  6765. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CITRINE,
  6766. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_575B, 0, 0,
  6767. IPR_USE_LONG_TRANSOP_TIMEOUT },
  6768. { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_OBSIDIAN,
  6769. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_572A, 0, 0, 0 },
  6770. { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_OBSIDIAN,
  6771. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_572B, 0, 0,
  6772. IPR_USE_LONG_TRANSOP_TIMEOUT },
  6773. { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_OBSIDIAN,
  6774. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_575C, 0, 0,
  6775. IPR_USE_LONG_TRANSOP_TIMEOUT },
  6776. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN,
  6777. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_572A, 0, 0, 0 },
  6778. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN,
  6779. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_572B, 0, 0,
  6780. IPR_USE_LONG_TRANSOP_TIMEOUT},
  6781. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN,
  6782. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_575C, 0, 0,
  6783. IPR_USE_LONG_TRANSOP_TIMEOUT },
  6784. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN_E,
  6785. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_574E, 0, 0,
  6786. IPR_USE_LONG_TRANSOP_TIMEOUT },
  6787. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN_E,
  6788. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_575D, 0, 0,
  6789. IPR_USE_LONG_TRANSOP_TIMEOUT },
  6790. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN_E,
  6791. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57B3, 0, 0, 0 },
  6792. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN_E,
  6793. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57B7, 0, 0,
  6794. IPR_USE_LONG_TRANSOP_TIMEOUT | IPR_USE_PCI_WARM_RESET },
  6795. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_SNIPE,
  6796. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_2780, 0, 0, 0 },
  6797. { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_SCAMP,
  6798. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_571E, 0, 0, 0 },
  6799. { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_SCAMP,
  6800. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_571F, 0, 0,
  6801. IPR_USE_LONG_TRANSOP_TIMEOUT },
  6802. { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_SCAMP,
  6803. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_572F, 0, 0,
  6804. IPR_USE_LONG_TRANSOP_TIMEOUT },
  6805. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_SCAMP_E,
  6806. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_574D, 0, 0,
  6807. IPR_USE_LONG_TRANSOP_TIMEOUT },
  6808. { }
  6809. };
  6810. MODULE_DEVICE_TABLE(pci, ipr_pci_table);
  6811. static struct pci_error_handlers ipr_err_handler = {
  6812. .error_detected = ipr_pci_error_detected,
  6813. .slot_reset = ipr_pci_slot_reset,
  6814. };
  6815. static struct pci_driver ipr_driver = {
  6816. .name = IPR_NAME,
  6817. .id_table = ipr_pci_table,
  6818. .probe = ipr_probe,
  6819. .remove = ipr_remove,
  6820. .shutdown = ipr_shutdown,
  6821. .err_handler = &ipr_err_handler,
  6822. };
  6823. /**
  6824. * ipr_init - Module entry point
  6825. *
  6826. * Return value:
  6827. * 0 on success / negative value on failure
  6828. **/
  6829. static int __init ipr_init(void)
  6830. {
  6831. ipr_info("IBM Power RAID SCSI Device Driver version: %s %s\n",
  6832. IPR_DRIVER_VERSION, IPR_DRIVER_DATE);
  6833. return pci_register_driver(&ipr_driver);
  6834. }
  6835. /**
  6836. * ipr_exit - Module unload
  6837. *
  6838. * Module unload entry point.
  6839. *
  6840. * Return value:
  6841. * none
  6842. **/
  6843. static void __exit ipr_exit(void)
  6844. {
  6845. pci_unregister_driver(&ipr_driver);
  6846. }
  6847. module_init(ipr_init);
  6848. module_exit(ipr_exit);