lpfc_hbadisc.c 66 KB

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