qla_os.c 147 KB

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