[SCSI] lpfc 8.1.12 : Reorganize lpfc_nlp_list() and callers to prepare for nodelist...
[deliverable/linux.git] / drivers / scsi / lpfc / lpfc_nportdisc.c
CommitLineData
dea3101e 1/*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
c44ce173 3 * Fibre Channel Host Bus Adapters. *
2fe165b6 4 * Copyright (C) 2004-2006 Emulex. All rights reserved. *
c44ce173 5 * EMULEX and SLI are trademarks of Emulex. *
dea3101e 6 * www.emulex.com *
c44ce173 7 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
dea3101e 8 * *
9 * This program is free software; you can redistribute it and/or *
c44ce173
JSEC
10 * modify it under the terms of version 2 of the GNU General *
11 * Public License as published by the Free Software Foundation. *
12 * This program is distributed in the hope that it will be useful. *
13 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
14 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
15 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
16 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
17 * TO BE LEGALLY INVALID. See the GNU General Public License for *
18 * more details, a copy of which can be found in the file COPYING *
19 * included with this package. *
dea3101e 20 *******************************************************************/
21
dea3101e 22#include <linux/blkdev.h>
23#include <linux/pci.h>
24#include <linux/interrupt.h>
25
91886523 26#include <scsi/scsi.h>
dea3101e 27#include <scsi/scsi_device.h>
28#include <scsi/scsi_host.h>
29#include <scsi/scsi_transport_fc.h>
30
31#include "lpfc_hw.h"
32#include "lpfc_sli.h"
33#include "lpfc_disc.h"
34#include "lpfc_scsi.h"
35#include "lpfc.h"
36#include "lpfc_logmsg.h"
37#include "lpfc_crtn.h"
38
39
40/* Called to verify a rcv'ed ADISC was intended for us. */
41static int
42lpfc_check_adisc(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp,
43 struct lpfc_name * nn, struct lpfc_name * pn)
44{
45 /* Compare the ADISC rsp WWNN / WWPN matches our internal node
46 * table entry for that node.
47 */
48 if (memcmp(nn, &ndlp->nlp_nodename, sizeof (struct lpfc_name)) != 0)
c9f8735b 49 return 0;
dea3101e 50
51 if (memcmp(pn, &ndlp->nlp_portname, sizeof (struct lpfc_name)) != 0)
c9f8735b 52 return 0;
dea3101e 53
54 /* we match, return success */
c9f8735b 55 return 1;
dea3101e 56}
57
dea3101e 58int
59lpfc_check_sparm(struct lpfc_hba * phba,
60 struct lpfc_nodelist * ndlp, struct serv_parm * sp,
61 uint32_t class)
62{
63 volatile struct serv_parm *hsp = &phba->fc_sparam;
2fb70f79
JSEC
64 uint16_t hsp_value, ssp_value = 0;
65
66 /*
67 * The receive data field size and buffer-to-buffer receive data field
68 * size entries are 16 bits but are represented as two 8-bit fields in
69 * the driver data structure to account for rsvd bits and other control
70 * bits. Reconstruct and compare the fields as a 16-bit values before
71 * correcting the byte values.
72 */
dea3101e 73 if (sp->cls1.classValid) {
2fb70f79
JSEC
74 hsp_value = (hsp->cls1.rcvDataSizeMsb << 8) |
75 hsp->cls1.rcvDataSizeLsb;
76 ssp_value = (sp->cls1.rcvDataSizeMsb << 8) |
77 sp->cls1.rcvDataSizeLsb;
78 if (ssp_value > hsp_value) {
dea3101e 79 sp->cls1.rcvDataSizeLsb = hsp->cls1.rcvDataSizeLsb;
2fb70f79
JSEC
80 sp->cls1.rcvDataSizeMsb = hsp->cls1.rcvDataSizeMsb;
81 }
dea3101e 82 } else if (class == CLASS1) {
2fb70f79 83 return 0;
dea3101e 84 }
85
86 if (sp->cls2.classValid) {
2fb70f79
JSEC
87 hsp_value = (hsp->cls2.rcvDataSizeMsb << 8) |
88 hsp->cls2.rcvDataSizeLsb;
89 ssp_value = (sp->cls2.rcvDataSizeMsb << 8) |
90 sp->cls2.rcvDataSizeLsb;
91 if (ssp_value > hsp_value) {
dea3101e 92 sp->cls2.rcvDataSizeLsb = hsp->cls2.rcvDataSizeLsb;
2fb70f79
JSEC
93 sp->cls2.rcvDataSizeMsb = hsp->cls2.rcvDataSizeMsb;
94 }
dea3101e 95 } else if (class == CLASS2) {
2fb70f79 96 return 0;
dea3101e 97 }
98
99 if (sp->cls3.classValid) {
2fb70f79
JSEC
100 hsp_value = (hsp->cls3.rcvDataSizeMsb << 8) |
101 hsp->cls3.rcvDataSizeLsb;
102 ssp_value = (sp->cls3.rcvDataSizeMsb << 8) |
103 sp->cls3.rcvDataSizeLsb;
104 if (ssp_value > hsp_value) {
dea3101e 105 sp->cls3.rcvDataSizeLsb = hsp->cls3.rcvDataSizeLsb;
2fb70f79
JSEC
106 sp->cls3.rcvDataSizeMsb = hsp->cls3.rcvDataSizeMsb;
107 }
dea3101e 108 } else if (class == CLASS3) {
2fb70f79 109 return 0;
dea3101e 110 }
111
2fb70f79
JSEC
112 /*
113 * Preserve the upper four bits of the MSB from the PLOGI response.
114 * These bits contain the Buffer-to-Buffer State Change Number
115 * from the target and need to be passed to the FW.
116 */
117 hsp_value = (hsp->cmn.bbRcvSizeMsb << 8) | hsp->cmn.bbRcvSizeLsb;
118 ssp_value = (sp->cmn.bbRcvSizeMsb << 8) | sp->cmn.bbRcvSizeLsb;
119 if (ssp_value > hsp_value) {
dea3101e 120 sp->cmn.bbRcvSizeLsb = hsp->cmn.bbRcvSizeLsb;
2fb70f79
JSEC
121 sp->cmn.bbRcvSizeMsb = (sp->cmn.bbRcvSizeMsb & 0xF0) |
122 (hsp->cmn.bbRcvSizeMsb & 0x0F);
123 }
dea3101e 124
dea3101e 125 memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof (struct lpfc_name));
126 memcpy(&ndlp->nlp_portname, &sp->portName, sizeof (struct lpfc_name));
2fb70f79 127 return 1;
dea3101e 128}
129
130static void *
131lpfc_check_elscmpl_iocb(struct lpfc_hba * phba,
132 struct lpfc_iocbq *cmdiocb,
133 struct lpfc_iocbq *rspiocb)
134{
135 struct lpfc_dmabuf *pcmd, *prsp;
136 uint32_t *lp;
137 void *ptr = NULL;
138 IOCB_t *irsp;
139
140 irsp = &rspiocb->iocb;
141 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
142
143 /* For lpfc_els_abort, context2 could be zero'ed to delay
144 * freeing associated memory till after ABTS completes.
145 */
146 if (pcmd) {
147 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf,
148 list);
149 if (prsp) {
150 lp = (uint32_t *) prsp->virt;
151 ptr = (void *)((uint8_t *)lp + sizeof(uint32_t));
152 }
2fe165b6 153 } else {
dea3101e 154 /* Force ulpStatus error since we are returning NULL ptr */
155 if (!(irsp->ulpStatus)) {
156 irsp->ulpStatus = IOSTAT_LOCAL_REJECT;
157 irsp->un.ulpWord[4] = IOERR_SLI_ABORTED;
158 }
159 ptr = NULL;
160 }
c9f8735b 161 return ptr;
dea3101e 162}
163
164
165/*
166 * Free resources / clean up outstanding I/Os
167 * associated with a LPFC_NODELIST entry. This
168 * routine effectively results in a "software abort".
169 */
170int
07951076 171lpfc_els_abort(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp)
dea3101e 172{
2534ba75 173 LIST_HEAD(completions);
dea3101e 174 struct lpfc_sli *psli;
175 struct lpfc_sli_ring *pring;
176 struct lpfc_iocbq *iocb, *next_iocb;
2534ba75 177 IOCB_t *cmd;
dea3101e 178
179 /* Abort outstanding I/O on NPort <nlp_DID> */
180 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
dca9479b 181 "%d:0205 Abort outstanding I/O on NPort x%x "
dea3101e 182 "Data: x%x x%x x%x\n",
183 phba->brd_no, ndlp->nlp_DID, ndlp->nlp_flag,
184 ndlp->nlp_state, ndlp->nlp_rpi);
185
186 psli = &phba->sli;
187 pring = &psli->ring[LPFC_ELS_RING];
188
189 /* First check the txq */
2534ba75
JS
190 spin_lock_irq(phba->host->host_lock);
191 list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
192 /* Check to see if iocb matches the nport we are looking
193 for */
194 if (lpfc_check_sli_ndlp(phba, pring, iocb, ndlp)) {
195 /* It matches, so deque and call compl with an
196 error */
197 list_move_tail(&iocb->list, &completions);
198 pring->txq_cnt--;
dea3101e 199 }
2534ba75 200 }
dea3101e 201
dea3101e 202 /* Next check the txcmplq */
07951076
JS
203 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
204 /* Check to see if iocb matches the nport we are looking
205 for */
2534ba75 206 if (lpfc_check_sli_ndlp(phba, pring, iocb, ndlp))
07951076 207 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
07951076
JS
208 }
209 spin_unlock_irq(phba->host->host_lock);
dea3101e 210
2534ba75
JS
211 while (!list_empty(&completions)) {
212 iocb = list_get_first(&completions, struct lpfc_iocbq, list);
213 cmd = &iocb->iocb;
214 list_del(&iocb->list);
215
216 if (iocb->iocb_cmpl) {
217 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
218 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
219 (iocb->iocb_cmpl) (phba, iocb, iocb);
220 } else
221 lpfc_sli_release_iocbq(phba, iocb);
222 }
223
dea3101e 224 /* If we are delaying issuing an ELS command, cancel it */
fdcebe28
JS
225 if (ndlp->nlp_flag & NLP_DELAY_TMO)
226 lpfc_cancel_retry_delay_tmo(phba, ndlp);
c9f8735b 227 return 0;
dea3101e 228}
229
230static int
231lpfc_rcv_plogi(struct lpfc_hba * phba,
232 struct lpfc_nodelist * ndlp,
233 struct lpfc_iocbq *cmdiocb)
234{
235 struct lpfc_dmabuf *pcmd;
236 uint32_t *lp;
237 IOCB_t *icmd;
238 struct serv_parm *sp;
239 LPFC_MBOXQ_t *mbox;
240 struct ls_rjt stat;
241 int rc;
242
243 memset(&stat, 0, sizeof (struct ls_rjt));
244 if (phba->hba_state <= LPFC_FLOGI) {
245 /* Before responding to PLOGI, check for pt2pt mode.
246 * If we are pt2pt, with an outstanding FLOGI, abort
247 * the FLOGI and resend it first.
248 */
249 if (phba->fc_flag & FC_PT2PT) {
250 lpfc_els_abort_flogi(phba);
251 if (!(phba->fc_flag & FC_PT2PT_PLOGI)) {
252 /* If the other side is supposed to initiate
253 * the PLOGI anyway, just ACC it now and
254 * move on with discovery.
255 */
256 phba->fc_edtov = FF_DEF_EDTOV;
257 phba->fc_ratov = FF_DEF_RATOV;
258 /* Start discovery - this should just do
259 CLEAR_LA */
260 lpfc_disc_start(phba);
2fe165b6 261 } else {
dea3101e 262 lpfc_initial_flogi(phba);
263 }
2fe165b6 264 } else {
dea3101e 265 stat.un.b.lsRjtRsnCode = LSRJT_LOGICAL_BSY;
266 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
267 lpfc_els_rsp_reject(phba, stat.un.lsRjtError, cmdiocb,
268 ndlp);
269 return 0;
270 }
271 }
272 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
273 lp = (uint32_t *) pcmd->virt;
274 sp = (struct serv_parm *) ((uint8_t *) lp + sizeof (uint32_t));
275 if ((lpfc_check_sparm(phba, ndlp, sp, CLASS3) == 0)) {
276 /* Reject this request because invalid parameters */
277 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
278 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
279 lpfc_els_rsp_reject(phba, stat.un.lsRjtError, cmdiocb, ndlp);
c9f8735b 280 return 0;
dea3101e 281 }
282 icmd = &cmdiocb->iocb;
283
284 /* PLOGI chkparm OK */
285 lpfc_printf_log(phba,
286 KERN_INFO,
287 LOG_ELS,
288 "%d:0114 PLOGI chkparm OK Data: x%x x%x x%x x%x\n",
289 phba->brd_no,
290 ndlp->nlp_DID, ndlp->nlp_state, ndlp->nlp_flag,
291 ndlp->nlp_rpi);
292
293 if ((phba->cfg_fcp_class == 2) &&
294 (sp->cls2.classValid)) {
295 ndlp->nlp_fcp_info |= CLASS2;
296 } else {
297 ndlp->nlp_fcp_info |= CLASS3;
298 }
299 ndlp->nlp_class_sup = 0;
300 if (sp->cls1.classValid)
301 ndlp->nlp_class_sup |= FC_COS_CLASS1;
302 if (sp->cls2.classValid)
303 ndlp->nlp_class_sup |= FC_COS_CLASS2;
304 if (sp->cls3.classValid)
305 ndlp->nlp_class_sup |= FC_COS_CLASS3;
306 if (sp->cls4.classValid)
307 ndlp->nlp_class_sup |= FC_COS_CLASS4;
308 ndlp->nlp_maxframe =
309 ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) | sp->cmn.bbRcvSizeLsb;
310
311 /* no need to reg_login if we are already in one of these states */
2fe165b6 312 switch (ndlp->nlp_state) {
dea3101e 313 case NLP_STE_NPR_NODE:
314 if (!(ndlp->nlp_flag & NLP_NPR_ADISC))
315 break;
316 case NLP_STE_REG_LOGIN_ISSUE:
317 case NLP_STE_PRLI_ISSUE:
318 case NLP_STE_UNMAPPED_NODE:
319 case NLP_STE_MAPPED_NODE:
320 lpfc_els_rsp_acc(phba, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL, 0);
c9f8735b 321 return 1;
dea3101e 322 }
323
324 if ((phba->fc_flag & FC_PT2PT)
325 && !(phba->fc_flag & FC_PT2PT_PLOGI)) {
326 /* rcv'ed PLOGI decides what our NPortId will be */
327 phba->fc_myDID = icmd->un.rcvels.parmRo;
328 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
329 if (mbox == NULL)
330 goto out;
331 lpfc_config_link(phba, mbox);
332 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
333 rc = lpfc_sli_issue_mbox
334 (phba, mbox, (MBX_NOWAIT | MBX_STOP_IOCB));
335 if (rc == MBX_NOT_FINISHED) {
336 mempool_free( mbox, phba->mbox_mem_pool);
337 goto out;
338 }
339
340 lpfc_can_disctmo(phba);
341 }
342 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
343 if (mbox == NULL)
344 goto out;
345
346 if (lpfc_reg_login(phba, icmd->un.rcvels.remoteID,
347 (uint8_t *) sp, mbox, 0)) {
348 mempool_free( mbox, phba->mbox_mem_pool);
349 goto out;
350 }
351
352 /* ACC PLOGI rsp command needs to execute first,
353 * queue this mbox command to be processed later.
354 */
355 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
356 mbox->context2 = ndlp;
5024ab17 357 ndlp->nlp_flag |= (NLP_ACC_REGLOGIN | NLP_RCV_PLOGI);
dea3101e 358
33ccf8d1
JS
359 /*
360 * If there is an outstanding PLOGI issued, abort it before
361 * sending ACC rsp for received PLOGI. If pending plogi
362 * is not canceled here, the plogi will be rejected by
363 * remote port and will be retried. On a configuration with
364 * single discovery thread, this will cause a huge delay in
365 * discovery. Also this will cause multiple state machines
366 * running in parallel for this node.
367 */
368 if (ndlp->nlp_state == NLP_STE_PLOGI_ISSUE) {
369 /* software abort outstanding PLOGI */
07951076 370 lpfc_els_abort(phba, ndlp);
33ccf8d1
JS
371 }
372
dea3101e 373 lpfc_els_rsp_acc(phba, ELS_CMD_PLOGI, cmdiocb, ndlp, mbox, 0);
c9f8735b 374 return 1;
dea3101e 375
376out:
377 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
378 stat.un.b.lsRjtRsnCodeExp = LSEXP_OUT_OF_RESOURCE;
379 lpfc_els_rsp_reject(phba, stat.un.lsRjtError, cmdiocb, ndlp);
c9f8735b 380 return 0;
dea3101e 381}
382
383static int
384lpfc_rcv_padisc(struct lpfc_hba * phba,
385 struct lpfc_nodelist * ndlp,
386 struct lpfc_iocbq *cmdiocb)
387{
388 struct lpfc_dmabuf *pcmd;
389 struct serv_parm *sp;
390 struct lpfc_name *pnn, *ppn;
391 struct ls_rjt stat;
392 ADISC *ap;
393 IOCB_t *icmd;
394 uint32_t *lp;
395 uint32_t cmd;
396
397 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
398 lp = (uint32_t *) pcmd->virt;
399
400 cmd = *lp++;
401 if (cmd == ELS_CMD_ADISC) {
402 ap = (ADISC *) lp;
403 pnn = (struct lpfc_name *) & ap->nodeName;
404 ppn = (struct lpfc_name *) & ap->portName;
405 } else {
406 sp = (struct serv_parm *) lp;
407 pnn = (struct lpfc_name *) & sp->nodeName;
408 ppn = (struct lpfc_name *) & sp->portName;
409 }
410
411 icmd = &cmdiocb->iocb;
412 if ((icmd->ulpStatus == 0) &&
413 (lpfc_check_adisc(phba, ndlp, pnn, ppn))) {
414 if (cmd == ELS_CMD_ADISC) {
415 lpfc_els_rsp_adisc_acc(phba, cmdiocb, ndlp);
2fe165b6 416 } else {
dea3101e 417 lpfc_els_rsp_acc(phba, ELS_CMD_PLOGI, cmdiocb, ndlp,
418 NULL, 0);
419 }
c9f8735b 420 return 1;
dea3101e 421 }
422 /* Reject this request because invalid parameters */
423 stat.un.b.lsRjtRsvd0 = 0;
424 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
425 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
426 stat.un.b.vendorUnique = 0;
427 lpfc_els_rsp_reject(phba, stat.un.lsRjtError, cmdiocb, ndlp);
428
dea3101e 429 /* 1 sec timeout */
430 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ);
431
432 spin_lock_irq(phba->host->host_lock);
433 ndlp->nlp_flag |= NLP_DELAY_TMO;
434 spin_unlock_irq(phba->host->host_lock);
5024ab17
JW
435 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
436 ndlp->nlp_prev_state = ndlp->nlp_state;
de0c5b32 437 lpfc_nlp_set_state(phba, ndlp, NLP_STE_NPR_NODE);
c9f8735b 438 return 0;
dea3101e 439}
440
441static int
442lpfc_rcv_logo(struct lpfc_hba * phba,
443 struct lpfc_nodelist * ndlp,
82d9a2a2
JS
444 struct lpfc_iocbq *cmdiocb,
445 uint32_t els_cmd)
dea3101e 446{
447 /* Put ndlp on NPR list with 1 sec timeout for plogi, ACC logo */
448 /* Only call LOGO ACC for first LOGO, this avoids sending unnecessary
449 * PLOGIs during LOGO storms from a device.
450 */
451 ndlp->nlp_flag |= NLP_LOGO_ACC;
82d9a2a2
JS
452 if (els_cmd == ELS_CMD_PRLO)
453 lpfc_els_rsp_acc(phba, ELS_CMD_PRLO, cmdiocb, ndlp, NULL, 0);
454 else
455 lpfc_els_rsp_acc(phba, ELS_CMD_ACC, cmdiocb, ndlp, NULL, 0);
dea3101e 456
c9f8735b
JW
457 if (!(ndlp->nlp_type & NLP_FABRIC) ||
458 (ndlp->nlp_state == NLP_STE_ADISC_ISSUE)) {
dea3101e 459 /* Only try to re-login if this is NOT a Fabric Node */
dea3101e 460 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1);
461 spin_lock_irq(phba->host->host_lock);
462 ndlp->nlp_flag |= NLP_DELAY_TMO;
463 spin_unlock_irq(phba->host->host_lock);
dea3101e 464
5024ab17
JW
465 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
466 ndlp->nlp_prev_state = ndlp->nlp_state;
de0c5b32 467 lpfc_nlp_set_state(phba, ndlp, NLP_STE_NPR_NODE);
c9f8735b 468 } else {
5024ab17 469 ndlp->nlp_prev_state = ndlp->nlp_state;
de0c5b32 470 lpfc_nlp_set_state(phba, ndlp, NLP_STE_UNUSED_NODE);
c9f8735b 471 }
dea3101e 472
c9f8735b 473 spin_lock_irq(phba->host->host_lock);
dea3101e 474 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
c9f8735b 475 spin_unlock_irq(phba->host->host_lock);
dea3101e 476 /* The driver has to wait until the ACC completes before it continues
477 * processing the LOGO. The action will resume in
478 * lpfc_cmpl_els_logo_acc routine. Since part of processing includes an
479 * unreg_login, the driver waits so the ACC does not get aborted.
480 */
c9f8735b 481 return 0;
dea3101e 482}
483
484static void
485lpfc_rcv_prli(struct lpfc_hba * phba,
486 struct lpfc_nodelist * ndlp,
487 struct lpfc_iocbq *cmdiocb)
488{
489 struct lpfc_dmabuf *pcmd;
490 uint32_t *lp;
491 PRLI *npr;
492 struct fc_rport *rport = ndlp->rport;
493 u32 roles;
494
495 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
496 lp = (uint32_t *) pcmd->virt;
497 npr = (PRLI *) ((uint8_t *) lp + sizeof (uint32_t));
498
499 ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
500 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
501 if ((npr->acceptRspCode == PRLI_REQ_EXECUTED) &&
502 (npr->prliType == PRLI_FCP_TYPE)) {
503 if (npr->initiatorFunc)
504 ndlp->nlp_type |= NLP_FCP_INITIATOR;
505 if (npr->targetFunc)
506 ndlp->nlp_type |= NLP_FCP_TARGET;
507 if (npr->Retry)
508 ndlp->nlp_fcp_info |= NLP_FCP_2_DEVICE;
509 }
510 if (rport) {
511 /* We need to update the rport role values */
512 roles = FC_RPORT_ROLE_UNKNOWN;
513 if (ndlp->nlp_type & NLP_FCP_INITIATOR)
514 roles |= FC_RPORT_ROLE_FCP_INITIATOR;
515 if (ndlp->nlp_type & NLP_FCP_TARGET)
516 roles |= FC_RPORT_ROLE_FCP_TARGET;
517 fc_remote_port_rolechg(rport, roles);
518 }
519}
520
521static uint32_t
522lpfc_disc_set_adisc(struct lpfc_hba * phba,
523 struct lpfc_nodelist * ndlp)
524{
525 /* Check config parameter use-adisc or FCP-2 */
526 if ((phba->cfg_use_adisc == 0) &&
527 !(phba->fc_flag & FC_RSCN_MODE)) {
528 if (!(ndlp->nlp_fcp_info & NLP_FCP_2_DEVICE))
c9f8735b 529 return 0;
dea3101e 530 }
531 spin_lock_irq(phba->host->host_lock);
532 ndlp->nlp_flag |= NLP_NPR_ADISC;
533 spin_unlock_irq(phba->host->host_lock);
c9f8735b 534 return 1;
dea3101e 535}
536
537static uint32_t
538lpfc_disc_illegal(struct lpfc_hba * phba,
539 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
540{
541 lpfc_printf_log(phba,
542 KERN_ERR,
543 LOG_DISCOVERY,
544 "%d:0253 Illegal State Transition: node x%x event x%x, "
545 "state x%x Data: x%x x%x\n",
546 phba->brd_no,
547 ndlp->nlp_DID, evt, ndlp->nlp_state, ndlp->nlp_rpi,
548 ndlp->nlp_flag);
c9f8735b 549 return ndlp->nlp_state;
dea3101e 550}
551
552/* Start of Discovery State Machine routines */
553
554static uint32_t
555lpfc_rcv_plogi_unused_node(struct lpfc_hba * phba,
556 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
557{
558 struct lpfc_iocbq *cmdiocb;
559
560 cmdiocb = (struct lpfc_iocbq *) arg;
561
562 if (lpfc_rcv_plogi(phba, ndlp, cmdiocb)) {
5024ab17 563 ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE;
de0c5b32 564 lpfc_nlp_set_state(phba, ndlp, NLP_STE_UNUSED_NODE);
c9f8735b 565 return ndlp->nlp_state;
dea3101e 566 }
de0c5b32 567 lpfc_drop_node(phba, ndlp);
c9f8735b 568 return NLP_STE_FREED_NODE;
dea3101e 569}
570
571static uint32_t
572lpfc_rcv_els_unused_node(struct lpfc_hba * phba,
573 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
574{
575 lpfc_issue_els_logo(phba, ndlp, 0);
de0c5b32 576 lpfc_nlp_set_state(phba, ndlp, NLP_STE_UNUSED_NODE);
c9f8735b 577 return ndlp->nlp_state;
dea3101e 578}
579
580static uint32_t
581lpfc_rcv_logo_unused_node(struct lpfc_hba * phba,
582 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
583{
584 struct lpfc_iocbq *cmdiocb;
585
586 cmdiocb = (struct lpfc_iocbq *) arg;
587
588 spin_lock_irq(phba->host->host_lock);
589 ndlp->nlp_flag |= NLP_LOGO_ACC;
590 spin_unlock_irq(phba->host->host_lock);
591 lpfc_els_rsp_acc(phba, ELS_CMD_ACC, cmdiocb, ndlp, NULL, 0);
de0c5b32 592 lpfc_nlp_set_state(phba, ndlp, NLP_STE_UNUSED_NODE);
dea3101e 593
c9f8735b 594 return ndlp->nlp_state;
dea3101e 595}
596
597static uint32_t
598lpfc_cmpl_logo_unused_node(struct lpfc_hba * phba,
599 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
600{
de0c5b32 601 lpfc_drop_node(phba, ndlp);
c9f8735b 602 return NLP_STE_FREED_NODE;
dea3101e 603}
604
605static uint32_t
606lpfc_device_rm_unused_node(struct lpfc_hba * phba,
607 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
608{
de0c5b32 609 lpfc_drop_node(phba, ndlp);
c9f8735b 610 return NLP_STE_FREED_NODE;
dea3101e 611}
612
613static uint32_t
614lpfc_rcv_plogi_plogi_issue(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp,
615 void *arg, uint32_t evt)
616{
617 struct lpfc_iocbq *cmdiocb = arg;
618 struct lpfc_dmabuf *pcmd;
619 struct serv_parm *sp;
620 uint32_t *lp;
621 struct ls_rjt stat;
622 int port_cmp;
623
624 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
625 lp = (uint32_t *) pcmd->virt;
626 sp = (struct serv_parm *) ((uint8_t *) lp + sizeof (uint32_t));
627
628 memset(&stat, 0, sizeof (struct ls_rjt));
629
630 /* For a PLOGI, we only accept if our portname is less
631 * than the remote portname.
632 */
633 phba->fc_stat.elsLogiCol++;
634 port_cmp = memcmp(&phba->fc_portname, &sp->portName,
635 sizeof (struct lpfc_name));
636
637 if (port_cmp >= 0) {
638 /* Reject this request because the remote node will accept
639 ours */
640 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
641 stat.un.b.lsRjtRsnCodeExp = LSEXP_CMD_IN_PROGRESS;
642 lpfc_els_rsp_reject(phba, stat.un.lsRjtError, cmdiocb, ndlp);
2fe165b6 643 } else {
dea3101e 644 lpfc_rcv_plogi(phba, ndlp, cmdiocb);
645 } /* if our portname was less */
646
c9f8735b
JW
647 return ndlp->nlp_state;
648}
649
650static uint32_t
651lpfc_rcv_logo_plogi_issue(struct lpfc_hba * phba,
652 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
653{
654 struct lpfc_iocbq *cmdiocb;
655
656 cmdiocb = (struct lpfc_iocbq *) arg;
657
658 /* software abort outstanding PLOGI */
07951076 659 lpfc_els_abort(phba, ndlp);
c9f8735b 660
82d9a2a2 661 lpfc_rcv_logo(phba, ndlp, cmdiocb, ELS_CMD_LOGO);
c9f8735b 662 return ndlp->nlp_state;
dea3101e 663}
664
665static uint32_t
666lpfc_rcv_els_plogi_issue(struct lpfc_hba * phba,
667 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
668{
669 struct lpfc_iocbq *cmdiocb;
670
671 cmdiocb = (struct lpfc_iocbq *) arg;
672
673 /* software abort outstanding PLOGI */
07951076 674 lpfc_els_abort(phba, ndlp);
dea3101e 675
676 if (evt == NLP_EVT_RCV_LOGO) {
677 lpfc_els_rsp_acc(phba, ELS_CMD_ACC, cmdiocb, ndlp, NULL, 0);
2fe165b6 678 } else {
dea3101e 679 lpfc_issue_els_logo(phba, ndlp, 0);
680 }
681
682 /* Put ndlp in npr list set plogi timer for 1 sec */
5024ab17
JW
683 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1);
684 spin_lock_irq(phba->host->host_lock);
685 ndlp->nlp_flag |= NLP_DELAY_TMO;
686 spin_unlock_irq(phba->host->host_lock);
687 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
688 ndlp->nlp_prev_state = NLP_STE_PLOGI_ISSUE;
de0c5b32 689 lpfc_nlp_set_state(phba, ndlp, NLP_STE_NPR_NODE);
dea3101e 690
c9f8735b 691 return ndlp->nlp_state;
dea3101e 692}
693
694static uint32_t
695lpfc_cmpl_plogi_plogi_issue(struct lpfc_hba * phba,
696 struct lpfc_nodelist * ndlp, void *arg,
697 uint32_t evt)
698{
699 struct lpfc_iocbq *cmdiocb, *rspiocb;
14691150 700 struct lpfc_dmabuf *pcmd, *prsp, *mp;
dea3101e 701 uint32_t *lp;
702 IOCB_t *irsp;
703 struct serv_parm *sp;
704 LPFC_MBOXQ_t *mbox;
705
706 cmdiocb = (struct lpfc_iocbq *) arg;
707 rspiocb = cmdiocb->context_un.rsp_iocb;
708
709 if (ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
5024ab17 710 /* Recovery from PLOGI collision logic */
c9f8735b 711 return ndlp->nlp_state;
dea3101e 712 }
713
714 irsp = &rspiocb->iocb;
715
716 if (irsp->ulpStatus)
717 goto out;
718
719 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
720
721 prsp = list_get_first(&pcmd->list,
722 struct lpfc_dmabuf,
723 list);
724 lp = (uint32_t *) prsp->virt;
725
726 sp = (struct serv_parm *) ((uint8_t *) lp + sizeof (uint32_t));
727 if (!lpfc_check_sparm(phba, ndlp, sp, CLASS3))
728 goto out;
729
730 /* PLOGI chkparm OK */
731 lpfc_printf_log(phba,
732 KERN_INFO,
733 LOG_ELS,
734 "%d:0121 PLOGI chkparm OK "
735 "Data: x%x x%x x%x x%x\n",
736 phba->brd_no,
737 ndlp->nlp_DID, ndlp->nlp_state,
738 ndlp->nlp_flag, ndlp->nlp_rpi);
739
740 if ((phba->cfg_fcp_class == 2) &&
741 (sp->cls2.classValid)) {
742 ndlp->nlp_fcp_info |= CLASS2;
743 } else {
744 ndlp->nlp_fcp_info |= CLASS3;
745 }
746 ndlp->nlp_class_sup = 0;
747 if (sp->cls1.classValid)
748 ndlp->nlp_class_sup |= FC_COS_CLASS1;
749 if (sp->cls2.classValid)
750 ndlp->nlp_class_sup |= FC_COS_CLASS2;
751 if (sp->cls3.classValid)
752 ndlp->nlp_class_sup |= FC_COS_CLASS3;
753 if (sp->cls4.classValid)
754 ndlp->nlp_class_sup |= FC_COS_CLASS4;
755 ndlp->nlp_maxframe =
756 ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) |
757 sp->cmn.bbRcvSizeLsb;
758
759 if (!(mbox = mempool_alloc(phba->mbox_mem_pool,
760 GFP_KERNEL)))
761 goto out;
762
763 lpfc_unreg_rpi(phba, ndlp);
de0c5b32
JS
764 if (lpfc_reg_login(phba, irsp->un.elsreq64.remoteID, (uint8_t *) sp,
765 mbox, 0) == 0) {
2fe165b6 766 switch (ndlp->nlp_DID) {
dea3101e 767 case NameServer_DID:
de0c5b32 768 mbox->mbox_cmpl = lpfc_mbx_cmpl_ns_reg_login;
dea3101e 769 break;
770 case FDMI_DID:
de0c5b32 771 mbox->mbox_cmpl = lpfc_mbx_cmpl_fdmi_reg_login;
dea3101e 772 break;
773 default:
de0c5b32 774 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
dea3101e 775 }
776 mbox->context2 = ndlp;
777 if (lpfc_sli_issue_mbox(phba, mbox,
778 (MBX_NOWAIT | MBX_STOP_IOCB))
779 != MBX_NOT_FINISHED) {
de0c5b32 780 lpfc_nlp_set_state(phba, ndlp, NLP_STE_REG_LOGIN_ISSUE);
c9f8735b 781 return ndlp->nlp_state;
dea3101e 782 }
14691150
JS
783 mp = (struct lpfc_dmabuf *)mbox->context1;
784 lpfc_mbuf_free(phba, mp->virt, mp->phys);
785 kfree(mp);
dea3101e 786 mempool_free(mbox, phba->mbox_mem_pool);
787 } else {
788 mempool_free(mbox, phba->mbox_mem_pool);
789 }
790
791
792 out:
793 /* Free this node since the driver cannot login or has the wrong
794 sparm */
de0c5b32 795 lpfc_drop_node(phba, ndlp);
c9f8735b 796 return NLP_STE_FREED_NODE;
dea3101e 797}
798
799static uint32_t
800lpfc_device_rm_plogi_issue(struct lpfc_hba * phba,
801 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
802{
a0f9b48d
JS
803 if(ndlp->nlp_flag & NLP_NPR_2B_DISC) {
804 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
805 return ndlp->nlp_state;
806 }
807 else {
808 /* software abort outstanding PLOGI */
07951076 809 lpfc_els_abort(phba, ndlp);
dea3101e 810
de0c5b32 811 lpfc_drop_node(phba, ndlp);
a0f9b48d
JS
812 return NLP_STE_FREED_NODE;
813 }
dea3101e 814}
815
816static uint32_t
817lpfc_device_recov_plogi_issue(struct lpfc_hba * phba,
818 struct lpfc_nodelist * ndlp, void *arg,
819 uint32_t evt)
820{
821 /* software abort outstanding PLOGI */
07951076 822 lpfc_els_abort(phba, ndlp);
dea3101e 823
5024ab17 824 ndlp->nlp_prev_state = NLP_STE_PLOGI_ISSUE;
de0c5b32 825 lpfc_nlp_set_state(phba, ndlp, NLP_STE_NPR_NODE);
dea3101e 826 spin_lock_irq(phba->host->host_lock);
a0f9b48d 827 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
dea3101e 828 spin_unlock_irq(phba->host->host_lock);
829
c9f8735b 830 return ndlp->nlp_state;
dea3101e 831}
832
833static uint32_t
834lpfc_rcv_plogi_adisc_issue(struct lpfc_hba * phba,
835 struct lpfc_nodelist * ndlp, void *arg,
836 uint32_t evt)
837{
838 struct lpfc_iocbq *cmdiocb;
839
840 /* software abort outstanding ADISC */
07951076 841 lpfc_els_abort(phba, ndlp);
dea3101e 842
843 cmdiocb = (struct lpfc_iocbq *) arg;
844
845 if (lpfc_rcv_plogi(phba, ndlp, cmdiocb)) {
c9f8735b 846 return ndlp->nlp_state;
dea3101e 847 }
5024ab17 848 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
de0c5b32 849 lpfc_nlp_set_state(phba, ndlp, NLP_STE_PLOGI_ISSUE);
488d1469 850 lpfc_issue_els_plogi(phba, ndlp->nlp_DID, 0);
dea3101e 851
c9f8735b 852 return ndlp->nlp_state;
dea3101e 853}
854
855static uint32_t
856lpfc_rcv_prli_adisc_issue(struct lpfc_hba * phba,
857 struct lpfc_nodelist * ndlp, void *arg,
858 uint32_t evt)
859{
860 struct lpfc_iocbq *cmdiocb;
861
862 cmdiocb = (struct lpfc_iocbq *) arg;
863
864 lpfc_els_rsp_prli_acc(phba, cmdiocb, ndlp);
c9f8735b 865 return ndlp->nlp_state;
dea3101e 866}
867
868static uint32_t
869lpfc_rcv_logo_adisc_issue(struct lpfc_hba * phba,
870 struct lpfc_nodelist * ndlp, void *arg,
871 uint32_t evt)
872{
873 struct lpfc_iocbq *cmdiocb;
874
875 cmdiocb = (struct lpfc_iocbq *) arg;
876
877 /* software abort outstanding ADISC */
07951076 878 lpfc_els_abort(phba, ndlp);
dea3101e 879
82d9a2a2 880 lpfc_rcv_logo(phba, ndlp, cmdiocb, ELS_CMD_LOGO);
c9f8735b 881 return ndlp->nlp_state;
dea3101e 882}
883
884static uint32_t
885lpfc_rcv_padisc_adisc_issue(struct lpfc_hba * phba,
886 struct lpfc_nodelist * ndlp, void *arg,
887 uint32_t evt)
888{
889 struct lpfc_iocbq *cmdiocb;
890
891 cmdiocb = (struct lpfc_iocbq *) arg;
892
893 lpfc_rcv_padisc(phba, ndlp, cmdiocb);
c9f8735b 894 return ndlp->nlp_state;
dea3101e 895}
896
897static uint32_t
898lpfc_rcv_prlo_adisc_issue(struct lpfc_hba * phba,
899 struct lpfc_nodelist * ndlp, void *arg,
900 uint32_t evt)
901{
902 struct lpfc_iocbq *cmdiocb;
903
904 cmdiocb = (struct lpfc_iocbq *) arg;
905
906 /* Treat like rcv logo */
82d9a2a2 907 lpfc_rcv_logo(phba, ndlp, cmdiocb, ELS_CMD_PRLO);
c9f8735b 908 return ndlp->nlp_state;
dea3101e 909}
910
911static uint32_t
912lpfc_cmpl_adisc_adisc_issue(struct lpfc_hba * phba,
913 struct lpfc_nodelist * ndlp, void *arg,
914 uint32_t evt)
915{
916 struct lpfc_iocbq *cmdiocb, *rspiocb;
917 IOCB_t *irsp;
918 ADISC *ap;
919
920 cmdiocb = (struct lpfc_iocbq *) arg;
921 rspiocb = cmdiocb->context_un.rsp_iocb;
922
923 ap = (ADISC *)lpfc_check_elscmpl_iocb(phba, cmdiocb, rspiocb);
924 irsp = &rspiocb->iocb;
925
926 if ((irsp->ulpStatus) ||
927 (!lpfc_check_adisc(phba, ndlp, &ap->nodeName, &ap->portName))) {
dea3101e 928 /* 1 sec timeout */
929 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ);
930 spin_lock_irq(phba->host->host_lock);
931 ndlp->nlp_flag |= NLP_DELAY_TMO;
932 spin_unlock_irq(phba->host->host_lock);
5024ab17 933 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
dea3101e 934
935 memset(&ndlp->nlp_nodename, 0, sizeof (struct lpfc_name));
936 memset(&ndlp->nlp_portname, 0, sizeof (struct lpfc_name));
937
5024ab17 938 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
de0c5b32 939 lpfc_nlp_set_state(phba, ndlp, NLP_STE_NPR_NODE);
dea3101e 940 lpfc_unreg_rpi(phba, ndlp);
c9f8735b 941 return ndlp->nlp_state;
dea3101e 942 }
5024ab17 943
2501322e 944 if (ndlp->nlp_type & NLP_FCP_TARGET) {
5024ab17 945 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
de0c5b32 946 lpfc_nlp_set_state(phba, ndlp, NLP_STE_MAPPED_NODE);
2501322e 947 } else {
5024ab17 948 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
de0c5b32 949 lpfc_nlp_set_state(phba, ndlp, NLP_STE_UNMAPPED_NODE);
2501322e 950 }
c9f8735b 951 return ndlp->nlp_state;
dea3101e 952}
953
954static uint32_t
955lpfc_device_rm_adisc_issue(struct lpfc_hba * phba,
956 struct lpfc_nodelist * ndlp, void *arg,
957 uint32_t evt)
958{
a0f9b48d
JS
959 if(ndlp->nlp_flag & NLP_NPR_2B_DISC) {
960 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
961 return ndlp->nlp_state;
962 }
963 else {
964 /* software abort outstanding ADISC */
07951076 965 lpfc_els_abort(phba, ndlp);
dea3101e 966
de0c5b32 967 lpfc_drop_node(phba, ndlp);
a0f9b48d
JS
968 return NLP_STE_FREED_NODE;
969 }
dea3101e 970}
971
972static uint32_t
973lpfc_device_recov_adisc_issue(struct lpfc_hba * phba,
974 struct lpfc_nodelist * ndlp, void *arg,
975 uint32_t evt)
976{
977 /* software abort outstanding ADISC */
07951076 978 lpfc_els_abort(phba, ndlp);
dea3101e 979
5024ab17 980 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
de0c5b32 981 lpfc_nlp_set_state(phba, ndlp, NLP_STE_NPR_NODE);
dea3101e 982 spin_lock_irq(phba->host->host_lock);
a0f9b48d 983 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
c9f8735b 984 ndlp->nlp_flag |= NLP_NPR_ADISC;
dea3101e 985 spin_unlock_irq(phba->host->host_lock);
986
c9f8735b 987 return ndlp->nlp_state;
dea3101e 988}
989
990static uint32_t
991lpfc_rcv_plogi_reglogin_issue(struct lpfc_hba * phba,
992 struct lpfc_nodelist * ndlp, void *arg,
993 uint32_t evt)
994{
995 struct lpfc_iocbq *cmdiocb;
996
997 cmdiocb = (struct lpfc_iocbq *) arg;
998
999 lpfc_rcv_plogi(phba, ndlp, cmdiocb);
c9f8735b 1000 return ndlp->nlp_state;
dea3101e 1001}
1002
1003static uint32_t
1004lpfc_rcv_prli_reglogin_issue(struct lpfc_hba * phba,
1005 struct lpfc_nodelist * ndlp, void *arg,
1006 uint32_t evt)
1007{
1008 struct lpfc_iocbq *cmdiocb;
1009
1010 cmdiocb = (struct lpfc_iocbq *) arg;
1011
1012 lpfc_els_rsp_prli_acc(phba, cmdiocb, ndlp);
c9f8735b 1013 return ndlp->nlp_state;
dea3101e 1014}
1015
1016static uint32_t
1017lpfc_rcv_logo_reglogin_issue(struct lpfc_hba * phba,
1018 struct lpfc_nodelist * ndlp, void *arg,
1019 uint32_t evt)
1020{
1021 struct lpfc_iocbq *cmdiocb;
1022
1023 cmdiocb = (struct lpfc_iocbq *) arg;
1024
82d9a2a2 1025 lpfc_rcv_logo(phba, ndlp, cmdiocb, ELS_CMD_LOGO);
c9f8735b 1026 return ndlp->nlp_state;
dea3101e 1027}
1028
1029static uint32_t
1030lpfc_rcv_padisc_reglogin_issue(struct lpfc_hba * phba,
1031 struct lpfc_nodelist * ndlp, void *arg,
1032 uint32_t evt)
1033{
1034 struct lpfc_iocbq *cmdiocb;
1035
1036 cmdiocb = (struct lpfc_iocbq *) arg;
1037
1038 lpfc_rcv_padisc(phba, ndlp, cmdiocb);
c9f8735b 1039 return ndlp->nlp_state;
dea3101e 1040}
1041
1042static uint32_t
1043lpfc_rcv_prlo_reglogin_issue(struct lpfc_hba * phba,
1044 struct lpfc_nodelist * ndlp, void *arg,
1045 uint32_t evt)
1046{
1047 struct lpfc_iocbq *cmdiocb;
1048
1049 cmdiocb = (struct lpfc_iocbq *) arg;
82d9a2a2 1050 lpfc_els_rsp_acc(phba, ELS_CMD_PRLO, cmdiocb, ndlp, NULL, 0);
c9f8735b 1051 return ndlp->nlp_state;
dea3101e 1052}
1053
1054static uint32_t
1055lpfc_cmpl_reglogin_reglogin_issue(struct lpfc_hba * phba,
1056 struct lpfc_nodelist * ndlp,
1057 void *arg, uint32_t evt)
1058{
1059 LPFC_MBOXQ_t *pmb;
1060 MAILBOX_t *mb;
1061 uint32_t did;
1062
1063 pmb = (LPFC_MBOXQ_t *) arg;
1064 mb = &pmb->mb;
1065 did = mb->un.varWords[1];
1066 if (mb->mbxStatus) {
1067 /* RegLogin failed */
1068 lpfc_printf_log(phba,
1069 KERN_ERR,
1070 LOG_DISCOVERY,
1071 "%d:0246 RegLogin failed Data: x%x x%x x%x\n",
1072 phba->brd_no,
1073 did, mb->mbxStatus, phba->hba_state);
1074
d0e56dad
JS
1075 /*
1076 * If RegLogin failed due to lack of HBA resources do not
1077 * retry discovery.
1078 */
1079 if (mb->mbxStatus == MBXERR_RPI_FULL) {
1080 ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE;
de0c5b32 1081 lpfc_nlp_set_state(phba, ndlp, NLP_STE_UNUSED_NODE);
d0e56dad
JS
1082 return ndlp->nlp_state;
1083 }
1084
5024ab17 1085 /* Put ndlp in npr list set plogi timer for 1 sec */
dea3101e 1086 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1);
1087 spin_lock_irq(phba->host->host_lock);
1088 ndlp->nlp_flag |= NLP_DELAY_TMO;
1089 spin_unlock_irq(phba->host->host_lock);
5024ab17 1090 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
dea3101e 1091
1092 lpfc_issue_els_logo(phba, ndlp, 0);
5024ab17 1093 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
de0c5b32 1094 lpfc_nlp_set_state(phba, ndlp, NLP_STE_NPR_NODE);
c9f8735b 1095 return ndlp->nlp_state;
dea3101e 1096 }
1097
dea3101e 1098 ndlp->nlp_rpi = mb->un.varWords[0];
dea3101e 1099
1100 /* Only if we are not a fabric nport do we issue PRLI */
1101 if (!(ndlp->nlp_type & NLP_FABRIC)) {
5024ab17 1102 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
de0c5b32 1103 lpfc_nlp_set_state(phba, ndlp, NLP_STE_PRLI_ISSUE);
dea3101e 1104 lpfc_issue_els_prli(phba, ndlp, 0);
1105 } else {
5024ab17 1106 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
de0c5b32 1107 lpfc_nlp_set_state(phba, ndlp, NLP_STE_UNMAPPED_NODE);
dea3101e 1108 }
c9f8735b 1109 return ndlp->nlp_state;
dea3101e 1110}
1111
1112static uint32_t
1113lpfc_device_rm_reglogin_issue(struct lpfc_hba * phba,
1114 struct lpfc_nodelist * ndlp, void *arg,
1115 uint32_t evt)
1116{
a0f9b48d
JS
1117 if(ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1118 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
1119 return ndlp->nlp_state;
1120 }
1121 else {
de0c5b32 1122 lpfc_drop_node(phba, ndlp);
a0f9b48d
JS
1123 return NLP_STE_FREED_NODE;
1124 }
dea3101e 1125}
1126
1127static uint32_t
1128lpfc_device_recov_reglogin_issue(struct lpfc_hba * phba,
1129 struct lpfc_nodelist * ndlp, void *arg,
1130 uint32_t evt)
1131{
5024ab17 1132 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
de0c5b32 1133 lpfc_nlp_set_state(phba, ndlp, NLP_STE_NPR_NODE);
dea3101e 1134 spin_lock_irq(phba->host->host_lock);
a0f9b48d 1135 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
dea3101e 1136 spin_unlock_irq(phba->host->host_lock);
c9f8735b 1137 return ndlp->nlp_state;
dea3101e 1138}
1139
1140static uint32_t
1141lpfc_rcv_plogi_prli_issue(struct lpfc_hba * phba,
1142 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1143{
1144 struct lpfc_iocbq *cmdiocb;
1145
1146 cmdiocb = (struct lpfc_iocbq *) arg;
1147
1148 lpfc_rcv_plogi(phba, ndlp, cmdiocb);
c9f8735b 1149 return ndlp->nlp_state;
dea3101e 1150}
1151
1152static uint32_t
1153lpfc_rcv_prli_prli_issue(struct lpfc_hba * phba,
1154 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1155{
1156 struct lpfc_iocbq *cmdiocb;
1157
1158 cmdiocb = (struct lpfc_iocbq *) arg;
1159
1160 lpfc_els_rsp_prli_acc(phba, cmdiocb, ndlp);
c9f8735b 1161 return ndlp->nlp_state;
dea3101e 1162}
1163
1164static uint32_t
1165lpfc_rcv_logo_prli_issue(struct lpfc_hba * phba,
1166 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1167{
1168 struct lpfc_iocbq *cmdiocb;
1169
1170 cmdiocb = (struct lpfc_iocbq *) arg;
1171
1172 /* Software abort outstanding PRLI before sending acc */
07951076 1173 lpfc_els_abort(phba, ndlp);
dea3101e 1174
82d9a2a2 1175 lpfc_rcv_logo(phba, ndlp, cmdiocb, ELS_CMD_LOGO);
c9f8735b 1176 return ndlp->nlp_state;
dea3101e 1177}
1178
1179static uint32_t
1180lpfc_rcv_padisc_prli_issue(struct lpfc_hba * phba,
1181 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1182{
1183 struct lpfc_iocbq *cmdiocb;
1184
1185 cmdiocb = (struct lpfc_iocbq *) arg;
1186
1187 lpfc_rcv_padisc(phba, ndlp, cmdiocb);
c9f8735b 1188 return ndlp->nlp_state;
dea3101e 1189}
1190
1191/* This routine is envoked when we rcv a PRLO request from a nport
1192 * we are logged into. We should send back a PRLO rsp setting the
1193 * appropriate bits.
1194 * NEXT STATE = PRLI_ISSUE
1195 */
1196static uint32_t
1197lpfc_rcv_prlo_prli_issue(struct lpfc_hba * phba,
1198 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1199{
1200 struct lpfc_iocbq *cmdiocb;
1201
1202 cmdiocb = (struct lpfc_iocbq *) arg;
82d9a2a2 1203 lpfc_els_rsp_acc(phba, ELS_CMD_PRLO, cmdiocb, ndlp, NULL, 0);
c9f8735b 1204 return ndlp->nlp_state;
dea3101e 1205}
1206
1207static uint32_t
1208lpfc_cmpl_prli_prli_issue(struct lpfc_hba * phba,
1209 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1210{
1211 struct lpfc_iocbq *cmdiocb, *rspiocb;
1212 IOCB_t *irsp;
1213 PRLI *npr;
1214
1215 cmdiocb = (struct lpfc_iocbq *) arg;
1216 rspiocb = cmdiocb->context_un.rsp_iocb;
1217 npr = (PRLI *)lpfc_check_elscmpl_iocb(phba, cmdiocb, rspiocb);
1218
1219 irsp = &rspiocb->iocb;
1220 if (irsp->ulpStatus) {
5024ab17 1221 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
de0c5b32 1222 lpfc_nlp_set_state(phba, ndlp, NLP_STE_UNMAPPED_NODE);
c9f8735b 1223 return ndlp->nlp_state;
dea3101e 1224 }
1225
1226 /* Check out PRLI rsp */
1227 ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
1228 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
1229 if ((npr->acceptRspCode == PRLI_REQ_EXECUTED) &&
1230 (npr->prliType == PRLI_FCP_TYPE)) {
1231 if (npr->initiatorFunc)
1232 ndlp->nlp_type |= NLP_FCP_INITIATOR;
1233 if (npr->targetFunc)
1234 ndlp->nlp_type |= NLP_FCP_TARGET;
1235 if (npr->Retry)
1236 ndlp->nlp_fcp_info |= NLP_FCP_2_DEVICE;
1237 }
1238
5024ab17 1239 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
de0c5b32 1240 lpfc_nlp_set_state(phba, ndlp, NLP_STE_MAPPED_NODE);
c9f8735b 1241 return ndlp->nlp_state;
dea3101e 1242}
1243
1244/*! lpfc_device_rm_prli_issue
1245 *
1246 * \pre
1247 * \post
1248 * \param phba
1249 * \param ndlp
1250 * \param arg
1251 * \param evt
1252 * \return uint32_t
1253 *
1254 * \b Description:
1255 * This routine is envoked when we a request to remove a nport we are in the
1256 * process of PRLIing. We should software abort outstanding prli, unreg
1257 * login, send a logout. We will change node state to UNUSED_NODE, put it
1258 * on plogi list so it can be freed when LOGO completes.
1259 *
1260 */
1261static uint32_t
1262lpfc_device_rm_prli_issue(struct lpfc_hba * phba,
1263 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1264{
a0f9b48d
JS
1265 if(ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1266 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
1267 return ndlp->nlp_state;
1268 }
1269 else {
1270 /* software abort outstanding PLOGI */
07951076 1271 lpfc_els_abort(phba, ndlp);
dea3101e 1272
de0c5b32 1273 lpfc_drop_node(phba, ndlp);
a0f9b48d
JS
1274 return NLP_STE_FREED_NODE;
1275 }
dea3101e 1276}
1277
1278
1279/*! lpfc_device_recov_prli_issue
1280 *
1281 * \pre
1282 * \post
1283 * \param phba
1284 * \param ndlp
1285 * \param arg
1286 * \param evt
1287 * \return uint32_t
1288 *
1289 * \b Description:
1290 * The routine is envoked when the state of a device is unknown, like
1291 * during a link down. We should remove the nodelist entry from the
1292 * unmapped list, issue a UNREG_LOGIN, do a software abort of the
1293 * outstanding PRLI command, then free the node entry.
1294 */
1295static uint32_t
1296lpfc_device_recov_prli_issue(struct lpfc_hba * phba,
1297 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1298{
1299 /* software abort outstanding PRLI */
07951076 1300 lpfc_els_abort(phba, ndlp);
dea3101e 1301
5024ab17 1302 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
de0c5b32 1303 lpfc_nlp_set_state(phba, ndlp, NLP_STE_NPR_NODE);
dea3101e 1304 spin_lock_irq(phba->host->host_lock);
a0f9b48d 1305 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
dea3101e 1306 spin_unlock_irq(phba->host->host_lock);
c9f8735b 1307 return ndlp->nlp_state;
dea3101e 1308}
1309
1310static uint32_t
1311lpfc_rcv_plogi_unmap_node(struct lpfc_hba * phba,
1312 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1313{
1314 struct lpfc_iocbq *cmdiocb;
1315
1316 cmdiocb = (struct lpfc_iocbq *) arg;
1317
1318 lpfc_rcv_plogi(phba, ndlp, cmdiocb);
c9f8735b 1319 return ndlp->nlp_state;
dea3101e 1320}
1321
1322static uint32_t
1323lpfc_rcv_prli_unmap_node(struct lpfc_hba * phba,
1324 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1325{
1326 struct lpfc_iocbq *cmdiocb;
1327
1328 cmdiocb = (struct lpfc_iocbq *) arg;
1329
1330 lpfc_rcv_prli(phba, ndlp, cmdiocb);
1331 lpfc_els_rsp_prli_acc(phba, cmdiocb, ndlp);
c9f8735b 1332 return ndlp->nlp_state;
dea3101e 1333}
1334
1335static uint32_t
1336lpfc_rcv_logo_unmap_node(struct lpfc_hba * phba,
1337 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1338{
1339 struct lpfc_iocbq *cmdiocb;
1340
1341 cmdiocb = (struct lpfc_iocbq *) arg;
1342
82d9a2a2 1343 lpfc_rcv_logo(phba, ndlp, cmdiocb, ELS_CMD_LOGO);
c9f8735b 1344 return ndlp->nlp_state;
dea3101e 1345}
1346
1347static uint32_t
1348lpfc_rcv_padisc_unmap_node(struct lpfc_hba * phba,
1349 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1350{
1351 struct lpfc_iocbq *cmdiocb;
1352
1353 cmdiocb = (struct lpfc_iocbq *) arg;
1354
1355 lpfc_rcv_padisc(phba, ndlp, cmdiocb);
c9f8735b 1356 return ndlp->nlp_state;
dea3101e 1357}
1358
1359static uint32_t
1360lpfc_rcv_prlo_unmap_node(struct lpfc_hba * phba,
1361 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1362{
1363 struct lpfc_iocbq *cmdiocb;
1364
1365 cmdiocb = (struct lpfc_iocbq *) arg;
1366
82d9a2a2 1367 lpfc_els_rsp_acc(phba, ELS_CMD_PRLO, cmdiocb, ndlp, NULL, 0);
c9f8735b 1368 return ndlp->nlp_state;
dea3101e 1369}
1370
1371static uint32_t
1372lpfc_device_recov_unmap_node(struct lpfc_hba * phba,
1373 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1374{
5024ab17 1375 ndlp->nlp_prev_state = NLP_STE_UNMAPPED_NODE;
de0c5b32 1376 lpfc_nlp_set_state(phba, ndlp, NLP_STE_NPR_NODE);
a0f9b48d 1377 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
dea3101e 1378 lpfc_disc_set_adisc(phba, ndlp);
1379
c9f8735b 1380 return ndlp->nlp_state;
dea3101e 1381}
1382
1383static uint32_t
1384lpfc_rcv_plogi_mapped_node(struct lpfc_hba * phba,
1385 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1386{
1387 struct lpfc_iocbq *cmdiocb;
1388
1389 cmdiocb = (struct lpfc_iocbq *) arg;
1390
1391 lpfc_rcv_plogi(phba, ndlp, cmdiocb);
c9f8735b 1392 return ndlp->nlp_state;
dea3101e 1393}
1394
1395static uint32_t
1396lpfc_rcv_prli_mapped_node(struct lpfc_hba * phba,
1397 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1398{
1399 struct lpfc_iocbq *cmdiocb;
1400
1401 cmdiocb = (struct lpfc_iocbq *) arg;
1402
1403 lpfc_els_rsp_prli_acc(phba, cmdiocb, ndlp);
c9f8735b 1404 return ndlp->nlp_state;
dea3101e 1405}
1406
1407static uint32_t
1408lpfc_rcv_logo_mapped_node(struct lpfc_hba * phba,
1409 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1410{
1411 struct lpfc_iocbq *cmdiocb;
1412
1413 cmdiocb = (struct lpfc_iocbq *) arg;
1414
82d9a2a2 1415 lpfc_rcv_logo(phba, ndlp, cmdiocb, ELS_CMD_LOGO);
c9f8735b 1416 return ndlp->nlp_state;
dea3101e 1417}
1418
1419static uint32_t
1420lpfc_rcv_padisc_mapped_node(struct lpfc_hba * phba,
1421 struct lpfc_nodelist * ndlp, void *arg,
1422 uint32_t evt)
1423{
1424 struct lpfc_iocbq *cmdiocb;
1425
1426 cmdiocb = (struct lpfc_iocbq *) arg;
1427
1428 lpfc_rcv_padisc(phba, ndlp, cmdiocb);
c9f8735b 1429 return ndlp->nlp_state;
dea3101e 1430}
1431
1432static uint32_t
1433lpfc_rcv_prlo_mapped_node(struct lpfc_hba * phba,
1434 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1435{
1436 struct lpfc_iocbq *cmdiocb;
1437
1438 cmdiocb = (struct lpfc_iocbq *) arg;
1439
1440 /* flush the target */
1441 spin_lock_irq(phba->host->host_lock);
1442 lpfc_sli_abort_iocb(phba, &phba->sli.ring[phba->sli.fcp_ring],
1443 ndlp->nlp_sid, 0, 0, LPFC_CTX_TGT);
1444 spin_unlock_irq(phba->host->host_lock);
1445
1446 /* Treat like rcv logo */
82d9a2a2 1447 lpfc_rcv_logo(phba, ndlp, cmdiocb, ELS_CMD_PRLO);
c9f8735b 1448 return ndlp->nlp_state;
dea3101e 1449}
1450
1451static uint32_t
1452lpfc_device_recov_mapped_node(struct lpfc_hba * phba,
1453 struct lpfc_nodelist * ndlp, void *arg,
1454 uint32_t evt)
1455{
5024ab17 1456 ndlp->nlp_prev_state = NLP_STE_MAPPED_NODE;
de0c5b32 1457 lpfc_nlp_set_state(phba, ndlp, NLP_STE_NPR_NODE);
dea3101e 1458 spin_lock_irq(phba->host->host_lock);
a0f9b48d 1459 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
dea3101e 1460 spin_unlock_irq(phba->host->host_lock);
1461 lpfc_disc_set_adisc(phba, ndlp);
c9f8735b 1462 return ndlp->nlp_state;
dea3101e 1463}
1464
1465static uint32_t
1466lpfc_rcv_plogi_npr_node(struct lpfc_hba * phba,
1467 struct lpfc_nodelist * ndlp, void *arg,
1468 uint32_t evt)
1469{
1470 struct lpfc_iocbq *cmdiocb;
1471
1472 cmdiocb = (struct lpfc_iocbq *) arg;
1473
1474 /* Ignore PLOGI if we have an outstanding LOGO */
1475 if (ndlp->nlp_flag & NLP_LOGO_SND) {
c9f8735b 1476 return ndlp->nlp_state;
dea3101e 1477 }
1478
1479 if (lpfc_rcv_plogi(phba, ndlp, cmdiocb)) {
1480 spin_lock_irq(phba->host->host_lock);
fdcebe28 1481 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
dea3101e 1482 spin_unlock_irq(phba->host->host_lock);
c9f8735b 1483 return ndlp->nlp_state;
dea3101e 1484 }
1485
1486 /* send PLOGI immediately, move to PLOGI issue state */
1487 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
488d1469 1488 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
de0c5b32 1489 lpfc_nlp_set_state(phba, ndlp, NLP_STE_PLOGI_ISSUE);
488d1469 1490 lpfc_issue_els_plogi(phba, ndlp->nlp_DID, 0);
dea3101e 1491 }
488d1469 1492
c9f8735b 1493 return ndlp->nlp_state;
dea3101e 1494}
1495
1496static uint32_t
1497lpfc_rcv_prli_npr_node(struct lpfc_hba * phba,
1498 struct lpfc_nodelist * ndlp, void *arg,
1499 uint32_t evt)
1500{
1501 struct lpfc_iocbq *cmdiocb;
1502 struct ls_rjt stat;
1503
1504 cmdiocb = (struct lpfc_iocbq *) arg;
1505
1506 memset(&stat, 0, sizeof (struct ls_rjt));
1507 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
1508 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
1509 lpfc_els_rsp_reject(phba, stat.un.lsRjtError, cmdiocb, ndlp);
1510
1511 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
1512 if (ndlp->nlp_flag & NLP_NPR_ADISC) {
c9f8735b
JW
1513 spin_lock_irq(phba->host->host_lock);
1514 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
1515 spin_unlock_irq(phba->host->host_lock);
5024ab17 1516 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
de0c5b32 1517 lpfc_nlp_set_state(phba, ndlp, NLP_STE_ADISC_ISSUE);
dea3101e 1518 lpfc_issue_els_adisc(phba, ndlp, 0);
1519 } else {
5024ab17 1520 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
de0c5b32 1521 lpfc_nlp_set_state(phba, ndlp, NLP_STE_PLOGI_ISSUE);
488d1469 1522 lpfc_issue_els_plogi(phba, ndlp->nlp_DID, 0);
dea3101e 1523 }
1524 }
c9f8735b 1525 return ndlp->nlp_state;
dea3101e 1526}
1527
1528static uint32_t
1529lpfc_rcv_logo_npr_node(struct lpfc_hba * phba,
1530 struct lpfc_nodelist * ndlp, void *arg,
1531 uint32_t evt)
1532{
1533 struct lpfc_iocbq *cmdiocb;
1534
1535 cmdiocb = (struct lpfc_iocbq *) arg;
1536
82d9a2a2 1537 lpfc_rcv_logo(phba, ndlp, cmdiocb, ELS_CMD_LOGO);
c9f8735b 1538 return ndlp->nlp_state;
dea3101e 1539}
1540
1541static uint32_t
1542lpfc_rcv_padisc_npr_node(struct lpfc_hba * phba,
1543 struct lpfc_nodelist * ndlp, void *arg,
1544 uint32_t evt)
1545{
1546 struct lpfc_iocbq *cmdiocb;
1547
1548 cmdiocb = (struct lpfc_iocbq *) arg;
1549
1550 lpfc_rcv_padisc(phba, ndlp, cmdiocb);
1551
33ccf8d1
JS
1552 /*
1553 * Do not start discovery if discovery is about to start
1554 * or discovery in progress for this node. Starting discovery
1555 * here will affect the counting of discovery threads.
1556 */
2fb9bd8b
JS
1557 if (!(ndlp->nlp_flag & NLP_DELAY_TMO) &&
1558 !(ndlp->nlp_flag & NLP_NPR_2B_DISC)){
dea3101e 1559 if (ndlp->nlp_flag & NLP_NPR_ADISC) {
5024ab17 1560 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
de0c5b32 1561 lpfc_nlp_set_state(phba, ndlp, NLP_STE_ADISC_ISSUE);
dea3101e 1562 lpfc_issue_els_adisc(phba, ndlp, 0);
1563 } else {
5024ab17 1564 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
de0c5b32 1565 lpfc_nlp_set_state(phba, ndlp, NLP_STE_PLOGI_ISSUE);
488d1469 1566 lpfc_issue_els_plogi(phba, ndlp->nlp_DID, 0);
dea3101e 1567 }
1568 }
c9f8735b 1569 return ndlp->nlp_state;
dea3101e 1570}
1571
1572static uint32_t
1573lpfc_rcv_prlo_npr_node(struct lpfc_hba * phba,
1574 struct lpfc_nodelist * ndlp, void *arg,
1575 uint32_t evt)
1576{
1577 struct lpfc_iocbq *cmdiocb;
1578
1579 cmdiocb = (struct lpfc_iocbq *) arg;
1580
c9f8735b
JW
1581 spin_lock_irq(phba->host->host_lock);
1582 ndlp->nlp_flag |= NLP_LOGO_ACC;
1583 spin_unlock_irq(phba->host->host_lock);
1584
dea3101e 1585 lpfc_els_rsp_acc(phba, ELS_CMD_ACC, cmdiocb, ndlp, NULL, 0);
1586
c9f8735b
JW
1587 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
1588 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1);
1589 spin_lock_irq(phba->host->host_lock);
1590 ndlp->nlp_flag |= NLP_DELAY_TMO;
1591 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
1592 spin_unlock_irq(phba->host->host_lock);
5024ab17 1593 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
c9f8735b
JW
1594 } else {
1595 spin_lock_irq(phba->host->host_lock);
1596 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
1597 spin_unlock_irq(phba->host->host_lock);
dea3101e 1598 }
c9f8735b
JW
1599 return ndlp->nlp_state;
1600}
dea3101e 1601
c9f8735b
JW
1602static uint32_t
1603lpfc_cmpl_plogi_npr_node(struct lpfc_hba * phba,
1604 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1605{
1606 struct lpfc_iocbq *cmdiocb, *rspiocb;
a0f9b48d 1607 IOCB_t *irsp;
c9f8735b
JW
1608
1609 cmdiocb = (struct lpfc_iocbq *) arg;
1610 rspiocb = cmdiocb->context_un.rsp_iocb;
a0f9b48d
JS
1611
1612 irsp = &rspiocb->iocb;
1613 if (irsp->ulpStatus) {
de0c5b32 1614 lpfc_drop_node(phba, ndlp);
a0f9b48d
JS
1615 return NLP_STE_FREED_NODE;
1616 }
c9f8735b
JW
1617 return ndlp->nlp_state;
1618}
1619
1620static uint32_t
1621lpfc_cmpl_prli_npr_node(struct lpfc_hba * phba,
1622 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1623{
1624 struct lpfc_iocbq *cmdiocb, *rspiocb;
a0f9b48d 1625 IOCB_t *irsp;
c9f8735b
JW
1626
1627 cmdiocb = (struct lpfc_iocbq *) arg;
1628 rspiocb = cmdiocb->context_un.rsp_iocb;
a0f9b48d
JS
1629
1630 irsp = &rspiocb->iocb;
1631 if (irsp->ulpStatus && (ndlp->nlp_flag & NLP_NODEV_REMOVE)) {
de0c5b32 1632 lpfc_drop_node(phba, ndlp);
a0f9b48d
JS
1633 return NLP_STE_FREED_NODE;
1634 }
c9f8735b 1635 return ndlp->nlp_state;
dea3101e 1636}
1637
1638static uint32_t
1639lpfc_cmpl_logo_npr_node(struct lpfc_hba * phba,
1640 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1641{
1642 lpfc_unreg_rpi(phba, ndlp);
1643 /* This routine does nothing, just return the current state */
c9f8735b
JW
1644 return ndlp->nlp_state;
1645}
1646
1647static uint32_t
1648lpfc_cmpl_adisc_npr_node(struct lpfc_hba * phba,
1649 struct lpfc_nodelist * ndlp, void *arg,
1650 uint32_t evt)
1651{
1652 struct lpfc_iocbq *cmdiocb, *rspiocb;
a0f9b48d 1653 IOCB_t *irsp;
c9f8735b
JW
1654
1655 cmdiocb = (struct lpfc_iocbq *) arg;
1656 rspiocb = cmdiocb->context_un.rsp_iocb;
a0f9b48d
JS
1657
1658 irsp = &rspiocb->iocb;
1659 if (irsp->ulpStatus && (ndlp->nlp_flag & NLP_NODEV_REMOVE)) {
de0c5b32 1660 lpfc_drop_node(phba, ndlp);
a0f9b48d
JS
1661 return NLP_STE_FREED_NODE;
1662 }
c9f8735b 1663 return ndlp->nlp_state;
dea3101e 1664}
1665
1666static uint32_t
1667lpfc_cmpl_reglogin_npr_node(struct lpfc_hba * phba,
1668 struct lpfc_nodelist * ndlp, void *arg,
1669 uint32_t evt)
1670{
1671 LPFC_MBOXQ_t *pmb;
1672 MAILBOX_t *mb;
1673
1674 pmb = (LPFC_MBOXQ_t *) arg;
1675 mb = &pmb->mb;
1676
c9f8735b
JW
1677 if (!mb->mbxStatus)
1678 ndlp->nlp_rpi = mb->un.varWords[0];
a0f9b48d
JS
1679 else {
1680 if (ndlp->nlp_flag & NLP_NODEV_REMOVE) {
de0c5b32 1681 lpfc_drop_node(phba, ndlp);
a0f9b48d
JS
1682 return NLP_STE_FREED_NODE;
1683 }
1684 }
c9f8735b 1685 return ndlp->nlp_state;
dea3101e 1686}
1687
1688static uint32_t
1689lpfc_device_rm_npr_node(struct lpfc_hba * phba,
1690 struct lpfc_nodelist * ndlp, void *arg,
1691 uint32_t evt)
1692{
a0f9b48d
JS
1693 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1694 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
1695 return ndlp->nlp_state;
1696 }
de0c5b32 1697 lpfc_drop_node(phba, ndlp);
c9f8735b 1698 return NLP_STE_FREED_NODE;
dea3101e 1699}
1700
1701static uint32_t
1702lpfc_device_recov_npr_node(struct lpfc_hba * phba,
1703 struct lpfc_nodelist * ndlp, void *arg,
1704 uint32_t evt)
1705{
1706 spin_lock_irq(phba->host->host_lock);
a0f9b48d 1707 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
fdcebe28 1708 spin_unlock_irq(phba->host->host_lock);
6ad42535 1709 if (ndlp->nlp_flag & NLP_DELAY_TMO) {
fdcebe28 1710 lpfc_cancel_retry_delay_tmo(phba, ndlp);
6ad42535 1711 }
c9f8735b 1712 return ndlp->nlp_state;
dea3101e 1713}
1714
1715
1716/* This next section defines the NPort Discovery State Machine */
1717
1718/* There are 4 different double linked lists nodelist entries can reside on.
1719 * The plogi list and adisc list are used when Link Up discovery or RSCN
1720 * processing is needed. Each list holds the nodes that we will send PLOGI
1721 * or ADISC on. These lists will keep track of what nodes will be effected
1722 * by an RSCN, or a Link Up (Typically, all nodes are effected on Link Up).
1723 * The unmapped_list will contain all nodes that we have successfully logged
1724 * into at the Fibre Channel level. The mapped_list will contain all nodes
1725 * that are mapped FCP targets.
1726 */
1727/*
1728 * The bind list is a list of undiscovered (potentially non-existent) nodes
1729 * that we have saved binding information on. This information is used when
1730 * nodes transition from the unmapped to the mapped list.
1731 */
1732/* For UNUSED_NODE state, the node has just been allocated .
1733 * For PLOGI_ISSUE and REG_LOGIN_ISSUE, the node is on
1734 * the PLOGI list. For REG_LOGIN_COMPL, the node is taken off the PLOGI list
1735 * and put on the unmapped list. For ADISC processing, the node is taken off
1736 * the ADISC list and placed on either the mapped or unmapped list (depending
1737 * on its previous state). Once on the unmapped list, a PRLI is issued and the
1738 * state changed to PRLI_ISSUE. When the PRLI completion occurs, the state is
1739 * changed to UNMAPPED_NODE. If the completion indicates a mapped
1740 * node, the node is taken off the unmapped list. The binding list is checked
1741 * for a valid binding, or a binding is automatically assigned. If binding
1742 * assignment is unsuccessful, the node is left on the unmapped list. If
1743 * binding assignment is successful, the associated binding list entry (if
1744 * any) is removed, and the node is placed on the mapped list.
1745 */
1746/*
1747 * For a Link Down, all nodes on the ADISC, PLOGI, unmapped or mapped
c01f3208 1748 * lists will receive a DEVICE_RECOVERY event. If the linkdown or devloss timers
dea3101e 1749 * expire, all effected nodes will receive a DEVICE_RM event.
1750 */
1751/*
1752 * For a Link Up or RSCN, all nodes will move from the mapped / unmapped lists
1753 * to either the ADISC or PLOGI list. After a Nameserver query or ALPA loopmap
1754 * check, additional nodes may be added or removed (via DEVICE_RM) to / from
1755 * the PLOGI or ADISC lists. Once the PLOGI and ADISC lists are populated,
1756 * we will first process the ADISC list. 32 entries are processed initially and
1757 * ADISC is initited for each one. Completions / Events for each node are
1758 * funnelled thru the state machine. As each node finishes ADISC processing, it
1759 * starts ADISC for any nodes waiting for ADISC processing. If no nodes are
1760 * waiting, and the ADISC list count is identically 0, then we are done. For
1761 * Link Up discovery, since all nodes on the PLOGI list are UNREG_LOGIN'ed, we
1762 * can issue a CLEAR_LA and reenable Link Events. Next we will process the PLOGI
1763 * list. 32 entries are processed initially and PLOGI is initited for each one.
1764 * Completions / Events for each node are funnelled thru the state machine. As
1765 * each node finishes PLOGI processing, it starts PLOGI for any nodes waiting
1766 * for PLOGI processing. If no nodes are waiting, and the PLOGI list count is
1767 * indentically 0, then we are done. We have now completed discovery / RSCN
1768 * handling. Upon completion, ALL nodes should be on either the mapped or
1769 * unmapped lists.
1770 */
1771
1772static uint32_t (*lpfc_disc_action[NLP_STE_MAX_STATE * NLP_EVT_MAX_EVENT])
1773 (struct lpfc_hba *, struct lpfc_nodelist *, void *, uint32_t) = {
1774 /* Action routine Event Current State */
1775 lpfc_rcv_plogi_unused_node, /* RCV_PLOGI UNUSED_NODE */
1776 lpfc_rcv_els_unused_node, /* RCV_PRLI */
1777 lpfc_rcv_logo_unused_node, /* RCV_LOGO */
1778 lpfc_rcv_els_unused_node, /* RCV_ADISC */
1779 lpfc_rcv_els_unused_node, /* RCV_PDISC */
1780 lpfc_rcv_els_unused_node, /* RCV_PRLO */
1781 lpfc_disc_illegal, /* CMPL_PLOGI */
1782 lpfc_disc_illegal, /* CMPL_PRLI */
1783 lpfc_cmpl_logo_unused_node, /* CMPL_LOGO */
1784 lpfc_disc_illegal, /* CMPL_ADISC */
1785 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
1786 lpfc_device_rm_unused_node, /* DEVICE_RM */
1787 lpfc_disc_illegal, /* DEVICE_RECOVERY */
1788
1789 lpfc_rcv_plogi_plogi_issue, /* RCV_PLOGI PLOGI_ISSUE */
1790 lpfc_rcv_els_plogi_issue, /* RCV_PRLI */
c9f8735b 1791 lpfc_rcv_logo_plogi_issue, /* RCV_LOGO */
dea3101e 1792 lpfc_rcv_els_plogi_issue, /* RCV_ADISC */
1793 lpfc_rcv_els_plogi_issue, /* RCV_PDISC */
1794 lpfc_rcv_els_plogi_issue, /* RCV_PRLO */
1795 lpfc_cmpl_plogi_plogi_issue, /* CMPL_PLOGI */
1796 lpfc_disc_illegal, /* CMPL_PRLI */
1797 lpfc_disc_illegal, /* CMPL_LOGO */
1798 lpfc_disc_illegal, /* CMPL_ADISC */
1799 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
1800 lpfc_device_rm_plogi_issue, /* DEVICE_RM */
1801 lpfc_device_recov_plogi_issue, /* DEVICE_RECOVERY */
1802
1803 lpfc_rcv_plogi_adisc_issue, /* RCV_PLOGI ADISC_ISSUE */
1804 lpfc_rcv_prli_adisc_issue, /* RCV_PRLI */
1805 lpfc_rcv_logo_adisc_issue, /* RCV_LOGO */
1806 lpfc_rcv_padisc_adisc_issue, /* RCV_ADISC */
1807 lpfc_rcv_padisc_adisc_issue, /* RCV_PDISC */
1808 lpfc_rcv_prlo_adisc_issue, /* RCV_PRLO */
1809 lpfc_disc_illegal, /* CMPL_PLOGI */
1810 lpfc_disc_illegal, /* CMPL_PRLI */
1811 lpfc_disc_illegal, /* CMPL_LOGO */
1812 lpfc_cmpl_adisc_adisc_issue, /* CMPL_ADISC */
1813 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
1814 lpfc_device_rm_adisc_issue, /* DEVICE_RM */
1815 lpfc_device_recov_adisc_issue, /* DEVICE_RECOVERY */
1816
1817 lpfc_rcv_plogi_reglogin_issue, /* RCV_PLOGI REG_LOGIN_ISSUE */
1818 lpfc_rcv_prli_reglogin_issue, /* RCV_PLOGI */
1819 lpfc_rcv_logo_reglogin_issue, /* RCV_LOGO */
1820 lpfc_rcv_padisc_reglogin_issue, /* RCV_ADISC */
1821 lpfc_rcv_padisc_reglogin_issue, /* RCV_PDISC */
1822 lpfc_rcv_prlo_reglogin_issue, /* RCV_PRLO */
1823 lpfc_disc_illegal, /* CMPL_PLOGI */
1824 lpfc_disc_illegal, /* CMPL_PRLI */
1825 lpfc_disc_illegal, /* CMPL_LOGO */
1826 lpfc_disc_illegal, /* CMPL_ADISC */
1827 lpfc_cmpl_reglogin_reglogin_issue,/* CMPL_REG_LOGIN */
1828 lpfc_device_rm_reglogin_issue, /* DEVICE_RM */
1829 lpfc_device_recov_reglogin_issue,/* DEVICE_RECOVERY */
1830
1831 lpfc_rcv_plogi_prli_issue, /* RCV_PLOGI PRLI_ISSUE */
1832 lpfc_rcv_prli_prli_issue, /* RCV_PRLI */
1833 lpfc_rcv_logo_prli_issue, /* RCV_LOGO */
1834 lpfc_rcv_padisc_prli_issue, /* RCV_ADISC */
1835 lpfc_rcv_padisc_prli_issue, /* RCV_PDISC */
1836 lpfc_rcv_prlo_prli_issue, /* RCV_PRLO */
1837 lpfc_disc_illegal, /* CMPL_PLOGI */
1838 lpfc_cmpl_prli_prli_issue, /* CMPL_PRLI */
1839 lpfc_disc_illegal, /* CMPL_LOGO */
1840 lpfc_disc_illegal, /* CMPL_ADISC */
1841 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
1842 lpfc_device_rm_prli_issue, /* DEVICE_RM */
1843 lpfc_device_recov_prli_issue, /* DEVICE_RECOVERY */
1844
1845 lpfc_rcv_plogi_unmap_node, /* RCV_PLOGI UNMAPPED_NODE */
1846 lpfc_rcv_prli_unmap_node, /* RCV_PRLI */
1847 lpfc_rcv_logo_unmap_node, /* RCV_LOGO */
1848 lpfc_rcv_padisc_unmap_node, /* RCV_ADISC */
1849 lpfc_rcv_padisc_unmap_node, /* RCV_PDISC */
1850 lpfc_rcv_prlo_unmap_node, /* RCV_PRLO */
1851 lpfc_disc_illegal, /* CMPL_PLOGI */
1852 lpfc_disc_illegal, /* CMPL_PRLI */
1853 lpfc_disc_illegal, /* CMPL_LOGO */
1854 lpfc_disc_illegal, /* CMPL_ADISC */
1855 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
1856 lpfc_disc_illegal, /* DEVICE_RM */
1857 lpfc_device_recov_unmap_node, /* DEVICE_RECOVERY */
1858
1859 lpfc_rcv_plogi_mapped_node, /* RCV_PLOGI MAPPED_NODE */
1860 lpfc_rcv_prli_mapped_node, /* RCV_PRLI */
1861 lpfc_rcv_logo_mapped_node, /* RCV_LOGO */
1862 lpfc_rcv_padisc_mapped_node, /* RCV_ADISC */
1863 lpfc_rcv_padisc_mapped_node, /* RCV_PDISC */
1864 lpfc_rcv_prlo_mapped_node, /* RCV_PRLO */
1865 lpfc_disc_illegal, /* CMPL_PLOGI */
1866 lpfc_disc_illegal, /* CMPL_PRLI */
1867 lpfc_disc_illegal, /* CMPL_LOGO */
1868 lpfc_disc_illegal, /* CMPL_ADISC */
1869 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
1870 lpfc_disc_illegal, /* DEVICE_RM */
1871 lpfc_device_recov_mapped_node, /* DEVICE_RECOVERY */
1872
1873 lpfc_rcv_plogi_npr_node, /* RCV_PLOGI NPR_NODE */
1874 lpfc_rcv_prli_npr_node, /* RCV_PRLI */
1875 lpfc_rcv_logo_npr_node, /* RCV_LOGO */
1876 lpfc_rcv_padisc_npr_node, /* RCV_ADISC */
1877 lpfc_rcv_padisc_npr_node, /* RCV_PDISC */
1878 lpfc_rcv_prlo_npr_node, /* RCV_PRLO */
c9f8735b
JW
1879 lpfc_cmpl_plogi_npr_node, /* CMPL_PLOGI */
1880 lpfc_cmpl_prli_npr_node, /* CMPL_PRLI */
dea3101e 1881 lpfc_cmpl_logo_npr_node, /* CMPL_LOGO */
c9f8735b 1882 lpfc_cmpl_adisc_npr_node, /* CMPL_ADISC */
dea3101e 1883 lpfc_cmpl_reglogin_npr_node, /* CMPL_REG_LOGIN */
1884 lpfc_device_rm_npr_node, /* DEVICE_RM */
1885 lpfc_device_recov_npr_node, /* DEVICE_RECOVERY */
1886};
1887
1888int
1889lpfc_disc_state_machine(struct lpfc_hba * phba,
1890 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1891{
1892 uint32_t cur_state, rc;
1893 uint32_t(*func) (struct lpfc_hba *, struct lpfc_nodelist *, void *,
1894 uint32_t);
1895
1896 ndlp->nlp_disc_refcnt++;
1897 cur_state = ndlp->nlp_state;
1898
1899 /* DSM in event <evt> on NPort <nlp_DID> in state <cur_state> */
1900 lpfc_printf_log(phba,
1901 KERN_INFO,
1902 LOG_DISCOVERY,
1903 "%d:0211 DSM in event x%x on NPort x%x in state %d "
1904 "Data: x%x\n",
1905 phba->brd_no,
1906 evt, ndlp->nlp_DID, cur_state, ndlp->nlp_flag);
1907
1908 func = lpfc_disc_action[(cur_state * NLP_EVT_MAX_EVENT) + evt];
1909 rc = (func) (phba, ndlp, arg, evt);
1910
1911 /* DSM out state <rc> on NPort <nlp_DID> */
1912 lpfc_printf_log(phba,
1913 KERN_INFO,
1914 LOG_DISCOVERY,
1915 "%d:0212 DSM out state %d on NPort x%x Data: x%x\n",
1916 phba->brd_no,
1917 rc, ndlp->nlp_DID, ndlp->nlp_flag);
1918
1919 ndlp->nlp_disc_refcnt--;
1920
1921 /* Check to see if ndlp removal is deferred */
1922 if ((ndlp->nlp_disc_refcnt == 0)
1923 && (ndlp->nlp_flag & NLP_DELAY_REMOVE)) {
1924 spin_lock_irq(phba->host->host_lock);
1925 ndlp->nlp_flag &= ~NLP_DELAY_REMOVE;
1926 spin_unlock_irq(phba->host->host_lock);
1927 lpfc_nlp_remove(phba, ndlp);
c9f8735b 1928 return NLP_STE_FREED_NODE;
dea3101e 1929 }
1930 if (rc == NLP_STE_FREED_NODE)
c9f8735b 1931 return NLP_STE_FREED_NODE;
c9f8735b 1932 return rc;
dea3101e 1933}
This page took 0.370078 seconds and 5 git commands to generate.