qla_os.c 153 KB

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