qla_os.c 123 KB

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