ipr.c 200 KB

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