qla_os.c 160 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870
  1. /*
  2. * QLogic Fibre Channel HBA Driver
  3. * Copyright (c) 2003-2014 QLogic Corporation
  4. *
  5. * See LICENSE.qla2xxx for copyright and licensing details.
  6. */
  7. #include "qla_def.h"
  8. #include <linux/moduleparam.h>
  9. #include <linux/vmalloc.h>
  10. #include <linux/delay.h>
  11. #include <linux/kthread.h>
  12. #include <linux/mutex.h>
  13. #include <linux/kobject.h>
  14. #include <linux/slab.h>
  15. #include <scsi/scsi_tcq.h>
  16. #include <scsi/scsicam.h>
  17. #include <scsi/scsi_transport.h>
  18. #include <scsi/scsi_transport_fc.h>
  19. #include "qla_target.h"
  20. /*
  21. * Driver version
  22. */
  23. char qla2x00_version_str[40];
  24. static int apidev_major;
  25. /*
  26. * SRB allocation cache
  27. */
  28. static struct kmem_cache *srb_cachep;
  29. /*
  30. * CT6 CTX allocation cache
  31. */
  32. static struct kmem_cache *ctx_cachep;
  33. /*
  34. * error level for logging
  35. */
  36. int ql_errlev = ql_log_all;
  37. static int ql2xenableclass2;
  38. module_param(ql2xenableclass2, int, S_IRUGO|S_IRUSR);
  39. MODULE_PARM_DESC(ql2xenableclass2,
  40. "Specify if Class 2 operations are supported from the very "
  41. "beginning. Default is 0 - class 2 not supported.");
  42. int ql2xlogintimeout = 20;
  43. module_param(ql2xlogintimeout, int, S_IRUGO);
  44. MODULE_PARM_DESC(ql2xlogintimeout,
  45. "Login timeout value in seconds.");
  46. int qlport_down_retry;
  47. module_param(qlport_down_retry, int, S_IRUGO);
  48. MODULE_PARM_DESC(qlport_down_retry,
  49. "Maximum number of command retries to a port that returns "
  50. "a PORT-DOWN status.");
  51. int ql2xplogiabsentdevice;
  52. module_param(ql2xplogiabsentdevice, int, S_IRUGO|S_IWUSR);
  53. MODULE_PARM_DESC(ql2xplogiabsentdevice,
  54. "Option to enable PLOGI to devices that are not present after "
  55. "a Fabric scan. This is needed for several broken switches. "
  56. "Default is 0 - no PLOGI. 1 - perfom PLOGI.");
  57. int ql2xloginretrycount = 0;
  58. module_param(ql2xloginretrycount, int, S_IRUGO);
  59. MODULE_PARM_DESC(ql2xloginretrycount,
  60. "Specify an alternate value for the NVRAM login retry count.");
  61. int ql2xallocfwdump = 1;
  62. module_param(ql2xallocfwdump, int, S_IRUGO);
  63. MODULE_PARM_DESC(ql2xallocfwdump,
  64. "Option to enable allocation of memory for a firmware dump "
  65. "during HBA initialization. Memory allocation requirements "
  66. "vary by ISP type. Default is 1 - allocate memory.");
  67. int ql2xextended_error_logging;
  68. module_param(ql2xextended_error_logging, int, S_IRUGO|S_IWUSR);
  69. MODULE_PARM_DESC(ql2xextended_error_logging,
  70. "Option to enable extended error logging,\n"
  71. "\t\tDefault is 0 - no logging. 0x40000000 - Module Init & Probe.\n"
  72. "\t\t0x20000000 - Mailbox Cmnds. 0x10000000 - Device Discovery.\n"
  73. "\t\t0x08000000 - IO tracing. 0x04000000 - DPC Thread.\n"
  74. "\t\t0x02000000 - Async events. 0x01000000 - Timer routines.\n"
  75. "\t\t0x00800000 - User space. 0x00400000 - Task Management.\n"
  76. "\t\t0x00200000 - AER/EEH. 0x00100000 - Multi Q.\n"
  77. "\t\t0x00080000 - P3P Specific. 0x00040000 - Virtual Port.\n"
  78. "\t\t0x00020000 - Buffer Dump. 0x00010000 - Misc.\n"
  79. "\t\t0x00008000 - Verbose. 0x00004000 - Target.\n"
  80. "\t\t0x00002000 - Target Mgmt. 0x00001000 - Target TMF.\n"
  81. "\t\t0x7fffffff - For enabling all logs, can be too many logs.\n"
  82. "\t\t0x1e400000 - Preferred value for capturing essential "
  83. "debug information (equivalent to old "
  84. "ql2xextended_error_logging=1).\n"
  85. "\t\tDo LOGICAL OR of the value to enable more than one level");
  86. int ql2xshiftctondsd = 6;
  87. module_param(ql2xshiftctondsd, int, S_IRUGO);
  88. MODULE_PARM_DESC(ql2xshiftctondsd,
  89. "Set to control shifting of command type processing "
  90. "based on total number of SG elements.");
  91. int ql2xfdmienable=1;
  92. module_param(ql2xfdmienable, int, S_IRUGO|S_IWUSR);
  93. MODULE_PARM_DESC(ql2xfdmienable,
  94. "Enables FDMI registrations. "
  95. "0 - no FDMI. Default is 1 - perform FDMI.");
  96. #define MAX_Q_DEPTH 32
  97. static int ql2xmaxqdepth = MAX_Q_DEPTH;
  98. module_param(ql2xmaxqdepth, int, S_IRUGO|S_IWUSR);
  99. MODULE_PARM_DESC(ql2xmaxqdepth,
  100. "Maximum queue depth to set for each LUN. "
  101. "Default is 32.");
  102. int ql2xenabledif = 2;
  103. module_param(ql2xenabledif, int, S_IRUGO);
  104. MODULE_PARM_DESC(ql2xenabledif,
  105. " Enable T10-CRC-DIF:\n"
  106. " Default is 2.\n"
  107. " 0 -- No DIF Support\n"
  108. " 1 -- Enable DIF for all types\n"
  109. " 2 -- Enable DIF for all types, except Type 0.\n");
  110. int ql2xenablehba_err_chk = 2;
  111. module_param(ql2xenablehba_err_chk, int, S_IRUGO|S_IWUSR);
  112. MODULE_PARM_DESC(ql2xenablehba_err_chk,
  113. " Enable T10-CRC-DIF Error isolation by HBA:\n"
  114. " Default is 2.\n"
  115. " 0 -- Error isolation disabled\n"
  116. " 1 -- Error isolation enabled only for DIX Type 0\n"
  117. " 2 -- Error isolation enabled for all Types\n");
  118. int ql2xiidmaenable=1;
  119. module_param(ql2xiidmaenable, int, S_IRUGO);
  120. MODULE_PARM_DESC(ql2xiidmaenable,
  121. "Enables iIDMA settings "
  122. "Default is 1 - perform iIDMA. 0 - no iIDMA.");
  123. int ql2xmaxqueues = 1;
  124. module_param(ql2xmaxqueues, int, S_IRUGO);
  125. MODULE_PARM_DESC(ql2xmaxqueues,
  126. "Enables MQ settings "
  127. "Default is 1 for single queue. Set it to number "
  128. "of queues in MQ mode.");
  129. int ql2xmultique_tag;
  130. module_param(ql2xmultique_tag, int, S_IRUGO);
  131. MODULE_PARM_DESC(ql2xmultique_tag,
  132. "Enables CPU affinity settings for the driver "
  133. "Default is 0 for no affinity of request and response IO. "
  134. "Set it to 1 to turn on the cpu affinity.");
  135. int ql2xfwloadbin;
  136. module_param(ql2xfwloadbin, int, S_IRUGO|S_IWUSR);
  137. MODULE_PARM_DESC(ql2xfwloadbin,
  138. "Option to specify location from which to load ISP firmware:.\n"
  139. " 2 -- load firmware via the request_firmware() (hotplug).\n"
  140. " interface.\n"
  141. " 1 -- load firmware from flash.\n"
  142. " 0 -- use default semantics.\n");
  143. int ql2xetsenable;
  144. module_param(ql2xetsenable, int, S_IRUGO);
  145. MODULE_PARM_DESC(ql2xetsenable,
  146. "Enables firmware ETS burst."
  147. "Default is 0 - skip ETS enablement.");
  148. int ql2xdbwr = 1;
  149. module_param(ql2xdbwr, int, S_IRUGO|S_IWUSR);
  150. MODULE_PARM_DESC(ql2xdbwr,
  151. "Option to specify scheme for request queue posting.\n"
  152. " 0 -- Regular doorbell.\n"
  153. " 1 -- CAMRAM doorbell (faster).\n");
  154. int ql2xtargetreset = 1;
  155. module_param(ql2xtargetreset, int, S_IRUGO);
  156. MODULE_PARM_DESC(ql2xtargetreset,
  157. "Enable target reset."
  158. "Default is 1 - use hw defaults.");
  159. int ql2xgffidenable;
  160. module_param(ql2xgffidenable, int, S_IRUGO);
  161. MODULE_PARM_DESC(ql2xgffidenable,
  162. "Enables GFF_ID checks of port type. "
  163. "Default is 0 - Do not use GFF_ID information.");
  164. int ql2xasynctmfenable;
  165. module_param(ql2xasynctmfenable, int, S_IRUGO);
  166. MODULE_PARM_DESC(ql2xasynctmfenable,
  167. "Enables issue of TM IOCBs asynchronously via IOCB mechanism"
  168. "Default is 0 - Issue TM IOCBs via mailbox mechanism.");
  169. int ql2xdontresethba;
  170. module_param(ql2xdontresethba, int, S_IRUGO|S_IWUSR);
  171. MODULE_PARM_DESC(ql2xdontresethba,
  172. "Option to specify reset behaviour.\n"
  173. " 0 (Default) -- Reset on failure.\n"
  174. " 1 -- Do not reset on failure.\n");
  175. uint64_t ql2xmaxlun = MAX_LUNS;
  176. module_param(ql2xmaxlun, ullong, S_IRUGO);
  177. MODULE_PARM_DESC(ql2xmaxlun,
  178. "Defines the maximum LU number to register with the SCSI "
  179. "midlayer. Default is 65535.");
  180. int ql2xmdcapmask = 0x1F;
  181. module_param(ql2xmdcapmask, int, S_IRUGO);
  182. MODULE_PARM_DESC(ql2xmdcapmask,
  183. "Set the Minidump driver capture mask level. "
  184. "Default is 0x1F - Can be set to 0x3, 0x7, 0xF, 0x1F, 0x7F.");
  185. int ql2xmdenable = 1;
  186. module_param(ql2xmdenable, int, S_IRUGO);
  187. MODULE_PARM_DESC(ql2xmdenable,
  188. "Enable/disable MiniDump. "
  189. "0 - MiniDump disabled. "
  190. "1 (Default) - MiniDump enabled.");
  191. /*
  192. * SCSI host template entry points
  193. */
  194. static int qla2xxx_slave_configure(struct scsi_device * device);
  195. static int qla2xxx_slave_alloc(struct scsi_device *);
  196. static int qla2xxx_scan_finished(struct Scsi_Host *, unsigned long time);
  197. static void qla2xxx_scan_start(struct Scsi_Host *);
  198. static void qla2xxx_slave_destroy(struct scsi_device *);
  199. static int qla2xxx_queuecommand(struct Scsi_Host *h, struct scsi_cmnd *cmd);
  200. static int qla2xxx_eh_abort(struct scsi_cmnd *);
  201. static int qla2xxx_eh_device_reset(struct scsi_cmnd *);
  202. static int qla2xxx_eh_target_reset(struct scsi_cmnd *);
  203. static int qla2xxx_eh_bus_reset(struct scsi_cmnd *);
  204. static int qla2xxx_eh_host_reset(struct scsi_cmnd *);
  205. static void qla2x00_clear_drv_active(struct qla_hw_data *);
  206. static void qla2x00_free_device(scsi_qla_host_t *);
  207. static void qla83xx_disable_laser(scsi_qla_host_t *vha);
  208. struct scsi_host_template qla2xxx_driver_template = {
  209. .module = THIS_MODULE,
  210. .name = QLA2XXX_DRIVER_NAME,
  211. .queuecommand = qla2xxx_queuecommand,
  212. .eh_abort_handler = qla2xxx_eh_abort,
  213. .eh_device_reset_handler = qla2xxx_eh_device_reset,
  214. .eh_target_reset_handler = qla2xxx_eh_target_reset,
  215. .eh_bus_reset_handler = qla2xxx_eh_bus_reset,
  216. .eh_host_reset_handler = qla2xxx_eh_host_reset,
  217. .slave_configure = qla2xxx_slave_configure,
  218. .slave_alloc = qla2xxx_slave_alloc,
  219. .slave_destroy = qla2xxx_slave_destroy,
  220. .scan_finished = qla2xxx_scan_finished,
  221. .scan_start = qla2xxx_scan_start,
  222. .change_queue_depth = scsi_change_queue_depth,
  223. .this_id = -1,
  224. .cmd_per_lun = 3,
  225. .use_clustering = ENABLE_CLUSTERING,
  226. .sg_tablesize = SG_ALL,
  227. .max_sectors = 0xFFFF,
  228. .shost_attrs = qla2x00_host_attrs,
  229. .supported_mode = MODE_INITIATOR,
  230. .track_queue_depth = 1,
  231. };
  232. static struct scsi_transport_template *qla2xxx_transport_template = NULL;
  233. struct scsi_transport_template *qla2xxx_transport_vport_template = NULL;
  234. /* TODO Convert to inlines
  235. *
  236. * Timer routines
  237. */
  238. __inline__ void
  239. qla2x00_start_timer(scsi_qla_host_t *vha, void *func, unsigned long interval)
  240. {
  241. init_timer(&vha->timer);
  242. vha->timer.expires = jiffies + interval * HZ;
  243. vha->timer.data = (unsigned long)vha;
  244. vha->timer.function = (void (*)(unsigned long))func;
  245. add_timer(&vha->timer);
  246. vha->timer_active = 1;
  247. }
  248. static inline void
  249. qla2x00_restart_timer(scsi_qla_host_t *vha, unsigned long interval)
  250. {
  251. /* Currently used for 82XX only. */
  252. if (vha->device_flags & DFLG_DEV_FAILED) {
  253. ql_dbg(ql_dbg_timer, vha, 0x600d,
  254. "Device in a failed state, returning.\n");
  255. return;
  256. }
  257. mod_timer(&vha->timer, jiffies + interval * HZ);
  258. }
  259. static __inline__ void
  260. qla2x00_stop_timer(scsi_qla_host_t *vha)
  261. {
  262. del_timer_sync(&vha->timer);
  263. vha->timer_active = 0;
  264. }
  265. static int qla2x00_do_dpc(void *data);
  266. static void qla2x00_rst_aen(scsi_qla_host_t *);
  267. static int qla2x00_mem_alloc(struct qla_hw_data *, uint16_t, uint16_t,
  268. struct req_que **, struct rsp_que **);
  269. static void qla2x00_free_fw_dump(struct qla_hw_data *);
  270. static void qla2x00_mem_free(struct qla_hw_data *);
  271. /* -------------------------------------------------------------------------- */
  272. static int qla2x00_alloc_queues(struct qla_hw_data *ha, struct req_que *req,
  273. struct rsp_que *rsp)
  274. {
  275. scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev);
  276. ha->req_q_map = kzalloc(sizeof(struct req_que *) * ha->max_req_queues,
  277. GFP_KERNEL);
  278. if (!ha->req_q_map) {
  279. ql_log(ql_log_fatal, vha, 0x003b,
  280. "Unable to allocate memory for request queue ptrs.\n");
  281. goto fail_req_map;
  282. }
  283. ha->rsp_q_map = kzalloc(sizeof(struct rsp_que *) * ha->max_rsp_queues,
  284. GFP_KERNEL);
  285. if (!ha->rsp_q_map) {
  286. ql_log(ql_log_fatal, vha, 0x003c,
  287. "Unable to allocate memory for response queue ptrs.\n");
  288. goto fail_rsp_map;
  289. }
  290. /*
  291. * Make sure we record at least the request and response queue zero in
  292. * case we need to free them if part of the probe fails.
  293. */
  294. ha->rsp_q_map[0] = rsp;
  295. ha->req_q_map[0] = req;
  296. set_bit(0, ha->rsp_qid_map);
  297. set_bit(0, ha->req_qid_map);
  298. return 1;
  299. fail_rsp_map:
  300. kfree(ha->req_q_map);
  301. ha->req_q_map = NULL;
  302. fail_req_map:
  303. return -ENOMEM;
  304. }
  305. static void qla2x00_free_req_que(struct qla_hw_data *ha, struct req_que *req)
  306. {
  307. if (IS_QLAFX00(ha)) {
  308. if (req && req->ring_fx00)
  309. dma_free_coherent(&ha->pdev->dev,
  310. (req->length_fx00 + 1) * sizeof(request_t),
  311. req->ring_fx00, req->dma_fx00);
  312. } else if (req && req->ring)
  313. dma_free_coherent(&ha->pdev->dev,
  314. (req->length + 1) * sizeof(request_t),
  315. req->ring, req->dma);
  316. if (req)
  317. kfree(req->outstanding_cmds);
  318. kfree(req);
  319. req = NULL;
  320. }
  321. static void qla2x00_free_rsp_que(struct qla_hw_data *ha, struct rsp_que *rsp)
  322. {
  323. if (IS_QLAFX00(ha)) {
  324. if (rsp && rsp->ring)
  325. dma_free_coherent(&ha->pdev->dev,
  326. (rsp->length_fx00 + 1) * sizeof(request_t),
  327. rsp->ring_fx00, rsp->dma_fx00);
  328. } else if (rsp && rsp->ring) {
  329. dma_free_coherent(&ha->pdev->dev,
  330. (rsp->length + 1) * sizeof(response_t),
  331. rsp->ring, rsp->dma);
  332. }
  333. kfree(rsp);
  334. rsp = NULL;
  335. }
  336. static void qla2x00_free_queues(struct qla_hw_data *ha)
  337. {
  338. struct req_que *req;
  339. struct rsp_que *rsp;
  340. int cnt;
  341. for (cnt = 0; cnt < ha->max_req_queues; cnt++) {
  342. if (!test_bit(cnt, ha->req_qid_map))
  343. continue;
  344. req = ha->req_q_map[cnt];
  345. qla2x00_free_req_que(ha, req);
  346. }
  347. kfree(ha->req_q_map);
  348. ha->req_q_map = NULL;
  349. for (cnt = 0; cnt < ha->max_rsp_queues; cnt++) {
  350. if (!test_bit(cnt, ha->rsp_qid_map))
  351. continue;
  352. rsp = ha->rsp_q_map[cnt];
  353. qla2x00_free_rsp_que(ha, rsp);
  354. }
  355. kfree(ha->rsp_q_map);
  356. ha->rsp_q_map = NULL;
  357. }
  358. static int qla25xx_setup_mode(struct scsi_qla_host *vha)
  359. {
  360. uint16_t options = 0;
  361. int ques, req, ret;
  362. struct qla_hw_data *ha = vha->hw;
  363. if (!(ha->fw_attributes & BIT_6)) {
  364. ql_log(ql_log_warn, vha, 0x00d8,
  365. "Firmware is not multi-queue capable.\n");
  366. goto fail;
  367. }
  368. if (ql2xmultique_tag) {
  369. /* create a request queue for IO */
  370. options |= BIT_7;
  371. req = qla25xx_create_req_que(ha, options, 0, 0, -1,
  372. QLA_DEFAULT_QUE_QOS);
  373. if (!req) {
  374. ql_log(ql_log_warn, vha, 0x00e0,
  375. "Failed to create request queue.\n");
  376. goto fail;
  377. }
  378. ha->wq = alloc_workqueue("qla2xxx_wq", WQ_MEM_RECLAIM, 1);
  379. vha->req = ha->req_q_map[req];
  380. options |= BIT_1;
  381. for (ques = 1; ques < ha->max_rsp_queues; ques++) {
  382. ret = qla25xx_create_rsp_que(ha, options, 0, 0, req);
  383. if (!ret) {
  384. ql_log(ql_log_warn, vha, 0x00e8,
  385. "Failed to create response queue.\n");
  386. goto fail2;
  387. }
  388. }
  389. ha->flags.cpu_affinity_enabled = 1;
  390. ql_dbg(ql_dbg_multiq, vha, 0xc007,
  391. "CPU affinity mode enabled, "
  392. "no. of response queues:%d no. of request queues:%d.\n",
  393. ha->max_rsp_queues, ha->max_req_queues);
  394. ql_dbg(ql_dbg_init, vha, 0x00e9,
  395. "CPU affinity mode enabled, "
  396. "no. of response queues:%d no. of request queues:%d.\n",
  397. ha->max_rsp_queues, ha->max_req_queues);
  398. }
  399. return 0;
  400. fail2:
  401. qla25xx_delete_queues(vha);
  402. destroy_workqueue(ha->wq);
  403. ha->wq = NULL;
  404. vha->req = ha->req_q_map[0];
  405. fail:
  406. ha->mqenable = 0;
  407. kfree(ha->req_q_map);
  408. kfree(ha->rsp_q_map);
  409. ha->max_req_queues = ha->max_rsp_queues = 1;
  410. return 1;
  411. }
  412. static char *
  413. qla2x00_pci_info_str(struct scsi_qla_host *vha, char *str)
  414. {
  415. struct qla_hw_data *ha = vha->hw;
  416. static char *pci_bus_modes[] = {
  417. "33", "66", "100", "133",
  418. };
  419. uint16_t pci_bus;
  420. strcpy(str, "PCI");
  421. pci_bus = (ha->pci_attr & (BIT_9 | BIT_10)) >> 9;
  422. if (pci_bus) {
  423. strcat(str, "-X (");
  424. strcat(str, pci_bus_modes[pci_bus]);
  425. } else {
  426. pci_bus = (ha->pci_attr & BIT_8) >> 8;
  427. strcat(str, " (");
  428. strcat(str, pci_bus_modes[pci_bus]);
  429. }
  430. strcat(str, " MHz)");
  431. return (str);
  432. }
  433. static char *
  434. qla24xx_pci_info_str(struct scsi_qla_host *vha, char *str)
  435. {
  436. static char *pci_bus_modes[] = { "33", "66", "100", "133", };
  437. struct qla_hw_data *ha = vha->hw;
  438. uint32_t pci_bus;
  439. if (pci_is_pcie(ha->pdev)) {
  440. char lwstr[6];
  441. uint32_t lstat, lspeed, lwidth;
  442. pcie_capability_read_dword(ha->pdev, PCI_EXP_LNKCAP, &lstat);
  443. lspeed = lstat & PCI_EXP_LNKCAP_SLS;
  444. lwidth = (lstat & PCI_EXP_LNKCAP_MLW) >> 4;
  445. strcpy(str, "PCIe (");
  446. switch (lspeed) {
  447. case 1:
  448. strcat(str, "2.5GT/s ");
  449. break;
  450. case 2:
  451. strcat(str, "5.0GT/s ");
  452. break;
  453. case 3:
  454. strcat(str, "8.0GT/s ");
  455. break;
  456. default:
  457. strcat(str, "<unknown> ");
  458. break;
  459. }
  460. snprintf(lwstr, sizeof(lwstr), "x%d)", lwidth);
  461. strcat(str, lwstr);
  462. return str;
  463. }
  464. strcpy(str, "PCI");
  465. pci_bus = (ha->pci_attr & CSRX_PCIX_BUS_MODE_MASK) >> 8;
  466. if (pci_bus == 0 || pci_bus == 8) {
  467. strcat(str, " (");
  468. strcat(str, pci_bus_modes[pci_bus >> 3]);
  469. } else {
  470. strcat(str, "-X ");
  471. if (pci_bus & BIT_2)
  472. strcat(str, "Mode 2");
  473. else
  474. strcat(str, "Mode 1");
  475. strcat(str, " (");
  476. strcat(str, pci_bus_modes[pci_bus & ~BIT_2]);
  477. }
  478. strcat(str, " MHz)");
  479. return str;
  480. }
  481. static char *
  482. qla2x00_fw_version_str(struct scsi_qla_host *vha, char *str, size_t size)
  483. {
  484. char un_str[10];
  485. struct qla_hw_data *ha = vha->hw;
  486. snprintf(str, size, "%d.%02d.%02d ", ha->fw_major_version,
  487. ha->fw_minor_version, ha->fw_subminor_version);
  488. if (ha->fw_attributes & BIT_9) {
  489. strcat(str, "FLX");
  490. return (str);
  491. }
  492. switch (ha->fw_attributes & 0xFF) {
  493. case 0x7:
  494. strcat(str, "EF");
  495. break;
  496. case 0x17:
  497. strcat(str, "TP");
  498. break;
  499. case 0x37:
  500. strcat(str, "IP");
  501. break;
  502. case 0x77:
  503. strcat(str, "VI");
  504. break;
  505. default:
  506. sprintf(un_str, "(%x)", ha->fw_attributes);
  507. strcat(str, un_str);
  508. break;
  509. }
  510. if (ha->fw_attributes & 0x100)
  511. strcat(str, "X");
  512. return (str);
  513. }
  514. static char *
  515. qla24xx_fw_version_str(struct scsi_qla_host *vha, char *str, size_t size)
  516. {
  517. struct qla_hw_data *ha = vha->hw;
  518. snprintf(str, size, "%d.%02d.%02d (%x)", ha->fw_major_version,
  519. ha->fw_minor_version, ha->fw_subminor_version, ha->fw_attributes);
  520. return str;
  521. }
  522. void
  523. qla2x00_sp_free_dma(void *vha, void *ptr)
  524. {
  525. srb_t *sp = (srb_t *)ptr;
  526. struct scsi_cmnd *cmd = GET_CMD_SP(sp);
  527. struct qla_hw_data *ha = sp->fcport->vha->hw;
  528. void *ctx = GET_CMD_CTX_SP(sp);
  529. if (sp->flags & SRB_DMA_VALID) {
  530. scsi_dma_unmap(cmd);
  531. sp->flags &= ~SRB_DMA_VALID;
  532. }
  533. if (sp->flags & SRB_CRC_PROT_DMA_VALID) {
  534. dma_unmap_sg(&ha->pdev->dev, scsi_prot_sglist(cmd),
  535. scsi_prot_sg_count(cmd), cmd->sc_data_direction);
  536. sp->flags &= ~SRB_CRC_PROT_DMA_VALID;
  537. }
  538. if (sp->flags & SRB_CRC_CTX_DSD_VALID) {
  539. /* List assured to be having elements */
  540. qla2x00_clean_dsd_pool(ha, sp, NULL);
  541. sp->flags &= ~SRB_CRC_CTX_DSD_VALID;
  542. }
  543. if (sp->flags & SRB_CRC_CTX_DMA_VALID) {
  544. dma_pool_free(ha->dl_dma_pool, ctx,
  545. ((struct crc_context *)ctx)->crc_ctx_dma);
  546. sp->flags &= ~SRB_CRC_CTX_DMA_VALID;
  547. }
  548. if (sp->flags & SRB_FCP_CMND_DMA_VALID) {
  549. struct ct6_dsd *ctx1 = (struct ct6_dsd *)ctx;
  550. dma_pool_free(ha->fcp_cmnd_dma_pool, ctx1->fcp_cmnd,
  551. ctx1->fcp_cmnd_dma);
  552. list_splice(&ctx1->dsd_list, &ha->gbl_dsd_list);
  553. ha->gbl_dsd_inuse -= ctx1->dsd_use_cnt;
  554. ha->gbl_dsd_avail += ctx1->dsd_use_cnt;
  555. mempool_free(ctx1, ha->ctx_mempool);
  556. ctx1 = NULL;
  557. }
  558. CMD_SP(cmd) = NULL;
  559. qla2x00_rel_sp(sp->fcport->vha, sp);
  560. }
  561. static void
  562. qla2x00_sp_compl(void *data, void *ptr, int res)
  563. {
  564. struct qla_hw_data *ha = (struct qla_hw_data *)data;
  565. srb_t *sp = (srb_t *)ptr;
  566. struct scsi_cmnd *cmd = GET_CMD_SP(sp);
  567. cmd->result = res;
  568. if (atomic_read(&sp->ref_count) == 0) {
  569. ql_dbg(ql_dbg_io, sp->fcport->vha, 0x3015,
  570. "SP reference-count to ZERO -- sp=%p cmd=%p.\n",
  571. sp, GET_CMD_SP(sp));
  572. if (ql2xextended_error_logging & ql_dbg_io)
  573. WARN_ON(atomic_read(&sp->ref_count) == 0);
  574. return;
  575. }
  576. if (!atomic_dec_and_test(&sp->ref_count))
  577. return;
  578. qla2x00_sp_free_dma(ha, sp);
  579. cmd->scsi_done(cmd);
  580. }
  581. /* If we are SP1 here, we need to still take and release the host_lock as SP1
  582. * does not have the changes necessary to avoid taking host->host_lock.
  583. */
  584. static int
  585. qla2xxx_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd)
  586. {
  587. scsi_qla_host_t *vha = shost_priv(host);
  588. fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
  589. struct fc_rport *rport = starget_to_rport(scsi_target(cmd->device));
  590. struct qla_hw_data *ha = vha->hw;
  591. struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
  592. srb_t *sp;
  593. int rval;
  594. if (unlikely(test_bit(UNLOADING, &base_vha->dpc_flags))) {
  595. cmd->result = DID_NO_CONNECT << 16;
  596. goto qc24_fail_command;
  597. }
  598. if (ha->flags.eeh_busy) {
  599. if (ha->flags.pci_channel_io_perm_failure) {
  600. ql_dbg(ql_dbg_aer, vha, 0x9010,
  601. "PCI Channel IO permanent failure, exiting "
  602. "cmd=%p.\n", cmd);
  603. cmd->result = DID_NO_CONNECT << 16;
  604. } else {
  605. ql_dbg(ql_dbg_aer, vha, 0x9011,
  606. "EEH_Busy, Requeuing the cmd=%p.\n", cmd);
  607. cmd->result = DID_REQUEUE << 16;
  608. }
  609. goto qc24_fail_command;
  610. }
  611. rval = fc_remote_port_chkready(rport);
  612. if (rval) {
  613. cmd->result = rval;
  614. ql_dbg(ql_dbg_io + ql_dbg_verbose, vha, 0x3003,
  615. "fc_remote_port_chkready failed for cmd=%p, rval=0x%x.\n",
  616. cmd, rval);
  617. goto qc24_fail_command;
  618. }
  619. if (!vha->flags.difdix_supported &&
  620. scsi_get_prot_op(cmd) != SCSI_PROT_NORMAL) {
  621. ql_dbg(ql_dbg_io, vha, 0x3004,
  622. "DIF Cap not reg, fail DIF capable cmd's:%p.\n",
  623. cmd);
  624. cmd->result = DID_NO_CONNECT << 16;
  625. goto qc24_fail_command;
  626. }
  627. if (!fcport) {
  628. cmd->result = DID_NO_CONNECT << 16;
  629. goto qc24_fail_command;
  630. }
  631. if (atomic_read(&fcport->state) != FCS_ONLINE) {
  632. if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
  633. atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
  634. ql_dbg(ql_dbg_io, vha, 0x3005,
  635. "Returning DNC, fcport_state=%d loop_state=%d.\n",
  636. atomic_read(&fcport->state),
  637. atomic_read(&base_vha->loop_state));
  638. cmd->result = DID_NO_CONNECT << 16;
  639. goto qc24_fail_command;
  640. }
  641. goto qc24_target_busy;
  642. }
  643. /*
  644. * Return target busy if we've received a non-zero retry_delay_timer
  645. * in a FCP_RSP.
  646. */
  647. if (fcport->retry_delay_timestamp == 0) {
  648. /* retry delay not set */
  649. } else if (time_after(jiffies, fcport->retry_delay_timestamp))
  650. fcport->retry_delay_timestamp = 0;
  651. else
  652. goto qc24_target_busy;
  653. sp = qla2x00_get_sp(vha, fcport, GFP_ATOMIC);
  654. if (!sp)
  655. goto qc24_host_busy;
  656. sp->u.scmd.cmd = cmd;
  657. sp->type = SRB_SCSI_CMD;
  658. atomic_set(&sp->ref_count, 1);
  659. CMD_SP(cmd) = (void *)sp;
  660. sp->free = qla2x00_sp_free_dma;
  661. sp->done = qla2x00_sp_compl;
  662. rval = ha->isp_ops->start_scsi(sp);
  663. if (rval != QLA_SUCCESS) {
  664. ql_dbg(ql_dbg_io + ql_dbg_verbose, vha, 0x3013,
  665. "Start scsi failed rval=%d for cmd=%p.\n", rval, cmd);
  666. goto qc24_host_busy_free_sp;
  667. }
  668. return 0;
  669. qc24_host_busy_free_sp:
  670. qla2x00_sp_free_dma(ha, sp);
  671. qc24_host_busy:
  672. return SCSI_MLQUEUE_HOST_BUSY;
  673. qc24_target_busy:
  674. return SCSI_MLQUEUE_TARGET_BUSY;
  675. qc24_fail_command:
  676. cmd->scsi_done(cmd);
  677. return 0;
  678. }
  679. /*
  680. * qla2x00_eh_wait_on_command
  681. * Waits for the command to be returned by the Firmware for some
  682. * max time.
  683. *
  684. * Input:
  685. * cmd = Scsi Command to wait on.
  686. *
  687. * Return:
  688. * Not Found : 0
  689. * Found : 1
  690. */
  691. static int
  692. qla2x00_eh_wait_on_command(struct scsi_cmnd *cmd)
  693. {
  694. #define ABORT_POLLING_PERIOD 1000
  695. #define ABORT_WAIT_ITER ((2 * 1000) / (ABORT_POLLING_PERIOD))
  696. unsigned long wait_iter = ABORT_WAIT_ITER;
  697. scsi_qla_host_t *vha = shost_priv(cmd->device->host);
  698. struct qla_hw_data *ha = vha->hw;
  699. int ret = QLA_SUCCESS;
  700. if (unlikely(pci_channel_offline(ha->pdev)) || ha->flags.eeh_busy) {
  701. ql_dbg(ql_dbg_taskm, vha, 0x8005,
  702. "Return:eh_wait.\n");
  703. return ret;
  704. }
  705. while (CMD_SP(cmd) && wait_iter--) {
  706. msleep(ABORT_POLLING_PERIOD);
  707. }
  708. if (CMD_SP(cmd))
  709. ret = QLA_FUNCTION_FAILED;
  710. return ret;
  711. }
  712. /*
  713. * qla2x00_wait_for_hba_online
  714. * Wait till the HBA is online after going through
  715. * <= MAX_RETRIES_OF_ISP_ABORT or
  716. * finally HBA is disabled ie marked offline
  717. *
  718. * Input:
  719. * ha - pointer to host adapter structure
  720. *
  721. * Note:
  722. * Does context switching-Release SPIN_LOCK
  723. * (if any) before calling this routine.
  724. *
  725. * Return:
  726. * Success (Adapter is online) : 0
  727. * Failed (Adapter is offline/disabled) : 1
  728. */
  729. int
  730. qla2x00_wait_for_hba_online(scsi_qla_host_t *vha)
  731. {
  732. int return_status;
  733. unsigned long wait_online;
  734. struct qla_hw_data *ha = vha->hw;
  735. scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
  736. wait_online = jiffies + (MAX_LOOP_TIMEOUT * HZ);
  737. while (((test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) ||
  738. test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) ||
  739. test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) ||
  740. ha->dpc_active) && time_before(jiffies, wait_online)) {
  741. msleep(1000);
  742. }
  743. if (base_vha->flags.online)
  744. return_status = QLA_SUCCESS;
  745. else
  746. return_status = QLA_FUNCTION_FAILED;
  747. return (return_status);
  748. }
  749. /*
  750. * qla2x00_wait_for_hba_ready
  751. * Wait till the HBA is ready before doing driver unload
  752. *
  753. * Input:
  754. * ha - pointer to host adapter structure
  755. *
  756. * Note:
  757. * Does context switching-Release SPIN_LOCK
  758. * (if any) before calling this routine.
  759. *
  760. */
  761. static void
  762. qla2x00_wait_for_hba_ready(scsi_qla_host_t *vha)
  763. {
  764. struct qla_hw_data *ha = vha->hw;
  765. while (((qla2x00_reset_active(vha)) || ha->dpc_active ||
  766. ha->flags.mbox_busy) ||
  767. test_bit(FX00_RESET_RECOVERY, &vha->dpc_flags) ||
  768. test_bit(FX00_TARGET_SCAN, &vha->dpc_flags))
  769. msleep(1000);
  770. }
  771. int
  772. qla2x00_wait_for_chip_reset(scsi_qla_host_t *vha)
  773. {
  774. int return_status;
  775. unsigned long wait_reset;
  776. struct qla_hw_data *ha = vha->hw;
  777. scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
  778. wait_reset = jiffies + (MAX_LOOP_TIMEOUT * HZ);
  779. while (((test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) ||
  780. test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) ||
  781. test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) ||
  782. ha->dpc_active) && time_before(jiffies, wait_reset)) {
  783. msleep(1000);
  784. if (!test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags) &&
  785. ha->flags.chip_reset_done)
  786. break;
  787. }
  788. if (ha->flags.chip_reset_done)
  789. return_status = QLA_SUCCESS;
  790. else
  791. return_status = QLA_FUNCTION_FAILED;
  792. return return_status;
  793. }
  794. static void
  795. sp_get(struct srb *sp)
  796. {
  797. atomic_inc(&sp->ref_count);
  798. }
  799. /**************************************************************************
  800. * qla2xxx_eh_abort
  801. *
  802. * Description:
  803. * The abort function will abort the specified command.
  804. *
  805. * Input:
  806. * cmd = Linux SCSI command packet to be aborted.
  807. *
  808. * Returns:
  809. * Either SUCCESS or FAILED.
  810. *
  811. * Note:
  812. * Only return FAILED if command not returned by firmware.
  813. **************************************************************************/
  814. static int
  815. qla2xxx_eh_abort(struct scsi_cmnd *cmd)
  816. {
  817. scsi_qla_host_t *vha = shost_priv(cmd->device->host);
  818. srb_t *sp;
  819. int ret;
  820. unsigned int id;
  821. uint64_t lun;
  822. unsigned long flags;
  823. int rval, wait = 0;
  824. struct qla_hw_data *ha = vha->hw;
  825. if (!CMD_SP(cmd))
  826. return SUCCESS;
  827. ret = fc_block_scsi_eh(cmd);
  828. if (ret != 0)
  829. return ret;
  830. ret = SUCCESS;
  831. id = cmd->device->id;
  832. lun = cmd->device->lun;
  833. spin_lock_irqsave(&ha->hardware_lock, flags);
  834. sp = (srb_t *) CMD_SP(cmd);
  835. if (!sp) {
  836. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  837. return SUCCESS;
  838. }
  839. ql_dbg(ql_dbg_taskm, vha, 0x8002,
  840. "Aborting from RISC nexus=%ld:%d:%llu sp=%p cmd=%p handle=%x\n",
  841. vha->host_no, id, lun, sp, cmd, sp->handle);
  842. /* Get a reference to the sp and drop the lock.*/
  843. sp_get(sp);
  844. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  845. rval = ha->isp_ops->abort_command(sp);
  846. if (rval) {
  847. if (rval == QLA_FUNCTION_PARAMETER_ERROR)
  848. ret = SUCCESS;
  849. else
  850. ret = FAILED;
  851. ql_dbg(ql_dbg_taskm, vha, 0x8003,
  852. "Abort command mbx failed cmd=%p, rval=%x.\n", cmd, rval);
  853. } else {
  854. ql_dbg(ql_dbg_taskm, vha, 0x8004,
  855. "Abort command mbx success cmd=%p.\n", cmd);
  856. wait = 1;
  857. }
  858. spin_lock_irqsave(&ha->hardware_lock, flags);
  859. sp->done(ha, sp, 0);
  860. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  861. /* Did the command return during mailbox execution? */
  862. if (ret == FAILED && !CMD_SP(cmd))
  863. ret = SUCCESS;
  864. /* Wait for the command to be returned. */
  865. if (wait) {
  866. if (qla2x00_eh_wait_on_command(cmd) != QLA_SUCCESS) {
  867. ql_log(ql_log_warn, vha, 0x8006,
  868. "Abort handler timed out cmd=%p.\n", cmd);
  869. ret = FAILED;
  870. }
  871. }
  872. ql_log(ql_log_info, vha, 0x801c,
  873. "Abort command issued nexus=%ld:%d:%llu -- %d %x.\n",
  874. vha->host_no, id, lun, wait, ret);
  875. return ret;
  876. }
  877. int
  878. qla2x00_eh_wait_for_pending_commands(scsi_qla_host_t *vha, unsigned int t,
  879. uint64_t l, enum nexus_wait_type type)
  880. {
  881. int cnt, match, status;
  882. unsigned long flags;
  883. struct qla_hw_data *ha = vha->hw;
  884. struct req_que *req;
  885. srb_t *sp;
  886. struct scsi_cmnd *cmd;
  887. status = QLA_SUCCESS;
  888. spin_lock_irqsave(&ha->hardware_lock, flags);
  889. req = vha->req;
  890. for (cnt = 1; status == QLA_SUCCESS &&
  891. cnt < req->num_outstanding_cmds; cnt++) {
  892. sp = req->outstanding_cmds[cnt];
  893. if (!sp)
  894. continue;
  895. if (sp->type != SRB_SCSI_CMD)
  896. continue;
  897. if (vha->vp_idx != sp->fcport->vha->vp_idx)
  898. continue;
  899. match = 0;
  900. cmd = GET_CMD_SP(sp);
  901. switch (type) {
  902. case WAIT_HOST:
  903. match = 1;
  904. break;
  905. case WAIT_TARGET:
  906. match = cmd->device->id == t;
  907. break;
  908. case WAIT_LUN:
  909. match = (cmd->device->id == t &&
  910. cmd->device->lun == l);
  911. break;
  912. }
  913. if (!match)
  914. continue;
  915. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  916. status = qla2x00_eh_wait_on_command(cmd);
  917. spin_lock_irqsave(&ha->hardware_lock, flags);
  918. }
  919. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  920. return status;
  921. }
  922. static char *reset_errors[] = {
  923. "HBA not online",
  924. "HBA not ready",
  925. "Task management failed",
  926. "Waiting for command completions",
  927. };
  928. static int
  929. __qla2xxx_eh_generic_reset(char *name, enum nexus_wait_type type,
  930. struct scsi_cmnd *cmd, int (*do_reset)(struct fc_port *, uint64_t, int))
  931. {
  932. scsi_qla_host_t *vha = shost_priv(cmd->device->host);
  933. fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
  934. int err;
  935. if (!fcport) {
  936. return FAILED;
  937. }
  938. err = fc_block_scsi_eh(cmd);
  939. if (err != 0)
  940. return err;
  941. ql_log(ql_log_info, vha, 0x8009,
  942. "%s RESET ISSUED nexus=%ld:%d:%llu cmd=%p.\n", name, vha->host_no,
  943. cmd->device->id, cmd->device->lun, cmd);
  944. err = 0;
  945. if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
  946. ql_log(ql_log_warn, vha, 0x800a,
  947. "Wait for hba online failed for cmd=%p.\n", cmd);
  948. goto eh_reset_failed;
  949. }
  950. err = 2;
  951. if (do_reset(fcport, cmd->device->lun, cmd->request->cpu + 1)
  952. != QLA_SUCCESS) {
  953. ql_log(ql_log_warn, vha, 0x800c,
  954. "do_reset failed for cmd=%p.\n", cmd);
  955. goto eh_reset_failed;
  956. }
  957. err = 3;
  958. if (qla2x00_eh_wait_for_pending_commands(vha, cmd->device->id,
  959. cmd->device->lun, type) != QLA_SUCCESS) {
  960. ql_log(ql_log_warn, vha, 0x800d,
  961. "wait for pending cmds failed for cmd=%p.\n", cmd);
  962. goto eh_reset_failed;
  963. }
  964. ql_log(ql_log_info, vha, 0x800e,
  965. "%s RESET SUCCEEDED nexus:%ld:%d:%llu cmd=%p.\n", name,
  966. vha->host_no, cmd->device->id, cmd->device->lun, cmd);
  967. return SUCCESS;
  968. eh_reset_failed:
  969. ql_log(ql_log_info, vha, 0x800f,
  970. "%s RESET FAILED: %s nexus=%ld:%d:%llu cmd=%p.\n", name,
  971. reset_errors[err], vha->host_no, cmd->device->id, cmd->device->lun,
  972. cmd);
  973. return FAILED;
  974. }
  975. static int
  976. qla2xxx_eh_device_reset(struct scsi_cmnd *cmd)
  977. {
  978. scsi_qla_host_t *vha = shost_priv(cmd->device->host);
  979. struct qla_hw_data *ha = vha->hw;
  980. return __qla2xxx_eh_generic_reset("DEVICE", WAIT_LUN, cmd,
  981. ha->isp_ops->lun_reset);
  982. }
  983. static int
  984. qla2xxx_eh_target_reset(struct scsi_cmnd *cmd)
  985. {
  986. scsi_qla_host_t *vha = shost_priv(cmd->device->host);
  987. struct qla_hw_data *ha = vha->hw;
  988. return __qla2xxx_eh_generic_reset("TARGET", WAIT_TARGET, cmd,
  989. ha->isp_ops->target_reset);
  990. }
  991. /**************************************************************************
  992. * qla2xxx_eh_bus_reset
  993. *
  994. * Description:
  995. * The bus reset function will reset the bus and abort any executing
  996. * commands.
  997. *
  998. * Input:
  999. * cmd = Linux SCSI command packet of the command that cause the
  1000. * bus reset.
  1001. *
  1002. * Returns:
  1003. * SUCCESS/FAILURE (defined as macro in scsi.h).
  1004. *
  1005. **************************************************************************/
  1006. static int
  1007. qla2xxx_eh_bus_reset(struct scsi_cmnd *cmd)
  1008. {
  1009. scsi_qla_host_t *vha = shost_priv(cmd->device->host);
  1010. fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
  1011. int ret = FAILED;
  1012. unsigned int id;
  1013. uint64_t lun;
  1014. id = cmd->device->id;
  1015. lun = cmd->device->lun;
  1016. if (!fcport) {
  1017. return ret;
  1018. }
  1019. ret = fc_block_scsi_eh(cmd);
  1020. if (ret != 0)
  1021. return ret;
  1022. ret = FAILED;
  1023. ql_log(ql_log_info, vha, 0x8012,
  1024. "BUS RESET ISSUED nexus=%ld:%d:%llu.\n", vha->host_no, id, lun);
  1025. if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
  1026. ql_log(ql_log_fatal, vha, 0x8013,
  1027. "Wait for hba online failed board disabled.\n");
  1028. goto eh_bus_reset_done;
  1029. }
  1030. if (qla2x00_loop_reset(vha) == QLA_SUCCESS)
  1031. ret = SUCCESS;
  1032. if (ret == FAILED)
  1033. goto eh_bus_reset_done;
  1034. /* Flush outstanding commands. */
  1035. if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST) !=
  1036. QLA_SUCCESS) {
  1037. ql_log(ql_log_warn, vha, 0x8014,
  1038. "Wait for pending commands failed.\n");
  1039. ret = FAILED;
  1040. }
  1041. eh_bus_reset_done:
  1042. ql_log(ql_log_warn, vha, 0x802b,
  1043. "BUS RESET %s nexus=%ld:%d:%llu.\n",
  1044. (ret == FAILED) ? "FAILED" : "SUCCEEDED", vha->host_no, id, lun);
  1045. return ret;
  1046. }
  1047. /**************************************************************************
  1048. * qla2xxx_eh_host_reset
  1049. *
  1050. * Description:
  1051. * The reset function will reset the Adapter.
  1052. *
  1053. * Input:
  1054. * cmd = Linux SCSI command packet of the command that cause the
  1055. * adapter reset.
  1056. *
  1057. * Returns:
  1058. * Either SUCCESS or FAILED.
  1059. *
  1060. * Note:
  1061. **************************************************************************/
  1062. static int
  1063. qla2xxx_eh_host_reset(struct scsi_cmnd *cmd)
  1064. {
  1065. scsi_qla_host_t *vha = shost_priv(cmd->device->host);
  1066. struct qla_hw_data *ha = vha->hw;
  1067. int ret = FAILED;
  1068. unsigned int id;
  1069. uint64_t lun;
  1070. scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
  1071. id = cmd->device->id;
  1072. lun = cmd->device->lun;
  1073. ql_log(ql_log_info, vha, 0x8018,
  1074. "ADAPTER RESET ISSUED nexus=%ld:%d:%llu.\n", vha->host_no, id, lun);
  1075. /*
  1076. * No point in issuing another reset if one is active. Also do not
  1077. * attempt a reset if we are updating flash.
  1078. */
  1079. if (qla2x00_reset_active(vha) || ha->optrom_state != QLA_SWAITING)
  1080. goto eh_host_reset_lock;
  1081. if (vha != base_vha) {
  1082. if (qla2x00_vp_abort_isp(vha))
  1083. goto eh_host_reset_lock;
  1084. } else {
  1085. if (IS_P3P_TYPE(vha->hw)) {
  1086. if (!qla82xx_fcoe_ctx_reset(vha)) {
  1087. /* Ctx reset success */
  1088. ret = SUCCESS;
  1089. goto eh_host_reset_lock;
  1090. }
  1091. /* fall thru if ctx reset failed */
  1092. }
  1093. if (ha->wq)
  1094. flush_workqueue(ha->wq);
  1095. set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
  1096. if (ha->isp_ops->abort_isp(base_vha)) {
  1097. clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
  1098. /* failed. schedule dpc to try */
  1099. set_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags);
  1100. if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
  1101. ql_log(ql_log_warn, vha, 0x802a,
  1102. "wait for hba online failed.\n");
  1103. goto eh_host_reset_lock;
  1104. }
  1105. }
  1106. clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
  1107. }
  1108. /* Waiting for command to be returned to OS.*/
  1109. if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST) ==
  1110. QLA_SUCCESS)
  1111. ret = SUCCESS;
  1112. eh_host_reset_lock:
  1113. ql_log(ql_log_info, vha, 0x8017,
  1114. "ADAPTER RESET %s nexus=%ld:%d:%llu.\n",
  1115. (ret == FAILED) ? "FAILED" : "SUCCEEDED", vha->host_no, id, lun);
  1116. return ret;
  1117. }
  1118. /*
  1119. * qla2x00_loop_reset
  1120. * Issue loop reset.
  1121. *
  1122. * Input:
  1123. * ha = adapter block pointer.
  1124. *
  1125. * Returns:
  1126. * 0 = success
  1127. */
  1128. int
  1129. qla2x00_loop_reset(scsi_qla_host_t *vha)
  1130. {
  1131. int ret;
  1132. struct fc_port *fcport;
  1133. struct qla_hw_data *ha = vha->hw;
  1134. if (IS_QLAFX00(ha)) {
  1135. return qlafx00_loop_reset(vha);
  1136. }
  1137. if (ql2xtargetreset == 1 && ha->flags.enable_target_reset) {
  1138. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  1139. if (fcport->port_type != FCT_TARGET)
  1140. continue;
  1141. ret = ha->isp_ops->target_reset(fcport, 0, 0);
  1142. if (ret != QLA_SUCCESS) {
  1143. ql_dbg(ql_dbg_taskm, vha, 0x802c,
  1144. "Bus Reset failed: Reset=%d "
  1145. "d_id=%x.\n", ret, fcport->d_id.b24);
  1146. }
  1147. }
  1148. }
  1149. if (ha->flags.enable_lip_full_login && !IS_CNA_CAPABLE(ha)) {
  1150. atomic_set(&vha->loop_state, LOOP_DOWN);
  1151. atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
  1152. qla2x00_mark_all_devices_lost(vha, 0);
  1153. ret = qla2x00_full_login_lip(vha);
  1154. if (ret != QLA_SUCCESS) {
  1155. ql_dbg(ql_dbg_taskm, vha, 0x802d,
  1156. "full_login_lip=%d.\n", ret);
  1157. }
  1158. }
  1159. if (ha->flags.enable_lip_reset) {
  1160. ret = qla2x00_lip_reset(vha);
  1161. if (ret != QLA_SUCCESS)
  1162. ql_dbg(ql_dbg_taskm, vha, 0x802e,
  1163. "lip_reset failed (%d).\n", ret);
  1164. }
  1165. /* Issue marker command only when we are going to start the I/O */
  1166. vha->marker_needed = 1;
  1167. return QLA_SUCCESS;
  1168. }
  1169. void
  1170. qla2x00_abort_all_cmds(scsi_qla_host_t *vha, int res)
  1171. {
  1172. int que, cnt;
  1173. unsigned long flags;
  1174. srb_t *sp;
  1175. struct qla_hw_data *ha = vha->hw;
  1176. struct req_que *req;
  1177. qlt_host_reset_handler(ha);
  1178. spin_lock_irqsave(&ha->hardware_lock, flags);
  1179. for (que = 0; que < ha->max_req_queues; que++) {
  1180. req = ha->req_q_map[que];
  1181. if (!req)
  1182. continue;
  1183. if (!req->outstanding_cmds)
  1184. continue;
  1185. for (cnt = 1; cnt < req->num_outstanding_cmds; cnt++) {
  1186. sp = req->outstanding_cmds[cnt];
  1187. if (sp) {
  1188. req->outstanding_cmds[cnt] = NULL;
  1189. sp->done(vha, sp, res);
  1190. }
  1191. }
  1192. }
  1193. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1194. }
  1195. static int
  1196. qla2xxx_slave_alloc(struct scsi_device *sdev)
  1197. {
  1198. struct fc_rport *rport = starget_to_rport(scsi_target(sdev));
  1199. if (!rport || fc_remote_port_chkready(rport))
  1200. return -ENXIO;
  1201. sdev->hostdata = *(fc_port_t **)rport->dd_data;
  1202. return 0;
  1203. }
  1204. static int
  1205. qla2xxx_slave_configure(struct scsi_device *sdev)
  1206. {
  1207. scsi_qla_host_t *vha = shost_priv(sdev->host);
  1208. struct req_que *req = vha->req;
  1209. if (IS_T10_PI_CAPABLE(vha->hw))
  1210. blk_queue_update_dma_alignment(sdev->request_queue, 0x7);
  1211. scsi_change_queue_depth(sdev, req->max_q_depth);
  1212. return 0;
  1213. }
  1214. static void
  1215. qla2xxx_slave_destroy(struct scsi_device *sdev)
  1216. {
  1217. sdev->hostdata = NULL;
  1218. }
  1219. /**
  1220. * qla2x00_config_dma_addressing() - Configure OS DMA addressing method.
  1221. * @ha: HA context
  1222. *
  1223. * At exit, the @ha's flags.enable_64bit_addressing set to indicated
  1224. * supported addressing method.
  1225. */
  1226. static void
  1227. qla2x00_config_dma_addressing(struct qla_hw_data *ha)
  1228. {
  1229. /* Assume a 32bit DMA mask. */
  1230. ha->flags.enable_64bit_addressing = 0;
  1231. if (!dma_set_mask(&ha->pdev->dev, DMA_BIT_MASK(64))) {
  1232. /* Any upper-dword bits set? */
  1233. if (MSD(dma_get_required_mask(&ha->pdev->dev)) &&
  1234. !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
  1235. /* Ok, a 64bit DMA mask is applicable. */
  1236. ha->flags.enable_64bit_addressing = 1;
  1237. ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
  1238. ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
  1239. return;
  1240. }
  1241. }
  1242. dma_set_mask(&ha->pdev->dev, DMA_BIT_MASK(32));
  1243. pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(32));
  1244. }
  1245. static void
  1246. qla2x00_enable_intrs(struct qla_hw_data *ha)
  1247. {
  1248. unsigned long flags = 0;
  1249. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  1250. spin_lock_irqsave(&ha->hardware_lock, flags);
  1251. ha->interrupts_on = 1;
  1252. /* enable risc and host interrupts */
  1253. WRT_REG_WORD(&reg->ictrl, ICR_EN_INT | ICR_EN_RISC);
  1254. RD_REG_WORD(&reg->ictrl);
  1255. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1256. }
  1257. static void
  1258. qla2x00_disable_intrs(struct qla_hw_data *ha)
  1259. {
  1260. unsigned long flags = 0;
  1261. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  1262. spin_lock_irqsave(&ha->hardware_lock, flags);
  1263. ha->interrupts_on = 0;
  1264. /* disable risc and host interrupts */
  1265. WRT_REG_WORD(&reg->ictrl, 0);
  1266. RD_REG_WORD(&reg->ictrl);
  1267. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1268. }
  1269. static void
  1270. qla24xx_enable_intrs(struct qla_hw_data *ha)
  1271. {
  1272. unsigned long flags = 0;
  1273. struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
  1274. spin_lock_irqsave(&ha->hardware_lock, flags);
  1275. ha->interrupts_on = 1;
  1276. WRT_REG_DWORD(&reg->ictrl, ICRX_EN_RISC_INT);
  1277. RD_REG_DWORD(&reg->ictrl);
  1278. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1279. }
  1280. static void
  1281. qla24xx_disable_intrs(struct qla_hw_data *ha)
  1282. {
  1283. unsigned long flags = 0;
  1284. struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
  1285. if (IS_NOPOLLING_TYPE(ha))
  1286. return;
  1287. spin_lock_irqsave(&ha->hardware_lock, flags);
  1288. ha->interrupts_on = 0;
  1289. WRT_REG_DWORD(&reg->ictrl, 0);
  1290. RD_REG_DWORD(&reg->ictrl);
  1291. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1292. }
  1293. static int
  1294. qla2x00_iospace_config(struct qla_hw_data *ha)
  1295. {
  1296. resource_size_t pio;
  1297. uint16_t msix;
  1298. int cpus;
  1299. if (pci_request_selected_regions(ha->pdev, ha->bars,
  1300. QLA2XXX_DRIVER_NAME)) {
  1301. ql_log_pci(ql_log_fatal, ha->pdev, 0x0011,
  1302. "Failed to reserve PIO/MMIO regions (%s), aborting.\n",
  1303. pci_name(ha->pdev));
  1304. goto iospace_error_exit;
  1305. }
  1306. if (!(ha->bars & 1))
  1307. goto skip_pio;
  1308. /* We only need PIO for Flash operations on ISP2312 v2 chips. */
  1309. pio = pci_resource_start(ha->pdev, 0);
  1310. if (pci_resource_flags(ha->pdev, 0) & IORESOURCE_IO) {
  1311. if (pci_resource_len(ha->pdev, 0) < MIN_IOBASE_LEN) {
  1312. ql_log_pci(ql_log_warn, ha->pdev, 0x0012,
  1313. "Invalid pci I/O region size (%s).\n",
  1314. pci_name(ha->pdev));
  1315. pio = 0;
  1316. }
  1317. } else {
  1318. ql_log_pci(ql_log_warn, ha->pdev, 0x0013,
  1319. "Region #0 no a PIO resource (%s).\n",
  1320. pci_name(ha->pdev));
  1321. pio = 0;
  1322. }
  1323. ha->pio_address = pio;
  1324. ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0014,
  1325. "PIO address=%llu.\n",
  1326. (unsigned long long)ha->pio_address);
  1327. skip_pio:
  1328. /* Use MMIO operations for all accesses. */
  1329. if (!(pci_resource_flags(ha->pdev, 1) & IORESOURCE_MEM)) {
  1330. ql_log_pci(ql_log_fatal, ha->pdev, 0x0015,
  1331. "Region #1 not an MMIO resource (%s), aborting.\n",
  1332. pci_name(ha->pdev));
  1333. goto iospace_error_exit;
  1334. }
  1335. if (pci_resource_len(ha->pdev, 1) < MIN_IOBASE_LEN) {
  1336. ql_log_pci(ql_log_fatal, ha->pdev, 0x0016,
  1337. "Invalid PCI mem region size (%s), aborting.\n",
  1338. pci_name(ha->pdev));
  1339. goto iospace_error_exit;
  1340. }
  1341. ha->iobase = ioremap(pci_resource_start(ha->pdev, 1), MIN_IOBASE_LEN);
  1342. if (!ha->iobase) {
  1343. ql_log_pci(ql_log_fatal, ha->pdev, 0x0017,
  1344. "Cannot remap MMIO (%s), aborting.\n",
  1345. pci_name(ha->pdev));
  1346. goto iospace_error_exit;
  1347. }
  1348. /* Determine queue resources */
  1349. ha->max_req_queues = ha->max_rsp_queues = 1;
  1350. if ((ql2xmaxqueues <= 1 && !ql2xmultique_tag) ||
  1351. (ql2xmaxqueues > 1 && ql2xmultique_tag) ||
  1352. (!IS_QLA25XX(ha) && !IS_QLA81XX(ha)))
  1353. goto mqiobase_exit;
  1354. ha->mqiobase = ioremap(pci_resource_start(ha->pdev, 3),
  1355. pci_resource_len(ha->pdev, 3));
  1356. if (ha->mqiobase) {
  1357. ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0018,
  1358. "MQIO Base=%p.\n", ha->mqiobase);
  1359. /* Read MSIX vector size of the board */
  1360. pci_read_config_word(ha->pdev, QLA_PCI_MSIX_CONTROL, &msix);
  1361. ha->msix_count = msix;
  1362. /* Max queues are bounded by available msix vectors */
  1363. /* queue 0 uses two msix vectors */
  1364. if (ql2xmultique_tag) {
  1365. cpus = num_online_cpus();
  1366. ha->max_rsp_queues = (ha->msix_count - 1 > cpus) ?
  1367. (cpus + 1) : (ha->msix_count - 1);
  1368. ha->max_req_queues = 2;
  1369. } else if (ql2xmaxqueues > 1) {
  1370. ha->max_req_queues = ql2xmaxqueues > QLA_MQ_SIZE ?
  1371. QLA_MQ_SIZE : ql2xmaxqueues;
  1372. ql_dbg_pci(ql_dbg_multiq, ha->pdev, 0xc008,
  1373. "QoS mode set, max no of request queues:%d.\n",
  1374. ha->max_req_queues);
  1375. ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0019,
  1376. "QoS mode set, max no of request queues:%d.\n",
  1377. ha->max_req_queues);
  1378. }
  1379. ql_log_pci(ql_log_info, ha->pdev, 0x001a,
  1380. "MSI-X vector count: %d.\n", msix);
  1381. } else
  1382. ql_log_pci(ql_log_info, ha->pdev, 0x001b,
  1383. "BAR 3 not enabled.\n");
  1384. mqiobase_exit:
  1385. ha->msix_count = ha->max_rsp_queues + 1;
  1386. ql_dbg_pci(ql_dbg_init, ha->pdev, 0x001c,
  1387. "MSIX Count:%d.\n", ha->msix_count);
  1388. return (0);
  1389. iospace_error_exit:
  1390. return (-ENOMEM);
  1391. }
  1392. static int
  1393. qla83xx_iospace_config(struct qla_hw_data *ha)
  1394. {
  1395. uint16_t msix;
  1396. int cpus;
  1397. if (pci_request_selected_regions(ha->pdev, ha->bars,
  1398. QLA2XXX_DRIVER_NAME)) {
  1399. ql_log_pci(ql_log_fatal, ha->pdev, 0x0117,
  1400. "Failed to reserve PIO/MMIO regions (%s), aborting.\n",
  1401. pci_name(ha->pdev));
  1402. goto iospace_error_exit;
  1403. }
  1404. /* Use MMIO operations for all accesses. */
  1405. if (!(pci_resource_flags(ha->pdev, 0) & IORESOURCE_MEM)) {
  1406. ql_log_pci(ql_log_warn, ha->pdev, 0x0118,
  1407. "Invalid pci I/O region size (%s).\n",
  1408. pci_name(ha->pdev));
  1409. goto iospace_error_exit;
  1410. }
  1411. if (pci_resource_len(ha->pdev, 0) < MIN_IOBASE_LEN) {
  1412. ql_log_pci(ql_log_warn, ha->pdev, 0x0119,
  1413. "Invalid PCI mem region size (%s), aborting\n",
  1414. pci_name(ha->pdev));
  1415. goto iospace_error_exit;
  1416. }
  1417. ha->iobase = ioremap(pci_resource_start(ha->pdev, 0), MIN_IOBASE_LEN);
  1418. if (!ha->iobase) {
  1419. ql_log_pci(ql_log_fatal, ha->pdev, 0x011a,
  1420. "Cannot remap MMIO (%s), aborting.\n",
  1421. pci_name(ha->pdev));
  1422. goto iospace_error_exit;
  1423. }
  1424. /* 64bit PCI BAR - BAR2 will correspoond to region 4 */
  1425. /* 83XX 26XX always use MQ type access for queues
  1426. * - mbar 2, a.k.a region 4 */
  1427. ha->max_req_queues = ha->max_rsp_queues = 1;
  1428. ha->mqiobase = ioremap(pci_resource_start(ha->pdev, 4),
  1429. pci_resource_len(ha->pdev, 4));
  1430. if (!ha->mqiobase) {
  1431. ql_log_pci(ql_log_fatal, ha->pdev, 0x011d,
  1432. "BAR2/region4 not enabled\n");
  1433. goto mqiobase_exit;
  1434. }
  1435. ha->msixbase = ioremap(pci_resource_start(ha->pdev, 2),
  1436. pci_resource_len(ha->pdev, 2));
  1437. if (ha->msixbase) {
  1438. /* Read MSIX vector size of the board */
  1439. pci_read_config_word(ha->pdev,
  1440. QLA_83XX_PCI_MSIX_CONTROL, &msix);
  1441. ha->msix_count = msix;
  1442. /* Max queues are bounded by available msix vectors */
  1443. /* queue 0 uses two msix vectors */
  1444. if (ql2xmultique_tag) {
  1445. cpus = num_online_cpus();
  1446. ha->max_rsp_queues = (ha->msix_count - 1 > cpus) ?
  1447. (cpus + 1) : (ha->msix_count - 1);
  1448. ha->max_req_queues = 2;
  1449. } else if (ql2xmaxqueues > 1) {
  1450. ha->max_req_queues = ql2xmaxqueues > QLA_MQ_SIZE ?
  1451. QLA_MQ_SIZE : ql2xmaxqueues;
  1452. ql_dbg_pci(ql_dbg_multiq, ha->pdev, 0xc00c,
  1453. "QoS mode set, max no of request queues:%d.\n",
  1454. ha->max_req_queues);
  1455. ql_dbg_pci(ql_dbg_init, ha->pdev, 0x011b,
  1456. "QoS mode set, max no of request queues:%d.\n",
  1457. ha->max_req_queues);
  1458. }
  1459. ql_log_pci(ql_log_info, ha->pdev, 0x011c,
  1460. "MSI-X vector count: %d.\n", msix);
  1461. } else
  1462. ql_log_pci(ql_log_info, ha->pdev, 0x011e,
  1463. "BAR 1 not enabled.\n");
  1464. mqiobase_exit:
  1465. ha->msix_count = ha->max_rsp_queues + 1;
  1466. qlt_83xx_iospace_config(ha);
  1467. ql_dbg_pci(ql_dbg_init, ha->pdev, 0x011f,
  1468. "MSIX Count:%d.\n", ha->msix_count);
  1469. return 0;
  1470. iospace_error_exit:
  1471. return -ENOMEM;
  1472. }
  1473. static struct isp_operations qla2100_isp_ops = {
  1474. .pci_config = qla2100_pci_config,
  1475. .reset_chip = qla2x00_reset_chip,
  1476. .chip_diag = qla2x00_chip_diag,
  1477. .config_rings = qla2x00_config_rings,
  1478. .reset_adapter = qla2x00_reset_adapter,
  1479. .nvram_config = qla2x00_nvram_config,
  1480. .update_fw_options = qla2x00_update_fw_options,
  1481. .load_risc = qla2x00_load_risc,
  1482. .pci_info_str = qla2x00_pci_info_str,
  1483. .fw_version_str = qla2x00_fw_version_str,
  1484. .intr_handler = qla2100_intr_handler,
  1485. .enable_intrs = qla2x00_enable_intrs,
  1486. .disable_intrs = qla2x00_disable_intrs,
  1487. .abort_command = qla2x00_abort_command,
  1488. .target_reset = qla2x00_abort_target,
  1489. .lun_reset = qla2x00_lun_reset,
  1490. .fabric_login = qla2x00_login_fabric,
  1491. .fabric_logout = qla2x00_fabric_logout,
  1492. .calc_req_entries = qla2x00_calc_iocbs_32,
  1493. .build_iocbs = qla2x00_build_scsi_iocbs_32,
  1494. .prep_ms_iocb = qla2x00_prep_ms_iocb,
  1495. .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
  1496. .read_nvram = qla2x00_read_nvram_data,
  1497. .write_nvram = qla2x00_write_nvram_data,
  1498. .fw_dump = qla2100_fw_dump,
  1499. .beacon_on = NULL,
  1500. .beacon_off = NULL,
  1501. .beacon_blink = NULL,
  1502. .read_optrom = qla2x00_read_optrom_data,
  1503. .write_optrom = qla2x00_write_optrom_data,
  1504. .get_flash_version = qla2x00_get_flash_version,
  1505. .start_scsi = qla2x00_start_scsi,
  1506. .abort_isp = qla2x00_abort_isp,
  1507. .iospace_config = qla2x00_iospace_config,
  1508. .initialize_adapter = qla2x00_initialize_adapter,
  1509. };
  1510. static struct isp_operations qla2300_isp_ops = {
  1511. .pci_config = qla2300_pci_config,
  1512. .reset_chip = qla2x00_reset_chip,
  1513. .chip_diag = qla2x00_chip_diag,
  1514. .config_rings = qla2x00_config_rings,
  1515. .reset_adapter = qla2x00_reset_adapter,
  1516. .nvram_config = qla2x00_nvram_config,
  1517. .update_fw_options = qla2x00_update_fw_options,
  1518. .load_risc = qla2x00_load_risc,
  1519. .pci_info_str = qla2x00_pci_info_str,
  1520. .fw_version_str = qla2x00_fw_version_str,
  1521. .intr_handler = qla2300_intr_handler,
  1522. .enable_intrs = qla2x00_enable_intrs,
  1523. .disable_intrs = qla2x00_disable_intrs,
  1524. .abort_command = qla2x00_abort_command,
  1525. .target_reset = qla2x00_abort_target,
  1526. .lun_reset = qla2x00_lun_reset,
  1527. .fabric_login = qla2x00_login_fabric,
  1528. .fabric_logout = qla2x00_fabric_logout,
  1529. .calc_req_entries = qla2x00_calc_iocbs_32,
  1530. .build_iocbs = qla2x00_build_scsi_iocbs_32,
  1531. .prep_ms_iocb = qla2x00_prep_ms_iocb,
  1532. .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
  1533. .read_nvram = qla2x00_read_nvram_data,
  1534. .write_nvram = qla2x00_write_nvram_data,
  1535. .fw_dump = qla2300_fw_dump,
  1536. .beacon_on = qla2x00_beacon_on,
  1537. .beacon_off = qla2x00_beacon_off,
  1538. .beacon_blink = qla2x00_beacon_blink,
  1539. .read_optrom = qla2x00_read_optrom_data,
  1540. .write_optrom = qla2x00_write_optrom_data,
  1541. .get_flash_version = qla2x00_get_flash_version,
  1542. .start_scsi = qla2x00_start_scsi,
  1543. .abort_isp = qla2x00_abort_isp,
  1544. .iospace_config = qla2x00_iospace_config,
  1545. .initialize_adapter = qla2x00_initialize_adapter,
  1546. };
  1547. static struct isp_operations qla24xx_isp_ops = {
  1548. .pci_config = qla24xx_pci_config,
  1549. .reset_chip = qla24xx_reset_chip,
  1550. .chip_diag = qla24xx_chip_diag,
  1551. .config_rings = qla24xx_config_rings,
  1552. .reset_adapter = qla24xx_reset_adapter,
  1553. .nvram_config = qla24xx_nvram_config,
  1554. .update_fw_options = qla24xx_update_fw_options,
  1555. .load_risc = qla24xx_load_risc,
  1556. .pci_info_str = qla24xx_pci_info_str,
  1557. .fw_version_str = qla24xx_fw_version_str,
  1558. .intr_handler = qla24xx_intr_handler,
  1559. .enable_intrs = qla24xx_enable_intrs,
  1560. .disable_intrs = qla24xx_disable_intrs,
  1561. .abort_command = qla24xx_abort_command,
  1562. .target_reset = qla24xx_abort_target,
  1563. .lun_reset = qla24xx_lun_reset,
  1564. .fabric_login = qla24xx_login_fabric,
  1565. .fabric_logout = qla24xx_fabric_logout,
  1566. .calc_req_entries = NULL,
  1567. .build_iocbs = NULL,
  1568. .prep_ms_iocb = qla24xx_prep_ms_iocb,
  1569. .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
  1570. .read_nvram = qla24xx_read_nvram_data,
  1571. .write_nvram = qla24xx_write_nvram_data,
  1572. .fw_dump = qla24xx_fw_dump,
  1573. .beacon_on = qla24xx_beacon_on,
  1574. .beacon_off = qla24xx_beacon_off,
  1575. .beacon_blink = qla24xx_beacon_blink,
  1576. .read_optrom = qla24xx_read_optrom_data,
  1577. .write_optrom = qla24xx_write_optrom_data,
  1578. .get_flash_version = qla24xx_get_flash_version,
  1579. .start_scsi = qla24xx_start_scsi,
  1580. .abort_isp = qla2x00_abort_isp,
  1581. .iospace_config = qla2x00_iospace_config,
  1582. .initialize_adapter = qla2x00_initialize_adapter,
  1583. };
  1584. static struct isp_operations qla25xx_isp_ops = {
  1585. .pci_config = qla25xx_pci_config,
  1586. .reset_chip = qla24xx_reset_chip,
  1587. .chip_diag = qla24xx_chip_diag,
  1588. .config_rings = qla24xx_config_rings,
  1589. .reset_adapter = qla24xx_reset_adapter,
  1590. .nvram_config = qla24xx_nvram_config,
  1591. .update_fw_options = qla24xx_update_fw_options,
  1592. .load_risc = qla24xx_load_risc,
  1593. .pci_info_str = qla24xx_pci_info_str,
  1594. .fw_version_str = qla24xx_fw_version_str,
  1595. .intr_handler = qla24xx_intr_handler,
  1596. .enable_intrs = qla24xx_enable_intrs,
  1597. .disable_intrs = qla24xx_disable_intrs,
  1598. .abort_command = qla24xx_abort_command,
  1599. .target_reset = qla24xx_abort_target,
  1600. .lun_reset = qla24xx_lun_reset,
  1601. .fabric_login = qla24xx_login_fabric,
  1602. .fabric_logout = qla24xx_fabric_logout,
  1603. .calc_req_entries = NULL,
  1604. .build_iocbs = NULL,
  1605. .prep_ms_iocb = qla24xx_prep_ms_iocb,
  1606. .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
  1607. .read_nvram = qla25xx_read_nvram_data,
  1608. .write_nvram = qla25xx_write_nvram_data,
  1609. .fw_dump = qla25xx_fw_dump,
  1610. .beacon_on = qla24xx_beacon_on,
  1611. .beacon_off = qla24xx_beacon_off,
  1612. .beacon_blink = qla24xx_beacon_blink,
  1613. .read_optrom = qla25xx_read_optrom_data,
  1614. .write_optrom = qla24xx_write_optrom_data,
  1615. .get_flash_version = qla24xx_get_flash_version,
  1616. .start_scsi = qla24xx_dif_start_scsi,
  1617. .abort_isp = qla2x00_abort_isp,
  1618. .iospace_config = qla2x00_iospace_config,
  1619. .initialize_adapter = qla2x00_initialize_adapter,
  1620. };
  1621. static struct isp_operations qla81xx_isp_ops = {
  1622. .pci_config = qla25xx_pci_config,
  1623. .reset_chip = qla24xx_reset_chip,
  1624. .chip_diag = qla24xx_chip_diag,
  1625. .config_rings = qla24xx_config_rings,
  1626. .reset_adapter = qla24xx_reset_adapter,
  1627. .nvram_config = qla81xx_nvram_config,
  1628. .update_fw_options = qla81xx_update_fw_options,
  1629. .load_risc = qla81xx_load_risc,
  1630. .pci_info_str = qla24xx_pci_info_str,
  1631. .fw_version_str = qla24xx_fw_version_str,
  1632. .intr_handler = qla24xx_intr_handler,
  1633. .enable_intrs = qla24xx_enable_intrs,
  1634. .disable_intrs = qla24xx_disable_intrs,
  1635. .abort_command = qla24xx_abort_command,
  1636. .target_reset = qla24xx_abort_target,
  1637. .lun_reset = qla24xx_lun_reset,
  1638. .fabric_login = qla24xx_login_fabric,
  1639. .fabric_logout = qla24xx_fabric_logout,
  1640. .calc_req_entries = NULL,
  1641. .build_iocbs = NULL,
  1642. .prep_ms_iocb = qla24xx_prep_ms_iocb,
  1643. .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
  1644. .read_nvram = NULL,
  1645. .write_nvram = NULL,
  1646. .fw_dump = qla81xx_fw_dump,
  1647. .beacon_on = qla24xx_beacon_on,
  1648. .beacon_off = qla24xx_beacon_off,
  1649. .beacon_blink = qla83xx_beacon_blink,
  1650. .read_optrom = qla25xx_read_optrom_data,
  1651. .write_optrom = qla24xx_write_optrom_data,
  1652. .get_flash_version = qla24xx_get_flash_version,
  1653. .start_scsi = qla24xx_dif_start_scsi,
  1654. .abort_isp = qla2x00_abort_isp,
  1655. .iospace_config = qla2x00_iospace_config,
  1656. .initialize_adapter = qla2x00_initialize_adapter,
  1657. };
  1658. static struct isp_operations qla82xx_isp_ops = {
  1659. .pci_config = qla82xx_pci_config,
  1660. .reset_chip = qla82xx_reset_chip,
  1661. .chip_diag = qla24xx_chip_diag,
  1662. .config_rings = qla82xx_config_rings,
  1663. .reset_adapter = qla24xx_reset_adapter,
  1664. .nvram_config = qla81xx_nvram_config,
  1665. .update_fw_options = qla24xx_update_fw_options,
  1666. .load_risc = qla82xx_load_risc,
  1667. .pci_info_str = qla24xx_pci_info_str,
  1668. .fw_version_str = qla24xx_fw_version_str,
  1669. .intr_handler = qla82xx_intr_handler,
  1670. .enable_intrs = qla82xx_enable_intrs,
  1671. .disable_intrs = qla82xx_disable_intrs,
  1672. .abort_command = qla24xx_abort_command,
  1673. .target_reset = qla24xx_abort_target,
  1674. .lun_reset = qla24xx_lun_reset,
  1675. .fabric_login = qla24xx_login_fabric,
  1676. .fabric_logout = qla24xx_fabric_logout,
  1677. .calc_req_entries = NULL,
  1678. .build_iocbs = NULL,
  1679. .prep_ms_iocb = qla24xx_prep_ms_iocb,
  1680. .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
  1681. .read_nvram = qla24xx_read_nvram_data,
  1682. .write_nvram = qla24xx_write_nvram_data,
  1683. .fw_dump = qla82xx_fw_dump,
  1684. .beacon_on = qla82xx_beacon_on,
  1685. .beacon_off = qla82xx_beacon_off,
  1686. .beacon_blink = NULL,
  1687. .read_optrom = qla82xx_read_optrom_data,
  1688. .write_optrom = qla82xx_write_optrom_data,
  1689. .get_flash_version = qla82xx_get_flash_version,
  1690. .start_scsi = qla82xx_start_scsi,
  1691. .abort_isp = qla82xx_abort_isp,
  1692. .iospace_config = qla82xx_iospace_config,
  1693. .initialize_adapter = qla2x00_initialize_adapter,
  1694. };
  1695. static struct isp_operations qla8044_isp_ops = {
  1696. .pci_config = qla82xx_pci_config,
  1697. .reset_chip = qla82xx_reset_chip,
  1698. .chip_diag = qla24xx_chip_diag,
  1699. .config_rings = qla82xx_config_rings,
  1700. .reset_adapter = qla24xx_reset_adapter,
  1701. .nvram_config = qla81xx_nvram_config,
  1702. .update_fw_options = qla24xx_update_fw_options,
  1703. .load_risc = qla82xx_load_risc,
  1704. .pci_info_str = qla24xx_pci_info_str,
  1705. .fw_version_str = qla24xx_fw_version_str,
  1706. .intr_handler = qla8044_intr_handler,
  1707. .enable_intrs = qla82xx_enable_intrs,
  1708. .disable_intrs = qla82xx_disable_intrs,
  1709. .abort_command = qla24xx_abort_command,
  1710. .target_reset = qla24xx_abort_target,
  1711. .lun_reset = qla24xx_lun_reset,
  1712. .fabric_login = qla24xx_login_fabric,
  1713. .fabric_logout = qla24xx_fabric_logout,
  1714. .calc_req_entries = NULL,
  1715. .build_iocbs = NULL,
  1716. .prep_ms_iocb = qla24xx_prep_ms_iocb,
  1717. .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
  1718. .read_nvram = NULL,
  1719. .write_nvram = NULL,
  1720. .fw_dump = qla8044_fw_dump,
  1721. .beacon_on = qla82xx_beacon_on,
  1722. .beacon_off = qla82xx_beacon_off,
  1723. .beacon_blink = NULL,
  1724. .read_optrom = qla8044_read_optrom_data,
  1725. .write_optrom = qla8044_write_optrom_data,
  1726. .get_flash_version = qla82xx_get_flash_version,
  1727. .start_scsi = qla82xx_start_scsi,
  1728. .abort_isp = qla8044_abort_isp,
  1729. .iospace_config = qla82xx_iospace_config,
  1730. .initialize_adapter = qla2x00_initialize_adapter,
  1731. };
  1732. static struct isp_operations qla83xx_isp_ops = {
  1733. .pci_config = qla25xx_pci_config,
  1734. .reset_chip = qla24xx_reset_chip,
  1735. .chip_diag = qla24xx_chip_diag,
  1736. .config_rings = qla24xx_config_rings,
  1737. .reset_adapter = qla24xx_reset_adapter,
  1738. .nvram_config = qla81xx_nvram_config,
  1739. .update_fw_options = qla81xx_update_fw_options,
  1740. .load_risc = qla81xx_load_risc,
  1741. .pci_info_str = qla24xx_pci_info_str,
  1742. .fw_version_str = qla24xx_fw_version_str,
  1743. .intr_handler = qla24xx_intr_handler,
  1744. .enable_intrs = qla24xx_enable_intrs,
  1745. .disable_intrs = qla24xx_disable_intrs,
  1746. .abort_command = qla24xx_abort_command,
  1747. .target_reset = qla24xx_abort_target,
  1748. .lun_reset = qla24xx_lun_reset,
  1749. .fabric_login = qla24xx_login_fabric,
  1750. .fabric_logout = qla24xx_fabric_logout,
  1751. .calc_req_entries = NULL,
  1752. .build_iocbs = NULL,
  1753. .prep_ms_iocb = qla24xx_prep_ms_iocb,
  1754. .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
  1755. .read_nvram = NULL,
  1756. .write_nvram = NULL,
  1757. .fw_dump = qla83xx_fw_dump,
  1758. .beacon_on = qla24xx_beacon_on,
  1759. .beacon_off = qla24xx_beacon_off,
  1760. .beacon_blink = qla83xx_beacon_blink,
  1761. .read_optrom = qla25xx_read_optrom_data,
  1762. .write_optrom = qla24xx_write_optrom_data,
  1763. .get_flash_version = qla24xx_get_flash_version,
  1764. .start_scsi = qla24xx_dif_start_scsi,
  1765. .abort_isp = qla2x00_abort_isp,
  1766. .iospace_config = qla83xx_iospace_config,
  1767. .initialize_adapter = qla2x00_initialize_adapter,
  1768. };
  1769. static struct isp_operations qlafx00_isp_ops = {
  1770. .pci_config = qlafx00_pci_config,
  1771. .reset_chip = qlafx00_soft_reset,
  1772. .chip_diag = qlafx00_chip_diag,
  1773. .config_rings = qlafx00_config_rings,
  1774. .reset_adapter = qlafx00_soft_reset,
  1775. .nvram_config = NULL,
  1776. .update_fw_options = NULL,
  1777. .load_risc = NULL,
  1778. .pci_info_str = qlafx00_pci_info_str,
  1779. .fw_version_str = qlafx00_fw_version_str,
  1780. .intr_handler = qlafx00_intr_handler,
  1781. .enable_intrs = qlafx00_enable_intrs,
  1782. .disable_intrs = qlafx00_disable_intrs,
  1783. .abort_command = qla24xx_async_abort_command,
  1784. .target_reset = qlafx00_abort_target,
  1785. .lun_reset = qlafx00_lun_reset,
  1786. .fabric_login = NULL,
  1787. .fabric_logout = NULL,
  1788. .calc_req_entries = NULL,
  1789. .build_iocbs = NULL,
  1790. .prep_ms_iocb = qla24xx_prep_ms_iocb,
  1791. .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
  1792. .read_nvram = qla24xx_read_nvram_data,
  1793. .write_nvram = qla24xx_write_nvram_data,
  1794. .fw_dump = NULL,
  1795. .beacon_on = qla24xx_beacon_on,
  1796. .beacon_off = qla24xx_beacon_off,
  1797. .beacon_blink = NULL,
  1798. .read_optrom = qla24xx_read_optrom_data,
  1799. .write_optrom = qla24xx_write_optrom_data,
  1800. .get_flash_version = qla24xx_get_flash_version,
  1801. .start_scsi = qlafx00_start_scsi,
  1802. .abort_isp = qlafx00_abort_isp,
  1803. .iospace_config = qlafx00_iospace_config,
  1804. .initialize_adapter = qlafx00_initialize_adapter,
  1805. };
  1806. static struct isp_operations qla27xx_isp_ops = {
  1807. .pci_config = qla25xx_pci_config,
  1808. .reset_chip = qla24xx_reset_chip,
  1809. .chip_diag = qla24xx_chip_diag,
  1810. .config_rings = qla24xx_config_rings,
  1811. .reset_adapter = qla24xx_reset_adapter,
  1812. .nvram_config = qla81xx_nvram_config,
  1813. .update_fw_options = qla81xx_update_fw_options,
  1814. .load_risc = qla81xx_load_risc,
  1815. .pci_info_str = qla24xx_pci_info_str,
  1816. .fw_version_str = qla24xx_fw_version_str,
  1817. .intr_handler = qla24xx_intr_handler,
  1818. .enable_intrs = qla24xx_enable_intrs,
  1819. .disable_intrs = qla24xx_disable_intrs,
  1820. .abort_command = qla24xx_abort_command,
  1821. .target_reset = qla24xx_abort_target,
  1822. .lun_reset = qla24xx_lun_reset,
  1823. .fabric_login = qla24xx_login_fabric,
  1824. .fabric_logout = qla24xx_fabric_logout,
  1825. .calc_req_entries = NULL,
  1826. .build_iocbs = NULL,
  1827. .prep_ms_iocb = qla24xx_prep_ms_iocb,
  1828. .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
  1829. .read_nvram = NULL,
  1830. .write_nvram = NULL,
  1831. .fw_dump = qla27xx_fwdump,
  1832. .beacon_on = qla24xx_beacon_on,
  1833. .beacon_off = qla24xx_beacon_off,
  1834. .beacon_blink = qla83xx_beacon_blink,
  1835. .read_optrom = qla25xx_read_optrom_data,
  1836. .write_optrom = qla24xx_write_optrom_data,
  1837. .get_flash_version = qla24xx_get_flash_version,
  1838. .start_scsi = qla24xx_dif_start_scsi,
  1839. .abort_isp = qla2x00_abort_isp,
  1840. .iospace_config = qla83xx_iospace_config,
  1841. .initialize_adapter = qla2x00_initialize_adapter,
  1842. };
  1843. static inline void
  1844. qla2x00_set_isp_flags(struct qla_hw_data *ha)
  1845. {
  1846. ha->device_type = DT_EXTENDED_IDS;
  1847. switch (ha->pdev->device) {
  1848. case PCI_DEVICE_ID_QLOGIC_ISP2100:
  1849. ha->device_type |= DT_ISP2100;
  1850. ha->device_type &= ~DT_EXTENDED_IDS;
  1851. ha->fw_srisc_address = RISC_START_ADDRESS_2100;
  1852. break;
  1853. case PCI_DEVICE_ID_QLOGIC_ISP2200:
  1854. ha->device_type |= DT_ISP2200;
  1855. ha->device_type &= ~DT_EXTENDED_IDS;
  1856. ha->fw_srisc_address = RISC_START_ADDRESS_2100;
  1857. break;
  1858. case PCI_DEVICE_ID_QLOGIC_ISP2300:
  1859. ha->device_type |= DT_ISP2300;
  1860. ha->device_type |= DT_ZIO_SUPPORTED;
  1861. ha->fw_srisc_address = RISC_START_ADDRESS_2300;
  1862. break;
  1863. case PCI_DEVICE_ID_QLOGIC_ISP2312:
  1864. ha->device_type |= DT_ISP2312;
  1865. ha->device_type |= DT_ZIO_SUPPORTED;
  1866. ha->fw_srisc_address = RISC_START_ADDRESS_2300;
  1867. break;
  1868. case PCI_DEVICE_ID_QLOGIC_ISP2322:
  1869. ha->device_type |= DT_ISP2322;
  1870. ha->device_type |= DT_ZIO_SUPPORTED;
  1871. if (ha->pdev->subsystem_vendor == 0x1028 &&
  1872. ha->pdev->subsystem_device == 0x0170)
  1873. ha->device_type |= DT_OEM_001;
  1874. ha->fw_srisc_address = RISC_START_ADDRESS_2300;
  1875. break;
  1876. case PCI_DEVICE_ID_QLOGIC_ISP6312:
  1877. ha->device_type |= DT_ISP6312;
  1878. ha->fw_srisc_address = RISC_START_ADDRESS_2300;
  1879. break;
  1880. case PCI_DEVICE_ID_QLOGIC_ISP6322:
  1881. ha->device_type |= DT_ISP6322;
  1882. ha->fw_srisc_address = RISC_START_ADDRESS_2300;
  1883. break;
  1884. case PCI_DEVICE_ID_QLOGIC_ISP2422:
  1885. ha->device_type |= DT_ISP2422;
  1886. ha->device_type |= DT_ZIO_SUPPORTED;
  1887. ha->device_type |= DT_FWI2;
  1888. ha->device_type |= DT_IIDMA;
  1889. ha->fw_srisc_address = RISC_START_ADDRESS_2400;
  1890. break;
  1891. case PCI_DEVICE_ID_QLOGIC_ISP2432:
  1892. ha->device_type |= DT_ISP2432;
  1893. ha->device_type |= DT_ZIO_SUPPORTED;
  1894. ha->device_type |= DT_FWI2;
  1895. ha->device_type |= DT_IIDMA;
  1896. ha->fw_srisc_address = RISC_START_ADDRESS_2400;
  1897. break;
  1898. case PCI_DEVICE_ID_QLOGIC_ISP8432:
  1899. ha->device_type |= DT_ISP8432;
  1900. ha->device_type |= DT_ZIO_SUPPORTED;
  1901. ha->device_type |= DT_FWI2;
  1902. ha->device_type |= DT_IIDMA;
  1903. ha->fw_srisc_address = RISC_START_ADDRESS_2400;
  1904. break;
  1905. case PCI_DEVICE_ID_QLOGIC_ISP5422:
  1906. ha->device_type |= DT_ISP5422;
  1907. ha->device_type |= DT_FWI2;
  1908. ha->fw_srisc_address = RISC_START_ADDRESS_2400;
  1909. break;
  1910. case PCI_DEVICE_ID_QLOGIC_ISP5432:
  1911. ha->device_type |= DT_ISP5432;
  1912. ha->device_type |= DT_FWI2;
  1913. ha->fw_srisc_address = RISC_START_ADDRESS_2400;
  1914. break;
  1915. case PCI_DEVICE_ID_QLOGIC_ISP2532:
  1916. ha->device_type |= DT_ISP2532;
  1917. ha->device_type |= DT_ZIO_SUPPORTED;
  1918. ha->device_type |= DT_FWI2;
  1919. ha->device_type |= DT_IIDMA;
  1920. ha->fw_srisc_address = RISC_START_ADDRESS_2400;
  1921. break;
  1922. case PCI_DEVICE_ID_QLOGIC_ISP8001:
  1923. ha->device_type |= DT_ISP8001;
  1924. ha->device_type |= DT_ZIO_SUPPORTED;
  1925. ha->device_type |= DT_FWI2;
  1926. ha->device_type |= DT_IIDMA;
  1927. ha->fw_srisc_address = RISC_START_ADDRESS_2400;
  1928. break;
  1929. case PCI_DEVICE_ID_QLOGIC_ISP8021:
  1930. ha->device_type |= DT_ISP8021;
  1931. ha->device_type |= DT_ZIO_SUPPORTED;
  1932. ha->device_type |= DT_FWI2;
  1933. ha->fw_srisc_address = RISC_START_ADDRESS_2400;
  1934. /* Initialize 82XX ISP flags */
  1935. qla82xx_init_flags(ha);
  1936. break;
  1937. case PCI_DEVICE_ID_QLOGIC_ISP8044:
  1938. ha->device_type |= DT_ISP8044;
  1939. ha->device_type |= DT_ZIO_SUPPORTED;
  1940. ha->device_type |= DT_FWI2;
  1941. ha->fw_srisc_address = RISC_START_ADDRESS_2400;
  1942. /* Initialize 82XX ISP flags */
  1943. qla82xx_init_flags(ha);
  1944. break;
  1945. case PCI_DEVICE_ID_QLOGIC_ISP2031:
  1946. ha->device_type |= DT_ISP2031;
  1947. ha->device_type |= DT_ZIO_SUPPORTED;
  1948. ha->device_type |= DT_FWI2;
  1949. ha->device_type |= DT_IIDMA;
  1950. ha->device_type |= DT_T10_PI;
  1951. ha->fw_srisc_address = RISC_START_ADDRESS_2400;
  1952. break;
  1953. case PCI_DEVICE_ID_QLOGIC_ISP8031:
  1954. ha->device_type |= DT_ISP8031;
  1955. ha->device_type |= DT_ZIO_SUPPORTED;
  1956. ha->device_type |= DT_FWI2;
  1957. ha->device_type |= DT_IIDMA;
  1958. ha->device_type |= DT_T10_PI;
  1959. ha->fw_srisc_address = RISC_START_ADDRESS_2400;
  1960. break;
  1961. case PCI_DEVICE_ID_QLOGIC_ISPF001:
  1962. ha->device_type |= DT_ISPFX00;
  1963. break;
  1964. case PCI_DEVICE_ID_QLOGIC_ISP2071:
  1965. ha->device_type |= DT_ISP2071;
  1966. ha->device_type |= DT_ZIO_SUPPORTED;
  1967. ha->device_type |= DT_FWI2;
  1968. ha->device_type |= DT_IIDMA;
  1969. ha->fw_srisc_address = RISC_START_ADDRESS_2400;
  1970. break;
  1971. case PCI_DEVICE_ID_QLOGIC_ISP2271:
  1972. ha->device_type |= DT_ISP2271;
  1973. ha->device_type |= DT_ZIO_SUPPORTED;
  1974. ha->device_type |= DT_FWI2;
  1975. ha->device_type |= DT_IIDMA;
  1976. ha->fw_srisc_address = RISC_START_ADDRESS_2400;
  1977. break;
  1978. case PCI_DEVICE_ID_QLOGIC_ISP2261:
  1979. ha->device_type |= DT_ISP2261;
  1980. ha->device_type |= DT_ZIO_SUPPORTED;
  1981. ha->device_type |= DT_FWI2;
  1982. ha->device_type |= DT_IIDMA;
  1983. ha->fw_srisc_address = RISC_START_ADDRESS_2400;
  1984. break;
  1985. }
  1986. if (IS_QLA82XX(ha))
  1987. ha->port_no = ha->portnum & 1;
  1988. else {
  1989. /* Get adapter physical port no from interrupt pin register. */
  1990. pci_read_config_byte(ha->pdev, PCI_INTERRUPT_PIN, &ha->port_no);
  1991. if (IS_QLA27XX(ha))
  1992. ha->port_no--;
  1993. else
  1994. ha->port_no = !(ha->port_no & 1);
  1995. }
  1996. ql_dbg_pci(ql_dbg_init, ha->pdev, 0x000b,
  1997. "device_type=0x%x port=%d fw_srisc_address=0x%x.\n",
  1998. ha->device_type, ha->port_no, ha->fw_srisc_address);
  1999. }
  2000. static void
  2001. qla2xxx_scan_start(struct Scsi_Host *shost)
  2002. {
  2003. scsi_qla_host_t *vha = shost_priv(shost);
  2004. if (vha->hw->flags.running_gold_fw)
  2005. return;
  2006. set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
  2007. set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
  2008. set_bit(RSCN_UPDATE, &vha->dpc_flags);
  2009. set_bit(NPIV_CONFIG_NEEDED, &vha->dpc_flags);
  2010. }
  2011. static int
  2012. qla2xxx_scan_finished(struct Scsi_Host *shost, unsigned long time)
  2013. {
  2014. scsi_qla_host_t *vha = shost_priv(shost);
  2015. if (test_bit(UNLOADING, &vha->dpc_flags))
  2016. return 1;
  2017. if (!vha->host)
  2018. return 1;
  2019. if (time > vha->hw->loop_reset_delay * HZ)
  2020. return 1;
  2021. return atomic_read(&vha->loop_state) == LOOP_READY;
  2022. }
  2023. /*
  2024. * PCI driver interface
  2025. */
  2026. static int
  2027. qla2x00_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
  2028. {
  2029. int ret = -ENODEV;
  2030. struct Scsi_Host *host;
  2031. scsi_qla_host_t *base_vha = NULL;
  2032. struct qla_hw_data *ha;
  2033. char pci_info[30];
  2034. char fw_str[30], wq_name[30];
  2035. struct scsi_host_template *sht;
  2036. int bars, mem_only = 0;
  2037. uint16_t req_length = 0, rsp_length = 0;
  2038. struct req_que *req = NULL;
  2039. struct rsp_que *rsp = NULL;
  2040. bars = pci_select_bars(pdev, IORESOURCE_MEM | IORESOURCE_IO);
  2041. sht = &qla2xxx_driver_template;
  2042. if (pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2422 ||
  2043. pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2432 ||
  2044. pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8432 ||
  2045. pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5422 ||
  2046. pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5432 ||
  2047. pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2532 ||
  2048. pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8001 ||
  2049. pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8021 ||
  2050. pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2031 ||
  2051. pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8031 ||
  2052. pdev->device == PCI_DEVICE_ID_QLOGIC_ISPF001 ||
  2053. pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8044 ||
  2054. pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2071 ||
  2055. pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2271 ||
  2056. pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2261) {
  2057. bars = pci_select_bars(pdev, IORESOURCE_MEM);
  2058. mem_only = 1;
  2059. ql_dbg_pci(ql_dbg_init, pdev, 0x0007,
  2060. "Mem only adapter.\n");
  2061. }
  2062. ql_dbg_pci(ql_dbg_init, pdev, 0x0008,
  2063. "Bars=%d.\n", bars);
  2064. if (mem_only) {
  2065. if (pci_enable_device_mem(pdev))
  2066. return ret;
  2067. } else {
  2068. if (pci_enable_device(pdev))
  2069. return ret;
  2070. }
  2071. /* This may fail but that's ok */
  2072. pci_enable_pcie_error_reporting(pdev);
  2073. ha = kzalloc(sizeof(struct qla_hw_data), GFP_KERNEL);
  2074. if (!ha) {
  2075. ql_log_pci(ql_log_fatal, pdev, 0x0009,
  2076. "Unable to allocate memory for ha.\n");
  2077. goto disable_device;
  2078. }
  2079. ql_dbg_pci(ql_dbg_init, pdev, 0x000a,
  2080. "Memory allocated for ha=%p.\n", ha);
  2081. ha->pdev = pdev;
  2082. ha->tgt.enable_class_2 = ql2xenableclass2;
  2083. INIT_LIST_HEAD(&ha->tgt.q_full_list);
  2084. spin_lock_init(&ha->tgt.q_full_lock);
  2085. /* Clear our data area */
  2086. ha->bars = bars;
  2087. ha->mem_only = mem_only;
  2088. spin_lock_init(&ha->hardware_lock);
  2089. spin_lock_init(&ha->vport_slock);
  2090. mutex_init(&ha->selflogin_lock);
  2091. mutex_init(&ha->optrom_mutex);
  2092. /* Set ISP-type information. */
  2093. qla2x00_set_isp_flags(ha);
  2094. /* Set EEH reset type to fundamental if required by hba */
  2095. if (IS_QLA24XX(ha) || IS_QLA25XX(ha) || IS_QLA81XX(ha) ||
  2096. IS_QLA83XX(ha) || IS_QLA27XX(ha))
  2097. pdev->needs_freset = 1;
  2098. ha->prev_topology = 0;
  2099. ha->init_cb_size = sizeof(init_cb_t);
  2100. ha->link_data_rate = PORT_SPEED_UNKNOWN;
  2101. ha->optrom_size = OPTROM_SIZE_2300;
  2102. /* Assign ISP specific operations. */
  2103. if (IS_QLA2100(ha)) {
  2104. ha->max_fibre_devices = MAX_FIBRE_DEVICES_2100;
  2105. ha->mbx_count = MAILBOX_REGISTER_COUNT_2100;
  2106. req_length = REQUEST_ENTRY_CNT_2100;
  2107. rsp_length = RESPONSE_ENTRY_CNT_2100;
  2108. ha->max_loop_id = SNS_LAST_LOOP_ID_2100;
  2109. ha->gid_list_info_size = 4;
  2110. ha->flash_conf_off = ~0;
  2111. ha->flash_data_off = ~0;
  2112. ha->nvram_conf_off = ~0;
  2113. ha->nvram_data_off = ~0;
  2114. ha->isp_ops = &qla2100_isp_ops;
  2115. } else if (IS_QLA2200(ha)) {
  2116. ha->max_fibre_devices = MAX_FIBRE_DEVICES_2100;
  2117. ha->mbx_count = MAILBOX_REGISTER_COUNT_2200;
  2118. req_length = REQUEST_ENTRY_CNT_2200;
  2119. rsp_length = RESPONSE_ENTRY_CNT_2100;
  2120. ha->max_loop_id = SNS_LAST_LOOP_ID_2100;
  2121. ha->gid_list_info_size = 4;
  2122. ha->flash_conf_off = ~0;
  2123. ha->flash_data_off = ~0;
  2124. ha->nvram_conf_off = ~0;
  2125. ha->nvram_data_off = ~0;
  2126. ha->isp_ops = &qla2100_isp_ops;
  2127. } else if (IS_QLA23XX(ha)) {
  2128. ha->max_fibre_devices = MAX_FIBRE_DEVICES_2100;
  2129. ha->mbx_count = MAILBOX_REGISTER_COUNT;
  2130. req_length = REQUEST_ENTRY_CNT_2200;
  2131. rsp_length = RESPONSE_ENTRY_CNT_2300;
  2132. ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
  2133. ha->gid_list_info_size = 6;
  2134. if (IS_QLA2322(ha) || IS_QLA6322(ha))
  2135. ha->optrom_size = OPTROM_SIZE_2322;
  2136. ha->flash_conf_off = ~0;
  2137. ha->flash_data_off = ~0;
  2138. ha->nvram_conf_off = ~0;
  2139. ha->nvram_data_off = ~0;
  2140. ha->isp_ops = &qla2300_isp_ops;
  2141. } else if (IS_QLA24XX_TYPE(ha)) {
  2142. ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
  2143. ha->mbx_count = MAILBOX_REGISTER_COUNT;
  2144. req_length = REQUEST_ENTRY_CNT_24XX;
  2145. rsp_length = RESPONSE_ENTRY_CNT_2300;
  2146. ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
  2147. ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
  2148. ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
  2149. ha->gid_list_info_size = 8;
  2150. ha->optrom_size = OPTROM_SIZE_24XX;
  2151. ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA24XX;
  2152. ha->isp_ops = &qla24xx_isp_ops;
  2153. ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
  2154. ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
  2155. ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
  2156. ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
  2157. } else if (IS_QLA25XX(ha)) {
  2158. ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
  2159. ha->mbx_count = MAILBOX_REGISTER_COUNT;
  2160. req_length = REQUEST_ENTRY_CNT_24XX;
  2161. rsp_length = RESPONSE_ENTRY_CNT_2300;
  2162. ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
  2163. ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
  2164. ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
  2165. ha->gid_list_info_size = 8;
  2166. ha->optrom_size = OPTROM_SIZE_25XX;
  2167. ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
  2168. ha->isp_ops = &qla25xx_isp_ops;
  2169. ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
  2170. ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
  2171. ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
  2172. ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
  2173. } else if (IS_QLA81XX(ha)) {
  2174. ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
  2175. ha->mbx_count = MAILBOX_REGISTER_COUNT;
  2176. req_length = REQUEST_ENTRY_CNT_24XX;
  2177. rsp_length = RESPONSE_ENTRY_CNT_2300;
  2178. ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
  2179. ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
  2180. ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
  2181. ha->gid_list_info_size = 8;
  2182. ha->optrom_size = OPTROM_SIZE_81XX;
  2183. ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
  2184. ha->isp_ops = &qla81xx_isp_ops;
  2185. ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_81XX;
  2186. ha->flash_data_off = FARX_ACCESS_FLASH_DATA_81XX;
  2187. ha->nvram_conf_off = ~0;
  2188. ha->nvram_data_off = ~0;
  2189. } else if (IS_QLA82XX(ha)) {
  2190. ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
  2191. ha->mbx_count = MAILBOX_REGISTER_COUNT;
  2192. req_length = REQUEST_ENTRY_CNT_82XX;
  2193. rsp_length = RESPONSE_ENTRY_CNT_82XX;
  2194. ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
  2195. ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
  2196. ha->gid_list_info_size = 8;
  2197. ha->optrom_size = OPTROM_SIZE_82XX;
  2198. ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
  2199. ha->isp_ops = &qla82xx_isp_ops;
  2200. ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
  2201. ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
  2202. ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
  2203. ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
  2204. } else if (IS_QLA8044(ha)) {
  2205. ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
  2206. ha->mbx_count = MAILBOX_REGISTER_COUNT;
  2207. req_length = REQUEST_ENTRY_CNT_82XX;
  2208. rsp_length = RESPONSE_ENTRY_CNT_82XX;
  2209. ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
  2210. ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
  2211. ha->gid_list_info_size = 8;
  2212. ha->optrom_size = OPTROM_SIZE_83XX;
  2213. ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
  2214. ha->isp_ops = &qla8044_isp_ops;
  2215. ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
  2216. ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
  2217. ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
  2218. ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
  2219. } else if (IS_QLA83XX(ha)) {
  2220. ha->portnum = PCI_FUNC(ha->pdev->devfn);
  2221. ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
  2222. ha->mbx_count = MAILBOX_REGISTER_COUNT;
  2223. req_length = REQUEST_ENTRY_CNT_83XX;
  2224. rsp_length = RESPONSE_ENTRY_CNT_2300;
  2225. ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
  2226. ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
  2227. ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
  2228. ha->gid_list_info_size = 8;
  2229. ha->optrom_size = OPTROM_SIZE_83XX;
  2230. ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
  2231. ha->isp_ops = &qla83xx_isp_ops;
  2232. ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_81XX;
  2233. ha->flash_data_off = FARX_ACCESS_FLASH_DATA_81XX;
  2234. ha->nvram_conf_off = ~0;
  2235. ha->nvram_data_off = ~0;
  2236. } else if (IS_QLAFX00(ha)) {
  2237. ha->max_fibre_devices = MAX_FIBRE_DEVICES_FX00;
  2238. ha->mbx_count = MAILBOX_REGISTER_COUNT_FX00;
  2239. ha->aen_mbx_count = AEN_MAILBOX_REGISTER_COUNT_FX00;
  2240. req_length = REQUEST_ENTRY_CNT_FX00;
  2241. rsp_length = RESPONSE_ENTRY_CNT_FX00;
  2242. ha->isp_ops = &qlafx00_isp_ops;
  2243. ha->port_down_retry_count = 30; /* default value */
  2244. ha->mr.fw_hbt_cnt = QLAFX00_HEARTBEAT_INTERVAL;
  2245. ha->mr.fw_reset_timer_tick = QLAFX00_RESET_INTERVAL;
  2246. ha->mr.fw_critemp_timer_tick = QLAFX00_CRITEMP_INTERVAL;
  2247. ha->mr.fw_hbt_en = 1;
  2248. ha->mr.host_info_resend = false;
  2249. ha->mr.hinfo_resend_timer_tick = QLAFX00_HINFO_RESEND_INTERVAL;
  2250. } else if (IS_QLA27XX(ha)) {
  2251. ha->portnum = PCI_FUNC(ha->pdev->devfn);
  2252. ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
  2253. ha->mbx_count = MAILBOX_REGISTER_COUNT;
  2254. req_length = REQUEST_ENTRY_CNT_24XX;
  2255. rsp_length = RESPONSE_ENTRY_CNT_2300;
  2256. ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
  2257. ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
  2258. ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
  2259. ha->gid_list_info_size = 8;
  2260. ha->optrom_size = OPTROM_SIZE_83XX;
  2261. ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
  2262. ha->isp_ops = &qla27xx_isp_ops;
  2263. ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_81XX;
  2264. ha->flash_data_off = FARX_ACCESS_FLASH_DATA_81XX;
  2265. ha->nvram_conf_off = ~0;
  2266. ha->nvram_data_off = ~0;
  2267. }
  2268. ql_dbg_pci(ql_dbg_init, pdev, 0x001e,
  2269. "mbx_count=%d, req_length=%d, "
  2270. "rsp_length=%d, max_loop_id=%d, init_cb_size=%d, "
  2271. "gid_list_info_size=%d, optrom_size=%d, nvram_npiv_size=%d, "
  2272. "max_fibre_devices=%d.\n",
  2273. ha->mbx_count, req_length, rsp_length, ha->max_loop_id,
  2274. ha->init_cb_size, ha->gid_list_info_size, ha->optrom_size,
  2275. ha->nvram_npiv_size, ha->max_fibre_devices);
  2276. ql_dbg_pci(ql_dbg_init, pdev, 0x001f,
  2277. "isp_ops=%p, flash_conf_off=%d, "
  2278. "flash_data_off=%d, nvram_conf_off=%d, nvram_data_off=%d.\n",
  2279. ha->isp_ops, ha->flash_conf_off, ha->flash_data_off,
  2280. ha->nvram_conf_off, ha->nvram_data_off);
  2281. /* Configure PCI I/O space */
  2282. ret = ha->isp_ops->iospace_config(ha);
  2283. if (ret)
  2284. goto iospace_config_failed;
  2285. ql_log_pci(ql_log_info, pdev, 0x001d,
  2286. "Found an ISP%04X irq %d iobase 0x%p.\n",
  2287. pdev->device, pdev->irq, ha->iobase);
  2288. mutex_init(&ha->vport_lock);
  2289. init_completion(&ha->mbx_cmd_comp);
  2290. complete(&ha->mbx_cmd_comp);
  2291. init_completion(&ha->mbx_intr_comp);
  2292. init_completion(&ha->dcbx_comp);
  2293. init_completion(&ha->lb_portup_comp);
  2294. set_bit(0, (unsigned long *) ha->vp_idx_map);
  2295. qla2x00_config_dma_addressing(ha);
  2296. ql_dbg_pci(ql_dbg_init, pdev, 0x0020,
  2297. "64 Bit addressing is %s.\n",
  2298. ha->flags.enable_64bit_addressing ? "enable" :
  2299. "disable");
  2300. ret = qla2x00_mem_alloc(ha, req_length, rsp_length, &req, &rsp);
  2301. if (ret) {
  2302. ql_log_pci(ql_log_fatal, pdev, 0x0031,
  2303. "Failed to allocate memory for adapter, aborting.\n");
  2304. goto probe_hw_failed;
  2305. }
  2306. req->max_q_depth = MAX_Q_DEPTH;
  2307. if (ql2xmaxqdepth != 0 && ql2xmaxqdepth <= 0xffffU)
  2308. req->max_q_depth = ql2xmaxqdepth;
  2309. base_vha = qla2x00_create_host(sht, ha);
  2310. if (!base_vha) {
  2311. ret = -ENOMEM;
  2312. qla2x00_mem_free(ha);
  2313. qla2x00_free_req_que(ha, req);
  2314. qla2x00_free_rsp_que(ha, rsp);
  2315. goto probe_hw_failed;
  2316. }
  2317. pci_set_drvdata(pdev, base_vha);
  2318. set_bit(PFLG_DRIVER_PROBING, &base_vha->pci_flags);
  2319. host = base_vha->host;
  2320. base_vha->req = req;
  2321. if (IS_QLA2XXX_MIDTYPE(ha))
  2322. base_vha->mgmt_svr_loop_id = 10 + base_vha->vp_idx;
  2323. else
  2324. base_vha->mgmt_svr_loop_id = MANAGEMENT_SERVER +
  2325. base_vha->vp_idx;
  2326. /* Setup fcport template structure. */
  2327. ha->mr.fcport.vha = base_vha;
  2328. ha->mr.fcport.port_type = FCT_UNKNOWN;
  2329. ha->mr.fcport.loop_id = FC_NO_LOOP_ID;
  2330. qla2x00_set_fcport_state(&ha->mr.fcport, FCS_UNCONFIGURED);
  2331. ha->mr.fcport.supported_classes = FC_COS_UNSPECIFIED;
  2332. ha->mr.fcport.scan_state = 1;
  2333. /* Set the SG table size based on ISP type */
  2334. if (!IS_FWI2_CAPABLE(ha)) {
  2335. if (IS_QLA2100(ha))
  2336. host->sg_tablesize = 32;
  2337. } else {
  2338. if (!IS_QLA82XX(ha))
  2339. host->sg_tablesize = QLA_SG_ALL;
  2340. }
  2341. host->max_id = ha->max_fibre_devices;
  2342. host->cmd_per_lun = 3;
  2343. host->unique_id = host->host_no;
  2344. if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif)
  2345. host->max_cmd_len = 32;
  2346. else
  2347. host->max_cmd_len = MAX_CMDSZ;
  2348. host->max_channel = MAX_BUSES - 1;
  2349. /* Older HBAs support only 16-bit LUNs */
  2350. if (!IS_QLAFX00(ha) && !IS_FWI2_CAPABLE(ha) &&
  2351. ql2xmaxlun > 0xffff)
  2352. host->max_lun = 0xffff;
  2353. else
  2354. host->max_lun = ql2xmaxlun;
  2355. host->transportt = qla2xxx_transport_template;
  2356. sht->vendor_id = (SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_QLOGIC);
  2357. ql_dbg(ql_dbg_init, base_vha, 0x0033,
  2358. "max_id=%d this_id=%d "
  2359. "cmd_per_len=%d unique_id=%d max_cmd_len=%d max_channel=%d "
  2360. "max_lun=%llu transportt=%p, vendor_id=%llu.\n", host->max_id,
  2361. host->this_id, host->cmd_per_lun, host->unique_id,
  2362. host->max_cmd_len, host->max_channel, host->max_lun,
  2363. host->transportt, sht->vendor_id);
  2364. que_init:
  2365. /* Alloc arrays of request and response ring ptrs */
  2366. if (!qla2x00_alloc_queues(ha, req, rsp)) {
  2367. ql_log(ql_log_fatal, base_vha, 0x003d,
  2368. "Failed to allocate memory for queue pointers..."
  2369. "aborting.\n");
  2370. goto probe_init_failed;
  2371. }
  2372. qlt_probe_one_stage1(base_vha, ha);
  2373. /* Set up the irqs */
  2374. ret = qla2x00_request_irqs(ha, rsp);
  2375. if (ret)
  2376. goto probe_init_failed;
  2377. pci_save_state(pdev);
  2378. /* Assign back pointers */
  2379. rsp->req = req;
  2380. req->rsp = rsp;
  2381. if (IS_QLAFX00(ha)) {
  2382. ha->rsp_q_map[0] = rsp;
  2383. ha->req_q_map[0] = req;
  2384. set_bit(0, ha->req_qid_map);
  2385. set_bit(0, ha->rsp_qid_map);
  2386. }
  2387. /* FWI2-capable only. */
  2388. req->req_q_in = &ha->iobase->isp24.req_q_in;
  2389. req->req_q_out = &ha->iobase->isp24.req_q_out;
  2390. rsp->rsp_q_in = &ha->iobase->isp24.rsp_q_in;
  2391. rsp->rsp_q_out = &ha->iobase->isp24.rsp_q_out;
  2392. if (ha->mqenable || IS_QLA83XX(ha) || IS_QLA27XX(ha)) {
  2393. req->req_q_in = &ha->mqiobase->isp25mq.req_q_in;
  2394. req->req_q_out = &ha->mqiobase->isp25mq.req_q_out;
  2395. rsp->rsp_q_in = &ha->mqiobase->isp25mq.rsp_q_in;
  2396. rsp->rsp_q_out = &ha->mqiobase->isp25mq.rsp_q_out;
  2397. }
  2398. if (IS_QLAFX00(ha)) {
  2399. req->req_q_in = &ha->iobase->ispfx00.req_q_in;
  2400. req->req_q_out = &ha->iobase->ispfx00.req_q_out;
  2401. rsp->rsp_q_in = &ha->iobase->ispfx00.rsp_q_in;
  2402. rsp->rsp_q_out = &ha->iobase->ispfx00.rsp_q_out;
  2403. }
  2404. if (IS_P3P_TYPE(ha)) {
  2405. req->req_q_out = &ha->iobase->isp82.req_q_out[0];
  2406. rsp->rsp_q_in = &ha->iobase->isp82.rsp_q_in[0];
  2407. rsp->rsp_q_out = &ha->iobase->isp82.rsp_q_out[0];
  2408. }
  2409. ql_dbg(ql_dbg_multiq, base_vha, 0xc009,
  2410. "rsp_q_map=%p req_q_map=%p rsp->req=%p req->rsp=%p.\n",
  2411. ha->rsp_q_map, ha->req_q_map, rsp->req, req->rsp);
  2412. ql_dbg(ql_dbg_multiq, base_vha, 0xc00a,
  2413. "req->req_q_in=%p req->req_q_out=%p "
  2414. "rsp->rsp_q_in=%p rsp->rsp_q_out=%p.\n",
  2415. req->req_q_in, req->req_q_out,
  2416. rsp->rsp_q_in, rsp->rsp_q_out);
  2417. ql_dbg(ql_dbg_init, base_vha, 0x003e,
  2418. "rsp_q_map=%p req_q_map=%p rsp->req=%p req->rsp=%p.\n",
  2419. ha->rsp_q_map, ha->req_q_map, rsp->req, req->rsp);
  2420. ql_dbg(ql_dbg_init, base_vha, 0x003f,
  2421. "req->req_q_in=%p req->req_q_out=%p rsp->rsp_q_in=%p rsp->rsp_q_out=%p.\n",
  2422. req->req_q_in, req->req_q_out, rsp->rsp_q_in, rsp->rsp_q_out);
  2423. if (ha->isp_ops->initialize_adapter(base_vha)) {
  2424. ql_log(ql_log_fatal, base_vha, 0x00d6,
  2425. "Failed to initialize adapter - Adapter flags %x.\n",
  2426. base_vha->device_flags);
  2427. if (IS_QLA82XX(ha)) {
  2428. qla82xx_idc_lock(ha);
  2429. qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
  2430. QLA8XXX_DEV_FAILED);
  2431. qla82xx_idc_unlock(ha);
  2432. ql_log(ql_log_fatal, base_vha, 0x00d7,
  2433. "HW State: FAILED.\n");
  2434. } else if (IS_QLA8044(ha)) {
  2435. qla8044_idc_lock(ha);
  2436. qla8044_wr_direct(base_vha,
  2437. QLA8044_CRB_DEV_STATE_INDEX,
  2438. QLA8XXX_DEV_FAILED);
  2439. qla8044_idc_unlock(ha);
  2440. ql_log(ql_log_fatal, base_vha, 0x0150,
  2441. "HW State: FAILED.\n");
  2442. }
  2443. ret = -ENODEV;
  2444. goto probe_failed;
  2445. }
  2446. if (IS_QLAFX00(ha))
  2447. host->can_queue = QLAFX00_MAX_CANQUEUE;
  2448. else
  2449. host->can_queue = req->num_outstanding_cmds - 10;
  2450. ql_dbg(ql_dbg_init, base_vha, 0x0032,
  2451. "can_queue=%d, req=%p, mgmt_svr_loop_id=%d, sg_tablesize=%d.\n",
  2452. host->can_queue, base_vha->req,
  2453. base_vha->mgmt_svr_loop_id, host->sg_tablesize);
  2454. if (ha->mqenable) {
  2455. if (qla25xx_setup_mode(base_vha)) {
  2456. ql_log(ql_log_warn, base_vha, 0x00ec,
  2457. "Failed to create queues, falling back to single queue mode.\n");
  2458. goto que_init;
  2459. }
  2460. }
  2461. if (ha->flags.running_gold_fw)
  2462. goto skip_dpc;
  2463. /*
  2464. * Startup the kernel thread for this host adapter
  2465. */
  2466. ha->dpc_thread = kthread_create(qla2x00_do_dpc, ha,
  2467. "%s_dpc", base_vha->host_str);
  2468. if (IS_ERR(ha->dpc_thread)) {
  2469. ql_log(ql_log_fatal, base_vha, 0x00ed,
  2470. "Failed to start DPC thread.\n");
  2471. ret = PTR_ERR(ha->dpc_thread);
  2472. goto probe_failed;
  2473. }
  2474. ql_dbg(ql_dbg_init, base_vha, 0x00ee,
  2475. "DPC thread started successfully.\n");
  2476. /*
  2477. * If we're not coming up in initiator mode, we might sit for
  2478. * a while without waking up the dpc thread, which leads to a
  2479. * stuck process warning. So just kick the dpc once here and
  2480. * let the kthread start (and go back to sleep in qla2x00_do_dpc).
  2481. */
  2482. qla2xxx_wake_dpc(base_vha);
  2483. INIT_WORK(&ha->board_disable, qla2x00_disable_board_on_pci_error);
  2484. if (IS_QLA8031(ha) || IS_MCTP_CAPABLE(ha)) {
  2485. sprintf(wq_name, "qla2xxx_%lu_dpc_lp_wq", base_vha->host_no);
  2486. ha->dpc_lp_wq = create_singlethread_workqueue(wq_name);
  2487. INIT_WORK(&ha->idc_aen, qla83xx_service_idc_aen);
  2488. sprintf(wq_name, "qla2xxx_%lu_dpc_hp_wq", base_vha->host_no);
  2489. ha->dpc_hp_wq = create_singlethread_workqueue(wq_name);
  2490. INIT_WORK(&ha->nic_core_reset, qla83xx_nic_core_reset_work);
  2491. INIT_WORK(&ha->idc_state_handler,
  2492. qla83xx_idc_state_handler_work);
  2493. INIT_WORK(&ha->nic_core_unrecoverable,
  2494. qla83xx_nic_core_unrecoverable_work);
  2495. }
  2496. skip_dpc:
  2497. list_add_tail(&base_vha->list, &ha->vp_list);
  2498. base_vha->host->irq = ha->pdev->irq;
  2499. /* Initialized the timer */
  2500. qla2x00_start_timer(base_vha, qla2x00_timer, WATCH_INTERVAL);
  2501. ql_dbg(ql_dbg_init, base_vha, 0x00ef,
  2502. "Started qla2x00_timer with "
  2503. "interval=%d.\n", WATCH_INTERVAL);
  2504. ql_dbg(ql_dbg_init, base_vha, 0x00f0,
  2505. "Detected hba at address=%p.\n",
  2506. ha);
  2507. if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif) {
  2508. if (ha->fw_attributes & BIT_4) {
  2509. int prot = 0, guard;
  2510. base_vha->flags.difdix_supported = 1;
  2511. ql_dbg(ql_dbg_init, base_vha, 0x00f1,
  2512. "Registering for DIF/DIX type 1 and 3 protection.\n");
  2513. if (ql2xenabledif == 1)
  2514. prot = SHOST_DIX_TYPE0_PROTECTION;
  2515. scsi_host_set_prot(host,
  2516. prot | SHOST_DIF_TYPE1_PROTECTION
  2517. | SHOST_DIF_TYPE2_PROTECTION
  2518. | SHOST_DIF_TYPE3_PROTECTION
  2519. | SHOST_DIX_TYPE1_PROTECTION
  2520. | SHOST_DIX_TYPE2_PROTECTION
  2521. | SHOST_DIX_TYPE3_PROTECTION);
  2522. guard = SHOST_DIX_GUARD_CRC;
  2523. if (IS_PI_IPGUARD_CAPABLE(ha) &&
  2524. (ql2xenabledif > 1 || IS_PI_DIFB_DIX0_CAPABLE(ha)))
  2525. guard |= SHOST_DIX_GUARD_IP;
  2526. scsi_host_set_guard(host, guard);
  2527. } else
  2528. base_vha->flags.difdix_supported = 0;
  2529. }
  2530. ha->isp_ops->enable_intrs(ha);
  2531. if (IS_QLAFX00(ha)) {
  2532. ret = qlafx00_fx_disc(base_vha,
  2533. &base_vha->hw->mr.fcport, FXDISC_GET_CONFIG_INFO);
  2534. host->sg_tablesize = (ha->mr.extended_io_enabled) ?
  2535. QLA_SG_ALL : 128;
  2536. }
  2537. ret = scsi_add_host(host, &pdev->dev);
  2538. if (ret)
  2539. goto probe_failed;
  2540. base_vha->flags.init_done = 1;
  2541. base_vha->flags.online = 1;
  2542. ha->prev_minidump_failed = 0;
  2543. ql_dbg(ql_dbg_init, base_vha, 0x00f2,
  2544. "Init done and hba is online.\n");
  2545. if (qla_ini_mode_enabled(base_vha))
  2546. scsi_scan_host(host);
  2547. else
  2548. ql_dbg(ql_dbg_init, base_vha, 0x0122,
  2549. "skipping scsi_scan_host() for non-initiator port\n");
  2550. qla2x00_alloc_sysfs_attr(base_vha);
  2551. if (IS_QLAFX00(ha)) {
  2552. ret = qlafx00_fx_disc(base_vha,
  2553. &base_vha->hw->mr.fcport, FXDISC_GET_PORT_INFO);
  2554. /* Register system information */
  2555. ret = qlafx00_fx_disc(base_vha,
  2556. &base_vha->hw->mr.fcport, FXDISC_REG_HOST_INFO);
  2557. }
  2558. qla2x00_init_host_attr(base_vha);
  2559. qla2x00_dfs_setup(base_vha);
  2560. ql_log(ql_log_info, base_vha, 0x00fb,
  2561. "QLogic %s - %s.\n", ha->model_number, ha->model_desc);
  2562. ql_log(ql_log_info, base_vha, 0x00fc,
  2563. "ISP%04X: %s @ %s hdma%c host#=%ld fw=%s.\n",
  2564. pdev->device, ha->isp_ops->pci_info_str(base_vha, pci_info),
  2565. pci_name(pdev), ha->flags.enable_64bit_addressing ? '+' : '-',
  2566. base_vha->host_no,
  2567. ha->isp_ops->fw_version_str(base_vha, fw_str, sizeof(fw_str)));
  2568. qlt_add_target(ha, base_vha);
  2569. clear_bit(PFLG_DRIVER_PROBING, &base_vha->pci_flags);
  2570. return 0;
  2571. probe_init_failed:
  2572. qla2x00_free_req_que(ha, req);
  2573. ha->req_q_map[0] = NULL;
  2574. clear_bit(0, ha->req_qid_map);
  2575. qla2x00_free_rsp_que(ha, rsp);
  2576. ha->rsp_q_map[0] = NULL;
  2577. clear_bit(0, ha->rsp_qid_map);
  2578. ha->max_req_queues = ha->max_rsp_queues = 0;
  2579. probe_failed:
  2580. if (base_vha->timer_active)
  2581. qla2x00_stop_timer(base_vha);
  2582. base_vha->flags.online = 0;
  2583. if (ha->dpc_thread) {
  2584. struct task_struct *t = ha->dpc_thread;
  2585. ha->dpc_thread = NULL;
  2586. kthread_stop(t);
  2587. }
  2588. qla2x00_free_device(base_vha);
  2589. scsi_host_put(base_vha->host);
  2590. probe_hw_failed:
  2591. qla2x00_clear_drv_active(ha);
  2592. iospace_config_failed:
  2593. if (IS_P3P_TYPE(ha)) {
  2594. if (!ha->nx_pcibase)
  2595. iounmap((device_reg_t *)ha->nx_pcibase);
  2596. if (!ql2xdbwr)
  2597. iounmap((device_reg_t *)ha->nxdb_wr_ptr);
  2598. } else {
  2599. if (ha->iobase)
  2600. iounmap(ha->iobase);
  2601. if (ha->cregbase)
  2602. iounmap(ha->cregbase);
  2603. }
  2604. pci_release_selected_regions(ha->pdev, ha->bars);
  2605. kfree(ha);
  2606. ha = NULL;
  2607. disable_device:
  2608. pci_disable_device(pdev);
  2609. return ret;
  2610. }
  2611. static void
  2612. qla2x00_shutdown(struct pci_dev *pdev)
  2613. {
  2614. scsi_qla_host_t *vha;
  2615. struct qla_hw_data *ha;
  2616. if (!atomic_read(&pdev->enable_cnt))
  2617. return;
  2618. vha = pci_get_drvdata(pdev);
  2619. ha = vha->hw;
  2620. /* Notify ISPFX00 firmware */
  2621. if (IS_QLAFX00(ha))
  2622. qlafx00_driver_shutdown(vha, 20);
  2623. /* Turn-off FCE trace */
  2624. if (ha->flags.fce_enabled) {
  2625. qla2x00_disable_fce_trace(vha, NULL, NULL);
  2626. ha->flags.fce_enabled = 0;
  2627. }
  2628. /* Turn-off EFT trace */
  2629. if (ha->eft)
  2630. qla2x00_disable_eft_trace(vha);
  2631. /* Stop currently executing firmware. */
  2632. qla2x00_try_to_stop_firmware(vha);
  2633. /* Turn adapter off line */
  2634. vha->flags.online = 0;
  2635. /* turn-off interrupts on the card */
  2636. if (ha->interrupts_on) {
  2637. vha->flags.init_done = 0;
  2638. ha->isp_ops->disable_intrs(ha);
  2639. }
  2640. qla2x00_free_irqs(vha);
  2641. qla2x00_free_fw_dump(ha);
  2642. pci_disable_pcie_error_reporting(pdev);
  2643. pci_disable_device(pdev);
  2644. }
  2645. /* Deletes all the virtual ports for a given ha */
  2646. static void
  2647. qla2x00_delete_all_vps(struct qla_hw_data *ha, scsi_qla_host_t *base_vha)
  2648. {
  2649. scsi_qla_host_t *vha;
  2650. unsigned long flags;
  2651. mutex_lock(&ha->vport_lock);
  2652. while (ha->cur_vport_count) {
  2653. spin_lock_irqsave(&ha->vport_slock, flags);
  2654. BUG_ON(base_vha->list.next == &ha->vp_list);
  2655. /* This assumes first entry in ha->vp_list is always base vha */
  2656. vha = list_first_entry(&base_vha->list, scsi_qla_host_t, list);
  2657. scsi_host_get(vha->host);
  2658. spin_unlock_irqrestore(&ha->vport_slock, flags);
  2659. mutex_unlock(&ha->vport_lock);
  2660. fc_vport_terminate(vha->fc_vport);
  2661. scsi_host_put(vha->host);
  2662. mutex_lock(&ha->vport_lock);
  2663. }
  2664. mutex_unlock(&ha->vport_lock);
  2665. }
  2666. /* Stops all deferred work threads */
  2667. static void
  2668. qla2x00_destroy_deferred_work(struct qla_hw_data *ha)
  2669. {
  2670. /* Flush the work queue and remove it */
  2671. if (ha->wq) {
  2672. flush_workqueue(ha->wq);
  2673. destroy_workqueue(ha->wq);
  2674. ha->wq = NULL;
  2675. }
  2676. /* Cancel all work and destroy DPC workqueues */
  2677. if (ha->dpc_lp_wq) {
  2678. cancel_work_sync(&ha->idc_aen);
  2679. destroy_workqueue(ha->dpc_lp_wq);
  2680. ha->dpc_lp_wq = NULL;
  2681. }
  2682. if (ha->dpc_hp_wq) {
  2683. cancel_work_sync(&ha->nic_core_reset);
  2684. cancel_work_sync(&ha->idc_state_handler);
  2685. cancel_work_sync(&ha->nic_core_unrecoverable);
  2686. destroy_workqueue(ha->dpc_hp_wq);
  2687. ha->dpc_hp_wq = NULL;
  2688. }
  2689. /* Kill the kernel thread for this host */
  2690. if (ha->dpc_thread) {
  2691. struct task_struct *t = ha->dpc_thread;
  2692. /*
  2693. * qla2xxx_wake_dpc checks for ->dpc_thread
  2694. * so we need to zero it out.
  2695. */
  2696. ha->dpc_thread = NULL;
  2697. kthread_stop(t);
  2698. }
  2699. }
  2700. static void
  2701. qla2x00_unmap_iobases(struct qla_hw_data *ha)
  2702. {
  2703. if (IS_QLA82XX(ha)) {
  2704. iounmap((device_reg_t *)ha->nx_pcibase);
  2705. if (!ql2xdbwr)
  2706. iounmap((device_reg_t *)ha->nxdb_wr_ptr);
  2707. } else {
  2708. if (ha->iobase)
  2709. iounmap(ha->iobase);
  2710. if (ha->cregbase)
  2711. iounmap(ha->cregbase);
  2712. if (ha->mqiobase)
  2713. iounmap(ha->mqiobase);
  2714. if ((IS_QLA83XX(ha) || IS_QLA27XX(ha)) && ha->msixbase)
  2715. iounmap(ha->msixbase);
  2716. }
  2717. }
  2718. static void
  2719. qla2x00_clear_drv_active(struct qla_hw_data *ha)
  2720. {
  2721. if (IS_QLA8044(ha)) {
  2722. qla8044_idc_lock(ha);
  2723. qla8044_clear_drv_active(ha);
  2724. qla8044_idc_unlock(ha);
  2725. } else if (IS_QLA82XX(ha)) {
  2726. qla82xx_idc_lock(ha);
  2727. qla82xx_clear_drv_active(ha);
  2728. qla82xx_idc_unlock(ha);
  2729. }
  2730. }
  2731. static void
  2732. qla2x00_remove_one(struct pci_dev *pdev)
  2733. {
  2734. scsi_qla_host_t *base_vha;
  2735. struct qla_hw_data *ha;
  2736. base_vha = pci_get_drvdata(pdev);
  2737. ha = base_vha->hw;
  2738. /* Indicate device removal to prevent future board_disable and wait
  2739. * until any pending board_disable has completed. */
  2740. set_bit(PFLG_DRIVER_REMOVING, &base_vha->pci_flags);
  2741. cancel_work_sync(&ha->board_disable);
  2742. /*
  2743. * If the PCI device is disabled then there was a PCI-disconnect and
  2744. * qla2x00_disable_board_on_pci_error has taken care of most of the
  2745. * resources.
  2746. */
  2747. if (!atomic_read(&pdev->enable_cnt)) {
  2748. scsi_host_put(base_vha->host);
  2749. kfree(ha);
  2750. pci_set_drvdata(pdev, NULL);
  2751. return;
  2752. }
  2753. qla2x00_wait_for_hba_ready(base_vha);
  2754. set_bit(UNLOADING, &base_vha->dpc_flags);
  2755. if (IS_QLAFX00(ha))
  2756. qlafx00_driver_shutdown(base_vha, 20);
  2757. qla2x00_delete_all_vps(ha, base_vha);
  2758. if (IS_QLA8031(ha)) {
  2759. ql_dbg(ql_dbg_p3p, base_vha, 0xb07e,
  2760. "Clearing fcoe driver presence.\n");
  2761. if (qla83xx_clear_drv_presence(base_vha) != QLA_SUCCESS)
  2762. ql_dbg(ql_dbg_p3p, base_vha, 0xb079,
  2763. "Error while clearing DRV-Presence.\n");
  2764. }
  2765. qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16);
  2766. qla2x00_dfs_remove(base_vha);
  2767. qla84xx_put_chip(base_vha);
  2768. /* Laser should be disabled only for ISP2031 */
  2769. if (IS_QLA2031(ha))
  2770. qla83xx_disable_laser(base_vha);
  2771. /* Disable timer */
  2772. if (base_vha->timer_active)
  2773. qla2x00_stop_timer(base_vha);
  2774. base_vha->flags.online = 0;
  2775. qla2x00_destroy_deferred_work(ha);
  2776. qlt_remove_target(ha, base_vha);
  2777. qla2x00_free_sysfs_attr(base_vha, true);
  2778. fc_remove_host(base_vha->host);
  2779. scsi_remove_host(base_vha->host);
  2780. qla2x00_free_device(base_vha);
  2781. qla2x00_clear_drv_active(ha);
  2782. scsi_host_put(base_vha->host);
  2783. qla2x00_unmap_iobases(ha);
  2784. pci_release_selected_regions(ha->pdev, ha->bars);
  2785. kfree(ha);
  2786. ha = NULL;
  2787. pci_disable_pcie_error_reporting(pdev);
  2788. pci_disable_device(pdev);
  2789. }
  2790. static void
  2791. qla2x00_free_device(scsi_qla_host_t *vha)
  2792. {
  2793. struct qla_hw_data *ha = vha->hw;
  2794. qla2x00_abort_all_cmds(vha, DID_NO_CONNECT << 16);
  2795. /* Disable timer */
  2796. if (vha->timer_active)
  2797. qla2x00_stop_timer(vha);
  2798. qla25xx_delete_queues(vha);
  2799. if (ha->flags.fce_enabled)
  2800. qla2x00_disable_fce_trace(vha, NULL, NULL);
  2801. if (ha->eft)
  2802. qla2x00_disable_eft_trace(vha);
  2803. /* Stop currently executing firmware. */
  2804. qla2x00_try_to_stop_firmware(vha);
  2805. vha->flags.online = 0;
  2806. /* turn-off interrupts on the card */
  2807. if (ha->interrupts_on) {
  2808. vha->flags.init_done = 0;
  2809. ha->isp_ops->disable_intrs(ha);
  2810. }
  2811. qla2x00_free_irqs(vha);
  2812. qla2x00_free_fcports(vha);
  2813. qla2x00_mem_free(ha);
  2814. qla82xx_md_free(vha);
  2815. qla2x00_free_queues(ha);
  2816. }
  2817. void qla2x00_free_fcports(struct scsi_qla_host *vha)
  2818. {
  2819. fc_port_t *fcport, *tfcport;
  2820. list_for_each_entry_safe(fcport, tfcport, &vha->vp_fcports, list) {
  2821. list_del(&fcport->list);
  2822. qla2x00_clear_loop_id(fcport);
  2823. kfree(fcport);
  2824. fcport = NULL;
  2825. }
  2826. }
  2827. static inline void
  2828. qla2x00_schedule_rport_del(struct scsi_qla_host *vha, fc_port_t *fcport,
  2829. int defer)
  2830. {
  2831. struct fc_rport *rport;
  2832. scsi_qla_host_t *base_vha;
  2833. unsigned long flags;
  2834. if (!fcport->rport)
  2835. return;
  2836. rport = fcport->rport;
  2837. if (defer) {
  2838. base_vha = pci_get_drvdata(vha->hw->pdev);
  2839. spin_lock_irqsave(vha->host->host_lock, flags);
  2840. fcport->drport = rport;
  2841. spin_unlock_irqrestore(vha->host->host_lock, flags);
  2842. qlt_do_generation_tick(vha, &base_vha->total_fcport_update_gen);
  2843. set_bit(FCPORT_UPDATE_NEEDED, &base_vha->dpc_flags);
  2844. qla2xxx_wake_dpc(base_vha);
  2845. } else {
  2846. int now;
  2847. if (rport)
  2848. fc_remote_port_delete(rport);
  2849. qlt_do_generation_tick(vha, &now);
  2850. qlt_fc_port_deleted(vha, fcport, now);
  2851. }
  2852. }
  2853. /*
  2854. * qla2x00_mark_device_lost Updates fcport state when device goes offline.
  2855. *
  2856. * Input: ha = adapter block pointer. fcport = port structure pointer.
  2857. *
  2858. * Return: None.
  2859. *
  2860. * Context:
  2861. */
  2862. void qla2x00_mark_device_lost(scsi_qla_host_t *vha, fc_port_t *fcport,
  2863. int do_login, int defer)
  2864. {
  2865. if (IS_QLAFX00(vha->hw)) {
  2866. qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
  2867. qla2x00_schedule_rport_del(vha, fcport, defer);
  2868. return;
  2869. }
  2870. if (atomic_read(&fcport->state) == FCS_ONLINE &&
  2871. vha->vp_idx == fcport->vha->vp_idx) {
  2872. qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
  2873. qla2x00_schedule_rport_del(vha, fcport, defer);
  2874. }
  2875. /*
  2876. * We may need to retry the login, so don't change the state of the
  2877. * port but do the retries.
  2878. */
  2879. if (atomic_read(&fcport->state) != FCS_DEVICE_DEAD)
  2880. qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
  2881. if (!do_login)
  2882. return;
  2883. set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
  2884. if (fcport->login_retry == 0) {
  2885. fcport->login_retry = vha->hw->login_retry_count;
  2886. ql_dbg(ql_dbg_disc, vha, 0x2067,
  2887. "Port login retry %8phN, id = 0x%04x retry cnt=%d.\n",
  2888. fcport->port_name, fcport->loop_id, fcport->login_retry);
  2889. }
  2890. }
  2891. /*
  2892. * qla2x00_mark_all_devices_lost
  2893. * Updates fcport state when device goes offline.
  2894. *
  2895. * Input:
  2896. * ha = adapter block pointer.
  2897. * fcport = port structure pointer.
  2898. *
  2899. * Return:
  2900. * None.
  2901. *
  2902. * Context:
  2903. */
  2904. void
  2905. qla2x00_mark_all_devices_lost(scsi_qla_host_t *vha, int defer)
  2906. {
  2907. fc_port_t *fcport;
  2908. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  2909. if (vha->vp_idx != 0 && vha->vp_idx != fcport->vha->vp_idx)
  2910. continue;
  2911. /*
  2912. * No point in marking the device as lost, if the device is
  2913. * already DEAD.
  2914. */
  2915. if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD)
  2916. continue;
  2917. if (atomic_read(&fcport->state) == FCS_ONLINE) {
  2918. qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
  2919. if (defer)
  2920. qla2x00_schedule_rport_del(vha, fcport, defer);
  2921. else if (vha->vp_idx == fcport->vha->vp_idx)
  2922. qla2x00_schedule_rport_del(vha, fcport, defer);
  2923. }
  2924. }
  2925. }
  2926. /*
  2927. * qla2x00_mem_alloc
  2928. * Allocates adapter memory.
  2929. *
  2930. * Returns:
  2931. * 0 = success.
  2932. * !0 = failure.
  2933. */
  2934. static int
  2935. qla2x00_mem_alloc(struct qla_hw_data *ha, uint16_t req_len, uint16_t rsp_len,
  2936. struct req_que **req, struct rsp_que **rsp)
  2937. {
  2938. char name[16];
  2939. ha->init_cb = dma_alloc_coherent(&ha->pdev->dev, ha->init_cb_size,
  2940. &ha->init_cb_dma, GFP_KERNEL);
  2941. if (!ha->init_cb)
  2942. goto fail;
  2943. if (qlt_mem_alloc(ha) < 0)
  2944. goto fail_free_init_cb;
  2945. ha->gid_list = dma_alloc_coherent(&ha->pdev->dev,
  2946. qla2x00_gid_list_size(ha), &ha->gid_list_dma, GFP_KERNEL);
  2947. if (!ha->gid_list)
  2948. goto fail_free_tgt_mem;
  2949. ha->srb_mempool = mempool_create_slab_pool(SRB_MIN_REQ, srb_cachep);
  2950. if (!ha->srb_mempool)
  2951. goto fail_free_gid_list;
  2952. if (IS_P3P_TYPE(ha)) {
  2953. /* Allocate cache for CT6 Ctx. */
  2954. if (!ctx_cachep) {
  2955. ctx_cachep = kmem_cache_create("qla2xxx_ctx",
  2956. sizeof(struct ct6_dsd), 0,
  2957. SLAB_HWCACHE_ALIGN, NULL);
  2958. if (!ctx_cachep)
  2959. goto fail_free_srb_mempool;
  2960. }
  2961. ha->ctx_mempool = mempool_create_slab_pool(SRB_MIN_REQ,
  2962. ctx_cachep);
  2963. if (!ha->ctx_mempool)
  2964. goto fail_free_srb_mempool;
  2965. ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0021,
  2966. "ctx_cachep=%p ctx_mempool=%p.\n",
  2967. ctx_cachep, ha->ctx_mempool);
  2968. }
  2969. /* Get memory for cached NVRAM */
  2970. ha->nvram = kzalloc(MAX_NVRAM_SIZE, GFP_KERNEL);
  2971. if (!ha->nvram)
  2972. goto fail_free_ctx_mempool;
  2973. snprintf(name, sizeof(name), "%s_%d", QLA2XXX_DRIVER_NAME,
  2974. ha->pdev->device);
  2975. ha->s_dma_pool = dma_pool_create(name, &ha->pdev->dev,
  2976. DMA_POOL_SIZE, 8, 0);
  2977. if (!ha->s_dma_pool)
  2978. goto fail_free_nvram;
  2979. ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0022,
  2980. "init_cb=%p gid_list=%p, srb_mempool=%p s_dma_pool=%p.\n",
  2981. ha->init_cb, ha->gid_list, ha->srb_mempool, ha->s_dma_pool);
  2982. if (IS_P3P_TYPE(ha) || ql2xenabledif) {
  2983. ha->dl_dma_pool = dma_pool_create(name, &ha->pdev->dev,
  2984. DSD_LIST_DMA_POOL_SIZE, 8, 0);
  2985. if (!ha->dl_dma_pool) {
  2986. ql_log_pci(ql_log_fatal, ha->pdev, 0x0023,
  2987. "Failed to allocate memory for dl_dma_pool.\n");
  2988. goto fail_s_dma_pool;
  2989. }
  2990. ha->fcp_cmnd_dma_pool = dma_pool_create(name, &ha->pdev->dev,
  2991. FCP_CMND_DMA_POOL_SIZE, 8, 0);
  2992. if (!ha->fcp_cmnd_dma_pool) {
  2993. ql_log_pci(ql_log_fatal, ha->pdev, 0x0024,
  2994. "Failed to allocate memory for fcp_cmnd_dma_pool.\n");
  2995. goto fail_dl_dma_pool;
  2996. }
  2997. ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0025,
  2998. "dl_dma_pool=%p fcp_cmnd_dma_pool=%p.\n",
  2999. ha->dl_dma_pool, ha->fcp_cmnd_dma_pool);
  3000. }
  3001. /* Allocate memory for SNS commands */
  3002. if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
  3003. /* Get consistent memory allocated for SNS commands */
  3004. ha->sns_cmd = dma_alloc_coherent(&ha->pdev->dev,
  3005. sizeof(struct sns_cmd_pkt), &ha->sns_cmd_dma, GFP_KERNEL);
  3006. if (!ha->sns_cmd)
  3007. goto fail_dma_pool;
  3008. ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0026,
  3009. "sns_cmd: %p.\n", ha->sns_cmd);
  3010. } else {
  3011. /* Get consistent memory allocated for MS IOCB */
  3012. ha->ms_iocb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
  3013. &ha->ms_iocb_dma);
  3014. if (!ha->ms_iocb)
  3015. goto fail_dma_pool;
  3016. /* Get consistent memory allocated for CT SNS commands */
  3017. ha->ct_sns = dma_alloc_coherent(&ha->pdev->dev,
  3018. sizeof(struct ct_sns_pkt), &ha->ct_sns_dma, GFP_KERNEL);
  3019. if (!ha->ct_sns)
  3020. goto fail_free_ms_iocb;
  3021. ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0027,
  3022. "ms_iocb=%p ct_sns=%p.\n",
  3023. ha->ms_iocb, ha->ct_sns);
  3024. }
  3025. /* Allocate memory for request ring */
  3026. *req = kzalloc(sizeof(struct req_que), GFP_KERNEL);
  3027. if (!*req) {
  3028. ql_log_pci(ql_log_fatal, ha->pdev, 0x0028,
  3029. "Failed to allocate memory for req.\n");
  3030. goto fail_req;
  3031. }
  3032. (*req)->length = req_len;
  3033. (*req)->ring = dma_alloc_coherent(&ha->pdev->dev,
  3034. ((*req)->length + 1) * sizeof(request_t),
  3035. &(*req)->dma, GFP_KERNEL);
  3036. if (!(*req)->ring) {
  3037. ql_log_pci(ql_log_fatal, ha->pdev, 0x0029,
  3038. "Failed to allocate memory for req_ring.\n");
  3039. goto fail_req_ring;
  3040. }
  3041. /* Allocate memory for response ring */
  3042. *rsp = kzalloc(sizeof(struct rsp_que), GFP_KERNEL);
  3043. if (!*rsp) {
  3044. ql_log_pci(ql_log_fatal, ha->pdev, 0x002a,
  3045. "Failed to allocate memory for rsp.\n");
  3046. goto fail_rsp;
  3047. }
  3048. (*rsp)->hw = ha;
  3049. (*rsp)->length = rsp_len;
  3050. (*rsp)->ring = dma_alloc_coherent(&ha->pdev->dev,
  3051. ((*rsp)->length + 1) * sizeof(response_t),
  3052. &(*rsp)->dma, GFP_KERNEL);
  3053. if (!(*rsp)->ring) {
  3054. ql_log_pci(ql_log_fatal, ha->pdev, 0x002b,
  3055. "Failed to allocate memory for rsp_ring.\n");
  3056. goto fail_rsp_ring;
  3057. }
  3058. (*req)->rsp = *rsp;
  3059. (*rsp)->req = *req;
  3060. ql_dbg_pci(ql_dbg_init, ha->pdev, 0x002c,
  3061. "req=%p req->length=%d req->ring=%p rsp=%p "
  3062. "rsp->length=%d rsp->ring=%p.\n",
  3063. *req, (*req)->length, (*req)->ring, *rsp, (*rsp)->length,
  3064. (*rsp)->ring);
  3065. /* Allocate memory for NVRAM data for vports */
  3066. if (ha->nvram_npiv_size) {
  3067. ha->npiv_info = kzalloc(sizeof(struct qla_npiv_entry) *
  3068. ha->nvram_npiv_size, GFP_KERNEL);
  3069. if (!ha->npiv_info) {
  3070. ql_log_pci(ql_log_fatal, ha->pdev, 0x002d,
  3071. "Failed to allocate memory for npiv_info.\n");
  3072. goto fail_npiv_info;
  3073. }
  3074. } else
  3075. ha->npiv_info = NULL;
  3076. /* Get consistent memory allocated for EX-INIT-CB. */
  3077. if (IS_CNA_CAPABLE(ha) || IS_QLA2031(ha) || IS_QLA27XX(ha)) {
  3078. ha->ex_init_cb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
  3079. &ha->ex_init_cb_dma);
  3080. if (!ha->ex_init_cb)
  3081. goto fail_ex_init_cb;
  3082. ql_dbg_pci(ql_dbg_init, ha->pdev, 0x002e,
  3083. "ex_init_cb=%p.\n", ha->ex_init_cb);
  3084. }
  3085. INIT_LIST_HEAD(&ha->gbl_dsd_list);
  3086. /* Get consistent memory allocated for Async Port-Database. */
  3087. if (!IS_FWI2_CAPABLE(ha)) {
  3088. ha->async_pd = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
  3089. &ha->async_pd_dma);
  3090. if (!ha->async_pd)
  3091. goto fail_async_pd;
  3092. ql_dbg_pci(ql_dbg_init, ha->pdev, 0x002f,
  3093. "async_pd=%p.\n", ha->async_pd);
  3094. }
  3095. INIT_LIST_HEAD(&ha->vp_list);
  3096. /* Allocate memory for our loop_id bitmap */
  3097. ha->loop_id_map = kzalloc(BITS_TO_LONGS(LOOPID_MAP_SIZE) * sizeof(long),
  3098. GFP_KERNEL);
  3099. if (!ha->loop_id_map)
  3100. goto fail_loop_id_map;
  3101. else {
  3102. qla2x00_set_reserved_loop_ids(ha);
  3103. ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0123,
  3104. "loop_id_map=%p.\n", ha->loop_id_map);
  3105. }
  3106. return 0;
  3107. fail_loop_id_map:
  3108. dma_pool_free(ha->s_dma_pool, ha->async_pd, ha->async_pd_dma);
  3109. fail_async_pd:
  3110. dma_pool_free(ha->s_dma_pool, ha->ex_init_cb, ha->ex_init_cb_dma);
  3111. fail_ex_init_cb:
  3112. kfree(ha->npiv_info);
  3113. fail_npiv_info:
  3114. dma_free_coherent(&ha->pdev->dev, ((*rsp)->length + 1) *
  3115. sizeof(response_t), (*rsp)->ring, (*rsp)->dma);
  3116. (*rsp)->ring = NULL;
  3117. (*rsp)->dma = 0;
  3118. fail_rsp_ring:
  3119. kfree(*rsp);
  3120. fail_rsp:
  3121. dma_free_coherent(&ha->pdev->dev, ((*req)->length + 1) *
  3122. sizeof(request_t), (*req)->ring, (*req)->dma);
  3123. (*req)->ring = NULL;
  3124. (*req)->dma = 0;
  3125. fail_req_ring:
  3126. kfree(*req);
  3127. fail_req:
  3128. dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
  3129. ha->ct_sns, ha->ct_sns_dma);
  3130. ha->ct_sns = NULL;
  3131. ha->ct_sns_dma = 0;
  3132. fail_free_ms_iocb:
  3133. dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
  3134. ha->ms_iocb = NULL;
  3135. ha->ms_iocb_dma = 0;
  3136. if (ha->sns_cmd)
  3137. dma_free_coherent(&ha->pdev->dev, sizeof(struct sns_cmd_pkt),
  3138. ha->sns_cmd, ha->sns_cmd_dma);
  3139. fail_dma_pool:
  3140. if (IS_QLA82XX(ha) || ql2xenabledif) {
  3141. dma_pool_destroy(ha->fcp_cmnd_dma_pool);
  3142. ha->fcp_cmnd_dma_pool = NULL;
  3143. }
  3144. fail_dl_dma_pool:
  3145. if (IS_QLA82XX(ha) || ql2xenabledif) {
  3146. dma_pool_destroy(ha->dl_dma_pool);
  3147. ha->dl_dma_pool = NULL;
  3148. }
  3149. fail_s_dma_pool:
  3150. dma_pool_destroy(ha->s_dma_pool);
  3151. ha->s_dma_pool = NULL;
  3152. fail_free_nvram:
  3153. kfree(ha->nvram);
  3154. ha->nvram = NULL;
  3155. fail_free_ctx_mempool:
  3156. if (ha->ctx_mempool)
  3157. mempool_destroy(ha->ctx_mempool);
  3158. ha->ctx_mempool = NULL;
  3159. fail_free_srb_mempool:
  3160. if (ha->srb_mempool)
  3161. mempool_destroy(ha->srb_mempool);
  3162. ha->srb_mempool = NULL;
  3163. fail_free_gid_list:
  3164. dma_free_coherent(&ha->pdev->dev, qla2x00_gid_list_size(ha),
  3165. ha->gid_list,
  3166. ha->gid_list_dma);
  3167. ha->gid_list = NULL;
  3168. ha->gid_list_dma = 0;
  3169. fail_free_tgt_mem:
  3170. qlt_mem_free(ha);
  3171. fail_free_init_cb:
  3172. dma_free_coherent(&ha->pdev->dev, ha->init_cb_size, ha->init_cb,
  3173. ha->init_cb_dma);
  3174. ha->init_cb = NULL;
  3175. ha->init_cb_dma = 0;
  3176. fail:
  3177. ql_log(ql_log_fatal, NULL, 0x0030,
  3178. "Memory allocation failure.\n");
  3179. return -ENOMEM;
  3180. }
  3181. /*
  3182. * qla2x00_free_fw_dump
  3183. * Frees fw dump stuff.
  3184. *
  3185. * Input:
  3186. * ha = adapter block pointer
  3187. */
  3188. static void
  3189. qla2x00_free_fw_dump(struct qla_hw_data *ha)
  3190. {
  3191. if (ha->fce)
  3192. dma_free_coherent(&ha->pdev->dev,
  3193. FCE_SIZE, ha->fce, ha->fce_dma);
  3194. if (ha->eft)
  3195. dma_free_coherent(&ha->pdev->dev,
  3196. EFT_SIZE, ha->eft, ha->eft_dma);
  3197. if (ha->fw_dump)
  3198. vfree(ha->fw_dump);
  3199. if (ha->fw_dump_template)
  3200. vfree(ha->fw_dump_template);
  3201. ha->fce = NULL;
  3202. ha->fce_dma = 0;
  3203. ha->eft = NULL;
  3204. ha->eft_dma = 0;
  3205. ha->fw_dumped = 0;
  3206. ha->fw_dump_cap_flags = 0;
  3207. ha->fw_dump_reading = 0;
  3208. ha->fw_dump = NULL;
  3209. ha->fw_dump_len = 0;
  3210. ha->fw_dump_template = NULL;
  3211. ha->fw_dump_template_len = 0;
  3212. }
  3213. /*
  3214. * qla2x00_mem_free
  3215. * Frees all adapter allocated memory.
  3216. *
  3217. * Input:
  3218. * ha = adapter block pointer.
  3219. */
  3220. static void
  3221. qla2x00_mem_free(struct qla_hw_data *ha)
  3222. {
  3223. qla2x00_free_fw_dump(ha);
  3224. if (ha->mctp_dump)
  3225. dma_free_coherent(&ha->pdev->dev, MCTP_DUMP_SIZE, ha->mctp_dump,
  3226. ha->mctp_dump_dma);
  3227. if (ha->srb_mempool)
  3228. mempool_destroy(ha->srb_mempool);
  3229. if (ha->dcbx_tlv)
  3230. dma_free_coherent(&ha->pdev->dev, DCBX_TLV_DATA_SIZE,
  3231. ha->dcbx_tlv, ha->dcbx_tlv_dma);
  3232. if (ha->xgmac_data)
  3233. dma_free_coherent(&ha->pdev->dev, XGMAC_DATA_SIZE,
  3234. ha->xgmac_data, ha->xgmac_data_dma);
  3235. if (ha->sns_cmd)
  3236. dma_free_coherent(&ha->pdev->dev, sizeof(struct sns_cmd_pkt),
  3237. ha->sns_cmd, ha->sns_cmd_dma);
  3238. if (ha->ct_sns)
  3239. dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
  3240. ha->ct_sns, ha->ct_sns_dma);
  3241. if (ha->sfp_data)
  3242. dma_pool_free(ha->s_dma_pool, ha->sfp_data, ha->sfp_data_dma);
  3243. if (ha->ms_iocb)
  3244. dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
  3245. if (ha->ex_init_cb)
  3246. dma_pool_free(ha->s_dma_pool,
  3247. ha->ex_init_cb, ha->ex_init_cb_dma);
  3248. if (ha->async_pd)
  3249. dma_pool_free(ha->s_dma_pool, ha->async_pd, ha->async_pd_dma);
  3250. if (ha->s_dma_pool)
  3251. dma_pool_destroy(ha->s_dma_pool);
  3252. if (ha->gid_list)
  3253. dma_free_coherent(&ha->pdev->dev, qla2x00_gid_list_size(ha),
  3254. ha->gid_list, ha->gid_list_dma);
  3255. if (IS_QLA82XX(ha)) {
  3256. if (!list_empty(&ha->gbl_dsd_list)) {
  3257. struct dsd_dma *dsd_ptr, *tdsd_ptr;
  3258. /* clean up allocated prev pool */
  3259. list_for_each_entry_safe(dsd_ptr,
  3260. tdsd_ptr, &ha->gbl_dsd_list, list) {
  3261. dma_pool_free(ha->dl_dma_pool,
  3262. dsd_ptr->dsd_addr, dsd_ptr->dsd_list_dma);
  3263. list_del(&dsd_ptr->list);
  3264. kfree(dsd_ptr);
  3265. }
  3266. }
  3267. }
  3268. if (ha->dl_dma_pool)
  3269. dma_pool_destroy(ha->dl_dma_pool);
  3270. if (ha->fcp_cmnd_dma_pool)
  3271. dma_pool_destroy(ha->fcp_cmnd_dma_pool);
  3272. if (ha->ctx_mempool)
  3273. mempool_destroy(ha->ctx_mempool);
  3274. qlt_mem_free(ha);
  3275. if (ha->init_cb)
  3276. dma_free_coherent(&ha->pdev->dev, ha->init_cb_size,
  3277. ha->init_cb, ha->init_cb_dma);
  3278. vfree(ha->optrom_buffer);
  3279. kfree(ha->nvram);
  3280. kfree(ha->npiv_info);
  3281. kfree(ha->swl);
  3282. kfree(ha->loop_id_map);
  3283. ha->srb_mempool = NULL;
  3284. ha->ctx_mempool = NULL;
  3285. ha->sns_cmd = NULL;
  3286. ha->sns_cmd_dma = 0;
  3287. ha->ct_sns = NULL;
  3288. ha->ct_sns_dma = 0;
  3289. ha->ms_iocb = NULL;
  3290. ha->ms_iocb_dma = 0;
  3291. ha->init_cb = NULL;
  3292. ha->init_cb_dma = 0;
  3293. ha->ex_init_cb = NULL;
  3294. ha->ex_init_cb_dma = 0;
  3295. ha->async_pd = NULL;
  3296. ha->async_pd_dma = 0;
  3297. ha->s_dma_pool = NULL;
  3298. ha->dl_dma_pool = NULL;
  3299. ha->fcp_cmnd_dma_pool = NULL;
  3300. ha->gid_list = NULL;
  3301. ha->gid_list_dma = 0;
  3302. ha->tgt.atio_ring = NULL;
  3303. ha->tgt.atio_dma = 0;
  3304. ha->tgt.tgt_vp_map = NULL;
  3305. }
  3306. struct scsi_qla_host *qla2x00_create_host(struct scsi_host_template *sht,
  3307. struct qla_hw_data *ha)
  3308. {
  3309. struct Scsi_Host *host;
  3310. struct scsi_qla_host *vha = NULL;
  3311. host = scsi_host_alloc(sht, sizeof(scsi_qla_host_t));
  3312. if (host == NULL) {
  3313. ql_log_pci(ql_log_fatal, ha->pdev, 0x0107,
  3314. "Failed to allocate host from the scsi layer, aborting.\n");
  3315. goto fail;
  3316. }
  3317. /* Clear our data area */
  3318. vha = shost_priv(host);
  3319. memset(vha, 0, sizeof(scsi_qla_host_t));
  3320. vha->host = host;
  3321. vha->host_no = host->host_no;
  3322. vha->hw = ha;
  3323. INIT_LIST_HEAD(&vha->vp_fcports);
  3324. INIT_LIST_HEAD(&vha->work_list);
  3325. INIT_LIST_HEAD(&vha->list);
  3326. INIT_LIST_HEAD(&vha->qla_cmd_list);
  3327. INIT_LIST_HEAD(&vha->qla_sess_op_cmd_list);
  3328. spin_lock_init(&vha->work_lock);
  3329. spin_lock_init(&vha->cmd_list_lock);
  3330. sprintf(vha->host_str, "%s_%ld", QLA2XXX_DRIVER_NAME, vha->host_no);
  3331. ql_dbg(ql_dbg_init, vha, 0x0041,
  3332. "Allocated the host=%p hw=%p vha=%p dev_name=%s",
  3333. vha->host, vha->hw, vha,
  3334. dev_name(&(ha->pdev->dev)));
  3335. return vha;
  3336. fail:
  3337. return vha;
  3338. }
  3339. static struct qla_work_evt *
  3340. qla2x00_alloc_work(struct scsi_qla_host *vha, enum qla_work_type type)
  3341. {
  3342. struct qla_work_evt *e;
  3343. uint8_t bail;
  3344. QLA_VHA_MARK_BUSY(vha, bail);
  3345. if (bail)
  3346. return NULL;
  3347. e = kzalloc(sizeof(struct qla_work_evt), GFP_ATOMIC);
  3348. if (!e) {
  3349. QLA_VHA_MARK_NOT_BUSY(vha);
  3350. return NULL;
  3351. }
  3352. INIT_LIST_HEAD(&e->list);
  3353. e->type = type;
  3354. e->flags = QLA_EVT_FLAG_FREE;
  3355. return e;
  3356. }
  3357. static int
  3358. qla2x00_post_work(struct scsi_qla_host *vha, struct qla_work_evt *e)
  3359. {
  3360. unsigned long flags;
  3361. spin_lock_irqsave(&vha->work_lock, flags);
  3362. list_add_tail(&e->list, &vha->work_list);
  3363. spin_unlock_irqrestore(&vha->work_lock, flags);
  3364. qla2xxx_wake_dpc(vha);
  3365. return QLA_SUCCESS;
  3366. }
  3367. int
  3368. qla2x00_post_aen_work(struct scsi_qla_host *vha, enum fc_host_event_code code,
  3369. u32 data)
  3370. {
  3371. struct qla_work_evt *e;
  3372. e = qla2x00_alloc_work(vha, QLA_EVT_AEN);
  3373. if (!e)
  3374. return QLA_FUNCTION_FAILED;
  3375. e->u.aen.code = code;
  3376. e->u.aen.data = data;
  3377. return qla2x00_post_work(vha, e);
  3378. }
  3379. int
  3380. qla2x00_post_idc_ack_work(struct scsi_qla_host *vha, uint16_t *mb)
  3381. {
  3382. struct qla_work_evt *e;
  3383. e = qla2x00_alloc_work(vha, QLA_EVT_IDC_ACK);
  3384. if (!e)
  3385. return QLA_FUNCTION_FAILED;
  3386. memcpy(e->u.idc_ack.mb, mb, QLA_IDC_ACK_REGS * sizeof(uint16_t));
  3387. return qla2x00_post_work(vha, e);
  3388. }
  3389. #define qla2x00_post_async_work(name, type) \
  3390. int qla2x00_post_async_##name##_work( \
  3391. struct scsi_qla_host *vha, \
  3392. fc_port_t *fcport, uint16_t *data) \
  3393. { \
  3394. struct qla_work_evt *e; \
  3395. \
  3396. e = qla2x00_alloc_work(vha, type); \
  3397. if (!e) \
  3398. return QLA_FUNCTION_FAILED; \
  3399. \
  3400. e->u.logio.fcport = fcport; \
  3401. if (data) { \
  3402. e->u.logio.data[0] = data[0]; \
  3403. e->u.logio.data[1] = data[1]; \
  3404. } \
  3405. return qla2x00_post_work(vha, e); \
  3406. }
  3407. qla2x00_post_async_work(login, QLA_EVT_ASYNC_LOGIN);
  3408. qla2x00_post_async_work(login_done, QLA_EVT_ASYNC_LOGIN_DONE);
  3409. qla2x00_post_async_work(logout, QLA_EVT_ASYNC_LOGOUT);
  3410. qla2x00_post_async_work(logout_done, QLA_EVT_ASYNC_LOGOUT_DONE);
  3411. qla2x00_post_async_work(adisc, QLA_EVT_ASYNC_ADISC);
  3412. qla2x00_post_async_work(adisc_done, QLA_EVT_ASYNC_ADISC_DONE);
  3413. int
  3414. qla2x00_post_uevent_work(struct scsi_qla_host *vha, u32 code)
  3415. {
  3416. struct qla_work_evt *e;
  3417. e = qla2x00_alloc_work(vha, QLA_EVT_UEVENT);
  3418. if (!e)
  3419. return QLA_FUNCTION_FAILED;
  3420. e->u.uevent.code = code;
  3421. return qla2x00_post_work(vha, e);
  3422. }
  3423. static void
  3424. qla2x00_uevent_emit(struct scsi_qla_host *vha, u32 code)
  3425. {
  3426. char event_string[40];
  3427. char *envp[] = { event_string, NULL };
  3428. switch (code) {
  3429. case QLA_UEVENT_CODE_FW_DUMP:
  3430. snprintf(event_string, sizeof(event_string), "FW_DUMP=%ld",
  3431. vha->host_no);
  3432. break;
  3433. default:
  3434. /* do nothing */
  3435. break;
  3436. }
  3437. kobject_uevent_env(&vha->hw->pdev->dev.kobj, KOBJ_CHANGE, envp);
  3438. }
  3439. int
  3440. qlafx00_post_aenfx_work(struct scsi_qla_host *vha, uint32_t evtcode,
  3441. uint32_t *data, int cnt)
  3442. {
  3443. struct qla_work_evt *e;
  3444. e = qla2x00_alloc_work(vha, QLA_EVT_AENFX);
  3445. if (!e)
  3446. return QLA_FUNCTION_FAILED;
  3447. e->u.aenfx.evtcode = evtcode;
  3448. e->u.aenfx.count = cnt;
  3449. memcpy(e->u.aenfx.mbx, data, sizeof(*data) * cnt);
  3450. return qla2x00_post_work(vha, e);
  3451. }
  3452. void
  3453. qla2x00_do_work(struct scsi_qla_host *vha)
  3454. {
  3455. struct qla_work_evt *e, *tmp;
  3456. unsigned long flags;
  3457. LIST_HEAD(work);
  3458. spin_lock_irqsave(&vha->work_lock, flags);
  3459. list_splice_init(&vha->work_list, &work);
  3460. spin_unlock_irqrestore(&vha->work_lock, flags);
  3461. list_for_each_entry_safe(e, tmp, &work, list) {
  3462. list_del_init(&e->list);
  3463. switch (e->type) {
  3464. case QLA_EVT_AEN:
  3465. fc_host_post_event(vha->host, fc_get_event_number(),
  3466. e->u.aen.code, e->u.aen.data);
  3467. break;
  3468. case QLA_EVT_IDC_ACK:
  3469. qla81xx_idc_ack(vha, e->u.idc_ack.mb);
  3470. break;
  3471. case QLA_EVT_ASYNC_LOGIN:
  3472. qla2x00_async_login(vha, e->u.logio.fcport,
  3473. e->u.logio.data);
  3474. break;
  3475. case QLA_EVT_ASYNC_LOGIN_DONE:
  3476. qla2x00_async_login_done(vha, e->u.logio.fcport,
  3477. e->u.logio.data);
  3478. break;
  3479. case QLA_EVT_ASYNC_LOGOUT:
  3480. qla2x00_async_logout(vha, e->u.logio.fcport);
  3481. break;
  3482. case QLA_EVT_ASYNC_LOGOUT_DONE:
  3483. qla2x00_async_logout_done(vha, e->u.logio.fcport,
  3484. e->u.logio.data);
  3485. break;
  3486. case QLA_EVT_ASYNC_ADISC:
  3487. qla2x00_async_adisc(vha, e->u.logio.fcport,
  3488. e->u.logio.data);
  3489. break;
  3490. case QLA_EVT_ASYNC_ADISC_DONE:
  3491. qla2x00_async_adisc_done(vha, e->u.logio.fcport,
  3492. e->u.logio.data);
  3493. break;
  3494. case QLA_EVT_UEVENT:
  3495. qla2x00_uevent_emit(vha, e->u.uevent.code);
  3496. break;
  3497. case QLA_EVT_AENFX:
  3498. qlafx00_process_aen(vha, e);
  3499. break;
  3500. }
  3501. if (e->flags & QLA_EVT_FLAG_FREE)
  3502. kfree(e);
  3503. /* For each work completed decrement vha ref count */
  3504. QLA_VHA_MARK_NOT_BUSY(vha);
  3505. }
  3506. }
  3507. /* Relogins all the fcports of a vport
  3508. * Context: dpc thread
  3509. */
  3510. void qla2x00_relogin(struct scsi_qla_host *vha)
  3511. {
  3512. fc_port_t *fcport;
  3513. int status;
  3514. uint16_t next_loopid = 0;
  3515. struct qla_hw_data *ha = vha->hw;
  3516. uint16_t data[2];
  3517. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  3518. /*
  3519. * If the port is not ONLINE then try to login
  3520. * to it if we haven't run out of retries.
  3521. */
  3522. if (atomic_read(&fcport->state) != FCS_ONLINE &&
  3523. fcport->login_retry && !(fcport->flags & FCF_ASYNC_SENT)) {
  3524. fcport->login_retry--;
  3525. if (fcport->flags & FCF_FABRIC_DEVICE) {
  3526. if (fcport->flags & FCF_FCP2_DEVICE)
  3527. ha->isp_ops->fabric_logout(vha,
  3528. fcport->loop_id,
  3529. fcport->d_id.b.domain,
  3530. fcport->d_id.b.area,
  3531. fcport->d_id.b.al_pa);
  3532. if (fcport->loop_id == FC_NO_LOOP_ID) {
  3533. fcport->loop_id = next_loopid =
  3534. ha->min_external_loopid;
  3535. status = qla2x00_find_new_loop_id(
  3536. vha, fcport);
  3537. if (status != QLA_SUCCESS) {
  3538. /* Ran out of IDs to use */
  3539. break;
  3540. }
  3541. }
  3542. if (IS_ALOGIO_CAPABLE(ha)) {
  3543. fcport->flags |= FCF_ASYNC_SENT;
  3544. data[0] = 0;
  3545. data[1] = QLA_LOGIO_LOGIN_RETRIED;
  3546. status = qla2x00_post_async_login_work(
  3547. vha, fcport, data);
  3548. if (status == QLA_SUCCESS)
  3549. continue;
  3550. /* Attempt a retry. */
  3551. status = 1;
  3552. } else {
  3553. status = qla2x00_fabric_login(vha,
  3554. fcport, &next_loopid);
  3555. if (status == QLA_SUCCESS) {
  3556. int status2;
  3557. uint8_t opts;
  3558. opts = 0;
  3559. if (fcport->flags &
  3560. FCF_FCP2_DEVICE)
  3561. opts |= BIT_1;
  3562. status2 =
  3563. qla2x00_get_port_database(
  3564. vha, fcport, opts);
  3565. if (status2 != QLA_SUCCESS)
  3566. status = 1;
  3567. }
  3568. }
  3569. } else
  3570. status = qla2x00_local_device_login(vha,
  3571. fcport);
  3572. if (status == QLA_SUCCESS) {
  3573. fcport->old_loop_id = fcport->loop_id;
  3574. ql_dbg(ql_dbg_disc, vha, 0x2003,
  3575. "Port login OK: logged in ID 0x%x.\n",
  3576. fcport->loop_id);
  3577. qla2x00_update_fcport(vha, fcport);
  3578. } else if (status == 1) {
  3579. set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
  3580. /* retry the login again */
  3581. ql_dbg(ql_dbg_disc, vha, 0x2007,
  3582. "Retrying %d login again loop_id 0x%x.\n",
  3583. fcport->login_retry, fcport->loop_id);
  3584. } else {
  3585. fcport->login_retry = 0;
  3586. }
  3587. if (fcport->login_retry == 0 && status != QLA_SUCCESS)
  3588. qla2x00_clear_loop_id(fcport);
  3589. }
  3590. if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
  3591. break;
  3592. }
  3593. }
  3594. /* Schedule work on any of the dpc-workqueues */
  3595. void
  3596. qla83xx_schedule_work(scsi_qla_host_t *base_vha, int work_code)
  3597. {
  3598. struct qla_hw_data *ha = base_vha->hw;
  3599. switch (work_code) {
  3600. case MBA_IDC_AEN: /* 0x8200 */
  3601. if (ha->dpc_lp_wq)
  3602. queue_work(ha->dpc_lp_wq, &ha->idc_aen);
  3603. break;
  3604. case QLA83XX_NIC_CORE_RESET: /* 0x1 */
  3605. if (!ha->flags.nic_core_reset_hdlr_active) {
  3606. if (ha->dpc_hp_wq)
  3607. queue_work(ha->dpc_hp_wq, &ha->nic_core_reset);
  3608. } else
  3609. ql_dbg(ql_dbg_p3p, base_vha, 0xb05e,
  3610. "NIC Core reset is already active. Skip "
  3611. "scheduling it again.\n");
  3612. break;
  3613. case QLA83XX_IDC_STATE_HANDLER: /* 0x2 */
  3614. if (ha->dpc_hp_wq)
  3615. queue_work(ha->dpc_hp_wq, &ha->idc_state_handler);
  3616. break;
  3617. case QLA83XX_NIC_CORE_UNRECOVERABLE: /* 0x3 */
  3618. if (ha->dpc_hp_wq)
  3619. queue_work(ha->dpc_hp_wq, &ha->nic_core_unrecoverable);
  3620. break;
  3621. default:
  3622. ql_log(ql_log_warn, base_vha, 0xb05f,
  3623. "Unknown work-code=0x%x.\n", work_code);
  3624. }
  3625. return;
  3626. }
  3627. /* Work: Perform NIC Core Unrecoverable state handling */
  3628. void
  3629. qla83xx_nic_core_unrecoverable_work(struct work_struct *work)
  3630. {
  3631. struct qla_hw_data *ha =
  3632. container_of(work, struct qla_hw_data, nic_core_unrecoverable);
  3633. scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
  3634. uint32_t dev_state = 0;
  3635. qla83xx_idc_lock(base_vha, 0);
  3636. qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
  3637. qla83xx_reset_ownership(base_vha);
  3638. if (ha->flags.nic_core_reset_owner) {
  3639. ha->flags.nic_core_reset_owner = 0;
  3640. qla83xx_wr_reg(base_vha, QLA83XX_IDC_DEV_STATE,
  3641. QLA8XXX_DEV_FAILED);
  3642. ql_log(ql_log_info, base_vha, 0xb060, "HW State: FAILED.\n");
  3643. qla83xx_schedule_work(base_vha, QLA83XX_IDC_STATE_HANDLER);
  3644. }
  3645. qla83xx_idc_unlock(base_vha, 0);
  3646. }
  3647. /* Work: Execute IDC state handler */
  3648. void
  3649. qla83xx_idc_state_handler_work(struct work_struct *work)
  3650. {
  3651. struct qla_hw_data *ha =
  3652. container_of(work, struct qla_hw_data, idc_state_handler);
  3653. scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
  3654. uint32_t dev_state = 0;
  3655. qla83xx_idc_lock(base_vha, 0);
  3656. qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
  3657. if (dev_state == QLA8XXX_DEV_FAILED ||
  3658. dev_state == QLA8XXX_DEV_NEED_QUIESCENT)
  3659. qla83xx_idc_state_handler(base_vha);
  3660. qla83xx_idc_unlock(base_vha, 0);
  3661. }
  3662. static int
  3663. qla83xx_check_nic_core_fw_alive(scsi_qla_host_t *base_vha)
  3664. {
  3665. int rval = QLA_SUCCESS;
  3666. unsigned long heart_beat_wait = jiffies + (1 * HZ);
  3667. uint32_t heart_beat_counter1, heart_beat_counter2;
  3668. do {
  3669. if (time_after(jiffies, heart_beat_wait)) {
  3670. ql_dbg(ql_dbg_p3p, base_vha, 0xb07c,
  3671. "Nic Core f/w is not alive.\n");
  3672. rval = QLA_FUNCTION_FAILED;
  3673. break;
  3674. }
  3675. qla83xx_idc_lock(base_vha, 0);
  3676. qla83xx_rd_reg(base_vha, QLA83XX_FW_HEARTBEAT,
  3677. &heart_beat_counter1);
  3678. qla83xx_idc_unlock(base_vha, 0);
  3679. msleep(100);
  3680. qla83xx_idc_lock(base_vha, 0);
  3681. qla83xx_rd_reg(base_vha, QLA83XX_FW_HEARTBEAT,
  3682. &heart_beat_counter2);
  3683. qla83xx_idc_unlock(base_vha, 0);
  3684. } while (heart_beat_counter1 == heart_beat_counter2);
  3685. return rval;
  3686. }
  3687. /* Work: Perform NIC Core Reset handling */
  3688. void
  3689. qla83xx_nic_core_reset_work(struct work_struct *work)
  3690. {
  3691. struct qla_hw_data *ha =
  3692. container_of(work, struct qla_hw_data, nic_core_reset);
  3693. scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
  3694. uint32_t dev_state = 0;
  3695. if (IS_QLA2031(ha)) {
  3696. if (qla2xxx_mctp_dump(base_vha) != QLA_SUCCESS)
  3697. ql_log(ql_log_warn, base_vha, 0xb081,
  3698. "Failed to dump mctp\n");
  3699. return;
  3700. }
  3701. if (!ha->flags.nic_core_reset_hdlr_active) {
  3702. if (qla83xx_check_nic_core_fw_alive(base_vha) == QLA_SUCCESS) {
  3703. qla83xx_idc_lock(base_vha, 0);
  3704. qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE,
  3705. &dev_state);
  3706. qla83xx_idc_unlock(base_vha, 0);
  3707. if (dev_state != QLA8XXX_DEV_NEED_RESET) {
  3708. ql_dbg(ql_dbg_p3p, base_vha, 0xb07a,
  3709. "Nic Core f/w is alive.\n");
  3710. return;
  3711. }
  3712. }
  3713. ha->flags.nic_core_reset_hdlr_active = 1;
  3714. if (qla83xx_nic_core_reset(base_vha)) {
  3715. /* NIC Core reset failed. */
  3716. ql_dbg(ql_dbg_p3p, base_vha, 0xb061,
  3717. "NIC Core reset failed.\n");
  3718. }
  3719. ha->flags.nic_core_reset_hdlr_active = 0;
  3720. }
  3721. }
  3722. /* Work: Handle 8200 IDC aens */
  3723. void
  3724. qla83xx_service_idc_aen(struct work_struct *work)
  3725. {
  3726. struct qla_hw_data *ha =
  3727. container_of(work, struct qla_hw_data, idc_aen);
  3728. scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
  3729. uint32_t dev_state, idc_control;
  3730. qla83xx_idc_lock(base_vha, 0);
  3731. qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
  3732. qla83xx_rd_reg(base_vha, QLA83XX_IDC_CONTROL, &idc_control);
  3733. qla83xx_idc_unlock(base_vha, 0);
  3734. if (dev_state == QLA8XXX_DEV_NEED_RESET) {
  3735. if (idc_control & QLA83XX_IDC_GRACEFUL_RESET) {
  3736. ql_dbg(ql_dbg_p3p, base_vha, 0xb062,
  3737. "Application requested NIC Core Reset.\n");
  3738. qla83xx_schedule_work(base_vha, QLA83XX_NIC_CORE_RESET);
  3739. } else if (qla83xx_check_nic_core_fw_alive(base_vha) ==
  3740. QLA_SUCCESS) {
  3741. ql_dbg(ql_dbg_p3p, base_vha, 0xb07b,
  3742. "Other protocol driver requested NIC Core Reset.\n");
  3743. qla83xx_schedule_work(base_vha, QLA83XX_NIC_CORE_RESET);
  3744. }
  3745. } else if (dev_state == QLA8XXX_DEV_FAILED ||
  3746. dev_state == QLA8XXX_DEV_NEED_QUIESCENT) {
  3747. qla83xx_schedule_work(base_vha, QLA83XX_IDC_STATE_HANDLER);
  3748. }
  3749. }
  3750. static void
  3751. qla83xx_wait_logic(void)
  3752. {
  3753. int i;
  3754. /* Yield CPU */
  3755. if (!in_interrupt()) {
  3756. /*
  3757. * Wait about 200ms before retrying again.
  3758. * This controls the number of retries for single
  3759. * lock operation.
  3760. */
  3761. msleep(100);
  3762. schedule();
  3763. } else {
  3764. for (i = 0; i < 20; i++)
  3765. cpu_relax(); /* This a nop instr on i386 */
  3766. }
  3767. }
  3768. static int
  3769. qla83xx_force_lock_recovery(scsi_qla_host_t *base_vha)
  3770. {
  3771. int rval;
  3772. uint32_t data;
  3773. uint32_t idc_lck_rcvry_stage_mask = 0x3;
  3774. uint32_t idc_lck_rcvry_owner_mask = 0x3c;
  3775. struct qla_hw_data *ha = base_vha->hw;
  3776. ql_dbg(ql_dbg_p3p, base_vha, 0xb086,
  3777. "Trying force recovery of the IDC lock.\n");
  3778. rval = qla83xx_rd_reg(base_vha, QLA83XX_IDC_LOCK_RECOVERY, &data);
  3779. if (rval)
  3780. return rval;
  3781. if ((data & idc_lck_rcvry_stage_mask) > 0) {
  3782. return QLA_SUCCESS;
  3783. } else {
  3784. data = (IDC_LOCK_RECOVERY_STAGE1) | (ha->portnum << 2);
  3785. rval = qla83xx_wr_reg(base_vha, QLA83XX_IDC_LOCK_RECOVERY,
  3786. data);
  3787. if (rval)
  3788. return rval;
  3789. msleep(200);
  3790. rval = qla83xx_rd_reg(base_vha, QLA83XX_IDC_LOCK_RECOVERY,
  3791. &data);
  3792. if (rval)
  3793. return rval;
  3794. if (((data & idc_lck_rcvry_owner_mask) >> 2) == ha->portnum) {
  3795. data &= (IDC_LOCK_RECOVERY_STAGE2 |
  3796. ~(idc_lck_rcvry_stage_mask));
  3797. rval = qla83xx_wr_reg(base_vha,
  3798. QLA83XX_IDC_LOCK_RECOVERY, data);
  3799. if (rval)
  3800. return rval;
  3801. /* Forcefully perform IDC UnLock */
  3802. rval = qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_UNLOCK,
  3803. &data);
  3804. if (rval)
  3805. return rval;
  3806. /* Clear lock-id by setting 0xff */
  3807. rval = qla83xx_wr_reg(base_vha, QLA83XX_DRIVER_LOCKID,
  3808. 0xff);
  3809. if (rval)
  3810. return rval;
  3811. /* Clear lock-recovery by setting 0x0 */
  3812. rval = qla83xx_wr_reg(base_vha,
  3813. QLA83XX_IDC_LOCK_RECOVERY, 0x0);
  3814. if (rval)
  3815. return rval;
  3816. } else
  3817. return QLA_SUCCESS;
  3818. }
  3819. return rval;
  3820. }
  3821. static int
  3822. qla83xx_idc_lock_recovery(scsi_qla_host_t *base_vha)
  3823. {
  3824. int rval = QLA_SUCCESS;
  3825. uint32_t o_drv_lockid, n_drv_lockid;
  3826. unsigned long lock_recovery_timeout;
  3827. lock_recovery_timeout = jiffies + QLA83XX_MAX_LOCK_RECOVERY_WAIT;
  3828. retry_lockid:
  3829. rval = qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID, &o_drv_lockid);
  3830. if (rval)
  3831. goto exit;
  3832. /* MAX wait time before forcing IDC Lock recovery = 2 secs */
  3833. if (time_after_eq(jiffies, lock_recovery_timeout)) {
  3834. if (qla83xx_force_lock_recovery(base_vha) == QLA_SUCCESS)
  3835. return QLA_SUCCESS;
  3836. else
  3837. return QLA_FUNCTION_FAILED;
  3838. }
  3839. rval = qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID, &n_drv_lockid);
  3840. if (rval)
  3841. goto exit;
  3842. if (o_drv_lockid == n_drv_lockid) {
  3843. qla83xx_wait_logic();
  3844. goto retry_lockid;
  3845. } else
  3846. return QLA_SUCCESS;
  3847. exit:
  3848. return rval;
  3849. }
  3850. void
  3851. qla83xx_idc_lock(scsi_qla_host_t *base_vha, uint16_t requester_id)
  3852. {
  3853. uint16_t options = (requester_id << 15) | BIT_6;
  3854. uint32_t data;
  3855. uint32_t lock_owner;
  3856. struct qla_hw_data *ha = base_vha->hw;
  3857. /* IDC-lock implementation using driver-lock/lock-id remote registers */
  3858. retry_lock:
  3859. if (qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCK, &data)
  3860. == QLA_SUCCESS) {
  3861. if (data) {
  3862. /* Setting lock-id to our function-number */
  3863. qla83xx_wr_reg(base_vha, QLA83XX_DRIVER_LOCKID,
  3864. ha->portnum);
  3865. } else {
  3866. qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID,
  3867. &lock_owner);
  3868. ql_dbg(ql_dbg_p3p, base_vha, 0xb063,
  3869. "Failed to acquire IDC lock, acquired by %d, "
  3870. "retrying...\n", lock_owner);
  3871. /* Retry/Perform IDC-Lock recovery */
  3872. if (qla83xx_idc_lock_recovery(base_vha)
  3873. == QLA_SUCCESS) {
  3874. qla83xx_wait_logic();
  3875. goto retry_lock;
  3876. } else
  3877. ql_log(ql_log_warn, base_vha, 0xb075,
  3878. "IDC Lock recovery FAILED.\n");
  3879. }
  3880. }
  3881. return;
  3882. /* XXX: IDC-lock implementation using access-control mbx */
  3883. retry_lock2:
  3884. if (qla83xx_access_control(base_vha, options, 0, 0, NULL)) {
  3885. ql_dbg(ql_dbg_p3p, base_vha, 0xb072,
  3886. "Failed to acquire IDC lock. retrying...\n");
  3887. /* Retry/Perform IDC-Lock recovery */
  3888. if (qla83xx_idc_lock_recovery(base_vha) == QLA_SUCCESS) {
  3889. qla83xx_wait_logic();
  3890. goto retry_lock2;
  3891. } else
  3892. ql_log(ql_log_warn, base_vha, 0xb076,
  3893. "IDC Lock recovery FAILED.\n");
  3894. }
  3895. return;
  3896. }
  3897. void
  3898. qla83xx_idc_unlock(scsi_qla_host_t *base_vha, uint16_t requester_id)
  3899. {
  3900. #if 0
  3901. uint16_t options = (requester_id << 15) | BIT_7;
  3902. #endif
  3903. uint16_t retry;
  3904. uint32_t data;
  3905. struct qla_hw_data *ha = base_vha->hw;
  3906. /* IDC-unlock implementation using driver-unlock/lock-id
  3907. * remote registers
  3908. */
  3909. retry = 0;
  3910. retry_unlock:
  3911. if (qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID, &data)
  3912. == QLA_SUCCESS) {
  3913. if (data == ha->portnum) {
  3914. qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_UNLOCK, &data);
  3915. /* Clearing lock-id by setting 0xff */
  3916. qla83xx_wr_reg(base_vha, QLA83XX_DRIVER_LOCKID, 0xff);
  3917. } else if (retry < 10) {
  3918. /* SV: XXX: IDC unlock retrying needed here? */
  3919. /* Retry for IDC-unlock */
  3920. qla83xx_wait_logic();
  3921. retry++;
  3922. ql_dbg(ql_dbg_p3p, base_vha, 0xb064,
  3923. "Failed to release IDC lock, retyring=%d\n", retry);
  3924. goto retry_unlock;
  3925. }
  3926. } else if (retry < 10) {
  3927. /* Retry for IDC-unlock */
  3928. qla83xx_wait_logic();
  3929. retry++;
  3930. ql_dbg(ql_dbg_p3p, base_vha, 0xb065,
  3931. "Failed to read drv-lockid, retyring=%d\n", retry);
  3932. goto retry_unlock;
  3933. }
  3934. return;
  3935. #if 0
  3936. /* XXX: IDC-unlock implementation using access-control mbx */
  3937. retry = 0;
  3938. retry_unlock2:
  3939. if (qla83xx_access_control(base_vha, options, 0, 0, NULL)) {
  3940. if (retry < 10) {
  3941. /* Retry for IDC-unlock */
  3942. qla83xx_wait_logic();
  3943. retry++;
  3944. ql_dbg(ql_dbg_p3p, base_vha, 0xb066,
  3945. "Failed to release IDC lock, retyring=%d\n", retry);
  3946. goto retry_unlock2;
  3947. }
  3948. }
  3949. return;
  3950. #endif
  3951. }
  3952. int
  3953. __qla83xx_set_drv_presence(scsi_qla_host_t *vha)
  3954. {
  3955. int rval = QLA_SUCCESS;
  3956. struct qla_hw_data *ha = vha->hw;
  3957. uint32_t drv_presence;
  3958. rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
  3959. if (rval == QLA_SUCCESS) {
  3960. drv_presence |= (1 << ha->portnum);
  3961. rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRV_PRESENCE,
  3962. drv_presence);
  3963. }
  3964. return rval;
  3965. }
  3966. int
  3967. qla83xx_set_drv_presence(scsi_qla_host_t *vha)
  3968. {
  3969. int rval = QLA_SUCCESS;
  3970. qla83xx_idc_lock(vha, 0);
  3971. rval = __qla83xx_set_drv_presence(vha);
  3972. qla83xx_idc_unlock(vha, 0);
  3973. return rval;
  3974. }
  3975. int
  3976. __qla83xx_clear_drv_presence(scsi_qla_host_t *vha)
  3977. {
  3978. int rval = QLA_SUCCESS;
  3979. struct qla_hw_data *ha = vha->hw;
  3980. uint32_t drv_presence;
  3981. rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
  3982. if (rval == QLA_SUCCESS) {
  3983. drv_presence &= ~(1 << ha->portnum);
  3984. rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRV_PRESENCE,
  3985. drv_presence);
  3986. }
  3987. return rval;
  3988. }
  3989. int
  3990. qla83xx_clear_drv_presence(scsi_qla_host_t *vha)
  3991. {
  3992. int rval = QLA_SUCCESS;
  3993. qla83xx_idc_lock(vha, 0);
  3994. rval = __qla83xx_clear_drv_presence(vha);
  3995. qla83xx_idc_unlock(vha, 0);
  3996. return rval;
  3997. }
  3998. static void
  3999. qla83xx_need_reset_handler(scsi_qla_host_t *vha)
  4000. {
  4001. struct qla_hw_data *ha = vha->hw;
  4002. uint32_t drv_ack, drv_presence;
  4003. unsigned long ack_timeout;
  4004. /* Wait for IDC ACK from all functions (DRV-ACK == DRV-PRESENCE) */
  4005. ack_timeout = jiffies + (ha->fcoe_reset_timeout * HZ);
  4006. while (1) {
  4007. qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack);
  4008. qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
  4009. if ((drv_ack & drv_presence) == drv_presence)
  4010. break;
  4011. if (time_after_eq(jiffies, ack_timeout)) {
  4012. ql_log(ql_log_warn, vha, 0xb067,
  4013. "RESET ACK TIMEOUT! drv_presence=0x%x "
  4014. "drv_ack=0x%x\n", drv_presence, drv_ack);
  4015. /*
  4016. * The function(s) which did not ack in time are forced
  4017. * to withdraw any further participation in the IDC
  4018. * reset.
  4019. */
  4020. if (drv_ack != drv_presence)
  4021. qla83xx_wr_reg(vha, QLA83XX_IDC_DRV_PRESENCE,
  4022. drv_ack);
  4023. break;
  4024. }
  4025. qla83xx_idc_unlock(vha, 0);
  4026. msleep(1000);
  4027. qla83xx_idc_lock(vha, 0);
  4028. }
  4029. qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_COLD);
  4030. ql_log(ql_log_info, vha, 0xb068, "HW State: COLD/RE-INIT.\n");
  4031. }
  4032. static int
  4033. qla83xx_device_bootstrap(scsi_qla_host_t *vha)
  4034. {
  4035. int rval = QLA_SUCCESS;
  4036. uint32_t idc_control;
  4037. qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_INITIALIZING);
  4038. ql_log(ql_log_info, vha, 0xb069, "HW State: INITIALIZING.\n");
  4039. /* Clearing IDC-Control Graceful-Reset Bit before resetting f/w */
  4040. __qla83xx_get_idc_control(vha, &idc_control);
  4041. idc_control &= ~QLA83XX_IDC_GRACEFUL_RESET;
  4042. __qla83xx_set_idc_control(vha, 0);
  4043. qla83xx_idc_unlock(vha, 0);
  4044. rval = qla83xx_restart_nic_firmware(vha);
  4045. qla83xx_idc_lock(vha, 0);
  4046. if (rval != QLA_SUCCESS) {
  4047. ql_log(ql_log_fatal, vha, 0xb06a,
  4048. "Failed to restart NIC f/w.\n");
  4049. qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_FAILED);
  4050. ql_log(ql_log_info, vha, 0xb06b, "HW State: FAILED.\n");
  4051. } else {
  4052. ql_dbg(ql_dbg_p3p, vha, 0xb06c,
  4053. "Success in restarting nic f/w.\n");
  4054. qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_READY);
  4055. ql_log(ql_log_info, vha, 0xb06d, "HW State: READY.\n");
  4056. }
  4057. return rval;
  4058. }
  4059. /* Assumes idc_lock always held on entry */
  4060. int
  4061. qla83xx_idc_state_handler(scsi_qla_host_t *base_vha)
  4062. {
  4063. struct qla_hw_data *ha = base_vha->hw;
  4064. int rval = QLA_SUCCESS;
  4065. unsigned long dev_init_timeout;
  4066. uint32_t dev_state;
  4067. /* Wait for MAX-INIT-TIMEOUT for the device to go ready */
  4068. dev_init_timeout = jiffies + (ha->fcoe_dev_init_timeout * HZ);
  4069. while (1) {
  4070. if (time_after_eq(jiffies, dev_init_timeout)) {
  4071. ql_log(ql_log_warn, base_vha, 0xb06e,
  4072. "Initialization TIMEOUT!\n");
  4073. /* Init timeout. Disable further NIC Core
  4074. * communication.
  4075. */
  4076. qla83xx_wr_reg(base_vha, QLA83XX_IDC_DEV_STATE,
  4077. QLA8XXX_DEV_FAILED);
  4078. ql_log(ql_log_info, base_vha, 0xb06f,
  4079. "HW State: FAILED.\n");
  4080. }
  4081. qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
  4082. switch (dev_state) {
  4083. case QLA8XXX_DEV_READY:
  4084. if (ha->flags.nic_core_reset_owner)
  4085. qla83xx_idc_audit(base_vha,
  4086. IDC_AUDIT_COMPLETION);
  4087. ha->flags.nic_core_reset_owner = 0;
  4088. ql_dbg(ql_dbg_p3p, base_vha, 0xb070,
  4089. "Reset_owner reset by 0x%x.\n",
  4090. ha->portnum);
  4091. goto exit;
  4092. case QLA8XXX_DEV_COLD:
  4093. if (ha->flags.nic_core_reset_owner)
  4094. rval = qla83xx_device_bootstrap(base_vha);
  4095. else {
  4096. /* Wait for AEN to change device-state */
  4097. qla83xx_idc_unlock(base_vha, 0);
  4098. msleep(1000);
  4099. qla83xx_idc_lock(base_vha, 0);
  4100. }
  4101. break;
  4102. case QLA8XXX_DEV_INITIALIZING:
  4103. /* Wait for AEN to change device-state */
  4104. qla83xx_idc_unlock(base_vha, 0);
  4105. msleep(1000);
  4106. qla83xx_idc_lock(base_vha, 0);
  4107. break;
  4108. case QLA8XXX_DEV_NEED_RESET:
  4109. if (!ql2xdontresethba && ha->flags.nic_core_reset_owner)
  4110. qla83xx_need_reset_handler(base_vha);
  4111. else {
  4112. /* Wait for AEN to change device-state */
  4113. qla83xx_idc_unlock(base_vha, 0);
  4114. msleep(1000);
  4115. qla83xx_idc_lock(base_vha, 0);
  4116. }
  4117. /* reset timeout value after need reset handler */
  4118. dev_init_timeout = jiffies +
  4119. (ha->fcoe_dev_init_timeout * HZ);
  4120. break;
  4121. case QLA8XXX_DEV_NEED_QUIESCENT:
  4122. /* XXX: DEBUG for now */
  4123. qla83xx_idc_unlock(base_vha, 0);
  4124. msleep(1000);
  4125. qla83xx_idc_lock(base_vha, 0);
  4126. break;
  4127. case QLA8XXX_DEV_QUIESCENT:
  4128. /* XXX: DEBUG for now */
  4129. if (ha->flags.quiesce_owner)
  4130. goto exit;
  4131. qla83xx_idc_unlock(base_vha, 0);
  4132. msleep(1000);
  4133. qla83xx_idc_lock(base_vha, 0);
  4134. dev_init_timeout = jiffies +
  4135. (ha->fcoe_dev_init_timeout * HZ);
  4136. break;
  4137. case QLA8XXX_DEV_FAILED:
  4138. if (ha->flags.nic_core_reset_owner)
  4139. qla83xx_idc_audit(base_vha,
  4140. IDC_AUDIT_COMPLETION);
  4141. ha->flags.nic_core_reset_owner = 0;
  4142. __qla83xx_clear_drv_presence(base_vha);
  4143. qla83xx_idc_unlock(base_vha, 0);
  4144. qla8xxx_dev_failed_handler(base_vha);
  4145. rval = QLA_FUNCTION_FAILED;
  4146. qla83xx_idc_lock(base_vha, 0);
  4147. goto exit;
  4148. case QLA8XXX_BAD_VALUE:
  4149. qla83xx_idc_unlock(base_vha, 0);
  4150. msleep(1000);
  4151. qla83xx_idc_lock(base_vha, 0);
  4152. break;
  4153. default:
  4154. ql_log(ql_log_warn, base_vha, 0xb071,
  4155. "Unknown Device State: %x.\n", dev_state);
  4156. qla83xx_idc_unlock(base_vha, 0);
  4157. qla8xxx_dev_failed_handler(base_vha);
  4158. rval = QLA_FUNCTION_FAILED;
  4159. qla83xx_idc_lock(base_vha, 0);
  4160. goto exit;
  4161. }
  4162. }
  4163. exit:
  4164. return rval;
  4165. }
  4166. void
  4167. qla2x00_disable_board_on_pci_error(struct work_struct *work)
  4168. {
  4169. struct qla_hw_data *ha = container_of(work, struct qla_hw_data,
  4170. board_disable);
  4171. struct pci_dev *pdev = ha->pdev;
  4172. scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
  4173. ql_log(ql_log_warn, base_vha, 0x015b,
  4174. "Disabling adapter.\n");
  4175. set_bit(UNLOADING, &base_vha->dpc_flags);
  4176. qla2x00_delete_all_vps(ha, base_vha);
  4177. qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16);
  4178. qla2x00_dfs_remove(base_vha);
  4179. qla84xx_put_chip(base_vha);
  4180. if (base_vha->timer_active)
  4181. qla2x00_stop_timer(base_vha);
  4182. base_vha->flags.online = 0;
  4183. qla2x00_destroy_deferred_work(ha);
  4184. /*
  4185. * Do not try to stop beacon blink as it will issue a mailbox
  4186. * command.
  4187. */
  4188. qla2x00_free_sysfs_attr(base_vha, false);
  4189. fc_remove_host(base_vha->host);
  4190. scsi_remove_host(base_vha->host);
  4191. base_vha->flags.init_done = 0;
  4192. qla25xx_delete_queues(base_vha);
  4193. qla2x00_free_irqs(base_vha);
  4194. qla2x00_free_fcports(base_vha);
  4195. qla2x00_mem_free(ha);
  4196. qla82xx_md_free(base_vha);
  4197. qla2x00_free_queues(ha);
  4198. qla2x00_unmap_iobases(ha);
  4199. pci_release_selected_regions(ha->pdev, ha->bars);
  4200. pci_disable_pcie_error_reporting(pdev);
  4201. pci_disable_device(pdev);
  4202. /*
  4203. * Let qla2x00_remove_one cleanup qla_hw_data on device removal.
  4204. */
  4205. }
  4206. /**************************************************************************
  4207. * qla2x00_do_dpc
  4208. * This kernel thread is a task that is schedule by the interrupt handler
  4209. * to perform the background processing for interrupts.
  4210. *
  4211. * Notes:
  4212. * This task always run in the context of a kernel thread. It
  4213. * is kick-off by the driver's detect code and starts up
  4214. * up one per adapter. It immediately goes to sleep and waits for
  4215. * some fibre event. When either the interrupt handler or
  4216. * the timer routine detects a event it will one of the task
  4217. * bits then wake us up.
  4218. **************************************************************************/
  4219. static int
  4220. qla2x00_do_dpc(void *data)
  4221. {
  4222. scsi_qla_host_t *base_vha;
  4223. struct qla_hw_data *ha;
  4224. ha = (struct qla_hw_data *)data;
  4225. base_vha = pci_get_drvdata(ha->pdev);
  4226. set_user_nice(current, MIN_NICE);
  4227. set_current_state(TASK_INTERRUPTIBLE);
  4228. while (!kthread_should_stop()) {
  4229. ql_dbg(ql_dbg_dpc, base_vha, 0x4000,
  4230. "DPC handler sleeping.\n");
  4231. schedule();
  4232. if (!base_vha->flags.init_done || ha->flags.mbox_busy)
  4233. goto end_loop;
  4234. if (ha->flags.eeh_busy) {
  4235. ql_dbg(ql_dbg_dpc, base_vha, 0x4003,
  4236. "eeh_busy=%d.\n", ha->flags.eeh_busy);
  4237. goto end_loop;
  4238. }
  4239. ha->dpc_active = 1;
  4240. ql_dbg(ql_dbg_dpc + ql_dbg_verbose, base_vha, 0x4001,
  4241. "DPC handler waking up, dpc_flags=0x%lx.\n",
  4242. base_vha->dpc_flags);
  4243. qla2x00_do_work(base_vha);
  4244. if (IS_P3P_TYPE(ha)) {
  4245. if (IS_QLA8044(ha)) {
  4246. if (test_and_clear_bit(ISP_UNRECOVERABLE,
  4247. &base_vha->dpc_flags)) {
  4248. qla8044_idc_lock(ha);
  4249. qla8044_wr_direct(base_vha,
  4250. QLA8044_CRB_DEV_STATE_INDEX,
  4251. QLA8XXX_DEV_FAILED);
  4252. qla8044_idc_unlock(ha);
  4253. ql_log(ql_log_info, base_vha, 0x4004,
  4254. "HW State: FAILED.\n");
  4255. qla8044_device_state_handler(base_vha);
  4256. continue;
  4257. }
  4258. } else {
  4259. if (test_and_clear_bit(ISP_UNRECOVERABLE,
  4260. &base_vha->dpc_flags)) {
  4261. qla82xx_idc_lock(ha);
  4262. qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
  4263. QLA8XXX_DEV_FAILED);
  4264. qla82xx_idc_unlock(ha);
  4265. ql_log(ql_log_info, base_vha, 0x0151,
  4266. "HW State: FAILED.\n");
  4267. qla82xx_device_state_handler(base_vha);
  4268. continue;
  4269. }
  4270. }
  4271. if (test_and_clear_bit(FCOE_CTX_RESET_NEEDED,
  4272. &base_vha->dpc_flags)) {
  4273. ql_dbg(ql_dbg_dpc, base_vha, 0x4005,
  4274. "FCoE context reset scheduled.\n");
  4275. if (!(test_and_set_bit(ABORT_ISP_ACTIVE,
  4276. &base_vha->dpc_flags))) {
  4277. if (qla82xx_fcoe_ctx_reset(base_vha)) {
  4278. /* FCoE-ctx reset failed.
  4279. * Escalate to chip-reset
  4280. */
  4281. set_bit(ISP_ABORT_NEEDED,
  4282. &base_vha->dpc_flags);
  4283. }
  4284. clear_bit(ABORT_ISP_ACTIVE,
  4285. &base_vha->dpc_flags);
  4286. }
  4287. ql_dbg(ql_dbg_dpc, base_vha, 0x4006,
  4288. "FCoE context reset end.\n");
  4289. }
  4290. } else if (IS_QLAFX00(ha)) {
  4291. if (test_and_clear_bit(ISP_UNRECOVERABLE,
  4292. &base_vha->dpc_flags)) {
  4293. ql_dbg(ql_dbg_dpc, base_vha, 0x4020,
  4294. "Firmware Reset Recovery\n");
  4295. if (qlafx00_reset_initialize(base_vha)) {
  4296. /* Failed. Abort isp later. */
  4297. if (!test_bit(UNLOADING,
  4298. &base_vha->dpc_flags)) {
  4299. set_bit(ISP_UNRECOVERABLE,
  4300. &base_vha->dpc_flags);
  4301. ql_dbg(ql_dbg_dpc, base_vha,
  4302. 0x4021,
  4303. "Reset Recovery Failed\n");
  4304. }
  4305. }
  4306. }
  4307. if (test_and_clear_bit(FX00_TARGET_SCAN,
  4308. &base_vha->dpc_flags)) {
  4309. ql_dbg(ql_dbg_dpc, base_vha, 0x4022,
  4310. "ISPFx00 Target Scan scheduled\n");
  4311. if (qlafx00_rescan_isp(base_vha)) {
  4312. if (!test_bit(UNLOADING,
  4313. &base_vha->dpc_flags))
  4314. set_bit(ISP_UNRECOVERABLE,
  4315. &base_vha->dpc_flags);
  4316. ql_dbg(ql_dbg_dpc, base_vha, 0x401e,
  4317. "ISPFx00 Target Scan Failed\n");
  4318. }
  4319. ql_dbg(ql_dbg_dpc, base_vha, 0x401f,
  4320. "ISPFx00 Target Scan End\n");
  4321. }
  4322. if (test_and_clear_bit(FX00_HOST_INFO_RESEND,
  4323. &base_vha->dpc_flags)) {
  4324. ql_dbg(ql_dbg_dpc, base_vha, 0x4023,
  4325. "ISPFx00 Host Info resend scheduled\n");
  4326. qlafx00_fx_disc(base_vha,
  4327. &base_vha->hw->mr.fcport,
  4328. FXDISC_REG_HOST_INFO);
  4329. }
  4330. }
  4331. if (test_and_clear_bit
  4332. (ISP_ABORT_NEEDED, &base_vha->dpc_flags) &&
  4333. !test_bit(UNLOADING, &base_vha->dpc_flags)) {
  4334. ql_dbg(ql_dbg_dpc, base_vha, 0x4007,
  4335. "ISP abort scheduled.\n");
  4336. if (!(test_and_set_bit(ABORT_ISP_ACTIVE,
  4337. &base_vha->dpc_flags))) {
  4338. if (ha->isp_ops->abort_isp(base_vha)) {
  4339. /* failed. retry later */
  4340. set_bit(ISP_ABORT_NEEDED,
  4341. &base_vha->dpc_flags);
  4342. }
  4343. clear_bit(ABORT_ISP_ACTIVE,
  4344. &base_vha->dpc_flags);
  4345. }
  4346. ql_dbg(ql_dbg_dpc, base_vha, 0x4008,
  4347. "ISP abort end.\n");
  4348. }
  4349. if (test_and_clear_bit(FCPORT_UPDATE_NEEDED,
  4350. &base_vha->dpc_flags)) {
  4351. qla2x00_update_fcports(base_vha);
  4352. }
  4353. if (test_bit(SCR_PENDING, &base_vha->dpc_flags)) {
  4354. int ret;
  4355. ret = qla2x00_send_change_request(base_vha, 0x3, 0);
  4356. if (ret != QLA_SUCCESS)
  4357. ql_log(ql_log_warn, base_vha, 0x121,
  4358. "Failed to enable receiving of RSCN "
  4359. "requests: 0x%x.\n", ret);
  4360. clear_bit(SCR_PENDING, &base_vha->dpc_flags);
  4361. }
  4362. if (IS_QLAFX00(ha))
  4363. goto loop_resync_check;
  4364. if (test_bit(ISP_QUIESCE_NEEDED, &base_vha->dpc_flags)) {
  4365. ql_dbg(ql_dbg_dpc, base_vha, 0x4009,
  4366. "Quiescence mode scheduled.\n");
  4367. if (IS_P3P_TYPE(ha)) {
  4368. if (IS_QLA82XX(ha))
  4369. qla82xx_device_state_handler(base_vha);
  4370. if (IS_QLA8044(ha))
  4371. qla8044_device_state_handler(base_vha);
  4372. clear_bit(ISP_QUIESCE_NEEDED,
  4373. &base_vha->dpc_flags);
  4374. if (!ha->flags.quiesce_owner) {
  4375. qla2x00_perform_loop_resync(base_vha);
  4376. if (IS_QLA82XX(ha)) {
  4377. qla82xx_idc_lock(ha);
  4378. qla82xx_clear_qsnt_ready(
  4379. base_vha);
  4380. qla82xx_idc_unlock(ha);
  4381. } else if (IS_QLA8044(ha)) {
  4382. qla8044_idc_lock(ha);
  4383. qla8044_clear_qsnt_ready(
  4384. base_vha);
  4385. qla8044_idc_unlock(ha);
  4386. }
  4387. }
  4388. } else {
  4389. clear_bit(ISP_QUIESCE_NEEDED,
  4390. &base_vha->dpc_flags);
  4391. qla2x00_quiesce_io(base_vha);
  4392. }
  4393. ql_dbg(ql_dbg_dpc, base_vha, 0x400a,
  4394. "Quiescence mode end.\n");
  4395. }
  4396. if (test_and_clear_bit(RESET_MARKER_NEEDED,
  4397. &base_vha->dpc_flags) &&
  4398. (!(test_and_set_bit(RESET_ACTIVE, &base_vha->dpc_flags)))) {
  4399. ql_dbg(ql_dbg_dpc, base_vha, 0x400b,
  4400. "Reset marker scheduled.\n");
  4401. qla2x00_rst_aen(base_vha);
  4402. clear_bit(RESET_ACTIVE, &base_vha->dpc_flags);
  4403. ql_dbg(ql_dbg_dpc, base_vha, 0x400c,
  4404. "Reset marker end.\n");
  4405. }
  4406. /* Retry each device up to login retry count */
  4407. if ((test_and_clear_bit(RELOGIN_NEEDED,
  4408. &base_vha->dpc_flags)) &&
  4409. !test_bit(LOOP_RESYNC_NEEDED, &base_vha->dpc_flags) &&
  4410. atomic_read(&base_vha->loop_state) != LOOP_DOWN) {
  4411. ql_dbg(ql_dbg_dpc, base_vha, 0x400d,
  4412. "Relogin scheduled.\n");
  4413. qla2x00_relogin(base_vha);
  4414. ql_dbg(ql_dbg_dpc, base_vha, 0x400e,
  4415. "Relogin end.\n");
  4416. }
  4417. loop_resync_check:
  4418. if (test_and_clear_bit(LOOP_RESYNC_NEEDED,
  4419. &base_vha->dpc_flags)) {
  4420. ql_dbg(ql_dbg_dpc, base_vha, 0x400f,
  4421. "Loop resync scheduled.\n");
  4422. if (!(test_and_set_bit(LOOP_RESYNC_ACTIVE,
  4423. &base_vha->dpc_flags))) {
  4424. qla2x00_loop_resync(base_vha);
  4425. clear_bit(LOOP_RESYNC_ACTIVE,
  4426. &base_vha->dpc_flags);
  4427. }
  4428. ql_dbg(ql_dbg_dpc, base_vha, 0x4010,
  4429. "Loop resync end.\n");
  4430. }
  4431. if (IS_QLAFX00(ha))
  4432. goto intr_on_check;
  4433. if (test_bit(NPIV_CONFIG_NEEDED, &base_vha->dpc_flags) &&
  4434. atomic_read(&base_vha->loop_state) == LOOP_READY) {
  4435. clear_bit(NPIV_CONFIG_NEEDED, &base_vha->dpc_flags);
  4436. qla2xxx_flash_npiv_conf(base_vha);
  4437. }
  4438. intr_on_check:
  4439. if (!ha->interrupts_on)
  4440. ha->isp_ops->enable_intrs(ha);
  4441. if (test_and_clear_bit(BEACON_BLINK_NEEDED,
  4442. &base_vha->dpc_flags)) {
  4443. if (ha->beacon_blink_led == 1)
  4444. ha->isp_ops->beacon_blink(base_vha);
  4445. }
  4446. if (!IS_QLAFX00(ha))
  4447. qla2x00_do_dpc_all_vps(base_vha);
  4448. ha->dpc_active = 0;
  4449. end_loop:
  4450. set_current_state(TASK_INTERRUPTIBLE);
  4451. } /* End of while(1) */
  4452. __set_current_state(TASK_RUNNING);
  4453. ql_dbg(ql_dbg_dpc, base_vha, 0x4011,
  4454. "DPC handler exiting.\n");
  4455. /*
  4456. * Make sure that nobody tries to wake us up again.
  4457. */
  4458. ha->dpc_active = 0;
  4459. /* Cleanup any residual CTX SRBs. */
  4460. qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16);
  4461. return 0;
  4462. }
  4463. void
  4464. qla2xxx_wake_dpc(struct scsi_qla_host *vha)
  4465. {
  4466. struct qla_hw_data *ha = vha->hw;
  4467. struct task_struct *t = ha->dpc_thread;
  4468. if (!test_bit(UNLOADING, &vha->dpc_flags) && t)
  4469. wake_up_process(t);
  4470. }
  4471. /*
  4472. * qla2x00_rst_aen
  4473. * Processes asynchronous reset.
  4474. *
  4475. * Input:
  4476. * ha = adapter block pointer.
  4477. */
  4478. static void
  4479. qla2x00_rst_aen(scsi_qla_host_t *vha)
  4480. {
  4481. if (vha->flags.online && !vha->flags.reset_active &&
  4482. !atomic_read(&vha->loop_down_timer) &&
  4483. !(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags))) {
  4484. do {
  4485. clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
  4486. /*
  4487. * Issue marker command only when we are going to start
  4488. * the I/O.
  4489. */
  4490. vha->marker_needed = 1;
  4491. } while (!atomic_read(&vha->loop_down_timer) &&
  4492. (test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags)));
  4493. }
  4494. }
  4495. /**************************************************************************
  4496. * qla2x00_timer
  4497. *
  4498. * Description:
  4499. * One second timer
  4500. *
  4501. * Context: Interrupt
  4502. ***************************************************************************/
  4503. void
  4504. qla2x00_timer(scsi_qla_host_t *vha)
  4505. {
  4506. unsigned long cpu_flags = 0;
  4507. int start_dpc = 0;
  4508. int index;
  4509. srb_t *sp;
  4510. uint16_t w;
  4511. struct qla_hw_data *ha = vha->hw;
  4512. struct req_que *req;
  4513. if (ha->flags.eeh_busy) {
  4514. ql_dbg(ql_dbg_timer, vha, 0x6000,
  4515. "EEH = %d, restarting timer.\n",
  4516. ha->flags.eeh_busy);
  4517. qla2x00_restart_timer(vha, WATCH_INTERVAL);
  4518. return;
  4519. }
  4520. /*
  4521. * Hardware read to raise pending EEH errors during mailbox waits. If
  4522. * the read returns -1 then disable the board.
  4523. */
  4524. if (!pci_channel_offline(ha->pdev)) {
  4525. pci_read_config_word(ha->pdev, PCI_VENDOR_ID, &w);
  4526. qla2x00_check_reg16_for_disconnect(vha, w);
  4527. }
  4528. /* Make sure qla82xx_watchdog is run only for physical port */
  4529. if (!vha->vp_idx && IS_P3P_TYPE(ha)) {
  4530. if (test_bit(ISP_QUIESCE_NEEDED, &vha->dpc_flags))
  4531. start_dpc++;
  4532. if (IS_QLA82XX(ha))
  4533. qla82xx_watchdog(vha);
  4534. else if (IS_QLA8044(ha))
  4535. qla8044_watchdog(vha);
  4536. }
  4537. if (!vha->vp_idx && IS_QLAFX00(ha))
  4538. qlafx00_timer_routine(vha);
  4539. /* Loop down handler. */
  4540. if (atomic_read(&vha->loop_down_timer) > 0 &&
  4541. !(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags)) &&
  4542. !(test_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags))
  4543. && vha->flags.online) {
  4544. if (atomic_read(&vha->loop_down_timer) ==
  4545. vha->loop_down_abort_time) {
  4546. ql_log(ql_log_info, vha, 0x6008,
  4547. "Loop down - aborting the queues before time expires.\n");
  4548. if (!IS_QLA2100(ha) && vha->link_down_timeout)
  4549. atomic_set(&vha->loop_state, LOOP_DEAD);
  4550. /*
  4551. * Schedule an ISP abort to return any FCP2-device
  4552. * commands.
  4553. */
  4554. /* NPIV - scan physical port only */
  4555. if (!vha->vp_idx) {
  4556. spin_lock_irqsave(&ha->hardware_lock,
  4557. cpu_flags);
  4558. req = ha->req_q_map[0];
  4559. for (index = 1;
  4560. index < req->num_outstanding_cmds;
  4561. index++) {
  4562. fc_port_t *sfcp;
  4563. sp = req->outstanding_cmds[index];
  4564. if (!sp)
  4565. continue;
  4566. if (sp->type != SRB_SCSI_CMD)
  4567. continue;
  4568. sfcp = sp->fcport;
  4569. if (!(sfcp->flags & FCF_FCP2_DEVICE))
  4570. continue;
  4571. if (IS_QLA82XX(ha))
  4572. set_bit(FCOE_CTX_RESET_NEEDED,
  4573. &vha->dpc_flags);
  4574. else
  4575. set_bit(ISP_ABORT_NEEDED,
  4576. &vha->dpc_flags);
  4577. break;
  4578. }
  4579. spin_unlock_irqrestore(&ha->hardware_lock,
  4580. cpu_flags);
  4581. }
  4582. start_dpc++;
  4583. }
  4584. /* if the loop has been down for 4 minutes, reinit adapter */
  4585. if (atomic_dec_and_test(&vha->loop_down_timer) != 0) {
  4586. if (!(vha->device_flags & DFLG_NO_CABLE)) {
  4587. ql_log(ql_log_warn, vha, 0x6009,
  4588. "Loop down - aborting ISP.\n");
  4589. if (IS_QLA82XX(ha))
  4590. set_bit(FCOE_CTX_RESET_NEEDED,
  4591. &vha->dpc_flags);
  4592. else
  4593. set_bit(ISP_ABORT_NEEDED,
  4594. &vha->dpc_flags);
  4595. }
  4596. }
  4597. ql_dbg(ql_dbg_timer, vha, 0x600a,
  4598. "Loop down - seconds remaining %d.\n",
  4599. atomic_read(&vha->loop_down_timer));
  4600. }
  4601. /* Check if beacon LED needs to be blinked for physical host only */
  4602. if (!vha->vp_idx && (ha->beacon_blink_led == 1)) {
  4603. /* There is no beacon_blink function for ISP82xx */
  4604. if (!IS_P3P_TYPE(ha)) {
  4605. set_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags);
  4606. start_dpc++;
  4607. }
  4608. }
  4609. /* Process any deferred work. */
  4610. if (!list_empty(&vha->work_list))
  4611. start_dpc++;
  4612. /* Schedule the DPC routine if needed */
  4613. if ((test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) ||
  4614. test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags) ||
  4615. test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags) ||
  4616. start_dpc ||
  4617. test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags) ||
  4618. test_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags) ||
  4619. test_bit(ISP_UNRECOVERABLE, &vha->dpc_flags) ||
  4620. test_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags) ||
  4621. test_bit(VP_DPC_NEEDED, &vha->dpc_flags) ||
  4622. test_bit(RELOGIN_NEEDED, &vha->dpc_flags))) {
  4623. ql_dbg(ql_dbg_timer, vha, 0x600b,
  4624. "isp_abort_needed=%d loop_resync_needed=%d "
  4625. "fcport_update_needed=%d start_dpc=%d "
  4626. "reset_marker_needed=%d",
  4627. test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags),
  4628. test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags),
  4629. test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags),
  4630. start_dpc,
  4631. test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags));
  4632. ql_dbg(ql_dbg_timer, vha, 0x600c,
  4633. "beacon_blink_needed=%d isp_unrecoverable=%d "
  4634. "fcoe_ctx_reset_needed=%d vp_dpc_needed=%d "
  4635. "relogin_needed=%d.\n",
  4636. test_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags),
  4637. test_bit(ISP_UNRECOVERABLE, &vha->dpc_flags),
  4638. test_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags),
  4639. test_bit(VP_DPC_NEEDED, &vha->dpc_flags),
  4640. test_bit(RELOGIN_NEEDED, &vha->dpc_flags));
  4641. qla2xxx_wake_dpc(vha);
  4642. }
  4643. qla2x00_restart_timer(vha, WATCH_INTERVAL);
  4644. }
  4645. /* Firmware interface routines. */
  4646. #define FW_BLOBS 11
  4647. #define FW_ISP21XX 0
  4648. #define FW_ISP22XX 1
  4649. #define FW_ISP2300 2
  4650. #define FW_ISP2322 3
  4651. #define FW_ISP24XX 4
  4652. #define FW_ISP25XX 5
  4653. #define FW_ISP81XX 6
  4654. #define FW_ISP82XX 7
  4655. #define FW_ISP2031 8
  4656. #define FW_ISP8031 9
  4657. #define FW_ISP27XX 10
  4658. #define FW_FILE_ISP21XX "ql2100_fw.bin"
  4659. #define FW_FILE_ISP22XX "ql2200_fw.bin"
  4660. #define FW_FILE_ISP2300 "ql2300_fw.bin"
  4661. #define FW_FILE_ISP2322 "ql2322_fw.bin"
  4662. #define FW_FILE_ISP24XX "ql2400_fw.bin"
  4663. #define FW_FILE_ISP25XX "ql2500_fw.bin"
  4664. #define FW_FILE_ISP81XX "ql8100_fw.bin"
  4665. #define FW_FILE_ISP82XX "ql8200_fw.bin"
  4666. #define FW_FILE_ISP2031 "ql2600_fw.bin"
  4667. #define FW_FILE_ISP8031 "ql8300_fw.bin"
  4668. #define FW_FILE_ISP27XX "ql2700_fw.bin"
  4669. static DEFINE_MUTEX(qla_fw_lock);
  4670. static struct fw_blob qla_fw_blobs[FW_BLOBS] = {
  4671. { .name = FW_FILE_ISP21XX, .segs = { 0x1000, 0 }, },
  4672. { .name = FW_FILE_ISP22XX, .segs = { 0x1000, 0 }, },
  4673. { .name = FW_FILE_ISP2300, .segs = { 0x800, 0 }, },
  4674. { .name = FW_FILE_ISP2322, .segs = { 0x800, 0x1c000, 0x1e000, 0 }, },
  4675. { .name = FW_FILE_ISP24XX, },
  4676. { .name = FW_FILE_ISP25XX, },
  4677. { .name = FW_FILE_ISP81XX, },
  4678. { .name = FW_FILE_ISP82XX, },
  4679. { .name = FW_FILE_ISP2031, },
  4680. { .name = FW_FILE_ISP8031, },
  4681. { .name = FW_FILE_ISP27XX, },
  4682. };
  4683. struct fw_blob *
  4684. qla2x00_request_firmware(scsi_qla_host_t *vha)
  4685. {
  4686. struct qla_hw_data *ha = vha->hw;
  4687. struct fw_blob *blob;
  4688. if (IS_QLA2100(ha)) {
  4689. blob = &qla_fw_blobs[FW_ISP21XX];
  4690. } else if (IS_QLA2200(ha)) {
  4691. blob = &qla_fw_blobs[FW_ISP22XX];
  4692. } else if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
  4693. blob = &qla_fw_blobs[FW_ISP2300];
  4694. } else if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
  4695. blob = &qla_fw_blobs[FW_ISP2322];
  4696. } else if (IS_QLA24XX_TYPE(ha)) {
  4697. blob = &qla_fw_blobs[FW_ISP24XX];
  4698. } else if (IS_QLA25XX(ha)) {
  4699. blob = &qla_fw_blobs[FW_ISP25XX];
  4700. } else if (IS_QLA81XX(ha)) {
  4701. blob = &qla_fw_blobs[FW_ISP81XX];
  4702. } else if (IS_QLA82XX(ha)) {
  4703. blob = &qla_fw_blobs[FW_ISP82XX];
  4704. } else if (IS_QLA2031(ha)) {
  4705. blob = &qla_fw_blobs[FW_ISP2031];
  4706. } else if (IS_QLA8031(ha)) {
  4707. blob = &qla_fw_blobs[FW_ISP8031];
  4708. } else if (IS_QLA27XX(ha)) {
  4709. blob = &qla_fw_blobs[FW_ISP27XX];
  4710. } else {
  4711. return NULL;
  4712. }
  4713. mutex_lock(&qla_fw_lock);
  4714. if (blob->fw)
  4715. goto out;
  4716. if (request_firmware(&blob->fw, blob->name, &ha->pdev->dev)) {
  4717. ql_log(ql_log_warn, vha, 0x0063,
  4718. "Failed to load firmware image (%s).\n", blob->name);
  4719. blob->fw = NULL;
  4720. blob = NULL;
  4721. goto out;
  4722. }
  4723. out:
  4724. mutex_unlock(&qla_fw_lock);
  4725. return blob;
  4726. }
  4727. static void
  4728. qla2x00_release_firmware(void)
  4729. {
  4730. int idx;
  4731. mutex_lock(&qla_fw_lock);
  4732. for (idx = 0; idx < FW_BLOBS; idx++)
  4733. release_firmware(qla_fw_blobs[idx].fw);
  4734. mutex_unlock(&qla_fw_lock);
  4735. }
  4736. static pci_ers_result_t
  4737. qla2xxx_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
  4738. {
  4739. scsi_qla_host_t *vha = pci_get_drvdata(pdev);
  4740. struct qla_hw_data *ha = vha->hw;
  4741. ql_dbg(ql_dbg_aer, vha, 0x9000,
  4742. "PCI error detected, state %x.\n", state);
  4743. switch (state) {
  4744. case pci_channel_io_normal:
  4745. ha->flags.eeh_busy = 0;
  4746. return PCI_ERS_RESULT_CAN_RECOVER;
  4747. case pci_channel_io_frozen:
  4748. ha->flags.eeh_busy = 1;
  4749. /* For ISP82XX complete any pending mailbox cmd */
  4750. if (IS_QLA82XX(ha)) {
  4751. ha->flags.isp82xx_fw_hung = 1;
  4752. ql_dbg(ql_dbg_aer, vha, 0x9001, "Pci channel io frozen\n");
  4753. qla82xx_clear_pending_mbx(vha);
  4754. }
  4755. qla2x00_free_irqs(vha);
  4756. pci_disable_device(pdev);
  4757. /* Return back all IOs */
  4758. qla2x00_abort_all_cmds(vha, DID_RESET << 16);
  4759. return PCI_ERS_RESULT_NEED_RESET;
  4760. case pci_channel_io_perm_failure:
  4761. ha->flags.pci_channel_io_perm_failure = 1;
  4762. qla2x00_abort_all_cmds(vha, DID_NO_CONNECT << 16);
  4763. return PCI_ERS_RESULT_DISCONNECT;
  4764. }
  4765. return PCI_ERS_RESULT_NEED_RESET;
  4766. }
  4767. static pci_ers_result_t
  4768. qla2xxx_pci_mmio_enabled(struct pci_dev *pdev)
  4769. {
  4770. int risc_paused = 0;
  4771. uint32_t stat;
  4772. unsigned long flags;
  4773. scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
  4774. struct qla_hw_data *ha = base_vha->hw;
  4775. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  4776. struct device_reg_24xx __iomem *reg24 = &ha->iobase->isp24;
  4777. if (IS_QLA82XX(ha))
  4778. return PCI_ERS_RESULT_RECOVERED;
  4779. spin_lock_irqsave(&ha->hardware_lock, flags);
  4780. if (IS_QLA2100(ha) || IS_QLA2200(ha)){
  4781. stat = RD_REG_DWORD(&reg->hccr);
  4782. if (stat & HCCR_RISC_PAUSE)
  4783. risc_paused = 1;
  4784. } else if (IS_QLA23XX(ha)) {
  4785. stat = RD_REG_DWORD(&reg->u.isp2300.host_status);
  4786. if (stat & HSR_RISC_PAUSED)
  4787. risc_paused = 1;
  4788. } else if (IS_FWI2_CAPABLE(ha)) {
  4789. stat = RD_REG_DWORD(&reg24->host_status);
  4790. if (stat & HSRX_RISC_PAUSED)
  4791. risc_paused = 1;
  4792. }
  4793. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  4794. if (risc_paused) {
  4795. ql_log(ql_log_info, base_vha, 0x9003,
  4796. "RISC paused -- mmio_enabled, Dumping firmware.\n");
  4797. ha->isp_ops->fw_dump(base_vha, 0);
  4798. return PCI_ERS_RESULT_NEED_RESET;
  4799. } else
  4800. return PCI_ERS_RESULT_RECOVERED;
  4801. }
  4802. static uint32_t
  4803. qla82xx_error_recovery(scsi_qla_host_t *base_vha)
  4804. {
  4805. uint32_t rval = QLA_FUNCTION_FAILED;
  4806. uint32_t drv_active = 0;
  4807. struct qla_hw_data *ha = base_vha->hw;
  4808. int fn;
  4809. struct pci_dev *other_pdev = NULL;
  4810. ql_dbg(ql_dbg_aer, base_vha, 0x9006,
  4811. "Entered %s.\n", __func__);
  4812. set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
  4813. if (base_vha->flags.online) {
  4814. /* Abort all outstanding commands,
  4815. * so as to be requeued later */
  4816. qla2x00_abort_isp_cleanup(base_vha);
  4817. }
  4818. fn = PCI_FUNC(ha->pdev->devfn);
  4819. while (fn > 0) {
  4820. fn--;
  4821. ql_dbg(ql_dbg_aer, base_vha, 0x9007,
  4822. "Finding pci device at function = 0x%x.\n", fn);
  4823. other_pdev =
  4824. pci_get_domain_bus_and_slot(pci_domain_nr(ha->pdev->bus),
  4825. ha->pdev->bus->number, PCI_DEVFN(PCI_SLOT(ha->pdev->devfn),
  4826. fn));
  4827. if (!other_pdev)
  4828. continue;
  4829. if (atomic_read(&other_pdev->enable_cnt)) {
  4830. ql_dbg(ql_dbg_aer, base_vha, 0x9008,
  4831. "Found PCI func available and enable at 0x%x.\n",
  4832. fn);
  4833. pci_dev_put(other_pdev);
  4834. break;
  4835. }
  4836. pci_dev_put(other_pdev);
  4837. }
  4838. if (!fn) {
  4839. /* Reset owner */
  4840. ql_dbg(ql_dbg_aer, base_vha, 0x9009,
  4841. "This devfn is reset owner = 0x%x.\n",
  4842. ha->pdev->devfn);
  4843. qla82xx_idc_lock(ha);
  4844. qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
  4845. QLA8XXX_DEV_INITIALIZING);
  4846. qla82xx_wr_32(ha, QLA82XX_CRB_DRV_IDC_VERSION,
  4847. QLA82XX_IDC_VERSION);
  4848. drv_active = qla82xx_rd_32(ha, QLA82XX_CRB_DRV_ACTIVE);
  4849. ql_dbg(ql_dbg_aer, base_vha, 0x900a,
  4850. "drv_active = 0x%x.\n", drv_active);
  4851. qla82xx_idc_unlock(ha);
  4852. /* Reset if device is not already reset
  4853. * drv_active would be 0 if a reset has already been done
  4854. */
  4855. if (drv_active)
  4856. rval = qla82xx_start_firmware(base_vha);
  4857. else
  4858. rval = QLA_SUCCESS;
  4859. qla82xx_idc_lock(ha);
  4860. if (rval != QLA_SUCCESS) {
  4861. ql_log(ql_log_info, base_vha, 0x900b,
  4862. "HW State: FAILED.\n");
  4863. qla82xx_clear_drv_active(ha);
  4864. qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
  4865. QLA8XXX_DEV_FAILED);
  4866. } else {
  4867. ql_log(ql_log_info, base_vha, 0x900c,
  4868. "HW State: READY.\n");
  4869. qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
  4870. QLA8XXX_DEV_READY);
  4871. qla82xx_idc_unlock(ha);
  4872. ha->flags.isp82xx_fw_hung = 0;
  4873. rval = qla82xx_restart_isp(base_vha);
  4874. qla82xx_idc_lock(ha);
  4875. /* Clear driver state register */
  4876. qla82xx_wr_32(ha, QLA82XX_CRB_DRV_STATE, 0);
  4877. qla82xx_set_drv_active(base_vha);
  4878. }
  4879. qla82xx_idc_unlock(ha);
  4880. } else {
  4881. ql_dbg(ql_dbg_aer, base_vha, 0x900d,
  4882. "This devfn is not reset owner = 0x%x.\n",
  4883. ha->pdev->devfn);
  4884. if ((qla82xx_rd_32(ha, QLA82XX_CRB_DEV_STATE) ==
  4885. QLA8XXX_DEV_READY)) {
  4886. ha->flags.isp82xx_fw_hung = 0;
  4887. rval = qla82xx_restart_isp(base_vha);
  4888. qla82xx_idc_lock(ha);
  4889. qla82xx_set_drv_active(base_vha);
  4890. qla82xx_idc_unlock(ha);
  4891. }
  4892. }
  4893. clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
  4894. return rval;
  4895. }
  4896. static pci_ers_result_t
  4897. qla2xxx_pci_slot_reset(struct pci_dev *pdev)
  4898. {
  4899. pci_ers_result_t ret = PCI_ERS_RESULT_DISCONNECT;
  4900. scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
  4901. struct qla_hw_data *ha = base_vha->hw;
  4902. struct rsp_que *rsp;
  4903. int rc, retries = 10;
  4904. ql_dbg(ql_dbg_aer, base_vha, 0x9004,
  4905. "Slot Reset.\n");
  4906. /* Workaround: qla2xxx driver which access hardware earlier
  4907. * needs error state to be pci_channel_io_online.
  4908. * Otherwise mailbox command timesout.
  4909. */
  4910. pdev->error_state = pci_channel_io_normal;
  4911. pci_restore_state(pdev);
  4912. /* pci_restore_state() clears the saved_state flag of the device
  4913. * save restored state which resets saved_state flag
  4914. */
  4915. pci_save_state(pdev);
  4916. if (ha->mem_only)
  4917. rc = pci_enable_device_mem(pdev);
  4918. else
  4919. rc = pci_enable_device(pdev);
  4920. if (rc) {
  4921. ql_log(ql_log_warn, base_vha, 0x9005,
  4922. "Can't re-enable PCI device after reset.\n");
  4923. goto exit_slot_reset;
  4924. }
  4925. rsp = ha->rsp_q_map[0];
  4926. if (qla2x00_request_irqs(ha, rsp))
  4927. goto exit_slot_reset;
  4928. if (ha->isp_ops->pci_config(base_vha))
  4929. goto exit_slot_reset;
  4930. if (IS_QLA82XX(ha)) {
  4931. if (qla82xx_error_recovery(base_vha) == QLA_SUCCESS) {
  4932. ret = PCI_ERS_RESULT_RECOVERED;
  4933. goto exit_slot_reset;
  4934. } else
  4935. goto exit_slot_reset;
  4936. }
  4937. while (ha->flags.mbox_busy && retries--)
  4938. msleep(1000);
  4939. set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
  4940. if (ha->isp_ops->abort_isp(base_vha) == QLA_SUCCESS)
  4941. ret = PCI_ERS_RESULT_RECOVERED;
  4942. clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
  4943. exit_slot_reset:
  4944. ql_dbg(ql_dbg_aer, base_vha, 0x900e,
  4945. "slot_reset return %x.\n", ret);
  4946. return ret;
  4947. }
  4948. static void
  4949. qla2xxx_pci_resume(struct pci_dev *pdev)
  4950. {
  4951. scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
  4952. struct qla_hw_data *ha = base_vha->hw;
  4953. int ret;
  4954. ql_dbg(ql_dbg_aer, base_vha, 0x900f,
  4955. "pci_resume.\n");
  4956. ret = qla2x00_wait_for_hba_online(base_vha);
  4957. if (ret != QLA_SUCCESS) {
  4958. ql_log(ql_log_fatal, base_vha, 0x9002,
  4959. "The device failed to resume I/O from slot/link_reset.\n");
  4960. }
  4961. pci_cleanup_aer_uncorrect_error_status(pdev);
  4962. ha->flags.eeh_busy = 0;
  4963. }
  4964. static void
  4965. qla83xx_disable_laser(scsi_qla_host_t *vha)
  4966. {
  4967. uint32_t reg, data, fn;
  4968. struct qla_hw_data *ha = vha->hw;
  4969. struct device_reg_24xx __iomem *isp_reg = &ha->iobase->isp24;
  4970. /* pci func #/port # */
  4971. ql_dbg(ql_dbg_init, vha, 0x004b,
  4972. "Disabling Laser for hba: %p\n", vha);
  4973. fn = (RD_REG_DWORD(&isp_reg->ctrl_status) &
  4974. (BIT_15|BIT_14|BIT_13|BIT_12));
  4975. fn = (fn >> 12);
  4976. if (fn & 1)
  4977. reg = PORT_1_2031;
  4978. else
  4979. reg = PORT_0_2031;
  4980. data = LASER_OFF_2031;
  4981. qla83xx_wr_reg(vha, reg, data);
  4982. }
  4983. static const struct pci_error_handlers qla2xxx_err_handler = {
  4984. .error_detected = qla2xxx_pci_error_detected,
  4985. .mmio_enabled = qla2xxx_pci_mmio_enabled,
  4986. .slot_reset = qla2xxx_pci_slot_reset,
  4987. .resume = qla2xxx_pci_resume,
  4988. };
  4989. static struct pci_device_id qla2xxx_pci_tbl[] = {
  4990. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2100) },
  4991. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2200) },
  4992. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2300) },
  4993. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2312) },
  4994. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2322) },
  4995. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6312) },
  4996. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6322) },
  4997. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2422) },
  4998. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2432) },
  4999. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8432) },
  5000. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5422) },
  5001. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5432) },
  5002. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2532) },
  5003. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2031) },
  5004. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8001) },
  5005. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8021) },
  5006. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8031) },
  5007. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISPF001) },
  5008. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8044) },
  5009. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2071) },
  5010. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2271) },
  5011. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2261) },
  5012. { 0 },
  5013. };
  5014. MODULE_DEVICE_TABLE(pci, qla2xxx_pci_tbl);
  5015. static struct pci_driver qla2xxx_pci_driver = {
  5016. .name = QLA2XXX_DRIVER_NAME,
  5017. .driver = {
  5018. .owner = THIS_MODULE,
  5019. },
  5020. .id_table = qla2xxx_pci_tbl,
  5021. .probe = qla2x00_probe_one,
  5022. .remove = qla2x00_remove_one,
  5023. .shutdown = qla2x00_shutdown,
  5024. .err_handler = &qla2xxx_err_handler,
  5025. };
  5026. static const struct file_operations apidev_fops = {
  5027. .owner = THIS_MODULE,
  5028. .llseek = noop_llseek,
  5029. };
  5030. /**
  5031. * qla2x00_module_init - Module initialization.
  5032. **/
  5033. static int __init
  5034. qla2x00_module_init(void)
  5035. {
  5036. int ret = 0;
  5037. /* Allocate cache for SRBs. */
  5038. srb_cachep = kmem_cache_create("qla2xxx_srbs", sizeof(srb_t), 0,
  5039. SLAB_HWCACHE_ALIGN, NULL);
  5040. if (srb_cachep == NULL) {
  5041. ql_log(ql_log_fatal, NULL, 0x0001,
  5042. "Unable to allocate SRB cache...Failing load!.\n");
  5043. return -ENOMEM;
  5044. }
  5045. /* Initialize target kmem_cache and mem_pools */
  5046. ret = qlt_init();
  5047. if (ret < 0) {
  5048. kmem_cache_destroy(srb_cachep);
  5049. return ret;
  5050. } else if (ret > 0) {
  5051. /*
  5052. * If initiator mode is explictly disabled by qlt_init(),
  5053. * prevent scsi_transport_fc.c:fc_scsi_scan_rport() from
  5054. * performing scsi_scan_target() during LOOP UP event.
  5055. */
  5056. qla2xxx_transport_functions.disable_target_scan = 1;
  5057. qla2xxx_transport_vport_functions.disable_target_scan = 1;
  5058. }
  5059. /* Derive version string. */
  5060. strcpy(qla2x00_version_str, QLA2XXX_VERSION);
  5061. if (ql2xextended_error_logging)
  5062. strcat(qla2x00_version_str, "-debug");
  5063. qla2xxx_transport_template =
  5064. fc_attach_transport(&qla2xxx_transport_functions);
  5065. if (!qla2xxx_transport_template) {
  5066. kmem_cache_destroy(srb_cachep);
  5067. ql_log(ql_log_fatal, NULL, 0x0002,
  5068. "fc_attach_transport failed...Failing load!.\n");
  5069. qlt_exit();
  5070. return -ENODEV;
  5071. }
  5072. apidev_major = register_chrdev(0, QLA2XXX_APIDEV, &apidev_fops);
  5073. if (apidev_major < 0) {
  5074. ql_log(ql_log_fatal, NULL, 0x0003,
  5075. "Unable to register char device %s.\n", QLA2XXX_APIDEV);
  5076. }
  5077. qla2xxx_transport_vport_template =
  5078. fc_attach_transport(&qla2xxx_transport_vport_functions);
  5079. if (!qla2xxx_transport_vport_template) {
  5080. kmem_cache_destroy(srb_cachep);
  5081. qlt_exit();
  5082. fc_release_transport(qla2xxx_transport_template);
  5083. ql_log(ql_log_fatal, NULL, 0x0004,
  5084. "fc_attach_transport vport failed...Failing load!.\n");
  5085. return -ENODEV;
  5086. }
  5087. ql_log(ql_log_info, NULL, 0x0005,
  5088. "QLogic Fibre Channel HBA Driver: %s.\n",
  5089. qla2x00_version_str);
  5090. ret = pci_register_driver(&qla2xxx_pci_driver);
  5091. if (ret) {
  5092. kmem_cache_destroy(srb_cachep);
  5093. qlt_exit();
  5094. fc_release_transport(qla2xxx_transport_template);
  5095. fc_release_transport(qla2xxx_transport_vport_template);
  5096. ql_log(ql_log_fatal, NULL, 0x0006,
  5097. "pci_register_driver failed...ret=%d Failing load!.\n",
  5098. ret);
  5099. }
  5100. return ret;
  5101. }
  5102. /**
  5103. * qla2x00_module_exit - Module cleanup.
  5104. **/
  5105. static void __exit
  5106. qla2x00_module_exit(void)
  5107. {
  5108. unregister_chrdev(apidev_major, QLA2XXX_APIDEV);
  5109. pci_unregister_driver(&qla2xxx_pci_driver);
  5110. qla2x00_release_firmware();
  5111. kmem_cache_destroy(srb_cachep);
  5112. qlt_exit();
  5113. if (ctx_cachep)
  5114. kmem_cache_destroy(ctx_cachep);
  5115. fc_release_transport(qla2xxx_transport_template);
  5116. fc_release_transport(qla2xxx_transport_vport_template);
  5117. }
  5118. module_init(qla2x00_module_init);
  5119. module_exit(qla2x00_module_exit);
  5120. MODULE_AUTHOR("QLogic Corporation");
  5121. MODULE_DESCRIPTION("QLogic Fibre Channel HBA Driver");
  5122. MODULE_LICENSE("GPL");
  5123. MODULE_VERSION(QLA2XXX_VERSION);
  5124. MODULE_FIRMWARE(FW_FILE_ISP21XX);
  5125. MODULE_FIRMWARE(FW_FILE_ISP22XX);
  5126. MODULE_FIRMWARE(FW_FILE_ISP2300);
  5127. MODULE_FIRMWARE(FW_FILE_ISP2322);
  5128. MODULE_FIRMWARE(FW_FILE_ISP24XX);
  5129. MODULE_FIRMWARE(FW_FILE_ISP25XX);
  5130. MODULE_FIRMWARE(FW_FILE_ISP2031);
  5131. MODULE_FIRMWARE(FW_FILE_ISP8031);
  5132. MODULE_FIRMWARE(FW_FILE_ISP27XX);