lpfc_hbadisc.c 62 KB

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