qla_os.c 105 KB

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