lpfc_hbadisc.c 66 KB

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