ipr.c 171 KB

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