lpfc_els.c 139 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099
  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. spin_lock_irq(shost->host_lock);
  1530. nlp->nlp_flag &= ~NLP_DELAY_TMO;
  1531. spin_unlock_irq(shost->host_lock);
  1532. del_timer_sync(&nlp->nlp_delayfunc);
  1533. nlp->nlp_last_elscmd = 0;
  1534. if (!list_empty(&nlp->els_retry_evt.evt_listp)) {
  1535. list_del_init(&nlp->els_retry_evt.evt_listp);
  1536. /* Decrement nlp reference count held for the delayed retry */
  1537. evtp = &nlp->els_retry_evt;
  1538. lpfc_nlp_put((struct lpfc_nodelist *)evtp->evt_arg1);
  1539. }
  1540. if (nlp->nlp_flag & NLP_NPR_2B_DISC) {
  1541. spin_lock_irq(shost->host_lock);
  1542. nlp->nlp_flag &= ~NLP_NPR_2B_DISC;
  1543. spin_unlock_irq(shost->host_lock);
  1544. if (vport->num_disc_nodes) {
  1545. /* Check to see if there are more
  1546. * PLOGIs to be sent
  1547. */
  1548. lpfc_more_plogi(vport);
  1549. if (vport->num_disc_nodes == 0) {
  1550. spin_lock_irq(shost->host_lock);
  1551. vport->fc_flag &= ~FC_NDISC_ACTIVE;
  1552. spin_unlock_irq(shost->host_lock);
  1553. lpfc_can_disctmo(vport);
  1554. lpfc_end_rscn(vport);
  1555. }
  1556. }
  1557. }
  1558. return;
  1559. }
  1560. void
  1561. lpfc_els_retry_delay(unsigned long ptr)
  1562. {
  1563. struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) ptr;
  1564. struct lpfc_vport *vport = ndlp->vport;
  1565. struct lpfc_hba *phba = vport->phba;
  1566. unsigned long flags;
  1567. struct lpfc_work_evt *evtp = &ndlp->els_retry_evt;
  1568. ndlp = (struct lpfc_nodelist *) ptr;
  1569. phba = ndlp->vport->phba;
  1570. evtp = &ndlp->els_retry_evt;
  1571. spin_lock_irqsave(&phba->hbalock, flags);
  1572. if (!list_empty(&evtp->evt_listp)) {
  1573. spin_unlock_irqrestore(&phba->hbalock, flags);
  1574. return;
  1575. }
  1576. /* We need to hold the node by incrementing the reference
  1577. * count until the queued work is done
  1578. */
  1579. evtp->evt_arg1 = lpfc_nlp_get(ndlp);
  1580. evtp->evt = LPFC_EVT_ELS_RETRY;
  1581. list_add_tail(&evtp->evt_listp, &phba->work_list);
  1582. if (phba->work_wait)
  1583. lpfc_worker_wake_up(phba);
  1584. spin_unlock_irqrestore(&phba->hbalock, flags);
  1585. return;
  1586. }
  1587. void
  1588. lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp)
  1589. {
  1590. struct lpfc_vport *vport = ndlp->vport;
  1591. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  1592. uint32_t cmd, did, retry;
  1593. spin_lock_irq(shost->host_lock);
  1594. did = ndlp->nlp_DID;
  1595. cmd = ndlp->nlp_last_elscmd;
  1596. ndlp->nlp_last_elscmd = 0;
  1597. if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
  1598. spin_unlock_irq(shost->host_lock);
  1599. return;
  1600. }
  1601. ndlp->nlp_flag &= ~NLP_DELAY_TMO;
  1602. spin_unlock_irq(shost->host_lock);
  1603. /*
  1604. * If a discovery event readded nlp_delayfunc after timer
  1605. * firing and before processing the timer, cancel the
  1606. * nlp_delayfunc.
  1607. */
  1608. del_timer_sync(&ndlp->nlp_delayfunc);
  1609. retry = ndlp->nlp_retry;
  1610. switch (cmd) {
  1611. case ELS_CMD_FLOGI:
  1612. lpfc_issue_els_flogi(vport, ndlp, retry);
  1613. break;
  1614. case ELS_CMD_PLOGI:
  1615. if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) {
  1616. ndlp->nlp_prev_state = ndlp->nlp_state;
  1617. lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
  1618. }
  1619. break;
  1620. case ELS_CMD_ADISC:
  1621. if (!lpfc_issue_els_adisc(vport, ndlp, retry)) {
  1622. ndlp->nlp_prev_state = ndlp->nlp_state;
  1623. lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
  1624. }
  1625. break;
  1626. case ELS_CMD_PRLI:
  1627. if (!lpfc_issue_els_prli(vport, ndlp, retry)) {
  1628. ndlp->nlp_prev_state = ndlp->nlp_state;
  1629. lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
  1630. }
  1631. break;
  1632. case ELS_CMD_LOGO:
  1633. if (!lpfc_issue_els_logo(vport, ndlp, retry)) {
  1634. ndlp->nlp_prev_state = ndlp->nlp_state;
  1635. lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
  1636. }
  1637. break;
  1638. case ELS_CMD_FDISC:
  1639. lpfc_issue_els_fdisc(vport, ndlp, retry);
  1640. break;
  1641. }
  1642. return;
  1643. }
  1644. static int
  1645. lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  1646. struct lpfc_iocbq *rspiocb)
  1647. {
  1648. struct lpfc_vport *vport = cmdiocb->vport;
  1649. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  1650. IOCB_t *irsp = &rspiocb->iocb;
  1651. struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
  1652. struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
  1653. uint32_t *elscmd;
  1654. struct ls_rjt stat;
  1655. int retry = 0, maxretry = lpfc_max_els_tries, delay = 0;
  1656. int logerr = 0;
  1657. uint32_t cmd = 0;
  1658. uint32_t did;
  1659. /* Note: context2 may be 0 for internal driver abort
  1660. * of delays ELS command.
  1661. */
  1662. if (pcmd && pcmd->virt) {
  1663. elscmd = (uint32_t *) (pcmd->virt);
  1664. cmd = *elscmd++;
  1665. }
  1666. if (ndlp && NLP_CHK_NODE_ACT(ndlp))
  1667. did = ndlp->nlp_DID;
  1668. else {
  1669. /* We should only hit this case for retrying PLOGI */
  1670. did = irsp->un.elsreq64.remoteID;
  1671. ndlp = lpfc_findnode_did(vport, did);
  1672. if ((!ndlp || !NLP_CHK_NODE_ACT(ndlp))
  1673. && (cmd != ELS_CMD_PLOGI))
  1674. return 1;
  1675. }
  1676. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  1677. "Retry ELS: wd7:x%x wd4:x%x did:x%x",
  1678. *(((uint32_t *) irsp) + 7), irsp->un.ulpWord[4], ndlp->nlp_DID);
  1679. switch (irsp->ulpStatus) {
  1680. case IOSTAT_FCP_RSP_ERROR:
  1681. case IOSTAT_REMOTE_STOP:
  1682. break;
  1683. case IOSTAT_LOCAL_REJECT:
  1684. switch ((irsp->un.ulpWord[4] & 0xff)) {
  1685. case IOERR_LOOP_OPEN_FAILURE:
  1686. if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0)
  1687. delay = 1000;
  1688. retry = 1;
  1689. break;
  1690. case IOERR_ILLEGAL_COMMAND:
  1691. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  1692. "0124 Retry illegal cmd x%x "
  1693. "retry:x%x delay:x%x\n",
  1694. cmd, cmdiocb->retry, delay);
  1695. retry = 1;
  1696. /* All command's retry policy */
  1697. maxretry = 8;
  1698. if (cmdiocb->retry > 2)
  1699. delay = 1000;
  1700. break;
  1701. case IOERR_NO_RESOURCES:
  1702. logerr = 1; /* HBA out of resources */
  1703. retry = 1;
  1704. if (cmdiocb->retry > 100)
  1705. delay = 100;
  1706. maxretry = 250;
  1707. break;
  1708. case IOERR_ILLEGAL_FRAME:
  1709. delay = 100;
  1710. retry = 1;
  1711. break;
  1712. case IOERR_SEQUENCE_TIMEOUT:
  1713. case IOERR_INVALID_RPI:
  1714. retry = 1;
  1715. break;
  1716. }
  1717. break;
  1718. case IOSTAT_NPORT_RJT:
  1719. case IOSTAT_FABRIC_RJT:
  1720. if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
  1721. retry = 1;
  1722. break;
  1723. }
  1724. break;
  1725. case IOSTAT_NPORT_BSY:
  1726. case IOSTAT_FABRIC_BSY:
  1727. logerr = 1; /* Fabric / Remote NPort out of resources */
  1728. retry = 1;
  1729. break;
  1730. case IOSTAT_LS_RJT:
  1731. stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]);
  1732. /* Added for Vendor specifc support
  1733. * Just keep retrying for these Rsn / Exp codes
  1734. */
  1735. switch (stat.un.b.lsRjtRsnCode) {
  1736. case LSRJT_UNABLE_TPC:
  1737. if (stat.un.b.lsRjtRsnCodeExp ==
  1738. LSEXP_CMD_IN_PROGRESS) {
  1739. if (cmd == ELS_CMD_PLOGI) {
  1740. delay = 1000;
  1741. maxretry = 48;
  1742. }
  1743. retry = 1;
  1744. break;
  1745. }
  1746. if (cmd == ELS_CMD_PLOGI) {
  1747. delay = 1000;
  1748. maxretry = lpfc_max_els_tries + 1;
  1749. retry = 1;
  1750. break;
  1751. }
  1752. if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
  1753. (cmd == ELS_CMD_FDISC) &&
  1754. (stat.un.b.lsRjtRsnCodeExp == LSEXP_OUT_OF_RESOURCE)){
  1755. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  1756. "0125 FDISC Failed (x%x). "
  1757. "Fabric out of resources\n",
  1758. stat.un.lsRjtError);
  1759. lpfc_vport_set_state(vport,
  1760. FC_VPORT_NO_FABRIC_RSCS);
  1761. }
  1762. break;
  1763. case LSRJT_LOGICAL_BSY:
  1764. if ((cmd == ELS_CMD_PLOGI) ||
  1765. (cmd == ELS_CMD_PRLI)) {
  1766. delay = 1000;
  1767. maxretry = 48;
  1768. } else if (cmd == ELS_CMD_FDISC) {
  1769. /* FDISC retry policy */
  1770. maxretry = 48;
  1771. if (cmdiocb->retry >= 32)
  1772. delay = 1000;
  1773. }
  1774. retry = 1;
  1775. break;
  1776. case LSRJT_LOGICAL_ERR:
  1777. /* There are some cases where switches return this
  1778. * error when they are not ready and should be returning
  1779. * Logical Busy. We should delay every time.
  1780. */
  1781. if (cmd == ELS_CMD_FDISC &&
  1782. stat.un.b.lsRjtRsnCodeExp == LSEXP_PORT_LOGIN_REQ) {
  1783. maxretry = 3;
  1784. delay = 1000;
  1785. retry = 1;
  1786. break;
  1787. }
  1788. case LSRJT_PROTOCOL_ERR:
  1789. if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
  1790. (cmd == ELS_CMD_FDISC) &&
  1791. ((stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_PNAME) ||
  1792. (stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_NPORT_ID))
  1793. ) {
  1794. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  1795. "0123 FDISC Failed (x%x). "
  1796. "Fabric Detected Bad WWN\n",
  1797. stat.un.lsRjtError);
  1798. lpfc_vport_set_state(vport,
  1799. FC_VPORT_FABRIC_REJ_WWN);
  1800. }
  1801. break;
  1802. }
  1803. break;
  1804. case IOSTAT_INTERMED_RSP:
  1805. case IOSTAT_BA_RJT:
  1806. break;
  1807. default:
  1808. break;
  1809. }
  1810. if (did == FDMI_DID)
  1811. retry = 1;
  1812. if ((cmd == ELS_CMD_FLOGI) &&
  1813. (phba->fc_topology != TOPOLOGY_LOOP) &&
  1814. !lpfc_error_lost_link(irsp)) {
  1815. /* FLOGI retry policy */
  1816. retry = 1;
  1817. maxretry = 48;
  1818. if (cmdiocb->retry >= 32)
  1819. delay = 1000;
  1820. }
  1821. if ((++cmdiocb->retry) >= maxretry) {
  1822. phba->fc_stat.elsRetryExceeded++;
  1823. retry = 0;
  1824. }
  1825. if ((vport->load_flag & FC_UNLOADING) != 0)
  1826. retry = 0;
  1827. if (retry) {
  1828. /* Retry ELS command <elsCmd> to remote NPORT <did> */
  1829. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  1830. "0107 Retry ELS command x%x to remote "
  1831. "NPORT x%x Data: x%x x%x\n",
  1832. cmd, did, cmdiocb->retry, delay);
  1833. if (((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) &&
  1834. ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
  1835. ((irsp->un.ulpWord[4] & 0xff) != IOERR_NO_RESOURCES))) {
  1836. /* Don't reset timer for no resources */
  1837. /* If discovery / RSCN timer is running, reset it */
  1838. if (timer_pending(&vport->fc_disctmo) ||
  1839. (vport->fc_flag & FC_RSCN_MODE))
  1840. lpfc_set_disctmo(vport);
  1841. }
  1842. phba->fc_stat.elsXmitRetry++;
  1843. if (ndlp && NLP_CHK_NODE_ACT(ndlp) && delay) {
  1844. phba->fc_stat.elsDelayRetry++;
  1845. ndlp->nlp_retry = cmdiocb->retry;
  1846. /* delay is specified in milliseconds */
  1847. mod_timer(&ndlp->nlp_delayfunc,
  1848. jiffies + msecs_to_jiffies(delay));
  1849. spin_lock_irq(shost->host_lock);
  1850. ndlp->nlp_flag |= NLP_DELAY_TMO;
  1851. spin_unlock_irq(shost->host_lock);
  1852. ndlp->nlp_prev_state = ndlp->nlp_state;
  1853. if (cmd == ELS_CMD_PRLI)
  1854. lpfc_nlp_set_state(vport, ndlp,
  1855. NLP_STE_REG_LOGIN_ISSUE);
  1856. else
  1857. lpfc_nlp_set_state(vport, ndlp,
  1858. NLP_STE_NPR_NODE);
  1859. ndlp->nlp_last_elscmd = cmd;
  1860. return 1;
  1861. }
  1862. switch (cmd) {
  1863. case ELS_CMD_FLOGI:
  1864. lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry);
  1865. return 1;
  1866. case ELS_CMD_FDISC:
  1867. lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry);
  1868. return 1;
  1869. case ELS_CMD_PLOGI:
  1870. if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
  1871. ndlp->nlp_prev_state = ndlp->nlp_state;
  1872. lpfc_nlp_set_state(vport, ndlp,
  1873. NLP_STE_PLOGI_ISSUE);
  1874. }
  1875. lpfc_issue_els_plogi(vport, did, cmdiocb->retry);
  1876. return 1;
  1877. case ELS_CMD_ADISC:
  1878. ndlp->nlp_prev_state = ndlp->nlp_state;
  1879. lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
  1880. lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry);
  1881. return 1;
  1882. case ELS_CMD_PRLI:
  1883. ndlp->nlp_prev_state = ndlp->nlp_state;
  1884. lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
  1885. lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry);
  1886. return 1;
  1887. case ELS_CMD_LOGO:
  1888. ndlp->nlp_prev_state = ndlp->nlp_state;
  1889. lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
  1890. lpfc_issue_els_logo(vport, ndlp, cmdiocb->retry);
  1891. return 1;
  1892. }
  1893. }
  1894. /* No retry ELS command <elsCmd> to remote NPORT <did> */
  1895. if (logerr) {
  1896. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  1897. "0137 No retry ELS command x%x to remote "
  1898. "NPORT x%x: Out of Resources: Error:x%x/%x\n",
  1899. cmd, did, irsp->ulpStatus,
  1900. irsp->un.ulpWord[4]);
  1901. }
  1902. else {
  1903. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  1904. "0108 No retry ELS command x%x to remote "
  1905. "NPORT x%x Retried:%d Error:x%x/%x\n",
  1906. cmd, did, cmdiocb->retry, irsp->ulpStatus,
  1907. irsp->un.ulpWord[4]);
  1908. }
  1909. return 0;
  1910. }
  1911. static int
  1912. lpfc_els_free_data(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr1)
  1913. {
  1914. struct lpfc_dmabuf *buf_ptr;
  1915. /* Free the response before processing the command. */
  1916. if (!list_empty(&buf_ptr1->list)) {
  1917. list_remove_head(&buf_ptr1->list, buf_ptr,
  1918. struct lpfc_dmabuf,
  1919. list);
  1920. lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
  1921. kfree(buf_ptr);
  1922. }
  1923. lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys);
  1924. kfree(buf_ptr1);
  1925. return 0;
  1926. }
  1927. static int
  1928. lpfc_els_free_bpl(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr)
  1929. {
  1930. lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
  1931. kfree(buf_ptr);
  1932. return 0;
  1933. }
  1934. int
  1935. lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb)
  1936. {
  1937. struct lpfc_dmabuf *buf_ptr, *buf_ptr1;
  1938. struct lpfc_nodelist *ndlp;
  1939. ndlp = (struct lpfc_nodelist *)elsiocb->context1;
  1940. if (ndlp) {
  1941. if (ndlp->nlp_flag & NLP_DEFER_RM) {
  1942. lpfc_nlp_put(ndlp);
  1943. /* If the ndlp is not being used by another discovery
  1944. * thread, free it.
  1945. */
  1946. if (!lpfc_nlp_not_used(ndlp)) {
  1947. /* If ndlp is being used by another discovery
  1948. * thread, just clear NLP_DEFER_RM
  1949. */
  1950. ndlp->nlp_flag &= ~NLP_DEFER_RM;
  1951. }
  1952. }
  1953. else
  1954. lpfc_nlp_put(ndlp);
  1955. elsiocb->context1 = NULL;
  1956. }
  1957. /* context2 = cmd, context2->next = rsp, context3 = bpl */
  1958. if (elsiocb->context2) {
  1959. if (elsiocb->iocb_flag & LPFC_DELAY_MEM_FREE) {
  1960. /* Firmware could still be in progress of DMAing
  1961. * payload, so don't free data buffer till after
  1962. * a hbeat.
  1963. */
  1964. elsiocb->iocb_flag &= ~LPFC_DELAY_MEM_FREE;
  1965. buf_ptr = elsiocb->context2;
  1966. elsiocb->context2 = NULL;
  1967. if (buf_ptr) {
  1968. buf_ptr1 = NULL;
  1969. spin_lock_irq(&phba->hbalock);
  1970. if (!list_empty(&buf_ptr->list)) {
  1971. list_remove_head(&buf_ptr->list,
  1972. buf_ptr1, struct lpfc_dmabuf,
  1973. list);
  1974. INIT_LIST_HEAD(&buf_ptr1->list);
  1975. list_add_tail(&buf_ptr1->list,
  1976. &phba->elsbuf);
  1977. phba->elsbuf_cnt++;
  1978. }
  1979. INIT_LIST_HEAD(&buf_ptr->list);
  1980. list_add_tail(&buf_ptr->list, &phba->elsbuf);
  1981. phba->elsbuf_cnt++;
  1982. spin_unlock_irq(&phba->hbalock);
  1983. }
  1984. } else {
  1985. buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2;
  1986. lpfc_els_free_data(phba, buf_ptr1);
  1987. }
  1988. }
  1989. if (elsiocb->context3) {
  1990. buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3;
  1991. lpfc_els_free_bpl(phba, buf_ptr);
  1992. }
  1993. lpfc_sli_release_iocbq(phba, elsiocb);
  1994. return 0;
  1995. }
  1996. static void
  1997. lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  1998. struct lpfc_iocbq *rspiocb)
  1999. {
  2000. struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
  2001. struct lpfc_vport *vport = cmdiocb->vport;
  2002. IOCB_t *irsp;
  2003. irsp = &rspiocb->iocb;
  2004. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
  2005. "ACC LOGO cmpl: status:x%x/x%x did:x%x",
  2006. irsp->ulpStatus, irsp->un.ulpWord[4], ndlp->nlp_DID);
  2007. /* ACC to LOGO completes to NPort <nlp_DID> */
  2008. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  2009. "0109 ACC to LOGO completes to NPort x%x "
  2010. "Data: x%x x%x x%x\n",
  2011. ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
  2012. ndlp->nlp_rpi);
  2013. if (ndlp->nlp_state == NLP_STE_NPR_NODE) {
  2014. /* NPort Recovery mode or node is just allocated */
  2015. if (!lpfc_nlp_not_used(ndlp)) {
  2016. /* If the ndlp is being used by another discovery
  2017. * thread, just unregister the RPI.
  2018. */
  2019. lpfc_unreg_rpi(vport, ndlp);
  2020. } else {
  2021. /* Indicate the node has already released, should
  2022. * not reference to it from within lpfc_els_free_iocb.
  2023. */
  2024. cmdiocb->context1 = NULL;
  2025. }
  2026. }
  2027. lpfc_els_free_iocb(phba, cmdiocb);
  2028. return;
  2029. }
  2030. void
  2031. lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  2032. {
  2033. struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
  2034. struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
  2035. pmb->context1 = NULL;
  2036. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  2037. kfree(mp);
  2038. mempool_free(pmb, phba->mbox_mem_pool);
  2039. if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
  2040. lpfc_nlp_put(ndlp);
  2041. /* This is the end of the default RPI cleanup logic for this
  2042. * ndlp. If no other discovery threads are using this ndlp.
  2043. * we should free all resources associated with it.
  2044. */
  2045. lpfc_nlp_not_used(ndlp);
  2046. }
  2047. return;
  2048. }
  2049. static void
  2050. lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  2051. struct lpfc_iocbq *rspiocb)
  2052. {
  2053. struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
  2054. struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL;
  2055. struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL;
  2056. IOCB_t *irsp;
  2057. uint8_t *pcmd;
  2058. LPFC_MBOXQ_t *mbox = NULL;
  2059. struct lpfc_dmabuf *mp = NULL;
  2060. uint32_t ls_rjt = 0;
  2061. irsp = &rspiocb->iocb;
  2062. if (cmdiocb->context_un.mbox)
  2063. mbox = cmdiocb->context_un.mbox;
  2064. /* First determine if this is a LS_RJT cmpl. Note, this callback
  2065. * function can have cmdiocb->contest1 (ndlp) field set to NULL.
  2066. */
  2067. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
  2068. if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
  2069. (*((uint32_t *) (pcmd)) == ELS_CMD_LS_RJT)) {
  2070. /* A LS_RJT associated with Default RPI cleanup has its own
  2071. * seperate code path.
  2072. */
  2073. if (!(ndlp->nlp_flag & NLP_RM_DFLT_RPI))
  2074. ls_rjt = 1;
  2075. }
  2076. /* Check to see if link went down during discovery */
  2077. if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || lpfc_els_chk_latt(vport)) {
  2078. if (mbox) {
  2079. mp = (struct lpfc_dmabuf *) mbox->context1;
  2080. if (mp) {
  2081. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  2082. kfree(mp);
  2083. }
  2084. mempool_free(mbox, phba->mbox_mem_pool);
  2085. }
  2086. if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
  2087. (ndlp->nlp_flag & NLP_RM_DFLT_RPI))
  2088. if (lpfc_nlp_not_used(ndlp)) {
  2089. ndlp = NULL;
  2090. /* Indicate the node has already released,
  2091. * should not reference to it from within
  2092. * the routine lpfc_els_free_iocb.
  2093. */
  2094. cmdiocb->context1 = NULL;
  2095. }
  2096. goto out;
  2097. }
  2098. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
  2099. "ELS rsp cmpl: status:x%x/x%x did:x%x",
  2100. irsp->ulpStatus, irsp->un.ulpWord[4],
  2101. cmdiocb->iocb.un.elsreq64.remoteID);
  2102. /* ELS response tag <ulpIoTag> completes */
  2103. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  2104. "0110 ELS response tag x%x completes "
  2105. "Data: x%x x%x x%x x%x x%x x%x x%x\n",
  2106. cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus,
  2107. rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout,
  2108. ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
  2109. ndlp->nlp_rpi);
  2110. if (mbox) {
  2111. if ((rspiocb->iocb.ulpStatus == 0)
  2112. && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) {
  2113. lpfc_unreg_rpi(vport, ndlp);
  2114. /* Increment reference count to ndlp to hold the
  2115. * reference to ndlp for the callback function.
  2116. */
  2117. mbox->context2 = lpfc_nlp_get(ndlp);
  2118. mbox->vport = vport;
  2119. if (ndlp->nlp_flag & NLP_RM_DFLT_RPI) {
  2120. mbox->mbox_flag |= LPFC_MBX_IMED_UNREG;
  2121. mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
  2122. }
  2123. else {
  2124. mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
  2125. ndlp->nlp_prev_state = ndlp->nlp_state;
  2126. lpfc_nlp_set_state(vport, ndlp,
  2127. NLP_STE_REG_LOGIN_ISSUE);
  2128. }
  2129. if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
  2130. != MBX_NOT_FINISHED)
  2131. goto out;
  2132. else
  2133. /* Decrement the ndlp reference count we
  2134. * set for this failed mailbox command.
  2135. */
  2136. lpfc_nlp_put(ndlp);
  2137. /* ELS rsp: Cannot issue reg_login for <NPortid> */
  2138. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  2139. "0138 ELS rsp: Cannot issue reg_login for x%x "
  2140. "Data: x%x x%x x%x\n",
  2141. ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
  2142. ndlp->nlp_rpi);
  2143. if (lpfc_nlp_not_used(ndlp)) {
  2144. ndlp = NULL;
  2145. /* Indicate node has already been released,
  2146. * should not reference to it from within
  2147. * the routine lpfc_els_free_iocb.
  2148. */
  2149. cmdiocb->context1 = NULL;
  2150. }
  2151. } else {
  2152. /* Do not drop node for lpfc_els_abort'ed ELS cmds */
  2153. if (!lpfc_error_lost_link(irsp) &&
  2154. ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
  2155. if (lpfc_nlp_not_used(ndlp)) {
  2156. ndlp = NULL;
  2157. /* Indicate node has already been
  2158. * released, should not reference
  2159. * to it from within the routine
  2160. * lpfc_els_free_iocb.
  2161. */
  2162. cmdiocb->context1 = NULL;
  2163. }
  2164. }
  2165. }
  2166. mp = (struct lpfc_dmabuf *) mbox->context1;
  2167. if (mp) {
  2168. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  2169. kfree(mp);
  2170. }
  2171. mempool_free(mbox, phba->mbox_mem_pool);
  2172. }
  2173. out:
  2174. if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
  2175. spin_lock_irq(shost->host_lock);
  2176. ndlp->nlp_flag &= ~(NLP_ACC_REGLOGIN | NLP_RM_DFLT_RPI);
  2177. spin_unlock_irq(shost->host_lock);
  2178. /* If the node is not being used by another discovery thread,
  2179. * and we are sending a reject, we are done with it.
  2180. * Release driver reference count here and free associated
  2181. * resources.
  2182. */
  2183. if (ls_rjt)
  2184. if (lpfc_nlp_not_used(ndlp))
  2185. /* Indicate node has already been released,
  2186. * should not reference to it from within
  2187. * the routine lpfc_els_free_iocb.
  2188. */
  2189. cmdiocb->context1 = NULL;
  2190. }
  2191. lpfc_els_free_iocb(phba, cmdiocb);
  2192. return;
  2193. }
  2194. int
  2195. lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag,
  2196. struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
  2197. LPFC_MBOXQ_t *mbox)
  2198. {
  2199. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2200. struct lpfc_hba *phba = vport->phba;
  2201. IOCB_t *icmd;
  2202. IOCB_t *oldcmd;
  2203. struct lpfc_iocbq *elsiocb;
  2204. struct lpfc_sli_ring *pring;
  2205. struct lpfc_sli *psli;
  2206. uint8_t *pcmd;
  2207. uint16_t cmdsize;
  2208. int rc;
  2209. ELS_PKT *els_pkt_ptr;
  2210. psli = &phba->sli;
  2211. pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
  2212. oldcmd = &oldiocb->iocb;
  2213. switch (flag) {
  2214. case ELS_CMD_ACC:
  2215. cmdsize = sizeof(uint32_t);
  2216. elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
  2217. ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
  2218. if (!elsiocb) {
  2219. spin_lock_irq(shost->host_lock);
  2220. ndlp->nlp_flag &= ~NLP_LOGO_ACC;
  2221. spin_unlock_irq(shost->host_lock);
  2222. return 1;
  2223. }
  2224. icmd = &elsiocb->iocb;
  2225. icmd->ulpContext = oldcmd->ulpContext; /* Xri */
  2226. pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  2227. *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
  2228. pcmd += sizeof(uint32_t);
  2229. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
  2230. "Issue ACC: did:x%x flg:x%x",
  2231. ndlp->nlp_DID, ndlp->nlp_flag, 0);
  2232. break;
  2233. case ELS_CMD_PLOGI:
  2234. cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t));
  2235. elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
  2236. ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
  2237. if (!elsiocb)
  2238. return 1;
  2239. icmd = &elsiocb->iocb;
  2240. icmd->ulpContext = oldcmd->ulpContext; /* Xri */
  2241. pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  2242. if (mbox)
  2243. elsiocb->context_un.mbox = mbox;
  2244. *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
  2245. pcmd += sizeof(uint32_t);
  2246. memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
  2247. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
  2248. "Issue ACC PLOGI: did:x%x flg:x%x",
  2249. ndlp->nlp_DID, ndlp->nlp_flag, 0);
  2250. break;
  2251. case ELS_CMD_PRLO:
  2252. cmdsize = sizeof(uint32_t) + sizeof(PRLO);
  2253. elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
  2254. ndlp, ndlp->nlp_DID, ELS_CMD_PRLO);
  2255. if (!elsiocb)
  2256. return 1;
  2257. icmd = &elsiocb->iocb;
  2258. icmd->ulpContext = oldcmd->ulpContext; /* Xri */
  2259. pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  2260. memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt,
  2261. sizeof(uint32_t) + sizeof(PRLO));
  2262. *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC;
  2263. els_pkt_ptr = (ELS_PKT *) pcmd;
  2264. els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED;
  2265. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
  2266. "Issue ACC PRLO: did:x%x flg:x%x",
  2267. ndlp->nlp_DID, ndlp->nlp_flag, 0);
  2268. break;
  2269. default:
  2270. return 1;
  2271. }
  2272. /* Xmit ELS ACC response tag <ulpIoTag> */
  2273. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  2274. "0128 Xmit ELS ACC response tag x%x, XRI: x%x, "
  2275. "DID: x%x, nlp_flag: x%x nlp_state: x%x RPI: x%x\n",
  2276. elsiocb->iotag, elsiocb->iocb.ulpContext,
  2277. ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
  2278. ndlp->nlp_rpi);
  2279. if (ndlp->nlp_flag & NLP_LOGO_ACC) {
  2280. spin_lock_irq(shost->host_lock);
  2281. ndlp->nlp_flag &= ~NLP_LOGO_ACC;
  2282. spin_unlock_irq(shost->host_lock);
  2283. elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc;
  2284. } else {
  2285. elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
  2286. }
  2287. phba->fc_stat.elsXmitACC++;
  2288. rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
  2289. if (rc == IOCB_ERROR) {
  2290. lpfc_els_free_iocb(phba, elsiocb);
  2291. return 1;
  2292. }
  2293. return 0;
  2294. }
  2295. int
  2296. lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError,
  2297. struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
  2298. LPFC_MBOXQ_t *mbox)
  2299. {
  2300. struct lpfc_hba *phba = vport->phba;
  2301. IOCB_t *icmd;
  2302. IOCB_t *oldcmd;
  2303. struct lpfc_iocbq *elsiocb;
  2304. struct lpfc_sli_ring *pring;
  2305. struct lpfc_sli *psli;
  2306. uint8_t *pcmd;
  2307. uint16_t cmdsize;
  2308. int rc;
  2309. psli = &phba->sli;
  2310. pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
  2311. cmdsize = 2 * sizeof(uint32_t);
  2312. elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
  2313. ndlp->nlp_DID, ELS_CMD_LS_RJT);
  2314. if (!elsiocb)
  2315. return 1;
  2316. icmd = &elsiocb->iocb;
  2317. oldcmd = &oldiocb->iocb;
  2318. icmd->ulpContext = oldcmd->ulpContext; /* Xri */
  2319. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  2320. *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
  2321. pcmd += sizeof(uint32_t);
  2322. *((uint32_t *) (pcmd)) = rejectError;
  2323. if (mbox)
  2324. elsiocb->context_un.mbox = mbox;
  2325. /* Xmit ELS RJT <err> response tag <ulpIoTag> */
  2326. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  2327. "0129 Xmit ELS RJT x%x response tag x%x "
  2328. "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
  2329. "rpi x%x\n",
  2330. rejectError, elsiocb->iotag,
  2331. elsiocb->iocb.ulpContext, ndlp->nlp_DID,
  2332. ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
  2333. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
  2334. "Issue LS_RJT: did:x%x flg:x%x err:x%x",
  2335. ndlp->nlp_DID, ndlp->nlp_flag, rejectError);
  2336. phba->fc_stat.elsXmitLSRJT++;
  2337. elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
  2338. rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
  2339. if (rc == IOCB_ERROR) {
  2340. lpfc_els_free_iocb(phba, elsiocb);
  2341. return 1;
  2342. }
  2343. return 0;
  2344. }
  2345. int
  2346. lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
  2347. struct lpfc_nodelist *ndlp)
  2348. {
  2349. struct lpfc_hba *phba = vport->phba;
  2350. struct lpfc_sli *psli = &phba->sli;
  2351. struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
  2352. ADISC *ap;
  2353. IOCB_t *icmd, *oldcmd;
  2354. struct lpfc_iocbq *elsiocb;
  2355. uint8_t *pcmd;
  2356. uint16_t cmdsize;
  2357. int rc;
  2358. cmdsize = sizeof(uint32_t) + sizeof(ADISC);
  2359. elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
  2360. ndlp->nlp_DID, ELS_CMD_ACC);
  2361. if (!elsiocb)
  2362. return 1;
  2363. icmd = &elsiocb->iocb;
  2364. oldcmd = &oldiocb->iocb;
  2365. icmd->ulpContext = oldcmd->ulpContext; /* Xri */
  2366. /* Xmit ADISC ACC response tag <ulpIoTag> */
  2367. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  2368. "0130 Xmit ADISC ACC response iotag x%x xri: "
  2369. "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n",
  2370. elsiocb->iotag, elsiocb->iocb.ulpContext,
  2371. ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
  2372. ndlp->nlp_rpi);
  2373. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  2374. *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
  2375. pcmd += sizeof(uint32_t);
  2376. ap = (ADISC *) (pcmd);
  2377. ap->hardAL_PA = phba->fc_pref_ALPA;
  2378. memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
  2379. memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
  2380. ap->DID = be32_to_cpu(vport->fc_myDID);
  2381. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
  2382. "Issue ACC ADISC: did:x%x flg:x%x",
  2383. ndlp->nlp_DID, ndlp->nlp_flag, 0);
  2384. phba->fc_stat.elsXmitACC++;
  2385. elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
  2386. rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
  2387. if (rc == IOCB_ERROR) {
  2388. lpfc_els_free_iocb(phba, elsiocb);
  2389. return 1;
  2390. }
  2391. return 0;
  2392. }
  2393. int
  2394. lpfc_els_rsp_prli_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
  2395. struct lpfc_nodelist *ndlp)
  2396. {
  2397. struct lpfc_hba *phba = vport->phba;
  2398. PRLI *npr;
  2399. lpfc_vpd_t *vpd;
  2400. IOCB_t *icmd;
  2401. IOCB_t *oldcmd;
  2402. struct lpfc_iocbq *elsiocb;
  2403. struct lpfc_sli_ring *pring;
  2404. struct lpfc_sli *psli;
  2405. uint8_t *pcmd;
  2406. uint16_t cmdsize;
  2407. int rc;
  2408. psli = &phba->sli;
  2409. pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
  2410. cmdsize = sizeof(uint32_t) + sizeof(PRLI);
  2411. elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
  2412. ndlp->nlp_DID, (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK)));
  2413. if (!elsiocb)
  2414. return 1;
  2415. icmd = &elsiocb->iocb;
  2416. oldcmd = &oldiocb->iocb;
  2417. icmd->ulpContext = oldcmd->ulpContext; /* Xri */
  2418. /* Xmit PRLI ACC response tag <ulpIoTag> */
  2419. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  2420. "0131 Xmit PRLI ACC response tag x%x xri x%x, "
  2421. "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
  2422. elsiocb->iotag, elsiocb->iocb.ulpContext,
  2423. ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
  2424. ndlp->nlp_rpi);
  2425. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  2426. *((uint32_t *) (pcmd)) = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK));
  2427. pcmd += sizeof(uint32_t);
  2428. /* For PRLI, remainder of payload is PRLI parameter page */
  2429. memset(pcmd, 0, sizeof(PRLI));
  2430. npr = (PRLI *) pcmd;
  2431. vpd = &phba->vpd;
  2432. /*
  2433. * If our firmware version is 3.20 or later,
  2434. * set the following bits for FC-TAPE support.
  2435. */
  2436. if (vpd->rev.feaLevelHigh >= 0x02) {
  2437. npr->ConfmComplAllowed = 1;
  2438. npr->Retry = 1;
  2439. npr->TaskRetryIdReq = 1;
  2440. }
  2441. npr->acceptRspCode = PRLI_REQ_EXECUTED;
  2442. npr->estabImagePair = 1;
  2443. npr->readXferRdyDis = 1;
  2444. npr->ConfmComplAllowed = 1;
  2445. npr->prliType = PRLI_FCP_TYPE;
  2446. npr->initiatorFunc = 1;
  2447. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
  2448. "Issue ACC PRLI: did:x%x flg:x%x",
  2449. ndlp->nlp_DID, ndlp->nlp_flag, 0);
  2450. phba->fc_stat.elsXmitACC++;
  2451. elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
  2452. rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
  2453. if (rc == IOCB_ERROR) {
  2454. lpfc_els_free_iocb(phba, elsiocb);
  2455. return 1;
  2456. }
  2457. return 0;
  2458. }
  2459. static int
  2460. lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format,
  2461. struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
  2462. {
  2463. struct lpfc_hba *phba = vport->phba;
  2464. RNID *rn;
  2465. IOCB_t *icmd, *oldcmd;
  2466. struct lpfc_iocbq *elsiocb;
  2467. struct lpfc_sli_ring *pring;
  2468. struct lpfc_sli *psli;
  2469. uint8_t *pcmd;
  2470. uint16_t cmdsize;
  2471. int rc;
  2472. psli = &phba->sli;
  2473. pring = &psli->ring[LPFC_ELS_RING];
  2474. cmdsize = sizeof(uint32_t) + sizeof(uint32_t)
  2475. + (2 * sizeof(struct lpfc_name));
  2476. if (format)
  2477. cmdsize += sizeof(RNID_TOP_DISC);
  2478. elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
  2479. ndlp->nlp_DID, ELS_CMD_ACC);
  2480. if (!elsiocb)
  2481. return 1;
  2482. icmd = &elsiocb->iocb;
  2483. oldcmd = &oldiocb->iocb;
  2484. icmd->ulpContext = oldcmd->ulpContext; /* Xri */
  2485. /* Xmit RNID ACC response tag <ulpIoTag> */
  2486. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  2487. "0132 Xmit RNID ACC response tag x%x xri x%x\n",
  2488. elsiocb->iotag, elsiocb->iocb.ulpContext);
  2489. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  2490. *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
  2491. pcmd += sizeof(uint32_t);
  2492. memset(pcmd, 0, sizeof(RNID));
  2493. rn = (RNID *) (pcmd);
  2494. rn->Format = format;
  2495. rn->CommonLen = (2 * sizeof(struct lpfc_name));
  2496. memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name));
  2497. memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
  2498. switch (format) {
  2499. case 0:
  2500. rn->SpecificLen = 0;
  2501. break;
  2502. case RNID_TOPOLOGY_DISC:
  2503. rn->SpecificLen = sizeof(RNID_TOP_DISC);
  2504. memcpy(&rn->un.topologyDisc.portName,
  2505. &vport->fc_portname, sizeof(struct lpfc_name));
  2506. rn->un.topologyDisc.unitType = RNID_HBA;
  2507. rn->un.topologyDisc.physPort = 0;
  2508. rn->un.topologyDisc.attachedNodes = 0;
  2509. break;
  2510. default:
  2511. rn->CommonLen = 0;
  2512. rn->SpecificLen = 0;
  2513. break;
  2514. }
  2515. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
  2516. "Issue ACC RNID: did:x%x flg:x%x",
  2517. ndlp->nlp_DID, ndlp->nlp_flag, 0);
  2518. phba->fc_stat.elsXmitACC++;
  2519. elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
  2520. lpfc_nlp_put(ndlp);
  2521. elsiocb->context1 = NULL; /* Don't need ndlp for cmpl,
  2522. * it could be freed */
  2523. rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
  2524. if (rc == IOCB_ERROR) {
  2525. lpfc_els_free_iocb(phba, elsiocb);
  2526. return 1;
  2527. }
  2528. return 0;
  2529. }
  2530. int
  2531. lpfc_els_disc_adisc(struct lpfc_vport *vport)
  2532. {
  2533. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2534. struct lpfc_nodelist *ndlp, *next_ndlp;
  2535. int sentadisc = 0;
  2536. /* go thru NPR nodes and issue any remaining ELS ADISCs */
  2537. list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
  2538. if (!NLP_CHK_NODE_ACT(ndlp))
  2539. continue;
  2540. if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
  2541. (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
  2542. (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) {
  2543. spin_lock_irq(shost->host_lock);
  2544. ndlp->nlp_flag &= ~NLP_NPR_ADISC;
  2545. spin_unlock_irq(shost->host_lock);
  2546. ndlp->nlp_prev_state = ndlp->nlp_state;
  2547. lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
  2548. lpfc_issue_els_adisc(vport, ndlp, 0);
  2549. sentadisc++;
  2550. vport->num_disc_nodes++;
  2551. if (vport->num_disc_nodes >=
  2552. vport->cfg_discovery_threads) {
  2553. spin_lock_irq(shost->host_lock);
  2554. vport->fc_flag |= FC_NLP_MORE;
  2555. spin_unlock_irq(shost->host_lock);
  2556. break;
  2557. }
  2558. }
  2559. }
  2560. if (sentadisc == 0) {
  2561. spin_lock_irq(shost->host_lock);
  2562. vport->fc_flag &= ~FC_NLP_MORE;
  2563. spin_unlock_irq(shost->host_lock);
  2564. }
  2565. return sentadisc;
  2566. }
  2567. int
  2568. lpfc_els_disc_plogi(struct lpfc_vport *vport)
  2569. {
  2570. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2571. struct lpfc_nodelist *ndlp, *next_ndlp;
  2572. int sentplogi = 0;
  2573. /* go thru NPR nodes and issue any remaining ELS PLOGIs */
  2574. list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
  2575. if (!NLP_CHK_NODE_ACT(ndlp))
  2576. continue;
  2577. if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
  2578. (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
  2579. (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 &&
  2580. (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) {
  2581. ndlp->nlp_prev_state = ndlp->nlp_state;
  2582. lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
  2583. lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
  2584. sentplogi++;
  2585. vport->num_disc_nodes++;
  2586. if (vport->num_disc_nodes >=
  2587. vport->cfg_discovery_threads) {
  2588. spin_lock_irq(shost->host_lock);
  2589. vport->fc_flag |= FC_NLP_MORE;
  2590. spin_unlock_irq(shost->host_lock);
  2591. break;
  2592. }
  2593. }
  2594. }
  2595. if (sentplogi) {
  2596. lpfc_set_disctmo(vport);
  2597. }
  2598. else {
  2599. spin_lock_irq(shost->host_lock);
  2600. vport->fc_flag &= ~FC_NLP_MORE;
  2601. spin_unlock_irq(shost->host_lock);
  2602. }
  2603. return sentplogi;
  2604. }
  2605. void
  2606. lpfc_els_flush_rscn(struct lpfc_vport *vport)
  2607. {
  2608. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2609. struct lpfc_hba *phba = vport->phba;
  2610. int i;
  2611. spin_lock_irq(shost->host_lock);
  2612. if (vport->fc_rscn_flush) {
  2613. /* Another thread is walking fc_rscn_id_list on this vport */
  2614. spin_unlock_irq(shost->host_lock);
  2615. return;
  2616. }
  2617. /* Indicate we are walking lpfc_els_flush_rscn on this vport */
  2618. vport->fc_rscn_flush = 1;
  2619. spin_unlock_irq(shost->host_lock);
  2620. for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
  2621. lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]);
  2622. vport->fc_rscn_id_list[i] = NULL;
  2623. }
  2624. spin_lock_irq(shost->host_lock);
  2625. vport->fc_rscn_id_cnt = 0;
  2626. vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY);
  2627. spin_unlock_irq(shost->host_lock);
  2628. lpfc_can_disctmo(vport);
  2629. /* Indicate we are done walking this fc_rscn_id_list */
  2630. vport->fc_rscn_flush = 0;
  2631. }
  2632. int
  2633. lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did)
  2634. {
  2635. D_ID ns_did;
  2636. D_ID rscn_did;
  2637. uint32_t *lp;
  2638. uint32_t payload_len, i;
  2639. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2640. ns_did.un.word = did;
  2641. /* Never match fabric nodes for RSCNs */
  2642. if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
  2643. return 0;
  2644. /* If we are doing a FULL RSCN rediscovery, match everything */
  2645. if (vport->fc_flag & FC_RSCN_DISCOVERY)
  2646. return did;
  2647. spin_lock_irq(shost->host_lock);
  2648. if (vport->fc_rscn_flush) {
  2649. /* Another thread is walking fc_rscn_id_list on this vport */
  2650. spin_unlock_irq(shost->host_lock);
  2651. return 0;
  2652. }
  2653. /* Indicate we are walking fc_rscn_id_list on this vport */
  2654. vport->fc_rscn_flush = 1;
  2655. spin_unlock_irq(shost->host_lock);
  2656. for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
  2657. lp = vport->fc_rscn_id_list[i]->virt;
  2658. payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
  2659. payload_len -= sizeof(uint32_t); /* take off word 0 */
  2660. while (payload_len) {
  2661. rscn_did.un.word = be32_to_cpu(*lp++);
  2662. payload_len -= sizeof(uint32_t);
  2663. switch (rscn_did.un.b.resv) {
  2664. case 0: /* Single N_Port ID effected */
  2665. if (ns_did.un.word == rscn_did.un.word)
  2666. goto return_did_out;
  2667. break;
  2668. case 1: /* Whole N_Port Area effected */
  2669. if ((ns_did.un.b.domain == rscn_did.un.b.domain)
  2670. && (ns_did.un.b.area == rscn_did.un.b.area))
  2671. goto return_did_out;
  2672. break;
  2673. case 2: /* Whole N_Port Domain effected */
  2674. if (ns_did.un.b.domain == rscn_did.un.b.domain)
  2675. goto return_did_out;
  2676. break;
  2677. default:
  2678. /* Unknown Identifier in RSCN node */
  2679. lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
  2680. "0217 Unknown Identifier in "
  2681. "RSCN payload Data: x%x\n",
  2682. rscn_did.un.word);
  2683. case 3: /* Whole Fabric effected */
  2684. goto return_did_out;
  2685. }
  2686. }
  2687. }
  2688. /* Indicate we are done with walking fc_rscn_id_list on this vport */
  2689. vport->fc_rscn_flush = 0;
  2690. return 0;
  2691. return_did_out:
  2692. /* Indicate we are done with walking fc_rscn_id_list on this vport */
  2693. vport->fc_rscn_flush = 0;
  2694. return did;
  2695. }
  2696. static int
  2697. lpfc_rscn_recovery_check(struct lpfc_vport *vport)
  2698. {
  2699. struct lpfc_nodelist *ndlp = NULL;
  2700. /* Look at all nodes effected by pending RSCNs and move
  2701. * them to NPR state.
  2702. */
  2703. list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
  2704. if (!NLP_CHK_NODE_ACT(ndlp) ||
  2705. ndlp->nlp_state == NLP_STE_UNUSED_NODE ||
  2706. lpfc_rscn_payload_check(vport, ndlp->nlp_DID) == 0)
  2707. continue;
  2708. lpfc_disc_state_machine(vport, ndlp, NULL,
  2709. NLP_EVT_DEVICE_RECOVERY);
  2710. /*
  2711. * Make sure NLP_DELAY_TMO is NOT running after a device
  2712. * recovery event.
  2713. */
  2714. if (ndlp->nlp_flag & NLP_DELAY_TMO)
  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_dmabuf *pcmd;
  3344. uint32_t *lp;
  3345. IOCB_t *icmd;
  3346. uint32_t cmd, did;
  3347. FAN *fp;
  3348. struct lpfc_nodelist *ndlp, *next_ndlp;
  3349. struct lpfc_hba *phba = vport->phba;
  3350. /* FAN received */
  3351. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  3352. "0265 FAN received\n");
  3353. icmd = &cmdiocb->iocb;
  3354. did = icmd->un.elsreq64.remoteID;
  3355. pcmd = (struct lpfc_dmabuf *)cmdiocb->context2;
  3356. lp = (uint32_t *)pcmd->virt;
  3357. cmd = *lp++;
  3358. fp = (FAN *) lp;
  3359. /* FAN received; Fan does not have a reply sequence */
  3360. if (phba->pport->port_state == LPFC_LOCAL_CFG_LINK) {
  3361. if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName,
  3362. sizeof(struct lpfc_name)) != 0) ||
  3363. (memcmp(&phba->fc_fabparam.portName, &fp->FportName,
  3364. sizeof(struct lpfc_name)) != 0)) {
  3365. /*
  3366. * This node has switched fabrics. FLOGI is required
  3367. * Clean up the old rpi's
  3368. */
  3369. list_for_each_entry_safe(ndlp, next_ndlp,
  3370. &vport->fc_nodes, nlp_listp) {
  3371. if (!NLP_CHK_NODE_ACT(ndlp))
  3372. continue;
  3373. if (ndlp->nlp_state != NLP_STE_NPR_NODE)
  3374. continue;
  3375. if (ndlp->nlp_type & NLP_FABRIC) {
  3376. /*
  3377. * Clean up old Fabric, Nameserver and
  3378. * other NLP_FABRIC logins
  3379. */
  3380. lpfc_drop_node(vport, ndlp);
  3381. } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
  3382. /* Fail outstanding I/O now since this
  3383. * device is marked for PLOGI
  3384. */
  3385. lpfc_unreg_rpi(vport, ndlp);
  3386. }
  3387. }
  3388. lpfc_initial_flogi(vport);
  3389. return 0;
  3390. }
  3391. /* Discovery not needed,
  3392. * move the nodes to their original state.
  3393. */
  3394. list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes,
  3395. nlp_listp) {
  3396. if (!NLP_CHK_NODE_ACT(ndlp))
  3397. continue;
  3398. if (ndlp->nlp_state != NLP_STE_NPR_NODE)
  3399. continue;
  3400. switch (ndlp->nlp_prev_state) {
  3401. case NLP_STE_UNMAPPED_NODE:
  3402. ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
  3403. lpfc_nlp_set_state(vport, ndlp,
  3404. NLP_STE_UNMAPPED_NODE);
  3405. break;
  3406. case NLP_STE_MAPPED_NODE:
  3407. ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
  3408. lpfc_nlp_set_state(vport, ndlp,
  3409. NLP_STE_MAPPED_NODE);
  3410. break;
  3411. default:
  3412. break;
  3413. }
  3414. }
  3415. /* Start discovery - this should just do CLEAR_LA */
  3416. lpfc_disc_start(vport);
  3417. }
  3418. return 0;
  3419. }
  3420. void
  3421. lpfc_els_timeout(unsigned long ptr)
  3422. {
  3423. struct lpfc_vport *vport = (struct lpfc_vport *) ptr;
  3424. struct lpfc_hba *phba = vport->phba;
  3425. unsigned long iflag;
  3426. spin_lock_irqsave(&vport->work_port_lock, iflag);
  3427. if ((vport->work_port_events & WORKER_ELS_TMO) == 0) {
  3428. vport->work_port_events |= WORKER_ELS_TMO;
  3429. spin_unlock_irqrestore(&vport->work_port_lock, iflag);
  3430. spin_lock_irqsave(&phba->hbalock, iflag);
  3431. if (phba->work_wait)
  3432. lpfc_worker_wake_up(phba);
  3433. spin_unlock_irqrestore(&phba->hbalock, iflag);
  3434. }
  3435. else
  3436. spin_unlock_irqrestore(&vport->work_port_lock, iflag);
  3437. return;
  3438. }
  3439. void
  3440. lpfc_els_timeout_handler(struct lpfc_vport *vport)
  3441. {
  3442. struct lpfc_hba *phba = vport->phba;
  3443. struct lpfc_sli_ring *pring;
  3444. struct lpfc_iocbq *tmp_iocb, *piocb;
  3445. IOCB_t *cmd = NULL;
  3446. struct lpfc_dmabuf *pcmd;
  3447. uint32_t els_command = 0;
  3448. uint32_t timeout;
  3449. uint32_t remote_ID = 0xffffffff;
  3450. /* If the timer is already canceled do nothing */
  3451. if ((vport->work_port_events & WORKER_ELS_TMO) == 0) {
  3452. return;
  3453. }
  3454. spin_lock_irq(&phba->hbalock);
  3455. timeout = (uint32_t)(phba->fc_ratov << 1);
  3456. pring = &phba->sli.ring[LPFC_ELS_RING];
  3457. list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
  3458. cmd = &piocb->iocb;
  3459. if ((piocb->iocb_flag & LPFC_IO_LIBDFC) != 0 ||
  3460. piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
  3461. piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
  3462. continue;
  3463. if (piocb->vport != vport)
  3464. continue;
  3465. pcmd = (struct lpfc_dmabuf *) piocb->context2;
  3466. if (pcmd)
  3467. els_command = *(uint32_t *) (pcmd->virt);
  3468. if (els_command == ELS_CMD_FARP ||
  3469. els_command == ELS_CMD_FARPR ||
  3470. els_command == ELS_CMD_FDISC)
  3471. continue;
  3472. if (vport != piocb->vport)
  3473. continue;
  3474. if (piocb->drvrTimeout > 0) {
  3475. if (piocb->drvrTimeout >= timeout)
  3476. piocb->drvrTimeout -= timeout;
  3477. else
  3478. piocb->drvrTimeout = 0;
  3479. continue;
  3480. }
  3481. remote_ID = 0xffffffff;
  3482. if (cmd->ulpCommand != CMD_GEN_REQUEST64_CR)
  3483. remote_ID = cmd->un.elsreq64.remoteID;
  3484. else {
  3485. struct lpfc_nodelist *ndlp;
  3486. ndlp = __lpfc_findnode_rpi(vport, cmd->ulpContext);
  3487. if (ndlp && NLP_CHK_NODE_ACT(ndlp))
  3488. remote_ID = ndlp->nlp_DID;
  3489. }
  3490. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  3491. "0127 ELS timeout Data: x%x x%x x%x "
  3492. "x%x\n", els_command,
  3493. remote_ID, cmd->ulpCommand, cmd->ulpIoTag);
  3494. lpfc_sli_issue_abort_iotag(phba, pring, piocb);
  3495. }
  3496. spin_unlock_irq(&phba->hbalock);
  3497. if (phba->sli.ring[LPFC_ELS_RING].txcmplq_cnt)
  3498. mod_timer(&vport->els_tmofunc, jiffies + HZ * timeout);
  3499. }
  3500. void
  3501. lpfc_els_flush_cmd(struct lpfc_vport *vport)
  3502. {
  3503. LIST_HEAD(completions);
  3504. struct lpfc_hba *phba = vport->phba;
  3505. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  3506. struct lpfc_iocbq *tmp_iocb, *piocb;
  3507. IOCB_t *cmd = NULL;
  3508. lpfc_fabric_abort_vport(vport);
  3509. spin_lock_irq(&phba->hbalock);
  3510. list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
  3511. cmd = &piocb->iocb;
  3512. if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
  3513. continue;
  3514. }
  3515. /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
  3516. if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
  3517. cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
  3518. cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
  3519. cmd->ulpCommand == CMD_ABORT_XRI_CN)
  3520. continue;
  3521. if (piocb->vport != vport)
  3522. continue;
  3523. list_move_tail(&piocb->list, &completions);
  3524. pring->txq_cnt--;
  3525. }
  3526. list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
  3527. if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
  3528. continue;
  3529. }
  3530. if (piocb->vport != vport)
  3531. continue;
  3532. lpfc_sli_issue_abort_iotag(phba, pring, piocb);
  3533. }
  3534. spin_unlock_irq(&phba->hbalock);
  3535. while (!list_empty(&completions)) {
  3536. piocb = list_get_first(&completions, struct lpfc_iocbq, list);
  3537. cmd = &piocb->iocb;
  3538. list_del_init(&piocb->list);
  3539. if (!piocb->iocb_cmpl)
  3540. lpfc_sli_release_iocbq(phba, piocb);
  3541. else {
  3542. cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
  3543. cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
  3544. (piocb->iocb_cmpl) (phba, piocb, piocb);
  3545. }
  3546. }
  3547. return;
  3548. }
  3549. void
  3550. lpfc_els_flush_all_cmd(struct lpfc_hba *phba)
  3551. {
  3552. LIST_HEAD(completions);
  3553. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  3554. struct lpfc_iocbq *tmp_iocb, *piocb;
  3555. IOCB_t *cmd = NULL;
  3556. lpfc_fabric_abort_hba(phba);
  3557. spin_lock_irq(&phba->hbalock);
  3558. list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
  3559. cmd = &piocb->iocb;
  3560. if (piocb->iocb_flag & LPFC_IO_LIBDFC)
  3561. continue;
  3562. /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
  3563. if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
  3564. cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
  3565. cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
  3566. cmd->ulpCommand == CMD_ABORT_XRI_CN)
  3567. continue;
  3568. list_move_tail(&piocb->list, &completions);
  3569. pring->txq_cnt--;
  3570. }
  3571. list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
  3572. if (piocb->iocb_flag & LPFC_IO_LIBDFC)
  3573. continue;
  3574. lpfc_sli_issue_abort_iotag(phba, pring, piocb);
  3575. }
  3576. spin_unlock_irq(&phba->hbalock);
  3577. while (!list_empty(&completions)) {
  3578. piocb = list_get_first(&completions, struct lpfc_iocbq, list);
  3579. cmd = &piocb->iocb;
  3580. list_del_init(&piocb->list);
  3581. if (!piocb->iocb_cmpl)
  3582. lpfc_sli_release_iocbq(phba, piocb);
  3583. else {
  3584. cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
  3585. cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
  3586. (piocb->iocb_cmpl) (phba, piocb, piocb);
  3587. }
  3588. }
  3589. return;
  3590. }
  3591. static void
  3592. lpfc_els_unsol_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  3593. struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb)
  3594. {
  3595. struct Scsi_Host *shost;
  3596. struct lpfc_nodelist *ndlp;
  3597. struct ls_rjt stat;
  3598. uint32_t *payload;
  3599. uint32_t cmd, did, newnode, rjt_err = 0;
  3600. IOCB_t *icmd = &elsiocb->iocb;
  3601. if (!vport || !(elsiocb->context2))
  3602. goto dropit;
  3603. newnode = 0;
  3604. payload = ((struct lpfc_dmabuf *)elsiocb->context2)->virt;
  3605. cmd = *payload;
  3606. if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0)
  3607. lpfc_post_buffer(phba, pring, 1, 1);
  3608. did = icmd->un.rcvels.remoteID;
  3609. if (icmd->ulpStatus) {
  3610. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  3611. "RCV Unsol ELS: status:x%x/x%x did:x%x",
  3612. icmd->ulpStatus, icmd->un.ulpWord[4], did);
  3613. goto dropit;
  3614. }
  3615. /* Check to see if link went down during discovery */
  3616. if (lpfc_els_chk_latt(vport))
  3617. goto dropit;
  3618. /* Ignore traffic recevied during vport shutdown. */
  3619. if (vport->load_flag & FC_UNLOADING)
  3620. goto dropit;
  3621. ndlp = lpfc_findnode_did(vport, did);
  3622. if (!ndlp) {
  3623. /* Cannot find existing Fabric ndlp, so allocate a new one */
  3624. ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
  3625. if (!ndlp)
  3626. goto dropit;
  3627. lpfc_nlp_init(vport, ndlp, did);
  3628. lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
  3629. newnode = 1;
  3630. if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
  3631. ndlp->nlp_type |= NLP_FABRIC;
  3632. } else if (!NLP_CHK_NODE_ACT(ndlp)) {
  3633. ndlp = lpfc_enable_node(vport, ndlp,
  3634. NLP_STE_UNUSED_NODE);
  3635. if (!ndlp)
  3636. goto dropit;
  3637. lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
  3638. newnode = 1;
  3639. if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
  3640. ndlp->nlp_type |= NLP_FABRIC;
  3641. } else if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
  3642. /* This is similar to the new node path */
  3643. ndlp = lpfc_nlp_get(ndlp);
  3644. if (!ndlp)
  3645. goto dropit;
  3646. lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
  3647. newnode = 1;
  3648. }
  3649. phba->fc_stat.elsRcvFrame++;
  3650. if (elsiocb->context1)
  3651. lpfc_nlp_put(elsiocb->context1);
  3652. elsiocb->context1 = lpfc_nlp_get(ndlp);
  3653. elsiocb->vport = vport;
  3654. if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) {
  3655. cmd &= ELS_CMD_MASK;
  3656. }
  3657. /* ELS command <elsCmd> received from NPORT <did> */
  3658. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  3659. "0112 ELS command x%x received from NPORT x%x "
  3660. "Data: x%x\n", cmd, did, vport->port_state);
  3661. switch (cmd) {
  3662. case ELS_CMD_PLOGI:
  3663. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  3664. "RCV PLOGI: did:x%x/ste:x%x flg:x%x",
  3665. did, vport->port_state, ndlp->nlp_flag);
  3666. phba->fc_stat.elsRcvPLOGI++;
  3667. ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp);
  3668. if (vport->port_state < LPFC_DISC_AUTH) {
  3669. if (!(phba->pport->fc_flag & FC_PT2PT) ||
  3670. (phba->pport->fc_flag & FC_PT2PT_PLOGI)) {
  3671. rjt_err = LSRJT_UNABLE_TPC;
  3672. break;
  3673. }
  3674. /* We get here, and drop thru, if we are PT2PT with
  3675. * another NPort and the other side has initiated
  3676. * the PLOGI before responding to our FLOGI.
  3677. */
  3678. }
  3679. shost = lpfc_shost_from_vport(vport);
  3680. spin_lock_irq(shost->host_lock);
  3681. ndlp->nlp_flag &= ~NLP_TARGET_REMOVE;
  3682. spin_unlock_irq(shost->host_lock);
  3683. lpfc_disc_state_machine(vport, ndlp, elsiocb,
  3684. NLP_EVT_RCV_PLOGI);
  3685. break;
  3686. case ELS_CMD_FLOGI:
  3687. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  3688. "RCV FLOGI: did:x%x/ste:x%x flg:x%x",
  3689. did, vport->port_state, ndlp->nlp_flag);
  3690. phba->fc_stat.elsRcvFLOGI++;
  3691. lpfc_els_rcv_flogi(vport, elsiocb, ndlp);
  3692. if (newnode)
  3693. lpfc_nlp_put(ndlp);
  3694. break;
  3695. case ELS_CMD_LOGO:
  3696. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  3697. "RCV LOGO: did:x%x/ste:x%x flg:x%x",
  3698. did, vport->port_state, ndlp->nlp_flag);
  3699. phba->fc_stat.elsRcvLOGO++;
  3700. if (vport->port_state < LPFC_DISC_AUTH) {
  3701. rjt_err = LSRJT_UNABLE_TPC;
  3702. break;
  3703. }
  3704. lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO);
  3705. break;
  3706. case ELS_CMD_PRLO:
  3707. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  3708. "RCV PRLO: did:x%x/ste:x%x flg:x%x",
  3709. did, vport->port_state, ndlp->nlp_flag);
  3710. phba->fc_stat.elsRcvPRLO++;
  3711. if (vport->port_state < LPFC_DISC_AUTH) {
  3712. rjt_err = LSRJT_UNABLE_TPC;
  3713. break;
  3714. }
  3715. lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO);
  3716. break;
  3717. case ELS_CMD_RSCN:
  3718. phba->fc_stat.elsRcvRSCN++;
  3719. lpfc_els_rcv_rscn(vport, elsiocb, ndlp);
  3720. if (newnode)
  3721. lpfc_nlp_put(ndlp);
  3722. break;
  3723. case ELS_CMD_ADISC:
  3724. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  3725. "RCV ADISC: did:x%x/ste:x%x flg:x%x",
  3726. did, vport->port_state, ndlp->nlp_flag);
  3727. phba->fc_stat.elsRcvADISC++;
  3728. if (vport->port_state < LPFC_DISC_AUTH) {
  3729. rjt_err = LSRJT_UNABLE_TPC;
  3730. break;
  3731. }
  3732. lpfc_disc_state_machine(vport, ndlp, elsiocb,
  3733. NLP_EVT_RCV_ADISC);
  3734. break;
  3735. case ELS_CMD_PDISC:
  3736. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  3737. "RCV PDISC: did:x%x/ste:x%x flg:x%x",
  3738. did, vport->port_state, ndlp->nlp_flag);
  3739. phba->fc_stat.elsRcvPDISC++;
  3740. if (vport->port_state < LPFC_DISC_AUTH) {
  3741. rjt_err = LSRJT_UNABLE_TPC;
  3742. break;
  3743. }
  3744. lpfc_disc_state_machine(vport, ndlp, elsiocb,
  3745. NLP_EVT_RCV_PDISC);
  3746. break;
  3747. case ELS_CMD_FARPR:
  3748. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  3749. "RCV FARPR: did:x%x/ste:x%x flg:x%x",
  3750. did, vport->port_state, ndlp->nlp_flag);
  3751. phba->fc_stat.elsRcvFARPR++;
  3752. lpfc_els_rcv_farpr(vport, elsiocb, ndlp);
  3753. break;
  3754. case ELS_CMD_FARP:
  3755. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  3756. "RCV FARP: did:x%x/ste:x%x flg:x%x",
  3757. did, vport->port_state, ndlp->nlp_flag);
  3758. phba->fc_stat.elsRcvFARP++;
  3759. lpfc_els_rcv_farp(vport, elsiocb, ndlp);
  3760. break;
  3761. case ELS_CMD_FAN:
  3762. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  3763. "RCV FAN: did:x%x/ste:x%x flg:x%x",
  3764. did, vport->port_state, ndlp->nlp_flag);
  3765. phba->fc_stat.elsRcvFAN++;
  3766. lpfc_els_rcv_fan(vport, elsiocb, ndlp);
  3767. break;
  3768. case ELS_CMD_PRLI:
  3769. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  3770. "RCV PRLI: did:x%x/ste:x%x flg:x%x",
  3771. did, vport->port_state, ndlp->nlp_flag);
  3772. phba->fc_stat.elsRcvPRLI++;
  3773. if (vport->port_state < LPFC_DISC_AUTH) {
  3774. rjt_err = LSRJT_UNABLE_TPC;
  3775. break;
  3776. }
  3777. lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI);
  3778. break;
  3779. case ELS_CMD_LIRR:
  3780. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  3781. "RCV LIRR: did:x%x/ste:x%x flg:x%x",
  3782. did, vport->port_state, ndlp->nlp_flag);
  3783. phba->fc_stat.elsRcvLIRR++;
  3784. lpfc_els_rcv_lirr(vport, elsiocb, ndlp);
  3785. if (newnode)
  3786. lpfc_nlp_put(ndlp);
  3787. break;
  3788. case ELS_CMD_RPS:
  3789. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  3790. "RCV RPS: did:x%x/ste:x%x flg:x%x",
  3791. did, vport->port_state, ndlp->nlp_flag);
  3792. phba->fc_stat.elsRcvRPS++;
  3793. lpfc_els_rcv_rps(vport, elsiocb, ndlp);
  3794. if (newnode)
  3795. lpfc_nlp_put(ndlp);
  3796. break;
  3797. case ELS_CMD_RPL:
  3798. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  3799. "RCV RPL: did:x%x/ste:x%x flg:x%x",
  3800. did, vport->port_state, ndlp->nlp_flag);
  3801. phba->fc_stat.elsRcvRPL++;
  3802. lpfc_els_rcv_rpl(vport, elsiocb, ndlp);
  3803. if (newnode)
  3804. lpfc_nlp_put(ndlp);
  3805. break;
  3806. case ELS_CMD_RNID:
  3807. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  3808. "RCV RNID: did:x%x/ste:x%x flg:x%x",
  3809. did, vport->port_state, ndlp->nlp_flag);
  3810. phba->fc_stat.elsRcvRNID++;
  3811. lpfc_els_rcv_rnid(vport, elsiocb, ndlp);
  3812. if (newnode)
  3813. lpfc_nlp_put(ndlp);
  3814. break;
  3815. default:
  3816. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  3817. "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x",
  3818. cmd, did, vport->port_state);
  3819. /* Unsupported ELS command, reject */
  3820. rjt_err = LSRJT_INVALID_CMD;
  3821. /* Unknown ELS command <elsCmd> received from NPORT <did> */
  3822. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  3823. "0115 Unknown ELS command x%x "
  3824. "received from NPORT x%x\n", cmd, did);
  3825. if (newnode)
  3826. lpfc_nlp_put(ndlp);
  3827. break;
  3828. }
  3829. /* check if need to LS_RJT received ELS cmd */
  3830. if (rjt_err) {
  3831. memset(&stat, 0, sizeof(stat));
  3832. stat.un.b.lsRjtRsnCode = rjt_err;
  3833. stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
  3834. lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp,
  3835. NULL);
  3836. }
  3837. return;
  3838. dropit:
  3839. if (vport && !(vport->load_flag & FC_UNLOADING))
  3840. lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
  3841. "(%d):0111 Dropping received ELS cmd "
  3842. "Data: x%x x%x x%x\n",
  3843. vport->vpi, icmd->ulpStatus,
  3844. icmd->un.ulpWord[4], icmd->ulpTimeout);
  3845. phba->fc_stat.elsRcvDrop++;
  3846. }
  3847. static struct lpfc_vport *
  3848. lpfc_find_vport_by_vpid(struct lpfc_hba *phba, uint16_t vpi)
  3849. {
  3850. struct lpfc_vport *vport;
  3851. unsigned long flags;
  3852. spin_lock_irqsave(&phba->hbalock, flags);
  3853. list_for_each_entry(vport, &phba->port_list, listentry) {
  3854. if (vport->vpi == vpi) {
  3855. spin_unlock_irqrestore(&phba->hbalock, flags);
  3856. return vport;
  3857. }
  3858. }
  3859. spin_unlock_irqrestore(&phba->hbalock, flags);
  3860. return NULL;
  3861. }
  3862. void
  3863. lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  3864. struct lpfc_iocbq *elsiocb)
  3865. {
  3866. struct lpfc_vport *vport = phba->pport;
  3867. IOCB_t *icmd = &elsiocb->iocb;
  3868. dma_addr_t paddr;
  3869. struct lpfc_dmabuf *bdeBuf1 = elsiocb->context2;
  3870. struct lpfc_dmabuf *bdeBuf2 = elsiocb->context3;
  3871. elsiocb->context2 = NULL;
  3872. elsiocb->context3 = NULL;
  3873. if (icmd->ulpStatus == IOSTAT_NEED_BUFFER) {
  3874. lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
  3875. } else if (icmd->ulpStatus == IOSTAT_LOCAL_REJECT &&
  3876. (icmd->un.ulpWord[4] & 0xff) == IOERR_RCV_BUFFER_WAITING) {
  3877. phba->fc_stat.NoRcvBuf++;
  3878. /* Not enough posted buffers; Try posting more buffers */
  3879. if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
  3880. lpfc_post_buffer(phba, pring, 0, 1);
  3881. return;
  3882. }
  3883. if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
  3884. (icmd->ulpCommand == CMD_IOCB_RCV_ELS64_CX ||
  3885. icmd->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
  3886. if (icmd->unsli3.rcvsli3.vpi == 0xffff)
  3887. vport = phba->pport;
  3888. else {
  3889. uint16_t vpi = icmd->unsli3.rcvsli3.vpi;
  3890. vport = lpfc_find_vport_by_vpid(phba, vpi);
  3891. }
  3892. }
  3893. /* If there are no BDEs associated
  3894. * with this IOCB, there is nothing to do.
  3895. */
  3896. if (icmd->ulpBdeCount == 0)
  3897. return;
  3898. /* type of ELS cmd is first 32bit word
  3899. * in packet
  3900. */
  3901. if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
  3902. elsiocb->context2 = bdeBuf1;
  3903. } else {
  3904. paddr = getPaddr(icmd->un.cont64[0].addrHigh,
  3905. icmd->un.cont64[0].addrLow);
  3906. elsiocb->context2 = lpfc_sli_ringpostbuf_get(phba, pring,
  3907. paddr);
  3908. }
  3909. lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
  3910. /*
  3911. * The different unsolicited event handlers would tell us
  3912. * if they are done with "mp" by setting context2 to NULL.
  3913. */
  3914. lpfc_nlp_put(elsiocb->context1);
  3915. elsiocb->context1 = NULL;
  3916. if (elsiocb->context2) {
  3917. lpfc_in_buf_free(phba, (struct lpfc_dmabuf *)elsiocb->context2);
  3918. elsiocb->context2 = NULL;
  3919. }
  3920. /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */
  3921. if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) &&
  3922. icmd->ulpBdeCount == 2) {
  3923. elsiocb->context2 = bdeBuf2;
  3924. lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
  3925. /* free mp if we are done with it */
  3926. if (elsiocb->context2) {
  3927. lpfc_in_buf_free(phba, elsiocb->context2);
  3928. elsiocb->context2 = NULL;
  3929. }
  3930. }
  3931. }
  3932. void
  3933. lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport)
  3934. {
  3935. struct lpfc_nodelist *ndlp, *ndlp_fdmi;
  3936. ndlp = lpfc_findnode_did(vport, NameServer_DID);
  3937. if (!ndlp) {
  3938. ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
  3939. if (!ndlp) {
  3940. if (phba->fc_topology == TOPOLOGY_LOOP) {
  3941. lpfc_disc_start(vport);
  3942. return;
  3943. }
  3944. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  3945. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  3946. "0251 NameServer login: no memory\n");
  3947. return;
  3948. }
  3949. lpfc_nlp_init(vport, ndlp, NameServer_DID);
  3950. } else if (!NLP_CHK_NODE_ACT(ndlp)) {
  3951. ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
  3952. if (!ndlp) {
  3953. if (phba->fc_topology == TOPOLOGY_LOOP) {
  3954. lpfc_disc_start(vport);
  3955. return;
  3956. }
  3957. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  3958. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  3959. "0348 NameServer login: node freed\n");
  3960. return;
  3961. }
  3962. }
  3963. ndlp->nlp_type |= NLP_FABRIC;
  3964. lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
  3965. if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) {
  3966. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  3967. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  3968. "0252 Cannot issue NameServer login\n");
  3969. return;
  3970. }
  3971. if (vport->cfg_fdmi_on) {
  3972. ndlp_fdmi = mempool_alloc(phba->nlp_mem_pool,
  3973. GFP_KERNEL);
  3974. if (ndlp_fdmi) {
  3975. lpfc_nlp_init(vport, ndlp_fdmi, FDMI_DID);
  3976. ndlp_fdmi->nlp_type |= NLP_FABRIC;
  3977. lpfc_nlp_set_state(vport, ndlp_fdmi,
  3978. NLP_STE_PLOGI_ISSUE);
  3979. lpfc_issue_els_plogi(vport, ndlp_fdmi->nlp_DID,
  3980. 0);
  3981. }
  3982. }
  3983. return;
  3984. }
  3985. static void
  3986. lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  3987. {
  3988. struct lpfc_vport *vport = pmb->vport;
  3989. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  3990. struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
  3991. MAILBOX_t *mb = &pmb->mb;
  3992. spin_lock_irq(shost->host_lock);
  3993. vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
  3994. spin_unlock_irq(shost->host_lock);
  3995. if (mb->mbxStatus) {
  3996. lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
  3997. "0915 Register VPI failed: 0x%x\n",
  3998. mb->mbxStatus);
  3999. switch (mb->mbxStatus) {
  4000. case 0x11: /* unsupported feature */
  4001. case 0x9603: /* max_vpi exceeded */
  4002. case 0x9602: /* Link event since CLEAR_LA */
  4003. /* giving up on vport registration */
  4004. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  4005. spin_lock_irq(shost->host_lock);
  4006. vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
  4007. spin_unlock_irq(shost->host_lock);
  4008. lpfc_can_disctmo(vport);
  4009. break;
  4010. default:
  4011. /* Try to recover from this error */
  4012. lpfc_mbx_unreg_vpi(vport);
  4013. spin_lock_irq(shost->host_lock);
  4014. vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
  4015. spin_unlock_irq(shost->host_lock);
  4016. if (vport->port_type == LPFC_PHYSICAL_PORT)
  4017. lpfc_initial_flogi(vport);
  4018. else
  4019. lpfc_initial_fdisc(vport);
  4020. break;
  4021. }
  4022. } else {
  4023. if (vport == phba->pport)
  4024. lpfc_issue_fabric_reglogin(vport);
  4025. else
  4026. lpfc_do_scr_ns_plogi(phba, vport);
  4027. }
  4028. /* Now, we decrement the ndlp reference count held for this
  4029. * callback function
  4030. */
  4031. lpfc_nlp_put(ndlp);
  4032. mempool_free(pmb, phba->mbox_mem_pool);
  4033. return;
  4034. }
  4035. static void
  4036. lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport,
  4037. struct lpfc_nodelist *ndlp)
  4038. {
  4039. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  4040. LPFC_MBOXQ_t *mbox;
  4041. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  4042. if (mbox) {
  4043. lpfc_reg_vpi(phba, vport->vpi, vport->fc_myDID, mbox);
  4044. mbox->vport = vport;
  4045. mbox->context2 = lpfc_nlp_get(ndlp);
  4046. mbox->mbox_cmpl = lpfc_cmpl_reg_new_vport;
  4047. if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
  4048. == MBX_NOT_FINISHED) {
  4049. /* mailbox command not success, decrement ndlp
  4050. * reference count for this command
  4051. */
  4052. lpfc_nlp_put(ndlp);
  4053. mempool_free(mbox, phba->mbox_mem_pool);
  4054. lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
  4055. "0253 Register VPI: Can't send mbox\n");
  4056. goto mbox_err_exit;
  4057. }
  4058. } else {
  4059. lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
  4060. "0254 Register VPI: no memory\n");
  4061. goto mbox_err_exit;
  4062. }
  4063. return;
  4064. mbox_err_exit:
  4065. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  4066. spin_lock_irq(shost->host_lock);
  4067. vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
  4068. spin_unlock_irq(shost->host_lock);
  4069. return;
  4070. }
  4071. static void
  4072. lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  4073. struct lpfc_iocbq *rspiocb)
  4074. {
  4075. struct lpfc_vport *vport = cmdiocb->vport;
  4076. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  4077. struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
  4078. struct lpfc_nodelist *np;
  4079. struct lpfc_nodelist *next_np;
  4080. IOCB_t *irsp = &rspiocb->iocb;
  4081. struct lpfc_iocbq *piocb;
  4082. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  4083. "0123 FDISC completes. x%x/x%x prevDID: x%x\n",
  4084. irsp->ulpStatus, irsp->un.ulpWord[4],
  4085. vport->fc_prevDID);
  4086. /* Since all FDISCs are being single threaded, we
  4087. * must reset the discovery timer for ALL vports
  4088. * waiting to send FDISC when one completes.
  4089. */
  4090. list_for_each_entry(piocb, &phba->fabric_iocb_list, list) {
  4091. lpfc_set_disctmo(piocb->vport);
  4092. }
  4093. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  4094. "FDISC cmpl: status:x%x/x%x prevdid:x%x",
  4095. irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_prevDID);
  4096. if (irsp->ulpStatus) {
  4097. /* Check for retry */
  4098. if (lpfc_els_retry(phba, cmdiocb, rspiocb))
  4099. goto out;
  4100. /* FDISC failed */
  4101. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  4102. "0124 FDISC failed. (%d/%d)\n",
  4103. irsp->ulpStatus, irsp->un.ulpWord[4]);
  4104. if (vport->fc_vport->vport_state == FC_VPORT_INITIALIZING)
  4105. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  4106. lpfc_nlp_put(ndlp);
  4107. /* giving up on FDISC. Cancel discovery timer */
  4108. lpfc_can_disctmo(vport);
  4109. } else {
  4110. spin_lock_irq(shost->host_lock);
  4111. vport->fc_flag |= FC_FABRIC;
  4112. if (vport->phba->fc_topology == TOPOLOGY_LOOP)
  4113. vport->fc_flag |= FC_PUBLIC_LOOP;
  4114. spin_unlock_irq(shost->host_lock);
  4115. vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
  4116. lpfc_vport_set_state(vport, FC_VPORT_ACTIVE);
  4117. if ((vport->fc_prevDID != vport->fc_myDID) &&
  4118. !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
  4119. /* If our NportID changed, we need to ensure all
  4120. * remaining NPORTs get unreg_login'ed so we can
  4121. * issue unreg_vpi.
  4122. */
  4123. list_for_each_entry_safe(np, next_np,
  4124. &vport->fc_nodes, nlp_listp) {
  4125. if (!NLP_CHK_NODE_ACT(ndlp) ||
  4126. (np->nlp_state != NLP_STE_NPR_NODE) ||
  4127. !(np->nlp_flag & NLP_NPR_ADISC))
  4128. continue;
  4129. spin_lock_irq(shost->host_lock);
  4130. np->nlp_flag &= ~NLP_NPR_ADISC;
  4131. spin_unlock_irq(shost->host_lock);
  4132. lpfc_unreg_rpi(vport, np);
  4133. }
  4134. lpfc_mbx_unreg_vpi(vport);
  4135. spin_lock_irq(shost->host_lock);
  4136. vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
  4137. spin_unlock_irq(shost->host_lock);
  4138. }
  4139. if (vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
  4140. lpfc_register_new_vport(phba, vport, ndlp);
  4141. else
  4142. lpfc_do_scr_ns_plogi(phba, vport);
  4143. /* Unconditionaly kick off releasing fabric node for vports */
  4144. lpfc_nlp_put(ndlp);
  4145. }
  4146. out:
  4147. lpfc_els_free_iocb(phba, cmdiocb);
  4148. }
  4149. static int
  4150. lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  4151. uint8_t retry)
  4152. {
  4153. struct lpfc_hba *phba = vport->phba;
  4154. IOCB_t *icmd;
  4155. struct lpfc_iocbq *elsiocb;
  4156. struct serv_parm *sp;
  4157. uint8_t *pcmd;
  4158. uint16_t cmdsize;
  4159. int did = ndlp->nlp_DID;
  4160. int rc;
  4161. cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
  4162. elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
  4163. ELS_CMD_FDISC);
  4164. if (!elsiocb) {
  4165. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  4166. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  4167. "0255 Issue FDISC: no IOCB\n");
  4168. return 1;
  4169. }
  4170. icmd = &elsiocb->iocb;
  4171. icmd->un.elsreq64.myID = 0;
  4172. icmd->un.elsreq64.fl = 1;
  4173. /* For FDISC, Let FDISC rsp set the NPortID for this VPI */
  4174. icmd->ulpCt_h = 1;
  4175. icmd->ulpCt_l = 0;
  4176. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  4177. *((uint32_t *) (pcmd)) = ELS_CMD_FDISC;
  4178. pcmd += sizeof(uint32_t); /* CSP Word 1 */
  4179. memcpy(pcmd, &vport->phba->pport->fc_sparam, sizeof(struct serv_parm));
  4180. sp = (struct serv_parm *) pcmd;
  4181. /* Setup CSPs accordingly for Fabric */
  4182. sp->cmn.e_d_tov = 0;
  4183. sp->cmn.w2.r_a_tov = 0;
  4184. sp->cls1.classValid = 0;
  4185. sp->cls2.seqDelivery = 1;
  4186. sp->cls3.seqDelivery = 1;
  4187. pcmd += sizeof(uint32_t); /* CSP Word 2 */
  4188. pcmd += sizeof(uint32_t); /* CSP Word 3 */
  4189. pcmd += sizeof(uint32_t); /* CSP Word 4 */
  4190. pcmd += sizeof(uint32_t); /* Port Name */
  4191. memcpy(pcmd, &vport->fc_portname, 8);
  4192. pcmd += sizeof(uint32_t); /* Node Name */
  4193. pcmd += sizeof(uint32_t); /* Node Name */
  4194. memcpy(pcmd, &vport->fc_nodename, 8);
  4195. lpfc_set_disctmo(vport);
  4196. phba->fc_stat.elsXmitFDISC++;
  4197. elsiocb->iocb_cmpl = lpfc_cmpl_els_fdisc;
  4198. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  4199. "Issue FDISC: did:x%x",
  4200. did, 0, 0);
  4201. rc = lpfc_issue_fabric_iocb(phba, elsiocb);
  4202. if (rc == IOCB_ERROR) {
  4203. lpfc_els_free_iocb(phba, elsiocb);
  4204. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  4205. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  4206. "0256 Issue FDISC: Cannot send IOCB\n");
  4207. return 1;
  4208. }
  4209. lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING);
  4210. vport->port_state = LPFC_FDISC;
  4211. return 0;
  4212. }
  4213. static void
  4214. lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  4215. struct lpfc_iocbq *rspiocb)
  4216. {
  4217. struct lpfc_vport *vport = cmdiocb->vport;
  4218. IOCB_t *irsp;
  4219. struct lpfc_nodelist *ndlp;
  4220. ndlp = (struct lpfc_nodelist *)cmdiocb->context1;
  4221. irsp = &rspiocb->iocb;
  4222. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  4223. "LOGO npiv cmpl: status:x%x/x%x did:x%x",
  4224. irsp->ulpStatus, irsp->un.ulpWord[4], irsp->un.rcvels.remoteID);
  4225. lpfc_els_free_iocb(phba, cmdiocb);
  4226. vport->unreg_vpi_cmpl = VPORT_ERROR;
  4227. /* Trigger the release of the ndlp after logo */
  4228. lpfc_nlp_put(ndlp);
  4229. }
  4230. int
  4231. lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
  4232. {
  4233. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  4234. struct lpfc_hba *phba = vport->phba;
  4235. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  4236. IOCB_t *icmd;
  4237. struct lpfc_iocbq *elsiocb;
  4238. uint8_t *pcmd;
  4239. uint16_t cmdsize;
  4240. cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name);
  4241. elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID,
  4242. ELS_CMD_LOGO);
  4243. if (!elsiocb)
  4244. return 1;
  4245. icmd = &elsiocb->iocb;
  4246. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  4247. *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
  4248. pcmd += sizeof(uint32_t);
  4249. /* Fill in LOGO payload */
  4250. *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
  4251. pcmd += sizeof(uint32_t);
  4252. memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
  4253. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  4254. "Issue LOGO npiv did:x%x flg:x%x",
  4255. ndlp->nlp_DID, ndlp->nlp_flag, 0);
  4256. elsiocb->iocb_cmpl = lpfc_cmpl_els_npiv_logo;
  4257. spin_lock_irq(shost->host_lock);
  4258. ndlp->nlp_flag |= NLP_LOGO_SND;
  4259. spin_unlock_irq(shost->host_lock);
  4260. if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
  4261. spin_lock_irq(shost->host_lock);
  4262. ndlp->nlp_flag &= ~NLP_LOGO_SND;
  4263. spin_unlock_irq(shost->host_lock);
  4264. lpfc_els_free_iocb(phba, elsiocb);
  4265. return 1;
  4266. }
  4267. return 0;
  4268. }
  4269. void
  4270. lpfc_fabric_block_timeout(unsigned long ptr)
  4271. {
  4272. struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
  4273. unsigned long iflags;
  4274. uint32_t tmo_posted;
  4275. spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
  4276. tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO;
  4277. if (!tmo_posted)
  4278. phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO;
  4279. spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
  4280. if (!tmo_posted) {
  4281. spin_lock_irqsave(&phba->hbalock, iflags);
  4282. if (phba->work_wait)
  4283. lpfc_worker_wake_up(phba);
  4284. spin_unlock_irqrestore(&phba->hbalock, iflags);
  4285. }
  4286. }
  4287. static void
  4288. lpfc_resume_fabric_iocbs(struct lpfc_hba *phba)
  4289. {
  4290. struct lpfc_iocbq *iocb;
  4291. unsigned long iflags;
  4292. int ret;
  4293. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  4294. IOCB_t *cmd;
  4295. repeat:
  4296. iocb = NULL;
  4297. spin_lock_irqsave(&phba->hbalock, iflags);
  4298. /* Post any pending iocb to the SLI layer */
  4299. if (atomic_read(&phba->fabric_iocb_count) == 0) {
  4300. list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb),
  4301. list);
  4302. if (iocb)
  4303. /* Increment fabric iocb count to hold the position */
  4304. atomic_inc(&phba->fabric_iocb_count);
  4305. }
  4306. spin_unlock_irqrestore(&phba->hbalock, iflags);
  4307. if (iocb) {
  4308. iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
  4309. iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
  4310. iocb->iocb_flag |= LPFC_IO_FABRIC;
  4311. lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
  4312. "Fabric sched1: ste:x%x",
  4313. iocb->vport->port_state, 0, 0);
  4314. ret = lpfc_sli_issue_iocb(phba, pring, iocb, 0);
  4315. if (ret == IOCB_ERROR) {
  4316. iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
  4317. iocb->fabric_iocb_cmpl = NULL;
  4318. iocb->iocb_flag &= ~LPFC_IO_FABRIC;
  4319. cmd = &iocb->iocb;
  4320. cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
  4321. cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
  4322. iocb->iocb_cmpl(phba, iocb, iocb);
  4323. atomic_dec(&phba->fabric_iocb_count);
  4324. goto repeat;
  4325. }
  4326. }
  4327. return;
  4328. }
  4329. void
  4330. lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba)
  4331. {
  4332. clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
  4333. lpfc_resume_fabric_iocbs(phba);
  4334. return;
  4335. }
  4336. static void
  4337. lpfc_block_fabric_iocbs(struct lpfc_hba *phba)
  4338. {
  4339. int blocked;
  4340. blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
  4341. /* Start a timer to unblock fabric iocbs after 100ms */
  4342. if (!blocked)
  4343. mod_timer(&phba->fabric_block_timer, jiffies + HZ/10 );
  4344. return;
  4345. }
  4346. static void
  4347. lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  4348. struct lpfc_iocbq *rspiocb)
  4349. {
  4350. struct ls_rjt stat;
  4351. if ((cmdiocb->iocb_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC)
  4352. BUG();
  4353. switch (rspiocb->iocb.ulpStatus) {
  4354. case IOSTAT_NPORT_RJT:
  4355. case IOSTAT_FABRIC_RJT:
  4356. if (rspiocb->iocb.un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
  4357. lpfc_block_fabric_iocbs(phba);
  4358. }
  4359. break;
  4360. case IOSTAT_NPORT_BSY:
  4361. case IOSTAT_FABRIC_BSY:
  4362. lpfc_block_fabric_iocbs(phba);
  4363. break;
  4364. case IOSTAT_LS_RJT:
  4365. stat.un.lsRjtError =
  4366. be32_to_cpu(rspiocb->iocb.un.ulpWord[4]);
  4367. if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) ||
  4368. (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY))
  4369. lpfc_block_fabric_iocbs(phba);
  4370. break;
  4371. }
  4372. if (atomic_read(&phba->fabric_iocb_count) == 0)
  4373. BUG();
  4374. cmdiocb->iocb_cmpl = cmdiocb->fabric_iocb_cmpl;
  4375. cmdiocb->fabric_iocb_cmpl = NULL;
  4376. cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC;
  4377. cmdiocb->iocb_cmpl(phba, cmdiocb, rspiocb);
  4378. atomic_dec(&phba->fabric_iocb_count);
  4379. if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) {
  4380. /* Post any pending iocbs to HBA */
  4381. lpfc_resume_fabric_iocbs(phba);
  4382. }
  4383. }
  4384. static int
  4385. lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb)
  4386. {
  4387. unsigned long iflags;
  4388. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  4389. int ready;
  4390. int ret;
  4391. if (atomic_read(&phba->fabric_iocb_count) > 1)
  4392. BUG();
  4393. spin_lock_irqsave(&phba->hbalock, iflags);
  4394. ready = atomic_read(&phba->fabric_iocb_count) == 0 &&
  4395. !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
  4396. if (ready)
  4397. /* Increment fabric iocb count to hold the position */
  4398. atomic_inc(&phba->fabric_iocb_count);
  4399. spin_unlock_irqrestore(&phba->hbalock, iflags);
  4400. if (ready) {
  4401. iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
  4402. iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
  4403. iocb->iocb_flag |= LPFC_IO_FABRIC;
  4404. lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
  4405. "Fabric sched2: ste:x%x",
  4406. iocb->vport->port_state, 0, 0);
  4407. ret = lpfc_sli_issue_iocb(phba, pring, iocb, 0);
  4408. if (ret == IOCB_ERROR) {
  4409. iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
  4410. iocb->fabric_iocb_cmpl = NULL;
  4411. iocb->iocb_flag &= ~LPFC_IO_FABRIC;
  4412. atomic_dec(&phba->fabric_iocb_count);
  4413. }
  4414. } else {
  4415. spin_lock_irqsave(&phba->hbalock, iflags);
  4416. list_add_tail(&iocb->list, &phba->fabric_iocb_list);
  4417. spin_unlock_irqrestore(&phba->hbalock, iflags);
  4418. ret = IOCB_SUCCESS;
  4419. }
  4420. return ret;
  4421. }
  4422. static void lpfc_fabric_abort_vport(struct lpfc_vport *vport)
  4423. {
  4424. LIST_HEAD(completions);
  4425. struct lpfc_hba *phba = vport->phba;
  4426. struct lpfc_iocbq *tmp_iocb, *piocb;
  4427. IOCB_t *cmd;
  4428. spin_lock_irq(&phba->hbalock);
  4429. list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
  4430. list) {
  4431. if (piocb->vport != vport)
  4432. continue;
  4433. list_move_tail(&piocb->list, &completions);
  4434. }
  4435. spin_unlock_irq(&phba->hbalock);
  4436. while (!list_empty(&completions)) {
  4437. piocb = list_get_first(&completions, struct lpfc_iocbq, list);
  4438. list_del_init(&piocb->list);
  4439. cmd = &piocb->iocb;
  4440. cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
  4441. cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
  4442. (piocb->iocb_cmpl) (phba, piocb, piocb);
  4443. }
  4444. }
  4445. void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp)
  4446. {
  4447. LIST_HEAD(completions);
  4448. struct lpfc_hba *phba = ndlp->vport->phba;
  4449. struct lpfc_iocbq *tmp_iocb, *piocb;
  4450. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  4451. IOCB_t *cmd;
  4452. spin_lock_irq(&phba->hbalock);
  4453. list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
  4454. list) {
  4455. if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) {
  4456. list_move_tail(&piocb->list, &completions);
  4457. }
  4458. }
  4459. spin_unlock_irq(&phba->hbalock);
  4460. while (!list_empty(&completions)) {
  4461. piocb = list_get_first(&completions, struct lpfc_iocbq, list);
  4462. list_del_init(&piocb->list);
  4463. cmd = &piocb->iocb;
  4464. cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
  4465. cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
  4466. (piocb->iocb_cmpl) (phba, piocb, piocb);
  4467. }
  4468. }
  4469. void lpfc_fabric_abort_hba(struct lpfc_hba *phba)
  4470. {
  4471. LIST_HEAD(completions);
  4472. struct lpfc_iocbq *piocb;
  4473. IOCB_t *cmd;
  4474. spin_lock_irq(&phba->hbalock);
  4475. list_splice_init(&phba->fabric_iocb_list, &completions);
  4476. spin_unlock_irq(&phba->hbalock);
  4477. while (!list_empty(&completions)) {
  4478. piocb = list_get_first(&completions, struct lpfc_iocbq, list);
  4479. list_del_init(&piocb->list);
  4480. cmd = &piocb->iocb;
  4481. cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
  4482. cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
  4483. (piocb->iocb_cmpl) (phba, piocb, piocb);
  4484. }
  4485. }