ipr.c 217 KB

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