qla_init.c 143 KB

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