qla_os.c 153 KB

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