lpfc_hbadisc.c 68 KB

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