lpfc_hbadisc.c 65 KB

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