qla_os.c 119 KB

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