qla_os.c 118 KB

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