ipr.c 247 KB

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