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