lpfc_hbadisc.c 132 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739
  1. /*******************************************************************
  2. * This file is part of the Emulex Linux Device Driver for *
  3. * Fibre Channel Host Bus Adapters. *
  4. * Copyright (C) 2004-2009 Emulex. All rights reserved. *
  5. * EMULEX and SLI are trademarks of Emulex. *
  6. * www.emulex.com *
  7. * Portions Copyright (C) 2004-2005 Christoph Hellwig *
  8. * *
  9. * This program is free software; you can redistribute it and/or *
  10. * modify it under the terms of version 2 of the GNU General *
  11. * Public License as published by the Free Software Foundation. *
  12. * This program is distributed in the hope that it will be useful. *
  13. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
  14. * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
  15. * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
  16. * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
  17. * TO BE LEGALLY INVALID. See the GNU General Public License for *
  18. * more details, a copy of which can be found in the file COPYING *
  19. * included with this package. *
  20. *******************************************************************/
  21. #include <linux/blkdev.h>
  22. #include <linux/pci.h>
  23. #include <linux/kthread.h>
  24. #include <linux/interrupt.h>
  25. #include <scsi/scsi.h>
  26. #include <scsi/scsi_device.h>
  27. #include <scsi/scsi_host.h>
  28. #include <scsi/scsi_transport_fc.h>
  29. #include "lpfc_hw4.h"
  30. #include "lpfc_hw.h"
  31. #include "lpfc_nl.h"
  32. #include "lpfc_disc.h"
  33. #include "lpfc_sli.h"
  34. #include "lpfc_sli4.h"
  35. #include "lpfc_scsi.h"
  36. #include "lpfc.h"
  37. #include "lpfc_logmsg.h"
  38. #include "lpfc_crtn.h"
  39. #include "lpfc_vport.h"
  40. #include "lpfc_debugfs.h"
  41. /* AlpaArray for assignment of scsid for scan-down and bind_method */
  42. static uint8_t lpfcAlpaArray[] = {
  43. 0xEF, 0xE8, 0xE4, 0xE2, 0xE1, 0xE0, 0xDC, 0xDA, 0xD9, 0xD6,
  44. 0xD5, 0xD4, 0xD3, 0xD2, 0xD1, 0xCE, 0xCD, 0xCC, 0xCB, 0xCA,
  45. 0xC9, 0xC7, 0xC6, 0xC5, 0xC3, 0xBC, 0xBA, 0xB9, 0xB6, 0xB5,
  46. 0xB4, 0xB3, 0xB2, 0xB1, 0xAE, 0xAD, 0xAC, 0xAB, 0xAA, 0xA9,
  47. 0xA7, 0xA6, 0xA5, 0xA3, 0x9F, 0x9E, 0x9D, 0x9B, 0x98, 0x97,
  48. 0x90, 0x8F, 0x88, 0x84, 0x82, 0x81, 0x80, 0x7C, 0x7A, 0x79,
  49. 0x76, 0x75, 0x74, 0x73, 0x72, 0x71, 0x6E, 0x6D, 0x6C, 0x6B,
  50. 0x6A, 0x69, 0x67, 0x66, 0x65, 0x63, 0x5C, 0x5A, 0x59, 0x56,
  51. 0x55, 0x54, 0x53, 0x52, 0x51, 0x4E, 0x4D, 0x4C, 0x4B, 0x4A,
  52. 0x49, 0x47, 0x46, 0x45, 0x43, 0x3C, 0x3A, 0x39, 0x36, 0x35,
  53. 0x34, 0x33, 0x32, 0x31, 0x2E, 0x2D, 0x2C, 0x2B, 0x2A, 0x29,
  54. 0x27, 0x26, 0x25, 0x23, 0x1F, 0x1E, 0x1D, 0x1B, 0x18, 0x17,
  55. 0x10, 0x0F, 0x08, 0x04, 0x02, 0x01
  56. };
  57. static void lpfc_disc_timeout_handler(struct lpfc_vport *);
  58. static void lpfc_disc_flush_list(struct lpfc_vport *vport);
  59. static void lpfc_unregister_fcfi_cmpl(struct lpfc_hba *, LPFC_MBOXQ_t *);
  60. void
  61. lpfc_terminate_rport_io(struct fc_rport *rport)
  62. {
  63. struct lpfc_rport_data *rdata;
  64. struct lpfc_nodelist * ndlp;
  65. struct lpfc_hba *phba;
  66. rdata = rport->dd_data;
  67. ndlp = rdata->pnode;
  68. if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
  69. if (rport->roles & FC_RPORT_ROLE_FCP_TARGET)
  70. printk(KERN_ERR "Cannot find remote node"
  71. " to terminate I/O Data x%x\n",
  72. rport->port_id);
  73. return;
  74. }
  75. phba = ndlp->phba;
  76. lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_RPORT,
  77. "rport terminate: sid:x%x did:x%x flg:x%x",
  78. ndlp->nlp_sid, ndlp->nlp_DID, ndlp->nlp_flag);
  79. if (ndlp->nlp_sid != NLP_NO_SID) {
  80. lpfc_sli_abort_iocb(ndlp->vport,
  81. &phba->sli.ring[phba->sli.fcp_ring],
  82. ndlp->nlp_sid, 0, LPFC_CTX_TGT);
  83. }
  84. }
  85. /*
  86. * This function will be called when dev_loss_tmo fire.
  87. */
  88. void
  89. lpfc_dev_loss_tmo_callbk(struct fc_rport *rport)
  90. {
  91. struct lpfc_rport_data *rdata;
  92. struct lpfc_nodelist * ndlp;
  93. struct lpfc_vport *vport;
  94. struct lpfc_hba *phba;
  95. struct lpfc_work_evt *evtp;
  96. int put_node;
  97. int put_rport;
  98. rdata = rport->dd_data;
  99. ndlp = rdata->pnode;
  100. if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
  101. return;
  102. vport = ndlp->vport;
  103. phba = vport->phba;
  104. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
  105. "rport devlosscb: sid:x%x did:x%x flg:x%x",
  106. ndlp->nlp_sid, ndlp->nlp_DID, ndlp->nlp_flag);
  107. /* Don't defer this if we are in the process of deleting the vport
  108. * or unloading the driver. The unload will cleanup the node
  109. * appropriately we just need to cleanup the ndlp rport info here.
  110. */
  111. if (vport->load_flag & FC_UNLOADING) {
  112. put_node = rdata->pnode != NULL;
  113. put_rport = ndlp->rport != NULL;
  114. rdata->pnode = NULL;
  115. ndlp->rport = NULL;
  116. if (put_node)
  117. lpfc_nlp_put(ndlp);
  118. if (put_rport)
  119. put_device(&rport->dev);
  120. return;
  121. }
  122. if (ndlp->nlp_state == NLP_STE_MAPPED_NODE)
  123. return;
  124. evtp = &ndlp->dev_loss_evt;
  125. if (!list_empty(&evtp->evt_listp))
  126. return;
  127. spin_lock_irq(&phba->hbalock);
  128. /* We need to hold the node by incrementing the reference
  129. * count until this queued work is done
  130. */
  131. evtp->evt_arg1 = lpfc_nlp_get(ndlp);
  132. if (evtp->evt_arg1) {
  133. evtp->evt = LPFC_EVT_DEV_LOSS;
  134. list_add_tail(&evtp->evt_listp, &phba->work_list);
  135. lpfc_worker_wake_up(phba);
  136. }
  137. spin_unlock_irq(&phba->hbalock);
  138. return;
  139. }
  140. /*
  141. * This function is called from the worker thread when dev_loss_tmo
  142. * expire.
  143. */
  144. static void
  145. lpfc_dev_loss_tmo_handler(struct lpfc_nodelist *ndlp)
  146. {
  147. struct lpfc_rport_data *rdata;
  148. struct fc_rport *rport;
  149. struct lpfc_vport *vport;
  150. struct lpfc_hba *phba;
  151. uint8_t *name;
  152. int put_node;
  153. int put_rport;
  154. int warn_on = 0;
  155. rport = ndlp->rport;
  156. if (!rport)
  157. return;
  158. rdata = rport->dd_data;
  159. name = (uint8_t *) &ndlp->nlp_portname;
  160. vport = ndlp->vport;
  161. phba = vport->phba;
  162. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
  163. "rport devlosstmo:did:x%x type:x%x id:x%x",
  164. ndlp->nlp_DID, ndlp->nlp_type, rport->scsi_target_id);
  165. /* Don't defer this if we are in the process of deleting the vport
  166. * or unloading the driver. The unload will cleanup the node
  167. * appropriately we just need to cleanup the ndlp rport info here.
  168. */
  169. if (vport->load_flag & FC_UNLOADING) {
  170. if (ndlp->nlp_sid != NLP_NO_SID) {
  171. /* flush the target */
  172. lpfc_sli_abort_iocb(vport,
  173. &phba->sli.ring[phba->sli.fcp_ring],
  174. ndlp->nlp_sid, 0, LPFC_CTX_TGT);
  175. }
  176. put_node = rdata->pnode != NULL;
  177. put_rport = ndlp->rport != NULL;
  178. rdata->pnode = NULL;
  179. ndlp->rport = NULL;
  180. if (put_node)
  181. lpfc_nlp_put(ndlp);
  182. if (put_rport)
  183. put_device(&rport->dev);
  184. return;
  185. }
  186. if (ndlp->nlp_state == NLP_STE_MAPPED_NODE) {
  187. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  188. "0284 Devloss timeout Ignored on "
  189. "WWPN %x:%x:%x:%x:%x:%x:%x:%x "
  190. "NPort x%x\n",
  191. *name, *(name+1), *(name+2), *(name+3),
  192. *(name+4), *(name+5), *(name+6), *(name+7),
  193. ndlp->nlp_DID);
  194. return;
  195. }
  196. if (ndlp->nlp_type & NLP_FABRIC) {
  197. /* We will clean up these Nodes in linkup */
  198. put_node = rdata->pnode != NULL;
  199. put_rport = ndlp->rport != NULL;
  200. rdata->pnode = NULL;
  201. ndlp->rport = NULL;
  202. if (put_node)
  203. lpfc_nlp_put(ndlp);
  204. if (put_rport)
  205. put_device(&rport->dev);
  206. return;
  207. }
  208. if (ndlp->nlp_sid != NLP_NO_SID) {
  209. warn_on = 1;
  210. /* flush the target */
  211. lpfc_sli_abort_iocb(vport, &phba->sli.ring[phba->sli.fcp_ring],
  212. ndlp->nlp_sid, 0, LPFC_CTX_TGT);
  213. }
  214. if (warn_on) {
  215. lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
  216. "0203 Devloss timeout on "
  217. "WWPN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x "
  218. "NPort x%06x Data: x%x x%x x%x\n",
  219. *name, *(name+1), *(name+2), *(name+3),
  220. *(name+4), *(name+5), *(name+6), *(name+7),
  221. ndlp->nlp_DID, ndlp->nlp_flag,
  222. ndlp->nlp_state, ndlp->nlp_rpi);
  223. } else {
  224. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  225. "0204 Devloss timeout on "
  226. "WWPN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x "
  227. "NPort x%06x Data: x%x x%x x%x\n",
  228. *name, *(name+1), *(name+2), *(name+3),
  229. *(name+4), *(name+5), *(name+6), *(name+7),
  230. ndlp->nlp_DID, ndlp->nlp_flag,
  231. ndlp->nlp_state, ndlp->nlp_rpi);
  232. }
  233. put_node = rdata->pnode != NULL;
  234. put_rport = ndlp->rport != NULL;
  235. rdata->pnode = NULL;
  236. ndlp->rport = NULL;
  237. if (put_node)
  238. lpfc_nlp_put(ndlp);
  239. if (put_rport)
  240. put_device(&rport->dev);
  241. if (!(vport->load_flag & FC_UNLOADING) &&
  242. !(ndlp->nlp_flag & NLP_DELAY_TMO) &&
  243. !(ndlp->nlp_flag & NLP_NPR_2B_DISC) &&
  244. (ndlp->nlp_state != NLP_STE_UNMAPPED_NODE))
  245. lpfc_disc_state_machine(vport, ndlp, NULL, NLP_EVT_DEVICE_RM);
  246. lpfc_unregister_unused_fcf(phba);
  247. }
  248. /**
  249. * lpfc_alloc_fast_evt - Allocates data structure for posting event
  250. * @phba: Pointer to hba context object.
  251. *
  252. * This function is called from the functions which need to post
  253. * events from interrupt context. This function allocates data
  254. * structure required for posting event. It also keeps track of
  255. * number of events pending and prevent event storm when there are
  256. * too many events.
  257. **/
  258. struct lpfc_fast_path_event *
  259. lpfc_alloc_fast_evt(struct lpfc_hba *phba) {
  260. struct lpfc_fast_path_event *ret;
  261. /* If there are lot of fast event do not exhaust memory due to this */
  262. if (atomic_read(&phba->fast_event_count) > LPFC_MAX_EVT_COUNT)
  263. return NULL;
  264. ret = kzalloc(sizeof(struct lpfc_fast_path_event),
  265. GFP_ATOMIC);
  266. if (ret) {
  267. atomic_inc(&phba->fast_event_count);
  268. INIT_LIST_HEAD(&ret->work_evt.evt_listp);
  269. ret->work_evt.evt = LPFC_EVT_FASTPATH_MGMT_EVT;
  270. }
  271. return ret;
  272. }
  273. /**
  274. * lpfc_free_fast_evt - Frees event data structure
  275. * @phba: Pointer to hba context object.
  276. * @evt: Event object which need to be freed.
  277. *
  278. * This function frees the data structure required for posting
  279. * events.
  280. **/
  281. void
  282. lpfc_free_fast_evt(struct lpfc_hba *phba,
  283. struct lpfc_fast_path_event *evt) {
  284. atomic_dec(&phba->fast_event_count);
  285. kfree(evt);
  286. }
  287. /**
  288. * lpfc_send_fastpath_evt - Posts events generated from fast path
  289. * @phba: Pointer to hba context object.
  290. * @evtp: Event data structure.
  291. *
  292. * This function is called from worker thread, when the interrupt
  293. * context need to post an event. This function posts the event
  294. * to fc transport netlink interface.
  295. **/
  296. static void
  297. lpfc_send_fastpath_evt(struct lpfc_hba *phba,
  298. struct lpfc_work_evt *evtp)
  299. {
  300. unsigned long evt_category, evt_sub_category;
  301. struct lpfc_fast_path_event *fast_evt_data;
  302. char *evt_data;
  303. uint32_t evt_data_size;
  304. struct Scsi_Host *shost;
  305. fast_evt_data = container_of(evtp, struct lpfc_fast_path_event,
  306. work_evt);
  307. evt_category = (unsigned long) fast_evt_data->un.fabric_evt.event_type;
  308. evt_sub_category = (unsigned long) fast_evt_data->un.
  309. fabric_evt.subcategory;
  310. shost = lpfc_shost_from_vport(fast_evt_data->vport);
  311. if (evt_category == FC_REG_FABRIC_EVENT) {
  312. if (evt_sub_category == LPFC_EVENT_FCPRDCHKERR) {
  313. evt_data = (char *) &fast_evt_data->un.read_check_error;
  314. evt_data_size = sizeof(fast_evt_data->un.
  315. read_check_error);
  316. } else if ((evt_sub_category == LPFC_EVENT_FABRIC_BUSY) ||
  317. (evt_sub_category == LPFC_EVENT_PORT_BUSY)) {
  318. evt_data = (char *) &fast_evt_data->un.fabric_evt;
  319. evt_data_size = sizeof(fast_evt_data->un.fabric_evt);
  320. } else {
  321. lpfc_free_fast_evt(phba, fast_evt_data);
  322. return;
  323. }
  324. } else if (evt_category == FC_REG_SCSI_EVENT) {
  325. switch (evt_sub_category) {
  326. case LPFC_EVENT_QFULL:
  327. case LPFC_EVENT_DEVBSY:
  328. evt_data = (char *) &fast_evt_data->un.scsi_evt;
  329. evt_data_size = sizeof(fast_evt_data->un.scsi_evt);
  330. break;
  331. case LPFC_EVENT_CHECK_COND:
  332. evt_data = (char *) &fast_evt_data->un.check_cond_evt;
  333. evt_data_size = sizeof(fast_evt_data->un.
  334. check_cond_evt);
  335. break;
  336. case LPFC_EVENT_VARQUEDEPTH:
  337. evt_data = (char *) &fast_evt_data->un.queue_depth_evt;
  338. evt_data_size = sizeof(fast_evt_data->un.
  339. queue_depth_evt);
  340. break;
  341. default:
  342. lpfc_free_fast_evt(phba, fast_evt_data);
  343. return;
  344. }
  345. } else {
  346. lpfc_free_fast_evt(phba, fast_evt_data);
  347. return;
  348. }
  349. fc_host_post_vendor_event(shost,
  350. fc_get_event_number(),
  351. evt_data_size,
  352. evt_data,
  353. LPFC_NL_VENDOR_ID);
  354. lpfc_free_fast_evt(phba, fast_evt_data);
  355. return;
  356. }
  357. static void
  358. lpfc_work_list_done(struct lpfc_hba *phba)
  359. {
  360. struct lpfc_work_evt *evtp = NULL;
  361. struct lpfc_nodelist *ndlp;
  362. int free_evt;
  363. spin_lock_irq(&phba->hbalock);
  364. while (!list_empty(&phba->work_list)) {
  365. list_remove_head((&phba->work_list), evtp, typeof(*evtp),
  366. evt_listp);
  367. spin_unlock_irq(&phba->hbalock);
  368. free_evt = 1;
  369. switch (evtp->evt) {
  370. case LPFC_EVT_ELS_RETRY:
  371. ndlp = (struct lpfc_nodelist *) (evtp->evt_arg1);
  372. lpfc_els_retry_delay_handler(ndlp);
  373. free_evt = 0; /* evt is part of ndlp */
  374. /* decrement the node reference count held
  375. * for this queued work
  376. */
  377. lpfc_nlp_put(ndlp);
  378. break;
  379. case LPFC_EVT_DEV_LOSS:
  380. ndlp = (struct lpfc_nodelist *)(evtp->evt_arg1);
  381. lpfc_dev_loss_tmo_handler(ndlp);
  382. free_evt = 0;
  383. /* decrement the node reference count held for
  384. * this queued work
  385. */
  386. lpfc_nlp_put(ndlp);
  387. break;
  388. case LPFC_EVT_ONLINE:
  389. if (phba->link_state < LPFC_LINK_DOWN)
  390. *(int *) (evtp->evt_arg1) = lpfc_online(phba);
  391. else
  392. *(int *) (evtp->evt_arg1) = 0;
  393. complete((struct completion *)(evtp->evt_arg2));
  394. break;
  395. case LPFC_EVT_OFFLINE_PREP:
  396. if (phba->link_state >= LPFC_LINK_DOWN)
  397. lpfc_offline_prep(phba);
  398. *(int *)(evtp->evt_arg1) = 0;
  399. complete((struct completion *)(evtp->evt_arg2));
  400. break;
  401. case LPFC_EVT_OFFLINE:
  402. lpfc_offline(phba);
  403. lpfc_sli_brdrestart(phba);
  404. *(int *)(evtp->evt_arg1) =
  405. lpfc_sli_brdready(phba, HS_FFRDY | HS_MBRDY);
  406. lpfc_unblock_mgmt_io(phba);
  407. complete((struct completion *)(evtp->evt_arg2));
  408. break;
  409. case LPFC_EVT_WARM_START:
  410. lpfc_offline(phba);
  411. lpfc_reset_barrier(phba);
  412. lpfc_sli_brdreset(phba);
  413. lpfc_hba_down_post(phba);
  414. *(int *)(evtp->evt_arg1) =
  415. lpfc_sli_brdready(phba, HS_MBRDY);
  416. lpfc_unblock_mgmt_io(phba);
  417. complete((struct completion *)(evtp->evt_arg2));
  418. break;
  419. case LPFC_EVT_KILL:
  420. lpfc_offline(phba);
  421. *(int *)(evtp->evt_arg1)
  422. = (phba->pport->stopped)
  423. ? 0 : lpfc_sli_brdkill(phba);
  424. lpfc_unblock_mgmt_io(phba);
  425. complete((struct completion *)(evtp->evt_arg2));
  426. break;
  427. case LPFC_EVT_FASTPATH_MGMT_EVT:
  428. lpfc_send_fastpath_evt(phba, evtp);
  429. free_evt = 0;
  430. break;
  431. }
  432. if (free_evt)
  433. kfree(evtp);
  434. spin_lock_irq(&phba->hbalock);
  435. }
  436. spin_unlock_irq(&phba->hbalock);
  437. }
  438. static void
  439. lpfc_work_done(struct lpfc_hba *phba)
  440. {
  441. struct lpfc_sli_ring *pring;
  442. uint32_t ha_copy, status, control, work_port_events;
  443. struct lpfc_vport **vports;
  444. struct lpfc_vport *vport;
  445. int i;
  446. spin_lock_irq(&phba->hbalock);
  447. ha_copy = phba->work_ha;
  448. phba->work_ha = 0;
  449. spin_unlock_irq(&phba->hbalock);
  450. /* First, try to post the next mailbox command to SLI4 device */
  451. if (phba->pci_dev_grp == LPFC_PCI_DEV_OC)
  452. lpfc_sli4_post_async_mbox(phba);
  453. if (ha_copy & HA_ERATT)
  454. /* Handle the error attention event */
  455. lpfc_handle_eratt(phba);
  456. if (ha_copy & HA_MBATT)
  457. lpfc_sli_handle_mb_event(phba);
  458. if (ha_copy & HA_LATT)
  459. lpfc_handle_latt(phba);
  460. /* Process SLI4 events */
  461. if (phba->pci_dev_grp == LPFC_PCI_DEV_OC) {
  462. if (phba->hba_flag & FCP_XRI_ABORT_EVENT)
  463. lpfc_sli4_fcp_xri_abort_event_proc(phba);
  464. if (phba->hba_flag & ELS_XRI_ABORT_EVENT)
  465. lpfc_sli4_els_xri_abort_event_proc(phba);
  466. if (phba->hba_flag & ASYNC_EVENT)
  467. lpfc_sli4_async_event_proc(phba);
  468. if (phba->hba_flag & HBA_POST_RECEIVE_BUFFER) {
  469. spin_lock_irq(&phba->hbalock);
  470. phba->hba_flag &= ~HBA_POST_RECEIVE_BUFFER;
  471. spin_unlock_irq(&phba->hbalock);
  472. lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
  473. }
  474. }
  475. vports = lpfc_create_vport_work_array(phba);
  476. if (vports != NULL)
  477. for (i = 0; i <= phba->max_vports; i++) {
  478. /*
  479. * We could have no vports in array if unloading, so if
  480. * this happens then just use the pport
  481. */
  482. if (vports[i] == NULL && i == 0)
  483. vport = phba->pport;
  484. else
  485. vport = vports[i];
  486. if (vport == NULL)
  487. break;
  488. spin_lock_irq(&vport->work_port_lock);
  489. work_port_events = vport->work_port_events;
  490. vport->work_port_events &= ~work_port_events;
  491. spin_unlock_irq(&vport->work_port_lock);
  492. if (work_port_events & WORKER_DISC_TMO)
  493. lpfc_disc_timeout_handler(vport);
  494. if (work_port_events & WORKER_ELS_TMO)
  495. lpfc_els_timeout_handler(vport);
  496. if (work_port_events & WORKER_HB_TMO)
  497. lpfc_hb_timeout_handler(phba);
  498. if (work_port_events & WORKER_MBOX_TMO)
  499. lpfc_mbox_timeout_handler(phba);
  500. if (work_port_events & WORKER_FABRIC_BLOCK_TMO)
  501. lpfc_unblock_fabric_iocbs(phba);
  502. if (work_port_events & WORKER_FDMI_TMO)
  503. lpfc_fdmi_timeout_handler(vport);
  504. if (work_port_events & WORKER_RAMP_DOWN_QUEUE)
  505. lpfc_ramp_down_queue_handler(phba);
  506. if (work_port_events & WORKER_RAMP_UP_QUEUE)
  507. lpfc_ramp_up_queue_handler(phba);
  508. }
  509. lpfc_destroy_vport_work_array(phba, vports);
  510. pring = &phba->sli.ring[LPFC_ELS_RING];
  511. status = (ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING)));
  512. status >>= (4*LPFC_ELS_RING);
  513. if ((status & HA_RXMASK) ||
  514. (pring->flag & LPFC_DEFERRED_RING_EVENT) ||
  515. (phba->hba_flag & HBA_SP_QUEUE_EVT)) {
  516. if (pring->flag & LPFC_STOP_IOCB_EVENT) {
  517. pring->flag |= LPFC_DEFERRED_RING_EVENT;
  518. /* Set the lpfc data pending flag */
  519. set_bit(LPFC_DATA_READY, &phba->data_flags);
  520. } else {
  521. pring->flag &= ~LPFC_DEFERRED_RING_EVENT;
  522. lpfc_sli_handle_slow_ring_event(phba, pring,
  523. (status &
  524. HA_RXMASK));
  525. }
  526. /*
  527. * Turn on Ring interrupts
  528. */
  529. if (phba->sli_rev <= LPFC_SLI_REV3) {
  530. spin_lock_irq(&phba->hbalock);
  531. control = readl(phba->HCregaddr);
  532. if (!(control & (HC_R0INT_ENA << LPFC_ELS_RING))) {
  533. lpfc_debugfs_slow_ring_trc(phba,
  534. "WRK Enable ring: cntl:x%x hacopy:x%x",
  535. control, ha_copy, 0);
  536. control |= (HC_R0INT_ENA << LPFC_ELS_RING);
  537. writel(control, phba->HCregaddr);
  538. readl(phba->HCregaddr); /* flush */
  539. } else {
  540. lpfc_debugfs_slow_ring_trc(phba,
  541. "WRK Ring ok: cntl:x%x hacopy:x%x",
  542. control, ha_copy, 0);
  543. }
  544. spin_unlock_irq(&phba->hbalock);
  545. }
  546. }
  547. lpfc_work_list_done(phba);
  548. }
  549. int
  550. lpfc_do_work(void *p)
  551. {
  552. struct lpfc_hba *phba = p;
  553. int rc;
  554. set_user_nice(current, -20);
  555. phba->data_flags = 0;
  556. while (!kthread_should_stop()) {
  557. /* wait and check worker queue activities */
  558. rc = wait_event_interruptible(phba->work_waitq,
  559. (test_and_clear_bit(LPFC_DATA_READY,
  560. &phba->data_flags)
  561. || kthread_should_stop()));
  562. /* Signal wakeup shall terminate the worker thread */
  563. if (rc) {
  564. lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
  565. "0433 Wakeup on signal: rc=x%x\n", rc);
  566. break;
  567. }
  568. /* Attend pending lpfc data processing */
  569. lpfc_work_done(phba);
  570. }
  571. phba->worker_thread = NULL;
  572. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  573. "0432 Worker thread stopped.\n");
  574. return 0;
  575. }
  576. /*
  577. * This is only called to handle FC worker events. Since this a rare
  578. * occurance, we allocate a struct lpfc_work_evt structure here instead of
  579. * embedding it in the IOCB.
  580. */
  581. int
  582. lpfc_workq_post_event(struct lpfc_hba *phba, void *arg1, void *arg2,
  583. uint32_t evt)
  584. {
  585. struct lpfc_work_evt *evtp;
  586. unsigned long flags;
  587. /*
  588. * All Mailbox completions and LPFC_ELS_RING rcv ring IOCB events will
  589. * be queued to worker thread for processing
  590. */
  591. evtp = kmalloc(sizeof(struct lpfc_work_evt), GFP_ATOMIC);
  592. if (!evtp)
  593. return 0;
  594. evtp->evt_arg1 = arg1;
  595. evtp->evt_arg2 = arg2;
  596. evtp->evt = evt;
  597. spin_lock_irqsave(&phba->hbalock, flags);
  598. list_add_tail(&evtp->evt_listp, &phba->work_list);
  599. spin_unlock_irqrestore(&phba->hbalock, flags);
  600. lpfc_worker_wake_up(phba);
  601. return 1;
  602. }
  603. void
  604. lpfc_cleanup_rpis(struct lpfc_vport *vport, int remove)
  605. {
  606. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  607. struct lpfc_hba *phba = vport->phba;
  608. struct lpfc_nodelist *ndlp, *next_ndlp;
  609. int rc;
  610. list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
  611. if (!NLP_CHK_NODE_ACT(ndlp))
  612. continue;
  613. if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
  614. continue;
  615. if ((phba->sli3_options & LPFC_SLI3_VPORT_TEARDOWN) ||
  616. ((vport->port_type == LPFC_NPIV_PORT) &&
  617. (ndlp->nlp_DID == NameServer_DID)))
  618. lpfc_unreg_rpi(vport, ndlp);
  619. /* Leave Fabric nodes alone on link down */
  620. if ((phba->sli_rev < LPFC_SLI_REV4) &&
  621. (!remove && ndlp->nlp_type & NLP_FABRIC))
  622. continue;
  623. rc = lpfc_disc_state_machine(vport, ndlp, NULL,
  624. remove
  625. ? NLP_EVT_DEVICE_RM
  626. : NLP_EVT_DEVICE_RECOVERY);
  627. }
  628. if (phba->sli3_options & LPFC_SLI3_VPORT_TEARDOWN) {
  629. lpfc_mbx_unreg_vpi(vport);
  630. spin_lock_irq(shost->host_lock);
  631. vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
  632. spin_unlock_irq(shost->host_lock);
  633. }
  634. }
  635. void
  636. lpfc_port_link_failure(struct lpfc_vport *vport)
  637. {
  638. /* Cleanup any outstanding received buffers */
  639. lpfc_cleanup_rcv_buffers(vport);
  640. /* Cleanup any outstanding RSCN activity */
  641. lpfc_els_flush_rscn(vport);
  642. /* Cleanup any outstanding ELS commands */
  643. lpfc_els_flush_cmd(vport);
  644. lpfc_cleanup_rpis(vport, 0);
  645. /* Turn off discovery timer if its running */
  646. lpfc_can_disctmo(vport);
  647. }
  648. void
  649. lpfc_linkdown_port(struct lpfc_vport *vport)
  650. {
  651. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  652. fc_host_post_event(shost, fc_get_event_number(), FCH_EVT_LINKDOWN, 0);
  653. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  654. "Link Down: state:x%x rtry:x%x flg:x%x",
  655. vport->port_state, vport->fc_ns_retry, vport->fc_flag);
  656. lpfc_port_link_failure(vport);
  657. }
  658. int
  659. lpfc_linkdown(struct lpfc_hba *phba)
  660. {
  661. struct lpfc_vport *vport = phba->pport;
  662. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  663. struct lpfc_vport **vports;
  664. LPFC_MBOXQ_t *mb;
  665. int i;
  666. if (phba->link_state == LPFC_LINK_DOWN)
  667. return 0;
  668. spin_lock_irq(&phba->hbalock);
  669. phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_DISCOVERED);
  670. if (phba->link_state > LPFC_LINK_DOWN) {
  671. phba->link_state = LPFC_LINK_DOWN;
  672. phba->pport->fc_flag &= ~FC_LBIT;
  673. }
  674. spin_unlock_irq(&phba->hbalock);
  675. vports = lpfc_create_vport_work_array(phba);
  676. if (vports != NULL)
  677. for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
  678. /* Issue a LINK DOWN event to all nodes */
  679. lpfc_linkdown_port(vports[i]);
  680. }
  681. lpfc_destroy_vport_work_array(phba, vports);
  682. /* Clean up any firmware default rpi's */
  683. mb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  684. if (mb) {
  685. lpfc_unreg_did(phba, 0xffff, 0xffffffff, mb);
  686. mb->vport = vport;
  687. mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  688. if (lpfc_sli_issue_mbox(phba, mb, MBX_NOWAIT)
  689. == MBX_NOT_FINISHED) {
  690. mempool_free(mb, phba->mbox_mem_pool);
  691. }
  692. }
  693. /* Setup myDID for link up if we are in pt2pt mode */
  694. if (phba->pport->fc_flag & FC_PT2PT) {
  695. phba->pport->fc_myDID = 0;
  696. mb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  697. if (mb) {
  698. lpfc_config_link(phba, mb);
  699. mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  700. mb->vport = vport;
  701. if (lpfc_sli_issue_mbox(phba, mb, MBX_NOWAIT)
  702. == MBX_NOT_FINISHED) {
  703. mempool_free(mb, phba->mbox_mem_pool);
  704. }
  705. }
  706. spin_lock_irq(shost->host_lock);
  707. phba->pport->fc_flag &= ~(FC_PT2PT | FC_PT2PT_PLOGI);
  708. spin_unlock_irq(shost->host_lock);
  709. }
  710. return 0;
  711. }
  712. static void
  713. lpfc_linkup_cleanup_nodes(struct lpfc_vport *vport)
  714. {
  715. struct lpfc_nodelist *ndlp;
  716. list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
  717. if (!NLP_CHK_NODE_ACT(ndlp))
  718. continue;
  719. if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
  720. continue;
  721. if (ndlp->nlp_type & NLP_FABRIC) {
  722. /* On Linkup its safe to clean up the ndlp
  723. * from Fabric connections.
  724. */
  725. if (ndlp->nlp_DID != Fabric_DID)
  726. lpfc_unreg_rpi(vport, ndlp);
  727. lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
  728. } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
  729. /* Fail outstanding IO now since device is
  730. * marked for PLOGI.
  731. */
  732. lpfc_unreg_rpi(vport, ndlp);
  733. }
  734. }
  735. }
  736. static void
  737. lpfc_linkup_port(struct lpfc_vport *vport)
  738. {
  739. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  740. struct lpfc_hba *phba = vport->phba;
  741. if ((vport->load_flag & FC_UNLOADING) != 0)
  742. return;
  743. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  744. "Link Up: top:x%x speed:x%x flg:x%x",
  745. phba->fc_topology, phba->fc_linkspeed, phba->link_flag);
  746. /* If NPIV is not enabled, only bring the physical port up */
  747. if (!(phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
  748. (vport != phba->pport))
  749. return;
  750. fc_host_post_event(shost, fc_get_event_number(), FCH_EVT_LINKUP, 0);
  751. spin_lock_irq(shost->host_lock);
  752. vport->fc_flag &= ~(FC_PT2PT | FC_PT2PT_PLOGI | FC_ABORT_DISCOVERY |
  753. FC_RSCN_MODE | FC_NLP_MORE | FC_RSCN_DISCOVERY);
  754. vport->fc_flag |= FC_NDISC_ACTIVE;
  755. vport->fc_ns_retry = 0;
  756. spin_unlock_irq(shost->host_lock);
  757. if (vport->fc_flag & FC_LBIT)
  758. lpfc_linkup_cleanup_nodes(vport);
  759. }
  760. static int
  761. lpfc_linkup(struct lpfc_hba *phba)
  762. {
  763. struct lpfc_vport **vports;
  764. int i;
  765. phba->link_state = LPFC_LINK_UP;
  766. /* Unblock fabric iocbs if they are blocked */
  767. clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
  768. del_timer_sync(&phba->fabric_block_timer);
  769. vports = lpfc_create_vport_work_array(phba);
  770. if (vports != NULL)
  771. for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++)
  772. lpfc_linkup_port(vports[i]);
  773. lpfc_destroy_vport_work_array(phba, vports);
  774. if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
  775. (phba->sli_rev < LPFC_SLI_REV4))
  776. lpfc_issue_clear_la(phba, phba->pport);
  777. return 0;
  778. }
  779. /*
  780. * This routine handles processing a CLEAR_LA mailbox
  781. * command upon completion. It is setup in the LPFC_MBOXQ
  782. * as the completion routine when the command is
  783. * handed off to the SLI layer.
  784. */
  785. static void
  786. lpfc_mbx_cmpl_clear_la(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  787. {
  788. struct lpfc_vport *vport = pmb->vport;
  789. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  790. struct lpfc_sli *psli = &phba->sli;
  791. MAILBOX_t *mb = &pmb->u.mb;
  792. uint32_t control;
  793. /* Since we don't do discovery right now, turn these off here */
  794. psli->ring[psli->extra_ring].flag &= ~LPFC_STOP_IOCB_EVENT;
  795. psli->ring[psli->fcp_ring].flag &= ~LPFC_STOP_IOCB_EVENT;
  796. psli->ring[psli->next_ring].flag &= ~LPFC_STOP_IOCB_EVENT;
  797. /* Check for error */
  798. if ((mb->mbxStatus) && (mb->mbxStatus != 0x1601)) {
  799. /* CLEAR_LA mbox error <mbxStatus> state <hba_state> */
  800. lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
  801. "0320 CLEAR_LA mbxStatus error x%x hba "
  802. "state x%x\n",
  803. mb->mbxStatus, vport->port_state);
  804. phba->link_state = LPFC_HBA_ERROR;
  805. goto out;
  806. }
  807. if (vport->port_type == LPFC_PHYSICAL_PORT)
  808. phba->link_state = LPFC_HBA_READY;
  809. spin_lock_irq(&phba->hbalock);
  810. psli->sli_flag |= LPFC_PROCESS_LA;
  811. control = readl(phba->HCregaddr);
  812. control |= HC_LAINT_ENA;
  813. writel(control, phba->HCregaddr);
  814. readl(phba->HCregaddr); /* flush */
  815. spin_unlock_irq(&phba->hbalock);
  816. mempool_free(pmb, phba->mbox_mem_pool);
  817. return;
  818. out:
  819. /* Device Discovery completes */
  820. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  821. "0225 Device Discovery completes\n");
  822. mempool_free(pmb, phba->mbox_mem_pool);
  823. spin_lock_irq(shost->host_lock);
  824. vport->fc_flag &= ~FC_ABORT_DISCOVERY;
  825. spin_unlock_irq(shost->host_lock);
  826. lpfc_can_disctmo(vport);
  827. /* turn on Link Attention interrupts */
  828. spin_lock_irq(&phba->hbalock);
  829. psli->sli_flag |= LPFC_PROCESS_LA;
  830. control = readl(phba->HCregaddr);
  831. control |= HC_LAINT_ENA;
  832. writel(control, phba->HCregaddr);
  833. readl(phba->HCregaddr); /* flush */
  834. spin_unlock_irq(&phba->hbalock);
  835. return;
  836. }
  837. static void
  838. lpfc_mbx_cmpl_local_config_link(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  839. {
  840. struct lpfc_vport *vport = pmb->vport;
  841. if (pmb->u.mb.mbxStatus)
  842. goto out;
  843. mempool_free(pmb, phba->mbox_mem_pool);
  844. if (phba->fc_topology == TOPOLOGY_LOOP &&
  845. vport->fc_flag & FC_PUBLIC_LOOP &&
  846. !(vport->fc_flag & FC_LBIT)) {
  847. /* Need to wait for FAN - use discovery timer
  848. * for timeout. port_state is identically
  849. * LPFC_LOCAL_CFG_LINK while waiting for FAN
  850. */
  851. lpfc_set_disctmo(vport);
  852. return;
  853. }
  854. /* Start discovery by sending a FLOGI. port_state is identically
  855. * LPFC_FLOGI while waiting for FLOGI cmpl
  856. */
  857. if (vport->port_state != LPFC_FLOGI) {
  858. lpfc_initial_flogi(vport);
  859. }
  860. return;
  861. out:
  862. lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
  863. "0306 CONFIG_LINK mbxStatus error x%x "
  864. "HBA state x%x\n",
  865. pmb->u.mb.mbxStatus, vport->port_state);
  866. mempool_free(pmb, phba->mbox_mem_pool);
  867. lpfc_linkdown(phba);
  868. lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
  869. "0200 CONFIG_LINK bad hba state x%x\n",
  870. vport->port_state);
  871. lpfc_issue_clear_la(phba, vport);
  872. return;
  873. }
  874. static void
  875. lpfc_mbx_cmpl_reg_fcfi(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  876. {
  877. struct lpfc_vport *vport = mboxq->vport;
  878. unsigned long flags;
  879. if (mboxq->u.mb.mbxStatus) {
  880. lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
  881. "2017 REG_FCFI mbxStatus error x%x "
  882. "HBA state x%x\n",
  883. mboxq->u.mb.mbxStatus, vport->port_state);
  884. mempool_free(mboxq, phba->mbox_mem_pool);
  885. return;
  886. }
  887. /* Start FCoE discovery by sending a FLOGI. */
  888. phba->fcf.fcfi = bf_get(lpfc_reg_fcfi_fcfi, &mboxq->u.mqe.un.reg_fcfi);
  889. /* Set the FCFI registered flag */
  890. spin_lock_irqsave(&phba->hbalock, flags);
  891. phba->fcf.fcf_flag |= FCF_REGISTERED;
  892. spin_unlock_irqrestore(&phba->hbalock, flags);
  893. /* If there is a pending FCoE event, restart FCF table scan. */
  894. if (lpfc_check_pending_fcoe_event(phba, 1)) {
  895. mempool_free(mboxq, phba->mbox_mem_pool);
  896. return;
  897. }
  898. spin_lock_irqsave(&phba->hbalock, flags);
  899. phba->fcf.fcf_flag |= (FCF_DISCOVERED | FCF_IN_USE);
  900. phba->hba_flag &= ~FCF_DISC_INPROGRESS;
  901. spin_unlock_irqrestore(&phba->hbalock, flags);
  902. if (vport->port_state != LPFC_FLOGI)
  903. lpfc_initial_flogi(vport);
  904. mempool_free(mboxq, phba->mbox_mem_pool);
  905. return;
  906. }
  907. /**
  908. * lpfc_fab_name_match - Check if the fcf fabric name match.
  909. * @fab_name: pointer to fabric name.
  910. * @new_fcf_record: pointer to fcf record.
  911. *
  912. * This routine compare the fcf record's fabric name with provided
  913. * fabric name. If the fabric name are identical this function
  914. * returns 1 else return 0.
  915. **/
  916. static uint32_t
  917. lpfc_fab_name_match(uint8_t *fab_name, struct fcf_record *new_fcf_record)
  918. {
  919. if ((fab_name[0] ==
  920. bf_get(lpfc_fcf_record_fab_name_0, new_fcf_record)) &&
  921. (fab_name[1] ==
  922. bf_get(lpfc_fcf_record_fab_name_1, new_fcf_record)) &&
  923. (fab_name[2] ==
  924. bf_get(lpfc_fcf_record_fab_name_2, new_fcf_record)) &&
  925. (fab_name[3] ==
  926. bf_get(lpfc_fcf_record_fab_name_3, new_fcf_record)) &&
  927. (fab_name[4] ==
  928. bf_get(lpfc_fcf_record_fab_name_4, new_fcf_record)) &&
  929. (fab_name[5] ==
  930. bf_get(lpfc_fcf_record_fab_name_5, new_fcf_record)) &&
  931. (fab_name[6] ==
  932. bf_get(lpfc_fcf_record_fab_name_6, new_fcf_record)) &&
  933. (fab_name[7] ==
  934. bf_get(lpfc_fcf_record_fab_name_7, new_fcf_record)))
  935. return 1;
  936. else
  937. return 0;
  938. }
  939. /**
  940. * lpfc_sw_name_match - Check if the fcf switch name match.
  941. * @fab_name: pointer to fabric name.
  942. * @new_fcf_record: pointer to fcf record.
  943. *
  944. * This routine compare the fcf record's switch name with provided
  945. * switch name. If the switch name are identical this function
  946. * returns 1 else return 0.
  947. **/
  948. static uint32_t
  949. lpfc_sw_name_match(uint8_t *sw_name, struct fcf_record *new_fcf_record)
  950. {
  951. if ((sw_name[0] ==
  952. bf_get(lpfc_fcf_record_switch_name_0, new_fcf_record)) &&
  953. (sw_name[1] ==
  954. bf_get(lpfc_fcf_record_switch_name_1, new_fcf_record)) &&
  955. (sw_name[2] ==
  956. bf_get(lpfc_fcf_record_switch_name_2, new_fcf_record)) &&
  957. (sw_name[3] ==
  958. bf_get(lpfc_fcf_record_switch_name_3, new_fcf_record)) &&
  959. (sw_name[4] ==
  960. bf_get(lpfc_fcf_record_switch_name_4, new_fcf_record)) &&
  961. (sw_name[5] ==
  962. bf_get(lpfc_fcf_record_switch_name_5, new_fcf_record)) &&
  963. (sw_name[6] ==
  964. bf_get(lpfc_fcf_record_switch_name_6, new_fcf_record)) &&
  965. (sw_name[7] ==
  966. bf_get(lpfc_fcf_record_switch_name_7, new_fcf_record)))
  967. return 1;
  968. else
  969. return 0;
  970. }
  971. /**
  972. * lpfc_mac_addr_match - Check if the fcf mac address match.
  973. * @phba: pointer to lpfc hba data structure.
  974. * @new_fcf_record: pointer to fcf record.
  975. *
  976. * This routine compare the fcf record's mac address with HBA's
  977. * FCF mac address. If the mac addresses are identical this function
  978. * returns 1 else return 0.
  979. **/
  980. static uint32_t
  981. lpfc_mac_addr_match(struct lpfc_hba *phba, struct fcf_record *new_fcf_record)
  982. {
  983. if ((phba->fcf.mac_addr[0] ==
  984. bf_get(lpfc_fcf_record_mac_0, new_fcf_record)) &&
  985. (phba->fcf.mac_addr[1] ==
  986. bf_get(lpfc_fcf_record_mac_1, new_fcf_record)) &&
  987. (phba->fcf.mac_addr[2] ==
  988. bf_get(lpfc_fcf_record_mac_2, new_fcf_record)) &&
  989. (phba->fcf.mac_addr[3] ==
  990. bf_get(lpfc_fcf_record_mac_3, new_fcf_record)) &&
  991. (phba->fcf.mac_addr[4] ==
  992. bf_get(lpfc_fcf_record_mac_4, new_fcf_record)) &&
  993. (phba->fcf.mac_addr[5] ==
  994. bf_get(lpfc_fcf_record_mac_5, new_fcf_record)))
  995. return 1;
  996. else
  997. return 0;
  998. }
  999. /**
  1000. * lpfc_copy_fcf_record - Copy fcf information to lpfc_hba.
  1001. * @phba: pointer to lpfc hba data structure.
  1002. * @new_fcf_record: pointer to fcf record.
  1003. *
  1004. * This routine copies the FCF information from the FCF
  1005. * record to lpfc_hba data structure.
  1006. **/
  1007. static void
  1008. lpfc_copy_fcf_record(struct lpfc_hba *phba, struct fcf_record *new_fcf_record)
  1009. {
  1010. phba->fcf.fabric_name[0] =
  1011. bf_get(lpfc_fcf_record_fab_name_0, new_fcf_record);
  1012. phba->fcf.fabric_name[1] =
  1013. bf_get(lpfc_fcf_record_fab_name_1, new_fcf_record);
  1014. phba->fcf.fabric_name[2] =
  1015. bf_get(lpfc_fcf_record_fab_name_2, new_fcf_record);
  1016. phba->fcf.fabric_name[3] =
  1017. bf_get(lpfc_fcf_record_fab_name_3, new_fcf_record);
  1018. phba->fcf.fabric_name[4] =
  1019. bf_get(lpfc_fcf_record_fab_name_4, new_fcf_record);
  1020. phba->fcf.fabric_name[5] =
  1021. bf_get(lpfc_fcf_record_fab_name_5, new_fcf_record);
  1022. phba->fcf.fabric_name[6] =
  1023. bf_get(lpfc_fcf_record_fab_name_6, new_fcf_record);
  1024. phba->fcf.fabric_name[7] =
  1025. bf_get(lpfc_fcf_record_fab_name_7, new_fcf_record);
  1026. phba->fcf.mac_addr[0] =
  1027. bf_get(lpfc_fcf_record_mac_0, new_fcf_record);
  1028. phba->fcf.mac_addr[1] =
  1029. bf_get(lpfc_fcf_record_mac_1, new_fcf_record);
  1030. phba->fcf.mac_addr[2] =
  1031. bf_get(lpfc_fcf_record_mac_2, new_fcf_record);
  1032. phba->fcf.mac_addr[3] =
  1033. bf_get(lpfc_fcf_record_mac_3, new_fcf_record);
  1034. phba->fcf.mac_addr[4] =
  1035. bf_get(lpfc_fcf_record_mac_4, new_fcf_record);
  1036. phba->fcf.mac_addr[5] =
  1037. bf_get(lpfc_fcf_record_mac_5, new_fcf_record);
  1038. phba->fcf.fcf_indx = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record);
  1039. phba->fcf.priority = new_fcf_record->fip_priority;
  1040. phba->fcf.switch_name[0] =
  1041. bf_get(lpfc_fcf_record_switch_name_0, new_fcf_record);
  1042. phba->fcf.switch_name[1] =
  1043. bf_get(lpfc_fcf_record_switch_name_1, new_fcf_record);
  1044. phba->fcf.switch_name[2] =
  1045. bf_get(lpfc_fcf_record_switch_name_2, new_fcf_record);
  1046. phba->fcf.switch_name[3] =
  1047. bf_get(lpfc_fcf_record_switch_name_3, new_fcf_record);
  1048. phba->fcf.switch_name[4] =
  1049. bf_get(lpfc_fcf_record_switch_name_4, new_fcf_record);
  1050. phba->fcf.switch_name[5] =
  1051. bf_get(lpfc_fcf_record_switch_name_5, new_fcf_record);
  1052. phba->fcf.switch_name[6] =
  1053. bf_get(lpfc_fcf_record_switch_name_6, new_fcf_record);
  1054. phba->fcf.switch_name[7] =
  1055. bf_get(lpfc_fcf_record_switch_name_7, new_fcf_record);
  1056. }
  1057. /**
  1058. * lpfc_register_fcf - Register the FCF with hba.
  1059. * @phba: pointer to lpfc hba data structure.
  1060. *
  1061. * This routine issues a register fcfi mailbox command to register
  1062. * the fcf with HBA.
  1063. **/
  1064. static void
  1065. lpfc_register_fcf(struct lpfc_hba *phba)
  1066. {
  1067. LPFC_MBOXQ_t *fcf_mbxq;
  1068. int rc;
  1069. unsigned long flags;
  1070. spin_lock_irqsave(&phba->hbalock, flags);
  1071. /* If the FCF is not availabe do nothing. */
  1072. if (!(phba->fcf.fcf_flag & FCF_AVAILABLE)) {
  1073. phba->hba_flag &= ~FCF_DISC_INPROGRESS;
  1074. spin_unlock_irqrestore(&phba->hbalock, flags);
  1075. return;
  1076. }
  1077. /* The FCF is already registered, start discovery */
  1078. if (phba->fcf.fcf_flag & FCF_REGISTERED) {
  1079. phba->fcf.fcf_flag |= (FCF_DISCOVERED | FCF_IN_USE);
  1080. phba->hba_flag &= ~FCF_DISC_INPROGRESS;
  1081. spin_unlock_irqrestore(&phba->hbalock, flags);
  1082. if (phba->pport->port_state != LPFC_FLOGI)
  1083. lpfc_initial_flogi(phba->pport);
  1084. return;
  1085. }
  1086. spin_unlock_irqrestore(&phba->hbalock, flags);
  1087. fcf_mbxq = mempool_alloc(phba->mbox_mem_pool,
  1088. GFP_KERNEL);
  1089. if (!fcf_mbxq) {
  1090. spin_lock_irqsave(&phba->hbalock, flags);
  1091. phba->hba_flag &= ~FCF_DISC_INPROGRESS;
  1092. spin_unlock_irqrestore(&phba->hbalock, flags);
  1093. return;
  1094. }
  1095. lpfc_reg_fcfi(phba, fcf_mbxq);
  1096. fcf_mbxq->vport = phba->pport;
  1097. fcf_mbxq->mbox_cmpl = lpfc_mbx_cmpl_reg_fcfi;
  1098. rc = lpfc_sli_issue_mbox(phba, fcf_mbxq, MBX_NOWAIT);
  1099. if (rc == MBX_NOT_FINISHED) {
  1100. spin_lock_irqsave(&phba->hbalock, flags);
  1101. phba->hba_flag &= ~FCF_DISC_INPROGRESS;
  1102. spin_unlock_irqrestore(&phba->hbalock, flags);
  1103. mempool_free(fcf_mbxq, phba->mbox_mem_pool);
  1104. }
  1105. return;
  1106. }
  1107. /**
  1108. * lpfc_match_fcf_conn_list - Check if the FCF record can be used for discovery.
  1109. * @phba: pointer to lpfc hba data structure.
  1110. * @new_fcf_record: pointer to fcf record.
  1111. * @boot_flag: Indicates if this record used by boot bios.
  1112. * @addr_mode: The address mode to be used by this FCF
  1113. *
  1114. * This routine compare the fcf record with connect list obtained from the
  1115. * config region to decide if this FCF can be used for SAN discovery. It returns
  1116. * 1 if this record can be used for SAN discovery else return zero. If this FCF
  1117. * record can be used for SAN discovery, the boot_flag will indicate if this FCF
  1118. * is used by boot bios and addr_mode will indicate the addressing mode to be
  1119. * used for this FCF when the function returns.
  1120. * If the FCF record need to be used with a particular vlan id, the vlan is
  1121. * set in the vlan_id on return of the function. If not VLAN tagging need to
  1122. * be used with the FCF vlan_id will be set to 0xFFFF;
  1123. **/
  1124. static int
  1125. lpfc_match_fcf_conn_list(struct lpfc_hba *phba,
  1126. struct fcf_record *new_fcf_record,
  1127. uint32_t *boot_flag, uint32_t *addr_mode,
  1128. uint16_t *vlan_id)
  1129. {
  1130. struct lpfc_fcf_conn_entry *conn_entry;
  1131. int i, j, fcf_vlan_id = 0;
  1132. /* Find the lowest VLAN id in the FCF record */
  1133. for (i = 0; i < 512; i++) {
  1134. if (new_fcf_record->vlan_bitmap[i]) {
  1135. fcf_vlan_id = i * 8;
  1136. j = 0;
  1137. while (!((new_fcf_record->vlan_bitmap[i] >> j) & 1)) {
  1138. j++;
  1139. fcf_vlan_id++;
  1140. }
  1141. break;
  1142. }
  1143. }
  1144. /* If FCF not available return 0 */
  1145. if (!bf_get(lpfc_fcf_record_fcf_avail, new_fcf_record) ||
  1146. !bf_get(lpfc_fcf_record_fcf_valid, new_fcf_record))
  1147. return 0;
  1148. if (!(phba->hba_flag & HBA_FIP_SUPPORT)) {
  1149. *boot_flag = 0;
  1150. *addr_mode = bf_get(lpfc_fcf_record_mac_addr_prov,
  1151. new_fcf_record);
  1152. if (phba->valid_vlan)
  1153. *vlan_id = phba->vlan_id;
  1154. else
  1155. *vlan_id = 0xFFFF;
  1156. return 1;
  1157. }
  1158. /*
  1159. * If there are no FCF connection table entry, driver connect to all
  1160. * FCFs.
  1161. */
  1162. if (list_empty(&phba->fcf_conn_rec_list)) {
  1163. *boot_flag = 0;
  1164. *addr_mode = bf_get(lpfc_fcf_record_mac_addr_prov,
  1165. new_fcf_record);
  1166. /*
  1167. * When there are no FCF connect entries, use driver's default
  1168. * addressing mode - FPMA.
  1169. */
  1170. if (*addr_mode & LPFC_FCF_FPMA)
  1171. *addr_mode = LPFC_FCF_FPMA;
  1172. /* If FCF record report a vlan id use that vlan id */
  1173. if (fcf_vlan_id)
  1174. *vlan_id = fcf_vlan_id;
  1175. else
  1176. *vlan_id = 0xFFFF;
  1177. return 1;
  1178. }
  1179. list_for_each_entry(conn_entry, &phba->fcf_conn_rec_list, list) {
  1180. if (!(conn_entry->conn_rec.flags & FCFCNCT_VALID))
  1181. continue;
  1182. if ((conn_entry->conn_rec.flags & FCFCNCT_FBNM_VALID) &&
  1183. !lpfc_fab_name_match(conn_entry->conn_rec.fabric_name,
  1184. new_fcf_record))
  1185. continue;
  1186. if ((conn_entry->conn_rec.flags & FCFCNCT_SWNM_VALID) &&
  1187. !lpfc_sw_name_match(conn_entry->conn_rec.switch_name,
  1188. new_fcf_record))
  1189. continue;
  1190. if (conn_entry->conn_rec.flags & FCFCNCT_VLAN_VALID) {
  1191. /*
  1192. * If the vlan bit map does not have the bit set for the
  1193. * vlan id to be used, then it is not a match.
  1194. */
  1195. if (!(new_fcf_record->vlan_bitmap
  1196. [conn_entry->conn_rec.vlan_tag / 8] &
  1197. (1 << (conn_entry->conn_rec.vlan_tag % 8))))
  1198. continue;
  1199. }
  1200. /*
  1201. * If connection record does not support any addressing mode,
  1202. * skip the FCF record.
  1203. */
  1204. if (!(bf_get(lpfc_fcf_record_mac_addr_prov, new_fcf_record)
  1205. & (LPFC_FCF_FPMA | LPFC_FCF_SPMA)))
  1206. continue;
  1207. /*
  1208. * Check if the connection record specifies a required
  1209. * addressing mode.
  1210. */
  1211. if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) &&
  1212. !(conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED)) {
  1213. /*
  1214. * If SPMA required but FCF not support this continue.
  1215. */
  1216. if ((conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) &&
  1217. !(bf_get(lpfc_fcf_record_mac_addr_prov,
  1218. new_fcf_record) & LPFC_FCF_SPMA))
  1219. continue;
  1220. /*
  1221. * If FPMA required but FCF not support this continue.
  1222. */
  1223. if (!(conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) &&
  1224. !(bf_get(lpfc_fcf_record_mac_addr_prov,
  1225. new_fcf_record) & LPFC_FCF_FPMA))
  1226. continue;
  1227. }
  1228. /*
  1229. * This fcf record matches filtering criteria.
  1230. */
  1231. if (conn_entry->conn_rec.flags & FCFCNCT_BOOT)
  1232. *boot_flag = 1;
  1233. else
  1234. *boot_flag = 0;
  1235. /*
  1236. * If user did not specify any addressing mode, or if the
  1237. * prefered addressing mode specified by user is not supported
  1238. * by FCF, allow fabric to pick the addressing mode.
  1239. */
  1240. *addr_mode = bf_get(lpfc_fcf_record_mac_addr_prov,
  1241. new_fcf_record);
  1242. /*
  1243. * If the user specified a required address mode, assign that
  1244. * address mode
  1245. */
  1246. if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) &&
  1247. (!(conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED)))
  1248. *addr_mode = (conn_entry->conn_rec.flags &
  1249. FCFCNCT_AM_SPMA) ?
  1250. LPFC_FCF_SPMA : LPFC_FCF_FPMA;
  1251. /*
  1252. * If the user specified a prefered address mode, use the
  1253. * addr mode only if FCF support the addr_mode.
  1254. */
  1255. else if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) &&
  1256. (conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED) &&
  1257. (conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) &&
  1258. (*addr_mode & LPFC_FCF_SPMA))
  1259. *addr_mode = LPFC_FCF_SPMA;
  1260. else if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) &&
  1261. (conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED) &&
  1262. !(conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) &&
  1263. (*addr_mode & LPFC_FCF_FPMA))
  1264. *addr_mode = LPFC_FCF_FPMA;
  1265. /* If matching connect list has a vlan id, use it */
  1266. if (conn_entry->conn_rec.flags & FCFCNCT_VLAN_VALID)
  1267. *vlan_id = conn_entry->conn_rec.vlan_tag;
  1268. /*
  1269. * If no vlan id is specified in connect list, use the vlan id
  1270. * in the FCF record
  1271. */
  1272. else if (fcf_vlan_id)
  1273. *vlan_id = fcf_vlan_id;
  1274. else
  1275. *vlan_id = 0xFFFF;
  1276. return 1;
  1277. }
  1278. return 0;
  1279. }
  1280. /**
  1281. * lpfc_check_pending_fcoe_event - Check if there is pending fcoe event.
  1282. * @phba: pointer to lpfc hba data structure.
  1283. * @unreg_fcf: Unregister FCF if FCF table need to be re-scaned.
  1284. *
  1285. * This function check if there is any fcoe event pending while driver
  1286. * scan FCF entries. If there is any pending event, it will restart the
  1287. * FCF saning and return 1 else return 0.
  1288. */
  1289. int
  1290. lpfc_check_pending_fcoe_event(struct lpfc_hba *phba, uint8_t unreg_fcf)
  1291. {
  1292. LPFC_MBOXQ_t *mbox;
  1293. int rc;
  1294. /*
  1295. * If the Link is up and no FCoE events while in the
  1296. * FCF discovery, no need to restart FCF discovery.
  1297. */
  1298. if ((phba->link_state >= LPFC_LINK_UP) &&
  1299. (phba->fcoe_eventtag == phba->fcoe_eventtag_at_fcf_scan))
  1300. return 0;
  1301. spin_lock_irq(&phba->hbalock);
  1302. phba->fcf.fcf_flag &= ~FCF_AVAILABLE;
  1303. spin_unlock_irq(&phba->hbalock);
  1304. if (phba->link_state >= LPFC_LINK_UP)
  1305. lpfc_sli4_read_fcf_record(phba, LPFC_FCOE_FCF_GET_FIRST);
  1306. else {
  1307. /*
  1308. * Do not continue FCF discovery and clear FCF_DISC_INPROGRESS
  1309. * flag
  1310. */
  1311. spin_lock_irq(&phba->hbalock);
  1312. phba->hba_flag &= ~FCF_DISC_INPROGRESS;
  1313. spin_unlock_irq(&phba->hbalock);
  1314. }
  1315. if (unreg_fcf) {
  1316. spin_lock_irq(&phba->hbalock);
  1317. phba->fcf.fcf_flag &= ~FCF_REGISTERED;
  1318. spin_unlock_irq(&phba->hbalock);
  1319. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  1320. if (!mbox) {
  1321. lpfc_printf_log(phba, KERN_ERR,
  1322. LOG_DISCOVERY|LOG_MBOX,
  1323. "2610 UNREG_FCFI mbox allocation failed\n");
  1324. return 1;
  1325. }
  1326. lpfc_unreg_fcfi(mbox, phba->fcf.fcfi);
  1327. mbox->vport = phba->pport;
  1328. mbox->mbox_cmpl = lpfc_unregister_fcfi_cmpl;
  1329. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
  1330. if (rc == MBX_NOT_FINISHED) {
  1331. lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
  1332. "2611 UNREG_FCFI issue mbox failed\n");
  1333. mempool_free(mbox, phba->mbox_mem_pool);
  1334. }
  1335. }
  1336. return 1;
  1337. }
  1338. /**
  1339. * lpfc_mbx_cmpl_read_fcf_record - Completion handler for read_fcf mbox.
  1340. * @phba: pointer to lpfc hba data structure.
  1341. * @mboxq: pointer to mailbox object.
  1342. *
  1343. * This function iterate through all the fcf records available in
  1344. * HBA and choose the optimal FCF record for discovery. After finding
  1345. * the FCF for discovery it register the FCF record and kick start
  1346. * discovery.
  1347. * If FCF_IN_USE flag is set in currently used FCF, the routine try to
  1348. * use a FCF record which match fabric name and mac address of the
  1349. * currently used FCF record.
  1350. * If the driver support only one FCF, it will try to use the FCF record
  1351. * used by BOOT_BIOS.
  1352. */
  1353. void
  1354. lpfc_mbx_cmpl_read_fcf_record(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  1355. {
  1356. void *virt_addr;
  1357. dma_addr_t phys_addr;
  1358. uint8_t *bytep;
  1359. struct lpfc_mbx_sge sge;
  1360. struct lpfc_mbx_read_fcf_tbl *read_fcf;
  1361. uint32_t shdr_status, shdr_add_status;
  1362. union lpfc_sli4_cfg_shdr *shdr;
  1363. struct fcf_record *new_fcf_record;
  1364. int rc;
  1365. uint32_t boot_flag, addr_mode;
  1366. uint32_t next_fcf_index;
  1367. unsigned long flags;
  1368. uint16_t vlan_id;
  1369. /* If there is pending FCoE event restart FCF table scan */
  1370. if (lpfc_check_pending_fcoe_event(phba, 0)) {
  1371. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  1372. return;
  1373. }
  1374. /* Get the first SGE entry from the non-embedded DMA memory. This
  1375. * routine only uses a single SGE.
  1376. */
  1377. lpfc_sli4_mbx_sge_get(mboxq, 0, &sge);
  1378. phys_addr = getPaddr(sge.pa_hi, sge.pa_lo);
  1379. if (unlikely(!mboxq->sge_array)) {
  1380. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
  1381. "2524 Failed to get the non-embedded SGE "
  1382. "virtual address\n");
  1383. goto out;
  1384. }
  1385. virt_addr = mboxq->sge_array->addr[0];
  1386. shdr = (union lpfc_sli4_cfg_shdr *)virt_addr;
  1387. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  1388. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status,
  1389. &shdr->response);
  1390. /*
  1391. * The FCF Record was read and there is no reason for the driver
  1392. * to maintain the FCF record data or memory. Instead, just need
  1393. * to book keeping the FCFIs can be used.
  1394. */
  1395. if (shdr_status || shdr_add_status) {
  1396. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  1397. "2521 READ_FCF_RECORD mailbox failed "
  1398. "with status x%x add_status x%x, mbx\n",
  1399. shdr_status, shdr_add_status);
  1400. goto out;
  1401. }
  1402. /* Interpreting the returned information of FCF records */
  1403. read_fcf = (struct lpfc_mbx_read_fcf_tbl *)virt_addr;
  1404. lpfc_sli_pcimem_bcopy(read_fcf, read_fcf,
  1405. sizeof(struct lpfc_mbx_read_fcf_tbl));
  1406. next_fcf_index = bf_get(lpfc_mbx_read_fcf_tbl_nxt_vindx, read_fcf);
  1407. new_fcf_record = (struct fcf_record *)(virt_addr +
  1408. sizeof(struct lpfc_mbx_read_fcf_tbl));
  1409. lpfc_sli_pcimem_bcopy(new_fcf_record, new_fcf_record,
  1410. sizeof(struct fcf_record));
  1411. bytep = virt_addr + sizeof(union lpfc_sli4_cfg_shdr);
  1412. rc = lpfc_match_fcf_conn_list(phba, new_fcf_record,
  1413. &boot_flag, &addr_mode,
  1414. &vlan_id);
  1415. /*
  1416. * If the fcf record does not match with connect list entries
  1417. * read the next entry.
  1418. */
  1419. if (!rc)
  1420. goto read_next_fcf;
  1421. /*
  1422. * If this is not the first FCF discovery of the HBA, use last
  1423. * FCF record for the discovery.
  1424. */
  1425. spin_lock_irqsave(&phba->hbalock, flags);
  1426. if (phba->fcf.fcf_flag & FCF_IN_USE) {
  1427. if (lpfc_fab_name_match(phba->fcf.fabric_name,
  1428. new_fcf_record) &&
  1429. lpfc_sw_name_match(phba->fcf.switch_name,
  1430. new_fcf_record) &&
  1431. lpfc_mac_addr_match(phba, new_fcf_record)) {
  1432. phba->fcf.fcf_flag |= FCF_AVAILABLE;
  1433. spin_unlock_irqrestore(&phba->hbalock, flags);
  1434. goto out;
  1435. }
  1436. spin_unlock_irqrestore(&phba->hbalock, flags);
  1437. goto read_next_fcf;
  1438. }
  1439. if (phba->fcf.fcf_flag & FCF_AVAILABLE) {
  1440. /*
  1441. * If the current FCF record does not have boot flag
  1442. * set and new fcf record has boot flag set, use the
  1443. * new fcf record.
  1444. */
  1445. if (boot_flag && !(phba->fcf.fcf_flag & FCF_BOOT_ENABLE)) {
  1446. /* Use this FCF record */
  1447. lpfc_copy_fcf_record(phba, new_fcf_record);
  1448. phba->fcf.addr_mode = addr_mode;
  1449. phba->fcf.fcf_flag |= FCF_BOOT_ENABLE;
  1450. if (vlan_id != 0xFFFF) {
  1451. phba->fcf.fcf_flag |= FCF_VALID_VLAN;
  1452. phba->fcf.vlan_id = vlan_id;
  1453. }
  1454. spin_unlock_irqrestore(&phba->hbalock, flags);
  1455. goto read_next_fcf;
  1456. }
  1457. /*
  1458. * If the current FCF record has boot flag set and the
  1459. * new FCF record does not have boot flag, read the next
  1460. * FCF record.
  1461. */
  1462. if (!boot_flag && (phba->fcf.fcf_flag & FCF_BOOT_ENABLE)) {
  1463. spin_unlock_irqrestore(&phba->hbalock, flags);
  1464. goto read_next_fcf;
  1465. }
  1466. /*
  1467. * If there is a record with lower priority value for
  1468. * the current FCF, use that record.
  1469. */
  1470. if (lpfc_fab_name_match(phba->fcf.fabric_name,
  1471. new_fcf_record) &&
  1472. (new_fcf_record->fip_priority < phba->fcf.priority)) {
  1473. /* Use this FCF record */
  1474. lpfc_copy_fcf_record(phba, new_fcf_record);
  1475. phba->fcf.addr_mode = addr_mode;
  1476. if (vlan_id != 0xFFFF) {
  1477. phba->fcf.fcf_flag |= FCF_VALID_VLAN;
  1478. phba->fcf.vlan_id = vlan_id;
  1479. }
  1480. spin_unlock_irqrestore(&phba->hbalock, flags);
  1481. goto read_next_fcf;
  1482. }
  1483. spin_unlock_irqrestore(&phba->hbalock, flags);
  1484. goto read_next_fcf;
  1485. }
  1486. /*
  1487. * This is the first available FCF record, use this
  1488. * record.
  1489. */
  1490. lpfc_copy_fcf_record(phba, new_fcf_record);
  1491. phba->fcf.addr_mode = addr_mode;
  1492. if (boot_flag)
  1493. phba->fcf.fcf_flag |= FCF_BOOT_ENABLE;
  1494. phba->fcf.fcf_flag |= FCF_AVAILABLE;
  1495. if (vlan_id != 0xFFFF) {
  1496. phba->fcf.fcf_flag |= FCF_VALID_VLAN;
  1497. phba->fcf.vlan_id = vlan_id;
  1498. }
  1499. spin_unlock_irqrestore(&phba->hbalock, flags);
  1500. goto read_next_fcf;
  1501. read_next_fcf:
  1502. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  1503. if (next_fcf_index == LPFC_FCOE_FCF_NEXT_NONE || next_fcf_index == 0)
  1504. lpfc_register_fcf(phba);
  1505. else
  1506. lpfc_sli4_read_fcf_record(phba, next_fcf_index);
  1507. return;
  1508. out:
  1509. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  1510. lpfc_register_fcf(phba);
  1511. return;
  1512. }
  1513. /**
  1514. * lpfc_init_vpi_cmpl - Completion handler for init_vpi mbox command.
  1515. * @phba: pointer to lpfc hba data structure.
  1516. * @mboxq: pointer to mailbox data structure.
  1517. *
  1518. * This function handles completion of init vpi mailbox command.
  1519. */
  1520. static void
  1521. lpfc_init_vpi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  1522. {
  1523. struct lpfc_vport *vport = mboxq->vport;
  1524. if (mboxq->u.mb.mbxStatus) {
  1525. lpfc_printf_vlog(vport, KERN_ERR,
  1526. LOG_MBOX,
  1527. "2609 Init VPI mailbox failed 0x%x\n",
  1528. mboxq->u.mb.mbxStatus);
  1529. mempool_free(mboxq, phba->mbox_mem_pool);
  1530. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  1531. return;
  1532. }
  1533. vport->fc_flag &= ~FC_VPORT_NEEDS_INIT_VPI;
  1534. if (phba->link_flag & LS_NPIV_FAB_SUPPORTED)
  1535. lpfc_initial_fdisc(vport);
  1536. else {
  1537. lpfc_vport_set_state(vport, FC_VPORT_NO_FABRIC_SUPP);
  1538. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  1539. "2606 No NPIV Fabric support\n");
  1540. }
  1541. return;
  1542. }
  1543. /**
  1544. * lpfc_start_fdiscs - send fdiscs for each vports on this port.
  1545. * @phba: pointer to lpfc hba data structure.
  1546. *
  1547. * This function loops through the list of vports on the @phba and issues an
  1548. * FDISC if possible.
  1549. */
  1550. void
  1551. lpfc_start_fdiscs(struct lpfc_hba *phba)
  1552. {
  1553. struct lpfc_vport **vports;
  1554. int i;
  1555. LPFC_MBOXQ_t *mboxq;
  1556. int rc;
  1557. vports = lpfc_create_vport_work_array(phba);
  1558. if (vports != NULL) {
  1559. for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
  1560. if (vports[i]->port_type == LPFC_PHYSICAL_PORT)
  1561. continue;
  1562. /* There are no vpi for this vport */
  1563. if (vports[i]->vpi > phba->max_vpi) {
  1564. lpfc_vport_set_state(vports[i],
  1565. FC_VPORT_FAILED);
  1566. continue;
  1567. }
  1568. if (phba->fc_topology == TOPOLOGY_LOOP) {
  1569. lpfc_vport_set_state(vports[i],
  1570. FC_VPORT_LINKDOWN);
  1571. continue;
  1572. }
  1573. if (vports[i]->fc_flag & FC_VPORT_NEEDS_INIT_VPI) {
  1574. mboxq = mempool_alloc(phba->mbox_mem_pool,
  1575. GFP_KERNEL);
  1576. if (!mboxq) {
  1577. lpfc_printf_vlog(vports[i], KERN_ERR,
  1578. LOG_MBOX, "2607 Failed to allocate "
  1579. "init_vpi mailbox\n");
  1580. continue;
  1581. }
  1582. lpfc_init_vpi(phba, mboxq, vports[i]->vpi);
  1583. mboxq->vport = vports[i];
  1584. mboxq->mbox_cmpl = lpfc_init_vpi_cmpl;
  1585. rc = lpfc_sli_issue_mbox(phba, mboxq,
  1586. MBX_NOWAIT);
  1587. if (rc == MBX_NOT_FINISHED) {
  1588. lpfc_printf_vlog(vports[i], KERN_ERR,
  1589. LOG_MBOX, "2608 Failed to issue "
  1590. "init_vpi mailbox\n");
  1591. mempool_free(mboxq,
  1592. phba->mbox_mem_pool);
  1593. }
  1594. continue;
  1595. }
  1596. if (phba->link_flag & LS_NPIV_FAB_SUPPORTED)
  1597. lpfc_initial_fdisc(vports[i]);
  1598. else {
  1599. lpfc_vport_set_state(vports[i],
  1600. FC_VPORT_NO_FABRIC_SUPP);
  1601. lpfc_printf_vlog(vports[i], KERN_ERR,
  1602. LOG_ELS,
  1603. "0259 No NPIV "
  1604. "Fabric support\n");
  1605. }
  1606. }
  1607. }
  1608. lpfc_destroy_vport_work_array(phba, vports);
  1609. }
  1610. void
  1611. lpfc_mbx_cmpl_reg_vfi(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  1612. {
  1613. struct lpfc_dmabuf *dmabuf = mboxq->context1;
  1614. struct lpfc_vport *vport = mboxq->vport;
  1615. if (mboxq->u.mb.mbxStatus) {
  1616. lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
  1617. "2018 REG_VFI mbxStatus error x%x "
  1618. "HBA state x%x\n",
  1619. mboxq->u.mb.mbxStatus, vport->port_state);
  1620. if (phba->fc_topology == TOPOLOGY_LOOP) {
  1621. /* FLOGI failed, use loop map to make discovery list */
  1622. lpfc_disc_list_loopmap(vport);
  1623. /* Start discovery */
  1624. lpfc_disc_start(vport);
  1625. goto fail_free_mem;
  1626. }
  1627. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  1628. goto fail_free_mem;
  1629. }
  1630. /* The VPI is implicitly registered when the VFI is registered */
  1631. vport->vpi_state |= LPFC_VPI_REGISTERED;
  1632. if (vport->port_state == LPFC_FABRIC_CFG_LINK) {
  1633. lpfc_start_fdiscs(phba);
  1634. lpfc_do_scr_ns_plogi(phba, vport);
  1635. }
  1636. fail_free_mem:
  1637. mempool_free(mboxq, phba->mbox_mem_pool);
  1638. lpfc_mbuf_free(phba, dmabuf->virt, dmabuf->phys);
  1639. kfree(dmabuf);
  1640. return;
  1641. }
  1642. static void
  1643. lpfc_mbx_cmpl_read_sparam(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  1644. {
  1645. MAILBOX_t *mb = &pmb->u.mb;
  1646. struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) pmb->context1;
  1647. struct lpfc_vport *vport = pmb->vport;
  1648. /* Check for error */
  1649. if (mb->mbxStatus) {
  1650. /* READ_SPARAM mbox error <mbxStatus> state <hba_state> */
  1651. lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
  1652. "0319 READ_SPARAM mbxStatus error x%x "
  1653. "hba state x%x>\n",
  1654. mb->mbxStatus, vport->port_state);
  1655. lpfc_linkdown(phba);
  1656. goto out;
  1657. }
  1658. memcpy((uint8_t *) &vport->fc_sparam, (uint8_t *) mp->virt,
  1659. sizeof (struct serv_parm));
  1660. if (phba->cfg_soft_wwnn)
  1661. u64_to_wwn(phba->cfg_soft_wwnn,
  1662. vport->fc_sparam.nodeName.u.wwn);
  1663. if (phba->cfg_soft_wwpn)
  1664. u64_to_wwn(phba->cfg_soft_wwpn,
  1665. vport->fc_sparam.portName.u.wwn);
  1666. memcpy(&vport->fc_nodename, &vport->fc_sparam.nodeName,
  1667. sizeof(vport->fc_nodename));
  1668. memcpy(&vport->fc_portname, &vport->fc_sparam.portName,
  1669. sizeof(vport->fc_portname));
  1670. if (vport->port_type == LPFC_PHYSICAL_PORT) {
  1671. memcpy(&phba->wwnn, &vport->fc_nodename, sizeof(phba->wwnn));
  1672. memcpy(&phba->wwpn, &vport->fc_portname, sizeof(phba->wwnn));
  1673. }
  1674. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  1675. kfree(mp);
  1676. mempool_free(pmb, phba->mbox_mem_pool);
  1677. return;
  1678. out:
  1679. pmb->context1 = NULL;
  1680. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  1681. kfree(mp);
  1682. lpfc_issue_clear_la(phba, vport);
  1683. mempool_free(pmb, phba->mbox_mem_pool);
  1684. return;
  1685. }
  1686. static void
  1687. lpfc_mbx_process_link_up(struct lpfc_hba *phba, READ_LA_VAR *la)
  1688. {
  1689. struct lpfc_vport *vport = phba->pport;
  1690. LPFC_MBOXQ_t *sparam_mbox, *cfglink_mbox = NULL;
  1691. int i;
  1692. struct lpfc_dmabuf *mp;
  1693. int rc;
  1694. struct fcf_record *fcf_record;
  1695. sparam_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  1696. spin_lock_irq(&phba->hbalock);
  1697. switch (la->UlnkSpeed) {
  1698. case LA_1GHZ_LINK:
  1699. phba->fc_linkspeed = LA_1GHZ_LINK;
  1700. break;
  1701. case LA_2GHZ_LINK:
  1702. phba->fc_linkspeed = LA_2GHZ_LINK;
  1703. break;
  1704. case LA_4GHZ_LINK:
  1705. phba->fc_linkspeed = LA_4GHZ_LINK;
  1706. break;
  1707. case LA_8GHZ_LINK:
  1708. phba->fc_linkspeed = LA_8GHZ_LINK;
  1709. break;
  1710. case LA_10GHZ_LINK:
  1711. phba->fc_linkspeed = LA_10GHZ_LINK;
  1712. break;
  1713. default:
  1714. phba->fc_linkspeed = LA_UNKNW_LINK;
  1715. break;
  1716. }
  1717. phba->fc_topology = la->topology;
  1718. phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED;
  1719. if (phba->fc_topology == TOPOLOGY_LOOP) {
  1720. phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED;
  1721. /* if npiv is enabled and this adapter supports npiv log
  1722. * a message that npiv is not supported in this topology
  1723. */
  1724. if (phba->cfg_enable_npiv && phba->max_vpi)
  1725. lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
  1726. "1309 Link Up Event npiv not supported in loop "
  1727. "topology\n");
  1728. /* Get Loop Map information */
  1729. if (la->il)
  1730. vport->fc_flag |= FC_LBIT;
  1731. vport->fc_myDID = la->granted_AL_PA;
  1732. i = la->un.lilpBde64.tus.f.bdeSize;
  1733. if (i == 0) {
  1734. phba->alpa_map[0] = 0;
  1735. } else {
  1736. if (vport->cfg_log_verbose & LOG_LINK_EVENT) {
  1737. int numalpa, j, k;
  1738. union {
  1739. uint8_t pamap[16];
  1740. struct {
  1741. uint32_t wd1;
  1742. uint32_t wd2;
  1743. uint32_t wd3;
  1744. uint32_t wd4;
  1745. } pa;
  1746. } un;
  1747. numalpa = phba->alpa_map[0];
  1748. j = 0;
  1749. while (j < numalpa) {
  1750. memset(un.pamap, 0, 16);
  1751. for (k = 1; j < numalpa; k++) {
  1752. un.pamap[k - 1] =
  1753. phba->alpa_map[j + 1];
  1754. j++;
  1755. if (k == 16)
  1756. break;
  1757. }
  1758. /* Link Up Event ALPA map */
  1759. lpfc_printf_log(phba,
  1760. KERN_WARNING,
  1761. LOG_LINK_EVENT,
  1762. "1304 Link Up Event "
  1763. "ALPA map Data: x%x "
  1764. "x%x x%x x%x\n",
  1765. un.pa.wd1, un.pa.wd2,
  1766. un.pa.wd3, un.pa.wd4);
  1767. }
  1768. }
  1769. }
  1770. } else {
  1771. if (!(phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)) {
  1772. if (phba->max_vpi && phba->cfg_enable_npiv &&
  1773. (phba->sli_rev == 3))
  1774. phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED;
  1775. }
  1776. vport->fc_myDID = phba->fc_pref_DID;
  1777. vport->fc_flag |= FC_LBIT;
  1778. }
  1779. spin_unlock_irq(&phba->hbalock);
  1780. lpfc_linkup(phba);
  1781. if (sparam_mbox) {
  1782. lpfc_read_sparam(phba, sparam_mbox, 0);
  1783. sparam_mbox->vport = vport;
  1784. sparam_mbox->mbox_cmpl = lpfc_mbx_cmpl_read_sparam;
  1785. rc = lpfc_sli_issue_mbox(phba, sparam_mbox, MBX_NOWAIT);
  1786. if (rc == MBX_NOT_FINISHED) {
  1787. mp = (struct lpfc_dmabuf *) sparam_mbox->context1;
  1788. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  1789. kfree(mp);
  1790. mempool_free(sparam_mbox, phba->mbox_mem_pool);
  1791. goto out;
  1792. }
  1793. }
  1794. if (!(phba->hba_flag & HBA_FCOE_SUPPORT)) {
  1795. cfglink_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  1796. if (!cfglink_mbox)
  1797. goto out;
  1798. vport->port_state = LPFC_LOCAL_CFG_LINK;
  1799. lpfc_config_link(phba, cfglink_mbox);
  1800. cfglink_mbox->vport = vport;
  1801. cfglink_mbox->mbox_cmpl = lpfc_mbx_cmpl_local_config_link;
  1802. rc = lpfc_sli_issue_mbox(phba, cfglink_mbox, MBX_NOWAIT);
  1803. if (rc == MBX_NOT_FINISHED) {
  1804. mempool_free(cfglink_mbox, phba->mbox_mem_pool);
  1805. goto out;
  1806. }
  1807. } else {
  1808. vport->port_state = LPFC_VPORT_UNKNOWN;
  1809. /*
  1810. * Add the driver's default FCF record at FCF index 0 now. This
  1811. * is phase 1 implementation that support FCF index 0 and driver
  1812. * defaults.
  1813. */
  1814. if (!(phba->hba_flag & HBA_FIP_SUPPORT)) {
  1815. fcf_record = kzalloc(sizeof(struct fcf_record),
  1816. GFP_KERNEL);
  1817. if (unlikely(!fcf_record)) {
  1818. lpfc_printf_log(phba, KERN_ERR,
  1819. LOG_MBOX | LOG_SLI,
  1820. "2554 Could not allocate memmory for "
  1821. "fcf record\n");
  1822. rc = -ENODEV;
  1823. goto out;
  1824. }
  1825. lpfc_sli4_build_dflt_fcf_record(phba, fcf_record,
  1826. LPFC_FCOE_FCF_DEF_INDEX);
  1827. rc = lpfc_sli4_add_fcf_record(phba, fcf_record);
  1828. if (unlikely(rc)) {
  1829. lpfc_printf_log(phba, KERN_ERR,
  1830. LOG_MBOX | LOG_SLI,
  1831. "2013 Could not manually add FCF "
  1832. "record 0, status %d\n", rc);
  1833. rc = -ENODEV;
  1834. kfree(fcf_record);
  1835. goto out;
  1836. }
  1837. kfree(fcf_record);
  1838. }
  1839. /*
  1840. * The driver is expected to do FIP/FCF. Call the port
  1841. * and get the FCF Table.
  1842. */
  1843. spin_lock_irq(&phba->hbalock);
  1844. if (phba->hba_flag & FCF_DISC_INPROGRESS) {
  1845. spin_unlock_irq(&phba->hbalock);
  1846. return;
  1847. }
  1848. spin_unlock_irq(&phba->hbalock);
  1849. rc = lpfc_sli4_read_fcf_record(phba,
  1850. LPFC_FCOE_FCF_GET_FIRST);
  1851. if (rc)
  1852. goto out;
  1853. }
  1854. return;
  1855. out:
  1856. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  1857. lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
  1858. "0263 Discovery Mailbox error: state: 0x%x : %p %p\n",
  1859. vport->port_state, sparam_mbox, cfglink_mbox);
  1860. lpfc_issue_clear_la(phba, vport);
  1861. return;
  1862. }
  1863. static void
  1864. lpfc_enable_la(struct lpfc_hba *phba)
  1865. {
  1866. uint32_t control;
  1867. struct lpfc_sli *psli = &phba->sli;
  1868. spin_lock_irq(&phba->hbalock);
  1869. psli->sli_flag |= LPFC_PROCESS_LA;
  1870. if (phba->sli_rev <= LPFC_SLI_REV3) {
  1871. control = readl(phba->HCregaddr);
  1872. control |= HC_LAINT_ENA;
  1873. writel(control, phba->HCregaddr);
  1874. readl(phba->HCregaddr); /* flush */
  1875. }
  1876. spin_unlock_irq(&phba->hbalock);
  1877. }
  1878. static void
  1879. lpfc_mbx_issue_link_down(struct lpfc_hba *phba)
  1880. {
  1881. lpfc_linkdown(phba);
  1882. lpfc_enable_la(phba);
  1883. lpfc_unregister_unused_fcf(phba);
  1884. /* turn on Link Attention interrupts - no CLEAR_LA needed */
  1885. }
  1886. /*
  1887. * This routine handles processing a READ_LA mailbox
  1888. * command upon completion. It is setup in the LPFC_MBOXQ
  1889. * as the completion routine when the command is
  1890. * handed off to the SLI layer.
  1891. */
  1892. void
  1893. lpfc_mbx_cmpl_read_la(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  1894. {
  1895. struct lpfc_vport *vport = pmb->vport;
  1896. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  1897. READ_LA_VAR *la;
  1898. MAILBOX_t *mb = &pmb->u.mb;
  1899. struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
  1900. /* Unblock ELS traffic */
  1901. phba->sli.ring[LPFC_ELS_RING].flag &= ~LPFC_STOP_IOCB_EVENT;
  1902. /* Check for error */
  1903. if (mb->mbxStatus) {
  1904. lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
  1905. "1307 READ_LA mbox error x%x state x%x\n",
  1906. mb->mbxStatus, vport->port_state);
  1907. lpfc_mbx_issue_link_down(phba);
  1908. phba->link_state = LPFC_HBA_ERROR;
  1909. goto lpfc_mbx_cmpl_read_la_free_mbuf;
  1910. }
  1911. la = (READ_LA_VAR *) &pmb->u.mb.un.varReadLA;
  1912. memcpy(&phba->alpa_map[0], mp->virt, 128);
  1913. spin_lock_irq(shost->host_lock);
  1914. if (la->pb)
  1915. vport->fc_flag |= FC_BYPASSED_MODE;
  1916. else
  1917. vport->fc_flag &= ~FC_BYPASSED_MODE;
  1918. spin_unlock_irq(shost->host_lock);
  1919. if ((phba->fc_eventTag < la->eventTag) ||
  1920. (phba->fc_eventTag == la->eventTag)) {
  1921. phba->fc_stat.LinkMultiEvent++;
  1922. if (la->attType == AT_LINK_UP)
  1923. if (phba->fc_eventTag != 0)
  1924. lpfc_linkdown(phba);
  1925. }
  1926. phba->fc_eventTag = la->eventTag;
  1927. if (la->mm)
  1928. phba->sli.sli_flag |= LPFC_MENLO_MAINT;
  1929. else
  1930. phba->sli.sli_flag &= ~LPFC_MENLO_MAINT;
  1931. phba->link_events++;
  1932. if (la->attType == AT_LINK_UP && (!la->mm)) {
  1933. phba->fc_stat.LinkUp++;
  1934. if (phba->link_flag & LS_LOOPBACK_MODE) {
  1935. lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
  1936. "1306 Link Up Event in loop back mode "
  1937. "x%x received Data: x%x x%x x%x x%x\n",
  1938. la->eventTag, phba->fc_eventTag,
  1939. la->granted_AL_PA, la->UlnkSpeed,
  1940. phba->alpa_map[0]);
  1941. } else {
  1942. lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
  1943. "1303 Link Up Event x%x received "
  1944. "Data: x%x x%x x%x x%x x%x x%x %d\n",
  1945. la->eventTag, phba->fc_eventTag,
  1946. la->granted_AL_PA, la->UlnkSpeed,
  1947. phba->alpa_map[0],
  1948. la->mm, la->fa,
  1949. phba->wait_4_mlo_maint_flg);
  1950. }
  1951. lpfc_mbx_process_link_up(phba, la);
  1952. } else if (la->attType == AT_LINK_DOWN) {
  1953. phba->fc_stat.LinkDown++;
  1954. if (phba->link_flag & LS_LOOPBACK_MODE) {
  1955. lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
  1956. "1308 Link Down Event in loop back mode "
  1957. "x%x received "
  1958. "Data: x%x x%x x%x\n",
  1959. la->eventTag, phba->fc_eventTag,
  1960. phba->pport->port_state, vport->fc_flag);
  1961. }
  1962. else {
  1963. lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
  1964. "1305 Link Down Event x%x received "
  1965. "Data: x%x x%x x%x x%x x%x\n",
  1966. la->eventTag, phba->fc_eventTag,
  1967. phba->pport->port_state, vport->fc_flag,
  1968. la->mm, la->fa);
  1969. }
  1970. lpfc_mbx_issue_link_down(phba);
  1971. }
  1972. if (la->mm && la->attType == AT_LINK_UP) {
  1973. if (phba->link_state != LPFC_LINK_DOWN) {
  1974. phba->fc_stat.LinkDown++;
  1975. lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
  1976. "1312 Link Down Event x%x received "
  1977. "Data: x%x x%x x%x\n",
  1978. la->eventTag, phba->fc_eventTag,
  1979. phba->pport->port_state, vport->fc_flag);
  1980. lpfc_mbx_issue_link_down(phba);
  1981. } else
  1982. lpfc_enable_la(phba);
  1983. lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
  1984. "1310 Menlo Maint Mode Link up Event x%x rcvd "
  1985. "Data: x%x x%x x%x\n",
  1986. la->eventTag, phba->fc_eventTag,
  1987. phba->pport->port_state, vport->fc_flag);
  1988. /*
  1989. * The cmnd that triggered this will be waiting for this
  1990. * signal.
  1991. */
  1992. /* WAKEUP for MENLO_SET_MODE or MENLO_RESET command. */
  1993. if (phba->wait_4_mlo_maint_flg) {
  1994. phba->wait_4_mlo_maint_flg = 0;
  1995. wake_up_interruptible(&phba->wait_4_mlo_m_q);
  1996. }
  1997. }
  1998. if (la->fa) {
  1999. if (la->mm)
  2000. lpfc_issue_clear_la(phba, vport);
  2001. lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
  2002. "1311 fa %d\n", la->fa);
  2003. }
  2004. lpfc_mbx_cmpl_read_la_free_mbuf:
  2005. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  2006. kfree(mp);
  2007. mempool_free(pmb, phba->mbox_mem_pool);
  2008. return;
  2009. }
  2010. /*
  2011. * This routine handles processing a REG_LOGIN mailbox
  2012. * command upon completion. It is setup in the LPFC_MBOXQ
  2013. * as the completion routine when the command is
  2014. * handed off to the SLI layer.
  2015. */
  2016. void
  2017. lpfc_mbx_cmpl_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  2018. {
  2019. struct lpfc_vport *vport = pmb->vport;
  2020. struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
  2021. struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
  2022. pmb->context1 = NULL;
  2023. /* Good status, call state machine */
  2024. lpfc_disc_state_machine(vport, ndlp, pmb, NLP_EVT_CMPL_REG_LOGIN);
  2025. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  2026. kfree(mp);
  2027. mempool_free(pmb, phba->mbox_mem_pool);
  2028. /* decrement the node reference count held for this callback
  2029. * function.
  2030. */
  2031. lpfc_nlp_put(ndlp);
  2032. return;
  2033. }
  2034. static void
  2035. lpfc_mbx_cmpl_unreg_vpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  2036. {
  2037. MAILBOX_t *mb = &pmb->u.mb;
  2038. struct lpfc_vport *vport = pmb->vport;
  2039. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2040. switch (mb->mbxStatus) {
  2041. case 0x0011:
  2042. case 0x0020:
  2043. case 0x9700:
  2044. lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
  2045. "0911 cmpl_unreg_vpi, mb status = 0x%x\n",
  2046. mb->mbxStatus);
  2047. break;
  2048. }
  2049. vport->vpi_state &= ~LPFC_VPI_REGISTERED;
  2050. vport->unreg_vpi_cmpl = VPORT_OK;
  2051. mempool_free(pmb, phba->mbox_mem_pool);
  2052. /*
  2053. * This shost reference might have been taken at the beginning of
  2054. * lpfc_vport_delete()
  2055. */
  2056. if ((vport->load_flag & FC_UNLOADING) && (vport != phba->pport))
  2057. scsi_host_put(shost);
  2058. }
  2059. int
  2060. lpfc_mbx_unreg_vpi(struct lpfc_vport *vport)
  2061. {
  2062. struct lpfc_hba *phba = vport->phba;
  2063. LPFC_MBOXQ_t *mbox;
  2064. int rc;
  2065. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  2066. if (!mbox)
  2067. return 1;
  2068. lpfc_unreg_vpi(phba, vport->vpi, mbox);
  2069. mbox->vport = vport;
  2070. mbox->mbox_cmpl = lpfc_mbx_cmpl_unreg_vpi;
  2071. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
  2072. if (rc == MBX_NOT_FINISHED) {
  2073. lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX | LOG_VPORT,
  2074. "1800 Could not issue unreg_vpi\n");
  2075. mempool_free(mbox, phba->mbox_mem_pool);
  2076. vport->unreg_vpi_cmpl = VPORT_ERROR;
  2077. return rc;
  2078. }
  2079. return 0;
  2080. }
  2081. static void
  2082. lpfc_mbx_cmpl_reg_vpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  2083. {
  2084. struct lpfc_vport *vport = pmb->vport;
  2085. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2086. MAILBOX_t *mb = &pmb->u.mb;
  2087. switch (mb->mbxStatus) {
  2088. case 0x0011:
  2089. case 0x9601:
  2090. case 0x9602:
  2091. lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
  2092. "0912 cmpl_reg_vpi, mb status = 0x%x\n",
  2093. mb->mbxStatus);
  2094. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  2095. spin_lock_irq(shost->host_lock);
  2096. vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
  2097. spin_unlock_irq(shost->host_lock);
  2098. vport->fc_myDID = 0;
  2099. goto out;
  2100. }
  2101. vport->vpi_state |= LPFC_VPI_REGISTERED;
  2102. vport->num_disc_nodes = 0;
  2103. /* go thru NPR list and issue ELS PLOGIs */
  2104. if (vport->fc_npr_cnt)
  2105. lpfc_els_disc_plogi(vport);
  2106. if (!vport->num_disc_nodes) {
  2107. spin_lock_irq(shost->host_lock);
  2108. vport->fc_flag &= ~FC_NDISC_ACTIVE;
  2109. spin_unlock_irq(shost->host_lock);
  2110. lpfc_can_disctmo(vport);
  2111. }
  2112. vport->port_state = LPFC_VPORT_READY;
  2113. out:
  2114. mempool_free(pmb, phba->mbox_mem_pool);
  2115. return;
  2116. }
  2117. /**
  2118. * lpfc_create_static_vport - Read HBA config region to create static vports.
  2119. * @phba: pointer to lpfc hba data structure.
  2120. *
  2121. * This routine issue a DUMP mailbox command for config region 22 to get
  2122. * the list of static vports to be created. The function create vports
  2123. * based on the information returned from the HBA.
  2124. **/
  2125. void
  2126. lpfc_create_static_vport(struct lpfc_hba *phba)
  2127. {
  2128. LPFC_MBOXQ_t *pmb = NULL;
  2129. MAILBOX_t *mb;
  2130. struct static_vport_info *vport_info;
  2131. int rc = 0, i;
  2132. struct fc_vport_identifiers vport_id;
  2133. struct fc_vport *new_fc_vport;
  2134. struct Scsi_Host *shost;
  2135. struct lpfc_vport *vport;
  2136. uint16_t offset = 0;
  2137. uint8_t *vport_buff;
  2138. struct lpfc_dmabuf *mp;
  2139. uint32_t byte_count = 0;
  2140. pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  2141. if (!pmb) {
  2142. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  2143. "0542 lpfc_create_static_vport failed to"
  2144. " allocate mailbox memory\n");
  2145. return;
  2146. }
  2147. mb = &pmb->u.mb;
  2148. vport_info = kzalloc(sizeof(struct static_vport_info), GFP_KERNEL);
  2149. if (!vport_info) {
  2150. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  2151. "0543 lpfc_create_static_vport failed to"
  2152. " allocate vport_info\n");
  2153. mempool_free(pmb, phba->mbox_mem_pool);
  2154. return;
  2155. }
  2156. vport_buff = (uint8_t *) vport_info;
  2157. do {
  2158. if (lpfc_dump_static_vport(phba, pmb, offset))
  2159. goto out;
  2160. pmb->vport = phba->pport;
  2161. rc = lpfc_sli_issue_mbox_wait(phba, pmb, LPFC_MBOX_TMO);
  2162. if ((rc != MBX_SUCCESS) || mb->mbxStatus) {
  2163. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  2164. "0544 lpfc_create_static_vport failed to"
  2165. " issue dump mailbox command ret 0x%x "
  2166. "status 0x%x\n",
  2167. rc, mb->mbxStatus);
  2168. goto out;
  2169. }
  2170. if (phba->sli_rev == LPFC_SLI_REV4) {
  2171. byte_count = pmb->u.mqe.un.mb_words[5];
  2172. mp = (struct lpfc_dmabuf *) pmb->context2;
  2173. if (byte_count > sizeof(struct static_vport_info) -
  2174. offset)
  2175. byte_count = sizeof(struct static_vport_info)
  2176. - offset;
  2177. memcpy(vport_buff + offset, mp->virt, byte_count);
  2178. offset += byte_count;
  2179. } else {
  2180. if (mb->un.varDmp.word_cnt >
  2181. sizeof(struct static_vport_info) - offset)
  2182. mb->un.varDmp.word_cnt =
  2183. sizeof(struct static_vport_info)
  2184. - offset;
  2185. byte_count = mb->un.varDmp.word_cnt;
  2186. lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET,
  2187. vport_buff + offset,
  2188. byte_count);
  2189. offset += byte_count;
  2190. }
  2191. } while (byte_count &&
  2192. offset < sizeof(struct static_vport_info));
  2193. if ((le32_to_cpu(vport_info->signature) != VPORT_INFO_SIG) ||
  2194. ((le32_to_cpu(vport_info->rev) & VPORT_INFO_REV_MASK)
  2195. != VPORT_INFO_REV)) {
  2196. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  2197. "0545 lpfc_create_static_vport bad"
  2198. " information header 0x%x 0x%x\n",
  2199. le32_to_cpu(vport_info->signature),
  2200. le32_to_cpu(vport_info->rev) & VPORT_INFO_REV_MASK);
  2201. goto out;
  2202. }
  2203. shost = lpfc_shost_from_vport(phba->pport);
  2204. for (i = 0; i < MAX_STATIC_VPORT_COUNT; i++) {
  2205. memset(&vport_id, 0, sizeof(vport_id));
  2206. vport_id.port_name = wwn_to_u64(vport_info->vport_list[i].wwpn);
  2207. vport_id.node_name = wwn_to_u64(vport_info->vport_list[i].wwnn);
  2208. if (!vport_id.port_name || !vport_id.node_name)
  2209. continue;
  2210. vport_id.roles = FC_PORT_ROLE_FCP_INITIATOR;
  2211. vport_id.vport_type = FC_PORTTYPE_NPIV;
  2212. vport_id.disable = false;
  2213. new_fc_vport = fc_vport_create(shost, 0, &vport_id);
  2214. if (!new_fc_vport) {
  2215. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  2216. "0546 lpfc_create_static_vport failed to"
  2217. " create vport\n");
  2218. continue;
  2219. }
  2220. vport = *(struct lpfc_vport **)new_fc_vport->dd_data;
  2221. vport->vport_flag |= STATIC_VPORT;
  2222. }
  2223. out:
  2224. kfree(vport_info);
  2225. if (rc != MBX_TIMEOUT) {
  2226. if (pmb->context2) {
  2227. mp = (struct lpfc_dmabuf *) pmb->context2;
  2228. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  2229. kfree(mp);
  2230. }
  2231. mempool_free(pmb, phba->mbox_mem_pool);
  2232. }
  2233. return;
  2234. }
  2235. /*
  2236. * This routine handles processing a Fabric REG_LOGIN mailbox
  2237. * command upon completion. It is setup in the LPFC_MBOXQ
  2238. * as the completion routine when the command is
  2239. * handed off to the SLI layer.
  2240. */
  2241. void
  2242. lpfc_mbx_cmpl_fabric_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  2243. {
  2244. struct lpfc_vport *vport = pmb->vport;
  2245. MAILBOX_t *mb = &pmb->u.mb;
  2246. struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
  2247. struct lpfc_nodelist *ndlp;
  2248. ndlp = (struct lpfc_nodelist *) pmb->context2;
  2249. pmb->context1 = NULL;
  2250. pmb->context2 = NULL;
  2251. if (mb->mbxStatus) {
  2252. lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
  2253. "0258 Register Fabric login error: 0x%x\n",
  2254. mb->mbxStatus);
  2255. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  2256. kfree(mp);
  2257. mempool_free(pmb, phba->mbox_mem_pool);
  2258. if (phba->fc_topology == TOPOLOGY_LOOP) {
  2259. /* FLOGI failed, use loop map to make discovery list */
  2260. lpfc_disc_list_loopmap(vport);
  2261. /* Start discovery */
  2262. lpfc_disc_start(vport);
  2263. /* Decrement the reference count to ndlp after the
  2264. * reference to the ndlp are done.
  2265. */
  2266. lpfc_nlp_put(ndlp);
  2267. return;
  2268. }
  2269. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  2270. /* Decrement the reference count to ndlp after the reference
  2271. * to the ndlp are done.
  2272. */
  2273. lpfc_nlp_put(ndlp);
  2274. return;
  2275. }
  2276. ndlp->nlp_rpi = mb->un.varWords[0];
  2277. ndlp->nlp_flag |= NLP_RPI_VALID;
  2278. ndlp->nlp_type |= NLP_FABRIC;
  2279. lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
  2280. if (vport->port_state == LPFC_FABRIC_CFG_LINK) {
  2281. lpfc_start_fdiscs(phba);
  2282. lpfc_do_scr_ns_plogi(phba, vport);
  2283. }
  2284. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  2285. kfree(mp);
  2286. mempool_free(pmb, phba->mbox_mem_pool);
  2287. /* Drop the reference count from the mbox at the end after
  2288. * all the current reference to the ndlp have been done.
  2289. */
  2290. lpfc_nlp_put(ndlp);
  2291. return;
  2292. }
  2293. /*
  2294. * This routine handles processing a NameServer REG_LOGIN mailbox
  2295. * command upon completion. It is setup in the LPFC_MBOXQ
  2296. * as the completion routine when the command is
  2297. * handed off to the SLI layer.
  2298. */
  2299. void
  2300. lpfc_mbx_cmpl_ns_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  2301. {
  2302. MAILBOX_t *mb = &pmb->u.mb;
  2303. struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
  2304. struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
  2305. struct lpfc_vport *vport = pmb->vport;
  2306. if (mb->mbxStatus) {
  2307. out:
  2308. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  2309. "0260 Register NameServer error: 0x%x\n",
  2310. mb->mbxStatus);
  2311. /* decrement the node reference count held for this
  2312. * callback function.
  2313. */
  2314. lpfc_nlp_put(ndlp);
  2315. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  2316. kfree(mp);
  2317. mempool_free(pmb, phba->mbox_mem_pool);
  2318. /* If no other thread is using the ndlp, free it */
  2319. lpfc_nlp_not_used(ndlp);
  2320. if (phba->fc_topology == TOPOLOGY_LOOP) {
  2321. /*
  2322. * RegLogin failed, use loop map to make discovery
  2323. * list
  2324. */
  2325. lpfc_disc_list_loopmap(vport);
  2326. /* Start discovery */
  2327. lpfc_disc_start(vport);
  2328. return;
  2329. }
  2330. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  2331. return;
  2332. }
  2333. pmb->context1 = NULL;
  2334. ndlp->nlp_rpi = mb->un.varWords[0];
  2335. ndlp->nlp_flag |= NLP_RPI_VALID;
  2336. ndlp->nlp_type |= NLP_FABRIC;
  2337. lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
  2338. if (vport->port_state < LPFC_VPORT_READY) {
  2339. /* Link up discovery requires Fabric registration. */
  2340. lpfc_ns_cmd(vport, SLI_CTNS_RFF_ID, 0, 0); /* Do this first! */
  2341. lpfc_ns_cmd(vport, SLI_CTNS_RNN_ID, 0, 0);
  2342. lpfc_ns_cmd(vport, SLI_CTNS_RSNN_NN, 0, 0);
  2343. lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0);
  2344. lpfc_ns_cmd(vport, SLI_CTNS_RFT_ID, 0, 0);
  2345. /* Issue SCR just before NameServer GID_FT Query */
  2346. lpfc_issue_els_scr(vport, SCR_DID, 0);
  2347. }
  2348. vport->fc_ns_retry = 0;
  2349. /* Good status, issue CT Request to NameServer */
  2350. if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, 0)) {
  2351. /* Cannot issue NameServer Query, so finish up discovery */
  2352. goto out;
  2353. }
  2354. /* decrement the node reference count held for this
  2355. * callback function.
  2356. */
  2357. lpfc_nlp_put(ndlp);
  2358. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  2359. kfree(mp);
  2360. mempool_free(pmb, phba->mbox_mem_pool);
  2361. return;
  2362. }
  2363. static void
  2364. lpfc_register_remote_port(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
  2365. {
  2366. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2367. struct fc_rport *rport;
  2368. struct lpfc_rport_data *rdata;
  2369. struct fc_rport_identifiers rport_ids;
  2370. struct lpfc_hba *phba = vport->phba;
  2371. /* Remote port has reappeared. Re-register w/ FC transport */
  2372. rport_ids.node_name = wwn_to_u64(ndlp->nlp_nodename.u.wwn);
  2373. rport_ids.port_name = wwn_to_u64(ndlp->nlp_portname.u.wwn);
  2374. rport_ids.port_id = ndlp->nlp_DID;
  2375. rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
  2376. /*
  2377. * We leave our node pointer in rport->dd_data when we unregister a
  2378. * FCP target port. But fc_remote_port_add zeros the space to which
  2379. * rport->dd_data points. So, if we're reusing a previously
  2380. * registered port, drop the reference that we took the last time we
  2381. * registered the port.
  2382. */
  2383. if (ndlp->rport && ndlp->rport->dd_data &&
  2384. ((struct lpfc_rport_data *) ndlp->rport->dd_data)->pnode == ndlp)
  2385. lpfc_nlp_put(ndlp);
  2386. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
  2387. "rport add: did:x%x flg:x%x type x%x",
  2388. ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type);
  2389. ndlp->rport = rport = fc_remote_port_add(shost, 0, &rport_ids);
  2390. if (!rport || !get_device(&rport->dev)) {
  2391. dev_printk(KERN_WARNING, &phba->pcidev->dev,
  2392. "Warning: fc_remote_port_add failed\n");
  2393. return;
  2394. }
  2395. /* initialize static port data */
  2396. rport->maxframe_size = ndlp->nlp_maxframe;
  2397. rport->supported_classes = ndlp->nlp_class_sup;
  2398. rdata = rport->dd_data;
  2399. rdata->pnode = lpfc_nlp_get(ndlp);
  2400. if (ndlp->nlp_type & NLP_FCP_TARGET)
  2401. rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
  2402. if (ndlp->nlp_type & NLP_FCP_INITIATOR)
  2403. rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
  2404. if (rport_ids.roles != FC_RPORT_ROLE_UNKNOWN)
  2405. fc_remote_port_rolechg(rport, rport_ids.roles);
  2406. if ((rport->scsi_target_id != -1) &&
  2407. (rport->scsi_target_id < LPFC_MAX_TARGET)) {
  2408. ndlp->nlp_sid = rport->scsi_target_id;
  2409. }
  2410. return;
  2411. }
  2412. static void
  2413. lpfc_unregister_remote_port(struct lpfc_nodelist *ndlp)
  2414. {
  2415. struct fc_rport *rport = ndlp->rport;
  2416. lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_RPORT,
  2417. "rport delete: did:x%x flg:x%x type x%x",
  2418. ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type);
  2419. fc_remote_port_delete(rport);
  2420. return;
  2421. }
  2422. static void
  2423. lpfc_nlp_counters(struct lpfc_vport *vport, int state, int count)
  2424. {
  2425. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2426. spin_lock_irq(shost->host_lock);
  2427. switch (state) {
  2428. case NLP_STE_UNUSED_NODE:
  2429. vport->fc_unused_cnt += count;
  2430. break;
  2431. case NLP_STE_PLOGI_ISSUE:
  2432. vport->fc_plogi_cnt += count;
  2433. break;
  2434. case NLP_STE_ADISC_ISSUE:
  2435. vport->fc_adisc_cnt += count;
  2436. break;
  2437. case NLP_STE_REG_LOGIN_ISSUE:
  2438. vport->fc_reglogin_cnt += count;
  2439. break;
  2440. case NLP_STE_PRLI_ISSUE:
  2441. vport->fc_prli_cnt += count;
  2442. break;
  2443. case NLP_STE_UNMAPPED_NODE:
  2444. vport->fc_unmap_cnt += count;
  2445. break;
  2446. case NLP_STE_MAPPED_NODE:
  2447. vport->fc_map_cnt += count;
  2448. break;
  2449. case NLP_STE_NPR_NODE:
  2450. vport->fc_npr_cnt += count;
  2451. break;
  2452. }
  2453. spin_unlock_irq(shost->host_lock);
  2454. }
  2455. static void
  2456. lpfc_nlp_state_cleanup(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  2457. int old_state, int new_state)
  2458. {
  2459. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2460. if (new_state == NLP_STE_UNMAPPED_NODE) {
  2461. ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
  2462. ndlp->nlp_flag &= ~NLP_NODEV_REMOVE;
  2463. ndlp->nlp_type |= NLP_FC_NODE;
  2464. }
  2465. if (new_state == NLP_STE_MAPPED_NODE)
  2466. ndlp->nlp_flag &= ~NLP_NODEV_REMOVE;
  2467. if (new_state == NLP_STE_NPR_NODE)
  2468. ndlp->nlp_flag &= ~NLP_RCV_PLOGI;
  2469. /* Transport interface */
  2470. if (ndlp->rport && (old_state == NLP_STE_MAPPED_NODE ||
  2471. old_state == NLP_STE_UNMAPPED_NODE)) {
  2472. vport->phba->nport_event_cnt++;
  2473. lpfc_unregister_remote_port(ndlp);
  2474. }
  2475. if (new_state == NLP_STE_MAPPED_NODE ||
  2476. new_state == NLP_STE_UNMAPPED_NODE) {
  2477. vport->phba->nport_event_cnt++;
  2478. /*
  2479. * Tell the fc transport about the port, if we haven't
  2480. * already. If we have, and it's a scsi entity, be
  2481. * sure to unblock any attached scsi devices
  2482. */
  2483. lpfc_register_remote_port(vport, ndlp);
  2484. }
  2485. if ((new_state == NLP_STE_MAPPED_NODE) &&
  2486. (vport->stat_data_enabled)) {
  2487. /*
  2488. * A new target is discovered, if there is no buffer for
  2489. * statistical data collection allocate buffer.
  2490. */
  2491. ndlp->lat_data = kcalloc(LPFC_MAX_BUCKET_COUNT,
  2492. sizeof(struct lpfc_scsicmd_bkt),
  2493. GFP_KERNEL);
  2494. if (!ndlp->lat_data)
  2495. lpfc_printf_vlog(vport, KERN_ERR, LOG_NODE,
  2496. "0286 lpfc_nlp_state_cleanup failed to "
  2497. "allocate statistical data buffer DID "
  2498. "0x%x\n", ndlp->nlp_DID);
  2499. }
  2500. /*
  2501. * if we added to Mapped list, but the remote port
  2502. * registration failed or assigned a target id outside
  2503. * our presentable range - move the node to the
  2504. * Unmapped List
  2505. */
  2506. if (new_state == NLP_STE_MAPPED_NODE &&
  2507. (!ndlp->rport ||
  2508. ndlp->rport->scsi_target_id == -1 ||
  2509. ndlp->rport->scsi_target_id >= LPFC_MAX_TARGET)) {
  2510. spin_lock_irq(shost->host_lock);
  2511. ndlp->nlp_flag |= NLP_TGT_NO_SCSIID;
  2512. spin_unlock_irq(shost->host_lock);
  2513. lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
  2514. }
  2515. }
  2516. static char *
  2517. lpfc_nlp_state_name(char *buffer, size_t size, int state)
  2518. {
  2519. static char *states[] = {
  2520. [NLP_STE_UNUSED_NODE] = "UNUSED",
  2521. [NLP_STE_PLOGI_ISSUE] = "PLOGI",
  2522. [NLP_STE_ADISC_ISSUE] = "ADISC",
  2523. [NLP_STE_REG_LOGIN_ISSUE] = "REGLOGIN",
  2524. [NLP_STE_PRLI_ISSUE] = "PRLI",
  2525. [NLP_STE_UNMAPPED_NODE] = "UNMAPPED",
  2526. [NLP_STE_MAPPED_NODE] = "MAPPED",
  2527. [NLP_STE_NPR_NODE] = "NPR",
  2528. };
  2529. if (state < NLP_STE_MAX_STATE && states[state])
  2530. strlcpy(buffer, states[state], size);
  2531. else
  2532. snprintf(buffer, size, "unknown (%d)", state);
  2533. return buffer;
  2534. }
  2535. void
  2536. lpfc_nlp_set_state(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  2537. int state)
  2538. {
  2539. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2540. int old_state = ndlp->nlp_state;
  2541. char name1[16], name2[16];
  2542. lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
  2543. "0904 NPort state transition x%06x, %s -> %s\n",
  2544. ndlp->nlp_DID,
  2545. lpfc_nlp_state_name(name1, sizeof(name1), old_state),
  2546. lpfc_nlp_state_name(name2, sizeof(name2), state));
  2547. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE,
  2548. "node statechg did:x%x old:%d ste:%d",
  2549. ndlp->nlp_DID, old_state, state);
  2550. if (old_state == NLP_STE_NPR_NODE &&
  2551. state != NLP_STE_NPR_NODE)
  2552. lpfc_cancel_retry_delay_tmo(vport, ndlp);
  2553. if (old_state == NLP_STE_UNMAPPED_NODE) {
  2554. ndlp->nlp_flag &= ~NLP_TGT_NO_SCSIID;
  2555. ndlp->nlp_type &= ~NLP_FC_NODE;
  2556. }
  2557. if (list_empty(&ndlp->nlp_listp)) {
  2558. spin_lock_irq(shost->host_lock);
  2559. list_add_tail(&ndlp->nlp_listp, &vport->fc_nodes);
  2560. spin_unlock_irq(shost->host_lock);
  2561. } else if (old_state)
  2562. lpfc_nlp_counters(vport, old_state, -1);
  2563. ndlp->nlp_state = state;
  2564. lpfc_nlp_counters(vport, state, 1);
  2565. lpfc_nlp_state_cleanup(vport, ndlp, old_state, state);
  2566. }
  2567. void
  2568. lpfc_enqueue_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
  2569. {
  2570. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2571. if (list_empty(&ndlp->nlp_listp)) {
  2572. spin_lock_irq(shost->host_lock);
  2573. list_add_tail(&ndlp->nlp_listp, &vport->fc_nodes);
  2574. spin_unlock_irq(shost->host_lock);
  2575. }
  2576. }
  2577. void
  2578. lpfc_dequeue_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
  2579. {
  2580. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2581. lpfc_cancel_retry_delay_tmo(vport, ndlp);
  2582. if (ndlp->nlp_state && !list_empty(&ndlp->nlp_listp))
  2583. lpfc_nlp_counters(vport, ndlp->nlp_state, -1);
  2584. spin_lock_irq(shost->host_lock);
  2585. list_del_init(&ndlp->nlp_listp);
  2586. spin_unlock_irq(shost->host_lock);
  2587. lpfc_nlp_state_cleanup(vport, ndlp, ndlp->nlp_state,
  2588. NLP_STE_UNUSED_NODE);
  2589. }
  2590. static void
  2591. lpfc_disable_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
  2592. {
  2593. lpfc_cancel_retry_delay_tmo(vport, ndlp);
  2594. if (ndlp->nlp_state && !list_empty(&ndlp->nlp_listp))
  2595. lpfc_nlp_counters(vport, ndlp->nlp_state, -1);
  2596. lpfc_nlp_state_cleanup(vport, ndlp, ndlp->nlp_state,
  2597. NLP_STE_UNUSED_NODE);
  2598. }
  2599. /**
  2600. * lpfc_initialize_node - Initialize all fields of node object
  2601. * @vport: Pointer to Virtual Port object.
  2602. * @ndlp: Pointer to FC node object.
  2603. * @did: FC_ID of the node.
  2604. *
  2605. * This function is always called when node object need to be initialized.
  2606. * It initializes all the fields of the node object. Although the reference
  2607. * to phba from @ndlp can be obtained indirectly through it's reference to
  2608. * @vport, a direct reference to phba is taken here by @ndlp. This is due
  2609. * to the life-span of the @ndlp might go beyond the existence of @vport as
  2610. * the final release of ndlp is determined by its reference count. And, the
  2611. * operation on @ndlp needs the reference to phba.
  2612. **/
  2613. static inline void
  2614. lpfc_initialize_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  2615. uint32_t did)
  2616. {
  2617. INIT_LIST_HEAD(&ndlp->els_retry_evt.evt_listp);
  2618. INIT_LIST_HEAD(&ndlp->dev_loss_evt.evt_listp);
  2619. init_timer(&ndlp->nlp_delayfunc);
  2620. ndlp->nlp_delayfunc.function = lpfc_els_retry_delay;
  2621. ndlp->nlp_delayfunc.data = (unsigned long)ndlp;
  2622. ndlp->nlp_DID = did;
  2623. ndlp->vport = vport;
  2624. ndlp->phba = vport->phba;
  2625. ndlp->nlp_sid = NLP_NO_SID;
  2626. kref_init(&ndlp->kref);
  2627. NLP_INT_NODE_ACT(ndlp);
  2628. atomic_set(&ndlp->cmd_pending, 0);
  2629. ndlp->cmd_qdepth = LPFC_MAX_TGT_QDEPTH;
  2630. }
  2631. struct lpfc_nodelist *
  2632. lpfc_enable_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  2633. int state)
  2634. {
  2635. struct lpfc_hba *phba = vport->phba;
  2636. uint32_t did;
  2637. unsigned long flags;
  2638. if (!ndlp)
  2639. return NULL;
  2640. spin_lock_irqsave(&phba->ndlp_lock, flags);
  2641. /* The ndlp should not be in memory free mode */
  2642. if (NLP_CHK_FREE_REQ(ndlp)) {
  2643. spin_unlock_irqrestore(&phba->ndlp_lock, flags);
  2644. lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE,
  2645. "0277 lpfc_enable_node: ndlp:x%p "
  2646. "usgmap:x%x refcnt:%d\n",
  2647. (void *)ndlp, ndlp->nlp_usg_map,
  2648. atomic_read(&ndlp->kref.refcount));
  2649. return NULL;
  2650. }
  2651. /* The ndlp should not already be in active mode */
  2652. if (NLP_CHK_NODE_ACT(ndlp)) {
  2653. spin_unlock_irqrestore(&phba->ndlp_lock, flags);
  2654. lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE,
  2655. "0278 lpfc_enable_node: ndlp:x%p "
  2656. "usgmap:x%x refcnt:%d\n",
  2657. (void *)ndlp, ndlp->nlp_usg_map,
  2658. atomic_read(&ndlp->kref.refcount));
  2659. return NULL;
  2660. }
  2661. /* Keep the original DID */
  2662. did = ndlp->nlp_DID;
  2663. /* re-initialize ndlp except of ndlp linked list pointer */
  2664. memset((((char *)ndlp) + sizeof (struct list_head)), 0,
  2665. sizeof (struct lpfc_nodelist) - sizeof (struct list_head));
  2666. lpfc_initialize_node(vport, ndlp, did);
  2667. spin_unlock_irqrestore(&phba->ndlp_lock, flags);
  2668. if (state != NLP_STE_UNUSED_NODE)
  2669. lpfc_nlp_set_state(vport, ndlp, state);
  2670. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE,
  2671. "node enable: did:x%x",
  2672. ndlp->nlp_DID, 0, 0);
  2673. return ndlp;
  2674. }
  2675. void
  2676. lpfc_drop_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
  2677. {
  2678. /*
  2679. * Use of lpfc_drop_node and UNUSED list: lpfc_drop_node should
  2680. * be used if we wish to issue the "last" lpfc_nlp_put() to remove
  2681. * the ndlp from the vport. The ndlp marked as UNUSED on the list
  2682. * until ALL other outstanding threads have completed. We check
  2683. * that the ndlp not already in the UNUSED state before we proceed.
  2684. */
  2685. if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
  2686. return;
  2687. lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNUSED_NODE);
  2688. lpfc_nlp_put(ndlp);
  2689. return;
  2690. }
  2691. /*
  2692. * Start / ReStart rescue timer for Discovery / RSCN handling
  2693. */
  2694. void
  2695. lpfc_set_disctmo(struct lpfc_vport *vport)
  2696. {
  2697. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2698. struct lpfc_hba *phba = vport->phba;
  2699. uint32_t tmo;
  2700. if (vport->port_state == LPFC_LOCAL_CFG_LINK) {
  2701. /* For FAN, timeout should be greater than edtov */
  2702. tmo = (((phba->fc_edtov + 999) / 1000) + 1);
  2703. } else {
  2704. /* Normal discovery timeout should be > than ELS/CT timeout
  2705. * FC spec states we need 3 * ratov for CT requests
  2706. */
  2707. tmo = ((phba->fc_ratov * 3) + 3);
  2708. }
  2709. if (!timer_pending(&vport->fc_disctmo)) {
  2710. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  2711. "set disc timer: tmo:x%x state:x%x flg:x%x",
  2712. tmo, vport->port_state, vport->fc_flag);
  2713. }
  2714. mod_timer(&vport->fc_disctmo, jiffies + HZ * tmo);
  2715. spin_lock_irq(shost->host_lock);
  2716. vport->fc_flag |= FC_DISC_TMO;
  2717. spin_unlock_irq(shost->host_lock);
  2718. /* Start Discovery Timer state <hba_state> */
  2719. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  2720. "0247 Start Discovery Timer state x%x "
  2721. "Data: x%x x%lx x%x x%x\n",
  2722. vport->port_state, tmo,
  2723. (unsigned long)&vport->fc_disctmo, vport->fc_plogi_cnt,
  2724. vport->fc_adisc_cnt);
  2725. return;
  2726. }
  2727. /*
  2728. * Cancel rescue timer for Discovery / RSCN handling
  2729. */
  2730. int
  2731. lpfc_can_disctmo(struct lpfc_vport *vport)
  2732. {
  2733. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2734. unsigned long iflags;
  2735. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  2736. "can disc timer: state:x%x rtry:x%x flg:x%x",
  2737. vport->port_state, vport->fc_ns_retry, vport->fc_flag);
  2738. /* Turn off discovery timer if its running */
  2739. if (vport->fc_flag & FC_DISC_TMO) {
  2740. spin_lock_irqsave(shost->host_lock, iflags);
  2741. vport->fc_flag &= ~FC_DISC_TMO;
  2742. spin_unlock_irqrestore(shost->host_lock, iflags);
  2743. del_timer_sync(&vport->fc_disctmo);
  2744. spin_lock_irqsave(&vport->work_port_lock, iflags);
  2745. vport->work_port_events &= ~WORKER_DISC_TMO;
  2746. spin_unlock_irqrestore(&vport->work_port_lock, iflags);
  2747. }
  2748. /* Cancel Discovery Timer state <hba_state> */
  2749. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  2750. "0248 Cancel Discovery Timer state x%x "
  2751. "Data: x%x x%x x%x\n",
  2752. vport->port_state, vport->fc_flag,
  2753. vport->fc_plogi_cnt, vport->fc_adisc_cnt);
  2754. return 0;
  2755. }
  2756. /*
  2757. * Check specified ring for outstanding IOCB on the SLI queue
  2758. * Return true if iocb matches the specified nport
  2759. */
  2760. int
  2761. lpfc_check_sli_ndlp(struct lpfc_hba *phba,
  2762. struct lpfc_sli_ring *pring,
  2763. struct lpfc_iocbq *iocb,
  2764. struct lpfc_nodelist *ndlp)
  2765. {
  2766. struct lpfc_sli *psli = &phba->sli;
  2767. IOCB_t *icmd = &iocb->iocb;
  2768. struct lpfc_vport *vport = ndlp->vport;
  2769. if (iocb->vport != vport)
  2770. return 0;
  2771. if (pring->ringno == LPFC_ELS_RING) {
  2772. switch (icmd->ulpCommand) {
  2773. case CMD_GEN_REQUEST64_CR:
  2774. if (iocb->context_un.ndlp == ndlp)
  2775. return 1;
  2776. case CMD_ELS_REQUEST64_CR:
  2777. if (icmd->un.elsreq64.remoteID == ndlp->nlp_DID)
  2778. return 1;
  2779. case CMD_XMIT_ELS_RSP64_CX:
  2780. if (iocb->context1 == (uint8_t *) ndlp)
  2781. return 1;
  2782. }
  2783. } else if (pring->ringno == psli->extra_ring) {
  2784. } else if (pring->ringno == psli->fcp_ring) {
  2785. /* Skip match check if waiting to relogin to FCP target */
  2786. if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
  2787. (ndlp->nlp_flag & NLP_DELAY_TMO)) {
  2788. return 0;
  2789. }
  2790. if (icmd->ulpContext == (volatile ushort)ndlp->nlp_rpi) {
  2791. return 1;
  2792. }
  2793. } else if (pring->ringno == psli->next_ring) {
  2794. }
  2795. return 0;
  2796. }
  2797. /*
  2798. * Free resources / clean up outstanding I/Os
  2799. * associated with nlp_rpi in the LPFC_NODELIST entry.
  2800. */
  2801. static int
  2802. lpfc_no_rpi(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
  2803. {
  2804. LIST_HEAD(completions);
  2805. struct lpfc_sli *psli;
  2806. struct lpfc_sli_ring *pring;
  2807. struct lpfc_iocbq *iocb, *next_iocb;
  2808. uint32_t i;
  2809. lpfc_fabric_abort_nport(ndlp);
  2810. /*
  2811. * Everything that matches on txcmplq will be returned
  2812. * by firmware with a no rpi error.
  2813. */
  2814. psli = &phba->sli;
  2815. if (ndlp->nlp_flag & NLP_RPI_VALID) {
  2816. /* Now process each ring */
  2817. for (i = 0; i < psli->num_rings; i++) {
  2818. pring = &psli->ring[i];
  2819. spin_lock_irq(&phba->hbalock);
  2820. list_for_each_entry_safe(iocb, next_iocb, &pring->txq,
  2821. list) {
  2822. /*
  2823. * Check to see if iocb matches the nport we are
  2824. * looking for
  2825. */
  2826. if ((lpfc_check_sli_ndlp(phba, pring, iocb,
  2827. ndlp))) {
  2828. /* It matches, so deque and call compl
  2829. with an error */
  2830. list_move_tail(&iocb->list,
  2831. &completions);
  2832. pring->txq_cnt--;
  2833. }
  2834. }
  2835. spin_unlock_irq(&phba->hbalock);
  2836. }
  2837. }
  2838. /* Cancel all the IOCBs from the completions list */
  2839. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  2840. IOERR_SLI_ABORTED);
  2841. return 0;
  2842. }
  2843. /*
  2844. * Free rpi associated with LPFC_NODELIST entry.
  2845. * This routine is called from lpfc_freenode(), when we are removing
  2846. * a LPFC_NODELIST entry. It is also called if the driver initiates a
  2847. * LOGO that completes successfully, and we are waiting to PLOGI back
  2848. * to the remote NPort. In addition, it is called after we receive
  2849. * and unsolicated ELS cmd, send back a rsp, the rsp completes and
  2850. * we are waiting to PLOGI back to the remote NPort.
  2851. */
  2852. int
  2853. lpfc_unreg_rpi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
  2854. {
  2855. struct lpfc_hba *phba = vport->phba;
  2856. LPFC_MBOXQ_t *mbox;
  2857. int rc;
  2858. if (ndlp->nlp_flag & NLP_RPI_VALID) {
  2859. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  2860. if (mbox) {
  2861. lpfc_unreg_login(phba, vport->vpi, ndlp->nlp_rpi, mbox);
  2862. mbox->vport = vport;
  2863. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  2864. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
  2865. if (rc == MBX_NOT_FINISHED)
  2866. mempool_free(mbox, phba->mbox_mem_pool);
  2867. }
  2868. lpfc_no_rpi(phba, ndlp);
  2869. ndlp->nlp_rpi = 0;
  2870. ndlp->nlp_flag &= ~NLP_RPI_VALID;
  2871. ndlp->nlp_flag &= ~NLP_NPR_ADISC;
  2872. return 1;
  2873. }
  2874. return 0;
  2875. }
  2876. void
  2877. lpfc_unreg_all_rpis(struct lpfc_vport *vport)
  2878. {
  2879. struct lpfc_hba *phba = vport->phba;
  2880. LPFC_MBOXQ_t *mbox;
  2881. int rc;
  2882. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  2883. if (mbox) {
  2884. lpfc_unreg_login(phba, vport->vpi, 0xffff, mbox);
  2885. mbox->vport = vport;
  2886. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  2887. mbox->context1 = NULL;
  2888. rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO);
  2889. if (rc != MBX_TIMEOUT)
  2890. mempool_free(mbox, phba->mbox_mem_pool);
  2891. if ((rc == MBX_TIMEOUT) || (rc == MBX_NOT_FINISHED))
  2892. lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX | LOG_VPORT,
  2893. "1836 Could not issue "
  2894. "unreg_login(all_rpis) status %d\n", rc);
  2895. }
  2896. }
  2897. void
  2898. lpfc_unreg_default_rpis(struct lpfc_vport *vport)
  2899. {
  2900. struct lpfc_hba *phba = vport->phba;
  2901. LPFC_MBOXQ_t *mbox;
  2902. int rc;
  2903. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  2904. if (mbox) {
  2905. lpfc_unreg_did(phba, vport->vpi, 0xffffffff, mbox);
  2906. mbox->vport = vport;
  2907. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  2908. mbox->context1 = NULL;
  2909. rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO);
  2910. if (rc != MBX_TIMEOUT)
  2911. mempool_free(mbox, phba->mbox_mem_pool);
  2912. if ((rc == MBX_TIMEOUT) || (rc == MBX_NOT_FINISHED))
  2913. lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX | LOG_VPORT,
  2914. "1815 Could not issue "
  2915. "unreg_did (default rpis) status %d\n",
  2916. rc);
  2917. }
  2918. }
  2919. /*
  2920. * Free resources associated with LPFC_NODELIST entry
  2921. * so it can be freed.
  2922. */
  2923. static int
  2924. lpfc_cleanup_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
  2925. {
  2926. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2927. struct lpfc_hba *phba = vport->phba;
  2928. LPFC_MBOXQ_t *mb, *nextmb;
  2929. struct lpfc_dmabuf *mp;
  2930. /* Cleanup node for NPort <nlp_DID> */
  2931. lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
  2932. "0900 Cleanup node for NPort x%x "
  2933. "Data: x%x x%x x%x\n",
  2934. ndlp->nlp_DID, ndlp->nlp_flag,
  2935. ndlp->nlp_state, ndlp->nlp_rpi);
  2936. if (NLP_CHK_FREE_REQ(ndlp)) {
  2937. lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE,
  2938. "0280 lpfc_cleanup_node: ndlp:x%p "
  2939. "usgmap:x%x refcnt:%d\n",
  2940. (void *)ndlp, ndlp->nlp_usg_map,
  2941. atomic_read(&ndlp->kref.refcount));
  2942. lpfc_dequeue_node(vport, ndlp);
  2943. } else {
  2944. lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE,
  2945. "0281 lpfc_cleanup_node: ndlp:x%p "
  2946. "usgmap:x%x refcnt:%d\n",
  2947. (void *)ndlp, ndlp->nlp_usg_map,
  2948. atomic_read(&ndlp->kref.refcount));
  2949. lpfc_disable_node(vport, ndlp);
  2950. }
  2951. /* cleanup any ndlp on mbox q waiting for reglogin cmpl */
  2952. if ((mb = phba->sli.mbox_active)) {
  2953. if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) &&
  2954. (ndlp == (struct lpfc_nodelist *) mb->context2)) {
  2955. mb->context2 = NULL;
  2956. mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  2957. }
  2958. }
  2959. spin_lock_irq(&phba->hbalock);
  2960. list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
  2961. if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) &&
  2962. (ndlp == (struct lpfc_nodelist *) mb->context2)) {
  2963. mp = (struct lpfc_dmabuf *) (mb->context1);
  2964. if (mp) {
  2965. __lpfc_mbuf_free(phba, mp->virt, mp->phys);
  2966. kfree(mp);
  2967. }
  2968. list_del(&mb->list);
  2969. mempool_free(mb, phba->mbox_mem_pool);
  2970. /* We shall not invoke the lpfc_nlp_put to decrement
  2971. * the ndlp reference count as we are in the process
  2972. * of lpfc_nlp_release.
  2973. */
  2974. }
  2975. }
  2976. spin_unlock_irq(&phba->hbalock);
  2977. lpfc_els_abort(phba, ndlp);
  2978. spin_lock_irq(shost->host_lock);
  2979. ndlp->nlp_flag &= ~NLP_DELAY_TMO;
  2980. spin_unlock_irq(shost->host_lock);
  2981. ndlp->nlp_last_elscmd = 0;
  2982. del_timer_sync(&ndlp->nlp_delayfunc);
  2983. list_del_init(&ndlp->els_retry_evt.evt_listp);
  2984. list_del_init(&ndlp->dev_loss_evt.evt_listp);
  2985. lpfc_unreg_rpi(vport, ndlp);
  2986. return 0;
  2987. }
  2988. /*
  2989. * Check to see if we can free the nlp back to the freelist.
  2990. * If we are in the middle of using the nlp in the discovery state
  2991. * machine, defer the free till we reach the end of the state machine.
  2992. */
  2993. static void
  2994. lpfc_nlp_remove(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
  2995. {
  2996. struct lpfc_hba *phba = vport->phba;
  2997. struct lpfc_rport_data *rdata;
  2998. LPFC_MBOXQ_t *mbox;
  2999. int rc;
  3000. lpfc_cancel_retry_delay_tmo(vport, ndlp);
  3001. if ((ndlp->nlp_flag & NLP_DEFER_RM) &&
  3002. !(ndlp->nlp_flag & NLP_RPI_VALID)) {
  3003. /* For this case we need to cleanup the default rpi
  3004. * allocated by the firmware.
  3005. */
  3006. if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL))
  3007. != NULL) {
  3008. rc = lpfc_reg_rpi(phba, vport->vpi, ndlp->nlp_DID,
  3009. (uint8_t *) &vport->fc_sparam, mbox, 0);
  3010. if (rc) {
  3011. mempool_free(mbox, phba->mbox_mem_pool);
  3012. }
  3013. else {
  3014. mbox->mbox_flag |= LPFC_MBX_IMED_UNREG;
  3015. mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
  3016. mbox->vport = vport;
  3017. mbox->context2 = NULL;
  3018. rc =lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
  3019. if (rc == MBX_NOT_FINISHED) {
  3020. mempool_free(mbox, phba->mbox_mem_pool);
  3021. }
  3022. }
  3023. }
  3024. }
  3025. lpfc_cleanup_node(vport, ndlp);
  3026. /*
  3027. * We can get here with a non-NULL ndlp->rport because when we
  3028. * unregister a rport we don't break the rport/node linkage. So if we
  3029. * do, make sure we don't leaving any dangling pointers behind.
  3030. */
  3031. if (ndlp->rport) {
  3032. rdata = ndlp->rport->dd_data;
  3033. rdata->pnode = NULL;
  3034. ndlp->rport = NULL;
  3035. }
  3036. }
  3037. static int
  3038. lpfc_matchdid(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  3039. uint32_t did)
  3040. {
  3041. D_ID mydid, ndlpdid, matchdid;
  3042. if (did == Bcast_DID)
  3043. return 0;
  3044. /* First check for Direct match */
  3045. if (ndlp->nlp_DID == did)
  3046. return 1;
  3047. /* Next check for area/domain identically equals 0 match */
  3048. mydid.un.word = vport->fc_myDID;
  3049. if ((mydid.un.b.domain == 0) && (mydid.un.b.area == 0)) {
  3050. return 0;
  3051. }
  3052. matchdid.un.word = did;
  3053. ndlpdid.un.word = ndlp->nlp_DID;
  3054. if (matchdid.un.b.id == ndlpdid.un.b.id) {
  3055. if ((mydid.un.b.domain == matchdid.un.b.domain) &&
  3056. (mydid.un.b.area == matchdid.un.b.area)) {
  3057. if ((ndlpdid.un.b.domain == 0) &&
  3058. (ndlpdid.un.b.area == 0)) {
  3059. if (ndlpdid.un.b.id)
  3060. return 1;
  3061. }
  3062. return 0;
  3063. }
  3064. matchdid.un.word = ndlp->nlp_DID;
  3065. if ((mydid.un.b.domain == ndlpdid.un.b.domain) &&
  3066. (mydid.un.b.area == ndlpdid.un.b.area)) {
  3067. if ((matchdid.un.b.domain == 0) &&
  3068. (matchdid.un.b.area == 0)) {
  3069. if (matchdid.un.b.id)
  3070. return 1;
  3071. }
  3072. }
  3073. }
  3074. return 0;
  3075. }
  3076. /* Search for a nodelist entry */
  3077. static struct lpfc_nodelist *
  3078. __lpfc_findnode_did(struct lpfc_vport *vport, uint32_t did)
  3079. {
  3080. struct lpfc_nodelist *ndlp;
  3081. uint32_t data1;
  3082. list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
  3083. if (lpfc_matchdid(vport, ndlp, did)) {
  3084. data1 = (((uint32_t) ndlp->nlp_state << 24) |
  3085. ((uint32_t) ndlp->nlp_xri << 16) |
  3086. ((uint32_t) ndlp->nlp_type << 8) |
  3087. ((uint32_t) ndlp->nlp_rpi & 0xff));
  3088. lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
  3089. "0929 FIND node DID "
  3090. "Data: x%p x%x x%x x%x\n",
  3091. ndlp, ndlp->nlp_DID,
  3092. ndlp->nlp_flag, data1);
  3093. return ndlp;
  3094. }
  3095. }
  3096. /* FIND node did <did> NOT FOUND */
  3097. lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
  3098. "0932 FIND node did x%x NOT FOUND.\n", did);
  3099. return NULL;
  3100. }
  3101. struct lpfc_nodelist *
  3102. lpfc_findnode_did(struct lpfc_vport *vport, uint32_t did)
  3103. {
  3104. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  3105. struct lpfc_nodelist *ndlp;
  3106. spin_lock_irq(shost->host_lock);
  3107. ndlp = __lpfc_findnode_did(vport, did);
  3108. spin_unlock_irq(shost->host_lock);
  3109. return ndlp;
  3110. }
  3111. struct lpfc_nodelist *
  3112. lpfc_setup_disc_node(struct lpfc_vport *vport, uint32_t did)
  3113. {
  3114. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  3115. struct lpfc_nodelist *ndlp;
  3116. ndlp = lpfc_findnode_did(vport, did);
  3117. if (!ndlp) {
  3118. if ((vport->fc_flag & FC_RSCN_MODE) != 0 &&
  3119. lpfc_rscn_payload_check(vport, did) == 0)
  3120. return NULL;
  3121. ndlp = (struct lpfc_nodelist *)
  3122. mempool_alloc(vport->phba->nlp_mem_pool, GFP_KERNEL);
  3123. if (!ndlp)
  3124. return NULL;
  3125. lpfc_nlp_init(vport, ndlp, did);
  3126. lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
  3127. spin_lock_irq(shost->host_lock);
  3128. ndlp->nlp_flag |= NLP_NPR_2B_DISC;
  3129. spin_unlock_irq(shost->host_lock);
  3130. return ndlp;
  3131. } else if (!NLP_CHK_NODE_ACT(ndlp)) {
  3132. ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_NPR_NODE);
  3133. if (!ndlp)
  3134. return NULL;
  3135. spin_lock_irq(shost->host_lock);
  3136. ndlp->nlp_flag |= NLP_NPR_2B_DISC;
  3137. spin_unlock_irq(shost->host_lock);
  3138. return ndlp;
  3139. }
  3140. if ((vport->fc_flag & FC_RSCN_MODE) &&
  3141. !(vport->fc_flag & FC_NDISC_ACTIVE)) {
  3142. if (lpfc_rscn_payload_check(vport, did)) {
  3143. /* If we've already recieved a PLOGI from this NPort
  3144. * we don't need to try to discover it again.
  3145. */
  3146. if (ndlp->nlp_flag & NLP_RCV_PLOGI)
  3147. return NULL;
  3148. /* Since this node is marked for discovery,
  3149. * delay timeout is not needed.
  3150. */
  3151. lpfc_cancel_retry_delay_tmo(vport, ndlp);
  3152. spin_lock_irq(shost->host_lock);
  3153. ndlp->nlp_flag |= NLP_NPR_2B_DISC;
  3154. spin_unlock_irq(shost->host_lock);
  3155. } else
  3156. ndlp = NULL;
  3157. } else {
  3158. /* If we've already recieved a PLOGI from this NPort,
  3159. * or we are already in the process of discovery on it,
  3160. * we don't need to try to discover it again.
  3161. */
  3162. if (ndlp->nlp_state == NLP_STE_ADISC_ISSUE ||
  3163. ndlp->nlp_state == NLP_STE_PLOGI_ISSUE ||
  3164. ndlp->nlp_flag & NLP_RCV_PLOGI)
  3165. return NULL;
  3166. lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
  3167. spin_lock_irq(shost->host_lock);
  3168. ndlp->nlp_flag |= NLP_NPR_2B_DISC;
  3169. spin_unlock_irq(shost->host_lock);
  3170. }
  3171. return ndlp;
  3172. }
  3173. /* Build a list of nodes to discover based on the loopmap */
  3174. void
  3175. lpfc_disc_list_loopmap(struct lpfc_vport *vport)
  3176. {
  3177. struct lpfc_hba *phba = vport->phba;
  3178. int j;
  3179. uint32_t alpa, index;
  3180. if (!lpfc_is_link_up(phba))
  3181. return;
  3182. if (phba->fc_topology != TOPOLOGY_LOOP)
  3183. return;
  3184. /* Check for loop map present or not */
  3185. if (phba->alpa_map[0]) {
  3186. for (j = 1; j <= phba->alpa_map[0]; j++) {
  3187. alpa = phba->alpa_map[j];
  3188. if (((vport->fc_myDID & 0xff) == alpa) || (alpa == 0))
  3189. continue;
  3190. lpfc_setup_disc_node(vport, alpa);
  3191. }
  3192. } else {
  3193. /* No alpamap, so try all alpa's */
  3194. for (j = 0; j < FC_MAXLOOP; j++) {
  3195. /* If cfg_scan_down is set, start from highest
  3196. * ALPA (0xef) to lowest (0x1).
  3197. */
  3198. if (vport->cfg_scan_down)
  3199. index = j;
  3200. else
  3201. index = FC_MAXLOOP - j - 1;
  3202. alpa = lpfcAlpaArray[index];
  3203. if ((vport->fc_myDID & 0xff) == alpa)
  3204. continue;
  3205. lpfc_setup_disc_node(vport, alpa);
  3206. }
  3207. }
  3208. return;
  3209. }
  3210. void
  3211. lpfc_issue_clear_la(struct lpfc_hba *phba, struct lpfc_vport *vport)
  3212. {
  3213. LPFC_MBOXQ_t *mbox;
  3214. struct lpfc_sli *psli = &phba->sli;
  3215. struct lpfc_sli_ring *extra_ring = &psli->ring[psli->extra_ring];
  3216. struct lpfc_sli_ring *fcp_ring = &psli->ring[psli->fcp_ring];
  3217. struct lpfc_sli_ring *next_ring = &psli->ring[psli->next_ring];
  3218. int rc;
  3219. /*
  3220. * if it's not a physical port or if we already send
  3221. * clear_la then don't send it.
  3222. */
  3223. if ((phba->link_state >= LPFC_CLEAR_LA) ||
  3224. (vport->port_type != LPFC_PHYSICAL_PORT) ||
  3225. (phba->sli_rev == LPFC_SLI_REV4))
  3226. return;
  3227. /* Link up discovery */
  3228. if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL)) != NULL) {
  3229. phba->link_state = LPFC_CLEAR_LA;
  3230. lpfc_clear_la(phba, mbox);
  3231. mbox->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
  3232. mbox->vport = vport;
  3233. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
  3234. if (rc == MBX_NOT_FINISHED) {
  3235. mempool_free(mbox, phba->mbox_mem_pool);
  3236. lpfc_disc_flush_list(vport);
  3237. extra_ring->flag &= ~LPFC_STOP_IOCB_EVENT;
  3238. fcp_ring->flag &= ~LPFC_STOP_IOCB_EVENT;
  3239. next_ring->flag &= ~LPFC_STOP_IOCB_EVENT;
  3240. phba->link_state = LPFC_HBA_ERROR;
  3241. }
  3242. }
  3243. }
  3244. /* Reg_vpi to tell firmware to resume normal operations */
  3245. void
  3246. lpfc_issue_reg_vpi(struct lpfc_hba *phba, struct lpfc_vport *vport)
  3247. {
  3248. LPFC_MBOXQ_t *regvpimbox;
  3249. regvpimbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3250. if (regvpimbox) {
  3251. lpfc_reg_vpi(vport, regvpimbox);
  3252. regvpimbox->mbox_cmpl = lpfc_mbx_cmpl_reg_vpi;
  3253. regvpimbox->vport = vport;
  3254. if (lpfc_sli_issue_mbox(phba, regvpimbox, MBX_NOWAIT)
  3255. == MBX_NOT_FINISHED) {
  3256. mempool_free(regvpimbox, phba->mbox_mem_pool);
  3257. }
  3258. }
  3259. }
  3260. /* Start Link up / RSCN discovery on NPR nodes */
  3261. void
  3262. lpfc_disc_start(struct lpfc_vport *vport)
  3263. {
  3264. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  3265. struct lpfc_hba *phba = vport->phba;
  3266. uint32_t num_sent;
  3267. uint32_t clear_la_pending;
  3268. int did_changed;
  3269. if (!lpfc_is_link_up(phba))
  3270. return;
  3271. if (phba->link_state == LPFC_CLEAR_LA)
  3272. clear_la_pending = 1;
  3273. else
  3274. clear_la_pending = 0;
  3275. if (vport->port_state < LPFC_VPORT_READY)
  3276. vport->port_state = LPFC_DISC_AUTH;
  3277. lpfc_set_disctmo(vport);
  3278. if (vport->fc_prevDID == vport->fc_myDID)
  3279. did_changed = 0;
  3280. else
  3281. did_changed = 1;
  3282. vport->fc_prevDID = vport->fc_myDID;
  3283. vport->num_disc_nodes = 0;
  3284. /* Start Discovery state <hba_state> */
  3285. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  3286. "0202 Start Discovery hba state x%x "
  3287. "Data: x%x x%x x%x\n",
  3288. vport->port_state, vport->fc_flag, vport->fc_plogi_cnt,
  3289. vport->fc_adisc_cnt);
  3290. /* First do ADISCs - if any */
  3291. num_sent = lpfc_els_disc_adisc(vport);
  3292. if (num_sent)
  3293. return;
  3294. /*
  3295. * For SLI3, cmpl_reg_vpi will set port_state to READY, and
  3296. * continue discovery.
  3297. */
  3298. if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
  3299. !(vport->fc_flag & FC_PT2PT) &&
  3300. !(vport->fc_flag & FC_RSCN_MODE) &&
  3301. (phba->sli_rev < LPFC_SLI_REV4)) {
  3302. lpfc_issue_reg_vpi(phba, vport);
  3303. return;
  3304. }
  3305. /*
  3306. * For SLI2, we need to set port_state to READY and continue
  3307. * discovery.
  3308. */
  3309. if (vport->port_state < LPFC_VPORT_READY && !clear_la_pending) {
  3310. /* If we get here, there is nothing to ADISC */
  3311. if (vport->port_type == LPFC_PHYSICAL_PORT)
  3312. lpfc_issue_clear_la(phba, vport);
  3313. if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
  3314. vport->num_disc_nodes = 0;
  3315. /* go thru NPR nodes and issue ELS PLOGIs */
  3316. if (vport->fc_npr_cnt)
  3317. lpfc_els_disc_plogi(vport);
  3318. if (!vport->num_disc_nodes) {
  3319. spin_lock_irq(shost->host_lock);
  3320. vport->fc_flag &= ~FC_NDISC_ACTIVE;
  3321. spin_unlock_irq(shost->host_lock);
  3322. lpfc_can_disctmo(vport);
  3323. }
  3324. }
  3325. vport->port_state = LPFC_VPORT_READY;
  3326. } else {
  3327. /* Next do PLOGIs - if any */
  3328. num_sent = lpfc_els_disc_plogi(vport);
  3329. if (num_sent)
  3330. return;
  3331. if (vport->fc_flag & FC_RSCN_MODE) {
  3332. /* Check to see if more RSCNs came in while we
  3333. * were processing this one.
  3334. */
  3335. if ((vport->fc_rscn_id_cnt == 0) &&
  3336. (!(vport->fc_flag & FC_RSCN_DISCOVERY))) {
  3337. spin_lock_irq(shost->host_lock);
  3338. vport->fc_flag &= ~FC_RSCN_MODE;
  3339. spin_unlock_irq(shost->host_lock);
  3340. lpfc_can_disctmo(vport);
  3341. } else
  3342. lpfc_els_handle_rscn(vport);
  3343. }
  3344. }
  3345. return;
  3346. }
  3347. /*
  3348. * Ignore completion for all IOCBs on tx and txcmpl queue for ELS
  3349. * ring the match the sppecified nodelist.
  3350. */
  3351. static void
  3352. lpfc_free_tx(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
  3353. {
  3354. LIST_HEAD(completions);
  3355. struct lpfc_sli *psli;
  3356. IOCB_t *icmd;
  3357. struct lpfc_iocbq *iocb, *next_iocb;
  3358. struct lpfc_sli_ring *pring;
  3359. psli = &phba->sli;
  3360. pring = &psli->ring[LPFC_ELS_RING];
  3361. /* Error matching iocb on txq or txcmplq
  3362. * First check the txq.
  3363. */
  3364. spin_lock_irq(&phba->hbalock);
  3365. list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
  3366. if (iocb->context1 != ndlp) {
  3367. continue;
  3368. }
  3369. icmd = &iocb->iocb;
  3370. if ((icmd->ulpCommand == CMD_ELS_REQUEST64_CR) ||
  3371. (icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX)) {
  3372. list_move_tail(&iocb->list, &completions);
  3373. pring->txq_cnt--;
  3374. }
  3375. }
  3376. /* Next check the txcmplq */
  3377. list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
  3378. if (iocb->context1 != ndlp) {
  3379. continue;
  3380. }
  3381. icmd = &iocb->iocb;
  3382. if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR ||
  3383. icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX) {
  3384. lpfc_sli_issue_abort_iotag(phba, pring, iocb);
  3385. }
  3386. }
  3387. spin_unlock_irq(&phba->hbalock);
  3388. /* Cancel all the IOCBs from the completions list */
  3389. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  3390. IOERR_SLI_ABORTED);
  3391. }
  3392. static void
  3393. lpfc_disc_flush_list(struct lpfc_vport *vport)
  3394. {
  3395. struct lpfc_nodelist *ndlp, *next_ndlp;
  3396. struct lpfc_hba *phba = vport->phba;
  3397. if (vport->fc_plogi_cnt || vport->fc_adisc_cnt) {
  3398. list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes,
  3399. nlp_listp) {
  3400. if (!NLP_CHK_NODE_ACT(ndlp))
  3401. continue;
  3402. if (ndlp->nlp_state == NLP_STE_PLOGI_ISSUE ||
  3403. ndlp->nlp_state == NLP_STE_ADISC_ISSUE) {
  3404. lpfc_free_tx(phba, ndlp);
  3405. }
  3406. }
  3407. }
  3408. }
  3409. void
  3410. lpfc_cleanup_discovery_resources(struct lpfc_vport *vport)
  3411. {
  3412. lpfc_els_flush_rscn(vport);
  3413. lpfc_els_flush_cmd(vport);
  3414. lpfc_disc_flush_list(vport);
  3415. }
  3416. /*****************************************************************************/
  3417. /*
  3418. * NAME: lpfc_disc_timeout
  3419. *
  3420. * FUNCTION: Fibre Channel driver discovery timeout routine.
  3421. *
  3422. * EXECUTION ENVIRONMENT: interrupt only
  3423. *
  3424. * CALLED FROM:
  3425. * Timer function
  3426. *
  3427. * RETURNS:
  3428. * none
  3429. */
  3430. /*****************************************************************************/
  3431. void
  3432. lpfc_disc_timeout(unsigned long ptr)
  3433. {
  3434. struct lpfc_vport *vport = (struct lpfc_vport *) ptr;
  3435. struct lpfc_hba *phba = vport->phba;
  3436. uint32_t tmo_posted;
  3437. unsigned long flags = 0;
  3438. if (unlikely(!phba))
  3439. return;
  3440. spin_lock_irqsave(&vport->work_port_lock, flags);
  3441. tmo_posted = vport->work_port_events & WORKER_DISC_TMO;
  3442. if (!tmo_posted)
  3443. vport->work_port_events |= WORKER_DISC_TMO;
  3444. spin_unlock_irqrestore(&vport->work_port_lock, flags);
  3445. if (!tmo_posted)
  3446. lpfc_worker_wake_up(phba);
  3447. return;
  3448. }
  3449. static void
  3450. lpfc_disc_timeout_handler(struct lpfc_vport *vport)
  3451. {
  3452. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  3453. struct lpfc_hba *phba = vport->phba;
  3454. struct lpfc_sli *psli = &phba->sli;
  3455. struct lpfc_nodelist *ndlp, *next_ndlp;
  3456. LPFC_MBOXQ_t *initlinkmbox;
  3457. int rc, clrlaerr = 0;
  3458. if (!(vport->fc_flag & FC_DISC_TMO))
  3459. return;
  3460. spin_lock_irq(shost->host_lock);
  3461. vport->fc_flag &= ~FC_DISC_TMO;
  3462. spin_unlock_irq(shost->host_lock);
  3463. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  3464. "disc timeout: state:x%x rtry:x%x flg:x%x",
  3465. vport->port_state, vport->fc_ns_retry, vport->fc_flag);
  3466. switch (vport->port_state) {
  3467. case LPFC_LOCAL_CFG_LINK:
  3468. /* port_state is identically LPFC_LOCAL_CFG_LINK while waiting for
  3469. * FAN
  3470. */
  3471. /* FAN timeout */
  3472. lpfc_printf_vlog(vport, KERN_WARNING, LOG_DISCOVERY,
  3473. "0221 FAN timeout\n");
  3474. /* Start discovery by sending FLOGI, clean up old rpis */
  3475. list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes,
  3476. nlp_listp) {
  3477. if (!NLP_CHK_NODE_ACT(ndlp))
  3478. continue;
  3479. if (ndlp->nlp_state != NLP_STE_NPR_NODE)
  3480. continue;
  3481. if (ndlp->nlp_type & NLP_FABRIC) {
  3482. /* Clean up the ndlp on Fabric connections */
  3483. lpfc_drop_node(vport, ndlp);
  3484. } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
  3485. /* Fail outstanding IO now since device
  3486. * is marked for PLOGI.
  3487. */
  3488. lpfc_unreg_rpi(vport, ndlp);
  3489. }
  3490. }
  3491. if (vport->port_state != LPFC_FLOGI) {
  3492. lpfc_initial_flogi(vport);
  3493. return;
  3494. }
  3495. break;
  3496. case LPFC_FDISC:
  3497. case LPFC_FLOGI:
  3498. /* port_state is identically LPFC_FLOGI while waiting for FLOGI cmpl */
  3499. /* Initial FLOGI timeout */
  3500. lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
  3501. "0222 Initial %s timeout\n",
  3502. vport->vpi ? "FDISC" : "FLOGI");
  3503. /* Assume no Fabric and go on with discovery.
  3504. * Check for outstanding ELS FLOGI to abort.
  3505. */
  3506. /* FLOGI failed, so just use loop map to make discovery list */
  3507. lpfc_disc_list_loopmap(vport);
  3508. /* Start discovery */
  3509. lpfc_disc_start(vport);
  3510. break;
  3511. case LPFC_FABRIC_CFG_LINK:
  3512. /* hba_state is identically LPFC_FABRIC_CFG_LINK while waiting for
  3513. NameServer login */
  3514. lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
  3515. "0223 Timeout while waiting for "
  3516. "NameServer login\n");
  3517. /* Next look for NameServer ndlp */
  3518. ndlp = lpfc_findnode_did(vport, NameServer_DID);
  3519. if (ndlp && NLP_CHK_NODE_ACT(ndlp))
  3520. lpfc_els_abort(phba, ndlp);
  3521. /* ReStart discovery */
  3522. goto restart_disc;
  3523. case LPFC_NS_QRY:
  3524. /* Check for wait for NameServer Rsp timeout */
  3525. lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
  3526. "0224 NameServer Query timeout "
  3527. "Data: x%x x%x\n",
  3528. vport->fc_ns_retry, LPFC_MAX_NS_RETRY);
  3529. if (vport->fc_ns_retry < LPFC_MAX_NS_RETRY) {
  3530. /* Try it one more time */
  3531. vport->fc_ns_retry++;
  3532. rc = lpfc_ns_cmd(vport, SLI_CTNS_GID_FT,
  3533. vport->fc_ns_retry, 0);
  3534. if (rc == 0)
  3535. break;
  3536. }
  3537. vport->fc_ns_retry = 0;
  3538. restart_disc:
  3539. /*
  3540. * Discovery is over.
  3541. * set port_state to PORT_READY if SLI2.
  3542. * cmpl_reg_vpi will set port_state to READY for SLI3.
  3543. */
  3544. if (phba->sli_rev < LPFC_SLI_REV4) {
  3545. if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
  3546. lpfc_issue_reg_vpi(phba, vport);
  3547. else { /* NPIV Not enabled */
  3548. lpfc_issue_clear_la(phba, vport);
  3549. vport->port_state = LPFC_VPORT_READY;
  3550. }
  3551. }
  3552. /* Setup and issue mailbox INITIALIZE LINK command */
  3553. initlinkmbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3554. if (!initlinkmbox) {
  3555. lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
  3556. "0206 Device Discovery "
  3557. "completion error\n");
  3558. phba->link_state = LPFC_HBA_ERROR;
  3559. break;
  3560. }
  3561. lpfc_linkdown(phba);
  3562. lpfc_init_link(phba, initlinkmbox, phba->cfg_topology,
  3563. phba->cfg_link_speed);
  3564. initlinkmbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0;
  3565. initlinkmbox->vport = vport;
  3566. initlinkmbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  3567. rc = lpfc_sli_issue_mbox(phba, initlinkmbox, MBX_NOWAIT);
  3568. lpfc_set_loopback_flag(phba);
  3569. if (rc == MBX_NOT_FINISHED)
  3570. mempool_free(initlinkmbox, phba->mbox_mem_pool);
  3571. break;
  3572. case LPFC_DISC_AUTH:
  3573. /* Node Authentication timeout */
  3574. lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
  3575. "0227 Node Authentication timeout\n");
  3576. lpfc_disc_flush_list(vport);
  3577. /*
  3578. * set port_state to PORT_READY if SLI2.
  3579. * cmpl_reg_vpi will set port_state to READY for SLI3.
  3580. */
  3581. if (phba->sli_rev < LPFC_SLI_REV4) {
  3582. if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
  3583. lpfc_issue_reg_vpi(phba, vport);
  3584. else { /* NPIV Not enabled */
  3585. lpfc_issue_clear_la(phba, vport);
  3586. vport->port_state = LPFC_VPORT_READY;
  3587. }
  3588. }
  3589. break;
  3590. case LPFC_VPORT_READY:
  3591. if (vport->fc_flag & FC_RSCN_MODE) {
  3592. lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
  3593. "0231 RSCN timeout Data: x%x "
  3594. "x%x\n",
  3595. vport->fc_ns_retry, LPFC_MAX_NS_RETRY);
  3596. /* Cleanup any outstanding ELS commands */
  3597. lpfc_els_flush_cmd(vport);
  3598. lpfc_els_flush_rscn(vport);
  3599. lpfc_disc_flush_list(vport);
  3600. }
  3601. break;
  3602. default:
  3603. lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
  3604. "0273 Unexpected discovery timeout, "
  3605. "vport State x%x\n", vport->port_state);
  3606. break;
  3607. }
  3608. switch (phba->link_state) {
  3609. case LPFC_CLEAR_LA:
  3610. /* CLEAR LA timeout */
  3611. lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
  3612. "0228 CLEAR LA timeout\n");
  3613. clrlaerr = 1;
  3614. break;
  3615. case LPFC_LINK_UP:
  3616. lpfc_issue_clear_la(phba, vport);
  3617. /* Drop thru */
  3618. case LPFC_LINK_UNKNOWN:
  3619. case LPFC_WARM_START:
  3620. case LPFC_INIT_START:
  3621. case LPFC_INIT_MBX_CMDS:
  3622. case LPFC_LINK_DOWN:
  3623. case LPFC_HBA_ERROR:
  3624. lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
  3625. "0230 Unexpected timeout, hba link "
  3626. "state x%x\n", phba->link_state);
  3627. clrlaerr = 1;
  3628. break;
  3629. case LPFC_HBA_READY:
  3630. break;
  3631. }
  3632. if (clrlaerr) {
  3633. lpfc_disc_flush_list(vport);
  3634. psli->ring[(psli->extra_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
  3635. psli->ring[(psli->fcp_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
  3636. psli->ring[(psli->next_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
  3637. vport->port_state = LPFC_VPORT_READY;
  3638. }
  3639. return;
  3640. }
  3641. /*
  3642. * This routine handles processing a NameServer REG_LOGIN mailbox
  3643. * command upon completion. It is setup in the LPFC_MBOXQ
  3644. * as the completion routine when the command is
  3645. * handed off to the SLI layer.
  3646. */
  3647. void
  3648. lpfc_mbx_cmpl_fdmi_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  3649. {
  3650. MAILBOX_t *mb = &pmb->u.mb;
  3651. struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
  3652. struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
  3653. struct lpfc_vport *vport = pmb->vport;
  3654. pmb->context1 = NULL;
  3655. ndlp->nlp_rpi = mb->un.varWords[0];
  3656. ndlp->nlp_flag |= NLP_RPI_VALID;
  3657. ndlp->nlp_type |= NLP_FABRIC;
  3658. lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
  3659. /*
  3660. * Start issuing Fabric-Device Management Interface (FDMI) command to
  3661. * 0xfffffa (FDMI well known port) or Delay issuing FDMI command if
  3662. * fdmi-on=2 (supporting RPA/hostnmae)
  3663. */
  3664. if (vport->cfg_fdmi_on == 1)
  3665. lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA);
  3666. else
  3667. mod_timer(&vport->fc_fdmitmo, jiffies + HZ * 60);
  3668. /* decrement the node reference count held for this callback
  3669. * function.
  3670. */
  3671. lpfc_nlp_put(ndlp);
  3672. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  3673. kfree(mp);
  3674. mempool_free(pmb, phba->mbox_mem_pool);
  3675. return;
  3676. }
  3677. static int
  3678. lpfc_filter_by_rpi(struct lpfc_nodelist *ndlp, void *param)
  3679. {
  3680. uint16_t *rpi = param;
  3681. return ndlp->nlp_rpi == *rpi;
  3682. }
  3683. static int
  3684. lpfc_filter_by_wwpn(struct lpfc_nodelist *ndlp, void *param)
  3685. {
  3686. return memcmp(&ndlp->nlp_portname, param,
  3687. sizeof(ndlp->nlp_portname)) == 0;
  3688. }
  3689. static struct lpfc_nodelist *
  3690. __lpfc_find_node(struct lpfc_vport *vport, node_filter filter, void *param)
  3691. {
  3692. struct lpfc_nodelist *ndlp;
  3693. list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
  3694. if (filter(ndlp, param))
  3695. return ndlp;
  3696. }
  3697. return NULL;
  3698. }
  3699. /*
  3700. * This routine looks up the ndlp lists for the given RPI. If rpi found it
  3701. * returns the node list element pointer else return NULL.
  3702. */
  3703. struct lpfc_nodelist *
  3704. __lpfc_findnode_rpi(struct lpfc_vport *vport, uint16_t rpi)
  3705. {
  3706. return __lpfc_find_node(vport, lpfc_filter_by_rpi, &rpi);
  3707. }
  3708. /*
  3709. * This routine looks up the ndlp lists for the given WWPN. If WWPN found it
  3710. * returns the node element list pointer else return NULL.
  3711. */
  3712. struct lpfc_nodelist *
  3713. lpfc_findnode_wwpn(struct lpfc_vport *vport, struct lpfc_name *wwpn)
  3714. {
  3715. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  3716. struct lpfc_nodelist *ndlp;
  3717. spin_lock_irq(shost->host_lock);
  3718. ndlp = __lpfc_find_node(vport, lpfc_filter_by_wwpn, wwpn);
  3719. spin_unlock_irq(shost->host_lock);
  3720. return ndlp;
  3721. }
  3722. void
  3723. lpfc_nlp_init(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  3724. uint32_t did)
  3725. {
  3726. memset(ndlp, 0, sizeof (struct lpfc_nodelist));
  3727. lpfc_initialize_node(vport, ndlp, did);
  3728. INIT_LIST_HEAD(&ndlp->nlp_listp);
  3729. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE,
  3730. "node init: did:x%x",
  3731. ndlp->nlp_DID, 0, 0);
  3732. return;
  3733. }
  3734. /* This routine releases all resources associated with a specifc NPort's ndlp
  3735. * and mempool_free's the nodelist.
  3736. */
  3737. static void
  3738. lpfc_nlp_release(struct kref *kref)
  3739. {
  3740. struct lpfc_hba *phba;
  3741. unsigned long flags;
  3742. struct lpfc_nodelist *ndlp = container_of(kref, struct lpfc_nodelist,
  3743. kref);
  3744. lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
  3745. "node release: did:x%x flg:x%x type:x%x",
  3746. ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type);
  3747. lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE,
  3748. "0279 lpfc_nlp_release: ndlp:x%p "
  3749. "usgmap:x%x refcnt:%d\n",
  3750. (void *)ndlp, ndlp->nlp_usg_map,
  3751. atomic_read(&ndlp->kref.refcount));
  3752. /* remove ndlp from action. */
  3753. lpfc_nlp_remove(ndlp->vport, ndlp);
  3754. /* clear the ndlp active flag for all release cases */
  3755. phba = ndlp->phba;
  3756. spin_lock_irqsave(&phba->ndlp_lock, flags);
  3757. NLP_CLR_NODE_ACT(ndlp);
  3758. spin_unlock_irqrestore(&phba->ndlp_lock, flags);
  3759. /* free ndlp memory for final ndlp release */
  3760. if (NLP_CHK_FREE_REQ(ndlp)) {
  3761. kfree(ndlp->lat_data);
  3762. mempool_free(ndlp, ndlp->phba->nlp_mem_pool);
  3763. }
  3764. }
  3765. /* This routine bumps the reference count for a ndlp structure to ensure
  3766. * that one discovery thread won't free a ndlp while another discovery thread
  3767. * is using it.
  3768. */
  3769. struct lpfc_nodelist *
  3770. lpfc_nlp_get(struct lpfc_nodelist *ndlp)
  3771. {
  3772. struct lpfc_hba *phba;
  3773. unsigned long flags;
  3774. if (ndlp) {
  3775. lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
  3776. "node get: did:x%x flg:x%x refcnt:x%x",
  3777. ndlp->nlp_DID, ndlp->nlp_flag,
  3778. atomic_read(&ndlp->kref.refcount));
  3779. /* The check of ndlp usage to prevent incrementing the
  3780. * ndlp reference count that is in the process of being
  3781. * released.
  3782. */
  3783. phba = ndlp->phba;
  3784. spin_lock_irqsave(&phba->ndlp_lock, flags);
  3785. if (!NLP_CHK_NODE_ACT(ndlp) || NLP_CHK_FREE_ACK(ndlp)) {
  3786. spin_unlock_irqrestore(&phba->ndlp_lock, flags);
  3787. lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_NODE,
  3788. "0276 lpfc_nlp_get: ndlp:x%p "
  3789. "usgmap:x%x refcnt:%d\n",
  3790. (void *)ndlp, ndlp->nlp_usg_map,
  3791. atomic_read(&ndlp->kref.refcount));
  3792. return NULL;
  3793. } else
  3794. kref_get(&ndlp->kref);
  3795. spin_unlock_irqrestore(&phba->ndlp_lock, flags);
  3796. }
  3797. return ndlp;
  3798. }
  3799. /* This routine decrements the reference count for a ndlp structure. If the
  3800. * count goes to 0, this indicates the the associated nodelist should be
  3801. * freed. Returning 1 indicates the ndlp resource has been released; on the
  3802. * other hand, returning 0 indicates the ndlp resource has not been released
  3803. * yet.
  3804. */
  3805. int
  3806. lpfc_nlp_put(struct lpfc_nodelist *ndlp)
  3807. {
  3808. struct lpfc_hba *phba;
  3809. unsigned long flags;
  3810. if (!ndlp)
  3811. return 1;
  3812. lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
  3813. "node put: did:x%x flg:x%x refcnt:x%x",
  3814. ndlp->nlp_DID, ndlp->nlp_flag,
  3815. atomic_read(&ndlp->kref.refcount));
  3816. phba = ndlp->phba;
  3817. spin_lock_irqsave(&phba->ndlp_lock, flags);
  3818. /* Check the ndlp memory free acknowledge flag to avoid the
  3819. * possible race condition that kref_put got invoked again
  3820. * after previous one has done ndlp memory free.
  3821. */
  3822. if (NLP_CHK_FREE_ACK(ndlp)) {
  3823. spin_unlock_irqrestore(&phba->ndlp_lock, flags);
  3824. lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_NODE,
  3825. "0274 lpfc_nlp_put: ndlp:x%p "
  3826. "usgmap:x%x refcnt:%d\n",
  3827. (void *)ndlp, ndlp->nlp_usg_map,
  3828. atomic_read(&ndlp->kref.refcount));
  3829. return 1;
  3830. }
  3831. /* Check the ndlp inactivate log flag to avoid the possible
  3832. * race condition that kref_put got invoked again after ndlp
  3833. * is already in inactivating state.
  3834. */
  3835. if (NLP_CHK_IACT_REQ(ndlp)) {
  3836. spin_unlock_irqrestore(&phba->ndlp_lock, flags);
  3837. lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_NODE,
  3838. "0275 lpfc_nlp_put: ndlp:x%p "
  3839. "usgmap:x%x refcnt:%d\n",
  3840. (void *)ndlp, ndlp->nlp_usg_map,
  3841. atomic_read(&ndlp->kref.refcount));
  3842. return 1;
  3843. }
  3844. /* For last put, mark the ndlp usage flags to make sure no
  3845. * other kref_get and kref_put on the same ndlp shall get
  3846. * in between the process when the final kref_put has been
  3847. * invoked on this ndlp.
  3848. */
  3849. if (atomic_read(&ndlp->kref.refcount) == 1) {
  3850. /* Indicate ndlp is put to inactive state. */
  3851. NLP_SET_IACT_REQ(ndlp);
  3852. /* Acknowledge ndlp memory free has been seen. */
  3853. if (NLP_CHK_FREE_REQ(ndlp))
  3854. NLP_SET_FREE_ACK(ndlp);
  3855. }
  3856. spin_unlock_irqrestore(&phba->ndlp_lock, flags);
  3857. /* Note, the kref_put returns 1 when decrementing a reference
  3858. * count that was 1, it invokes the release callback function,
  3859. * but it still left the reference count as 1 (not actually
  3860. * performs the last decrementation). Otherwise, it actually
  3861. * decrements the reference count and returns 0.
  3862. */
  3863. return kref_put(&ndlp->kref, lpfc_nlp_release);
  3864. }
  3865. /* This routine free's the specified nodelist if it is not in use
  3866. * by any other discovery thread. This routine returns 1 if the
  3867. * ndlp has been freed. A return value of 0 indicates the ndlp is
  3868. * not yet been released.
  3869. */
  3870. int
  3871. lpfc_nlp_not_used(struct lpfc_nodelist *ndlp)
  3872. {
  3873. lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
  3874. "node not used: did:x%x flg:x%x refcnt:x%x",
  3875. ndlp->nlp_DID, ndlp->nlp_flag,
  3876. atomic_read(&ndlp->kref.refcount));
  3877. if (atomic_read(&ndlp->kref.refcount) == 1)
  3878. if (lpfc_nlp_put(ndlp))
  3879. return 1;
  3880. return 0;
  3881. }
  3882. /**
  3883. * lpfc_fcf_inuse - Check if FCF can be unregistered.
  3884. * @phba: Pointer to hba context object.
  3885. *
  3886. * This function iterate through all FC nodes associated
  3887. * will all vports to check if there is any node with
  3888. * fc_rports associated with it. If there is an fc_rport
  3889. * associated with the node, then the node is either in
  3890. * discovered state or its devloss_timer is pending.
  3891. */
  3892. static int
  3893. lpfc_fcf_inuse(struct lpfc_hba *phba)
  3894. {
  3895. struct lpfc_vport **vports;
  3896. int i, ret = 0;
  3897. struct lpfc_nodelist *ndlp;
  3898. struct Scsi_Host *shost;
  3899. vports = lpfc_create_vport_work_array(phba);
  3900. for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
  3901. shost = lpfc_shost_from_vport(vports[i]);
  3902. spin_lock_irq(shost->host_lock);
  3903. list_for_each_entry(ndlp, &vports[i]->fc_nodes, nlp_listp) {
  3904. if (NLP_CHK_NODE_ACT(ndlp) && ndlp->rport &&
  3905. (ndlp->rport->roles & FC_RPORT_ROLE_FCP_TARGET)) {
  3906. ret = 1;
  3907. spin_unlock_irq(shost->host_lock);
  3908. goto out;
  3909. } else {
  3910. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  3911. "2624 RPI %x DID %x flg %x still "
  3912. "logged in\n",
  3913. ndlp->nlp_rpi, ndlp->nlp_DID,
  3914. ndlp->nlp_flag);
  3915. if (ndlp->nlp_flag & NLP_RPI_VALID)
  3916. ret = 1;
  3917. }
  3918. }
  3919. spin_unlock_irq(shost->host_lock);
  3920. }
  3921. out:
  3922. lpfc_destroy_vport_work_array(phba, vports);
  3923. return ret;
  3924. }
  3925. /**
  3926. * lpfc_unregister_vfi_cmpl - Completion handler for unreg vfi.
  3927. * @phba: Pointer to hba context object.
  3928. * @mboxq: Pointer to mailbox object.
  3929. *
  3930. * This function frees memory associated with the mailbox command.
  3931. */
  3932. static void
  3933. lpfc_unregister_vfi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  3934. {
  3935. struct lpfc_vport *vport = mboxq->vport;
  3936. if (mboxq->u.mb.mbxStatus) {
  3937. lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
  3938. "2555 UNREG_VFI mbxStatus error x%x "
  3939. "HBA state x%x\n",
  3940. mboxq->u.mb.mbxStatus, vport->port_state);
  3941. }
  3942. mempool_free(mboxq, phba->mbox_mem_pool);
  3943. return;
  3944. }
  3945. /**
  3946. * lpfc_unregister_fcfi_cmpl - Completion handler for unreg fcfi.
  3947. * @phba: Pointer to hba context object.
  3948. * @mboxq: Pointer to mailbox object.
  3949. *
  3950. * This function frees memory associated with the mailbox command.
  3951. */
  3952. static void
  3953. lpfc_unregister_fcfi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  3954. {
  3955. struct lpfc_vport *vport = mboxq->vport;
  3956. if (mboxq->u.mb.mbxStatus) {
  3957. lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
  3958. "2550 UNREG_FCFI mbxStatus error x%x "
  3959. "HBA state x%x\n",
  3960. mboxq->u.mb.mbxStatus, vport->port_state);
  3961. }
  3962. mempool_free(mboxq, phba->mbox_mem_pool);
  3963. return;
  3964. }
  3965. /**
  3966. * lpfc_unregister_unused_fcf - Unregister FCF if all devices are disconnected.
  3967. * @phba: Pointer to hba context object.
  3968. *
  3969. * This function check if there are any connected remote port for the FCF and
  3970. * if all the devices are disconnected, this function unregister FCFI.
  3971. * This function also tries to use another FCF for discovery.
  3972. */
  3973. void
  3974. lpfc_unregister_unused_fcf(struct lpfc_hba *phba)
  3975. {
  3976. LPFC_MBOXQ_t *mbox;
  3977. int rc;
  3978. struct lpfc_vport **vports;
  3979. int i;
  3980. spin_lock_irq(&phba->hbalock);
  3981. /*
  3982. * If HBA is not running in FIP mode or
  3983. * If HBA does not support FCoE or
  3984. * If FCF is not registered.
  3985. * do nothing.
  3986. */
  3987. if (!(phba->hba_flag & HBA_FCOE_SUPPORT) ||
  3988. !(phba->fcf.fcf_flag & FCF_REGISTERED) ||
  3989. (!(phba->hba_flag & HBA_FIP_SUPPORT))) {
  3990. spin_unlock_irq(&phba->hbalock);
  3991. return;
  3992. }
  3993. spin_unlock_irq(&phba->hbalock);
  3994. if (lpfc_fcf_inuse(phba))
  3995. return;
  3996. /* At this point, all discovery is aborted */
  3997. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  3998. /* Unregister VPIs */
  3999. vports = lpfc_create_vport_work_array(phba);
  4000. if (vports &&
  4001. (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED))
  4002. for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
  4003. lpfc_mbx_unreg_vpi(vports[i]);
  4004. vports[i]->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
  4005. vports[i]->vpi_state &= ~LPFC_VPI_REGISTERED;
  4006. }
  4007. lpfc_destroy_vport_work_array(phba, vports);
  4008. /* Unregister VFI */
  4009. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  4010. if (!mbox) {
  4011. lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
  4012. "2556 UNREG_VFI mbox allocation failed"
  4013. "HBA state x%x\n",
  4014. phba->pport->port_state);
  4015. return;
  4016. }
  4017. lpfc_unreg_vfi(mbox, phba->pport);
  4018. mbox->vport = phba->pport;
  4019. mbox->mbox_cmpl = lpfc_unregister_vfi_cmpl;
  4020. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
  4021. if (rc == MBX_NOT_FINISHED) {
  4022. lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
  4023. "2557 UNREG_VFI issue mbox failed rc x%x "
  4024. "HBA state x%x\n",
  4025. rc, phba->pport->port_state);
  4026. mempool_free(mbox, phba->mbox_mem_pool);
  4027. return;
  4028. }
  4029. /* Unregister FCF */
  4030. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  4031. if (!mbox) {
  4032. lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
  4033. "2551 UNREG_FCFI mbox allocation failed"
  4034. "HBA state x%x\n",
  4035. phba->pport->port_state);
  4036. return;
  4037. }
  4038. lpfc_unreg_fcfi(mbox, phba->fcf.fcfi);
  4039. mbox->vport = phba->pport;
  4040. mbox->mbox_cmpl = lpfc_unregister_fcfi_cmpl;
  4041. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
  4042. if (rc == MBX_NOT_FINISHED) {
  4043. lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
  4044. "2552 UNREG_FCFI issue mbox failed rc x%x "
  4045. "HBA state x%x\n",
  4046. rc, phba->pport->port_state);
  4047. mempool_free(mbox, phba->mbox_mem_pool);
  4048. return;
  4049. }
  4050. spin_lock_irq(&phba->hbalock);
  4051. phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_REGISTERED |
  4052. FCF_DISCOVERED | FCF_BOOT_ENABLE | FCF_IN_USE |
  4053. FCF_VALID_VLAN);
  4054. spin_unlock_irq(&phba->hbalock);
  4055. /*
  4056. * If driver is not unloading, check if there is any other
  4057. * FCF record that can be used for discovery.
  4058. */
  4059. if ((phba->pport->load_flag & FC_UNLOADING) ||
  4060. (phba->link_state < LPFC_LINK_UP))
  4061. return;
  4062. rc = lpfc_sli4_read_fcf_record(phba, LPFC_FCOE_FCF_GET_FIRST);
  4063. if (rc)
  4064. lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
  4065. "2553 lpfc_unregister_unused_fcf failed to read FCF"
  4066. " record HBA state x%x\n",
  4067. phba->pport->port_state);
  4068. }
  4069. /**
  4070. * lpfc_read_fcf_conn_tbl - Create driver FCF connection table.
  4071. * @phba: Pointer to hba context object.
  4072. * @buff: Buffer containing the FCF connection table as in the config
  4073. * region.
  4074. * This function create driver data structure for the FCF connection
  4075. * record table read from config region 23.
  4076. */
  4077. static void
  4078. lpfc_read_fcf_conn_tbl(struct lpfc_hba *phba,
  4079. uint8_t *buff)
  4080. {
  4081. struct lpfc_fcf_conn_entry *conn_entry, *next_conn_entry;
  4082. struct lpfc_fcf_conn_hdr *conn_hdr;
  4083. struct lpfc_fcf_conn_rec *conn_rec;
  4084. uint32_t record_count;
  4085. int i;
  4086. /* Free the current connect table */
  4087. list_for_each_entry_safe(conn_entry, next_conn_entry,
  4088. &phba->fcf_conn_rec_list, list) {
  4089. list_del_init(&conn_entry->list);
  4090. kfree(conn_entry);
  4091. }
  4092. conn_hdr = (struct lpfc_fcf_conn_hdr *) buff;
  4093. record_count = conn_hdr->length * sizeof(uint32_t)/
  4094. sizeof(struct lpfc_fcf_conn_rec);
  4095. conn_rec = (struct lpfc_fcf_conn_rec *)
  4096. (buff + sizeof(struct lpfc_fcf_conn_hdr));
  4097. for (i = 0; i < record_count; i++) {
  4098. if (!(conn_rec[i].flags & FCFCNCT_VALID))
  4099. continue;
  4100. conn_entry = kzalloc(sizeof(struct lpfc_fcf_conn_entry),
  4101. GFP_KERNEL);
  4102. if (!conn_entry) {
  4103. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4104. "2566 Failed to allocate connection"
  4105. " table entry\n");
  4106. return;
  4107. }
  4108. memcpy(&conn_entry->conn_rec, &conn_rec[i],
  4109. sizeof(struct lpfc_fcf_conn_rec));
  4110. conn_entry->conn_rec.vlan_tag =
  4111. le16_to_cpu(conn_entry->conn_rec.vlan_tag) & 0xFFF;
  4112. conn_entry->conn_rec.flags =
  4113. le16_to_cpu(conn_entry->conn_rec.flags);
  4114. list_add_tail(&conn_entry->list,
  4115. &phba->fcf_conn_rec_list);
  4116. }
  4117. }
  4118. /**
  4119. * lpfc_read_fcoe_param - Read FCoe parameters from conf region..
  4120. * @phba: Pointer to hba context object.
  4121. * @buff: Buffer containing the FCoE parameter data structure.
  4122. *
  4123. * This function update driver data structure with config
  4124. * parameters read from config region 23.
  4125. */
  4126. static void
  4127. lpfc_read_fcoe_param(struct lpfc_hba *phba,
  4128. uint8_t *buff)
  4129. {
  4130. struct lpfc_fip_param_hdr *fcoe_param_hdr;
  4131. struct lpfc_fcoe_params *fcoe_param;
  4132. fcoe_param_hdr = (struct lpfc_fip_param_hdr *)
  4133. buff;
  4134. fcoe_param = (struct lpfc_fcoe_params *)
  4135. (buff + sizeof(struct lpfc_fip_param_hdr));
  4136. if ((fcoe_param_hdr->parm_version != FIPP_VERSION) ||
  4137. (fcoe_param_hdr->length != FCOE_PARAM_LENGTH))
  4138. return;
  4139. if (fcoe_param_hdr->parm_flags & FIPP_VLAN_VALID) {
  4140. phba->valid_vlan = 1;
  4141. phba->vlan_id = le16_to_cpu(fcoe_param->vlan_tag) &
  4142. 0xFFF;
  4143. }
  4144. phba->fc_map[0] = fcoe_param->fc_map[0];
  4145. phba->fc_map[1] = fcoe_param->fc_map[1];
  4146. phba->fc_map[2] = fcoe_param->fc_map[2];
  4147. return;
  4148. }
  4149. /**
  4150. * lpfc_get_rec_conf23 - Get a record type in config region data.
  4151. * @buff: Buffer containing config region 23 data.
  4152. * @size: Size of the data buffer.
  4153. * @rec_type: Record type to be searched.
  4154. *
  4155. * This function searches config region data to find the begining
  4156. * of the record specified by record_type. If record found, this
  4157. * function return pointer to the record else return NULL.
  4158. */
  4159. static uint8_t *
  4160. lpfc_get_rec_conf23(uint8_t *buff, uint32_t size, uint8_t rec_type)
  4161. {
  4162. uint32_t offset = 0, rec_length;
  4163. if ((buff[0] == LPFC_REGION23_LAST_REC) ||
  4164. (size < sizeof(uint32_t)))
  4165. return NULL;
  4166. rec_length = buff[offset + 1];
  4167. /*
  4168. * One TLV record has one word header and number of data words
  4169. * specified in the rec_length field of the record header.
  4170. */
  4171. while ((offset + rec_length * sizeof(uint32_t) + sizeof(uint32_t))
  4172. <= size) {
  4173. if (buff[offset] == rec_type)
  4174. return &buff[offset];
  4175. if (buff[offset] == LPFC_REGION23_LAST_REC)
  4176. return NULL;
  4177. offset += rec_length * sizeof(uint32_t) + sizeof(uint32_t);
  4178. rec_length = buff[offset + 1];
  4179. }
  4180. return NULL;
  4181. }
  4182. /**
  4183. * lpfc_parse_fcoe_conf - Parse FCoE config data read from config region 23.
  4184. * @phba: Pointer to lpfc_hba data structure.
  4185. * @buff: Buffer containing config region 23 data.
  4186. * @size: Size of the data buffer.
  4187. *
  4188. * This fuction parse the FCoE config parameters in config region 23 and
  4189. * populate driver data structure with the parameters.
  4190. */
  4191. void
  4192. lpfc_parse_fcoe_conf(struct lpfc_hba *phba,
  4193. uint8_t *buff,
  4194. uint32_t size)
  4195. {
  4196. uint32_t offset = 0, rec_length;
  4197. uint8_t *rec_ptr;
  4198. /*
  4199. * If data size is less than 2 words signature and version cannot be
  4200. * verified.
  4201. */
  4202. if (size < 2*sizeof(uint32_t))
  4203. return;
  4204. /* Check the region signature first */
  4205. if (memcmp(buff, LPFC_REGION23_SIGNATURE, 4)) {
  4206. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4207. "2567 Config region 23 has bad signature\n");
  4208. return;
  4209. }
  4210. offset += 4;
  4211. /* Check the data structure version */
  4212. if (buff[offset] != LPFC_REGION23_VERSION) {
  4213. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4214. "2568 Config region 23 has bad version\n");
  4215. return;
  4216. }
  4217. offset += 4;
  4218. rec_length = buff[offset + 1];
  4219. /* Read FCoE param record */
  4220. rec_ptr = lpfc_get_rec_conf23(&buff[offset],
  4221. size - offset, FCOE_PARAM_TYPE);
  4222. if (rec_ptr)
  4223. lpfc_read_fcoe_param(phba, rec_ptr);
  4224. /* Read FCF connection table */
  4225. rec_ptr = lpfc_get_rec_conf23(&buff[offset],
  4226. size - offset, FCOE_CONN_TBL_TYPE);
  4227. if (rec_ptr)
  4228. lpfc_read_fcf_conn_tbl(phba, rec_ptr);
  4229. }