lpfc_hbadisc.c 66 KB

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