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