lpfc_hbadisc.c 65 KB

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