lpfc_hbadisc.c 86 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188
  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. #include <linux/blkdev.h>
  22. #include <linux/pci.h>
  23. #include <linux/kthread.h>
  24. #include <linux/interrupt.h>
  25. #include <scsi/scsi.h>
  26. #include <scsi/scsi_device.h>
  27. #include <scsi/scsi_host.h>
  28. #include <scsi/scsi_transport_fc.h>
  29. #include "lpfc_hw.h"
  30. #include "lpfc_disc.h"
  31. #include "lpfc_sli.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. /* AlpaArray for assignment of scsid for scan-down and bind_method */
  39. static uint8_t lpfcAlpaArray[] = {
  40. 0xEF, 0xE8, 0xE4, 0xE2, 0xE1, 0xE0, 0xDC, 0xDA, 0xD9, 0xD6,
  41. 0xD5, 0xD4, 0xD3, 0xD2, 0xD1, 0xCE, 0xCD, 0xCC, 0xCB, 0xCA,
  42. 0xC9, 0xC7, 0xC6, 0xC5, 0xC3, 0xBC, 0xBA, 0xB9, 0xB6, 0xB5,
  43. 0xB4, 0xB3, 0xB2, 0xB1, 0xAE, 0xAD, 0xAC, 0xAB, 0xAA, 0xA9,
  44. 0xA7, 0xA6, 0xA5, 0xA3, 0x9F, 0x9E, 0x9D, 0x9B, 0x98, 0x97,
  45. 0x90, 0x8F, 0x88, 0x84, 0x82, 0x81, 0x80, 0x7C, 0x7A, 0x79,
  46. 0x76, 0x75, 0x74, 0x73, 0x72, 0x71, 0x6E, 0x6D, 0x6C, 0x6B,
  47. 0x6A, 0x69, 0x67, 0x66, 0x65, 0x63, 0x5C, 0x5A, 0x59, 0x56,
  48. 0x55, 0x54, 0x53, 0x52, 0x51, 0x4E, 0x4D, 0x4C, 0x4B, 0x4A,
  49. 0x49, 0x47, 0x46, 0x45, 0x43, 0x3C, 0x3A, 0x39, 0x36, 0x35,
  50. 0x34, 0x33, 0x32, 0x31, 0x2E, 0x2D, 0x2C, 0x2B, 0x2A, 0x29,
  51. 0x27, 0x26, 0x25, 0x23, 0x1F, 0x1E, 0x1D, 0x1B, 0x18, 0x17,
  52. 0x10, 0x0F, 0x08, 0x04, 0x02, 0x01
  53. };
  54. static void lpfc_disc_timeout_handler(struct lpfc_vport *);
  55. static void lpfc_disc_flush_list(struct lpfc_vport *vport);
  56. void
  57. lpfc_terminate_rport_io(struct fc_rport *rport)
  58. {
  59. struct lpfc_rport_data *rdata;
  60. struct lpfc_nodelist * ndlp;
  61. struct lpfc_hba *phba;
  62. rdata = rport->dd_data;
  63. ndlp = rdata->pnode;
  64. if (!ndlp) {
  65. if (rport->roles & FC_RPORT_ROLE_FCP_TARGET)
  66. printk(KERN_ERR "Cannot find remote node"
  67. " to terminate I/O Data x%x\n",
  68. rport->port_id);
  69. return;
  70. }
  71. phba = ndlp->vport->phba;
  72. lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_RPORT,
  73. "rport terminate: sid:x%x did:x%x flg:x%x",
  74. ndlp->nlp_sid, ndlp->nlp_DID, ndlp->nlp_flag);
  75. if (ndlp->nlp_sid != NLP_NO_SID) {
  76. lpfc_sli_abort_iocb(ndlp->vport,
  77. &phba->sli.ring[phba->sli.fcp_ring],
  78. ndlp->nlp_sid, 0, LPFC_CTX_TGT);
  79. }
  80. /*
  81. * A device is normally blocked for rediscovery and unblocked when
  82. * devloss timeout happens. In case a vport is removed or driver
  83. * unloaded before devloss timeout happens, we need to unblock here.
  84. */
  85. scsi_target_unblock(&rport->dev);
  86. return;
  87. }
  88. /*
  89. * This function will be called when dev_loss_tmo fire.
  90. */
  91. void
  92. lpfc_dev_loss_tmo_callbk(struct fc_rport *rport)
  93. {
  94. struct lpfc_rport_data *rdata;
  95. struct lpfc_nodelist * ndlp;
  96. struct lpfc_vport *vport;
  97. struct lpfc_hba *phba;
  98. struct lpfc_work_evt *evtp;
  99. int put_node;
  100. int put_rport;
  101. rdata = rport->dd_data;
  102. ndlp = rdata->pnode;
  103. if (!ndlp)
  104. return;
  105. vport = ndlp->vport;
  106. phba = vport->phba;
  107. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
  108. "rport devlosscb: sid:x%x did:x%x flg:x%x",
  109. ndlp->nlp_sid, ndlp->nlp_DID, ndlp->nlp_flag);
  110. /* Don't defer this if we are in the process of deleting the vport
  111. * or unloading the driver. The unload will cleanup the node
  112. * appropriately we just need to cleanup the ndlp rport info here.
  113. */
  114. if (vport->load_flag & FC_UNLOADING) {
  115. put_node = rdata->pnode != NULL;
  116. put_rport = ndlp->rport != NULL;
  117. rdata->pnode = NULL;
  118. ndlp->rport = NULL;
  119. if (put_node)
  120. lpfc_nlp_put(ndlp);
  121. if (put_rport)
  122. put_device(&rport->dev);
  123. return;
  124. }
  125. if (ndlp->nlp_state == NLP_STE_MAPPED_NODE)
  126. return;
  127. evtp = &ndlp->dev_loss_evt;
  128. if (!list_empty(&evtp->evt_listp))
  129. return;
  130. spin_lock_irq(&phba->hbalock);
  131. /* We need to hold the node by incrementing the reference
  132. * count until this queued work is done
  133. */
  134. evtp->evt_arg1 = lpfc_nlp_get(ndlp);
  135. evtp->evt = LPFC_EVT_DEV_LOSS;
  136. list_add_tail(&evtp->evt_listp, &phba->work_list);
  137. if (phba->work_wait)
  138. wake_up(phba->work_wait);
  139. spin_unlock_irq(&phba->hbalock);
  140. return;
  141. }
  142. /*
  143. * This function is called from the worker thread when dev_loss_tmo
  144. * expire.
  145. */
  146. static void
  147. lpfc_dev_loss_tmo_handler(struct lpfc_nodelist *ndlp)
  148. {
  149. struct lpfc_rport_data *rdata;
  150. struct fc_rport *rport;
  151. struct lpfc_vport *vport;
  152. struct lpfc_hba *phba;
  153. uint8_t *name;
  154. int put_node;
  155. int put_rport;
  156. int warn_on = 0;
  157. rport = ndlp->rport;
  158. if (!rport)
  159. return;
  160. rdata = rport->dd_data;
  161. name = (uint8_t *) &ndlp->nlp_portname;
  162. vport = ndlp->vport;
  163. phba = vport->phba;
  164. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
  165. "rport devlosstmo:did:x%x type:x%x id:x%x",
  166. ndlp->nlp_DID, ndlp->nlp_type, rport->scsi_target_id);
  167. /* Don't defer this if we are in the process of deleting the vport
  168. * or unloading the driver. The unload will cleanup the node
  169. * appropriately we just need to cleanup the ndlp rport info here.
  170. */
  171. if (vport->load_flag & FC_UNLOADING) {
  172. if (ndlp->nlp_sid != NLP_NO_SID) {
  173. /* flush the target */
  174. lpfc_sli_abort_iocb(vport,
  175. &phba->sli.ring[phba->sli.fcp_ring],
  176. ndlp->nlp_sid, 0, LPFC_CTX_TGT);
  177. }
  178. put_node = rdata->pnode != NULL;
  179. put_rport = ndlp->rport != NULL;
  180. rdata->pnode = NULL;
  181. ndlp->rport = NULL;
  182. if (put_node)
  183. lpfc_nlp_put(ndlp);
  184. if (put_rport)
  185. put_device(&rport->dev);
  186. return;
  187. }
  188. if (ndlp->nlp_state == NLP_STE_MAPPED_NODE)
  189. return;
  190. if (ndlp->nlp_type & NLP_FABRIC) {
  191. /* We will clean up these Nodes in linkup */
  192. put_node = rdata->pnode != NULL;
  193. put_rport = ndlp->rport != NULL;
  194. rdata->pnode = NULL;
  195. ndlp->rport = NULL;
  196. if (put_node)
  197. lpfc_nlp_put(ndlp);
  198. if (put_rport)
  199. put_device(&rport->dev);
  200. return;
  201. }
  202. if (ndlp->nlp_sid != NLP_NO_SID) {
  203. warn_on = 1;
  204. /* flush the target */
  205. lpfc_sli_abort_iocb(vport, &phba->sli.ring[phba->sli.fcp_ring],
  206. ndlp->nlp_sid, 0, LPFC_CTX_TGT);
  207. }
  208. if (vport->load_flag & FC_UNLOADING)
  209. warn_on = 0;
  210. if (warn_on) {
  211. lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
  212. "0203 Devloss timeout on "
  213. "WWPN %x:%x:%x:%x:%x:%x:%x:%x "
  214. "NPort x%x Data: x%x x%x x%x\n",
  215. *name, *(name+1), *(name+2), *(name+3),
  216. *(name+4), *(name+5), *(name+6), *(name+7),
  217. ndlp->nlp_DID, ndlp->nlp_flag,
  218. ndlp->nlp_state, ndlp->nlp_rpi);
  219. } else {
  220. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  221. "0204 Devloss timeout on "
  222. "WWPN %x:%x:%x:%x:%x:%x:%x:%x "
  223. "NPort x%x Data: x%x x%x x%x\n",
  224. *name, *(name+1), *(name+2), *(name+3),
  225. *(name+4), *(name+5), *(name+6), *(name+7),
  226. ndlp->nlp_DID, ndlp->nlp_flag,
  227. ndlp->nlp_state, ndlp->nlp_rpi);
  228. }
  229. put_node = rdata->pnode != NULL;
  230. put_rport = ndlp->rport != NULL;
  231. rdata->pnode = NULL;
  232. ndlp->rport = NULL;
  233. if (put_node)
  234. lpfc_nlp_put(ndlp);
  235. if (put_rport)
  236. put_device(&rport->dev);
  237. if (!(vport->load_flag & FC_UNLOADING) &&
  238. !(ndlp->nlp_flag & NLP_DELAY_TMO) &&
  239. !(ndlp->nlp_flag & NLP_NPR_2B_DISC) &&
  240. (ndlp->nlp_state != NLP_STE_UNMAPPED_NODE))
  241. lpfc_disc_state_machine(vport, ndlp, NULL, NLP_EVT_DEVICE_RM);
  242. }
  243. void
  244. lpfc_worker_wake_up(struct lpfc_hba *phba)
  245. {
  246. wake_up(phba->work_wait);
  247. return;
  248. }
  249. static void
  250. lpfc_work_list_done(struct lpfc_hba *phba)
  251. {
  252. struct lpfc_work_evt *evtp = NULL;
  253. struct lpfc_nodelist *ndlp;
  254. int free_evt;
  255. spin_lock_irq(&phba->hbalock);
  256. while (!list_empty(&phba->work_list)) {
  257. list_remove_head((&phba->work_list), evtp, typeof(*evtp),
  258. evt_listp);
  259. spin_unlock_irq(&phba->hbalock);
  260. free_evt = 1;
  261. switch (evtp->evt) {
  262. case LPFC_EVT_ELS_RETRY:
  263. ndlp = (struct lpfc_nodelist *) (evtp->evt_arg1);
  264. lpfc_els_retry_delay_handler(ndlp);
  265. free_evt = 0; /* evt is part of ndlp */
  266. /* decrement the node reference count held
  267. * for this queued work
  268. */
  269. lpfc_nlp_put(ndlp);
  270. break;
  271. case LPFC_EVT_DEV_LOSS:
  272. ndlp = (struct lpfc_nodelist *)(evtp->evt_arg1);
  273. lpfc_dev_loss_tmo_handler(ndlp);
  274. free_evt = 0;
  275. /* decrement the node reference count held for
  276. * this queued work
  277. */
  278. lpfc_nlp_put(ndlp);
  279. break;
  280. case LPFC_EVT_ONLINE:
  281. if (phba->link_state < LPFC_LINK_DOWN)
  282. *(int *) (evtp->evt_arg1) = lpfc_online(phba);
  283. else
  284. *(int *) (evtp->evt_arg1) = 0;
  285. complete((struct completion *)(evtp->evt_arg2));
  286. break;
  287. case LPFC_EVT_OFFLINE_PREP:
  288. if (phba->link_state >= LPFC_LINK_DOWN)
  289. lpfc_offline_prep(phba);
  290. *(int *)(evtp->evt_arg1) = 0;
  291. complete((struct completion *)(evtp->evt_arg2));
  292. break;
  293. case LPFC_EVT_OFFLINE:
  294. lpfc_offline(phba);
  295. lpfc_sli_brdrestart(phba);
  296. *(int *)(evtp->evt_arg1) =
  297. lpfc_sli_brdready(phba, HS_FFRDY | HS_MBRDY);
  298. lpfc_unblock_mgmt_io(phba);
  299. complete((struct completion *)(evtp->evt_arg2));
  300. break;
  301. case LPFC_EVT_WARM_START:
  302. lpfc_offline(phba);
  303. lpfc_reset_barrier(phba);
  304. lpfc_sli_brdreset(phba);
  305. lpfc_hba_down_post(phba);
  306. *(int *)(evtp->evt_arg1) =
  307. lpfc_sli_brdready(phba, HS_MBRDY);
  308. lpfc_unblock_mgmt_io(phba);
  309. complete((struct completion *)(evtp->evt_arg2));
  310. break;
  311. case LPFC_EVT_KILL:
  312. lpfc_offline(phba);
  313. *(int *)(evtp->evt_arg1)
  314. = (phba->pport->stopped)
  315. ? 0 : lpfc_sli_brdkill(phba);
  316. lpfc_unblock_mgmt_io(phba);
  317. complete((struct completion *)(evtp->evt_arg2));
  318. break;
  319. }
  320. if (free_evt)
  321. kfree(evtp);
  322. spin_lock_irq(&phba->hbalock);
  323. }
  324. spin_unlock_irq(&phba->hbalock);
  325. }
  326. static void
  327. lpfc_work_done(struct lpfc_hba *phba)
  328. {
  329. struct lpfc_sli_ring *pring;
  330. uint32_t ha_copy, status, control, work_port_events;
  331. struct lpfc_vport **vports;
  332. struct lpfc_vport *vport;
  333. int i;
  334. spin_lock_irq(&phba->hbalock);
  335. ha_copy = phba->work_ha;
  336. phba->work_ha = 0;
  337. spin_unlock_irq(&phba->hbalock);
  338. if (ha_copy & HA_ERATT)
  339. lpfc_handle_eratt(phba);
  340. if (ha_copy & HA_MBATT)
  341. lpfc_sli_handle_mb_event(phba);
  342. if (ha_copy & HA_LATT)
  343. lpfc_handle_latt(phba);
  344. vports = lpfc_create_vport_work_array(phba);
  345. if (vports != NULL)
  346. for(i = 0; i <= phba->max_vpi; i++) {
  347. /*
  348. * We could have no vports in array if unloading, so if
  349. * this happens then just use the pport
  350. */
  351. if (vports[i] == NULL && i == 0)
  352. vport = phba->pport;
  353. else
  354. vport = vports[i];
  355. if (vport == NULL)
  356. break;
  357. work_port_events = vport->work_port_events;
  358. if (work_port_events & WORKER_DISC_TMO)
  359. lpfc_disc_timeout_handler(vport);
  360. if (work_port_events & WORKER_ELS_TMO)
  361. lpfc_els_timeout_handler(vport);
  362. if (work_port_events & WORKER_HB_TMO)
  363. lpfc_hb_timeout_handler(phba);
  364. if (work_port_events & WORKER_MBOX_TMO)
  365. lpfc_mbox_timeout_handler(phba);
  366. if (work_port_events & WORKER_FABRIC_BLOCK_TMO)
  367. lpfc_unblock_fabric_iocbs(phba);
  368. if (work_port_events & WORKER_FDMI_TMO)
  369. lpfc_fdmi_timeout_handler(vport);
  370. if (work_port_events & WORKER_RAMP_DOWN_QUEUE)
  371. lpfc_ramp_down_queue_handler(phba);
  372. if (work_port_events & WORKER_RAMP_UP_QUEUE)
  373. lpfc_ramp_up_queue_handler(phba);
  374. spin_lock_irq(&vport->work_port_lock);
  375. vport->work_port_events &= ~work_port_events;
  376. spin_unlock_irq(&vport->work_port_lock);
  377. }
  378. lpfc_destroy_vport_work_array(phba, vports);
  379. pring = &phba->sli.ring[LPFC_ELS_RING];
  380. status = (ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING)));
  381. status >>= (4*LPFC_ELS_RING);
  382. if ((status & HA_RXMASK)
  383. || (pring->flag & LPFC_DEFERRED_RING_EVENT)) {
  384. if (pring->flag & LPFC_STOP_IOCB_EVENT) {
  385. pring->flag |= LPFC_DEFERRED_RING_EVENT;
  386. } else {
  387. lpfc_sli_handle_slow_ring_event(phba, pring,
  388. (status &
  389. HA_RXMASK));
  390. pring->flag &= ~LPFC_DEFERRED_RING_EVENT;
  391. }
  392. /*
  393. * Turn on Ring interrupts
  394. */
  395. spin_lock_irq(&phba->hbalock);
  396. control = readl(phba->HCregaddr);
  397. if (!(control & (HC_R0INT_ENA << LPFC_ELS_RING))) {
  398. lpfc_debugfs_slow_ring_trc(phba,
  399. "WRK Enable ring: cntl:x%x hacopy:x%x",
  400. control, ha_copy, 0);
  401. control |= (HC_R0INT_ENA << LPFC_ELS_RING);
  402. writel(control, phba->HCregaddr);
  403. readl(phba->HCregaddr); /* flush */
  404. }
  405. else {
  406. lpfc_debugfs_slow_ring_trc(phba,
  407. "WRK Ring ok: cntl:x%x hacopy:x%x",
  408. control, ha_copy, 0);
  409. }
  410. spin_unlock_irq(&phba->hbalock);
  411. }
  412. lpfc_work_list_done(phba);
  413. }
  414. static int
  415. check_work_wait_done(struct lpfc_hba *phba)
  416. {
  417. struct lpfc_vport *vport;
  418. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  419. int rc = 0;
  420. spin_lock_irq(&phba->hbalock);
  421. list_for_each_entry(vport, &phba->port_list, listentry) {
  422. if (vport->work_port_events) {
  423. rc = 1;
  424. break;
  425. }
  426. }
  427. if (rc || phba->work_ha || (!list_empty(&phba->work_list)) ||
  428. kthread_should_stop() || pring->flag & LPFC_DEFERRED_RING_EVENT) {
  429. rc = 1;
  430. phba->work_found++;
  431. } else
  432. phba->work_found = 0;
  433. spin_unlock_irq(&phba->hbalock);
  434. return rc;
  435. }
  436. int
  437. lpfc_do_work(void *p)
  438. {
  439. struct lpfc_hba *phba = p;
  440. int rc;
  441. DECLARE_WAIT_QUEUE_HEAD_ONSTACK(work_waitq);
  442. set_user_nice(current, -20);
  443. phba->work_wait = &work_waitq;
  444. phba->work_found = 0;
  445. while (1) {
  446. rc = wait_event_interruptible(work_waitq,
  447. check_work_wait_done(phba));
  448. BUG_ON(rc);
  449. if (kthread_should_stop())
  450. break;
  451. lpfc_work_done(phba);
  452. /* If there is alot of slow ring work, like during link up
  453. * check_work_wait_done() may cause this thread to not give
  454. * up the CPU for very long periods of time. This may cause
  455. * soft lockups or other problems. To avoid these situations
  456. * give up the CPU here after LPFC_MAX_WORKER_ITERATION
  457. * consecutive iterations.
  458. */
  459. if (phba->work_found >= LPFC_MAX_WORKER_ITERATION) {
  460. phba->work_found = 0;
  461. schedule();
  462. }
  463. }
  464. phba->work_wait = NULL;
  465. return 0;
  466. }
  467. /*
  468. * This is only called to handle FC worker events. Since this a rare
  469. * occurance, we allocate a struct lpfc_work_evt structure here instead of
  470. * embedding it in the IOCB.
  471. */
  472. int
  473. lpfc_workq_post_event(struct lpfc_hba *phba, void *arg1, void *arg2,
  474. uint32_t evt)
  475. {
  476. struct lpfc_work_evt *evtp;
  477. unsigned long flags;
  478. /*
  479. * All Mailbox completions and LPFC_ELS_RING rcv ring IOCB events will
  480. * be queued to worker thread for processing
  481. */
  482. evtp = kmalloc(sizeof(struct lpfc_work_evt), GFP_ATOMIC);
  483. if (!evtp)
  484. return 0;
  485. evtp->evt_arg1 = arg1;
  486. evtp->evt_arg2 = arg2;
  487. evtp->evt = evt;
  488. spin_lock_irqsave(&phba->hbalock, flags);
  489. list_add_tail(&evtp->evt_listp, &phba->work_list);
  490. if (phba->work_wait)
  491. lpfc_worker_wake_up(phba);
  492. spin_unlock_irqrestore(&phba->hbalock, flags);
  493. return 1;
  494. }
  495. void
  496. lpfc_cleanup_rpis(struct lpfc_vport *vport, int remove)
  497. {
  498. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  499. struct lpfc_hba *phba = vport->phba;
  500. struct lpfc_nodelist *ndlp, *next_ndlp;
  501. int rc;
  502. list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
  503. if (!NLP_CHK_NODE_ACT(ndlp))
  504. continue;
  505. if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
  506. continue;
  507. if ((phba->sli3_options & LPFC_SLI3_VPORT_TEARDOWN) ||
  508. ((vport->port_type == LPFC_NPIV_PORT) &&
  509. (ndlp->nlp_DID == NameServer_DID)))
  510. lpfc_unreg_rpi(vport, ndlp);
  511. /* Leave Fabric nodes alone on link down */
  512. if (!remove && ndlp->nlp_type & NLP_FABRIC)
  513. continue;
  514. rc = lpfc_disc_state_machine(vport, ndlp, NULL,
  515. remove
  516. ? NLP_EVT_DEVICE_RM
  517. : NLP_EVT_DEVICE_RECOVERY);
  518. }
  519. if (phba->sli3_options & LPFC_SLI3_VPORT_TEARDOWN) {
  520. lpfc_mbx_unreg_vpi(vport);
  521. spin_lock_irq(shost->host_lock);
  522. vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
  523. spin_unlock_irq(shost->host_lock);
  524. }
  525. }
  526. void
  527. lpfc_port_link_failure(struct lpfc_vport *vport)
  528. {
  529. /* Cleanup any outstanding RSCN activity */
  530. lpfc_els_flush_rscn(vport);
  531. /* Cleanup any outstanding ELS commands */
  532. lpfc_els_flush_cmd(vport);
  533. lpfc_cleanup_rpis(vport, 0);
  534. /* Turn off discovery timer if its running */
  535. lpfc_can_disctmo(vport);
  536. }
  537. static void
  538. lpfc_linkdown_port(struct lpfc_vport *vport)
  539. {
  540. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  541. fc_host_post_event(shost, fc_get_event_number(), FCH_EVT_LINKDOWN, 0);
  542. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  543. "Link Down: state:x%x rtry:x%x flg:x%x",
  544. vport->port_state, vport->fc_ns_retry, vport->fc_flag);
  545. lpfc_port_link_failure(vport);
  546. }
  547. int
  548. lpfc_linkdown(struct lpfc_hba *phba)
  549. {
  550. struct lpfc_vport *vport = phba->pport;
  551. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  552. struct lpfc_vport **vports;
  553. LPFC_MBOXQ_t *mb;
  554. int i;
  555. if (phba->link_state == LPFC_LINK_DOWN)
  556. return 0;
  557. spin_lock_irq(&phba->hbalock);
  558. if (phba->link_state > LPFC_LINK_DOWN) {
  559. phba->link_state = LPFC_LINK_DOWN;
  560. phba->pport->fc_flag &= ~FC_LBIT;
  561. }
  562. spin_unlock_irq(&phba->hbalock);
  563. vports = lpfc_create_vport_work_array(phba);
  564. if (vports != NULL)
  565. for(i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) {
  566. /* Issue a LINK DOWN event to all nodes */
  567. lpfc_linkdown_port(vports[i]);
  568. }
  569. lpfc_destroy_vport_work_array(phba, vports);
  570. /* Clean up any firmware default rpi's */
  571. mb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  572. if (mb) {
  573. lpfc_unreg_did(phba, 0xffff, 0xffffffff, mb);
  574. mb->vport = vport;
  575. mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  576. if (lpfc_sli_issue_mbox(phba, mb, MBX_NOWAIT)
  577. == MBX_NOT_FINISHED) {
  578. mempool_free(mb, phba->mbox_mem_pool);
  579. }
  580. }
  581. /* Setup myDID for link up if we are in pt2pt mode */
  582. if (phba->pport->fc_flag & FC_PT2PT) {
  583. phba->pport->fc_myDID = 0;
  584. mb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  585. if (mb) {
  586. lpfc_config_link(phba, mb);
  587. mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  588. mb->vport = vport;
  589. if (lpfc_sli_issue_mbox(phba, mb, MBX_NOWAIT)
  590. == MBX_NOT_FINISHED) {
  591. mempool_free(mb, phba->mbox_mem_pool);
  592. }
  593. }
  594. spin_lock_irq(shost->host_lock);
  595. phba->pport->fc_flag &= ~(FC_PT2PT | FC_PT2PT_PLOGI);
  596. spin_unlock_irq(shost->host_lock);
  597. }
  598. return 0;
  599. }
  600. static void
  601. lpfc_linkup_cleanup_nodes(struct lpfc_vport *vport)
  602. {
  603. struct lpfc_nodelist *ndlp;
  604. list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
  605. if (!NLP_CHK_NODE_ACT(ndlp))
  606. continue;
  607. if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
  608. continue;
  609. if (ndlp->nlp_type & NLP_FABRIC) {
  610. /* On Linkup its safe to clean up the ndlp
  611. * from Fabric connections.
  612. */
  613. if (ndlp->nlp_DID != Fabric_DID)
  614. lpfc_unreg_rpi(vport, ndlp);
  615. lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
  616. } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
  617. /* Fail outstanding IO now since device is
  618. * marked for PLOGI.
  619. */
  620. lpfc_unreg_rpi(vport, ndlp);
  621. }
  622. }
  623. }
  624. static void
  625. lpfc_linkup_port(struct lpfc_vport *vport)
  626. {
  627. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  628. struct lpfc_hba *phba = vport->phba;
  629. if ((vport->load_flag & FC_UNLOADING) != 0)
  630. return;
  631. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  632. "Link Up: top:x%x speed:x%x flg:x%x",
  633. phba->fc_topology, phba->fc_linkspeed, phba->link_flag);
  634. /* If NPIV is not enabled, only bring the physical port up */
  635. if (!(phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
  636. (vport != phba->pport))
  637. return;
  638. fc_host_post_event(shost, fc_get_event_number(), FCH_EVT_LINKUP, 0);
  639. spin_lock_irq(shost->host_lock);
  640. vport->fc_flag &= ~(FC_PT2PT | FC_PT2PT_PLOGI | FC_ABORT_DISCOVERY |
  641. FC_RSCN_MODE | FC_NLP_MORE | FC_RSCN_DISCOVERY);
  642. vport->fc_flag |= FC_NDISC_ACTIVE;
  643. vport->fc_ns_retry = 0;
  644. spin_unlock_irq(shost->host_lock);
  645. if (vport->fc_flag & FC_LBIT)
  646. lpfc_linkup_cleanup_nodes(vport);
  647. }
  648. static int
  649. lpfc_linkup(struct lpfc_hba *phba)
  650. {
  651. struct lpfc_vport **vports;
  652. int i;
  653. phba->link_state = LPFC_LINK_UP;
  654. /* Unblock fabric iocbs if they are blocked */
  655. clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
  656. del_timer_sync(&phba->fabric_block_timer);
  657. vports = lpfc_create_vport_work_array(phba);
  658. if (vports != NULL)
  659. for(i = 0; i <= phba->max_vpi && vports[i] != NULL; i++)
  660. lpfc_linkup_port(vports[i]);
  661. lpfc_destroy_vport_work_array(phba, vports);
  662. if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
  663. lpfc_issue_clear_la(phba, phba->pport);
  664. return 0;
  665. }
  666. /*
  667. * This routine handles processing a CLEAR_LA mailbox
  668. * command upon completion. It is setup in the LPFC_MBOXQ
  669. * as the completion routine when the command is
  670. * handed off to the SLI layer.
  671. */
  672. static void
  673. lpfc_mbx_cmpl_clear_la(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  674. {
  675. struct lpfc_vport *vport = pmb->vport;
  676. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  677. struct lpfc_sli *psli = &phba->sli;
  678. MAILBOX_t *mb = &pmb->mb;
  679. uint32_t control;
  680. /* Since we don't do discovery right now, turn these off here */
  681. psli->ring[psli->extra_ring].flag &= ~LPFC_STOP_IOCB_EVENT;
  682. psli->ring[psli->fcp_ring].flag &= ~LPFC_STOP_IOCB_EVENT;
  683. psli->ring[psli->next_ring].flag &= ~LPFC_STOP_IOCB_EVENT;
  684. /* Check for error */
  685. if ((mb->mbxStatus) && (mb->mbxStatus != 0x1601)) {
  686. /* CLEAR_LA mbox error <mbxStatus> state <hba_state> */
  687. lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
  688. "0320 CLEAR_LA mbxStatus error x%x hba "
  689. "state x%x\n",
  690. mb->mbxStatus, vport->port_state);
  691. phba->link_state = LPFC_HBA_ERROR;
  692. goto out;
  693. }
  694. if (vport->port_type == LPFC_PHYSICAL_PORT)
  695. phba->link_state = LPFC_HBA_READY;
  696. spin_lock_irq(&phba->hbalock);
  697. psli->sli_flag |= LPFC_PROCESS_LA;
  698. control = readl(phba->HCregaddr);
  699. control |= HC_LAINT_ENA;
  700. writel(control, phba->HCregaddr);
  701. readl(phba->HCregaddr); /* flush */
  702. spin_unlock_irq(&phba->hbalock);
  703. mempool_free(pmb, phba->mbox_mem_pool);
  704. return;
  705. out:
  706. /* Device Discovery completes */
  707. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  708. "0225 Device Discovery completes\n");
  709. mempool_free(pmb, phba->mbox_mem_pool);
  710. spin_lock_irq(shost->host_lock);
  711. vport->fc_flag &= ~(FC_ABORT_DISCOVERY | FC_ESTABLISH_LINK);
  712. spin_unlock_irq(shost->host_lock);
  713. del_timer_sync(&phba->fc_estabtmo);
  714. lpfc_can_disctmo(vport);
  715. /* turn on Link Attention interrupts */
  716. spin_lock_irq(&phba->hbalock);
  717. psli->sli_flag |= LPFC_PROCESS_LA;
  718. control = readl(phba->HCregaddr);
  719. control |= HC_LAINT_ENA;
  720. writel(control, phba->HCregaddr);
  721. readl(phba->HCregaddr); /* flush */
  722. spin_unlock_irq(&phba->hbalock);
  723. return;
  724. }
  725. static void
  726. lpfc_mbx_cmpl_local_config_link(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  727. {
  728. struct lpfc_vport *vport = pmb->vport;
  729. if (pmb->mb.mbxStatus)
  730. goto out;
  731. mempool_free(pmb, phba->mbox_mem_pool);
  732. if (phba->fc_topology == TOPOLOGY_LOOP &&
  733. vport->fc_flag & FC_PUBLIC_LOOP &&
  734. !(vport->fc_flag & FC_LBIT)) {
  735. /* Need to wait for FAN - use discovery timer
  736. * for timeout. port_state is identically
  737. * LPFC_LOCAL_CFG_LINK while waiting for FAN
  738. */
  739. lpfc_set_disctmo(vport);
  740. return;
  741. }
  742. /* Start discovery by sending a FLOGI. port_state is identically
  743. * LPFC_FLOGI while waiting for FLOGI cmpl
  744. */
  745. if (vport->port_state != LPFC_FLOGI) {
  746. lpfc_initial_flogi(vport);
  747. }
  748. return;
  749. out:
  750. lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
  751. "0306 CONFIG_LINK mbxStatus error x%x "
  752. "HBA state x%x\n",
  753. pmb->mb.mbxStatus, vport->port_state);
  754. mempool_free(pmb, phba->mbox_mem_pool);
  755. lpfc_linkdown(phba);
  756. lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
  757. "0200 CONFIG_LINK bad hba state x%x\n",
  758. vport->port_state);
  759. lpfc_issue_clear_la(phba, vport);
  760. return;
  761. }
  762. static void
  763. lpfc_mbx_cmpl_read_sparam(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  764. {
  765. MAILBOX_t *mb = &pmb->mb;
  766. struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) pmb->context1;
  767. struct lpfc_vport *vport = pmb->vport;
  768. /* Check for error */
  769. if (mb->mbxStatus) {
  770. /* READ_SPARAM mbox error <mbxStatus> state <hba_state> */
  771. lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
  772. "0319 READ_SPARAM mbxStatus error x%x "
  773. "hba state x%x>\n",
  774. mb->mbxStatus, vport->port_state);
  775. lpfc_linkdown(phba);
  776. goto out;
  777. }
  778. memcpy((uint8_t *) &vport->fc_sparam, (uint8_t *) mp->virt,
  779. sizeof (struct serv_parm));
  780. if (phba->cfg_soft_wwnn)
  781. u64_to_wwn(phba->cfg_soft_wwnn,
  782. vport->fc_sparam.nodeName.u.wwn);
  783. if (phba->cfg_soft_wwpn)
  784. u64_to_wwn(phba->cfg_soft_wwpn,
  785. vport->fc_sparam.portName.u.wwn);
  786. memcpy(&vport->fc_nodename, &vport->fc_sparam.nodeName,
  787. sizeof(vport->fc_nodename));
  788. memcpy(&vport->fc_portname, &vport->fc_sparam.portName,
  789. sizeof(vport->fc_portname));
  790. if (vport->port_type == LPFC_PHYSICAL_PORT) {
  791. memcpy(&phba->wwnn, &vport->fc_nodename, sizeof(phba->wwnn));
  792. memcpy(&phba->wwpn, &vport->fc_portname, sizeof(phba->wwnn));
  793. }
  794. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  795. kfree(mp);
  796. mempool_free(pmb, phba->mbox_mem_pool);
  797. return;
  798. out:
  799. pmb->context1 = NULL;
  800. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  801. kfree(mp);
  802. lpfc_issue_clear_la(phba, vport);
  803. mempool_free(pmb, phba->mbox_mem_pool);
  804. return;
  805. }
  806. static void
  807. lpfc_mbx_process_link_up(struct lpfc_hba *phba, READ_LA_VAR *la)
  808. {
  809. struct lpfc_vport *vport = phba->pport;
  810. LPFC_MBOXQ_t *sparam_mbox, *cfglink_mbox;
  811. int i;
  812. struct lpfc_dmabuf *mp;
  813. int rc;
  814. sparam_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  815. cfglink_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  816. spin_lock_irq(&phba->hbalock);
  817. switch (la->UlnkSpeed) {
  818. case LA_1GHZ_LINK:
  819. phba->fc_linkspeed = LA_1GHZ_LINK;
  820. break;
  821. case LA_2GHZ_LINK:
  822. phba->fc_linkspeed = LA_2GHZ_LINK;
  823. break;
  824. case LA_4GHZ_LINK:
  825. phba->fc_linkspeed = LA_4GHZ_LINK;
  826. break;
  827. case LA_8GHZ_LINK:
  828. phba->fc_linkspeed = LA_8GHZ_LINK;
  829. break;
  830. default:
  831. phba->fc_linkspeed = LA_UNKNW_LINK;
  832. break;
  833. }
  834. phba->fc_topology = la->topology;
  835. phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED;
  836. if (phba->fc_topology == TOPOLOGY_LOOP) {
  837. phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED;
  838. /* Get Loop Map information */
  839. if (la->il)
  840. vport->fc_flag |= FC_LBIT;
  841. vport->fc_myDID = la->granted_AL_PA;
  842. i = la->un.lilpBde64.tus.f.bdeSize;
  843. if (i == 0) {
  844. phba->alpa_map[0] = 0;
  845. } else {
  846. if (vport->cfg_log_verbose & LOG_LINK_EVENT) {
  847. int numalpa, j, k;
  848. union {
  849. uint8_t pamap[16];
  850. struct {
  851. uint32_t wd1;
  852. uint32_t wd2;
  853. uint32_t wd3;
  854. uint32_t wd4;
  855. } pa;
  856. } un;
  857. numalpa = phba->alpa_map[0];
  858. j = 0;
  859. while (j < numalpa) {
  860. memset(un.pamap, 0, 16);
  861. for (k = 1; j < numalpa; k++) {
  862. un.pamap[k - 1] =
  863. phba->alpa_map[j + 1];
  864. j++;
  865. if (k == 16)
  866. break;
  867. }
  868. /* Link Up Event ALPA map */
  869. lpfc_printf_log(phba,
  870. KERN_WARNING,
  871. LOG_LINK_EVENT,
  872. "1304 Link Up Event "
  873. "ALPA map Data: x%x "
  874. "x%x x%x x%x\n",
  875. un.pa.wd1, un.pa.wd2,
  876. un.pa.wd3, un.pa.wd4);
  877. }
  878. }
  879. }
  880. } else {
  881. if (!(phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)) {
  882. if (phba->max_vpi && phba->cfg_enable_npiv &&
  883. (phba->sli_rev == 3))
  884. phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED;
  885. }
  886. vport->fc_myDID = phba->fc_pref_DID;
  887. vport->fc_flag |= FC_LBIT;
  888. }
  889. spin_unlock_irq(&phba->hbalock);
  890. lpfc_linkup(phba);
  891. if (sparam_mbox) {
  892. lpfc_read_sparam(phba, sparam_mbox, 0);
  893. sparam_mbox->vport = vport;
  894. sparam_mbox->mbox_cmpl = lpfc_mbx_cmpl_read_sparam;
  895. rc = lpfc_sli_issue_mbox(phba, sparam_mbox, MBX_NOWAIT);
  896. if (rc == MBX_NOT_FINISHED) {
  897. mp = (struct lpfc_dmabuf *) sparam_mbox->context1;
  898. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  899. kfree(mp);
  900. mempool_free(sparam_mbox, phba->mbox_mem_pool);
  901. if (cfglink_mbox)
  902. mempool_free(cfglink_mbox, phba->mbox_mem_pool);
  903. goto out;
  904. }
  905. }
  906. if (cfglink_mbox) {
  907. vport->port_state = LPFC_LOCAL_CFG_LINK;
  908. lpfc_config_link(phba, cfglink_mbox);
  909. cfglink_mbox->vport = vport;
  910. cfglink_mbox->mbox_cmpl = lpfc_mbx_cmpl_local_config_link;
  911. rc = lpfc_sli_issue_mbox(phba, cfglink_mbox, MBX_NOWAIT);
  912. if (rc != MBX_NOT_FINISHED)
  913. return;
  914. mempool_free(cfglink_mbox, phba->mbox_mem_pool);
  915. }
  916. out:
  917. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  918. lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
  919. "0263 Discovery Mailbox error: state: 0x%x : %p %p\n",
  920. vport->port_state, sparam_mbox, cfglink_mbox);
  921. lpfc_issue_clear_la(phba, vport);
  922. return;
  923. }
  924. static void
  925. lpfc_mbx_issue_link_down(struct lpfc_hba *phba)
  926. {
  927. uint32_t control;
  928. struct lpfc_sli *psli = &phba->sli;
  929. lpfc_linkdown(phba);
  930. /* turn on Link Attention interrupts - no CLEAR_LA needed */
  931. spin_lock_irq(&phba->hbalock);
  932. psli->sli_flag |= LPFC_PROCESS_LA;
  933. control = readl(phba->HCregaddr);
  934. control |= HC_LAINT_ENA;
  935. writel(control, phba->HCregaddr);
  936. readl(phba->HCregaddr); /* flush */
  937. spin_unlock_irq(&phba->hbalock);
  938. }
  939. /*
  940. * This routine handles processing a READ_LA mailbox
  941. * command upon completion. It is setup in the LPFC_MBOXQ
  942. * as the completion routine when the command is
  943. * handed off to the SLI layer.
  944. */
  945. void
  946. lpfc_mbx_cmpl_read_la(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  947. {
  948. struct lpfc_vport *vport = pmb->vport;
  949. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  950. READ_LA_VAR *la;
  951. MAILBOX_t *mb = &pmb->mb;
  952. struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
  953. /* Check for error */
  954. if (mb->mbxStatus) {
  955. lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
  956. "1307 READ_LA mbox error x%x state x%x\n",
  957. mb->mbxStatus, vport->port_state);
  958. lpfc_mbx_issue_link_down(phba);
  959. phba->link_state = LPFC_HBA_ERROR;
  960. goto lpfc_mbx_cmpl_read_la_free_mbuf;
  961. }
  962. la = (READ_LA_VAR *) & pmb->mb.un.varReadLA;
  963. memcpy(&phba->alpa_map[0], mp->virt, 128);
  964. spin_lock_irq(shost->host_lock);
  965. if (la->pb)
  966. vport->fc_flag |= FC_BYPASSED_MODE;
  967. else
  968. vport->fc_flag &= ~FC_BYPASSED_MODE;
  969. spin_unlock_irq(shost->host_lock);
  970. if (((phba->fc_eventTag + 1) < la->eventTag) ||
  971. (phba->fc_eventTag == la->eventTag)) {
  972. phba->fc_stat.LinkMultiEvent++;
  973. if (la->attType == AT_LINK_UP)
  974. if (phba->fc_eventTag != 0)
  975. lpfc_linkdown(phba);
  976. }
  977. phba->fc_eventTag = la->eventTag;
  978. if (la->attType == AT_LINK_UP) {
  979. phba->fc_stat.LinkUp++;
  980. if (phba->link_flag & LS_LOOPBACK_MODE) {
  981. lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
  982. "1306 Link Up Event in loop back mode "
  983. "x%x received Data: x%x x%x x%x x%x\n",
  984. la->eventTag, phba->fc_eventTag,
  985. la->granted_AL_PA, la->UlnkSpeed,
  986. phba->alpa_map[0]);
  987. } else {
  988. lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
  989. "1303 Link Up Event x%x received "
  990. "Data: x%x x%x x%x x%x\n",
  991. la->eventTag, phba->fc_eventTag,
  992. la->granted_AL_PA, la->UlnkSpeed,
  993. phba->alpa_map[0]);
  994. }
  995. lpfc_mbx_process_link_up(phba, la);
  996. } else {
  997. phba->fc_stat.LinkDown++;
  998. if (phba->link_flag & LS_LOOPBACK_MODE) {
  999. lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
  1000. "1308 Link Down Event in loop back mode "
  1001. "x%x received "
  1002. "Data: x%x x%x x%x\n",
  1003. la->eventTag, phba->fc_eventTag,
  1004. phba->pport->port_state, vport->fc_flag);
  1005. }
  1006. else {
  1007. lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
  1008. "1305 Link Down Event x%x received "
  1009. "Data: x%x x%x x%x\n",
  1010. la->eventTag, phba->fc_eventTag,
  1011. phba->pport->port_state, vport->fc_flag);
  1012. }
  1013. lpfc_mbx_issue_link_down(phba);
  1014. }
  1015. lpfc_mbx_cmpl_read_la_free_mbuf:
  1016. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  1017. kfree(mp);
  1018. mempool_free(pmb, phba->mbox_mem_pool);
  1019. return;
  1020. }
  1021. /*
  1022. * This routine handles processing a REG_LOGIN mailbox
  1023. * command upon completion. It is setup in the LPFC_MBOXQ
  1024. * as the completion routine when the command is
  1025. * handed off to the SLI layer.
  1026. */
  1027. void
  1028. lpfc_mbx_cmpl_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  1029. {
  1030. struct lpfc_vport *vport = pmb->vport;
  1031. struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
  1032. struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
  1033. pmb->context1 = NULL;
  1034. /* Good status, call state machine */
  1035. lpfc_disc_state_machine(vport, ndlp, pmb, NLP_EVT_CMPL_REG_LOGIN);
  1036. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  1037. kfree(mp);
  1038. mempool_free(pmb, phba->mbox_mem_pool);
  1039. /* decrement the node reference count held for this callback
  1040. * function.
  1041. */
  1042. lpfc_nlp_put(ndlp);
  1043. return;
  1044. }
  1045. static void
  1046. lpfc_mbx_cmpl_unreg_vpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  1047. {
  1048. MAILBOX_t *mb = &pmb->mb;
  1049. struct lpfc_vport *vport = pmb->vport;
  1050. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  1051. switch (mb->mbxStatus) {
  1052. case 0x0011:
  1053. case 0x0020:
  1054. case 0x9700:
  1055. lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
  1056. "0911 cmpl_unreg_vpi, mb status = 0x%x\n",
  1057. mb->mbxStatus);
  1058. break;
  1059. }
  1060. vport->unreg_vpi_cmpl = VPORT_OK;
  1061. mempool_free(pmb, phba->mbox_mem_pool);
  1062. /*
  1063. * This shost reference might have been taken at the beginning of
  1064. * lpfc_vport_delete()
  1065. */
  1066. if (vport->load_flag & FC_UNLOADING)
  1067. scsi_host_put(shost);
  1068. }
  1069. void
  1070. lpfc_mbx_unreg_vpi(struct lpfc_vport *vport)
  1071. {
  1072. struct lpfc_hba *phba = vport->phba;
  1073. LPFC_MBOXQ_t *mbox;
  1074. int rc;
  1075. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  1076. if (!mbox)
  1077. return;
  1078. lpfc_unreg_vpi(phba, vport->vpi, mbox);
  1079. mbox->vport = vport;
  1080. mbox->mbox_cmpl = lpfc_mbx_cmpl_unreg_vpi;
  1081. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
  1082. if (rc == MBX_NOT_FINISHED) {
  1083. lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX | LOG_VPORT,
  1084. "1800 Could not issue unreg_vpi\n");
  1085. mempool_free(mbox, phba->mbox_mem_pool);
  1086. vport->unreg_vpi_cmpl = VPORT_ERROR;
  1087. }
  1088. }
  1089. static void
  1090. lpfc_mbx_cmpl_reg_vpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  1091. {
  1092. struct lpfc_vport *vport = pmb->vport;
  1093. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  1094. MAILBOX_t *mb = &pmb->mb;
  1095. switch (mb->mbxStatus) {
  1096. case 0x0011:
  1097. case 0x9601:
  1098. case 0x9602:
  1099. lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
  1100. "0912 cmpl_reg_vpi, mb status = 0x%x\n",
  1101. mb->mbxStatus);
  1102. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  1103. spin_lock_irq(shost->host_lock);
  1104. vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
  1105. spin_unlock_irq(shost->host_lock);
  1106. vport->fc_myDID = 0;
  1107. goto out;
  1108. }
  1109. vport->num_disc_nodes = 0;
  1110. /* go thru NPR list and issue ELS PLOGIs */
  1111. if (vport->fc_npr_cnt)
  1112. lpfc_els_disc_plogi(vport);
  1113. if (!vport->num_disc_nodes) {
  1114. spin_lock_irq(shost->host_lock);
  1115. vport->fc_flag &= ~FC_NDISC_ACTIVE;
  1116. spin_unlock_irq(shost->host_lock);
  1117. lpfc_can_disctmo(vport);
  1118. }
  1119. vport->port_state = LPFC_VPORT_READY;
  1120. out:
  1121. mempool_free(pmb, phba->mbox_mem_pool);
  1122. return;
  1123. }
  1124. /*
  1125. * This routine handles processing a Fabric REG_LOGIN mailbox
  1126. * command upon completion. It is setup in the LPFC_MBOXQ
  1127. * as the completion routine when the command is
  1128. * handed off to the SLI layer.
  1129. */
  1130. void
  1131. lpfc_mbx_cmpl_fabric_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  1132. {
  1133. struct lpfc_vport *vport = pmb->vport;
  1134. MAILBOX_t *mb = &pmb->mb;
  1135. struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
  1136. struct lpfc_nodelist *ndlp;
  1137. struct lpfc_vport **vports;
  1138. int i;
  1139. ndlp = (struct lpfc_nodelist *) pmb->context2;
  1140. pmb->context1 = NULL;
  1141. pmb->context2 = NULL;
  1142. if (mb->mbxStatus) {
  1143. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  1144. kfree(mp);
  1145. mempool_free(pmb, phba->mbox_mem_pool);
  1146. if (phba->fc_topology == TOPOLOGY_LOOP) {
  1147. /* FLOGI failed, use loop map to make discovery list */
  1148. lpfc_disc_list_loopmap(vport);
  1149. /* Start discovery */
  1150. lpfc_disc_start(vport);
  1151. /* Decrement the reference count to ndlp after the
  1152. * reference to the ndlp are done.
  1153. */
  1154. lpfc_nlp_put(ndlp);
  1155. return;
  1156. }
  1157. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  1158. lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
  1159. "0258 Register Fabric login error: 0x%x\n",
  1160. mb->mbxStatus);
  1161. /* Decrement the reference count to ndlp after the reference
  1162. * to the ndlp are done.
  1163. */
  1164. lpfc_nlp_put(ndlp);
  1165. return;
  1166. }
  1167. ndlp->nlp_rpi = mb->un.varWords[0];
  1168. ndlp->nlp_type |= NLP_FABRIC;
  1169. lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
  1170. if (vport->port_state == LPFC_FABRIC_CFG_LINK) {
  1171. vports = lpfc_create_vport_work_array(phba);
  1172. if (vports != NULL)
  1173. for(i = 0;
  1174. i <= phba->max_vpi && vports[i] != NULL;
  1175. i++) {
  1176. if (vports[i]->port_type == LPFC_PHYSICAL_PORT)
  1177. continue;
  1178. if (phba->link_flag & LS_NPIV_FAB_SUPPORTED)
  1179. lpfc_initial_fdisc(vports[i]);
  1180. else if (phba->sli3_options &
  1181. LPFC_SLI3_NPIV_ENABLED) {
  1182. lpfc_vport_set_state(vports[i],
  1183. FC_VPORT_NO_FABRIC_SUPP);
  1184. lpfc_printf_vlog(vport, KERN_ERR,
  1185. LOG_ELS,
  1186. "0259 No NPIV "
  1187. "Fabric support\n");
  1188. }
  1189. }
  1190. lpfc_destroy_vport_work_array(phba, vports);
  1191. lpfc_do_scr_ns_plogi(phba, vport);
  1192. }
  1193. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  1194. kfree(mp);
  1195. mempool_free(pmb, phba->mbox_mem_pool);
  1196. /* Drop the reference count from the mbox at the end after
  1197. * all the current reference to the ndlp have been done.
  1198. */
  1199. lpfc_nlp_put(ndlp);
  1200. return;
  1201. }
  1202. /*
  1203. * This routine handles processing a NameServer REG_LOGIN mailbox
  1204. * command upon completion. It is setup in the LPFC_MBOXQ
  1205. * as the completion routine when the command is
  1206. * handed off to the SLI layer.
  1207. */
  1208. void
  1209. lpfc_mbx_cmpl_ns_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  1210. {
  1211. MAILBOX_t *mb = &pmb->mb;
  1212. struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
  1213. struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
  1214. struct lpfc_vport *vport = pmb->vport;
  1215. if (mb->mbxStatus) {
  1216. out:
  1217. /* decrement the node reference count held for this
  1218. * callback function.
  1219. */
  1220. lpfc_nlp_put(ndlp);
  1221. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  1222. kfree(mp);
  1223. mempool_free(pmb, phba->mbox_mem_pool);
  1224. /* If no other thread is using the ndlp, free it */
  1225. lpfc_nlp_not_used(ndlp);
  1226. if (phba->fc_topology == TOPOLOGY_LOOP) {
  1227. /*
  1228. * RegLogin failed, use loop map to make discovery
  1229. * list
  1230. */
  1231. lpfc_disc_list_loopmap(vport);
  1232. /* Start discovery */
  1233. lpfc_disc_start(vport);
  1234. return;
  1235. }
  1236. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  1237. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  1238. "0260 Register NameServer error: 0x%x\n",
  1239. mb->mbxStatus);
  1240. return;
  1241. }
  1242. pmb->context1 = NULL;
  1243. ndlp->nlp_rpi = mb->un.varWords[0];
  1244. ndlp->nlp_type |= NLP_FABRIC;
  1245. lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
  1246. if (vport->port_state < LPFC_VPORT_READY) {
  1247. /* Link up discovery requires Fabric registration. */
  1248. lpfc_ns_cmd(vport, SLI_CTNS_RFF_ID, 0, 0); /* Do this first! */
  1249. lpfc_ns_cmd(vport, SLI_CTNS_RNN_ID, 0, 0);
  1250. lpfc_ns_cmd(vport, SLI_CTNS_RSNN_NN, 0, 0);
  1251. lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0);
  1252. lpfc_ns_cmd(vport, SLI_CTNS_RFT_ID, 0, 0);
  1253. /* Issue SCR just before NameServer GID_FT Query */
  1254. lpfc_issue_els_scr(vport, SCR_DID, 0);
  1255. }
  1256. vport->fc_ns_retry = 0;
  1257. /* Good status, issue CT Request to NameServer */
  1258. if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, 0)) {
  1259. /* Cannot issue NameServer Query, so finish up discovery */
  1260. goto out;
  1261. }
  1262. /* decrement the node reference count held for this
  1263. * callback function.
  1264. */
  1265. lpfc_nlp_put(ndlp);
  1266. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  1267. kfree(mp);
  1268. mempool_free(pmb, phba->mbox_mem_pool);
  1269. return;
  1270. }
  1271. static void
  1272. lpfc_register_remote_port(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
  1273. {
  1274. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  1275. struct fc_rport *rport;
  1276. struct lpfc_rport_data *rdata;
  1277. struct fc_rport_identifiers rport_ids;
  1278. struct lpfc_hba *phba = vport->phba;
  1279. /* Remote port has reappeared. Re-register w/ FC transport */
  1280. rport_ids.node_name = wwn_to_u64(ndlp->nlp_nodename.u.wwn);
  1281. rport_ids.port_name = wwn_to_u64(ndlp->nlp_portname.u.wwn);
  1282. rport_ids.port_id = ndlp->nlp_DID;
  1283. rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
  1284. /*
  1285. * We leave our node pointer in rport->dd_data when we unregister a
  1286. * FCP target port. But fc_remote_port_add zeros the space to which
  1287. * rport->dd_data points. So, if we're reusing a previously
  1288. * registered port, drop the reference that we took the last time we
  1289. * registered the port.
  1290. */
  1291. if (ndlp->rport && ndlp->rport->dd_data &&
  1292. ((struct lpfc_rport_data *) ndlp->rport->dd_data)->pnode == ndlp)
  1293. lpfc_nlp_put(ndlp);
  1294. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
  1295. "rport add: did:x%x flg:x%x type x%x",
  1296. ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type);
  1297. ndlp->rport = rport = fc_remote_port_add(shost, 0, &rport_ids);
  1298. if (!rport || !get_device(&rport->dev)) {
  1299. dev_printk(KERN_WARNING, &phba->pcidev->dev,
  1300. "Warning: fc_remote_port_add failed\n");
  1301. return;
  1302. }
  1303. /* initialize static port data */
  1304. rport->maxframe_size = ndlp->nlp_maxframe;
  1305. rport->supported_classes = ndlp->nlp_class_sup;
  1306. rdata = rport->dd_data;
  1307. rdata->pnode = lpfc_nlp_get(ndlp);
  1308. if (ndlp->nlp_type & NLP_FCP_TARGET)
  1309. rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
  1310. if (ndlp->nlp_type & NLP_FCP_INITIATOR)
  1311. rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
  1312. if (rport_ids.roles != FC_RPORT_ROLE_UNKNOWN)
  1313. fc_remote_port_rolechg(rport, rport_ids.roles);
  1314. if ((rport->scsi_target_id != -1) &&
  1315. (rport->scsi_target_id < LPFC_MAX_TARGET)) {
  1316. ndlp->nlp_sid = rport->scsi_target_id;
  1317. }
  1318. return;
  1319. }
  1320. static void
  1321. lpfc_unregister_remote_port(struct lpfc_nodelist *ndlp)
  1322. {
  1323. struct fc_rport *rport = ndlp->rport;
  1324. lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_RPORT,
  1325. "rport delete: did:x%x flg:x%x type x%x",
  1326. ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type);
  1327. fc_remote_port_delete(rport);
  1328. return;
  1329. }
  1330. static void
  1331. lpfc_nlp_counters(struct lpfc_vport *vport, int state, int count)
  1332. {
  1333. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  1334. spin_lock_irq(shost->host_lock);
  1335. switch (state) {
  1336. case NLP_STE_UNUSED_NODE:
  1337. vport->fc_unused_cnt += count;
  1338. break;
  1339. case NLP_STE_PLOGI_ISSUE:
  1340. vport->fc_plogi_cnt += count;
  1341. break;
  1342. case NLP_STE_ADISC_ISSUE:
  1343. vport->fc_adisc_cnt += count;
  1344. break;
  1345. case NLP_STE_REG_LOGIN_ISSUE:
  1346. vport->fc_reglogin_cnt += count;
  1347. break;
  1348. case NLP_STE_PRLI_ISSUE:
  1349. vport->fc_prli_cnt += count;
  1350. break;
  1351. case NLP_STE_UNMAPPED_NODE:
  1352. vport->fc_unmap_cnt += count;
  1353. break;
  1354. case NLP_STE_MAPPED_NODE:
  1355. vport->fc_map_cnt += count;
  1356. break;
  1357. case NLP_STE_NPR_NODE:
  1358. vport->fc_npr_cnt += count;
  1359. break;
  1360. }
  1361. spin_unlock_irq(shost->host_lock);
  1362. }
  1363. static void
  1364. lpfc_nlp_state_cleanup(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  1365. int old_state, int new_state)
  1366. {
  1367. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  1368. if (new_state == NLP_STE_UNMAPPED_NODE) {
  1369. ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
  1370. ndlp->nlp_flag &= ~NLP_NODEV_REMOVE;
  1371. ndlp->nlp_type |= NLP_FC_NODE;
  1372. }
  1373. if (new_state == NLP_STE_MAPPED_NODE)
  1374. ndlp->nlp_flag &= ~NLP_NODEV_REMOVE;
  1375. if (new_state == NLP_STE_NPR_NODE)
  1376. ndlp->nlp_flag &= ~NLP_RCV_PLOGI;
  1377. /* Transport interface */
  1378. if (ndlp->rport && (old_state == NLP_STE_MAPPED_NODE ||
  1379. old_state == NLP_STE_UNMAPPED_NODE)) {
  1380. vport->phba->nport_event_cnt++;
  1381. lpfc_unregister_remote_port(ndlp);
  1382. }
  1383. if (new_state == NLP_STE_MAPPED_NODE ||
  1384. new_state == NLP_STE_UNMAPPED_NODE) {
  1385. vport->phba->nport_event_cnt++;
  1386. /*
  1387. * Tell the fc transport about the port, if we haven't
  1388. * already. If we have, and it's a scsi entity, be
  1389. * sure to unblock any attached scsi devices
  1390. */
  1391. lpfc_register_remote_port(vport, ndlp);
  1392. }
  1393. /*
  1394. * if we added to Mapped list, but the remote port
  1395. * registration failed or assigned a target id outside
  1396. * our presentable range - move the node to the
  1397. * Unmapped List
  1398. */
  1399. if (new_state == NLP_STE_MAPPED_NODE &&
  1400. (!ndlp->rport ||
  1401. ndlp->rport->scsi_target_id == -1 ||
  1402. ndlp->rport->scsi_target_id >= LPFC_MAX_TARGET)) {
  1403. spin_lock_irq(shost->host_lock);
  1404. ndlp->nlp_flag |= NLP_TGT_NO_SCSIID;
  1405. spin_unlock_irq(shost->host_lock);
  1406. lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
  1407. }
  1408. }
  1409. static char *
  1410. lpfc_nlp_state_name(char *buffer, size_t size, int state)
  1411. {
  1412. static char *states[] = {
  1413. [NLP_STE_UNUSED_NODE] = "UNUSED",
  1414. [NLP_STE_PLOGI_ISSUE] = "PLOGI",
  1415. [NLP_STE_ADISC_ISSUE] = "ADISC",
  1416. [NLP_STE_REG_LOGIN_ISSUE] = "REGLOGIN",
  1417. [NLP_STE_PRLI_ISSUE] = "PRLI",
  1418. [NLP_STE_UNMAPPED_NODE] = "UNMAPPED",
  1419. [NLP_STE_MAPPED_NODE] = "MAPPED",
  1420. [NLP_STE_NPR_NODE] = "NPR",
  1421. };
  1422. if (state < NLP_STE_MAX_STATE && states[state])
  1423. strlcpy(buffer, states[state], size);
  1424. else
  1425. snprintf(buffer, size, "unknown (%d)", state);
  1426. return buffer;
  1427. }
  1428. void
  1429. lpfc_nlp_set_state(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  1430. int state)
  1431. {
  1432. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  1433. int old_state = ndlp->nlp_state;
  1434. char name1[16], name2[16];
  1435. lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
  1436. "0904 NPort state transition x%06x, %s -> %s\n",
  1437. ndlp->nlp_DID,
  1438. lpfc_nlp_state_name(name1, sizeof(name1), old_state),
  1439. lpfc_nlp_state_name(name2, sizeof(name2), state));
  1440. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE,
  1441. "node statechg did:x%x old:%d ste:%d",
  1442. ndlp->nlp_DID, old_state, state);
  1443. if (old_state == NLP_STE_NPR_NODE &&
  1444. (ndlp->nlp_flag & NLP_DELAY_TMO) != 0 &&
  1445. state != NLP_STE_NPR_NODE)
  1446. lpfc_cancel_retry_delay_tmo(vport, ndlp);
  1447. if (old_state == NLP_STE_UNMAPPED_NODE) {
  1448. ndlp->nlp_flag &= ~NLP_TGT_NO_SCSIID;
  1449. ndlp->nlp_type &= ~NLP_FC_NODE;
  1450. }
  1451. if (list_empty(&ndlp->nlp_listp)) {
  1452. spin_lock_irq(shost->host_lock);
  1453. list_add_tail(&ndlp->nlp_listp, &vport->fc_nodes);
  1454. spin_unlock_irq(shost->host_lock);
  1455. } else if (old_state)
  1456. lpfc_nlp_counters(vport, old_state, -1);
  1457. ndlp->nlp_state = state;
  1458. lpfc_nlp_counters(vport, state, 1);
  1459. lpfc_nlp_state_cleanup(vport, ndlp, old_state, state);
  1460. }
  1461. void
  1462. lpfc_enqueue_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
  1463. {
  1464. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  1465. if (list_empty(&ndlp->nlp_listp)) {
  1466. spin_lock_irq(shost->host_lock);
  1467. list_add_tail(&ndlp->nlp_listp, &vport->fc_nodes);
  1468. spin_unlock_irq(shost->host_lock);
  1469. }
  1470. }
  1471. void
  1472. lpfc_dequeue_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
  1473. {
  1474. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  1475. if ((ndlp->nlp_flag & NLP_DELAY_TMO) != 0)
  1476. lpfc_cancel_retry_delay_tmo(vport, ndlp);
  1477. if (ndlp->nlp_state && !list_empty(&ndlp->nlp_listp))
  1478. lpfc_nlp_counters(vport, ndlp->nlp_state, -1);
  1479. spin_lock_irq(shost->host_lock);
  1480. list_del_init(&ndlp->nlp_listp);
  1481. spin_unlock_irq(shost->host_lock);
  1482. lpfc_nlp_state_cleanup(vport, ndlp, ndlp->nlp_state,
  1483. NLP_STE_UNUSED_NODE);
  1484. }
  1485. static void
  1486. lpfc_disable_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
  1487. {
  1488. if ((ndlp->nlp_flag & NLP_DELAY_TMO) != 0)
  1489. lpfc_cancel_retry_delay_tmo(vport, ndlp);
  1490. if (ndlp->nlp_state && !list_empty(&ndlp->nlp_listp))
  1491. lpfc_nlp_counters(vport, ndlp->nlp_state, -1);
  1492. lpfc_nlp_state_cleanup(vport, ndlp, ndlp->nlp_state,
  1493. NLP_STE_UNUSED_NODE);
  1494. }
  1495. struct lpfc_nodelist *
  1496. lpfc_enable_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  1497. int state)
  1498. {
  1499. struct lpfc_hba *phba = vport->phba;
  1500. uint32_t did;
  1501. unsigned long flags;
  1502. if (!ndlp)
  1503. return NULL;
  1504. spin_lock_irqsave(&phba->ndlp_lock, flags);
  1505. /* The ndlp should not be in memory free mode */
  1506. if (NLP_CHK_FREE_REQ(ndlp)) {
  1507. spin_unlock_irqrestore(&phba->ndlp_lock, flags);
  1508. lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE,
  1509. "0277 lpfc_enable_node: ndlp:x%p "
  1510. "usgmap:x%x refcnt:%d\n",
  1511. (void *)ndlp, ndlp->nlp_usg_map,
  1512. atomic_read(&ndlp->kref.refcount));
  1513. return NULL;
  1514. }
  1515. /* The ndlp should not already be in active mode */
  1516. if (NLP_CHK_NODE_ACT(ndlp)) {
  1517. spin_unlock_irqrestore(&phba->ndlp_lock, flags);
  1518. lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE,
  1519. "0278 lpfc_enable_node: ndlp:x%p "
  1520. "usgmap:x%x refcnt:%d\n",
  1521. (void *)ndlp, ndlp->nlp_usg_map,
  1522. atomic_read(&ndlp->kref.refcount));
  1523. return NULL;
  1524. }
  1525. /* Keep the original DID */
  1526. did = ndlp->nlp_DID;
  1527. /* re-initialize ndlp except of ndlp linked list pointer */
  1528. memset((((char *)ndlp) + sizeof (struct list_head)), 0,
  1529. sizeof (struct lpfc_nodelist) - sizeof (struct list_head));
  1530. INIT_LIST_HEAD(&ndlp->els_retry_evt.evt_listp);
  1531. INIT_LIST_HEAD(&ndlp->dev_loss_evt.evt_listp);
  1532. init_timer(&ndlp->nlp_delayfunc);
  1533. ndlp->nlp_delayfunc.function = lpfc_els_retry_delay;
  1534. ndlp->nlp_delayfunc.data = (unsigned long)ndlp;
  1535. ndlp->nlp_DID = did;
  1536. ndlp->vport = vport;
  1537. ndlp->nlp_sid = NLP_NO_SID;
  1538. /* ndlp management re-initialize */
  1539. kref_init(&ndlp->kref);
  1540. NLP_INT_NODE_ACT(ndlp);
  1541. spin_unlock_irqrestore(&phba->ndlp_lock, flags);
  1542. if (state != NLP_STE_UNUSED_NODE)
  1543. lpfc_nlp_set_state(vport, ndlp, state);
  1544. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE,
  1545. "node enable: did:x%x",
  1546. ndlp->nlp_DID, 0, 0);
  1547. return ndlp;
  1548. }
  1549. void
  1550. lpfc_drop_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
  1551. {
  1552. /*
  1553. * Use of lpfc_drop_node and UNUSED list: lpfc_drop_node should
  1554. * be used if we wish to issue the "last" lpfc_nlp_put() to remove
  1555. * the ndlp from the vport. The ndlp marked as UNUSED on the list
  1556. * until ALL other outstanding threads have completed. We check
  1557. * that the ndlp not already in the UNUSED state before we proceed.
  1558. */
  1559. if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
  1560. return;
  1561. lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNUSED_NODE);
  1562. lpfc_nlp_put(ndlp);
  1563. return;
  1564. }
  1565. /*
  1566. * Start / ReStart rescue timer for Discovery / RSCN handling
  1567. */
  1568. void
  1569. lpfc_set_disctmo(struct lpfc_vport *vport)
  1570. {
  1571. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  1572. struct lpfc_hba *phba = vport->phba;
  1573. uint32_t tmo;
  1574. if (vport->port_state == LPFC_LOCAL_CFG_LINK) {
  1575. /* For FAN, timeout should be greater then edtov */
  1576. tmo = (((phba->fc_edtov + 999) / 1000) + 1);
  1577. } else {
  1578. /* Normal discovery timeout should be > then ELS/CT timeout
  1579. * FC spec states we need 3 * ratov for CT requests
  1580. */
  1581. tmo = ((phba->fc_ratov * 3) + 3);
  1582. }
  1583. if (!timer_pending(&vport->fc_disctmo)) {
  1584. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  1585. "set disc timer: tmo:x%x state:x%x flg:x%x",
  1586. tmo, vport->port_state, vport->fc_flag);
  1587. }
  1588. mod_timer(&vport->fc_disctmo, jiffies + HZ * tmo);
  1589. spin_lock_irq(shost->host_lock);
  1590. vport->fc_flag |= FC_DISC_TMO;
  1591. spin_unlock_irq(shost->host_lock);
  1592. /* Start Discovery Timer state <hba_state> */
  1593. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  1594. "0247 Start Discovery Timer state x%x "
  1595. "Data: x%x x%lx x%x x%x\n",
  1596. vport->port_state, tmo,
  1597. (unsigned long)&vport->fc_disctmo, vport->fc_plogi_cnt,
  1598. vport->fc_adisc_cnt);
  1599. return;
  1600. }
  1601. /*
  1602. * Cancel rescue timer for Discovery / RSCN handling
  1603. */
  1604. int
  1605. lpfc_can_disctmo(struct lpfc_vport *vport)
  1606. {
  1607. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  1608. unsigned long iflags;
  1609. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  1610. "can disc timer: state:x%x rtry:x%x flg:x%x",
  1611. vport->port_state, vport->fc_ns_retry, vport->fc_flag);
  1612. /* Turn off discovery timer if its running */
  1613. if (vport->fc_flag & FC_DISC_TMO) {
  1614. spin_lock_irqsave(shost->host_lock, iflags);
  1615. vport->fc_flag &= ~FC_DISC_TMO;
  1616. spin_unlock_irqrestore(shost->host_lock, iflags);
  1617. del_timer_sync(&vport->fc_disctmo);
  1618. spin_lock_irqsave(&vport->work_port_lock, iflags);
  1619. vport->work_port_events &= ~WORKER_DISC_TMO;
  1620. spin_unlock_irqrestore(&vport->work_port_lock, iflags);
  1621. }
  1622. /* Cancel Discovery Timer state <hba_state> */
  1623. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  1624. "0248 Cancel Discovery Timer state x%x "
  1625. "Data: x%x x%x x%x\n",
  1626. vport->port_state, vport->fc_flag,
  1627. vport->fc_plogi_cnt, vport->fc_adisc_cnt);
  1628. return 0;
  1629. }
  1630. /*
  1631. * Check specified ring for outstanding IOCB on the SLI queue
  1632. * Return true if iocb matches the specified nport
  1633. */
  1634. int
  1635. lpfc_check_sli_ndlp(struct lpfc_hba *phba,
  1636. struct lpfc_sli_ring *pring,
  1637. struct lpfc_iocbq *iocb,
  1638. struct lpfc_nodelist *ndlp)
  1639. {
  1640. struct lpfc_sli *psli = &phba->sli;
  1641. IOCB_t *icmd = &iocb->iocb;
  1642. struct lpfc_vport *vport = ndlp->vport;
  1643. if (iocb->vport != vport)
  1644. return 0;
  1645. if (pring->ringno == LPFC_ELS_RING) {
  1646. switch (icmd->ulpCommand) {
  1647. case CMD_GEN_REQUEST64_CR:
  1648. if (icmd->ulpContext == (volatile ushort)ndlp->nlp_rpi)
  1649. return 1;
  1650. case CMD_ELS_REQUEST64_CR:
  1651. if (icmd->un.elsreq64.remoteID == ndlp->nlp_DID)
  1652. return 1;
  1653. case CMD_XMIT_ELS_RSP64_CX:
  1654. if (iocb->context1 == (uint8_t *) ndlp)
  1655. return 1;
  1656. }
  1657. } else if (pring->ringno == psli->extra_ring) {
  1658. } else if (pring->ringno == psli->fcp_ring) {
  1659. /* Skip match check if waiting to relogin to FCP target */
  1660. if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
  1661. (ndlp->nlp_flag & NLP_DELAY_TMO)) {
  1662. return 0;
  1663. }
  1664. if (icmd->ulpContext == (volatile ushort)ndlp->nlp_rpi) {
  1665. return 1;
  1666. }
  1667. } else if (pring->ringno == psli->next_ring) {
  1668. }
  1669. return 0;
  1670. }
  1671. /*
  1672. * Free resources / clean up outstanding I/Os
  1673. * associated with nlp_rpi in the LPFC_NODELIST entry.
  1674. */
  1675. static int
  1676. lpfc_no_rpi(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
  1677. {
  1678. LIST_HEAD(completions);
  1679. struct lpfc_sli *psli;
  1680. struct lpfc_sli_ring *pring;
  1681. struct lpfc_iocbq *iocb, *next_iocb;
  1682. IOCB_t *icmd;
  1683. uint32_t rpi, i;
  1684. lpfc_fabric_abort_nport(ndlp);
  1685. /*
  1686. * Everything that matches on txcmplq will be returned
  1687. * by firmware with a no rpi error.
  1688. */
  1689. psli = &phba->sli;
  1690. rpi = ndlp->nlp_rpi;
  1691. if (rpi) {
  1692. /* Now process each ring */
  1693. for (i = 0; i < psli->num_rings; i++) {
  1694. pring = &psli->ring[i];
  1695. spin_lock_irq(&phba->hbalock);
  1696. list_for_each_entry_safe(iocb, next_iocb, &pring->txq,
  1697. list) {
  1698. /*
  1699. * Check to see if iocb matches the nport we are
  1700. * looking for
  1701. */
  1702. if ((lpfc_check_sli_ndlp(phba, pring, iocb,
  1703. ndlp))) {
  1704. /* It matches, so deque and call compl
  1705. with an error */
  1706. list_move_tail(&iocb->list,
  1707. &completions);
  1708. pring->txq_cnt--;
  1709. }
  1710. }
  1711. spin_unlock_irq(&phba->hbalock);
  1712. }
  1713. }
  1714. while (!list_empty(&completions)) {
  1715. iocb = list_get_first(&completions, struct lpfc_iocbq, list);
  1716. list_del_init(&iocb->list);
  1717. if (!iocb->iocb_cmpl)
  1718. lpfc_sli_release_iocbq(phba, iocb);
  1719. else {
  1720. icmd = &iocb->iocb;
  1721. icmd->ulpStatus = IOSTAT_LOCAL_REJECT;
  1722. icmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
  1723. (iocb->iocb_cmpl)(phba, iocb, iocb);
  1724. }
  1725. }
  1726. return 0;
  1727. }
  1728. /*
  1729. * Free rpi associated with LPFC_NODELIST entry.
  1730. * This routine is called from lpfc_freenode(), when we are removing
  1731. * a LPFC_NODELIST entry. It is also called if the driver initiates a
  1732. * LOGO that completes successfully, and we are waiting to PLOGI back
  1733. * to the remote NPort. In addition, it is called after we receive
  1734. * and unsolicated ELS cmd, send back a rsp, the rsp completes and
  1735. * we are waiting to PLOGI back to the remote NPort.
  1736. */
  1737. int
  1738. lpfc_unreg_rpi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
  1739. {
  1740. struct lpfc_hba *phba = vport->phba;
  1741. LPFC_MBOXQ_t *mbox;
  1742. int rc;
  1743. if (ndlp->nlp_rpi) {
  1744. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  1745. if (mbox) {
  1746. lpfc_unreg_login(phba, vport->vpi, ndlp->nlp_rpi, mbox);
  1747. mbox->vport = vport;
  1748. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  1749. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
  1750. if (rc == MBX_NOT_FINISHED)
  1751. mempool_free(mbox, phba->mbox_mem_pool);
  1752. }
  1753. lpfc_no_rpi(phba, ndlp);
  1754. ndlp->nlp_rpi = 0;
  1755. return 1;
  1756. }
  1757. return 0;
  1758. }
  1759. void
  1760. lpfc_unreg_all_rpis(struct lpfc_vport *vport)
  1761. {
  1762. struct lpfc_hba *phba = vport->phba;
  1763. LPFC_MBOXQ_t *mbox;
  1764. int rc;
  1765. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  1766. if (mbox) {
  1767. lpfc_unreg_login(phba, vport->vpi, 0xffff, mbox);
  1768. mbox->vport = vport;
  1769. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  1770. mbox->context1 = NULL;
  1771. rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO);
  1772. if (rc == MBX_NOT_FINISHED) {
  1773. mempool_free(mbox, phba->mbox_mem_pool);
  1774. }
  1775. }
  1776. }
  1777. void
  1778. lpfc_unreg_default_rpis(struct lpfc_vport *vport)
  1779. {
  1780. struct lpfc_hba *phba = vport->phba;
  1781. LPFC_MBOXQ_t *mbox;
  1782. int rc;
  1783. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  1784. if (mbox) {
  1785. lpfc_unreg_did(phba, vport->vpi, 0xffffffff, mbox);
  1786. mbox->vport = vport;
  1787. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  1788. mbox->context1 = NULL;
  1789. rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO);
  1790. if (rc == MBX_NOT_FINISHED) {
  1791. lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX | LOG_VPORT,
  1792. "1815 Could not issue "
  1793. "unreg_did (default rpis)\n");
  1794. mempool_free(mbox, phba->mbox_mem_pool);
  1795. }
  1796. }
  1797. }
  1798. /*
  1799. * Free resources associated with LPFC_NODELIST entry
  1800. * so it can be freed.
  1801. */
  1802. static int
  1803. lpfc_cleanup_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
  1804. {
  1805. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  1806. struct lpfc_hba *phba = vport->phba;
  1807. LPFC_MBOXQ_t *mb, *nextmb;
  1808. struct lpfc_dmabuf *mp;
  1809. /* Cleanup node for NPort <nlp_DID> */
  1810. lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
  1811. "0900 Cleanup node for NPort x%x "
  1812. "Data: x%x x%x x%x\n",
  1813. ndlp->nlp_DID, ndlp->nlp_flag,
  1814. ndlp->nlp_state, ndlp->nlp_rpi);
  1815. if (NLP_CHK_FREE_REQ(ndlp)) {
  1816. lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE,
  1817. "0280 lpfc_cleanup_node: ndlp:x%p "
  1818. "usgmap:x%x refcnt:%d\n",
  1819. (void *)ndlp, ndlp->nlp_usg_map,
  1820. atomic_read(&ndlp->kref.refcount));
  1821. lpfc_dequeue_node(vport, ndlp);
  1822. } else {
  1823. lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE,
  1824. "0281 lpfc_cleanup_node: ndlp:x%p "
  1825. "usgmap:x%x refcnt:%d\n",
  1826. (void *)ndlp, ndlp->nlp_usg_map,
  1827. atomic_read(&ndlp->kref.refcount));
  1828. lpfc_disable_node(vport, ndlp);
  1829. }
  1830. /* cleanup any ndlp on mbox q waiting for reglogin cmpl */
  1831. if ((mb = phba->sli.mbox_active)) {
  1832. if ((mb->mb.mbxCommand == MBX_REG_LOGIN64) &&
  1833. (ndlp == (struct lpfc_nodelist *) mb->context2)) {
  1834. mb->context2 = NULL;
  1835. mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  1836. }
  1837. }
  1838. spin_lock_irq(&phba->hbalock);
  1839. list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
  1840. if ((mb->mb.mbxCommand == MBX_REG_LOGIN64) &&
  1841. (ndlp == (struct lpfc_nodelist *) mb->context2)) {
  1842. mp = (struct lpfc_dmabuf *) (mb->context1);
  1843. if (mp) {
  1844. __lpfc_mbuf_free(phba, mp->virt, mp->phys);
  1845. kfree(mp);
  1846. }
  1847. list_del(&mb->list);
  1848. mempool_free(mb, phba->mbox_mem_pool);
  1849. /* We shall not invoke the lpfc_nlp_put to decrement
  1850. * the ndlp reference count as we are in the process
  1851. * of lpfc_nlp_release.
  1852. */
  1853. }
  1854. }
  1855. spin_unlock_irq(&phba->hbalock);
  1856. lpfc_els_abort(phba, ndlp);
  1857. spin_lock_irq(shost->host_lock);
  1858. ndlp->nlp_flag &= ~NLP_DELAY_TMO;
  1859. spin_unlock_irq(shost->host_lock);
  1860. ndlp->nlp_last_elscmd = 0;
  1861. del_timer_sync(&ndlp->nlp_delayfunc);
  1862. if (!list_empty(&ndlp->els_retry_evt.evt_listp))
  1863. list_del_init(&ndlp->els_retry_evt.evt_listp);
  1864. if (!list_empty(&ndlp->dev_loss_evt.evt_listp))
  1865. list_del_init(&ndlp->dev_loss_evt.evt_listp);
  1866. lpfc_unreg_rpi(vport, ndlp);
  1867. return 0;
  1868. }
  1869. /*
  1870. * Check to see if we can free the nlp back to the freelist.
  1871. * If we are in the middle of using the nlp in the discovery state
  1872. * machine, defer the free till we reach the end of the state machine.
  1873. */
  1874. static void
  1875. lpfc_nlp_remove(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
  1876. {
  1877. struct lpfc_hba *phba = vport->phba;
  1878. struct lpfc_rport_data *rdata;
  1879. LPFC_MBOXQ_t *mbox;
  1880. int rc;
  1881. if (ndlp->nlp_flag & NLP_DELAY_TMO) {
  1882. lpfc_cancel_retry_delay_tmo(vport, ndlp);
  1883. }
  1884. if (ndlp->nlp_flag & NLP_DEFER_RM && !ndlp->nlp_rpi) {
  1885. /* For this case we need to cleanup the default rpi
  1886. * allocated by the firmware.
  1887. */
  1888. if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL))
  1889. != NULL) {
  1890. rc = lpfc_reg_login(phba, vport->vpi, ndlp->nlp_DID,
  1891. (uint8_t *) &vport->fc_sparam, mbox, 0);
  1892. if (rc) {
  1893. mempool_free(mbox, phba->mbox_mem_pool);
  1894. }
  1895. else {
  1896. mbox->mbox_flag |= LPFC_MBX_IMED_UNREG;
  1897. mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
  1898. mbox->vport = vport;
  1899. mbox->context2 = NULL;
  1900. rc =lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
  1901. if (rc == MBX_NOT_FINISHED) {
  1902. mempool_free(mbox, phba->mbox_mem_pool);
  1903. }
  1904. }
  1905. }
  1906. }
  1907. lpfc_cleanup_node(vport, ndlp);
  1908. /*
  1909. * We can get here with a non-NULL ndlp->rport because when we
  1910. * unregister a rport we don't break the rport/node linkage. So if we
  1911. * do, make sure we don't leaving any dangling pointers behind.
  1912. */
  1913. if (ndlp->rport) {
  1914. rdata = ndlp->rport->dd_data;
  1915. rdata->pnode = NULL;
  1916. ndlp->rport = NULL;
  1917. }
  1918. }
  1919. static int
  1920. lpfc_matchdid(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  1921. uint32_t did)
  1922. {
  1923. D_ID mydid, ndlpdid, matchdid;
  1924. if (did == Bcast_DID)
  1925. return 0;
  1926. if (ndlp->nlp_DID == 0) {
  1927. return 0;
  1928. }
  1929. /* First check for Direct match */
  1930. if (ndlp->nlp_DID == did)
  1931. return 1;
  1932. /* Next check for area/domain identically equals 0 match */
  1933. mydid.un.word = vport->fc_myDID;
  1934. if ((mydid.un.b.domain == 0) && (mydid.un.b.area == 0)) {
  1935. return 0;
  1936. }
  1937. matchdid.un.word = did;
  1938. ndlpdid.un.word = ndlp->nlp_DID;
  1939. if (matchdid.un.b.id == ndlpdid.un.b.id) {
  1940. if ((mydid.un.b.domain == matchdid.un.b.domain) &&
  1941. (mydid.un.b.area == matchdid.un.b.area)) {
  1942. if ((ndlpdid.un.b.domain == 0) &&
  1943. (ndlpdid.un.b.area == 0)) {
  1944. if (ndlpdid.un.b.id)
  1945. return 1;
  1946. }
  1947. return 0;
  1948. }
  1949. matchdid.un.word = ndlp->nlp_DID;
  1950. if ((mydid.un.b.domain == ndlpdid.un.b.domain) &&
  1951. (mydid.un.b.area == ndlpdid.un.b.area)) {
  1952. if ((matchdid.un.b.domain == 0) &&
  1953. (matchdid.un.b.area == 0)) {
  1954. if (matchdid.un.b.id)
  1955. return 1;
  1956. }
  1957. }
  1958. }
  1959. return 0;
  1960. }
  1961. /* Search for a nodelist entry */
  1962. static struct lpfc_nodelist *
  1963. __lpfc_findnode_did(struct lpfc_vport *vport, uint32_t did)
  1964. {
  1965. struct lpfc_nodelist *ndlp;
  1966. uint32_t data1;
  1967. list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
  1968. if (lpfc_matchdid(vport, ndlp, did)) {
  1969. data1 = (((uint32_t) ndlp->nlp_state << 24) |
  1970. ((uint32_t) ndlp->nlp_xri << 16) |
  1971. ((uint32_t) ndlp->nlp_type << 8) |
  1972. ((uint32_t) ndlp->nlp_rpi & 0xff));
  1973. lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
  1974. "0929 FIND node DID "
  1975. "Data: x%p x%x x%x x%x\n",
  1976. ndlp, ndlp->nlp_DID,
  1977. ndlp->nlp_flag, data1);
  1978. return ndlp;
  1979. }
  1980. }
  1981. /* FIND node did <did> NOT FOUND */
  1982. lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
  1983. "0932 FIND node did x%x NOT FOUND.\n", did);
  1984. return NULL;
  1985. }
  1986. struct lpfc_nodelist *
  1987. lpfc_findnode_did(struct lpfc_vport *vport, uint32_t did)
  1988. {
  1989. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  1990. struct lpfc_nodelist *ndlp;
  1991. spin_lock_irq(shost->host_lock);
  1992. ndlp = __lpfc_findnode_did(vport, did);
  1993. spin_unlock_irq(shost->host_lock);
  1994. return ndlp;
  1995. }
  1996. struct lpfc_nodelist *
  1997. lpfc_setup_disc_node(struct lpfc_vport *vport, uint32_t did)
  1998. {
  1999. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2000. struct lpfc_nodelist *ndlp;
  2001. ndlp = lpfc_findnode_did(vport, did);
  2002. if (!ndlp) {
  2003. if ((vport->fc_flag & FC_RSCN_MODE) != 0 &&
  2004. lpfc_rscn_payload_check(vport, did) == 0)
  2005. return NULL;
  2006. ndlp = (struct lpfc_nodelist *)
  2007. mempool_alloc(vport->phba->nlp_mem_pool, GFP_KERNEL);
  2008. if (!ndlp)
  2009. return NULL;
  2010. lpfc_nlp_init(vport, ndlp, did);
  2011. lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
  2012. spin_lock_irq(shost->host_lock);
  2013. ndlp->nlp_flag |= NLP_NPR_2B_DISC;
  2014. spin_unlock_irq(shost->host_lock);
  2015. return ndlp;
  2016. } else if (!NLP_CHK_NODE_ACT(ndlp)) {
  2017. ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_NPR_NODE);
  2018. if (!ndlp)
  2019. return NULL;
  2020. spin_lock_irq(shost->host_lock);
  2021. ndlp->nlp_flag |= NLP_NPR_2B_DISC;
  2022. spin_unlock_irq(shost->host_lock);
  2023. return ndlp;
  2024. }
  2025. if (vport->fc_flag & FC_RSCN_MODE) {
  2026. if (lpfc_rscn_payload_check(vport, did)) {
  2027. /* If we've already recieved a PLOGI from this NPort
  2028. * we don't need to try to discover it again.
  2029. */
  2030. if (ndlp->nlp_flag & NLP_RCV_PLOGI)
  2031. return NULL;
  2032. spin_lock_irq(shost->host_lock);
  2033. ndlp->nlp_flag |= NLP_NPR_2B_DISC;
  2034. spin_unlock_irq(shost->host_lock);
  2035. /* Since this node is marked for discovery,
  2036. * delay timeout is not needed.
  2037. */
  2038. if (ndlp->nlp_flag & NLP_DELAY_TMO)
  2039. lpfc_cancel_retry_delay_tmo(vport, ndlp);
  2040. } else
  2041. ndlp = NULL;
  2042. } else {
  2043. /* If we've already recieved a PLOGI from this NPort,
  2044. * or we are already in the process of discovery on it,
  2045. * we don't need to try to discover it again.
  2046. */
  2047. if (ndlp->nlp_state == NLP_STE_ADISC_ISSUE ||
  2048. ndlp->nlp_state == NLP_STE_PLOGI_ISSUE ||
  2049. ndlp->nlp_flag & NLP_RCV_PLOGI)
  2050. return NULL;
  2051. lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
  2052. spin_lock_irq(shost->host_lock);
  2053. ndlp->nlp_flag |= NLP_NPR_2B_DISC;
  2054. spin_unlock_irq(shost->host_lock);
  2055. }
  2056. return ndlp;
  2057. }
  2058. /* Build a list of nodes to discover based on the loopmap */
  2059. void
  2060. lpfc_disc_list_loopmap(struct lpfc_vport *vport)
  2061. {
  2062. struct lpfc_hba *phba = vport->phba;
  2063. int j;
  2064. uint32_t alpa, index;
  2065. if (!lpfc_is_link_up(phba))
  2066. return;
  2067. if (phba->fc_topology != TOPOLOGY_LOOP)
  2068. return;
  2069. /* Check for loop map present or not */
  2070. if (phba->alpa_map[0]) {
  2071. for (j = 1; j <= phba->alpa_map[0]; j++) {
  2072. alpa = phba->alpa_map[j];
  2073. if (((vport->fc_myDID & 0xff) == alpa) || (alpa == 0))
  2074. continue;
  2075. lpfc_setup_disc_node(vport, alpa);
  2076. }
  2077. } else {
  2078. /* No alpamap, so try all alpa's */
  2079. for (j = 0; j < FC_MAXLOOP; j++) {
  2080. /* If cfg_scan_down is set, start from highest
  2081. * ALPA (0xef) to lowest (0x1).
  2082. */
  2083. if (vport->cfg_scan_down)
  2084. index = j;
  2085. else
  2086. index = FC_MAXLOOP - j - 1;
  2087. alpa = lpfcAlpaArray[index];
  2088. if ((vport->fc_myDID & 0xff) == alpa)
  2089. continue;
  2090. lpfc_setup_disc_node(vport, alpa);
  2091. }
  2092. }
  2093. return;
  2094. }
  2095. void
  2096. lpfc_issue_clear_la(struct lpfc_hba *phba, struct lpfc_vport *vport)
  2097. {
  2098. LPFC_MBOXQ_t *mbox;
  2099. struct lpfc_sli *psli = &phba->sli;
  2100. struct lpfc_sli_ring *extra_ring = &psli->ring[psli->extra_ring];
  2101. struct lpfc_sli_ring *fcp_ring = &psli->ring[psli->fcp_ring];
  2102. struct lpfc_sli_ring *next_ring = &psli->ring[psli->next_ring];
  2103. int rc;
  2104. /*
  2105. * if it's not a physical port or if we already send
  2106. * clear_la then don't send it.
  2107. */
  2108. if ((phba->link_state >= LPFC_CLEAR_LA) ||
  2109. (vport->port_type != LPFC_PHYSICAL_PORT))
  2110. return;
  2111. /* Link up discovery */
  2112. if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL)) != NULL) {
  2113. phba->link_state = LPFC_CLEAR_LA;
  2114. lpfc_clear_la(phba, mbox);
  2115. mbox->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
  2116. mbox->vport = vport;
  2117. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
  2118. if (rc == MBX_NOT_FINISHED) {
  2119. mempool_free(mbox, phba->mbox_mem_pool);
  2120. lpfc_disc_flush_list(vport);
  2121. extra_ring->flag &= ~LPFC_STOP_IOCB_EVENT;
  2122. fcp_ring->flag &= ~LPFC_STOP_IOCB_EVENT;
  2123. next_ring->flag &= ~LPFC_STOP_IOCB_EVENT;
  2124. phba->link_state = LPFC_HBA_ERROR;
  2125. }
  2126. }
  2127. }
  2128. /* Reg_vpi to tell firmware to resume normal operations */
  2129. void
  2130. lpfc_issue_reg_vpi(struct lpfc_hba *phba, struct lpfc_vport *vport)
  2131. {
  2132. LPFC_MBOXQ_t *regvpimbox;
  2133. regvpimbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  2134. if (regvpimbox) {
  2135. lpfc_reg_vpi(phba, vport->vpi, vport->fc_myDID, regvpimbox);
  2136. regvpimbox->mbox_cmpl = lpfc_mbx_cmpl_reg_vpi;
  2137. regvpimbox->vport = vport;
  2138. if (lpfc_sli_issue_mbox(phba, regvpimbox, MBX_NOWAIT)
  2139. == MBX_NOT_FINISHED) {
  2140. mempool_free(regvpimbox, phba->mbox_mem_pool);
  2141. }
  2142. }
  2143. }
  2144. /* Start Link up / RSCN discovery on NPR nodes */
  2145. void
  2146. lpfc_disc_start(struct lpfc_vport *vport)
  2147. {
  2148. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2149. struct lpfc_hba *phba = vport->phba;
  2150. uint32_t num_sent;
  2151. uint32_t clear_la_pending;
  2152. int did_changed;
  2153. if (!lpfc_is_link_up(phba))
  2154. return;
  2155. if (phba->link_state == LPFC_CLEAR_LA)
  2156. clear_la_pending = 1;
  2157. else
  2158. clear_la_pending = 0;
  2159. if (vport->port_state < LPFC_VPORT_READY)
  2160. vport->port_state = LPFC_DISC_AUTH;
  2161. lpfc_set_disctmo(vport);
  2162. if (vport->fc_prevDID == vport->fc_myDID)
  2163. did_changed = 0;
  2164. else
  2165. did_changed = 1;
  2166. vport->fc_prevDID = vport->fc_myDID;
  2167. vport->num_disc_nodes = 0;
  2168. /* Start Discovery state <hba_state> */
  2169. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  2170. "0202 Start Discovery hba state x%x "
  2171. "Data: x%x x%x x%x\n",
  2172. vport->port_state, vport->fc_flag, vport->fc_plogi_cnt,
  2173. vport->fc_adisc_cnt);
  2174. /* First do ADISCs - if any */
  2175. num_sent = lpfc_els_disc_adisc(vport);
  2176. if (num_sent)
  2177. return;
  2178. /*
  2179. * For SLI3, cmpl_reg_vpi will set port_state to READY, and
  2180. * continue discovery.
  2181. */
  2182. if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
  2183. !(vport->fc_flag & FC_PT2PT) &&
  2184. !(vport->fc_flag & FC_RSCN_MODE)) {
  2185. lpfc_issue_reg_vpi(phba, vport);
  2186. return;
  2187. }
  2188. /*
  2189. * For SLI2, we need to set port_state to READY and continue
  2190. * discovery.
  2191. */
  2192. if (vport->port_state < LPFC_VPORT_READY && !clear_la_pending) {
  2193. /* If we get here, there is nothing to ADISC */
  2194. if (vport->port_type == LPFC_PHYSICAL_PORT)
  2195. lpfc_issue_clear_la(phba, vport);
  2196. if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
  2197. vport->num_disc_nodes = 0;
  2198. /* go thru NPR nodes and issue ELS PLOGIs */
  2199. if (vport->fc_npr_cnt)
  2200. lpfc_els_disc_plogi(vport);
  2201. if (!vport->num_disc_nodes) {
  2202. spin_lock_irq(shost->host_lock);
  2203. vport->fc_flag &= ~FC_NDISC_ACTIVE;
  2204. spin_unlock_irq(shost->host_lock);
  2205. lpfc_can_disctmo(vport);
  2206. }
  2207. }
  2208. vport->port_state = LPFC_VPORT_READY;
  2209. } else {
  2210. /* Next do PLOGIs - if any */
  2211. num_sent = lpfc_els_disc_plogi(vport);
  2212. if (num_sent)
  2213. return;
  2214. if (vport->fc_flag & FC_RSCN_MODE) {
  2215. /* Check to see if more RSCNs came in while we
  2216. * were processing this one.
  2217. */
  2218. if ((vport->fc_rscn_id_cnt == 0) &&
  2219. (!(vport->fc_flag & FC_RSCN_DISCOVERY))) {
  2220. spin_lock_irq(shost->host_lock);
  2221. vport->fc_flag &= ~FC_RSCN_MODE;
  2222. spin_unlock_irq(shost->host_lock);
  2223. lpfc_can_disctmo(vport);
  2224. } else
  2225. lpfc_els_handle_rscn(vport);
  2226. }
  2227. }
  2228. return;
  2229. }
  2230. /*
  2231. * Ignore completion for all IOCBs on tx and txcmpl queue for ELS
  2232. * ring the match the sppecified nodelist.
  2233. */
  2234. static void
  2235. lpfc_free_tx(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
  2236. {
  2237. LIST_HEAD(completions);
  2238. struct lpfc_sli *psli;
  2239. IOCB_t *icmd;
  2240. struct lpfc_iocbq *iocb, *next_iocb;
  2241. struct lpfc_sli_ring *pring;
  2242. psli = &phba->sli;
  2243. pring = &psli->ring[LPFC_ELS_RING];
  2244. /* Error matching iocb on txq or txcmplq
  2245. * First check the txq.
  2246. */
  2247. spin_lock_irq(&phba->hbalock);
  2248. list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
  2249. if (iocb->context1 != ndlp) {
  2250. continue;
  2251. }
  2252. icmd = &iocb->iocb;
  2253. if ((icmd->ulpCommand == CMD_ELS_REQUEST64_CR) ||
  2254. (icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX)) {
  2255. list_move_tail(&iocb->list, &completions);
  2256. pring->txq_cnt--;
  2257. }
  2258. }
  2259. /* Next check the txcmplq */
  2260. list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
  2261. if (iocb->context1 != ndlp) {
  2262. continue;
  2263. }
  2264. icmd = &iocb->iocb;
  2265. if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR ||
  2266. icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX) {
  2267. lpfc_sli_issue_abort_iotag(phba, pring, iocb);
  2268. }
  2269. }
  2270. spin_unlock_irq(&phba->hbalock);
  2271. while (!list_empty(&completions)) {
  2272. iocb = list_get_first(&completions, struct lpfc_iocbq, list);
  2273. list_del_init(&iocb->list);
  2274. if (!iocb->iocb_cmpl)
  2275. lpfc_sli_release_iocbq(phba, iocb);
  2276. else {
  2277. icmd = &iocb->iocb;
  2278. icmd->ulpStatus = IOSTAT_LOCAL_REJECT;
  2279. icmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
  2280. (iocb->iocb_cmpl) (phba, iocb, iocb);
  2281. }
  2282. }
  2283. }
  2284. static void
  2285. lpfc_disc_flush_list(struct lpfc_vport *vport)
  2286. {
  2287. struct lpfc_nodelist *ndlp, *next_ndlp;
  2288. struct lpfc_hba *phba = vport->phba;
  2289. if (vport->fc_plogi_cnt || vport->fc_adisc_cnt) {
  2290. list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes,
  2291. nlp_listp) {
  2292. if (!NLP_CHK_NODE_ACT(ndlp))
  2293. continue;
  2294. if (ndlp->nlp_state == NLP_STE_PLOGI_ISSUE ||
  2295. ndlp->nlp_state == NLP_STE_ADISC_ISSUE) {
  2296. lpfc_free_tx(phba, ndlp);
  2297. }
  2298. }
  2299. }
  2300. }
  2301. void
  2302. lpfc_cleanup_discovery_resources(struct lpfc_vport *vport)
  2303. {
  2304. lpfc_els_flush_rscn(vport);
  2305. lpfc_els_flush_cmd(vport);
  2306. lpfc_disc_flush_list(vport);
  2307. }
  2308. /*****************************************************************************/
  2309. /*
  2310. * NAME: lpfc_disc_timeout
  2311. *
  2312. * FUNCTION: Fibre Channel driver discovery timeout routine.
  2313. *
  2314. * EXECUTION ENVIRONMENT: interrupt only
  2315. *
  2316. * CALLED FROM:
  2317. * Timer function
  2318. *
  2319. * RETURNS:
  2320. * none
  2321. */
  2322. /*****************************************************************************/
  2323. void
  2324. lpfc_disc_timeout(unsigned long ptr)
  2325. {
  2326. struct lpfc_vport *vport = (struct lpfc_vport *) ptr;
  2327. struct lpfc_hba *phba = vport->phba;
  2328. unsigned long flags = 0;
  2329. if (unlikely(!phba))
  2330. return;
  2331. if ((vport->work_port_events & WORKER_DISC_TMO) == 0) {
  2332. spin_lock_irqsave(&vport->work_port_lock, flags);
  2333. vport->work_port_events |= WORKER_DISC_TMO;
  2334. spin_unlock_irqrestore(&vport->work_port_lock, flags);
  2335. spin_lock_irqsave(&phba->hbalock, flags);
  2336. if (phba->work_wait)
  2337. lpfc_worker_wake_up(phba);
  2338. spin_unlock_irqrestore(&phba->hbalock, flags);
  2339. }
  2340. return;
  2341. }
  2342. static void
  2343. lpfc_disc_timeout_handler(struct lpfc_vport *vport)
  2344. {
  2345. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2346. struct lpfc_hba *phba = vport->phba;
  2347. struct lpfc_sli *psli = &phba->sli;
  2348. struct lpfc_nodelist *ndlp, *next_ndlp;
  2349. LPFC_MBOXQ_t *initlinkmbox;
  2350. int rc, clrlaerr = 0;
  2351. if (!(vport->fc_flag & FC_DISC_TMO))
  2352. return;
  2353. spin_lock_irq(shost->host_lock);
  2354. vport->fc_flag &= ~FC_DISC_TMO;
  2355. spin_unlock_irq(shost->host_lock);
  2356. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  2357. "disc timeout: state:x%x rtry:x%x flg:x%x",
  2358. vport->port_state, vport->fc_ns_retry, vport->fc_flag);
  2359. switch (vport->port_state) {
  2360. case LPFC_LOCAL_CFG_LINK:
  2361. /* port_state is identically LPFC_LOCAL_CFG_LINK while waiting for
  2362. * FAN
  2363. */
  2364. /* FAN timeout */
  2365. lpfc_printf_vlog(vport, KERN_WARNING, LOG_DISCOVERY,
  2366. "0221 FAN timeout\n");
  2367. /* Start discovery by sending FLOGI, clean up old rpis */
  2368. list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes,
  2369. nlp_listp) {
  2370. if (!NLP_CHK_NODE_ACT(ndlp))
  2371. continue;
  2372. if (ndlp->nlp_state != NLP_STE_NPR_NODE)
  2373. continue;
  2374. if (ndlp->nlp_type & NLP_FABRIC) {
  2375. /* Clean up the ndlp on Fabric connections */
  2376. lpfc_drop_node(vport, ndlp);
  2377. } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
  2378. /* Fail outstanding IO now since device
  2379. * is marked for PLOGI.
  2380. */
  2381. lpfc_unreg_rpi(vport, ndlp);
  2382. }
  2383. }
  2384. if (vport->port_state != LPFC_FLOGI) {
  2385. lpfc_initial_flogi(vport);
  2386. return;
  2387. }
  2388. break;
  2389. case LPFC_FDISC:
  2390. case LPFC_FLOGI:
  2391. /* port_state is identically LPFC_FLOGI while waiting for FLOGI cmpl */
  2392. /* Initial FLOGI timeout */
  2393. lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
  2394. "0222 Initial %s timeout\n",
  2395. vport->vpi ? "FDISC" : "FLOGI");
  2396. /* Assume no Fabric and go on with discovery.
  2397. * Check for outstanding ELS FLOGI to abort.
  2398. */
  2399. /* FLOGI failed, so just use loop map to make discovery list */
  2400. lpfc_disc_list_loopmap(vport);
  2401. /* Start discovery */
  2402. lpfc_disc_start(vport);
  2403. break;
  2404. case LPFC_FABRIC_CFG_LINK:
  2405. /* hba_state is identically LPFC_FABRIC_CFG_LINK while waiting for
  2406. NameServer login */
  2407. lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
  2408. "0223 Timeout while waiting for "
  2409. "NameServer login\n");
  2410. /* Next look for NameServer ndlp */
  2411. ndlp = lpfc_findnode_did(vport, NameServer_DID);
  2412. if (ndlp && NLP_CHK_NODE_ACT(ndlp))
  2413. lpfc_els_abort(phba, ndlp);
  2414. /* ReStart discovery */
  2415. goto restart_disc;
  2416. case LPFC_NS_QRY:
  2417. /* Check for wait for NameServer Rsp timeout */
  2418. lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
  2419. "0224 NameServer Query timeout "
  2420. "Data: x%x x%x\n",
  2421. vport->fc_ns_retry, LPFC_MAX_NS_RETRY);
  2422. if (vport->fc_ns_retry < LPFC_MAX_NS_RETRY) {
  2423. /* Try it one more time */
  2424. vport->fc_ns_retry++;
  2425. rc = lpfc_ns_cmd(vport, SLI_CTNS_GID_FT,
  2426. vport->fc_ns_retry, 0);
  2427. if (rc == 0)
  2428. break;
  2429. }
  2430. vport->fc_ns_retry = 0;
  2431. restart_disc:
  2432. /*
  2433. * Discovery is over.
  2434. * set port_state to PORT_READY if SLI2.
  2435. * cmpl_reg_vpi will set port_state to READY for SLI3.
  2436. */
  2437. if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
  2438. lpfc_issue_reg_vpi(phba, vport);
  2439. else { /* NPIV Not enabled */
  2440. lpfc_issue_clear_la(phba, vport);
  2441. vport->port_state = LPFC_VPORT_READY;
  2442. }
  2443. /* Setup and issue mailbox INITIALIZE LINK command */
  2444. initlinkmbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  2445. if (!initlinkmbox) {
  2446. lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
  2447. "0206 Device Discovery "
  2448. "completion error\n");
  2449. phba->link_state = LPFC_HBA_ERROR;
  2450. break;
  2451. }
  2452. lpfc_linkdown(phba);
  2453. lpfc_init_link(phba, initlinkmbox, phba->cfg_topology,
  2454. phba->cfg_link_speed);
  2455. initlinkmbox->mb.un.varInitLnk.lipsr_AL_PA = 0;
  2456. initlinkmbox->vport = vport;
  2457. initlinkmbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  2458. rc = lpfc_sli_issue_mbox(phba, initlinkmbox, MBX_NOWAIT);
  2459. lpfc_set_loopback_flag(phba);
  2460. if (rc == MBX_NOT_FINISHED)
  2461. mempool_free(initlinkmbox, phba->mbox_mem_pool);
  2462. break;
  2463. case LPFC_DISC_AUTH:
  2464. /* Node Authentication timeout */
  2465. lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
  2466. "0227 Node Authentication timeout\n");
  2467. lpfc_disc_flush_list(vport);
  2468. /*
  2469. * set port_state to PORT_READY if SLI2.
  2470. * cmpl_reg_vpi will set port_state to READY for SLI3.
  2471. */
  2472. if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
  2473. lpfc_issue_reg_vpi(phba, vport);
  2474. else { /* NPIV Not enabled */
  2475. lpfc_issue_clear_la(phba, vport);
  2476. vport->port_state = LPFC_VPORT_READY;
  2477. }
  2478. break;
  2479. case LPFC_VPORT_READY:
  2480. if (vport->fc_flag & FC_RSCN_MODE) {
  2481. lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
  2482. "0231 RSCN timeout Data: x%x "
  2483. "x%x\n",
  2484. vport->fc_ns_retry, LPFC_MAX_NS_RETRY);
  2485. /* Cleanup any outstanding ELS commands */
  2486. lpfc_els_flush_cmd(vport);
  2487. lpfc_els_flush_rscn(vport);
  2488. lpfc_disc_flush_list(vport);
  2489. }
  2490. break;
  2491. default:
  2492. lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
  2493. "0229 Unexpected discovery timeout, "
  2494. "vport State x%x\n", vport->port_state);
  2495. break;
  2496. }
  2497. switch (phba->link_state) {
  2498. case LPFC_CLEAR_LA:
  2499. /* CLEAR LA timeout */
  2500. lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
  2501. "0228 CLEAR LA timeout\n");
  2502. clrlaerr = 1;
  2503. break;
  2504. case LPFC_LINK_UP:
  2505. lpfc_issue_clear_la(phba, vport);
  2506. /* Drop thru */
  2507. case LPFC_LINK_UNKNOWN:
  2508. case LPFC_WARM_START:
  2509. case LPFC_INIT_START:
  2510. case LPFC_INIT_MBX_CMDS:
  2511. case LPFC_LINK_DOWN:
  2512. case LPFC_HBA_ERROR:
  2513. lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
  2514. "0230 Unexpected timeout, hba link "
  2515. "state x%x\n", phba->link_state);
  2516. clrlaerr = 1;
  2517. break;
  2518. case LPFC_HBA_READY:
  2519. break;
  2520. }
  2521. if (clrlaerr) {
  2522. lpfc_disc_flush_list(vport);
  2523. psli->ring[(psli->extra_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
  2524. psli->ring[(psli->fcp_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
  2525. psli->ring[(psli->next_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
  2526. vport->port_state = LPFC_VPORT_READY;
  2527. }
  2528. return;
  2529. }
  2530. /*
  2531. * This routine handles processing a NameServer REG_LOGIN mailbox
  2532. * command upon completion. It is setup in the LPFC_MBOXQ
  2533. * as the completion routine when the command is
  2534. * handed off to the SLI layer.
  2535. */
  2536. void
  2537. lpfc_mbx_cmpl_fdmi_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  2538. {
  2539. MAILBOX_t *mb = &pmb->mb;
  2540. struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
  2541. struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
  2542. struct lpfc_vport *vport = pmb->vport;
  2543. pmb->context1 = NULL;
  2544. ndlp->nlp_rpi = mb->un.varWords[0];
  2545. ndlp->nlp_type |= NLP_FABRIC;
  2546. lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
  2547. /*
  2548. * Start issuing Fabric-Device Management Interface (FDMI) command to
  2549. * 0xfffffa (FDMI well known port) or Delay issuing FDMI command if
  2550. * fdmi-on=2 (supporting RPA/hostnmae)
  2551. */
  2552. if (vport->cfg_fdmi_on == 1)
  2553. lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA);
  2554. else
  2555. mod_timer(&vport->fc_fdmitmo, jiffies + HZ * 60);
  2556. /* decrement the node reference count held for this callback
  2557. * function.
  2558. */
  2559. lpfc_nlp_put(ndlp);
  2560. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  2561. kfree(mp);
  2562. mempool_free(pmb, phba->mbox_mem_pool);
  2563. return;
  2564. }
  2565. static int
  2566. lpfc_filter_by_rpi(struct lpfc_nodelist *ndlp, void *param)
  2567. {
  2568. uint16_t *rpi = param;
  2569. return ndlp->nlp_rpi == *rpi;
  2570. }
  2571. static int
  2572. lpfc_filter_by_wwpn(struct lpfc_nodelist *ndlp, void *param)
  2573. {
  2574. return memcmp(&ndlp->nlp_portname, param,
  2575. sizeof(ndlp->nlp_portname)) == 0;
  2576. }
  2577. static struct lpfc_nodelist *
  2578. __lpfc_find_node(struct lpfc_vport *vport, node_filter filter, void *param)
  2579. {
  2580. struct lpfc_nodelist *ndlp;
  2581. list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
  2582. if (filter(ndlp, param))
  2583. return ndlp;
  2584. }
  2585. return NULL;
  2586. }
  2587. #if 0
  2588. /*
  2589. * Search node lists for a remote port matching filter criteria
  2590. * Caller needs to hold host_lock before calling this routine.
  2591. */
  2592. struct lpfc_nodelist *
  2593. lpfc_find_node(struct lpfc_vport *vport, node_filter filter, void *param)
  2594. {
  2595. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2596. struct lpfc_nodelist *ndlp;
  2597. spin_lock_irq(shost->host_lock);
  2598. ndlp = __lpfc_find_node(vport, filter, param);
  2599. spin_unlock_irq(shost->host_lock);
  2600. return ndlp;
  2601. }
  2602. #endif /* 0 */
  2603. /*
  2604. * This routine looks up the ndlp lists for the given RPI. If rpi found it
  2605. * returns the node list element pointer else return NULL.
  2606. */
  2607. struct lpfc_nodelist *
  2608. __lpfc_findnode_rpi(struct lpfc_vport *vport, uint16_t rpi)
  2609. {
  2610. return __lpfc_find_node(vport, lpfc_filter_by_rpi, &rpi);
  2611. }
  2612. #if 0
  2613. struct lpfc_nodelist *
  2614. lpfc_findnode_rpi(struct lpfc_vport *vport, uint16_t rpi)
  2615. {
  2616. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2617. struct lpfc_nodelist *ndlp;
  2618. spin_lock_irq(shost->host_lock);
  2619. ndlp = __lpfc_findnode_rpi(vport, rpi);
  2620. spin_unlock_irq(shost->host_lock);
  2621. return ndlp;
  2622. }
  2623. #endif /* 0 */
  2624. /*
  2625. * This routine looks up the ndlp lists for the given WWPN. If WWPN found it
  2626. * returns the node element list pointer else return NULL.
  2627. */
  2628. struct lpfc_nodelist *
  2629. lpfc_findnode_wwpn(struct lpfc_vport *vport, struct lpfc_name *wwpn)
  2630. {
  2631. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2632. struct lpfc_nodelist *ndlp;
  2633. spin_lock_irq(shost->host_lock);
  2634. ndlp = __lpfc_find_node(vport, lpfc_filter_by_wwpn, wwpn);
  2635. spin_unlock_irq(shost->host_lock);
  2636. return ndlp;
  2637. }
  2638. void
  2639. lpfc_nlp_init(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  2640. uint32_t did)
  2641. {
  2642. memset(ndlp, 0, sizeof (struct lpfc_nodelist));
  2643. INIT_LIST_HEAD(&ndlp->els_retry_evt.evt_listp);
  2644. INIT_LIST_HEAD(&ndlp->dev_loss_evt.evt_listp);
  2645. init_timer(&ndlp->nlp_delayfunc);
  2646. ndlp->nlp_delayfunc.function = lpfc_els_retry_delay;
  2647. ndlp->nlp_delayfunc.data = (unsigned long)ndlp;
  2648. ndlp->nlp_DID = did;
  2649. ndlp->vport = vport;
  2650. ndlp->nlp_sid = NLP_NO_SID;
  2651. INIT_LIST_HEAD(&ndlp->nlp_listp);
  2652. kref_init(&ndlp->kref);
  2653. NLP_INT_NODE_ACT(ndlp);
  2654. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE,
  2655. "node init: did:x%x",
  2656. ndlp->nlp_DID, 0, 0);
  2657. return;
  2658. }
  2659. /* This routine releases all resources associated with a specifc NPort's ndlp
  2660. * and mempool_free's the nodelist.
  2661. */
  2662. static void
  2663. lpfc_nlp_release(struct kref *kref)
  2664. {
  2665. struct lpfc_hba *phba;
  2666. unsigned long flags;
  2667. struct lpfc_nodelist *ndlp = container_of(kref, struct lpfc_nodelist,
  2668. kref);
  2669. lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
  2670. "node release: did:x%x flg:x%x type:x%x",
  2671. ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type);
  2672. lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE,
  2673. "0279 lpfc_nlp_release: ndlp:x%p "
  2674. "usgmap:x%x refcnt:%d\n",
  2675. (void *)ndlp, ndlp->nlp_usg_map,
  2676. atomic_read(&ndlp->kref.refcount));
  2677. /* remove ndlp from action. */
  2678. lpfc_nlp_remove(ndlp->vport, ndlp);
  2679. /* clear the ndlp active flag for all release cases */
  2680. phba = ndlp->vport->phba;
  2681. spin_lock_irqsave(&phba->ndlp_lock, flags);
  2682. NLP_CLR_NODE_ACT(ndlp);
  2683. spin_unlock_irqrestore(&phba->ndlp_lock, flags);
  2684. /* free ndlp memory for final ndlp release */
  2685. if (NLP_CHK_FREE_REQ(ndlp))
  2686. mempool_free(ndlp, ndlp->vport->phba->nlp_mem_pool);
  2687. }
  2688. /* This routine bumps the reference count for a ndlp structure to ensure
  2689. * that one discovery thread won't free a ndlp while another discovery thread
  2690. * is using it.
  2691. */
  2692. struct lpfc_nodelist *
  2693. lpfc_nlp_get(struct lpfc_nodelist *ndlp)
  2694. {
  2695. struct lpfc_hba *phba;
  2696. unsigned long flags;
  2697. if (ndlp) {
  2698. lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
  2699. "node get: did:x%x flg:x%x refcnt:x%x",
  2700. ndlp->nlp_DID, ndlp->nlp_flag,
  2701. atomic_read(&ndlp->kref.refcount));
  2702. /* The check of ndlp usage to prevent incrementing the
  2703. * ndlp reference count that is in the process of being
  2704. * released.
  2705. */
  2706. phba = ndlp->vport->phba;
  2707. spin_lock_irqsave(&phba->ndlp_lock, flags);
  2708. if (!NLP_CHK_NODE_ACT(ndlp) || NLP_CHK_FREE_ACK(ndlp)) {
  2709. spin_unlock_irqrestore(&phba->ndlp_lock, flags);
  2710. lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_NODE,
  2711. "0276 lpfc_nlp_get: ndlp:x%p "
  2712. "usgmap:x%x refcnt:%d\n",
  2713. (void *)ndlp, ndlp->nlp_usg_map,
  2714. atomic_read(&ndlp->kref.refcount));
  2715. return NULL;
  2716. } else
  2717. kref_get(&ndlp->kref);
  2718. spin_unlock_irqrestore(&phba->ndlp_lock, flags);
  2719. }
  2720. return ndlp;
  2721. }
  2722. /* This routine decrements the reference count for a ndlp structure. If the
  2723. * count goes to 0, this indicates the the associated nodelist should be
  2724. * freed. Returning 1 indicates the ndlp resource has been released; on the
  2725. * other hand, returning 0 indicates the ndlp resource has not been released
  2726. * yet.
  2727. */
  2728. int
  2729. lpfc_nlp_put(struct lpfc_nodelist *ndlp)
  2730. {
  2731. struct lpfc_hba *phba;
  2732. unsigned long flags;
  2733. if (!ndlp)
  2734. return 1;
  2735. lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
  2736. "node put: did:x%x flg:x%x refcnt:x%x",
  2737. ndlp->nlp_DID, ndlp->nlp_flag,
  2738. atomic_read(&ndlp->kref.refcount));
  2739. phba = ndlp->vport->phba;
  2740. spin_lock_irqsave(&phba->ndlp_lock, flags);
  2741. /* Check the ndlp memory free acknowledge flag to avoid the
  2742. * possible race condition that kref_put got invoked again
  2743. * after previous one has done ndlp memory free.
  2744. */
  2745. if (NLP_CHK_FREE_ACK(ndlp)) {
  2746. spin_unlock_irqrestore(&phba->ndlp_lock, flags);
  2747. lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_NODE,
  2748. "0274 lpfc_nlp_put: ndlp:x%p "
  2749. "usgmap:x%x refcnt:%d\n",
  2750. (void *)ndlp, ndlp->nlp_usg_map,
  2751. atomic_read(&ndlp->kref.refcount));
  2752. return 1;
  2753. }
  2754. /* Check the ndlp inactivate log flag to avoid the possible
  2755. * race condition that kref_put got invoked again after ndlp
  2756. * is already in inactivating state.
  2757. */
  2758. if (NLP_CHK_IACT_REQ(ndlp)) {
  2759. spin_unlock_irqrestore(&phba->ndlp_lock, flags);
  2760. lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_NODE,
  2761. "0275 lpfc_nlp_put: ndlp:x%p "
  2762. "usgmap:x%x refcnt:%d\n",
  2763. (void *)ndlp, ndlp->nlp_usg_map,
  2764. atomic_read(&ndlp->kref.refcount));
  2765. return 1;
  2766. }
  2767. /* For last put, mark the ndlp usage flags to make sure no
  2768. * other kref_get and kref_put on the same ndlp shall get
  2769. * in between the process when the final kref_put has been
  2770. * invoked on this ndlp.
  2771. */
  2772. if (atomic_read(&ndlp->kref.refcount) == 1) {
  2773. /* Indicate ndlp is put to inactive state. */
  2774. NLP_SET_IACT_REQ(ndlp);
  2775. /* Acknowledge ndlp memory free has been seen. */
  2776. if (NLP_CHK_FREE_REQ(ndlp))
  2777. NLP_SET_FREE_ACK(ndlp);
  2778. }
  2779. spin_unlock_irqrestore(&phba->ndlp_lock, flags);
  2780. /* Note, the kref_put returns 1 when decrementing a reference
  2781. * count that was 1, it invokes the release callback function,
  2782. * but it still left the reference count as 1 (not actually
  2783. * performs the last decrementation). Otherwise, it actually
  2784. * decrements the reference count and returns 0.
  2785. */
  2786. return kref_put(&ndlp->kref, lpfc_nlp_release);
  2787. }
  2788. /* This routine free's the specified nodelist if it is not in use
  2789. * by any other discovery thread. This routine returns 1 if the
  2790. * ndlp has been freed. A return value of 0 indicates the ndlp is
  2791. * not yet been released.
  2792. */
  2793. int
  2794. lpfc_nlp_not_used(struct lpfc_nodelist *ndlp)
  2795. {
  2796. lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
  2797. "node not used: did:x%x flg:x%x refcnt:x%x",
  2798. ndlp->nlp_DID, ndlp->nlp_flag,
  2799. atomic_read(&ndlp->kref.refcount));
  2800. if (atomic_read(&ndlp->kref.refcount) == 1)
  2801. if (lpfc_nlp_put(ndlp))
  2802. return 1;
  2803. return 0;
  2804. }