qla_os.c 144 KB

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