qla_init.c 144 KB

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