lpfc_hbadisc.c 67 KB

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