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