lpfc_hbadisc.c 85 KB

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