lpfc_hbadisc.c 133 KB

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