qla_os.c 144 KB

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