lpfc_hbadisc.c 66 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542
  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. /* Remote port has reappeared. Re-register w/ FC transport */
  880. rport_ids.node_name = wwn_to_u64(ndlp->nlp_nodename.u.wwn);
  881. rport_ids.port_name = wwn_to_u64(ndlp->nlp_portname.u.wwn);
  882. rport_ids.port_id = ndlp->nlp_DID;
  883. rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
  884. if (ndlp->nlp_type & NLP_FCP_TARGET)
  885. rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
  886. if (ndlp->nlp_type & NLP_FCP_INITIATOR)
  887. rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
  888. ndlp->rport = rport = fc_remote_port_add(phba->host, 0, &rport_ids);
  889. if (!rport) {
  890. dev_printk(KERN_WARNING, &phba->pcidev->dev,
  891. "Warning: fc_remote_port_add failed\n");
  892. return;
  893. }
  894. /* initialize static port data */
  895. rport->maxframe_size = ndlp->nlp_maxframe;
  896. rport->supported_classes = ndlp->nlp_class_sup;
  897. if ((rport->scsi_target_id != -1) &&
  898. (rport->scsi_target_id < MAX_FCP_TARGET)) {
  899. ndlp->nlp_sid = rport->scsi_target_id;
  900. }
  901. rdata = rport->dd_data;
  902. rdata->pnode = ndlp;
  903. return;
  904. }
  905. int
  906. lpfc_nlp_list(struct lpfc_hba * phba, struct lpfc_nodelist * nlp, int list)
  907. {
  908. enum { none, unmapped, mapped } rport_add = none, rport_del = none;
  909. struct lpfc_sli *psli;
  910. psli = &phba->sli;
  911. /* Sanity check to ensure we are not moving to / from the same list */
  912. if ((nlp->nlp_flag & NLP_LIST_MASK) == list) {
  913. if (list != NLP_NO_LIST)
  914. return(0);
  915. }
  916. switch(nlp->nlp_flag & NLP_LIST_MASK) {
  917. case NLP_NO_LIST: /* Not on any list */
  918. break;
  919. case NLP_UNUSED_LIST:
  920. phba->fc_unused_cnt--;
  921. list_del(&nlp->nlp_listp);
  922. break;
  923. case NLP_PLOGI_LIST:
  924. phba->fc_plogi_cnt--;
  925. list_del(&nlp->nlp_listp);
  926. break;
  927. case NLP_ADISC_LIST:
  928. phba->fc_adisc_cnt--;
  929. list_del(&nlp->nlp_listp);
  930. break;
  931. case NLP_REGLOGIN_LIST:
  932. phba->fc_reglogin_cnt--;
  933. list_del(&nlp->nlp_listp);
  934. break;
  935. case NLP_PRLI_LIST:
  936. phba->fc_prli_cnt--;
  937. list_del(&nlp->nlp_listp);
  938. break;
  939. case NLP_UNMAPPED_LIST:
  940. phba->fc_unmap_cnt--;
  941. list_del(&nlp->nlp_listp);
  942. spin_lock_irq(phba->host->host_lock);
  943. nlp->nlp_flag &= ~NLP_TGT_NO_SCSIID;
  944. nlp->nlp_type &= ~NLP_FC_NODE;
  945. spin_unlock_irq(phba->host->host_lock);
  946. phba->nport_event_cnt++;
  947. if (nlp->rport)
  948. rport_del = unmapped;
  949. break;
  950. case NLP_MAPPED_LIST:
  951. phba->fc_map_cnt--;
  952. list_del(&nlp->nlp_listp);
  953. phba->nport_event_cnt++;
  954. if (nlp->rport)
  955. rport_del = mapped;
  956. break;
  957. case NLP_NPR_LIST:
  958. phba->fc_npr_cnt--;
  959. list_del(&nlp->nlp_listp);
  960. /* Stop delay tmo if taking node off NPR list */
  961. if ((nlp->nlp_flag & NLP_DELAY_TMO) &&
  962. (list != NLP_NPR_LIST)) {
  963. spin_lock_irq(phba->host->host_lock);
  964. nlp->nlp_flag &= ~NLP_DELAY_TMO;
  965. spin_unlock_irq(phba->host->host_lock);
  966. del_timer_sync(&nlp->nlp_delayfunc);
  967. if (!list_empty(&nlp->els_retry_evt.evt_listp))
  968. list_del_init(&nlp->els_retry_evt.evt_listp);
  969. }
  970. break;
  971. }
  972. spin_lock_irq(phba->host->host_lock);
  973. nlp->nlp_flag &= ~NLP_LIST_MASK;
  974. spin_unlock_irq(phba->host->host_lock);
  975. /* Add NPort <did> to <num> list */
  976. lpfc_printf_log(phba,
  977. KERN_INFO,
  978. LOG_NODE,
  979. "%d:0904 Add NPort x%x to %d list Data: x%x\n",
  980. phba->brd_no,
  981. nlp->nlp_DID, list, nlp->nlp_flag);
  982. switch(list) {
  983. case NLP_NO_LIST: /* No list, just remove it */
  984. lpfc_nlp_remove(phba, nlp);
  985. /* as node removed - stop further transport calls */
  986. rport_del = none;
  987. break;
  988. case NLP_UNUSED_LIST:
  989. spin_lock_irq(phba->host->host_lock);
  990. nlp->nlp_flag |= list;
  991. spin_unlock_irq(phba->host->host_lock);
  992. /* Put it at the end of the unused list */
  993. list_add_tail(&nlp->nlp_listp, &phba->fc_unused_list);
  994. phba->fc_unused_cnt++;
  995. break;
  996. case NLP_PLOGI_LIST:
  997. spin_lock_irq(phba->host->host_lock);
  998. nlp->nlp_flag |= list;
  999. spin_unlock_irq(phba->host->host_lock);
  1000. /* Put it at the end of the plogi list */
  1001. list_add_tail(&nlp->nlp_listp, &phba->fc_plogi_list);
  1002. phba->fc_plogi_cnt++;
  1003. break;
  1004. case NLP_ADISC_LIST:
  1005. spin_lock_irq(phba->host->host_lock);
  1006. nlp->nlp_flag |= list;
  1007. spin_unlock_irq(phba->host->host_lock);
  1008. /* Put it at the end of the adisc list */
  1009. list_add_tail(&nlp->nlp_listp, &phba->fc_adisc_list);
  1010. phba->fc_adisc_cnt++;
  1011. break;
  1012. case NLP_REGLOGIN_LIST:
  1013. spin_lock_irq(phba->host->host_lock);
  1014. nlp->nlp_flag |= list;
  1015. spin_unlock_irq(phba->host->host_lock);
  1016. /* Put it at the end of the reglogin list */
  1017. list_add_tail(&nlp->nlp_listp, &phba->fc_reglogin_list);
  1018. phba->fc_reglogin_cnt++;
  1019. break;
  1020. case NLP_PRLI_LIST:
  1021. spin_lock_irq(phba->host->host_lock);
  1022. nlp->nlp_flag |= list;
  1023. spin_unlock_irq(phba->host->host_lock);
  1024. /* Put it at the end of the prli list */
  1025. list_add_tail(&nlp->nlp_listp, &phba->fc_prli_list);
  1026. phba->fc_prli_cnt++;
  1027. break;
  1028. case NLP_UNMAPPED_LIST:
  1029. rport_add = unmapped;
  1030. /* ensure all vestiges of "mapped" significance are gone */
  1031. nlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
  1032. spin_lock_irq(phba->host->host_lock);
  1033. nlp->nlp_flag |= list;
  1034. spin_unlock_irq(phba->host->host_lock);
  1035. /* Put it at the end of the unmap list */
  1036. list_add_tail(&nlp->nlp_listp, &phba->fc_nlpunmap_list);
  1037. phba->fc_unmap_cnt++;
  1038. phba->nport_event_cnt++;
  1039. /* stop nodev tmo if running */
  1040. if (nlp->nlp_flag & NLP_NODEV_TMO) {
  1041. spin_lock_irq(phba->host->host_lock);
  1042. nlp->nlp_flag &= ~NLP_NODEV_TMO;
  1043. spin_unlock_irq(phba->host->host_lock);
  1044. del_timer_sync(&nlp->nlp_tmofunc);
  1045. if (!list_empty(&nlp->nodev_timeout_evt.evt_listp))
  1046. list_del_init(&nlp->nodev_timeout_evt.
  1047. evt_listp);
  1048. }
  1049. nlp->nlp_type |= NLP_FC_NODE;
  1050. break;
  1051. case NLP_MAPPED_LIST:
  1052. rport_add = mapped;
  1053. spin_lock_irq(phba->host->host_lock);
  1054. nlp->nlp_flag |= list;
  1055. spin_unlock_irq(phba->host->host_lock);
  1056. /* Put it at the end of the map list */
  1057. list_add_tail(&nlp->nlp_listp, &phba->fc_nlpmap_list);
  1058. phba->fc_map_cnt++;
  1059. phba->nport_event_cnt++;
  1060. /* stop nodev tmo if running */
  1061. if (nlp->nlp_flag & NLP_NODEV_TMO) {
  1062. nlp->nlp_flag &= ~NLP_NODEV_TMO;
  1063. del_timer_sync(&nlp->nlp_tmofunc);
  1064. if (!list_empty(&nlp->nodev_timeout_evt.evt_listp))
  1065. list_del_init(&nlp->nodev_timeout_evt.
  1066. evt_listp);
  1067. }
  1068. break;
  1069. case NLP_NPR_LIST:
  1070. spin_lock_irq(phba->host->host_lock);
  1071. nlp->nlp_flag |= list;
  1072. spin_unlock_irq(phba->host->host_lock);
  1073. /* Put it at the end of the npr list */
  1074. list_add_tail(&nlp->nlp_listp, &phba->fc_npr_list);
  1075. phba->fc_npr_cnt++;
  1076. /*
  1077. * Sanity check for Fabric entity.
  1078. * Set nodev_tmo for NPR state, for Fabric use 1 sec.
  1079. */
  1080. if (nlp->nlp_type & NLP_FABRIC) {
  1081. mod_timer(&nlp->nlp_tmofunc, jiffies + HZ);
  1082. }
  1083. else {
  1084. mod_timer(&nlp->nlp_tmofunc,
  1085. jiffies + HZ * phba->cfg_nodev_tmo);
  1086. }
  1087. spin_lock_irq(phba->host->host_lock);
  1088. nlp->nlp_flag |= NLP_NODEV_TMO;
  1089. nlp->nlp_flag &= ~NLP_RCV_PLOGI;
  1090. spin_unlock_irq(phba->host->host_lock);
  1091. break;
  1092. case NLP_JUST_DQ:
  1093. break;
  1094. }
  1095. /*
  1096. * We make all the calls into the transport after we have
  1097. * moved the node between lists. This so that we don't
  1098. * release the lock while in-between lists.
  1099. */
  1100. /* Don't upcall midlayer if we're unloading */
  1101. if (!(phba->fc_flag & FC_UNLOADING)) {
  1102. /*
  1103. * We revalidate the rport pointer as the "add" function
  1104. * may have removed the remote port.
  1105. */
  1106. if ((rport_del != none) && nlp->rport)
  1107. fc_remote_port_block(nlp->rport);
  1108. if (rport_add != none) {
  1109. /*
  1110. * Tell the fc transport about the port, if we haven't
  1111. * already. If we have, and it's a scsi entity, be
  1112. * sure to unblock any attached scsi devices
  1113. */
  1114. if (!nlp->rport)
  1115. lpfc_register_remote_port(phba, nlp);
  1116. else
  1117. fc_remote_port_unblock(nlp->rport);
  1118. /*
  1119. * if we added to Mapped list, but the remote port
  1120. * registration failed or assigned a target id outside
  1121. * our presentable range - move the node to the
  1122. * Unmapped List
  1123. */
  1124. if ((rport_add == mapped) &&
  1125. ((!nlp->rport) ||
  1126. (nlp->rport->scsi_target_id == -1) ||
  1127. (nlp->rport->scsi_target_id >= MAX_FCP_TARGET))) {
  1128. nlp->nlp_state = NLP_STE_UNMAPPED_NODE;
  1129. spin_lock_irq(phba->host->host_lock);
  1130. nlp->nlp_flag |= NLP_TGT_NO_SCSIID;
  1131. spin_unlock_irq(phba->host->host_lock);
  1132. lpfc_nlp_list(phba, nlp, NLP_UNMAPPED_LIST);
  1133. }
  1134. }
  1135. }
  1136. return (0);
  1137. }
  1138. /*
  1139. * Start / ReStart rescue timer for Discovery / RSCN handling
  1140. */
  1141. void
  1142. lpfc_set_disctmo(struct lpfc_hba * phba)
  1143. {
  1144. uint32_t tmo;
  1145. tmo = ((phba->fc_ratov * 2) + 1);
  1146. mod_timer(&phba->fc_disctmo, jiffies + HZ * tmo);
  1147. spin_lock_irq(phba->host->host_lock);
  1148. phba->fc_flag |= FC_DISC_TMO;
  1149. spin_unlock_irq(phba->host->host_lock);
  1150. /* Start Discovery Timer state <hba_state> */
  1151. lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
  1152. "%d:0247 Start Discovery Timer state x%x "
  1153. "Data: x%x x%lx x%x x%x\n",
  1154. phba->brd_no,
  1155. phba->hba_state, tmo, (unsigned long)&phba->fc_disctmo,
  1156. phba->fc_plogi_cnt, phba->fc_adisc_cnt);
  1157. return;
  1158. }
  1159. /*
  1160. * Cancel rescue timer for Discovery / RSCN handling
  1161. */
  1162. int
  1163. lpfc_can_disctmo(struct lpfc_hba * phba)
  1164. {
  1165. /* Turn off discovery timer if its running */
  1166. if (phba->fc_flag & FC_DISC_TMO) {
  1167. spin_lock_irq(phba->host->host_lock);
  1168. phba->fc_flag &= ~FC_DISC_TMO;
  1169. spin_unlock_irq(phba->host->host_lock);
  1170. del_timer_sync(&phba->fc_disctmo);
  1171. phba->work_hba_events &= ~WORKER_DISC_TMO;
  1172. }
  1173. /* Cancel Discovery Timer state <hba_state> */
  1174. lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
  1175. "%d:0248 Cancel Discovery Timer state x%x "
  1176. "Data: x%x x%x x%x\n",
  1177. phba->brd_no, phba->hba_state, phba->fc_flag,
  1178. phba->fc_plogi_cnt, phba->fc_adisc_cnt);
  1179. return (0);
  1180. }
  1181. /*
  1182. * Check specified ring for outstanding IOCB on the SLI queue
  1183. * Return true if iocb matches the specified nport
  1184. */
  1185. int
  1186. lpfc_check_sli_ndlp(struct lpfc_hba * phba,
  1187. struct lpfc_sli_ring * pring,
  1188. struct lpfc_iocbq * iocb, struct lpfc_nodelist * ndlp)
  1189. {
  1190. struct lpfc_sli *psli;
  1191. IOCB_t *icmd;
  1192. psli = &phba->sli;
  1193. icmd = &iocb->iocb;
  1194. if (pring->ringno == LPFC_ELS_RING) {
  1195. switch (icmd->ulpCommand) {
  1196. case CMD_GEN_REQUEST64_CR:
  1197. if (icmd->ulpContext == (volatile ushort)ndlp->nlp_rpi)
  1198. return (1);
  1199. case CMD_ELS_REQUEST64_CR:
  1200. case CMD_XMIT_ELS_RSP64_CX:
  1201. if (iocb->context1 == (uint8_t *) ndlp)
  1202. return (1);
  1203. }
  1204. } else if (pring->ringno == psli->ip_ring) {
  1205. } else if (pring->ringno == psli->fcp_ring) {
  1206. /* Skip match check if waiting to relogin to FCP target */
  1207. if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
  1208. (ndlp->nlp_flag & NLP_DELAY_TMO)) {
  1209. return (0);
  1210. }
  1211. if (icmd->ulpContext == (volatile ushort)ndlp->nlp_rpi) {
  1212. return (1);
  1213. }
  1214. } else if (pring->ringno == psli->next_ring) {
  1215. }
  1216. return (0);
  1217. }
  1218. /*
  1219. * Free resources / clean up outstanding I/Os
  1220. * associated with nlp_rpi in the LPFC_NODELIST entry.
  1221. */
  1222. static int
  1223. lpfc_no_rpi(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp)
  1224. {
  1225. struct lpfc_sli *psli;
  1226. struct lpfc_sli_ring *pring;
  1227. struct lpfc_iocbq *iocb, *next_iocb;
  1228. IOCB_t *icmd;
  1229. uint32_t rpi, i;
  1230. /*
  1231. * Everything that matches on txcmplq will be returned
  1232. * by firmware with a no rpi error.
  1233. */
  1234. psli = &phba->sli;
  1235. rpi = ndlp->nlp_rpi;
  1236. if (rpi) {
  1237. /* Now process each ring */
  1238. for (i = 0; i < psli->num_rings; i++) {
  1239. pring = &psli->ring[i];
  1240. spin_lock_irq(phba->host->host_lock);
  1241. list_for_each_entry_safe(iocb, next_iocb, &pring->txq,
  1242. list) {
  1243. /*
  1244. * Check to see if iocb matches the nport we are
  1245. * looking for
  1246. */
  1247. if ((lpfc_check_sli_ndlp
  1248. (phba, pring, iocb, ndlp))) {
  1249. /* It matches, so deque and call compl
  1250. with an error */
  1251. list_del(&iocb->list);
  1252. pring->txq_cnt--;
  1253. if (iocb->iocb_cmpl) {
  1254. icmd = &iocb->iocb;
  1255. icmd->ulpStatus =
  1256. IOSTAT_LOCAL_REJECT;
  1257. icmd->un.ulpWord[4] =
  1258. IOERR_SLI_ABORTED;
  1259. spin_unlock_irq(phba->host->
  1260. host_lock);
  1261. (iocb->iocb_cmpl) (phba,
  1262. iocb, iocb);
  1263. spin_lock_irq(phba->host->
  1264. host_lock);
  1265. } else {
  1266. list_add_tail(&iocb->list,
  1267. &phba->lpfc_iocb_list);
  1268. }
  1269. }
  1270. }
  1271. spin_unlock_irq(phba->host->host_lock);
  1272. }
  1273. }
  1274. return (0);
  1275. }
  1276. /*
  1277. * Free rpi associated with LPFC_NODELIST entry.
  1278. * This routine is called from lpfc_freenode(), when we are removing
  1279. * a LPFC_NODELIST entry. It is also called if the driver initiates a
  1280. * LOGO that completes successfully, and we are waiting to PLOGI back
  1281. * to the remote NPort. In addition, it is called after we receive
  1282. * and unsolicated ELS cmd, send back a rsp, the rsp completes and
  1283. * we are waiting to PLOGI back to the remote NPort.
  1284. */
  1285. int
  1286. lpfc_unreg_rpi(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp)
  1287. {
  1288. LPFC_MBOXQ_t *mbox;
  1289. int rc;
  1290. if (ndlp->nlp_rpi) {
  1291. if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL))) {
  1292. lpfc_unreg_login(phba, ndlp->nlp_rpi, mbox);
  1293. mbox->mbox_cmpl=lpfc_sli_def_mbox_cmpl;
  1294. rc = lpfc_sli_issue_mbox
  1295. (phba, mbox, (MBX_NOWAIT | MBX_STOP_IOCB));
  1296. if (rc == MBX_NOT_FINISHED)
  1297. mempool_free( mbox, phba->mbox_mem_pool);
  1298. }
  1299. lpfc_findnode_remove_rpi(phba, ndlp->nlp_rpi);
  1300. lpfc_no_rpi(phba, ndlp);
  1301. ndlp->nlp_rpi = 0;
  1302. return 1;
  1303. }
  1304. return 0;
  1305. }
  1306. /*
  1307. * Free resources associated with LPFC_NODELIST entry
  1308. * so it can be freed.
  1309. */
  1310. static int
  1311. lpfc_freenode(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp)
  1312. {
  1313. LPFC_MBOXQ_t *mb;
  1314. LPFC_MBOXQ_t *nextmb;
  1315. struct lpfc_dmabuf *mp;
  1316. struct fc_rport *rport;
  1317. /* Cleanup node for NPort <nlp_DID> */
  1318. lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
  1319. "%d:0900 Cleanup node for NPort x%x "
  1320. "Data: x%x x%x x%x\n",
  1321. phba->brd_no, ndlp->nlp_DID, ndlp->nlp_flag,
  1322. ndlp->nlp_state, ndlp->nlp_rpi);
  1323. lpfc_nlp_list(phba, ndlp, NLP_JUST_DQ);
  1324. /*
  1325. * if unloading the driver - just leave the remote port in place.
  1326. * The driver unload will force the attached devices to detach
  1327. * and flush cache's w/o generating flush errors.
  1328. */
  1329. if ((ndlp->rport) && !(phba->fc_flag & FC_UNLOADING)) {
  1330. rport = ndlp->rport;
  1331. ndlp->rport = NULL;
  1332. fc_remote_port_unblock(rport);
  1333. fc_remote_port_delete(rport);
  1334. ndlp->nlp_sid = NLP_NO_SID;
  1335. }
  1336. /* cleanup any ndlp on mbox q waiting for reglogin cmpl */
  1337. if ((mb = phba->sli.mbox_active)) {
  1338. if ((mb->mb.mbxCommand == MBX_REG_LOGIN64) &&
  1339. (ndlp == (struct lpfc_nodelist *) mb->context2)) {
  1340. mb->context2 = NULL;
  1341. mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  1342. }
  1343. }
  1344. list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
  1345. if ((mb->mb.mbxCommand == MBX_REG_LOGIN64) &&
  1346. (ndlp == (struct lpfc_nodelist *) mb->context2)) {
  1347. mp = (struct lpfc_dmabuf *) (mb->context1);
  1348. if (mp) {
  1349. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  1350. kfree(mp);
  1351. }
  1352. list_del(&mb->list);
  1353. mempool_free(mb, phba->mbox_mem_pool);
  1354. }
  1355. }
  1356. lpfc_els_abort(phba,ndlp,0);
  1357. spin_lock_irq(phba->host->host_lock);
  1358. ndlp->nlp_flag &= ~(NLP_NODEV_TMO|NLP_DELAY_TMO);
  1359. spin_unlock_irq(phba->host->host_lock);
  1360. del_timer_sync(&ndlp->nlp_tmofunc);
  1361. del_timer_sync(&ndlp->nlp_delayfunc);
  1362. if (!list_empty(&ndlp->nodev_timeout_evt.evt_listp))
  1363. list_del_init(&ndlp->nodev_timeout_evt.evt_listp);
  1364. if (!list_empty(&ndlp->els_retry_evt.evt_listp))
  1365. list_del_init(&ndlp->els_retry_evt.evt_listp);
  1366. lpfc_unreg_rpi(phba, ndlp);
  1367. return (0);
  1368. }
  1369. /*
  1370. * Check to see if we can free the nlp back to the freelist.
  1371. * If we are in the middle of using the nlp in the discovery state
  1372. * machine, defer the free till we reach the end of the state machine.
  1373. */
  1374. int
  1375. lpfc_nlp_remove(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp)
  1376. {
  1377. if (ndlp->nlp_flag & NLP_NODEV_TMO) {
  1378. spin_lock_irq(phba->host->host_lock);
  1379. ndlp->nlp_flag &= ~NLP_NODEV_TMO;
  1380. spin_unlock_irq(phba->host->host_lock);
  1381. del_timer_sync(&ndlp->nlp_tmofunc);
  1382. if (!list_empty(&ndlp->nodev_timeout_evt.evt_listp))
  1383. list_del_init(&ndlp->nodev_timeout_evt.evt_listp);
  1384. }
  1385. if (ndlp->nlp_flag & NLP_DELAY_TMO) {
  1386. spin_lock_irq(phba->host->host_lock);
  1387. ndlp->nlp_flag &= ~NLP_DELAY_TMO;
  1388. spin_unlock_irq(phba->host->host_lock);
  1389. del_timer_sync(&ndlp->nlp_delayfunc);
  1390. if (!list_empty(&ndlp->els_retry_evt.evt_listp))
  1391. list_del_init(&ndlp->els_retry_evt.evt_listp);
  1392. }
  1393. if (ndlp->nlp_disc_refcnt) {
  1394. spin_lock_irq(phba->host->host_lock);
  1395. ndlp->nlp_flag |= NLP_DELAY_REMOVE;
  1396. spin_unlock_irq(phba->host->host_lock);
  1397. }
  1398. else {
  1399. lpfc_freenode(phba, ndlp);
  1400. mempool_free( ndlp, phba->nlp_mem_pool);
  1401. }
  1402. return(0);
  1403. }
  1404. static int
  1405. lpfc_matchdid(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp, uint32_t did)
  1406. {
  1407. D_ID mydid;
  1408. D_ID ndlpdid;
  1409. D_ID matchdid;
  1410. if (did == Bcast_DID)
  1411. return (0);
  1412. if (ndlp->nlp_DID == 0) {
  1413. return (0);
  1414. }
  1415. /* First check for Direct match */
  1416. if (ndlp->nlp_DID == did)
  1417. return (1);
  1418. /* Next check for area/domain identically equals 0 match */
  1419. mydid.un.word = phba->fc_myDID;
  1420. if ((mydid.un.b.domain == 0) && (mydid.un.b.area == 0)) {
  1421. return (0);
  1422. }
  1423. matchdid.un.word = did;
  1424. ndlpdid.un.word = ndlp->nlp_DID;
  1425. if (matchdid.un.b.id == ndlpdid.un.b.id) {
  1426. if ((mydid.un.b.domain == matchdid.un.b.domain) &&
  1427. (mydid.un.b.area == matchdid.un.b.area)) {
  1428. if ((ndlpdid.un.b.domain == 0) &&
  1429. (ndlpdid.un.b.area == 0)) {
  1430. if (ndlpdid.un.b.id)
  1431. return (1);
  1432. }
  1433. return (0);
  1434. }
  1435. matchdid.un.word = ndlp->nlp_DID;
  1436. if ((mydid.un.b.domain == ndlpdid.un.b.domain) &&
  1437. (mydid.un.b.area == ndlpdid.un.b.area)) {
  1438. if ((matchdid.un.b.domain == 0) &&
  1439. (matchdid.un.b.area == 0)) {
  1440. if (matchdid.un.b.id)
  1441. return (1);
  1442. }
  1443. }
  1444. }
  1445. return (0);
  1446. }
  1447. /* Search for a nodelist entry on a specific list */
  1448. struct lpfc_nodelist *
  1449. lpfc_findnode_did(struct lpfc_hba * phba, uint32_t order, uint32_t did)
  1450. {
  1451. struct lpfc_nodelist *ndlp, *next_ndlp;
  1452. uint32_t data1;
  1453. if (order & NLP_SEARCH_UNMAPPED) {
  1454. list_for_each_entry_safe(ndlp, next_ndlp,
  1455. &phba->fc_nlpunmap_list, nlp_listp) {
  1456. if (lpfc_matchdid(phba, ndlp, did)) {
  1457. data1 = (((uint32_t) ndlp->nlp_state << 24) |
  1458. ((uint32_t) ndlp->nlp_xri << 16) |
  1459. ((uint32_t) ndlp->nlp_type << 8) |
  1460. ((uint32_t) ndlp->nlp_rpi & 0xff));
  1461. /* FIND node DID unmapped */
  1462. lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
  1463. "%d:0929 FIND node DID unmapped"
  1464. " Data: x%p x%x x%x x%x\n",
  1465. phba->brd_no,
  1466. ndlp, ndlp->nlp_DID,
  1467. ndlp->nlp_flag, data1);
  1468. return (ndlp);
  1469. }
  1470. }
  1471. }
  1472. if (order & NLP_SEARCH_MAPPED) {
  1473. list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_nlpmap_list,
  1474. nlp_listp) {
  1475. if (lpfc_matchdid(phba, ndlp, did)) {
  1476. data1 = (((uint32_t) ndlp->nlp_state << 24) |
  1477. ((uint32_t) ndlp->nlp_xri << 16) |
  1478. ((uint32_t) ndlp->nlp_type << 8) |
  1479. ((uint32_t) ndlp->nlp_rpi & 0xff));
  1480. /* FIND node DID mapped */
  1481. lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
  1482. "%d:0930 FIND node DID mapped "
  1483. "Data: x%p x%x x%x x%x\n",
  1484. phba->brd_no,
  1485. ndlp, ndlp->nlp_DID,
  1486. ndlp->nlp_flag, data1);
  1487. return (ndlp);
  1488. }
  1489. }
  1490. }
  1491. if (order & NLP_SEARCH_PLOGI) {
  1492. list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_plogi_list,
  1493. nlp_listp) {
  1494. if (lpfc_matchdid(phba, ndlp, did)) {
  1495. data1 = (((uint32_t) ndlp->nlp_state << 24) |
  1496. ((uint32_t) ndlp->nlp_xri << 16) |
  1497. ((uint32_t) ndlp->nlp_type << 8) |
  1498. ((uint32_t) ndlp->nlp_rpi & 0xff));
  1499. /* LOG change to PLOGI */
  1500. /* FIND node DID plogi */
  1501. lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
  1502. "%d:0908 FIND node DID plogi "
  1503. "Data: x%p x%x x%x x%x\n",
  1504. phba->brd_no,
  1505. ndlp, ndlp->nlp_DID,
  1506. ndlp->nlp_flag, data1);
  1507. return (ndlp);
  1508. }
  1509. }
  1510. }
  1511. if (order & NLP_SEARCH_ADISC) {
  1512. list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_adisc_list,
  1513. nlp_listp) {
  1514. if (lpfc_matchdid(phba, ndlp, did)) {
  1515. data1 = (((uint32_t) ndlp->nlp_state << 24) |
  1516. ((uint32_t) ndlp->nlp_xri << 16) |
  1517. ((uint32_t) ndlp->nlp_type << 8) |
  1518. ((uint32_t) ndlp->nlp_rpi & 0xff));
  1519. /* LOG change to ADISC */
  1520. /* FIND node DID adisc */
  1521. lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
  1522. "%d:0931 FIND node DID adisc "
  1523. "Data: x%p x%x x%x x%x\n",
  1524. phba->brd_no,
  1525. ndlp, ndlp->nlp_DID,
  1526. ndlp->nlp_flag, data1);
  1527. return (ndlp);
  1528. }
  1529. }
  1530. }
  1531. if (order & NLP_SEARCH_REGLOGIN) {
  1532. list_for_each_entry_safe(ndlp, next_ndlp,
  1533. &phba->fc_reglogin_list, nlp_listp) {
  1534. if (lpfc_matchdid(phba, ndlp, did)) {
  1535. data1 = (((uint32_t) ndlp->nlp_state << 24) |
  1536. ((uint32_t) ndlp->nlp_xri << 16) |
  1537. ((uint32_t) ndlp->nlp_type << 8) |
  1538. ((uint32_t) ndlp->nlp_rpi & 0xff));
  1539. /* LOG change to REGLOGIN */
  1540. /* FIND node DID reglogin */
  1541. lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
  1542. "%d:0931 FIND node DID reglogin"
  1543. " Data: x%p x%x x%x x%x\n",
  1544. phba->brd_no,
  1545. ndlp, ndlp->nlp_DID,
  1546. ndlp->nlp_flag, data1);
  1547. return (ndlp);
  1548. }
  1549. }
  1550. }
  1551. if (order & NLP_SEARCH_PRLI) {
  1552. list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_prli_list,
  1553. nlp_listp) {
  1554. if (lpfc_matchdid(phba, ndlp, did)) {
  1555. data1 = (((uint32_t) ndlp->nlp_state << 24) |
  1556. ((uint32_t) ndlp->nlp_xri << 16) |
  1557. ((uint32_t) ndlp->nlp_type << 8) |
  1558. ((uint32_t) ndlp->nlp_rpi & 0xff));
  1559. /* LOG change to PRLI */
  1560. /* FIND node DID prli */
  1561. lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
  1562. "%d:0931 FIND node DID prli "
  1563. "Data: x%p x%x x%x x%x\n",
  1564. phba->brd_no,
  1565. ndlp, ndlp->nlp_DID,
  1566. ndlp->nlp_flag, data1);
  1567. return (ndlp);
  1568. }
  1569. }
  1570. }
  1571. if (order & NLP_SEARCH_NPR) {
  1572. list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_npr_list,
  1573. nlp_listp) {
  1574. if (lpfc_matchdid(phba, ndlp, did)) {
  1575. data1 = (((uint32_t) ndlp->nlp_state << 24) |
  1576. ((uint32_t) ndlp->nlp_xri << 16) |
  1577. ((uint32_t) ndlp->nlp_type << 8) |
  1578. ((uint32_t) ndlp->nlp_rpi & 0xff));
  1579. /* LOG change to NPR */
  1580. /* FIND node DID npr */
  1581. lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
  1582. "%d:0931 FIND node DID npr "
  1583. "Data: x%p x%x x%x x%x\n",
  1584. phba->brd_no,
  1585. ndlp, ndlp->nlp_DID,
  1586. ndlp->nlp_flag, data1);
  1587. return (ndlp);
  1588. }
  1589. }
  1590. }
  1591. if (order & NLP_SEARCH_UNUSED) {
  1592. list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_adisc_list,
  1593. nlp_listp) {
  1594. if (lpfc_matchdid(phba, ndlp, did)) {
  1595. data1 = (((uint32_t) ndlp->nlp_state << 24) |
  1596. ((uint32_t) ndlp->nlp_xri << 16) |
  1597. ((uint32_t) ndlp->nlp_type << 8) |
  1598. ((uint32_t) ndlp->nlp_rpi & 0xff));
  1599. /* LOG change to UNUSED */
  1600. /* FIND node DID unused */
  1601. lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
  1602. "%d:0931 FIND node DID unused "
  1603. "Data: x%p x%x x%x x%x\n",
  1604. phba->brd_no,
  1605. ndlp, ndlp->nlp_DID,
  1606. ndlp->nlp_flag, data1);
  1607. return (ndlp);
  1608. }
  1609. }
  1610. }
  1611. /* FIND node did <did> NOT FOUND */
  1612. lpfc_printf_log(phba,
  1613. KERN_INFO,
  1614. LOG_NODE,
  1615. "%d:0932 FIND node did x%x NOT FOUND Data: x%x\n",
  1616. phba->brd_no, did, order);
  1617. /* no match found */
  1618. return NULL;
  1619. }
  1620. struct lpfc_nodelist *
  1621. lpfc_setup_disc_node(struct lpfc_hba * phba, uint32_t did)
  1622. {
  1623. struct lpfc_nodelist *ndlp;
  1624. uint32_t flg;
  1625. if ((ndlp = lpfc_findnode_did(phba, NLP_SEARCH_ALL, did)) == 0) {
  1626. if ((phba->hba_state == LPFC_HBA_READY) &&
  1627. ((lpfc_rscn_payload_check(phba, did) == 0)))
  1628. return NULL;
  1629. ndlp = (struct lpfc_nodelist *)
  1630. mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
  1631. if (!ndlp)
  1632. return NULL;
  1633. lpfc_nlp_init(phba, ndlp, did);
  1634. ndlp->nlp_state = NLP_STE_NPR_NODE;
  1635. lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
  1636. ndlp->nlp_flag |= NLP_NPR_2B_DISC;
  1637. return ndlp;
  1638. }
  1639. if ((phba->hba_state == LPFC_HBA_READY) &&
  1640. (phba->fc_flag & FC_RSCN_MODE)) {
  1641. if (lpfc_rscn_payload_check(phba, did)) {
  1642. ndlp->nlp_flag |= NLP_NPR_2B_DISC;
  1643. }
  1644. else {
  1645. ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
  1646. ndlp = NULL;
  1647. }
  1648. }
  1649. else {
  1650. flg = ndlp->nlp_flag & NLP_LIST_MASK;
  1651. if ((flg == NLP_ADISC_LIST) ||
  1652. (flg == NLP_PLOGI_LIST)) {
  1653. return NULL;
  1654. }
  1655. ndlp->nlp_state = NLP_STE_NPR_NODE;
  1656. lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
  1657. ndlp->nlp_flag |= NLP_NPR_2B_DISC;
  1658. }
  1659. return ndlp;
  1660. }
  1661. /* Build a list of nodes to discover based on the loopmap */
  1662. void
  1663. lpfc_disc_list_loopmap(struct lpfc_hba * phba)
  1664. {
  1665. int j;
  1666. uint32_t alpa, index;
  1667. if (phba->hba_state <= LPFC_LINK_DOWN) {
  1668. return;
  1669. }
  1670. if (phba->fc_topology != TOPOLOGY_LOOP) {
  1671. return;
  1672. }
  1673. /* Check for loop map present or not */
  1674. if (phba->alpa_map[0]) {
  1675. for (j = 1; j <= phba->alpa_map[0]; j++) {
  1676. alpa = phba->alpa_map[j];
  1677. if (((phba->fc_myDID & 0xff) == alpa) || (alpa == 0)) {
  1678. continue;
  1679. }
  1680. lpfc_setup_disc_node(phba, alpa);
  1681. }
  1682. } else {
  1683. /* No alpamap, so try all alpa's */
  1684. for (j = 0; j < FC_MAXLOOP; j++) {
  1685. /* If cfg_scan_down is set, start from highest
  1686. * ALPA (0xef) to lowest (0x1).
  1687. */
  1688. if (phba->cfg_scan_down)
  1689. index = j;
  1690. else
  1691. index = FC_MAXLOOP - j - 1;
  1692. alpa = lpfcAlpaArray[index];
  1693. if ((phba->fc_myDID & 0xff) == alpa) {
  1694. continue;
  1695. }
  1696. lpfc_setup_disc_node(phba, alpa);
  1697. }
  1698. }
  1699. return;
  1700. }
  1701. /* Start Link up / RSCN discovery on NPR list */
  1702. void
  1703. lpfc_disc_start(struct lpfc_hba * phba)
  1704. {
  1705. struct lpfc_sli *psli;
  1706. LPFC_MBOXQ_t *mbox;
  1707. struct lpfc_nodelist *ndlp, *next_ndlp;
  1708. uint32_t did_changed, num_sent;
  1709. uint32_t clear_la_pending;
  1710. int rc;
  1711. psli = &phba->sli;
  1712. if (phba->hba_state <= LPFC_LINK_DOWN) {
  1713. return;
  1714. }
  1715. if (phba->hba_state == LPFC_CLEAR_LA)
  1716. clear_la_pending = 1;
  1717. else
  1718. clear_la_pending = 0;
  1719. if (phba->hba_state < LPFC_HBA_READY) {
  1720. phba->hba_state = LPFC_DISC_AUTH;
  1721. }
  1722. lpfc_set_disctmo(phba);
  1723. if (phba->fc_prevDID == phba->fc_myDID) {
  1724. did_changed = 0;
  1725. } else {
  1726. did_changed = 1;
  1727. }
  1728. phba->fc_prevDID = phba->fc_myDID;
  1729. phba->num_disc_nodes = 0;
  1730. /* Start Discovery state <hba_state> */
  1731. lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
  1732. "%d:0202 Start Discovery hba state x%x "
  1733. "Data: x%x x%x x%x\n",
  1734. phba->brd_no, phba->hba_state, phba->fc_flag,
  1735. phba->fc_plogi_cnt, phba->fc_adisc_cnt);
  1736. /* If our did changed, we MUST do PLOGI */
  1737. list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_npr_list,
  1738. nlp_listp) {
  1739. if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
  1740. if (did_changed) {
  1741. spin_lock_irq(phba->host->host_lock);
  1742. ndlp->nlp_flag &= ~NLP_NPR_ADISC;
  1743. spin_unlock_irq(phba->host->host_lock);
  1744. }
  1745. }
  1746. }
  1747. /* First do ADISCs - if any */
  1748. num_sent = lpfc_els_disc_adisc(phba);
  1749. if (num_sent)
  1750. return;
  1751. if ((phba->hba_state < LPFC_HBA_READY) && (!clear_la_pending)) {
  1752. /* If we get here, there is nothing to ADISC */
  1753. if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL))) {
  1754. phba->hba_state = LPFC_CLEAR_LA;
  1755. lpfc_clear_la(phba, mbox);
  1756. mbox->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
  1757. rc = lpfc_sli_issue_mbox(phba, mbox,
  1758. (MBX_NOWAIT | MBX_STOP_IOCB));
  1759. if (rc == MBX_NOT_FINISHED) {
  1760. mempool_free( mbox, phba->mbox_mem_pool);
  1761. lpfc_disc_flush_list(phba);
  1762. psli->ring[(psli->ip_ring)].flag &=
  1763. ~LPFC_STOP_IOCB_EVENT;
  1764. psli->ring[(psli->fcp_ring)].flag &=
  1765. ~LPFC_STOP_IOCB_EVENT;
  1766. psli->ring[(psli->next_ring)].flag &=
  1767. ~LPFC_STOP_IOCB_EVENT;
  1768. phba->hba_state = LPFC_HBA_READY;
  1769. }
  1770. }
  1771. } else {
  1772. /* Next do PLOGIs - if any */
  1773. num_sent = lpfc_els_disc_plogi(phba);
  1774. if (num_sent)
  1775. return;
  1776. if (phba->fc_flag & FC_RSCN_MODE) {
  1777. /* Check to see if more RSCNs came in while we
  1778. * were processing this one.
  1779. */
  1780. if ((phba->fc_rscn_id_cnt == 0) &&
  1781. (!(phba->fc_flag & FC_RSCN_DISCOVERY))) {
  1782. spin_lock_irq(phba->host->host_lock);
  1783. phba->fc_flag &= ~FC_RSCN_MODE;
  1784. spin_unlock_irq(phba->host->host_lock);
  1785. }
  1786. else
  1787. lpfc_els_handle_rscn(phba);
  1788. }
  1789. }
  1790. return;
  1791. }
  1792. /*
  1793. * Ignore completion for all IOCBs on tx and txcmpl queue for ELS
  1794. * ring the match the sppecified nodelist.
  1795. */
  1796. static void
  1797. lpfc_free_tx(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp)
  1798. {
  1799. struct lpfc_sli *psli;
  1800. IOCB_t *icmd;
  1801. struct lpfc_iocbq *iocb, *next_iocb;
  1802. struct lpfc_sli_ring *pring;
  1803. struct lpfc_dmabuf *mp;
  1804. psli = &phba->sli;
  1805. pring = &psli->ring[LPFC_ELS_RING];
  1806. /* Error matching iocb on txq or txcmplq
  1807. * First check the txq.
  1808. */
  1809. list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
  1810. if (iocb->context1 != ndlp) {
  1811. continue;
  1812. }
  1813. icmd = &iocb->iocb;
  1814. if ((icmd->ulpCommand == CMD_ELS_REQUEST64_CR) ||
  1815. (icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX)) {
  1816. list_del(&iocb->list);
  1817. pring->txq_cnt--;
  1818. lpfc_els_free_iocb(phba, iocb);
  1819. }
  1820. }
  1821. /* Next check the txcmplq */
  1822. list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
  1823. if (iocb->context1 != ndlp) {
  1824. continue;
  1825. }
  1826. icmd = &iocb->iocb;
  1827. if ((icmd->ulpCommand == CMD_ELS_REQUEST64_CR) ||
  1828. (icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX)) {
  1829. iocb->iocb_cmpl = NULL;
  1830. /* context2 = cmd, context2->next = rsp, context3 =
  1831. bpl */
  1832. if (iocb->context2) {
  1833. /* Free the response IOCB before handling the
  1834. command. */
  1835. mp = (struct lpfc_dmabuf *) (iocb->context2);
  1836. mp = list_get_first(&mp->list,
  1837. struct lpfc_dmabuf,
  1838. list);
  1839. if (mp) {
  1840. /* Delay before releasing rsp buffer to
  1841. * give UNREG mbox a chance to take
  1842. * effect.
  1843. */
  1844. list_add(&mp->list,
  1845. &phba->freebufList);
  1846. }
  1847. lpfc_mbuf_free(phba,
  1848. ((struct lpfc_dmabuf *)
  1849. iocb->context2)->virt,
  1850. ((struct lpfc_dmabuf *)
  1851. iocb->context2)->phys);
  1852. kfree(iocb->context2);
  1853. }
  1854. if (iocb->context3) {
  1855. lpfc_mbuf_free(phba,
  1856. ((struct lpfc_dmabuf *)
  1857. iocb->context3)->virt,
  1858. ((struct lpfc_dmabuf *)
  1859. iocb->context3)->phys);
  1860. kfree(iocb->context3);
  1861. }
  1862. }
  1863. }
  1864. return;
  1865. }
  1866. void
  1867. lpfc_disc_flush_list(struct lpfc_hba * phba)
  1868. {
  1869. struct lpfc_nodelist *ndlp, *next_ndlp;
  1870. if (phba->fc_plogi_cnt) {
  1871. list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_plogi_list,
  1872. nlp_listp) {
  1873. lpfc_free_tx(phba, ndlp);
  1874. lpfc_nlp_remove(phba, ndlp);
  1875. }
  1876. }
  1877. if (phba->fc_adisc_cnt) {
  1878. list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_adisc_list,
  1879. nlp_listp) {
  1880. lpfc_free_tx(phba, ndlp);
  1881. lpfc_nlp_remove(phba, ndlp);
  1882. }
  1883. }
  1884. return;
  1885. }
  1886. /*****************************************************************************/
  1887. /*
  1888. * NAME: lpfc_disc_timeout
  1889. *
  1890. * FUNCTION: Fibre Channel driver discovery timeout routine.
  1891. *
  1892. * EXECUTION ENVIRONMENT: interrupt only
  1893. *
  1894. * CALLED FROM:
  1895. * Timer function
  1896. *
  1897. * RETURNS:
  1898. * none
  1899. */
  1900. /*****************************************************************************/
  1901. void
  1902. lpfc_disc_timeout(unsigned long ptr)
  1903. {
  1904. struct lpfc_hba *phba = (struct lpfc_hba *)ptr;
  1905. unsigned long flags = 0;
  1906. if (unlikely(!phba))
  1907. return;
  1908. spin_lock_irqsave(phba->host->host_lock, flags);
  1909. if (!(phba->work_hba_events & WORKER_DISC_TMO)) {
  1910. phba->work_hba_events |= WORKER_DISC_TMO;
  1911. if (phba->work_wait)
  1912. wake_up(phba->work_wait);
  1913. }
  1914. spin_unlock_irqrestore(phba->host->host_lock, flags);
  1915. return;
  1916. }
  1917. static void
  1918. lpfc_disc_timeout_handler(struct lpfc_hba *phba)
  1919. {
  1920. struct lpfc_sli *psli;
  1921. struct lpfc_nodelist *ndlp;
  1922. LPFC_MBOXQ_t *clearlambox, *initlinkmbox;
  1923. int rc, clrlaerr = 0;
  1924. if (unlikely(!phba))
  1925. return;
  1926. if (!(phba->fc_flag & FC_DISC_TMO))
  1927. return;
  1928. psli = &phba->sli;
  1929. spin_lock_irq(phba->host->host_lock);
  1930. phba->fc_flag &= ~FC_DISC_TMO;
  1931. spin_unlock_irq(phba->host->host_lock);
  1932. switch (phba->hba_state) {
  1933. case LPFC_LOCAL_CFG_LINK:
  1934. /* hba_state is identically LPFC_LOCAL_CFG_LINK while waiting for FAN */
  1935. /* FAN timeout */
  1936. lpfc_printf_log(phba,
  1937. KERN_WARNING,
  1938. LOG_DISCOVERY,
  1939. "%d:0221 FAN timeout\n",
  1940. phba->brd_no);
  1941. /* Forget about FAN, Start discovery by sending a FLOGI
  1942. * hba_state is identically LPFC_FLOGI while waiting for FLOGI
  1943. * cmpl
  1944. */
  1945. phba->hba_state = LPFC_FLOGI;
  1946. lpfc_set_disctmo(phba);
  1947. lpfc_initial_flogi(phba);
  1948. break;
  1949. case LPFC_FLOGI:
  1950. /* hba_state is identically LPFC_FLOGI while waiting for FLOGI cmpl */
  1951. /* Initial FLOGI timeout */
  1952. lpfc_printf_log(phba,
  1953. KERN_ERR,
  1954. LOG_DISCOVERY,
  1955. "%d:0222 Initial FLOGI timeout\n",
  1956. phba->brd_no);
  1957. /* Assume no Fabric and go on with discovery.
  1958. * Check for outstanding ELS FLOGI to abort.
  1959. */
  1960. /* FLOGI failed, so just use loop map to make discovery list */
  1961. lpfc_disc_list_loopmap(phba);
  1962. /* Start discovery */
  1963. lpfc_disc_start(phba);
  1964. break;
  1965. case LPFC_FABRIC_CFG_LINK:
  1966. /* hba_state is identically LPFC_FABRIC_CFG_LINK while waiting for
  1967. NameServer login */
  1968. lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
  1969. "%d:0223 Timeout while waiting for NameServer "
  1970. "login\n", phba->brd_no);
  1971. /* Next look for NameServer ndlp */
  1972. ndlp = lpfc_findnode_did(phba, NLP_SEARCH_ALL, NameServer_DID);
  1973. if (ndlp)
  1974. lpfc_nlp_remove(phba, ndlp);
  1975. /* Start discovery */
  1976. lpfc_disc_start(phba);
  1977. break;
  1978. case LPFC_NS_QRY:
  1979. /* Check for wait for NameServer Rsp timeout */
  1980. lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
  1981. "%d:0224 NameServer Query timeout "
  1982. "Data: x%x x%x\n",
  1983. phba->brd_no,
  1984. phba->fc_ns_retry, LPFC_MAX_NS_RETRY);
  1985. ndlp = lpfc_findnode_did(phba, NLP_SEARCH_UNMAPPED,
  1986. NameServer_DID);
  1987. if (ndlp) {
  1988. if (phba->fc_ns_retry < LPFC_MAX_NS_RETRY) {
  1989. /* Try it one more time */
  1990. rc = lpfc_ns_cmd(phba, ndlp, SLI_CTNS_GID_FT);
  1991. if (rc == 0)
  1992. break;
  1993. }
  1994. phba->fc_ns_retry = 0;
  1995. }
  1996. /* Nothing to authenticate, so CLEAR_LA right now */
  1997. clearlambox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  1998. if (!clearlambox) {
  1999. clrlaerr = 1;
  2000. lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
  2001. "%d:0226 Device Discovery "
  2002. "completion error\n",
  2003. phba->brd_no);
  2004. phba->hba_state = LPFC_HBA_ERROR;
  2005. break;
  2006. }
  2007. phba->hba_state = LPFC_CLEAR_LA;
  2008. lpfc_clear_la(phba, clearlambox);
  2009. clearlambox->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
  2010. rc = lpfc_sli_issue_mbox(phba, clearlambox,
  2011. (MBX_NOWAIT | MBX_STOP_IOCB));
  2012. if (rc == MBX_NOT_FINISHED) {
  2013. mempool_free(clearlambox, phba->mbox_mem_pool);
  2014. clrlaerr = 1;
  2015. break;
  2016. }
  2017. /* Setup and issue mailbox INITIALIZE LINK command */
  2018. initlinkmbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  2019. if (!initlinkmbox) {
  2020. lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
  2021. "%d:0226 Device Discovery "
  2022. "completion error\n",
  2023. phba->brd_no);
  2024. phba->hba_state = LPFC_HBA_ERROR;
  2025. break;
  2026. }
  2027. lpfc_linkdown(phba);
  2028. lpfc_init_link(phba, initlinkmbox, phba->cfg_topology,
  2029. phba->cfg_link_speed);
  2030. initlinkmbox->mb.un.varInitLnk.lipsr_AL_PA = 0;
  2031. rc = lpfc_sli_issue_mbox(phba, initlinkmbox,
  2032. (MBX_NOWAIT | MBX_STOP_IOCB));
  2033. if (rc == MBX_NOT_FINISHED)
  2034. mempool_free(initlinkmbox, phba->mbox_mem_pool);
  2035. break;
  2036. case LPFC_DISC_AUTH:
  2037. /* Node Authentication timeout */
  2038. lpfc_printf_log(phba,
  2039. KERN_ERR,
  2040. LOG_DISCOVERY,
  2041. "%d:0227 Node Authentication timeout\n",
  2042. phba->brd_no);
  2043. lpfc_disc_flush_list(phba);
  2044. clearlambox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  2045. if (!clearlambox) {
  2046. clrlaerr = 1;
  2047. lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
  2048. "%d:0226 Device Discovery "
  2049. "completion error\n",
  2050. phba->brd_no);
  2051. phba->hba_state = LPFC_HBA_ERROR;
  2052. break;
  2053. }
  2054. phba->hba_state = LPFC_CLEAR_LA;
  2055. lpfc_clear_la(phba, clearlambox);
  2056. clearlambox->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
  2057. rc = lpfc_sli_issue_mbox(phba, clearlambox,
  2058. (MBX_NOWAIT | MBX_STOP_IOCB));
  2059. if (rc == MBX_NOT_FINISHED) {
  2060. mempool_free(clearlambox, phba->mbox_mem_pool);
  2061. clrlaerr = 1;
  2062. }
  2063. break;
  2064. case LPFC_CLEAR_LA:
  2065. /* CLEAR LA timeout */
  2066. lpfc_printf_log(phba,
  2067. KERN_ERR,
  2068. LOG_DISCOVERY,
  2069. "%d:0228 CLEAR LA timeout\n",
  2070. phba->brd_no);
  2071. clrlaerr = 1;
  2072. break;
  2073. case LPFC_HBA_READY:
  2074. if (phba->fc_flag & FC_RSCN_MODE) {
  2075. lpfc_printf_log(phba,
  2076. KERN_ERR,
  2077. LOG_DISCOVERY,
  2078. "%d:0231 RSCN timeout Data: x%x x%x\n",
  2079. phba->brd_no,
  2080. phba->fc_ns_retry, LPFC_MAX_NS_RETRY);
  2081. /* Cleanup any outstanding ELS commands */
  2082. lpfc_els_flush_cmd(phba);
  2083. lpfc_els_flush_rscn(phba);
  2084. lpfc_disc_flush_list(phba);
  2085. }
  2086. break;
  2087. }
  2088. if (clrlaerr) {
  2089. lpfc_disc_flush_list(phba);
  2090. psli->ring[(psli->ip_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
  2091. psli->ring[(psli->fcp_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
  2092. psli->ring[(psli->next_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
  2093. phba->hba_state = LPFC_HBA_READY;
  2094. }
  2095. return;
  2096. }
  2097. static void
  2098. lpfc_nodev_timeout(unsigned long ptr)
  2099. {
  2100. struct lpfc_hba *phba;
  2101. struct lpfc_nodelist *ndlp;
  2102. unsigned long iflag;
  2103. struct lpfc_work_evt *evtp;
  2104. ndlp = (struct lpfc_nodelist *)ptr;
  2105. phba = ndlp->nlp_phba;
  2106. evtp = &ndlp->nodev_timeout_evt;
  2107. spin_lock_irqsave(phba->host->host_lock, iflag);
  2108. if (!list_empty(&evtp->evt_listp)) {
  2109. spin_unlock_irqrestore(phba->host->host_lock, iflag);
  2110. return;
  2111. }
  2112. evtp->evt_arg1 = ndlp;
  2113. evtp->evt = LPFC_EVT_NODEV_TMO;
  2114. list_add_tail(&evtp->evt_listp, &phba->work_list);
  2115. if (phba->work_wait)
  2116. wake_up(phba->work_wait);
  2117. spin_unlock_irqrestore(phba->host->host_lock, iflag);
  2118. return;
  2119. }
  2120. /*
  2121. * This routine handles processing a NameServer REG_LOGIN mailbox
  2122. * command upon completion. It is setup in the LPFC_MBOXQ
  2123. * as the completion routine when the command is
  2124. * handed off to the SLI layer.
  2125. */
  2126. void
  2127. lpfc_mbx_cmpl_fdmi_reg_login(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
  2128. {
  2129. struct lpfc_sli *psli;
  2130. MAILBOX_t *mb;
  2131. struct lpfc_dmabuf *mp;
  2132. struct lpfc_nodelist *ndlp;
  2133. psli = &phba->sli;
  2134. mb = &pmb->mb;
  2135. ndlp = (struct lpfc_nodelist *) pmb->context2;
  2136. mp = (struct lpfc_dmabuf *) (pmb->context1);
  2137. pmb->context1 = NULL;
  2138. if (ndlp->nlp_rpi != 0)
  2139. lpfc_findnode_remove_rpi(phba, ndlp->nlp_rpi);
  2140. ndlp->nlp_rpi = mb->un.varWords[0];
  2141. lpfc_addnode_rpi(phba, ndlp, ndlp->nlp_rpi);
  2142. ndlp->nlp_type |= NLP_FABRIC;
  2143. ndlp->nlp_state = NLP_STE_UNMAPPED_NODE;
  2144. lpfc_nlp_list(phba, ndlp, NLP_UNMAPPED_LIST);
  2145. /* Start issuing Fabric-Device Management Interface (FDMI)
  2146. * command to 0xfffffa (FDMI well known port)
  2147. */
  2148. if (phba->cfg_fdmi_on == 1) {
  2149. lpfc_fdmi_cmd(phba, ndlp, SLI_MGMT_DHBA);
  2150. } else {
  2151. /*
  2152. * Delay issuing FDMI command if fdmi-on=2
  2153. * (supporting RPA/hostnmae)
  2154. */
  2155. mod_timer(&phba->fc_fdmitmo, jiffies + HZ * 60);
  2156. }
  2157. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  2158. kfree(mp);
  2159. mempool_free( pmb, phba->mbox_mem_pool);
  2160. return;
  2161. }
  2162. /*
  2163. * This routine looks up the ndlp hash
  2164. * table for the given RPI. If rpi found
  2165. * it return the node list pointer
  2166. * else return 0.
  2167. */
  2168. struct lpfc_nodelist *
  2169. lpfc_findnode_rpi(struct lpfc_hba * phba, uint16_t rpi)
  2170. {
  2171. struct lpfc_nodelist *ret;
  2172. ret = phba->fc_nlplookup[LPFC_RPI_HASH_FUNC(rpi)];
  2173. while ((ret != 0) && (ret->nlp_rpi != rpi)) {
  2174. ret = ret->nlp_rpi_hash_next;
  2175. }
  2176. return ret;
  2177. }
  2178. /*
  2179. * This routine looks up the ndlp hash table for the
  2180. * given RPI. If rpi found it return the node list
  2181. * pointer else return 0 after deleting the entry
  2182. * from hash table.
  2183. */
  2184. struct lpfc_nodelist *
  2185. lpfc_findnode_remove_rpi(struct lpfc_hba * phba, uint16_t rpi)
  2186. {
  2187. struct lpfc_nodelist *ret, *temp;;
  2188. ret = phba->fc_nlplookup[LPFC_RPI_HASH_FUNC(rpi)];
  2189. if (ret == 0)
  2190. return NULL;
  2191. if (ret->nlp_rpi == rpi) {
  2192. phba->fc_nlplookup[LPFC_RPI_HASH_FUNC(rpi)] =
  2193. ret->nlp_rpi_hash_next;
  2194. ret->nlp_rpi_hash_next = NULL;
  2195. return ret;
  2196. }
  2197. while ((ret->nlp_rpi_hash_next != 0) &&
  2198. (ret->nlp_rpi_hash_next->nlp_rpi != rpi)) {
  2199. ret = ret->nlp_rpi_hash_next;
  2200. }
  2201. if (ret->nlp_rpi_hash_next != 0) {
  2202. temp = ret->nlp_rpi_hash_next;
  2203. ret->nlp_rpi_hash_next = temp->nlp_rpi_hash_next;
  2204. temp->nlp_rpi_hash_next = NULL;
  2205. return temp;
  2206. } else {
  2207. return NULL;
  2208. }
  2209. }
  2210. /*
  2211. * This routine adds the node list entry to the
  2212. * ndlp hash table.
  2213. */
  2214. void
  2215. lpfc_addnode_rpi(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp,
  2216. uint16_t rpi)
  2217. {
  2218. uint32_t index;
  2219. index = LPFC_RPI_HASH_FUNC(rpi);
  2220. ndlp->nlp_rpi_hash_next = phba->fc_nlplookup[index];
  2221. phba->fc_nlplookup[index] = ndlp;
  2222. return;
  2223. }
  2224. void
  2225. lpfc_nlp_init(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp,
  2226. uint32_t did)
  2227. {
  2228. memset(ndlp, 0, sizeof (struct lpfc_nodelist));
  2229. INIT_LIST_HEAD(&ndlp->nodev_timeout_evt.evt_listp);
  2230. INIT_LIST_HEAD(&ndlp->els_retry_evt.evt_listp);
  2231. init_timer(&ndlp->nlp_tmofunc);
  2232. ndlp->nlp_tmofunc.function = lpfc_nodev_timeout;
  2233. ndlp->nlp_tmofunc.data = (unsigned long)ndlp;
  2234. init_timer(&ndlp->nlp_delayfunc);
  2235. ndlp->nlp_delayfunc.function = lpfc_els_retry_delay;
  2236. ndlp->nlp_delayfunc.data = (unsigned long)ndlp;
  2237. ndlp->nlp_DID = did;
  2238. ndlp->nlp_phba = phba;
  2239. ndlp->nlp_sid = NLP_NO_SID;
  2240. return;
  2241. }