blob: 2a2e2eb406ace598fb005806acbff446eeb00be2 [file] [log] [blame]
dea31012005-04-17 16:05:31 -05001/*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04003 * Fibre Channel Host Bus Adapters. *
Jamie Wellnitz41415862006-02-28 19:25:27 -05004 * Copyright (C) 2004-2006 Emulex. All rights reserved. *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04005 * EMULEX and SLI are trademarks of Emulex. *
dea31012005-04-17 16:05:31 -05006 * www.emulex.com *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04007 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
dea31012005-04-17 16:05:31 -05008 * *
9 * This program is free software; you can redistribute it and/or *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -040010 * 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. *
dea31012005-04-17 16:05:31 -050020 *******************************************************************/
21
dea31012005-04-17 16:05:31 -050022#include <linux/blkdev.h>
23#include <linux/pci.h>
24#include <linux/kthread.h>
25#include <linux/interrupt.h>
26
James.Smart@Emulex.Com91886522005-08-10 15:03:09 -040027#include <scsi/scsi.h>
dea31012005-04-17 16:05:31 -050028#include <scsi/scsi_device.h>
29#include <scsi/scsi_host.h>
30#include <scsi/scsi_transport_fc.h>
31
32#include "lpfc_hw.h"
33#include "lpfc_disc.h"
34#include "lpfc_sli.h"
35#include "lpfc_scsi.h"
36#include "lpfc.h"
37#include "lpfc_logmsg.h"
38#include "lpfc_crtn.h"
39
40/* AlpaArray for assignment of scsid for scan-down and bind_method */
41static uint8_t lpfcAlpaArray[] = {
42 0xEF, 0xE8, 0xE4, 0xE2, 0xE1, 0xE0, 0xDC, 0xDA, 0xD9, 0xD6,
43 0xD5, 0xD4, 0xD3, 0xD2, 0xD1, 0xCE, 0xCD, 0xCC, 0xCB, 0xCA,
44 0xC9, 0xC7, 0xC6, 0xC5, 0xC3, 0xBC, 0xBA, 0xB9, 0xB6, 0xB5,
45 0xB4, 0xB3, 0xB2, 0xB1, 0xAE, 0xAD, 0xAC, 0xAB, 0xAA, 0xA9,
46 0xA7, 0xA6, 0xA5, 0xA3, 0x9F, 0x9E, 0x9D, 0x9B, 0x98, 0x97,
47 0x90, 0x8F, 0x88, 0x84, 0x82, 0x81, 0x80, 0x7C, 0x7A, 0x79,
48 0x76, 0x75, 0x74, 0x73, 0x72, 0x71, 0x6E, 0x6D, 0x6C, 0x6B,
49 0x6A, 0x69, 0x67, 0x66, 0x65, 0x63, 0x5C, 0x5A, 0x59, 0x56,
50 0x55, 0x54, 0x53, 0x52, 0x51, 0x4E, 0x4D, 0x4C, 0x4B, 0x4A,
51 0x49, 0x47, 0x46, 0x45, 0x43, 0x3C, 0x3A, 0x39, 0x36, 0x35,
52 0x34, 0x33, 0x32, 0x31, 0x2E, 0x2D, 0x2C, 0x2B, 0x2A, 0x29,
53 0x27, 0x26, 0x25, 0x23, 0x1F, 0x1E, 0x1D, 0x1B, 0x18, 0x17,
54 0x10, 0x0F, 0x08, 0x04, 0x02, 0x01
55};
56
57static void lpfc_disc_timeout_handler(struct lpfc_hba *);
58
59static void
60lpfc_process_nodev_timeout(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
61{
James Smart488d1462006-03-07 15:02:37 -050062 uint8_t *name = (uint8_t *)&ndlp->nlp_portname;
James.Smart@Emulex.Com6e8215e2005-06-25 10:34:04 -040063 int warn_on = 0;
dea31012005-04-17 16:05:31 -050064
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
James Smart1a169682006-03-07 15:04:06 -050071 /*
72 * If a discovery event readded nodev_timer after timer
73 * firing and before processing the timer, cancel the
74 * nlp_tmofunc.
75 */
76 spin_unlock_irq(phba->host->host_lock);
77 del_timer_sync(&ndlp->nlp_tmofunc);
78 spin_lock_irq(phba->host->host_lock);
79
dea31012005-04-17 16:05:31 -050080 ndlp->nlp_flag &= ~NLP_NODEV_TMO;
81
82 if (ndlp->nlp_sid != NLP_NO_SID) {
James.Smart@Emulex.Com6e8215e2005-06-25 10:34:04 -040083 warn_on = 1;
dea31012005-04-17 16:05:31 -050084 /* flush the target */
85 lpfc_sli_abort_iocb(phba, &phba->sli.ring[phba->sli.fcp_ring],
86 ndlp->nlp_sid, 0, 0, LPFC_CTX_TGT);
87 }
88 spin_unlock_irq(phba->host->host_lock);
89
James.Smart@Emulex.Com6e8215e2005-06-25 10:34:04 -040090 if (warn_on) {
91 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
James Smart488d1462006-03-07 15:02:37 -050092 "%d:0203 Nodev timeout on "
93 "WWPN %x:%x:%x:%x:%x:%x:%x:%x "
94 "NPort x%x Data: x%x x%x x%x\n",
95 phba->brd_no,
96 *name, *(name+1), *(name+2), *(name+3),
97 *(name+4), *(name+5), *(name+6), *(name+7),
98 ndlp->nlp_DID, ndlp->nlp_flag,
James.Smart@Emulex.Com6e8215e2005-06-25 10:34:04 -040099 ndlp->nlp_state, ndlp->nlp_rpi);
100 } else {
101 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
James Smart488d1462006-03-07 15:02:37 -0500102 "%d:0204 Nodev timeout on "
103 "WWPN %x:%x:%x:%x:%x:%x:%x:%x "
104 "NPort x%x Data: x%x x%x x%x\n",
105 phba->brd_no,
106 *name, *(name+1), *(name+2), *(name+3),
107 *(name+4), *(name+5), *(name+6), *(name+7),
108 ndlp->nlp_DID, ndlp->nlp_flag,
James.Smart@Emulex.Com6e8215e2005-06-25 10:34:04 -0400109 ndlp->nlp_state, ndlp->nlp_rpi);
110 }
111
dea31012005-04-17 16:05:31 -0500112 lpfc_disc_state_machine(phba, ndlp, NULL, NLP_EVT_DEVICE_RM);
113 return;
114}
115
116static void
117lpfc_work_list_done(struct lpfc_hba * phba)
118{
119 struct lpfc_work_evt *evtp = NULL;
120 struct lpfc_nodelist *ndlp;
121 int free_evt;
122
123 spin_lock_irq(phba->host->host_lock);
124 while(!list_empty(&phba->work_list)) {
125 list_remove_head((&phba->work_list), evtp, typeof(*evtp),
126 evt_listp);
127 spin_unlock_irq(phba->host->host_lock);
128 free_evt = 1;
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500129 switch (evtp->evt) {
dea31012005-04-17 16:05:31 -0500130 case LPFC_EVT_NODEV_TMO:
131 ndlp = (struct lpfc_nodelist *)(evtp->evt_arg1);
132 lpfc_process_nodev_timeout(phba, ndlp);
133 free_evt = 0;
134 break;
135 case LPFC_EVT_ELS_RETRY:
136 ndlp = (struct lpfc_nodelist *)(evtp->evt_arg1);
137 lpfc_els_retry_delay_handler(ndlp);
138 free_evt = 0;
139 break;
140 case LPFC_EVT_ONLINE:
Jamie Wellnitz41415862006-02-28 19:25:27 -0500141 if (phba->hba_state < LPFC_LINK_DOWN)
142 *(int *)(evtp->evt_arg1) = lpfc_online(phba);
143 else
144 *(int *)(evtp->evt_arg1) = 0;
dea31012005-04-17 16:05:31 -0500145 complete((struct completion *)(evtp->evt_arg2));
146 break;
147 case LPFC_EVT_OFFLINE:
Jamie Wellnitz41415862006-02-28 19:25:27 -0500148 if (phba->hba_state >= LPFC_LINK_DOWN)
149 lpfc_offline(phba);
150 lpfc_sli_brdrestart(phba);
151 *(int *)(evtp->evt_arg1) =
152 lpfc_sli_brdready(phba,HS_FFRDY | HS_MBRDY);
153 complete((struct completion *)(evtp->evt_arg2));
154 break;
155 case LPFC_EVT_WARM_START:
156 if (phba->hba_state >= LPFC_LINK_DOWN)
157 lpfc_offline(phba);
James Smart92908312006-03-07 15:04:13 -0500158 lpfc_reset_barrier(phba);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500159 lpfc_sli_brdreset(phba);
160 lpfc_hba_down_post(phba);
161 *(int *)(evtp->evt_arg1) =
162 lpfc_sli_brdready(phba, HS_MBRDY);
163 complete((struct completion *)(evtp->evt_arg2));
164 break;
165 case LPFC_EVT_KILL:
166 if (phba->hba_state >= LPFC_LINK_DOWN)
167 lpfc_offline(phba);
James Smart92908312006-03-07 15:04:13 -0500168 *(int *)(evtp->evt_arg1)
169 = (phba->stopped) ? 0 : lpfc_sli_brdkill(phba);
dea31012005-04-17 16:05:31 -0500170 complete((struct completion *)(evtp->evt_arg2));
171 break;
172 }
173 if (free_evt)
174 kfree(evtp);
175 spin_lock_irq(phba->host->host_lock);
176 }
177 spin_unlock_irq(phba->host->host_lock);
178
179}
180
181static void
182lpfc_work_done(struct lpfc_hba * phba)
183{
184 struct lpfc_sli_ring *pring;
185 int i;
186 uint32_t ha_copy;
187 uint32_t control;
188 uint32_t work_hba_events;
189
190 spin_lock_irq(phba->host->host_lock);
191 ha_copy = phba->work_ha;
192 phba->work_ha = 0;
193 work_hba_events=phba->work_hba_events;
194 spin_unlock_irq(phba->host->host_lock);
195
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500196 if (ha_copy & HA_ERATT)
dea31012005-04-17 16:05:31 -0500197 lpfc_handle_eratt(phba);
198
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500199 if (ha_copy & HA_MBATT)
dea31012005-04-17 16:05:31 -0500200 lpfc_sli_handle_mb_event(phba);
201
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500202 if (ha_copy & HA_LATT)
dea31012005-04-17 16:05:31 -0500203 lpfc_handle_latt(phba);
204
205 if (work_hba_events & WORKER_DISC_TMO)
206 lpfc_disc_timeout_handler(phba);
207
208 if (work_hba_events & WORKER_ELS_TMO)
209 lpfc_els_timeout_handler(phba);
210
211 if (work_hba_events & WORKER_MBOX_TMO)
212 lpfc_mbox_timeout_handler(phba);
213
214 if (work_hba_events & WORKER_FDMI_TMO)
215 lpfc_fdmi_tmo_handler(phba);
216
217 spin_lock_irq(phba->host->host_lock);
218 phba->work_hba_events &= ~work_hba_events;
219 spin_unlock_irq(phba->host->host_lock);
220
221 for (i = 0; i < phba->sli.num_rings; i++, ha_copy >>= 4) {
222 pring = &phba->sli.ring[i];
223 if ((ha_copy & HA_RXATT)
224 || (pring->flag & LPFC_DEFERRED_RING_EVENT)) {
225 if (pring->flag & LPFC_STOP_IOCB_MASK) {
226 pring->flag |= LPFC_DEFERRED_RING_EVENT;
227 } else {
228 lpfc_sli_handle_slow_ring_event(phba, pring,
229 (ha_copy &
230 HA_RXMASK));
231 pring->flag &= ~LPFC_DEFERRED_RING_EVENT;
232 }
233 /*
234 * Turn on Ring interrupts
235 */
236 spin_lock_irq(phba->host->host_lock);
237 control = readl(phba->HCregaddr);
238 control |= (HC_R0INT_ENA << i);
239 writel(control, phba->HCregaddr);
240 readl(phba->HCregaddr); /* flush */
241 spin_unlock_irq(phba->host->host_lock);
242 }
243 }
244
245 lpfc_work_list_done (phba);
246
247}
248
249static int
250check_work_wait_done(struct lpfc_hba *phba) {
251
252 spin_lock_irq(phba->host->host_lock);
253 if (phba->work_ha ||
254 phba->work_hba_events ||
255 (!list_empty(&phba->work_list)) ||
256 kthread_should_stop()) {
257 spin_unlock_irq(phba->host->host_lock);
258 return 1;
259 } else {
260 spin_unlock_irq(phba->host->host_lock);
261 return 0;
262 }
263}
264
265int
266lpfc_do_work(void *p)
267{
268 struct lpfc_hba *phba = p;
269 int rc;
270 DECLARE_WAIT_QUEUE_HEAD(work_waitq);
271
272 set_user_nice(current, -20);
273 phba->work_wait = &work_waitq;
274
275 while (1) {
276
277 rc = wait_event_interruptible(work_waitq,
278 check_work_wait_done(phba));
279 BUG_ON(rc);
280
281 if (kthread_should_stop())
282 break;
283
284 lpfc_work_done(phba);
285
286 }
287 phba->work_wait = NULL;
288 return 0;
289}
290
291/*
292 * This is only called to handle FC worker events. Since this a rare
293 * occurance, we allocate a struct lpfc_work_evt structure here instead of
294 * embedding it in the IOCB.
295 */
296int
297lpfc_workq_post_event(struct lpfc_hba * phba, void *arg1, void *arg2,
298 uint32_t evt)
299{
300 struct lpfc_work_evt *evtp;
301
302 /*
303 * All Mailbox completions and LPFC_ELS_RING rcv ring IOCB events will
304 * be queued to worker thread for processing
305 */
306 evtp = kmalloc(sizeof(struct lpfc_work_evt), GFP_KERNEL);
307 if (!evtp)
308 return 0;
309
310 evtp->evt_arg1 = arg1;
311 evtp->evt_arg2 = arg2;
312 evtp->evt = evt;
313
314 list_add_tail(&evtp->evt_listp, &phba->work_list);
315 spin_lock_irq(phba->host->host_lock);
316 if (phba->work_wait)
317 wake_up(phba->work_wait);
318 spin_unlock_irq(phba->host->host_lock);
319
320 return 1;
321}
322
323int
324lpfc_linkdown(struct lpfc_hba * phba)
325{
326 struct lpfc_sli *psli;
327 struct lpfc_nodelist *ndlp, *next_ndlp;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500328 struct list_head *listp, *node_list[7];
dea31012005-04-17 16:05:31 -0500329 LPFC_MBOXQ_t *mb;
330 int rc, i;
331
332 psli = &phba->sli;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500333 /* sysfs or selective reset may call this routine to clean up */
Jamie Wellnitz5024ab12006-02-28 19:25:28 -0500334 if (phba->hba_state >= LPFC_LINK_DOWN) {
335 if (phba->hba_state == LPFC_LINK_DOWN)
336 return 0;
337
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500338 spin_lock_irq(phba->host->host_lock);
339 phba->hba_state = LPFC_LINK_DOWN;
340 spin_unlock_irq(phba->host->host_lock);
341 }
dea31012005-04-17 16:05:31 -0500342
343 /* Clean up any firmware default rpi's */
344 if ((mb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL))) {
345 lpfc_unreg_did(phba, 0xffffffff, mb);
346 mb->mbox_cmpl=lpfc_sli_def_mbox_cmpl;
347 if (lpfc_sli_issue_mbox(phba, mb, (MBX_NOWAIT | MBX_STOP_IOCB))
348 == MBX_NOT_FINISHED) {
349 mempool_free( mb, phba->mbox_mem_pool);
350 }
351 }
352
353 /* Cleanup any outstanding RSCN activity */
354 lpfc_els_flush_rscn(phba);
355
356 /* Cleanup any outstanding ELS commands */
357 lpfc_els_flush_cmd(phba);
358
359 /* Issue a LINK DOWN event to all nodes */
360 node_list[0] = &phba->fc_npr_list; /* MUST do this list first */
361 node_list[1] = &phba->fc_nlpmap_list;
362 node_list[2] = &phba->fc_nlpunmap_list;
363 node_list[3] = &phba->fc_prli_list;
364 node_list[4] = &phba->fc_reglogin_list;
365 node_list[5] = &phba->fc_adisc_list;
366 node_list[6] = &phba->fc_plogi_list;
367 for (i = 0; i < 7; i++) {
368 listp = node_list[i];
369 if (list_empty(listp))
370 continue;
371
372 list_for_each_entry_safe(ndlp, next_ndlp, listp, nlp_listp) {
dea31012005-04-17 16:05:31 -0500373
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500374 rc = lpfc_disc_state_machine(phba, ndlp, NULL,
375 NLP_EVT_DEVICE_RECOVERY);
dea31012005-04-17 16:05:31 -0500376
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500377 /* Check config parameter use-adisc or FCP-2 */
378 if ((rc != NLP_STE_FREED_NODE) &&
379 (phba->cfg_use_adisc == 0) &&
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500380 !(ndlp->nlp_fcp_info & NLP_FCP_2_DEVICE)) {
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500381 /* We know we will have to relogin, so
382 * unreglogin the rpi right now to fail
383 * any outstanding I/Os quickly.
384 */
385 lpfc_unreg_rpi(phba, ndlp);
dea31012005-04-17 16:05:31 -0500386 }
387 }
388 }
389
390 /* free any ndlp's on unused list */
391 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_unused_list,
392 nlp_listp) {
393 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
394 }
395
396 /* Setup myDID for link up if we are in pt2pt mode */
397 if (phba->fc_flag & FC_PT2PT) {
398 phba->fc_myDID = 0;
399 if ((mb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL))) {
400 lpfc_config_link(phba, mb);
401 mb->mbox_cmpl=lpfc_sli_def_mbox_cmpl;
402 if (lpfc_sli_issue_mbox
403 (phba, mb, (MBX_NOWAIT | MBX_STOP_IOCB))
404 == MBX_NOT_FINISHED) {
405 mempool_free( mb, phba->mbox_mem_pool);
406 }
407 }
408 spin_lock_irq(phba->host->host_lock);
409 phba->fc_flag &= ~(FC_PT2PT | FC_PT2PT_PLOGI);
410 spin_unlock_irq(phba->host->host_lock);
411 }
412 spin_lock_irq(phba->host->host_lock);
413 phba->fc_flag &= ~FC_LBIT;
414 spin_unlock_irq(phba->host->host_lock);
415
416 /* Turn off discovery timer if its running */
417 lpfc_can_disctmo(phba);
418
419 /* Must process IOCBs on all rings to handle ABORTed I/Os */
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500420 return 0;
dea31012005-04-17 16:05:31 -0500421}
422
423static int
424lpfc_linkup(struct lpfc_hba * phba)
425{
426 struct lpfc_nodelist *ndlp, *next_ndlp;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500427 struct list_head *listp, *node_list[7];
428 int i;
dea31012005-04-17 16:05:31 -0500429
430 spin_lock_irq(phba->host->host_lock);
431 phba->hba_state = LPFC_LINK_UP;
432 phba->fc_flag &= ~(FC_PT2PT | FC_PT2PT_PLOGI | FC_ABORT_DISCOVERY |
433 FC_RSCN_MODE | FC_NLP_MORE | FC_RSCN_DISCOVERY);
434 phba->fc_flag |= FC_NDISC_ACTIVE;
435 phba->fc_ns_retry = 0;
436 spin_unlock_irq(phba->host->host_lock);
437
438
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500439 node_list[0] = &phba->fc_plogi_list;
440 node_list[1] = &phba->fc_adisc_list;
441 node_list[2] = &phba->fc_reglogin_list;
442 node_list[3] = &phba->fc_prli_list;
443 node_list[4] = &phba->fc_nlpunmap_list;
444 node_list[5] = &phba->fc_nlpmap_list;
445 node_list[6] = &phba->fc_npr_list;
446 for (i = 0; i < 7; i++) {
447 listp = node_list[i];
448 if (list_empty(listp))
449 continue;
450
451 list_for_each_entry_safe(ndlp, next_ndlp, listp, nlp_listp) {
452 if (phba->fc_flag & FC_LBIT) {
453 if (ndlp->nlp_type & NLP_FABRIC) {
454 /* On Linkup its safe to clean up the
455 * ndlp from Fabric connections.
456 */
457 lpfc_nlp_list(phba, ndlp,
458 NLP_UNUSED_LIST);
459 } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
460 /* Fail outstanding IO now since device
461 * is marked for PLOGI.
462 */
463 lpfc_unreg_rpi(phba, ndlp);
464 }
465 }
dea31012005-04-17 16:05:31 -0500466 }
467 }
468
469 /* free any ndlp's on unused list */
470 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_unused_list,
471 nlp_listp) {
472 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
473 }
474
475 return 0;
476}
477
478/*
479 * This routine handles processing a CLEAR_LA mailbox
480 * command upon completion. It is setup in the LPFC_MBOXQ
481 * as the completion routine when the command is
482 * handed off to the SLI layer.
483 */
484void
485lpfc_mbx_cmpl_clear_la(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
486{
487 struct lpfc_sli *psli;
488 MAILBOX_t *mb;
489 uint32_t control;
490
491 psli = &phba->sli;
492 mb = &pmb->mb;
493 /* Since we don't do discovery right now, turn these off here */
494 psli->ring[psli->ip_ring].flag &= ~LPFC_STOP_IOCB_EVENT;
495 psli->ring[psli->fcp_ring].flag &= ~LPFC_STOP_IOCB_EVENT;
496 psli->ring[psli->next_ring].flag &= ~LPFC_STOP_IOCB_EVENT;
497
498 /* Check for error */
499 if ((mb->mbxStatus) && (mb->mbxStatus != 0x1601)) {
500 /* CLEAR_LA mbox error <mbxStatus> state <hba_state> */
501 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
502 "%d:0320 CLEAR_LA mbxStatus error x%x hba "
503 "state x%x\n",
504 phba->brd_no, mb->mbxStatus, phba->hba_state);
505
506 phba->hba_state = LPFC_HBA_ERROR;
507 goto out;
508 }
509
510 if (phba->fc_flag & FC_ABORT_DISCOVERY)
511 goto out;
512
513 phba->num_disc_nodes = 0;
514 /* go thru NPR list and issue ELS PLOGIs */
515 if (phba->fc_npr_cnt) {
516 lpfc_els_disc_plogi(phba);
517 }
518
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500519 if (!phba->num_disc_nodes) {
dea31012005-04-17 16:05:31 -0500520 spin_lock_irq(phba->host->host_lock);
521 phba->fc_flag &= ~FC_NDISC_ACTIVE;
522 spin_unlock_irq(phba->host->host_lock);
523 }
524
525 phba->hba_state = LPFC_HBA_READY;
526
527out:
528 /* Device Discovery completes */
529 lpfc_printf_log(phba,
530 KERN_INFO,
531 LOG_DISCOVERY,
532 "%d:0225 Device Discovery completes\n",
533 phba->brd_no);
534
535 mempool_free( pmb, phba->mbox_mem_pool);
536
537 spin_lock_irq(phba->host->host_lock);
538 phba->fc_flag &= ~FC_ABORT_DISCOVERY;
539 if (phba->fc_flag & FC_ESTABLISH_LINK) {
540 phba->fc_flag &= ~FC_ESTABLISH_LINK;
541 }
542 spin_unlock_irq(phba->host->host_lock);
543
544 del_timer_sync(&phba->fc_estabtmo);
545
546 lpfc_can_disctmo(phba);
547
548 /* turn on Link Attention interrupts */
549 spin_lock_irq(phba->host->host_lock);
550 psli->sli_flag |= LPFC_PROCESS_LA;
551 control = readl(phba->HCregaddr);
552 control |= HC_LAINT_ENA;
553 writel(control, phba->HCregaddr);
554 readl(phba->HCregaddr); /* flush */
555 spin_unlock_irq(phba->host->host_lock);
556
557 return;
558}
559
560static void
Jamie Wellnitz25594c62006-02-28 19:25:34 -0500561lpfc_mbx_cmpl_local_config_link(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea31012005-04-17 16:05:31 -0500562{
Jamie Wellnitz25594c62006-02-28 19:25:34 -0500563 struct lpfc_sli *psli = &phba->sli;
564 int rc;
dea31012005-04-17 16:05:31 -0500565
Jamie Wellnitz25594c62006-02-28 19:25:34 -0500566 if (pmb->mb.mbxStatus)
dea31012005-04-17 16:05:31 -0500567 goto out;
dea31012005-04-17 16:05:31 -0500568
Jamie Wellnitz25594c62006-02-28 19:25:34 -0500569 mempool_free(pmb, phba->mbox_mem_pool);
570
571 if (phba->fc_topology == TOPOLOGY_LOOP &&
572 phba->fc_flag & FC_PUBLIC_LOOP &&
573 !(phba->fc_flag & FC_LBIT)) {
574 /* Need to wait for FAN - use discovery timer
575 * for timeout. hba_state is identically
576 * LPFC_LOCAL_CFG_LINK while waiting for FAN
577 */
578 lpfc_set_disctmo(phba);
579 return;
dea31012005-04-17 16:05:31 -0500580 }
581
Jamie Wellnitz25594c62006-02-28 19:25:34 -0500582 /* Start discovery by sending a FLOGI. hba_state is identically
583 * LPFC_FLOGI while waiting for FLOGI cmpl
584 */
585 phba->hba_state = LPFC_FLOGI;
586 lpfc_set_disctmo(phba);
587 lpfc_initial_flogi(phba);
588 return;
dea31012005-04-17 16:05:31 -0500589
590out:
Jamie Wellnitz25594c62006-02-28 19:25:34 -0500591 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
592 "%d:0306 CONFIG_LINK mbxStatus error x%x "
593 "HBA state x%x\n",
594 phba->brd_no, pmb->mb.mbxStatus, phba->hba_state);
595
596 lpfc_linkdown(phba);
597
598 phba->hba_state = LPFC_HBA_ERROR;
599
600 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
dea31012005-04-17 16:05:31 -0500601 "%d:0200 CONFIG_LINK bad hba state x%x\n",
602 phba->brd_no, phba->hba_state);
603
Jamie Wellnitz25594c62006-02-28 19:25:34 -0500604 lpfc_clear_la(phba, pmb);
605 pmb->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
606 rc = lpfc_sli_issue_mbox(phba, pmb, (MBX_NOWAIT | MBX_STOP_IOCB));
607 if (rc == MBX_NOT_FINISHED) {
608 mempool_free(pmb, phba->mbox_mem_pool);
609 lpfc_disc_flush_list(phba);
610 psli->ring[(psli->ip_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
611 psli->ring[(psli->fcp_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
612 psli->ring[(psli->next_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
613 phba->hba_state = LPFC_HBA_READY;
dea31012005-04-17 16:05:31 -0500614 }
615 return;
616}
617
618static void
619lpfc_mbx_cmpl_read_sparam(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
620{
621 struct lpfc_sli *psli = &phba->sli;
622 MAILBOX_t *mb = &pmb->mb;
623 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) pmb->context1;
624
625
626 /* Check for error */
627 if (mb->mbxStatus) {
628 /* READ_SPARAM mbox error <mbxStatus> state <hba_state> */
629 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
630 "%d:0319 READ_SPARAM mbxStatus error x%x "
631 "hba state x%x>\n",
632 phba->brd_no, mb->mbxStatus, phba->hba_state);
633
634 lpfc_linkdown(phba);
635 phba->hba_state = LPFC_HBA_ERROR;
636 goto out;
637 }
638
639 memcpy((uint8_t *) & phba->fc_sparam, (uint8_t *) mp->virt,
640 sizeof (struct serv_parm));
641 memcpy((uint8_t *) & phba->fc_nodename,
642 (uint8_t *) & phba->fc_sparam.nodeName,
643 sizeof (struct lpfc_name));
644 memcpy((uint8_t *) & phba->fc_portname,
645 (uint8_t *) & phba->fc_sparam.portName,
646 sizeof (struct lpfc_name));
647 lpfc_mbuf_free(phba, mp->virt, mp->phys);
648 kfree(mp);
649 mempool_free( pmb, phba->mbox_mem_pool);
650 return;
651
652out:
653 pmb->context1 = NULL;
654 lpfc_mbuf_free(phba, mp->virt, mp->phys);
655 kfree(mp);
656 if (phba->hba_state != LPFC_CLEAR_LA) {
657 lpfc_clear_la(phba, pmb);
658 pmb->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
659 if (lpfc_sli_issue_mbox(phba, pmb, (MBX_NOWAIT | MBX_STOP_IOCB))
660 == MBX_NOT_FINISHED) {
661 mempool_free( pmb, phba->mbox_mem_pool);
662 lpfc_disc_flush_list(phba);
663 psli->ring[(psli->ip_ring)].flag &=
664 ~LPFC_STOP_IOCB_EVENT;
665 psli->ring[(psli->fcp_ring)].flag &=
666 ~LPFC_STOP_IOCB_EVENT;
667 psli->ring[(psli->next_ring)].flag &=
668 ~LPFC_STOP_IOCB_EVENT;
669 phba->hba_state = LPFC_HBA_READY;
670 }
671 } else {
672 mempool_free( pmb, phba->mbox_mem_pool);
673 }
674 return;
675}
676
677static void
678lpfc_mbx_process_link_up(struct lpfc_hba *phba, READ_LA_VAR *la)
679{
680 int i;
681 LPFC_MBOXQ_t *sparam_mbox, *cfglink_mbox;
682 sparam_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
683 cfglink_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
684
685 spin_lock_irq(phba->host->host_lock);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500686 switch (la->UlnkSpeed) {
dea31012005-04-17 16:05:31 -0500687 case LA_1GHZ_LINK:
688 phba->fc_linkspeed = LA_1GHZ_LINK;
689 break;
690 case LA_2GHZ_LINK:
691 phba->fc_linkspeed = LA_2GHZ_LINK;
692 break;
693 case LA_4GHZ_LINK:
694 phba->fc_linkspeed = LA_4GHZ_LINK;
695 break;
696 default:
697 phba->fc_linkspeed = LA_UNKNW_LINK;
698 break;
699 }
700
701 phba->fc_topology = la->topology;
702
703 if (phba->fc_topology == TOPOLOGY_LOOP) {
704 /* Get Loop Map information */
705
706 if (la->il)
707 phba->fc_flag |= FC_LBIT;
708
709 phba->fc_myDID = la->granted_AL_PA;
710 i = la->un.lilpBde64.tus.f.bdeSize;
711
712 if (i == 0) {
713 phba->alpa_map[0] = 0;
714 } else {
715 if (phba->cfg_log_verbose & LOG_LINK_EVENT) {
716 int numalpa, j, k;
717 union {
718 uint8_t pamap[16];
719 struct {
720 uint32_t wd1;
721 uint32_t wd2;
722 uint32_t wd3;
723 uint32_t wd4;
724 } pa;
725 } un;
726 numalpa = phba->alpa_map[0];
727 j = 0;
728 while (j < numalpa) {
729 memset(un.pamap, 0, 16);
730 for (k = 1; j < numalpa; k++) {
731 un.pamap[k - 1] =
732 phba->alpa_map[j + 1];
733 j++;
734 if (k == 16)
735 break;
736 }
737 /* Link Up Event ALPA map */
738 lpfc_printf_log(phba,
739 KERN_WARNING,
740 LOG_LINK_EVENT,
741 "%d:1304 Link Up Event "
742 "ALPA map Data: x%x "
743 "x%x x%x x%x\n",
744 phba->brd_no,
745 un.pa.wd1, un.pa.wd2,
746 un.pa.wd3, un.pa.wd4);
747 }
748 }
749 }
750 } else {
751 phba->fc_myDID = phba->fc_pref_DID;
752 phba->fc_flag |= FC_LBIT;
753 }
754 spin_unlock_irq(phba->host->host_lock);
755
756 lpfc_linkup(phba);
757 if (sparam_mbox) {
758 lpfc_read_sparam(phba, sparam_mbox);
759 sparam_mbox->mbox_cmpl = lpfc_mbx_cmpl_read_sparam;
760 lpfc_sli_issue_mbox(phba, sparam_mbox,
761 (MBX_NOWAIT | MBX_STOP_IOCB));
762 }
763
764 if (cfglink_mbox) {
765 phba->hba_state = LPFC_LOCAL_CFG_LINK;
766 lpfc_config_link(phba, cfglink_mbox);
Jamie Wellnitz25594c62006-02-28 19:25:34 -0500767 cfglink_mbox->mbox_cmpl = lpfc_mbx_cmpl_local_config_link;
dea31012005-04-17 16:05:31 -0500768 lpfc_sli_issue_mbox(phba, cfglink_mbox,
769 (MBX_NOWAIT | MBX_STOP_IOCB));
770 }
771}
772
773static void
774lpfc_mbx_issue_link_down(struct lpfc_hba *phba) {
775 uint32_t control;
776 struct lpfc_sli *psli = &phba->sli;
777
778 lpfc_linkdown(phba);
779
780 /* turn on Link Attention interrupts - no CLEAR_LA needed */
781 spin_lock_irq(phba->host->host_lock);
782 psli->sli_flag |= LPFC_PROCESS_LA;
783 control = readl(phba->HCregaddr);
784 control |= HC_LAINT_ENA;
785 writel(control, phba->HCregaddr);
786 readl(phba->HCregaddr); /* flush */
787 spin_unlock_irq(phba->host->host_lock);
788}
789
790/*
791 * This routine handles processing a READ_LA mailbox
792 * command upon completion. It is setup in the LPFC_MBOXQ
793 * as the completion routine when the command is
794 * handed off to the SLI layer.
795 */
796void
797lpfc_mbx_cmpl_read_la(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
798{
799 READ_LA_VAR *la;
800 MAILBOX_t *mb = &pmb->mb;
801 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
802
803 /* Check for error */
804 if (mb->mbxStatus) {
805 lpfc_printf_log(phba,
806 KERN_INFO,
807 LOG_LINK_EVENT,
808 "%d:1307 READ_LA mbox error x%x state x%x\n",
809 phba->brd_no,
810 mb->mbxStatus, phba->hba_state);
811 lpfc_mbx_issue_link_down(phba);
812 phba->hba_state = LPFC_HBA_ERROR;
813 goto lpfc_mbx_cmpl_read_la_free_mbuf;
814 }
815
816 la = (READ_LA_VAR *) & pmb->mb.un.varReadLA;
817
818 memcpy(&phba->alpa_map[0], mp->virt, 128);
819
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500820 spin_lock_irq(phba->host->host_lock);
821 if (la->pb)
822 phba->fc_flag |= FC_BYPASSED_MODE;
823 else
824 phba->fc_flag &= ~FC_BYPASSED_MODE;
825 spin_unlock_irq(phba->host->host_lock);
826
dea31012005-04-17 16:05:31 -0500827 if (((phba->fc_eventTag + 1) < la->eventTag) ||
828 (phba->fc_eventTag == la->eventTag)) {
829 phba->fc_stat.LinkMultiEvent++;
830 if (la->attType == AT_LINK_UP) {
831 if (phba->fc_eventTag != 0)
832 lpfc_linkdown(phba);
833 }
834 }
835
836 phba->fc_eventTag = la->eventTag;
837
838 if (la->attType == AT_LINK_UP) {
839 phba->fc_stat.LinkUp++;
840 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
841 "%d:1303 Link Up Event x%x received "
842 "Data: x%x x%x x%x x%x\n",
843 phba->brd_no, la->eventTag, phba->fc_eventTag,
844 la->granted_AL_PA, la->UlnkSpeed,
845 phba->alpa_map[0]);
846 lpfc_mbx_process_link_up(phba, la);
847 } else {
848 phba->fc_stat.LinkDown++;
849 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
850 "%d:1305 Link Down Event x%x received "
851 "Data: x%x x%x x%x\n",
852 phba->brd_no, la->eventTag, phba->fc_eventTag,
853 phba->hba_state, phba->fc_flag);
854 lpfc_mbx_issue_link_down(phba);
855 }
856
857lpfc_mbx_cmpl_read_la_free_mbuf:
858 lpfc_mbuf_free(phba, mp->virt, mp->phys);
859 kfree(mp);
860 mempool_free(pmb, phba->mbox_mem_pool);
861 return;
862}
863
864/*
865 * This routine handles processing a REG_LOGIN mailbox
866 * command upon completion. It is setup in the LPFC_MBOXQ
867 * as the completion routine when the command is
868 * handed off to the SLI layer.
869 */
870void
871lpfc_mbx_cmpl_reg_login(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
872{
873 struct lpfc_sli *psli;
874 MAILBOX_t *mb;
875 struct lpfc_dmabuf *mp;
876 struct lpfc_nodelist *ndlp;
877
878 psli = &phba->sli;
879 mb = &pmb->mb;
880
881 ndlp = (struct lpfc_nodelist *) pmb->context2;
882 mp = (struct lpfc_dmabuf *) (pmb->context1);
883
884 pmb->context1 = NULL;
885
886 /* Good status, call state machine */
887 lpfc_disc_state_machine(phba, ndlp, pmb, NLP_EVT_CMPL_REG_LOGIN);
888 lpfc_mbuf_free(phba, mp->virt, mp->phys);
889 kfree(mp);
890 mempool_free( pmb, phba->mbox_mem_pool);
891
892 return;
893}
894
895/*
896 * This routine handles processing a Fabric REG_LOGIN mailbox
897 * command upon completion. It is setup in the LPFC_MBOXQ
898 * as the completion routine when the command is
899 * handed off to the SLI layer.
900 */
901void
902lpfc_mbx_cmpl_fabric_reg_login(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
903{
904 struct lpfc_sli *psli;
905 MAILBOX_t *mb;
906 struct lpfc_dmabuf *mp;
907 struct lpfc_nodelist *ndlp;
908 struct lpfc_nodelist *ndlp_fdmi;
909
910
911 psli = &phba->sli;
912 mb = &pmb->mb;
913
914 ndlp = (struct lpfc_nodelist *) pmb->context2;
915 mp = (struct lpfc_dmabuf *) (pmb->context1);
916
917 if (mb->mbxStatus) {
918 lpfc_mbuf_free(phba, mp->virt, mp->phys);
919 kfree(mp);
920 mempool_free( pmb, phba->mbox_mem_pool);
921 mempool_free( ndlp, phba->nlp_mem_pool);
922
923 /* FLOGI failed, so just use loop map to make discovery list */
924 lpfc_disc_list_loopmap(phba);
925
926 /* Start discovery */
927 lpfc_disc_start(phba);
928 return;
929 }
930
931 pmb->context1 = NULL;
932
dea31012005-04-17 16:05:31 -0500933 ndlp->nlp_rpi = mb->un.varWords[0];
dea31012005-04-17 16:05:31 -0500934 ndlp->nlp_type |= NLP_FABRIC;
935 ndlp->nlp_state = NLP_STE_UNMAPPED_NODE;
936 lpfc_nlp_list(phba, ndlp, NLP_UNMAPPED_LIST);
937
938 if (phba->hba_state == LPFC_FABRIC_CFG_LINK) {
939 /* This NPort has been assigned an NPort_ID by the fabric as a
940 * result of the completed fabric login. Issue a State Change
941 * Registration (SCR) ELS request to the fabric controller
942 * (SCR_DID) so that this NPort gets RSCN events from the
943 * fabric.
944 */
945 lpfc_issue_els_scr(phba, SCR_DID, 0);
946
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500947 ndlp = lpfc_findnode_did(phba, NLP_SEARCH_ALL, NameServer_DID);
948 if (!ndlp) {
949 /* Allocate a new node instance. If the pool is empty,
950 * start the discovery process and skip the Nameserver
951 * login process. This is attempted again later on.
952 * Otherwise, issue a Port Login (PLOGI) to NameServer.
953 */
954 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_ATOMIC);
955 if (!ndlp) {
956 lpfc_disc_start(phba);
957 lpfc_mbuf_free(phba, mp->virt, mp->phys);
958 kfree(mp);
959 mempool_free( pmb, phba->mbox_mem_pool);
960 return;
961 } else {
962 lpfc_nlp_init(phba, ndlp, NameServer_DID);
963 ndlp->nlp_type |= NLP_FABRIC;
964 }
965 }
966 ndlp->nlp_state = NLP_STE_PLOGI_ISSUE;
967 lpfc_nlp_list(phba, ndlp, NLP_PLOGI_LIST);
James Smart488d1462006-03-07 15:02:37 -0500968 lpfc_issue_els_plogi(phba, NameServer_DID, 0);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500969 if (phba->cfg_fdmi_on) {
970 ndlp_fdmi = mempool_alloc(phba->nlp_mem_pool,
971 GFP_KERNEL);
972 if (ndlp_fdmi) {
973 lpfc_nlp_init(phba, ndlp_fdmi, FDMI_DID);
974 ndlp_fdmi->nlp_type |= NLP_FABRIC;
975 ndlp_fdmi->nlp_state = NLP_STE_PLOGI_ISSUE;
James Smart488d1462006-03-07 15:02:37 -0500976 lpfc_issue_els_plogi(phba, FDMI_DID, 0);
dea31012005-04-17 16:05:31 -0500977 }
978 }
979 }
980
981 lpfc_mbuf_free(phba, mp->virt, mp->phys);
982 kfree(mp);
983 mempool_free( pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500984 return;
985}
986
987/*
988 * This routine handles processing a NameServer REG_LOGIN mailbox
989 * command upon completion. It is setup in the LPFC_MBOXQ
990 * as the completion routine when the command is
991 * handed off to the SLI layer.
992 */
993void
994lpfc_mbx_cmpl_ns_reg_login(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
995{
996 struct lpfc_sli *psli;
997 MAILBOX_t *mb;
998 struct lpfc_dmabuf *mp;
999 struct lpfc_nodelist *ndlp;
1000
1001 psli = &phba->sli;
1002 mb = &pmb->mb;
1003
1004 ndlp = (struct lpfc_nodelist *) pmb->context2;
1005 mp = (struct lpfc_dmabuf *) (pmb->context1);
1006
1007 if (mb->mbxStatus) {
1008 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1009 kfree(mp);
1010 mempool_free( pmb, phba->mbox_mem_pool);
1011 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
1012
1013 /* RegLogin failed, so just use loop map to make discovery
1014 list */
1015 lpfc_disc_list_loopmap(phba);
1016
1017 /* Start discovery */
1018 lpfc_disc_start(phba);
1019 return;
1020 }
1021
1022 pmb->context1 = NULL;
1023
dea31012005-04-17 16:05:31 -05001024 ndlp->nlp_rpi = mb->un.varWords[0];
dea31012005-04-17 16:05:31 -05001025 ndlp->nlp_type |= NLP_FABRIC;
1026 ndlp->nlp_state = NLP_STE_UNMAPPED_NODE;
1027 lpfc_nlp_list(phba, ndlp, NLP_UNMAPPED_LIST);
1028
1029 if (phba->hba_state < LPFC_HBA_READY) {
1030 /* Link up discovery requires Fabrib registration. */
1031 lpfc_ns_cmd(phba, ndlp, SLI_CTNS_RNN_ID);
1032 lpfc_ns_cmd(phba, ndlp, SLI_CTNS_RSNN_NN);
1033 lpfc_ns_cmd(phba, ndlp, SLI_CTNS_RFT_ID);
1034 }
1035
1036 phba->fc_ns_retry = 0;
1037 /* Good status, issue CT Request to NameServer */
1038 if (lpfc_ns_cmd(phba, ndlp, SLI_CTNS_GID_FT)) {
1039 /* Cannot issue NameServer Query, so finish up discovery */
1040 lpfc_disc_start(phba);
1041 }
1042
1043 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1044 kfree(mp);
1045 mempool_free( pmb, phba->mbox_mem_pool);
1046
1047 return;
1048}
1049
1050static void
1051lpfc_register_remote_port(struct lpfc_hba * phba,
1052 struct lpfc_nodelist * ndlp)
1053{
1054 struct fc_rport *rport;
1055 struct lpfc_rport_data *rdata;
1056 struct fc_rport_identifiers rport_ids;
dea31012005-04-17 16:05:31 -05001057
1058 /* Remote port has reappeared. Re-register w/ FC transport */
Andrew Morton68ce1eb2005-09-21 09:46:54 -07001059 rport_ids.node_name = wwn_to_u64(ndlp->nlp_nodename.u.wwn);
1060 rport_ids.port_name = wwn_to_u64(ndlp->nlp_portname.u.wwn);
dea31012005-04-17 16:05:31 -05001061 rport_ids.port_id = ndlp->nlp_DID;
1062 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
dea31012005-04-17 16:05:31 -05001063
1064 ndlp->rport = rport = fc_remote_port_add(phba->host, 0, &rport_ids);
1065 if (!rport) {
1066 dev_printk(KERN_WARNING, &phba->pcidev->dev,
1067 "Warning: fc_remote_port_add failed\n");
1068 return;
1069 }
1070
1071 /* initialize static port data */
1072 rport->maxframe_size = ndlp->nlp_maxframe;
1073 rport->supported_classes = ndlp->nlp_class_sup;
1074 if ((rport->scsi_target_id != -1) &&
1075 (rport->scsi_target_id < MAX_FCP_TARGET)) {
1076 ndlp->nlp_sid = rport->scsi_target_id;
1077 }
1078 rdata = rport->dd_data;
1079 rdata->pnode = ndlp;
James.Smart@Emulex.Com23dc04f2005-11-28 11:41:44 -05001080
1081 if (ndlp->nlp_type & NLP_FCP_TARGET)
1082 rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
1083 if (ndlp->nlp_type & NLP_FCP_INITIATOR)
1084 rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
1085
1086
1087 if (rport_ids.roles != FC_RPORT_ROLE_UNKNOWN)
1088 fc_remote_port_rolechg(rport, rport_ids.roles);
1089
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001090
1091 return;
1092}
1093
1094static void
1095lpfc_unregister_remote_port(struct lpfc_hba * phba,
1096 struct lpfc_nodelist * ndlp)
1097{
1098 struct fc_rport *rport = ndlp->rport;
1099 struct lpfc_rport_data *rdata = rport->dd_data;
1100
1101 ndlp->rport = NULL;
1102 rdata->pnode = NULL;
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001103 fc_remote_port_delete(rport);
dea31012005-04-17 16:05:31 -05001104
1105 return;
1106}
1107
1108int
1109lpfc_nlp_list(struct lpfc_hba * phba, struct lpfc_nodelist * nlp, int list)
1110{
1111 enum { none, unmapped, mapped } rport_add = none, rport_del = none;
1112 struct lpfc_sli *psli;
1113
1114 psli = &phba->sli;
1115 /* Sanity check to ensure we are not moving to / from the same list */
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05001116 if ((nlp->nlp_flag & NLP_LIST_MASK) == list)
dea31012005-04-17 16:05:31 -05001117 if (list != NLP_NO_LIST)
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05001118 return 0;
dea31012005-04-17 16:05:31 -05001119
Jamie Wellnitz66a9ed62006-02-28 22:33:10 -05001120 spin_lock_irq(phba->host->host_lock);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05001121 switch (nlp->nlp_flag & NLP_LIST_MASK) {
dea31012005-04-17 16:05:31 -05001122 case NLP_NO_LIST: /* Not on any list */
1123 break;
1124 case NLP_UNUSED_LIST:
1125 phba->fc_unused_cnt--;
1126 list_del(&nlp->nlp_listp);
1127 break;
1128 case NLP_PLOGI_LIST:
1129 phba->fc_plogi_cnt--;
1130 list_del(&nlp->nlp_listp);
1131 break;
1132 case NLP_ADISC_LIST:
1133 phba->fc_adisc_cnt--;
1134 list_del(&nlp->nlp_listp);
1135 break;
1136 case NLP_REGLOGIN_LIST:
1137 phba->fc_reglogin_cnt--;
1138 list_del(&nlp->nlp_listp);
1139 break;
1140 case NLP_PRLI_LIST:
1141 phba->fc_prli_cnt--;
1142 list_del(&nlp->nlp_listp);
1143 break;
1144 case NLP_UNMAPPED_LIST:
1145 phba->fc_unmap_cnt--;
1146 list_del(&nlp->nlp_listp);
dea31012005-04-17 16:05:31 -05001147 nlp->nlp_flag &= ~NLP_TGT_NO_SCSIID;
1148 nlp->nlp_type &= ~NLP_FC_NODE;
dea31012005-04-17 16:05:31 -05001149 phba->nport_event_cnt++;
1150 if (nlp->rport)
1151 rport_del = unmapped;
1152 break;
1153 case NLP_MAPPED_LIST:
1154 phba->fc_map_cnt--;
1155 list_del(&nlp->nlp_listp);
1156 phba->nport_event_cnt++;
1157 if (nlp->rport)
1158 rport_del = mapped;
1159 break;
1160 case NLP_NPR_LIST:
1161 phba->fc_npr_cnt--;
1162 list_del(&nlp->nlp_listp);
1163 /* Stop delay tmo if taking node off NPR list */
1164 if ((nlp->nlp_flag & NLP_DELAY_TMO) &&
1165 (list != NLP_NPR_LIST)) {
Jamie Wellnitz66a9ed62006-02-28 22:33:10 -05001166 spin_unlock_irq(phba->host->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05001167 lpfc_cancel_retry_delay_tmo(phba, nlp);
Jamie Wellnitz66a9ed62006-02-28 22:33:10 -05001168 spin_lock_irq(phba->host->host_lock);
dea31012005-04-17 16:05:31 -05001169 }
1170 break;
1171 }
1172
dea31012005-04-17 16:05:31 -05001173 nlp->nlp_flag &= ~NLP_LIST_MASK;
dea31012005-04-17 16:05:31 -05001174
1175 /* Add NPort <did> to <num> list */
1176 lpfc_printf_log(phba,
1177 KERN_INFO,
1178 LOG_NODE,
1179 "%d:0904 Add NPort x%x to %d list Data: x%x\n",
1180 phba->brd_no,
1181 nlp->nlp_DID, list, nlp->nlp_flag);
1182
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05001183 switch (list) {
dea31012005-04-17 16:05:31 -05001184 case NLP_NO_LIST: /* No list, just remove it */
Jamie Wellnitz66a9ed62006-02-28 22:33:10 -05001185 spin_unlock_irq(phba->host->host_lock);
dea31012005-04-17 16:05:31 -05001186 lpfc_nlp_remove(phba, nlp);
Jamie Wellnitz66a9ed62006-02-28 22:33:10 -05001187 spin_lock_irq(phba->host->host_lock);
James.Smart@Emulex.Com8cbdc5f2005-08-10 15:02:50 -04001188 /* as node removed - stop further transport calls */
1189 rport_del = none;
dea31012005-04-17 16:05:31 -05001190 break;
1191 case NLP_UNUSED_LIST:
dea31012005-04-17 16:05:31 -05001192 nlp->nlp_flag |= list;
dea31012005-04-17 16:05:31 -05001193 /* Put it at the end of the unused list */
1194 list_add_tail(&nlp->nlp_listp, &phba->fc_unused_list);
1195 phba->fc_unused_cnt++;
1196 break;
1197 case NLP_PLOGI_LIST:
dea31012005-04-17 16:05:31 -05001198 nlp->nlp_flag |= list;
dea31012005-04-17 16:05:31 -05001199 /* Put it at the end of the plogi list */
1200 list_add_tail(&nlp->nlp_listp, &phba->fc_plogi_list);
1201 phba->fc_plogi_cnt++;
1202 break;
1203 case NLP_ADISC_LIST:
dea31012005-04-17 16:05:31 -05001204 nlp->nlp_flag |= list;
dea31012005-04-17 16:05:31 -05001205 /* Put it at the end of the adisc list */
1206 list_add_tail(&nlp->nlp_listp, &phba->fc_adisc_list);
1207 phba->fc_adisc_cnt++;
1208 break;
1209 case NLP_REGLOGIN_LIST:
dea31012005-04-17 16:05:31 -05001210 nlp->nlp_flag |= list;
dea31012005-04-17 16:05:31 -05001211 /* Put it at the end of the reglogin list */
1212 list_add_tail(&nlp->nlp_listp, &phba->fc_reglogin_list);
1213 phba->fc_reglogin_cnt++;
1214 break;
1215 case NLP_PRLI_LIST:
dea31012005-04-17 16:05:31 -05001216 nlp->nlp_flag |= list;
dea31012005-04-17 16:05:31 -05001217 /* Put it at the end of the prli list */
1218 list_add_tail(&nlp->nlp_listp, &phba->fc_prli_list);
1219 phba->fc_prli_cnt++;
1220 break;
1221 case NLP_UNMAPPED_LIST:
1222 rport_add = unmapped;
1223 /* ensure all vestiges of "mapped" significance are gone */
1224 nlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
dea31012005-04-17 16:05:31 -05001225 nlp->nlp_flag |= list;
dea31012005-04-17 16:05:31 -05001226 /* Put it at the end of the unmap list */
1227 list_add_tail(&nlp->nlp_listp, &phba->fc_nlpunmap_list);
1228 phba->fc_unmap_cnt++;
1229 phba->nport_event_cnt++;
1230 /* stop nodev tmo if running */
1231 if (nlp->nlp_flag & NLP_NODEV_TMO) {
dea31012005-04-17 16:05:31 -05001232 nlp->nlp_flag &= ~NLP_NODEV_TMO;
1233 spin_unlock_irq(phba->host->host_lock);
1234 del_timer_sync(&nlp->nlp_tmofunc);
Jamie Wellnitz66a9ed62006-02-28 22:33:10 -05001235 spin_lock_irq(phba->host->host_lock);
dea31012005-04-17 16:05:31 -05001236 if (!list_empty(&nlp->nodev_timeout_evt.evt_listp))
1237 list_del_init(&nlp->nodev_timeout_evt.
1238 evt_listp);
1239
1240 }
James Smarta0f9b482006-04-15 11:52:56 -04001241 nlp->nlp_flag &= ~NLP_NODEV_REMOVE;
dea31012005-04-17 16:05:31 -05001242 nlp->nlp_type |= NLP_FC_NODE;
1243 break;
1244 case NLP_MAPPED_LIST:
1245 rport_add = mapped;
dea31012005-04-17 16:05:31 -05001246 nlp->nlp_flag |= list;
dea31012005-04-17 16:05:31 -05001247 /* Put it at the end of the map list */
1248 list_add_tail(&nlp->nlp_listp, &phba->fc_nlpmap_list);
1249 phba->fc_map_cnt++;
1250 phba->nport_event_cnt++;
1251 /* stop nodev tmo if running */
1252 if (nlp->nlp_flag & NLP_NODEV_TMO) {
1253 nlp->nlp_flag &= ~NLP_NODEV_TMO;
Jamie Wellnitz66a9ed62006-02-28 22:33:10 -05001254 spin_unlock_irq(phba->host->host_lock);
dea31012005-04-17 16:05:31 -05001255 del_timer_sync(&nlp->nlp_tmofunc);
Jamie Wellnitz66a9ed62006-02-28 22:33:10 -05001256 spin_lock_irq(phba->host->host_lock);
dea31012005-04-17 16:05:31 -05001257 if (!list_empty(&nlp->nodev_timeout_evt.evt_listp))
1258 list_del_init(&nlp->nodev_timeout_evt.
1259 evt_listp);
1260
1261 }
James Smarta0f9b482006-04-15 11:52:56 -04001262 nlp->nlp_flag &= ~NLP_NODEV_REMOVE;
dea31012005-04-17 16:05:31 -05001263 break;
1264 case NLP_NPR_LIST:
dea31012005-04-17 16:05:31 -05001265 nlp->nlp_flag |= list;
dea31012005-04-17 16:05:31 -05001266 /* Put it at the end of the npr list */
1267 list_add_tail(&nlp->nlp_listp, &phba->fc_npr_list);
1268 phba->fc_npr_cnt++;
1269
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05001270 if (!(nlp->nlp_flag & NLP_NODEV_TMO))
dea31012005-04-17 16:05:31 -05001271 mod_timer(&nlp->nlp_tmofunc,
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001272 jiffies + HZ * phba->cfg_nodev_tmo);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05001273
dea31012005-04-17 16:05:31 -05001274 nlp->nlp_flag |= NLP_NODEV_TMO;
1275 nlp->nlp_flag &= ~NLP_RCV_PLOGI;
dea31012005-04-17 16:05:31 -05001276 break;
1277 case NLP_JUST_DQ:
1278 break;
1279 }
1280
Jamie Wellnitz66a9ed62006-02-28 22:33:10 -05001281 spin_unlock_irq(phba->host->host_lock);
1282
dea31012005-04-17 16:05:31 -05001283 /*
1284 * We make all the calls into the transport after we have
1285 * moved the node between lists. This so that we don't
1286 * release the lock while in-between lists.
1287 */
1288
1289 /* Don't upcall midlayer if we're unloading */
1290 if (!(phba->fc_flag & FC_UNLOADING)) {
1291 /*
1292 * We revalidate the rport pointer as the "add" function
1293 * may have removed the remote port.
1294 */
1295 if ((rport_del != none) && nlp->rport)
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001296 lpfc_unregister_remote_port(phba, nlp);
dea31012005-04-17 16:05:31 -05001297
1298 if (rport_add != none) {
1299 /*
1300 * Tell the fc transport about the port, if we haven't
1301 * already. If we have, and it's a scsi entity, be
1302 * sure to unblock any attached scsi devices
1303 */
1304 if (!nlp->rport)
1305 lpfc_register_remote_port(phba, nlp);
dea31012005-04-17 16:05:31 -05001306
1307 /*
1308 * if we added to Mapped list, but the remote port
1309 * registration failed or assigned a target id outside
1310 * our presentable range - move the node to the
1311 * Unmapped List
1312 */
1313 if ((rport_add == mapped) &&
1314 ((!nlp->rport) ||
1315 (nlp->rport->scsi_target_id == -1) ||
1316 (nlp->rport->scsi_target_id >= MAX_FCP_TARGET))) {
1317 nlp->nlp_state = NLP_STE_UNMAPPED_NODE;
1318 spin_lock_irq(phba->host->host_lock);
1319 nlp->nlp_flag |= NLP_TGT_NO_SCSIID;
1320 spin_unlock_irq(phba->host->host_lock);
1321 lpfc_nlp_list(phba, nlp, NLP_UNMAPPED_LIST);
1322 }
1323 }
1324 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05001325 return 0;
dea31012005-04-17 16:05:31 -05001326}
1327
1328/*
1329 * Start / ReStart rescue timer for Discovery / RSCN handling
1330 */
1331void
1332lpfc_set_disctmo(struct lpfc_hba * phba)
1333{
1334 uint32_t tmo;
1335
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001336 if (phba->hba_state == LPFC_LOCAL_CFG_LINK) {
1337 /* For FAN, timeout should be greater then edtov */
1338 tmo = (((phba->fc_edtov + 999) / 1000) + 1);
1339 } else {
1340 /* Normal discovery timeout should be > then ELS/CT timeout
1341 * FC spec states we need 3 * ratov for CT requests
1342 */
1343 tmo = ((phba->fc_ratov * 3) + 3);
1344 }
dea31012005-04-17 16:05:31 -05001345
1346 mod_timer(&phba->fc_disctmo, jiffies + HZ * tmo);
1347 spin_lock_irq(phba->host->host_lock);
1348 phba->fc_flag |= FC_DISC_TMO;
1349 spin_unlock_irq(phba->host->host_lock);
1350
1351 /* Start Discovery Timer state <hba_state> */
1352 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
1353 "%d:0247 Start Discovery Timer state x%x "
1354 "Data: x%x x%lx x%x x%x\n",
1355 phba->brd_no,
1356 phba->hba_state, tmo, (unsigned long)&phba->fc_disctmo,
1357 phba->fc_plogi_cnt, phba->fc_adisc_cnt);
1358
1359 return;
1360}
1361
1362/*
1363 * Cancel rescue timer for Discovery / RSCN handling
1364 */
1365int
1366lpfc_can_disctmo(struct lpfc_hba * phba)
1367{
1368 /* Turn off discovery timer if its running */
1369 if (phba->fc_flag & FC_DISC_TMO) {
1370 spin_lock_irq(phba->host->host_lock);
1371 phba->fc_flag &= ~FC_DISC_TMO;
1372 spin_unlock_irq(phba->host->host_lock);
1373 del_timer_sync(&phba->fc_disctmo);
1374 phba->work_hba_events &= ~WORKER_DISC_TMO;
1375 }
1376
1377 /* Cancel Discovery Timer state <hba_state> */
1378 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
1379 "%d:0248 Cancel Discovery Timer state x%x "
1380 "Data: x%x x%x x%x\n",
1381 phba->brd_no, phba->hba_state, phba->fc_flag,
1382 phba->fc_plogi_cnt, phba->fc_adisc_cnt);
1383
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05001384 return 0;
dea31012005-04-17 16:05:31 -05001385}
1386
1387/*
1388 * Check specified ring for outstanding IOCB on the SLI queue
1389 * Return true if iocb matches the specified nport
1390 */
1391int
1392lpfc_check_sli_ndlp(struct lpfc_hba * phba,
1393 struct lpfc_sli_ring * pring,
1394 struct lpfc_iocbq * iocb, struct lpfc_nodelist * ndlp)
1395{
1396 struct lpfc_sli *psli;
1397 IOCB_t *icmd;
1398
1399 psli = &phba->sli;
1400 icmd = &iocb->iocb;
1401 if (pring->ringno == LPFC_ELS_RING) {
1402 switch (icmd->ulpCommand) {
1403 case CMD_GEN_REQUEST64_CR:
1404 if (icmd->ulpContext == (volatile ushort)ndlp->nlp_rpi)
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05001405 return 1;
dea31012005-04-17 16:05:31 -05001406 case CMD_ELS_REQUEST64_CR:
1407 case CMD_XMIT_ELS_RSP64_CX:
1408 if (iocb->context1 == (uint8_t *) ndlp)
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05001409 return 1;
dea31012005-04-17 16:05:31 -05001410 }
1411 } else if (pring->ringno == psli->ip_ring) {
1412
1413 } else if (pring->ringno == psli->fcp_ring) {
1414 /* Skip match check if waiting to relogin to FCP target */
1415 if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
1416 (ndlp->nlp_flag & NLP_DELAY_TMO)) {
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05001417 return 0;
dea31012005-04-17 16:05:31 -05001418 }
1419 if (icmd->ulpContext == (volatile ushort)ndlp->nlp_rpi) {
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05001420 return 1;
dea31012005-04-17 16:05:31 -05001421 }
1422 } else if (pring->ringno == psli->next_ring) {
1423
1424 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05001425 return 0;
dea31012005-04-17 16:05:31 -05001426}
1427
1428/*
1429 * Free resources / clean up outstanding I/Os
1430 * associated with nlp_rpi in the LPFC_NODELIST entry.
1431 */
1432static int
1433lpfc_no_rpi(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp)
1434{
1435 struct lpfc_sli *psli;
1436 struct lpfc_sli_ring *pring;
1437 struct lpfc_iocbq *iocb, *next_iocb;
1438 IOCB_t *icmd;
1439 uint32_t rpi, i;
1440
1441 /*
1442 * Everything that matches on txcmplq will be returned
1443 * by firmware with a no rpi error.
1444 */
1445 psli = &phba->sli;
1446 rpi = ndlp->nlp_rpi;
1447 if (rpi) {
1448 /* Now process each ring */
1449 for (i = 0; i < psli->num_rings; i++) {
1450 pring = &psli->ring[i];
1451
1452 spin_lock_irq(phba->host->host_lock);
1453 list_for_each_entry_safe(iocb, next_iocb, &pring->txq,
1454 list) {
1455 /*
1456 * Check to see if iocb matches the nport we are
1457 * looking for
1458 */
1459 if ((lpfc_check_sli_ndlp
1460 (phba, pring, iocb, ndlp))) {
1461 /* It matches, so deque and call compl
1462 with an error */
1463 list_del(&iocb->list);
1464 pring->txq_cnt--;
1465 if (iocb->iocb_cmpl) {
1466 icmd = &iocb->iocb;
1467 icmd->ulpStatus =
1468 IOSTAT_LOCAL_REJECT;
1469 icmd->un.ulpWord[4] =
1470 IOERR_SLI_ABORTED;
1471 spin_unlock_irq(phba->host->
1472 host_lock);
1473 (iocb->iocb_cmpl) (phba,
1474 iocb, iocb);
1475 spin_lock_irq(phba->host->
1476 host_lock);
James Bottomley604a3e32005-10-29 10:28:33 -05001477 } else
1478 lpfc_sli_release_iocbq(phba,
1479 iocb);
dea31012005-04-17 16:05:31 -05001480 }
1481 }
1482 spin_unlock_irq(phba->host->host_lock);
1483
1484 }
1485 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05001486 return 0;
dea31012005-04-17 16:05:31 -05001487}
1488
1489/*
1490 * Free rpi associated with LPFC_NODELIST entry.
1491 * This routine is called from lpfc_freenode(), when we are removing
1492 * a LPFC_NODELIST entry. It is also called if the driver initiates a
1493 * LOGO that completes successfully, and we are waiting to PLOGI back
1494 * to the remote NPort. In addition, it is called after we receive
1495 * and unsolicated ELS cmd, send back a rsp, the rsp completes and
1496 * we are waiting to PLOGI back to the remote NPort.
1497 */
1498int
1499lpfc_unreg_rpi(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp)
1500{
1501 LPFC_MBOXQ_t *mbox;
1502 int rc;
1503
1504 if (ndlp->nlp_rpi) {
1505 if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL))) {
1506 lpfc_unreg_login(phba, ndlp->nlp_rpi, mbox);
1507 mbox->mbox_cmpl=lpfc_sli_def_mbox_cmpl;
1508 rc = lpfc_sli_issue_mbox
1509 (phba, mbox, (MBX_NOWAIT | MBX_STOP_IOCB));
1510 if (rc == MBX_NOT_FINISHED)
1511 mempool_free( mbox, phba->mbox_mem_pool);
1512 }
dea31012005-04-17 16:05:31 -05001513 lpfc_no_rpi(phba, ndlp);
1514 ndlp->nlp_rpi = 0;
1515 return 1;
1516 }
1517 return 0;
1518}
1519
1520/*
1521 * Free resources associated with LPFC_NODELIST entry
1522 * so it can be freed.
1523 */
1524static int
1525lpfc_freenode(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp)
1526{
1527 LPFC_MBOXQ_t *mb;
1528 LPFC_MBOXQ_t *nextmb;
1529 struct lpfc_dmabuf *mp;
dea31012005-04-17 16:05:31 -05001530
1531 /* Cleanup node for NPort <nlp_DID> */
1532 lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
1533 "%d:0900 Cleanup node for NPort x%x "
1534 "Data: x%x x%x x%x\n",
1535 phba->brd_no, ndlp->nlp_DID, ndlp->nlp_flag,
1536 ndlp->nlp_state, ndlp->nlp_rpi);
1537
1538 lpfc_nlp_list(phba, ndlp, NLP_JUST_DQ);
1539
1540 /*
1541 * if unloading the driver - just leave the remote port in place.
1542 * The driver unload will force the attached devices to detach
1543 * and flush cache's w/o generating flush errors.
1544 */
1545 if ((ndlp->rport) && !(phba->fc_flag & FC_UNLOADING)) {
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001546 lpfc_unregister_remote_port(phba, ndlp);
dea31012005-04-17 16:05:31 -05001547 ndlp->nlp_sid = NLP_NO_SID;
1548 }
1549
1550 /* cleanup any ndlp on mbox q waiting for reglogin cmpl */
1551 if ((mb = phba->sli.mbox_active)) {
1552 if ((mb->mb.mbxCommand == MBX_REG_LOGIN64) &&
1553 (ndlp == (struct lpfc_nodelist *) mb->context2)) {
1554 mb->context2 = NULL;
1555 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1556 }
1557 }
1558 list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
1559 if ((mb->mb.mbxCommand == MBX_REG_LOGIN64) &&
1560 (ndlp == (struct lpfc_nodelist *) mb->context2)) {
1561 mp = (struct lpfc_dmabuf *) (mb->context1);
1562 if (mp) {
1563 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1564 kfree(mp);
1565 }
1566 list_del(&mb->list);
1567 mempool_free(mb, phba->mbox_mem_pool);
1568 }
1569 }
1570
1571 lpfc_els_abort(phba,ndlp,0);
1572 spin_lock_irq(phba->host->host_lock);
1573 ndlp->nlp_flag &= ~(NLP_NODEV_TMO|NLP_DELAY_TMO);
1574 spin_unlock_irq(phba->host->host_lock);
1575 del_timer_sync(&ndlp->nlp_tmofunc);
1576
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001577 ndlp->nlp_last_elscmd = 0;
dea31012005-04-17 16:05:31 -05001578 del_timer_sync(&ndlp->nlp_delayfunc);
1579
1580 if (!list_empty(&ndlp->nodev_timeout_evt.evt_listp))
1581 list_del_init(&ndlp->nodev_timeout_evt.evt_listp);
1582 if (!list_empty(&ndlp->els_retry_evt.evt_listp))
1583 list_del_init(&ndlp->els_retry_evt.evt_listp);
1584
1585 lpfc_unreg_rpi(phba, ndlp);
1586
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05001587 return 0;
dea31012005-04-17 16:05:31 -05001588}
1589
1590/*
1591 * Check to see if we can free the nlp back to the freelist.
1592 * If we are in the middle of using the nlp in the discovery state
1593 * machine, defer the free till we reach the end of the state machine.
1594 */
1595int
1596lpfc_nlp_remove(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp)
1597{
1598 if (ndlp->nlp_flag & NLP_NODEV_TMO) {
1599 spin_lock_irq(phba->host->host_lock);
1600 ndlp->nlp_flag &= ~NLP_NODEV_TMO;
1601 spin_unlock_irq(phba->host->host_lock);
1602 del_timer_sync(&ndlp->nlp_tmofunc);
1603 if (!list_empty(&ndlp->nodev_timeout_evt.evt_listp))
1604 list_del_init(&ndlp->nodev_timeout_evt.evt_listp);
1605
1606 }
1607
1608
1609 if (ndlp->nlp_flag & NLP_DELAY_TMO) {
James Smartfdcebe22006-03-07 15:04:01 -05001610 lpfc_cancel_retry_delay_tmo(phba, ndlp);
dea31012005-04-17 16:05:31 -05001611 }
1612
1613 if (ndlp->nlp_disc_refcnt) {
1614 spin_lock_irq(phba->host->host_lock);
1615 ndlp->nlp_flag |= NLP_DELAY_REMOVE;
1616 spin_unlock_irq(phba->host->host_lock);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05001617 } else {
dea31012005-04-17 16:05:31 -05001618 lpfc_freenode(phba, ndlp);
1619 mempool_free( ndlp, phba->nlp_mem_pool);
1620 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05001621 return 0;
dea31012005-04-17 16:05:31 -05001622}
1623
1624static int
1625lpfc_matchdid(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp, uint32_t did)
1626{
1627 D_ID mydid;
1628 D_ID ndlpdid;
1629 D_ID matchdid;
1630
1631 if (did == Bcast_DID)
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05001632 return 0;
dea31012005-04-17 16:05:31 -05001633
1634 if (ndlp->nlp_DID == 0) {
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05001635 return 0;
dea31012005-04-17 16:05:31 -05001636 }
1637
1638 /* First check for Direct match */
1639 if (ndlp->nlp_DID == did)
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05001640 return 1;
dea31012005-04-17 16:05:31 -05001641
1642 /* Next check for area/domain identically equals 0 match */
1643 mydid.un.word = phba->fc_myDID;
1644 if ((mydid.un.b.domain == 0) && (mydid.un.b.area == 0)) {
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05001645 return 0;
dea31012005-04-17 16:05:31 -05001646 }
1647
1648 matchdid.un.word = did;
1649 ndlpdid.un.word = ndlp->nlp_DID;
1650 if (matchdid.un.b.id == ndlpdid.un.b.id) {
1651 if ((mydid.un.b.domain == matchdid.un.b.domain) &&
1652 (mydid.un.b.area == matchdid.un.b.area)) {
1653 if ((ndlpdid.un.b.domain == 0) &&
1654 (ndlpdid.un.b.area == 0)) {
1655 if (ndlpdid.un.b.id)
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05001656 return 1;
dea31012005-04-17 16:05:31 -05001657 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05001658 return 0;
dea31012005-04-17 16:05:31 -05001659 }
1660
1661 matchdid.un.word = ndlp->nlp_DID;
1662 if ((mydid.un.b.domain == ndlpdid.un.b.domain) &&
1663 (mydid.un.b.area == ndlpdid.un.b.area)) {
1664 if ((matchdid.un.b.domain == 0) &&
1665 (matchdid.un.b.area == 0)) {
1666 if (matchdid.un.b.id)
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05001667 return 1;
dea31012005-04-17 16:05:31 -05001668 }
1669 }
1670 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05001671 return 0;
dea31012005-04-17 16:05:31 -05001672}
1673
1674/* Search for a nodelist entry on a specific list */
1675struct lpfc_nodelist *
1676lpfc_findnode_did(struct lpfc_hba * phba, uint32_t order, uint32_t did)
1677{
1678 struct lpfc_nodelist *ndlp, *next_ndlp;
1679 uint32_t data1;
1680
Jamie Wellnitz66a9ed62006-02-28 22:33:10 -05001681 spin_lock_irq(phba->host->host_lock);
dea31012005-04-17 16:05:31 -05001682 if (order & NLP_SEARCH_UNMAPPED) {
1683 list_for_each_entry_safe(ndlp, next_ndlp,
1684 &phba->fc_nlpunmap_list, nlp_listp) {
1685 if (lpfc_matchdid(phba, ndlp, did)) {
1686 data1 = (((uint32_t) ndlp->nlp_state << 24) |
1687 ((uint32_t) ndlp->nlp_xri << 16) |
1688 ((uint32_t) ndlp->nlp_type << 8) |
1689 ((uint32_t) ndlp->nlp_rpi & 0xff));
1690 /* FIND node DID unmapped */
1691 lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
1692 "%d:0929 FIND node DID unmapped"
1693 " Data: x%p x%x x%x x%x\n",
1694 phba->brd_no,
1695 ndlp, ndlp->nlp_DID,
1696 ndlp->nlp_flag, data1);
Jamie Wellnitz66a9ed62006-02-28 22:33:10 -05001697 spin_unlock_irq(phba->host->host_lock);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05001698 return ndlp;
dea31012005-04-17 16:05:31 -05001699 }
1700 }
1701 }
1702
1703 if (order & NLP_SEARCH_MAPPED) {
1704 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_nlpmap_list,
1705 nlp_listp) {
1706 if (lpfc_matchdid(phba, ndlp, did)) {
1707
1708 data1 = (((uint32_t) ndlp->nlp_state << 24) |
1709 ((uint32_t) ndlp->nlp_xri << 16) |
1710 ((uint32_t) ndlp->nlp_type << 8) |
1711 ((uint32_t) ndlp->nlp_rpi & 0xff));
1712 /* FIND node DID mapped */
1713 lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
1714 "%d:0930 FIND node DID mapped "
1715 "Data: x%p x%x x%x x%x\n",
1716 phba->brd_no,
1717 ndlp, ndlp->nlp_DID,
1718 ndlp->nlp_flag, data1);
Jamie Wellnitz66a9ed62006-02-28 22:33:10 -05001719 spin_unlock_irq(phba->host->host_lock);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05001720 return ndlp;
dea31012005-04-17 16:05:31 -05001721 }
1722 }
1723 }
1724
1725 if (order & NLP_SEARCH_PLOGI) {
1726 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_plogi_list,
1727 nlp_listp) {
1728 if (lpfc_matchdid(phba, ndlp, did)) {
1729
1730 data1 = (((uint32_t) ndlp->nlp_state << 24) |
1731 ((uint32_t) ndlp->nlp_xri << 16) |
1732 ((uint32_t) ndlp->nlp_type << 8) |
1733 ((uint32_t) ndlp->nlp_rpi & 0xff));
1734 /* LOG change to PLOGI */
1735 /* FIND node DID plogi */
1736 lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
1737 "%d:0908 FIND node DID plogi "
1738 "Data: x%p x%x x%x x%x\n",
1739 phba->brd_no,
1740 ndlp, ndlp->nlp_DID,
1741 ndlp->nlp_flag, data1);
Jamie Wellnitz66a9ed62006-02-28 22:33:10 -05001742 spin_unlock_irq(phba->host->host_lock);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05001743 return ndlp;
dea31012005-04-17 16:05:31 -05001744 }
1745 }
1746 }
1747
1748 if (order & NLP_SEARCH_ADISC) {
1749 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_adisc_list,
1750 nlp_listp) {
1751 if (lpfc_matchdid(phba, ndlp, did)) {
1752
1753 data1 = (((uint32_t) ndlp->nlp_state << 24) |
1754 ((uint32_t) ndlp->nlp_xri << 16) |
1755 ((uint32_t) ndlp->nlp_type << 8) |
1756 ((uint32_t) ndlp->nlp_rpi & 0xff));
1757 /* LOG change to ADISC */
1758 /* FIND node DID adisc */
1759 lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
1760 "%d:0931 FIND node DID adisc "
1761 "Data: x%p x%x x%x x%x\n",
1762 phba->brd_no,
1763 ndlp, ndlp->nlp_DID,
1764 ndlp->nlp_flag, data1);
James Smartfc6c12b2006-03-07 15:04:19 -05001765 spin_unlock_irq(phba->host->host_lock);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05001766 return ndlp;
dea31012005-04-17 16:05:31 -05001767 }
1768 }
1769 }
1770
1771 if (order & NLP_SEARCH_REGLOGIN) {
1772 list_for_each_entry_safe(ndlp, next_ndlp,
1773 &phba->fc_reglogin_list, nlp_listp) {
1774 if (lpfc_matchdid(phba, ndlp, did)) {
1775
1776 data1 = (((uint32_t) ndlp->nlp_state << 24) |
1777 ((uint32_t) ndlp->nlp_xri << 16) |
1778 ((uint32_t) ndlp->nlp_type << 8) |
1779 ((uint32_t) ndlp->nlp_rpi & 0xff));
1780 /* LOG change to REGLOGIN */
1781 /* FIND node DID reglogin */
1782 lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
1783 "%d:0931 FIND node DID reglogin"
1784 " Data: x%p x%x x%x x%x\n",
1785 phba->brd_no,
1786 ndlp, ndlp->nlp_DID,
1787 ndlp->nlp_flag, data1);
Jamie Wellnitz66a9ed62006-02-28 22:33:10 -05001788 spin_unlock_irq(phba->host->host_lock);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05001789 return ndlp;
dea31012005-04-17 16:05:31 -05001790 }
1791 }
1792 }
1793
1794 if (order & NLP_SEARCH_PRLI) {
1795 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_prli_list,
1796 nlp_listp) {
1797 if (lpfc_matchdid(phba, ndlp, did)) {
1798
1799 data1 = (((uint32_t) ndlp->nlp_state << 24) |
1800 ((uint32_t) ndlp->nlp_xri << 16) |
1801 ((uint32_t) ndlp->nlp_type << 8) |
1802 ((uint32_t) ndlp->nlp_rpi & 0xff));
1803 /* LOG change to PRLI */
1804 /* FIND node DID prli */
1805 lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
1806 "%d:0931 FIND node DID prli "
1807 "Data: x%p x%x x%x x%x\n",
1808 phba->brd_no,
1809 ndlp, ndlp->nlp_DID,
1810 ndlp->nlp_flag, data1);
James Smartfc6c12b2006-03-07 15:04:19 -05001811 spin_unlock_irq(phba->host->host_lock);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05001812 return ndlp;
dea31012005-04-17 16:05:31 -05001813 }
1814 }
1815 }
1816
1817 if (order & NLP_SEARCH_NPR) {
1818 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_npr_list,
1819 nlp_listp) {
1820 if (lpfc_matchdid(phba, ndlp, did)) {
1821
1822 data1 = (((uint32_t) ndlp->nlp_state << 24) |
1823 ((uint32_t) ndlp->nlp_xri << 16) |
1824 ((uint32_t) ndlp->nlp_type << 8) |
1825 ((uint32_t) ndlp->nlp_rpi & 0xff));
1826 /* LOG change to NPR */
1827 /* FIND node DID npr */
1828 lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
1829 "%d:0931 FIND node DID npr "
1830 "Data: x%p x%x x%x x%x\n",
1831 phba->brd_no,
1832 ndlp, ndlp->nlp_DID,
1833 ndlp->nlp_flag, data1);
Jamie Wellnitz66a9ed62006-02-28 22:33:10 -05001834 spin_unlock_irq(phba->host->host_lock);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05001835 return ndlp;
dea31012005-04-17 16:05:31 -05001836 }
1837 }
1838 }
1839
1840 if (order & NLP_SEARCH_UNUSED) {
1841 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_adisc_list,
1842 nlp_listp) {
1843 if (lpfc_matchdid(phba, ndlp, did)) {
1844
1845 data1 = (((uint32_t) ndlp->nlp_state << 24) |
1846 ((uint32_t) ndlp->nlp_xri << 16) |
1847 ((uint32_t) ndlp->nlp_type << 8) |
1848 ((uint32_t) ndlp->nlp_rpi & 0xff));
1849 /* LOG change to UNUSED */
1850 /* FIND node DID unused */
1851 lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
1852 "%d:0931 FIND node DID unused "
1853 "Data: x%p x%x x%x x%x\n",
1854 phba->brd_no,
1855 ndlp, ndlp->nlp_DID,
1856 ndlp->nlp_flag, data1);
Jamie Wellnitz66a9ed62006-02-28 22:33:10 -05001857 spin_unlock_irq(phba->host->host_lock);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05001858 return ndlp;
dea31012005-04-17 16:05:31 -05001859 }
1860 }
1861 }
1862
Jamie Wellnitz66a9ed62006-02-28 22:33:10 -05001863 spin_unlock_irq(phba->host->host_lock);
1864
dea31012005-04-17 16:05:31 -05001865 /* FIND node did <did> NOT FOUND */
1866 lpfc_printf_log(phba,
1867 KERN_INFO,
1868 LOG_NODE,
1869 "%d:0932 FIND node did x%x NOT FOUND Data: x%x\n",
1870 phba->brd_no, did, order);
1871
1872 /* no match found */
1873 return NULL;
1874}
1875
1876struct lpfc_nodelist *
1877lpfc_setup_disc_node(struct lpfc_hba * phba, uint32_t did)
1878{
1879 struct lpfc_nodelist *ndlp;
1880 uint32_t flg;
1881
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001882 ndlp = lpfc_findnode_did(phba, NLP_SEARCH_ALL, did);
1883 if (!ndlp) {
1884 if ((phba->fc_flag & FC_RSCN_MODE) &&
dea31012005-04-17 16:05:31 -05001885 ((lpfc_rscn_payload_check(phba, did) == 0)))
1886 return NULL;
1887 ndlp = (struct lpfc_nodelist *)
1888 mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1889 if (!ndlp)
1890 return NULL;
1891 lpfc_nlp_init(phba, ndlp, did);
1892 ndlp->nlp_state = NLP_STE_NPR_NODE;
1893 lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
1894 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1895 return ndlp;
1896 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001897 if (phba->fc_flag & FC_RSCN_MODE) {
dea31012005-04-17 16:05:31 -05001898 if (lpfc_rscn_payload_check(phba, did)) {
1899 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001900
1901 /* Since this node is marked for discovery,
1902 * delay timeout is not needed.
1903 */
James Smartfdcebe22006-03-07 15:04:01 -05001904 if (ndlp->nlp_flag & NLP_DELAY_TMO)
1905 lpfc_cancel_retry_delay_tmo(phba, ndlp);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05001906 } else {
dea31012005-04-17 16:05:31 -05001907 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1908 ndlp = NULL;
1909 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05001910 } else {
dea31012005-04-17 16:05:31 -05001911 flg = ndlp->nlp_flag & NLP_LIST_MASK;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001912 if ((flg == NLP_ADISC_LIST) || (flg == NLP_PLOGI_LIST))
dea31012005-04-17 16:05:31 -05001913 return NULL;
dea31012005-04-17 16:05:31 -05001914 ndlp->nlp_state = NLP_STE_NPR_NODE;
1915 lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
1916 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1917 }
1918 return ndlp;
1919}
1920
1921/* Build a list of nodes to discover based on the loopmap */
1922void
1923lpfc_disc_list_loopmap(struct lpfc_hba * phba)
1924{
1925 int j;
1926 uint32_t alpa, index;
1927
1928 if (phba->hba_state <= LPFC_LINK_DOWN) {
1929 return;
1930 }
1931 if (phba->fc_topology != TOPOLOGY_LOOP) {
1932 return;
1933 }
1934
1935 /* Check for loop map present or not */
1936 if (phba->alpa_map[0]) {
1937 for (j = 1; j <= phba->alpa_map[0]; j++) {
1938 alpa = phba->alpa_map[j];
1939
1940 if (((phba->fc_myDID & 0xff) == alpa) || (alpa == 0)) {
1941 continue;
1942 }
1943 lpfc_setup_disc_node(phba, alpa);
1944 }
1945 } else {
1946 /* No alpamap, so try all alpa's */
1947 for (j = 0; j < FC_MAXLOOP; j++) {
1948 /* If cfg_scan_down is set, start from highest
1949 * ALPA (0xef) to lowest (0x1).
1950 */
1951 if (phba->cfg_scan_down)
1952 index = j;
1953 else
1954 index = FC_MAXLOOP - j - 1;
1955 alpa = lpfcAlpaArray[index];
1956 if ((phba->fc_myDID & 0xff) == alpa) {
1957 continue;
1958 }
1959
1960 lpfc_setup_disc_node(phba, alpa);
1961 }
1962 }
1963 return;
1964}
1965
1966/* Start Link up / RSCN discovery on NPR list */
1967void
1968lpfc_disc_start(struct lpfc_hba * phba)
1969{
1970 struct lpfc_sli *psli;
1971 LPFC_MBOXQ_t *mbox;
1972 struct lpfc_nodelist *ndlp, *next_ndlp;
1973 uint32_t did_changed, num_sent;
1974 uint32_t clear_la_pending;
1975 int rc;
1976
1977 psli = &phba->sli;
1978
1979 if (phba->hba_state <= LPFC_LINK_DOWN) {
1980 return;
1981 }
1982 if (phba->hba_state == LPFC_CLEAR_LA)
1983 clear_la_pending = 1;
1984 else
1985 clear_la_pending = 0;
1986
1987 if (phba->hba_state < LPFC_HBA_READY) {
1988 phba->hba_state = LPFC_DISC_AUTH;
1989 }
1990 lpfc_set_disctmo(phba);
1991
1992 if (phba->fc_prevDID == phba->fc_myDID) {
1993 did_changed = 0;
1994 } else {
1995 did_changed = 1;
1996 }
1997 phba->fc_prevDID = phba->fc_myDID;
1998 phba->num_disc_nodes = 0;
1999
2000 /* Start Discovery state <hba_state> */
2001 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
2002 "%d:0202 Start Discovery hba state x%x "
2003 "Data: x%x x%x x%x\n",
2004 phba->brd_no, phba->hba_state, phba->fc_flag,
2005 phba->fc_plogi_cnt, phba->fc_adisc_cnt);
2006
2007 /* If our did changed, we MUST do PLOGI */
2008 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_npr_list,
2009 nlp_listp) {
2010 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
2011 if (did_changed) {
2012 spin_lock_irq(phba->host->host_lock);
2013 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
2014 spin_unlock_irq(phba->host->host_lock);
2015 }
2016 }
2017 }
2018
2019 /* First do ADISCs - if any */
2020 num_sent = lpfc_els_disc_adisc(phba);
2021
2022 if (num_sent)
2023 return;
2024
2025 if ((phba->hba_state < LPFC_HBA_READY) && (!clear_la_pending)) {
2026 /* If we get here, there is nothing to ADISC */
2027 if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL))) {
2028 phba->hba_state = LPFC_CLEAR_LA;
2029 lpfc_clear_la(phba, mbox);
2030 mbox->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
2031 rc = lpfc_sli_issue_mbox(phba, mbox,
2032 (MBX_NOWAIT | MBX_STOP_IOCB));
2033 if (rc == MBX_NOT_FINISHED) {
2034 mempool_free( mbox, phba->mbox_mem_pool);
2035 lpfc_disc_flush_list(phba);
2036 psli->ring[(psli->ip_ring)].flag &=
2037 ~LPFC_STOP_IOCB_EVENT;
2038 psli->ring[(psli->fcp_ring)].flag &=
2039 ~LPFC_STOP_IOCB_EVENT;
2040 psli->ring[(psli->next_ring)].flag &=
2041 ~LPFC_STOP_IOCB_EVENT;
2042 phba->hba_state = LPFC_HBA_READY;
2043 }
2044 }
2045 } else {
2046 /* Next do PLOGIs - if any */
2047 num_sent = lpfc_els_disc_plogi(phba);
2048
2049 if (num_sent)
2050 return;
2051
2052 if (phba->fc_flag & FC_RSCN_MODE) {
2053 /* Check to see if more RSCNs came in while we
2054 * were processing this one.
2055 */
2056 if ((phba->fc_rscn_id_cnt == 0) &&
2057 (!(phba->fc_flag & FC_RSCN_DISCOVERY))) {
2058 spin_lock_irq(phba->host->host_lock);
2059 phba->fc_flag &= ~FC_RSCN_MODE;
2060 spin_unlock_irq(phba->host->host_lock);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05002061 } else
dea31012005-04-17 16:05:31 -05002062 lpfc_els_handle_rscn(phba);
2063 }
2064 }
2065 return;
2066}
2067
2068/*
2069 * Ignore completion for all IOCBs on tx and txcmpl queue for ELS
2070 * ring the match the sppecified nodelist.
2071 */
2072static void
2073lpfc_free_tx(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp)
2074{
2075 struct lpfc_sli *psli;
2076 IOCB_t *icmd;
2077 struct lpfc_iocbq *iocb, *next_iocb;
2078 struct lpfc_sli_ring *pring;
2079 struct lpfc_dmabuf *mp;
2080
2081 psli = &phba->sli;
2082 pring = &psli->ring[LPFC_ELS_RING];
2083
2084 /* Error matching iocb on txq or txcmplq
2085 * First check the txq.
2086 */
2087 list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
2088 if (iocb->context1 != ndlp) {
2089 continue;
2090 }
2091 icmd = &iocb->iocb;
2092 if ((icmd->ulpCommand == CMD_ELS_REQUEST64_CR) ||
2093 (icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX)) {
2094
2095 list_del(&iocb->list);
2096 pring->txq_cnt--;
2097 lpfc_els_free_iocb(phba, iocb);
2098 }
2099 }
2100
2101 /* Next check the txcmplq */
2102 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
2103 if (iocb->context1 != ndlp) {
2104 continue;
2105 }
2106 icmd = &iocb->iocb;
2107 if ((icmd->ulpCommand == CMD_ELS_REQUEST64_CR) ||
2108 (icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX)) {
2109
2110 iocb->iocb_cmpl = NULL;
2111 /* context2 = cmd, context2->next = rsp, context3 =
2112 bpl */
2113 if (iocb->context2) {
2114 /* Free the response IOCB before handling the
2115 command. */
2116
2117 mp = (struct lpfc_dmabuf *) (iocb->context2);
2118 mp = list_get_first(&mp->list,
2119 struct lpfc_dmabuf,
2120 list);
2121 if (mp) {
2122 /* Delay before releasing rsp buffer to
2123 * give UNREG mbox a chance to take
2124 * effect.
2125 */
2126 list_add(&mp->list,
2127 &phba->freebufList);
2128 }
2129 lpfc_mbuf_free(phba,
2130 ((struct lpfc_dmabuf *)
2131 iocb->context2)->virt,
2132 ((struct lpfc_dmabuf *)
2133 iocb->context2)->phys);
2134 kfree(iocb->context2);
2135 }
2136
2137 if (iocb->context3) {
2138 lpfc_mbuf_free(phba,
2139 ((struct lpfc_dmabuf *)
2140 iocb->context3)->virt,
2141 ((struct lpfc_dmabuf *)
2142 iocb->context3)->phys);
2143 kfree(iocb->context3);
2144 }
2145 }
2146 }
2147
2148 return;
2149}
2150
2151void
2152lpfc_disc_flush_list(struct lpfc_hba * phba)
2153{
2154 struct lpfc_nodelist *ndlp, *next_ndlp;
2155
2156 if (phba->fc_plogi_cnt) {
2157 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_plogi_list,
2158 nlp_listp) {
2159 lpfc_free_tx(phba, ndlp);
2160 lpfc_nlp_remove(phba, ndlp);
2161 }
2162 }
2163 if (phba->fc_adisc_cnt) {
2164 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_adisc_list,
2165 nlp_listp) {
2166 lpfc_free_tx(phba, ndlp);
2167 lpfc_nlp_remove(phba, ndlp);
2168 }
2169 }
2170 return;
2171}
2172
2173/*****************************************************************************/
2174/*
2175 * NAME: lpfc_disc_timeout
2176 *
2177 * FUNCTION: Fibre Channel driver discovery timeout routine.
2178 *
2179 * EXECUTION ENVIRONMENT: interrupt only
2180 *
2181 * CALLED FROM:
2182 * Timer function
2183 *
2184 * RETURNS:
2185 * none
2186 */
2187/*****************************************************************************/
2188void
2189lpfc_disc_timeout(unsigned long ptr)
2190{
2191 struct lpfc_hba *phba = (struct lpfc_hba *)ptr;
2192 unsigned long flags = 0;
2193
2194 if (unlikely(!phba))
2195 return;
2196
2197 spin_lock_irqsave(phba->host->host_lock, flags);
2198 if (!(phba->work_hba_events & WORKER_DISC_TMO)) {
2199 phba->work_hba_events |= WORKER_DISC_TMO;
2200 if (phba->work_wait)
2201 wake_up(phba->work_wait);
2202 }
2203 spin_unlock_irqrestore(phba->host->host_lock, flags);
2204 return;
2205}
2206
2207static void
2208lpfc_disc_timeout_handler(struct lpfc_hba *phba)
2209{
2210 struct lpfc_sli *psli;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002211 struct lpfc_nodelist *ndlp, *next_ndlp;
dea31012005-04-17 16:05:31 -05002212 LPFC_MBOXQ_t *clearlambox, *initlinkmbox;
2213 int rc, clrlaerr = 0;
2214
2215 if (unlikely(!phba))
2216 return;
2217
2218 if (!(phba->fc_flag & FC_DISC_TMO))
2219 return;
2220
2221 psli = &phba->sli;
2222
2223 spin_lock_irq(phba->host->host_lock);
2224 phba->fc_flag &= ~FC_DISC_TMO;
2225 spin_unlock_irq(phba->host->host_lock);
2226
2227 switch (phba->hba_state) {
2228
2229 case LPFC_LOCAL_CFG_LINK:
2230 /* hba_state is identically LPFC_LOCAL_CFG_LINK while waiting for FAN */
2231 /* FAN timeout */
2232 lpfc_printf_log(phba,
2233 KERN_WARNING,
2234 LOG_DISCOVERY,
2235 "%d:0221 FAN timeout\n",
2236 phba->brd_no);
2237
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002238 /* Start discovery by sending FLOGI, clean up old rpis */
2239 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_npr_list,
2240 nlp_listp) {
2241 if (ndlp->nlp_type & NLP_FABRIC) {
2242 /* Clean up the ndlp on Fabric connections */
2243 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05002244 } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002245 /* Fail outstanding IO now since device
2246 * is marked for PLOGI.
2247 */
2248 lpfc_unreg_rpi(phba, ndlp);
2249 }
2250 }
dea31012005-04-17 16:05:31 -05002251 phba->hba_state = LPFC_FLOGI;
2252 lpfc_set_disctmo(phba);
2253 lpfc_initial_flogi(phba);
2254 break;
2255
2256 case LPFC_FLOGI:
2257 /* hba_state is identically LPFC_FLOGI while waiting for FLOGI cmpl */
2258 /* Initial FLOGI timeout */
2259 lpfc_printf_log(phba,
2260 KERN_ERR,
2261 LOG_DISCOVERY,
2262 "%d:0222 Initial FLOGI timeout\n",
2263 phba->brd_no);
2264
2265 /* Assume no Fabric and go on with discovery.
2266 * Check for outstanding ELS FLOGI to abort.
2267 */
2268
2269 /* FLOGI failed, so just use loop map to make discovery list */
2270 lpfc_disc_list_loopmap(phba);
2271
2272 /* Start discovery */
2273 lpfc_disc_start(phba);
2274 break;
2275
2276 case LPFC_FABRIC_CFG_LINK:
2277 /* hba_state is identically LPFC_FABRIC_CFG_LINK while waiting for
2278 NameServer login */
2279 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
2280 "%d:0223 Timeout while waiting for NameServer "
2281 "login\n", phba->brd_no);
2282
2283 /* Next look for NameServer ndlp */
2284 ndlp = lpfc_findnode_did(phba, NLP_SEARCH_ALL, NameServer_DID);
2285 if (ndlp)
2286 lpfc_nlp_remove(phba, ndlp);
2287 /* Start discovery */
2288 lpfc_disc_start(phba);
2289 break;
2290
2291 case LPFC_NS_QRY:
2292 /* Check for wait for NameServer Rsp timeout */
2293 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
2294 "%d:0224 NameServer Query timeout "
2295 "Data: x%x x%x\n",
2296 phba->brd_no,
2297 phba->fc_ns_retry, LPFC_MAX_NS_RETRY);
2298
2299 ndlp = lpfc_findnode_did(phba, NLP_SEARCH_UNMAPPED,
2300 NameServer_DID);
2301 if (ndlp) {
2302 if (phba->fc_ns_retry < LPFC_MAX_NS_RETRY) {
2303 /* Try it one more time */
2304 rc = lpfc_ns_cmd(phba, ndlp, SLI_CTNS_GID_FT);
2305 if (rc == 0)
2306 break;
2307 }
2308 phba->fc_ns_retry = 0;
2309 }
2310
2311 /* Nothing to authenticate, so CLEAR_LA right now */
2312 clearlambox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2313 if (!clearlambox) {
2314 clrlaerr = 1;
2315 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
2316 "%d:0226 Device Discovery "
2317 "completion error\n",
2318 phba->brd_no);
2319 phba->hba_state = LPFC_HBA_ERROR;
2320 break;
2321 }
2322
2323 phba->hba_state = LPFC_CLEAR_LA;
2324 lpfc_clear_la(phba, clearlambox);
2325 clearlambox->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
2326 rc = lpfc_sli_issue_mbox(phba, clearlambox,
2327 (MBX_NOWAIT | MBX_STOP_IOCB));
2328 if (rc == MBX_NOT_FINISHED) {
2329 mempool_free(clearlambox, phba->mbox_mem_pool);
2330 clrlaerr = 1;
2331 break;
2332 }
2333
2334 /* Setup and issue mailbox INITIALIZE LINK command */
2335 initlinkmbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2336 if (!initlinkmbox) {
2337 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
2338 "%d:0226 Device Discovery "
2339 "completion error\n",
2340 phba->brd_no);
2341 phba->hba_state = LPFC_HBA_ERROR;
2342 break;
2343 }
2344
2345 lpfc_linkdown(phba);
2346 lpfc_init_link(phba, initlinkmbox, phba->cfg_topology,
2347 phba->cfg_link_speed);
2348 initlinkmbox->mb.un.varInitLnk.lipsr_AL_PA = 0;
2349 rc = lpfc_sli_issue_mbox(phba, initlinkmbox,
2350 (MBX_NOWAIT | MBX_STOP_IOCB));
2351 if (rc == MBX_NOT_FINISHED)
2352 mempool_free(initlinkmbox, phba->mbox_mem_pool);
2353
2354 break;
2355
2356 case LPFC_DISC_AUTH:
2357 /* Node Authentication timeout */
2358 lpfc_printf_log(phba,
2359 KERN_ERR,
2360 LOG_DISCOVERY,
2361 "%d:0227 Node Authentication timeout\n",
2362 phba->brd_no);
2363 lpfc_disc_flush_list(phba);
2364 clearlambox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2365 if (!clearlambox) {
2366 clrlaerr = 1;
2367 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
2368 "%d:0226 Device Discovery "
2369 "completion error\n",
2370 phba->brd_no);
2371 phba->hba_state = LPFC_HBA_ERROR;
2372 break;
2373 }
2374 phba->hba_state = LPFC_CLEAR_LA;
2375 lpfc_clear_la(phba, clearlambox);
2376 clearlambox->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
2377 rc = lpfc_sli_issue_mbox(phba, clearlambox,
2378 (MBX_NOWAIT | MBX_STOP_IOCB));
2379 if (rc == MBX_NOT_FINISHED) {
2380 mempool_free(clearlambox, phba->mbox_mem_pool);
2381 clrlaerr = 1;
2382 }
2383 break;
2384
2385 case LPFC_CLEAR_LA:
2386 /* CLEAR LA timeout */
2387 lpfc_printf_log(phba,
2388 KERN_ERR,
2389 LOG_DISCOVERY,
2390 "%d:0228 CLEAR LA timeout\n",
2391 phba->brd_no);
2392 clrlaerr = 1;
2393 break;
2394
2395 case LPFC_HBA_READY:
2396 if (phba->fc_flag & FC_RSCN_MODE) {
2397 lpfc_printf_log(phba,
2398 KERN_ERR,
2399 LOG_DISCOVERY,
2400 "%d:0231 RSCN timeout Data: x%x x%x\n",
2401 phba->brd_no,
2402 phba->fc_ns_retry, LPFC_MAX_NS_RETRY);
2403
2404 /* Cleanup any outstanding ELS commands */
2405 lpfc_els_flush_cmd(phba);
2406
2407 lpfc_els_flush_rscn(phba);
2408 lpfc_disc_flush_list(phba);
2409 }
2410 break;
2411 }
2412
2413 if (clrlaerr) {
2414 lpfc_disc_flush_list(phba);
2415 psli->ring[(psli->ip_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
2416 psli->ring[(psli->fcp_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
2417 psli->ring[(psli->next_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
2418 phba->hba_state = LPFC_HBA_READY;
2419 }
2420
2421 return;
2422}
2423
2424static void
2425lpfc_nodev_timeout(unsigned long ptr)
2426{
2427 struct lpfc_hba *phba;
2428 struct lpfc_nodelist *ndlp;
2429 unsigned long iflag;
2430 struct lpfc_work_evt *evtp;
2431
2432 ndlp = (struct lpfc_nodelist *)ptr;
2433 phba = ndlp->nlp_phba;
2434 evtp = &ndlp->nodev_timeout_evt;
2435 spin_lock_irqsave(phba->host->host_lock, iflag);
2436
2437 if (!list_empty(&evtp->evt_listp)) {
2438 spin_unlock_irqrestore(phba->host->host_lock, iflag);
2439 return;
2440 }
2441 evtp->evt_arg1 = ndlp;
2442 evtp->evt = LPFC_EVT_NODEV_TMO;
2443 list_add_tail(&evtp->evt_listp, &phba->work_list);
2444 if (phba->work_wait)
2445 wake_up(phba->work_wait);
2446
2447 spin_unlock_irqrestore(phba->host->host_lock, iflag);
2448 return;
2449}
2450
2451
2452/*
2453 * This routine handles processing a NameServer REG_LOGIN mailbox
2454 * command upon completion. It is setup in the LPFC_MBOXQ
2455 * as the completion routine when the command is
2456 * handed off to the SLI layer.
2457 */
2458void
2459lpfc_mbx_cmpl_fdmi_reg_login(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
2460{
2461 struct lpfc_sli *psli;
2462 MAILBOX_t *mb;
2463 struct lpfc_dmabuf *mp;
2464 struct lpfc_nodelist *ndlp;
2465
2466 psli = &phba->sli;
2467 mb = &pmb->mb;
2468
2469 ndlp = (struct lpfc_nodelist *) pmb->context2;
2470 mp = (struct lpfc_dmabuf *) (pmb->context1);
2471
2472 pmb->context1 = NULL;
2473
dea31012005-04-17 16:05:31 -05002474 ndlp->nlp_rpi = mb->un.varWords[0];
dea31012005-04-17 16:05:31 -05002475 ndlp->nlp_type |= NLP_FABRIC;
2476 ndlp->nlp_state = NLP_STE_UNMAPPED_NODE;
2477 lpfc_nlp_list(phba, ndlp, NLP_UNMAPPED_LIST);
2478
2479 /* Start issuing Fabric-Device Management Interface (FDMI)
2480 * command to 0xfffffa (FDMI well known port)
2481 */
2482 if (phba->cfg_fdmi_on == 1) {
2483 lpfc_fdmi_cmd(phba, ndlp, SLI_MGMT_DHBA);
2484 } else {
2485 /*
2486 * Delay issuing FDMI command if fdmi-on=2
2487 * (supporting RPA/hostnmae)
2488 */
2489 mod_timer(&phba->fc_fdmitmo, jiffies + HZ * 60);
2490 }
2491
2492 lpfc_mbuf_free(phba, mp->virt, mp->phys);
2493 kfree(mp);
2494 mempool_free( pmb, phba->mbox_mem_pool);
2495
2496 return;
2497}
2498
2499/*
James.Smart@Emulex.Com21568f52005-10-28 20:29:36 -04002500 * This routine looks up the ndlp lists
2501 * for the given RPI. If rpi found
dea31012005-04-17 16:05:31 -05002502 * it return the node list pointer
James.Smart@Emulex.Com21568f52005-10-28 20:29:36 -04002503 * else return NULL.
dea31012005-04-17 16:05:31 -05002504 */
2505struct lpfc_nodelist *
2506lpfc_findnode_rpi(struct lpfc_hba * phba, uint16_t rpi)
2507{
James.Smart@Emulex.Com21568f52005-10-28 20:29:36 -04002508 struct lpfc_nodelist *ndlp;
2509 struct list_head * lists[]={&phba->fc_nlpunmap_list,
2510 &phba->fc_nlpmap_list,
2511 &phba->fc_plogi_list,
2512 &phba->fc_adisc_list,
2513 &phba->fc_reglogin_list};
2514 int i;
dea31012005-04-17 16:05:31 -05002515
Jamie Wellnitz66a9ed62006-02-28 22:33:10 -05002516 spin_lock_irq(phba->host->host_lock);
James.Smart@Emulex.Com21568f52005-10-28 20:29:36 -04002517 for (i = 0; i < ARRAY_SIZE(lists); i++ )
2518 list_for_each_entry(ndlp, lists[i], nlp_listp)
Jamie Wellnitz66a9ed62006-02-28 22:33:10 -05002519 if (ndlp->nlp_rpi == rpi) {
2520 spin_unlock_irq(phba->host->host_lock);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05002521 return ndlp;
Jamie Wellnitz66a9ed62006-02-28 22:33:10 -05002522 }
2523 spin_unlock_irq(phba->host->host_lock);
James.Smart@Emulex.Com21568f52005-10-28 20:29:36 -04002524 return NULL;
dea31012005-04-17 16:05:31 -05002525}
2526
James Smart488d1462006-03-07 15:02:37 -05002527/*
2528 * This routine looks up the ndlp lists
2529 * for the given WWPN. If WWPN found
2530 * it return the node list pointer
2531 * else return NULL.
2532 */
2533struct lpfc_nodelist *
2534lpfc_findnode_wwpn(struct lpfc_hba * phba, uint32_t order,
2535 struct lpfc_name * wwpn)
2536{
2537 struct lpfc_nodelist *ndlp;
2538 struct list_head * lists[]={&phba->fc_nlpunmap_list,
2539 &phba->fc_nlpmap_list,
2540 &phba->fc_npr_list,
2541 &phba->fc_plogi_list,
2542 &phba->fc_adisc_list,
2543 &phba->fc_reglogin_list,
2544 &phba->fc_prli_list};
2545 uint32_t search[]={NLP_SEARCH_UNMAPPED,
2546 NLP_SEARCH_MAPPED,
2547 NLP_SEARCH_NPR,
2548 NLP_SEARCH_PLOGI,
2549 NLP_SEARCH_ADISC,
2550 NLP_SEARCH_REGLOGIN,
2551 NLP_SEARCH_PRLI};
2552 int i;
2553
2554 spin_lock_irq(phba->host->host_lock);
2555 for (i = 0; i < ARRAY_SIZE(lists); i++ ) {
2556 if (!(order & search[i]))
2557 continue;
2558 list_for_each_entry(ndlp, lists[i], nlp_listp) {
2559 if (memcmp(&ndlp->nlp_portname, wwpn,
2560 sizeof(struct lpfc_name)) == 0) {
2561 spin_unlock_irq(phba->host->host_lock);
2562 return ndlp;
2563 }
2564 }
2565 }
2566 spin_unlock_irq(phba->host->host_lock);
2567 return NULL;
2568}
2569
dea31012005-04-17 16:05:31 -05002570void
2571lpfc_nlp_init(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp,
2572 uint32_t did)
2573{
2574 memset(ndlp, 0, sizeof (struct lpfc_nodelist));
2575 INIT_LIST_HEAD(&ndlp->nodev_timeout_evt.evt_listp);
2576 INIT_LIST_HEAD(&ndlp->els_retry_evt.evt_listp);
2577 init_timer(&ndlp->nlp_tmofunc);
2578 ndlp->nlp_tmofunc.function = lpfc_nodev_timeout;
2579 ndlp->nlp_tmofunc.data = (unsigned long)ndlp;
2580 init_timer(&ndlp->nlp_delayfunc);
2581 ndlp->nlp_delayfunc.function = lpfc_els_retry_delay;
2582 ndlp->nlp_delayfunc.data = (unsigned long)ndlp;
2583 ndlp->nlp_DID = did;
2584 ndlp->nlp_phba = phba;
2585 ndlp->nlp_sid = NLP_NO_SID;
2586 return;
2587}