qla_init.c 146 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657
  1. /*
  2. * QLogic Fibre Channel HBA Driver
  3. * Copyright (c) 2003-2010 QLogic Corporation
  4. *
  5. * See LICENSE.qla2xxx for copyright and licensing details.
  6. */
  7. #include "qla_def.h"
  8. #include "qla_gbl.h"
  9. #include <linux/delay.h>
  10. #include <linux/slab.h>
  11. #include <linux/vmalloc.h>
  12. #include "qla_devtbl.h"
  13. #ifdef CONFIG_SPARC
  14. #include <asm/prom.h>
  15. #endif
  16. /*
  17. * QLogic ISP2x00 Hardware Support Function Prototypes.
  18. */
  19. static int qla2x00_isp_firmware(scsi_qla_host_t *);
  20. static int qla2x00_setup_chip(scsi_qla_host_t *);
  21. static int qla2x00_init_rings(scsi_qla_host_t *);
  22. static int qla2x00_fw_ready(scsi_qla_host_t *);
  23. static int qla2x00_configure_hba(scsi_qla_host_t *);
  24. static int qla2x00_configure_loop(scsi_qla_host_t *);
  25. static int qla2x00_configure_local_loop(scsi_qla_host_t *);
  26. static int qla2x00_configure_fabric(scsi_qla_host_t *);
  27. static int qla2x00_find_all_fabric_devs(scsi_qla_host_t *, struct list_head *);
  28. static int qla2x00_device_resync(scsi_qla_host_t *);
  29. static int qla2x00_fabric_dev_login(scsi_qla_host_t *, fc_port_t *,
  30. uint16_t *);
  31. static int qla2x00_restart_isp(scsi_qla_host_t *);
  32. static int qla2x00_find_new_loop_id(scsi_qla_host_t *, fc_port_t *);
  33. static struct qla_chip_state_84xx *qla84xx_get_chip(struct scsi_qla_host *);
  34. static int qla84xx_init_chip(scsi_qla_host_t *);
  35. static int qla25xx_init_queues(struct qla_hw_data *);
  36. /* SRB Extensions ---------------------------------------------------------- */
  37. static void
  38. qla2x00_ctx_sp_timeout(unsigned long __data)
  39. {
  40. srb_t *sp = (srb_t *)__data;
  41. struct srb_ctx *ctx;
  42. struct srb_iocb *iocb;
  43. fc_port_t *fcport = sp->fcport;
  44. struct qla_hw_data *ha = fcport->vha->hw;
  45. struct req_que *req;
  46. unsigned long flags;
  47. spin_lock_irqsave(&ha->hardware_lock, flags);
  48. req = ha->req_q_map[0];
  49. req->outstanding_cmds[sp->handle] = NULL;
  50. ctx = sp->ctx;
  51. iocb = ctx->u.iocb_cmd;
  52. iocb->timeout(sp);
  53. iocb->free(sp);
  54. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  55. }
  56. static void
  57. qla2x00_ctx_sp_free(srb_t *sp)
  58. {
  59. struct srb_ctx *ctx = sp->ctx;
  60. struct srb_iocb *iocb = ctx->u.iocb_cmd;
  61. struct scsi_qla_host *vha = sp->fcport->vha;
  62. del_timer(&iocb->timer);
  63. kfree(iocb);
  64. kfree(ctx);
  65. mempool_free(sp, sp->fcport->vha->hw->srb_mempool);
  66. QLA_VHA_MARK_NOT_BUSY(vha);
  67. }
  68. inline srb_t *
  69. qla2x00_get_ctx_sp(scsi_qla_host_t *vha, fc_port_t *fcport, size_t size,
  70. unsigned long tmo)
  71. {
  72. srb_t *sp = NULL;
  73. struct qla_hw_data *ha = vha->hw;
  74. struct srb_ctx *ctx;
  75. struct srb_iocb *iocb;
  76. uint8_t bail;
  77. QLA_VHA_MARK_BUSY(vha, bail);
  78. if (bail)
  79. return NULL;
  80. sp = mempool_alloc(ha->srb_mempool, GFP_KERNEL);
  81. if (!sp)
  82. goto done;
  83. ctx = kzalloc(size, GFP_KERNEL);
  84. if (!ctx) {
  85. mempool_free(sp, ha->srb_mempool);
  86. sp = NULL;
  87. goto done;
  88. }
  89. iocb = kzalloc(sizeof(struct srb_iocb), GFP_KERNEL);
  90. if (!iocb) {
  91. mempool_free(sp, ha->srb_mempool);
  92. sp = NULL;
  93. kfree(ctx);
  94. goto done;
  95. }
  96. memset(sp, 0, sizeof(*sp));
  97. sp->fcport = fcport;
  98. sp->ctx = ctx;
  99. ctx->u.iocb_cmd = iocb;
  100. iocb->free = qla2x00_ctx_sp_free;
  101. init_timer(&iocb->timer);
  102. if (!tmo)
  103. goto done;
  104. iocb->timer.expires = jiffies + tmo * HZ;
  105. iocb->timer.data = (unsigned long)sp;
  106. iocb->timer.function = qla2x00_ctx_sp_timeout;
  107. add_timer(&iocb->timer);
  108. done:
  109. if (!sp)
  110. QLA_VHA_MARK_NOT_BUSY(vha);
  111. return sp;
  112. }
  113. /* Asynchronous Login/Logout Routines -------------------------------------- */
  114. static inline unsigned long
  115. qla2x00_get_async_timeout(struct scsi_qla_host *vha)
  116. {
  117. unsigned long tmo;
  118. struct qla_hw_data *ha = vha->hw;
  119. /* Firmware should use switch negotiated r_a_tov for timeout. */
  120. tmo = ha->r_a_tov / 10 * 2;
  121. if (!IS_FWI2_CAPABLE(ha)) {
  122. /*
  123. * Except for earlier ISPs where the timeout is seeded from the
  124. * initialization control block.
  125. */
  126. tmo = ha->login_timeout;
  127. }
  128. return tmo;
  129. }
  130. static void
  131. qla2x00_async_iocb_timeout(srb_t *sp)
  132. {
  133. fc_port_t *fcport = sp->fcport;
  134. struct srb_ctx *ctx = sp->ctx;
  135. DEBUG2(printk(KERN_WARNING
  136. "scsi(%ld:%x): Async-%s timeout - portid=%02x%02x%02x.\n",
  137. fcport->vha->host_no, sp->handle,
  138. ctx->name, fcport->d_id.b.domain,
  139. fcport->d_id.b.area, fcport->d_id.b.al_pa));
  140. fcport->flags &= ~FCF_ASYNC_SENT;
  141. if (ctx->type == SRB_LOGIN_CMD) {
  142. struct srb_iocb *lio = ctx->u.iocb_cmd;
  143. qla2x00_post_async_logout_work(fcport->vha, fcport, NULL);
  144. /* Retry as needed. */
  145. lio->u.logio.data[0] = MBS_COMMAND_ERROR;
  146. lio->u.logio.data[1] = lio->u.logio.flags & SRB_LOGIN_RETRIED ?
  147. QLA_LOGIO_LOGIN_RETRIED : 0;
  148. qla2x00_post_async_login_done_work(fcport->vha, fcport,
  149. lio->u.logio.data);
  150. }
  151. }
  152. static void
  153. qla2x00_async_login_ctx_done(srb_t *sp)
  154. {
  155. struct srb_ctx *ctx = sp->ctx;
  156. struct srb_iocb *lio = ctx->u.iocb_cmd;
  157. qla2x00_post_async_login_done_work(sp->fcport->vha, sp->fcport,
  158. lio->u.logio.data);
  159. lio->free(sp);
  160. }
  161. int
  162. qla2x00_async_login(struct scsi_qla_host *vha, fc_port_t *fcport,
  163. uint16_t *data)
  164. {
  165. srb_t *sp;
  166. struct srb_ctx *ctx;
  167. struct srb_iocb *lio;
  168. int rval;
  169. rval = QLA_FUNCTION_FAILED;
  170. sp = qla2x00_get_ctx_sp(vha, fcport, sizeof(struct srb_ctx),
  171. qla2x00_get_async_timeout(vha) + 2);
  172. if (!sp)
  173. goto done;
  174. ctx = sp->ctx;
  175. ctx->type = SRB_LOGIN_CMD;
  176. ctx->name = "login";
  177. lio = ctx->u.iocb_cmd;
  178. lio->timeout = qla2x00_async_iocb_timeout;
  179. lio->done = qla2x00_async_login_ctx_done;
  180. lio->u.logio.flags |= SRB_LOGIN_COND_PLOGI;
  181. if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
  182. lio->u.logio.flags |= SRB_LOGIN_RETRIED;
  183. rval = qla2x00_start_sp(sp);
  184. if (rval != QLA_SUCCESS)
  185. goto done_free_sp;
  186. DEBUG2(printk(KERN_DEBUG
  187. "scsi(%ld:%x): Async-login - loop-id=%x portid=%02x%02x%02x "
  188. "retries=%d.\n", fcport->vha->host_no, sp->handle, fcport->loop_id,
  189. fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa,
  190. fcport->login_retry));
  191. return rval;
  192. done_free_sp:
  193. lio->free(sp);
  194. done:
  195. return rval;
  196. }
  197. static void
  198. qla2x00_async_logout_ctx_done(srb_t *sp)
  199. {
  200. struct srb_ctx *ctx = sp->ctx;
  201. struct srb_iocb *lio = ctx->u.iocb_cmd;
  202. qla2x00_post_async_logout_done_work(sp->fcport->vha, sp->fcport,
  203. lio->u.logio.data);
  204. lio->free(sp);
  205. }
  206. int
  207. qla2x00_async_logout(struct scsi_qla_host *vha, fc_port_t *fcport)
  208. {
  209. srb_t *sp;
  210. struct srb_ctx *ctx;
  211. struct srb_iocb *lio;
  212. int rval;
  213. rval = QLA_FUNCTION_FAILED;
  214. sp = qla2x00_get_ctx_sp(vha, fcport, sizeof(struct srb_ctx),
  215. qla2x00_get_async_timeout(vha) + 2);
  216. if (!sp)
  217. goto done;
  218. ctx = sp->ctx;
  219. ctx->type = SRB_LOGOUT_CMD;
  220. ctx->name = "logout";
  221. lio = ctx->u.iocb_cmd;
  222. lio->timeout = qla2x00_async_iocb_timeout;
  223. lio->done = qla2x00_async_logout_ctx_done;
  224. rval = qla2x00_start_sp(sp);
  225. if (rval != QLA_SUCCESS)
  226. goto done_free_sp;
  227. DEBUG2(printk(KERN_DEBUG
  228. "scsi(%ld:%x): Async-logout - loop-id=%x portid=%02x%02x%02x.\n",
  229. fcport->vha->host_no, sp->handle, fcport->loop_id,
  230. fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa));
  231. return rval;
  232. done_free_sp:
  233. lio->free(sp);
  234. done:
  235. return rval;
  236. }
  237. static void
  238. qla2x00_async_adisc_ctx_done(srb_t *sp)
  239. {
  240. struct srb_ctx *ctx = sp->ctx;
  241. struct srb_iocb *lio = ctx->u.iocb_cmd;
  242. qla2x00_post_async_adisc_done_work(sp->fcport->vha, sp->fcport,
  243. lio->u.logio.data);
  244. lio->free(sp);
  245. }
  246. int
  247. qla2x00_async_adisc(struct scsi_qla_host *vha, fc_port_t *fcport,
  248. uint16_t *data)
  249. {
  250. srb_t *sp;
  251. struct srb_ctx *ctx;
  252. struct srb_iocb *lio;
  253. int rval;
  254. rval = QLA_FUNCTION_FAILED;
  255. sp = qla2x00_get_ctx_sp(vha, fcport, sizeof(struct srb_ctx),
  256. qla2x00_get_async_timeout(vha) + 2);
  257. if (!sp)
  258. goto done;
  259. ctx = sp->ctx;
  260. ctx->type = SRB_ADISC_CMD;
  261. ctx->name = "adisc";
  262. lio = ctx->u.iocb_cmd;
  263. lio->timeout = qla2x00_async_iocb_timeout;
  264. lio->done = qla2x00_async_adisc_ctx_done;
  265. if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
  266. lio->u.logio.flags |= SRB_LOGIN_RETRIED;
  267. rval = qla2x00_start_sp(sp);
  268. if (rval != QLA_SUCCESS)
  269. goto done_free_sp;
  270. DEBUG2(printk(KERN_DEBUG
  271. "scsi(%ld:%x): Async-adisc - loop-id=%x portid=%02x%02x%02x.\n",
  272. fcport->vha->host_no, sp->handle, fcport->loop_id,
  273. fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa));
  274. return rval;
  275. done_free_sp:
  276. lio->free(sp);
  277. done:
  278. return rval;
  279. }
  280. static void
  281. qla2x00_async_tm_cmd_ctx_done(srb_t *sp)
  282. {
  283. struct srb_ctx *ctx = sp->ctx;
  284. struct srb_iocb *iocb = (struct srb_iocb *)ctx->u.iocb_cmd;
  285. qla2x00_async_tm_cmd_done(sp->fcport->vha, sp->fcport, iocb);
  286. iocb->free(sp);
  287. }
  288. int
  289. qla2x00_async_tm_cmd(fc_port_t *fcport, uint32_t flags, uint32_t lun,
  290. uint32_t tag)
  291. {
  292. struct scsi_qla_host *vha = fcport->vha;
  293. srb_t *sp;
  294. struct srb_ctx *ctx;
  295. struct srb_iocb *tcf;
  296. int rval;
  297. rval = QLA_FUNCTION_FAILED;
  298. sp = qla2x00_get_ctx_sp(vha, fcport, sizeof(struct srb_ctx),
  299. qla2x00_get_async_timeout(vha) + 2);
  300. if (!sp)
  301. goto done;
  302. ctx = sp->ctx;
  303. ctx->type = SRB_TM_CMD;
  304. ctx->name = "tmf";
  305. tcf = ctx->u.iocb_cmd;
  306. tcf->u.tmf.flags = flags;
  307. tcf->u.tmf.lun = lun;
  308. tcf->u.tmf.data = tag;
  309. tcf->timeout = qla2x00_async_iocb_timeout;
  310. tcf->done = qla2x00_async_tm_cmd_ctx_done;
  311. rval = qla2x00_start_sp(sp);
  312. if (rval != QLA_SUCCESS)
  313. goto done_free_sp;
  314. DEBUG2(printk(KERN_DEBUG
  315. "scsi(%ld:%x): Async-tmf - loop-id=%x portid=%02x%02x%02x.\n",
  316. fcport->vha->host_no, sp->handle, fcport->loop_id,
  317. fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa));
  318. return rval;
  319. done_free_sp:
  320. tcf->free(sp);
  321. done:
  322. return rval;
  323. }
  324. void
  325. qla2x00_async_login_done(struct scsi_qla_host *vha, fc_port_t *fcport,
  326. uint16_t *data)
  327. {
  328. int rval;
  329. switch (data[0]) {
  330. case MBS_COMMAND_COMPLETE:
  331. if (fcport->flags & FCF_FCP2_DEVICE) {
  332. fcport->flags |= FCF_ASYNC_SENT;
  333. qla2x00_post_async_adisc_work(vha, fcport, data);
  334. break;
  335. }
  336. qla2x00_update_fcport(vha, fcport);
  337. break;
  338. case MBS_COMMAND_ERROR:
  339. fcport->flags &= ~FCF_ASYNC_SENT;
  340. if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
  341. set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
  342. else
  343. qla2x00_mark_device_lost(vha, fcport, 1, 1);
  344. break;
  345. case MBS_PORT_ID_USED:
  346. fcport->loop_id = data[1];
  347. qla2x00_post_async_logout_work(vha, fcport, NULL);
  348. qla2x00_post_async_login_work(vha, fcport, NULL);
  349. break;
  350. case MBS_LOOP_ID_USED:
  351. fcport->loop_id++;
  352. rval = qla2x00_find_new_loop_id(vha, fcport);
  353. if (rval != QLA_SUCCESS) {
  354. fcport->flags &= ~FCF_ASYNC_SENT;
  355. qla2x00_mark_device_lost(vha, fcport, 1, 1);
  356. break;
  357. }
  358. qla2x00_post_async_login_work(vha, fcport, NULL);
  359. break;
  360. }
  361. return;
  362. }
  363. void
  364. qla2x00_async_logout_done(struct scsi_qla_host *vha, fc_port_t *fcport,
  365. uint16_t *data)
  366. {
  367. qla2x00_mark_device_lost(vha, fcport, 1, 0);
  368. return;
  369. }
  370. void
  371. qla2x00_async_adisc_done(struct scsi_qla_host *vha, fc_port_t *fcport,
  372. uint16_t *data)
  373. {
  374. if (data[0] == MBS_COMMAND_COMPLETE) {
  375. qla2x00_update_fcport(vha, fcport);
  376. return;
  377. }
  378. /* Retry login. */
  379. fcport->flags &= ~FCF_ASYNC_SENT;
  380. if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
  381. set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
  382. else
  383. qla2x00_mark_device_lost(vha, fcport, 1, 1);
  384. return;
  385. }
  386. void
  387. qla2x00_async_tm_cmd_done(struct scsi_qla_host *vha, fc_port_t *fcport,
  388. struct srb_iocb *iocb)
  389. {
  390. int rval;
  391. uint32_t flags;
  392. uint16_t lun;
  393. flags = iocb->u.tmf.flags;
  394. lun = (uint16_t)iocb->u.tmf.lun;
  395. /* Issue Marker IOCB */
  396. rval = qla2x00_marker(vha, vha->hw->req_q_map[0],
  397. vha->hw->rsp_q_map[0], fcport->loop_id, lun,
  398. flags == TCF_LUN_RESET ? MK_SYNC_ID_LUN : MK_SYNC_ID);
  399. if ((rval != QLA_SUCCESS) || iocb->u.tmf.data) {
  400. DEBUG2_3_11(printk(KERN_WARNING
  401. "%s(%ld): TM IOCB failed (%x).\n",
  402. __func__, vha->host_no, rval));
  403. }
  404. return;
  405. }
  406. /****************************************************************************/
  407. /* QLogic ISP2x00 Hardware Support Functions. */
  408. /****************************************************************************/
  409. /*
  410. * qla2x00_initialize_adapter
  411. * Initialize board.
  412. *
  413. * Input:
  414. * ha = adapter block pointer.
  415. *
  416. * Returns:
  417. * 0 = success
  418. */
  419. int
  420. qla2x00_initialize_adapter(scsi_qla_host_t *vha)
  421. {
  422. int rval;
  423. struct qla_hw_data *ha = vha->hw;
  424. struct req_que *req = ha->req_q_map[0];
  425. /* Clear adapter flags. */
  426. vha->flags.online = 0;
  427. ha->flags.chip_reset_done = 0;
  428. vha->flags.reset_active = 0;
  429. ha->flags.pci_channel_io_perm_failure = 0;
  430. ha->flags.eeh_busy = 0;
  431. ha->flags.thermal_supported = 1;
  432. atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
  433. atomic_set(&vha->loop_state, LOOP_DOWN);
  434. vha->device_flags = DFLG_NO_CABLE;
  435. vha->dpc_flags = 0;
  436. vha->flags.management_server_logged_in = 0;
  437. vha->marker_needed = 0;
  438. ha->isp_abort_cnt = 0;
  439. ha->beacon_blink_led = 0;
  440. set_bit(0, ha->req_qid_map);
  441. set_bit(0, ha->rsp_qid_map);
  442. qla_printk(KERN_INFO, ha, "Configuring PCI space...\n");
  443. rval = ha->isp_ops->pci_config(vha);
  444. if (rval) {
  445. DEBUG2(printk("scsi(%ld): Unable to configure PCI space.\n",
  446. vha->host_no));
  447. return (rval);
  448. }
  449. ha->isp_ops->reset_chip(vha);
  450. rval = qla2xxx_get_flash_info(vha);
  451. if (rval) {
  452. DEBUG2(printk("scsi(%ld): Unable to validate FLASH data.\n",
  453. vha->host_no));
  454. return (rval);
  455. }
  456. ha->isp_ops->get_flash_version(vha, req->ring);
  457. qla_printk(KERN_INFO, ha, "Configure NVRAM parameters...\n");
  458. ha->isp_ops->nvram_config(vha);
  459. if (ha->flags.disable_serdes) {
  460. /* Mask HBA via NVRAM settings? */
  461. qla_printk(KERN_INFO, ha, "Masking HBA WWPN "
  462. "%02x%02x%02x%02x%02x%02x%02x%02x (via NVRAM).\n",
  463. vha->port_name[0], vha->port_name[1],
  464. vha->port_name[2], vha->port_name[3],
  465. vha->port_name[4], vha->port_name[5],
  466. vha->port_name[6], vha->port_name[7]);
  467. return QLA_FUNCTION_FAILED;
  468. }
  469. qla_printk(KERN_INFO, ha, "Verifying loaded RISC code...\n");
  470. if (qla2x00_isp_firmware(vha) != QLA_SUCCESS) {
  471. rval = ha->isp_ops->chip_diag(vha);
  472. if (rval)
  473. return (rval);
  474. rval = qla2x00_setup_chip(vha);
  475. if (rval)
  476. return (rval);
  477. }
  478. if (IS_QLA84XX(ha)) {
  479. ha->cs84xx = qla84xx_get_chip(vha);
  480. if (!ha->cs84xx) {
  481. qla_printk(KERN_ERR, ha,
  482. "Unable to configure ISP84XX.\n");
  483. return QLA_FUNCTION_FAILED;
  484. }
  485. }
  486. rval = qla2x00_init_rings(vha);
  487. ha->flags.chip_reset_done = 1;
  488. if (rval == QLA_SUCCESS && IS_QLA84XX(ha)) {
  489. /* Issue verify 84xx FW IOCB to complete 84xx initialization */
  490. rval = qla84xx_init_chip(vha);
  491. if (rval != QLA_SUCCESS) {
  492. qla_printk(KERN_ERR, ha,
  493. "Unable to initialize ISP84XX.\n");
  494. qla84xx_put_chip(vha);
  495. }
  496. }
  497. if (IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha))
  498. qla24xx_read_fcp_prio_cfg(vha);
  499. return (rval);
  500. }
  501. /**
  502. * qla2100_pci_config() - Setup ISP21xx PCI configuration registers.
  503. * @ha: HA context
  504. *
  505. * Returns 0 on success.
  506. */
  507. int
  508. qla2100_pci_config(scsi_qla_host_t *vha)
  509. {
  510. uint16_t w;
  511. unsigned long flags;
  512. struct qla_hw_data *ha = vha->hw;
  513. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  514. pci_set_master(ha->pdev);
  515. pci_try_set_mwi(ha->pdev);
  516. pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
  517. w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
  518. pci_write_config_word(ha->pdev, PCI_COMMAND, w);
  519. pci_disable_rom(ha->pdev);
  520. /* Get PCI bus information. */
  521. spin_lock_irqsave(&ha->hardware_lock, flags);
  522. ha->pci_attr = RD_REG_WORD(&reg->ctrl_status);
  523. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  524. return QLA_SUCCESS;
  525. }
  526. /**
  527. * qla2300_pci_config() - Setup ISP23xx PCI configuration registers.
  528. * @ha: HA context
  529. *
  530. * Returns 0 on success.
  531. */
  532. int
  533. qla2300_pci_config(scsi_qla_host_t *vha)
  534. {
  535. uint16_t w;
  536. unsigned long flags = 0;
  537. uint32_t cnt;
  538. struct qla_hw_data *ha = vha->hw;
  539. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  540. pci_set_master(ha->pdev);
  541. pci_try_set_mwi(ha->pdev);
  542. pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
  543. w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
  544. if (IS_QLA2322(ha) || IS_QLA6322(ha))
  545. w &= ~PCI_COMMAND_INTX_DISABLE;
  546. pci_write_config_word(ha->pdev, PCI_COMMAND, w);
  547. /*
  548. * If this is a 2300 card and not 2312, reset the
  549. * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately,
  550. * the 2310 also reports itself as a 2300 so we need to get the
  551. * fb revision level -- a 6 indicates it really is a 2300 and
  552. * not a 2310.
  553. */
  554. if (IS_QLA2300(ha)) {
  555. spin_lock_irqsave(&ha->hardware_lock, flags);
  556. /* Pause RISC. */
  557. WRT_REG_WORD(&reg->hccr, HCCR_PAUSE_RISC);
  558. for (cnt = 0; cnt < 30000; cnt++) {
  559. if ((RD_REG_WORD(&reg->hccr) & HCCR_RISC_PAUSE) != 0)
  560. break;
  561. udelay(10);
  562. }
  563. /* Select FPM registers. */
  564. WRT_REG_WORD(&reg->ctrl_status, 0x20);
  565. RD_REG_WORD(&reg->ctrl_status);
  566. /* Get the fb rev level */
  567. ha->fb_rev = RD_FB_CMD_REG(ha, reg);
  568. if (ha->fb_rev == FPM_2300)
  569. pci_clear_mwi(ha->pdev);
  570. /* Deselect FPM registers. */
  571. WRT_REG_WORD(&reg->ctrl_status, 0x0);
  572. RD_REG_WORD(&reg->ctrl_status);
  573. /* Release RISC module. */
  574. WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
  575. for (cnt = 0; cnt < 30000; cnt++) {
  576. if ((RD_REG_WORD(&reg->hccr) & HCCR_RISC_PAUSE) == 0)
  577. break;
  578. udelay(10);
  579. }
  580. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  581. }
  582. pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
  583. pci_disable_rom(ha->pdev);
  584. /* Get PCI bus information. */
  585. spin_lock_irqsave(&ha->hardware_lock, flags);
  586. ha->pci_attr = RD_REG_WORD(&reg->ctrl_status);
  587. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  588. return QLA_SUCCESS;
  589. }
  590. /**
  591. * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers.
  592. * @ha: HA context
  593. *
  594. * Returns 0 on success.
  595. */
  596. int
  597. qla24xx_pci_config(scsi_qla_host_t *vha)
  598. {
  599. uint16_t w;
  600. unsigned long flags = 0;
  601. struct qla_hw_data *ha = vha->hw;
  602. struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
  603. pci_set_master(ha->pdev);
  604. pci_try_set_mwi(ha->pdev);
  605. pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
  606. w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
  607. w &= ~PCI_COMMAND_INTX_DISABLE;
  608. pci_write_config_word(ha->pdev, PCI_COMMAND, w);
  609. pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
  610. /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */
  611. if (pci_find_capability(ha->pdev, PCI_CAP_ID_PCIX))
  612. pcix_set_mmrbc(ha->pdev, 2048);
  613. /* PCIe -- adjust Maximum Read Request Size (2048). */
  614. if (pci_find_capability(ha->pdev, PCI_CAP_ID_EXP))
  615. pcie_set_readrq(ha->pdev, 2048);
  616. pci_disable_rom(ha->pdev);
  617. ha->chip_revision = ha->pdev->revision;
  618. /* Get PCI bus information. */
  619. spin_lock_irqsave(&ha->hardware_lock, flags);
  620. ha->pci_attr = RD_REG_DWORD(&reg->ctrl_status);
  621. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  622. return QLA_SUCCESS;
  623. }
  624. /**
  625. * qla25xx_pci_config() - Setup ISP25xx PCI configuration registers.
  626. * @ha: HA context
  627. *
  628. * Returns 0 on success.
  629. */
  630. int
  631. qla25xx_pci_config(scsi_qla_host_t *vha)
  632. {
  633. uint16_t w;
  634. struct qla_hw_data *ha = vha->hw;
  635. pci_set_master(ha->pdev);
  636. pci_try_set_mwi(ha->pdev);
  637. pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
  638. w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
  639. w &= ~PCI_COMMAND_INTX_DISABLE;
  640. pci_write_config_word(ha->pdev, PCI_COMMAND, w);
  641. /* PCIe -- adjust Maximum Read Request Size (2048). */
  642. if (pci_find_capability(ha->pdev, PCI_CAP_ID_EXP))
  643. pcie_set_readrq(ha->pdev, 2048);
  644. pci_disable_rom(ha->pdev);
  645. ha->chip_revision = ha->pdev->revision;
  646. return QLA_SUCCESS;
  647. }
  648. /**
  649. * qla2x00_isp_firmware() - Choose firmware image.
  650. * @ha: HA context
  651. *
  652. * Returns 0 on success.
  653. */
  654. static int
  655. qla2x00_isp_firmware(scsi_qla_host_t *vha)
  656. {
  657. int rval;
  658. uint16_t loop_id, topo, sw_cap;
  659. uint8_t domain, area, al_pa;
  660. struct qla_hw_data *ha = vha->hw;
  661. /* Assume loading risc code */
  662. rval = QLA_FUNCTION_FAILED;
  663. if (ha->flags.disable_risc_code_load) {
  664. DEBUG2(printk("scsi(%ld): RISC CODE NOT loaded\n",
  665. vha->host_no));
  666. qla_printk(KERN_INFO, ha, "RISC CODE NOT loaded\n");
  667. /* Verify checksum of loaded RISC code. */
  668. rval = qla2x00_verify_checksum(vha, ha->fw_srisc_address);
  669. if (rval == QLA_SUCCESS) {
  670. /* And, verify we are not in ROM code. */
  671. rval = qla2x00_get_adapter_id(vha, &loop_id, &al_pa,
  672. &area, &domain, &topo, &sw_cap);
  673. }
  674. }
  675. if (rval) {
  676. DEBUG2_3(printk("scsi(%ld): **** Load RISC code ****\n",
  677. vha->host_no));
  678. }
  679. return (rval);
  680. }
  681. /**
  682. * qla2x00_reset_chip() - Reset ISP chip.
  683. * @ha: HA context
  684. *
  685. * Returns 0 on success.
  686. */
  687. void
  688. qla2x00_reset_chip(scsi_qla_host_t *vha)
  689. {
  690. unsigned long flags = 0;
  691. struct qla_hw_data *ha = vha->hw;
  692. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  693. uint32_t cnt;
  694. uint16_t cmd;
  695. if (unlikely(pci_channel_offline(ha->pdev)))
  696. return;
  697. ha->isp_ops->disable_intrs(ha);
  698. spin_lock_irqsave(&ha->hardware_lock, flags);
  699. /* Turn off master enable */
  700. cmd = 0;
  701. pci_read_config_word(ha->pdev, PCI_COMMAND, &cmd);
  702. cmd &= ~PCI_COMMAND_MASTER;
  703. pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
  704. if (!IS_QLA2100(ha)) {
  705. /* Pause RISC. */
  706. WRT_REG_WORD(&reg->hccr, HCCR_PAUSE_RISC);
  707. if (IS_QLA2200(ha) || IS_QLA2300(ha)) {
  708. for (cnt = 0; cnt < 30000; cnt++) {
  709. if ((RD_REG_WORD(&reg->hccr) &
  710. HCCR_RISC_PAUSE) != 0)
  711. break;
  712. udelay(100);
  713. }
  714. } else {
  715. RD_REG_WORD(&reg->hccr); /* PCI Posting. */
  716. udelay(10);
  717. }
  718. /* Select FPM registers. */
  719. WRT_REG_WORD(&reg->ctrl_status, 0x20);
  720. RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
  721. /* FPM Soft Reset. */
  722. WRT_REG_WORD(&reg->fpm_diag_config, 0x100);
  723. RD_REG_WORD(&reg->fpm_diag_config); /* PCI Posting. */
  724. /* Toggle Fpm Reset. */
  725. if (!IS_QLA2200(ha)) {
  726. WRT_REG_WORD(&reg->fpm_diag_config, 0x0);
  727. RD_REG_WORD(&reg->fpm_diag_config); /* PCI Posting. */
  728. }
  729. /* Select frame buffer registers. */
  730. WRT_REG_WORD(&reg->ctrl_status, 0x10);
  731. RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
  732. /* Reset frame buffer FIFOs. */
  733. if (IS_QLA2200(ha)) {
  734. WRT_FB_CMD_REG(ha, reg, 0xa000);
  735. RD_FB_CMD_REG(ha, reg); /* PCI Posting. */
  736. } else {
  737. WRT_FB_CMD_REG(ha, reg, 0x00fc);
  738. /* Read back fb_cmd until zero or 3 seconds max */
  739. for (cnt = 0; cnt < 3000; cnt++) {
  740. if ((RD_FB_CMD_REG(ha, reg) & 0xff) == 0)
  741. break;
  742. udelay(100);
  743. }
  744. }
  745. /* Select RISC module registers. */
  746. WRT_REG_WORD(&reg->ctrl_status, 0);
  747. RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
  748. /* Reset RISC processor. */
  749. WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
  750. RD_REG_WORD(&reg->hccr); /* PCI Posting. */
  751. /* Release RISC processor. */
  752. WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
  753. RD_REG_WORD(&reg->hccr); /* PCI Posting. */
  754. }
  755. WRT_REG_WORD(&reg->hccr, HCCR_CLR_RISC_INT);
  756. WRT_REG_WORD(&reg->hccr, HCCR_CLR_HOST_INT);
  757. /* Reset ISP chip. */
  758. WRT_REG_WORD(&reg->ctrl_status, CSR_ISP_SOFT_RESET);
  759. /* Wait for RISC to recover from reset. */
  760. if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
  761. /*
  762. * It is necessary to for a delay here since the card doesn't
  763. * respond to PCI reads during a reset. On some architectures
  764. * this will result in an MCA.
  765. */
  766. udelay(20);
  767. for (cnt = 30000; cnt; cnt--) {
  768. if ((RD_REG_WORD(&reg->ctrl_status) &
  769. CSR_ISP_SOFT_RESET) == 0)
  770. break;
  771. udelay(100);
  772. }
  773. } else
  774. udelay(10);
  775. /* Reset RISC processor. */
  776. WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
  777. WRT_REG_WORD(&reg->semaphore, 0);
  778. /* Release RISC processor. */
  779. WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
  780. RD_REG_WORD(&reg->hccr); /* PCI Posting. */
  781. if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
  782. for (cnt = 0; cnt < 30000; cnt++) {
  783. if (RD_MAILBOX_REG(ha, reg, 0) != MBS_BUSY)
  784. break;
  785. udelay(100);
  786. }
  787. } else
  788. udelay(100);
  789. /* Turn on master enable */
  790. cmd |= PCI_COMMAND_MASTER;
  791. pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
  792. /* Disable RISC pause on FPM parity error. */
  793. if (!IS_QLA2100(ha)) {
  794. WRT_REG_WORD(&reg->hccr, HCCR_DISABLE_PARITY_PAUSE);
  795. RD_REG_WORD(&reg->hccr); /* PCI Posting. */
  796. }
  797. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  798. }
  799. /**
  800. * qla81xx_reset_mpi() - Reset's MPI FW via Write MPI Register MBC.
  801. *
  802. * Returns 0 on success.
  803. */
  804. int
  805. qla81xx_reset_mpi(scsi_qla_host_t *vha)
  806. {
  807. uint16_t mb[4] = {0x1010, 0, 1, 0};
  808. return qla81xx_write_mpi_register(vha, mb);
  809. }
  810. /**
  811. * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC.
  812. * @ha: HA context
  813. *
  814. * Returns 0 on success.
  815. */
  816. static inline void
  817. qla24xx_reset_risc(scsi_qla_host_t *vha)
  818. {
  819. unsigned long flags = 0;
  820. struct qla_hw_data *ha = vha->hw;
  821. struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
  822. uint32_t cnt, d2;
  823. uint16_t wd;
  824. static int abts_cnt; /* ISP abort retry counts */
  825. spin_lock_irqsave(&ha->hardware_lock, flags);
  826. /* Reset RISC. */
  827. WRT_REG_DWORD(&reg->ctrl_status, CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
  828. for (cnt = 0; cnt < 30000; cnt++) {
  829. if ((RD_REG_DWORD(&reg->ctrl_status) & CSRX_DMA_ACTIVE) == 0)
  830. break;
  831. udelay(10);
  832. }
  833. WRT_REG_DWORD(&reg->ctrl_status,
  834. CSRX_ISP_SOFT_RESET|CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
  835. pci_read_config_word(ha->pdev, PCI_COMMAND, &wd);
  836. udelay(100);
  837. /* Wait for firmware to complete NVRAM accesses. */
  838. d2 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
  839. for (cnt = 10000 ; cnt && d2; cnt--) {
  840. udelay(5);
  841. d2 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
  842. barrier();
  843. }
  844. /* Wait for soft-reset to complete. */
  845. d2 = RD_REG_DWORD(&reg->ctrl_status);
  846. for (cnt = 6000000 ; cnt && (d2 & CSRX_ISP_SOFT_RESET); cnt--) {
  847. udelay(5);
  848. d2 = RD_REG_DWORD(&reg->ctrl_status);
  849. barrier();
  850. }
  851. /* If required, do an MPI FW reset now */
  852. if (test_and_clear_bit(MPI_RESET_NEEDED, &vha->dpc_flags)) {
  853. if (qla81xx_reset_mpi(vha) != QLA_SUCCESS) {
  854. if (++abts_cnt < 5) {
  855. set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
  856. set_bit(MPI_RESET_NEEDED, &vha->dpc_flags);
  857. } else {
  858. /*
  859. * We exhausted the ISP abort retries. We have to
  860. * set the board offline.
  861. */
  862. abts_cnt = 0;
  863. vha->flags.online = 0;
  864. }
  865. }
  866. }
  867. WRT_REG_DWORD(&reg->hccr, HCCRX_SET_RISC_RESET);
  868. RD_REG_DWORD(&reg->hccr);
  869. WRT_REG_DWORD(&reg->hccr, HCCRX_REL_RISC_PAUSE);
  870. RD_REG_DWORD(&reg->hccr);
  871. WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_RESET);
  872. RD_REG_DWORD(&reg->hccr);
  873. d2 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
  874. for (cnt = 6000000 ; cnt && d2; cnt--) {
  875. udelay(5);
  876. d2 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
  877. barrier();
  878. }
  879. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  880. if (IS_NOPOLLING_TYPE(ha))
  881. ha->isp_ops->enable_intrs(ha);
  882. }
  883. /**
  884. * qla24xx_reset_chip() - Reset ISP24xx chip.
  885. * @ha: HA context
  886. *
  887. * Returns 0 on success.
  888. */
  889. void
  890. qla24xx_reset_chip(scsi_qla_host_t *vha)
  891. {
  892. struct qla_hw_data *ha = vha->hw;
  893. if (pci_channel_offline(ha->pdev) &&
  894. ha->flags.pci_channel_io_perm_failure) {
  895. return;
  896. }
  897. ha->isp_ops->disable_intrs(ha);
  898. /* Perform RISC reset. */
  899. qla24xx_reset_risc(vha);
  900. }
  901. /**
  902. * qla2x00_chip_diag() - Test chip for proper operation.
  903. * @ha: HA context
  904. *
  905. * Returns 0 on success.
  906. */
  907. int
  908. qla2x00_chip_diag(scsi_qla_host_t *vha)
  909. {
  910. int rval;
  911. struct qla_hw_data *ha = vha->hw;
  912. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  913. unsigned long flags = 0;
  914. uint16_t data;
  915. uint32_t cnt;
  916. uint16_t mb[5];
  917. struct req_que *req = ha->req_q_map[0];
  918. /* Assume a failed state */
  919. rval = QLA_FUNCTION_FAILED;
  920. DEBUG3(printk("scsi(%ld): Testing device at %lx.\n",
  921. vha->host_no, (u_long)&reg->flash_address));
  922. spin_lock_irqsave(&ha->hardware_lock, flags);
  923. /* Reset ISP chip. */
  924. WRT_REG_WORD(&reg->ctrl_status, CSR_ISP_SOFT_RESET);
  925. /*
  926. * We need to have a delay here since the card will not respond while
  927. * in reset causing an MCA on some architectures.
  928. */
  929. udelay(20);
  930. data = qla2x00_debounce_register(&reg->ctrl_status);
  931. for (cnt = 6000000 ; cnt && (data & CSR_ISP_SOFT_RESET); cnt--) {
  932. udelay(5);
  933. data = RD_REG_WORD(&reg->ctrl_status);
  934. barrier();
  935. }
  936. if (!cnt)
  937. goto chip_diag_failed;
  938. DEBUG3(printk("scsi(%ld): Reset register cleared by chip reset\n",
  939. vha->host_no));
  940. /* Reset RISC processor. */
  941. WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
  942. WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
  943. /* Workaround for QLA2312 PCI parity error */
  944. if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
  945. data = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 0));
  946. for (cnt = 6000000; cnt && (data == MBS_BUSY); cnt--) {
  947. udelay(5);
  948. data = RD_MAILBOX_REG(ha, reg, 0);
  949. barrier();
  950. }
  951. } else
  952. udelay(10);
  953. if (!cnt)
  954. goto chip_diag_failed;
  955. /* Check product ID of chip */
  956. DEBUG3(printk("scsi(%ld): Checking product ID of chip\n", vha->host_no));
  957. mb[1] = RD_MAILBOX_REG(ha, reg, 1);
  958. mb[2] = RD_MAILBOX_REG(ha, reg, 2);
  959. mb[3] = RD_MAILBOX_REG(ha, reg, 3);
  960. mb[4] = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 4));
  961. if (mb[1] != PROD_ID_1 || (mb[2] != PROD_ID_2 && mb[2] != PROD_ID_2a) ||
  962. mb[3] != PROD_ID_3) {
  963. qla_printk(KERN_WARNING, ha,
  964. "Wrong product ID = 0x%x,0x%x,0x%x\n", mb[1], mb[2], mb[3]);
  965. goto chip_diag_failed;
  966. }
  967. ha->product_id[0] = mb[1];
  968. ha->product_id[1] = mb[2];
  969. ha->product_id[2] = mb[3];
  970. ha->product_id[3] = mb[4];
  971. /* Adjust fw RISC transfer size */
  972. if (req->length > 1024)
  973. ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024;
  974. else
  975. ha->fw_transfer_size = REQUEST_ENTRY_SIZE *
  976. req->length;
  977. if (IS_QLA2200(ha) &&
  978. RD_MAILBOX_REG(ha, reg, 7) == QLA2200A_RISC_ROM_VER) {
  979. /* Limit firmware transfer size with a 2200A */
  980. DEBUG3(printk("scsi(%ld): Found QLA2200A chip.\n",
  981. vha->host_no));
  982. ha->device_type |= DT_ISP2200A;
  983. ha->fw_transfer_size = 128;
  984. }
  985. /* Wrap Incoming Mailboxes Test. */
  986. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  987. DEBUG3(printk("scsi(%ld): Checking mailboxes.\n", vha->host_no));
  988. rval = qla2x00_mbx_reg_test(vha);
  989. if (rval) {
  990. DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
  991. vha->host_no));
  992. qla_printk(KERN_WARNING, ha,
  993. "Failed mailbox send register test\n");
  994. }
  995. else {
  996. /* Flag a successful rval */
  997. rval = QLA_SUCCESS;
  998. }
  999. spin_lock_irqsave(&ha->hardware_lock, flags);
  1000. chip_diag_failed:
  1001. if (rval)
  1002. DEBUG2_3(printk("scsi(%ld): Chip diagnostics **** FAILED "
  1003. "****\n", vha->host_no));
  1004. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1005. return (rval);
  1006. }
  1007. /**
  1008. * qla24xx_chip_diag() - Test ISP24xx for proper operation.
  1009. * @ha: HA context
  1010. *
  1011. * Returns 0 on success.
  1012. */
  1013. int
  1014. qla24xx_chip_diag(scsi_qla_host_t *vha)
  1015. {
  1016. int rval;
  1017. struct qla_hw_data *ha = vha->hw;
  1018. struct req_que *req = ha->req_q_map[0];
  1019. if (IS_QLA82XX(ha))
  1020. return QLA_SUCCESS;
  1021. ha->fw_transfer_size = REQUEST_ENTRY_SIZE * req->length;
  1022. rval = qla2x00_mbx_reg_test(vha);
  1023. if (rval) {
  1024. DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
  1025. vha->host_no));
  1026. qla_printk(KERN_WARNING, ha,
  1027. "Failed mailbox send register test\n");
  1028. } else {
  1029. /* Flag a successful rval */
  1030. rval = QLA_SUCCESS;
  1031. }
  1032. return rval;
  1033. }
  1034. void
  1035. qla2x00_alloc_fw_dump(scsi_qla_host_t *vha)
  1036. {
  1037. int rval;
  1038. uint32_t dump_size, fixed_size, mem_size, req_q_size, rsp_q_size,
  1039. eft_size, fce_size, mq_size;
  1040. dma_addr_t tc_dma;
  1041. void *tc;
  1042. struct qla_hw_data *ha = vha->hw;
  1043. struct req_que *req = ha->req_q_map[0];
  1044. struct rsp_que *rsp = ha->rsp_q_map[0];
  1045. if (ha->fw_dump) {
  1046. qla_printk(KERN_WARNING, ha,
  1047. "Firmware dump previously allocated.\n");
  1048. return;
  1049. }
  1050. ha->fw_dumped = 0;
  1051. fixed_size = mem_size = eft_size = fce_size = mq_size = 0;
  1052. if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
  1053. fixed_size = sizeof(struct qla2100_fw_dump);
  1054. } else if (IS_QLA23XX(ha)) {
  1055. fixed_size = offsetof(struct qla2300_fw_dump, data_ram);
  1056. mem_size = (ha->fw_memory_size - 0x11000 + 1) *
  1057. sizeof(uint16_t);
  1058. } else if (IS_FWI2_CAPABLE(ha)) {
  1059. if (IS_QLA81XX(ha))
  1060. fixed_size = offsetof(struct qla81xx_fw_dump, ext_mem);
  1061. else if (IS_QLA25XX(ha))
  1062. fixed_size = offsetof(struct qla25xx_fw_dump, ext_mem);
  1063. else
  1064. fixed_size = offsetof(struct qla24xx_fw_dump, ext_mem);
  1065. mem_size = (ha->fw_memory_size - 0x100000 + 1) *
  1066. sizeof(uint32_t);
  1067. if (ha->mqenable)
  1068. mq_size = sizeof(struct qla2xxx_mq_chain);
  1069. /* Allocate memory for Fibre Channel Event Buffer. */
  1070. if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha))
  1071. goto try_eft;
  1072. tc = dma_alloc_coherent(&ha->pdev->dev, FCE_SIZE, &tc_dma,
  1073. GFP_KERNEL);
  1074. if (!tc) {
  1075. qla_printk(KERN_WARNING, ha, "Unable to allocate "
  1076. "(%d KB) for FCE.\n", FCE_SIZE / 1024);
  1077. goto try_eft;
  1078. }
  1079. memset(tc, 0, FCE_SIZE);
  1080. rval = qla2x00_enable_fce_trace(vha, tc_dma, FCE_NUM_BUFFERS,
  1081. ha->fce_mb, &ha->fce_bufs);
  1082. if (rval) {
  1083. qla_printk(KERN_WARNING, ha, "Unable to initialize "
  1084. "FCE (%d).\n", rval);
  1085. dma_free_coherent(&ha->pdev->dev, FCE_SIZE, tc,
  1086. tc_dma);
  1087. ha->flags.fce_enabled = 0;
  1088. goto try_eft;
  1089. }
  1090. qla_printk(KERN_INFO, ha, "Allocated (%d KB) for FCE...\n",
  1091. FCE_SIZE / 1024);
  1092. fce_size = sizeof(struct qla2xxx_fce_chain) + FCE_SIZE;
  1093. ha->flags.fce_enabled = 1;
  1094. ha->fce_dma = tc_dma;
  1095. ha->fce = tc;
  1096. try_eft:
  1097. /* Allocate memory for Extended Trace Buffer. */
  1098. tc = dma_alloc_coherent(&ha->pdev->dev, EFT_SIZE, &tc_dma,
  1099. GFP_KERNEL);
  1100. if (!tc) {
  1101. qla_printk(KERN_WARNING, ha, "Unable to allocate "
  1102. "(%d KB) for EFT.\n", EFT_SIZE / 1024);
  1103. goto cont_alloc;
  1104. }
  1105. memset(tc, 0, EFT_SIZE);
  1106. rval = qla2x00_enable_eft_trace(vha, tc_dma, EFT_NUM_BUFFERS);
  1107. if (rval) {
  1108. qla_printk(KERN_WARNING, ha, "Unable to initialize "
  1109. "EFT (%d).\n", rval);
  1110. dma_free_coherent(&ha->pdev->dev, EFT_SIZE, tc,
  1111. tc_dma);
  1112. goto cont_alloc;
  1113. }
  1114. qla_printk(KERN_INFO, ha, "Allocated (%d KB) for EFT...\n",
  1115. EFT_SIZE / 1024);
  1116. eft_size = EFT_SIZE;
  1117. ha->eft_dma = tc_dma;
  1118. ha->eft = tc;
  1119. }
  1120. cont_alloc:
  1121. req_q_size = req->length * sizeof(request_t);
  1122. rsp_q_size = rsp->length * sizeof(response_t);
  1123. dump_size = offsetof(struct qla2xxx_fw_dump, isp);
  1124. dump_size += fixed_size + mem_size + req_q_size + rsp_q_size + eft_size;
  1125. ha->chain_offset = dump_size;
  1126. dump_size += mq_size + fce_size;
  1127. ha->fw_dump = vmalloc(dump_size);
  1128. if (!ha->fw_dump) {
  1129. qla_printk(KERN_WARNING, ha, "Unable to allocate (%d KB) for "
  1130. "firmware dump!!!\n", dump_size / 1024);
  1131. if (ha->fce) {
  1132. dma_free_coherent(&ha->pdev->dev, FCE_SIZE, ha->fce,
  1133. ha->fce_dma);
  1134. ha->fce = NULL;
  1135. ha->fce_dma = 0;
  1136. }
  1137. if (ha->eft) {
  1138. dma_free_coherent(&ha->pdev->dev, eft_size, ha->eft,
  1139. ha->eft_dma);
  1140. ha->eft = NULL;
  1141. ha->eft_dma = 0;
  1142. }
  1143. return;
  1144. }
  1145. qla_printk(KERN_INFO, ha, "Allocated (%d KB) for firmware dump...\n",
  1146. dump_size / 1024);
  1147. ha->fw_dump_len = dump_size;
  1148. ha->fw_dump->signature[0] = 'Q';
  1149. ha->fw_dump->signature[1] = 'L';
  1150. ha->fw_dump->signature[2] = 'G';
  1151. ha->fw_dump->signature[3] = 'C';
  1152. ha->fw_dump->version = __constant_htonl(1);
  1153. ha->fw_dump->fixed_size = htonl(fixed_size);
  1154. ha->fw_dump->mem_size = htonl(mem_size);
  1155. ha->fw_dump->req_q_size = htonl(req_q_size);
  1156. ha->fw_dump->rsp_q_size = htonl(rsp_q_size);
  1157. ha->fw_dump->eft_size = htonl(eft_size);
  1158. ha->fw_dump->eft_addr_l = htonl(LSD(ha->eft_dma));
  1159. ha->fw_dump->eft_addr_h = htonl(MSD(ha->eft_dma));
  1160. ha->fw_dump->header_size =
  1161. htonl(offsetof(struct qla2xxx_fw_dump, isp));
  1162. }
  1163. static int
  1164. qla81xx_mpi_sync(scsi_qla_host_t *vha)
  1165. {
  1166. #define MPS_MASK 0xe0
  1167. int rval;
  1168. uint16_t dc;
  1169. uint32_t dw;
  1170. struct qla_hw_data *ha = vha->hw;
  1171. if (!IS_QLA81XX(vha->hw))
  1172. return QLA_SUCCESS;
  1173. rval = qla2x00_write_ram_word(vha, 0x7c00, 1);
  1174. if (rval != QLA_SUCCESS) {
  1175. DEBUG2(qla_printk(KERN_WARNING, ha,
  1176. "Sync-MPI: Unable to acquire semaphore.\n"));
  1177. goto done;
  1178. }
  1179. pci_read_config_word(vha->hw->pdev, 0x54, &dc);
  1180. rval = qla2x00_read_ram_word(vha, 0x7a15, &dw);
  1181. if (rval != QLA_SUCCESS) {
  1182. DEBUG2(qla_printk(KERN_WARNING, ha,
  1183. "Sync-MPI: Unable to read sync.\n"));
  1184. goto done_release;
  1185. }
  1186. dc &= MPS_MASK;
  1187. if (dc == (dw & MPS_MASK))
  1188. goto done_release;
  1189. dw &= ~MPS_MASK;
  1190. dw |= dc;
  1191. rval = qla2x00_write_ram_word(vha, 0x7a15, dw);
  1192. if (rval != QLA_SUCCESS) {
  1193. DEBUG2(qla_printk(KERN_WARNING, ha,
  1194. "Sync-MPI: Unable to gain sync.\n"));
  1195. }
  1196. done_release:
  1197. rval = qla2x00_write_ram_word(vha, 0x7c00, 0);
  1198. if (rval != QLA_SUCCESS) {
  1199. DEBUG2(qla_printk(KERN_WARNING, ha,
  1200. "Sync-MPI: Unable to release semaphore.\n"));
  1201. }
  1202. done:
  1203. return rval;
  1204. }
  1205. /**
  1206. * qla2x00_setup_chip() - Load and start RISC firmware.
  1207. * @ha: HA context
  1208. *
  1209. * Returns 0 on success.
  1210. */
  1211. static int
  1212. qla2x00_setup_chip(scsi_qla_host_t *vha)
  1213. {
  1214. int rval;
  1215. uint32_t srisc_address = 0;
  1216. struct qla_hw_data *ha = vha->hw;
  1217. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  1218. unsigned long flags;
  1219. uint16_t fw_major_version;
  1220. if (IS_QLA82XX(ha)) {
  1221. rval = ha->isp_ops->load_risc(vha, &srisc_address);
  1222. if (rval == QLA_SUCCESS) {
  1223. qla2x00_stop_firmware(vha);
  1224. goto enable_82xx_npiv;
  1225. } else
  1226. goto failed;
  1227. }
  1228. if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
  1229. /* Disable SRAM, Instruction RAM and GP RAM parity. */
  1230. spin_lock_irqsave(&ha->hardware_lock, flags);
  1231. WRT_REG_WORD(&reg->hccr, (HCCR_ENABLE_PARITY + 0x0));
  1232. RD_REG_WORD(&reg->hccr);
  1233. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1234. }
  1235. qla81xx_mpi_sync(vha);
  1236. /* Load firmware sequences */
  1237. rval = ha->isp_ops->load_risc(vha, &srisc_address);
  1238. if (rval == QLA_SUCCESS) {
  1239. DEBUG(printk("scsi(%ld): Verifying Checksum of loaded RISC "
  1240. "code.\n", vha->host_no));
  1241. rval = qla2x00_verify_checksum(vha, srisc_address);
  1242. if (rval == QLA_SUCCESS) {
  1243. /* Start firmware execution. */
  1244. DEBUG(printk("scsi(%ld): Checksum OK, start "
  1245. "firmware.\n", vha->host_no));
  1246. rval = qla2x00_execute_fw(vha, srisc_address);
  1247. /* Retrieve firmware information. */
  1248. if (rval == QLA_SUCCESS) {
  1249. enable_82xx_npiv:
  1250. fw_major_version = ha->fw_major_version;
  1251. rval = qla2x00_get_fw_version(vha,
  1252. &ha->fw_major_version,
  1253. &ha->fw_minor_version,
  1254. &ha->fw_subminor_version,
  1255. &ha->fw_attributes, &ha->fw_memory_size,
  1256. ha->mpi_version, &ha->mpi_capabilities,
  1257. ha->phy_version);
  1258. if (rval != QLA_SUCCESS)
  1259. goto failed;
  1260. ha->flags.npiv_supported = 0;
  1261. if (IS_QLA2XXX_MIDTYPE(ha) &&
  1262. (ha->fw_attributes & BIT_2)) {
  1263. ha->flags.npiv_supported = 1;
  1264. if ((!ha->max_npiv_vports) ||
  1265. ((ha->max_npiv_vports + 1) %
  1266. MIN_MULTI_ID_FABRIC))
  1267. ha->max_npiv_vports =
  1268. MIN_MULTI_ID_FABRIC - 1;
  1269. }
  1270. qla2x00_get_resource_cnts(vha, NULL,
  1271. &ha->fw_xcb_count, NULL, NULL,
  1272. &ha->max_npiv_vports, NULL);
  1273. if (!fw_major_version && ql2xallocfwdump) {
  1274. if (!IS_QLA82XX(ha))
  1275. qla2x00_alloc_fw_dump(vha);
  1276. }
  1277. }
  1278. } else {
  1279. DEBUG2(printk(KERN_INFO
  1280. "scsi(%ld): ISP Firmware failed checksum.\n",
  1281. vha->host_no));
  1282. }
  1283. }
  1284. if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
  1285. /* Enable proper parity. */
  1286. spin_lock_irqsave(&ha->hardware_lock, flags);
  1287. if (IS_QLA2300(ha))
  1288. /* SRAM parity */
  1289. WRT_REG_WORD(&reg->hccr, HCCR_ENABLE_PARITY + 0x1);
  1290. else
  1291. /* SRAM, Instruction RAM and GP RAM parity */
  1292. WRT_REG_WORD(&reg->hccr, HCCR_ENABLE_PARITY + 0x7);
  1293. RD_REG_WORD(&reg->hccr);
  1294. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1295. }
  1296. if (rval == QLA_SUCCESS && IS_FAC_REQUIRED(ha)) {
  1297. uint32_t size;
  1298. rval = qla81xx_fac_get_sector_size(vha, &size);
  1299. if (rval == QLA_SUCCESS) {
  1300. ha->flags.fac_supported = 1;
  1301. ha->fdt_block_size = size << 2;
  1302. } else {
  1303. qla_printk(KERN_ERR, ha,
  1304. "Unsupported FAC firmware (%d.%02d.%02d).\n",
  1305. ha->fw_major_version, ha->fw_minor_version,
  1306. ha->fw_subminor_version);
  1307. }
  1308. }
  1309. failed:
  1310. if (rval) {
  1311. DEBUG2_3(printk("scsi(%ld): Setup chip **** FAILED ****.\n",
  1312. vha->host_no));
  1313. }
  1314. return (rval);
  1315. }
  1316. /**
  1317. * qla2x00_init_response_q_entries() - Initializes response queue entries.
  1318. * @ha: HA context
  1319. *
  1320. * Beginning of request ring has initialization control block already built
  1321. * by nvram config routine.
  1322. *
  1323. * Returns 0 on success.
  1324. */
  1325. void
  1326. qla2x00_init_response_q_entries(struct rsp_que *rsp)
  1327. {
  1328. uint16_t cnt;
  1329. response_t *pkt;
  1330. rsp->ring_ptr = rsp->ring;
  1331. rsp->ring_index = 0;
  1332. rsp->status_srb = NULL;
  1333. pkt = rsp->ring_ptr;
  1334. for (cnt = 0; cnt < rsp->length; cnt++) {
  1335. pkt->signature = RESPONSE_PROCESSED;
  1336. pkt++;
  1337. }
  1338. }
  1339. /**
  1340. * qla2x00_update_fw_options() - Read and process firmware options.
  1341. * @ha: HA context
  1342. *
  1343. * Returns 0 on success.
  1344. */
  1345. void
  1346. qla2x00_update_fw_options(scsi_qla_host_t *vha)
  1347. {
  1348. uint16_t swing, emphasis, tx_sens, rx_sens;
  1349. struct qla_hw_data *ha = vha->hw;
  1350. memset(ha->fw_options, 0, sizeof(ha->fw_options));
  1351. qla2x00_get_fw_options(vha, ha->fw_options);
  1352. if (IS_QLA2100(ha) || IS_QLA2200(ha))
  1353. return;
  1354. /* Serial Link options. */
  1355. DEBUG3(printk("scsi(%ld): Serial link options:\n",
  1356. vha->host_no));
  1357. DEBUG3(qla2x00_dump_buffer((uint8_t *)&ha->fw_seriallink_options,
  1358. sizeof(ha->fw_seriallink_options)));
  1359. ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING;
  1360. if (ha->fw_seriallink_options[3] & BIT_2) {
  1361. ha->fw_options[1] |= FO1_SET_EMPHASIS_SWING;
  1362. /* 1G settings */
  1363. swing = ha->fw_seriallink_options[2] & (BIT_2 | BIT_1 | BIT_0);
  1364. emphasis = (ha->fw_seriallink_options[2] &
  1365. (BIT_4 | BIT_3)) >> 3;
  1366. tx_sens = ha->fw_seriallink_options[0] &
  1367. (BIT_3 | BIT_2 | BIT_1 | BIT_0);
  1368. rx_sens = (ha->fw_seriallink_options[0] &
  1369. (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
  1370. ha->fw_options[10] = (emphasis << 14) | (swing << 8);
  1371. if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
  1372. if (rx_sens == 0x0)
  1373. rx_sens = 0x3;
  1374. ha->fw_options[10] |= (tx_sens << 4) | rx_sens;
  1375. } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
  1376. ha->fw_options[10] |= BIT_5 |
  1377. ((rx_sens & (BIT_1 | BIT_0)) << 2) |
  1378. (tx_sens & (BIT_1 | BIT_0));
  1379. /* 2G settings */
  1380. swing = (ha->fw_seriallink_options[2] &
  1381. (BIT_7 | BIT_6 | BIT_5)) >> 5;
  1382. emphasis = ha->fw_seriallink_options[3] & (BIT_1 | BIT_0);
  1383. tx_sens = ha->fw_seriallink_options[1] &
  1384. (BIT_3 | BIT_2 | BIT_1 | BIT_0);
  1385. rx_sens = (ha->fw_seriallink_options[1] &
  1386. (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
  1387. ha->fw_options[11] = (emphasis << 14) | (swing << 8);
  1388. if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
  1389. if (rx_sens == 0x0)
  1390. rx_sens = 0x3;
  1391. ha->fw_options[11] |= (tx_sens << 4) | rx_sens;
  1392. } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
  1393. ha->fw_options[11] |= BIT_5 |
  1394. ((rx_sens & (BIT_1 | BIT_0)) << 2) |
  1395. (tx_sens & (BIT_1 | BIT_0));
  1396. }
  1397. /* FCP2 options. */
  1398. /* Return command IOCBs without waiting for an ABTS to complete. */
  1399. ha->fw_options[3] |= BIT_13;
  1400. /* LED scheme. */
  1401. if (ha->flags.enable_led_scheme)
  1402. ha->fw_options[2] |= BIT_12;
  1403. /* Detect ISP6312. */
  1404. if (IS_QLA6312(ha))
  1405. ha->fw_options[2] |= BIT_13;
  1406. /* Update firmware options. */
  1407. qla2x00_set_fw_options(vha, ha->fw_options);
  1408. }
  1409. void
  1410. qla24xx_update_fw_options(scsi_qla_host_t *vha)
  1411. {
  1412. int rval;
  1413. struct qla_hw_data *ha = vha->hw;
  1414. if (IS_QLA82XX(ha))
  1415. return;
  1416. /* Update Serial Link options. */
  1417. if ((le16_to_cpu(ha->fw_seriallink_options24[0]) & BIT_0) == 0)
  1418. return;
  1419. rval = qla2x00_set_serdes_params(vha,
  1420. le16_to_cpu(ha->fw_seriallink_options24[1]),
  1421. le16_to_cpu(ha->fw_seriallink_options24[2]),
  1422. le16_to_cpu(ha->fw_seriallink_options24[3]));
  1423. if (rval != QLA_SUCCESS) {
  1424. qla_printk(KERN_WARNING, ha,
  1425. "Unable to update Serial Link options (%x).\n", rval);
  1426. }
  1427. }
  1428. void
  1429. qla2x00_config_rings(struct scsi_qla_host *vha)
  1430. {
  1431. struct qla_hw_data *ha = vha->hw;
  1432. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  1433. struct req_que *req = ha->req_q_map[0];
  1434. struct rsp_que *rsp = ha->rsp_q_map[0];
  1435. /* Setup ring parameters in initialization control block. */
  1436. ha->init_cb->request_q_outpointer = __constant_cpu_to_le16(0);
  1437. ha->init_cb->response_q_inpointer = __constant_cpu_to_le16(0);
  1438. ha->init_cb->request_q_length = cpu_to_le16(req->length);
  1439. ha->init_cb->response_q_length = cpu_to_le16(rsp->length);
  1440. ha->init_cb->request_q_address[0] = cpu_to_le32(LSD(req->dma));
  1441. ha->init_cb->request_q_address[1] = cpu_to_le32(MSD(req->dma));
  1442. ha->init_cb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma));
  1443. ha->init_cb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma));
  1444. WRT_REG_WORD(ISP_REQ_Q_IN(ha, reg), 0);
  1445. WRT_REG_WORD(ISP_REQ_Q_OUT(ha, reg), 0);
  1446. WRT_REG_WORD(ISP_RSP_Q_IN(ha, reg), 0);
  1447. WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), 0);
  1448. RD_REG_WORD(ISP_RSP_Q_OUT(ha, reg)); /* PCI Posting. */
  1449. }
  1450. void
  1451. qla24xx_config_rings(struct scsi_qla_host *vha)
  1452. {
  1453. struct qla_hw_data *ha = vha->hw;
  1454. device_reg_t __iomem *reg = ISP_QUE_REG(ha, 0);
  1455. struct device_reg_2xxx __iomem *ioreg = &ha->iobase->isp;
  1456. struct qla_msix_entry *msix;
  1457. struct init_cb_24xx *icb;
  1458. uint16_t rid = 0;
  1459. struct req_que *req = ha->req_q_map[0];
  1460. struct rsp_que *rsp = ha->rsp_q_map[0];
  1461. /* Setup ring parameters in initialization control block. */
  1462. icb = (struct init_cb_24xx *)ha->init_cb;
  1463. icb->request_q_outpointer = __constant_cpu_to_le16(0);
  1464. icb->response_q_inpointer = __constant_cpu_to_le16(0);
  1465. icb->request_q_length = cpu_to_le16(req->length);
  1466. icb->response_q_length = cpu_to_le16(rsp->length);
  1467. icb->request_q_address[0] = cpu_to_le32(LSD(req->dma));
  1468. icb->request_q_address[1] = cpu_to_le32(MSD(req->dma));
  1469. icb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma));
  1470. icb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma));
  1471. if (ha->mqenable) {
  1472. icb->qos = __constant_cpu_to_le16(QLA_DEFAULT_QUE_QOS);
  1473. icb->rid = __constant_cpu_to_le16(rid);
  1474. if (ha->flags.msix_enabled) {
  1475. msix = &ha->msix_entries[1];
  1476. DEBUG2_17(printk(KERN_INFO
  1477. "Registering vector 0x%x for base que\n", msix->entry));
  1478. icb->msix = cpu_to_le16(msix->entry);
  1479. }
  1480. /* Use alternate PCI bus number */
  1481. if (MSB(rid))
  1482. icb->firmware_options_2 |=
  1483. __constant_cpu_to_le32(BIT_19);
  1484. /* Use alternate PCI devfn */
  1485. if (LSB(rid))
  1486. icb->firmware_options_2 |=
  1487. __constant_cpu_to_le32(BIT_18);
  1488. /* Use Disable MSIX Handshake mode for capable adapters */
  1489. if (IS_MSIX_NACK_CAPABLE(ha)) {
  1490. icb->firmware_options_2 &=
  1491. __constant_cpu_to_le32(~BIT_22);
  1492. ha->flags.disable_msix_handshake = 1;
  1493. qla_printk(KERN_INFO, ha,
  1494. "MSIX Handshake Disable Mode turned on\n");
  1495. } else {
  1496. icb->firmware_options_2 |=
  1497. __constant_cpu_to_le32(BIT_22);
  1498. }
  1499. icb->firmware_options_2 |= __constant_cpu_to_le32(BIT_23);
  1500. WRT_REG_DWORD(&reg->isp25mq.req_q_in, 0);
  1501. WRT_REG_DWORD(&reg->isp25mq.req_q_out, 0);
  1502. WRT_REG_DWORD(&reg->isp25mq.rsp_q_in, 0);
  1503. WRT_REG_DWORD(&reg->isp25mq.rsp_q_out, 0);
  1504. } else {
  1505. WRT_REG_DWORD(&reg->isp24.req_q_in, 0);
  1506. WRT_REG_DWORD(&reg->isp24.req_q_out, 0);
  1507. WRT_REG_DWORD(&reg->isp24.rsp_q_in, 0);
  1508. WRT_REG_DWORD(&reg->isp24.rsp_q_out, 0);
  1509. }
  1510. /* PCI posting */
  1511. RD_REG_DWORD(&ioreg->hccr);
  1512. }
  1513. /**
  1514. * qla2x00_init_rings() - Initializes firmware.
  1515. * @ha: HA context
  1516. *
  1517. * Beginning of request ring has initialization control block already built
  1518. * by nvram config routine.
  1519. *
  1520. * Returns 0 on success.
  1521. */
  1522. static int
  1523. qla2x00_init_rings(scsi_qla_host_t *vha)
  1524. {
  1525. int rval;
  1526. unsigned long flags = 0;
  1527. int cnt, que;
  1528. struct qla_hw_data *ha = vha->hw;
  1529. struct req_que *req;
  1530. struct rsp_que *rsp;
  1531. struct scsi_qla_host *vp;
  1532. struct mid_init_cb_24xx *mid_init_cb =
  1533. (struct mid_init_cb_24xx *) ha->init_cb;
  1534. spin_lock_irqsave(&ha->hardware_lock, flags);
  1535. /* Clear outstanding commands array. */
  1536. for (que = 0; que < ha->max_req_queues; que++) {
  1537. req = ha->req_q_map[que];
  1538. if (!req)
  1539. continue;
  1540. for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++)
  1541. req->outstanding_cmds[cnt] = NULL;
  1542. req->current_outstanding_cmd = 1;
  1543. /* Initialize firmware. */
  1544. req->ring_ptr = req->ring;
  1545. req->ring_index = 0;
  1546. req->cnt = req->length;
  1547. }
  1548. for (que = 0; que < ha->max_rsp_queues; que++) {
  1549. rsp = ha->rsp_q_map[que];
  1550. if (!rsp)
  1551. continue;
  1552. /* Initialize response queue entries */
  1553. qla2x00_init_response_q_entries(rsp);
  1554. }
  1555. spin_lock(&ha->vport_slock);
  1556. /* Clear RSCN queue. */
  1557. list_for_each_entry(vp, &ha->vp_list, list) {
  1558. vp->rscn_in_ptr = 0;
  1559. vp->rscn_out_ptr = 0;
  1560. }
  1561. spin_unlock(&ha->vport_slock);
  1562. ha->isp_ops->config_rings(vha);
  1563. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1564. /* Update any ISP specific firmware options before initialization. */
  1565. ha->isp_ops->update_fw_options(vha);
  1566. DEBUG(printk("scsi(%ld): Issue init firmware.\n", vha->host_no));
  1567. if (ha->flags.npiv_supported) {
  1568. if (ha->operating_mode == LOOP)
  1569. ha->max_npiv_vports = MIN_MULTI_ID_FABRIC - 1;
  1570. mid_init_cb->count = cpu_to_le16(ha->max_npiv_vports);
  1571. }
  1572. if (IS_FWI2_CAPABLE(ha)) {
  1573. mid_init_cb->options = __constant_cpu_to_le16(BIT_1);
  1574. mid_init_cb->init_cb.execution_throttle =
  1575. cpu_to_le16(ha->fw_xcb_count);
  1576. }
  1577. rval = qla2x00_init_firmware(vha, ha->init_cb_size);
  1578. if (rval) {
  1579. DEBUG2_3(printk("scsi(%ld): Init firmware **** FAILED ****.\n",
  1580. vha->host_no));
  1581. } else {
  1582. DEBUG3(printk("scsi(%ld): Init firmware -- success.\n",
  1583. vha->host_no));
  1584. }
  1585. return (rval);
  1586. }
  1587. /**
  1588. * qla2x00_fw_ready() - Waits for firmware ready.
  1589. * @ha: HA context
  1590. *
  1591. * Returns 0 on success.
  1592. */
  1593. static int
  1594. qla2x00_fw_ready(scsi_qla_host_t *vha)
  1595. {
  1596. int rval;
  1597. unsigned long wtime, mtime, cs84xx_time;
  1598. uint16_t min_wait; /* Minimum wait time if loop is down */
  1599. uint16_t wait_time; /* Wait time if loop is coming ready */
  1600. uint16_t state[5];
  1601. struct qla_hw_data *ha = vha->hw;
  1602. rval = QLA_SUCCESS;
  1603. /* 20 seconds for loop down. */
  1604. min_wait = 20;
  1605. /*
  1606. * Firmware should take at most one RATOV to login, plus 5 seconds for
  1607. * our own processing.
  1608. */
  1609. if ((wait_time = (ha->retry_count*ha->login_timeout) + 5) < min_wait) {
  1610. wait_time = min_wait;
  1611. }
  1612. /* Min wait time if loop down */
  1613. mtime = jiffies + (min_wait * HZ);
  1614. /* wait time before firmware ready */
  1615. wtime = jiffies + (wait_time * HZ);
  1616. /* Wait for ISP to finish LIP */
  1617. if (!vha->flags.init_done)
  1618. qla_printk(KERN_INFO, ha, "Waiting for LIP to complete...\n");
  1619. DEBUG3(printk("scsi(%ld): Waiting for LIP to complete...\n",
  1620. vha->host_no));
  1621. do {
  1622. rval = qla2x00_get_firmware_state(vha, state);
  1623. if (rval == QLA_SUCCESS) {
  1624. if (state[0] < FSTATE_LOSS_OF_SYNC) {
  1625. vha->device_flags &= ~DFLG_NO_CABLE;
  1626. }
  1627. if (IS_QLA84XX(ha) && state[0] != FSTATE_READY) {
  1628. DEBUG16(printk("scsi(%ld): fw_state=%x "
  1629. "84xx=%x.\n", vha->host_no, state[0],
  1630. state[2]));
  1631. if ((state[2] & FSTATE_LOGGED_IN) &&
  1632. (state[2] & FSTATE_WAITING_FOR_VERIFY)) {
  1633. DEBUG16(printk("scsi(%ld): Sending "
  1634. "verify iocb.\n", vha->host_no));
  1635. cs84xx_time = jiffies;
  1636. rval = qla84xx_init_chip(vha);
  1637. if (rval != QLA_SUCCESS)
  1638. break;
  1639. /* Add time taken to initialize. */
  1640. cs84xx_time = jiffies - cs84xx_time;
  1641. wtime += cs84xx_time;
  1642. mtime += cs84xx_time;
  1643. DEBUG16(printk("scsi(%ld): Increasing "
  1644. "wait time by %ld. New time %ld\n",
  1645. vha->host_no, cs84xx_time, wtime));
  1646. }
  1647. } else if (state[0] == FSTATE_READY) {
  1648. DEBUG(printk("scsi(%ld): F/W Ready - OK \n",
  1649. vha->host_no));
  1650. qla2x00_get_retry_cnt(vha, &ha->retry_count,
  1651. &ha->login_timeout, &ha->r_a_tov);
  1652. rval = QLA_SUCCESS;
  1653. break;
  1654. }
  1655. rval = QLA_FUNCTION_FAILED;
  1656. if (atomic_read(&vha->loop_down_timer) &&
  1657. state[0] != FSTATE_READY) {
  1658. /* Loop down. Timeout on min_wait for states
  1659. * other than Wait for Login.
  1660. */
  1661. if (time_after_eq(jiffies, mtime)) {
  1662. qla_printk(KERN_INFO, ha,
  1663. "Cable is unplugged...\n");
  1664. vha->device_flags |= DFLG_NO_CABLE;
  1665. break;
  1666. }
  1667. }
  1668. } else {
  1669. /* Mailbox cmd failed. Timeout on min_wait. */
  1670. if (time_after_eq(jiffies, mtime) ||
  1671. ha->flags.isp82xx_fw_hung)
  1672. break;
  1673. }
  1674. if (time_after_eq(jiffies, wtime))
  1675. break;
  1676. /* Delay for a while */
  1677. msleep(500);
  1678. DEBUG3(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
  1679. vha->host_no, state[0], jiffies));
  1680. } while (1);
  1681. DEBUG(printk("scsi(%ld): fw_state=%x (%x, %x, %x, %x) curr time=%lx.\n",
  1682. vha->host_no, state[0], state[1], state[2], state[3], state[4],
  1683. jiffies));
  1684. if (rval) {
  1685. DEBUG2_3(printk("scsi(%ld): Firmware ready **** FAILED ****.\n",
  1686. vha->host_no));
  1687. }
  1688. return (rval);
  1689. }
  1690. /*
  1691. * qla2x00_configure_hba
  1692. * Setup adapter context.
  1693. *
  1694. * Input:
  1695. * ha = adapter state pointer.
  1696. *
  1697. * Returns:
  1698. * 0 = success
  1699. *
  1700. * Context:
  1701. * Kernel context.
  1702. */
  1703. static int
  1704. qla2x00_configure_hba(scsi_qla_host_t *vha)
  1705. {
  1706. int rval;
  1707. uint16_t loop_id;
  1708. uint16_t topo;
  1709. uint16_t sw_cap;
  1710. uint8_t al_pa;
  1711. uint8_t area;
  1712. uint8_t domain;
  1713. char connect_type[22];
  1714. struct qla_hw_data *ha = vha->hw;
  1715. /* Get host addresses. */
  1716. rval = qla2x00_get_adapter_id(vha,
  1717. &loop_id, &al_pa, &area, &domain, &topo, &sw_cap);
  1718. if (rval != QLA_SUCCESS) {
  1719. if (LOOP_TRANSITION(vha) || atomic_read(&ha->loop_down_timer) ||
  1720. IS_QLA8XXX_TYPE(ha) ||
  1721. (rval == QLA_COMMAND_ERROR && loop_id == 0x7)) {
  1722. DEBUG2(printk("%s(%ld) Loop is in a transition state\n",
  1723. __func__, vha->host_no));
  1724. } else {
  1725. qla_printk(KERN_WARNING, ha,
  1726. "ERROR -- Unable to get host loop ID.\n");
  1727. set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
  1728. }
  1729. return (rval);
  1730. }
  1731. if (topo == 4) {
  1732. qla_printk(KERN_INFO, ha,
  1733. "Cannot get topology - retrying.\n");
  1734. return (QLA_FUNCTION_FAILED);
  1735. }
  1736. vha->loop_id = loop_id;
  1737. /* initialize */
  1738. ha->min_external_loopid = SNS_FIRST_LOOP_ID;
  1739. ha->operating_mode = LOOP;
  1740. ha->switch_cap = 0;
  1741. switch (topo) {
  1742. case 0:
  1743. DEBUG3(printk("scsi(%ld): HBA in NL topology.\n",
  1744. vha->host_no));
  1745. ha->current_topology = ISP_CFG_NL;
  1746. strcpy(connect_type, "(Loop)");
  1747. break;
  1748. case 1:
  1749. DEBUG3(printk("scsi(%ld): HBA in FL topology.\n",
  1750. vha->host_no));
  1751. ha->switch_cap = sw_cap;
  1752. ha->current_topology = ISP_CFG_FL;
  1753. strcpy(connect_type, "(FL_Port)");
  1754. break;
  1755. case 2:
  1756. DEBUG3(printk("scsi(%ld): HBA in N P2P topology.\n",
  1757. vha->host_no));
  1758. ha->operating_mode = P2P;
  1759. ha->current_topology = ISP_CFG_N;
  1760. strcpy(connect_type, "(N_Port-to-N_Port)");
  1761. break;
  1762. case 3:
  1763. DEBUG3(printk("scsi(%ld): HBA in F P2P topology.\n",
  1764. vha->host_no));
  1765. ha->switch_cap = sw_cap;
  1766. ha->operating_mode = P2P;
  1767. ha->current_topology = ISP_CFG_F;
  1768. strcpy(connect_type, "(F_Port)");
  1769. break;
  1770. default:
  1771. DEBUG3(printk("scsi(%ld): HBA in unknown topology %x. "
  1772. "Using NL.\n",
  1773. vha->host_no, topo));
  1774. ha->current_topology = ISP_CFG_NL;
  1775. strcpy(connect_type, "(Loop)");
  1776. break;
  1777. }
  1778. /* Save Host port and loop ID. */
  1779. /* byte order - Big Endian */
  1780. vha->d_id.b.domain = domain;
  1781. vha->d_id.b.area = area;
  1782. vha->d_id.b.al_pa = al_pa;
  1783. if (!vha->flags.init_done)
  1784. qla_printk(KERN_INFO, ha,
  1785. "Topology - %s, Host Loop address 0x%x\n",
  1786. connect_type, vha->loop_id);
  1787. if (rval) {
  1788. DEBUG2_3(printk("scsi(%ld): FAILED.\n", vha->host_no));
  1789. } else {
  1790. DEBUG3(printk("scsi(%ld): exiting normally.\n", vha->host_no));
  1791. }
  1792. return(rval);
  1793. }
  1794. inline void
  1795. qla2x00_set_model_info(scsi_qla_host_t *vha, uint8_t *model, size_t len,
  1796. char *def)
  1797. {
  1798. char *st, *en;
  1799. uint16_t index;
  1800. struct qla_hw_data *ha = vha->hw;
  1801. int use_tbl = !IS_QLA24XX_TYPE(ha) && !IS_QLA25XX(ha) &&
  1802. !IS_QLA8XXX_TYPE(ha);
  1803. if (memcmp(model, BINZERO, len) != 0) {
  1804. strncpy(ha->model_number, model, len);
  1805. st = en = ha->model_number;
  1806. en += len - 1;
  1807. while (en > st) {
  1808. if (*en != 0x20 && *en != 0x00)
  1809. break;
  1810. *en-- = '\0';
  1811. }
  1812. index = (ha->pdev->subsystem_device & 0xff);
  1813. if (use_tbl &&
  1814. ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
  1815. index < QLA_MODEL_NAMES)
  1816. strncpy(ha->model_desc,
  1817. qla2x00_model_name[index * 2 + 1],
  1818. sizeof(ha->model_desc) - 1);
  1819. } else {
  1820. index = (ha->pdev->subsystem_device & 0xff);
  1821. if (use_tbl &&
  1822. ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
  1823. index < QLA_MODEL_NAMES) {
  1824. strcpy(ha->model_number,
  1825. qla2x00_model_name[index * 2]);
  1826. strncpy(ha->model_desc,
  1827. qla2x00_model_name[index * 2 + 1],
  1828. sizeof(ha->model_desc) - 1);
  1829. } else {
  1830. strcpy(ha->model_number, def);
  1831. }
  1832. }
  1833. if (IS_FWI2_CAPABLE(ha))
  1834. qla2xxx_get_vpd_field(vha, "\x82", ha->model_desc,
  1835. sizeof(ha->model_desc));
  1836. }
  1837. /* On sparc systems, obtain port and node WWN from firmware
  1838. * properties.
  1839. */
  1840. static void qla2xxx_nvram_wwn_from_ofw(scsi_qla_host_t *vha, nvram_t *nv)
  1841. {
  1842. #ifdef CONFIG_SPARC
  1843. struct qla_hw_data *ha = vha->hw;
  1844. struct pci_dev *pdev = ha->pdev;
  1845. struct device_node *dp = pci_device_to_OF_node(pdev);
  1846. const u8 *val;
  1847. int len;
  1848. val = of_get_property(dp, "port-wwn", &len);
  1849. if (val && len >= WWN_SIZE)
  1850. memcpy(nv->port_name, val, WWN_SIZE);
  1851. val = of_get_property(dp, "node-wwn", &len);
  1852. if (val && len >= WWN_SIZE)
  1853. memcpy(nv->node_name, val, WWN_SIZE);
  1854. #endif
  1855. }
  1856. /*
  1857. * NVRAM configuration for ISP 2xxx
  1858. *
  1859. * Input:
  1860. * ha = adapter block pointer.
  1861. *
  1862. * Output:
  1863. * initialization control block in response_ring
  1864. * host adapters parameters in host adapter block
  1865. *
  1866. * Returns:
  1867. * 0 = success.
  1868. */
  1869. int
  1870. qla2x00_nvram_config(scsi_qla_host_t *vha)
  1871. {
  1872. int rval;
  1873. uint8_t chksum = 0;
  1874. uint16_t cnt;
  1875. uint8_t *dptr1, *dptr2;
  1876. struct qla_hw_data *ha = vha->hw;
  1877. init_cb_t *icb = ha->init_cb;
  1878. nvram_t *nv = ha->nvram;
  1879. uint8_t *ptr = ha->nvram;
  1880. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  1881. rval = QLA_SUCCESS;
  1882. /* Determine NVRAM starting address. */
  1883. ha->nvram_size = sizeof(nvram_t);
  1884. ha->nvram_base = 0;
  1885. if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha))
  1886. if ((RD_REG_WORD(&reg->ctrl_status) >> 14) == 1)
  1887. ha->nvram_base = 0x80;
  1888. /* Get NVRAM data and calculate checksum. */
  1889. ha->isp_ops->read_nvram(vha, ptr, ha->nvram_base, ha->nvram_size);
  1890. for (cnt = 0, chksum = 0; cnt < ha->nvram_size; cnt++)
  1891. chksum += *ptr++;
  1892. DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", vha->host_no));
  1893. DEBUG5(qla2x00_dump_buffer((uint8_t *)nv, ha->nvram_size));
  1894. /* Bad NVRAM data, set defaults parameters. */
  1895. if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' ||
  1896. nv->id[2] != 'P' || nv->id[3] != ' ' || nv->nvram_version < 1) {
  1897. /* Reset NVRAM data. */
  1898. qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
  1899. "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
  1900. nv->nvram_version);
  1901. qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
  1902. "invalid -- WWPN) defaults.\n");
  1903. /*
  1904. * Set default initialization control block.
  1905. */
  1906. memset(nv, 0, ha->nvram_size);
  1907. nv->parameter_block_version = ICB_VERSION;
  1908. if (IS_QLA23XX(ha)) {
  1909. nv->firmware_options[0] = BIT_2 | BIT_1;
  1910. nv->firmware_options[1] = BIT_7 | BIT_5;
  1911. nv->add_firmware_options[0] = BIT_5;
  1912. nv->add_firmware_options[1] = BIT_5 | BIT_4;
  1913. nv->frame_payload_size = __constant_cpu_to_le16(2048);
  1914. nv->special_options[1] = BIT_7;
  1915. } else if (IS_QLA2200(ha)) {
  1916. nv->firmware_options[0] = BIT_2 | BIT_1;
  1917. nv->firmware_options[1] = BIT_7 | BIT_5;
  1918. nv->add_firmware_options[0] = BIT_5;
  1919. nv->add_firmware_options[1] = BIT_5 | BIT_4;
  1920. nv->frame_payload_size = __constant_cpu_to_le16(1024);
  1921. } else if (IS_QLA2100(ha)) {
  1922. nv->firmware_options[0] = BIT_3 | BIT_1;
  1923. nv->firmware_options[1] = BIT_5;
  1924. nv->frame_payload_size = __constant_cpu_to_le16(1024);
  1925. }
  1926. nv->max_iocb_allocation = __constant_cpu_to_le16(256);
  1927. nv->execution_throttle = __constant_cpu_to_le16(16);
  1928. nv->retry_count = 8;
  1929. nv->retry_delay = 1;
  1930. nv->port_name[0] = 33;
  1931. nv->port_name[3] = 224;
  1932. nv->port_name[4] = 139;
  1933. qla2xxx_nvram_wwn_from_ofw(vha, nv);
  1934. nv->login_timeout = 4;
  1935. /*
  1936. * Set default host adapter parameters
  1937. */
  1938. nv->host_p[1] = BIT_2;
  1939. nv->reset_delay = 5;
  1940. nv->port_down_retry_count = 8;
  1941. nv->max_luns_per_target = __constant_cpu_to_le16(8);
  1942. nv->link_down_timeout = 60;
  1943. rval = 1;
  1944. }
  1945. #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
  1946. /*
  1947. * The SN2 does not provide BIOS emulation which means you can't change
  1948. * potentially bogus BIOS settings. Force the use of default settings
  1949. * for link rate and frame size. Hope that the rest of the settings
  1950. * are valid.
  1951. */
  1952. if (ia64_platform_is("sn2")) {
  1953. nv->frame_payload_size = __constant_cpu_to_le16(2048);
  1954. if (IS_QLA23XX(ha))
  1955. nv->special_options[1] = BIT_7;
  1956. }
  1957. #endif
  1958. /* Reset Initialization control block */
  1959. memset(icb, 0, ha->init_cb_size);
  1960. /*
  1961. * Setup driver NVRAM options.
  1962. */
  1963. nv->firmware_options[0] |= (BIT_6 | BIT_1);
  1964. nv->firmware_options[0] &= ~(BIT_5 | BIT_4);
  1965. nv->firmware_options[1] |= (BIT_5 | BIT_0);
  1966. nv->firmware_options[1] &= ~BIT_4;
  1967. if (IS_QLA23XX(ha)) {
  1968. nv->firmware_options[0] |= BIT_2;
  1969. nv->firmware_options[0] &= ~BIT_3;
  1970. nv->firmware_options[0] &= ~BIT_6;
  1971. nv->add_firmware_options[1] |= BIT_5 | BIT_4;
  1972. if (IS_QLA2300(ha)) {
  1973. if (ha->fb_rev == FPM_2310) {
  1974. strcpy(ha->model_number, "QLA2310");
  1975. } else {
  1976. strcpy(ha->model_number, "QLA2300");
  1977. }
  1978. } else {
  1979. qla2x00_set_model_info(vha, nv->model_number,
  1980. sizeof(nv->model_number), "QLA23xx");
  1981. }
  1982. } else if (IS_QLA2200(ha)) {
  1983. nv->firmware_options[0] |= BIT_2;
  1984. /*
  1985. * 'Point-to-point preferred, else loop' is not a safe
  1986. * connection mode setting.
  1987. */
  1988. if ((nv->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) ==
  1989. (BIT_5 | BIT_4)) {
  1990. /* Force 'loop preferred, else point-to-point'. */
  1991. nv->add_firmware_options[0] &= ~(BIT_6 | BIT_5 | BIT_4);
  1992. nv->add_firmware_options[0] |= BIT_5;
  1993. }
  1994. strcpy(ha->model_number, "QLA22xx");
  1995. } else /*if (IS_QLA2100(ha))*/ {
  1996. strcpy(ha->model_number, "QLA2100");
  1997. }
  1998. /*
  1999. * Copy over NVRAM RISC parameter block to initialization control block.
  2000. */
  2001. dptr1 = (uint8_t *)icb;
  2002. dptr2 = (uint8_t *)&nv->parameter_block_version;
  2003. cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version;
  2004. while (cnt--)
  2005. *dptr1++ = *dptr2++;
  2006. /* Copy 2nd half. */
  2007. dptr1 = (uint8_t *)icb->add_firmware_options;
  2008. cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options;
  2009. while (cnt--)
  2010. *dptr1++ = *dptr2++;
  2011. /* Use alternate WWN? */
  2012. if (nv->host_p[1] & BIT_7) {
  2013. memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
  2014. memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
  2015. }
  2016. /* Prepare nodename */
  2017. if ((icb->firmware_options[1] & BIT_6) == 0) {
  2018. /*
  2019. * Firmware will apply the following mask if the nodename was
  2020. * not provided.
  2021. */
  2022. memcpy(icb->node_name, icb->port_name, WWN_SIZE);
  2023. icb->node_name[0] &= 0xF0;
  2024. }
  2025. /*
  2026. * Set host adapter parameters.
  2027. */
  2028. if (nv->host_p[0] & BIT_7)
  2029. ql2xextended_error_logging = 1;
  2030. ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0);
  2031. /* Always load RISC code on non ISP2[12]00 chips. */
  2032. if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
  2033. ha->flags.disable_risc_code_load = 0;
  2034. ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0);
  2035. ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0);
  2036. ha->flags.enable_target_reset = ((nv->host_p[1] & BIT_3) ? 1 : 0);
  2037. ha->flags.enable_led_scheme = (nv->special_options[1] & BIT_4) ? 1 : 0;
  2038. ha->flags.disable_serdes = 0;
  2039. ha->operating_mode =
  2040. (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4;
  2041. memcpy(ha->fw_seriallink_options, nv->seriallink_options,
  2042. sizeof(ha->fw_seriallink_options));
  2043. /* save HBA serial number */
  2044. ha->serial0 = icb->port_name[5];
  2045. ha->serial1 = icb->port_name[6];
  2046. ha->serial2 = icb->port_name[7];
  2047. memcpy(vha->node_name, icb->node_name, WWN_SIZE);
  2048. memcpy(vha->port_name, icb->port_name, WWN_SIZE);
  2049. icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
  2050. ha->retry_count = nv->retry_count;
  2051. /* Set minimum login_timeout to 4 seconds. */
  2052. if (nv->login_timeout != ql2xlogintimeout)
  2053. nv->login_timeout = ql2xlogintimeout;
  2054. if (nv->login_timeout < 4)
  2055. nv->login_timeout = 4;
  2056. ha->login_timeout = nv->login_timeout;
  2057. icb->login_timeout = nv->login_timeout;
  2058. /* Set minimum RATOV to 100 tenths of a second. */
  2059. ha->r_a_tov = 100;
  2060. ha->loop_reset_delay = nv->reset_delay;
  2061. /* Link Down Timeout = 0:
  2062. *
  2063. * When Port Down timer expires we will start returning
  2064. * I/O's to OS with "DID_NO_CONNECT".
  2065. *
  2066. * Link Down Timeout != 0:
  2067. *
  2068. * The driver waits for the link to come up after link down
  2069. * before returning I/Os to OS with "DID_NO_CONNECT".
  2070. */
  2071. if (nv->link_down_timeout == 0) {
  2072. ha->loop_down_abort_time =
  2073. (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
  2074. } else {
  2075. ha->link_down_timeout = nv->link_down_timeout;
  2076. ha->loop_down_abort_time =
  2077. (LOOP_DOWN_TIME - ha->link_down_timeout);
  2078. }
  2079. /*
  2080. * Need enough time to try and get the port back.
  2081. */
  2082. ha->port_down_retry_count = nv->port_down_retry_count;
  2083. if (qlport_down_retry)
  2084. ha->port_down_retry_count = qlport_down_retry;
  2085. /* Set login_retry_count */
  2086. ha->login_retry_count = nv->retry_count;
  2087. if (ha->port_down_retry_count == nv->port_down_retry_count &&
  2088. ha->port_down_retry_count > 3)
  2089. ha->login_retry_count = ha->port_down_retry_count;
  2090. else if (ha->port_down_retry_count > (int)ha->login_retry_count)
  2091. ha->login_retry_count = ha->port_down_retry_count;
  2092. if (ql2xloginretrycount)
  2093. ha->login_retry_count = ql2xloginretrycount;
  2094. icb->lun_enables = __constant_cpu_to_le16(0);
  2095. icb->command_resource_count = 0;
  2096. icb->immediate_notify_resource_count = 0;
  2097. icb->timeout = __constant_cpu_to_le16(0);
  2098. if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
  2099. /* Enable RIO */
  2100. icb->firmware_options[0] &= ~BIT_3;
  2101. icb->add_firmware_options[0] &=
  2102. ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
  2103. icb->add_firmware_options[0] |= BIT_2;
  2104. icb->response_accumulation_timer = 3;
  2105. icb->interrupt_delay_timer = 5;
  2106. vha->flags.process_response_queue = 1;
  2107. } else {
  2108. /* Enable ZIO. */
  2109. if (!vha->flags.init_done) {
  2110. ha->zio_mode = icb->add_firmware_options[0] &
  2111. (BIT_3 | BIT_2 | BIT_1 | BIT_0);
  2112. ha->zio_timer = icb->interrupt_delay_timer ?
  2113. icb->interrupt_delay_timer: 2;
  2114. }
  2115. icb->add_firmware_options[0] &=
  2116. ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
  2117. vha->flags.process_response_queue = 0;
  2118. if (ha->zio_mode != QLA_ZIO_DISABLED) {
  2119. ha->zio_mode = QLA_ZIO_MODE_6;
  2120. DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer "
  2121. "delay (%d us).\n", vha->host_no, ha->zio_mode,
  2122. ha->zio_timer * 100));
  2123. qla_printk(KERN_INFO, ha,
  2124. "ZIO mode %d enabled; timer delay (%d us).\n",
  2125. ha->zio_mode, ha->zio_timer * 100);
  2126. icb->add_firmware_options[0] |= (uint8_t)ha->zio_mode;
  2127. icb->interrupt_delay_timer = (uint8_t)ha->zio_timer;
  2128. vha->flags.process_response_queue = 1;
  2129. }
  2130. }
  2131. if (rval) {
  2132. DEBUG2_3(printk(KERN_WARNING
  2133. "scsi(%ld): NVRAM configuration failed!\n", vha->host_no));
  2134. }
  2135. return (rval);
  2136. }
  2137. static void
  2138. qla2x00_rport_del(void *data)
  2139. {
  2140. fc_port_t *fcport = data;
  2141. struct fc_rport *rport;
  2142. unsigned long flags;
  2143. spin_lock_irqsave(fcport->vha->host->host_lock, flags);
  2144. rport = fcport->drport ? fcport->drport: fcport->rport;
  2145. fcport->drport = NULL;
  2146. spin_unlock_irqrestore(fcport->vha->host->host_lock, flags);
  2147. if (rport)
  2148. fc_remote_port_delete(rport);
  2149. }
  2150. /**
  2151. * qla2x00_alloc_fcport() - Allocate a generic fcport.
  2152. * @ha: HA context
  2153. * @flags: allocation flags
  2154. *
  2155. * Returns a pointer to the allocated fcport, or NULL, if none available.
  2156. */
  2157. fc_port_t *
  2158. qla2x00_alloc_fcport(scsi_qla_host_t *vha, gfp_t flags)
  2159. {
  2160. fc_port_t *fcport;
  2161. fcport = kzalloc(sizeof(fc_port_t), flags);
  2162. if (!fcport)
  2163. return NULL;
  2164. /* Setup fcport template structure. */
  2165. fcport->vha = vha;
  2166. fcport->vp_idx = vha->vp_idx;
  2167. fcport->port_type = FCT_UNKNOWN;
  2168. fcport->loop_id = FC_NO_LOOP_ID;
  2169. atomic_set(&fcport->state, FCS_UNCONFIGURED);
  2170. fcport->supported_classes = FC_COS_UNSPECIFIED;
  2171. return fcport;
  2172. }
  2173. /*
  2174. * qla2x00_configure_loop
  2175. * Updates Fibre Channel Device Database with what is actually on loop.
  2176. *
  2177. * Input:
  2178. * ha = adapter block pointer.
  2179. *
  2180. * Returns:
  2181. * 0 = success.
  2182. * 1 = error.
  2183. * 2 = database was full and device was not configured.
  2184. */
  2185. static int
  2186. qla2x00_configure_loop(scsi_qla_host_t *vha)
  2187. {
  2188. int rval;
  2189. unsigned long flags, save_flags;
  2190. struct qla_hw_data *ha = vha->hw;
  2191. rval = QLA_SUCCESS;
  2192. /* Get Initiator ID */
  2193. if (test_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags)) {
  2194. rval = qla2x00_configure_hba(vha);
  2195. if (rval != QLA_SUCCESS) {
  2196. DEBUG(printk("scsi(%ld): Unable to configure HBA.\n",
  2197. vha->host_no));
  2198. return (rval);
  2199. }
  2200. }
  2201. save_flags = flags = vha->dpc_flags;
  2202. DEBUG(printk("scsi(%ld): Configure loop -- dpc flags =0x%lx\n",
  2203. vha->host_no, flags));
  2204. /*
  2205. * If we have both an RSCN and PORT UPDATE pending then handle them
  2206. * both at the same time.
  2207. */
  2208. clear_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
  2209. clear_bit(RSCN_UPDATE, &vha->dpc_flags);
  2210. qla2x00_get_data_rate(vha);
  2211. /* Determine what we need to do */
  2212. if (ha->current_topology == ISP_CFG_FL &&
  2213. (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
  2214. vha->flags.rscn_queue_overflow = 1;
  2215. set_bit(RSCN_UPDATE, &flags);
  2216. } else if (ha->current_topology == ISP_CFG_F &&
  2217. (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
  2218. vha->flags.rscn_queue_overflow = 1;
  2219. set_bit(RSCN_UPDATE, &flags);
  2220. clear_bit(LOCAL_LOOP_UPDATE, &flags);
  2221. } else if (ha->current_topology == ISP_CFG_N) {
  2222. clear_bit(RSCN_UPDATE, &flags);
  2223. } else if (!vha->flags.online ||
  2224. (test_bit(ABORT_ISP_ACTIVE, &flags))) {
  2225. vha->flags.rscn_queue_overflow = 1;
  2226. set_bit(RSCN_UPDATE, &flags);
  2227. set_bit(LOCAL_LOOP_UPDATE, &flags);
  2228. }
  2229. if (test_bit(LOCAL_LOOP_UPDATE, &flags)) {
  2230. if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
  2231. rval = QLA_FUNCTION_FAILED;
  2232. else
  2233. rval = qla2x00_configure_local_loop(vha);
  2234. }
  2235. if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) {
  2236. if (LOOP_TRANSITION(vha))
  2237. rval = QLA_FUNCTION_FAILED;
  2238. else
  2239. rval = qla2x00_configure_fabric(vha);
  2240. }
  2241. if (rval == QLA_SUCCESS) {
  2242. if (atomic_read(&vha->loop_down_timer) ||
  2243. test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
  2244. rval = QLA_FUNCTION_FAILED;
  2245. } else {
  2246. atomic_set(&vha->loop_state, LOOP_READY);
  2247. DEBUG(printk("scsi(%ld): LOOP READY\n", vha->host_no));
  2248. }
  2249. }
  2250. if (rval) {
  2251. DEBUG2_3(printk("%s(%ld): *** FAILED ***\n",
  2252. __func__, vha->host_no));
  2253. } else {
  2254. DEBUG3(printk("%s: exiting normally\n", __func__));
  2255. }
  2256. /* Restore state if a resync event occurred during processing */
  2257. if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
  2258. if (test_bit(LOCAL_LOOP_UPDATE, &save_flags))
  2259. set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
  2260. if (test_bit(RSCN_UPDATE, &save_flags)) {
  2261. set_bit(RSCN_UPDATE, &vha->dpc_flags);
  2262. if (!IS_ALOGIO_CAPABLE(ha))
  2263. vha->flags.rscn_queue_overflow = 1;
  2264. }
  2265. }
  2266. return (rval);
  2267. }
  2268. /*
  2269. * qla2x00_configure_local_loop
  2270. * Updates Fibre Channel Device Database with local loop devices.
  2271. *
  2272. * Input:
  2273. * ha = adapter block pointer.
  2274. *
  2275. * Returns:
  2276. * 0 = success.
  2277. */
  2278. static int
  2279. qla2x00_configure_local_loop(scsi_qla_host_t *vha)
  2280. {
  2281. int rval, rval2;
  2282. int found_devs;
  2283. int found;
  2284. fc_port_t *fcport, *new_fcport;
  2285. uint16_t index;
  2286. uint16_t entries;
  2287. char *id_iter;
  2288. uint16_t loop_id;
  2289. uint8_t domain, area, al_pa;
  2290. struct qla_hw_data *ha = vha->hw;
  2291. found_devs = 0;
  2292. new_fcport = NULL;
  2293. entries = MAX_FIBRE_DEVICES;
  2294. DEBUG3(printk("scsi(%ld): Getting FCAL position map\n", vha->host_no));
  2295. DEBUG3(qla2x00_get_fcal_position_map(vha, NULL));
  2296. /* Get list of logged in devices. */
  2297. memset(ha->gid_list, 0, GID_LIST_SIZE);
  2298. rval = qla2x00_get_id_list(vha, ha->gid_list, ha->gid_list_dma,
  2299. &entries);
  2300. if (rval != QLA_SUCCESS)
  2301. goto cleanup_allocation;
  2302. DEBUG3(printk("scsi(%ld): Entries in ID list (%d)\n",
  2303. vha->host_no, entries));
  2304. DEBUG3(qla2x00_dump_buffer((uint8_t *)ha->gid_list,
  2305. entries * sizeof(struct gid_list_info)));
  2306. /* Allocate temporary fcport for any new fcports discovered. */
  2307. new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
  2308. if (new_fcport == NULL) {
  2309. rval = QLA_MEMORY_ALLOC_FAILED;
  2310. goto cleanup_allocation;
  2311. }
  2312. new_fcport->flags &= ~FCF_FABRIC_DEVICE;
  2313. /*
  2314. * Mark local devices that were present with FCF_DEVICE_LOST for now.
  2315. */
  2316. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  2317. if (atomic_read(&fcport->state) == FCS_ONLINE &&
  2318. fcport->port_type != FCT_BROADCAST &&
  2319. (fcport->flags & FCF_FABRIC_DEVICE) == 0) {
  2320. DEBUG(printk("scsi(%ld): Marking port lost, "
  2321. "loop_id=0x%04x\n",
  2322. vha->host_no, fcport->loop_id));
  2323. atomic_set(&fcport->state, FCS_DEVICE_LOST);
  2324. }
  2325. }
  2326. /* Add devices to port list. */
  2327. id_iter = (char *)ha->gid_list;
  2328. for (index = 0; index < entries; index++) {
  2329. domain = ((struct gid_list_info *)id_iter)->domain;
  2330. area = ((struct gid_list_info *)id_iter)->area;
  2331. al_pa = ((struct gid_list_info *)id_iter)->al_pa;
  2332. if (IS_QLA2100(ha) || IS_QLA2200(ha))
  2333. loop_id = (uint16_t)
  2334. ((struct gid_list_info *)id_iter)->loop_id_2100;
  2335. else
  2336. loop_id = le16_to_cpu(
  2337. ((struct gid_list_info *)id_iter)->loop_id);
  2338. id_iter += ha->gid_list_info_size;
  2339. /* Bypass reserved domain fields. */
  2340. if ((domain & 0xf0) == 0xf0)
  2341. continue;
  2342. /* Bypass if not same domain and area of adapter. */
  2343. if (area && domain &&
  2344. (area != vha->d_id.b.area || domain != vha->d_id.b.domain))
  2345. continue;
  2346. /* Bypass invalid local loop ID. */
  2347. if (loop_id > LAST_LOCAL_LOOP_ID)
  2348. continue;
  2349. /* Fill in member data. */
  2350. new_fcport->d_id.b.domain = domain;
  2351. new_fcport->d_id.b.area = area;
  2352. new_fcport->d_id.b.al_pa = al_pa;
  2353. new_fcport->loop_id = loop_id;
  2354. new_fcport->vp_idx = vha->vp_idx;
  2355. rval2 = qla2x00_get_port_database(vha, new_fcport, 0);
  2356. if (rval2 != QLA_SUCCESS) {
  2357. DEBUG2(printk("scsi(%ld): Failed to retrieve fcport "
  2358. "information -- get_port_database=%x, "
  2359. "loop_id=0x%04x\n",
  2360. vha->host_no, rval2, new_fcport->loop_id));
  2361. DEBUG2(printk("scsi(%ld): Scheduling resync...\n",
  2362. vha->host_no));
  2363. set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
  2364. continue;
  2365. }
  2366. /* Check for matching device in port list. */
  2367. found = 0;
  2368. fcport = NULL;
  2369. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  2370. if (memcmp(new_fcport->port_name, fcport->port_name,
  2371. WWN_SIZE))
  2372. continue;
  2373. fcport->flags &= ~FCF_FABRIC_DEVICE;
  2374. fcport->loop_id = new_fcport->loop_id;
  2375. fcport->port_type = new_fcport->port_type;
  2376. fcport->d_id.b24 = new_fcport->d_id.b24;
  2377. memcpy(fcport->node_name, new_fcport->node_name,
  2378. WWN_SIZE);
  2379. found++;
  2380. break;
  2381. }
  2382. if (!found) {
  2383. /* New device, add to fcports list. */
  2384. if (vha->vp_idx) {
  2385. new_fcport->vha = vha;
  2386. new_fcport->vp_idx = vha->vp_idx;
  2387. }
  2388. list_add_tail(&new_fcport->list, &vha->vp_fcports);
  2389. /* Allocate a new replacement fcport. */
  2390. fcport = new_fcport;
  2391. new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
  2392. if (new_fcport == NULL) {
  2393. rval = QLA_MEMORY_ALLOC_FAILED;
  2394. goto cleanup_allocation;
  2395. }
  2396. new_fcport->flags &= ~FCF_FABRIC_DEVICE;
  2397. }
  2398. /* Base iIDMA settings on HBA port speed. */
  2399. fcport->fp_speed = ha->link_data_rate;
  2400. qla2x00_update_fcport(vha, fcport);
  2401. found_devs++;
  2402. }
  2403. cleanup_allocation:
  2404. kfree(new_fcport);
  2405. if (rval != QLA_SUCCESS) {
  2406. DEBUG2(printk("scsi(%ld): Configure local loop error exit: "
  2407. "rval=%x\n", vha->host_no, rval));
  2408. }
  2409. return (rval);
  2410. }
  2411. static void
  2412. qla2x00_iidma_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
  2413. {
  2414. #define LS_UNKNOWN 2
  2415. static char *link_speeds[] = { "1", "2", "?", "4", "8", "10" };
  2416. char *link_speed;
  2417. int rval;
  2418. uint16_t mb[4];
  2419. struct qla_hw_data *ha = vha->hw;
  2420. if (!IS_IIDMA_CAPABLE(ha))
  2421. return;
  2422. if (atomic_read(&fcport->state) != FCS_ONLINE)
  2423. return;
  2424. if (fcport->fp_speed == PORT_SPEED_UNKNOWN ||
  2425. fcport->fp_speed > ha->link_data_rate)
  2426. return;
  2427. rval = qla2x00_set_idma_speed(vha, fcport->loop_id, fcport->fp_speed,
  2428. mb);
  2429. if (rval != QLA_SUCCESS) {
  2430. DEBUG2(printk("scsi(%ld): Unable to adjust iIDMA "
  2431. "%02x%02x%02x%02x%02x%02x%02x%02x -- %04x %x %04x %04x.\n",
  2432. vha->host_no, fcport->port_name[0], fcport->port_name[1],
  2433. fcport->port_name[2], fcport->port_name[3],
  2434. fcport->port_name[4], fcport->port_name[5],
  2435. fcport->port_name[6], fcport->port_name[7], rval,
  2436. fcport->fp_speed, mb[0], mb[1]));
  2437. } else {
  2438. link_speed = link_speeds[LS_UNKNOWN];
  2439. if (fcport->fp_speed < 5)
  2440. link_speed = link_speeds[fcport->fp_speed];
  2441. else if (fcport->fp_speed == 0x13)
  2442. link_speed = link_speeds[5];
  2443. DEBUG2(qla_printk(KERN_INFO, ha,
  2444. "iIDMA adjusted to %s GB/s on "
  2445. "%02x%02x%02x%02x%02x%02x%02x%02x.\n",
  2446. link_speed, fcport->port_name[0],
  2447. fcport->port_name[1], fcport->port_name[2],
  2448. fcport->port_name[3], fcport->port_name[4],
  2449. fcport->port_name[5], fcport->port_name[6],
  2450. fcport->port_name[7]));
  2451. }
  2452. }
  2453. static void
  2454. qla2x00_reg_remote_port(scsi_qla_host_t *vha, fc_port_t *fcport)
  2455. {
  2456. struct fc_rport_identifiers rport_ids;
  2457. struct fc_rport *rport;
  2458. struct qla_hw_data *ha = vha->hw;
  2459. unsigned long flags;
  2460. qla2x00_rport_del(fcport);
  2461. rport_ids.node_name = wwn_to_u64(fcport->node_name);
  2462. rport_ids.port_name = wwn_to_u64(fcport->port_name);
  2463. rport_ids.port_id = fcport->d_id.b.domain << 16 |
  2464. fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
  2465. rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
  2466. fcport->rport = rport = fc_remote_port_add(vha->host, 0, &rport_ids);
  2467. if (!rport) {
  2468. qla_printk(KERN_WARNING, ha,
  2469. "Unable to allocate fc remote port!\n");
  2470. return;
  2471. }
  2472. spin_lock_irqsave(fcport->vha->host->host_lock, flags);
  2473. *((fc_port_t **)rport->dd_data) = fcport;
  2474. spin_unlock_irqrestore(fcport->vha->host->host_lock, flags);
  2475. rport->supported_classes = fcport->supported_classes;
  2476. rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
  2477. if (fcport->port_type == FCT_INITIATOR)
  2478. rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
  2479. if (fcport->port_type == FCT_TARGET)
  2480. rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
  2481. fc_remote_port_rolechg(rport, rport_ids.roles);
  2482. }
  2483. /*
  2484. * qla2x00_update_fcport
  2485. * Updates device on list.
  2486. *
  2487. * Input:
  2488. * ha = adapter block pointer.
  2489. * fcport = port structure pointer.
  2490. *
  2491. * Return:
  2492. * 0 - Success
  2493. * BIT_0 - error
  2494. *
  2495. * Context:
  2496. * Kernel context.
  2497. */
  2498. void
  2499. qla2x00_update_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
  2500. {
  2501. fcport->vha = vha;
  2502. fcport->login_retry = 0;
  2503. fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
  2504. qla2x00_iidma_fcport(vha, fcport);
  2505. qla24xx_update_fcport_fcp_prio(vha, fcport);
  2506. qla2x00_reg_remote_port(vha, fcport);
  2507. atomic_set(&fcport->state, FCS_ONLINE);
  2508. }
  2509. /*
  2510. * qla2x00_configure_fabric
  2511. * Setup SNS devices with loop ID's.
  2512. *
  2513. * Input:
  2514. * ha = adapter block pointer.
  2515. *
  2516. * Returns:
  2517. * 0 = success.
  2518. * BIT_0 = error
  2519. */
  2520. static int
  2521. qla2x00_configure_fabric(scsi_qla_host_t *vha)
  2522. {
  2523. int rval, rval2;
  2524. fc_port_t *fcport, *fcptemp;
  2525. uint16_t next_loopid;
  2526. uint16_t mb[MAILBOX_REGISTER_COUNT];
  2527. uint16_t loop_id;
  2528. LIST_HEAD(new_fcports);
  2529. struct qla_hw_data *ha = vha->hw;
  2530. struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
  2531. /* If FL port exists, then SNS is present */
  2532. if (IS_FWI2_CAPABLE(ha))
  2533. loop_id = NPH_F_PORT;
  2534. else
  2535. loop_id = SNS_FL_PORT;
  2536. rval = qla2x00_get_port_name(vha, loop_id, vha->fabric_node_name, 1);
  2537. if (rval != QLA_SUCCESS) {
  2538. DEBUG2(printk("scsi(%ld): MBC_GET_PORT_NAME Failed, No FL "
  2539. "Port\n", vha->host_no));
  2540. vha->device_flags &= ~SWITCH_FOUND;
  2541. return (QLA_SUCCESS);
  2542. }
  2543. vha->device_flags |= SWITCH_FOUND;
  2544. /* Mark devices that need re-synchronization. */
  2545. rval2 = qla2x00_device_resync(vha);
  2546. if (rval2 == QLA_RSCNS_HANDLED) {
  2547. /* No point doing the scan, just continue. */
  2548. return (QLA_SUCCESS);
  2549. }
  2550. do {
  2551. /* FDMI support. */
  2552. if (ql2xfdmienable &&
  2553. test_and_clear_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags))
  2554. qla2x00_fdmi_register(vha);
  2555. /* Ensure we are logged into the SNS. */
  2556. if (IS_FWI2_CAPABLE(ha))
  2557. loop_id = NPH_SNS;
  2558. else
  2559. loop_id = SIMPLE_NAME_SERVER;
  2560. ha->isp_ops->fabric_login(vha, loop_id, 0xff, 0xff,
  2561. 0xfc, mb, BIT_1 | BIT_0);
  2562. if (mb[0] != MBS_COMMAND_COMPLETE) {
  2563. DEBUG2(qla_printk(KERN_INFO, ha,
  2564. "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
  2565. "mb[2]=%x mb[6]=%x mb[7]=%x\n", loop_id,
  2566. mb[0], mb[1], mb[2], mb[6], mb[7]));
  2567. return (QLA_SUCCESS);
  2568. }
  2569. if (test_and_clear_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags)) {
  2570. if (qla2x00_rft_id(vha)) {
  2571. /* EMPTY */
  2572. DEBUG2(printk("scsi(%ld): Register FC-4 "
  2573. "TYPE failed.\n", vha->host_no));
  2574. }
  2575. if (qla2x00_rff_id(vha)) {
  2576. /* EMPTY */
  2577. DEBUG2(printk("scsi(%ld): Register FC-4 "
  2578. "Features failed.\n", vha->host_no));
  2579. }
  2580. if (qla2x00_rnn_id(vha)) {
  2581. /* EMPTY */
  2582. DEBUG2(printk("scsi(%ld): Register Node Name "
  2583. "failed.\n", vha->host_no));
  2584. } else if (qla2x00_rsnn_nn(vha)) {
  2585. /* EMPTY */
  2586. DEBUG2(printk("scsi(%ld): Register Symbolic "
  2587. "Node Name failed.\n", vha->host_no));
  2588. }
  2589. }
  2590. rval = qla2x00_find_all_fabric_devs(vha, &new_fcports);
  2591. if (rval != QLA_SUCCESS)
  2592. break;
  2593. /*
  2594. * Logout all previous fabric devices marked lost, except
  2595. * FCP2 devices.
  2596. */
  2597. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  2598. if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
  2599. break;
  2600. if ((fcport->flags & FCF_FABRIC_DEVICE) == 0)
  2601. continue;
  2602. if (atomic_read(&fcport->state) == FCS_DEVICE_LOST) {
  2603. qla2x00_mark_device_lost(vha, fcport,
  2604. ql2xplogiabsentdevice, 0);
  2605. if (fcport->loop_id != FC_NO_LOOP_ID &&
  2606. (fcport->flags & FCF_FCP2_DEVICE) == 0 &&
  2607. fcport->port_type != FCT_INITIATOR &&
  2608. fcport->port_type != FCT_BROADCAST) {
  2609. ha->isp_ops->fabric_logout(vha,
  2610. fcport->loop_id,
  2611. fcport->d_id.b.domain,
  2612. fcport->d_id.b.area,
  2613. fcport->d_id.b.al_pa);
  2614. fcport->loop_id = FC_NO_LOOP_ID;
  2615. }
  2616. }
  2617. }
  2618. /* Starting free loop ID. */
  2619. next_loopid = ha->min_external_loopid;
  2620. /*
  2621. * Scan through our port list and login entries that need to be
  2622. * logged in.
  2623. */
  2624. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  2625. if (atomic_read(&vha->loop_down_timer) ||
  2626. test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
  2627. break;
  2628. if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
  2629. (fcport->flags & FCF_LOGIN_NEEDED) == 0)
  2630. continue;
  2631. if (fcport->loop_id == FC_NO_LOOP_ID) {
  2632. fcport->loop_id = next_loopid;
  2633. rval = qla2x00_find_new_loop_id(
  2634. base_vha, fcport);
  2635. if (rval != QLA_SUCCESS) {
  2636. /* Ran out of IDs to use */
  2637. break;
  2638. }
  2639. }
  2640. /* Login and update database */
  2641. qla2x00_fabric_dev_login(vha, fcport, &next_loopid);
  2642. }
  2643. /* Exit if out of loop IDs. */
  2644. if (rval != QLA_SUCCESS) {
  2645. break;
  2646. }
  2647. /*
  2648. * Login and add the new devices to our port list.
  2649. */
  2650. list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
  2651. if (atomic_read(&vha->loop_down_timer) ||
  2652. test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
  2653. break;
  2654. /* Find a new loop ID to use. */
  2655. fcport->loop_id = next_loopid;
  2656. rval = qla2x00_find_new_loop_id(base_vha, fcport);
  2657. if (rval != QLA_SUCCESS) {
  2658. /* Ran out of IDs to use */
  2659. break;
  2660. }
  2661. /* Login and update database */
  2662. qla2x00_fabric_dev_login(vha, fcport, &next_loopid);
  2663. if (vha->vp_idx) {
  2664. fcport->vha = vha;
  2665. fcport->vp_idx = vha->vp_idx;
  2666. }
  2667. list_move_tail(&fcport->list, &vha->vp_fcports);
  2668. }
  2669. } while (0);
  2670. /* Free all new device structures not processed. */
  2671. list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
  2672. list_del(&fcport->list);
  2673. kfree(fcport);
  2674. }
  2675. if (rval) {
  2676. DEBUG2(printk("scsi(%ld): Configure fabric error exit: "
  2677. "rval=%d\n", vha->host_no, rval));
  2678. }
  2679. return (rval);
  2680. }
  2681. /*
  2682. * qla2x00_find_all_fabric_devs
  2683. *
  2684. * Input:
  2685. * ha = adapter block pointer.
  2686. * dev = database device entry pointer.
  2687. *
  2688. * Returns:
  2689. * 0 = success.
  2690. *
  2691. * Context:
  2692. * Kernel context.
  2693. */
  2694. static int
  2695. qla2x00_find_all_fabric_devs(scsi_qla_host_t *vha,
  2696. struct list_head *new_fcports)
  2697. {
  2698. int rval;
  2699. uint16_t loop_id;
  2700. fc_port_t *fcport, *new_fcport, *fcptemp;
  2701. int found;
  2702. sw_info_t *swl;
  2703. int swl_idx;
  2704. int first_dev, last_dev;
  2705. port_id_t wrap = {}, nxt_d_id;
  2706. struct qla_hw_data *ha = vha->hw;
  2707. struct scsi_qla_host *vp, *base_vha = pci_get_drvdata(ha->pdev);
  2708. struct scsi_qla_host *tvp;
  2709. rval = QLA_SUCCESS;
  2710. /* Try GID_PT to get device list, else GAN. */
  2711. swl = kcalloc(MAX_FIBRE_DEVICES, sizeof(sw_info_t), GFP_KERNEL);
  2712. if (!swl) {
  2713. /*EMPTY*/
  2714. DEBUG2(printk("scsi(%ld): GID_PT allocations failed, fallback "
  2715. "on GA_NXT\n", vha->host_no));
  2716. } else {
  2717. if (qla2x00_gid_pt(vha, swl) != QLA_SUCCESS) {
  2718. kfree(swl);
  2719. swl = NULL;
  2720. } else if (qla2x00_gpn_id(vha, swl) != QLA_SUCCESS) {
  2721. kfree(swl);
  2722. swl = NULL;
  2723. } else if (qla2x00_gnn_id(vha, swl) != QLA_SUCCESS) {
  2724. kfree(swl);
  2725. swl = NULL;
  2726. } else if (ql2xiidmaenable &&
  2727. qla2x00_gfpn_id(vha, swl) == QLA_SUCCESS) {
  2728. qla2x00_gpsc(vha, swl);
  2729. }
  2730. /* If other queries succeeded probe for FC-4 type */
  2731. if (swl)
  2732. qla2x00_gff_id(vha, swl);
  2733. }
  2734. swl_idx = 0;
  2735. /* Allocate temporary fcport for any new fcports discovered. */
  2736. new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
  2737. if (new_fcport == NULL) {
  2738. kfree(swl);
  2739. return (QLA_MEMORY_ALLOC_FAILED);
  2740. }
  2741. new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
  2742. /* Set start port ID scan at adapter ID. */
  2743. first_dev = 1;
  2744. last_dev = 0;
  2745. /* Starting free loop ID. */
  2746. loop_id = ha->min_external_loopid;
  2747. for (; loop_id <= ha->max_loop_id; loop_id++) {
  2748. if (qla2x00_is_reserved_id(vha, loop_id))
  2749. continue;
  2750. if (ha->current_topology == ISP_CFG_FL &&
  2751. (atomic_read(&vha->loop_down_timer) ||
  2752. LOOP_TRANSITION(vha))) {
  2753. atomic_set(&vha->loop_down_timer, 0);
  2754. set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
  2755. set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
  2756. break;
  2757. }
  2758. if (swl != NULL) {
  2759. if (last_dev) {
  2760. wrap.b24 = new_fcport->d_id.b24;
  2761. } else {
  2762. new_fcport->d_id.b24 = swl[swl_idx].d_id.b24;
  2763. memcpy(new_fcport->node_name,
  2764. swl[swl_idx].node_name, WWN_SIZE);
  2765. memcpy(new_fcport->port_name,
  2766. swl[swl_idx].port_name, WWN_SIZE);
  2767. memcpy(new_fcport->fabric_port_name,
  2768. swl[swl_idx].fabric_port_name, WWN_SIZE);
  2769. new_fcport->fp_speed = swl[swl_idx].fp_speed;
  2770. new_fcport->fc4_type = swl[swl_idx].fc4_type;
  2771. if (swl[swl_idx].d_id.b.rsvd_1 != 0) {
  2772. last_dev = 1;
  2773. }
  2774. swl_idx++;
  2775. }
  2776. } else {
  2777. /* Send GA_NXT to the switch */
  2778. rval = qla2x00_ga_nxt(vha, new_fcport);
  2779. if (rval != QLA_SUCCESS) {
  2780. qla_printk(KERN_WARNING, ha,
  2781. "SNS scan failed -- assuming zero-entry "
  2782. "result...\n");
  2783. list_for_each_entry_safe(fcport, fcptemp,
  2784. new_fcports, list) {
  2785. list_del(&fcport->list);
  2786. kfree(fcport);
  2787. }
  2788. rval = QLA_SUCCESS;
  2789. break;
  2790. }
  2791. }
  2792. /* If wrap on switch device list, exit. */
  2793. if (first_dev) {
  2794. wrap.b24 = new_fcport->d_id.b24;
  2795. first_dev = 0;
  2796. } else if (new_fcport->d_id.b24 == wrap.b24) {
  2797. DEBUG2(printk("scsi(%ld): device wrap (%02x%02x%02x)\n",
  2798. vha->host_no, new_fcport->d_id.b.domain,
  2799. new_fcport->d_id.b.area, new_fcport->d_id.b.al_pa));
  2800. break;
  2801. }
  2802. /* Bypass if same physical adapter. */
  2803. if (new_fcport->d_id.b24 == base_vha->d_id.b24)
  2804. continue;
  2805. /* Bypass virtual ports of the same host. */
  2806. found = 0;
  2807. if (ha->num_vhosts) {
  2808. unsigned long flags;
  2809. spin_lock_irqsave(&ha->vport_slock, flags);
  2810. list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
  2811. if (new_fcport->d_id.b24 == vp->d_id.b24) {
  2812. found = 1;
  2813. break;
  2814. }
  2815. }
  2816. spin_unlock_irqrestore(&ha->vport_slock, flags);
  2817. if (found)
  2818. continue;
  2819. }
  2820. /* Bypass if same domain and area of adapter. */
  2821. if (((new_fcport->d_id.b24 & 0xffff00) ==
  2822. (vha->d_id.b24 & 0xffff00)) && ha->current_topology ==
  2823. ISP_CFG_FL)
  2824. continue;
  2825. /* Bypass reserved domain fields. */
  2826. if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0)
  2827. continue;
  2828. /* Bypass ports whose FCP-4 type is not FCP_SCSI */
  2829. if (ql2xgffidenable &&
  2830. (new_fcport->fc4_type != FC4_TYPE_FCP_SCSI &&
  2831. new_fcport->fc4_type != FC4_TYPE_UNKNOWN))
  2832. continue;
  2833. /* Locate matching device in database. */
  2834. found = 0;
  2835. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  2836. if (memcmp(new_fcport->port_name, fcport->port_name,
  2837. WWN_SIZE))
  2838. continue;
  2839. found++;
  2840. /* Update port state. */
  2841. memcpy(fcport->fabric_port_name,
  2842. new_fcport->fabric_port_name, WWN_SIZE);
  2843. fcport->fp_speed = new_fcport->fp_speed;
  2844. /*
  2845. * If address the same and state FCS_ONLINE, nothing
  2846. * changed.
  2847. */
  2848. if (fcport->d_id.b24 == new_fcport->d_id.b24 &&
  2849. atomic_read(&fcport->state) == FCS_ONLINE) {
  2850. break;
  2851. }
  2852. /*
  2853. * If device was not a fabric device before.
  2854. */
  2855. if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) {
  2856. fcport->d_id.b24 = new_fcport->d_id.b24;
  2857. fcport->loop_id = FC_NO_LOOP_ID;
  2858. fcport->flags |= (FCF_FABRIC_DEVICE |
  2859. FCF_LOGIN_NEEDED);
  2860. break;
  2861. }
  2862. /*
  2863. * Port ID changed or device was marked to be updated;
  2864. * Log it out if still logged in and mark it for
  2865. * relogin later.
  2866. */
  2867. fcport->d_id.b24 = new_fcport->d_id.b24;
  2868. fcport->flags |= FCF_LOGIN_NEEDED;
  2869. if (fcport->loop_id != FC_NO_LOOP_ID &&
  2870. (fcport->flags & FCF_FCP2_DEVICE) == 0 &&
  2871. fcport->port_type != FCT_INITIATOR &&
  2872. fcport->port_type != FCT_BROADCAST) {
  2873. ha->isp_ops->fabric_logout(vha, fcport->loop_id,
  2874. fcport->d_id.b.domain, fcport->d_id.b.area,
  2875. fcport->d_id.b.al_pa);
  2876. fcport->loop_id = FC_NO_LOOP_ID;
  2877. }
  2878. break;
  2879. }
  2880. if (found)
  2881. continue;
  2882. /* If device was not in our fcports list, then add it. */
  2883. list_add_tail(&new_fcport->list, new_fcports);
  2884. /* Allocate a new replacement fcport. */
  2885. nxt_d_id.b24 = new_fcport->d_id.b24;
  2886. new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
  2887. if (new_fcport == NULL) {
  2888. kfree(swl);
  2889. return (QLA_MEMORY_ALLOC_FAILED);
  2890. }
  2891. new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
  2892. new_fcport->d_id.b24 = nxt_d_id.b24;
  2893. }
  2894. kfree(swl);
  2895. kfree(new_fcport);
  2896. return (rval);
  2897. }
  2898. /*
  2899. * qla2x00_find_new_loop_id
  2900. * Scan through our port list and find a new usable loop ID.
  2901. *
  2902. * Input:
  2903. * ha: adapter state pointer.
  2904. * dev: port structure pointer.
  2905. *
  2906. * Returns:
  2907. * qla2x00 local function return status code.
  2908. *
  2909. * Context:
  2910. * Kernel context.
  2911. */
  2912. static int
  2913. qla2x00_find_new_loop_id(scsi_qla_host_t *vha, fc_port_t *dev)
  2914. {
  2915. int rval;
  2916. int found;
  2917. fc_port_t *fcport;
  2918. uint16_t first_loop_id;
  2919. struct qla_hw_data *ha = vha->hw;
  2920. struct scsi_qla_host *vp;
  2921. struct scsi_qla_host *tvp;
  2922. unsigned long flags = 0;
  2923. rval = QLA_SUCCESS;
  2924. /* Save starting loop ID. */
  2925. first_loop_id = dev->loop_id;
  2926. for (;;) {
  2927. /* Skip loop ID if already used by adapter. */
  2928. if (dev->loop_id == vha->loop_id)
  2929. dev->loop_id++;
  2930. /* Skip reserved loop IDs. */
  2931. while (qla2x00_is_reserved_id(vha, dev->loop_id))
  2932. dev->loop_id++;
  2933. /* Reset loop ID if passed the end. */
  2934. if (dev->loop_id > ha->max_loop_id) {
  2935. /* first loop ID. */
  2936. dev->loop_id = ha->min_external_loopid;
  2937. }
  2938. /* Check for loop ID being already in use. */
  2939. found = 0;
  2940. fcport = NULL;
  2941. spin_lock_irqsave(&ha->vport_slock, flags);
  2942. list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
  2943. list_for_each_entry(fcport, &vp->vp_fcports, list) {
  2944. if (fcport->loop_id == dev->loop_id &&
  2945. fcport != dev) {
  2946. /* ID possibly in use */
  2947. found++;
  2948. break;
  2949. }
  2950. }
  2951. if (found)
  2952. break;
  2953. }
  2954. spin_unlock_irqrestore(&ha->vport_slock, flags);
  2955. /* If not in use then it is free to use. */
  2956. if (!found) {
  2957. break;
  2958. }
  2959. /* ID in use. Try next value. */
  2960. dev->loop_id++;
  2961. /* If wrap around. No free ID to use. */
  2962. if (dev->loop_id == first_loop_id) {
  2963. dev->loop_id = FC_NO_LOOP_ID;
  2964. rval = QLA_FUNCTION_FAILED;
  2965. break;
  2966. }
  2967. }
  2968. return (rval);
  2969. }
  2970. /*
  2971. * qla2x00_device_resync
  2972. * Marks devices in the database that needs resynchronization.
  2973. *
  2974. * Input:
  2975. * ha = adapter block pointer.
  2976. *
  2977. * Context:
  2978. * Kernel context.
  2979. */
  2980. static int
  2981. qla2x00_device_resync(scsi_qla_host_t *vha)
  2982. {
  2983. int rval;
  2984. uint32_t mask;
  2985. fc_port_t *fcport;
  2986. uint32_t rscn_entry;
  2987. uint8_t rscn_out_iter;
  2988. uint8_t format;
  2989. port_id_t d_id = {};
  2990. rval = QLA_RSCNS_HANDLED;
  2991. while (vha->rscn_out_ptr != vha->rscn_in_ptr ||
  2992. vha->flags.rscn_queue_overflow) {
  2993. rscn_entry = vha->rscn_queue[vha->rscn_out_ptr];
  2994. format = MSB(MSW(rscn_entry));
  2995. d_id.b.domain = LSB(MSW(rscn_entry));
  2996. d_id.b.area = MSB(LSW(rscn_entry));
  2997. d_id.b.al_pa = LSB(LSW(rscn_entry));
  2998. DEBUG(printk("scsi(%ld): RSCN queue entry[%d] = "
  2999. "[%02x/%02x%02x%02x].\n",
  3000. vha->host_no, vha->rscn_out_ptr, format, d_id.b.domain,
  3001. d_id.b.area, d_id.b.al_pa));
  3002. vha->rscn_out_ptr++;
  3003. if (vha->rscn_out_ptr == MAX_RSCN_COUNT)
  3004. vha->rscn_out_ptr = 0;
  3005. /* Skip duplicate entries. */
  3006. for (rscn_out_iter = vha->rscn_out_ptr;
  3007. !vha->flags.rscn_queue_overflow &&
  3008. rscn_out_iter != vha->rscn_in_ptr;
  3009. rscn_out_iter = (rscn_out_iter ==
  3010. (MAX_RSCN_COUNT - 1)) ? 0: rscn_out_iter + 1) {
  3011. if (rscn_entry != vha->rscn_queue[rscn_out_iter])
  3012. break;
  3013. DEBUG(printk("scsi(%ld): Skipping duplicate RSCN queue "
  3014. "entry found at [%d].\n", vha->host_no,
  3015. rscn_out_iter));
  3016. vha->rscn_out_ptr = rscn_out_iter;
  3017. }
  3018. /* Queue overflow, set switch default case. */
  3019. if (vha->flags.rscn_queue_overflow) {
  3020. DEBUG(printk("scsi(%ld): device_resync: rscn "
  3021. "overflow.\n", vha->host_no));
  3022. format = 3;
  3023. vha->flags.rscn_queue_overflow = 0;
  3024. }
  3025. switch (format) {
  3026. case 0:
  3027. mask = 0xffffff;
  3028. break;
  3029. case 1:
  3030. mask = 0xffff00;
  3031. break;
  3032. case 2:
  3033. mask = 0xff0000;
  3034. break;
  3035. default:
  3036. mask = 0x0;
  3037. d_id.b24 = 0;
  3038. vha->rscn_out_ptr = vha->rscn_in_ptr;
  3039. break;
  3040. }
  3041. rval = QLA_SUCCESS;
  3042. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  3043. if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
  3044. (fcport->d_id.b24 & mask) != d_id.b24 ||
  3045. fcport->port_type == FCT_BROADCAST)
  3046. continue;
  3047. if (atomic_read(&fcport->state) == FCS_ONLINE) {
  3048. if (format != 3 ||
  3049. fcport->port_type != FCT_INITIATOR) {
  3050. qla2x00_mark_device_lost(vha, fcport,
  3051. 0, 0);
  3052. }
  3053. }
  3054. }
  3055. }
  3056. return (rval);
  3057. }
  3058. /*
  3059. * qla2x00_fabric_dev_login
  3060. * Login fabric target device and update FC port database.
  3061. *
  3062. * Input:
  3063. * ha: adapter state pointer.
  3064. * fcport: port structure list pointer.
  3065. * next_loopid: contains value of a new loop ID that can be used
  3066. * by the next login attempt.
  3067. *
  3068. * Returns:
  3069. * qla2x00 local function return status code.
  3070. *
  3071. * Context:
  3072. * Kernel context.
  3073. */
  3074. static int
  3075. qla2x00_fabric_dev_login(scsi_qla_host_t *vha, fc_port_t *fcport,
  3076. uint16_t *next_loopid)
  3077. {
  3078. int rval;
  3079. int retry;
  3080. uint8_t opts;
  3081. struct qla_hw_data *ha = vha->hw;
  3082. rval = QLA_SUCCESS;
  3083. retry = 0;
  3084. if (IS_ALOGIO_CAPABLE(ha)) {
  3085. if (fcport->flags & FCF_ASYNC_SENT)
  3086. return rval;
  3087. fcport->flags |= FCF_ASYNC_SENT;
  3088. rval = qla2x00_post_async_login_work(vha, fcport, NULL);
  3089. if (!rval)
  3090. return rval;
  3091. }
  3092. fcport->flags &= ~FCF_ASYNC_SENT;
  3093. rval = qla2x00_fabric_login(vha, fcport, next_loopid);
  3094. if (rval == QLA_SUCCESS) {
  3095. /* Send an ADISC to FCP2 devices.*/
  3096. opts = 0;
  3097. if (fcport->flags & FCF_FCP2_DEVICE)
  3098. opts |= BIT_1;
  3099. rval = qla2x00_get_port_database(vha, fcport, opts);
  3100. if (rval != QLA_SUCCESS) {
  3101. ha->isp_ops->fabric_logout(vha, fcport->loop_id,
  3102. fcport->d_id.b.domain, fcport->d_id.b.area,
  3103. fcport->d_id.b.al_pa);
  3104. qla2x00_mark_device_lost(vha, fcport, 1, 0);
  3105. } else {
  3106. qla2x00_update_fcport(vha, fcport);
  3107. }
  3108. }
  3109. return (rval);
  3110. }
  3111. /*
  3112. * qla2x00_fabric_login
  3113. * Issue fabric login command.
  3114. *
  3115. * Input:
  3116. * ha = adapter block pointer.
  3117. * device = pointer to FC device type structure.
  3118. *
  3119. * Returns:
  3120. * 0 - Login successfully
  3121. * 1 - Login failed
  3122. * 2 - Initiator device
  3123. * 3 - Fatal error
  3124. */
  3125. int
  3126. qla2x00_fabric_login(scsi_qla_host_t *vha, fc_port_t *fcport,
  3127. uint16_t *next_loopid)
  3128. {
  3129. int rval;
  3130. int retry;
  3131. uint16_t tmp_loopid;
  3132. uint16_t mb[MAILBOX_REGISTER_COUNT];
  3133. struct qla_hw_data *ha = vha->hw;
  3134. retry = 0;
  3135. tmp_loopid = 0;
  3136. for (;;) {
  3137. DEBUG(printk("scsi(%ld): Trying Fabric Login w/loop id 0x%04x "
  3138. "for port %02x%02x%02x.\n",
  3139. vha->host_no, fcport->loop_id, fcport->d_id.b.domain,
  3140. fcport->d_id.b.area, fcport->d_id.b.al_pa));
  3141. /* Login fcport on switch. */
  3142. ha->isp_ops->fabric_login(vha, fcport->loop_id,
  3143. fcport->d_id.b.domain, fcport->d_id.b.area,
  3144. fcport->d_id.b.al_pa, mb, BIT_0);
  3145. if (mb[0] == MBS_PORT_ID_USED) {
  3146. /*
  3147. * Device has another loop ID. The firmware team
  3148. * recommends the driver perform an implicit login with
  3149. * the specified ID again. The ID we just used is save
  3150. * here so we return with an ID that can be tried by
  3151. * the next login.
  3152. */
  3153. retry++;
  3154. tmp_loopid = fcport->loop_id;
  3155. fcport->loop_id = mb[1];
  3156. DEBUG(printk("Fabric Login: port in use - next "
  3157. "loop id=0x%04x, port Id=%02x%02x%02x.\n",
  3158. fcport->loop_id, fcport->d_id.b.domain,
  3159. fcport->d_id.b.area, fcport->d_id.b.al_pa));
  3160. } else if (mb[0] == MBS_COMMAND_COMPLETE) {
  3161. /*
  3162. * Login succeeded.
  3163. */
  3164. if (retry) {
  3165. /* A retry occurred before. */
  3166. *next_loopid = tmp_loopid;
  3167. } else {
  3168. /*
  3169. * No retry occurred before. Just increment the
  3170. * ID value for next login.
  3171. */
  3172. *next_loopid = (fcport->loop_id + 1);
  3173. }
  3174. if (mb[1] & BIT_0) {
  3175. fcport->port_type = FCT_INITIATOR;
  3176. } else {
  3177. fcport->port_type = FCT_TARGET;
  3178. if (mb[1] & BIT_1) {
  3179. fcport->flags |= FCF_FCP2_DEVICE;
  3180. }
  3181. }
  3182. if (mb[10] & BIT_0)
  3183. fcport->supported_classes |= FC_COS_CLASS2;
  3184. if (mb[10] & BIT_1)
  3185. fcport->supported_classes |= FC_COS_CLASS3;
  3186. rval = QLA_SUCCESS;
  3187. break;
  3188. } else if (mb[0] == MBS_LOOP_ID_USED) {
  3189. /*
  3190. * Loop ID already used, try next loop ID.
  3191. */
  3192. fcport->loop_id++;
  3193. rval = qla2x00_find_new_loop_id(vha, fcport);
  3194. if (rval != QLA_SUCCESS) {
  3195. /* Ran out of loop IDs to use */
  3196. break;
  3197. }
  3198. } else if (mb[0] == MBS_COMMAND_ERROR) {
  3199. /*
  3200. * Firmware possibly timed out during login. If NO
  3201. * retries are left to do then the device is declared
  3202. * dead.
  3203. */
  3204. *next_loopid = fcport->loop_id;
  3205. ha->isp_ops->fabric_logout(vha, fcport->loop_id,
  3206. fcport->d_id.b.domain, fcport->d_id.b.area,
  3207. fcport->d_id.b.al_pa);
  3208. qla2x00_mark_device_lost(vha, fcport, 1, 0);
  3209. rval = 1;
  3210. break;
  3211. } else {
  3212. /*
  3213. * unrecoverable / not handled error
  3214. */
  3215. DEBUG2(printk("%s(%ld): failed=%x port_id=%02x%02x%02x "
  3216. "loop_id=%x jiffies=%lx.\n",
  3217. __func__, vha->host_no, mb[0],
  3218. fcport->d_id.b.domain, fcport->d_id.b.area,
  3219. fcport->d_id.b.al_pa, fcport->loop_id, jiffies));
  3220. *next_loopid = fcport->loop_id;
  3221. ha->isp_ops->fabric_logout(vha, fcport->loop_id,
  3222. fcport->d_id.b.domain, fcport->d_id.b.area,
  3223. fcport->d_id.b.al_pa);
  3224. fcport->loop_id = FC_NO_LOOP_ID;
  3225. fcport->login_retry = 0;
  3226. rval = 3;
  3227. break;
  3228. }
  3229. }
  3230. return (rval);
  3231. }
  3232. /*
  3233. * qla2x00_local_device_login
  3234. * Issue local device login command.
  3235. *
  3236. * Input:
  3237. * ha = adapter block pointer.
  3238. * loop_id = loop id of device to login to.
  3239. *
  3240. * Returns (Where's the #define!!!!):
  3241. * 0 - Login successfully
  3242. * 1 - Login failed
  3243. * 3 - Fatal error
  3244. */
  3245. int
  3246. qla2x00_local_device_login(scsi_qla_host_t *vha, fc_port_t *fcport)
  3247. {
  3248. int rval;
  3249. uint16_t mb[MAILBOX_REGISTER_COUNT];
  3250. memset(mb, 0, sizeof(mb));
  3251. rval = qla2x00_login_local_device(vha, fcport, mb, BIT_0);
  3252. if (rval == QLA_SUCCESS) {
  3253. /* Interrogate mailbox registers for any errors */
  3254. if (mb[0] == MBS_COMMAND_ERROR)
  3255. rval = 1;
  3256. else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR)
  3257. /* device not in PCB table */
  3258. rval = 3;
  3259. }
  3260. return (rval);
  3261. }
  3262. /*
  3263. * qla2x00_loop_resync
  3264. * Resync with fibre channel devices.
  3265. *
  3266. * Input:
  3267. * ha = adapter block pointer.
  3268. *
  3269. * Returns:
  3270. * 0 = success
  3271. */
  3272. int
  3273. qla2x00_loop_resync(scsi_qla_host_t *vha)
  3274. {
  3275. int rval = QLA_SUCCESS;
  3276. uint32_t wait_time;
  3277. struct req_que *req;
  3278. struct rsp_que *rsp;
  3279. if (vha->hw->flags.cpu_affinity_enabled)
  3280. req = vha->hw->req_q_map[0];
  3281. else
  3282. req = vha->req;
  3283. rsp = req->rsp;
  3284. atomic_set(&vha->loop_state, LOOP_UPDATE);
  3285. clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
  3286. if (vha->flags.online) {
  3287. if (!(rval = qla2x00_fw_ready(vha))) {
  3288. /* Wait at most MAX_TARGET RSCNs for a stable link. */
  3289. wait_time = 256;
  3290. do {
  3291. atomic_set(&vha->loop_state, LOOP_UPDATE);
  3292. /* Issue a marker after FW becomes ready. */
  3293. qla2x00_marker(vha, req, rsp, 0, 0,
  3294. MK_SYNC_ALL);
  3295. vha->marker_needed = 0;
  3296. /* Remap devices on Loop. */
  3297. clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
  3298. qla2x00_configure_loop(vha);
  3299. wait_time--;
  3300. } while (!atomic_read(&vha->loop_down_timer) &&
  3301. !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
  3302. && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
  3303. &vha->dpc_flags)));
  3304. }
  3305. }
  3306. if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
  3307. return (QLA_FUNCTION_FAILED);
  3308. if (rval)
  3309. DEBUG2_3(printk("%s(): **** FAILED ****\n", __func__));
  3310. return (rval);
  3311. }
  3312. /*
  3313. * qla2x00_perform_loop_resync
  3314. * Description: This function will set the appropriate flags and call
  3315. * qla2x00_loop_resync. If successful loop will be resynced
  3316. * Arguments : scsi_qla_host_t pointer
  3317. * returm : Success or Failure
  3318. */
  3319. int qla2x00_perform_loop_resync(scsi_qla_host_t *ha)
  3320. {
  3321. int32_t rval = 0;
  3322. if (!test_and_set_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags)) {
  3323. /*Configure the flags so that resync happens properly*/
  3324. atomic_set(&ha->loop_down_timer, 0);
  3325. if (!(ha->device_flags & DFLG_NO_CABLE)) {
  3326. atomic_set(&ha->loop_state, LOOP_UP);
  3327. set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
  3328. set_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags);
  3329. set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
  3330. rval = qla2x00_loop_resync(ha);
  3331. } else
  3332. atomic_set(&ha->loop_state, LOOP_DEAD);
  3333. clear_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags);
  3334. }
  3335. return rval;
  3336. }
  3337. void
  3338. qla2x00_update_fcports(scsi_qla_host_t *base_vha)
  3339. {
  3340. fc_port_t *fcport;
  3341. struct scsi_qla_host *vha;
  3342. struct qla_hw_data *ha = base_vha->hw;
  3343. unsigned long flags;
  3344. spin_lock_irqsave(&ha->vport_slock, flags);
  3345. /* Go with deferred removal of rport references. */
  3346. list_for_each_entry(vha, &base_vha->hw->vp_list, list) {
  3347. atomic_inc(&vha->vref_count);
  3348. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  3349. if (fcport->drport &&
  3350. atomic_read(&fcport->state) != FCS_UNCONFIGURED) {
  3351. spin_unlock_irqrestore(&ha->vport_slock, flags);
  3352. qla2x00_rport_del(fcport);
  3353. spin_lock_irqsave(&ha->vport_slock, flags);
  3354. }
  3355. }
  3356. atomic_dec(&vha->vref_count);
  3357. }
  3358. spin_unlock_irqrestore(&ha->vport_slock, flags);
  3359. }
  3360. /*
  3361. * qla82xx_quiescent_state_cleanup
  3362. * Description: This function will block the new I/Os
  3363. * Its not aborting any I/Os as context
  3364. * is not destroyed during quiescence
  3365. * Arguments: scsi_qla_host_t
  3366. * return : void
  3367. */
  3368. void
  3369. qla82xx_quiescent_state_cleanup(scsi_qla_host_t *vha)
  3370. {
  3371. struct qla_hw_data *ha = vha->hw;
  3372. struct scsi_qla_host *vp;
  3373. qla_printk(KERN_INFO, ha,
  3374. "Performing ISP error recovery - ha= %p.\n", ha);
  3375. atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
  3376. if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
  3377. atomic_set(&vha->loop_state, LOOP_DOWN);
  3378. qla2x00_mark_all_devices_lost(vha, 0);
  3379. list_for_each_entry(vp, &ha->vp_list, list)
  3380. qla2x00_mark_all_devices_lost(vha, 0);
  3381. } else {
  3382. if (!atomic_read(&vha->loop_down_timer))
  3383. atomic_set(&vha->loop_down_timer,
  3384. LOOP_DOWN_TIME);
  3385. }
  3386. /* Wait for pending cmds to complete */
  3387. qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST);
  3388. }
  3389. void
  3390. qla2x00_abort_isp_cleanup(scsi_qla_host_t *vha)
  3391. {
  3392. struct qla_hw_data *ha = vha->hw;
  3393. struct scsi_qla_host *vp;
  3394. unsigned long flags;
  3395. fc_port_t *fcport;
  3396. /* For ISP82XX, driver waits for completion of the commands.
  3397. * online flag should be set.
  3398. */
  3399. if (!IS_QLA82XX(ha))
  3400. vha->flags.online = 0;
  3401. ha->flags.chip_reset_done = 0;
  3402. clear_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
  3403. ha->qla_stats.total_isp_aborts++;
  3404. qla_printk(KERN_INFO, ha,
  3405. "Performing ISP error recovery - ha= %p.\n", ha);
  3406. /* For ISP82XX, reset_chip is just disabling interrupts.
  3407. * Driver waits for the completion of the commands.
  3408. * the interrupts need to be enabled.
  3409. */
  3410. if (!IS_QLA82XX(ha))
  3411. ha->isp_ops->reset_chip(vha);
  3412. atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
  3413. if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
  3414. atomic_set(&vha->loop_state, LOOP_DOWN);
  3415. qla2x00_mark_all_devices_lost(vha, 0);
  3416. spin_lock_irqsave(&ha->vport_slock, flags);
  3417. list_for_each_entry(vp, &ha->vp_list, list) {
  3418. atomic_inc(&vp->vref_count);
  3419. spin_unlock_irqrestore(&ha->vport_slock, flags);
  3420. qla2x00_mark_all_devices_lost(vp, 0);
  3421. spin_lock_irqsave(&ha->vport_slock, flags);
  3422. atomic_dec(&vp->vref_count);
  3423. }
  3424. spin_unlock_irqrestore(&ha->vport_slock, flags);
  3425. } else {
  3426. if (!atomic_read(&vha->loop_down_timer))
  3427. atomic_set(&vha->loop_down_timer,
  3428. LOOP_DOWN_TIME);
  3429. }
  3430. /* Clear all async request states across all VPs. */
  3431. list_for_each_entry(fcport, &vha->vp_fcports, list)
  3432. fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
  3433. spin_lock_irqsave(&ha->vport_slock, flags);
  3434. list_for_each_entry(vp, &ha->vp_list, list) {
  3435. atomic_inc(&vp->vref_count);
  3436. spin_unlock_irqrestore(&ha->vport_slock, flags);
  3437. list_for_each_entry(fcport, &vp->vp_fcports, list)
  3438. fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
  3439. spin_lock_irqsave(&ha->vport_slock, flags);
  3440. atomic_dec(&vp->vref_count);
  3441. }
  3442. spin_unlock_irqrestore(&ha->vport_slock, flags);
  3443. if (!ha->flags.eeh_busy) {
  3444. /* Make sure for ISP 82XX IO DMA is complete */
  3445. if (IS_QLA82XX(ha)) {
  3446. qla82xx_chip_reset_cleanup(vha);
  3447. /* Done waiting for pending commands.
  3448. * Reset the online flag.
  3449. */
  3450. vha->flags.online = 0;
  3451. }
  3452. /* Requeue all commands in outstanding command list. */
  3453. qla2x00_abort_all_cmds(vha, DID_RESET << 16);
  3454. }
  3455. }
  3456. /*
  3457. * qla2x00_abort_isp
  3458. * Resets ISP and aborts all outstanding commands.
  3459. *
  3460. * Input:
  3461. * ha = adapter block pointer.
  3462. *
  3463. * Returns:
  3464. * 0 = success
  3465. */
  3466. int
  3467. qla2x00_abort_isp(scsi_qla_host_t *vha)
  3468. {
  3469. int rval;
  3470. uint8_t status = 0;
  3471. struct qla_hw_data *ha = vha->hw;
  3472. struct scsi_qla_host *vp;
  3473. struct req_que *req = ha->req_q_map[0];
  3474. unsigned long flags;
  3475. if (vha->flags.online) {
  3476. qla2x00_abort_isp_cleanup(vha);
  3477. if (unlikely(pci_channel_offline(ha->pdev) &&
  3478. ha->flags.pci_channel_io_perm_failure)) {
  3479. clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
  3480. status = 0;
  3481. return status;
  3482. }
  3483. ha->isp_ops->get_flash_version(vha, req->ring);
  3484. ha->isp_ops->nvram_config(vha);
  3485. if (!qla2x00_restart_isp(vha)) {
  3486. clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
  3487. if (!atomic_read(&vha->loop_down_timer)) {
  3488. /*
  3489. * Issue marker command only when we are going
  3490. * to start the I/O .
  3491. */
  3492. vha->marker_needed = 1;
  3493. }
  3494. vha->flags.online = 1;
  3495. ha->isp_ops->enable_intrs(ha);
  3496. ha->isp_abort_cnt = 0;
  3497. clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
  3498. if (IS_QLA81XX(ha))
  3499. qla2x00_get_fw_version(vha,
  3500. &ha->fw_major_version,
  3501. &ha->fw_minor_version,
  3502. &ha->fw_subminor_version,
  3503. &ha->fw_attributes, &ha->fw_memory_size,
  3504. ha->mpi_version, &ha->mpi_capabilities,
  3505. ha->phy_version);
  3506. if (ha->fce) {
  3507. ha->flags.fce_enabled = 1;
  3508. memset(ha->fce, 0,
  3509. fce_calc_size(ha->fce_bufs));
  3510. rval = qla2x00_enable_fce_trace(vha,
  3511. ha->fce_dma, ha->fce_bufs, ha->fce_mb,
  3512. &ha->fce_bufs);
  3513. if (rval) {
  3514. qla_printk(KERN_WARNING, ha,
  3515. "Unable to reinitialize FCE "
  3516. "(%d).\n", rval);
  3517. ha->flags.fce_enabled = 0;
  3518. }
  3519. }
  3520. if (ha->eft) {
  3521. memset(ha->eft, 0, EFT_SIZE);
  3522. rval = qla2x00_enable_eft_trace(vha,
  3523. ha->eft_dma, EFT_NUM_BUFFERS);
  3524. if (rval) {
  3525. qla_printk(KERN_WARNING, ha,
  3526. "Unable to reinitialize EFT "
  3527. "(%d).\n", rval);
  3528. }
  3529. }
  3530. } else { /* failed the ISP abort */
  3531. vha->flags.online = 1;
  3532. if (test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
  3533. if (ha->isp_abort_cnt == 0) {
  3534. qla_printk(KERN_WARNING, ha,
  3535. "ISP error recovery failed - "
  3536. "board disabled\n");
  3537. /*
  3538. * The next call disables the board
  3539. * completely.
  3540. */
  3541. ha->isp_ops->reset_adapter(vha);
  3542. vha->flags.online = 0;
  3543. clear_bit(ISP_ABORT_RETRY,
  3544. &vha->dpc_flags);
  3545. status = 0;
  3546. } else { /* schedule another ISP abort */
  3547. ha->isp_abort_cnt--;
  3548. DEBUG(printk("qla%ld: ISP abort - "
  3549. "retry remaining %d\n",
  3550. vha->host_no, ha->isp_abort_cnt));
  3551. status = 1;
  3552. }
  3553. } else {
  3554. ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT;
  3555. DEBUG(printk("qla2x00(%ld): ISP error recovery "
  3556. "- retrying (%d) more times\n",
  3557. vha->host_no, ha->isp_abort_cnt));
  3558. set_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
  3559. status = 1;
  3560. }
  3561. }
  3562. }
  3563. if (!status) {
  3564. DEBUG(printk(KERN_INFO
  3565. "qla2x00_abort_isp(%ld): succeeded.\n",
  3566. vha->host_no));
  3567. spin_lock_irqsave(&ha->vport_slock, flags);
  3568. list_for_each_entry(vp, &ha->vp_list, list) {
  3569. if (vp->vp_idx) {
  3570. atomic_inc(&vp->vref_count);
  3571. spin_unlock_irqrestore(&ha->vport_slock, flags);
  3572. qla2x00_vp_abort_isp(vp);
  3573. spin_lock_irqsave(&ha->vport_slock, flags);
  3574. atomic_dec(&vp->vref_count);
  3575. }
  3576. }
  3577. spin_unlock_irqrestore(&ha->vport_slock, flags);
  3578. } else {
  3579. qla_printk(KERN_INFO, ha,
  3580. "qla2x00_abort_isp: **** FAILED ****\n");
  3581. }
  3582. return(status);
  3583. }
  3584. /*
  3585. * qla2x00_restart_isp
  3586. * restarts the ISP after a reset
  3587. *
  3588. * Input:
  3589. * ha = adapter block pointer.
  3590. *
  3591. * Returns:
  3592. * 0 = success
  3593. */
  3594. static int
  3595. qla2x00_restart_isp(scsi_qla_host_t *vha)
  3596. {
  3597. int status = 0;
  3598. uint32_t wait_time;
  3599. struct qla_hw_data *ha = vha->hw;
  3600. struct req_que *req = ha->req_q_map[0];
  3601. struct rsp_que *rsp = ha->rsp_q_map[0];
  3602. /* If firmware needs to be loaded */
  3603. if (qla2x00_isp_firmware(vha)) {
  3604. vha->flags.online = 0;
  3605. status = ha->isp_ops->chip_diag(vha);
  3606. if (!status)
  3607. status = qla2x00_setup_chip(vha);
  3608. }
  3609. if (!status && !(status = qla2x00_init_rings(vha))) {
  3610. clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
  3611. ha->flags.chip_reset_done = 1;
  3612. /* Initialize the queues in use */
  3613. qla25xx_init_queues(ha);
  3614. status = qla2x00_fw_ready(vha);
  3615. if (!status) {
  3616. DEBUG(printk("%s(): Start configure loop, "
  3617. "status = %d\n", __func__, status));
  3618. /* Issue a marker after FW becomes ready. */
  3619. qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
  3620. vha->flags.online = 1;
  3621. /* Wait at most MAX_TARGET RSCNs for a stable link. */
  3622. wait_time = 256;
  3623. do {
  3624. clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
  3625. qla2x00_configure_loop(vha);
  3626. wait_time--;
  3627. } while (!atomic_read(&vha->loop_down_timer) &&
  3628. !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
  3629. && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
  3630. &vha->dpc_flags)));
  3631. }
  3632. /* if no cable then assume it's good */
  3633. if ((vha->device_flags & DFLG_NO_CABLE))
  3634. status = 0;
  3635. DEBUG(printk("%s(): Configure loop done, status = 0x%x\n",
  3636. __func__,
  3637. status));
  3638. }
  3639. return (status);
  3640. }
  3641. static int
  3642. qla25xx_init_queues(struct qla_hw_data *ha)
  3643. {
  3644. struct rsp_que *rsp = NULL;
  3645. struct req_que *req = NULL;
  3646. struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
  3647. int ret = -1;
  3648. int i;
  3649. for (i = 1; i < ha->max_rsp_queues; i++) {
  3650. rsp = ha->rsp_q_map[i];
  3651. if (rsp) {
  3652. rsp->options &= ~BIT_0;
  3653. ret = qla25xx_init_rsp_que(base_vha, rsp);
  3654. if (ret != QLA_SUCCESS)
  3655. DEBUG2_17(printk(KERN_WARNING
  3656. "%s Rsp que:%d init failed\n", __func__,
  3657. rsp->id));
  3658. else
  3659. DEBUG2_17(printk(KERN_INFO
  3660. "%s Rsp que:%d inited\n", __func__,
  3661. rsp->id));
  3662. }
  3663. }
  3664. for (i = 1; i < ha->max_req_queues; i++) {
  3665. req = ha->req_q_map[i];
  3666. if (req) {
  3667. /* Clear outstanding commands array. */
  3668. req->options &= ~BIT_0;
  3669. ret = qla25xx_init_req_que(base_vha, req);
  3670. if (ret != QLA_SUCCESS)
  3671. DEBUG2_17(printk(KERN_WARNING
  3672. "%s Req que:%d init failed\n", __func__,
  3673. req->id));
  3674. else
  3675. DEBUG2_17(printk(KERN_WARNING
  3676. "%s Req que:%d inited\n", __func__,
  3677. req->id));
  3678. }
  3679. }
  3680. return ret;
  3681. }
  3682. /*
  3683. * qla2x00_reset_adapter
  3684. * Reset adapter.
  3685. *
  3686. * Input:
  3687. * ha = adapter block pointer.
  3688. */
  3689. void
  3690. qla2x00_reset_adapter(scsi_qla_host_t *vha)
  3691. {
  3692. unsigned long flags = 0;
  3693. struct qla_hw_data *ha = vha->hw;
  3694. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  3695. vha->flags.online = 0;
  3696. ha->isp_ops->disable_intrs(ha);
  3697. spin_lock_irqsave(&ha->hardware_lock, flags);
  3698. WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
  3699. RD_REG_WORD(&reg->hccr); /* PCI Posting. */
  3700. WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
  3701. RD_REG_WORD(&reg->hccr); /* PCI Posting. */
  3702. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  3703. }
  3704. void
  3705. qla24xx_reset_adapter(scsi_qla_host_t *vha)
  3706. {
  3707. unsigned long flags = 0;
  3708. struct qla_hw_data *ha = vha->hw;
  3709. struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
  3710. if (IS_QLA82XX(ha))
  3711. return;
  3712. vha->flags.online = 0;
  3713. ha->isp_ops->disable_intrs(ha);
  3714. spin_lock_irqsave(&ha->hardware_lock, flags);
  3715. WRT_REG_DWORD(&reg->hccr, HCCRX_SET_RISC_RESET);
  3716. RD_REG_DWORD(&reg->hccr);
  3717. WRT_REG_DWORD(&reg->hccr, HCCRX_REL_RISC_PAUSE);
  3718. RD_REG_DWORD(&reg->hccr);
  3719. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  3720. if (IS_NOPOLLING_TYPE(ha))
  3721. ha->isp_ops->enable_intrs(ha);
  3722. }
  3723. /* On sparc systems, obtain port and node WWN from firmware
  3724. * properties.
  3725. */
  3726. static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t *vha,
  3727. struct nvram_24xx *nv)
  3728. {
  3729. #ifdef CONFIG_SPARC
  3730. struct qla_hw_data *ha = vha->hw;
  3731. struct pci_dev *pdev = ha->pdev;
  3732. struct device_node *dp = pci_device_to_OF_node(pdev);
  3733. const u8 *val;
  3734. int len;
  3735. val = of_get_property(dp, "port-wwn", &len);
  3736. if (val && len >= WWN_SIZE)
  3737. memcpy(nv->port_name, val, WWN_SIZE);
  3738. val = of_get_property(dp, "node-wwn", &len);
  3739. if (val && len >= WWN_SIZE)
  3740. memcpy(nv->node_name, val, WWN_SIZE);
  3741. #endif
  3742. }
  3743. int
  3744. qla24xx_nvram_config(scsi_qla_host_t *vha)
  3745. {
  3746. int rval;
  3747. struct init_cb_24xx *icb;
  3748. struct nvram_24xx *nv;
  3749. uint32_t *dptr;
  3750. uint8_t *dptr1, *dptr2;
  3751. uint32_t chksum;
  3752. uint16_t cnt;
  3753. struct qla_hw_data *ha = vha->hw;
  3754. rval = QLA_SUCCESS;
  3755. icb = (struct init_cb_24xx *)ha->init_cb;
  3756. nv = ha->nvram;
  3757. /* Determine NVRAM starting address. */
  3758. if (ha->flags.port0) {
  3759. ha->nvram_base = FA_NVRAM_FUNC0_ADDR;
  3760. ha->vpd_base = FA_NVRAM_VPD0_ADDR;
  3761. } else {
  3762. ha->nvram_base = FA_NVRAM_FUNC1_ADDR;
  3763. ha->vpd_base = FA_NVRAM_VPD1_ADDR;
  3764. }
  3765. ha->nvram_size = sizeof(struct nvram_24xx);
  3766. ha->vpd_size = FA_NVRAM_VPD_SIZE;
  3767. if (IS_QLA82XX(ha))
  3768. ha->vpd_size = FA_VPD_SIZE_82XX;
  3769. /* Get VPD data into cache */
  3770. ha->vpd = ha->nvram + VPD_OFFSET;
  3771. ha->isp_ops->read_nvram(vha, (uint8_t *)ha->vpd,
  3772. ha->nvram_base - FA_NVRAM_FUNC0_ADDR, FA_NVRAM_VPD_SIZE * 4);
  3773. /* Get NVRAM data into cache and calculate checksum. */
  3774. dptr = (uint32_t *)nv;
  3775. ha->isp_ops->read_nvram(vha, (uint8_t *)dptr, ha->nvram_base,
  3776. ha->nvram_size);
  3777. for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++)
  3778. chksum += le32_to_cpu(*dptr++);
  3779. DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", vha->host_no));
  3780. DEBUG5(qla2x00_dump_buffer((uint8_t *)nv, ha->nvram_size));
  3781. /* Bad NVRAM data, set defaults parameters. */
  3782. if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
  3783. || nv->id[3] != ' ' ||
  3784. nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) {
  3785. /* Reset NVRAM data. */
  3786. qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
  3787. "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
  3788. le16_to_cpu(nv->nvram_version));
  3789. qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
  3790. "invalid -- WWPN) defaults.\n");
  3791. /*
  3792. * Set default initialization control block.
  3793. */
  3794. memset(nv, 0, ha->nvram_size);
  3795. nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION);
  3796. nv->version = __constant_cpu_to_le16(ICB_VERSION);
  3797. nv->frame_payload_size = __constant_cpu_to_le16(2048);
  3798. nv->execution_throttle = __constant_cpu_to_le16(0xFFFF);
  3799. nv->exchange_count = __constant_cpu_to_le16(0);
  3800. nv->hard_address = __constant_cpu_to_le16(124);
  3801. nv->port_name[0] = 0x21;
  3802. nv->port_name[1] = 0x00 + ha->port_no;
  3803. nv->port_name[2] = 0x00;
  3804. nv->port_name[3] = 0xe0;
  3805. nv->port_name[4] = 0x8b;
  3806. nv->port_name[5] = 0x1c;
  3807. nv->port_name[6] = 0x55;
  3808. nv->port_name[7] = 0x86;
  3809. nv->node_name[0] = 0x20;
  3810. nv->node_name[1] = 0x00;
  3811. nv->node_name[2] = 0x00;
  3812. nv->node_name[3] = 0xe0;
  3813. nv->node_name[4] = 0x8b;
  3814. nv->node_name[5] = 0x1c;
  3815. nv->node_name[6] = 0x55;
  3816. nv->node_name[7] = 0x86;
  3817. qla24xx_nvram_wwn_from_ofw(vha, nv);
  3818. nv->login_retry_count = __constant_cpu_to_le16(8);
  3819. nv->interrupt_delay_timer = __constant_cpu_to_le16(0);
  3820. nv->login_timeout = __constant_cpu_to_le16(0);
  3821. nv->firmware_options_1 =
  3822. __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
  3823. nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4);
  3824. nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12);
  3825. nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13);
  3826. nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10);
  3827. nv->efi_parameters = __constant_cpu_to_le32(0);
  3828. nv->reset_delay = 5;
  3829. nv->max_luns_per_target = __constant_cpu_to_le16(128);
  3830. nv->port_down_retry_count = __constant_cpu_to_le16(30);
  3831. nv->link_down_timeout = __constant_cpu_to_le16(30);
  3832. rval = 1;
  3833. }
  3834. /* Reset Initialization control block */
  3835. memset(icb, 0, ha->init_cb_size);
  3836. /* Copy 1st segment. */
  3837. dptr1 = (uint8_t *)icb;
  3838. dptr2 = (uint8_t *)&nv->version;
  3839. cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
  3840. while (cnt--)
  3841. *dptr1++ = *dptr2++;
  3842. icb->login_retry_count = nv->login_retry_count;
  3843. icb->link_down_on_nos = nv->link_down_on_nos;
  3844. /* Copy 2nd segment. */
  3845. dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
  3846. dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
  3847. cnt = (uint8_t *)&icb->reserved_3 -
  3848. (uint8_t *)&icb->interrupt_delay_timer;
  3849. while (cnt--)
  3850. *dptr1++ = *dptr2++;
  3851. /*
  3852. * Setup driver NVRAM options.
  3853. */
  3854. qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
  3855. "QLA2462");
  3856. /* Use alternate WWN? */
  3857. if (nv->host_p & __constant_cpu_to_le32(BIT_15)) {
  3858. memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
  3859. memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
  3860. }
  3861. /* Prepare nodename */
  3862. if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) {
  3863. /*
  3864. * Firmware will apply the following mask if the nodename was
  3865. * not provided.
  3866. */
  3867. memcpy(icb->node_name, icb->port_name, WWN_SIZE);
  3868. icb->node_name[0] &= 0xF0;
  3869. }
  3870. /* Set host adapter parameters. */
  3871. ha->flags.disable_risc_code_load = 0;
  3872. ha->flags.enable_lip_reset = 0;
  3873. ha->flags.enable_lip_full_login =
  3874. le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
  3875. ha->flags.enable_target_reset =
  3876. le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
  3877. ha->flags.enable_led_scheme = 0;
  3878. ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
  3879. ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
  3880. (BIT_6 | BIT_5 | BIT_4)) >> 4;
  3881. memcpy(ha->fw_seriallink_options24, nv->seriallink_options,
  3882. sizeof(ha->fw_seriallink_options24));
  3883. /* save HBA serial number */
  3884. ha->serial0 = icb->port_name[5];
  3885. ha->serial1 = icb->port_name[6];
  3886. ha->serial2 = icb->port_name[7];
  3887. memcpy(vha->node_name, icb->node_name, WWN_SIZE);
  3888. memcpy(vha->port_name, icb->port_name, WWN_SIZE);
  3889. icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
  3890. ha->retry_count = le16_to_cpu(nv->login_retry_count);
  3891. /* Set minimum login_timeout to 4 seconds. */
  3892. if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
  3893. nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
  3894. if (le16_to_cpu(nv->login_timeout) < 4)
  3895. nv->login_timeout = __constant_cpu_to_le16(4);
  3896. ha->login_timeout = le16_to_cpu(nv->login_timeout);
  3897. icb->login_timeout = nv->login_timeout;
  3898. /* Set minimum RATOV to 100 tenths of a second. */
  3899. ha->r_a_tov = 100;
  3900. ha->loop_reset_delay = nv->reset_delay;
  3901. /* Link Down Timeout = 0:
  3902. *
  3903. * When Port Down timer expires we will start returning
  3904. * I/O's to OS with "DID_NO_CONNECT".
  3905. *
  3906. * Link Down Timeout != 0:
  3907. *
  3908. * The driver waits for the link to come up after link down
  3909. * before returning I/Os to OS with "DID_NO_CONNECT".
  3910. */
  3911. if (le16_to_cpu(nv->link_down_timeout) == 0) {
  3912. ha->loop_down_abort_time =
  3913. (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
  3914. } else {
  3915. ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
  3916. ha->loop_down_abort_time =
  3917. (LOOP_DOWN_TIME - ha->link_down_timeout);
  3918. }
  3919. /* Need enough time to try and get the port back. */
  3920. ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
  3921. if (qlport_down_retry)
  3922. ha->port_down_retry_count = qlport_down_retry;
  3923. /* Set login_retry_count */
  3924. ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
  3925. if (ha->port_down_retry_count ==
  3926. le16_to_cpu(nv->port_down_retry_count) &&
  3927. ha->port_down_retry_count > 3)
  3928. ha->login_retry_count = ha->port_down_retry_count;
  3929. else if (ha->port_down_retry_count > (int)ha->login_retry_count)
  3930. ha->login_retry_count = ha->port_down_retry_count;
  3931. if (ql2xloginretrycount)
  3932. ha->login_retry_count = ql2xloginretrycount;
  3933. /* Enable ZIO. */
  3934. if (!vha->flags.init_done) {
  3935. ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
  3936. (BIT_3 | BIT_2 | BIT_1 | BIT_0);
  3937. ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
  3938. le16_to_cpu(icb->interrupt_delay_timer): 2;
  3939. }
  3940. icb->firmware_options_2 &= __constant_cpu_to_le32(
  3941. ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
  3942. vha->flags.process_response_queue = 0;
  3943. if (ha->zio_mode != QLA_ZIO_DISABLED) {
  3944. ha->zio_mode = QLA_ZIO_MODE_6;
  3945. DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer delay "
  3946. "(%d us).\n", vha->host_no, ha->zio_mode,
  3947. ha->zio_timer * 100));
  3948. qla_printk(KERN_INFO, ha,
  3949. "ZIO mode %d enabled; timer delay (%d us).\n",
  3950. ha->zio_mode, ha->zio_timer * 100);
  3951. icb->firmware_options_2 |= cpu_to_le32(
  3952. (uint32_t)ha->zio_mode);
  3953. icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
  3954. vha->flags.process_response_queue = 1;
  3955. }
  3956. if (rval) {
  3957. DEBUG2_3(printk(KERN_WARNING
  3958. "scsi(%ld): NVRAM configuration failed!\n", vha->host_no));
  3959. }
  3960. return (rval);
  3961. }
  3962. static int
  3963. qla24xx_load_risc_flash(scsi_qla_host_t *vha, uint32_t *srisc_addr,
  3964. uint32_t faddr)
  3965. {
  3966. int rval = QLA_SUCCESS;
  3967. int segments, fragment;
  3968. uint32_t *dcode, dlen;
  3969. uint32_t risc_addr;
  3970. uint32_t risc_size;
  3971. uint32_t i;
  3972. struct qla_hw_data *ha = vha->hw;
  3973. struct req_que *req = ha->req_q_map[0];
  3974. qla_printk(KERN_INFO, ha,
  3975. "FW: Loading from flash (%x)...\n", faddr);
  3976. rval = QLA_SUCCESS;
  3977. segments = FA_RISC_CODE_SEGMENTS;
  3978. dcode = (uint32_t *)req->ring;
  3979. *srisc_addr = 0;
  3980. /* Validate firmware image by checking version. */
  3981. qla24xx_read_flash_data(vha, dcode, faddr + 4, 4);
  3982. for (i = 0; i < 4; i++)
  3983. dcode[i] = be32_to_cpu(dcode[i]);
  3984. if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
  3985. dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
  3986. (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
  3987. dcode[3] == 0)) {
  3988. qla_printk(KERN_WARNING, ha,
  3989. "Unable to verify integrity of flash firmware image!\n");
  3990. qla_printk(KERN_WARNING, ha,
  3991. "Firmware data: %08x %08x %08x %08x!\n", dcode[0],
  3992. dcode[1], dcode[2], dcode[3]);
  3993. return QLA_FUNCTION_FAILED;
  3994. }
  3995. while (segments && rval == QLA_SUCCESS) {
  3996. /* Read segment's load information. */
  3997. qla24xx_read_flash_data(vha, dcode, faddr, 4);
  3998. risc_addr = be32_to_cpu(dcode[2]);
  3999. *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
  4000. risc_size = be32_to_cpu(dcode[3]);
  4001. fragment = 0;
  4002. while (risc_size > 0 && rval == QLA_SUCCESS) {
  4003. dlen = (uint32_t)(ha->fw_transfer_size >> 2);
  4004. if (dlen > risc_size)
  4005. dlen = risc_size;
  4006. DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
  4007. "addr %x, number of dwords 0x%x, offset 0x%x.\n",
  4008. vha->host_no, risc_addr, dlen, faddr));
  4009. qla24xx_read_flash_data(vha, dcode, faddr, dlen);
  4010. for (i = 0; i < dlen; i++)
  4011. dcode[i] = swab32(dcode[i]);
  4012. rval = qla2x00_load_ram(vha, req->dma, risc_addr,
  4013. dlen);
  4014. if (rval) {
  4015. DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
  4016. "segment %d of firmware\n", vha->host_no,
  4017. fragment));
  4018. qla_printk(KERN_WARNING, ha,
  4019. "[ERROR] Failed to load segment %d of "
  4020. "firmware\n", fragment);
  4021. break;
  4022. }
  4023. faddr += dlen;
  4024. risc_addr += dlen;
  4025. risc_size -= dlen;
  4026. fragment++;
  4027. }
  4028. /* Next segment. */
  4029. segments--;
  4030. }
  4031. return rval;
  4032. }
  4033. #define QLA_FW_URL "ftp://ftp.qlogic.com/outgoing/linux/firmware/"
  4034. int
  4035. qla2x00_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
  4036. {
  4037. int rval;
  4038. int i, fragment;
  4039. uint16_t *wcode, *fwcode;
  4040. uint32_t risc_addr, risc_size, fwclen, wlen, *seg;
  4041. struct fw_blob *blob;
  4042. struct qla_hw_data *ha = vha->hw;
  4043. struct req_que *req = ha->req_q_map[0];
  4044. /* Load firmware blob. */
  4045. blob = qla2x00_request_firmware(vha);
  4046. if (!blob) {
  4047. qla_printk(KERN_ERR, ha, "Firmware image unavailable.\n");
  4048. qla_printk(KERN_ERR, ha, "Firmware images can be retrieved "
  4049. "from: " QLA_FW_URL ".\n");
  4050. return QLA_FUNCTION_FAILED;
  4051. }
  4052. rval = QLA_SUCCESS;
  4053. wcode = (uint16_t *)req->ring;
  4054. *srisc_addr = 0;
  4055. fwcode = (uint16_t *)blob->fw->data;
  4056. fwclen = 0;
  4057. /* Validate firmware image by checking version. */
  4058. if (blob->fw->size < 8 * sizeof(uint16_t)) {
  4059. qla_printk(KERN_WARNING, ha,
  4060. "Unable to verify integrity of firmware image (%Zd)!\n",
  4061. blob->fw->size);
  4062. goto fail_fw_integrity;
  4063. }
  4064. for (i = 0; i < 4; i++)
  4065. wcode[i] = be16_to_cpu(fwcode[i + 4]);
  4066. if ((wcode[0] == 0xffff && wcode[1] == 0xffff && wcode[2] == 0xffff &&
  4067. wcode[3] == 0xffff) || (wcode[0] == 0 && wcode[1] == 0 &&
  4068. wcode[2] == 0 && wcode[3] == 0)) {
  4069. qla_printk(KERN_WARNING, ha,
  4070. "Unable to verify integrity of firmware image!\n");
  4071. qla_printk(KERN_WARNING, ha,
  4072. "Firmware data: %04x %04x %04x %04x!\n", wcode[0],
  4073. wcode[1], wcode[2], wcode[3]);
  4074. goto fail_fw_integrity;
  4075. }
  4076. seg = blob->segs;
  4077. while (*seg && rval == QLA_SUCCESS) {
  4078. risc_addr = *seg;
  4079. *srisc_addr = *srisc_addr == 0 ? *seg : *srisc_addr;
  4080. risc_size = be16_to_cpu(fwcode[3]);
  4081. /* Validate firmware image size. */
  4082. fwclen += risc_size * sizeof(uint16_t);
  4083. if (blob->fw->size < fwclen) {
  4084. qla_printk(KERN_WARNING, ha,
  4085. "Unable to verify integrity of firmware image "
  4086. "(%Zd)!\n", blob->fw->size);
  4087. goto fail_fw_integrity;
  4088. }
  4089. fragment = 0;
  4090. while (risc_size > 0 && rval == QLA_SUCCESS) {
  4091. wlen = (uint16_t)(ha->fw_transfer_size >> 1);
  4092. if (wlen > risc_size)
  4093. wlen = risc_size;
  4094. DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
  4095. "addr %x, number of words 0x%x.\n", vha->host_no,
  4096. risc_addr, wlen));
  4097. for (i = 0; i < wlen; i++)
  4098. wcode[i] = swab16(fwcode[i]);
  4099. rval = qla2x00_load_ram(vha, req->dma, risc_addr,
  4100. wlen);
  4101. if (rval) {
  4102. DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
  4103. "segment %d of firmware\n", vha->host_no,
  4104. fragment));
  4105. qla_printk(KERN_WARNING, ha,
  4106. "[ERROR] Failed to load segment %d of "
  4107. "firmware\n", fragment);
  4108. break;
  4109. }
  4110. fwcode += wlen;
  4111. risc_addr += wlen;
  4112. risc_size -= wlen;
  4113. fragment++;
  4114. }
  4115. /* Next segment. */
  4116. seg++;
  4117. }
  4118. return rval;
  4119. fail_fw_integrity:
  4120. return QLA_FUNCTION_FAILED;
  4121. }
  4122. static int
  4123. qla24xx_load_risc_blob(scsi_qla_host_t *vha, uint32_t *srisc_addr)
  4124. {
  4125. int rval;
  4126. int segments, fragment;
  4127. uint32_t *dcode, dlen;
  4128. uint32_t risc_addr;
  4129. uint32_t risc_size;
  4130. uint32_t i;
  4131. struct fw_blob *blob;
  4132. uint32_t *fwcode, fwclen;
  4133. struct qla_hw_data *ha = vha->hw;
  4134. struct req_que *req = ha->req_q_map[0];
  4135. /* Load firmware blob. */
  4136. blob = qla2x00_request_firmware(vha);
  4137. if (!blob) {
  4138. qla_printk(KERN_ERR, ha, "Firmware image unavailable.\n");
  4139. qla_printk(KERN_ERR, ha, "Firmware images can be retrieved "
  4140. "from: " QLA_FW_URL ".\n");
  4141. return QLA_FUNCTION_FAILED;
  4142. }
  4143. qla_printk(KERN_INFO, ha,
  4144. "FW: Loading via request-firmware...\n");
  4145. rval = QLA_SUCCESS;
  4146. segments = FA_RISC_CODE_SEGMENTS;
  4147. dcode = (uint32_t *)req->ring;
  4148. *srisc_addr = 0;
  4149. fwcode = (uint32_t *)blob->fw->data;
  4150. fwclen = 0;
  4151. /* Validate firmware image by checking version. */
  4152. if (blob->fw->size < 8 * sizeof(uint32_t)) {
  4153. qla_printk(KERN_WARNING, ha,
  4154. "Unable to verify integrity of firmware image (%Zd)!\n",
  4155. blob->fw->size);
  4156. goto fail_fw_integrity;
  4157. }
  4158. for (i = 0; i < 4; i++)
  4159. dcode[i] = be32_to_cpu(fwcode[i + 4]);
  4160. if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
  4161. dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
  4162. (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
  4163. dcode[3] == 0)) {
  4164. qla_printk(KERN_WARNING, ha,
  4165. "Unable to verify integrity of firmware image!\n");
  4166. qla_printk(KERN_WARNING, ha,
  4167. "Firmware data: %08x %08x %08x %08x!\n", dcode[0],
  4168. dcode[1], dcode[2], dcode[3]);
  4169. goto fail_fw_integrity;
  4170. }
  4171. while (segments && rval == QLA_SUCCESS) {
  4172. risc_addr = be32_to_cpu(fwcode[2]);
  4173. *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
  4174. risc_size = be32_to_cpu(fwcode[3]);
  4175. /* Validate firmware image size. */
  4176. fwclen += risc_size * sizeof(uint32_t);
  4177. if (blob->fw->size < fwclen) {
  4178. qla_printk(KERN_WARNING, ha,
  4179. "Unable to verify integrity of firmware image "
  4180. "(%Zd)!\n", blob->fw->size);
  4181. goto fail_fw_integrity;
  4182. }
  4183. fragment = 0;
  4184. while (risc_size > 0 && rval == QLA_SUCCESS) {
  4185. dlen = (uint32_t)(ha->fw_transfer_size >> 2);
  4186. if (dlen > risc_size)
  4187. dlen = risc_size;
  4188. DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
  4189. "addr %x, number of dwords 0x%x.\n", vha->host_no,
  4190. risc_addr, dlen));
  4191. for (i = 0; i < dlen; i++)
  4192. dcode[i] = swab32(fwcode[i]);
  4193. rval = qla2x00_load_ram(vha, req->dma, risc_addr,
  4194. dlen);
  4195. if (rval) {
  4196. DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
  4197. "segment %d of firmware\n", vha->host_no,
  4198. fragment));
  4199. qla_printk(KERN_WARNING, ha,
  4200. "[ERROR] Failed to load segment %d of "
  4201. "firmware\n", fragment);
  4202. break;
  4203. }
  4204. fwcode += dlen;
  4205. risc_addr += dlen;
  4206. risc_size -= dlen;
  4207. fragment++;
  4208. }
  4209. /* Next segment. */
  4210. segments--;
  4211. }
  4212. return rval;
  4213. fail_fw_integrity:
  4214. return QLA_FUNCTION_FAILED;
  4215. }
  4216. int
  4217. qla24xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
  4218. {
  4219. int rval;
  4220. if (ql2xfwloadbin == 1)
  4221. return qla81xx_load_risc(vha, srisc_addr);
  4222. /*
  4223. * FW Load priority:
  4224. * 1) Firmware via request-firmware interface (.bin file).
  4225. * 2) Firmware residing in flash.
  4226. */
  4227. rval = qla24xx_load_risc_blob(vha, srisc_addr);
  4228. if (rval == QLA_SUCCESS)
  4229. return rval;
  4230. return qla24xx_load_risc_flash(vha, srisc_addr,
  4231. vha->hw->flt_region_fw);
  4232. }
  4233. int
  4234. qla81xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
  4235. {
  4236. int rval;
  4237. struct qla_hw_data *ha = vha->hw;
  4238. if (ql2xfwloadbin == 2)
  4239. goto try_blob_fw;
  4240. /*
  4241. * FW Load priority:
  4242. * 1) Firmware residing in flash.
  4243. * 2) Firmware via request-firmware interface (.bin file).
  4244. * 3) Golden-Firmware residing in flash -- limited operation.
  4245. */
  4246. rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_fw);
  4247. if (rval == QLA_SUCCESS)
  4248. return rval;
  4249. try_blob_fw:
  4250. rval = qla24xx_load_risc_blob(vha, srisc_addr);
  4251. if (rval == QLA_SUCCESS || !ha->flt_region_gold_fw)
  4252. return rval;
  4253. qla_printk(KERN_ERR, ha,
  4254. "FW: Attempting to fallback to golden firmware...\n");
  4255. rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_gold_fw);
  4256. if (rval != QLA_SUCCESS)
  4257. return rval;
  4258. qla_printk(KERN_ERR, ha,
  4259. "FW: Please update operational firmware...\n");
  4260. ha->flags.running_gold_fw = 1;
  4261. return rval;
  4262. }
  4263. void
  4264. qla2x00_try_to_stop_firmware(scsi_qla_host_t *vha)
  4265. {
  4266. int ret, retries;
  4267. struct qla_hw_data *ha = vha->hw;
  4268. if (ha->flags.pci_channel_io_perm_failure)
  4269. return;
  4270. if (!IS_FWI2_CAPABLE(ha))
  4271. return;
  4272. if (!ha->fw_major_version)
  4273. return;
  4274. ret = qla2x00_stop_firmware(vha);
  4275. for (retries = 5; ret != QLA_SUCCESS && ret != QLA_FUNCTION_TIMEOUT &&
  4276. ret != QLA_INVALID_COMMAND && retries ; retries--) {
  4277. ha->isp_ops->reset_chip(vha);
  4278. if (ha->isp_ops->chip_diag(vha) != QLA_SUCCESS)
  4279. continue;
  4280. if (qla2x00_setup_chip(vha) != QLA_SUCCESS)
  4281. continue;
  4282. qla_printk(KERN_INFO, ha,
  4283. "Attempting retry of stop-firmware command...\n");
  4284. ret = qla2x00_stop_firmware(vha);
  4285. }
  4286. }
  4287. int
  4288. qla24xx_configure_vhba(scsi_qla_host_t *vha)
  4289. {
  4290. int rval = QLA_SUCCESS;
  4291. uint16_t mb[MAILBOX_REGISTER_COUNT];
  4292. struct qla_hw_data *ha = vha->hw;
  4293. struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
  4294. struct req_que *req;
  4295. struct rsp_que *rsp;
  4296. if (!vha->vp_idx)
  4297. return -EINVAL;
  4298. rval = qla2x00_fw_ready(base_vha);
  4299. if (ha->flags.cpu_affinity_enabled)
  4300. req = ha->req_q_map[0];
  4301. else
  4302. req = vha->req;
  4303. rsp = req->rsp;
  4304. if (rval == QLA_SUCCESS) {
  4305. clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
  4306. qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
  4307. }
  4308. vha->flags.management_server_logged_in = 0;
  4309. /* Login to SNS first */
  4310. ha->isp_ops->fabric_login(vha, NPH_SNS, 0xff, 0xff, 0xfc, mb, BIT_1);
  4311. if (mb[0] != MBS_COMMAND_COMPLETE) {
  4312. DEBUG15(qla_printk(KERN_INFO, ha,
  4313. "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
  4314. "mb[2]=%x mb[6]=%x mb[7]=%x\n", NPH_SNS,
  4315. mb[0], mb[1], mb[2], mb[6], mb[7]));
  4316. return (QLA_FUNCTION_FAILED);
  4317. }
  4318. atomic_set(&vha->loop_down_timer, 0);
  4319. atomic_set(&vha->loop_state, LOOP_UP);
  4320. set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
  4321. set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
  4322. rval = qla2x00_loop_resync(base_vha);
  4323. return rval;
  4324. }
  4325. /* 84XX Support **************************************************************/
  4326. static LIST_HEAD(qla_cs84xx_list);
  4327. static DEFINE_MUTEX(qla_cs84xx_mutex);
  4328. static struct qla_chip_state_84xx *
  4329. qla84xx_get_chip(struct scsi_qla_host *vha)
  4330. {
  4331. struct qla_chip_state_84xx *cs84xx;
  4332. struct qla_hw_data *ha = vha->hw;
  4333. mutex_lock(&qla_cs84xx_mutex);
  4334. /* Find any shared 84xx chip. */
  4335. list_for_each_entry(cs84xx, &qla_cs84xx_list, list) {
  4336. if (cs84xx->bus == ha->pdev->bus) {
  4337. kref_get(&cs84xx->kref);
  4338. goto done;
  4339. }
  4340. }
  4341. cs84xx = kzalloc(sizeof(*cs84xx), GFP_KERNEL);
  4342. if (!cs84xx)
  4343. goto done;
  4344. kref_init(&cs84xx->kref);
  4345. spin_lock_init(&cs84xx->access_lock);
  4346. mutex_init(&cs84xx->fw_update_mutex);
  4347. cs84xx->bus = ha->pdev->bus;
  4348. list_add_tail(&cs84xx->list, &qla_cs84xx_list);
  4349. done:
  4350. mutex_unlock(&qla_cs84xx_mutex);
  4351. return cs84xx;
  4352. }
  4353. static void
  4354. __qla84xx_chip_release(struct kref *kref)
  4355. {
  4356. struct qla_chip_state_84xx *cs84xx =
  4357. container_of(kref, struct qla_chip_state_84xx, kref);
  4358. mutex_lock(&qla_cs84xx_mutex);
  4359. list_del(&cs84xx->list);
  4360. mutex_unlock(&qla_cs84xx_mutex);
  4361. kfree(cs84xx);
  4362. }
  4363. void
  4364. qla84xx_put_chip(struct scsi_qla_host *vha)
  4365. {
  4366. struct qla_hw_data *ha = vha->hw;
  4367. if (ha->cs84xx)
  4368. kref_put(&ha->cs84xx->kref, __qla84xx_chip_release);
  4369. }
  4370. static int
  4371. qla84xx_init_chip(scsi_qla_host_t *vha)
  4372. {
  4373. int rval;
  4374. uint16_t status[2];
  4375. struct qla_hw_data *ha = vha->hw;
  4376. mutex_lock(&ha->cs84xx->fw_update_mutex);
  4377. rval = qla84xx_verify_chip(vha, status);
  4378. mutex_unlock(&ha->cs84xx->fw_update_mutex);
  4379. return rval != QLA_SUCCESS || status[0] ? QLA_FUNCTION_FAILED:
  4380. QLA_SUCCESS;
  4381. }
  4382. /* 81XX Support **************************************************************/
  4383. int
  4384. qla81xx_nvram_config(scsi_qla_host_t *vha)
  4385. {
  4386. int rval;
  4387. struct init_cb_81xx *icb;
  4388. struct nvram_81xx *nv;
  4389. uint32_t *dptr;
  4390. uint8_t *dptr1, *dptr2;
  4391. uint32_t chksum;
  4392. uint16_t cnt;
  4393. struct qla_hw_data *ha = vha->hw;
  4394. rval = QLA_SUCCESS;
  4395. icb = (struct init_cb_81xx *)ha->init_cb;
  4396. nv = ha->nvram;
  4397. /* Determine NVRAM starting address. */
  4398. ha->nvram_size = sizeof(struct nvram_81xx);
  4399. ha->vpd_size = FA_NVRAM_VPD_SIZE;
  4400. /* Get VPD data into cache */
  4401. ha->vpd = ha->nvram + VPD_OFFSET;
  4402. ha->isp_ops->read_optrom(vha, ha->vpd, ha->flt_region_vpd << 2,
  4403. ha->vpd_size);
  4404. /* Get NVRAM data into cache and calculate checksum. */
  4405. ha->isp_ops->read_optrom(vha, ha->nvram, ha->flt_region_nvram << 2,
  4406. ha->nvram_size);
  4407. dptr = (uint32_t *)nv;
  4408. for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++)
  4409. chksum += le32_to_cpu(*dptr++);
  4410. DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", vha->host_no));
  4411. DEBUG5(qla2x00_dump_buffer((uint8_t *)nv, ha->nvram_size));
  4412. /* Bad NVRAM data, set defaults parameters. */
  4413. if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
  4414. || nv->id[3] != ' ' ||
  4415. nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) {
  4416. /* Reset NVRAM data. */
  4417. qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
  4418. "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
  4419. le16_to_cpu(nv->nvram_version));
  4420. qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
  4421. "invalid -- WWPN) defaults.\n");
  4422. /*
  4423. * Set default initialization control block.
  4424. */
  4425. memset(nv, 0, ha->nvram_size);
  4426. nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION);
  4427. nv->version = __constant_cpu_to_le16(ICB_VERSION);
  4428. nv->frame_payload_size = __constant_cpu_to_le16(2048);
  4429. nv->execution_throttle = __constant_cpu_to_le16(0xFFFF);
  4430. nv->exchange_count = __constant_cpu_to_le16(0);
  4431. nv->port_name[0] = 0x21;
  4432. nv->port_name[1] = 0x00 + ha->port_no;
  4433. nv->port_name[2] = 0x00;
  4434. nv->port_name[3] = 0xe0;
  4435. nv->port_name[4] = 0x8b;
  4436. nv->port_name[5] = 0x1c;
  4437. nv->port_name[6] = 0x55;
  4438. nv->port_name[7] = 0x86;
  4439. nv->node_name[0] = 0x20;
  4440. nv->node_name[1] = 0x00;
  4441. nv->node_name[2] = 0x00;
  4442. nv->node_name[3] = 0xe0;
  4443. nv->node_name[4] = 0x8b;
  4444. nv->node_name[5] = 0x1c;
  4445. nv->node_name[6] = 0x55;
  4446. nv->node_name[7] = 0x86;
  4447. nv->login_retry_count = __constant_cpu_to_le16(8);
  4448. nv->interrupt_delay_timer = __constant_cpu_to_le16(0);
  4449. nv->login_timeout = __constant_cpu_to_le16(0);
  4450. nv->firmware_options_1 =
  4451. __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
  4452. nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4);
  4453. nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12);
  4454. nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13);
  4455. nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10);
  4456. nv->efi_parameters = __constant_cpu_to_le32(0);
  4457. nv->reset_delay = 5;
  4458. nv->max_luns_per_target = __constant_cpu_to_le16(128);
  4459. nv->port_down_retry_count = __constant_cpu_to_le16(30);
  4460. nv->link_down_timeout = __constant_cpu_to_le16(30);
  4461. nv->enode_mac[0] = 0x00;
  4462. nv->enode_mac[1] = 0x02;
  4463. nv->enode_mac[2] = 0x03;
  4464. nv->enode_mac[3] = 0x04;
  4465. nv->enode_mac[4] = 0x05;
  4466. nv->enode_mac[5] = 0x06 + ha->port_no;
  4467. rval = 1;
  4468. }
  4469. /* Reset Initialization control block */
  4470. memset(icb, 0, sizeof(struct init_cb_81xx));
  4471. /* Copy 1st segment. */
  4472. dptr1 = (uint8_t *)icb;
  4473. dptr2 = (uint8_t *)&nv->version;
  4474. cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
  4475. while (cnt--)
  4476. *dptr1++ = *dptr2++;
  4477. icb->login_retry_count = nv->login_retry_count;
  4478. /* Copy 2nd segment. */
  4479. dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
  4480. dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
  4481. cnt = (uint8_t *)&icb->reserved_5 -
  4482. (uint8_t *)&icb->interrupt_delay_timer;
  4483. while (cnt--)
  4484. *dptr1++ = *dptr2++;
  4485. memcpy(icb->enode_mac, nv->enode_mac, sizeof(icb->enode_mac));
  4486. /* Some boards (with valid NVRAMs) still have NULL enode_mac!! */
  4487. if (!memcmp(icb->enode_mac, "\0\0\0\0\0\0", sizeof(icb->enode_mac))) {
  4488. icb->enode_mac[0] = 0x01;
  4489. icb->enode_mac[1] = 0x02;
  4490. icb->enode_mac[2] = 0x03;
  4491. icb->enode_mac[3] = 0x04;
  4492. icb->enode_mac[4] = 0x05;
  4493. icb->enode_mac[5] = 0x06 + ha->port_no;
  4494. }
  4495. /* Use extended-initialization control block. */
  4496. memcpy(ha->ex_init_cb, &nv->ex_version, sizeof(*ha->ex_init_cb));
  4497. /*
  4498. * Setup driver NVRAM options.
  4499. */
  4500. qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
  4501. "QLE8XXX");
  4502. /* Use alternate WWN? */
  4503. if (nv->host_p & __constant_cpu_to_le32(BIT_15)) {
  4504. memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
  4505. memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
  4506. }
  4507. /* Prepare nodename */
  4508. if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) {
  4509. /*
  4510. * Firmware will apply the following mask if the nodename was
  4511. * not provided.
  4512. */
  4513. memcpy(icb->node_name, icb->port_name, WWN_SIZE);
  4514. icb->node_name[0] &= 0xF0;
  4515. }
  4516. /* Set host adapter parameters. */
  4517. ha->flags.disable_risc_code_load = 0;
  4518. ha->flags.enable_lip_reset = 0;
  4519. ha->flags.enable_lip_full_login =
  4520. le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
  4521. ha->flags.enable_target_reset =
  4522. le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
  4523. ha->flags.enable_led_scheme = 0;
  4524. ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
  4525. ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
  4526. (BIT_6 | BIT_5 | BIT_4)) >> 4;
  4527. /* save HBA serial number */
  4528. ha->serial0 = icb->port_name[5];
  4529. ha->serial1 = icb->port_name[6];
  4530. ha->serial2 = icb->port_name[7];
  4531. memcpy(vha->node_name, icb->node_name, WWN_SIZE);
  4532. memcpy(vha->port_name, icb->port_name, WWN_SIZE);
  4533. icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
  4534. ha->retry_count = le16_to_cpu(nv->login_retry_count);
  4535. /* Set minimum login_timeout to 4 seconds. */
  4536. if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
  4537. nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
  4538. if (le16_to_cpu(nv->login_timeout) < 4)
  4539. nv->login_timeout = __constant_cpu_to_le16(4);
  4540. ha->login_timeout = le16_to_cpu(nv->login_timeout);
  4541. icb->login_timeout = nv->login_timeout;
  4542. /* Set minimum RATOV to 100 tenths of a second. */
  4543. ha->r_a_tov = 100;
  4544. ha->loop_reset_delay = nv->reset_delay;
  4545. /* Link Down Timeout = 0:
  4546. *
  4547. * When Port Down timer expires we will start returning
  4548. * I/O's to OS with "DID_NO_CONNECT".
  4549. *
  4550. * Link Down Timeout != 0:
  4551. *
  4552. * The driver waits for the link to come up after link down
  4553. * before returning I/Os to OS with "DID_NO_CONNECT".
  4554. */
  4555. if (le16_to_cpu(nv->link_down_timeout) == 0) {
  4556. ha->loop_down_abort_time =
  4557. (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
  4558. } else {
  4559. ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
  4560. ha->loop_down_abort_time =
  4561. (LOOP_DOWN_TIME - ha->link_down_timeout);
  4562. }
  4563. /* Need enough time to try and get the port back. */
  4564. ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
  4565. if (qlport_down_retry)
  4566. ha->port_down_retry_count = qlport_down_retry;
  4567. /* Set login_retry_count */
  4568. ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
  4569. if (ha->port_down_retry_count ==
  4570. le16_to_cpu(nv->port_down_retry_count) &&
  4571. ha->port_down_retry_count > 3)
  4572. ha->login_retry_count = ha->port_down_retry_count;
  4573. else if (ha->port_down_retry_count > (int)ha->login_retry_count)
  4574. ha->login_retry_count = ha->port_down_retry_count;
  4575. if (ql2xloginretrycount)
  4576. ha->login_retry_count = ql2xloginretrycount;
  4577. /* Enable ZIO. */
  4578. if (!vha->flags.init_done) {
  4579. ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
  4580. (BIT_3 | BIT_2 | BIT_1 | BIT_0);
  4581. ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
  4582. le16_to_cpu(icb->interrupt_delay_timer): 2;
  4583. }
  4584. icb->firmware_options_2 &= __constant_cpu_to_le32(
  4585. ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
  4586. vha->flags.process_response_queue = 0;
  4587. if (ha->zio_mode != QLA_ZIO_DISABLED) {
  4588. ha->zio_mode = QLA_ZIO_MODE_6;
  4589. DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer delay "
  4590. "(%d us).\n", vha->host_no, ha->zio_mode,
  4591. ha->zio_timer * 100));
  4592. qla_printk(KERN_INFO, ha,
  4593. "ZIO mode %d enabled; timer delay (%d us).\n",
  4594. ha->zio_mode, ha->zio_timer * 100);
  4595. icb->firmware_options_2 |= cpu_to_le32(
  4596. (uint32_t)ha->zio_mode);
  4597. icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
  4598. vha->flags.process_response_queue = 1;
  4599. }
  4600. if (rval) {
  4601. DEBUG2_3(printk(KERN_WARNING
  4602. "scsi(%ld): NVRAM configuration failed!\n", vha->host_no));
  4603. }
  4604. return (rval);
  4605. }
  4606. int
  4607. qla82xx_restart_isp(scsi_qla_host_t *vha)
  4608. {
  4609. int status, rval;
  4610. uint32_t wait_time;
  4611. struct qla_hw_data *ha = vha->hw;
  4612. struct req_que *req = ha->req_q_map[0];
  4613. struct rsp_que *rsp = ha->rsp_q_map[0];
  4614. struct scsi_qla_host *vp;
  4615. unsigned long flags;
  4616. status = qla2x00_init_rings(vha);
  4617. if (!status) {
  4618. clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
  4619. ha->flags.chip_reset_done = 1;
  4620. status = qla2x00_fw_ready(vha);
  4621. if (!status) {
  4622. qla_printk(KERN_INFO, ha,
  4623. "%s(): Start configure loop, "
  4624. "status = %d\n", __func__, status);
  4625. /* Issue a marker after FW becomes ready. */
  4626. qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
  4627. vha->flags.online = 1;
  4628. /* Wait at most MAX_TARGET RSCNs for a stable link. */
  4629. wait_time = 256;
  4630. do {
  4631. clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
  4632. qla2x00_configure_loop(vha);
  4633. wait_time--;
  4634. } while (!atomic_read(&vha->loop_down_timer) &&
  4635. !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags)) &&
  4636. wait_time &&
  4637. (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)));
  4638. }
  4639. /* if no cable then assume it's good */
  4640. if ((vha->device_flags & DFLG_NO_CABLE))
  4641. status = 0;
  4642. qla_printk(KERN_INFO, ha,
  4643. "%s(): Configure loop done, status = 0x%x\n",
  4644. __func__, status);
  4645. }
  4646. if (!status) {
  4647. clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
  4648. if (!atomic_read(&vha->loop_down_timer)) {
  4649. /*
  4650. * Issue marker command only when we are going
  4651. * to start the I/O .
  4652. */
  4653. vha->marker_needed = 1;
  4654. }
  4655. vha->flags.online = 1;
  4656. ha->isp_ops->enable_intrs(ha);
  4657. ha->isp_abort_cnt = 0;
  4658. clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
  4659. if (ha->fce) {
  4660. ha->flags.fce_enabled = 1;
  4661. memset(ha->fce, 0,
  4662. fce_calc_size(ha->fce_bufs));
  4663. rval = qla2x00_enable_fce_trace(vha,
  4664. ha->fce_dma, ha->fce_bufs, ha->fce_mb,
  4665. &ha->fce_bufs);
  4666. if (rval) {
  4667. qla_printk(KERN_WARNING, ha,
  4668. "Unable to reinitialize FCE "
  4669. "(%d).\n", rval);
  4670. ha->flags.fce_enabled = 0;
  4671. }
  4672. }
  4673. if (ha->eft) {
  4674. memset(ha->eft, 0, EFT_SIZE);
  4675. rval = qla2x00_enable_eft_trace(vha,
  4676. ha->eft_dma, EFT_NUM_BUFFERS);
  4677. if (rval) {
  4678. qla_printk(KERN_WARNING, ha,
  4679. "Unable to reinitialize EFT "
  4680. "(%d).\n", rval);
  4681. }
  4682. }
  4683. }
  4684. if (!status) {
  4685. DEBUG(printk(KERN_INFO
  4686. "qla82xx_restart_isp(%ld): succeeded.\n",
  4687. vha->host_no));
  4688. spin_lock_irqsave(&ha->vport_slock, flags);
  4689. list_for_each_entry(vp, &ha->vp_list, list) {
  4690. if (vp->vp_idx) {
  4691. atomic_inc(&vp->vref_count);
  4692. spin_unlock_irqrestore(&ha->vport_slock, flags);
  4693. qla2x00_vp_abort_isp(vp);
  4694. spin_lock_irqsave(&ha->vport_slock, flags);
  4695. atomic_dec(&vp->vref_count);
  4696. }
  4697. }
  4698. spin_unlock_irqrestore(&ha->vport_slock, flags);
  4699. } else {
  4700. qla_printk(KERN_INFO, ha,
  4701. "qla82xx_restart_isp: **** FAILED ****\n");
  4702. }
  4703. return status;
  4704. }
  4705. void
  4706. qla81xx_update_fw_options(scsi_qla_host_t *vha)
  4707. {
  4708. struct qla_hw_data *ha = vha->hw;
  4709. if (!ql2xetsenable)
  4710. return;
  4711. /* Enable ETS Burst. */
  4712. memset(ha->fw_options, 0, sizeof(ha->fw_options));
  4713. ha->fw_options[2] |= BIT_9;
  4714. qla2x00_set_fw_options(vha, ha->fw_options);
  4715. }
  4716. /*
  4717. * qla24xx_get_fcp_prio
  4718. * Gets the fcp cmd priority value for the logged in port.
  4719. * Looks for a match of the port descriptors within
  4720. * each of the fcp prio config entries. If a match is found,
  4721. * the tag (priority) value is returned.
  4722. *
  4723. * Input:
  4724. * vha = scsi host structure pointer.
  4725. * fcport = port structure pointer.
  4726. *
  4727. * Return:
  4728. * non-zero (if found)
  4729. * 0 (if not found)
  4730. *
  4731. * Context:
  4732. * Kernel context
  4733. */
  4734. uint8_t
  4735. qla24xx_get_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport)
  4736. {
  4737. int i, entries;
  4738. uint8_t pid_match, wwn_match;
  4739. uint8_t priority;
  4740. uint32_t pid1, pid2;
  4741. uint64_t wwn1, wwn2;
  4742. struct qla_fcp_prio_entry *pri_entry;
  4743. struct qla_hw_data *ha = vha->hw;
  4744. if (!ha->fcp_prio_cfg || !ha->flags.fcp_prio_enabled)
  4745. return 0;
  4746. priority = 0;
  4747. entries = ha->fcp_prio_cfg->num_entries;
  4748. pri_entry = &ha->fcp_prio_cfg->entry[0];
  4749. for (i = 0; i < entries; i++) {
  4750. pid_match = wwn_match = 0;
  4751. if (!(pri_entry->flags & FCP_PRIO_ENTRY_VALID)) {
  4752. pri_entry++;
  4753. continue;
  4754. }
  4755. /* check source pid for a match */
  4756. if (pri_entry->flags & FCP_PRIO_ENTRY_SPID_VALID) {
  4757. pid1 = pri_entry->src_pid & INVALID_PORT_ID;
  4758. pid2 = vha->d_id.b24 & INVALID_PORT_ID;
  4759. if (pid1 == INVALID_PORT_ID)
  4760. pid_match++;
  4761. else if (pid1 == pid2)
  4762. pid_match++;
  4763. }
  4764. /* check destination pid for a match */
  4765. if (pri_entry->flags & FCP_PRIO_ENTRY_DPID_VALID) {
  4766. pid1 = pri_entry->dst_pid & INVALID_PORT_ID;
  4767. pid2 = fcport->d_id.b24 & INVALID_PORT_ID;
  4768. if (pid1 == INVALID_PORT_ID)
  4769. pid_match++;
  4770. else if (pid1 == pid2)
  4771. pid_match++;
  4772. }
  4773. /* check source WWN for a match */
  4774. if (pri_entry->flags & FCP_PRIO_ENTRY_SWWN_VALID) {
  4775. wwn1 = wwn_to_u64(vha->port_name);
  4776. wwn2 = wwn_to_u64(pri_entry->src_wwpn);
  4777. if (wwn2 == (uint64_t)-1)
  4778. wwn_match++;
  4779. else if (wwn1 == wwn2)
  4780. wwn_match++;
  4781. }
  4782. /* check destination WWN for a match */
  4783. if (pri_entry->flags & FCP_PRIO_ENTRY_DWWN_VALID) {
  4784. wwn1 = wwn_to_u64(fcport->port_name);
  4785. wwn2 = wwn_to_u64(pri_entry->dst_wwpn);
  4786. if (wwn2 == (uint64_t)-1)
  4787. wwn_match++;
  4788. else if (wwn1 == wwn2)
  4789. wwn_match++;
  4790. }
  4791. if (pid_match == 2 || wwn_match == 2) {
  4792. /* Found a matching entry */
  4793. if (pri_entry->flags & FCP_PRIO_ENTRY_TAG_VALID)
  4794. priority = pri_entry->tag;
  4795. break;
  4796. }
  4797. pri_entry++;
  4798. }
  4799. return priority;
  4800. }
  4801. /*
  4802. * qla24xx_update_fcport_fcp_prio
  4803. * Activates fcp priority for the logged in fc port
  4804. *
  4805. * Input:
  4806. * vha = scsi host structure pointer.
  4807. * fcp = port structure pointer.
  4808. *
  4809. * Return:
  4810. * QLA_SUCCESS or QLA_FUNCTION_FAILED
  4811. *
  4812. * Context:
  4813. * Kernel context.
  4814. */
  4815. int
  4816. qla24xx_update_fcport_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport)
  4817. {
  4818. int ret;
  4819. uint8_t priority;
  4820. uint16_t mb[5];
  4821. if (fcport->port_type != FCT_TARGET ||
  4822. fcport->loop_id == FC_NO_LOOP_ID)
  4823. return QLA_FUNCTION_FAILED;
  4824. priority = qla24xx_get_fcp_prio(vha, fcport);
  4825. ret = qla24xx_set_fcp_prio(vha, fcport->loop_id, priority, mb);
  4826. if (ret == QLA_SUCCESS)
  4827. fcport->fcp_prio = priority;
  4828. else
  4829. DEBUG2(printk(KERN_WARNING
  4830. "scsi(%ld): Unable to activate fcp priority, "
  4831. " ret=0x%x\n", vha->host_no, ret));
  4832. return ret;
  4833. }
  4834. /*
  4835. * qla24xx_update_all_fcp_prio
  4836. * Activates fcp priority for all the logged in ports
  4837. *
  4838. * Input:
  4839. * ha = adapter block pointer.
  4840. *
  4841. * Return:
  4842. * QLA_SUCCESS or QLA_FUNCTION_FAILED
  4843. *
  4844. * Context:
  4845. * Kernel context.
  4846. */
  4847. int
  4848. qla24xx_update_all_fcp_prio(scsi_qla_host_t *vha)
  4849. {
  4850. int ret;
  4851. fc_port_t *fcport;
  4852. ret = QLA_FUNCTION_FAILED;
  4853. /* We need to set priority for all logged in ports */
  4854. list_for_each_entry(fcport, &vha->vp_fcports, list)
  4855. ret = qla24xx_update_fcport_fcp_prio(vha, fcport);
  4856. return ret;
  4857. }