qla_os.c 144 KB

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