1 /******************************************************************* 2 * This file is part of the Emulex Linux Device Driver for * 3 * Fibre Channel Host Bus Adapters. * 4 * Copyright (C) 2017-2025 Broadcom. All Rights Reserved. The term * 5 * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. * 6 * Copyright (C) 2004-2016 Emulex. All rights reserved. * 7 * EMULEX and SLI are trademarks of Emulex. * 8 * www.broadcom.com * 9 * Portions Copyright (C) 2004-2005 Christoph Hellwig * 10 * * 11 * This program is free software; you can redistribute it and/or * 12 * modify it under the terms of version 2 of the GNU General * 13 * Public License as published by the Free Software Foundation. * 14 * This program is distributed in the hope that it will be useful. * 15 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND * 16 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, * 17 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE * 18 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD * 19 * TO BE LEGALLY INVALID. See the GNU General Public License for * 20 * more details, a copy of which can be found in the file COPYING * 21 * included with this package. * 22 *******************************************************************/ 23 /* See Fibre Channel protocol T11 FC-LS for details */ 24 #include <linux/blkdev.h> 25 #include <linux/pci.h> 26 #include <linux/slab.h> 27 #include <linux/interrupt.h> 28 #include <linux/delay.h> 29 30 #include <scsi/scsi.h> 31 #include <scsi/scsi_device.h> 32 #include <scsi/scsi_host.h> 33 #include <scsi/scsi_transport_fc.h> 34 #include <uapi/scsi/fc/fc_fs.h> 35 #include <uapi/scsi/fc/fc_els.h> 36 37 #include "lpfc_hw4.h" 38 #include "lpfc_hw.h" 39 #include "lpfc_sli.h" 40 #include "lpfc_sli4.h" 41 #include "lpfc_nl.h" 42 #include "lpfc_disc.h" 43 #include "lpfc_scsi.h" 44 #include "lpfc.h" 45 #include "lpfc_logmsg.h" 46 #include "lpfc_crtn.h" 47 #include "lpfc_vport.h" 48 #include "lpfc_debugfs.h" 49 50 static int lpfc_els_retry(struct lpfc_hba *, struct lpfc_iocbq *, 51 struct lpfc_iocbq *); 52 static void lpfc_cmpl_fabric_iocb(struct lpfc_hba *, struct lpfc_iocbq *, 53 struct lpfc_iocbq *); 54 static void lpfc_fabric_abort_vport(struct lpfc_vport *vport); 55 static int lpfc_issue_els_fdisc(struct lpfc_vport *vport, 56 struct lpfc_nodelist *ndlp, uint8_t retry); 57 static int lpfc_issue_fabric_iocb(struct lpfc_hba *phba, 58 struct lpfc_iocbq *iocb); 59 static void lpfc_cmpl_els_edc(struct lpfc_hba *phba, 60 struct lpfc_iocbq *cmdiocb, 61 struct lpfc_iocbq *rspiocb); 62 static void lpfc_cmpl_els_uvem(struct lpfc_hba *, struct lpfc_iocbq *, 63 struct lpfc_iocbq *); 64 65 static int lpfc_max_els_tries = 3; 66 67 static void lpfc_init_cs_ctl_bitmap(struct lpfc_vport *vport); 68 static void lpfc_vmid_set_cs_ctl_range(struct lpfc_vport *vport, u32 min, u32 max); 69 static void lpfc_vmid_put_cs_ctl(struct lpfc_vport *vport, u32 ctcl_vmid); 70 71 /** 72 * lpfc_els_chk_latt - Check host link attention event for a vport 73 * @vport: pointer to a host virtual N_Port data structure. 74 * 75 * This routine checks whether there is an outstanding host link 76 * attention event during the discovery process with the @vport. It is done 77 * by reading the HBA's Host Attention (HA) register. If there is any host 78 * link attention events during this @vport's discovery process, the @vport 79 * shall be marked as FC_ABORT_DISCOVERY, a host link attention clear shall 80 * be issued if the link state is not already in host link cleared state, 81 * and a return code shall indicate whether the host link attention event 82 * had happened. 83 * 84 * Note that, if either the host link is in state LPFC_LINK_DOWN or @vport 85 * state in LPFC_VPORT_READY, the request for checking host link attention 86 * event will be ignored and a return code shall indicate no host link 87 * attention event had happened. 88 * 89 * Return codes 90 * 0 - no host link attention event happened 91 * 1 - host link attention event happened 92 **/ 93 int 94 lpfc_els_chk_latt(struct lpfc_vport *vport) 95 { 96 struct lpfc_hba *phba = vport->phba; 97 uint32_t ha_copy; 98 99 if (vport->port_state >= LPFC_VPORT_READY || 100 phba->link_state == LPFC_LINK_DOWN || 101 phba->sli_rev > LPFC_SLI_REV3) 102 return 0; 103 104 /* Read the HBA Host Attention Register */ 105 if (lpfc_readl(phba->HAregaddr, &ha_copy)) 106 return 1; 107 108 if (!(ha_copy & HA_LATT)) 109 return 0; 110 111 /* Pending Link Event during Discovery */ 112 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, 113 "0237 Pending Link Event during " 114 "Discovery: State x%x\n", 115 phba->pport->port_state); 116 117 /* CLEAR_LA should re-enable link attention events and 118 * we should then immediately take a LATT event. The 119 * LATT processing should call lpfc_linkdown() which 120 * will cleanup any left over in-progress discovery 121 * events. 122 */ 123 set_bit(FC_ABORT_DISCOVERY, &vport->fc_flag); 124 125 if (phba->link_state != LPFC_CLEAR_LA) 126 lpfc_issue_clear_la(phba, vport); 127 128 return 1; 129 } 130 131 static bool lpfc_is_els_acc_rsp(struct lpfc_dmabuf *buf) 132 { 133 struct fc_els_ls_acc *rsp = buf->virt; 134 135 if (rsp && rsp->la_cmd == ELS_LS_ACC) 136 return true; 137 return false; 138 } 139 140 /** 141 * lpfc_prep_els_iocb - Allocate and prepare a lpfc iocb data structure 142 * @vport: pointer to a host virtual N_Port data structure. 143 * @expect_rsp: flag indicating whether response is expected. 144 * @cmd_size: size of the ELS command. 145 * @retry: number of retries to the command when it fails. 146 * @ndlp: pointer to a node-list data structure. 147 * @did: destination identifier. 148 * @elscmd: the ELS command code. 149 * 150 * This routine is used for allocating a lpfc-IOCB data structure from 151 * the driver lpfc-IOCB free-list and prepare the IOCB with the parameters 152 * passed into the routine for discovery state machine to issue an Extended 153 * Link Service (ELS) commands. It is a generic lpfc-IOCB allocation 154 * and preparation routine that is used by all the discovery state machine 155 * routines and the ELS command-specific fields will be later set up by 156 * the individual discovery machine routines after calling this routine 157 * allocating and preparing a generic IOCB data structure. It fills in the 158 * Buffer Descriptor Entries (BDEs), allocates buffers for both command 159 * payload and response payload (if expected). The reference count on the 160 * ndlp is incremented by 1 and the reference to the ndlp is put into 161 * ndlp of the IOCB data structure for this IOCB to hold the ndlp 162 * reference for the command's callback function to access later. 163 * 164 * Return code 165 * Pointer to the newly allocated/prepared els iocb data structure 166 * NULL - when els iocb data structure allocation/preparation failed 167 **/ 168 struct lpfc_iocbq * 169 lpfc_prep_els_iocb(struct lpfc_vport *vport, u8 expect_rsp, 170 u16 cmd_size, u8 retry, 171 struct lpfc_nodelist *ndlp, u32 did, 172 u32 elscmd) 173 { 174 struct lpfc_hba *phba = vport->phba; 175 struct lpfc_iocbq *elsiocb; 176 struct lpfc_dmabuf *pcmd, *prsp, *pbuflist, *bmp; 177 struct ulp_bde64_le *bpl; 178 u32 timeout = 0; 179 180 if (!lpfc_is_link_up(phba)) 181 return NULL; 182 183 /* Allocate buffer for command iocb */ 184 elsiocb = lpfc_sli_get_iocbq(phba); 185 if (!elsiocb) 186 return NULL; 187 188 /* 189 * If this command is for fabric controller and HBA running 190 * in FIP mode send FLOGI, FDISC and LOGO as FIP frames. 191 */ 192 if (did == Fabric_DID && 193 test_bit(HBA_FIP_SUPPORT, &phba->hba_flag) && 194 (elscmd == ELS_CMD_FLOGI || 195 elscmd == ELS_CMD_FDISC || 196 elscmd == ELS_CMD_LOGO)) 197 switch (elscmd) { 198 case ELS_CMD_FLOGI: 199 elsiocb->cmd_flag |= 200 ((LPFC_ELS_ID_FLOGI << LPFC_FIP_ELS_ID_SHIFT) 201 & LPFC_FIP_ELS_ID_MASK); 202 break; 203 case ELS_CMD_FDISC: 204 elsiocb->cmd_flag |= 205 ((LPFC_ELS_ID_FDISC << LPFC_FIP_ELS_ID_SHIFT) 206 & LPFC_FIP_ELS_ID_MASK); 207 break; 208 case ELS_CMD_LOGO: 209 elsiocb->cmd_flag |= 210 ((LPFC_ELS_ID_LOGO << LPFC_FIP_ELS_ID_SHIFT) 211 & LPFC_FIP_ELS_ID_MASK); 212 break; 213 } 214 else 215 elsiocb->cmd_flag &= ~LPFC_FIP_ELS_ID_MASK; 216 217 /* fill in BDEs for command */ 218 /* Allocate buffer for command payload */ 219 pcmd = kmalloc(sizeof(*pcmd), GFP_KERNEL); 220 if (pcmd) 221 pcmd->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &pcmd->phys); 222 if (!pcmd || !pcmd->virt) 223 goto els_iocb_free_pcmb_exit; 224 225 INIT_LIST_HEAD(&pcmd->list); 226 227 /* Allocate buffer for response payload */ 228 if (expect_rsp) { 229 prsp = kmalloc(sizeof(*prsp), GFP_KERNEL); 230 if (prsp) 231 prsp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, 232 &prsp->phys); 233 if (!prsp || !prsp->virt) 234 goto els_iocb_free_prsp_exit; 235 INIT_LIST_HEAD(&prsp->list); 236 } else { 237 prsp = NULL; 238 } 239 240 /* Allocate buffer for Buffer ptr list */ 241 pbuflist = kmalloc(sizeof(*pbuflist), GFP_KERNEL); 242 if (pbuflist) 243 pbuflist->virt = lpfc_mbuf_alloc(phba, MEM_PRI, 244 &pbuflist->phys); 245 if (!pbuflist || !pbuflist->virt) 246 goto els_iocb_free_pbuf_exit; 247 248 INIT_LIST_HEAD(&pbuflist->list); 249 250 if (expect_rsp) { 251 switch (elscmd) { 252 case ELS_CMD_FLOGI: 253 timeout = FF_DEF_RATOV * 2; 254 break; 255 case ELS_CMD_LOGO: 256 timeout = phba->fc_ratov; 257 break; 258 default: 259 timeout = phba->fc_ratov * 2; 260 } 261 262 /* Fill SGE for the num bde count */ 263 elsiocb->num_bdes = 2; 264 } 265 266 if (phba->sli_rev == LPFC_SLI_REV4) 267 bmp = pcmd; 268 else 269 bmp = pbuflist; 270 271 lpfc_sli_prep_els_req_rsp(phba, elsiocb, vport, bmp, cmd_size, did, 272 elscmd, timeout, expect_rsp); 273 274 bpl = (struct ulp_bde64_le *)pbuflist->virt; 275 bpl->addr_low = cpu_to_le32(putPaddrLow(pcmd->phys)); 276 bpl->addr_high = cpu_to_le32(putPaddrHigh(pcmd->phys)); 277 bpl->type_size = cpu_to_le32(cmd_size); 278 bpl->type_size |= cpu_to_le32(ULP_BDE64_TYPE_BDE_64); 279 280 if (expect_rsp) { 281 bpl++; 282 bpl->addr_low = cpu_to_le32(putPaddrLow(prsp->phys)); 283 bpl->addr_high = cpu_to_le32(putPaddrHigh(prsp->phys)); 284 bpl->type_size = cpu_to_le32(FCELSSIZE); 285 bpl->type_size |= cpu_to_le32(ULP_BDE64_TYPE_BDE_64); 286 } 287 288 elsiocb->cmd_dmabuf = pcmd; 289 elsiocb->bpl_dmabuf = pbuflist; 290 elsiocb->retry = retry; 291 elsiocb->vport = vport; 292 elsiocb->drvrTimeout = (phba->fc_ratov << 1) + LPFC_DRVR_TIMEOUT; 293 294 if (prsp) 295 list_add(&prsp->list, &pcmd->list); 296 if (expect_rsp) { 297 /* Xmit ELS command <elsCmd> to remote NPORT <did> */ 298 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, 299 "0116 Xmit ELS command x%x to remote " 300 "NPORT x%x I/O tag: x%x, port state:x%x " 301 "rpi x%x fc_flag:x%lx\n", 302 elscmd, did, elsiocb->iotag, 303 vport->port_state, ndlp->nlp_rpi, 304 vport->fc_flag); 305 } else { 306 /* Xmit ELS response <elsCmd> to remote NPORT <did> */ 307 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, 308 "0117 Xmit ELS response x%x to remote " 309 "NPORT x%x I/O tag: x%x, size: x%x " 310 "port_state x%x rpi x%x fc_flag x%lx\n", 311 elscmd, ndlp->nlp_DID, elsiocb->iotag, 312 cmd_size, vport->port_state, 313 ndlp->nlp_rpi, vport->fc_flag); 314 } 315 316 return elsiocb; 317 318 els_iocb_free_pbuf_exit: 319 if (expect_rsp) 320 lpfc_mbuf_free(phba, prsp->virt, prsp->phys); 321 kfree(pbuflist); 322 323 els_iocb_free_prsp_exit: 324 lpfc_mbuf_free(phba, pcmd->virt, pcmd->phys); 325 kfree(prsp); 326 327 els_iocb_free_pcmb_exit: 328 kfree(pcmd); 329 lpfc_sli_release_iocbq(phba, elsiocb); 330 return NULL; 331 } 332 333 /** 334 * lpfc_issue_fabric_reglogin - Issue fabric registration login for a vport 335 * @vport: pointer to a host virtual N_Port data structure. 336 * 337 * This routine issues a fabric registration login for a @vport. An 338 * active ndlp node with Fabric_DID must already exist for this @vport. 339 * The routine invokes two mailbox commands to carry out fabric registration 340 * login through the HBA firmware: the first mailbox command requests the 341 * HBA to perform link configuration for the @vport; and the second mailbox 342 * command requests the HBA to perform the actual fabric registration login 343 * with the @vport. 344 * 345 * Return code 346 * 0 - successfully issued fabric registration login for @vport 347 * -ENXIO -- failed to issue fabric registration login for @vport 348 **/ 349 int 350 lpfc_issue_fabric_reglogin(struct lpfc_vport *vport) 351 { 352 struct lpfc_hba *phba = vport->phba; 353 LPFC_MBOXQ_t *mbox; 354 struct lpfc_nodelist *ndlp; 355 struct serv_parm *sp; 356 int rc; 357 int err = 0; 358 359 sp = &phba->fc_fabparam; 360 ndlp = lpfc_findnode_did(vport, Fabric_DID); 361 if (!ndlp) { 362 err = 1; 363 goto fail; 364 } 365 366 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); 367 if (!mbox) { 368 err = 2; 369 goto fail; 370 } 371 372 vport->port_state = LPFC_FABRIC_CFG_LINK; 373 lpfc_config_link(phba, mbox); 374 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; 375 mbox->vport = vport; 376 377 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); 378 if (rc == MBX_NOT_FINISHED) { 379 err = 3; 380 goto fail_free_mbox; 381 } 382 383 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); 384 if (!mbox) { 385 err = 4; 386 goto fail; 387 } 388 rc = lpfc_reg_rpi(phba, vport->vpi, Fabric_DID, (uint8_t *)sp, mbox, 389 ndlp->nlp_rpi); 390 if (rc) { 391 err = 5; 392 goto fail_free_mbox; 393 } 394 395 mbox->mbox_cmpl = lpfc_mbx_cmpl_fabric_reg_login; 396 mbox->vport = vport; 397 /* increment the reference count on ndlp to hold reference 398 * for the callback routine. 399 */ 400 mbox->ctx_ndlp = lpfc_nlp_get(ndlp); 401 if (!mbox->ctx_ndlp) { 402 err = 6; 403 goto fail_free_mbox; 404 } 405 406 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); 407 if (rc == MBX_NOT_FINISHED) { 408 err = 7; 409 goto fail_issue_reg_login; 410 } 411 412 return 0; 413 414 fail_issue_reg_login: 415 /* decrement the reference count on ndlp just incremented 416 * for the failed mbox command. 417 */ 418 lpfc_nlp_put(ndlp); 419 fail_free_mbox: 420 lpfc_mbox_rsrc_cleanup(phba, mbox, MBOX_THD_UNLOCKED); 421 fail: 422 lpfc_vport_set_state(vport, FC_VPORT_FAILED); 423 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, 424 "0249 Cannot issue Register Fabric login: Err %d\n", 425 err); 426 return -ENXIO; 427 } 428 429 /** 430 * lpfc_issue_reg_vfi - Register VFI for this vport's fabric login 431 * @vport: pointer to a host virtual N_Port data structure. 432 * 433 * This routine issues a REG_VFI mailbox for the vfi, vpi, fcfi triplet for 434 * the @vport. This mailbox command is necessary for SLI4 port only. 435 * 436 * Return code 437 * 0 - successfully issued REG_VFI for @vport 438 * A failure code otherwise. 439 **/ 440 int 441 lpfc_issue_reg_vfi(struct lpfc_vport *vport) 442 { 443 struct lpfc_hba *phba = vport->phba; 444 LPFC_MBOXQ_t *mboxq = NULL; 445 struct lpfc_nodelist *ndlp; 446 struct lpfc_dmabuf *dmabuf = NULL; 447 int rc = 0; 448 449 /* move forward in case of SLI4 FC port loopback test and pt2pt mode */ 450 if ((phba->sli_rev == LPFC_SLI_REV4) && 451 !(phba->link_flag & LS_LOOPBACK_MODE) && 452 !test_bit(FC_PT2PT, &vport->fc_flag)) { 453 ndlp = lpfc_findnode_did(vport, Fabric_DID); 454 if (!ndlp) { 455 rc = -ENODEV; 456 goto fail; 457 } 458 } 459 460 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); 461 if (!mboxq) { 462 rc = -ENOMEM; 463 goto fail; 464 } 465 466 /* Supply CSP's only if we are fabric connect or pt-to-pt connect */ 467 if (test_bit(FC_FABRIC, &vport->fc_flag) || 468 test_bit(FC_PT2PT, &vport->fc_flag)) { 469 rc = lpfc_mbox_rsrc_prep(phba, mboxq); 470 if (rc) { 471 rc = -ENOMEM; 472 goto fail_mbox; 473 } 474 dmabuf = mboxq->ctx_buf; 475 memcpy(dmabuf->virt, &phba->fc_fabparam, 476 sizeof(struct serv_parm)); 477 } 478 479 vport->port_state = LPFC_FABRIC_CFG_LINK; 480 if (dmabuf) { 481 lpfc_reg_vfi(mboxq, vport, dmabuf->phys); 482 /* lpfc_reg_vfi memsets the mailbox. Restore the ctx_buf. */ 483 mboxq->ctx_buf = dmabuf; 484 } else { 485 lpfc_reg_vfi(mboxq, vport, 0); 486 } 487 488 mboxq->mbox_cmpl = lpfc_mbx_cmpl_reg_vfi; 489 mboxq->vport = vport; 490 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); 491 if (rc == MBX_NOT_FINISHED) { 492 rc = -ENXIO; 493 goto fail_mbox; 494 } 495 return 0; 496 497 fail_mbox: 498 lpfc_mbox_rsrc_cleanup(phba, mboxq, MBOX_THD_UNLOCKED); 499 fail: 500 lpfc_vport_set_state(vport, FC_VPORT_FAILED); 501 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, 502 "0289 Issue Register VFI failed: Err %d\n", rc); 503 return rc; 504 } 505 506 /** 507 * lpfc_issue_unreg_vfi - Unregister VFI for this vport's fabric login 508 * @vport: pointer to a host virtual N_Port data structure. 509 * 510 * This routine issues a UNREG_VFI mailbox with the vfi, vpi, fcfi triplet for 511 * the @vport. This mailbox command is necessary for SLI4 port only. 512 * 513 * Return code 514 * 0 - successfully issued REG_VFI for @vport 515 * A failure code otherwise. 516 **/ 517 int 518 lpfc_issue_unreg_vfi(struct lpfc_vport *vport) 519 { 520 struct lpfc_hba *phba = vport->phba; 521 LPFC_MBOXQ_t *mboxq; 522 int rc; 523 524 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); 525 if (!mboxq) { 526 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, 527 "2556 UNREG_VFI mbox allocation failed" 528 "HBA state x%x\n", phba->pport->port_state); 529 return -ENOMEM; 530 } 531 532 lpfc_unreg_vfi(mboxq, vport); 533 mboxq->vport = vport; 534 mboxq->mbox_cmpl = lpfc_unregister_vfi_cmpl; 535 536 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); 537 if (rc == MBX_NOT_FINISHED) { 538 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, 539 "2557 UNREG_VFI issue mbox failed rc x%x " 540 "HBA state x%x\n", 541 rc, phba->pport->port_state); 542 mempool_free(mboxq, phba->mbox_mem_pool); 543 return -EIO; 544 } 545 546 clear_bit(FC_VFI_REGISTERED, &vport->fc_flag); 547 return 0; 548 } 549 550 /** 551 * lpfc_check_clean_addr_bit - Check whether assigned FCID is clean. 552 * @vport: pointer to a host virtual N_Port data structure. 553 * @sp: pointer to service parameter data structure. 554 * 555 * This routine is called from FLOGI/FDISC completion handler functions. 556 * lpfc_check_clean_addr_bit return 1 when FCID/Fabric portname/ Fabric 557 * node nodename is changed in the completion service parameter else return 558 * 0. This function also set flag in the vport data structure to delay 559 * NP_Port discovery after the FLOGI/FDISC completion if Clean address bit 560 * in FLOGI/FDISC response is cleared and FCID/Fabric portname/ Fabric 561 * node nodename is changed in the completion service parameter. 562 * 563 * Return code 564 * 0 - FCID and Fabric Nodename and Fabric portname is not changed. 565 * 1 - FCID or Fabric Nodename or Fabric portname is changed. 566 * 567 **/ 568 static uint8_t 569 lpfc_check_clean_addr_bit(struct lpfc_vport *vport, 570 struct serv_parm *sp) 571 { 572 struct lpfc_hba *phba = vport->phba; 573 uint8_t fabric_param_changed = 0; 574 575 if ((vport->fc_prevDID != vport->fc_myDID) || 576 memcmp(&vport->fabric_portname, &sp->portName, 577 sizeof(struct lpfc_name)) || 578 memcmp(&vport->fabric_nodename, &sp->nodeName, 579 sizeof(struct lpfc_name)) || 580 (vport->vport_flag & FAWWPN_PARAM_CHG)) { 581 fabric_param_changed = 1; 582 vport->vport_flag &= ~FAWWPN_PARAM_CHG; 583 } 584 /* 585 * Word 1 Bit 31 in common service parameter is overloaded. 586 * Word 1 Bit 31 in FLOGI request is multiple NPort request 587 * Word 1 Bit 31 in FLOGI response is clean address bit 588 * 589 * If fabric parameter is changed and clean address bit is 590 * cleared delay nport discovery if 591 * - vport->fc_prevDID != 0 (not initial discovery) OR 592 * - lpfc_delay_discovery module parameter is set. 593 */ 594 if (fabric_param_changed && !sp->cmn.clean_address_bit && 595 (vport->fc_prevDID || phba->cfg_delay_discovery)) 596 set_bit(FC_DISC_DELAYED, &vport->fc_flag); 597 598 return fabric_param_changed; 599 } 600 601 602 /** 603 * lpfc_cmpl_els_flogi_fabric - Completion function for flogi to a fabric port 604 * @vport: pointer to a host virtual N_Port data structure. 605 * @ndlp: pointer to a node-list data structure. 606 * @sp: pointer to service parameter data structure. 607 * @ulp_word4: command response value 608 * 609 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback 610 * function to handle the completion of a Fabric Login (FLOGI) into a fabric 611 * port in a fabric topology. It properly sets up the parameters to the @ndlp 612 * from the IOCB response. It also check the newly assigned N_Port ID to the 613 * @vport against the previously assigned N_Port ID. If it is different from 614 * the previously assigned Destination ID (DID), the lpfc_unreg_rpi() routine 615 * is invoked on all the remaining nodes with the @vport to unregister the 616 * Remote Port Indicators (RPIs). Finally, the lpfc_issue_fabric_reglogin() 617 * is invoked to register login to the fabric. 618 * 619 * Return code 620 * 0 - Success (currently, always return 0) 621 **/ 622 static int 623 lpfc_cmpl_els_flogi_fabric(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, 624 struct serv_parm *sp, uint32_t ulp_word4) 625 { 626 struct lpfc_hba *phba = vport->phba; 627 struct lpfc_nodelist *np; 628 struct lpfc_nodelist *next_np; 629 uint8_t fabric_param_changed; 630 631 set_bit(FC_FABRIC, &vport->fc_flag); 632 633 phba->fc_edtov = be32_to_cpu(sp->cmn.e_d_tov); 634 if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */ 635 phba->fc_edtov = (phba->fc_edtov + 999999) / 1000000; 636 637 phba->fc_edtovResol = sp->cmn.edtovResolution; 638 phba->fc_ratov = (be32_to_cpu(sp->cmn.w2.r_a_tov) + 999) / 1000; 639 640 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) 641 set_bit(FC_PUBLIC_LOOP, &vport->fc_flag); 642 643 vport->fc_myDID = ulp_word4 & Mask_DID; 644 memcpy(&ndlp->nlp_portname, &sp->portName, sizeof(struct lpfc_name)); 645 memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof(struct lpfc_name)); 646 ndlp->nlp_class_sup = 0; 647 if (sp->cls1.classValid) 648 ndlp->nlp_class_sup |= FC_COS_CLASS1; 649 if (sp->cls2.classValid) 650 ndlp->nlp_class_sup |= FC_COS_CLASS2; 651 if (sp->cls3.classValid) 652 ndlp->nlp_class_sup |= FC_COS_CLASS3; 653 if (sp->cls4.classValid) 654 ndlp->nlp_class_sup |= FC_COS_CLASS4; 655 ndlp->nlp_maxframe = ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) | 656 sp->cmn.bbRcvSizeLsb; 657 658 fabric_param_changed = lpfc_check_clean_addr_bit(vport, sp); 659 if (fabric_param_changed) { 660 /* Reset FDMI attribute masks based on config parameter */ 661 if (phba->cfg_enable_SmartSAN || 662 (phba->cfg_fdmi_on == LPFC_FDMI_SUPPORT)) { 663 /* Setup appropriate attribute masks */ 664 vport->fdmi_hba_mask = LPFC_FDMI2_HBA_ATTR; 665 if (phba->cfg_enable_SmartSAN) 666 vport->fdmi_port_mask = LPFC_FDMI2_SMART_ATTR; 667 else 668 vport->fdmi_port_mask = LPFC_FDMI2_PORT_ATTR; 669 } else { 670 vport->fdmi_hba_mask = 0; 671 vport->fdmi_port_mask = 0; 672 } 673 674 } 675 memcpy(&vport->fabric_portname, &sp->portName, 676 sizeof(struct lpfc_name)); 677 memcpy(&vport->fabric_nodename, &sp->nodeName, 678 sizeof(struct lpfc_name)); 679 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm)); 680 681 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) { 682 if (sp->cmn.response_multiple_NPort) { 683 lpfc_printf_vlog(vport, KERN_WARNING, 684 LOG_ELS | LOG_VPORT, 685 "1816 FLOGI NPIV supported, " 686 "response data 0x%x\n", 687 sp->cmn.response_multiple_NPort); 688 spin_lock_irq(&phba->hbalock); 689 phba->link_flag |= LS_NPIV_FAB_SUPPORTED; 690 spin_unlock_irq(&phba->hbalock); 691 } else { 692 /* Because we asked f/w for NPIV it still expects us 693 to call reg_vnpid at least for the physical host */ 694 lpfc_printf_vlog(vport, KERN_WARNING, 695 LOG_ELS | LOG_VPORT, 696 "1817 Fabric does not support NPIV " 697 "- configuring single port mode.\n"); 698 spin_lock_irq(&phba->hbalock); 699 phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED; 700 spin_unlock_irq(&phba->hbalock); 701 } 702 } 703 704 /* 705 * For FC we need to do some special processing because of the SLI 706 * Port's default settings of the Common Service Parameters. 707 */ 708 if ((phba->sli_rev == LPFC_SLI_REV4) && 709 (phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_FC)) { 710 /* If physical FC port changed, unreg VFI and ALL VPIs / RPIs */ 711 if (fabric_param_changed) 712 lpfc_unregister_fcf_prep(phba); 713 714 /* This should just update the VFI CSPs*/ 715 if (test_bit(FC_VFI_REGISTERED, &vport->fc_flag)) 716 lpfc_issue_reg_vfi(vport); 717 } 718 719 if (fabric_param_changed && 720 !test_bit(FC_VPORT_NEEDS_REG_VPI, &vport->fc_flag)) { 721 722 /* If our NportID changed, we need to ensure all 723 * remaining NPORTs get unreg_login'ed. 724 */ 725 list_for_each_entry_safe(np, next_np, 726 &vport->fc_nodes, nlp_listp) { 727 if ((np->nlp_state != NLP_STE_NPR_NODE) || 728 !test_bit(NLP_NPR_ADISC, &np->nlp_flag)) 729 continue; 730 clear_bit(NLP_NPR_ADISC, &np->nlp_flag); 731 lpfc_unreg_rpi(vport, np); 732 } 733 lpfc_cleanup_pending_mbox(vport); 734 735 if (phba->sli_rev == LPFC_SLI_REV4) { 736 lpfc_sli4_unreg_all_rpis(vport); 737 lpfc_mbx_unreg_vpi(vport); 738 set_bit(FC_VPORT_NEEDS_INIT_VPI, &vport->fc_flag); 739 } 740 741 /* 742 * For SLI3 and SLI4, the VPI needs to be reregistered in 743 * response to this fabric parameter change event. 744 */ 745 set_bit(FC_VPORT_NEEDS_REG_VPI, &vport->fc_flag); 746 } else if ((phba->sli_rev == LPFC_SLI_REV4) && 747 !test_bit(FC_VPORT_NEEDS_REG_VPI, &vport->fc_flag)) { 748 /* 749 * Driver needs to re-reg VPI in order for f/w 750 * to update the MAC address. 751 */ 752 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE); 753 lpfc_register_new_vport(phba, vport, ndlp); 754 return 0; 755 } 756 757 if (phba->sli_rev < LPFC_SLI_REV4) { 758 lpfc_nlp_set_state(vport, ndlp, NLP_STE_REG_LOGIN_ISSUE); 759 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED && 760 test_bit(FC_VPORT_NEEDS_REG_VPI, &vport->fc_flag)) 761 lpfc_register_new_vport(phba, vport, ndlp); 762 else 763 lpfc_issue_fabric_reglogin(vport); 764 } else { 765 ndlp->nlp_type |= NLP_FABRIC; 766 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE); 767 if ((!test_bit(FC_VPORT_NEEDS_REG_VPI, &vport->fc_flag)) && 768 (vport->vpi_state & LPFC_VPI_REGISTERED)) { 769 lpfc_start_fdiscs(phba); 770 lpfc_do_scr_ns_plogi(phba, vport); 771 } else if (test_bit(FC_VFI_REGISTERED, &vport->fc_flag)) 772 lpfc_issue_init_vpi(vport); 773 else { 774 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, 775 "3135 Need register VFI: (x%x/%x)\n", 776 vport->fc_prevDID, vport->fc_myDID); 777 lpfc_issue_reg_vfi(vport); 778 } 779 } 780 return 0; 781 } 782 783 /** 784 * lpfc_cmpl_els_flogi_nport - Completion function for flogi to an N_Port 785 * @vport: pointer to a host virtual N_Port data structure. 786 * @ndlp: pointer to a node-list data structure. 787 * @sp: pointer to service parameter data structure. 788 * 789 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback 790 * function to handle the completion of a Fabric Login (FLOGI) into an N_Port 791 * in a point-to-point topology. First, the @vport's N_Port Name is compared 792 * with the received N_Port Name: if the @vport's N_Port Name is greater than 793 * the received N_Port Name lexicographically, this node shall assign local 794 * N_Port ID (PT2PT_LocalID: 1) and remote N_Port ID (PT2PT_RemoteID: 2) and 795 * will send out Port Login (PLOGI) with the N_Port IDs assigned. Otherwise, 796 * this node shall just wait for the remote node to issue PLOGI and assign 797 * N_Port IDs. 798 * 799 * Return code 800 * 0 - Success 801 * -ENXIO - Fail 802 **/ 803 static int 804 lpfc_cmpl_els_flogi_nport(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, 805 struct serv_parm *sp) 806 { 807 struct lpfc_hba *phba = vport->phba; 808 LPFC_MBOXQ_t *mbox; 809 int rc; 810 811 clear_bit(FC_FABRIC, &vport->fc_flag); 812 clear_bit(FC_PUBLIC_LOOP, &vport->fc_flag); 813 set_bit(FC_PT2PT, &vport->fc_flag); 814 815 /* If we are pt2pt with another NPort, force NPIV off! */ 816 phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED; 817 818 /* If physical FC port changed, unreg VFI and ALL VPIs / RPIs */ 819 if ((phba->sli_rev == LPFC_SLI_REV4) && phba->fc_topology_changed) { 820 lpfc_unregister_fcf_prep(phba); 821 clear_bit(FC_VFI_REGISTERED, &vport->fc_flag); 822 phba->fc_topology_changed = 0; 823 } 824 825 rc = memcmp(&vport->fc_portname, &sp->portName, 826 sizeof(vport->fc_portname)); 827 828 if (rc >= 0) { 829 /* This side will initiate the PLOGI */ 830 set_bit(FC_PT2PT_PLOGI, &vport->fc_flag); 831 832 /* 833 * N_Port ID cannot be 0, set our Id to LocalID 834 * the other side will be RemoteID. 835 */ 836 837 /* not equal */ 838 if (rc) 839 vport->fc_myDID = PT2PT_LocalID; 840 841 /* If not registered with a transport, decrement ndlp reference 842 * count indicating that ndlp can be safely released when other 843 * references are removed. 844 */ 845 if (!(ndlp->fc4_xpt_flags & (SCSI_XPT_REGD | NVME_XPT_REGD))) 846 lpfc_nlp_put(ndlp); 847 848 ndlp = lpfc_findnode_did(vport, PT2PT_RemoteID); 849 if (!ndlp) { 850 /* 851 * Cannot find existing Fabric ndlp, so allocate a 852 * new one 853 */ 854 ndlp = lpfc_nlp_init(vport, PT2PT_RemoteID); 855 if (!ndlp) 856 goto fail; 857 } 858 859 memcpy(&ndlp->nlp_portname, &sp->portName, 860 sizeof(struct lpfc_name)); 861 memcpy(&ndlp->nlp_nodename, &sp->nodeName, 862 sizeof(struct lpfc_name)); 863 /* Set state will put ndlp onto node list if not already done */ 864 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); 865 set_bit(NLP_NPR_2B_DISC, &ndlp->nlp_flag); 866 867 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); 868 if (!mbox) 869 goto fail; 870 871 lpfc_config_link(phba, mbox); 872 873 mbox->mbox_cmpl = lpfc_mbx_cmpl_local_config_link; 874 mbox->vport = vport; 875 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); 876 if (rc == MBX_NOT_FINISHED) { 877 mempool_free(mbox, phba->mbox_mem_pool); 878 goto fail; 879 } 880 } else { 881 /* This side will wait for the PLOGI. If not registered with 882 * a transport, decrement node reference count indicating that 883 * ndlp can be released when other references are removed. 884 */ 885 if (!(ndlp->fc4_xpt_flags & (SCSI_XPT_REGD | NVME_XPT_REGD))) 886 lpfc_nlp_put(ndlp); 887 888 /* Start discovery - this should just do CLEAR_LA */ 889 lpfc_disc_start(vport); 890 } 891 892 return 0; 893 fail: 894 return -ENXIO; 895 } 896 897 /** 898 * lpfc_cmpl_els_flogi - Completion callback function for flogi 899 * @phba: pointer to lpfc hba data structure. 900 * @cmdiocb: pointer to lpfc command iocb data structure. 901 * @rspiocb: pointer to lpfc response iocb data structure. 902 * 903 * This routine is the top-level completion callback function for issuing 904 * a Fabric Login (FLOGI) command. If the response IOCB reported error, 905 * the lpfc_els_retry() routine shall be invoked to retry the FLOGI. If 906 * retry has been made (either immediately or delayed with lpfc_els_retry() 907 * returning 1), the command IOCB will be released and function returned. 908 * If the retry attempt has been given up (possibly reach the maximum 909 * number of retries), one additional decrement of ndlp reference shall be 910 * invoked before going out after releasing the command IOCB. This will 911 * actually release the remote node (Note, lpfc_els_free_iocb() will also 912 * invoke one decrement of ndlp reference count). If no error reported in 913 * the IOCB status, the command Port ID field is used to determine whether 914 * this is a point-to-point topology or a fabric topology: if the Port ID 915 * field is assigned, it is a fabric topology; otherwise, it is a 916 * point-to-point topology. The routine lpfc_cmpl_els_flogi_fabric() or 917 * lpfc_cmpl_els_flogi_nport() shall be invoked accordingly to handle the 918 * specific topology completion conditions. 919 **/ 920 static void 921 lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, 922 struct lpfc_iocbq *rspiocb) 923 { 924 struct lpfc_vport *vport = cmdiocb->vport; 925 struct lpfc_nodelist *ndlp = cmdiocb->ndlp; 926 IOCB_t *irsp; 927 struct lpfc_dmabuf *pcmd = cmdiocb->cmd_dmabuf, *prsp; 928 struct serv_parm *sp; 929 uint16_t fcf_index; 930 int rc; 931 u32 ulp_status, ulp_word4, tmo; 932 bool flogi_in_retry = false; 933 934 /* Check to see if link went down during discovery */ 935 if (lpfc_els_chk_latt(vport)) { 936 /* One additional decrement on node reference count to 937 * trigger the release of the node 938 */ 939 if (!(ndlp->fc4_xpt_flags & SCSI_XPT_REGD)) 940 lpfc_nlp_put(ndlp); 941 goto out; 942 } 943 944 ulp_status = get_job_ulpstatus(phba, rspiocb); 945 ulp_word4 = get_job_word4(phba, rspiocb); 946 947 if (phba->sli_rev == LPFC_SLI_REV4) { 948 tmo = get_wqe_tmo(cmdiocb); 949 } else { 950 irsp = &rspiocb->iocb; 951 tmo = irsp->ulpTimeout; 952 } 953 954 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, 955 "FLOGI cmpl: status:x%x/x%x state:x%x", 956 ulp_status, ulp_word4, 957 vport->port_state); 958 959 if (ulp_status) { 960 /* 961 * In case of FIP mode, perform roundrobin FCF failover 962 * due to new FCF discovery 963 */ 964 if (test_bit(HBA_FIP_SUPPORT, &phba->hba_flag) && 965 (phba->fcf.fcf_flag & FCF_DISCOVERY)) { 966 if (phba->link_state < LPFC_LINK_UP) 967 goto stop_rr_fcf_flogi; 968 if ((phba->fcoe_cvl_eventtag_attn == 969 phba->fcoe_cvl_eventtag) && 970 (ulp_status == IOSTAT_LOCAL_REJECT) && 971 ((ulp_word4 & IOERR_PARAM_MASK) == 972 IOERR_SLI_ABORTED)) 973 goto stop_rr_fcf_flogi; 974 else 975 phba->fcoe_cvl_eventtag_attn = 976 phba->fcoe_cvl_eventtag; 977 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | LOG_ELS, 978 "2611 FLOGI FCF (x%x), " 979 "status:x%x/x%x, tmo:x%x, perform " 980 "roundrobin FCF failover\n", 981 phba->fcf.current_rec.fcf_indx, 982 ulp_status, ulp_word4, tmo); 983 lpfc_sli4_set_fcf_flogi_fail(phba, 984 phba->fcf.current_rec.fcf_indx); 985 fcf_index = lpfc_sli4_fcf_rr_next_index_get(phba); 986 rc = lpfc_sli4_fcf_rr_next_proc(vport, fcf_index); 987 if (rc) 988 goto out; 989 } 990 991 stop_rr_fcf_flogi: 992 /* FLOGI failure */ 993 if (!(ulp_status == IOSTAT_LOCAL_REJECT && 994 ((ulp_word4 & IOERR_PARAM_MASK) == 995 IOERR_LOOP_OPEN_FAILURE))) 996 lpfc_vlog_msg(vport, KERN_WARNING, LOG_ELS, 997 "2858 FLOGI Status:x%x/x%x TMO" 998 ":x%x Data x%lx x%x\n", 999 ulp_status, ulp_word4, tmo, 1000 phba->hba_flag, phba->fcf.fcf_flag); 1001 1002 /* Check for retry */ 1003 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) { 1004 /* Address a timing race with dev_loss. If dev_loss 1005 * is active on this FPort node, put the initial ref 1006 * count back to stop premature node release actions. 1007 */ 1008 lpfc_check_nlp_post_devloss(vport, ndlp); 1009 flogi_in_retry = true; 1010 goto out; 1011 } 1012 1013 /* The FLOGI will not be retried. If the FPort node is not 1014 * registered with the SCSI transport, remove the initial 1015 * reference to trigger node release. 1016 */ 1017 if (!test_bit(NLP_IN_DEV_LOSS, &ndlp->nlp_flag) && 1018 !(ndlp->fc4_xpt_flags & SCSI_XPT_REGD)) 1019 lpfc_nlp_put(ndlp); 1020 1021 lpfc_printf_vlog(vport, KERN_WARNING, LOG_ELS, 1022 "0150 FLOGI Status:x%x/x%x " 1023 "xri x%x TMO:x%x refcnt %d\n", 1024 ulp_status, ulp_word4, cmdiocb->sli4_xritag, 1025 tmo, kref_read(&ndlp->kref)); 1026 1027 /* If this is not a loop open failure, bail out */ 1028 if (!(ulp_status == IOSTAT_LOCAL_REJECT && 1029 ((ulp_word4 & IOERR_PARAM_MASK) == 1030 IOERR_LOOP_OPEN_FAILURE))) { 1031 /* Warn FLOGI status */ 1032 lpfc_vlog_msg(vport, KERN_WARNING, LOG_ELS, 1033 "0100 FLOGI Status:x%x/x%x " 1034 "TMO:x%x\n", 1035 ulp_status, ulp_word4, tmo); 1036 goto flogifail; 1037 } 1038 1039 /* FLOGI failed, so there is no fabric */ 1040 clear_bit(FC_FABRIC, &vport->fc_flag); 1041 clear_bit(FC_PUBLIC_LOOP, &vport->fc_flag); 1042 clear_bit(FC_PT2PT_NO_NVME, &vport->fc_flag); 1043 1044 /* If private loop, then allow max outstanding els to be 1045 * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no 1046 * alpa map would take too long otherwise. 1047 */ 1048 if (phba->alpa_map[0] == 0) 1049 vport->cfg_discovery_threads = LPFC_MAX_DISC_THREADS; 1050 if ((phba->sli_rev == LPFC_SLI_REV4) && 1051 (!test_bit(FC_VFI_REGISTERED, &vport->fc_flag) || 1052 (vport->fc_prevDID != vport->fc_myDID) || 1053 phba->fc_topology_changed)) { 1054 if (test_bit(FC_VFI_REGISTERED, &vport->fc_flag)) { 1055 if (phba->fc_topology_changed) { 1056 lpfc_unregister_fcf_prep(phba); 1057 clear_bit(FC_VFI_REGISTERED, 1058 &vport->fc_flag); 1059 phba->fc_topology_changed = 0; 1060 } else { 1061 lpfc_sli4_unreg_all_rpis(vport); 1062 } 1063 } 1064 1065 /* Do not register VFI if the driver aborted FLOGI */ 1066 if (!lpfc_error_lost_link(vport, ulp_status, ulp_word4)) 1067 lpfc_issue_reg_vfi(vport); 1068 1069 goto out; 1070 } 1071 goto flogifail; 1072 } 1073 clear_bit(FC_VPORT_CVL_RCVD, &vport->fc_flag); 1074 clear_bit(FC_VPORT_LOGO_RCVD, &vport->fc_flag); 1075 1076 /* 1077 * The FLOGI succeeded. Sync the data for the CPU before 1078 * accessing it. 1079 */ 1080 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list); 1081 if (!prsp) 1082 goto out; 1083 if (!lpfc_is_els_acc_rsp(prsp)) 1084 goto out; 1085 sp = prsp->virt + sizeof(uint32_t); 1086 1087 /* FLOGI completes successfully */ 1088 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, 1089 "0101 FLOGI completes successfully, I/O tag:x%x " 1090 "xri x%x Data: x%x x%x x%x x%x x%x x%lx x%x %d\n", 1091 cmdiocb->iotag, cmdiocb->sli4_xritag, 1092 ulp_word4, sp->cmn.e_d_tov, 1093 sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution, 1094 vport->port_state, vport->fc_flag, 1095 sp->cmn.priority_tagging, kref_read(&ndlp->kref)); 1096 1097 /* reinitialize the VMID datastructure before returning */ 1098 if (lpfc_is_vmid_enabled(phba)) { 1099 lpfc_reinit_vmid(vport); 1100 vport->vmid_flag = 0; 1101 } 1102 if (sp->cmn.priority_tagging) 1103 vport->phba->pport->vmid_flag |= (LPFC_VMID_ISSUE_QFPA | 1104 LPFC_VMID_TYPE_PRIO); 1105 1106 /* 1107 * Address a timing race with dev_loss. If dev_loss is active on 1108 * this FPort node, put the initial ref count back to stop premature 1109 * node release actions. 1110 */ 1111 lpfc_check_nlp_post_devloss(vport, ndlp); 1112 if (vport->port_state == LPFC_FLOGI) { 1113 /* 1114 * If Common Service Parameters indicate Nport 1115 * we are point to point, if Fport we are Fabric. 1116 */ 1117 if (sp->cmn.fPort) 1118 rc = lpfc_cmpl_els_flogi_fabric(vport, ndlp, sp, 1119 ulp_word4); 1120 else if (!test_bit(HBA_FCOE_MODE, &phba->hba_flag)) 1121 rc = lpfc_cmpl_els_flogi_nport(vport, ndlp, sp); 1122 else { 1123 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, 1124 "2831 FLOGI response with cleared Fabric " 1125 "bit fcf_index 0x%x " 1126 "Switch Name %02x%02x%02x%02x%02x%02x%02x%02x " 1127 "Fabric Name " 1128 "%02x%02x%02x%02x%02x%02x%02x%02x\n", 1129 phba->fcf.current_rec.fcf_indx, 1130 phba->fcf.current_rec.switch_name[0], 1131 phba->fcf.current_rec.switch_name[1], 1132 phba->fcf.current_rec.switch_name[2], 1133 phba->fcf.current_rec.switch_name[3], 1134 phba->fcf.current_rec.switch_name[4], 1135 phba->fcf.current_rec.switch_name[5], 1136 phba->fcf.current_rec.switch_name[6], 1137 phba->fcf.current_rec.switch_name[7], 1138 phba->fcf.current_rec.fabric_name[0], 1139 phba->fcf.current_rec.fabric_name[1], 1140 phba->fcf.current_rec.fabric_name[2], 1141 phba->fcf.current_rec.fabric_name[3], 1142 phba->fcf.current_rec.fabric_name[4], 1143 phba->fcf.current_rec.fabric_name[5], 1144 phba->fcf.current_rec.fabric_name[6], 1145 phba->fcf.current_rec.fabric_name[7]); 1146 1147 lpfc_nlp_put(ndlp); 1148 spin_lock_irq(&phba->hbalock); 1149 phba->fcf.fcf_flag &= ~FCF_DISCOVERY; 1150 spin_unlock_irq(&phba->hbalock); 1151 clear_bit(FCF_RR_INPROG, &phba->hba_flag); 1152 clear_bit(HBA_DEVLOSS_TMO, &phba->hba_flag); 1153 phba->fcf.fcf_redisc_attempted = 0; /* reset */ 1154 goto out; 1155 } 1156 if (!rc) { 1157 /* Mark the FCF discovery process done */ 1158 if (test_bit(HBA_FIP_SUPPORT, &phba->hba_flag)) 1159 lpfc_printf_vlog(vport, KERN_INFO, LOG_FIP | 1160 LOG_ELS, 1161 "2769 FLOGI to FCF (x%x) " 1162 "completed successfully\n", 1163 phba->fcf.current_rec.fcf_indx); 1164 spin_lock_irq(&phba->hbalock); 1165 phba->fcf.fcf_flag &= ~FCF_DISCOVERY; 1166 spin_unlock_irq(&phba->hbalock); 1167 clear_bit(FCF_RR_INPROG, &phba->hba_flag); 1168 clear_bit(HBA_DEVLOSS_TMO, &phba->hba_flag); 1169 phba->fcf.fcf_redisc_attempted = 0; /* reset */ 1170 goto out; 1171 } 1172 } else if (vport->port_state > LPFC_FLOGI && 1173 test_bit(FC_PT2PT, &vport->fc_flag)) { 1174 /* 1175 * In a p2p topology, it is possible that discovery has 1176 * already progressed, and this completion can be ignored. 1177 * Recheck the indicated topology. 1178 */ 1179 if (!sp->cmn.fPort) 1180 goto out; 1181 } 1182 1183 flogifail: 1184 spin_lock_irq(&phba->hbalock); 1185 phba->fcf.fcf_flag &= ~FCF_DISCOVERY; 1186 spin_unlock_irq(&phba->hbalock); 1187 1188 if (!lpfc_error_lost_link(vport, ulp_status, ulp_word4)) { 1189 /* FLOGI failed, so just use loop map to make discovery list */ 1190 lpfc_disc_list_loopmap(vport); 1191 1192 /* Start discovery */ 1193 lpfc_disc_start(vport); 1194 } else if (((ulp_status != IOSTAT_LOCAL_REJECT) || 1195 (((ulp_word4 & IOERR_PARAM_MASK) != 1196 IOERR_SLI_ABORTED) && 1197 ((ulp_word4 & IOERR_PARAM_MASK) != 1198 IOERR_SLI_DOWN))) && 1199 (phba->link_state != LPFC_CLEAR_LA)) { 1200 /* If FLOGI failed enable link interrupt. */ 1201 lpfc_issue_clear_la(phba, vport); 1202 } 1203 out: 1204 if (!flogi_in_retry) 1205 clear_bit(HBA_FLOGI_OUTSTANDING, &phba->hba_flag); 1206 1207 lpfc_els_free_iocb(phba, cmdiocb); 1208 lpfc_nlp_put(ndlp); 1209 } 1210 1211 /** 1212 * lpfc_cmpl_els_link_down - Completion callback function for ELS command 1213 * aborted during a link down 1214 * @phba: pointer to lpfc hba data structure. 1215 * @cmdiocb: pointer to lpfc command iocb data structure. 1216 * @rspiocb: pointer to lpfc response iocb data structure. 1217 * 1218 */ 1219 static void 1220 lpfc_cmpl_els_link_down(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, 1221 struct lpfc_iocbq *rspiocb) 1222 { 1223 uint32_t *pcmd; 1224 uint32_t cmd; 1225 u32 ulp_status, ulp_word4; 1226 1227 pcmd = (uint32_t *)cmdiocb->cmd_dmabuf->virt; 1228 cmd = *pcmd; 1229 1230 ulp_status = get_job_ulpstatus(phba, rspiocb); 1231 ulp_word4 = get_job_word4(phba, rspiocb); 1232 1233 lpfc_printf_log(phba, KERN_INFO, LOG_ELS, 1234 "6445 ELS completes after LINK_DOWN: " 1235 " Status %x/%x cmd x%x flg x%x iotag x%x\n", 1236 ulp_status, ulp_word4, cmd, 1237 cmdiocb->cmd_flag, cmdiocb->iotag); 1238 1239 if (cmdiocb->cmd_flag & LPFC_IO_FABRIC) { 1240 cmdiocb->cmd_flag &= ~LPFC_IO_FABRIC; 1241 atomic_dec(&phba->fabric_iocb_count); 1242 } 1243 lpfc_els_free_iocb(phba, cmdiocb); 1244 } 1245 1246 /** 1247 * lpfc_issue_els_flogi - Issue an flogi iocb command for a vport 1248 * @vport: pointer to a host virtual N_Port data structure. 1249 * @ndlp: pointer to a node-list data structure. 1250 * @retry: number of retries to the command IOCB. 1251 * 1252 * This routine issues a Fabric Login (FLOGI) Request ELS command 1253 * for a @vport. The initiator service parameters are put into the payload 1254 * of the FLOGI Request IOCB and the top-level callback function pointer 1255 * to lpfc_cmpl_els_flogi() routine is put to the IOCB completion callback 1256 * function field. The lpfc_issue_fabric_iocb routine is invoked to send 1257 * out FLOGI ELS command with one outstanding fabric IOCB at a time. 1258 * 1259 * Note that the ndlp reference count will be incremented by 1 for holding the 1260 * ndlp and the reference to ndlp will be stored into the ndlp field of 1261 * the IOCB for the completion callback function to the FLOGI ELS command. 1262 * 1263 * Return code 1264 * 0 - successfully issued flogi iocb for @vport 1265 * 1 - failed to issue flogi iocb for @vport 1266 **/ 1267 static int 1268 lpfc_issue_els_flogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, 1269 uint8_t retry) 1270 { 1271 struct lpfc_hba *phba = vport->phba; 1272 struct serv_parm *sp; 1273 union lpfc_wqe128 *wqe = NULL; 1274 IOCB_t *icmd = NULL; 1275 struct lpfc_iocbq *elsiocb; 1276 struct lpfc_iocbq defer_flogi_acc; 1277 u8 *pcmd, ct; 1278 uint16_t cmdsize; 1279 uint32_t tmo, did; 1280 int rc; 1281 1282 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm)); 1283 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, 1284 ndlp->nlp_DID, ELS_CMD_FLOGI); 1285 1286 if (!elsiocb) 1287 return 1; 1288 1289 wqe = &elsiocb->wqe; 1290 pcmd = (uint8_t *)elsiocb->cmd_dmabuf->virt; 1291 icmd = &elsiocb->iocb; 1292 1293 /* For FLOGI request, remainder of payload is service parameters */ 1294 *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI; 1295 pcmd += sizeof(uint32_t); 1296 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm)); 1297 sp = (struct serv_parm *) pcmd; 1298 1299 /* Setup CSPs accordingly for Fabric */ 1300 sp->cmn.e_d_tov = 0; 1301 sp->cmn.w2.r_a_tov = 0; 1302 sp->cmn.virtual_fabric_support = 0; 1303 sp->cls1.classValid = 0; 1304 if (sp->cmn.fcphLow < FC_PH3) 1305 sp->cmn.fcphLow = FC_PH3; 1306 if (sp->cmn.fcphHigh < FC_PH3) 1307 sp->cmn.fcphHigh = FC_PH3; 1308 1309 /* Determine if switch supports priority tagging */ 1310 if (phba->cfg_vmid_priority_tagging) { 1311 sp->cmn.priority_tagging = 1; 1312 /* lpfc_vmid_host_uuid is combination of wwpn and wwnn */ 1313 if (!memchr_inv(vport->lpfc_vmid_host_uuid, 0, 1314 sizeof(vport->lpfc_vmid_host_uuid))) { 1315 memcpy(vport->lpfc_vmid_host_uuid, phba->wwpn, 1316 sizeof(phba->wwpn)); 1317 memcpy(&vport->lpfc_vmid_host_uuid[8], phba->wwnn, 1318 sizeof(phba->wwnn)); 1319 } 1320 } 1321 1322 if (phba->sli_rev == LPFC_SLI_REV4) { 1323 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) == 1324 LPFC_SLI_INTF_IF_TYPE_0) { 1325 /* FLOGI needs to be 3 for WQE FCFI */ 1326 ct = SLI4_CT_FCFI; 1327 bf_set(wqe_ct, &wqe->els_req.wqe_com, ct); 1328 1329 /* Set the fcfi to the fcfi we registered with */ 1330 bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com, 1331 phba->fcf.fcfi); 1332 } 1333 1334 /* Can't do SLI4 class2 without support sequence coalescing */ 1335 sp->cls2.classValid = 0; 1336 sp->cls2.seqDelivery = 0; 1337 } else { 1338 /* Historical, setting sequential-delivery bit for SLI3 */ 1339 sp->cls2.seqDelivery = (sp->cls2.classValid) ? 1 : 0; 1340 sp->cls3.seqDelivery = (sp->cls3.classValid) ? 1 : 0; 1341 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) { 1342 sp->cmn.request_multiple_Nport = 1; 1343 /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */ 1344 icmd->ulpCt_h = 1; 1345 icmd->ulpCt_l = 0; 1346 } else { 1347 sp->cmn.request_multiple_Nport = 0; 1348 } 1349 1350 if (phba->fc_topology != LPFC_TOPOLOGY_LOOP) { 1351 icmd->un.elsreq64.myID = 0; 1352 icmd->un.elsreq64.fl = 1; 1353 } 1354 } 1355 1356 tmo = phba->fc_ratov; 1357 phba->fc_ratov = LPFC_DISC_FLOGI_TMO; 1358 lpfc_set_disctmo(vport); 1359 phba->fc_ratov = tmo; 1360 1361 phba->fc_stat.elsXmitFLOGI++; 1362 elsiocb->cmd_cmpl = lpfc_cmpl_els_flogi; 1363 1364 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, 1365 "Issue FLOGI: opt:x%x", 1366 phba->sli3_options, 0, 0); 1367 1368 elsiocb->ndlp = lpfc_nlp_get(ndlp); 1369 if (!elsiocb->ndlp) { 1370 lpfc_els_free_iocb(phba, elsiocb); 1371 return 1; 1372 } 1373 1374 /* Avoid race with FLOGI completion and hba_flags. */ 1375 set_bit(HBA_FLOGI_ISSUED, &phba->hba_flag); 1376 set_bit(HBA_FLOGI_OUTSTANDING, &phba->hba_flag); 1377 1378 rc = lpfc_issue_fabric_iocb(phba, elsiocb); 1379 if (rc == IOCB_ERROR) { 1380 clear_bit(HBA_FLOGI_ISSUED, &phba->hba_flag); 1381 clear_bit(HBA_FLOGI_OUTSTANDING, &phba->hba_flag); 1382 lpfc_els_free_iocb(phba, elsiocb); 1383 lpfc_nlp_put(ndlp); 1384 return 1; 1385 } 1386 1387 /* Clear external loopback plug detected flag */ 1388 phba->link_flag &= ~LS_EXTERNAL_LOOPBACK; 1389 1390 /* Check for a deferred FLOGI ACC condition */ 1391 if (phba->defer_flogi_acc.flag) { 1392 /* lookup ndlp for received FLOGI */ 1393 ndlp = lpfc_findnode_did(vport, 0); 1394 if (!ndlp) 1395 return 0; 1396 1397 did = vport->fc_myDID; 1398 vport->fc_myDID = Fabric_DID; 1399 1400 memset(&defer_flogi_acc, 0, sizeof(struct lpfc_iocbq)); 1401 1402 if (phba->sli_rev == LPFC_SLI_REV4) { 1403 bf_set(wqe_ctxt_tag, 1404 &defer_flogi_acc.wqe.xmit_els_rsp.wqe_com, 1405 phba->defer_flogi_acc.rx_id); 1406 bf_set(wqe_rcvoxid, 1407 &defer_flogi_acc.wqe.xmit_els_rsp.wqe_com, 1408 phba->defer_flogi_acc.ox_id); 1409 } else { 1410 icmd = &defer_flogi_acc.iocb; 1411 icmd->ulpContext = phba->defer_flogi_acc.rx_id; 1412 icmd->unsli3.rcvsli3.ox_id = 1413 phba->defer_flogi_acc.ox_id; 1414 } 1415 1416 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, 1417 "3354 Xmit deferred FLOGI ACC: rx_id: x%x," 1418 " ox_id: x%x, hba_flag x%lx\n", 1419 phba->defer_flogi_acc.rx_id, 1420 phba->defer_flogi_acc.ox_id, phba->hba_flag); 1421 1422 /* Send deferred FLOGI ACC */ 1423 lpfc_els_rsp_acc(vport, ELS_CMD_FLOGI, &defer_flogi_acc, 1424 ndlp, NULL); 1425 1426 phba->defer_flogi_acc.flag = false; 1427 1428 /* Decrement the held ndlp that was incremented when the 1429 * deferred flogi acc flag was set. 1430 */ 1431 if (phba->defer_flogi_acc.ndlp) { 1432 lpfc_nlp_put(phba->defer_flogi_acc.ndlp); 1433 phba->defer_flogi_acc.ndlp = NULL; 1434 } 1435 1436 vport->fc_myDID = did; 1437 } 1438 1439 return 0; 1440 } 1441 1442 /** 1443 * lpfc_els_abort_flogi - Abort all outstanding flogi iocbs 1444 * @phba: pointer to lpfc hba data structure. 1445 * 1446 * This routine aborts all the outstanding Fabric Login (FLOGI) IOCBs 1447 * with a @phba. This routine walks all the outstanding IOCBs on the txcmplq 1448 * list and issues an abort IOCB commond on each outstanding IOCB that 1449 * contains a active Fabric_DID ndlp. Note that this function is to issue 1450 * the abort IOCB command on all the outstanding IOCBs, thus when this 1451 * function returns, it does not guarantee all the IOCBs are actually aborted. 1452 * 1453 * Return code 1454 * 0 - Successfully issued abort iocb on all outstanding flogis (Always 0) 1455 **/ 1456 int 1457 lpfc_els_abort_flogi(struct lpfc_hba *phba) 1458 { 1459 struct lpfc_sli_ring *pring; 1460 struct lpfc_iocbq *iocb, *next_iocb; 1461 struct lpfc_nodelist *ndlp; 1462 u32 ulp_command; 1463 1464 /* Abort outstanding I/O on NPort <nlp_DID> */ 1465 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY, 1466 "0201 Abort outstanding I/O on NPort x%x\n", 1467 Fabric_DID); 1468 1469 pring = lpfc_phba_elsring(phba); 1470 if (unlikely(!pring)) 1471 return -EIO; 1472 1473 /* 1474 * Check the txcmplq for an iocb that matches the nport the driver is 1475 * searching for. 1476 */ 1477 spin_lock_irq(&phba->hbalock); 1478 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) { 1479 ulp_command = get_job_cmnd(phba, iocb); 1480 if (ulp_command == CMD_ELS_REQUEST64_CR) { 1481 ndlp = iocb->ndlp; 1482 if (ndlp && ndlp->nlp_DID == Fabric_DID) { 1483 if (test_bit(FC_PT2PT, &phba->pport->fc_flag) && 1484 !test_bit(FC_PT2PT_PLOGI, 1485 &phba->pport->fc_flag)) 1486 iocb->fabric_cmd_cmpl = 1487 lpfc_ignore_els_cmpl; 1488 lpfc_sli_issue_abort_iotag(phba, pring, iocb, 1489 NULL); 1490 } 1491 } 1492 } 1493 /* Make sure HBA is alive */ 1494 lpfc_issue_hb_tmo(phba); 1495 1496 spin_unlock_irq(&phba->hbalock); 1497 1498 return 0; 1499 } 1500 1501 /** 1502 * lpfc_initial_flogi - Issue an initial fabric login for a vport 1503 * @vport: pointer to a host virtual N_Port data structure. 1504 * 1505 * This routine issues an initial Fabric Login (FLOGI) for the @vport 1506 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from 1507 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and 1508 * put it into the @vport's ndlp list. If an inactive ndlp found on the list, 1509 * it will just be enabled and made active. The lpfc_issue_els_flogi() routine 1510 * is then invoked with the @vport and the ndlp to perform the FLOGI for the 1511 * @vport. 1512 * 1513 * Return code 1514 * 0 - failed to issue initial flogi for @vport 1515 * 1 - successfully issued initial flogi for @vport 1516 **/ 1517 int 1518 lpfc_initial_flogi(struct lpfc_vport *vport) 1519 { 1520 struct lpfc_nodelist *ndlp; 1521 1522 vport->port_state = LPFC_FLOGI; 1523 lpfc_set_disctmo(vport); 1524 1525 /* First look for the Fabric ndlp */ 1526 ndlp = lpfc_findnode_did(vport, Fabric_DID); 1527 if (!ndlp) { 1528 /* Cannot find existing Fabric ndlp, so allocate a new one */ 1529 ndlp = lpfc_nlp_init(vport, Fabric_DID); 1530 if (!ndlp) 1531 return 0; 1532 /* Set the node type */ 1533 ndlp->nlp_type |= NLP_FABRIC; 1534 1535 /* Put ndlp onto node list */ 1536 lpfc_enqueue_node(vport, ndlp); 1537 } 1538 1539 /* Reset the Fabric flag, topology change may have happened */ 1540 clear_bit(FC_FABRIC, &vport->fc_flag); 1541 if (lpfc_issue_els_flogi(vport, ndlp, 0)) { 1542 /* A node reference should be retained while registered with a 1543 * transport or dev-loss-evt work is pending. 1544 * Otherwise, decrement node reference to trigger release. 1545 */ 1546 if (!(ndlp->fc4_xpt_flags & (SCSI_XPT_REGD | NVME_XPT_REGD)) && 1547 !test_bit(NLP_IN_DEV_LOSS, &ndlp->nlp_flag)) 1548 lpfc_nlp_put(ndlp); 1549 return 0; 1550 } 1551 return 1; 1552 } 1553 1554 /** 1555 * lpfc_initial_fdisc - Issue an initial fabric discovery for a vport 1556 * @vport: pointer to a host virtual N_Port data structure. 1557 * 1558 * This routine issues an initial Fabric Discover (FDISC) for the @vport 1559 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from 1560 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and 1561 * put it into the @vport's ndlp list. If an inactive ndlp found on the list, 1562 * it will just be enabled and made active. The lpfc_issue_els_fdisc() routine 1563 * is then invoked with the @vport and the ndlp to perform the FDISC for the 1564 * @vport. 1565 * 1566 * Return code 1567 * 0 - failed to issue initial fdisc for @vport 1568 * 1 - successfully issued initial fdisc for @vport 1569 **/ 1570 int 1571 lpfc_initial_fdisc(struct lpfc_vport *vport) 1572 { 1573 struct lpfc_nodelist *ndlp; 1574 1575 /* First look for the Fabric ndlp */ 1576 ndlp = lpfc_findnode_did(vport, Fabric_DID); 1577 if (!ndlp) { 1578 /* Cannot find existing Fabric ndlp, so allocate a new one */ 1579 ndlp = lpfc_nlp_init(vport, Fabric_DID); 1580 if (!ndlp) 1581 return 0; 1582 1583 /* NPIV is only supported in Fabrics. */ 1584 ndlp->nlp_type |= NLP_FABRIC; 1585 1586 /* Put ndlp onto node list */ 1587 lpfc_enqueue_node(vport, ndlp); 1588 } 1589 1590 if (lpfc_issue_els_fdisc(vport, ndlp, 0)) { 1591 /* A node reference should be retained while registered with a 1592 * transport or dev-loss-evt work is pending. 1593 * Otherwise, decrement node reference to trigger release. 1594 */ 1595 if (!(ndlp->fc4_xpt_flags & (SCSI_XPT_REGD | NVME_XPT_REGD)) && 1596 !test_bit(NLP_IN_DEV_LOSS, &ndlp->nlp_flag)) 1597 lpfc_nlp_put(ndlp); 1598 return 0; 1599 } 1600 return 1; 1601 } 1602 1603 /** 1604 * lpfc_more_plogi - Check and issue remaining plogis for a vport 1605 * @vport: pointer to a host virtual N_Port data structure. 1606 * 1607 * This routine checks whether there are more remaining Port Logins 1608 * (PLOGI) to be issued for the @vport. If so, it will invoke the routine 1609 * lpfc_els_disc_plogi() to go through the Node Port Recovery (NPR) nodes 1610 * to issue ELS PLOGIs up to the configured discover threads with the 1611 * @vport (@vport->cfg_discovery_threads). The function also decrement 1612 * the @vport's num_disc_node by 1 if it is not already 0. 1613 **/ 1614 void 1615 lpfc_more_plogi(struct lpfc_vport *vport) 1616 { 1617 if (vport->num_disc_nodes) 1618 vport->num_disc_nodes--; 1619 1620 /* Continue discovery with <num_disc_nodes> PLOGIs to go */ 1621 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, 1622 "0232 Continue discovery with %d PLOGIs to go " 1623 "Data: x%x x%lx x%x\n", 1624 vport->num_disc_nodes, 1625 atomic_read(&vport->fc_plogi_cnt), 1626 vport->fc_flag, vport->port_state); 1627 /* Check to see if there are more PLOGIs to be sent */ 1628 if (test_bit(FC_NLP_MORE, &vport->fc_flag)) 1629 /* go thru NPR nodes and issue any remaining ELS PLOGIs */ 1630 lpfc_els_disc_plogi(vport); 1631 1632 return; 1633 } 1634 1635 /** 1636 * lpfc_plogi_confirm_nport - Confirm plogi wwpn matches stored ndlp 1637 * @phba: pointer to lpfc hba data structure. 1638 * @prsp: pointer to response IOCB payload. 1639 * @ndlp: pointer to a node-list data structure. 1640 * 1641 * This routine checks and indicates whether the WWPN of an N_Port, retrieved 1642 * from a PLOGI, matches the WWPN that is stored in the @ndlp for that N_POrt. 1643 * The following cases are considered N_Port confirmed: 1644 * 1) The N_Port is a Fabric ndlp; 2) The @ndlp is on vport list and matches 1645 * the WWPN of the N_Port logged into; 3) The @ndlp is not on vport list but 1646 * it does not have WWPN assigned either. If the WWPN is confirmed, the 1647 * pointer to the @ndlp will be returned. If the WWPN is not confirmed: 1648 * 1) if there is a node on vport list other than the @ndlp with the same 1649 * WWPN of the N_Port PLOGI logged into, the lpfc_unreg_rpi() will be invoked 1650 * on that node to release the RPI associated with the node; 2) if there is 1651 * no node found on vport list with the same WWPN of the N_Port PLOGI logged 1652 * into, a new node shall be allocated (or activated). In either case, the 1653 * parameters of the @ndlp shall be copied to the new_ndlp, the @ndlp shall 1654 * be released and the new_ndlp shall be put on to the vport node list and 1655 * its pointer returned as the confirmed node. 1656 * 1657 * Note that before the @ndlp got "released", the keepDID from not-matching 1658 * or inactive "new_ndlp" on the vport node list is assigned to the nlp_DID 1659 * of the @ndlp. This is because the release of @ndlp is actually to put it 1660 * into an inactive state on the vport node list and the vport node list 1661 * management algorithm does not allow two node with a same DID. 1662 * 1663 * Return code 1664 * pointer to the PLOGI N_Port @ndlp 1665 **/ 1666 static struct lpfc_nodelist * 1667 lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp, 1668 struct lpfc_nodelist *ndlp) 1669 { 1670 struct lpfc_vport *vport = ndlp->vport; 1671 struct lpfc_nodelist *new_ndlp; 1672 struct serv_parm *sp; 1673 uint8_t name[sizeof(struct lpfc_name)]; 1674 uint32_t keepDID = 0; 1675 int rc; 1676 unsigned long keep_nlp_flag = 0, keep_new_nlp_flag = 0; 1677 uint16_t keep_nlp_state; 1678 u32 keep_nlp_fc4_type = 0; 1679 struct lpfc_nvme_rport *keep_nrport = NULL; 1680 unsigned long *active_rrqs_xri_bitmap = NULL; 1681 1682 sp = (struct serv_parm *) ((uint8_t *) prsp + sizeof(uint32_t)); 1683 memset(name, 0, sizeof(struct lpfc_name)); 1684 1685 /* Now we find out if the NPort we are logging into, matches the WWPN 1686 * we have for that ndlp. If not, we have some work to do. 1687 */ 1688 new_ndlp = lpfc_findnode_wwpn(vport, &sp->portName); 1689 1690 /* return immediately if the WWPN matches ndlp */ 1691 if (new_ndlp == ndlp) 1692 return ndlp; 1693 1694 if (phba->sli_rev == LPFC_SLI_REV4) { 1695 active_rrqs_xri_bitmap = mempool_alloc(phba->active_rrq_pool, 1696 GFP_KERNEL); 1697 if (active_rrqs_xri_bitmap) 1698 memset(active_rrqs_xri_bitmap, 0, 1699 phba->cfg_rrq_xri_bitmap_sz); 1700 } 1701 1702 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS | LOG_NODE, 1703 "3178 PLOGI confirm: ndlp x%x x%lx x%x: " 1704 "new_ndlp x%x x%lx x%x\n", 1705 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_fc4_type, 1706 (new_ndlp ? new_ndlp->nlp_DID : 0), 1707 (new_ndlp ? new_ndlp->nlp_flag : 0), 1708 (new_ndlp ? new_ndlp->nlp_fc4_type : 0)); 1709 1710 if (!new_ndlp) { 1711 rc = memcmp(&ndlp->nlp_portname, name, 1712 sizeof(struct lpfc_name)); 1713 if (!rc) { 1714 if (active_rrqs_xri_bitmap) 1715 mempool_free(active_rrqs_xri_bitmap, 1716 phba->active_rrq_pool); 1717 return ndlp; 1718 } 1719 new_ndlp = lpfc_nlp_init(vport, ndlp->nlp_DID); 1720 if (!new_ndlp) { 1721 if (active_rrqs_xri_bitmap) 1722 mempool_free(active_rrqs_xri_bitmap, 1723 phba->active_rrq_pool); 1724 return ndlp; 1725 } 1726 } else { 1727 if (phba->sli_rev == LPFC_SLI_REV4 && 1728 active_rrqs_xri_bitmap) 1729 memcpy(active_rrqs_xri_bitmap, 1730 new_ndlp->active_rrqs_xri_bitmap, 1731 phba->cfg_rrq_xri_bitmap_sz); 1732 1733 /* 1734 * Unregister from backend if not done yet. Could have been 1735 * skipped due to ADISC 1736 */ 1737 lpfc_nlp_unreg_node(vport, new_ndlp); 1738 } 1739 1740 keepDID = new_ndlp->nlp_DID; 1741 1742 /* At this point in this routine, we know new_ndlp will be 1743 * returned. however, any previous GID_FTs that were done 1744 * would have updated nlp_fc4_type in ndlp, so we must ensure 1745 * new_ndlp has the right value. 1746 */ 1747 if (test_bit(FC_FABRIC, &vport->fc_flag)) { 1748 keep_nlp_fc4_type = new_ndlp->nlp_fc4_type; 1749 new_ndlp->nlp_fc4_type = ndlp->nlp_fc4_type; 1750 } 1751 1752 lpfc_unreg_rpi(vport, new_ndlp); 1753 new_ndlp->nlp_DID = ndlp->nlp_DID; 1754 new_ndlp->nlp_prev_state = ndlp->nlp_prev_state; 1755 if (phba->sli_rev == LPFC_SLI_REV4) 1756 memcpy(new_ndlp->active_rrqs_xri_bitmap, 1757 ndlp->active_rrqs_xri_bitmap, 1758 phba->cfg_rrq_xri_bitmap_sz); 1759 1760 /* Lock both ndlps */ 1761 spin_lock_irq(&ndlp->lock); 1762 spin_lock_irq(&new_ndlp->lock); 1763 keep_new_nlp_flag = new_ndlp->nlp_flag; 1764 keep_nlp_flag = ndlp->nlp_flag; 1765 new_ndlp->nlp_flag = ndlp->nlp_flag; 1766 1767 /* if new_ndlp had NLP_UNREG_INP set, keep it */ 1768 if (test_bit(NLP_UNREG_INP, &keep_new_nlp_flag)) 1769 set_bit(NLP_UNREG_INP, &new_ndlp->nlp_flag); 1770 else 1771 clear_bit(NLP_UNREG_INP, &new_ndlp->nlp_flag); 1772 1773 /* if new_ndlp had NLP_RPI_REGISTERED set, keep it */ 1774 if (test_bit(NLP_RPI_REGISTERED, &keep_new_nlp_flag)) 1775 set_bit(NLP_RPI_REGISTERED, &new_ndlp->nlp_flag); 1776 else 1777 clear_bit(NLP_RPI_REGISTERED, &new_ndlp->nlp_flag); 1778 1779 /* 1780 * Retain the DROPPED flag. This will take care of the init 1781 * refcount when affecting the state change 1782 */ 1783 if (test_bit(NLP_DROPPED, &keep_new_nlp_flag)) 1784 set_bit(NLP_DROPPED, &new_ndlp->nlp_flag); 1785 else 1786 clear_bit(NLP_DROPPED, &new_ndlp->nlp_flag); 1787 1788 ndlp->nlp_flag = keep_new_nlp_flag; 1789 1790 /* if ndlp had NLP_UNREG_INP set, keep it */ 1791 if (test_bit(NLP_UNREG_INP, &keep_nlp_flag)) 1792 set_bit(NLP_UNREG_INP, &ndlp->nlp_flag); 1793 else 1794 clear_bit(NLP_UNREG_INP, &ndlp->nlp_flag); 1795 1796 /* if ndlp had NLP_RPI_REGISTERED set, keep it */ 1797 if (test_bit(NLP_RPI_REGISTERED, &keep_nlp_flag)) 1798 set_bit(NLP_RPI_REGISTERED, &ndlp->nlp_flag); 1799 else 1800 clear_bit(NLP_RPI_REGISTERED, &ndlp->nlp_flag); 1801 1802 /* 1803 * Retain the DROPPED flag. This will take care of the init 1804 * refcount when affecting the state change 1805 */ 1806 if (test_bit(NLP_DROPPED, &keep_nlp_flag)) 1807 set_bit(NLP_DROPPED, &ndlp->nlp_flag); 1808 else 1809 clear_bit(NLP_DROPPED, &ndlp->nlp_flag); 1810 1811 spin_unlock_irq(&new_ndlp->lock); 1812 spin_unlock_irq(&ndlp->lock); 1813 1814 /* Set nlp_states accordingly */ 1815 keep_nlp_state = new_ndlp->nlp_state; 1816 lpfc_nlp_set_state(vport, new_ndlp, ndlp->nlp_state); 1817 1818 /* interchange the nvme remoteport structs */ 1819 keep_nrport = new_ndlp->nrport; 1820 new_ndlp->nrport = ndlp->nrport; 1821 1822 /* Move this back to NPR state */ 1823 if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0) { 1824 /* The ndlp doesn't have a portname yet, but does have an 1825 * NPort ID. The new_ndlp portname matches the Rport's 1826 * portname. Reinstantiate the new_ndlp and reset the ndlp. 1827 */ 1828 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, 1829 "3179 PLOGI confirm NEW: %x %x\n", 1830 new_ndlp->nlp_DID, keepDID); 1831 1832 /* Two ndlps cannot have the same did on the nodelist. 1833 * The KeepDID and keep_nlp_fc4_type need to be swapped 1834 * because ndlp is inflight with no WWPN. 1835 */ 1836 ndlp->nlp_DID = keepDID; 1837 ndlp->nlp_fc4_type = keep_nlp_fc4_type; 1838 lpfc_nlp_set_state(vport, ndlp, keep_nlp_state); 1839 if (phba->sli_rev == LPFC_SLI_REV4 && 1840 active_rrqs_xri_bitmap) 1841 memcpy(ndlp->active_rrqs_xri_bitmap, 1842 active_rrqs_xri_bitmap, 1843 phba->cfg_rrq_xri_bitmap_sz); 1844 1845 } else { 1846 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, 1847 "3180 PLOGI confirm SWAP: %x %x\n", 1848 new_ndlp->nlp_DID, keepDID); 1849 1850 lpfc_unreg_rpi(vport, ndlp); 1851 1852 /* The ndlp and new_ndlp both have WWPNs but are swapping 1853 * NPort Ids and attributes. 1854 */ 1855 ndlp->nlp_DID = keepDID; 1856 ndlp->nlp_fc4_type = keep_nlp_fc4_type; 1857 1858 if (phba->sli_rev == LPFC_SLI_REV4 && 1859 active_rrqs_xri_bitmap) 1860 memcpy(ndlp->active_rrqs_xri_bitmap, 1861 active_rrqs_xri_bitmap, 1862 phba->cfg_rrq_xri_bitmap_sz); 1863 1864 /* Since we are switching over to the new_ndlp, 1865 * reset the old ndlp state 1866 */ 1867 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) || 1868 (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) 1869 keep_nlp_state = NLP_STE_NPR_NODE; 1870 lpfc_nlp_set_state(vport, ndlp, keep_nlp_state); 1871 ndlp->nrport = keep_nrport; 1872 } 1873 1874 /* 1875 * If ndlp is not associated with any rport we can drop it here else 1876 * let dev_loss_tmo_callbk trigger DEVICE_RM event 1877 */ 1878 if (!ndlp->rport && (ndlp->nlp_state == NLP_STE_NPR_NODE)) 1879 lpfc_disc_state_machine(vport, ndlp, NULL, NLP_EVT_DEVICE_RM); 1880 1881 if (phba->sli_rev == LPFC_SLI_REV4 && 1882 active_rrqs_xri_bitmap) 1883 mempool_free(active_rrqs_xri_bitmap, 1884 phba->active_rrq_pool); 1885 1886 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS | LOG_NODE, 1887 "3173 PLOGI confirm exit: new_ndlp x%x x%lx x%x\n", 1888 new_ndlp->nlp_DID, new_ndlp->nlp_flag, 1889 new_ndlp->nlp_fc4_type); 1890 1891 return new_ndlp; 1892 } 1893 1894 /** 1895 * lpfc_end_rscn - Check and handle more rscn for a vport 1896 * @vport: pointer to a host virtual N_Port data structure. 1897 * 1898 * This routine checks whether more Registration State Change 1899 * Notifications (RSCNs) came in while the discovery state machine was in 1900 * the FC_RSCN_MODE. If so, the lpfc_els_handle_rscn() routine will be 1901 * invoked to handle the additional RSCNs for the @vport. Otherwise, the 1902 * FC_RSCN_MODE bit will be cleared with the @vport to mark as the end of 1903 * handling the RSCNs. 1904 **/ 1905 void 1906 lpfc_end_rscn(struct lpfc_vport *vport) 1907 { 1908 1909 if (test_bit(FC_RSCN_MODE, &vport->fc_flag)) { 1910 /* 1911 * Check to see if more RSCNs came in while we were 1912 * processing this one. 1913 */ 1914 if (vport->fc_rscn_id_cnt || 1915 test_bit(FC_RSCN_DISCOVERY, &vport->fc_flag)) 1916 lpfc_els_handle_rscn(vport); 1917 else 1918 clear_bit(FC_RSCN_MODE, &vport->fc_flag); 1919 } 1920 } 1921 1922 /** 1923 * lpfc_cmpl_els_rrq - Completion handled for els RRQs. 1924 * @phba: pointer to lpfc hba data structure. 1925 * @cmdiocb: pointer to lpfc command iocb data structure. 1926 * @rspiocb: pointer to lpfc response iocb data structure. 1927 * 1928 * This routine will call the clear rrq function to free the rrq and 1929 * clear the xri's bit in the ndlp's xri_bitmap. If the ndlp does not 1930 * exist then the clear_rrq is still called because the rrq needs to 1931 * be freed. 1932 **/ 1933 1934 static void 1935 lpfc_cmpl_els_rrq(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, 1936 struct lpfc_iocbq *rspiocb) 1937 { 1938 struct lpfc_vport *vport = cmdiocb->vport; 1939 struct lpfc_nodelist *ndlp = cmdiocb->ndlp; 1940 struct lpfc_node_rrq *rrq; 1941 u32 ulp_status = get_job_ulpstatus(phba, rspiocb); 1942 u32 ulp_word4 = get_job_word4(phba, rspiocb); 1943 1944 /* we pass cmdiocb to state machine which needs rspiocb as well */ 1945 rrq = cmdiocb->context_un.rrq; 1946 cmdiocb->rsp_iocb = rspiocb; 1947 1948 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, 1949 "RRQ cmpl: status:x%x/x%x did:x%x", 1950 ulp_status, ulp_word4, 1951 get_job_els_rsp64_did(phba, cmdiocb)); 1952 1953 1954 /* rrq completes to NPort <nlp_DID> */ 1955 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, 1956 "2880 RRQ completes to DID x%x " 1957 "Data: x%x x%x x%x x%x x%x\n", 1958 ndlp->nlp_DID, ulp_status, ulp_word4, 1959 get_wqe_tmo(cmdiocb), rrq->xritag, rrq->rxid); 1960 1961 if (ulp_status) { 1962 /* Check for retry */ 1963 /* Warn RRQ status Don't print the vport to vport rjts */ 1964 if (ulp_status != IOSTAT_LS_RJT || 1965 (((ulp_word4) >> 16 != LSRJT_INVALID_CMD) && 1966 ((ulp_word4) >> 16 != LSRJT_UNABLE_TPC)) || 1967 (phba)->pport->cfg_log_verbose & LOG_ELS) 1968 lpfc_vlog_msg(vport, KERN_WARNING, LOG_ELS, 1969 "2881 RRQ DID:%06X Status:" 1970 "x%x/x%x\n", 1971 ndlp->nlp_DID, ulp_status, 1972 ulp_word4); 1973 } 1974 1975 lpfc_clr_rrq_active(phba, rrq->xritag, rrq); 1976 lpfc_els_free_iocb(phba, cmdiocb); 1977 lpfc_nlp_put(ndlp); 1978 return; 1979 } 1980 /** 1981 * lpfc_cmpl_els_plogi - Completion callback function for plogi 1982 * @phba: pointer to lpfc hba data structure. 1983 * @cmdiocb: pointer to lpfc command iocb data structure. 1984 * @rspiocb: pointer to lpfc response iocb data structure. 1985 * 1986 * This routine is the completion callback function for issuing the Port 1987 * Login (PLOGI) command. For PLOGI completion, there must be an active 1988 * ndlp on the vport node list that matches the remote node ID from the 1989 * PLOGI response IOCB. If such ndlp does not exist, the PLOGI is simply 1990 * ignored and command IOCB released. The PLOGI response IOCB status is 1991 * checked for error conditions. If there is error status reported, PLOGI 1992 * retry shall be attempted by invoking the lpfc_els_retry() routine. 1993 * Otherwise, the lpfc_plogi_confirm_nport() routine shall be invoked on 1994 * the ndlp and the NLP_EVT_CMPL_PLOGI state to the Discover State Machine 1995 * (DSM) is set for this PLOGI completion. Finally, it checks whether 1996 * there are additional N_Port nodes with the vport that need to perform 1997 * PLOGI. If so, the lpfc_more_plogi() routine is invoked to issue addition 1998 * PLOGIs. 1999 **/ 2000 static void 2001 lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, 2002 struct lpfc_iocbq *rspiocb) 2003 { 2004 struct lpfc_vport *vport = cmdiocb->vport; 2005 IOCB_t *irsp; 2006 struct lpfc_nodelist *ndlp, *free_ndlp; 2007 struct lpfc_dmabuf *prsp; 2008 bool disc; 2009 struct serv_parm *sp = NULL; 2010 u32 ulp_status, ulp_word4, did, iotag; 2011 bool release_node = false; 2012 2013 /* we pass cmdiocb to state machine which needs rspiocb as well */ 2014 cmdiocb->rsp_iocb = rspiocb; 2015 2016 ulp_status = get_job_ulpstatus(phba, rspiocb); 2017 ulp_word4 = get_job_word4(phba, rspiocb); 2018 did = get_job_els_rsp64_did(phba, cmdiocb); 2019 2020 if (phba->sli_rev == LPFC_SLI_REV4) { 2021 iotag = get_wqe_reqtag(cmdiocb); 2022 } else { 2023 irsp = &rspiocb->iocb; 2024 iotag = irsp->ulpIoTag; 2025 } 2026 2027 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, 2028 "PLOGI cmpl: status:x%x/x%x did:x%x", 2029 ulp_status, ulp_word4, did); 2030 2031 ndlp = lpfc_findnode_did(vport, did); 2032 if (!ndlp) { 2033 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, 2034 "0136 PLOGI completes to NPort x%x " 2035 "with no ndlp. Data: x%x x%x x%x\n", 2036 did, ulp_status, ulp_word4, iotag); 2037 goto out_freeiocb; 2038 } 2039 2040 /* Since ndlp can be freed in the disc state machine, note if this node 2041 * is being used during discovery. 2042 */ 2043 disc = test_and_clear_bit(NLP_NPR_2B_DISC, &ndlp->nlp_flag); 2044 2045 /* PLOGI completes to NPort <nlp_DID> */ 2046 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, 2047 "0102 PLOGI completes to NPort x%06x " 2048 "IoTag x%x Data: x%x x%x x%x x%x x%x\n", 2049 ndlp->nlp_DID, iotag, 2050 ndlp->nlp_fc4_type, 2051 ulp_status, ulp_word4, 2052 disc, vport->num_disc_nodes); 2053 2054 /* Check to see if link went down during discovery */ 2055 if (lpfc_els_chk_latt(vport)) { 2056 set_bit(NLP_NPR_2B_DISC, &ndlp->nlp_flag); 2057 goto out; 2058 } 2059 2060 if (ulp_status) { 2061 /* Check for retry */ 2062 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) { 2063 /* ELS command is being retried */ 2064 if (disc) 2065 set_bit(NLP_NPR_2B_DISC, &ndlp->nlp_flag); 2066 goto out; 2067 } 2068 /* Warn PLOGI status Don't print the vport to vport rjts */ 2069 if (ulp_status != IOSTAT_LS_RJT || 2070 (((ulp_word4) >> 16 != LSRJT_INVALID_CMD) && 2071 ((ulp_word4) >> 16 != LSRJT_UNABLE_TPC)) || 2072 (phba)->pport->cfg_log_verbose & LOG_ELS) 2073 lpfc_vlog_msg(vport, KERN_WARNING, LOG_ELS, 2074 "2753 PLOGI DID:%06X " 2075 "Status:x%x/x%x\n", 2076 ndlp->nlp_DID, ulp_status, 2077 ulp_word4); 2078 2079 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ 2080 if (!lpfc_error_lost_link(vport, ulp_status, ulp_word4)) 2081 lpfc_disc_state_machine(vport, ndlp, cmdiocb, 2082 NLP_EVT_CMPL_PLOGI); 2083 2084 /* If a PLOGI collision occurred, the node needs to continue 2085 * with the reglogin process. 2086 */ 2087 spin_lock_irq(&ndlp->lock); 2088 if ((test_bit(NLP_ACC_REGLOGIN, &ndlp->nlp_flag) || 2089 test_bit(NLP_RCV_PLOGI, &ndlp->nlp_flag)) && 2090 ndlp->nlp_state == NLP_STE_REG_LOGIN_ISSUE) { 2091 spin_unlock_irq(&ndlp->lock); 2092 goto out; 2093 } 2094 2095 /* No PLOGI collision and the node is not registered with the 2096 * scsi or nvme transport. It is no longer an active node. Just 2097 * start the device remove process. 2098 */ 2099 if (!(ndlp->fc4_xpt_flags & (SCSI_XPT_REGD | NVME_XPT_REGD))) { 2100 clear_bit(NLP_NPR_2B_DISC, &ndlp->nlp_flag); 2101 if (!test_bit(NLP_IN_DEV_LOSS, &ndlp->nlp_flag)) 2102 release_node = true; 2103 } 2104 spin_unlock_irq(&ndlp->lock); 2105 2106 if (release_node) 2107 lpfc_disc_state_machine(vport, ndlp, cmdiocb, 2108 NLP_EVT_DEVICE_RM); 2109 } else { 2110 /* Good status, call state machine */ 2111 prsp = list_get_first(&cmdiocb->cmd_dmabuf->list, 2112 struct lpfc_dmabuf, list); 2113 if (!prsp) 2114 goto out; 2115 if (!lpfc_is_els_acc_rsp(prsp)) 2116 goto out; 2117 ndlp = lpfc_plogi_confirm_nport(phba, prsp->virt, ndlp); 2118 2119 sp = (struct serv_parm *)((u8 *)prsp->virt + 2120 sizeof(u32)); 2121 2122 ndlp->vmid_support = 0; 2123 if ((phba->cfg_vmid_app_header && sp->cmn.app_hdr_support) || 2124 (phba->cfg_vmid_priority_tagging && 2125 sp->cmn.priority_tagging)) { 2126 lpfc_printf_log(phba, KERN_DEBUG, LOG_ELS, 2127 "4018 app_hdr_support %d tagging %d DID x%x\n", 2128 sp->cmn.app_hdr_support, 2129 sp->cmn.priority_tagging, 2130 ndlp->nlp_DID); 2131 /* if the dest port supports VMID, mark it in ndlp */ 2132 ndlp->vmid_support = 1; 2133 } 2134 2135 lpfc_disc_state_machine(vport, ndlp, cmdiocb, 2136 NLP_EVT_CMPL_PLOGI); 2137 } 2138 2139 if (disc && vport->num_disc_nodes) { 2140 /* Check to see if there are more PLOGIs to be sent */ 2141 lpfc_more_plogi(vport); 2142 2143 if (vport->num_disc_nodes == 0) { 2144 clear_bit(FC_NDISC_ACTIVE, &vport->fc_flag); 2145 2146 lpfc_can_disctmo(vport); 2147 lpfc_end_rscn(vport); 2148 } 2149 } 2150 2151 out: 2152 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE, 2153 "PLOGI Cmpl PUT: did:x%x refcnt %d", 2154 ndlp->nlp_DID, kref_read(&ndlp->kref), 0); 2155 2156 out_freeiocb: 2157 /* Release the reference on the original I/O request. */ 2158 free_ndlp = cmdiocb->ndlp; 2159 2160 lpfc_els_free_iocb(phba, cmdiocb); 2161 lpfc_nlp_put(free_ndlp); 2162 return; 2163 } 2164 2165 /** 2166 * lpfc_issue_els_plogi - Issue an plogi iocb command for a vport 2167 * @vport: pointer to a host virtual N_Port data structure. 2168 * @did: destination port identifier. 2169 * @retry: number of retries to the command IOCB. 2170 * 2171 * This routine issues a Port Login (PLOGI) command to a remote N_Port 2172 * (with the @did) for a @vport. Before issuing a PLOGI to a remote N_Port, 2173 * the ndlp with the remote N_Port DID must exist on the @vport's ndlp list. 2174 * This routine constructs the proper fields of the PLOGI IOCB and invokes 2175 * the lpfc_sli_issue_iocb() routine to send out PLOGI ELS command. 2176 * 2177 * Note that the ndlp reference count will be incremented by 1 for holding 2178 * the ndlp and the reference to ndlp will be stored into the ndlp field 2179 * of the IOCB for the completion callback function to the PLOGI ELS command. 2180 * 2181 * Return code 2182 * 0 - Successfully issued a plogi for @vport 2183 * 1 - failed to issue a plogi for @vport 2184 **/ 2185 int 2186 lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry) 2187 { 2188 struct lpfc_hba *phba = vport->phba; 2189 struct serv_parm *sp; 2190 struct lpfc_nodelist *ndlp; 2191 struct lpfc_iocbq *elsiocb; 2192 uint8_t *pcmd; 2193 uint16_t cmdsize; 2194 int ret; 2195 2196 ndlp = lpfc_findnode_did(vport, did); 2197 if (!ndlp) 2198 return 1; 2199 2200 /* Defer the processing of the issue PLOGI until after the 2201 * outstanding UNREG_RPI mbox command completes, unless we 2202 * are going offline. This logic does not apply for Fabric DIDs 2203 */ 2204 if ((test_bit(NLP_IGNR_REG_CMPL, &ndlp->nlp_flag) || 2205 test_bit(NLP_UNREG_INP, &ndlp->nlp_flag)) && 2206 ((ndlp->nlp_DID & Fabric_DID_MASK) != Fabric_DID_MASK) && 2207 !test_bit(FC_OFFLINE_MODE, &vport->fc_flag)) { 2208 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, 2209 "4110 Issue PLOGI x%x deferred " 2210 "on NPort x%x rpi x%x flg x%lx Data:" 2211 " x%px\n", 2212 ndlp->nlp_defer_did, ndlp->nlp_DID, 2213 ndlp->nlp_rpi, ndlp->nlp_flag, ndlp); 2214 2215 /* We can only defer 1st PLOGI */ 2216 if (ndlp->nlp_defer_did == NLP_EVT_NOTHING_PENDING) 2217 ndlp->nlp_defer_did = did; 2218 return 0; 2219 } 2220 2221 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm)); 2222 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did, 2223 ELS_CMD_PLOGI); 2224 if (!elsiocb) 2225 return 1; 2226 2227 pcmd = (uint8_t *)elsiocb->cmd_dmabuf->virt; 2228 2229 /* For PLOGI request, remainder of payload is service parameters */ 2230 *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI; 2231 pcmd += sizeof(uint32_t); 2232 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm)); 2233 sp = (struct serv_parm *) pcmd; 2234 2235 /* 2236 * If we are a N-port connected to a Fabric, fix-up paramm's so logins 2237 * to device on remote loops work. 2238 */ 2239 if (test_bit(FC_FABRIC, &vport->fc_flag) && 2240 !test_bit(FC_PUBLIC_LOOP, &vport->fc_flag)) 2241 sp->cmn.altBbCredit = 1; 2242 2243 if (sp->cmn.fcphLow < FC_PH_4_3) 2244 sp->cmn.fcphLow = FC_PH_4_3; 2245 2246 if (sp->cmn.fcphHigh < FC_PH3) 2247 sp->cmn.fcphHigh = FC_PH3; 2248 2249 sp->cmn.valid_vendor_ver_level = 0; 2250 memset(sp->un.vendorVersion, 0, sizeof(sp->un.vendorVersion)); 2251 sp->cmn.bbRcvSizeMsb &= 0xF; 2252 2253 /* Check if the destination port supports VMID */ 2254 ndlp->vmid_support = 0; 2255 if (vport->vmid_priority_tagging) 2256 sp->cmn.priority_tagging = 1; 2257 else if (phba->cfg_vmid_app_header && 2258 bf_get(lpfc_ftr_ashdr, &phba->sli4_hba.sli4_flags)) 2259 sp->cmn.app_hdr_support = 1; 2260 2261 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, 2262 "Issue PLOGI: did:x%x", 2263 did, 0, 0); 2264 2265 /* If our firmware supports this feature, convey that 2266 * information to the target using the vendor specific field. 2267 */ 2268 if (phba->sli.sli_flag & LPFC_SLI_SUPPRESS_RSP) { 2269 sp->cmn.valid_vendor_ver_level = 1; 2270 sp->un.vv.vid = cpu_to_be32(LPFC_VV_EMLX_ID); 2271 sp->un.vv.flags = cpu_to_be32(LPFC_VV_SUPPRESS_RSP); 2272 } 2273 2274 phba->fc_stat.elsXmitPLOGI++; 2275 elsiocb->cmd_cmpl = lpfc_cmpl_els_plogi; 2276 2277 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, 2278 "Issue PLOGI: did:x%x refcnt %d", 2279 did, kref_read(&ndlp->kref), 0); 2280 elsiocb->ndlp = lpfc_nlp_get(ndlp); 2281 if (!elsiocb->ndlp) { 2282 lpfc_els_free_iocb(phba, elsiocb); 2283 return 1; 2284 } 2285 2286 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); 2287 if (ret) { 2288 lpfc_els_free_iocb(phba, elsiocb); 2289 lpfc_nlp_put(ndlp); 2290 return 1; 2291 } 2292 2293 return 0; 2294 } 2295 2296 /** 2297 * lpfc_cmpl_els_prli - Completion callback function for prli 2298 * @phba: pointer to lpfc hba data structure. 2299 * @cmdiocb: pointer to lpfc command iocb data structure. 2300 * @rspiocb: pointer to lpfc response iocb data structure. 2301 * 2302 * This routine is the completion callback function for a Process Login 2303 * (PRLI) ELS command. The PRLI response IOCB status is checked for error 2304 * status. If there is error status reported, PRLI retry shall be attempted 2305 * by invoking the lpfc_els_retry() routine. Otherwise, the state 2306 * NLP_EVT_CMPL_PRLI is sent to the Discover State Machine (DSM) for this 2307 * ndlp to mark the PRLI completion. 2308 **/ 2309 static void 2310 lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, 2311 struct lpfc_iocbq *rspiocb) 2312 { 2313 struct lpfc_vport *vport = cmdiocb->vport; 2314 struct lpfc_nodelist *ndlp; 2315 char *mode; 2316 u32 ulp_status; 2317 u32 ulp_word4; 2318 bool release_node = false; 2319 2320 /* we pass cmdiocb to state machine which needs rspiocb as well */ 2321 cmdiocb->rsp_iocb = rspiocb; 2322 2323 ndlp = cmdiocb->ndlp; 2324 2325 ulp_status = get_job_ulpstatus(phba, rspiocb); 2326 ulp_word4 = get_job_word4(phba, rspiocb); 2327 2328 clear_bit(NLP_PRLI_SND, &ndlp->nlp_flag); 2329 2330 /* Driver supports multiple FC4 types. Counters matter. */ 2331 spin_lock_irq(&ndlp->lock); 2332 vport->fc_prli_sent--; 2333 ndlp->fc4_prli_sent--; 2334 spin_unlock_irq(&ndlp->lock); 2335 2336 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, 2337 "PRLI cmpl: status:x%x/x%x did:x%x", 2338 ulp_status, ulp_word4, 2339 ndlp->nlp_DID); 2340 2341 /* PRLI completes to NPort <nlp_DID> */ 2342 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, 2343 "0103 PRLI completes to NPort x%06x " 2344 "Data: x%x x%x x%x x%x x%x\n", 2345 ndlp->nlp_DID, ulp_status, ulp_word4, 2346 vport->num_disc_nodes, ndlp->fc4_prli_sent, 2347 ndlp->fc4_xpt_flags); 2348 2349 /* Check to see if link went down during discovery */ 2350 if (lpfc_els_chk_latt(vport)) 2351 goto out; 2352 2353 if (ulp_status) { 2354 /* Check for retry */ 2355 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) { 2356 /* ELS command is being retried */ 2357 goto out; 2358 } 2359 2360 /* If we don't send GFT_ID to Fabric, a PRLI error 2361 * could be expected. 2362 */ 2363 if (test_bit(FC_FABRIC, &vport->fc_flag) || 2364 vport->cfg_enable_fc4_type != LPFC_ENABLE_BOTH) 2365 mode = KERN_WARNING; 2366 else 2367 mode = KERN_INFO; 2368 2369 /* Warn PRLI status */ 2370 lpfc_printf_vlog(vport, mode, LOG_ELS, 2371 "2754 PRLI DID:%06X Status:x%x/x%x, " 2372 "data: x%x x%x x%lx\n", 2373 ndlp->nlp_DID, ulp_status, 2374 ulp_word4, ndlp->nlp_state, 2375 ndlp->fc4_prli_sent, ndlp->nlp_flag); 2376 2377 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ 2378 if (!lpfc_error_lost_link(vport, ulp_status, ulp_word4)) 2379 lpfc_disc_state_machine(vport, ndlp, cmdiocb, 2380 NLP_EVT_CMPL_PRLI); 2381 2382 /* The following condition catches an inflight transition 2383 * mismatch typically caused by an RSCN. Skip any 2384 * processing to allow recovery. 2385 */ 2386 if ((ndlp->nlp_state >= NLP_STE_PLOGI_ISSUE && 2387 ndlp->nlp_state <= NLP_STE_REG_LOGIN_ISSUE) || 2388 (ndlp->nlp_state == NLP_STE_NPR_NODE && 2389 test_bit(NLP_DELAY_TMO, &ndlp->nlp_flag))) { 2390 lpfc_printf_vlog(vport, KERN_ERR, LOG_NODE, 2391 "2784 PRLI cmpl: Allow Node recovery " 2392 "DID x%06x nstate x%x nflag x%lx\n", 2393 ndlp->nlp_DID, ndlp->nlp_state, 2394 ndlp->nlp_flag); 2395 goto out; 2396 } 2397 2398 /* 2399 * For P2P topology, retain the node so that PLOGI can be 2400 * attempted on it again. 2401 */ 2402 if (test_bit(FC_PT2PT, &vport->fc_flag)) 2403 goto out; 2404 2405 /* As long as this node is not registered with the SCSI 2406 * or NVMe transport and no other PRLIs are outstanding, 2407 * it is no longer an active node. Otherwise devloss 2408 * handles the final cleanup. 2409 */ 2410 spin_lock_irq(&ndlp->lock); 2411 if (!(ndlp->fc4_xpt_flags & (SCSI_XPT_REGD | NVME_XPT_REGD)) && 2412 !ndlp->fc4_prli_sent) { 2413 clear_bit(NLP_NPR_2B_DISC, &ndlp->nlp_flag); 2414 if (!test_bit(NLP_IN_DEV_LOSS, &ndlp->nlp_flag)) 2415 release_node = true; 2416 } 2417 spin_unlock_irq(&ndlp->lock); 2418 2419 if (release_node) 2420 lpfc_disc_state_machine(vport, ndlp, cmdiocb, 2421 NLP_EVT_DEVICE_RM); 2422 } else { 2423 /* Good status, call state machine. However, if another 2424 * PRLI is outstanding, don't call the state machine 2425 * because final disposition to Mapped or Unmapped is 2426 * completed there. 2427 */ 2428 lpfc_disc_state_machine(vport, ndlp, cmdiocb, 2429 NLP_EVT_CMPL_PRLI); 2430 } 2431 2432 out: 2433 lpfc_els_free_iocb(phba, cmdiocb); 2434 lpfc_nlp_put(ndlp); 2435 return; 2436 } 2437 2438 /** 2439 * lpfc_issue_els_prli - Issue a prli iocb command for a vport 2440 * @vport: pointer to a host virtual N_Port data structure. 2441 * @ndlp: pointer to a node-list data structure. 2442 * @retry: number of retries to the command IOCB. 2443 * 2444 * This routine issues a Process Login (PRLI) ELS command for the 2445 * @vport. The PRLI service parameters are set up in the payload of the 2446 * PRLI Request command and the pointer to lpfc_cmpl_els_prli() routine 2447 * is put to the IOCB completion callback func field before invoking the 2448 * routine lpfc_sli_issue_iocb() to send out PRLI command. 2449 * 2450 * Note that the ndlp reference count will be incremented by 1 for holding the 2451 * ndlp and the reference to ndlp will be stored into the ndlp field of 2452 * the IOCB for the completion callback function to the PRLI ELS command. 2453 * 2454 * Return code 2455 * 0 - successfully issued prli iocb command for @vport 2456 * 1 - failed to issue prli iocb command for @vport 2457 **/ 2458 int 2459 lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, 2460 uint8_t retry) 2461 { 2462 int rc = 0; 2463 struct lpfc_hba *phba = vport->phba; 2464 PRLI *npr; 2465 struct lpfc_nvme_prli *npr_nvme; 2466 struct lpfc_iocbq *elsiocb; 2467 uint8_t *pcmd; 2468 uint16_t cmdsize; 2469 u32 local_nlp_type, elscmd; 2470 2471 /* 2472 * If we are in RSCN mode, the FC4 types supported from a 2473 * previous GFT_ID command may not be accurate. So, if we 2474 * are a NVME Initiator, always look for the possibility of 2475 * the remote NPort beng a NVME Target. 2476 */ 2477 if (phba->sli_rev == LPFC_SLI_REV4 && 2478 test_bit(FC_RSCN_MODE, &vport->fc_flag) && 2479 vport->nvmei_support) 2480 ndlp->nlp_fc4_type |= NLP_FC4_NVME; 2481 local_nlp_type = ndlp->nlp_fc4_type; 2482 2483 /* This routine will issue 1 or 2 PRLIs, so zero all the ndlp 2484 * fields here before any of them can complete. 2485 */ 2486 ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR); 2487 ndlp->nlp_type &= ~(NLP_NVME_TARGET | NLP_NVME_INITIATOR); 2488 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE; 2489 clear_bit(NLP_FIRSTBURST, &ndlp->nlp_flag); 2490 clear_bit(NLP_NPR_2B_DISC, &ndlp->nlp_flag); 2491 ndlp->nvme_fb_size = 0; 2492 2493 send_next_prli: 2494 if (local_nlp_type & NLP_FC4_FCP) { 2495 /* Payload is 4 + 16 = 20 x14 bytes. */ 2496 cmdsize = (sizeof(uint32_t) + sizeof(PRLI)); 2497 elscmd = ELS_CMD_PRLI; 2498 } else if (local_nlp_type & NLP_FC4_NVME) { 2499 /* Payload is 4 + 20 = 24 x18 bytes. */ 2500 cmdsize = (sizeof(uint32_t) + sizeof(struct lpfc_nvme_prli)); 2501 elscmd = ELS_CMD_NVMEPRLI; 2502 } else { 2503 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, 2504 "3083 Unknown FC_TYPE x%x ndlp x%06x\n", 2505 ndlp->nlp_fc4_type, ndlp->nlp_DID); 2506 return 1; 2507 } 2508 2509 /* SLI3 ports don't support NVME. If this rport is a strict NVME 2510 * FC4 type, implicitly LOGO. 2511 */ 2512 if (phba->sli_rev == LPFC_SLI_REV3 && 2513 ndlp->nlp_fc4_type == NLP_FC4_NVME) { 2514 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, 2515 "3088 Rport fc4 type 0x%x not supported by SLI3 adapter\n", 2516 ndlp->nlp_type); 2517 lpfc_disc_state_machine(vport, ndlp, NULL, NLP_EVT_DEVICE_RM); 2518 return 1; 2519 } 2520 2521 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, 2522 ndlp->nlp_DID, elscmd); 2523 if (!elsiocb) 2524 return 1; 2525 2526 pcmd = (uint8_t *)elsiocb->cmd_dmabuf->virt; 2527 2528 /* For PRLI request, remainder of payload is service parameters */ 2529 memset(pcmd, 0, cmdsize); 2530 2531 if (local_nlp_type & NLP_FC4_FCP) { 2532 /* Remainder of payload is FCP PRLI parameter page. 2533 * Note: this data structure is defined as 2534 * BE/LE in the structure definition so no 2535 * byte swap call is made. 2536 */ 2537 *((uint32_t *)(pcmd)) = ELS_CMD_PRLI; 2538 pcmd += sizeof(uint32_t); 2539 npr = (PRLI *)pcmd; 2540 2541 /* 2542 * If our firmware version is 3.20 or later, 2543 * set the following bits for FC-TAPE support. 2544 */ 2545 if (phba->vpd.rev.feaLevelHigh >= 0x02) { 2546 npr->ConfmComplAllowed = 1; 2547 npr->Retry = 1; 2548 npr->TaskRetryIdReq = 1; 2549 } 2550 npr->estabImagePair = 1; 2551 npr->readXferRdyDis = 1; 2552 if (vport->cfg_first_burst_size) 2553 npr->writeXferRdyDis = 1; 2554 2555 /* For FCP support */ 2556 npr->prliType = PRLI_FCP_TYPE; 2557 npr->initiatorFunc = 1; 2558 elsiocb->cmd_flag |= LPFC_PRLI_FCP_REQ; 2559 2560 /* Remove FCP type - processed. */ 2561 local_nlp_type &= ~NLP_FC4_FCP; 2562 } else if (local_nlp_type & NLP_FC4_NVME) { 2563 /* Remainder of payload is NVME PRLI parameter page. 2564 * This data structure is the newer definition that 2565 * uses bf macros so a byte swap is required. 2566 */ 2567 *((uint32_t *)(pcmd)) = ELS_CMD_NVMEPRLI; 2568 pcmd += sizeof(uint32_t); 2569 npr_nvme = (struct lpfc_nvme_prli *)pcmd; 2570 bf_set(prli_type_code, npr_nvme, PRLI_NVME_TYPE); 2571 bf_set(prli_estabImagePair, npr_nvme, 0); /* Should be 0 */ 2572 if (phba->nsler) { 2573 bf_set(prli_nsler, npr_nvme, 1); 2574 bf_set(prli_conf, npr_nvme, 1); 2575 } 2576 2577 /* Only initiators request first burst. */ 2578 if ((phba->cfg_nvme_enable_fb) && 2579 !phba->nvmet_support) 2580 bf_set(prli_fba, npr_nvme, 1); 2581 2582 if (phba->nvmet_support) { 2583 bf_set(prli_tgt, npr_nvme, 1); 2584 bf_set(prli_disc, npr_nvme, 1); 2585 } else { 2586 bf_set(prli_init, npr_nvme, 1); 2587 bf_set(prli_conf, npr_nvme, 1); 2588 } 2589 2590 npr_nvme->word1 = cpu_to_be32(npr_nvme->word1); 2591 npr_nvme->word4 = cpu_to_be32(npr_nvme->word4); 2592 elsiocb->cmd_flag |= LPFC_PRLI_NVME_REQ; 2593 2594 /* Remove NVME type - processed. */ 2595 local_nlp_type &= ~NLP_FC4_NVME; 2596 } 2597 2598 phba->fc_stat.elsXmitPRLI++; 2599 elsiocb->cmd_cmpl = lpfc_cmpl_els_prli; 2600 2601 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, 2602 "Issue PRLI: did:x%x refcnt %d", 2603 ndlp->nlp_DID, kref_read(&ndlp->kref), 0); 2604 elsiocb->ndlp = lpfc_nlp_get(ndlp); 2605 if (!elsiocb->ndlp) { 2606 lpfc_els_free_iocb(phba, elsiocb); 2607 return 1; 2608 } 2609 2610 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); 2611 if (rc == IOCB_ERROR) { 2612 lpfc_els_free_iocb(phba, elsiocb); 2613 lpfc_nlp_put(ndlp); 2614 return 1; 2615 } 2616 2617 /* The vport counters are used for lpfc_scan_finished, but 2618 * the ndlp is used to track outstanding PRLIs for different 2619 * FC4 types. 2620 */ 2621 set_bit(NLP_PRLI_SND, &ndlp->nlp_flag); 2622 spin_lock_irq(&ndlp->lock); 2623 vport->fc_prli_sent++; 2624 ndlp->fc4_prli_sent++; 2625 spin_unlock_irq(&ndlp->lock); 2626 2627 /* The driver supports 2 FC4 types. Make sure 2628 * a PRLI is issued for all types before exiting. 2629 */ 2630 if (phba->sli_rev == LPFC_SLI_REV4 && 2631 local_nlp_type & (NLP_FC4_FCP | NLP_FC4_NVME)) 2632 goto send_next_prli; 2633 else 2634 return 0; 2635 } 2636 2637 /** 2638 * lpfc_rscn_disc - Perform rscn discovery for a vport 2639 * @vport: pointer to a host virtual N_Port data structure. 2640 * 2641 * This routine performs Registration State Change Notification (RSCN) 2642 * discovery for a @vport. If the @vport's node port recovery count is not 2643 * zero, it will invoke the lpfc_els_disc_plogi() to perform PLOGI for all 2644 * the nodes that need recovery. If none of the PLOGI were needed through 2645 * the lpfc_els_disc_plogi() routine, the lpfc_end_rscn() routine shall be 2646 * invoked to check and handle possible more RSCN came in during the period 2647 * of processing the current ones. 2648 **/ 2649 static void 2650 lpfc_rscn_disc(struct lpfc_vport *vport) 2651 { 2652 lpfc_can_disctmo(vport); 2653 2654 /* RSCN discovery */ 2655 /* go thru NPR nodes and issue ELS PLOGIs */ 2656 if (atomic_read(&vport->fc_npr_cnt)) 2657 if (lpfc_els_disc_plogi(vport)) 2658 return; 2659 2660 lpfc_end_rscn(vport); 2661 } 2662 2663 /** 2664 * lpfc_adisc_done - Complete the adisc phase of discovery 2665 * @vport: pointer to lpfc_vport hba data structure that finished all ADISCs. 2666 * 2667 * This function is called when the final ADISC is completed during discovery. 2668 * This function handles clearing link attention or issuing reg_vpi depending 2669 * on whether npiv is enabled. This function also kicks off the PLOGI phase of 2670 * discovery. 2671 * This function is called with no locks held. 2672 **/ 2673 static void 2674 lpfc_adisc_done(struct lpfc_vport *vport) 2675 { 2676 struct lpfc_hba *phba = vport->phba; 2677 2678 /* 2679 * For NPIV, cmpl_reg_vpi will set port_state to READY, 2680 * and continue discovery. 2681 */ 2682 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && 2683 !test_bit(FC_RSCN_MODE, &vport->fc_flag) && 2684 (phba->sli_rev < LPFC_SLI_REV4)) { 2685 2686 /* 2687 * If link is down, clear_la and reg_vpi will be done after 2688 * flogi following a link up event 2689 */ 2690 if (!lpfc_is_link_up(phba)) 2691 return; 2692 2693 /* The ADISCs are complete. Doesn't matter if they 2694 * succeeded or failed because the ADISC completion 2695 * routine guarantees to call the state machine and 2696 * the RPI is either unregistered (failed ADISC response) 2697 * or the RPI is still valid and the node is marked 2698 * mapped for a target. The exchanges should be in the 2699 * correct state. This code is specific to SLI3. 2700 */ 2701 lpfc_issue_clear_la(phba, vport); 2702 lpfc_issue_reg_vpi(phba, vport); 2703 return; 2704 } 2705 /* 2706 * For SLI2, we need to set port_state to READY 2707 * and continue discovery. 2708 */ 2709 if (vport->port_state < LPFC_VPORT_READY) { 2710 /* If we get here, there is nothing to ADISC */ 2711 lpfc_issue_clear_la(phba, vport); 2712 if (!test_bit(FC_ABORT_DISCOVERY, &vport->fc_flag)) { 2713 vport->num_disc_nodes = 0; 2714 /* go thru NPR list, issue ELS PLOGIs */ 2715 if (atomic_read(&vport->fc_npr_cnt)) 2716 lpfc_els_disc_plogi(vport); 2717 if (!vport->num_disc_nodes) { 2718 clear_bit(FC_NDISC_ACTIVE, &vport->fc_flag); 2719 lpfc_can_disctmo(vport); 2720 lpfc_end_rscn(vport); 2721 } 2722 } 2723 vport->port_state = LPFC_VPORT_READY; 2724 } else 2725 lpfc_rscn_disc(vport); 2726 } 2727 2728 /** 2729 * lpfc_more_adisc - Issue more adisc as needed 2730 * @vport: pointer to a host virtual N_Port data structure. 2731 * 2732 * This routine determines whether there are more ndlps on a @vport 2733 * node list need to have Address Discover (ADISC) issued. If so, it will 2734 * invoke the lpfc_els_disc_adisc() routine to issue ADISC on the @vport's 2735 * remaining nodes which need to have ADISC sent. 2736 **/ 2737 void 2738 lpfc_more_adisc(struct lpfc_vport *vport) 2739 { 2740 if (vport->num_disc_nodes) 2741 vport->num_disc_nodes--; 2742 /* Continue discovery with <num_disc_nodes> ADISCs to go */ 2743 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, 2744 "0210 Continue discovery with %d ADISCs to go " 2745 "Data: x%x x%lx x%x\n", 2746 vport->num_disc_nodes, 2747 atomic_read(&vport->fc_adisc_cnt), 2748 vport->fc_flag, vport->port_state); 2749 /* Check to see if there are more ADISCs to be sent */ 2750 if (test_bit(FC_NLP_MORE, &vport->fc_flag)) { 2751 lpfc_set_disctmo(vport); 2752 /* go thru NPR nodes and issue any remaining ELS ADISCs */ 2753 lpfc_els_disc_adisc(vport); 2754 } 2755 if (!vport->num_disc_nodes) 2756 lpfc_adisc_done(vport); 2757 return; 2758 } 2759 2760 /** 2761 * lpfc_cmpl_els_adisc - Completion callback function for adisc 2762 * @phba: pointer to lpfc hba data structure. 2763 * @cmdiocb: pointer to lpfc command iocb data structure. 2764 * @rspiocb: pointer to lpfc response iocb data structure. 2765 * 2766 * This routine is the completion function for issuing the Address Discover 2767 * (ADISC) command. It first checks to see whether link went down during 2768 * the discovery process. If so, the node will be marked as node port 2769 * recovery for issuing discover IOCB by the link attention handler and 2770 * exit. Otherwise, the response status is checked. If error was reported 2771 * in the response status, the ADISC command shall be retried by invoking 2772 * the lpfc_els_retry() routine. Otherwise, if no error was reported in 2773 * the response status, the state machine is invoked to set transition 2774 * with respect to NLP_EVT_CMPL_ADISC event. 2775 **/ 2776 static void 2777 lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, 2778 struct lpfc_iocbq *rspiocb) 2779 { 2780 struct lpfc_vport *vport = cmdiocb->vport; 2781 IOCB_t *irsp; 2782 struct lpfc_nodelist *ndlp; 2783 bool disc; 2784 u32 ulp_status, ulp_word4, tmo, iotag; 2785 bool release_node = false; 2786 2787 /* we pass cmdiocb to state machine which needs rspiocb as well */ 2788 cmdiocb->rsp_iocb = rspiocb; 2789 2790 ndlp = cmdiocb->ndlp; 2791 2792 ulp_status = get_job_ulpstatus(phba, rspiocb); 2793 ulp_word4 = get_job_word4(phba, rspiocb); 2794 2795 if (phba->sli_rev == LPFC_SLI_REV4) { 2796 tmo = get_wqe_tmo(cmdiocb); 2797 iotag = get_wqe_reqtag(cmdiocb); 2798 } else { 2799 irsp = &rspiocb->iocb; 2800 tmo = irsp->ulpTimeout; 2801 iotag = irsp->ulpIoTag; 2802 } 2803 2804 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, 2805 "ADISC cmpl: status:x%x/x%x did:x%x", 2806 ulp_status, ulp_word4, 2807 ndlp->nlp_DID); 2808 2809 /* Since ndlp can be freed in the disc state machine, note if this node 2810 * is being used during discovery. 2811 */ 2812 disc = test_and_clear_bit(NLP_NPR_2B_DISC, &ndlp->nlp_flag); 2813 clear_bit(NLP_ADISC_SND, &ndlp->nlp_flag); 2814 /* ADISC completes to NPort <nlp_DID> */ 2815 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, 2816 "0104 ADISC completes to NPort x%x " 2817 "IoTag x%x Data: x%x x%x x%x x%x x%x\n", 2818 ndlp->nlp_DID, iotag, 2819 ulp_status, ulp_word4, 2820 tmo, disc, vport->num_disc_nodes); 2821 2822 /* Check to see if link went down during discovery */ 2823 if (lpfc_els_chk_latt(vport)) { 2824 set_bit(NLP_NPR_2B_DISC, &ndlp->nlp_flag); 2825 goto out; 2826 } 2827 2828 if (ulp_status) { 2829 /* Check for retry */ 2830 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) { 2831 /* ELS command is being retried */ 2832 if (disc) { 2833 set_bit(NLP_NPR_2B_DISC, &ndlp->nlp_flag); 2834 lpfc_set_disctmo(vport); 2835 } 2836 goto out; 2837 } 2838 /* Warn ADISC status */ 2839 lpfc_vlog_msg(vport, KERN_WARNING, LOG_ELS, 2840 "2755 ADISC DID:%06X Status:x%x/x%x\n", 2841 ndlp->nlp_DID, ulp_status, 2842 ulp_word4); 2843 lpfc_disc_state_machine(vport, ndlp, cmdiocb, 2844 NLP_EVT_CMPL_ADISC); 2845 2846 /* As long as this node is not registered with the SCSI or NVMe 2847 * transport, it is no longer an active node. Otherwise 2848 * devloss handles the final cleanup. 2849 */ 2850 spin_lock_irq(&ndlp->lock); 2851 if (!(ndlp->fc4_xpt_flags & (SCSI_XPT_REGD | NVME_XPT_REGD))) { 2852 clear_bit(NLP_NPR_2B_DISC, &ndlp->nlp_flag); 2853 if (!test_bit(NLP_IN_DEV_LOSS, &ndlp->nlp_flag)) 2854 release_node = true; 2855 } 2856 spin_unlock_irq(&ndlp->lock); 2857 2858 if (release_node) 2859 lpfc_disc_state_machine(vport, ndlp, cmdiocb, 2860 NLP_EVT_DEVICE_RM); 2861 } else 2862 /* Good status, call state machine */ 2863 lpfc_disc_state_machine(vport, ndlp, cmdiocb, 2864 NLP_EVT_CMPL_ADISC); 2865 2866 /* Check to see if there are more ADISCs to be sent */ 2867 if (disc && vport->num_disc_nodes) 2868 lpfc_more_adisc(vport); 2869 out: 2870 lpfc_els_free_iocb(phba, cmdiocb); 2871 lpfc_nlp_put(ndlp); 2872 return; 2873 } 2874 2875 /** 2876 * lpfc_issue_els_adisc - Issue an address discover iocb to an node on a vport 2877 * @vport: pointer to a virtual N_Port data structure. 2878 * @ndlp: pointer to a node-list data structure. 2879 * @retry: number of retries to the command IOCB. 2880 * 2881 * This routine issues an Address Discover (ADISC) for an @ndlp on a 2882 * @vport. It prepares the payload of the ADISC ELS command, updates the 2883 * and states of the ndlp, and invokes the lpfc_sli_issue_iocb() routine 2884 * to issue the ADISC ELS command. 2885 * 2886 * Note that the ndlp reference count will be incremented by 1 for holding the 2887 * ndlp and the reference to ndlp will be stored into the ndlp field of 2888 * the IOCB for the completion callback function to the ADISC ELS command. 2889 * 2890 * Return code 2891 * 0 - successfully issued adisc 2892 * 1 - failed to issue adisc 2893 **/ 2894 int 2895 lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, 2896 uint8_t retry) 2897 { 2898 int rc = 0; 2899 struct lpfc_hba *phba = vport->phba; 2900 ADISC *ap; 2901 struct lpfc_iocbq *elsiocb; 2902 uint8_t *pcmd; 2903 uint16_t cmdsize; 2904 2905 cmdsize = (sizeof(uint32_t) + sizeof(ADISC)); 2906 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, 2907 ndlp->nlp_DID, ELS_CMD_ADISC); 2908 if (!elsiocb) 2909 return 1; 2910 2911 pcmd = (uint8_t *)elsiocb->cmd_dmabuf->virt; 2912 2913 /* For ADISC request, remainder of payload is service parameters */ 2914 *((uint32_t *) (pcmd)) = ELS_CMD_ADISC; 2915 pcmd += sizeof(uint32_t); 2916 2917 /* Fill in ADISC payload */ 2918 ap = (ADISC *) pcmd; 2919 ap->hardAL_PA = phba->fc_pref_ALPA; 2920 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name)); 2921 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); 2922 ap->DID = be32_to_cpu(vport->fc_myDID); 2923 2924 phba->fc_stat.elsXmitADISC++; 2925 elsiocb->cmd_cmpl = lpfc_cmpl_els_adisc; 2926 set_bit(NLP_ADISC_SND, &ndlp->nlp_flag); 2927 elsiocb->ndlp = lpfc_nlp_get(ndlp); 2928 if (!elsiocb->ndlp) { 2929 lpfc_els_free_iocb(phba, elsiocb); 2930 goto err; 2931 } 2932 2933 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, 2934 "Issue ADISC: did:x%x refcnt %d", 2935 ndlp->nlp_DID, kref_read(&ndlp->kref), 0); 2936 2937 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); 2938 if (rc == IOCB_ERROR) { 2939 lpfc_els_free_iocb(phba, elsiocb); 2940 lpfc_nlp_put(ndlp); 2941 goto err; 2942 } 2943 2944 return 0; 2945 2946 err: 2947 clear_bit(NLP_ADISC_SND, &ndlp->nlp_flag); 2948 return 1; 2949 } 2950 2951 /** 2952 * lpfc_cmpl_els_logo - Completion callback function for logo 2953 * @phba: pointer to lpfc hba data structure. 2954 * @cmdiocb: pointer to lpfc command iocb data structure. 2955 * @rspiocb: pointer to lpfc response iocb data structure. 2956 * 2957 * This routine is the completion function for issuing the ELS Logout (LOGO) 2958 * command. If no error status was reported from the LOGO response, the 2959 * state machine of the associated ndlp shall be invoked for transition with 2960 * respect to NLP_EVT_CMPL_LOGO event. 2961 **/ 2962 static void 2963 lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, 2964 struct lpfc_iocbq *rspiocb) 2965 { 2966 struct lpfc_nodelist *ndlp = cmdiocb->ndlp; 2967 struct lpfc_vport *vport = ndlp->vport; 2968 IOCB_t *irsp; 2969 uint32_t skip_recovery = 0; 2970 int wake_up_waiter = 0; 2971 u32 ulp_status; 2972 u32 ulp_word4; 2973 u32 tmo, iotag; 2974 2975 /* we pass cmdiocb to state machine which needs rspiocb as well */ 2976 cmdiocb->rsp_iocb = rspiocb; 2977 2978 ulp_status = get_job_ulpstatus(phba, rspiocb); 2979 ulp_word4 = get_job_word4(phba, rspiocb); 2980 2981 if (phba->sli_rev == LPFC_SLI_REV4) { 2982 tmo = get_wqe_tmo(cmdiocb); 2983 iotag = get_wqe_reqtag(cmdiocb); 2984 } else { 2985 irsp = &rspiocb->iocb; 2986 tmo = irsp->ulpTimeout; 2987 iotag = irsp->ulpIoTag; 2988 } 2989 2990 clear_bit(NLP_LOGO_SND, &ndlp->nlp_flag); 2991 if (test_and_clear_bit(NLP_WAIT_FOR_LOGO, &ndlp->save_flags)) 2992 wake_up_waiter = 1; 2993 2994 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, 2995 "LOGO cmpl: status:x%x/x%x did:x%x", 2996 ulp_status, ulp_word4, 2997 ndlp->nlp_DID); 2998 2999 /* LOGO completes to NPort <nlp_DID> */ 3000 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, 3001 "0105 LOGO completes to NPort x%x " 3002 "IoTag x%x refcnt %d nflags x%lx xflags x%x " 3003 "Data: x%x x%x x%x x%x\n", 3004 ndlp->nlp_DID, iotag, 3005 kref_read(&ndlp->kref), ndlp->nlp_flag, 3006 ndlp->fc4_xpt_flags, ulp_status, ulp_word4, 3007 tmo, vport->num_disc_nodes); 3008 3009 if (lpfc_els_chk_latt(vport)) { 3010 skip_recovery = 1; 3011 goto out; 3012 } 3013 3014 /* The LOGO will not be retried on failure. A LOGO was 3015 * issued to the remote rport and a ACC or RJT or no Answer are 3016 * all acceptable. Note the failure and move forward with 3017 * discovery. The PLOGI will retry. 3018 */ 3019 if (ulp_status) { 3020 /* Warn LOGO status */ 3021 lpfc_vlog_msg(vport, KERN_WARNING, LOG_ELS, 3022 "2756 LOGO, No Retry DID:%06X " 3023 "Status:x%x/x%x\n", 3024 ndlp->nlp_DID, ulp_status, 3025 ulp_word4); 3026 3027 if (lpfc_error_lost_link(vport, ulp_status, ulp_word4)) 3028 skip_recovery = 1; 3029 } 3030 3031 /* Call state machine. This will unregister the rpi if needed. */ 3032 lpfc_disc_state_machine(vport, ndlp, cmdiocb, NLP_EVT_CMPL_LOGO); 3033 3034 out: 3035 /* At this point, the LOGO processing is complete. NOTE: For a 3036 * pt2pt topology, we are assuming the NPortID will only change 3037 * on link up processing. For a LOGO / PLOGI initiated by the 3038 * Initiator, we are assuming the NPortID is not going to change. 3039 */ 3040 3041 if (wake_up_waiter && ndlp->logo_waitq) 3042 wake_up(ndlp->logo_waitq); 3043 /* 3044 * If the node is a target, the handling attempts to recover the port. 3045 * For any other port type, the rpi is unregistered as an implicit 3046 * LOGO. 3047 */ 3048 if (ndlp->nlp_type & (NLP_FCP_TARGET | NLP_NVME_TARGET) && 3049 skip_recovery == 0) { 3050 lpfc_cancel_retry_delay_tmo(vport, ndlp); 3051 set_bit(NLP_NPR_2B_DISC, &ndlp->nlp_flag); 3052 3053 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, 3054 "3187 LOGO completes to NPort x%x: Start " 3055 "Recovery Data: x%x x%x x%x x%x\n", 3056 ndlp->nlp_DID, ulp_status, 3057 ulp_word4, tmo, 3058 vport->num_disc_nodes); 3059 3060 lpfc_els_free_iocb(phba, cmdiocb); 3061 lpfc_nlp_put(ndlp); 3062 3063 lpfc_disc_start(vport); 3064 return; 3065 } 3066 3067 /* Cleanup path for failed REG_RPI handling. If REG_RPI fails, the 3068 * driver sends a LOGO to the rport to cleanup. For fabric and 3069 * initiator ports cleanup the node as long as it the node is not 3070 * register with the transport. 3071 */ 3072 if (!(ndlp->fc4_xpt_flags & (SCSI_XPT_REGD | NVME_XPT_REGD))) { 3073 clear_bit(NLP_NPR_2B_DISC, &ndlp->nlp_flag); 3074 lpfc_disc_state_machine(vport, ndlp, cmdiocb, 3075 NLP_EVT_DEVICE_RM); 3076 } 3077 3078 /* Driver is done with the I/O. */ 3079 lpfc_els_free_iocb(phba, cmdiocb); 3080 lpfc_nlp_put(ndlp); 3081 } 3082 3083 /** 3084 * lpfc_issue_els_logo - Issue a logo to an node on a vport 3085 * @vport: pointer to a virtual N_Port data structure. 3086 * @ndlp: pointer to a node-list data structure. 3087 * @retry: number of retries to the command IOCB. 3088 * 3089 * This routine constructs and issues an ELS Logout (LOGO) iocb command 3090 * to a remote node, referred by an @ndlp on a @vport. It constructs the 3091 * payload of the IOCB, properly sets up the @ndlp state, and invokes the 3092 * lpfc_sli_issue_iocb() routine to send out the LOGO ELS command. 3093 * 3094 * Note that the ndlp reference count will be incremented by 1 for holding the 3095 * ndlp and the reference to ndlp will be stored into the ndlp field of 3096 * the IOCB for the completion callback function to the LOGO ELS command. 3097 * 3098 * Callers of this routine are expected to unregister the RPI first 3099 * 3100 * Return code 3101 * 0 - successfully issued logo 3102 * 1 - failed to issue logo 3103 **/ 3104 int 3105 lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, 3106 uint8_t retry) 3107 { 3108 struct lpfc_hba *phba = vport->phba; 3109 struct lpfc_iocbq *elsiocb; 3110 uint8_t *pcmd; 3111 uint16_t cmdsize; 3112 int rc; 3113 3114 if (test_bit(NLP_LOGO_SND, &ndlp->nlp_flag)) 3115 return 0; 3116 3117 cmdsize = (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name); 3118 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, 3119 ndlp->nlp_DID, ELS_CMD_LOGO); 3120 if (!elsiocb) 3121 return 1; 3122 3123 pcmd = (uint8_t *)elsiocb->cmd_dmabuf->virt; 3124 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO; 3125 pcmd += sizeof(uint32_t); 3126 3127 /* Fill in LOGO payload */ 3128 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID); 3129 pcmd += sizeof(uint32_t); 3130 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name)); 3131 3132 phba->fc_stat.elsXmitLOGO++; 3133 elsiocb->cmd_cmpl = lpfc_cmpl_els_logo; 3134 set_bit(NLP_LOGO_SND, &ndlp->nlp_flag); 3135 clear_bit(NLP_ISSUE_LOGO, &ndlp->nlp_flag); 3136 elsiocb->ndlp = lpfc_nlp_get(ndlp); 3137 if (!elsiocb->ndlp) { 3138 lpfc_els_free_iocb(phba, elsiocb); 3139 goto err; 3140 } 3141 3142 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, 3143 "Issue LOGO: did:x%x refcnt %d", 3144 ndlp->nlp_DID, kref_read(&ndlp->kref), 0); 3145 3146 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); 3147 if (rc == IOCB_ERROR) { 3148 lpfc_els_free_iocb(phba, elsiocb); 3149 lpfc_nlp_put(ndlp); 3150 goto err; 3151 } 3152 3153 spin_lock_irq(&ndlp->lock); 3154 ndlp->nlp_prev_state = ndlp->nlp_state; 3155 spin_unlock_irq(&ndlp->lock); 3156 lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE); 3157 return 0; 3158 3159 err: 3160 clear_bit(NLP_LOGO_SND, &ndlp->nlp_flag); 3161 return 1; 3162 } 3163 3164 /** 3165 * lpfc_cmpl_els_cmd - Completion callback function for generic els command 3166 * @phba: pointer to lpfc hba data structure. 3167 * @cmdiocb: pointer to lpfc command iocb data structure. 3168 * @rspiocb: pointer to lpfc response iocb data structure. 3169 * 3170 * This routine is a generic completion callback function for ELS commands. 3171 * Specifically, it is the callback function which does not need to perform 3172 * any command specific operations. It is currently used by the ELS command 3173 * issuing routines for RSCN, lpfc_issue_els_rscn, and the ELS Fibre Channel 3174 * Address Resolution Protocol Response (FARPR) routine, lpfc_issue_els_farpr(). 3175 * Other than certain debug loggings, this callback function simply invokes the 3176 * lpfc_els_chk_latt() routine to check whether link went down during the 3177 * discovery process. 3178 **/ 3179 static void 3180 lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, 3181 struct lpfc_iocbq *rspiocb) 3182 { 3183 struct lpfc_vport *vport = cmdiocb->vport; 3184 struct lpfc_nodelist *free_ndlp; 3185 IOCB_t *irsp; 3186 u32 ulp_status, ulp_word4, tmo, did, iotag; 3187 3188 ulp_status = get_job_ulpstatus(phba, rspiocb); 3189 ulp_word4 = get_job_word4(phba, rspiocb); 3190 did = get_job_els_rsp64_did(phba, cmdiocb); 3191 3192 if (phba->sli_rev == LPFC_SLI_REV4) { 3193 tmo = get_wqe_tmo(cmdiocb); 3194 iotag = get_wqe_reqtag(cmdiocb); 3195 } else { 3196 irsp = &rspiocb->iocb; 3197 tmo = irsp->ulpTimeout; 3198 iotag = irsp->ulpIoTag; 3199 } 3200 3201 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, 3202 "ELS cmd cmpl: status:x%x/x%x did:x%x", 3203 ulp_status, ulp_word4, did); 3204 3205 /* ELS cmd tag <ulpIoTag> completes */ 3206 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, 3207 "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n", 3208 iotag, ulp_status, ulp_word4, tmo); 3209 3210 /* Check to see if link went down during discovery */ 3211 lpfc_els_chk_latt(vport); 3212 3213 free_ndlp = cmdiocb->ndlp; 3214 3215 lpfc_els_free_iocb(phba, cmdiocb); 3216 lpfc_nlp_put(free_ndlp); 3217 } 3218 3219 /** 3220 * lpfc_reg_fab_ctrl_node - RPI register the fabric controller node. 3221 * @vport: pointer to lpfc_vport data structure. 3222 * @fc_ndlp: pointer to the fabric controller (0xfffffd) node. 3223 * 3224 * This routine registers the rpi assigned to the fabric controller 3225 * NPort_ID (0xfffffd) with the port and moves the node to UNMAPPED 3226 * state triggering a registration with the SCSI transport. 3227 * 3228 * This routine is single out because the fabric controller node 3229 * does not receive a PLOGI. This routine is consumed by the 3230 * SCR and RDF ELS commands. Callers are expected to qualify 3231 * with SLI4 first. 3232 **/ 3233 static int 3234 lpfc_reg_fab_ctrl_node(struct lpfc_vport *vport, struct lpfc_nodelist *fc_ndlp) 3235 { 3236 int rc; 3237 struct lpfc_hba *phba = vport->phba; 3238 struct lpfc_nodelist *ns_ndlp; 3239 LPFC_MBOXQ_t *mbox; 3240 3241 if (test_bit(NLP_RPI_REGISTERED, &fc_ndlp->nlp_flag)) 3242 return 0; 3243 3244 ns_ndlp = lpfc_findnode_did(vport, NameServer_DID); 3245 if (!ns_ndlp) 3246 return -ENODEV; 3247 3248 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, 3249 "0935 %s: Reg FC RPI x%x on FC DID x%x NSSte: x%x\n", 3250 __func__, fc_ndlp->nlp_rpi, fc_ndlp->nlp_DID, 3251 ns_ndlp->nlp_state); 3252 if (ns_ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) 3253 return -ENODEV; 3254 3255 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); 3256 if (!mbox) { 3257 lpfc_printf_vlog(vport, KERN_ERR, LOG_NODE, 3258 "0936 %s: no memory for reg_login " 3259 "Data: x%x x%x x%lx x%x\n", __func__, 3260 fc_ndlp->nlp_DID, fc_ndlp->nlp_state, 3261 fc_ndlp->nlp_flag, fc_ndlp->nlp_rpi); 3262 return -ENOMEM; 3263 } 3264 rc = lpfc_reg_rpi(phba, vport->vpi, fc_ndlp->nlp_DID, 3265 (u8 *)&vport->fc_sparam, mbox, fc_ndlp->nlp_rpi); 3266 if (rc) { 3267 rc = -EACCES; 3268 goto out; 3269 } 3270 3271 set_bit(NLP_REG_LOGIN_SEND, &fc_ndlp->nlp_flag); 3272 mbox->mbox_cmpl = lpfc_mbx_cmpl_fc_reg_login; 3273 mbox->ctx_ndlp = lpfc_nlp_get(fc_ndlp); 3274 if (!mbox->ctx_ndlp) { 3275 rc = -ENOMEM; 3276 goto out; 3277 } 3278 3279 mbox->vport = vport; 3280 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); 3281 if (rc == MBX_NOT_FINISHED) { 3282 rc = -ENODEV; 3283 lpfc_nlp_put(fc_ndlp); 3284 goto out; 3285 } 3286 /* Success path. Exit. */ 3287 lpfc_nlp_set_state(vport, fc_ndlp, 3288 NLP_STE_REG_LOGIN_ISSUE); 3289 return 0; 3290 3291 out: 3292 lpfc_mbox_rsrc_cleanup(phba, mbox, MBOX_THD_UNLOCKED); 3293 lpfc_printf_vlog(vport, KERN_ERR, LOG_NODE, 3294 "0938 %s: failed to format reg_login " 3295 "Data: x%x x%x x%lx x%x\n", __func__, 3296 fc_ndlp->nlp_DID, fc_ndlp->nlp_state, 3297 fc_ndlp->nlp_flag, fc_ndlp->nlp_rpi); 3298 return rc; 3299 } 3300 3301 /** 3302 * lpfc_cmpl_els_disc_cmd - Completion callback function for Discovery ELS cmd 3303 * @phba: pointer to lpfc hba data structure. 3304 * @cmdiocb: pointer to lpfc command iocb data structure. 3305 * @rspiocb: pointer to lpfc response iocb data structure. 3306 * 3307 * This routine is a generic completion callback function for Discovery ELS cmd. 3308 * Currently used by the ELS command issuing routines for the ELS State Change 3309 * Request (SCR), lpfc_issue_els_scr() and the ELS RDF, lpfc_issue_els_rdf(). 3310 * These commands will be retried once only for ELS timeout errors. 3311 **/ 3312 static void 3313 lpfc_cmpl_els_disc_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, 3314 struct lpfc_iocbq *rspiocb) 3315 { 3316 struct lpfc_vport *vport = cmdiocb->vport; 3317 IOCB_t *irsp; 3318 struct lpfc_els_rdf_rsp *prdf; 3319 struct lpfc_dmabuf *pcmd, *prsp; 3320 u32 *pdata; 3321 u32 cmd; 3322 struct lpfc_nodelist *ndlp = cmdiocb->ndlp; 3323 u32 ulp_status, ulp_word4, tmo, did, iotag; 3324 3325 ulp_status = get_job_ulpstatus(phba, rspiocb); 3326 ulp_word4 = get_job_word4(phba, rspiocb); 3327 did = get_job_els_rsp64_did(phba, cmdiocb); 3328 3329 if (phba->sli_rev == LPFC_SLI_REV4) { 3330 tmo = get_wqe_tmo(cmdiocb); 3331 iotag = get_wqe_reqtag(cmdiocb); 3332 } else { 3333 irsp = &rspiocb->iocb; 3334 tmo = irsp->ulpTimeout; 3335 iotag = irsp->ulpIoTag; 3336 } 3337 3338 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, 3339 "ELS cmd cmpl: status:x%x/x%x did:x%x", 3340 ulp_status, ulp_word4, did); 3341 3342 /* ELS cmd tag <ulpIoTag> completes */ 3343 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS | LOG_CGN_MGMT, 3344 "0217 ELS cmd tag x%x completes Data: x%x x%x x%x x%x\n", 3345 iotag, ulp_status, ulp_word4, tmo, cmdiocb->retry); 3346 3347 pcmd = cmdiocb->cmd_dmabuf; 3348 if (!pcmd) 3349 goto out; 3350 3351 pdata = (u32 *)pcmd->virt; 3352 if (!pdata) 3353 goto out; 3354 cmd = *pdata; 3355 3356 /* Only 1 retry for ELS Timeout only */ 3357 if (ulp_status == IOSTAT_LOCAL_REJECT && 3358 ((ulp_word4 & IOERR_PARAM_MASK) == 3359 IOERR_SEQUENCE_TIMEOUT)) { 3360 cmdiocb->retry++; 3361 if (cmdiocb->retry <= 1) { 3362 switch (cmd) { 3363 case ELS_CMD_SCR: 3364 lpfc_issue_els_scr(vport, cmdiocb->retry); 3365 break; 3366 case ELS_CMD_EDC: 3367 lpfc_issue_els_edc(vport, cmdiocb->retry); 3368 break; 3369 case ELS_CMD_RDF: 3370 lpfc_issue_els_rdf(vport, cmdiocb->retry); 3371 break; 3372 } 3373 goto out; 3374 } 3375 phba->fc_stat.elsRetryExceeded++; 3376 } 3377 if (cmd == ELS_CMD_EDC) { 3378 /* must be called before checking uplStatus and returning */ 3379 lpfc_cmpl_els_edc(phba, cmdiocb, rspiocb); 3380 return; 3381 } 3382 if (ulp_status) { 3383 /* ELS discovery cmd completes with error */ 3384 lpfc_printf_vlog(vport, KERN_WARNING, LOG_ELS | LOG_CGN_MGMT, 3385 "4203 ELS cmd x%x error: x%x x%X\n", cmd, 3386 ulp_status, ulp_word4); 3387 goto out; 3388 } 3389 3390 /* The RDF response doesn't have any impact on the running driver 3391 * but the notification descriptors are dumped here for support. 3392 */ 3393 if (cmd == ELS_CMD_RDF) { 3394 int i; 3395 3396 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list); 3397 if (!prsp) 3398 goto out; 3399 3400 prdf = (struct lpfc_els_rdf_rsp *)prsp->virt; 3401 if (!prdf) 3402 goto out; 3403 if (!lpfc_is_els_acc_rsp(prsp)) 3404 goto out; 3405 3406 for (i = 0; i < ELS_RDF_REG_TAG_CNT && 3407 i < be32_to_cpu(prdf->reg_d1.reg_desc.count); i++) 3408 lpfc_printf_vlog(vport, KERN_INFO, 3409 LOG_ELS | LOG_CGN_MGMT, 3410 "4677 Fabric RDF Notification Grant " 3411 "Data: 0x%08x Reg: %x %x\n", 3412 be32_to_cpu( 3413 prdf->reg_d1.desc_tags[i]), 3414 phba->cgn_reg_signal, 3415 phba->cgn_reg_fpin); 3416 } 3417 3418 out: 3419 /* Check to see if link went down during discovery */ 3420 lpfc_els_chk_latt(vport); 3421 lpfc_els_free_iocb(phba, cmdiocb); 3422 lpfc_nlp_put(ndlp); 3423 return; 3424 } 3425 3426 /** 3427 * lpfc_issue_els_scr - Issue a scr to an node on a vport 3428 * @vport: pointer to a host virtual N_Port data structure. 3429 * @retry: retry counter for the command IOCB. 3430 * 3431 * This routine issues a State Change Request (SCR) to a fabric node 3432 * on a @vport. The remote node is Fabric Controller (0xfffffd). It 3433 * first search the @vport node list to find the matching ndlp. If no such 3434 * ndlp is found, a new ndlp shall be created for this (SCR) purpose. An 3435 * IOCB is allocated, payload prepared, and the lpfc_sli_issue_iocb() 3436 * routine is invoked to send the SCR IOCB. 3437 * 3438 * Note that the ndlp reference count will be incremented by 1 for holding the 3439 * ndlp and the reference to ndlp will be stored into the ndlp field of 3440 * the IOCB for the completion callback function to the SCR ELS command. 3441 * 3442 * Return code 3443 * 0 - Successfully issued scr command 3444 * 1 - Failed to issue scr command 3445 **/ 3446 int 3447 lpfc_issue_els_scr(struct lpfc_vport *vport, uint8_t retry) 3448 { 3449 int rc = 0; 3450 struct lpfc_hba *phba = vport->phba; 3451 struct lpfc_iocbq *elsiocb; 3452 uint8_t *pcmd; 3453 uint16_t cmdsize; 3454 struct lpfc_nodelist *ndlp; 3455 3456 cmdsize = (sizeof(uint32_t) + sizeof(SCR)); 3457 3458 ndlp = lpfc_findnode_did(vport, Fabric_Cntl_DID); 3459 if (!ndlp) { 3460 ndlp = lpfc_nlp_init(vport, Fabric_Cntl_DID); 3461 if (!ndlp) 3462 return 1; 3463 lpfc_enqueue_node(vport, ndlp); 3464 } 3465 3466 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, 3467 ndlp->nlp_DID, ELS_CMD_SCR); 3468 if (!elsiocb) 3469 return 1; 3470 3471 if (phba->sli_rev == LPFC_SLI_REV4) { 3472 rc = lpfc_reg_fab_ctrl_node(vport, ndlp); 3473 if (rc) { 3474 lpfc_els_free_iocb(phba, elsiocb); 3475 lpfc_printf_vlog(vport, KERN_ERR, LOG_NODE, 3476 "0937 %s: Failed to reg fc node, rc %d\n", 3477 __func__, rc); 3478 return 1; 3479 } 3480 } 3481 pcmd = (uint8_t *)elsiocb->cmd_dmabuf->virt; 3482 3483 *((uint32_t *) (pcmd)) = ELS_CMD_SCR; 3484 pcmd += sizeof(uint32_t); 3485 3486 /* For SCR, remainder of payload is SCR parameter page */ 3487 memset(pcmd, 0, sizeof(SCR)); 3488 ((SCR *) pcmd)->Function = SCR_FUNC_FULL; 3489 3490 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, 3491 "Issue SCR: did:x%x", 3492 ndlp->nlp_DID, 0, 0); 3493 3494 phba->fc_stat.elsXmitSCR++; 3495 elsiocb->cmd_cmpl = lpfc_cmpl_els_disc_cmd; 3496 elsiocb->ndlp = lpfc_nlp_get(ndlp); 3497 if (!elsiocb->ndlp) { 3498 lpfc_els_free_iocb(phba, elsiocb); 3499 return 1; 3500 } 3501 3502 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, 3503 "Issue SCR: did:x%x refcnt %d", 3504 ndlp->nlp_DID, kref_read(&ndlp->kref), 0); 3505 3506 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); 3507 if (rc == IOCB_ERROR) { 3508 lpfc_els_free_iocb(phba, elsiocb); 3509 lpfc_nlp_put(ndlp); 3510 return 1; 3511 } 3512 3513 return 0; 3514 } 3515 3516 /** 3517 * lpfc_issue_els_rscn - Issue an RSCN to the Fabric Controller (Fabric) 3518 * or the other nport (pt2pt). 3519 * @vport: pointer to a host virtual N_Port data structure. 3520 * @retry: number of retries to the command IOCB. 3521 * 3522 * This routine issues a RSCN to the Fabric Controller (DID 0xFFFFFD) 3523 * when connected to a fabric, or to the remote port when connected 3524 * in point-to-point mode. When sent to the Fabric Controller, it will 3525 * replay the RSCN to registered recipients. 3526 * 3527 * Note that the ndlp reference count will be incremented by 1 for holding the 3528 * ndlp and the reference to ndlp will be stored into the ndlp field of 3529 * the IOCB for the completion callback function to the RSCN ELS command. 3530 * 3531 * Return code 3532 * 0 - Successfully issued RSCN command 3533 * 1 - Failed to issue RSCN command 3534 **/ 3535 int 3536 lpfc_issue_els_rscn(struct lpfc_vport *vport, uint8_t retry) 3537 { 3538 int rc = 0; 3539 struct lpfc_hba *phba = vport->phba; 3540 struct lpfc_iocbq *elsiocb; 3541 struct lpfc_nodelist *ndlp; 3542 struct { 3543 struct fc_els_rscn rscn; 3544 struct fc_els_rscn_page portid; 3545 } *event; 3546 uint32_t nportid; 3547 uint16_t cmdsize = sizeof(*event); 3548 3549 /* Not supported for private loop */ 3550 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP && 3551 !test_bit(FC_PUBLIC_LOOP, &vport->fc_flag)) 3552 return 1; 3553 3554 if (test_bit(FC_PT2PT, &vport->fc_flag)) { 3555 /* find any mapped nport - that would be the other nport */ 3556 ndlp = lpfc_findnode_mapped(vport); 3557 if (!ndlp) 3558 return 1; 3559 } else { 3560 nportid = FC_FID_FCTRL; 3561 /* find the fabric controller node */ 3562 ndlp = lpfc_findnode_did(vport, nportid); 3563 if (!ndlp) { 3564 /* if one didn't exist, make one */ 3565 ndlp = lpfc_nlp_init(vport, nportid); 3566 if (!ndlp) 3567 return 1; 3568 lpfc_enqueue_node(vport, ndlp); 3569 } 3570 } 3571 3572 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, 3573 ndlp->nlp_DID, ELS_CMD_RSCN_XMT); 3574 3575 if (!elsiocb) 3576 return 1; 3577 3578 event = elsiocb->cmd_dmabuf->virt; 3579 3580 event->rscn.rscn_cmd = ELS_RSCN; 3581 event->rscn.rscn_page_len = sizeof(struct fc_els_rscn_page); 3582 event->rscn.rscn_plen = cpu_to_be16(cmdsize); 3583 3584 nportid = vport->fc_myDID; 3585 /* appears that page flags must be 0 for fabric to broadcast RSCN */ 3586 event->portid.rscn_page_flags = 0; 3587 event->portid.rscn_fid[0] = (nportid & 0x00FF0000) >> 16; 3588 event->portid.rscn_fid[1] = (nportid & 0x0000FF00) >> 8; 3589 event->portid.rscn_fid[2] = nportid & 0x000000FF; 3590 3591 phba->fc_stat.elsXmitRSCN++; 3592 elsiocb->cmd_cmpl = lpfc_cmpl_els_cmd; 3593 elsiocb->ndlp = lpfc_nlp_get(ndlp); 3594 if (!elsiocb->ndlp) { 3595 lpfc_els_free_iocb(phba, elsiocb); 3596 return 1; 3597 } 3598 3599 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, 3600 "Issue RSCN: did:x%x", 3601 ndlp->nlp_DID, 0, 0); 3602 3603 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); 3604 if (rc == IOCB_ERROR) { 3605 lpfc_els_free_iocb(phba, elsiocb); 3606 lpfc_nlp_put(ndlp); 3607 return 1; 3608 } 3609 3610 return 0; 3611 } 3612 3613 /** 3614 * lpfc_issue_els_farpr - Issue a farp to an node on a vport 3615 * @vport: pointer to a host virtual N_Port data structure. 3616 * @nportid: N_Port identifier to the remote node. 3617 * @retry: number of retries to the command IOCB. 3618 * 3619 * This routine issues a Fibre Channel Address Resolution Response 3620 * (FARPR) to a node on a vport. The remote node N_Port identifier (@nportid) 3621 * is passed into the function. It first search the @vport node list to find 3622 * the matching ndlp. If no such ndlp is found, a new ndlp shall be created 3623 * for this (FARPR) purpose. An IOCB is allocated, payload prepared, and the 3624 * lpfc_sli_issue_iocb() routine is invoked to send the FARPR ELS command. 3625 * 3626 * Note that the ndlp reference count will be incremented by 1 for holding the 3627 * ndlp and the reference to ndlp will be stored into the ndlp field of 3628 * the IOCB for the completion callback function to the FARPR ELS command. 3629 * 3630 * Return code 3631 * 0 - Successfully issued farpr command 3632 * 1 - Failed to issue farpr command 3633 **/ 3634 static int 3635 lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry) 3636 { 3637 int rc = 0; 3638 struct lpfc_hba *phba = vport->phba; 3639 struct lpfc_iocbq *elsiocb; 3640 FARP *fp; 3641 uint8_t *pcmd; 3642 uint32_t *lp; 3643 uint16_t cmdsize; 3644 struct lpfc_nodelist *ondlp; 3645 struct lpfc_nodelist *ndlp; 3646 3647 cmdsize = (sizeof(uint32_t) + sizeof(FARP)); 3648 3649 ndlp = lpfc_findnode_did(vport, nportid); 3650 if (!ndlp) { 3651 ndlp = lpfc_nlp_init(vport, nportid); 3652 if (!ndlp) 3653 return 1; 3654 lpfc_enqueue_node(vport, ndlp); 3655 } 3656 3657 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, 3658 ndlp->nlp_DID, ELS_CMD_FARPR); 3659 if (!elsiocb) 3660 return 1; 3661 3662 pcmd = (uint8_t *)elsiocb->cmd_dmabuf->virt; 3663 3664 *((uint32_t *) (pcmd)) = ELS_CMD_FARPR; 3665 pcmd += sizeof(uint32_t); 3666 3667 /* Fill in FARPR payload */ 3668 fp = (FARP *) (pcmd); 3669 memset(fp, 0, sizeof(FARP)); 3670 lp = (uint32_t *) pcmd; 3671 *lp++ = be32_to_cpu(nportid); 3672 *lp++ = be32_to_cpu(vport->fc_myDID); 3673 fp->Rflags = 0; 3674 fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE); 3675 3676 memcpy(&fp->RportName, &vport->fc_portname, sizeof(struct lpfc_name)); 3677 memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); 3678 ondlp = lpfc_findnode_did(vport, nportid); 3679 if (ondlp) { 3680 memcpy(&fp->OportName, &ondlp->nlp_portname, 3681 sizeof(struct lpfc_name)); 3682 memcpy(&fp->OnodeName, &ondlp->nlp_nodename, 3683 sizeof(struct lpfc_name)); 3684 } 3685 3686 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, 3687 "Issue FARPR: did:x%x", 3688 ndlp->nlp_DID, 0, 0); 3689 3690 phba->fc_stat.elsXmitFARPR++; 3691 elsiocb->cmd_cmpl = lpfc_cmpl_els_cmd; 3692 elsiocb->ndlp = lpfc_nlp_get(ndlp); 3693 if (!elsiocb->ndlp) { 3694 lpfc_els_free_iocb(phba, elsiocb); 3695 return 1; 3696 } 3697 3698 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); 3699 if (rc == IOCB_ERROR) { 3700 /* The additional lpfc_nlp_put will cause the following 3701 * lpfc_els_free_iocb routine to trigger the release of 3702 * the node. 3703 */ 3704 lpfc_els_free_iocb(phba, elsiocb); 3705 lpfc_nlp_put(ndlp); 3706 return 1; 3707 } 3708 /* This will cause the callback-function lpfc_cmpl_els_cmd to 3709 * trigger the release of the node. 3710 */ 3711 /* Don't release reference count as RDF is likely outstanding */ 3712 return 0; 3713 } 3714 3715 /** 3716 * lpfc_issue_els_rdf - Register for diagnostic functions from the fabric. 3717 * @vport: pointer to a host virtual N_Port data structure. 3718 * @retry: retry counter for the command IOCB. 3719 * 3720 * This routine issues an ELS RDF to the Fabric Controller to register 3721 * for diagnostic functions. 3722 * 3723 * Note that the ndlp reference count will be incremented by 1 for holding the 3724 * ndlp and the reference to ndlp will be stored into the ndlp field of 3725 * the IOCB for the completion callback function to the RDF ELS command. 3726 * 3727 * Return code 3728 * 0 - Successfully issued rdf command 3729 * 1 - Failed to issue rdf command 3730 **/ 3731 int 3732 lpfc_issue_els_rdf(struct lpfc_vport *vport, uint8_t retry) 3733 { 3734 struct lpfc_hba *phba = vport->phba; 3735 struct lpfc_iocbq *elsiocb; 3736 struct lpfc_els_rdf_req *prdf; 3737 struct lpfc_nodelist *ndlp; 3738 uint16_t cmdsize; 3739 int rc; 3740 3741 cmdsize = sizeof(*prdf); 3742 3743 ndlp = lpfc_findnode_did(vport, Fabric_Cntl_DID); 3744 if (!ndlp) { 3745 ndlp = lpfc_nlp_init(vport, Fabric_Cntl_DID); 3746 if (!ndlp) 3747 return -ENODEV; 3748 lpfc_enqueue_node(vport, ndlp); 3749 } 3750 3751 /* RDF ELS is not required on an NPIV VN_Port. */ 3752 if (vport->port_type == LPFC_NPIV_PORT) 3753 return -EACCES; 3754 3755 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, 3756 ndlp->nlp_DID, ELS_CMD_RDF); 3757 if (!elsiocb) 3758 return -ENOMEM; 3759 3760 /* Configure the payload for the supported FPIN events. */ 3761 prdf = (struct lpfc_els_rdf_req *)elsiocb->cmd_dmabuf->virt; 3762 memset(prdf, 0, cmdsize); 3763 prdf->rdf.fpin_cmd = ELS_RDF; 3764 prdf->rdf.desc_len = cpu_to_be32(sizeof(struct lpfc_els_rdf_req) - 3765 sizeof(struct fc_els_rdf)); 3766 prdf->reg_d1.reg_desc.desc_tag = cpu_to_be32(ELS_DTAG_FPIN_REGISTER); 3767 prdf->reg_d1.reg_desc.desc_len = cpu_to_be32( 3768 FC_TLV_DESC_LENGTH_FROM_SZ(prdf->reg_d1)); 3769 prdf->reg_d1.reg_desc.count = cpu_to_be32(ELS_RDF_REG_TAG_CNT); 3770 prdf->reg_d1.desc_tags[0] = cpu_to_be32(ELS_DTAG_LNK_INTEGRITY); 3771 prdf->reg_d1.desc_tags[1] = cpu_to_be32(ELS_DTAG_DELIVERY); 3772 prdf->reg_d1.desc_tags[2] = cpu_to_be32(ELS_DTAG_PEER_CONGEST); 3773 prdf->reg_d1.desc_tags[3] = cpu_to_be32(ELS_DTAG_CONGESTION); 3774 3775 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS | LOG_CGN_MGMT, 3776 "6444 Xmit RDF to remote NPORT x%x Reg: %x %x\n", 3777 ndlp->nlp_DID, phba->cgn_reg_signal, 3778 phba->cgn_reg_fpin); 3779 3780 phba->cgn_fpin_frequency = LPFC_FPIN_INIT_FREQ; 3781 elsiocb->cmd_cmpl = lpfc_cmpl_els_disc_cmd; 3782 elsiocb->ndlp = lpfc_nlp_get(ndlp); 3783 if (!elsiocb->ndlp) { 3784 lpfc_els_free_iocb(phba, elsiocb); 3785 return -EIO; 3786 } 3787 3788 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, 3789 "Issue RDF: did:x%x refcnt %d", 3790 ndlp->nlp_DID, kref_read(&ndlp->kref), 0); 3791 3792 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); 3793 if (rc == IOCB_ERROR) { 3794 lpfc_els_free_iocb(phba, elsiocb); 3795 lpfc_nlp_put(ndlp); 3796 return -EIO; 3797 } 3798 return 0; 3799 } 3800 3801 /** 3802 * lpfc_els_rcv_rdf - Receive RDF ELS request from the fabric. 3803 * @vport: pointer to a host virtual N_Port data structure. 3804 * @cmdiocb: pointer to lpfc command iocb data structure. 3805 * @ndlp: pointer to a node-list data structure. 3806 * 3807 * A received RDF implies a possible change to fabric supported diagnostic 3808 * functions. This routine sends LS_ACC and then has the Nx_Port issue a new 3809 * RDF request to reregister for supported diagnostic functions. 3810 * 3811 * Return code 3812 * 0 - Success 3813 * -EIO - Failed to process received RDF 3814 **/ 3815 static int 3816 lpfc_els_rcv_rdf(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, 3817 struct lpfc_nodelist *ndlp) 3818 { 3819 /* Send LS_ACC */ 3820 if (lpfc_els_rsp_acc(vport, ELS_CMD_RDF, cmdiocb, ndlp, NULL)) { 3821 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS | LOG_CGN_MGMT, 3822 "1623 Failed to RDF_ACC from x%x for x%x\n", 3823 ndlp->nlp_DID, vport->fc_myDID); 3824 return -EIO; 3825 } 3826 3827 /* Issue new RDF for reregistering */ 3828 if (lpfc_issue_els_rdf(vport, 0)) { 3829 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS | LOG_CGN_MGMT, 3830 "2623 Failed to re register RDF for x%x\n", 3831 vport->fc_myDID); 3832 return -EIO; 3833 } 3834 3835 return 0; 3836 } 3837 3838 /** 3839 * lpfc_least_capable_settings - helper function for EDC rsp processing 3840 * @phba: pointer to lpfc hba data structure. 3841 * @pcgd: pointer to congestion detection descriptor in EDC rsp. 3842 * 3843 * This helper routine determines the least capable setting for 3844 * congestion signals, signal freq, including scale, from the 3845 * congestion detection descriptor in the EDC rsp. The routine 3846 * sets @phba values in preparation for a set_featues mailbox. 3847 **/ 3848 static void 3849 lpfc_least_capable_settings(struct lpfc_hba *phba, 3850 struct fc_diag_cg_sig_desc *pcgd) 3851 { 3852 u32 rsp_sig_cap = 0, drv_sig_cap = 0; 3853 u32 rsp_sig_freq_cyc = 0, rsp_sig_freq_scale = 0; 3854 3855 /* Get rsp signal and frequency capabilities. */ 3856 rsp_sig_cap = be32_to_cpu(pcgd->xmt_signal_capability); 3857 rsp_sig_freq_cyc = be16_to_cpu(pcgd->xmt_signal_frequency.count); 3858 rsp_sig_freq_scale = be16_to_cpu(pcgd->xmt_signal_frequency.units); 3859 3860 /* If the Fport does not support signals. Set FPIN only */ 3861 if (rsp_sig_cap == EDC_CG_SIG_NOTSUPPORTED) 3862 goto out_no_support; 3863 3864 /* Apply the xmt scale to the xmt cycle to get the correct frequency. 3865 * Adapter default is 100 millisSeconds. Convert all xmt cycle values 3866 * to milliSeconds. 3867 */ 3868 switch (rsp_sig_freq_scale) { 3869 case EDC_CG_SIGFREQ_SEC: 3870 rsp_sig_freq_cyc *= MSEC_PER_SEC; 3871 break; 3872 case EDC_CG_SIGFREQ_MSEC: 3873 rsp_sig_freq_cyc = 1; 3874 break; 3875 default: 3876 goto out_no_support; 3877 } 3878 3879 /* Convenient shorthand. */ 3880 drv_sig_cap = phba->cgn_reg_signal; 3881 3882 /* Choose the least capable frequency. */ 3883 if (rsp_sig_freq_cyc > phba->cgn_sig_freq) 3884 phba->cgn_sig_freq = rsp_sig_freq_cyc; 3885 3886 /* Should be some common signals support. Settle on least capable 3887 * signal and adjust FPIN values. Initialize defaults to ease the 3888 * decision. 3889 */ 3890 phba->cgn_reg_fpin = LPFC_CGN_FPIN_WARN | LPFC_CGN_FPIN_ALARM; 3891 phba->cgn_reg_signal = EDC_CG_SIG_NOTSUPPORTED; 3892 if (rsp_sig_cap == EDC_CG_SIG_WARN_ONLY && 3893 (drv_sig_cap == EDC_CG_SIG_WARN_ONLY || 3894 drv_sig_cap == EDC_CG_SIG_WARN_ALARM)) { 3895 phba->cgn_reg_signal = EDC_CG_SIG_WARN_ONLY; 3896 phba->cgn_reg_fpin &= ~LPFC_CGN_FPIN_WARN; 3897 } 3898 if (rsp_sig_cap == EDC_CG_SIG_WARN_ALARM) { 3899 if (drv_sig_cap == EDC_CG_SIG_WARN_ALARM) { 3900 phba->cgn_reg_signal = EDC_CG_SIG_WARN_ALARM; 3901 phba->cgn_reg_fpin = LPFC_CGN_FPIN_NONE; 3902 } 3903 if (drv_sig_cap == EDC_CG_SIG_WARN_ONLY) { 3904 phba->cgn_reg_signal = EDC_CG_SIG_WARN_ONLY; 3905 phba->cgn_reg_fpin &= ~LPFC_CGN_FPIN_WARN; 3906 } 3907 } 3908 3909 /* We are NOT recording signal frequency in congestion info buffer */ 3910 return; 3911 3912 out_no_support: 3913 phba->cgn_reg_signal = EDC_CG_SIG_NOTSUPPORTED; 3914 phba->cgn_sig_freq = 0; 3915 phba->cgn_reg_fpin = LPFC_CGN_FPIN_ALARM | LPFC_CGN_FPIN_WARN; 3916 } 3917 3918 DECLARE_ENUM2STR_LOOKUP(lpfc_get_tlv_dtag_nm, fc_ls_tlv_dtag, 3919 FC_LS_TLV_DTAG_INIT); 3920 3921 /** 3922 * lpfc_cmpl_els_edc - Completion callback function for EDC 3923 * @phba: pointer to lpfc hba data structure. 3924 * @cmdiocb: pointer to lpfc command iocb data structure. 3925 * @rspiocb: pointer to lpfc response iocb data structure. 3926 * 3927 * This routine is the completion callback function for issuing the Exchange 3928 * Diagnostic Capabilities (EDC) command. The driver issues an EDC to 3929 * notify the FPort of its Congestion and Link Fault capabilities. This 3930 * routine parses the FPort's response and decides on the least common 3931 * values applicable to both FPort and NPort for Warnings and Alarms that 3932 * are communicated via hardware signals. 3933 **/ 3934 static void 3935 lpfc_cmpl_els_edc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, 3936 struct lpfc_iocbq *rspiocb) 3937 { 3938 IOCB_t *irsp_iocb; 3939 struct fc_els_edc_resp *edc_rsp; 3940 struct fc_tlv_desc *tlv; 3941 struct fc_diag_cg_sig_desc *pcgd; 3942 struct fc_diag_lnkflt_desc *plnkflt; 3943 struct lpfc_dmabuf *pcmd, *prsp; 3944 const char *dtag_nm; 3945 u32 *pdata, dtag; 3946 int desc_cnt = 0, bytes_remain; 3947 bool rcv_cap_desc = false; 3948 struct lpfc_nodelist *ndlp; 3949 u32 ulp_status, ulp_word4, tmo, did, iotag; 3950 3951 ndlp = cmdiocb->ndlp; 3952 3953 ulp_status = get_job_ulpstatus(phba, rspiocb); 3954 ulp_word4 = get_job_word4(phba, rspiocb); 3955 did = get_job_els_rsp64_did(phba, rspiocb); 3956 3957 if (phba->sli_rev == LPFC_SLI_REV4) { 3958 tmo = get_wqe_tmo(rspiocb); 3959 iotag = get_wqe_reqtag(rspiocb); 3960 } else { 3961 irsp_iocb = &rspiocb->iocb; 3962 tmo = irsp_iocb->ulpTimeout; 3963 iotag = irsp_iocb->ulpIoTag; 3964 } 3965 3966 lpfc_debugfs_disc_trc(phba->pport, LPFC_DISC_TRC_ELS_CMD, 3967 "EDC cmpl: status:x%x/x%x did:x%x", 3968 ulp_status, ulp_word4, did); 3969 3970 /* ELS cmd tag <ulpIoTag> completes */ 3971 lpfc_printf_log(phba, KERN_INFO, LOG_ELS | LOG_CGN_MGMT, 3972 "4201 EDC cmd tag x%x completes Data: x%x x%x x%x\n", 3973 iotag, ulp_status, ulp_word4, tmo); 3974 3975 pcmd = cmdiocb->cmd_dmabuf; 3976 if (!pcmd) 3977 goto out; 3978 3979 pdata = (u32 *)pcmd->virt; 3980 if (!pdata) 3981 goto out; 3982 3983 /* Need to clear signal values, send features MB and RDF with FPIN. */ 3984 if (ulp_status) 3985 goto out; 3986 3987 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list); 3988 if (!prsp) 3989 goto out; 3990 3991 edc_rsp = prsp->virt; 3992 if (!edc_rsp) 3993 goto out; 3994 3995 /* ELS cmd tag <ulpIoTag> completes */ 3996 lpfc_printf_log(phba, KERN_INFO, 3997 LOG_ELS | LOG_CGN_MGMT | LOG_LDS_EVENT, 3998 "4676 Fabric EDC Rsp: " 3999 "0x%02x, 0x%08x\n", 4000 edc_rsp->acc_hdr.la_cmd, 4001 be32_to_cpu(edc_rsp->desc_list_len)); 4002 4003 if (!lpfc_is_els_acc_rsp(prsp)) 4004 goto out; 4005 4006 /* 4007 * Payload length in bytes is the response descriptor list 4008 * length minus the 12 bytes of Link Service Request 4009 * Information descriptor in the reply. 4010 */ 4011 bytes_remain = be32_to_cpu(edc_rsp->desc_list_len) - 4012 sizeof(struct fc_els_lsri_desc); 4013 if (bytes_remain <= 0) 4014 goto out; 4015 4016 tlv = edc_rsp->desc; 4017 4018 /* 4019 * cycle through EDC diagnostic descriptors to find the 4020 * congestion signaling capability descriptor 4021 */ 4022 while (bytes_remain) { 4023 if (bytes_remain < FC_TLV_DESC_HDR_SZ) { 4024 lpfc_printf_log(phba, KERN_WARNING, LOG_CGN_MGMT, 4025 "6461 Truncated TLV hdr on " 4026 "Diagnostic descriptor[%d]\n", 4027 desc_cnt); 4028 goto out; 4029 } 4030 4031 dtag = be32_to_cpu(tlv->desc_tag); 4032 switch (dtag) { 4033 case ELS_DTAG_LNK_FAULT_CAP: 4034 if (bytes_remain < FC_TLV_DESC_SZ_FROM_LENGTH(tlv) || 4035 FC_TLV_DESC_SZ_FROM_LENGTH(tlv) != 4036 sizeof(struct fc_diag_lnkflt_desc)) { 4037 lpfc_printf_log(phba, KERN_WARNING, 4038 LOG_ELS | LOG_CGN_MGMT | LOG_LDS_EVENT, 4039 "6462 Truncated Link Fault Diagnostic " 4040 "descriptor[%d]: %d vs 0x%zx 0x%zx\n", 4041 desc_cnt, bytes_remain, 4042 FC_TLV_DESC_SZ_FROM_LENGTH(tlv), 4043 sizeof(struct fc_diag_lnkflt_desc)); 4044 goto out; 4045 } 4046 plnkflt = (struct fc_diag_lnkflt_desc *)tlv; 4047 lpfc_printf_log(phba, KERN_INFO, 4048 LOG_ELS | LOG_LDS_EVENT, 4049 "4617 Link Fault Desc Data: 0x%08x 0x%08x " 4050 "0x%08x 0x%08x 0x%08x\n", 4051 be32_to_cpu(plnkflt->desc_tag), 4052 be32_to_cpu(plnkflt->desc_len), 4053 be32_to_cpu( 4054 plnkflt->degrade_activate_threshold), 4055 be32_to_cpu( 4056 plnkflt->degrade_deactivate_threshold), 4057 be32_to_cpu(plnkflt->fec_degrade_interval)); 4058 break; 4059 case ELS_DTAG_CG_SIGNAL_CAP: 4060 if (bytes_remain < FC_TLV_DESC_SZ_FROM_LENGTH(tlv) || 4061 FC_TLV_DESC_SZ_FROM_LENGTH(tlv) != 4062 sizeof(struct fc_diag_cg_sig_desc)) { 4063 lpfc_printf_log( 4064 phba, KERN_WARNING, LOG_CGN_MGMT, 4065 "6463 Truncated Cgn Signal Diagnostic " 4066 "descriptor[%d]: %d vs 0x%zx 0x%zx\n", 4067 desc_cnt, bytes_remain, 4068 FC_TLV_DESC_SZ_FROM_LENGTH(tlv), 4069 sizeof(struct fc_diag_cg_sig_desc)); 4070 goto out; 4071 } 4072 4073 pcgd = (struct fc_diag_cg_sig_desc *)tlv; 4074 lpfc_printf_log( 4075 phba, KERN_INFO, LOG_ELS | LOG_CGN_MGMT, 4076 "4616 CGN Desc Data: 0x%08x 0x%08x " 4077 "0x%08x 0x%04x 0x%04x 0x%08x 0x%04x 0x%04x\n", 4078 be32_to_cpu(pcgd->desc_tag), 4079 be32_to_cpu(pcgd->desc_len), 4080 be32_to_cpu(pcgd->xmt_signal_capability), 4081 be16_to_cpu(pcgd->xmt_signal_frequency.count), 4082 be16_to_cpu(pcgd->xmt_signal_frequency.units), 4083 be32_to_cpu(pcgd->rcv_signal_capability), 4084 be16_to_cpu(pcgd->rcv_signal_frequency.count), 4085 be16_to_cpu(pcgd->rcv_signal_frequency.units)); 4086 4087 /* Compare driver and Fport capabilities and choose 4088 * least common. 4089 */ 4090 lpfc_least_capable_settings(phba, pcgd); 4091 rcv_cap_desc = true; 4092 break; 4093 default: 4094 dtag_nm = lpfc_get_tlv_dtag_nm(dtag); 4095 lpfc_printf_log(phba, KERN_WARNING, LOG_CGN_MGMT, 4096 "4919 unknown Diagnostic " 4097 "Descriptor[%d]: tag x%x (%s)\n", 4098 desc_cnt, dtag, dtag_nm); 4099 } 4100 4101 bytes_remain -= FC_TLV_DESC_SZ_FROM_LENGTH(tlv); 4102 tlv = fc_tlv_next_desc(tlv); 4103 desc_cnt++; 4104 } 4105 4106 out: 4107 if (!rcv_cap_desc) { 4108 phba->cgn_reg_fpin = LPFC_CGN_FPIN_ALARM | LPFC_CGN_FPIN_WARN; 4109 phba->cgn_reg_signal = EDC_CG_SIG_NOTSUPPORTED; 4110 phba->cgn_sig_freq = 0; 4111 lpfc_printf_log(phba, KERN_WARNING, LOG_ELS | LOG_CGN_MGMT, 4112 "4202 EDC rsp error - sending RDF " 4113 "for FPIN only.\n"); 4114 } 4115 4116 lpfc_config_cgn_signal(phba); 4117 4118 /* Check to see if link went down during discovery */ 4119 lpfc_els_chk_latt(phba->pport); 4120 lpfc_debugfs_disc_trc(phba->pport, LPFC_DISC_TRC_ELS_CMD, 4121 "EDC Cmpl: did:x%x refcnt %d", 4122 ndlp->nlp_DID, kref_read(&ndlp->kref), 0); 4123 lpfc_els_free_iocb(phba, cmdiocb); 4124 lpfc_nlp_put(ndlp); 4125 } 4126 4127 static void 4128 lpfc_format_edc_lft_desc(struct lpfc_hba *phba, struct fc_tlv_desc *tlv) 4129 { 4130 struct fc_diag_lnkflt_desc *lft = (struct fc_diag_lnkflt_desc *)tlv; 4131 4132 lft->desc_tag = cpu_to_be32(ELS_DTAG_LNK_FAULT_CAP); 4133 lft->desc_len = cpu_to_be32( 4134 FC_TLV_DESC_LENGTH_FROM_SZ(struct fc_diag_lnkflt_desc)); 4135 4136 lft->degrade_activate_threshold = 4137 cpu_to_be32(phba->degrade_activate_threshold); 4138 lft->degrade_deactivate_threshold = 4139 cpu_to_be32(phba->degrade_deactivate_threshold); 4140 lft->fec_degrade_interval = cpu_to_be32(phba->fec_degrade_interval); 4141 } 4142 4143 static void 4144 lpfc_format_edc_cgn_desc(struct lpfc_hba *phba, struct fc_tlv_desc *tlv) 4145 { 4146 struct fc_diag_cg_sig_desc *cgd = (struct fc_diag_cg_sig_desc *)tlv; 4147 4148 /* We are assuming cgd was zero'ed before calling this routine */ 4149 4150 /* Configure the congestion detection capability */ 4151 cgd->desc_tag = cpu_to_be32(ELS_DTAG_CG_SIGNAL_CAP); 4152 4153 /* Descriptor len doesn't include the tag or len fields. */ 4154 cgd->desc_len = cpu_to_be32( 4155 FC_TLV_DESC_LENGTH_FROM_SZ(struct fc_diag_cg_sig_desc)); 4156 4157 /* xmt_signal_capability already set to EDC_CG_SIG_NOTSUPPORTED. 4158 * xmt_signal_frequency.count already set to 0. 4159 * xmt_signal_frequency.units already set to 0. 4160 */ 4161 4162 if (phba->cmf_active_mode == LPFC_CFG_OFF) { 4163 /* rcv_signal_capability already set to EDC_CG_SIG_NOTSUPPORTED. 4164 * rcv_signal_frequency.count already set to 0. 4165 * rcv_signal_frequency.units already set to 0. 4166 */ 4167 phba->cgn_sig_freq = 0; 4168 return; 4169 } 4170 switch (phba->cgn_reg_signal) { 4171 case EDC_CG_SIG_WARN_ONLY: 4172 cgd->rcv_signal_capability = cpu_to_be32(EDC_CG_SIG_WARN_ONLY); 4173 break; 4174 case EDC_CG_SIG_WARN_ALARM: 4175 cgd->rcv_signal_capability = cpu_to_be32(EDC_CG_SIG_WARN_ALARM); 4176 break; 4177 default: 4178 /* rcv_signal_capability left 0 thus no support */ 4179 break; 4180 } 4181 4182 /* We start negotiation with lpfc_fabric_cgn_frequency, after 4183 * the completion we settle on the higher frequency. 4184 */ 4185 cgd->rcv_signal_frequency.count = 4186 cpu_to_be16(lpfc_fabric_cgn_frequency); 4187 cgd->rcv_signal_frequency.units = 4188 cpu_to_be16(EDC_CG_SIGFREQ_MSEC); 4189 } 4190 4191 static bool 4192 lpfc_link_is_lds_capable(struct lpfc_hba *phba) 4193 { 4194 if (!(phba->lmt & LMT_64Gb)) 4195 return false; 4196 if (phba->sli_rev != LPFC_SLI_REV4) 4197 return false; 4198 4199 if (phba->sli4_hba.conf_trunk) { 4200 if (phba->trunk_link.phy_lnk_speed == LPFC_USER_LINK_SPEED_64G) 4201 return true; 4202 } else if (phba->fc_linkspeed == LPFC_LINK_SPEED_64GHZ) { 4203 return true; 4204 } 4205 return false; 4206 } 4207 4208 /** 4209 * lpfc_issue_els_edc - Exchange Diagnostic Capabilities with the fabric. 4210 * @vport: pointer to a host virtual N_Port data structure. 4211 * @retry: retry counter for the command iocb. 4212 * 4213 * This routine issues an ELS EDC to the F-Port Controller to communicate 4214 * this N_Port's support of hardware signals in its Congestion 4215 * Capabilities Descriptor. 4216 * 4217 * Note: This routine does not check if one or more signals are 4218 * set in the cgn_reg_signal parameter. The caller makes the 4219 * decision to enforce cgn_reg_signal as nonzero or zero depending 4220 * on the conditions. During Fabric requests, the driver 4221 * requires cgn_reg_signals to be nonzero. But a dynamic request 4222 * to set the congestion mode to OFF from Monitor or Manage 4223 * would correctly issue an EDC with no signals enabled to 4224 * turn off switch functionality and then update the FW. 4225 * 4226 * Return code 4227 * 0 - Successfully issued edc command 4228 * 1 - Failed to issue edc command 4229 **/ 4230 int 4231 lpfc_issue_els_edc(struct lpfc_vport *vport, uint8_t retry) 4232 { 4233 struct lpfc_hba *phba = vport->phba; 4234 struct lpfc_iocbq *elsiocb; 4235 struct fc_els_edc *edc_req; 4236 struct fc_tlv_desc *tlv; 4237 u16 cmdsize; 4238 struct lpfc_nodelist *ndlp; 4239 u8 *pcmd = NULL; 4240 u32 cgn_desc_size, lft_desc_size; 4241 int rc; 4242 4243 if (vport->port_type == LPFC_NPIV_PORT) 4244 return -EACCES; 4245 4246 ndlp = lpfc_findnode_did(vport, Fabric_DID); 4247 if (!ndlp || ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) 4248 return -ENODEV; 4249 4250 cgn_desc_size = (phba->cgn_init_reg_signal) ? 4251 sizeof(struct fc_diag_cg_sig_desc) : 0; 4252 lft_desc_size = (lpfc_link_is_lds_capable(phba)) ? 4253 sizeof(struct fc_diag_lnkflt_desc) : 0; 4254 cmdsize = cgn_desc_size + lft_desc_size; 4255 4256 /* Skip EDC if no applicable descriptors */ 4257 if (!cmdsize) 4258 goto try_rdf; 4259 4260 cmdsize += sizeof(struct fc_els_edc); 4261 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, 4262 ndlp->nlp_DID, ELS_CMD_EDC); 4263 if (!elsiocb) 4264 goto try_rdf; 4265 4266 /* Configure the payload for the supported Diagnostics capabilities. */ 4267 pcmd = (u8 *)elsiocb->cmd_dmabuf->virt; 4268 memset(pcmd, 0, cmdsize); 4269 edc_req = (struct fc_els_edc *)pcmd; 4270 edc_req->desc_len = cpu_to_be32(cgn_desc_size + lft_desc_size); 4271 edc_req->edc_cmd = ELS_EDC; 4272 tlv = edc_req->desc; 4273 4274 if (cgn_desc_size) { 4275 lpfc_format_edc_cgn_desc(phba, tlv); 4276 phba->cgn_sig_freq = lpfc_fabric_cgn_frequency; 4277 tlv = fc_tlv_next_desc(tlv); 4278 } 4279 4280 if (lft_desc_size) 4281 lpfc_format_edc_lft_desc(phba, tlv); 4282 4283 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS | LOG_CGN_MGMT, 4284 "4623 Xmit EDC to remote " 4285 "NPORT x%x reg_sig x%x reg_fpin:x%x\n", 4286 ndlp->nlp_DID, phba->cgn_reg_signal, 4287 phba->cgn_reg_fpin); 4288 4289 elsiocb->cmd_cmpl = lpfc_cmpl_els_disc_cmd; 4290 elsiocb->ndlp = lpfc_nlp_get(ndlp); 4291 if (!elsiocb->ndlp) { 4292 lpfc_els_free_iocb(phba, elsiocb); 4293 return -EIO; 4294 } 4295 4296 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, 4297 "Issue EDC: did:x%x refcnt %d", 4298 ndlp->nlp_DID, kref_read(&ndlp->kref), 0); 4299 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); 4300 if (rc == IOCB_ERROR) { 4301 /* The additional lpfc_nlp_put will cause the following 4302 * lpfc_els_free_iocb routine to trigger the rlease of 4303 * the node. 4304 */ 4305 lpfc_els_free_iocb(phba, elsiocb); 4306 lpfc_nlp_put(ndlp); 4307 goto try_rdf; 4308 } 4309 return 0; 4310 try_rdf: 4311 phba->cgn_reg_fpin = LPFC_CGN_FPIN_WARN | LPFC_CGN_FPIN_ALARM; 4312 phba->cgn_reg_signal = EDC_CG_SIG_NOTSUPPORTED; 4313 rc = lpfc_issue_els_rdf(vport, 0); 4314 return rc; 4315 } 4316 4317 /** 4318 * lpfc_cancel_retry_delay_tmo - Cancel the timer with delayed iocb-cmd retry 4319 * @vport: pointer to a host virtual N_Port data structure. 4320 * @nlp: pointer to a node-list data structure. 4321 * 4322 * This routine cancels the timer with a delayed IOCB-command retry for 4323 * a @vport's @ndlp. It stops the timer for the delayed function retrial and 4324 * removes the ELS retry event if it presents. In addition, if the 4325 * NLP_NPR_2B_DISC bit is set in the @nlp's nlp_flag bitmap, ADISC IOCB 4326 * commands are sent for the @vport's nodes that require issuing discovery 4327 * ADISC. 4328 **/ 4329 void 4330 lpfc_cancel_retry_delay_tmo(struct lpfc_vport *vport, struct lpfc_nodelist *nlp) 4331 { 4332 struct lpfc_work_evt *evtp; 4333 4334 if (!test_and_clear_bit(NLP_DELAY_TMO, &nlp->nlp_flag)) 4335 return; 4336 timer_delete_sync(&nlp->nlp_delayfunc); 4337 nlp->nlp_last_elscmd = 0; 4338 if (!list_empty(&nlp->els_retry_evt.evt_listp)) { 4339 list_del_init(&nlp->els_retry_evt.evt_listp); 4340 /* Decrement nlp reference count held for the delayed retry */ 4341 evtp = &nlp->els_retry_evt; 4342 lpfc_nlp_put((struct lpfc_nodelist *)evtp->evt_arg1); 4343 } 4344 if (test_and_clear_bit(NLP_NPR_2B_DISC, &nlp->nlp_flag)) { 4345 if (vport->num_disc_nodes) { 4346 if (vport->port_state < LPFC_VPORT_READY) { 4347 /* Check if there are more ADISCs to be sent */ 4348 lpfc_more_adisc(vport); 4349 } else { 4350 /* Check if there are more PLOGIs to be sent */ 4351 lpfc_more_plogi(vport); 4352 if (vport->num_disc_nodes == 0) { 4353 clear_bit(FC_NDISC_ACTIVE, 4354 &vport->fc_flag); 4355 lpfc_can_disctmo(vport); 4356 lpfc_end_rscn(vport); 4357 } 4358 } 4359 } 4360 } 4361 return; 4362 } 4363 4364 /** 4365 * lpfc_els_retry_delay - Timer function with a ndlp delayed function timer 4366 * @t: pointer to the timer function associated data (ndlp). 4367 * 4368 * This routine is invoked by the ndlp delayed-function timer to check 4369 * whether there is any pending ELS retry event(s) with the node. If not, it 4370 * simply returns. Otherwise, if there is at least one ELS delayed event, it 4371 * adds the delayed events to the HBA work list and invokes the 4372 * lpfc_worker_wake_up() routine to wake up worker thread to process the 4373 * event. Note that lpfc_nlp_get() is called before posting the event to 4374 * the work list to hold reference count of ndlp so that it guarantees the 4375 * reference to ndlp will still be available when the worker thread gets 4376 * to the event associated with the ndlp. 4377 **/ 4378 void 4379 lpfc_els_retry_delay(struct timer_list *t) 4380 { 4381 struct lpfc_nodelist *ndlp = from_timer(ndlp, t, nlp_delayfunc); 4382 struct lpfc_vport *vport = ndlp->vport; 4383 struct lpfc_hba *phba = vport->phba; 4384 unsigned long flags; 4385 struct lpfc_work_evt *evtp = &ndlp->els_retry_evt; 4386 4387 /* Hold a node reference for outstanding queued work */ 4388 if (!lpfc_nlp_get(ndlp)) 4389 return; 4390 4391 spin_lock_irqsave(&phba->hbalock, flags); 4392 if (!list_empty(&evtp->evt_listp)) { 4393 spin_unlock_irqrestore(&phba->hbalock, flags); 4394 lpfc_nlp_put(ndlp); 4395 return; 4396 } 4397 4398 evtp->evt_arg1 = ndlp; 4399 evtp->evt = LPFC_EVT_ELS_RETRY; 4400 list_add_tail(&evtp->evt_listp, &phba->work_list); 4401 spin_unlock_irqrestore(&phba->hbalock, flags); 4402 4403 lpfc_worker_wake_up(phba); 4404 } 4405 4406 /** 4407 * lpfc_els_retry_delay_handler - Work thread handler for ndlp delayed function 4408 * @ndlp: pointer to a node-list data structure. 4409 * 4410 * This routine is the worker-thread handler for processing the @ndlp delayed 4411 * event(s), posted by the lpfc_els_retry_delay() routine. It simply retrieves 4412 * the last ELS command from the associated ndlp and invokes the proper ELS 4413 * function according to the delayed ELS command to retry the command. 4414 **/ 4415 void 4416 lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp) 4417 { 4418 struct lpfc_vport *vport = ndlp->vport; 4419 uint32_t cmd, retry; 4420 4421 spin_lock_irq(&ndlp->lock); 4422 cmd = ndlp->nlp_last_elscmd; 4423 ndlp->nlp_last_elscmd = 0; 4424 spin_unlock_irq(&ndlp->lock); 4425 4426 if (!test_and_clear_bit(NLP_DELAY_TMO, &ndlp->nlp_flag)) 4427 return; 4428 4429 /* 4430 * If a discovery event readded nlp_delayfunc after timer 4431 * firing and before processing the timer, cancel the 4432 * nlp_delayfunc. 4433 */ 4434 timer_delete_sync(&ndlp->nlp_delayfunc); 4435 retry = ndlp->nlp_retry; 4436 ndlp->nlp_retry = 0; 4437 4438 switch (cmd) { 4439 case ELS_CMD_FLOGI: 4440 lpfc_issue_els_flogi(vport, ndlp, retry); 4441 break; 4442 case ELS_CMD_PLOGI: 4443 if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) { 4444 ndlp->nlp_prev_state = ndlp->nlp_state; 4445 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); 4446 } 4447 break; 4448 case ELS_CMD_ADISC: 4449 if (!lpfc_issue_els_adisc(vport, ndlp, retry)) { 4450 ndlp->nlp_prev_state = ndlp->nlp_state; 4451 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE); 4452 } 4453 break; 4454 case ELS_CMD_PRLI: 4455 case ELS_CMD_NVMEPRLI: 4456 if (!lpfc_issue_els_prli(vport, ndlp, retry)) { 4457 ndlp->nlp_prev_state = ndlp->nlp_state; 4458 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE); 4459 } 4460 break; 4461 case ELS_CMD_LOGO: 4462 if (!lpfc_issue_els_logo(vport, ndlp, retry)) { 4463 ndlp->nlp_prev_state = ndlp->nlp_state; 4464 lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE); 4465 } 4466 break; 4467 case ELS_CMD_FDISC: 4468 if (!test_bit(FC_VPORT_NEEDS_INIT_VPI, &vport->fc_flag)) 4469 lpfc_issue_els_fdisc(vport, ndlp, retry); 4470 break; 4471 } 4472 return; 4473 } 4474 4475 /** 4476 * lpfc_link_reset - Issue link reset 4477 * @vport: pointer to a virtual N_Port data structure. 4478 * 4479 * This routine performs link reset by sending INIT_LINK mailbox command. 4480 * For SLI-3 adapter, link attention interrupt is enabled before issuing 4481 * INIT_LINK mailbox command. 4482 * 4483 * Return code 4484 * 0 - Link reset initiated successfully 4485 * 1 - Failed to initiate link reset 4486 **/ 4487 int 4488 lpfc_link_reset(struct lpfc_vport *vport) 4489 { 4490 struct lpfc_hba *phba = vport->phba; 4491 LPFC_MBOXQ_t *mbox; 4492 uint32_t control; 4493 int rc; 4494 4495 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, 4496 "2851 Attempt link reset\n"); 4497 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); 4498 if (!mbox) { 4499 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, 4500 "2852 Failed to allocate mbox memory"); 4501 return 1; 4502 } 4503 4504 /* Enable Link attention interrupts */ 4505 if (phba->sli_rev <= LPFC_SLI_REV3) { 4506 spin_lock_irq(&phba->hbalock); 4507 phba->sli.sli_flag |= LPFC_PROCESS_LA; 4508 control = readl(phba->HCregaddr); 4509 control |= HC_LAINT_ENA; 4510 writel(control, phba->HCregaddr); 4511 readl(phba->HCregaddr); /* flush */ 4512 spin_unlock_irq(&phba->hbalock); 4513 } 4514 4515 lpfc_init_link(phba, mbox, phba->cfg_topology, 4516 phba->cfg_link_speed); 4517 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; 4518 mbox->vport = vport; 4519 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); 4520 if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) { 4521 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, 4522 "2853 Failed to issue INIT_LINK " 4523 "mbox command, rc:x%x\n", rc); 4524 mempool_free(mbox, phba->mbox_mem_pool); 4525 return 1; 4526 } 4527 4528 return 0; 4529 } 4530 4531 /** 4532 * lpfc_els_retry - Make retry decision on an els command iocb 4533 * @phba: pointer to lpfc hba data structure. 4534 * @cmdiocb: pointer to lpfc command iocb data structure. 4535 * @rspiocb: pointer to lpfc response iocb data structure. 4536 * 4537 * This routine makes a retry decision on an ELS command IOCB, which has 4538 * failed. The following ELS IOCBs use this function for retrying the command 4539 * when previously issued command responsed with error status: FLOGI, PLOGI, 4540 * PRLI, ADISC and FDISC. Based on the ELS command type and the 4541 * returned error status, it makes the decision whether a retry shall be 4542 * issued for the command, and whether a retry shall be made immediately or 4543 * delayed. In the former case, the corresponding ELS command issuing-function 4544 * is called to retry the command. In the later case, the ELS command shall 4545 * be posted to the ndlp delayed event and delayed function timer set to the 4546 * ndlp for the delayed command issusing. 4547 * 4548 * Return code 4549 * 0 - No retry of els command is made 4550 * 1 - Immediate or delayed retry of els command is made 4551 **/ 4552 static int 4553 lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, 4554 struct lpfc_iocbq *rspiocb) 4555 { 4556 struct lpfc_vport *vport = cmdiocb->vport; 4557 union lpfc_wqe128 *irsp = &rspiocb->wqe; 4558 struct lpfc_nodelist *ndlp = cmdiocb->ndlp; 4559 struct lpfc_dmabuf *pcmd = cmdiocb->cmd_dmabuf; 4560 uint32_t *elscmd; 4561 struct ls_rjt stat; 4562 int retry = 0, maxretry = lpfc_max_els_tries, delay = 0; 4563 int logerr = 0; 4564 uint32_t cmd = 0; 4565 uint32_t did; 4566 int link_reset = 0, rc; 4567 u32 ulp_status = get_job_ulpstatus(phba, rspiocb); 4568 u32 ulp_word4 = get_job_word4(phba, rspiocb); 4569 u8 rsn_code_exp = 0; 4570 4571 4572 /* Note: cmd_dmabuf may be 0 for internal driver abort 4573 * of delays ELS command. 4574 */ 4575 4576 if (pcmd && pcmd->virt) { 4577 elscmd = (uint32_t *) (pcmd->virt); 4578 cmd = *elscmd++; 4579 } 4580 4581 if (ndlp) 4582 did = ndlp->nlp_DID; 4583 else { 4584 /* We should only hit this case for retrying PLOGI */ 4585 did = get_job_els_rsp64_did(phba, rspiocb); 4586 ndlp = lpfc_findnode_did(vport, did); 4587 if (!ndlp && (cmd != ELS_CMD_PLOGI)) 4588 return 0; 4589 } 4590 4591 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, 4592 "Retry ELS: wd7:x%x wd4:x%x did:x%x", 4593 *(((uint32_t *)irsp) + 7), ulp_word4, did); 4594 4595 switch (ulp_status) { 4596 case IOSTAT_FCP_RSP_ERROR: 4597 break; 4598 case IOSTAT_REMOTE_STOP: 4599 if (phba->sli_rev == LPFC_SLI_REV4) { 4600 /* This IO was aborted by the target, we don't 4601 * know the rxid and because we did not send the 4602 * ABTS we cannot generate and RRQ. 4603 */ 4604 lpfc_set_rrq_active(phba, ndlp, 4605 cmdiocb->sli4_lxritag, 0, 0); 4606 } 4607 break; 4608 case IOSTAT_LOCAL_REJECT: 4609 switch ((ulp_word4 & IOERR_PARAM_MASK)) { 4610 case IOERR_LOOP_OPEN_FAILURE: 4611 if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0) 4612 delay = 1000; 4613 retry = 1; 4614 break; 4615 4616 case IOERR_ILLEGAL_COMMAND: 4617 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, 4618 "0124 Retry illegal cmd x%x " 4619 "retry:x%x delay:x%x\n", 4620 cmd, cmdiocb->retry, delay); 4621 retry = 1; 4622 /* All command's retry policy */ 4623 maxretry = 8; 4624 if (cmdiocb->retry > 2) 4625 delay = 1000; 4626 break; 4627 4628 case IOERR_NO_RESOURCES: 4629 logerr = 1; /* HBA out of resources */ 4630 retry = 1; 4631 if (cmdiocb->retry > 100) 4632 delay = 100; 4633 maxretry = 250; 4634 break; 4635 4636 case IOERR_ILLEGAL_FRAME: 4637 delay = 100; 4638 retry = 1; 4639 break; 4640 4641 case IOERR_INVALID_RPI: 4642 if (cmd == ELS_CMD_PLOGI && 4643 did == NameServer_DID) { 4644 /* Continue forever if plogi to */ 4645 /* the nameserver fails */ 4646 maxretry = 0; 4647 delay = 100; 4648 } else if (cmd == ELS_CMD_PRLI && 4649 ndlp->nlp_state != NLP_STE_PRLI_ISSUE) { 4650 /* State-command disagreement. The PRLI was 4651 * failed with an invalid rpi meaning there 4652 * some unexpected state change. Don't retry. 4653 */ 4654 maxretry = 0; 4655 retry = 0; 4656 break; 4657 } 4658 retry = 1; 4659 break; 4660 4661 case IOERR_SEQUENCE_TIMEOUT: 4662 if (cmd == ELS_CMD_PLOGI && 4663 did == NameServer_DID && 4664 (cmdiocb->retry + 1) == maxretry) { 4665 /* Reset the Link */ 4666 link_reset = 1; 4667 break; 4668 } 4669 retry = 1; 4670 delay = 100; 4671 break; 4672 case IOERR_SLI_ABORTED: 4673 /* Retry ELS PLOGI command? 4674 * Possibly the rport just wasn't ready. 4675 */ 4676 if (cmd == ELS_CMD_PLOGI) { 4677 /* No retry if state change */ 4678 if (ndlp && 4679 ndlp->nlp_state != NLP_STE_PLOGI_ISSUE) 4680 goto out_retry; 4681 retry = 1; 4682 maxretry = 2; 4683 } 4684 break; 4685 } 4686 break; 4687 4688 case IOSTAT_NPORT_RJT: 4689 case IOSTAT_FABRIC_RJT: 4690 if (ulp_word4 & RJT_UNAVAIL_TEMP) { 4691 retry = 1; 4692 break; 4693 } 4694 break; 4695 4696 case IOSTAT_NPORT_BSY: 4697 case IOSTAT_FABRIC_BSY: 4698 logerr = 1; /* Fabric / Remote NPort out of resources */ 4699 retry = 1; 4700 break; 4701 4702 case IOSTAT_LS_RJT: 4703 stat.un.ls_rjt_error_be = cpu_to_be32(ulp_word4); 4704 /* Added for Vendor specifc support 4705 * Just keep retrying for these Rsn / Exp codes 4706 */ 4707 if (test_bit(FC_PT2PT, &vport->fc_flag) && 4708 cmd == ELS_CMD_NVMEPRLI) { 4709 switch (stat.un.b.lsRjtRsnCode) { 4710 case LSRJT_UNABLE_TPC: 4711 case LSRJT_INVALID_CMD: 4712 case LSRJT_LOGICAL_ERR: 4713 case LSRJT_CMD_UNSUPPORTED: 4714 lpfc_printf_vlog(vport, KERN_WARNING, LOG_ELS, 4715 "0168 NVME PRLI LS_RJT " 4716 "reason %x port doesn't " 4717 "support NVME, disabling NVME\n", 4718 stat.un.b.lsRjtRsnCode); 4719 retry = 0; 4720 set_bit(FC_PT2PT_NO_NVME, &vport->fc_flag); 4721 goto out_retry; 4722 } 4723 } 4724 switch (stat.un.b.lsRjtRsnCode) { 4725 case LSRJT_UNABLE_TPC: 4726 /* Special case for PRLI LS_RJTs. Recall that lpfc 4727 * uses a single routine to issue both PRLI FC4 types. 4728 * If the PRLI is rejected because that FC4 type 4729 * isn't really supported, don't retry and cause 4730 * multiple transport registrations. Otherwise, parse 4731 * the reason code/reason code explanation and take the 4732 * appropriate action. 4733 */ 4734 lpfc_printf_vlog(vport, KERN_INFO, 4735 LOG_DISCOVERY | LOG_ELS | LOG_NODE, 4736 "0153 ELS cmd x%x LS_RJT by x%x. " 4737 "RsnCode x%x RsnCodeExp x%x\n", 4738 cmd, did, stat.un.b.lsRjtRsnCode, 4739 stat.un.b.lsRjtRsnCodeExp); 4740 4741 switch (stat.un.b.lsRjtRsnCodeExp) { 4742 case LSEXP_CANT_GIVE_DATA: 4743 case LSEXP_CMD_IN_PROGRESS: 4744 if (cmd == ELS_CMD_PLOGI) { 4745 delay = 1000; 4746 maxretry = 48; 4747 } 4748 retry = 1; 4749 break; 4750 case LSEXP_REQ_UNSUPPORTED: 4751 case LSEXP_NO_RSRC_ASSIGN: 4752 /* These explanation codes get no retry. */ 4753 if (cmd == ELS_CMD_PRLI || 4754 cmd == ELS_CMD_NVMEPRLI) 4755 break; 4756 fallthrough; 4757 default: 4758 /* Limit the delay and retry action to a limited 4759 * cmd set. There are other ELS commands where 4760 * a retry is not expected. 4761 */ 4762 if (cmd == ELS_CMD_PLOGI || 4763 cmd == ELS_CMD_PRLI || 4764 cmd == ELS_CMD_NVMEPRLI) { 4765 delay = 1000; 4766 maxretry = lpfc_max_els_tries + 1; 4767 retry = 1; 4768 } 4769 break; 4770 } 4771 4772 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && 4773 (cmd == ELS_CMD_FDISC) && 4774 (stat.un.b.lsRjtRsnCodeExp == LSEXP_OUT_OF_RESOURCE)){ 4775 lpfc_vlog_msg(vport, KERN_WARNING, LOG_ELS, 4776 "0125 FDISC (x%x). " 4777 "Fabric out of resources\n", 4778 stat.un.lsRjtError); 4779 lpfc_vport_set_state(vport, 4780 FC_VPORT_NO_FABRIC_RSCS); 4781 } 4782 break; 4783 4784 case LSRJT_LOGICAL_BSY: 4785 rsn_code_exp = stat.un.b.lsRjtRsnCodeExp; 4786 if ((cmd == ELS_CMD_PLOGI) || 4787 (cmd == ELS_CMD_PRLI) || 4788 (cmd == ELS_CMD_NVMEPRLI)) { 4789 delay = 1000; 4790 maxretry = 48; 4791 4792 /* An authentication LS_RJT reason code 4793 * explanation means some error in the 4794 * security settings end-to-end. Reduce 4795 * the retry count to allow lpfc to clear 4796 * RSCN mode and not race with dev_loss. 4797 */ 4798 if (cmd == ELS_CMD_PLOGI && 4799 rsn_code_exp == LSEXP_AUTH_REQ) 4800 maxretry = 8; 4801 } else if (cmd == ELS_CMD_FDISC) { 4802 /* FDISC retry policy */ 4803 maxretry = 48; 4804 if (cmdiocb->retry >= 32) 4805 delay = 1000; 4806 } 4807 retry = 1; 4808 break; 4809 4810 case LSRJT_LOGICAL_ERR: 4811 /* There are some cases where switches return this 4812 * error when they are not ready and should be returning 4813 * Logical Busy. We should delay every time. 4814 */ 4815 if (cmd == ELS_CMD_FDISC && 4816 stat.un.b.lsRjtRsnCodeExp == LSEXP_PORT_LOGIN_REQ) { 4817 maxretry = 3; 4818 delay = 1000; 4819 retry = 1; 4820 } else if (cmd == ELS_CMD_FLOGI && 4821 stat.un.b.lsRjtRsnCodeExp == 4822 LSEXP_NOTHING_MORE) { 4823 vport->fc_sparam.cmn.bbRcvSizeMsb &= 0xf; 4824 retry = 1; 4825 lpfc_vlog_msg(vport, KERN_WARNING, LOG_ELS, 4826 "0820 FLOGI (x%x). " 4827 "BBCredit Not Supported\n", 4828 stat.un.lsRjtError); 4829 } else if (cmd == ELS_CMD_PLOGI) { 4830 rsn_code_exp = stat.un.b.lsRjtRsnCodeExp; 4831 4832 /* An authentication LS_RJT reason code 4833 * explanation means some error in the 4834 * security settings end-to-end. Reduce 4835 * the retry count to allow lpfc to clear 4836 * RSCN mode and not race with dev_loss. 4837 */ 4838 if (rsn_code_exp == LSEXP_AUTH_REQ) { 4839 delay = 1000; 4840 retry = 1; 4841 maxretry = 8; 4842 } 4843 } 4844 break; 4845 4846 case LSRJT_PROTOCOL_ERR: 4847 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && 4848 (cmd == ELS_CMD_FDISC) && 4849 ((stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_PNAME) || 4850 (stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_NPORT_ID)) 4851 ) { 4852 lpfc_vlog_msg(vport, KERN_WARNING, LOG_ELS, 4853 "0122 FDISC (x%x). " 4854 "Fabric Detected Bad WWN\n", 4855 stat.un.lsRjtError); 4856 lpfc_vport_set_state(vport, 4857 FC_VPORT_FABRIC_REJ_WWN); 4858 } 4859 break; 4860 case LSRJT_VENDOR_UNIQUE: 4861 if ((stat.un.b.vendorUnique == 0x45) && 4862 (cmd == ELS_CMD_FLOGI)) { 4863 goto out_retry; 4864 } 4865 break; 4866 case LSRJT_CMD_UNSUPPORTED: 4867 /* lpfc nvmet returns this type of LS_RJT when it 4868 * receives an FCP PRLI because lpfc nvmet only 4869 * support NVME. ELS request is terminated for FCP4 4870 * on this rport. 4871 */ 4872 if (stat.un.b.lsRjtRsnCodeExp == 4873 LSEXP_REQ_UNSUPPORTED) { 4874 if (cmd == ELS_CMD_PRLI) 4875 goto out_retry; 4876 } 4877 break; 4878 } 4879 break; 4880 4881 case IOSTAT_INTERMED_RSP: 4882 case IOSTAT_BA_RJT: 4883 break; 4884 4885 default: 4886 break; 4887 } 4888 4889 if (link_reset) { 4890 rc = lpfc_link_reset(vport); 4891 if (rc) { 4892 /* Do not give up. Retry PLOGI one more time and attempt 4893 * link reset if PLOGI fails again. 4894 */ 4895 retry = 1; 4896 delay = 100; 4897 goto out_retry; 4898 } 4899 return 1; 4900 } 4901 4902 if (did == FDMI_DID) 4903 retry = 1; 4904 4905 if ((cmd == ELS_CMD_FLOGI) && 4906 (phba->fc_topology != LPFC_TOPOLOGY_LOOP) && 4907 !lpfc_error_lost_link(vport, ulp_status, ulp_word4)) { 4908 /* FLOGI retry policy */ 4909 retry = 1; 4910 /* retry FLOGI forever */ 4911 if (phba->link_flag != LS_LOOPBACK_MODE) 4912 maxretry = 0; 4913 else 4914 maxretry = 2; 4915 4916 if (cmdiocb->retry >= 100) 4917 delay = 5000; 4918 else if (cmdiocb->retry >= 32) 4919 delay = 1000; 4920 } else if ((cmd == ELS_CMD_FDISC) && 4921 !lpfc_error_lost_link(vport, ulp_status, ulp_word4)) { 4922 /* retry FDISCs every second up to devloss */ 4923 retry = 1; 4924 maxretry = vport->cfg_devloss_tmo; 4925 delay = 1000; 4926 } 4927 4928 cmdiocb->retry++; 4929 if (maxretry && (cmdiocb->retry >= maxretry)) { 4930 phba->fc_stat.elsRetryExceeded++; 4931 retry = 0; 4932 } 4933 4934 if (test_bit(FC_UNLOADING, &vport->load_flag)) 4935 retry = 0; 4936 4937 out_retry: 4938 if (retry) { 4939 if ((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_FDISC)) { 4940 /* Stop retrying PLOGI and FDISC if in FCF discovery */ 4941 if (phba->fcf.fcf_flag & FCF_DISCOVERY) { 4942 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, 4943 "2849 Stop retry ELS command " 4944 "x%x to remote NPORT x%x, " 4945 "Data: x%x x%x\n", cmd, did, 4946 cmdiocb->retry, delay); 4947 return 0; 4948 } 4949 } 4950 4951 /* Retry ELS command <elsCmd> to remote NPORT <did> */ 4952 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, 4953 "0107 Retry ELS command x%x to remote " 4954 "NPORT x%x Data: x%x x%x\n", 4955 cmd, did, cmdiocb->retry, delay); 4956 4957 if (((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) && 4958 ((ulp_status != IOSTAT_LOCAL_REJECT) || 4959 ((ulp_word4 & IOERR_PARAM_MASK) != 4960 IOERR_NO_RESOURCES))) { 4961 /* Don't reset timer for no resources */ 4962 4963 /* If discovery / RSCN timer is running, reset it */ 4964 if (timer_pending(&vport->fc_disctmo) || 4965 test_bit(FC_RSCN_MODE, &vport->fc_flag)) 4966 lpfc_set_disctmo(vport); 4967 } 4968 4969 phba->fc_stat.elsXmitRetry++; 4970 if (ndlp && delay) { 4971 phba->fc_stat.elsDelayRetry++; 4972 ndlp->nlp_retry = cmdiocb->retry; 4973 4974 /* delay is specified in milliseconds */ 4975 mod_timer(&ndlp->nlp_delayfunc, 4976 jiffies + msecs_to_jiffies(delay)); 4977 set_bit(NLP_DELAY_TMO, &ndlp->nlp_flag); 4978 4979 ndlp->nlp_prev_state = ndlp->nlp_state; 4980 if ((cmd == ELS_CMD_PRLI) || 4981 (cmd == ELS_CMD_NVMEPRLI)) 4982 lpfc_nlp_set_state(vport, ndlp, 4983 NLP_STE_PRLI_ISSUE); 4984 else if (cmd != ELS_CMD_ADISC) 4985 lpfc_nlp_set_state(vport, ndlp, 4986 NLP_STE_NPR_NODE); 4987 ndlp->nlp_last_elscmd = cmd; 4988 4989 return 1; 4990 } 4991 switch (cmd) { 4992 case ELS_CMD_FLOGI: 4993 lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry); 4994 return 1; 4995 case ELS_CMD_FDISC: 4996 lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry); 4997 return 1; 4998 case ELS_CMD_PLOGI: 4999 if (ndlp) { 5000 ndlp->nlp_prev_state = ndlp->nlp_state; 5001 lpfc_nlp_set_state(vport, ndlp, 5002 NLP_STE_PLOGI_ISSUE); 5003 } 5004 lpfc_issue_els_plogi(vport, did, cmdiocb->retry); 5005 return 1; 5006 case ELS_CMD_ADISC: 5007 ndlp->nlp_prev_state = ndlp->nlp_state; 5008 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE); 5009 lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry); 5010 return 1; 5011 case ELS_CMD_PRLI: 5012 case ELS_CMD_NVMEPRLI: 5013 ndlp->nlp_prev_state = ndlp->nlp_state; 5014 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE); 5015 lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry); 5016 return 1; 5017 case ELS_CMD_LOGO: 5018 ndlp->nlp_prev_state = ndlp->nlp_state; 5019 lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE); 5020 lpfc_issue_els_logo(vport, ndlp, cmdiocb->retry); 5021 return 1; 5022 } 5023 } 5024 /* No retry ELS command <elsCmd> to remote NPORT <did> */ 5025 if (logerr) { 5026 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, 5027 "0137 No retry ELS command x%x to remote " 5028 "NPORT x%x: Out of Resources: Error:x%x/%x " 5029 "IoTag x%x\n", 5030 cmd, did, ulp_status, ulp_word4, 5031 cmdiocb->iotag); 5032 } 5033 else { 5034 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, 5035 "0108 No retry ELS command x%x to remote " 5036 "NPORT x%x Retried:%d Error:x%x/%x " 5037 "IoTag x%x nflags x%lx\n", 5038 cmd, did, cmdiocb->retry, ulp_status, 5039 ulp_word4, cmdiocb->iotag, 5040 (ndlp ? ndlp->nlp_flag : 0)); 5041 } 5042 return 0; 5043 } 5044 5045 /** 5046 * lpfc_els_free_data - Free lpfc dma buffer and data structure with an iocb 5047 * @phba: pointer to lpfc hba data structure. 5048 * @buf_ptr1: pointer to the lpfc DMA buffer data structure. 5049 * 5050 * This routine releases the lpfc DMA (Direct Memory Access) buffer(s) 5051 * associated with a command IOCB back to the lpfc DMA buffer pool. It first 5052 * checks to see whether there is a lpfc DMA buffer associated with the 5053 * response of the command IOCB. If so, it will be released before releasing 5054 * the lpfc DMA buffer associated with the IOCB itself. 5055 * 5056 * Return code 5057 * 0 - Successfully released lpfc DMA buffer (currently, always return 0) 5058 **/ 5059 static int 5060 lpfc_els_free_data(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr1) 5061 { 5062 struct lpfc_dmabuf *buf_ptr; 5063 5064 /* Free the response before processing the command. */ 5065 if (!list_empty(&buf_ptr1->list)) { 5066 list_remove_head(&buf_ptr1->list, buf_ptr, 5067 struct lpfc_dmabuf, 5068 list); 5069 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); 5070 kfree(buf_ptr); 5071 } 5072 lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys); 5073 kfree(buf_ptr1); 5074 return 0; 5075 } 5076 5077 /** 5078 * lpfc_els_free_bpl - Free lpfc dma buffer and data structure with bpl 5079 * @phba: pointer to lpfc hba data structure. 5080 * @buf_ptr: pointer to the lpfc dma buffer data structure. 5081 * 5082 * This routine releases the lpfc Direct Memory Access (DMA) buffer 5083 * associated with a Buffer Pointer List (BPL) back to the lpfc DMA buffer 5084 * pool. 5085 * 5086 * Return code 5087 * 0 - Successfully released lpfc DMA buffer (currently, always return 0) 5088 **/ 5089 static int 5090 lpfc_els_free_bpl(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr) 5091 { 5092 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); 5093 kfree(buf_ptr); 5094 return 0; 5095 } 5096 5097 /** 5098 * lpfc_els_free_iocb - Free a command iocb and its associated resources 5099 * @phba: pointer to lpfc hba data structure. 5100 * @elsiocb: pointer to lpfc els command iocb data structure. 5101 * 5102 * This routine frees a command IOCB and its associated resources. The 5103 * command IOCB data structure contains the reference to various associated 5104 * resources, these fields must be set to NULL if the associated reference 5105 * not present: 5106 * cmd_dmabuf - reference to cmd. 5107 * cmd_dmabuf->next - reference to rsp 5108 * rsp_dmabuf - unused 5109 * bpl_dmabuf - reference to bpl 5110 * 5111 * It first properly decrements the reference count held on ndlp for the 5112 * IOCB completion callback function. If LPFC_DELAY_MEM_FREE flag is not 5113 * set, it invokes the lpfc_els_free_data() routine to release the Direct 5114 * Memory Access (DMA) buffers associated with the IOCB. Otherwise, it 5115 * adds the DMA buffer the @phba data structure for the delayed release. 5116 * If reference to the Buffer Pointer List (BPL) is present, the 5117 * lpfc_els_free_bpl() routine is invoked to release the DMA memory 5118 * associated with BPL. Finally, the lpfc_sli_release_iocbq() routine is 5119 * invoked to release the IOCB data structure back to @phba IOCBQ list. 5120 * 5121 * Return code 5122 * 0 - Success (currently, always return 0) 5123 **/ 5124 int 5125 lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb) 5126 { 5127 struct lpfc_dmabuf *buf_ptr, *buf_ptr1; 5128 5129 /* The I/O iocb is complete. Clear the node and first dmbuf */ 5130 elsiocb->ndlp = NULL; 5131 5132 /* cmd_dmabuf = cmd, cmd_dmabuf->next = rsp, bpl_dmabuf = bpl */ 5133 if (elsiocb->cmd_dmabuf) { 5134 if (elsiocb->cmd_flag & LPFC_DELAY_MEM_FREE) { 5135 /* Firmware could still be in progress of DMAing 5136 * payload, so don't free data buffer till after 5137 * a hbeat. 5138 */ 5139 elsiocb->cmd_flag &= ~LPFC_DELAY_MEM_FREE; 5140 buf_ptr = elsiocb->cmd_dmabuf; 5141 elsiocb->cmd_dmabuf = NULL; 5142 if (buf_ptr) { 5143 buf_ptr1 = NULL; 5144 spin_lock_irq(&phba->hbalock); 5145 if (!list_empty(&buf_ptr->list)) { 5146 list_remove_head(&buf_ptr->list, 5147 buf_ptr1, struct lpfc_dmabuf, 5148 list); 5149 INIT_LIST_HEAD(&buf_ptr1->list); 5150 list_add_tail(&buf_ptr1->list, 5151 &phba->elsbuf); 5152 phba->elsbuf_cnt++; 5153 } 5154 INIT_LIST_HEAD(&buf_ptr->list); 5155 list_add_tail(&buf_ptr->list, &phba->elsbuf); 5156 phba->elsbuf_cnt++; 5157 spin_unlock_irq(&phba->hbalock); 5158 } 5159 } else { 5160 buf_ptr1 = elsiocb->cmd_dmabuf; 5161 lpfc_els_free_data(phba, buf_ptr1); 5162 elsiocb->cmd_dmabuf = NULL; 5163 } 5164 } 5165 5166 if (elsiocb->bpl_dmabuf) { 5167 buf_ptr = elsiocb->bpl_dmabuf; 5168 lpfc_els_free_bpl(phba, buf_ptr); 5169 elsiocb->bpl_dmabuf = NULL; 5170 } 5171 lpfc_sli_release_iocbq(phba, elsiocb); 5172 return 0; 5173 } 5174 5175 /** 5176 * lpfc_cmpl_els_logo_acc - Completion callback function to logo acc response 5177 * @phba: pointer to lpfc hba data structure. 5178 * @cmdiocb: pointer to lpfc command iocb data structure. 5179 * @rspiocb: pointer to lpfc response iocb data structure. 5180 * 5181 * This routine is the completion callback function to the Logout (LOGO) 5182 * Accept (ACC) Response ELS command. This routine is invoked to indicate 5183 * the completion of the LOGO process. If the node has transitioned to NPR, 5184 * this routine unregisters the RPI if it is still registered. The 5185 * lpfc_els_free_iocb() is invoked to release the IOCB data structure. 5186 **/ 5187 static void 5188 lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, 5189 struct lpfc_iocbq *rspiocb) 5190 { 5191 struct lpfc_nodelist *ndlp = cmdiocb->ndlp; 5192 struct lpfc_vport *vport = cmdiocb->vport; 5193 u32 ulp_status, ulp_word4; 5194 5195 ulp_status = get_job_ulpstatus(phba, rspiocb); 5196 ulp_word4 = get_job_word4(phba, rspiocb); 5197 5198 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, 5199 "ACC LOGO cmpl: status:x%x/x%x did:x%x", 5200 ulp_status, ulp_word4, ndlp->nlp_DID); 5201 /* ACC to LOGO completes to NPort <nlp_DID> */ 5202 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, 5203 "0109 ACC to LOGO completes to NPort x%x refcnt %d " 5204 "last els x%x Data: x%lx x%x x%x\n", 5205 ndlp->nlp_DID, kref_read(&ndlp->kref), 5206 ndlp->nlp_last_elscmd, ndlp->nlp_flag, ndlp->nlp_state, 5207 ndlp->nlp_rpi); 5208 5209 /* This clause allows the LOGO ACC to complete and free resources 5210 * for the Fabric Domain Controller. It does deliberately skip 5211 * the unreg_rpi and release rpi because some fabrics send RDP 5212 * requests after logging out from the initiator. 5213 */ 5214 if (ndlp->nlp_type & NLP_FABRIC && 5215 ((ndlp->nlp_DID & WELL_KNOWN_DID_MASK) != WELL_KNOWN_DID_MASK)) 5216 goto out; 5217 5218 if (ndlp->nlp_state == NLP_STE_NPR_NODE) { 5219 if (test_bit(NLP_RPI_REGISTERED, &ndlp->nlp_flag)) 5220 lpfc_unreg_rpi(vport, ndlp); 5221 5222 /* If came from PRLO, then PRLO_ACC is done. 5223 * Start rediscovery now. 5224 */ 5225 if (ndlp->nlp_last_elscmd == ELS_CMD_PRLO) { 5226 set_bit(NLP_NPR_2B_DISC, &ndlp->nlp_flag); 5227 ndlp->nlp_prev_state = ndlp->nlp_state; 5228 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); 5229 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0); 5230 } 5231 } 5232 5233 out: 5234 /* 5235 * The driver received a LOGO from the rport and has ACK'd it. 5236 * At this point, the driver is done so release the IOCB 5237 */ 5238 lpfc_els_free_iocb(phba, cmdiocb); 5239 lpfc_nlp_put(ndlp); 5240 } 5241 5242 /** 5243 * lpfc_mbx_cmpl_dflt_rpi - Completion callbk func for unreg dflt rpi mbox cmd 5244 * @phba: pointer to lpfc hba data structure. 5245 * @pmb: pointer to the driver internal queue element for mailbox command. 5246 * 5247 * This routine is the completion callback function for unregister default 5248 * RPI (Remote Port Index) mailbox command to the @phba. It simply releases 5249 * the associated lpfc Direct Memory Access (DMA) buffer back to the pool and 5250 * decrements the ndlp reference count held for this completion callback 5251 * function. After that, it invokes the lpfc_drop_node to check 5252 * whether it is appropriate to release the node. 5253 **/ 5254 void 5255 lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) 5256 { 5257 struct lpfc_nodelist *ndlp = pmb->ctx_ndlp; 5258 u32 mbx_flag = pmb->mbox_flag; 5259 u32 mbx_cmd = pmb->u.mb.mbxCommand; 5260 5261 if (ndlp) { 5262 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE, 5263 "0006 rpi x%x DID:%x flg:%lx %d x%px " 5264 "mbx_cmd x%x mbx_flag x%x x%px\n", 5265 ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag, 5266 kref_read(&ndlp->kref), ndlp, mbx_cmd, 5267 mbx_flag, pmb); 5268 5269 /* This ends the default/temporary RPI cleanup logic for this 5270 * ndlp and the node and rpi needs to be released. Free the rpi 5271 * first on an UNREG_LOGIN and then release the final 5272 * references. 5273 */ 5274 clear_bit(NLP_REG_LOGIN_SEND, &ndlp->nlp_flag); 5275 if (mbx_cmd == MBX_UNREG_LOGIN) 5276 clear_bit(NLP_UNREG_INP, &ndlp->nlp_flag); 5277 lpfc_nlp_put(ndlp); 5278 lpfc_drop_node(ndlp->vport, ndlp); 5279 } 5280 5281 lpfc_mbox_rsrc_cleanup(phba, pmb, MBOX_THD_UNLOCKED); 5282 } 5283 5284 /** 5285 * lpfc_cmpl_els_rsp - Completion callback function for els response iocb cmd 5286 * @phba: pointer to lpfc hba data structure. 5287 * @cmdiocb: pointer to lpfc command iocb data structure. 5288 * @rspiocb: pointer to lpfc response iocb data structure. 5289 * 5290 * This routine is the completion callback function for ELS Response IOCB 5291 * command. In normal case, this callback function just properly sets the 5292 * nlp_flag bitmap in the ndlp data structure, if the mbox command reference 5293 * field in the command IOCB is not NULL, the referred mailbox command will 5294 * be send out, and then invokes the lpfc_els_free_iocb() routine to release 5295 * the IOCB. 5296 **/ 5297 static void 5298 lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, 5299 struct lpfc_iocbq *rspiocb) 5300 { 5301 struct lpfc_nodelist *ndlp = cmdiocb->ndlp; 5302 struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL; 5303 struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL; 5304 IOCB_t *irsp; 5305 LPFC_MBOXQ_t *mbox = NULL; 5306 u32 ulp_status, ulp_word4, tmo, did, iotag; 5307 5308 if (!vport) { 5309 lpfc_printf_log(phba, KERN_WARNING, LOG_ELS, 5310 "3177 null vport in ELS rsp\n"); 5311 goto out; 5312 } 5313 if (cmdiocb->context_un.mbox) 5314 mbox = cmdiocb->context_un.mbox; 5315 5316 ulp_status = get_job_ulpstatus(phba, rspiocb); 5317 ulp_word4 = get_job_word4(phba, rspiocb); 5318 did = get_job_els_rsp64_did(phba, cmdiocb); 5319 5320 if (phba->sli_rev == LPFC_SLI_REV4) { 5321 tmo = get_wqe_tmo(cmdiocb); 5322 iotag = get_wqe_reqtag(cmdiocb); 5323 } else { 5324 irsp = &rspiocb->iocb; 5325 tmo = irsp->ulpTimeout; 5326 iotag = irsp->ulpIoTag; 5327 } 5328 5329 /* Check to see if link went down during discovery */ 5330 if (!ndlp || lpfc_els_chk_latt(vport)) { 5331 if (mbox) 5332 lpfc_mbox_rsrc_cleanup(phba, mbox, MBOX_THD_UNLOCKED); 5333 goto out; 5334 } 5335 5336 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, 5337 "ELS rsp cmpl: status:x%x/x%x did:x%x", 5338 ulp_status, ulp_word4, did); 5339 /* ELS response tag <ulpIoTag> completes */ 5340 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, 5341 "0110 ELS response tag x%x completes " 5342 "Data: x%x x%x x%x x%x x%lx x%x x%x x%x %p %p\n", 5343 iotag, ulp_status, ulp_word4, tmo, 5344 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, 5345 ndlp->nlp_rpi, kref_read(&ndlp->kref), mbox, ndlp); 5346 if (mbox) { 5347 if (ulp_status == 0 && 5348 test_bit(NLP_ACC_REGLOGIN, &ndlp->nlp_flag)) { 5349 if (!lpfc_unreg_rpi(vport, ndlp) && 5350 !test_bit(FC_PT2PT, &vport->fc_flag)) { 5351 if (ndlp->nlp_state == NLP_STE_PLOGI_ISSUE || 5352 ndlp->nlp_state == 5353 NLP_STE_REG_LOGIN_ISSUE) { 5354 lpfc_printf_vlog(vport, KERN_INFO, 5355 LOG_DISCOVERY, 5356 "0314 PLOGI recov " 5357 "DID x%x " 5358 "Data: x%x x%x x%lx\n", 5359 ndlp->nlp_DID, 5360 ndlp->nlp_state, 5361 ndlp->nlp_rpi, 5362 ndlp->nlp_flag); 5363 goto out_free_mbox; 5364 } 5365 } 5366 5367 /* Increment reference count to ndlp to hold the 5368 * reference to ndlp for the callback function. 5369 */ 5370 mbox->ctx_ndlp = lpfc_nlp_get(ndlp); 5371 if (!mbox->ctx_ndlp) 5372 goto out_free_mbox; 5373 5374 mbox->vport = vport; 5375 if (test_bit(NLP_RM_DFLT_RPI, &ndlp->nlp_flag)) { 5376 mbox->mbox_flag |= LPFC_MBX_IMED_UNREG; 5377 mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi; 5378 } else { 5379 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login; 5380 ndlp->nlp_prev_state = ndlp->nlp_state; 5381 lpfc_nlp_set_state(vport, ndlp, 5382 NLP_STE_REG_LOGIN_ISSUE); 5383 } 5384 5385 set_bit(NLP_REG_LOGIN_SEND, &ndlp->nlp_flag); 5386 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) 5387 != MBX_NOT_FINISHED) 5388 goto out; 5389 5390 /* Decrement the ndlp reference count we 5391 * set for this failed mailbox command. 5392 */ 5393 lpfc_nlp_put(ndlp); 5394 clear_bit(NLP_REG_LOGIN_SEND, &ndlp->nlp_flag); 5395 5396 /* ELS rsp: Cannot issue reg_login for <NPortid> */ 5397 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, 5398 "0138 ELS rsp: Cannot issue reg_login for x%x " 5399 "Data: x%lx x%x x%x\n", 5400 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, 5401 ndlp->nlp_rpi); 5402 } 5403 out_free_mbox: 5404 lpfc_mbox_rsrc_cleanup(phba, mbox, MBOX_THD_UNLOCKED); 5405 } 5406 out: 5407 if (ndlp && shost) { 5408 if (mbox) 5409 clear_bit(NLP_ACC_REGLOGIN, &ndlp->nlp_flag); 5410 clear_bit(NLP_RM_DFLT_RPI, &ndlp->nlp_flag); 5411 } 5412 5413 /* An SLI4 NPIV instance wants to drop the node at this point under 5414 * these conditions because it doesn't need the login. 5415 */ 5416 if (phba->sli_rev == LPFC_SLI_REV4 && 5417 vport && vport->port_type == LPFC_NPIV_PORT && 5418 !(ndlp->fc4_xpt_flags & SCSI_XPT_REGD)) { 5419 if (ndlp->nlp_state != NLP_STE_PLOGI_ISSUE && 5420 ndlp->nlp_state != NLP_STE_REG_LOGIN_ISSUE && 5421 ndlp->nlp_state != NLP_STE_PRLI_ISSUE) { 5422 /* Drop ndlp if there is no planned or outstanding 5423 * issued PRLI. 5424 * 5425 * In cases when the ndlp is acting as both an initiator 5426 * and target function, let our issued PRLI determine 5427 * the final ndlp kref drop. 5428 */ 5429 lpfc_drop_node(vport, ndlp); 5430 } 5431 } 5432 5433 /* Release the originating I/O reference. */ 5434 lpfc_els_free_iocb(phba, cmdiocb); 5435 lpfc_nlp_put(ndlp); 5436 return; 5437 } 5438 5439 /** 5440 * lpfc_els_rsp_acc - Prepare and issue an acc response iocb command 5441 * @vport: pointer to a host virtual N_Port data structure. 5442 * @flag: the els command code to be accepted. 5443 * @oldiocb: pointer to the original lpfc command iocb data structure. 5444 * @ndlp: pointer to a node-list data structure. 5445 * @mbox: pointer to the driver internal queue element for mailbox command. 5446 * 5447 * This routine prepares and issues an Accept (ACC) response IOCB 5448 * command. It uses the @flag to properly set up the IOCB field for the 5449 * specific ACC response command to be issued and invokes the 5450 * lpfc_sli_issue_iocb() routine to send out ACC response IOCB. If a 5451 * @mbox pointer is passed in, it will be put into the context_un.mbox 5452 * field of the IOCB for the completion callback function to issue the 5453 * mailbox command to the HBA later when callback is invoked. 5454 * 5455 * Note that the ndlp reference count will be incremented by 1 for holding the 5456 * ndlp and the reference to ndlp will be stored into the ndlp field of 5457 * the IOCB for the completion callback function to the corresponding 5458 * response ELS IOCB command. 5459 * 5460 * Return code 5461 * 0 - Successfully issued acc response 5462 * 1 - Failed to issue acc response 5463 **/ 5464 int 5465 lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag, 5466 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp, 5467 LPFC_MBOXQ_t *mbox) 5468 { 5469 struct lpfc_hba *phba = vport->phba; 5470 IOCB_t *icmd; 5471 IOCB_t *oldcmd; 5472 union lpfc_wqe128 *wqe; 5473 union lpfc_wqe128 *oldwqe = &oldiocb->wqe; 5474 struct lpfc_iocbq *elsiocb; 5475 uint8_t *pcmd; 5476 struct serv_parm *sp; 5477 uint16_t cmdsize; 5478 int rc; 5479 ELS_PKT *els_pkt_ptr; 5480 struct fc_els_rdf_resp *rdf_resp; 5481 5482 switch (flag) { 5483 case ELS_CMD_ACC: 5484 cmdsize = sizeof(uint32_t); 5485 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, 5486 ndlp, ndlp->nlp_DID, ELS_CMD_ACC); 5487 if (!elsiocb) { 5488 clear_bit(NLP_LOGO_ACC, &ndlp->nlp_flag); 5489 return 1; 5490 } 5491 5492 if (phba->sli_rev == LPFC_SLI_REV4) { 5493 wqe = &elsiocb->wqe; 5494 /* XRI / rx_id */ 5495 bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com, 5496 bf_get(wqe_ctxt_tag, 5497 &oldwqe->xmit_els_rsp.wqe_com)); 5498 5499 /* oxid */ 5500 bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com, 5501 bf_get(wqe_rcvoxid, 5502 &oldwqe->xmit_els_rsp.wqe_com)); 5503 } else { 5504 icmd = &elsiocb->iocb; 5505 oldcmd = &oldiocb->iocb; 5506 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */ 5507 icmd->unsli3.rcvsli3.ox_id = 5508 oldcmd->unsli3.rcvsli3.ox_id; 5509 } 5510 5511 pcmd = elsiocb->cmd_dmabuf->virt; 5512 *((uint32_t *) (pcmd)) = ELS_CMD_ACC; 5513 pcmd += sizeof(uint32_t); 5514 5515 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, 5516 "Issue ACC: did:x%x flg:x%lx", 5517 ndlp->nlp_DID, ndlp->nlp_flag, 0); 5518 break; 5519 case ELS_CMD_FLOGI: 5520 case ELS_CMD_PLOGI: 5521 cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t)); 5522 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, 5523 ndlp, ndlp->nlp_DID, ELS_CMD_ACC); 5524 if (!elsiocb) 5525 return 1; 5526 5527 if (phba->sli_rev == LPFC_SLI_REV4) { 5528 wqe = &elsiocb->wqe; 5529 /* XRI / rx_id */ 5530 bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com, 5531 bf_get(wqe_ctxt_tag, 5532 &oldwqe->xmit_els_rsp.wqe_com)); 5533 5534 /* oxid */ 5535 bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com, 5536 bf_get(wqe_rcvoxid, 5537 &oldwqe->xmit_els_rsp.wqe_com)); 5538 } else { 5539 icmd = &elsiocb->iocb; 5540 oldcmd = &oldiocb->iocb; 5541 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */ 5542 icmd->unsli3.rcvsli3.ox_id = 5543 oldcmd->unsli3.rcvsli3.ox_id; 5544 } 5545 5546 pcmd = (u8 *)elsiocb->cmd_dmabuf->virt; 5547 5548 if (mbox) 5549 elsiocb->context_un.mbox = mbox; 5550 5551 *((uint32_t *) (pcmd)) = ELS_CMD_ACC; 5552 pcmd += sizeof(uint32_t); 5553 sp = (struct serv_parm *)pcmd; 5554 5555 if (flag == ELS_CMD_FLOGI) { 5556 /* Copy the received service parameters back */ 5557 memcpy(sp, &phba->fc_fabparam, 5558 sizeof(struct serv_parm)); 5559 5560 /* Clear the F_Port bit */ 5561 sp->cmn.fPort = 0; 5562 5563 /* Mark all class service parameters as invalid */ 5564 sp->cls1.classValid = 0; 5565 sp->cls2.classValid = 0; 5566 sp->cls3.classValid = 0; 5567 sp->cls4.classValid = 0; 5568 5569 /* Copy our worldwide names */ 5570 memcpy(&sp->portName, &vport->fc_sparam.portName, 5571 sizeof(struct lpfc_name)); 5572 memcpy(&sp->nodeName, &vport->fc_sparam.nodeName, 5573 sizeof(struct lpfc_name)); 5574 } else { 5575 memcpy(pcmd, &vport->fc_sparam, 5576 sizeof(struct serv_parm)); 5577 5578 sp->cmn.valid_vendor_ver_level = 0; 5579 memset(sp->un.vendorVersion, 0, 5580 sizeof(sp->un.vendorVersion)); 5581 sp->cmn.bbRcvSizeMsb &= 0xF; 5582 5583 /* If our firmware supports this feature, convey that 5584 * info to the target using the vendor specific field. 5585 */ 5586 if (phba->sli.sli_flag & LPFC_SLI_SUPPRESS_RSP) { 5587 sp->cmn.valid_vendor_ver_level = 1; 5588 sp->un.vv.vid = cpu_to_be32(LPFC_VV_EMLX_ID); 5589 sp->un.vv.flags = 5590 cpu_to_be32(LPFC_VV_SUPPRESS_RSP); 5591 } 5592 } 5593 5594 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, 5595 "Issue ACC FLOGI/PLOGI: did:x%x flg:x%lx", 5596 ndlp->nlp_DID, ndlp->nlp_flag, 0); 5597 break; 5598 case ELS_CMD_PRLO: 5599 cmdsize = sizeof(uint32_t) + sizeof(PRLO); 5600 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, 5601 ndlp, ndlp->nlp_DID, ELS_CMD_PRLO); 5602 if (!elsiocb) 5603 return 1; 5604 5605 if (phba->sli_rev == LPFC_SLI_REV4) { 5606 wqe = &elsiocb->wqe; 5607 /* XRI / rx_id */ 5608 bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com, 5609 bf_get(wqe_ctxt_tag, 5610 &oldwqe->xmit_els_rsp.wqe_com)); 5611 5612 /* oxid */ 5613 bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com, 5614 bf_get(wqe_rcvoxid, 5615 &oldwqe->xmit_els_rsp.wqe_com)); 5616 } else { 5617 icmd = &elsiocb->iocb; 5618 oldcmd = &oldiocb->iocb; 5619 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */ 5620 icmd->unsli3.rcvsli3.ox_id = 5621 oldcmd->unsli3.rcvsli3.ox_id; 5622 } 5623 5624 pcmd = (u8 *) elsiocb->cmd_dmabuf->virt; 5625 5626 memcpy(pcmd, oldiocb->cmd_dmabuf->virt, 5627 sizeof(uint32_t) + sizeof(PRLO)); 5628 *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC; 5629 els_pkt_ptr = (ELS_PKT *) pcmd; 5630 els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED; 5631 5632 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, 5633 "Issue ACC PRLO: did:x%x flg:x%lx", 5634 ndlp->nlp_DID, ndlp->nlp_flag, 0); 5635 break; 5636 case ELS_CMD_RDF: 5637 cmdsize = sizeof(*rdf_resp); 5638 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, 5639 ndlp, ndlp->nlp_DID, ELS_CMD_ACC); 5640 if (!elsiocb) 5641 return 1; 5642 5643 if (phba->sli_rev == LPFC_SLI_REV4) { 5644 wqe = &elsiocb->wqe; 5645 /* XRI / rx_id */ 5646 bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com, 5647 bf_get(wqe_ctxt_tag, 5648 &oldwqe->xmit_els_rsp.wqe_com)); 5649 5650 /* oxid */ 5651 bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com, 5652 bf_get(wqe_rcvoxid, 5653 &oldwqe->xmit_els_rsp.wqe_com)); 5654 } else { 5655 icmd = &elsiocb->iocb; 5656 oldcmd = &oldiocb->iocb; 5657 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */ 5658 icmd->unsli3.rcvsli3.ox_id = 5659 oldcmd->unsli3.rcvsli3.ox_id; 5660 } 5661 5662 pcmd = (u8 *)elsiocb->cmd_dmabuf->virt; 5663 rdf_resp = (struct fc_els_rdf_resp *)pcmd; 5664 memset(rdf_resp, 0, sizeof(*rdf_resp)); 5665 rdf_resp->acc_hdr.la_cmd = ELS_LS_ACC; 5666 5667 /* FC-LS-5 specifies desc_list_len shall be set to 12 */ 5668 rdf_resp->desc_list_len = cpu_to_be32(12); 5669 5670 /* FC-LS-5 specifies LS REQ Information descriptor */ 5671 rdf_resp->lsri.desc_tag = cpu_to_be32(1); 5672 rdf_resp->lsri.desc_len = cpu_to_be32(sizeof(u32)); 5673 rdf_resp->lsri.rqst_w0.cmd = ELS_RDF; 5674 break; 5675 default: 5676 return 1; 5677 } 5678 if (test_bit(NLP_LOGO_ACC, &ndlp->nlp_flag)) { 5679 if (!test_bit(NLP_RPI_REGISTERED, &ndlp->nlp_flag) && 5680 !test_bit(NLP_REG_LOGIN_SEND, &ndlp->nlp_flag)) 5681 clear_bit(NLP_LOGO_ACC, &ndlp->nlp_flag); 5682 elsiocb->cmd_cmpl = lpfc_cmpl_els_logo_acc; 5683 } else { 5684 elsiocb->cmd_cmpl = lpfc_cmpl_els_rsp; 5685 } 5686 5687 phba->fc_stat.elsXmitACC++; 5688 elsiocb->ndlp = lpfc_nlp_get(ndlp); 5689 if (!elsiocb->ndlp) { 5690 lpfc_els_free_iocb(phba, elsiocb); 5691 return 1; 5692 } 5693 5694 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); 5695 if (rc == IOCB_ERROR) { 5696 lpfc_els_free_iocb(phba, elsiocb); 5697 lpfc_nlp_put(ndlp); 5698 return 1; 5699 } 5700 5701 /* Xmit ELS ACC response tag <ulpIoTag> */ 5702 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, 5703 "0128 Xmit ELS ACC response Status: x%x, IoTag: x%x, " 5704 "XRI: x%x, DID: x%x, nlp_flag: x%lx nlp_state: x%x " 5705 "RPI: x%x, fc_flag x%lx refcnt %d\n", 5706 rc, elsiocb->iotag, elsiocb->sli4_xritag, 5707 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, 5708 ndlp->nlp_rpi, vport->fc_flag, kref_read(&ndlp->kref)); 5709 return 0; 5710 } 5711 5712 /** 5713 * lpfc_els_rsp_reject - Prepare and issue a rjt response iocb command 5714 * @vport: pointer to a virtual N_Port data structure. 5715 * @rejectError: reject response to issue 5716 * @oldiocb: pointer to the original lpfc command iocb data structure. 5717 * @ndlp: pointer to a node-list data structure. 5718 * @mbox: pointer to the driver internal queue element for mailbox command. 5719 * 5720 * This routine prepares and issue an Reject (RJT) response IOCB 5721 * command. If a @mbox pointer is passed in, it will be put into the 5722 * context_un.mbox field of the IOCB for the completion callback function 5723 * to issue to the HBA later. 5724 * 5725 * Note that the ndlp reference count will be incremented by 1 for holding the 5726 * ndlp and the reference to ndlp will be stored into the ndlp field of 5727 * the IOCB for the completion callback function to the reject response 5728 * ELS IOCB command. 5729 * 5730 * Return code 5731 * 0 - Successfully issued reject response 5732 * 1 - Failed to issue reject response 5733 **/ 5734 int 5735 lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError, 5736 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp, 5737 LPFC_MBOXQ_t *mbox) 5738 { 5739 int rc; 5740 struct lpfc_hba *phba = vport->phba; 5741 IOCB_t *icmd; 5742 IOCB_t *oldcmd; 5743 union lpfc_wqe128 *wqe; 5744 struct lpfc_iocbq *elsiocb; 5745 uint8_t *pcmd; 5746 uint16_t cmdsize; 5747 5748 cmdsize = 2 * sizeof(uint32_t); 5749 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, 5750 ndlp->nlp_DID, ELS_CMD_LS_RJT); 5751 if (!elsiocb) 5752 return 1; 5753 5754 if (phba->sli_rev == LPFC_SLI_REV4) { 5755 wqe = &elsiocb->wqe; 5756 bf_set(wqe_ctxt_tag, &wqe->generic.wqe_com, 5757 get_job_ulpcontext(phba, oldiocb)); /* Xri / rx_id */ 5758 bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com, 5759 get_job_rcvoxid(phba, oldiocb)); 5760 } else { 5761 icmd = &elsiocb->iocb; 5762 oldcmd = &oldiocb->iocb; 5763 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */ 5764 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id; 5765 } 5766 5767 pcmd = (uint8_t *)elsiocb->cmd_dmabuf->virt; 5768 5769 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT; 5770 pcmd += sizeof(uint32_t); 5771 *((uint32_t *) (pcmd)) = rejectError; 5772 5773 if (mbox) 5774 elsiocb->context_un.mbox = mbox; 5775 5776 /* Xmit ELS RJT <err> response tag <ulpIoTag> */ 5777 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, 5778 "0129 Xmit ELS RJT x%x response tag x%x " 5779 "xri x%x, did x%x, nlp_flag x%lx, nlp_state x%x, " 5780 "rpi x%x\n", 5781 rejectError, elsiocb->iotag, 5782 get_job_ulpcontext(phba, elsiocb), ndlp->nlp_DID, 5783 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi); 5784 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, 5785 "Issue LS_RJT: did:x%x flg:x%lx err:x%x", 5786 ndlp->nlp_DID, ndlp->nlp_flag, rejectError); 5787 5788 phba->fc_stat.elsXmitLSRJT++; 5789 elsiocb->cmd_cmpl = lpfc_cmpl_els_rsp; 5790 elsiocb->ndlp = lpfc_nlp_get(ndlp); 5791 if (!elsiocb->ndlp) { 5792 lpfc_els_free_iocb(phba, elsiocb); 5793 return 1; 5794 } 5795 5796 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); 5797 if (rc == IOCB_ERROR) { 5798 lpfc_els_free_iocb(phba, elsiocb); 5799 lpfc_nlp_put(ndlp); 5800 return 1; 5801 } 5802 5803 return 0; 5804 } 5805 5806 /** 5807 * lpfc_issue_els_edc_rsp - Exchange Diagnostic Capabilities with the fabric. 5808 * @vport: pointer to a host virtual N_Port data structure. 5809 * @cmdiocb: pointer to the original lpfc command iocb data structure. 5810 * @ndlp: NPort to where rsp is directed 5811 * 5812 * This routine issues an EDC ACC RSP to the F-Port Controller to communicate 5813 * this N_Port's support of hardware signals in its Congestion 5814 * Capabilities Descriptor. 5815 * 5816 * Return code 5817 * 0 - Successfully issued edc rsp command 5818 * 1 - Failed to issue edc rsp command 5819 **/ 5820 static int 5821 lpfc_issue_els_edc_rsp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, 5822 struct lpfc_nodelist *ndlp) 5823 { 5824 struct lpfc_hba *phba = vport->phba; 5825 struct fc_els_edc_resp *edc_rsp; 5826 struct fc_tlv_desc *tlv; 5827 struct lpfc_iocbq *elsiocb; 5828 IOCB_t *icmd, *cmd; 5829 union lpfc_wqe128 *wqe; 5830 u32 cgn_desc_size, lft_desc_size; 5831 u16 cmdsize; 5832 uint8_t *pcmd; 5833 int rc; 5834 5835 cmdsize = sizeof(struct fc_els_edc_resp); 5836 cgn_desc_size = sizeof(struct fc_diag_cg_sig_desc); 5837 lft_desc_size = (lpfc_link_is_lds_capable(phba)) ? 5838 sizeof(struct fc_diag_lnkflt_desc) : 0; 5839 cmdsize += cgn_desc_size + lft_desc_size; 5840 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, cmdiocb->retry, 5841 ndlp, ndlp->nlp_DID, ELS_CMD_ACC); 5842 if (!elsiocb) 5843 return 1; 5844 5845 if (phba->sli_rev == LPFC_SLI_REV4) { 5846 wqe = &elsiocb->wqe; 5847 bf_set(wqe_ctxt_tag, &wqe->generic.wqe_com, 5848 get_job_ulpcontext(phba, cmdiocb)); /* Xri / rx_id */ 5849 bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com, 5850 get_job_rcvoxid(phba, cmdiocb)); 5851 } else { 5852 icmd = &elsiocb->iocb; 5853 cmd = &cmdiocb->iocb; 5854 icmd->ulpContext = cmd->ulpContext; /* Xri / rx_id */ 5855 icmd->unsli3.rcvsli3.ox_id = cmd->unsli3.rcvsli3.ox_id; 5856 } 5857 5858 pcmd = elsiocb->cmd_dmabuf->virt; 5859 memset(pcmd, 0, cmdsize); 5860 5861 edc_rsp = (struct fc_els_edc_resp *)pcmd; 5862 edc_rsp->acc_hdr.la_cmd = ELS_LS_ACC; 5863 edc_rsp->desc_list_len = cpu_to_be32(sizeof(struct fc_els_lsri_desc) + 5864 cgn_desc_size + lft_desc_size); 5865 edc_rsp->lsri.desc_tag = cpu_to_be32(ELS_DTAG_LS_REQ_INFO); 5866 edc_rsp->lsri.desc_len = cpu_to_be32( 5867 FC_TLV_DESC_LENGTH_FROM_SZ(struct fc_els_lsri_desc)); 5868 edc_rsp->lsri.rqst_w0.cmd = ELS_EDC; 5869 tlv = edc_rsp->desc; 5870 lpfc_format_edc_cgn_desc(phba, tlv); 5871 tlv = fc_tlv_next_desc(tlv); 5872 if (lft_desc_size) 5873 lpfc_format_edc_lft_desc(phba, tlv); 5874 5875 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, 5876 "Issue EDC ACC: did:x%x flg:x%lx refcnt %d", 5877 ndlp->nlp_DID, ndlp->nlp_flag, 5878 kref_read(&ndlp->kref)); 5879 elsiocb->cmd_cmpl = lpfc_cmpl_els_rsp; 5880 5881 phba->fc_stat.elsXmitACC++; 5882 elsiocb->ndlp = lpfc_nlp_get(ndlp); 5883 if (!elsiocb->ndlp) { 5884 lpfc_els_free_iocb(phba, elsiocb); 5885 return 1; 5886 } 5887 5888 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); 5889 if (rc == IOCB_ERROR) { 5890 lpfc_els_free_iocb(phba, elsiocb); 5891 lpfc_nlp_put(ndlp); 5892 return 1; 5893 } 5894 5895 /* Xmit ELS ACC response tag <ulpIoTag> */ 5896 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, 5897 "0152 Xmit EDC ACC response Status: x%x, IoTag: x%x, " 5898 "XRI: x%x, DID: x%x, nlp_flag: x%lx nlp_state: x%x " 5899 "RPI: x%x, fc_flag x%lx\n", 5900 rc, elsiocb->iotag, elsiocb->sli4_xritag, 5901 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, 5902 ndlp->nlp_rpi, vport->fc_flag); 5903 5904 return 0; 5905 } 5906 5907 /** 5908 * lpfc_els_rsp_adisc_acc - Prepare and issue acc response to adisc iocb cmd 5909 * @vport: pointer to a virtual N_Port data structure. 5910 * @oldiocb: pointer to the original lpfc command iocb data structure. 5911 * @ndlp: pointer to a node-list data structure. 5912 * 5913 * This routine prepares and issues an Accept (ACC) response to Address 5914 * Discover (ADISC) ELS command. It simply prepares the payload of the IOCB 5915 * and invokes the lpfc_sli_issue_iocb() routine to send out the command. 5916 * 5917 * Note that the ndlp reference count will be incremented by 1 for holding the 5918 * ndlp and the reference to ndlp will be stored into the ndlp field of 5919 * the IOCB for the completion callback function to the ADISC Accept response 5920 * ELS IOCB command. 5921 * 5922 * Return code 5923 * 0 - Successfully issued acc adisc response 5924 * 1 - Failed to issue adisc acc response 5925 **/ 5926 int 5927 lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb, 5928 struct lpfc_nodelist *ndlp) 5929 { 5930 struct lpfc_hba *phba = vport->phba; 5931 ADISC *ap; 5932 IOCB_t *icmd, *oldcmd; 5933 union lpfc_wqe128 *wqe; 5934 struct lpfc_iocbq *elsiocb; 5935 uint8_t *pcmd; 5936 uint16_t cmdsize; 5937 int rc; 5938 u32 ulp_context; 5939 5940 cmdsize = sizeof(uint32_t) + sizeof(ADISC); 5941 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, 5942 ndlp->nlp_DID, ELS_CMD_ACC); 5943 if (!elsiocb) 5944 return 1; 5945 5946 if (phba->sli_rev == LPFC_SLI_REV4) { 5947 wqe = &elsiocb->wqe; 5948 /* XRI / rx_id */ 5949 bf_set(wqe_ctxt_tag, &wqe->generic.wqe_com, 5950 get_job_ulpcontext(phba, oldiocb)); 5951 ulp_context = get_job_ulpcontext(phba, elsiocb); 5952 /* oxid */ 5953 bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com, 5954 get_job_rcvoxid(phba, oldiocb)); 5955 } else { 5956 icmd = &elsiocb->iocb; 5957 oldcmd = &oldiocb->iocb; 5958 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */ 5959 ulp_context = elsiocb->iocb.ulpContext; 5960 icmd->unsli3.rcvsli3.ox_id = 5961 oldcmd->unsli3.rcvsli3.ox_id; 5962 } 5963 5964 /* Xmit ADISC ACC response tag <ulpIoTag> */ 5965 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, 5966 "0130 Xmit ADISC ACC response iotag x%x xri: " 5967 "x%x, did x%x, nlp_flag x%lx, nlp_state x%x rpi x%x\n", 5968 elsiocb->iotag, ulp_context, 5969 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, 5970 ndlp->nlp_rpi); 5971 pcmd = (uint8_t *)elsiocb->cmd_dmabuf->virt; 5972 5973 *((uint32_t *) (pcmd)) = ELS_CMD_ACC; 5974 pcmd += sizeof(uint32_t); 5975 5976 ap = (ADISC *) (pcmd); 5977 ap->hardAL_PA = phba->fc_pref_ALPA; 5978 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name)); 5979 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); 5980 ap->DID = be32_to_cpu(vport->fc_myDID); 5981 5982 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, 5983 "Issue ACC ADISC: did:x%x flg:x%lx refcnt %d", 5984 ndlp->nlp_DID, ndlp->nlp_flag, kref_read(&ndlp->kref)); 5985 5986 phba->fc_stat.elsXmitACC++; 5987 elsiocb->cmd_cmpl = lpfc_cmpl_els_rsp; 5988 elsiocb->ndlp = lpfc_nlp_get(ndlp); 5989 if (!elsiocb->ndlp) { 5990 lpfc_els_free_iocb(phba, elsiocb); 5991 return 1; 5992 } 5993 5994 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); 5995 if (rc == IOCB_ERROR) { 5996 lpfc_els_free_iocb(phba, elsiocb); 5997 lpfc_nlp_put(ndlp); 5998 return 1; 5999 } 6000 6001 return 0; 6002 } 6003 6004 /** 6005 * lpfc_els_rsp_prli_acc - Prepare and issue acc response to prli iocb cmd 6006 * @vport: pointer to a virtual N_Port data structure. 6007 * @oldiocb: pointer to the original lpfc command iocb data structure. 6008 * @ndlp: pointer to a node-list data structure. 6009 * 6010 * This routine prepares and issues an Accept (ACC) response to Process 6011 * Login (PRLI) ELS command. It simply prepares the payload of the IOCB 6012 * and invokes the lpfc_sli_issue_iocb() routine to send out the command. 6013 * 6014 * Note that the ndlp reference count will be incremented by 1 for holding the 6015 * ndlp and the reference to ndlp will be stored into the ndlp field of 6016 * the IOCB for the completion callback function to the PRLI Accept response 6017 * ELS IOCB command. 6018 * 6019 * Return code 6020 * 0 - Successfully issued acc prli response 6021 * 1 - Failed to issue acc prli response 6022 **/ 6023 int 6024 lpfc_els_rsp_prli_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb, 6025 struct lpfc_nodelist *ndlp) 6026 { 6027 struct lpfc_hba *phba = vport->phba; 6028 PRLI *npr; 6029 struct lpfc_nvme_prli *npr_nvme; 6030 lpfc_vpd_t *vpd; 6031 IOCB_t *icmd; 6032 IOCB_t *oldcmd; 6033 union lpfc_wqe128 *wqe; 6034 struct lpfc_iocbq *elsiocb; 6035 uint8_t *pcmd; 6036 uint16_t cmdsize; 6037 uint32_t prli_fc4_req, *req_payload; 6038 struct lpfc_dmabuf *req_buf; 6039 int rc; 6040 u32 elsrspcmd, ulp_context; 6041 6042 /* Need the incoming PRLI payload to determine if the ACC is for an 6043 * FC4 or NVME PRLI type. The PRLI type is at word 1. 6044 */ 6045 req_buf = oldiocb->cmd_dmabuf; 6046 req_payload = (((uint32_t *)req_buf->virt) + 1); 6047 6048 /* PRLI type payload is at byte 3 for FCP or NVME. */ 6049 prli_fc4_req = be32_to_cpu(*req_payload); 6050 prli_fc4_req = (prli_fc4_req >> 24) & 0xff; 6051 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, 6052 "6127 PRLI_ACC: Req Type x%x, Word1 x%08x\n", 6053 prli_fc4_req, *((uint32_t *)req_payload)); 6054 6055 if (prli_fc4_req == PRLI_FCP_TYPE) { 6056 cmdsize = sizeof(uint32_t) + sizeof(PRLI); 6057 elsrspcmd = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK)); 6058 } else if (prli_fc4_req == PRLI_NVME_TYPE) { 6059 cmdsize = sizeof(uint32_t) + sizeof(struct lpfc_nvme_prli); 6060 elsrspcmd = (ELS_CMD_ACC | (ELS_CMD_NVMEPRLI & ~ELS_RSP_MASK)); 6061 } else { 6062 return 1; 6063 } 6064 6065 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, 6066 ndlp->nlp_DID, elsrspcmd); 6067 if (!elsiocb) 6068 return 1; 6069 6070 if (phba->sli_rev == LPFC_SLI_REV4) { 6071 wqe = &elsiocb->wqe; 6072 bf_set(wqe_ctxt_tag, &wqe->generic.wqe_com, 6073 get_job_ulpcontext(phba, oldiocb)); /* Xri / rx_id */ 6074 ulp_context = get_job_ulpcontext(phba, elsiocb); 6075 bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com, 6076 get_job_rcvoxid(phba, oldiocb)); 6077 } else { 6078 icmd = &elsiocb->iocb; 6079 oldcmd = &oldiocb->iocb; 6080 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */ 6081 ulp_context = elsiocb->iocb.ulpContext; 6082 icmd->unsli3.rcvsli3.ox_id = 6083 oldcmd->unsli3.rcvsli3.ox_id; 6084 } 6085 6086 /* Xmit PRLI ACC response tag <ulpIoTag> */ 6087 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, 6088 "0131 Xmit PRLI ACC response tag x%x xri x%x, " 6089 "did x%x, nlp_flag x%lx, nlp_state x%x, rpi x%x\n", 6090 elsiocb->iotag, ulp_context, 6091 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, 6092 ndlp->nlp_rpi); 6093 pcmd = (uint8_t *)elsiocb->cmd_dmabuf->virt; 6094 memset(pcmd, 0, cmdsize); 6095 6096 *((uint32_t *)(pcmd)) = elsrspcmd; 6097 pcmd += sizeof(uint32_t); 6098 6099 /* For PRLI, remainder of payload is PRLI parameter page */ 6100 vpd = &phba->vpd; 6101 6102 if (prli_fc4_req == PRLI_FCP_TYPE) { 6103 /* 6104 * If the remote port is a target and our firmware version 6105 * is 3.20 or later, set the following bits for FC-TAPE 6106 * support. 6107 */ 6108 npr = (PRLI *) pcmd; 6109 if ((ndlp->nlp_type & NLP_FCP_TARGET) && 6110 (vpd->rev.feaLevelHigh >= 0x02)) { 6111 npr->ConfmComplAllowed = 1; 6112 npr->Retry = 1; 6113 npr->TaskRetryIdReq = 1; 6114 } 6115 npr->acceptRspCode = PRLI_REQ_EXECUTED; 6116 6117 /* Set image pair for complementary pairs only. */ 6118 if (ndlp->nlp_type & NLP_FCP_TARGET) 6119 npr->estabImagePair = 1; 6120 else 6121 npr->estabImagePair = 0; 6122 npr->readXferRdyDis = 1; 6123 npr->ConfmComplAllowed = 1; 6124 npr->prliType = PRLI_FCP_TYPE; 6125 npr->initiatorFunc = 1; 6126 6127 /* Xmit PRLI ACC response tag <ulpIoTag> */ 6128 lpfc_printf_vlog(vport, KERN_INFO, 6129 LOG_ELS | LOG_NODE | LOG_DISCOVERY, 6130 "6014 FCP issue PRLI ACC imgpair %d " 6131 "retry %d task %d\n", 6132 npr->estabImagePair, 6133 npr->Retry, npr->TaskRetryIdReq); 6134 6135 } else if (prli_fc4_req == PRLI_NVME_TYPE) { 6136 /* Respond with an NVME PRLI Type */ 6137 npr_nvme = (struct lpfc_nvme_prli *) pcmd; 6138 bf_set(prli_type_code, npr_nvme, PRLI_NVME_TYPE); 6139 bf_set(prli_estabImagePair, npr_nvme, 0); /* Should be 0 */ 6140 bf_set(prli_acc_rsp_code, npr_nvme, PRLI_REQ_EXECUTED); 6141 if (phba->nvmet_support) { 6142 bf_set(prli_tgt, npr_nvme, 1); 6143 bf_set(prli_disc, npr_nvme, 1); 6144 if (phba->cfg_nvme_enable_fb) { 6145 bf_set(prli_fba, npr_nvme, 1); 6146 6147 /* TBD. Target mode needs to post buffers 6148 * that support the configured first burst 6149 * byte size. 6150 */ 6151 bf_set(prli_fb_sz, npr_nvme, 6152 phba->cfg_nvmet_fb_size); 6153 } 6154 } else { 6155 bf_set(prli_init, npr_nvme, 1); 6156 } 6157 6158 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_DISC, 6159 "6015 NVME issue PRLI ACC word1 x%08x " 6160 "word4 x%08x word5 x%08x flag x%lx, " 6161 "fcp_info x%x nlp_type x%x\n", 6162 npr_nvme->word1, npr_nvme->word4, 6163 npr_nvme->word5, ndlp->nlp_flag, 6164 ndlp->nlp_fcp_info, ndlp->nlp_type); 6165 npr_nvme->word1 = cpu_to_be32(npr_nvme->word1); 6166 npr_nvme->word4 = cpu_to_be32(npr_nvme->word4); 6167 npr_nvme->word5 = cpu_to_be32(npr_nvme->word5); 6168 } else 6169 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, 6170 "6128 Unknown FC_TYPE x%x x%x ndlp x%06x\n", 6171 prli_fc4_req, ndlp->nlp_fc4_type, 6172 ndlp->nlp_DID); 6173 6174 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, 6175 "Issue ACC PRLI: did:x%x flg:x%lx", 6176 ndlp->nlp_DID, ndlp->nlp_flag, kref_read(&ndlp->kref)); 6177 6178 phba->fc_stat.elsXmitACC++; 6179 elsiocb->cmd_cmpl = lpfc_cmpl_els_rsp; 6180 elsiocb->ndlp = lpfc_nlp_get(ndlp); 6181 if (!elsiocb->ndlp) { 6182 lpfc_els_free_iocb(phba, elsiocb); 6183 return 1; 6184 } 6185 6186 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); 6187 if (rc == IOCB_ERROR) { 6188 lpfc_els_free_iocb(phba, elsiocb); 6189 lpfc_nlp_put(ndlp); 6190 return 1; 6191 } 6192 6193 return 0; 6194 } 6195 6196 /** 6197 * lpfc_els_rsp_rnid_acc - Issue rnid acc response iocb command 6198 * @vport: pointer to a virtual N_Port data structure. 6199 * @format: rnid command format. 6200 * @oldiocb: pointer to the original lpfc command iocb data structure. 6201 * @ndlp: pointer to a node-list data structure. 6202 * 6203 * This routine issues a Request Node Identification Data (RNID) Accept 6204 * (ACC) response. It constructs the RNID ACC response command according to 6205 * the proper @format and then calls the lpfc_sli_issue_iocb() routine to 6206 * issue the response. 6207 * 6208 * Note that the ndlp reference count will be incremented by 1 for holding the 6209 * ndlp and the reference to ndlp will be stored into the ndlp field of 6210 * the IOCB for the completion callback function. 6211 * 6212 * Return code 6213 * 0 - Successfully issued acc rnid response 6214 * 1 - Failed to issue acc rnid response 6215 **/ 6216 static int 6217 lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format, 6218 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp) 6219 { 6220 struct lpfc_hba *phba = vport->phba; 6221 RNID *rn; 6222 IOCB_t *icmd, *oldcmd; 6223 union lpfc_wqe128 *wqe; 6224 struct lpfc_iocbq *elsiocb; 6225 uint8_t *pcmd; 6226 uint16_t cmdsize; 6227 int rc; 6228 u32 ulp_context; 6229 6230 cmdsize = sizeof(uint32_t) + sizeof(uint32_t) 6231 + (2 * sizeof(struct lpfc_name)); 6232 if (format) 6233 cmdsize += sizeof(RNID_TOP_DISC); 6234 6235 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, 6236 ndlp->nlp_DID, ELS_CMD_ACC); 6237 if (!elsiocb) 6238 return 1; 6239 6240 if (phba->sli_rev == LPFC_SLI_REV4) { 6241 wqe = &elsiocb->wqe; 6242 bf_set(wqe_ctxt_tag, &wqe->generic.wqe_com, 6243 get_job_ulpcontext(phba, oldiocb)); /* Xri / rx_id */ 6244 ulp_context = get_job_ulpcontext(phba, elsiocb); 6245 bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com, 6246 get_job_rcvoxid(phba, oldiocb)); 6247 } else { 6248 icmd = &elsiocb->iocb; 6249 oldcmd = &oldiocb->iocb; 6250 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */ 6251 ulp_context = elsiocb->iocb.ulpContext; 6252 icmd->unsli3.rcvsli3.ox_id = 6253 oldcmd->unsli3.rcvsli3.ox_id; 6254 } 6255 6256 /* Xmit RNID ACC response tag <ulpIoTag> */ 6257 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, 6258 "0132 Xmit RNID ACC response tag x%x xri x%x\n", 6259 elsiocb->iotag, ulp_context); 6260 pcmd = (uint8_t *)elsiocb->cmd_dmabuf->virt; 6261 *((uint32_t *) (pcmd)) = ELS_CMD_ACC; 6262 pcmd += sizeof(uint32_t); 6263 6264 memset(pcmd, 0, sizeof(RNID)); 6265 rn = (RNID *) (pcmd); 6266 rn->Format = format; 6267 rn->CommonLen = (2 * sizeof(struct lpfc_name)); 6268 memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name)); 6269 memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); 6270 switch (format) { 6271 case 0: 6272 rn->SpecificLen = 0; 6273 break; 6274 case RNID_TOPOLOGY_DISC: 6275 rn->SpecificLen = sizeof(RNID_TOP_DISC); 6276 memcpy(&rn->un.topologyDisc.portName, 6277 &vport->fc_portname, sizeof(struct lpfc_name)); 6278 rn->un.topologyDisc.unitType = RNID_HBA; 6279 rn->un.topologyDisc.physPort = 0; 6280 rn->un.topologyDisc.attachedNodes = 0; 6281 break; 6282 default: 6283 rn->CommonLen = 0; 6284 rn->SpecificLen = 0; 6285 break; 6286 } 6287 6288 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, 6289 "Issue ACC RNID: did:x%x flg:x%lx refcnt %d", 6290 ndlp->nlp_DID, ndlp->nlp_flag, kref_read(&ndlp->kref)); 6291 6292 phba->fc_stat.elsXmitACC++; 6293 elsiocb->cmd_cmpl = lpfc_cmpl_els_rsp; 6294 elsiocb->ndlp = lpfc_nlp_get(ndlp); 6295 if (!elsiocb->ndlp) { 6296 lpfc_els_free_iocb(phba, elsiocb); 6297 return 1; 6298 } 6299 6300 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); 6301 if (rc == IOCB_ERROR) { 6302 lpfc_els_free_iocb(phba, elsiocb); 6303 lpfc_nlp_put(ndlp); 6304 return 1; 6305 } 6306 6307 return 0; 6308 } 6309 6310 /** 6311 * lpfc_els_clear_rrq - Clear the rq that this rrq describes. 6312 * @vport: pointer to a virtual N_Port data structure. 6313 * @iocb: pointer to the lpfc command iocb data structure. 6314 * @ndlp: pointer to a node-list data structure. 6315 * 6316 * Return 6317 **/ 6318 static void 6319 lpfc_els_clear_rrq(struct lpfc_vport *vport, 6320 struct lpfc_iocbq *iocb, struct lpfc_nodelist *ndlp) 6321 { 6322 struct lpfc_hba *phba = vport->phba; 6323 uint8_t *pcmd; 6324 struct RRQ *rrq; 6325 uint16_t rxid; 6326 uint16_t xri; 6327 struct lpfc_node_rrq *prrq; 6328 6329 6330 pcmd = (uint8_t *)iocb->cmd_dmabuf->virt; 6331 pcmd += sizeof(uint32_t); 6332 rrq = (struct RRQ *)pcmd; 6333 rrq->rrq_exchg = be32_to_cpu(rrq->rrq_exchg); 6334 rxid = bf_get(rrq_rxid, rrq); 6335 6336 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, 6337 "2883 Clear RRQ for SID:x%x OXID:x%x RXID:x%x" 6338 " x%x x%x\n", 6339 be32_to_cpu(bf_get(rrq_did, rrq)), 6340 bf_get(rrq_oxid, rrq), 6341 rxid, 6342 get_wqe_reqtag(iocb), 6343 get_job_ulpcontext(phba, iocb)); 6344 6345 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, 6346 "Clear RRQ: did:x%x flg:x%lx exchg:x%.08x", 6347 ndlp->nlp_DID, ndlp->nlp_flag, rrq->rrq_exchg); 6348 if (vport->fc_myDID == be32_to_cpu(bf_get(rrq_did, rrq))) 6349 xri = bf_get(rrq_oxid, rrq); 6350 else 6351 xri = rxid; 6352 prrq = lpfc_get_active_rrq(vport, xri, ndlp->nlp_DID); 6353 if (prrq) 6354 lpfc_clr_rrq_active(phba, xri, prrq); 6355 return; 6356 } 6357 6358 /** 6359 * lpfc_els_rsp_echo_acc - Issue echo acc response 6360 * @vport: pointer to a virtual N_Port data structure. 6361 * @data: pointer to echo data to return in the accept. 6362 * @oldiocb: pointer to the original lpfc command iocb data structure. 6363 * @ndlp: pointer to a node-list data structure. 6364 * 6365 * Return code 6366 * 0 - Successfully issued acc echo response 6367 * 1 - Failed to issue acc echo response 6368 **/ 6369 static int 6370 lpfc_els_rsp_echo_acc(struct lpfc_vport *vport, uint8_t *data, 6371 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp) 6372 { 6373 struct lpfc_hba *phba = vport->phba; 6374 IOCB_t *icmd, *oldcmd; 6375 union lpfc_wqe128 *wqe; 6376 struct lpfc_iocbq *elsiocb; 6377 uint8_t *pcmd; 6378 uint16_t cmdsize; 6379 int rc; 6380 u32 ulp_context; 6381 6382 if (phba->sli_rev == LPFC_SLI_REV4) 6383 cmdsize = oldiocb->wcqe_cmpl.total_data_placed; 6384 else 6385 cmdsize = oldiocb->iocb.unsli3.rcvsli3.acc_len; 6386 6387 /* The accumulated length can exceed the BPL_SIZE. For 6388 * now, use this as the limit 6389 */ 6390 if (cmdsize > LPFC_BPL_SIZE) 6391 cmdsize = LPFC_BPL_SIZE; 6392 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, 6393 ndlp->nlp_DID, ELS_CMD_ACC); 6394 if (!elsiocb) 6395 return 1; 6396 6397 if (phba->sli_rev == LPFC_SLI_REV4) { 6398 wqe = &elsiocb->wqe; 6399 bf_set(wqe_ctxt_tag, &wqe->generic.wqe_com, 6400 get_job_ulpcontext(phba, oldiocb)); /* Xri / rx_id */ 6401 ulp_context = get_job_ulpcontext(phba, elsiocb); 6402 bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com, 6403 get_job_rcvoxid(phba, oldiocb)); 6404 } else { 6405 icmd = &elsiocb->iocb; 6406 oldcmd = &oldiocb->iocb; 6407 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */ 6408 ulp_context = elsiocb->iocb.ulpContext; 6409 icmd->unsli3.rcvsli3.ox_id = 6410 oldcmd->unsli3.rcvsli3.ox_id; 6411 } 6412 6413 /* Xmit ECHO ACC response tag <ulpIoTag> */ 6414 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, 6415 "2876 Xmit ECHO ACC response tag x%x xri x%x\n", 6416 elsiocb->iotag, ulp_context); 6417 pcmd = (uint8_t *)elsiocb->cmd_dmabuf->virt; 6418 *((uint32_t *) (pcmd)) = ELS_CMD_ACC; 6419 pcmd += sizeof(uint32_t); 6420 memcpy(pcmd, data, cmdsize - sizeof(uint32_t)); 6421 6422 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, 6423 "Issue ACC ECHO: did:x%x flg:x%lx refcnt %d", 6424 ndlp->nlp_DID, ndlp->nlp_flag, kref_read(&ndlp->kref)); 6425 6426 phba->fc_stat.elsXmitACC++; 6427 elsiocb->cmd_cmpl = lpfc_cmpl_els_rsp; 6428 elsiocb->ndlp = lpfc_nlp_get(ndlp); 6429 if (!elsiocb->ndlp) { 6430 lpfc_els_free_iocb(phba, elsiocb); 6431 return 1; 6432 } 6433 6434 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); 6435 if (rc == IOCB_ERROR) { 6436 lpfc_els_free_iocb(phba, elsiocb); 6437 lpfc_nlp_put(ndlp); 6438 return 1; 6439 } 6440 6441 return 0; 6442 } 6443 6444 /** 6445 * lpfc_els_disc_adisc - Issue remaining adisc iocbs to npr nodes of a vport 6446 * @vport: pointer to a host virtual N_Port data structure. 6447 * 6448 * This routine issues Address Discover (ADISC) ELS commands to those 6449 * N_Ports which are in node port recovery state and ADISC has not been issued 6450 * for the @vport. Each time an ELS ADISC IOCB is issued by invoking the 6451 * lpfc_issue_els_adisc() routine, the per @vport number of discover count 6452 * (num_disc_nodes) shall be incremented. If the num_disc_nodes reaches a 6453 * pre-configured threshold (cfg_discovery_threads), the @vport fc_flag will 6454 * be marked with FC_NLP_MORE bit and the process of issuing remaining ADISC 6455 * IOCBs quit for later pick up. On the other hand, after walking through 6456 * all the ndlps with the @vport and there is none ADISC IOCB issued, the 6457 * @vport fc_flag shall be cleared with FC_NLP_MORE bit indicating there is 6458 * no more ADISC need to be sent. 6459 * 6460 * Return code 6461 * The number of N_Ports with adisc issued. 6462 **/ 6463 int 6464 lpfc_els_disc_adisc(struct lpfc_vport *vport) 6465 { 6466 struct lpfc_nodelist *ndlp, *next_ndlp; 6467 int sentadisc = 0; 6468 6469 /* go thru NPR nodes and issue any remaining ELS ADISCs */ 6470 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) { 6471 6472 if (ndlp->nlp_state != NLP_STE_NPR_NODE || 6473 !test_bit(NLP_NPR_ADISC, &ndlp->nlp_flag)) 6474 continue; 6475 6476 clear_bit(NLP_NPR_ADISC, &ndlp->nlp_flag); 6477 6478 if (!test_bit(NLP_NPR_2B_DISC, &ndlp->nlp_flag)) { 6479 /* This node was marked for ADISC but was not picked 6480 * for discovery. This is possible if the node was 6481 * missing in gidft response. 6482 * 6483 * At time of marking node for ADISC, we skipped unreg 6484 * from backend 6485 */ 6486 lpfc_nlp_unreg_node(vport, ndlp); 6487 lpfc_unreg_rpi(vport, ndlp); 6488 continue; 6489 } 6490 6491 ndlp->nlp_prev_state = ndlp->nlp_state; 6492 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE); 6493 lpfc_issue_els_adisc(vport, ndlp, 0); 6494 sentadisc++; 6495 vport->num_disc_nodes++; 6496 if (vport->num_disc_nodes >= 6497 vport->cfg_discovery_threads) { 6498 set_bit(FC_NLP_MORE, &vport->fc_flag); 6499 break; 6500 } 6501 6502 } 6503 if (sentadisc == 0) 6504 clear_bit(FC_NLP_MORE, &vport->fc_flag); 6505 return sentadisc; 6506 } 6507 6508 /** 6509 * lpfc_els_disc_plogi - Issue plogi for all npr nodes of a vport before adisc 6510 * @vport: pointer to a host virtual N_Port data structure. 6511 * 6512 * This routine issues Port Login (PLOGI) ELS commands to all the N_Ports 6513 * which are in node port recovery state, with a @vport. Each time an ELS 6514 * ADISC PLOGI IOCB is issued by invoking the lpfc_issue_els_plogi() routine, 6515 * the per @vport number of discover count (num_disc_nodes) shall be 6516 * incremented. If the num_disc_nodes reaches a pre-configured threshold 6517 * (cfg_discovery_threads), the @vport fc_flag will be marked with FC_NLP_MORE 6518 * bit set and quit the process of issuing remaining ADISC PLOGIN IOCBs for 6519 * later pick up. On the other hand, after walking through all the ndlps with 6520 * the @vport and there is none ADISC PLOGI IOCB issued, the @vport fc_flag 6521 * shall be cleared with the FC_NLP_MORE bit indicating there is no more ADISC 6522 * PLOGI need to be sent. 6523 * 6524 * Return code 6525 * The number of N_Ports with plogi issued. 6526 **/ 6527 int 6528 lpfc_els_disc_plogi(struct lpfc_vport *vport) 6529 { 6530 struct lpfc_nodelist *ndlp, *next_ndlp; 6531 int sentplogi = 0; 6532 6533 /* go thru NPR nodes and issue any remaining ELS PLOGIs */ 6534 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) { 6535 if (ndlp->nlp_state == NLP_STE_NPR_NODE && 6536 test_bit(NLP_NPR_2B_DISC, &ndlp->nlp_flag) && 6537 !test_bit(NLP_DELAY_TMO, &ndlp->nlp_flag) && 6538 !test_bit(NLP_NPR_ADISC, &ndlp->nlp_flag)) { 6539 ndlp->nlp_prev_state = ndlp->nlp_state; 6540 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); 6541 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0); 6542 sentplogi++; 6543 vport->num_disc_nodes++; 6544 if (vport->num_disc_nodes >= 6545 vport->cfg_discovery_threads) { 6546 set_bit(FC_NLP_MORE, &vport->fc_flag); 6547 break; 6548 } 6549 } 6550 } 6551 6552 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, 6553 "6452 Discover PLOGI %d flag x%lx\n", 6554 sentplogi, vport->fc_flag); 6555 6556 if (sentplogi) 6557 lpfc_set_disctmo(vport); 6558 else 6559 clear_bit(FC_NLP_MORE, &vport->fc_flag); 6560 return sentplogi; 6561 } 6562 6563 static uint32_t 6564 lpfc_rdp_res_link_service(struct fc_rdp_link_service_desc *desc, 6565 uint32_t word0) 6566 { 6567 6568 desc->tag = cpu_to_be32(RDP_LINK_SERVICE_DESC_TAG); 6569 desc->payload.els_req = word0; 6570 desc->length = cpu_to_be32(sizeof(desc->payload)); 6571 6572 return sizeof(struct fc_rdp_link_service_desc); 6573 } 6574 6575 static uint32_t 6576 lpfc_rdp_res_sfp_desc(struct fc_rdp_sfp_desc *desc, 6577 uint8_t *page_a0, uint8_t *page_a2) 6578 { 6579 uint16_t wavelength; 6580 uint16_t temperature; 6581 uint16_t rx_power; 6582 uint16_t tx_bias; 6583 uint16_t tx_power; 6584 uint16_t vcc; 6585 uint16_t flag = 0; 6586 struct sff_trasnceiver_codes_byte4 *trasn_code_byte4; 6587 struct sff_trasnceiver_codes_byte5 *trasn_code_byte5; 6588 6589 desc->tag = cpu_to_be32(RDP_SFP_DESC_TAG); 6590 6591 trasn_code_byte4 = (struct sff_trasnceiver_codes_byte4 *) 6592 &page_a0[SSF_TRANSCEIVER_CODE_B4]; 6593 trasn_code_byte5 = (struct sff_trasnceiver_codes_byte5 *) 6594 &page_a0[SSF_TRANSCEIVER_CODE_B5]; 6595 6596 if ((trasn_code_byte4->fc_sw_laser) || 6597 (trasn_code_byte5->fc_sw_laser_sl) || 6598 (trasn_code_byte5->fc_sw_laser_sn)) { /* check if its short WL */ 6599 flag |= (SFP_FLAG_PT_SWLASER << SFP_FLAG_PT_SHIFT); 6600 } else if (trasn_code_byte4->fc_lw_laser) { 6601 wavelength = (page_a0[SSF_WAVELENGTH_B1] << 8) | 6602 page_a0[SSF_WAVELENGTH_B0]; 6603 if (wavelength == SFP_WAVELENGTH_LC1310) 6604 flag |= SFP_FLAG_PT_LWLASER_LC1310 << SFP_FLAG_PT_SHIFT; 6605 if (wavelength == SFP_WAVELENGTH_LL1550) 6606 flag |= SFP_FLAG_PT_LWLASER_LL1550 << SFP_FLAG_PT_SHIFT; 6607 } 6608 /* check if its SFP+ */ 6609 flag |= ((page_a0[SSF_IDENTIFIER] == SFF_PG0_IDENT_SFP) ? 6610 SFP_FLAG_CT_SFP_PLUS : SFP_FLAG_CT_UNKNOWN) 6611 << SFP_FLAG_CT_SHIFT; 6612 6613 /* check if its OPTICAL */ 6614 flag |= ((page_a0[SSF_CONNECTOR] == SFF_PG0_CONNECTOR_LC) ? 6615 SFP_FLAG_IS_OPTICAL_PORT : 0) 6616 << SFP_FLAG_IS_OPTICAL_SHIFT; 6617 6618 temperature = (page_a2[SFF_TEMPERATURE_B1] << 8 | 6619 page_a2[SFF_TEMPERATURE_B0]); 6620 vcc = (page_a2[SFF_VCC_B1] << 8 | 6621 page_a2[SFF_VCC_B0]); 6622 tx_power = (page_a2[SFF_TXPOWER_B1] << 8 | 6623 page_a2[SFF_TXPOWER_B0]); 6624 tx_bias = (page_a2[SFF_TX_BIAS_CURRENT_B1] << 8 | 6625 page_a2[SFF_TX_BIAS_CURRENT_B0]); 6626 rx_power = (page_a2[SFF_RXPOWER_B1] << 8 | 6627 page_a2[SFF_RXPOWER_B0]); 6628 desc->sfp_info.temperature = cpu_to_be16(temperature); 6629 desc->sfp_info.rx_power = cpu_to_be16(rx_power); 6630 desc->sfp_info.tx_bias = cpu_to_be16(tx_bias); 6631 desc->sfp_info.tx_power = cpu_to_be16(tx_power); 6632 desc->sfp_info.vcc = cpu_to_be16(vcc); 6633 6634 desc->sfp_info.flags = cpu_to_be16(flag); 6635 desc->length = cpu_to_be32(sizeof(desc->sfp_info)); 6636 6637 return sizeof(struct fc_rdp_sfp_desc); 6638 } 6639 6640 static uint32_t 6641 lpfc_rdp_res_link_error(struct fc_rdp_link_error_status_desc *desc, 6642 READ_LNK_VAR *stat) 6643 { 6644 uint32_t type; 6645 6646 desc->tag = cpu_to_be32(RDP_LINK_ERROR_STATUS_DESC_TAG); 6647 6648 type = VN_PT_PHY_PF_PORT << VN_PT_PHY_SHIFT; 6649 6650 desc->info.port_type = cpu_to_be32(type); 6651 6652 desc->info.link_status.link_failure_cnt = 6653 cpu_to_be32(stat->linkFailureCnt); 6654 desc->info.link_status.loss_of_synch_cnt = 6655 cpu_to_be32(stat->lossSyncCnt); 6656 desc->info.link_status.loss_of_signal_cnt = 6657 cpu_to_be32(stat->lossSignalCnt); 6658 desc->info.link_status.primitive_seq_proto_err = 6659 cpu_to_be32(stat->primSeqErrCnt); 6660 desc->info.link_status.invalid_trans_word = 6661 cpu_to_be32(stat->invalidXmitWord); 6662 desc->info.link_status.invalid_crc_cnt = cpu_to_be32(stat->crcCnt); 6663 6664 desc->length = cpu_to_be32(sizeof(desc->info)); 6665 6666 return sizeof(struct fc_rdp_link_error_status_desc); 6667 } 6668 6669 static uint32_t 6670 lpfc_rdp_res_bbc_desc(struct fc_rdp_bbc_desc *desc, READ_LNK_VAR *stat, 6671 struct lpfc_vport *vport) 6672 { 6673 uint32_t bbCredit; 6674 6675 desc->tag = cpu_to_be32(RDP_BBC_DESC_TAG); 6676 6677 bbCredit = vport->fc_sparam.cmn.bbCreditLsb | 6678 (vport->fc_sparam.cmn.bbCreditMsb << 8); 6679 desc->bbc_info.port_bbc = cpu_to_be32(bbCredit); 6680 if (vport->phba->fc_topology != LPFC_TOPOLOGY_LOOP) { 6681 bbCredit = vport->phba->fc_fabparam.cmn.bbCreditLsb | 6682 (vport->phba->fc_fabparam.cmn.bbCreditMsb << 8); 6683 desc->bbc_info.attached_port_bbc = cpu_to_be32(bbCredit); 6684 } else { 6685 desc->bbc_info.attached_port_bbc = 0; 6686 } 6687 6688 desc->bbc_info.rtt = 0; 6689 desc->length = cpu_to_be32(sizeof(desc->bbc_info)); 6690 6691 return sizeof(struct fc_rdp_bbc_desc); 6692 } 6693 6694 static uint32_t 6695 lpfc_rdp_res_oed_temp_desc(struct lpfc_hba *phba, 6696 struct fc_rdp_oed_sfp_desc *desc, uint8_t *page_a2) 6697 { 6698 uint32_t flags = 0; 6699 6700 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG); 6701 6702 desc->oed_info.hi_alarm = page_a2[SSF_TEMP_HIGH_ALARM]; 6703 desc->oed_info.lo_alarm = page_a2[SSF_TEMP_LOW_ALARM]; 6704 desc->oed_info.hi_warning = page_a2[SSF_TEMP_HIGH_WARNING]; 6705 desc->oed_info.lo_warning = page_a2[SSF_TEMP_LOW_WARNING]; 6706 6707 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_TEMPERATURE) 6708 flags |= RDP_OET_HIGH_ALARM; 6709 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_TEMPERATURE) 6710 flags |= RDP_OET_LOW_ALARM; 6711 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_TEMPERATURE) 6712 flags |= RDP_OET_HIGH_WARNING; 6713 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_TEMPERATURE) 6714 flags |= RDP_OET_LOW_WARNING; 6715 6716 flags |= ((0xf & RDP_OED_TEMPERATURE) << RDP_OED_TYPE_SHIFT); 6717 desc->oed_info.function_flags = cpu_to_be32(flags); 6718 desc->length = cpu_to_be32(sizeof(desc->oed_info)); 6719 return sizeof(struct fc_rdp_oed_sfp_desc); 6720 } 6721 6722 static uint32_t 6723 lpfc_rdp_res_oed_voltage_desc(struct lpfc_hba *phba, 6724 struct fc_rdp_oed_sfp_desc *desc, 6725 uint8_t *page_a2) 6726 { 6727 uint32_t flags = 0; 6728 6729 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG); 6730 6731 desc->oed_info.hi_alarm = page_a2[SSF_VOLTAGE_HIGH_ALARM]; 6732 desc->oed_info.lo_alarm = page_a2[SSF_VOLTAGE_LOW_ALARM]; 6733 desc->oed_info.hi_warning = page_a2[SSF_VOLTAGE_HIGH_WARNING]; 6734 desc->oed_info.lo_warning = page_a2[SSF_VOLTAGE_LOW_WARNING]; 6735 6736 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_VOLTAGE) 6737 flags |= RDP_OET_HIGH_ALARM; 6738 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_VOLTAGE) 6739 flags |= RDP_OET_LOW_ALARM; 6740 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_VOLTAGE) 6741 flags |= RDP_OET_HIGH_WARNING; 6742 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_VOLTAGE) 6743 flags |= RDP_OET_LOW_WARNING; 6744 6745 flags |= ((0xf & RDP_OED_VOLTAGE) << RDP_OED_TYPE_SHIFT); 6746 desc->oed_info.function_flags = cpu_to_be32(flags); 6747 desc->length = cpu_to_be32(sizeof(desc->oed_info)); 6748 return sizeof(struct fc_rdp_oed_sfp_desc); 6749 } 6750 6751 static uint32_t 6752 lpfc_rdp_res_oed_txbias_desc(struct lpfc_hba *phba, 6753 struct fc_rdp_oed_sfp_desc *desc, 6754 uint8_t *page_a2) 6755 { 6756 uint32_t flags = 0; 6757 6758 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG); 6759 6760 desc->oed_info.hi_alarm = page_a2[SSF_BIAS_HIGH_ALARM]; 6761 desc->oed_info.lo_alarm = page_a2[SSF_BIAS_LOW_ALARM]; 6762 desc->oed_info.hi_warning = page_a2[SSF_BIAS_HIGH_WARNING]; 6763 desc->oed_info.lo_warning = page_a2[SSF_BIAS_LOW_WARNING]; 6764 6765 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_TXBIAS) 6766 flags |= RDP_OET_HIGH_ALARM; 6767 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_TXBIAS) 6768 flags |= RDP_OET_LOW_ALARM; 6769 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_TXBIAS) 6770 flags |= RDP_OET_HIGH_WARNING; 6771 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_TXBIAS) 6772 flags |= RDP_OET_LOW_WARNING; 6773 6774 flags |= ((0xf & RDP_OED_TXBIAS) << RDP_OED_TYPE_SHIFT); 6775 desc->oed_info.function_flags = cpu_to_be32(flags); 6776 desc->length = cpu_to_be32(sizeof(desc->oed_info)); 6777 return sizeof(struct fc_rdp_oed_sfp_desc); 6778 } 6779 6780 static uint32_t 6781 lpfc_rdp_res_oed_txpower_desc(struct lpfc_hba *phba, 6782 struct fc_rdp_oed_sfp_desc *desc, 6783 uint8_t *page_a2) 6784 { 6785 uint32_t flags = 0; 6786 6787 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG); 6788 6789 desc->oed_info.hi_alarm = page_a2[SSF_TXPOWER_HIGH_ALARM]; 6790 desc->oed_info.lo_alarm = page_a2[SSF_TXPOWER_LOW_ALARM]; 6791 desc->oed_info.hi_warning = page_a2[SSF_TXPOWER_HIGH_WARNING]; 6792 desc->oed_info.lo_warning = page_a2[SSF_TXPOWER_LOW_WARNING]; 6793 6794 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_TXPOWER) 6795 flags |= RDP_OET_HIGH_ALARM; 6796 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_TXPOWER) 6797 flags |= RDP_OET_LOW_ALARM; 6798 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_TXPOWER) 6799 flags |= RDP_OET_HIGH_WARNING; 6800 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_TXPOWER) 6801 flags |= RDP_OET_LOW_WARNING; 6802 6803 flags |= ((0xf & RDP_OED_TXPOWER) << RDP_OED_TYPE_SHIFT); 6804 desc->oed_info.function_flags = cpu_to_be32(flags); 6805 desc->length = cpu_to_be32(sizeof(desc->oed_info)); 6806 return sizeof(struct fc_rdp_oed_sfp_desc); 6807 } 6808 6809 6810 static uint32_t 6811 lpfc_rdp_res_oed_rxpower_desc(struct lpfc_hba *phba, 6812 struct fc_rdp_oed_sfp_desc *desc, 6813 uint8_t *page_a2) 6814 { 6815 uint32_t flags = 0; 6816 6817 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG); 6818 6819 desc->oed_info.hi_alarm = page_a2[SSF_RXPOWER_HIGH_ALARM]; 6820 desc->oed_info.lo_alarm = page_a2[SSF_RXPOWER_LOW_ALARM]; 6821 desc->oed_info.hi_warning = page_a2[SSF_RXPOWER_HIGH_WARNING]; 6822 desc->oed_info.lo_warning = page_a2[SSF_RXPOWER_LOW_WARNING]; 6823 6824 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_RXPOWER) 6825 flags |= RDP_OET_HIGH_ALARM; 6826 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_RXPOWER) 6827 flags |= RDP_OET_LOW_ALARM; 6828 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_RXPOWER) 6829 flags |= RDP_OET_HIGH_WARNING; 6830 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_RXPOWER) 6831 flags |= RDP_OET_LOW_WARNING; 6832 6833 flags |= ((0xf & RDP_OED_RXPOWER) << RDP_OED_TYPE_SHIFT); 6834 desc->oed_info.function_flags = cpu_to_be32(flags); 6835 desc->length = cpu_to_be32(sizeof(desc->oed_info)); 6836 return sizeof(struct fc_rdp_oed_sfp_desc); 6837 } 6838 6839 static uint32_t 6840 lpfc_rdp_res_opd_desc(struct fc_rdp_opd_sfp_desc *desc, 6841 uint8_t *page_a0, struct lpfc_vport *vport) 6842 { 6843 desc->tag = cpu_to_be32(RDP_OPD_DESC_TAG); 6844 memcpy(desc->opd_info.vendor_name, &page_a0[SSF_VENDOR_NAME], 16); 6845 memcpy(desc->opd_info.model_number, &page_a0[SSF_VENDOR_PN], 16); 6846 memcpy(desc->opd_info.serial_number, &page_a0[SSF_VENDOR_SN], 16); 6847 memcpy(desc->opd_info.revision, &page_a0[SSF_VENDOR_REV], 4); 6848 memcpy(desc->opd_info.date, &page_a0[SSF_DATE_CODE], 8); 6849 desc->length = cpu_to_be32(sizeof(desc->opd_info)); 6850 return sizeof(struct fc_rdp_opd_sfp_desc); 6851 } 6852 6853 static uint32_t 6854 lpfc_rdp_res_fec_desc(struct fc_fec_rdp_desc *desc, READ_LNK_VAR *stat) 6855 { 6856 if (bf_get(lpfc_read_link_stat_gec2, stat) == 0) 6857 return 0; 6858 desc->tag = cpu_to_be32(RDP_FEC_DESC_TAG); 6859 6860 desc->info.CorrectedBlocks = 6861 cpu_to_be32(stat->fecCorrBlkCount); 6862 desc->info.UncorrectableBlocks = 6863 cpu_to_be32(stat->fecUncorrBlkCount); 6864 6865 desc->length = cpu_to_be32(sizeof(desc->info)); 6866 6867 return sizeof(struct fc_fec_rdp_desc); 6868 } 6869 6870 static uint32_t 6871 lpfc_rdp_res_speed(struct fc_rdp_port_speed_desc *desc, struct lpfc_hba *phba) 6872 { 6873 uint16_t rdp_cap = 0; 6874 uint16_t rdp_speed; 6875 6876 desc->tag = cpu_to_be32(RDP_PORT_SPEED_DESC_TAG); 6877 6878 switch (phba->fc_linkspeed) { 6879 case LPFC_LINK_SPEED_1GHZ: 6880 rdp_speed = RDP_PS_1GB; 6881 break; 6882 case LPFC_LINK_SPEED_2GHZ: 6883 rdp_speed = RDP_PS_2GB; 6884 break; 6885 case LPFC_LINK_SPEED_4GHZ: 6886 rdp_speed = RDP_PS_4GB; 6887 break; 6888 case LPFC_LINK_SPEED_8GHZ: 6889 rdp_speed = RDP_PS_8GB; 6890 break; 6891 case LPFC_LINK_SPEED_10GHZ: 6892 rdp_speed = RDP_PS_10GB; 6893 break; 6894 case LPFC_LINK_SPEED_16GHZ: 6895 rdp_speed = RDP_PS_16GB; 6896 break; 6897 case LPFC_LINK_SPEED_32GHZ: 6898 rdp_speed = RDP_PS_32GB; 6899 break; 6900 case LPFC_LINK_SPEED_64GHZ: 6901 rdp_speed = RDP_PS_64GB; 6902 break; 6903 case LPFC_LINK_SPEED_128GHZ: 6904 rdp_speed = RDP_PS_128GB; 6905 break; 6906 case LPFC_LINK_SPEED_256GHZ: 6907 rdp_speed = RDP_PS_256GB; 6908 break; 6909 default: 6910 rdp_speed = RDP_PS_UNKNOWN; 6911 break; 6912 } 6913 6914 desc->info.port_speed.speed = cpu_to_be16(rdp_speed); 6915 6916 if (phba->lmt & LMT_256Gb) 6917 rdp_cap |= RDP_PS_256GB; 6918 if (phba->lmt & LMT_128Gb) 6919 rdp_cap |= RDP_PS_128GB; 6920 if (phba->lmt & LMT_64Gb) 6921 rdp_cap |= RDP_PS_64GB; 6922 if (phba->lmt & LMT_32Gb) 6923 rdp_cap |= RDP_PS_32GB; 6924 if (phba->lmt & LMT_16Gb) 6925 rdp_cap |= RDP_PS_16GB; 6926 if (phba->lmt & LMT_10Gb) 6927 rdp_cap |= RDP_PS_10GB; 6928 if (phba->lmt & LMT_8Gb) 6929 rdp_cap |= RDP_PS_8GB; 6930 if (phba->lmt & LMT_4Gb) 6931 rdp_cap |= RDP_PS_4GB; 6932 if (phba->lmt & LMT_2Gb) 6933 rdp_cap |= RDP_PS_2GB; 6934 if (phba->lmt & LMT_1Gb) 6935 rdp_cap |= RDP_PS_1GB; 6936 6937 if (rdp_cap == 0) 6938 rdp_cap = RDP_CAP_UNKNOWN; 6939 if (phba->cfg_link_speed != LPFC_USER_LINK_SPEED_AUTO) 6940 rdp_cap |= RDP_CAP_USER_CONFIGURED; 6941 6942 desc->info.port_speed.capabilities = cpu_to_be16(rdp_cap); 6943 desc->length = cpu_to_be32(sizeof(desc->info)); 6944 return sizeof(struct fc_rdp_port_speed_desc); 6945 } 6946 6947 static uint32_t 6948 lpfc_rdp_res_diag_port_names(struct fc_rdp_port_name_desc *desc, 6949 struct lpfc_vport *vport) 6950 { 6951 6952 desc->tag = cpu_to_be32(RDP_PORT_NAMES_DESC_TAG); 6953 6954 memcpy(desc->port_names.wwnn, &vport->fc_nodename, 6955 sizeof(desc->port_names.wwnn)); 6956 6957 memcpy(desc->port_names.wwpn, &vport->fc_portname, 6958 sizeof(desc->port_names.wwpn)); 6959 6960 desc->length = cpu_to_be32(sizeof(desc->port_names)); 6961 return sizeof(struct fc_rdp_port_name_desc); 6962 } 6963 6964 static uint32_t 6965 lpfc_rdp_res_attach_port_names(struct fc_rdp_port_name_desc *desc, 6966 struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) 6967 { 6968 6969 desc->tag = cpu_to_be32(RDP_PORT_NAMES_DESC_TAG); 6970 if (test_bit(FC_FABRIC, &vport->fc_flag)) { 6971 memcpy(desc->port_names.wwnn, &vport->fabric_nodename, 6972 sizeof(desc->port_names.wwnn)); 6973 6974 memcpy(desc->port_names.wwpn, &vport->fabric_portname, 6975 sizeof(desc->port_names.wwpn)); 6976 } else { /* Point to Point */ 6977 memcpy(desc->port_names.wwnn, &ndlp->nlp_nodename, 6978 sizeof(desc->port_names.wwnn)); 6979 6980 memcpy(desc->port_names.wwpn, &ndlp->nlp_portname, 6981 sizeof(desc->port_names.wwpn)); 6982 } 6983 6984 desc->length = cpu_to_be32(sizeof(desc->port_names)); 6985 return sizeof(struct fc_rdp_port_name_desc); 6986 } 6987 6988 static void 6989 lpfc_els_rdp_cmpl(struct lpfc_hba *phba, struct lpfc_rdp_context *rdp_context, 6990 int status) 6991 { 6992 struct lpfc_nodelist *ndlp = rdp_context->ndlp; 6993 struct lpfc_vport *vport = ndlp->vport; 6994 struct lpfc_iocbq *elsiocb; 6995 struct ulp_bde64 *bpl; 6996 IOCB_t *icmd; 6997 union lpfc_wqe128 *wqe; 6998 uint8_t *pcmd; 6999 struct ls_rjt *stat; 7000 struct fc_rdp_res_frame *rdp_res; 7001 uint32_t cmdsize, len; 7002 uint16_t *flag_ptr; 7003 int rc; 7004 u32 ulp_context; 7005 7006 if (status != SUCCESS) 7007 goto error; 7008 7009 /* This will change once we know the true size of the RDP payload */ 7010 cmdsize = sizeof(struct fc_rdp_res_frame); 7011 7012 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, 7013 lpfc_max_els_tries, rdp_context->ndlp, 7014 rdp_context->ndlp->nlp_DID, ELS_CMD_ACC); 7015 if (!elsiocb) 7016 goto free_rdp_context; 7017 7018 ulp_context = get_job_ulpcontext(phba, elsiocb); 7019 if (phba->sli_rev == LPFC_SLI_REV4) { 7020 wqe = &elsiocb->wqe; 7021 /* ox-id of the frame */ 7022 bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com, 7023 rdp_context->ox_id); 7024 bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com, 7025 rdp_context->rx_id); 7026 } else { 7027 icmd = &elsiocb->iocb; 7028 icmd->ulpContext = rdp_context->rx_id; 7029 icmd->unsli3.rcvsli3.ox_id = rdp_context->ox_id; 7030 } 7031 7032 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, 7033 "2171 Xmit RDP response tag x%x xri x%x, " 7034 "did x%x, nlp_flag x%lx, nlp_state x%x, rpi x%x", 7035 elsiocb->iotag, ulp_context, 7036 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, 7037 ndlp->nlp_rpi); 7038 rdp_res = (struct fc_rdp_res_frame *)elsiocb->cmd_dmabuf->virt; 7039 pcmd = (uint8_t *)elsiocb->cmd_dmabuf->virt; 7040 memset(pcmd, 0, sizeof(struct fc_rdp_res_frame)); 7041 *((uint32_t *) (pcmd)) = ELS_CMD_ACC; 7042 7043 /* Update Alarm and Warning */ 7044 flag_ptr = (uint16_t *)(rdp_context->page_a2 + SSF_ALARM_FLAGS); 7045 phba->sfp_alarm |= *flag_ptr; 7046 flag_ptr = (uint16_t *)(rdp_context->page_a2 + SSF_WARNING_FLAGS); 7047 phba->sfp_warning |= *flag_ptr; 7048 7049 /* For RDP payload */ 7050 len = 8; 7051 len += lpfc_rdp_res_link_service((struct fc_rdp_link_service_desc *) 7052 (len + pcmd), ELS_CMD_RDP); 7053 7054 len += lpfc_rdp_res_sfp_desc((struct fc_rdp_sfp_desc *)(len + pcmd), 7055 rdp_context->page_a0, rdp_context->page_a2); 7056 len += lpfc_rdp_res_speed((struct fc_rdp_port_speed_desc *)(len + pcmd), 7057 phba); 7058 len += lpfc_rdp_res_link_error((struct fc_rdp_link_error_status_desc *) 7059 (len + pcmd), &rdp_context->link_stat); 7060 len += lpfc_rdp_res_diag_port_names((struct fc_rdp_port_name_desc *) 7061 (len + pcmd), vport); 7062 len += lpfc_rdp_res_attach_port_names((struct fc_rdp_port_name_desc *) 7063 (len + pcmd), vport, ndlp); 7064 len += lpfc_rdp_res_fec_desc((struct fc_fec_rdp_desc *)(len + pcmd), 7065 &rdp_context->link_stat); 7066 len += lpfc_rdp_res_bbc_desc((struct fc_rdp_bbc_desc *)(len + pcmd), 7067 &rdp_context->link_stat, vport); 7068 len += lpfc_rdp_res_oed_temp_desc(phba, 7069 (struct fc_rdp_oed_sfp_desc *)(len + pcmd), 7070 rdp_context->page_a2); 7071 len += lpfc_rdp_res_oed_voltage_desc(phba, 7072 (struct fc_rdp_oed_sfp_desc *)(len + pcmd), 7073 rdp_context->page_a2); 7074 len += lpfc_rdp_res_oed_txbias_desc(phba, 7075 (struct fc_rdp_oed_sfp_desc *)(len + pcmd), 7076 rdp_context->page_a2); 7077 len += lpfc_rdp_res_oed_txpower_desc(phba, 7078 (struct fc_rdp_oed_sfp_desc *)(len + pcmd), 7079 rdp_context->page_a2); 7080 len += lpfc_rdp_res_oed_rxpower_desc(phba, 7081 (struct fc_rdp_oed_sfp_desc *)(len + pcmd), 7082 rdp_context->page_a2); 7083 len += lpfc_rdp_res_opd_desc((struct fc_rdp_opd_sfp_desc *)(len + pcmd), 7084 rdp_context->page_a0, vport); 7085 7086 rdp_res->length = cpu_to_be32(len - 8); 7087 elsiocb->cmd_cmpl = lpfc_cmpl_els_rsp; 7088 7089 /* Now that we know the true size of the payload, update the BPL */ 7090 bpl = (struct ulp_bde64 *)elsiocb->bpl_dmabuf->virt; 7091 bpl->tus.f.bdeSize = len; 7092 bpl->tus.f.bdeFlags = 0; 7093 bpl->tus.w = le32_to_cpu(bpl->tus.w); 7094 7095 phba->fc_stat.elsXmitACC++; 7096 elsiocb->ndlp = lpfc_nlp_get(ndlp); 7097 if (!elsiocb->ndlp) { 7098 lpfc_els_free_iocb(phba, elsiocb); 7099 goto free_rdp_context; 7100 } 7101 7102 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); 7103 if (rc == IOCB_ERROR) { 7104 lpfc_els_free_iocb(phba, elsiocb); 7105 lpfc_nlp_put(ndlp); 7106 } 7107 7108 goto free_rdp_context; 7109 7110 error: 7111 cmdsize = 2 * sizeof(uint32_t); 7112 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, lpfc_max_els_tries, 7113 ndlp, ndlp->nlp_DID, ELS_CMD_LS_RJT); 7114 if (!elsiocb) 7115 goto free_rdp_context; 7116 7117 if (phba->sli_rev == LPFC_SLI_REV4) { 7118 wqe = &elsiocb->wqe; 7119 /* ox-id of the frame */ 7120 bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com, 7121 rdp_context->ox_id); 7122 bf_set(wqe_ctxt_tag, 7123 &wqe->xmit_els_rsp.wqe_com, 7124 rdp_context->rx_id); 7125 } else { 7126 icmd = &elsiocb->iocb; 7127 icmd->ulpContext = rdp_context->rx_id; 7128 icmd->unsli3.rcvsli3.ox_id = rdp_context->ox_id; 7129 } 7130 7131 pcmd = (uint8_t *)elsiocb->cmd_dmabuf->virt; 7132 7133 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT; 7134 stat = (struct ls_rjt *)(pcmd + sizeof(uint32_t)); 7135 stat->un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; 7136 7137 phba->fc_stat.elsXmitLSRJT++; 7138 elsiocb->cmd_cmpl = lpfc_cmpl_els_rsp; 7139 elsiocb->ndlp = lpfc_nlp_get(ndlp); 7140 if (!elsiocb->ndlp) { 7141 lpfc_els_free_iocb(phba, elsiocb); 7142 goto free_rdp_context; 7143 } 7144 7145 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); 7146 if (rc == IOCB_ERROR) { 7147 lpfc_els_free_iocb(phba, elsiocb); 7148 lpfc_nlp_put(ndlp); 7149 } 7150 7151 free_rdp_context: 7152 /* This reference put is for the original unsolicited RDP. If the 7153 * prep failed, there is no reference to remove. 7154 */ 7155 lpfc_nlp_put(ndlp); 7156 kfree(rdp_context); 7157 } 7158 7159 static int 7160 lpfc_get_rdp_info(struct lpfc_hba *phba, struct lpfc_rdp_context *rdp_context) 7161 { 7162 LPFC_MBOXQ_t *mbox = NULL; 7163 int rc; 7164 7165 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); 7166 if (!mbox) { 7167 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_ELS, 7168 "7105 failed to allocate mailbox memory"); 7169 return 1; 7170 } 7171 7172 if (lpfc_sli4_dump_page_a0(phba, mbox)) 7173 goto rdp_fail; 7174 mbox->vport = rdp_context->ndlp->vport; 7175 mbox->mbox_cmpl = lpfc_mbx_cmpl_rdp_page_a0; 7176 mbox->ctx_u.rdp = rdp_context; 7177 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); 7178 if (rc == MBX_NOT_FINISHED) { 7179 lpfc_mbox_rsrc_cleanup(phba, mbox, MBOX_THD_UNLOCKED); 7180 return 1; 7181 } 7182 7183 return 0; 7184 7185 rdp_fail: 7186 mempool_free(mbox, phba->mbox_mem_pool); 7187 return 1; 7188 } 7189 7190 int lpfc_get_sfp_info_wait(struct lpfc_hba *phba, 7191 struct lpfc_rdp_context *rdp_context) 7192 { 7193 LPFC_MBOXQ_t *mbox = NULL; 7194 int rc; 7195 struct lpfc_dmabuf *mp; 7196 struct lpfc_dmabuf *mpsave; 7197 void *virt; 7198 MAILBOX_t *mb; 7199 7200 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); 7201 if (!mbox) { 7202 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_ELS, 7203 "7205 failed to allocate mailbox memory"); 7204 return 1; 7205 } 7206 7207 if (lpfc_sli4_dump_page_a0(phba, mbox)) 7208 goto sfp_fail; 7209 mp = mbox->ctx_buf; 7210 mpsave = mp; 7211 virt = mp->virt; 7212 if (phba->sli_rev < LPFC_SLI_REV4) { 7213 mb = &mbox->u.mb; 7214 mb->un.varDmp.cv = 1; 7215 mb->un.varDmp.co = 1; 7216 mb->un.varWords[2] = 0; 7217 mb->un.varWords[3] = DMP_SFF_PAGE_A0_SIZE / 4; 7218 mb->un.varWords[4] = 0; 7219 mb->un.varWords[5] = 0; 7220 mb->un.varWords[6] = 0; 7221 mb->un.varWords[7] = 0; 7222 mb->un.varWords[8] = 0; 7223 mb->un.varWords[9] = 0; 7224 mb->un.varWords[10] = 0; 7225 mbox->in_ext_byte_len = DMP_SFF_PAGE_A0_SIZE; 7226 mbox->out_ext_byte_len = DMP_SFF_PAGE_A0_SIZE; 7227 mbox->mbox_offset_word = 5; 7228 mbox->ext_buf = virt; 7229 } else { 7230 bf_set(lpfc_mbx_memory_dump_type3_length, 7231 &mbox->u.mqe.un.mem_dump_type3, DMP_SFF_PAGE_A0_SIZE); 7232 mbox->u.mqe.un.mem_dump_type3.addr_lo = putPaddrLow(mp->phys); 7233 mbox->u.mqe.un.mem_dump_type3.addr_hi = putPaddrHigh(mp->phys); 7234 } 7235 mbox->vport = phba->pport; 7236 rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_SLI4_CONFIG_TMO); 7237 if (rc == MBX_NOT_FINISHED) { 7238 rc = 1; 7239 goto error; 7240 } 7241 if (rc == MBX_TIMEOUT) 7242 goto error; 7243 if (phba->sli_rev == LPFC_SLI_REV4) 7244 mp = mbox->ctx_buf; 7245 else 7246 mp = mpsave; 7247 7248 if (bf_get(lpfc_mqe_status, &mbox->u.mqe)) { 7249 rc = 1; 7250 goto error; 7251 } 7252 7253 lpfc_sli_bemem_bcopy(mp->virt, &rdp_context->page_a0, 7254 DMP_SFF_PAGE_A0_SIZE); 7255 7256 memset(mbox, 0, sizeof(*mbox)); 7257 memset(mp->virt, 0, DMP_SFF_PAGE_A2_SIZE); 7258 INIT_LIST_HEAD(&mp->list); 7259 7260 /* save address for completion */ 7261 mbox->ctx_buf = mp; 7262 mbox->vport = phba->pport; 7263 7264 bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_DUMP_MEMORY); 7265 bf_set(lpfc_mbx_memory_dump_type3_type, 7266 &mbox->u.mqe.un.mem_dump_type3, DMP_LMSD); 7267 bf_set(lpfc_mbx_memory_dump_type3_link, 7268 &mbox->u.mqe.un.mem_dump_type3, phba->sli4_hba.physical_port); 7269 bf_set(lpfc_mbx_memory_dump_type3_page_no, 7270 &mbox->u.mqe.un.mem_dump_type3, DMP_PAGE_A2); 7271 if (phba->sli_rev < LPFC_SLI_REV4) { 7272 mb = &mbox->u.mb; 7273 mb->un.varDmp.cv = 1; 7274 mb->un.varDmp.co = 1; 7275 mb->un.varWords[2] = 0; 7276 mb->un.varWords[3] = DMP_SFF_PAGE_A2_SIZE / 4; 7277 mb->un.varWords[4] = 0; 7278 mb->un.varWords[5] = 0; 7279 mb->un.varWords[6] = 0; 7280 mb->un.varWords[7] = 0; 7281 mb->un.varWords[8] = 0; 7282 mb->un.varWords[9] = 0; 7283 mb->un.varWords[10] = 0; 7284 mbox->in_ext_byte_len = DMP_SFF_PAGE_A2_SIZE; 7285 mbox->out_ext_byte_len = DMP_SFF_PAGE_A2_SIZE; 7286 mbox->mbox_offset_word = 5; 7287 mbox->ext_buf = virt; 7288 } else { 7289 bf_set(lpfc_mbx_memory_dump_type3_length, 7290 &mbox->u.mqe.un.mem_dump_type3, DMP_SFF_PAGE_A2_SIZE); 7291 mbox->u.mqe.un.mem_dump_type3.addr_lo = putPaddrLow(mp->phys); 7292 mbox->u.mqe.un.mem_dump_type3.addr_hi = putPaddrHigh(mp->phys); 7293 } 7294 7295 rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_SLI4_CONFIG_TMO); 7296 7297 if (rc == MBX_TIMEOUT) 7298 goto error; 7299 if (bf_get(lpfc_mqe_status, &mbox->u.mqe)) { 7300 rc = 1; 7301 goto error; 7302 } 7303 rc = 0; 7304 7305 lpfc_sli_bemem_bcopy(mp->virt, &rdp_context->page_a2, 7306 DMP_SFF_PAGE_A2_SIZE); 7307 7308 error: 7309 if (mbox->mbox_flag & LPFC_MBX_WAKE) { 7310 mbox->ctx_buf = mpsave; 7311 lpfc_mbox_rsrc_cleanup(phba, mbox, MBOX_THD_UNLOCKED); 7312 } 7313 7314 return rc; 7315 7316 sfp_fail: 7317 mempool_free(mbox, phba->mbox_mem_pool); 7318 return 1; 7319 } 7320 7321 /* 7322 * lpfc_els_rcv_rdp - Process an unsolicited RDP ELS. 7323 * @vport: pointer to a host virtual N_Port data structure. 7324 * @cmdiocb: pointer to lpfc command iocb data structure. 7325 * @ndlp: pointer to a node-list data structure. 7326 * 7327 * This routine processes an unsolicited RDP(Read Diagnostic Parameters) 7328 * IOCB. First, the payload of the unsolicited RDP is checked. 7329 * Then it will (1) send MBX_DUMP_MEMORY, Embedded DMP_LMSD sub command TYPE-3 7330 * for Page A0, (2) send MBX_DUMP_MEMORY, DMP_LMSD for Page A2, 7331 * (3) send MBX_READ_LNK_STAT to get link stat, (4) Call lpfc_els_rdp_cmpl 7332 * gather all data and send RDP response. 7333 * 7334 * Return code 7335 * 0 - Sent the acc response 7336 * 1 - Sent the reject response. 7337 */ 7338 static int 7339 lpfc_els_rcv_rdp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, 7340 struct lpfc_nodelist *ndlp) 7341 { 7342 struct lpfc_hba *phba = vport->phba; 7343 struct lpfc_dmabuf *pcmd; 7344 uint8_t rjt_err, rjt_expl = LSEXP_NOTHING_MORE; 7345 struct fc_rdp_req_frame *rdp_req; 7346 struct lpfc_rdp_context *rdp_context; 7347 union lpfc_wqe128 *cmd = NULL; 7348 struct ls_rjt stat; 7349 7350 if (phba->sli_rev < LPFC_SLI_REV4 || 7351 bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) < 7352 LPFC_SLI_INTF_IF_TYPE_2) { 7353 rjt_err = LSRJT_UNABLE_TPC; 7354 rjt_expl = LSEXP_REQ_UNSUPPORTED; 7355 goto error; 7356 } 7357 7358 if (phba->sli_rev < LPFC_SLI_REV4 || 7359 test_bit(HBA_FCOE_MODE, &phba->hba_flag)) { 7360 rjt_err = LSRJT_UNABLE_TPC; 7361 rjt_expl = LSEXP_REQ_UNSUPPORTED; 7362 goto error; 7363 } 7364 7365 pcmd = cmdiocb->cmd_dmabuf; 7366 rdp_req = (struct fc_rdp_req_frame *) pcmd->virt; 7367 7368 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, 7369 "2422 ELS RDP Request " 7370 "dec len %d tag x%x port_id %d len %d\n", 7371 be32_to_cpu(rdp_req->rdp_des_length), 7372 be32_to_cpu(rdp_req->nport_id_desc.tag), 7373 be32_to_cpu(rdp_req->nport_id_desc.nport_id), 7374 be32_to_cpu(rdp_req->nport_id_desc.length)); 7375 7376 if (sizeof(struct fc_rdp_nport_desc) != 7377 be32_to_cpu(rdp_req->rdp_des_length)) 7378 goto rjt_logerr; 7379 if (RDP_N_PORT_DESC_TAG != be32_to_cpu(rdp_req->nport_id_desc.tag)) 7380 goto rjt_logerr; 7381 if (RDP_NPORT_ID_SIZE != 7382 be32_to_cpu(rdp_req->nport_id_desc.length)) 7383 goto rjt_logerr; 7384 rdp_context = kzalloc(sizeof(struct lpfc_rdp_context), GFP_KERNEL); 7385 if (!rdp_context) { 7386 rjt_err = LSRJT_UNABLE_TPC; 7387 goto error; 7388 } 7389 7390 cmd = &cmdiocb->wqe; 7391 rdp_context->ndlp = lpfc_nlp_get(ndlp); 7392 if (!rdp_context->ndlp) { 7393 kfree(rdp_context); 7394 rjt_err = LSRJT_UNABLE_TPC; 7395 goto error; 7396 } 7397 rdp_context->ox_id = bf_get(wqe_rcvoxid, 7398 &cmd->xmit_els_rsp.wqe_com); 7399 rdp_context->rx_id = bf_get(wqe_ctxt_tag, 7400 &cmd->xmit_els_rsp.wqe_com); 7401 rdp_context->cmpl = lpfc_els_rdp_cmpl; 7402 if (lpfc_get_rdp_info(phba, rdp_context)) { 7403 lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_ELS, 7404 "2423 Unable to send mailbox"); 7405 kfree(rdp_context); 7406 rjt_err = LSRJT_UNABLE_TPC; 7407 lpfc_nlp_put(ndlp); 7408 goto error; 7409 } 7410 7411 return 0; 7412 7413 rjt_logerr: 7414 rjt_err = LSRJT_LOGICAL_ERR; 7415 7416 error: 7417 memset(&stat, 0, sizeof(stat)); 7418 stat.un.b.lsRjtRsnCode = rjt_err; 7419 stat.un.b.lsRjtRsnCodeExp = rjt_expl; 7420 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); 7421 return 1; 7422 } 7423 7424 7425 static void 7426 lpfc_els_lcb_rsp(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) 7427 { 7428 MAILBOX_t *mb; 7429 IOCB_t *icmd; 7430 union lpfc_wqe128 *wqe; 7431 uint8_t *pcmd; 7432 struct lpfc_iocbq *elsiocb; 7433 struct lpfc_nodelist *ndlp; 7434 struct ls_rjt *stat; 7435 union lpfc_sli4_cfg_shdr *shdr; 7436 struct lpfc_lcb_context *lcb_context; 7437 struct fc_lcb_res_frame *lcb_res; 7438 uint32_t cmdsize, shdr_status, shdr_add_status; 7439 int rc; 7440 7441 mb = &pmb->u.mb; 7442 lcb_context = pmb->ctx_u.lcb; 7443 ndlp = lcb_context->ndlp; 7444 memset(&pmb->ctx_u, 0, sizeof(pmb->ctx_u)); 7445 pmb->ctx_buf = NULL; 7446 7447 shdr = (union lpfc_sli4_cfg_shdr *) 7448 &pmb->u.mqe.un.beacon_config.header.cfg_shdr; 7449 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); 7450 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); 7451 7452 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX, 7453 "0194 SET_BEACON_CONFIG mailbox " 7454 "completed with status x%x add_status x%x," 7455 " mbx status x%x\n", 7456 shdr_status, shdr_add_status, mb->mbxStatus); 7457 7458 if ((mb->mbxStatus != MBX_SUCCESS) || shdr_status || 7459 (shdr_add_status == ADD_STATUS_OPERATION_ALREADY_ACTIVE) || 7460 (shdr_add_status == ADD_STATUS_INVALID_REQUEST)) { 7461 mempool_free(pmb, phba->mbox_mem_pool); 7462 goto error; 7463 } 7464 7465 mempool_free(pmb, phba->mbox_mem_pool); 7466 cmdsize = sizeof(struct fc_lcb_res_frame); 7467 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize, 7468 lpfc_max_els_tries, ndlp, 7469 ndlp->nlp_DID, ELS_CMD_ACC); 7470 7471 /* Decrement the ndlp reference count from previous mbox command */ 7472 lpfc_nlp_put(ndlp); 7473 7474 if (!elsiocb) 7475 goto free_lcb_context; 7476 7477 lcb_res = (struct fc_lcb_res_frame *)elsiocb->cmd_dmabuf->virt; 7478 7479 memset(lcb_res, 0, sizeof(struct fc_lcb_res_frame)); 7480 7481 if (phba->sli_rev == LPFC_SLI_REV4) { 7482 wqe = &elsiocb->wqe; 7483 bf_set(wqe_ctxt_tag, &wqe->generic.wqe_com, lcb_context->rx_id); 7484 bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com, 7485 lcb_context->ox_id); 7486 } else { 7487 icmd = &elsiocb->iocb; 7488 icmd->ulpContext = lcb_context->rx_id; 7489 icmd->unsli3.rcvsli3.ox_id = lcb_context->ox_id; 7490 } 7491 7492 pcmd = (uint8_t *)elsiocb->cmd_dmabuf->virt; 7493 *((uint32_t *)(pcmd)) = ELS_CMD_ACC; 7494 lcb_res->lcb_sub_command = lcb_context->sub_command; 7495 lcb_res->lcb_type = lcb_context->type; 7496 lcb_res->capability = lcb_context->capability; 7497 lcb_res->lcb_frequency = lcb_context->frequency; 7498 lcb_res->lcb_duration = lcb_context->duration; 7499 elsiocb->cmd_cmpl = lpfc_cmpl_els_rsp; 7500 phba->fc_stat.elsXmitACC++; 7501 7502 elsiocb->ndlp = lpfc_nlp_get(ndlp); 7503 if (!elsiocb->ndlp) { 7504 lpfc_els_free_iocb(phba, elsiocb); 7505 goto out; 7506 } 7507 7508 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); 7509 if (rc == IOCB_ERROR) { 7510 lpfc_els_free_iocb(phba, elsiocb); 7511 lpfc_nlp_put(ndlp); 7512 } 7513 out: 7514 kfree(lcb_context); 7515 return; 7516 7517 error: 7518 cmdsize = sizeof(struct fc_lcb_res_frame); 7519 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize, 7520 lpfc_max_els_tries, ndlp, 7521 ndlp->nlp_DID, ELS_CMD_LS_RJT); 7522 lpfc_nlp_put(ndlp); 7523 if (!elsiocb) 7524 goto free_lcb_context; 7525 7526 if (phba->sli_rev == LPFC_SLI_REV4) { 7527 wqe = &elsiocb->wqe; 7528 bf_set(wqe_ctxt_tag, &wqe->generic.wqe_com, lcb_context->rx_id); 7529 bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com, 7530 lcb_context->ox_id); 7531 } else { 7532 icmd = &elsiocb->iocb; 7533 icmd->ulpContext = lcb_context->rx_id; 7534 icmd->unsli3.rcvsli3.ox_id = lcb_context->ox_id; 7535 } 7536 7537 pcmd = (uint8_t *)elsiocb->cmd_dmabuf->virt; 7538 7539 *((uint32_t *)(pcmd)) = ELS_CMD_LS_RJT; 7540 stat = (struct ls_rjt *)(pcmd + sizeof(uint32_t)); 7541 stat->un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; 7542 7543 if (shdr_add_status == ADD_STATUS_OPERATION_ALREADY_ACTIVE) 7544 stat->un.b.lsRjtRsnCodeExp = LSEXP_CMD_IN_PROGRESS; 7545 7546 elsiocb->cmd_cmpl = lpfc_cmpl_els_rsp; 7547 phba->fc_stat.elsXmitLSRJT++; 7548 elsiocb->ndlp = lpfc_nlp_get(ndlp); 7549 if (!elsiocb->ndlp) { 7550 lpfc_els_free_iocb(phba, elsiocb); 7551 goto free_lcb_context; 7552 } 7553 7554 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); 7555 if (rc == IOCB_ERROR) { 7556 lpfc_els_free_iocb(phba, elsiocb); 7557 lpfc_nlp_put(ndlp); 7558 } 7559 free_lcb_context: 7560 kfree(lcb_context); 7561 } 7562 7563 static int 7564 lpfc_sli4_set_beacon(struct lpfc_vport *vport, 7565 struct lpfc_lcb_context *lcb_context, 7566 uint32_t beacon_state) 7567 { 7568 struct lpfc_hba *phba = vport->phba; 7569 union lpfc_sli4_cfg_shdr *cfg_shdr; 7570 LPFC_MBOXQ_t *mbox = NULL; 7571 uint32_t len; 7572 int rc; 7573 7574 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); 7575 if (!mbox) 7576 return 1; 7577 7578 cfg_shdr = &mbox->u.mqe.un.sli4_config.header.cfg_shdr; 7579 len = sizeof(struct lpfc_mbx_set_beacon_config) - 7580 sizeof(struct lpfc_sli4_cfg_mhdr); 7581 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, 7582 LPFC_MBOX_OPCODE_SET_BEACON_CONFIG, len, 7583 LPFC_SLI4_MBX_EMBED); 7584 mbox->ctx_u.lcb = lcb_context; 7585 mbox->vport = phba->pport; 7586 mbox->mbox_cmpl = lpfc_els_lcb_rsp; 7587 bf_set(lpfc_mbx_set_beacon_port_num, &mbox->u.mqe.un.beacon_config, 7588 phba->sli4_hba.physical_port); 7589 bf_set(lpfc_mbx_set_beacon_state, &mbox->u.mqe.un.beacon_config, 7590 beacon_state); 7591 mbox->u.mqe.un.beacon_config.word5 = 0; /* Reserved */ 7592 7593 /* 7594 * Check bv1s bit before issuing the mailbox 7595 * if bv1s == 1, LCB V1 supported 7596 * else, LCB V0 supported 7597 */ 7598 7599 if (phba->sli4_hba.pc_sli4_params.bv1s) { 7600 /* COMMON_SET_BEACON_CONFIG_V1 */ 7601 cfg_shdr->request.word9 = BEACON_VERSION_V1; 7602 lcb_context->capability |= LCB_CAPABILITY_DURATION; 7603 bf_set(lpfc_mbx_set_beacon_port_type, 7604 &mbox->u.mqe.un.beacon_config, 0); 7605 bf_set(lpfc_mbx_set_beacon_duration_v1, 7606 &mbox->u.mqe.un.beacon_config, 7607 be16_to_cpu(lcb_context->duration)); 7608 } else { 7609 /* COMMON_SET_BEACON_CONFIG_V0 */ 7610 if (be16_to_cpu(lcb_context->duration) != 0) { 7611 mempool_free(mbox, phba->mbox_mem_pool); 7612 return 1; 7613 } 7614 cfg_shdr->request.word9 = BEACON_VERSION_V0; 7615 lcb_context->capability &= ~(LCB_CAPABILITY_DURATION); 7616 bf_set(lpfc_mbx_set_beacon_state, 7617 &mbox->u.mqe.un.beacon_config, beacon_state); 7618 bf_set(lpfc_mbx_set_beacon_port_type, 7619 &mbox->u.mqe.un.beacon_config, 1); 7620 bf_set(lpfc_mbx_set_beacon_duration, 7621 &mbox->u.mqe.un.beacon_config, 7622 be16_to_cpu(lcb_context->duration)); 7623 } 7624 7625 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); 7626 if (rc == MBX_NOT_FINISHED) { 7627 mempool_free(mbox, phba->mbox_mem_pool); 7628 return 1; 7629 } 7630 7631 return 0; 7632 } 7633 7634 7635 /** 7636 * lpfc_els_rcv_lcb - Process an unsolicited LCB 7637 * @vport: pointer to a host virtual N_Port data structure. 7638 * @cmdiocb: pointer to lpfc command iocb data structure. 7639 * @ndlp: pointer to a node-list data structure. 7640 * 7641 * This routine processes an unsolicited LCB(LINK CABLE BEACON) IOCB. 7642 * First, the payload of the unsolicited LCB is checked. 7643 * Then based on Subcommand beacon will either turn on or off. 7644 * 7645 * Return code 7646 * 0 - Sent the acc response 7647 * 1 - Sent the reject response. 7648 **/ 7649 static int 7650 lpfc_els_rcv_lcb(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, 7651 struct lpfc_nodelist *ndlp) 7652 { 7653 struct lpfc_hba *phba = vport->phba; 7654 struct lpfc_dmabuf *pcmd; 7655 uint8_t *lp; 7656 struct fc_lcb_request_frame *beacon; 7657 struct lpfc_lcb_context *lcb_context; 7658 u8 state, rjt_err = 0; 7659 struct ls_rjt stat; 7660 7661 pcmd = cmdiocb->cmd_dmabuf; 7662 lp = (uint8_t *)pcmd->virt; 7663 beacon = (struct fc_lcb_request_frame *)pcmd->virt; 7664 7665 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, 7666 "0192 ELS LCB Data x%x x%x x%x x%x sub x%x " 7667 "type x%x frequency %x duration x%x\n", 7668 lp[0], lp[1], lp[2], 7669 beacon->lcb_command, 7670 beacon->lcb_sub_command, 7671 beacon->lcb_type, 7672 beacon->lcb_frequency, 7673 be16_to_cpu(beacon->lcb_duration)); 7674 7675 if (beacon->lcb_sub_command != LPFC_LCB_ON && 7676 beacon->lcb_sub_command != LPFC_LCB_OFF) { 7677 rjt_err = LSRJT_CMD_UNSUPPORTED; 7678 goto rjt; 7679 } 7680 7681 if (phba->sli_rev < LPFC_SLI_REV4 || 7682 test_bit(HBA_FCOE_MODE, &phba->hba_flag) || 7683 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) < 7684 LPFC_SLI_INTF_IF_TYPE_2)) { 7685 rjt_err = LSRJT_CMD_UNSUPPORTED; 7686 goto rjt; 7687 } 7688 7689 lcb_context = kmalloc(sizeof(*lcb_context), GFP_KERNEL); 7690 if (!lcb_context) { 7691 rjt_err = LSRJT_UNABLE_TPC; 7692 goto rjt; 7693 } 7694 7695 state = (beacon->lcb_sub_command == LPFC_LCB_ON) ? 1 : 0; 7696 lcb_context->sub_command = beacon->lcb_sub_command; 7697 lcb_context->capability = 0; 7698 lcb_context->type = beacon->lcb_type; 7699 lcb_context->frequency = beacon->lcb_frequency; 7700 lcb_context->duration = beacon->lcb_duration; 7701 lcb_context->ox_id = get_job_rcvoxid(phba, cmdiocb); 7702 lcb_context->rx_id = get_job_ulpcontext(phba, cmdiocb); 7703 lcb_context->ndlp = lpfc_nlp_get(ndlp); 7704 if (!lcb_context->ndlp) { 7705 rjt_err = LSRJT_UNABLE_TPC; 7706 goto rjt_free; 7707 } 7708 7709 if (lpfc_sli4_set_beacon(vport, lcb_context, state)) { 7710 lpfc_printf_vlog(ndlp->vport, KERN_ERR, LOG_TRACE_EVENT, 7711 "0193 failed to send mail box"); 7712 lpfc_nlp_put(ndlp); 7713 rjt_err = LSRJT_UNABLE_TPC; 7714 goto rjt_free; 7715 } 7716 return 0; 7717 7718 rjt_free: 7719 kfree(lcb_context); 7720 rjt: 7721 memset(&stat, 0, sizeof(stat)); 7722 stat.un.b.lsRjtRsnCode = rjt_err; 7723 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); 7724 return 1; 7725 } 7726 7727 7728 /** 7729 * lpfc_els_flush_rscn - Clean up any rscn activities with a vport 7730 * @vport: pointer to a host virtual N_Port data structure. 7731 * 7732 * This routine cleans up any Registration State Change Notification 7733 * (RSCN) activity with a @vport. Note that the fc_rscn_flush flag of the 7734 * @vport together with the host_lock is used to prevent multiple thread 7735 * trying to access the RSCN array on a same @vport at the same time. 7736 **/ 7737 void 7738 lpfc_els_flush_rscn(struct lpfc_vport *vport) 7739 { 7740 struct Scsi_Host *shost = lpfc_shost_from_vport(vport); 7741 struct lpfc_hba *phba = vport->phba; 7742 int i; 7743 7744 spin_lock_irq(shost->host_lock); 7745 if (vport->fc_rscn_flush) { 7746 /* Another thread is walking fc_rscn_id_list on this vport */ 7747 spin_unlock_irq(shost->host_lock); 7748 return; 7749 } 7750 /* Indicate we are walking lpfc_els_flush_rscn on this vport */ 7751 vport->fc_rscn_flush = 1; 7752 spin_unlock_irq(shost->host_lock); 7753 7754 for (i = 0; i < vport->fc_rscn_id_cnt; i++) { 7755 lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]); 7756 vport->fc_rscn_id_list[i] = NULL; 7757 } 7758 clear_bit(FC_RSCN_MODE, &vport->fc_flag); 7759 clear_bit(FC_RSCN_DISCOVERY, &vport->fc_flag); 7760 spin_lock_irq(shost->host_lock); 7761 vport->fc_rscn_id_cnt = 0; 7762 spin_unlock_irq(shost->host_lock); 7763 lpfc_can_disctmo(vport); 7764 /* Indicate we are done walking this fc_rscn_id_list */ 7765 vport->fc_rscn_flush = 0; 7766 } 7767 7768 /** 7769 * lpfc_rscn_payload_check - Check whether there is a pending rscn to a did 7770 * @vport: pointer to a host virtual N_Port data structure. 7771 * @did: remote destination port identifier. 7772 * 7773 * This routine checks whether there is any pending Registration State 7774 * Configuration Notification (RSCN) to a @did on @vport. 7775 * 7776 * Return code 7777 * None zero - The @did matched with a pending rscn 7778 * 0 - not able to match @did with a pending rscn 7779 **/ 7780 int 7781 lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did) 7782 { 7783 D_ID ns_did; 7784 D_ID rscn_did; 7785 uint32_t *lp; 7786 uint32_t payload_len, i; 7787 struct Scsi_Host *shost = lpfc_shost_from_vport(vport); 7788 7789 ns_did.un.word = did; 7790 7791 /* Never match fabric nodes for RSCNs */ 7792 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) 7793 return 0; 7794 7795 /* If we are doing a FULL RSCN rediscovery, match everything */ 7796 if (test_bit(FC_RSCN_DISCOVERY, &vport->fc_flag)) 7797 return did; 7798 7799 spin_lock_irq(shost->host_lock); 7800 if (vport->fc_rscn_flush) { 7801 /* Another thread is walking fc_rscn_id_list on this vport */ 7802 spin_unlock_irq(shost->host_lock); 7803 return 0; 7804 } 7805 /* Indicate we are walking fc_rscn_id_list on this vport */ 7806 vport->fc_rscn_flush = 1; 7807 spin_unlock_irq(shost->host_lock); 7808 for (i = 0; i < vport->fc_rscn_id_cnt; i++) { 7809 lp = vport->fc_rscn_id_list[i]->virt; 7810 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK); 7811 payload_len -= sizeof(uint32_t); /* take off word 0 */ 7812 while (payload_len) { 7813 rscn_did.un.word = be32_to_cpu(*lp++); 7814 payload_len -= sizeof(uint32_t); 7815 switch (rscn_did.un.b.resv & RSCN_ADDRESS_FORMAT_MASK) { 7816 case RSCN_ADDRESS_FORMAT_PORT: 7817 if ((ns_did.un.b.domain == rscn_did.un.b.domain) 7818 && (ns_did.un.b.area == rscn_did.un.b.area) 7819 && (ns_did.un.b.id == rscn_did.un.b.id)) 7820 goto return_did_out; 7821 break; 7822 case RSCN_ADDRESS_FORMAT_AREA: 7823 if ((ns_did.un.b.domain == rscn_did.un.b.domain) 7824 && (ns_did.un.b.area == rscn_did.un.b.area)) 7825 goto return_did_out; 7826 break; 7827 case RSCN_ADDRESS_FORMAT_DOMAIN: 7828 if (ns_did.un.b.domain == rscn_did.un.b.domain) 7829 goto return_did_out; 7830 break; 7831 case RSCN_ADDRESS_FORMAT_FABRIC: 7832 goto return_did_out; 7833 } 7834 } 7835 } 7836 /* Indicate we are done with walking fc_rscn_id_list on this vport */ 7837 vport->fc_rscn_flush = 0; 7838 return 0; 7839 return_did_out: 7840 /* Indicate we are done with walking fc_rscn_id_list on this vport */ 7841 vport->fc_rscn_flush = 0; 7842 return did; 7843 } 7844 7845 /** 7846 * lpfc_rscn_recovery_check - Send recovery event to vport nodes matching rscn 7847 * @vport: pointer to a host virtual N_Port data structure. 7848 * 7849 * This routine sends recovery (NLP_EVT_DEVICE_RECOVERY) event to the 7850 * state machine for a @vport's nodes that are with pending RSCN (Registration 7851 * State Change Notification). 7852 * 7853 * Return code 7854 * 0 - Successful (currently alway return 0) 7855 **/ 7856 static int 7857 lpfc_rscn_recovery_check(struct lpfc_vport *vport) 7858 { 7859 struct lpfc_nodelist *ndlp = NULL, *n; 7860 7861 /* Move all affected nodes by pending RSCNs to NPR state. */ 7862 list_for_each_entry_safe(ndlp, n, &vport->fc_nodes, nlp_listp) { 7863 if ((ndlp->nlp_state == NLP_STE_UNUSED_NODE) || 7864 !lpfc_rscn_payload_check(vport, ndlp->nlp_DID)) 7865 continue; 7866 7867 /* NVME Target mode does not do RSCN Recovery. */ 7868 if (vport->phba->nvmet_support) 7869 continue; 7870 7871 /* If we are in the process of doing discovery on this 7872 * NPort, let it continue on its own. 7873 */ 7874 switch (ndlp->nlp_state) { 7875 case NLP_STE_PLOGI_ISSUE: 7876 case NLP_STE_ADISC_ISSUE: 7877 case NLP_STE_REG_LOGIN_ISSUE: 7878 case NLP_STE_PRLI_ISSUE: 7879 case NLP_STE_LOGO_ISSUE: 7880 continue; 7881 } 7882 7883 lpfc_disc_state_machine(vport, ndlp, NULL, 7884 NLP_EVT_DEVICE_RECOVERY); 7885 lpfc_cancel_retry_delay_tmo(vport, ndlp); 7886 } 7887 return 0; 7888 } 7889 7890 /** 7891 * lpfc_send_rscn_event - Send an RSCN event to management application 7892 * @vport: pointer to a host virtual N_Port data structure. 7893 * @cmdiocb: pointer to lpfc command iocb data structure. 7894 * 7895 * lpfc_send_rscn_event sends an RSCN netlink event to management 7896 * applications. 7897 */ 7898 static void 7899 lpfc_send_rscn_event(struct lpfc_vport *vport, 7900 struct lpfc_iocbq *cmdiocb) 7901 { 7902 struct lpfc_dmabuf *pcmd; 7903 struct Scsi_Host *shost = lpfc_shost_from_vport(vport); 7904 uint32_t *payload_ptr; 7905 uint32_t payload_len; 7906 struct lpfc_rscn_event_header *rscn_event_data; 7907 7908 pcmd = cmdiocb->cmd_dmabuf; 7909 payload_ptr = (uint32_t *) pcmd->virt; 7910 payload_len = be32_to_cpu(*payload_ptr & ~ELS_CMD_MASK); 7911 7912 rscn_event_data = kmalloc(sizeof(struct lpfc_rscn_event_header) + 7913 payload_len, GFP_KERNEL); 7914 if (!rscn_event_data) { 7915 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, 7916 "0147 Failed to allocate memory for RSCN event\n"); 7917 return; 7918 } 7919 rscn_event_data->event_type = FC_REG_RSCN_EVENT; 7920 rscn_event_data->payload_length = payload_len; 7921 memcpy(rscn_event_data->rscn_payload, payload_ptr, 7922 payload_len); 7923 7924 fc_host_post_vendor_event(shost, 7925 fc_get_event_number(), 7926 sizeof(struct lpfc_rscn_event_header) + payload_len, 7927 (char *)rscn_event_data, 7928 LPFC_NL_VENDOR_ID); 7929 7930 kfree(rscn_event_data); 7931 } 7932 7933 /** 7934 * lpfc_els_rcv_rscn - Process an unsolicited rscn iocb 7935 * @vport: pointer to a host virtual N_Port data structure. 7936 * @cmdiocb: pointer to lpfc command iocb data structure. 7937 * @ndlp: pointer to a node-list data structure. 7938 * 7939 * This routine processes an unsolicited RSCN (Registration State Change 7940 * Notification) IOCB. First, the payload of the unsolicited RSCN is walked 7941 * to invoke fc_host_post_event() routine to the FC transport layer. If the 7942 * discover state machine is about to begin discovery, it just accepts the 7943 * RSCN and the discovery process will satisfy the RSCN. If this RSCN only 7944 * contains N_Port IDs for other vports on this HBA, it just accepts the 7945 * RSCN and ignore processing it. If the state machine is in the recovery 7946 * state, the fc_rscn_id_list of this @vport is walked and the 7947 * lpfc_rscn_recovery_check() routine is invoked to send recovery event for 7948 * all nodes that match RSCN payload. Otherwise, the lpfc_els_handle_rscn() 7949 * routine is invoked to handle the RSCN event. 7950 * 7951 * Return code 7952 * 0 - Just sent the acc response 7953 * 1 - Sent the acc response and waited for name server completion 7954 **/ 7955 static int 7956 lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, 7957 struct lpfc_nodelist *ndlp) 7958 { 7959 struct Scsi_Host *shost = lpfc_shost_from_vport(vport); 7960 struct lpfc_hba *phba = vport->phba; 7961 struct lpfc_dmabuf *pcmd; 7962 uint32_t *lp, *datap; 7963 uint32_t payload_len, length, nportid, *cmd; 7964 int rscn_cnt; 7965 int rscn_id = 0, hba_id = 0; 7966 int i, tmo; 7967 7968 pcmd = cmdiocb->cmd_dmabuf; 7969 lp = (uint32_t *) pcmd->virt; 7970 7971 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK); 7972 payload_len -= sizeof(uint32_t); /* take off word 0 */ 7973 /* RSCN received */ 7974 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, 7975 "0214 RSCN received Data: x%lx x%x x%x x%x\n", 7976 vport->fc_flag, payload_len, *lp, 7977 vport->fc_rscn_id_cnt); 7978 7979 /* Send an RSCN event to the management application */ 7980 lpfc_send_rscn_event(vport, cmdiocb); 7981 7982 for (i = 0; i < payload_len/sizeof(uint32_t); i++) 7983 fc_host_post_event(shost, fc_get_event_number(), 7984 FCH_EVT_RSCN, lp[i]); 7985 7986 /* Check if RSCN is coming from a direct-connected remote NPort */ 7987 if (test_bit(FC_PT2PT, &vport->fc_flag)) { 7988 /* If so, just ACC it, no other action needed for now */ 7989 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, 7990 "2024 pt2pt RSCN %08x Data: x%lx x%x\n", 7991 *lp, vport->fc_flag, payload_len); 7992 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); 7993 7994 /* Check to see if we need to NVME rescan this target 7995 * remoteport. 7996 */ 7997 if (ndlp->nlp_fc4_type & NLP_FC4_NVME && 7998 ndlp->nlp_type & (NLP_NVME_TARGET | NLP_NVME_DISCOVERY)) 7999 lpfc_nvme_rescan_port(vport, ndlp); 8000 return 0; 8001 } 8002 8003 /* If we are about to begin discovery, just ACC the RSCN. 8004 * Discovery processing will satisfy it. 8005 */ 8006 if (vport->port_state <= LPFC_NS_QRY) { 8007 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, 8008 "RCV RSCN ignore: did:x%x/ste:x%x flg:x%lx", 8009 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag); 8010 8011 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); 8012 return 0; 8013 } 8014 8015 /* If this RSCN just contains NPortIDs for other vports on this HBA, 8016 * just ACC and ignore it. 8017 */ 8018 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && 8019 !(vport->cfg_peer_port_login)) { 8020 i = payload_len; 8021 datap = lp; 8022 while (i > 0) { 8023 nportid = *datap++; 8024 nportid = ((be32_to_cpu(nportid)) & Mask_DID); 8025 i -= sizeof(uint32_t); 8026 rscn_id++; 8027 if (lpfc_find_vport_by_did(phba, nportid)) 8028 hba_id++; 8029 } 8030 if (rscn_id == hba_id) { 8031 /* ALL NPortIDs in RSCN are on HBA */ 8032 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, 8033 "0219 Ignore RSCN " 8034 "Data: x%lx x%x x%x x%x\n", 8035 vport->fc_flag, payload_len, 8036 *lp, vport->fc_rscn_id_cnt); 8037 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, 8038 "RCV RSCN vport: did:x%x/ste:x%x flg:x%lx", 8039 ndlp->nlp_DID, vport->port_state, 8040 ndlp->nlp_flag); 8041 8042 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, 8043 ndlp, NULL); 8044 /* Restart disctmo if its already running */ 8045 if (test_bit(FC_DISC_TMO, &vport->fc_flag)) { 8046 tmo = ((phba->fc_ratov * 3) + 3); 8047 mod_timer(&vport->fc_disctmo, 8048 jiffies + secs_to_jiffies(tmo)); 8049 } 8050 return 0; 8051 } 8052 } 8053 8054 spin_lock_irq(shost->host_lock); 8055 if (vport->fc_rscn_flush) { 8056 /* Another thread is walking fc_rscn_id_list on this vport */ 8057 spin_unlock_irq(shost->host_lock); 8058 set_bit(FC_RSCN_DISCOVERY, &vport->fc_flag); 8059 /* Send back ACC */ 8060 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); 8061 return 0; 8062 } 8063 /* Indicate we are walking fc_rscn_id_list on this vport */ 8064 vport->fc_rscn_flush = 1; 8065 spin_unlock_irq(shost->host_lock); 8066 /* Get the array count after successfully have the token */ 8067 rscn_cnt = vport->fc_rscn_id_cnt; 8068 /* If we are already processing an RSCN, save the received 8069 * RSCN payload buffer, cmdiocb->cmd_dmabuf to process later. 8070 */ 8071 if (test_bit(FC_RSCN_MODE, &vport->fc_flag) || 8072 test_bit(FC_NDISC_ACTIVE, &vport->fc_flag)) { 8073 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, 8074 "RCV RSCN defer: did:x%x/ste:x%x flg:x%lx", 8075 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag); 8076 8077 set_bit(FC_RSCN_DEFERRED, &vport->fc_flag); 8078 8079 /* Restart disctmo if its already running */ 8080 if (test_bit(FC_DISC_TMO, &vport->fc_flag)) { 8081 tmo = ((phba->fc_ratov * 3) + 3); 8082 mod_timer(&vport->fc_disctmo, 8083 jiffies + secs_to_jiffies(tmo)); 8084 } 8085 if ((rscn_cnt < FC_MAX_HOLD_RSCN) && 8086 !test_bit(FC_RSCN_DISCOVERY, &vport->fc_flag)) { 8087 set_bit(FC_RSCN_MODE, &vport->fc_flag); 8088 if (rscn_cnt) { 8089 cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt; 8090 length = be32_to_cpu(*cmd & ~ELS_CMD_MASK); 8091 } 8092 if ((rscn_cnt) && 8093 (payload_len + length <= LPFC_BPL_SIZE)) { 8094 *cmd &= ELS_CMD_MASK; 8095 *cmd |= cpu_to_be32(payload_len + length); 8096 memcpy(((uint8_t *)cmd) + length, lp, 8097 payload_len); 8098 } else { 8099 vport->fc_rscn_id_list[rscn_cnt] = pcmd; 8100 vport->fc_rscn_id_cnt++; 8101 /* If we zero, cmdiocb->cmd_dmabuf, the calling 8102 * routine will not try to free it. 8103 */ 8104 cmdiocb->cmd_dmabuf = NULL; 8105 } 8106 /* Deferred RSCN */ 8107 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, 8108 "0235 Deferred RSCN " 8109 "Data: x%x x%lx x%x\n", 8110 vport->fc_rscn_id_cnt, vport->fc_flag, 8111 vport->port_state); 8112 } else { 8113 set_bit(FC_RSCN_DISCOVERY, &vport->fc_flag); 8114 /* ReDiscovery RSCN */ 8115 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, 8116 "0234 ReDiscovery RSCN " 8117 "Data: x%x x%lx x%x\n", 8118 vport->fc_rscn_id_cnt, vport->fc_flag, 8119 vport->port_state); 8120 } 8121 /* Indicate we are done walking fc_rscn_id_list on this vport */ 8122 vport->fc_rscn_flush = 0; 8123 /* Send back ACC */ 8124 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); 8125 /* send RECOVERY event for ALL nodes that match RSCN payload */ 8126 lpfc_rscn_recovery_check(vport); 8127 return 0; 8128 } 8129 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, 8130 "RCV RSCN: did:x%x/ste:x%x flg:x%lx", 8131 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag); 8132 8133 set_bit(FC_RSCN_MODE, &vport->fc_flag); 8134 vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd; 8135 /* Indicate we are done walking fc_rscn_id_list on this vport */ 8136 vport->fc_rscn_flush = 0; 8137 /* 8138 * If we zero, cmdiocb->cmd_dmabuf, the calling routine will 8139 * not try to free it. 8140 */ 8141 cmdiocb->cmd_dmabuf = NULL; 8142 lpfc_set_disctmo(vport); 8143 /* Send back ACC */ 8144 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); 8145 /* send RECOVERY event for ALL nodes that match RSCN payload */ 8146 lpfc_rscn_recovery_check(vport); 8147 return lpfc_els_handle_rscn(vport); 8148 } 8149 8150 /** 8151 * lpfc_els_handle_rscn - Handle rscn for a vport 8152 * @vport: pointer to a host virtual N_Port data structure. 8153 * 8154 * This routine handles the Registration State Configuration Notification 8155 * (RSCN) for a @vport. If login to NameServer does not exist, a new ndlp shall 8156 * be created and a Port Login (PLOGI) to the NameServer is issued. Otherwise, 8157 * if the ndlp to NameServer exists, a Common Transport (CT) command to the 8158 * NameServer shall be issued. If CT command to the NameServer fails to be 8159 * issued, the lpfc_els_flush_rscn() routine shall be invoked to clean up any 8160 * RSCN activities with the @vport. 8161 * 8162 * Return code 8163 * 0 - Cleaned up rscn on the @vport 8164 * 1 - Wait for plogi to name server before proceed 8165 **/ 8166 int 8167 lpfc_els_handle_rscn(struct lpfc_vport *vport) 8168 { 8169 struct lpfc_nodelist *ndlp; 8170 struct lpfc_hba *phba = vport->phba; 8171 8172 /* Ignore RSCN if the port is being torn down. */ 8173 if (test_bit(FC_UNLOADING, &vport->load_flag)) { 8174 lpfc_els_flush_rscn(vport); 8175 return 0; 8176 } 8177 8178 /* Start timer for RSCN processing */ 8179 lpfc_set_disctmo(vport); 8180 8181 /* RSCN processed */ 8182 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, 8183 "0215 RSCN processed Data: x%lx x%x x%x x%x x%x x%x\n", 8184 vport->fc_flag, 0, vport->fc_rscn_id_cnt, 8185 vport->port_state, vport->num_disc_nodes, 8186 vport->gidft_inp); 8187 8188 /* To process RSCN, first compare RSCN data with NameServer */ 8189 vport->fc_ns_retry = 0; 8190 vport->num_disc_nodes = 0; 8191 8192 ndlp = lpfc_findnode_did(vport, NameServer_DID); 8193 if (ndlp && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) { 8194 /* Good ndlp, issue CT Request to NameServer. Need to 8195 * know how many gidfts were issued. If none, then just 8196 * flush the RSCN. Otherwise, the outstanding requests 8197 * need to complete. 8198 */ 8199 if (phba->cfg_ns_query == LPFC_NS_QUERY_GID_FT) { 8200 if (lpfc_issue_gidft(vport) > 0) 8201 return 1; 8202 } else if (phba->cfg_ns_query == LPFC_NS_QUERY_GID_PT) { 8203 if (lpfc_issue_gidpt(vport) > 0) 8204 return 1; 8205 } else { 8206 return 1; 8207 } 8208 } else { 8209 /* Nameserver login in question. Revalidate. */ 8210 if (ndlp) { 8211 ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE; 8212 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); 8213 } else { 8214 ndlp = lpfc_nlp_init(vport, NameServer_DID); 8215 if (!ndlp) { 8216 lpfc_els_flush_rscn(vport); 8217 return 0; 8218 } 8219 ndlp->nlp_prev_state = ndlp->nlp_state; 8220 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); 8221 } 8222 ndlp->nlp_type |= NLP_FABRIC; 8223 lpfc_issue_els_plogi(vport, NameServer_DID, 0); 8224 /* Wait for NameServer login cmpl before we can 8225 * continue 8226 */ 8227 return 1; 8228 } 8229 8230 lpfc_els_flush_rscn(vport); 8231 return 0; 8232 } 8233 8234 /** 8235 * lpfc_els_rcv_flogi - Process an unsolicited flogi iocb 8236 * @vport: pointer to a host virtual N_Port data structure. 8237 * @cmdiocb: pointer to lpfc command iocb data structure. 8238 * @ndlp: pointer to a node-list data structure. 8239 * 8240 * This routine processes Fabric Login (FLOGI) IOCB received as an ELS 8241 * unsolicited event. An unsolicited FLOGI can be received in a point-to- 8242 * point topology. As an unsolicited FLOGI should not be received in a loop 8243 * mode, any unsolicited FLOGI received in loop mode shall be ignored. The 8244 * lpfc_check_sparm() routine is invoked to check the parameters in the 8245 * unsolicited FLOGI. If parameters validation failed, the routine 8246 * lpfc_els_rsp_reject() shall be called with reject reason code set to 8247 * LSEXP_SPARM_OPTIONS to reject the FLOGI. Otherwise, the Port WWN in the 8248 * FLOGI shall be compared with the Port WWN of the @vport to determine who 8249 * will initiate PLOGI. The higher lexicographical value party shall has 8250 * higher priority (as the winning port) and will initiate PLOGI and 8251 * communicate Port_IDs (Addresses) for both nodes in PLOGI. The result 8252 * of this will be marked in the @vport fc_flag field with FC_PT2PT_PLOGI 8253 * and then the lpfc_els_rsp_acc() routine is invoked to accept the FLOGI. 8254 * 8255 * Return code 8256 * 0 - Successfully processed the unsolicited flogi 8257 * 1 - Failed to process the unsolicited flogi 8258 **/ 8259 static int 8260 lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, 8261 struct lpfc_nodelist *ndlp) 8262 { 8263 struct Scsi_Host *shost = lpfc_shost_from_vport(vport); 8264 struct lpfc_hba *phba = vport->phba; 8265 struct lpfc_dmabuf *pcmd = cmdiocb->cmd_dmabuf; 8266 uint32_t *lp = (uint32_t *) pcmd->virt; 8267 union lpfc_wqe128 *wqe = &cmdiocb->wqe; 8268 struct serv_parm *sp; 8269 LPFC_MBOXQ_t *mbox; 8270 uint32_t cmd, did; 8271 int rc; 8272 unsigned long fc_flag = 0; 8273 uint32_t port_state = 0; 8274 8275 /* Clear external loopback plug detected flag */ 8276 phba->link_flag &= ~LS_EXTERNAL_LOOPBACK; 8277 8278 cmd = *lp++; 8279 sp = (struct serv_parm *) lp; 8280 8281 /* FLOGI received */ 8282 8283 lpfc_set_disctmo(vport); 8284 8285 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { 8286 /* We should never receive a FLOGI in loop mode, ignore it */ 8287 did = bf_get(wqe_els_did, &wqe->xmit_els_rsp.wqe_dest); 8288 8289 /* An FLOGI ELS command <elsCmd> was received from DID <did> in 8290 Loop Mode */ 8291 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, 8292 "0113 An FLOGI ELS command x%x was " 8293 "received from DID x%x in Loop Mode\n", 8294 cmd, did); 8295 return 1; 8296 } 8297 8298 (void) lpfc_check_sparm(vport, ndlp, sp, CLASS3, 1); 8299 8300 /* 8301 * If our portname is greater than the remote portname, 8302 * then we initiate Nport login. 8303 */ 8304 8305 rc = memcmp(&vport->fc_portname, &sp->portName, 8306 sizeof(struct lpfc_name)); 8307 8308 if (!rc) { 8309 if (phba->sli_rev < LPFC_SLI_REV4) { 8310 mbox = mempool_alloc(phba->mbox_mem_pool, 8311 GFP_KERNEL); 8312 if (!mbox) 8313 return 1; 8314 lpfc_linkdown(phba); 8315 lpfc_init_link(phba, mbox, 8316 phba->cfg_topology, 8317 phba->cfg_link_speed); 8318 mbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0; 8319 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; 8320 mbox->vport = vport; 8321 rc = lpfc_sli_issue_mbox(phba, mbox, 8322 MBX_NOWAIT); 8323 lpfc_set_loopback_flag(phba); 8324 if (rc == MBX_NOT_FINISHED) 8325 mempool_free(mbox, phba->mbox_mem_pool); 8326 return 1; 8327 } 8328 8329 /* External loopback plug insertion detected */ 8330 phba->link_flag |= LS_EXTERNAL_LOOPBACK; 8331 8332 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS | LOG_LIBDFC, 8333 "1119 External Loopback plug detected\n"); 8334 8335 /* abort the flogi coming back to ourselves 8336 * due to external loopback on the port. 8337 */ 8338 lpfc_els_abort_flogi(phba); 8339 return 0; 8340 8341 } else if (rc > 0) { /* greater than */ 8342 set_bit(FC_PT2PT_PLOGI, &vport->fc_flag); 8343 8344 /* If we have the high WWPN we can assign our own 8345 * myDID; otherwise, we have to WAIT for a PLOGI 8346 * from the remote NPort to find out what it 8347 * will be. 8348 */ 8349 vport->fc_myDID = PT2PT_LocalID; 8350 } else { 8351 vport->fc_myDID = PT2PT_RemoteID; 8352 } 8353 8354 /* 8355 * The vport state should go to LPFC_FLOGI only 8356 * AFTER we issue a FLOGI, not receive one. 8357 */ 8358 spin_lock_irq(shost->host_lock); 8359 fc_flag = vport->fc_flag; 8360 port_state = vport->port_state; 8361 /* Acking an unsol FLOGI. Count 1 for link bounce 8362 * work-around. 8363 */ 8364 vport->rcv_flogi_cnt++; 8365 spin_unlock_irq(shost->host_lock); 8366 set_bit(FC_PT2PT, &vport->fc_flag); 8367 clear_bit(FC_FABRIC, &vport->fc_flag); 8368 clear_bit(FC_PUBLIC_LOOP, &vport->fc_flag); 8369 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, 8370 "3311 Rcv Flogi PS x%x new PS x%x " 8371 "fc_flag x%lx new fc_flag x%lx\n", 8372 port_state, vport->port_state, 8373 fc_flag, vport->fc_flag); 8374 8375 /* 8376 * We temporarily set fc_myDID to make it look like we are 8377 * a Fabric. This is done just so we end up with the right 8378 * did / sid on the FLOGI ACC rsp. 8379 */ 8380 did = vport->fc_myDID; 8381 vport->fc_myDID = Fabric_DID; 8382 8383 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm)); 8384 8385 /* Defer ACC response until AFTER we issue a FLOGI */ 8386 if (!test_bit(HBA_FLOGI_ISSUED, &phba->hba_flag)) { 8387 phba->defer_flogi_acc.rx_id = bf_get(wqe_ctxt_tag, 8388 &wqe->xmit_els_rsp.wqe_com); 8389 phba->defer_flogi_acc.ox_id = bf_get(wqe_rcvoxid, 8390 &wqe->xmit_els_rsp.wqe_com); 8391 8392 vport->fc_myDID = did; 8393 8394 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, 8395 "3344 Deferring FLOGI ACC: rx_id: x%x," 8396 " ox_id: x%x, hba_flag x%lx\n", 8397 phba->defer_flogi_acc.rx_id, 8398 phba->defer_flogi_acc.ox_id, phba->hba_flag); 8399 8400 phba->defer_flogi_acc.flag = true; 8401 8402 /* This nlp_get is paired with nlp_puts that reset the 8403 * defer_flogi_acc.flag back to false. We need to retain 8404 * a kref on the ndlp until the deferred FLOGI ACC is 8405 * processed or cancelled. 8406 */ 8407 phba->defer_flogi_acc.ndlp = lpfc_nlp_get(ndlp); 8408 return 0; 8409 } 8410 8411 /* Send back ACC */ 8412 lpfc_els_rsp_acc(vport, ELS_CMD_FLOGI, cmdiocb, ndlp, NULL); 8413 8414 /* Now lets put fc_myDID back to what its supposed to be */ 8415 vport->fc_myDID = did; 8416 8417 return 0; 8418 } 8419 8420 /** 8421 * lpfc_els_rcv_rnid - Process an unsolicited rnid iocb 8422 * @vport: pointer to a host virtual N_Port data structure. 8423 * @cmdiocb: pointer to lpfc command iocb data structure. 8424 * @ndlp: pointer to a node-list data structure. 8425 * 8426 * This routine processes Request Node Identification Data (RNID) IOCB 8427 * received as an ELS unsolicited event. Only when the RNID specified format 8428 * 0x0 or 0xDF (Topology Discovery Specific Node Identification Data) 8429 * present, this routine will invoke the lpfc_els_rsp_rnid_acc() routine to 8430 * Accept (ACC) the RNID ELS command. All the other RNID formats are 8431 * rejected by invoking the lpfc_els_rsp_reject() routine. 8432 * 8433 * Return code 8434 * 0 - Successfully processed rnid iocb (currently always return 0) 8435 **/ 8436 static int 8437 lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, 8438 struct lpfc_nodelist *ndlp) 8439 { 8440 struct lpfc_dmabuf *pcmd; 8441 uint32_t *lp; 8442 RNID *rn; 8443 struct ls_rjt stat; 8444 8445 pcmd = cmdiocb->cmd_dmabuf; 8446 lp = (uint32_t *) pcmd->virt; 8447 8448 lp++; 8449 rn = (RNID *) lp; 8450 8451 /* RNID received */ 8452 8453 switch (rn->Format) { 8454 case 0: 8455 case RNID_TOPOLOGY_DISC: 8456 /* Send back ACC */ 8457 lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp); 8458 break; 8459 default: 8460 /* Reject this request because format not supported */ 8461 stat.un.b.lsRjtRsvd0 = 0; 8462 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; 8463 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; 8464 stat.un.b.vendorUnique = 0; 8465 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, 8466 NULL); 8467 } 8468 return 0; 8469 } 8470 8471 /** 8472 * lpfc_els_rcv_echo - Process an unsolicited echo iocb 8473 * @vport: pointer to a host virtual N_Port data structure. 8474 * @cmdiocb: pointer to lpfc command iocb data structure. 8475 * @ndlp: pointer to a node-list data structure. 8476 * 8477 * Return code 8478 * 0 - Successfully processed echo iocb (currently always return 0) 8479 **/ 8480 static int 8481 lpfc_els_rcv_echo(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, 8482 struct lpfc_nodelist *ndlp) 8483 { 8484 uint8_t *pcmd; 8485 8486 pcmd = (uint8_t *)cmdiocb->cmd_dmabuf->virt; 8487 8488 /* skip over first word of echo command to find echo data */ 8489 pcmd += sizeof(uint32_t); 8490 8491 lpfc_els_rsp_echo_acc(vport, pcmd, cmdiocb, ndlp); 8492 return 0; 8493 } 8494 8495 /** 8496 * lpfc_els_rcv_lirr - Process an unsolicited lirr iocb 8497 * @vport: pointer to a host virtual N_Port data structure. 8498 * @cmdiocb: pointer to lpfc command iocb data structure. 8499 * @ndlp: pointer to a node-list data structure. 8500 * 8501 * This routine processes a Link Incident Report Registration(LIRR) IOCB 8502 * received as an ELS unsolicited event. Currently, this function just invokes 8503 * the lpfc_els_rsp_reject() routine to reject the LIRR IOCB unconditionally. 8504 * 8505 * Return code 8506 * 0 - Successfully processed lirr iocb (currently always return 0) 8507 **/ 8508 static int 8509 lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, 8510 struct lpfc_nodelist *ndlp) 8511 { 8512 struct ls_rjt stat; 8513 8514 /* For now, unconditionally reject this command */ 8515 stat.un.b.lsRjtRsvd0 = 0; 8516 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; 8517 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; 8518 stat.un.b.vendorUnique = 0; 8519 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); 8520 return 0; 8521 } 8522 8523 /** 8524 * lpfc_els_rcv_rrq - Process an unsolicited rrq iocb 8525 * @vport: pointer to a host virtual N_Port data structure. 8526 * @cmdiocb: pointer to lpfc command iocb data structure. 8527 * @ndlp: pointer to a node-list data structure. 8528 * 8529 * This routine processes a Reinstate Recovery Qualifier (RRQ) IOCB 8530 * received as an ELS unsolicited event. A request to RRQ shall only 8531 * be accepted if the Originator Nx_Port N_Port_ID or the Responder 8532 * Nx_Port N_Port_ID of the target Exchange is the same as the 8533 * N_Port_ID of the Nx_Port that makes the request. If the RRQ is 8534 * not accepted, an LS_RJT with reason code "Unable to perform 8535 * command request" and reason code explanation "Invalid Originator 8536 * S_ID" shall be returned. For now, we just unconditionally accept 8537 * RRQ from the target. 8538 **/ 8539 static void 8540 lpfc_els_rcv_rrq(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, 8541 struct lpfc_nodelist *ndlp) 8542 { 8543 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); 8544 if (vport->phba->sli_rev == LPFC_SLI_REV4) 8545 lpfc_els_clear_rrq(vport, cmdiocb, ndlp); 8546 } 8547 8548 /** 8549 * lpfc_els_rsp_rls_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd 8550 * @phba: pointer to lpfc hba data structure. 8551 * @pmb: pointer to the driver internal queue element for mailbox command. 8552 * 8553 * This routine is the completion callback function for the MBX_READ_LNK_STAT 8554 * mailbox command. This callback function is to actually send the Accept 8555 * (ACC) response to a Read Link Status (RLS) unsolicited IOCB event. It 8556 * collects the link statistics from the completion of the MBX_READ_LNK_STAT 8557 * mailbox command, constructs the RLS response with the link statistics 8558 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC 8559 * response to the RLS. 8560 * 8561 * Note that the ndlp reference count will be incremented by 1 for holding the 8562 * ndlp and the reference to ndlp will be stored into the ndlp field of 8563 * the IOCB for the completion callback function to the RLS Accept Response 8564 * ELS IOCB command. 8565 * 8566 **/ 8567 static void 8568 lpfc_els_rsp_rls_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) 8569 { 8570 int rc = 0; 8571 MAILBOX_t *mb; 8572 IOCB_t *icmd; 8573 union lpfc_wqe128 *wqe; 8574 struct RLS_RSP *rls_rsp; 8575 uint8_t *pcmd; 8576 struct lpfc_iocbq *elsiocb; 8577 struct lpfc_nodelist *ndlp; 8578 uint16_t oxid; 8579 uint16_t rxid; 8580 uint32_t cmdsize; 8581 u32 ulp_context; 8582 8583 mb = &pmb->u.mb; 8584 8585 ndlp = pmb->ctx_ndlp; 8586 rxid = (uint16_t)(pmb->ctx_u.ox_rx_id & 0xffff); 8587 oxid = (uint16_t)((pmb->ctx_u.ox_rx_id >> 16) & 0xffff); 8588 memset(&pmb->ctx_u, 0, sizeof(pmb->ctx_u)); 8589 pmb->ctx_ndlp = NULL; 8590 8591 if (mb->mbxStatus) { 8592 mempool_free(pmb, phba->mbox_mem_pool); 8593 return; 8594 } 8595 8596 cmdsize = sizeof(struct RLS_RSP) + sizeof(uint32_t); 8597 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize, 8598 lpfc_max_els_tries, ndlp, 8599 ndlp->nlp_DID, ELS_CMD_ACC); 8600 8601 /* Decrement the ndlp reference count from previous mbox command */ 8602 lpfc_nlp_put(ndlp); 8603 8604 if (!elsiocb) { 8605 mempool_free(pmb, phba->mbox_mem_pool); 8606 return; 8607 } 8608 8609 ulp_context = get_job_ulpcontext(phba, elsiocb); 8610 if (phba->sli_rev == LPFC_SLI_REV4) { 8611 wqe = &elsiocb->wqe; 8612 /* Xri / rx_id */ 8613 bf_set(wqe_ctxt_tag, &wqe->generic.wqe_com, rxid); 8614 bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com, oxid); 8615 } else { 8616 icmd = &elsiocb->iocb; 8617 icmd->ulpContext = rxid; 8618 icmd->unsli3.rcvsli3.ox_id = oxid; 8619 } 8620 8621 pcmd = (uint8_t *)elsiocb->cmd_dmabuf->virt; 8622 *((uint32_t *) (pcmd)) = ELS_CMD_ACC; 8623 pcmd += sizeof(uint32_t); /* Skip past command */ 8624 rls_rsp = (struct RLS_RSP *)pcmd; 8625 8626 rls_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt); 8627 rls_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt); 8628 rls_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt); 8629 rls_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt); 8630 rls_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord); 8631 rls_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt); 8632 mempool_free(pmb, phba->mbox_mem_pool); 8633 /* Xmit ELS RLS ACC response tag <ulpIoTag> */ 8634 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS, 8635 "2874 Xmit ELS RLS ACC response tag x%x xri x%x, " 8636 "did x%x, nlp_flag x%lx, nlp_state x%x, rpi x%x\n", 8637 elsiocb->iotag, ulp_context, 8638 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, 8639 ndlp->nlp_rpi); 8640 elsiocb->cmd_cmpl = lpfc_cmpl_els_rsp; 8641 phba->fc_stat.elsXmitACC++; 8642 elsiocb->ndlp = lpfc_nlp_get(ndlp); 8643 if (!elsiocb->ndlp) { 8644 lpfc_els_free_iocb(phba, elsiocb); 8645 return; 8646 } 8647 8648 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); 8649 if (rc == IOCB_ERROR) { 8650 lpfc_els_free_iocb(phba, elsiocb); 8651 lpfc_nlp_put(ndlp); 8652 } 8653 return; 8654 } 8655 8656 /** 8657 * lpfc_els_rcv_rls - Process an unsolicited rls iocb 8658 * @vport: pointer to a host virtual N_Port data structure. 8659 * @cmdiocb: pointer to lpfc command iocb data structure. 8660 * @ndlp: pointer to a node-list data structure. 8661 * 8662 * This routine processes Read Link Status (RLS) IOCB received as an 8663 * ELS unsolicited event. It first checks the remote port state. If the 8664 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE 8665 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject 8666 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command 8667 * for reading the HBA link statistics. It is for the callback function, 8668 * lpfc_els_rsp_rls_acc(), set to the MBX_READ_LNK_STAT mailbox command 8669 * to actually sending out RPL Accept (ACC) response. 8670 * 8671 * Return codes 8672 * 0 - Successfully processed rls iocb (currently always return 0) 8673 **/ 8674 static int 8675 lpfc_els_rcv_rls(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, 8676 struct lpfc_nodelist *ndlp) 8677 { 8678 struct lpfc_hba *phba = vport->phba; 8679 LPFC_MBOXQ_t *mbox; 8680 struct ls_rjt stat; 8681 u32 ctx = get_job_ulpcontext(phba, cmdiocb); 8682 u32 ox_id = get_job_rcvoxid(phba, cmdiocb); 8683 8684 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && 8685 (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) 8686 /* reject the unsolicited RLS request and done with it */ 8687 goto reject_out; 8688 8689 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC); 8690 if (mbox) { 8691 lpfc_read_lnk_stat(phba, mbox); 8692 mbox->ctx_u.ox_rx_id = ox_id << 16 | ctx; 8693 mbox->ctx_ndlp = lpfc_nlp_get(ndlp); 8694 if (!mbox->ctx_ndlp) 8695 goto node_err; 8696 mbox->vport = vport; 8697 mbox->mbox_cmpl = lpfc_els_rsp_rls_acc; 8698 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) 8699 != MBX_NOT_FINISHED) 8700 /* Mbox completion will send ELS Response */ 8701 return 0; 8702 /* Decrement reference count used for the failed mbox 8703 * command. 8704 */ 8705 lpfc_nlp_put(ndlp); 8706 node_err: 8707 mempool_free(mbox, phba->mbox_mem_pool); 8708 } 8709 reject_out: 8710 /* issue rejection response */ 8711 stat.un.b.lsRjtRsvd0 = 0; 8712 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; 8713 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; 8714 stat.un.b.vendorUnique = 0; 8715 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); 8716 return 0; 8717 } 8718 8719 /** 8720 * lpfc_els_rcv_rtv - Process an unsolicited rtv iocb 8721 * @vport: pointer to a host virtual N_Port data structure. 8722 * @cmdiocb: pointer to lpfc command iocb data structure. 8723 * @ndlp: pointer to a node-list data structure. 8724 * 8725 * This routine processes Read Timout Value (RTV) IOCB received as an 8726 * ELS unsolicited event. It first checks the remote port state. If the 8727 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE 8728 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject 8729 * response. Otherwise, it sends the Accept(ACC) response to a Read Timeout 8730 * Value (RTV) unsolicited IOCB event. 8731 * 8732 * Note that the ndlp reference count will be incremented by 1 for holding the 8733 * ndlp and the reference to ndlp will be stored into the ndlp field of 8734 * the IOCB for the completion callback function to the RTV Accept Response 8735 * ELS IOCB command. 8736 * 8737 * Return codes 8738 * 0 - Successfully processed rtv iocb (currently always return 0) 8739 **/ 8740 static int 8741 lpfc_els_rcv_rtv(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, 8742 struct lpfc_nodelist *ndlp) 8743 { 8744 int rc = 0; 8745 IOCB_t *icmd; 8746 union lpfc_wqe128 *wqe; 8747 struct lpfc_hba *phba = vport->phba; 8748 struct ls_rjt stat; 8749 struct RTV_RSP *rtv_rsp; 8750 uint8_t *pcmd; 8751 struct lpfc_iocbq *elsiocb; 8752 uint32_t cmdsize; 8753 u32 ulp_context; 8754 8755 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && 8756 (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) 8757 /* reject the unsolicited RTV request and done with it */ 8758 goto reject_out; 8759 8760 cmdsize = sizeof(struct RTV_RSP) + sizeof(uint32_t); 8761 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize, 8762 lpfc_max_els_tries, ndlp, 8763 ndlp->nlp_DID, ELS_CMD_ACC); 8764 8765 if (!elsiocb) 8766 return 1; 8767 8768 pcmd = (uint8_t *)elsiocb->cmd_dmabuf->virt; 8769 *((uint32_t *) (pcmd)) = ELS_CMD_ACC; 8770 pcmd += sizeof(uint32_t); /* Skip past command */ 8771 8772 ulp_context = get_job_ulpcontext(phba, elsiocb); 8773 /* use the command's xri in the response */ 8774 if (phba->sli_rev == LPFC_SLI_REV4) { 8775 wqe = &elsiocb->wqe; 8776 bf_set(wqe_ctxt_tag, &wqe->generic.wqe_com, 8777 get_job_ulpcontext(phba, cmdiocb)); 8778 bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com, 8779 get_job_rcvoxid(phba, cmdiocb)); 8780 } else { 8781 icmd = &elsiocb->iocb; 8782 icmd->ulpContext = get_job_ulpcontext(phba, cmdiocb); 8783 icmd->unsli3.rcvsli3.ox_id = get_job_rcvoxid(phba, cmdiocb); 8784 } 8785 8786 rtv_rsp = (struct RTV_RSP *)pcmd; 8787 8788 /* populate RTV payload */ 8789 rtv_rsp->ratov = cpu_to_be32(phba->fc_ratov * 1000); /* report msecs */ 8790 rtv_rsp->edtov = cpu_to_be32(phba->fc_edtov); 8791 bf_set(qtov_edtovres, rtv_rsp, phba->fc_edtovResol ? 1 : 0); 8792 bf_set(qtov_rttov, rtv_rsp, 0); /* Field is for FC ONLY */ 8793 rtv_rsp->qtov = cpu_to_be32(rtv_rsp->qtov); 8794 8795 /* Xmit ELS RLS ACC response tag <ulpIoTag> */ 8796 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS, 8797 "2875 Xmit ELS RTV ACC response tag x%x xri x%x, " 8798 "did x%x, nlp_flag x%lx, nlp_state x%x, rpi x%x, " 8799 "Data: x%x x%x x%x\n", 8800 elsiocb->iotag, ulp_context, 8801 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, 8802 ndlp->nlp_rpi, 8803 rtv_rsp->ratov, rtv_rsp->edtov, rtv_rsp->qtov); 8804 elsiocb->cmd_cmpl = lpfc_cmpl_els_rsp; 8805 phba->fc_stat.elsXmitACC++; 8806 elsiocb->ndlp = lpfc_nlp_get(ndlp); 8807 if (!elsiocb->ndlp) { 8808 lpfc_els_free_iocb(phba, elsiocb); 8809 return 0; 8810 } 8811 8812 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); 8813 if (rc == IOCB_ERROR) { 8814 lpfc_els_free_iocb(phba, elsiocb); 8815 lpfc_nlp_put(ndlp); 8816 } 8817 return 0; 8818 8819 reject_out: 8820 /* issue rejection response */ 8821 stat.un.b.lsRjtRsvd0 = 0; 8822 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; 8823 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; 8824 stat.un.b.vendorUnique = 0; 8825 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); 8826 return 0; 8827 } 8828 8829 /* lpfc_issue_els_rrq - Process an unsolicited rrq iocb 8830 * @vport: pointer to a host virtual N_Port data structure. 8831 * @ndlp: pointer to a node-list data structure. 8832 * @did: DID of the target. 8833 * @rrq: Pointer to the rrq struct. 8834 * 8835 * Build a ELS RRQ command and send it to the target. If the issue_iocb is 8836 * successful, the completion handler will clear the RRQ. 8837 * 8838 * Return codes 8839 * 0 - Successfully sent rrq els iocb. 8840 * 1 - Failed to send rrq els iocb. 8841 **/ 8842 static int 8843 lpfc_issue_els_rrq(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, 8844 uint32_t did, struct lpfc_node_rrq *rrq) 8845 { 8846 struct lpfc_hba *phba = vport->phba; 8847 struct RRQ *els_rrq; 8848 struct lpfc_iocbq *elsiocb; 8849 uint8_t *pcmd; 8850 uint16_t cmdsize; 8851 int ret; 8852 8853 if (!ndlp) 8854 return 1; 8855 8856 /* If ndlp is not NULL, we will bump the reference count on it */ 8857 cmdsize = (sizeof(uint32_t) + sizeof(struct RRQ)); 8858 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, did, 8859 ELS_CMD_RRQ); 8860 if (!elsiocb) 8861 return 1; 8862 8863 pcmd = (uint8_t *)elsiocb->cmd_dmabuf->virt; 8864 8865 /* For RRQ request, remainder of payload is Exchange IDs */ 8866 *((uint32_t *) (pcmd)) = ELS_CMD_RRQ; 8867 pcmd += sizeof(uint32_t); 8868 els_rrq = (struct RRQ *) pcmd; 8869 8870 bf_set(rrq_oxid, els_rrq, phba->sli4_hba.xri_ids[rrq->xritag]); 8871 bf_set(rrq_rxid, els_rrq, rrq->rxid); 8872 bf_set(rrq_did, els_rrq, vport->fc_myDID); 8873 els_rrq->rrq = cpu_to_be32(els_rrq->rrq); 8874 els_rrq->rrq_exchg = cpu_to_be32(els_rrq->rrq_exchg); 8875 8876 8877 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, 8878 "Issue RRQ: did:x%x", 8879 did, rrq->xritag, rrq->rxid); 8880 elsiocb->context_un.rrq = rrq; 8881 elsiocb->cmd_cmpl = lpfc_cmpl_els_rrq; 8882 8883 elsiocb->ndlp = lpfc_nlp_get(ndlp); 8884 if (!elsiocb->ndlp) 8885 goto io_err; 8886 8887 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); 8888 if (ret == IOCB_ERROR) { 8889 lpfc_nlp_put(ndlp); 8890 goto io_err; 8891 } 8892 return 0; 8893 8894 io_err: 8895 lpfc_els_free_iocb(phba, elsiocb); 8896 return 1; 8897 } 8898 8899 /** 8900 * lpfc_send_rrq - Sends ELS RRQ if needed. 8901 * @phba: pointer to lpfc hba data structure. 8902 * @rrq: pointer to the active rrq. 8903 * 8904 * This routine will call the lpfc_issue_els_rrq if the rrq is 8905 * still active for the xri. If this function returns a failure then 8906 * the caller needs to clean up the RRQ by calling lpfc_clr_active_rrq. 8907 * 8908 * Returns 0 Success. 8909 * 1 Failure. 8910 **/ 8911 int 8912 lpfc_send_rrq(struct lpfc_hba *phba, struct lpfc_node_rrq *rrq) 8913 { 8914 struct lpfc_nodelist *ndlp = lpfc_findnode_did(rrq->vport, 8915 rrq->nlp_DID); 8916 if (!ndlp) 8917 return 1; 8918 8919 if (lpfc_test_rrq_active(phba, ndlp, rrq->xritag)) 8920 return lpfc_issue_els_rrq(rrq->vport, ndlp, 8921 rrq->nlp_DID, rrq); 8922 else 8923 return 1; 8924 } 8925 8926 /** 8927 * lpfc_els_rsp_rpl_acc - Issue an accept rpl els command 8928 * @vport: pointer to a host virtual N_Port data structure. 8929 * @cmdsize: size of the ELS command. 8930 * @oldiocb: pointer to the original lpfc command iocb data structure. 8931 * @ndlp: pointer to a node-list data structure. 8932 * 8933 * This routine issuees an Accept (ACC) Read Port List (RPL) ELS command. 8934 * It is to be called by the lpfc_els_rcv_rpl() routine to accept the RPL. 8935 * 8936 * Note that the ndlp reference count will be incremented by 1 for holding the 8937 * ndlp and the reference to ndlp will be stored into the ndlp field of 8938 * the IOCB for the completion callback function to the RPL Accept Response 8939 * ELS command. 8940 * 8941 * Return code 8942 * 0 - Successfully issued ACC RPL ELS command 8943 * 1 - Failed to issue ACC RPL ELS command 8944 **/ 8945 static int 8946 lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize, 8947 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp) 8948 { 8949 int rc = 0; 8950 struct lpfc_hba *phba = vport->phba; 8951 IOCB_t *icmd; 8952 union lpfc_wqe128 *wqe; 8953 RPL_RSP rpl_rsp; 8954 struct lpfc_iocbq *elsiocb; 8955 uint8_t *pcmd; 8956 u32 ulp_context; 8957 8958 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, 8959 ndlp->nlp_DID, ELS_CMD_ACC); 8960 8961 if (!elsiocb) 8962 return 1; 8963 8964 ulp_context = get_job_ulpcontext(phba, elsiocb); 8965 if (phba->sli_rev == LPFC_SLI_REV4) { 8966 wqe = &elsiocb->wqe; 8967 /* Xri / rx_id */ 8968 bf_set(wqe_ctxt_tag, &wqe->generic.wqe_com, 8969 get_job_ulpcontext(phba, oldiocb)); 8970 bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com, 8971 get_job_rcvoxid(phba, oldiocb)); 8972 } else { 8973 icmd = &elsiocb->iocb; 8974 icmd->ulpContext = get_job_ulpcontext(phba, oldiocb); 8975 icmd->unsli3.rcvsli3.ox_id = get_job_rcvoxid(phba, oldiocb); 8976 } 8977 8978 pcmd = elsiocb->cmd_dmabuf->virt; 8979 *((uint32_t *) (pcmd)) = ELS_CMD_ACC; 8980 pcmd += sizeof(uint16_t); 8981 *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize); 8982 pcmd += sizeof(uint16_t); 8983 8984 /* Setup the RPL ACC payload */ 8985 rpl_rsp.listLen = be32_to_cpu(1); 8986 rpl_rsp.index = 0; 8987 rpl_rsp.port_num_blk.portNum = 0; 8988 rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID); 8989 memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname, 8990 sizeof(struct lpfc_name)); 8991 memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t)); 8992 /* Xmit ELS RPL ACC response tag <ulpIoTag> */ 8993 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, 8994 "0120 Xmit ELS RPL ACC response tag x%x " 8995 "xri x%x, did x%x, nlp_flag x%lx, nlp_state x%x, " 8996 "rpi x%x\n", 8997 elsiocb->iotag, ulp_context, 8998 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, 8999 ndlp->nlp_rpi); 9000 elsiocb->cmd_cmpl = lpfc_cmpl_els_rsp; 9001 phba->fc_stat.elsXmitACC++; 9002 elsiocb->ndlp = lpfc_nlp_get(ndlp); 9003 if (!elsiocb->ndlp) { 9004 lpfc_els_free_iocb(phba, elsiocb); 9005 return 1; 9006 } 9007 9008 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); 9009 if (rc == IOCB_ERROR) { 9010 lpfc_els_free_iocb(phba, elsiocb); 9011 lpfc_nlp_put(ndlp); 9012 return 1; 9013 } 9014 9015 return 0; 9016 } 9017 9018 /** 9019 * lpfc_els_rcv_rpl - Process an unsolicited rpl iocb 9020 * @vport: pointer to a host virtual N_Port data structure. 9021 * @cmdiocb: pointer to lpfc command iocb data structure. 9022 * @ndlp: pointer to a node-list data structure. 9023 * 9024 * This routine processes Read Port List (RPL) IOCB received as an ELS 9025 * unsolicited event. It first checks the remote port state. If the remote 9026 * port is not in NLP_STE_UNMAPPED_NODE and NLP_STE_MAPPED_NODE states, it 9027 * invokes the lpfc_els_rsp_reject() routine to send reject response. 9028 * Otherwise, this routine then invokes the lpfc_els_rsp_rpl_acc() routine 9029 * to accept the RPL. 9030 * 9031 * Return code 9032 * 0 - Successfully processed rpl iocb (currently always return 0) 9033 **/ 9034 static int 9035 lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, 9036 struct lpfc_nodelist *ndlp) 9037 { 9038 struct lpfc_dmabuf *pcmd; 9039 uint32_t *lp; 9040 uint32_t maxsize; 9041 uint16_t cmdsize; 9042 RPL *rpl; 9043 struct ls_rjt stat; 9044 9045 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && 9046 (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) { 9047 /* issue rejection response */ 9048 stat.un.b.lsRjtRsvd0 = 0; 9049 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; 9050 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; 9051 stat.un.b.vendorUnique = 0; 9052 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, 9053 NULL); 9054 /* rejected the unsolicited RPL request and done with it */ 9055 return 0; 9056 } 9057 9058 pcmd = cmdiocb->cmd_dmabuf; 9059 lp = (uint32_t *) pcmd->virt; 9060 rpl = (RPL *) (lp + 1); 9061 maxsize = be32_to_cpu(rpl->maxsize); 9062 9063 /* We support only one port */ 9064 if ((rpl->index == 0) && 9065 ((maxsize == 0) || 9066 ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) { 9067 cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP); 9068 } else { 9069 cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t); 9070 } 9071 lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp); 9072 9073 return 0; 9074 } 9075 9076 /** 9077 * lpfc_els_rcv_farp - Process an unsolicited farp request els command 9078 * @vport: pointer to a virtual N_Port data structure. 9079 * @cmdiocb: pointer to lpfc command iocb data structure. 9080 * @ndlp: pointer to a node-list data structure. 9081 * 9082 * This routine processes Fibre Channel Address Resolution Protocol 9083 * (FARP) Request IOCB received as an ELS unsolicited event. Currently, 9084 * the lpfc driver only supports matching on WWPN or WWNN for FARP. As such, 9085 * FARP_MATCH_PORT flag and FARP_MATCH_NODE flag are checked against the 9086 * Match Flag in the FARP request IOCB: if FARP_MATCH_PORT flag is set, the 9087 * remote PortName is compared against the FC PortName stored in the @vport 9088 * data structure; if FARP_MATCH_NODE flag is set, the remote NodeName is 9089 * compared against the FC NodeName stored in the @vport data structure. 9090 * If any of these matches and the FARP_REQUEST_FARPR flag is set in the 9091 * FARP request IOCB Response Flag, the lpfc_issue_els_farpr() routine is 9092 * invoked to send out FARP Response to the remote node. Before sending the 9093 * FARP Response, however, the FARP_REQUEST_PLOGI flag is check in the FARP 9094 * request IOCB Response Flag and, if it is set, the lpfc_issue_els_plogi() 9095 * routine is invoked to log into the remote port first. 9096 * 9097 * Return code 9098 * 0 - Either the FARP Match Mode not supported or successfully processed 9099 **/ 9100 static int 9101 lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, 9102 struct lpfc_nodelist *ndlp) 9103 { 9104 struct lpfc_dmabuf *pcmd; 9105 uint32_t *lp; 9106 FARP *fp; 9107 uint32_t cnt, did; 9108 9109 did = get_job_els_rsp64_did(vport->phba, cmdiocb); 9110 pcmd = cmdiocb->cmd_dmabuf; 9111 lp = (uint32_t *) pcmd->virt; 9112 9113 lp++; 9114 fp = (FARP *) lp; 9115 /* FARP-REQ received from DID <did> */ 9116 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, 9117 "0601 FARP-REQ received from DID x%x\n", did); 9118 /* We will only support match on WWPN or WWNN */ 9119 if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) { 9120 return 0; 9121 } 9122 9123 cnt = 0; 9124 /* If this FARP command is searching for my portname */ 9125 if (fp->Mflags & FARP_MATCH_PORT) { 9126 if (memcmp(&fp->RportName, &vport->fc_portname, 9127 sizeof(struct lpfc_name)) == 0) 9128 cnt = 1; 9129 } 9130 9131 /* If this FARP command is searching for my nodename */ 9132 if (fp->Mflags & FARP_MATCH_NODE) { 9133 if (memcmp(&fp->RnodeName, &vport->fc_nodename, 9134 sizeof(struct lpfc_name)) == 0) 9135 cnt = 1; 9136 } 9137 9138 if (cnt) { 9139 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) || 9140 (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) { 9141 /* Log back into the node before sending the FARP. */ 9142 if (fp->Rflags & FARP_REQUEST_PLOGI) { 9143 ndlp->nlp_prev_state = ndlp->nlp_state; 9144 lpfc_nlp_set_state(vport, ndlp, 9145 NLP_STE_PLOGI_ISSUE); 9146 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0); 9147 } 9148 9149 /* Send a FARP response to that node */ 9150 if (fp->Rflags & FARP_REQUEST_FARPR) 9151 lpfc_issue_els_farpr(vport, did, 0); 9152 } 9153 } 9154 return 0; 9155 } 9156 9157 /** 9158 * lpfc_els_rcv_farpr - Process an unsolicited farp response iocb 9159 * @vport: pointer to a host virtual N_Port data structure. 9160 * @cmdiocb: pointer to lpfc command iocb data structure. 9161 * @ndlp: pointer to a node-list data structure. 9162 * 9163 * This routine processes Fibre Channel Address Resolution Protocol 9164 * Response (FARPR) IOCB received as an ELS unsolicited event. It simply 9165 * invokes the lpfc_els_rsp_acc() routine to the remote node to accept 9166 * the FARP response request. 9167 * 9168 * Return code 9169 * 0 - Successfully processed FARPR IOCB (currently always return 0) 9170 **/ 9171 static int 9172 lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, 9173 struct lpfc_nodelist *ndlp) 9174 { 9175 uint32_t did; 9176 9177 did = get_job_els_rsp64_did(vport->phba, cmdiocb); 9178 9179 /* FARP-RSP received from DID <did> */ 9180 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, 9181 "0600 FARP-RSP received from DID x%x\n", did); 9182 /* ACCEPT the Farp resp request */ 9183 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); 9184 9185 return 0; 9186 } 9187 9188 /** 9189 * lpfc_els_rcv_fan - Process an unsolicited fan iocb command 9190 * @vport: pointer to a host virtual N_Port data structure. 9191 * @cmdiocb: pointer to lpfc command iocb data structure. 9192 * @fan_ndlp: pointer to a node-list data structure. 9193 * 9194 * This routine processes a Fabric Address Notification (FAN) IOCB 9195 * command received as an ELS unsolicited event. The FAN ELS command will 9196 * only be processed on a physical port (i.e., the @vport represents the 9197 * physical port). The fabric NodeName and PortName from the FAN IOCB are 9198 * compared against those in the phba data structure. If any of those is 9199 * different, the lpfc_initial_flogi() routine is invoked to initialize 9200 * Fabric Login (FLOGI) to the fabric to start the discover over. Otherwise, 9201 * if both of those are identical, the lpfc_issue_fabric_reglogin() routine 9202 * is invoked to register login to the fabric. 9203 * 9204 * Return code 9205 * 0 - Successfully processed fan iocb (currently always return 0). 9206 **/ 9207 static int 9208 lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, 9209 struct lpfc_nodelist *fan_ndlp) 9210 { 9211 struct lpfc_hba *phba = vport->phba; 9212 uint32_t *lp; 9213 FAN *fp; 9214 9215 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, "0265 FAN received\n"); 9216 lp = (uint32_t *)cmdiocb->cmd_dmabuf->virt; 9217 fp = (FAN *) ++lp; 9218 /* FAN received; Fan does not have a reply sequence */ 9219 if ((vport == phba->pport) && 9220 (vport->port_state == LPFC_LOCAL_CFG_LINK)) { 9221 if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName, 9222 sizeof(struct lpfc_name))) || 9223 (memcmp(&phba->fc_fabparam.portName, &fp->FportName, 9224 sizeof(struct lpfc_name)))) { 9225 /* This port has switched fabrics. FLOGI is required */ 9226 lpfc_issue_init_vfi(vport); 9227 } else { 9228 /* FAN verified - skip FLOGI */ 9229 vport->fc_myDID = vport->fc_prevDID; 9230 if (phba->sli_rev < LPFC_SLI_REV4) 9231 lpfc_issue_fabric_reglogin(vport); 9232 else { 9233 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, 9234 "3138 Need register VFI: (x%x/%x)\n", 9235 vport->fc_prevDID, vport->fc_myDID); 9236 lpfc_issue_reg_vfi(vport); 9237 } 9238 } 9239 } 9240 return 0; 9241 } 9242 9243 /** 9244 * lpfc_els_rcv_edc - Process an unsolicited EDC iocb 9245 * @vport: pointer to a host virtual N_Port data structure. 9246 * @cmdiocb: pointer to lpfc command iocb data structure. 9247 * @ndlp: pointer to a node-list data structure. 9248 * 9249 * Return code 9250 * 0 - Successfully processed echo iocb (currently always return 0) 9251 **/ 9252 static int 9253 lpfc_els_rcv_edc(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, 9254 struct lpfc_nodelist *ndlp) 9255 { 9256 struct lpfc_hba *phba = vport->phba; 9257 struct fc_els_edc *edc_req; 9258 struct fc_tlv_desc *tlv; 9259 uint8_t *payload; 9260 uint32_t *ptr, dtag; 9261 const char *dtag_nm; 9262 int desc_cnt = 0, bytes_remain; 9263 struct fc_diag_lnkflt_desc *plnkflt; 9264 9265 payload = cmdiocb->cmd_dmabuf->virt; 9266 9267 edc_req = (struct fc_els_edc *)payload; 9268 bytes_remain = be32_to_cpu(edc_req->desc_len); 9269 9270 ptr = (uint32_t *)payload; 9271 lpfc_printf_vlog(vport, KERN_INFO, 9272 LOG_ELS | LOG_CGN_MGMT | LOG_LDS_EVENT, 9273 "3319 Rcv EDC payload len %d: x%x x%x x%x\n", 9274 bytes_remain, be32_to_cpu(*ptr), 9275 be32_to_cpu(*(ptr + 1)), be32_to_cpu(*(ptr + 2))); 9276 9277 /* No signal support unless there is a congestion descriptor */ 9278 phba->cgn_reg_signal = EDC_CG_SIG_NOTSUPPORTED; 9279 phba->cgn_sig_freq = 0; 9280 phba->cgn_reg_fpin = LPFC_CGN_FPIN_ALARM | LPFC_CGN_FPIN_WARN; 9281 9282 if (bytes_remain <= 0) 9283 goto out; 9284 9285 tlv = edc_req->desc; 9286 9287 /* 9288 * cycle through EDC diagnostic descriptors to find the 9289 * congestion signaling capability descriptor 9290 */ 9291 while (bytes_remain) { 9292 if (bytes_remain < FC_TLV_DESC_HDR_SZ) { 9293 lpfc_printf_log(phba, KERN_WARNING, 9294 LOG_ELS | LOG_CGN_MGMT | LOG_LDS_EVENT, 9295 "6464 Truncated TLV hdr on " 9296 "Diagnostic descriptor[%d]\n", 9297 desc_cnt); 9298 goto out; 9299 } 9300 9301 dtag = be32_to_cpu(tlv->desc_tag); 9302 switch (dtag) { 9303 case ELS_DTAG_LNK_FAULT_CAP: 9304 if (bytes_remain < FC_TLV_DESC_SZ_FROM_LENGTH(tlv) || 9305 FC_TLV_DESC_SZ_FROM_LENGTH(tlv) != 9306 sizeof(struct fc_diag_lnkflt_desc)) { 9307 lpfc_printf_log(phba, KERN_WARNING, 9308 LOG_ELS | LOG_CGN_MGMT | LOG_LDS_EVENT, 9309 "6465 Truncated Link Fault Diagnostic " 9310 "descriptor[%d]: %d vs 0x%zx 0x%zx\n", 9311 desc_cnt, bytes_remain, 9312 FC_TLV_DESC_SZ_FROM_LENGTH(tlv), 9313 sizeof(struct fc_diag_lnkflt_desc)); 9314 goto out; 9315 } 9316 plnkflt = (struct fc_diag_lnkflt_desc *)tlv; 9317 lpfc_printf_log(phba, KERN_INFO, 9318 LOG_ELS | LOG_LDS_EVENT, 9319 "4626 Link Fault Desc Data: x%08x len x%x " 9320 "da x%x dd x%x interval x%x\n", 9321 be32_to_cpu(plnkflt->desc_tag), 9322 be32_to_cpu(plnkflt->desc_len), 9323 be32_to_cpu( 9324 plnkflt->degrade_activate_threshold), 9325 be32_to_cpu( 9326 plnkflt->degrade_deactivate_threshold), 9327 be32_to_cpu(plnkflt->fec_degrade_interval)); 9328 break; 9329 case ELS_DTAG_CG_SIGNAL_CAP: 9330 if (bytes_remain < FC_TLV_DESC_SZ_FROM_LENGTH(tlv) || 9331 FC_TLV_DESC_SZ_FROM_LENGTH(tlv) != 9332 sizeof(struct fc_diag_cg_sig_desc)) { 9333 lpfc_printf_log( 9334 phba, KERN_WARNING, LOG_CGN_MGMT, 9335 "6466 Truncated cgn signal Diagnostic " 9336 "descriptor[%d]: %d vs 0x%zx 0x%zx\n", 9337 desc_cnt, bytes_remain, 9338 FC_TLV_DESC_SZ_FROM_LENGTH(tlv), 9339 sizeof(struct fc_diag_cg_sig_desc)); 9340 goto out; 9341 } 9342 9343 phba->cgn_reg_fpin = phba->cgn_init_reg_fpin; 9344 phba->cgn_reg_signal = phba->cgn_init_reg_signal; 9345 9346 /* We start negotiation with lpfc_fabric_cgn_frequency. 9347 * When we process the EDC, we will settle on the 9348 * higher frequency. 9349 */ 9350 phba->cgn_sig_freq = lpfc_fabric_cgn_frequency; 9351 9352 lpfc_least_capable_settings( 9353 phba, (struct fc_diag_cg_sig_desc *)tlv); 9354 break; 9355 default: 9356 dtag_nm = lpfc_get_tlv_dtag_nm(dtag); 9357 lpfc_printf_log(phba, KERN_WARNING, 9358 LOG_ELS | LOG_CGN_MGMT | LOG_LDS_EVENT, 9359 "6467 unknown Diagnostic " 9360 "Descriptor[%d]: tag x%x (%s)\n", 9361 desc_cnt, dtag, dtag_nm); 9362 } 9363 bytes_remain -= FC_TLV_DESC_SZ_FROM_LENGTH(tlv); 9364 tlv = fc_tlv_next_desc(tlv); 9365 desc_cnt++; 9366 } 9367 out: 9368 /* Need to send back an ACC */ 9369 lpfc_issue_els_edc_rsp(vport, cmdiocb, ndlp); 9370 9371 lpfc_config_cgn_signal(phba); 9372 return 0; 9373 } 9374 9375 /** 9376 * lpfc_els_timeout - Handler funciton to the els timer 9377 * @t: timer context used to obtain the vport. 9378 * 9379 * This routine is invoked by the ELS timer after timeout. It posts the ELS 9380 * timer timeout event by setting the WORKER_ELS_TMO bit to the work port 9381 * event bitmap and then invokes the lpfc_worker_wake_up() routine to wake 9382 * up the worker thread. It is for the worker thread to invoke the routine 9383 * lpfc_els_timeout_handler() to work on the posted event WORKER_ELS_TMO. 9384 **/ 9385 void 9386 lpfc_els_timeout(struct timer_list *t) 9387 { 9388 struct lpfc_vport *vport = from_timer(vport, t, els_tmofunc); 9389 struct lpfc_hba *phba = vport->phba; 9390 uint32_t tmo_posted; 9391 unsigned long iflag; 9392 9393 spin_lock_irqsave(&vport->work_port_lock, iflag); 9394 tmo_posted = vport->work_port_events & WORKER_ELS_TMO; 9395 if (!tmo_posted && !test_bit(FC_UNLOADING, &vport->load_flag)) 9396 vport->work_port_events |= WORKER_ELS_TMO; 9397 spin_unlock_irqrestore(&vport->work_port_lock, iflag); 9398 9399 if (!tmo_posted && !test_bit(FC_UNLOADING, &vport->load_flag)) 9400 lpfc_worker_wake_up(phba); 9401 return; 9402 } 9403 9404 9405 /** 9406 * lpfc_els_timeout_handler - Process an els timeout event 9407 * @vport: pointer to a virtual N_Port data structure. 9408 * 9409 * This routine is the actual handler function that processes an ELS timeout 9410 * event. It walks the ELS ring to get and abort all the IOCBs (except the 9411 * ABORT/CLOSE/FARP/FARPR/FDISC), which are associated with the @vport by 9412 * invoking the lpfc_sli_issue_abort_iotag() routine. 9413 **/ 9414 void 9415 lpfc_els_timeout_handler(struct lpfc_vport *vport) 9416 { 9417 struct lpfc_hba *phba = vport->phba; 9418 struct lpfc_sli_ring *pring; 9419 struct lpfc_iocbq *tmp_iocb, *piocb; 9420 IOCB_t *cmd = NULL; 9421 struct lpfc_dmabuf *pcmd; 9422 uint32_t els_command = 0; 9423 uint32_t timeout; 9424 uint32_t remote_ID = 0xffffffff; 9425 LIST_HEAD(abort_list); 9426 u32 ulp_command = 0, ulp_context = 0, did = 0, iotag = 0; 9427 9428 9429 timeout = (uint32_t)(phba->fc_ratov << 1); 9430 9431 pring = lpfc_phba_elsring(phba); 9432 if (unlikely(!pring)) 9433 return; 9434 9435 if (test_bit(FC_UNLOADING, &phba->pport->load_flag)) 9436 return; 9437 9438 spin_lock_irq(&phba->hbalock); 9439 if (phba->sli_rev == LPFC_SLI_REV4) 9440 spin_lock(&pring->ring_lock); 9441 9442 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) { 9443 ulp_command = get_job_cmnd(phba, piocb); 9444 ulp_context = get_job_ulpcontext(phba, piocb); 9445 did = get_job_els_rsp64_did(phba, piocb); 9446 9447 if (phba->sli_rev == LPFC_SLI_REV4) { 9448 iotag = get_wqe_reqtag(piocb); 9449 } else { 9450 cmd = &piocb->iocb; 9451 iotag = cmd->ulpIoTag; 9452 } 9453 9454 if ((piocb->cmd_flag & LPFC_IO_LIBDFC) != 0 || 9455 ulp_command == CMD_ABORT_XRI_CX || 9456 ulp_command == CMD_ABORT_XRI_CN || 9457 ulp_command == CMD_CLOSE_XRI_CN) 9458 continue; 9459 9460 if (piocb->vport != vport) 9461 continue; 9462 9463 pcmd = piocb->cmd_dmabuf; 9464 if (pcmd) 9465 els_command = *(uint32_t *) (pcmd->virt); 9466 9467 if (els_command == ELS_CMD_FARP || 9468 els_command == ELS_CMD_FARPR || 9469 els_command == ELS_CMD_FDISC) 9470 continue; 9471 9472 if (piocb->drvrTimeout > 0) { 9473 if (piocb->drvrTimeout >= timeout) 9474 piocb->drvrTimeout -= timeout; 9475 else 9476 piocb->drvrTimeout = 0; 9477 continue; 9478 } 9479 9480 remote_ID = 0xffffffff; 9481 if (ulp_command != CMD_GEN_REQUEST64_CR) { 9482 remote_ID = did; 9483 } else { 9484 struct lpfc_nodelist *ndlp; 9485 ndlp = __lpfc_findnode_rpi(vport, ulp_context); 9486 if (ndlp) 9487 remote_ID = ndlp->nlp_DID; 9488 } 9489 list_add_tail(&piocb->dlist, &abort_list); 9490 } 9491 if (phba->sli_rev == LPFC_SLI_REV4) 9492 spin_unlock(&pring->ring_lock); 9493 spin_unlock_irq(&phba->hbalock); 9494 9495 list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) { 9496 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, 9497 "0127 ELS timeout Data: x%x x%x x%x " 9498 "x%x\n", els_command, 9499 remote_ID, ulp_command, iotag); 9500 9501 spin_lock_irq(&phba->hbalock); 9502 list_del_init(&piocb->dlist); 9503 lpfc_sli_issue_abort_iotag(phba, pring, piocb, NULL); 9504 spin_unlock_irq(&phba->hbalock); 9505 } 9506 9507 /* Make sure HBA is alive */ 9508 lpfc_issue_hb_tmo(phba); 9509 9510 if (!list_empty(&pring->txcmplq)) 9511 if (!test_bit(FC_UNLOADING, &phba->pport->load_flag)) 9512 mod_timer(&vport->els_tmofunc, 9513 jiffies + secs_to_jiffies(timeout)); 9514 } 9515 9516 /** 9517 * lpfc_els_flush_cmd - Clean up the outstanding els commands to a vport 9518 * @vport: pointer to a host virtual N_Port data structure. 9519 * 9520 * This routine is used to clean up all the outstanding ELS commands on a 9521 * @vport. It first aborts the @vport by invoking lpfc_fabric_abort_vport() 9522 * routine. After that, it walks the ELS transmit queue to remove all the 9523 * IOCBs with the @vport other than the QUE_RING and ABORT/CLOSE IOCBs. For 9524 * the IOCBs with a non-NULL completion callback function, the callback 9525 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and 9526 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs with a NULL completion 9527 * callback function, the IOCB will simply be released. Finally, it walks 9528 * the ELS transmit completion queue to issue an abort IOCB to any transmit 9529 * completion queue IOCB that is associated with the @vport and is not 9530 * an IOCB from libdfc (i.e., the management plane IOCBs that are not 9531 * part of the discovery state machine) out to HBA by invoking the 9532 * lpfc_sli_issue_abort_iotag() routine. Note that this function issues the 9533 * abort IOCB to any transmit completion queueed IOCB, it does not guarantee 9534 * the IOCBs are aborted when this function returns. 9535 **/ 9536 void 9537 lpfc_els_flush_cmd(struct lpfc_vport *vport) 9538 { 9539 LIST_HEAD(abort_list); 9540 LIST_HEAD(cancel_list); 9541 struct lpfc_hba *phba = vport->phba; 9542 struct lpfc_sli_ring *pring; 9543 struct lpfc_iocbq *tmp_iocb, *piocb; 9544 u32 ulp_command; 9545 unsigned long iflags = 0; 9546 bool mbx_tmo_err; 9547 9548 lpfc_fabric_abort_vport(vport); 9549 9550 /* 9551 * For SLI3, only the hbalock is required. But SLI4 needs to coordinate 9552 * with the ring insert operation. Because lpfc_sli_issue_abort_iotag 9553 * ultimately grabs the ring_lock, the driver must splice the list into 9554 * a working list and release the locks before calling the abort. 9555 */ 9556 spin_lock_irqsave(&phba->hbalock, iflags); 9557 pring = lpfc_phba_elsring(phba); 9558 9559 /* Bail out if we've no ELS wq, like in PCI error recovery case. */ 9560 if (unlikely(!pring)) { 9561 spin_unlock_irqrestore(&phba->hbalock, iflags); 9562 return; 9563 } 9564 9565 if (phba->sli_rev == LPFC_SLI_REV4) 9566 spin_lock(&pring->ring_lock); 9567 9568 mbx_tmo_err = test_bit(MBX_TMO_ERR, &phba->bit_flags); 9569 /* First we need to issue aborts to outstanding cmds on txcmpl */ 9570 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) { 9571 if (piocb->vport != vport) 9572 continue; 9573 9574 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, 9575 "2243 iotag = 0x%x cmd_flag = 0x%x " 9576 "ulp_command = 0x%x sli_flag = 0x%x\n", 9577 piocb->iotag, piocb->cmd_flag, 9578 get_job_cmnd(phba, piocb), 9579 phba->sli.sli_flag); 9580 9581 if ((phba->sli.sli_flag & LPFC_SLI_ACTIVE) && !mbx_tmo_err) { 9582 if (piocb->cmd_flag & LPFC_IO_LIBDFC) 9583 continue; 9584 if (piocb->cmd_flag & LPFC_DRIVER_ABORTED) 9585 continue; 9586 } 9587 9588 /* On the ELS ring we can have ELS_REQUESTs, ELS_RSPs, 9589 * or GEN_REQUESTs waiting for a CQE response. 9590 */ 9591 ulp_command = get_job_cmnd(phba, piocb); 9592 if (ulp_command == CMD_ELS_REQUEST64_WQE || 9593 ulp_command == CMD_XMIT_ELS_RSP64_WQE) { 9594 list_add_tail(&piocb->dlist, &abort_list); 9595 9596 /* If the link is down when flushing ELS commands 9597 * the firmware will not complete them till after 9598 * the link comes back up. This may confuse 9599 * discovery for the new link up, so we need to 9600 * change the compl routine to just clean up the iocb 9601 * and avoid any retry logic. 9602 */ 9603 if (phba->link_state == LPFC_LINK_DOWN) 9604 piocb->cmd_cmpl = lpfc_cmpl_els_link_down; 9605 } else if (ulp_command == CMD_GEN_REQUEST64_CR || 9606 mbx_tmo_err) 9607 list_add_tail(&piocb->dlist, &abort_list); 9608 } 9609 9610 if (phba->sli_rev == LPFC_SLI_REV4) 9611 spin_unlock(&pring->ring_lock); 9612 spin_unlock_irqrestore(&phba->hbalock, iflags); 9613 9614 /* Abort each txcmpl iocb on aborted list and remove the dlist links. */ 9615 list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) { 9616 spin_lock_irqsave(&phba->hbalock, iflags); 9617 list_del_init(&piocb->dlist); 9618 if (mbx_tmo_err || !(phba->sli.sli_flag & LPFC_SLI_ACTIVE)) 9619 list_move_tail(&piocb->list, &cancel_list); 9620 else 9621 lpfc_sli_issue_abort_iotag(phba, pring, piocb, NULL); 9622 9623 spin_unlock_irqrestore(&phba->hbalock, iflags); 9624 } 9625 if (!list_empty(&cancel_list)) 9626 lpfc_sli_cancel_iocbs(phba, &cancel_list, IOSTAT_LOCAL_REJECT, 9627 IOERR_SLI_ABORTED); 9628 else 9629 /* Make sure HBA is alive */ 9630 lpfc_issue_hb_tmo(phba); 9631 9632 if (!list_empty(&abort_list)) 9633 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, 9634 "3387 abort list for txq not empty\n"); 9635 INIT_LIST_HEAD(&abort_list); 9636 9637 spin_lock_irqsave(&phba->hbalock, iflags); 9638 if (phba->sli_rev == LPFC_SLI_REV4) 9639 spin_lock(&pring->ring_lock); 9640 9641 /* No need to abort the txq list, 9642 * just queue them up for lpfc_sli_cancel_iocbs 9643 */ 9644 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) { 9645 ulp_command = get_job_cmnd(phba, piocb); 9646 9647 if (piocb->cmd_flag & LPFC_IO_LIBDFC) 9648 continue; 9649 9650 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */ 9651 if (ulp_command == CMD_QUE_RING_BUF_CN || 9652 ulp_command == CMD_QUE_RING_BUF64_CN || 9653 ulp_command == CMD_CLOSE_XRI_CN || 9654 ulp_command == CMD_ABORT_XRI_CN || 9655 ulp_command == CMD_ABORT_XRI_CX) 9656 continue; 9657 9658 if (piocb->vport != vport) 9659 continue; 9660 9661 list_del_init(&piocb->list); 9662 list_add_tail(&piocb->list, &abort_list); 9663 } 9664 9665 /* The same holds true for any FLOGI/FDISC on the fabric_iocb_list */ 9666 if (vport == phba->pport) { 9667 list_for_each_entry_safe(piocb, tmp_iocb, 9668 &phba->fabric_iocb_list, list) { 9669 list_del_init(&piocb->list); 9670 list_add_tail(&piocb->list, &abort_list); 9671 } 9672 } 9673 9674 if (phba->sli_rev == LPFC_SLI_REV4) 9675 spin_unlock(&pring->ring_lock); 9676 spin_unlock_irqrestore(&phba->hbalock, iflags); 9677 9678 /* Cancel all the IOCBs from the completions list */ 9679 lpfc_sli_cancel_iocbs(phba, &abort_list, 9680 IOSTAT_LOCAL_REJECT, IOERR_SLI_ABORTED); 9681 9682 return; 9683 } 9684 9685 /** 9686 * lpfc_els_flush_all_cmd - Clean up all the outstanding els commands to a HBA 9687 * @phba: pointer to lpfc hba data structure. 9688 * 9689 * This routine is used to clean up all the outstanding ELS commands on a 9690 * @phba. It first aborts the @phba by invoking the lpfc_fabric_abort_hba() 9691 * routine. After that, it walks the ELS transmit queue to remove all the 9692 * IOCBs to the @phba other than the QUE_RING and ABORT/CLOSE IOCBs. For 9693 * the IOCBs with the completion callback function associated, the callback 9694 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and 9695 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs without the completion 9696 * callback function associated, the IOCB will simply be released. Finally, 9697 * it walks the ELS transmit completion queue to issue an abort IOCB to any 9698 * transmit completion queue IOCB that is not an IOCB from libdfc (i.e., the 9699 * management plane IOCBs that are not part of the discovery state machine) 9700 * out to HBA by invoking the lpfc_sli_issue_abort_iotag() routine. 9701 **/ 9702 void 9703 lpfc_els_flush_all_cmd(struct lpfc_hba *phba) 9704 { 9705 struct lpfc_vport *vport; 9706 9707 spin_lock_irq(&phba->port_list_lock); 9708 list_for_each_entry(vport, &phba->port_list, listentry) 9709 lpfc_els_flush_cmd(vport); 9710 spin_unlock_irq(&phba->port_list_lock); 9711 9712 return; 9713 } 9714 9715 /** 9716 * lpfc_send_els_failure_event - Posts an ELS command failure event 9717 * @phba: Pointer to hba context object. 9718 * @cmdiocbp: Pointer to command iocb which reported error. 9719 * @rspiocbp: Pointer to response iocb which reported error. 9720 * 9721 * This function sends an event when there is an ELS command 9722 * failure. 9723 **/ 9724 void 9725 lpfc_send_els_failure_event(struct lpfc_hba *phba, 9726 struct lpfc_iocbq *cmdiocbp, 9727 struct lpfc_iocbq *rspiocbp) 9728 { 9729 struct lpfc_vport *vport = cmdiocbp->vport; 9730 struct Scsi_Host *shost = lpfc_shost_from_vport(vport); 9731 struct lpfc_lsrjt_event lsrjt_event; 9732 struct lpfc_fabric_event_header fabric_event; 9733 struct ls_rjt stat; 9734 struct lpfc_nodelist *ndlp; 9735 uint32_t *pcmd; 9736 u32 ulp_status, ulp_word4; 9737 9738 ndlp = cmdiocbp->ndlp; 9739 if (!ndlp) 9740 return; 9741 9742 ulp_status = get_job_ulpstatus(phba, rspiocbp); 9743 ulp_word4 = get_job_word4(phba, rspiocbp); 9744 9745 if (ulp_status == IOSTAT_LS_RJT) { 9746 lsrjt_event.header.event_type = FC_REG_ELS_EVENT; 9747 lsrjt_event.header.subcategory = LPFC_EVENT_LSRJT_RCV; 9748 memcpy(lsrjt_event.header.wwpn, &ndlp->nlp_portname, 9749 sizeof(struct lpfc_name)); 9750 memcpy(lsrjt_event.header.wwnn, &ndlp->nlp_nodename, 9751 sizeof(struct lpfc_name)); 9752 pcmd = (uint32_t *)cmdiocbp->cmd_dmabuf->virt; 9753 lsrjt_event.command = (pcmd != NULL) ? *pcmd : 0; 9754 stat.un.ls_rjt_error_be = cpu_to_be32(ulp_word4); 9755 lsrjt_event.reason_code = stat.un.b.lsRjtRsnCode; 9756 lsrjt_event.explanation = stat.un.b.lsRjtRsnCodeExp; 9757 fc_host_post_vendor_event(shost, 9758 fc_get_event_number(), 9759 sizeof(lsrjt_event), 9760 (char *)&lsrjt_event, 9761 LPFC_NL_VENDOR_ID); 9762 return; 9763 } 9764 if (ulp_status == IOSTAT_NPORT_BSY || 9765 ulp_status == IOSTAT_FABRIC_BSY) { 9766 fabric_event.event_type = FC_REG_FABRIC_EVENT; 9767 if (ulp_status == IOSTAT_NPORT_BSY) 9768 fabric_event.subcategory = LPFC_EVENT_PORT_BUSY; 9769 else 9770 fabric_event.subcategory = LPFC_EVENT_FABRIC_BUSY; 9771 memcpy(fabric_event.wwpn, &ndlp->nlp_portname, 9772 sizeof(struct lpfc_name)); 9773 memcpy(fabric_event.wwnn, &ndlp->nlp_nodename, 9774 sizeof(struct lpfc_name)); 9775 fc_host_post_vendor_event(shost, 9776 fc_get_event_number(), 9777 sizeof(fabric_event), 9778 (char *)&fabric_event, 9779 LPFC_NL_VENDOR_ID); 9780 return; 9781 } 9782 9783 } 9784 9785 /** 9786 * lpfc_send_els_event - Posts unsolicited els event 9787 * @vport: Pointer to vport object. 9788 * @ndlp: Pointer FC node object. 9789 * @payload: ELS command code type. 9790 * 9791 * This function posts an event when there is an incoming 9792 * unsolicited ELS command. 9793 **/ 9794 static void 9795 lpfc_send_els_event(struct lpfc_vport *vport, 9796 struct lpfc_nodelist *ndlp, 9797 uint32_t *payload) 9798 { 9799 struct lpfc_els_event_header *els_data = NULL; 9800 struct lpfc_logo_event *logo_data = NULL; 9801 struct Scsi_Host *shost = lpfc_shost_from_vport(vport); 9802 9803 if (*payload == ELS_CMD_LOGO) { 9804 logo_data = kmalloc(sizeof(struct lpfc_logo_event), GFP_KERNEL); 9805 if (!logo_data) { 9806 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, 9807 "0148 Failed to allocate memory " 9808 "for LOGO event\n"); 9809 return; 9810 } 9811 els_data = &logo_data->header; 9812 } else { 9813 els_data = kmalloc(sizeof(struct lpfc_els_event_header), 9814 GFP_KERNEL); 9815 if (!els_data) { 9816 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, 9817 "0149 Failed to allocate memory " 9818 "for ELS event\n"); 9819 return; 9820 } 9821 } 9822 els_data->event_type = FC_REG_ELS_EVENT; 9823 switch (*payload) { 9824 case ELS_CMD_PLOGI: 9825 els_data->subcategory = LPFC_EVENT_PLOGI_RCV; 9826 break; 9827 case ELS_CMD_PRLO: 9828 els_data->subcategory = LPFC_EVENT_PRLO_RCV; 9829 break; 9830 case ELS_CMD_ADISC: 9831 els_data->subcategory = LPFC_EVENT_ADISC_RCV; 9832 break; 9833 case ELS_CMD_LOGO: 9834 els_data->subcategory = LPFC_EVENT_LOGO_RCV; 9835 /* Copy the WWPN in the LOGO payload */ 9836 memcpy(logo_data->logo_wwpn, &payload[2], 9837 sizeof(struct lpfc_name)); 9838 break; 9839 default: 9840 kfree(els_data); 9841 return; 9842 } 9843 memcpy(els_data->wwpn, &ndlp->nlp_portname, sizeof(struct lpfc_name)); 9844 memcpy(els_data->wwnn, &ndlp->nlp_nodename, sizeof(struct lpfc_name)); 9845 if (*payload == ELS_CMD_LOGO) { 9846 fc_host_post_vendor_event(shost, 9847 fc_get_event_number(), 9848 sizeof(struct lpfc_logo_event), 9849 (char *)logo_data, 9850 LPFC_NL_VENDOR_ID); 9851 kfree(logo_data); 9852 } else { 9853 fc_host_post_vendor_event(shost, 9854 fc_get_event_number(), 9855 sizeof(struct lpfc_els_event_header), 9856 (char *)els_data, 9857 LPFC_NL_VENDOR_ID); 9858 kfree(els_data); 9859 } 9860 9861 return; 9862 } 9863 9864 9865 DECLARE_ENUM2STR_LOOKUP(lpfc_get_fpin_li_event_nm, fc_fpin_li_event_types, 9866 FC_FPIN_LI_EVT_TYPES_INIT); 9867 9868 DECLARE_ENUM2STR_LOOKUP(lpfc_get_fpin_deli_event_nm, fc_fpin_deli_event_types, 9869 FC_FPIN_DELI_EVT_TYPES_INIT); 9870 9871 DECLARE_ENUM2STR_LOOKUP(lpfc_get_fpin_congn_event_nm, fc_fpin_congn_event_types, 9872 FC_FPIN_CONGN_EVT_TYPES_INIT); 9873 9874 DECLARE_ENUM2STR_LOOKUP(lpfc_get_fpin_congn_severity_nm, 9875 fc_fpin_congn_severity_types, 9876 FC_FPIN_CONGN_SEVERITY_INIT); 9877 9878 9879 /** 9880 * lpfc_display_fpin_wwpn - Display WWPNs accessible by the attached port 9881 * @phba: Pointer to phba object. 9882 * @wwnlist: Pointer to list of WWPNs in FPIN payload 9883 * @cnt: count of WWPNs in FPIN payload 9884 * 9885 * This routine is called by LI and PC descriptors. 9886 * Limit the number of WWPNs displayed to 6 log messages, 6 per log message 9887 */ 9888 static void 9889 lpfc_display_fpin_wwpn(struct lpfc_hba *phba, __be64 *wwnlist, u32 cnt) 9890 { 9891 char buf[LPFC_FPIN_WWPN_LINE_SZ]; 9892 __be64 wwn; 9893 u64 wwpn; 9894 int i, len; 9895 int line = 0; 9896 int wcnt = 0; 9897 bool endit = false; 9898 9899 len = scnprintf(buf, LPFC_FPIN_WWPN_LINE_SZ, "Accessible WWPNs:"); 9900 for (i = 0; i < cnt; i++) { 9901 /* Are we on the last WWPN */ 9902 if (i == (cnt - 1)) 9903 endit = true; 9904 9905 /* Extract the next WWPN from the payload */ 9906 wwn = *wwnlist++; 9907 wwpn = be64_to_cpu(wwn); 9908 len += scnprintf(buf + len, LPFC_FPIN_WWPN_LINE_SZ - len, 9909 " %016llx", wwpn); 9910 9911 /* Log a message if we are on the last WWPN 9912 * or if we hit the max allowed per message. 9913 */ 9914 wcnt++; 9915 if (wcnt == LPFC_FPIN_WWPN_LINE_CNT || endit) { 9916 buf[len] = 0; 9917 lpfc_printf_log(phba, KERN_INFO, LOG_ELS, 9918 "4686 %s\n", buf); 9919 9920 /* Check if we reached the last WWPN */ 9921 if (endit) 9922 return; 9923 9924 /* Limit the number of log message displayed per FPIN */ 9925 line++; 9926 if (line == LPFC_FPIN_WWPN_NUM_LINE) { 9927 lpfc_printf_log(phba, KERN_INFO, LOG_ELS, 9928 "4687 %d WWPNs Truncated\n", 9929 cnt - i - 1); 9930 return; 9931 } 9932 9933 /* Start over with next log message */ 9934 wcnt = 0; 9935 len = scnprintf(buf, LPFC_FPIN_WWPN_LINE_SZ, 9936 "Additional WWPNs:"); 9937 } 9938 } 9939 } 9940 9941 /** 9942 * lpfc_els_rcv_fpin_li - Process an FPIN Link Integrity Event. 9943 * @phba: Pointer to phba object. 9944 * @tlv: Pointer to the Link Integrity Notification Descriptor. 9945 * 9946 * This function processes a Link Integrity FPIN event by logging a message. 9947 **/ 9948 static void 9949 lpfc_els_rcv_fpin_li(struct lpfc_hba *phba, struct fc_tlv_desc *tlv) 9950 { 9951 struct fc_fn_li_desc *li = (struct fc_fn_li_desc *)tlv; 9952 const char *li_evt_str; 9953 u32 li_evt, cnt; 9954 9955 li_evt = be16_to_cpu(li->event_type); 9956 li_evt_str = lpfc_get_fpin_li_event_nm(li_evt); 9957 cnt = be32_to_cpu(li->pname_count); 9958 9959 lpfc_printf_log(phba, KERN_INFO, LOG_ELS, 9960 "4680 FPIN Link Integrity %s (x%x) " 9961 "Detecting PN x%016llx Attached PN x%016llx " 9962 "Duration %d mSecs Count %d Port Cnt %d\n", 9963 li_evt_str, li_evt, 9964 be64_to_cpu(li->detecting_wwpn), 9965 be64_to_cpu(li->attached_wwpn), 9966 be32_to_cpu(li->event_threshold), 9967 be32_to_cpu(li->event_count), cnt); 9968 9969 lpfc_display_fpin_wwpn(phba, (__be64 *)&li->pname_list, cnt); 9970 } 9971 9972 /** 9973 * lpfc_els_rcv_fpin_del - Process an FPIN Delivery Event. 9974 * @phba: Pointer to hba object. 9975 * @tlv: Pointer to the Delivery Notification Descriptor TLV 9976 * 9977 * This function processes a Delivery FPIN event by logging a message. 9978 **/ 9979 static void 9980 lpfc_els_rcv_fpin_del(struct lpfc_hba *phba, struct fc_tlv_desc *tlv) 9981 { 9982 struct fc_fn_deli_desc *del = (struct fc_fn_deli_desc *)tlv; 9983 const char *del_rsn_str; 9984 u32 del_rsn; 9985 __be32 *frame; 9986 9987 del_rsn = be16_to_cpu(del->deli_reason_code); 9988 del_rsn_str = lpfc_get_fpin_deli_event_nm(del_rsn); 9989 9990 /* Skip over desc_tag/desc_len header to payload */ 9991 frame = (__be32 *)(del + 1); 9992 9993 lpfc_printf_log(phba, KERN_INFO, LOG_ELS, 9994 "4681 FPIN Delivery %s (x%x) " 9995 "Detecting PN x%016llx Attached PN x%016llx " 9996 "DiscHdr0 x%08x " 9997 "DiscHdr1 x%08x DiscHdr2 x%08x DiscHdr3 x%08x " 9998 "DiscHdr4 x%08x DiscHdr5 x%08x\n", 9999 del_rsn_str, del_rsn, 10000 be64_to_cpu(del->detecting_wwpn), 10001 be64_to_cpu(del->attached_wwpn), 10002 be32_to_cpu(frame[0]), 10003 be32_to_cpu(frame[1]), 10004 be32_to_cpu(frame[2]), 10005 be32_to_cpu(frame[3]), 10006 be32_to_cpu(frame[4]), 10007 be32_to_cpu(frame[5])); 10008 } 10009 10010 /** 10011 * lpfc_els_rcv_fpin_peer_cgn - Process a FPIN Peer Congestion Event. 10012 * @phba: Pointer to hba object. 10013 * @tlv: Pointer to the Peer Congestion Notification Descriptor TLV 10014 * 10015 * This function processes a Peer Congestion FPIN event by logging a message. 10016 **/ 10017 static void 10018 lpfc_els_rcv_fpin_peer_cgn(struct lpfc_hba *phba, struct fc_tlv_desc *tlv) 10019 { 10020 struct fc_fn_peer_congn_desc *pc = (struct fc_fn_peer_congn_desc *)tlv; 10021 const char *pc_evt_str; 10022 u32 pc_evt, cnt; 10023 10024 pc_evt = be16_to_cpu(pc->event_type); 10025 pc_evt_str = lpfc_get_fpin_congn_event_nm(pc_evt); 10026 cnt = be32_to_cpu(pc->pname_count); 10027 10028 /* Capture FPIN frequency */ 10029 phba->cgn_fpin_frequency = be32_to_cpu(pc->event_period); 10030 10031 lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT | LOG_ELS, 10032 "4684 FPIN Peer Congestion %s (x%x) " 10033 "Duration %d mSecs " 10034 "Detecting PN x%016llx Attached PN x%016llx " 10035 "Impacted Port Cnt %d\n", 10036 pc_evt_str, pc_evt, 10037 be32_to_cpu(pc->event_period), 10038 be64_to_cpu(pc->detecting_wwpn), 10039 be64_to_cpu(pc->attached_wwpn), 10040 cnt); 10041 10042 lpfc_display_fpin_wwpn(phba, (__be64 *)&pc->pname_list, cnt); 10043 } 10044 10045 /** 10046 * lpfc_els_rcv_fpin_cgn - Process an FPIN Congestion notification 10047 * @phba: Pointer to hba object. 10048 * @tlv: Pointer to the Congestion Notification Descriptor TLV 10049 * 10050 * This function processes an FPIN Congestion Notifiction. The notification 10051 * could be an Alarm or Warning. This routine feeds that data into driver's 10052 * running congestion algorithm. It also processes the FPIN by 10053 * logging a message. It returns 1 to indicate deliver this message 10054 * to the upper layer or 0 to indicate don't deliver it. 10055 **/ 10056 static int 10057 lpfc_els_rcv_fpin_cgn(struct lpfc_hba *phba, struct fc_tlv_desc *tlv) 10058 { 10059 struct lpfc_cgn_info *cp; 10060 struct fc_fn_congn_desc *cgn = (struct fc_fn_congn_desc *)tlv; 10061 const char *cgn_evt_str; 10062 u32 cgn_evt; 10063 const char *cgn_sev_str; 10064 u32 cgn_sev; 10065 uint16_t value; 10066 u32 crc; 10067 bool nm_log = false; 10068 int rc = 1; 10069 10070 cgn_evt = be16_to_cpu(cgn->event_type); 10071 cgn_evt_str = lpfc_get_fpin_congn_event_nm(cgn_evt); 10072 cgn_sev = cgn->severity; 10073 cgn_sev_str = lpfc_get_fpin_congn_severity_nm(cgn_sev); 10074 10075 /* The driver only takes action on a Credit Stall or Oversubscription 10076 * event type to engage the IO algorithm. The driver prints an 10077 * unmaskable message only for Lost Credit and Credit Stall. 10078 * TODO: Still need to have definition of host action on clear, 10079 * lost credit and device specific event types. 10080 */ 10081 switch (cgn_evt) { 10082 case FPIN_CONGN_LOST_CREDIT: 10083 nm_log = true; 10084 break; 10085 case FPIN_CONGN_CREDIT_STALL: 10086 nm_log = true; 10087 fallthrough; 10088 case FPIN_CONGN_OVERSUBSCRIPTION: 10089 if (cgn_evt == FPIN_CONGN_OVERSUBSCRIPTION) 10090 nm_log = false; 10091 switch (cgn_sev) { 10092 case FPIN_CONGN_SEVERITY_ERROR: 10093 /* Take action here for an Alarm event */ 10094 if (phba->cmf_active_mode != LPFC_CFG_OFF) { 10095 if (phba->cgn_reg_fpin & LPFC_CGN_FPIN_ALARM) { 10096 /* Track of alarm cnt for SYNC_WQE */ 10097 atomic_inc(&phba->cgn_sync_alarm_cnt); 10098 } 10099 /* Track alarm cnt for cgn_info regardless 10100 * of whether CMF is configured for Signals 10101 * or FPINs. 10102 */ 10103 atomic_inc(&phba->cgn_fabric_alarm_cnt); 10104 goto cleanup; 10105 } 10106 break; 10107 case FPIN_CONGN_SEVERITY_WARNING: 10108 /* Take action here for a Warning event */ 10109 if (phba->cmf_active_mode != LPFC_CFG_OFF) { 10110 if (phba->cgn_reg_fpin & LPFC_CGN_FPIN_WARN) { 10111 /* Track of warning cnt for SYNC_WQE */ 10112 atomic_inc(&phba->cgn_sync_warn_cnt); 10113 } 10114 /* Track warning cnt and freq for cgn_info 10115 * regardless of whether CMF is configured for 10116 * Signals or FPINs. 10117 */ 10118 atomic_inc(&phba->cgn_fabric_warn_cnt); 10119 cleanup: 10120 /* Save frequency in ms */ 10121 phba->cgn_fpin_frequency = 10122 be32_to_cpu(cgn->event_period); 10123 value = phba->cgn_fpin_frequency; 10124 if (phba->cgn_i) { 10125 cp = (struct lpfc_cgn_info *) 10126 phba->cgn_i->virt; 10127 cp->cgn_alarm_freq = 10128 cpu_to_le16(value); 10129 cp->cgn_warn_freq = 10130 cpu_to_le16(value); 10131 crc = lpfc_cgn_calc_crc32 10132 (cp, 10133 LPFC_CGN_INFO_SZ, 10134 LPFC_CGN_CRC32_SEED); 10135 cp->cgn_info_crc = cpu_to_le32(crc); 10136 } 10137 10138 /* Don't deliver to upper layer since 10139 * driver took action on this tlv. 10140 */ 10141 rc = 0; 10142 } 10143 break; 10144 } 10145 break; 10146 } 10147 10148 /* Change the log level to unmaskable for the following event types. */ 10149 lpfc_printf_log(phba, (nm_log ? KERN_WARNING : KERN_INFO), 10150 LOG_CGN_MGMT | LOG_ELS, 10151 "4683 FPIN CONGESTION %s type %s (x%x) Event " 10152 "Duration %d mSecs\n", 10153 cgn_sev_str, cgn_evt_str, cgn_evt, 10154 be32_to_cpu(cgn->event_period)); 10155 return rc; 10156 } 10157 10158 void 10159 lpfc_els_rcv_fpin(struct lpfc_vport *vport, void *p, u32 fpin_length) 10160 { 10161 struct lpfc_hba *phba = vport->phba; 10162 struct fc_els_fpin *fpin = (struct fc_els_fpin *)p; 10163 struct fc_tlv_desc *tlv, *first_tlv, *current_tlv; 10164 const char *dtag_nm; 10165 int desc_cnt = 0, bytes_remain, cnt; 10166 u32 dtag, deliver = 0; 10167 int len; 10168 10169 /* FPINs handled only if we are in the right discovery state */ 10170 if (vport->port_state < LPFC_DISC_AUTH) 10171 return; 10172 10173 /* make sure there is the full fpin header */ 10174 if (fpin_length < sizeof(struct fc_els_fpin)) 10175 return; 10176 10177 /* Sanity check descriptor length. The desc_len value does not 10178 * include space for the ELS command and the desc_len fields. 10179 */ 10180 len = be32_to_cpu(fpin->desc_len); 10181 if (fpin_length < len + sizeof(struct fc_els_fpin)) { 10182 lpfc_printf_log(phba, KERN_WARNING, LOG_CGN_MGMT, 10183 "4671 Bad ELS FPIN length %d: %d\n", 10184 len, fpin_length); 10185 return; 10186 } 10187 10188 tlv = (struct fc_tlv_desc *)&fpin->fpin_desc[0]; 10189 first_tlv = tlv; 10190 bytes_remain = fpin_length - offsetof(struct fc_els_fpin, fpin_desc); 10191 bytes_remain = min_t(u32, bytes_remain, be32_to_cpu(fpin->desc_len)); 10192 10193 /* process each descriptor separately */ 10194 while (bytes_remain >= FC_TLV_DESC_HDR_SZ && 10195 bytes_remain >= FC_TLV_DESC_SZ_FROM_LENGTH(tlv)) { 10196 dtag = be32_to_cpu(tlv->desc_tag); 10197 switch (dtag) { 10198 case ELS_DTAG_LNK_INTEGRITY: 10199 lpfc_els_rcv_fpin_li(phba, tlv); 10200 deliver = 1; 10201 break; 10202 case ELS_DTAG_DELIVERY: 10203 lpfc_els_rcv_fpin_del(phba, tlv); 10204 deliver = 1; 10205 break; 10206 case ELS_DTAG_PEER_CONGEST: 10207 lpfc_els_rcv_fpin_peer_cgn(phba, tlv); 10208 deliver = 1; 10209 break; 10210 case ELS_DTAG_CONGESTION: 10211 deliver = lpfc_els_rcv_fpin_cgn(phba, tlv); 10212 break; 10213 default: 10214 dtag_nm = lpfc_get_tlv_dtag_nm(dtag); 10215 lpfc_printf_log(phba, KERN_WARNING, LOG_CGN_MGMT, 10216 "4678 unknown FPIN descriptor[%d]: " 10217 "tag x%x (%s)\n", 10218 desc_cnt, dtag, dtag_nm); 10219 10220 /* If descriptor is bad, drop the rest of the data */ 10221 return; 10222 } 10223 lpfc_cgn_update_stat(phba, dtag); 10224 cnt = be32_to_cpu(tlv->desc_len); 10225 10226 /* Sanity check descriptor length. The desc_len value does not 10227 * include space for the desc_tag and the desc_len fields. 10228 */ 10229 len -= (cnt + sizeof(struct fc_tlv_desc)); 10230 if (len < 0) { 10231 dtag_nm = lpfc_get_tlv_dtag_nm(dtag); 10232 lpfc_printf_log(phba, KERN_WARNING, LOG_CGN_MGMT, 10233 "4672 Bad FPIN descriptor TLV length " 10234 "%d: %d %d %s\n", 10235 cnt, len, fpin_length, dtag_nm); 10236 return; 10237 } 10238 10239 current_tlv = tlv; 10240 bytes_remain -= FC_TLV_DESC_SZ_FROM_LENGTH(tlv); 10241 tlv = fc_tlv_next_desc(tlv); 10242 10243 /* Format payload such that the FPIN delivered to the 10244 * upper layer is a single descriptor FPIN. 10245 */ 10246 if (desc_cnt) 10247 memcpy(first_tlv, current_tlv, 10248 (cnt + sizeof(struct fc_els_fpin))); 10249 10250 /* Adjust the length so that it only reflects a 10251 * single descriptor FPIN. 10252 */ 10253 fpin_length = cnt + sizeof(struct fc_els_fpin); 10254 fpin->desc_len = cpu_to_be32(fpin_length); 10255 fpin_length += sizeof(struct fc_els_fpin); /* the entire FPIN */ 10256 10257 /* Send every descriptor individually to the upper layer */ 10258 if (deliver) 10259 fc_host_fpin_rcv(lpfc_shost_from_vport(vport), 10260 fpin_length, (char *)fpin, 0); 10261 desc_cnt++; 10262 } 10263 } 10264 10265 /** 10266 * lpfc_els_unsol_buffer - Process an unsolicited event data buffer 10267 * @phba: pointer to lpfc hba data structure. 10268 * @pring: pointer to a SLI ring. 10269 * @vport: pointer to a host virtual N_Port data structure. 10270 * @elsiocb: pointer to lpfc els command iocb data structure. 10271 * 10272 * This routine is used for processing the IOCB associated with a unsolicited 10273 * event. It first determines whether there is an existing ndlp that matches 10274 * the DID from the unsolicited IOCB. If not, it will create a new one with 10275 * the DID from the unsolicited IOCB. The ELS command from the unsolicited 10276 * IOCB is then used to invoke the proper routine and to set up proper state 10277 * of the discovery state machine. 10278 **/ 10279 static void 10280 lpfc_els_unsol_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, 10281 struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb) 10282 { 10283 struct lpfc_nodelist *ndlp; 10284 struct ls_rjt stat; 10285 u32 *payload, payload_len; 10286 u32 cmd = 0, did = 0, newnode, status = 0; 10287 uint8_t rjt_exp, rjt_err = 0, init_link = 0; 10288 struct lpfc_wcqe_complete *wcqe_cmpl = NULL; 10289 LPFC_MBOXQ_t *mbox; 10290 10291 if (!vport || !elsiocb->cmd_dmabuf) 10292 goto dropit; 10293 10294 newnode = 0; 10295 wcqe_cmpl = &elsiocb->wcqe_cmpl; 10296 payload = elsiocb->cmd_dmabuf->virt; 10297 if (phba->sli_rev == LPFC_SLI_REV4) 10298 payload_len = wcqe_cmpl->total_data_placed; 10299 else 10300 payload_len = elsiocb->iocb.unsli3.rcvsli3.acc_len; 10301 status = get_job_ulpstatus(phba, elsiocb); 10302 cmd = *payload; 10303 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0) 10304 lpfc_sli3_post_buffer(phba, pring, 1); 10305 10306 did = get_job_els_rsp64_did(phba, elsiocb); 10307 if (status) { 10308 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, 10309 "RCV Unsol ELS: status:x%x/x%x did:x%x", 10310 status, get_job_word4(phba, elsiocb), did); 10311 goto dropit; 10312 } 10313 10314 /* Check to see if link went down during discovery */ 10315 if (lpfc_els_chk_latt(vport)) 10316 goto dropit; 10317 10318 /* Ignore traffic received during vport shutdown. */ 10319 if (test_bit(FC_UNLOADING, &vport->load_flag)) 10320 goto dropit; 10321 10322 /* If NPort discovery is delayed drop incoming ELS */ 10323 if (test_bit(FC_DISC_DELAYED, &vport->fc_flag) && 10324 cmd != ELS_CMD_PLOGI) 10325 goto dropit; 10326 10327 ndlp = lpfc_findnode_did(vport, did); 10328 if (!ndlp) { 10329 /* Cannot find existing Fabric ndlp, so allocate a new one */ 10330 ndlp = lpfc_nlp_init(vport, did); 10331 if (!ndlp) 10332 goto dropit; 10333 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); 10334 newnode = 1; 10335 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) 10336 ndlp->nlp_type |= NLP_FABRIC; 10337 } else if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) { 10338 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); 10339 newnode = 1; 10340 } 10341 10342 phba->fc_stat.elsRcvFrame++; 10343 10344 /* 10345 * Do not process any unsolicited ELS commands 10346 * if the ndlp is in DEV_LOSS 10347 */ 10348 if (test_bit(NLP_IN_DEV_LOSS, &ndlp->nlp_flag)) { 10349 if (newnode) 10350 lpfc_nlp_put(ndlp); 10351 goto dropit; 10352 } 10353 10354 elsiocb->ndlp = lpfc_nlp_get(ndlp); 10355 if (!elsiocb->ndlp) 10356 goto dropit; 10357 elsiocb->vport = vport; 10358 10359 if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) { 10360 cmd &= ELS_CMD_MASK; 10361 } 10362 /* ELS command <elsCmd> received from NPORT <did> */ 10363 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, 10364 "0112 ELS command x%x received from NPORT x%x " 10365 "refcnt %d Data: x%x x%lx x%x x%x\n", 10366 cmd, did, kref_read(&ndlp->kref), vport->port_state, 10367 vport->fc_flag, vport->fc_myDID, vport->fc_prevDID); 10368 10369 /* reject till our FLOGI completes or PLOGI assigned DID via PT2PT */ 10370 if ((vport->port_state < LPFC_FABRIC_CFG_LINK) && 10371 (cmd != ELS_CMD_FLOGI) && 10372 !((cmd == ELS_CMD_PLOGI) && test_bit(FC_PT2PT, &vport->fc_flag))) { 10373 rjt_err = LSRJT_LOGICAL_BSY; 10374 rjt_exp = LSEXP_NOTHING_MORE; 10375 goto lsrjt; 10376 } 10377 10378 switch (cmd) { 10379 case ELS_CMD_PLOGI: 10380 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, 10381 "RCV PLOGI: did:x%x/ste:x%x flg:x%lx", 10382 did, vport->port_state, ndlp->nlp_flag); 10383 10384 phba->fc_stat.elsRcvPLOGI++; 10385 ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp); 10386 if (phba->sli_rev == LPFC_SLI_REV4 && 10387 test_bit(FC_PT2PT, &phba->pport->fc_flag)) { 10388 vport->fc_prevDID = vport->fc_myDID; 10389 /* Our DID needs to be updated before registering 10390 * the vfi. This is done in lpfc_rcv_plogi but 10391 * that is called after the reg_vfi. 10392 */ 10393 vport->fc_myDID = 10394 bf_get(els_rsp64_sid, 10395 &elsiocb->wqe.xmit_els_rsp); 10396 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, 10397 "3312 Remote port assigned DID x%x " 10398 "%x\n", vport->fc_myDID, 10399 vport->fc_prevDID); 10400 } 10401 10402 lpfc_send_els_event(vport, ndlp, payload); 10403 10404 /* If Nport discovery is delayed, reject PLOGIs */ 10405 if (test_bit(FC_DISC_DELAYED, &vport->fc_flag)) { 10406 rjt_err = LSRJT_UNABLE_TPC; 10407 rjt_exp = LSEXP_NOTHING_MORE; 10408 break; 10409 } 10410 10411 if (vport->port_state < LPFC_DISC_AUTH) { 10412 if (!test_bit(FC_PT2PT, &phba->pport->fc_flag) || 10413 test_bit(FC_PT2PT_PLOGI, &phba->pport->fc_flag)) { 10414 rjt_err = LSRJT_UNABLE_TPC; 10415 rjt_exp = LSEXP_NOTHING_MORE; 10416 break; 10417 } 10418 } 10419 10420 lpfc_disc_state_machine(vport, ndlp, elsiocb, 10421 NLP_EVT_RCV_PLOGI); 10422 10423 break; 10424 case ELS_CMD_FLOGI: 10425 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, 10426 "RCV FLOGI: did:x%x/ste:x%x flg:x%lx", 10427 did, vport->port_state, ndlp->nlp_flag); 10428 10429 phba->fc_stat.elsRcvFLOGI++; 10430 10431 /* If the driver believes fabric discovery is done and is ready, 10432 * bounce the link. There is some descrepancy. 10433 */ 10434 if (vport->port_state >= LPFC_LOCAL_CFG_LINK && 10435 test_bit(FC_PT2PT, &vport->fc_flag) && 10436 vport->rcv_flogi_cnt >= 1) { 10437 rjt_err = LSRJT_LOGICAL_BSY; 10438 rjt_exp = LSEXP_NOTHING_MORE; 10439 init_link++; 10440 goto lsrjt; 10441 } 10442 10443 lpfc_els_rcv_flogi(vport, elsiocb, ndlp); 10444 /* retain node if our response is deferred */ 10445 if (phba->defer_flogi_acc.flag) 10446 break; 10447 if (newnode) 10448 lpfc_disc_state_machine(vport, ndlp, NULL, 10449 NLP_EVT_DEVICE_RM); 10450 break; 10451 case ELS_CMD_LOGO: 10452 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, 10453 "RCV LOGO: did:x%x/ste:x%x flg:x%lx", 10454 did, vport->port_state, ndlp->nlp_flag); 10455 10456 phba->fc_stat.elsRcvLOGO++; 10457 lpfc_send_els_event(vport, ndlp, payload); 10458 if (vport->port_state < LPFC_DISC_AUTH) { 10459 rjt_err = LSRJT_UNABLE_TPC; 10460 rjt_exp = LSEXP_NOTHING_MORE; 10461 break; 10462 } 10463 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO); 10464 if (newnode) 10465 lpfc_disc_state_machine(vport, ndlp, NULL, 10466 NLP_EVT_DEVICE_RM); 10467 break; 10468 case ELS_CMD_PRLO: 10469 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, 10470 "RCV PRLO: did:x%x/ste:x%x flg:x%lx", 10471 did, vport->port_state, ndlp->nlp_flag); 10472 10473 phba->fc_stat.elsRcvPRLO++; 10474 lpfc_send_els_event(vport, ndlp, payload); 10475 if (vport->port_state < LPFC_DISC_AUTH) { 10476 rjt_err = LSRJT_UNABLE_TPC; 10477 rjt_exp = LSEXP_NOTHING_MORE; 10478 break; 10479 } 10480 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO); 10481 break; 10482 case ELS_CMD_LCB: 10483 phba->fc_stat.elsRcvLCB++; 10484 lpfc_els_rcv_lcb(vport, elsiocb, ndlp); 10485 break; 10486 case ELS_CMD_RDP: 10487 phba->fc_stat.elsRcvRDP++; 10488 lpfc_els_rcv_rdp(vport, elsiocb, ndlp); 10489 break; 10490 case ELS_CMD_RSCN: 10491 phba->fc_stat.elsRcvRSCN++; 10492 lpfc_els_rcv_rscn(vport, elsiocb, ndlp); 10493 if (newnode) 10494 lpfc_disc_state_machine(vport, ndlp, NULL, 10495 NLP_EVT_DEVICE_RM); 10496 break; 10497 case ELS_CMD_ADISC: 10498 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, 10499 "RCV ADISC: did:x%x/ste:x%x flg:x%lx", 10500 did, vport->port_state, ndlp->nlp_flag); 10501 10502 lpfc_send_els_event(vport, ndlp, payload); 10503 phba->fc_stat.elsRcvADISC++; 10504 if (vport->port_state < LPFC_DISC_AUTH) { 10505 rjt_err = LSRJT_UNABLE_TPC; 10506 rjt_exp = LSEXP_NOTHING_MORE; 10507 break; 10508 } 10509 lpfc_disc_state_machine(vport, ndlp, elsiocb, 10510 NLP_EVT_RCV_ADISC); 10511 break; 10512 case ELS_CMD_PDISC: 10513 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, 10514 "RCV PDISC: did:x%x/ste:x%x flg:x%lx", 10515 did, vport->port_state, ndlp->nlp_flag); 10516 10517 phba->fc_stat.elsRcvPDISC++; 10518 if (vport->port_state < LPFC_DISC_AUTH) { 10519 rjt_err = LSRJT_UNABLE_TPC; 10520 rjt_exp = LSEXP_NOTHING_MORE; 10521 break; 10522 } 10523 lpfc_disc_state_machine(vport, ndlp, elsiocb, 10524 NLP_EVT_RCV_PDISC); 10525 break; 10526 case ELS_CMD_FARPR: 10527 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, 10528 "RCV FARPR: did:x%x/ste:x%x flg:x%lx", 10529 did, vport->port_state, ndlp->nlp_flag); 10530 10531 phba->fc_stat.elsRcvFARPR++; 10532 lpfc_els_rcv_farpr(vport, elsiocb, ndlp); 10533 break; 10534 case ELS_CMD_FARP: 10535 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, 10536 "RCV FARP: did:x%x/ste:x%x flg:x%lx", 10537 did, vport->port_state, ndlp->nlp_flag); 10538 10539 phba->fc_stat.elsRcvFARP++; 10540 lpfc_els_rcv_farp(vport, elsiocb, ndlp); 10541 break; 10542 case ELS_CMD_FAN: 10543 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, 10544 "RCV FAN: did:x%x/ste:x%x flg:x%lx", 10545 did, vport->port_state, ndlp->nlp_flag); 10546 10547 phba->fc_stat.elsRcvFAN++; 10548 lpfc_els_rcv_fan(vport, elsiocb, ndlp); 10549 break; 10550 case ELS_CMD_PRLI: 10551 case ELS_CMD_NVMEPRLI: 10552 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, 10553 "RCV PRLI: did:x%x/ste:x%x flg:x%lx", 10554 did, vport->port_state, ndlp->nlp_flag); 10555 10556 phba->fc_stat.elsRcvPRLI++; 10557 if ((vport->port_state < LPFC_DISC_AUTH) && 10558 test_bit(FC_FABRIC, &vport->fc_flag)) { 10559 rjt_err = LSRJT_UNABLE_TPC; 10560 rjt_exp = LSEXP_NOTHING_MORE; 10561 break; 10562 } 10563 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI); 10564 break; 10565 case ELS_CMD_LIRR: 10566 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, 10567 "RCV LIRR: did:x%x/ste:x%x flg:x%lx", 10568 did, vport->port_state, ndlp->nlp_flag); 10569 10570 phba->fc_stat.elsRcvLIRR++; 10571 lpfc_els_rcv_lirr(vport, elsiocb, ndlp); 10572 if (newnode) 10573 lpfc_disc_state_machine(vport, ndlp, NULL, 10574 NLP_EVT_DEVICE_RM); 10575 break; 10576 case ELS_CMD_RLS: 10577 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, 10578 "RCV RLS: did:x%x/ste:x%x flg:x%lx", 10579 did, vport->port_state, ndlp->nlp_flag); 10580 10581 phba->fc_stat.elsRcvRLS++; 10582 lpfc_els_rcv_rls(vport, elsiocb, ndlp); 10583 if (newnode) 10584 lpfc_disc_state_machine(vport, ndlp, NULL, 10585 NLP_EVT_DEVICE_RM); 10586 break; 10587 case ELS_CMD_RPL: 10588 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, 10589 "RCV RPL: did:x%x/ste:x%x flg:x%lx", 10590 did, vport->port_state, ndlp->nlp_flag); 10591 10592 phba->fc_stat.elsRcvRPL++; 10593 lpfc_els_rcv_rpl(vport, elsiocb, ndlp); 10594 if (newnode) 10595 lpfc_disc_state_machine(vport, ndlp, NULL, 10596 NLP_EVT_DEVICE_RM); 10597 break; 10598 case ELS_CMD_RNID: 10599 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, 10600 "RCV RNID: did:x%x/ste:x%x flg:x%lx", 10601 did, vport->port_state, ndlp->nlp_flag); 10602 10603 phba->fc_stat.elsRcvRNID++; 10604 lpfc_els_rcv_rnid(vport, elsiocb, ndlp); 10605 if (newnode) 10606 lpfc_disc_state_machine(vport, ndlp, NULL, 10607 NLP_EVT_DEVICE_RM); 10608 break; 10609 case ELS_CMD_RTV: 10610 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, 10611 "RCV RTV: did:x%x/ste:x%x flg:x%lx", 10612 did, vport->port_state, ndlp->nlp_flag); 10613 phba->fc_stat.elsRcvRTV++; 10614 lpfc_els_rcv_rtv(vport, elsiocb, ndlp); 10615 if (newnode) 10616 lpfc_disc_state_machine(vport, ndlp, NULL, 10617 NLP_EVT_DEVICE_RM); 10618 break; 10619 case ELS_CMD_RRQ: 10620 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, 10621 "RCV RRQ: did:x%x/ste:x%x flg:x%lx", 10622 did, vport->port_state, ndlp->nlp_flag); 10623 10624 phba->fc_stat.elsRcvRRQ++; 10625 lpfc_els_rcv_rrq(vport, elsiocb, ndlp); 10626 if (newnode) 10627 lpfc_disc_state_machine(vport, ndlp, NULL, 10628 NLP_EVT_DEVICE_RM); 10629 break; 10630 case ELS_CMD_ECHO: 10631 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, 10632 "RCV ECHO: did:x%x/ste:x%x flg:x%lx", 10633 did, vport->port_state, ndlp->nlp_flag); 10634 10635 phba->fc_stat.elsRcvECHO++; 10636 lpfc_els_rcv_echo(vport, elsiocb, ndlp); 10637 if (newnode) 10638 lpfc_disc_state_machine(vport, ndlp, NULL, 10639 NLP_EVT_DEVICE_RM); 10640 break; 10641 case ELS_CMD_REC: 10642 /* receive this due to exchange closed */ 10643 rjt_err = LSRJT_UNABLE_TPC; 10644 rjt_exp = LSEXP_INVALID_OX_RX; 10645 break; 10646 case ELS_CMD_FPIN: 10647 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, 10648 "RCV FPIN: did:x%x/ste:x%x " 10649 "flg:x%lx", 10650 did, vport->port_state, ndlp->nlp_flag); 10651 10652 lpfc_els_rcv_fpin(vport, (struct fc_els_fpin *)payload, 10653 payload_len); 10654 10655 /* There are no replies, so no rjt codes */ 10656 break; 10657 case ELS_CMD_EDC: 10658 lpfc_els_rcv_edc(vport, elsiocb, ndlp); 10659 break; 10660 case ELS_CMD_RDF: 10661 phba->fc_stat.elsRcvRDF++; 10662 /* Accept RDF only from fabric controller */ 10663 if (did != Fabric_Cntl_DID) { 10664 lpfc_printf_vlog(vport, KERN_WARNING, LOG_ELS, 10665 "1115 Received RDF from invalid DID " 10666 "x%x\n", did); 10667 rjt_err = LSRJT_PROTOCOL_ERR; 10668 rjt_exp = LSEXP_NOTHING_MORE; 10669 goto lsrjt; 10670 } 10671 10672 lpfc_els_rcv_rdf(vport, elsiocb, ndlp); 10673 break; 10674 default: 10675 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, 10676 "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x", 10677 cmd, did, vport->port_state); 10678 10679 /* Unsupported ELS command, reject */ 10680 rjt_err = LSRJT_CMD_UNSUPPORTED; 10681 rjt_exp = LSEXP_NOTHING_MORE; 10682 10683 /* Unknown ELS command <elsCmd> received from NPORT <did> */ 10684 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, 10685 "0115 Unknown ELS command x%x " 10686 "received from NPORT x%x\n", cmd, did); 10687 if (newnode) 10688 lpfc_disc_state_machine(vport, ndlp, NULL, 10689 NLP_EVT_DEVICE_RM); 10690 break; 10691 } 10692 10693 lsrjt: 10694 /* check if need to LS_RJT received ELS cmd */ 10695 if (rjt_err) { 10696 memset(&stat, 0, sizeof(stat)); 10697 stat.un.b.lsRjtRsnCode = rjt_err; 10698 stat.un.b.lsRjtRsnCodeExp = rjt_exp; 10699 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp, 10700 NULL); 10701 /* Remove the reference from above for new nodes. */ 10702 if (newnode) 10703 lpfc_disc_state_machine(vport, ndlp, NULL, 10704 NLP_EVT_DEVICE_RM); 10705 } 10706 10707 /* Release the reference on this elsiocb, not the ndlp. */ 10708 lpfc_nlp_put(elsiocb->ndlp); 10709 elsiocb->ndlp = NULL; 10710 10711 /* Special case. Driver received an unsolicited command that 10712 * unsupportable given the driver's current state. Reset the 10713 * link and start over. 10714 */ 10715 if (init_link) { 10716 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); 10717 if (!mbox) 10718 return; 10719 lpfc_linkdown(phba); 10720 lpfc_init_link(phba, mbox, 10721 phba->cfg_topology, 10722 phba->cfg_link_speed); 10723 mbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0; 10724 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; 10725 mbox->vport = vport; 10726 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) == 10727 MBX_NOT_FINISHED) 10728 mempool_free(mbox, phba->mbox_mem_pool); 10729 } 10730 10731 return; 10732 10733 dropit: 10734 if (vport && !test_bit(FC_UNLOADING, &vport->load_flag)) 10735 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, 10736 "0111 Dropping received ELS cmd " 10737 "Data: x%x x%x x%x x%x\n", 10738 cmd, status, get_job_word4(phba, elsiocb), did); 10739 10740 phba->fc_stat.elsRcvDrop++; 10741 } 10742 10743 /** 10744 * lpfc_els_unsol_event - Process an unsolicited event from an els sli ring 10745 * @phba: pointer to lpfc hba data structure. 10746 * @pring: pointer to a SLI ring. 10747 * @elsiocb: pointer to lpfc els iocb data structure. 10748 * 10749 * This routine is used to process an unsolicited event received from a SLI 10750 * (Service Level Interface) ring. The actual processing of the data buffer 10751 * associated with the unsolicited event is done by invoking the routine 10752 * lpfc_els_unsol_buffer() after properly set up the iocb buffer from the 10753 * SLI ring on which the unsolicited event was received. 10754 **/ 10755 void 10756 lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, 10757 struct lpfc_iocbq *elsiocb) 10758 { 10759 struct lpfc_vport *vport = elsiocb->vport; 10760 u32 ulp_command, status, parameter, bde_count = 0; 10761 IOCB_t *icmd; 10762 struct lpfc_wcqe_complete *wcqe_cmpl = NULL; 10763 struct lpfc_dmabuf *bdeBuf1 = elsiocb->cmd_dmabuf; 10764 struct lpfc_dmabuf *bdeBuf2 = elsiocb->bpl_dmabuf; 10765 dma_addr_t paddr; 10766 10767 elsiocb->cmd_dmabuf = NULL; 10768 elsiocb->rsp_dmabuf = NULL; 10769 elsiocb->bpl_dmabuf = NULL; 10770 10771 wcqe_cmpl = &elsiocb->wcqe_cmpl; 10772 ulp_command = get_job_cmnd(phba, elsiocb); 10773 status = get_job_ulpstatus(phba, elsiocb); 10774 parameter = get_job_word4(phba, elsiocb); 10775 if (phba->sli_rev == LPFC_SLI_REV4) 10776 bde_count = wcqe_cmpl->word3; 10777 else 10778 bde_count = elsiocb->iocb.ulpBdeCount; 10779 10780 if (status == IOSTAT_NEED_BUFFER) { 10781 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ); 10782 } else if (status == IOSTAT_LOCAL_REJECT && 10783 (parameter & IOERR_PARAM_MASK) == 10784 IOERR_RCV_BUFFER_WAITING) { 10785 phba->fc_stat.NoRcvBuf++; 10786 /* Not enough posted buffers; Try posting more buffers */ 10787 if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) 10788 lpfc_sli3_post_buffer(phba, pring, 0); 10789 return; 10790 } 10791 10792 if (phba->sli_rev == LPFC_SLI_REV3) { 10793 icmd = &elsiocb->iocb; 10794 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && 10795 (ulp_command == CMD_IOCB_RCV_ELS64_CX || 10796 ulp_command == CMD_IOCB_RCV_SEQ64_CX)) { 10797 if (icmd->unsli3.rcvsli3.vpi == 0xffff) 10798 vport = phba->pport; 10799 else 10800 vport = lpfc_find_vport_by_vpid(phba, 10801 icmd->unsli3.rcvsli3.vpi); 10802 } 10803 } 10804 10805 /* If there are no BDEs associated 10806 * with this IOCB, there is nothing to do. 10807 */ 10808 if (bde_count == 0) 10809 return; 10810 10811 /* Account for SLI2 or SLI3 and later unsolicited buffering */ 10812 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) { 10813 elsiocb->cmd_dmabuf = bdeBuf1; 10814 if (bde_count == 2) 10815 elsiocb->bpl_dmabuf = bdeBuf2; 10816 } else { 10817 icmd = &elsiocb->iocb; 10818 paddr = getPaddr(icmd->un.cont64[0].addrHigh, 10819 icmd->un.cont64[0].addrLow); 10820 elsiocb->cmd_dmabuf = lpfc_sli_ringpostbuf_get(phba, pring, 10821 paddr); 10822 if (bde_count == 2) { 10823 paddr = getPaddr(icmd->un.cont64[1].addrHigh, 10824 icmd->un.cont64[1].addrLow); 10825 elsiocb->bpl_dmabuf = lpfc_sli_ringpostbuf_get(phba, 10826 pring, 10827 paddr); 10828 } 10829 } 10830 10831 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb); 10832 /* 10833 * The different unsolicited event handlers would tell us 10834 * if they are done with "mp" by setting cmd_dmabuf to NULL. 10835 */ 10836 if (elsiocb->cmd_dmabuf) { 10837 lpfc_in_buf_free(phba, elsiocb->cmd_dmabuf); 10838 elsiocb->cmd_dmabuf = NULL; 10839 } 10840 10841 if (elsiocb->bpl_dmabuf) { 10842 lpfc_in_buf_free(phba, elsiocb->bpl_dmabuf); 10843 elsiocb->bpl_dmabuf = NULL; 10844 } 10845 10846 } 10847 10848 static void 10849 lpfc_start_fdmi(struct lpfc_vport *vport) 10850 { 10851 struct lpfc_nodelist *ndlp; 10852 10853 /* If this is the first time, allocate an ndlp and initialize 10854 * it. Otherwise, make sure the node is enabled and then do the 10855 * login. 10856 */ 10857 ndlp = lpfc_findnode_did(vport, FDMI_DID); 10858 if (!ndlp) { 10859 ndlp = lpfc_nlp_init(vport, FDMI_DID); 10860 if (ndlp) { 10861 ndlp->nlp_type |= NLP_FABRIC; 10862 } else { 10863 return; 10864 } 10865 } 10866 10867 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); 10868 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0); 10869 } 10870 10871 /** 10872 * lpfc_do_scr_ns_plogi - Issue a plogi to the name server for scr 10873 * @phba: pointer to lpfc hba data structure. 10874 * @vport: pointer to a virtual N_Port data structure. 10875 * 10876 * This routine issues a Port Login (PLOGI) to the Name Server with 10877 * State Change Request (SCR) for a @vport. This routine will create an 10878 * ndlp for the Name Server associated to the @vport if such node does 10879 * not already exist. The PLOGI to Name Server is issued by invoking the 10880 * lpfc_issue_els_plogi() routine. If Fabric-Device Management Interface 10881 * (FDMI) is configured to the @vport, a FDMI node will be created and 10882 * the PLOGI to FDMI is issued by invoking lpfc_issue_els_plogi() routine. 10883 **/ 10884 void 10885 lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport) 10886 { 10887 struct lpfc_nodelist *ndlp; 10888 10889 /* 10890 * If lpfc_delay_discovery parameter is set and the clean address 10891 * bit is cleared and fc fabric parameters chenged, delay FC NPort 10892 * discovery. 10893 */ 10894 if (test_bit(FC_DISC_DELAYED, &vport->fc_flag)) { 10895 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, 10896 "3334 Delay fc port discovery for %d secs\n", 10897 phba->fc_ratov); 10898 mod_timer(&vport->delayed_disc_tmo, 10899 jiffies + secs_to_jiffies(phba->fc_ratov)); 10900 return; 10901 } 10902 10903 ndlp = lpfc_findnode_did(vport, NameServer_DID); 10904 if (!ndlp) { 10905 ndlp = lpfc_nlp_init(vport, NameServer_DID); 10906 if (!ndlp) { 10907 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { 10908 lpfc_disc_start(vport); 10909 return; 10910 } 10911 lpfc_vport_set_state(vport, FC_VPORT_FAILED); 10912 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, 10913 "0251 NameServer login: no memory\n"); 10914 return; 10915 } 10916 } 10917 10918 ndlp->nlp_type |= NLP_FABRIC; 10919 10920 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); 10921 10922 if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) { 10923 lpfc_vport_set_state(vport, FC_VPORT_FAILED); 10924 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, 10925 "0252 Cannot issue NameServer login\n"); 10926 return; 10927 } 10928 10929 if ((phba->cfg_enable_SmartSAN || 10930 phba->cfg_fdmi_on == LPFC_FDMI_SUPPORT) && 10931 test_bit(FC_ALLOW_FDMI, &vport->load_flag)) 10932 lpfc_start_fdmi(vport); 10933 } 10934 10935 /** 10936 * lpfc_cmpl_reg_new_vport - Completion callback function to register new vport 10937 * @phba: pointer to lpfc hba data structure. 10938 * @pmb: pointer to the driver internal queue element for mailbox command. 10939 * 10940 * This routine is the completion callback function to register new vport 10941 * mailbox command. If the new vport mailbox command completes successfully, 10942 * the fabric registration login shall be performed on physical port (the 10943 * new vport created is actually a physical port, with VPI 0) or the port 10944 * login to Name Server for State Change Request (SCR) will be performed 10945 * on virtual port (real virtual port, with VPI greater than 0). 10946 **/ 10947 static void 10948 lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) 10949 { 10950 struct lpfc_vport *vport = pmb->vport; 10951 struct Scsi_Host *shost = lpfc_shost_from_vport(vport); 10952 struct lpfc_nodelist *ndlp = pmb->ctx_ndlp; 10953 MAILBOX_t *mb = &pmb->u.mb; 10954 int rc; 10955 10956 clear_bit(FC_VPORT_NEEDS_REG_VPI, &vport->fc_flag); 10957 10958 if (mb->mbxStatus) { 10959 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, 10960 "0915 Register VPI failed : Status: x%x" 10961 " upd bit: x%x \n", mb->mbxStatus, 10962 mb->un.varRegVpi.upd); 10963 if (phba->sli_rev == LPFC_SLI_REV4 && 10964 mb->un.varRegVpi.upd) 10965 goto mbox_err_exit ; 10966 10967 switch (mb->mbxStatus) { 10968 case 0x11: /* unsupported feature */ 10969 case 0x9603: /* max_vpi exceeded */ 10970 case 0x9602: /* Link event since CLEAR_LA */ 10971 /* giving up on vport registration */ 10972 lpfc_vport_set_state(vport, FC_VPORT_FAILED); 10973 clear_bit(FC_FABRIC, &vport->fc_flag); 10974 clear_bit(FC_PUBLIC_LOOP, &vport->fc_flag); 10975 lpfc_can_disctmo(vport); 10976 break; 10977 /* If reg_vpi fail with invalid VPI status, re-init VPI */ 10978 case 0x20: 10979 set_bit(FC_VPORT_NEEDS_REG_VPI, &vport->fc_flag); 10980 lpfc_init_vpi(phba, pmb, vport->vpi); 10981 pmb->vport = vport; 10982 pmb->mbox_cmpl = lpfc_init_vpi_cmpl; 10983 rc = lpfc_sli_issue_mbox(phba, pmb, 10984 MBX_NOWAIT); 10985 if (rc == MBX_NOT_FINISHED) { 10986 lpfc_printf_vlog(vport, KERN_ERR, 10987 LOG_TRACE_EVENT, 10988 "2732 Failed to issue INIT_VPI" 10989 " mailbox command\n"); 10990 } else { 10991 lpfc_nlp_put(ndlp); 10992 return; 10993 } 10994 fallthrough; 10995 default: 10996 /* Try to recover from this error */ 10997 if (phba->sli_rev == LPFC_SLI_REV4) 10998 lpfc_sli4_unreg_all_rpis(vport); 10999 lpfc_mbx_unreg_vpi(vport); 11000 set_bit(FC_VPORT_NEEDS_REG_VPI, &vport->fc_flag); 11001 if (mb->mbxStatus == MBX_NOT_FINISHED) 11002 break; 11003 if ((vport->port_type == LPFC_PHYSICAL_PORT) && 11004 !test_bit(FC_LOGO_RCVD_DID_CHNG, &vport->fc_flag)) { 11005 if (phba->sli_rev == LPFC_SLI_REV4) 11006 lpfc_issue_init_vfi(vport); 11007 else 11008 lpfc_initial_flogi(vport); 11009 } else { 11010 lpfc_initial_fdisc(vport); 11011 } 11012 break; 11013 } 11014 } else { 11015 spin_lock_irq(shost->host_lock); 11016 vport->vpi_state |= LPFC_VPI_REGISTERED; 11017 spin_unlock_irq(shost->host_lock); 11018 if (vport == phba->pport) { 11019 if (phba->sli_rev < LPFC_SLI_REV4) 11020 lpfc_issue_fabric_reglogin(vport); 11021 else { 11022 /* 11023 * If the physical port is instantiated using 11024 * FDISC, do not start vport discovery. 11025 */ 11026 if (vport->port_state != LPFC_FDISC) 11027 lpfc_start_fdiscs(phba); 11028 lpfc_do_scr_ns_plogi(phba, vport); 11029 } 11030 } else { 11031 lpfc_do_scr_ns_plogi(phba, vport); 11032 } 11033 } 11034 mbox_err_exit: 11035 /* Now, we decrement the ndlp reference count held for this 11036 * callback function 11037 */ 11038 lpfc_nlp_put(ndlp); 11039 11040 mempool_free(pmb, phba->mbox_mem_pool); 11041 11042 /* reinitialize the VMID datastructure before returning. 11043 * this is specifically for vport 11044 */ 11045 if (lpfc_is_vmid_enabled(phba)) 11046 lpfc_reinit_vmid(vport); 11047 vport->vmid_flag = vport->phba->pport->vmid_flag; 11048 11049 return; 11050 } 11051 11052 /** 11053 * lpfc_register_new_vport - Register a new vport with a HBA 11054 * @phba: pointer to lpfc hba data structure. 11055 * @vport: pointer to a host virtual N_Port data structure. 11056 * @ndlp: pointer to a node-list data structure. 11057 * 11058 * This routine registers the @vport as a new virtual port with a HBA. 11059 * It is done through a registering vpi mailbox command. 11060 **/ 11061 void 11062 lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport, 11063 struct lpfc_nodelist *ndlp) 11064 { 11065 LPFC_MBOXQ_t *mbox; 11066 11067 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); 11068 if (mbox) { 11069 lpfc_reg_vpi(vport, mbox); 11070 mbox->vport = vport; 11071 mbox->ctx_ndlp = lpfc_nlp_get(ndlp); 11072 if (!mbox->ctx_ndlp) { 11073 mempool_free(mbox, phba->mbox_mem_pool); 11074 goto mbox_err_exit; 11075 } 11076 11077 mbox->mbox_cmpl = lpfc_cmpl_reg_new_vport; 11078 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) 11079 == MBX_NOT_FINISHED) { 11080 /* mailbox command not success, decrement ndlp 11081 * reference count for this command 11082 */ 11083 lpfc_nlp_put(ndlp); 11084 mempool_free(mbox, phba->mbox_mem_pool); 11085 11086 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, 11087 "0253 Register VPI: Can't send mbox\n"); 11088 goto mbox_err_exit; 11089 } 11090 } else { 11091 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, 11092 "0254 Register VPI: no memory\n"); 11093 goto mbox_err_exit; 11094 } 11095 return; 11096 11097 mbox_err_exit: 11098 lpfc_vport_set_state(vport, FC_VPORT_FAILED); 11099 clear_bit(FC_VPORT_NEEDS_REG_VPI, &vport->fc_flag); 11100 return; 11101 } 11102 11103 /** 11104 * lpfc_cancel_all_vport_retry_delay_timer - Cancel all vport retry delay timer 11105 * @phba: pointer to lpfc hba data structure. 11106 * 11107 * This routine cancels the retry delay timers to all the vports. 11108 **/ 11109 void 11110 lpfc_cancel_all_vport_retry_delay_timer(struct lpfc_hba *phba) 11111 { 11112 struct lpfc_vport **vports; 11113 struct lpfc_nodelist *ndlp; 11114 uint32_t link_state; 11115 int i; 11116 11117 /* Treat this failure as linkdown for all vports */ 11118 link_state = phba->link_state; 11119 lpfc_linkdown(phba); 11120 phba->link_state = link_state; 11121 11122 vports = lpfc_create_vport_work_array(phba); 11123 11124 if (vports) { 11125 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { 11126 ndlp = lpfc_findnode_did(vports[i], Fabric_DID); 11127 if (ndlp) 11128 lpfc_cancel_retry_delay_tmo(vports[i], ndlp); 11129 lpfc_els_flush_cmd(vports[i]); 11130 } 11131 lpfc_destroy_vport_work_array(phba, vports); 11132 } 11133 } 11134 11135 /** 11136 * lpfc_retry_pport_discovery - Start timer to retry FLOGI. 11137 * @phba: pointer to lpfc hba data structure. 11138 * 11139 * This routine abort all pending discovery commands and 11140 * start a timer to retry FLOGI for the physical port 11141 * discovery. 11142 **/ 11143 void 11144 lpfc_retry_pport_discovery(struct lpfc_hba *phba) 11145 { 11146 struct lpfc_nodelist *ndlp; 11147 11148 /* Cancel the all vports retry delay retry timers */ 11149 lpfc_cancel_all_vport_retry_delay_timer(phba); 11150 11151 /* If fabric require FLOGI, then re-instantiate physical login */ 11152 ndlp = lpfc_findnode_did(phba->pport, Fabric_DID); 11153 if (!ndlp) 11154 return; 11155 11156 mod_timer(&ndlp->nlp_delayfunc, jiffies + secs_to_jiffies(1)); 11157 set_bit(NLP_DELAY_TMO, &ndlp->nlp_flag); 11158 ndlp->nlp_last_elscmd = ELS_CMD_FLOGI; 11159 phba->pport->port_state = LPFC_FLOGI; 11160 return; 11161 } 11162 11163 /** 11164 * lpfc_fabric_login_reqd - Check if FLOGI required. 11165 * @phba: pointer to lpfc hba data structure. 11166 * @cmdiocb: pointer to FDISC command iocb. 11167 * @rspiocb: pointer to FDISC response iocb. 11168 * 11169 * This routine checks if a FLOGI is reguired for FDISC 11170 * to succeed. 11171 **/ 11172 static int 11173 lpfc_fabric_login_reqd(struct lpfc_hba *phba, 11174 struct lpfc_iocbq *cmdiocb, 11175 struct lpfc_iocbq *rspiocb) 11176 { 11177 u32 ulp_status = get_job_ulpstatus(phba, rspiocb); 11178 u32 ulp_word4 = get_job_word4(phba, rspiocb); 11179 11180 if (ulp_status != IOSTAT_FABRIC_RJT || 11181 ulp_word4 != RJT_LOGIN_REQUIRED) 11182 return 0; 11183 else 11184 return 1; 11185 } 11186 11187 /** 11188 * lpfc_cmpl_els_fdisc - Completion function for fdisc iocb command 11189 * @phba: pointer to lpfc hba data structure. 11190 * @cmdiocb: pointer to lpfc command iocb data structure. 11191 * @rspiocb: pointer to lpfc response iocb data structure. 11192 * 11193 * This routine is the completion callback function to a Fabric Discover 11194 * (FDISC) ELS command. Since all the FDISC ELS commands are issued 11195 * single threaded, each FDISC completion callback function will reset 11196 * the discovery timer for all vports such that the timers will not get 11197 * unnecessary timeout. The function checks the FDISC IOCB status. If error 11198 * detected, the vport will be set to FC_VPORT_FAILED state. Otherwise,the 11199 * vport will set to FC_VPORT_ACTIVE state. It then checks whether the DID 11200 * assigned to the vport has been changed with the completion of the FDISC 11201 * command. If so, both RPI (Remote Port Index) and VPI (Virtual Port Index) 11202 * are unregistered from the HBA, and then the lpfc_register_new_vport() 11203 * routine is invoked to register new vport with the HBA. Otherwise, the 11204 * lpfc_do_scr_ns_plogi() routine is invoked to issue a PLOGI to the Name 11205 * Server for State Change Request (SCR). 11206 **/ 11207 static void 11208 lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, 11209 struct lpfc_iocbq *rspiocb) 11210 { 11211 struct lpfc_vport *vport = cmdiocb->vport; 11212 struct lpfc_nodelist *ndlp = cmdiocb->ndlp; 11213 struct lpfc_nodelist *np; 11214 struct lpfc_nodelist *next_np; 11215 struct lpfc_iocbq *piocb; 11216 struct lpfc_dmabuf *pcmd = cmdiocb->cmd_dmabuf, *prsp; 11217 struct serv_parm *sp; 11218 uint8_t fabric_param_changed; 11219 u32 ulp_status, ulp_word4; 11220 11221 ulp_status = get_job_ulpstatus(phba, rspiocb); 11222 ulp_word4 = get_job_word4(phba, rspiocb); 11223 11224 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, 11225 "0123 FDISC completes. x%x/x%x prevDID: x%x\n", 11226 ulp_status, ulp_word4, 11227 vport->fc_prevDID); 11228 /* Since all FDISCs are being single threaded, we 11229 * must reset the discovery timer for ALL vports 11230 * waiting to send FDISC when one completes. 11231 */ 11232 list_for_each_entry(piocb, &phba->fabric_iocb_list, list) { 11233 lpfc_set_disctmo(piocb->vport); 11234 } 11235 11236 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, 11237 "FDISC cmpl: status:x%x/x%x prevdid:x%x", 11238 ulp_status, ulp_word4, vport->fc_prevDID); 11239 11240 if (ulp_status) { 11241 11242 if (lpfc_fabric_login_reqd(phba, cmdiocb, rspiocb)) { 11243 lpfc_retry_pport_discovery(phba); 11244 goto out; 11245 } 11246 11247 /* Check for retry */ 11248 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) 11249 goto out; 11250 /* Warn FDISC status */ 11251 lpfc_vlog_msg(vport, KERN_WARNING, LOG_ELS, 11252 "0126 FDISC cmpl status: x%x/x%x)\n", 11253 ulp_status, ulp_word4); 11254 goto fdisc_failed; 11255 } 11256 11257 lpfc_check_nlp_post_devloss(vport, ndlp); 11258 11259 clear_bit(FC_VPORT_CVL_RCVD, &vport->fc_flag); 11260 clear_bit(FC_VPORT_LOGO_RCVD, &vport->fc_flag); 11261 set_bit(FC_FABRIC, &vport->fc_flag); 11262 if (vport->phba->fc_topology == LPFC_TOPOLOGY_LOOP) 11263 set_bit(FC_PUBLIC_LOOP, &vport->fc_flag); 11264 11265 vport->fc_myDID = ulp_word4 & Mask_DID; 11266 lpfc_vport_set_state(vport, FC_VPORT_ACTIVE); 11267 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list); 11268 if (!prsp) 11269 goto out; 11270 if (!lpfc_is_els_acc_rsp(prsp)) 11271 goto out; 11272 11273 sp = prsp->virt + sizeof(uint32_t); 11274 fabric_param_changed = lpfc_check_clean_addr_bit(vport, sp); 11275 memcpy(&vport->fabric_portname, &sp->portName, 11276 sizeof(struct lpfc_name)); 11277 memcpy(&vport->fabric_nodename, &sp->nodeName, 11278 sizeof(struct lpfc_name)); 11279 if (fabric_param_changed && 11280 !test_bit(FC_VPORT_NEEDS_REG_VPI, &vport->fc_flag)) { 11281 /* If our NportID changed, we need to ensure all 11282 * remaining NPORTs get unreg_login'ed so we can 11283 * issue unreg_vpi. 11284 */ 11285 list_for_each_entry_safe(np, next_np, 11286 &vport->fc_nodes, nlp_listp) { 11287 if ((np->nlp_state != NLP_STE_NPR_NODE) || 11288 !test_bit(NLP_NPR_ADISC, &np->nlp_flag)) 11289 continue; 11290 clear_bit(NLP_NPR_ADISC, &np->nlp_flag); 11291 lpfc_unreg_rpi(vport, np); 11292 } 11293 lpfc_cleanup_pending_mbox(vport); 11294 11295 if (phba->sli_rev == LPFC_SLI_REV4) 11296 lpfc_sli4_unreg_all_rpis(vport); 11297 11298 lpfc_mbx_unreg_vpi(vport); 11299 set_bit(FC_VPORT_NEEDS_REG_VPI, &vport->fc_flag); 11300 if (phba->sli_rev == LPFC_SLI_REV4) 11301 set_bit(FC_VPORT_NEEDS_INIT_VPI, &vport->fc_flag); 11302 else 11303 set_bit(FC_LOGO_RCVD_DID_CHNG, &vport->fc_flag); 11304 } else if ((phba->sli_rev == LPFC_SLI_REV4) && 11305 !test_bit(FC_VPORT_NEEDS_REG_VPI, &vport->fc_flag)) { 11306 /* 11307 * Driver needs to re-reg VPI in order for f/w 11308 * to update the MAC address. 11309 */ 11310 lpfc_register_new_vport(phba, vport, ndlp); 11311 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE); 11312 goto out; 11313 } 11314 11315 if (test_bit(FC_VPORT_NEEDS_INIT_VPI, &vport->fc_flag)) 11316 lpfc_issue_init_vpi(vport); 11317 else if (test_bit(FC_VPORT_NEEDS_REG_VPI, &vport->fc_flag)) 11318 lpfc_register_new_vport(phba, vport, ndlp); 11319 else 11320 lpfc_do_scr_ns_plogi(phba, vport); 11321 11322 /* The FDISC completed successfully. Move the fabric ndlp to 11323 * UNMAPPED state and register with the transport. 11324 */ 11325 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE); 11326 goto out; 11327 11328 fdisc_failed: 11329 if (vport->fc_vport && 11330 (vport->fc_vport->vport_state != FC_VPORT_NO_FABRIC_RSCS)) 11331 lpfc_vport_set_state(vport, FC_VPORT_FAILED); 11332 /* Cancel discovery timer */ 11333 lpfc_can_disctmo(vport); 11334 out: 11335 lpfc_els_free_iocb(phba, cmdiocb); 11336 lpfc_nlp_put(ndlp); 11337 } 11338 11339 /** 11340 * lpfc_issue_els_fdisc - Issue a fdisc iocb command 11341 * @vport: pointer to a virtual N_Port data structure. 11342 * @ndlp: pointer to a node-list data structure. 11343 * @retry: number of retries to the command IOCB. 11344 * 11345 * This routine prepares and issues a Fabric Discover (FDISC) IOCB to 11346 * a remote node (@ndlp) off a @vport. It uses the lpfc_issue_fabric_iocb() 11347 * routine to issue the IOCB, which makes sure only one outstanding fabric 11348 * IOCB will be sent off HBA at any given time. 11349 * 11350 * Note that the ndlp reference count will be incremented by 1 for holding the 11351 * ndlp and the reference to ndlp will be stored into the ndlp field of 11352 * the IOCB for the completion callback function to the FDISC ELS command. 11353 * 11354 * Return code 11355 * 0 - Successfully issued fdisc iocb command 11356 * 1 - Failed to issue fdisc iocb command 11357 **/ 11358 static int 11359 lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, 11360 uint8_t retry) 11361 { 11362 struct lpfc_hba *phba = vport->phba; 11363 IOCB_t *icmd; 11364 union lpfc_wqe128 *wqe = NULL; 11365 struct lpfc_iocbq *elsiocb; 11366 struct serv_parm *sp; 11367 uint8_t *pcmd; 11368 uint16_t cmdsize; 11369 int did = ndlp->nlp_DID; 11370 int rc; 11371 11372 vport->port_state = LPFC_FDISC; 11373 vport->fc_myDID = 0; 11374 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm)); 11375 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did, 11376 ELS_CMD_FDISC); 11377 if (!elsiocb) { 11378 lpfc_vport_set_state(vport, FC_VPORT_FAILED); 11379 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, 11380 "0255 Issue FDISC: no IOCB\n"); 11381 return 1; 11382 } 11383 11384 if (phba->sli_rev == LPFC_SLI_REV4) { 11385 wqe = &elsiocb->wqe; 11386 bf_set(els_req64_sid, &wqe->els_req, 0); 11387 bf_set(els_req64_sp, &wqe->els_req, 1); 11388 } else { 11389 icmd = &elsiocb->iocb; 11390 icmd->un.elsreq64.myID = 0; 11391 icmd->un.elsreq64.fl = 1; 11392 icmd->ulpCt_h = 1; 11393 icmd->ulpCt_l = 0; 11394 } 11395 11396 pcmd = (uint8_t *)elsiocb->cmd_dmabuf->virt; 11397 *((uint32_t *) (pcmd)) = ELS_CMD_FDISC; 11398 pcmd += sizeof(uint32_t); /* CSP Word 1 */ 11399 memcpy(pcmd, &vport->phba->pport->fc_sparam, sizeof(struct serv_parm)); 11400 sp = (struct serv_parm *) pcmd; 11401 /* Setup CSPs accordingly for Fabric */ 11402 sp->cmn.e_d_tov = 0; 11403 sp->cmn.w2.r_a_tov = 0; 11404 sp->cmn.virtual_fabric_support = 0; 11405 sp->cls1.classValid = 0; 11406 sp->cls2.seqDelivery = 1; 11407 sp->cls3.seqDelivery = 1; 11408 11409 pcmd += sizeof(uint32_t); /* CSP Word 2 */ 11410 pcmd += sizeof(uint32_t); /* CSP Word 3 */ 11411 pcmd += sizeof(uint32_t); /* CSP Word 4 */ 11412 pcmd += sizeof(uint32_t); /* Port Name */ 11413 memcpy(pcmd, &vport->fc_portname, 8); 11414 pcmd += sizeof(uint32_t); /* Node Name */ 11415 pcmd += sizeof(uint32_t); /* Node Name */ 11416 memcpy(pcmd, &vport->fc_nodename, 8); 11417 sp->cmn.valid_vendor_ver_level = 0; 11418 memset(sp->un.vendorVersion, 0, sizeof(sp->un.vendorVersion)); 11419 lpfc_set_disctmo(vport); 11420 11421 phba->fc_stat.elsXmitFDISC++; 11422 elsiocb->cmd_cmpl = lpfc_cmpl_els_fdisc; 11423 11424 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, 11425 "Issue FDISC: did:x%x", 11426 did, 0, 0); 11427 11428 elsiocb->ndlp = lpfc_nlp_get(ndlp); 11429 if (!elsiocb->ndlp) 11430 goto err_out; 11431 11432 rc = lpfc_issue_fabric_iocb(phba, elsiocb); 11433 if (rc == IOCB_ERROR) { 11434 lpfc_nlp_put(ndlp); 11435 goto err_out; 11436 } 11437 11438 lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING); 11439 return 0; 11440 11441 err_out: 11442 lpfc_els_free_iocb(phba, elsiocb); 11443 lpfc_vport_set_state(vport, FC_VPORT_FAILED); 11444 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, 11445 "0256 Issue FDISC: Cannot send IOCB\n"); 11446 return 1; 11447 } 11448 11449 /** 11450 * lpfc_cmpl_els_npiv_logo - Completion function with vport logo 11451 * @phba: pointer to lpfc hba data structure. 11452 * @cmdiocb: pointer to lpfc command iocb data structure. 11453 * @rspiocb: pointer to lpfc response iocb data structure. 11454 * 11455 * This routine is the completion callback function to the issuing of a LOGO 11456 * ELS command off a vport. It frees the command IOCB and then decrement the 11457 * reference count held on ndlp for this completion function, indicating that 11458 * the reference to the ndlp is no long needed. Note that the 11459 * lpfc_els_free_iocb() routine decrements the ndlp reference held for this 11460 * callback function and an additional explicit ndlp reference decrementation 11461 * will trigger the actual release of the ndlp. 11462 **/ 11463 static void 11464 lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, 11465 struct lpfc_iocbq *rspiocb) 11466 { 11467 struct lpfc_vport *vport = cmdiocb->vport; 11468 IOCB_t *irsp; 11469 struct lpfc_nodelist *ndlp; 11470 u32 ulp_status, ulp_word4, did, tmo; 11471 11472 ndlp = cmdiocb->ndlp; 11473 11474 ulp_status = get_job_ulpstatus(phba, rspiocb); 11475 ulp_word4 = get_job_word4(phba, rspiocb); 11476 11477 if (phba->sli_rev == LPFC_SLI_REV4) { 11478 did = get_job_els_rsp64_did(phba, cmdiocb); 11479 tmo = get_wqe_tmo(cmdiocb); 11480 } else { 11481 irsp = &rspiocb->iocb; 11482 did = get_job_els_rsp64_did(phba, rspiocb); 11483 tmo = irsp->ulpTimeout; 11484 } 11485 11486 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, 11487 "LOGO npiv cmpl: status:x%x/x%x did:x%x", 11488 ulp_status, ulp_word4, did); 11489 11490 /* NPIV LOGO completes to NPort <nlp_DID> */ 11491 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, 11492 "2928 NPIV LOGO completes to NPort x%x " 11493 "Data: x%x x%x x%x x%x x%x x%lx x%x\n", 11494 ndlp->nlp_DID, ulp_status, ulp_word4, 11495 tmo, vport->num_disc_nodes, 11496 kref_read(&ndlp->kref), ndlp->nlp_flag, 11497 ndlp->fc4_xpt_flags); 11498 11499 if (ulp_status == IOSTAT_SUCCESS) { 11500 clear_bit(FC_NDISC_ACTIVE, &vport->fc_flag); 11501 clear_bit(FC_FABRIC, &vport->fc_flag); 11502 lpfc_can_disctmo(vport); 11503 } 11504 11505 if (test_bit(NLP_WAIT_FOR_LOGO, &ndlp->save_flags)) { 11506 /* Wake up lpfc_vport_delete if waiting...*/ 11507 if (ndlp->logo_waitq) 11508 wake_up(ndlp->logo_waitq); 11509 clear_bit(NLP_ISSUE_LOGO, &ndlp->nlp_flag); 11510 clear_bit(NLP_LOGO_SND, &ndlp->nlp_flag); 11511 clear_bit(NLP_WAIT_FOR_LOGO, &ndlp->save_flags); 11512 } 11513 11514 /* Safe to release resources now. */ 11515 lpfc_els_free_iocb(phba, cmdiocb); 11516 lpfc_nlp_put(ndlp); 11517 } 11518 11519 /** 11520 * lpfc_issue_els_npiv_logo - Issue a logo off a vport 11521 * @vport: pointer to a virtual N_Port data structure. 11522 * @ndlp: pointer to a node-list data structure. 11523 * 11524 * This routine issues a LOGO ELS command to an @ndlp off a @vport. 11525 * 11526 * Note that the ndlp reference count will be incremented by 1 for holding the 11527 * ndlp and the reference to ndlp will be stored into the ndlp field of 11528 * the IOCB for the completion callback function to the LOGO ELS command. 11529 * 11530 * Return codes 11531 * 0 - Successfully issued logo off the @vport 11532 * 1 - Failed to issue logo off the @vport 11533 **/ 11534 int 11535 lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) 11536 { 11537 int rc = 0; 11538 struct lpfc_hba *phba = vport->phba; 11539 struct lpfc_iocbq *elsiocb; 11540 uint8_t *pcmd; 11541 uint16_t cmdsize; 11542 11543 cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name); 11544 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID, 11545 ELS_CMD_LOGO); 11546 if (!elsiocb) 11547 return 1; 11548 11549 pcmd = (uint8_t *)elsiocb->cmd_dmabuf->virt; 11550 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO; 11551 pcmd += sizeof(uint32_t); 11552 11553 /* Fill in LOGO payload */ 11554 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID); 11555 pcmd += sizeof(uint32_t); 11556 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name)); 11557 11558 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, 11559 "Issue LOGO npiv did:x%x flg:x%lx", 11560 ndlp->nlp_DID, ndlp->nlp_flag, 0); 11561 11562 elsiocb->cmd_cmpl = lpfc_cmpl_els_npiv_logo; 11563 set_bit(NLP_LOGO_SND, &ndlp->nlp_flag); 11564 elsiocb->ndlp = lpfc_nlp_get(ndlp); 11565 if (!elsiocb->ndlp) { 11566 lpfc_els_free_iocb(phba, elsiocb); 11567 goto err; 11568 } 11569 11570 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); 11571 if (rc == IOCB_ERROR) { 11572 lpfc_els_free_iocb(phba, elsiocb); 11573 lpfc_nlp_put(ndlp); 11574 goto err; 11575 } 11576 return 0; 11577 11578 err: 11579 clear_bit(NLP_LOGO_SND, &ndlp->nlp_flag); 11580 return 1; 11581 } 11582 11583 /** 11584 * lpfc_fabric_block_timeout - Handler function to the fabric block timer 11585 * @t: timer context used to obtain the lpfc hba. 11586 * 11587 * This routine is invoked by the fabric iocb block timer after 11588 * timeout. It posts the fabric iocb block timeout event by setting the 11589 * WORKER_FABRIC_BLOCK_TMO bit to work port event bitmap and then invokes 11590 * lpfc_worker_wake_up() routine to wake up the worker thread. It is for 11591 * the worker thread to invoke the lpfc_unblock_fabric_iocbs() on the 11592 * posted event WORKER_FABRIC_BLOCK_TMO. 11593 **/ 11594 void 11595 lpfc_fabric_block_timeout(struct timer_list *t) 11596 { 11597 struct lpfc_hba *phba = from_timer(phba, t, fabric_block_timer); 11598 unsigned long iflags; 11599 uint32_t tmo_posted; 11600 11601 spin_lock_irqsave(&phba->pport->work_port_lock, iflags); 11602 tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO; 11603 if (!tmo_posted) 11604 phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO; 11605 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags); 11606 11607 if (!tmo_posted) 11608 lpfc_worker_wake_up(phba); 11609 return; 11610 } 11611 11612 /** 11613 * lpfc_resume_fabric_iocbs - Issue a fabric iocb from driver internal list 11614 * @phba: pointer to lpfc hba data structure. 11615 * 11616 * This routine issues one fabric iocb from the driver internal list to 11617 * the HBA. It first checks whether it's ready to issue one fabric iocb to 11618 * the HBA (whether there is no outstanding fabric iocb). If so, it shall 11619 * remove one pending fabric iocb from the driver internal list and invokes 11620 * lpfc_sli_issue_iocb() routine to send the fabric iocb to the HBA. 11621 **/ 11622 static void 11623 lpfc_resume_fabric_iocbs(struct lpfc_hba *phba) 11624 { 11625 struct lpfc_iocbq *iocb; 11626 unsigned long iflags; 11627 int ret; 11628 11629 repeat: 11630 iocb = NULL; 11631 spin_lock_irqsave(&phba->hbalock, iflags); 11632 /* Post any pending iocb to the SLI layer */ 11633 if (atomic_read(&phba->fabric_iocb_count) == 0) { 11634 list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb), 11635 list); 11636 if (iocb) 11637 /* Increment fabric iocb count to hold the position */ 11638 atomic_inc(&phba->fabric_iocb_count); 11639 } 11640 spin_unlock_irqrestore(&phba->hbalock, iflags); 11641 if (iocb) { 11642 iocb->fabric_cmd_cmpl = iocb->cmd_cmpl; 11643 iocb->cmd_cmpl = lpfc_cmpl_fabric_iocb; 11644 iocb->cmd_flag |= LPFC_IO_FABRIC; 11645 11646 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD, 11647 "Fabric sched1: ste:x%x", 11648 iocb->vport->port_state, 0, 0); 11649 11650 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0); 11651 11652 if (ret == IOCB_ERROR) { 11653 iocb->cmd_cmpl = iocb->fabric_cmd_cmpl; 11654 iocb->fabric_cmd_cmpl = NULL; 11655 iocb->cmd_flag &= ~LPFC_IO_FABRIC; 11656 set_job_ulpstatus(iocb, IOSTAT_LOCAL_REJECT); 11657 iocb->wcqe_cmpl.parameter = IOERR_SLI_ABORTED; 11658 iocb->cmd_cmpl(phba, iocb, iocb); 11659 11660 atomic_dec(&phba->fabric_iocb_count); 11661 goto repeat; 11662 } 11663 } 11664 } 11665 11666 /** 11667 * lpfc_unblock_fabric_iocbs - Unblock issuing fabric iocb command 11668 * @phba: pointer to lpfc hba data structure. 11669 * 11670 * This routine unblocks the issuing fabric iocb command. The function 11671 * will clear the fabric iocb block bit and then invoke the routine 11672 * lpfc_resume_fabric_iocbs() to issue one of the pending fabric iocb 11673 * from the driver internal fabric iocb list. 11674 **/ 11675 void 11676 lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba) 11677 { 11678 clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags); 11679 11680 lpfc_resume_fabric_iocbs(phba); 11681 return; 11682 } 11683 11684 /** 11685 * lpfc_block_fabric_iocbs - Block issuing fabric iocb command 11686 * @phba: pointer to lpfc hba data structure. 11687 * 11688 * This routine blocks the issuing fabric iocb for a specified amount of 11689 * time (currently 100 ms). This is done by set the fabric iocb block bit 11690 * and set up a timeout timer for 100ms. When the block bit is set, no more 11691 * fabric iocb will be issued out of the HBA. 11692 **/ 11693 static void 11694 lpfc_block_fabric_iocbs(struct lpfc_hba *phba) 11695 { 11696 int blocked; 11697 11698 blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags); 11699 /* Start a timer to unblock fabric iocbs after 100ms */ 11700 if (!blocked) 11701 mod_timer(&phba->fabric_block_timer, 11702 jiffies + msecs_to_jiffies(100)); 11703 11704 return; 11705 } 11706 11707 /** 11708 * lpfc_cmpl_fabric_iocb - Completion callback function for fabric iocb 11709 * @phba: pointer to lpfc hba data structure. 11710 * @cmdiocb: pointer to lpfc command iocb data structure. 11711 * @rspiocb: pointer to lpfc response iocb data structure. 11712 * 11713 * This routine is the callback function that is put to the fabric iocb's 11714 * callback function pointer (iocb->cmd_cmpl). The original iocb's callback 11715 * function pointer has been stored in iocb->fabric_cmd_cmpl. This callback 11716 * function first restores and invokes the original iocb's callback function 11717 * and then invokes the lpfc_resume_fabric_iocbs() routine to issue the next 11718 * fabric bound iocb from the driver internal fabric iocb list onto the wire. 11719 **/ 11720 static void 11721 lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, 11722 struct lpfc_iocbq *rspiocb) 11723 { 11724 struct ls_rjt stat; 11725 u32 ulp_status = get_job_ulpstatus(phba, rspiocb); 11726 u32 ulp_word4 = get_job_word4(phba, rspiocb); 11727 11728 WARN_ON((cmdiocb->cmd_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC); 11729 11730 switch (ulp_status) { 11731 case IOSTAT_NPORT_RJT: 11732 case IOSTAT_FABRIC_RJT: 11733 if (ulp_word4 & RJT_UNAVAIL_TEMP) 11734 lpfc_block_fabric_iocbs(phba); 11735 break; 11736 11737 case IOSTAT_NPORT_BSY: 11738 case IOSTAT_FABRIC_BSY: 11739 lpfc_block_fabric_iocbs(phba); 11740 break; 11741 11742 case IOSTAT_LS_RJT: 11743 stat.un.ls_rjt_error_be = 11744 cpu_to_be32(ulp_word4); 11745 if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) || 11746 (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY)) 11747 lpfc_block_fabric_iocbs(phba); 11748 break; 11749 } 11750 11751 BUG_ON(atomic_read(&phba->fabric_iocb_count) == 0); 11752 11753 cmdiocb->cmd_cmpl = cmdiocb->fabric_cmd_cmpl; 11754 cmdiocb->fabric_cmd_cmpl = NULL; 11755 cmdiocb->cmd_flag &= ~LPFC_IO_FABRIC; 11756 cmdiocb->cmd_cmpl(phba, cmdiocb, rspiocb); 11757 11758 atomic_dec(&phba->fabric_iocb_count); 11759 if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) { 11760 /* Post any pending iocbs to HBA */ 11761 lpfc_resume_fabric_iocbs(phba); 11762 } 11763 } 11764 11765 /** 11766 * lpfc_issue_fabric_iocb - Issue a fabric iocb command 11767 * @phba: pointer to lpfc hba data structure. 11768 * @iocb: pointer to lpfc command iocb data structure. 11769 * 11770 * This routine is used as the top-level API for issuing a fabric iocb command 11771 * such as FLOGI and FDISC. To accommodate certain switch fabric, this driver 11772 * function makes sure that only one fabric bound iocb will be outstanding at 11773 * any given time. As such, this function will first check to see whether there 11774 * is already an outstanding fabric iocb on the wire. If so, it will put the 11775 * newly issued iocb onto the driver internal fabric iocb list, waiting to be 11776 * issued later. Otherwise, it will issue the iocb on the wire and update the 11777 * fabric iocb count it indicate that there is one fabric iocb on the wire. 11778 * 11779 * Note, this implementation has a potential sending out fabric IOCBs out of 11780 * order. The problem is caused by the construction of the "ready" boolen does 11781 * not include the condition that the internal fabric IOCB list is empty. As 11782 * such, it is possible a fabric IOCB issued by this routine might be "jump" 11783 * ahead of the fabric IOCBs in the internal list. 11784 * 11785 * Return code 11786 * IOCB_SUCCESS - either fabric iocb put on the list or issued successfully 11787 * IOCB_ERROR - failed to issue fabric iocb 11788 **/ 11789 static int 11790 lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb) 11791 { 11792 unsigned long iflags; 11793 int ready; 11794 int ret; 11795 11796 BUG_ON(atomic_read(&phba->fabric_iocb_count) > 1); 11797 11798 spin_lock_irqsave(&phba->hbalock, iflags); 11799 ready = atomic_read(&phba->fabric_iocb_count) == 0 && 11800 !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags); 11801 11802 if (ready) 11803 /* Increment fabric iocb count to hold the position */ 11804 atomic_inc(&phba->fabric_iocb_count); 11805 spin_unlock_irqrestore(&phba->hbalock, iflags); 11806 if (ready) { 11807 iocb->fabric_cmd_cmpl = iocb->cmd_cmpl; 11808 iocb->cmd_cmpl = lpfc_cmpl_fabric_iocb; 11809 iocb->cmd_flag |= LPFC_IO_FABRIC; 11810 11811 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD, 11812 "Fabric sched2: ste:x%x", 11813 iocb->vport->port_state, 0, 0); 11814 11815 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0); 11816 11817 if (ret == IOCB_ERROR) { 11818 iocb->cmd_cmpl = iocb->fabric_cmd_cmpl; 11819 iocb->fabric_cmd_cmpl = NULL; 11820 iocb->cmd_flag &= ~LPFC_IO_FABRIC; 11821 atomic_dec(&phba->fabric_iocb_count); 11822 } 11823 } else { 11824 spin_lock_irqsave(&phba->hbalock, iflags); 11825 list_add_tail(&iocb->list, &phba->fabric_iocb_list); 11826 spin_unlock_irqrestore(&phba->hbalock, iflags); 11827 ret = IOCB_SUCCESS; 11828 } 11829 return ret; 11830 } 11831 11832 /** 11833 * lpfc_fabric_abort_vport - Abort a vport's iocbs from driver fabric iocb list 11834 * @vport: pointer to a virtual N_Port data structure. 11835 * 11836 * This routine aborts all the IOCBs associated with a @vport from the 11837 * driver internal fabric IOCB list. The list contains fabric IOCBs to be 11838 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB 11839 * list, removes each IOCB associated with the @vport off the list, set the 11840 * status field to IOSTAT_LOCAL_REJECT, and invokes the callback function 11841 * associated with the IOCB. 11842 **/ 11843 static void lpfc_fabric_abort_vport(struct lpfc_vport *vport) 11844 { 11845 LIST_HEAD(completions); 11846 struct lpfc_hba *phba = vport->phba; 11847 struct lpfc_iocbq *tmp_iocb, *piocb; 11848 11849 spin_lock_irq(&phba->hbalock); 11850 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list, 11851 list) { 11852 11853 if (piocb->vport != vport) 11854 continue; 11855 11856 list_move_tail(&piocb->list, &completions); 11857 } 11858 spin_unlock_irq(&phba->hbalock); 11859 11860 /* Cancel all the IOCBs from the completions list */ 11861 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, 11862 IOERR_SLI_ABORTED); 11863 } 11864 11865 /** 11866 * lpfc_fabric_abort_nport - Abort a ndlp's iocbs from driver fabric iocb list 11867 * @ndlp: pointer to a node-list data structure. 11868 * 11869 * This routine aborts all the IOCBs associated with an @ndlp from the 11870 * driver internal fabric IOCB list. The list contains fabric IOCBs to be 11871 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB 11872 * list, removes each IOCB associated with the @ndlp off the list, set the 11873 * status field to IOSTAT_LOCAL_REJECT, and invokes the callback function 11874 * associated with the IOCB. 11875 **/ 11876 void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp) 11877 { 11878 LIST_HEAD(completions); 11879 struct lpfc_hba *phba = ndlp->phba; 11880 struct lpfc_iocbq *tmp_iocb, *piocb; 11881 struct lpfc_sli_ring *pring; 11882 11883 pring = lpfc_phba_elsring(phba); 11884 11885 if (unlikely(!pring)) 11886 return; 11887 11888 spin_lock_irq(&phba->hbalock); 11889 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list, 11890 list) { 11891 if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) { 11892 11893 list_move_tail(&piocb->list, &completions); 11894 } 11895 } 11896 spin_unlock_irq(&phba->hbalock); 11897 11898 /* Cancel all the IOCBs from the completions list */ 11899 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, 11900 IOERR_SLI_ABORTED); 11901 } 11902 11903 /** 11904 * lpfc_fabric_abort_hba - Abort all iocbs on driver fabric iocb list 11905 * @phba: pointer to lpfc hba data structure. 11906 * 11907 * This routine aborts all the IOCBs currently on the driver internal 11908 * fabric IOCB list. The list contains fabric IOCBs to be issued to the ELS 11909 * IOCB ring. This function takes the entire IOCB list off the fabric IOCB 11910 * list, removes IOCBs off the list, set the status field to 11911 * IOSTAT_LOCAL_REJECT, and invokes the callback function associated with 11912 * the IOCB. 11913 **/ 11914 void lpfc_fabric_abort_hba(struct lpfc_hba *phba) 11915 { 11916 LIST_HEAD(completions); 11917 11918 spin_lock_irq(&phba->hbalock); 11919 list_splice_init(&phba->fabric_iocb_list, &completions); 11920 spin_unlock_irq(&phba->hbalock); 11921 11922 /* Cancel all the IOCBs from the completions list */ 11923 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, 11924 IOERR_SLI_ABORTED); 11925 } 11926 11927 /** 11928 * lpfc_sli4_vport_delete_els_xri_aborted -Remove all ndlp references for vport 11929 * @vport: pointer to lpfc vport data structure. 11930 * 11931 * This routine is invoked by the vport cleanup for deletions and the cleanup 11932 * for an ndlp on removal. 11933 **/ 11934 void 11935 lpfc_sli4_vport_delete_els_xri_aborted(struct lpfc_vport *vport) 11936 { 11937 struct lpfc_hba *phba = vport->phba; 11938 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL; 11939 struct lpfc_nodelist *ndlp = NULL; 11940 unsigned long iflag = 0; 11941 11942 spin_lock_irqsave(&phba->sli4_hba.sgl_list_lock, iflag); 11943 list_for_each_entry_safe(sglq_entry, sglq_next, 11944 &phba->sli4_hba.lpfc_abts_els_sgl_list, list) { 11945 if (sglq_entry->ndlp && sglq_entry->ndlp->vport == vport) { 11946 lpfc_nlp_put(sglq_entry->ndlp); 11947 ndlp = sglq_entry->ndlp; 11948 sglq_entry->ndlp = NULL; 11949 11950 /* If the xri on the abts_els_sgl list is for the Fport 11951 * node and the vport is unloading, the xri aborted wcqe 11952 * likely isn't coming back. Just release the sgl. 11953 */ 11954 if (test_bit(FC_UNLOADING, &vport->load_flag) && 11955 ndlp->nlp_DID == Fabric_DID) { 11956 list_del(&sglq_entry->list); 11957 sglq_entry->state = SGL_FREED; 11958 list_add_tail(&sglq_entry->list, 11959 &phba->sli4_hba.lpfc_els_sgl_list); 11960 } 11961 } 11962 } 11963 spin_unlock_irqrestore(&phba->sli4_hba.sgl_list_lock, iflag); 11964 return; 11965 } 11966 11967 /** 11968 * lpfc_sli4_els_xri_aborted - Slow-path process of els xri abort 11969 * @phba: pointer to lpfc hba data structure. 11970 * @axri: pointer to the els xri abort wcqe structure. 11971 * 11972 * This routine is invoked by the worker thread to process a SLI4 slow-path 11973 * ELS aborted xri. 11974 **/ 11975 void 11976 lpfc_sli4_els_xri_aborted(struct lpfc_hba *phba, 11977 struct sli4_wcqe_xri_aborted *axri) 11978 { 11979 uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri); 11980 uint16_t rxid = bf_get(lpfc_wcqe_xa_remote_xid, axri); 11981 uint16_t lxri = 0; 11982 11983 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL; 11984 unsigned long iflag = 0; 11985 struct lpfc_nodelist *ndlp; 11986 struct lpfc_sli_ring *pring; 11987 11988 pring = lpfc_phba_elsring(phba); 11989 11990 spin_lock_irqsave(&phba->sli4_hba.sgl_list_lock, iflag); 11991 list_for_each_entry_safe(sglq_entry, sglq_next, 11992 &phba->sli4_hba.lpfc_abts_els_sgl_list, list) { 11993 if (sglq_entry->sli4_xritag == xri) { 11994 list_del(&sglq_entry->list); 11995 ndlp = sglq_entry->ndlp; 11996 sglq_entry->ndlp = NULL; 11997 list_add_tail(&sglq_entry->list, 11998 &phba->sli4_hba.lpfc_els_sgl_list); 11999 sglq_entry->state = SGL_FREED; 12000 spin_unlock_irqrestore(&phba->sli4_hba.sgl_list_lock, 12001 iflag); 12002 12003 if (ndlp) { 12004 lpfc_set_rrq_active(phba, ndlp, 12005 sglq_entry->sli4_lxritag, 12006 rxid, 1); 12007 lpfc_nlp_put(ndlp); 12008 } 12009 12010 /* Check if TXQ queue needs to be serviced */ 12011 if (pring && !list_empty(&pring->txq)) 12012 lpfc_worker_wake_up(phba); 12013 return; 12014 } 12015 } 12016 spin_unlock_irqrestore(&phba->sli4_hba.sgl_list_lock, iflag); 12017 lxri = lpfc_sli4_xri_inrange(phba, xri); 12018 if (lxri == NO_XRI) 12019 return; 12020 12021 spin_lock_irqsave(&phba->hbalock, iflag); 12022 sglq_entry = __lpfc_get_active_sglq(phba, lxri); 12023 if (!sglq_entry || (sglq_entry->sli4_xritag != xri)) { 12024 spin_unlock_irqrestore(&phba->hbalock, iflag); 12025 return; 12026 } 12027 sglq_entry->state = SGL_XRI_ABORTED; 12028 spin_unlock_irqrestore(&phba->hbalock, iflag); 12029 return; 12030 } 12031 12032 /* lpfc_sli_abts_recover_port - Recover a port that failed a BLS_ABORT req. 12033 * @vport: pointer to virtual port object. 12034 * @ndlp: nodelist pointer for the impacted node. 12035 * 12036 * The driver calls this routine in response to an SLI4 XRI ABORT CQE 12037 * or an SLI3 ASYNC_STATUS_CN event from the port. For either event, 12038 * the driver is required to send a LOGO to the remote node before it 12039 * attempts to recover its login to the remote node. 12040 */ 12041 void 12042 lpfc_sli_abts_recover_port(struct lpfc_vport *vport, 12043 struct lpfc_nodelist *ndlp) 12044 { 12045 struct Scsi_Host *shost; 12046 struct lpfc_hba *phba; 12047 unsigned long flags = 0; 12048 12049 shost = lpfc_shost_from_vport(vport); 12050 phba = vport->phba; 12051 if (ndlp->nlp_state != NLP_STE_MAPPED_NODE) { 12052 lpfc_printf_log(phba, KERN_INFO, 12053 LOG_SLI, "3093 No rport recovery needed. " 12054 "rport in state 0x%x\n", ndlp->nlp_state); 12055 return; 12056 } 12057 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, 12058 "3094 Start rport recovery on shost id 0x%x " 12059 "fc_id 0x%06x vpi 0x%x rpi 0x%x state 0x%x " 12060 "flag 0x%lx\n", 12061 shost->host_no, ndlp->nlp_DID, 12062 vport->vpi, ndlp->nlp_rpi, ndlp->nlp_state, 12063 ndlp->nlp_flag); 12064 /* 12065 * The rport is not responding. Remove the FCP-2 flag to prevent 12066 * an ADISC in the follow-up recovery code. 12067 */ 12068 spin_lock_irqsave(&ndlp->lock, flags); 12069 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE; 12070 spin_unlock_irqrestore(&ndlp->lock, flags); 12071 set_bit(NLP_ISSUE_LOGO, &ndlp->nlp_flag); 12072 lpfc_unreg_rpi(vport, ndlp); 12073 } 12074 12075 static void lpfc_init_cs_ctl_bitmap(struct lpfc_vport *vport) 12076 { 12077 bitmap_zero(vport->vmid_priority_range, LPFC_VMID_MAX_PRIORITY_RANGE); 12078 } 12079 12080 static void 12081 lpfc_vmid_set_cs_ctl_range(struct lpfc_vport *vport, u32 min, u32 max) 12082 { 12083 u32 i; 12084 12085 if ((min > max) || (max > LPFC_VMID_MAX_PRIORITY_RANGE)) 12086 return; 12087 12088 for (i = min; i <= max; i++) 12089 set_bit(i, vport->vmid_priority_range); 12090 } 12091 12092 static void lpfc_vmid_put_cs_ctl(struct lpfc_vport *vport, u32 ctcl_vmid) 12093 { 12094 set_bit(ctcl_vmid, vport->vmid_priority_range); 12095 } 12096 12097 u32 lpfc_vmid_get_cs_ctl(struct lpfc_vport *vport) 12098 { 12099 u32 i; 12100 12101 i = find_first_bit(vport->vmid_priority_range, 12102 LPFC_VMID_MAX_PRIORITY_RANGE); 12103 12104 if (i == LPFC_VMID_MAX_PRIORITY_RANGE) 12105 return 0; 12106 12107 clear_bit(i, vport->vmid_priority_range); 12108 return i; 12109 } 12110 12111 #define MAX_PRIORITY_DESC 255 12112 12113 static void 12114 lpfc_cmpl_els_qfpa(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, 12115 struct lpfc_iocbq *rspiocb) 12116 { 12117 struct lpfc_vport *vport = cmdiocb->vport; 12118 struct priority_range_desc *desc; 12119 struct lpfc_dmabuf *prsp = NULL; 12120 struct lpfc_vmid_priority_range *vmid_range = NULL; 12121 u32 *data; 12122 struct lpfc_dmabuf *dmabuf = cmdiocb->cmd_dmabuf; 12123 u32 ulp_status = get_job_ulpstatus(phba, rspiocb); 12124 u32 ulp_word4 = get_job_word4(phba, rspiocb); 12125 u8 *pcmd, max_desc; 12126 u32 len, i; 12127 struct lpfc_nodelist *ndlp = cmdiocb->ndlp; 12128 12129 prsp = list_get_first(&dmabuf->list, struct lpfc_dmabuf, list); 12130 if (!prsp) 12131 goto out; 12132 12133 pcmd = prsp->virt; 12134 data = (u32 *)pcmd; 12135 if (data[0] == ELS_CMD_LS_RJT) { 12136 lpfc_printf_vlog(vport, KERN_WARNING, LOG_SLI, 12137 "3277 QFPA LS_RJT x%x x%x\n", 12138 data[0], data[1]); 12139 goto out; 12140 } 12141 if (ulp_status) { 12142 lpfc_printf_vlog(vport, KERN_ERR, LOG_SLI, 12143 "6529 QFPA failed with status x%x x%x\n", 12144 ulp_status, ulp_word4); 12145 goto out; 12146 } 12147 12148 if (!vport->qfpa_res) { 12149 max_desc = FCELSSIZE / sizeof(*vport->qfpa_res); 12150 vport->qfpa_res = kcalloc(max_desc, sizeof(*vport->qfpa_res), 12151 GFP_KERNEL); 12152 if (!vport->qfpa_res) 12153 goto out; 12154 } 12155 12156 len = *((u32 *)(pcmd + 4)); 12157 len = be32_to_cpu(len); 12158 memcpy(vport->qfpa_res, pcmd, len + 8); 12159 len = len / LPFC_PRIORITY_RANGE_DESC_SIZE; 12160 12161 desc = (struct priority_range_desc *)(pcmd + 8); 12162 vmid_range = vport->vmid_priority.vmid_range; 12163 if (!vmid_range) { 12164 vmid_range = kcalloc(MAX_PRIORITY_DESC, sizeof(*vmid_range), 12165 GFP_KERNEL); 12166 if (!vmid_range) { 12167 kfree(vport->qfpa_res); 12168 goto out; 12169 } 12170 vport->vmid_priority.vmid_range = vmid_range; 12171 } 12172 vport->vmid_priority.num_descriptors = len; 12173 12174 for (i = 0; i < len; i++, vmid_range++, desc++) { 12175 lpfc_printf_vlog(vport, KERN_DEBUG, LOG_ELS, 12176 "6539 vmid values low=%d, high=%d, qos=%d, " 12177 "local ve id=%d\n", desc->lo_range, 12178 desc->hi_range, desc->qos_priority, 12179 desc->local_ve_id); 12180 12181 vmid_range->low = desc->lo_range << 1; 12182 if (desc->local_ve_id == QFPA_ODD_ONLY) 12183 vmid_range->low++; 12184 if (desc->qos_priority) 12185 vport->vmid_flag |= LPFC_VMID_QOS_ENABLED; 12186 vmid_range->qos = desc->qos_priority; 12187 12188 vmid_range->high = desc->hi_range << 1; 12189 if ((desc->local_ve_id == QFPA_ODD_ONLY) || 12190 (desc->local_ve_id == QFPA_EVEN_ODD)) 12191 vmid_range->high++; 12192 } 12193 lpfc_init_cs_ctl_bitmap(vport); 12194 for (i = 0; i < vport->vmid_priority.num_descriptors; i++) { 12195 lpfc_vmid_set_cs_ctl_range(vport, 12196 vport->vmid_priority.vmid_range[i].low, 12197 vport->vmid_priority.vmid_range[i].high); 12198 } 12199 12200 vport->vmid_flag |= LPFC_VMID_QFPA_CMPL; 12201 out: 12202 lpfc_els_free_iocb(phba, cmdiocb); 12203 lpfc_nlp_put(ndlp); 12204 } 12205 12206 int lpfc_issue_els_qfpa(struct lpfc_vport *vport) 12207 { 12208 struct lpfc_hba *phba = vport->phba; 12209 struct lpfc_nodelist *ndlp; 12210 struct lpfc_iocbq *elsiocb; 12211 u8 *pcmd; 12212 int ret; 12213 12214 ndlp = lpfc_findnode_did(phba->pport, Fabric_DID); 12215 if (!ndlp || ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) 12216 return -ENXIO; 12217 12218 elsiocb = lpfc_prep_els_iocb(vport, 1, LPFC_QFPA_SIZE, 2, ndlp, 12219 ndlp->nlp_DID, ELS_CMD_QFPA); 12220 if (!elsiocb) 12221 return -ENOMEM; 12222 12223 pcmd = (u8 *)elsiocb->cmd_dmabuf->virt; 12224 12225 *((u32 *)(pcmd)) = ELS_CMD_QFPA; 12226 pcmd += 4; 12227 12228 elsiocb->cmd_cmpl = lpfc_cmpl_els_qfpa; 12229 12230 elsiocb->ndlp = lpfc_nlp_get(ndlp); 12231 if (!elsiocb->ndlp) { 12232 lpfc_els_free_iocb(vport->phba, elsiocb); 12233 return -ENXIO; 12234 } 12235 12236 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 2); 12237 if (ret != IOCB_SUCCESS) { 12238 lpfc_els_free_iocb(phba, elsiocb); 12239 lpfc_nlp_put(ndlp); 12240 return -EIO; 12241 } 12242 vport->vmid_flag &= ~LPFC_VMID_QOS_ENABLED; 12243 return 0; 12244 } 12245 12246 int 12247 lpfc_vmid_uvem(struct lpfc_vport *vport, 12248 struct lpfc_vmid *vmid, bool instantiated) 12249 { 12250 struct lpfc_vem_id_desc *vem_id_desc; 12251 struct lpfc_nodelist *ndlp; 12252 struct lpfc_iocbq *elsiocb; 12253 struct instantiated_ve_desc *inst_desc; 12254 struct lpfc_vmid_context *vmid_context; 12255 u8 *pcmd; 12256 u32 *len; 12257 int ret = 0; 12258 12259 ndlp = lpfc_findnode_did(vport, Fabric_DID); 12260 if (!ndlp || ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) 12261 return -ENXIO; 12262 12263 vmid_context = kmalloc(sizeof(*vmid_context), GFP_KERNEL); 12264 if (!vmid_context) 12265 return -ENOMEM; 12266 elsiocb = lpfc_prep_els_iocb(vport, 1, LPFC_UVEM_SIZE, 2, 12267 ndlp, Fabric_DID, ELS_CMD_UVEM); 12268 if (!elsiocb) 12269 goto out; 12270 12271 lpfc_printf_vlog(vport, KERN_DEBUG, LOG_ELS, 12272 "3427 Host vmid %s %d\n", 12273 vmid->host_vmid, instantiated); 12274 vmid_context->vmp = vmid; 12275 vmid_context->nlp = ndlp; 12276 vmid_context->instantiated = instantiated; 12277 elsiocb->vmid_tag.vmid_context = vmid_context; 12278 pcmd = (u8 *)elsiocb->cmd_dmabuf->virt; 12279 12280 if (!memchr_inv(vport->lpfc_vmid_host_uuid, 0, 12281 sizeof(vport->lpfc_vmid_host_uuid))) 12282 memcpy(vport->lpfc_vmid_host_uuid, vmid->host_vmid, 12283 sizeof(vport->lpfc_vmid_host_uuid)); 12284 12285 *((u32 *)(pcmd)) = ELS_CMD_UVEM; 12286 len = (u32 *)(pcmd + 4); 12287 *len = cpu_to_be32(LPFC_UVEM_SIZE - 8); 12288 12289 vem_id_desc = (struct lpfc_vem_id_desc *)(pcmd + 8); 12290 vem_id_desc->tag = be32_to_cpu(VEM_ID_DESC_TAG); 12291 vem_id_desc->length = be32_to_cpu(LPFC_UVEM_VEM_ID_DESC_SIZE); 12292 memcpy(vem_id_desc->vem_id, vport->lpfc_vmid_host_uuid, 12293 sizeof(vem_id_desc->vem_id)); 12294 12295 inst_desc = (struct instantiated_ve_desc *)(pcmd + 32); 12296 inst_desc->tag = be32_to_cpu(INSTANTIATED_VE_DESC_TAG); 12297 inst_desc->length = be32_to_cpu(LPFC_UVEM_VE_MAP_DESC_SIZE); 12298 memcpy(inst_desc->global_vem_id, vmid->host_vmid, 12299 sizeof(inst_desc->global_vem_id)); 12300 12301 bf_set(lpfc_instantiated_nport_id, inst_desc, vport->fc_myDID); 12302 bf_set(lpfc_instantiated_local_id, inst_desc, 12303 vmid->un.cs_ctl_vmid); 12304 if (instantiated) { 12305 inst_desc->tag = be32_to_cpu(INSTANTIATED_VE_DESC_TAG); 12306 } else { 12307 inst_desc->tag = be32_to_cpu(DEINSTANTIATED_VE_DESC_TAG); 12308 lpfc_vmid_put_cs_ctl(vport, vmid->un.cs_ctl_vmid); 12309 } 12310 inst_desc->word6 = cpu_to_be32(inst_desc->word6); 12311 12312 elsiocb->cmd_cmpl = lpfc_cmpl_els_uvem; 12313 12314 elsiocb->ndlp = lpfc_nlp_get(ndlp); 12315 if (!elsiocb->ndlp) { 12316 lpfc_els_free_iocb(vport->phba, elsiocb); 12317 goto out; 12318 } 12319 12320 ret = lpfc_sli_issue_iocb(vport->phba, LPFC_ELS_RING, elsiocb, 0); 12321 if (ret != IOCB_SUCCESS) { 12322 lpfc_els_free_iocb(vport->phba, elsiocb); 12323 lpfc_nlp_put(ndlp); 12324 goto out; 12325 } 12326 12327 return 0; 12328 out: 12329 kfree(vmid_context); 12330 return -EIO; 12331 } 12332 12333 static void 12334 lpfc_cmpl_els_uvem(struct lpfc_hba *phba, struct lpfc_iocbq *icmdiocb, 12335 struct lpfc_iocbq *rspiocb) 12336 { 12337 struct lpfc_vport *vport = icmdiocb->vport; 12338 struct lpfc_dmabuf *prsp = NULL; 12339 struct lpfc_vmid_context *vmid_context = 12340 icmdiocb->vmid_tag.vmid_context; 12341 struct lpfc_nodelist *ndlp = icmdiocb->ndlp; 12342 u8 *pcmd; 12343 u32 *data; 12344 u32 ulp_status = get_job_ulpstatus(phba, rspiocb); 12345 u32 ulp_word4 = get_job_word4(phba, rspiocb); 12346 struct lpfc_dmabuf *dmabuf = icmdiocb->cmd_dmabuf; 12347 struct lpfc_vmid *vmid; 12348 12349 vmid = vmid_context->vmp; 12350 if (!ndlp || ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) 12351 ndlp = NULL; 12352 12353 prsp = list_get_first(&dmabuf->list, struct lpfc_dmabuf, list); 12354 if (!prsp) 12355 goto out; 12356 pcmd = prsp->virt; 12357 data = (u32 *)pcmd; 12358 if (data[0] == ELS_CMD_LS_RJT) { 12359 lpfc_printf_vlog(vport, KERN_WARNING, LOG_SLI, 12360 "4532 UVEM LS_RJT %x %x\n", data[0], data[1]); 12361 goto out; 12362 } 12363 if (ulp_status) { 12364 lpfc_printf_vlog(vport, KERN_WARNING, LOG_SLI, 12365 "4533 UVEM error status %x: %x\n", 12366 ulp_status, ulp_word4); 12367 goto out; 12368 } 12369 spin_lock(&phba->hbalock); 12370 /* Set IN USE flag */ 12371 vport->vmid_flag |= LPFC_VMID_IN_USE; 12372 phba->pport->vmid_flag |= LPFC_VMID_IN_USE; 12373 spin_unlock(&phba->hbalock); 12374 12375 if (vmid_context->instantiated) { 12376 write_lock(&vport->vmid_lock); 12377 vmid->flag |= LPFC_VMID_REGISTERED; 12378 vmid->flag &= ~LPFC_VMID_REQ_REGISTER; 12379 write_unlock(&vport->vmid_lock); 12380 } 12381 12382 out: 12383 kfree(vmid_context); 12384 lpfc_els_free_iocb(phba, icmdiocb); 12385 lpfc_nlp_put(ndlp); 12386 } 12387