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 = timer_container_of(ndlp, t, 4382 nlp_delayfunc); 4383 struct lpfc_vport *vport = ndlp->vport; 4384 struct lpfc_hba *phba = vport->phba; 4385 unsigned long flags; 4386 struct lpfc_work_evt *evtp = &ndlp->els_retry_evt; 4387 4388 /* Hold a node reference for outstanding queued work */ 4389 if (!lpfc_nlp_get(ndlp)) 4390 return; 4391 4392 spin_lock_irqsave(&phba->hbalock, flags); 4393 if (!list_empty(&evtp->evt_listp)) { 4394 spin_unlock_irqrestore(&phba->hbalock, flags); 4395 lpfc_nlp_put(ndlp); 4396 return; 4397 } 4398 4399 evtp->evt_arg1 = ndlp; 4400 evtp->evt = LPFC_EVT_ELS_RETRY; 4401 list_add_tail(&evtp->evt_listp, &phba->work_list); 4402 spin_unlock_irqrestore(&phba->hbalock, flags); 4403 4404 lpfc_worker_wake_up(phba); 4405 } 4406 4407 /** 4408 * lpfc_els_retry_delay_handler - Work thread handler for ndlp delayed function 4409 * @ndlp: pointer to a node-list data structure. 4410 * 4411 * This routine is the worker-thread handler for processing the @ndlp delayed 4412 * event(s), posted by the lpfc_els_retry_delay() routine. It simply retrieves 4413 * the last ELS command from the associated ndlp and invokes the proper ELS 4414 * function according to the delayed ELS command to retry the command. 4415 **/ 4416 void 4417 lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp) 4418 { 4419 struct lpfc_vport *vport = ndlp->vport; 4420 uint32_t cmd, retry; 4421 4422 spin_lock_irq(&ndlp->lock); 4423 cmd = ndlp->nlp_last_elscmd; 4424 ndlp->nlp_last_elscmd = 0; 4425 spin_unlock_irq(&ndlp->lock); 4426 4427 if (!test_and_clear_bit(NLP_DELAY_TMO, &ndlp->nlp_flag)) 4428 return; 4429 4430 /* 4431 * If a discovery event readded nlp_delayfunc after timer 4432 * firing and before processing the timer, cancel the 4433 * nlp_delayfunc. 4434 */ 4435 timer_delete_sync(&ndlp->nlp_delayfunc); 4436 retry = ndlp->nlp_retry; 4437 ndlp->nlp_retry = 0; 4438 4439 switch (cmd) { 4440 case ELS_CMD_FLOGI: 4441 lpfc_issue_els_flogi(vport, ndlp, retry); 4442 break; 4443 case ELS_CMD_PLOGI: 4444 if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) { 4445 ndlp->nlp_prev_state = ndlp->nlp_state; 4446 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); 4447 } 4448 break; 4449 case ELS_CMD_ADISC: 4450 if (!lpfc_issue_els_adisc(vport, ndlp, retry)) { 4451 ndlp->nlp_prev_state = ndlp->nlp_state; 4452 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE); 4453 } 4454 break; 4455 case ELS_CMD_PRLI: 4456 case ELS_CMD_NVMEPRLI: 4457 if (!lpfc_issue_els_prli(vport, ndlp, retry)) { 4458 ndlp->nlp_prev_state = ndlp->nlp_state; 4459 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE); 4460 } 4461 break; 4462 case ELS_CMD_LOGO: 4463 if (!lpfc_issue_els_logo(vport, ndlp, retry)) { 4464 ndlp->nlp_prev_state = ndlp->nlp_state; 4465 lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE); 4466 } 4467 break; 4468 case ELS_CMD_FDISC: 4469 if (!test_bit(FC_VPORT_NEEDS_INIT_VPI, &vport->fc_flag)) 4470 lpfc_issue_els_fdisc(vport, ndlp, retry); 4471 break; 4472 } 4473 return; 4474 } 4475 4476 /** 4477 * lpfc_link_reset - Issue link reset 4478 * @vport: pointer to a virtual N_Port data structure. 4479 * 4480 * This routine performs link reset by sending INIT_LINK mailbox command. 4481 * For SLI-3 adapter, link attention interrupt is enabled before issuing 4482 * INIT_LINK mailbox command. 4483 * 4484 * Return code 4485 * 0 - Link reset initiated successfully 4486 * 1 - Failed to initiate link reset 4487 **/ 4488 int 4489 lpfc_link_reset(struct lpfc_vport *vport) 4490 { 4491 struct lpfc_hba *phba = vport->phba; 4492 LPFC_MBOXQ_t *mbox; 4493 uint32_t control; 4494 int rc; 4495 4496 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, 4497 "2851 Attempt link reset\n"); 4498 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); 4499 if (!mbox) { 4500 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, 4501 "2852 Failed to allocate mbox memory"); 4502 return 1; 4503 } 4504 4505 /* Enable Link attention interrupts */ 4506 if (phba->sli_rev <= LPFC_SLI_REV3) { 4507 spin_lock_irq(&phba->hbalock); 4508 phba->sli.sli_flag |= LPFC_PROCESS_LA; 4509 control = readl(phba->HCregaddr); 4510 control |= HC_LAINT_ENA; 4511 writel(control, phba->HCregaddr); 4512 readl(phba->HCregaddr); /* flush */ 4513 spin_unlock_irq(&phba->hbalock); 4514 } 4515 4516 lpfc_init_link(phba, mbox, phba->cfg_topology, 4517 phba->cfg_link_speed); 4518 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; 4519 mbox->vport = vport; 4520 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); 4521 if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) { 4522 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, 4523 "2853 Failed to issue INIT_LINK " 4524 "mbox command, rc:x%x\n", rc); 4525 mempool_free(mbox, phba->mbox_mem_pool); 4526 return 1; 4527 } 4528 4529 return 0; 4530 } 4531 4532 /** 4533 * lpfc_els_retry - Make retry decision on an els command iocb 4534 * @phba: pointer to lpfc hba data structure. 4535 * @cmdiocb: pointer to lpfc command iocb data structure. 4536 * @rspiocb: pointer to lpfc response iocb data structure. 4537 * 4538 * This routine makes a retry decision on an ELS command IOCB, which has 4539 * failed. The following ELS IOCBs use this function for retrying the command 4540 * when previously issued command responsed with error status: FLOGI, PLOGI, 4541 * PRLI, ADISC and FDISC. Based on the ELS command type and the 4542 * returned error status, it makes the decision whether a retry shall be 4543 * issued for the command, and whether a retry shall be made immediately or 4544 * delayed. In the former case, the corresponding ELS command issuing-function 4545 * is called to retry the command. In the later case, the ELS command shall 4546 * be posted to the ndlp delayed event and delayed function timer set to the 4547 * ndlp for the delayed command issusing. 4548 * 4549 * Return code 4550 * 0 - No retry of els command is made 4551 * 1 - Immediate or delayed retry of els command is made 4552 **/ 4553 static int 4554 lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, 4555 struct lpfc_iocbq *rspiocb) 4556 { 4557 struct lpfc_vport *vport = cmdiocb->vport; 4558 union lpfc_wqe128 *irsp = &rspiocb->wqe; 4559 struct lpfc_nodelist *ndlp = cmdiocb->ndlp; 4560 struct lpfc_dmabuf *pcmd = cmdiocb->cmd_dmabuf; 4561 uint32_t *elscmd; 4562 struct ls_rjt stat; 4563 int retry = 0, maxretry = lpfc_max_els_tries, delay = 0; 4564 int logerr = 0; 4565 uint32_t cmd = 0; 4566 uint32_t did; 4567 int link_reset = 0, rc; 4568 u32 ulp_status = get_job_ulpstatus(phba, rspiocb); 4569 u32 ulp_word4 = get_job_word4(phba, rspiocb); 4570 u8 rsn_code_exp = 0; 4571 4572 4573 /* Note: cmd_dmabuf may be 0 for internal driver abort 4574 * of delays ELS command. 4575 */ 4576 4577 if (pcmd && pcmd->virt) { 4578 elscmd = (uint32_t *) (pcmd->virt); 4579 cmd = *elscmd++; 4580 } 4581 4582 if (ndlp) 4583 did = ndlp->nlp_DID; 4584 else { 4585 /* We should only hit this case for retrying PLOGI */ 4586 did = get_job_els_rsp64_did(phba, rspiocb); 4587 ndlp = lpfc_findnode_did(vport, did); 4588 if (!ndlp && (cmd != ELS_CMD_PLOGI)) 4589 return 0; 4590 } 4591 4592 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, 4593 "Retry ELS: wd7:x%x wd4:x%x did:x%x", 4594 *(((uint32_t *)irsp) + 7), ulp_word4, did); 4595 4596 switch (ulp_status) { 4597 case IOSTAT_FCP_RSP_ERROR: 4598 break; 4599 case IOSTAT_REMOTE_STOP: 4600 if (phba->sli_rev == LPFC_SLI_REV4) { 4601 /* This IO was aborted by the target, we don't 4602 * know the rxid and because we did not send the 4603 * ABTS we cannot generate and RRQ. 4604 */ 4605 lpfc_set_rrq_active(phba, ndlp, 4606 cmdiocb->sli4_lxritag, 0, 0); 4607 } 4608 break; 4609 case IOSTAT_LOCAL_REJECT: 4610 switch ((ulp_word4 & IOERR_PARAM_MASK)) { 4611 case IOERR_LOOP_OPEN_FAILURE: 4612 if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0) 4613 delay = 1000; 4614 retry = 1; 4615 break; 4616 4617 case IOERR_ILLEGAL_COMMAND: 4618 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, 4619 "0124 Retry illegal cmd x%x " 4620 "retry:x%x delay:x%x\n", 4621 cmd, cmdiocb->retry, delay); 4622 retry = 1; 4623 /* All command's retry policy */ 4624 maxretry = 8; 4625 if (cmdiocb->retry > 2) 4626 delay = 1000; 4627 break; 4628 4629 case IOERR_NO_RESOURCES: 4630 logerr = 1; /* HBA out of resources */ 4631 retry = 1; 4632 if (cmdiocb->retry > 100) 4633 delay = 100; 4634 maxretry = 250; 4635 break; 4636 4637 case IOERR_ILLEGAL_FRAME: 4638 delay = 100; 4639 retry = 1; 4640 break; 4641 4642 case IOERR_INVALID_RPI: 4643 if (cmd == ELS_CMD_PLOGI && 4644 did == NameServer_DID) { 4645 /* Continue forever if plogi to */ 4646 /* the nameserver fails */ 4647 maxretry = 0; 4648 delay = 100; 4649 } else if (cmd == ELS_CMD_PRLI && 4650 ndlp->nlp_state != NLP_STE_PRLI_ISSUE) { 4651 /* State-command disagreement. The PRLI was 4652 * failed with an invalid rpi meaning there 4653 * some unexpected state change. Don't retry. 4654 */ 4655 maxretry = 0; 4656 retry = 0; 4657 break; 4658 } 4659 retry = 1; 4660 break; 4661 4662 case IOERR_SEQUENCE_TIMEOUT: 4663 if (cmd == ELS_CMD_PLOGI && 4664 did == NameServer_DID && 4665 (cmdiocb->retry + 1) == maxretry) { 4666 /* Reset the Link */ 4667 link_reset = 1; 4668 break; 4669 } 4670 retry = 1; 4671 delay = 100; 4672 break; 4673 case IOERR_SLI_ABORTED: 4674 /* Retry ELS PLOGI command? 4675 * Possibly the rport just wasn't ready. 4676 */ 4677 if (cmd == ELS_CMD_PLOGI) { 4678 /* No retry if state change */ 4679 if (ndlp && 4680 ndlp->nlp_state != NLP_STE_PLOGI_ISSUE) 4681 goto out_retry; 4682 retry = 1; 4683 maxretry = 2; 4684 } 4685 break; 4686 } 4687 break; 4688 4689 case IOSTAT_NPORT_RJT: 4690 case IOSTAT_FABRIC_RJT: 4691 if (ulp_word4 & RJT_UNAVAIL_TEMP) { 4692 retry = 1; 4693 break; 4694 } 4695 break; 4696 4697 case IOSTAT_NPORT_BSY: 4698 case IOSTAT_FABRIC_BSY: 4699 logerr = 1; /* Fabric / Remote NPort out of resources */ 4700 retry = 1; 4701 break; 4702 4703 case IOSTAT_LS_RJT: 4704 stat.un.ls_rjt_error_be = cpu_to_be32(ulp_word4); 4705 /* Added for Vendor specifc support 4706 * Just keep retrying for these Rsn / Exp codes 4707 */ 4708 if (test_bit(FC_PT2PT, &vport->fc_flag) && 4709 cmd == ELS_CMD_NVMEPRLI) { 4710 switch (stat.un.b.lsRjtRsnCode) { 4711 case LSRJT_UNABLE_TPC: 4712 case LSRJT_INVALID_CMD: 4713 case LSRJT_LOGICAL_ERR: 4714 case LSRJT_CMD_UNSUPPORTED: 4715 lpfc_printf_vlog(vport, KERN_WARNING, LOG_ELS, 4716 "0168 NVME PRLI LS_RJT " 4717 "reason %x port doesn't " 4718 "support NVME, disabling NVME\n", 4719 stat.un.b.lsRjtRsnCode); 4720 retry = 0; 4721 set_bit(FC_PT2PT_NO_NVME, &vport->fc_flag); 4722 goto out_retry; 4723 } 4724 } 4725 switch (stat.un.b.lsRjtRsnCode) { 4726 case LSRJT_UNABLE_TPC: 4727 /* Special case for PRLI LS_RJTs. Recall that lpfc 4728 * uses a single routine to issue both PRLI FC4 types. 4729 * If the PRLI is rejected because that FC4 type 4730 * isn't really supported, don't retry and cause 4731 * multiple transport registrations. Otherwise, parse 4732 * the reason code/reason code explanation and take the 4733 * appropriate action. 4734 */ 4735 lpfc_printf_vlog(vport, KERN_INFO, 4736 LOG_DISCOVERY | LOG_ELS | LOG_NODE, 4737 "0153 ELS cmd x%x LS_RJT by x%x. " 4738 "RsnCode x%x RsnCodeExp x%x\n", 4739 cmd, did, stat.un.b.lsRjtRsnCode, 4740 stat.un.b.lsRjtRsnCodeExp); 4741 4742 switch (stat.un.b.lsRjtRsnCodeExp) { 4743 case LSEXP_CANT_GIVE_DATA: 4744 case LSEXP_CMD_IN_PROGRESS: 4745 if (cmd == ELS_CMD_PLOGI) { 4746 delay = 1000; 4747 maxretry = 48; 4748 } 4749 retry = 1; 4750 break; 4751 case LSEXP_REQ_UNSUPPORTED: 4752 case LSEXP_NO_RSRC_ASSIGN: 4753 /* These explanation codes get no retry. */ 4754 if (cmd == ELS_CMD_PRLI || 4755 cmd == ELS_CMD_NVMEPRLI) 4756 break; 4757 fallthrough; 4758 default: 4759 /* Limit the delay and retry action to a limited 4760 * cmd set. There are other ELS commands where 4761 * a retry is not expected. 4762 */ 4763 if (cmd == ELS_CMD_PLOGI || 4764 cmd == ELS_CMD_PRLI || 4765 cmd == ELS_CMD_NVMEPRLI) { 4766 delay = 1000; 4767 maxretry = lpfc_max_els_tries + 1; 4768 retry = 1; 4769 } 4770 break; 4771 } 4772 4773 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && 4774 (cmd == ELS_CMD_FDISC) && 4775 (stat.un.b.lsRjtRsnCodeExp == LSEXP_OUT_OF_RESOURCE)){ 4776 lpfc_vlog_msg(vport, KERN_WARNING, LOG_ELS, 4777 "0125 FDISC (x%x). " 4778 "Fabric out of resources\n", 4779 stat.un.lsRjtError); 4780 lpfc_vport_set_state(vport, 4781 FC_VPORT_NO_FABRIC_RSCS); 4782 } 4783 break; 4784 4785 case LSRJT_LOGICAL_BSY: 4786 rsn_code_exp = stat.un.b.lsRjtRsnCodeExp; 4787 if ((cmd == ELS_CMD_PLOGI) || 4788 (cmd == ELS_CMD_PRLI) || 4789 (cmd == ELS_CMD_NVMEPRLI)) { 4790 delay = 1000; 4791 maxretry = 48; 4792 4793 /* An authentication LS_RJT reason code 4794 * explanation means some error in the 4795 * security settings end-to-end. Reduce 4796 * the retry count to allow lpfc to clear 4797 * RSCN mode and not race with dev_loss. 4798 */ 4799 if (cmd == ELS_CMD_PLOGI && 4800 rsn_code_exp == LSEXP_AUTH_REQ) 4801 maxretry = 8; 4802 } else if (cmd == ELS_CMD_FDISC) { 4803 /* FDISC retry policy */ 4804 maxretry = 48; 4805 if (cmdiocb->retry >= 32) 4806 delay = 1000; 4807 } 4808 retry = 1; 4809 break; 4810 4811 case LSRJT_LOGICAL_ERR: 4812 /* There are some cases where switches return this 4813 * error when they are not ready and should be returning 4814 * Logical Busy. We should delay every time. 4815 */ 4816 if (cmd == ELS_CMD_FDISC && 4817 stat.un.b.lsRjtRsnCodeExp == LSEXP_PORT_LOGIN_REQ) { 4818 maxretry = 3; 4819 delay = 1000; 4820 retry = 1; 4821 } else if (cmd == ELS_CMD_FLOGI && 4822 stat.un.b.lsRjtRsnCodeExp == 4823 LSEXP_NOTHING_MORE) { 4824 vport->fc_sparam.cmn.bbRcvSizeMsb &= 0xf; 4825 retry = 1; 4826 lpfc_vlog_msg(vport, KERN_WARNING, LOG_ELS, 4827 "0820 FLOGI (x%x). " 4828 "BBCredit Not Supported\n", 4829 stat.un.lsRjtError); 4830 } else if (cmd == ELS_CMD_PLOGI) { 4831 rsn_code_exp = stat.un.b.lsRjtRsnCodeExp; 4832 4833 /* An authentication LS_RJT reason code 4834 * explanation means some error in the 4835 * security settings end-to-end. Reduce 4836 * the retry count to allow lpfc to clear 4837 * RSCN mode and not race with dev_loss. 4838 */ 4839 if (rsn_code_exp == LSEXP_AUTH_REQ) { 4840 delay = 1000; 4841 retry = 1; 4842 maxretry = 8; 4843 } 4844 } 4845 break; 4846 4847 case LSRJT_PROTOCOL_ERR: 4848 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && 4849 (cmd == ELS_CMD_FDISC) && 4850 ((stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_PNAME) || 4851 (stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_NPORT_ID)) 4852 ) { 4853 lpfc_vlog_msg(vport, KERN_WARNING, LOG_ELS, 4854 "0122 FDISC (x%x). " 4855 "Fabric Detected Bad WWN\n", 4856 stat.un.lsRjtError); 4857 lpfc_vport_set_state(vport, 4858 FC_VPORT_FABRIC_REJ_WWN); 4859 } 4860 break; 4861 case LSRJT_VENDOR_UNIQUE: 4862 if ((stat.un.b.vendorUnique == 0x45) && 4863 (cmd == ELS_CMD_FLOGI)) { 4864 goto out_retry; 4865 } 4866 break; 4867 case LSRJT_CMD_UNSUPPORTED: 4868 /* lpfc nvmet returns this type of LS_RJT when it 4869 * receives an FCP PRLI because lpfc nvmet only 4870 * support NVME. ELS request is terminated for FCP4 4871 * on this rport. 4872 */ 4873 if (stat.un.b.lsRjtRsnCodeExp == 4874 LSEXP_REQ_UNSUPPORTED) { 4875 if (cmd == ELS_CMD_PRLI) 4876 goto out_retry; 4877 } 4878 break; 4879 } 4880 break; 4881 4882 case IOSTAT_INTERMED_RSP: 4883 case IOSTAT_BA_RJT: 4884 break; 4885 4886 default: 4887 break; 4888 } 4889 4890 if (link_reset) { 4891 rc = lpfc_link_reset(vport); 4892 if (rc) { 4893 /* Do not give up. Retry PLOGI one more time and attempt 4894 * link reset if PLOGI fails again. 4895 */ 4896 retry = 1; 4897 delay = 100; 4898 goto out_retry; 4899 } 4900 return 1; 4901 } 4902 4903 if (did == FDMI_DID) 4904 retry = 1; 4905 4906 if ((cmd == ELS_CMD_FLOGI) && 4907 (phba->fc_topology != LPFC_TOPOLOGY_LOOP) && 4908 !lpfc_error_lost_link(vport, ulp_status, ulp_word4)) { 4909 /* FLOGI retry policy */ 4910 retry = 1; 4911 /* retry FLOGI forever */ 4912 if (phba->link_flag != LS_LOOPBACK_MODE) 4913 maxretry = 0; 4914 else 4915 maxretry = 2; 4916 4917 if (cmdiocb->retry >= 100) 4918 delay = 5000; 4919 else if (cmdiocb->retry >= 32) 4920 delay = 1000; 4921 } else if ((cmd == ELS_CMD_FDISC) && 4922 !lpfc_error_lost_link(vport, ulp_status, ulp_word4)) { 4923 /* retry FDISCs every second up to devloss */ 4924 retry = 1; 4925 maxretry = vport->cfg_devloss_tmo; 4926 delay = 1000; 4927 } 4928 4929 cmdiocb->retry++; 4930 if (maxretry && (cmdiocb->retry >= maxretry)) { 4931 phba->fc_stat.elsRetryExceeded++; 4932 retry = 0; 4933 } 4934 4935 if (test_bit(FC_UNLOADING, &vport->load_flag)) 4936 retry = 0; 4937 4938 out_retry: 4939 if (retry) { 4940 if ((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_FDISC)) { 4941 /* Stop retrying PLOGI and FDISC if in FCF discovery */ 4942 if (phba->fcf.fcf_flag & FCF_DISCOVERY) { 4943 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, 4944 "2849 Stop retry ELS command " 4945 "x%x to remote NPORT x%x, " 4946 "Data: x%x x%x\n", cmd, did, 4947 cmdiocb->retry, delay); 4948 return 0; 4949 } 4950 } 4951 4952 /* Retry ELS command <elsCmd> to remote NPORT <did> */ 4953 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, 4954 "0107 Retry ELS command x%x to remote " 4955 "NPORT x%x Data: x%x x%x\n", 4956 cmd, did, cmdiocb->retry, delay); 4957 4958 if (((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) && 4959 ((ulp_status != IOSTAT_LOCAL_REJECT) || 4960 ((ulp_word4 & IOERR_PARAM_MASK) != 4961 IOERR_NO_RESOURCES))) { 4962 /* Don't reset timer for no resources */ 4963 4964 /* If discovery / RSCN timer is running, reset it */ 4965 if (timer_pending(&vport->fc_disctmo) || 4966 test_bit(FC_RSCN_MODE, &vport->fc_flag)) 4967 lpfc_set_disctmo(vport); 4968 } 4969 4970 phba->fc_stat.elsXmitRetry++; 4971 if (ndlp && delay) { 4972 phba->fc_stat.elsDelayRetry++; 4973 ndlp->nlp_retry = cmdiocb->retry; 4974 4975 /* delay is specified in milliseconds */ 4976 mod_timer(&ndlp->nlp_delayfunc, 4977 jiffies + msecs_to_jiffies(delay)); 4978 set_bit(NLP_DELAY_TMO, &ndlp->nlp_flag); 4979 4980 ndlp->nlp_prev_state = ndlp->nlp_state; 4981 if ((cmd == ELS_CMD_PRLI) || 4982 (cmd == ELS_CMD_NVMEPRLI)) 4983 lpfc_nlp_set_state(vport, ndlp, 4984 NLP_STE_PRLI_ISSUE); 4985 else if (cmd != ELS_CMD_ADISC) 4986 lpfc_nlp_set_state(vport, ndlp, 4987 NLP_STE_NPR_NODE); 4988 ndlp->nlp_last_elscmd = cmd; 4989 4990 return 1; 4991 } 4992 switch (cmd) { 4993 case ELS_CMD_FLOGI: 4994 lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry); 4995 return 1; 4996 case ELS_CMD_FDISC: 4997 lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry); 4998 return 1; 4999 case ELS_CMD_PLOGI: 5000 if (ndlp) { 5001 ndlp->nlp_prev_state = ndlp->nlp_state; 5002 lpfc_nlp_set_state(vport, ndlp, 5003 NLP_STE_PLOGI_ISSUE); 5004 } 5005 lpfc_issue_els_plogi(vport, did, cmdiocb->retry); 5006 return 1; 5007 case ELS_CMD_ADISC: 5008 ndlp->nlp_prev_state = ndlp->nlp_state; 5009 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE); 5010 lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry); 5011 return 1; 5012 case ELS_CMD_PRLI: 5013 case ELS_CMD_NVMEPRLI: 5014 ndlp->nlp_prev_state = ndlp->nlp_state; 5015 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE); 5016 lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry); 5017 return 1; 5018 case ELS_CMD_LOGO: 5019 ndlp->nlp_prev_state = ndlp->nlp_state; 5020 lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE); 5021 lpfc_issue_els_logo(vport, ndlp, cmdiocb->retry); 5022 return 1; 5023 } 5024 } 5025 /* No retry ELS command <elsCmd> to remote NPORT <did> */ 5026 if (logerr) { 5027 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, 5028 "0137 No retry ELS command x%x to remote " 5029 "NPORT x%x: Out of Resources: Error:x%x/%x " 5030 "IoTag x%x\n", 5031 cmd, did, ulp_status, ulp_word4, 5032 cmdiocb->iotag); 5033 } 5034 else { 5035 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, 5036 "0108 No retry ELS command x%x to remote " 5037 "NPORT x%x Retried:%d Error:x%x/%x " 5038 "IoTag x%x nflags x%lx\n", 5039 cmd, did, cmdiocb->retry, ulp_status, 5040 ulp_word4, cmdiocb->iotag, 5041 (ndlp ? ndlp->nlp_flag : 0)); 5042 } 5043 return 0; 5044 } 5045 5046 /** 5047 * lpfc_els_free_data - Free lpfc dma buffer and data structure with an iocb 5048 * @phba: pointer to lpfc hba data structure. 5049 * @buf_ptr1: pointer to the lpfc DMA buffer data structure. 5050 * 5051 * This routine releases the lpfc DMA (Direct Memory Access) buffer(s) 5052 * associated with a command IOCB back to the lpfc DMA buffer pool. It first 5053 * checks to see whether there is a lpfc DMA buffer associated with the 5054 * response of the command IOCB. If so, it will be released before releasing 5055 * the lpfc DMA buffer associated with the IOCB itself. 5056 * 5057 * Return code 5058 * 0 - Successfully released lpfc DMA buffer (currently, always return 0) 5059 **/ 5060 static int 5061 lpfc_els_free_data(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr1) 5062 { 5063 struct lpfc_dmabuf *buf_ptr; 5064 5065 /* Free the response before processing the command. */ 5066 if (!list_empty(&buf_ptr1->list)) { 5067 list_remove_head(&buf_ptr1->list, buf_ptr, 5068 struct lpfc_dmabuf, 5069 list); 5070 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); 5071 kfree(buf_ptr); 5072 } 5073 lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys); 5074 kfree(buf_ptr1); 5075 return 0; 5076 } 5077 5078 /** 5079 * lpfc_els_free_bpl - Free lpfc dma buffer and data structure with bpl 5080 * @phba: pointer to lpfc hba data structure. 5081 * @buf_ptr: pointer to the lpfc dma buffer data structure. 5082 * 5083 * This routine releases the lpfc Direct Memory Access (DMA) buffer 5084 * associated with a Buffer Pointer List (BPL) back to the lpfc DMA buffer 5085 * pool. 5086 * 5087 * Return code 5088 * 0 - Successfully released lpfc DMA buffer (currently, always return 0) 5089 **/ 5090 static int 5091 lpfc_els_free_bpl(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr) 5092 { 5093 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); 5094 kfree(buf_ptr); 5095 return 0; 5096 } 5097 5098 /** 5099 * lpfc_els_free_iocb - Free a command iocb and its associated resources 5100 * @phba: pointer to lpfc hba data structure. 5101 * @elsiocb: pointer to lpfc els command iocb data structure. 5102 * 5103 * This routine frees a command IOCB and its associated resources. The 5104 * command IOCB data structure contains the reference to various associated 5105 * resources, these fields must be set to NULL if the associated reference 5106 * not present: 5107 * cmd_dmabuf - reference to cmd. 5108 * cmd_dmabuf->next - reference to rsp 5109 * rsp_dmabuf - unused 5110 * bpl_dmabuf - reference to bpl 5111 * 5112 * It first properly decrements the reference count held on ndlp for the 5113 * IOCB completion callback function. If LPFC_DELAY_MEM_FREE flag is not 5114 * set, it invokes the lpfc_els_free_data() routine to release the Direct 5115 * Memory Access (DMA) buffers associated with the IOCB. Otherwise, it 5116 * adds the DMA buffer the @phba data structure for the delayed release. 5117 * If reference to the Buffer Pointer List (BPL) is present, the 5118 * lpfc_els_free_bpl() routine is invoked to release the DMA memory 5119 * associated with BPL. Finally, the lpfc_sli_release_iocbq() routine is 5120 * invoked to release the IOCB data structure back to @phba IOCBQ list. 5121 * 5122 * Return code 5123 * 0 - Success (currently, always return 0) 5124 **/ 5125 int 5126 lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb) 5127 { 5128 struct lpfc_dmabuf *buf_ptr, *buf_ptr1; 5129 5130 /* The I/O iocb is complete. Clear the node and first dmbuf */ 5131 elsiocb->ndlp = NULL; 5132 5133 /* cmd_dmabuf = cmd, cmd_dmabuf->next = rsp, bpl_dmabuf = bpl */ 5134 if (elsiocb->cmd_dmabuf) { 5135 if (elsiocb->cmd_flag & LPFC_DELAY_MEM_FREE) { 5136 /* Firmware could still be in progress of DMAing 5137 * payload, so don't free data buffer till after 5138 * a hbeat. 5139 */ 5140 elsiocb->cmd_flag &= ~LPFC_DELAY_MEM_FREE; 5141 buf_ptr = elsiocb->cmd_dmabuf; 5142 elsiocb->cmd_dmabuf = NULL; 5143 if (buf_ptr) { 5144 buf_ptr1 = NULL; 5145 spin_lock_irq(&phba->hbalock); 5146 if (!list_empty(&buf_ptr->list)) { 5147 list_remove_head(&buf_ptr->list, 5148 buf_ptr1, struct lpfc_dmabuf, 5149 list); 5150 INIT_LIST_HEAD(&buf_ptr1->list); 5151 list_add_tail(&buf_ptr1->list, 5152 &phba->elsbuf); 5153 phba->elsbuf_cnt++; 5154 } 5155 INIT_LIST_HEAD(&buf_ptr->list); 5156 list_add_tail(&buf_ptr->list, &phba->elsbuf); 5157 phba->elsbuf_cnt++; 5158 spin_unlock_irq(&phba->hbalock); 5159 } 5160 } else { 5161 buf_ptr1 = elsiocb->cmd_dmabuf; 5162 lpfc_els_free_data(phba, buf_ptr1); 5163 elsiocb->cmd_dmabuf = NULL; 5164 } 5165 } 5166 5167 if (elsiocb->bpl_dmabuf) { 5168 buf_ptr = elsiocb->bpl_dmabuf; 5169 lpfc_els_free_bpl(phba, buf_ptr); 5170 elsiocb->bpl_dmabuf = NULL; 5171 } 5172 lpfc_sli_release_iocbq(phba, elsiocb); 5173 return 0; 5174 } 5175 5176 /** 5177 * lpfc_cmpl_els_logo_acc - Completion callback function to logo acc response 5178 * @phba: pointer to lpfc hba data structure. 5179 * @cmdiocb: pointer to lpfc command iocb data structure. 5180 * @rspiocb: pointer to lpfc response iocb data structure. 5181 * 5182 * This routine is the completion callback function to the Logout (LOGO) 5183 * Accept (ACC) Response ELS command. This routine is invoked to indicate 5184 * the completion of the LOGO process. If the node has transitioned to NPR, 5185 * this routine unregisters the RPI if it is still registered. The 5186 * lpfc_els_free_iocb() is invoked to release the IOCB data structure. 5187 **/ 5188 static void 5189 lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, 5190 struct lpfc_iocbq *rspiocb) 5191 { 5192 struct lpfc_nodelist *ndlp = cmdiocb->ndlp; 5193 struct lpfc_vport *vport = cmdiocb->vport; 5194 u32 ulp_status, ulp_word4; 5195 5196 ulp_status = get_job_ulpstatus(phba, rspiocb); 5197 ulp_word4 = get_job_word4(phba, rspiocb); 5198 5199 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, 5200 "ACC LOGO cmpl: status:x%x/x%x did:x%x", 5201 ulp_status, ulp_word4, ndlp->nlp_DID); 5202 /* ACC to LOGO completes to NPort <nlp_DID> */ 5203 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, 5204 "0109 ACC to LOGO completes to NPort x%x refcnt %d " 5205 "last els x%x Data: x%lx x%x x%x\n", 5206 ndlp->nlp_DID, kref_read(&ndlp->kref), 5207 ndlp->nlp_last_elscmd, ndlp->nlp_flag, ndlp->nlp_state, 5208 ndlp->nlp_rpi); 5209 5210 /* This clause allows the LOGO ACC to complete and free resources 5211 * for the Fabric Domain Controller. It does deliberately skip 5212 * the unreg_rpi and release rpi because some fabrics send RDP 5213 * requests after logging out from the initiator. 5214 */ 5215 if (ndlp->nlp_type & NLP_FABRIC && 5216 ((ndlp->nlp_DID & WELL_KNOWN_DID_MASK) != WELL_KNOWN_DID_MASK)) 5217 goto out; 5218 5219 if (ndlp->nlp_state == NLP_STE_NPR_NODE) { 5220 if (test_bit(NLP_RPI_REGISTERED, &ndlp->nlp_flag)) 5221 lpfc_unreg_rpi(vport, ndlp); 5222 5223 /* If came from PRLO, then PRLO_ACC is done. 5224 * Start rediscovery now. 5225 */ 5226 if (ndlp->nlp_last_elscmd == ELS_CMD_PRLO) { 5227 set_bit(NLP_NPR_2B_DISC, &ndlp->nlp_flag); 5228 ndlp->nlp_prev_state = ndlp->nlp_state; 5229 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); 5230 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0); 5231 } 5232 } 5233 5234 out: 5235 /* 5236 * The driver received a LOGO from the rport and has ACK'd it. 5237 * At this point, the driver is done so release the IOCB 5238 */ 5239 lpfc_els_free_iocb(phba, cmdiocb); 5240 lpfc_nlp_put(ndlp); 5241 } 5242 5243 /** 5244 * lpfc_mbx_cmpl_dflt_rpi - Completion callbk func for unreg dflt rpi mbox cmd 5245 * @phba: pointer to lpfc hba data structure. 5246 * @pmb: pointer to the driver internal queue element for mailbox command. 5247 * 5248 * This routine is the completion callback function for unregister default 5249 * RPI (Remote Port Index) mailbox command to the @phba. It simply releases 5250 * the associated lpfc Direct Memory Access (DMA) buffer back to the pool and 5251 * decrements the ndlp reference count held for this completion callback 5252 * function. After that, it invokes the lpfc_drop_node to check 5253 * whether it is appropriate to release the node. 5254 **/ 5255 void 5256 lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) 5257 { 5258 struct lpfc_nodelist *ndlp = pmb->ctx_ndlp; 5259 u32 mbx_flag = pmb->mbox_flag; 5260 u32 mbx_cmd = pmb->u.mb.mbxCommand; 5261 5262 if (ndlp) { 5263 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE, 5264 "0006 rpi x%x DID:%x flg:%lx %d x%px " 5265 "mbx_cmd x%x mbx_flag x%x x%px\n", 5266 ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag, 5267 kref_read(&ndlp->kref), ndlp, mbx_cmd, 5268 mbx_flag, pmb); 5269 5270 /* This ends the default/temporary RPI cleanup logic for this 5271 * ndlp and the node and rpi needs to be released. Free the rpi 5272 * first on an UNREG_LOGIN and then release the final 5273 * references. 5274 */ 5275 clear_bit(NLP_REG_LOGIN_SEND, &ndlp->nlp_flag); 5276 if (mbx_cmd == MBX_UNREG_LOGIN) 5277 clear_bit(NLP_UNREG_INP, &ndlp->nlp_flag); 5278 lpfc_nlp_put(ndlp); 5279 lpfc_drop_node(ndlp->vport, ndlp); 5280 } 5281 5282 lpfc_mbox_rsrc_cleanup(phba, pmb, MBOX_THD_UNLOCKED); 5283 } 5284 5285 /** 5286 * lpfc_cmpl_els_rsp - Completion callback function for els response iocb cmd 5287 * @phba: pointer to lpfc hba data structure. 5288 * @cmdiocb: pointer to lpfc command iocb data structure. 5289 * @rspiocb: pointer to lpfc response iocb data structure. 5290 * 5291 * This routine is the completion callback function for ELS Response IOCB 5292 * command. In normal case, this callback function just properly sets the 5293 * nlp_flag bitmap in the ndlp data structure, if the mbox command reference 5294 * field in the command IOCB is not NULL, the referred mailbox command will 5295 * be send out, and then invokes the lpfc_els_free_iocb() routine to release 5296 * the IOCB. 5297 **/ 5298 static void 5299 lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, 5300 struct lpfc_iocbq *rspiocb) 5301 { 5302 struct lpfc_nodelist *ndlp = cmdiocb->ndlp; 5303 struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL; 5304 struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL; 5305 IOCB_t *irsp; 5306 LPFC_MBOXQ_t *mbox = NULL; 5307 u32 ulp_status, ulp_word4, tmo, did, iotag; 5308 5309 if (!vport) { 5310 lpfc_printf_log(phba, KERN_WARNING, LOG_ELS, 5311 "3177 null vport in ELS rsp\n"); 5312 goto out; 5313 } 5314 if (cmdiocb->context_un.mbox) 5315 mbox = cmdiocb->context_un.mbox; 5316 5317 ulp_status = get_job_ulpstatus(phba, rspiocb); 5318 ulp_word4 = get_job_word4(phba, rspiocb); 5319 did = get_job_els_rsp64_did(phba, cmdiocb); 5320 5321 if (phba->sli_rev == LPFC_SLI_REV4) { 5322 tmo = get_wqe_tmo(cmdiocb); 5323 iotag = get_wqe_reqtag(cmdiocb); 5324 } else { 5325 irsp = &rspiocb->iocb; 5326 tmo = irsp->ulpTimeout; 5327 iotag = irsp->ulpIoTag; 5328 } 5329 5330 /* Check to see if link went down during discovery */ 5331 if (!ndlp || lpfc_els_chk_latt(vport)) { 5332 if (mbox) 5333 lpfc_mbox_rsrc_cleanup(phba, mbox, MBOX_THD_UNLOCKED); 5334 goto out; 5335 } 5336 5337 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, 5338 "ELS rsp cmpl: status:x%x/x%x did:x%x", 5339 ulp_status, ulp_word4, did); 5340 /* ELS response tag <ulpIoTag> completes */ 5341 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, 5342 "0110 ELS response tag x%x completes " 5343 "Data: x%x x%x x%x x%x x%lx x%x x%x x%x %p %p\n", 5344 iotag, ulp_status, ulp_word4, tmo, 5345 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, 5346 ndlp->nlp_rpi, kref_read(&ndlp->kref), mbox, ndlp); 5347 if (mbox) { 5348 if (ulp_status == 0 && 5349 test_bit(NLP_ACC_REGLOGIN, &ndlp->nlp_flag)) { 5350 if (!lpfc_unreg_rpi(vport, ndlp) && 5351 !test_bit(FC_PT2PT, &vport->fc_flag)) { 5352 if (ndlp->nlp_state == NLP_STE_PLOGI_ISSUE || 5353 ndlp->nlp_state == 5354 NLP_STE_REG_LOGIN_ISSUE) { 5355 lpfc_printf_vlog(vport, KERN_INFO, 5356 LOG_DISCOVERY, 5357 "0314 PLOGI recov " 5358 "DID x%x " 5359 "Data: x%x x%x x%lx\n", 5360 ndlp->nlp_DID, 5361 ndlp->nlp_state, 5362 ndlp->nlp_rpi, 5363 ndlp->nlp_flag); 5364 goto out_free_mbox; 5365 } 5366 } 5367 5368 /* Increment reference count to ndlp to hold the 5369 * reference to ndlp for the callback function. 5370 */ 5371 mbox->ctx_ndlp = lpfc_nlp_get(ndlp); 5372 if (!mbox->ctx_ndlp) 5373 goto out_free_mbox; 5374 5375 mbox->vport = vport; 5376 if (test_bit(NLP_RM_DFLT_RPI, &ndlp->nlp_flag)) { 5377 mbox->mbox_flag |= LPFC_MBX_IMED_UNREG; 5378 mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi; 5379 } else { 5380 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login; 5381 ndlp->nlp_prev_state = ndlp->nlp_state; 5382 lpfc_nlp_set_state(vport, ndlp, 5383 NLP_STE_REG_LOGIN_ISSUE); 5384 } 5385 5386 set_bit(NLP_REG_LOGIN_SEND, &ndlp->nlp_flag); 5387 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) 5388 != MBX_NOT_FINISHED) 5389 goto out; 5390 5391 /* Decrement the ndlp reference count we 5392 * set for this failed mailbox command. 5393 */ 5394 lpfc_nlp_put(ndlp); 5395 clear_bit(NLP_REG_LOGIN_SEND, &ndlp->nlp_flag); 5396 5397 /* ELS rsp: Cannot issue reg_login for <NPortid> */ 5398 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, 5399 "0138 ELS rsp: Cannot issue reg_login for x%x " 5400 "Data: x%lx x%x x%x\n", 5401 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, 5402 ndlp->nlp_rpi); 5403 } 5404 out_free_mbox: 5405 lpfc_mbox_rsrc_cleanup(phba, mbox, MBOX_THD_UNLOCKED); 5406 } 5407 out: 5408 if (ndlp && shost) { 5409 if (mbox) 5410 clear_bit(NLP_ACC_REGLOGIN, &ndlp->nlp_flag); 5411 clear_bit(NLP_RM_DFLT_RPI, &ndlp->nlp_flag); 5412 } 5413 5414 /* An SLI4 NPIV instance wants to drop the node at this point under 5415 * these conditions because it doesn't need the login. 5416 */ 5417 if (phba->sli_rev == LPFC_SLI_REV4 && 5418 vport && vport->port_type == LPFC_NPIV_PORT && 5419 !(ndlp->fc4_xpt_flags & SCSI_XPT_REGD)) { 5420 if (ndlp->nlp_state != NLP_STE_PLOGI_ISSUE && 5421 ndlp->nlp_state != NLP_STE_REG_LOGIN_ISSUE && 5422 ndlp->nlp_state != NLP_STE_PRLI_ISSUE) { 5423 /* Drop ndlp if there is no planned or outstanding 5424 * issued PRLI. 5425 * 5426 * In cases when the ndlp is acting as both an initiator 5427 * and target function, let our issued PRLI determine 5428 * the final ndlp kref drop. 5429 */ 5430 lpfc_drop_node(vport, ndlp); 5431 } 5432 } 5433 5434 /* Release the originating I/O reference. */ 5435 lpfc_els_free_iocb(phba, cmdiocb); 5436 lpfc_nlp_put(ndlp); 5437 return; 5438 } 5439 5440 /** 5441 * lpfc_els_rsp_acc - Prepare and issue an acc response iocb command 5442 * @vport: pointer to a host virtual N_Port data structure. 5443 * @flag: the els command code to be accepted. 5444 * @oldiocb: pointer to the original lpfc command iocb data structure. 5445 * @ndlp: pointer to a node-list data structure. 5446 * @mbox: pointer to the driver internal queue element for mailbox command. 5447 * 5448 * This routine prepares and issues an Accept (ACC) response IOCB 5449 * command. It uses the @flag to properly set up the IOCB field for the 5450 * specific ACC response command to be issued and invokes the 5451 * lpfc_sli_issue_iocb() routine to send out ACC response IOCB. If a 5452 * @mbox pointer is passed in, it will be put into the context_un.mbox 5453 * field of the IOCB for the completion callback function to issue the 5454 * mailbox command to the HBA later when callback is invoked. 5455 * 5456 * Note that the ndlp reference count will be incremented by 1 for holding the 5457 * ndlp and the reference to ndlp will be stored into the ndlp field of 5458 * the IOCB for the completion callback function to the corresponding 5459 * response ELS IOCB command. 5460 * 5461 * Return code 5462 * 0 - Successfully issued acc response 5463 * 1 - Failed to issue acc response 5464 **/ 5465 int 5466 lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag, 5467 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp, 5468 LPFC_MBOXQ_t *mbox) 5469 { 5470 struct lpfc_hba *phba = vport->phba; 5471 IOCB_t *icmd; 5472 IOCB_t *oldcmd; 5473 union lpfc_wqe128 *wqe; 5474 union lpfc_wqe128 *oldwqe = &oldiocb->wqe; 5475 struct lpfc_iocbq *elsiocb; 5476 uint8_t *pcmd; 5477 struct serv_parm *sp; 5478 uint16_t cmdsize; 5479 int rc; 5480 ELS_PKT *els_pkt_ptr; 5481 struct fc_els_rdf_resp *rdf_resp; 5482 5483 switch (flag) { 5484 case ELS_CMD_ACC: 5485 cmdsize = sizeof(uint32_t); 5486 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, 5487 ndlp, ndlp->nlp_DID, ELS_CMD_ACC); 5488 if (!elsiocb) { 5489 clear_bit(NLP_LOGO_ACC, &ndlp->nlp_flag); 5490 return 1; 5491 } 5492 5493 if (phba->sli_rev == LPFC_SLI_REV4) { 5494 wqe = &elsiocb->wqe; 5495 /* XRI / rx_id */ 5496 bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com, 5497 bf_get(wqe_ctxt_tag, 5498 &oldwqe->xmit_els_rsp.wqe_com)); 5499 5500 /* oxid */ 5501 bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com, 5502 bf_get(wqe_rcvoxid, 5503 &oldwqe->xmit_els_rsp.wqe_com)); 5504 } else { 5505 icmd = &elsiocb->iocb; 5506 oldcmd = &oldiocb->iocb; 5507 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */ 5508 icmd->unsli3.rcvsli3.ox_id = 5509 oldcmd->unsli3.rcvsli3.ox_id; 5510 } 5511 5512 pcmd = elsiocb->cmd_dmabuf->virt; 5513 *((uint32_t *) (pcmd)) = ELS_CMD_ACC; 5514 pcmd += sizeof(uint32_t); 5515 5516 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, 5517 "Issue ACC: did:x%x flg:x%lx", 5518 ndlp->nlp_DID, ndlp->nlp_flag, 0); 5519 break; 5520 case ELS_CMD_FLOGI: 5521 case ELS_CMD_PLOGI: 5522 cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t)); 5523 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, 5524 ndlp, ndlp->nlp_DID, ELS_CMD_ACC); 5525 if (!elsiocb) 5526 return 1; 5527 5528 if (phba->sli_rev == LPFC_SLI_REV4) { 5529 wqe = &elsiocb->wqe; 5530 /* XRI / rx_id */ 5531 bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com, 5532 bf_get(wqe_ctxt_tag, 5533 &oldwqe->xmit_els_rsp.wqe_com)); 5534 5535 /* oxid */ 5536 bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com, 5537 bf_get(wqe_rcvoxid, 5538 &oldwqe->xmit_els_rsp.wqe_com)); 5539 } else { 5540 icmd = &elsiocb->iocb; 5541 oldcmd = &oldiocb->iocb; 5542 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */ 5543 icmd->unsli3.rcvsli3.ox_id = 5544 oldcmd->unsli3.rcvsli3.ox_id; 5545 } 5546 5547 pcmd = (u8 *)elsiocb->cmd_dmabuf->virt; 5548 5549 if (mbox) 5550 elsiocb->context_un.mbox = mbox; 5551 5552 *((uint32_t *) (pcmd)) = ELS_CMD_ACC; 5553 pcmd += sizeof(uint32_t); 5554 sp = (struct serv_parm *)pcmd; 5555 5556 if (flag == ELS_CMD_FLOGI) { 5557 /* Copy the received service parameters back */ 5558 memcpy(sp, &phba->fc_fabparam, 5559 sizeof(struct serv_parm)); 5560 5561 /* Clear the F_Port bit */ 5562 sp->cmn.fPort = 0; 5563 5564 /* Mark all class service parameters as invalid */ 5565 sp->cls1.classValid = 0; 5566 sp->cls2.classValid = 0; 5567 sp->cls3.classValid = 0; 5568 sp->cls4.classValid = 0; 5569 5570 /* Copy our worldwide names */ 5571 memcpy(&sp->portName, &vport->fc_sparam.portName, 5572 sizeof(struct lpfc_name)); 5573 memcpy(&sp->nodeName, &vport->fc_sparam.nodeName, 5574 sizeof(struct lpfc_name)); 5575 } else { 5576 memcpy(pcmd, &vport->fc_sparam, 5577 sizeof(struct serv_parm)); 5578 5579 sp->cmn.valid_vendor_ver_level = 0; 5580 memset(sp->un.vendorVersion, 0, 5581 sizeof(sp->un.vendorVersion)); 5582 sp->cmn.bbRcvSizeMsb &= 0xF; 5583 5584 /* If our firmware supports this feature, convey that 5585 * info to the target using the vendor specific field. 5586 */ 5587 if (phba->sli.sli_flag & LPFC_SLI_SUPPRESS_RSP) { 5588 sp->cmn.valid_vendor_ver_level = 1; 5589 sp->un.vv.vid = cpu_to_be32(LPFC_VV_EMLX_ID); 5590 sp->un.vv.flags = 5591 cpu_to_be32(LPFC_VV_SUPPRESS_RSP); 5592 } 5593 } 5594 5595 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, 5596 "Issue ACC FLOGI/PLOGI: did:x%x flg:x%lx", 5597 ndlp->nlp_DID, ndlp->nlp_flag, 0); 5598 break; 5599 case ELS_CMD_PRLO: 5600 cmdsize = sizeof(uint32_t) + sizeof(PRLO); 5601 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, 5602 ndlp, ndlp->nlp_DID, ELS_CMD_PRLO); 5603 if (!elsiocb) 5604 return 1; 5605 5606 if (phba->sli_rev == LPFC_SLI_REV4) { 5607 wqe = &elsiocb->wqe; 5608 /* XRI / rx_id */ 5609 bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com, 5610 bf_get(wqe_ctxt_tag, 5611 &oldwqe->xmit_els_rsp.wqe_com)); 5612 5613 /* oxid */ 5614 bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com, 5615 bf_get(wqe_rcvoxid, 5616 &oldwqe->xmit_els_rsp.wqe_com)); 5617 } else { 5618 icmd = &elsiocb->iocb; 5619 oldcmd = &oldiocb->iocb; 5620 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */ 5621 icmd->unsli3.rcvsli3.ox_id = 5622 oldcmd->unsli3.rcvsli3.ox_id; 5623 } 5624 5625 pcmd = (u8 *) elsiocb->cmd_dmabuf->virt; 5626 5627 memcpy(pcmd, oldiocb->cmd_dmabuf->virt, 5628 sizeof(uint32_t) + sizeof(PRLO)); 5629 *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC; 5630 els_pkt_ptr = (ELS_PKT *) pcmd; 5631 els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED; 5632 5633 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, 5634 "Issue ACC PRLO: did:x%x flg:x%lx", 5635 ndlp->nlp_DID, ndlp->nlp_flag, 0); 5636 break; 5637 case ELS_CMD_RDF: 5638 cmdsize = sizeof(*rdf_resp); 5639 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, 5640 ndlp, ndlp->nlp_DID, ELS_CMD_ACC); 5641 if (!elsiocb) 5642 return 1; 5643 5644 if (phba->sli_rev == LPFC_SLI_REV4) { 5645 wqe = &elsiocb->wqe; 5646 /* XRI / rx_id */ 5647 bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com, 5648 bf_get(wqe_ctxt_tag, 5649 &oldwqe->xmit_els_rsp.wqe_com)); 5650 5651 /* oxid */ 5652 bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com, 5653 bf_get(wqe_rcvoxid, 5654 &oldwqe->xmit_els_rsp.wqe_com)); 5655 } else { 5656 icmd = &elsiocb->iocb; 5657 oldcmd = &oldiocb->iocb; 5658 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */ 5659 icmd->unsli3.rcvsli3.ox_id = 5660 oldcmd->unsli3.rcvsli3.ox_id; 5661 } 5662 5663 pcmd = (u8 *)elsiocb->cmd_dmabuf->virt; 5664 rdf_resp = (struct fc_els_rdf_resp *)pcmd; 5665 memset(rdf_resp, 0, sizeof(*rdf_resp)); 5666 rdf_resp->acc_hdr.la_cmd = ELS_LS_ACC; 5667 5668 /* FC-LS-5 specifies desc_list_len shall be set to 12 */ 5669 rdf_resp->desc_list_len = cpu_to_be32(12); 5670 5671 /* FC-LS-5 specifies LS REQ Information descriptor */ 5672 rdf_resp->lsri.desc_tag = cpu_to_be32(1); 5673 rdf_resp->lsri.desc_len = cpu_to_be32(sizeof(u32)); 5674 rdf_resp->lsri.rqst_w0.cmd = ELS_RDF; 5675 break; 5676 default: 5677 return 1; 5678 } 5679 if (test_bit(NLP_LOGO_ACC, &ndlp->nlp_flag)) { 5680 if (!test_bit(NLP_RPI_REGISTERED, &ndlp->nlp_flag) && 5681 !test_bit(NLP_REG_LOGIN_SEND, &ndlp->nlp_flag)) 5682 clear_bit(NLP_LOGO_ACC, &ndlp->nlp_flag); 5683 elsiocb->cmd_cmpl = lpfc_cmpl_els_logo_acc; 5684 } else { 5685 elsiocb->cmd_cmpl = lpfc_cmpl_els_rsp; 5686 } 5687 5688 phba->fc_stat.elsXmitACC++; 5689 elsiocb->ndlp = lpfc_nlp_get(ndlp); 5690 if (!elsiocb->ndlp) { 5691 lpfc_els_free_iocb(phba, elsiocb); 5692 return 1; 5693 } 5694 5695 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); 5696 if (rc == IOCB_ERROR) { 5697 lpfc_els_free_iocb(phba, elsiocb); 5698 lpfc_nlp_put(ndlp); 5699 return 1; 5700 } 5701 5702 /* Xmit ELS ACC response tag <ulpIoTag> */ 5703 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, 5704 "0128 Xmit ELS ACC response Status: x%x, IoTag: x%x, " 5705 "XRI: x%x, DID: x%x, nlp_flag: x%lx nlp_state: x%x " 5706 "RPI: x%x, fc_flag x%lx refcnt %d\n", 5707 rc, elsiocb->iotag, elsiocb->sli4_xritag, 5708 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, 5709 ndlp->nlp_rpi, vport->fc_flag, kref_read(&ndlp->kref)); 5710 return 0; 5711 } 5712 5713 /** 5714 * lpfc_els_rsp_reject - Prepare and issue a rjt response iocb command 5715 * @vport: pointer to a virtual N_Port data structure. 5716 * @rejectError: reject response to issue 5717 * @oldiocb: pointer to the original lpfc command iocb data structure. 5718 * @ndlp: pointer to a node-list data structure. 5719 * @mbox: pointer to the driver internal queue element for mailbox command. 5720 * 5721 * This routine prepares and issue an Reject (RJT) response IOCB 5722 * command. If a @mbox pointer is passed in, it will be put into the 5723 * context_un.mbox field of the IOCB for the completion callback function 5724 * to issue to the HBA later. 5725 * 5726 * Note that the ndlp reference count will be incremented by 1 for holding the 5727 * ndlp and the reference to ndlp will be stored into the ndlp field of 5728 * the IOCB for the completion callback function to the reject response 5729 * ELS IOCB command. 5730 * 5731 * Return code 5732 * 0 - Successfully issued reject response 5733 * 1 - Failed to issue reject response 5734 **/ 5735 int 5736 lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError, 5737 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp, 5738 LPFC_MBOXQ_t *mbox) 5739 { 5740 int rc; 5741 struct lpfc_hba *phba = vport->phba; 5742 IOCB_t *icmd; 5743 IOCB_t *oldcmd; 5744 union lpfc_wqe128 *wqe; 5745 struct lpfc_iocbq *elsiocb; 5746 uint8_t *pcmd; 5747 uint16_t cmdsize; 5748 5749 cmdsize = 2 * sizeof(uint32_t); 5750 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, 5751 ndlp->nlp_DID, ELS_CMD_LS_RJT); 5752 if (!elsiocb) 5753 return 1; 5754 5755 if (phba->sli_rev == LPFC_SLI_REV4) { 5756 wqe = &elsiocb->wqe; 5757 bf_set(wqe_ctxt_tag, &wqe->generic.wqe_com, 5758 get_job_ulpcontext(phba, oldiocb)); /* Xri / rx_id */ 5759 bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com, 5760 get_job_rcvoxid(phba, oldiocb)); 5761 } else { 5762 icmd = &elsiocb->iocb; 5763 oldcmd = &oldiocb->iocb; 5764 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */ 5765 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id; 5766 } 5767 5768 pcmd = (uint8_t *)elsiocb->cmd_dmabuf->virt; 5769 5770 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT; 5771 pcmd += sizeof(uint32_t); 5772 *((uint32_t *) (pcmd)) = rejectError; 5773 5774 if (mbox) 5775 elsiocb->context_un.mbox = mbox; 5776 5777 /* Xmit ELS RJT <err> response tag <ulpIoTag> */ 5778 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, 5779 "0129 Xmit ELS RJT x%x response tag x%x " 5780 "xri x%x, did x%x, nlp_flag x%lx, nlp_state x%x, " 5781 "rpi x%x\n", 5782 rejectError, elsiocb->iotag, 5783 get_job_ulpcontext(phba, elsiocb), ndlp->nlp_DID, 5784 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi); 5785 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, 5786 "Issue LS_RJT: did:x%x flg:x%lx err:x%x", 5787 ndlp->nlp_DID, ndlp->nlp_flag, rejectError); 5788 5789 phba->fc_stat.elsXmitLSRJT++; 5790 elsiocb->cmd_cmpl = lpfc_cmpl_els_rsp; 5791 elsiocb->ndlp = lpfc_nlp_get(ndlp); 5792 if (!elsiocb->ndlp) { 5793 lpfc_els_free_iocb(phba, elsiocb); 5794 return 1; 5795 } 5796 5797 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); 5798 if (rc == IOCB_ERROR) { 5799 lpfc_els_free_iocb(phba, elsiocb); 5800 lpfc_nlp_put(ndlp); 5801 return 1; 5802 } 5803 5804 return 0; 5805 } 5806 5807 /** 5808 * lpfc_issue_els_edc_rsp - Exchange Diagnostic Capabilities with the fabric. 5809 * @vport: pointer to a host virtual N_Port data structure. 5810 * @cmdiocb: pointer to the original lpfc command iocb data structure. 5811 * @ndlp: NPort to where rsp is directed 5812 * 5813 * This routine issues an EDC ACC RSP to the F-Port Controller to communicate 5814 * this N_Port's support of hardware signals in its Congestion 5815 * Capabilities Descriptor. 5816 * 5817 * Return code 5818 * 0 - Successfully issued edc rsp command 5819 * 1 - Failed to issue edc rsp command 5820 **/ 5821 static int 5822 lpfc_issue_els_edc_rsp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, 5823 struct lpfc_nodelist *ndlp) 5824 { 5825 struct lpfc_hba *phba = vport->phba; 5826 struct fc_els_edc_resp *edc_rsp; 5827 struct fc_tlv_desc *tlv; 5828 struct lpfc_iocbq *elsiocb; 5829 IOCB_t *icmd, *cmd; 5830 union lpfc_wqe128 *wqe; 5831 u32 cgn_desc_size, lft_desc_size; 5832 u16 cmdsize; 5833 uint8_t *pcmd; 5834 int rc; 5835 5836 cmdsize = sizeof(struct fc_els_edc_resp); 5837 cgn_desc_size = sizeof(struct fc_diag_cg_sig_desc); 5838 lft_desc_size = (lpfc_link_is_lds_capable(phba)) ? 5839 sizeof(struct fc_diag_lnkflt_desc) : 0; 5840 cmdsize += cgn_desc_size + lft_desc_size; 5841 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, cmdiocb->retry, 5842 ndlp, ndlp->nlp_DID, ELS_CMD_ACC); 5843 if (!elsiocb) 5844 return 1; 5845 5846 if (phba->sli_rev == LPFC_SLI_REV4) { 5847 wqe = &elsiocb->wqe; 5848 bf_set(wqe_ctxt_tag, &wqe->generic.wqe_com, 5849 get_job_ulpcontext(phba, cmdiocb)); /* Xri / rx_id */ 5850 bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com, 5851 get_job_rcvoxid(phba, cmdiocb)); 5852 } else { 5853 icmd = &elsiocb->iocb; 5854 cmd = &cmdiocb->iocb; 5855 icmd->ulpContext = cmd->ulpContext; /* Xri / rx_id */ 5856 icmd->unsli3.rcvsli3.ox_id = cmd->unsli3.rcvsli3.ox_id; 5857 } 5858 5859 pcmd = elsiocb->cmd_dmabuf->virt; 5860 memset(pcmd, 0, cmdsize); 5861 5862 edc_rsp = (struct fc_els_edc_resp *)pcmd; 5863 edc_rsp->acc_hdr.la_cmd = ELS_LS_ACC; 5864 edc_rsp->desc_list_len = cpu_to_be32(sizeof(struct fc_els_lsri_desc) + 5865 cgn_desc_size + lft_desc_size); 5866 edc_rsp->lsri.desc_tag = cpu_to_be32(ELS_DTAG_LS_REQ_INFO); 5867 edc_rsp->lsri.desc_len = cpu_to_be32( 5868 FC_TLV_DESC_LENGTH_FROM_SZ(struct fc_els_lsri_desc)); 5869 edc_rsp->lsri.rqst_w0.cmd = ELS_EDC; 5870 tlv = edc_rsp->desc; 5871 lpfc_format_edc_cgn_desc(phba, tlv); 5872 tlv = fc_tlv_next_desc(tlv); 5873 if (lft_desc_size) 5874 lpfc_format_edc_lft_desc(phba, tlv); 5875 5876 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, 5877 "Issue EDC ACC: did:x%x flg:x%lx refcnt %d", 5878 ndlp->nlp_DID, ndlp->nlp_flag, 5879 kref_read(&ndlp->kref)); 5880 elsiocb->cmd_cmpl = lpfc_cmpl_els_rsp; 5881 5882 phba->fc_stat.elsXmitACC++; 5883 elsiocb->ndlp = lpfc_nlp_get(ndlp); 5884 if (!elsiocb->ndlp) { 5885 lpfc_els_free_iocb(phba, elsiocb); 5886 return 1; 5887 } 5888 5889 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); 5890 if (rc == IOCB_ERROR) { 5891 lpfc_els_free_iocb(phba, elsiocb); 5892 lpfc_nlp_put(ndlp); 5893 return 1; 5894 } 5895 5896 /* Xmit ELS ACC response tag <ulpIoTag> */ 5897 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, 5898 "0152 Xmit EDC ACC response Status: x%x, IoTag: x%x, " 5899 "XRI: x%x, DID: x%x, nlp_flag: x%lx nlp_state: x%x " 5900 "RPI: x%x, fc_flag x%lx\n", 5901 rc, elsiocb->iotag, elsiocb->sli4_xritag, 5902 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, 5903 ndlp->nlp_rpi, vport->fc_flag); 5904 5905 return 0; 5906 } 5907 5908 /** 5909 * lpfc_els_rsp_adisc_acc - Prepare and issue acc response to adisc iocb cmd 5910 * @vport: pointer to a virtual N_Port data structure. 5911 * @oldiocb: pointer to the original lpfc command iocb data structure. 5912 * @ndlp: pointer to a node-list data structure. 5913 * 5914 * This routine prepares and issues an Accept (ACC) response to Address 5915 * Discover (ADISC) ELS command. It simply prepares the payload of the IOCB 5916 * and invokes the lpfc_sli_issue_iocb() routine to send out the command. 5917 * 5918 * Note that the ndlp reference count will be incremented by 1 for holding the 5919 * ndlp and the reference to ndlp will be stored into the ndlp field of 5920 * the IOCB for the completion callback function to the ADISC Accept response 5921 * ELS IOCB command. 5922 * 5923 * Return code 5924 * 0 - Successfully issued acc adisc response 5925 * 1 - Failed to issue adisc acc response 5926 **/ 5927 int 5928 lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb, 5929 struct lpfc_nodelist *ndlp) 5930 { 5931 struct lpfc_hba *phba = vport->phba; 5932 ADISC *ap; 5933 IOCB_t *icmd, *oldcmd; 5934 union lpfc_wqe128 *wqe; 5935 struct lpfc_iocbq *elsiocb; 5936 uint8_t *pcmd; 5937 uint16_t cmdsize; 5938 int rc; 5939 u32 ulp_context; 5940 5941 cmdsize = sizeof(uint32_t) + sizeof(ADISC); 5942 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, 5943 ndlp->nlp_DID, ELS_CMD_ACC); 5944 if (!elsiocb) 5945 return 1; 5946 5947 if (phba->sli_rev == LPFC_SLI_REV4) { 5948 wqe = &elsiocb->wqe; 5949 /* XRI / rx_id */ 5950 bf_set(wqe_ctxt_tag, &wqe->generic.wqe_com, 5951 get_job_ulpcontext(phba, oldiocb)); 5952 ulp_context = get_job_ulpcontext(phba, elsiocb); 5953 /* oxid */ 5954 bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com, 5955 get_job_rcvoxid(phba, oldiocb)); 5956 } else { 5957 icmd = &elsiocb->iocb; 5958 oldcmd = &oldiocb->iocb; 5959 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */ 5960 ulp_context = elsiocb->iocb.ulpContext; 5961 icmd->unsli3.rcvsli3.ox_id = 5962 oldcmd->unsli3.rcvsli3.ox_id; 5963 } 5964 5965 /* Xmit ADISC ACC response tag <ulpIoTag> */ 5966 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, 5967 "0130 Xmit ADISC ACC response iotag x%x xri: " 5968 "x%x, did x%x, nlp_flag x%lx, nlp_state x%x rpi x%x\n", 5969 elsiocb->iotag, ulp_context, 5970 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, 5971 ndlp->nlp_rpi); 5972 pcmd = (uint8_t *)elsiocb->cmd_dmabuf->virt; 5973 5974 *((uint32_t *) (pcmd)) = ELS_CMD_ACC; 5975 pcmd += sizeof(uint32_t); 5976 5977 ap = (ADISC *) (pcmd); 5978 ap->hardAL_PA = phba->fc_pref_ALPA; 5979 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name)); 5980 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); 5981 ap->DID = be32_to_cpu(vport->fc_myDID); 5982 5983 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, 5984 "Issue ACC ADISC: did:x%x flg:x%lx refcnt %d", 5985 ndlp->nlp_DID, ndlp->nlp_flag, kref_read(&ndlp->kref)); 5986 5987 phba->fc_stat.elsXmitACC++; 5988 elsiocb->cmd_cmpl = lpfc_cmpl_els_rsp; 5989 elsiocb->ndlp = lpfc_nlp_get(ndlp); 5990 if (!elsiocb->ndlp) { 5991 lpfc_els_free_iocb(phba, elsiocb); 5992 return 1; 5993 } 5994 5995 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); 5996 if (rc == IOCB_ERROR) { 5997 lpfc_els_free_iocb(phba, elsiocb); 5998 lpfc_nlp_put(ndlp); 5999 return 1; 6000 } 6001 6002 return 0; 6003 } 6004 6005 /** 6006 * lpfc_els_rsp_prli_acc - Prepare and issue acc response to prli iocb cmd 6007 * @vport: pointer to a virtual N_Port data structure. 6008 * @oldiocb: pointer to the original lpfc command iocb data structure. 6009 * @ndlp: pointer to a node-list data structure. 6010 * 6011 * This routine prepares and issues an Accept (ACC) response to Process 6012 * Login (PRLI) ELS command. It simply prepares the payload of the IOCB 6013 * and invokes the lpfc_sli_issue_iocb() routine to send out the command. 6014 * 6015 * Note that the ndlp reference count will be incremented by 1 for holding the 6016 * ndlp and the reference to ndlp will be stored into the ndlp field of 6017 * the IOCB for the completion callback function to the PRLI Accept response 6018 * ELS IOCB command. 6019 * 6020 * Return code 6021 * 0 - Successfully issued acc prli response 6022 * 1 - Failed to issue acc prli response 6023 **/ 6024 int 6025 lpfc_els_rsp_prli_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb, 6026 struct lpfc_nodelist *ndlp) 6027 { 6028 struct lpfc_hba *phba = vport->phba; 6029 PRLI *npr; 6030 struct lpfc_nvme_prli *npr_nvme; 6031 lpfc_vpd_t *vpd; 6032 IOCB_t *icmd; 6033 IOCB_t *oldcmd; 6034 union lpfc_wqe128 *wqe; 6035 struct lpfc_iocbq *elsiocb; 6036 uint8_t *pcmd; 6037 uint16_t cmdsize; 6038 uint32_t prli_fc4_req, *req_payload; 6039 struct lpfc_dmabuf *req_buf; 6040 int rc; 6041 u32 elsrspcmd, ulp_context; 6042 6043 /* Need the incoming PRLI payload to determine if the ACC is for an 6044 * FC4 or NVME PRLI type. The PRLI type is at word 1. 6045 */ 6046 req_buf = oldiocb->cmd_dmabuf; 6047 req_payload = (((uint32_t *)req_buf->virt) + 1); 6048 6049 /* PRLI type payload is at byte 3 for FCP or NVME. */ 6050 prli_fc4_req = be32_to_cpu(*req_payload); 6051 prli_fc4_req = (prli_fc4_req >> 24) & 0xff; 6052 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, 6053 "6127 PRLI_ACC: Req Type x%x, Word1 x%08x\n", 6054 prli_fc4_req, *((uint32_t *)req_payload)); 6055 6056 if (prli_fc4_req == PRLI_FCP_TYPE) { 6057 cmdsize = sizeof(uint32_t) + sizeof(PRLI); 6058 elsrspcmd = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK)); 6059 } else if (prli_fc4_req == PRLI_NVME_TYPE) { 6060 cmdsize = sizeof(uint32_t) + sizeof(struct lpfc_nvme_prli); 6061 elsrspcmd = (ELS_CMD_ACC | (ELS_CMD_NVMEPRLI & ~ELS_RSP_MASK)); 6062 } else { 6063 return 1; 6064 } 6065 6066 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, 6067 ndlp->nlp_DID, elsrspcmd); 6068 if (!elsiocb) 6069 return 1; 6070 6071 if (phba->sli_rev == LPFC_SLI_REV4) { 6072 wqe = &elsiocb->wqe; 6073 bf_set(wqe_ctxt_tag, &wqe->generic.wqe_com, 6074 get_job_ulpcontext(phba, oldiocb)); /* Xri / rx_id */ 6075 ulp_context = get_job_ulpcontext(phba, elsiocb); 6076 bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com, 6077 get_job_rcvoxid(phba, oldiocb)); 6078 } else { 6079 icmd = &elsiocb->iocb; 6080 oldcmd = &oldiocb->iocb; 6081 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */ 6082 ulp_context = elsiocb->iocb.ulpContext; 6083 icmd->unsli3.rcvsli3.ox_id = 6084 oldcmd->unsli3.rcvsli3.ox_id; 6085 } 6086 6087 /* Xmit PRLI ACC response tag <ulpIoTag> */ 6088 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, 6089 "0131 Xmit PRLI ACC response tag x%x xri x%x, " 6090 "did x%x, nlp_flag x%lx, nlp_state x%x, rpi x%x\n", 6091 elsiocb->iotag, ulp_context, 6092 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, 6093 ndlp->nlp_rpi); 6094 pcmd = (uint8_t *)elsiocb->cmd_dmabuf->virt; 6095 memset(pcmd, 0, cmdsize); 6096 6097 *((uint32_t *)(pcmd)) = elsrspcmd; 6098 pcmd += sizeof(uint32_t); 6099 6100 /* For PRLI, remainder of payload is PRLI parameter page */ 6101 vpd = &phba->vpd; 6102 6103 if (prli_fc4_req == PRLI_FCP_TYPE) { 6104 /* 6105 * If the remote port is a target and our firmware version 6106 * is 3.20 or later, set the following bits for FC-TAPE 6107 * support. 6108 */ 6109 npr = (PRLI *) pcmd; 6110 if ((ndlp->nlp_type & NLP_FCP_TARGET) && 6111 (vpd->rev.feaLevelHigh >= 0x02)) { 6112 npr->ConfmComplAllowed = 1; 6113 npr->Retry = 1; 6114 npr->TaskRetryIdReq = 1; 6115 } 6116 npr->acceptRspCode = PRLI_REQ_EXECUTED; 6117 6118 /* Set image pair for complementary pairs only. */ 6119 if (ndlp->nlp_type & NLP_FCP_TARGET) 6120 npr->estabImagePair = 1; 6121 else 6122 npr->estabImagePair = 0; 6123 npr->readXferRdyDis = 1; 6124 npr->ConfmComplAllowed = 1; 6125 npr->prliType = PRLI_FCP_TYPE; 6126 npr->initiatorFunc = 1; 6127 6128 /* Xmit PRLI ACC response tag <ulpIoTag> */ 6129 lpfc_printf_vlog(vport, KERN_INFO, 6130 LOG_ELS | LOG_NODE | LOG_DISCOVERY, 6131 "6014 FCP issue PRLI ACC imgpair %d " 6132 "retry %d task %d\n", 6133 npr->estabImagePair, 6134 npr->Retry, npr->TaskRetryIdReq); 6135 6136 } else if (prli_fc4_req == PRLI_NVME_TYPE) { 6137 /* Respond with an NVME PRLI Type */ 6138 npr_nvme = (struct lpfc_nvme_prli *) pcmd; 6139 bf_set(prli_type_code, npr_nvme, PRLI_NVME_TYPE); 6140 bf_set(prli_estabImagePair, npr_nvme, 0); /* Should be 0 */ 6141 bf_set(prli_acc_rsp_code, npr_nvme, PRLI_REQ_EXECUTED); 6142 if (phba->nvmet_support) { 6143 bf_set(prli_tgt, npr_nvme, 1); 6144 bf_set(prli_disc, npr_nvme, 1); 6145 if (phba->cfg_nvme_enable_fb) { 6146 bf_set(prli_fba, npr_nvme, 1); 6147 6148 /* TBD. Target mode needs to post buffers 6149 * that support the configured first burst 6150 * byte size. 6151 */ 6152 bf_set(prli_fb_sz, npr_nvme, 6153 phba->cfg_nvmet_fb_size); 6154 } 6155 } else { 6156 bf_set(prli_init, npr_nvme, 1); 6157 } 6158 6159 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_DISC, 6160 "6015 NVME issue PRLI ACC word1 x%08x " 6161 "word4 x%08x word5 x%08x flag x%lx, " 6162 "fcp_info x%x nlp_type x%x\n", 6163 npr_nvme->word1, npr_nvme->word4, 6164 npr_nvme->word5, ndlp->nlp_flag, 6165 ndlp->nlp_fcp_info, ndlp->nlp_type); 6166 npr_nvme->word1 = cpu_to_be32(npr_nvme->word1); 6167 npr_nvme->word4 = cpu_to_be32(npr_nvme->word4); 6168 npr_nvme->word5 = cpu_to_be32(npr_nvme->word5); 6169 } else 6170 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, 6171 "6128 Unknown FC_TYPE x%x x%x ndlp x%06x\n", 6172 prli_fc4_req, ndlp->nlp_fc4_type, 6173 ndlp->nlp_DID); 6174 6175 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, 6176 "Issue ACC PRLI: did:x%x flg:x%lx", 6177 ndlp->nlp_DID, ndlp->nlp_flag, kref_read(&ndlp->kref)); 6178 6179 phba->fc_stat.elsXmitACC++; 6180 elsiocb->cmd_cmpl = lpfc_cmpl_els_rsp; 6181 elsiocb->ndlp = lpfc_nlp_get(ndlp); 6182 if (!elsiocb->ndlp) { 6183 lpfc_els_free_iocb(phba, elsiocb); 6184 return 1; 6185 } 6186 6187 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); 6188 if (rc == IOCB_ERROR) { 6189 lpfc_els_free_iocb(phba, elsiocb); 6190 lpfc_nlp_put(ndlp); 6191 return 1; 6192 } 6193 6194 return 0; 6195 } 6196 6197 /** 6198 * lpfc_els_rsp_rnid_acc - Issue rnid acc response iocb command 6199 * @vport: pointer to a virtual N_Port data structure. 6200 * @format: rnid command format. 6201 * @oldiocb: pointer to the original lpfc command iocb data structure. 6202 * @ndlp: pointer to a node-list data structure. 6203 * 6204 * This routine issues a Request Node Identification Data (RNID) Accept 6205 * (ACC) response. It constructs the RNID ACC response command according to 6206 * the proper @format and then calls the lpfc_sli_issue_iocb() routine to 6207 * issue the response. 6208 * 6209 * Note that the ndlp reference count will be incremented by 1 for holding the 6210 * ndlp and the reference to ndlp will be stored into the ndlp field of 6211 * the IOCB for the completion callback function. 6212 * 6213 * Return code 6214 * 0 - Successfully issued acc rnid response 6215 * 1 - Failed to issue acc rnid response 6216 **/ 6217 static int 6218 lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format, 6219 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp) 6220 { 6221 struct lpfc_hba *phba = vport->phba; 6222 RNID *rn; 6223 IOCB_t *icmd, *oldcmd; 6224 union lpfc_wqe128 *wqe; 6225 struct lpfc_iocbq *elsiocb; 6226 uint8_t *pcmd; 6227 uint16_t cmdsize; 6228 int rc; 6229 u32 ulp_context; 6230 6231 cmdsize = sizeof(uint32_t) + sizeof(uint32_t) 6232 + (2 * sizeof(struct lpfc_name)); 6233 if (format) 6234 cmdsize += sizeof(RNID_TOP_DISC); 6235 6236 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, 6237 ndlp->nlp_DID, ELS_CMD_ACC); 6238 if (!elsiocb) 6239 return 1; 6240 6241 if (phba->sli_rev == LPFC_SLI_REV4) { 6242 wqe = &elsiocb->wqe; 6243 bf_set(wqe_ctxt_tag, &wqe->generic.wqe_com, 6244 get_job_ulpcontext(phba, oldiocb)); /* Xri / rx_id */ 6245 ulp_context = get_job_ulpcontext(phba, elsiocb); 6246 bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com, 6247 get_job_rcvoxid(phba, oldiocb)); 6248 } else { 6249 icmd = &elsiocb->iocb; 6250 oldcmd = &oldiocb->iocb; 6251 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */ 6252 ulp_context = elsiocb->iocb.ulpContext; 6253 icmd->unsli3.rcvsli3.ox_id = 6254 oldcmd->unsli3.rcvsli3.ox_id; 6255 } 6256 6257 /* Xmit RNID ACC response tag <ulpIoTag> */ 6258 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, 6259 "0132 Xmit RNID ACC response tag x%x xri x%x\n", 6260 elsiocb->iotag, ulp_context); 6261 pcmd = (uint8_t *)elsiocb->cmd_dmabuf->virt; 6262 *((uint32_t *) (pcmd)) = ELS_CMD_ACC; 6263 pcmd += sizeof(uint32_t); 6264 6265 memset(pcmd, 0, sizeof(RNID)); 6266 rn = (RNID *) (pcmd); 6267 rn->Format = format; 6268 rn->CommonLen = (2 * sizeof(struct lpfc_name)); 6269 memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name)); 6270 memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); 6271 switch (format) { 6272 case 0: 6273 rn->SpecificLen = 0; 6274 break; 6275 case RNID_TOPOLOGY_DISC: 6276 rn->SpecificLen = sizeof(RNID_TOP_DISC); 6277 memcpy(&rn->un.topologyDisc.portName, 6278 &vport->fc_portname, sizeof(struct lpfc_name)); 6279 rn->un.topologyDisc.unitType = RNID_HBA; 6280 rn->un.topologyDisc.physPort = 0; 6281 rn->un.topologyDisc.attachedNodes = 0; 6282 break; 6283 default: 6284 rn->CommonLen = 0; 6285 rn->SpecificLen = 0; 6286 break; 6287 } 6288 6289 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, 6290 "Issue ACC RNID: did:x%x flg:x%lx refcnt %d", 6291 ndlp->nlp_DID, ndlp->nlp_flag, kref_read(&ndlp->kref)); 6292 6293 phba->fc_stat.elsXmitACC++; 6294 elsiocb->cmd_cmpl = lpfc_cmpl_els_rsp; 6295 elsiocb->ndlp = lpfc_nlp_get(ndlp); 6296 if (!elsiocb->ndlp) { 6297 lpfc_els_free_iocb(phba, elsiocb); 6298 return 1; 6299 } 6300 6301 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); 6302 if (rc == IOCB_ERROR) { 6303 lpfc_els_free_iocb(phba, elsiocb); 6304 lpfc_nlp_put(ndlp); 6305 return 1; 6306 } 6307 6308 return 0; 6309 } 6310 6311 /** 6312 * lpfc_els_clear_rrq - Clear the rq that this rrq describes. 6313 * @vport: pointer to a virtual N_Port data structure. 6314 * @iocb: pointer to the lpfc command iocb data structure. 6315 * @ndlp: pointer to a node-list data structure. 6316 * 6317 * Return 6318 **/ 6319 static void 6320 lpfc_els_clear_rrq(struct lpfc_vport *vport, 6321 struct lpfc_iocbq *iocb, struct lpfc_nodelist *ndlp) 6322 { 6323 struct lpfc_hba *phba = vport->phba; 6324 uint8_t *pcmd; 6325 struct RRQ *rrq; 6326 uint16_t rxid; 6327 uint16_t xri; 6328 struct lpfc_node_rrq *prrq; 6329 6330 6331 pcmd = (uint8_t *)iocb->cmd_dmabuf->virt; 6332 pcmd += sizeof(uint32_t); 6333 rrq = (struct RRQ *)pcmd; 6334 rrq->rrq_exchg = be32_to_cpu(rrq->rrq_exchg); 6335 rxid = bf_get(rrq_rxid, rrq); 6336 6337 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, 6338 "2883 Clear RRQ for SID:x%x OXID:x%x RXID:x%x" 6339 " x%x x%x\n", 6340 be32_to_cpu(bf_get(rrq_did, rrq)), 6341 bf_get(rrq_oxid, rrq), 6342 rxid, 6343 get_wqe_reqtag(iocb), 6344 get_job_ulpcontext(phba, iocb)); 6345 6346 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, 6347 "Clear RRQ: did:x%x flg:x%lx exchg:x%.08x", 6348 ndlp->nlp_DID, ndlp->nlp_flag, rrq->rrq_exchg); 6349 if (vport->fc_myDID == be32_to_cpu(bf_get(rrq_did, rrq))) 6350 xri = bf_get(rrq_oxid, rrq); 6351 else 6352 xri = rxid; 6353 prrq = lpfc_get_active_rrq(vport, xri, ndlp->nlp_DID); 6354 if (prrq) 6355 lpfc_clr_rrq_active(phba, xri, prrq); 6356 return; 6357 } 6358 6359 /** 6360 * lpfc_els_rsp_echo_acc - Issue echo acc response 6361 * @vport: pointer to a virtual N_Port data structure. 6362 * @data: pointer to echo data to return in the accept. 6363 * @oldiocb: pointer to the original lpfc command iocb data structure. 6364 * @ndlp: pointer to a node-list data structure. 6365 * 6366 * Return code 6367 * 0 - Successfully issued acc echo response 6368 * 1 - Failed to issue acc echo response 6369 **/ 6370 static int 6371 lpfc_els_rsp_echo_acc(struct lpfc_vport *vport, uint8_t *data, 6372 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp) 6373 { 6374 struct lpfc_hba *phba = vport->phba; 6375 IOCB_t *icmd, *oldcmd; 6376 union lpfc_wqe128 *wqe; 6377 struct lpfc_iocbq *elsiocb; 6378 uint8_t *pcmd; 6379 uint16_t cmdsize; 6380 int rc; 6381 u32 ulp_context; 6382 6383 if (phba->sli_rev == LPFC_SLI_REV4) 6384 cmdsize = oldiocb->wcqe_cmpl.total_data_placed; 6385 else 6386 cmdsize = oldiocb->iocb.unsli3.rcvsli3.acc_len; 6387 6388 /* The accumulated length can exceed the BPL_SIZE. For 6389 * now, use this as the limit 6390 */ 6391 if (cmdsize > LPFC_BPL_SIZE) 6392 cmdsize = LPFC_BPL_SIZE; 6393 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, 6394 ndlp->nlp_DID, ELS_CMD_ACC); 6395 if (!elsiocb) 6396 return 1; 6397 6398 if (phba->sli_rev == LPFC_SLI_REV4) { 6399 wqe = &elsiocb->wqe; 6400 bf_set(wqe_ctxt_tag, &wqe->generic.wqe_com, 6401 get_job_ulpcontext(phba, oldiocb)); /* Xri / rx_id */ 6402 ulp_context = get_job_ulpcontext(phba, elsiocb); 6403 bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com, 6404 get_job_rcvoxid(phba, oldiocb)); 6405 } else { 6406 icmd = &elsiocb->iocb; 6407 oldcmd = &oldiocb->iocb; 6408 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */ 6409 ulp_context = elsiocb->iocb.ulpContext; 6410 icmd->unsli3.rcvsli3.ox_id = 6411 oldcmd->unsli3.rcvsli3.ox_id; 6412 } 6413 6414 /* Xmit ECHO ACC response tag <ulpIoTag> */ 6415 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, 6416 "2876 Xmit ECHO ACC response tag x%x xri x%x\n", 6417 elsiocb->iotag, ulp_context); 6418 pcmd = (uint8_t *)elsiocb->cmd_dmabuf->virt; 6419 *((uint32_t *) (pcmd)) = ELS_CMD_ACC; 6420 pcmd += sizeof(uint32_t); 6421 memcpy(pcmd, data, cmdsize - sizeof(uint32_t)); 6422 6423 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, 6424 "Issue ACC ECHO: did:x%x flg:x%lx refcnt %d", 6425 ndlp->nlp_DID, ndlp->nlp_flag, kref_read(&ndlp->kref)); 6426 6427 phba->fc_stat.elsXmitACC++; 6428 elsiocb->cmd_cmpl = lpfc_cmpl_els_rsp; 6429 elsiocb->ndlp = lpfc_nlp_get(ndlp); 6430 if (!elsiocb->ndlp) { 6431 lpfc_els_free_iocb(phba, elsiocb); 6432 return 1; 6433 } 6434 6435 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); 6436 if (rc == IOCB_ERROR) { 6437 lpfc_els_free_iocb(phba, elsiocb); 6438 lpfc_nlp_put(ndlp); 6439 return 1; 6440 } 6441 6442 return 0; 6443 } 6444 6445 /** 6446 * lpfc_els_disc_adisc - Issue remaining adisc iocbs to npr nodes of a vport 6447 * @vport: pointer to a host virtual N_Port data structure. 6448 * 6449 * This routine issues Address Discover (ADISC) ELS commands to those 6450 * N_Ports which are in node port recovery state and ADISC has not been issued 6451 * for the @vport. Each time an ELS ADISC IOCB is issued by invoking the 6452 * lpfc_issue_els_adisc() routine, the per @vport number of discover count 6453 * (num_disc_nodes) shall be incremented. If the num_disc_nodes reaches a 6454 * pre-configured threshold (cfg_discovery_threads), the @vport fc_flag will 6455 * be marked with FC_NLP_MORE bit and the process of issuing remaining ADISC 6456 * IOCBs quit for later pick up. On the other hand, after walking through 6457 * all the ndlps with the @vport and there is none ADISC IOCB issued, the 6458 * @vport fc_flag shall be cleared with FC_NLP_MORE bit indicating there is 6459 * no more ADISC need to be sent. 6460 * 6461 * Return code 6462 * The number of N_Ports with adisc issued. 6463 **/ 6464 int 6465 lpfc_els_disc_adisc(struct lpfc_vport *vport) 6466 { 6467 struct lpfc_nodelist *ndlp, *next_ndlp; 6468 int sentadisc = 0; 6469 6470 /* go thru NPR nodes and issue any remaining ELS ADISCs */ 6471 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) { 6472 6473 if (ndlp->nlp_state != NLP_STE_NPR_NODE || 6474 !test_bit(NLP_NPR_ADISC, &ndlp->nlp_flag)) 6475 continue; 6476 6477 clear_bit(NLP_NPR_ADISC, &ndlp->nlp_flag); 6478 6479 if (!test_bit(NLP_NPR_2B_DISC, &ndlp->nlp_flag)) { 6480 /* This node was marked for ADISC but was not picked 6481 * for discovery. This is possible if the node was 6482 * missing in gidft response. 6483 * 6484 * At time of marking node for ADISC, we skipped unreg 6485 * from backend 6486 */ 6487 lpfc_nlp_unreg_node(vport, ndlp); 6488 lpfc_unreg_rpi(vport, ndlp); 6489 continue; 6490 } 6491 6492 ndlp->nlp_prev_state = ndlp->nlp_state; 6493 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE); 6494 lpfc_issue_els_adisc(vport, ndlp, 0); 6495 sentadisc++; 6496 vport->num_disc_nodes++; 6497 if (vport->num_disc_nodes >= 6498 vport->cfg_discovery_threads) { 6499 set_bit(FC_NLP_MORE, &vport->fc_flag); 6500 break; 6501 } 6502 6503 } 6504 if (sentadisc == 0) 6505 clear_bit(FC_NLP_MORE, &vport->fc_flag); 6506 return sentadisc; 6507 } 6508 6509 /** 6510 * lpfc_els_disc_plogi - Issue plogi for all npr nodes of a vport before adisc 6511 * @vport: pointer to a host virtual N_Port data structure. 6512 * 6513 * This routine issues Port Login (PLOGI) ELS commands to all the N_Ports 6514 * which are in node port recovery state, with a @vport. Each time an ELS 6515 * ADISC PLOGI IOCB is issued by invoking the lpfc_issue_els_plogi() routine, 6516 * the per @vport number of discover count (num_disc_nodes) shall be 6517 * incremented. If the num_disc_nodes reaches a pre-configured threshold 6518 * (cfg_discovery_threads), the @vport fc_flag will be marked with FC_NLP_MORE 6519 * bit set and quit the process of issuing remaining ADISC PLOGIN IOCBs for 6520 * later pick up. On the other hand, after walking through all the ndlps with 6521 * the @vport and there is none ADISC PLOGI IOCB issued, the @vport fc_flag 6522 * shall be cleared with the FC_NLP_MORE bit indicating there is no more ADISC 6523 * PLOGI need to be sent. 6524 * 6525 * Return code 6526 * The number of N_Ports with plogi issued. 6527 **/ 6528 int 6529 lpfc_els_disc_plogi(struct lpfc_vport *vport) 6530 { 6531 struct lpfc_nodelist *ndlp, *next_ndlp; 6532 int sentplogi = 0; 6533 6534 /* go thru NPR nodes and issue any remaining ELS PLOGIs */ 6535 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) { 6536 if (ndlp->nlp_state == NLP_STE_NPR_NODE && 6537 test_bit(NLP_NPR_2B_DISC, &ndlp->nlp_flag) && 6538 !test_bit(NLP_DELAY_TMO, &ndlp->nlp_flag) && 6539 !test_bit(NLP_NPR_ADISC, &ndlp->nlp_flag)) { 6540 ndlp->nlp_prev_state = ndlp->nlp_state; 6541 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); 6542 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0); 6543 sentplogi++; 6544 vport->num_disc_nodes++; 6545 if (vport->num_disc_nodes >= 6546 vport->cfg_discovery_threads) { 6547 set_bit(FC_NLP_MORE, &vport->fc_flag); 6548 break; 6549 } 6550 } 6551 } 6552 6553 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, 6554 "6452 Discover PLOGI %d flag x%lx\n", 6555 sentplogi, vport->fc_flag); 6556 6557 if (sentplogi) 6558 lpfc_set_disctmo(vport); 6559 else 6560 clear_bit(FC_NLP_MORE, &vport->fc_flag); 6561 return sentplogi; 6562 } 6563 6564 static uint32_t 6565 lpfc_rdp_res_link_service(struct fc_rdp_link_service_desc *desc, 6566 uint32_t word0) 6567 { 6568 6569 desc->tag = cpu_to_be32(RDP_LINK_SERVICE_DESC_TAG); 6570 desc->payload.els_req = word0; 6571 desc->length = cpu_to_be32(sizeof(desc->payload)); 6572 6573 return sizeof(struct fc_rdp_link_service_desc); 6574 } 6575 6576 static uint32_t 6577 lpfc_rdp_res_sfp_desc(struct fc_rdp_sfp_desc *desc, 6578 uint8_t *page_a0, uint8_t *page_a2) 6579 { 6580 uint16_t wavelength; 6581 uint16_t temperature; 6582 uint16_t rx_power; 6583 uint16_t tx_bias; 6584 uint16_t tx_power; 6585 uint16_t vcc; 6586 uint16_t flag = 0; 6587 struct sff_trasnceiver_codes_byte4 *trasn_code_byte4; 6588 struct sff_trasnceiver_codes_byte5 *trasn_code_byte5; 6589 6590 desc->tag = cpu_to_be32(RDP_SFP_DESC_TAG); 6591 6592 trasn_code_byte4 = (struct sff_trasnceiver_codes_byte4 *) 6593 &page_a0[SSF_TRANSCEIVER_CODE_B4]; 6594 trasn_code_byte5 = (struct sff_trasnceiver_codes_byte5 *) 6595 &page_a0[SSF_TRANSCEIVER_CODE_B5]; 6596 6597 if ((trasn_code_byte4->fc_sw_laser) || 6598 (trasn_code_byte5->fc_sw_laser_sl) || 6599 (trasn_code_byte5->fc_sw_laser_sn)) { /* check if its short WL */ 6600 flag |= (SFP_FLAG_PT_SWLASER << SFP_FLAG_PT_SHIFT); 6601 } else if (trasn_code_byte4->fc_lw_laser) { 6602 wavelength = (page_a0[SSF_WAVELENGTH_B1] << 8) | 6603 page_a0[SSF_WAVELENGTH_B0]; 6604 if (wavelength == SFP_WAVELENGTH_LC1310) 6605 flag |= SFP_FLAG_PT_LWLASER_LC1310 << SFP_FLAG_PT_SHIFT; 6606 if (wavelength == SFP_WAVELENGTH_LL1550) 6607 flag |= SFP_FLAG_PT_LWLASER_LL1550 << SFP_FLAG_PT_SHIFT; 6608 } 6609 /* check if its SFP+ */ 6610 flag |= ((page_a0[SSF_IDENTIFIER] == SFF_PG0_IDENT_SFP) ? 6611 SFP_FLAG_CT_SFP_PLUS : SFP_FLAG_CT_UNKNOWN) 6612 << SFP_FLAG_CT_SHIFT; 6613 6614 /* check if its OPTICAL */ 6615 flag |= ((page_a0[SSF_CONNECTOR] == SFF_PG0_CONNECTOR_LC) ? 6616 SFP_FLAG_IS_OPTICAL_PORT : 0) 6617 << SFP_FLAG_IS_OPTICAL_SHIFT; 6618 6619 temperature = (page_a2[SFF_TEMPERATURE_B1] << 8 | 6620 page_a2[SFF_TEMPERATURE_B0]); 6621 vcc = (page_a2[SFF_VCC_B1] << 8 | 6622 page_a2[SFF_VCC_B0]); 6623 tx_power = (page_a2[SFF_TXPOWER_B1] << 8 | 6624 page_a2[SFF_TXPOWER_B0]); 6625 tx_bias = (page_a2[SFF_TX_BIAS_CURRENT_B1] << 8 | 6626 page_a2[SFF_TX_BIAS_CURRENT_B0]); 6627 rx_power = (page_a2[SFF_RXPOWER_B1] << 8 | 6628 page_a2[SFF_RXPOWER_B0]); 6629 desc->sfp_info.temperature = cpu_to_be16(temperature); 6630 desc->sfp_info.rx_power = cpu_to_be16(rx_power); 6631 desc->sfp_info.tx_bias = cpu_to_be16(tx_bias); 6632 desc->sfp_info.tx_power = cpu_to_be16(tx_power); 6633 desc->sfp_info.vcc = cpu_to_be16(vcc); 6634 6635 desc->sfp_info.flags = cpu_to_be16(flag); 6636 desc->length = cpu_to_be32(sizeof(desc->sfp_info)); 6637 6638 return sizeof(struct fc_rdp_sfp_desc); 6639 } 6640 6641 static uint32_t 6642 lpfc_rdp_res_link_error(struct fc_rdp_link_error_status_desc *desc, 6643 READ_LNK_VAR *stat) 6644 { 6645 uint32_t type; 6646 6647 desc->tag = cpu_to_be32(RDP_LINK_ERROR_STATUS_DESC_TAG); 6648 6649 type = VN_PT_PHY_PF_PORT << VN_PT_PHY_SHIFT; 6650 6651 desc->info.port_type = cpu_to_be32(type); 6652 6653 desc->info.link_status.link_failure_cnt = 6654 cpu_to_be32(stat->linkFailureCnt); 6655 desc->info.link_status.loss_of_synch_cnt = 6656 cpu_to_be32(stat->lossSyncCnt); 6657 desc->info.link_status.loss_of_signal_cnt = 6658 cpu_to_be32(stat->lossSignalCnt); 6659 desc->info.link_status.primitive_seq_proto_err = 6660 cpu_to_be32(stat->primSeqErrCnt); 6661 desc->info.link_status.invalid_trans_word = 6662 cpu_to_be32(stat->invalidXmitWord); 6663 desc->info.link_status.invalid_crc_cnt = cpu_to_be32(stat->crcCnt); 6664 6665 desc->length = cpu_to_be32(sizeof(desc->info)); 6666 6667 return sizeof(struct fc_rdp_link_error_status_desc); 6668 } 6669 6670 static uint32_t 6671 lpfc_rdp_res_bbc_desc(struct fc_rdp_bbc_desc *desc, READ_LNK_VAR *stat, 6672 struct lpfc_vport *vport) 6673 { 6674 uint32_t bbCredit; 6675 6676 desc->tag = cpu_to_be32(RDP_BBC_DESC_TAG); 6677 6678 bbCredit = vport->fc_sparam.cmn.bbCreditLsb | 6679 (vport->fc_sparam.cmn.bbCreditMsb << 8); 6680 desc->bbc_info.port_bbc = cpu_to_be32(bbCredit); 6681 if (vport->phba->fc_topology != LPFC_TOPOLOGY_LOOP) { 6682 bbCredit = vport->phba->fc_fabparam.cmn.bbCreditLsb | 6683 (vport->phba->fc_fabparam.cmn.bbCreditMsb << 8); 6684 desc->bbc_info.attached_port_bbc = cpu_to_be32(bbCredit); 6685 } else { 6686 desc->bbc_info.attached_port_bbc = 0; 6687 } 6688 6689 desc->bbc_info.rtt = 0; 6690 desc->length = cpu_to_be32(sizeof(desc->bbc_info)); 6691 6692 return sizeof(struct fc_rdp_bbc_desc); 6693 } 6694 6695 static uint32_t 6696 lpfc_rdp_res_oed_temp_desc(struct lpfc_hba *phba, 6697 struct fc_rdp_oed_sfp_desc *desc, uint8_t *page_a2) 6698 { 6699 uint32_t flags = 0; 6700 6701 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG); 6702 6703 desc->oed_info.hi_alarm = page_a2[SSF_TEMP_HIGH_ALARM]; 6704 desc->oed_info.lo_alarm = page_a2[SSF_TEMP_LOW_ALARM]; 6705 desc->oed_info.hi_warning = page_a2[SSF_TEMP_HIGH_WARNING]; 6706 desc->oed_info.lo_warning = page_a2[SSF_TEMP_LOW_WARNING]; 6707 6708 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_TEMPERATURE) 6709 flags |= RDP_OET_HIGH_ALARM; 6710 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_TEMPERATURE) 6711 flags |= RDP_OET_LOW_ALARM; 6712 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_TEMPERATURE) 6713 flags |= RDP_OET_HIGH_WARNING; 6714 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_TEMPERATURE) 6715 flags |= RDP_OET_LOW_WARNING; 6716 6717 flags |= ((0xf & RDP_OED_TEMPERATURE) << RDP_OED_TYPE_SHIFT); 6718 desc->oed_info.function_flags = cpu_to_be32(flags); 6719 desc->length = cpu_to_be32(sizeof(desc->oed_info)); 6720 return sizeof(struct fc_rdp_oed_sfp_desc); 6721 } 6722 6723 static uint32_t 6724 lpfc_rdp_res_oed_voltage_desc(struct lpfc_hba *phba, 6725 struct fc_rdp_oed_sfp_desc *desc, 6726 uint8_t *page_a2) 6727 { 6728 uint32_t flags = 0; 6729 6730 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG); 6731 6732 desc->oed_info.hi_alarm = page_a2[SSF_VOLTAGE_HIGH_ALARM]; 6733 desc->oed_info.lo_alarm = page_a2[SSF_VOLTAGE_LOW_ALARM]; 6734 desc->oed_info.hi_warning = page_a2[SSF_VOLTAGE_HIGH_WARNING]; 6735 desc->oed_info.lo_warning = page_a2[SSF_VOLTAGE_LOW_WARNING]; 6736 6737 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_VOLTAGE) 6738 flags |= RDP_OET_HIGH_ALARM; 6739 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_VOLTAGE) 6740 flags |= RDP_OET_LOW_ALARM; 6741 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_VOLTAGE) 6742 flags |= RDP_OET_HIGH_WARNING; 6743 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_VOLTAGE) 6744 flags |= RDP_OET_LOW_WARNING; 6745 6746 flags |= ((0xf & RDP_OED_VOLTAGE) << RDP_OED_TYPE_SHIFT); 6747 desc->oed_info.function_flags = cpu_to_be32(flags); 6748 desc->length = cpu_to_be32(sizeof(desc->oed_info)); 6749 return sizeof(struct fc_rdp_oed_sfp_desc); 6750 } 6751 6752 static uint32_t 6753 lpfc_rdp_res_oed_txbias_desc(struct lpfc_hba *phba, 6754 struct fc_rdp_oed_sfp_desc *desc, 6755 uint8_t *page_a2) 6756 { 6757 uint32_t flags = 0; 6758 6759 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG); 6760 6761 desc->oed_info.hi_alarm = page_a2[SSF_BIAS_HIGH_ALARM]; 6762 desc->oed_info.lo_alarm = page_a2[SSF_BIAS_LOW_ALARM]; 6763 desc->oed_info.hi_warning = page_a2[SSF_BIAS_HIGH_WARNING]; 6764 desc->oed_info.lo_warning = page_a2[SSF_BIAS_LOW_WARNING]; 6765 6766 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_TXBIAS) 6767 flags |= RDP_OET_HIGH_ALARM; 6768 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_TXBIAS) 6769 flags |= RDP_OET_LOW_ALARM; 6770 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_TXBIAS) 6771 flags |= RDP_OET_HIGH_WARNING; 6772 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_TXBIAS) 6773 flags |= RDP_OET_LOW_WARNING; 6774 6775 flags |= ((0xf & RDP_OED_TXBIAS) << RDP_OED_TYPE_SHIFT); 6776 desc->oed_info.function_flags = cpu_to_be32(flags); 6777 desc->length = cpu_to_be32(sizeof(desc->oed_info)); 6778 return sizeof(struct fc_rdp_oed_sfp_desc); 6779 } 6780 6781 static uint32_t 6782 lpfc_rdp_res_oed_txpower_desc(struct lpfc_hba *phba, 6783 struct fc_rdp_oed_sfp_desc *desc, 6784 uint8_t *page_a2) 6785 { 6786 uint32_t flags = 0; 6787 6788 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG); 6789 6790 desc->oed_info.hi_alarm = page_a2[SSF_TXPOWER_HIGH_ALARM]; 6791 desc->oed_info.lo_alarm = page_a2[SSF_TXPOWER_LOW_ALARM]; 6792 desc->oed_info.hi_warning = page_a2[SSF_TXPOWER_HIGH_WARNING]; 6793 desc->oed_info.lo_warning = page_a2[SSF_TXPOWER_LOW_WARNING]; 6794 6795 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_TXPOWER) 6796 flags |= RDP_OET_HIGH_ALARM; 6797 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_TXPOWER) 6798 flags |= RDP_OET_LOW_ALARM; 6799 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_TXPOWER) 6800 flags |= RDP_OET_HIGH_WARNING; 6801 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_TXPOWER) 6802 flags |= RDP_OET_LOW_WARNING; 6803 6804 flags |= ((0xf & RDP_OED_TXPOWER) << RDP_OED_TYPE_SHIFT); 6805 desc->oed_info.function_flags = cpu_to_be32(flags); 6806 desc->length = cpu_to_be32(sizeof(desc->oed_info)); 6807 return sizeof(struct fc_rdp_oed_sfp_desc); 6808 } 6809 6810 6811 static uint32_t 6812 lpfc_rdp_res_oed_rxpower_desc(struct lpfc_hba *phba, 6813 struct fc_rdp_oed_sfp_desc *desc, 6814 uint8_t *page_a2) 6815 { 6816 uint32_t flags = 0; 6817 6818 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG); 6819 6820 desc->oed_info.hi_alarm = page_a2[SSF_RXPOWER_HIGH_ALARM]; 6821 desc->oed_info.lo_alarm = page_a2[SSF_RXPOWER_LOW_ALARM]; 6822 desc->oed_info.hi_warning = page_a2[SSF_RXPOWER_HIGH_WARNING]; 6823 desc->oed_info.lo_warning = page_a2[SSF_RXPOWER_LOW_WARNING]; 6824 6825 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_RXPOWER) 6826 flags |= RDP_OET_HIGH_ALARM; 6827 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_RXPOWER) 6828 flags |= RDP_OET_LOW_ALARM; 6829 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_RXPOWER) 6830 flags |= RDP_OET_HIGH_WARNING; 6831 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_RXPOWER) 6832 flags |= RDP_OET_LOW_WARNING; 6833 6834 flags |= ((0xf & RDP_OED_RXPOWER) << RDP_OED_TYPE_SHIFT); 6835 desc->oed_info.function_flags = cpu_to_be32(flags); 6836 desc->length = cpu_to_be32(sizeof(desc->oed_info)); 6837 return sizeof(struct fc_rdp_oed_sfp_desc); 6838 } 6839 6840 static uint32_t 6841 lpfc_rdp_res_opd_desc(struct fc_rdp_opd_sfp_desc *desc, 6842 uint8_t *page_a0, struct lpfc_vport *vport) 6843 { 6844 desc->tag = cpu_to_be32(RDP_OPD_DESC_TAG); 6845 memcpy(desc->opd_info.vendor_name, &page_a0[SSF_VENDOR_NAME], 16); 6846 memcpy(desc->opd_info.model_number, &page_a0[SSF_VENDOR_PN], 16); 6847 memcpy(desc->opd_info.serial_number, &page_a0[SSF_VENDOR_SN], 16); 6848 memcpy(desc->opd_info.revision, &page_a0[SSF_VENDOR_REV], 4); 6849 memcpy(desc->opd_info.date, &page_a0[SSF_DATE_CODE], 8); 6850 desc->length = cpu_to_be32(sizeof(desc->opd_info)); 6851 return sizeof(struct fc_rdp_opd_sfp_desc); 6852 } 6853 6854 static uint32_t 6855 lpfc_rdp_res_fec_desc(struct fc_fec_rdp_desc *desc, READ_LNK_VAR *stat) 6856 { 6857 if (bf_get(lpfc_read_link_stat_gec2, stat) == 0) 6858 return 0; 6859 desc->tag = cpu_to_be32(RDP_FEC_DESC_TAG); 6860 6861 desc->info.CorrectedBlocks = 6862 cpu_to_be32(stat->fecCorrBlkCount); 6863 desc->info.UncorrectableBlocks = 6864 cpu_to_be32(stat->fecUncorrBlkCount); 6865 6866 desc->length = cpu_to_be32(sizeof(desc->info)); 6867 6868 return sizeof(struct fc_fec_rdp_desc); 6869 } 6870 6871 static uint32_t 6872 lpfc_rdp_res_speed(struct fc_rdp_port_speed_desc *desc, struct lpfc_hba *phba) 6873 { 6874 uint16_t rdp_cap = 0; 6875 uint16_t rdp_speed; 6876 6877 desc->tag = cpu_to_be32(RDP_PORT_SPEED_DESC_TAG); 6878 6879 switch (phba->fc_linkspeed) { 6880 case LPFC_LINK_SPEED_1GHZ: 6881 rdp_speed = RDP_PS_1GB; 6882 break; 6883 case LPFC_LINK_SPEED_2GHZ: 6884 rdp_speed = RDP_PS_2GB; 6885 break; 6886 case LPFC_LINK_SPEED_4GHZ: 6887 rdp_speed = RDP_PS_4GB; 6888 break; 6889 case LPFC_LINK_SPEED_8GHZ: 6890 rdp_speed = RDP_PS_8GB; 6891 break; 6892 case LPFC_LINK_SPEED_10GHZ: 6893 rdp_speed = RDP_PS_10GB; 6894 break; 6895 case LPFC_LINK_SPEED_16GHZ: 6896 rdp_speed = RDP_PS_16GB; 6897 break; 6898 case LPFC_LINK_SPEED_32GHZ: 6899 rdp_speed = RDP_PS_32GB; 6900 break; 6901 case LPFC_LINK_SPEED_64GHZ: 6902 rdp_speed = RDP_PS_64GB; 6903 break; 6904 case LPFC_LINK_SPEED_128GHZ: 6905 rdp_speed = RDP_PS_128GB; 6906 break; 6907 case LPFC_LINK_SPEED_256GHZ: 6908 rdp_speed = RDP_PS_256GB; 6909 break; 6910 default: 6911 rdp_speed = RDP_PS_UNKNOWN; 6912 break; 6913 } 6914 6915 desc->info.port_speed.speed = cpu_to_be16(rdp_speed); 6916 6917 if (phba->lmt & LMT_256Gb) 6918 rdp_cap |= RDP_PS_256GB; 6919 if (phba->lmt & LMT_128Gb) 6920 rdp_cap |= RDP_PS_128GB; 6921 if (phba->lmt & LMT_64Gb) 6922 rdp_cap |= RDP_PS_64GB; 6923 if (phba->lmt & LMT_32Gb) 6924 rdp_cap |= RDP_PS_32GB; 6925 if (phba->lmt & LMT_16Gb) 6926 rdp_cap |= RDP_PS_16GB; 6927 if (phba->lmt & LMT_10Gb) 6928 rdp_cap |= RDP_PS_10GB; 6929 if (phba->lmt & LMT_8Gb) 6930 rdp_cap |= RDP_PS_8GB; 6931 if (phba->lmt & LMT_4Gb) 6932 rdp_cap |= RDP_PS_4GB; 6933 if (phba->lmt & LMT_2Gb) 6934 rdp_cap |= RDP_PS_2GB; 6935 if (phba->lmt & LMT_1Gb) 6936 rdp_cap |= RDP_PS_1GB; 6937 6938 if (rdp_cap == 0) 6939 rdp_cap = RDP_CAP_UNKNOWN; 6940 if (phba->cfg_link_speed != LPFC_USER_LINK_SPEED_AUTO) 6941 rdp_cap |= RDP_CAP_USER_CONFIGURED; 6942 6943 desc->info.port_speed.capabilities = cpu_to_be16(rdp_cap); 6944 desc->length = cpu_to_be32(sizeof(desc->info)); 6945 return sizeof(struct fc_rdp_port_speed_desc); 6946 } 6947 6948 static uint32_t 6949 lpfc_rdp_res_diag_port_names(struct fc_rdp_port_name_desc *desc, 6950 struct lpfc_vport *vport) 6951 { 6952 6953 desc->tag = cpu_to_be32(RDP_PORT_NAMES_DESC_TAG); 6954 6955 memcpy(desc->port_names.wwnn, &vport->fc_nodename, 6956 sizeof(desc->port_names.wwnn)); 6957 6958 memcpy(desc->port_names.wwpn, &vport->fc_portname, 6959 sizeof(desc->port_names.wwpn)); 6960 6961 desc->length = cpu_to_be32(sizeof(desc->port_names)); 6962 return sizeof(struct fc_rdp_port_name_desc); 6963 } 6964 6965 static uint32_t 6966 lpfc_rdp_res_attach_port_names(struct fc_rdp_port_name_desc *desc, 6967 struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) 6968 { 6969 6970 desc->tag = cpu_to_be32(RDP_PORT_NAMES_DESC_TAG); 6971 if (test_bit(FC_FABRIC, &vport->fc_flag)) { 6972 memcpy(desc->port_names.wwnn, &vport->fabric_nodename, 6973 sizeof(desc->port_names.wwnn)); 6974 6975 memcpy(desc->port_names.wwpn, &vport->fabric_portname, 6976 sizeof(desc->port_names.wwpn)); 6977 } else { /* Point to Point */ 6978 memcpy(desc->port_names.wwnn, &ndlp->nlp_nodename, 6979 sizeof(desc->port_names.wwnn)); 6980 6981 memcpy(desc->port_names.wwpn, &ndlp->nlp_portname, 6982 sizeof(desc->port_names.wwpn)); 6983 } 6984 6985 desc->length = cpu_to_be32(sizeof(desc->port_names)); 6986 return sizeof(struct fc_rdp_port_name_desc); 6987 } 6988 6989 static void 6990 lpfc_els_rdp_cmpl(struct lpfc_hba *phba, struct lpfc_rdp_context *rdp_context, 6991 int status) 6992 { 6993 struct lpfc_nodelist *ndlp = rdp_context->ndlp; 6994 struct lpfc_vport *vport = ndlp->vport; 6995 struct lpfc_iocbq *elsiocb; 6996 struct ulp_bde64 *bpl; 6997 IOCB_t *icmd; 6998 union lpfc_wqe128 *wqe; 6999 uint8_t *pcmd; 7000 struct ls_rjt *stat; 7001 struct fc_rdp_res_frame *rdp_res; 7002 uint32_t cmdsize, len; 7003 uint16_t *flag_ptr; 7004 int rc; 7005 u32 ulp_context; 7006 7007 if (status != SUCCESS) 7008 goto error; 7009 7010 /* This will change once we know the true size of the RDP payload */ 7011 cmdsize = sizeof(struct fc_rdp_res_frame); 7012 7013 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, 7014 lpfc_max_els_tries, rdp_context->ndlp, 7015 rdp_context->ndlp->nlp_DID, ELS_CMD_ACC); 7016 if (!elsiocb) 7017 goto free_rdp_context; 7018 7019 ulp_context = get_job_ulpcontext(phba, elsiocb); 7020 if (phba->sli_rev == LPFC_SLI_REV4) { 7021 wqe = &elsiocb->wqe; 7022 /* ox-id of the frame */ 7023 bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com, 7024 rdp_context->ox_id); 7025 bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com, 7026 rdp_context->rx_id); 7027 } else { 7028 icmd = &elsiocb->iocb; 7029 icmd->ulpContext = rdp_context->rx_id; 7030 icmd->unsli3.rcvsli3.ox_id = rdp_context->ox_id; 7031 } 7032 7033 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, 7034 "2171 Xmit RDP response tag x%x xri x%x, " 7035 "did x%x, nlp_flag x%lx, nlp_state x%x, rpi x%x", 7036 elsiocb->iotag, ulp_context, 7037 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, 7038 ndlp->nlp_rpi); 7039 rdp_res = (struct fc_rdp_res_frame *)elsiocb->cmd_dmabuf->virt; 7040 pcmd = (uint8_t *)elsiocb->cmd_dmabuf->virt; 7041 memset(pcmd, 0, sizeof(struct fc_rdp_res_frame)); 7042 *((uint32_t *) (pcmd)) = ELS_CMD_ACC; 7043 7044 /* Update Alarm and Warning */ 7045 flag_ptr = (uint16_t *)(rdp_context->page_a2 + SSF_ALARM_FLAGS); 7046 phba->sfp_alarm |= *flag_ptr; 7047 flag_ptr = (uint16_t *)(rdp_context->page_a2 + SSF_WARNING_FLAGS); 7048 phba->sfp_warning |= *flag_ptr; 7049 7050 /* For RDP payload */ 7051 len = 8; 7052 len += lpfc_rdp_res_link_service((struct fc_rdp_link_service_desc *) 7053 (len + pcmd), ELS_CMD_RDP); 7054 7055 len += lpfc_rdp_res_sfp_desc((struct fc_rdp_sfp_desc *)(len + pcmd), 7056 rdp_context->page_a0, rdp_context->page_a2); 7057 len += lpfc_rdp_res_speed((struct fc_rdp_port_speed_desc *)(len + pcmd), 7058 phba); 7059 len += lpfc_rdp_res_link_error((struct fc_rdp_link_error_status_desc *) 7060 (len + pcmd), &rdp_context->link_stat); 7061 len += lpfc_rdp_res_diag_port_names((struct fc_rdp_port_name_desc *) 7062 (len + pcmd), vport); 7063 len += lpfc_rdp_res_attach_port_names((struct fc_rdp_port_name_desc *) 7064 (len + pcmd), vport, ndlp); 7065 len += lpfc_rdp_res_fec_desc((struct fc_fec_rdp_desc *)(len + pcmd), 7066 &rdp_context->link_stat); 7067 len += lpfc_rdp_res_bbc_desc((struct fc_rdp_bbc_desc *)(len + pcmd), 7068 &rdp_context->link_stat, vport); 7069 len += lpfc_rdp_res_oed_temp_desc(phba, 7070 (struct fc_rdp_oed_sfp_desc *)(len + pcmd), 7071 rdp_context->page_a2); 7072 len += lpfc_rdp_res_oed_voltage_desc(phba, 7073 (struct fc_rdp_oed_sfp_desc *)(len + pcmd), 7074 rdp_context->page_a2); 7075 len += lpfc_rdp_res_oed_txbias_desc(phba, 7076 (struct fc_rdp_oed_sfp_desc *)(len + pcmd), 7077 rdp_context->page_a2); 7078 len += lpfc_rdp_res_oed_txpower_desc(phba, 7079 (struct fc_rdp_oed_sfp_desc *)(len + pcmd), 7080 rdp_context->page_a2); 7081 len += lpfc_rdp_res_oed_rxpower_desc(phba, 7082 (struct fc_rdp_oed_sfp_desc *)(len + pcmd), 7083 rdp_context->page_a2); 7084 len += lpfc_rdp_res_opd_desc((struct fc_rdp_opd_sfp_desc *)(len + pcmd), 7085 rdp_context->page_a0, vport); 7086 7087 rdp_res->length = cpu_to_be32(len - 8); 7088 elsiocb->cmd_cmpl = lpfc_cmpl_els_rsp; 7089 7090 /* Now that we know the true size of the payload, update the BPL */ 7091 bpl = (struct ulp_bde64 *)elsiocb->bpl_dmabuf->virt; 7092 bpl->tus.f.bdeSize = len; 7093 bpl->tus.f.bdeFlags = 0; 7094 bpl->tus.w = le32_to_cpu(bpl->tus.w); 7095 7096 phba->fc_stat.elsXmitACC++; 7097 elsiocb->ndlp = lpfc_nlp_get(ndlp); 7098 if (!elsiocb->ndlp) { 7099 lpfc_els_free_iocb(phba, elsiocb); 7100 goto free_rdp_context; 7101 } 7102 7103 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); 7104 if (rc == IOCB_ERROR) { 7105 lpfc_els_free_iocb(phba, elsiocb); 7106 lpfc_nlp_put(ndlp); 7107 } 7108 7109 goto free_rdp_context; 7110 7111 error: 7112 cmdsize = 2 * sizeof(uint32_t); 7113 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, lpfc_max_els_tries, 7114 ndlp, ndlp->nlp_DID, ELS_CMD_LS_RJT); 7115 if (!elsiocb) 7116 goto free_rdp_context; 7117 7118 if (phba->sli_rev == LPFC_SLI_REV4) { 7119 wqe = &elsiocb->wqe; 7120 /* ox-id of the frame */ 7121 bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com, 7122 rdp_context->ox_id); 7123 bf_set(wqe_ctxt_tag, 7124 &wqe->xmit_els_rsp.wqe_com, 7125 rdp_context->rx_id); 7126 } else { 7127 icmd = &elsiocb->iocb; 7128 icmd->ulpContext = rdp_context->rx_id; 7129 icmd->unsli3.rcvsli3.ox_id = rdp_context->ox_id; 7130 } 7131 7132 pcmd = (uint8_t *)elsiocb->cmd_dmabuf->virt; 7133 7134 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT; 7135 stat = (struct ls_rjt *)(pcmd + sizeof(uint32_t)); 7136 stat->un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; 7137 7138 phba->fc_stat.elsXmitLSRJT++; 7139 elsiocb->cmd_cmpl = lpfc_cmpl_els_rsp; 7140 elsiocb->ndlp = lpfc_nlp_get(ndlp); 7141 if (!elsiocb->ndlp) { 7142 lpfc_els_free_iocb(phba, elsiocb); 7143 goto free_rdp_context; 7144 } 7145 7146 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); 7147 if (rc == IOCB_ERROR) { 7148 lpfc_els_free_iocb(phba, elsiocb); 7149 lpfc_nlp_put(ndlp); 7150 } 7151 7152 free_rdp_context: 7153 /* This reference put is for the original unsolicited RDP. If the 7154 * prep failed, there is no reference to remove. 7155 */ 7156 lpfc_nlp_put(ndlp); 7157 kfree(rdp_context); 7158 } 7159 7160 static int 7161 lpfc_get_rdp_info(struct lpfc_hba *phba, struct lpfc_rdp_context *rdp_context) 7162 { 7163 LPFC_MBOXQ_t *mbox = NULL; 7164 int rc; 7165 7166 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); 7167 if (!mbox) { 7168 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_ELS, 7169 "7105 failed to allocate mailbox memory"); 7170 return 1; 7171 } 7172 7173 if (lpfc_sli4_dump_page_a0(phba, mbox)) 7174 goto rdp_fail; 7175 mbox->vport = rdp_context->ndlp->vport; 7176 mbox->mbox_cmpl = lpfc_mbx_cmpl_rdp_page_a0; 7177 mbox->ctx_u.rdp = rdp_context; 7178 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); 7179 if (rc == MBX_NOT_FINISHED) { 7180 lpfc_mbox_rsrc_cleanup(phba, mbox, MBOX_THD_UNLOCKED); 7181 return 1; 7182 } 7183 7184 return 0; 7185 7186 rdp_fail: 7187 mempool_free(mbox, phba->mbox_mem_pool); 7188 return 1; 7189 } 7190 7191 int lpfc_get_sfp_info_wait(struct lpfc_hba *phba, 7192 struct lpfc_rdp_context *rdp_context) 7193 { 7194 LPFC_MBOXQ_t *mbox = NULL; 7195 int rc; 7196 struct lpfc_dmabuf *mp; 7197 struct lpfc_dmabuf *mpsave; 7198 void *virt; 7199 MAILBOX_t *mb; 7200 7201 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); 7202 if (!mbox) { 7203 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_ELS, 7204 "7205 failed to allocate mailbox memory"); 7205 return 1; 7206 } 7207 7208 if (lpfc_sli4_dump_page_a0(phba, mbox)) 7209 goto sfp_fail; 7210 mp = mbox->ctx_buf; 7211 mpsave = mp; 7212 virt = mp->virt; 7213 if (phba->sli_rev < LPFC_SLI_REV4) { 7214 mb = &mbox->u.mb; 7215 mb->un.varDmp.cv = 1; 7216 mb->un.varDmp.co = 1; 7217 mb->un.varWords[2] = 0; 7218 mb->un.varWords[3] = DMP_SFF_PAGE_A0_SIZE / 4; 7219 mb->un.varWords[4] = 0; 7220 mb->un.varWords[5] = 0; 7221 mb->un.varWords[6] = 0; 7222 mb->un.varWords[7] = 0; 7223 mb->un.varWords[8] = 0; 7224 mb->un.varWords[9] = 0; 7225 mb->un.varWords[10] = 0; 7226 mbox->in_ext_byte_len = DMP_SFF_PAGE_A0_SIZE; 7227 mbox->out_ext_byte_len = DMP_SFF_PAGE_A0_SIZE; 7228 mbox->mbox_offset_word = 5; 7229 mbox->ext_buf = virt; 7230 } else { 7231 bf_set(lpfc_mbx_memory_dump_type3_length, 7232 &mbox->u.mqe.un.mem_dump_type3, DMP_SFF_PAGE_A0_SIZE); 7233 mbox->u.mqe.un.mem_dump_type3.addr_lo = putPaddrLow(mp->phys); 7234 mbox->u.mqe.un.mem_dump_type3.addr_hi = putPaddrHigh(mp->phys); 7235 } 7236 mbox->vport = phba->pport; 7237 rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_SLI4_CONFIG_TMO); 7238 if (rc == MBX_NOT_FINISHED) { 7239 rc = 1; 7240 goto error; 7241 } 7242 if (rc == MBX_TIMEOUT) 7243 goto error; 7244 if (phba->sli_rev == LPFC_SLI_REV4) 7245 mp = mbox->ctx_buf; 7246 else 7247 mp = mpsave; 7248 7249 if (bf_get(lpfc_mqe_status, &mbox->u.mqe)) { 7250 rc = 1; 7251 goto error; 7252 } 7253 7254 lpfc_sli_bemem_bcopy(mp->virt, &rdp_context->page_a0, 7255 DMP_SFF_PAGE_A0_SIZE); 7256 7257 memset(mbox, 0, sizeof(*mbox)); 7258 memset(mp->virt, 0, DMP_SFF_PAGE_A2_SIZE); 7259 INIT_LIST_HEAD(&mp->list); 7260 7261 /* save address for completion */ 7262 mbox->ctx_buf = mp; 7263 mbox->vport = phba->pport; 7264 7265 bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_DUMP_MEMORY); 7266 bf_set(lpfc_mbx_memory_dump_type3_type, 7267 &mbox->u.mqe.un.mem_dump_type3, DMP_LMSD); 7268 bf_set(lpfc_mbx_memory_dump_type3_link, 7269 &mbox->u.mqe.un.mem_dump_type3, phba->sli4_hba.physical_port); 7270 bf_set(lpfc_mbx_memory_dump_type3_page_no, 7271 &mbox->u.mqe.un.mem_dump_type3, DMP_PAGE_A2); 7272 if (phba->sli_rev < LPFC_SLI_REV4) { 7273 mb = &mbox->u.mb; 7274 mb->un.varDmp.cv = 1; 7275 mb->un.varDmp.co = 1; 7276 mb->un.varWords[2] = 0; 7277 mb->un.varWords[3] = DMP_SFF_PAGE_A2_SIZE / 4; 7278 mb->un.varWords[4] = 0; 7279 mb->un.varWords[5] = 0; 7280 mb->un.varWords[6] = 0; 7281 mb->un.varWords[7] = 0; 7282 mb->un.varWords[8] = 0; 7283 mb->un.varWords[9] = 0; 7284 mb->un.varWords[10] = 0; 7285 mbox->in_ext_byte_len = DMP_SFF_PAGE_A2_SIZE; 7286 mbox->out_ext_byte_len = DMP_SFF_PAGE_A2_SIZE; 7287 mbox->mbox_offset_word = 5; 7288 mbox->ext_buf = virt; 7289 } else { 7290 bf_set(lpfc_mbx_memory_dump_type3_length, 7291 &mbox->u.mqe.un.mem_dump_type3, DMP_SFF_PAGE_A2_SIZE); 7292 mbox->u.mqe.un.mem_dump_type3.addr_lo = putPaddrLow(mp->phys); 7293 mbox->u.mqe.un.mem_dump_type3.addr_hi = putPaddrHigh(mp->phys); 7294 } 7295 7296 rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_SLI4_CONFIG_TMO); 7297 7298 if (rc == MBX_TIMEOUT) 7299 goto error; 7300 if (bf_get(lpfc_mqe_status, &mbox->u.mqe)) { 7301 rc = 1; 7302 goto error; 7303 } 7304 rc = 0; 7305 7306 lpfc_sli_bemem_bcopy(mp->virt, &rdp_context->page_a2, 7307 DMP_SFF_PAGE_A2_SIZE); 7308 7309 error: 7310 if (mbox->mbox_flag & LPFC_MBX_WAKE) { 7311 mbox->ctx_buf = mpsave; 7312 lpfc_mbox_rsrc_cleanup(phba, mbox, MBOX_THD_UNLOCKED); 7313 } 7314 7315 return rc; 7316 7317 sfp_fail: 7318 mempool_free(mbox, phba->mbox_mem_pool); 7319 return 1; 7320 } 7321 7322 /* 7323 * lpfc_els_rcv_rdp - Process an unsolicited RDP ELS. 7324 * @vport: pointer to a host virtual N_Port data structure. 7325 * @cmdiocb: pointer to lpfc command iocb data structure. 7326 * @ndlp: pointer to a node-list data structure. 7327 * 7328 * This routine processes an unsolicited RDP(Read Diagnostic Parameters) 7329 * IOCB. First, the payload of the unsolicited RDP is checked. 7330 * Then it will (1) send MBX_DUMP_MEMORY, Embedded DMP_LMSD sub command TYPE-3 7331 * for Page A0, (2) send MBX_DUMP_MEMORY, DMP_LMSD for Page A2, 7332 * (3) send MBX_READ_LNK_STAT to get link stat, (4) Call lpfc_els_rdp_cmpl 7333 * gather all data and send RDP response. 7334 * 7335 * Return code 7336 * 0 - Sent the acc response 7337 * 1 - Sent the reject response. 7338 */ 7339 static int 7340 lpfc_els_rcv_rdp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, 7341 struct lpfc_nodelist *ndlp) 7342 { 7343 struct lpfc_hba *phba = vport->phba; 7344 struct lpfc_dmabuf *pcmd; 7345 uint8_t rjt_err, rjt_expl = LSEXP_NOTHING_MORE; 7346 struct fc_rdp_req_frame *rdp_req; 7347 struct lpfc_rdp_context *rdp_context; 7348 union lpfc_wqe128 *cmd = NULL; 7349 struct ls_rjt stat; 7350 7351 if (phba->sli_rev < LPFC_SLI_REV4 || 7352 bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) < 7353 LPFC_SLI_INTF_IF_TYPE_2) { 7354 rjt_err = LSRJT_UNABLE_TPC; 7355 rjt_expl = LSEXP_REQ_UNSUPPORTED; 7356 goto error; 7357 } 7358 7359 if (phba->sli_rev < LPFC_SLI_REV4 || 7360 test_bit(HBA_FCOE_MODE, &phba->hba_flag)) { 7361 rjt_err = LSRJT_UNABLE_TPC; 7362 rjt_expl = LSEXP_REQ_UNSUPPORTED; 7363 goto error; 7364 } 7365 7366 pcmd = cmdiocb->cmd_dmabuf; 7367 rdp_req = (struct fc_rdp_req_frame *) pcmd->virt; 7368 7369 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, 7370 "2422 ELS RDP Request " 7371 "dec len %d tag x%x port_id %d len %d\n", 7372 be32_to_cpu(rdp_req->rdp_des_length), 7373 be32_to_cpu(rdp_req->nport_id_desc.tag), 7374 be32_to_cpu(rdp_req->nport_id_desc.nport_id), 7375 be32_to_cpu(rdp_req->nport_id_desc.length)); 7376 7377 if (sizeof(struct fc_rdp_nport_desc) != 7378 be32_to_cpu(rdp_req->rdp_des_length)) 7379 goto rjt_logerr; 7380 if (RDP_N_PORT_DESC_TAG != be32_to_cpu(rdp_req->nport_id_desc.tag)) 7381 goto rjt_logerr; 7382 if (RDP_NPORT_ID_SIZE != 7383 be32_to_cpu(rdp_req->nport_id_desc.length)) 7384 goto rjt_logerr; 7385 rdp_context = kzalloc(sizeof(struct lpfc_rdp_context), GFP_KERNEL); 7386 if (!rdp_context) { 7387 rjt_err = LSRJT_UNABLE_TPC; 7388 goto error; 7389 } 7390 7391 cmd = &cmdiocb->wqe; 7392 rdp_context->ndlp = lpfc_nlp_get(ndlp); 7393 if (!rdp_context->ndlp) { 7394 kfree(rdp_context); 7395 rjt_err = LSRJT_UNABLE_TPC; 7396 goto error; 7397 } 7398 rdp_context->ox_id = bf_get(wqe_rcvoxid, 7399 &cmd->xmit_els_rsp.wqe_com); 7400 rdp_context->rx_id = bf_get(wqe_ctxt_tag, 7401 &cmd->xmit_els_rsp.wqe_com); 7402 rdp_context->cmpl = lpfc_els_rdp_cmpl; 7403 if (lpfc_get_rdp_info(phba, rdp_context)) { 7404 lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_ELS, 7405 "2423 Unable to send mailbox"); 7406 kfree(rdp_context); 7407 rjt_err = LSRJT_UNABLE_TPC; 7408 lpfc_nlp_put(ndlp); 7409 goto error; 7410 } 7411 7412 return 0; 7413 7414 rjt_logerr: 7415 rjt_err = LSRJT_LOGICAL_ERR; 7416 7417 error: 7418 memset(&stat, 0, sizeof(stat)); 7419 stat.un.b.lsRjtRsnCode = rjt_err; 7420 stat.un.b.lsRjtRsnCodeExp = rjt_expl; 7421 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); 7422 return 1; 7423 } 7424 7425 7426 static void 7427 lpfc_els_lcb_rsp(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) 7428 { 7429 MAILBOX_t *mb; 7430 IOCB_t *icmd; 7431 union lpfc_wqe128 *wqe; 7432 uint8_t *pcmd; 7433 struct lpfc_iocbq *elsiocb; 7434 struct lpfc_nodelist *ndlp; 7435 struct ls_rjt *stat; 7436 union lpfc_sli4_cfg_shdr *shdr; 7437 struct lpfc_lcb_context *lcb_context; 7438 struct fc_lcb_res_frame *lcb_res; 7439 uint32_t cmdsize, shdr_status, shdr_add_status; 7440 int rc; 7441 7442 mb = &pmb->u.mb; 7443 lcb_context = pmb->ctx_u.lcb; 7444 ndlp = lcb_context->ndlp; 7445 memset(&pmb->ctx_u, 0, sizeof(pmb->ctx_u)); 7446 pmb->ctx_buf = NULL; 7447 7448 shdr = (union lpfc_sli4_cfg_shdr *) 7449 &pmb->u.mqe.un.beacon_config.header.cfg_shdr; 7450 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); 7451 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); 7452 7453 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX, 7454 "0194 SET_BEACON_CONFIG mailbox " 7455 "completed with status x%x add_status x%x," 7456 " mbx status x%x\n", 7457 shdr_status, shdr_add_status, mb->mbxStatus); 7458 7459 if ((mb->mbxStatus != MBX_SUCCESS) || shdr_status || 7460 (shdr_add_status == ADD_STATUS_OPERATION_ALREADY_ACTIVE) || 7461 (shdr_add_status == ADD_STATUS_INVALID_REQUEST)) { 7462 mempool_free(pmb, phba->mbox_mem_pool); 7463 goto error; 7464 } 7465 7466 mempool_free(pmb, phba->mbox_mem_pool); 7467 cmdsize = sizeof(struct fc_lcb_res_frame); 7468 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize, 7469 lpfc_max_els_tries, ndlp, 7470 ndlp->nlp_DID, ELS_CMD_ACC); 7471 7472 /* Decrement the ndlp reference count from previous mbox command */ 7473 lpfc_nlp_put(ndlp); 7474 7475 if (!elsiocb) 7476 goto free_lcb_context; 7477 7478 lcb_res = (struct fc_lcb_res_frame *)elsiocb->cmd_dmabuf->virt; 7479 7480 memset(lcb_res, 0, sizeof(struct fc_lcb_res_frame)); 7481 7482 if (phba->sli_rev == LPFC_SLI_REV4) { 7483 wqe = &elsiocb->wqe; 7484 bf_set(wqe_ctxt_tag, &wqe->generic.wqe_com, lcb_context->rx_id); 7485 bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com, 7486 lcb_context->ox_id); 7487 } else { 7488 icmd = &elsiocb->iocb; 7489 icmd->ulpContext = lcb_context->rx_id; 7490 icmd->unsli3.rcvsli3.ox_id = lcb_context->ox_id; 7491 } 7492 7493 pcmd = (uint8_t *)elsiocb->cmd_dmabuf->virt; 7494 *((uint32_t *)(pcmd)) = ELS_CMD_ACC; 7495 lcb_res->lcb_sub_command = lcb_context->sub_command; 7496 lcb_res->lcb_type = lcb_context->type; 7497 lcb_res->capability = lcb_context->capability; 7498 lcb_res->lcb_frequency = lcb_context->frequency; 7499 lcb_res->lcb_duration = lcb_context->duration; 7500 elsiocb->cmd_cmpl = lpfc_cmpl_els_rsp; 7501 phba->fc_stat.elsXmitACC++; 7502 7503 elsiocb->ndlp = lpfc_nlp_get(ndlp); 7504 if (!elsiocb->ndlp) { 7505 lpfc_els_free_iocb(phba, elsiocb); 7506 goto out; 7507 } 7508 7509 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); 7510 if (rc == IOCB_ERROR) { 7511 lpfc_els_free_iocb(phba, elsiocb); 7512 lpfc_nlp_put(ndlp); 7513 } 7514 out: 7515 kfree(lcb_context); 7516 return; 7517 7518 error: 7519 cmdsize = sizeof(struct fc_lcb_res_frame); 7520 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize, 7521 lpfc_max_els_tries, ndlp, 7522 ndlp->nlp_DID, ELS_CMD_LS_RJT); 7523 lpfc_nlp_put(ndlp); 7524 if (!elsiocb) 7525 goto free_lcb_context; 7526 7527 if (phba->sli_rev == LPFC_SLI_REV4) { 7528 wqe = &elsiocb->wqe; 7529 bf_set(wqe_ctxt_tag, &wqe->generic.wqe_com, lcb_context->rx_id); 7530 bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com, 7531 lcb_context->ox_id); 7532 } else { 7533 icmd = &elsiocb->iocb; 7534 icmd->ulpContext = lcb_context->rx_id; 7535 icmd->unsli3.rcvsli3.ox_id = lcb_context->ox_id; 7536 } 7537 7538 pcmd = (uint8_t *)elsiocb->cmd_dmabuf->virt; 7539 7540 *((uint32_t *)(pcmd)) = ELS_CMD_LS_RJT; 7541 stat = (struct ls_rjt *)(pcmd + sizeof(uint32_t)); 7542 stat->un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; 7543 7544 if (shdr_add_status == ADD_STATUS_OPERATION_ALREADY_ACTIVE) 7545 stat->un.b.lsRjtRsnCodeExp = LSEXP_CMD_IN_PROGRESS; 7546 7547 elsiocb->cmd_cmpl = lpfc_cmpl_els_rsp; 7548 phba->fc_stat.elsXmitLSRJT++; 7549 elsiocb->ndlp = lpfc_nlp_get(ndlp); 7550 if (!elsiocb->ndlp) { 7551 lpfc_els_free_iocb(phba, elsiocb); 7552 goto free_lcb_context; 7553 } 7554 7555 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); 7556 if (rc == IOCB_ERROR) { 7557 lpfc_els_free_iocb(phba, elsiocb); 7558 lpfc_nlp_put(ndlp); 7559 } 7560 free_lcb_context: 7561 kfree(lcb_context); 7562 } 7563 7564 static int 7565 lpfc_sli4_set_beacon(struct lpfc_vport *vport, 7566 struct lpfc_lcb_context *lcb_context, 7567 uint32_t beacon_state) 7568 { 7569 struct lpfc_hba *phba = vport->phba; 7570 union lpfc_sli4_cfg_shdr *cfg_shdr; 7571 LPFC_MBOXQ_t *mbox = NULL; 7572 uint32_t len; 7573 int rc; 7574 7575 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); 7576 if (!mbox) 7577 return 1; 7578 7579 cfg_shdr = &mbox->u.mqe.un.sli4_config.header.cfg_shdr; 7580 len = sizeof(struct lpfc_mbx_set_beacon_config) - 7581 sizeof(struct lpfc_sli4_cfg_mhdr); 7582 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, 7583 LPFC_MBOX_OPCODE_SET_BEACON_CONFIG, len, 7584 LPFC_SLI4_MBX_EMBED); 7585 mbox->ctx_u.lcb = lcb_context; 7586 mbox->vport = phba->pport; 7587 mbox->mbox_cmpl = lpfc_els_lcb_rsp; 7588 bf_set(lpfc_mbx_set_beacon_port_num, &mbox->u.mqe.un.beacon_config, 7589 phba->sli4_hba.physical_port); 7590 bf_set(lpfc_mbx_set_beacon_state, &mbox->u.mqe.un.beacon_config, 7591 beacon_state); 7592 mbox->u.mqe.un.beacon_config.word5 = 0; /* Reserved */ 7593 7594 /* 7595 * Check bv1s bit before issuing the mailbox 7596 * if bv1s == 1, LCB V1 supported 7597 * else, LCB V0 supported 7598 */ 7599 7600 if (phba->sli4_hba.pc_sli4_params.bv1s) { 7601 /* COMMON_SET_BEACON_CONFIG_V1 */ 7602 cfg_shdr->request.word9 = BEACON_VERSION_V1; 7603 lcb_context->capability |= LCB_CAPABILITY_DURATION; 7604 bf_set(lpfc_mbx_set_beacon_port_type, 7605 &mbox->u.mqe.un.beacon_config, 0); 7606 bf_set(lpfc_mbx_set_beacon_duration_v1, 7607 &mbox->u.mqe.un.beacon_config, 7608 be16_to_cpu(lcb_context->duration)); 7609 } else { 7610 /* COMMON_SET_BEACON_CONFIG_V0 */ 7611 if (be16_to_cpu(lcb_context->duration) != 0) { 7612 mempool_free(mbox, phba->mbox_mem_pool); 7613 return 1; 7614 } 7615 cfg_shdr->request.word9 = BEACON_VERSION_V0; 7616 lcb_context->capability &= ~(LCB_CAPABILITY_DURATION); 7617 bf_set(lpfc_mbx_set_beacon_state, 7618 &mbox->u.mqe.un.beacon_config, beacon_state); 7619 bf_set(lpfc_mbx_set_beacon_port_type, 7620 &mbox->u.mqe.un.beacon_config, 1); 7621 bf_set(lpfc_mbx_set_beacon_duration, 7622 &mbox->u.mqe.un.beacon_config, 7623 be16_to_cpu(lcb_context->duration)); 7624 } 7625 7626 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); 7627 if (rc == MBX_NOT_FINISHED) { 7628 mempool_free(mbox, phba->mbox_mem_pool); 7629 return 1; 7630 } 7631 7632 return 0; 7633 } 7634 7635 7636 /** 7637 * lpfc_els_rcv_lcb - Process an unsolicited LCB 7638 * @vport: pointer to a host virtual N_Port data structure. 7639 * @cmdiocb: pointer to lpfc command iocb data structure. 7640 * @ndlp: pointer to a node-list data structure. 7641 * 7642 * This routine processes an unsolicited LCB(LINK CABLE BEACON) IOCB. 7643 * First, the payload of the unsolicited LCB is checked. 7644 * Then based on Subcommand beacon will either turn on or off. 7645 * 7646 * Return code 7647 * 0 - Sent the acc response 7648 * 1 - Sent the reject response. 7649 **/ 7650 static int 7651 lpfc_els_rcv_lcb(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, 7652 struct lpfc_nodelist *ndlp) 7653 { 7654 struct lpfc_hba *phba = vport->phba; 7655 struct lpfc_dmabuf *pcmd; 7656 uint8_t *lp; 7657 struct fc_lcb_request_frame *beacon; 7658 struct lpfc_lcb_context *lcb_context; 7659 u8 state, rjt_err = 0; 7660 struct ls_rjt stat; 7661 7662 pcmd = cmdiocb->cmd_dmabuf; 7663 lp = (uint8_t *)pcmd->virt; 7664 beacon = (struct fc_lcb_request_frame *)pcmd->virt; 7665 7666 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, 7667 "0192 ELS LCB Data x%x x%x x%x x%x sub x%x " 7668 "type x%x frequency %x duration x%x\n", 7669 lp[0], lp[1], lp[2], 7670 beacon->lcb_command, 7671 beacon->lcb_sub_command, 7672 beacon->lcb_type, 7673 beacon->lcb_frequency, 7674 be16_to_cpu(beacon->lcb_duration)); 7675 7676 if (beacon->lcb_sub_command != LPFC_LCB_ON && 7677 beacon->lcb_sub_command != LPFC_LCB_OFF) { 7678 rjt_err = LSRJT_CMD_UNSUPPORTED; 7679 goto rjt; 7680 } 7681 7682 if (phba->sli_rev < LPFC_SLI_REV4 || 7683 test_bit(HBA_FCOE_MODE, &phba->hba_flag) || 7684 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) < 7685 LPFC_SLI_INTF_IF_TYPE_2)) { 7686 rjt_err = LSRJT_CMD_UNSUPPORTED; 7687 goto rjt; 7688 } 7689 7690 lcb_context = kmalloc(sizeof(*lcb_context), GFP_KERNEL); 7691 if (!lcb_context) { 7692 rjt_err = LSRJT_UNABLE_TPC; 7693 goto rjt; 7694 } 7695 7696 state = (beacon->lcb_sub_command == LPFC_LCB_ON) ? 1 : 0; 7697 lcb_context->sub_command = beacon->lcb_sub_command; 7698 lcb_context->capability = 0; 7699 lcb_context->type = beacon->lcb_type; 7700 lcb_context->frequency = beacon->lcb_frequency; 7701 lcb_context->duration = beacon->lcb_duration; 7702 lcb_context->ox_id = get_job_rcvoxid(phba, cmdiocb); 7703 lcb_context->rx_id = get_job_ulpcontext(phba, cmdiocb); 7704 lcb_context->ndlp = lpfc_nlp_get(ndlp); 7705 if (!lcb_context->ndlp) { 7706 rjt_err = LSRJT_UNABLE_TPC; 7707 goto rjt_free; 7708 } 7709 7710 if (lpfc_sli4_set_beacon(vport, lcb_context, state)) { 7711 lpfc_printf_vlog(ndlp->vport, KERN_ERR, LOG_TRACE_EVENT, 7712 "0193 failed to send mail box"); 7713 lpfc_nlp_put(ndlp); 7714 rjt_err = LSRJT_UNABLE_TPC; 7715 goto rjt_free; 7716 } 7717 return 0; 7718 7719 rjt_free: 7720 kfree(lcb_context); 7721 rjt: 7722 memset(&stat, 0, sizeof(stat)); 7723 stat.un.b.lsRjtRsnCode = rjt_err; 7724 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); 7725 return 1; 7726 } 7727 7728 7729 /** 7730 * lpfc_els_flush_rscn - Clean up any rscn activities with a vport 7731 * @vport: pointer to a host virtual N_Port data structure. 7732 * 7733 * This routine cleans up any Registration State Change Notification 7734 * (RSCN) activity with a @vport. Note that the fc_rscn_flush flag of the 7735 * @vport together with the host_lock is used to prevent multiple thread 7736 * trying to access the RSCN array on a same @vport at the same time. 7737 **/ 7738 void 7739 lpfc_els_flush_rscn(struct lpfc_vport *vport) 7740 { 7741 struct Scsi_Host *shost = lpfc_shost_from_vport(vport); 7742 struct lpfc_hba *phba = vport->phba; 7743 int i; 7744 7745 spin_lock_irq(shost->host_lock); 7746 if (vport->fc_rscn_flush) { 7747 /* Another thread is walking fc_rscn_id_list on this vport */ 7748 spin_unlock_irq(shost->host_lock); 7749 return; 7750 } 7751 /* Indicate we are walking lpfc_els_flush_rscn on this vport */ 7752 vport->fc_rscn_flush = 1; 7753 spin_unlock_irq(shost->host_lock); 7754 7755 for (i = 0; i < vport->fc_rscn_id_cnt; i++) { 7756 lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]); 7757 vport->fc_rscn_id_list[i] = NULL; 7758 } 7759 clear_bit(FC_RSCN_MODE, &vport->fc_flag); 7760 clear_bit(FC_RSCN_DISCOVERY, &vport->fc_flag); 7761 spin_lock_irq(shost->host_lock); 7762 vport->fc_rscn_id_cnt = 0; 7763 spin_unlock_irq(shost->host_lock); 7764 lpfc_can_disctmo(vport); 7765 /* Indicate we are done walking this fc_rscn_id_list */ 7766 vport->fc_rscn_flush = 0; 7767 } 7768 7769 /** 7770 * lpfc_rscn_payload_check - Check whether there is a pending rscn to a did 7771 * @vport: pointer to a host virtual N_Port data structure. 7772 * @did: remote destination port identifier. 7773 * 7774 * This routine checks whether there is any pending Registration State 7775 * Configuration Notification (RSCN) to a @did on @vport. 7776 * 7777 * Return code 7778 * None zero - The @did matched with a pending rscn 7779 * 0 - not able to match @did with a pending rscn 7780 **/ 7781 int 7782 lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did) 7783 { 7784 D_ID ns_did; 7785 D_ID rscn_did; 7786 uint32_t *lp; 7787 uint32_t payload_len, i; 7788 struct Scsi_Host *shost = lpfc_shost_from_vport(vport); 7789 7790 ns_did.un.word = did; 7791 7792 /* Never match fabric nodes for RSCNs */ 7793 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) 7794 return 0; 7795 7796 /* If we are doing a FULL RSCN rediscovery, match everything */ 7797 if (test_bit(FC_RSCN_DISCOVERY, &vport->fc_flag)) 7798 return did; 7799 7800 spin_lock_irq(shost->host_lock); 7801 if (vport->fc_rscn_flush) { 7802 /* Another thread is walking fc_rscn_id_list on this vport */ 7803 spin_unlock_irq(shost->host_lock); 7804 return 0; 7805 } 7806 /* Indicate we are walking fc_rscn_id_list on this vport */ 7807 vport->fc_rscn_flush = 1; 7808 spin_unlock_irq(shost->host_lock); 7809 for (i = 0; i < vport->fc_rscn_id_cnt; i++) { 7810 lp = vport->fc_rscn_id_list[i]->virt; 7811 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK); 7812 payload_len -= sizeof(uint32_t); /* take off word 0 */ 7813 while (payload_len) { 7814 rscn_did.un.word = be32_to_cpu(*lp++); 7815 payload_len -= sizeof(uint32_t); 7816 switch (rscn_did.un.b.resv & RSCN_ADDRESS_FORMAT_MASK) { 7817 case RSCN_ADDRESS_FORMAT_PORT: 7818 if ((ns_did.un.b.domain == rscn_did.un.b.domain) 7819 && (ns_did.un.b.area == rscn_did.un.b.area) 7820 && (ns_did.un.b.id == rscn_did.un.b.id)) 7821 goto return_did_out; 7822 break; 7823 case RSCN_ADDRESS_FORMAT_AREA: 7824 if ((ns_did.un.b.domain == rscn_did.un.b.domain) 7825 && (ns_did.un.b.area == rscn_did.un.b.area)) 7826 goto return_did_out; 7827 break; 7828 case RSCN_ADDRESS_FORMAT_DOMAIN: 7829 if (ns_did.un.b.domain == rscn_did.un.b.domain) 7830 goto return_did_out; 7831 break; 7832 case RSCN_ADDRESS_FORMAT_FABRIC: 7833 goto return_did_out; 7834 } 7835 } 7836 } 7837 /* Indicate we are done with walking fc_rscn_id_list on this vport */ 7838 vport->fc_rscn_flush = 0; 7839 return 0; 7840 return_did_out: 7841 /* Indicate we are done with walking fc_rscn_id_list on this vport */ 7842 vport->fc_rscn_flush = 0; 7843 return did; 7844 } 7845 7846 /** 7847 * lpfc_rscn_recovery_check - Send recovery event to vport nodes matching rscn 7848 * @vport: pointer to a host virtual N_Port data structure. 7849 * 7850 * This routine sends recovery (NLP_EVT_DEVICE_RECOVERY) event to the 7851 * state machine for a @vport's nodes that are with pending RSCN (Registration 7852 * State Change Notification). 7853 * 7854 * Return code 7855 * 0 - Successful (currently alway return 0) 7856 **/ 7857 static int 7858 lpfc_rscn_recovery_check(struct lpfc_vport *vport) 7859 { 7860 struct lpfc_nodelist *ndlp = NULL, *n; 7861 7862 /* Move all affected nodes by pending RSCNs to NPR state. */ 7863 list_for_each_entry_safe(ndlp, n, &vport->fc_nodes, nlp_listp) { 7864 if ((ndlp->nlp_state == NLP_STE_UNUSED_NODE) || 7865 !lpfc_rscn_payload_check(vport, ndlp->nlp_DID)) 7866 continue; 7867 7868 /* NVME Target mode does not do RSCN Recovery. */ 7869 if (vport->phba->nvmet_support) 7870 continue; 7871 7872 /* If we are in the process of doing discovery on this 7873 * NPort, let it continue on its own. 7874 */ 7875 switch (ndlp->nlp_state) { 7876 case NLP_STE_PLOGI_ISSUE: 7877 case NLP_STE_ADISC_ISSUE: 7878 case NLP_STE_REG_LOGIN_ISSUE: 7879 case NLP_STE_PRLI_ISSUE: 7880 case NLP_STE_LOGO_ISSUE: 7881 continue; 7882 } 7883 7884 lpfc_disc_state_machine(vport, ndlp, NULL, 7885 NLP_EVT_DEVICE_RECOVERY); 7886 lpfc_cancel_retry_delay_tmo(vport, ndlp); 7887 } 7888 return 0; 7889 } 7890 7891 /** 7892 * lpfc_send_rscn_event - Send an RSCN event to management application 7893 * @vport: pointer to a host virtual N_Port data structure. 7894 * @cmdiocb: pointer to lpfc command iocb data structure. 7895 * 7896 * lpfc_send_rscn_event sends an RSCN netlink event to management 7897 * applications. 7898 */ 7899 static void 7900 lpfc_send_rscn_event(struct lpfc_vport *vport, 7901 struct lpfc_iocbq *cmdiocb) 7902 { 7903 struct lpfc_dmabuf *pcmd; 7904 struct Scsi_Host *shost = lpfc_shost_from_vport(vport); 7905 uint32_t *payload_ptr; 7906 uint32_t payload_len; 7907 struct lpfc_rscn_event_header *rscn_event_data; 7908 7909 pcmd = cmdiocb->cmd_dmabuf; 7910 payload_ptr = (uint32_t *) pcmd->virt; 7911 payload_len = be32_to_cpu(*payload_ptr & ~ELS_CMD_MASK); 7912 7913 rscn_event_data = kmalloc(sizeof(struct lpfc_rscn_event_header) + 7914 payload_len, GFP_KERNEL); 7915 if (!rscn_event_data) { 7916 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, 7917 "0147 Failed to allocate memory for RSCN event\n"); 7918 return; 7919 } 7920 rscn_event_data->event_type = FC_REG_RSCN_EVENT; 7921 rscn_event_data->payload_length = payload_len; 7922 memcpy(rscn_event_data->rscn_payload, payload_ptr, 7923 payload_len); 7924 7925 fc_host_post_vendor_event(shost, 7926 fc_get_event_number(), 7927 sizeof(struct lpfc_rscn_event_header) + payload_len, 7928 (char *)rscn_event_data, 7929 LPFC_NL_VENDOR_ID); 7930 7931 kfree(rscn_event_data); 7932 } 7933 7934 /** 7935 * lpfc_els_rcv_rscn - Process an unsolicited rscn iocb 7936 * @vport: pointer to a host virtual N_Port data structure. 7937 * @cmdiocb: pointer to lpfc command iocb data structure. 7938 * @ndlp: pointer to a node-list data structure. 7939 * 7940 * This routine processes an unsolicited RSCN (Registration State Change 7941 * Notification) IOCB. First, the payload of the unsolicited RSCN is walked 7942 * to invoke fc_host_post_event() routine to the FC transport layer. If the 7943 * discover state machine is about to begin discovery, it just accepts the 7944 * RSCN and the discovery process will satisfy the RSCN. If this RSCN only 7945 * contains N_Port IDs for other vports on this HBA, it just accepts the 7946 * RSCN and ignore processing it. If the state machine is in the recovery 7947 * state, the fc_rscn_id_list of this @vport is walked and the 7948 * lpfc_rscn_recovery_check() routine is invoked to send recovery event for 7949 * all nodes that match RSCN payload. Otherwise, the lpfc_els_handle_rscn() 7950 * routine is invoked to handle the RSCN event. 7951 * 7952 * Return code 7953 * 0 - Just sent the acc response 7954 * 1 - Sent the acc response and waited for name server completion 7955 **/ 7956 static int 7957 lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, 7958 struct lpfc_nodelist *ndlp) 7959 { 7960 struct Scsi_Host *shost = lpfc_shost_from_vport(vport); 7961 struct lpfc_hba *phba = vport->phba; 7962 struct lpfc_dmabuf *pcmd; 7963 uint32_t *lp, *datap; 7964 uint32_t payload_len, length, nportid, *cmd; 7965 int rscn_cnt; 7966 int rscn_id = 0, hba_id = 0; 7967 int i, tmo; 7968 7969 pcmd = cmdiocb->cmd_dmabuf; 7970 lp = (uint32_t *) pcmd->virt; 7971 7972 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK); 7973 payload_len -= sizeof(uint32_t); /* take off word 0 */ 7974 /* RSCN received */ 7975 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, 7976 "0214 RSCN received Data: x%lx x%x x%x x%x\n", 7977 vport->fc_flag, payload_len, *lp, 7978 vport->fc_rscn_id_cnt); 7979 7980 /* Send an RSCN event to the management application */ 7981 lpfc_send_rscn_event(vport, cmdiocb); 7982 7983 for (i = 0; i < payload_len/sizeof(uint32_t); i++) 7984 fc_host_post_event(shost, fc_get_event_number(), 7985 FCH_EVT_RSCN, lp[i]); 7986 7987 /* Check if RSCN is coming from a direct-connected remote NPort */ 7988 if (test_bit(FC_PT2PT, &vport->fc_flag)) { 7989 /* If so, just ACC it, no other action needed for now */ 7990 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, 7991 "2024 pt2pt RSCN %08x Data: x%lx x%x\n", 7992 *lp, vport->fc_flag, payload_len); 7993 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); 7994 7995 /* Check to see if we need to NVME rescan this target 7996 * remoteport. 7997 */ 7998 if (ndlp->nlp_fc4_type & NLP_FC4_NVME && 7999 ndlp->nlp_type & (NLP_NVME_TARGET | NLP_NVME_DISCOVERY)) 8000 lpfc_nvme_rescan_port(vport, ndlp); 8001 return 0; 8002 } 8003 8004 /* If we are about to begin discovery, just ACC the RSCN. 8005 * Discovery processing will satisfy it. 8006 */ 8007 if (vport->port_state <= LPFC_NS_QRY) { 8008 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, 8009 "RCV RSCN ignore: did:x%x/ste:x%x flg:x%lx", 8010 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag); 8011 8012 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); 8013 return 0; 8014 } 8015 8016 /* If this RSCN just contains NPortIDs for other vports on this HBA, 8017 * just ACC and ignore it. 8018 */ 8019 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && 8020 !(vport->cfg_peer_port_login)) { 8021 i = payload_len; 8022 datap = lp; 8023 while (i > 0) { 8024 nportid = *datap++; 8025 nportid = ((be32_to_cpu(nportid)) & Mask_DID); 8026 i -= sizeof(uint32_t); 8027 rscn_id++; 8028 if (lpfc_find_vport_by_did(phba, nportid)) 8029 hba_id++; 8030 } 8031 if (rscn_id == hba_id) { 8032 /* ALL NPortIDs in RSCN are on HBA */ 8033 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, 8034 "0219 Ignore RSCN " 8035 "Data: x%lx x%x x%x x%x\n", 8036 vport->fc_flag, payload_len, 8037 *lp, vport->fc_rscn_id_cnt); 8038 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, 8039 "RCV RSCN vport: did:x%x/ste:x%x flg:x%lx", 8040 ndlp->nlp_DID, vport->port_state, 8041 ndlp->nlp_flag); 8042 8043 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, 8044 ndlp, NULL); 8045 /* Restart disctmo if its already running */ 8046 if (test_bit(FC_DISC_TMO, &vport->fc_flag)) { 8047 tmo = ((phba->fc_ratov * 3) + 3); 8048 mod_timer(&vport->fc_disctmo, 8049 jiffies + secs_to_jiffies(tmo)); 8050 } 8051 return 0; 8052 } 8053 } 8054 8055 spin_lock_irq(shost->host_lock); 8056 if (vport->fc_rscn_flush) { 8057 /* Another thread is walking fc_rscn_id_list on this vport */ 8058 spin_unlock_irq(shost->host_lock); 8059 set_bit(FC_RSCN_DISCOVERY, &vport->fc_flag); 8060 /* Send back ACC */ 8061 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); 8062 return 0; 8063 } 8064 /* Indicate we are walking fc_rscn_id_list on this vport */ 8065 vport->fc_rscn_flush = 1; 8066 spin_unlock_irq(shost->host_lock); 8067 /* Get the array count after successfully have the token */ 8068 rscn_cnt = vport->fc_rscn_id_cnt; 8069 /* If we are already processing an RSCN, save the received 8070 * RSCN payload buffer, cmdiocb->cmd_dmabuf to process later. 8071 */ 8072 if (test_bit(FC_RSCN_MODE, &vport->fc_flag) || 8073 test_bit(FC_NDISC_ACTIVE, &vport->fc_flag)) { 8074 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, 8075 "RCV RSCN defer: did:x%x/ste:x%x flg:x%lx", 8076 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag); 8077 8078 set_bit(FC_RSCN_DEFERRED, &vport->fc_flag); 8079 8080 /* Restart disctmo if its already running */ 8081 if (test_bit(FC_DISC_TMO, &vport->fc_flag)) { 8082 tmo = ((phba->fc_ratov * 3) + 3); 8083 mod_timer(&vport->fc_disctmo, 8084 jiffies + secs_to_jiffies(tmo)); 8085 } 8086 if ((rscn_cnt < FC_MAX_HOLD_RSCN) && 8087 !test_bit(FC_RSCN_DISCOVERY, &vport->fc_flag)) { 8088 set_bit(FC_RSCN_MODE, &vport->fc_flag); 8089 if (rscn_cnt) { 8090 cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt; 8091 length = be32_to_cpu(*cmd & ~ELS_CMD_MASK); 8092 } 8093 if ((rscn_cnt) && 8094 (payload_len + length <= LPFC_BPL_SIZE)) { 8095 *cmd &= ELS_CMD_MASK; 8096 *cmd |= cpu_to_be32(payload_len + length); 8097 memcpy(((uint8_t *)cmd) + length, lp, 8098 payload_len); 8099 } else { 8100 vport->fc_rscn_id_list[rscn_cnt] = pcmd; 8101 vport->fc_rscn_id_cnt++; 8102 /* If we zero, cmdiocb->cmd_dmabuf, the calling 8103 * routine will not try to free it. 8104 */ 8105 cmdiocb->cmd_dmabuf = NULL; 8106 } 8107 /* Deferred RSCN */ 8108 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, 8109 "0235 Deferred RSCN " 8110 "Data: x%x x%lx x%x\n", 8111 vport->fc_rscn_id_cnt, vport->fc_flag, 8112 vport->port_state); 8113 } else { 8114 set_bit(FC_RSCN_DISCOVERY, &vport->fc_flag); 8115 /* ReDiscovery RSCN */ 8116 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, 8117 "0234 ReDiscovery RSCN " 8118 "Data: x%x x%lx x%x\n", 8119 vport->fc_rscn_id_cnt, vport->fc_flag, 8120 vport->port_state); 8121 } 8122 /* Indicate we are done walking fc_rscn_id_list on this vport */ 8123 vport->fc_rscn_flush = 0; 8124 /* Send back ACC */ 8125 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); 8126 /* send RECOVERY event for ALL nodes that match RSCN payload */ 8127 lpfc_rscn_recovery_check(vport); 8128 return 0; 8129 } 8130 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, 8131 "RCV RSCN: did:x%x/ste:x%x flg:x%lx", 8132 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag); 8133 8134 set_bit(FC_RSCN_MODE, &vport->fc_flag); 8135 vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd; 8136 /* Indicate we are done walking fc_rscn_id_list on this vport */ 8137 vport->fc_rscn_flush = 0; 8138 /* 8139 * If we zero, cmdiocb->cmd_dmabuf, the calling routine will 8140 * not try to free it. 8141 */ 8142 cmdiocb->cmd_dmabuf = NULL; 8143 lpfc_set_disctmo(vport); 8144 /* Send back ACC */ 8145 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); 8146 /* send RECOVERY event for ALL nodes that match RSCN payload */ 8147 lpfc_rscn_recovery_check(vport); 8148 return lpfc_els_handle_rscn(vport); 8149 } 8150 8151 /** 8152 * lpfc_els_handle_rscn - Handle rscn for a vport 8153 * @vport: pointer to a host virtual N_Port data structure. 8154 * 8155 * This routine handles the Registration State Configuration Notification 8156 * (RSCN) for a @vport. If login to NameServer does not exist, a new ndlp shall 8157 * be created and a Port Login (PLOGI) to the NameServer is issued. Otherwise, 8158 * if the ndlp to NameServer exists, a Common Transport (CT) command to the 8159 * NameServer shall be issued. If CT command to the NameServer fails to be 8160 * issued, the lpfc_els_flush_rscn() routine shall be invoked to clean up any 8161 * RSCN activities with the @vport. 8162 * 8163 * Return code 8164 * 0 - Cleaned up rscn on the @vport 8165 * 1 - Wait for plogi to name server before proceed 8166 **/ 8167 int 8168 lpfc_els_handle_rscn(struct lpfc_vport *vport) 8169 { 8170 struct lpfc_nodelist *ndlp; 8171 struct lpfc_hba *phba = vport->phba; 8172 8173 /* Ignore RSCN if the port is being torn down. */ 8174 if (test_bit(FC_UNLOADING, &vport->load_flag)) { 8175 lpfc_els_flush_rscn(vport); 8176 return 0; 8177 } 8178 8179 /* Start timer for RSCN processing */ 8180 lpfc_set_disctmo(vport); 8181 8182 /* RSCN processed */ 8183 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, 8184 "0215 RSCN processed Data: x%lx x%x x%x x%x x%x x%x\n", 8185 vport->fc_flag, 0, vport->fc_rscn_id_cnt, 8186 vport->port_state, vport->num_disc_nodes, 8187 vport->gidft_inp); 8188 8189 /* To process RSCN, first compare RSCN data with NameServer */ 8190 vport->fc_ns_retry = 0; 8191 vport->num_disc_nodes = 0; 8192 8193 ndlp = lpfc_findnode_did(vport, NameServer_DID); 8194 if (ndlp && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) { 8195 /* Good ndlp, issue CT Request to NameServer. Need to 8196 * know how many gidfts were issued. If none, then just 8197 * flush the RSCN. Otherwise, the outstanding requests 8198 * need to complete. 8199 */ 8200 if (phba->cfg_ns_query == LPFC_NS_QUERY_GID_FT) { 8201 if (lpfc_issue_gidft(vport) > 0) 8202 return 1; 8203 } else if (phba->cfg_ns_query == LPFC_NS_QUERY_GID_PT) { 8204 if (lpfc_issue_gidpt(vport) > 0) 8205 return 1; 8206 } else { 8207 return 1; 8208 } 8209 } else { 8210 /* Nameserver login in question. Revalidate. */ 8211 if (ndlp) { 8212 ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE; 8213 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); 8214 } else { 8215 ndlp = lpfc_nlp_init(vport, NameServer_DID); 8216 if (!ndlp) { 8217 lpfc_els_flush_rscn(vport); 8218 return 0; 8219 } 8220 ndlp->nlp_prev_state = ndlp->nlp_state; 8221 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); 8222 } 8223 ndlp->nlp_type |= NLP_FABRIC; 8224 lpfc_issue_els_plogi(vport, NameServer_DID, 0); 8225 /* Wait for NameServer login cmpl before we can 8226 * continue 8227 */ 8228 return 1; 8229 } 8230 8231 lpfc_els_flush_rscn(vport); 8232 return 0; 8233 } 8234 8235 /** 8236 * lpfc_els_rcv_flogi - Process an unsolicited flogi iocb 8237 * @vport: pointer to a host virtual N_Port data structure. 8238 * @cmdiocb: pointer to lpfc command iocb data structure. 8239 * @ndlp: pointer to a node-list data structure. 8240 * 8241 * This routine processes Fabric Login (FLOGI) IOCB received as an ELS 8242 * unsolicited event. An unsolicited FLOGI can be received in a point-to- 8243 * point topology. As an unsolicited FLOGI should not be received in a loop 8244 * mode, any unsolicited FLOGI received in loop mode shall be ignored. The 8245 * lpfc_check_sparm() routine is invoked to check the parameters in the 8246 * unsolicited FLOGI. If parameters validation failed, the routine 8247 * lpfc_els_rsp_reject() shall be called with reject reason code set to 8248 * LSEXP_SPARM_OPTIONS to reject the FLOGI. Otherwise, the Port WWN in the 8249 * FLOGI shall be compared with the Port WWN of the @vport to determine who 8250 * will initiate PLOGI. The higher lexicographical value party shall has 8251 * higher priority (as the winning port) and will initiate PLOGI and 8252 * communicate Port_IDs (Addresses) for both nodes in PLOGI. The result 8253 * of this will be marked in the @vport fc_flag field with FC_PT2PT_PLOGI 8254 * and then the lpfc_els_rsp_acc() routine is invoked to accept the FLOGI. 8255 * 8256 * Return code 8257 * 0 - Successfully processed the unsolicited flogi 8258 * 1 - Failed to process the unsolicited flogi 8259 **/ 8260 static int 8261 lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, 8262 struct lpfc_nodelist *ndlp) 8263 { 8264 struct Scsi_Host *shost = lpfc_shost_from_vport(vport); 8265 struct lpfc_hba *phba = vport->phba; 8266 struct lpfc_dmabuf *pcmd = cmdiocb->cmd_dmabuf; 8267 uint32_t *lp = (uint32_t *) pcmd->virt; 8268 union lpfc_wqe128 *wqe = &cmdiocb->wqe; 8269 struct serv_parm *sp; 8270 LPFC_MBOXQ_t *mbox; 8271 uint32_t cmd, did; 8272 int rc; 8273 unsigned long fc_flag = 0; 8274 uint32_t port_state = 0; 8275 8276 /* Clear external loopback plug detected flag */ 8277 phba->link_flag &= ~LS_EXTERNAL_LOOPBACK; 8278 8279 cmd = *lp++; 8280 sp = (struct serv_parm *) lp; 8281 8282 /* FLOGI received */ 8283 8284 lpfc_set_disctmo(vport); 8285 8286 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { 8287 /* We should never receive a FLOGI in loop mode, ignore it */ 8288 did = bf_get(wqe_els_did, &wqe->xmit_els_rsp.wqe_dest); 8289 8290 /* An FLOGI ELS command <elsCmd> was received from DID <did> in 8291 Loop Mode */ 8292 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, 8293 "0113 An FLOGI ELS command x%x was " 8294 "received from DID x%x in Loop Mode\n", 8295 cmd, did); 8296 return 1; 8297 } 8298 8299 (void) lpfc_check_sparm(vport, ndlp, sp, CLASS3, 1); 8300 8301 /* 8302 * If our portname is greater than the remote portname, 8303 * then we initiate Nport login. 8304 */ 8305 8306 rc = memcmp(&vport->fc_portname, &sp->portName, 8307 sizeof(struct lpfc_name)); 8308 8309 if (!rc) { 8310 if (phba->sli_rev < LPFC_SLI_REV4) { 8311 mbox = mempool_alloc(phba->mbox_mem_pool, 8312 GFP_KERNEL); 8313 if (!mbox) 8314 return 1; 8315 lpfc_linkdown(phba); 8316 lpfc_init_link(phba, mbox, 8317 phba->cfg_topology, 8318 phba->cfg_link_speed); 8319 mbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0; 8320 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; 8321 mbox->vport = vport; 8322 rc = lpfc_sli_issue_mbox(phba, mbox, 8323 MBX_NOWAIT); 8324 lpfc_set_loopback_flag(phba); 8325 if (rc == MBX_NOT_FINISHED) 8326 mempool_free(mbox, phba->mbox_mem_pool); 8327 return 1; 8328 } 8329 8330 /* External loopback plug insertion detected */ 8331 phba->link_flag |= LS_EXTERNAL_LOOPBACK; 8332 8333 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS | LOG_LIBDFC, 8334 "1119 External Loopback plug detected\n"); 8335 8336 /* abort the flogi coming back to ourselves 8337 * due to external loopback on the port. 8338 */ 8339 lpfc_els_abort_flogi(phba); 8340 return 0; 8341 8342 } else if (rc > 0) { /* greater than */ 8343 set_bit(FC_PT2PT_PLOGI, &vport->fc_flag); 8344 8345 /* If we have the high WWPN we can assign our own 8346 * myDID; otherwise, we have to WAIT for a PLOGI 8347 * from the remote NPort to find out what it 8348 * will be. 8349 */ 8350 vport->fc_myDID = PT2PT_LocalID; 8351 } else { 8352 vport->fc_myDID = PT2PT_RemoteID; 8353 } 8354 8355 /* 8356 * The vport state should go to LPFC_FLOGI only 8357 * AFTER we issue a FLOGI, not receive one. 8358 */ 8359 spin_lock_irq(shost->host_lock); 8360 fc_flag = vport->fc_flag; 8361 port_state = vport->port_state; 8362 /* Acking an unsol FLOGI. Count 1 for link bounce 8363 * work-around. 8364 */ 8365 vport->rcv_flogi_cnt++; 8366 spin_unlock_irq(shost->host_lock); 8367 set_bit(FC_PT2PT, &vport->fc_flag); 8368 clear_bit(FC_FABRIC, &vport->fc_flag); 8369 clear_bit(FC_PUBLIC_LOOP, &vport->fc_flag); 8370 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, 8371 "3311 Rcv Flogi PS x%x new PS x%x " 8372 "fc_flag x%lx new fc_flag x%lx\n", 8373 port_state, vport->port_state, 8374 fc_flag, vport->fc_flag); 8375 8376 /* 8377 * We temporarily set fc_myDID to make it look like we are 8378 * a Fabric. This is done just so we end up with the right 8379 * did / sid on the FLOGI ACC rsp. 8380 */ 8381 did = vport->fc_myDID; 8382 vport->fc_myDID = Fabric_DID; 8383 8384 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm)); 8385 8386 /* Defer ACC response until AFTER we issue a FLOGI */ 8387 if (!test_bit(HBA_FLOGI_ISSUED, &phba->hba_flag)) { 8388 phba->defer_flogi_acc.rx_id = bf_get(wqe_ctxt_tag, 8389 &wqe->xmit_els_rsp.wqe_com); 8390 phba->defer_flogi_acc.ox_id = bf_get(wqe_rcvoxid, 8391 &wqe->xmit_els_rsp.wqe_com); 8392 8393 vport->fc_myDID = did; 8394 8395 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, 8396 "3344 Deferring FLOGI ACC: rx_id: x%x," 8397 " ox_id: x%x, hba_flag x%lx\n", 8398 phba->defer_flogi_acc.rx_id, 8399 phba->defer_flogi_acc.ox_id, phba->hba_flag); 8400 8401 phba->defer_flogi_acc.flag = true; 8402 8403 /* This nlp_get is paired with nlp_puts that reset the 8404 * defer_flogi_acc.flag back to false. We need to retain 8405 * a kref on the ndlp until the deferred FLOGI ACC is 8406 * processed or cancelled. 8407 */ 8408 phba->defer_flogi_acc.ndlp = lpfc_nlp_get(ndlp); 8409 return 0; 8410 } 8411 8412 /* Send back ACC */ 8413 lpfc_els_rsp_acc(vport, ELS_CMD_FLOGI, cmdiocb, ndlp, NULL); 8414 8415 /* Now lets put fc_myDID back to what its supposed to be */ 8416 vport->fc_myDID = did; 8417 8418 return 0; 8419 } 8420 8421 /** 8422 * lpfc_els_rcv_rnid - Process an unsolicited rnid iocb 8423 * @vport: pointer to a host virtual N_Port data structure. 8424 * @cmdiocb: pointer to lpfc command iocb data structure. 8425 * @ndlp: pointer to a node-list data structure. 8426 * 8427 * This routine processes Request Node Identification Data (RNID) IOCB 8428 * received as an ELS unsolicited event. Only when the RNID specified format 8429 * 0x0 or 0xDF (Topology Discovery Specific Node Identification Data) 8430 * present, this routine will invoke the lpfc_els_rsp_rnid_acc() routine to 8431 * Accept (ACC) the RNID ELS command. All the other RNID formats are 8432 * rejected by invoking the lpfc_els_rsp_reject() routine. 8433 * 8434 * Return code 8435 * 0 - Successfully processed rnid iocb (currently always return 0) 8436 **/ 8437 static int 8438 lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, 8439 struct lpfc_nodelist *ndlp) 8440 { 8441 struct lpfc_dmabuf *pcmd; 8442 uint32_t *lp; 8443 RNID *rn; 8444 struct ls_rjt stat; 8445 8446 pcmd = cmdiocb->cmd_dmabuf; 8447 lp = (uint32_t *) pcmd->virt; 8448 8449 lp++; 8450 rn = (RNID *) lp; 8451 8452 /* RNID received */ 8453 8454 switch (rn->Format) { 8455 case 0: 8456 case RNID_TOPOLOGY_DISC: 8457 /* Send back ACC */ 8458 lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp); 8459 break; 8460 default: 8461 /* Reject this request because format not supported */ 8462 stat.un.b.lsRjtRsvd0 = 0; 8463 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; 8464 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; 8465 stat.un.b.vendorUnique = 0; 8466 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, 8467 NULL); 8468 } 8469 return 0; 8470 } 8471 8472 /** 8473 * lpfc_els_rcv_echo - Process an unsolicited echo iocb 8474 * @vport: pointer to a host virtual N_Port data structure. 8475 * @cmdiocb: pointer to lpfc command iocb data structure. 8476 * @ndlp: pointer to a node-list data structure. 8477 * 8478 * Return code 8479 * 0 - Successfully processed echo iocb (currently always return 0) 8480 **/ 8481 static int 8482 lpfc_els_rcv_echo(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, 8483 struct lpfc_nodelist *ndlp) 8484 { 8485 uint8_t *pcmd; 8486 8487 pcmd = (uint8_t *)cmdiocb->cmd_dmabuf->virt; 8488 8489 /* skip over first word of echo command to find echo data */ 8490 pcmd += sizeof(uint32_t); 8491 8492 lpfc_els_rsp_echo_acc(vport, pcmd, cmdiocb, ndlp); 8493 return 0; 8494 } 8495 8496 /** 8497 * lpfc_els_rcv_lirr - Process an unsolicited lirr iocb 8498 * @vport: pointer to a host virtual N_Port data structure. 8499 * @cmdiocb: pointer to lpfc command iocb data structure. 8500 * @ndlp: pointer to a node-list data structure. 8501 * 8502 * This routine processes a Link Incident Report Registration(LIRR) IOCB 8503 * received as an ELS unsolicited event. Currently, this function just invokes 8504 * the lpfc_els_rsp_reject() routine to reject the LIRR IOCB unconditionally. 8505 * 8506 * Return code 8507 * 0 - Successfully processed lirr iocb (currently always return 0) 8508 **/ 8509 static int 8510 lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, 8511 struct lpfc_nodelist *ndlp) 8512 { 8513 struct ls_rjt stat; 8514 8515 /* For now, unconditionally reject this command */ 8516 stat.un.b.lsRjtRsvd0 = 0; 8517 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; 8518 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; 8519 stat.un.b.vendorUnique = 0; 8520 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); 8521 return 0; 8522 } 8523 8524 /** 8525 * lpfc_els_rcv_rrq - Process an unsolicited rrq iocb 8526 * @vport: pointer to a host virtual N_Port data structure. 8527 * @cmdiocb: pointer to lpfc command iocb data structure. 8528 * @ndlp: pointer to a node-list data structure. 8529 * 8530 * This routine processes a Reinstate Recovery Qualifier (RRQ) IOCB 8531 * received as an ELS unsolicited event. A request to RRQ shall only 8532 * be accepted if the Originator Nx_Port N_Port_ID or the Responder 8533 * Nx_Port N_Port_ID of the target Exchange is the same as the 8534 * N_Port_ID of the Nx_Port that makes the request. If the RRQ is 8535 * not accepted, an LS_RJT with reason code "Unable to perform 8536 * command request" and reason code explanation "Invalid Originator 8537 * S_ID" shall be returned. For now, we just unconditionally accept 8538 * RRQ from the target. 8539 **/ 8540 static void 8541 lpfc_els_rcv_rrq(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, 8542 struct lpfc_nodelist *ndlp) 8543 { 8544 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); 8545 if (vport->phba->sli_rev == LPFC_SLI_REV4) 8546 lpfc_els_clear_rrq(vport, cmdiocb, ndlp); 8547 } 8548 8549 /** 8550 * lpfc_els_rsp_rls_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd 8551 * @phba: pointer to lpfc hba data structure. 8552 * @pmb: pointer to the driver internal queue element for mailbox command. 8553 * 8554 * This routine is the completion callback function for the MBX_READ_LNK_STAT 8555 * mailbox command. This callback function is to actually send the Accept 8556 * (ACC) response to a Read Link Status (RLS) unsolicited IOCB event. It 8557 * collects the link statistics from the completion of the MBX_READ_LNK_STAT 8558 * mailbox command, constructs the RLS response with the link statistics 8559 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC 8560 * response to the RLS. 8561 * 8562 * Note that the ndlp reference count will be incremented by 1 for holding the 8563 * ndlp and the reference to ndlp will be stored into the ndlp field of 8564 * the IOCB for the completion callback function to the RLS Accept Response 8565 * ELS IOCB command. 8566 * 8567 **/ 8568 static void 8569 lpfc_els_rsp_rls_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) 8570 { 8571 int rc = 0; 8572 MAILBOX_t *mb; 8573 IOCB_t *icmd; 8574 union lpfc_wqe128 *wqe; 8575 struct RLS_RSP *rls_rsp; 8576 uint8_t *pcmd; 8577 struct lpfc_iocbq *elsiocb; 8578 struct lpfc_nodelist *ndlp; 8579 uint16_t oxid; 8580 uint16_t rxid; 8581 uint32_t cmdsize; 8582 u32 ulp_context; 8583 8584 mb = &pmb->u.mb; 8585 8586 ndlp = pmb->ctx_ndlp; 8587 rxid = (uint16_t)(pmb->ctx_u.ox_rx_id & 0xffff); 8588 oxid = (uint16_t)((pmb->ctx_u.ox_rx_id >> 16) & 0xffff); 8589 memset(&pmb->ctx_u, 0, sizeof(pmb->ctx_u)); 8590 pmb->ctx_ndlp = NULL; 8591 8592 if (mb->mbxStatus) { 8593 mempool_free(pmb, phba->mbox_mem_pool); 8594 return; 8595 } 8596 8597 cmdsize = sizeof(struct RLS_RSP) + sizeof(uint32_t); 8598 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize, 8599 lpfc_max_els_tries, ndlp, 8600 ndlp->nlp_DID, ELS_CMD_ACC); 8601 8602 /* Decrement the ndlp reference count from previous mbox command */ 8603 lpfc_nlp_put(ndlp); 8604 8605 if (!elsiocb) { 8606 mempool_free(pmb, phba->mbox_mem_pool); 8607 return; 8608 } 8609 8610 ulp_context = get_job_ulpcontext(phba, elsiocb); 8611 if (phba->sli_rev == LPFC_SLI_REV4) { 8612 wqe = &elsiocb->wqe; 8613 /* Xri / rx_id */ 8614 bf_set(wqe_ctxt_tag, &wqe->generic.wqe_com, rxid); 8615 bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com, oxid); 8616 } else { 8617 icmd = &elsiocb->iocb; 8618 icmd->ulpContext = rxid; 8619 icmd->unsli3.rcvsli3.ox_id = oxid; 8620 } 8621 8622 pcmd = (uint8_t *)elsiocb->cmd_dmabuf->virt; 8623 *((uint32_t *) (pcmd)) = ELS_CMD_ACC; 8624 pcmd += sizeof(uint32_t); /* Skip past command */ 8625 rls_rsp = (struct RLS_RSP *)pcmd; 8626 8627 rls_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt); 8628 rls_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt); 8629 rls_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt); 8630 rls_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt); 8631 rls_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord); 8632 rls_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt); 8633 mempool_free(pmb, phba->mbox_mem_pool); 8634 /* Xmit ELS RLS ACC response tag <ulpIoTag> */ 8635 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS, 8636 "2874 Xmit ELS RLS ACC response tag x%x xri x%x, " 8637 "did x%x, nlp_flag x%lx, nlp_state x%x, rpi x%x\n", 8638 elsiocb->iotag, ulp_context, 8639 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, 8640 ndlp->nlp_rpi); 8641 elsiocb->cmd_cmpl = lpfc_cmpl_els_rsp; 8642 phba->fc_stat.elsXmitACC++; 8643 elsiocb->ndlp = lpfc_nlp_get(ndlp); 8644 if (!elsiocb->ndlp) { 8645 lpfc_els_free_iocb(phba, elsiocb); 8646 return; 8647 } 8648 8649 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); 8650 if (rc == IOCB_ERROR) { 8651 lpfc_els_free_iocb(phba, elsiocb); 8652 lpfc_nlp_put(ndlp); 8653 } 8654 return; 8655 } 8656 8657 /** 8658 * lpfc_els_rcv_rls - Process an unsolicited rls iocb 8659 * @vport: pointer to a host virtual N_Port data structure. 8660 * @cmdiocb: pointer to lpfc command iocb data structure. 8661 * @ndlp: pointer to a node-list data structure. 8662 * 8663 * This routine processes Read Link Status (RLS) IOCB received as an 8664 * ELS unsolicited event. It first checks the remote port state. If the 8665 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE 8666 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject 8667 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command 8668 * for reading the HBA link statistics. It is for the callback function, 8669 * lpfc_els_rsp_rls_acc(), set to the MBX_READ_LNK_STAT mailbox command 8670 * to actually sending out RPL Accept (ACC) response. 8671 * 8672 * Return codes 8673 * 0 - Successfully processed rls iocb (currently always return 0) 8674 **/ 8675 static int 8676 lpfc_els_rcv_rls(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, 8677 struct lpfc_nodelist *ndlp) 8678 { 8679 struct lpfc_hba *phba = vport->phba; 8680 LPFC_MBOXQ_t *mbox; 8681 struct ls_rjt stat; 8682 u32 ctx = get_job_ulpcontext(phba, cmdiocb); 8683 u32 ox_id = get_job_rcvoxid(phba, cmdiocb); 8684 8685 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && 8686 (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) 8687 /* reject the unsolicited RLS request and done with it */ 8688 goto reject_out; 8689 8690 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC); 8691 if (mbox) { 8692 lpfc_read_lnk_stat(phba, mbox); 8693 mbox->ctx_u.ox_rx_id = ox_id << 16 | ctx; 8694 mbox->ctx_ndlp = lpfc_nlp_get(ndlp); 8695 if (!mbox->ctx_ndlp) 8696 goto node_err; 8697 mbox->vport = vport; 8698 mbox->mbox_cmpl = lpfc_els_rsp_rls_acc; 8699 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) 8700 != MBX_NOT_FINISHED) 8701 /* Mbox completion will send ELS Response */ 8702 return 0; 8703 /* Decrement reference count used for the failed mbox 8704 * command. 8705 */ 8706 lpfc_nlp_put(ndlp); 8707 node_err: 8708 mempool_free(mbox, phba->mbox_mem_pool); 8709 } 8710 reject_out: 8711 /* issue rejection response */ 8712 stat.un.b.lsRjtRsvd0 = 0; 8713 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; 8714 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; 8715 stat.un.b.vendorUnique = 0; 8716 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); 8717 return 0; 8718 } 8719 8720 /** 8721 * lpfc_els_rcv_rtv - Process an unsolicited rtv iocb 8722 * @vport: pointer to a host virtual N_Port data structure. 8723 * @cmdiocb: pointer to lpfc command iocb data structure. 8724 * @ndlp: pointer to a node-list data structure. 8725 * 8726 * This routine processes Read Timout Value (RTV) IOCB received as an 8727 * ELS unsolicited event. It first checks the remote port state. If the 8728 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE 8729 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject 8730 * response. Otherwise, it sends the Accept(ACC) response to a Read Timeout 8731 * Value (RTV) unsolicited IOCB event. 8732 * 8733 * Note that the ndlp reference count will be incremented by 1 for holding the 8734 * ndlp and the reference to ndlp will be stored into the ndlp field of 8735 * the IOCB for the completion callback function to the RTV Accept Response 8736 * ELS IOCB command. 8737 * 8738 * Return codes 8739 * 0 - Successfully processed rtv iocb (currently always return 0) 8740 **/ 8741 static int 8742 lpfc_els_rcv_rtv(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, 8743 struct lpfc_nodelist *ndlp) 8744 { 8745 int rc = 0; 8746 IOCB_t *icmd; 8747 union lpfc_wqe128 *wqe; 8748 struct lpfc_hba *phba = vport->phba; 8749 struct ls_rjt stat; 8750 struct RTV_RSP *rtv_rsp; 8751 uint8_t *pcmd; 8752 struct lpfc_iocbq *elsiocb; 8753 uint32_t cmdsize; 8754 u32 ulp_context; 8755 8756 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && 8757 (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) 8758 /* reject the unsolicited RTV request and done with it */ 8759 goto reject_out; 8760 8761 cmdsize = sizeof(struct RTV_RSP) + sizeof(uint32_t); 8762 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize, 8763 lpfc_max_els_tries, ndlp, 8764 ndlp->nlp_DID, ELS_CMD_ACC); 8765 8766 if (!elsiocb) 8767 return 1; 8768 8769 pcmd = (uint8_t *)elsiocb->cmd_dmabuf->virt; 8770 *((uint32_t *) (pcmd)) = ELS_CMD_ACC; 8771 pcmd += sizeof(uint32_t); /* Skip past command */ 8772 8773 ulp_context = get_job_ulpcontext(phba, elsiocb); 8774 /* use the command's xri in the response */ 8775 if (phba->sli_rev == LPFC_SLI_REV4) { 8776 wqe = &elsiocb->wqe; 8777 bf_set(wqe_ctxt_tag, &wqe->generic.wqe_com, 8778 get_job_ulpcontext(phba, cmdiocb)); 8779 bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com, 8780 get_job_rcvoxid(phba, cmdiocb)); 8781 } else { 8782 icmd = &elsiocb->iocb; 8783 icmd->ulpContext = get_job_ulpcontext(phba, cmdiocb); 8784 icmd->unsli3.rcvsli3.ox_id = get_job_rcvoxid(phba, cmdiocb); 8785 } 8786 8787 rtv_rsp = (struct RTV_RSP *)pcmd; 8788 8789 /* populate RTV payload */ 8790 rtv_rsp->ratov = cpu_to_be32(phba->fc_ratov * 1000); /* report msecs */ 8791 rtv_rsp->edtov = cpu_to_be32(phba->fc_edtov); 8792 bf_set(qtov_edtovres, rtv_rsp, phba->fc_edtovResol ? 1 : 0); 8793 bf_set(qtov_rttov, rtv_rsp, 0); /* Field is for FC ONLY */ 8794 rtv_rsp->qtov = cpu_to_be32(rtv_rsp->qtov); 8795 8796 /* Xmit ELS RLS ACC response tag <ulpIoTag> */ 8797 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS, 8798 "2875 Xmit ELS RTV ACC response tag x%x xri x%x, " 8799 "did x%x, nlp_flag x%lx, nlp_state x%x, rpi x%x, " 8800 "Data: x%x x%x x%x\n", 8801 elsiocb->iotag, ulp_context, 8802 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, 8803 ndlp->nlp_rpi, 8804 rtv_rsp->ratov, rtv_rsp->edtov, rtv_rsp->qtov); 8805 elsiocb->cmd_cmpl = lpfc_cmpl_els_rsp; 8806 phba->fc_stat.elsXmitACC++; 8807 elsiocb->ndlp = lpfc_nlp_get(ndlp); 8808 if (!elsiocb->ndlp) { 8809 lpfc_els_free_iocb(phba, elsiocb); 8810 return 0; 8811 } 8812 8813 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); 8814 if (rc == IOCB_ERROR) { 8815 lpfc_els_free_iocb(phba, elsiocb); 8816 lpfc_nlp_put(ndlp); 8817 } 8818 return 0; 8819 8820 reject_out: 8821 /* issue rejection response */ 8822 stat.un.b.lsRjtRsvd0 = 0; 8823 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; 8824 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; 8825 stat.un.b.vendorUnique = 0; 8826 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); 8827 return 0; 8828 } 8829 8830 /* lpfc_issue_els_rrq - Process an unsolicited rrq iocb 8831 * @vport: pointer to a host virtual N_Port data structure. 8832 * @ndlp: pointer to a node-list data structure. 8833 * @did: DID of the target. 8834 * @rrq: Pointer to the rrq struct. 8835 * 8836 * Build a ELS RRQ command and send it to the target. If the issue_iocb is 8837 * successful, the completion handler will clear the RRQ. 8838 * 8839 * Return codes 8840 * 0 - Successfully sent rrq els iocb. 8841 * 1 - Failed to send rrq els iocb. 8842 **/ 8843 static int 8844 lpfc_issue_els_rrq(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, 8845 uint32_t did, struct lpfc_node_rrq *rrq) 8846 { 8847 struct lpfc_hba *phba = vport->phba; 8848 struct RRQ *els_rrq; 8849 struct lpfc_iocbq *elsiocb; 8850 uint8_t *pcmd; 8851 uint16_t cmdsize; 8852 int ret; 8853 8854 if (!ndlp) 8855 return 1; 8856 8857 /* If ndlp is not NULL, we will bump the reference count on it */ 8858 cmdsize = (sizeof(uint32_t) + sizeof(struct RRQ)); 8859 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, did, 8860 ELS_CMD_RRQ); 8861 if (!elsiocb) 8862 return 1; 8863 8864 pcmd = (uint8_t *)elsiocb->cmd_dmabuf->virt; 8865 8866 /* For RRQ request, remainder of payload is Exchange IDs */ 8867 *((uint32_t *) (pcmd)) = ELS_CMD_RRQ; 8868 pcmd += sizeof(uint32_t); 8869 els_rrq = (struct RRQ *) pcmd; 8870 8871 bf_set(rrq_oxid, els_rrq, phba->sli4_hba.xri_ids[rrq->xritag]); 8872 bf_set(rrq_rxid, els_rrq, rrq->rxid); 8873 bf_set(rrq_did, els_rrq, vport->fc_myDID); 8874 els_rrq->rrq = cpu_to_be32(els_rrq->rrq); 8875 els_rrq->rrq_exchg = cpu_to_be32(els_rrq->rrq_exchg); 8876 8877 8878 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, 8879 "Issue RRQ: did:x%x", 8880 did, rrq->xritag, rrq->rxid); 8881 elsiocb->context_un.rrq = rrq; 8882 elsiocb->cmd_cmpl = lpfc_cmpl_els_rrq; 8883 8884 elsiocb->ndlp = lpfc_nlp_get(ndlp); 8885 if (!elsiocb->ndlp) 8886 goto io_err; 8887 8888 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); 8889 if (ret == IOCB_ERROR) { 8890 lpfc_nlp_put(ndlp); 8891 goto io_err; 8892 } 8893 return 0; 8894 8895 io_err: 8896 lpfc_els_free_iocb(phba, elsiocb); 8897 return 1; 8898 } 8899 8900 /** 8901 * lpfc_send_rrq - Sends ELS RRQ if needed. 8902 * @phba: pointer to lpfc hba data structure. 8903 * @rrq: pointer to the active rrq. 8904 * 8905 * This routine will call the lpfc_issue_els_rrq if the rrq is 8906 * still active for the xri. If this function returns a failure then 8907 * the caller needs to clean up the RRQ by calling lpfc_clr_active_rrq. 8908 * 8909 * Returns 0 Success. 8910 * 1 Failure. 8911 **/ 8912 int 8913 lpfc_send_rrq(struct lpfc_hba *phba, struct lpfc_node_rrq *rrq) 8914 { 8915 struct lpfc_nodelist *ndlp = lpfc_findnode_did(rrq->vport, 8916 rrq->nlp_DID); 8917 if (!ndlp) 8918 return 1; 8919 8920 if (lpfc_test_rrq_active(phba, ndlp, rrq->xritag)) 8921 return lpfc_issue_els_rrq(rrq->vport, ndlp, 8922 rrq->nlp_DID, rrq); 8923 else 8924 return 1; 8925 } 8926 8927 /** 8928 * lpfc_els_rsp_rpl_acc - Issue an accept rpl els command 8929 * @vport: pointer to a host virtual N_Port data structure. 8930 * @cmdsize: size of the ELS command. 8931 * @oldiocb: pointer to the original lpfc command iocb data structure. 8932 * @ndlp: pointer to a node-list data structure. 8933 * 8934 * This routine issuees an Accept (ACC) Read Port List (RPL) ELS command. 8935 * It is to be called by the lpfc_els_rcv_rpl() routine to accept the RPL. 8936 * 8937 * Note that the ndlp reference count will be incremented by 1 for holding the 8938 * ndlp and the reference to ndlp will be stored into the ndlp field of 8939 * the IOCB for the completion callback function to the RPL Accept Response 8940 * ELS command. 8941 * 8942 * Return code 8943 * 0 - Successfully issued ACC RPL ELS command 8944 * 1 - Failed to issue ACC RPL ELS command 8945 **/ 8946 static int 8947 lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize, 8948 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp) 8949 { 8950 int rc = 0; 8951 struct lpfc_hba *phba = vport->phba; 8952 IOCB_t *icmd; 8953 union lpfc_wqe128 *wqe; 8954 RPL_RSP rpl_rsp; 8955 struct lpfc_iocbq *elsiocb; 8956 uint8_t *pcmd; 8957 u32 ulp_context; 8958 8959 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, 8960 ndlp->nlp_DID, ELS_CMD_ACC); 8961 8962 if (!elsiocb) 8963 return 1; 8964 8965 ulp_context = get_job_ulpcontext(phba, elsiocb); 8966 if (phba->sli_rev == LPFC_SLI_REV4) { 8967 wqe = &elsiocb->wqe; 8968 /* Xri / rx_id */ 8969 bf_set(wqe_ctxt_tag, &wqe->generic.wqe_com, 8970 get_job_ulpcontext(phba, oldiocb)); 8971 bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com, 8972 get_job_rcvoxid(phba, oldiocb)); 8973 } else { 8974 icmd = &elsiocb->iocb; 8975 icmd->ulpContext = get_job_ulpcontext(phba, oldiocb); 8976 icmd->unsli3.rcvsli3.ox_id = get_job_rcvoxid(phba, oldiocb); 8977 } 8978 8979 pcmd = elsiocb->cmd_dmabuf->virt; 8980 *((uint32_t *) (pcmd)) = ELS_CMD_ACC; 8981 pcmd += sizeof(uint16_t); 8982 *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize); 8983 pcmd += sizeof(uint16_t); 8984 8985 /* Setup the RPL ACC payload */ 8986 rpl_rsp.listLen = be32_to_cpu(1); 8987 rpl_rsp.index = 0; 8988 rpl_rsp.port_num_blk.portNum = 0; 8989 rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID); 8990 memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname, 8991 sizeof(struct lpfc_name)); 8992 memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t)); 8993 /* Xmit ELS RPL ACC response tag <ulpIoTag> */ 8994 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, 8995 "0120 Xmit ELS RPL ACC response tag x%x " 8996 "xri x%x, did x%x, nlp_flag x%lx, nlp_state x%x, " 8997 "rpi x%x\n", 8998 elsiocb->iotag, ulp_context, 8999 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, 9000 ndlp->nlp_rpi); 9001 elsiocb->cmd_cmpl = lpfc_cmpl_els_rsp; 9002 phba->fc_stat.elsXmitACC++; 9003 elsiocb->ndlp = lpfc_nlp_get(ndlp); 9004 if (!elsiocb->ndlp) { 9005 lpfc_els_free_iocb(phba, elsiocb); 9006 return 1; 9007 } 9008 9009 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); 9010 if (rc == IOCB_ERROR) { 9011 lpfc_els_free_iocb(phba, elsiocb); 9012 lpfc_nlp_put(ndlp); 9013 return 1; 9014 } 9015 9016 return 0; 9017 } 9018 9019 /** 9020 * lpfc_els_rcv_rpl - Process an unsolicited rpl iocb 9021 * @vport: pointer to a host virtual N_Port data structure. 9022 * @cmdiocb: pointer to lpfc command iocb data structure. 9023 * @ndlp: pointer to a node-list data structure. 9024 * 9025 * This routine processes Read Port List (RPL) IOCB received as an ELS 9026 * unsolicited event. It first checks the remote port state. If the remote 9027 * port is not in NLP_STE_UNMAPPED_NODE and NLP_STE_MAPPED_NODE states, it 9028 * invokes the lpfc_els_rsp_reject() routine to send reject response. 9029 * Otherwise, this routine then invokes the lpfc_els_rsp_rpl_acc() routine 9030 * to accept the RPL. 9031 * 9032 * Return code 9033 * 0 - Successfully processed rpl iocb (currently always return 0) 9034 **/ 9035 static int 9036 lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, 9037 struct lpfc_nodelist *ndlp) 9038 { 9039 struct lpfc_dmabuf *pcmd; 9040 uint32_t *lp; 9041 uint32_t maxsize; 9042 uint16_t cmdsize; 9043 RPL *rpl; 9044 struct ls_rjt stat; 9045 9046 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && 9047 (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) { 9048 /* issue rejection response */ 9049 stat.un.b.lsRjtRsvd0 = 0; 9050 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; 9051 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; 9052 stat.un.b.vendorUnique = 0; 9053 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, 9054 NULL); 9055 /* rejected the unsolicited RPL request and done with it */ 9056 return 0; 9057 } 9058 9059 pcmd = cmdiocb->cmd_dmabuf; 9060 lp = (uint32_t *) pcmd->virt; 9061 rpl = (RPL *) (lp + 1); 9062 maxsize = be32_to_cpu(rpl->maxsize); 9063 9064 /* We support only one port */ 9065 if ((rpl->index == 0) && 9066 ((maxsize == 0) || 9067 ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) { 9068 cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP); 9069 } else { 9070 cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t); 9071 } 9072 lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp); 9073 9074 return 0; 9075 } 9076 9077 /** 9078 * lpfc_els_rcv_farp - Process an unsolicited farp request els command 9079 * @vport: pointer to a virtual N_Port data structure. 9080 * @cmdiocb: pointer to lpfc command iocb data structure. 9081 * @ndlp: pointer to a node-list data structure. 9082 * 9083 * This routine processes Fibre Channel Address Resolution Protocol 9084 * (FARP) Request IOCB received as an ELS unsolicited event. Currently, 9085 * the lpfc driver only supports matching on WWPN or WWNN for FARP. As such, 9086 * FARP_MATCH_PORT flag and FARP_MATCH_NODE flag are checked against the 9087 * Match Flag in the FARP request IOCB: if FARP_MATCH_PORT flag is set, the 9088 * remote PortName is compared against the FC PortName stored in the @vport 9089 * data structure; if FARP_MATCH_NODE flag is set, the remote NodeName is 9090 * compared against the FC NodeName stored in the @vport data structure. 9091 * If any of these matches and the FARP_REQUEST_FARPR flag is set in the 9092 * FARP request IOCB Response Flag, the lpfc_issue_els_farpr() routine is 9093 * invoked to send out FARP Response to the remote node. Before sending the 9094 * FARP Response, however, the FARP_REQUEST_PLOGI flag is check in the FARP 9095 * request IOCB Response Flag and, if it is set, the lpfc_issue_els_plogi() 9096 * routine is invoked to log into the remote port first. 9097 * 9098 * Return code 9099 * 0 - Either the FARP Match Mode not supported or successfully processed 9100 **/ 9101 static int 9102 lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, 9103 struct lpfc_nodelist *ndlp) 9104 { 9105 struct lpfc_dmabuf *pcmd; 9106 uint32_t *lp; 9107 FARP *fp; 9108 uint32_t cnt, did; 9109 9110 did = get_job_els_rsp64_did(vport->phba, cmdiocb); 9111 pcmd = cmdiocb->cmd_dmabuf; 9112 lp = (uint32_t *) pcmd->virt; 9113 9114 lp++; 9115 fp = (FARP *) lp; 9116 /* FARP-REQ received from DID <did> */ 9117 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, 9118 "0601 FARP-REQ received from DID x%x\n", did); 9119 /* We will only support match on WWPN or WWNN */ 9120 if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) { 9121 return 0; 9122 } 9123 9124 cnt = 0; 9125 /* If this FARP command is searching for my portname */ 9126 if (fp->Mflags & FARP_MATCH_PORT) { 9127 if (memcmp(&fp->RportName, &vport->fc_portname, 9128 sizeof(struct lpfc_name)) == 0) 9129 cnt = 1; 9130 } 9131 9132 /* If this FARP command is searching for my nodename */ 9133 if (fp->Mflags & FARP_MATCH_NODE) { 9134 if (memcmp(&fp->RnodeName, &vport->fc_nodename, 9135 sizeof(struct lpfc_name)) == 0) 9136 cnt = 1; 9137 } 9138 9139 if (cnt) { 9140 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) || 9141 (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) { 9142 /* Log back into the node before sending the FARP. */ 9143 if (fp->Rflags & FARP_REQUEST_PLOGI) { 9144 ndlp->nlp_prev_state = ndlp->nlp_state; 9145 lpfc_nlp_set_state(vport, ndlp, 9146 NLP_STE_PLOGI_ISSUE); 9147 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0); 9148 } 9149 9150 /* Send a FARP response to that node */ 9151 if (fp->Rflags & FARP_REQUEST_FARPR) 9152 lpfc_issue_els_farpr(vport, did, 0); 9153 } 9154 } 9155 return 0; 9156 } 9157 9158 /** 9159 * lpfc_els_rcv_farpr - Process an unsolicited farp response iocb 9160 * @vport: pointer to a host virtual N_Port data structure. 9161 * @cmdiocb: pointer to lpfc command iocb data structure. 9162 * @ndlp: pointer to a node-list data structure. 9163 * 9164 * This routine processes Fibre Channel Address Resolution Protocol 9165 * Response (FARPR) IOCB received as an ELS unsolicited event. It simply 9166 * invokes the lpfc_els_rsp_acc() routine to the remote node to accept 9167 * the FARP response request. 9168 * 9169 * Return code 9170 * 0 - Successfully processed FARPR IOCB (currently always return 0) 9171 **/ 9172 static int 9173 lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, 9174 struct lpfc_nodelist *ndlp) 9175 { 9176 uint32_t did; 9177 9178 did = get_job_els_rsp64_did(vport->phba, cmdiocb); 9179 9180 /* FARP-RSP received from DID <did> */ 9181 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, 9182 "0600 FARP-RSP received from DID x%x\n", did); 9183 /* ACCEPT the Farp resp request */ 9184 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); 9185 9186 return 0; 9187 } 9188 9189 /** 9190 * lpfc_els_rcv_fan - Process an unsolicited fan iocb command 9191 * @vport: pointer to a host virtual N_Port data structure. 9192 * @cmdiocb: pointer to lpfc command iocb data structure. 9193 * @fan_ndlp: pointer to a node-list data structure. 9194 * 9195 * This routine processes a Fabric Address Notification (FAN) IOCB 9196 * command received as an ELS unsolicited event. The FAN ELS command will 9197 * only be processed on a physical port (i.e., the @vport represents the 9198 * physical port). The fabric NodeName and PortName from the FAN IOCB are 9199 * compared against those in the phba data structure. If any of those is 9200 * different, the lpfc_initial_flogi() routine is invoked to initialize 9201 * Fabric Login (FLOGI) to the fabric to start the discover over. Otherwise, 9202 * if both of those are identical, the lpfc_issue_fabric_reglogin() routine 9203 * is invoked to register login to the fabric. 9204 * 9205 * Return code 9206 * 0 - Successfully processed fan iocb (currently always return 0). 9207 **/ 9208 static int 9209 lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, 9210 struct lpfc_nodelist *fan_ndlp) 9211 { 9212 struct lpfc_hba *phba = vport->phba; 9213 uint32_t *lp; 9214 FAN *fp; 9215 9216 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, "0265 FAN received\n"); 9217 lp = (uint32_t *)cmdiocb->cmd_dmabuf->virt; 9218 fp = (FAN *) ++lp; 9219 /* FAN received; Fan does not have a reply sequence */ 9220 if ((vport == phba->pport) && 9221 (vport->port_state == LPFC_LOCAL_CFG_LINK)) { 9222 if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName, 9223 sizeof(struct lpfc_name))) || 9224 (memcmp(&phba->fc_fabparam.portName, &fp->FportName, 9225 sizeof(struct lpfc_name)))) { 9226 /* This port has switched fabrics. FLOGI is required */ 9227 lpfc_issue_init_vfi(vport); 9228 } else { 9229 /* FAN verified - skip FLOGI */ 9230 vport->fc_myDID = vport->fc_prevDID; 9231 if (phba->sli_rev < LPFC_SLI_REV4) 9232 lpfc_issue_fabric_reglogin(vport); 9233 else { 9234 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, 9235 "3138 Need register VFI: (x%x/%x)\n", 9236 vport->fc_prevDID, vport->fc_myDID); 9237 lpfc_issue_reg_vfi(vport); 9238 } 9239 } 9240 } 9241 return 0; 9242 } 9243 9244 /** 9245 * lpfc_els_rcv_edc - Process an unsolicited EDC iocb 9246 * @vport: pointer to a host virtual N_Port data structure. 9247 * @cmdiocb: pointer to lpfc command iocb data structure. 9248 * @ndlp: pointer to a node-list data structure. 9249 * 9250 * Return code 9251 * 0 - Successfully processed echo iocb (currently always return 0) 9252 **/ 9253 static int 9254 lpfc_els_rcv_edc(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, 9255 struct lpfc_nodelist *ndlp) 9256 { 9257 struct lpfc_hba *phba = vport->phba; 9258 struct fc_els_edc *edc_req; 9259 struct fc_tlv_desc *tlv; 9260 uint8_t *payload; 9261 uint32_t *ptr, dtag; 9262 const char *dtag_nm; 9263 int desc_cnt = 0, bytes_remain; 9264 struct fc_diag_lnkflt_desc *plnkflt; 9265 9266 payload = cmdiocb->cmd_dmabuf->virt; 9267 9268 edc_req = (struct fc_els_edc *)payload; 9269 bytes_remain = be32_to_cpu(edc_req->desc_len); 9270 9271 ptr = (uint32_t *)payload; 9272 lpfc_printf_vlog(vport, KERN_INFO, 9273 LOG_ELS | LOG_CGN_MGMT | LOG_LDS_EVENT, 9274 "3319 Rcv EDC payload len %d: x%x x%x x%x\n", 9275 bytes_remain, be32_to_cpu(*ptr), 9276 be32_to_cpu(*(ptr + 1)), be32_to_cpu(*(ptr + 2))); 9277 9278 /* No signal support unless there is a congestion descriptor */ 9279 phba->cgn_reg_signal = EDC_CG_SIG_NOTSUPPORTED; 9280 phba->cgn_sig_freq = 0; 9281 phba->cgn_reg_fpin = LPFC_CGN_FPIN_ALARM | LPFC_CGN_FPIN_WARN; 9282 9283 if (bytes_remain <= 0) 9284 goto out; 9285 9286 tlv = edc_req->desc; 9287 9288 /* 9289 * cycle through EDC diagnostic descriptors to find the 9290 * congestion signaling capability descriptor 9291 */ 9292 while (bytes_remain) { 9293 if (bytes_remain < FC_TLV_DESC_HDR_SZ) { 9294 lpfc_printf_log(phba, KERN_WARNING, 9295 LOG_ELS | LOG_CGN_MGMT | LOG_LDS_EVENT, 9296 "6464 Truncated TLV hdr on " 9297 "Diagnostic descriptor[%d]\n", 9298 desc_cnt); 9299 goto out; 9300 } 9301 9302 dtag = be32_to_cpu(tlv->desc_tag); 9303 switch (dtag) { 9304 case ELS_DTAG_LNK_FAULT_CAP: 9305 if (bytes_remain < FC_TLV_DESC_SZ_FROM_LENGTH(tlv) || 9306 FC_TLV_DESC_SZ_FROM_LENGTH(tlv) != 9307 sizeof(struct fc_diag_lnkflt_desc)) { 9308 lpfc_printf_log(phba, KERN_WARNING, 9309 LOG_ELS | LOG_CGN_MGMT | LOG_LDS_EVENT, 9310 "6465 Truncated Link Fault Diagnostic " 9311 "descriptor[%d]: %d vs 0x%zx 0x%zx\n", 9312 desc_cnt, bytes_remain, 9313 FC_TLV_DESC_SZ_FROM_LENGTH(tlv), 9314 sizeof(struct fc_diag_lnkflt_desc)); 9315 goto out; 9316 } 9317 plnkflt = (struct fc_diag_lnkflt_desc *)tlv; 9318 lpfc_printf_log(phba, KERN_INFO, 9319 LOG_ELS | LOG_LDS_EVENT, 9320 "4626 Link Fault Desc Data: x%08x len x%x " 9321 "da x%x dd x%x interval x%x\n", 9322 be32_to_cpu(plnkflt->desc_tag), 9323 be32_to_cpu(plnkflt->desc_len), 9324 be32_to_cpu( 9325 plnkflt->degrade_activate_threshold), 9326 be32_to_cpu( 9327 plnkflt->degrade_deactivate_threshold), 9328 be32_to_cpu(plnkflt->fec_degrade_interval)); 9329 break; 9330 case ELS_DTAG_CG_SIGNAL_CAP: 9331 if (bytes_remain < FC_TLV_DESC_SZ_FROM_LENGTH(tlv) || 9332 FC_TLV_DESC_SZ_FROM_LENGTH(tlv) != 9333 sizeof(struct fc_diag_cg_sig_desc)) { 9334 lpfc_printf_log( 9335 phba, KERN_WARNING, LOG_CGN_MGMT, 9336 "6466 Truncated cgn signal Diagnostic " 9337 "descriptor[%d]: %d vs 0x%zx 0x%zx\n", 9338 desc_cnt, bytes_remain, 9339 FC_TLV_DESC_SZ_FROM_LENGTH(tlv), 9340 sizeof(struct fc_diag_cg_sig_desc)); 9341 goto out; 9342 } 9343 9344 phba->cgn_reg_fpin = phba->cgn_init_reg_fpin; 9345 phba->cgn_reg_signal = phba->cgn_init_reg_signal; 9346 9347 /* We start negotiation with lpfc_fabric_cgn_frequency. 9348 * When we process the EDC, we will settle on the 9349 * higher frequency. 9350 */ 9351 phba->cgn_sig_freq = lpfc_fabric_cgn_frequency; 9352 9353 lpfc_least_capable_settings( 9354 phba, (struct fc_diag_cg_sig_desc *)tlv); 9355 break; 9356 default: 9357 dtag_nm = lpfc_get_tlv_dtag_nm(dtag); 9358 lpfc_printf_log(phba, KERN_WARNING, 9359 LOG_ELS | LOG_CGN_MGMT | LOG_LDS_EVENT, 9360 "6467 unknown Diagnostic " 9361 "Descriptor[%d]: tag x%x (%s)\n", 9362 desc_cnt, dtag, dtag_nm); 9363 } 9364 bytes_remain -= FC_TLV_DESC_SZ_FROM_LENGTH(tlv); 9365 tlv = fc_tlv_next_desc(tlv); 9366 desc_cnt++; 9367 } 9368 out: 9369 /* Need to send back an ACC */ 9370 lpfc_issue_els_edc_rsp(vport, cmdiocb, ndlp); 9371 9372 lpfc_config_cgn_signal(phba); 9373 return 0; 9374 } 9375 9376 /** 9377 * lpfc_els_timeout - Handler funciton to the els timer 9378 * @t: timer context used to obtain the vport. 9379 * 9380 * This routine is invoked by the ELS timer after timeout. It posts the ELS 9381 * timer timeout event by setting the WORKER_ELS_TMO bit to the work port 9382 * event bitmap and then invokes the lpfc_worker_wake_up() routine to wake 9383 * up the worker thread. It is for the worker thread to invoke the routine 9384 * lpfc_els_timeout_handler() to work on the posted event WORKER_ELS_TMO. 9385 **/ 9386 void 9387 lpfc_els_timeout(struct timer_list *t) 9388 { 9389 struct lpfc_vport *vport = timer_container_of(vport, t, els_tmofunc); 9390 struct lpfc_hba *phba = vport->phba; 9391 uint32_t tmo_posted; 9392 unsigned long iflag; 9393 9394 spin_lock_irqsave(&vport->work_port_lock, iflag); 9395 tmo_posted = vport->work_port_events & WORKER_ELS_TMO; 9396 if (!tmo_posted && !test_bit(FC_UNLOADING, &vport->load_flag)) 9397 vport->work_port_events |= WORKER_ELS_TMO; 9398 spin_unlock_irqrestore(&vport->work_port_lock, iflag); 9399 9400 if (!tmo_posted && !test_bit(FC_UNLOADING, &vport->load_flag)) 9401 lpfc_worker_wake_up(phba); 9402 return; 9403 } 9404 9405 9406 /** 9407 * lpfc_els_timeout_handler - Process an els timeout event 9408 * @vport: pointer to a virtual N_Port data structure. 9409 * 9410 * This routine is the actual handler function that processes an ELS timeout 9411 * event. It walks the ELS ring to get and abort all the IOCBs (except the 9412 * ABORT/CLOSE/FARP/FARPR/FDISC), which are associated with the @vport by 9413 * invoking the lpfc_sli_issue_abort_iotag() routine. 9414 **/ 9415 void 9416 lpfc_els_timeout_handler(struct lpfc_vport *vport) 9417 { 9418 struct lpfc_hba *phba = vport->phba; 9419 struct lpfc_sli_ring *pring; 9420 struct lpfc_iocbq *tmp_iocb, *piocb; 9421 IOCB_t *cmd = NULL; 9422 struct lpfc_dmabuf *pcmd; 9423 uint32_t els_command = 0; 9424 uint32_t timeout; 9425 uint32_t remote_ID = 0xffffffff; 9426 LIST_HEAD(abort_list); 9427 u32 ulp_command = 0, ulp_context = 0, did = 0, iotag = 0; 9428 9429 9430 timeout = (uint32_t)(phba->fc_ratov << 1); 9431 9432 pring = lpfc_phba_elsring(phba); 9433 if (unlikely(!pring)) 9434 return; 9435 9436 if (test_bit(FC_UNLOADING, &phba->pport->load_flag)) 9437 return; 9438 9439 spin_lock_irq(&phba->hbalock); 9440 if (phba->sli_rev == LPFC_SLI_REV4) 9441 spin_lock(&pring->ring_lock); 9442 9443 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) { 9444 ulp_command = get_job_cmnd(phba, piocb); 9445 ulp_context = get_job_ulpcontext(phba, piocb); 9446 did = get_job_els_rsp64_did(phba, piocb); 9447 9448 if (phba->sli_rev == LPFC_SLI_REV4) { 9449 iotag = get_wqe_reqtag(piocb); 9450 } else { 9451 cmd = &piocb->iocb; 9452 iotag = cmd->ulpIoTag; 9453 } 9454 9455 if ((piocb->cmd_flag & LPFC_IO_LIBDFC) != 0 || 9456 ulp_command == CMD_ABORT_XRI_CX || 9457 ulp_command == CMD_ABORT_XRI_CN || 9458 ulp_command == CMD_CLOSE_XRI_CN) 9459 continue; 9460 9461 if (piocb->vport != vport) 9462 continue; 9463 9464 pcmd = piocb->cmd_dmabuf; 9465 if (pcmd) 9466 els_command = *(uint32_t *) (pcmd->virt); 9467 9468 if (els_command == ELS_CMD_FARP || 9469 els_command == ELS_CMD_FARPR || 9470 els_command == ELS_CMD_FDISC) 9471 continue; 9472 9473 if (piocb->drvrTimeout > 0) { 9474 if (piocb->drvrTimeout >= timeout) 9475 piocb->drvrTimeout -= timeout; 9476 else 9477 piocb->drvrTimeout = 0; 9478 continue; 9479 } 9480 9481 remote_ID = 0xffffffff; 9482 if (ulp_command != CMD_GEN_REQUEST64_CR) { 9483 remote_ID = did; 9484 } else { 9485 struct lpfc_nodelist *ndlp; 9486 ndlp = __lpfc_findnode_rpi(vport, ulp_context); 9487 if (ndlp) 9488 remote_ID = ndlp->nlp_DID; 9489 } 9490 list_add_tail(&piocb->dlist, &abort_list); 9491 } 9492 if (phba->sli_rev == LPFC_SLI_REV4) 9493 spin_unlock(&pring->ring_lock); 9494 spin_unlock_irq(&phba->hbalock); 9495 9496 list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) { 9497 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, 9498 "0127 ELS timeout Data: x%x x%x x%x " 9499 "x%x\n", els_command, 9500 remote_ID, ulp_command, iotag); 9501 9502 spin_lock_irq(&phba->hbalock); 9503 list_del_init(&piocb->dlist); 9504 lpfc_sli_issue_abort_iotag(phba, pring, piocb, NULL); 9505 spin_unlock_irq(&phba->hbalock); 9506 } 9507 9508 /* Make sure HBA is alive */ 9509 lpfc_issue_hb_tmo(phba); 9510 9511 if (!list_empty(&pring->txcmplq)) 9512 if (!test_bit(FC_UNLOADING, &phba->pport->load_flag)) 9513 mod_timer(&vport->els_tmofunc, 9514 jiffies + secs_to_jiffies(timeout)); 9515 } 9516 9517 /** 9518 * lpfc_els_flush_cmd - Clean up the outstanding els commands to a vport 9519 * @vport: pointer to a host virtual N_Port data structure. 9520 * 9521 * This routine is used to clean up all the outstanding ELS commands on a 9522 * @vport. It first aborts the @vport by invoking lpfc_fabric_abort_vport() 9523 * routine. After that, it walks the ELS transmit queue to remove all the 9524 * IOCBs with the @vport other than the QUE_RING and ABORT/CLOSE IOCBs. For 9525 * the IOCBs with a non-NULL completion callback function, the callback 9526 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and 9527 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs with a NULL completion 9528 * callback function, the IOCB will simply be released. Finally, it walks 9529 * the ELS transmit completion queue to issue an abort IOCB to any transmit 9530 * completion queue IOCB that is associated with the @vport and is not 9531 * an IOCB from libdfc (i.e., the management plane IOCBs that are not 9532 * part of the discovery state machine) out to HBA by invoking the 9533 * lpfc_sli_issue_abort_iotag() routine. Note that this function issues the 9534 * abort IOCB to any transmit completion queueed IOCB, it does not guarantee 9535 * the IOCBs are aborted when this function returns. 9536 **/ 9537 void 9538 lpfc_els_flush_cmd(struct lpfc_vport *vport) 9539 { 9540 LIST_HEAD(abort_list); 9541 LIST_HEAD(cancel_list); 9542 struct lpfc_hba *phba = vport->phba; 9543 struct lpfc_sli_ring *pring; 9544 struct lpfc_iocbq *tmp_iocb, *piocb; 9545 u32 ulp_command; 9546 unsigned long iflags = 0; 9547 bool mbx_tmo_err; 9548 9549 lpfc_fabric_abort_vport(vport); 9550 9551 /* 9552 * For SLI3, only the hbalock is required. But SLI4 needs to coordinate 9553 * with the ring insert operation. Because lpfc_sli_issue_abort_iotag 9554 * ultimately grabs the ring_lock, the driver must splice the list into 9555 * a working list and release the locks before calling the abort. 9556 */ 9557 spin_lock_irqsave(&phba->hbalock, iflags); 9558 pring = lpfc_phba_elsring(phba); 9559 9560 /* Bail out if we've no ELS wq, like in PCI error recovery case. */ 9561 if (unlikely(!pring)) { 9562 spin_unlock_irqrestore(&phba->hbalock, iflags); 9563 return; 9564 } 9565 9566 if (phba->sli_rev == LPFC_SLI_REV4) 9567 spin_lock(&pring->ring_lock); 9568 9569 mbx_tmo_err = test_bit(MBX_TMO_ERR, &phba->bit_flags); 9570 /* First we need to issue aborts to outstanding cmds on txcmpl */ 9571 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) { 9572 if (piocb->vport != vport) 9573 continue; 9574 9575 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, 9576 "2243 iotag = 0x%x cmd_flag = 0x%x " 9577 "ulp_command = 0x%x sli_flag = 0x%x\n", 9578 piocb->iotag, piocb->cmd_flag, 9579 get_job_cmnd(phba, piocb), 9580 phba->sli.sli_flag); 9581 9582 if ((phba->sli.sli_flag & LPFC_SLI_ACTIVE) && !mbx_tmo_err) { 9583 if (piocb->cmd_flag & LPFC_IO_LIBDFC) 9584 continue; 9585 if (piocb->cmd_flag & LPFC_DRIVER_ABORTED) 9586 continue; 9587 } 9588 9589 /* On the ELS ring we can have ELS_REQUESTs, ELS_RSPs, 9590 * or GEN_REQUESTs waiting for a CQE response. 9591 */ 9592 ulp_command = get_job_cmnd(phba, piocb); 9593 if (ulp_command == CMD_ELS_REQUEST64_WQE || 9594 ulp_command == CMD_XMIT_ELS_RSP64_WQE) { 9595 list_add_tail(&piocb->dlist, &abort_list); 9596 9597 /* If the link is down when flushing ELS commands 9598 * the firmware will not complete them till after 9599 * the link comes back up. This may confuse 9600 * discovery for the new link up, so we need to 9601 * change the compl routine to just clean up the iocb 9602 * and avoid any retry logic. 9603 */ 9604 if (phba->link_state == LPFC_LINK_DOWN) 9605 piocb->cmd_cmpl = lpfc_cmpl_els_link_down; 9606 } else if (ulp_command == CMD_GEN_REQUEST64_CR || 9607 mbx_tmo_err) 9608 list_add_tail(&piocb->dlist, &abort_list); 9609 } 9610 9611 if (phba->sli_rev == LPFC_SLI_REV4) 9612 spin_unlock(&pring->ring_lock); 9613 spin_unlock_irqrestore(&phba->hbalock, iflags); 9614 9615 /* Abort each txcmpl iocb on aborted list and remove the dlist links. */ 9616 list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) { 9617 spin_lock_irqsave(&phba->hbalock, iflags); 9618 list_del_init(&piocb->dlist); 9619 if (mbx_tmo_err || !(phba->sli.sli_flag & LPFC_SLI_ACTIVE)) 9620 list_move_tail(&piocb->list, &cancel_list); 9621 else 9622 lpfc_sli_issue_abort_iotag(phba, pring, piocb, NULL); 9623 9624 spin_unlock_irqrestore(&phba->hbalock, iflags); 9625 } 9626 if (!list_empty(&cancel_list)) 9627 lpfc_sli_cancel_iocbs(phba, &cancel_list, IOSTAT_LOCAL_REJECT, 9628 IOERR_SLI_ABORTED); 9629 else 9630 /* Make sure HBA is alive */ 9631 lpfc_issue_hb_tmo(phba); 9632 9633 if (!list_empty(&abort_list)) 9634 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, 9635 "3387 abort list for txq not empty\n"); 9636 INIT_LIST_HEAD(&abort_list); 9637 9638 spin_lock_irqsave(&phba->hbalock, iflags); 9639 if (phba->sli_rev == LPFC_SLI_REV4) 9640 spin_lock(&pring->ring_lock); 9641 9642 /* No need to abort the txq list, 9643 * just queue them up for lpfc_sli_cancel_iocbs 9644 */ 9645 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) { 9646 ulp_command = get_job_cmnd(phba, piocb); 9647 9648 if (piocb->cmd_flag & LPFC_IO_LIBDFC) 9649 continue; 9650 9651 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */ 9652 if (ulp_command == CMD_QUE_RING_BUF_CN || 9653 ulp_command == CMD_QUE_RING_BUF64_CN || 9654 ulp_command == CMD_CLOSE_XRI_CN || 9655 ulp_command == CMD_ABORT_XRI_CN || 9656 ulp_command == CMD_ABORT_XRI_CX) 9657 continue; 9658 9659 if (piocb->vport != vport) 9660 continue; 9661 9662 list_del_init(&piocb->list); 9663 list_add_tail(&piocb->list, &abort_list); 9664 } 9665 9666 /* The same holds true for any FLOGI/FDISC on the fabric_iocb_list */ 9667 if (vport == phba->pport) { 9668 list_for_each_entry_safe(piocb, tmp_iocb, 9669 &phba->fabric_iocb_list, list) { 9670 list_del_init(&piocb->list); 9671 list_add_tail(&piocb->list, &abort_list); 9672 } 9673 } 9674 9675 if (phba->sli_rev == LPFC_SLI_REV4) 9676 spin_unlock(&pring->ring_lock); 9677 spin_unlock_irqrestore(&phba->hbalock, iflags); 9678 9679 /* Cancel all the IOCBs from the completions list */ 9680 lpfc_sli_cancel_iocbs(phba, &abort_list, 9681 IOSTAT_LOCAL_REJECT, IOERR_SLI_ABORTED); 9682 9683 return; 9684 } 9685 9686 /** 9687 * lpfc_els_flush_all_cmd - Clean up all the outstanding els commands to a HBA 9688 * @phba: pointer to lpfc hba data structure. 9689 * 9690 * This routine is used to clean up all the outstanding ELS commands on a 9691 * @phba. It first aborts the @phba by invoking the lpfc_fabric_abort_hba() 9692 * routine. After that, it walks the ELS transmit queue to remove all the 9693 * IOCBs to the @phba other than the QUE_RING and ABORT/CLOSE IOCBs. For 9694 * the IOCBs with the completion callback function associated, the callback 9695 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and 9696 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs without the completion 9697 * callback function associated, the IOCB will simply be released. Finally, 9698 * it walks the ELS transmit completion queue to issue an abort IOCB to any 9699 * transmit completion queue IOCB that is not an IOCB from libdfc (i.e., the 9700 * management plane IOCBs that are not part of the discovery state machine) 9701 * out to HBA by invoking the lpfc_sli_issue_abort_iotag() routine. 9702 **/ 9703 void 9704 lpfc_els_flush_all_cmd(struct lpfc_hba *phba) 9705 { 9706 struct lpfc_vport *vport; 9707 9708 spin_lock_irq(&phba->port_list_lock); 9709 list_for_each_entry(vport, &phba->port_list, listentry) 9710 lpfc_els_flush_cmd(vport); 9711 spin_unlock_irq(&phba->port_list_lock); 9712 9713 return; 9714 } 9715 9716 /** 9717 * lpfc_send_els_failure_event - Posts an ELS command failure event 9718 * @phba: Pointer to hba context object. 9719 * @cmdiocbp: Pointer to command iocb which reported error. 9720 * @rspiocbp: Pointer to response iocb which reported error. 9721 * 9722 * This function sends an event when there is an ELS command 9723 * failure. 9724 **/ 9725 void 9726 lpfc_send_els_failure_event(struct lpfc_hba *phba, 9727 struct lpfc_iocbq *cmdiocbp, 9728 struct lpfc_iocbq *rspiocbp) 9729 { 9730 struct lpfc_vport *vport = cmdiocbp->vport; 9731 struct Scsi_Host *shost = lpfc_shost_from_vport(vport); 9732 struct lpfc_lsrjt_event lsrjt_event; 9733 struct lpfc_fabric_event_header fabric_event; 9734 struct ls_rjt stat; 9735 struct lpfc_nodelist *ndlp; 9736 uint32_t *pcmd; 9737 u32 ulp_status, ulp_word4; 9738 9739 ndlp = cmdiocbp->ndlp; 9740 if (!ndlp) 9741 return; 9742 9743 ulp_status = get_job_ulpstatus(phba, rspiocbp); 9744 ulp_word4 = get_job_word4(phba, rspiocbp); 9745 9746 if (ulp_status == IOSTAT_LS_RJT) { 9747 lsrjt_event.header.event_type = FC_REG_ELS_EVENT; 9748 lsrjt_event.header.subcategory = LPFC_EVENT_LSRJT_RCV; 9749 memcpy(lsrjt_event.header.wwpn, &ndlp->nlp_portname, 9750 sizeof(struct lpfc_name)); 9751 memcpy(lsrjt_event.header.wwnn, &ndlp->nlp_nodename, 9752 sizeof(struct lpfc_name)); 9753 pcmd = (uint32_t *)cmdiocbp->cmd_dmabuf->virt; 9754 lsrjt_event.command = (pcmd != NULL) ? *pcmd : 0; 9755 stat.un.ls_rjt_error_be = cpu_to_be32(ulp_word4); 9756 lsrjt_event.reason_code = stat.un.b.lsRjtRsnCode; 9757 lsrjt_event.explanation = stat.un.b.lsRjtRsnCodeExp; 9758 fc_host_post_vendor_event(shost, 9759 fc_get_event_number(), 9760 sizeof(lsrjt_event), 9761 (char *)&lsrjt_event, 9762 LPFC_NL_VENDOR_ID); 9763 return; 9764 } 9765 if (ulp_status == IOSTAT_NPORT_BSY || 9766 ulp_status == IOSTAT_FABRIC_BSY) { 9767 fabric_event.event_type = FC_REG_FABRIC_EVENT; 9768 if (ulp_status == IOSTAT_NPORT_BSY) 9769 fabric_event.subcategory = LPFC_EVENT_PORT_BUSY; 9770 else 9771 fabric_event.subcategory = LPFC_EVENT_FABRIC_BUSY; 9772 memcpy(fabric_event.wwpn, &ndlp->nlp_portname, 9773 sizeof(struct lpfc_name)); 9774 memcpy(fabric_event.wwnn, &ndlp->nlp_nodename, 9775 sizeof(struct lpfc_name)); 9776 fc_host_post_vendor_event(shost, 9777 fc_get_event_number(), 9778 sizeof(fabric_event), 9779 (char *)&fabric_event, 9780 LPFC_NL_VENDOR_ID); 9781 return; 9782 } 9783 9784 } 9785 9786 /** 9787 * lpfc_send_els_event - Posts unsolicited els event 9788 * @vport: Pointer to vport object. 9789 * @ndlp: Pointer FC node object. 9790 * @payload: ELS command code type. 9791 * 9792 * This function posts an event when there is an incoming 9793 * unsolicited ELS command. 9794 **/ 9795 static void 9796 lpfc_send_els_event(struct lpfc_vport *vport, 9797 struct lpfc_nodelist *ndlp, 9798 uint32_t *payload) 9799 { 9800 struct lpfc_els_event_header *els_data = NULL; 9801 struct lpfc_logo_event *logo_data = NULL; 9802 struct Scsi_Host *shost = lpfc_shost_from_vport(vport); 9803 9804 if (*payload == ELS_CMD_LOGO) { 9805 logo_data = kmalloc(sizeof(struct lpfc_logo_event), GFP_KERNEL); 9806 if (!logo_data) { 9807 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, 9808 "0148 Failed to allocate memory " 9809 "for LOGO event\n"); 9810 return; 9811 } 9812 els_data = &logo_data->header; 9813 } else { 9814 els_data = kmalloc(sizeof(struct lpfc_els_event_header), 9815 GFP_KERNEL); 9816 if (!els_data) { 9817 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, 9818 "0149 Failed to allocate memory " 9819 "for ELS event\n"); 9820 return; 9821 } 9822 } 9823 els_data->event_type = FC_REG_ELS_EVENT; 9824 switch (*payload) { 9825 case ELS_CMD_PLOGI: 9826 els_data->subcategory = LPFC_EVENT_PLOGI_RCV; 9827 break; 9828 case ELS_CMD_PRLO: 9829 els_data->subcategory = LPFC_EVENT_PRLO_RCV; 9830 break; 9831 case ELS_CMD_ADISC: 9832 els_data->subcategory = LPFC_EVENT_ADISC_RCV; 9833 break; 9834 case ELS_CMD_LOGO: 9835 els_data->subcategory = LPFC_EVENT_LOGO_RCV; 9836 /* Copy the WWPN in the LOGO payload */ 9837 memcpy(logo_data->logo_wwpn, &payload[2], 9838 sizeof(struct lpfc_name)); 9839 break; 9840 default: 9841 kfree(els_data); 9842 return; 9843 } 9844 memcpy(els_data->wwpn, &ndlp->nlp_portname, sizeof(struct lpfc_name)); 9845 memcpy(els_data->wwnn, &ndlp->nlp_nodename, sizeof(struct lpfc_name)); 9846 if (*payload == ELS_CMD_LOGO) { 9847 fc_host_post_vendor_event(shost, 9848 fc_get_event_number(), 9849 sizeof(struct lpfc_logo_event), 9850 (char *)logo_data, 9851 LPFC_NL_VENDOR_ID); 9852 kfree(logo_data); 9853 } else { 9854 fc_host_post_vendor_event(shost, 9855 fc_get_event_number(), 9856 sizeof(struct lpfc_els_event_header), 9857 (char *)els_data, 9858 LPFC_NL_VENDOR_ID); 9859 kfree(els_data); 9860 } 9861 9862 return; 9863 } 9864 9865 9866 DECLARE_ENUM2STR_LOOKUP(lpfc_get_fpin_li_event_nm, fc_fpin_li_event_types, 9867 FC_FPIN_LI_EVT_TYPES_INIT); 9868 9869 DECLARE_ENUM2STR_LOOKUP(lpfc_get_fpin_deli_event_nm, fc_fpin_deli_event_types, 9870 FC_FPIN_DELI_EVT_TYPES_INIT); 9871 9872 DECLARE_ENUM2STR_LOOKUP(lpfc_get_fpin_congn_event_nm, fc_fpin_congn_event_types, 9873 FC_FPIN_CONGN_EVT_TYPES_INIT); 9874 9875 DECLARE_ENUM2STR_LOOKUP(lpfc_get_fpin_congn_severity_nm, 9876 fc_fpin_congn_severity_types, 9877 FC_FPIN_CONGN_SEVERITY_INIT); 9878 9879 9880 /** 9881 * lpfc_display_fpin_wwpn - Display WWPNs accessible by the attached port 9882 * @phba: Pointer to phba object. 9883 * @wwnlist: Pointer to list of WWPNs in FPIN payload 9884 * @cnt: count of WWPNs in FPIN payload 9885 * 9886 * This routine is called by LI and PC descriptors. 9887 * Limit the number of WWPNs displayed to 6 log messages, 6 per log message 9888 */ 9889 static void 9890 lpfc_display_fpin_wwpn(struct lpfc_hba *phba, __be64 *wwnlist, u32 cnt) 9891 { 9892 char buf[LPFC_FPIN_WWPN_LINE_SZ]; 9893 __be64 wwn; 9894 u64 wwpn; 9895 int i, len; 9896 int line = 0; 9897 int wcnt = 0; 9898 bool endit = false; 9899 9900 len = scnprintf(buf, LPFC_FPIN_WWPN_LINE_SZ, "Accessible WWPNs:"); 9901 for (i = 0; i < cnt; i++) { 9902 /* Are we on the last WWPN */ 9903 if (i == (cnt - 1)) 9904 endit = true; 9905 9906 /* Extract the next WWPN from the payload */ 9907 wwn = *wwnlist++; 9908 wwpn = be64_to_cpu(wwn); 9909 len += scnprintf(buf + len, LPFC_FPIN_WWPN_LINE_SZ - len, 9910 " %016llx", wwpn); 9911 9912 /* Log a message if we are on the last WWPN 9913 * or if we hit the max allowed per message. 9914 */ 9915 wcnt++; 9916 if (wcnt == LPFC_FPIN_WWPN_LINE_CNT || endit) { 9917 buf[len] = 0; 9918 lpfc_printf_log(phba, KERN_INFO, LOG_ELS, 9919 "4686 %s\n", buf); 9920 9921 /* Check if we reached the last WWPN */ 9922 if (endit) 9923 return; 9924 9925 /* Limit the number of log message displayed per FPIN */ 9926 line++; 9927 if (line == LPFC_FPIN_WWPN_NUM_LINE) { 9928 lpfc_printf_log(phba, KERN_INFO, LOG_ELS, 9929 "4687 %d WWPNs Truncated\n", 9930 cnt - i - 1); 9931 return; 9932 } 9933 9934 /* Start over with next log message */ 9935 wcnt = 0; 9936 len = scnprintf(buf, LPFC_FPIN_WWPN_LINE_SZ, 9937 "Additional WWPNs:"); 9938 } 9939 } 9940 } 9941 9942 /** 9943 * lpfc_els_rcv_fpin_li - Process an FPIN Link Integrity Event. 9944 * @phba: Pointer to phba object. 9945 * @tlv: Pointer to the Link Integrity Notification Descriptor. 9946 * 9947 * This function processes a Link Integrity FPIN event by logging a message. 9948 **/ 9949 static void 9950 lpfc_els_rcv_fpin_li(struct lpfc_hba *phba, struct fc_tlv_desc *tlv) 9951 { 9952 struct fc_fn_li_desc *li = (struct fc_fn_li_desc *)tlv; 9953 const char *li_evt_str; 9954 u32 li_evt, cnt; 9955 9956 li_evt = be16_to_cpu(li->event_type); 9957 li_evt_str = lpfc_get_fpin_li_event_nm(li_evt); 9958 cnt = be32_to_cpu(li->pname_count); 9959 9960 lpfc_printf_log(phba, KERN_INFO, LOG_ELS, 9961 "4680 FPIN Link Integrity %s (x%x) " 9962 "Detecting PN x%016llx Attached PN x%016llx " 9963 "Duration %d mSecs Count %d Port Cnt %d\n", 9964 li_evt_str, li_evt, 9965 be64_to_cpu(li->detecting_wwpn), 9966 be64_to_cpu(li->attached_wwpn), 9967 be32_to_cpu(li->event_threshold), 9968 be32_to_cpu(li->event_count), cnt); 9969 9970 lpfc_display_fpin_wwpn(phba, (__be64 *)&li->pname_list, cnt); 9971 } 9972 9973 /** 9974 * lpfc_els_rcv_fpin_del - Process an FPIN Delivery Event. 9975 * @phba: Pointer to hba object. 9976 * @tlv: Pointer to the Delivery Notification Descriptor TLV 9977 * 9978 * This function processes a Delivery FPIN event by logging a message. 9979 **/ 9980 static void 9981 lpfc_els_rcv_fpin_del(struct lpfc_hba *phba, struct fc_tlv_desc *tlv) 9982 { 9983 struct fc_fn_deli_desc *del = (struct fc_fn_deli_desc *)tlv; 9984 const char *del_rsn_str; 9985 u32 del_rsn; 9986 __be32 *frame; 9987 9988 del_rsn = be16_to_cpu(del->deli_reason_code); 9989 del_rsn_str = lpfc_get_fpin_deli_event_nm(del_rsn); 9990 9991 /* Skip over desc_tag/desc_len header to payload */ 9992 frame = (__be32 *)(del + 1); 9993 9994 lpfc_printf_log(phba, KERN_INFO, LOG_ELS, 9995 "4681 FPIN Delivery %s (x%x) " 9996 "Detecting PN x%016llx Attached PN x%016llx " 9997 "DiscHdr0 x%08x " 9998 "DiscHdr1 x%08x DiscHdr2 x%08x DiscHdr3 x%08x " 9999 "DiscHdr4 x%08x DiscHdr5 x%08x\n", 10000 del_rsn_str, del_rsn, 10001 be64_to_cpu(del->detecting_wwpn), 10002 be64_to_cpu(del->attached_wwpn), 10003 be32_to_cpu(frame[0]), 10004 be32_to_cpu(frame[1]), 10005 be32_to_cpu(frame[2]), 10006 be32_to_cpu(frame[3]), 10007 be32_to_cpu(frame[4]), 10008 be32_to_cpu(frame[5])); 10009 } 10010 10011 /** 10012 * lpfc_els_rcv_fpin_peer_cgn - Process a FPIN Peer Congestion Event. 10013 * @phba: Pointer to hba object. 10014 * @tlv: Pointer to the Peer Congestion Notification Descriptor TLV 10015 * 10016 * This function processes a Peer Congestion FPIN event by logging a message. 10017 **/ 10018 static void 10019 lpfc_els_rcv_fpin_peer_cgn(struct lpfc_hba *phba, struct fc_tlv_desc *tlv) 10020 { 10021 struct fc_fn_peer_congn_desc *pc = (struct fc_fn_peer_congn_desc *)tlv; 10022 const char *pc_evt_str; 10023 u32 pc_evt, cnt; 10024 10025 pc_evt = be16_to_cpu(pc->event_type); 10026 pc_evt_str = lpfc_get_fpin_congn_event_nm(pc_evt); 10027 cnt = be32_to_cpu(pc->pname_count); 10028 10029 /* Capture FPIN frequency */ 10030 phba->cgn_fpin_frequency = be32_to_cpu(pc->event_period); 10031 10032 lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT | LOG_ELS, 10033 "4684 FPIN Peer Congestion %s (x%x) " 10034 "Duration %d mSecs " 10035 "Detecting PN x%016llx Attached PN x%016llx " 10036 "Impacted Port Cnt %d\n", 10037 pc_evt_str, pc_evt, 10038 be32_to_cpu(pc->event_period), 10039 be64_to_cpu(pc->detecting_wwpn), 10040 be64_to_cpu(pc->attached_wwpn), 10041 cnt); 10042 10043 lpfc_display_fpin_wwpn(phba, (__be64 *)&pc->pname_list, cnt); 10044 } 10045 10046 /** 10047 * lpfc_els_rcv_fpin_cgn - Process an FPIN Congestion notification 10048 * @phba: Pointer to hba object. 10049 * @tlv: Pointer to the Congestion Notification Descriptor TLV 10050 * 10051 * This function processes an FPIN Congestion Notifiction. The notification 10052 * could be an Alarm or Warning. This routine feeds that data into driver's 10053 * running congestion algorithm. It also processes the FPIN by 10054 * logging a message. It returns 1 to indicate deliver this message 10055 * to the upper layer or 0 to indicate don't deliver it. 10056 **/ 10057 static int 10058 lpfc_els_rcv_fpin_cgn(struct lpfc_hba *phba, struct fc_tlv_desc *tlv) 10059 { 10060 struct lpfc_cgn_info *cp; 10061 struct fc_fn_congn_desc *cgn = (struct fc_fn_congn_desc *)tlv; 10062 const char *cgn_evt_str; 10063 u32 cgn_evt; 10064 const char *cgn_sev_str; 10065 u32 cgn_sev; 10066 uint16_t value; 10067 u32 crc; 10068 bool nm_log = false; 10069 int rc = 1; 10070 10071 cgn_evt = be16_to_cpu(cgn->event_type); 10072 cgn_evt_str = lpfc_get_fpin_congn_event_nm(cgn_evt); 10073 cgn_sev = cgn->severity; 10074 cgn_sev_str = lpfc_get_fpin_congn_severity_nm(cgn_sev); 10075 10076 /* The driver only takes action on a Credit Stall or Oversubscription 10077 * event type to engage the IO algorithm. The driver prints an 10078 * unmaskable message only for Lost Credit and Credit Stall. 10079 * TODO: Still need to have definition of host action on clear, 10080 * lost credit and device specific event types. 10081 */ 10082 switch (cgn_evt) { 10083 case FPIN_CONGN_LOST_CREDIT: 10084 nm_log = true; 10085 break; 10086 case FPIN_CONGN_CREDIT_STALL: 10087 nm_log = true; 10088 fallthrough; 10089 case FPIN_CONGN_OVERSUBSCRIPTION: 10090 if (cgn_evt == FPIN_CONGN_OVERSUBSCRIPTION) 10091 nm_log = false; 10092 switch (cgn_sev) { 10093 case FPIN_CONGN_SEVERITY_ERROR: 10094 /* Take action here for an Alarm event */ 10095 if (phba->cmf_active_mode != LPFC_CFG_OFF) { 10096 if (phba->cgn_reg_fpin & LPFC_CGN_FPIN_ALARM) { 10097 /* Track of alarm cnt for SYNC_WQE */ 10098 atomic_inc(&phba->cgn_sync_alarm_cnt); 10099 } 10100 /* Track alarm cnt for cgn_info regardless 10101 * of whether CMF is configured for Signals 10102 * or FPINs. 10103 */ 10104 atomic_inc(&phba->cgn_fabric_alarm_cnt); 10105 goto cleanup; 10106 } 10107 break; 10108 case FPIN_CONGN_SEVERITY_WARNING: 10109 /* Take action here for a Warning event */ 10110 if (phba->cmf_active_mode != LPFC_CFG_OFF) { 10111 if (phba->cgn_reg_fpin & LPFC_CGN_FPIN_WARN) { 10112 /* Track of warning cnt for SYNC_WQE */ 10113 atomic_inc(&phba->cgn_sync_warn_cnt); 10114 } 10115 /* Track warning cnt and freq for cgn_info 10116 * regardless of whether CMF is configured for 10117 * Signals or FPINs. 10118 */ 10119 atomic_inc(&phba->cgn_fabric_warn_cnt); 10120 cleanup: 10121 /* Save frequency in ms */ 10122 phba->cgn_fpin_frequency = 10123 be32_to_cpu(cgn->event_period); 10124 value = phba->cgn_fpin_frequency; 10125 if (phba->cgn_i) { 10126 cp = (struct lpfc_cgn_info *) 10127 phba->cgn_i->virt; 10128 cp->cgn_alarm_freq = 10129 cpu_to_le16(value); 10130 cp->cgn_warn_freq = 10131 cpu_to_le16(value); 10132 crc = lpfc_cgn_calc_crc32 10133 (cp, 10134 LPFC_CGN_INFO_SZ, 10135 LPFC_CGN_CRC32_SEED); 10136 cp->cgn_info_crc = cpu_to_le32(crc); 10137 } 10138 10139 /* Don't deliver to upper layer since 10140 * driver took action on this tlv. 10141 */ 10142 rc = 0; 10143 } 10144 break; 10145 } 10146 break; 10147 } 10148 10149 /* Change the log level to unmaskable for the following event types. */ 10150 lpfc_printf_log(phba, (nm_log ? KERN_WARNING : KERN_INFO), 10151 LOG_CGN_MGMT | LOG_ELS, 10152 "4683 FPIN CONGESTION %s type %s (x%x) Event " 10153 "Duration %d mSecs\n", 10154 cgn_sev_str, cgn_evt_str, cgn_evt, 10155 be32_to_cpu(cgn->event_period)); 10156 return rc; 10157 } 10158 10159 void 10160 lpfc_els_rcv_fpin(struct lpfc_vport *vport, void *p, u32 fpin_length) 10161 { 10162 struct lpfc_hba *phba = vport->phba; 10163 struct fc_els_fpin *fpin = (struct fc_els_fpin *)p; 10164 struct fc_tlv_desc *tlv, *first_tlv, *current_tlv; 10165 const char *dtag_nm; 10166 int desc_cnt = 0, bytes_remain, cnt; 10167 u32 dtag, deliver = 0; 10168 int len; 10169 10170 /* FPINs handled only if we are in the right discovery state */ 10171 if (vport->port_state < LPFC_DISC_AUTH) 10172 return; 10173 10174 /* make sure there is the full fpin header */ 10175 if (fpin_length < sizeof(struct fc_els_fpin)) 10176 return; 10177 10178 /* Sanity check descriptor length. The desc_len value does not 10179 * include space for the ELS command and the desc_len fields. 10180 */ 10181 len = be32_to_cpu(fpin->desc_len); 10182 if (fpin_length < len + sizeof(struct fc_els_fpin)) { 10183 lpfc_printf_log(phba, KERN_WARNING, LOG_CGN_MGMT, 10184 "4671 Bad ELS FPIN length %d: %d\n", 10185 len, fpin_length); 10186 return; 10187 } 10188 10189 tlv = (struct fc_tlv_desc *)&fpin->fpin_desc[0]; 10190 first_tlv = tlv; 10191 bytes_remain = fpin_length - offsetof(struct fc_els_fpin, fpin_desc); 10192 bytes_remain = min_t(u32, bytes_remain, be32_to_cpu(fpin->desc_len)); 10193 10194 /* process each descriptor separately */ 10195 while (bytes_remain >= FC_TLV_DESC_HDR_SZ && 10196 bytes_remain >= FC_TLV_DESC_SZ_FROM_LENGTH(tlv)) { 10197 dtag = be32_to_cpu(tlv->desc_tag); 10198 switch (dtag) { 10199 case ELS_DTAG_LNK_INTEGRITY: 10200 lpfc_els_rcv_fpin_li(phba, tlv); 10201 deliver = 1; 10202 break; 10203 case ELS_DTAG_DELIVERY: 10204 lpfc_els_rcv_fpin_del(phba, tlv); 10205 deliver = 1; 10206 break; 10207 case ELS_DTAG_PEER_CONGEST: 10208 lpfc_els_rcv_fpin_peer_cgn(phba, tlv); 10209 deliver = 1; 10210 break; 10211 case ELS_DTAG_CONGESTION: 10212 deliver = lpfc_els_rcv_fpin_cgn(phba, tlv); 10213 break; 10214 default: 10215 dtag_nm = lpfc_get_tlv_dtag_nm(dtag); 10216 lpfc_printf_log(phba, KERN_WARNING, LOG_CGN_MGMT, 10217 "4678 unknown FPIN descriptor[%d]: " 10218 "tag x%x (%s)\n", 10219 desc_cnt, dtag, dtag_nm); 10220 10221 /* If descriptor is bad, drop the rest of the data */ 10222 return; 10223 } 10224 lpfc_cgn_update_stat(phba, dtag); 10225 cnt = be32_to_cpu(tlv->desc_len); 10226 10227 /* Sanity check descriptor length. The desc_len value does not 10228 * include space for the desc_tag and the desc_len fields. 10229 */ 10230 len -= (cnt + sizeof(struct fc_tlv_desc)); 10231 if (len < 0) { 10232 dtag_nm = lpfc_get_tlv_dtag_nm(dtag); 10233 lpfc_printf_log(phba, KERN_WARNING, LOG_CGN_MGMT, 10234 "4672 Bad FPIN descriptor TLV length " 10235 "%d: %d %d %s\n", 10236 cnt, len, fpin_length, dtag_nm); 10237 return; 10238 } 10239 10240 current_tlv = tlv; 10241 bytes_remain -= FC_TLV_DESC_SZ_FROM_LENGTH(tlv); 10242 tlv = fc_tlv_next_desc(tlv); 10243 10244 /* Format payload such that the FPIN delivered to the 10245 * upper layer is a single descriptor FPIN. 10246 */ 10247 if (desc_cnt) 10248 memcpy(first_tlv, current_tlv, 10249 (cnt + sizeof(struct fc_els_fpin))); 10250 10251 /* Adjust the length so that it only reflects a 10252 * single descriptor FPIN. 10253 */ 10254 fpin_length = cnt + sizeof(struct fc_els_fpin); 10255 fpin->desc_len = cpu_to_be32(fpin_length); 10256 fpin_length += sizeof(struct fc_els_fpin); /* the entire FPIN */ 10257 10258 /* Send every descriptor individually to the upper layer */ 10259 if (deliver) 10260 fc_host_fpin_rcv(lpfc_shost_from_vport(vport), 10261 fpin_length, (char *)fpin, 0); 10262 desc_cnt++; 10263 } 10264 } 10265 10266 /** 10267 * lpfc_els_unsol_buffer - Process an unsolicited event data buffer 10268 * @phba: pointer to lpfc hba data structure. 10269 * @pring: pointer to a SLI ring. 10270 * @vport: pointer to a host virtual N_Port data structure. 10271 * @elsiocb: pointer to lpfc els command iocb data structure. 10272 * 10273 * This routine is used for processing the IOCB associated with a unsolicited 10274 * event. It first determines whether there is an existing ndlp that matches 10275 * the DID from the unsolicited IOCB. If not, it will create a new one with 10276 * the DID from the unsolicited IOCB. The ELS command from the unsolicited 10277 * IOCB is then used to invoke the proper routine and to set up proper state 10278 * of the discovery state machine. 10279 **/ 10280 static void 10281 lpfc_els_unsol_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, 10282 struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb) 10283 { 10284 struct lpfc_nodelist *ndlp; 10285 struct ls_rjt stat; 10286 u32 *payload, payload_len; 10287 u32 cmd = 0, did = 0, newnode, status = 0; 10288 uint8_t rjt_exp, rjt_err = 0, init_link = 0; 10289 struct lpfc_wcqe_complete *wcqe_cmpl = NULL; 10290 LPFC_MBOXQ_t *mbox; 10291 10292 if (!vport || !elsiocb->cmd_dmabuf) 10293 goto dropit; 10294 10295 newnode = 0; 10296 wcqe_cmpl = &elsiocb->wcqe_cmpl; 10297 payload = elsiocb->cmd_dmabuf->virt; 10298 if (phba->sli_rev == LPFC_SLI_REV4) 10299 payload_len = wcqe_cmpl->total_data_placed; 10300 else 10301 payload_len = elsiocb->iocb.unsli3.rcvsli3.acc_len; 10302 status = get_job_ulpstatus(phba, elsiocb); 10303 cmd = *payload; 10304 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0) 10305 lpfc_sli3_post_buffer(phba, pring, 1); 10306 10307 did = get_job_els_rsp64_did(phba, elsiocb); 10308 if (status) { 10309 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, 10310 "RCV Unsol ELS: status:x%x/x%x did:x%x", 10311 status, get_job_word4(phba, elsiocb), did); 10312 goto dropit; 10313 } 10314 10315 /* Check to see if link went down during discovery */ 10316 if (lpfc_els_chk_latt(vport)) 10317 goto dropit; 10318 10319 /* Ignore traffic received during vport shutdown. */ 10320 if (test_bit(FC_UNLOADING, &vport->load_flag)) 10321 goto dropit; 10322 10323 /* If NPort discovery is delayed drop incoming ELS */ 10324 if (test_bit(FC_DISC_DELAYED, &vport->fc_flag) && 10325 cmd != ELS_CMD_PLOGI) 10326 goto dropit; 10327 10328 ndlp = lpfc_findnode_did(vport, did); 10329 if (!ndlp) { 10330 /* Cannot find existing Fabric ndlp, so allocate a new one */ 10331 ndlp = lpfc_nlp_init(vport, did); 10332 if (!ndlp) 10333 goto dropit; 10334 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); 10335 newnode = 1; 10336 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) 10337 ndlp->nlp_type |= NLP_FABRIC; 10338 } else if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) { 10339 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); 10340 newnode = 1; 10341 } 10342 10343 phba->fc_stat.elsRcvFrame++; 10344 10345 /* 10346 * Do not process any unsolicited ELS commands 10347 * if the ndlp is in DEV_LOSS 10348 */ 10349 if (test_bit(NLP_IN_DEV_LOSS, &ndlp->nlp_flag)) { 10350 if (newnode) 10351 lpfc_nlp_put(ndlp); 10352 goto dropit; 10353 } 10354 10355 elsiocb->ndlp = lpfc_nlp_get(ndlp); 10356 if (!elsiocb->ndlp) 10357 goto dropit; 10358 elsiocb->vport = vport; 10359 10360 if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) { 10361 cmd &= ELS_CMD_MASK; 10362 } 10363 /* ELS command <elsCmd> received from NPORT <did> */ 10364 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, 10365 "0112 ELS command x%x received from NPORT x%x " 10366 "refcnt %d Data: x%x x%lx x%x x%x\n", 10367 cmd, did, kref_read(&ndlp->kref), vport->port_state, 10368 vport->fc_flag, vport->fc_myDID, vport->fc_prevDID); 10369 10370 /* reject till our FLOGI completes or PLOGI assigned DID via PT2PT */ 10371 if ((vport->port_state < LPFC_FABRIC_CFG_LINK) && 10372 (cmd != ELS_CMD_FLOGI) && 10373 !((cmd == ELS_CMD_PLOGI) && test_bit(FC_PT2PT, &vport->fc_flag))) { 10374 rjt_err = LSRJT_LOGICAL_BSY; 10375 rjt_exp = LSEXP_NOTHING_MORE; 10376 goto lsrjt; 10377 } 10378 10379 switch (cmd) { 10380 case ELS_CMD_PLOGI: 10381 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, 10382 "RCV PLOGI: did:x%x/ste:x%x flg:x%lx", 10383 did, vport->port_state, ndlp->nlp_flag); 10384 10385 phba->fc_stat.elsRcvPLOGI++; 10386 ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp); 10387 if (phba->sli_rev == LPFC_SLI_REV4 && 10388 test_bit(FC_PT2PT, &phba->pport->fc_flag)) { 10389 vport->fc_prevDID = vport->fc_myDID; 10390 /* Our DID needs to be updated before registering 10391 * the vfi. This is done in lpfc_rcv_plogi but 10392 * that is called after the reg_vfi. 10393 */ 10394 vport->fc_myDID = 10395 bf_get(els_rsp64_sid, 10396 &elsiocb->wqe.xmit_els_rsp); 10397 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, 10398 "3312 Remote port assigned DID x%x " 10399 "%x\n", vport->fc_myDID, 10400 vport->fc_prevDID); 10401 } 10402 10403 lpfc_send_els_event(vport, ndlp, payload); 10404 10405 /* If Nport discovery is delayed, reject PLOGIs */ 10406 if (test_bit(FC_DISC_DELAYED, &vport->fc_flag)) { 10407 rjt_err = LSRJT_UNABLE_TPC; 10408 rjt_exp = LSEXP_NOTHING_MORE; 10409 break; 10410 } 10411 10412 if (vport->port_state < LPFC_DISC_AUTH) { 10413 if (!test_bit(FC_PT2PT, &phba->pport->fc_flag) || 10414 test_bit(FC_PT2PT_PLOGI, &phba->pport->fc_flag)) { 10415 rjt_err = LSRJT_UNABLE_TPC; 10416 rjt_exp = LSEXP_NOTHING_MORE; 10417 break; 10418 } 10419 } 10420 10421 lpfc_disc_state_machine(vport, ndlp, elsiocb, 10422 NLP_EVT_RCV_PLOGI); 10423 10424 break; 10425 case ELS_CMD_FLOGI: 10426 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, 10427 "RCV FLOGI: did:x%x/ste:x%x flg:x%lx", 10428 did, vport->port_state, ndlp->nlp_flag); 10429 10430 phba->fc_stat.elsRcvFLOGI++; 10431 10432 /* If the driver believes fabric discovery is done and is ready, 10433 * bounce the link. There is some descrepancy. 10434 */ 10435 if (vport->port_state >= LPFC_LOCAL_CFG_LINK && 10436 test_bit(FC_PT2PT, &vport->fc_flag) && 10437 vport->rcv_flogi_cnt >= 1) { 10438 rjt_err = LSRJT_LOGICAL_BSY; 10439 rjt_exp = LSEXP_NOTHING_MORE; 10440 init_link++; 10441 goto lsrjt; 10442 } 10443 10444 lpfc_els_rcv_flogi(vport, elsiocb, ndlp); 10445 /* retain node if our response is deferred */ 10446 if (phba->defer_flogi_acc.flag) 10447 break; 10448 if (newnode) 10449 lpfc_disc_state_machine(vport, ndlp, NULL, 10450 NLP_EVT_DEVICE_RM); 10451 break; 10452 case ELS_CMD_LOGO: 10453 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, 10454 "RCV LOGO: did:x%x/ste:x%x flg:x%lx", 10455 did, vport->port_state, ndlp->nlp_flag); 10456 10457 phba->fc_stat.elsRcvLOGO++; 10458 lpfc_send_els_event(vport, ndlp, payload); 10459 if (vport->port_state < LPFC_DISC_AUTH) { 10460 rjt_err = LSRJT_UNABLE_TPC; 10461 rjt_exp = LSEXP_NOTHING_MORE; 10462 break; 10463 } 10464 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO); 10465 if (newnode) 10466 lpfc_disc_state_machine(vport, ndlp, NULL, 10467 NLP_EVT_DEVICE_RM); 10468 break; 10469 case ELS_CMD_PRLO: 10470 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, 10471 "RCV PRLO: did:x%x/ste:x%x flg:x%lx", 10472 did, vport->port_state, ndlp->nlp_flag); 10473 10474 phba->fc_stat.elsRcvPRLO++; 10475 lpfc_send_els_event(vport, ndlp, payload); 10476 if (vport->port_state < LPFC_DISC_AUTH) { 10477 rjt_err = LSRJT_UNABLE_TPC; 10478 rjt_exp = LSEXP_NOTHING_MORE; 10479 break; 10480 } 10481 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO); 10482 break; 10483 case ELS_CMD_LCB: 10484 phba->fc_stat.elsRcvLCB++; 10485 lpfc_els_rcv_lcb(vport, elsiocb, ndlp); 10486 break; 10487 case ELS_CMD_RDP: 10488 phba->fc_stat.elsRcvRDP++; 10489 lpfc_els_rcv_rdp(vport, elsiocb, ndlp); 10490 break; 10491 case ELS_CMD_RSCN: 10492 phba->fc_stat.elsRcvRSCN++; 10493 lpfc_els_rcv_rscn(vport, elsiocb, ndlp); 10494 if (newnode) 10495 lpfc_disc_state_machine(vport, ndlp, NULL, 10496 NLP_EVT_DEVICE_RM); 10497 break; 10498 case ELS_CMD_ADISC: 10499 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, 10500 "RCV ADISC: did:x%x/ste:x%x flg:x%lx", 10501 did, vport->port_state, ndlp->nlp_flag); 10502 10503 lpfc_send_els_event(vport, ndlp, payload); 10504 phba->fc_stat.elsRcvADISC++; 10505 if (vport->port_state < LPFC_DISC_AUTH) { 10506 rjt_err = LSRJT_UNABLE_TPC; 10507 rjt_exp = LSEXP_NOTHING_MORE; 10508 break; 10509 } 10510 lpfc_disc_state_machine(vport, ndlp, elsiocb, 10511 NLP_EVT_RCV_ADISC); 10512 break; 10513 case ELS_CMD_PDISC: 10514 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, 10515 "RCV PDISC: did:x%x/ste:x%x flg:x%lx", 10516 did, vport->port_state, ndlp->nlp_flag); 10517 10518 phba->fc_stat.elsRcvPDISC++; 10519 if (vport->port_state < LPFC_DISC_AUTH) { 10520 rjt_err = LSRJT_UNABLE_TPC; 10521 rjt_exp = LSEXP_NOTHING_MORE; 10522 break; 10523 } 10524 lpfc_disc_state_machine(vport, ndlp, elsiocb, 10525 NLP_EVT_RCV_PDISC); 10526 break; 10527 case ELS_CMD_FARPR: 10528 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, 10529 "RCV FARPR: did:x%x/ste:x%x flg:x%lx", 10530 did, vport->port_state, ndlp->nlp_flag); 10531 10532 phba->fc_stat.elsRcvFARPR++; 10533 lpfc_els_rcv_farpr(vport, elsiocb, ndlp); 10534 break; 10535 case ELS_CMD_FARP: 10536 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, 10537 "RCV FARP: did:x%x/ste:x%x flg:x%lx", 10538 did, vport->port_state, ndlp->nlp_flag); 10539 10540 phba->fc_stat.elsRcvFARP++; 10541 lpfc_els_rcv_farp(vport, elsiocb, ndlp); 10542 break; 10543 case ELS_CMD_FAN: 10544 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, 10545 "RCV FAN: did:x%x/ste:x%x flg:x%lx", 10546 did, vport->port_state, ndlp->nlp_flag); 10547 10548 phba->fc_stat.elsRcvFAN++; 10549 lpfc_els_rcv_fan(vport, elsiocb, ndlp); 10550 break; 10551 case ELS_CMD_PRLI: 10552 case ELS_CMD_NVMEPRLI: 10553 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, 10554 "RCV PRLI: did:x%x/ste:x%x flg:x%lx", 10555 did, vport->port_state, ndlp->nlp_flag); 10556 10557 phba->fc_stat.elsRcvPRLI++; 10558 if ((vport->port_state < LPFC_DISC_AUTH) && 10559 test_bit(FC_FABRIC, &vport->fc_flag)) { 10560 rjt_err = LSRJT_UNABLE_TPC; 10561 rjt_exp = LSEXP_NOTHING_MORE; 10562 break; 10563 } 10564 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI); 10565 break; 10566 case ELS_CMD_LIRR: 10567 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, 10568 "RCV LIRR: did:x%x/ste:x%x flg:x%lx", 10569 did, vport->port_state, ndlp->nlp_flag); 10570 10571 phba->fc_stat.elsRcvLIRR++; 10572 lpfc_els_rcv_lirr(vport, elsiocb, ndlp); 10573 if (newnode) 10574 lpfc_disc_state_machine(vport, ndlp, NULL, 10575 NLP_EVT_DEVICE_RM); 10576 break; 10577 case ELS_CMD_RLS: 10578 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, 10579 "RCV RLS: did:x%x/ste:x%x flg:x%lx", 10580 did, vport->port_state, ndlp->nlp_flag); 10581 10582 phba->fc_stat.elsRcvRLS++; 10583 lpfc_els_rcv_rls(vport, elsiocb, ndlp); 10584 if (newnode) 10585 lpfc_disc_state_machine(vport, ndlp, NULL, 10586 NLP_EVT_DEVICE_RM); 10587 break; 10588 case ELS_CMD_RPL: 10589 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, 10590 "RCV RPL: did:x%x/ste:x%x flg:x%lx", 10591 did, vport->port_state, ndlp->nlp_flag); 10592 10593 phba->fc_stat.elsRcvRPL++; 10594 lpfc_els_rcv_rpl(vport, elsiocb, ndlp); 10595 if (newnode) 10596 lpfc_disc_state_machine(vport, ndlp, NULL, 10597 NLP_EVT_DEVICE_RM); 10598 break; 10599 case ELS_CMD_RNID: 10600 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, 10601 "RCV RNID: did:x%x/ste:x%x flg:x%lx", 10602 did, vport->port_state, ndlp->nlp_flag); 10603 10604 phba->fc_stat.elsRcvRNID++; 10605 lpfc_els_rcv_rnid(vport, elsiocb, ndlp); 10606 if (newnode) 10607 lpfc_disc_state_machine(vport, ndlp, NULL, 10608 NLP_EVT_DEVICE_RM); 10609 break; 10610 case ELS_CMD_RTV: 10611 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, 10612 "RCV RTV: did:x%x/ste:x%x flg:x%lx", 10613 did, vport->port_state, ndlp->nlp_flag); 10614 phba->fc_stat.elsRcvRTV++; 10615 lpfc_els_rcv_rtv(vport, elsiocb, ndlp); 10616 if (newnode) 10617 lpfc_disc_state_machine(vport, ndlp, NULL, 10618 NLP_EVT_DEVICE_RM); 10619 break; 10620 case ELS_CMD_RRQ: 10621 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, 10622 "RCV RRQ: did:x%x/ste:x%x flg:x%lx", 10623 did, vport->port_state, ndlp->nlp_flag); 10624 10625 phba->fc_stat.elsRcvRRQ++; 10626 lpfc_els_rcv_rrq(vport, elsiocb, ndlp); 10627 if (newnode) 10628 lpfc_disc_state_machine(vport, ndlp, NULL, 10629 NLP_EVT_DEVICE_RM); 10630 break; 10631 case ELS_CMD_ECHO: 10632 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, 10633 "RCV ECHO: did:x%x/ste:x%x flg:x%lx", 10634 did, vport->port_state, ndlp->nlp_flag); 10635 10636 phba->fc_stat.elsRcvECHO++; 10637 lpfc_els_rcv_echo(vport, elsiocb, ndlp); 10638 if (newnode) 10639 lpfc_disc_state_machine(vport, ndlp, NULL, 10640 NLP_EVT_DEVICE_RM); 10641 break; 10642 case ELS_CMD_REC: 10643 /* receive this due to exchange closed */ 10644 rjt_err = LSRJT_UNABLE_TPC; 10645 rjt_exp = LSEXP_INVALID_OX_RX; 10646 break; 10647 case ELS_CMD_FPIN: 10648 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, 10649 "RCV FPIN: did:x%x/ste:x%x " 10650 "flg:x%lx", 10651 did, vport->port_state, ndlp->nlp_flag); 10652 10653 lpfc_els_rcv_fpin(vport, (struct fc_els_fpin *)payload, 10654 payload_len); 10655 10656 /* There are no replies, so no rjt codes */ 10657 break; 10658 case ELS_CMD_EDC: 10659 lpfc_els_rcv_edc(vport, elsiocb, ndlp); 10660 break; 10661 case ELS_CMD_RDF: 10662 phba->fc_stat.elsRcvRDF++; 10663 /* Accept RDF only from fabric controller */ 10664 if (did != Fabric_Cntl_DID) { 10665 lpfc_printf_vlog(vport, KERN_WARNING, LOG_ELS, 10666 "1115 Received RDF from invalid DID " 10667 "x%x\n", did); 10668 rjt_err = LSRJT_PROTOCOL_ERR; 10669 rjt_exp = LSEXP_NOTHING_MORE; 10670 goto lsrjt; 10671 } 10672 10673 lpfc_els_rcv_rdf(vport, elsiocb, ndlp); 10674 break; 10675 default: 10676 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, 10677 "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x", 10678 cmd, did, vport->port_state); 10679 10680 /* Unsupported ELS command, reject */ 10681 rjt_err = LSRJT_CMD_UNSUPPORTED; 10682 rjt_exp = LSEXP_NOTHING_MORE; 10683 10684 /* Unknown ELS command <elsCmd> received from NPORT <did> */ 10685 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, 10686 "0115 Unknown ELS command x%x " 10687 "received from NPORT x%x\n", cmd, did); 10688 if (newnode) 10689 lpfc_disc_state_machine(vport, ndlp, NULL, 10690 NLP_EVT_DEVICE_RM); 10691 break; 10692 } 10693 10694 lsrjt: 10695 /* check if need to LS_RJT received ELS cmd */ 10696 if (rjt_err) { 10697 memset(&stat, 0, sizeof(stat)); 10698 stat.un.b.lsRjtRsnCode = rjt_err; 10699 stat.un.b.lsRjtRsnCodeExp = rjt_exp; 10700 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp, 10701 NULL); 10702 /* Remove the reference from above for new nodes. */ 10703 if (newnode) 10704 lpfc_disc_state_machine(vport, ndlp, NULL, 10705 NLP_EVT_DEVICE_RM); 10706 } 10707 10708 /* Release the reference on this elsiocb, not the ndlp. */ 10709 lpfc_nlp_put(elsiocb->ndlp); 10710 elsiocb->ndlp = NULL; 10711 10712 /* Special case. Driver received an unsolicited command that 10713 * unsupportable given the driver's current state. Reset the 10714 * link and start over. 10715 */ 10716 if (init_link) { 10717 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); 10718 if (!mbox) 10719 return; 10720 lpfc_linkdown(phba); 10721 lpfc_init_link(phba, mbox, 10722 phba->cfg_topology, 10723 phba->cfg_link_speed); 10724 mbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0; 10725 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; 10726 mbox->vport = vport; 10727 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) == 10728 MBX_NOT_FINISHED) 10729 mempool_free(mbox, phba->mbox_mem_pool); 10730 } 10731 10732 return; 10733 10734 dropit: 10735 if (vport && !test_bit(FC_UNLOADING, &vport->load_flag)) 10736 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, 10737 "0111 Dropping received ELS cmd " 10738 "Data: x%x x%x x%x x%x\n", 10739 cmd, status, get_job_word4(phba, elsiocb), did); 10740 10741 phba->fc_stat.elsRcvDrop++; 10742 } 10743 10744 /** 10745 * lpfc_els_unsol_event - Process an unsolicited event from an els sli ring 10746 * @phba: pointer to lpfc hba data structure. 10747 * @pring: pointer to a SLI ring. 10748 * @elsiocb: pointer to lpfc els iocb data structure. 10749 * 10750 * This routine is used to process an unsolicited event received from a SLI 10751 * (Service Level Interface) ring. The actual processing of the data buffer 10752 * associated with the unsolicited event is done by invoking the routine 10753 * lpfc_els_unsol_buffer() after properly set up the iocb buffer from the 10754 * SLI ring on which the unsolicited event was received. 10755 **/ 10756 void 10757 lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, 10758 struct lpfc_iocbq *elsiocb) 10759 { 10760 struct lpfc_vport *vport = elsiocb->vport; 10761 u32 ulp_command, status, parameter, bde_count = 0; 10762 IOCB_t *icmd; 10763 struct lpfc_wcqe_complete *wcqe_cmpl = NULL; 10764 struct lpfc_dmabuf *bdeBuf1 = elsiocb->cmd_dmabuf; 10765 struct lpfc_dmabuf *bdeBuf2 = elsiocb->bpl_dmabuf; 10766 dma_addr_t paddr; 10767 10768 elsiocb->cmd_dmabuf = NULL; 10769 elsiocb->rsp_dmabuf = NULL; 10770 elsiocb->bpl_dmabuf = NULL; 10771 10772 wcqe_cmpl = &elsiocb->wcqe_cmpl; 10773 ulp_command = get_job_cmnd(phba, elsiocb); 10774 status = get_job_ulpstatus(phba, elsiocb); 10775 parameter = get_job_word4(phba, elsiocb); 10776 if (phba->sli_rev == LPFC_SLI_REV4) 10777 bde_count = wcqe_cmpl->word3; 10778 else 10779 bde_count = elsiocb->iocb.ulpBdeCount; 10780 10781 if (status == IOSTAT_NEED_BUFFER) { 10782 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ); 10783 } else if (status == IOSTAT_LOCAL_REJECT && 10784 (parameter & IOERR_PARAM_MASK) == 10785 IOERR_RCV_BUFFER_WAITING) { 10786 phba->fc_stat.NoRcvBuf++; 10787 /* Not enough posted buffers; Try posting more buffers */ 10788 if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) 10789 lpfc_sli3_post_buffer(phba, pring, 0); 10790 return; 10791 } 10792 10793 if (phba->sli_rev == LPFC_SLI_REV3) { 10794 icmd = &elsiocb->iocb; 10795 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && 10796 (ulp_command == CMD_IOCB_RCV_ELS64_CX || 10797 ulp_command == CMD_IOCB_RCV_SEQ64_CX)) { 10798 if (icmd->unsli3.rcvsli3.vpi == 0xffff) 10799 vport = phba->pport; 10800 else 10801 vport = lpfc_find_vport_by_vpid(phba, 10802 icmd->unsli3.rcvsli3.vpi); 10803 } 10804 } 10805 10806 /* If there are no BDEs associated 10807 * with this IOCB, there is nothing to do. 10808 */ 10809 if (bde_count == 0) 10810 return; 10811 10812 /* Account for SLI2 or SLI3 and later unsolicited buffering */ 10813 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) { 10814 elsiocb->cmd_dmabuf = bdeBuf1; 10815 if (bde_count == 2) 10816 elsiocb->bpl_dmabuf = bdeBuf2; 10817 } else { 10818 icmd = &elsiocb->iocb; 10819 paddr = getPaddr(icmd->un.cont64[0].addrHigh, 10820 icmd->un.cont64[0].addrLow); 10821 elsiocb->cmd_dmabuf = lpfc_sli_ringpostbuf_get(phba, pring, 10822 paddr); 10823 if (bde_count == 2) { 10824 paddr = getPaddr(icmd->un.cont64[1].addrHigh, 10825 icmd->un.cont64[1].addrLow); 10826 elsiocb->bpl_dmabuf = lpfc_sli_ringpostbuf_get(phba, 10827 pring, 10828 paddr); 10829 } 10830 } 10831 10832 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb); 10833 /* 10834 * The different unsolicited event handlers would tell us 10835 * if they are done with "mp" by setting cmd_dmabuf to NULL. 10836 */ 10837 if (elsiocb->cmd_dmabuf) { 10838 lpfc_in_buf_free(phba, elsiocb->cmd_dmabuf); 10839 elsiocb->cmd_dmabuf = NULL; 10840 } 10841 10842 if (elsiocb->bpl_dmabuf) { 10843 lpfc_in_buf_free(phba, elsiocb->bpl_dmabuf); 10844 elsiocb->bpl_dmabuf = NULL; 10845 } 10846 10847 } 10848 10849 static void 10850 lpfc_start_fdmi(struct lpfc_vport *vport) 10851 { 10852 struct lpfc_nodelist *ndlp; 10853 10854 /* If this is the first time, allocate an ndlp and initialize 10855 * it. Otherwise, make sure the node is enabled and then do the 10856 * login. 10857 */ 10858 ndlp = lpfc_findnode_did(vport, FDMI_DID); 10859 if (!ndlp) { 10860 ndlp = lpfc_nlp_init(vport, FDMI_DID); 10861 if (ndlp) { 10862 ndlp->nlp_type |= NLP_FABRIC; 10863 } else { 10864 return; 10865 } 10866 } 10867 10868 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); 10869 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0); 10870 } 10871 10872 /** 10873 * lpfc_do_scr_ns_plogi - Issue a plogi to the name server for scr 10874 * @phba: pointer to lpfc hba data structure. 10875 * @vport: pointer to a virtual N_Port data structure. 10876 * 10877 * This routine issues a Port Login (PLOGI) to the Name Server with 10878 * State Change Request (SCR) for a @vport. This routine will create an 10879 * ndlp for the Name Server associated to the @vport if such node does 10880 * not already exist. The PLOGI to Name Server is issued by invoking the 10881 * lpfc_issue_els_plogi() routine. If Fabric-Device Management Interface 10882 * (FDMI) is configured to the @vport, a FDMI node will be created and 10883 * the PLOGI to FDMI is issued by invoking lpfc_issue_els_plogi() routine. 10884 **/ 10885 void 10886 lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport) 10887 { 10888 struct lpfc_nodelist *ndlp; 10889 10890 /* 10891 * If lpfc_delay_discovery parameter is set and the clean address 10892 * bit is cleared and fc fabric parameters chenged, delay FC NPort 10893 * discovery. 10894 */ 10895 if (test_bit(FC_DISC_DELAYED, &vport->fc_flag)) { 10896 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, 10897 "3334 Delay fc port discovery for %d secs\n", 10898 phba->fc_ratov); 10899 mod_timer(&vport->delayed_disc_tmo, 10900 jiffies + secs_to_jiffies(phba->fc_ratov)); 10901 return; 10902 } 10903 10904 ndlp = lpfc_findnode_did(vport, NameServer_DID); 10905 if (!ndlp) { 10906 ndlp = lpfc_nlp_init(vport, NameServer_DID); 10907 if (!ndlp) { 10908 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { 10909 lpfc_disc_start(vport); 10910 return; 10911 } 10912 lpfc_vport_set_state(vport, FC_VPORT_FAILED); 10913 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, 10914 "0251 NameServer login: no memory\n"); 10915 return; 10916 } 10917 } 10918 10919 ndlp->nlp_type |= NLP_FABRIC; 10920 10921 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); 10922 10923 if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) { 10924 lpfc_vport_set_state(vport, FC_VPORT_FAILED); 10925 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, 10926 "0252 Cannot issue NameServer login\n"); 10927 return; 10928 } 10929 10930 if ((phba->cfg_enable_SmartSAN || 10931 phba->cfg_fdmi_on == LPFC_FDMI_SUPPORT) && 10932 test_bit(FC_ALLOW_FDMI, &vport->load_flag)) 10933 lpfc_start_fdmi(vport); 10934 } 10935 10936 /** 10937 * lpfc_cmpl_reg_new_vport - Completion callback function to register new vport 10938 * @phba: pointer to lpfc hba data structure. 10939 * @pmb: pointer to the driver internal queue element for mailbox command. 10940 * 10941 * This routine is the completion callback function to register new vport 10942 * mailbox command. If the new vport mailbox command completes successfully, 10943 * the fabric registration login shall be performed on physical port (the 10944 * new vport created is actually a physical port, with VPI 0) or the port 10945 * login to Name Server for State Change Request (SCR) will be performed 10946 * on virtual port (real virtual port, with VPI greater than 0). 10947 **/ 10948 static void 10949 lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) 10950 { 10951 struct lpfc_vport *vport = pmb->vport; 10952 struct Scsi_Host *shost = lpfc_shost_from_vport(vport); 10953 struct lpfc_nodelist *ndlp = pmb->ctx_ndlp; 10954 MAILBOX_t *mb = &pmb->u.mb; 10955 int rc; 10956 10957 clear_bit(FC_VPORT_NEEDS_REG_VPI, &vport->fc_flag); 10958 10959 if (mb->mbxStatus) { 10960 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, 10961 "0915 Register VPI failed : Status: x%x" 10962 " upd bit: x%x \n", mb->mbxStatus, 10963 mb->un.varRegVpi.upd); 10964 if (phba->sli_rev == LPFC_SLI_REV4 && 10965 mb->un.varRegVpi.upd) 10966 goto mbox_err_exit ; 10967 10968 switch (mb->mbxStatus) { 10969 case 0x11: /* unsupported feature */ 10970 case 0x9603: /* max_vpi exceeded */ 10971 case 0x9602: /* Link event since CLEAR_LA */ 10972 /* giving up on vport registration */ 10973 lpfc_vport_set_state(vport, FC_VPORT_FAILED); 10974 clear_bit(FC_FABRIC, &vport->fc_flag); 10975 clear_bit(FC_PUBLIC_LOOP, &vport->fc_flag); 10976 lpfc_can_disctmo(vport); 10977 break; 10978 /* If reg_vpi fail with invalid VPI status, re-init VPI */ 10979 case 0x20: 10980 set_bit(FC_VPORT_NEEDS_REG_VPI, &vport->fc_flag); 10981 lpfc_init_vpi(phba, pmb, vport->vpi); 10982 pmb->vport = vport; 10983 pmb->mbox_cmpl = lpfc_init_vpi_cmpl; 10984 rc = lpfc_sli_issue_mbox(phba, pmb, 10985 MBX_NOWAIT); 10986 if (rc == MBX_NOT_FINISHED) { 10987 lpfc_printf_vlog(vport, KERN_ERR, 10988 LOG_TRACE_EVENT, 10989 "2732 Failed to issue INIT_VPI" 10990 " mailbox command\n"); 10991 } else { 10992 lpfc_nlp_put(ndlp); 10993 return; 10994 } 10995 fallthrough; 10996 default: 10997 /* Try to recover from this error */ 10998 if (phba->sli_rev == LPFC_SLI_REV4) 10999 lpfc_sli4_unreg_all_rpis(vport); 11000 lpfc_mbx_unreg_vpi(vport); 11001 set_bit(FC_VPORT_NEEDS_REG_VPI, &vport->fc_flag); 11002 if (mb->mbxStatus == MBX_NOT_FINISHED) 11003 break; 11004 if ((vport->port_type == LPFC_PHYSICAL_PORT) && 11005 !test_bit(FC_LOGO_RCVD_DID_CHNG, &vport->fc_flag)) { 11006 if (phba->sli_rev == LPFC_SLI_REV4) 11007 lpfc_issue_init_vfi(vport); 11008 else 11009 lpfc_initial_flogi(vport); 11010 } else { 11011 lpfc_initial_fdisc(vport); 11012 } 11013 break; 11014 } 11015 } else { 11016 spin_lock_irq(shost->host_lock); 11017 vport->vpi_state |= LPFC_VPI_REGISTERED; 11018 spin_unlock_irq(shost->host_lock); 11019 if (vport == phba->pport) { 11020 if (phba->sli_rev < LPFC_SLI_REV4) 11021 lpfc_issue_fabric_reglogin(vport); 11022 else { 11023 /* 11024 * If the physical port is instantiated using 11025 * FDISC, do not start vport discovery. 11026 */ 11027 if (vport->port_state != LPFC_FDISC) 11028 lpfc_start_fdiscs(phba); 11029 lpfc_do_scr_ns_plogi(phba, vport); 11030 } 11031 } else { 11032 lpfc_do_scr_ns_plogi(phba, vport); 11033 } 11034 } 11035 mbox_err_exit: 11036 /* Now, we decrement the ndlp reference count held for this 11037 * callback function 11038 */ 11039 lpfc_nlp_put(ndlp); 11040 11041 mempool_free(pmb, phba->mbox_mem_pool); 11042 11043 /* reinitialize the VMID datastructure before returning. 11044 * this is specifically for vport 11045 */ 11046 if (lpfc_is_vmid_enabled(phba)) 11047 lpfc_reinit_vmid(vport); 11048 vport->vmid_flag = vport->phba->pport->vmid_flag; 11049 11050 return; 11051 } 11052 11053 /** 11054 * lpfc_register_new_vport - Register a new vport with a HBA 11055 * @phba: pointer to lpfc hba data structure. 11056 * @vport: pointer to a host virtual N_Port data structure. 11057 * @ndlp: pointer to a node-list data structure. 11058 * 11059 * This routine registers the @vport as a new virtual port with a HBA. 11060 * It is done through a registering vpi mailbox command. 11061 **/ 11062 void 11063 lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport, 11064 struct lpfc_nodelist *ndlp) 11065 { 11066 LPFC_MBOXQ_t *mbox; 11067 11068 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); 11069 if (mbox) { 11070 lpfc_reg_vpi(vport, mbox); 11071 mbox->vport = vport; 11072 mbox->ctx_ndlp = lpfc_nlp_get(ndlp); 11073 if (!mbox->ctx_ndlp) { 11074 mempool_free(mbox, phba->mbox_mem_pool); 11075 goto mbox_err_exit; 11076 } 11077 11078 mbox->mbox_cmpl = lpfc_cmpl_reg_new_vport; 11079 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) 11080 == MBX_NOT_FINISHED) { 11081 /* mailbox command not success, decrement ndlp 11082 * reference count for this command 11083 */ 11084 lpfc_nlp_put(ndlp); 11085 mempool_free(mbox, phba->mbox_mem_pool); 11086 11087 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, 11088 "0253 Register VPI: Can't send mbox\n"); 11089 goto mbox_err_exit; 11090 } 11091 } else { 11092 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, 11093 "0254 Register VPI: no memory\n"); 11094 goto mbox_err_exit; 11095 } 11096 return; 11097 11098 mbox_err_exit: 11099 lpfc_vport_set_state(vport, FC_VPORT_FAILED); 11100 clear_bit(FC_VPORT_NEEDS_REG_VPI, &vport->fc_flag); 11101 return; 11102 } 11103 11104 /** 11105 * lpfc_cancel_all_vport_retry_delay_timer - Cancel all vport retry delay timer 11106 * @phba: pointer to lpfc hba data structure. 11107 * 11108 * This routine cancels the retry delay timers to all the vports. 11109 **/ 11110 void 11111 lpfc_cancel_all_vport_retry_delay_timer(struct lpfc_hba *phba) 11112 { 11113 struct lpfc_vport **vports; 11114 struct lpfc_nodelist *ndlp; 11115 uint32_t link_state; 11116 int i; 11117 11118 /* Treat this failure as linkdown for all vports */ 11119 link_state = phba->link_state; 11120 lpfc_linkdown(phba); 11121 phba->link_state = link_state; 11122 11123 vports = lpfc_create_vport_work_array(phba); 11124 11125 if (vports) { 11126 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { 11127 ndlp = lpfc_findnode_did(vports[i], Fabric_DID); 11128 if (ndlp) 11129 lpfc_cancel_retry_delay_tmo(vports[i], ndlp); 11130 lpfc_els_flush_cmd(vports[i]); 11131 } 11132 lpfc_destroy_vport_work_array(phba, vports); 11133 } 11134 } 11135 11136 /** 11137 * lpfc_retry_pport_discovery - Start timer to retry FLOGI. 11138 * @phba: pointer to lpfc hba data structure. 11139 * 11140 * This routine abort all pending discovery commands and 11141 * start a timer to retry FLOGI for the physical port 11142 * discovery. 11143 **/ 11144 void 11145 lpfc_retry_pport_discovery(struct lpfc_hba *phba) 11146 { 11147 struct lpfc_nodelist *ndlp; 11148 11149 /* Cancel the all vports retry delay retry timers */ 11150 lpfc_cancel_all_vport_retry_delay_timer(phba); 11151 11152 /* If fabric require FLOGI, then re-instantiate physical login */ 11153 ndlp = lpfc_findnode_did(phba->pport, Fabric_DID); 11154 if (!ndlp) 11155 return; 11156 11157 mod_timer(&ndlp->nlp_delayfunc, jiffies + secs_to_jiffies(1)); 11158 set_bit(NLP_DELAY_TMO, &ndlp->nlp_flag); 11159 ndlp->nlp_last_elscmd = ELS_CMD_FLOGI; 11160 phba->pport->port_state = LPFC_FLOGI; 11161 return; 11162 } 11163 11164 /** 11165 * lpfc_fabric_login_reqd - Check if FLOGI required. 11166 * @phba: pointer to lpfc hba data structure. 11167 * @cmdiocb: pointer to FDISC command iocb. 11168 * @rspiocb: pointer to FDISC response iocb. 11169 * 11170 * This routine checks if a FLOGI is reguired for FDISC 11171 * to succeed. 11172 **/ 11173 static int 11174 lpfc_fabric_login_reqd(struct lpfc_hba *phba, 11175 struct lpfc_iocbq *cmdiocb, 11176 struct lpfc_iocbq *rspiocb) 11177 { 11178 u32 ulp_status = get_job_ulpstatus(phba, rspiocb); 11179 u32 ulp_word4 = get_job_word4(phba, rspiocb); 11180 11181 if (ulp_status != IOSTAT_FABRIC_RJT || 11182 ulp_word4 != RJT_LOGIN_REQUIRED) 11183 return 0; 11184 else 11185 return 1; 11186 } 11187 11188 /** 11189 * lpfc_cmpl_els_fdisc - Completion function for fdisc iocb command 11190 * @phba: pointer to lpfc hba data structure. 11191 * @cmdiocb: pointer to lpfc command iocb data structure. 11192 * @rspiocb: pointer to lpfc response iocb data structure. 11193 * 11194 * This routine is the completion callback function to a Fabric Discover 11195 * (FDISC) ELS command. Since all the FDISC ELS commands are issued 11196 * single threaded, each FDISC completion callback function will reset 11197 * the discovery timer for all vports such that the timers will not get 11198 * unnecessary timeout. The function checks the FDISC IOCB status. If error 11199 * detected, the vport will be set to FC_VPORT_FAILED state. Otherwise,the 11200 * vport will set to FC_VPORT_ACTIVE state. It then checks whether the DID 11201 * assigned to the vport has been changed with the completion of the FDISC 11202 * command. If so, both RPI (Remote Port Index) and VPI (Virtual Port Index) 11203 * are unregistered from the HBA, and then the lpfc_register_new_vport() 11204 * routine is invoked to register new vport with the HBA. Otherwise, the 11205 * lpfc_do_scr_ns_plogi() routine is invoked to issue a PLOGI to the Name 11206 * Server for State Change Request (SCR). 11207 **/ 11208 static void 11209 lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, 11210 struct lpfc_iocbq *rspiocb) 11211 { 11212 struct lpfc_vport *vport = cmdiocb->vport; 11213 struct lpfc_nodelist *ndlp = cmdiocb->ndlp; 11214 struct lpfc_nodelist *np; 11215 struct lpfc_nodelist *next_np; 11216 struct lpfc_iocbq *piocb; 11217 struct lpfc_dmabuf *pcmd = cmdiocb->cmd_dmabuf, *prsp; 11218 struct serv_parm *sp; 11219 uint8_t fabric_param_changed; 11220 u32 ulp_status, ulp_word4; 11221 11222 ulp_status = get_job_ulpstatus(phba, rspiocb); 11223 ulp_word4 = get_job_word4(phba, rspiocb); 11224 11225 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, 11226 "0123 FDISC completes. x%x/x%x prevDID: x%x\n", 11227 ulp_status, ulp_word4, 11228 vport->fc_prevDID); 11229 /* Since all FDISCs are being single threaded, we 11230 * must reset the discovery timer for ALL vports 11231 * waiting to send FDISC when one completes. 11232 */ 11233 list_for_each_entry(piocb, &phba->fabric_iocb_list, list) { 11234 lpfc_set_disctmo(piocb->vport); 11235 } 11236 11237 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, 11238 "FDISC cmpl: status:x%x/x%x prevdid:x%x", 11239 ulp_status, ulp_word4, vport->fc_prevDID); 11240 11241 if (ulp_status) { 11242 11243 if (lpfc_fabric_login_reqd(phba, cmdiocb, rspiocb)) { 11244 lpfc_retry_pport_discovery(phba); 11245 goto out; 11246 } 11247 11248 /* Check for retry */ 11249 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) 11250 goto out; 11251 /* Warn FDISC status */ 11252 lpfc_vlog_msg(vport, KERN_WARNING, LOG_ELS, 11253 "0126 FDISC cmpl status: x%x/x%x)\n", 11254 ulp_status, ulp_word4); 11255 goto fdisc_failed; 11256 } 11257 11258 lpfc_check_nlp_post_devloss(vport, ndlp); 11259 11260 clear_bit(FC_VPORT_CVL_RCVD, &vport->fc_flag); 11261 clear_bit(FC_VPORT_LOGO_RCVD, &vport->fc_flag); 11262 set_bit(FC_FABRIC, &vport->fc_flag); 11263 if (vport->phba->fc_topology == LPFC_TOPOLOGY_LOOP) 11264 set_bit(FC_PUBLIC_LOOP, &vport->fc_flag); 11265 11266 vport->fc_myDID = ulp_word4 & Mask_DID; 11267 lpfc_vport_set_state(vport, FC_VPORT_ACTIVE); 11268 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list); 11269 if (!prsp) 11270 goto out; 11271 if (!lpfc_is_els_acc_rsp(prsp)) 11272 goto out; 11273 11274 sp = prsp->virt + sizeof(uint32_t); 11275 fabric_param_changed = lpfc_check_clean_addr_bit(vport, sp); 11276 memcpy(&vport->fabric_portname, &sp->portName, 11277 sizeof(struct lpfc_name)); 11278 memcpy(&vport->fabric_nodename, &sp->nodeName, 11279 sizeof(struct lpfc_name)); 11280 if (fabric_param_changed && 11281 !test_bit(FC_VPORT_NEEDS_REG_VPI, &vport->fc_flag)) { 11282 /* If our NportID changed, we need to ensure all 11283 * remaining NPORTs get unreg_login'ed so we can 11284 * issue unreg_vpi. 11285 */ 11286 list_for_each_entry_safe(np, next_np, 11287 &vport->fc_nodes, nlp_listp) { 11288 if ((np->nlp_state != NLP_STE_NPR_NODE) || 11289 !test_bit(NLP_NPR_ADISC, &np->nlp_flag)) 11290 continue; 11291 clear_bit(NLP_NPR_ADISC, &np->nlp_flag); 11292 lpfc_unreg_rpi(vport, np); 11293 } 11294 lpfc_cleanup_pending_mbox(vport); 11295 11296 if (phba->sli_rev == LPFC_SLI_REV4) 11297 lpfc_sli4_unreg_all_rpis(vport); 11298 11299 lpfc_mbx_unreg_vpi(vport); 11300 set_bit(FC_VPORT_NEEDS_REG_VPI, &vport->fc_flag); 11301 if (phba->sli_rev == LPFC_SLI_REV4) 11302 set_bit(FC_VPORT_NEEDS_INIT_VPI, &vport->fc_flag); 11303 else 11304 set_bit(FC_LOGO_RCVD_DID_CHNG, &vport->fc_flag); 11305 } else if ((phba->sli_rev == LPFC_SLI_REV4) && 11306 !test_bit(FC_VPORT_NEEDS_REG_VPI, &vport->fc_flag)) { 11307 /* 11308 * Driver needs to re-reg VPI in order for f/w 11309 * to update the MAC address. 11310 */ 11311 lpfc_register_new_vport(phba, vport, ndlp); 11312 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE); 11313 goto out; 11314 } 11315 11316 if (test_bit(FC_VPORT_NEEDS_INIT_VPI, &vport->fc_flag)) 11317 lpfc_issue_init_vpi(vport); 11318 else if (test_bit(FC_VPORT_NEEDS_REG_VPI, &vport->fc_flag)) 11319 lpfc_register_new_vport(phba, vport, ndlp); 11320 else 11321 lpfc_do_scr_ns_plogi(phba, vport); 11322 11323 /* The FDISC completed successfully. Move the fabric ndlp to 11324 * UNMAPPED state and register with the transport. 11325 */ 11326 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE); 11327 goto out; 11328 11329 fdisc_failed: 11330 if (vport->fc_vport && 11331 (vport->fc_vport->vport_state != FC_VPORT_NO_FABRIC_RSCS)) 11332 lpfc_vport_set_state(vport, FC_VPORT_FAILED); 11333 /* Cancel discovery timer */ 11334 lpfc_can_disctmo(vport); 11335 out: 11336 lpfc_els_free_iocb(phba, cmdiocb); 11337 lpfc_nlp_put(ndlp); 11338 } 11339 11340 /** 11341 * lpfc_issue_els_fdisc - Issue a fdisc iocb command 11342 * @vport: pointer to a virtual N_Port data structure. 11343 * @ndlp: pointer to a node-list data structure. 11344 * @retry: number of retries to the command IOCB. 11345 * 11346 * This routine prepares and issues a Fabric Discover (FDISC) IOCB to 11347 * a remote node (@ndlp) off a @vport. It uses the lpfc_issue_fabric_iocb() 11348 * routine to issue the IOCB, which makes sure only one outstanding fabric 11349 * IOCB will be sent off HBA at any given time. 11350 * 11351 * Note that the ndlp reference count will be incremented by 1 for holding the 11352 * ndlp and the reference to ndlp will be stored into the ndlp field of 11353 * the IOCB for the completion callback function to the FDISC ELS command. 11354 * 11355 * Return code 11356 * 0 - Successfully issued fdisc iocb command 11357 * 1 - Failed to issue fdisc iocb command 11358 **/ 11359 static int 11360 lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, 11361 uint8_t retry) 11362 { 11363 struct lpfc_hba *phba = vport->phba; 11364 IOCB_t *icmd; 11365 union lpfc_wqe128 *wqe = NULL; 11366 struct lpfc_iocbq *elsiocb; 11367 struct serv_parm *sp; 11368 uint8_t *pcmd; 11369 uint16_t cmdsize; 11370 int did = ndlp->nlp_DID; 11371 int rc; 11372 11373 vport->port_state = LPFC_FDISC; 11374 vport->fc_myDID = 0; 11375 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm)); 11376 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did, 11377 ELS_CMD_FDISC); 11378 if (!elsiocb) { 11379 lpfc_vport_set_state(vport, FC_VPORT_FAILED); 11380 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, 11381 "0255 Issue FDISC: no IOCB\n"); 11382 return 1; 11383 } 11384 11385 if (phba->sli_rev == LPFC_SLI_REV4) { 11386 wqe = &elsiocb->wqe; 11387 bf_set(els_req64_sid, &wqe->els_req, 0); 11388 bf_set(els_req64_sp, &wqe->els_req, 1); 11389 } else { 11390 icmd = &elsiocb->iocb; 11391 icmd->un.elsreq64.myID = 0; 11392 icmd->un.elsreq64.fl = 1; 11393 icmd->ulpCt_h = 1; 11394 icmd->ulpCt_l = 0; 11395 } 11396 11397 pcmd = (uint8_t *)elsiocb->cmd_dmabuf->virt; 11398 *((uint32_t *) (pcmd)) = ELS_CMD_FDISC; 11399 pcmd += sizeof(uint32_t); /* CSP Word 1 */ 11400 memcpy(pcmd, &vport->phba->pport->fc_sparam, sizeof(struct serv_parm)); 11401 sp = (struct serv_parm *) pcmd; 11402 /* Setup CSPs accordingly for Fabric */ 11403 sp->cmn.e_d_tov = 0; 11404 sp->cmn.w2.r_a_tov = 0; 11405 sp->cmn.virtual_fabric_support = 0; 11406 sp->cls1.classValid = 0; 11407 sp->cls2.seqDelivery = 1; 11408 sp->cls3.seqDelivery = 1; 11409 11410 pcmd += sizeof(uint32_t); /* CSP Word 2 */ 11411 pcmd += sizeof(uint32_t); /* CSP Word 3 */ 11412 pcmd += sizeof(uint32_t); /* CSP Word 4 */ 11413 pcmd += sizeof(uint32_t); /* Port Name */ 11414 memcpy(pcmd, &vport->fc_portname, 8); 11415 pcmd += sizeof(uint32_t); /* Node Name */ 11416 pcmd += sizeof(uint32_t); /* Node Name */ 11417 memcpy(pcmd, &vport->fc_nodename, 8); 11418 sp->cmn.valid_vendor_ver_level = 0; 11419 memset(sp->un.vendorVersion, 0, sizeof(sp->un.vendorVersion)); 11420 lpfc_set_disctmo(vport); 11421 11422 phba->fc_stat.elsXmitFDISC++; 11423 elsiocb->cmd_cmpl = lpfc_cmpl_els_fdisc; 11424 11425 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, 11426 "Issue FDISC: did:x%x", 11427 did, 0, 0); 11428 11429 elsiocb->ndlp = lpfc_nlp_get(ndlp); 11430 if (!elsiocb->ndlp) 11431 goto err_out; 11432 11433 rc = lpfc_issue_fabric_iocb(phba, elsiocb); 11434 if (rc == IOCB_ERROR) { 11435 lpfc_nlp_put(ndlp); 11436 goto err_out; 11437 } 11438 11439 lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING); 11440 return 0; 11441 11442 err_out: 11443 lpfc_els_free_iocb(phba, elsiocb); 11444 lpfc_vport_set_state(vport, FC_VPORT_FAILED); 11445 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, 11446 "0256 Issue FDISC: Cannot send IOCB\n"); 11447 return 1; 11448 } 11449 11450 /** 11451 * lpfc_cmpl_els_npiv_logo - Completion function with vport logo 11452 * @phba: pointer to lpfc hba data structure. 11453 * @cmdiocb: pointer to lpfc command iocb data structure. 11454 * @rspiocb: pointer to lpfc response iocb data structure. 11455 * 11456 * This routine is the completion callback function to the issuing of a LOGO 11457 * ELS command off a vport. It frees the command IOCB and then decrement the 11458 * reference count held on ndlp for this completion function, indicating that 11459 * the reference to the ndlp is no long needed. Note that the 11460 * lpfc_els_free_iocb() routine decrements the ndlp reference held for this 11461 * callback function and an additional explicit ndlp reference decrementation 11462 * will trigger the actual release of the ndlp. 11463 **/ 11464 static void 11465 lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, 11466 struct lpfc_iocbq *rspiocb) 11467 { 11468 struct lpfc_vport *vport = cmdiocb->vport; 11469 IOCB_t *irsp; 11470 struct lpfc_nodelist *ndlp; 11471 u32 ulp_status, ulp_word4, did, tmo; 11472 11473 ndlp = cmdiocb->ndlp; 11474 11475 ulp_status = get_job_ulpstatus(phba, rspiocb); 11476 ulp_word4 = get_job_word4(phba, rspiocb); 11477 11478 if (phba->sli_rev == LPFC_SLI_REV4) { 11479 did = get_job_els_rsp64_did(phba, cmdiocb); 11480 tmo = get_wqe_tmo(cmdiocb); 11481 } else { 11482 irsp = &rspiocb->iocb; 11483 did = get_job_els_rsp64_did(phba, rspiocb); 11484 tmo = irsp->ulpTimeout; 11485 } 11486 11487 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, 11488 "LOGO npiv cmpl: status:x%x/x%x did:x%x", 11489 ulp_status, ulp_word4, did); 11490 11491 /* NPIV LOGO completes to NPort <nlp_DID> */ 11492 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, 11493 "2928 NPIV LOGO completes to NPort x%x " 11494 "Data: x%x x%x x%x x%x x%x x%lx x%x\n", 11495 ndlp->nlp_DID, ulp_status, ulp_word4, 11496 tmo, vport->num_disc_nodes, 11497 kref_read(&ndlp->kref), ndlp->nlp_flag, 11498 ndlp->fc4_xpt_flags); 11499 11500 if (ulp_status == IOSTAT_SUCCESS) { 11501 clear_bit(FC_NDISC_ACTIVE, &vport->fc_flag); 11502 clear_bit(FC_FABRIC, &vport->fc_flag); 11503 lpfc_can_disctmo(vport); 11504 } 11505 11506 if (test_bit(NLP_WAIT_FOR_LOGO, &ndlp->save_flags)) { 11507 /* Wake up lpfc_vport_delete if waiting...*/ 11508 if (ndlp->logo_waitq) 11509 wake_up(ndlp->logo_waitq); 11510 clear_bit(NLP_ISSUE_LOGO, &ndlp->nlp_flag); 11511 clear_bit(NLP_LOGO_SND, &ndlp->nlp_flag); 11512 clear_bit(NLP_WAIT_FOR_LOGO, &ndlp->save_flags); 11513 } 11514 11515 /* Safe to release resources now. */ 11516 lpfc_els_free_iocb(phba, cmdiocb); 11517 lpfc_nlp_put(ndlp); 11518 } 11519 11520 /** 11521 * lpfc_issue_els_npiv_logo - Issue a logo off a vport 11522 * @vport: pointer to a virtual N_Port data structure. 11523 * @ndlp: pointer to a node-list data structure. 11524 * 11525 * This routine issues a LOGO ELS command to an @ndlp off a @vport. 11526 * 11527 * Note that the ndlp reference count will be incremented by 1 for holding the 11528 * ndlp and the reference to ndlp will be stored into the ndlp field of 11529 * the IOCB for the completion callback function to the LOGO ELS command. 11530 * 11531 * Return codes 11532 * 0 - Successfully issued logo off the @vport 11533 * 1 - Failed to issue logo off the @vport 11534 **/ 11535 int 11536 lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) 11537 { 11538 int rc = 0; 11539 struct lpfc_hba *phba = vport->phba; 11540 struct lpfc_iocbq *elsiocb; 11541 uint8_t *pcmd; 11542 uint16_t cmdsize; 11543 11544 cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name); 11545 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID, 11546 ELS_CMD_LOGO); 11547 if (!elsiocb) 11548 return 1; 11549 11550 pcmd = (uint8_t *)elsiocb->cmd_dmabuf->virt; 11551 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO; 11552 pcmd += sizeof(uint32_t); 11553 11554 /* Fill in LOGO payload */ 11555 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID); 11556 pcmd += sizeof(uint32_t); 11557 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name)); 11558 11559 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, 11560 "Issue LOGO npiv did:x%x flg:x%lx", 11561 ndlp->nlp_DID, ndlp->nlp_flag, 0); 11562 11563 elsiocb->cmd_cmpl = lpfc_cmpl_els_npiv_logo; 11564 set_bit(NLP_LOGO_SND, &ndlp->nlp_flag); 11565 elsiocb->ndlp = lpfc_nlp_get(ndlp); 11566 if (!elsiocb->ndlp) { 11567 lpfc_els_free_iocb(phba, elsiocb); 11568 goto err; 11569 } 11570 11571 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); 11572 if (rc == IOCB_ERROR) { 11573 lpfc_els_free_iocb(phba, elsiocb); 11574 lpfc_nlp_put(ndlp); 11575 goto err; 11576 } 11577 return 0; 11578 11579 err: 11580 clear_bit(NLP_LOGO_SND, &ndlp->nlp_flag); 11581 return 1; 11582 } 11583 11584 /** 11585 * lpfc_fabric_block_timeout - Handler function to the fabric block timer 11586 * @t: timer context used to obtain the lpfc hba. 11587 * 11588 * This routine is invoked by the fabric iocb block timer after 11589 * timeout. It posts the fabric iocb block timeout event by setting the 11590 * WORKER_FABRIC_BLOCK_TMO bit to work port event bitmap and then invokes 11591 * lpfc_worker_wake_up() routine to wake up the worker thread. It is for 11592 * the worker thread to invoke the lpfc_unblock_fabric_iocbs() on the 11593 * posted event WORKER_FABRIC_BLOCK_TMO. 11594 **/ 11595 void 11596 lpfc_fabric_block_timeout(struct timer_list *t) 11597 { 11598 struct lpfc_hba *phba = timer_container_of(phba, t, 11599 fabric_block_timer); 11600 unsigned long iflags; 11601 uint32_t tmo_posted; 11602 11603 spin_lock_irqsave(&phba->pport->work_port_lock, iflags); 11604 tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO; 11605 if (!tmo_posted) 11606 phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO; 11607 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags); 11608 11609 if (!tmo_posted) 11610 lpfc_worker_wake_up(phba); 11611 return; 11612 } 11613 11614 /** 11615 * lpfc_resume_fabric_iocbs - Issue a fabric iocb from driver internal list 11616 * @phba: pointer to lpfc hba data structure. 11617 * 11618 * This routine issues one fabric iocb from the driver internal list to 11619 * the HBA. It first checks whether it's ready to issue one fabric iocb to 11620 * the HBA (whether there is no outstanding fabric iocb). If so, it shall 11621 * remove one pending fabric iocb from the driver internal list and invokes 11622 * lpfc_sli_issue_iocb() routine to send the fabric iocb to the HBA. 11623 **/ 11624 static void 11625 lpfc_resume_fabric_iocbs(struct lpfc_hba *phba) 11626 { 11627 struct lpfc_iocbq *iocb; 11628 unsigned long iflags; 11629 int ret; 11630 11631 repeat: 11632 iocb = NULL; 11633 spin_lock_irqsave(&phba->hbalock, iflags); 11634 /* Post any pending iocb to the SLI layer */ 11635 if (atomic_read(&phba->fabric_iocb_count) == 0) { 11636 list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb), 11637 list); 11638 if (iocb) 11639 /* Increment fabric iocb count to hold the position */ 11640 atomic_inc(&phba->fabric_iocb_count); 11641 } 11642 spin_unlock_irqrestore(&phba->hbalock, iflags); 11643 if (iocb) { 11644 iocb->fabric_cmd_cmpl = iocb->cmd_cmpl; 11645 iocb->cmd_cmpl = lpfc_cmpl_fabric_iocb; 11646 iocb->cmd_flag |= LPFC_IO_FABRIC; 11647 11648 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD, 11649 "Fabric sched1: ste:x%x", 11650 iocb->vport->port_state, 0, 0); 11651 11652 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0); 11653 11654 if (ret == IOCB_ERROR) { 11655 iocb->cmd_cmpl = iocb->fabric_cmd_cmpl; 11656 iocb->fabric_cmd_cmpl = NULL; 11657 iocb->cmd_flag &= ~LPFC_IO_FABRIC; 11658 set_job_ulpstatus(iocb, IOSTAT_LOCAL_REJECT); 11659 iocb->wcqe_cmpl.parameter = IOERR_SLI_ABORTED; 11660 iocb->cmd_cmpl(phba, iocb, iocb); 11661 11662 atomic_dec(&phba->fabric_iocb_count); 11663 goto repeat; 11664 } 11665 } 11666 } 11667 11668 /** 11669 * lpfc_unblock_fabric_iocbs - Unblock issuing fabric iocb command 11670 * @phba: pointer to lpfc hba data structure. 11671 * 11672 * This routine unblocks the issuing fabric iocb command. The function 11673 * will clear the fabric iocb block bit and then invoke the routine 11674 * lpfc_resume_fabric_iocbs() to issue one of the pending fabric iocb 11675 * from the driver internal fabric iocb list. 11676 **/ 11677 void 11678 lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba) 11679 { 11680 clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags); 11681 11682 lpfc_resume_fabric_iocbs(phba); 11683 return; 11684 } 11685 11686 /** 11687 * lpfc_block_fabric_iocbs - Block issuing fabric iocb command 11688 * @phba: pointer to lpfc hba data structure. 11689 * 11690 * This routine blocks the issuing fabric iocb for a specified amount of 11691 * time (currently 100 ms). This is done by set the fabric iocb block bit 11692 * and set up a timeout timer for 100ms. When the block bit is set, no more 11693 * fabric iocb will be issued out of the HBA. 11694 **/ 11695 static void 11696 lpfc_block_fabric_iocbs(struct lpfc_hba *phba) 11697 { 11698 int blocked; 11699 11700 blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags); 11701 /* Start a timer to unblock fabric iocbs after 100ms */ 11702 if (!blocked) 11703 mod_timer(&phba->fabric_block_timer, 11704 jiffies + msecs_to_jiffies(100)); 11705 11706 return; 11707 } 11708 11709 /** 11710 * lpfc_cmpl_fabric_iocb - Completion callback function for fabric iocb 11711 * @phba: pointer to lpfc hba data structure. 11712 * @cmdiocb: pointer to lpfc command iocb data structure. 11713 * @rspiocb: pointer to lpfc response iocb data structure. 11714 * 11715 * This routine is the callback function that is put to the fabric iocb's 11716 * callback function pointer (iocb->cmd_cmpl). The original iocb's callback 11717 * function pointer has been stored in iocb->fabric_cmd_cmpl. This callback 11718 * function first restores and invokes the original iocb's callback function 11719 * and then invokes the lpfc_resume_fabric_iocbs() routine to issue the next 11720 * fabric bound iocb from the driver internal fabric iocb list onto the wire. 11721 **/ 11722 static void 11723 lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, 11724 struct lpfc_iocbq *rspiocb) 11725 { 11726 struct ls_rjt stat; 11727 u32 ulp_status = get_job_ulpstatus(phba, rspiocb); 11728 u32 ulp_word4 = get_job_word4(phba, rspiocb); 11729 11730 WARN_ON((cmdiocb->cmd_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC); 11731 11732 switch (ulp_status) { 11733 case IOSTAT_NPORT_RJT: 11734 case IOSTAT_FABRIC_RJT: 11735 if (ulp_word4 & RJT_UNAVAIL_TEMP) 11736 lpfc_block_fabric_iocbs(phba); 11737 break; 11738 11739 case IOSTAT_NPORT_BSY: 11740 case IOSTAT_FABRIC_BSY: 11741 lpfc_block_fabric_iocbs(phba); 11742 break; 11743 11744 case IOSTAT_LS_RJT: 11745 stat.un.ls_rjt_error_be = 11746 cpu_to_be32(ulp_word4); 11747 if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) || 11748 (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY)) 11749 lpfc_block_fabric_iocbs(phba); 11750 break; 11751 } 11752 11753 BUG_ON(atomic_read(&phba->fabric_iocb_count) == 0); 11754 11755 cmdiocb->cmd_cmpl = cmdiocb->fabric_cmd_cmpl; 11756 cmdiocb->fabric_cmd_cmpl = NULL; 11757 cmdiocb->cmd_flag &= ~LPFC_IO_FABRIC; 11758 cmdiocb->cmd_cmpl(phba, cmdiocb, rspiocb); 11759 11760 atomic_dec(&phba->fabric_iocb_count); 11761 if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) { 11762 /* Post any pending iocbs to HBA */ 11763 lpfc_resume_fabric_iocbs(phba); 11764 } 11765 } 11766 11767 /** 11768 * lpfc_issue_fabric_iocb - Issue a fabric iocb command 11769 * @phba: pointer to lpfc hba data structure. 11770 * @iocb: pointer to lpfc command iocb data structure. 11771 * 11772 * This routine is used as the top-level API for issuing a fabric iocb command 11773 * such as FLOGI and FDISC. To accommodate certain switch fabric, this driver 11774 * function makes sure that only one fabric bound iocb will be outstanding at 11775 * any given time. As such, this function will first check to see whether there 11776 * is already an outstanding fabric iocb on the wire. If so, it will put the 11777 * newly issued iocb onto the driver internal fabric iocb list, waiting to be 11778 * issued later. Otherwise, it will issue the iocb on the wire and update the 11779 * fabric iocb count it indicate that there is one fabric iocb on the wire. 11780 * 11781 * Note, this implementation has a potential sending out fabric IOCBs out of 11782 * order. The problem is caused by the construction of the "ready" boolen does 11783 * not include the condition that the internal fabric IOCB list is empty. As 11784 * such, it is possible a fabric IOCB issued by this routine might be "jump" 11785 * ahead of the fabric IOCBs in the internal list. 11786 * 11787 * Return code 11788 * IOCB_SUCCESS - either fabric iocb put on the list or issued successfully 11789 * IOCB_ERROR - failed to issue fabric iocb 11790 **/ 11791 static int 11792 lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb) 11793 { 11794 unsigned long iflags; 11795 int ready; 11796 int ret; 11797 11798 BUG_ON(atomic_read(&phba->fabric_iocb_count) > 1); 11799 11800 spin_lock_irqsave(&phba->hbalock, iflags); 11801 ready = atomic_read(&phba->fabric_iocb_count) == 0 && 11802 !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags); 11803 11804 if (ready) 11805 /* Increment fabric iocb count to hold the position */ 11806 atomic_inc(&phba->fabric_iocb_count); 11807 spin_unlock_irqrestore(&phba->hbalock, iflags); 11808 if (ready) { 11809 iocb->fabric_cmd_cmpl = iocb->cmd_cmpl; 11810 iocb->cmd_cmpl = lpfc_cmpl_fabric_iocb; 11811 iocb->cmd_flag |= LPFC_IO_FABRIC; 11812 11813 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD, 11814 "Fabric sched2: ste:x%x", 11815 iocb->vport->port_state, 0, 0); 11816 11817 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0); 11818 11819 if (ret == IOCB_ERROR) { 11820 iocb->cmd_cmpl = iocb->fabric_cmd_cmpl; 11821 iocb->fabric_cmd_cmpl = NULL; 11822 iocb->cmd_flag &= ~LPFC_IO_FABRIC; 11823 atomic_dec(&phba->fabric_iocb_count); 11824 } 11825 } else { 11826 spin_lock_irqsave(&phba->hbalock, iflags); 11827 list_add_tail(&iocb->list, &phba->fabric_iocb_list); 11828 spin_unlock_irqrestore(&phba->hbalock, iflags); 11829 ret = IOCB_SUCCESS; 11830 } 11831 return ret; 11832 } 11833 11834 /** 11835 * lpfc_fabric_abort_vport - Abort a vport's iocbs from driver fabric iocb list 11836 * @vport: pointer to a virtual N_Port data structure. 11837 * 11838 * This routine aborts all the IOCBs associated with a @vport from the 11839 * driver internal fabric IOCB list. The list contains fabric IOCBs to be 11840 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB 11841 * list, removes each IOCB associated with the @vport off the list, set the 11842 * status field to IOSTAT_LOCAL_REJECT, and invokes the callback function 11843 * associated with the IOCB. 11844 **/ 11845 static void lpfc_fabric_abort_vport(struct lpfc_vport *vport) 11846 { 11847 LIST_HEAD(completions); 11848 struct lpfc_hba *phba = vport->phba; 11849 struct lpfc_iocbq *tmp_iocb, *piocb; 11850 11851 spin_lock_irq(&phba->hbalock); 11852 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list, 11853 list) { 11854 11855 if (piocb->vport != vport) 11856 continue; 11857 11858 list_move_tail(&piocb->list, &completions); 11859 } 11860 spin_unlock_irq(&phba->hbalock); 11861 11862 /* Cancel all the IOCBs from the completions list */ 11863 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, 11864 IOERR_SLI_ABORTED); 11865 } 11866 11867 /** 11868 * lpfc_fabric_abort_nport - Abort a ndlp's iocbs from driver fabric iocb list 11869 * @ndlp: pointer to a node-list data structure. 11870 * 11871 * This routine aborts all the IOCBs associated with an @ndlp from the 11872 * driver internal fabric IOCB list. The list contains fabric IOCBs to be 11873 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB 11874 * list, removes each IOCB associated with the @ndlp off the list, set the 11875 * status field to IOSTAT_LOCAL_REJECT, and invokes the callback function 11876 * associated with the IOCB. 11877 **/ 11878 void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp) 11879 { 11880 LIST_HEAD(completions); 11881 struct lpfc_hba *phba = ndlp->phba; 11882 struct lpfc_iocbq *tmp_iocb, *piocb; 11883 struct lpfc_sli_ring *pring; 11884 11885 pring = lpfc_phba_elsring(phba); 11886 11887 if (unlikely(!pring)) 11888 return; 11889 11890 spin_lock_irq(&phba->hbalock); 11891 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list, 11892 list) { 11893 if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) { 11894 11895 list_move_tail(&piocb->list, &completions); 11896 } 11897 } 11898 spin_unlock_irq(&phba->hbalock); 11899 11900 /* Cancel all the IOCBs from the completions list */ 11901 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, 11902 IOERR_SLI_ABORTED); 11903 } 11904 11905 /** 11906 * lpfc_fabric_abort_hba - Abort all iocbs on driver fabric iocb list 11907 * @phba: pointer to lpfc hba data structure. 11908 * 11909 * This routine aborts all the IOCBs currently on the driver internal 11910 * fabric IOCB list. The list contains fabric IOCBs to be issued to the ELS 11911 * IOCB ring. This function takes the entire IOCB list off the fabric IOCB 11912 * list, removes IOCBs off the list, set the status field to 11913 * IOSTAT_LOCAL_REJECT, and invokes the callback function associated with 11914 * the IOCB. 11915 **/ 11916 void lpfc_fabric_abort_hba(struct lpfc_hba *phba) 11917 { 11918 LIST_HEAD(completions); 11919 11920 spin_lock_irq(&phba->hbalock); 11921 list_splice_init(&phba->fabric_iocb_list, &completions); 11922 spin_unlock_irq(&phba->hbalock); 11923 11924 /* Cancel all the IOCBs from the completions list */ 11925 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, 11926 IOERR_SLI_ABORTED); 11927 } 11928 11929 /** 11930 * lpfc_sli4_vport_delete_els_xri_aborted -Remove all ndlp references for vport 11931 * @vport: pointer to lpfc vport data structure. 11932 * 11933 * This routine is invoked by the vport cleanup for deletions and the cleanup 11934 * for an ndlp on removal. 11935 **/ 11936 void 11937 lpfc_sli4_vport_delete_els_xri_aborted(struct lpfc_vport *vport) 11938 { 11939 struct lpfc_hba *phba = vport->phba; 11940 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL; 11941 struct lpfc_nodelist *ndlp = NULL; 11942 unsigned long iflag = 0; 11943 11944 spin_lock_irqsave(&phba->sli4_hba.sgl_list_lock, iflag); 11945 list_for_each_entry_safe(sglq_entry, sglq_next, 11946 &phba->sli4_hba.lpfc_abts_els_sgl_list, list) { 11947 if (sglq_entry->ndlp && sglq_entry->ndlp->vport == vport) { 11948 lpfc_nlp_put(sglq_entry->ndlp); 11949 ndlp = sglq_entry->ndlp; 11950 sglq_entry->ndlp = NULL; 11951 11952 /* If the xri on the abts_els_sgl list is for the Fport 11953 * node and the vport is unloading, the xri aborted wcqe 11954 * likely isn't coming back. Just release the sgl. 11955 */ 11956 if (test_bit(FC_UNLOADING, &vport->load_flag) && 11957 ndlp->nlp_DID == Fabric_DID) { 11958 list_del(&sglq_entry->list); 11959 sglq_entry->state = SGL_FREED; 11960 list_add_tail(&sglq_entry->list, 11961 &phba->sli4_hba.lpfc_els_sgl_list); 11962 } 11963 } 11964 } 11965 spin_unlock_irqrestore(&phba->sli4_hba.sgl_list_lock, iflag); 11966 return; 11967 } 11968 11969 /** 11970 * lpfc_sli4_els_xri_aborted - Slow-path process of els xri abort 11971 * @phba: pointer to lpfc hba data structure. 11972 * @axri: pointer to the els xri abort wcqe structure. 11973 * 11974 * This routine is invoked by the worker thread to process a SLI4 slow-path 11975 * ELS aborted xri. 11976 **/ 11977 void 11978 lpfc_sli4_els_xri_aborted(struct lpfc_hba *phba, 11979 struct sli4_wcqe_xri_aborted *axri) 11980 { 11981 uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri); 11982 uint16_t rxid = bf_get(lpfc_wcqe_xa_remote_xid, axri); 11983 uint16_t lxri = 0; 11984 11985 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL; 11986 unsigned long iflag = 0; 11987 struct lpfc_nodelist *ndlp; 11988 struct lpfc_sli_ring *pring; 11989 11990 pring = lpfc_phba_elsring(phba); 11991 11992 spin_lock_irqsave(&phba->sli4_hba.sgl_list_lock, iflag); 11993 list_for_each_entry_safe(sglq_entry, sglq_next, 11994 &phba->sli4_hba.lpfc_abts_els_sgl_list, list) { 11995 if (sglq_entry->sli4_xritag == xri) { 11996 list_del(&sglq_entry->list); 11997 ndlp = sglq_entry->ndlp; 11998 sglq_entry->ndlp = NULL; 11999 list_add_tail(&sglq_entry->list, 12000 &phba->sli4_hba.lpfc_els_sgl_list); 12001 sglq_entry->state = SGL_FREED; 12002 spin_unlock_irqrestore(&phba->sli4_hba.sgl_list_lock, 12003 iflag); 12004 12005 if (ndlp) { 12006 lpfc_set_rrq_active(phba, ndlp, 12007 sglq_entry->sli4_lxritag, 12008 rxid, 1); 12009 lpfc_nlp_put(ndlp); 12010 } 12011 12012 /* Check if TXQ queue needs to be serviced */ 12013 if (pring && !list_empty(&pring->txq)) 12014 lpfc_worker_wake_up(phba); 12015 return; 12016 } 12017 } 12018 spin_unlock_irqrestore(&phba->sli4_hba.sgl_list_lock, iflag); 12019 lxri = lpfc_sli4_xri_inrange(phba, xri); 12020 if (lxri == NO_XRI) 12021 return; 12022 12023 spin_lock_irqsave(&phba->hbalock, iflag); 12024 sglq_entry = __lpfc_get_active_sglq(phba, lxri); 12025 if (!sglq_entry || (sglq_entry->sli4_xritag != xri)) { 12026 spin_unlock_irqrestore(&phba->hbalock, iflag); 12027 return; 12028 } 12029 sglq_entry->state = SGL_XRI_ABORTED; 12030 spin_unlock_irqrestore(&phba->hbalock, iflag); 12031 return; 12032 } 12033 12034 /* lpfc_sli_abts_recover_port - Recover a port that failed a BLS_ABORT req. 12035 * @vport: pointer to virtual port object. 12036 * @ndlp: nodelist pointer for the impacted node. 12037 * 12038 * The driver calls this routine in response to an SLI4 XRI ABORT CQE 12039 * or an SLI3 ASYNC_STATUS_CN event from the port. For either event, 12040 * the driver is required to send a LOGO to the remote node before it 12041 * attempts to recover its login to the remote node. 12042 */ 12043 void 12044 lpfc_sli_abts_recover_port(struct lpfc_vport *vport, 12045 struct lpfc_nodelist *ndlp) 12046 { 12047 struct Scsi_Host *shost; 12048 struct lpfc_hba *phba; 12049 unsigned long flags = 0; 12050 12051 shost = lpfc_shost_from_vport(vport); 12052 phba = vport->phba; 12053 if (ndlp->nlp_state != NLP_STE_MAPPED_NODE) { 12054 lpfc_printf_log(phba, KERN_INFO, 12055 LOG_SLI, "3093 No rport recovery needed. " 12056 "rport in state 0x%x\n", ndlp->nlp_state); 12057 return; 12058 } 12059 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, 12060 "3094 Start rport recovery on shost id 0x%x " 12061 "fc_id 0x%06x vpi 0x%x rpi 0x%x state 0x%x " 12062 "flag 0x%lx\n", 12063 shost->host_no, ndlp->nlp_DID, 12064 vport->vpi, ndlp->nlp_rpi, ndlp->nlp_state, 12065 ndlp->nlp_flag); 12066 /* 12067 * The rport is not responding. Remove the FCP-2 flag to prevent 12068 * an ADISC in the follow-up recovery code. 12069 */ 12070 spin_lock_irqsave(&ndlp->lock, flags); 12071 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE; 12072 spin_unlock_irqrestore(&ndlp->lock, flags); 12073 set_bit(NLP_ISSUE_LOGO, &ndlp->nlp_flag); 12074 lpfc_unreg_rpi(vport, ndlp); 12075 } 12076 12077 static void lpfc_init_cs_ctl_bitmap(struct lpfc_vport *vport) 12078 { 12079 bitmap_zero(vport->vmid_priority_range, LPFC_VMID_MAX_PRIORITY_RANGE); 12080 } 12081 12082 static void 12083 lpfc_vmid_set_cs_ctl_range(struct lpfc_vport *vport, u32 min, u32 max) 12084 { 12085 u32 i; 12086 12087 if ((min > max) || (max > LPFC_VMID_MAX_PRIORITY_RANGE)) 12088 return; 12089 12090 for (i = min; i <= max; i++) 12091 set_bit(i, vport->vmid_priority_range); 12092 } 12093 12094 static void lpfc_vmid_put_cs_ctl(struct lpfc_vport *vport, u32 ctcl_vmid) 12095 { 12096 set_bit(ctcl_vmid, vport->vmid_priority_range); 12097 } 12098 12099 u32 lpfc_vmid_get_cs_ctl(struct lpfc_vport *vport) 12100 { 12101 u32 i; 12102 12103 i = find_first_bit(vport->vmid_priority_range, 12104 LPFC_VMID_MAX_PRIORITY_RANGE); 12105 12106 if (i == LPFC_VMID_MAX_PRIORITY_RANGE) 12107 return 0; 12108 12109 clear_bit(i, vport->vmid_priority_range); 12110 return i; 12111 } 12112 12113 #define MAX_PRIORITY_DESC 255 12114 12115 static void 12116 lpfc_cmpl_els_qfpa(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, 12117 struct lpfc_iocbq *rspiocb) 12118 { 12119 struct lpfc_vport *vport = cmdiocb->vport; 12120 struct priority_range_desc *desc; 12121 struct lpfc_dmabuf *prsp = NULL; 12122 struct lpfc_vmid_priority_range *vmid_range = NULL; 12123 u32 *data; 12124 struct lpfc_dmabuf *dmabuf = cmdiocb->cmd_dmabuf; 12125 u32 ulp_status = get_job_ulpstatus(phba, rspiocb); 12126 u32 ulp_word4 = get_job_word4(phba, rspiocb); 12127 u8 *pcmd, max_desc; 12128 u32 len, i; 12129 struct lpfc_nodelist *ndlp = cmdiocb->ndlp; 12130 12131 prsp = list_get_first(&dmabuf->list, struct lpfc_dmabuf, list); 12132 if (!prsp) 12133 goto out; 12134 12135 pcmd = prsp->virt; 12136 data = (u32 *)pcmd; 12137 if (data[0] == ELS_CMD_LS_RJT) { 12138 lpfc_printf_vlog(vport, KERN_WARNING, LOG_SLI, 12139 "3277 QFPA LS_RJT x%x x%x\n", 12140 data[0], data[1]); 12141 goto out; 12142 } 12143 if (ulp_status) { 12144 lpfc_printf_vlog(vport, KERN_ERR, LOG_SLI, 12145 "6529 QFPA failed with status x%x x%x\n", 12146 ulp_status, ulp_word4); 12147 goto out; 12148 } 12149 12150 if (!vport->qfpa_res) { 12151 max_desc = FCELSSIZE / sizeof(*vport->qfpa_res); 12152 vport->qfpa_res = kcalloc(max_desc, sizeof(*vport->qfpa_res), 12153 GFP_KERNEL); 12154 if (!vport->qfpa_res) 12155 goto out; 12156 } 12157 12158 len = *((u32 *)(pcmd + 4)); 12159 len = be32_to_cpu(len); 12160 memcpy(vport->qfpa_res, pcmd, len + 8); 12161 len = len / LPFC_PRIORITY_RANGE_DESC_SIZE; 12162 12163 desc = (struct priority_range_desc *)(pcmd + 8); 12164 vmid_range = vport->vmid_priority.vmid_range; 12165 if (!vmid_range) { 12166 vmid_range = kcalloc(MAX_PRIORITY_DESC, sizeof(*vmid_range), 12167 GFP_KERNEL); 12168 if (!vmid_range) { 12169 kfree(vport->qfpa_res); 12170 goto out; 12171 } 12172 vport->vmid_priority.vmid_range = vmid_range; 12173 } 12174 vport->vmid_priority.num_descriptors = len; 12175 12176 for (i = 0; i < len; i++, vmid_range++, desc++) { 12177 lpfc_printf_vlog(vport, KERN_DEBUG, LOG_ELS, 12178 "6539 vmid values low=%d, high=%d, qos=%d, " 12179 "local ve id=%d\n", desc->lo_range, 12180 desc->hi_range, desc->qos_priority, 12181 desc->local_ve_id); 12182 12183 vmid_range->low = desc->lo_range << 1; 12184 if (desc->local_ve_id == QFPA_ODD_ONLY) 12185 vmid_range->low++; 12186 if (desc->qos_priority) 12187 vport->vmid_flag |= LPFC_VMID_QOS_ENABLED; 12188 vmid_range->qos = desc->qos_priority; 12189 12190 vmid_range->high = desc->hi_range << 1; 12191 if ((desc->local_ve_id == QFPA_ODD_ONLY) || 12192 (desc->local_ve_id == QFPA_EVEN_ODD)) 12193 vmid_range->high++; 12194 } 12195 lpfc_init_cs_ctl_bitmap(vport); 12196 for (i = 0; i < vport->vmid_priority.num_descriptors; i++) { 12197 lpfc_vmid_set_cs_ctl_range(vport, 12198 vport->vmid_priority.vmid_range[i].low, 12199 vport->vmid_priority.vmid_range[i].high); 12200 } 12201 12202 vport->vmid_flag |= LPFC_VMID_QFPA_CMPL; 12203 out: 12204 lpfc_els_free_iocb(phba, cmdiocb); 12205 lpfc_nlp_put(ndlp); 12206 } 12207 12208 int lpfc_issue_els_qfpa(struct lpfc_vport *vport) 12209 { 12210 struct lpfc_hba *phba = vport->phba; 12211 struct lpfc_nodelist *ndlp; 12212 struct lpfc_iocbq *elsiocb; 12213 u8 *pcmd; 12214 int ret; 12215 12216 ndlp = lpfc_findnode_did(phba->pport, Fabric_DID); 12217 if (!ndlp || ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) 12218 return -ENXIO; 12219 12220 elsiocb = lpfc_prep_els_iocb(vport, 1, LPFC_QFPA_SIZE, 2, ndlp, 12221 ndlp->nlp_DID, ELS_CMD_QFPA); 12222 if (!elsiocb) 12223 return -ENOMEM; 12224 12225 pcmd = (u8 *)elsiocb->cmd_dmabuf->virt; 12226 12227 *((u32 *)(pcmd)) = ELS_CMD_QFPA; 12228 pcmd += 4; 12229 12230 elsiocb->cmd_cmpl = lpfc_cmpl_els_qfpa; 12231 12232 elsiocb->ndlp = lpfc_nlp_get(ndlp); 12233 if (!elsiocb->ndlp) { 12234 lpfc_els_free_iocb(vport->phba, elsiocb); 12235 return -ENXIO; 12236 } 12237 12238 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 2); 12239 if (ret != IOCB_SUCCESS) { 12240 lpfc_els_free_iocb(phba, elsiocb); 12241 lpfc_nlp_put(ndlp); 12242 return -EIO; 12243 } 12244 vport->vmid_flag &= ~LPFC_VMID_QOS_ENABLED; 12245 return 0; 12246 } 12247 12248 int 12249 lpfc_vmid_uvem(struct lpfc_vport *vport, 12250 struct lpfc_vmid *vmid, bool instantiated) 12251 { 12252 struct lpfc_vem_id_desc *vem_id_desc; 12253 struct lpfc_nodelist *ndlp; 12254 struct lpfc_iocbq *elsiocb; 12255 struct instantiated_ve_desc *inst_desc; 12256 struct lpfc_vmid_context *vmid_context; 12257 u8 *pcmd; 12258 u32 *len; 12259 int ret = 0; 12260 12261 ndlp = lpfc_findnode_did(vport, Fabric_DID); 12262 if (!ndlp || ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) 12263 return -ENXIO; 12264 12265 vmid_context = kmalloc(sizeof(*vmid_context), GFP_KERNEL); 12266 if (!vmid_context) 12267 return -ENOMEM; 12268 elsiocb = lpfc_prep_els_iocb(vport, 1, LPFC_UVEM_SIZE, 2, 12269 ndlp, Fabric_DID, ELS_CMD_UVEM); 12270 if (!elsiocb) 12271 goto out; 12272 12273 lpfc_printf_vlog(vport, KERN_DEBUG, LOG_ELS, 12274 "3427 Host vmid %s %d\n", 12275 vmid->host_vmid, instantiated); 12276 vmid_context->vmp = vmid; 12277 vmid_context->nlp = ndlp; 12278 vmid_context->instantiated = instantiated; 12279 elsiocb->vmid_tag.vmid_context = vmid_context; 12280 pcmd = (u8 *)elsiocb->cmd_dmabuf->virt; 12281 12282 if (!memchr_inv(vport->lpfc_vmid_host_uuid, 0, 12283 sizeof(vport->lpfc_vmid_host_uuid))) 12284 memcpy(vport->lpfc_vmid_host_uuid, vmid->host_vmid, 12285 sizeof(vport->lpfc_vmid_host_uuid)); 12286 12287 *((u32 *)(pcmd)) = ELS_CMD_UVEM; 12288 len = (u32 *)(pcmd + 4); 12289 *len = cpu_to_be32(LPFC_UVEM_SIZE - 8); 12290 12291 vem_id_desc = (struct lpfc_vem_id_desc *)(pcmd + 8); 12292 vem_id_desc->tag = be32_to_cpu(VEM_ID_DESC_TAG); 12293 vem_id_desc->length = be32_to_cpu(LPFC_UVEM_VEM_ID_DESC_SIZE); 12294 memcpy(vem_id_desc->vem_id, vport->lpfc_vmid_host_uuid, 12295 sizeof(vem_id_desc->vem_id)); 12296 12297 inst_desc = (struct instantiated_ve_desc *)(pcmd + 32); 12298 inst_desc->tag = be32_to_cpu(INSTANTIATED_VE_DESC_TAG); 12299 inst_desc->length = be32_to_cpu(LPFC_UVEM_VE_MAP_DESC_SIZE); 12300 memcpy(inst_desc->global_vem_id, vmid->host_vmid, 12301 sizeof(inst_desc->global_vem_id)); 12302 12303 bf_set(lpfc_instantiated_nport_id, inst_desc, vport->fc_myDID); 12304 bf_set(lpfc_instantiated_local_id, inst_desc, 12305 vmid->un.cs_ctl_vmid); 12306 if (instantiated) { 12307 inst_desc->tag = be32_to_cpu(INSTANTIATED_VE_DESC_TAG); 12308 } else { 12309 inst_desc->tag = be32_to_cpu(DEINSTANTIATED_VE_DESC_TAG); 12310 lpfc_vmid_put_cs_ctl(vport, vmid->un.cs_ctl_vmid); 12311 } 12312 inst_desc->word6 = cpu_to_be32(inst_desc->word6); 12313 12314 elsiocb->cmd_cmpl = lpfc_cmpl_els_uvem; 12315 12316 elsiocb->ndlp = lpfc_nlp_get(ndlp); 12317 if (!elsiocb->ndlp) { 12318 lpfc_els_free_iocb(vport->phba, elsiocb); 12319 goto out; 12320 } 12321 12322 ret = lpfc_sli_issue_iocb(vport->phba, LPFC_ELS_RING, elsiocb, 0); 12323 if (ret != IOCB_SUCCESS) { 12324 lpfc_els_free_iocb(vport->phba, elsiocb); 12325 lpfc_nlp_put(ndlp); 12326 goto out; 12327 } 12328 12329 return 0; 12330 out: 12331 kfree(vmid_context); 12332 return -EIO; 12333 } 12334 12335 static void 12336 lpfc_cmpl_els_uvem(struct lpfc_hba *phba, struct lpfc_iocbq *icmdiocb, 12337 struct lpfc_iocbq *rspiocb) 12338 { 12339 struct lpfc_vport *vport = icmdiocb->vport; 12340 struct lpfc_dmabuf *prsp = NULL; 12341 struct lpfc_vmid_context *vmid_context = 12342 icmdiocb->vmid_tag.vmid_context; 12343 struct lpfc_nodelist *ndlp = icmdiocb->ndlp; 12344 u8 *pcmd; 12345 u32 *data; 12346 u32 ulp_status = get_job_ulpstatus(phba, rspiocb); 12347 u32 ulp_word4 = get_job_word4(phba, rspiocb); 12348 struct lpfc_dmabuf *dmabuf = icmdiocb->cmd_dmabuf; 12349 struct lpfc_vmid *vmid; 12350 12351 vmid = vmid_context->vmp; 12352 if (!ndlp || ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) 12353 ndlp = NULL; 12354 12355 prsp = list_get_first(&dmabuf->list, struct lpfc_dmabuf, list); 12356 if (!prsp) 12357 goto out; 12358 pcmd = prsp->virt; 12359 data = (u32 *)pcmd; 12360 if (data[0] == ELS_CMD_LS_RJT) { 12361 lpfc_printf_vlog(vport, KERN_WARNING, LOG_SLI, 12362 "4532 UVEM LS_RJT %x %x\n", data[0], data[1]); 12363 goto out; 12364 } 12365 if (ulp_status) { 12366 lpfc_printf_vlog(vport, KERN_WARNING, LOG_SLI, 12367 "4533 UVEM error status %x: %x\n", 12368 ulp_status, ulp_word4); 12369 goto out; 12370 } 12371 spin_lock(&phba->hbalock); 12372 /* Set IN USE flag */ 12373 vport->vmid_flag |= LPFC_VMID_IN_USE; 12374 phba->pport->vmid_flag |= LPFC_VMID_IN_USE; 12375 spin_unlock(&phba->hbalock); 12376 12377 if (vmid_context->instantiated) { 12378 write_lock(&vport->vmid_lock); 12379 vmid->flag |= LPFC_VMID_REGISTERED; 12380 vmid->flag &= ~LPFC_VMID_REQ_REGISTER; 12381 write_unlock(&vport->vmid_lock); 12382 } 12383 12384 out: 12385 kfree(vmid_context); 12386 lpfc_els_free_iocb(phba, icmdiocb); 12387 lpfc_nlp_put(ndlp); 12388 } 12389