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