]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blob - drivers/scsi/lpfc/lpfc_nportdisc.c
d317a158d55f1686b664e39c1a09c40b1c5d9ead
[mirror_ubuntu-bionic-kernel.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) 2017-2018 Broadcom. All Rights Reserved. The term *
5 * “Broadcom” refers to Broadcom Limited and/or its subsidiaries. *
6 * Copyright (C) 2004-2016 Emulex. All rights reserved. *
7 * EMULEX and SLI are trademarks of Emulex. *
8 * www.broadcom.com *
9 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
10 * *
11 * This program is free software; you can redistribute it and/or *
12 * modify it under the terms of version 2 of the GNU General *
13 * Public License as published by the Free Software Foundation. *
14 * This program is distributed in the hope that it will be useful. *
15 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
16 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
17 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
18 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
19 * TO BE LEGALLY INVALID. See the GNU General Public License for *
20 * more details, a copy of which can be found in the file COPYING *
21 * included with this package. *
22 *******************************************************************/
23
24 #include <linux/blkdev.h>
25 #include <linux/pci.h>
26 #include <linux/slab.h>
27 #include <linux/interrupt.h>
28
29 #include <scsi/scsi.h>
30 #include <scsi/scsi_device.h>
31 #include <scsi/scsi_host.h>
32 #include <scsi/scsi_transport_fc.h>
33 #include <scsi/fc/fc_fs.h>
34
35 #include <linux/nvme-fc-driver.h>
36
37 #include "lpfc_hw4.h"
38 #include "lpfc_hw.h"
39 #include "lpfc_sli.h"
40 #include "lpfc_sli4.h"
41 #include "lpfc_nl.h"
42 #include "lpfc_disc.h"
43 #include "lpfc.h"
44 #include "lpfc_scsi.h"
45 #include "lpfc_nvme.h"
46 #include "lpfc_logmsg.h"
47 #include "lpfc_crtn.h"
48 #include "lpfc_vport.h"
49 #include "lpfc_debugfs.h"
50
51
52 /* Called to verify a rcv'ed ADISC was intended for us. */
53 static int
54 lpfc_check_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
55 struct lpfc_name *nn, struct lpfc_name *pn)
56 {
57 /* First, we MUST have a RPI registered */
58 if (!(ndlp->nlp_flag & NLP_RPI_REGISTERED))
59 return 0;
60
61 /* Compare the ADISC rsp WWNN / WWPN matches our internal node
62 * table entry for that node.
63 */
64 if (memcmp(nn, &ndlp->nlp_nodename, sizeof (struct lpfc_name)))
65 return 0;
66
67 if (memcmp(pn, &ndlp->nlp_portname, sizeof (struct lpfc_name)))
68 return 0;
69
70 /* we match, return success */
71 return 1;
72 }
73
74 int
75 lpfc_check_sparm(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
76 struct serv_parm *sp, uint32_t class, int flogi)
77 {
78 volatile struct serv_parm *hsp = &vport->fc_sparam;
79 uint16_t hsp_value, ssp_value = 0;
80
81 /*
82 * The receive data field size and buffer-to-buffer receive data field
83 * size entries are 16 bits but are represented as two 8-bit fields in
84 * the driver data structure to account for rsvd bits and other control
85 * bits. Reconstruct and compare the fields as a 16-bit values before
86 * correcting the byte values.
87 */
88 if (sp->cls1.classValid) {
89 if (!flogi) {
90 hsp_value = ((hsp->cls1.rcvDataSizeMsb << 8) |
91 hsp->cls1.rcvDataSizeLsb);
92 ssp_value = ((sp->cls1.rcvDataSizeMsb << 8) |
93 sp->cls1.rcvDataSizeLsb);
94 if (!ssp_value)
95 goto bad_service_param;
96 if (ssp_value > hsp_value) {
97 sp->cls1.rcvDataSizeLsb =
98 hsp->cls1.rcvDataSizeLsb;
99 sp->cls1.rcvDataSizeMsb =
100 hsp->cls1.rcvDataSizeMsb;
101 }
102 }
103 } else if (class == CLASS1)
104 goto bad_service_param;
105 if (sp->cls2.classValid) {
106 if (!flogi) {
107 hsp_value = ((hsp->cls2.rcvDataSizeMsb << 8) |
108 hsp->cls2.rcvDataSizeLsb);
109 ssp_value = ((sp->cls2.rcvDataSizeMsb << 8) |
110 sp->cls2.rcvDataSizeLsb);
111 if (!ssp_value)
112 goto bad_service_param;
113 if (ssp_value > hsp_value) {
114 sp->cls2.rcvDataSizeLsb =
115 hsp->cls2.rcvDataSizeLsb;
116 sp->cls2.rcvDataSizeMsb =
117 hsp->cls2.rcvDataSizeMsb;
118 }
119 }
120 } else if (class == CLASS2)
121 goto bad_service_param;
122 if (sp->cls3.classValid) {
123 if (!flogi) {
124 hsp_value = ((hsp->cls3.rcvDataSizeMsb << 8) |
125 hsp->cls3.rcvDataSizeLsb);
126 ssp_value = ((sp->cls3.rcvDataSizeMsb << 8) |
127 sp->cls3.rcvDataSizeLsb);
128 if (!ssp_value)
129 goto bad_service_param;
130 if (ssp_value > hsp_value) {
131 sp->cls3.rcvDataSizeLsb =
132 hsp->cls3.rcvDataSizeLsb;
133 sp->cls3.rcvDataSizeMsb =
134 hsp->cls3.rcvDataSizeMsb;
135 }
136 }
137 } else if (class == CLASS3)
138 goto bad_service_param;
139
140 /*
141 * Preserve the upper four bits of the MSB from the PLOGI response.
142 * These bits contain the Buffer-to-Buffer State Change Number
143 * from the target and need to be passed to the FW.
144 */
145 hsp_value = (hsp->cmn.bbRcvSizeMsb << 8) | hsp->cmn.bbRcvSizeLsb;
146 ssp_value = (sp->cmn.bbRcvSizeMsb << 8) | sp->cmn.bbRcvSizeLsb;
147 if (ssp_value > hsp_value) {
148 sp->cmn.bbRcvSizeLsb = hsp->cmn.bbRcvSizeLsb;
149 sp->cmn.bbRcvSizeMsb = (sp->cmn.bbRcvSizeMsb & 0xF0) |
150 (hsp->cmn.bbRcvSizeMsb & 0x0F);
151 }
152
153 memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof (struct lpfc_name));
154 memcpy(&ndlp->nlp_portname, &sp->portName, sizeof (struct lpfc_name));
155 return 1;
156 bad_service_param:
157 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
158 "0207 Device %x "
159 "(%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x) sent "
160 "invalid service parameters. Ignoring device.\n",
161 ndlp->nlp_DID,
162 sp->nodeName.u.wwn[0], sp->nodeName.u.wwn[1],
163 sp->nodeName.u.wwn[2], sp->nodeName.u.wwn[3],
164 sp->nodeName.u.wwn[4], sp->nodeName.u.wwn[5],
165 sp->nodeName.u.wwn[6], sp->nodeName.u.wwn[7]);
166 return 0;
167 }
168
169 static void *
170 lpfc_check_elscmpl_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
171 struct lpfc_iocbq *rspiocb)
172 {
173 struct lpfc_dmabuf *pcmd, *prsp;
174 uint32_t *lp;
175 void *ptr = NULL;
176 IOCB_t *irsp;
177
178 irsp = &rspiocb->iocb;
179 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
180
181 /* For lpfc_els_abort, context2 could be zero'ed to delay
182 * freeing associated memory till after ABTS completes.
183 */
184 if (pcmd) {
185 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf,
186 list);
187 if (prsp) {
188 lp = (uint32_t *) prsp->virt;
189 ptr = (void *)((uint8_t *)lp + sizeof(uint32_t));
190 }
191 } else {
192 /* Force ulpStatus error since we are returning NULL ptr */
193 if (!(irsp->ulpStatus)) {
194 irsp->ulpStatus = IOSTAT_LOCAL_REJECT;
195 irsp->un.ulpWord[4] = IOERR_SLI_ABORTED;
196 }
197 ptr = NULL;
198 }
199 return ptr;
200 }
201
202
203
204 /*
205 * Free resources / clean up outstanding I/Os
206 * associated with a LPFC_NODELIST entry. This
207 * routine effectively results in a "software abort".
208 */
209 void
210 lpfc_els_abort(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
211 {
212 LIST_HEAD(abort_list);
213 struct lpfc_sli_ring *pring;
214 struct lpfc_iocbq *iocb, *next_iocb;
215
216 pring = lpfc_phba_elsring(phba);
217
218 /* In case of error recovery path, we might have a NULL pring here */
219 if (unlikely(!pring))
220 return;
221
222 /* Abort outstanding I/O on NPort <nlp_DID> */
223 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_DISCOVERY,
224 "2819 Abort outstanding I/O on NPort x%x "
225 "Data: x%x x%x x%x\n",
226 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
227 ndlp->nlp_rpi);
228 /* Clean up all fabric IOs first.*/
229 lpfc_fabric_abort_nport(ndlp);
230
231 /*
232 * Lock the ELS ring txcmplq for SLI3/SLI4 and build a local list
233 * of all ELS IOs that need an ABTS. The IOs need to stay on the
234 * txcmplq so that the abort operation completes them successfully.
235 */
236 spin_lock_irq(&phba->hbalock);
237 if (phba->sli_rev == LPFC_SLI_REV4)
238 spin_lock(&pring->ring_lock);
239 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
240 /* Add to abort_list on on NDLP match. */
241 if (lpfc_check_sli_ndlp(phba, pring, iocb, ndlp))
242 list_add_tail(&iocb->dlist, &abort_list);
243 }
244 if (phba->sli_rev == LPFC_SLI_REV4)
245 spin_unlock(&pring->ring_lock);
246 spin_unlock_irq(&phba->hbalock);
247
248 /* Abort the targeted IOs and remove them from the abort list. */
249 list_for_each_entry_safe(iocb, next_iocb, &abort_list, dlist) {
250 spin_lock_irq(&phba->hbalock);
251 list_del_init(&iocb->dlist);
252 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
253 spin_unlock_irq(&phba->hbalock);
254 }
255
256 INIT_LIST_HEAD(&abort_list);
257
258 /* Now process the txq */
259 spin_lock_irq(&phba->hbalock);
260 if (phba->sli_rev == LPFC_SLI_REV4)
261 spin_lock(&pring->ring_lock);
262
263 list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
264 /* Check to see if iocb matches the nport we are looking for */
265 if (lpfc_check_sli_ndlp(phba, pring, iocb, ndlp)) {
266 list_del_init(&iocb->list);
267 list_add_tail(&iocb->list, &abort_list);
268 }
269 }
270
271 if (phba->sli_rev == LPFC_SLI_REV4)
272 spin_unlock(&pring->ring_lock);
273 spin_unlock_irq(&phba->hbalock);
274
275 /* Cancel all the IOCBs from the completions list */
276 lpfc_sli_cancel_iocbs(phba, &abort_list,
277 IOSTAT_LOCAL_REJECT, IOERR_SLI_ABORTED);
278
279 lpfc_cancel_retry_delay_tmo(phba->pport, ndlp);
280 }
281
282 static int
283 lpfc_rcv_plogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
284 struct lpfc_iocbq *cmdiocb)
285 {
286 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
287 struct lpfc_hba *phba = vport->phba;
288 struct lpfc_dmabuf *pcmd;
289 uint64_t nlp_portwwn = 0;
290 uint32_t *lp;
291 IOCB_t *icmd;
292 struct serv_parm *sp;
293 uint32_t ed_tov;
294 LPFC_MBOXQ_t *mbox;
295 struct ls_rjt stat;
296 uint32_t vid, flag;
297 int rc;
298
299 memset(&stat, 0, sizeof (struct ls_rjt));
300 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
301 lp = (uint32_t *) pcmd->virt;
302 sp = (struct serv_parm *) ((uint8_t *) lp + sizeof (uint32_t));
303 if (wwn_to_u64(sp->portName.u.wwn) == 0) {
304 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
305 "0140 PLOGI Reject: invalid nname\n");
306 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
307 stat.un.b.lsRjtRsnCodeExp = LSEXP_INVALID_PNAME;
308 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
309 NULL);
310 return 0;
311 }
312 if (wwn_to_u64(sp->nodeName.u.wwn) == 0) {
313 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
314 "0141 PLOGI Reject: invalid pname\n");
315 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
316 stat.un.b.lsRjtRsnCodeExp = LSEXP_INVALID_NNAME;
317 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
318 NULL);
319 return 0;
320 }
321
322 nlp_portwwn = wwn_to_u64(ndlp->nlp_portname.u.wwn);
323 if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3, 0) == 0)) {
324 /* Reject this request because invalid parameters */
325 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
326 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
327 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
328 NULL);
329 return 0;
330 }
331 icmd = &cmdiocb->iocb;
332
333 /* PLOGI chkparm OK */
334 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
335 "0114 PLOGI chkparm OK Data: x%x x%x x%x "
336 "x%x x%x x%x\n",
337 ndlp->nlp_DID, ndlp->nlp_state, ndlp->nlp_flag,
338 ndlp->nlp_rpi, vport->port_state,
339 vport->fc_flag);
340
341 if (vport->cfg_fcp_class == 2 && sp->cls2.classValid)
342 ndlp->nlp_fcp_info |= CLASS2;
343 else
344 ndlp->nlp_fcp_info |= CLASS3;
345
346 ndlp->nlp_class_sup = 0;
347 if (sp->cls1.classValid)
348 ndlp->nlp_class_sup |= FC_COS_CLASS1;
349 if (sp->cls2.classValid)
350 ndlp->nlp_class_sup |= FC_COS_CLASS2;
351 if (sp->cls3.classValid)
352 ndlp->nlp_class_sup |= FC_COS_CLASS3;
353 if (sp->cls4.classValid)
354 ndlp->nlp_class_sup |= FC_COS_CLASS4;
355 ndlp->nlp_maxframe =
356 ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) | sp->cmn.bbRcvSizeLsb;
357
358 /* if already logged in, do implicit logout */
359 switch (ndlp->nlp_state) {
360 case NLP_STE_NPR_NODE:
361 if (!(ndlp->nlp_flag & NLP_NPR_ADISC))
362 break;
363 case NLP_STE_REG_LOGIN_ISSUE:
364 case NLP_STE_PRLI_ISSUE:
365 case NLP_STE_UNMAPPED_NODE:
366 case NLP_STE_MAPPED_NODE:
367 /* For initiators, lpfc_plogi_confirm_nport skips fabric did.
368 * For target mode, execute implicit logo.
369 * Fabric nodes go into NPR.
370 */
371 if (!(ndlp->nlp_type & NLP_FABRIC) &&
372 !(phba->nvmet_support)) {
373 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb,
374 ndlp, NULL);
375 return 1;
376 }
377 if (nlp_portwwn != 0 &&
378 nlp_portwwn != wwn_to_u64(sp->portName.u.wwn))
379 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
380 "0143 PLOGI recv'd from DID: x%x "
381 "WWPN changed: old %llx new %llx\n",
382 ndlp->nlp_DID,
383 (unsigned long long)nlp_portwwn,
384 (unsigned long long)
385 wwn_to_u64(sp->portName.u.wwn));
386
387 ndlp->nlp_prev_state = ndlp->nlp_state;
388 /* rport needs to be unregistered first */
389 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
390 break;
391 }
392
393 ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
394 ndlp->nlp_type &= ~(NLP_NVME_TARGET | NLP_NVME_INITIATOR);
395 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
396 ndlp->nlp_flag &= ~NLP_FIRSTBURST;
397
398 /* Check for Nport to NPort pt2pt protocol */
399 if ((vport->fc_flag & FC_PT2PT) &&
400 !(vport->fc_flag & FC_PT2PT_PLOGI)) {
401 /* rcv'ed PLOGI decides what our NPortId will be */
402 vport->fc_myDID = icmd->un.rcvels.parmRo;
403
404 ed_tov = be32_to_cpu(sp->cmn.e_d_tov);
405 if (sp->cmn.edtovResolution) {
406 /* E_D_TOV ticks are in nanoseconds */
407 ed_tov = (phba->fc_edtov + 999999) / 1000000;
408 }
409
410 /*
411 * For pt-to-pt, use the larger EDTOV
412 * RATOV = 2 * EDTOV
413 */
414 if (ed_tov > phba->fc_edtov)
415 phba->fc_edtov = ed_tov;
416 phba->fc_ratov = (2 * phba->fc_edtov) / 1000;
417
418 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
419
420 /* Issue config_link / reg_vfi to account for updated TOV's */
421
422 if (phba->sli_rev == LPFC_SLI_REV4)
423 lpfc_issue_reg_vfi(vport);
424 else {
425 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
426 if (mbox == NULL)
427 goto out;
428 lpfc_config_link(phba, mbox);
429 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
430 mbox->vport = vport;
431 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
432 if (rc == MBX_NOT_FINISHED) {
433 mempool_free(mbox, phba->mbox_mem_pool);
434 goto out;
435 }
436 }
437
438 lpfc_can_disctmo(vport);
439 }
440
441 ndlp->nlp_flag &= ~NLP_SUPPRESS_RSP;
442 if ((phba->sli.sli_flag & LPFC_SLI_SUPPRESS_RSP) &&
443 sp->cmn.valid_vendor_ver_level) {
444 vid = be32_to_cpu(sp->un.vv.vid);
445 flag = be32_to_cpu(sp->un.vv.flags);
446 if ((vid == LPFC_VV_EMLX_ID) && (flag & LPFC_VV_SUPPRESS_RSP))
447 ndlp->nlp_flag |= NLP_SUPPRESS_RSP;
448 }
449
450 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
451 if (!mbox)
452 goto out;
453
454 /* Registering an existing RPI behaves differently for SLI3 vs SLI4 */
455 if (phba->sli_rev == LPFC_SLI_REV4)
456 lpfc_unreg_rpi(vport, ndlp);
457
458 rc = lpfc_reg_rpi(phba, vport->vpi, icmd->un.rcvels.remoteID,
459 (uint8_t *) sp, mbox, ndlp->nlp_rpi);
460 if (rc) {
461 mempool_free(mbox, phba->mbox_mem_pool);
462 goto out;
463 }
464
465 /* ACC PLOGI rsp command needs to execute first,
466 * queue this mbox command to be processed later.
467 */
468 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
469 /*
470 * mbox->context2 = lpfc_nlp_get(ndlp) deferred until mailbox
471 * command issued in lpfc_cmpl_els_acc().
472 */
473 mbox->vport = vport;
474 spin_lock_irq(shost->host_lock);
475 ndlp->nlp_flag |= (NLP_ACC_REGLOGIN | NLP_RCV_PLOGI);
476 spin_unlock_irq(shost->host_lock);
477
478 /*
479 * If there is an outstanding PLOGI issued, abort it before
480 * sending ACC rsp for received PLOGI. If pending plogi
481 * is not canceled here, the plogi will be rejected by
482 * remote port and will be retried. On a configuration with
483 * single discovery thread, this will cause a huge delay in
484 * discovery. Also this will cause multiple state machines
485 * running in parallel for this node.
486 */
487 if (ndlp->nlp_state == NLP_STE_PLOGI_ISSUE) {
488 /* software abort outstanding PLOGI */
489 lpfc_els_abort(phba, ndlp);
490 }
491
492 if ((vport->port_type == LPFC_NPIV_PORT &&
493 vport->cfg_restrict_login)) {
494
495 /* In order to preserve RPIs, we want to cleanup
496 * the default RPI the firmware created to rcv
497 * this ELS request. The only way to do this is
498 * to register, then unregister the RPI.
499 */
500 spin_lock_irq(shost->host_lock);
501 ndlp->nlp_flag |= NLP_RM_DFLT_RPI;
502 spin_unlock_irq(shost->host_lock);
503 stat.un.b.lsRjtRsnCode = LSRJT_INVALID_CMD;
504 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
505 rc = lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb,
506 ndlp, mbox);
507 if (rc)
508 mempool_free(mbox, phba->mbox_mem_pool);
509 return 1;
510 }
511 rc = lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, mbox);
512 if (rc)
513 mempool_free(mbox, phba->mbox_mem_pool);
514 return 1;
515 out:
516 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
517 stat.un.b.lsRjtRsnCodeExp = LSEXP_OUT_OF_RESOURCE;
518 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
519 return 0;
520 }
521
522 /**
523 * lpfc_mbx_cmpl_resume_rpi - Resume RPI completion routine
524 * @phba: pointer to lpfc hba data structure.
525 * @mboxq: pointer to mailbox object
526 *
527 * This routine is invoked to issue a completion to a rcv'ed
528 * ADISC or PDISC after the paused RPI has been resumed.
529 **/
530 static void
531 lpfc_mbx_cmpl_resume_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
532 {
533 struct lpfc_vport *vport;
534 struct lpfc_iocbq *elsiocb;
535 struct lpfc_nodelist *ndlp;
536 uint32_t cmd;
537
538 elsiocb = (struct lpfc_iocbq *)mboxq->context1;
539 ndlp = (struct lpfc_nodelist *) mboxq->context2;
540 vport = mboxq->vport;
541 cmd = elsiocb->drvrTimeout;
542
543 if (cmd == ELS_CMD_ADISC) {
544 lpfc_els_rsp_adisc_acc(vport, elsiocb, ndlp);
545 } else {
546 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, elsiocb,
547 ndlp, NULL);
548 }
549 kfree(elsiocb);
550 mempool_free(mboxq, phba->mbox_mem_pool);
551 }
552
553 static int
554 lpfc_rcv_padisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
555 struct lpfc_iocbq *cmdiocb)
556 {
557 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
558 struct lpfc_iocbq *elsiocb;
559 struct lpfc_dmabuf *pcmd;
560 struct serv_parm *sp;
561 struct lpfc_name *pnn, *ppn;
562 struct ls_rjt stat;
563 ADISC *ap;
564 IOCB_t *icmd;
565 uint32_t *lp;
566 uint32_t cmd;
567
568 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
569 lp = (uint32_t *) pcmd->virt;
570
571 cmd = *lp++;
572 if (cmd == ELS_CMD_ADISC) {
573 ap = (ADISC *) lp;
574 pnn = (struct lpfc_name *) & ap->nodeName;
575 ppn = (struct lpfc_name *) & ap->portName;
576 } else {
577 sp = (struct serv_parm *) lp;
578 pnn = (struct lpfc_name *) & sp->nodeName;
579 ppn = (struct lpfc_name *) & sp->portName;
580 }
581
582 icmd = &cmdiocb->iocb;
583 if (icmd->ulpStatus == 0 && lpfc_check_adisc(vport, ndlp, pnn, ppn)) {
584
585 /*
586 * As soon as we send ACC, the remote NPort can
587 * start sending us data. Thus, for SLI4 we must
588 * resume the RPI before the ACC goes out.
589 */
590 if (vport->phba->sli_rev == LPFC_SLI_REV4) {
591 elsiocb = kmalloc(sizeof(struct lpfc_iocbq),
592 GFP_KERNEL);
593 if (elsiocb) {
594
595 /* Save info from cmd IOCB used in rsp */
596 memcpy((uint8_t *)elsiocb, (uint8_t *)cmdiocb,
597 sizeof(struct lpfc_iocbq));
598
599 /* Save the ELS cmd */
600 elsiocb->drvrTimeout = cmd;
601
602 lpfc_sli4_resume_rpi(ndlp,
603 lpfc_mbx_cmpl_resume_rpi, elsiocb);
604 goto out;
605 }
606 }
607
608 if (cmd == ELS_CMD_ADISC) {
609 lpfc_els_rsp_adisc_acc(vport, cmdiocb, ndlp);
610 } else {
611 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb,
612 ndlp, NULL);
613 }
614 out:
615 /* If we are authenticated, move to the proper state */
616 if (ndlp->nlp_type & NLP_FCP_TARGET)
617 lpfc_nlp_set_state(vport, ndlp, NLP_STE_MAPPED_NODE);
618 else
619 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
620
621 return 1;
622 }
623 /* Reject this request because invalid parameters */
624 stat.un.b.lsRjtRsvd0 = 0;
625 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
626 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
627 stat.un.b.vendorUnique = 0;
628 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
629
630 /* 1 sec timeout */
631 mod_timer(&ndlp->nlp_delayfunc, jiffies + msecs_to_jiffies(1000));
632
633 spin_lock_irq(shost->host_lock);
634 ndlp->nlp_flag |= NLP_DELAY_TMO;
635 spin_unlock_irq(shost->host_lock);
636 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
637 ndlp->nlp_prev_state = ndlp->nlp_state;
638 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
639 return 0;
640 }
641
642 static int
643 lpfc_rcv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
644 struct lpfc_iocbq *cmdiocb, uint32_t els_cmd)
645 {
646 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
647 struct lpfc_hba *phba = vport->phba;
648 struct lpfc_vport **vports;
649 int i, active_vlink_present = 0 ;
650
651 /* Put ndlp in NPR state with 1 sec timeout for plogi, ACC logo */
652 /* Only call LOGO ACC for first LOGO, this avoids sending unnecessary
653 * PLOGIs during LOGO storms from a device.
654 */
655 spin_lock_irq(shost->host_lock);
656 ndlp->nlp_flag |= NLP_LOGO_ACC;
657 spin_unlock_irq(shost->host_lock);
658 if (els_cmd == ELS_CMD_PRLO)
659 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
660 else
661 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
662 if (ndlp->nlp_DID == Fabric_DID) {
663 if (vport->port_state <= LPFC_FDISC)
664 goto out;
665 lpfc_linkdown_port(vport);
666 spin_lock_irq(shost->host_lock);
667 vport->fc_flag |= FC_VPORT_LOGO_RCVD;
668 spin_unlock_irq(shost->host_lock);
669 vports = lpfc_create_vport_work_array(phba);
670 if (vports) {
671 for (i = 0; i <= phba->max_vports && vports[i] != NULL;
672 i++) {
673 if ((!(vports[i]->fc_flag &
674 FC_VPORT_LOGO_RCVD)) &&
675 (vports[i]->port_state > LPFC_FDISC)) {
676 active_vlink_present = 1;
677 break;
678 }
679 }
680 lpfc_destroy_vport_work_array(phba, vports);
681 }
682
683 /*
684 * Don't re-instantiate if vport is marked for deletion.
685 * If we are here first then vport_delete is going to wait
686 * for discovery to complete.
687 */
688 if (!(vport->load_flag & FC_UNLOADING) &&
689 active_vlink_present) {
690 /*
691 * If there are other active VLinks present,
692 * re-instantiate the Vlink using FDISC.
693 */
694 mod_timer(&ndlp->nlp_delayfunc,
695 jiffies + msecs_to_jiffies(1000));
696 spin_lock_irq(shost->host_lock);
697 ndlp->nlp_flag |= NLP_DELAY_TMO;
698 spin_unlock_irq(shost->host_lock);
699 ndlp->nlp_last_elscmd = ELS_CMD_FDISC;
700 vport->port_state = LPFC_FDISC;
701 } else {
702 spin_lock_irq(shost->host_lock);
703 phba->pport->fc_flag &= ~FC_LOGO_RCVD_DID_CHNG;
704 spin_unlock_irq(shost->host_lock);
705 lpfc_retry_pport_discovery(phba);
706 }
707 } else if ((!(ndlp->nlp_type & NLP_FABRIC) &&
708 ((ndlp->nlp_type & NLP_FCP_TARGET) ||
709 !(ndlp->nlp_type & NLP_FCP_INITIATOR))) ||
710 (ndlp->nlp_state == NLP_STE_ADISC_ISSUE)) {
711 /* Only try to re-login if this is NOT a Fabric Node */
712 mod_timer(&ndlp->nlp_delayfunc,
713 jiffies + msecs_to_jiffies(1000 * 1));
714 spin_lock_irq(shost->host_lock);
715 ndlp->nlp_flag |= NLP_DELAY_TMO;
716 spin_unlock_irq(shost->host_lock);
717
718 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
719 }
720 out:
721 ndlp->nlp_prev_state = ndlp->nlp_state;
722 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
723
724 spin_lock_irq(shost->host_lock);
725 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
726 spin_unlock_irq(shost->host_lock);
727 /* The driver has to wait until the ACC completes before it continues
728 * processing the LOGO. The action will resume in
729 * lpfc_cmpl_els_logo_acc routine. Since part of processing includes an
730 * unreg_login, the driver waits so the ACC does not get aborted.
731 */
732 return 0;
733 }
734
735 static uint32_t
736 lpfc_rcv_prli_support_check(struct lpfc_vport *vport,
737 struct lpfc_nodelist *ndlp,
738 struct lpfc_iocbq *cmdiocb)
739 {
740 struct ls_rjt stat;
741 uint32_t *payload;
742 uint32_t cmd;
743
744 payload = ((struct lpfc_dmabuf *)cmdiocb->context2)->virt;
745 cmd = *payload;
746 if (vport->phba->nvmet_support) {
747 /* Must be a NVME PRLI */
748 if (cmd == ELS_CMD_PRLI)
749 goto out;
750 } else {
751 /* Initiator mode. */
752 if (!vport->nvmei_support && (cmd == ELS_CMD_NVMEPRLI))
753 goto out;
754 }
755 return 1;
756 out:
757 lpfc_printf_vlog(vport, KERN_WARNING, LOG_NVME_DISC,
758 "6115 Rcv PRLI (%x) check failed: ndlp rpi %d "
759 "state x%x flags x%x\n",
760 cmd, ndlp->nlp_rpi, ndlp->nlp_state,
761 ndlp->nlp_flag);
762 memset(&stat, 0, sizeof(struct ls_rjt));
763 stat.un.b.lsRjtRsnCode = LSRJT_CMD_UNSUPPORTED;
764 stat.un.b.lsRjtRsnCodeExp = LSEXP_REQ_UNSUPPORTED;
765 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb,
766 ndlp, NULL);
767 return 0;
768 }
769
770 static void
771 lpfc_rcv_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
772 struct lpfc_iocbq *cmdiocb)
773 {
774 struct lpfc_hba *phba = vport->phba;
775 struct lpfc_dmabuf *pcmd;
776 uint32_t *lp;
777 PRLI *npr;
778 struct fc_rport *rport = ndlp->rport;
779 u32 roles;
780
781 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
782 lp = (uint32_t *) pcmd->virt;
783 npr = (PRLI *) ((uint8_t *) lp + sizeof (uint32_t));
784
785 if ((npr->prliType == PRLI_FCP_TYPE) ||
786 (npr->prliType == PRLI_NVME_TYPE)) {
787 if (npr->initiatorFunc) {
788 if (npr->prliType == PRLI_FCP_TYPE)
789 ndlp->nlp_type |= NLP_FCP_INITIATOR;
790 if (npr->prliType == PRLI_NVME_TYPE)
791 ndlp->nlp_type |= NLP_NVME_INITIATOR;
792 }
793 if (npr->targetFunc) {
794 if (npr->prliType == PRLI_FCP_TYPE)
795 ndlp->nlp_type |= NLP_FCP_TARGET;
796 if (npr->prliType == PRLI_NVME_TYPE)
797 ndlp->nlp_type |= NLP_NVME_TARGET;
798 if (npr->writeXferRdyDis)
799 ndlp->nlp_flag |= NLP_FIRSTBURST;
800 }
801 if (npr->Retry)
802 ndlp->nlp_fcp_info |= NLP_FCP_2_DEVICE;
803
804 /* If this driver is in nvme target mode, set the ndlp's fc4
805 * type to NVME provided the PRLI response claims NVME FC4
806 * type. Target mode does not issue gft_id so doesn't get
807 * the fc4 type set until now.
808 */
809 if (phba->nvmet_support && (npr->prliType == PRLI_NVME_TYPE)) {
810 ndlp->nlp_fc4_type |= NLP_FC4_NVME;
811 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
812 }
813 if (npr->prliType == PRLI_FCP_TYPE)
814 ndlp->nlp_fc4_type |= NLP_FC4_FCP;
815 }
816 if (rport) {
817 /* We need to update the rport role values */
818 roles = FC_RPORT_ROLE_UNKNOWN;
819 if (ndlp->nlp_type & NLP_FCP_INITIATOR)
820 roles |= FC_RPORT_ROLE_FCP_INITIATOR;
821 if (ndlp->nlp_type & NLP_FCP_TARGET)
822 roles |= FC_RPORT_ROLE_FCP_TARGET;
823
824 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
825 "rport rolechg: role:x%x did:x%x flg:x%x",
826 roles, ndlp->nlp_DID, ndlp->nlp_flag);
827
828 if (phba->cfg_enable_fc4_type != LPFC_ENABLE_NVME)
829 fc_remote_port_rolechg(rport, roles);
830 }
831 }
832
833 static uint32_t
834 lpfc_disc_set_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
835 {
836 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
837
838 if (!(ndlp->nlp_flag & NLP_RPI_REGISTERED)) {
839 spin_lock_irq(shost->host_lock);
840 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
841 spin_unlock_irq(shost->host_lock);
842 return 0;
843 }
844
845 if (!(vport->fc_flag & FC_PT2PT)) {
846 /* Check config parameter use-adisc or FCP-2 */
847 if (vport->cfg_use_adisc && ((vport->fc_flag & FC_RSCN_MODE) ||
848 ((ndlp->nlp_fcp_info & NLP_FCP_2_DEVICE) &&
849 (ndlp->nlp_type & NLP_FCP_TARGET)))) {
850 spin_lock_irq(shost->host_lock);
851 ndlp->nlp_flag |= NLP_NPR_ADISC;
852 spin_unlock_irq(shost->host_lock);
853 return 1;
854 }
855 }
856
857 spin_lock_irq(shost->host_lock);
858 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
859 spin_unlock_irq(shost->host_lock);
860 lpfc_unreg_rpi(vport, ndlp);
861 return 0;
862 }
863
864 /**
865 * lpfc_release_rpi - Release a RPI by issuing unreg_login mailbox cmd.
866 * @phba : Pointer to lpfc_hba structure.
867 * @vport: Pointer to lpfc_vport structure.
868 * @rpi : rpi to be release.
869 *
870 * This function will send a unreg_login mailbox command to the firmware
871 * to release a rpi.
872 **/
873 void
874 lpfc_release_rpi(struct lpfc_hba *phba,
875 struct lpfc_vport *vport,
876 uint16_t rpi)
877 {
878 LPFC_MBOXQ_t *pmb;
879 int rc;
880
881 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
882 GFP_KERNEL);
883 if (!pmb)
884 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
885 "2796 mailbox memory allocation failed \n");
886 else {
887 lpfc_unreg_login(phba, vport->vpi, rpi, pmb);
888 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
889 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
890 if (rc == MBX_NOT_FINISHED)
891 mempool_free(pmb, phba->mbox_mem_pool);
892 }
893 }
894
895 static uint32_t
896 lpfc_disc_illegal(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
897 void *arg, uint32_t evt)
898 {
899 struct lpfc_hba *phba;
900 LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
901 uint16_t rpi;
902
903 phba = vport->phba;
904 /* Release the RPI if reglogin completing */
905 if (!(phba->pport->load_flag & FC_UNLOADING) &&
906 (evt == NLP_EVT_CMPL_REG_LOGIN) &&
907 (!pmb->u.mb.mbxStatus)) {
908 rpi = pmb->u.mb.un.varWords[0];
909 lpfc_release_rpi(phba, vport, rpi);
910 }
911 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
912 "0271 Illegal State Transition: node x%x "
913 "event x%x, state x%x Data: x%x x%x\n",
914 ndlp->nlp_DID, evt, ndlp->nlp_state, ndlp->nlp_rpi,
915 ndlp->nlp_flag);
916 return ndlp->nlp_state;
917 }
918
919 static uint32_t
920 lpfc_cmpl_plogi_illegal(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
921 void *arg, uint32_t evt)
922 {
923 /* This transition is only legal if we previously
924 * rcv'ed a PLOGI. Since we don't want 2 discovery threads
925 * working on the same NPortID, do nothing for this thread
926 * to stop it.
927 */
928 if (!(ndlp->nlp_flag & NLP_RCV_PLOGI)) {
929 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
930 "0272 Illegal State Transition: node x%x "
931 "event x%x, state x%x Data: x%x x%x\n",
932 ndlp->nlp_DID, evt, ndlp->nlp_state, ndlp->nlp_rpi,
933 ndlp->nlp_flag);
934 }
935 return ndlp->nlp_state;
936 }
937
938 /* Start of Discovery State Machine routines */
939
940 static uint32_t
941 lpfc_rcv_plogi_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
942 void *arg, uint32_t evt)
943 {
944 struct lpfc_iocbq *cmdiocb;
945
946 cmdiocb = (struct lpfc_iocbq *) arg;
947
948 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb)) {
949 return ndlp->nlp_state;
950 }
951 return NLP_STE_FREED_NODE;
952 }
953
954 static uint32_t
955 lpfc_rcv_els_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
956 void *arg, uint32_t evt)
957 {
958 lpfc_issue_els_logo(vport, ndlp, 0);
959 return ndlp->nlp_state;
960 }
961
962 static uint32_t
963 lpfc_rcv_logo_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
964 void *arg, uint32_t evt)
965 {
966 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
967 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
968
969 spin_lock_irq(shost->host_lock);
970 ndlp->nlp_flag |= NLP_LOGO_ACC;
971 spin_unlock_irq(shost->host_lock);
972 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
973
974 return ndlp->nlp_state;
975 }
976
977 static uint32_t
978 lpfc_cmpl_logo_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
979 void *arg, uint32_t evt)
980 {
981 return NLP_STE_FREED_NODE;
982 }
983
984 static uint32_t
985 lpfc_device_rm_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
986 void *arg, uint32_t evt)
987 {
988 return NLP_STE_FREED_NODE;
989 }
990
991 static uint32_t
992 lpfc_device_recov_unused_node(struct lpfc_vport *vport,
993 struct lpfc_nodelist *ndlp,
994 void *arg, uint32_t evt)
995 {
996 return ndlp->nlp_state;
997 }
998
999 static uint32_t
1000 lpfc_rcv_plogi_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1001 void *arg, uint32_t evt)
1002 {
1003 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1004 struct lpfc_hba *phba = vport->phba;
1005 struct lpfc_iocbq *cmdiocb = arg;
1006 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
1007 uint32_t *lp = (uint32_t *) pcmd->virt;
1008 struct serv_parm *sp = (struct serv_parm *) (lp + 1);
1009 struct ls_rjt stat;
1010 int port_cmp;
1011
1012 memset(&stat, 0, sizeof (struct ls_rjt));
1013
1014 /* For a PLOGI, we only accept if our portname is less
1015 * than the remote portname.
1016 */
1017 phba->fc_stat.elsLogiCol++;
1018 port_cmp = memcmp(&vport->fc_portname, &sp->portName,
1019 sizeof(struct lpfc_name));
1020
1021 if (port_cmp >= 0) {
1022 /* Reject this request because the remote node will accept
1023 ours */
1024 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
1025 stat.un.b.lsRjtRsnCodeExp = LSEXP_CMD_IN_PROGRESS;
1026 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
1027 NULL);
1028 } else {
1029 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb) &&
1030 (ndlp->nlp_flag & NLP_NPR_2B_DISC) &&
1031 (vport->num_disc_nodes)) {
1032 spin_lock_irq(shost->host_lock);
1033 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1034 spin_unlock_irq(shost->host_lock);
1035 /* Check if there are more PLOGIs to be sent */
1036 lpfc_more_plogi(vport);
1037 if (vport->num_disc_nodes == 0) {
1038 spin_lock_irq(shost->host_lock);
1039 vport->fc_flag &= ~FC_NDISC_ACTIVE;
1040 spin_unlock_irq(shost->host_lock);
1041 lpfc_can_disctmo(vport);
1042 lpfc_end_rscn(vport);
1043 }
1044 }
1045 } /* If our portname was less */
1046
1047 return ndlp->nlp_state;
1048 }
1049
1050 static uint32_t
1051 lpfc_rcv_prli_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1052 void *arg, uint32_t evt)
1053 {
1054 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1055 struct ls_rjt stat;
1056
1057 memset(&stat, 0, sizeof (struct ls_rjt));
1058 stat.un.b.lsRjtRsnCode = LSRJT_LOGICAL_BSY;
1059 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
1060 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
1061 return ndlp->nlp_state;
1062 }
1063
1064 static uint32_t
1065 lpfc_rcv_logo_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1066 void *arg, uint32_t evt)
1067 {
1068 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1069
1070 /* software abort outstanding PLOGI */
1071 lpfc_els_abort(vport->phba, ndlp);
1072
1073 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
1074 return ndlp->nlp_state;
1075 }
1076
1077 static uint32_t
1078 lpfc_rcv_els_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1079 void *arg, uint32_t evt)
1080 {
1081 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1082 struct lpfc_hba *phba = vport->phba;
1083 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1084
1085 /* software abort outstanding PLOGI */
1086 lpfc_els_abort(phba, ndlp);
1087
1088 if (evt == NLP_EVT_RCV_LOGO) {
1089 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
1090 } else {
1091 lpfc_issue_els_logo(vport, ndlp, 0);
1092 }
1093
1094 /* Put ndlp in npr state set plogi timer for 1 sec */
1095 mod_timer(&ndlp->nlp_delayfunc, jiffies + msecs_to_jiffies(1000 * 1));
1096 spin_lock_irq(shost->host_lock);
1097 ndlp->nlp_flag |= NLP_DELAY_TMO;
1098 spin_unlock_irq(shost->host_lock);
1099 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
1100 ndlp->nlp_prev_state = NLP_STE_PLOGI_ISSUE;
1101 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1102
1103 return ndlp->nlp_state;
1104 }
1105
1106 static uint32_t
1107 lpfc_cmpl_plogi_plogi_issue(struct lpfc_vport *vport,
1108 struct lpfc_nodelist *ndlp,
1109 void *arg,
1110 uint32_t evt)
1111 {
1112 struct lpfc_hba *phba = vport->phba;
1113 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1114 struct lpfc_iocbq *cmdiocb, *rspiocb;
1115 struct lpfc_dmabuf *pcmd, *prsp, *mp;
1116 uint32_t *lp;
1117 uint32_t vid, flag;
1118 IOCB_t *irsp;
1119 struct serv_parm *sp;
1120 uint32_t ed_tov;
1121 LPFC_MBOXQ_t *mbox;
1122 int rc;
1123
1124 cmdiocb = (struct lpfc_iocbq *) arg;
1125 rspiocb = cmdiocb->context_un.rsp_iocb;
1126
1127 if (ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
1128 /* Recovery from PLOGI collision logic */
1129 return ndlp->nlp_state;
1130 }
1131
1132 irsp = &rspiocb->iocb;
1133
1134 if (irsp->ulpStatus)
1135 goto out;
1136
1137 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
1138
1139 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
1140 if (!prsp)
1141 goto out;
1142
1143 lp = (uint32_t *) prsp->virt;
1144 sp = (struct serv_parm *) ((uint8_t *) lp + sizeof (uint32_t));
1145
1146 /* Some switches have FDMI servers returning 0 for WWN */
1147 if ((ndlp->nlp_DID != FDMI_DID) &&
1148 (wwn_to_u64(sp->portName.u.wwn) == 0 ||
1149 wwn_to_u64(sp->nodeName.u.wwn) == 0)) {
1150 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1151 "0142 PLOGI RSP: Invalid WWN.\n");
1152 goto out;
1153 }
1154 if (!lpfc_check_sparm(vport, ndlp, sp, CLASS3, 0))
1155 goto out;
1156 /* PLOGI chkparm OK */
1157 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1158 "0121 PLOGI chkparm OK Data: x%x x%x x%x x%x\n",
1159 ndlp->nlp_DID, ndlp->nlp_state,
1160 ndlp->nlp_flag, ndlp->nlp_rpi);
1161 if (vport->cfg_fcp_class == 2 && (sp->cls2.classValid))
1162 ndlp->nlp_fcp_info |= CLASS2;
1163 else
1164 ndlp->nlp_fcp_info |= CLASS3;
1165
1166 ndlp->nlp_class_sup = 0;
1167 if (sp->cls1.classValid)
1168 ndlp->nlp_class_sup |= FC_COS_CLASS1;
1169 if (sp->cls2.classValid)
1170 ndlp->nlp_class_sup |= FC_COS_CLASS2;
1171 if (sp->cls3.classValid)
1172 ndlp->nlp_class_sup |= FC_COS_CLASS3;
1173 if (sp->cls4.classValid)
1174 ndlp->nlp_class_sup |= FC_COS_CLASS4;
1175 ndlp->nlp_maxframe =
1176 ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) | sp->cmn.bbRcvSizeLsb;
1177
1178 if ((vport->fc_flag & FC_PT2PT) &&
1179 (vport->fc_flag & FC_PT2PT_PLOGI)) {
1180 ed_tov = be32_to_cpu(sp->cmn.e_d_tov);
1181 if (sp->cmn.edtovResolution) {
1182 /* E_D_TOV ticks are in nanoseconds */
1183 ed_tov = (phba->fc_edtov + 999999) / 1000000;
1184 }
1185
1186 ndlp->nlp_flag &= ~NLP_SUPPRESS_RSP;
1187 if ((phba->sli.sli_flag & LPFC_SLI_SUPPRESS_RSP) &&
1188 sp->cmn.valid_vendor_ver_level) {
1189 vid = be32_to_cpu(sp->un.vv.vid);
1190 flag = be32_to_cpu(sp->un.vv.flags);
1191 if ((vid == LPFC_VV_EMLX_ID) &&
1192 (flag & LPFC_VV_SUPPRESS_RSP))
1193 ndlp->nlp_flag |= NLP_SUPPRESS_RSP;
1194 }
1195
1196 /*
1197 * Use the larger EDTOV
1198 * RATOV = 2 * EDTOV for pt-to-pt
1199 */
1200 if (ed_tov > phba->fc_edtov)
1201 phba->fc_edtov = ed_tov;
1202 phba->fc_ratov = (2 * phba->fc_edtov) / 1000;
1203
1204 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
1205
1206 /* Issue config_link / reg_vfi to account for updated TOV's */
1207 if (phba->sli_rev == LPFC_SLI_REV4) {
1208 lpfc_issue_reg_vfi(vport);
1209 } else {
1210 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1211 if (!mbox) {
1212 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1213 "0133 PLOGI: no memory "
1214 "for config_link "
1215 "Data: x%x x%x x%x x%x\n",
1216 ndlp->nlp_DID, ndlp->nlp_state,
1217 ndlp->nlp_flag, ndlp->nlp_rpi);
1218 goto out;
1219 }
1220
1221 lpfc_config_link(phba, mbox);
1222
1223 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1224 mbox->vport = vport;
1225 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
1226 if (rc == MBX_NOT_FINISHED) {
1227 mempool_free(mbox, phba->mbox_mem_pool);
1228 goto out;
1229 }
1230 }
1231 }
1232
1233 lpfc_unreg_rpi(vport, ndlp);
1234
1235 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1236 if (!mbox) {
1237 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1238 "0018 PLOGI: no memory for reg_login "
1239 "Data: x%x x%x x%x x%x\n",
1240 ndlp->nlp_DID, ndlp->nlp_state,
1241 ndlp->nlp_flag, ndlp->nlp_rpi);
1242 goto out;
1243 }
1244
1245 if (lpfc_reg_rpi(phba, vport->vpi, irsp->un.elsreq64.remoteID,
1246 (uint8_t *) sp, mbox, ndlp->nlp_rpi) == 0) {
1247 switch (ndlp->nlp_DID) {
1248 case NameServer_DID:
1249 mbox->mbox_cmpl = lpfc_mbx_cmpl_ns_reg_login;
1250 break;
1251 case FDMI_DID:
1252 mbox->mbox_cmpl = lpfc_mbx_cmpl_fdmi_reg_login;
1253 break;
1254 default:
1255 ndlp->nlp_flag |= NLP_REG_LOGIN_SEND;
1256 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
1257 }
1258 mbox->context2 = lpfc_nlp_get(ndlp);
1259 mbox->vport = vport;
1260 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
1261 != MBX_NOT_FINISHED) {
1262 lpfc_nlp_set_state(vport, ndlp,
1263 NLP_STE_REG_LOGIN_ISSUE);
1264 return ndlp->nlp_state;
1265 }
1266 if (ndlp->nlp_flag & NLP_REG_LOGIN_SEND)
1267 ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
1268 /* decrement node reference count to the failed mbox
1269 * command
1270 */
1271 lpfc_nlp_put(ndlp);
1272 mp = (struct lpfc_dmabuf *) mbox->context1;
1273 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1274 kfree(mp);
1275 mempool_free(mbox, phba->mbox_mem_pool);
1276
1277 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1278 "0134 PLOGI: cannot issue reg_login "
1279 "Data: x%x x%x x%x x%x\n",
1280 ndlp->nlp_DID, ndlp->nlp_state,
1281 ndlp->nlp_flag, ndlp->nlp_rpi);
1282 } else {
1283 mempool_free(mbox, phba->mbox_mem_pool);
1284
1285 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1286 "0135 PLOGI: cannot format reg_login "
1287 "Data: x%x x%x x%x x%x\n",
1288 ndlp->nlp_DID, ndlp->nlp_state,
1289 ndlp->nlp_flag, ndlp->nlp_rpi);
1290 }
1291
1292
1293 out:
1294 if (ndlp->nlp_DID == NameServer_DID) {
1295 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
1296 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1297 "0261 Cannot Register NameServer login\n");
1298 }
1299
1300 /*
1301 ** In case the node reference counter does not go to zero, ensure that
1302 ** the stale state for the node is not processed.
1303 */
1304
1305 ndlp->nlp_prev_state = ndlp->nlp_state;
1306 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1307 spin_lock_irq(shost->host_lock);
1308 ndlp->nlp_flag |= NLP_DEFER_RM;
1309 spin_unlock_irq(shost->host_lock);
1310 return NLP_STE_FREED_NODE;
1311 }
1312
1313 static uint32_t
1314 lpfc_cmpl_logo_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1315 void *arg, uint32_t evt)
1316 {
1317 return ndlp->nlp_state;
1318 }
1319
1320 static uint32_t
1321 lpfc_cmpl_reglogin_plogi_issue(struct lpfc_vport *vport,
1322 struct lpfc_nodelist *ndlp, void *arg, uint32_t evt)
1323 {
1324 struct lpfc_hba *phba;
1325 LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
1326 MAILBOX_t *mb = &pmb->u.mb;
1327 uint16_t rpi;
1328
1329 phba = vport->phba;
1330 /* Release the RPI */
1331 if (!(phba->pport->load_flag & FC_UNLOADING) &&
1332 !mb->mbxStatus) {
1333 rpi = pmb->u.mb.un.varWords[0];
1334 lpfc_release_rpi(phba, vport, rpi);
1335 }
1336 return ndlp->nlp_state;
1337 }
1338
1339 static uint32_t
1340 lpfc_device_rm_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1341 void *arg, uint32_t evt)
1342 {
1343 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1344
1345 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1346 spin_lock_irq(shost->host_lock);
1347 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
1348 spin_unlock_irq(shost->host_lock);
1349 return ndlp->nlp_state;
1350 } else {
1351 /* software abort outstanding PLOGI */
1352 lpfc_els_abort(vport->phba, ndlp);
1353
1354 lpfc_drop_node(vport, ndlp);
1355 return NLP_STE_FREED_NODE;
1356 }
1357 }
1358
1359 static uint32_t
1360 lpfc_device_recov_plogi_issue(struct lpfc_vport *vport,
1361 struct lpfc_nodelist *ndlp,
1362 void *arg,
1363 uint32_t evt)
1364 {
1365 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1366 struct lpfc_hba *phba = vport->phba;
1367
1368 /* Don't do anything that will mess up processing of the
1369 * previous RSCN.
1370 */
1371 if (vport->fc_flag & FC_RSCN_DEFERRED)
1372 return ndlp->nlp_state;
1373
1374 /* software abort outstanding PLOGI */
1375 lpfc_els_abort(phba, ndlp);
1376
1377 ndlp->nlp_prev_state = NLP_STE_PLOGI_ISSUE;
1378 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1379 spin_lock_irq(shost->host_lock);
1380 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
1381 spin_unlock_irq(shost->host_lock);
1382
1383 return ndlp->nlp_state;
1384 }
1385
1386 static uint32_t
1387 lpfc_rcv_plogi_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1388 void *arg, uint32_t evt)
1389 {
1390 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1391 struct lpfc_hba *phba = vport->phba;
1392 struct lpfc_iocbq *cmdiocb;
1393
1394 /* software abort outstanding ADISC */
1395 lpfc_els_abort(phba, ndlp);
1396
1397 cmdiocb = (struct lpfc_iocbq *) arg;
1398
1399 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb)) {
1400 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1401 spin_lock_irq(shost->host_lock);
1402 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1403 spin_unlock_irq(shost->host_lock);
1404 if (vport->num_disc_nodes)
1405 lpfc_more_adisc(vport);
1406 }
1407 return ndlp->nlp_state;
1408 }
1409 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1410 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
1411 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
1412
1413 return ndlp->nlp_state;
1414 }
1415
1416 static uint32_t
1417 lpfc_rcv_prli_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1418 void *arg, uint32_t evt)
1419 {
1420 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1421
1422 if (lpfc_rcv_prli_support_check(vport, ndlp, cmdiocb))
1423 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
1424 return ndlp->nlp_state;
1425 }
1426
1427 static uint32_t
1428 lpfc_rcv_logo_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1429 void *arg, uint32_t evt)
1430 {
1431 struct lpfc_hba *phba = vport->phba;
1432 struct lpfc_iocbq *cmdiocb;
1433
1434 cmdiocb = (struct lpfc_iocbq *) arg;
1435
1436 /* software abort outstanding ADISC */
1437 lpfc_els_abort(phba, ndlp);
1438
1439 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
1440 return ndlp->nlp_state;
1441 }
1442
1443 static uint32_t
1444 lpfc_rcv_padisc_adisc_issue(struct lpfc_vport *vport,
1445 struct lpfc_nodelist *ndlp,
1446 void *arg, uint32_t evt)
1447 {
1448 struct lpfc_iocbq *cmdiocb;
1449
1450 cmdiocb = (struct lpfc_iocbq *) arg;
1451
1452 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
1453 return ndlp->nlp_state;
1454 }
1455
1456 static uint32_t
1457 lpfc_rcv_prlo_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1458 void *arg, uint32_t evt)
1459 {
1460 struct lpfc_iocbq *cmdiocb;
1461
1462 cmdiocb = (struct lpfc_iocbq *) arg;
1463
1464 /* Treat like rcv logo */
1465 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_PRLO);
1466 return ndlp->nlp_state;
1467 }
1468
1469 static uint32_t
1470 lpfc_cmpl_adisc_adisc_issue(struct lpfc_vport *vport,
1471 struct lpfc_nodelist *ndlp,
1472 void *arg, uint32_t evt)
1473 {
1474 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1475 struct lpfc_hba *phba = vport->phba;
1476 struct lpfc_iocbq *cmdiocb, *rspiocb;
1477 IOCB_t *irsp;
1478 ADISC *ap;
1479 int rc;
1480
1481 cmdiocb = (struct lpfc_iocbq *) arg;
1482 rspiocb = cmdiocb->context_un.rsp_iocb;
1483
1484 ap = (ADISC *)lpfc_check_elscmpl_iocb(phba, cmdiocb, rspiocb);
1485 irsp = &rspiocb->iocb;
1486
1487 if ((irsp->ulpStatus) ||
1488 (!lpfc_check_adisc(vport, ndlp, &ap->nodeName, &ap->portName))) {
1489 /* 1 sec timeout */
1490 mod_timer(&ndlp->nlp_delayfunc,
1491 jiffies + msecs_to_jiffies(1000));
1492 spin_lock_irq(shost->host_lock);
1493 ndlp->nlp_flag |= NLP_DELAY_TMO;
1494 spin_unlock_irq(shost->host_lock);
1495 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
1496
1497 memset(&ndlp->nlp_nodename, 0, sizeof(struct lpfc_name));
1498 memset(&ndlp->nlp_portname, 0, sizeof(struct lpfc_name));
1499
1500 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1501 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1502 lpfc_unreg_rpi(vport, ndlp);
1503 return ndlp->nlp_state;
1504 }
1505
1506 if (phba->sli_rev == LPFC_SLI_REV4) {
1507 rc = lpfc_sli4_resume_rpi(ndlp, NULL, NULL);
1508 if (rc) {
1509 /* Stay in state and retry. */
1510 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1511 return ndlp->nlp_state;
1512 }
1513 }
1514
1515 if (ndlp->nlp_type & NLP_FCP_TARGET) {
1516 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1517 lpfc_nlp_set_state(vport, ndlp, NLP_STE_MAPPED_NODE);
1518 } else {
1519 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1520 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
1521 }
1522
1523 return ndlp->nlp_state;
1524 }
1525
1526 static uint32_t
1527 lpfc_device_rm_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1528 void *arg, uint32_t evt)
1529 {
1530 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1531
1532 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1533 spin_lock_irq(shost->host_lock);
1534 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
1535 spin_unlock_irq(shost->host_lock);
1536 return ndlp->nlp_state;
1537 } else {
1538 /* software abort outstanding ADISC */
1539 lpfc_els_abort(vport->phba, ndlp);
1540
1541 lpfc_drop_node(vport, ndlp);
1542 return NLP_STE_FREED_NODE;
1543 }
1544 }
1545
1546 static uint32_t
1547 lpfc_device_recov_adisc_issue(struct lpfc_vport *vport,
1548 struct lpfc_nodelist *ndlp,
1549 void *arg,
1550 uint32_t evt)
1551 {
1552 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1553 struct lpfc_hba *phba = vport->phba;
1554
1555 /* Don't do anything that will mess up processing of the
1556 * previous RSCN.
1557 */
1558 if (vport->fc_flag & FC_RSCN_DEFERRED)
1559 return ndlp->nlp_state;
1560
1561 /* software abort outstanding ADISC */
1562 lpfc_els_abort(phba, ndlp);
1563
1564 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1565 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1566 spin_lock_irq(shost->host_lock);
1567 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
1568 spin_unlock_irq(shost->host_lock);
1569 lpfc_disc_set_adisc(vport, ndlp);
1570 return ndlp->nlp_state;
1571 }
1572
1573 static uint32_t
1574 lpfc_rcv_plogi_reglogin_issue(struct lpfc_vport *vport,
1575 struct lpfc_nodelist *ndlp,
1576 void *arg,
1577 uint32_t evt)
1578 {
1579 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1580
1581 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
1582 return ndlp->nlp_state;
1583 }
1584
1585 static uint32_t
1586 lpfc_rcv_prli_reglogin_issue(struct lpfc_vport *vport,
1587 struct lpfc_nodelist *ndlp,
1588 void *arg,
1589 uint32_t evt)
1590 {
1591 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1592 struct ls_rjt stat;
1593
1594 if (!lpfc_rcv_prli_support_check(vport, ndlp, cmdiocb)) {
1595 return ndlp->nlp_state;
1596 }
1597 if (vport->phba->nvmet_support) {
1598 /* NVME Target mode. Handle and respond to the PRLI and
1599 * transition to UNMAPPED provided the RPI has completed
1600 * registration.
1601 */
1602 if (ndlp->nlp_flag & NLP_RPI_REGISTERED) {
1603 lpfc_rcv_prli(vport, ndlp, cmdiocb);
1604 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
1605 } else {
1606 /* RPI registration has not completed. Reject the PRLI
1607 * to prevent an illegal state transition when the
1608 * rpi registration does complete.
1609 */
1610 memset(&stat, 0, sizeof(struct ls_rjt));
1611 stat.un.b.lsRjtRsnCode = LSRJT_LOGICAL_BSY;
1612 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
1613 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb,
1614 ndlp, NULL);
1615 return ndlp->nlp_state;
1616 }
1617 } else {
1618 /* Initiator mode. */
1619 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
1620 }
1621 return ndlp->nlp_state;
1622 }
1623
1624 static uint32_t
1625 lpfc_rcv_logo_reglogin_issue(struct lpfc_vport *vport,
1626 struct lpfc_nodelist *ndlp,
1627 void *arg,
1628 uint32_t evt)
1629 {
1630 struct lpfc_hba *phba = vport->phba;
1631 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1632 LPFC_MBOXQ_t *mb;
1633 LPFC_MBOXQ_t *nextmb;
1634 struct lpfc_dmabuf *mp;
1635
1636 cmdiocb = (struct lpfc_iocbq *) arg;
1637
1638 /* cleanup any ndlp on mbox q waiting for reglogin cmpl */
1639 if ((mb = phba->sli.mbox_active)) {
1640 if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) &&
1641 (ndlp == (struct lpfc_nodelist *) mb->context2)) {
1642 ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
1643 lpfc_nlp_put(ndlp);
1644 mb->context2 = NULL;
1645 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1646 }
1647 }
1648
1649 spin_lock_irq(&phba->hbalock);
1650 list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
1651 if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) &&
1652 (ndlp == (struct lpfc_nodelist *) mb->context2)) {
1653 mp = (struct lpfc_dmabuf *) (mb->context1);
1654 if (mp) {
1655 __lpfc_mbuf_free(phba, mp->virt, mp->phys);
1656 kfree(mp);
1657 }
1658 ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
1659 lpfc_nlp_put(ndlp);
1660 list_del(&mb->list);
1661 phba->sli.mboxq_cnt--;
1662 mempool_free(mb, phba->mbox_mem_pool);
1663 }
1664 }
1665 spin_unlock_irq(&phba->hbalock);
1666
1667 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
1668 return ndlp->nlp_state;
1669 }
1670
1671 static uint32_t
1672 lpfc_rcv_padisc_reglogin_issue(struct lpfc_vport *vport,
1673 struct lpfc_nodelist *ndlp,
1674 void *arg,
1675 uint32_t evt)
1676 {
1677 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1678
1679 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
1680 return ndlp->nlp_state;
1681 }
1682
1683 static uint32_t
1684 lpfc_rcv_prlo_reglogin_issue(struct lpfc_vport *vport,
1685 struct lpfc_nodelist *ndlp,
1686 void *arg,
1687 uint32_t evt)
1688 {
1689 struct lpfc_iocbq *cmdiocb;
1690
1691 cmdiocb = (struct lpfc_iocbq *) arg;
1692 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
1693 return ndlp->nlp_state;
1694 }
1695
1696 static uint32_t
1697 lpfc_cmpl_reglogin_reglogin_issue(struct lpfc_vport *vport,
1698 struct lpfc_nodelist *ndlp,
1699 void *arg,
1700 uint32_t evt)
1701 {
1702 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1703 struct lpfc_hba *phba = vport->phba;
1704 LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
1705 MAILBOX_t *mb = &pmb->u.mb;
1706 uint32_t did = mb->un.varWords[1];
1707 int rc = 0;
1708
1709 if (mb->mbxStatus) {
1710 /* RegLogin failed */
1711 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
1712 "0246 RegLogin failed Data: x%x x%x x%x x%x "
1713 "x%x\n",
1714 did, mb->mbxStatus, vport->port_state,
1715 mb->un.varRegLogin.vpi,
1716 mb->un.varRegLogin.rpi);
1717 /*
1718 * If RegLogin failed due to lack of HBA resources do not
1719 * retry discovery.
1720 */
1721 if (mb->mbxStatus == MBXERR_RPI_FULL) {
1722 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1723 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1724 return ndlp->nlp_state;
1725 }
1726
1727 /* Put ndlp in npr state set plogi timer for 1 sec */
1728 mod_timer(&ndlp->nlp_delayfunc,
1729 jiffies + msecs_to_jiffies(1000 * 1));
1730 spin_lock_irq(shost->host_lock);
1731 ndlp->nlp_flag |= NLP_DELAY_TMO;
1732 spin_unlock_irq(shost->host_lock);
1733 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
1734
1735 lpfc_issue_els_logo(vport, ndlp, 0);
1736 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1737 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1738 return ndlp->nlp_state;
1739 }
1740
1741 /* SLI4 ports have preallocated logical rpis. */
1742 if (phba->sli_rev < LPFC_SLI_REV4)
1743 ndlp->nlp_rpi = mb->un.varWords[0];
1744
1745 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
1746
1747 /* Only if we are not a fabric nport do we issue PRLI */
1748 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1749 "3066 RegLogin Complete on x%x x%x x%x\n",
1750 did, ndlp->nlp_type, ndlp->nlp_fc4_type);
1751 if (!(ndlp->nlp_type & NLP_FABRIC) &&
1752 (phba->nvmet_support == 0)) {
1753 /* The driver supports FCP and NVME concurrently. If the
1754 * ndlp's nlp_fc4_type is still zero, the driver doesn't
1755 * know what PRLI to send yet. Figure that out now and
1756 * call PRLI depending on the outcome.
1757 */
1758 if (vport->fc_flag & FC_PT2PT) {
1759 /* If we are pt2pt, there is no Fabric to determine
1760 * the FC4 type of the remote nport. So if NVME
1761 * is configured try it.
1762 */
1763 ndlp->nlp_fc4_type |= NLP_FC4_FCP;
1764 if ((phba->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
1765 (phba->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) {
1766 ndlp->nlp_fc4_type |= NLP_FC4_NVME;
1767 /* We need to update the localport also */
1768 lpfc_nvme_update_localport(vport);
1769 }
1770
1771 } else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
1772 ndlp->nlp_fc4_type |= NLP_FC4_FCP;
1773
1774 } else if (ndlp->nlp_fc4_type == 0) {
1775 rc = lpfc_ns_cmd(vport, SLI_CTNS_GFT_ID,
1776 0, ndlp->nlp_DID);
1777 return ndlp->nlp_state;
1778 }
1779
1780 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1781 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
1782 lpfc_issue_els_prli(vport, ndlp, 0);
1783 } else {
1784 if ((vport->fc_flag & FC_PT2PT) && phba->nvmet_support)
1785 phba->targetport->port_id = vport->fc_myDID;
1786
1787 /* Only Fabric ports should transition. NVME target
1788 * must complete PRLI.
1789 */
1790 if (ndlp->nlp_type & NLP_FABRIC) {
1791 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1792 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
1793 }
1794 }
1795 return ndlp->nlp_state;
1796 }
1797
1798 static uint32_t
1799 lpfc_device_rm_reglogin_issue(struct lpfc_vport *vport,
1800 struct lpfc_nodelist *ndlp,
1801 void *arg,
1802 uint32_t evt)
1803 {
1804 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1805
1806 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1807 spin_lock_irq(shost->host_lock);
1808 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
1809 spin_unlock_irq(shost->host_lock);
1810 return ndlp->nlp_state;
1811 } else {
1812 lpfc_drop_node(vport, ndlp);
1813 return NLP_STE_FREED_NODE;
1814 }
1815 }
1816
1817 static uint32_t
1818 lpfc_device_recov_reglogin_issue(struct lpfc_vport *vport,
1819 struct lpfc_nodelist *ndlp,
1820 void *arg,
1821 uint32_t evt)
1822 {
1823 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1824
1825 /* Don't do anything that will mess up processing of the
1826 * previous RSCN.
1827 */
1828 if (vport->fc_flag & FC_RSCN_DEFERRED)
1829 return ndlp->nlp_state;
1830
1831 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1832 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1833 spin_lock_irq(shost->host_lock);
1834
1835 /* If we are a target we won't immediately transition into PRLI,
1836 * so if REG_LOGIN already completed we don't need to ignore it.
1837 */
1838 if (!(ndlp->nlp_flag & NLP_RPI_REGISTERED) ||
1839 !vport->phba->nvmet_support)
1840 ndlp->nlp_flag |= NLP_IGNR_REG_CMPL;
1841
1842 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
1843 spin_unlock_irq(shost->host_lock);
1844 lpfc_disc_set_adisc(vport, ndlp);
1845 return ndlp->nlp_state;
1846 }
1847
1848 static uint32_t
1849 lpfc_rcv_plogi_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1850 void *arg, uint32_t evt)
1851 {
1852 struct lpfc_iocbq *cmdiocb;
1853
1854 cmdiocb = (struct lpfc_iocbq *) arg;
1855
1856 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
1857 return ndlp->nlp_state;
1858 }
1859
1860 static uint32_t
1861 lpfc_rcv_prli_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1862 void *arg, uint32_t evt)
1863 {
1864 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1865
1866 if (!lpfc_rcv_prli_support_check(vport, ndlp, cmdiocb))
1867 return ndlp->nlp_state;
1868 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
1869 return ndlp->nlp_state;
1870 }
1871
1872 static uint32_t
1873 lpfc_rcv_logo_prli_issue(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 /* Software abort outstanding PRLI before sending acc */
1879 lpfc_els_abort(vport->phba, ndlp);
1880
1881 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
1882 return ndlp->nlp_state;
1883 }
1884
1885 static uint32_t
1886 lpfc_rcv_padisc_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1887 void *arg, uint32_t evt)
1888 {
1889 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1890
1891 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
1892 return ndlp->nlp_state;
1893 }
1894
1895 /* This routine is envoked when we rcv a PRLO request from a nport
1896 * we are logged into. We should send back a PRLO rsp setting the
1897 * appropriate bits.
1898 * NEXT STATE = PRLI_ISSUE
1899 */
1900 static uint32_t
1901 lpfc_rcv_prlo_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1902 void *arg, uint32_t evt)
1903 {
1904 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1905
1906 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
1907 return ndlp->nlp_state;
1908 }
1909
1910 static uint32_t
1911 lpfc_cmpl_prli_prli_issue(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, *rspiocb;
1916 struct lpfc_hba *phba = vport->phba;
1917 IOCB_t *irsp;
1918 PRLI *npr;
1919 struct lpfc_nvme_prli *nvpr;
1920 void *temp_ptr;
1921
1922 cmdiocb = (struct lpfc_iocbq *) arg;
1923 rspiocb = cmdiocb->context_un.rsp_iocb;
1924
1925 /* A solicited PRLI is either FCP or NVME. The PRLI cmd/rsp
1926 * format is different so NULL the two PRLI types so that the
1927 * driver correctly gets the correct context.
1928 */
1929 npr = NULL;
1930 nvpr = NULL;
1931 temp_ptr = lpfc_check_elscmpl_iocb(phba, cmdiocb, rspiocb);
1932 if (cmdiocb->iocb_flag & LPFC_PRLI_FCP_REQ)
1933 npr = (PRLI *) temp_ptr;
1934 else if (cmdiocb->iocb_flag & LPFC_PRLI_NVME_REQ)
1935 nvpr = (struct lpfc_nvme_prli *) temp_ptr;
1936
1937 irsp = &rspiocb->iocb;
1938 if (irsp->ulpStatus) {
1939 if ((vport->port_type == LPFC_NPIV_PORT) &&
1940 vport->cfg_restrict_login) {
1941 goto out;
1942 }
1943
1944 /* When the rport rejected the FCP PRLI as unsupported.
1945 * This should only happen in Pt2Pt so an NVME PRLI
1946 * should be outstanding still.
1947 */
1948 if (npr && ndlp->nlp_flag & NLP_FCP_PRLI_RJT) {
1949 ndlp->nlp_fc4_type &= ~NLP_FC4_FCP;
1950 goto out_err;
1951 }
1952
1953 /* The LS Req had some error. Don't let this be a
1954 * target.
1955 */
1956 if ((ndlp->fc4_prli_sent == 1) &&
1957 (ndlp->nlp_state == NLP_STE_PRLI_ISSUE) &&
1958 (ndlp->nlp_type & (NLP_FCP_TARGET | NLP_FCP_INITIATOR)))
1959 /* The FCP PRLI completed successfully but
1960 * the NVME PRLI failed. Since they are sent in
1961 * succession, allow the FCP to complete.
1962 */
1963 goto out_err;
1964
1965 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
1966 ndlp->nlp_type |= NLP_FCP_INITIATOR;
1967 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
1968 return ndlp->nlp_state;
1969 }
1970
1971 if (npr && (npr->acceptRspCode == PRLI_REQ_EXECUTED) &&
1972 (npr->prliType == PRLI_FCP_TYPE)) {
1973 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_DISC,
1974 "6028 FCP NPR PRLI Cmpl Init %d Target %d\n",
1975 npr->initiatorFunc,
1976 npr->targetFunc);
1977 if (npr->initiatorFunc)
1978 ndlp->nlp_type |= NLP_FCP_INITIATOR;
1979 if (npr->targetFunc) {
1980 ndlp->nlp_type |= NLP_FCP_TARGET;
1981 if (npr->writeXferRdyDis)
1982 ndlp->nlp_flag |= NLP_FIRSTBURST;
1983 }
1984 if (npr->Retry)
1985 ndlp->nlp_fcp_info |= NLP_FCP_2_DEVICE;
1986
1987 } else if (nvpr &&
1988 (bf_get_be32(prli_acc_rsp_code, nvpr) ==
1989 PRLI_REQ_EXECUTED) &&
1990 (bf_get_be32(prli_type_code, nvpr) ==
1991 PRLI_NVME_TYPE)) {
1992
1993 /* Complete setting up the remote ndlp personality. */
1994 if (bf_get_be32(prli_init, nvpr))
1995 ndlp->nlp_type |= NLP_NVME_INITIATOR;
1996
1997 /* Target driver cannot solicit NVME FB. */
1998 if (bf_get_be32(prli_tgt, nvpr)) {
1999 /* Complete the nvme target roles. The transport
2000 * needs to know if the rport is capable of
2001 * discovery in addition to its role.
2002 */
2003 ndlp->nlp_type |= NLP_NVME_TARGET;
2004 if (bf_get_be32(prli_disc, nvpr))
2005 ndlp->nlp_type |= NLP_NVME_DISCOVERY;
2006
2007 /*
2008 * If prli_fba is set, the Target supports FirstBurst.
2009 * If prli_fb_sz is 0, the FirstBurst size is unlimited,
2010 * otherwise it defines the actual size supported by
2011 * the NVME Target.
2012 */
2013 if ((bf_get_be32(prli_fba, nvpr) == 1) &&
2014 (phba->cfg_nvme_enable_fb) &&
2015 (!phba->nvmet_support)) {
2016 /* Both sides support FB. The target's first
2017 * burst size is a 512 byte encoded value.
2018 */
2019 ndlp->nlp_flag |= NLP_FIRSTBURST;
2020 ndlp->nvme_fb_size = bf_get_be32(prli_fb_sz,
2021 nvpr);
2022
2023 /* Expressed in units of 512 bytes */
2024 if (ndlp->nvme_fb_size)
2025 ndlp->nvme_fb_size <<=
2026 LPFC_NVME_FB_SHIFT;
2027 else
2028 ndlp->nvme_fb_size = LPFC_NVME_MAX_FB;
2029 }
2030 }
2031
2032 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_DISC,
2033 "6029 NVME PRLI Cmpl w1 x%08x "
2034 "w4 x%08x w5 x%08x flag x%x, "
2035 "fcp_info x%x nlp_type x%x\n",
2036 be32_to_cpu(nvpr->word1),
2037 be32_to_cpu(nvpr->word4),
2038 be32_to_cpu(nvpr->word5),
2039 ndlp->nlp_flag, ndlp->nlp_fcp_info,
2040 ndlp->nlp_type);
2041 }
2042 if (!(ndlp->nlp_type & NLP_FCP_TARGET) &&
2043 (vport->port_type == LPFC_NPIV_PORT) &&
2044 vport->cfg_restrict_login) {
2045 out:
2046 spin_lock_irq(shost->host_lock);
2047 ndlp->nlp_flag |= NLP_TARGET_REMOVE;
2048 spin_unlock_irq(shost->host_lock);
2049 lpfc_issue_els_logo(vport, ndlp, 0);
2050
2051 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
2052 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2053 return ndlp->nlp_state;
2054 }
2055
2056 out_err:
2057 /* The ndlp state cannot move to MAPPED or UNMAPPED before all PRLIs
2058 * are complete.
2059 */
2060 if (ndlp->fc4_prli_sent == 0) {
2061 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
2062 if (ndlp->nlp_type & (NLP_FCP_TARGET | NLP_NVME_TARGET))
2063 lpfc_nlp_set_state(vport, ndlp, NLP_STE_MAPPED_NODE);
2064 else if (ndlp->nlp_type &
2065 (NLP_FCP_INITIATOR | NLP_NVME_INITIATOR))
2066 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
2067 } else
2068 lpfc_printf_vlog(vport,
2069 KERN_INFO, LOG_ELS,
2070 "3067 PRLI's still outstanding "
2071 "on x%06x - count %d, Pend Node Mode "
2072 "transition...\n",
2073 ndlp->nlp_DID, ndlp->fc4_prli_sent);
2074
2075 return ndlp->nlp_state;
2076 }
2077
2078 /*! lpfc_device_rm_prli_issue
2079 *
2080 * \pre
2081 * \post
2082 * \param phba
2083 * \param ndlp
2084 * \param arg
2085 * \param evt
2086 * \return uint32_t
2087 *
2088 * \b Description:
2089 * This routine is envoked when we a request to remove a nport we are in the
2090 * process of PRLIing. We should software abort outstanding prli, unreg
2091 * login, send a logout. We will change node state to UNUSED_NODE, put it
2092 * on plogi list so it can be freed when LOGO completes.
2093 *
2094 */
2095
2096 static uint32_t
2097 lpfc_device_rm_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2098 void *arg, uint32_t evt)
2099 {
2100 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2101
2102 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
2103 spin_lock_irq(shost->host_lock);
2104 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
2105 spin_unlock_irq(shost->host_lock);
2106 return ndlp->nlp_state;
2107 } else {
2108 /* software abort outstanding PLOGI */
2109 lpfc_els_abort(vport->phba, ndlp);
2110
2111 lpfc_drop_node(vport, ndlp);
2112 return NLP_STE_FREED_NODE;
2113 }
2114 }
2115
2116
2117 /*! lpfc_device_recov_prli_issue
2118 *
2119 * \pre
2120 * \post
2121 * \param phba
2122 * \param ndlp
2123 * \param arg
2124 * \param evt
2125 * \return uint32_t
2126 *
2127 * \b Description:
2128 * The routine is envoked when the state of a device is unknown, like
2129 * during a link down. We should remove the nodelist entry from the
2130 * unmapped list, issue a UNREG_LOGIN, do a software abort of the
2131 * outstanding PRLI command, then free the node entry.
2132 */
2133 static uint32_t
2134 lpfc_device_recov_prli_issue(struct lpfc_vport *vport,
2135 struct lpfc_nodelist *ndlp,
2136 void *arg,
2137 uint32_t evt)
2138 {
2139 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2140 struct lpfc_hba *phba = vport->phba;
2141
2142 /* Don't do anything that will mess up processing of the
2143 * previous RSCN.
2144 */
2145 if (vport->fc_flag & FC_RSCN_DEFERRED)
2146 return ndlp->nlp_state;
2147
2148 /* software abort outstanding PRLI */
2149 lpfc_els_abort(phba, ndlp);
2150
2151 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
2152 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2153 spin_lock_irq(shost->host_lock);
2154 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
2155 spin_unlock_irq(shost->host_lock);
2156 lpfc_disc_set_adisc(vport, ndlp);
2157 return ndlp->nlp_state;
2158 }
2159
2160 static uint32_t
2161 lpfc_rcv_plogi_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2162 void *arg, uint32_t evt)
2163 {
2164 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *)arg;
2165 struct ls_rjt stat;
2166
2167 memset(&stat, 0, sizeof(struct ls_rjt));
2168 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
2169 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
2170 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
2171 return ndlp->nlp_state;
2172 }
2173
2174 static uint32_t
2175 lpfc_rcv_prli_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2176 void *arg, uint32_t evt)
2177 {
2178 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *)arg;
2179 struct ls_rjt stat;
2180
2181 memset(&stat, 0, sizeof(struct ls_rjt));
2182 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
2183 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
2184 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
2185 return ndlp->nlp_state;
2186 }
2187
2188 static uint32_t
2189 lpfc_rcv_logo_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2190 void *arg, uint32_t evt)
2191 {
2192 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2193 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *)arg;
2194
2195 spin_lock_irq(shost->host_lock);
2196 ndlp->nlp_flag |= NLP_LOGO_ACC;
2197 spin_unlock_irq(shost->host_lock);
2198 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
2199 return ndlp->nlp_state;
2200 }
2201
2202 static uint32_t
2203 lpfc_rcv_padisc_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2204 void *arg, uint32_t evt)
2205 {
2206 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *)arg;
2207 struct ls_rjt stat;
2208
2209 memset(&stat, 0, sizeof(struct ls_rjt));
2210 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
2211 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
2212 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
2213 return ndlp->nlp_state;
2214 }
2215
2216 static uint32_t
2217 lpfc_rcv_prlo_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2218 void *arg, uint32_t evt)
2219 {
2220 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *)arg;
2221 struct ls_rjt stat;
2222
2223 memset(&stat, 0, sizeof(struct ls_rjt));
2224 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
2225 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
2226 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
2227 return ndlp->nlp_state;
2228 }
2229
2230 static uint32_t
2231 lpfc_cmpl_logo_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2232 void *arg, uint32_t evt)
2233 {
2234 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2235
2236 ndlp->nlp_prev_state = NLP_STE_LOGO_ISSUE;
2237 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2238 spin_lock_irq(shost->host_lock);
2239 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
2240 spin_unlock_irq(shost->host_lock);
2241 lpfc_disc_set_adisc(vport, ndlp);
2242 return ndlp->nlp_state;
2243 }
2244
2245 static uint32_t
2246 lpfc_device_rm_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2247 void *arg, uint32_t evt)
2248 {
2249 /*
2250 * DevLoss has timed out and is calling for Device Remove.
2251 * In this case, abort the LOGO and cleanup the ndlp
2252 */
2253
2254 lpfc_unreg_rpi(vport, ndlp);
2255 /* software abort outstanding PLOGI */
2256 lpfc_els_abort(vport->phba, ndlp);
2257 lpfc_drop_node(vport, ndlp);
2258 return NLP_STE_FREED_NODE;
2259 }
2260
2261 static uint32_t
2262 lpfc_device_recov_logo_issue(struct lpfc_vport *vport,
2263 struct lpfc_nodelist *ndlp,
2264 void *arg, uint32_t evt)
2265 {
2266 /*
2267 * Device Recovery events have no meaning for a node with a LOGO
2268 * outstanding. The LOGO has to complete first and handle the
2269 * node from that point.
2270 */
2271 return ndlp->nlp_state;
2272 }
2273
2274 static uint32_t
2275 lpfc_rcv_plogi_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2276 void *arg, uint32_t evt)
2277 {
2278 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2279
2280 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
2281 return ndlp->nlp_state;
2282 }
2283
2284 static uint32_t
2285 lpfc_rcv_prli_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2286 void *arg, uint32_t evt)
2287 {
2288 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2289
2290 if (!lpfc_rcv_prli_support_check(vport, ndlp, cmdiocb))
2291 return ndlp->nlp_state;
2292
2293 lpfc_rcv_prli(vport, ndlp, cmdiocb);
2294 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
2295 return ndlp->nlp_state;
2296 }
2297
2298 static uint32_t
2299 lpfc_rcv_logo_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2300 void *arg, uint32_t evt)
2301 {
2302 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2303
2304 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
2305 return ndlp->nlp_state;
2306 }
2307
2308 static uint32_t
2309 lpfc_rcv_padisc_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2310 void *arg, uint32_t evt)
2311 {
2312 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2313
2314 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
2315 return ndlp->nlp_state;
2316 }
2317
2318 static uint32_t
2319 lpfc_rcv_prlo_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2320 void *arg, uint32_t evt)
2321 {
2322 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2323
2324 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
2325 return ndlp->nlp_state;
2326 }
2327
2328 static uint32_t
2329 lpfc_device_recov_unmap_node(struct lpfc_vport *vport,
2330 struct lpfc_nodelist *ndlp,
2331 void *arg,
2332 uint32_t evt)
2333 {
2334 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2335
2336 ndlp->nlp_prev_state = NLP_STE_UNMAPPED_NODE;
2337 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2338 spin_lock_irq(shost->host_lock);
2339 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
2340 spin_unlock_irq(shost->host_lock);
2341 lpfc_disc_set_adisc(vport, ndlp);
2342
2343 return ndlp->nlp_state;
2344 }
2345
2346 static uint32_t
2347 lpfc_rcv_plogi_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2348 void *arg, uint32_t evt)
2349 {
2350 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2351
2352 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
2353 return ndlp->nlp_state;
2354 }
2355
2356 static uint32_t
2357 lpfc_rcv_prli_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2358 void *arg, uint32_t evt)
2359 {
2360 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2361
2362 if (!lpfc_rcv_prli_support_check(vport, ndlp, cmdiocb))
2363 return ndlp->nlp_state;
2364 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
2365 return ndlp->nlp_state;
2366 }
2367
2368 static uint32_t
2369 lpfc_rcv_logo_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2370 void *arg, uint32_t evt)
2371 {
2372 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2373
2374 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
2375 return ndlp->nlp_state;
2376 }
2377
2378 static uint32_t
2379 lpfc_rcv_padisc_mapped_node(struct lpfc_vport *vport,
2380 struct lpfc_nodelist *ndlp,
2381 void *arg, uint32_t evt)
2382 {
2383 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2384
2385 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
2386 return ndlp->nlp_state;
2387 }
2388
2389 static uint32_t
2390 lpfc_rcv_prlo_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2391 void *arg, uint32_t evt)
2392 {
2393 struct lpfc_hba *phba = vport->phba;
2394 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2395
2396 /* flush the target */
2397 lpfc_sli_abort_iocb(vport, &phba->sli.sli3_ring[LPFC_FCP_RING],
2398 ndlp->nlp_sid, 0, LPFC_CTX_TGT);
2399
2400 /* Treat like rcv logo */
2401 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_PRLO);
2402 return ndlp->nlp_state;
2403 }
2404
2405 static uint32_t
2406 lpfc_device_recov_mapped_node(struct lpfc_vport *vport,
2407 struct lpfc_nodelist *ndlp,
2408 void *arg,
2409 uint32_t evt)
2410 {
2411 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2412
2413 ndlp->nlp_prev_state = NLP_STE_MAPPED_NODE;
2414 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2415 spin_lock_irq(shost->host_lock);
2416 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
2417 spin_unlock_irq(shost->host_lock);
2418 lpfc_disc_set_adisc(vport, ndlp);
2419 return ndlp->nlp_state;
2420 }
2421
2422 static uint32_t
2423 lpfc_rcv_plogi_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2424 void *arg, uint32_t evt)
2425 {
2426 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2427 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2428
2429 /* Ignore PLOGI if we have an outstanding LOGO */
2430 if (ndlp->nlp_flag & (NLP_LOGO_SND | NLP_LOGO_ACC))
2431 return ndlp->nlp_state;
2432 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb)) {
2433 lpfc_cancel_retry_delay_tmo(vport, ndlp);
2434 spin_lock_irq(shost->host_lock);
2435 ndlp->nlp_flag &= ~(NLP_NPR_ADISC | NLP_NPR_2B_DISC);
2436 spin_unlock_irq(shost->host_lock);
2437 } else if (!(ndlp->nlp_flag & NLP_NPR_2B_DISC)) {
2438 /* send PLOGI immediately, move to PLOGI issue state */
2439 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
2440 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
2441 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
2442 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
2443 }
2444 }
2445 return ndlp->nlp_state;
2446 }
2447
2448 static uint32_t
2449 lpfc_rcv_prli_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2450 void *arg, uint32_t evt)
2451 {
2452 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2453 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2454 struct ls_rjt stat;
2455
2456 memset(&stat, 0, sizeof (struct ls_rjt));
2457 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
2458 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
2459 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
2460
2461 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
2462 if (ndlp->nlp_flag & NLP_NPR_ADISC) {
2463 spin_lock_irq(shost->host_lock);
2464 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
2465 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
2466 spin_unlock_irq(shost->host_lock);
2467 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
2468 lpfc_issue_els_adisc(vport, ndlp, 0);
2469 } else {
2470 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
2471 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
2472 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
2473 }
2474 }
2475 return ndlp->nlp_state;
2476 }
2477
2478 static uint32_t
2479 lpfc_rcv_logo_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2480 void *arg, uint32_t evt)
2481 {
2482 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2483
2484 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
2485 return ndlp->nlp_state;
2486 }
2487
2488 static uint32_t
2489 lpfc_rcv_padisc_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2490 void *arg, uint32_t evt)
2491 {
2492 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2493
2494 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
2495 /*
2496 * Do not start discovery if discovery is about to start
2497 * or discovery in progress for this node. Starting discovery
2498 * here will affect the counting of discovery threads.
2499 */
2500 if (!(ndlp->nlp_flag & NLP_DELAY_TMO) &&
2501 !(ndlp->nlp_flag & NLP_NPR_2B_DISC)) {
2502 if (ndlp->nlp_flag & NLP_NPR_ADISC) {
2503 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
2504 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
2505 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
2506 lpfc_issue_els_adisc(vport, ndlp, 0);
2507 } else {
2508 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
2509 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
2510 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
2511 }
2512 }
2513 return ndlp->nlp_state;
2514 }
2515
2516 static uint32_t
2517 lpfc_rcv_prlo_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2518 void *arg, uint32_t evt)
2519 {
2520 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2521 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
2522
2523 spin_lock_irq(shost->host_lock);
2524 ndlp->nlp_flag |= NLP_LOGO_ACC;
2525 spin_unlock_irq(shost->host_lock);
2526
2527 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
2528
2529 if ((ndlp->nlp_flag & NLP_DELAY_TMO) == 0) {
2530 mod_timer(&ndlp->nlp_delayfunc,
2531 jiffies + msecs_to_jiffies(1000 * 1));
2532 spin_lock_irq(shost->host_lock);
2533 ndlp->nlp_flag |= NLP_DELAY_TMO;
2534 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
2535 spin_unlock_irq(shost->host_lock);
2536 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
2537 } else {
2538 spin_lock_irq(shost->host_lock);
2539 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
2540 spin_unlock_irq(shost->host_lock);
2541 }
2542 return ndlp->nlp_state;
2543 }
2544
2545 static uint32_t
2546 lpfc_cmpl_plogi_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2547 void *arg, uint32_t evt)
2548 {
2549 struct lpfc_iocbq *cmdiocb, *rspiocb;
2550 IOCB_t *irsp;
2551 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2552
2553 cmdiocb = (struct lpfc_iocbq *) arg;
2554 rspiocb = cmdiocb->context_un.rsp_iocb;
2555
2556 irsp = &rspiocb->iocb;
2557 if (irsp->ulpStatus) {
2558 spin_lock_irq(shost->host_lock);
2559 ndlp->nlp_flag |= NLP_DEFER_RM;
2560 spin_unlock_irq(shost->host_lock);
2561 return NLP_STE_FREED_NODE;
2562 }
2563 return ndlp->nlp_state;
2564 }
2565
2566 static uint32_t
2567 lpfc_cmpl_prli_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2568 void *arg, uint32_t evt)
2569 {
2570 struct lpfc_iocbq *cmdiocb, *rspiocb;
2571 IOCB_t *irsp;
2572
2573 cmdiocb = (struct lpfc_iocbq *) arg;
2574 rspiocb = cmdiocb->context_un.rsp_iocb;
2575
2576 irsp = &rspiocb->iocb;
2577 if (irsp->ulpStatus && (ndlp->nlp_flag & NLP_NODEV_REMOVE)) {
2578 lpfc_drop_node(vport, ndlp);
2579 return NLP_STE_FREED_NODE;
2580 }
2581 return ndlp->nlp_state;
2582 }
2583
2584 static uint32_t
2585 lpfc_cmpl_logo_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2586 void *arg, uint32_t evt)
2587 {
2588 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2589
2590 /* For the fabric port just clear the fc flags. */
2591 if (ndlp->nlp_DID == Fabric_DID) {
2592 spin_lock_irq(shost->host_lock);
2593 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
2594 spin_unlock_irq(shost->host_lock);
2595 }
2596 lpfc_unreg_rpi(vport, ndlp);
2597 return ndlp->nlp_state;
2598 }
2599
2600 static uint32_t
2601 lpfc_cmpl_adisc_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2602 void *arg, uint32_t evt)
2603 {
2604 struct lpfc_iocbq *cmdiocb, *rspiocb;
2605 IOCB_t *irsp;
2606
2607 cmdiocb = (struct lpfc_iocbq *) arg;
2608 rspiocb = cmdiocb->context_un.rsp_iocb;
2609
2610 irsp = &rspiocb->iocb;
2611 if (irsp->ulpStatus && (ndlp->nlp_flag & NLP_NODEV_REMOVE)) {
2612 lpfc_drop_node(vport, ndlp);
2613 return NLP_STE_FREED_NODE;
2614 }
2615 return ndlp->nlp_state;
2616 }
2617
2618 static uint32_t
2619 lpfc_cmpl_reglogin_npr_node(struct lpfc_vport *vport,
2620 struct lpfc_nodelist *ndlp,
2621 void *arg, uint32_t evt)
2622 {
2623 LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
2624 MAILBOX_t *mb = &pmb->u.mb;
2625
2626 if (!mb->mbxStatus) {
2627 /* SLI4 ports have preallocated logical rpis. */
2628 if (vport->phba->sli_rev < LPFC_SLI_REV4)
2629 ndlp->nlp_rpi = mb->un.varWords[0];
2630 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
2631 if (ndlp->nlp_flag & NLP_LOGO_ACC) {
2632 lpfc_unreg_rpi(vport, ndlp);
2633 }
2634 } else {
2635 if (ndlp->nlp_flag & NLP_NODEV_REMOVE) {
2636 lpfc_drop_node(vport, ndlp);
2637 return NLP_STE_FREED_NODE;
2638 }
2639 }
2640 return ndlp->nlp_state;
2641 }
2642
2643 static uint32_t
2644 lpfc_device_rm_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2645 void *arg, uint32_t evt)
2646 {
2647 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2648
2649 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
2650 spin_lock_irq(shost->host_lock);
2651 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
2652 spin_unlock_irq(shost->host_lock);
2653 return ndlp->nlp_state;
2654 }
2655 lpfc_drop_node(vport, ndlp);
2656 return NLP_STE_FREED_NODE;
2657 }
2658
2659 static uint32_t
2660 lpfc_device_recov_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2661 void *arg, uint32_t evt)
2662 {
2663 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2664
2665 /* Don't do anything that will mess up processing of the
2666 * previous RSCN.
2667 */
2668 if (vport->fc_flag & FC_RSCN_DEFERRED)
2669 return ndlp->nlp_state;
2670
2671 lpfc_cancel_retry_delay_tmo(vport, ndlp);
2672 spin_lock_irq(shost->host_lock);
2673 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
2674 spin_unlock_irq(shost->host_lock);
2675 return ndlp->nlp_state;
2676 }
2677
2678
2679 /* This next section defines the NPort Discovery State Machine */
2680
2681 /* There are 4 different double linked lists nodelist entries can reside on.
2682 * The plogi list and adisc list are used when Link Up discovery or RSCN
2683 * processing is needed. Each list holds the nodes that we will send PLOGI
2684 * or ADISC on. These lists will keep track of what nodes will be effected
2685 * by an RSCN, or a Link Up (Typically, all nodes are effected on Link Up).
2686 * The unmapped_list will contain all nodes that we have successfully logged
2687 * into at the Fibre Channel level. The mapped_list will contain all nodes
2688 * that are mapped FCP targets.
2689 */
2690 /*
2691 * The bind list is a list of undiscovered (potentially non-existent) nodes
2692 * that we have saved binding information on. This information is used when
2693 * nodes transition from the unmapped to the mapped list.
2694 */
2695 /* For UNUSED_NODE state, the node has just been allocated .
2696 * For PLOGI_ISSUE and REG_LOGIN_ISSUE, the node is on
2697 * the PLOGI list. For REG_LOGIN_COMPL, the node is taken off the PLOGI list
2698 * and put on the unmapped list. For ADISC processing, the node is taken off
2699 * the ADISC list and placed on either the mapped or unmapped list (depending
2700 * on its previous state). Once on the unmapped list, a PRLI is issued and the
2701 * state changed to PRLI_ISSUE. When the PRLI completion occurs, the state is
2702 * changed to UNMAPPED_NODE. If the completion indicates a mapped
2703 * node, the node is taken off the unmapped list. The binding list is checked
2704 * for a valid binding, or a binding is automatically assigned. If binding
2705 * assignment is unsuccessful, the node is left on the unmapped list. If
2706 * binding assignment is successful, the associated binding list entry (if
2707 * any) is removed, and the node is placed on the mapped list.
2708 */
2709 /*
2710 * For a Link Down, all nodes on the ADISC, PLOGI, unmapped or mapped
2711 * lists will receive a DEVICE_RECOVERY event. If the linkdown or devloss timers
2712 * expire, all effected nodes will receive a DEVICE_RM event.
2713 */
2714 /*
2715 * For a Link Up or RSCN, all nodes will move from the mapped / unmapped lists
2716 * to either the ADISC or PLOGI list. After a Nameserver query or ALPA loopmap
2717 * check, additional nodes may be added or removed (via DEVICE_RM) to / from
2718 * the PLOGI or ADISC lists. Once the PLOGI and ADISC lists are populated,
2719 * we will first process the ADISC list. 32 entries are processed initially and
2720 * ADISC is initited for each one. Completions / Events for each node are
2721 * funnelled thru the state machine. As each node finishes ADISC processing, it
2722 * starts ADISC for any nodes waiting for ADISC processing. If no nodes are
2723 * waiting, and the ADISC list count is identically 0, then we are done. For
2724 * Link Up discovery, since all nodes on the PLOGI list are UNREG_LOGIN'ed, we
2725 * can issue a CLEAR_LA and reenable Link Events. Next we will process the PLOGI
2726 * list. 32 entries are processed initially and PLOGI is initited for each one.
2727 * Completions / Events for each node are funnelled thru the state machine. As
2728 * each node finishes PLOGI processing, it starts PLOGI for any nodes waiting
2729 * for PLOGI processing. If no nodes are waiting, and the PLOGI list count is
2730 * indentically 0, then we are done. We have now completed discovery / RSCN
2731 * handling. Upon completion, ALL nodes should be on either the mapped or
2732 * unmapped lists.
2733 */
2734
2735 static uint32_t (*lpfc_disc_action[NLP_STE_MAX_STATE * NLP_EVT_MAX_EVENT])
2736 (struct lpfc_vport *, struct lpfc_nodelist *, void *, uint32_t) = {
2737 /* Action routine Event Current State */
2738 lpfc_rcv_plogi_unused_node, /* RCV_PLOGI UNUSED_NODE */
2739 lpfc_rcv_els_unused_node, /* RCV_PRLI */
2740 lpfc_rcv_logo_unused_node, /* RCV_LOGO */
2741 lpfc_rcv_els_unused_node, /* RCV_ADISC */
2742 lpfc_rcv_els_unused_node, /* RCV_PDISC */
2743 lpfc_rcv_els_unused_node, /* RCV_PRLO */
2744 lpfc_disc_illegal, /* CMPL_PLOGI */
2745 lpfc_disc_illegal, /* CMPL_PRLI */
2746 lpfc_cmpl_logo_unused_node, /* CMPL_LOGO */
2747 lpfc_disc_illegal, /* CMPL_ADISC */
2748 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2749 lpfc_device_rm_unused_node, /* DEVICE_RM */
2750 lpfc_device_recov_unused_node, /* DEVICE_RECOVERY */
2751
2752 lpfc_rcv_plogi_plogi_issue, /* RCV_PLOGI PLOGI_ISSUE */
2753 lpfc_rcv_prli_plogi_issue, /* RCV_PRLI */
2754 lpfc_rcv_logo_plogi_issue, /* RCV_LOGO */
2755 lpfc_rcv_els_plogi_issue, /* RCV_ADISC */
2756 lpfc_rcv_els_plogi_issue, /* RCV_PDISC */
2757 lpfc_rcv_els_plogi_issue, /* RCV_PRLO */
2758 lpfc_cmpl_plogi_plogi_issue, /* CMPL_PLOGI */
2759 lpfc_disc_illegal, /* CMPL_PRLI */
2760 lpfc_cmpl_logo_plogi_issue, /* CMPL_LOGO */
2761 lpfc_disc_illegal, /* CMPL_ADISC */
2762 lpfc_cmpl_reglogin_plogi_issue,/* CMPL_REG_LOGIN */
2763 lpfc_device_rm_plogi_issue, /* DEVICE_RM */
2764 lpfc_device_recov_plogi_issue, /* DEVICE_RECOVERY */
2765
2766 lpfc_rcv_plogi_adisc_issue, /* RCV_PLOGI ADISC_ISSUE */
2767 lpfc_rcv_prli_adisc_issue, /* RCV_PRLI */
2768 lpfc_rcv_logo_adisc_issue, /* RCV_LOGO */
2769 lpfc_rcv_padisc_adisc_issue, /* RCV_ADISC */
2770 lpfc_rcv_padisc_adisc_issue, /* RCV_PDISC */
2771 lpfc_rcv_prlo_adisc_issue, /* RCV_PRLO */
2772 lpfc_disc_illegal, /* CMPL_PLOGI */
2773 lpfc_disc_illegal, /* CMPL_PRLI */
2774 lpfc_disc_illegal, /* CMPL_LOGO */
2775 lpfc_cmpl_adisc_adisc_issue, /* CMPL_ADISC */
2776 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2777 lpfc_device_rm_adisc_issue, /* DEVICE_RM */
2778 lpfc_device_recov_adisc_issue, /* DEVICE_RECOVERY */
2779
2780 lpfc_rcv_plogi_reglogin_issue, /* RCV_PLOGI REG_LOGIN_ISSUE */
2781 lpfc_rcv_prli_reglogin_issue, /* RCV_PLOGI */
2782 lpfc_rcv_logo_reglogin_issue, /* RCV_LOGO */
2783 lpfc_rcv_padisc_reglogin_issue, /* RCV_ADISC */
2784 lpfc_rcv_padisc_reglogin_issue, /* RCV_PDISC */
2785 lpfc_rcv_prlo_reglogin_issue, /* RCV_PRLO */
2786 lpfc_cmpl_plogi_illegal, /* CMPL_PLOGI */
2787 lpfc_disc_illegal, /* CMPL_PRLI */
2788 lpfc_disc_illegal, /* CMPL_LOGO */
2789 lpfc_disc_illegal, /* CMPL_ADISC */
2790 lpfc_cmpl_reglogin_reglogin_issue,/* CMPL_REG_LOGIN */
2791 lpfc_device_rm_reglogin_issue, /* DEVICE_RM */
2792 lpfc_device_recov_reglogin_issue,/* DEVICE_RECOVERY */
2793
2794 lpfc_rcv_plogi_prli_issue, /* RCV_PLOGI PRLI_ISSUE */
2795 lpfc_rcv_prli_prli_issue, /* RCV_PRLI */
2796 lpfc_rcv_logo_prli_issue, /* RCV_LOGO */
2797 lpfc_rcv_padisc_prli_issue, /* RCV_ADISC */
2798 lpfc_rcv_padisc_prli_issue, /* RCV_PDISC */
2799 lpfc_rcv_prlo_prli_issue, /* RCV_PRLO */
2800 lpfc_cmpl_plogi_illegal, /* CMPL_PLOGI */
2801 lpfc_cmpl_prli_prli_issue, /* CMPL_PRLI */
2802 lpfc_disc_illegal, /* CMPL_LOGO */
2803 lpfc_disc_illegal, /* CMPL_ADISC */
2804 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2805 lpfc_device_rm_prli_issue, /* DEVICE_RM */
2806 lpfc_device_recov_prli_issue, /* DEVICE_RECOVERY */
2807
2808 lpfc_rcv_plogi_logo_issue, /* RCV_PLOGI LOGO_ISSUE */
2809 lpfc_rcv_prli_logo_issue, /* RCV_PRLI */
2810 lpfc_rcv_logo_logo_issue, /* RCV_LOGO */
2811 lpfc_rcv_padisc_logo_issue, /* RCV_ADISC */
2812 lpfc_rcv_padisc_logo_issue, /* RCV_PDISC */
2813 lpfc_rcv_prlo_logo_issue, /* RCV_PRLO */
2814 lpfc_cmpl_plogi_illegal, /* CMPL_PLOGI */
2815 lpfc_disc_illegal, /* CMPL_PRLI */
2816 lpfc_cmpl_logo_logo_issue, /* CMPL_LOGO */
2817 lpfc_disc_illegal, /* CMPL_ADISC */
2818 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2819 lpfc_device_rm_logo_issue, /* DEVICE_RM */
2820 lpfc_device_recov_logo_issue, /* DEVICE_RECOVERY */
2821
2822 lpfc_rcv_plogi_unmap_node, /* RCV_PLOGI UNMAPPED_NODE */
2823 lpfc_rcv_prli_unmap_node, /* RCV_PRLI */
2824 lpfc_rcv_logo_unmap_node, /* RCV_LOGO */
2825 lpfc_rcv_padisc_unmap_node, /* RCV_ADISC */
2826 lpfc_rcv_padisc_unmap_node, /* RCV_PDISC */
2827 lpfc_rcv_prlo_unmap_node, /* RCV_PRLO */
2828 lpfc_disc_illegal, /* CMPL_PLOGI */
2829 lpfc_disc_illegal, /* CMPL_PRLI */
2830 lpfc_disc_illegal, /* CMPL_LOGO */
2831 lpfc_disc_illegal, /* CMPL_ADISC */
2832 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2833 lpfc_disc_illegal, /* DEVICE_RM */
2834 lpfc_device_recov_unmap_node, /* DEVICE_RECOVERY */
2835
2836 lpfc_rcv_plogi_mapped_node, /* RCV_PLOGI MAPPED_NODE */
2837 lpfc_rcv_prli_mapped_node, /* RCV_PRLI */
2838 lpfc_rcv_logo_mapped_node, /* RCV_LOGO */
2839 lpfc_rcv_padisc_mapped_node, /* RCV_ADISC */
2840 lpfc_rcv_padisc_mapped_node, /* RCV_PDISC */
2841 lpfc_rcv_prlo_mapped_node, /* RCV_PRLO */
2842 lpfc_disc_illegal, /* CMPL_PLOGI */
2843 lpfc_disc_illegal, /* CMPL_PRLI */
2844 lpfc_disc_illegal, /* CMPL_LOGO */
2845 lpfc_disc_illegal, /* CMPL_ADISC */
2846 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2847 lpfc_disc_illegal, /* DEVICE_RM */
2848 lpfc_device_recov_mapped_node, /* DEVICE_RECOVERY */
2849
2850 lpfc_rcv_plogi_npr_node, /* RCV_PLOGI NPR_NODE */
2851 lpfc_rcv_prli_npr_node, /* RCV_PRLI */
2852 lpfc_rcv_logo_npr_node, /* RCV_LOGO */
2853 lpfc_rcv_padisc_npr_node, /* RCV_ADISC */
2854 lpfc_rcv_padisc_npr_node, /* RCV_PDISC */
2855 lpfc_rcv_prlo_npr_node, /* RCV_PRLO */
2856 lpfc_cmpl_plogi_npr_node, /* CMPL_PLOGI */
2857 lpfc_cmpl_prli_npr_node, /* CMPL_PRLI */
2858 lpfc_cmpl_logo_npr_node, /* CMPL_LOGO */
2859 lpfc_cmpl_adisc_npr_node, /* CMPL_ADISC */
2860 lpfc_cmpl_reglogin_npr_node, /* CMPL_REG_LOGIN */
2861 lpfc_device_rm_npr_node, /* DEVICE_RM */
2862 lpfc_device_recov_npr_node, /* DEVICE_RECOVERY */
2863 };
2864
2865 int
2866 lpfc_disc_state_machine(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2867 void *arg, uint32_t evt)
2868 {
2869 uint32_t cur_state, rc;
2870 uint32_t(*func) (struct lpfc_vport *, struct lpfc_nodelist *, void *,
2871 uint32_t);
2872 uint32_t got_ndlp = 0;
2873
2874 if (lpfc_nlp_get(ndlp))
2875 got_ndlp = 1;
2876
2877 cur_state = ndlp->nlp_state;
2878
2879 /* DSM in event <evt> on NPort <nlp_DID> in state <cur_state> */
2880 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2881 "0211 DSM in event x%x on NPort x%x in "
2882 "state %d Data: x%x x%x\n",
2883 evt, ndlp->nlp_DID, cur_state,
2884 ndlp->nlp_flag, ndlp->nlp_fc4_type);
2885
2886 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_DSM,
2887 "DSM in: evt:%d ste:%d did:x%x",
2888 evt, cur_state, ndlp->nlp_DID);
2889
2890 func = lpfc_disc_action[(cur_state * NLP_EVT_MAX_EVENT) + evt];
2891 rc = (func) (vport, ndlp, arg, evt);
2892
2893 /* DSM out state <rc> on NPort <nlp_DID> */
2894 if (got_ndlp) {
2895 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2896 "0212 DSM out state %d on NPort x%x Data: x%x\n",
2897 rc, ndlp->nlp_DID, ndlp->nlp_flag);
2898
2899 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_DSM,
2900 "DSM out: ste:%d did:x%x flg:x%x",
2901 rc, ndlp->nlp_DID, ndlp->nlp_flag);
2902 /* Decrement the ndlp reference count held for this function */
2903 lpfc_nlp_put(ndlp);
2904 } else {
2905 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2906 "0213 DSM out state %d on NPort free\n", rc);
2907
2908 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_DSM,
2909 "DSM out: ste:%d did:x%x flg:x%x",
2910 rc, 0, 0);
2911 }
2912
2913 return rc;
2914 }