lpfc_hbadisc.c 68 KB

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