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