ipr.c 182 KB

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