lpfc_hbadisc.c 62 KB

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