qla_os.c 117 KB

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