lpfc_hbadisc.c 84 KB

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