lpfc_hbadisc.c 62 KB

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