qla_os.c 117 KB

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