qla_os.c 144 KB

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