qla_os.c 147 KB

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