blob: 164af8a7e95dc14f3e8913712a12185f7866cc2e [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
James Smartc01f3202006-08-18 17:47:08 -040059void
60lpfc_terminate_rport_io(struct fc_rport *rport)
dea31012005-04-17 16:05:31 -050061{
James Smartc01f3202006-08-18 17:47:08 -040062 struct lpfc_rport_data *rdata;
63 struct lpfc_nodelist * ndlp;
64 struct lpfc_hba *phba;
dea31012005-04-17 16:05:31 -050065
James Smartc01f3202006-08-18 17:47:08 -040066 rdata = rport->dd_data;
67 ndlp = rdata->pnode;
68
69 if (!ndlp) {
70 if (rport->roles & FC_RPORT_ROLE_FCP_TARGET)
71 printk(KERN_ERR "Cannot find remote node"
72 " to terminate I/O Data x%x\n",
73 rport->port_id);
dea31012005-04-17 16:05:31 -050074 return;
75 }
76
James Smartc01f3202006-08-18 17:47:08 -040077 phba = ndlp->nlp_phba;
James Smart1a169682006-03-07 15:04:06 -050078
James Smartc01f3202006-08-18 17:47:08 -040079 spin_lock_irq(phba->host->host_lock);
80 if (ndlp->nlp_sid != NLP_NO_SID) {
81 lpfc_sli_abort_iocb(phba, &phba->sli.ring[phba->sli.fcp_ring],
82 ndlp->nlp_sid, 0, 0, LPFC_CTX_TGT);
83 }
84 spin_unlock_irq(phba->host->host_lock);
85
86 return;
87}
88
89/*
90 * This function will be called when dev_loss_tmo fire.
91 */
92void
93lpfc_dev_loss_tmo_callbk(struct fc_rport *rport)
94{
95 struct lpfc_rport_data *rdata;
96 struct lpfc_nodelist * ndlp;
97 uint8_t *name;
98 int warn_on = 0;
99 struct lpfc_hba *phba;
100
101 rdata = rport->dd_data;
102 ndlp = rdata->pnode;
103
104 if (!ndlp) {
105 if (rport->roles & FC_RPORT_ROLE_FCP_TARGET)
106 printk(KERN_ERR "Cannot find remote node"
107 " for rport in dev_loss_tmo_callbk x%x\n",
108 rport->port_id);
109 return;
110 }
111
James Smart82085712007-04-25 09:52:41 -0400112 if (ndlp->nlp_state == NLP_STE_MAPPED_NODE)
113 return;
114
James Smartc01f3202006-08-18 17:47:08 -0400115 name = (uint8_t *)&ndlp->nlp_portname;
116 phba = ndlp->nlp_phba;
117
118 spin_lock_irq(phba->host->host_lock);
dea31012005-04-17 16:05:31 -0500119
120 if (ndlp->nlp_sid != NLP_NO_SID) {
James.Smart@Emulex.Com6e8215e2005-06-25 10:34:04 -0400121 warn_on = 1;
dea31012005-04-17 16:05:31 -0500122 /* flush the target */
123 lpfc_sli_abort_iocb(phba, &phba->sli.ring[phba->sli.fcp_ring],
124 ndlp->nlp_sid, 0, 0, LPFC_CTX_TGT);
125 }
James Smartc01f3202006-08-18 17:47:08 -0400126 if (phba->fc_flag & FC_UNLOADING)
127 warn_on = 0;
128
dea31012005-04-17 16:05:31 -0500129 spin_unlock_irq(phba->host->host_lock);
130
James.Smart@Emulex.Com6e8215e2005-06-25 10:34:04 -0400131 if (warn_on) {
132 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
James Smartc01f3202006-08-18 17:47:08 -0400133 "%d:0203 Devloss timeout on "
James Smart488d1462006-03-07 15:02:37 -0500134 "WWPN %x:%x:%x:%x:%x:%x:%x:%x "
135 "NPort x%x Data: x%x x%x x%x\n",
136 phba->brd_no,
137 *name, *(name+1), *(name+2), *(name+3),
138 *(name+4), *(name+5), *(name+6), *(name+7),
139 ndlp->nlp_DID, ndlp->nlp_flag,
James.Smart@Emulex.Com6e8215e2005-06-25 10:34:04 -0400140 ndlp->nlp_state, ndlp->nlp_rpi);
141 } else {
142 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
James Smartc01f3202006-08-18 17:47:08 -0400143 "%d:0204 Devloss timeout on "
James Smart488d1462006-03-07 15:02:37 -0500144 "WWPN %x:%x:%x:%x:%x:%x:%x:%x "
145 "NPort x%x Data: x%x x%x x%x\n",
146 phba->brd_no,
147 *name, *(name+1), *(name+2), *(name+3),
148 *(name+4), *(name+5), *(name+6), *(name+7),
149 ndlp->nlp_DID, ndlp->nlp_flag,
James.Smart@Emulex.Com6e8215e2005-06-25 10:34:04 -0400150 ndlp->nlp_state, ndlp->nlp_rpi);
151 }
152
James Smart1dcb58e2007-04-25 09:51:30 -0400153 if (!(phba->fc_flag & FC_UNLOADING) &&
154 !(ndlp->nlp_flag & NLP_DELAY_TMO) &&
James Smart82085712007-04-25 09:52:41 -0400155 !(ndlp->nlp_flag & NLP_NPR_2B_DISC) &&
156 (ndlp->nlp_state != NLP_STE_UNMAPPED_NODE))
James Smartc01f3202006-08-18 17:47:08 -0400157 lpfc_disc_state_machine(phba, ndlp, NULL, NLP_EVT_DEVICE_RM);
James Smart1dcb58e2007-04-25 09:51:30 -0400158 else {
159 rdata->pnode = NULL;
160 ndlp->rport = NULL;
161 }
James Smartc01f3202006-08-18 17:47:08 -0400162
dea31012005-04-17 16:05:31 -0500163 return;
164}
165
166static void
167lpfc_work_list_done(struct lpfc_hba * phba)
168{
169 struct lpfc_work_evt *evtp = NULL;
170 struct lpfc_nodelist *ndlp;
171 int free_evt;
172
173 spin_lock_irq(phba->host->host_lock);
174 while(!list_empty(&phba->work_list)) {
175 list_remove_head((&phba->work_list), evtp, typeof(*evtp),
176 evt_listp);
177 spin_unlock_irq(phba->host->host_lock);
178 free_evt = 1;
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500179 switch (evtp->evt) {
dea31012005-04-17 16:05:31 -0500180 case LPFC_EVT_ELS_RETRY:
181 ndlp = (struct lpfc_nodelist *)(evtp->evt_arg1);
182 lpfc_els_retry_delay_handler(ndlp);
183 free_evt = 0;
184 break;
185 case LPFC_EVT_ONLINE:
Jamie Wellnitz41415862006-02-28 19:25:27 -0500186 if (phba->hba_state < LPFC_LINK_DOWN)
187 *(int *)(evtp->evt_arg1) = lpfc_online(phba);
188 else
189 *(int *)(evtp->evt_arg1) = 0;
dea31012005-04-17 16:05:31 -0500190 complete((struct completion *)(evtp->evt_arg2));
191 break;
James Smart46fa3112007-04-25 09:51:45 -0400192 case LPFC_EVT_OFFLINE_PREP:
Jamie Wellnitz41415862006-02-28 19:25:27 -0500193 if (phba->hba_state >= LPFC_LINK_DOWN)
James Smart46fa3112007-04-25 09:51:45 -0400194 lpfc_offline_prep(phba);
195 *(int *)(evtp->evt_arg1) = 0;
196 complete((struct completion *)(evtp->evt_arg2));
197 break;
198 case LPFC_EVT_OFFLINE:
199 lpfc_offline(phba);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500200 lpfc_sli_brdrestart(phba);
201 *(int *)(evtp->evt_arg1) =
James Smart46fa3112007-04-25 09:51:45 -0400202 lpfc_sli_brdready(phba, HS_FFRDY | HS_MBRDY);
203 lpfc_unblock_mgmt_io(phba);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500204 complete((struct completion *)(evtp->evt_arg2));
205 break;
206 case LPFC_EVT_WARM_START:
James Smart46fa3112007-04-25 09:51:45 -0400207 lpfc_offline(phba);
James Smart92908312006-03-07 15:04:13 -0500208 lpfc_reset_barrier(phba);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500209 lpfc_sli_brdreset(phba);
210 lpfc_hba_down_post(phba);
211 *(int *)(evtp->evt_arg1) =
212 lpfc_sli_brdready(phba, HS_MBRDY);
James Smart46fa3112007-04-25 09:51:45 -0400213 lpfc_unblock_mgmt_io(phba);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500214 complete((struct completion *)(evtp->evt_arg2));
215 break;
216 case LPFC_EVT_KILL:
James Smart46fa3112007-04-25 09:51:45 -0400217 lpfc_offline(phba);
James Smart92908312006-03-07 15:04:13 -0500218 *(int *)(evtp->evt_arg1)
219 = (phba->stopped) ? 0 : lpfc_sli_brdkill(phba);
James Smart46fa3112007-04-25 09:51:45 -0400220 lpfc_unblock_mgmt_io(phba);
dea31012005-04-17 16:05:31 -0500221 complete((struct completion *)(evtp->evt_arg2));
222 break;
223 }
224 if (free_evt)
225 kfree(evtp);
226 spin_lock_irq(phba->host->host_lock);
227 }
228 spin_unlock_irq(phba->host->host_lock);
229
230}
231
232static void
233lpfc_work_done(struct lpfc_hba * phba)
234{
235 struct lpfc_sli_ring *pring;
236 int i;
237 uint32_t ha_copy;
238 uint32_t control;
239 uint32_t work_hba_events;
240
241 spin_lock_irq(phba->host->host_lock);
242 ha_copy = phba->work_ha;
243 phba->work_ha = 0;
244 work_hba_events=phba->work_hba_events;
245 spin_unlock_irq(phba->host->host_lock);
246
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500247 if (ha_copy & HA_ERATT)
dea31012005-04-17 16:05:31 -0500248 lpfc_handle_eratt(phba);
249
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500250 if (ha_copy & HA_MBATT)
dea31012005-04-17 16:05:31 -0500251 lpfc_sli_handle_mb_event(phba);
252
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500253 if (ha_copy & HA_LATT)
dea31012005-04-17 16:05:31 -0500254 lpfc_handle_latt(phba);
255
256 if (work_hba_events & WORKER_DISC_TMO)
257 lpfc_disc_timeout_handler(phba);
258
259 if (work_hba_events & WORKER_ELS_TMO)
260 lpfc_els_timeout_handler(phba);
261
262 if (work_hba_events & WORKER_MBOX_TMO)
263 lpfc_mbox_timeout_handler(phba);
264
265 if (work_hba_events & WORKER_FDMI_TMO)
266 lpfc_fdmi_tmo_handler(phba);
267
268 spin_lock_irq(phba->host->host_lock);
269 phba->work_hba_events &= ~work_hba_events;
270 spin_unlock_irq(phba->host->host_lock);
271
272 for (i = 0; i < phba->sli.num_rings; i++, ha_copy >>= 4) {
273 pring = &phba->sli.ring[i];
274 if ((ha_copy & HA_RXATT)
275 || (pring->flag & LPFC_DEFERRED_RING_EVENT)) {
276 if (pring->flag & LPFC_STOP_IOCB_MASK) {
277 pring->flag |= LPFC_DEFERRED_RING_EVENT;
278 } else {
279 lpfc_sli_handle_slow_ring_event(phba, pring,
280 (ha_copy &
281 HA_RXMASK));
282 pring->flag &= ~LPFC_DEFERRED_RING_EVENT;
283 }
284 /*
285 * Turn on Ring interrupts
286 */
287 spin_lock_irq(phba->host->host_lock);
288 control = readl(phba->HCregaddr);
289 control |= (HC_R0INT_ENA << i);
290 writel(control, phba->HCregaddr);
291 readl(phba->HCregaddr); /* flush */
292 spin_unlock_irq(phba->host->host_lock);
293 }
294 }
295
296 lpfc_work_list_done (phba);
297
298}
299
300static int
301check_work_wait_done(struct lpfc_hba *phba) {
302
303 spin_lock_irq(phba->host->host_lock);
304 if (phba->work_ha ||
305 phba->work_hba_events ||
306 (!list_empty(&phba->work_list)) ||
307 kthread_should_stop()) {
308 spin_unlock_irq(phba->host->host_lock);
309 return 1;
310 } else {
311 spin_unlock_irq(phba->host->host_lock);
312 return 0;
313 }
314}
315
316int
317lpfc_do_work(void *p)
318{
319 struct lpfc_hba *phba = p;
320 int rc;
Peter Zijlstra7259f0d2006-10-29 22:46:36 -0800321 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(work_waitq);
dea31012005-04-17 16:05:31 -0500322
323 set_user_nice(current, -20);
324 phba->work_wait = &work_waitq;
325
326 while (1) {
327
328 rc = wait_event_interruptible(work_waitq,
329 check_work_wait_done(phba));
330 BUG_ON(rc);
331
332 if (kthread_should_stop())
333 break;
334
335 lpfc_work_done(phba);
336
337 }
338 phba->work_wait = NULL;
339 return 0;
340}
341
342/*
343 * This is only called to handle FC worker events. Since this a rare
344 * occurance, we allocate a struct lpfc_work_evt structure here instead of
345 * embedding it in the IOCB.
346 */
347int
348lpfc_workq_post_event(struct lpfc_hba * phba, void *arg1, void *arg2,
349 uint32_t evt)
350{
351 struct lpfc_work_evt *evtp;
352
353 /*
354 * All Mailbox completions and LPFC_ELS_RING rcv ring IOCB events will
355 * be queued to worker thread for processing
356 */
357 evtp = kmalloc(sizeof(struct lpfc_work_evt), GFP_KERNEL);
358 if (!evtp)
359 return 0;
360
361 evtp->evt_arg1 = arg1;
362 evtp->evt_arg2 = arg2;
363 evtp->evt = evt;
364
dea31012005-04-17 16:05:31 -0500365 spin_lock_irq(phba->host->host_lock);
James Smart071fbd3d2006-04-15 11:53:20 -0400366 list_add_tail(&evtp->evt_listp, &phba->work_list);
dea31012005-04-17 16:05:31 -0500367 if (phba->work_wait)
368 wake_up(phba->work_wait);
369 spin_unlock_irq(phba->host->host_lock);
370
371 return 1;
372}
373
374int
375lpfc_linkdown(struct lpfc_hba * phba)
376{
377 struct lpfc_sli *psli;
378 struct lpfc_nodelist *ndlp, *next_ndlp;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500379 struct list_head *listp, *node_list[7];
dea31012005-04-17 16:05:31 -0500380 LPFC_MBOXQ_t *mb;
381 int rc, i;
382
383 psli = &phba->sli;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500384 /* sysfs or selective reset may call this routine to clean up */
Jamie Wellnitz5024ab12006-02-28 19:25:28 -0500385 if (phba->hba_state >= LPFC_LINK_DOWN) {
386 if (phba->hba_state == LPFC_LINK_DOWN)
387 return 0;
388
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500389 spin_lock_irq(phba->host->host_lock);
390 phba->hba_state = LPFC_LINK_DOWN;
391 spin_unlock_irq(phba->host->host_lock);
392 }
dea31012005-04-17 16:05:31 -0500393
James Smartd2873e42006-08-18 17:46:43 -0400394 fc_host_post_event(phba->host, fc_get_event_number(),
395 FCH_EVT_LINKDOWN, 0);
396
dea31012005-04-17 16:05:31 -0500397 /* Clean up any firmware default rpi's */
398 if ((mb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL))) {
399 lpfc_unreg_did(phba, 0xffffffff, mb);
400 mb->mbox_cmpl=lpfc_sli_def_mbox_cmpl;
401 if (lpfc_sli_issue_mbox(phba, mb, (MBX_NOWAIT | MBX_STOP_IOCB))
402 == MBX_NOT_FINISHED) {
403 mempool_free( mb, phba->mbox_mem_pool);
404 }
405 }
406
407 /* Cleanup any outstanding RSCN activity */
408 lpfc_els_flush_rscn(phba);
409
410 /* Cleanup any outstanding ELS commands */
411 lpfc_els_flush_cmd(phba);
412
413 /* Issue a LINK DOWN event to all nodes */
414 node_list[0] = &phba->fc_npr_list; /* MUST do this list first */
415 node_list[1] = &phba->fc_nlpmap_list;
416 node_list[2] = &phba->fc_nlpunmap_list;
417 node_list[3] = &phba->fc_prli_list;
418 node_list[4] = &phba->fc_reglogin_list;
419 node_list[5] = &phba->fc_adisc_list;
420 node_list[6] = &phba->fc_plogi_list;
421 for (i = 0; i < 7; i++) {
422 listp = node_list[i];
423 if (list_empty(listp))
424 continue;
425
426 list_for_each_entry_safe(ndlp, next_ndlp, listp, nlp_listp) {
dea31012005-04-17 16:05:31 -0500427
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500428 rc = lpfc_disc_state_machine(phba, ndlp, NULL,
429 NLP_EVT_DEVICE_RECOVERY);
dea31012005-04-17 16:05:31 -0500430
dea31012005-04-17 16:05:31 -0500431 }
432 }
433
434 /* free any ndlp's on unused list */
435 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_unused_list,
James Smartde0c5b32007-04-25 09:52:27 -0400436 nlp_listp)
437 lpfc_drop_node(phba, ndlp);
dea31012005-04-17 16:05:31 -0500438
439 /* Setup myDID for link up if we are in pt2pt mode */
440 if (phba->fc_flag & FC_PT2PT) {
441 phba->fc_myDID = 0;
442 if ((mb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL))) {
443 lpfc_config_link(phba, mb);
444 mb->mbox_cmpl=lpfc_sli_def_mbox_cmpl;
445 if (lpfc_sli_issue_mbox
446 (phba, mb, (MBX_NOWAIT | MBX_STOP_IOCB))
447 == MBX_NOT_FINISHED) {
448 mempool_free( mb, phba->mbox_mem_pool);
449 }
450 }
451 spin_lock_irq(phba->host->host_lock);
452 phba->fc_flag &= ~(FC_PT2PT | FC_PT2PT_PLOGI);
453 spin_unlock_irq(phba->host->host_lock);
454 }
455 spin_lock_irq(phba->host->host_lock);
456 phba->fc_flag &= ~FC_LBIT;
457 spin_unlock_irq(phba->host->host_lock);
458
459 /* Turn off discovery timer if its running */
460 lpfc_can_disctmo(phba);
461
462 /* Must process IOCBs on all rings to handle ABORTed I/Os */
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500463 return 0;
dea31012005-04-17 16:05:31 -0500464}
465
466static int
467lpfc_linkup(struct lpfc_hba * phba)
468{
469 struct lpfc_nodelist *ndlp, *next_ndlp;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500470 struct list_head *listp, *node_list[7];
471 int i;
dea31012005-04-17 16:05:31 -0500472
James Smartd2873e42006-08-18 17:46:43 -0400473 fc_host_post_event(phba->host, fc_get_event_number(),
474 FCH_EVT_LINKUP, 0);
475
dea31012005-04-17 16:05:31 -0500476 spin_lock_irq(phba->host->host_lock);
477 phba->hba_state = LPFC_LINK_UP;
478 phba->fc_flag &= ~(FC_PT2PT | FC_PT2PT_PLOGI | FC_ABORT_DISCOVERY |
479 FC_RSCN_MODE | FC_NLP_MORE | FC_RSCN_DISCOVERY);
480 phba->fc_flag |= FC_NDISC_ACTIVE;
481 phba->fc_ns_retry = 0;
482 spin_unlock_irq(phba->host->host_lock);
483
484
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500485 node_list[0] = &phba->fc_plogi_list;
486 node_list[1] = &phba->fc_adisc_list;
487 node_list[2] = &phba->fc_reglogin_list;
488 node_list[3] = &phba->fc_prli_list;
489 node_list[4] = &phba->fc_nlpunmap_list;
490 node_list[5] = &phba->fc_nlpmap_list;
491 node_list[6] = &phba->fc_npr_list;
492 for (i = 0; i < 7; i++) {
493 listp = node_list[i];
494 if (list_empty(listp))
495 continue;
496
497 list_for_each_entry_safe(ndlp, next_ndlp, listp, nlp_listp) {
498 if (phba->fc_flag & FC_LBIT) {
499 if (ndlp->nlp_type & NLP_FABRIC) {
500 /* On Linkup its safe to clean up the
501 * ndlp from Fabric connections.
502 */
James Smartde0c5b32007-04-25 09:52:27 -0400503 lpfc_nlp_set_state(phba, ndlp,
504 NLP_STE_UNUSED_NODE);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500505 } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
506 /* Fail outstanding IO now since device
507 * is marked for PLOGI.
508 */
509 lpfc_unreg_rpi(phba, ndlp);
510 }
511 }
dea31012005-04-17 16:05:31 -0500512 }
513 }
514
515 /* free any ndlp's on unused list */
516 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_unused_list,
James Smartde0c5b32007-04-25 09:52:27 -0400517 nlp_listp)
518 lpfc_drop_node(phba, ndlp);
dea31012005-04-17 16:05:31 -0500519
520 return 0;
521}
522
523/*
524 * This routine handles processing a CLEAR_LA mailbox
525 * command upon completion. It is setup in the LPFC_MBOXQ
526 * as the completion routine when the command is
527 * handed off to the SLI layer.
528 */
529void
530lpfc_mbx_cmpl_clear_la(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
531{
532 struct lpfc_sli *psli;
533 MAILBOX_t *mb;
534 uint32_t control;
535
536 psli = &phba->sli;
537 mb = &pmb->mb;
538 /* Since we don't do discovery right now, turn these off here */
James Smarta4bc3372006-12-02 13:34:16 -0500539 psli->ring[psli->extra_ring].flag &= ~LPFC_STOP_IOCB_EVENT;
dea31012005-04-17 16:05:31 -0500540 psli->ring[psli->fcp_ring].flag &= ~LPFC_STOP_IOCB_EVENT;
541 psli->ring[psli->next_ring].flag &= ~LPFC_STOP_IOCB_EVENT;
542
543 /* Check for error */
544 if ((mb->mbxStatus) && (mb->mbxStatus != 0x1601)) {
545 /* CLEAR_LA mbox error <mbxStatus> state <hba_state> */
546 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
547 "%d:0320 CLEAR_LA mbxStatus error x%x hba "
548 "state x%x\n",
549 phba->brd_no, mb->mbxStatus, phba->hba_state);
550
551 phba->hba_state = LPFC_HBA_ERROR;
552 goto out;
553 }
554
555 if (phba->fc_flag & FC_ABORT_DISCOVERY)
556 goto out;
557
558 phba->num_disc_nodes = 0;
559 /* go thru NPR list and issue ELS PLOGIs */
560 if (phba->fc_npr_cnt) {
561 lpfc_els_disc_plogi(phba);
562 }
563
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500564 if (!phba->num_disc_nodes) {
dea31012005-04-17 16:05:31 -0500565 spin_lock_irq(phba->host->host_lock);
566 phba->fc_flag &= ~FC_NDISC_ACTIVE;
567 spin_unlock_irq(phba->host->host_lock);
568 }
569
570 phba->hba_state = LPFC_HBA_READY;
571
572out:
573 /* Device Discovery completes */
574 lpfc_printf_log(phba,
575 KERN_INFO,
576 LOG_DISCOVERY,
577 "%d:0225 Device Discovery completes\n",
578 phba->brd_no);
579
580 mempool_free( pmb, phba->mbox_mem_pool);
581
582 spin_lock_irq(phba->host->host_lock);
583 phba->fc_flag &= ~FC_ABORT_DISCOVERY;
584 if (phba->fc_flag & FC_ESTABLISH_LINK) {
585 phba->fc_flag &= ~FC_ESTABLISH_LINK;
586 }
587 spin_unlock_irq(phba->host->host_lock);
588
589 del_timer_sync(&phba->fc_estabtmo);
590
591 lpfc_can_disctmo(phba);
592
593 /* turn on Link Attention interrupts */
594 spin_lock_irq(phba->host->host_lock);
595 psli->sli_flag |= LPFC_PROCESS_LA;
596 control = readl(phba->HCregaddr);
597 control |= HC_LAINT_ENA;
598 writel(control, phba->HCregaddr);
599 readl(phba->HCregaddr); /* flush */
600 spin_unlock_irq(phba->host->host_lock);
601
602 return;
603}
604
605static void
Jamie Wellnitz25594c62006-02-28 19:25:34 -0500606lpfc_mbx_cmpl_local_config_link(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea31012005-04-17 16:05:31 -0500607{
Jamie Wellnitz25594c62006-02-28 19:25:34 -0500608 struct lpfc_sli *psli = &phba->sli;
609 int rc;
dea31012005-04-17 16:05:31 -0500610
Jamie Wellnitz25594c62006-02-28 19:25:34 -0500611 if (pmb->mb.mbxStatus)
dea31012005-04-17 16:05:31 -0500612 goto out;
dea31012005-04-17 16:05:31 -0500613
Jamie Wellnitz25594c62006-02-28 19:25:34 -0500614 mempool_free(pmb, phba->mbox_mem_pool);
615
616 if (phba->fc_topology == TOPOLOGY_LOOP &&
617 phba->fc_flag & FC_PUBLIC_LOOP &&
618 !(phba->fc_flag & FC_LBIT)) {
619 /* Need to wait for FAN - use discovery timer
620 * for timeout. hba_state is identically
621 * LPFC_LOCAL_CFG_LINK while waiting for FAN
622 */
623 lpfc_set_disctmo(phba);
624 return;
dea31012005-04-17 16:05:31 -0500625 }
626
Jamie Wellnitz25594c62006-02-28 19:25:34 -0500627 /* Start discovery by sending a FLOGI. hba_state is identically
628 * LPFC_FLOGI while waiting for FLOGI cmpl
629 */
630 phba->hba_state = LPFC_FLOGI;
631 lpfc_set_disctmo(phba);
632 lpfc_initial_flogi(phba);
633 return;
dea31012005-04-17 16:05:31 -0500634
635out:
Jamie Wellnitz25594c62006-02-28 19:25:34 -0500636 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
637 "%d:0306 CONFIG_LINK mbxStatus error x%x "
638 "HBA state x%x\n",
639 phba->brd_no, pmb->mb.mbxStatus, phba->hba_state);
640
641 lpfc_linkdown(phba);
642
643 phba->hba_state = LPFC_HBA_ERROR;
644
645 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
dea31012005-04-17 16:05:31 -0500646 "%d:0200 CONFIG_LINK bad hba state x%x\n",
647 phba->brd_no, phba->hba_state);
648
Jamie Wellnitz25594c62006-02-28 19:25:34 -0500649 lpfc_clear_la(phba, pmb);
650 pmb->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
651 rc = lpfc_sli_issue_mbox(phba, pmb, (MBX_NOWAIT | MBX_STOP_IOCB));
652 if (rc == MBX_NOT_FINISHED) {
653 mempool_free(pmb, phba->mbox_mem_pool);
654 lpfc_disc_flush_list(phba);
James Smarta4bc3372006-12-02 13:34:16 -0500655 psli->ring[(psli->extra_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
Jamie Wellnitz25594c62006-02-28 19:25:34 -0500656 psli->ring[(psli->fcp_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
657 psli->ring[(psli->next_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
658 phba->hba_state = LPFC_HBA_READY;
dea31012005-04-17 16:05:31 -0500659 }
660 return;
661}
662
663static void
664lpfc_mbx_cmpl_read_sparam(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
665{
666 struct lpfc_sli *psli = &phba->sli;
667 MAILBOX_t *mb = &pmb->mb;
668 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) pmb->context1;
669
670
671 /* Check for error */
672 if (mb->mbxStatus) {
673 /* READ_SPARAM mbox error <mbxStatus> state <hba_state> */
674 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
675 "%d:0319 READ_SPARAM mbxStatus error x%x "
676 "hba state x%x>\n",
677 phba->brd_no, mb->mbxStatus, phba->hba_state);
678
679 lpfc_linkdown(phba);
680 phba->hba_state = LPFC_HBA_ERROR;
681 goto out;
682 }
683
684 memcpy((uint8_t *) & phba->fc_sparam, (uint8_t *) mp->virt,
685 sizeof (struct serv_parm));
James Smarta12e07b2006-12-02 13:35:30 -0500686 if (phba->cfg_soft_wwnn)
687 u64_to_wwn(phba->cfg_soft_wwnn, phba->fc_sparam.nodeName.u.wwn);
James Smartc3f28af2006-08-18 17:47:18 -0400688 if (phba->cfg_soft_wwpn)
689 u64_to_wwn(phba->cfg_soft_wwpn, phba->fc_sparam.portName.u.wwn);
dea31012005-04-17 16:05:31 -0500690 memcpy((uint8_t *) & phba->fc_nodename,
691 (uint8_t *) & phba->fc_sparam.nodeName,
692 sizeof (struct lpfc_name));
693 memcpy((uint8_t *) & phba->fc_portname,
694 (uint8_t *) & phba->fc_sparam.portName,
695 sizeof (struct lpfc_name));
696 lpfc_mbuf_free(phba, mp->virt, mp->phys);
697 kfree(mp);
698 mempool_free( pmb, phba->mbox_mem_pool);
699 return;
700
701out:
702 pmb->context1 = NULL;
703 lpfc_mbuf_free(phba, mp->virt, mp->phys);
704 kfree(mp);
705 if (phba->hba_state != LPFC_CLEAR_LA) {
706 lpfc_clear_la(phba, pmb);
707 pmb->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
708 if (lpfc_sli_issue_mbox(phba, pmb, (MBX_NOWAIT | MBX_STOP_IOCB))
709 == MBX_NOT_FINISHED) {
710 mempool_free( pmb, phba->mbox_mem_pool);
711 lpfc_disc_flush_list(phba);
James Smarta4bc3372006-12-02 13:34:16 -0500712 psli->ring[(psli->extra_ring)].flag &=
dea31012005-04-17 16:05:31 -0500713 ~LPFC_STOP_IOCB_EVENT;
714 psli->ring[(psli->fcp_ring)].flag &=
715 ~LPFC_STOP_IOCB_EVENT;
716 psli->ring[(psli->next_ring)].flag &=
717 ~LPFC_STOP_IOCB_EVENT;
718 phba->hba_state = LPFC_HBA_READY;
719 }
720 } else {
721 mempool_free( pmb, phba->mbox_mem_pool);
722 }
723 return;
724}
725
726static void
727lpfc_mbx_process_link_up(struct lpfc_hba *phba, READ_LA_VAR *la)
728{
729 int i;
730 LPFC_MBOXQ_t *sparam_mbox, *cfglink_mbox;
James Smart14691152006-12-02 13:34:28 -0500731 struct lpfc_dmabuf *mp;
732 int rc;
733
dea31012005-04-17 16:05:31 -0500734 sparam_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
735 cfglink_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
736
737 spin_lock_irq(phba->host->host_lock);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500738 switch (la->UlnkSpeed) {
dea31012005-04-17 16:05:31 -0500739 case LA_1GHZ_LINK:
740 phba->fc_linkspeed = LA_1GHZ_LINK;
741 break;
742 case LA_2GHZ_LINK:
743 phba->fc_linkspeed = LA_2GHZ_LINK;
744 break;
745 case LA_4GHZ_LINK:
746 phba->fc_linkspeed = LA_4GHZ_LINK;
747 break;
748 default:
749 phba->fc_linkspeed = LA_UNKNW_LINK;
750 break;
751 }
752
753 phba->fc_topology = la->topology;
754
755 if (phba->fc_topology == TOPOLOGY_LOOP) {
756 /* Get Loop Map information */
757
758 if (la->il)
759 phba->fc_flag |= FC_LBIT;
760
761 phba->fc_myDID = la->granted_AL_PA;
762 i = la->un.lilpBde64.tus.f.bdeSize;
763
764 if (i == 0) {
765 phba->alpa_map[0] = 0;
766 } else {
767 if (phba->cfg_log_verbose & LOG_LINK_EVENT) {
768 int numalpa, j, k;
769 union {
770 uint8_t pamap[16];
771 struct {
772 uint32_t wd1;
773 uint32_t wd2;
774 uint32_t wd3;
775 uint32_t wd4;
776 } pa;
777 } un;
778 numalpa = phba->alpa_map[0];
779 j = 0;
780 while (j < numalpa) {
781 memset(un.pamap, 0, 16);
782 for (k = 1; j < numalpa; k++) {
783 un.pamap[k - 1] =
784 phba->alpa_map[j + 1];
785 j++;
786 if (k == 16)
787 break;
788 }
789 /* Link Up Event ALPA map */
790 lpfc_printf_log(phba,
791 KERN_WARNING,
792 LOG_LINK_EVENT,
793 "%d:1304 Link Up Event "
794 "ALPA map Data: x%x "
795 "x%x x%x x%x\n",
796 phba->brd_no,
797 un.pa.wd1, un.pa.wd2,
798 un.pa.wd3, un.pa.wd4);
799 }
800 }
801 }
802 } else {
803 phba->fc_myDID = phba->fc_pref_DID;
804 phba->fc_flag |= FC_LBIT;
805 }
806 spin_unlock_irq(phba->host->host_lock);
807
808 lpfc_linkup(phba);
809 if (sparam_mbox) {
810 lpfc_read_sparam(phba, sparam_mbox);
811 sparam_mbox->mbox_cmpl = lpfc_mbx_cmpl_read_sparam;
James Smart14691152006-12-02 13:34:28 -0500812 rc = lpfc_sli_issue_mbox(phba, sparam_mbox,
dea31012005-04-17 16:05:31 -0500813 (MBX_NOWAIT | MBX_STOP_IOCB));
James Smart14691152006-12-02 13:34:28 -0500814 if (rc == MBX_NOT_FINISHED) {
815 mp = (struct lpfc_dmabuf *) sparam_mbox->context1;
816 lpfc_mbuf_free(phba, mp->virt, mp->phys);
817 kfree(mp);
818 mempool_free(sparam_mbox, phba->mbox_mem_pool);
819 if (cfglink_mbox)
820 mempool_free(cfglink_mbox, phba->mbox_mem_pool);
821 return;
822 }
dea31012005-04-17 16:05:31 -0500823 }
824
825 if (cfglink_mbox) {
826 phba->hba_state = LPFC_LOCAL_CFG_LINK;
827 lpfc_config_link(phba, cfglink_mbox);
Jamie Wellnitz25594c62006-02-28 19:25:34 -0500828 cfglink_mbox->mbox_cmpl = lpfc_mbx_cmpl_local_config_link;
James Smart14691152006-12-02 13:34:28 -0500829 rc = lpfc_sli_issue_mbox(phba, cfglink_mbox,
dea31012005-04-17 16:05:31 -0500830 (MBX_NOWAIT | MBX_STOP_IOCB));
James Smart14691152006-12-02 13:34:28 -0500831 if (rc == MBX_NOT_FINISHED)
832 mempool_free(cfglink_mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500833 }
834}
835
836static void
837lpfc_mbx_issue_link_down(struct lpfc_hba *phba) {
838 uint32_t control;
839 struct lpfc_sli *psli = &phba->sli;
840
841 lpfc_linkdown(phba);
842
843 /* turn on Link Attention interrupts - no CLEAR_LA needed */
844 spin_lock_irq(phba->host->host_lock);
845 psli->sli_flag |= LPFC_PROCESS_LA;
846 control = readl(phba->HCregaddr);
847 control |= HC_LAINT_ENA;
848 writel(control, phba->HCregaddr);
849 readl(phba->HCregaddr); /* flush */
850 spin_unlock_irq(phba->host->host_lock);
851}
852
853/*
854 * This routine handles processing a READ_LA mailbox
855 * command upon completion. It is setup in the LPFC_MBOXQ
856 * as the completion routine when the command is
857 * handed off to the SLI layer.
858 */
859void
860lpfc_mbx_cmpl_read_la(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
861{
862 READ_LA_VAR *la;
863 MAILBOX_t *mb = &pmb->mb;
864 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
865
866 /* Check for error */
867 if (mb->mbxStatus) {
868 lpfc_printf_log(phba,
869 KERN_INFO,
870 LOG_LINK_EVENT,
871 "%d:1307 READ_LA mbox error x%x state x%x\n",
872 phba->brd_no,
873 mb->mbxStatus, phba->hba_state);
874 lpfc_mbx_issue_link_down(phba);
875 phba->hba_state = LPFC_HBA_ERROR;
876 goto lpfc_mbx_cmpl_read_la_free_mbuf;
877 }
878
879 la = (READ_LA_VAR *) & pmb->mb.un.varReadLA;
880
881 memcpy(&phba->alpa_map[0], mp->virt, 128);
882
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500883 spin_lock_irq(phba->host->host_lock);
884 if (la->pb)
885 phba->fc_flag |= FC_BYPASSED_MODE;
886 else
887 phba->fc_flag &= ~FC_BYPASSED_MODE;
888 spin_unlock_irq(phba->host->host_lock);
889
dea31012005-04-17 16:05:31 -0500890 if (((phba->fc_eventTag + 1) < la->eventTag) ||
891 (phba->fc_eventTag == la->eventTag)) {
892 phba->fc_stat.LinkMultiEvent++;
893 if (la->attType == AT_LINK_UP) {
894 if (phba->fc_eventTag != 0)
895 lpfc_linkdown(phba);
896 }
897 }
898
899 phba->fc_eventTag = la->eventTag;
900
901 if (la->attType == AT_LINK_UP) {
902 phba->fc_stat.LinkUp++;
James Smart5b8bd0c2007-04-25 09:52:49 -0400903 if (phba->fc_flag & FC_LOOPBACK_MODE) {
904 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
905 "%d:1306 Link Up Event in loop back mode "
906 "x%x received Data: x%x x%x x%x x%x\n",
907 phba->brd_no, la->eventTag, phba->fc_eventTag,
908 la->granted_AL_PA, la->UlnkSpeed,
909 phba->alpa_map[0]);
910 } else {
911 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
dea31012005-04-17 16:05:31 -0500912 "%d:1303 Link Up Event x%x received "
913 "Data: x%x x%x x%x x%x\n",
914 phba->brd_no, la->eventTag, phba->fc_eventTag,
915 la->granted_AL_PA, la->UlnkSpeed,
916 phba->alpa_map[0]);
James Smart5b8bd0c2007-04-25 09:52:49 -0400917 }
dea31012005-04-17 16:05:31 -0500918 lpfc_mbx_process_link_up(phba, la);
919 } else {
920 phba->fc_stat.LinkDown++;
921 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
922 "%d:1305 Link Down Event x%x received "
923 "Data: x%x x%x x%x\n",
924 phba->brd_no, la->eventTag, phba->fc_eventTag,
925 phba->hba_state, phba->fc_flag);
926 lpfc_mbx_issue_link_down(phba);
927 }
928
929lpfc_mbx_cmpl_read_la_free_mbuf:
930 lpfc_mbuf_free(phba, mp->virt, mp->phys);
931 kfree(mp);
932 mempool_free(pmb, phba->mbox_mem_pool);
933 return;
934}
935
936/*
937 * This routine handles processing a REG_LOGIN mailbox
938 * command upon completion. It is setup in the LPFC_MBOXQ
939 * as the completion routine when the command is
940 * handed off to the SLI layer.
941 */
942void
943lpfc_mbx_cmpl_reg_login(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
944{
945 struct lpfc_sli *psli;
946 MAILBOX_t *mb;
947 struct lpfc_dmabuf *mp;
948 struct lpfc_nodelist *ndlp;
949
950 psli = &phba->sli;
951 mb = &pmb->mb;
952
953 ndlp = (struct lpfc_nodelist *) pmb->context2;
954 mp = (struct lpfc_dmabuf *) (pmb->context1);
955
956 pmb->context1 = NULL;
957
958 /* Good status, call state machine */
959 lpfc_disc_state_machine(phba, ndlp, pmb, NLP_EVT_CMPL_REG_LOGIN);
960 lpfc_mbuf_free(phba, mp->virt, mp->phys);
961 kfree(mp);
962 mempool_free( pmb, phba->mbox_mem_pool);
963
964 return;
965}
966
967/*
968 * This routine handles processing a Fabric REG_LOGIN mailbox
969 * command upon completion. It is setup in the LPFC_MBOXQ
970 * as the completion routine when the command is
971 * handed off to the SLI layer.
972 */
973void
974lpfc_mbx_cmpl_fabric_reg_login(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
975{
976 struct lpfc_sli *psli;
977 MAILBOX_t *mb;
978 struct lpfc_dmabuf *mp;
979 struct lpfc_nodelist *ndlp;
980 struct lpfc_nodelist *ndlp_fdmi;
981
982
983 psli = &phba->sli;
984 mb = &pmb->mb;
985
986 ndlp = (struct lpfc_nodelist *) pmb->context2;
987 mp = (struct lpfc_dmabuf *) (pmb->context1);
988
989 if (mb->mbxStatus) {
990 lpfc_mbuf_free(phba, mp->virt, mp->phys);
991 kfree(mp);
992 mempool_free( pmb, phba->mbox_mem_pool);
993 mempool_free( ndlp, phba->nlp_mem_pool);
994
995 /* FLOGI failed, so just use loop map to make discovery list */
996 lpfc_disc_list_loopmap(phba);
997
998 /* Start discovery */
999 lpfc_disc_start(phba);
1000 return;
1001 }
1002
1003 pmb->context1 = NULL;
1004
dea31012005-04-17 16:05:31 -05001005 ndlp->nlp_rpi = mb->un.varWords[0];
dea31012005-04-17 16:05:31 -05001006 ndlp->nlp_type |= NLP_FABRIC;
James Smartde0c5b32007-04-25 09:52:27 -04001007 lpfc_nlp_set_state(phba, ndlp, NLP_STE_UNMAPPED_NODE);
dea31012005-04-17 16:05:31 -05001008
1009 if (phba->hba_state == LPFC_FABRIC_CFG_LINK) {
1010 /* This NPort has been assigned an NPort_ID by the fabric as a
1011 * result of the completed fabric login. Issue a State Change
1012 * Registration (SCR) ELS request to the fabric controller
1013 * (SCR_DID) so that this NPort gets RSCN events from the
1014 * fabric.
1015 */
1016 lpfc_issue_els_scr(phba, SCR_DID, 0);
1017
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001018 ndlp = lpfc_findnode_did(phba, NLP_SEARCH_ALL, NameServer_DID);
1019 if (!ndlp) {
1020 /* Allocate a new node instance. If the pool is empty,
1021 * start the discovery process and skip the Nameserver
1022 * login process. This is attempted again later on.
1023 * Otherwise, issue a Port Login (PLOGI) to NameServer.
1024 */
1025 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_ATOMIC);
1026 if (!ndlp) {
1027 lpfc_disc_start(phba);
1028 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1029 kfree(mp);
1030 mempool_free( pmb, phba->mbox_mem_pool);
1031 return;
1032 } else {
1033 lpfc_nlp_init(phba, ndlp, NameServer_DID);
1034 ndlp->nlp_type |= NLP_FABRIC;
1035 }
1036 }
James Smartde0c5b32007-04-25 09:52:27 -04001037 lpfc_nlp_set_state(phba, ndlp, NLP_STE_PLOGI_ISSUE);
James Smart488d1462006-03-07 15:02:37 -05001038 lpfc_issue_els_plogi(phba, NameServer_DID, 0);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001039 if (phba->cfg_fdmi_on) {
1040 ndlp_fdmi = mempool_alloc(phba->nlp_mem_pool,
1041 GFP_KERNEL);
1042 if (ndlp_fdmi) {
1043 lpfc_nlp_init(phba, ndlp_fdmi, FDMI_DID);
1044 ndlp_fdmi->nlp_type |= NLP_FABRIC;
1045 ndlp_fdmi->nlp_state = NLP_STE_PLOGI_ISSUE;
James Smart488d1462006-03-07 15:02:37 -05001046 lpfc_issue_els_plogi(phba, FDMI_DID, 0);
dea31012005-04-17 16:05:31 -05001047 }
1048 }
1049 }
1050
1051 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1052 kfree(mp);
1053 mempool_free( pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05001054 return;
1055}
1056
1057/*
1058 * This routine handles processing a NameServer REG_LOGIN mailbox
1059 * command upon completion. It is setup in the LPFC_MBOXQ
1060 * as the completion routine when the command is
1061 * handed off to the SLI layer.
1062 */
1063void
1064lpfc_mbx_cmpl_ns_reg_login(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
1065{
1066 struct lpfc_sli *psli;
1067 MAILBOX_t *mb;
1068 struct lpfc_dmabuf *mp;
1069 struct lpfc_nodelist *ndlp;
1070
1071 psli = &phba->sli;
1072 mb = &pmb->mb;
1073
1074 ndlp = (struct lpfc_nodelist *) pmb->context2;
1075 mp = (struct lpfc_dmabuf *) (pmb->context1);
1076
1077 if (mb->mbxStatus) {
1078 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1079 kfree(mp);
James Smartde0c5b32007-04-25 09:52:27 -04001080 mempool_free(pmb, phba->mbox_mem_pool);
1081 lpfc_drop_node(phba, ndlp);
dea31012005-04-17 16:05:31 -05001082
1083 /* RegLogin failed, so just use loop map to make discovery
1084 list */
1085 lpfc_disc_list_loopmap(phba);
1086
1087 /* Start discovery */
1088 lpfc_disc_start(phba);
1089 return;
1090 }
1091
1092 pmb->context1 = NULL;
1093
dea31012005-04-17 16:05:31 -05001094 ndlp->nlp_rpi = mb->un.varWords[0];
dea31012005-04-17 16:05:31 -05001095 ndlp->nlp_type |= NLP_FABRIC;
James Smartde0c5b32007-04-25 09:52:27 -04001096 lpfc_nlp_set_state(phba, ndlp, NLP_STE_UNMAPPED_NODE);
dea31012005-04-17 16:05:31 -05001097
1098 if (phba->hba_state < LPFC_HBA_READY) {
1099 /* Link up discovery requires Fabrib registration. */
1100 lpfc_ns_cmd(phba, ndlp, SLI_CTNS_RNN_ID);
1101 lpfc_ns_cmd(phba, ndlp, SLI_CTNS_RSNN_NN);
1102 lpfc_ns_cmd(phba, ndlp, SLI_CTNS_RFT_ID);
James Smart2fb9bd82006-12-02 13:33:57 -05001103 lpfc_ns_cmd(phba, ndlp, SLI_CTNS_RFF_ID);
dea31012005-04-17 16:05:31 -05001104 }
1105
1106 phba->fc_ns_retry = 0;
1107 /* Good status, issue CT Request to NameServer */
1108 if (lpfc_ns_cmd(phba, ndlp, SLI_CTNS_GID_FT)) {
1109 /* Cannot issue NameServer Query, so finish up discovery */
1110 lpfc_disc_start(phba);
1111 }
1112
1113 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1114 kfree(mp);
1115 mempool_free( pmb, phba->mbox_mem_pool);
1116
1117 return;
1118}
1119
1120static void
1121lpfc_register_remote_port(struct lpfc_hba * phba,
1122 struct lpfc_nodelist * ndlp)
1123{
1124 struct fc_rport *rport;
1125 struct lpfc_rport_data *rdata;
1126 struct fc_rport_identifiers rport_ids;
dea31012005-04-17 16:05:31 -05001127
1128 /* Remote port has reappeared. Re-register w/ FC transport */
Andrew Morton68ce1eb2005-09-21 09:46:54 -07001129 rport_ids.node_name = wwn_to_u64(ndlp->nlp_nodename.u.wwn);
1130 rport_ids.port_name = wwn_to_u64(ndlp->nlp_portname.u.wwn);
dea31012005-04-17 16:05:31 -05001131 rport_ids.port_id = ndlp->nlp_DID;
1132 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
dea31012005-04-17 16:05:31 -05001133
1134 ndlp->rport = rport = fc_remote_port_add(phba->host, 0, &rport_ids);
1135 if (!rport) {
1136 dev_printk(KERN_WARNING, &phba->pcidev->dev,
1137 "Warning: fc_remote_port_add failed\n");
1138 return;
1139 }
1140
1141 /* initialize static port data */
1142 rport->maxframe_size = ndlp->nlp_maxframe;
1143 rport->supported_classes = ndlp->nlp_class_sup;
dea31012005-04-17 16:05:31 -05001144 rdata = rport->dd_data;
1145 rdata->pnode = ndlp;
James.Smart@Emulex.Com23dc04f2005-11-28 11:41:44 -05001146
1147 if (ndlp->nlp_type & NLP_FCP_TARGET)
1148 rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
1149 if (ndlp->nlp_type & NLP_FCP_INITIATOR)
1150 rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
1151
1152
1153 if (rport_ids.roles != FC_RPORT_ROLE_UNKNOWN)
1154 fc_remote_port_rolechg(rport, rport_ids.roles);
1155
James Smart071fbd3d2006-04-15 11:53:20 -04001156 if ((rport->scsi_target_id != -1) &&
James Smarte17da182006-07-06 15:49:25 -04001157 (rport->scsi_target_id < LPFC_MAX_TARGET)) {
James Smart071fbd3d2006-04-15 11:53:20 -04001158 ndlp->nlp_sid = rport->scsi_target_id;
1159 }
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001160
1161 return;
1162}
1163
1164static void
1165lpfc_unregister_remote_port(struct lpfc_hba * phba,
1166 struct lpfc_nodelist * ndlp)
1167{
1168 struct fc_rport *rport = ndlp->rport;
1169 struct lpfc_rport_data *rdata = rport->dd_data;
1170
James Smartc01f3202006-08-18 17:47:08 -04001171 if (rport->scsi_target_id == -1) {
1172 ndlp->rport = NULL;
1173 rdata->pnode = NULL;
1174 }
1175
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001176 fc_remote_port_delete(rport);
dea31012005-04-17 16:05:31 -05001177
1178 return;
1179}
1180
James Smartde0c5b32007-04-25 09:52:27 -04001181static void
1182lpfc_nlp_counters(struct lpfc_hba *phba, int state, int count)
1183{
1184 switch (state) {
1185 case NLP_STE_UNUSED_NODE:
1186 phba->fc_unused_cnt += count;
1187 break;
1188 case NLP_STE_PLOGI_ISSUE:
1189 phba->fc_plogi_cnt += count;
1190 break;
1191 case NLP_STE_ADISC_ISSUE:
1192 phba->fc_adisc_cnt += count;
1193 break;
1194 case NLP_STE_REG_LOGIN_ISSUE:
1195 phba->fc_reglogin_cnt += count;
1196 break;
1197 case NLP_STE_PRLI_ISSUE:
1198 phba->fc_prli_cnt += count;
1199 break;
1200 case NLP_STE_UNMAPPED_NODE:
1201 phba->fc_unmap_cnt += count;
1202 break;
1203 case NLP_STE_MAPPED_NODE:
1204 phba->fc_map_cnt += count;
1205 break;
1206 case NLP_STE_NPR_NODE:
1207 phba->fc_npr_cnt += count;
1208 break;
1209 }
1210}
1211
1212void
1213lpfc_delink_node(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
1214{
1215 switch (ndlp->nlp_flag & NLP_LIST_MASK) {
1216 case NLP_UNUSED_LIST:
1217 list_del_init(&ndlp->nlp_listp);
1218 break;
1219 case NLP_PLOGI_LIST:
1220 list_del_init(&ndlp->nlp_listp);
1221 break;
1222 case NLP_ADISC_LIST:
1223 list_del_init(&ndlp->nlp_listp);
1224 break;
1225 case NLP_REGLOGIN_LIST:
1226 list_del_init(&ndlp->nlp_listp);
1227 break;
1228 case NLP_PRLI_LIST:
1229 list_del_init(&ndlp->nlp_listp);
1230 break;
1231 case NLP_UNMAPPED_LIST:
1232 list_del_init(&ndlp->nlp_listp);
1233 break;
1234 case NLP_MAPPED_LIST:
1235 list_del_init(&ndlp->nlp_listp);
1236 break;
1237 case NLP_NPR_LIST:
1238 list_del_init(&ndlp->nlp_listp);
1239 break;
1240 }
1241
1242 ndlp->nlp_flag &= ~NLP_LIST_MASK;
1243}
1244
1245static int
dea31012005-04-17 16:05:31 -05001246lpfc_nlp_list(struct lpfc_hba * phba, struct lpfc_nodelist * nlp, int list)
1247{
dea31012005-04-17 16:05:31 -05001248 struct lpfc_sli *psli;
1249
1250 psli = &phba->sli;
1251 /* Sanity check to ensure we are not moving to / from the same list */
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05001252 if ((nlp->nlp_flag & NLP_LIST_MASK) == list)
James Smartde0c5b32007-04-25 09:52:27 -04001253 return 0;
dea31012005-04-17 16:05:31 -05001254
Jamie Wellnitz66a9ed62006-02-28 22:33:10 -05001255 spin_lock_irq(phba->host->host_lock);
James Smartde0c5b32007-04-25 09:52:27 -04001256 lpfc_delink_node(phba, nlp);
dea31012005-04-17 16:05:31 -05001257
1258 /* Add NPort <did> to <num> list */
1259 lpfc_printf_log(phba,
1260 KERN_INFO,
1261 LOG_NODE,
1262 "%d:0904 Add NPort x%x to %d list Data: x%x\n",
1263 phba->brd_no,
1264 nlp->nlp_DID, list, nlp->nlp_flag);
1265
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05001266 switch (list) {
dea31012005-04-17 16:05:31 -05001267 case NLP_UNUSED_LIST:
dea31012005-04-17 16:05:31 -05001268 nlp->nlp_flag |= list;
dea31012005-04-17 16:05:31 -05001269 /* Put it at the end of the unused list */
1270 list_add_tail(&nlp->nlp_listp, &phba->fc_unused_list);
dea31012005-04-17 16:05:31 -05001271 break;
1272 case NLP_PLOGI_LIST:
dea31012005-04-17 16:05:31 -05001273 nlp->nlp_flag |= list;
dea31012005-04-17 16:05:31 -05001274 /* Put it at the end of the plogi list */
1275 list_add_tail(&nlp->nlp_listp, &phba->fc_plogi_list);
dea31012005-04-17 16:05:31 -05001276 break;
1277 case NLP_ADISC_LIST:
dea31012005-04-17 16:05:31 -05001278 nlp->nlp_flag |= list;
dea31012005-04-17 16:05:31 -05001279 /* Put it at the end of the adisc list */
1280 list_add_tail(&nlp->nlp_listp, &phba->fc_adisc_list);
dea31012005-04-17 16:05:31 -05001281 break;
1282 case NLP_REGLOGIN_LIST:
dea31012005-04-17 16:05:31 -05001283 nlp->nlp_flag |= list;
dea31012005-04-17 16:05:31 -05001284 /* Put it at the end of the reglogin list */
1285 list_add_tail(&nlp->nlp_listp, &phba->fc_reglogin_list);
dea31012005-04-17 16:05:31 -05001286 break;
1287 case NLP_PRLI_LIST:
dea31012005-04-17 16:05:31 -05001288 nlp->nlp_flag |= list;
dea31012005-04-17 16:05:31 -05001289 /* Put it at the end of the prli list */
1290 list_add_tail(&nlp->nlp_listp, &phba->fc_prli_list);
dea31012005-04-17 16:05:31 -05001291 break;
1292 case NLP_UNMAPPED_LIST:
dea31012005-04-17 16:05:31 -05001293 nlp->nlp_flag |= list;
dea31012005-04-17 16:05:31 -05001294 /* Put it at the end of the unmap list */
1295 list_add_tail(&nlp->nlp_listp, &phba->fc_nlpunmap_list);
dea31012005-04-17 16:05:31 -05001296 break;
1297 case NLP_MAPPED_LIST:
dea31012005-04-17 16:05:31 -05001298 nlp->nlp_flag |= list;
dea31012005-04-17 16:05:31 -05001299 /* Put it at the end of the map list */
1300 list_add_tail(&nlp->nlp_listp, &phba->fc_nlpmap_list);
dea31012005-04-17 16:05:31 -05001301 break;
1302 case NLP_NPR_LIST:
dea31012005-04-17 16:05:31 -05001303 nlp->nlp_flag |= list;
dea31012005-04-17 16:05:31 -05001304 /* Put it at the end of the npr list */
1305 list_add_tail(&nlp->nlp_listp, &phba->fc_npr_list);
dea31012005-04-17 16:05:31 -05001306 break;
1307 }
1308
Jamie Wellnitz66a9ed62006-02-28 22:33:10 -05001309 spin_unlock_irq(phba->host->host_lock);
James Smartde0c5b32007-04-25 09:52:27 -04001310 return 0;
1311}
Jamie Wellnitz66a9ed62006-02-28 22:33:10 -05001312
James Smartde0c5b32007-04-25 09:52:27 -04001313static void
1314lpfc_nlp_state_cleanup(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp,
1315 int old_state, int new_state)
1316{
1317 if (new_state == NLP_STE_UNMAPPED_NODE) {
1318 ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
1319 ndlp->nlp_flag &= ~NLP_NODEV_REMOVE;
1320 ndlp->nlp_type |= NLP_FC_NODE;
1321 }
1322 if (new_state == NLP_STE_MAPPED_NODE)
1323 ndlp->nlp_flag &= ~NLP_NODEV_REMOVE;
1324 if (new_state == NLP_STE_NPR_NODE)
1325 ndlp->nlp_flag &= ~NLP_RCV_PLOGI;
dea31012005-04-17 16:05:31 -05001326
James Smartde0c5b32007-04-25 09:52:27 -04001327 /* Transport interface */
1328 if (ndlp->rport && (old_state == NLP_STE_MAPPED_NODE ||
1329 old_state == NLP_STE_UNMAPPED_NODE)) {
1330 phba->nport_event_cnt++;
1331 lpfc_unregister_remote_port(phba, ndlp);
1332 }
dea31012005-04-17 16:05:31 -05001333
James Smartde0c5b32007-04-25 09:52:27 -04001334 if (new_state == NLP_STE_MAPPED_NODE ||
1335 new_state == NLP_STE_UNMAPPED_NODE) {
1336 phba->nport_event_cnt++;
dea31012005-04-17 16:05:31 -05001337 /*
1338 * Tell the fc transport about the port, if we haven't
1339 * already. If we have, and it's a scsi entity, be
1340 * sure to unblock any attached scsi devices
1341 */
James Smartde0c5b32007-04-25 09:52:27 -04001342 lpfc_register_remote_port(phba, ndlp);
1343 }
dea31012005-04-17 16:05:31 -05001344
1345 /*
1346 * if we added to Mapped list, but the remote port
1347 * registration failed or assigned a target id outside
1348 * our presentable range - move the node to the
1349 * Unmapped List
1350 */
James Smartde0c5b32007-04-25 09:52:27 -04001351 if (new_state == NLP_STE_MAPPED_NODE &&
1352 (!ndlp->rport ||
1353 ndlp->rport->scsi_target_id == -1 ||
1354 ndlp->rport->scsi_target_id >= LPFC_MAX_TARGET)) {
1355 spin_lock_irq(phba->host->host_lock);
1356 ndlp->nlp_flag |= NLP_TGT_NO_SCSIID;
1357 spin_unlock_irq(phba->host->host_lock);
1358 lpfc_nlp_set_state(phba, ndlp, NLP_STE_UNMAPPED_NODE);
dea31012005-04-17 16:05:31 -05001359 }
James Smartde0c5b32007-04-25 09:52:27 -04001360}
1361
1362void
1363lpfc_nlp_set_state(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp, int state)
1364{
1365 int old_state = ndlp->nlp_state;
1366 static int list_id[] = {
1367 [NLP_STE_UNUSED_NODE] = NLP_UNUSED_LIST,
1368 [NLP_STE_PLOGI_ISSUE] = NLP_PLOGI_LIST,
1369 [NLP_STE_ADISC_ISSUE] = NLP_ADISC_LIST,
1370 [NLP_STE_REG_LOGIN_ISSUE] = NLP_REGLOGIN_LIST,
1371 [NLP_STE_PRLI_ISSUE] = NLP_PRLI_LIST,
1372 [NLP_STE_UNMAPPED_NODE] = NLP_UNMAPPED_LIST,
1373 [NLP_STE_MAPPED_NODE] = NLP_MAPPED_LIST,
1374 [NLP_STE_NPR_NODE] = NLP_NPR_LIST,
1375 };
1376
1377 if (old_state == NLP_STE_NPR_NODE &&
1378 (ndlp->nlp_flag & NLP_DELAY_TMO) != 0 &&
1379 state != NLP_STE_NPR_NODE)
1380 lpfc_cancel_retry_delay_tmo(phba, ndlp);
1381 if (old_state == NLP_STE_UNMAPPED_NODE) {
1382 ndlp->nlp_flag &= ~NLP_TGT_NO_SCSIID;
1383 ndlp->nlp_type &= ~NLP_FC_NODE;
1384 }
1385
1386 if (old_state && !list_empty(&ndlp->nlp_listp))
1387 lpfc_nlp_counters(phba, old_state, -1);
1388
1389 ndlp->nlp_state = state;
1390 lpfc_nlp_list(phba, ndlp, list_id[state]);
1391 lpfc_nlp_counters(phba, state, 1);
1392
1393 lpfc_nlp_state_cleanup(phba, ndlp, old_state, state);
1394}
1395
1396void
1397lpfc_dequeue_node(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
1398{
1399 if ((ndlp->nlp_flag & NLP_DELAY_TMO) != 0)
1400 lpfc_cancel_retry_delay_tmo(phba, ndlp);
1401 spin_lock_irq(phba->host->host_lock);
1402 if (ndlp->nlp_state && !list_empty(&ndlp->nlp_listp))
1403 lpfc_nlp_counters(phba, ndlp->nlp_state, -1);
1404 lpfc_delink_node(phba, ndlp);
1405 spin_unlock_irq(phba->host->host_lock);
1406 lpfc_nlp_state_cleanup(phba, ndlp, ndlp->nlp_state, 0);
1407}
1408
1409void
1410lpfc_drop_node(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
1411{
1412 if ((ndlp->nlp_flag & NLP_DELAY_TMO) != 0)
1413 lpfc_cancel_retry_delay_tmo(phba, ndlp);
1414 spin_lock_irq(phba->host->host_lock);
1415 if (ndlp->nlp_state && !list_empty(&ndlp->nlp_listp))
1416 lpfc_nlp_counters(phba, ndlp->nlp_state, -1);
1417 lpfc_delink_node(phba, ndlp);
1418 spin_unlock_irq(phba->host->host_lock);
1419 lpfc_nlp_remove(phba, ndlp);
dea31012005-04-17 16:05:31 -05001420}
1421
1422/*
1423 * Start / ReStart rescue timer for Discovery / RSCN handling
1424 */
1425void
1426lpfc_set_disctmo(struct lpfc_hba * phba)
1427{
1428 uint32_t tmo;
1429
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001430 if (phba->hba_state == LPFC_LOCAL_CFG_LINK) {
1431 /* For FAN, timeout should be greater then edtov */
1432 tmo = (((phba->fc_edtov + 999) / 1000) + 1);
1433 } else {
1434 /* Normal discovery timeout should be > then ELS/CT timeout
1435 * FC spec states we need 3 * ratov for CT requests
1436 */
1437 tmo = ((phba->fc_ratov * 3) + 3);
1438 }
dea31012005-04-17 16:05:31 -05001439
1440 mod_timer(&phba->fc_disctmo, jiffies + HZ * tmo);
1441 spin_lock_irq(phba->host->host_lock);
1442 phba->fc_flag |= FC_DISC_TMO;
1443 spin_unlock_irq(phba->host->host_lock);
1444
1445 /* Start Discovery Timer state <hba_state> */
1446 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
1447 "%d:0247 Start Discovery Timer state x%x "
1448 "Data: x%x x%lx x%x x%x\n",
1449 phba->brd_no,
1450 phba->hba_state, tmo, (unsigned long)&phba->fc_disctmo,
1451 phba->fc_plogi_cnt, phba->fc_adisc_cnt);
1452
1453 return;
1454}
1455
1456/*
1457 * Cancel rescue timer for Discovery / RSCN handling
1458 */
1459int
1460lpfc_can_disctmo(struct lpfc_hba * phba)
1461{
1462 /* Turn off discovery timer if its running */
1463 if (phba->fc_flag & FC_DISC_TMO) {
1464 spin_lock_irq(phba->host->host_lock);
1465 phba->fc_flag &= ~FC_DISC_TMO;
1466 spin_unlock_irq(phba->host->host_lock);
1467 del_timer_sync(&phba->fc_disctmo);
1468 phba->work_hba_events &= ~WORKER_DISC_TMO;
1469 }
1470
1471 /* Cancel Discovery Timer state <hba_state> */
1472 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
1473 "%d:0248 Cancel Discovery Timer state x%x "
1474 "Data: x%x x%x x%x\n",
1475 phba->brd_no, phba->hba_state, phba->fc_flag,
1476 phba->fc_plogi_cnt, phba->fc_adisc_cnt);
1477
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05001478 return 0;
dea31012005-04-17 16:05:31 -05001479}
1480
1481/*
1482 * Check specified ring for outstanding IOCB on the SLI queue
1483 * Return true if iocb matches the specified nport
1484 */
1485int
1486lpfc_check_sli_ndlp(struct lpfc_hba * phba,
1487 struct lpfc_sli_ring * pring,
1488 struct lpfc_iocbq * iocb, struct lpfc_nodelist * ndlp)
1489{
1490 struct lpfc_sli *psli;
1491 IOCB_t *icmd;
1492
1493 psli = &phba->sli;
1494 icmd = &iocb->iocb;
1495 if (pring->ringno == LPFC_ELS_RING) {
1496 switch (icmd->ulpCommand) {
1497 case CMD_GEN_REQUEST64_CR:
1498 if (icmd->ulpContext == (volatile ushort)ndlp->nlp_rpi)
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05001499 return 1;
dea31012005-04-17 16:05:31 -05001500 case CMD_ELS_REQUEST64_CR:
James Smart10d4e952006-04-15 11:53:15 -04001501 if (icmd->un.elsreq64.remoteID == ndlp->nlp_DID)
1502 return 1;
dea31012005-04-17 16:05:31 -05001503 case CMD_XMIT_ELS_RSP64_CX:
1504 if (iocb->context1 == (uint8_t *) ndlp)
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05001505 return 1;
dea31012005-04-17 16:05:31 -05001506 }
James Smarta4bc3372006-12-02 13:34:16 -05001507 } else if (pring->ringno == psli->extra_ring) {
dea31012005-04-17 16:05:31 -05001508
1509 } else if (pring->ringno == psli->fcp_ring) {
1510 /* Skip match check if waiting to relogin to FCP target */
1511 if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
1512 (ndlp->nlp_flag & NLP_DELAY_TMO)) {
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05001513 return 0;
dea31012005-04-17 16:05:31 -05001514 }
1515 if (icmd->ulpContext == (volatile ushort)ndlp->nlp_rpi) {
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05001516 return 1;
dea31012005-04-17 16:05:31 -05001517 }
1518 } else if (pring->ringno == psli->next_ring) {
1519
1520 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05001521 return 0;
dea31012005-04-17 16:05:31 -05001522}
1523
1524/*
1525 * Free resources / clean up outstanding I/Os
1526 * associated with nlp_rpi in the LPFC_NODELIST entry.
1527 */
1528static int
1529lpfc_no_rpi(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp)
1530{
James Smart2534ba72007-04-25 09:52:20 -04001531 LIST_HEAD(completions);
dea31012005-04-17 16:05:31 -05001532 struct lpfc_sli *psli;
1533 struct lpfc_sli_ring *pring;
1534 struct lpfc_iocbq *iocb, *next_iocb;
1535 IOCB_t *icmd;
1536 uint32_t rpi, i;
1537
1538 /*
1539 * Everything that matches on txcmplq will be returned
1540 * by firmware with a no rpi error.
1541 */
1542 psli = &phba->sli;
1543 rpi = ndlp->nlp_rpi;
1544 if (rpi) {
1545 /* Now process each ring */
1546 for (i = 0; i < psli->num_rings; i++) {
1547 pring = &psli->ring[i];
1548
1549 spin_lock_irq(phba->host->host_lock);
1550 list_for_each_entry_safe(iocb, next_iocb, &pring->txq,
1551 list) {
1552 /*
1553 * Check to see if iocb matches the nport we are
1554 * looking for
1555 */
1556 if ((lpfc_check_sli_ndlp
1557 (phba, pring, iocb, ndlp))) {
1558 /* It matches, so deque and call compl
1559 with an error */
James Smart2534ba72007-04-25 09:52:20 -04001560 list_move_tail(&iocb->list,
1561 &completions);
dea31012005-04-17 16:05:31 -05001562 pring->txq_cnt--;
dea31012005-04-17 16:05:31 -05001563 }
1564 }
1565 spin_unlock_irq(phba->host->host_lock);
1566
1567 }
1568 }
James Smart2534ba72007-04-25 09:52:20 -04001569
1570 while (!list_empty(&completions)) {
1571 iocb = list_get_first(&completions, struct lpfc_iocbq, list);
1572 list_del(&iocb->list);
1573
1574 if (iocb->iocb_cmpl) {
1575 icmd = &iocb->iocb;
1576 icmd->ulpStatus = IOSTAT_LOCAL_REJECT;
1577 icmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
1578 (iocb->iocb_cmpl) (phba, iocb, iocb);
1579 } else
1580 lpfc_sli_release_iocbq(phba, iocb);
1581 }
1582
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05001583 return 0;
dea31012005-04-17 16:05:31 -05001584}
1585
1586/*
1587 * Free rpi associated with LPFC_NODELIST entry.
1588 * This routine is called from lpfc_freenode(), when we are removing
1589 * a LPFC_NODELIST entry. It is also called if the driver initiates a
1590 * LOGO that completes successfully, and we are waiting to PLOGI back
1591 * to the remote NPort. In addition, it is called after we receive
1592 * and unsolicated ELS cmd, send back a rsp, the rsp completes and
1593 * we are waiting to PLOGI back to the remote NPort.
1594 */
1595int
1596lpfc_unreg_rpi(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp)
1597{
1598 LPFC_MBOXQ_t *mbox;
1599 int rc;
1600
1601 if (ndlp->nlp_rpi) {
1602 if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL))) {
1603 lpfc_unreg_login(phba, ndlp->nlp_rpi, mbox);
1604 mbox->mbox_cmpl=lpfc_sli_def_mbox_cmpl;
1605 rc = lpfc_sli_issue_mbox
1606 (phba, mbox, (MBX_NOWAIT | MBX_STOP_IOCB));
1607 if (rc == MBX_NOT_FINISHED)
1608 mempool_free( mbox, phba->mbox_mem_pool);
1609 }
dea31012005-04-17 16:05:31 -05001610 lpfc_no_rpi(phba, ndlp);
1611 ndlp->nlp_rpi = 0;
1612 return 1;
1613 }
1614 return 0;
1615}
1616
1617/*
1618 * Free resources associated with LPFC_NODELIST entry
1619 * so it can be freed.
1620 */
1621static int
1622lpfc_freenode(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp)
1623{
1624 LPFC_MBOXQ_t *mb;
1625 LPFC_MBOXQ_t *nextmb;
1626 struct lpfc_dmabuf *mp;
dea31012005-04-17 16:05:31 -05001627
1628 /* Cleanup node for NPort <nlp_DID> */
1629 lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
1630 "%d:0900 Cleanup node for NPort x%x "
1631 "Data: x%x x%x x%x\n",
1632 phba->brd_no, ndlp->nlp_DID, ndlp->nlp_flag,
1633 ndlp->nlp_state, ndlp->nlp_rpi);
1634
James Smartde0c5b32007-04-25 09:52:27 -04001635 lpfc_dequeue_node(phba, ndlp);
dea31012005-04-17 16:05:31 -05001636
dea31012005-04-17 16:05:31 -05001637 /* cleanup any ndlp on mbox q waiting for reglogin cmpl */
1638 if ((mb = phba->sli.mbox_active)) {
1639 if ((mb->mb.mbxCommand == MBX_REG_LOGIN64) &&
1640 (ndlp == (struct lpfc_nodelist *) mb->context2)) {
1641 mb->context2 = NULL;
1642 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1643 }
1644 }
James Smart33ccf8d2006-08-17 11:57:58 -04001645
1646 spin_lock_irq(phba->host->host_lock);
dea31012005-04-17 16:05:31 -05001647 list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
1648 if ((mb->mb.mbxCommand == MBX_REG_LOGIN64) &&
1649 (ndlp == (struct lpfc_nodelist *) mb->context2)) {
1650 mp = (struct lpfc_dmabuf *) (mb->context1);
1651 if (mp) {
1652 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1653 kfree(mp);
1654 }
1655 list_del(&mb->list);
1656 mempool_free(mb, phba->mbox_mem_pool);
1657 }
1658 }
James Smart33ccf8d2006-08-17 11:57:58 -04001659 spin_unlock_irq(phba->host->host_lock);
dea31012005-04-17 16:05:31 -05001660
James Smart07951072007-04-25 09:51:38 -04001661 lpfc_els_abort(phba,ndlp);
dea31012005-04-17 16:05:31 -05001662 spin_lock_irq(phba->host->host_lock);
James Smartc01f3202006-08-18 17:47:08 -04001663 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
dea31012005-04-17 16:05:31 -05001664 spin_unlock_irq(phba->host->host_lock);
dea31012005-04-17 16:05:31 -05001665
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001666 ndlp->nlp_last_elscmd = 0;
dea31012005-04-17 16:05:31 -05001667 del_timer_sync(&ndlp->nlp_delayfunc);
1668
dea31012005-04-17 16:05:31 -05001669 if (!list_empty(&ndlp->els_retry_evt.evt_listp))
1670 list_del_init(&ndlp->els_retry_evt.evt_listp);
1671
1672 lpfc_unreg_rpi(phba, ndlp);
1673
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05001674 return 0;
dea31012005-04-17 16:05:31 -05001675}
1676
1677/*
1678 * Check to see if we can free the nlp back to the freelist.
1679 * If we are in the middle of using the nlp in the discovery state
1680 * machine, defer the free till we reach the end of the state machine.
1681 */
1682int
1683lpfc_nlp_remove(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp)
1684{
James Smart1dcb58e2007-04-25 09:51:30 -04001685 struct lpfc_rport_data *rdata;
dea31012005-04-17 16:05:31 -05001686
1687 if (ndlp->nlp_flag & NLP_DELAY_TMO) {
James Smartfdcebe22006-03-07 15:04:01 -05001688 lpfc_cancel_retry_delay_tmo(phba, ndlp);
dea31012005-04-17 16:05:31 -05001689 }
1690
1691 if (ndlp->nlp_disc_refcnt) {
1692 spin_lock_irq(phba->host->host_lock);
1693 ndlp->nlp_flag |= NLP_DELAY_REMOVE;
1694 spin_unlock_irq(phba->host->host_lock);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05001695 } else {
dea31012005-04-17 16:05:31 -05001696 lpfc_freenode(phba, ndlp);
James Smart1dcb58e2007-04-25 09:51:30 -04001697
1698 if ((ndlp->rport) && !(phba->fc_flag & FC_UNLOADING)) {
1699 rdata = ndlp->rport->dd_data;
1700 rdata->pnode = NULL;
1701 ndlp->rport = NULL;
1702 }
1703
dea31012005-04-17 16:05:31 -05001704 mempool_free( ndlp, phba->nlp_mem_pool);
1705 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05001706 return 0;
dea31012005-04-17 16:05:31 -05001707}
1708
1709static int
1710lpfc_matchdid(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp, uint32_t did)
1711{
1712 D_ID mydid;
1713 D_ID ndlpdid;
1714 D_ID matchdid;
1715
1716 if (did == Bcast_DID)
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05001717 return 0;
dea31012005-04-17 16:05:31 -05001718
1719 if (ndlp->nlp_DID == 0) {
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05001720 return 0;
dea31012005-04-17 16:05:31 -05001721 }
1722
1723 /* First check for Direct match */
1724 if (ndlp->nlp_DID == did)
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05001725 return 1;
dea31012005-04-17 16:05:31 -05001726
1727 /* Next check for area/domain identically equals 0 match */
1728 mydid.un.word = phba->fc_myDID;
1729 if ((mydid.un.b.domain == 0) && (mydid.un.b.area == 0)) {
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05001730 return 0;
dea31012005-04-17 16:05:31 -05001731 }
1732
1733 matchdid.un.word = did;
1734 ndlpdid.un.word = ndlp->nlp_DID;
1735 if (matchdid.un.b.id == ndlpdid.un.b.id) {
1736 if ((mydid.un.b.domain == matchdid.un.b.domain) &&
1737 (mydid.un.b.area == matchdid.un.b.area)) {
1738 if ((ndlpdid.un.b.domain == 0) &&
1739 (ndlpdid.un.b.area == 0)) {
1740 if (ndlpdid.un.b.id)
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05001741 return 1;
dea31012005-04-17 16:05:31 -05001742 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05001743 return 0;
dea31012005-04-17 16:05:31 -05001744 }
1745
1746 matchdid.un.word = ndlp->nlp_DID;
1747 if ((mydid.un.b.domain == ndlpdid.un.b.domain) &&
1748 (mydid.un.b.area == ndlpdid.un.b.area)) {
1749 if ((matchdid.un.b.domain == 0) &&
1750 (matchdid.un.b.area == 0)) {
1751 if (matchdid.un.b.id)
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05001752 return 1;
dea31012005-04-17 16:05:31 -05001753 }
1754 }
1755 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05001756 return 0;
dea31012005-04-17 16:05:31 -05001757}
1758
1759/* Search for a nodelist entry on a specific list */
1760struct lpfc_nodelist *
1761lpfc_findnode_did(struct lpfc_hba * phba, uint32_t order, uint32_t did)
1762{
James Smart2fb9bd82006-12-02 13:33:57 -05001763 struct lpfc_nodelist *ndlp;
1764 struct list_head *lists[]={&phba->fc_nlpunmap_list,
1765 &phba->fc_nlpmap_list,
1766 &phba->fc_plogi_list,
1767 &phba->fc_adisc_list,
1768 &phba->fc_reglogin_list,
1769 &phba->fc_prli_list,
1770 &phba->fc_npr_list,
1771 &phba->fc_unused_list};
1772 uint32_t search[]={NLP_SEARCH_UNMAPPED,
1773 NLP_SEARCH_MAPPED,
1774 NLP_SEARCH_PLOGI,
1775 NLP_SEARCH_ADISC,
1776 NLP_SEARCH_REGLOGIN,
1777 NLP_SEARCH_PRLI,
1778 NLP_SEARCH_NPR,
1779 NLP_SEARCH_UNUSED};
1780 int i;
dea31012005-04-17 16:05:31 -05001781 uint32_t data1;
1782
Jamie Wellnitz66a9ed62006-02-28 22:33:10 -05001783 spin_lock_irq(phba->host->host_lock);
James Smart2fb9bd82006-12-02 13:33:57 -05001784 for (i = 0; i < ARRAY_SIZE(lists); i++ ) {
1785 if (!(order & search[i]))
1786 continue;
1787 list_for_each_entry(ndlp, lists[i], nlp_listp) {
dea31012005-04-17 16:05:31 -05001788 if (lpfc_matchdid(phba, ndlp, did)) {
1789 data1 = (((uint32_t) ndlp->nlp_state << 24) |
1790 ((uint32_t) ndlp->nlp_xri << 16) |
1791 ((uint32_t) ndlp->nlp_type << 8) |
1792 ((uint32_t) ndlp->nlp_rpi & 0xff));
dea31012005-04-17 16:05:31 -05001793 lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
James Smart2fb9bd82006-12-02 13:33:57 -05001794 "%d:0929 FIND node DID "
dea31012005-04-17 16:05:31 -05001795 " Data: x%p x%x x%x x%x\n",
1796 phba->brd_no,
1797 ndlp, ndlp->nlp_DID,
1798 ndlp->nlp_flag, data1);
Jamie Wellnitz66a9ed62006-02-28 22:33:10 -05001799 spin_unlock_irq(phba->host->host_lock);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05001800 return ndlp;
dea31012005-04-17 16:05:31 -05001801 }
1802 }
1803 }
Jamie Wellnitz66a9ed62006-02-28 22:33:10 -05001804 spin_unlock_irq(phba->host->host_lock);
1805
dea31012005-04-17 16:05:31 -05001806 /* FIND node did <did> NOT FOUND */
James Smart2fb9bd82006-12-02 13:33:57 -05001807 lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
dea31012005-04-17 16:05:31 -05001808 "%d:0932 FIND node did x%x NOT FOUND Data: x%x\n",
1809 phba->brd_no, did, order);
dea31012005-04-17 16:05:31 -05001810 return NULL;
1811}
1812
1813struct lpfc_nodelist *
1814lpfc_setup_disc_node(struct lpfc_hba * phba, uint32_t did)
1815{
1816 struct lpfc_nodelist *ndlp;
1817 uint32_t flg;
1818
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001819 ndlp = lpfc_findnode_did(phba, NLP_SEARCH_ALL, did);
1820 if (!ndlp) {
1821 if ((phba->fc_flag & FC_RSCN_MODE) &&
dea31012005-04-17 16:05:31 -05001822 ((lpfc_rscn_payload_check(phba, did) == 0)))
1823 return NULL;
1824 ndlp = (struct lpfc_nodelist *)
1825 mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1826 if (!ndlp)
1827 return NULL;
1828 lpfc_nlp_init(phba, ndlp, did);
James Smartde0c5b32007-04-25 09:52:27 -04001829 lpfc_nlp_set_state(phba, ndlp, NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -05001830 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1831 return ndlp;
1832 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001833 if (phba->fc_flag & FC_RSCN_MODE) {
dea31012005-04-17 16:05:31 -05001834 if (lpfc_rscn_payload_check(phba, did)) {
1835 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001836
1837 /* Since this node is marked for discovery,
1838 * delay timeout is not needed.
1839 */
James Smartfdcebe22006-03-07 15:04:01 -05001840 if (ndlp->nlp_flag & NLP_DELAY_TMO)
1841 lpfc_cancel_retry_delay_tmo(phba, ndlp);
James Smart071fbd3d2006-04-15 11:53:20 -04001842 } else
dea31012005-04-17 16:05:31 -05001843 ndlp = NULL;
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05001844 } else {
dea31012005-04-17 16:05:31 -05001845 flg = ndlp->nlp_flag & NLP_LIST_MASK;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001846 if ((flg == NLP_ADISC_LIST) || (flg == NLP_PLOGI_LIST))
dea31012005-04-17 16:05:31 -05001847 return NULL;
James Smartde0c5b32007-04-25 09:52:27 -04001848 lpfc_nlp_set_state(phba, ndlp, NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -05001849 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1850 }
1851 return ndlp;
1852}
1853
1854/* Build a list of nodes to discover based on the loopmap */
1855void
1856lpfc_disc_list_loopmap(struct lpfc_hba * phba)
1857{
1858 int j;
1859 uint32_t alpa, index;
1860
1861 if (phba->hba_state <= LPFC_LINK_DOWN) {
1862 return;
1863 }
1864 if (phba->fc_topology != TOPOLOGY_LOOP) {
1865 return;
1866 }
1867
1868 /* Check for loop map present or not */
1869 if (phba->alpa_map[0]) {
1870 for (j = 1; j <= phba->alpa_map[0]; j++) {
1871 alpa = phba->alpa_map[j];
1872
1873 if (((phba->fc_myDID & 0xff) == alpa) || (alpa == 0)) {
1874 continue;
1875 }
1876 lpfc_setup_disc_node(phba, alpa);
1877 }
1878 } else {
1879 /* No alpamap, so try all alpa's */
1880 for (j = 0; j < FC_MAXLOOP; j++) {
1881 /* If cfg_scan_down is set, start from highest
1882 * ALPA (0xef) to lowest (0x1).
1883 */
1884 if (phba->cfg_scan_down)
1885 index = j;
1886 else
1887 index = FC_MAXLOOP - j - 1;
1888 alpa = lpfcAlpaArray[index];
1889 if ((phba->fc_myDID & 0xff) == alpa) {
1890 continue;
1891 }
1892
1893 lpfc_setup_disc_node(phba, alpa);
1894 }
1895 }
1896 return;
1897}
1898
1899/* Start Link up / RSCN discovery on NPR list */
1900void
1901lpfc_disc_start(struct lpfc_hba * phba)
1902{
1903 struct lpfc_sli *psli;
1904 LPFC_MBOXQ_t *mbox;
1905 struct lpfc_nodelist *ndlp, *next_ndlp;
1906 uint32_t did_changed, num_sent;
1907 uint32_t clear_la_pending;
1908 int rc;
1909
1910 psli = &phba->sli;
1911
1912 if (phba->hba_state <= LPFC_LINK_DOWN) {
1913 return;
1914 }
1915 if (phba->hba_state == LPFC_CLEAR_LA)
1916 clear_la_pending = 1;
1917 else
1918 clear_la_pending = 0;
1919
1920 if (phba->hba_state < LPFC_HBA_READY) {
1921 phba->hba_state = LPFC_DISC_AUTH;
1922 }
1923 lpfc_set_disctmo(phba);
1924
1925 if (phba->fc_prevDID == phba->fc_myDID) {
1926 did_changed = 0;
1927 } else {
1928 did_changed = 1;
1929 }
1930 phba->fc_prevDID = phba->fc_myDID;
1931 phba->num_disc_nodes = 0;
1932
1933 /* Start Discovery state <hba_state> */
1934 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
1935 "%d:0202 Start Discovery hba state x%x "
1936 "Data: x%x x%x x%x\n",
1937 phba->brd_no, phba->hba_state, phba->fc_flag,
1938 phba->fc_plogi_cnt, phba->fc_adisc_cnt);
1939
1940 /* If our did changed, we MUST do PLOGI */
1941 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_npr_list,
1942 nlp_listp) {
1943 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1944 if (did_changed) {
1945 spin_lock_irq(phba->host->host_lock);
1946 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
1947 spin_unlock_irq(phba->host->host_lock);
1948 }
1949 }
1950 }
1951
1952 /* First do ADISCs - if any */
1953 num_sent = lpfc_els_disc_adisc(phba);
1954
1955 if (num_sent)
1956 return;
1957
1958 if ((phba->hba_state < LPFC_HBA_READY) && (!clear_la_pending)) {
1959 /* If we get here, there is nothing to ADISC */
1960 if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL))) {
1961 phba->hba_state = LPFC_CLEAR_LA;
1962 lpfc_clear_la(phba, mbox);
1963 mbox->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
1964 rc = lpfc_sli_issue_mbox(phba, mbox,
1965 (MBX_NOWAIT | MBX_STOP_IOCB));
1966 if (rc == MBX_NOT_FINISHED) {
1967 mempool_free( mbox, phba->mbox_mem_pool);
1968 lpfc_disc_flush_list(phba);
James Smarta4bc3372006-12-02 13:34:16 -05001969 psli->ring[(psli->extra_ring)].flag &=
dea31012005-04-17 16:05:31 -05001970 ~LPFC_STOP_IOCB_EVENT;
1971 psli->ring[(psli->fcp_ring)].flag &=
1972 ~LPFC_STOP_IOCB_EVENT;
1973 psli->ring[(psli->next_ring)].flag &=
1974 ~LPFC_STOP_IOCB_EVENT;
1975 phba->hba_state = LPFC_HBA_READY;
1976 }
1977 }
1978 } else {
1979 /* Next do PLOGIs - if any */
1980 num_sent = lpfc_els_disc_plogi(phba);
1981
1982 if (num_sent)
1983 return;
1984
1985 if (phba->fc_flag & FC_RSCN_MODE) {
1986 /* Check to see if more RSCNs came in while we
1987 * were processing this one.
1988 */
1989 if ((phba->fc_rscn_id_cnt == 0) &&
1990 (!(phba->fc_flag & FC_RSCN_DISCOVERY))) {
1991 spin_lock_irq(phba->host->host_lock);
1992 phba->fc_flag &= ~FC_RSCN_MODE;
1993 spin_unlock_irq(phba->host->host_lock);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05001994 } else
dea31012005-04-17 16:05:31 -05001995 lpfc_els_handle_rscn(phba);
1996 }
1997 }
1998 return;
1999}
2000
2001/*
2002 * Ignore completion for all IOCBs on tx and txcmpl queue for ELS
2003 * ring the match the sppecified nodelist.
2004 */
2005static void
2006lpfc_free_tx(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp)
2007{
James Smart2534ba72007-04-25 09:52:20 -04002008 LIST_HEAD(completions);
dea31012005-04-17 16:05:31 -05002009 struct lpfc_sli *psli;
2010 IOCB_t *icmd;
2011 struct lpfc_iocbq *iocb, *next_iocb;
2012 struct lpfc_sli_ring *pring;
dea31012005-04-17 16:05:31 -05002013
2014 psli = &phba->sli;
2015 pring = &psli->ring[LPFC_ELS_RING];
2016
2017 /* Error matching iocb on txq or txcmplq
2018 * First check the txq.
2019 */
James Smart2534ba72007-04-25 09:52:20 -04002020 spin_lock_irq(phba->host->host_lock);
dea31012005-04-17 16:05:31 -05002021 list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
2022 if (iocb->context1 != ndlp) {
2023 continue;
2024 }
2025 icmd = &iocb->iocb;
2026 if ((icmd->ulpCommand == CMD_ELS_REQUEST64_CR) ||
2027 (icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX)) {
2028
James Smart2534ba72007-04-25 09:52:20 -04002029 list_move_tail(&iocb->list, &completions);
dea31012005-04-17 16:05:31 -05002030 pring->txq_cnt--;
dea31012005-04-17 16:05:31 -05002031 }
2032 }
2033
2034 /* Next check the txcmplq */
2035 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
2036 if (iocb->context1 != ndlp) {
2037 continue;
2038 }
2039 icmd = &iocb->iocb;
2040 if ((icmd->ulpCommand == CMD_ELS_REQUEST64_CR) ||
2041 (icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX)) {
James Smart2534ba72007-04-25 09:52:20 -04002042 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
dea31012005-04-17 16:05:31 -05002043 }
2044 }
James Smart2534ba72007-04-25 09:52:20 -04002045 spin_unlock_irq(phba->host->host_lock);
2046
2047 while (!list_empty(&completions)) {
2048 iocb = list_get_first(&completions, struct lpfc_iocbq, list);
2049 list_del(&iocb->list);
2050
2051 if (iocb->iocb_cmpl) {
2052 icmd = &iocb->iocb;
2053 icmd->ulpStatus = IOSTAT_LOCAL_REJECT;
2054 icmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
2055 (iocb->iocb_cmpl) (phba, iocb, iocb);
2056 } else
2057 lpfc_sli_release_iocbq(phba, iocb);
2058 }
dea31012005-04-17 16:05:31 -05002059
2060 return;
2061}
2062
2063void
2064lpfc_disc_flush_list(struct lpfc_hba * phba)
2065{
2066 struct lpfc_nodelist *ndlp, *next_ndlp;
2067
2068 if (phba->fc_plogi_cnt) {
2069 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_plogi_list,
2070 nlp_listp) {
2071 lpfc_free_tx(phba, ndlp);
2072 lpfc_nlp_remove(phba, ndlp);
2073 }
2074 }
2075 if (phba->fc_adisc_cnt) {
2076 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_adisc_list,
2077 nlp_listp) {
2078 lpfc_free_tx(phba, ndlp);
2079 lpfc_nlp_remove(phba, ndlp);
2080 }
2081 }
2082 return;
2083}
2084
2085/*****************************************************************************/
2086/*
2087 * NAME: lpfc_disc_timeout
2088 *
2089 * FUNCTION: Fibre Channel driver discovery timeout routine.
2090 *
2091 * EXECUTION ENVIRONMENT: interrupt only
2092 *
2093 * CALLED FROM:
2094 * Timer function
2095 *
2096 * RETURNS:
2097 * none
2098 */
2099/*****************************************************************************/
2100void
2101lpfc_disc_timeout(unsigned long ptr)
2102{
2103 struct lpfc_hba *phba = (struct lpfc_hba *)ptr;
2104 unsigned long flags = 0;
2105
2106 if (unlikely(!phba))
2107 return;
2108
2109 spin_lock_irqsave(phba->host->host_lock, flags);
2110 if (!(phba->work_hba_events & WORKER_DISC_TMO)) {
2111 phba->work_hba_events |= WORKER_DISC_TMO;
2112 if (phba->work_wait)
2113 wake_up(phba->work_wait);
2114 }
2115 spin_unlock_irqrestore(phba->host->host_lock, flags);
2116 return;
2117}
2118
2119static void
2120lpfc_disc_timeout_handler(struct lpfc_hba *phba)
2121{
2122 struct lpfc_sli *psli;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002123 struct lpfc_nodelist *ndlp, *next_ndlp;
dea31012005-04-17 16:05:31 -05002124 LPFC_MBOXQ_t *clearlambox, *initlinkmbox;
2125 int rc, clrlaerr = 0;
2126
2127 if (unlikely(!phba))
2128 return;
2129
2130 if (!(phba->fc_flag & FC_DISC_TMO))
2131 return;
2132
2133 psli = &phba->sli;
2134
2135 spin_lock_irq(phba->host->host_lock);
2136 phba->fc_flag &= ~FC_DISC_TMO;
2137 spin_unlock_irq(phba->host->host_lock);
2138
2139 switch (phba->hba_state) {
2140
2141 case LPFC_LOCAL_CFG_LINK:
2142 /* hba_state is identically LPFC_LOCAL_CFG_LINK while waiting for FAN */
2143 /* FAN timeout */
2144 lpfc_printf_log(phba,
2145 KERN_WARNING,
2146 LOG_DISCOVERY,
2147 "%d:0221 FAN timeout\n",
2148 phba->brd_no);
2149
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002150 /* Start discovery by sending FLOGI, clean up old rpis */
2151 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_npr_list,
2152 nlp_listp) {
2153 if (ndlp->nlp_type & NLP_FABRIC) {
2154 /* Clean up the ndlp on Fabric connections */
James Smartde0c5b32007-04-25 09:52:27 -04002155 lpfc_drop_node(phba, ndlp);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05002156 } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002157 /* Fail outstanding IO now since device
2158 * is marked for PLOGI.
2159 */
2160 lpfc_unreg_rpi(phba, ndlp);
2161 }
2162 }
dea31012005-04-17 16:05:31 -05002163 phba->hba_state = LPFC_FLOGI;
2164 lpfc_set_disctmo(phba);
2165 lpfc_initial_flogi(phba);
2166 break;
2167
2168 case LPFC_FLOGI:
2169 /* hba_state is identically LPFC_FLOGI while waiting for FLOGI cmpl */
2170 /* Initial FLOGI timeout */
2171 lpfc_printf_log(phba,
2172 KERN_ERR,
2173 LOG_DISCOVERY,
2174 "%d:0222 Initial FLOGI timeout\n",
2175 phba->brd_no);
2176
2177 /* Assume no Fabric and go on with discovery.
2178 * Check for outstanding ELS FLOGI to abort.
2179 */
2180
2181 /* FLOGI failed, so just use loop map to make discovery list */
2182 lpfc_disc_list_loopmap(phba);
2183
2184 /* Start discovery */
2185 lpfc_disc_start(phba);
2186 break;
2187
2188 case LPFC_FABRIC_CFG_LINK:
2189 /* hba_state is identically LPFC_FABRIC_CFG_LINK while waiting for
2190 NameServer login */
2191 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
2192 "%d:0223 Timeout while waiting for NameServer "
2193 "login\n", phba->brd_no);
2194
2195 /* Next look for NameServer ndlp */
2196 ndlp = lpfc_findnode_did(phba, NLP_SEARCH_ALL, NameServer_DID);
2197 if (ndlp)
2198 lpfc_nlp_remove(phba, ndlp);
2199 /* Start discovery */
2200 lpfc_disc_start(phba);
2201 break;
2202
2203 case LPFC_NS_QRY:
2204 /* Check for wait for NameServer Rsp timeout */
2205 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
2206 "%d:0224 NameServer Query timeout "
2207 "Data: x%x x%x\n",
2208 phba->brd_no,
2209 phba->fc_ns_retry, LPFC_MAX_NS_RETRY);
2210
2211 ndlp = lpfc_findnode_did(phba, NLP_SEARCH_UNMAPPED,
2212 NameServer_DID);
2213 if (ndlp) {
2214 if (phba->fc_ns_retry < LPFC_MAX_NS_RETRY) {
2215 /* Try it one more time */
2216 rc = lpfc_ns_cmd(phba, ndlp, SLI_CTNS_GID_FT);
2217 if (rc == 0)
2218 break;
2219 }
2220 phba->fc_ns_retry = 0;
2221 }
2222
2223 /* Nothing to authenticate, so CLEAR_LA right now */
2224 clearlambox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2225 if (!clearlambox) {
2226 clrlaerr = 1;
2227 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
2228 "%d:0226 Device Discovery "
2229 "completion error\n",
2230 phba->brd_no);
2231 phba->hba_state = LPFC_HBA_ERROR;
2232 break;
2233 }
2234
2235 phba->hba_state = LPFC_CLEAR_LA;
2236 lpfc_clear_la(phba, clearlambox);
2237 clearlambox->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
2238 rc = lpfc_sli_issue_mbox(phba, clearlambox,
2239 (MBX_NOWAIT | MBX_STOP_IOCB));
2240 if (rc == MBX_NOT_FINISHED) {
2241 mempool_free(clearlambox, phba->mbox_mem_pool);
2242 clrlaerr = 1;
2243 break;
2244 }
2245
2246 /* Setup and issue mailbox INITIALIZE LINK command */
2247 initlinkmbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2248 if (!initlinkmbox) {
2249 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
James Smartdca94792006-08-01 07:34:08 -04002250 "%d:0206 Device Discovery "
dea31012005-04-17 16:05:31 -05002251 "completion error\n",
2252 phba->brd_no);
2253 phba->hba_state = LPFC_HBA_ERROR;
2254 break;
2255 }
2256
2257 lpfc_linkdown(phba);
2258 lpfc_init_link(phba, initlinkmbox, phba->cfg_topology,
2259 phba->cfg_link_speed);
2260 initlinkmbox->mb.un.varInitLnk.lipsr_AL_PA = 0;
2261 rc = lpfc_sli_issue_mbox(phba, initlinkmbox,
2262 (MBX_NOWAIT | MBX_STOP_IOCB));
James Smart5b8bd0c2007-04-25 09:52:49 -04002263 lpfc_set_loopback_flag(phba);
dea31012005-04-17 16:05:31 -05002264 if (rc == MBX_NOT_FINISHED)
2265 mempool_free(initlinkmbox, phba->mbox_mem_pool);
2266
2267 break;
2268
2269 case LPFC_DISC_AUTH:
2270 /* Node Authentication timeout */
2271 lpfc_printf_log(phba,
2272 KERN_ERR,
2273 LOG_DISCOVERY,
2274 "%d:0227 Node Authentication timeout\n",
2275 phba->brd_no);
2276 lpfc_disc_flush_list(phba);
2277 clearlambox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2278 if (!clearlambox) {
2279 clrlaerr = 1;
2280 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
James Smartdca94792006-08-01 07:34:08 -04002281 "%d:0207 Device Discovery "
dea31012005-04-17 16:05:31 -05002282 "completion error\n",
2283 phba->brd_no);
2284 phba->hba_state = LPFC_HBA_ERROR;
2285 break;
2286 }
2287 phba->hba_state = LPFC_CLEAR_LA;
2288 lpfc_clear_la(phba, clearlambox);
2289 clearlambox->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
2290 rc = lpfc_sli_issue_mbox(phba, clearlambox,
2291 (MBX_NOWAIT | MBX_STOP_IOCB));
2292 if (rc == MBX_NOT_FINISHED) {
2293 mempool_free(clearlambox, phba->mbox_mem_pool);
2294 clrlaerr = 1;
2295 }
2296 break;
2297
2298 case LPFC_CLEAR_LA:
2299 /* CLEAR LA timeout */
2300 lpfc_printf_log(phba,
2301 KERN_ERR,
2302 LOG_DISCOVERY,
2303 "%d:0228 CLEAR LA timeout\n",
2304 phba->brd_no);
2305 clrlaerr = 1;
2306 break;
2307
2308 case LPFC_HBA_READY:
2309 if (phba->fc_flag & FC_RSCN_MODE) {
2310 lpfc_printf_log(phba,
2311 KERN_ERR,
2312 LOG_DISCOVERY,
2313 "%d:0231 RSCN timeout Data: x%x x%x\n",
2314 phba->brd_no,
2315 phba->fc_ns_retry, LPFC_MAX_NS_RETRY);
2316
2317 /* Cleanup any outstanding ELS commands */
2318 lpfc_els_flush_cmd(phba);
2319
2320 lpfc_els_flush_rscn(phba);
2321 lpfc_disc_flush_list(phba);
2322 }
2323 break;
2324 }
2325
2326 if (clrlaerr) {
2327 lpfc_disc_flush_list(phba);
James Smarta4bc3372006-12-02 13:34:16 -05002328 psli->ring[(psli->extra_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
dea31012005-04-17 16:05:31 -05002329 psli->ring[(psli->fcp_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
2330 psli->ring[(psli->next_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
2331 phba->hba_state = LPFC_HBA_READY;
2332 }
2333
2334 return;
2335}
2336
dea31012005-04-17 16:05:31 -05002337/*
2338 * This routine handles processing a NameServer REG_LOGIN mailbox
2339 * command upon completion. It is setup in the LPFC_MBOXQ
2340 * as the completion routine when the command is
2341 * handed off to the SLI layer.
2342 */
2343void
2344lpfc_mbx_cmpl_fdmi_reg_login(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
2345{
2346 struct lpfc_sli *psli;
2347 MAILBOX_t *mb;
2348 struct lpfc_dmabuf *mp;
2349 struct lpfc_nodelist *ndlp;
2350
2351 psli = &phba->sli;
2352 mb = &pmb->mb;
2353
2354 ndlp = (struct lpfc_nodelist *) pmb->context2;
2355 mp = (struct lpfc_dmabuf *) (pmb->context1);
2356
2357 pmb->context1 = NULL;
2358
dea31012005-04-17 16:05:31 -05002359 ndlp->nlp_rpi = mb->un.varWords[0];
dea31012005-04-17 16:05:31 -05002360 ndlp->nlp_type |= NLP_FABRIC;
James Smartde0c5b32007-04-25 09:52:27 -04002361 lpfc_nlp_set_state(phba, ndlp, NLP_STE_UNMAPPED_NODE);
dea31012005-04-17 16:05:31 -05002362
2363 /* Start issuing Fabric-Device Management Interface (FDMI)
2364 * command to 0xfffffa (FDMI well known port)
2365 */
2366 if (phba->cfg_fdmi_on == 1) {
2367 lpfc_fdmi_cmd(phba, ndlp, SLI_MGMT_DHBA);
2368 } else {
2369 /*
2370 * Delay issuing FDMI command if fdmi-on=2
2371 * (supporting RPA/hostnmae)
2372 */
2373 mod_timer(&phba->fc_fdmitmo, jiffies + HZ * 60);
2374 }
2375
2376 lpfc_mbuf_free(phba, mp->virt, mp->phys);
2377 kfree(mp);
2378 mempool_free( pmb, phba->mbox_mem_pool);
2379
2380 return;
2381}
2382
2383/*
James.Smart@Emulex.Com21568f52005-10-28 20:29:36 -04002384 * This routine looks up the ndlp lists
2385 * for the given RPI. If rpi found
dea31012005-04-17 16:05:31 -05002386 * it return the node list pointer
James.Smart@Emulex.Com21568f52005-10-28 20:29:36 -04002387 * else return NULL.
dea31012005-04-17 16:05:31 -05002388 */
2389struct lpfc_nodelist *
James Smart2534ba72007-04-25 09:52:20 -04002390__lpfc_findnode_rpi(struct lpfc_hba * phba, uint16_t rpi)
dea31012005-04-17 16:05:31 -05002391{
James.Smart@Emulex.Com21568f52005-10-28 20:29:36 -04002392 struct lpfc_nodelist *ndlp;
2393 struct list_head * lists[]={&phba->fc_nlpunmap_list,
2394 &phba->fc_nlpmap_list,
2395 &phba->fc_plogi_list,
2396 &phba->fc_adisc_list,
2397 &phba->fc_reglogin_list};
2398 int i;
dea31012005-04-17 16:05:31 -05002399
James.Smart@Emulex.Com21568f52005-10-28 20:29:36 -04002400 for (i = 0; i < ARRAY_SIZE(lists); i++ )
2401 list_for_each_entry(ndlp, lists[i], nlp_listp)
Jamie Wellnitz66a9ed62006-02-28 22:33:10 -05002402 if (ndlp->nlp_rpi == rpi) {
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05002403 return ndlp;
Jamie Wellnitz66a9ed62006-02-28 22:33:10 -05002404 }
James.Smart@Emulex.Com21568f52005-10-28 20:29:36 -04002405 return NULL;
dea31012005-04-17 16:05:31 -05002406}
2407
James Smart2534ba72007-04-25 09:52:20 -04002408struct lpfc_nodelist *
2409lpfc_findnode_rpi(struct lpfc_hba * phba, uint16_t rpi)
2410{
2411 struct lpfc_nodelist *ndlp;
2412
2413 spin_lock_irq(phba->host->host_lock);
2414 ndlp = __lpfc_findnode_rpi(phba, rpi);
2415 spin_unlock_irq(phba->host->host_lock);
2416 return ndlp;
2417}
2418
James Smart488d1462006-03-07 15:02:37 -05002419/*
2420 * This routine looks up the ndlp lists
2421 * for the given WWPN. If WWPN found
2422 * it return the node list pointer
2423 * else return NULL.
2424 */
2425struct lpfc_nodelist *
2426lpfc_findnode_wwpn(struct lpfc_hba * phba, uint32_t order,
2427 struct lpfc_name * wwpn)
2428{
2429 struct lpfc_nodelist *ndlp;
2430 struct list_head * lists[]={&phba->fc_nlpunmap_list,
2431 &phba->fc_nlpmap_list,
2432 &phba->fc_npr_list,
2433 &phba->fc_plogi_list,
2434 &phba->fc_adisc_list,
2435 &phba->fc_reglogin_list,
2436 &phba->fc_prli_list};
2437 uint32_t search[]={NLP_SEARCH_UNMAPPED,
2438 NLP_SEARCH_MAPPED,
2439 NLP_SEARCH_NPR,
2440 NLP_SEARCH_PLOGI,
2441 NLP_SEARCH_ADISC,
2442 NLP_SEARCH_REGLOGIN,
2443 NLP_SEARCH_PRLI};
2444 int i;
2445
2446 spin_lock_irq(phba->host->host_lock);
2447 for (i = 0; i < ARRAY_SIZE(lists); i++ ) {
2448 if (!(order & search[i]))
2449 continue;
2450 list_for_each_entry(ndlp, lists[i], nlp_listp) {
2451 if (memcmp(&ndlp->nlp_portname, wwpn,
2452 sizeof(struct lpfc_name)) == 0) {
2453 spin_unlock_irq(phba->host->host_lock);
2454 return ndlp;
2455 }
2456 }
2457 }
2458 spin_unlock_irq(phba->host->host_lock);
2459 return NULL;
2460}
2461
dea31012005-04-17 16:05:31 -05002462void
2463lpfc_nlp_init(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp,
2464 uint32_t did)
2465{
2466 memset(ndlp, 0, sizeof (struct lpfc_nodelist));
dea31012005-04-17 16:05:31 -05002467 INIT_LIST_HEAD(&ndlp->els_retry_evt.evt_listp);
dea31012005-04-17 16:05:31 -05002468 init_timer(&ndlp->nlp_delayfunc);
2469 ndlp->nlp_delayfunc.function = lpfc_els_retry_delay;
2470 ndlp->nlp_delayfunc.data = (unsigned long)ndlp;
2471 ndlp->nlp_DID = did;
2472 ndlp->nlp_phba = phba;
2473 ndlp->nlp_sid = NLP_NO_SID;
2474 return;
2475}