lpfc_hbadisc.c 68 KB

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