lpfc_hbadisc.c 63 KB

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