lpfc_hbadisc.c 65 KB

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