lpfc_hbadisc.c 85 KB

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