qla_os.c 119 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443
  1. /*
  2. * QLogic Fibre Channel HBA Driver
  3. * Copyright (c) 2003-2011 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. /*
  20. * Driver version
  21. */
  22. char qla2x00_version_str[40];
  23. static int apidev_major;
  24. /*
  25. * SRB allocation cache
  26. */
  27. static struct kmem_cache *srb_cachep;
  28. /*
  29. * CT6 CTX allocation cache
  30. */
  31. static struct kmem_cache *ctx_cachep;
  32. /*
  33. * error level for logging
  34. */
  35. int ql_errlev = ql_log_all;
  36. int ql2xlogintimeout = 20;
  37. module_param(ql2xlogintimeout, int, S_IRUGO);
  38. MODULE_PARM_DESC(ql2xlogintimeout,
  39. "Login timeout value in seconds.");
  40. int qlport_down_retry;
  41. module_param(qlport_down_retry, int, S_IRUGO);
  42. MODULE_PARM_DESC(qlport_down_retry,
  43. "Maximum number of command retries to a port that returns "
  44. "a PORT-DOWN status.");
  45. int ql2xplogiabsentdevice;
  46. module_param(ql2xplogiabsentdevice, int, S_IRUGO|S_IWUSR);
  47. MODULE_PARM_DESC(ql2xplogiabsentdevice,
  48. "Option to enable PLOGI to devices that are not present after "
  49. "a Fabric scan. This is needed for several broken switches. "
  50. "Default is 0 - no PLOGI. 1 - perfom PLOGI.");
  51. int ql2xloginretrycount = 0;
  52. module_param(ql2xloginretrycount, int, S_IRUGO);
  53. MODULE_PARM_DESC(ql2xloginretrycount,
  54. "Specify an alternate value for the NVRAM login retry count.");
  55. int ql2xallocfwdump = 1;
  56. module_param(ql2xallocfwdump, int, S_IRUGO);
  57. MODULE_PARM_DESC(ql2xallocfwdump,
  58. "Option to enable allocation of memory for a firmware dump "
  59. "during HBA initialization. Memory allocation requirements "
  60. "vary by ISP type. Default is 1 - allocate memory.");
  61. int ql2xextended_error_logging;
  62. module_param(ql2xextended_error_logging, int, S_IRUGO|S_IWUSR);
  63. MODULE_PARM_DESC(ql2xextended_error_logging,
  64. "Option to enable extended error logging,\n"
  65. "\t\tDefault is 0 - no logging. 0x40000000 - Module Init & Probe.\n"
  66. "\t\t0x20000000 - Mailbox Cmnds. 0x10000000 - Device Discovery.\n"
  67. "\t\t0x08000000 - IO tracing. 0x04000000 - DPC Thread.\n"
  68. "\t\t0x02000000 - Async events. 0x01000000 - Timer routines.\n"
  69. "\t\t0x00800000 - User space. 0x00400000 - Task Management.\n"
  70. "\t\t0x00200000 - AER/EEH. 0x00100000 - Multi Q.\n"
  71. "\t\t0x00080000 - P3P Specific. 0x00040000 - Virtual Port.\n"
  72. "\t\t0x00020000 - Buffer Dump. 0x00010000 - Misc.\n"
  73. "\t\t0x7fffffff - For enabling all logs, can be too many logs.\n"
  74. "\t\tDo LOGICAL OR of the value to enable more than one level");
  75. int ql2xshiftctondsd = 6;
  76. module_param(ql2xshiftctondsd, int, S_IRUGO);
  77. MODULE_PARM_DESC(ql2xshiftctondsd,
  78. "Set to control shifting of command type processing "
  79. "based on total number of SG elements.");
  80. static void qla2x00_free_device(scsi_qla_host_t *);
  81. int ql2xfdmienable=1;
  82. module_param(ql2xfdmienable, int, S_IRUGO);
  83. MODULE_PARM_DESC(ql2xfdmienable,
  84. "Enables FDMI registrations. "
  85. "0 - no FDMI. Default is 1 - perform FDMI.");
  86. #define MAX_Q_DEPTH 32
  87. static int ql2xmaxqdepth = MAX_Q_DEPTH;
  88. module_param(ql2xmaxqdepth, int, S_IRUGO|S_IWUSR);
  89. MODULE_PARM_DESC(ql2xmaxqdepth,
  90. "Maximum queue depth to report for target devices.");
  91. /* Do not change the value of this after module load */
  92. int ql2xenabledif = 0;
  93. module_param(ql2xenabledif, int, S_IRUGO|S_IWUSR);
  94. MODULE_PARM_DESC(ql2xenabledif,
  95. " Enable T10-CRC-DIF "
  96. " Default is 0 - No DIF Support. 1 - Enable it"
  97. ", 2 - Enable DIF for all types, except Type 0.");
  98. int ql2xenablehba_err_chk = 2;
  99. module_param(ql2xenablehba_err_chk, int, S_IRUGO|S_IWUSR);
  100. MODULE_PARM_DESC(ql2xenablehba_err_chk,
  101. " Enable T10-CRC-DIF Error isolation by HBA:\n"
  102. " Default is 1.\n"
  103. " 0 -- Error isolation disabled\n"
  104. " 1 -- Error isolation enabled only for DIX Type 0\n"
  105. " 2 -- Error isolation enabled for all Types\n");
  106. int ql2xiidmaenable=1;
  107. module_param(ql2xiidmaenable, int, S_IRUGO);
  108. MODULE_PARM_DESC(ql2xiidmaenable,
  109. "Enables iIDMA settings "
  110. "Default is 1 - perform iIDMA. 0 - no iIDMA.");
  111. int ql2xmaxqueues = 1;
  112. module_param(ql2xmaxqueues, int, S_IRUGO);
  113. MODULE_PARM_DESC(ql2xmaxqueues,
  114. "Enables MQ settings "
  115. "Default is 1 for single queue. Set it to number "
  116. "of queues in MQ mode.");
  117. int ql2xmultique_tag;
  118. module_param(ql2xmultique_tag, int, S_IRUGO);
  119. MODULE_PARM_DESC(ql2xmultique_tag,
  120. "Enables CPU affinity settings for the driver "
  121. "Default is 0 for no affinity of request and response IO. "
  122. "Set it to 1 to turn on the cpu affinity.");
  123. int ql2xfwloadbin;
  124. module_param(ql2xfwloadbin, int, S_IRUGO);
  125. MODULE_PARM_DESC(ql2xfwloadbin,
  126. "Option to specify location from which to load ISP firmware:.\n"
  127. " 2 -- load firmware via the request_firmware() (hotplug).\n"
  128. " interface.\n"
  129. " 1 -- load firmware from flash.\n"
  130. " 0 -- use default semantics.\n");
  131. int ql2xetsenable;
  132. module_param(ql2xetsenable, int, S_IRUGO);
  133. MODULE_PARM_DESC(ql2xetsenable,
  134. "Enables firmware ETS burst."
  135. "Default is 0 - skip ETS enablement.");
  136. int ql2xdbwr = 1;
  137. module_param(ql2xdbwr, int, S_IRUGO);
  138. MODULE_PARM_DESC(ql2xdbwr,
  139. "Option to specify scheme for request queue posting.\n"
  140. " 0 -- Regular doorbell.\n"
  141. " 1 -- CAMRAM doorbell (faster).\n");
  142. int ql2xtargetreset = 1;
  143. module_param(ql2xtargetreset, int, S_IRUGO);
  144. MODULE_PARM_DESC(ql2xtargetreset,
  145. "Enable target reset."
  146. "Default is 1 - use hw defaults.");
  147. int ql2xgffidenable;
  148. module_param(ql2xgffidenable, int, S_IRUGO);
  149. MODULE_PARM_DESC(ql2xgffidenable,
  150. "Enables GFF_ID checks of port type. "
  151. "Default is 0 - Do not use GFF_ID information.");
  152. int ql2xasynctmfenable;
  153. module_param(ql2xasynctmfenable, int, S_IRUGO);
  154. MODULE_PARM_DESC(ql2xasynctmfenable,
  155. "Enables issue of TM IOCBs asynchronously via IOCB mechanism"
  156. "Default is 0 - Issue TM IOCBs via mailbox mechanism.");
  157. int ql2xdontresethba;
  158. module_param(ql2xdontresethba, int, S_IRUGO);
  159. MODULE_PARM_DESC(ql2xdontresethba,
  160. "Option to specify reset behaviour.\n"
  161. " 0 (Default) -- Reset on failure.\n"
  162. " 1 -- Do not reset on failure.\n");
  163. uint ql2xmaxlun = MAX_LUNS;
  164. module_param(ql2xmaxlun, uint, S_IRUGO);
  165. MODULE_PARM_DESC(ql2xmaxlun,
  166. "Defines the maximum LU number to register with the SCSI "
  167. "midlayer. Default is 65535.");
  168. /*
  169. * SCSI host template entry points
  170. */
  171. static int qla2xxx_slave_configure(struct scsi_device * device);
  172. static int qla2xxx_slave_alloc(struct scsi_device *);
  173. static int qla2xxx_scan_finished(struct Scsi_Host *, unsigned long time);
  174. static void qla2xxx_scan_start(struct Scsi_Host *);
  175. static void qla2xxx_slave_destroy(struct scsi_device *);
  176. static int qla2xxx_queuecommand(struct Scsi_Host *h, struct scsi_cmnd *cmd);
  177. static int qla2xxx_eh_abort(struct scsi_cmnd *);
  178. static int qla2xxx_eh_device_reset(struct scsi_cmnd *);
  179. static int qla2xxx_eh_target_reset(struct scsi_cmnd *);
  180. static int qla2xxx_eh_bus_reset(struct scsi_cmnd *);
  181. static int qla2xxx_eh_host_reset(struct scsi_cmnd *);
  182. static int qla2x00_change_queue_depth(struct scsi_device *, int, int);
  183. static int qla2x00_change_queue_type(struct scsi_device *, int);
  184. struct scsi_host_template qla2xxx_driver_template = {
  185. .module = THIS_MODULE,
  186. .name = QLA2XXX_DRIVER_NAME,
  187. .queuecommand = qla2xxx_queuecommand,
  188. .eh_abort_handler = qla2xxx_eh_abort,
  189. .eh_device_reset_handler = qla2xxx_eh_device_reset,
  190. .eh_target_reset_handler = qla2xxx_eh_target_reset,
  191. .eh_bus_reset_handler = qla2xxx_eh_bus_reset,
  192. .eh_host_reset_handler = qla2xxx_eh_host_reset,
  193. .slave_configure = qla2xxx_slave_configure,
  194. .slave_alloc = qla2xxx_slave_alloc,
  195. .slave_destroy = qla2xxx_slave_destroy,
  196. .scan_finished = qla2xxx_scan_finished,
  197. .scan_start = qla2xxx_scan_start,
  198. .change_queue_depth = qla2x00_change_queue_depth,
  199. .change_queue_type = qla2x00_change_queue_type,
  200. .this_id = -1,
  201. .cmd_per_lun = 3,
  202. .use_clustering = ENABLE_CLUSTERING,
  203. .sg_tablesize = SG_ALL,
  204. .max_sectors = 0xFFFF,
  205. .shost_attrs = qla2x00_host_attrs,
  206. };
  207. static struct scsi_transport_template *qla2xxx_transport_template = NULL;
  208. struct scsi_transport_template *qla2xxx_transport_vport_template = NULL;
  209. /* TODO Convert to inlines
  210. *
  211. * Timer routines
  212. */
  213. __inline__ void
  214. qla2x00_start_timer(scsi_qla_host_t *vha, void *func, unsigned long interval)
  215. {
  216. init_timer(&vha->timer);
  217. vha->timer.expires = jiffies + interval * HZ;
  218. vha->timer.data = (unsigned long)vha;
  219. vha->timer.function = (void (*)(unsigned long))func;
  220. add_timer(&vha->timer);
  221. vha->timer_active = 1;
  222. }
  223. static inline void
  224. qla2x00_restart_timer(scsi_qla_host_t *vha, unsigned long interval)
  225. {
  226. /* Currently used for 82XX only. */
  227. if (vha->device_flags & DFLG_DEV_FAILED) {
  228. ql_dbg(ql_dbg_timer, vha, 0x600d,
  229. "Device in a failed state, returning.\n");
  230. return;
  231. }
  232. mod_timer(&vha->timer, jiffies + interval * HZ);
  233. }
  234. static __inline__ void
  235. qla2x00_stop_timer(scsi_qla_host_t *vha)
  236. {
  237. del_timer_sync(&vha->timer);
  238. vha->timer_active = 0;
  239. }
  240. static int qla2x00_do_dpc(void *data);
  241. static void qla2x00_rst_aen(scsi_qla_host_t *);
  242. static int qla2x00_mem_alloc(struct qla_hw_data *, uint16_t, uint16_t,
  243. struct req_que **, struct rsp_que **);
  244. static void qla2x00_free_fw_dump(struct qla_hw_data *);
  245. static void qla2x00_mem_free(struct qla_hw_data *);
  246. static void qla2x00_sp_free_dma(srb_t *);
  247. /* -------------------------------------------------------------------------- */
  248. static int qla2x00_alloc_queues(struct qla_hw_data *ha)
  249. {
  250. scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev);
  251. ha->req_q_map = kzalloc(sizeof(struct req_que *) * ha->max_req_queues,
  252. GFP_KERNEL);
  253. if (!ha->req_q_map) {
  254. ql_log(ql_log_fatal, vha, 0x003b,
  255. "Unable to allocate memory for request queue ptrs.\n");
  256. goto fail_req_map;
  257. }
  258. ha->rsp_q_map = kzalloc(sizeof(struct rsp_que *) * ha->max_rsp_queues,
  259. GFP_KERNEL);
  260. if (!ha->rsp_q_map) {
  261. ql_log(ql_log_fatal, vha, 0x003c,
  262. "Unable to allocate memory for response queue ptrs.\n");
  263. goto fail_rsp_map;
  264. }
  265. set_bit(0, ha->rsp_qid_map);
  266. set_bit(0, ha->req_qid_map);
  267. return 1;
  268. fail_rsp_map:
  269. kfree(ha->req_q_map);
  270. ha->req_q_map = NULL;
  271. fail_req_map:
  272. return -ENOMEM;
  273. }
  274. static void qla2x00_free_req_que(struct qla_hw_data *ha, struct req_que *req)
  275. {
  276. if (req && req->ring)
  277. dma_free_coherent(&ha->pdev->dev,
  278. (req->length + 1) * sizeof(request_t),
  279. req->ring, req->dma);
  280. kfree(req);
  281. req = NULL;
  282. }
  283. static void qla2x00_free_rsp_que(struct qla_hw_data *ha, struct rsp_que *rsp)
  284. {
  285. if (rsp && rsp->ring)
  286. dma_free_coherent(&ha->pdev->dev,
  287. (rsp->length + 1) * sizeof(response_t),
  288. rsp->ring, rsp->dma);
  289. kfree(rsp);
  290. rsp = NULL;
  291. }
  292. static void qla2x00_free_queues(struct qla_hw_data *ha)
  293. {
  294. struct req_que *req;
  295. struct rsp_que *rsp;
  296. int cnt;
  297. for (cnt = 0; cnt < ha->max_req_queues; cnt++) {
  298. req = ha->req_q_map[cnt];
  299. qla2x00_free_req_que(ha, req);
  300. }
  301. kfree(ha->req_q_map);
  302. ha->req_q_map = NULL;
  303. for (cnt = 0; cnt < ha->max_rsp_queues; cnt++) {
  304. rsp = ha->rsp_q_map[cnt];
  305. qla2x00_free_rsp_que(ha, rsp);
  306. }
  307. kfree(ha->rsp_q_map);
  308. ha->rsp_q_map = NULL;
  309. }
  310. static int qla25xx_setup_mode(struct scsi_qla_host *vha)
  311. {
  312. uint16_t options = 0;
  313. int ques, req, ret;
  314. struct qla_hw_data *ha = vha->hw;
  315. if (!(ha->fw_attributes & BIT_6)) {
  316. ql_log(ql_log_warn, vha, 0x00d8,
  317. "Firmware is not multi-queue capable.\n");
  318. goto fail;
  319. }
  320. if (ql2xmultique_tag) {
  321. /* create a request queue for IO */
  322. options |= BIT_7;
  323. req = qla25xx_create_req_que(ha, options, 0, 0, -1,
  324. QLA_DEFAULT_QUE_QOS);
  325. if (!req) {
  326. ql_log(ql_log_warn, vha, 0x00e0,
  327. "Failed to create request queue.\n");
  328. goto fail;
  329. }
  330. ha->wq = alloc_workqueue("qla2xxx_wq", WQ_MEM_RECLAIM, 1);
  331. vha->req = ha->req_q_map[req];
  332. options |= BIT_1;
  333. for (ques = 1; ques < ha->max_rsp_queues; ques++) {
  334. ret = qla25xx_create_rsp_que(ha, options, 0, 0, req);
  335. if (!ret) {
  336. ql_log(ql_log_warn, vha, 0x00e8,
  337. "Failed to create response queue.\n");
  338. goto fail2;
  339. }
  340. }
  341. ha->flags.cpu_affinity_enabled = 1;
  342. ql_dbg(ql_dbg_multiq, vha, 0xc007,
  343. "CPU affinity mode enalbed, "
  344. "no. of response queues:%d no. of request queues:%d.\n",
  345. ha->max_rsp_queues, ha->max_req_queues);
  346. ql_dbg(ql_dbg_init, vha, 0x00e9,
  347. "CPU affinity mode enalbed, "
  348. "no. of response queues:%d no. of request queues:%d.\n",
  349. ha->max_rsp_queues, ha->max_req_queues);
  350. }
  351. return 0;
  352. fail2:
  353. qla25xx_delete_queues(vha);
  354. destroy_workqueue(ha->wq);
  355. ha->wq = NULL;
  356. fail:
  357. ha->mqenable = 0;
  358. kfree(ha->req_q_map);
  359. kfree(ha->rsp_q_map);
  360. ha->max_req_queues = ha->max_rsp_queues = 1;
  361. return 1;
  362. }
  363. static char *
  364. qla2x00_pci_info_str(struct scsi_qla_host *vha, char *str)
  365. {
  366. struct qla_hw_data *ha = vha->hw;
  367. static char *pci_bus_modes[] = {
  368. "33", "66", "100", "133",
  369. };
  370. uint16_t pci_bus;
  371. strcpy(str, "PCI");
  372. pci_bus = (ha->pci_attr & (BIT_9 | BIT_10)) >> 9;
  373. if (pci_bus) {
  374. strcat(str, "-X (");
  375. strcat(str, pci_bus_modes[pci_bus]);
  376. } else {
  377. pci_bus = (ha->pci_attr & BIT_8) >> 8;
  378. strcat(str, " (");
  379. strcat(str, pci_bus_modes[pci_bus]);
  380. }
  381. strcat(str, " MHz)");
  382. return (str);
  383. }
  384. static char *
  385. qla24xx_pci_info_str(struct scsi_qla_host *vha, char *str)
  386. {
  387. static char *pci_bus_modes[] = { "33", "66", "100", "133", };
  388. struct qla_hw_data *ha = vha->hw;
  389. uint32_t pci_bus;
  390. int pcie_reg;
  391. pcie_reg = pci_find_capability(ha->pdev, PCI_CAP_ID_EXP);
  392. if (pcie_reg) {
  393. char lwstr[6];
  394. uint16_t pcie_lstat, lspeed, lwidth;
  395. pcie_reg += 0x12;
  396. pci_read_config_word(ha->pdev, pcie_reg, &pcie_lstat);
  397. lspeed = pcie_lstat & (BIT_0 | BIT_1 | BIT_2 | BIT_3);
  398. lwidth = (pcie_lstat &
  399. (BIT_4 | BIT_5 | BIT_6 | BIT_7 | BIT_8 | BIT_9)) >> 4;
  400. strcpy(str, "PCIe (");
  401. if (lspeed == 1)
  402. strcat(str, "2.5GT/s ");
  403. else if (lspeed == 2)
  404. strcat(str, "5.0GT/s ");
  405. else
  406. strcat(str, "<unknown> ");
  407. snprintf(lwstr, sizeof(lwstr), "x%d)", lwidth);
  408. strcat(str, lwstr);
  409. return str;
  410. }
  411. strcpy(str, "PCI");
  412. pci_bus = (ha->pci_attr & CSRX_PCIX_BUS_MODE_MASK) >> 8;
  413. if (pci_bus == 0 || pci_bus == 8) {
  414. strcat(str, " (");
  415. strcat(str, pci_bus_modes[pci_bus >> 3]);
  416. } else {
  417. strcat(str, "-X ");
  418. if (pci_bus & BIT_2)
  419. strcat(str, "Mode 2");
  420. else
  421. strcat(str, "Mode 1");
  422. strcat(str, " (");
  423. strcat(str, pci_bus_modes[pci_bus & ~BIT_2]);
  424. }
  425. strcat(str, " MHz)");
  426. return str;
  427. }
  428. static char *
  429. qla2x00_fw_version_str(struct scsi_qla_host *vha, char *str)
  430. {
  431. char un_str[10];
  432. struct qla_hw_data *ha = vha->hw;
  433. sprintf(str, "%d.%02d.%02d ", ha->fw_major_version,
  434. ha->fw_minor_version,
  435. ha->fw_subminor_version);
  436. if (ha->fw_attributes & BIT_9) {
  437. strcat(str, "FLX");
  438. return (str);
  439. }
  440. switch (ha->fw_attributes & 0xFF) {
  441. case 0x7:
  442. strcat(str, "EF");
  443. break;
  444. case 0x17:
  445. strcat(str, "TP");
  446. break;
  447. case 0x37:
  448. strcat(str, "IP");
  449. break;
  450. case 0x77:
  451. strcat(str, "VI");
  452. break;
  453. default:
  454. sprintf(un_str, "(%x)", ha->fw_attributes);
  455. strcat(str, un_str);
  456. break;
  457. }
  458. if (ha->fw_attributes & 0x100)
  459. strcat(str, "X");
  460. return (str);
  461. }
  462. static char *
  463. qla24xx_fw_version_str(struct scsi_qla_host *vha, char *str)
  464. {
  465. struct qla_hw_data *ha = vha->hw;
  466. sprintf(str, "%d.%02d.%02d (%x)", ha->fw_major_version,
  467. ha->fw_minor_version, ha->fw_subminor_version, ha->fw_attributes);
  468. return str;
  469. }
  470. static inline srb_t *
  471. qla2x00_get_new_sp(scsi_qla_host_t *vha, fc_port_t *fcport,
  472. struct scsi_cmnd *cmd)
  473. {
  474. srb_t *sp;
  475. struct qla_hw_data *ha = vha->hw;
  476. sp = mempool_alloc(ha->srb_mempool, GFP_ATOMIC);
  477. if (!sp) {
  478. ql_log(ql_log_warn, vha, 0x3006,
  479. "Memory allocation failed for sp.\n");
  480. return sp;
  481. }
  482. atomic_set(&sp->ref_count, 1);
  483. sp->fcport = fcport;
  484. sp->cmd = cmd;
  485. sp->flags = 0;
  486. CMD_SP(cmd) = (void *)sp;
  487. sp->ctx = NULL;
  488. return sp;
  489. }
  490. static int
  491. qla2xxx_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd)
  492. {
  493. scsi_qla_host_t *vha = shost_priv(host);
  494. fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
  495. struct fc_rport *rport = starget_to_rport(scsi_target(cmd->device));
  496. struct qla_hw_data *ha = vha->hw;
  497. struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
  498. srb_t *sp;
  499. int rval;
  500. if (ha->flags.eeh_busy) {
  501. if (ha->flags.pci_channel_io_perm_failure) {
  502. ql_dbg(ql_dbg_io, vha, 0x3001,
  503. "PCI Channel IO permanent failure, exiting "
  504. "cmd=%p.\n", cmd);
  505. cmd->result = DID_NO_CONNECT << 16;
  506. } else {
  507. ql_dbg(ql_dbg_io, vha, 0x3002,
  508. "EEH_Busy, Requeuing the cmd=%p.\n", cmd);
  509. cmd->result = DID_REQUEUE << 16;
  510. }
  511. goto qc24_fail_command;
  512. }
  513. rval = fc_remote_port_chkready(rport);
  514. if (rval) {
  515. cmd->result = rval;
  516. ql_dbg(ql_dbg_io, vha, 0x3003,
  517. "fc_remote_port_chkready failed for cmd=%p, rval=0x%x.\n",
  518. cmd, rval);
  519. goto qc24_fail_command;
  520. }
  521. if (!vha->flags.difdix_supported &&
  522. scsi_get_prot_op(cmd) != SCSI_PROT_NORMAL) {
  523. ql_dbg(ql_dbg_io, vha, 0x3004,
  524. "DIF Cap not reg, fail DIF capable cmd's:%p.\n",
  525. cmd);
  526. cmd->result = DID_NO_CONNECT << 16;
  527. goto qc24_fail_command;
  528. }
  529. if (atomic_read(&fcport->state) != FCS_ONLINE) {
  530. if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
  531. atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
  532. ql_dbg(ql_dbg_io, vha, 0x3005,
  533. "Returning DNC, fcport_state=%d loop_state=%d.\n",
  534. atomic_read(&fcport->state),
  535. atomic_read(&base_vha->loop_state));
  536. cmd->result = DID_NO_CONNECT << 16;
  537. goto qc24_fail_command;
  538. }
  539. goto qc24_target_busy;
  540. }
  541. sp = qla2x00_get_new_sp(base_vha, fcport, cmd);
  542. if (!sp)
  543. goto qc24_host_busy;
  544. rval = ha->isp_ops->start_scsi(sp);
  545. if (rval != QLA_SUCCESS) {
  546. ql_dbg(ql_dbg_io, vha, 0x3013,
  547. "Start scsi failed rval=%d for cmd=%p.\n", rval, cmd);
  548. goto qc24_host_busy_free_sp;
  549. }
  550. return 0;
  551. qc24_host_busy_free_sp:
  552. qla2x00_sp_free_dma(sp);
  553. mempool_free(sp, ha->srb_mempool);
  554. qc24_host_busy:
  555. return SCSI_MLQUEUE_HOST_BUSY;
  556. qc24_target_busy:
  557. return SCSI_MLQUEUE_TARGET_BUSY;
  558. qc24_fail_command:
  559. cmd->scsi_done(cmd);
  560. return 0;
  561. }
  562. /*
  563. * qla2x00_eh_wait_on_command
  564. * Waits for the command to be returned by the Firmware for some
  565. * max time.
  566. *
  567. * Input:
  568. * cmd = Scsi Command to wait on.
  569. *
  570. * Return:
  571. * Not Found : 0
  572. * Found : 1
  573. */
  574. static int
  575. qla2x00_eh_wait_on_command(struct scsi_cmnd *cmd)
  576. {
  577. #define ABORT_POLLING_PERIOD 1000
  578. #define ABORT_WAIT_ITER ((10 * 1000) / (ABORT_POLLING_PERIOD))
  579. unsigned long wait_iter = ABORT_WAIT_ITER;
  580. scsi_qla_host_t *vha = shost_priv(cmd->device->host);
  581. struct qla_hw_data *ha = vha->hw;
  582. int ret = QLA_SUCCESS;
  583. if (unlikely(pci_channel_offline(ha->pdev)) || ha->flags.eeh_busy) {
  584. ql_dbg(ql_dbg_taskm, vha, 0x8005,
  585. "Return:eh_wait.\n");
  586. return ret;
  587. }
  588. while (CMD_SP(cmd) && wait_iter--) {
  589. msleep(ABORT_POLLING_PERIOD);
  590. }
  591. if (CMD_SP(cmd))
  592. ret = QLA_FUNCTION_FAILED;
  593. return ret;
  594. }
  595. /*
  596. * qla2x00_wait_for_hba_online
  597. * Wait till the HBA is online after going through
  598. * <= MAX_RETRIES_OF_ISP_ABORT or
  599. * finally HBA is disabled ie marked offline
  600. *
  601. * Input:
  602. * ha - pointer to host adapter structure
  603. *
  604. * Note:
  605. * Does context switching-Release SPIN_LOCK
  606. * (if any) before calling this routine.
  607. *
  608. * Return:
  609. * Success (Adapter is online) : 0
  610. * Failed (Adapter is offline/disabled) : 1
  611. */
  612. int
  613. qla2x00_wait_for_hba_online(scsi_qla_host_t *vha)
  614. {
  615. int return_status;
  616. unsigned long wait_online;
  617. struct qla_hw_data *ha = vha->hw;
  618. scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
  619. wait_online = jiffies + (MAX_LOOP_TIMEOUT * HZ);
  620. while (((test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) ||
  621. test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) ||
  622. test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) ||
  623. ha->dpc_active) && time_before(jiffies, wait_online)) {
  624. msleep(1000);
  625. }
  626. if (base_vha->flags.online)
  627. return_status = QLA_SUCCESS;
  628. else
  629. return_status = QLA_FUNCTION_FAILED;
  630. return (return_status);
  631. }
  632. /*
  633. * qla2x00_wait_for_reset_ready
  634. * Wait till the HBA is online after going through
  635. * <= MAX_RETRIES_OF_ISP_ABORT or
  636. * finally HBA is disabled ie marked offline or flash
  637. * operations are in progress.
  638. *
  639. * Input:
  640. * ha - pointer to host adapter structure
  641. *
  642. * Note:
  643. * Does context switching-Release SPIN_LOCK
  644. * (if any) before calling this routine.
  645. *
  646. * Return:
  647. * Success (Adapter is online/no flash ops) : 0
  648. * Failed (Adapter is offline/disabled/flash ops in progress) : 1
  649. */
  650. static int
  651. qla2x00_wait_for_reset_ready(scsi_qla_host_t *vha)
  652. {
  653. int return_status;
  654. unsigned long wait_online;
  655. struct qla_hw_data *ha = vha->hw;
  656. scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
  657. wait_online = jiffies + (MAX_LOOP_TIMEOUT * HZ);
  658. while (((test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) ||
  659. test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) ||
  660. test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) ||
  661. ha->optrom_state != QLA_SWAITING ||
  662. ha->dpc_active) && time_before(jiffies, wait_online))
  663. msleep(1000);
  664. if (base_vha->flags.online && ha->optrom_state == QLA_SWAITING)
  665. return_status = QLA_SUCCESS;
  666. else
  667. return_status = QLA_FUNCTION_FAILED;
  668. ql_dbg(ql_dbg_taskm, vha, 0x8019,
  669. "%s return status=%d.\n", __func__, return_status);
  670. return return_status;
  671. }
  672. int
  673. qla2x00_wait_for_chip_reset(scsi_qla_host_t *vha)
  674. {
  675. int return_status;
  676. unsigned long wait_reset;
  677. struct qla_hw_data *ha = vha->hw;
  678. scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
  679. wait_reset = jiffies + (MAX_LOOP_TIMEOUT * HZ);
  680. while (((test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) ||
  681. test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) ||
  682. test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) ||
  683. ha->dpc_active) && time_before(jiffies, wait_reset)) {
  684. msleep(1000);
  685. if (!test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags) &&
  686. ha->flags.chip_reset_done)
  687. break;
  688. }
  689. if (ha->flags.chip_reset_done)
  690. return_status = QLA_SUCCESS;
  691. else
  692. return_status = QLA_FUNCTION_FAILED;
  693. return return_status;
  694. }
  695. /*
  696. * qla2x00_wait_for_loop_ready
  697. * Wait for MAX_LOOP_TIMEOUT(5 min) value for loop
  698. * to be in LOOP_READY state.
  699. * Input:
  700. * ha - pointer to host adapter structure
  701. *
  702. * Note:
  703. * Does context switching-Release SPIN_LOCK
  704. * (if any) before calling this routine.
  705. *
  706. *
  707. * Return:
  708. * Success (LOOP_READY) : 0
  709. * Failed (LOOP_NOT_READY) : 1
  710. */
  711. static inline int
  712. qla2x00_wait_for_loop_ready(scsi_qla_host_t *vha)
  713. {
  714. int return_status = QLA_SUCCESS;
  715. unsigned long loop_timeout ;
  716. struct qla_hw_data *ha = vha->hw;
  717. scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
  718. /* wait for 5 min at the max for loop to be ready */
  719. loop_timeout = jiffies + (MAX_LOOP_TIMEOUT * HZ);
  720. while ((!atomic_read(&base_vha->loop_down_timer) &&
  721. atomic_read(&base_vha->loop_state) == LOOP_DOWN) ||
  722. atomic_read(&base_vha->loop_state) != LOOP_READY) {
  723. if (atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
  724. return_status = QLA_FUNCTION_FAILED;
  725. break;
  726. }
  727. msleep(1000);
  728. if (time_after_eq(jiffies, loop_timeout)) {
  729. return_status = QLA_FUNCTION_FAILED;
  730. break;
  731. }
  732. }
  733. return (return_status);
  734. }
  735. static void
  736. sp_get(struct srb *sp)
  737. {
  738. atomic_inc(&sp->ref_count);
  739. }
  740. /**************************************************************************
  741. * qla2xxx_eh_abort
  742. *
  743. * Description:
  744. * The abort function will abort the specified command.
  745. *
  746. * Input:
  747. * cmd = Linux SCSI command packet to be aborted.
  748. *
  749. * Returns:
  750. * Either SUCCESS or FAILED.
  751. *
  752. * Note:
  753. * Only return FAILED if command not returned by firmware.
  754. **************************************************************************/
  755. static int
  756. qla2xxx_eh_abort(struct scsi_cmnd *cmd)
  757. {
  758. scsi_qla_host_t *vha = shost_priv(cmd->device->host);
  759. srb_t *sp;
  760. int ret;
  761. unsigned int id, lun;
  762. unsigned long flags;
  763. int wait = 0;
  764. struct qla_hw_data *ha = vha->hw;
  765. ql_dbg(ql_dbg_taskm, vha, 0x8000,
  766. "Entered %s for cmd=%p.\n", __func__, cmd);
  767. if (!CMD_SP(cmd))
  768. return SUCCESS;
  769. ret = fc_block_scsi_eh(cmd);
  770. ql_dbg(ql_dbg_taskm, vha, 0x8001,
  771. "Return value of fc_block_scsi_eh=%d.\n", ret);
  772. if (ret != 0)
  773. return ret;
  774. ret = SUCCESS;
  775. id = cmd->device->id;
  776. lun = cmd->device->lun;
  777. spin_lock_irqsave(&ha->hardware_lock, flags);
  778. sp = (srb_t *) CMD_SP(cmd);
  779. if (!sp) {
  780. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  781. return SUCCESS;
  782. }
  783. ql_dbg(ql_dbg_taskm, vha, 0x8002,
  784. "Aborting sp=%p cmd=%p from RISC ", sp, cmd);
  785. /* Get a reference to the sp and drop the lock.*/
  786. sp_get(sp);
  787. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  788. if (ha->isp_ops->abort_command(sp)) {
  789. ql_dbg(ql_dbg_taskm, vha, 0x8003,
  790. "Abort command mbx failed for cmd=%p.\n", cmd);
  791. } else {
  792. ql_dbg(ql_dbg_taskm, vha, 0x8004,
  793. "Abort command mbx success.\n");
  794. wait = 1;
  795. }
  796. spin_lock_irqsave(&ha->hardware_lock, flags);
  797. qla2x00_sp_compl(ha, sp);
  798. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  799. /* Did the command return during mailbox execution? */
  800. if (ret == FAILED && !CMD_SP(cmd))
  801. ret = SUCCESS;
  802. /* Wait for the command to be returned. */
  803. if (wait) {
  804. if (qla2x00_eh_wait_on_command(cmd) != QLA_SUCCESS) {
  805. ql_log(ql_log_warn, vha, 0x8006,
  806. "Abort handler timed out for cmd=%p.\n", cmd);
  807. ret = FAILED;
  808. }
  809. }
  810. ql_log(ql_log_info, vha, 0x801c,
  811. "Abort command issued -- %d %x.\n", wait, ret);
  812. return ret;
  813. }
  814. int
  815. qla2x00_eh_wait_for_pending_commands(scsi_qla_host_t *vha, unsigned int t,
  816. unsigned int l, enum nexus_wait_type type)
  817. {
  818. int cnt, match, status;
  819. unsigned long flags;
  820. struct qla_hw_data *ha = vha->hw;
  821. struct req_que *req;
  822. srb_t *sp;
  823. status = QLA_SUCCESS;
  824. spin_lock_irqsave(&ha->hardware_lock, flags);
  825. req = vha->req;
  826. for (cnt = 1; status == QLA_SUCCESS &&
  827. cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
  828. sp = req->outstanding_cmds[cnt];
  829. if (!sp)
  830. continue;
  831. if ((sp->ctx) && !IS_PROT_IO(sp))
  832. continue;
  833. if (vha->vp_idx != sp->fcport->vha->vp_idx)
  834. continue;
  835. match = 0;
  836. switch (type) {
  837. case WAIT_HOST:
  838. match = 1;
  839. break;
  840. case WAIT_TARGET:
  841. match = sp->cmd->device->id == t;
  842. break;
  843. case WAIT_LUN:
  844. match = (sp->cmd->device->id == t &&
  845. sp->cmd->device->lun == l);
  846. break;
  847. }
  848. if (!match)
  849. continue;
  850. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  851. status = qla2x00_eh_wait_on_command(sp->cmd);
  852. spin_lock_irqsave(&ha->hardware_lock, flags);
  853. }
  854. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  855. return status;
  856. }
  857. static char *reset_errors[] = {
  858. "HBA not online",
  859. "HBA not ready",
  860. "Task management failed",
  861. "Waiting for command completions",
  862. };
  863. static int
  864. __qla2xxx_eh_generic_reset(char *name, enum nexus_wait_type type,
  865. struct scsi_cmnd *cmd, int (*do_reset)(struct fc_port *, unsigned int, int))
  866. {
  867. scsi_qla_host_t *vha = shost_priv(cmd->device->host);
  868. fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
  869. int err;
  870. if (!fcport) {
  871. ql_log(ql_log_warn, vha, 0x8007,
  872. "fcport is NULL.\n");
  873. return FAILED;
  874. }
  875. err = fc_block_scsi_eh(cmd);
  876. ql_dbg(ql_dbg_taskm, vha, 0x8008,
  877. "fc_block_scsi_eh ret=%d.\n", err);
  878. if (err != 0)
  879. return err;
  880. ql_log(ql_log_info, vha, 0x8009,
  881. "%s RESET ISSUED for id %d lun %d cmd=%p.\n", name,
  882. cmd->device->id, cmd->device->lun, cmd);
  883. err = 0;
  884. if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
  885. ql_log(ql_log_warn, vha, 0x800a,
  886. "Wait for hba online failed for cmd=%p.\n", cmd);
  887. goto eh_reset_failed;
  888. }
  889. err = 1;
  890. if (qla2x00_wait_for_loop_ready(vha) != QLA_SUCCESS) {
  891. ql_log(ql_log_warn, vha, 0x800b,
  892. "Wait for loop ready failed for cmd=%p.\n", cmd);
  893. goto eh_reset_failed;
  894. }
  895. err = 2;
  896. if (do_reset(fcport, cmd->device->lun, cmd->request->cpu + 1)
  897. != QLA_SUCCESS) {
  898. ql_log(ql_log_warn, vha, 0x800c,
  899. "do_reset failed for cmd=%p.\n", cmd);
  900. goto eh_reset_failed;
  901. }
  902. err = 3;
  903. if (qla2x00_eh_wait_for_pending_commands(vha, cmd->device->id,
  904. cmd->device->lun, type) != QLA_SUCCESS) {
  905. ql_log(ql_log_warn, vha, 0x800d,
  906. "wait for peding cmds failed for cmd=%p.\n", cmd);
  907. goto eh_reset_failed;
  908. }
  909. ql_log(ql_log_info, vha, 0x800e,
  910. "%s RESET SUCCEEDED for id %d lun %d cmd=%p.\n", name,
  911. cmd->device->id, cmd->device->lun, cmd);
  912. return SUCCESS;
  913. eh_reset_failed:
  914. ql_log(ql_log_info, vha, 0x800f,
  915. "%s RESET FAILED: %s for id %d lun %d cmd=%p.\n", name,
  916. reset_errors[err], cmd->device->id, cmd->device->lun);
  917. return FAILED;
  918. }
  919. static int
  920. qla2xxx_eh_device_reset(struct scsi_cmnd *cmd)
  921. {
  922. scsi_qla_host_t *vha = shost_priv(cmd->device->host);
  923. struct qla_hw_data *ha = vha->hw;
  924. return __qla2xxx_eh_generic_reset("DEVICE", WAIT_LUN, cmd,
  925. ha->isp_ops->lun_reset);
  926. }
  927. static int
  928. qla2xxx_eh_target_reset(struct scsi_cmnd *cmd)
  929. {
  930. scsi_qla_host_t *vha = shost_priv(cmd->device->host);
  931. struct qla_hw_data *ha = vha->hw;
  932. return __qla2xxx_eh_generic_reset("TARGET", WAIT_TARGET, cmd,
  933. ha->isp_ops->target_reset);
  934. }
  935. /**************************************************************************
  936. * qla2xxx_eh_bus_reset
  937. *
  938. * Description:
  939. * The bus reset function will reset the bus and abort any executing
  940. * commands.
  941. *
  942. * Input:
  943. * cmd = Linux SCSI command packet of the command that cause the
  944. * bus reset.
  945. *
  946. * Returns:
  947. * SUCCESS/FAILURE (defined as macro in scsi.h).
  948. *
  949. **************************************************************************/
  950. static int
  951. qla2xxx_eh_bus_reset(struct scsi_cmnd *cmd)
  952. {
  953. scsi_qla_host_t *vha = shost_priv(cmd->device->host);
  954. fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
  955. int ret = FAILED;
  956. unsigned int id, lun;
  957. id = cmd->device->id;
  958. lun = cmd->device->lun;
  959. if (!fcport) {
  960. ql_log(ql_log_warn, vha, 0x8010,
  961. "fcport is NULL.\n");
  962. return ret;
  963. }
  964. ret = fc_block_scsi_eh(cmd);
  965. ql_dbg(ql_dbg_taskm, vha, 0x8011,
  966. "fc_block_scsi_eh ret=%d.\n", ret);
  967. if (ret != 0)
  968. return ret;
  969. ret = FAILED;
  970. ql_log(ql_log_info, vha, 0x8012,
  971. "BUS RESET ISSUED for id %d lun %d.\n", id, lun);
  972. if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
  973. ql_log(ql_log_fatal, vha, 0x8013,
  974. "Wait for hba online failed board disabled.\n");
  975. goto eh_bus_reset_done;
  976. }
  977. if (qla2x00_wait_for_loop_ready(vha) == QLA_SUCCESS) {
  978. if (qla2x00_loop_reset(vha) == QLA_SUCCESS)
  979. ret = SUCCESS;
  980. }
  981. if (ret == FAILED)
  982. goto eh_bus_reset_done;
  983. /* Flush outstanding commands. */
  984. if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST) !=
  985. QLA_SUCCESS) {
  986. ql_log(ql_log_warn, vha, 0x8014,
  987. "Wait for pending commands failed.\n");
  988. ret = FAILED;
  989. }
  990. eh_bus_reset_done:
  991. ql_log(ql_log_warn, vha, 0x802b,
  992. "BUS RESET %s.\n", (ret == FAILED) ? "FAILED" : "SUCCEDED");
  993. return ret;
  994. }
  995. /**************************************************************************
  996. * qla2xxx_eh_host_reset
  997. *
  998. * Description:
  999. * The reset function will reset the Adapter.
  1000. *
  1001. * Input:
  1002. * cmd = Linux SCSI command packet of the command that cause the
  1003. * adapter reset.
  1004. *
  1005. * Returns:
  1006. * Either SUCCESS or FAILED.
  1007. *
  1008. * Note:
  1009. **************************************************************************/
  1010. static int
  1011. qla2xxx_eh_host_reset(struct scsi_cmnd *cmd)
  1012. {
  1013. scsi_qla_host_t *vha = shost_priv(cmd->device->host);
  1014. fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
  1015. struct qla_hw_data *ha = vha->hw;
  1016. int ret = FAILED;
  1017. unsigned int id, lun;
  1018. scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
  1019. id = cmd->device->id;
  1020. lun = cmd->device->lun;
  1021. if (!fcport) {
  1022. ql_log(ql_log_warn, vha, 0x8016,
  1023. "fcport is NULL.\n");
  1024. return ret;
  1025. }
  1026. ret = fc_block_scsi_eh(cmd);
  1027. ql_dbg(ql_dbg_taskm, vha, 0x8017,
  1028. "fc_block_scsi_eh ret=%d.\n", ret);
  1029. if (ret != 0)
  1030. return ret;
  1031. ret = FAILED;
  1032. ql_log(ql_log_info, vha, 0x8018,
  1033. "ADAPTER RESET ISSUED for id %d lun %d.\n", id, lun);
  1034. if (qla2x00_wait_for_reset_ready(vha) != QLA_SUCCESS)
  1035. goto eh_host_reset_lock;
  1036. /*
  1037. * Fixme-may be dpc thread is active and processing
  1038. * loop_resync,so wait a while for it to
  1039. * be completed and then issue big hammer.Otherwise
  1040. * it may cause I/O failure as big hammer marks the
  1041. * devices as lost kicking of the port_down_timer
  1042. * while dpc is stuck for the mailbox to complete.
  1043. */
  1044. qla2x00_wait_for_loop_ready(vha);
  1045. if (vha != base_vha) {
  1046. if (qla2x00_vp_abort_isp(vha))
  1047. goto eh_host_reset_lock;
  1048. } else {
  1049. if (IS_QLA82XX(vha->hw)) {
  1050. if (!qla82xx_fcoe_ctx_reset(vha)) {
  1051. /* Ctx reset success */
  1052. ret = SUCCESS;
  1053. goto eh_host_reset_lock;
  1054. }
  1055. /* fall thru if ctx reset failed */
  1056. }
  1057. if (ha->wq)
  1058. flush_workqueue(ha->wq);
  1059. set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
  1060. if (ha->isp_ops->abort_isp(base_vha)) {
  1061. clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
  1062. /* failed. schedule dpc to try */
  1063. set_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags);
  1064. if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
  1065. ql_log(ql_log_warn, vha, 0x802a,
  1066. "wait for hba online failed.\n");
  1067. goto eh_host_reset_lock;
  1068. }
  1069. }
  1070. clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
  1071. }
  1072. /* Waiting for command to be returned to OS.*/
  1073. if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST) ==
  1074. QLA_SUCCESS)
  1075. ret = SUCCESS;
  1076. eh_host_reset_lock:
  1077. qla_printk(KERN_INFO, ha, "%s: reset %s.\n", __func__,
  1078. (ret == FAILED) ? "failed" : "succeeded");
  1079. return ret;
  1080. }
  1081. /*
  1082. * qla2x00_loop_reset
  1083. * Issue loop reset.
  1084. *
  1085. * Input:
  1086. * ha = adapter block pointer.
  1087. *
  1088. * Returns:
  1089. * 0 = success
  1090. */
  1091. int
  1092. qla2x00_loop_reset(scsi_qla_host_t *vha)
  1093. {
  1094. int ret;
  1095. struct fc_port *fcport;
  1096. struct qla_hw_data *ha = vha->hw;
  1097. if (ql2xtargetreset == 1 && ha->flags.enable_target_reset) {
  1098. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  1099. if (fcport->port_type != FCT_TARGET)
  1100. continue;
  1101. ret = ha->isp_ops->target_reset(fcport, 0, 0);
  1102. if (ret != QLA_SUCCESS) {
  1103. ql_dbg(ql_dbg_taskm, vha, 0x802c,
  1104. "Bus Reset failed: Target Reset=%d "
  1105. "d_id=%x.\n", ret, fcport->d_id.b24);
  1106. }
  1107. }
  1108. }
  1109. if (ha->flags.enable_lip_full_login && !IS_QLA8XXX_TYPE(ha)) {
  1110. ret = qla2x00_full_login_lip(vha);
  1111. if (ret != QLA_SUCCESS) {
  1112. ql_dbg(ql_dbg_taskm, vha, 0x802d,
  1113. "full_login_lip=%d.\n", ret);
  1114. }
  1115. atomic_set(&vha->loop_state, LOOP_DOWN);
  1116. atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
  1117. qla2x00_mark_all_devices_lost(vha, 0);
  1118. qla2x00_wait_for_loop_ready(vha);
  1119. }
  1120. if (ha->flags.enable_lip_reset) {
  1121. ret = qla2x00_lip_reset(vha);
  1122. if (ret != QLA_SUCCESS) {
  1123. ql_dbg(ql_dbg_taskm, vha, 0x802e,
  1124. "lip_reset failed (%d).\n", ret);
  1125. } else
  1126. qla2x00_wait_for_loop_ready(vha);
  1127. }
  1128. /* Issue marker command only when we are going to start the I/O */
  1129. vha->marker_needed = 1;
  1130. return QLA_SUCCESS;
  1131. }
  1132. void
  1133. qla2x00_abort_all_cmds(scsi_qla_host_t *vha, int res)
  1134. {
  1135. int que, cnt;
  1136. unsigned long flags;
  1137. srb_t *sp;
  1138. struct srb_ctx *ctx;
  1139. struct qla_hw_data *ha = vha->hw;
  1140. struct req_que *req;
  1141. spin_lock_irqsave(&ha->hardware_lock, flags);
  1142. for (que = 0; que < ha->max_req_queues; que++) {
  1143. req = ha->req_q_map[que];
  1144. if (!req)
  1145. continue;
  1146. for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
  1147. sp = req->outstanding_cmds[cnt];
  1148. if (sp) {
  1149. req->outstanding_cmds[cnt] = NULL;
  1150. if (!sp->ctx ||
  1151. (sp->flags & SRB_FCP_CMND_DMA_VALID) ||
  1152. IS_PROT_IO(sp)) {
  1153. sp->cmd->result = res;
  1154. qla2x00_sp_compl(ha, sp);
  1155. } else {
  1156. ctx = sp->ctx;
  1157. if (ctx->type == SRB_LOGIN_CMD ||
  1158. ctx->type == SRB_LOGOUT_CMD) {
  1159. ctx->u.iocb_cmd->free(sp);
  1160. } else {
  1161. struct fc_bsg_job *bsg_job =
  1162. ctx->u.bsg_job;
  1163. if (bsg_job->request->msgcode
  1164. == FC_BSG_HST_CT)
  1165. kfree(sp->fcport);
  1166. bsg_job->req->errors = 0;
  1167. bsg_job->reply->result = res;
  1168. bsg_job->job_done(bsg_job);
  1169. kfree(sp->ctx);
  1170. mempool_free(sp,
  1171. ha->srb_mempool);
  1172. }
  1173. }
  1174. }
  1175. }
  1176. }
  1177. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1178. }
  1179. static int
  1180. qla2xxx_slave_alloc(struct scsi_device *sdev)
  1181. {
  1182. struct fc_rport *rport = starget_to_rport(scsi_target(sdev));
  1183. if (!rport || fc_remote_port_chkready(rport))
  1184. return -ENXIO;
  1185. sdev->hostdata = *(fc_port_t **)rport->dd_data;
  1186. return 0;
  1187. }
  1188. static int
  1189. qla2xxx_slave_configure(struct scsi_device *sdev)
  1190. {
  1191. scsi_qla_host_t *vha = shost_priv(sdev->host);
  1192. struct req_que *req = vha->req;
  1193. if (sdev->tagged_supported)
  1194. scsi_activate_tcq(sdev, req->max_q_depth);
  1195. else
  1196. scsi_deactivate_tcq(sdev, req->max_q_depth);
  1197. return 0;
  1198. }
  1199. static void
  1200. qla2xxx_slave_destroy(struct scsi_device *sdev)
  1201. {
  1202. sdev->hostdata = NULL;
  1203. }
  1204. static void qla2x00_handle_queue_full(struct scsi_device *sdev, int qdepth)
  1205. {
  1206. fc_port_t *fcport = (struct fc_port *) sdev->hostdata;
  1207. if (!scsi_track_queue_full(sdev, qdepth))
  1208. return;
  1209. ql_dbg(ql_dbg_io, fcport->vha, 0x3029,
  1210. "Queue depth adjusted-down "
  1211. "to %d for scsi(%ld:%d:%d:%d).\n",
  1212. sdev->queue_depth, fcport->vha->host_no,
  1213. sdev->channel, sdev->id, sdev->lun);
  1214. }
  1215. static void qla2x00_adjust_sdev_qdepth_up(struct scsi_device *sdev, int qdepth)
  1216. {
  1217. fc_port_t *fcport = sdev->hostdata;
  1218. struct scsi_qla_host *vha = fcport->vha;
  1219. struct req_que *req = NULL;
  1220. req = vha->req;
  1221. if (!req)
  1222. return;
  1223. if (req->max_q_depth <= sdev->queue_depth || req->max_q_depth < qdepth)
  1224. return;
  1225. if (sdev->ordered_tags)
  1226. scsi_adjust_queue_depth(sdev, MSG_ORDERED_TAG, qdepth);
  1227. else
  1228. scsi_adjust_queue_depth(sdev, MSG_SIMPLE_TAG, qdepth);
  1229. ql_dbg(ql_dbg_io, vha, 0x302a,
  1230. "Queue depth adjusted-up to %d for "
  1231. "scsi(%ld:%d:%d:%d).\n",
  1232. sdev->queue_depth, fcport->vha->host_no,
  1233. sdev->channel, sdev->id, sdev->lun);
  1234. }
  1235. static int
  1236. qla2x00_change_queue_depth(struct scsi_device *sdev, int qdepth, int reason)
  1237. {
  1238. switch (reason) {
  1239. case SCSI_QDEPTH_DEFAULT:
  1240. scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), qdepth);
  1241. break;
  1242. case SCSI_QDEPTH_QFULL:
  1243. qla2x00_handle_queue_full(sdev, qdepth);
  1244. break;
  1245. case SCSI_QDEPTH_RAMP_UP:
  1246. qla2x00_adjust_sdev_qdepth_up(sdev, qdepth);
  1247. break;
  1248. default:
  1249. return -EOPNOTSUPP;
  1250. }
  1251. return sdev->queue_depth;
  1252. }
  1253. static int
  1254. qla2x00_change_queue_type(struct scsi_device *sdev, int tag_type)
  1255. {
  1256. if (sdev->tagged_supported) {
  1257. scsi_set_tag_type(sdev, tag_type);
  1258. if (tag_type)
  1259. scsi_activate_tcq(sdev, sdev->queue_depth);
  1260. else
  1261. scsi_deactivate_tcq(sdev, sdev->queue_depth);
  1262. } else
  1263. tag_type = 0;
  1264. return tag_type;
  1265. }
  1266. /**
  1267. * qla2x00_config_dma_addressing() - Configure OS DMA addressing method.
  1268. * @ha: HA context
  1269. *
  1270. * At exit, the @ha's flags.enable_64bit_addressing set to indicated
  1271. * supported addressing method.
  1272. */
  1273. static void
  1274. qla2x00_config_dma_addressing(struct qla_hw_data *ha)
  1275. {
  1276. /* Assume a 32bit DMA mask. */
  1277. ha->flags.enable_64bit_addressing = 0;
  1278. if (!dma_set_mask(&ha->pdev->dev, DMA_BIT_MASK(64))) {
  1279. /* Any upper-dword bits set? */
  1280. if (MSD(dma_get_required_mask(&ha->pdev->dev)) &&
  1281. !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
  1282. /* Ok, a 64bit DMA mask is applicable. */
  1283. ha->flags.enable_64bit_addressing = 1;
  1284. ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
  1285. ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
  1286. return;
  1287. }
  1288. }
  1289. dma_set_mask(&ha->pdev->dev, DMA_BIT_MASK(32));
  1290. pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(32));
  1291. }
  1292. static void
  1293. qla2x00_enable_intrs(struct qla_hw_data *ha)
  1294. {
  1295. unsigned long flags = 0;
  1296. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  1297. spin_lock_irqsave(&ha->hardware_lock, flags);
  1298. ha->interrupts_on = 1;
  1299. /* enable risc and host interrupts */
  1300. WRT_REG_WORD(&reg->ictrl, ICR_EN_INT | ICR_EN_RISC);
  1301. RD_REG_WORD(&reg->ictrl);
  1302. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1303. }
  1304. static void
  1305. qla2x00_disable_intrs(struct qla_hw_data *ha)
  1306. {
  1307. unsigned long flags = 0;
  1308. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  1309. spin_lock_irqsave(&ha->hardware_lock, flags);
  1310. ha->interrupts_on = 0;
  1311. /* disable risc and host interrupts */
  1312. WRT_REG_WORD(&reg->ictrl, 0);
  1313. RD_REG_WORD(&reg->ictrl);
  1314. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1315. }
  1316. static void
  1317. qla24xx_enable_intrs(struct qla_hw_data *ha)
  1318. {
  1319. unsigned long flags = 0;
  1320. struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
  1321. spin_lock_irqsave(&ha->hardware_lock, flags);
  1322. ha->interrupts_on = 1;
  1323. WRT_REG_DWORD(&reg->ictrl, ICRX_EN_RISC_INT);
  1324. RD_REG_DWORD(&reg->ictrl);
  1325. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1326. }
  1327. static void
  1328. qla24xx_disable_intrs(struct qla_hw_data *ha)
  1329. {
  1330. unsigned long flags = 0;
  1331. struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
  1332. if (IS_NOPOLLING_TYPE(ha))
  1333. return;
  1334. spin_lock_irqsave(&ha->hardware_lock, flags);
  1335. ha->interrupts_on = 0;
  1336. WRT_REG_DWORD(&reg->ictrl, 0);
  1337. RD_REG_DWORD(&reg->ictrl);
  1338. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1339. }
  1340. static struct isp_operations qla2100_isp_ops = {
  1341. .pci_config = qla2100_pci_config,
  1342. .reset_chip = qla2x00_reset_chip,
  1343. .chip_diag = qla2x00_chip_diag,
  1344. .config_rings = qla2x00_config_rings,
  1345. .reset_adapter = qla2x00_reset_adapter,
  1346. .nvram_config = qla2x00_nvram_config,
  1347. .update_fw_options = qla2x00_update_fw_options,
  1348. .load_risc = qla2x00_load_risc,
  1349. .pci_info_str = qla2x00_pci_info_str,
  1350. .fw_version_str = qla2x00_fw_version_str,
  1351. .intr_handler = qla2100_intr_handler,
  1352. .enable_intrs = qla2x00_enable_intrs,
  1353. .disable_intrs = qla2x00_disable_intrs,
  1354. .abort_command = qla2x00_abort_command,
  1355. .target_reset = qla2x00_abort_target,
  1356. .lun_reset = qla2x00_lun_reset,
  1357. .fabric_login = qla2x00_login_fabric,
  1358. .fabric_logout = qla2x00_fabric_logout,
  1359. .calc_req_entries = qla2x00_calc_iocbs_32,
  1360. .build_iocbs = qla2x00_build_scsi_iocbs_32,
  1361. .prep_ms_iocb = qla2x00_prep_ms_iocb,
  1362. .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
  1363. .read_nvram = qla2x00_read_nvram_data,
  1364. .write_nvram = qla2x00_write_nvram_data,
  1365. .fw_dump = qla2100_fw_dump,
  1366. .beacon_on = NULL,
  1367. .beacon_off = NULL,
  1368. .beacon_blink = NULL,
  1369. .read_optrom = qla2x00_read_optrom_data,
  1370. .write_optrom = qla2x00_write_optrom_data,
  1371. .get_flash_version = qla2x00_get_flash_version,
  1372. .start_scsi = qla2x00_start_scsi,
  1373. .abort_isp = qla2x00_abort_isp,
  1374. };
  1375. static struct isp_operations qla2300_isp_ops = {
  1376. .pci_config = qla2300_pci_config,
  1377. .reset_chip = qla2x00_reset_chip,
  1378. .chip_diag = qla2x00_chip_diag,
  1379. .config_rings = qla2x00_config_rings,
  1380. .reset_adapter = qla2x00_reset_adapter,
  1381. .nvram_config = qla2x00_nvram_config,
  1382. .update_fw_options = qla2x00_update_fw_options,
  1383. .load_risc = qla2x00_load_risc,
  1384. .pci_info_str = qla2x00_pci_info_str,
  1385. .fw_version_str = qla2x00_fw_version_str,
  1386. .intr_handler = qla2300_intr_handler,
  1387. .enable_intrs = qla2x00_enable_intrs,
  1388. .disable_intrs = qla2x00_disable_intrs,
  1389. .abort_command = qla2x00_abort_command,
  1390. .target_reset = qla2x00_abort_target,
  1391. .lun_reset = qla2x00_lun_reset,
  1392. .fabric_login = qla2x00_login_fabric,
  1393. .fabric_logout = qla2x00_fabric_logout,
  1394. .calc_req_entries = qla2x00_calc_iocbs_32,
  1395. .build_iocbs = qla2x00_build_scsi_iocbs_32,
  1396. .prep_ms_iocb = qla2x00_prep_ms_iocb,
  1397. .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
  1398. .read_nvram = qla2x00_read_nvram_data,
  1399. .write_nvram = qla2x00_write_nvram_data,
  1400. .fw_dump = qla2300_fw_dump,
  1401. .beacon_on = qla2x00_beacon_on,
  1402. .beacon_off = qla2x00_beacon_off,
  1403. .beacon_blink = qla2x00_beacon_blink,
  1404. .read_optrom = qla2x00_read_optrom_data,
  1405. .write_optrom = qla2x00_write_optrom_data,
  1406. .get_flash_version = qla2x00_get_flash_version,
  1407. .start_scsi = qla2x00_start_scsi,
  1408. .abort_isp = qla2x00_abort_isp,
  1409. };
  1410. static struct isp_operations qla24xx_isp_ops = {
  1411. .pci_config = qla24xx_pci_config,
  1412. .reset_chip = qla24xx_reset_chip,
  1413. .chip_diag = qla24xx_chip_diag,
  1414. .config_rings = qla24xx_config_rings,
  1415. .reset_adapter = qla24xx_reset_adapter,
  1416. .nvram_config = qla24xx_nvram_config,
  1417. .update_fw_options = qla24xx_update_fw_options,
  1418. .load_risc = qla24xx_load_risc,
  1419. .pci_info_str = qla24xx_pci_info_str,
  1420. .fw_version_str = qla24xx_fw_version_str,
  1421. .intr_handler = qla24xx_intr_handler,
  1422. .enable_intrs = qla24xx_enable_intrs,
  1423. .disable_intrs = qla24xx_disable_intrs,
  1424. .abort_command = qla24xx_abort_command,
  1425. .target_reset = qla24xx_abort_target,
  1426. .lun_reset = qla24xx_lun_reset,
  1427. .fabric_login = qla24xx_login_fabric,
  1428. .fabric_logout = qla24xx_fabric_logout,
  1429. .calc_req_entries = NULL,
  1430. .build_iocbs = NULL,
  1431. .prep_ms_iocb = qla24xx_prep_ms_iocb,
  1432. .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
  1433. .read_nvram = qla24xx_read_nvram_data,
  1434. .write_nvram = qla24xx_write_nvram_data,
  1435. .fw_dump = qla24xx_fw_dump,
  1436. .beacon_on = qla24xx_beacon_on,
  1437. .beacon_off = qla24xx_beacon_off,
  1438. .beacon_blink = qla24xx_beacon_blink,
  1439. .read_optrom = qla24xx_read_optrom_data,
  1440. .write_optrom = qla24xx_write_optrom_data,
  1441. .get_flash_version = qla24xx_get_flash_version,
  1442. .start_scsi = qla24xx_start_scsi,
  1443. .abort_isp = qla2x00_abort_isp,
  1444. };
  1445. static struct isp_operations qla25xx_isp_ops = {
  1446. .pci_config = qla25xx_pci_config,
  1447. .reset_chip = qla24xx_reset_chip,
  1448. .chip_diag = qla24xx_chip_diag,
  1449. .config_rings = qla24xx_config_rings,
  1450. .reset_adapter = qla24xx_reset_adapter,
  1451. .nvram_config = qla24xx_nvram_config,
  1452. .update_fw_options = qla24xx_update_fw_options,
  1453. .load_risc = qla24xx_load_risc,
  1454. .pci_info_str = qla24xx_pci_info_str,
  1455. .fw_version_str = qla24xx_fw_version_str,
  1456. .intr_handler = qla24xx_intr_handler,
  1457. .enable_intrs = qla24xx_enable_intrs,
  1458. .disable_intrs = qla24xx_disable_intrs,
  1459. .abort_command = qla24xx_abort_command,
  1460. .target_reset = qla24xx_abort_target,
  1461. .lun_reset = qla24xx_lun_reset,
  1462. .fabric_login = qla24xx_login_fabric,
  1463. .fabric_logout = qla24xx_fabric_logout,
  1464. .calc_req_entries = NULL,
  1465. .build_iocbs = NULL,
  1466. .prep_ms_iocb = qla24xx_prep_ms_iocb,
  1467. .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
  1468. .read_nvram = qla25xx_read_nvram_data,
  1469. .write_nvram = qla25xx_write_nvram_data,
  1470. .fw_dump = qla25xx_fw_dump,
  1471. .beacon_on = qla24xx_beacon_on,
  1472. .beacon_off = qla24xx_beacon_off,
  1473. .beacon_blink = qla24xx_beacon_blink,
  1474. .read_optrom = qla25xx_read_optrom_data,
  1475. .write_optrom = qla24xx_write_optrom_data,
  1476. .get_flash_version = qla24xx_get_flash_version,
  1477. .start_scsi = qla24xx_dif_start_scsi,
  1478. .abort_isp = qla2x00_abort_isp,
  1479. };
  1480. static struct isp_operations qla81xx_isp_ops = {
  1481. .pci_config = qla25xx_pci_config,
  1482. .reset_chip = qla24xx_reset_chip,
  1483. .chip_diag = qla24xx_chip_diag,
  1484. .config_rings = qla24xx_config_rings,
  1485. .reset_adapter = qla24xx_reset_adapter,
  1486. .nvram_config = qla81xx_nvram_config,
  1487. .update_fw_options = qla81xx_update_fw_options,
  1488. .load_risc = qla81xx_load_risc,
  1489. .pci_info_str = qla24xx_pci_info_str,
  1490. .fw_version_str = qla24xx_fw_version_str,
  1491. .intr_handler = qla24xx_intr_handler,
  1492. .enable_intrs = qla24xx_enable_intrs,
  1493. .disable_intrs = qla24xx_disable_intrs,
  1494. .abort_command = qla24xx_abort_command,
  1495. .target_reset = qla24xx_abort_target,
  1496. .lun_reset = qla24xx_lun_reset,
  1497. .fabric_login = qla24xx_login_fabric,
  1498. .fabric_logout = qla24xx_fabric_logout,
  1499. .calc_req_entries = NULL,
  1500. .build_iocbs = NULL,
  1501. .prep_ms_iocb = qla24xx_prep_ms_iocb,
  1502. .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
  1503. .read_nvram = NULL,
  1504. .write_nvram = NULL,
  1505. .fw_dump = qla81xx_fw_dump,
  1506. .beacon_on = qla24xx_beacon_on,
  1507. .beacon_off = qla24xx_beacon_off,
  1508. .beacon_blink = qla24xx_beacon_blink,
  1509. .read_optrom = qla25xx_read_optrom_data,
  1510. .write_optrom = qla24xx_write_optrom_data,
  1511. .get_flash_version = qla24xx_get_flash_version,
  1512. .start_scsi = qla24xx_dif_start_scsi,
  1513. .abort_isp = qla2x00_abort_isp,
  1514. };
  1515. static struct isp_operations qla82xx_isp_ops = {
  1516. .pci_config = qla82xx_pci_config,
  1517. .reset_chip = qla82xx_reset_chip,
  1518. .chip_diag = qla24xx_chip_diag,
  1519. .config_rings = qla82xx_config_rings,
  1520. .reset_adapter = qla24xx_reset_adapter,
  1521. .nvram_config = qla81xx_nvram_config,
  1522. .update_fw_options = qla24xx_update_fw_options,
  1523. .load_risc = qla82xx_load_risc,
  1524. .pci_info_str = qla82xx_pci_info_str,
  1525. .fw_version_str = qla24xx_fw_version_str,
  1526. .intr_handler = qla82xx_intr_handler,
  1527. .enable_intrs = qla82xx_enable_intrs,
  1528. .disable_intrs = qla82xx_disable_intrs,
  1529. .abort_command = qla24xx_abort_command,
  1530. .target_reset = qla24xx_abort_target,
  1531. .lun_reset = qla24xx_lun_reset,
  1532. .fabric_login = qla24xx_login_fabric,
  1533. .fabric_logout = qla24xx_fabric_logout,
  1534. .calc_req_entries = NULL,
  1535. .build_iocbs = NULL,
  1536. .prep_ms_iocb = qla24xx_prep_ms_iocb,
  1537. .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
  1538. .read_nvram = qla24xx_read_nvram_data,
  1539. .write_nvram = qla24xx_write_nvram_data,
  1540. .fw_dump = qla24xx_fw_dump,
  1541. .beacon_on = qla24xx_beacon_on,
  1542. .beacon_off = qla24xx_beacon_off,
  1543. .beacon_blink = qla24xx_beacon_blink,
  1544. .read_optrom = qla82xx_read_optrom_data,
  1545. .write_optrom = qla82xx_write_optrom_data,
  1546. .get_flash_version = qla24xx_get_flash_version,
  1547. .start_scsi = qla82xx_start_scsi,
  1548. .abort_isp = qla82xx_abort_isp,
  1549. };
  1550. static inline void
  1551. qla2x00_set_isp_flags(struct qla_hw_data *ha)
  1552. {
  1553. ha->device_type = DT_EXTENDED_IDS;
  1554. switch (ha->pdev->device) {
  1555. case PCI_DEVICE_ID_QLOGIC_ISP2100:
  1556. ha->device_type |= DT_ISP2100;
  1557. ha->device_type &= ~DT_EXTENDED_IDS;
  1558. ha->fw_srisc_address = RISC_START_ADDRESS_2100;
  1559. break;
  1560. case PCI_DEVICE_ID_QLOGIC_ISP2200:
  1561. ha->device_type |= DT_ISP2200;
  1562. ha->device_type &= ~DT_EXTENDED_IDS;
  1563. ha->fw_srisc_address = RISC_START_ADDRESS_2100;
  1564. break;
  1565. case PCI_DEVICE_ID_QLOGIC_ISP2300:
  1566. ha->device_type |= DT_ISP2300;
  1567. ha->device_type |= DT_ZIO_SUPPORTED;
  1568. ha->fw_srisc_address = RISC_START_ADDRESS_2300;
  1569. break;
  1570. case PCI_DEVICE_ID_QLOGIC_ISP2312:
  1571. ha->device_type |= DT_ISP2312;
  1572. ha->device_type |= DT_ZIO_SUPPORTED;
  1573. ha->fw_srisc_address = RISC_START_ADDRESS_2300;
  1574. break;
  1575. case PCI_DEVICE_ID_QLOGIC_ISP2322:
  1576. ha->device_type |= DT_ISP2322;
  1577. ha->device_type |= DT_ZIO_SUPPORTED;
  1578. if (ha->pdev->subsystem_vendor == 0x1028 &&
  1579. ha->pdev->subsystem_device == 0x0170)
  1580. ha->device_type |= DT_OEM_001;
  1581. ha->fw_srisc_address = RISC_START_ADDRESS_2300;
  1582. break;
  1583. case PCI_DEVICE_ID_QLOGIC_ISP6312:
  1584. ha->device_type |= DT_ISP6312;
  1585. ha->fw_srisc_address = RISC_START_ADDRESS_2300;
  1586. break;
  1587. case PCI_DEVICE_ID_QLOGIC_ISP6322:
  1588. ha->device_type |= DT_ISP6322;
  1589. ha->fw_srisc_address = RISC_START_ADDRESS_2300;
  1590. break;
  1591. case PCI_DEVICE_ID_QLOGIC_ISP2422:
  1592. ha->device_type |= DT_ISP2422;
  1593. ha->device_type |= DT_ZIO_SUPPORTED;
  1594. ha->device_type |= DT_FWI2;
  1595. ha->device_type |= DT_IIDMA;
  1596. ha->fw_srisc_address = RISC_START_ADDRESS_2400;
  1597. break;
  1598. case PCI_DEVICE_ID_QLOGIC_ISP2432:
  1599. ha->device_type |= DT_ISP2432;
  1600. ha->device_type |= DT_ZIO_SUPPORTED;
  1601. ha->device_type |= DT_FWI2;
  1602. ha->device_type |= DT_IIDMA;
  1603. ha->fw_srisc_address = RISC_START_ADDRESS_2400;
  1604. break;
  1605. case PCI_DEVICE_ID_QLOGIC_ISP8432:
  1606. ha->device_type |= DT_ISP8432;
  1607. ha->device_type |= DT_ZIO_SUPPORTED;
  1608. ha->device_type |= DT_FWI2;
  1609. ha->device_type |= DT_IIDMA;
  1610. ha->fw_srisc_address = RISC_START_ADDRESS_2400;
  1611. break;
  1612. case PCI_DEVICE_ID_QLOGIC_ISP5422:
  1613. ha->device_type |= DT_ISP5422;
  1614. ha->device_type |= DT_FWI2;
  1615. ha->fw_srisc_address = RISC_START_ADDRESS_2400;
  1616. break;
  1617. case PCI_DEVICE_ID_QLOGIC_ISP5432:
  1618. ha->device_type |= DT_ISP5432;
  1619. ha->device_type |= DT_FWI2;
  1620. ha->fw_srisc_address = RISC_START_ADDRESS_2400;
  1621. break;
  1622. case PCI_DEVICE_ID_QLOGIC_ISP2532:
  1623. ha->device_type |= DT_ISP2532;
  1624. ha->device_type |= DT_ZIO_SUPPORTED;
  1625. ha->device_type |= DT_FWI2;
  1626. ha->device_type |= DT_IIDMA;
  1627. ha->fw_srisc_address = RISC_START_ADDRESS_2400;
  1628. break;
  1629. case PCI_DEVICE_ID_QLOGIC_ISP8001:
  1630. ha->device_type |= DT_ISP8001;
  1631. ha->device_type |= DT_ZIO_SUPPORTED;
  1632. ha->device_type |= DT_FWI2;
  1633. ha->device_type |= DT_IIDMA;
  1634. ha->fw_srisc_address = RISC_START_ADDRESS_2400;
  1635. break;
  1636. case PCI_DEVICE_ID_QLOGIC_ISP8021:
  1637. ha->device_type |= DT_ISP8021;
  1638. ha->device_type |= DT_ZIO_SUPPORTED;
  1639. ha->device_type |= DT_FWI2;
  1640. ha->fw_srisc_address = RISC_START_ADDRESS_2400;
  1641. /* Initialize 82XX ISP flags */
  1642. qla82xx_init_flags(ha);
  1643. break;
  1644. }
  1645. if (IS_QLA82XX(ha))
  1646. ha->port_no = !(ha->portnum & 1);
  1647. else
  1648. /* Get adapter physical port no from interrupt pin register. */
  1649. pci_read_config_byte(ha->pdev, PCI_INTERRUPT_PIN, &ha->port_no);
  1650. if (ha->port_no & 1)
  1651. ha->flags.port0 = 1;
  1652. else
  1653. ha->flags.port0 = 0;
  1654. ql_dbg_pci(ql_dbg_init, ha->pdev, 0x000b,
  1655. "device_type=0x%x port=%d fw_srisc_address=%p.\n",
  1656. ha->device_type, ha->flags.port0, ha->fw_srisc_address);
  1657. }
  1658. static int
  1659. qla2x00_iospace_config(struct qla_hw_data *ha)
  1660. {
  1661. resource_size_t pio;
  1662. uint16_t msix;
  1663. int cpus;
  1664. if (IS_QLA82XX(ha))
  1665. return qla82xx_iospace_config(ha);
  1666. if (pci_request_selected_regions(ha->pdev, ha->bars,
  1667. QLA2XXX_DRIVER_NAME)) {
  1668. ql_log_pci(ql_log_fatal, ha->pdev, 0x0011,
  1669. "Failed to reserve PIO/MMIO regions (%s), aborting.\n",
  1670. pci_name(ha->pdev));
  1671. goto iospace_error_exit;
  1672. }
  1673. if (!(ha->bars & 1))
  1674. goto skip_pio;
  1675. /* We only need PIO for Flash operations on ISP2312 v2 chips. */
  1676. pio = pci_resource_start(ha->pdev, 0);
  1677. if (pci_resource_flags(ha->pdev, 0) & IORESOURCE_IO) {
  1678. if (pci_resource_len(ha->pdev, 0) < MIN_IOBASE_LEN) {
  1679. ql_log_pci(ql_log_warn, ha->pdev, 0x0012,
  1680. "Invalid pci I/O region size (%s).\n",
  1681. pci_name(ha->pdev));
  1682. pio = 0;
  1683. }
  1684. } else {
  1685. ql_log_pci(ql_log_warn, ha->pdev, 0x0013,
  1686. "Region #0 no a PIO resource (%s).\n",
  1687. pci_name(ha->pdev));
  1688. pio = 0;
  1689. }
  1690. ha->pio_address = pio;
  1691. ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0014,
  1692. "PIO address=%p.\n",
  1693. ha->pio_address);
  1694. skip_pio:
  1695. /* Use MMIO operations for all accesses. */
  1696. if (!(pci_resource_flags(ha->pdev, 1) & IORESOURCE_MEM)) {
  1697. ql_log_pci(ql_log_fatal, ha->pdev, 0x0015,
  1698. "Region #1 not an MMIO resource (%s), aborting.\n",
  1699. pci_name(ha->pdev));
  1700. goto iospace_error_exit;
  1701. }
  1702. if (pci_resource_len(ha->pdev, 1) < MIN_IOBASE_LEN) {
  1703. ql_log_pci(ql_log_fatal, ha->pdev, 0x0016,
  1704. "Invalid PCI mem region size (%s), aborting.\n",
  1705. pci_name(ha->pdev));
  1706. goto iospace_error_exit;
  1707. }
  1708. ha->iobase = ioremap(pci_resource_start(ha->pdev, 1), MIN_IOBASE_LEN);
  1709. if (!ha->iobase) {
  1710. ql_log_pci(ql_log_fatal, ha->pdev, 0x0017,
  1711. "Cannot remap MMIO (%s), aborting.\n",
  1712. pci_name(ha->pdev));
  1713. goto iospace_error_exit;
  1714. }
  1715. /* Determine queue resources */
  1716. ha->max_req_queues = ha->max_rsp_queues = 1;
  1717. if ((ql2xmaxqueues <= 1 && !ql2xmultique_tag) ||
  1718. (ql2xmaxqueues > 1 && ql2xmultique_tag) ||
  1719. (!IS_QLA25XX(ha) && !IS_QLA81XX(ha)))
  1720. goto mqiobase_exit;
  1721. ha->mqiobase = ioremap(pci_resource_start(ha->pdev, 3),
  1722. pci_resource_len(ha->pdev, 3));
  1723. if (ha->mqiobase) {
  1724. ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0018,
  1725. "MQIO Base=%p.\n", ha->mqiobase);
  1726. /* Read MSIX vector size of the board */
  1727. pci_read_config_word(ha->pdev, QLA_PCI_MSIX_CONTROL, &msix);
  1728. ha->msix_count = msix;
  1729. /* Max queues are bounded by available msix vectors */
  1730. /* queue 0 uses two msix vectors */
  1731. if (ql2xmultique_tag) {
  1732. cpus = num_online_cpus();
  1733. ha->max_rsp_queues = (ha->msix_count - 1 > cpus) ?
  1734. (cpus + 1) : (ha->msix_count - 1);
  1735. ha->max_req_queues = 2;
  1736. } else if (ql2xmaxqueues > 1) {
  1737. ha->max_req_queues = ql2xmaxqueues > QLA_MQ_SIZE ?
  1738. QLA_MQ_SIZE : ql2xmaxqueues;
  1739. ql_dbg_pci(ql_dbg_multiq, ha->pdev, 0xc008,
  1740. "QoS mode set, max no of request queues:%d.\n",
  1741. ha->max_req_queues);
  1742. ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0019,
  1743. "QoS mode set, max no of request queues:%d.\n",
  1744. ha->max_req_queues);
  1745. }
  1746. ql_log_pci(ql_log_info, ha->pdev, 0x001a,
  1747. "MSI-X vector count: %d.\n", msix);
  1748. } else
  1749. ql_log_pci(ql_log_info, ha->pdev, 0x001b,
  1750. "BAR 3 not enabled.\n");
  1751. mqiobase_exit:
  1752. ha->msix_count = ha->max_rsp_queues + 1;
  1753. ql_dbg_pci(ql_dbg_init, ha->pdev, 0x001c,
  1754. "MSIX Count:%d.\n", ha->msix_count);
  1755. return (0);
  1756. iospace_error_exit:
  1757. return (-ENOMEM);
  1758. }
  1759. static void
  1760. qla2xxx_scan_start(struct Scsi_Host *shost)
  1761. {
  1762. scsi_qla_host_t *vha = shost_priv(shost);
  1763. if (vha->hw->flags.running_gold_fw)
  1764. return;
  1765. set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
  1766. set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
  1767. set_bit(RSCN_UPDATE, &vha->dpc_flags);
  1768. set_bit(NPIV_CONFIG_NEEDED, &vha->dpc_flags);
  1769. }
  1770. static int
  1771. qla2xxx_scan_finished(struct Scsi_Host *shost, unsigned long time)
  1772. {
  1773. scsi_qla_host_t *vha = shost_priv(shost);
  1774. if (!vha->host)
  1775. return 1;
  1776. if (time > vha->hw->loop_reset_delay * HZ)
  1777. return 1;
  1778. return atomic_read(&vha->loop_state) == LOOP_READY;
  1779. }
  1780. /*
  1781. * PCI driver interface
  1782. */
  1783. static int __devinit
  1784. qla2x00_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
  1785. {
  1786. int ret = -ENODEV;
  1787. struct Scsi_Host *host;
  1788. scsi_qla_host_t *base_vha = NULL;
  1789. struct qla_hw_data *ha;
  1790. char pci_info[30];
  1791. char fw_str[30];
  1792. struct scsi_host_template *sht;
  1793. int bars, max_id, mem_only = 0;
  1794. uint16_t req_length = 0, rsp_length = 0;
  1795. struct req_que *req = NULL;
  1796. struct rsp_que *rsp = NULL;
  1797. bars = pci_select_bars(pdev, IORESOURCE_MEM | IORESOURCE_IO);
  1798. sht = &qla2xxx_driver_template;
  1799. if (pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2422 ||
  1800. pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2432 ||
  1801. pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8432 ||
  1802. pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5422 ||
  1803. pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5432 ||
  1804. pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2532 ||
  1805. pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8001 ||
  1806. pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8021) {
  1807. bars = pci_select_bars(pdev, IORESOURCE_MEM);
  1808. mem_only = 1;
  1809. ql_dbg_pci(ql_dbg_init, pdev, 0x0007,
  1810. "Mem only adapter.\n");
  1811. }
  1812. ql_dbg_pci(ql_dbg_init, pdev, 0x0008,
  1813. "Bars=%d.\n", bars);
  1814. if (mem_only) {
  1815. if (pci_enable_device_mem(pdev))
  1816. goto probe_out;
  1817. } else {
  1818. if (pci_enable_device(pdev))
  1819. goto probe_out;
  1820. }
  1821. /* This may fail but that's ok */
  1822. pci_enable_pcie_error_reporting(pdev);
  1823. ha = kzalloc(sizeof(struct qla_hw_data), GFP_KERNEL);
  1824. if (!ha) {
  1825. ql_log_pci(ql_log_fatal, pdev, 0x0009,
  1826. "Unable to allocate memory for ha.\n");
  1827. goto probe_out;
  1828. }
  1829. ql_dbg_pci(ql_dbg_init, pdev, 0x000a,
  1830. "Memory allocated for ha=%p.\n", ha);
  1831. ha->pdev = pdev;
  1832. /* Clear our data area */
  1833. ha->bars = bars;
  1834. ha->mem_only = mem_only;
  1835. spin_lock_init(&ha->hardware_lock);
  1836. spin_lock_init(&ha->vport_slock);
  1837. /* Set ISP-type information. */
  1838. qla2x00_set_isp_flags(ha);
  1839. /* Set EEH reset type to fundamental if required by hba */
  1840. if ( IS_QLA24XX(ha) || IS_QLA25XX(ha) || IS_QLA81XX(ha)) {
  1841. pdev->needs_freset = 1;
  1842. }
  1843. /* Configure PCI I/O space */
  1844. ret = qla2x00_iospace_config(ha);
  1845. if (ret)
  1846. goto probe_hw_failed;
  1847. ql_log_pci(ql_log_info, pdev, 0x001d,
  1848. "Found an ISP%04X irq %d iobase 0x%p.\n",
  1849. pdev->device, pdev->irq, ha->iobase);
  1850. ha->prev_topology = 0;
  1851. ha->init_cb_size = sizeof(init_cb_t);
  1852. ha->link_data_rate = PORT_SPEED_UNKNOWN;
  1853. ha->optrom_size = OPTROM_SIZE_2300;
  1854. /* Assign ISP specific operations. */
  1855. max_id = MAX_TARGETS_2200;
  1856. if (IS_QLA2100(ha)) {
  1857. max_id = MAX_TARGETS_2100;
  1858. ha->mbx_count = MAILBOX_REGISTER_COUNT_2100;
  1859. req_length = REQUEST_ENTRY_CNT_2100;
  1860. rsp_length = RESPONSE_ENTRY_CNT_2100;
  1861. ha->max_loop_id = SNS_LAST_LOOP_ID_2100;
  1862. ha->gid_list_info_size = 4;
  1863. ha->flash_conf_off = ~0;
  1864. ha->flash_data_off = ~0;
  1865. ha->nvram_conf_off = ~0;
  1866. ha->nvram_data_off = ~0;
  1867. ha->isp_ops = &qla2100_isp_ops;
  1868. } else if (IS_QLA2200(ha)) {
  1869. ha->mbx_count = MAILBOX_REGISTER_COUNT;
  1870. req_length = REQUEST_ENTRY_CNT_2200;
  1871. rsp_length = RESPONSE_ENTRY_CNT_2100;
  1872. ha->max_loop_id = SNS_LAST_LOOP_ID_2100;
  1873. ha->gid_list_info_size = 4;
  1874. ha->flash_conf_off = ~0;
  1875. ha->flash_data_off = ~0;
  1876. ha->nvram_conf_off = ~0;
  1877. ha->nvram_data_off = ~0;
  1878. ha->isp_ops = &qla2100_isp_ops;
  1879. } else if (IS_QLA23XX(ha)) {
  1880. ha->mbx_count = MAILBOX_REGISTER_COUNT;
  1881. req_length = REQUEST_ENTRY_CNT_2200;
  1882. rsp_length = RESPONSE_ENTRY_CNT_2300;
  1883. ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
  1884. ha->gid_list_info_size = 6;
  1885. if (IS_QLA2322(ha) || IS_QLA6322(ha))
  1886. ha->optrom_size = OPTROM_SIZE_2322;
  1887. ha->flash_conf_off = ~0;
  1888. ha->flash_data_off = ~0;
  1889. ha->nvram_conf_off = ~0;
  1890. ha->nvram_data_off = ~0;
  1891. ha->isp_ops = &qla2300_isp_ops;
  1892. } else if (IS_QLA24XX_TYPE(ha)) {
  1893. ha->mbx_count = MAILBOX_REGISTER_COUNT;
  1894. req_length = REQUEST_ENTRY_CNT_24XX;
  1895. rsp_length = RESPONSE_ENTRY_CNT_2300;
  1896. ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
  1897. ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
  1898. ha->gid_list_info_size = 8;
  1899. ha->optrom_size = OPTROM_SIZE_24XX;
  1900. ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA24XX;
  1901. ha->isp_ops = &qla24xx_isp_ops;
  1902. ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
  1903. ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
  1904. ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
  1905. ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
  1906. } else if (IS_QLA25XX(ha)) {
  1907. ha->mbx_count = MAILBOX_REGISTER_COUNT;
  1908. req_length = REQUEST_ENTRY_CNT_24XX;
  1909. rsp_length = RESPONSE_ENTRY_CNT_2300;
  1910. ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
  1911. ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
  1912. ha->gid_list_info_size = 8;
  1913. ha->optrom_size = OPTROM_SIZE_25XX;
  1914. ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
  1915. ha->isp_ops = &qla25xx_isp_ops;
  1916. ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
  1917. ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
  1918. ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
  1919. ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
  1920. } else if (IS_QLA81XX(ha)) {
  1921. ha->mbx_count = MAILBOX_REGISTER_COUNT;
  1922. req_length = REQUEST_ENTRY_CNT_24XX;
  1923. rsp_length = RESPONSE_ENTRY_CNT_2300;
  1924. ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
  1925. ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
  1926. ha->gid_list_info_size = 8;
  1927. ha->optrom_size = OPTROM_SIZE_81XX;
  1928. ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
  1929. ha->isp_ops = &qla81xx_isp_ops;
  1930. ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_81XX;
  1931. ha->flash_data_off = FARX_ACCESS_FLASH_DATA_81XX;
  1932. ha->nvram_conf_off = ~0;
  1933. ha->nvram_data_off = ~0;
  1934. } else if (IS_QLA82XX(ha)) {
  1935. ha->mbx_count = MAILBOX_REGISTER_COUNT;
  1936. req_length = REQUEST_ENTRY_CNT_82XX;
  1937. rsp_length = RESPONSE_ENTRY_CNT_82XX;
  1938. ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
  1939. ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
  1940. ha->gid_list_info_size = 8;
  1941. ha->optrom_size = OPTROM_SIZE_82XX;
  1942. ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
  1943. ha->isp_ops = &qla82xx_isp_ops;
  1944. ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
  1945. ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
  1946. ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
  1947. ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
  1948. }
  1949. ql_dbg_pci(ql_dbg_init, pdev, 0x001e,
  1950. "mbx_count=%d, req_length=%d, "
  1951. "rsp_length=%d, max_loop_id=%d, init_cb_size=%d, "
  1952. "gid_list_info_size=%d, optrom_size=%d, nvram_npiv_size=%d, .\n",
  1953. ha->mbx_count, req_length, rsp_length, ha->max_loop_id,
  1954. ha->init_cb_size, ha->gid_list_info_size, ha->optrom_size,
  1955. ha->nvram_npiv_size);
  1956. ql_dbg_pci(ql_dbg_init, pdev, 0x001f,
  1957. "isp_ops=%p, flash_conf_off=%d, "
  1958. "flash_data_off=%d, nvram_conf_off=%d, nvram_data_off=%d.\n",
  1959. ha->isp_ops, ha->flash_conf_off, ha->flash_data_off,
  1960. ha->nvram_conf_off, ha->nvram_data_off);
  1961. mutex_init(&ha->vport_lock);
  1962. init_completion(&ha->mbx_cmd_comp);
  1963. complete(&ha->mbx_cmd_comp);
  1964. init_completion(&ha->mbx_intr_comp);
  1965. init_completion(&ha->dcbx_comp);
  1966. set_bit(0, (unsigned long *) ha->vp_idx_map);
  1967. qla2x00_config_dma_addressing(ha);
  1968. ql_dbg_pci(ql_dbg_init, pdev, 0x0020,
  1969. "64 Bit addressing is %s.\n",
  1970. ha->flags.enable_64bit_addressing ? "enable" :
  1971. "disable");
  1972. ret = qla2x00_mem_alloc(ha, req_length, rsp_length, &req, &rsp);
  1973. if (!ret) {
  1974. ql_log_pci(ql_log_fatal, pdev, 0x0031,
  1975. "Failed to allocate memory for adapter, aborting.\n");
  1976. goto probe_hw_failed;
  1977. }
  1978. req->max_q_depth = MAX_Q_DEPTH;
  1979. if (ql2xmaxqdepth != 0 && ql2xmaxqdepth <= 0xffffU)
  1980. req->max_q_depth = ql2xmaxqdepth;
  1981. base_vha = qla2x00_create_host(sht, ha);
  1982. if (!base_vha) {
  1983. ret = -ENOMEM;
  1984. qla2x00_mem_free(ha);
  1985. qla2x00_free_req_que(ha, req);
  1986. qla2x00_free_rsp_que(ha, rsp);
  1987. goto probe_hw_failed;
  1988. }
  1989. pci_set_drvdata(pdev, base_vha);
  1990. host = base_vha->host;
  1991. base_vha->req = req;
  1992. host->can_queue = req->length + 128;
  1993. if (IS_QLA2XXX_MIDTYPE(ha))
  1994. base_vha->mgmt_svr_loop_id = 10 + base_vha->vp_idx;
  1995. else
  1996. base_vha->mgmt_svr_loop_id = MANAGEMENT_SERVER +
  1997. base_vha->vp_idx;
  1998. /* Set the SG table size based on ISP type */
  1999. if (!IS_FWI2_CAPABLE(ha)) {
  2000. if (IS_QLA2100(ha))
  2001. host->sg_tablesize = 32;
  2002. } else {
  2003. if (!IS_QLA82XX(ha))
  2004. host->sg_tablesize = QLA_SG_ALL;
  2005. }
  2006. ql_dbg(ql_dbg_init, base_vha, 0x0032,
  2007. "can_queue=%d, req=%p, "
  2008. "mgmt_svr_loop_id=%d, sg_tablesize=%d.\n",
  2009. host->can_queue, base_vha->req,
  2010. base_vha->mgmt_svr_loop_id, host->sg_tablesize);
  2011. host->max_id = max_id;
  2012. host->this_id = 255;
  2013. host->cmd_per_lun = 3;
  2014. host->unique_id = host->host_no;
  2015. if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif)
  2016. host->max_cmd_len = 32;
  2017. else
  2018. host->max_cmd_len = MAX_CMDSZ;
  2019. host->max_channel = MAX_BUSES - 1;
  2020. host->max_lun = ql2xmaxlun;
  2021. host->transportt = qla2xxx_transport_template;
  2022. sht->vendor_id = (SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_QLOGIC);
  2023. ql_dbg(ql_dbg_init, base_vha, 0x0033,
  2024. "max_id=%d this_id=%d "
  2025. "cmd_per_len=%d unique_id=%d max_cmd_len=%d max_channel=%d "
  2026. "max_lun=%d transportt=%p, vendor_id=%d.\n", host->max_id,
  2027. host->this_id, host->cmd_per_lun, host->unique_id,
  2028. host->max_cmd_len, host->max_channel, host->max_lun,
  2029. host->transportt, sht->vendor_id);
  2030. /* Set up the irqs */
  2031. ret = qla2x00_request_irqs(ha, rsp);
  2032. if (ret)
  2033. goto probe_init_failed;
  2034. pci_save_state(pdev);
  2035. /* Alloc arrays of request and response ring ptrs */
  2036. que_init:
  2037. if (!qla2x00_alloc_queues(ha)) {
  2038. ql_log(ql_log_fatal, base_vha, 0x003d,
  2039. "Failed to allocate memory for queue pointers.. aborting.\n");
  2040. goto probe_init_failed;
  2041. }
  2042. ha->rsp_q_map[0] = rsp;
  2043. ha->req_q_map[0] = req;
  2044. rsp->req = req;
  2045. req->rsp = rsp;
  2046. set_bit(0, ha->req_qid_map);
  2047. set_bit(0, ha->rsp_qid_map);
  2048. /* FWI2-capable only. */
  2049. req->req_q_in = &ha->iobase->isp24.req_q_in;
  2050. req->req_q_out = &ha->iobase->isp24.req_q_out;
  2051. rsp->rsp_q_in = &ha->iobase->isp24.rsp_q_in;
  2052. rsp->rsp_q_out = &ha->iobase->isp24.rsp_q_out;
  2053. if (ha->mqenable) {
  2054. req->req_q_in = &ha->mqiobase->isp25mq.req_q_in;
  2055. req->req_q_out = &ha->mqiobase->isp25mq.req_q_out;
  2056. rsp->rsp_q_in = &ha->mqiobase->isp25mq.rsp_q_in;
  2057. rsp->rsp_q_out = &ha->mqiobase->isp25mq.rsp_q_out;
  2058. }
  2059. if (IS_QLA82XX(ha)) {
  2060. req->req_q_out = &ha->iobase->isp82.req_q_out[0];
  2061. rsp->rsp_q_in = &ha->iobase->isp82.rsp_q_in[0];
  2062. rsp->rsp_q_out = &ha->iobase->isp82.rsp_q_out[0];
  2063. }
  2064. ql_dbg(ql_dbg_multiq, base_vha, 0xc009,
  2065. "rsp_q_map=%p req_q_map=%p rsp->req=%p req->rsp=%p.\n",
  2066. ha->rsp_q_map, ha->req_q_map, rsp->req, req->rsp);
  2067. ql_dbg(ql_dbg_multiq, base_vha, 0xc00a,
  2068. "req->req_q_in=%p req->req_q_out=%p "
  2069. "rsp->rsp_q_in=%p rsp->rsp_q_out=%p.\n",
  2070. req->req_q_in, req->req_q_out,
  2071. rsp->rsp_q_in, rsp->rsp_q_out);
  2072. ql_dbg(ql_dbg_init, base_vha, 0x003e,
  2073. "rsp_q_map=%p req_q_map=%p rsp->req=%p req->rsp=%p.\n",
  2074. ha->rsp_q_map, ha->req_q_map, rsp->req, req->rsp);
  2075. ql_dbg(ql_dbg_init, base_vha, 0x003f,
  2076. "req->req_q_in=%p req->req_q_out=%p rsp->rsp_q_in=%p rsp->rsp_q_out=%p.\n",
  2077. req->req_q_in, req->req_q_out, rsp->rsp_q_in, rsp->rsp_q_out);
  2078. if (qla2x00_initialize_adapter(base_vha)) {
  2079. ql_log(ql_log_fatal, base_vha, 0x00d6,
  2080. "Failed to initialize adapter - Adapter flags %x.\n",
  2081. base_vha->device_flags);
  2082. if (IS_QLA82XX(ha)) {
  2083. qla82xx_idc_lock(ha);
  2084. qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
  2085. QLA82XX_DEV_FAILED);
  2086. qla82xx_idc_unlock(ha);
  2087. ql_log(ql_log_fatal, base_vha, 0x00d7,
  2088. "HW State: FAILED.\n");
  2089. }
  2090. ret = -ENODEV;
  2091. goto probe_failed;
  2092. }
  2093. if (ha->mqenable) {
  2094. if (qla25xx_setup_mode(base_vha)) {
  2095. ql_log(ql_log_warn, base_vha, 0x00ec,
  2096. "Failed to create queues, falling back to single queue mode.\n");
  2097. goto que_init;
  2098. }
  2099. }
  2100. if (ha->flags.running_gold_fw)
  2101. goto skip_dpc;
  2102. /*
  2103. * Startup the kernel thread for this host adapter
  2104. */
  2105. ha->dpc_thread = kthread_create(qla2x00_do_dpc, ha,
  2106. "%s_dpc", base_vha->host_str);
  2107. if (IS_ERR(ha->dpc_thread)) {
  2108. ql_log(ql_log_fatal, base_vha, 0x00ed,
  2109. "Failed to start DPC thread.\n");
  2110. ret = PTR_ERR(ha->dpc_thread);
  2111. goto probe_failed;
  2112. }
  2113. ql_dbg(ql_dbg_init, base_vha, 0x00ee,
  2114. "DPC thread started successfully.\n");
  2115. skip_dpc:
  2116. list_add_tail(&base_vha->list, &ha->vp_list);
  2117. base_vha->host->irq = ha->pdev->irq;
  2118. /* Initialized the timer */
  2119. qla2x00_start_timer(base_vha, qla2x00_timer, WATCH_INTERVAL);
  2120. ql_dbg(ql_dbg_init, base_vha, 0x00ef,
  2121. "Started qla2x00_timer with "
  2122. "interval=%d.\n", WATCH_INTERVAL);
  2123. ql_dbg(ql_dbg_init, base_vha, 0x00f0,
  2124. "Detected hba at address=%p.\n",
  2125. ha);
  2126. if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif) {
  2127. if (ha->fw_attributes & BIT_4) {
  2128. int prot = 0;
  2129. base_vha->flags.difdix_supported = 1;
  2130. ql_dbg(ql_dbg_init, base_vha, 0x00f1,
  2131. "Registering for DIF/DIX type 1 and 3 protection.\n");
  2132. if (ql2xenabledif == 1)
  2133. prot = SHOST_DIX_TYPE0_PROTECTION;
  2134. scsi_host_set_prot(host,
  2135. prot | SHOST_DIF_TYPE1_PROTECTION
  2136. | SHOST_DIF_TYPE2_PROTECTION
  2137. | SHOST_DIF_TYPE3_PROTECTION
  2138. | SHOST_DIX_TYPE1_PROTECTION
  2139. | SHOST_DIX_TYPE2_PROTECTION
  2140. | SHOST_DIX_TYPE3_PROTECTION);
  2141. scsi_host_set_guard(host, SHOST_DIX_GUARD_CRC);
  2142. } else
  2143. base_vha->flags.difdix_supported = 0;
  2144. }
  2145. ha->isp_ops->enable_intrs(ha);
  2146. ret = scsi_add_host(host, &pdev->dev);
  2147. if (ret)
  2148. goto probe_failed;
  2149. base_vha->flags.init_done = 1;
  2150. base_vha->flags.online = 1;
  2151. ql_dbg(ql_dbg_init, base_vha, 0x00f2,
  2152. "Init done and hba is online.\n");
  2153. scsi_scan_host(host);
  2154. qla2x00_alloc_sysfs_attr(base_vha);
  2155. qla2x00_init_host_attr(base_vha);
  2156. qla2x00_dfs_setup(base_vha);
  2157. ql_log(ql_log_info, base_vha, 0x00fa,
  2158. "QLogic Fibre Channed HBA Driver: %s.\n",
  2159. qla2x00_version_str);
  2160. ql_log(ql_log_info, base_vha, 0x00fb,
  2161. "QLogic %s - %s.\n",
  2162. ha->model_number, ha->model_desc ? ha->model_desc : "");
  2163. ql_log(ql_log_info, base_vha, 0x00fc,
  2164. "ISP%04X: %s @ %s hdma%c host#=%ld fw=%s.\n",
  2165. pdev->device, ha->isp_ops->pci_info_str(base_vha, pci_info),
  2166. pci_name(pdev), ha->flags.enable_64bit_addressing ? '+' : '-',
  2167. base_vha->host_no,
  2168. ha->isp_ops->fw_version_str(base_vha, fw_str));
  2169. return 0;
  2170. probe_init_failed:
  2171. qla2x00_free_req_que(ha, req);
  2172. qla2x00_free_rsp_que(ha, rsp);
  2173. ha->max_req_queues = ha->max_rsp_queues = 0;
  2174. probe_failed:
  2175. if (base_vha->timer_active)
  2176. qla2x00_stop_timer(base_vha);
  2177. base_vha->flags.online = 0;
  2178. if (ha->dpc_thread) {
  2179. struct task_struct *t = ha->dpc_thread;
  2180. ha->dpc_thread = NULL;
  2181. kthread_stop(t);
  2182. }
  2183. qla2x00_free_device(base_vha);
  2184. scsi_host_put(base_vha->host);
  2185. probe_hw_failed:
  2186. if (IS_QLA82XX(ha)) {
  2187. qla82xx_idc_lock(ha);
  2188. qla82xx_clear_drv_active(ha);
  2189. qla82xx_idc_unlock(ha);
  2190. iounmap((device_reg_t __iomem *)ha->nx_pcibase);
  2191. if (!ql2xdbwr)
  2192. iounmap((device_reg_t __iomem *)ha->nxdb_wr_ptr);
  2193. } else {
  2194. if (ha->iobase)
  2195. iounmap(ha->iobase);
  2196. }
  2197. pci_release_selected_regions(ha->pdev, ha->bars);
  2198. kfree(ha);
  2199. ha = NULL;
  2200. probe_out:
  2201. pci_disable_device(pdev);
  2202. return ret;
  2203. }
  2204. static void
  2205. qla2x00_shutdown(struct pci_dev *pdev)
  2206. {
  2207. scsi_qla_host_t *vha;
  2208. struct qla_hw_data *ha;
  2209. vha = pci_get_drvdata(pdev);
  2210. ha = vha->hw;
  2211. /* Turn-off FCE trace */
  2212. if (ha->flags.fce_enabled) {
  2213. qla2x00_disable_fce_trace(vha, NULL, NULL);
  2214. ha->flags.fce_enabled = 0;
  2215. }
  2216. /* Turn-off EFT trace */
  2217. if (ha->eft)
  2218. qla2x00_disable_eft_trace(vha);
  2219. /* Stop currently executing firmware. */
  2220. qla2x00_try_to_stop_firmware(vha);
  2221. /* Turn adapter off line */
  2222. vha->flags.online = 0;
  2223. /* turn-off interrupts on the card */
  2224. if (ha->interrupts_on) {
  2225. vha->flags.init_done = 0;
  2226. ha->isp_ops->disable_intrs(ha);
  2227. }
  2228. qla2x00_free_irqs(vha);
  2229. qla2x00_free_fw_dump(ha);
  2230. }
  2231. static void
  2232. qla2x00_remove_one(struct pci_dev *pdev)
  2233. {
  2234. scsi_qla_host_t *base_vha, *vha;
  2235. struct qla_hw_data *ha;
  2236. unsigned long flags;
  2237. base_vha = pci_get_drvdata(pdev);
  2238. ha = base_vha->hw;
  2239. mutex_lock(&ha->vport_lock);
  2240. while (ha->cur_vport_count) {
  2241. struct Scsi_Host *scsi_host;
  2242. spin_lock_irqsave(&ha->vport_slock, flags);
  2243. BUG_ON(base_vha->list.next == &ha->vp_list);
  2244. /* This assumes first entry in ha->vp_list is always base vha */
  2245. vha = list_first_entry(&base_vha->list, scsi_qla_host_t, list);
  2246. scsi_host = scsi_host_get(vha->host);
  2247. spin_unlock_irqrestore(&ha->vport_slock, flags);
  2248. mutex_unlock(&ha->vport_lock);
  2249. fc_vport_terminate(vha->fc_vport);
  2250. scsi_host_put(vha->host);
  2251. mutex_lock(&ha->vport_lock);
  2252. }
  2253. mutex_unlock(&ha->vport_lock);
  2254. set_bit(UNLOADING, &base_vha->dpc_flags);
  2255. qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16);
  2256. qla2x00_dfs_remove(base_vha);
  2257. qla84xx_put_chip(base_vha);
  2258. /* Disable timer */
  2259. if (base_vha->timer_active)
  2260. qla2x00_stop_timer(base_vha);
  2261. base_vha->flags.online = 0;
  2262. /* Flush the work queue and remove it */
  2263. if (ha->wq) {
  2264. flush_workqueue(ha->wq);
  2265. destroy_workqueue(ha->wq);
  2266. ha->wq = NULL;
  2267. }
  2268. /* Kill the kernel thread for this host */
  2269. if (ha->dpc_thread) {
  2270. struct task_struct *t = ha->dpc_thread;
  2271. /*
  2272. * qla2xxx_wake_dpc checks for ->dpc_thread
  2273. * so we need to zero it out.
  2274. */
  2275. ha->dpc_thread = NULL;
  2276. kthread_stop(t);
  2277. }
  2278. qla2x00_free_sysfs_attr(base_vha);
  2279. fc_remove_host(base_vha->host);
  2280. scsi_remove_host(base_vha->host);
  2281. qla2x00_free_device(base_vha);
  2282. scsi_host_put(base_vha->host);
  2283. if (IS_QLA82XX(ha)) {
  2284. qla82xx_idc_lock(ha);
  2285. qla82xx_clear_drv_active(ha);
  2286. qla82xx_idc_unlock(ha);
  2287. iounmap((device_reg_t __iomem *)ha->nx_pcibase);
  2288. if (!ql2xdbwr)
  2289. iounmap((device_reg_t __iomem *)ha->nxdb_wr_ptr);
  2290. } else {
  2291. if (ha->iobase)
  2292. iounmap(ha->iobase);
  2293. if (ha->mqiobase)
  2294. iounmap(ha->mqiobase);
  2295. }
  2296. pci_release_selected_regions(ha->pdev, ha->bars);
  2297. kfree(ha);
  2298. ha = NULL;
  2299. pci_disable_pcie_error_reporting(pdev);
  2300. pci_disable_device(pdev);
  2301. pci_set_drvdata(pdev, NULL);
  2302. }
  2303. static void
  2304. qla2x00_free_device(scsi_qla_host_t *vha)
  2305. {
  2306. struct qla_hw_data *ha = vha->hw;
  2307. qla2x00_abort_all_cmds(vha, DID_NO_CONNECT << 16);
  2308. /* Disable timer */
  2309. if (vha->timer_active)
  2310. qla2x00_stop_timer(vha);
  2311. /* Kill the kernel thread for this host */
  2312. if (ha->dpc_thread) {
  2313. struct task_struct *t = ha->dpc_thread;
  2314. /*
  2315. * qla2xxx_wake_dpc checks for ->dpc_thread
  2316. * so we need to zero it out.
  2317. */
  2318. ha->dpc_thread = NULL;
  2319. kthread_stop(t);
  2320. }
  2321. qla25xx_delete_queues(vha);
  2322. if (ha->flags.fce_enabled)
  2323. qla2x00_disable_fce_trace(vha, NULL, NULL);
  2324. if (ha->eft)
  2325. qla2x00_disable_eft_trace(vha);
  2326. /* Stop currently executing firmware. */
  2327. qla2x00_try_to_stop_firmware(vha);
  2328. vha->flags.online = 0;
  2329. /* turn-off interrupts on the card */
  2330. if (ha->interrupts_on) {
  2331. vha->flags.init_done = 0;
  2332. ha->isp_ops->disable_intrs(ha);
  2333. }
  2334. qla2x00_free_irqs(vha);
  2335. qla2x00_free_fcports(vha);
  2336. qla2x00_mem_free(ha);
  2337. qla2x00_free_queues(ha);
  2338. }
  2339. void qla2x00_free_fcports(struct scsi_qla_host *vha)
  2340. {
  2341. fc_port_t *fcport, *tfcport;
  2342. list_for_each_entry_safe(fcport, tfcport, &vha->vp_fcports, list) {
  2343. list_del(&fcport->list);
  2344. kfree(fcport);
  2345. fcport = NULL;
  2346. }
  2347. }
  2348. static inline void
  2349. qla2x00_schedule_rport_del(struct scsi_qla_host *vha, fc_port_t *fcport,
  2350. int defer)
  2351. {
  2352. struct fc_rport *rport;
  2353. scsi_qla_host_t *base_vha;
  2354. unsigned long flags;
  2355. if (!fcport->rport)
  2356. return;
  2357. rport = fcport->rport;
  2358. if (defer) {
  2359. base_vha = pci_get_drvdata(vha->hw->pdev);
  2360. spin_lock_irqsave(vha->host->host_lock, flags);
  2361. fcport->drport = rport;
  2362. spin_unlock_irqrestore(vha->host->host_lock, flags);
  2363. set_bit(FCPORT_UPDATE_NEEDED, &base_vha->dpc_flags);
  2364. qla2xxx_wake_dpc(base_vha);
  2365. } else
  2366. fc_remote_port_delete(rport);
  2367. }
  2368. /*
  2369. * qla2x00_mark_device_lost Updates fcport state when device goes offline.
  2370. *
  2371. * Input: ha = adapter block pointer. fcport = port structure pointer.
  2372. *
  2373. * Return: None.
  2374. *
  2375. * Context:
  2376. */
  2377. void qla2x00_mark_device_lost(scsi_qla_host_t *vha, fc_port_t *fcport,
  2378. int do_login, int defer)
  2379. {
  2380. if (atomic_read(&fcport->state) == FCS_ONLINE &&
  2381. vha->vp_idx == fcport->vp_idx) {
  2382. qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
  2383. qla2x00_schedule_rport_del(vha, fcport, defer);
  2384. }
  2385. /*
  2386. * We may need to retry the login, so don't change the state of the
  2387. * port but do the retries.
  2388. */
  2389. if (atomic_read(&fcport->state) != FCS_DEVICE_DEAD)
  2390. qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
  2391. if (!do_login)
  2392. return;
  2393. if (fcport->login_retry == 0) {
  2394. fcport->login_retry = vha->hw->login_retry_count;
  2395. set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
  2396. ql_dbg(ql_dbg_disc, vha, 0x2067,
  2397. "Port login retry "
  2398. "%02x%02x%02x%02x%02x%02x%02x%02x, "
  2399. "id = 0x%04x retry cnt=%d.\n",
  2400. fcport->port_name[0], fcport->port_name[1],
  2401. fcport->port_name[2], fcport->port_name[3],
  2402. fcport->port_name[4], fcport->port_name[5],
  2403. fcport->port_name[6], fcport->port_name[7],
  2404. fcport->loop_id, fcport->login_retry);
  2405. }
  2406. }
  2407. /*
  2408. * qla2x00_mark_all_devices_lost
  2409. * Updates fcport state when device goes offline.
  2410. *
  2411. * Input:
  2412. * ha = adapter block pointer.
  2413. * fcport = port structure pointer.
  2414. *
  2415. * Return:
  2416. * None.
  2417. *
  2418. * Context:
  2419. */
  2420. void
  2421. qla2x00_mark_all_devices_lost(scsi_qla_host_t *vha, int defer)
  2422. {
  2423. fc_port_t *fcport;
  2424. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  2425. if (vha->vp_idx != 0 && vha->vp_idx != fcport->vp_idx)
  2426. continue;
  2427. /*
  2428. * No point in marking the device as lost, if the device is
  2429. * already DEAD.
  2430. */
  2431. if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD)
  2432. continue;
  2433. if (atomic_read(&fcport->state) == FCS_ONLINE) {
  2434. qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
  2435. if (defer)
  2436. qla2x00_schedule_rport_del(vha, fcport, defer);
  2437. else if (vha->vp_idx == fcport->vp_idx)
  2438. qla2x00_schedule_rport_del(vha, fcport, defer);
  2439. }
  2440. }
  2441. }
  2442. /*
  2443. * qla2x00_mem_alloc
  2444. * Allocates adapter memory.
  2445. *
  2446. * Returns:
  2447. * 0 = success.
  2448. * !0 = failure.
  2449. */
  2450. static int
  2451. qla2x00_mem_alloc(struct qla_hw_data *ha, uint16_t req_len, uint16_t rsp_len,
  2452. struct req_que **req, struct rsp_que **rsp)
  2453. {
  2454. char name[16];
  2455. ha->init_cb = dma_alloc_coherent(&ha->pdev->dev, ha->init_cb_size,
  2456. &ha->init_cb_dma, GFP_KERNEL);
  2457. if (!ha->init_cb)
  2458. goto fail;
  2459. ha->gid_list = dma_alloc_coherent(&ha->pdev->dev, GID_LIST_SIZE,
  2460. &ha->gid_list_dma, GFP_KERNEL);
  2461. if (!ha->gid_list)
  2462. goto fail_free_init_cb;
  2463. ha->srb_mempool = mempool_create_slab_pool(SRB_MIN_REQ, srb_cachep);
  2464. if (!ha->srb_mempool)
  2465. goto fail_free_gid_list;
  2466. if (IS_QLA82XX(ha)) {
  2467. /* Allocate cache for CT6 Ctx. */
  2468. if (!ctx_cachep) {
  2469. ctx_cachep = kmem_cache_create("qla2xxx_ctx",
  2470. sizeof(struct ct6_dsd), 0,
  2471. SLAB_HWCACHE_ALIGN, NULL);
  2472. if (!ctx_cachep)
  2473. goto fail_free_gid_list;
  2474. }
  2475. ha->ctx_mempool = mempool_create_slab_pool(SRB_MIN_REQ,
  2476. ctx_cachep);
  2477. if (!ha->ctx_mempool)
  2478. goto fail_free_srb_mempool;
  2479. ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0021,
  2480. "ctx_cachep=%p ctx_mempool=%p.\n",
  2481. ctx_cachep, ha->ctx_mempool);
  2482. }
  2483. /* Get memory for cached NVRAM */
  2484. ha->nvram = kzalloc(MAX_NVRAM_SIZE, GFP_KERNEL);
  2485. if (!ha->nvram)
  2486. goto fail_free_ctx_mempool;
  2487. snprintf(name, sizeof(name), "%s_%d", QLA2XXX_DRIVER_NAME,
  2488. ha->pdev->device);
  2489. ha->s_dma_pool = dma_pool_create(name, &ha->pdev->dev,
  2490. DMA_POOL_SIZE, 8, 0);
  2491. if (!ha->s_dma_pool)
  2492. goto fail_free_nvram;
  2493. ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0022,
  2494. "init_cb=%p gid_list=%p, srb_mempool=%p s_dma_pool=%p.\n",
  2495. ha->init_cb, ha->gid_list, ha->srb_mempool, ha->s_dma_pool);
  2496. if (IS_QLA82XX(ha) || ql2xenabledif) {
  2497. ha->dl_dma_pool = dma_pool_create(name, &ha->pdev->dev,
  2498. DSD_LIST_DMA_POOL_SIZE, 8, 0);
  2499. if (!ha->dl_dma_pool) {
  2500. ql_log_pci(ql_log_fatal, ha->pdev, 0x0023,
  2501. "Failed to allocate memory for dl_dma_pool.\n");
  2502. goto fail_s_dma_pool;
  2503. }
  2504. ha->fcp_cmnd_dma_pool = dma_pool_create(name, &ha->pdev->dev,
  2505. FCP_CMND_DMA_POOL_SIZE, 8, 0);
  2506. if (!ha->fcp_cmnd_dma_pool) {
  2507. ql_log_pci(ql_log_fatal, ha->pdev, 0x0024,
  2508. "Failed to allocate memory for fcp_cmnd_dma_pool.\n");
  2509. goto fail_dl_dma_pool;
  2510. }
  2511. ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0025,
  2512. "dl_dma_pool=%p fcp_cmnd_dma_pool=%p.\n",
  2513. ha->dl_dma_pool, ha->fcp_cmnd_dma_pool);
  2514. }
  2515. /* Allocate memory for SNS commands */
  2516. if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
  2517. /* Get consistent memory allocated for SNS commands */
  2518. ha->sns_cmd = dma_alloc_coherent(&ha->pdev->dev,
  2519. sizeof(struct sns_cmd_pkt), &ha->sns_cmd_dma, GFP_KERNEL);
  2520. if (!ha->sns_cmd)
  2521. goto fail_dma_pool;
  2522. ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0026,
  2523. "sns_cmd.\n", ha->sns_cmd);
  2524. } else {
  2525. /* Get consistent memory allocated for MS IOCB */
  2526. ha->ms_iocb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
  2527. &ha->ms_iocb_dma);
  2528. if (!ha->ms_iocb)
  2529. goto fail_dma_pool;
  2530. /* Get consistent memory allocated for CT SNS commands */
  2531. ha->ct_sns = dma_alloc_coherent(&ha->pdev->dev,
  2532. sizeof(struct ct_sns_pkt), &ha->ct_sns_dma, GFP_KERNEL);
  2533. if (!ha->ct_sns)
  2534. goto fail_free_ms_iocb;
  2535. ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0027,
  2536. "ms_iocb=%p ct_sns=%p.\n",
  2537. ha->ms_iocb, ha->ct_sns);
  2538. }
  2539. /* Allocate memory for request ring */
  2540. *req = kzalloc(sizeof(struct req_que), GFP_KERNEL);
  2541. if (!*req) {
  2542. ql_log_pci(ql_log_fatal, ha->pdev, 0x0028,
  2543. "Failed to allocate memory for req.\n");
  2544. goto fail_req;
  2545. }
  2546. (*req)->length = req_len;
  2547. (*req)->ring = dma_alloc_coherent(&ha->pdev->dev,
  2548. ((*req)->length + 1) * sizeof(request_t),
  2549. &(*req)->dma, GFP_KERNEL);
  2550. if (!(*req)->ring) {
  2551. ql_log_pci(ql_log_fatal, ha->pdev, 0x0029,
  2552. "Failed to allocate memory for req_ring.\n");
  2553. goto fail_req_ring;
  2554. }
  2555. /* Allocate memory for response ring */
  2556. *rsp = kzalloc(sizeof(struct rsp_que), GFP_KERNEL);
  2557. if (!*rsp) {
  2558. ql_log_pci(ql_log_fatal, ha->pdev, 0x002a,
  2559. "Failed to allocate memory for rsp.\n");
  2560. goto fail_rsp;
  2561. }
  2562. (*rsp)->hw = ha;
  2563. (*rsp)->length = rsp_len;
  2564. (*rsp)->ring = dma_alloc_coherent(&ha->pdev->dev,
  2565. ((*rsp)->length + 1) * sizeof(response_t),
  2566. &(*rsp)->dma, GFP_KERNEL);
  2567. if (!(*rsp)->ring) {
  2568. ql_log_pci(ql_log_fatal, ha->pdev, 0x002b,
  2569. "Failed to allocate memory for rsp_ring.\n");
  2570. goto fail_rsp_ring;
  2571. }
  2572. (*req)->rsp = *rsp;
  2573. (*rsp)->req = *req;
  2574. ql_dbg_pci(ql_dbg_init, ha->pdev, 0x002c,
  2575. "req=%p req->length=%d req->ring=%p rsp=%p "
  2576. "rsp->length=%d rsp->ring=%p.\n",
  2577. *req, (*req)->length, (*req)->ring, *rsp, (*rsp)->length,
  2578. (*rsp)->ring);
  2579. /* Allocate memory for NVRAM data for vports */
  2580. if (ha->nvram_npiv_size) {
  2581. ha->npiv_info = kzalloc(sizeof(struct qla_npiv_entry) *
  2582. ha->nvram_npiv_size, GFP_KERNEL);
  2583. if (!ha->npiv_info) {
  2584. ql_log_pci(ql_log_fatal, ha->pdev, 0x002d,
  2585. "Failed to allocate memory for npiv_info.\n");
  2586. goto fail_npiv_info;
  2587. }
  2588. } else
  2589. ha->npiv_info = NULL;
  2590. /* Get consistent memory allocated for EX-INIT-CB. */
  2591. if (IS_QLA8XXX_TYPE(ha)) {
  2592. ha->ex_init_cb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
  2593. &ha->ex_init_cb_dma);
  2594. if (!ha->ex_init_cb)
  2595. goto fail_ex_init_cb;
  2596. ql_dbg_pci(ql_dbg_init, ha->pdev, 0x002e,
  2597. "ex_init_cb=%p.\n", ha->ex_init_cb);
  2598. }
  2599. INIT_LIST_HEAD(&ha->gbl_dsd_list);
  2600. /* Get consistent memory allocated for Async Port-Database. */
  2601. if (!IS_FWI2_CAPABLE(ha)) {
  2602. ha->async_pd = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
  2603. &ha->async_pd_dma);
  2604. if (!ha->async_pd)
  2605. goto fail_async_pd;
  2606. ql_dbg_pci(ql_dbg_init, ha->pdev, 0x002f,
  2607. "async_pd=%p.\n", ha->async_pd);
  2608. }
  2609. INIT_LIST_HEAD(&ha->vp_list);
  2610. return 1;
  2611. fail_async_pd:
  2612. dma_pool_free(ha->s_dma_pool, ha->ex_init_cb, ha->ex_init_cb_dma);
  2613. fail_ex_init_cb:
  2614. kfree(ha->npiv_info);
  2615. fail_npiv_info:
  2616. dma_free_coherent(&ha->pdev->dev, ((*rsp)->length + 1) *
  2617. sizeof(response_t), (*rsp)->ring, (*rsp)->dma);
  2618. (*rsp)->ring = NULL;
  2619. (*rsp)->dma = 0;
  2620. fail_rsp_ring:
  2621. kfree(*rsp);
  2622. fail_rsp:
  2623. dma_free_coherent(&ha->pdev->dev, ((*req)->length + 1) *
  2624. sizeof(request_t), (*req)->ring, (*req)->dma);
  2625. (*req)->ring = NULL;
  2626. (*req)->dma = 0;
  2627. fail_req_ring:
  2628. kfree(*req);
  2629. fail_req:
  2630. dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
  2631. ha->ct_sns, ha->ct_sns_dma);
  2632. ha->ct_sns = NULL;
  2633. ha->ct_sns_dma = 0;
  2634. fail_free_ms_iocb:
  2635. dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
  2636. ha->ms_iocb = NULL;
  2637. ha->ms_iocb_dma = 0;
  2638. fail_dma_pool:
  2639. if (IS_QLA82XX(ha) || ql2xenabledif) {
  2640. dma_pool_destroy(ha->fcp_cmnd_dma_pool);
  2641. ha->fcp_cmnd_dma_pool = NULL;
  2642. }
  2643. fail_dl_dma_pool:
  2644. if (IS_QLA82XX(ha) || ql2xenabledif) {
  2645. dma_pool_destroy(ha->dl_dma_pool);
  2646. ha->dl_dma_pool = NULL;
  2647. }
  2648. fail_s_dma_pool:
  2649. dma_pool_destroy(ha->s_dma_pool);
  2650. ha->s_dma_pool = NULL;
  2651. fail_free_nvram:
  2652. kfree(ha->nvram);
  2653. ha->nvram = NULL;
  2654. fail_free_ctx_mempool:
  2655. mempool_destroy(ha->ctx_mempool);
  2656. ha->ctx_mempool = NULL;
  2657. fail_free_srb_mempool:
  2658. mempool_destroy(ha->srb_mempool);
  2659. ha->srb_mempool = NULL;
  2660. fail_free_gid_list:
  2661. dma_free_coherent(&ha->pdev->dev, GID_LIST_SIZE, ha->gid_list,
  2662. ha->gid_list_dma);
  2663. ha->gid_list = NULL;
  2664. ha->gid_list_dma = 0;
  2665. fail_free_init_cb:
  2666. dma_free_coherent(&ha->pdev->dev, ha->init_cb_size, ha->init_cb,
  2667. ha->init_cb_dma);
  2668. ha->init_cb = NULL;
  2669. ha->init_cb_dma = 0;
  2670. fail:
  2671. ql_log(ql_log_fatal, NULL, 0x0030,
  2672. "Memory allocation failure.\n");
  2673. return -ENOMEM;
  2674. }
  2675. /*
  2676. * qla2x00_free_fw_dump
  2677. * Frees fw dump stuff.
  2678. *
  2679. * Input:
  2680. * ha = adapter block pointer.
  2681. */
  2682. static void
  2683. qla2x00_free_fw_dump(struct qla_hw_data *ha)
  2684. {
  2685. if (ha->fce)
  2686. dma_free_coherent(&ha->pdev->dev, FCE_SIZE, ha->fce,
  2687. ha->fce_dma);
  2688. if (ha->fw_dump) {
  2689. if (ha->eft)
  2690. dma_free_coherent(&ha->pdev->dev,
  2691. ntohl(ha->fw_dump->eft_size), ha->eft, ha->eft_dma);
  2692. vfree(ha->fw_dump);
  2693. }
  2694. ha->fce = NULL;
  2695. ha->fce_dma = 0;
  2696. ha->eft = NULL;
  2697. ha->eft_dma = 0;
  2698. ha->fw_dump = NULL;
  2699. ha->fw_dumped = 0;
  2700. ha->fw_dump_reading = 0;
  2701. }
  2702. /*
  2703. * qla2x00_mem_free
  2704. * Frees all adapter allocated memory.
  2705. *
  2706. * Input:
  2707. * ha = adapter block pointer.
  2708. */
  2709. static void
  2710. qla2x00_mem_free(struct qla_hw_data *ha)
  2711. {
  2712. qla2x00_free_fw_dump(ha);
  2713. if (ha->srb_mempool)
  2714. mempool_destroy(ha->srb_mempool);
  2715. if (ha->dcbx_tlv)
  2716. dma_free_coherent(&ha->pdev->dev, DCBX_TLV_DATA_SIZE,
  2717. ha->dcbx_tlv, ha->dcbx_tlv_dma);
  2718. if (ha->xgmac_data)
  2719. dma_free_coherent(&ha->pdev->dev, XGMAC_DATA_SIZE,
  2720. ha->xgmac_data, ha->xgmac_data_dma);
  2721. if (ha->sns_cmd)
  2722. dma_free_coherent(&ha->pdev->dev, sizeof(struct sns_cmd_pkt),
  2723. ha->sns_cmd, ha->sns_cmd_dma);
  2724. if (ha->ct_sns)
  2725. dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
  2726. ha->ct_sns, ha->ct_sns_dma);
  2727. if (ha->sfp_data)
  2728. dma_pool_free(ha->s_dma_pool, ha->sfp_data, ha->sfp_data_dma);
  2729. if (ha->edc_data)
  2730. dma_pool_free(ha->s_dma_pool, ha->edc_data, ha->edc_data_dma);
  2731. if (ha->ms_iocb)
  2732. dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
  2733. if (ha->ex_init_cb)
  2734. dma_pool_free(ha->s_dma_pool,
  2735. ha->ex_init_cb, ha->ex_init_cb_dma);
  2736. if (ha->async_pd)
  2737. dma_pool_free(ha->s_dma_pool, ha->async_pd, ha->async_pd_dma);
  2738. if (ha->s_dma_pool)
  2739. dma_pool_destroy(ha->s_dma_pool);
  2740. if (ha->gid_list)
  2741. dma_free_coherent(&ha->pdev->dev, GID_LIST_SIZE, ha->gid_list,
  2742. ha->gid_list_dma);
  2743. if (IS_QLA82XX(ha)) {
  2744. if (!list_empty(&ha->gbl_dsd_list)) {
  2745. struct dsd_dma *dsd_ptr, *tdsd_ptr;
  2746. /* clean up allocated prev pool */
  2747. list_for_each_entry_safe(dsd_ptr,
  2748. tdsd_ptr, &ha->gbl_dsd_list, list) {
  2749. dma_pool_free(ha->dl_dma_pool,
  2750. dsd_ptr->dsd_addr, dsd_ptr->dsd_list_dma);
  2751. list_del(&dsd_ptr->list);
  2752. kfree(dsd_ptr);
  2753. }
  2754. }
  2755. }
  2756. if (ha->dl_dma_pool)
  2757. dma_pool_destroy(ha->dl_dma_pool);
  2758. if (ha->fcp_cmnd_dma_pool)
  2759. dma_pool_destroy(ha->fcp_cmnd_dma_pool);
  2760. if (ha->ctx_mempool)
  2761. mempool_destroy(ha->ctx_mempool);
  2762. if (ha->init_cb)
  2763. dma_free_coherent(&ha->pdev->dev, ha->init_cb_size,
  2764. ha->init_cb, ha->init_cb_dma);
  2765. vfree(ha->optrom_buffer);
  2766. kfree(ha->nvram);
  2767. kfree(ha->npiv_info);
  2768. ha->srb_mempool = NULL;
  2769. ha->ctx_mempool = NULL;
  2770. ha->sns_cmd = NULL;
  2771. ha->sns_cmd_dma = 0;
  2772. ha->ct_sns = NULL;
  2773. ha->ct_sns_dma = 0;
  2774. ha->ms_iocb = NULL;
  2775. ha->ms_iocb_dma = 0;
  2776. ha->init_cb = NULL;
  2777. ha->init_cb_dma = 0;
  2778. ha->ex_init_cb = NULL;
  2779. ha->ex_init_cb_dma = 0;
  2780. ha->async_pd = NULL;
  2781. ha->async_pd_dma = 0;
  2782. ha->s_dma_pool = NULL;
  2783. ha->dl_dma_pool = NULL;
  2784. ha->fcp_cmnd_dma_pool = NULL;
  2785. ha->gid_list = NULL;
  2786. ha->gid_list_dma = 0;
  2787. }
  2788. struct scsi_qla_host *qla2x00_create_host(struct scsi_host_template *sht,
  2789. struct qla_hw_data *ha)
  2790. {
  2791. struct Scsi_Host *host;
  2792. struct scsi_qla_host *vha = NULL;
  2793. host = scsi_host_alloc(sht, sizeof(scsi_qla_host_t));
  2794. if (host == NULL) {
  2795. ql_log_pci(ql_log_fatal, ha->pdev, 0x0107,
  2796. "Failed to allocate host from the scsi layer, aborting.\n");
  2797. goto fail;
  2798. }
  2799. /* Clear our data area */
  2800. vha = shost_priv(host);
  2801. memset(vha, 0, sizeof(scsi_qla_host_t));
  2802. vha->host = host;
  2803. vha->host_no = host->host_no;
  2804. vha->hw = ha;
  2805. INIT_LIST_HEAD(&vha->vp_fcports);
  2806. INIT_LIST_HEAD(&vha->work_list);
  2807. INIT_LIST_HEAD(&vha->list);
  2808. spin_lock_init(&vha->work_lock);
  2809. sprintf(vha->host_str, "%s_%ld", QLA2XXX_DRIVER_NAME, vha->host_no);
  2810. ql_dbg(ql_dbg_init, vha, 0x0041,
  2811. "Allocated the host=%p hw=%p vha=%p dev_name=%s",
  2812. vha->host, vha->hw, vha,
  2813. dev_name(&(ha->pdev->dev)));
  2814. return vha;
  2815. fail:
  2816. return vha;
  2817. }
  2818. static struct qla_work_evt *
  2819. qla2x00_alloc_work(struct scsi_qla_host *vha, enum qla_work_type type)
  2820. {
  2821. struct qla_work_evt *e;
  2822. uint8_t bail;
  2823. QLA_VHA_MARK_BUSY(vha, bail);
  2824. if (bail)
  2825. return NULL;
  2826. e = kzalloc(sizeof(struct qla_work_evt), GFP_ATOMIC);
  2827. if (!e) {
  2828. QLA_VHA_MARK_NOT_BUSY(vha);
  2829. return NULL;
  2830. }
  2831. INIT_LIST_HEAD(&e->list);
  2832. e->type = type;
  2833. e->flags = QLA_EVT_FLAG_FREE;
  2834. return e;
  2835. }
  2836. static int
  2837. qla2x00_post_work(struct scsi_qla_host *vha, struct qla_work_evt *e)
  2838. {
  2839. unsigned long flags;
  2840. spin_lock_irqsave(&vha->work_lock, flags);
  2841. list_add_tail(&e->list, &vha->work_list);
  2842. spin_unlock_irqrestore(&vha->work_lock, flags);
  2843. qla2xxx_wake_dpc(vha);
  2844. return QLA_SUCCESS;
  2845. }
  2846. int
  2847. qla2x00_post_aen_work(struct scsi_qla_host *vha, enum fc_host_event_code code,
  2848. u32 data)
  2849. {
  2850. struct qla_work_evt *e;
  2851. e = qla2x00_alloc_work(vha, QLA_EVT_AEN);
  2852. if (!e)
  2853. return QLA_FUNCTION_FAILED;
  2854. e->u.aen.code = code;
  2855. e->u.aen.data = data;
  2856. return qla2x00_post_work(vha, e);
  2857. }
  2858. int
  2859. qla2x00_post_idc_ack_work(struct scsi_qla_host *vha, uint16_t *mb)
  2860. {
  2861. struct qla_work_evt *e;
  2862. e = qla2x00_alloc_work(vha, QLA_EVT_IDC_ACK);
  2863. if (!e)
  2864. return QLA_FUNCTION_FAILED;
  2865. memcpy(e->u.idc_ack.mb, mb, QLA_IDC_ACK_REGS * sizeof(uint16_t));
  2866. return qla2x00_post_work(vha, e);
  2867. }
  2868. #define qla2x00_post_async_work(name, type) \
  2869. int qla2x00_post_async_##name##_work( \
  2870. struct scsi_qla_host *vha, \
  2871. fc_port_t *fcport, uint16_t *data) \
  2872. { \
  2873. struct qla_work_evt *e; \
  2874. \
  2875. e = qla2x00_alloc_work(vha, type); \
  2876. if (!e) \
  2877. return QLA_FUNCTION_FAILED; \
  2878. \
  2879. e->u.logio.fcport = fcport; \
  2880. if (data) { \
  2881. e->u.logio.data[0] = data[0]; \
  2882. e->u.logio.data[1] = data[1]; \
  2883. } \
  2884. return qla2x00_post_work(vha, e); \
  2885. }
  2886. qla2x00_post_async_work(login, QLA_EVT_ASYNC_LOGIN);
  2887. qla2x00_post_async_work(login_done, QLA_EVT_ASYNC_LOGIN_DONE);
  2888. qla2x00_post_async_work(logout, QLA_EVT_ASYNC_LOGOUT);
  2889. qla2x00_post_async_work(logout_done, QLA_EVT_ASYNC_LOGOUT_DONE);
  2890. qla2x00_post_async_work(adisc, QLA_EVT_ASYNC_ADISC);
  2891. qla2x00_post_async_work(adisc_done, QLA_EVT_ASYNC_ADISC_DONE);
  2892. int
  2893. qla2x00_post_uevent_work(struct scsi_qla_host *vha, u32 code)
  2894. {
  2895. struct qla_work_evt *e;
  2896. e = qla2x00_alloc_work(vha, QLA_EVT_UEVENT);
  2897. if (!e)
  2898. return QLA_FUNCTION_FAILED;
  2899. e->u.uevent.code = code;
  2900. return qla2x00_post_work(vha, e);
  2901. }
  2902. static void
  2903. qla2x00_uevent_emit(struct scsi_qla_host *vha, u32 code)
  2904. {
  2905. char event_string[40];
  2906. char *envp[] = { event_string, NULL };
  2907. switch (code) {
  2908. case QLA_UEVENT_CODE_FW_DUMP:
  2909. snprintf(event_string, sizeof(event_string), "FW_DUMP=%ld",
  2910. vha->host_no);
  2911. break;
  2912. default:
  2913. /* do nothing */
  2914. break;
  2915. }
  2916. kobject_uevent_env(&vha->hw->pdev->dev.kobj, KOBJ_CHANGE, envp);
  2917. }
  2918. void
  2919. qla2x00_do_work(struct scsi_qla_host *vha)
  2920. {
  2921. struct qla_work_evt *e, *tmp;
  2922. unsigned long flags;
  2923. LIST_HEAD(work);
  2924. spin_lock_irqsave(&vha->work_lock, flags);
  2925. list_splice_init(&vha->work_list, &work);
  2926. spin_unlock_irqrestore(&vha->work_lock, flags);
  2927. list_for_each_entry_safe(e, tmp, &work, list) {
  2928. list_del_init(&e->list);
  2929. switch (e->type) {
  2930. case QLA_EVT_AEN:
  2931. fc_host_post_event(vha->host, fc_get_event_number(),
  2932. e->u.aen.code, e->u.aen.data);
  2933. break;
  2934. case QLA_EVT_IDC_ACK:
  2935. qla81xx_idc_ack(vha, e->u.idc_ack.mb);
  2936. break;
  2937. case QLA_EVT_ASYNC_LOGIN:
  2938. qla2x00_async_login(vha, e->u.logio.fcport,
  2939. e->u.logio.data);
  2940. break;
  2941. case QLA_EVT_ASYNC_LOGIN_DONE:
  2942. qla2x00_async_login_done(vha, e->u.logio.fcport,
  2943. e->u.logio.data);
  2944. break;
  2945. case QLA_EVT_ASYNC_LOGOUT:
  2946. qla2x00_async_logout(vha, e->u.logio.fcport);
  2947. break;
  2948. case QLA_EVT_ASYNC_LOGOUT_DONE:
  2949. qla2x00_async_logout_done(vha, e->u.logio.fcport,
  2950. e->u.logio.data);
  2951. break;
  2952. case QLA_EVT_ASYNC_ADISC:
  2953. qla2x00_async_adisc(vha, e->u.logio.fcport,
  2954. e->u.logio.data);
  2955. break;
  2956. case QLA_EVT_ASYNC_ADISC_DONE:
  2957. qla2x00_async_adisc_done(vha, e->u.logio.fcport,
  2958. e->u.logio.data);
  2959. break;
  2960. case QLA_EVT_UEVENT:
  2961. qla2x00_uevent_emit(vha, e->u.uevent.code);
  2962. break;
  2963. }
  2964. if (e->flags & QLA_EVT_FLAG_FREE)
  2965. kfree(e);
  2966. /* For each work completed decrement vha ref count */
  2967. QLA_VHA_MARK_NOT_BUSY(vha);
  2968. }
  2969. }
  2970. /* Relogins all the fcports of a vport
  2971. * Context: dpc thread
  2972. */
  2973. void qla2x00_relogin(struct scsi_qla_host *vha)
  2974. {
  2975. fc_port_t *fcport;
  2976. int status;
  2977. uint16_t next_loopid = 0;
  2978. struct qla_hw_data *ha = vha->hw;
  2979. uint16_t data[2];
  2980. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  2981. /*
  2982. * If the port is not ONLINE then try to login
  2983. * to it if we haven't run out of retries.
  2984. */
  2985. if (atomic_read(&fcport->state) != FCS_ONLINE &&
  2986. fcport->login_retry && !(fcport->flags & FCF_ASYNC_SENT)) {
  2987. fcport->login_retry--;
  2988. if (fcport->flags & FCF_FABRIC_DEVICE) {
  2989. if (fcport->flags & FCF_FCP2_DEVICE)
  2990. ha->isp_ops->fabric_logout(vha,
  2991. fcport->loop_id,
  2992. fcport->d_id.b.domain,
  2993. fcport->d_id.b.area,
  2994. fcport->d_id.b.al_pa);
  2995. if (fcport->loop_id == FC_NO_LOOP_ID) {
  2996. fcport->loop_id = next_loopid =
  2997. ha->min_external_loopid;
  2998. status = qla2x00_find_new_loop_id(
  2999. vha, fcport);
  3000. if (status != QLA_SUCCESS) {
  3001. /* Ran out of IDs to use */
  3002. break;
  3003. }
  3004. }
  3005. if (IS_ALOGIO_CAPABLE(ha)) {
  3006. fcport->flags |= FCF_ASYNC_SENT;
  3007. data[0] = 0;
  3008. data[1] = QLA_LOGIO_LOGIN_RETRIED;
  3009. status = qla2x00_post_async_login_work(
  3010. vha, fcport, data);
  3011. if (status == QLA_SUCCESS)
  3012. continue;
  3013. /* Attempt a retry. */
  3014. status = 1;
  3015. } else
  3016. status = qla2x00_fabric_login(vha,
  3017. fcport, &next_loopid);
  3018. } else
  3019. status = qla2x00_local_device_login(vha,
  3020. fcport);
  3021. if (status == QLA_SUCCESS) {
  3022. fcport->old_loop_id = fcport->loop_id;
  3023. ql_dbg(ql_dbg_disc, vha, 0x2003,
  3024. "Port login OK: logged in ID 0x%x.\n",
  3025. fcport->loop_id);
  3026. qla2x00_update_fcport(vha, fcport);
  3027. } else if (status == 1) {
  3028. set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
  3029. /* retry the login again */
  3030. ql_dbg(ql_dbg_disc, vha, 0x2007,
  3031. "Retrying %d login again loop_id 0x%x.\n",
  3032. fcport->login_retry, fcport->loop_id);
  3033. } else {
  3034. fcport->login_retry = 0;
  3035. }
  3036. if (fcport->login_retry == 0 && status != QLA_SUCCESS)
  3037. fcport->loop_id = FC_NO_LOOP_ID;
  3038. }
  3039. if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
  3040. break;
  3041. }
  3042. }
  3043. /**************************************************************************
  3044. * qla2x00_do_dpc
  3045. * This kernel thread is a task that is schedule by the interrupt handler
  3046. * to perform the background processing for interrupts.
  3047. *
  3048. * Notes:
  3049. * This task always run in the context of a kernel thread. It
  3050. * is kick-off by the driver's detect code and starts up
  3051. * up one per adapter. It immediately goes to sleep and waits for
  3052. * some fibre event. When either the interrupt handler or
  3053. * the timer routine detects a event it will one of the task
  3054. * bits then wake us up.
  3055. **************************************************************************/
  3056. static int
  3057. qla2x00_do_dpc(void *data)
  3058. {
  3059. int rval;
  3060. scsi_qla_host_t *base_vha;
  3061. struct qla_hw_data *ha;
  3062. ha = (struct qla_hw_data *)data;
  3063. base_vha = pci_get_drvdata(ha->pdev);
  3064. set_user_nice(current, -20);
  3065. set_current_state(TASK_INTERRUPTIBLE);
  3066. while (!kthread_should_stop()) {
  3067. ql_dbg(ql_dbg_dpc, base_vha, 0x4000,
  3068. "DPC handler sleeping.\n");
  3069. schedule();
  3070. __set_current_state(TASK_RUNNING);
  3071. ql_dbg(ql_dbg_dpc, base_vha, 0x4001,
  3072. "DPC handler waking up.\n");
  3073. ql_dbg(ql_dbg_dpc, base_vha, 0x4002,
  3074. "dpc_flags=0x%lx.\n", base_vha->dpc_flags);
  3075. /* Initialization not yet finished. Don't do anything yet. */
  3076. if (!base_vha->flags.init_done)
  3077. continue;
  3078. if (ha->flags.eeh_busy) {
  3079. ql_dbg(ql_dbg_dpc, base_vha, 0x4003,
  3080. "eeh_busy=%d.\n", ha->flags.eeh_busy);
  3081. continue;
  3082. }
  3083. ha->dpc_active = 1;
  3084. if (ha->flags.mbox_busy) {
  3085. ha->dpc_active = 0;
  3086. continue;
  3087. }
  3088. qla2x00_do_work(base_vha);
  3089. if (IS_QLA82XX(ha)) {
  3090. if (test_and_clear_bit(ISP_UNRECOVERABLE,
  3091. &base_vha->dpc_flags)) {
  3092. qla82xx_idc_lock(ha);
  3093. qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
  3094. QLA82XX_DEV_FAILED);
  3095. qla82xx_idc_unlock(ha);
  3096. ql_log(ql_log_info, base_vha, 0x4004,
  3097. "HW State: FAILED.\n");
  3098. qla82xx_device_state_handler(base_vha);
  3099. continue;
  3100. }
  3101. if (test_and_clear_bit(FCOE_CTX_RESET_NEEDED,
  3102. &base_vha->dpc_flags)) {
  3103. ql_dbg(ql_dbg_dpc, base_vha, 0x4005,
  3104. "FCoE context reset scheduled.\n");
  3105. if (!(test_and_set_bit(ABORT_ISP_ACTIVE,
  3106. &base_vha->dpc_flags))) {
  3107. if (qla82xx_fcoe_ctx_reset(base_vha)) {
  3108. /* FCoE-ctx reset failed.
  3109. * Escalate to chip-reset
  3110. */
  3111. set_bit(ISP_ABORT_NEEDED,
  3112. &base_vha->dpc_flags);
  3113. }
  3114. clear_bit(ABORT_ISP_ACTIVE,
  3115. &base_vha->dpc_flags);
  3116. }
  3117. ql_dbg(ql_dbg_dpc, base_vha, 0x4006,
  3118. "FCoE context reset end.\n");
  3119. }
  3120. }
  3121. if (test_and_clear_bit(ISP_ABORT_NEEDED,
  3122. &base_vha->dpc_flags)) {
  3123. ql_dbg(ql_dbg_dpc, base_vha, 0x4007,
  3124. "ISP abort scheduled.\n");
  3125. if (!(test_and_set_bit(ABORT_ISP_ACTIVE,
  3126. &base_vha->dpc_flags))) {
  3127. if (ha->isp_ops->abort_isp(base_vha)) {
  3128. /* failed. retry later */
  3129. set_bit(ISP_ABORT_NEEDED,
  3130. &base_vha->dpc_flags);
  3131. }
  3132. clear_bit(ABORT_ISP_ACTIVE,
  3133. &base_vha->dpc_flags);
  3134. }
  3135. ql_dbg(ql_dbg_dpc, base_vha, 0x4008,
  3136. "ISP abort end.\n");
  3137. }
  3138. if (test_bit(FCPORT_UPDATE_NEEDED, &base_vha->dpc_flags)) {
  3139. qla2x00_update_fcports(base_vha);
  3140. clear_bit(FCPORT_UPDATE_NEEDED, &base_vha->dpc_flags);
  3141. }
  3142. if (test_bit(ISP_QUIESCE_NEEDED, &base_vha->dpc_flags)) {
  3143. ql_dbg(ql_dbg_dpc, base_vha, 0x4009,
  3144. "Quiescence mode scheduled.\n");
  3145. qla82xx_device_state_handler(base_vha);
  3146. clear_bit(ISP_QUIESCE_NEEDED, &base_vha->dpc_flags);
  3147. if (!ha->flags.quiesce_owner) {
  3148. qla2x00_perform_loop_resync(base_vha);
  3149. qla82xx_idc_lock(ha);
  3150. qla82xx_clear_qsnt_ready(base_vha);
  3151. qla82xx_idc_unlock(ha);
  3152. }
  3153. ql_dbg(ql_dbg_dpc, base_vha, 0x400a,
  3154. "Quiescence mode end.\n");
  3155. }
  3156. if (test_and_clear_bit(RESET_MARKER_NEEDED,
  3157. &base_vha->dpc_flags) &&
  3158. (!(test_and_set_bit(RESET_ACTIVE, &base_vha->dpc_flags)))) {
  3159. ql_dbg(ql_dbg_dpc, base_vha, 0x400b,
  3160. "Reset marker scheduled.\n");
  3161. qla2x00_rst_aen(base_vha);
  3162. clear_bit(RESET_ACTIVE, &base_vha->dpc_flags);
  3163. ql_dbg(ql_dbg_dpc, base_vha, 0x400c,
  3164. "Reset marker end.\n");
  3165. }
  3166. /* Retry each device up to login retry count */
  3167. if ((test_and_clear_bit(RELOGIN_NEEDED,
  3168. &base_vha->dpc_flags)) &&
  3169. !test_bit(LOOP_RESYNC_NEEDED, &base_vha->dpc_flags) &&
  3170. atomic_read(&base_vha->loop_state) != LOOP_DOWN) {
  3171. ql_dbg(ql_dbg_dpc, base_vha, 0x400d,
  3172. "Relogin scheduled.\n");
  3173. qla2x00_relogin(base_vha);
  3174. ql_dbg(ql_dbg_dpc, base_vha, 0x400e,
  3175. "Relogin end.\n");
  3176. }
  3177. if (test_and_clear_bit(LOOP_RESYNC_NEEDED,
  3178. &base_vha->dpc_flags)) {
  3179. ql_dbg(ql_dbg_dpc, base_vha, 0x400f,
  3180. "Loop resync scheduled.\n");
  3181. if (!(test_and_set_bit(LOOP_RESYNC_ACTIVE,
  3182. &base_vha->dpc_flags))) {
  3183. rval = qla2x00_loop_resync(base_vha);
  3184. clear_bit(LOOP_RESYNC_ACTIVE,
  3185. &base_vha->dpc_flags);
  3186. }
  3187. ql_dbg(ql_dbg_dpc, base_vha, 0x4010,
  3188. "Loop resync end.\n");
  3189. }
  3190. if (test_bit(NPIV_CONFIG_NEEDED, &base_vha->dpc_flags) &&
  3191. atomic_read(&base_vha->loop_state) == LOOP_READY) {
  3192. clear_bit(NPIV_CONFIG_NEEDED, &base_vha->dpc_flags);
  3193. qla2xxx_flash_npiv_conf(base_vha);
  3194. }
  3195. if (!ha->interrupts_on)
  3196. ha->isp_ops->enable_intrs(ha);
  3197. if (test_and_clear_bit(BEACON_BLINK_NEEDED,
  3198. &base_vha->dpc_flags))
  3199. ha->isp_ops->beacon_blink(base_vha);
  3200. qla2x00_do_dpc_all_vps(base_vha);
  3201. ha->dpc_active = 0;
  3202. set_current_state(TASK_INTERRUPTIBLE);
  3203. } /* End of while(1) */
  3204. __set_current_state(TASK_RUNNING);
  3205. ql_dbg(ql_dbg_dpc, base_vha, 0x4011,
  3206. "DPC handler exiting.\n");
  3207. /*
  3208. * Make sure that nobody tries to wake us up again.
  3209. */
  3210. ha->dpc_active = 0;
  3211. /* Cleanup any residual CTX SRBs. */
  3212. qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16);
  3213. return 0;
  3214. }
  3215. void
  3216. qla2xxx_wake_dpc(struct scsi_qla_host *vha)
  3217. {
  3218. struct qla_hw_data *ha = vha->hw;
  3219. struct task_struct *t = ha->dpc_thread;
  3220. if (!test_bit(UNLOADING, &vha->dpc_flags) && t)
  3221. wake_up_process(t);
  3222. }
  3223. /*
  3224. * qla2x00_rst_aen
  3225. * Processes asynchronous reset.
  3226. *
  3227. * Input:
  3228. * ha = adapter block pointer.
  3229. */
  3230. static void
  3231. qla2x00_rst_aen(scsi_qla_host_t *vha)
  3232. {
  3233. if (vha->flags.online && !vha->flags.reset_active &&
  3234. !atomic_read(&vha->loop_down_timer) &&
  3235. !(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags))) {
  3236. do {
  3237. clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
  3238. /*
  3239. * Issue marker command only when we are going to start
  3240. * the I/O.
  3241. */
  3242. vha->marker_needed = 1;
  3243. } while (!atomic_read(&vha->loop_down_timer) &&
  3244. (test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags)));
  3245. }
  3246. }
  3247. static void
  3248. qla2x00_sp_free_dma(srb_t *sp)
  3249. {
  3250. struct scsi_cmnd *cmd = sp->cmd;
  3251. struct qla_hw_data *ha = sp->fcport->vha->hw;
  3252. if (sp->flags & SRB_DMA_VALID) {
  3253. scsi_dma_unmap(cmd);
  3254. sp->flags &= ~SRB_DMA_VALID;
  3255. }
  3256. if (sp->flags & SRB_CRC_PROT_DMA_VALID) {
  3257. dma_unmap_sg(&ha->pdev->dev, scsi_prot_sglist(cmd),
  3258. scsi_prot_sg_count(cmd), cmd->sc_data_direction);
  3259. sp->flags &= ~SRB_CRC_PROT_DMA_VALID;
  3260. }
  3261. if (sp->flags & SRB_CRC_CTX_DSD_VALID) {
  3262. /* List assured to be having elements */
  3263. qla2x00_clean_dsd_pool(ha, sp);
  3264. sp->flags &= ~SRB_CRC_CTX_DSD_VALID;
  3265. }
  3266. if (sp->flags & SRB_CRC_CTX_DMA_VALID) {
  3267. dma_pool_free(ha->dl_dma_pool, sp->ctx,
  3268. ((struct crc_context *)sp->ctx)->crc_ctx_dma);
  3269. sp->flags &= ~SRB_CRC_CTX_DMA_VALID;
  3270. }
  3271. CMD_SP(cmd) = NULL;
  3272. }
  3273. static void
  3274. qla2x00_sp_final_compl(struct qla_hw_data *ha, srb_t *sp)
  3275. {
  3276. struct scsi_cmnd *cmd = sp->cmd;
  3277. qla2x00_sp_free_dma(sp);
  3278. if (sp->flags & SRB_FCP_CMND_DMA_VALID) {
  3279. struct ct6_dsd *ctx = sp->ctx;
  3280. dma_pool_free(ha->fcp_cmnd_dma_pool, ctx->fcp_cmnd,
  3281. ctx->fcp_cmnd_dma);
  3282. list_splice(&ctx->dsd_list, &ha->gbl_dsd_list);
  3283. ha->gbl_dsd_inuse -= ctx->dsd_use_cnt;
  3284. ha->gbl_dsd_avail += ctx->dsd_use_cnt;
  3285. mempool_free(sp->ctx, ha->ctx_mempool);
  3286. sp->ctx = NULL;
  3287. }
  3288. mempool_free(sp, ha->srb_mempool);
  3289. cmd->scsi_done(cmd);
  3290. }
  3291. void
  3292. qla2x00_sp_compl(struct qla_hw_data *ha, srb_t *sp)
  3293. {
  3294. if (atomic_read(&sp->ref_count) == 0) {
  3295. ql_dbg(ql_dbg_io, sp->fcport->vha, 0x3015,
  3296. "SP reference-count to ZERO -- sp=%p cmd=%p.\n",
  3297. sp, sp->cmd);
  3298. if (ql2xextended_error_logging & ql_dbg_io)
  3299. BUG();
  3300. return;
  3301. }
  3302. if (!atomic_dec_and_test(&sp->ref_count))
  3303. return;
  3304. qla2x00_sp_final_compl(ha, sp);
  3305. }
  3306. /**************************************************************************
  3307. * qla2x00_timer
  3308. *
  3309. * Description:
  3310. * One second timer
  3311. *
  3312. * Context: Interrupt
  3313. ***************************************************************************/
  3314. void
  3315. qla2x00_timer(scsi_qla_host_t *vha)
  3316. {
  3317. unsigned long cpu_flags = 0;
  3318. int start_dpc = 0;
  3319. int index;
  3320. srb_t *sp;
  3321. uint16_t w;
  3322. struct qla_hw_data *ha = vha->hw;
  3323. struct req_que *req;
  3324. if (ha->flags.eeh_busy) {
  3325. ql_dbg(ql_dbg_timer, vha, 0x6000,
  3326. "EEH = %d, restarting timer.\n",
  3327. ha->flags.eeh_busy);
  3328. qla2x00_restart_timer(vha, WATCH_INTERVAL);
  3329. return;
  3330. }
  3331. /* Hardware read to raise pending EEH errors during mailbox waits. */
  3332. if (!pci_channel_offline(ha->pdev))
  3333. pci_read_config_word(ha->pdev, PCI_VENDOR_ID, &w);
  3334. /* Make sure qla82xx_watchdog is run only for physical port */
  3335. if (!vha->vp_idx && IS_QLA82XX(ha)) {
  3336. if (test_bit(ISP_QUIESCE_NEEDED, &vha->dpc_flags))
  3337. start_dpc++;
  3338. qla82xx_watchdog(vha);
  3339. }
  3340. /* Loop down handler. */
  3341. if (atomic_read(&vha->loop_down_timer) > 0 &&
  3342. !(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags)) &&
  3343. !(test_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags))
  3344. && vha->flags.online) {
  3345. if (atomic_read(&vha->loop_down_timer) ==
  3346. vha->loop_down_abort_time) {
  3347. ql_log(ql_log_info, vha, 0x6008,
  3348. "Loop down - aborting the queues before time expires.\n");
  3349. if (!IS_QLA2100(ha) && vha->link_down_timeout)
  3350. atomic_set(&vha->loop_state, LOOP_DEAD);
  3351. /*
  3352. * Schedule an ISP abort to return any FCP2-device
  3353. * commands.
  3354. */
  3355. /* NPIV - scan physical port only */
  3356. if (!vha->vp_idx) {
  3357. spin_lock_irqsave(&ha->hardware_lock,
  3358. cpu_flags);
  3359. req = ha->req_q_map[0];
  3360. for (index = 1;
  3361. index < MAX_OUTSTANDING_COMMANDS;
  3362. index++) {
  3363. fc_port_t *sfcp;
  3364. sp = req->outstanding_cmds[index];
  3365. if (!sp)
  3366. continue;
  3367. if (sp->ctx && !IS_PROT_IO(sp))
  3368. continue;
  3369. sfcp = sp->fcport;
  3370. if (!(sfcp->flags & FCF_FCP2_DEVICE))
  3371. continue;
  3372. if (IS_QLA82XX(ha))
  3373. set_bit(FCOE_CTX_RESET_NEEDED,
  3374. &vha->dpc_flags);
  3375. else
  3376. set_bit(ISP_ABORT_NEEDED,
  3377. &vha->dpc_flags);
  3378. break;
  3379. }
  3380. spin_unlock_irqrestore(&ha->hardware_lock,
  3381. cpu_flags);
  3382. }
  3383. start_dpc++;
  3384. }
  3385. /* if the loop has been down for 4 minutes, reinit adapter */
  3386. if (atomic_dec_and_test(&vha->loop_down_timer) != 0) {
  3387. if (!(vha->device_flags & DFLG_NO_CABLE)) {
  3388. ql_log(ql_log_warn, vha, 0x6009,
  3389. "Loop down - aborting ISP.\n");
  3390. if (IS_QLA82XX(ha))
  3391. set_bit(FCOE_CTX_RESET_NEEDED,
  3392. &vha->dpc_flags);
  3393. else
  3394. set_bit(ISP_ABORT_NEEDED,
  3395. &vha->dpc_flags);
  3396. }
  3397. }
  3398. ql_dbg(ql_dbg_timer, vha, 0x600a,
  3399. "Loop down - seconds remaining %d.\n",
  3400. atomic_read(&vha->loop_down_timer));
  3401. }
  3402. /* Check if beacon LED needs to be blinked for physical host only */
  3403. if (!vha->vp_idx && (ha->beacon_blink_led == 1)) {
  3404. set_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags);
  3405. start_dpc++;
  3406. }
  3407. /* Process any deferred work. */
  3408. if (!list_empty(&vha->work_list))
  3409. start_dpc++;
  3410. /* Schedule the DPC routine if needed */
  3411. if ((test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) ||
  3412. test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags) ||
  3413. test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags) ||
  3414. start_dpc ||
  3415. test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags) ||
  3416. test_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags) ||
  3417. test_bit(ISP_UNRECOVERABLE, &vha->dpc_flags) ||
  3418. test_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags) ||
  3419. test_bit(VP_DPC_NEEDED, &vha->dpc_flags) ||
  3420. test_bit(RELOGIN_NEEDED, &vha->dpc_flags))) {
  3421. ql_dbg(ql_dbg_timer, vha, 0x600b,
  3422. "isp_abort_needed=%d loop_resync_needed=%d "
  3423. "fcport_update_needed=%d start_dpc=%d "
  3424. "reset_marker_needed=%d",
  3425. test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags),
  3426. test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags),
  3427. test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags),
  3428. start_dpc,
  3429. test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags));
  3430. ql_dbg(ql_dbg_timer, vha, 0x600c,
  3431. "beacon_blink_needed=%d isp_unrecoverable=%d "
  3432. "fcoe_ctx_reset_needed=%d vp_dpc_needed=%d "
  3433. "relogin_needed=%d.\n",
  3434. test_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags),
  3435. test_bit(ISP_UNRECOVERABLE, &vha->dpc_flags),
  3436. test_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags),
  3437. test_bit(VP_DPC_NEEDED, &vha->dpc_flags),
  3438. test_bit(RELOGIN_NEEDED, &vha->dpc_flags));
  3439. qla2xxx_wake_dpc(vha);
  3440. }
  3441. qla2x00_restart_timer(vha, WATCH_INTERVAL);
  3442. }
  3443. /* Firmware interface routines. */
  3444. #define FW_BLOBS 8
  3445. #define FW_ISP21XX 0
  3446. #define FW_ISP22XX 1
  3447. #define FW_ISP2300 2
  3448. #define FW_ISP2322 3
  3449. #define FW_ISP24XX 4
  3450. #define FW_ISP25XX 5
  3451. #define FW_ISP81XX 6
  3452. #define FW_ISP82XX 7
  3453. #define FW_FILE_ISP21XX "ql2100_fw.bin"
  3454. #define FW_FILE_ISP22XX "ql2200_fw.bin"
  3455. #define FW_FILE_ISP2300 "ql2300_fw.bin"
  3456. #define FW_FILE_ISP2322 "ql2322_fw.bin"
  3457. #define FW_FILE_ISP24XX "ql2400_fw.bin"
  3458. #define FW_FILE_ISP25XX "ql2500_fw.bin"
  3459. #define FW_FILE_ISP81XX "ql8100_fw.bin"
  3460. #define FW_FILE_ISP82XX "ql8200_fw.bin"
  3461. static DEFINE_MUTEX(qla_fw_lock);
  3462. static struct fw_blob qla_fw_blobs[FW_BLOBS] = {
  3463. { .name = FW_FILE_ISP21XX, .segs = { 0x1000, 0 }, },
  3464. { .name = FW_FILE_ISP22XX, .segs = { 0x1000, 0 }, },
  3465. { .name = FW_FILE_ISP2300, .segs = { 0x800, 0 }, },
  3466. { .name = FW_FILE_ISP2322, .segs = { 0x800, 0x1c000, 0x1e000, 0 }, },
  3467. { .name = FW_FILE_ISP24XX, },
  3468. { .name = FW_FILE_ISP25XX, },
  3469. { .name = FW_FILE_ISP81XX, },
  3470. { .name = FW_FILE_ISP82XX, },
  3471. };
  3472. struct fw_blob *
  3473. qla2x00_request_firmware(scsi_qla_host_t *vha)
  3474. {
  3475. struct qla_hw_data *ha = vha->hw;
  3476. struct fw_blob *blob;
  3477. blob = NULL;
  3478. if (IS_QLA2100(ha)) {
  3479. blob = &qla_fw_blobs[FW_ISP21XX];
  3480. } else if (IS_QLA2200(ha)) {
  3481. blob = &qla_fw_blobs[FW_ISP22XX];
  3482. } else if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
  3483. blob = &qla_fw_blobs[FW_ISP2300];
  3484. } else if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
  3485. blob = &qla_fw_blobs[FW_ISP2322];
  3486. } else if (IS_QLA24XX_TYPE(ha)) {
  3487. blob = &qla_fw_blobs[FW_ISP24XX];
  3488. } else if (IS_QLA25XX(ha)) {
  3489. blob = &qla_fw_blobs[FW_ISP25XX];
  3490. } else if (IS_QLA81XX(ha)) {
  3491. blob = &qla_fw_blobs[FW_ISP81XX];
  3492. } else if (IS_QLA82XX(ha)) {
  3493. blob = &qla_fw_blobs[FW_ISP82XX];
  3494. }
  3495. mutex_lock(&qla_fw_lock);
  3496. if (blob->fw)
  3497. goto out;
  3498. if (request_firmware(&blob->fw, blob->name, &ha->pdev->dev)) {
  3499. ql_log(ql_log_warn, vha, 0x0063,
  3500. "Failed to load firmware image (%s).\n", blob->name);
  3501. blob->fw = NULL;
  3502. blob = NULL;
  3503. goto out;
  3504. }
  3505. out:
  3506. mutex_unlock(&qla_fw_lock);
  3507. return blob;
  3508. }
  3509. static void
  3510. qla2x00_release_firmware(void)
  3511. {
  3512. int idx;
  3513. mutex_lock(&qla_fw_lock);
  3514. for (idx = 0; idx < FW_BLOBS; idx++)
  3515. if (qla_fw_blobs[idx].fw)
  3516. release_firmware(qla_fw_blobs[idx].fw);
  3517. mutex_unlock(&qla_fw_lock);
  3518. }
  3519. static pci_ers_result_t
  3520. qla2xxx_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
  3521. {
  3522. scsi_qla_host_t *vha = pci_get_drvdata(pdev);
  3523. struct qla_hw_data *ha = vha->hw;
  3524. ql_dbg(ql_dbg_aer, vha, 0x9000,
  3525. "PCI error detected, state %x.\n", state);
  3526. switch (state) {
  3527. case pci_channel_io_normal:
  3528. ha->flags.eeh_busy = 0;
  3529. return PCI_ERS_RESULT_CAN_RECOVER;
  3530. case pci_channel_io_frozen:
  3531. ha->flags.eeh_busy = 1;
  3532. /* For ISP82XX complete any pending mailbox cmd */
  3533. if (IS_QLA82XX(ha)) {
  3534. ha->flags.isp82xx_fw_hung = 1;
  3535. if (ha->flags.mbox_busy) {
  3536. ha->flags.mbox_int = 1;
  3537. ql_dbg(ql_dbg_aer, vha, 0x9001,
  3538. "Due to pci channel io frozen, doing premature "
  3539. "completion of mbx command.\n");
  3540. complete(&ha->mbx_intr_comp);
  3541. }
  3542. }
  3543. qla2x00_free_irqs(vha);
  3544. pci_disable_device(pdev);
  3545. /* Return back all IOs */
  3546. qla2x00_abort_all_cmds(vha, DID_RESET << 16);
  3547. return PCI_ERS_RESULT_NEED_RESET;
  3548. case pci_channel_io_perm_failure:
  3549. ha->flags.pci_channel_io_perm_failure = 1;
  3550. qla2x00_abort_all_cmds(vha, DID_NO_CONNECT << 16);
  3551. return PCI_ERS_RESULT_DISCONNECT;
  3552. }
  3553. return PCI_ERS_RESULT_NEED_RESET;
  3554. }
  3555. static pci_ers_result_t
  3556. qla2xxx_pci_mmio_enabled(struct pci_dev *pdev)
  3557. {
  3558. int risc_paused = 0;
  3559. uint32_t stat;
  3560. unsigned long flags;
  3561. scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
  3562. struct qla_hw_data *ha = base_vha->hw;
  3563. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  3564. struct device_reg_24xx __iomem *reg24 = &ha->iobase->isp24;
  3565. if (IS_QLA82XX(ha))
  3566. return PCI_ERS_RESULT_RECOVERED;
  3567. spin_lock_irqsave(&ha->hardware_lock, flags);
  3568. if (IS_QLA2100(ha) || IS_QLA2200(ha)){
  3569. stat = RD_REG_DWORD(&reg->hccr);
  3570. if (stat & HCCR_RISC_PAUSE)
  3571. risc_paused = 1;
  3572. } else if (IS_QLA23XX(ha)) {
  3573. stat = RD_REG_DWORD(&reg->u.isp2300.host_status);
  3574. if (stat & HSR_RISC_PAUSED)
  3575. risc_paused = 1;
  3576. } else if (IS_FWI2_CAPABLE(ha)) {
  3577. stat = RD_REG_DWORD(&reg24->host_status);
  3578. if (stat & HSRX_RISC_PAUSED)
  3579. risc_paused = 1;
  3580. }
  3581. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  3582. if (risc_paused) {
  3583. ql_log(ql_log_info, base_vha, 0x9003,
  3584. "RISC paused -- mmio_enabled, Dumping firmware.\n");
  3585. ha->isp_ops->fw_dump(base_vha, 0);
  3586. return PCI_ERS_RESULT_NEED_RESET;
  3587. } else
  3588. return PCI_ERS_RESULT_RECOVERED;
  3589. }
  3590. uint32_t qla82xx_error_recovery(scsi_qla_host_t *base_vha)
  3591. {
  3592. uint32_t rval = QLA_FUNCTION_FAILED;
  3593. uint32_t drv_active = 0;
  3594. struct qla_hw_data *ha = base_vha->hw;
  3595. int fn;
  3596. struct pci_dev *other_pdev = NULL;
  3597. ql_dbg(ql_dbg_aer, base_vha, 0x9006,
  3598. "Entered %s.\n", __func__);
  3599. set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
  3600. if (base_vha->flags.online) {
  3601. /* Abort all outstanding commands,
  3602. * so as to be requeued later */
  3603. qla2x00_abort_isp_cleanup(base_vha);
  3604. }
  3605. fn = PCI_FUNC(ha->pdev->devfn);
  3606. while (fn > 0) {
  3607. fn--;
  3608. ql_dbg(ql_dbg_aer, base_vha, 0x9007,
  3609. "Finding pci device at function = 0x%x.\n", fn);
  3610. other_pdev =
  3611. pci_get_domain_bus_and_slot(pci_domain_nr(ha->pdev->bus),
  3612. ha->pdev->bus->number, PCI_DEVFN(PCI_SLOT(ha->pdev->devfn),
  3613. fn));
  3614. if (!other_pdev)
  3615. continue;
  3616. if (atomic_read(&other_pdev->enable_cnt)) {
  3617. ql_dbg(ql_dbg_aer, base_vha, 0x9008,
  3618. "Found PCI func available and enable at 0x%x.\n",
  3619. fn);
  3620. pci_dev_put(other_pdev);
  3621. break;
  3622. }
  3623. pci_dev_put(other_pdev);
  3624. }
  3625. if (!fn) {
  3626. /* Reset owner */
  3627. ql_dbg(ql_dbg_aer, base_vha, 0x9009,
  3628. "This devfn is reset owner = 0x%x.\n",
  3629. ha->pdev->devfn);
  3630. qla82xx_idc_lock(ha);
  3631. qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
  3632. QLA82XX_DEV_INITIALIZING);
  3633. qla82xx_wr_32(ha, QLA82XX_CRB_DRV_IDC_VERSION,
  3634. QLA82XX_IDC_VERSION);
  3635. drv_active = qla82xx_rd_32(ha, QLA82XX_CRB_DRV_ACTIVE);
  3636. ql_dbg(ql_dbg_aer, base_vha, 0x900a,
  3637. "drv_active = 0x%x.\n", drv_active);
  3638. qla82xx_idc_unlock(ha);
  3639. /* Reset if device is not already reset
  3640. * drv_active would be 0 if a reset has already been done
  3641. */
  3642. if (drv_active)
  3643. rval = qla82xx_start_firmware(base_vha);
  3644. else
  3645. rval = QLA_SUCCESS;
  3646. qla82xx_idc_lock(ha);
  3647. if (rval != QLA_SUCCESS) {
  3648. ql_log(ql_log_info, base_vha, 0x900b,
  3649. "HW State: FAILED.\n");
  3650. qla82xx_clear_drv_active(ha);
  3651. qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
  3652. QLA82XX_DEV_FAILED);
  3653. } else {
  3654. ql_log(ql_log_info, base_vha, 0x900c,
  3655. "HW State: READY.\n");
  3656. qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
  3657. QLA82XX_DEV_READY);
  3658. qla82xx_idc_unlock(ha);
  3659. ha->flags.isp82xx_fw_hung = 0;
  3660. rval = qla82xx_restart_isp(base_vha);
  3661. qla82xx_idc_lock(ha);
  3662. /* Clear driver state register */
  3663. qla82xx_wr_32(ha, QLA82XX_CRB_DRV_STATE, 0);
  3664. qla82xx_set_drv_active(base_vha);
  3665. }
  3666. qla82xx_idc_unlock(ha);
  3667. } else {
  3668. ql_dbg(ql_dbg_aer, base_vha, 0x900d,
  3669. "This devfn is not reset owner = 0x%x.\n",
  3670. ha->pdev->devfn);
  3671. if ((qla82xx_rd_32(ha, QLA82XX_CRB_DEV_STATE) ==
  3672. QLA82XX_DEV_READY)) {
  3673. ha->flags.isp82xx_fw_hung = 0;
  3674. rval = qla82xx_restart_isp(base_vha);
  3675. qla82xx_idc_lock(ha);
  3676. qla82xx_set_drv_active(base_vha);
  3677. qla82xx_idc_unlock(ha);
  3678. }
  3679. }
  3680. clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
  3681. return rval;
  3682. }
  3683. static pci_ers_result_t
  3684. qla2xxx_pci_slot_reset(struct pci_dev *pdev)
  3685. {
  3686. pci_ers_result_t ret = PCI_ERS_RESULT_DISCONNECT;
  3687. scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
  3688. struct qla_hw_data *ha = base_vha->hw;
  3689. struct rsp_que *rsp;
  3690. int rc, retries = 10;
  3691. ql_dbg(ql_dbg_aer, base_vha, 0x9004,
  3692. "Slot Reset.\n");
  3693. /* Workaround: qla2xxx driver which access hardware earlier
  3694. * needs error state to be pci_channel_io_online.
  3695. * Otherwise mailbox command timesout.
  3696. */
  3697. pdev->error_state = pci_channel_io_normal;
  3698. pci_restore_state(pdev);
  3699. /* pci_restore_state() clears the saved_state flag of the device
  3700. * save restored state which resets saved_state flag
  3701. */
  3702. pci_save_state(pdev);
  3703. if (ha->mem_only)
  3704. rc = pci_enable_device_mem(pdev);
  3705. else
  3706. rc = pci_enable_device(pdev);
  3707. if (rc) {
  3708. ql_log(ql_log_warn, base_vha, 0x9005,
  3709. "Can't re-enable PCI device after reset.\n");
  3710. goto exit_slot_reset;
  3711. }
  3712. rsp = ha->rsp_q_map[0];
  3713. if (qla2x00_request_irqs(ha, rsp))
  3714. goto exit_slot_reset;
  3715. if (ha->isp_ops->pci_config(base_vha))
  3716. goto exit_slot_reset;
  3717. if (IS_QLA82XX(ha)) {
  3718. if (qla82xx_error_recovery(base_vha) == QLA_SUCCESS) {
  3719. ret = PCI_ERS_RESULT_RECOVERED;
  3720. goto exit_slot_reset;
  3721. } else
  3722. goto exit_slot_reset;
  3723. }
  3724. while (ha->flags.mbox_busy && retries--)
  3725. msleep(1000);
  3726. set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
  3727. if (ha->isp_ops->abort_isp(base_vha) == QLA_SUCCESS)
  3728. ret = PCI_ERS_RESULT_RECOVERED;
  3729. clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
  3730. exit_slot_reset:
  3731. ql_dbg(ql_dbg_aer, base_vha, 0x900e,
  3732. "slot_reset return %x.\n", ret);
  3733. return ret;
  3734. }
  3735. static void
  3736. qla2xxx_pci_resume(struct pci_dev *pdev)
  3737. {
  3738. scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
  3739. struct qla_hw_data *ha = base_vha->hw;
  3740. int ret;
  3741. ql_dbg(ql_dbg_aer, base_vha, 0x900f,
  3742. "pci_resume.\n");
  3743. ret = qla2x00_wait_for_hba_online(base_vha);
  3744. if (ret != QLA_SUCCESS) {
  3745. ql_log(ql_log_fatal, base_vha, 0x9002,
  3746. "The device failed to resume I/O from slot/link_reset.\n");
  3747. }
  3748. pci_cleanup_aer_uncorrect_error_status(pdev);
  3749. ha->flags.eeh_busy = 0;
  3750. }
  3751. static struct pci_error_handlers qla2xxx_err_handler = {
  3752. .error_detected = qla2xxx_pci_error_detected,
  3753. .mmio_enabled = qla2xxx_pci_mmio_enabled,
  3754. .slot_reset = qla2xxx_pci_slot_reset,
  3755. .resume = qla2xxx_pci_resume,
  3756. };
  3757. static struct pci_device_id qla2xxx_pci_tbl[] = {
  3758. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2100) },
  3759. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2200) },
  3760. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2300) },
  3761. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2312) },
  3762. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2322) },
  3763. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6312) },
  3764. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6322) },
  3765. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2422) },
  3766. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2432) },
  3767. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8432) },
  3768. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5422) },
  3769. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5432) },
  3770. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2532) },
  3771. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8001) },
  3772. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8021) },
  3773. { 0 },
  3774. };
  3775. MODULE_DEVICE_TABLE(pci, qla2xxx_pci_tbl);
  3776. static struct pci_driver qla2xxx_pci_driver = {
  3777. .name = QLA2XXX_DRIVER_NAME,
  3778. .driver = {
  3779. .owner = THIS_MODULE,
  3780. },
  3781. .id_table = qla2xxx_pci_tbl,
  3782. .probe = qla2x00_probe_one,
  3783. .remove = qla2x00_remove_one,
  3784. .shutdown = qla2x00_shutdown,
  3785. .err_handler = &qla2xxx_err_handler,
  3786. };
  3787. static struct file_operations apidev_fops = {
  3788. .owner = THIS_MODULE,
  3789. .llseek = noop_llseek,
  3790. };
  3791. /**
  3792. * qla2x00_module_init - Module initialization.
  3793. **/
  3794. static int __init
  3795. qla2x00_module_init(void)
  3796. {
  3797. int ret = 0;
  3798. /* Allocate cache for SRBs. */
  3799. srb_cachep = kmem_cache_create("qla2xxx_srbs", sizeof(srb_t), 0,
  3800. SLAB_HWCACHE_ALIGN, NULL);
  3801. if (srb_cachep == NULL) {
  3802. ql_log(ql_log_fatal, NULL, 0x0001,
  3803. "Unable to allocate SRB cache...Failing load!.\n");
  3804. return -ENOMEM;
  3805. }
  3806. /* Derive version string. */
  3807. strcpy(qla2x00_version_str, QLA2XXX_VERSION);
  3808. if (ql2xextended_error_logging)
  3809. strcat(qla2x00_version_str, "-debug");
  3810. qla2xxx_transport_template =
  3811. fc_attach_transport(&qla2xxx_transport_functions);
  3812. if (!qla2xxx_transport_template) {
  3813. kmem_cache_destroy(srb_cachep);
  3814. ql_log(ql_log_fatal, NULL, 0x0002,
  3815. "fc_attach_transport failed...Failing load!.\n");
  3816. return -ENODEV;
  3817. }
  3818. apidev_major = register_chrdev(0, QLA2XXX_APIDEV, &apidev_fops);
  3819. if (apidev_major < 0) {
  3820. ql_log(ql_log_fatal, NULL, 0x0003,
  3821. "Unable to register char device %s.\n", QLA2XXX_APIDEV);
  3822. }
  3823. qla2xxx_transport_vport_template =
  3824. fc_attach_transport(&qla2xxx_transport_vport_functions);
  3825. if (!qla2xxx_transport_vport_template) {
  3826. kmem_cache_destroy(srb_cachep);
  3827. fc_release_transport(qla2xxx_transport_template);
  3828. ql_log(ql_log_fatal, NULL, 0x0004,
  3829. "fc_attach_transport vport failed...Failing load!.\n");
  3830. return -ENODEV;
  3831. }
  3832. ql_log(ql_log_info, NULL, 0x0005,
  3833. "QLogic Fibre Channel HBA Driver: %s.\n",
  3834. qla2x00_version_str);
  3835. ret = pci_register_driver(&qla2xxx_pci_driver);
  3836. if (ret) {
  3837. kmem_cache_destroy(srb_cachep);
  3838. fc_release_transport(qla2xxx_transport_template);
  3839. fc_release_transport(qla2xxx_transport_vport_template);
  3840. ql_log(ql_log_fatal, NULL, 0x0006,
  3841. "pci_register_driver failed...ret=%d Failing load!.\n",
  3842. ret);
  3843. }
  3844. return ret;
  3845. }
  3846. /**
  3847. * qla2x00_module_exit - Module cleanup.
  3848. **/
  3849. static void __exit
  3850. qla2x00_module_exit(void)
  3851. {
  3852. unregister_chrdev(apidev_major, QLA2XXX_APIDEV);
  3853. pci_unregister_driver(&qla2xxx_pci_driver);
  3854. qla2x00_release_firmware();
  3855. kmem_cache_destroy(srb_cachep);
  3856. if (ctx_cachep)
  3857. kmem_cache_destroy(ctx_cachep);
  3858. fc_release_transport(qla2xxx_transport_template);
  3859. fc_release_transport(qla2xxx_transport_vport_template);
  3860. }
  3861. module_init(qla2x00_module_init);
  3862. module_exit(qla2x00_module_exit);
  3863. MODULE_AUTHOR("QLogic Corporation");
  3864. MODULE_DESCRIPTION("QLogic Fibre Channel HBA Driver");
  3865. MODULE_LICENSE("GPL");
  3866. MODULE_VERSION(QLA2XXX_VERSION);
  3867. MODULE_FIRMWARE(FW_FILE_ISP21XX);
  3868. MODULE_FIRMWARE(FW_FILE_ISP22XX);
  3869. MODULE_FIRMWARE(FW_FILE_ISP2300);
  3870. MODULE_FIRMWARE(FW_FILE_ISP2322);
  3871. MODULE_FIRMWARE(FW_FILE_ISP24XX);
  3872. MODULE_FIRMWARE(FW_FILE_ISP25XX);