lpfc_els.c 138 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018
  1. /*******************************************************************
  2. * This file is part of the Emulex Linux Device Driver for *
  3. * Fibre Channel Host Bus Adapters. *
  4. * Copyright (C) 2004-2008 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. /* See Fibre Channel protocol T11 FC-LS for details */
  22. #include <linux/blkdev.h>
  23. #include <linux/pci.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_hw.h"
  30. #include "lpfc_sli.h"
  31. #include "lpfc_disc.h"
  32. #include "lpfc_scsi.h"
  33. #include "lpfc.h"
  34. #include "lpfc_logmsg.h"
  35. #include "lpfc_crtn.h"
  36. #include "lpfc_vport.h"
  37. #include "lpfc_debugfs.h"
  38. static int lpfc_els_retry(struct lpfc_hba *, struct lpfc_iocbq *,
  39. struct lpfc_iocbq *);
  40. static void lpfc_cmpl_fabric_iocb(struct lpfc_hba *, struct lpfc_iocbq *,
  41. struct lpfc_iocbq *);
  42. static void lpfc_fabric_abort_vport(struct lpfc_vport *vport);
  43. static int lpfc_issue_els_fdisc(struct lpfc_vport *vport,
  44. struct lpfc_nodelist *ndlp, uint8_t retry);
  45. static int lpfc_issue_fabric_iocb(struct lpfc_hba *phba,
  46. struct lpfc_iocbq *iocb);
  47. static void lpfc_register_new_vport(struct lpfc_hba *phba,
  48. struct lpfc_vport *vport,
  49. struct lpfc_nodelist *ndlp);
  50. static int lpfc_max_els_tries = 3;
  51. int
  52. lpfc_els_chk_latt(struct lpfc_vport *vport)
  53. {
  54. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  55. struct lpfc_hba *phba = vport->phba;
  56. uint32_t ha_copy;
  57. if (vport->port_state >= LPFC_VPORT_READY ||
  58. phba->link_state == LPFC_LINK_DOWN)
  59. return 0;
  60. /* Read the HBA Host Attention Register */
  61. ha_copy = readl(phba->HAregaddr);
  62. if (!(ha_copy & HA_LATT))
  63. return 0;
  64. /* Pending Link Event during Discovery */
  65. lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
  66. "0237 Pending Link Event during "
  67. "Discovery: State x%x\n",
  68. phba->pport->port_state);
  69. /* CLEAR_LA should re-enable link attention events and
  70. * we should then imediately take a LATT event. The
  71. * LATT processing should call lpfc_linkdown() which
  72. * will cleanup any left over in-progress discovery
  73. * events.
  74. */
  75. spin_lock_irq(shost->host_lock);
  76. vport->fc_flag |= FC_ABORT_DISCOVERY;
  77. spin_unlock_irq(shost->host_lock);
  78. if (phba->link_state != LPFC_CLEAR_LA)
  79. lpfc_issue_clear_la(phba, vport);
  80. return 1;
  81. }
  82. static struct lpfc_iocbq *
  83. lpfc_prep_els_iocb(struct lpfc_vport *vport, uint8_t expectRsp,
  84. uint16_t cmdSize, uint8_t retry,
  85. struct lpfc_nodelist *ndlp, uint32_t did,
  86. uint32_t elscmd)
  87. {
  88. struct lpfc_hba *phba = vport->phba;
  89. struct lpfc_iocbq *elsiocb;
  90. struct lpfc_dmabuf *pcmd, *prsp, *pbuflist;
  91. struct ulp_bde64 *bpl;
  92. IOCB_t *icmd;
  93. if (!lpfc_is_link_up(phba))
  94. return NULL;
  95. /* Allocate buffer for command iocb */
  96. elsiocb = lpfc_sli_get_iocbq(phba);
  97. if (elsiocb == NULL)
  98. return NULL;
  99. icmd = &elsiocb->iocb;
  100. /* fill in BDEs for command */
  101. /* Allocate buffer for command payload */
  102. pcmd = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  103. if (pcmd)
  104. pcmd->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &pcmd->phys);
  105. if (!pcmd || !pcmd->virt)
  106. goto els_iocb_free_pcmb_exit;
  107. INIT_LIST_HEAD(&pcmd->list);
  108. /* Allocate buffer for response payload */
  109. if (expectRsp) {
  110. prsp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  111. if (prsp)
  112. prsp->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
  113. &prsp->phys);
  114. if (!prsp || !prsp->virt)
  115. goto els_iocb_free_prsp_exit;
  116. INIT_LIST_HEAD(&prsp->list);
  117. } else
  118. prsp = NULL;
  119. /* Allocate buffer for Buffer ptr list */
  120. pbuflist = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  121. if (pbuflist)
  122. pbuflist->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
  123. &pbuflist->phys);
  124. if (!pbuflist || !pbuflist->virt)
  125. goto els_iocb_free_pbuf_exit;
  126. INIT_LIST_HEAD(&pbuflist->list);
  127. icmd->un.elsreq64.bdl.addrHigh = putPaddrHigh(pbuflist->phys);
  128. icmd->un.elsreq64.bdl.addrLow = putPaddrLow(pbuflist->phys);
  129. icmd->un.elsreq64.bdl.bdeFlags = BUFF_TYPE_BDL;
  130. icmd->un.elsreq64.remoteID = did; /* DID */
  131. if (expectRsp) {
  132. icmd->un.elsreq64.bdl.bdeSize = (2 * sizeof(struct ulp_bde64));
  133. icmd->ulpCommand = CMD_ELS_REQUEST64_CR;
  134. icmd->ulpTimeout = phba->fc_ratov * 2;
  135. } else {
  136. icmd->un.elsreq64.bdl.bdeSize = sizeof(struct ulp_bde64);
  137. icmd->ulpCommand = CMD_XMIT_ELS_RSP64_CX;
  138. }
  139. icmd->ulpBdeCount = 1;
  140. icmd->ulpLe = 1;
  141. icmd->ulpClass = CLASS3;
  142. if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
  143. icmd->un.elsreq64.myID = vport->fc_myDID;
  144. /* For ELS_REQUEST64_CR, use the VPI by default */
  145. icmd->ulpContext = vport->vpi;
  146. icmd->ulpCt_h = 0;
  147. icmd->ulpCt_l = 1;
  148. }
  149. bpl = (struct ulp_bde64 *) pbuflist->virt;
  150. bpl->addrLow = le32_to_cpu(putPaddrLow(pcmd->phys));
  151. bpl->addrHigh = le32_to_cpu(putPaddrHigh(pcmd->phys));
  152. bpl->tus.f.bdeSize = cmdSize;
  153. bpl->tus.f.bdeFlags = 0;
  154. bpl->tus.w = le32_to_cpu(bpl->tus.w);
  155. if (expectRsp) {
  156. bpl++;
  157. bpl->addrLow = le32_to_cpu(putPaddrLow(prsp->phys));
  158. bpl->addrHigh = le32_to_cpu(putPaddrHigh(prsp->phys));
  159. bpl->tus.f.bdeSize = FCELSSIZE;
  160. bpl->tus.f.bdeFlags = BUFF_USE_RCV;
  161. bpl->tus.w = le32_to_cpu(bpl->tus.w);
  162. }
  163. /* prevent preparing iocb with NULL ndlp reference */
  164. elsiocb->context1 = lpfc_nlp_get(ndlp);
  165. if (!elsiocb->context1)
  166. goto els_iocb_free_pbuf_exit;
  167. elsiocb->context2 = pcmd;
  168. elsiocb->context3 = pbuflist;
  169. elsiocb->retry = retry;
  170. elsiocb->vport = vport;
  171. elsiocb->drvrTimeout = (phba->fc_ratov << 1) + LPFC_DRVR_TIMEOUT;
  172. if (prsp) {
  173. list_add(&prsp->list, &pcmd->list);
  174. }
  175. if (expectRsp) {
  176. /* Xmit ELS command <elsCmd> to remote NPORT <did> */
  177. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  178. "0116 Xmit ELS command x%x to remote "
  179. "NPORT x%x I/O tag: x%x, port state: x%x\n",
  180. elscmd, did, elsiocb->iotag,
  181. vport->port_state);
  182. } else {
  183. /* Xmit ELS response <elsCmd> to remote NPORT <did> */
  184. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  185. "0117 Xmit ELS response x%x to remote "
  186. "NPORT x%x I/O tag: x%x, size: x%x\n",
  187. elscmd, ndlp->nlp_DID, elsiocb->iotag,
  188. cmdSize);
  189. }
  190. return elsiocb;
  191. els_iocb_free_pbuf_exit:
  192. lpfc_mbuf_free(phba, prsp->virt, prsp->phys);
  193. kfree(pbuflist);
  194. els_iocb_free_prsp_exit:
  195. lpfc_mbuf_free(phba, pcmd->virt, pcmd->phys);
  196. kfree(prsp);
  197. els_iocb_free_pcmb_exit:
  198. kfree(pcmd);
  199. lpfc_sli_release_iocbq(phba, elsiocb);
  200. return NULL;
  201. }
  202. static int
  203. lpfc_issue_fabric_reglogin(struct lpfc_vport *vport)
  204. {
  205. struct lpfc_hba *phba = vport->phba;
  206. LPFC_MBOXQ_t *mbox;
  207. struct lpfc_dmabuf *mp;
  208. struct lpfc_nodelist *ndlp;
  209. struct serv_parm *sp;
  210. int rc;
  211. int err = 0;
  212. sp = &phba->fc_fabparam;
  213. ndlp = lpfc_findnode_did(vport, Fabric_DID);
  214. if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
  215. err = 1;
  216. goto fail;
  217. }
  218. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  219. if (!mbox) {
  220. err = 2;
  221. goto fail;
  222. }
  223. vport->port_state = LPFC_FABRIC_CFG_LINK;
  224. lpfc_config_link(phba, mbox);
  225. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  226. mbox->vport = vport;
  227. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
  228. if (rc == MBX_NOT_FINISHED) {
  229. err = 3;
  230. goto fail_free_mbox;
  231. }
  232. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  233. if (!mbox) {
  234. err = 4;
  235. goto fail;
  236. }
  237. rc = lpfc_reg_login(phba, vport->vpi, Fabric_DID, (uint8_t *)sp, mbox,
  238. 0);
  239. if (rc) {
  240. err = 5;
  241. goto fail_free_mbox;
  242. }
  243. mbox->mbox_cmpl = lpfc_mbx_cmpl_fabric_reg_login;
  244. mbox->vport = vport;
  245. /* increment the reference count on ndlp to hold reference
  246. * for the callback routine.
  247. */
  248. mbox->context2 = lpfc_nlp_get(ndlp);
  249. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
  250. if (rc == MBX_NOT_FINISHED) {
  251. err = 6;
  252. goto fail_issue_reg_login;
  253. }
  254. return 0;
  255. fail_issue_reg_login:
  256. /* decrement the reference count on ndlp just incremented
  257. * for the failed mbox command.
  258. */
  259. lpfc_nlp_put(ndlp);
  260. mp = (struct lpfc_dmabuf *) mbox->context1;
  261. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  262. kfree(mp);
  263. fail_free_mbox:
  264. mempool_free(mbox, phba->mbox_mem_pool);
  265. fail:
  266. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  267. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  268. "0249 Cannot issue Register Fabric login: Err %d\n", err);
  269. return -ENXIO;
  270. }
  271. static int
  272. lpfc_cmpl_els_flogi_fabric(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  273. struct serv_parm *sp, IOCB_t *irsp)
  274. {
  275. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  276. struct lpfc_hba *phba = vport->phba;
  277. struct lpfc_nodelist *np;
  278. struct lpfc_nodelist *next_np;
  279. spin_lock_irq(shost->host_lock);
  280. vport->fc_flag |= FC_FABRIC;
  281. spin_unlock_irq(shost->host_lock);
  282. phba->fc_edtov = be32_to_cpu(sp->cmn.e_d_tov);
  283. if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */
  284. phba->fc_edtov = (phba->fc_edtov + 999999) / 1000000;
  285. phba->fc_ratov = (be32_to_cpu(sp->cmn.w2.r_a_tov) + 999) / 1000;
  286. if (phba->fc_topology == TOPOLOGY_LOOP) {
  287. spin_lock_irq(shost->host_lock);
  288. vport->fc_flag |= FC_PUBLIC_LOOP;
  289. spin_unlock_irq(shost->host_lock);
  290. } else {
  291. /*
  292. * If we are a N-port connected to a Fabric, fixup sparam's so
  293. * logins to devices on remote loops work.
  294. */
  295. vport->fc_sparam.cmn.altBbCredit = 1;
  296. }
  297. vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
  298. memcpy(&ndlp->nlp_portname, &sp->portName, sizeof(struct lpfc_name));
  299. memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof(struct lpfc_name));
  300. ndlp->nlp_class_sup = 0;
  301. if (sp->cls1.classValid)
  302. ndlp->nlp_class_sup |= FC_COS_CLASS1;
  303. if (sp->cls2.classValid)
  304. ndlp->nlp_class_sup |= FC_COS_CLASS2;
  305. if (sp->cls3.classValid)
  306. ndlp->nlp_class_sup |= FC_COS_CLASS3;
  307. if (sp->cls4.classValid)
  308. ndlp->nlp_class_sup |= FC_COS_CLASS4;
  309. ndlp->nlp_maxframe = ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) |
  310. sp->cmn.bbRcvSizeLsb;
  311. memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
  312. if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
  313. if (sp->cmn.response_multiple_NPort) {
  314. lpfc_printf_vlog(vport, KERN_WARNING,
  315. LOG_ELS | LOG_VPORT,
  316. "1816 FLOGI NPIV supported, "
  317. "response data 0x%x\n",
  318. sp->cmn.response_multiple_NPort);
  319. phba->link_flag |= LS_NPIV_FAB_SUPPORTED;
  320. } else {
  321. /* Because we asked f/w for NPIV it still expects us
  322. to call reg_vnpid atleast for the physcial host */
  323. lpfc_printf_vlog(vport, KERN_WARNING,
  324. LOG_ELS | LOG_VPORT,
  325. "1817 Fabric does not support NPIV "
  326. "- configuring single port mode.\n");
  327. phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED;
  328. }
  329. }
  330. if ((vport->fc_prevDID != vport->fc_myDID) &&
  331. !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
  332. /* If our NportID changed, we need to ensure all
  333. * remaining NPORTs get unreg_login'ed.
  334. */
  335. list_for_each_entry_safe(np, next_np,
  336. &vport->fc_nodes, nlp_listp) {
  337. if (!NLP_CHK_NODE_ACT(ndlp))
  338. continue;
  339. if ((np->nlp_state != NLP_STE_NPR_NODE) ||
  340. !(np->nlp_flag & NLP_NPR_ADISC))
  341. continue;
  342. spin_lock_irq(shost->host_lock);
  343. np->nlp_flag &= ~NLP_NPR_ADISC;
  344. spin_unlock_irq(shost->host_lock);
  345. lpfc_unreg_rpi(vport, np);
  346. }
  347. if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
  348. lpfc_mbx_unreg_vpi(vport);
  349. spin_lock_irq(shost->host_lock);
  350. vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
  351. spin_unlock_irq(shost->host_lock);
  352. }
  353. }
  354. lpfc_nlp_set_state(vport, ndlp, NLP_STE_REG_LOGIN_ISSUE);
  355. if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED &&
  356. vport->fc_flag & FC_VPORT_NEEDS_REG_VPI) {
  357. lpfc_register_new_vport(phba, vport, ndlp);
  358. return 0;
  359. }
  360. lpfc_issue_fabric_reglogin(vport);
  361. return 0;
  362. }
  363. /*
  364. * We FLOGIed into an NPort, initiate pt2pt protocol
  365. */
  366. static int
  367. lpfc_cmpl_els_flogi_nport(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  368. struct serv_parm *sp)
  369. {
  370. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  371. struct lpfc_hba *phba = vport->phba;
  372. LPFC_MBOXQ_t *mbox;
  373. int rc;
  374. spin_lock_irq(shost->host_lock);
  375. vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
  376. spin_unlock_irq(shost->host_lock);
  377. phba->fc_edtov = FF_DEF_EDTOV;
  378. phba->fc_ratov = FF_DEF_RATOV;
  379. rc = memcmp(&vport->fc_portname, &sp->portName,
  380. sizeof(vport->fc_portname));
  381. if (rc >= 0) {
  382. /* This side will initiate the PLOGI */
  383. spin_lock_irq(shost->host_lock);
  384. vport->fc_flag |= FC_PT2PT_PLOGI;
  385. spin_unlock_irq(shost->host_lock);
  386. /*
  387. * N_Port ID cannot be 0, set our to LocalID the other
  388. * side will be RemoteID.
  389. */
  390. /* not equal */
  391. if (rc)
  392. vport->fc_myDID = PT2PT_LocalID;
  393. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  394. if (!mbox)
  395. goto fail;
  396. lpfc_config_link(phba, mbox);
  397. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  398. mbox->vport = vport;
  399. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
  400. if (rc == MBX_NOT_FINISHED) {
  401. mempool_free(mbox, phba->mbox_mem_pool);
  402. goto fail;
  403. }
  404. /* Decrement ndlp reference count indicating that ndlp can be
  405. * safely released when other references to it are done.
  406. */
  407. lpfc_nlp_put(ndlp);
  408. ndlp = lpfc_findnode_did(vport, PT2PT_RemoteID);
  409. if (!ndlp) {
  410. /*
  411. * Cannot find existing Fabric ndlp, so allocate a
  412. * new one
  413. */
  414. ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
  415. if (!ndlp)
  416. goto fail;
  417. lpfc_nlp_init(vport, ndlp, PT2PT_RemoteID);
  418. } else if (!NLP_CHK_NODE_ACT(ndlp)) {
  419. ndlp = lpfc_enable_node(vport, ndlp,
  420. NLP_STE_UNUSED_NODE);
  421. if(!ndlp)
  422. goto fail;
  423. }
  424. memcpy(&ndlp->nlp_portname, &sp->portName,
  425. sizeof(struct lpfc_name));
  426. memcpy(&ndlp->nlp_nodename, &sp->nodeName,
  427. sizeof(struct lpfc_name));
  428. /* Set state will put ndlp onto node list if not already done */
  429. lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
  430. spin_lock_irq(shost->host_lock);
  431. ndlp->nlp_flag |= NLP_NPR_2B_DISC;
  432. spin_unlock_irq(shost->host_lock);
  433. } else
  434. /* This side will wait for the PLOGI, decrement ndlp reference
  435. * count indicating that ndlp can be released when other
  436. * references to it are done.
  437. */
  438. lpfc_nlp_put(ndlp);
  439. /* If we are pt2pt with another NPort, force NPIV off! */
  440. phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED;
  441. spin_lock_irq(shost->host_lock);
  442. vport->fc_flag |= FC_PT2PT;
  443. spin_unlock_irq(shost->host_lock);
  444. /* Start discovery - this should just do CLEAR_LA */
  445. lpfc_disc_start(vport);
  446. return 0;
  447. fail:
  448. return -ENXIO;
  449. }
  450. static void
  451. lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  452. struct lpfc_iocbq *rspiocb)
  453. {
  454. struct lpfc_vport *vport = cmdiocb->vport;
  455. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  456. IOCB_t *irsp = &rspiocb->iocb;
  457. struct lpfc_nodelist *ndlp = cmdiocb->context1;
  458. struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
  459. struct serv_parm *sp;
  460. int rc;
  461. /* Check to see if link went down during discovery */
  462. if (lpfc_els_chk_latt(vport)) {
  463. /* One additional decrement on node reference count to
  464. * trigger the release of the node
  465. */
  466. lpfc_nlp_put(ndlp);
  467. goto out;
  468. }
  469. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  470. "FLOGI cmpl: status:x%x/x%x state:x%x",
  471. irsp->ulpStatus, irsp->un.ulpWord[4],
  472. vport->port_state);
  473. if (irsp->ulpStatus) {
  474. /* Check for retry */
  475. if (lpfc_els_retry(phba, cmdiocb, rspiocb))
  476. goto out;
  477. /* FLOGI failed, so there is no fabric */
  478. spin_lock_irq(shost->host_lock);
  479. vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
  480. spin_unlock_irq(shost->host_lock);
  481. /* If private loop, then allow max outstanding els to be
  482. * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no
  483. * alpa map would take too long otherwise.
  484. */
  485. if (phba->alpa_map[0] == 0) {
  486. vport->cfg_discovery_threads = LPFC_MAX_DISC_THREADS;
  487. }
  488. /* FLOGI failure */
  489. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  490. "0100 FLOGI failure Data: x%x x%x "
  491. "x%x\n",
  492. irsp->ulpStatus, irsp->un.ulpWord[4],
  493. irsp->ulpTimeout);
  494. goto flogifail;
  495. }
  496. /*
  497. * The FLogI succeeded. Sync the data for the CPU before
  498. * accessing it.
  499. */
  500. prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
  501. sp = prsp->virt + sizeof(uint32_t);
  502. /* FLOGI completes successfully */
  503. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  504. "0101 FLOGI completes sucessfully "
  505. "Data: x%x x%x x%x x%x\n",
  506. irsp->un.ulpWord[4], sp->cmn.e_d_tov,
  507. sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution);
  508. if (vport->port_state == LPFC_FLOGI) {
  509. /*
  510. * If Common Service Parameters indicate Nport
  511. * we are point to point, if Fport we are Fabric.
  512. */
  513. if (sp->cmn.fPort)
  514. rc = lpfc_cmpl_els_flogi_fabric(vport, ndlp, sp, irsp);
  515. else
  516. rc = lpfc_cmpl_els_flogi_nport(vport, ndlp, sp);
  517. if (!rc)
  518. goto out;
  519. }
  520. flogifail:
  521. lpfc_nlp_put(ndlp);
  522. if (!lpfc_error_lost_link(irsp)) {
  523. /* FLOGI failed, so just use loop map to make discovery list */
  524. lpfc_disc_list_loopmap(vport);
  525. /* Start discovery */
  526. lpfc_disc_start(vport);
  527. } else if (((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
  528. ((irsp->un.ulpWord[4] != IOERR_SLI_ABORTED) &&
  529. (irsp->un.ulpWord[4] != IOERR_SLI_DOWN))) &&
  530. (phba->link_state != LPFC_CLEAR_LA)) {
  531. /* If FLOGI failed enable link interrupt. */
  532. lpfc_issue_clear_la(phba, vport);
  533. }
  534. out:
  535. lpfc_els_free_iocb(phba, cmdiocb);
  536. }
  537. static int
  538. lpfc_issue_els_flogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  539. uint8_t retry)
  540. {
  541. struct lpfc_hba *phba = vport->phba;
  542. struct serv_parm *sp;
  543. IOCB_t *icmd;
  544. struct lpfc_iocbq *elsiocb;
  545. struct lpfc_sli_ring *pring;
  546. uint8_t *pcmd;
  547. uint16_t cmdsize;
  548. uint32_t tmo;
  549. int rc;
  550. pring = &phba->sli.ring[LPFC_ELS_RING];
  551. cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
  552. elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
  553. ndlp->nlp_DID, ELS_CMD_FLOGI);
  554. if (!elsiocb)
  555. return 1;
  556. icmd = &elsiocb->iocb;
  557. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  558. /* For FLOGI request, remainder of payload is service parameters */
  559. *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI;
  560. pcmd += sizeof(uint32_t);
  561. memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
  562. sp = (struct serv_parm *) pcmd;
  563. /* Setup CSPs accordingly for Fabric */
  564. sp->cmn.e_d_tov = 0;
  565. sp->cmn.w2.r_a_tov = 0;
  566. sp->cls1.classValid = 0;
  567. sp->cls2.seqDelivery = 1;
  568. sp->cls3.seqDelivery = 1;
  569. if (sp->cmn.fcphLow < FC_PH3)
  570. sp->cmn.fcphLow = FC_PH3;
  571. if (sp->cmn.fcphHigh < FC_PH3)
  572. sp->cmn.fcphHigh = FC_PH3;
  573. if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
  574. sp->cmn.request_multiple_Nport = 1;
  575. /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */
  576. icmd->ulpCt_h = 1;
  577. icmd->ulpCt_l = 0;
  578. }
  579. if (phba->fc_topology != TOPOLOGY_LOOP) {
  580. icmd->un.elsreq64.myID = 0;
  581. icmd->un.elsreq64.fl = 1;
  582. }
  583. tmo = phba->fc_ratov;
  584. phba->fc_ratov = LPFC_DISC_FLOGI_TMO;
  585. lpfc_set_disctmo(vport);
  586. phba->fc_ratov = tmo;
  587. phba->fc_stat.elsXmitFLOGI++;
  588. elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi;
  589. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  590. "Issue FLOGI: opt:x%x",
  591. phba->sli3_options, 0, 0);
  592. rc = lpfc_issue_fabric_iocb(phba, elsiocb);
  593. if (rc == IOCB_ERROR) {
  594. lpfc_els_free_iocb(phba, elsiocb);
  595. return 1;
  596. }
  597. return 0;
  598. }
  599. int
  600. lpfc_els_abort_flogi(struct lpfc_hba *phba)
  601. {
  602. struct lpfc_sli_ring *pring;
  603. struct lpfc_iocbq *iocb, *next_iocb;
  604. struct lpfc_nodelist *ndlp;
  605. IOCB_t *icmd;
  606. /* Abort outstanding I/O on NPort <nlp_DID> */
  607. lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
  608. "0201 Abort outstanding I/O on NPort x%x\n",
  609. Fabric_DID);
  610. pring = &phba->sli.ring[LPFC_ELS_RING];
  611. /*
  612. * Check the txcmplq for an iocb that matches the nport the driver is
  613. * searching for.
  614. */
  615. spin_lock_irq(&phba->hbalock);
  616. list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
  617. icmd = &iocb->iocb;
  618. if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR &&
  619. icmd->un.elsreq64.bdl.ulpIoTag32) {
  620. ndlp = (struct lpfc_nodelist *)(iocb->context1);
  621. if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
  622. (ndlp->nlp_DID == Fabric_DID))
  623. lpfc_sli_issue_abort_iotag(phba, pring, iocb);
  624. }
  625. }
  626. spin_unlock_irq(&phba->hbalock);
  627. return 0;
  628. }
  629. int
  630. lpfc_initial_flogi(struct lpfc_vport *vport)
  631. {
  632. struct lpfc_hba *phba = vport->phba;
  633. struct lpfc_nodelist *ndlp;
  634. vport->port_state = LPFC_FLOGI;
  635. lpfc_set_disctmo(vport);
  636. /* First look for the Fabric ndlp */
  637. ndlp = lpfc_findnode_did(vport, Fabric_DID);
  638. if (!ndlp) {
  639. /* Cannot find existing Fabric ndlp, so allocate a new one */
  640. ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
  641. if (!ndlp)
  642. return 0;
  643. lpfc_nlp_init(vport, ndlp, Fabric_DID);
  644. /* Put ndlp onto node list */
  645. lpfc_enqueue_node(vport, ndlp);
  646. } else if (!NLP_CHK_NODE_ACT(ndlp)) {
  647. /* re-setup ndlp without removing from node list */
  648. ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
  649. if (!ndlp)
  650. return 0;
  651. }
  652. if (lpfc_issue_els_flogi(vport, ndlp, 0))
  653. /* This decrement of reference count to node shall kick off
  654. * the release of the node.
  655. */
  656. lpfc_nlp_put(ndlp);
  657. return 1;
  658. }
  659. int
  660. lpfc_initial_fdisc(struct lpfc_vport *vport)
  661. {
  662. struct lpfc_hba *phba = vport->phba;
  663. struct lpfc_nodelist *ndlp;
  664. /* First look for the Fabric ndlp */
  665. ndlp = lpfc_findnode_did(vport, Fabric_DID);
  666. if (!ndlp) {
  667. /* Cannot find existing Fabric ndlp, so allocate a new one */
  668. ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
  669. if (!ndlp)
  670. return 0;
  671. lpfc_nlp_init(vport, ndlp, Fabric_DID);
  672. /* Put ndlp onto node list */
  673. lpfc_enqueue_node(vport, ndlp);
  674. } else if (!NLP_CHK_NODE_ACT(ndlp)) {
  675. /* re-setup ndlp without removing from node list */
  676. ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
  677. if (!ndlp)
  678. return 0;
  679. }
  680. if (lpfc_issue_els_fdisc(vport, ndlp, 0)) {
  681. /* decrement node reference count to trigger the release of
  682. * the node.
  683. */
  684. lpfc_nlp_put(ndlp);
  685. return 0;
  686. }
  687. return 1;
  688. }
  689. void
  690. lpfc_more_plogi(struct lpfc_vport *vport)
  691. {
  692. int sentplogi;
  693. if (vport->num_disc_nodes)
  694. vport->num_disc_nodes--;
  695. /* Continue discovery with <num_disc_nodes> PLOGIs to go */
  696. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  697. "0232 Continue discovery with %d PLOGIs to go "
  698. "Data: x%x x%x x%x\n",
  699. vport->num_disc_nodes, vport->fc_plogi_cnt,
  700. vport->fc_flag, vport->port_state);
  701. /* Check to see if there are more PLOGIs to be sent */
  702. if (vport->fc_flag & FC_NLP_MORE)
  703. /* go thru NPR nodes and issue any remaining ELS PLOGIs */
  704. sentplogi = lpfc_els_disc_plogi(vport);
  705. return;
  706. }
  707. static struct lpfc_nodelist *
  708. lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp,
  709. struct lpfc_nodelist *ndlp)
  710. {
  711. struct lpfc_vport *vport = ndlp->vport;
  712. struct lpfc_nodelist *new_ndlp;
  713. struct lpfc_rport_data *rdata;
  714. struct fc_rport *rport;
  715. struct serv_parm *sp;
  716. uint8_t name[sizeof(struct lpfc_name)];
  717. uint32_t rc, keepDID = 0;
  718. /* Fabric nodes can have the same WWPN so we don't bother searching
  719. * by WWPN. Just return the ndlp that was given to us.
  720. */
  721. if (ndlp->nlp_type & NLP_FABRIC)
  722. return ndlp;
  723. sp = (struct serv_parm *) ((uint8_t *) prsp + sizeof(uint32_t));
  724. memset(name, 0, sizeof(struct lpfc_name));
  725. /* Now we find out if the NPort we are logging into, matches the WWPN
  726. * we have for that ndlp. If not, we have some work to do.
  727. */
  728. new_ndlp = lpfc_findnode_wwpn(vport, &sp->portName);
  729. if (new_ndlp == ndlp && NLP_CHK_NODE_ACT(new_ndlp))
  730. return ndlp;
  731. if (!new_ndlp) {
  732. rc = memcmp(&ndlp->nlp_portname, name,
  733. sizeof(struct lpfc_name));
  734. if (!rc)
  735. return ndlp;
  736. new_ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_ATOMIC);
  737. if (!new_ndlp)
  738. return ndlp;
  739. lpfc_nlp_init(vport, new_ndlp, ndlp->nlp_DID);
  740. } else if (!NLP_CHK_NODE_ACT(new_ndlp)) {
  741. rc = memcmp(&ndlp->nlp_portname, name,
  742. sizeof(struct lpfc_name));
  743. if (!rc)
  744. return ndlp;
  745. new_ndlp = lpfc_enable_node(vport, new_ndlp,
  746. NLP_STE_UNUSED_NODE);
  747. if (!new_ndlp)
  748. return ndlp;
  749. keepDID = new_ndlp->nlp_DID;
  750. } else
  751. keepDID = new_ndlp->nlp_DID;
  752. lpfc_unreg_rpi(vport, new_ndlp);
  753. new_ndlp->nlp_DID = ndlp->nlp_DID;
  754. new_ndlp->nlp_prev_state = ndlp->nlp_prev_state;
  755. if (ndlp->nlp_flag & NLP_NPR_2B_DISC)
  756. new_ndlp->nlp_flag |= NLP_NPR_2B_DISC;
  757. ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
  758. /* Set state will put new_ndlp on to node list if not already done */
  759. lpfc_nlp_set_state(vport, new_ndlp, ndlp->nlp_state);
  760. /* Move this back to NPR state */
  761. if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0) {
  762. /* The new_ndlp is replacing ndlp totally, so we need
  763. * to put ndlp on UNUSED list and try to free it.
  764. */
  765. /* Fix up the rport accordingly */
  766. rport = ndlp->rport;
  767. if (rport) {
  768. rdata = rport->dd_data;
  769. if (rdata->pnode == ndlp) {
  770. lpfc_nlp_put(ndlp);
  771. ndlp->rport = NULL;
  772. rdata->pnode = lpfc_nlp_get(new_ndlp);
  773. new_ndlp->rport = rport;
  774. }
  775. new_ndlp->nlp_type = ndlp->nlp_type;
  776. }
  777. /* We shall actually free the ndlp with both nlp_DID and
  778. * nlp_portname fields equals 0 to avoid any ndlp on the
  779. * nodelist never to be used.
  780. */
  781. if (ndlp->nlp_DID == 0) {
  782. spin_lock_irq(&phba->ndlp_lock);
  783. NLP_SET_FREE_REQ(ndlp);
  784. spin_unlock_irq(&phba->ndlp_lock);
  785. }
  786. /* Two ndlps cannot have the same did on the nodelist */
  787. ndlp->nlp_DID = keepDID;
  788. lpfc_drop_node(vport, ndlp);
  789. }
  790. else {
  791. lpfc_unreg_rpi(vport, ndlp);
  792. /* Two ndlps cannot have the same did */
  793. ndlp->nlp_DID = keepDID;
  794. lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
  795. }
  796. return new_ndlp;
  797. }
  798. void
  799. lpfc_end_rscn(struct lpfc_vport *vport)
  800. {
  801. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  802. if (vport->fc_flag & FC_RSCN_MODE) {
  803. /*
  804. * Check to see if more RSCNs came in while we were
  805. * processing this one.
  806. */
  807. if (vport->fc_rscn_id_cnt ||
  808. (vport->fc_flag & FC_RSCN_DISCOVERY) != 0)
  809. lpfc_els_handle_rscn(vport);
  810. else {
  811. spin_lock_irq(shost->host_lock);
  812. vport->fc_flag &= ~FC_RSCN_MODE;
  813. spin_unlock_irq(shost->host_lock);
  814. }
  815. }
  816. }
  817. static void
  818. lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  819. struct lpfc_iocbq *rspiocb)
  820. {
  821. struct lpfc_vport *vport = cmdiocb->vport;
  822. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  823. IOCB_t *irsp;
  824. struct lpfc_nodelist *ndlp;
  825. struct lpfc_dmabuf *prsp;
  826. int disc, rc, did, type;
  827. /* we pass cmdiocb to state machine which needs rspiocb as well */
  828. cmdiocb->context_un.rsp_iocb = rspiocb;
  829. irsp = &rspiocb->iocb;
  830. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  831. "PLOGI cmpl: status:x%x/x%x did:x%x",
  832. irsp->ulpStatus, irsp->un.ulpWord[4],
  833. irsp->un.elsreq64.remoteID);
  834. ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
  835. if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
  836. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  837. "0136 PLOGI completes to NPort x%x "
  838. "with no ndlp. Data: x%x x%x x%x\n",
  839. irsp->un.elsreq64.remoteID,
  840. irsp->ulpStatus, irsp->un.ulpWord[4],
  841. irsp->ulpIoTag);
  842. goto out;
  843. }
  844. /* Since ndlp can be freed in the disc state machine, note if this node
  845. * is being used during discovery.
  846. */
  847. spin_lock_irq(shost->host_lock);
  848. disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
  849. ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
  850. spin_unlock_irq(shost->host_lock);
  851. rc = 0;
  852. /* PLOGI completes to NPort <nlp_DID> */
  853. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  854. "0102 PLOGI completes to NPort x%x "
  855. "Data: x%x x%x x%x x%x x%x\n",
  856. ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
  857. irsp->ulpTimeout, disc, vport->num_disc_nodes);
  858. /* Check to see if link went down during discovery */
  859. if (lpfc_els_chk_latt(vport)) {
  860. spin_lock_irq(shost->host_lock);
  861. ndlp->nlp_flag |= NLP_NPR_2B_DISC;
  862. spin_unlock_irq(shost->host_lock);
  863. goto out;
  864. }
  865. /* ndlp could be freed in DSM, save these values now */
  866. type = ndlp->nlp_type;
  867. did = ndlp->nlp_DID;
  868. if (irsp->ulpStatus) {
  869. /* Check for retry */
  870. if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
  871. /* ELS command is being retried */
  872. if (disc) {
  873. spin_lock_irq(shost->host_lock);
  874. ndlp->nlp_flag |= NLP_NPR_2B_DISC;
  875. spin_unlock_irq(shost->host_lock);
  876. }
  877. goto out;
  878. }
  879. /* PLOGI failed */
  880. /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
  881. if (lpfc_error_lost_link(irsp))
  882. rc = NLP_STE_FREED_NODE;
  883. else
  884. rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
  885. NLP_EVT_CMPL_PLOGI);
  886. } else {
  887. /* Good status, call state machine */
  888. prsp = list_entry(((struct lpfc_dmabuf *)
  889. cmdiocb->context2)->list.next,
  890. struct lpfc_dmabuf, list);
  891. ndlp = lpfc_plogi_confirm_nport(phba, prsp->virt, ndlp);
  892. rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
  893. NLP_EVT_CMPL_PLOGI);
  894. }
  895. if (disc && vport->num_disc_nodes) {
  896. /* Check to see if there are more PLOGIs to be sent */
  897. lpfc_more_plogi(vport);
  898. if (vport->num_disc_nodes == 0) {
  899. spin_lock_irq(shost->host_lock);
  900. vport->fc_flag &= ~FC_NDISC_ACTIVE;
  901. spin_unlock_irq(shost->host_lock);
  902. lpfc_can_disctmo(vport);
  903. lpfc_end_rscn(vport);
  904. }
  905. }
  906. out:
  907. lpfc_els_free_iocb(phba, cmdiocb);
  908. return;
  909. }
  910. int
  911. lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry)
  912. {
  913. struct lpfc_hba *phba = vport->phba;
  914. struct serv_parm *sp;
  915. IOCB_t *icmd;
  916. struct lpfc_nodelist *ndlp;
  917. struct lpfc_iocbq *elsiocb;
  918. struct lpfc_sli_ring *pring;
  919. struct lpfc_sli *psli;
  920. uint8_t *pcmd;
  921. uint16_t cmdsize;
  922. int ret;
  923. psli = &phba->sli;
  924. pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
  925. ndlp = lpfc_findnode_did(vport, did);
  926. if (ndlp && !NLP_CHK_NODE_ACT(ndlp))
  927. ndlp = NULL;
  928. /* If ndlp is not NULL, we will bump the reference count on it */
  929. cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
  930. elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
  931. ELS_CMD_PLOGI);
  932. if (!elsiocb)
  933. return 1;
  934. icmd = &elsiocb->iocb;
  935. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  936. /* For PLOGI request, remainder of payload is service parameters */
  937. *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI;
  938. pcmd += sizeof(uint32_t);
  939. memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
  940. sp = (struct serv_parm *) pcmd;
  941. if (sp->cmn.fcphLow < FC_PH_4_3)
  942. sp->cmn.fcphLow = FC_PH_4_3;
  943. if (sp->cmn.fcphHigh < FC_PH3)
  944. sp->cmn.fcphHigh = FC_PH3;
  945. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  946. "Issue PLOGI: did:x%x",
  947. did, 0, 0);
  948. phba->fc_stat.elsXmitPLOGI++;
  949. elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi;
  950. ret = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
  951. if (ret == IOCB_ERROR) {
  952. lpfc_els_free_iocb(phba, elsiocb);
  953. return 1;
  954. }
  955. return 0;
  956. }
  957. static void
  958. lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  959. struct lpfc_iocbq *rspiocb)
  960. {
  961. struct lpfc_vport *vport = cmdiocb->vport;
  962. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  963. IOCB_t *irsp;
  964. struct lpfc_sli *psli;
  965. struct lpfc_nodelist *ndlp;
  966. psli = &phba->sli;
  967. /* we pass cmdiocb to state machine which needs rspiocb as well */
  968. cmdiocb->context_un.rsp_iocb = rspiocb;
  969. irsp = &(rspiocb->iocb);
  970. ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
  971. spin_lock_irq(shost->host_lock);
  972. ndlp->nlp_flag &= ~NLP_PRLI_SND;
  973. spin_unlock_irq(shost->host_lock);
  974. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  975. "PRLI cmpl: status:x%x/x%x did:x%x",
  976. irsp->ulpStatus, irsp->un.ulpWord[4],
  977. ndlp->nlp_DID);
  978. /* PRLI completes to NPort <nlp_DID> */
  979. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  980. "0103 PRLI completes to NPort x%x "
  981. "Data: x%x x%x x%x x%x\n",
  982. ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
  983. irsp->ulpTimeout, vport->num_disc_nodes);
  984. vport->fc_prli_sent--;
  985. /* Check to see if link went down during discovery */
  986. if (lpfc_els_chk_latt(vport))
  987. goto out;
  988. if (irsp->ulpStatus) {
  989. /* Check for retry */
  990. if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
  991. /* ELS command is being retried */
  992. goto out;
  993. }
  994. /* PRLI failed */
  995. /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
  996. if (lpfc_error_lost_link(irsp))
  997. goto out;
  998. else
  999. lpfc_disc_state_machine(vport, ndlp, cmdiocb,
  1000. NLP_EVT_CMPL_PRLI);
  1001. } else
  1002. /* Good status, call state machine */
  1003. lpfc_disc_state_machine(vport, ndlp, cmdiocb,
  1004. NLP_EVT_CMPL_PRLI);
  1005. out:
  1006. lpfc_els_free_iocb(phba, cmdiocb);
  1007. return;
  1008. }
  1009. int
  1010. lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  1011. uint8_t retry)
  1012. {
  1013. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  1014. struct lpfc_hba *phba = vport->phba;
  1015. PRLI *npr;
  1016. IOCB_t *icmd;
  1017. struct lpfc_iocbq *elsiocb;
  1018. struct lpfc_sli_ring *pring;
  1019. struct lpfc_sli *psli;
  1020. uint8_t *pcmd;
  1021. uint16_t cmdsize;
  1022. psli = &phba->sli;
  1023. pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
  1024. cmdsize = (sizeof(uint32_t) + sizeof(PRLI));
  1025. elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
  1026. ndlp->nlp_DID, ELS_CMD_PRLI);
  1027. if (!elsiocb)
  1028. return 1;
  1029. icmd = &elsiocb->iocb;
  1030. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  1031. /* For PRLI request, remainder of payload is service parameters */
  1032. memset(pcmd, 0, (sizeof(PRLI) + sizeof(uint32_t)));
  1033. *((uint32_t *) (pcmd)) = ELS_CMD_PRLI;
  1034. pcmd += sizeof(uint32_t);
  1035. /* For PRLI, remainder of payload is PRLI parameter page */
  1036. npr = (PRLI *) pcmd;
  1037. /*
  1038. * If our firmware version is 3.20 or later,
  1039. * set the following bits for FC-TAPE support.
  1040. */
  1041. if (phba->vpd.rev.feaLevelHigh >= 0x02) {
  1042. npr->ConfmComplAllowed = 1;
  1043. npr->Retry = 1;
  1044. npr->TaskRetryIdReq = 1;
  1045. }
  1046. npr->estabImagePair = 1;
  1047. npr->readXferRdyDis = 1;
  1048. /* For FCP support */
  1049. npr->prliType = PRLI_FCP_TYPE;
  1050. npr->initiatorFunc = 1;
  1051. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  1052. "Issue PRLI: did:x%x",
  1053. ndlp->nlp_DID, 0, 0);
  1054. phba->fc_stat.elsXmitPRLI++;
  1055. elsiocb->iocb_cmpl = lpfc_cmpl_els_prli;
  1056. spin_lock_irq(shost->host_lock);
  1057. ndlp->nlp_flag |= NLP_PRLI_SND;
  1058. spin_unlock_irq(shost->host_lock);
  1059. if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
  1060. spin_lock_irq(shost->host_lock);
  1061. ndlp->nlp_flag &= ~NLP_PRLI_SND;
  1062. spin_unlock_irq(shost->host_lock);
  1063. lpfc_els_free_iocb(phba, elsiocb);
  1064. return 1;
  1065. }
  1066. vport->fc_prli_sent++;
  1067. return 0;
  1068. }
  1069. void
  1070. lpfc_more_adisc(struct lpfc_vport *vport)
  1071. {
  1072. int sentadisc;
  1073. if (vport->num_disc_nodes)
  1074. vport->num_disc_nodes--;
  1075. /* Continue discovery with <num_disc_nodes> ADISCs to go */
  1076. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  1077. "0210 Continue discovery with %d ADISCs to go "
  1078. "Data: x%x x%x x%x\n",
  1079. vport->num_disc_nodes, vport->fc_adisc_cnt,
  1080. vport->fc_flag, vport->port_state);
  1081. /* Check to see if there are more ADISCs to be sent */
  1082. if (vport->fc_flag & FC_NLP_MORE) {
  1083. lpfc_set_disctmo(vport);
  1084. /* go thru NPR nodes and issue any remaining ELS ADISCs */
  1085. sentadisc = lpfc_els_disc_adisc(vport);
  1086. }
  1087. return;
  1088. }
  1089. static void
  1090. lpfc_rscn_disc(struct lpfc_vport *vport)
  1091. {
  1092. lpfc_can_disctmo(vport);
  1093. /* RSCN discovery */
  1094. /* go thru NPR nodes and issue ELS PLOGIs */
  1095. if (vport->fc_npr_cnt)
  1096. if (lpfc_els_disc_plogi(vport))
  1097. return;
  1098. lpfc_end_rscn(vport);
  1099. }
  1100. static void
  1101. lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  1102. struct lpfc_iocbq *rspiocb)
  1103. {
  1104. struct lpfc_vport *vport = cmdiocb->vport;
  1105. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  1106. IOCB_t *irsp;
  1107. struct lpfc_nodelist *ndlp;
  1108. int disc;
  1109. /* we pass cmdiocb to state machine which needs rspiocb as well */
  1110. cmdiocb->context_un.rsp_iocb = rspiocb;
  1111. irsp = &(rspiocb->iocb);
  1112. ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
  1113. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  1114. "ADISC cmpl: status:x%x/x%x did:x%x",
  1115. irsp->ulpStatus, irsp->un.ulpWord[4],
  1116. ndlp->nlp_DID);
  1117. /* Since ndlp can be freed in the disc state machine, note if this node
  1118. * is being used during discovery.
  1119. */
  1120. spin_lock_irq(shost->host_lock);
  1121. disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
  1122. ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC);
  1123. spin_unlock_irq(shost->host_lock);
  1124. /* ADISC completes to NPort <nlp_DID> */
  1125. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  1126. "0104 ADISC completes to NPort x%x "
  1127. "Data: x%x x%x x%x x%x x%x\n",
  1128. ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
  1129. irsp->ulpTimeout, disc, vport->num_disc_nodes);
  1130. /* Check to see if link went down during discovery */
  1131. if (lpfc_els_chk_latt(vport)) {
  1132. spin_lock_irq(shost->host_lock);
  1133. ndlp->nlp_flag |= NLP_NPR_2B_DISC;
  1134. spin_unlock_irq(shost->host_lock);
  1135. goto out;
  1136. }
  1137. if (irsp->ulpStatus) {
  1138. /* Check for retry */
  1139. if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
  1140. /* ELS command is being retried */
  1141. if (disc) {
  1142. spin_lock_irq(shost->host_lock);
  1143. ndlp->nlp_flag |= NLP_NPR_2B_DISC;
  1144. spin_unlock_irq(shost->host_lock);
  1145. lpfc_set_disctmo(vport);
  1146. }
  1147. goto out;
  1148. }
  1149. /* ADISC failed */
  1150. /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
  1151. if (!lpfc_error_lost_link(irsp))
  1152. lpfc_disc_state_machine(vport, ndlp, cmdiocb,
  1153. NLP_EVT_CMPL_ADISC);
  1154. } else
  1155. /* Good status, call state machine */
  1156. lpfc_disc_state_machine(vport, ndlp, cmdiocb,
  1157. NLP_EVT_CMPL_ADISC);
  1158. if (disc && vport->num_disc_nodes) {
  1159. /* Check to see if there are more ADISCs to be sent */
  1160. lpfc_more_adisc(vport);
  1161. /* Check to see if we are done with ADISC authentication */
  1162. if (vport->num_disc_nodes == 0) {
  1163. /* If we get here, there is nothing left to ADISC */
  1164. /*
  1165. * For NPIV, cmpl_reg_vpi will set port_state to READY,
  1166. * and continue discovery.
  1167. */
  1168. if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
  1169. !(vport->fc_flag & FC_RSCN_MODE)) {
  1170. lpfc_issue_reg_vpi(phba, vport);
  1171. goto out;
  1172. }
  1173. /*
  1174. * For SLI2, we need to set port_state to READY
  1175. * and continue discovery.
  1176. */
  1177. if (vport->port_state < LPFC_VPORT_READY) {
  1178. /* If we get here, there is nothing to ADISC */
  1179. if (vport->port_type == LPFC_PHYSICAL_PORT)
  1180. lpfc_issue_clear_la(phba, vport);
  1181. if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
  1182. vport->num_disc_nodes = 0;
  1183. /* go thru NPR list, issue ELS PLOGIs */
  1184. if (vport->fc_npr_cnt)
  1185. lpfc_els_disc_plogi(vport);
  1186. if (!vport->num_disc_nodes) {
  1187. spin_lock_irq(shost->host_lock);
  1188. vport->fc_flag &=
  1189. ~FC_NDISC_ACTIVE;
  1190. spin_unlock_irq(
  1191. shost->host_lock);
  1192. lpfc_can_disctmo(vport);
  1193. }
  1194. }
  1195. vport->port_state = LPFC_VPORT_READY;
  1196. } else {
  1197. lpfc_rscn_disc(vport);
  1198. }
  1199. }
  1200. }
  1201. out:
  1202. lpfc_els_free_iocb(phba, cmdiocb);
  1203. return;
  1204. }
  1205. int
  1206. lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  1207. uint8_t retry)
  1208. {
  1209. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  1210. struct lpfc_hba *phba = vport->phba;
  1211. ADISC *ap;
  1212. IOCB_t *icmd;
  1213. struct lpfc_iocbq *elsiocb;
  1214. struct lpfc_sli *psli = &phba->sli;
  1215. struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
  1216. uint8_t *pcmd;
  1217. uint16_t cmdsize;
  1218. cmdsize = (sizeof(uint32_t) + sizeof(ADISC));
  1219. elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
  1220. ndlp->nlp_DID, ELS_CMD_ADISC);
  1221. if (!elsiocb)
  1222. return 1;
  1223. icmd = &elsiocb->iocb;
  1224. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  1225. /* For ADISC request, remainder of payload is service parameters */
  1226. *((uint32_t *) (pcmd)) = ELS_CMD_ADISC;
  1227. pcmd += sizeof(uint32_t);
  1228. /* Fill in ADISC payload */
  1229. ap = (ADISC *) pcmd;
  1230. ap->hardAL_PA = phba->fc_pref_ALPA;
  1231. memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
  1232. memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
  1233. ap->DID = be32_to_cpu(vport->fc_myDID);
  1234. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  1235. "Issue ADISC: did:x%x",
  1236. ndlp->nlp_DID, 0, 0);
  1237. phba->fc_stat.elsXmitADISC++;
  1238. elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc;
  1239. spin_lock_irq(shost->host_lock);
  1240. ndlp->nlp_flag |= NLP_ADISC_SND;
  1241. spin_unlock_irq(shost->host_lock);
  1242. if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
  1243. spin_lock_irq(shost->host_lock);
  1244. ndlp->nlp_flag &= ~NLP_ADISC_SND;
  1245. spin_unlock_irq(shost->host_lock);
  1246. lpfc_els_free_iocb(phba, elsiocb);
  1247. return 1;
  1248. }
  1249. return 0;
  1250. }
  1251. static void
  1252. lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  1253. struct lpfc_iocbq *rspiocb)
  1254. {
  1255. struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
  1256. struct lpfc_vport *vport = ndlp->vport;
  1257. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  1258. IOCB_t *irsp;
  1259. struct lpfc_sli *psli;
  1260. psli = &phba->sli;
  1261. /* we pass cmdiocb to state machine which needs rspiocb as well */
  1262. cmdiocb->context_un.rsp_iocb = rspiocb;
  1263. irsp = &(rspiocb->iocb);
  1264. spin_lock_irq(shost->host_lock);
  1265. ndlp->nlp_flag &= ~NLP_LOGO_SND;
  1266. spin_unlock_irq(shost->host_lock);
  1267. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  1268. "LOGO cmpl: status:x%x/x%x did:x%x",
  1269. irsp->ulpStatus, irsp->un.ulpWord[4],
  1270. ndlp->nlp_DID);
  1271. /* LOGO completes to NPort <nlp_DID> */
  1272. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  1273. "0105 LOGO completes to NPort x%x "
  1274. "Data: x%x x%x x%x x%x\n",
  1275. ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
  1276. irsp->ulpTimeout, vport->num_disc_nodes);
  1277. /* Check to see if link went down during discovery */
  1278. if (lpfc_els_chk_latt(vport))
  1279. goto out;
  1280. if (ndlp->nlp_flag & NLP_TARGET_REMOVE) {
  1281. /* NLP_EVT_DEVICE_RM should unregister the RPI
  1282. * which should abort all outstanding IOs.
  1283. */
  1284. lpfc_disc_state_machine(vport, ndlp, cmdiocb,
  1285. NLP_EVT_DEVICE_RM);
  1286. goto out;
  1287. }
  1288. if (irsp->ulpStatus) {
  1289. /* Check for retry */
  1290. if (lpfc_els_retry(phba, cmdiocb, rspiocb))
  1291. /* ELS command is being retried */
  1292. goto out;
  1293. /* LOGO failed */
  1294. /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
  1295. if (lpfc_error_lost_link(irsp))
  1296. goto out;
  1297. else
  1298. lpfc_disc_state_machine(vport, ndlp, cmdiocb,
  1299. NLP_EVT_CMPL_LOGO);
  1300. } else
  1301. /* Good status, call state machine.
  1302. * This will unregister the rpi if needed.
  1303. */
  1304. lpfc_disc_state_machine(vport, ndlp, cmdiocb,
  1305. NLP_EVT_CMPL_LOGO);
  1306. out:
  1307. lpfc_els_free_iocb(phba, cmdiocb);
  1308. return;
  1309. }
  1310. int
  1311. lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  1312. uint8_t retry)
  1313. {
  1314. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  1315. struct lpfc_hba *phba = vport->phba;
  1316. IOCB_t *icmd;
  1317. struct lpfc_iocbq *elsiocb;
  1318. struct lpfc_sli_ring *pring;
  1319. struct lpfc_sli *psli;
  1320. uint8_t *pcmd;
  1321. uint16_t cmdsize;
  1322. int rc;
  1323. psli = &phba->sli;
  1324. pring = &psli->ring[LPFC_ELS_RING];
  1325. spin_lock_irq(shost->host_lock);
  1326. if (ndlp->nlp_flag & NLP_LOGO_SND) {
  1327. spin_unlock_irq(shost->host_lock);
  1328. return 0;
  1329. }
  1330. spin_unlock_irq(shost->host_lock);
  1331. cmdsize = (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name);
  1332. elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
  1333. ndlp->nlp_DID, ELS_CMD_LOGO);
  1334. if (!elsiocb)
  1335. return 1;
  1336. icmd = &elsiocb->iocb;
  1337. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  1338. *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
  1339. pcmd += sizeof(uint32_t);
  1340. /* Fill in LOGO payload */
  1341. *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
  1342. pcmd += sizeof(uint32_t);
  1343. memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
  1344. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  1345. "Issue LOGO: did:x%x",
  1346. ndlp->nlp_DID, 0, 0);
  1347. phba->fc_stat.elsXmitLOGO++;
  1348. elsiocb->iocb_cmpl = lpfc_cmpl_els_logo;
  1349. spin_lock_irq(shost->host_lock);
  1350. ndlp->nlp_flag |= NLP_LOGO_SND;
  1351. spin_unlock_irq(shost->host_lock);
  1352. rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
  1353. if (rc == IOCB_ERROR) {
  1354. spin_lock_irq(shost->host_lock);
  1355. ndlp->nlp_flag &= ~NLP_LOGO_SND;
  1356. spin_unlock_irq(shost->host_lock);
  1357. lpfc_els_free_iocb(phba, elsiocb);
  1358. return 1;
  1359. }
  1360. return 0;
  1361. }
  1362. static void
  1363. lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  1364. struct lpfc_iocbq *rspiocb)
  1365. {
  1366. struct lpfc_vport *vport = cmdiocb->vport;
  1367. IOCB_t *irsp;
  1368. irsp = &rspiocb->iocb;
  1369. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  1370. "ELS cmd cmpl: status:x%x/x%x did:x%x",
  1371. irsp->ulpStatus, irsp->un.ulpWord[4],
  1372. irsp->un.elsreq64.remoteID);
  1373. /* ELS cmd tag <ulpIoTag> completes */
  1374. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  1375. "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n",
  1376. irsp->ulpIoTag, irsp->ulpStatus,
  1377. irsp->un.ulpWord[4], irsp->ulpTimeout);
  1378. /* Check to see if link went down during discovery */
  1379. lpfc_els_chk_latt(vport);
  1380. lpfc_els_free_iocb(phba, cmdiocb);
  1381. return;
  1382. }
  1383. int
  1384. lpfc_issue_els_scr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
  1385. {
  1386. struct lpfc_hba *phba = vport->phba;
  1387. IOCB_t *icmd;
  1388. struct lpfc_iocbq *elsiocb;
  1389. struct lpfc_sli_ring *pring;
  1390. struct lpfc_sli *psli;
  1391. uint8_t *pcmd;
  1392. uint16_t cmdsize;
  1393. struct lpfc_nodelist *ndlp;
  1394. psli = &phba->sli;
  1395. pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
  1396. cmdsize = (sizeof(uint32_t) + sizeof(SCR));
  1397. ndlp = lpfc_findnode_did(vport, nportid);
  1398. if (!ndlp) {
  1399. ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
  1400. if (!ndlp)
  1401. return 1;
  1402. lpfc_nlp_init(vport, ndlp, nportid);
  1403. lpfc_enqueue_node(vport, ndlp);
  1404. } else if (!NLP_CHK_NODE_ACT(ndlp)) {
  1405. ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
  1406. if (!ndlp)
  1407. return 1;
  1408. }
  1409. elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
  1410. ndlp->nlp_DID, ELS_CMD_SCR);
  1411. if (!elsiocb) {
  1412. /* This will trigger the release of the node just
  1413. * allocated
  1414. */
  1415. lpfc_nlp_put(ndlp);
  1416. return 1;
  1417. }
  1418. icmd = &elsiocb->iocb;
  1419. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  1420. *((uint32_t *) (pcmd)) = ELS_CMD_SCR;
  1421. pcmd += sizeof(uint32_t);
  1422. /* For SCR, remainder of payload is SCR parameter page */
  1423. memset(pcmd, 0, sizeof(SCR));
  1424. ((SCR *) pcmd)->Function = SCR_FUNC_FULL;
  1425. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  1426. "Issue SCR: did:x%x",
  1427. ndlp->nlp_DID, 0, 0);
  1428. phba->fc_stat.elsXmitSCR++;
  1429. elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
  1430. if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
  1431. /* The additional lpfc_nlp_put will cause the following
  1432. * lpfc_els_free_iocb routine to trigger the rlease of
  1433. * the node.
  1434. */
  1435. lpfc_nlp_put(ndlp);
  1436. lpfc_els_free_iocb(phba, elsiocb);
  1437. return 1;
  1438. }
  1439. /* This will cause the callback-function lpfc_cmpl_els_cmd to
  1440. * trigger the release of node.
  1441. */
  1442. lpfc_nlp_put(ndlp);
  1443. return 0;
  1444. }
  1445. static int
  1446. lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
  1447. {
  1448. struct lpfc_hba *phba = vport->phba;
  1449. IOCB_t *icmd;
  1450. struct lpfc_iocbq *elsiocb;
  1451. struct lpfc_sli_ring *pring;
  1452. struct lpfc_sli *psli;
  1453. FARP *fp;
  1454. uint8_t *pcmd;
  1455. uint32_t *lp;
  1456. uint16_t cmdsize;
  1457. struct lpfc_nodelist *ondlp;
  1458. struct lpfc_nodelist *ndlp;
  1459. psli = &phba->sli;
  1460. pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
  1461. cmdsize = (sizeof(uint32_t) + sizeof(FARP));
  1462. ndlp = lpfc_findnode_did(vport, nportid);
  1463. if (!ndlp) {
  1464. ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
  1465. if (!ndlp)
  1466. return 1;
  1467. lpfc_nlp_init(vport, ndlp, nportid);
  1468. lpfc_enqueue_node(vport, ndlp);
  1469. } else if (!NLP_CHK_NODE_ACT(ndlp)) {
  1470. ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
  1471. if (!ndlp)
  1472. return 1;
  1473. }
  1474. elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
  1475. ndlp->nlp_DID, ELS_CMD_RNID);
  1476. if (!elsiocb) {
  1477. /* This will trigger the release of the node just
  1478. * allocated
  1479. */
  1480. lpfc_nlp_put(ndlp);
  1481. return 1;
  1482. }
  1483. icmd = &elsiocb->iocb;
  1484. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  1485. *((uint32_t *) (pcmd)) = ELS_CMD_FARPR;
  1486. pcmd += sizeof(uint32_t);
  1487. /* Fill in FARPR payload */
  1488. fp = (FARP *) (pcmd);
  1489. memset(fp, 0, sizeof(FARP));
  1490. lp = (uint32_t *) pcmd;
  1491. *lp++ = be32_to_cpu(nportid);
  1492. *lp++ = be32_to_cpu(vport->fc_myDID);
  1493. fp->Rflags = 0;
  1494. fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE);
  1495. memcpy(&fp->RportName, &vport->fc_portname, sizeof(struct lpfc_name));
  1496. memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
  1497. ondlp = lpfc_findnode_did(vport, nportid);
  1498. if (ondlp && NLP_CHK_NODE_ACT(ondlp)) {
  1499. memcpy(&fp->OportName, &ondlp->nlp_portname,
  1500. sizeof(struct lpfc_name));
  1501. memcpy(&fp->OnodeName, &ondlp->nlp_nodename,
  1502. sizeof(struct lpfc_name));
  1503. }
  1504. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  1505. "Issue FARPR: did:x%x",
  1506. ndlp->nlp_DID, 0, 0);
  1507. phba->fc_stat.elsXmitFARPR++;
  1508. elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
  1509. if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
  1510. /* The additional lpfc_nlp_put will cause the following
  1511. * lpfc_els_free_iocb routine to trigger the release of
  1512. * the node.
  1513. */
  1514. lpfc_nlp_put(ndlp);
  1515. lpfc_els_free_iocb(phba, elsiocb);
  1516. return 1;
  1517. }
  1518. /* This will cause the callback-function lpfc_cmpl_els_cmd to
  1519. * trigger the release of the node.
  1520. */
  1521. lpfc_nlp_put(ndlp);
  1522. return 0;
  1523. }
  1524. void
  1525. lpfc_cancel_retry_delay_tmo(struct lpfc_vport *vport, struct lpfc_nodelist *nlp)
  1526. {
  1527. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  1528. struct lpfc_work_evt *evtp;
  1529. if (!(nlp->nlp_flag & NLP_DELAY_TMO))
  1530. return;
  1531. spin_lock_irq(shost->host_lock);
  1532. nlp->nlp_flag &= ~NLP_DELAY_TMO;
  1533. spin_unlock_irq(shost->host_lock);
  1534. del_timer_sync(&nlp->nlp_delayfunc);
  1535. nlp->nlp_last_elscmd = 0;
  1536. if (!list_empty(&nlp->els_retry_evt.evt_listp)) {
  1537. list_del_init(&nlp->els_retry_evt.evt_listp);
  1538. /* Decrement nlp reference count held for the delayed retry */
  1539. evtp = &nlp->els_retry_evt;
  1540. lpfc_nlp_put((struct lpfc_nodelist *)evtp->evt_arg1);
  1541. }
  1542. if (nlp->nlp_flag & NLP_NPR_2B_DISC) {
  1543. spin_lock_irq(shost->host_lock);
  1544. nlp->nlp_flag &= ~NLP_NPR_2B_DISC;
  1545. spin_unlock_irq(shost->host_lock);
  1546. if (vport->num_disc_nodes) {
  1547. if (vport->port_state < LPFC_VPORT_READY) {
  1548. /* Check if there are more ADISCs to be sent */
  1549. lpfc_more_adisc(vport);
  1550. if ((vport->num_disc_nodes == 0) &&
  1551. (vport->fc_npr_cnt))
  1552. lpfc_els_disc_plogi(vport);
  1553. } else {
  1554. /* Check if there are more PLOGIs to be sent */
  1555. lpfc_more_plogi(vport);
  1556. }
  1557. if (vport->num_disc_nodes == 0) {
  1558. spin_lock_irq(shost->host_lock);
  1559. vport->fc_flag &= ~FC_NDISC_ACTIVE;
  1560. spin_unlock_irq(shost->host_lock);
  1561. lpfc_can_disctmo(vport);
  1562. lpfc_end_rscn(vport);
  1563. }
  1564. }
  1565. }
  1566. return;
  1567. }
  1568. void
  1569. lpfc_els_retry_delay(unsigned long ptr)
  1570. {
  1571. struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) ptr;
  1572. struct lpfc_vport *vport = ndlp->vport;
  1573. struct lpfc_hba *phba = vport->phba;
  1574. unsigned long flags;
  1575. struct lpfc_work_evt *evtp = &ndlp->els_retry_evt;
  1576. spin_lock_irqsave(&phba->hbalock, flags);
  1577. if (!list_empty(&evtp->evt_listp)) {
  1578. spin_unlock_irqrestore(&phba->hbalock, flags);
  1579. return;
  1580. }
  1581. /* We need to hold the node by incrementing the reference
  1582. * count until the queued work is done
  1583. */
  1584. evtp->evt_arg1 = lpfc_nlp_get(ndlp);
  1585. if (evtp->evt_arg1) {
  1586. evtp->evt = LPFC_EVT_ELS_RETRY;
  1587. list_add_tail(&evtp->evt_listp, &phba->work_list);
  1588. lpfc_worker_wake_up(phba);
  1589. }
  1590. spin_unlock_irqrestore(&phba->hbalock, flags);
  1591. return;
  1592. }
  1593. void
  1594. lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp)
  1595. {
  1596. struct lpfc_vport *vport = ndlp->vport;
  1597. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  1598. uint32_t cmd, did, retry;
  1599. spin_lock_irq(shost->host_lock);
  1600. did = ndlp->nlp_DID;
  1601. cmd = ndlp->nlp_last_elscmd;
  1602. ndlp->nlp_last_elscmd = 0;
  1603. if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
  1604. spin_unlock_irq(shost->host_lock);
  1605. return;
  1606. }
  1607. ndlp->nlp_flag &= ~NLP_DELAY_TMO;
  1608. spin_unlock_irq(shost->host_lock);
  1609. /*
  1610. * If a discovery event readded nlp_delayfunc after timer
  1611. * firing and before processing the timer, cancel the
  1612. * nlp_delayfunc.
  1613. */
  1614. del_timer_sync(&ndlp->nlp_delayfunc);
  1615. retry = ndlp->nlp_retry;
  1616. switch (cmd) {
  1617. case ELS_CMD_FLOGI:
  1618. lpfc_issue_els_flogi(vport, ndlp, retry);
  1619. break;
  1620. case ELS_CMD_PLOGI:
  1621. if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) {
  1622. ndlp->nlp_prev_state = ndlp->nlp_state;
  1623. lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
  1624. }
  1625. break;
  1626. case ELS_CMD_ADISC:
  1627. if (!lpfc_issue_els_adisc(vport, ndlp, retry)) {
  1628. ndlp->nlp_prev_state = ndlp->nlp_state;
  1629. lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
  1630. }
  1631. break;
  1632. case ELS_CMD_PRLI:
  1633. if (!lpfc_issue_els_prli(vport, ndlp, retry)) {
  1634. ndlp->nlp_prev_state = ndlp->nlp_state;
  1635. lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
  1636. }
  1637. break;
  1638. case ELS_CMD_LOGO:
  1639. if (!lpfc_issue_els_logo(vport, ndlp, retry)) {
  1640. ndlp->nlp_prev_state = ndlp->nlp_state;
  1641. lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
  1642. }
  1643. break;
  1644. case ELS_CMD_FDISC:
  1645. lpfc_issue_els_fdisc(vport, ndlp, retry);
  1646. break;
  1647. }
  1648. return;
  1649. }
  1650. static int
  1651. lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  1652. struct lpfc_iocbq *rspiocb)
  1653. {
  1654. struct lpfc_vport *vport = cmdiocb->vport;
  1655. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  1656. IOCB_t *irsp = &rspiocb->iocb;
  1657. struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
  1658. struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
  1659. uint32_t *elscmd;
  1660. struct ls_rjt stat;
  1661. int retry = 0, maxretry = lpfc_max_els_tries, delay = 0;
  1662. int logerr = 0;
  1663. uint32_t cmd = 0;
  1664. uint32_t did;
  1665. /* Note: context2 may be 0 for internal driver abort
  1666. * of delays ELS command.
  1667. */
  1668. if (pcmd && pcmd->virt) {
  1669. elscmd = (uint32_t *) (pcmd->virt);
  1670. cmd = *elscmd++;
  1671. }
  1672. if (ndlp && NLP_CHK_NODE_ACT(ndlp))
  1673. did = ndlp->nlp_DID;
  1674. else {
  1675. /* We should only hit this case for retrying PLOGI */
  1676. did = irsp->un.elsreq64.remoteID;
  1677. ndlp = lpfc_findnode_did(vport, did);
  1678. if ((!ndlp || !NLP_CHK_NODE_ACT(ndlp))
  1679. && (cmd != ELS_CMD_PLOGI))
  1680. return 1;
  1681. }
  1682. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  1683. "Retry ELS: wd7:x%x wd4:x%x did:x%x",
  1684. *(((uint32_t *) irsp) + 7), irsp->un.ulpWord[4], ndlp->nlp_DID);
  1685. switch (irsp->ulpStatus) {
  1686. case IOSTAT_FCP_RSP_ERROR:
  1687. case IOSTAT_REMOTE_STOP:
  1688. break;
  1689. case IOSTAT_LOCAL_REJECT:
  1690. switch ((irsp->un.ulpWord[4] & 0xff)) {
  1691. case IOERR_LOOP_OPEN_FAILURE:
  1692. if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0)
  1693. delay = 1000;
  1694. retry = 1;
  1695. break;
  1696. case IOERR_ILLEGAL_COMMAND:
  1697. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  1698. "0124 Retry illegal cmd x%x "
  1699. "retry:x%x delay:x%x\n",
  1700. cmd, cmdiocb->retry, delay);
  1701. retry = 1;
  1702. /* All command's retry policy */
  1703. maxretry = 8;
  1704. if (cmdiocb->retry > 2)
  1705. delay = 1000;
  1706. break;
  1707. case IOERR_NO_RESOURCES:
  1708. logerr = 1; /* HBA out of resources */
  1709. retry = 1;
  1710. if (cmdiocb->retry > 100)
  1711. delay = 100;
  1712. maxretry = 250;
  1713. break;
  1714. case IOERR_ILLEGAL_FRAME:
  1715. delay = 100;
  1716. retry = 1;
  1717. break;
  1718. case IOERR_SEQUENCE_TIMEOUT:
  1719. case IOERR_INVALID_RPI:
  1720. retry = 1;
  1721. break;
  1722. }
  1723. break;
  1724. case IOSTAT_NPORT_RJT:
  1725. case IOSTAT_FABRIC_RJT:
  1726. if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
  1727. retry = 1;
  1728. break;
  1729. }
  1730. break;
  1731. case IOSTAT_NPORT_BSY:
  1732. case IOSTAT_FABRIC_BSY:
  1733. logerr = 1; /* Fabric / Remote NPort out of resources */
  1734. retry = 1;
  1735. break;
  1736. case IOSTAT_LS_RJT:
  1737. stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]);
  1738. /* Added for Vendor specifc support
  1739. * Just keep retrying for these Rsn / Exp codes
  1740. */
  1741. switch (stat.un.b.lsRjtRsnCode) {
  1742. case LSRJT_UNABLE_TPC:
  1743. if (stat.un.b.lsRjtRsnCodeExp ==
  1744. LSEXP_CMD_IN_PROGRESS) {
  1745. if (cmd == ELS_CMD_PLOGI) {
  1746. delay = 1000;
  1747. maxretry = 48;
  1748. }
  1749. retry = 1;
  1750. break;
  1751. }
  1752. if (cmd == ELS_CMD_PLOGI) {
  1753. delay = 1000;
  1754. maxretry = lpfc_max_els_tries + 1;
  1755. retry = 1;
  1756. break;
  1757. }
  1758. if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
  1759. (cmd == ELS_CMD_FDISC) &&
  1760. (stat.un.b.lsRjtRsnCodeExp == LSEXP_OUT_OF_RESOURCE)){
  1761. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  1762. "0125 FDISC Failed (x%x). "
  1763. "Fabric out of resources\n",
  1764. stat.un.lsRjtError);
  1765. lpfc_vport_set_state(vport,
  1766. FC_VPORT_NO_FABRIC_RSCS);
  1767. }
  1768. break;
  1769. case LSRJT_LOGICAL_BSY:
  1770. if ((cmd == ELS_CMD_PLOGI) ||
  1771. (cmd == ELS_CMD_PRLI)) {
  1772. delay = 1000;
  1773. maxretry = 48;
  1774. } else if (cmd == ELS_CMD_FDISC) {
  1775. /* FDISC retry policy */
  1776. maxretry = 48;
  1777. if (cmdiocb->retry >= 32)
  1778. delay = 1000;
  1779. }
  1780. retry = 1;
  1781. break;
  1782. case LSRJT_LOGICAL_ERR:
  1783. /* There are some cases where switches return this
  1784. * error when they are not ready and should be returning
  1785. * Logical Busy. We should delay every time.
  1786. */
  1787. if (cmd == ELS_CMD_FDISC &&
  1788. stat.un.b.lsRjtRsnCodeExp == LSEXP_PORT_LOGIN_REQ) {
  1789. maxretry = 3;
  1790. delay = 1000;
  1791. retry = 1;
  1792. break;
  1793. }
  1794. case LSRJT_PROTOCOL_ERR:
  1795. if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
  1796. (cmd == ELS_CMD_FDISC) &&
  1797. ((stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_PNAME) ||
  1798. (stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_NPORT_ID))
  1799. ) {
  1800. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  1801. "0123 FDISC Failed (x%x). "
  1802. "Fabric Detected Bad WWN\n",
  1803. stat.un.lsRjtError);
  1804. lpfc_vport_set_state(vport,
  1805. FC_VPORT_FABRIC_REJ_WWN);
  1806. }
  1807. break;
  1808. }
  1809. break;
  1810. case IOSTAT_INTERMED_RSP:
  1811. case IOSTAT_BA_RJT:
  1812. break;
  1813. default:
  1814. break;
  1815. }
  1816. if (did == FDMI_DID)
  1817. retry = 1;
  1818. if ((cmd == ELS_CMD_FLOGI) &&
  1819. (phba->fc_topology != TOPOLOGY_LOOP) &&
  1820. !lpfc_error_lost_link(irsp)) {
  1821. /* FLOGI retry policy */
  1822. retry = 1;
  1823. maxretry = 48;
  1824. if (cmdiocb->retry >= 32)
  1825. delay = 1000;
  1826. }
  1827. if ((++cmdiocb->retry) >= maxretry) {
  1828. phba->fc_stat.elsRetryExceeded++;
  1829. retry = 0;
  1830. }
  1831. if ((vport->load_flag & FC_UNLOADING) != 0)
  1832. retry = 0;
  1833. if (retry) {
  1834. /* Retry ELS command <elsCmd> to remote NPORT <did> */
  1835. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  1836. "0107 Retry ELS command x%x to remote "
  1837. "NPORT x%x Data: x%x x%x\n",
  1838. cmd, did, cmdiocb->retry, delay);
  1839. if (((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) &&
  1840. ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
  1841. ((irsp->un.ulpWord[4] & 0xff) != IOERR_NO_RESOURCES))) {
  1842. /* Don't reset timer for no resources */
  1843. /* If discovery / RSCN timer is running, reset it */
  1844. if (timer_pending(&vport->fc_disctmo) ||
  1845. (vport->fc_flag & FC_RSCN_MODE))
  1846. lpfc_set_disctmo(vport);
  1847. }
  1848. phba->fc_stat.elsXmitRetry++;
  1849. if (ndlp && NLP_CHK_NODE_ACT(ndlp) && delay) {
  1850. phba->fc_stat.elsDelayRetry++;
  1851. ndlp->nlp_retry = cmdiocb->retry;
  1852. /* delay is specified in milliseconds */
  1853. mod_timer(&ndlp->nlp_delayfunc,
  1854. jiffies + msecs_to_jiffies(delay));
  1855. spin_lock_irq(shost->host_lock);
  1856. ndlp->nlp_flag |= NLP_DELAY_TMO;
  1857. spin_unlock_irq(shost->host_lock);
  1858. ndlp->nlp_prev_state = ndlp->nlp_state;
  1859. if (cmd == ELS_CMD_PRLI)
  1860. lpfc_nlp_set_state(vport, ndlp,
  1861. NLP_STE_REG_LOGIN_ISSUE);
  1862. else
  1863. lpfc_nlp_set_state(vport, ndlp,
  1864. NLP_STE_NPR_NODE);
  1865. ndlp->nlp_last_elscmd = cmd;
  1866. return 1;
  1867. }
  1868. switch (cmd) {
  1869. case ELS_CMD_FLOGI:
  1870. lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry);
  1871. return 1;
  1872. case ELS_CMD_FDISC:
  1873. lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry);
  1874. return 1;
  1875. case ELS_CMD_PLOGI:
  1876. if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
  1877. ndlp->nlp_prev_state = ndlp->nlp_state;
  1878. lpfc_nlp_set_state(vport, ndlp,
  1879. NLP_STE_PLOGI_ISSUE);
  1880. }
  1881. lpfc_issue_els_plogi(vport, did, cmdiocb->retry);
  1882. return 1;
  1883. case ELS_CMD_ADISC:
  1884. ndlp->nlp_prev_state = ndlp->nlp_state;
  1885. lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
  1886. lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry);
  1887. return 1;
  1888. case ELS_CMD_PRLI:
  1889. ndlp->nlp_prev_state = ndlp->nlp_state;
  1890. lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
  1891. lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry);
  1892. return 1;
  1893. case ELS_CMD_LOGO:
  1894. ndlp->nlp_prev_state = ndlp->nlp_state;
  1895. lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
  1896. lpfc_issue_els_logo(vport, ndlp, cmdiocb->retry);
  1897. return 1;
  1898. }
  1899. }
  1900. /* No retry ELS command <elsCmd> to remote NPORT <did> */
  1901. if (logerr) {
  1902. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  1903. "0137 No retry ELS command x%x to remote "
  1904. "NPORT x%x: Out of Resources: Error:x%x/%x\n",
  1905. cmd, did, irsp->ulpStatus,
  1906. irsp->un.ulpWord[4]);
  1907. }
  1908. else {
  1909. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  1910. "0108 No retry ELS command x%x to remote "
  1911. "NPORT x%x Retried:%d Error:x%x/%x\n",
  1912. cmd, did, cmdiocb->retry, irsp->ulpStatus,
  1913. irsp->un.ulpWord[4]);
  1914. }
  1915. return 0;
  1916. }
  1917. static int
  1918. lpfc_els_free_data(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr1)
  1919. {
  1920. struct lpfc_dmabuf *buf_ptr;
  1921. /* Free the response before processing the command. */
  1922. if (!list_empty(&buf_ptr1->list)) {
  1923. list_remove_head(&buf_ptr1->list, buf_ptr,
  1924. struct lpfc_dmabuf,
  1925. list);
  1926. lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
  1927. kfree(buf_ptr);
  1928. }
  1929. lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys);
  1930. kfree(buf_ptr1);
  1931. return 0;
  1932. }
  1933. static int
  1934. lpfc_els_free_bpl(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr)
  1935. {
  1936. lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
  1937. kfree(buf_ptr);
  1938. return 0;
  1939. }
  1940. int
  1941. lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb)
  1942. {
  1943. struct lpfc_dmabuf *buf_ptr, *buf_ptr1;
  1944. struct lpfc_nodelist *ndlp;
  1945. ndlp = (struct lpfc_nodelist *)elsiocb->context1;
  1946. if (ndlp) {
  1947. if (ndlp->nlp_flag & NLP_DEFER_RM) {
  1948. lpfc_nlp_put(ndlp);
  1949. /* If the ndlp is not being used by another discovery
  1950. * thread, free it.
  1951. */
  1952. if (!lpfc_nlp_not_used(ndlp)) {
  1953. /* If ndlp is being used by another discovery
  1954. * thread, just clear NLP_DEFER_RM
  1955. */
  1956. ndlp->nlp_flag &= ~NLP_DEFER_RM;
  1957. }
  1958. }
  1959. else
  1960. lpfc_nlp_put(ndlp);
  1961. elsiocb->context1 = NULL;
  1962. }
  1963. /* context2 = cmd, context2->next = rsp, context3 = bpl */
  1964. if (elsiocb->context2) {
  1965. if (elsiocb->iocb_flag & LPFC_DELAY_MEM_FREE) {
  1966. /* Firmware could still be in progress of DMAing
  1967. * payload, so don't free data buffer till after
  1968. * a hbeat.
  1969. */
  1970. elsiocb->iocb_flag &= ~LPFC_DELAY_MEM_FREE;
  1971. buf_ptr = elsiocb->context2;
  1972. elsiocb->context2 = NULL;
  1973. if (buf_ptr) {
  1974. buf_ptr1 = NULL;
  1975. spin_lock_irq(&phba->hbalock);
  1976. if (!list_empty(&buf_ptr->list)) {
  1977. list_remove_head(&buf_ptr->list,
  1978. buf_ptr1, struct lpfc_dmabuf,
  1979. list);
  1980. INIT_LIST_HEAD(&buf_ptr1->list);
  1981. list_add_tail(&buf_ptr1->list,
  1982. &phba->elsbuf);
  1983. phba->elsbuf_cnt++;
  1984. }
  1985. INIT_LIST_HEAD(&buf_ptr->list);
  1986. list_add_tail(&buf_ptr->list, &phba->elsbuf);
  1987. phba->elsbuf_cnt++;
  1988. spin_unlock_irq(&phba->hbalock);
  1989. }
  1990. } else {
  1991. buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2;
  1992. lpfc_els_free_data(phba, buf_ptr1);
  1993. }
  1994. }
  1995. if (elsiocb->context3) {
  1996. buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3;
  1997. lpfc_els_free_bpl(phba, buf_ptr);
  1998. }
  1999. lpfc_sli_release_iocbq(phba, elsiocb);
  2000. return 0;
  2001. }
  2002. static void
  2003. lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  2004. struct lpfc_iocbq *rspiocb)
  2005. {
  2006. struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
  2007. struct lpfc_vport *vport = cmdiocb->vport;
  2008. IOCB_t *irsp;
  2009. irsp = &rspiocb->iocb;
  2010. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
  2011. "ACC LOGO cmpl: status:x%x/x%x did:x%x",
  2012. irsp->ulpStatus, irsp->un.ulpWord[4], ndlp->nlp_DID);
  2013. /* ACC to LOGO completes to NPort <nlp_DID> */
  2014. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  2015. "0109 ACC to LOGO completes to NPort x%x "
  2016. "Data: x%x x%x x%x\n",
  2017. ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
  2018. ndlp->nlp_rpi);
  2019. if (ndlp->nlp_state == NLP_STE_NPR_NODE) {
  2020. /* NPort Recovery mode or node is just allocated */
  2021. if (!lpfc_nlp_not_used(ndlp)) {
  2022. /* If the ndlp is being used by another discovery
  2023. * thread, just unregister the RPI.
  2024. */
  2025. lpfc_unreg_rpi(vport, ndlp);
  2026. } else {
  2027. /* Indicate the node has already released, should
  2028. * not reference to it from within lpfc_els_free_iocb.
  2029. */
  2030. cmdiocb->context1 = NULL;
  2031. }
  2032. }
  2033. lpfc_els_free_iocb(phba, cmdiocb);
  2034. return;
  2035. }
  2036. void
  2037. lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  2038. {
  2039. struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
  2040. struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
  2041. pmb->context1 = NULL;
  2042. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  2043. kfree(mp);
  2044. mempool_free(pmb, phba->mbox_mem_pool);
  2045. if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
  2046. lpfc_nlp_put(ndlp);
  2047. /* This is the end of the default RPI cleanup logic for this
  2048. * ndlp. If no other discovery threads are using this ndlp.
  2049. * we should free all resources associated with it.
  2050. */
  2051. lpfc_nlp_not_used(ndlp);
  2052. }
  2053. return;
  2054. }
  2055. static void
  2056. lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  2057. struct lpfc_iocbq *rspiocb)
  2058. {
  2059. struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
  2060. struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL;
  2061. struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL;
  2062. IOCB_t *irsp;
  2063. uint8_t *pcmd;
  2064. LPFC_MBOXQ_t *mbox = NULL;
  2065. struct lpfc_dmabuf *mp = NULL;
  2066. uint32_t ls_rjt = 0;
  2067. irsp = &rspiocb->iocb;
  2068. if (cmdiocb->context_un.mbox)
  2069. mbox = cmdiocb->context_un.mbox;
  2070. /* First determine if this is a LS_RJT cmpl. Note, this callback
  2071. * function can have cmdiocb->contest1 (ndlp) field set to NULL.
  2072. */
  2073. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
  2074. if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
  2075. (*((uint32_t *) (pcmd)) == ELS_CMD_LS_RJT)) {
  2076. /* A LS_RJT associated with Default RPI cleanup has its own
  2077. * seperate code path.
  2078. */
  2079. if (!(ndlp->nlp_flag & NLP_RM_DFLT_RPI))
  2080. ls_rjt = 1;
  2081. }
  2082. /* Check to see if link went down during discovery */
  2083. if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || lpfc_els_chk_latt(vport)) {
  2084. if (mbox) {
  2085. mp = (struct lpfc_dmabuf *) mbox->context1;
  2086. if (mp) {
  2087. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  2088. kfree(mp);
  2089. }
  2090. mempool_free(mbox, phba->mbox_mem_pool);
  2091. }
  2092. if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
  2093. (ndlp->nlp_flag & NLP_RM_DFLT_RPI))
  2094. if (lpfc_nlp_not_used(ndlp)) {
  2095. ndlp = NULL;
  2096. /* Indicate the node has already released,
  2097. * should not reference to it from within
  2098. * the routine lpfc_els_free_iocb.
  2099. */
  2100. cmdiocb->context1 = NULL;
  2101. }
  2102. goto out;
  2103. }
  2104. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
  2105. "ELS rsp cmpl: status:x%x/x%x did:x%x",
  2106. irsp->ulpStatus, irsp->un.ulpWord[4],
  2107. cmdiocb->iocb.un.elsreq64.remoteID);
  2108. /* ELS response tag <ulpIoTag> completes */
  2109. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  2110. "0110 ELS response tag x%x completes "
  2111. "Data: x%x x%x x%x x%x x%x x%x x%x\n",
  2112. cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus,
  2113. rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout,
  2114. ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
  2115. ndlp->nlp_rpi);
  2116. if (mbox) {
  2117. if ((rspiocb->iocb.ulpStatus == 0)
  2118. && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) {
  2119. lpfc_unreg_rpi(vport, ndlp);
  2120. /* Increment reference count to ndlp to hold the
  2121. * reference to ndlp for the callback function.
  2122. */
  2123. mbox->context2 = lpfc_nlp_get(ndlp);
  2124. mbox->vport = vport;
  2125. if (ndlp->nlp_flag & NLP_RM_DFLT_RPI) {
  2126. mbox->mbox_flag |= LPFC_MBX_IMED_UNREG;
  2127. mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
  2128. }
  2129. else {
  2130. mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
  2131. ndlp->nlp_prev_state = ndlp->nlp_state;
  2132. lpfc_nlp_set_state(vport, ndlp,
  2133. NLP_STE_REG_LOGIN_ISSUE);
  2134. }
  2135. if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
  2136. != MBX_NOT_FINISHED)
  2137. goto out;
  2138. else
  2139. /* Decrement the ndlp reference count we
  2140. * set for this failed mailbox command.
  2141. */
  2142. lpfc_nlp_put(ndlp);
  2143. /* ELS rsp: Cannot issue reg_login for <NPortid> */
  2144. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  2145. "0138 ELS rsp: Cannot issue reg_login for x%x "
  2146. "Data: x%x x%x x%x\n",
  2147. ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
  2148. ndlp->nlp_rpi);
  2149. if (lpfc_nlp_not_used(ndlp)) {
  2150. ndlp = NULL;
  2151. /* Indicate node has already been released,
  2152. * should not reference to it from within
  2153. * the routine lpfc_els_free_iocb.
  2154. */
  2155. cmdiocb->context1 = NULL;
  2156. }
  2157. } else {
  2158. /* Do not drop node for lpfc_els_abort'ed ELS cmds */
  2159. if (!lpfc_error_lost_link(irsp) &&
  2160. ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
  2161. if (lpfc_nlp_not_used(ndlp)) {
  2162. ndlp = NULL;
  2163. /* Indicate node has already been
  2164. * released, should not reference
  2165. * to it from within the routine
  2166. * lpfc_els_free_iocb.
  2167. */
  2168. cmdiocb->context1 = NULL;
  2169. }
  2170. }
  2171. }
  2172. mp = (struct lpfc_dmabuf *) mbox->context1;
  2173. if (mp) {
  2174. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  2175. kfree(mp);
  2176. }
  2177. mempool_free(mbox, phba->mbox_mem_pool);
  2178. }
  2179. out:
  2180. if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
  2181. spin_lock_irq(shost->host_lock);
  2182. ndlp->nlp_flag &= ~(NLP_ACC_REGLOGIN | NLP_RM_DFLT_RPI);
  2183. spin_unlock_irq(shost->host_lock);
  2184. /* If the node is not being used by another discovery thread,
  2185. * and we are sending a reject, we are done with it.
  2186. * Release driver reference count here and free associated
  2187. * resources.
  2188. */
  2189. if (ls_rjt)
  2190. if (lpfc_nlp_not_used(ndlp))
  2191. /* Indicate node has already been released,
  2192. * should not reference to it from within
  2193. * the routine lpfc_els_free_iocb.
  2194. */
  2195. cmdiocb->context1 = NULL;
  2196. }
  2197. lpfc_els_free_iocb(phba, cmdiocb);
  2198. return;
  2199. }
  2200. int
  2201. lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag,
  2202. struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
  2203. LPFC_MBOXQ_t *mbox)
  2204. {
  2205. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2206. struct lpfc_hba *phba = vport->phba;
  2207. IOCB_t *icmd;
  2208. IOCB_t *oldcmd;
  2209. struct lpfc_iocbq *elsiocb;
  2210. struct lpfc_sli_ring *pring;
  2211. struct lpfc_sli *psli;
  2212. uint8_t *pcmd;
  2213. uint16_t cmdsize;
  2214. int rc;
  2215. ELS_PKT *els_pkt_ptr;
  2216. psli = &phba->sli;
  2217. pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
  2218. oldcmd = &oldiocb->iocb;
  2219. switch (flag) {
  2220. case ELS_CMD_ACC:
  2221. cmdsize = sizeof(uint32_t);
  2222. elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
  2223. ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
  2224. if (!elsiocb) {
  2225. spin_lock_irq(shost->host_lock);
  2226. ndlp->nlp_flag &= ~NLP_LOGO_ACC;
  2227. spin_unlock_irq(shost->host_lock);
  2228. return 1;
  2229. }
  2230. icmd = &elsiocb->iocb;
  2231. icmd->ulpContext = oldcmd->ulpContext; /* Xri */
  2232. pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  2233. *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
  2234. pcmd += sizeof(uint32_t);
  2235. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
  2236. "Issue ACC: did:x%x flg:x%x",
  2237. ndlp->nlp_DID, ndlp->nlp_flag, 0);
  2238. break;
  2239. case ELS_CMD_PLOGI:
  2240. cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t));
  2241. elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
  2242. ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
  2243. if (!elsiocb)
  2244. return 1;
  2245. icmd = &elsiocb->iocb;
  2246. icmd->ulpContext = oldcmd->ulpContext; /* Xri */
  2247. pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  2248. if (mbox)
  2249. elsiocb->context_un.mbox = mbox;
  2250. *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
  2251. pcmd += sizeof(uint32_t);
  2252. memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
  2253. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
  2254. "Issue ACC PLOGI: did:x%x flg:x%x",
  2255. ndlp->nlp_DID, ndlp->nlp_flag, 0);
  2256. break;
  2257. case ELS_CMD_PRLO:
  2258. cmdsize = sizeof(uint32_t) + sizeof(PRLO);
  2259. elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
  2260. ndlp, ndlp->nlp_DID, ELS_CMD_PRLO);
  2261. if (!elsiocb)
  2262. return 1;
  2263. icmd = &elsiocb->iocb;
  2264. icmd->ulpContext = oldcmd->ulpContext; /* Xri */
  2265. pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  2266. memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt,
  2267. sizeof(uint32_t) + sizeof(PRLO));
  2268. *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC;
  2269. els_pkt_ptr = (ELS_PKT *) pcmd;
  2270. els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED;
  2271. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
  2272. "Issue ACC PRLO: did:x%x flg:x%x",
  2273. ndlp->nlp_DID, ndlp->nlp_flag, 0);
  2274. break;
  2275. default:
  2276. return 1;
  2277. }
  2278. /* Xmit ELS ACC response tag <ulpIoTag> */
  2279. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  2280. "0128 Xmit ELS ACC response tag x%x, XRI: x%x, "
  2281. "DID: x%x, nlp_flag: x%x nlp_state: x%x RPI: x%x\n",
  2282. elsiocb->iotag, elsiocb->iocb.ulpContext,
  2283. ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
  2284. ndlp->nlp_rpi);
  2285. if (ndlp->nlp_flag & NLP_LOGO_ACC) {
  2286. spin_lock_irq(shost->host_lock);
  2287. ndlp->nlp_flag &= ~NLP_LOGO_ACC;
  2288. spin_unlock_irq(shost->host_lock);
  2289. elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc;
  2290. } else {
  2291. elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
  2292. }
  2293. phba->fc_stat.elsXmitACC++;
  2294. rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
  2295. if (rc == IOCB_ERROR) {
  2296. lpfc_els_free_iocb(phba, elsiocb);
  2297. return 1;
  2298. }
  2299. return 0;
  2300. }
  2301. int
  2302. lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError,
  2303. struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
  2304. LPFC_MBOXQ_t *mbox)
  2305. {
  2306. struct lpfc_hba *phba = vport->phba;
  2307. IOCB_t *icmd;
  2308. IOCB_t *oldcmd;
  2309. struct lpfc_iocbq *elsiocb;
  2310. struct lpfc_sli_ring *pring;
  2311. struct lpfc_sli *psli;
  2312. uint8_t *pcmd;
  2313. uint16_t cmdsize;
  2314. int rc;
  2315. psli = &phba->sli;
  2316. pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
  2317. cmdsize = 2 * sizeof(uint32_t);
  2318. elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
  2319. ndlp->nlp_DID, ELS_CMD_LS_RJT);
  2320. if (!elsiocb)
  2321. return 1;
  2322. icmd = &elsiocb->iocb;
  2323. oldcmd = &oldiocb->iocb;
  2324. icmd->ulpContext = oldcmd->ulpContext; /* Xri */
  2325. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  2326. *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
  2327. pcmd += sizeof(uint32_t);
  2328. *((uint32_t *) (pcmd)) = rejectError;
  2329. if (mbox)
  2330. elsiocb->context_un.mbox = mbox;
  2331. /* Xmit ELS RJT <err> response tag <ulpIoTag> */
  2332. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  2333. "0129 Xmit ELS RJT x%x response tag x%x "
  2334. "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
  2335. "rpi x%x\n",
  2336. rejectError, elsiocb->iotag,
  2337. elsiocb->iocb.ulpContext, ndlp->nlp_DID,
  2338. ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
  2339. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
  2340. "Issue LS_RJT: did:x%x flg:x%x err:x%x",
  2341. ndlp->nlp_DID, ndlp->nlp_flag, rejectError);
  2342. phba->fc_stat.elsXmitLSRJT++;
  2343. elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
  2344. rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
  2345. if (rc == IOCB_ERROR) {
  2346. lpfc_els_free_iocb(phba, elsiocb);
  2347. return 1;
  2348. }
  2349. return 0;
  2350. }
  2351. int
  2352. lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
  2353. struct lpfc_nodelist *ndlp)
  2354. {
  2355. struct lpfc_hba *phba = vport->phba;
  2356. struct lpfc_sli *psli = &phba->sli;
  2357. struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
  2358. ADISC *ap;
  2359. IOCB_t *icmd, *oldcmd;
  2360. struct lpfc_iocbq *elsiocb;
  2361. uint8_t *pcmd;
  2362. uint16_t cmdsize;
  2363. int rc;
  2364. cmdsize = sizeof(uint32_t) + sizeof(ADISC);
  2365. elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
  2366. ndlp->nlp_DID, ELS_CMD_ACC);
  2367. if (!elsiocb)
  2368. return 1;
  2369. icmd = &elsiocb->iocb;
  2370. oldcmd = &oldiocb->iocb;
  2371. icmd->ulpContext = oldcmd->ulpContext; /* Xri */
  2372. /* Xmit ADISC ACC response tag <ulpIoTag> */
  2373. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  2374. "0130 Xmit ADISC ACC response iotag x%x xri: "
  2375. "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n",
  2376. elsiocb->iotag, elsiocb->iocb.ulpContext,
  2377. ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
  2378. ndlp->nlp_rpi);
  2379. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  2380. *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
  2381. pcmd += sizeof(uint32_t);
  2382. ap = (ADISC *) (pcmd);
  2383. ap->hardAL_PA = phba->fc_pref_ALPA;
  2384. memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
  2385. memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
  2386. ap->DID = be32_to_cpu(vport->fc_myDID);
  2387. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
  2388. "Issue ACC ADISC: did:x%x flg:x%x",
  2389. ndlp->nlp_DID, ndlp->nlp_flag, 0);
  2390. phba->fc_stat.elsXmitACC++;
  2391. elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
  2392. rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
  2393. if (rc == IOCB_ERROR) {
  2394. lpfc_els_free_iocb(phba, elsiocb);
  2395. return 1;
  2396. }
  2397. return 0;
  2398. }
  2399. int
  2400. lpfc_els_rsp_prli_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
  2401. struct lpfc_nodelist *ndlp)
  2402. {
  2403. struct lpfc_hba *phba = vport->phba;
  2404. PRLI *npr;
  2405. lpfc_vpd_t *vpd;
  2406. IOCB_t *icmd;
  2407. IOCB_t *oldcmd;
  2408. struct lpfc_iocbq *elsiocb;
  2409. struct lpfc_sli_ring *pring;
  2410. struct lpfc_sli *psli;
  2411. uint8_t *pcmd;
  2412. uint16_t cmdsize;
  2413. int rc;
  2414. psli = &phba->sli;
  2415. pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
  2416. cmdsize = sizeof(uint32_t) + sizeof(PRLI);
  2417. elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
  2418. ndlp->nlp_DID, (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK)));
  2419. if (!elsiocb)
  2420. return 1;
  2421. icmd = &elsiocb->iocb;
  2422. oldcmd = &oldiocb->iocb;
  2423. icmd->ulpContext = oldcmd->ulpContext; /* Xri */
  2424. /* Xmit PRLI ACC response tag <ulpIoTag> */
  2425. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  2426. "0131 Xmit PRLI ACC response tag x%x xri x%x, "
  2427. "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
  2428. elsiocb->iotag, elsiocb->iocb.ulpContext,
  2429. ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
  2430. ndlp->nlp_rpi);
  2431. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  2432. *((uint32_t *) (pcmd)) = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK));
  2433. pcmd += sizeof(uint32_t);
  2434. /* For PRLI, remainder of payload is PRLI parameter page */
  2435. memset(pcmd, 0, sizeof(PRLI));
  2436. npr = (PRLI *) pcmd;
  2437. vpd = &phba->vpd;
  2438. /*
  2439. * If the remote port is a target and our firmware version is 3.20 or
  2440. * later, set the following bits for FC-TAPE support.
  2441. */
  2442. if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
  2443. (vpd->rev.feaLevelHigh >= 0x02)) {
  2444. npr->ConfmComplAllowed = 1;
  2445. npr->Retry = 1;
  2446. npr->TaskRetryIdReq = 1;
  2447. }
  2448. npr->acceptRspCode = PRLI_REQ_EXECUTED;
  2449. npr->estabImagePair = 1;
  2450. npr->readXferRdyDis = 1;
  2451. npr->ConfmComplAllowed = 1;
  2452. npr->prliType = PRLI_FCP_TYPE;
  2453. npr->initiatorFunc = 1;
  2454. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
  2455. "Issue ACC PRLI: did:x%x flg:x%x",
  2456. ndlp->nlp_DID, ndlp->nlp_flag, 0);
  2457. phba->fc_stat.elsXmitACC++;
  2458. elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
  2459. rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
  2460. if (rc == IOCB_ERROR) {
  2461. lpfc_els_free_iocb(phba, elsiocb);
  2462. return 1;
  2463. }
  2464. return 0;
  2465. }
  2466. static int
  2467. lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format,
  2468. struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
  2469. {
  2470. struct lpfc_hba *phba = vport->phba;
  2471. RNID *rn;
  2472. IOCB_t *icmd, *oldcmd;
  2473. struct lpfc_iocbq *elsiocb;
  2474. struct lpfc_sli_ring *pring;
  2475. struct lpfc_sli *psli;
  2476. uint8_t *pcmd;
  2477. uint16_t cmdsize;
  2478. int rc;
  2479. psli = &phba->sli;
  2480. pring = &psli->ring[LPFC_ELS_RING];
  2481. cmdsize = sizeof(uint32_t) + sizeof(uint32_t)
  2482. + (2 * sizeof(struct lpfc_name));
  2483. if (format)
  2484. cmdsize += sizeof(RNID_TOP_DISC);
  2485. elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
  2486. ndlp->nlp_DID, ELS_CMD_ACC);
  2487. if (!elsiocb)
  2488. return 1;
  2489. icmd = &elsiocb->iocb;
  2490. oldcmd = &oldiocb->iocb;
  2491. icmd->ulpContext = oldcmd->ulpContext; /* Xri */
  2492. /* Xmit RNID ACC response tag <ulpIoTag> */
  2493. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  2494. "0132 Xmit RNID ACC response tag x%x xri x%x\n",
  2495. elsiocb->iotag, elsiocb->iocb.ulpContext);
  2496. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  2497. *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
  2498. pcmd += sizeof(uint32_t);
  2499. memset(pcmd, 0, sizeof(RNID));
  2500. rn = (RNID *) (pcmd);
  2501. rn->Format = format;
  2502. rn->CommonLen = (2 * sizeof(struct lpfc_name));
  2503. memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name));
  2504. memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
  2505. switch (format) {
  2506. case 0:
  2507. rn->SpecificLen = 0;
  2508. break;
  2509. case RNID_TOPOLOGY_DISC:
  2510. rn->SpecificLen = sizeof(RNID_TOP_DISC);
  2511. memcpy(&rn->un.topologyDisc.portName,
  2512. &vport->fc_portname, sizeof(struct lpfc_name));
  2513. rn->un.topologyDisc.unitType = RNID_HBA;
  2514. rn->un.topologyDisc.physPort = 0;
  2515. rn->un.topologyDisc.attachedNodes = 0;
  2516. break;
  2517. default:
  2518. rn->CommonLen = 0;
  2519. rn->SpecificLen = 0;
  2520. break;
  2521. }
  2522. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
  2523. "Issue ACC RNID: did:x%x flg:x%x",
  2524. ndlp->nlp_DID, ndlp->nlp_flag, 0);
  2525. phba->fc_stat.elsXmitACC++;
  2526. elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
  2527. lpfc_nlp_put(ndlp);
  2528. elsiocb->context1 = NULL; /* Don't need ndlp for cmpl,
  2529. * it could be freed */
  2530. rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
  2531. if (rc == IOCB_ERROR) {
  2532. lpfc_els_free_iocb(phba, elsiocb);
  2533. return 1;
  2534. }
  2535. return 0;
  2536. }
  2537. int
  2538. lpfc_els_disc_adisc(struct lpfc_vport *vport)
  2539. {
  2540. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2541. struct lpfc_nodelist *ndlp, *next_ndlp;
  2542. int sentadisc = 0;
  2543. /* go thru NPR nodes and issue any remaining ELS ADISCs */
  2544. list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
  2545. if (!NLP_CHK_NODE_ACT(ndlp))
  2546. continue;
  2547. if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
  2548. (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
  2549. (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) {
  2550. spin_lock_irq(shost->host_lock);
  2551. ndlp->nlp_flag &= ~NLP_NPR_ADISC;
  2552. spin_unlock_irq(shost->host_lock);
  2553. ndlp->nlp_prev_state = ndlp->nlp_state;
  2554. lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
  2555. lpfc_issue_els_adisc(vport, ndlp, 0);
  2556. sentadisc++;
  2557. vport->num_disc_nodes++;
  2558. if (vport->num_disc_nodes >=
  2559. vport->cfg_discovery_threads) {
  2560. spin_lock_irq(shost->host_lock);
  2561. vport->fc_flag |= FC_NLP_MORE;
  2562. spin_unlock_irq(shost->host_lock);
  2563. break;
  2564. }
  2565. }
  2566. }
  2567. if (sentadisc == 0) {
  2568. spin_lock_irq(shost->host_lock);
  2569. vport->fc_flag &= ~FC_NLP_MORE;
  2570. spin_unlock_irq(shost->host_lock);
  2571. }
  2572. return sentadisc;
  2573. }
  2574. int
  2575. lpfc_els_disc_plogi(struct lpfc_vport *vport)
  2576. {
  2577. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2578. struct lpfc_nodelist *ndlp, *next_ndlp;
  2579. int sentplogi = 0;
  2580. /* go thru NPR nodes and issue any remaining ELS PLOGIs */
  2581. list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
  2582. if (!NLP_CHK_NODE_ACT(ndlp))
  2583. continue;
  2584. if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
  2585. (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
  2586. (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 &&
  2587. (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) {
  2588. ndlp->nlp_prev_state = ndlp->nlp_state;
  2589. lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
  2590. lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
  2591. sentplogi++;
  2592. vport->num_disc_nodes++;
  2593. if (vport->num_disc_nodes >=
  2594. vport->cfg_discovery_threads) {
  2595. spin_lock_irq(shost->host_lock);
  2596. vport->fc_flag |= FC_NLP_MORE;
  2597. spin_unlock_irq(shost->host_lock);
  2598. break;
  2599. }
  2600. }
  2601. }
  2602. if (sentplogi) {
  2603. lpfc_set_disctmo(vport);
  2604. }
  2605. else {
  2606. spin_lock_irq(shost->host_lock);
  2607. vport->fc_flag &= ~FC_NLP_MORE;
  2608. spin_unlock_irq(shost->host_lock);
  2609. }
  2610. return sentplogi;
  2611. }
  2612. void
  2613. lpfc_els_flush_rscn(struct lpfc_vport *vport)
  2614. {
  2615. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2616. struct lpfc_hba *phba = vport->phba;
  2617. int i;
  2618. spin_lock_irq(shost->host_lock);
  2619. if (vport->fc_rscn_flush) {
  2620. /* Another thread is walking fc_rscn_id_list on this vport */
  2621. spin_unlock_irq(shost->host_lock);
  2622. return;
  2623. }
  2624. /* Indicate we are walking lpfc_els_flush_rscn on this vport */
  2625. vport->fc_rscn_flush = 1;
  2626. spin_unlock_irq(shost->host_lock);
  2627. for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
  2628. lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]);
  2629. vport->fc_rscn_id_list[i] = NULL;
  2630. }
  2631. spin_lock_irq(shost->host_lock);
  2632. vport->fc_rscn_id_cnt = 0;
  2633. vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY);
  2634. spin_unlock_irq(shost->host_lock);
  2635. lpfc_can_disctmo(vport);
  2636. /* Indicate we are done walking this fc_rscn_id_list */
  2637. vport->fc_rscn_flush = 0;
  2638. }
  2639. int
  2640. lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did)
  2641. {
  2642. D_ID ns_did;
  2643. D_ID rscn_did;
  2644. uint32_t *lp;
  2645. uint32_t payload_len, i;
  2646. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2647. ns_did.un.word = did;
  2648. /* Never match fabric nodes for RSCNs */
  2649. if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
  2650. return 0;
  2651. /* If we are doing a FULL RSCN rediscovery, match everything */
  2652. if (vport->fc_flag & FC_RSCN_DISCOVERY)
  2653. return did;
  2654. spin_lock_irq(shost->host_lock);
  2655. if (vport->fc_rscn_flush) {
  2656. /* Another thread is walking fc_rscn_id_list on this vport */
  2657. spin_unlock_irq(shost->host_lock);
  2658. return 0;
  2659. }
  2660. /* Indicate we are walking fc_rscn_id_list on this vport */
  2661. vport->fc_rscn_flush = 1;
  2662. spin_unlock_irq(shost->host_lock);
  2663. for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
  2664. lp = vport->fc_rscn_id_list[i]->virt;
  2665. payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
  2666. payload_len -= sizeof(uint32_t); /* take off word 0 */
  2667. while (payload_len) {
  2668. rscn_did.un.word = be32_to_cpu(*lp++);
  2669. payload_len -= sizeof(uint32_t);
  2670. switch (rscn_did.un.b.resv) {
  2671. case 0: /* Single N_Port ID effected */
  2672. if (ns_did.un.word == rscn_did.un.word)
  2673. goto return_did_out;
  2674. break;
  2675. case 1: /* Whole N_Port Area effected */
  2676. if ((ns_did.un.b.domain == rscn_did.un.b.domain)
  2677. && (ns_did.un.b.area == rscn_did.un.b.area))
  2678. goto return_did_out;
  2679. break;
  2680. case 2: /* Whole N_Port Domain effected */
  2681. if (ns_did.un.b.domain == rscn_did.un.b.domain)
  2682. goto return_did_out;
  2683. break;
  2684. default:
  2685. /* Unknown Identifier in RSCN node */
  2686. lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
  2687. "0217 Unknown Identifier in "
  2688. "RSCN payload Data: x%x\n",
  2689. rscn_did.un.word);
  2690. case 3: /* Whole Fabric effected */
  2691. goto return_did_out;
  2692. }
  2693. }
  2694. }
  2695. /* Indicate we are done with walking fc_rscn_id_list on this vport */
  2696. vport->fc_rscn_flush = 0;
  2697. return 0;
  2698. return_did_out:
  2699. /* Indicate we are done with walking fc_rscn_id_list on this vport */
  2700. vport->fc_rscn_flush = 0;
  2701. return did;
  2702. }
  2703. static int
  2704. lpfc_rscn_recovery_check(struct lpfc_vport *vport)
  2705. {
  2706. struct lpfc_nodelist *ndlp = NULL;
  2707. /* Move all affected nodes by pending RSCNs to NPR state. */
  2708. list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
  2709. if (!NLP_CHK_NODE_ACT(ndlp) ||
  2710. (ndlp->nlp_state == NLP_STE_UNUSED_NODE) ||
  2711. !lpfc_rscn_payload_check(vport, ndlp->nlp_DID))
  2712. continue;
  2713. lpfc_disc_state_machine(vport, ndlp, NULL,
  2714. NLP_EVT_DEVICE_RECOVERY);
  2715. lpfc_cancel_retry_delay_tmo(vport, ndlp);
  2716. }
  2717. return 0;
  2718. }
  2719. static int
  2720. lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
  2721. struct lpfc_nodelist *ndlp)
  2722. {
  2723. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2724. struct lpfc_hba *phba = vport->phba;
  2725. struct lpfc_dmabuf *pcmd;
  2726. uint32_t *lp, *datap;
  2727. IOCB_t *icmd;
  2728. uint32_t payload_len, length, nportid, *cmd;
  2729. int rscn_cnt;
  2730. int rscn_id = 0, hba_id = 0;
  2731. int i;
  2732. icmd = &cmdiocb->iocb;
  2733. pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
  2734. lp = (uint32_t *) pcmd->virt;
  2735. payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
  2736. payload_len -= sizeof(uint32_t); /* take off word 0 */
  2737. /* RSCN received */
  2738. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  2739. "0214 RSCN received Data: x%x x%x x%x x%x\n",
  2740. vport->fc_flag, payload_len, *lp,
  2741. vport->fc_rscn_id_cnt);
  2742. for (i = 0; i < payload_len/sizeof(uint32_t); i++)
  2743. fc_host_post_event(shost, fc_get_event_number(),
  2744. FCH_EVT_RSCN, lp[i]);
  2745. /* If we are about to begin discovery, just ACC the RSCN.
  2746. * Discovery processing will satisfy it.
  2747. */
  2748. if (vport->port_state <= LPFC_NS_QRY) {
  2749. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  2750. "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x",
  2751. ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
  2752. lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
  2753. return 0;
  2754. }
  2755. /* If this RSCN just contains NPortIDs for other vports on this HBA,
  2756. * just ACC and ignore it.
  2757. */
  2758. if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
  2759. !(vport->cfg_peer_port_login)) {
  2760. i = payload_len;
  2761. datap = lp;
  2762. while (i > 0) {
  2763. nportid = *datap++;
  2764. nportid = ((be32_to_cpu(nportid)) & Mask_DID);
  2765. i -= sizeof(uint32_t);
  2766. rscn_id++;
  2767. if (lpfc_find_vport_by_did(phba, nportid))
  2768. hba_id++;
  2769. }
  2770. if (rscn_id == hba_id) {
  2771. /* ALL NPortIDs in RSCN are on HBA */
  2772. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  2773. "0214 Ignore RSCN "
  2774. "Data: x%x x%x x%x x%x\n",
  2775. vport->fc_flag, payload_len,
  2776. *lp, vport->fc_rscn_id_cnt);
  2777. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  2778. "RCV RSCN vport: did:x%x/ste:x%x flg:x%x",
  2779. ndlp->nlp_DID, vport->port_state,
  2780. ndlp->nlp_flag);
  2781. lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb,
  2782. ndlp, NULL);
  2783. return 0;
  2784. }
  2785. }
  2786. spin_lock_irq(shost->host_lock);
  2787. if (vport->fc_rscn_flush) {
  2788. /* Another thread is walking fc_rscn_id_list on this vport */
  2789. spin_unlock_irq(shost->host_lock);
  2790. vport->fc_flag |= FC_RSCN_DISCOVERY;
  2791. /* Send back ACC */
  2792. lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
  2793. return 0;
  2794. }
  2795. /* Indicate we are walking fc_rscn_id_list on this vport */
  2796. vport->fc_rscn_flush = 1;
  2797. spin_unlock_irq(shost->host_lock);
  2798. /* Get the array count after sucessfully have the token */
  2799. rscn_cnt = vport->fc_rscn_id_cnt;
  2800. /* If we are already processing an RSCN, save the received
  2801. * RSCN payload buffer, cmdiocb->context2 to process later.
  2802. */
  2803. if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) {
  2804. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  2805. "RCV RSCN defer: did:x%x/ste:x%x flg:x%x",
  2806. ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
  2807. spin_lock_irq(shost->host_lock);
  2808. vport->fc_flag |= FC_RSCN_DEFERRED;
  2809. if ((rscn_cnt < FC_MAX_HOLD_RSCN) &&
  2810. !(vport->fc_flag & FC_RSCN_DISCOVERY)) {
  2811. vport->fc_flag |= FC_RSCN_MODE;
  2812. spin_unlock_irq(shost->host_lock);
  2813. if (rscn_cnt) {
  2814. cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt;
  2815. length = be32_to_cpu(*cmd & ~ELS_CMD_MASK);
  2816. }
  2817. if ((rscn_cnt) &&
  2818. (payload_len + length <= LPFC_BPL_SIZE)) {
  2819. *cmd &= ELS_CMD_MASK;
  2820. *cmd |= cpu_to_be32(payload_len + length);
  2821. memcpy(((uint8_t *)cmd) + length, lp,
  2822. payload_len);
  2823. } else {
  2824. vport->fc_rscn_id_list[rscn_cnt] = pcmd;
  2825. vport->fc_rscn_id_cnt++;
  2826. /* If we zero, cmdiocb->context2, the calling
  2827. * routine will not try to free it.
  2828. */
  2829. cmdiocb->context2 = NULL;
  2830. }
  2831. /* Deferred RSCN */
  2832. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  2833. "0235 Deferred RSCN "
  2834. "Data: x%x x%x x%x\n",
  2835. vport->fc_rscn_id_cnt, vport->fc_flag,
  2836. vport->port_state);
  2837. } else {
  2838. vport->fc_flag |= FC_RSCN_DISCOVERY;
  2839. spin_unlock_irq(shost->host_lock);
  2840. /* ReDiscovery RSCN */
  2841. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  2842. "0234 ReDiscovery RSCN "
  2843. "Data: x%x x%x x%x\n",
  2844. vport->fc_rscn_id_cnt, vport->fc_flag,
  2845. vport->port_state);
  2846. }
  2847. /* Indicate we are done walking fc_rscn_id_list on this vport */
  2848. vport->fc_rscn_flush = 0;
  2849. /* Send back ACC */
  2850. lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
  2851. /* send RECOVERY event for ALL nodes that match RSCN payload */
  2852. lpfc_rscn_recovery_check(vport);
  2853. spin_lock_irq(shost->host_lock);
  2854. vport->fc_flag &= ~FC_RSCN_DEFERRED;
  2855. spin_unlock_irq(shost->host_lock);
  2856. return 0;
  2857. }
  2858. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  2859. "RCV RSCN: did:x%x/ste:x%x flg:x%x",
  2860. ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
  2861. spin_lock_irq(shost->host_lock);
  2862. vport->fc_flag |= FC_RSCN_MODE;
  2863. spin_unlock_irq(shost->host_lock);
  2864. vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd;
  2865. /* Indicate we are done walking fc_rscn_id_list on this vport */
  2866. vport->fc_rscn_flush = 0;
  2867. /*
  2868. * If we zero, cmdiocb->context2, the calling routine will
  2869. * not try to free it.
  2870. */
  2871. cmdiocb->context2 = NULL;
  2872. lpfc_set_disctmo(vport);
  2873. /* Send back ACC */
  2874. lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
  2875. /* send RECOVERY event for ALL nodes that match RSCN payload */
  2876. lpfc_rscn_recovery_check(vport);
  2877. return lpfc_els_handle_rscn(vport);
  2878. }
  2879. int
  2880. lpfc_els_handle_rscn(struct lpfc_vport *vport)
  2881. {
  2882. struct lpfc_nodelist *ndlp;
  2883. struct lpfc_hba *phba = vport->phba;
  2884. /* Ignore RSCN if the port is being torn down. */
  2885. if (vport->load_flag & FC_UNLOADING) {
  2886. lpfc_els_flush_rscn(vport);
  2887. return 0;
  2888. }
  2889. /* Start timer for RSCN processing */
  2890. lpfc_set_disctmo(vport);
  2891. /* RSCN processed */
  2892. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  2893. "0215 RSCN processed Data: x%x x%x x%x x%x\n",
  2894. vport->fc_flag, 0, vport->fc_rscn_id_cnt,
  2895. vport->port_state);
  2896. /* To process RSCN, first compare RSCN data with NameServer */
  2897. vport->fc_ns_retry = 0;
  2898. vport->num_disc_nodes = 0;
  2899. ndlp = lpfc_findnode_did(vport, NameServer_DID);
  2900. if (ndlp && NLP_CHK_NODE_ACT(ndlp)
  2901. && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) {
  2902. /* Good ndlp, issue CT Request to NameServer */
  2903. if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, 0) == 0)
  2904. /* Wait for NameServer query cmpl before we can
  2905. continue */
  2906. return 1;
  2907. } else {
  2908. /* If login to NameServer does not exist, issue one */
  2909. /* Good status, issue PLOGI to NameServer */
  2910. ndlp = lpfc_findnode_did(vport, NameServer_DID);
  2911. if (ndlp && NLP_CHK_NODE_ACT(ndlp))
  2912. /* Wait for NameServer login cmpl before we can
  2913. continue */
  2914. return 1;
  2915. if (ndlp) {
  2916. ndlp = lpfc_enable_node(vport, ndlp,
  2917. NLP_STE_PLOGI_ISSUE);
  2918. if (!ndlp) {
  2919. lpfc_els_flush_rscn(vport);
  2920. return 0;
  2921. }
  2922. ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE;
  2923. } else {
  2924. ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
  2925. if (!ndlp) {
  2926. lpfc_els_flush_rscn(vport);
  2927. return 0;
  2928. }
  2929. lpfc_nlp_init(vport, ndlp, NameServer_DID);
  2930. ndlp->nlp_prev_state = ndlp->nlp_state;
  2931. lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
  2932. }
  2933. ndlp->nlp_type |= NLP_FABRIC;
  2934. lpfc_issue_els_plogi(vport, NameServer_DID, 0);
  2935. /* Wait for NameServer login cmpl before we can
  2936. * continue
  2937. */
  2938. return 1;
  2939. }
  2940. lpfc_els_flush_rscn(vport);
  2941. return 0;
  2942. }
  2943. static int
  2944. lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
  2945. struct lpfc_nodelist *ndlp)
  2946. {
  2947. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2948. struct lpfc_hba *phba = vport->phba;
  2949. struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
  2950. uint32_t *lp = (uint32_t *) pcmd->virt;
  2951. IOCB_t *icmd = &cmdiocb->iocb;
  2952. struct serv_parm *sp;
  2953. LPFC_MBOXQ_t *mbox;
  2954. struct ls_rjt stat;
  2955. uint32_t cmd, did;
  2956. int rc;
  2957. cmd = *lp++;
  2958. sp = (struct serv_parm *) lp;
  2959. /* FLOGI received */
  2960. lpfc_set_disctmo(vport);
  2961. if (phba->fc_topology == TOPOLOGY_LOOP) {
  2962. /* We should never receive a FLOGI in loop mode, ignore it */
  2963. did = icmd->un.elsreq64.remoteID;
  2964. /* An FLOGI ELS command <elsCmd> was received from DID <did> in
  2965. Loop Mode */
  2966. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  2967. "0113 An FLOGI ELS command x%x was "
  2968. "received from DID x%x in Loop Mode\n",
  2969. cmd, did);
  2970. return 1;
  2971. }
  2972. did = Fabric_DID;
  2973. if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3))) {
  2974. /* For a FLOGI we accept, then if our portname is greater
  2975. * then the remote portname we initiate Nport login.
  2976. */
  2977. rc = memcmp(&vport->fc_portname, &sp->portName,
  2978. sizeof(struct lpfc_name));
  2979. if (!rc) {
  2980. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  2981. if (!mbox)
  2982. return 1;
  2983. lpfc_linkdown(phba);
  2984. lpfc_init_link(phba, mbox,
  2985. phba->cfg_topology,
  2986. phba->cfg_link_speed);
  2987. mbox->mb.un.varInitLnk.lipsr_AL_PA = 0;
  2988. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  2989. mbox->vport = vport;
  2990. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
  2991. lpfc_set_loopback_flag(phba);
  2992. if (rc == MBX_NOT_FINISHED) {
  2993. mempool_free(mbox, phba->mbox_mem_pool);
  2994. }
  2995. return 1;
  2996. } else if (rc > 0) { /* greater than */
  2997. spin_lock_irq(shost->host_lock);
  2998. vport->fc_flag |= FC_PT2PT_PLOGI;
  2999. spin_unlock_irq(shost->host_lock);
  3000. }
  3001. spin_lock_irq(shost->host_lock);
  3002. vport->fc_flag |= FC_PT2PT;
  3003. vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
  3004. spin_unlock_irq(shost->host_lock);
  3005. } else {
  3006. /* Reject this request because invalid parameters */
  3007. stat.un.b.lsRjtRsvd0 = 0;
  3008. stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
  3009. stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
  3010. stat.un.b.vendorUnique = 0;
  3011. lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
  3012. NULL);
  3013. return 1;
  3014. }
  3015. /* Send back ACC */
  3016. lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL);
  3017. return 0;
  3018. }
  3019. static int
  3020. lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
  3021. struct lpfc_nodelist *ndlp)
  3022. {
  3023. struct lpfc_dmabuf *pcmd;
  3024. uint32_t *lp;
  3025. IOCB_t *icmd;
  3026. RNID *rn;
  3027. struct ls_rjt stat;
  3028. uint32_t cmd, did;
  3029. icmd = &cmdiocb->iocb;
  3030. did = icmd->un.elsreq64.remoteID;
  3031. pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
  3032. lp = (uint32_t *) pcmd->virt;
  3033. cmd = *lp++;
  3034. rn = (RNID *) lp;
  3035. /* RNID received */
  3036. switch (rn->Format) {
  3037. case 0:
  3038. case RNID_TOPOLOGY_DISC:
  3039. /* Send back ACC */
  3040. lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp);
  3041. break;
  3042. default:
  3043. /* Reject this request because format not supported */
  3044. stat.un.b.lsRjtRsvd0 = 0;
  3045. stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
  3046. stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
  3047. stat.un.b.vendorUnique = 0;
  3048. lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
  3049. NULL);
  3050. }
  3051. return 0;
  3052. }
  3053. static int
  3054. lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
  3055. struct lpfc_nodelist *ndlp)
  3056. {
  3057. struct ls_rjt stat;
  3058. /* For now, unconditionally reject this command */
  3059. stat.un.b.lsRjtRsvd0 = 0;
  3060. stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
  3061. stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
  3062. stat.un.b.vendorUnique = 0;
  3063. lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
  3064. return 0;
  3065. }
  3066. static void
  3067. lpfc_els_rsp_rps_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  3068. {
  3069. struct lpfc_sli *psli = &phba->sli;
  3070. struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
  3071. MAILBOX_t *mb;
  3072. IOCB_t *icmd;
  3073. RPS_RSP *rps_rsp;
  3074. uint8_t *pcmd;
  3075. struct lpfc_iocbq *elsiocb;
  3076. struct lpfc_nodelist *ndlp;
  3077. uint16_t xri, status;
  3078. uint32_t cmdsize;
  3079. mb = &pmb->mb;
  3080. ndlp = (struct lpfc_nodelist *) pmb->context2;
  3081. xri = (uint16_t) ((unsigned long)(pmb->context1));
  3082. pmb->context1 = NULL;
  3083. pmb->context2 = NULL;
  3084. if (mb->mbxStatus) {
  3085. mempool_free(pmb, phba->mbox_mem_pool);
  3086. return;
  3087. }
  3088. cmdsize = sizeof(RPS_RSP) + sizeof(uint32_t);
  3089. mempool_free(pmb, phba->mbox_mem_pool);
  3090. elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
  3091. lpfc_max_els_tries, ndlp,
  3092. ndlp->nlp_DID, ELS_CMD_ACC);
  3093. /* Decrement the ndlp reference count from previous mbox command */
  3094. lpfc_nlp_put(ndlp);
  3095. if (!elsiocb)
  3096. return;
  3097. icmd = &elsiocb->iocb;
  3098. icmd->ulpContext = xri;
  3099. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  3100. *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
  3101. pcmd += sizeof(uint32_t); /* Skip past command */
  3102. rps_rsp = (RPS_RSP *)pcmd;
  3103. if (phba->fc_topology != TOPOLOGY_LOOP)
  3104. status = 0x10;
  3105. else
  3106. status = 0x8;
  3107. if (phba->pport->fc_flag & FC_FABRIC)
  3108. status |= 0x4;
  3109. rps_rsp->rsvd1 = 0;
  3110. rps_rsp->portStatus = cpu_to_be16(status);
  3111. rps_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
  3112. rps_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
  3113. rps_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
  3114. rps_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
  3115. rps_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
  3116. rps_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
  3117. /* Xmit ELS RPS ACC response tag <ulpIoTag> */
  3118. lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
  3119. "0118 Xmit ELS RPS ACC response tag x%x xri x%x, "
  3120. "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
  3121. elsiocb->iotag, elsiocb->iocb.ulpContext,
  3122. ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
  3123. ndlp->nlp_rpi);
  3124. elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
  3125. phba->fc_stat.elsXmitACC++;
  3126. if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR)
  3127. lpfc_els_free_iocb(phba, elsiocb);
  3128. return;
  3129. }
  3130. static int
  3131. lpfc_els_rcv_rps(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
  3132. struct lpfc_nodelist *ndlp)
  3133. {
  3134. struct lpfc_hba *phba = vport->phba;
  3135. uint32_t *lp;
  3136. uint8_t flag;
  3137. LPFC_MBOXQ_t *mbox;
  3138. struct lpfc_dmabuf *pcmd;
  3139. RPS *rps;
  3140. struct ls_rjt stat;
  3141. if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
  3142. (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
  3143. stat.un.b.lsRjtRsvd0 = 0;
  3144. stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
  3145. stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
  3146. stat.un.b.vendorUnique = 0;
  3147. lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
  3148. NULL);
  3149. }
  3150. pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
  3151. lp = (uint32_t *) pcmd->virt;
  3152. flag = (be32_to_cpu(*lp++) & 0xf);
  3153. rps = (RPS *) lp;
  3154. if ((flag == 0) ||
  3155. ((flag == 1) && (be32_to_cpu(rps->un.portNum) == 0)) ||
  3156. ((flag == 2) && (memcmp(&rps->un.portName, &vport->fc_portname,
  3157. sizeof(struct lpfc_name)) == 0))) {
  3158. printk("Fix me....\n");
  3159. dump_stack();
  3160. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
  3161. if (mbox) {
  3162. lpfc_read_lnk_stat(phba, mbox);
  3163. mbox->context1 =
  3164. (void *)((unsigned long) cmdiocb->iocb.ulpContext);
  3165. mbox->context2 = lpfc_nlp_get(ndlp);
  3166. mbox->vport = vport;
  3167. mbox->mbox_cmpl = lpfc_els_rsp_rps_acc;
  3168. if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
  3169. != MBX_NOT_FINISHED)
  3170. /* Mbox completion will send ELS Response */
  3171. return 0;
  3172. /* Decrement reference count used for the failed mbox
  3173. * command.
  3174. */
  3175. lpfc_nlp_put(ndlp);
  3176. mempool_free(mbox, phba->mbox_mem_pool);
  3177. }
  3178. }
  3179. stat.un.b.lsRjtRsvd0 = 0;
  3180. stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
  3181. stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
  3182. stat.un.b.vendorUnique = 0;
  3183. lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
  3184. return 0;
  3185. }
  3186. static int
  3187. lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize,
  3188. struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
  3189. {
  3190. struct lpfc_hba *phba = vport->phba;
  3191. IOCB_t *icmd, *oldcmd;
  3192. RPL_RSP rpl_rsp;
  3193. struct lpfc_iocbq *elsiocb;
  3194. struct lpfc_sli *psli = &phba->sli;
  3195. struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
  3196. uint8_t *pcmd;
  3197. elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
  3198. ndlp->nlp_DID, ELS_CMD_ACC);
  3199. if (!elsiocb)
  3200. return 1;
  3201. icmd = &elsiocb->iocb;
  3202. oldcmd = &oldiocb->iocb;
  3203. icmd->ulpContext = oldcmd->ulpContext; /* Xri */
  3204. pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  3205. *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
  3206. pcmd += sizeof(uint16_t);
  3207. *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize);
  3208. pcmd += sizeof(uint16_t);
  3209. /* Setup the RPL ACC payload */
  3210. rpl_rsp.listLen = be32_to_cpu(1);
  3211. rpl_rsp.index = 0;
  3212. rpl_rsp.port_num_blk.portNum = 0;
  3213. rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID);
  3214. memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname,
  3215. sizeof(struct lpfc_name));
  3216. memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t));
  3217. /* Xmit ELS RPL ACC response tag <ulpIoTag> */
  3218. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  3219. "0120 Xmit ELS RPL ACC response tag x%x "
  3220. "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
  3221. "rpi x%x\n",
  3222. elsiocb->iotag, elsiocb->iocb.ulpContext,
  3223. ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
  3224. ndlp->nlp_rpi);
  3225. elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
  3226. phba->fc_stat.elsXmitACC++;
  3227. if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
  3228. lpfc_els_free_iocb(phba, elsiocb);
  3229. return 1;
  3230. }
  3231. return 0;
  3232. }
  3233. static int
  3234. lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
  3235. struct lpfc_nodelist *ndlp)
  3236. {
  3237. struct lpfc_dmabuf *pcmd;
  3238. uint32_t *lp;
  3239. uint32_t maxsize;
  3240. uint16_t cmdsize;
  3241. RPL *rpl;
  3242. struct ls_rjt stat;
  3243. if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
  3244. (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
  3245. stat.un.b.lsRjtRsvd0 = 0;
  3246. stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
  3247. stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
  3248. stat.un.b.vendorUnique = 0;
  3249. lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
  3250. NULL);
  3251. }
  3252. pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
  3253. lp = (uint32_t *) pcmd->virt;
  3254. rpl = (RPL *) (lp + 1);
  3255. maxsize = be32_to_cpu(rpl->maxsize);
  3256. /* We support only one port */
  3257. if ((rpl->index == 0) &&
  3258. ((maxsize == 0) ||
  3259. ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) {
  3260. cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP);
  3261. } else {
  3262. cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t);
  3263. }
  3264. lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp);
  3265. return 0;
  3266. }
  3267. static int
  3268. lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
  3269. struct lpfc_nodelist *ndlp)
  3270. {
  3271. struct lpfc_dmabuf *pcmd;
  3272. uint32_t *lp;
  3273. IOCB_t *icmd;
  3274. FARP *fp;
  3275. uint32_t cmd, cnt, did;
  3276. icmd = &cmdiocb->iocb;
  3277. did = icmd->un.elsreq64.remoteID;
  3278. pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
  3279. lp = (uint32_t *) pcmd->virt;
  3280. cmd = *lp++;
  3281. fp = (FARP *) lp;
  3282. /* FARP-REQ received from DID <did> */
  3283. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  3284. "0601 FARP-REQ received from DID x%x\n", did);
  3285. /* We will only support match on WWPN or WWNN */
  3286. if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) {
  3287. return 0;
  3288. }
  3289. cnt = 0;
  3290. /* If this FARP command is searching for my portname */
  3291. if (fp->Mflags & FARP_MATCH_PORT) {
  3292. if (memcmp(&fp->RportName, &vport->fc_portname,
  3293. sizeof(struct lpfc_name)) == 0)
  3294. cnt = 1;
  3295. }
  3296. /* If this FARP command is searching for my nodename */
  3297. if (fp->Mflags & FARP_MATCH_NODE) {
  3298. if (memcmp(&fp->RnodeName, &vport->fc_nodename,
  3299. sizeof(struct lpfc_name)) == 0)
  3300. cnt = 1;
  3301. }
  3302. if (cnt) {
  3303. if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
  3304. (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) {
  3305. /* Log back into the node before sending the FARP. */
  3306. if (fp->Rflags & FARP_REQUEST_PLOGI) {
  3307. ndlp->nlp_prev_state = ndlp->nlp_state;
  3308. lpfc_nlp_set_state(vport, ndlp,
  3309. NLP_STE_PLOGI_ISSUE);
  3310. lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
  3311. }
  3312. /* Send a FARP response to that node */
  3313. if (fp->Rflags & FARP_REQUEST_FARPR)
  3314. lpfc_issue_els_farpr(vport, did, 0);
  3315. }
  3316. }
  3317. return 0;
  3318. }
  3319. static int
  3320. lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
  3321. struct lpfc_nodelist *ndlp)
  3322. {
  3323. struct lpfc_dmabuf *pcmd;
  3324. uint32_t *lp;
  3325. IOCB_t *icmd;
  3326. uint32_t cmd, did;
  3327. icmd = &cmdiocb->iocb;
  3328. did = icmd->un.elsreq64.remoteID;
  3329. pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
  3330. lp = (uint32_t *) pcmd->virt;
  3331. cmd = *lp++;
  3332. /* FARP-RSP received from DID <did> */
  3333. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  3334. "0600 FARP-RSP received from DID x%x\n", did);
  3335. /* ACCEPT the Farp resp request */
  3336. lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
  3337. return 0;
  3338. }
  3339. static int
  3340. lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
  3341. struct lpfc_nodelist *fan_ndlp)
  3342. {
  3343. struct lpfc_hba *phba = vport->phba;
  3344. uint32_t *lp;
  3345. FAN *fp;
  3346. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, "0265 FAN received\n");
  3347. lp = (uint32_t *)((struct lpfc_dmabuf *)cmdiocb->context2)->virt;
  3348. fp = (FAN *) ++lp;
  3349. /* FAN received; Fan does not have a reply sequence */
  3350. if ((vport == phba->pport) &&
  3351. (vport->port_state == LPFC_LOCAL_CFG_LINK)) {
  3352. if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName,
  3353. sizeof(struct lpfc_name))) ||
  3354. (memcmp(&phba->fc_fabparam.portName, &fp->FportName,
  3355. sizeof(struct lpfc_name)))) {
  3356. /* This port has switched fabrics. FLOGI is required */
  3357. lpfc_initial_flogi(vport);
  3358. } else {
  3359. /* FAN verified - skip FLOGI */
  3360. vport->fc_myDID = vport->fc_prevDID;
  3361. lpfc_issue_fabric_reglogin(vport);
  3362. }
  3363. }
  3364. return 0;
  3365. }
  3366. void
  3367. lpfc_els_timeout(unsigned long ptr)
  3368. {
  3369. struct lpfc_vport *vport = (struct lpfc_vport *) ptr;
  3370. struct lpfc_hba *phba = vport->phba;
  3371. uint32_t tmo_posted;
  3372. unsigned long iflag;
  3373. spin_lock_irqsave(&vport->work_port_lock, iflag);
  3374. tmo_posted = vport->work_port_events & WORKER_ELS_TMO;
  3375. if (!tmo_posted)
  3376. vport->work_port_events |= WORKER_ELS_TMO;
  3377. spin_unlock_irqrestore(&vport->work_port_lock, iflag);
  3378. if (!tmo_posted)
  3379. lpfc_worker_wake_up(phba);
  3380. return;
  3381. }
  3382. void
  3383. lpfc_els_timeout_handler(struct lpfc_vport *vport)
  3384. {
  3385. struct lpfc_hba *phba = vport->phba;
  3386. struct lpfc_sli_ring *pring;
  3387. struct lpfc_iocbq *tmp_iocb, *piocb;
  3388. IOCB_t *cmd = NULL;
  3389. struct lpfc_dmabuf *pcmd;
  3390. uint32_t els_command = 0;
  3391. uint32_t timeout;
  3392. uint32_t remote_ID = 0xffffffff;
  3393. /* If the timer is already canceled do nothing */
  3394. if ((vport->work_port_events & WORKER_ELS_TMO) == 0) {
  3395. return;
  3396. }
  3397. spin_lock_irq(&phba->hbalock);
  3398. timeout = (uint32_t)(phba->fc_ratov << 1);
  3399. pring = &phba->sli.ring[LPFC_ELS_RING];
  3400. list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
  3401. cmd = &piocb->iocb;
  3402. if ((piocb->iocb_flag & LPFC_IO_LIBDFC) != 0 ||
  3403. piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
  3404. piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
  3405. continue;
  3406. if (piocb->vport != vport)
  3407. continue;
  3408. pcmd = (struct lpfc_dmabuf *) piocb->context2;
  3409. if (pcmd)
  3410. els_command = *(uint32_t *) (pcmd->virt);
  3411. if (els_command == ELS_CMD_FARP ||
  3412. els_command == ELS_CMD_FARPR ||
  3413. els_command == ELS_CMD_FDISC)
  3414. continue;
  3415. if (piocb->drvrTimeout > 0) {
  3416. if (piocb->drvrTimeout >= timeout)
  3417. piocb->drvrTimeout -= timeout;
  3418. else
  3419. piocb->drvrTimeout = 0;
  3420. continue;
  3421. }
  3422. remote_ID = 0xffffffff;
  3423. if (cmd->ulpCommand != CMD_GEN_REQUEST64_CR)
  3424. remote_ID = cmd->un.elsreq64.remoteID;
  3425. else {
  3426. struct lpfc_nodelist *ndlp;
  3427. ndlp = __lpfc_findnode_rpi(vport, cmd->ulpContext);
  3428. if (ndlp && NLP_CHK_NODE_ACT(ndlp))
  3429. remote_ID = ndlp->nlp_DID;
  3430. }
  3431. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  3432. "0127 ELS timeout Data: x%x x%x x%x "
  3433. "x%x\n", els_command,
  3434. remote_ID, cmd->ulpCommand, cmd->ulpIoTag);
  3435. lpfc_sli_issue_abort_iotag(phba, pring, piocb);
  3436. }
  3437. spin_unlock_irq(&phba->hbalock);
  3438. if (phba->sli.ring[LPFC_ELS_RING].txcmplq_cnt)
  3439. mod_timer(&vport->els_tmofunc, jiffies + HZ * timeout);
  3440. }
  3441. void
  3442. lpfc_els_flush_cmd(struct lpfc_vport *vport)
  3443. {
  3444. LIST_HEAD(completions);
  3445. struct lpfc_hba *phba = vport->phba;
  3446. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  3447. struct lpfc_iocbq *tmp_iocb, *piocb;
  3448. IOCB_t *cmd = NULL;
  3449. lpfc_fabric_abort_vport(vport);
  3450. spin_lock_irq(&phba->hbalock);
  3451. list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
  3452. cmd = &piocb->iocb;
  3453. if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
  3454. continue;
  3455. }
  3456. /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
  3457. if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
  3458. cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
  3459. cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
  3460. cmd->ulpCommand == CMD_ABORT_XRI_CN)
  3461. continue;
  3462. if (piocb->vport != vport)
  3463. continue;
  3464. list_move_tail(&piocb->list, &completions);
  3465. pring->txq_cnt--;
  3466. }
  3467. list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
  3468. if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
  3469. continue;
  3470. }
  3471. if (piocb->vport != vport)
  3472. continue;
  3473. lpfc_sli_issue_abort_iotag(phba, pring, piocb);
  3474. }
  3475. spin_unlock_irq(&phba->hbalock);
  3476. while (!list_empty(&completions)) {
  3477. piocb = list_get_first(&completions, struct lpfc_iocbq, list);
  3478. cmd = &piocb->iocb;
  3479. list_del_init(&piocb->list);
  3480. if (!piocb->iocb_cmpl)
  3481. lpfc_sli_release_iocbq(phba, piocb);
  3482. else {
  3483. cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
  3484. cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
  3485. (piocb->iocb_cmpl) (phba, piocb, piocb);
  3486. }
  3487. }
  3488. return;
  3489. }
  3490. void
  3491. lpfc_els_flush_all_cmd(struct lpfc_hba *phba)
  3492. {
  3493. LIST_HEAD(completions);
  3494. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  3495. struct lpfc_iocbq *tmp_iocb, *piocb;
  3496. IOCB_t *cmd = NULL;
  3497. lpfc_fabric_abort_hba(phba);
  3498. spin_lock_irq(&phba->hbalock);
  3499. list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
  3500. cmd = &piocb->iocb;
  3501. if (piocb->iocb_flag & LPFC_IO_LIBDFC)
  3502. continue;
  3503. /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
  3504. if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
  3505. cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
  3506. cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
  3507. cmd->ulpCommand == CMD_ABORT_XRI_CN)
  3508. continue;
  3509. list_move_tail(&piocb->list, &completions);
  3510. pring->txq_cnt--;
  3511. }
  3512. list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
  3513. if (piocb->iocb_flag & LPFC_IO_LIBDFC)
  3514. continue;
  3515. lpfc_sli_issue_abort_iotag(phba, pring, piocb);
  3516. }
  3517. spin_unlock_irq(&phba->hbalock);
  3518. while (!list_empty(&completions)) {
  3519. piocb = list_get_first(&completions, struct lpfc_iocbq, list);
  3520. cmd = &piocb->iocb;
  3521. list_del_init(&piocb->list);
  3522. if (!piocb->iocb_cmpl)
  3523. lpfc_sli_release_iocbq(phba, piocb);
  3524. else {
  3525. cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
  3526. cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
  3527. (piocb->iocb_cmpl) (phba, piocb, piocb);
  3528. }
  3529. }
  3530. return;
  3531. }
  3532. static void
  3533. lpfc_els_unsol_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  3534. struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb)
  3535. {
  3536. struct Scsi_Host *shost;
  3537. struct lpfc_nodelist *ndlp;
  3538. struct ls_rjt stat;
  3539. uint32_t *payload;
  3540. uint32_t cmd, did, newnode, rjt_err = 0;
  3541. IOCB_t *icmd = &elsiocb->iocb;
  3542. if (!vport || !(elsiocb->context2))
  3543. goto dropit;
  3544. newnode = 0;
  3545. payload = ((struct lpfc_dmabuf *)elsiocb->context2)->virt;
  3546. cmd = *payload;
  3547. if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0)
  3548. lpfc_post_buffer(phba, pring, 1);
  3549. did = icmd->un.rcvels.remoteID;
  3550. if (icmd->ulpStatus) {
  3551. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  3552. "RCV Unsol ELS: status:x%x/x%x did:x%x",
  3553. icmd->ulpStatus, icmd->un.ulpWord[4], did);
  3554. goto dropit;
  3555. }
  3556. /* Check to see if link went down during discovery */
  3557. if (lpfc_els_chk_latt(vport))
  3558. goto dropit;
  3559. /* Ignore traffic recevied during vport shutdown. */
  3560. if (vport->load_flag & FC_UNLOADING)
  3561. goto dropit;
  3562. ndlp = lpfc_findnode_did(vport, did);
  3563. if (!ndlp) {
  3564. /* Cannot find existing Fabric ndlp, so allocate a new one */
  3565. ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
  3566. if (!ndlp)
  3567. goto dropit;
  3568. lpfc_nlp_init(vport, ndlp, did);
  3569. lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
  3570. newnode = 1;
  3571. if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
  3572. ndlp->nlp_type |= NLP_FABRIC;
  3573. } else if (!NLP_CHK_NODE_ACT(ndlp)) {
  3574. ndlp = lpfc_enable_node(vport, ndlp,
  3575. NLP_STE_UNUSED_NODE);
  3576. if (!ndlp)
  3577. goto dropit;
  3578. lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
  3579. newnode = 1;
  3580. if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
  3581. ndlp->nlp_type |= NLP_FABRIC;
  3582. } else if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
  3583. /* This is similar to the new node path */
  3584. ndlp = lpfc_nlp_get(ndlp);
  3585. if (!ndlp)
  3586. goto dropit;
  3587. lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
  3588. newnode = 1;
  3589. }
  3590. phba->fc_stat.elsRcvFrame++;
  3591. if (elsiocb->context1)
  3592. lpfc_nlp_put(elsiocb->context1);
  3593. elsiocb->context1 = lpfc_nlp_get(ndlp);
  3594. elsiocb->vport = vport;
  3595. if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) {
  3596. cmd &= ELS_CMD_MASK;
  3597. }
  3598. /* ELS command <elsCmd> received from NPORT <did> */
  3599. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  3600. "0112 ELS command x%x received from NPORT x%x "
  3601. "Data: x%x\n", cmd, did, vport->port_state);
  3602. switch (cmd) {
  3603. case ELS_CMD_PLOGI:
  3604. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  3605. "RCV PLOGI: did:x%x/ste:x%x flg:x%x",
  3606. did, vport->port_state, ndlp->nlp_flag);
  3607. phba->fc_stat.elsRcvPLOGI++;
  3608. ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp);
  3609. if (vport->port_state < LPFC_DISC_AUTH) {
  3610. if (!(phba->pport->fc_flag & FC_PT2PT) ||
  3611. (phba->pport->fc_flag & FC_PT2PT_PLOGI)) {
  3612. rjt_err = LSRJT_UNABLE_TPC;
  3613. break;
  3614. }
  3615. /* We get here, and drop thru, if we are PT2PT with
  3616. * another NPort and the other side has initiated
  3617. * the PLOGI before responding to our FLOGI.
  3618. */
  3619. }
  3620. shost = lpfc_shost_from_vport(vport);
  3621. spin_lock_irq(shost->host_lock);
  3622. ndlp->nlp_flag &= ~NLP_TARGET_REMOVE;
  3623. spin_unlock_irq(shost->host_lock);
  3624. lpfc_disc_state_machine(vport, ndlp, elsiocb,
  3625. NLP_EVT_RCV_PLOGI);
  3626. break;
  3627. case ELS_CMD_FLOGI:
  3628. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  3629. "RCV FLOGI: did:x%x/ste:x%x flg:x%x",
  3630. did, vport->port_state, ndlp->nlp_flag);
  3631. phba->fc_stat.elsRcvFLOGI++;
  3632. lpfc_els_rcv_flogi(vport, elsiocb, ndlp);
  3633. if (newnode)
  3634. lpfc_nlp_put(ndlp);
  3635. break;
  3636. case ELS_CMD_LOGO:
  3637. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  3638. "RCV LOGO: did:x%x/ste:x%x flg:x%x",
  3639. did, vport->port_state, ndlp->nlp_flag);
  3640. phba->fc_stat.elsRcvLOGO++;
  3641. if (vport->port_state < LPFC_DISC_AUTH) {
  3642. rjt_err = LSRJT_UNABLE_TPC;
  3643. break;
  3644. }
  3645. lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO);
  3646. break;
  3647. case ELS_CMD_PRLO:
  3648. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  3649. "RCV PRLO: did:x%x/ste:x%x flg:x%x",
  3650. did, vport->port_state, ndlp->nlp_flag);
  3651. phba->fc_stat.elsRcvPRLO++;
  3652. if (vport->port_state < LPFC_DISC_AUTH) {
  3653. rjt_err = LSRJT_UNABLE_TPC;
  3654. break;
  3655. }
  3656. lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO);
  3657. break;
  3658. case ELS_CMD_RSCN:
  3659. phba->fc_stat.elsRcvRSCN++;
  3660. lpfc_els_rcv_rscn(vport, elsiocb, ndlp);
  3661. if (newnode)
  3662. lpfc_nlp_put(ndlp);
  3663. break;
  3664. case ELS_CMD_ADISC:
  3665. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  3666. "RCV ADISC: did:x%x/ste:x%x flg:x%x",
  3667. did, vport->port_state, ndlp->nlp_flag);
  3668. phba->fc_stat.elsRcvADISC++;
  3669. if (vport->port_state < LPFC_DISC_AUTH) {
  3670. rjt_err = LSRJT_UNABLE_TPC;
  3671. break;
  3672. }
  3673. lpfc_disc_state_machine(vport, ndlp, elsiocb,
  3674. NLP_EVT_RCV_ADISC);
  3675. break;
  3676. case ELS_CMD_PDISC:
  3677. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  3678. "RCV PDISC: did:x%x/ste:x%x flg:x%x",
  3679. did, vport->port_state, ndlp->nlp_flag);
  3680. phba->fc_stat.elsRcvPDISC++;
  3681. if (vport->port_state < LPFC_DISC_AUTH) {
  3682. rjt_err = LSRJT_UNABLE_TPC;
  3683. break;
  3684. }
  3685. lpfc_disc_state_machine(vport, ndlp, elsiocb,
  3686. NLP_EVT_RCV_PDISC);
  3687. break;
  3688. case ELS_CMD_FARPR:
  3689. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  3690. "RCV FARPR: did:x%x/ste:x%x flg:x%x",
  3691. did, vport->port_state, ndlp->nlp_flag);
  3692. phba->fc_stat.elsRcvFARPR++;
  3693. lpfc_els_rcv_farpr(vport, elsiocb, ndlp);
  3694. break;
  3695. case ELS_CMD_FARP:
  3696. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  3697. "RCV FARP: did:x%x/ste:x%x flg:x%x",
  3698. did, vport->port_state, ndlp->nlp_flag);
  3699. phba->fc_stat.elsRcvFARP++;
  3700. lpfc_els_rcv_farp(vport, elsiocb, ndlp);
  3701. break;
  3702. case ELS_CMD_FAN:
  3703. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  3704. "RCV FAN: did:x%x/ste:x%x flg:x%x",
  3705. did, vport->port_state, ndlp->nlp_flag);
  3706. phba->fc_stat.elsRcvFAN++;
  3707. lpfc_els_rcv_fan(vport, elsiocb, ndlp);
  3708. break;
  3709. case ELS_CMD_PRLI:
  3710. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  3711. "RCV PRLI: did:x%x/ste:x%x flg:x%x",
  3712. did, vport->port_state, ndlp->nlp_flag);
  3713. phba->fc_stat.elsRcvPRLI++;
  3714. if (vport->port_state < LPFC_DISC_AUTH) {
  3715. rjt_err = LSRJT_UNABLE_TPC;
  3716. break;
  3717. }
  3718. lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI);
  3719. break;
  3720. case ELS_CMD_LIRR:
  3721. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  3722. "RCV LIRR: did:x%x/ste:x%x flg:x%x",
  3723. did, vport->port_state, ndlp->nlp_flag);
  3724. phba->fc_stat.elsRcvLIRR++;
  3725. lpfc_els_rcv_lirr(vport, elsiocb, ndlp);
  3726. if (newnode)
  3727. lpfc_nlp_put(ndlp);
  3728. break;
  3729. case ELS_CMD_RPS:
  3730. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  3731. "RCV RPS: did:x%x/ste:x%x flg:x%x",
  3732. did, vport->port_state, ndlp->nlp_flag);
  3733. phba->fc_stat.elsRcvRPS++;
  3734. lpfc_els_rcv_rps(vport, elsiocb, ndlp);
  3735. if (newnode)
  3736. lpfc_nlp_put(ndlp);
  3737. break;
  3738. case ELS_CMD_RPL:
  3739. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  3740. "RCV RPL: did:x%x/ste:x%x flg:x%x",
  3741. did, vport->port_state, ndlp->nlp_flag);
  3742. phba->fc_stat.elsRcvRPL++;
  3743. lpfc_els_rcv_rpl(vport, elsiocb, ndlp);
  3744. if (newnode)
  3745. lpfc_nlp_put(ndlp);
  3746. break;
  3747. case ELS_CMD_RNID:
  3748. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  3749. "RCV RNID: did:x%x/ste:x%x flg:x%x",
  3750. did, vport->port_state, ndlp->nlp_flag);
  3751. phba->fc_stat.elsRcvRNID++;
  3752. lpfc_els_rcv_rnid(vport, elsiocb, ndlp);
  3753. if (newnode)
  3754. lpfc_nlp_put(ndlp);
  3755. break;
  3756. default:
  3757. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  3758. "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x",
  3759. cmd, did, vport->port_state);
  3760. /* Unsupported ELS command, reject */
  3761. rjt_err = LSRJT_INVALID_CMD;
  3762. /* Unknown ELS command <elsCmd> received from NPORT <did> */
  3763. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  3764. "0115 Unknown ELS command x%x "
  3765. "received from NPORT x%x\n", cmd, did);
  3766. if (newnode)
  3767. lpfc_nlp_put(ndlp);
  3768. break;
  3769. }
  3770. /* check if need to LS_RJT received ELS cmd */
  3771. if (rjt_err) {
  3772. memset(&stat, 0, sizeof(stat));
  3773. stat.un.b.lsRjtRsnCode = rjt_err;
  3774. stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
  3775. lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp,
  3776. NULL);
  3777. }
  3778. return;
  3779. dropit:
  3780. if (vport && !(vport->load_flag & FC_UNLOADING))
  3781. lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
  3782. "(%d):0111 Dropping received ELS cmd "
  3783. "Data: x%x x%x x%x\n",
  3784. vport->vpi, icmd->ulpStatus,
  3785. icmd->un.ulpWord[4], icmd->ulpTimeout);
  3786. phba->fc_stat.elsRcvDrop++;
  3787. }
  3788. static struct lpfc_vport *
  3789. lpfc_find_vport_by_vpid(struct lpfc_hba *phba, uint16_t vpi)
  3790. {
  3791. struct lpfc_vport *vport;
  3792. unsigned long flags;
  3793. spin_lock_irqsave(&phba->hbalock, flags);
  3794. list_for_each_entry(vport, &phba->port_list, listentry) {
  3795. if (vport->vpi == vpi) {
  3796. spin_unlock_irqrestore(&phba->hbalock, flags);
  3797. return vport;
  3798. }
  3799. }
  3800. spin_unlock_irqrestore(&phba->hbalock, flags);
  3801. return NULL;
  3802. }
  3803. void
  3804. lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  3805. struct lpfc_iocbq *elsiocb)
  3806. {
  3807. struct lpfc_vport *vport = phba->pport;
  3808. IOCB_t *icmd = &elsiocb->iocb;
  3809. dma_addr_t paddr;
  3810. struct lpfc_dmabuf *bdeBuf1 = elsiocb->context2;
  3811. struct lpfc_dmabuf *bdeBuf2 = elsiocb->context3;
  3812. elsiocb->context2 = NULL;
  3813. elsiocb->context3 = NULL;
  3814. if (icmd->ulpStatus == IOSTAT_NEED_BUFFER) {
  3815. lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
  3816. } else if (icmd->ulpStatus == IOSTAT_LOCAL_REJECT &&
  3817. (icmd->un.ulpWord[4] & 0xff) == IOERR_RCV_BUFFER_WAITING) {
  3818. phba->fc_stat.NoRcvBuf++;
  3819. /* Not enough posted buffers; Try posting more buffers */
  3820. if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
  3821. lpfc_post_buffer(phba, pring, 0);
  3822. return;
  3823. }
  3824. if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
  3825. (icmd->ulpCommand == CMD_IOCB_RCV_ELS64_CX ||
  3826. icmd->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
  3827. if (icmd->unsli3.rcvsli3.vpi == 0xffff)
  3828. vport = phba->pport;
  3829. else {
  3830. uint16_t vpi = icmd->unsli3.rcvsli3.vpi;
  3831. vport = lpfc_find_vport_by_vpid(phba, vpi);
  3832. }
  3833. }
  3834. /* If there are no BDEs associated
  3835. * with this IOCB, there is nothing to do.
  3836. */
  3837. if (icmd->ulpBdeCount == 0)
  3838. return;
  3839. /* type of ELS cmd is first 32bit word
  3840. * in packet
  3841. */
  3842. if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
  3843. elsiocb->context2 = bdeBuf1;
  3844. } else {
  3845. paddr = getPaddr(icmd->un.cont64[0].addrHigh,
  3846. icmd->un.cont64[0].addrLow);
  3847. elsiocb->context2 = lpfc_sli_ringpostbuf_get(phba, pring,
  3848. paddr);
  3849. }
  3850. lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
  3851. /*
  3852. * The different unsolicited event handlers would tell us
  3853. * if they are done with "mp" by setting context2 to NULL.
  3854. */
  3855. lpfc_nlp_put(elsiocb->context1);
  3856. elsiocb->context1 = NULL;
  3857. if (elsiocb->context2) {
  3858. lpfc_in_buf_free(phba, (struct lpfc_dmabuf *)elsiocb->context2);
  3859. elsiocb->context2 = NULL;
  3860. }
  3861. /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */
  3862. if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) &&
  3863. icmd->ulpBdeCount == 2) {
  3864. elsiocb->context2 = bdeBuf2;
  3865. lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
  3866. /* free mp if we are done with it */
  3867. if (elsiocb->context2) {
  3868. lpfc_in_buf_free(phba, elsiocb->context2);
  3869. elsiocb->context2 = NULL;
  3870. }
  3871. }
  3872. }
  3873. void
  3874. lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport)
  3875. {
  3876. struct lpfc_nodelist *ndlp, *ndlp_fdmi;
  3877. ndlp = lpfc_findnode_did(vport, NameServer_DID);
  3878. if (!ndlp) {
  3879. ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
  3880. if (!ndlp) {
  3881. if (phba->fc_topology == TOPOLOGY_LOOP) {
  3882. lpfc_disc_start(vport);
  3883. return;
  3884. }
  3885. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  3886. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  3887. "0251 NameServer login: no memory\n");
  3888. return;
  3889. }
  3890. lpfc_nlp_init(vport, ndlp, NameServer_DID);
  3891. } else if (!NLP_CHK_NODE_ACT(ndlp)) {
  3892. ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
  3893. if (!ndlp) {
  3894. if (phba->fc_topology == TOPOLOGY_LOOP) {
  3895. lpfc_disc_start(vport);
  3896. return;
  3897. }
  3898. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  3899. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  3900. "0348 NameServer login: node freed\n");
  3901. return;
  3902. }
  3903. }
  3904. ndlp->nlp_type |= NLP_FABRIC;
  3905. lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
  3906. if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) {
  3907. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  3908. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  3909. "0252 Cannot issue NameServer login\n");
  3910. return;
  3911. }
  3912. if (vport->cfg_fdmi_on) {
  3913. ndlp_fdmi = mempool_alloc(phba->nlp_mem_pool,
  3914. GFP_KERNEL);
  3915. if (ndlp_fdmi) {
  3916. lpfc_nlp_init(vport, ndlp_fdmi, FDMI_DID);
  3917. ndlp_fdmi->nlp_type |= NLP_FABRIC;
  3918. lpfc_nlp_set_state(vport, ndlp_fdmi,
  3919. NLP_STE_PLOGI_ISSUE);
  3920. lpfc_issue_els_plogi(vport, ndlp_fdmi->nlp_DID,
  3921. 0);
  3922. }
  3923. }
  3924. return;
  3925. }
  3926. static void
  3927. lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  3928. {
  3929. struct lpfc_vport *vport = pmb->vport;
  3930. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  3931. struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
  3932. MAILBOX_t *mb = &pmb->mb;
  3933. spin_lock_irq(shost->host_lock);
  3934. vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
  3935. spin_unlock_irq(shost->host_lock);
  3936. if (mb->mbxStatus) {
  3937. lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
  3938. "0915 Register VPI failed: 0x%x\n",
  3939. mb->mbxStatus);
  3940. switch (mb->mbxStatus) {
  3941. case 0x11: /* unsupported feature */
  3942. case 0x9603: /* max_vpi exceeded */
  3943. case 0x9602: /* Link event since CLEAR_LA */
  3944. /* giving up on vport registration */
  3945. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  3946. spin_lock_irq(shost->host_lock);
  3947. vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
  3948. spin_unlock_irq(shost->host_lock);
  3949. lpfc_can_disctmo(vport);
  3950. break;
  3951. default:
  3952. /* Try to recover from this error */
  3953. lpfc_mbx_unreg_vpi(vport);
  3954. spin_lock_irq(shost->host_lock);
  3955. vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
  3956. spin_unlock_irq(shost->host_lock);
  3957. if (vport->port_type == LPFC_PHYSICAL_PORT)
  3958. lpfc_initial_flogi(vport);
  3959. else
  3960. lpfc_initial_fdisc(vport);
  3961. break;
  3962. }
  3963. } else {
  3964. if (vport == phba->pport)
  3965. lpfc_issue_fabric_reglogin(vport);
  3966. else
  3967. lpfc_do_scr_ns_plogi(phba, vport);
  3968. }
  3969. /* Now, we decrement the ndlp reference count held for this
  3970. * callback function
  3971. */
  3972. lpfc_nlp_put(ndlp);
  3973. mempool_free(pmb, phba->mbox_mem_pool);
  3974. return;
  3975. }
  3976. static void
  3977. lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport,
  3978. struct lpfc_nodelist *ndlp)
  3979. {
  3980. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  3981. LPFC_MBOXQ_t *mbox;
  3982. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3983. if (mbox) {
  3984. lpfc_reg_vpi(phba, vport->vpi, vport->fc_myDID, mbox);
  3985. mbox->vport = vport;
  3986. mbox->context2 = lpfc_nlp_get(ndlp);
  3987. mbox->mbox_cmpl = lpfc_cmpl_reg_new_vport;
  3988. if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
  3989. == MBX_NOT_FINISHED) {
  3990. /* mailbox command not success, decrement ndlp
  3991. * reference count for this command
  3992. */
  3993. lpfc_nlp_put(ndlp);
  3994. mempool_free(mbox, phba->mbox_mem_pool);
  3995. lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
  3996. "0253 Register VPI: Can't send mbox\n");
  3997. goto mbox_err_exit;
  3998. }
  3999. } else {
  4000. lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
  4001. "0254 Register VPI: no memory\n");
  4002. goto mbox_err_exit;
  4003. }
  4004. return;
  4005. mbox_err_exit:
  4006. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  4007. spin_lock_irq(shost->host_lock);
  4008. vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
  4009. spin_unlock_irq(shost->host_lock);
  4010. return;
  4011. }
  4012. static void
  4013. lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  4014. struct lpfc_iocbq *rspiocb)
  4015. {
  4016. struct lpfc_vport *vport = cmdiocb->vport;
  4017. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  4018. struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
  4019. struct lpfc_nodelist *np;
  4020. struct lpfc_nodelist *next_np;
  4021. IOCB_t *irsp = &rspiocb->iocb;
  4022. struct lpfc_iocbq *piocb;
  4023. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  4024. "0123 FDISC completes. x%x/x%x prevDID: x%x\n",
  4025. irsp->ulpStatus, irsp->un.ulpWord[4],
  4026. vport->fc_prevDID);
  4027. /* Since all FDISCs are being single threaded, we
  4028. * must reset the discovery timer for ALL vports
  4029. * waiting to send FDISC when one completes.
  4030. */
  4031. list_for_each_entry(piocb, &phba->fabric_iocb_list, list) {
  4032. lpfc_set_disctmo(piocb->vport);
  4033. }
  4034. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  4035. "FDISC cmpl: status:x%x/x%x prevdid:x%x",
  4036. irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_prevDID);
  4037. if (irsp->ulpStatus) {
  4038. /* Check for retry */
  4039. if (lpfc_els_retry(phba, cmdiocb, rspiocb))
  4040. goto out;
  4041. /* FDISC failed */
  4042. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  4043. "0124 FDISC failed. (%d/%d)\n",
  4044. irsp->ulpStatus, irsp->un.ulpWord[4]);
  4045. if (vport->fc_vport->vport_state == FC_VPORT_INITIALIZING)
  4046. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  4047. lpfc_nlp_put(ndlp);
  4048. /* giving up on FDISC. Cancel discovery timer */
  4049. lpfc_can_disctmo(vport);
  4050. } else {
  4051. spin_lock_irq(shost->host_lock);
  4052. vport->fc_flag |= FC_FABRIC;
  4053. if (vport->phba->fc_topology == TOPOLOGY_LOOP)
  4054. vport->fc_flag |= FC_PUBLIC_LOOP;
  4055. spin_unlock_irq(shost->host_lock);
  4056. vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
  4057. lpfc_vport_set_state(vport, FC_VPORT_ACTIVE);
  4058. if ((vport->fc_prevDID != vport->fc_myDID) &&
  4059. !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
  4060. /* If our NportID changed, we need to ensure all
  4061. * remaining NPORTs get unreg_login'ed so we can
  4062. * issue unreg_vpi.
  4063. */
  4064. list_for_each_entry_safe(np, next_np,
  4065. &vport->fc_nodes, nlp_listp) {
  4066. if (!NLP_CHK_NODE_ACT(ndlp) ||
  4067. (np->nlp_state != NLP_STE_NPR_NODE) ||
  4068. !(np->nlp_flag & NLP_NPR_ADISC))
  4069. continue;
  4070. spin_lock_irq(shost->host_lock);
  4071. np->nlp_flag &= ~NLP_NPR_ADISC;
  4072. spin_unlock_irq(shost->host_lock);
  4073. lpfc_unreg_rpi(vport, np);
  4074. }
  4075. lpfc_mbx_unreg_vpi(vport);
  4076. spin_lock_irq(shost->host_lock);
  4077. vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
  4078. spin_unlock_irq(shost->host_lock);
  4079. }
  4080. if (vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
  4081. lpfc_register_new_vport(phba, vport, ndlp);
  4082. else
  4083. lpfc_do_scr_ns_plogi(phba, vport);
  4084. /* Unconditionaly kick off releasing fabric node for vports */
  4085. lpfc_nlp_put(ndlp);
  4086. }
  4087. out:
  4088. lpfc_els_free_iocb(phba, cmdiocb);
  4089. }
  4090. static int
  4091. lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  4092. uint8_t retry)
  4093. {
  4094. struct lpfc_hba *phba = vport->phba;
  4095. IOCB_t *icmd;
  4096. struct lpfc_iocbq *elsiocb;
  4097. struct serv_parm *sp;
  4098. uint8_t *pcmd;
  4099. uint16_t cmdsize;
  4100. int did = ndlp->nlp_DID;
  4101. int rc;
  4102. cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
  4103. elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
  4104. ELS_CMD_FDISC);
  4105. if (!elsiocb) {
  4106. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  4107. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  4108. "0255 Issue FDISC: no IOCB\n");
  4109. return 1;
  4110. }
  4111. icmd = &elsiocb->iocb;
  4112. icmd->un.elsreq64.myID = 0;
  4113. icmd->un.elsreq64.fl = 1;
  4114. /* For FDISC, Let FDISC rsp set the NPortID for this VPI */
  4115. icmd->ulpCt_h = 1;
  4116. icmd->ulpCt_l = 0;
  4117. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  4118. *((uint32_t *) (pcmd)) = ELS_CMD_FDISC;
  4119. pcmd += sizeof(uint32_t); /* CSP Word 1 */
  4120. memcpy(pcmd, &vport->phba->pport->fc_sparam, sizeof(struct serv_parm));
  4121. sp = (struct serv_parm *) pcmd;
  4122. /* Setup CSPs accordingly for Fabric */
  4123. sp->cmn.e_d_tov = 0;
  4124. sp->cmn.w2.r_a_tov = 0;
  4125. sp->cls1.classValid = 0;
  4126. sp->cls2.seqDelivery = 1;
  4127. sp->cls3.seqDelivery = 1;
  4128. pcmd += sizeof(uint32_t); /* CSP Word 2 */
  4129. pcmd += sizeof(uint32_t); /* CSP Word 3 */
  4130. pcmd += sizeof(uint32_t); /* CSP Word 4 */
  4131. pcmd += sizeof(uint32_t); /* Port Name */
  4132. memcpy(pcmd, &vport->fc_portname, 8);
  4133. pcmd += sizeof(uint32_t); /* Node Name */
  4134. pcmd += sizeof(uint32_t); /* Node Name */
  4135. memcpy(pcmd, &vport->fc_nodename, 8);
  4136. lpfc_set_disctmo(vport);
  4137. phba->fc_stat.elsXmitFDISC++;
  4138. elsiocb->iocb_cmpl = lpfc_cmpl_els_fdisc;
  4139. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  4140. "Issue FDISC: did:x%x",
  4141. did, 0, 0);
  4142. rc = lpfc_issue_fabric_iocb(phba, elsiocb);
  4143. if (rc == IOCB_ERROR) {
  4144. lpfc_els_free_iocb(phba, elsiocb);
  4145. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  4146. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  4147. "0256 Issue FDISC: Cannot send IOCB\n");
  4148. return 1;
  4149. }
  4150. lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING);
  4151. vport->port_state = LPFC_FDISC;
  4152. return 0;
  4153. }
  4154. static void
  4155. lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  4156. struct lpfc_iocbq *rspiocb)
  4157. {
  4158. struct lpfc_vport *vport = cmdiocb->vport;
  4159. IOCB_t *irsp;
  4160. struct lpfc_nodelist *ndlp;
  4161. ndlp = (struct lpfc_nodelist *)cmdiocb->context1;
  4162. irsp = &rspiocb->iocb;
  4163. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  4164. "LOGO npiv cmpl: status:x%x/x%x did:x%x",
  4165. irsp->ulpStatus, irsp->un.ulpWord[4], irsp->un.rcvels.remoteID);
  4166. lpfc_els_free_iocb(phba, cmdiocb);
  4167. vport->unreg_vpi_cmpl = VPORT_ERROR;
  4168. /* Trigger the release of the ndlp after logo */
  4169. lpfc_nlp_put(ndlp);
  4170. }
  4171. int
  4172. lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
  4173. {
  4174. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  4175. struct lpfc_hba *phba = vport->phba;
  4176. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  4177. IOCB_t *icmd;
  4178. struct lpfc_iocbq *elsiocb;
  4179. uint8_t *pcmd;
  4180. uint16_t cmdsize;
  4181. cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name);
  4182. elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID,
  4183. ELS_CMD_LOGO);
  4184. if (!elsiocb)
  4185. return 1;
  4186. icmd = &elsiocb->iocb;
  4187. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  4188. *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
  4189. pcmd += sizeof(uint32_t);
  4190. /* Fill in LOGO payload */
  4191. *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
  4192. pcmd += sizeof(uint32_t);
  4193. memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
  4194. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  4195. "Issue LOGO npiv did:x%x flg:x%x",
  4196. ndlp->nlp_DID, ndlp->nlp_flag, 0);
  4197. elsiocb->iocb_cmpl = lpfc_cmpl_els_npiv_logo;
  4198. spin_lock_irq(shost->host_lock);
  4199. ndlp->nlp_flag |= NLP_LOGO_SND;
  4200. spin_unlock_irq(shost->host_lock);
  4201. if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
  4202. spin_lock_irq(shost->host_lock);
  4203. ndlp->nlp_flag &= ~NLP_LOGO_SND;
  4204. spin_unlock_irq(shost->host_lock);
  4205. lpfc_els_free_iocb(phba, elsiocb);
  4206. return 1;
  4207. }
  4208. return 0;
  4209. }
  4210. void
  4211. lpfc_fabric_block_timeout(unsigned long ptr)
  4212. {
  4213. struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
  4214. unsigned long iflags;
  4215. uint32_t tmo_posted;
  4216. spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
  4217. tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO;
  4218. if (!tmo_posted)
  4219. phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO;
  4220. spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
  4221. if (!tmo_posted)
  4222. lpfc_worker_wake_up(phba);
  4223. return;
  4224. }
  4225. static void
  4226. lpfc_resume_fabric_iocbs(struct lpfc_hba *phba)
  4227. {
  4228. struct lpfc_iocbq *iocb;
  4229. unsigned long iflags;
  4230. int ret;
  4231. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  4232. IOCB_t *cmd;
  4233. repeat:
  4234. iocb = NULL;
  4235. spin_lock_irqsave(&phba->hbalock, iflags);
  4236. /* Post any pending iocb to the SLI layer */
  4237. if (atomic_read(&phba->fabric_iocb_count) == 0) {
  4238. list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb),
  4239. list);
  4240. if (iocb)
  4241. /* Increment fabric iocb count to hold the position */
  4242. atomic_inc(&phba->fabric_iocb_count);
  4243. }
  4244. spin_unlock_irqrestore(&phba->hbalock, iflags);
  4245. if (iocb) {
  4246. iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
  4247. iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
  4248. iocb->iocb_flag |= LPFC_IO_FABRIC;
  4249. lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
  4250. "Fabric sched1: ste:x%x",
  4251. iocb->vport->port_state, 0, 0);
  4252. ret = lpfc_sli_issue_iocb(phba, pring, iocb, 0);
  4253. if (ret == IOCB_ERROR) {
  4254. iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
  4255. iocb->fabric_iocb_cmpl = NULL;
  4256. iocb->iocb_flag &= ~LPFC_IO_FABRIC;
  4257. cmd = &iocb->iocb;
  4258. cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
  4259. cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
  4260. iocb->iocb_cmpl(phba, iocb, iocb);
  4261. atomic_dec(&phba->fabric_iocb_count);
  4262. goto repeat;
  4263. }
  4264. }
  4265. return;
  4266. }
  4267. void
  4268. lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba)
  4269. {
  4270. clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
  4271. lpfc_resume_fabric_iocbs(phba);
  4272. return;
  4273. }
  4274. static void
  4275. lpfc_block_fabric_iocbs(struct lpfc_hba *phba)
  4276. {
  4277. int blocked;
  4278. blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
  4279. /* Start a timer to unblock fabric iocbs after 100ms */
  4280. if (!blocked)
  4281. mod_timer(&phba->fabric_block_timer, jiffies + HZ/10 );
  4282. return;
  4283. }
  4284. static void
  4285. lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  4286. struct lpfc_iocbq *rspiocb)
  4287. {
  4288. struct ls_rjt stat;
  4289. if ((cmdiocb->iocb_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC)
  4290. BUG();
  4291. switch (rspiocb->iocb.ulpStatus) {
  4292. case IOSTAT_NPORT_RJT:
  4293. case IOSTAT_FABRIC_RJT:
  4294. if (rspiocb->iocb.un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
  4295. lpfc_block_fabric_iocbs(phba);
  4296. }
  4297. break;
  4298. case IOSTAT_NPORT_BSY:
  4299. case IOSTAT_FABRIC_BSY:
  4300. lpfc_block_fabric_iocbs(phba);
  4301. break;
  4302. case IOSTAT_LS_RJT:
  4303. stat.un.lsRjtError =
  4304. be32_to_cpu(rspiocb->iocb.un.ulpWord[4]);
  4305. if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) ||
  4306. (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY))
  4307. lpfc_block_fabric_iocbs(phba);
  4308. break;
  4309. }
  4310. if (atomic_read(&phba->fabric_iocb_count) == 0)
  4311. BUG();
  4312. cmdiocb->iocb_cmpl = cmdiocb->fabric_iocb_cmpl;
  4313. cmdiocb->fabric_iocb_cmpl = NULL;
  4314. cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC;
  4315. cmdiocb->iocb_cmpl(phba, cmdiocb, rspiocb);
  4316. atomic_dec(&phba->fabric_iocb_count);
  4317. if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) {
  4318. /* Post any pending iocbs to HBA */
  4319. lpfc_resume_fabric_iocbs(phba);
  4320. }
  4321. }
  4322. static int
  4323. lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb)
  4324. {
  4325. unsigned long iflags;
  4326. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  4327. int ready;
  4328. int ret;
  4329. if (atomic_read(&phba->fabric_iocb_count) > 1)
  4330. BUG();
  4331. spin_lock_irqsave(&phba->hbalock, iflags);
  4332. ready = atomic_read(&phba->fabric_iocb_count) == 0 &&
  4333. !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
  4334. if (ready)
  4335. /* Increment fabric iocb count to hold the position */
  4336. atomic_inc(&phba->fabric_iocb_count);
  4337. spin_unlock_irqrestore(&phba->hbalock, iflags);
  4338. if (ready) {
  4339. iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
  4340. iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
  4341. iocb->iocb_flag |= LPFC_IO_FABRIC;
  4342. lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
  4343. "Fabric sched2: ste:x%x",
  4344. iocb->vport->port_state, 0, 0);
  4345. ret = lpfc_sli_issue_iocb(phba, pring, iocb, 0);
  4346. if (ret == IOCB_ERROR) {
  4347. iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
  4348. iocb->fabric_iocb_cmpl = NULL;
  4349. iocb->iocb_flag &= ~LPFC_IO_FABRIC;
  4350. atomic_dec(&phba->fabric_iocb_count);
  4351. }
  4352. } else {
  4353. spin_lock_irqsave(&phba->hbalock, iflags);
  4354. list_add_tail(&iocb->list, &phba->fabric_iocb_list);
  4355. spin_unlock_irqrestore(&phba->hbalock, iflags);
  4356. ret = IOCB_SUCCESS;
  4357. }
  4358. return ret;
  4359. }
  4360. static void lpfc_fabric_abort_vport(struct lpfc_vport *vport)
  4361. {
  4362. LIST_HEAD(completions);
  4363. struct lpfc_hba *phba = vport->phba;
  4364. struct lpfc_iocbq *tmp_iocb, *piocb;
  4365. IOCB_t *cmd;
  4366. spin_lock_irq(&phba->hbalock);
  4367. list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
  4368. list) {
  4369. if (piocb->vport != vport)
  4370. continue;
  4371. list_move_tail(&piocb->list, &completions);
  4372. }
  4373. spin_unlock_irq(&phba->hbalock);
  4374. while (!list_empty(&completions)) {
  4375. piocb = list_get_first(&completions, struct lpfc_iocbq, list);
  4376. list_del_init(&piocb->list);
  4377. cmd = &piocb->iocb;
  4378. cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
  4379. cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
  4380. (piocb->iocb_cmpl) (phba, piocb, piocb);
  4381. }
  4382. }
  4383. void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp)
  4384. {
  4385. LIST_HEAD(completions);
  4386. struct lpfc_hba *phba = ndlp->vport->phba;
  4387. struct lpfc_iocbq *tmp_iocb, *piocb;
  4388. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  4389. IOCB_t *cmd;
  4390. spin_lock_irq(&phba->hbalock);
  4391. list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
  4392. list) {
  4393. if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) {
  4394. list_move_tail(&piocb->list, &completions);
  4395. }
  4396. }
  4397. spin_unlock_irq(&phba->hbalock);
  4398. while (!list_empty(&completions)) {
  4399. piocb = list_get_first(&completions, struct lpfc_iocbq, list);
  4400. list_del_init(&piocb->list);
  4401. cmd = &piocb->iocb;
  4402. cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
  4403. cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
  4404. (piocb->iocb_cmpl) (phba, piocb, piocb);
  4405. }
  4406. }
  4407. void lpfc_fabric_abort_hba(struct lpfc_hba *phba)
  4408. {
  4409. LIST_HEAD(completions);
  4410. struct lpfc_iocbq *piocb;
  4411. IOCB_t *cmd;
  4412. spin_lock_irq(&phba->hbalock);
  4413. list_splice_init(&phba->fabric_iocb_list, &completions);
  4414. spin_unlock_irq(&phba->hbalock);
  4415. while (!list_empty(&completions)) {
  4416. piocb = list_get_first(&completions, struct lpfc_iocbq, list);
  4417. list_del_init(&piocb->list);
  4418. cmd = &piocb->iocb;
  4419. cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
  4420. cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
  4421. (piocb->iocb_cmpl) (phba, piocb, piocb);
  4422. }
  4423. }