lpfc_hbadisc.c 66 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545
  1. /*******************************************************************
  2. * This file is part of the Emulex Linux Device Driver for *
  3. * Fibre Channel Host Bus Adapters. *
  4. * Copyright (C) 2004-2005 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. /* AlpaArray for assignment of scsid for scan-down and bind_method */
  37. static uint8_t lpfcAlpaArray[] = {
  38. 0xEF, 0xE8, 0xE4, 0xE2, 0xE1, 0xE0, 0xDC, 0xDA, 0xD9, 0xD6,
  39. 0xD5, 0xD4, 0xD3, 0xD2, 0xD1, 0xCE, 0xCD, 0xCC, 0xCB, 0xCA,
  40. 0xC9, 0xC7, 0xC6, 0xC5, 0xC3, 0xBC, 0xBA, 0xB9, 0xB6, 0xB5,
  41. 0xB4, 0xB3, 0xB2, 0xB1, 0xAE, 0xAD, 0xAC, 0xAB, 0xAA, 0xA9,
  42. 0xA7, 0xA6, 0xA5, 0xA3, 0x9F, 0x9E, 0x9D, 0x9B, 0x98, 0x97,
  43. 0x90, 0x8F, 0x88, 0x84, 0x82, 0x81, 0x80, 0x7C, 0x7A, 0x79,
  44. 0x76, 0x75, 0x74, 0x73, 0x72, 0x71, 0x6E, 0x6D, 0x6C, 0x6B,
  45. 0x6A, 0x69, 0x67, 0x66, 0x65, 0x63, 0x5C, 0x5A, 0x59, 0x56,
  46. 0x55, 0x54, 0x53, 0x52, 0x51, 0x4E, 0x4D, 0x4C, 0x4B, 0x4A,
  47. 0x49, 0x47, 0x46, 0x45, 0x43, 0x3C, 0x3A, 0x39, 0x36, 0x35,
  48. 0x34, 0x33, 0x32, 0x31, 0x2E, 0x2D, 0x2C, 0x2B, 0x2A, 0x29,
  49. 0x27, 0x26, 0x25, 0x23, 0x1F, 0x1E, 0x1D, 0x1B, 0x18, 0x17,
  50. 0x10, 0x0F, 0x08, 0x04, 0x02, 0x01
  51. };
  52. static void lpfc_disc_timeout_handler(struct lpfc_hba *);
  53. static void
  54. lpfc_process_nodev_timeout(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
  55. {
  56. int warn_on = 0;
  57. spin_lock_irq(phba->host->host_lock);
  58. if (!(ndlp->nlp_flag & NLP_NODEV_TMO)) {
  59. spin_unlock_irq(phba->host->host_lock);
  60. return;
  61. }
  62. ndlp->nlp_flag &= ~NLP_NODEV_TMO;
  63. if (ndlp->nlp_sid != NLP_NO_SID) {
  64. warn_on = 1;
  65. /* flush the target */
  66. lpfc_sli_abort_iocb(phba, &phba->sli.ring[phba->sli.fcp_ring],
  67. ndlp->nlp_sid, 0, 0, LPFC_CTX_TGT);
  68. }
  69. spin_unlock_irq(phba->host->host_lock);
  70. if (warn_on) {
  71. lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
  72. "%d:0203 Nodev timeout on NPort x%x "
  73. "Data: x%x x%x x%x\n",
  74. phba->brd_no, ndlp->nlp_DID, ndlp->nlp_flag,
  75. ndlp->nlp_state, ndlp->nlp_rpi);
  76. } else {
  77. lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
  78. "%d:0204 Nodev timeout on NPort x%x "
  79. "Data: x%x x%x x%x\n",
  80. phba->brd_no, ndlp->nlp_DID, ndlp->nlp_flag,
  81. ndlp->nlp_state, ndlp->nlp_rpi);
  82. }
  83. lpfc_disc_state_machine(phba, ndlp, NULL, NLP_EVT_DEVICE_RM);
  84. return;
  85. }
  86. static void
  87. lpfc_work_list_done(struct lpfc_hba * phba)
  88. {
  89. struct lpfc_work_evt *evtp = NULL;
  90. struct lpfc_nodelist *ndlp;
  91. int free_evt;
  92. spin_lock_irq(phba->host->host_lock);
  93. while(!list_empty(&phba->work_list)) {
  94. list_remove_head((&phba->work_list), evtp, typeof(*evtp),
  95. evt_listp);
  96. spin_unlock_irq(phba->host->host_lock);
  97. free_evt = 1;
  98. switch(evtp->evt) {
  99. case LPFC_EVT_NODEV_TMO:
  100. ndlp = (struct lpfc_nodelist *)(evtp->evt_arg1);
  101. lpfc_process_nodev_timeout(phba, ndlp);
  102. free_evt = 0;
  103. break;
  104. case LPFC_EVT_ELS_RETRY:
  105. ndlp = (struct lpfc_nodelist *)(evtp->evt_arg1);
  106. lpfc_els_retry_delay_handler(ndlp);
  107. free_evt = 0;
  108. break;
  109. case LPFC_EVT_ONLINE:
  110. *(int *)(evtp->evt_arg1) = lpfc_online(phba);
  111. complete((struct completion *)(evtp->evt_arg2));
  112. break;
  113. case LPFC_EVT_OFFLINE:
  114. *(int *)(evtp->evt_arg1) = lpfc_offline(phba);
  115. complete((struct completion *)(evtp->evt_arg2));
  116. break;
  117. }
  118. if (free_evt)
  119. kfree(evtp);
  120. spin_lock_irq(phba->host->host_lock);
  121. }
  122. spin_unlock_irq(phba->host->host_lock);
  123. }
  124. static void
  125. lpfc_work_done(struct lpfc_hba * phba)
  126. {
  127. struct lpfc_sli_ring *pring;
  128. int i;
  129. uint32_t ha_copy;
  130. uint32_t control;
  131. uint32_t work_hba_events;
  132. spin_lock_irq(phba->host->host_lock);
  133. ha_copy = phba->work_ha;
  134. phba->work_ha = 0;
  135. work_hba_events=phba->work_hba_events;
  136. spin_unlock_irq(phba->host->host_lock);
  137. if(ha_copy & HA_ERATT)
  138. lpfc_handle_eratt(phba);
  139. if(ha_copy & HA_MBATT)
  140. lpfc_sli_handle_mb_event(phba);
  141. if(ha_copy & HA_LATT)
  142. lpfc_handle_latt(phba);
  143. if (work_hba_events & WORKER_DISC_TMO)
  144. lpfc_disc_timeout_handler(phba);
  145. if (work_hba_events & WORKER_ELS_TMO)
  146. lpfc_els_timeout_handler(phba);
  147. if (work_hba_events & WORKER_MBOX_TMO)
  148. lpfc_mbox_timeout_handler(phba);
  149. if (work_hba_events & WORKER_FDMI_TMO)
  150. lpfc_fdmi_tmo_handler(phba);
  151. spin_lock_irq(phba->host->host_lock);
  152. phba->work_hba_events &= ~work_hba_events;
  153. spin_unlock_irq(phba->host->host_lock);
  154. for (i = 0; i < phba->sli.num_rings; i++, ha_copy >>= 4) {
  155. pring = &phba->sli.ring[i];
  156. if ((ha_copy & HA_RXATT)
  157. || (pring->flag & LPFC_DEFERRED_RING_EVENT)) {
  158. if (pring->flag & LPFC_STOP_IOCB_MASK) {
  159. pring->flag |= LPFC_DEFERRED_RING_EVENT;
  160. } else {
  161. lpfc_sli_handle_slow_ring_event(phba, pring,
  162. (ha_copy &
  163. HA_RXMASK));
  164. pring->flag &= ~LPFC_DEFERRED_RING_EVENT;
  165. }
  166. /*
  167. * Turn on Ring interrupts
  168. */
  169. spin_lock_irq(phba->host->host_lock);
  170. control = readl(phba->HCregaddr);
  171. control |= (HC_R0INT_ENA << i);
  172. writel(control, phba->HCregaddr);
  173. readl(phba->HCregaddr); /* flush */
  174. spin_unlock_irq(phba->host->host_lock);
  175. }
  176. }
  177. lpfc_work_list_done (phba);
  178. }
  179. static int
  180. check_work_wait_done(struct lpfc_hba *phba) {
  181. spin_lock_irq(phba->host->host_lock);
  182. if (phba->work_ha ||
  183. phba->work_hba_events ||
  184. (!list_empty(&phba->work_list)) ||
  185. kthread_should_stop()) {
  186. spin_unlock_irq(phba->host->host_lock);
  187. return 1;
  188. } else {
  189. spin_unlock_irq(phba->host->host_lock);
  190. return 0;
  191. }
  192. }
  193. int
  194. lpfc_do_work(void *p)
  195. {
  196. struct lpfc_hba *phba = p;
  197. int rc;
  198. DECLARE_WAIT_QUEUE_HEAD(work_waitq);
  199. set_user_nice(current, -20);
  200. phba->work_wait = &work_waitq;
  201. while (1) {
  202. rc = wait_event_interruptible(work_waitq,
  203. check_work_wait_done(phba));
  204. BUG_ON(rc);
  205. if (kthread_should_stop())
  206. break;
  207. lpfc_work_done(phba);
  208. }
  209. phba->work_wait = NULL;
  210. return 0;
  211. }
  212. /*
  213. * This is only called to handle FC worker events. Since this a rare
  214. * occurance, we allocate a struct lpfc_work_evt structure here instead of
  215. * embedding it in the IOCB.
  216. */
  217. int
  218. lpfc_workq_post_event(struct lpfc_hba * phba, void *arg1, void *arg2,
  219. uint32_t evt)
  220. {
  221. struct lpfc_work_evt *evtp;
  222. /*
  223. * All Mailbox completions and LPFC_ELS_RING rcv ring IOCB events will
  224. * be queued to worker thread for processing
  225. */
  226. evtp = kmalloc(sizeof(struct lpfc_work_evt), GFP_KERNEL);
  227. if (!evtp)
  228. return 0;
  229. evtp->evt_arg1 = arg1;
  230. evtp->evt_arg2 = arg2;
  231. evtp->evt = evt;
  232. list_add_tail(&evtp->evt_listp, &phba->work_list);
  233. spin_lock_irq(phba->host->host_lock);
  234. if (phba->work_wait)
  235. wake_up(phba->work_wait);
  236. spin_unlock_irq(phba->host->host_lock);
  237. return 1;
  238. }
  239. int
  240. lpfc_linkdown(struct lpfc_hba * phba)
  241. {
  242. struct lpfc_sli *psli;
  243. struct lpfc_nodelist *ndlp, *next_ndlp;
  244. struct list_head *listp;
  245. struct list_head *node_list[7];
  246. LPFC_MBOXQ_t *mb;
  247. int rc, i;
  248. psli = &phba->sli;
  249. spin_lock_irq(phba->host->host_lock);
  250. phba->hba_state = LPFC_LINK_DOWN;
  251. spin_unlock_irq(phba->host->host_lock);
  252. /* Clean up any firmware default rpi's */
  253. if ((mb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL))) {
  254. lpfc_unreg_did(phba, 0xffffffff, mb);
  255. mb->mbox_cmpl=lpfc_sli_def_mbox_cmpl;
  256. if (lpfc_sli_issue_mbox(phba, mb, (MBX_NOWAIT | MBX_STOP_IOCB))
  257. == MBX_NOT_FINISHED) {
  258. mempool_free( mb, phba->mbox_mem_pool);
  259. }
  260. }
  261. /* Cleanup any outstanding RSCN activity */
  262. lpfc_els_flush_rscn(phba);
  263. /* Cleanup any outstanding ELS commands */
  264. lpfc_els_flush_cmd(phba);
  265. /* Issue a LINK DOWN event to all nodes */
  266. node_list[0] = &phba->fc_npr_list; /* MUST do this list first */
  267. node_list[1] = &phba->fc_nlpmap_list;
  268. node_list[2] = &phba->fc_nlpunmap_list;
  269. node_list[3] = &phba->fc_prli_list;
  270. node_list[4] = &phba->fc_reglogin_list;
  271. node_list[5] = &phba->fc_adisc_list;
  272. node_list[6] = &phba->fc_plogi_list;
  273. for (i = 0; i < 7; i++) {
  274. listp = node_list[i];
  275. if (list_empty(listp))
  276. continue;
  277. list_for_each_entry_safe(ndlp, next_ndlp, listp, nlp_listp) {
  278. /* Fabric nodes are not handled thru state machine for
  279. link down */
  280. if (ndlp->nlp_type & NLP_FABRIC) {
  281. /* Remove ALL Fabric nodes except Fabric_DID */
  282. if (ndlp->nlp_DID != Fabric_DID) {
  283. /* Take it off current list and free */
  284. lpfc_nlp_list(phba, ndlp,
  285. NLP_NO_LIST);
  286. }
  287. }
  288. else {
  289. rc = lpfc_disc_state_machine(phba, ndlp, NULL,
  290. NLP_EVT_DEVICE_RECOVERY);
  291. /* Check config parameter use-adisc or FCP-2 */
  292. if ((rc != NLP_STE_FREED_NODE) &&
  293. (phba->cfg_use_adisc == 0) &&
  294. !(ndlp->nlp_fcp_info &
  295. NLP_FCP_2_DEVICE)) {
  296. /* We know we will have to relogin, so
  297. * unreglogin the rpi right now to fail
  298. * any outstanding I/Os quickly.
  299. */
  300. lpfc_unreg_rpi(phba, ndlp);
  301. }
  302. }
  303. }
  304. }
  305. /* free any ndlp's on unused list */
  306. list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_unused_list,
  307. nlp_listp) {
  308. lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
  309. }
  310. /* Setup myDID for link up if we are in pt2pt mode */
  311. if (phba->fc_flag & FC_PT2PT) {
  312. phba->fc_myDID = 0;
  313. if ((mb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL))) {
  314. lpfc_config_link(phba, mb);
  315. mb->mbox_cmpl=lpfc_sli_def_mbox_cmpl;
  316. if (lpfc_sli_issue_mbox
  317. (phba, mb, (MBX_NOWAIT | MBX_STOP_IOCB))
  318. == MBX_NOT_FINISHED) {
  319. mempool_free( mb, phba->mbox_mem_pool);
  320. }
  321. }
  322. spin_lock_irq(phba->host->host_lock);
  323. phba->fc_flag &= ~(FC_PT2PT | FC_PT2PT_PLOGI);
  324. spin_unlock_irq(phba->host->host_lock);
  325. }
  326. spin_lock_irq(phba->host->host_lock);
  327. phba->fc_flag &= ~FC_LBIT;
  328. spin_unlock_irq(phba->host->host_lock);
  329. /* Turn off discovery timer if its running */
  330. lpfc_can_disctmo(phba);
  331. /* Must process IOCBs on all rings to handle ABORTed I/Os */
  332. return (0);
  333. }
  334. static int
  335. lpfc_linkup(struct lpfc_hba * phba)
  336. {
  337. struct lpfc_nodelist *ndlp, *next_ndlp;
  338. spin_lock_irq(phba->host->host_lock);
  339. phba->hba_state = LPFC_LINK_UP;
  340. phba->fc_flag &= ~(FC_PT2PT | FC_PT2PT_PLOGI | FC_ABORT_DISCOVERY |
  341. FC_RSCN_MODE | FC_NLP_MORE | FC_RSCN_DISCOVERY);
  342. phba->fc_flag |= FC_NDISC_ACTIVE;
  343. phba->fc_ns_retry = 0;
  344. spin_unlock_irq(phba->host->host_lock);
  345. /*
  346. * Clean up old Fabric NLP_FABRIC logins.
  347. */
  348. list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_nlpunmap_list,
  349. nlp_listp) {
  350. if (ndlp->nlp_DID == Fabric_DID) {
  351. /* Take it off current list and free */
  352. lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
  353. }
  354. }
  355. /* free any ndlp's on unused list */
  356. list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_unused_list,
  357. nlp_listp) {
  358. lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
  359. }
  360. return 0;
  361. }
  362. /*
  363. * This routine handles processing a CLEAR_LA mailbox
  364. * command upon completion. It is setup in the LPFC_MBOXQ
  365. * as the completion routine when the command is
  366. * handed off to the SLI layer.
  367. */
  368. void
  369. lpfc_mbx_cmpl_clear_la(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
  370. {
  371. struct lpfc_sli *psli;
  372. MAILBOX_t *mb;
  373. uint32_t control;
  374. psli = &phba->sli;
  375. mb = &pmb->mb;
  376. /* Since we don't do discovery right now, turn these off here */
  377. psli->ring[psli->ip_ring].flag &= ~LPFC_STOP_IOCB_EVENT;
  378. psli->ring[psli->fcp_ring].flag &= ~LPFC_STOP_IOCB_EVENT;
  379. psli->ring[psli->next_ring].flag &= ~LPFC_STOP_IOCB_EVENT;
  380. /* Check for error */
  381. if ((mb->mbxStatus) && (mb->mbxStatus != 0x1601)) {
  382. /* CLEAR_LA mbox error <mbxStatus> state <hba_state> */
  383. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
  384. "%d:0320 CLEAR_LA mbxStatus error x%x hba "
  385. "state x%x\n",
  386. phba->brd_no, mb->mbxStatus, phba->hba_state);
  387. phba->hba_state = LPFC_HBA_ERROR;
  388. goto out;
  389. }
  390. if (phba->fc_flag & FC_ABORT_DISCOVERY)
  391. goto out;
  392. phba->num_disc_nodes = 0;
  393. /* go thru NPR list and issue ELS PLOGIs */
  394. if (phba->fc_npr_cnt) {
  395. lpfc_els_disc_plogi(phba);
  396. }
  397. if(!phba->num_disc_nodes) {
  398. spin_lock_irq(phba->host->host_lock);
  399. phba->fc_flag &= ~FC_NDISC_ACTIVE;
  400. spin_unlock_irq(phba->host->host_lock);
  401. }
  402. phba->hba_state = LPFC_HBA_READY;
  403. out:
  404. /* Device Discovery completes */
  405. lpfc_printf_log(phba,
  406. KERN_INFO,
  407. LOG_DISCOVERY,
  408. "%d:0225 Device Discovery completes\n",
  409. phba->brd_no);
  410. mempool_free( pmb, phba->mbox_mem_pool);
  411. spin_lock_irq(phba->host->host_lock);
  412. phba->fc_flag &= ~FC_ABORT_DISCOVERY;
  413. if (phba->fc_flag & FC_ESTABLISH_LINK) {
  414. phba->fc_flag &= ~FC_ESTABLISH_LINK;
  415. }
  416. spin_unlock_irq(phba->host->host_lock);
  417. del_timer_sync(&phba->fc_estabtmo);
  418. lpfc_can_disctmo(phba);
  419. /* turn on Link Attention interrupts */
  420. spin_lock_irq(phba->host->host_lock);
  421. psli->sli_flag |= LPFC_PROCESS_LA;
  422. control = readl(phba->HCregaddr);
  423. control |= HC_LAINT_ENA;
  424. writel(control, phba->HCregaddr);
  425. readl(phba->HCregaddr); /* flush */
  426. spin_unlock_irq(phba->host->host_lock);
  427. return;
  428. }
  429. static void
  430. lpfc_mbx_cmpl_config_link(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
  431. {
  432. struct lpfc_sli *psli;
  433. MAILBOX_t *mb;
  434. psli = &phba->sli;
  435. mb = &pmb->mb;
  436. /* Check for error */
  437. if (mb->mbxStatus) {
  438. /* CONFIG_LINK mbox error <mbxStatus> state <hba_state> */
  439. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
  440. "%d:0306 CONFIG_LINK mbxStatus error x%x "
  441. "HBA state x%x\n",
  442. phba->brd_no, mb->mbxStatus, phba->hba_state);
  443. lpfc_linkdown(phba);
  444. phba->hba_state = LPFC_HBA_ERROR;
  445. goto out;
  446. }
  447. if (phba->hba_state == LPFC_LOCAL_CFG_LINK) {
  448. if (phba->fc_topology == TOPOLOGY_LOOP) {
  449. /* If we are public loop and L bit was set */
  450. if ((phba->fc_flag & FC_PUBLIC_LOOP) &&
  451. !(phba->fc_flag & FC_LBIT)) {
  452. /* Need to wait for FAN - use discovery timer
  453. * for timeout. hba_state is identically
  454. * LPFC_LOCAL_CFG_LINK while waiting for FAN
  455. */
  456. lpfc_set_disctmo(phba);
  457. mempool_free( pmb, phba->mbox_mem_pool);
  458. return;
  459. }
  460. }
  461. /* Start discovery by sending a FLOGI hba_state is identically
  462. * LPFC_FLOGI while waiting for FLOGI cmpl
  463. */
  464. phba->hba_state = LPFC_FLOGI;
  465. lpfc_set_disctmo(phba);
  466. lpfc_initial_flogi(phba);
  467. mempool_free( pmb, phba->mbox_mem_pool);
  468. return;
  469. }
  470. if (phba->hba_state == LPFC_FABRIC_CFG_LINK) {
  471. mempool_free( pmb, phba->mbox_mem_pool);
  472. return;
  473. }
  474. out:
  475. /* CONFIG_LINK bad hba state <hba_state> */
  476. lpfc_printf_log(phba,
  477. KERN_ERR,
  478. LOG_DISCOVERY,
  479. "%d:0200 CONFIG_LINK bad hba state x%x\n",
  480. phba->brd_no, phba->hba_state);
  481. if (phba->hba_state != LPFC_CLEAR_LA) {
  482. lpfc_clear_la(phba, pmb);
  483. pmb->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
  484. if (lpfc_sli_issue_mbox(phba, pmb, (MBX_NOWAIT | MBX_STOP_IOCB))
  485. == MBX_NOT_FINISHED) {
  486. mempool_free( pmb, phba->mbox_mem_pool);
  487. lpfc_disc_flush_list(phba);
  488. psli->ring[(psli->ip_ring)].flag &=
  489. ~LPFC_STOP_IOCB_EVENT;
  490. psli->ring[(psli->fcp_ring)].flag &=
  491. ~LPFC_STOP_IOCB_EVENT;
  492. psli->ring[(psli->next_ring)].flag &=
  493. ~LPFC_STOP_IOCB_EVENT;
  494. phba->hba_state = LPFC_HBA_READY;
  495. }
  496. } else {
  497. mempool_free( pmb, phba->mbox_mem_pool);
  498. }
  499. return;
  500. }
  501. static void
  502. lpfc_mbx_cmpl_read_sparam(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
  503. {
  504. struct lpfc_sli *psli = &phba->sli;
  505. MAILBOX_t *mb = &pmb->mb;
  506. struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) pmb->context1;
  507. /* Check for error */
  508. if (mb->mbxStatus) {
  509. /* READ_SPARAM mbox error <mbxStatus> state <hba_state> */
  510. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
  511. "%d:0319 READ_SPARAM mbxStatus error x%x "
  512. "hba state x%x>\n",
  513. phba->brd_no, mb->mbxStatus, phba->hba_state);
  514. lpfc_linkdown(phba);
  515. phba->hba_state = LPFC_HBA_ERROR;
  516. goto out;
  517. }
  518. memcpy((uint8_t *) & phba->fc_sparam, (uint8_t *) mp->virt,
  519. sizeof (struct serv_parm));
  520. memcpy((uint8_t *) & phba->fc_nodename,
  521. (uint8_t *) & phba->fc_sparam.nodeName,
  522. sizeof (struct lpfc_name));
  523. memcpy((uint8_t *) & phba->fc_portname,
  524. (uint8_t *) & phba->fc_sparam.portName,
  525. sizeof (struct lpfc_name));
  526. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  527. kfree(mp);
  528. mempool_free( pmb, phba->mbox_mem_pool);
  529. return;
  530. out:
  531. pmb->context1 = NULL;
  532. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  533. kfree(mp);
  534. if (phba->hba_state != LPFC_CLEAR_LA) {
  535. lpfc_clear_la(phba, pmb);
  536. pmb->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
  537. if (lpfc_sli_issue_mbox(phba, pmb, (MBX_NOWAIT | MBX_STOP_IOCB))
  538. == MBX_NOT_FINISHED) {
  539. mempool_free( pmb, phba->mbox_mem_pool);
  540. lpfc_disc_flush_list(phba);
  541. psli->ring[(psli->ip_ring)].flag &=
  542. ~LPFC_STOP_IOCB_EVENT;
  543. psli->ring[(psli->fcp_ring)].flag &=
  544. ~LPFC_STOP_IOCB_EVENT;
  545. psli->ring[(psli->next_ring)].flag &=
  546. ~LPFC_STOP_IOCB_EVENT;
  547. phba->hba_state = LPFC_HBA_READY;
  548. }
  549. } else {
  550. mempool_free( pmb, phba->mbox_mem_pool);
  551. }
  552. return;
  553. }
  554. static void
  555. lpfc_mbx_process_link_up(struct lpfc_hba *phba, READ_LA_VAR *la)
  556. {
  557. int i;
  558. LPFC_MBOXQ_t *sparam_mbox, *cfglink_mbox;
  559. sparam_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  560. cfglink_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  561. spin_lock_irq(phba->host->host_lock);
  562. switch(la->UlnkSpeed) {
  563. case LA_1GHZ_LINK:
  564. phba->fc_linkspeed = LA_1GHZ_LINK;
  565. break;
  566. case LA_2GHZ_LINK:
  567. phba->fc_linkspeed = LA_2GHZ_LINK;
  568. break;
  569. case LA_4GHZ_LINK:
  570. phba->fc_linkspeed = LA_4GHZ_LINK;
  571. break;
  572. default:
  573. phba->fc_linkspeed = LA_UNKNW_LINK;
  574. break;
  575. }
  576. phba->fc_topology = la->topology;
  577. if (phba->fc_topology == TOPOLOGY_LOOP) {
  578. /* Get Loop Map information */
  579. if (la->il)
  580. phba->fc_flag |= FC_LBIT;
  581. phba->fc_myDID = la->granted_AL_PA;
  582. i = la->un.lilpBde64.tus.f.bdeSize;
  583. if (i == 0) {
  584. phba->alpa_map[0] = 0;
  585. } else {
  586. if (phba->cfg_log_verbose & LOG_LINK_EVENT) {
  587. int numalpa, j, k;
  588. union {
  589. uint8_t pamap[16];
  590. struct {
  591. uint32_t wd1;
  592. uint32_t wd2;
  593. uint32_t wd3;
  594. uint32_t wd4;
  595. } pa;
  596. } un;
  597. numalpa = phba->alpa_map[0];
  598. j = 0;
  599. while (j < numalpa) {
  600. memset(un.pamap, 0, 16);
  601. for (k = 1; j < numalpa; k++) {
  602. un.pamap[k - 1] =
  603. phba->alpa_map[j + 1];
  604. j++;
  605. if (k == 16)
  606. break;
  607. }
  608. /* Link Up Event ALPA map */
  609. lpfc_printf_log(phba,
  610. KERN_WARNING,
  611. LOG_LINK_EVENT,
  612. "%d:1304 Link Up Event "
  613. "ALPA map Data: x%x "
  614. "x%x x%x x%x\n",
  615. phba->brd_no,
  616. un.pa.wd1, un.pa.wd2,
  617. un.pa.wd3, un.pa.wd4);
  618. }
  619. }
  620. }
  621. } else {
  622. phba->fc_myDID = phba->fc_pref_DID;
  623. phba->fc_flag |= FC_LBIT;
  624. }
  625. spin_unlock_irq(phba->host->host_lock);
  626. lpfc_linkup(phba);
  627. if (sparam_mbox) {
  628. lpfc_read_sparam(phba, sparam_mbox);
  629. sparam_mbox->mbox_cmpl = lpfc_mbx_cmpl_read_sparam;
  630. lpfc_sli_issue_mbox(phba, sparam_mbox,
  631. (MBX_NOWAIT | MBX_STOP_IOCB));
  632. }
  633. if (cfglink_mbox) {
  634. phba->hba_state = LPFC_LOCAL_CFG_LINK;
  635. lpfc_config_link(phba, cfglink_mbox);
  636. cfglink_mbox->mbox_cmpl = lpfc_mbx_cmpl_config_link;
  637. lpfc_sli_issue_mbox(phba, cfglink_mbox,
  638. (MBX_NOWAIT | MBX_STOP_IOCB));
  639. }
  640. }
  641. static void
  642. lpfc_mbx_issue_link_down(struct lpfc_hba *phba) {
  643. uint32_t control;
  644. struct lpfc_sli *psli = &phba->sli;
  645. lpfc_linkdown(phba);
  646. /* turn on Link Attention interrupts - no CLEAR_LA needed */
  647. spin_lock_irq(phba->host->host_lock);
  648. psli->sli_flag |= LPFC_PROCESS_LA;
  649. control = readl(phba->HCregaddr);
  650. control |= HC_LAINT_ENA;
  651. writel(control, phba->HCregaddr);
  652. readl(phba->HCregaddr); /* flush */
  653. spin_unlock_irq(phba->host->host_lock);
  654. }
  655. /*
  656. * This routine handles processing a READ_LA mailbox
  657. * command upon completion. It is setup in the LPFC_MBOXQ
  658. * as the completion routine when the command is
  659. * handed off to the SLI layer.
  660. */
  661. void
  662. lpfc_mbx_cmpl_read_la(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
  663. {
  664. READ_LA_VAR *la;
  665. MAILBOX_t *mb = &pmb->mb;
  666. struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
  667. /* Check for error */
  668. if (mb->mbxStatus) {
  669. lpfc_printf_log(phba,
  670. KERN_INFO,
  671. LOG_LINK_EVENT,
  672. "%d:1307 READ_LA mbox error x%x state x%x\n",
  673. phba->brd_no,
  674. mb->mbxStatus, phba->hba_state);
  675. lpfc_mbx_issue_link_down(phba);
  676. phba->hba_state = LPFC_HBA_ERROR;
  677. goto lpfc_mbx_cmpl_read_la_free_mbuf;
  678. }
  679. la = (READ_LA_VAR *) & pmb->mb.un.varReadLA;
  680. memcpy(&phba->alpa_map[0], mp->virt, 128);
  681. if (((phba->fc_eventTag + 1) < la->eventTag) ||
  682. (phba->fc_eventTag == la->eventTag)) {
  683. phba->fc_stat.LinkMultiEvent++;
  684. if (la->attType == AT_LINK_UP) {
  685. if (phba->fc_eventTag != 0)
  686. lpfc_linkdown(phba);
  687. }
  688. }
  689. phba->fc_eventTag = la->eventTag;
  690. if (la->attType == AT_LINK_UP) {
  691. phba->fc_stat.LinkUp++;
  692. lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
  693. "%d:1303 Link Up Event x%x received "
  694. "Data: x%x x%x x%x x%x\n",
  695. phba->brd_no, la->eventTag, phba->fc_eventTag,
  696. la->granted_AL_PA, la->UlnkSpeed,
  697. phba->alpa_map[0]);
  698. lpfc_mbx_process_link_up(phba, la);
  699. } else {
  700. phba->fc_stat.LinkDown++;
  701. lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
  702. "%d:1305 Link Down Event x%x received "
  703. "Data: x%x x%x x%x\n",
  704. phba->brd_no, la->eventTag, phba->fc_eventTag,
  705. phba->hba_state, phba->fc_flag);
  706. lpfc_mbx_issue_link_down(phba);
  707. }
  708. lpfc_mbx_cmpl_read_la_free_mbuf:
  709. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  710. kfree(mp);
  711. mempool_free(pmb, phba->mbox_mem_pool);
  712. return;
  713. }
  714. /*
  715. * This routine handles processing a REG_LOGIN mailbox
  716. * command upon completion. It is setup in the LPFC_MBOXQ
  717. * as the completion routine when the command is
  718. * handed off to the SLI layer.
  719. */
  720. void
  721. lpfc_mbx_cmpl_reg_login(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
  722. {
  723. struct lpfc_sli *psli;
  724. MAILBOX_t *mb;
  725. struct lpfc_dmabuf *mp;
  726. struct lpfc_nodelist *ndlp;
  727. psli = &phba->sli;
  728. mb = &pmb->mb;
  729. ndlp = (struct lpfc_nodelist *) pmb->context2;
  730. mp = (struct lpfc_dmabuf *) (pmb->context1);
  731. pmb->context1 = NULL;
  732. /* Good status, call state machine */
  733. lpfc_disc_state_machine(phba, ndlp, pmb, NLP_EVT_CMPL_REG_LOGIN);
  734. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  735. kfree(mp);
  736. mempool_free( pmb, phba->mbox_mem_pool);
  737. return;
  738. }
  739. /*
  740. * This routine handles processing a Fabric REG_LOGIN mailbox
  741. * command upon completion. It is setup in the LPFC_MBOXQ
  742. * as the completion routine when the command is
  743. * handed off to the SLI layer.
  744. */
  745. void
  746. lpfc_mbx_cmpl_fabric_reg_login(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
  747. {
  748. struct lpfc_sli *psli;
  749. MAILBOX_t *mb;
  750. struct lpfc_dmabuf *mp;
  751. struct lpfc_nodelist *ndlp;
  752. struct lpfc_nodelist *ndlp_fdmi;
  753. psli = &phba->sli;
  754. mb = &pmb->mb;
  755. ndlp = (struct lpfc_nodelist *) pmb->context2;
  756. mp = (struct lpfc_dmabuf *) (pmb->context1);
  757. if (mb->mbxStatus) {
  758. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  759. kfree(mp);
  760. mempool_free( pmb, phba->mbox_mem_pool);
  761. mempool_free( ndlp, phba->nlp_mem_pool);
  762. /* FLOGI failed, so just use loop map to make discovery list */
  763. lpfc_disc_list_loopmap(phba);
  764. /* Start discovery */
  765. lpfc_disc_start(phba);
  766. return;
  767. }
  768. pmb->context1 = NULL;
  769. if (ndlp->nlp_rpi != 0)
  770. lpfc_findnode_remove_rpi(phba, ndlp->nlp_rpi);
  771. ndlp->nlp_rpi = mb->un.varWords[0];
  772. lpfc_addnode_rpi(phba, ndlp, ndlp->nlp_rpi);
  773. ndlp->nlp_type |= NLP_FABRIC;
  774. ndlp->nlp_state = NLP_STE_UNMAPPED_NODE;
  775. lpfc_nlp_list(phba, ndlp, NLP_UNMAPPED_LIST);
  776. if (phba->hba_state == LPFC_FABRIC_CFG_LINK) {
  777. /* This NPort has been assigned an NPort_ID by the fabric as a
  778. * result of the completed fabric login. Issue a State Change
  779. * Registration (SCR) ELS request to the fabric controller
  780. * (SCR_DID) so that this NPort gets RSCN events from the
  781. * fabric.
  782. */
  783. lpfc_issue_els_scr(phba, SCR_DID, 0);
  784. /* Allocate a new node instance. If the pool is empty, just
  785. * start the discovery process and skip the Nameserver login
  786. * process. This is attempted again later on. Otherwise, issue
  787. * a Port Login (PLOGI) to the NameServer
  788. */
  789. if ((ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL))
  790. == 0) {
  791. lpfc_disc_start(phba);
  792. } else {
  793. lpfc_nlp_init(phba, ndlp, NameServer_DID);
  794. ndlp->nlp_type |= NLP_FABRIC;
  795. ndlp->nlp_state = NLP_STE_PLOGI_ISSUE;
  796. lpfc_nlp_list(phba, ndlp, NLP_PLOGI_LIST);
  797. lpfc_issue_els_plogi(phba, ndlp, 0);
  798. if (phba->cfg_fdmi_on) {
  799. if ((ndlp_fdmi = mempool_alloc(
  800. phba->nlp_mem_pool,
  801. GFP_KERNEL))) {
  802. lpfc_nlp_init(phba, ndlp_fdmi,
  803. FDMI_DID);
  804. ndlp_fdmi->nlp_type |= NLP_FABRIC;
  805. ndlp_fdmi->nlp_state =
  806. NLP_STE_PLOGI_ISSUE;
  807. lpfc_issue_els_plogi(phba, ndlp_fdmi,
  808. 0);
  809. }
  810. }
  811. }
  812. }
  813. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  814. kfree(mp);
  815. mempool_free( pmb, phba->mbox_mem_pool);
  816. return;
  817. }
  818. /*
  819. * This routine handles processing a NameServer REG_LOGIN mailbox
  820. * command upon completion. It is setup in the LPFC_MBOXQ
  821. * as the completion routine when the command is
  822. * handed off to the SLI layer.
  823. */
  824. void
  825. lpfc_mbx_cmpl_ns_reg_login(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
  826. {
  827. struct lpfc_sli *psli;
  828. MAILBOX_t *mb;
  829. struct lpfc_dmabuf *mp;
  830. struct lpfc_nodelist *ndlp;
  831. psli = &phba->sli;
  832. mb = &pmb->mb;
  833. ndlp = (struct lpfc_nodelist *) pmb->context2;
  834. mp = (struct lpfc_dmabuf *) (pmb->context1);
  835. if (mb->mbxStatus) {
  836. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  837. kfree(mp);
  838. mempool_free( pmb, phba->mbox_mem_pool);
  839. lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
  840. /* RegLogin failed, so just use loop map to make discovery
  841. list */
  842. lpfc_disc_list_loopmap(phba);
  843. /* Start discovery */
  844. lpfc_disc_start(phba);
  845. return;
  846. }
  847. pmb->context1 = NULL;
  848. if (ndlp->nlp_rpi != 0)
  849. lpfc_findnode_remove_rpi(phba, ndlp->nlp_rpi);
  850. ndlp->nlp_rpi = mb->un.varWords[0];
  851. lpfc_addnode_rpi(phba, ndlp, ndlp->nlp_rpi);
  852. ndlp->nlp_type |= NLP_FABRIC;
  853. ndlp->nlp_state = NLP_STE_UNMAPPED_NODE;
  854. lpfc_nlp_list(phba, ndlp, NLP_UNMAPPED_LIST);
  855. if (phba->hba_state < LPFC_HBA_READY) {
  856. /* Link up discovery requires Fabrib registration. */
  857. lpfc_ns_cmd(phba, ndlp, SLI_CTNS_RNN_ID);
  858. lpfc_ns_cmd(phba, ndlp, SLI_CTNS_RSNN_NN);
  859. lpfc_ns_cmd(phba, ndlp, SLI_CTNS_RFT_ID);
  860. }
  861. phba->fc_ns_retry = 0;
  862. /* Good status, issue CT Request to NameServer */
  863. if (lpfc_ns_cmd(phba, ndlp, SLI_CTNS_GID_FT)) {
  864. /* Cannot issue NameServer Query, so finish up discovery */
  865. lpfc_disc_start(phba);
  866. }
  867. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  868. kfree(mp);
  869. mempool_free( pmb, phba->mbox_mem_pool);
  870. return;
  871. }
  872. static void
  873. lpfc_register_remote_port(struct lpfc_hba * phba,
  874. struct lpfc_nodelist * ndlp)
  875. {
  876. struct fc_rport *rport;
  877. struct lpfc_rport_data *rdata;
  878. struct fc_rport_identifiers rport_ids;
  879. uint64_t wwn;
  880. /* Remote port has reappeared. Re-register w/ FC transport */
  881. memcpy(&wwn, &ndlp->nlp_nodename, sizeof(uint64_t));
  882. rport_ids.node_name = be64_to_cpu(wwn);
  883. memcpy(&wwn, &ndlp->nlp_portname, sizeof(uint64_t));
  884. rport_ids.port_name = be64_to_cpu(wwn);
  885. rport_ids.port_id = ndlp->nlp_DID;
  886. rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
  887. if (ndlp->nlp_type & NLP_FCP_TARGET)
  888. rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
  889. if (ndlp->nlp_type & NLP_FCP_INITIATOR)
  890. rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
  891. ndlp->rport = rport = fc_remote_port_add(phba->host, 0, &rport_ids);
  892. if (!rport) {
  893. dev_printk(KERN_WARNING, &phba->pcidev->dev,
  894. "Warning: fc_remote_port_add failed\n");
  895. return;
  896. }
  897. /* initialize static port data */
  898. rport->maxframe_size = ndlp->nlp_maxframe;
  899. rport->supported_classes = ndlp->nlp_class_sup;
  900. if ((rport->scsi_target_id != -1) &&
  901. (rport->scsi_target_id < MAX_FCP_TARGET)) {
  902. ndlp->nlp_sid = rport->scsi_target_id;
  903. }
  904. rdata = rport->dd_data;
  905. rdata->pnode = ndlp;
  906. return;
  907. }
  908. int
  909. lpfc_nlp_list(struct lpfc_hba * phba, struct lpfc_nodelist * nlp, int list)
  910. {
  911. enum { none, unmapped, mapped } rport_add = none, rport_del = none;
  912. struct lpfc_sli *psli;
  913. psli = &phba->sli;
  914. /* Sanity check to ensure we are not moving to / from the same list */
  915. if ((nlp->nlp_flag & NLP_LIST_MASK) == list) {
  916. if (list != NLP_NO_LIST)
  917. return(0);
  918. }
  919. switch(nlp->nlp_flag & NLP_LIST_MASK) {
  920. case NLP_NO_LIST: /* Not on any list */
  921. break;
  922. case NLP_UNUSED_LIST:
  923. phba->fc_unused_cnt--;
  924. list_del(&nlp->nlp_listp);
  925. break;
  926. case NLP_PLOGI_LIST:
  927. phba->fc_plogi_cnt--;
  928. list_del(&nlp->nlp_listp);
  929. break;
  930. case NLP_ADISC_LIST:
  931. phba->fc_adisc_cnt--;
  932. list_del(&nlp->nlp_listp);
  933. break;
  934. case NLP_REGLOGIN_LIST:
  935. phba->fc_reglogin_cnt--;
  936. list_del(&nlp->nlp_listp);
  937. break;
  938. case NLP_PRLI_LIST:
  939. phba->fc_prli_cnt--;
  940. list_del(&nlp->nlp_listp);
  941. break;
  942. case NLP_UNMAPPED_LIST:
  943. phba->fc_unmap_cnt--;
  944. list_del(&nlp->nlp_listp);
  945. spin_lock_irq(phba->host->host_lock);
  946. nlp->nlp_flag &= ~NLP_TGT_NO_SCSIID;
  947. nlp->nlp_type &= ~NLP_FC_NODE;
  948. spin_unlock_irq(phba->host->host_lock);
  949. phba->nport_event_cnt++;
  950. if (nlp->rport)
  951. rport_del = unmapped;
  952. break;
  953. case NLP_MAPPED_LIST:
  954. phba->fc_map_cnt--;
  955. list_del(&nlp->nlp_listp);
  956. phba->nport_event_cnt++;
  957. if (nlp->rport)
  958. rport_del = mapped;
  959. break;
  960. case NLP_NPR_LIST:
  961. phba->fc_npr_cnt--;
  962. list_del(&nlp->nlp_listp);
  963. /* Stop delay tmo if taking node off NPR list */
  964. if ((nlp->nlp_flag & NLP_DELAY_TMO) &&
  965. (list != NLP_NPR_LIST)) {
  966. spin_lock_irq(phba->host->host_lock);
  967. nlp->nlp_flag &= ~NLP_DELAY_TMO;
  968. spin_unlock_irq(phba->host->host_lock);
  969. del_timer_sync(&nlp->nlp_delayfunc);
  970. if (!list_empty(&nlp->els_retry_evt.evt_listp))
  971. list_del_init(&nlp->els_retry_evt.evt_listp);
  972. }
  973. break;
  974. }
  975. spin_lock_irq(phba->host->host_lock);
  976. nlp->nlp_flag &= ~NLP_LIST_MASK;
  977. spin_unlock_irq(phba->host->host_lock);
  978. /* Add NPort <did> to <num> list */
  979. lpfc_printf_log(phba,
  980. KERN_INFO,
  981. LOG_NODE,
  982. "%d:0904 Add NPort x%x to %d list Data: x%x\n",
  983. phba->brd_no,
  984. nlp->nlp_DID, list, nlp->nlp_flag);
  985. switch(list) {
  986. case NLP_NO_LIST: /* No list, just remove it */
  987. lpfc_nlp_remove(phba, nlp);
  988. /* as node removed - stop further transport calls */
  989. rport_del = none;
  990. break;
  991. case NLP_UNUSED_LIST:
  992. spin_lock_irq(phba->host->host_lock);
  993. nlp->nlp_flag |= list;
  994. spin_unlock_irq(phba->host->host_lock);
  995. /* Put it at the end of the unused list */
  996. list_add_tail(&nlp->nlp_listp, &phba->fc_unused_list);
  997. phba->fc_unused_cnt++;
  998. break;
  999. case NLP_PLOGI_LIST:
  1000. spin_lock_irq(phba->host->host_lock);
  1001. nlp->nlp_flag |= list;
  1002. spin_unlock_irq(phba->host->host_lock);
  1003. /* Put it at the end of the plogi list */
  1004. list_add_tail(&nlp->nlp_listp, &phba->fc_plogi_list);
  1005. phba->fc_plogi_cnt++;
  1006. break;
  1007. case NLP_ADISC_LIST:
  1008. spin_lock_irq(phba->host->host_lock);
  1009. nlp->nlp_flag |= list;
  1010. spin_unlock_irq(phba->host->host_lock);
  1011. /* Put it at the end of the adisc list */
  1012. list_add_tail(&nlp->nlp_listp, &phba->fc_adisc_list);
  1013. phba->fc_adisc_cnt++;
  1014. break;
  1015. case NLP_REGLOGIN_LIST:
  1016. spin_lock_irq(phba->host->host_lock);
  1017. nlp->nlp_flag |= list;
  1018. spin_unlock_irq(phba->host->host_lock);
  1019. /* Put it at the end of the reglogin list */
  1020. list_add_tail(&nlp->nlp_listp, &phba->fc_reglogin_list);
  1021. phba->fc_reglogin_cnt++;
  1022. break;
  1023. case NLP_PRLI_LIST:
  1024. spin_lock_irq(phba->host->host_lock);
  1025. nlp->nlp_flag |= list;
  1026. spin_unlock_irq(phba->host->host_lock);
  1027. /* Put it at the end of the prli list */
  1028. list_add_tail(&nlp->nlp_listp, &phba->fc_prli_list);
  1029. phba->fc_prli_cnt++;
  1030. break;
  1031. case NLP_UNMAPPED_LIST:
  1032. rport_add = unmapped;
  1033. /* ensure all vestiges of "mapped" significance are gone */
  1034. nlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
  1035. spin_lock_irq(phba->host->host_lock);
  1036. nlp->nlp_flag |= list;
  1037. spin_unlock_irq(phba->host->host_lock);
  1038. /* Put it at the end of the unmap list */
  1039. list_add_tail(&nlp->nlp_listp, &phba->fc_nlpunmap_list);
  1040. phba->fc_unmap_cnt++;
  1041. phba->nport_event_cnt++;
  1042. /* stop nodev tmo if running */
  1043. if (nlp->nlp_flag & NLP_NODEV_TMO) {
  1044. spin_lock_irq(phba->host->host_lock);
  1045. nlp->nlp_flag &= ~NLP_NODEV_TMO;
  1046. spin_unlock_irq(phba->host->host_lock);
  1047. del_timer_sync(&nlp->nlp_tmofunc);
  1048. if (!list_empty(&nlp->nodev_timeout_evt.evt_listp))
  1049. list_del_init(&nlp->nodev_timeout_evt.
  1050. evt_listp);
  1051. }
  1052. nlp->nlp_type |= NLP_FC_NODE;
  1053. break;
  1054. case NLP_MAPPED_LIST:
  1055. rport_add = mapped;
  1056. spin_lock_irq(phba->host->host_lock);
  1057. nlp->nlp_flag |= list;
  1058. spin_unlock_irq(phba->host->host_lock);
  1059. /* Put it at the end of the map list */
  1060. list_add_tail(&nlp->nlp_listp, &phba->fc_nlpmap_list);
  1061. phba->fc_map_cnt++;
  1062. phba->nport_event_cnt++;
  1063. /* stop nodev tmo if running */
  1064. if (nlp->nlp_flag & NLP_NODEV_TMO) {
  1065. nlp->nlp_flag &= ~NLP_NODEV_TMO;
  1066. del_timer_sync(&nlp->nlp_tmofunc);
  1067. if (!list_empty(&nlp->nodev_timeout_evt.evt_listp))
  1068. list_del_init(&nlp->nodev_timeout_evt.
  1069. evt_listp);
  1070. }
  1071. break;
  1072. case NLP_NPR_LIST:
  1073. spin_lock_irq(phba->host->host_lock);
  1074. nlp->nlp_flag |= list;
  1075. spin_unlock_irq(phba->host->host_lock);
  1076. /* Put it at the end of the npr list */
  1077. list_add_tail(&nlp->nlp_listp, &phba->fc_npr_list);
  1078. phba->fc_npr_cnt++;
  1079. /*
  1080. * Sanity check for Fabric entity.
  1081. * Set nodev_tmo for NPR state, for Fabric use 1 sec.
  1082. */
  1083. if (nlp->nlp_type & NLP_FABRIC) {
  1084. mod_timer(&nlp->nlp_tmofunc, jiffies + HZ);
  1085. }
  1086. else {
  1087. mod_timer(&nlp->nlp_tmofunc,
  1088. jiffies + HZ * phba->cfg_nodev_tmo);
  1089. }
  1090. spin_lock_irq(phba->host->host_lock);
  1091. nlp->nlp_flag |= NLP_NODEV_TMO;
  1092. nlp->nlp_flag &= ~NLP_RCV_PLOGI;
  1093. spin_unlock_irq(phba->host->host_lock);
  1094. break;
  1095. case NLP_JUST_DQ:
  1096. break;
  1097. }
  1098. /*
  1099. * We make all the calls into the transport after we have
  1100. * moved the node between lists. This so that we don't
  1101. * release the lock while in-between lists.
  1102. */
  1103. /* Don't upcall midlayer if we're unloading */
  1104. if (!(phba->fc_flag & FC_UNLOADING)) {
  1105. /*
  1106. * We revalidate the rport pointer as the "add" function
  1107. * may have removed the remote port.
  1108. */
  1109. if ((rport_del != none) && nlp->rport)
  1110. fc_remote_port_block(nlp->rport);
  1111. if (rport_add != none) {
  1112. /*
  1113. * Tell the fc transport about the port, if we haven't
  1114. * already. If we have, and it's a scsi entity, be
  1115. * sure to unblock any attached scsi devices
  1116. */
  1117. if (!nlp->rport)
  1118. lpfc_register_remote_port(phba, nlp);
  1119. else
  1120. fc_remote_port_unblock(nlp->rport);
  1121. /*
  1122. * if we added to Mapped list, but the remote port
  1123. * registration failed or assigned a target id outside
  1124. * our presentable range - move the node to the
  1125. * Unmapped List
  1126. */
  1127. if ((rport_add == mapped) &&
  1128. ((!nlp->rport) ||
  1129. (nlp->rport->scsi_target_id == -1) ||
  1130. (nlp->rport->scsi_target_id >= MAX_FCP_TARGET))) {
  1131. nlp->nlp_state = NLP_STE_UNMAPPED_NODE;
  1132. spin_lock_irq(phba->host->host_lock);
  1133. nlp->nlp_flag |= NLP_TGT_NO_SCSIID;
  1134. spin_unlock_irq(phba->host->host_lock);
  1135. lpfc_nlp_list(phba, nlp, NLP_UNMAPPED_LIST);
  1136. }
  1137. }
  1138. }
  1139. return (0);
  1140. }
  1141. /*
  1142. * Start / ReStart rescue timer for Discovery / RSCN handling
  1143. */
  1144. void
  1145. lpfc_set_disctmo(struct lpfc_hba * phba)
  1146. {
  1147. uint32_t tmo;
  1148. tmo = ((phba->fc_ratov * 2) + 1);
  1149. mod_timer(&phba->fc_disctmo, jiffies + HZ * tmo);
  1150. spin_lock_irq(phba->host->host_lock);
  1151. phba->fc_flag |= FC_DISC_TMO;
  1152. spin_unlock_irq(phba->host->host_lock);
  1153. /* Start Discovery Timer state <hba_state> */
  1154. lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
  1155. "%d:0247 Start Discovery Timer state x%x "
  1156. "Data: x%x x%lx x%x x%x\n",
  1157. phba->brd_no,
  1158. phba->hba_state, tmo, (unsigned long)&phba->fc_disctmo,
  1159. phba->fc_plogi_cnt, phba->fc_adisc_cnt);
  1160. return;
  1161. }
  1162. /*
  1163. * Cancel rescue timer for Discovery / RSCN handling
  1164. */
  1165. int
  1166. lpfc_can_disctmo(struct lpfc_hba * phba)
  1167. {
  1168. /* Turn off discovery timer if its running */
  1169. if (phba->fc_flag & FC_DISC_TMO) {
  1170. spin_lock_irq(phba->host->host_lock);
  1171. phba->fc_flag &= ~FC_DISC_TMO;
  1172. spin_unlock_irq(phba->host->host_lock);
  1173. del_timer_sync(&phba->fc_disctmo);
  1174. phba->work_hba_events &= ~WORKER_DISC_TMO;
  1175. }
  1176. /* Cancel Discovery Timer state <hba_state> */
  1177. lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
  1178. "%d:0248 Cancel Discovery Timer state x%x "
  1179. "Data: x%x x%x x%x\n",
  1180. phba->brd_no, phba->hba_state, phba->fc_flag,
  1181. phba->fc_plogi_cnt, phba->fc_adisc_cnt);
  1182. return (0);
  1183. }
  1184. /*
  1185. * Check specified ring for outstanding IOCB on the SLI queue
  1186. * Return true if iocb matches the specified nport
  1187. */
  1188. int
  1189. lpfc_check_sli_ndlp(struct lpfc_hba * phba,
  1190. struct lpfc_sli_ring * pring,
  1191. struct lpfc_iocbq * iocb, struct lpfc_nodelist * ndlp)
  1192. {
  1193. struct lpfc_sli *psli;
  1194. IOCB_t *icmd;
  1195. psli = &phba->sli;
  1196. icmd = &iocb->iocb;
  1197. if (pring->ringno == LPFC_ELS_RING) {
  1198. switch (icmd->ulpCommand) {
  1199. case CMD_GEN_REQUEST64_CR:
  1200. if (icmd->ulpContext == (volatile ushort)ndlp->nlp_rpi)
  1201. return (1);
  1202. case CMD_ELS_REQUEST64_CR:
  1203. case CMD_XMIT_ELS_RSP64_CX:
  1204. if (iocb->context1 == (uint8_t *) ndlp)
  1205. return (1);
  1206. }
  1207. } else if (pring->ringno == psli->ip_ring) {
  1208. } else if (pring->ringno == psli->fcp_ring) {
  1209. /* Skip match check if waiting to relogin to FCP target */
  1210. if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
  1211. (ndlp->nlp_flag & NLP_DELAY_TMO)) {
  1212. return (0);
  1213. }
  1214. if (icmd->ulpContext == (volatile ushort)ndlp->nlp_rpi) {
  1215. return (1);
  1216. }
  1217. } else if (pring->ringno == psli->next_ring) {
  1218. }
  1219. return (0);
  1220. }
  1221. /*
  1222. * Free resources / clean up outstanding I/Os
  1223. * associated with nlp_rpi in the LPFC_NODELIST entry.
  1224. */
  1225. static int
  1226. lpfc_no_rpi(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp)
  1227. {
  1228. struct lpfc_sli *psli;
  1229. struct lpfc_sli_ring *pring;
  1230. struct lpfc_iocbq *iocb, *next_iocb;
  1231. IOCB_t *icmd;
  1232. uint32_t rpi, i;
  1233. /*
  1234. * Everything that matches on txcmplq will be returned
  1235. * by firmware with a no rpi error.
  1236. */
  1237. psli = &phba->sli;
  1238. rpi = ndlp->nlp_rpi;
  1239. if (rpi) {
  1240. /* Now process each ring */
  1241. for (i = 0; i < psli->num_rings; i++) {
  1242. pring = &psli->ring[i];
  1243. spin_lock_irq(phba->host->host_lock);
  1244. list_for_each_entry_safe(iocb, next_iocb, &pring->txq,
  1245. list) {
  1246. /*
  1247. * Check to see if iocb matches the nport we are
  1248. * looking for
  1249. */
  1250. if ((lpfc_check_sli_ndlp
  1251. (phba, pring, iocb, ndlp))) {
  1252. /* It matches, so deque and call compl
  1253. with an error */
  1254. list_del(&iocb->list);
  1255. pring->txq_cnt--;
  1256. if (iocb->iocb_cmpl) {
  1257. icmd = &iocb->iocb;
  1258. icmd->ulpStatus =
  1259. IOSTAT_LOCAL_REJECT;
  1260. icmd->un.ulpWord[4] =
  1261. IOERR_SLI_ABORTED;
  1262. spin_unlock_irq(phba->host->
  1263. host_lock);
  1264. (iocb->iocb_cmpl) (phba,
  1265. iocb, iocb);
  1266. spin_lock_irq(phba->host->
  1267. host_lock);
  1268. } else {
  1269. list_add_tail(&iocb->list,
  1270. &phba->lpfc_iocb_list);
  1271. }
  1272. }
  1273. }
  1274. spin_unlock_irq(phba->host->host_lock);
  1275. }
  1276. }
  1277. return (0);
  1278. }
  1279. /*
  1280. * Free rpi associated with LPFC_NODELIST entry.
  1281. * This routine is called from lpfc_freenode(), when we are removing
  1282. * a LPFC_NODELIST entry. It is also called if the driver initiates a
  1283. * LOGO that completes successfully, and we are waiting to PLOGI back
  1284. * to the remote NPort. In addition, it is called after we receive
  1285. * and unsolicated ELS cmd, send back a rsp, the rsp completes and
  1286. * we are waiting to PLOGI back to the remote NPort.
  1287. */
  1288. int
  1289. lpfc_unreg_rpi(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp)
  1290. {
  1291. LPFC_MBOXQ_t *mbox;
  1292. int rc;
  1293. if (ndlp->nlp_rpi) {
  1294. if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL))) {
  1295. lpfc_unreg_login(phba, ndlp->nlp_rpi, mbox);
  1296. mbox->mbox_cmpl=lpfc_sli_def_mbox_cmpl;
  1297. rc = lpfc_sli_issue_mbox
  1298. (phba, mbox, (MBX_NOWAIT | MBX_STOP_IOCB));
  1299. if (rc == MBX_NOT_FINISHED)
  1300. mempool_free( mbox, phba->mbox_mem_pool);
  1301. }
  1302. lpfc_findnode_remove_rpi(phba, ndlp->nlp_rpi);
  1303. lpfc_no_rpi(phba, ndlp);
  1304. ndlp->nlp_rpi = 0;
  1305. return 1;
  1306. }
  1307. return 0;
  1308. }
  1309. /*
  1310. * Free resources associated with LPFC_NODELIST entry
  1311. * so it can be freed.
  1312. */
  1313. static int
  1314. lpfc_freenode(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp)
  1315. {
  1316. LPFC_MBOXQ_t *mb;
  1317. LPFC_MBOXQ_t *nextmb;
  1318. struct lpfc_dmabuf *mp;
  1319. struct fc_rport *rport;
  1320. /* Cleanup node for NPort <nlp_DID> */
  1321. lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
  1322. "%d:0900 Cleanup node for NPort x%x "
  1323. "Data: x%x x%x x%x\n",
  1324. phba->brd_no, ndlp->nlp_DID, ndlp->nlp_flag,
  1325. ndlp->nlp_state, ndlp->nlp_rpi);
  1326. lpfc_nlp_list(phba, ndlp, NLP_JUST_DQ);
  1327. /*
  1328. * if unloading the driver - just leave the remote port in place.
  1329. * The driver unload will force the attached devices to detach
  1330. * and flush cache's w/o generating flush errors.
  1331. */
  1332. if ((ndlp->rport) && !(phba->fc_flag & FC_UNLOADING)) {
  1333. rport = ndlp->rport;
  1334. ndlp->rport = NULL;
  1335. fc_remote_port_unblock(rport);
  1336. fc_remote_port_delete(rport);
  1337. ndlp->nlp_sid = NLP_NO_SID;
  1338. }
  1339. /* cleanup any ndlp on mbox q waiting for reglogin cmpl */
  1340. if ((mb = phba->sli.mbox_active)) {
  1341. if ((mb->mb.mbxCommand == MBX_REG_LOGIN64) &&
  1342. (ndlp == (struct lpfc_nodelist *) mb->context2)) {
  1343. mb->context2 = NULL;
  1344. mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  1345. }
  1346. }
  1347. list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
  1348. if ((mb->mb.mbxCommand == MBX_REG_LOGIN64) &&
  1349. (ndlp == (struct lpfc_nodelist *) mb->context2)) {
  1350. mp = (struct lpfc_dmabuf *) (mb->context1);
  1351. if (mp) {
  1352. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  1353. kfree(mp);
  1354. }
  1355. list_del(&mb->list);
  1356. mempool_free(mb, phba->mbox_mem_pool);
  1357. }
  1358. }
  1359. lpfc_els_abort(phba,ndlp,0);
  1360. spin_lock_irq(phba->host->host_lock);
  1361. ndlp->nlp_flag &= ~(NLP_NODEV_TMO|NLP_DELAY_TMO);
  1362. spin_unlock_irq(phba->host->host_lock);
  1363. del_timer_sync(&ndlp->nlp_tmofunc);
  1364. del_timer_sync(&ndlp->nlp_delayfunc);
  1365. if (!list_empty(&ndlp->nodev_timeout_evt.evt_listp))
  1366. list_del_init(&ndlp->nodev_timeout_evt.evt_listp);
  1367. if (!list_empty(&ndlp->els_retry_evt.evt_listp))
  1368. list_del_init(&ndlp->els_retry_evt.evt_listp);
  1369. lpfc_unreg_rpi(phba, ndlp);
  1370. return (0);
  1371. }
  1372. /*
  1373. * Check to see if we can free the nlp back to the freelist.
  1374. * If we are in the middle of using the nlp in the discovery state
  1375. * machine, defer the free till we reach the end of the state machine.
  1376. */
  1377. int
  1378. lpfc_nlp_remove(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp)
  1379. {
  1380. if (ndlp->nlp_flag & NLP_NODEV_TMO) {
  1381. spin_lock_irq(phba->host->host_lock);
  1382. ndlp->nlp_flag &= ~NLP_NODEV_TMO;
  1383. spin_unlock_irq(phba->host->host_lock);
  1384. del_timer_sync(&ndlp->nlp_tmofunc);
  1385. if (!list_empty(&ndlp->nodev_timeout_evt.evt_listp))
  1386. list_del_init(&ndlp->nodev_timeout_evt.evt_listp);
  1387. }
  1388. if (ndlp->nlp_flag & NLP_DELAY_TMO) {
  1389. spin_lock_irq(phba->host->host_lock);
  1390. ndlp->nlp_flag &= ~NLP_DELAY_TMO;
  1391. spin_unlock_irq(phba->host->host_lock);
  1392. del_timer_sync(&ndlp->nlp_delayfunc);
  1393. if (!list_empty(&ndlp->els_retry_evt.evt_listp))
  1394. list_del_init(&ndlp->els_retry_evt.evt_listp);
  1395. }
  1396. if (ndlp->nlp_disc_refcnt) {
  1397. spin_lock_irq(phba->host->host_lock);
  1398. ndlp->nlp_flag |= NLP_DELAY_REMOVE;
  1399. spin_unlock_irq(phba->host->host_lock);
  1400. }
  1401. else {
  1402. lpfc_freenode(phba, ndlp);
  1403. mempool_free( ndlp, phba->nlp_mem_pool);
  1404. }
  1405. return(0);
  1406. }
  1407. static int
  1408. lpfc_matchdid(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp, uint32_t did)
  1409. {
  1410. D_ID mydid;
  1411. D_ID ndlpdid;
  1412. D_ID matchdid;
  1413. if (did == Bcast_DID)
  1414. return (0);
  1415. if (ndlp->nlp_DID == 0) {
  1416. return (0);
  1417. }
  1418. /* First check for Direct match */
  1419. if (ndlp->nlp_DID == did)
  1420. return (1);
  1421. /* Next check for area/domain identically equals 0 match */
  1422. mydid.un.word = phba->fc_myDID;
  1423. if ((mydid.un.b.domain == 0) && (mydid.un.b.area == 0)) {
  1424. return (0);
  1425. }
  1426. matchdid.un.word = did;
  1427. ndlpdid.un.word = ndlp->nlp_DID;
  1428. if (matchdid.un.b.id == ndlpdid.un.b.id) {
  1429. if ((mydid.un.b.domain == matchdid.un.b.domain) &&
  1430. (mydid.un.b.area == matchdid.un.b.area)) {
  1431. if ((ndlpdid.un.b.domain == 0) &&
  1432. (ndlpdid.un.b.area == 0)) {
  1433. if (ndlpdid.un.b.id)
  1434. return (1);
  1435. }
  1436. return (0);
  1437. }
  1438. matchdid.un.word = ndlp->nlp_DID;
  1439. if ((mydid.un.b.domain == ndlpdid.un.b.domain) &&
  1440. (mydid.un.b.area == ndlpdid.un.b.area)) {
  1441. if ((matchdid.un.b.domain == 0) &&
  1442. (matchdid.un.b.area == 0)) {
  1443. if (matchdid.un.b.id)
  1444. return (1);
  1445. }
  1446. }
  1447. }
  1448. return (0);
  1449. }
  1450. /* Search for a nodelist entry on a specific list */
  1451. struct lpfc_nodelist *
  1452. lpfc_findnode_did(struct lpfc_hba * phba, uint32_t order, uint32_t did)
  1453. {
  1454. struct lpfc_nodelist *ndlp, *next_ndlp;
  1455. uint32_t data1;
  1456. if (order & NLP_SEARCH_UNMAPPED) {
  1457. list_for_each_entry_safe(ndlp, next_ndlp,
  1458. &phba->fc_nlpunmap_list, nlp_listp) {
  1459. if (lpfc_matchdid(phba, ndlp, did)) {
  1460. data1 = (((uint32_t) ndlp->nlp_state << 24) |
  1461. ((uint32_t) ndlp->nlp_xri << 16) |
  1462. ((uint32_t) ndlp->nlp_type << 8) |
  1463. ((uint32_t) ndlp->nlp_rpi & 0xff));
  1464. /* FIND node DID unmapped */
  1465. lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
  1466. "%d:0929 FIND node DID unmapped"
  1467. " Data: x%p x%x x%x x%x\n",
  1468. phba->brd_no,
  1469. ndlp, ndlp->nlp_DID,
  1470. ndlp->nlp_flag, data1);
  1471. return (ndlp);
  1472. }
  1473. }
  1474. }
  1475. if (order & NLP_SEARCH_MAPPED) {
  1476. list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_nlpmap_list,
  1477. nlp_listp) {
  1478. if (lpfc_matchdid(phba, ndlp, did)) {
  1479. data1 = (((uint32_t) ndlp->nlp_state << 24) |
  1480. ((uint32_t) ndlp->nlp_xri << 16) |
  1481. ((uint32_t) ndlp->nlp_type << 8) |
  1482. ((uint32_t) ndlp->nlp_rpi & 0xff));
  1483. /* FIND node DID mapped */
  1484. lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
  1485. "%d:0930 FIND node DID mapped "
  1486. "Data: x%p x%x x%x x%x\n",
  1487. phba->brd_no,
  1488. ndlp, ndlp->nlp_DID,
  1489. ndlp->nlp_flag, data1);
  1490. return (ndlp);
  1491. }
  1492. }
  1493. }
  1494. if (order & NLP_SEARCH_PLOGI) {
  1495. list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_plogi_list,
  1496. nlp_listp) {
  1497. if (lpfc_matchdid(phba, ndlp, did)) {
  1498. data1 = (((uint32_t) ndlp->nlp_state << 24) |
  1499. ((uint32_t) ndlp->nlp_xri << 16) |
  1500. ((uint32_t) ndlp->nlp_type << 8) |
  1501. ((uint32_t) ndlp->nlp_rpi & 0xff));
  1502. /* LOG change to PLOGI */
  1503. /* FIND node DID plogi */
  1504. lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
  1505. "%d:0908 FIND node DID plogi "
  1506. "Data: x%p x%x x%x x%x\n",
  1507. phba->brd_no,
  1508. ndlp, ndlp->nlp_DID,
  1509. ndlp->nlp_flag, data1);
  1510. return (ndlp);
  1511. }
  1512. }
  1513. }
  1514. if (order & NLP_SEARCH_ADISC) {
  1515. list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_adisc_list,
  1516. nlp_listp) {
  1517. if (lpfc_matchdid(phba, ndlp, did)) {
  1518. data1 = (((uint32_t) ndlp->nlp_state << 24) |
  1519. ((uint32_t) ndlp->nlp_xri << 16) |
  1520. ((uint32_t) ndlp->nlp_type << 8) |
  1521. ((uint32_t) ndlp->nlp_rpi & 0xff));
  1522. /* LOG change to ADISC */
  1523. /* FIND node DID adisc */
  1524. lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
  1525. "%d:0931 FIND node DID adisc "
  1526. "Data: x%p x%x x%x x%x\n",
  1527. phba->brd_no,
  1528. ndlp, ndlp->nlp_DID,
  1529. ndlp->nlp_flag, data1);
  1530. return (ndlp);
  1531. }
  1532. }
  1533. }
  1534. if (order & NLP_SEARCH_REGLOGIN) {
  1535. list_for_each_entry_safe(ndlp, next_ndlp,
  1536. &phba->fc_reglogin_list, nlp_listp) {
  1537. if (lpfc_matchdid(phba, ndlp, did)) {
  1538. data1 = (((uint32_t) ndlp->nlp_state << 24) |
  1539. ((uint32_t) ndlp->nlp_xri << 16) |
  1540. ((uint32_t) ndlp->nlp_type << 8) |
  1541. ((uint32_t) ndlp->nlp_rpi & 0xff));
  1542. /* LOG change to REGLOGIN */
  1543. /* FIND node DID reglogin */
  1544. lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
  1545. "%d:0931 FIND node DID reglogin"
  1546. " Data: x%p x%x x%x x%x\n",
  1547. phba->brd_no,
  1548. ndlp, ndlp->nlp_DID,
  1549. ndlp->nlp_flag, data1);
  1550. return (ndlp);
  1551. }
  1552. }
  1553. }
  1554. if (order & NLP_SEARCH_PRLI) {
  1555. list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_prli_list,
  1556. nlp_listp) {
  1557. if (lpfc_matchdid(phba, ndlp, did)) {
  1558. data1 = (((uint32_t) ndlp->nlp_state << 24) |
  1559. ((uint32_t) ndlp->nlp_xri << 16) |
  1560. ((uint32_t) ndlp->nlp_type << 8) |
  1561. ((uint32_t) ndlp->nlp_rpi & 0xff));
  1562. /* LOG change to PRLI */
  1563. /* FIND node DID prli */
  1564. lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
  1565. "%d:0931 FIND node DID prli "
  1566. "Data: x%p x%x x%x x%x\n",
  1567. phba->brd_no,
  1568. ndlp, ndlp->nlp_DID,
  1569. ndlp->nlp_flag, data1);
  1570. return (ndlp);
  1571. }
  1572. }
  1573. }
  1574. if (order & NLP_SEARCH_NPR) {
  1575. list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_npr_list,
  1576. nlp_listp) {
  1577. if (lpfc_matchdid(phba, ndlp, did)) {
  1578. data1 = (((uint32_t) ndlp->nlp_state << 24) |
  1579. ((uint32_t) ndlp->nlp_xri << 16) |
  1580. ((uint32_t) ndlp->nlp_type << 8) |
  1581. ((uint32_t) ndlp->nlp_rpi & 0xff));
  1582. /* LOG change to NPR */
  1583. /* FIND node DID npr */
  1584. lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
  1585. "%d:0931 FIND node DID npr "
  1586. "Data: x%p x%x x%x x%x\n",
  1587. phba->brd_no,
  1588. ndlp, ndlp->nlp_DID,
  1589. ndlp->nlp_flag, data1);
  1590. return (ndlp);
  1591. }
  1592. }
  1593. }
  1594. if (order & NLP_SEARCH_UNUSED) {
  1595. list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_adisc_list,
  1596. nlp_listp) {
  1597. if (lpfc_matchdid(phba, ndlp, did)) {
  1598. data1 = (((uint32_t) ndlp->nlp_state << 24) |
  1599. ((uint32_t) ndlp->nlp_xri << 16) |
  1600. ((uint32_t) ndlp->nlp_type << 8) |
  1601. ((uint32_t) ndlp->nlp_rpi & 0xff));
  1602. /* LOG change to UNUSED */
  1603. /* FIND node DID unused */
  1604. lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
  1605. "%d:0931 FIND node DID unused "
  1606. "Data: x%p x%x x%x x%x\n",
  1607. phba->brd_no,
  1608. ndlp, ndlp->nlp_DID,
  1609. ndlp->nlp_flag, data1);
  1610. return (ndlp);
  1611. }
  1612. }
  1613. }
  1614. /* FIND node did <did> NOT FOUND */
  1615. lpfc_printf_log(phba,
  1616. KERN_INFO,
  1617. LOG_NODE,
  1618. "%d:0932 FIND node did x%x NOT FOUND Data: x%x\n",
  1619. phba->brd_no, did, order);
  1620. /* no match found */
  1621. return NULL;
  1622. }
  1623. struct lpfc_nodelist *
  1624. lpfc_setup_disc_node(struct lpfc_hba * phba, uint32_t did)
  1625. {
  1626. struct lpfc_nodelist *ndlp;
  1627. uint32_t flg;
  1628. if ((ndlp = lpfc_findnode_did(phba, NLP_SEARCH_ALL, did)) == 0) {
  1629. if ((phba->hba_state == LPFC_HBA_READY) &&
  1630. ((lpfc_rscn_payload_check(phba, did) == 0)))
  1631. return NULL;
  1632. ndlp = (struct lpfc_nodelist *)
  1633. mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
  1634. if (!ndlp)
  1635. return NULL;
  1636. lpfc_nlp_init(phba, ndlp, did);
  1637. ndlp->nlp_state = NLP_STE_NPR_NODE;
  1638. lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
  1639. ndlp->nlp_flag |= NLP_NPR_2B_DISC;
  1640. return ndlp;
  1641. }
  1642. if ((phba->hba_state == LPFC_HBA_READY) &&
  1643. (phba->fc_flag & FC_RSCN_MODE)) {
  1644. if (lpfc_rscn_payload_check(phba, did)) {
  1645. ndlp->nlp_flag |= NLP_NPR_2B_DISC;
  1646. }
  1647. else {
  1648. ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
  1649. ndlp = NULL;
  1650. }
  1651. }
  1652. else {
  1653. flg = ndlp->nlp_flag & NLP_LIST_MASK;
  1654. if ((flg == NLP_ADISC_LIST) ||
  1655. (flg == NLP_PLOGI_LIST)) {
  1656. return NULL;
  1657. }
  1658. ndlp->nlp_state = NLP_STE_NPR_NODE;
  1659. lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
  1660. ndlp->nlp_flag |= NLP_NPR_2B_DISC;
  1661. }
  1662. return ndlp;
  1663. }
  1664. /* Build a list of nodes to discover based on the loopmap */
  1665. void
  1666. lpfc_disc_list_loopmap(struct lpfc_hba * phba)
  1667. {
  1668. int j;
  1669. uint32_t alpa, index;
  1670. if (phba->hba_state <= LPFC_LINK_DOWN) {
  1671. return;
  1672. }
  1673. if (phba->fc_topology != TOPOLOGY_LOOP) {
  1674. return;
  1675. }
  1676. /* Check for loop map present or not */
  1677. if (phba->alpa_map[0]) {
  1678. for (j = 1; j <= phba->alpa_map[0]; j++) {
  1679. alpa = phba->alpa_map[j];
  1680. if (((phba->fc_myDID & 0xff) == alpa) || (alpa == 0)) {
  1681. continue;
  1682. }
  1683. lpfc_setup_disc_node(phba, alpa);
  1684. }
  1685. } else {
  1686. /* No alpamap, so try all alpa's */
  1687. for (j = 0; j < FC_MAXLOOP; j++) {
  1688. /* If cfg_scan_down is set, start from highest
  1689. * ALPA (0xef) to lowest (0x1).
  1690. */
  1691. if (phba->cfg_scan_down)
  1692. index = j;
  1693. else
  1694. index = FC_MAXLOOP - j - 1;
  1695. alpa = lpfcAlpaArray[index];
  1696. if ((phba->fc_myDID & 0xff) == alpa) {
  1697. continue;
  1698. }
  1699. lpfc_setup_disc_node(phba, alpa);
  1700. }
  1701. }
  1702. return;
  1703. }
  1704. /* Start Link up / RSCN discovery on NPR list */
  1705. void
  1706. lpfc_disc_start(struct lpfc_hba * phba)
  1707. {
  1708. struct lpfc_sli *psli;
  1709. LPFC_MBOXQ_t *mbox;
  1710. struct lpfc_nodelist *ndlp, *next_ndlp;
  1711. uint32_t did_changed, num_sent;
  1712. uint32_t clear_la_pending;
  1713. int rc;
  1714. psli = &phba->sli;
  1715. if (phba->hba_state <= LPFC_LINK_DOWN) {
  1716. return;
  1717. }
  1718. if (phba->hba_state == LPFC_CLEAR_LA)
  1719. clear_la_pending = 1;
  1720. else
  1721. clear_la_pending = 0;
  1722. if (phba->hba_state < LPFC_HBA_READY) {
  1723. phba->hba_state = LPFC_DISC_AUTH;
  1724. }
  1725. lpfc_set_disctmo(phba);
  1726. if (phba->fc_prevDID == phba->fc_myDID) {
  1727. did_changed = 0;
  1728. } else {
  1729. did_changed = 1;
  1730. }
  1731. phba->fc_prevDID = phba->fc_myDID;
  1732. phba->num_disc_nodes = 0;
  1733. /* Start Discovery state <hba_state> */
  1734. lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
  1735. "%d:0202 Start Discovery hba state x%x "
  1736. "Data: x%x x%x x%x\n",
  1737. phba->brd_no, phba->hba_state, phba->fc_flag,
  1738. phba->fc_plogi_cnt, phba->fc_adisc_cnt);
  1739. /* If our did changed, we MUST do PLOGI */
  1740. list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_npr_list,
  1741. nlp_listp) {
  1742. if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
  1743. if (did_changed) {
  1744. spin_lock_irq(phba->host->host_lock);
  1745. ndlp->nlp_flag &= ~NLP_NPR_ADISC;
  1746. spin_unlock_irq(phba->host->host_lock);
  1747. }
  1748. }
  1749. }
  1750. /* First do ADISCs - if any */
  1751. num_sent = lpfc_els_disc_adisc(phba);
  1752. if (num_sent)
  1753. return;
  1754. if ((phba->hba_state < LPFC_HBA_READY) && (!clear_la_pending)) {
  1755. /* If we get here, there is nothing to ADISC */
  1756. if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL))) {
  1757. phba->hba_state = LPFC_CLEAR_LA;
  1758. lpfc_clear_la(phba, mbox);
  1759. mbox->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
  1760. rc = lpfc_sli_issue_mbox(phba, mbox,
  1761. (MBX_NOWAIT | MBX_STOP_IOCB));
  1762. if (rc == MBX_NOT_FINISHED) {
  1763. mempool_free( mbox, phba->mbox_mem_pool);
  1764. lpfc_disc_flush_list(phba);
  1765. psli->ring[(psli->ip_ring)].flag &=
  1766. ~LPFC_STOP_IOCB_EVENT;
  1767. psli->ring[(psli->fcp_ring)].flag &=
  1768. ~LPFC_STOP_IOCB_EVENT;
  1769. psli->ring[(psli->next_ring)].flag &=
  1770. ~LPFC_STOP_IOCB_EVENT;
  1771. phba->hba_state = LPFC_HBA_READY;
  1772. }
  1773. }
  1774. } else {
  1775. /* Next do PLOGIs - if any */
  1776. num_sent = lpfc_els_disc_plogi(phba);
  1777. if (num_sent)
  1778. return;
  1779. if (phba->fc_flag & FC_RSCN_MODE) {
  1780. /* Check to see if more RSCNs came in while we
  1781. * were processing this one.
  1782. */
  1783. if ((phba->fc_rscn_id_cnt == 0) &&
  1784. (!(phba->fc_flag & FC_RSCN_DISCOVERY))) {
  1785. spin_lock_irq(phba->host->host_lock);
  1786. phba->fc_flag &= ~FC_RSCN_MODE;
  1787. spin_unlock_irq(phba->host->host_lock);
  1788. }
  1789. else
  1790. lpfc_els_handle_rscn(phba);
  1791. }
  1792. }
  1793. return;
  1794. }
  1795. /*
  1796. * Ignore completion for all IOCBs on tx and txcmpl queue for ELS
  1797. * ring the match the sppecified nodelist.
  1798. */
  1799. static void
  1800. lpfc_free_tx(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp)
  1801. {
  1802. struct lpfc_sli *psli;
  1803. IOCB_t *icmd;
  1804. struct lpfc_iocbq *iocb, *next_iocb;
  1805. struct lpfc_sli_ring *pring;
  1806. struct lpfc_dmabuf *mp;
  1807. psli = &phba->sli;
  1808. pring = &psli->ring[LPFC_ELS_RING];
  1809. /* Error matching iocb on txq or txcmplq
  1810. * First check the txq.
  1811. */
  1812. list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
  1813. if (iocb->context1 != ndlp) {
  1814. continue;
  1815. }
  1816. icmd = &iocb->iocb;
  1817. if ((icmd->ulpCommand == CMD_ELS_REQUEST64_CR) ||
  1818. (icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX)) {
  1819. list_del(&iocb->list);
  1820. pring->txq_cnt--;
  1821. lpfc_els_free_iocb(phba, iocb);
  1822. }
  1823. }
  1824. /* Next check the txcmplq */
  1825. list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
  1826. if (iocb->context1 != ndlp) {
  1827. continue;
  1828. }
  1829. icmd = &iocb->iocb;
  1830. if ((icmd->ulpCommand == CMD_ELS_REQUEST64_CR) ||
  1831. (icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX)) {
  1832. iocb->iocb_cmpl = NULL;
  1833. /* context2 = cmd, context2->next = rsp, context3 =
  1834. bpl */
  1835. if (iocb->context2) {
  1836. /* Free the response IOCB before handling the
  1837. command. */
  1838. mp = (struct lpfc_dmabuf *) (iocb->context2);
  1839. mp = list_get_first(&mp->list,
  1840. struct lpfc_dmabuf,
  1841. list);
  1842. if (mp) {
  1843. /* Delay before releasing rsp buffer to
  1844. * give UNREG mbox a chance to take
  1845. * effect.
  1846. */
  1847. list_add(&mp->list,
  1848. &phba->freebufList);
  1849. }
  1850. lpfc_mbuf_free(phba,
  1851. ((struct lpfc_dmabuf *)
  1852. iocb->context2)->virt,
  1853. ((struct lpfc_dmabuf *)
  1854. iocb->context2)->phys);
  1855. kfree(iocb->context2);
  1856. }
  1857. if (iocb->context3) {
  1858. lpfc_mbuf_free(phba,
  1859. ((struct lpfc_dmabuf *)
  1860. iocb->context3)->virt,
  1861. ((struct lpfc_dmabuf *)
  1862. iocb->context3)->phys);
  1863. kfree(iocb->context3);
  1864. }
  1865. }
  1866. }
  1867. return;
  1868. }
  1869. void
  1870. lpfc_disc_flush_list(struct lpfc_hba * phba)
  1871. {
  1872. struct lpfc_nodelist *ndlp, *next_ndlp;
  1873. if (phba->fc_plogi_cnt) {
  1874. list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_plogi_list,
  1875. nlp_listp) {
  1876. lpfc_free_tx(phba, ndlp);
  1877. lpfc_nlp_remove(phba, ndlp);
  1878. }
  1879. }
  1880. if (phba->fc_adisc_cnt) {
  1881. list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_adisc_list,
  1882. nlp_listp) {
  1883. lpfc_free_tx(phba, ndlp);
  1884. lpfc_nlp_remove(phba, ndlp);
  1885. }
  1886. }
  1887. return;
  1888. }
  1889. /*****************************************************************************/
  1890. /*
  1891. * NAME: lpfc_disc_timeout
  1892. *
  1893. * FUNCTION: Fibre Channel driver discovery timeout routine.
  1894. *
  1895. * EXECUTION ENVIRONMENT: interrupt only
  1896. *
  1897. * CALLED FROM:
  1898. * Timer function
  1899. *
  1900. * RETURNS:
  1901. * none
  1902. */
  1903. /*****************************************************************************/
  1904. void
  1905. lpfc_disc_timeout(unsigned long ptr)
  1906. {
  1907. struct lpfc_hba *phba = (struct lpfc_hba *)ptr;
  1908. unsigned long flags = 0;
  1909. if (unlikely(!phba))
  1910. return;
  1911. spin_lock_irqsave(phba->host->host_lock, flags);
  1912. if (!(phba->work_hba_events & WORKER_DISC_TMO)) {
  1913. phba->work_hba_events |= WORKER_DISC_TMO;
  1914. if (phba->work_wait)
  1915. wake_up(phba->work_wait);
  1916. }
  1917. spin_unlock_irqrestore(phba->host->host_lock, flags);
  1918. return;
  1919. }
  1920. static void
  1921. lpfc_disc_timeout_handler(struct lpfc_hba *phba)
  1922. {
  1923. struct lpfc_sli *psli;
  1924. struct lpfc_nodelist *ndlp;
  1925. LPFC_MBOXQ_t *clearlambox, *initlinkmbox;
  1926. int rc, clrlaerr = 0;
  1927. if (unlikely(!phba))
  1928. return;
  1929. if (!(phba->fc_flag & FC_DISC_TMO))
  1930. return;
  1931. psli = &phba->sli;
  1932. spin_lock_irq(phba->host->host_lock);
  1933. phba->fc_flag &= ~FC_DISC_TMO;
  1934. spin_unlock_irq(phba->host->host_lock);
  1935. switch (phba->hba_state) {
  1936. case LPFC_LOCAL_CFG_LINK:
  1937. /* hba_state is identically LPFC_LOCAL_CFG_LINK while waiting for FAN */
  1938. /* FAN timeout */
  1939. lpfc_printf_log(phba,
  1940. KERN_WARNING,
  1941. LOG_DISCOVERY,
  1942. "%d:0221 FAN timeout\n",
  1943. phba->brd_no);
  1944. /* Forget about FAN, Start discovery by sending a FLOGI
  1945. * hba_state is identically LPFC_FLOGI while waiting for FLOGI
  1946. * cmpl
  1947. */
  1948. phba->hba_state = LPFC_FLOGI;
  1949. lpfc_set_disctmo(phba);
  1950. lpfc_initial_flogi(phba);
  1951. break;
  1952. case LPFC_FLOGI:
  1953. /* hba_state is identically LPFC_FLOGI while waiting for FLOGI cmpl */
  1954. /* Initial FLOGI timeout */
  1955. lpfc_printf_log(phba,
  1956. KERN_ERR,
  1957. LOG_DISCOVERY,
  1958. "%d:0222 Initial FLOGI timeout\n",
  1959. phba->brd_no);
  1960. /* Assume no Fabric and go on with discovery.
  1961. * Check for outstanding ELS FLOGI to abort.
  1962. */
  1963. /* FLOGI failed, so just use loop map to make discovery list */
  1964. lpfc_disc_list_loopmap(phba);
  1965. /* Start discovery */
  1966. lpfc_disc_start(phba);
  1967. break;
  1968. case LPFC_FABRIC_CFG_LINK:
  1969. /* hba_state is identically LPFC_FABRIC_CFG_LINK while waiting for
  1970. NameServer login */
  1971. lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
  1972. "%d:0223 Timeout while waiting for NameServer "
  1973. "login\n", phba->brd_no);
  1974. /* Next look for NameServer ndlp */
  1975. ndlp = lpfc_findnode_did(phba, NLP_SEARCH_ALL, NameServer_DID);
  1976. if (ndlp)
  1977. lpfc_nlp_remove(phba, ndlp);
  1978. /* Start discovery */
  1979. lpfc_disc_start(phba);
  1980. break;
  1981. case LPFC_NS_QRY:
  1982. /* Check for wait for NameServer Rsp timeout */
  1983. lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
  1984. "%d:0224 NameServer Query timeout "
  1985. "Data: x%x x%x\n",
  1986. phba->brd_no,
  1987. phba->fc_ns_retry, LPFC_MAX_NS_RETRY);
  1988. ndlp = lpfc_findnode_did(phba, NLP_SEARCH_UNMAPPED,
  1989. NameServer_DID);
  1990. if (ndlp) {
  1991. if (phba->fc_ns_retry < LPFC_MAX_NS_RETRY) {
  1992. /* Try it one more time */
  1993. rc = lpfc_ns_cmd(phba, ndlp, SLI_CTNS_GID_FT);
  1994. if (rc == 0)
  1995. break;
  1996. }
  1997. phba->fc_ns_retry = 0;
  1998. }
  1999. /* Nothing to authenticate, so CLEAR_LA right now */
  2000. clearlambox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  2001. if (!clearlambox) {
  2002. clrlaerr = 1;
  2003. lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
  2004. "%d:0226 Device Discovery "
  2005. "completion error\n",
  2006. phba->brd_no);
  2007. phba->hba_state = LPFC_HBA_ERROR;
  2008. break;
  2009. }
  2010. phba->hba_state = LPFC_CLEAR_LA;
  2011. lpfc_clear_la(phba, clearlambox);
  2012. clearlambox->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
  2013. rc = lpfc_sli_issue_mbox(phba, clearlambox,
  2014. (MBX_NOWAIT | MBX_STOP_IOCB));
  2015. if (rc == MBX_NOT_FINISHED) {
  2016. mempool_free(clearlambox, phba->mbox_mem_pool);
  2017. clrlaerr = 1;
  2018. break;
  2019. }
  2020. /* Setup and issue mailbox INITIALIZE LINK command */
  2021. initlinkmbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  2022. if (!initlinkmbox) {
  2023. lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
  2024. "%d:0226 Device Discovery "
  2025. "completion error\n",
  2026. phba->brd_no);
  2027. phba->hba_state = LPFC_HBA_ERROR;
  2028. break;
  2029. }
  2030. lpfc_linkdown(phba);
  2031. lpfc_init_link(phba, initlinkmbox, phba->cfg_topology,
  2032. phba->cfg_link_speed);
  2033. initlinkmbox->mb.un.varInitLnk.lipsr_AL_PA = 0;
  2034. rc = lpfc_sli_issue_mbox(phba, initlinkmbox,
  2035. (MBX_NOWAIT | MBX_STOP_IOCB));
  2036. if (rc == MBX_NOT_FINISHED)
  2037. mempool_free(initlinkmbox, phba->mbox_mem_pool);
  2038. break;
  2039. case LPFC_DISC_AUTH:
  2040. /* Node Authentication timeout */
  2041. lpfc_printf_log(phba,
  2042. KERN_ERR,
  2043. LOG_DISCOVERY,
  2044. "%d:0227 Node Authentication timeout\n",
  2045. phba->brd_no);
  2046. lpfc_disc_flush_list(phba);
  2047. clearlambox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  2048. if (!clearlambox) {
  2049. clrlaerr = 1;
  2050. lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
  2051. "%d:0226 Device Discovery "
  2052. "completion error\n",
  2053. phba->brd_no);
  2054. phba->hba_state = LPFC_HBA_ERROR;
  2055. break;
  2056. }
  2057. phba->hba_state = LPFC_CLEAR_LA;
  2058. lpfc_clear_la(phba, clearlambox);
  2059. clearlambox->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
  2060. rc = lpfc_sli_issue_mbox(phba, clearlambox,
  2061. (MBX_NOWAIT | MBX_STOP_IOCB));
  2062. if (rc == MBX_NOT_FINISHED) {
  2063. mempool_free(clearlambox, phba->mbox_mem_pool);
  2064. clrlaerr = 1;
  2065. }
  2066. break;
  2067. case LPFC_CLEAR_LA:
  2068. /* CLEAR LA timeout */
  2069. lpfc_printf_log(phba,
  2070. KERN_ERR,
  2071. LOG_DISCOVERY,
  2072. "%d:0228 CLEAR LA timeout\n",
  2073. phba->brd_no);
  2074. clrlaerr = 1;
  2075. break;
  2076. case LPFC_HBA_READY:
  2077. if (phba->fc_flag & FC_RSCN_MODE) {
  2078. lpfc_printf_log(phba,
  2079. KERN_ERR,
  2080. LOG_DISCOVERY,
  2081. "%d:0231 RSCN timeout Data: x%x x%x\n",
  2082. phba->brd_no,
  2083. phba->fc_ns_retry, LPFC_MAX_NS_RETRY);
  2084. /* Cleanup any outstanding ELS commands */
  2085. lpfc_els_flush_cmd(phba);
  2086. lpfc_els_flush_rscn(phba);
  2087. lpfc_disc_flush_list(phba);
  2088. }
  2089. break;
  2090. }
  2091. if (clrlaerr) {
  2092. lpfc_disc_flush_list(phba);
  2093. psli->ring[(psli->ip_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
  2094. psli->ring[(psli->fcp_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
  2095. psli->ring[(psli->next_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
  2096. phba->hba_state = LPFC_HBA_READY;
  2097. }
  2098. return;
  2099. }
  2100. static void
  2101. lpfc_nodev_timeout(unsigned long ptr)
  2102. {
  2103. struct lpfc_hba *phba;
  2104. struct lpfc_nodelist *ndlp;
  2105. unsigned long iflag;
  2106. struct lpfc_work_evt *evtp;
  2107. ndlp = (struct lpfc_nodelist *)ptr;
  2108. phba = ndlp->nlp_phba;
  2109. evtp = &ndlp->nodev_timeout_evt;
  2110. spin_lock_irqsave(phba->host->host_lock, iflag);
  2111. if (!list_empty(&evtp->evt_listp)) {
  2112. spin_unlock_irqrestore(phba->host->host_lock, iflag);
  2113. return;
  2114. }
  2115. evtp->evt_arg1 = ndlp;
  2116. evtp->evt = LPFC_EVT_NODEV_TMO;
  2117. list_add_tail(&evtp->evt_listp, &phba->work_list);
  2118. if (phba->work_wait)
  2119. wake_up(phba->work_wait);
  2120. spin_unlock_irqrestore(phba->host->host_lock, iflag);
  2121. return;
  2122. }
  2123. /*
  2124. * This routine handles processing a NameServer REG_LOGIN mailbox
  2125. * command upon completion. It is setup in the LPFC_MBOXQ
  2126. * as the completion routine when the command is
  2127. * handed off to the SLI layer.
  2128. */
  2129. void
  2130. lpfc_mbx_cmpl_fdmi_reg_login(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
  2131. {
  2132. struct lpfc_sli *psli;
  2133. MAILBOX_t *mb;
  2134. struct lpfc_dmabuf *mp;
  2135. struct lpfc_nodelist *ndlp;
  2136. psli = &phba->sli;
  2137. mb = &pmb->mb;
  2138. ndlp = (struct lpfc_nodelist *) pmb->context2;
  2139. mp = (struct lpfc_dmabuf *) (pmb->context1);
  2140. pmb->context1 = NULL;
  2141. if (ndlp->nlp_rpi != 0)
  2142. lpfc_findnode_remove_rpi(phba, ndlp->nlp_rpi);
  2143. ndlp->nlp_rpi = mb->un.varWords[0];
  2144. lpfc_addnode_rpi(phba, ndlp, ndlp->nlp_rpi);
  2145. ndlp->nlp_type |= NLP_FABRIC;
  2146. ndlp->nlp_state = NLP_STE_UNMAPPED_NODE;
  2147. lpfc_nlp_list(phba, ndlp, NLP_UNMAPPED_LIST);
  2148. /* Start issuing Fabric-Device Management Interface (FDMI)
  2149. * command to 0xfffffa (FDMI well known port)
  2150. */
  2151. if (phba->cfg_fdmi_on == 1) {
  2152. lpfc_fdmi_cmd(phba, ndlp, SLI_MGMT_DHBA);
  2153. } else {
  2154. /*
  2155. * Delay issuing FDMI command if fdmi-on=2
  2156. * (supporting RPA/hostnmae)
  2157. */
  2158. mod_timer(&phba->fc_fdmitmo, jiffies + HZ * 60);
  2159. }
  2160. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  2161. kfree(mp);
  2162. mempool_free( pmb, phba->mbox_mem_pool);
  2163. return;
  2164. }
  2165. /*
  2166. * This routine looks up the ndlp hash
  2167. * table for the given RPI. If rpi found
  2168. * it return the node list pointer
  2169. * else return 0.
  2170. */
  2171. struct lpfc_nodelist *
  2172. lpfc_findnode_rpi(struct lpfc_hba * phba, uint16_t rpi)
  2173. {
  2174. struct lpfc_nodelist *ret;
  2175. ret = phba->fc_nlplookup[LPFC_RPI_HASH_FUNC(rpi)];
  2176. while ((ret != 0) && (ret->nlp_rpi != rpi)) {
  2177. ret = ret->nlp_rpi_hash_next;
  2178. }
  2179. return ret;
  2180. }
  2181. /*
  2182. * This routine looks up the ndlp hash table for the
  2183. * given RPI. If rpi found it return the node list
  2184. * pointer else return 0 after deleting the entry
  2185. * from hash table.
  2186. */
  2187. struct lpfc_nodelist *
  2188. lpfc_findnode_remove_rpi(struct lpfc_hba * phba, uint16_t rpi)
  2189. {
  2190. struct lpfc_nodelist *ret, *temp;;
  2191. ret = phba->fc_nlplookup[LPFC_RPI_HASH_FUNC(rpi)];
  2192. if (ret == 0)
  2193. return NULL;
  2194. if (ret->nlp_rpi == rpi) {
  2195. phba->fc_nlplookup[LPFC_RPI_HASH_FUNC(rpi)] =
  2196. ret->nlp_rpi_hash_next;
  2197. ret->nlp_rpi_hash_next = NULL;
  2198. return ret;
  2199. }
  2200. while ((ret->nlp_rpi_hash_next != 0) &&
  2201. (ret->nlp_rpi_hash_next->nlp_rpi != rpi)) {
  2202. ret = ret->nlp_rpi_hash_next;
  2203. }
  2204. if (ret->nlp_rpi_hash_next != 0) {
  2205. temp = ret->nlp_rpi_hash_next;
  2206. ret->nlp_rpi_hash_next = temp->nlp_rpi_hash_next;
  2207. temp->nlp_rpi_hash_next = NULL;
  2208. return temp;
  2209. } else {
  2210. return NULL;
  2211. }
  2212. }
  2213. /*
  2214. * This routine adds the node list entry to the
  2215. * ndlp hash table.
  2216. */
  2217. void
  2218. lpfc_addnode_rpi(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp,
  2219. uint16_t rpi)
  2220. {
  2221. uint32_t index;
  2222. index = LPFC_RPI_HASH_FUNC(rpi);
  2223. ndlp->nlp_rpi_hash_next = phba->fc_nlplookup[index];
  2224. phba->fc_nlplookup[index] = ndlp;
  2225. return;
  2226. }
  2227. void
  2228. lpfc_nlp_init(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp,
  2229. uint32_t did)
  2230. {
  2231. memset(ndlp, 0, sizeof (struct lpfc_nodelist));
  2232. INIT_LIST_HEAD(&ndlp->nodev_timeout_evt.evt_listp);
  2233. INIT_LIST_HEAD(&ndlp->els_retry_evt.evt_listp);
  2234. init_timer(&ndlp->nlp_tmofunc);
  2235. ndlp->nlp_tmofunc.function = lpfc_nodev_timeout;
  2236. ndlp->nlp_tmofunc.data = (unsigned long)ndlp;
  2237. init_timer(&ndlp->nlp_delayfunc);
  2238. ndlp->nlp_delayfunc.function = lpfc_els_retry_delay;
  2239. ndlp->nlp_delayfunc.data = (unsigned long)ndlp;
  2240. ndlp->nlp_DID = did;
  2241. ndlp->nlp_phba = phba;
  2242. ndlp->nlp_sid = NLP_NO_SID;
  2243. return;
  2244. }