lpfc_hbadisc.c 76 KB

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