1 /******************************************************************* 2 * This file is part of the Emulex Linux Device Driver for * 3 * Fibre Channel Host Bus Adapters. * 4 * Copyright (C) 2017-2021 Broadcom. All Rights Reserved. The term * 5 * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. * 6 * Copyright (C) 2004-2016 Emulex. All rights reserved. * 7 * EMULEX and SLI are trademarks of Emulex. * 8 * www.broadcom.com * 9 * * 10 * This program is free software; you can redistribute it and/or * 11 * modify it under the terms of version 2 of the GNU General * 12 * Public License as published by the Free Software Foundation. * 13 * This program is distributed in the hope that it will be useful. * 14 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND * 15 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, * 16 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE * 17 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD * 18 * TO BE LEGALLY INVALID. See the GNU General Public License for * 19 * more details, a copy of which can be found in the file COPYING * 20 * included with this package. * 21 *******************************************************************/ 22 23 /* 24 * Fibre Channel SCSI LAN Device Driver CT support: FC Generic Services FC-GS 25 */ 26 27 #include <linux/blkdev.h> 28 #include <linux/pci.h> 29 #include <linux/interrupt.h> 30 #include <linux/slab.h> 31 #include <linux/utsname.h> 32 33 #include <scsi/scsi.h> 34 #include <scsi/scsi_device.h> 35 #include <scsi/scsi_host.h> 36 #include <scsi/scsi_transport_fc.h> 37 #include <scsi/fc/fc_fs.h> 38 39 #include "lpfc_hw4.h" 40 #include "lpfc_hw.h" 41 #include "lpfc_sli.h" 42 #include "lpfc_sli4.h" 43 #include "lpfc_nl.h" 44 #include "lpfc_disc.h" 45 #include "lpfc.h" 46 #include "lpfc_scsi.h" 47 #include "lpfc_logmsg.h" 48 #include "lpfc_crtn.h" 49 #include "lpfc_version.h" 50 #include "lpfc_vport.h" 51 #include "lpfc_debugfs.h" 52 53 /* FDMI Port Speed definitions - FC-GS-7 */ 54 #define HBA_PORTSPEED_1GFC 0x00000001 /* 1G FC */ 55 #define HBA_PORTSPEED_2GFC 0x00000002 /* 2G FC */ 56 #define HBA_PORTSPEED_4GFC 0x00000008 /* 4G FC */ 57 #define HBA_PORTSPEED_10GFC 0x00000004 /* 10G FC */ 58 #define HBA_PORTSPEED_8GFC 0x00000010 /* 8G FC */ 59 #define HBA_PORTSPEED_16GFC 0x00000020 /* 16G FC */ 60 #define HBA_PORTSPEED_32GFC 0x00000040 /* 32G FC */ 61 #define HBA_PORTSPEED_20GFC 0x00000080 /* 20G FC */ 62 #define HBA_PORTSPEED_40GFC 0x00000100 /* 40G FC */ 63 #define HBA_PORTSPEED_128GFC 0x00000200 /* 128G FC */ 64 #define HBA_PORTSPEED_64GFC 0x00000400 /* 64G FC */ 65 #define HBA_PORTSPEED_256GFC 0x00000800 /* 256G FC */ 66 #define HBA_PORTSPEED_UNKNOWN 0x00008000 /* Unknown */ 67 #define HBA_PORTSPEED_10GE 0x00010000 /* 10G E */ 68 #define HBA_PORTSPEED_40GE 0x00020000 /* 40G E */ 69 #define HBA_PORTSPEED_100GE 0x00040000 /* 100G E */ 70 #define HBA_PORTSPEED_25GE 0x00080000 /* 25G E */ 71 #define HBA_PORTSPEED_50GE 0x00100000 /* 50G E */ 72 #define HBA_PORTSPEED_400GE 0x00200000 /* 400G E */ 73 74 #define FOURBYTES 4 75 76 77 static char *lpfc_release_version = LPFC_DRIVER_VERSION; 78 static void 79 lpfc_cmpl_ct_cmd_vmid(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, 80 struct lpfc_iocbq *rspiocb); 81 82 static void 83 lpfc_ct_ignore_hbq_buffer(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq, 84 struct lpfc_dmabuf *mp, uint32_t size) 85 { 86 if (!mp) { 87 lpfc_printf_log(phba, KERN_INFO, LOG_ELS, 88 "0146 Ignoring unsolicited CT No HBQ " 89 "status = x%x\n", 90 piocbq->iocb.ulpStatus); 91 } 92 lpfc_printf_log(phba, KERN_INFO, LOG_ELS, 93 "0145 Ignoring unsolicted CT HBQ Size:%d " 94 "status = x%x\n", 95 size, piocbq->iocb.ulpStatus); 96 } 97 98 static void 99 lpfc_ct_unsol_buffer(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq, 100 struct lpfc_dmabuf *mp, uint32_t size) 101 { 102 lpfc_ct_ignore_hbq_buffer(phba, piocbq, mp, size); 103 } 104 105 /** 106 * lpfc_ct_unsol_cmpl : Completion callback function for unsol ct commands 107 * @phba : pointer to lpfc hba data structure. 108 * @cmdiocb : pointer to lpfc command iocb data structure. 109 * @rspiocb : pointer to lpfc response iocb data structure. 110 * 111 * This routine is the callback function for issuing unsol ct reject command. 112 * The memory allocated in the reject command path is freed up here. 113 **/ 114 static void 115 lpfc_ct_unsol_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, 116 struct lpfc_iocbq *rspiocb) 117 { 118 struct lpfc_nodelist *ndlp; 119 struct lpfc_dmabuf *mp, *bmp; 120 121 ndlp = (struct lpfc_nodelist *)cmdiocb->context1; 122 if (ndlp) 123 lpfc_nlp_put(ndlp); 124 125 mp = cmdiocb->context2; 126 bmp = cmdiocb->context3; 127 if (mp) { 128 lpfc_mbuf_free(phba, mp->virt, mp->phys); 129 kfree(mp); 130 cmdiocb->context2 = NULL; 131 } 132 133 if (bmp) { 134 lpfc_mbuf_free(phba, bmp->virt, bmp->phys); 135 kfree(bmp); 136 cmdiocb->context3 = NULL; 137 } 138 139 lpfc_sli_release_iocbq(phba, cmdiocb); 140 } 141 142 /** 143 * lpfc_ct_reject_event - Issue reject for unhandled CT MIB commands 144 * @ndlp: pointer to a node-list data structure. 145 * @ct_req: pointer to the CT request data structure. 146 * @rx_id: rx_id of the received UNSOL CT command 147 * @ox_id: ox_id of the UNSOL CT command 148 * 149 * This routine is invoked by the lpfc_ct_handle_mibreq routine for sending 150 * a reject response. Reject response is sent for the unhandled commands. 151 **/ 152 static void 153 lpfc_ct_reject_event(struct lpfc_nodelist *ndlp, 154 struct lpfc_sli_ct_request *ct_req, 155 u16 rx_id, u16 ox_id) 156 { 157 struct lpfc_vport *vport = ndlp->vport; 158 struct lpfc_hba *phba = vport->phba; 159 struct lpfc_sli_ct_request *ct_rsp; 160 struct lpfc_iocbq *cmdiocbq = NULL; 161 struct lpfc_dmabuf *bmp = NULL; 162 struct lpfc_dmabuf *mp = NULL; 163 struct ulp_bde64 *bpl; 164 IOCB_t *icmd; 165 u8 rc = 0; 166 167 /* fill in BDEs for command */ 168 mp = kmalloc(sizeof(*mp), GFP_KERNEL); 169 if (!mp) { 170 rc = 1; 171 goto ct_exit; 172 } 173 174 mp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &mp->phys); 175 if (!mp->virt) { 176 rc = 2; 177 goto ct_free_mp; 178 } 179 180 /* Allocate buffer for Buffer ptr list */ 181 bmp = kmalloc(sizeof(*bmp), GFP_KERNEL); 182 if (!bmp) { 183 rc = 3; 184 goto ct_free_mpvirt; 185 } 186 187 bmp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &bmp->phys); 188 if (!bmp->virt) { 189 rc = 4; 190 goto ct_free_bmp; 191 } 192 193 INIT_LIST_HEAD(&mp->list); 194 INIT_LIST_HEAD(&bmp->list); 195 196 bpl = (struct ulp_bde64 *)bmp->virt; 197 memset(bpl, 0, sizeof(struct ulp_bde64)); 198 bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys)); 199 bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys)); 200 bpl->tus.f.bdeFlags = BUFF_TYPE_BLP_64; 201 bpl->tus.f.bdeSize = (LPFC_CT_PREAMBLE - 4); 202 bpl->tus.w = le32_to_cpu(bpl->tus.w); 203 204 ct_rsp = (struct lpfc_sli_ct_request *)mp->virt; 205 memset(ct_rsp, 0, sizeof(struct lpfc_sli_ct_request)); 206 207 ct_rsp->RevisionId.bits.Revision = SLI_CT_REVISION; 208 ct_rsp->RevisionId.bits.InId = 0; 209 ct_rsp->FsType = ct_req->FsType; 210 ct_rsp->FsSubType = ct_req->FsSubType; 211 ct_rsp->CommandResponse.bits.Size = 0; 212 ct_rsp->CommandResponse.bits.CmdRsp = 213 cpu_to_be16(SLI_CT_RESPONSE_FS_RJT); 214 ct_rsp->ReasonCode = SLI_CT_REQ_NOT_SUPPORTED; 215 ct_rsp->Explanation = SLI_CT_NO_ADDITIONAL_EXPL; 216 217 cmdiocbq = lpfc_sli_get_iocbq(phba); 218 if (!cmdiocbq) { 219 rc = 5; 220 goto ct_free_bmpvirt; 221 } 222 223 icmd = &cmdiocbq->iocb; 224 icmd->un.genreq64.bdl.ulpIoTag32 = 0; 225 icmd->un.genreq64.bdl.addrHigh = putPaddrHigh(bmp->phys); 226 icmd->un.genreq64.bdl.addrLow = putPaddrLow(bmp->phys); 227 icmd->un.genreq64.bdl.bdeFlags = BUFF_TYPE_BLP_64; 228 icmd->un.genreq64.bdl.bdeSize = sizeof(struct ulp_bde64); 229 icmd->un.genreq64.w5.hcsw.Fctl = (LS | LA); 230 icmd->un.genreq64.w5.hcsw.Dfctl = 0; 231 icmd->un.genreq64.w5.hcsw.Rctl = FC_RCTL_DD_SOL_CTL; 232 icmd->un.genreq64.w5.hcsw.Type = FC_TYPE_CT; 233 icmd->ulpCommand = CMD_XMIT_SEQUENCE64_CX; 234 icmd->ulpBdeCount = 1; 235 icmd->ulpLe = 1; 236 icmd->ulpClass = CLASS3; 237 238 /* Save for completion so we can release these resources */ 239 cmdiocbq->context1 = lpfc_nlp_get(ndlp); 240 cmdiocbq->context2 = (uint8_t *)mp; 241 cmdiocbq->context3 = (uint8_t *)bmp; 242 cmdiocbq->iocb_cmpl = lpfc_ct_unsol_cmpl; 243 icmd->ulpContext = rx_id; /* Xri / rx_id */ 244 icmd->unsli3.rcvsli3.ox_id = ox_id; 245 icmd->un.ulpWord[3] = 246 phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]; 247 icmd->ulpTimeout = (3 * phba->fc_ratov); 248 249 cmdiocbq->retry = 0; 250 cmdiocbq->vport = vport; 251 cmdiocbq->context_un.ndlp = NULL; 252 cmdiocbq->drvrTimeout = icmd->ulpTimeout + LPFC_DRVR_TIMEOUT; 253 254 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, cmdiocbq, 0); 255 if (!rc) 256 return; 257 258 rc = 6; 259 lpfc_nlp_put(ndlp); 260 lpfc_sli_release_iocbq(phba, cmdiocbq); 261 ct_free_bmpvirt: 262 lpfc_mbuf_free(phba, bmp->virt, bmp->phys); 263 ct_free_bmp: 264 kfree(bmp); 265 ct_free_mpvirt: 266 lpfc_mbuf_free(phba, mp->virt, mp->phys); 267 ct_free_mp: 268 kfree(mp); 269 ct_exit: 270 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, 271 "6440 Unsol CT: Rsp err %d Data: x%x\n", 272 rc, vport->fc_flag); 273 } 274 275 /** 276 * lpfc_ct_handle_mibreq - Process an unsolicited CT MIB request data buffer 277 * @phba: pointer to lpfc hba data structure. 278 * @ctiocbq: pointer to lpfc CT command iocb data structure. 279 * 280 * This routine is used for processing the IOCB associated with a unsolicited 281 * CT MIB request. It first determines whether there is an existing ndlp that 282 * matches the DID from the unsolicited IOCB. If not, it will return. 283 **/ 284 static void 285 lpfc_ct_handle_mibreq(struct lpfc_hba *phba, struct lpfc_iocbq *ctiocbq) 286 { 287 struct lpfc_sli_ct_request *ct_req; 288 struct lpfc_nodelist *ndlp = NULL; 289 struct lpfc_vport *vport = NULL; 290 IOCB_t *icmd = &ctiocbq->iocb; 291 u32 mi_cmd, vpi; 292 u32 did = 0; 293 294 vpi = ctiocbq->iocb.unsli3.rcvsli3.vpi; 295 vport = lpfc_find_vport_by_vpid(phba, vpi); 296 if (!vport) { 297 lpfc_printf_log(phba, KERN_INFO, LOG_ELS, 298 "6437 Unsol CT: VPORT NULL vpi : x%x\n", 299 vpi); 300 return; 301 } 302 303 did = ctiocbq->iocb.un.rcvels.remoteID; 304 if (icmd->ulpStatus) { 305 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, 306 "6438 Unsol CT: status:x%x/x%x did : x%x\n", 307 icmd->ulpStatus, icmd->un.ulpWord[4], did); 308 return; 309 } 310 311 /* Ignore traffic received during vport shutdown */ 312 if (vport->fc_flag & FC_UNLOADING) 313 return; 314 315 ndlp = lpfc_findnode_did(vport, did); 316 if (!ndlp) { 317 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, 318 "6439 Unsol CT: NDLP Not Found for DID : x%x", 319 did); 320 return; 321 } 322 323 ct_req = ((struct lpfc_sli_ct_request *) 324 (((struct lpfc_dmabuf *)ctiocbq->context2)->virt)); 325 326 mi_cmd = ct_req->CommandResponse.bits.CmdRsp; 327 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, 328 "6442 : MI Cmd : x%x Not Supported\n", mi_cmd); 329 lpfc_ct_reject_event(ndlp, ct_req, 330 ctiocbq->iocb.ulpContext, 331 ctiocbq->iocb.unsli3.rcvsli3.ox_id); 332 } 333 334 /** 335 * lpfc_ct_unsol_event - Process an unsolicited event from a ct sli ring 336 * @phba: pointer to lpfc hba data structure. 337 * @pring: pointer to a SLI ring. 338 * @ctiocbq: pointer to lpfc ct iocb data structure. 339 * 340 * This routine is used to process an unsolicited event received from a SLI 341 * (Service Level Interface) ring. The actual processing of the data buffer 342 * associated with the unsolicited event is done by invoking appropriate routine 343 * after properly set up the iocb buffer from the SLI ring on which the 344 * unsolicited event was received. 345 **/ 346 void 347 lpfc_ct_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, 348 struct lpfc_iocbq *ctiocbq) 349 { 350 struct lpfc_dmabuf *mp = NULL; 351 IOCB_t *icmd = &ctiocbq->iocb; 352 int i; 353 struct lpfc_iocbq *iocbq; 354 dma_addr_t dma_addr; 355 uint32_t size; 356 struct list_head head; 357 struct lpfc_sli_ct_request *ct_req; 358 struct lpfc_dmabuf *bdeBuf1 = ctiocbq->context2; 359 struct lpfc_dmabuf *bdeBuf2 = ctiocbq->context3; 360 361 ctiocbq->context1 = NULL; 362 ctiocbq->context2 = NULL; 363 ctiocbq->context3 = NULL; 364 365 if (unlikely(icmd->ulpStatus == IOSTAT_NEED_BUFFER)) { 366 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ); 367 } else if ((icmd->ulpStatus == IOSTAT_LOCAL_REJECT) && 368 ((icmd->un.ulpWord[4] & IOERR_PARAM_MASK) == 369 IOERR_RCV_BUFFER_WAITING)) { 370 /* Not enough posted buffers; Try posting more buffers */ 371 phba->fc_stat.NoRcvBuf++; 372 if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) 373 lpfc_post_buffer(phba, pring, 2); 374 return; 375 } 376 377 /* If there are no BDEs associated 378 * with this IOCB, there is nothing to do. 379 */ 380 if (icmd->ulpBdeCount == 0) 381 return; 382 383 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) { 384 ctiocbq->context2 = bdeBuf1; 385 if (icmd->ulpBdeCount == 2) 386 ctiocbq->context3 = bdeBuf2; 387 } else { 388 dma_addr = getPaddr(icmd->un.cont64[0].addrHigh, 389 icmd->un.cont64[0].addrLow); 390 ctiocbq->context2 = lpfc_sli_ringpostbuf_get(phba, pring, 391 dma_addr); 392 if (icmd->ulpBdeCount == 2) { 393 dma_addr = getPaddr(icmd->un.cont64[1].addrHigh, 394 icmd->un.cont64[1].addrLow); 395 ctiocbq->context3 = lpfc_sli_ringpostbuf_get(phba, 396 pring, 397 dma_addr); 398 } 399 } 400 401 ct_req = ((struct lpfc_sli_ct_request *) 402 (((struct lpfc_dmabuf *)ctiocbq->context2)->virt)); 403 404 if (ct_req->FsType == SLI_CT_MANAGEMENT_SERVICE && 405 ct_req->FsSubType == SLI_CT_MIB_Subtypes) { 406 lpfc_ct_handle_mibreq(phba, ctiocbq); 407 } else { 408 if (!lpfc_bsg_ct_unsol_event(phba, pring, ctiocbq)) 409 return; 410 } 411 412 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) { 413 INIT_LIST_HEAD(&head); 414 list_add_tail(&head, &ctiocbq->list); 415 list_for_each_entry(iocbq, &head, list) { 416 icmd = &iocbq->iocb; 417 if (icmd->ulpBdeCount == 0) 418 continue; 419 bdeBuf1 = iocbq->context2; 420 iocbq->context2 = NULL; 421 size = icmd->un.cont64[0].tus.f.bdeSize; 422 lpfc_ct_unsol_buffer(phba, ctiocbq, bdeBuf1, size); 423 lpfc_in_buf_free(phba, bdeBuf1); 424 if (icmd->ulpBdeCount == 2) { 425 bdeBuf2 = iocbq->context3; 426 iocbq->context3 = NULL; 427 size = icmd->unsli3.rcvsli3.bde2.tus.f.bdeSize; 428 lpfc_ct_unsol_buffer(phba, ctiocbq, bdeBuf2, 429 size); 430 lpfc_in_buf_free(phba, bdeBuf2); 431 } 432 } 433 list_del(&head); 434 } else { 435 INIT_LIST_HEAD(&head); 436 list_add_tail(&head, &ctiocbq->list); 437 list_for_each_entry(iocbq, &head, list) { 438 icmd = &iocbq->iocb; 439 if (icmd->ulpBdeCount == 0) 440 lpfc_ct_unsol_buffer(phba, iocbq, NULL, 0); 441 for (i = 0; i < icmd->ulpBdeCount; i++) { 442 dma_addr = getPaddr(icmd->un.cont64[i].addrHigh, 443 icmd->un.cont64[i].addrLow); 444 mp = lpfc_sli_ringpostbuf_get(phba, pring, 445 dma_addr); 446 size = icmd->un.cont64[i].tus.f.bdeSize; 447 lpfc_ct_unsol_buffer(phba, iocbq, mp, size); 448 lpfc_in_buf_free(phba, mp); 449 } 450 lpfc_post_buffer(phba, pring, i); 451 } 452 list_del(&head); 453 } 454 } 455 456 /** 457 * lpfc_ct_handle_unsol_abort - ct upper level protocol abort handler 458 * @phba: Pointer to HBA context object. 459 * @dmabuf: pointer to a dmabuf that describes the FC sequence 460 * 461 * This function serves as the upper level protocol abort handler for CT 462 * protocol. 463 * 464 * Return 1 if abort has been handled, 0 otherwise. 465 **/ 466 int 467 lpfc_ct_handle_unsol_abort(struct lpfc_hba *phba, struct hbq_dmabuf *dmabuf) 468 { 469 int handled; 470 471 /* CT upper level goes through BSG */ 472 handled = lpfc_bsg_ct_unsol_abort(phba, dmabuf); 473 474 return handled; 475 } 476 477 static void 478 lpfc_free_ct_rsp(struct lpfc_hba *phba, struct lpfc_dmabuf *mlist) 479 { 480 struct lpfc_dmabuf *mlast, *next_mlast; 481 482 list_for_each_entry_safe(mlast, next_mlast, &mlist->list, list) { 483 lpfc_mbuf_free(phba, mlast->virt, mlast->phys); 484 list_del(&mlast->list); 485 kfree(mlast); 486 } 487 lpfc_mbuf_free(phba, mlist->virt, mlist->phys); 488 kfree(mlist); 489 return; 490 } 491 492 static struct lpfc_dmabuf * 493 lpfc_alloc_ct_rsp(struct lpfc_hba *phba, int cmdcode, struct ulp_bde64 *bpl, 494 uint32_t size, int *entries) 495 { 496 struct lpfc_dmabuf *mlist = NULL; 497 struct lpfc_dmabuf *mp; 498 int cnt, i = 0; 499 500 /* We get chunks of FCELSSIZE */ 501 cnt = size > FCELSSIZE ? FCELSSIZE: size; 502 503 while (size) { 504 /* Allocate buffer for rsp payload */ 505 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); 506 if (!mp) { 507 if (mlist) 508 lpfc_free_ct_rsp(phba, mlist); 509 return NULL; 510 } 511 512 INIT_LIST_HEAD(&mp->list); 513 514 if (cmdcode == be16_to_cpu(SLI_CTNS_GID_FT) || 515 cmdcode == be16_to_cpu(SLI_CTNS_GFF_ID)) 516 mp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(mp->phys)); 517 else 518 mp->virt = lpfc_mbuf_alloc(phba, 0, &(mp->phys)); 519 520 if (!mp->virt) { 521 kfree(mp); 522 if (mlist) 523 lpfc_free_ct_rsp(phba, mlist); 524 return NULL; 525 } 526 527 /* Queue it to a linked list */ 528 if (!mlist) 529 mlist = mp; 530 else 531 list_add_tail(&mp->list, &mlist->list); 532 533 bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64I; 534 /* build buffer ptr list for IOCB */ 535 bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys) ); 536 bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys) ); 537 bpl->tus.f.bdeSize = (uint16_t) cnt; 538 bpl->tus.w = le32_to_cpu(bpl->tus.w); 539 bpl++; 540 541 i++; 542 size -= cnt; 543 } 544 545 *entries = i; 546 return mlist; 547 } 548 549 int 550 lpfc_ct_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *ctiocb) 551 { 552 struct lpfc_dmabuf *buf_ptr; 553 554 /* I/O job is complete so context is now invalid*/ 555 ctiocb->context_un.ndlp = NULL; 556 if (ctiocb->context1) { 557 buf_ptr = (struct lpfc_dmabuf *) ctiocb->context1; 558 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); 559 kfree(buf_ptr); 560 ctiocb->context1 = NULL; 561 } 562 if (ctiocb->context2) { 563 lpfc_free_ct_rsp(phba, (struct lpfc_dmabuf *) ctiocb->context2); 564 ctiocb->context2 = NULL; 565 } 566 567 if (ctiocb->context3) { 568 buf_ptr = (struct lpfc_dmabuf *) ctiocb->context3; 569 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); 570 kfree(buf_ptr); 571 ctiocb->context3 = NULL; 572 } 573 lpfc_sli_release_iocbq(phba, ctiocb); 574 return 0; 575 } 576 577 /* 578 * lpfc_gen_req - Build and issue a GEN_REQUEST command to the SLI Layer 579 * @vport: pointer to a host virtual N_Port data structure. 580 * @bmp: Pointer to BPL for SLI command 581 * @inp: Pointer to data buffer for response data. 582 * @outp: Pointer to data buffer that hold the CT command. 583 * @cmpl: completion routine to call when command completes 584 * @ndlp: Destination NPort nodelist entry 585 * 586 * This function as the final part for issuing a CT command. 587 */ 588 static int 589 lpfc_gen_req(struct lpfc_vport *vport, struct lpfc_dmabuf *bmp, 590 struct lpfc_dmabuf *inp, struct lpfc_dmabuf *outp, 591 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *, 592 struct lpfc_iocbq *), 593 struct lpfc_nodelist *ndlp, uint32_t event_tag, uint32_t num_entry, 594 uint32_t tmo, uint8_t retry) 595 { 596 struct lpfc_hba *phba = vport->phba; 597 IOCB_t *icmd; 598 struct lpfc_iocbq *geniocb; 599 int rc; 600 601 /* Allocate buffer for command iocb */ 602 geniocb = lpfc_sli_get_iocbq(phba); 603 604 if (geniocb == NULL) 605 return 1; 606 607 icmd = &geniocb->iocb; 608 icmd->un.genreq64.bdl.ulpIoTag32 = 0; 609 icmd->un.genreq64.bdl.addrHigh = putPaddrHigh(bmp->phys); 610 icmd->un.genreq64.bdl.addrLow = putPaddrLow(bmp->phys); 611 icmd->un.genreq64.bdl.bdeFlags = BUFF_TYPE_BLP_64; 612 icmd->un.genreq64.bdl.bdeSize = (num_entry * sizeof(struct ulp_bde64)); 613 614 geniocb->context3 = (uint8_t *) bmp; 615 616 /* Save for completion so we can release these resources */ 617 geniocb->context1 = (uint8_t *) inp; 618 geniocb->context2 = (uint8_t *) outp; 619 620 geniocb->event_tag = event_tag; 621 622 /* Fill in payload, bp points to frame payload */ 623 icmd->ulpCommand = CMD_GEN_REQUEST64_CR; 624 625 /* Fill in rest of iocb */ 626 icmd->un.genreq64.w5.hcsw.Fctl = (SI | LA); 627 icmd->un.genreq64.w5.hcsw.Dfctl = 0; 628 icmd->un.genreq64.w5.hcsw.Rctl = FC_RCTL_DD_UNSOL_CTL; 629 icmd->un.genreq64.w5.hcsw.Type = FC_TYPE_CT; 630 631 if (!tmo) { 632 /* FC spec states we need 3 * ratov for CT requests */ 633 tmo = (3 * phba->fc_ratov); 634 } 635 icmd->ulpTimeout = tmo; 636 icmd->ulpBdeCount = 1; 637 icmd->ulpLe = 1; 638 icmd->ulpClass = CLASS3; 639 icmd->ulpContext = ndlp->nlp_rpi; 640 if (phba->sli_rev == LPFC_SLI_REV4) 641 icmd->ulpContext = phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]; 642 643 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) { 644 /* For GEN_REQUEST64_CR, use the RPI */ 645 icmd->ulpCt_h = 0; 646 icmd->ulpCt_l = 0; 647 } 648 649 /* Issue GEN REQ IOCB for NPORT <did> */ 650 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, 651 "0119 Issue GEN REQ IOCB to NPORT x%x " 652 "Data: x%x x%x\n", 653 ndlp->nlp_DID, icmd->ulpIoTag, 654 vport->port_state); 655 geniocb->iocb_cmpl = cmpl; 656 geniocb->drvrTimeout = icmd->ulpTimeout + LPFC_DRVR_TIMEOUT; 657 geniocb->vport = vport; 658 geniocb->retry = retry; 659 geniocb->context_un.ndlp = lpfc_nlp_get(ndlp); 660 if (!geniocb->context_un.ndlp) 661 goto out; 662 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, geniocb, 0); 663 664 if (rc == IOCB_ERROR) { 665 geniocb->context_un.ndlp = NULL; 666 lpfc_nlp_put(ndlp); 667 goto out; 668 } 669 670 return 0; 671 out: 672 lpfc_sli_release_iocbq(phba, geniocb); 673 return 1; 674 } 675 676 /* 677 * lpfc_ct_cmd - Build and issue a CT command 678 * @vport: pointer to a host virtual N_Port data structure. 679 * @inmp: Pointer to data buffer for response data. 680 * @bmp: Pointer to BPL for SLI command 681 * @ndlp: Destination NPort nodelist entry 682 * @cmpl: completion routine to call when command completes 683 * 684 * This function is called for issuing a CT command. 685 */ 686 static int 687 lpfc_ct_cmd(struct lpfc_vport *vport, struct lpfc_dmabuf *inmp, 688 struct lpfc_dmabuf *bmp, struct lpfc_nodelist *ndlp, 689 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *, 690 struct lpfc_iocbq *), 691 uint32_t rsp_size, uint8_t retry) 692 { 693 struct lpfc_hba *phba = vport->phba; 694 struct ulp_bde64 *bpl = (struct ulp_bde64 *) bmp->virt; 695 struct lpfc_dmabuf *outmp; 696 int cnt = 0, status; 697 int cmdcode = ((struct lpfc_sli_ct_request *) inmp->virt)-> 698 CommandResponse.bits.CmdRsp; 699 700 bpl++; /* Skip past ct request */ 701 702 /* Put buffer(s) for ct rsp in bpl */ 703 outmp = lpfc_alloc_ct_rsp(phba, cmdcode, bpl, rsp_size, &cnt); 704 if (!outmp) 705 return -ENOMEM; 706 /* 707 * Form the CT IOCB. The total number of BDEs in this IOCB 708 * is the single command plus response count from 709 * lpfc_alloc_ct_rsp. 710 */ 711 cnt += 1; 712 status = lpfc_gen_req(vport, bmp, inmp, outmp, cmpl, ndlp, 713 phba->fc_eventTag, cnt, 0, retry); 714 if (status) { 715 lpfc_free_ct_rsp(phba, outmp); 716 return -ENOMEM; 717 } 718 return 0; 719 } 720 721 struct lpfc_vport * 722 lpfc_find_vport_by_did(struct lpfc_hba *phba, uint32_t did) { 723 struct lpfc_vport *vport_curr; 724 unsigned long flags; 725 726 spin_lock_irqsave(&phba->port_list_lock, flags); 727 list_for_each_entry(vport_curr, &phba->port_list, listentry) { 728 if ((vport_curr->fc_myDID) && (vport_curr->fc_myDID == did)) { 729 spin_unlock_irqrestore(&phba->port_list_lock, flags); 730 return vport_curr; 731 } 732 } 733 spin_unlock_irqrestore(&phba->port_list_lock, flags); 734 return NULL; 735 } 736 737 static void 738 lpfc_prep_node_fc4type(struct lpfc_vport *vport, uint32_t Did, uint8_t fc4_type) 739 { 740 struct lpfc_nodelist *ndlp; 741 742 if ((vport->port_type != LPFC_NPIV_PORT) || 743 !(vport->ct_flags & FC_CT_RFF_ID) || !vport->cfg_restrict_login) { 744 745 ndlp = lpfc_setup_disc_node(vport, Did); 746 747 if (ndlp) { 748 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT, 749 "Parse GID_FTrsp: did:x%x flg:x%x x%x", 750 Did, ndlp->nlp_flag, vport->fc_flag); 751 752 /* By default, the driver expects to support FCP FC4 */ 753 if (fc4_type == FC_TYPE_FCP) 754 ndlp->nlp_fc4_type |= NLP_FC4_FCP; 755 756 if (fc4_type == FC_TYPE_NVME) 757 ndlp->nlp_fc4_type |= NLP_FC4_NVME; 758 759 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, 760 "0238 Process x%06x NameServer Rsp " 761 "Data: x%x x%x x%x x%x x%x\n", Did, 762 ndlp->nlp_flag, ndlp->nlp_fc4_type, 763 ndlp->nlp_state, vport->fc_flag, 764 vport->fc_rscn_id_cnt); 765 766 /* if ndlp needs to be discovered and prior 767 * state of ndlp hit devloss, change state to 768 * allow rediscovery. 769 */ 770 if (ndlp->nlp_flag & NLP_NPR_2B_DISC && 771 ndlp->nlp_state == NLP_STE_UNUSED_NODE) { 772 lpfc_nlp_set_state(vport, ndlp, 773 NLP_STE_NPR_NODE); 774 } 775 } else { 776 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT, 777 "Skip1 GID_FTrsp: did:x%x flg:x%x cnt:%d", 778 Did, vport->fc_flag, vport->fc_rscn_id_cnt); 779 780 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, 781 "0239 Skip x%06x NameServer Rsp " 782 "Data: x%x x%x x%px\n", 783 Did, vport->fc_flag, 784 vport->fc_rscn_id_cnt, ndlp); 785 } 786 } else { 787 if (!(vport->fc_flag & FC_RSCN_MODE) || 788 lpfc_rscn_payload_check(vport, Did)) { 789 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT, 790 "Query GID_FTrsp: did:x%x flg:x%x cnt:%d", 791 Did, vport->fc_flag, vport->fc_rscn_id_cnt); 792 793 /* 794 * This NPortID was previously a FCP/NVMe target, 795 * Don't even bother to send GFF_ID. 796 */ 797 ndlp = lpfc_findnode_did(vport, Did); 798 if (ndlp && 799 (ndlp->nlp_type & 800 (NLP_FCP_TARGET | NLP_NVME_TARGET))) { 801 if (fc4_type == FC_TYPE_FCP) 802 ndlp->nlp_fc4_type |= NLP_FC4_FCP; 803 if (fc4_type == FC_TYPE_NVME) 804 ndlp->nlp_fc4_type |= NLP_FC4_NVME; 805 lpfc_setup_disc_node(vport, Did); 806 } else if (lpfc_ns_cmd(vport, SLI_CTNS_GFF_ID, 807 0, Did) == 0) 808 vport->num_disc_nodes++; 809 else 810 lpfc_setup_disc_node(vport, Did); 811 } else { 812 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT, 813 "Skip2 GID_FTrsp: did:x%x flg:x%x cnt:%d", 814 Did, vport->fc_flag, vport->fc_rscn_id_cnt); 815 816 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, 817 "0245 Skip x%06x NameServer Rsp " 818 "Data: x%x x%x\n", Did, 819 vport->fc_flag, 820 vport->fc_rscn_id_cnt); 821 } 822 } 823 } 824 825 static void 826 lpfc_ns_rsp_audit_did(struct lpfc_vport *vport, uint32_t Did, uint8_t fc4_type) 827 { 828 struct lpfc_hba *phba = vport->phba; 829 struct lpfc_nodelist *ndlp = NULL; 830 char *str; 831 832 if (phba->cfg_ns_query == LPFC_NS_QUERY_GID_FT) 833 str = "GID_FT"; 834 else 835 str = "GID_PT"; 836 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, 837 "6430 Process %s rsp for %08x type %x %s %s\n", 838 str, Did, fc4_type, 839 (fc4_type == FC_TYPE_FCP) ? "FCP" : " ", 840 (fc4_type == FC_TYPE_NVME) ? "NVME" : " "); 841 /* 842 * To conserve rpi's, filter out addresses for other 843 * vports on the same physical HBAs. 844 */ 845 if (Did != vport->fc_myDID && 846 (!lpfc_find_vport_by_did(phba, Did) || 847 vport->cfg_peer_port_login)) { 848 if (!phba->nvmet_support) { 849 /* FCPI/NVMEI path. Process Did */ 850 lpfc_prep_node_fc4type(vport, Did, fc4_type); 851 return; 852 } 853 /* NVMET path. NVMET only cares about NVMEI nodes. */ 854 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) { 855 if (ndlp->nlp_type != NLP_NVME_INITIATOR || 856 ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) 857 continue; 858 spin_lock_irq(&ndlp->lock); 859 if (ndlp->nlp_DID == Did) 860 ndlp->nlp_flag &= ~NLP_NVMET_RECOV; 861 else 862 ndlp->nlp_flag |= NLP_NVMET_RECOV; 863 spin_unlock_irq(&ndlp->lock); 864 } 865 } 866 } 867 868 static int 869 lpfc_ns_rsp(struct lpfc_vport *vport, struct lpfc_dmabuf *mp, uint8_t fc4_type, 870 uint32_t Size) 871 { 872 struct lpfc_sli_ct_request *Response = 873 (struct lpfc_sli_ct_request *) mp->virt; 874 struct lpfc_dmabuf *mlast, *next_mp; 875 uint32_t *ctptr = (uint32_t *) & Response->un.gid.PortType; 876 uint32_t Did, CTentry; 877 int Cnt; 878 struct list_head head; 879 struct lpfc_nodelist *ndlp = NULL; 880 881 lpfc_set_disctmo(vport); 882 vport->num_disc_nodes = 0; 883 vport->fc_ns_retry = 0; 884 885 886 list_add_tail(&head, &mp->list); 887 list_for_each_entry_safe(mp, next_mp, &head, list) { 888 mlast = mp; 889 890 Cnt = Size > FCELSSIZE ? FCELSSIZE : Size; 891 892 Size -= Cnt; 893 894 if (!ctptr) { 895 ctptr = (uint32_t *) mlast->virt; 896 } else 897 Cnt -= 16; /* subtract length of CT header */ 898 899 /* Loop through entire NameServer list of DIDs */ 900 while (Cnt >= sizeof(uint32_t)) { 901 /* Get next DID from NameServer List */ 902 CTentry = *ctptr++; 903 Did = ((be32_to_cpu(CTentry)) & Mask_DID); 904 lpfc_ns_rsp_audit_did(vport, Did, fc4_type); 905 if (CTentry & (cpu_to_be32(SLI_CT_LAST_ENTRY))) 906 goto nsout1; 907 908 Cnt -= sizeof(uint32_t); 909 } 910 ctptr = NULL; 911 912 } 913 914 /* All GID_FT entries processed. If the driver is running in 915 * in target mode, put impacted nodes into recovery and drop 916 * the RPI to flush outstanding IO. 917 */ 918 if (vport->phba->nvmet_support) { 919 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) { 920 if (!(ndlp->nlp_flag & NLP_NVMET_RECOV)) 921 continue; 922 lpfc_disc_state_machine(vport, ndlp, NULL, 923 NLP_EVT_DEVICE_RECOVERY); 924 spin_lock_irq(&ndlp->lock); 925 ndlp->nlp_flag &= ~NLP_NVMET_RECOV; 926 spin_unlock_irq(&ndlp->lock); 927 } 928 } 929 930 nsout1: 931 list_del(&head); 932 return 0; 933 } 934 935 static void 936 lpfc_cmpl_ct_cmd_gid_ft(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, 937 struct lpfc_iocbq *rspiocb) 938 { 939 struct lpfc_vport *vport = cmdiocb->vport; 940 struct Scsi_Host *shost = lpfc_shost_from_vport(vport); 941 IOCB_t *irsp; 942 struct lpfc_dmabuf *outp; 943 struct lpfc_dmabuf *inp; 944 struct lpfc_sli_ct_request *CTrsp; 945 struct lpfc_sli_ct_request *CTreq; 946 struct lpfc_nodelist *ndlp; 947 int rc, type; 948 949 /* First save ndlp, before we overwrite it */ 950 ndlp = cmdiocb->context_un.ndlp; 951 952 /* we pass cmdiocb to state machine which needs rspiocb as well */ 953 cmdiocb->context_un.rsp_iocb = rspiocb; 954 inp = (struct lpfc_dmabuf *) cmdiocb->context1; 955 outp = (struct lpfc_dmabuf *) cmdiocb->context2; 956 irsp = &rspiocb->iocb; 957 958 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT, 959 "GID_FT cmpl: status:x%x/x%x rtry:%d", 960 irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_ns_retry); 961 962 /* Ignore response if link flipped after this request was made */ 963 if (cmdiocb->event_tag != phba->fc_eventTag) { 964 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, 965 "9043 Event tag mismatch. Ignoring NS rsp\n"); 966 goto out; 967 } 968 969 /* Don't bother processing response if vport is being torn down. */ 970 if (vport->load_flag & FC_UNLOADING) { 971 if (vport->fc_flag & FC_RSCN_MODE) 972 lpfc_els_flush_rscn(vport); 973 goto out; 974 } 975 976 if (lpfc_els_chk_latt(vport)) { 977 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, 978 "0216 Link event during NS query\n"); 979 if (vport->fc_flag & FC_RSCN_MODE) 980 lpfc_els_flush_rscn(vport); 981 lpfc_vport_set_state(vport, FC_VPORT_FAILED); 982 goto out; 983 } 984 if (lpfc_error_lost_link(irsp)) { 985 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, 986 "0226 NS query failed due to link event\n"); 987 if (vport->fc_flag & FC_RSCN_MODE) 988 lpfc_els_flush_rscn(vport); 989 goto out; 990 } 991 992 spin_lock_irq(shost->host_lock); 993 if (vport->fc_flag & FC_RSCN_DEFERRED) { 994 vport->fc_flag &= ~FC_RSCN_DEFERRED; 995 spin_unlock_irq(shost->host_lock); 996 997 /* This is a GID_FT completing so the gidft_inp counter was 998 * incremented before the GID_FT was issued to the wire. 999 */ 1000 if (vport->gidft_inp) 1001 vport->gidft_inp--; 1002 1003 /* 1004 * Skip processing the NS response 1005 * Re-issue the NS cmd 1006 */ 1007 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, 1008 "0151 Process Deferred RSCN Data: x%x x%x\n", 1009 vport->fc_flag, vport->fc_rscn_id_cnt); 1010 lpfc_els_handle_rscn(vport); 1011 1012 goto out; 1013 } 1014 spin_unlock_irq(shost->host_lock); 1015 1016 if (irsp->ulpStatus) { 1017 /* Check for retry */ 1018 if (vport->fc_ns_retry < LPFC_MAX_NS_RETRY) { 1019 if (irsp->ulpStatus != IOSTAT_LOCAL_REJECT || 1020 (irsp->un.ulpWord[4] & IOERR_PARAM_MASK) != 1021 IOERR_NO_RESOURCES) 1022 vport->fc_ns_retry++; 1023 1024 type = lpfc_get_gidft_type(vport, cmdiocb); 1025 if (type == 0) 1026 goto out; 1027 1028 /* CT command is being retried */ 1029 rc = lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 1030 vport->fc_ns_retry, type); 1031 if (rc == 0) 1032 goto out; 1033 else { /* Unable to send NS cmd */ 1034 if (vport->gidft_inp) 1035 vport->gidft_inp--; 1036 } 1037 } 1038 if (vport->fc_flag & FC_RSCN_MODE) 1039 lpfc_els_flush_rscn(vport); 1040 lpfc_vport_set_state(vport, FC_VPORT_FAILED); 1041 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, 1042 "0257 GID_FT Query error: 0x%x 0x%x\n", 1043 irsp->ulpStatus, vport->fc_ns_retry); 1044 } else { 1045 /* Good status, continue checking */ 1046 CTreq = (struct lpfc_sli_ct_request *) inp->virt; 1047 CTrsp = (struct lpfc_sli_ct_request *) outp->virt; 1048 if (CTrsp->CommandResponse.bits.CmdRsp == 1049 cpu_to_be16(SLI_CT_RESPONSE_FS_ACC)) { 1050 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, 1051 "0208 NameServer Rsp Data: x%x x%x " 1052 "x%x x%x sz x%x\n", 1053 vport->fc_flag, 1054 CTreq->un.gid.Fc4Type, 1055 vport->num_disc_nodes, 1056 vport->gidft_inp, 1057 irsp->un.genreq64.bdl.bdeSize); 1058 1059 lpfc_ns_rsp(vport, 1060 outp, 1061 CTreq->un.gid.Fc4Type, 1062 (uint32_t) (irsp->un.genreq64.bdl.bdeSize)); 1063 } else if (CTrsp->CommandResponse.bits.CmdRsp == 1064 be16_to_cpu(SLI_CT_RESPONSE_FS_RJT)) { 1065 /* NameServer Rsp Error */ 1066 if ((CTrsp->ReasonCode == SLI_CT_UNABLE_TO_PERFORM_REQ) 1067 && (CTrsp->Explanation == SLI_CT_NO_FC4_TYPES)) { 1068 lpfc_printf_vlog(vport, KERN_INFO, 1069 LOG_DISCOVERY, 1070 "0269 No NameServer Entries " 1071 "Data: x%x x%x x%x x%x\n", 1072 CTrsp->CommandResponse.bits.CmdRsp, 1073 (uint32_t) CTrsp->ReasonCode, 1074 (uint32_t) CTrsp->Explanation, 1075 vport->fc_flag); 1076 1077 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT, 1078 "GID_FT no entry cmd:x%x rsn:x%x exp:x%x", 1079 (uint32_t)CTrsp->CommandResponse.bits.CmdRsp, 1080 (uint32_t) CTrsp->ReasonCode, 1081 (uint32_t) CTrsp->Explanation); 1082 } else { 1083 lpfc_printf_vlog(vport, KERN_INFO, 1084 LOG_DISCOVERY, 1085 "0240 NameServer Rsp Error " 1086 "Data: x%x x%x x%x x%x\n", 1087 CTrsp->CommandResponse.bits.CmdRsp, 1088 (uint32_t) CTrsp->ReasonCode, 1089 (uint32_t) CTrsp->Explanation, 1090 vport->fc_flag); 1091 1092 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT, 1093 "GID_FT rsp err1 cmd:x%x rsn:x%x exp:x%x", 1094 (uint32_t)CTrsp->CommandResponse.bits.CmdRsp, 1095 (uint32_t) CTrsp->ReasonCode, 1096 (uint32_t) CTrsp->Explanation); 1097 } 1098 1099 1100 } else { 1101 /* NameServer Rsp Error */ 1102 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, 1103 "0241 NameServer Rsp Error " 1104 "Data: x%x x%x x%x x%x\n", 1105 CTrsp->CommandResponse.bits.CmdRsp, 1106 (uint32_t) CTrsp->ReasonCode, 1107 (uint32_t) CTrsp->Explanation, 1108 vport->fc_flag); 1109 1110 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT, 1111 "GID_FT rsp err2 cmd:x%x rsn:x%x exp:x%x", 1112 (uint32_t)CTrsp->CommandResponse.bits.CmdRsp, 1113 (uint32_t) CTrsp->ReasonCode, 1114 (uint32_t) CTrsp->Explanation); 1115 } 1116 if (vport->gidft_inp) 1117 vport->gidft_inp--; 1118 } 1119 1120 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, 1121 "4216 GID_FT cmpl inp %d disc %d\n", 1122 vport->gidft_inp, vport->num_disc_nodes); 1123 1124 /* Link up / RSCN discovery */ 1125 if ((vport->num_disc_nodes == 0) && 1126 (vport->gidft_inp == 0)) { 1127 /* 1128 * The driver has cycled through all Nports in the RSCN payload. 1129 * Complete the handling by cleaning up and marking the 1130 * current driver state. 1131 */ 1132 if (vport->port_state >= LPFC_DISC_AUTH) { 1133 if (vport->fc_flag & FC_RSCN_MODE) { 1134 lpfc_els_flush_rscn(vport); 1135 spin_lock_irq(shost->host_lock); 1136 vport->fc_flag |= FC_RSCN_MODE; /* RSCN still */ 1137 spin_unlock_irq(shost->host_lock); 1138 } 1139 else 1140 lpfc_els_flush_rscn(vport); 1141 } 1142 1143 lpfc_disc_start(vport); 1144 } 1145 out: 1146 lpfc_ct_free_iocb(phba, cmdiocb); 1147 lpfc_nlp_put(ndlp); 1148 return; 1149 } 1150 1151 static void 1152 lpfc_cmpl_ct_cmd_gid_pt(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, 1153 struct lpfc_iocbq *rspiocb) 1154 { 1155 struct lpfc_vport *vport = cmdiocb->vport; 1156 struct Scsi_Host *shost = lpfc_shost_from_vport(vport); 1157 IOCB_t *irsp; 1158 struct lpfc_dmabuf *outp; 1159 struct lpfc_dmabuf *inp; 1160 struct lpfc_sli_ct_request *CTrsp; 1161 struct lpfc_sli_ct_request *CTreq; 1162 struct lpfc_nodelist *ndlp; 1163 int rc; 1164 1165 /* First save ndlp, before we overwrite it */ 1166 ndlp = cmdiocb->context_un.ndlp; 1167 1168 /* we pass cmdiocb to state machine which needs rspiocb as well */ 1169 cmdiocb->context_un.rsp_iocb = rspiocb; 1170 inp = (struct lpfc_dmabuf *)cmdiocb->context1; 1171 outp = (struct lpfc_dmabuf *)cmdiocb->context2; 1172 irsp = &rspiocb->iocb; 1173 1174 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT, 1175 "GID_PT cmpl: status:x%x/x%x rtry:%d", 1176 irsp->ulpStatus, irsp->un.ulpWord[4], 1177 vport->fc_ns_retry); 1178 1179 /* Ignore response if link flipped after this request was made */ 1180 if (cmdiocb->event_tag != phba->fc_eventTag) { 1181 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, 1182 "9044 Event tag mismatch. Ignoring NS rsp\n"); 1183 goto out; 1184 } 1185 1186 /* Don't bother processing response if vport is being torn down. */ 1187 if (vport->load_flag & FC_UNLOADING) { 1188 if (vport->fc_flag & FC_RSCN_MODE) 1189 lpfc_els_flush_rscn(vport); 1190 goto out; 1191 } 1192 1193 if (lpfc_els_chk_latt(vport)) { 1194 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, 1195 "4108 Link event during NS query\n"); 1196 if (vport->fc_flag & FC_RSCN_MODE) 1197 lpfc_els_flush_rscn(vport); 1198 lpfc_vport_set_state(vport, FC_VPORT_FAILED); 1199 goto out; 1200 } 1201 if (lpfc_error_lost_link(irsp)) { 1202 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, 1203 "4166 NS query failed due to link event\n"); 1204 if (vport->fc_flag & FC_RSCN_MODE) 1205 lpfc_els_flush_rscn(vport); 1206 goto out; 1207 } 1208 1209 spin_lock_irq(shost->host_lock); 1210 if (vport->fc_flag & FC_RSCN_DEFERRED) { 1211 vport->fc_flag &= ~FC_RSCN_DEFERRED; 1212 spin_unlock_irq(shost->host_lock); 1213 1214 /* This is a GID_PT completing so the gidft_inp counter was 1215 * incremented before the GID_PT was issued to the wire. 1216 */ 1217 if (vport->gidft_inp) 1218 vport->gidft_inp--; 1219 1220 /* 1221 * Skip processing the NS response 1222 * Re-issue the NS cmd 1223 */ 1224 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, 1225 "4167 Process Deferred RSCN Data: x%x x%x\n", 1226 vport->fc_flag, vport->fc_rscn_id_cnt); 1227 lpfc_els_handle_rscn(vport); 1228 1229 goto out; 1230 } 1231 spin_unlock_irq(shost->host_lock); 1232 1233 if (irsp->ulpStatus) { 1234 /* Check for retry */ 1235 if (vport->fc_ns_retry < LPFC_MAX_NS_RETRY) { 1236 if (irsp->ulpStatus != IOSTAT_LOCAL_REJECT || 1237 (irsp->un.ulpWord[4] & IOERR_PARAM_MASK) != 1238 IOERR_NO_RESOURCES) 1239 vport->fc_ns_retry++; 1240 1241 /* CT command is being retried */ 1242 rc = lpfc_ns_cmd(vport, SLI_CTNS_GID_PT, 1243 vport->fc_ns_retry, GID_PT_N_PORT); 1244 if (rc == 0) 1245 goto out; 1246 else { /* Unable to send NS cmd */ 1247 if (vport->gidft_inp) 1248 vport->gidft_inp--; 1249 } 1250 } 1251 if (vport->fc_flag & FC_RSCN_MODE) 1252 lpfc_els_flush_rscn(vport); 1253 lpfc_vport_set_state(vport, FC_VPORT_FAILED); 1254 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, 1255 "4103 GID_FT Query error: 0x%x 0x%x\n", 1256 irsp->ulpStatus, vport->fc_ns_retry); 1257 } else { 1258 /* Good status, continue checking */ 1259 CTreq = (struct lpfc_sli_ct_request *)inp->virt; 1260 CTrsp = (struct lpfc_sli_ct_request *)outp->virt; 1261 if (CTrsp->CommandResponse.bits.CmdRsp == 1262 cpu_to_be16(SLI_CT_RESPONSE_FS_ACC)) { 1263 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, 1264 "4105 NameServer Rsp Data: x%x x%x " 1265 "x%x x%x sz x%x\n", 1266 vport->fc_flag, 1267 CTreq->un.gid.Fc4Type, 1268 vport->num_disc_nodes, 1269 vport->gidft_inp, 1270 irsp->un.genreq64.bdl.bdeSize); 1271 1272 lpfc_ns_rsp(vport, 1273 outp, 1274 CTreq->un.gid.Fc4Type, 1275 (uint32_t)(irsp->un.genreq64.bdl.bdeSize)); 1276 } else if (CTrsp->CommandResponse.bits.CmdRsp == 1277 be16_to_cpu(SLI_CT_RESPONSE_FS_RJT)) { 1278 /* NameServer Rsp Error */ 1279 if ((CTrsp->ReasonCode == SLI_CT_UNABLE_TO_PERFORM_REQ) 1280 && (CTrsp->Explanation == SLI_CT_NO_FC4_TYPES)) { 1281 lpfc_printf_vlog( 1282 vport, KERN_INFO, LOG_DISCOVERY, 1283 "4106 No NameServer Entries " 1284 "Data: x%x x%x x%x x%x\n", 1285 CTrsp->CommandResponse.bits.CmdRsp, 1286 (uint32_t)CTrsp->ReasonCode, 1287 (uint32_t)CTrsp->Explanation, 1288 vport->fc_flag); 1289 1290 lpfc_debugfs_disc_trc( 1291 vport, LPFC_DISC_TRC_CT, 1292 "GID_PT no entry cmd:x%x rsn:x%x exp:x%x", 1293 (uint32_t)CTrsp->CommandResponse.bits.CmdRsp, 1294 (uint32_t)CTrsp->ReasonCode, 1295 (uint32_t)CTrsp->Explanation); 1296 } else { 1297 lpfc_printf_vlog( 1298 vport, KERN_INFO, LOG_DISCOVERY, 1299 "4107 NameServer Rsp Error " 1300 "Data: x%x x%x x%x x%x\n", 1301 CTrsp->CommandResponse.bits.CmdRsp, 1302 (uint32_t)CTrsp->ReasonCode, 1303 (uint32_t)CTrsp->Explanation, 1304 vport->fc_flag); 1305 1306 lpfc_debugfs_disc_trc( 1307 vport, LPFC_DISC_TRC_CT, 1308 "GID_PT rsp err1 cmd:x%x rsn:x%x exp:x%x", 1309 (uint32_t)CTrsp->CommandResponse.bits.CmdRsp, 1310 (uint32_t)CTrsp->ReasonCode, 1311 (uint32_t)CTrsp->Explanation); 1312 } 1313 } else { 1314 /* NameServer Rsp Error */ 1315 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, 1316 "4109 NameServer Rsp Error " 1317 "Data: x%x x%x x%x x%x\n", 1318 CTrsp->CommandResponse.bits.CmdRsp, 1319 (uint32_t)CTrsp->ReasonCode, 1320 (uint32_t)CTrsp->Explanation, 1321 vport->fc_flag); 1322 1323 lpfc_debugfs_disc_trc( 1324 vport, LPFC_DISC_TRC_CT, 1325 "GID_PT rsp err2 cmd:x%x rsn:x%x exp:x%x", 1326 (uint32_t)CTrsp->CommandResponse.bits.CmdRsp, 1327 (uint32_t)CTrsp->ReasonCode, 1328 (uint32_t)CTrsp->Explanation); 1329 } 1330 if (vport->gidft_inp) 1331 vport->gidft_inp--; 1332 } 1333 1334 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, 1335 "6450 GID_PT cmpl inp %d disc %d\n", 1336 vport->gidft_inp, vport->num_disc_nodes); 1337 1338 /* Link up / RSCN discovery */ 1339 if ((vport->num_disc_nodes == 0) && 1340 (vport->gidft_inp == 0)) { 1341 /* 1342 * The driver has cycled through all Nports in the RSCN payload. 1343 * Complete the handling by cleaning up and marking the 1344 * current driver state. 1345 */ 1346 if (vport->port_state >= LPFC_DISC_AUTH) { 1347 if (vport->fc_flag & FC_RSCN_MODE) { 1348 lpfc_els_flush_rscn(vport); 1349 spin_lock_irq(shost->host_lock); 1350 vport->fc_flag |= FC_RSCN_MODE; /* RSCN still */ 1351 spin_unlock_irq(shost->host_lock); 1352 } else { 1353 lpfc_els_flush_rscn(vport); 1354 } 1355 } 1356 1357 lpfc_disc_start(vport); 1358 } 1359 out: 1360 lpfc_ct_free_iocb(phba, cmdiocb); 1361 lpfc_nlp_put(ndlp); 1362 } 1363 1364 static void 1365 lpfc_cmpl_ct_cmd_gff_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, 1366 struct lpfc_iocbq *rspiocb) 1367 { 1368 struct lpfc_vport *vport = cmdiocb->vport; 1369 struct Scsi_Host *shost = lpfc_shost_from_vport(vport); 1370 IOCB_t *irsp = &rspiocb->iocb; 1371 struct lpfc_dmabuf *inp = (struct lpfc_dmabuf *) cmdiocb->context1; 1372 struct lpfc_dmabuf *outp = (struct lpfc_dmabuf *) cmdiocb->context2; 1373 struct lpfc_sli_ct_request *CTrsp; 1374 int did, rc, retry; 1375 uint8_t fbits; 1376 struct lpfc_nodelist *ndlp = NULL, *free_ndlp = NULL; 1377 1378 did = ((struct lpfc_sli_ct_request *) inp->virt)->un.gff.PortId; 1379 did = be32_to_cpu(did); 1380 1381 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT, 1382 "GFF_ID cmpl: status:x%x/x%x did:x%x", 1383 irsp->ulpStatus, irsp->un.ulpWord[4], did); 1384 1385 /* Ignore response if link flipped after this request was made */ 1386 if (cmdiocb->event_tag != phba->fc_eventTag) { 1387 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, 1388 "9045 Event tag mismatch. Ignoring NS rsp\n"); 1389 goto iocb_free; 1390 } 1391 1392 if (irsp->ulpStatus == IOSTAT_SUCCESS) { 1393 /* Good status, continue checking */ 1394 CTrsp = (struct lpfc_sli_ct_request *) outp->virt; 1395 fbits = CTrsp->un.gff_acc.fbits[FCP_TYPE_FEATURE_OFFSET]; 1396 1397 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, 1398 "6431 Process GFF_ID rsp for %08x " 1399 "fbits %02x %s %s\n", 1400 did, fbits, 1401 (fbits & FC4_FEATURE_INIT) ? "Initiator" : " ", 1402 (fbits & FC4_FEATURE_TARGET) ? "Target" : " "); 1403 1404 if (CTrsp->CommandResponse.bits.CmdRsp == 1405 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC)) { 1406 if ((fbits & FC4_FEATURE_INIT) && 1407 !(fbits & FC4_FEATURE_TARGET)) { 1408 lpfc_printf_vlog(vport, KERN_INFO, 1409 LOG_DISCOVERY, 1410 "0270 Skip x%x GFF " 1411 "NameServer Rsp Data: (init) " 1412 "x%x x%x\n", did, fbits, 1413 vport->fc_rscn_id_cnt); 1414 goto out; 1415 } 1416 } 1417 } 1418 else { 1419 /* Check for retry */ 1420 if (cmdiocb->retry < LPFC_MAX_NS_RETRY) { 1421 retry = 1; 1422 if (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) { 1423 switch ((irsp->un.ulpWord[4] & 1424 IOERR_PARAM_MASK)) { 1425 1426 case IOERR_NO_RESOURCES: 1427 /* We don't increment the retry 1428 * count for this case. 1429 */ 1430 break; 1431 case IOERR_LINK_DOWN: 1432 case IOERR_SLI_ABORTED: 1433 case IOERR_SLI_DOWN: 1434 retry = 0; 1435 break; 1436 default: 1437 cmdiocb->retry++; 1438 } 1439 } 1440 else 1441 cmdiocb->retry++; 1442 1443 if (retry) { 1444 /* CT command is being retried */ 1445 rc = lpfc_ns_cmd(vport, SLI_CTNS_GFF_ID, 1446 cmdiocb->retry, did); 1447 if (rc == 0) { 1448 /* success */ 1449 free_ndlp = cmdiocb->context_un.ndlp; 1450 lpfc_ct_free_iocb(phba, cmdiocb); 1451 lpfc_nlp_put(free_ndlp); 1452 return; 1453 } 1454 } 1455 } 1456 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, 1457 "0267 NameServer GFF Rsp " 1458 "x%x Error (%d %d) Data: x%x x%x\n", 1459 did, irsp->ulpStatus, irsp->un.ulpWord[4], 1460 vport->fc_flag, vport->fc_rscn_id_cnt); 1461 } 1462 1463 /* This is a target port, unregistered port, or the GFF_ID failed */ 1464 ndlp = lpfc_setup_disc_node(vport, did); 1465 if (ndlp) { 1466 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, 1467 "0242 Process x%x GFF " 1468 "NameServer Rsp Data: x%x x%x x%x\n", 1469 did, ndlp->nlp_flag, vport->fc_flag, 1470 vport->fc_rscn_id_cnt); 1471 } else { 1472 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, 1473 "0243 Skip x%x GFF " 1474 "NameServer Rsp Data: x%x x%x\n", did, 1475 vport->fc_flag, vport->fc_rscn_id_cnt); 1476 } 1477 out: 1478 /* Link up / RSCN discovery */ 1479 if (vport->num_disc_nodes) 1480 vport->num_disc_nodes--; 1481 1482 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, 1483 "6451 GFF_ID cmpl inp %d disc %d\n", 1484 vport->gidft_inp, vport->num_disc_nodes); 1485 1486 if (vport->num_disc_nodes == 0) { 1487 /* 1488 * The driver has cycled through all Nports in the RSCN payload. 1489 * Complete the handling by cleaning up and marking the 1490 * current driver state. 1491 */ 1492 if (vport->port_state >= LPFC_DISC_AUTH) { 1493 if (vport->fc_flag & FC_RSCN_MODE) { 1494 lpfc_els_flush_rscn(vport); 1495 spin_lock_irq(shost->host_lock); 1496 vport->fc_flag |= FC_RSCN_MODE; /* RSCN still */ 1497 spin_unlock_irq(shost->host_lock); 1498 } 1499 else 1500 lpfc_els_flush_rscn(vport); 1501 } 1502 lpfc_disc_start(vport); 1503 } 1504 1505 iocb_free: 1506 free_ndlp = cmdiocb->context_un.ndlp; 1507 lpfc_ct_free_iocb(phba, cmdiocb); 1508 lpfc_nlp_put(free_ndlp); 1509 return; 1510 } 1511 1512 static void 1513 lpfc_cmpl_ct_cmd_gft_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, 1514 struct lpfc_iocbq *rspiocb) 1515 { 1516 struct lpfc_vport *vport = cmdiocb->vport; 1517 IOCB_t *irsp = &rspiocb->iocb; 1518 struct lpfc_dmabuf *inp = (struct lpfc_dmabuf *)cmdiocb->context1; 1519 struct lpfc_dmabuf *outp = (struct lpfc_dmabuf *)cmdiocb->context2; 1520 struct lpfc_sli_ct_request *CTrsp; 1521 int did; 1522 struct lpfc_nodelist *ndlp = NULL; 1523 struct lpfc_nodelist *ns_ndlp = NULL; 1524 uint32_t fc4_data_0, fc4_data_1; 1525 1526 did = ((struct lpfc_sli_ct_request *)inp->virt)->un.gft.PortId; 1527 did = be32_to_cpu(did); 1528 1529 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT, 1530 "GFT_ID cmpl: status:x%x/x%x did:x%x", 1531 irsp->ulpStatus, irsp->un.ulpWord[4], did); 1532 1533 /* Ignore response if link flipped after this request was made */ 1534 if ((uint32_t) cmdiocb->event_tag != phba->fc_eventTag) { 1535 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, 1536 "9046 Event tag mismatch. Ignoring NS rsp\n"); 1537 goto out; 1538 } 1539 1540 /* Preserve the nameserver node to release the reference. */ 1541 ns_ndlp = cmdiocb->context_un.ndlp; 1542 1543 if (irsp->ulpStatus == IOSTAT_SUCCESS) { 1544 /* Good status, continue checking */ 1545 CTrsp = (struct lpfc_sli_ct_request *)outp->virt; 1546 fc4_data_0 = be32_to_cpu(CTrsp->un.gft_acc.fc4_types[0]); 1547 fc4_data_1 = be32_to_cpu(CTrsp->un.gft_acc.fc4_types[1]); 1548 1549 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, 1550 "6432 Process GFT_ID rsp for %08x " 1551 "Data %08x %08x %s %s\n", 1552 did, fc4_data_0, fc4_data_1, 1553 (fc4_data_0 & LPFC_FC4_TYPE_BITMASK) ? 1554 "FCP" : " ", 1555 (fc4_data_1 & LPFC_FC4_TYPE_BITMASK) ? 1556 "NVME" : " "); 1557 1558 /* Lookup the NPort_ID queried in the GFT_ID and find the 1559 * driver's local node. It's an error if the driver 1560 * doesn't have one. 1561 */ 1562 ndlp = lpfc_findnode_did(vport, did); 1563 if (ndlp) { 1564 /* The bitmask value for FCP and NVME FCP types is 1565 * the same because they are 32 bits distant from 1566 * each other in word0 and word0. 1567 */ 1568 if (fc4_data_0 & LPFC_FC4_TYPE_BITMASK) 1569 ndlp->nlp_fc4_type |= NLP_FC4_FCP; 1570 if (fc4_data_1 & LPFC_FC4_TYPE_BITMASK) 1571 ndlp->nlp_fc4_type |= NLP_FC4_NVME; 1572 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, 1573 "3064 Setting ndlp x%px, DID x%06x " 1574 "with FC4 x%08x, Data: x%08x x%08x " 1575 "%d\n", 1576 ndlp, did, ndlp->nlp_fc4_type, 1577 FC_TYPE_FCP, FC_TYPE_NVME, 1578 ndlp->nlp_state); 1579 1580 if (ndlp->nlp_state == NLP_STE_REG_LOGIN_ISSUE && 1581 ndlp->nlp_fc4_type) { 1582 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE; 1583 1584 lpfc_nlp_set_state(vport, ndlp, 1585 NLP_STE_PRLI_ISSUE); 1586 lpfc_issue_els_prli(vport, ndlp, 0); 1587 } else if (!ndlp->nlp_fc4_type) { 1588 /* If fc4 type is still unknown, then LOGO */ 1589 lpfc_printf_vlog(vport, KERN_INFO, 1590 LOG_DISCOVERY, 1591 "6443 Sending LOGO ndlp x%px," 1592 "DID x%06x with fc4_type: " 1593 "x%08x, state: %d\n", 1594 ndlp, did, ndlp->nlp_fc4_type, 1595 ndlp->nlp_state); 1596 lpfc_issue_els_logo(vport, ndlp, 0); 1597 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE; 1598 lpfc_nlp_set_state(vport, ndlp, 1599 NLP_STE_NPR_NODE); 1600 } 1601 } 1602 } else 1603 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, 1604 "3065 GFT_ID failed x%08x\n", irsp->ulpStatus); 1605 1606 out: 1607 lpfc_ct_free_iocb(phba, cmdiocb); 1608 lpfc_nlp_put(ns_ndlp); 1609 } 1610 1611 static void 1612 lpfc_cmpl_ct(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, 1613 struct lpfc_iocbq *rspiocb) 1614 { 1615 struct lpfc_vport *vport = cmdiocb->vport; 1616 struct lpfc_dmabuf *inp; 1617 struct lpfc_dmabuf *outp; 1618 IOCB_t *irsp; 1619 struct lpfc_sli_ct_request *CTrsp; 1620 struct lpfc_nodelist *ndlp; 1621 int cmdcode, rc; 1622 uint8_t retry; 1623 uint32_t latt; 1624 1625 /* First save ndlp, before we overwrite it */ 1626 ndlp = cmdiocb->context_un.ndlp; 1627 1628 /* we pass cmdiocb to state machine which needs rspiocb as well */ 1629 cmdiocb->context_un.rsp_iocb = rspiocb; 1630 1631 inp = (struct lpfc_dmabuf *) cmdiocb->context1; 1632 outp = (struct lpfc_dmabuf *) cmdiocb->context2; 1633 irsp = &rspiocb->iocb; 1634 1635 cmdcode = be16_to_cpu(((struct lpfc_sli_ct_request *) inp->virt)-> 1636 CommandResponse.bits.CmdRsp); 1637 CTrsp = (struct lpfc_sli_ct_request *) outp->virt; 1638 1639 latt = lpfc_els_chk_latt(vport); 1640 1641 /* RFT request completes status <ulpStatus> CmdRsp <CmdRsp> */ 1642 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, 1643 "0209 CT Request completes, latt %d, " 1644 "ulpStatus x%x CmdRsp x%x, Context x%x, Tag x%x\n", 1645 latt, irsp->ulpStatus, 1646 CTrsp->CommandResponse.bits.CmdRsp, 1647 cmdiocb->iocb.ulpContext, cmdiocb->iocb.ulpIoTag); 1648 1649 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT, 1650 "CT cmd cmpl: status:x%x/x%x cmd:x%x", 1651 irsp->ulpStatus, irsp->un.ulpWord[4], cmdcode); 1652 1653 if (irsp->ulpStatus) { 1654 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, 1655 "0268 NS cmd x%x Error (x%x x%x)\n", 1656 cmdcode, irsp->ulpStatus, irsp->un.ulpWord[4]); 1657 1658 if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) && 1659 (((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) == 1660 IOERR_SLI_DOWN) || 1661 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) == 1662 IOERR_SLI_ABORTED))) 1663 goto out; 1664 1665 retry = cmdiocb->retry; 1666 if (retry >= LPFC_MAX_NS_RETRY) 1667 goto out; 1668 1669 retry++; 1670 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, 1671 "0250 Retrying NS cmd %x\n", cmdcode); 1672 rc = lpfc_ns_cmd(vport, cmdcode, retry, 0); 1673 if (rc == 0) 1674 goto out; 1675 } 1676 1677 out: 1678 lpfc_ct_free_iocb(phba, cmdiocb); 1679 lpfc_nlp_put(ndlp); 1680 return; 1681 } 1682 1683 static void 1684 lpfc_cmpl_ct_cmd_rft_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, 1685 struct lpfc_iocbq *rspiocb) 1686 { 1687 IOCB_t *irsp = &rspiocb->iocb; 1688 struct lpfc_vport *vport = cmdiocb->vport; 1689 1690 if (irsp->ulpStatus == IOSTAT_SUCCESS) { 1691 struct lpfc_dmabuf *outp; 1692 struct lpfc_sli_ct_request *CTrsp; 1693 1694 outp = (struct lpfc_dmabuf *) cmdiocb->context2; 1695 CTrsp = (struct lpfc_sli_ct_request *) outp->virt; 1696 if (CTrsp->CommandResponse.bits.CmdRsp == 1697 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC)) 1698 vport->ct_flags |= FC_CT_RFT_ID; 1699 } 1700 lpfc_cmpl_ct(phba, cmdiocb, rspiocb); 1701 return; 1702 } 1703 1704 static void 1705 lpfc_cmpl_ct_cmd_rnn_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, 1706 struct lpfc_iocbq *rspiocb) 1707 { 1708 IOCB_t *irsp = &rspiocb->iocb; 1709 struct lpfc_vport *vport = cmdiocb->vport; 1710 1711 if (irsp->ulpStatus == IOSTAT_SUCCESS) { 1712 struct lpfc_dmabuf *outp; 1713 struct lpfc_sli_ct_request *CTrsp; 1714 1715 outp = (struct lpfc_dmabuf *) cmdiocb->context2; 1716 CTrsp = (struct lpfc_sli_ct_request *) outp->virt; 1717 if (CTrsp->CommandResponse.bits.CmdRsp == 1718 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC)) 1719 vport->ct_flags |= FC_CT_RNN_ID; 1720 } 1721 lpfc_cmpl_ct(phba, cmdiocb, rspiocb); 1722 return; 1723 } 1724 1725 static void 1726 lpfc_cmpl_ct_cmd_rspn_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, 1727 struct lpfc_iocbq *rspiocb) 1728 { 1729 IOCB_t *irsp = &rspiocb->iocb; 1730 struct lpfc_vport *vport = cmdiocb->vport; 1731 1732 if (irsp->ulpStatus == IOSTAT_SUCCESS) { 1733 struct lpfc_dmabuf *outp; 1734 struct lpfc_sli_ct_request *CTrsp; 1735 1736 outp = (struct lpfc_dmabuf *) cmdiocb->context2; 1737 CTrsp = (struct lpfc_sli_ct_request *) outp->virt; 1738 if (CTrsp->CommandResponse.bits.CmdRsp == 1739 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC)) 1740 vport->ct_flags |= FC_CT_RSPN_ID; 1741 } 1742 lpfc_cmpl_ct(phba, cmdiocb, rspiocb); 1743 return; 1744 } 1745 1746 static void 1747 lpfc_cmpl_ct_cmd_rsnn_nn(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, 1748 struct lpfc_iocbq *rspiocb) 1749 { 1750 IOCB_t *irsp = &rspiocb->iocb; 1751 struct lpfc_vport *vport = cmdiocb->vport; 1752 1753 if (irsp->ulpStatus == IOSTAT_SUCCESS) { 1754 struct lpfc_dmabuf *outp; 1755 struct lpfc_sli_ct_request *CTrsp; 1756 1757 outp = (struct lpfc_dmabuf *) cmdiocb->context2; 1758 CTrsp = (struct lpfc_sli_ct_request *) outp->virt; 1759 if (CTrsp->CommandResponse.bits.CmdRsp == 1760 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC)) 1761 vport->ct_flags |= FC_CT_RSNN_NN; 1762 } 1763 lpfc_cmpl_ct(phba, cmdiocb, rspiocb); 1764 return; 1765 } 1766 1767 static void 1768 lpfc_cmpl_ct_cmd_da_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, 1769 struct lpfc_iocbq *rspiocb) 1770 { 1771 struct lpfc_vport *vport = cmdiocb->vport; 1772 1773 /* even if it fails we will act as though it succeeded. */ 1774 vport->ct_flags = 0; 1775 lpfc_cmpl_ct(phba, cmdiocb, rspiocb); 1776 return; 1777 } 1778 1779 static void 1780 lpfc_cmpl_ct_cmd_rff_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, 1781 struct lpfc_iocbq *rspiocb) 1782 { 1783 IOCB_t *irsp = &rspiocb->iocb; 1784 struct lpfc_vport *vport = cmdiocb->vport; 1785 1786 if (irsp->ulpStatus == IOSTAT_SUCCESS) { 1787 struct lpfc_dmabuf *outp; 1788 struct lpfc_sli_ct_request *CTrsp; 1789 1790 outp = (struct lpfc_dmabuf *) cmdiocb->context2; 1791 CTrsp = (struct lpfc_sli_ct_request *) outp->virt; 1792 if (CTrsp->CommandResponse.bits.CmdRsp == 1793 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC)) 1794 vport->ct_flags |= FC_CT_RFF_ID; 1795 } 1796 lpfc_cmpl_ct(phba, cmdiocb, rspiocb); 1797 return; 1798 } 1799 1800 /* 1801 * Although the symbolic port name is thought to be an integer 1802 * as of January 18, 2016, leave it as a string until more of 1803 * the record state becomes defined. 1804 */ 1805 int 1806 lpfc_vport_symbolic_port_name(struct lpfc_vport *vport, char *symbol, 1807 size_t size) 1808 { 1809 int n; 1810 1811 /* 1812 * Use the lpfc board number as the Symbolic Port 1813 * Name object. NPIV is not in play so this integer 1814 * value is sufficient and unique per FC-ID. 1815 */ 1816 n = scnprintf(symbol, size, "%d", vport->phba->brd_no); 1817 return n; 1818 } 1819 1820 1821 int 1822 lpfc_vport_symbolic_node_name(struct lpfc_vport *vport, char *symbol, 1823 size_t size) 1824 { 1825 char fwrev[FW_REV_STR_SIZE] = {0}; 1826 char tmp[MAXHOSTNAMELEN] = {0}; 1827 1828 memset(symbol, 0, size); 1829 1830 scnprintf(tmp, sizeof(tmp), "Emulex %s", vport->phba->ModelName); 1831 if (strlcat(symbol, tmp, size) >= size) 1832 goto buffer_done; 1833 1834 lpfc_decode_firmware_rev(vport->phba, fwrev, 0); 1835 scnprintf(tmp, sizeof(tmp), " FV%s", fwrev); 1836 if (strlcat(symbol, tmp, size) >= size) 1837 goto buffer_done; 1838 1839 scnprintf(tmp, sizeof(tmp), " DV%s", lpfc_release_version); 1840 if (strlcat(symbol, tmp, size) >= size) 1841 goto buffer_done; 1842 1843 scnprintf(tmp, sizeof(tmp), " HN:%s", vport->phba->os_host_name); 1844 if (strlcat(symbol, tmp, size) >= size) 1845 goto buffer_done; 1846 1847 /* Note :- OS name is "Linux" */ 1848 scnprintf(tmp, sizeof(tmp), " OS:%s", init_utsname()->sysname); 1849 strlcat(symbol, tmp, size); 1850 1851 buffer_done: 1852 return strnlen(symbol, size); 1853 1854 } 1855 1856 static uint32_t 1857 lpfc_find_map_node(struct lpfc_vport *vport) 1858 { 1859 struct lpfc_nodelist *ndlp, *next_ndlp; 1860 struct Scsi_Host *shost; 1861 uint32_t cnt = 0; 1862 1863 shost = lpfc_shost_from_vport(vport); 1864 spin_lock_irq(shost->host_lock); 1865 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) { 1866 if (ndlp->nlp_type & NLP_FABRIC) 1867 continue; 1868 if ((ndlp->nlp_state == NLP_STE_MAPPED_NODE) || 1869 (ndlp->nlp_state == NLP_STE_UNMAPPED_NODE)) 1870 cnt++; 1871 } 1872 spin_unlock_irq(shost->host_lock); 1873 return cnt; 1874 } 1875 1876 /* 1877 * This routine will return the FC4 Type associated with the CT 1878 * GID_FT command. 1879 */ 1880 int 1881 lpfc_get_gidft_type(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb) 1882 { 1883 struct lpfc_sli_ct_request *CtReq; 1884 struct lpfc_dmabuf *mp; 1885 uint32_t type; 1886 1887 mp = cmdiocb->context1; 1888 if (mp == NULL) 1889 return 0; 1890 CtReq = (struct lpfc_sli_ct_request *)mp->virt; 1891 type = (uint32_t)CtReq->un.gid.Fc4Type; 1892 if ((type != SLI_CTPT_FCP) && (type != SLI_CTPT_NVME)) 1893 return 0; 1894 return type; 1895 } 1896 1897 /* 1898 * lpfc_ns_cmd 1899 * Description: 1900 * Issue Cmd to NameServer 1901 * SLI_CTNS_GID_FT 1902 * LI_CTNS_RFT_ID 1903 */ 1904 int 1905 lpfc_ns_cmd(struct lpfc_vport *vport, int cmdcode, 1906 uint8_t retry, uint32_t context) 1907 { 1908 struct lpfc_nodelist * ndlp; 1909 struct lpfc_hba *phba = vport->phba; 1910 struct lpfc_dmabuf *mp, *bmp; 1911 struct lpfc_sli_ct_request *CtReq; 1912 struct ulp_bde64 *bpl; 1913 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *, 1914 struct lpfc_iocbq *) = NULL; 1915 uint32_t *ptr; 1916 uint32_t rsp_size = 1024; 1917 size_t size; 1918 int rc = 0; 1919 1920 ndlp = lpfc_findnode_did(vport, NameServer_DID); 1921 if (!ndlp || ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) { 1922 rc=1; 1923 goto ns_cmd_exit; 1924 } 1925 1926 /* fill in BDEs for command */ 1927 /* Allocate buffer for command payload */ 1928 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); 1929 if (!mp) { 1930 rc=2; 1931 goto ns_cmd_exit; 1932 } 1933 1934 INIT_LIST_HEAD(&mp->list); 1935 mp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(mp->phys)); 1936 if (!mp->virt) { 1937 rc=3; 1938 goto ns_cmd_free_mp; 1939 } 1940 1941 /* Allocate buffer for Buffer ptr list */ 1942 bmp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); 1943 if (!bmp) { 1944 rc=4; 1945 goto ns_cmd_free_mpvirt; 1946 } 1947 1948 INIT_LIST_HEAD(&bmp->list); 1949 bmp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(bmp->phys)); 1950 if (!bmp->virt) { 1951 rc=5; 1952 goto ns_cmd_free_bmp; 1953 } 1954 1955 /* NameServer Req */ 1956 lpfc_printf_vlog(vport, KERN_INFO ,LOG_DISCOVERY, 1957 "0236 NameServer Req Data: x%x x%x x%x x%x\n", 1958 cmdcode, vport->fc_flag, vport->fc_rscn_id_cnt, 1959 context); 1960 1961 bpl = (struct ulp_bde64 *) bmp->virt; 1962 memset(bpl, 0, sizeof(struct ulp_bde64)); 1963 bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys) ); 1964 bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys) ); 1965 bpl->tus.f.bdeFlags = 0; 1966 if (cmdcode == SLI_CTNS_GID_FT) 1967 bpl->tus.f.bdeSize = GID_REQUEST_SZ; 1968 else if (cmdcode == SLI_CTNS_GID_PT) 1969 bpl->tus.f.bdeSize = GID_REQUEST_SZ; 1970 else if (cmdcode == SLI_CTNS_GFF_ID) 1971 bpl->tus.f.bdeSize = GFF_REQUEST_SZ; 1972 else if (cmdcode == SLI_CTNS_GFT_ID) 1973 bpl->tus.f.bdeSize = GFT_REQUEST_SZ; 1974 else if (cmdcode == SLI_CTNS_RFT_ID) 1975 bpl->tus.f.bdeSize = RFT_REQUEST_SZ; 1976 else if (cmdcode == SLI_CTNS_RNN_ID) 1977 bpl->tus.f.bdeSize = RNN_REQUEST_SZ; 1978 else if (cmdcode == SLI_CTNS_RSPN_ID) 1979 bpl->tus.f.bdeSize = RSPN_REQUEST_SZ; 1980 else if (cmdcode == SLI_CTNS_RSNN_NN) 1981 bpl->tus.f.bdeSize = RSNN_REQUEST_SZ; 1982 else if (cmdcode == SLI_CTNS_DA_ID) 1983 bpl->tus.f.bdeSize = DA_ID_REQUEST_SZ; 1984 else if (cmdcode == SLI_CTNS_RFF_ID) 1985 bpl->tus.f.bdeSize = RFF_REQUEST_SZ; 1986 else 1987 bpl->tus.f.bdeSize = 0; 1988 bpl->tus.w = le32_to_cpu(bpl->tus.w); 1989 1990 CtReq = (struct lpfc_sli_ct_request *) mp->virt; 1991 memset(CtReq, 0, sizeof(struct lpfc_sli_ct_request)); 1992 CtReq->RevisionId.bits.Revision = SLI_CT_REVISION; 1993 CtReq->RevisionId.bits.InId = 0; 1994 CtReq->FsType = SLI_CT_DIRECTORY_SERVICE; 1995 CtReq->FsSubType = SLI_CT_DIRECTORY_NAME_SERVER; 1996 CtReq->CommandResponse.bits.Size = 0; 1997 switch (cmdcode) { 1998 case SLI_CTNS_GID_FT: 1999 CtReq->CommandResponse.bits.CmdRsp = 2000 cpu_to_be16(SLI_CTNS_GID_FT); 2001 CtReq->un.gid.Fc4Type = context; 2002 2003 if (vport->port_state < LPFC_NS_QRY) 2004 vport->port_state = LPFC_NS_QRY; 2005 lpfc_set_disctmo(vport); 2006 cmpl = lpfc_cmpl_ct_cmd_gid_ft; 2007 rsp_size = FC_MAX_NS_RSP; 2008 break; 2009 2010 case SLI_CTNS_GID_PT: 2011 CtReq->CommandResponse.bits.CmdRsp = 2012 cpu_to_be16(SLI_CTNS_GID_PT); 2013 CtReq->un.gid.PortType = context; 2014 2015 if (vport->port_state < LPFC_NS_QRY) 2016 vport->port_state = LPFC_NS_QRY; 2017 lpfc_set_disctmo(vport); 2018 cmpl = lpfc_cmpl_ct_cmd_gid_pt; 2019 rsp_size = FC_MAX_NS_RSP; 2020 break; 2021 2022 case SLI_CTNS_GFF_ID: 2023 CtReq->CommandResponse.bits.CmdRsp = 2024 cpu_to_be16(SLI_CTNS_GFF_ID); 2025 CtReq->un.gff.PortId = cpu_to_be32(context); 2026 cmpl = lpfc_cmpl_ct_cmd_gff_id; 2027 break; 2028 2029 case SLI_CTNS_GFT_ID: 2030 CtReq->CommandResponse.bits.CmdRsp = 2031 cpu_to_be16(SLI_CTNS_GFT_ID); 2032 CtReq->un.gft.PortId = cpu_to_be32(context); 2033 cmpl = lpfc_cmpl_ct_cmd_gft_id; 2034 break; 2035 2036 case SLI_CTNS_RFT_ID: 2037 vport->ct_flags &= ~FC_CT_RFT_ID; 2038 CtReq->CommandResponse.bits.CmdRsp = 2039 cpu_to_be16(SLI_CTNS_RFT_ID); 2040 CtReq->un.rft.PortId = cpu_to_be32(vport->fc_myDID); 2041 2042 /* Register FC4 FCP type if enabled. */ 2043 if (vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH || 2044 vport->cfg_enable_fc4_type == LPFC_ENABLE_FCP) 2045 CtReq->un.rft.fcpReg = 1; 2046 2047 /* Register NVME type if enabled. Defined LE and swapped. 2048 * rsvd[0] is used as word1 because of the hard-coded 2049 * word0 usage in the ct_request data structure. 2050 */ 2051 if (vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH || 2052 vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME) 2053 CtReq->un.rft.rsvd[0] = 2054 cpu_to_be32(LPFC_FC4_TYPE_BITMASK); 2055 2056 ptr = (uint32_t *)CtReq; 2057 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, 2058 "6433 Issue RFT (%s %s): %08x %08x %08x %08x " 2059 "%08x %08x %08x %08x\n", 2060 CtReq->un.rft.fcpReg ? "FCP" : " ", 2061 CtReq->un.rft.rsvd[0] ? "NVME" : " ", 2062 *ptr, *(ptr + 1), *(ptr + 2), *(ptr + 3), 2063 *(ptr + 4), *(ptr + 5), 2064 *(ptr + 6), *(ptr + 7)); 2065 cmpl = lpfc_cmpl_ct_cmd_rft_id; 2066 break; 2067 2068 case SLI_CTNS_RNN_ID: 2069 vport->ct_flags &= ~FC_CT_RNN_ID; 2070 CtReq->CommandResponse.bits.CmdRsp = 2071 cpu_to_be16(SLI_CTNS_RNN_ID); 2072 CtReq->un.rnn.PortId = cpu_to_be32(vport->fc_myDID); 2073 memcpy(CtReq->un.rnn.wwnn, &vport->fc_nodename, 2074 sizeof(struct lpfc_name)); 2075 cmpl = lpfc_cmpl_ct_cmd_rnn_id; 2076 break; 2077 2078 case SLI_CTNS_RSPN_ID: 2079 vport->ct_flags &= ~FC_CT_RSPN_ID; 2080 CtReq->CommandResponse.bits.CmdRsp = 2081 cpu_to_be16(SLI_CTNS_RSPN_ID); 2082 CtReq->un.rspn.PortId = cpu_to_be32(vport->fc_myDID); 2083 size = sizeof(CtReq->un.rspn.symbname); 2084 CtReq->un.rspn.len = 2085 lpfc_vport_symbolic_port_name(vport, 2086 CtReq->un.rspn.symbname, size); 2087 cmpl = lpfc_cmpl_ct_cmd_rspn_id; 2088 break; 2089 case SLI_CTNS_RSNN_NN: 2090 vport->ct_flags &= ~FC_CT_RSNN_NN; 2091 CtReq->CommandResponse.bits.CmdRsp = 2092 cpu_to_be16(SLI_CTNS_RSNN_NN); 2093 memcpy(CtReq->un.rsnn.wwnn, &vport->fc_nodename, 2094 sizeof(struct lpfc_name)); 2095 size = sizeof(CtReq->un.rsnn.symbname); 2096 CtReq->un.rsnn.len = 2097 lpfc_vport_symbolic_node_name(vport, 2098 CtReq->un.rsnn.symbname, size); 2099 cmpl = lpfc_cmpl_ct_cmd_rsnn_nn; 2100 break; 2101 case SLI_CTNS_DA_ID: 2102 /* Implement DA_ID Nameserver request */ 2103 CtReq->CommandResponse.bits.CmdRsp = 2104 cpu_to_be16(SLI_CTNS_DA_ID); 2105 CtReq->un.da_id.port_id = cpu_to_be32(vport->fc_myDID); 2106 cmpl = lpfc_cmpl_ct_cmd_da_id; 2107 break; 2108 case SLI_CTNS_RFF_ID: 2109 vport->ct_flags &= ~FC_CT_RFF_ID; 2110 CtReq->CommandResponse.bits.CmdRsp = 2111 cpu_to_be16(SLI_CTNS_RFF_ID); 2112 CtReq->un.rff.PortId = cpu_to_be32(vport->fc_myDID); 2113 CtReq->un.rff.fbits = FC4_FEATURE_INIT; 2114 2115 /* The driver always supports FC_TYPE_FCP. However, the 2116 * caller can specify NVME (type x28) as well. But only 2117 * these that FC4 type is supported. 2118 */ 2119 if (((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) || 2120 (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) && 2121 (context == FC_TYPE_NVME)) { 2122 if ((vport == phba->pport) && phba->nvmet_support) { 2123 CtReq->un.rff.fbits = (FC4_FEATURE_TARGET | 2124 FC4_FEATURE_NVME_DISC); 2125 lpfc_nvmet_update_targetport(phba); 2126 } else { 2127 lpfc_nvme_update_localport(vport); 2128 } 2129 CtReq->un.rff.type_code = context; 2130 2131 } else if (((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) || 2132 (vport->cfg_enable_fc4_type == LPFC_ENABLE_FCP)) && 2133 (context == FC_TYPE_FCP)) 2134 CtReq->un.rff.type_code = context; 2135 2136 else 2137 goto ns_cmd_free_bmpvirt; 2138 2139 ptr = (uint32_t *)CtReq; 2140 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, 2141 "6434 Issue RFF (%s): %08x %08x %08x %08x " 2142 "%08x %08x %08x %08x\n", 2143 (context == FC_TYPE_NVME) ? "NVME" : "FCP", 2144 *ptr, *(ptr + 1), *(ptr + 2), *(ptr + 3), 2145 *(ptr + 4), *(ptr + 5), 2146 *(ptr + 6), *(ptr + 7)); 2147 cmpl = lpfc_cmpl_ct_cmd_rff_id; 2148 break; 2149 } 2150 /* The lpfc_ct_cmd/lpfc_get_req shall increment ndlp reference count 2151 * to hold ndlp reference for the corresponding callback function. 2152 */ 2153 if (!lpfc_ct_cmd(vport, mp, bmp, ndlp, cmpl, rsp_size, retry)) { 2154 /* On success, The cmpl function will free the buffers */ 2155 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT, 2156 "Issue CT cmd: cmd:x%x did:x%x", 2157 cmdcode, ndlp->nlp_DID, 0); 2158 return 0; 2159 } 2160 rc=6; 2161 2162 ns_cmd_free_bmpvirt: 2163 lpfc_mbuf_free(phba, bmp->virt, bmp->phys); 2164 ns_cmd_free_bmp: 2165 kfree(bmp); 2166 ns_cmd_free_mpvirt: 2167 lpfc_mbuf_free(phba, mp->virt, mp->phys); 2168 ns_cmd_free_mp: 2169 kfree(mp); 2170 ns_cmd_exit: 2171 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, 2172 "0266 Issue NameServer Req x%x err %d Data: x%x x%x\n", 2173 cmdcode, rc, vport->fc_flag, vport->fc_rscn_id_cnt); 2174 return 1; 2175 } 2176 2177 /** 2178 * lpfc_cmpl_ct_disc_fdmi - Handle a discovery FDMI completion 2179 * @phba: Pointer to HBA context object. 2180 * @cmdiocb: Pointer to the command IOCBQ. 2181 * @rspiocb: Pointer to the response IOCBQ. 2182 * 2183 * This function to handle the completion of a driver initiated FDMI 2184 * CT command issued during discovery. 2185 */ 2186 static void 2187 lpfc_cmpl_ct_disc_fdmi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, 2188 struct lpfc_iocbq *rspiocb) 2189 { 2190 struct lpfc_vport *vport = cmdiocb->vport; 2191 struct lpfc_dmabuf *inp = cmdiocb->context1; 2192 struct lpfc_dmabuf *outp = cmdiocb->context2; 2193 struct lpfc_sli_ct_request *CTcmd = inp->virt; 2194 struct lpfc_sli_ct_request *CTrsp = outp->virt; 2195 uint16_t fdmi_cmd = CTcmd->CommandResponse.bits.CmdRsp; 2196 uint16_t fdmi_rsp = CTrsp->CommandResponse.bits.CmdRsp; 2197 IOCB_t *irsp = &rspiocb->iocb; 2198 struct lpfc_nodelist *ndlp, *free_ndlp = NULL; 2199 uint32_t latt, cmd, err; 2200 2201 latt = lpfc_els_chk_latt(vport); 2202 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT, 2203 "FDMI cmpl: status:x%x/x%x latt:%d", 2204 irsp->ulpStatus, irsp->un.ulpWord[4], latt); 2205 2206 if (latt || irsp->ulpStatus) { 2207 2208 /* Look for a retryable error */ 2209 if (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) { 2210 switch ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK)) { 2211 case IOERR_SLI_ABORTED: 2212 case IOERR_SLI_DOWN: 2213 /* Driver aborted this IO. No retry as error 2214 * is likely Offline->Online or some adapter 2215 * error. Recovery will try again. 2216 */ 2217 break; 2218 case IOERR_ABORT_IN_PROGRESS: 2219 case IOERR_SEQUENCE_TIMEOUT: 2220 case IOERR_ILLEGAL_FRAME: 2221 case IOERR_NO_RESOURCES: 2222 case IOERR_ILLEGAL_COMMAND: 2223 cmdiocb->retry++; 2224 if (cmdiocb->retry >= LPFC_FDMI_MAX_RETRY) 2225 break; 2226 2227 /* Retry the same FDMI command */ 2228 err = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, 2229 cmdiocb, 0); 2230 if (err == IOCB_ERROR) 2231 break; 2232 return; 2233 default: 2234 break; 2235 } 2236 } 2237 2238 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, 2239 "0229 FDMI cmd %04x failed, latt = %d " 2240 "ulpStatus: x%x, rid x%x\n", 2241 be16_to_cpu(fdmi_cmd), latt, irsp->ulpStatus, 2242 irsp->un.ulpWord[4]); 2243 } 2244 2245 free_ndlp = cmdiocb->context_un.ndlp; 2246 lpfc_ct_free_iocb(phba, cmdiocb); 2247 lpfc_nlp_put(free_ndlp); 2248 2249 ndlp = lpfc_findnode_did(vport, FDMI_DID); 2250 if (!ndlp) 2251 return; 2252 2253 /* Check for a CT LS_RJT response */ 2254 cmd = be16_to_cpu(fdmi_cmd); 2255 if (fdmi_rsp == cpu_to_be16(SLI_CT_RESPONSE_FS_RJT)) { 2256 /* FDMI rsp failed */ 2257 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, 2258 "0220 FDMI cmd failed FS_RJT Data: x%x", cmd); 2259 2260 /* Should we fallback to FDMI-2 / FDMI-1 ? */ 2261 switch (cmd) { 2262 case SLI_MGMT_RHBA: 2263 if (vport->fdmi_hba_mask == LPFC_FDMI2_HBA_ATTR) { 2264 /* Fallback to FDMI-1 */ 2265 vport->fdmi_hba_mask = LPFC_FDMI1_HBA_ATTR; 2266 vport->fdmi_port_mask = LPFC_FDMI1_PORT_ATTR; 2267 /* Start over */ 2268 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA, 0); 2269 } 2270 return; 2271 2272 case SLI_MGMT_RPRT: 2273 if (vport->fdmi_port_mask == LPFC_FDMI2_PORT_ATTR) { 2274 /* Fallback to FDMI-1 */ 2275 vport->fdmi_port_mask = LPFC_FDMI1_PORT_ATTR; 2276 /* Start over */ 2277 lpfc_fdmi_cmd(vport, ndlp, cmd, 0); 2278 return; 2279 } 2280 if (vport->fdmi_port_mask == LPFC_FDMI2_SMART_ATTR) { 2281 vport->fdmi_port_mask = LPFC_FDMI2_PORT_ATTR; 2282 /* Retry the same command */ 2283 lpfc_fdmi_cmd(vport, ndlp, cmd, 0); 2284 } 2285 return; 2286 2287 case SLI_MGMT_RPA: 2288 /* No retry on Vendor, RPA only done on physical port */ 2289 if (phba->link_flag & LS_CT_VEN_RPA) { 2290 phba->link_flag &= ~LS_CT_VEN_RPA; 2291 lpfc_printf_log(phba, KERN_ERR, 2292 LOG_DISCOVERY | LOG_ELS, 2293 "6460 VEN FDMI RPA failure\n"); 2294 return; 2295 } 2296 if (vport->fdmi_port_mask == LPFC_FDMI2_PORT_ATTR) { 2297 /* Fallback to FDMI-1 */ 2298 vport->fdmi_hba_mask = LPFC_FDMI1_HBA_ATTR; 2299 vport->fdmi_port_mask = LPFC_FDMI1_PORT_ATTR; 2300 /* Start over */ 2301 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA, 0); 2302 return; 2303 } 2304 if (vport->fdmi_port_mask == LPFC_FDMI2_SMART_ATTR) { 2305 vport->fdmi_port_mask = LPFC_FDMI2_PORT_ATTR; 2306 /* Retry the same command */ 2307 lpfc_fdmi_cmd(vport, ndlp, cmd, 0); 2308 } 2309 return; 2310 } 2311 } 2312 2313 /* 2314 * On success, need to cycle thru FDMI registration for discovery 2315 * DHBA -> DPRT -> RHBA -> RPA (physical port) 2316 * DPRT -> RPRT (vports) 2317 */ 2318 switch (cmd) { 2319 case SLI_MGMT_RHBA: 2320 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RPA, 0); 2321 break; 2322 2323 case SLI_MGMT_DHBA: 2324 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DPRT, 0); 2325 break; 2326 2327 case SLI_MGMT_DPRT: 2328 if (vport->port_type == LPFC_PHYSICAL_PORT) 2329 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RHBA, 0); 2330 else 2331 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RPRT, 0); 2332 break; 2333 case SLI_MGMT_RPA: 2334 if (vport->port_type == LPFC_PHYSICAL_PORT && 2335 phba->cfg_enable_mi && 2336 phba->sli4_hba.pc_sli4_params.mi_ver > LPFC_MIB1_SUPPORT) { 2337 /* mi is only for the phyical port, no vports */ 2338 if (phba->link_flag & LS_CT_VEN_RPA) { 2339 lpfc_printf_vlog(vport, KERN_INFO, 2340 LOG_DISCOVERY | LOG_ELS, 2341 "6449 VEN RPA FDMI Success\n"); 2342 phba->link_flag &= ~LS_CT_VEN_RPA; 2343 break; 2344 } 2345 2346 if (lpfc_fdmi_cmd(vport, ndlp, cmd, 2347 LPFC_FDMI_VENDOR_ATTR_mi) == 0) 2348 phba->link_flag |= LS_CT_VEN_RPA; 2349 lpfc_printf_log(phba, KERN_INFO, 2350 LOG_DISCOVERY | LOG_ELS, 2351 "6458 Send MI FDMI:%x Flag x%x\n", 2352 phba->sli4_hba.pc_sli4_params.mi_value, 2353 phba->link_flag); 2354 } else { 2355 lpfc_printf_log(phba, KERN_INFO, 2356 LOG_DISCOVERY | LOG_ELS, 2357 "6459 No FDMI VEN MI support - " 2358 "RPA Success\n"); 2359 } 2360 break; 2361 } 2362 return; 2363 } 2364 2365 2366 /** 2367 * lpfc_fdmi_change_check - Check for changed FDMI parameters 2368 * @vport: pointer to a host virtual N_Port data structure. 2369 * 2370 * Check how many mapped NPorts we are connected to 2371 * Check if our hostname changed 2372 * Called from hbeat timeout routine to check if any FDMI parameters 2373 * changed. If so, re-register those Attributes. 2374 */ 2375 void 2376 lpfc_fdmi_change_check(struct lpfc_vport *vport) 2377 { 2378 struct lpfc_hba *phba = vport->phba; 2379 struct lpfc_nodelist *ndlp; 2380 uint16_t cnt; 2381 2382 if (!lpfc_is_link_up(phba)) 2383 return; 2384 2385 /* Must be connected to a Fabric */ 2386 if (!(vport->fc_flag & FC_FABRIC)) 2387 return; 2388 2389 ndlp = lpfc_findnode_did(vport, FDMI_DID); 2390 if (!ndlp) 2391 return; 2392 2393 /* Check if system hostname changed */ 2394 if (strcmp(phba->os_host_name, init_utsname()->nodename)) { 2395 memset(phba->os_host_name, 0, sizeof(phba->os_host_name)); 2396 scnprintf(phba->os_host_name, sizeof(phba->os_host_name), "%s", 2397 init_utsname()->nodename); 2398 lpfc_ns_cmd(vport, SLI_CTNS_RSNN_NN, 0, 0); 2399 2400 /* Since this effects multiple HBA and PORT attributes, we need 2401 * de-register and go thru the whole FDMI registration cycle. 2402 * DHBA -> DPRT -> RHBA -> RPA (physical port) 2403 * DPRT -> RPRT (vports) 2404 */ 2405 if (vport->port_type == LPFC_PHYSICAL_PORT) { 2406 /* For extra Vendor RPA */ 2407 phba->link_flag &= ~LS_CT_VEN_RPA; 2408 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA, 0); 2409 } else { 2410 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DPRT, 0); 2411 } 2412 2413 /* Since this code path registers all the port attributes 2414 * we can just return without further checking. 2415 */ 2416 return; 2417 } 2418 2419 if (!(vport->fdmi_port_mask & LPFC_FDMI_PORT_ATTR_num_disc)) 2420 return; 2421 2422 /* Check if the number of mapped NPorts changed */ 2423 cnt = lpfc_find_map_node(vport); 2424 if (cnt == vport->fdmi_num_disc) 2425 return; 2426 2427 if (vport->port_type == LPFC_PHYSICAL_PORT) { 2428 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RPA, 2429 LPFC_FDMI_PORT_ATTR_num_disc); 2430 } else { 2431 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RPRT, 2432 LPFC_FDMI_PORT_ATTR_num_disc); 2433 } 2434 } 2435 2436 /* Routines for all individual HBA attributes */ 2437 static int 2438 lpfc_fdmi_hba_attr_wwnn(struct lpfc_vport *vport, struct lpfc_fdmi_attr_def *ad) 2439 { 2440 struct lpfc_fdmi_attr_entry *ae; 2441 uint32_t size; 2442 2443 ae = &ad->AttrValue; 2444 memset(ae, 0, sizeof(*ae)); 2445 2446 memcpy(&ae->un.AttrWWN, &vport->fc_sparam.nodeName, 2447 sizeof(struct lpfc_name)); 2448 size = FOURBYTES + sizeof(struct lpfc_name); 2449 ad->AttrLen = cpu_to_be16(size); 2450 ad->AttrType = cpu_to_be16(RHBA_NODENAME); 2451 return size; 2452 } 2453 static int 2454 lpfc_fdmi_hba_attr_manufacturer(struct lpfc_vport *vport, 2455 struct lpfc_fdmi_attr_def *ad) 2456 { 2457 struct lpfc_fdmi_attr_entry *ae; 2458 uint32_t len, size; 2459 2460 ae = &ad->AttrValue; 2461 memset(ae, 0, sizeof(*ae)); 2462 2463 /* This string MUST be consistent with other FC platforms 2464 * supported by Broadcom. 2465 */ 2466 strncpy(ae->un.AttrString, 2467 "Emulex Corporation", 2468 sizeof(ae->un.AttrString)); 2469 len = strnlen(ae->un.AttrString, 2470 sizeof(ae->un.AttrString)); 2471 len += (len & 3) ? (4 - (len & 3)) : 4; 2472 size = FOURBYTES + len; 2473 ad->AttrLen = cpu_to_be16(size); 2474 ad->AttrType = cpu_to_be16(RHBA_MANUFACTURER); 2475 return size; 2476 } 2477 2478 static int 2479 lpfc_fdmi_hba_attr_sn(struct lpfc_vport *vport, struct lpfc_fdmi_attr_def *ad) 2480 { 2481 struct lpfc_hba *phba = vport->phba; 2482 struct lpfc_fdmi_attr_entry *ae; 2483 uint32_t len, size; 2484 2485 ae = &ad->AttrValue; 2486 memset(ae, 0, sizeof(*ae)); 2487 2488 strncpy(ae->un.AttrString, phba->SerialNumber, 2489 sizeof(ae->un.AttrString)); 2490 len = strnlen(ae->un.AttrString, 2491 sizeof(ae->un.AttrString)); 2492 len += (len & 3) ? (4 - (len & 3)) : 4; 2493 size = FOURBYTES + len; 2494 ad->AttrLen = cpu_to_be16(size); 2495 ad->AttrType = cpu_to_be16(RHBA_SERIAL_NUMBER); 2496 return size; 2497 } 2498 2499 static int 2500 lpfc_fdmi_hba_attr_model(struct lpfc_vport *vport, 2501 struct lpfc_fdmi_attr_def *ad) 2502 { 2503 struct lpfc_hba *phba = vport->phba; 2504 struct lpfc_fdmi_attr_entry *ae; 2505 uint32_t len, size; 2506 2507 ae = &ad->AttrValue; 2508 memset(ae, 0, sizeof(*ae)); 2509 2510 strncpy(ae->un.AttrString, phba->ModelName, 2511 sizeof(ae->un.AttrString)); 2512 len = strnlen(ae->un.AttrString, sizeof(ae->un.AttrString)); 2513 len += (len & 3) ? (4 - (len & 3)) : 4; 2514 size = FOURBYTES + len; 2515 ad->AttrLen = cpu_to_be16(size); 2516 ad->AttrType = cpu_to_be16(RHBA_MODEL); 2517 return size; 2518 } 2519 2520 static int 2521 lpfc_fdmi_hba_attr_description(struct lpfc_vport *vport, 2522 struct lpfc_fdmi_attr_def *ad) 2523 { 2524 struct lpfc_hba *phba = vport->phba; 2525 struct lpfc_fdmi_attr_entry *ae; 2526 uint32_t len, size; 2527 2528 ae = &ad->AttrValue; 2529 memset(ae, 0, sizeof(*ae)); 2530 2531 strncpy(ae->un.AttrString, phba->ModelDesc, 2532 sizeof(ae->un.AttrString)); 2533 len = strnlen(ae->un.AttrString, 2534 sizeof(ae->un.AttrString)); 2535 len += (len & 3) ? (4 - (len & 3)) : 4; 2536 size = FOURBYTES + len; 2537 ad->AttrLen = cpu_to_be16(size); 2538 ad->AttrType = cpu_to_be16(RHBA_MODEL_DESCRIPTION); 2539 return size; 2540 } 2541 2542 static int 2543 lpfc_fdmi_hba_attr_hdw_ver(struct lpfc_vport *vport, 2544 struct lpfc_fdmi_attr_def *ad) 2545 { 2546 struct lpfc_hba *phba = vport->phba; 2547 lpfc_vpd_t *vp = &phba->vpd; 2548 struct lpfc_fdmi_attr_entry *ae; 2549 uint32_t i, j, incr, size; 2550 2551 ae = &ad->AttrValue; 2552 memset(ae, 0, sizeof(*ae)); 2553 2554 /* Convert JEDEC ID to ascii for hardware version */ 2555 incr = vp->rev.biuRev; 2556 for (i = 0; i < 8; i++) { 2557 j = (incr & 0xf); 2558 if (j <= 9) 2559 ae->un.AttrString[7 - i] = 2560 (char)((uint8_t) 0x30 + 2561 (uint8_t) j); 2562 else 2563 ae->un.AttrString[7 - i] = 2564 (char)((uint8_t) 0x61 + 2565 (uint8_t) (j - 10)); 2566 incr = (incr >> 4); 2567 } 2568 size = FOURBYTES + 8; 2569 ad->AttrLen = cpu_to_be16(size); 2570 ad->AttrType = cpu_to_be16(RHBA_HARDWARE_VERSION); 2571 return size; 2572 } 2573 2574 static int 2575 lpfc_fdmi_hba_attr_drvr_ver(struct lpfc_vport *vport, 2576 struct lpfc_fdmi_attr_def *ad) 2577 { 2578 struct lpfc_fdmi_attr_entry *ae; 2579 uint32_t len, size; 2580 2581 ae = &ad->AttrValue; 2582 memset(ae, 0, sizeof(*ae)); 2583 2584 strncpy(ae->un.AttrString, lpfc_release_version, 2585 sizeof(ae->un.AttrString)); 2586 len = strnlen(ae->un.AttrString, 2587 sizeof(ae->un.AttrString)); 2588 len += (len & 3) ? (4 - (len & 3)) : 4; 2589 size = FOURBYTES + len; 2590 ad->AttrLen = cpu_to_be16(size); 2591 ad->AttrType = cpu_to_be16(RHBA_DRIVER_VERSION); 2592 return size; 2593 } 2594 2595 static int 2596 lpfc_fdmi_hba_attr_rom_ver(struct lpfc_vport *vport, 2597 struct lpfc_fdmi_attr_def *ad) 2598 { 2599 struct lpfc_hba *phba = vport->phba; 2600 struct lpfc_fdmi_attr_entry *ae; 2601 uint32_t len, size; 2602 2603 ae = &ad->AttrValue; 2604 memset(ae, 0, sizeof(*ae)); 2605 2606 if (phba->sli_rev == LPFC_SLI_REV4) 2607 lpfc_decode_firmware_rev(phba, ae->un.AttrString, 1); 2608 else 2609 strncpy(ae->un.AttrString, phba->OptionROMVersion, 2610 sizeof(ae->un.AttrString)); 2611 len = strnlen(ae->un.AttrString, 2612 sizeof(ae->un.AttrString)); 2613 len += (len & 3) ? (4 - (len & 3)) : 4; 2614 size = FOURBYTES + len; 2615 ad->AttrLen = cpu_to_be16(size); 2616 ad->AttrType = cpu_to_be16(RHBA_OPTION_ROM_VERSION); 2617 return size; 2618 } 2619 2620 static int 2621 lpfc_fdmi_hba_attr_fmw_ver(struct lpfc_vport *vport, 2622 struct lpfc_fdmi_attr_def *ad) 2623 { 2624 struct lpfc_hba *phba = vport->phba; 2625 struct lpfc_fdmi_attr_entry *ae; 2626 uint32_t len, size; 2627 2628 ae = &ad->AttrValue; 2629 memset(ae, 0, sizeof(*ae)); 2630 2631 lpfc_decode_firmware_rev(phba, ae->un.AttrString, 1); 2632 len = strnlen(ae->un.AttrString, 2633 sizeof(ae->un.AttrString)); 2634 len += (len & 3) ? (4 - (len & 3)) : 4; 2635 size = FOURBYTES + len; 2636 ad->AttrLen = cpu_to_be16(size); 2637 ad->AttrType = cpu_to_be16(RHBA_FIRMWARE_VERSION); 2638 return size; 2639 } 2640 2641 static int 2642 lpfc_fdmi_hba_attr_os_ver(struct lpfc_vport *vport, 2643 struct lpfc_fdmi_attr_def *ad) 2644 { 2645 struct lpfc_fdmi_attr_entry *ae; 2646 uint32_t len, size; 2647 2648 ae = &ad->AttrValue; 2649 memset(ae, 0, sizeof(*ae)); 2650 2651 snprintf(ae->un.AttrString, sizeof(ae->un.AttrString), "%s %s %s", 2652 init_utsname()->sysname, 2653 init_utsname()->release, 2654 init_utsname()->version); 2655 2656 len = strnlen(ae->un.AttrString, sizeof(ae->un.AttrString)); 2657 len += (len & 3) ? (4 - (len & 3)) : 4; 2658 size = FOURBYTES + len; 2659 ad->AttrLen = cpu_to_be16(size); 2660 ad->AttrType = cpu_to_be16(RHBA_OS_NAME_VERSION); 2661 return size; 2662 } 2663 2664 static int 2665 lpfc_fdmi_hba_attr_ct_len(struct lpfc_vport *vport, 2666 struct lpfc_fdmi_attr_def *ad) 2667 { 2668 struct lpfc_fdmi_attr_entry *ae; 2669 uint32_t size; 2670 2671 ae = &ad->AttrValue; 2672 2673 ae->un.AttrInt = cpu_to_be32(LPFC_MAX_CT_SIZE); 2674 size = FOURBYTES + sizeof(uint32_t); 2675 ad->AttrLen = cpu_to_be16(size); 2676 ad->AttrType = cpu_to_be16(RHBA_MAX_CT_PAYLOAD_LEN); 2677 return size; 2678 } 2679 2680 static int 2681 lpfc_fdmi_hba_attr_symbolic_name(struct lpfc_vport *vport, 2682 struct lpfc_fdmi_attr_def *ad) 2683 { 2684 struct lpfc_fdmi_attr_entry *ae; 2685 uint32_t len, size; 2686 2687 ae = &ad->AttrValue; 2688 memset(ae, 0, sizeof(*ae)); 2689 2690 len = lpfc_vport_symbolic_node_name(vport, 2691 ae->un.AttrString, 256); 2692 len += (len & 3) ? (4 - (len & 3)) : 4; 2693 size = FOURBYTES + len; 2694 ad->AttrLen = cpu_to_be16(size); 2695 ad->AttrType = cpu_to_be16(RHBA_SYM_NODENAME); 2696 return size; 2697 } 2698 2699 static int 2700 lpfc_fdmi_hba_attr_vendor_info(struct lpfc_vport *vport, 2701 struct lpfc_fdmi_attr_def *ad) 2702 { 2703 struct lpfc_fdmi_attr_entry *ae; 2704 uint32_t size; 2705 2706 ae = &ad->AttrValue; 2707 2708 /* Nothing is defined for this currently */ 2709 ae->un.AttrInt = cpu_to_be32(0); 2710 size = FOURBYTES + sizeof(uint32_t); 2711 ad->AttrLen = cpu_to_be16(size); 2712 ad->AttrType = cpu_to_be16(RHBA_VENDOR_INFO); 2713 return size; 2714 } 2715 2716 static int 2717 lpfc_fdmi_hba_attr_num_ports(struct lpfc_vport *vport, 2718 struct lpfc_fdmi_attr_def *ad) 2719 { 2720 struct lpfc_fdmi_attr_entry *ae; 2721 uint32_t size; 2722 2723 ae = &ad->AttrValue; 2724 2725 /* Each driver instance corresponds to a single port */ 2726 ae->un.AttrInt = cpu_to_be32(1); 2727 size = FOURBYTES + sizeof(uint32_t); 2728 ad->AttrLen = cpu_to_be16(size); 2729 ad->AttrType = cpu_to_be16(RHBA_NUM_PORTS); 2730 return size; 2731 } 2732 2733 static int 2734 lpfc_fdmi_hba_attr_fabric_wwnn(struct lpfc_vport *vport, 2735 struct lpfc_fdmi_attr_def *ad) 2736 { 2737 struct lpfc_fdmi_attr_entry *ae; 2738 uint32_t size; 2739 2740 ae = &ad->AttrValue; 2741 memset(ae, 0, sizeof(*ae)); 2742 2743 memcpy(&ae->un.AttrWWN, &vport->fabric_nodename, 2744 sizeof(struct lpfc_name)); 2745 size = FOURBYTES + sizeof(struct lpfc_name); 2746 ad->AttrLen = cpu_to_be16(size); 2747 ad->AttrType = cpu_to_be16(RHBA_FABRIC_WWNN); 2748 return size; 2749 } 2750 2751 static int 2752 lpfc_fdmi_hba_attr_bios_ver(struct lpfc_vport *vport, 2753 struct lpfc_fdmi_attr_def *ad) 2754 { 2755 struct lpfc_hba *phba = vport->phba; 2756 struct lpfc_fdmi_attr_entry *ae; 2757 uint32_t len, size; 2758 2759 ae = &ad->AttrValue; 2760 memset(ae, 0, sizeof(*ae)); 2761 2762 strlcat(ae->un.AttrString, phba->BIOSVersion, 2763 sizeof(ae->un.AttrString)); 2764 len = strnlen(ae->un.AttrString, 2765 sizeof(ae->un.AttrString)); 2766 len += (len & 3) ? (4 - (len & 3)) : 4; 2767 size = FOURBYTES + len; 2768 ad->AttrLen = cpu_to_be16(size); 2769 ad->AttrType = cpu_to_be16(RHBA_BIOS_VERSION); 2770 return size; 2771 } 2772 2773 static int 2774 lpfc_fdmi_hba_attr_bios_state(struct lpfc_vport *vport, 2775 struct lpfc_fdmi_attr_def *ad) 2776 { 2777 struct lpfc_fdmi_attr_entry *ae; 2778 uint32_t size; 2779 2780 ae = &ad->AttrValue; 2781 2782 /* Driver doesn't have access to this information */ 2783 ae->un.AttrInt = cpu_to_be32(0); 2784 size = FOURBYTES + sizeof(uint32_t); 2785 ad->AttrLen = cpu_to_be16(size); 2786 ad->AttrType = cpu_to_be16(RHBA_BIOS_STATE); 2787 return size; 2788 } 2789 2790 static int 2791 lpfc_fdmi_hba_attr_vendor_id(struct lpfc_vport *vport, 2792 struct lpfc_fdmi_attr_def *ad) 2793 { 2794 struct lpfc_fdmi_attr_entry *ae; 2795 uint32_t len, size; 2796 2797 ae = &ad->AttrValue; 2798 memset(ae, 0, sizeof(*ae)); 2799 2800 strncpy(ae->un.AttrString, "EMULEX", 2801 sizeof(ae->un.AttrString)); 2802 len = strnlen(ae->un.AttrString, 2803 sizeof(ae->un.AttrString)); 2804 len += (len & 3) ? (4 - (len & 3)) : 4; 2805 size = FOURBYTES + len; 2806 ad->AttrLen = cpu_to_be16(size); 2807 ad->AttrType = cpu_to_be16(RHBA_VENDOR_ID); 2808 return size; 2809 } 2810 2811 /* Routines for all individual PORT attributes */ 2812 static int 2813 lpfc_fdmi_port_attr_fc4type(struct lpfc_vport *vport, 2814 struct lpfc_fdmi_attr_def *ad) 2815 { 2816 struct lpfc_hba *phba = vport->phba; 2817 struct lpfc_fdmi_attr_entry *ae; 2818 uint32_t size; 2819 2820 ae = &ad->AttrValue; 2821 memset(ae, 0, sizeof(*ae)); 2822 2823 ae->un.AttrTypes[2] = 0x01; /* Type 0x8 - FCP */ 2824 ae->un.AttrTypes[7] = 0x01; /* Type 0x20 - CT */ 2825 2826 /* Check to see if Firmware supports NVME and on physical port */ 2827 if ((phba->sli_rev == LPFC_SLI_REV4) && (vport == phba->pport) && 2828 phba->sli4_hba.pc_sli4_params.nvme) 2829 ae->un.AttrTypes[6] = 0x01; /* Type 0x28 - NVME */ 2830 2831 size = FOURBYTES + 32; 2832 ad->AttrLen = cpu_to_be16(size); 2833 ad->AttrType = cpu_to_be16(RPRT_SUPPORTED_FC4_TYPES); 2834 return size; 2835 } 2836 2837 static int 2838 lpfc_fdmi_port_attr_support_speed(struct lpfc_vport *vport, 2839 struct lpfc_fdmi_attr_def *ad) 2840 { 2841 struct lpfc_hba *phba = vport->phba; 2842 struct lpfc_fdmi_attr_entry *ae; 2843 uint32_t size; 2844 2845 ae = &ad->AttrValue; 2846 2847 ae->un.AttrInt = 0; 2848 if (!(phba->hba_flag & HBA_FCOE_MODE)) { 2849 if (phba->lmt & LMT_256Gb) 2850 ae->un.AttrInt |= HBA_PORTSPEED_256GFC; 2851 if (phba->lmt & LMT_128Gb) 2852 ae->un.AttrInt |= HBA_PORTSPEED_128GFC; 2853 if (phba->lmt & LMT_64Gb) 2854 ae->un.AttrInt |= HBA_PORTSPEED_64GFC; 2855 if (phba->lmt & LMT_32Gb) 2856 ae->un.AttrInt |= HBA_PORTSPEED_32GFC; 2857 if (phba->lmt & LMT_16Gb) 2858 ae->un.AttrInt |= HBA_PORTSPEED_16GFC; 2859 if (phba->lmt & LMT_10Gb) 2860 ae->un.AttrInt |= HBA_PORTSPEED_10GFC; 2861 if (phba->lmt & LMT_8Gb) 2862 ae->un.AttrInt |= HBA_PORTSPEED_8GFC; 2863 if (phba->lmt & LMT_4Gb) 2864 ae->un.AttrInt |= HBA_PORTSPEED_4GFC; 2865 if (phba->lmt & LMT_2Gb) 2866 ae->un.AttrInt |= HBA_PORTSPEED_2GFC; 2867 if (phba->lmt & LMT_1Gb) 2868 ae->un.AttrInt |= HBA_PORTSPEED_1GFC; 2869 } else { 2870 /* FCoE links support only one speed */ 2871 switch (phba->fc_linkspeed) { 2872 case LPFC_ASYNC_LINK_SPEED_10GBPS: 2873 ae->un.AttrInt = HBA_PORTSPEED_10GE; 2874 break; 2875 case LPFC_ASYNC_LINK_SPEED_25GBPS: 2876 ae->un.AttrInt = HBA_PORTSPEED_25GE; 2877 break; 2878 case LPFC_ASYNC_LINK_SPEED_40GBPS: 2879 ae->un.AttrInt = HBA_PORTSPEED_40GE; 2880 break; 2881 case LPFC_ASYNC_LINK_SPEED_100GBPS: 2882 ae->un.AttrInt = HBA_PORTSPEED_100GE; 2883 break; 2884 } 2885 } 2886 ae->un.AttrInt = cpu_to_be32(ae->un.AttrInt); 2887 size = FOURBYTES + sizeof(uint32_t); 2888 ad->AttrLen = cpu_to_be16(size); 2889 ad->AttrType = cpu_to_be16(RPRT_SUPPORTED_SPEED); 2890 return size; 2891 } 2892 2893 static int 2894 lpfc_fdmi_port_attr_speed(struct lpfc_vport *vport, 2895 struct lpfc_fdmi_attr_def *ad) 2896 { 2897 struct lpfc_hba *phba = vport->phba; 2898 struct lpfc_fdmi_attr_entry *ae; 2899 uint32_t size; 2900 2901 ae = &ad->AttrValue; 2902 2903 if (!(phba->hba_flag & HBA_FCOE_MODE)) { 2904 switch (phba->fc_linkspeed) { 2905 case LPFC_LINK_SPEED_1GHZ: 2906 ae->un.AttrInt = HBA_PORTSPEED_1GFC; 2907 break; 2908 case LPFC_LINK_SPEED_2GHZ: 2909 ae->un.AttrInt = HBA_PORTSPEED_2GFC; 2910 break; 2911 case LPFC_LINK_SPEED_4GHZ: 2912 ae->un.AttrInt = HBA_PORTSPEED_4GFC; 2913 break; 2914 case LPFC_LINK_SPEED_8GHZ: 2915 ae->un.AttrInt = HBA_PORTSPEED_8GFC; 2916 break; 2917 case LPFC_LINK_SPEED_10GHZ: 2918 ae->un.AttrInt = HBA_PORTSPEED_10GFC; 2919 break; 2920 case LPFC_LINK_SPEED_16GHZ: 2921 ae->un.AttrInt = HBA_PORTSPEED_16GFC; 2922 break; 2923 case LPFC_LINK_SPEED_32GHZ: 2924 ae->un.AttrInt = HBA_PORTSPEED_32GFC; 2925 break; 2926 case LPFC_LINK_SPEED_64GHZ: 2927 ae->un.AttrInt = HBA_PORTSPEED_64GFC; 2928 break; 2929 case LPFC_LINK_SPEED_128GHZ: 2930 ae->un.AttrInt = HBA_PORTSPEED_128GFC; 2931 break; 2932 case LPFC_LINK_SPEED_256GHZ: 2933 ae->un.AttrInt = HBA_PORTSPEED_256GFC; 2934 break; 2935 default: 2936 ae->un.AttrInt = HBA_PORTSPEED_UNKNOWN; 2937 break; 2938 } 2939 } else { 2940 switch (phba->fc_linkspeed) { 2941 case LPFC_ASYNC_LINK_SPEED_10GBPS: 2942 ae->un.AttrInt = HBA_PORTSPEED_10GE; 2943 break; 2944 case LPFC_ASYNC_LINK_SPEED_25GBPS: 2945 ae->un.AttrInt = HBA_PORTSPEED_25GE; 2946 break; 2947 case LPFC_ASYNC_LINK_SPEED_40GBPS: 2948 ae->un.AttrInt = HBA_PORTSPEED_40GE; 2949 break; 2950 case LPFC_ASYNC_LINK_SPEED_100GBPS: 2951 ae->un.AttrInt = HBA_PORTSPEED_100GE; 2952 break; 2953 default: 2954 ae->un.AttrInt = HBA_PORTSPEED_UNKNOWN; 2955 break; 2956 } 2957 } 2958 2959 ae->un.AttrInt = cpu_to_be32(ae->un.AttrInt); 2960 size = FOURBYTES + sizeof(uint32_t); 2961 ad->AttrLen = cpu_to_be16(size); 2962 ad->AttrType = cpu_to_be16(RPRT_PORT_SPEED); 2963 return size; 2964 } 2965 2966 static int 2967 lpfc_fdmi_port_attr_max_frame(struct lpfc_vport *vport, 2968 struct lpfc_fdmi_attr_def *ad) 2969 { 2970 struct serv_parm *hsp; 2971 struct lpfc_fdmi_attr_entry *ae; 2972 uint32_t size; 2973 2974 ae = &ad->AttrValue; 2975 2976 hsp = (struct serv_parm *)&vport->fc_sparam; 2977 ae->un.AttrInt = (((uint32_t) hsp->cmn.bbRcvSizeMsb & 0x0F) << 8) | 2978 (uint32_t) hsp->cmn.bbRcvSizeLsb; 2979 ae->un.AttrInt = cpu_to_be32(ae->un.AttrInt); 2980 size = FOURBYTES + sizeof(uint32_t); 2981 ad->AttrLen = cpu_to_be16(size); 2982 ad->AttrType = cpu_to_be16(RPRT_MAX_FRAME_SIZE); 2983 return size; 2984 } 2985 2986 static int 2987 lpfc_fdmi_port_attr_os_devname(struct lpfc_vport *vport, 2988 struct lpfc_fdmi_attr_def *ad) 2989 { 2990 struct Scsi_Host *shost = lpfc_shost_from_vport(vport); 2991 struct lpfc_fdmi_attr_entry *ae; 2992 uint32_t len, size; 2993 2994 ae = &ad->AttrValue; 2995 memset(ae, 0, sizeof(*ae)); 2996 2997 snprintf(ae->un.AttrString, sizeof(ae->un.AttrString), 2998 "/sys/class/scsi_host/host%d", shost->host_no); 2999 len = strnlen((char *)ae->un.AttrString, 3000 sizeof(ae->un.AttrString)); 3001 len += (len & 3) ? (4 - (len & 3)) : 4; 3002 size = FOURBYTES + len; 3003 ad->AttrLen = cpu_to_be16(size); 3004 ad->AttrType = cpu_to_be16(RPRT_OS_DEVICE_NAME); 3005 return size; 3006 } 3007 3008 static int 3009 lpfc_fdmi_port_attr_host_name(struct lpfc_vport *vport, 3010 struct lpfc_fdmi_attr_def *ad) 3011 { 3012 struct lpfc_fdmi_attr_entry *ae; 3013 uint32_t len, size; 3014 3015 ae = &ad->AttrValue; 3016 memset(ae, 0, sizeof(*ae)); 3017 3018 scnprintf(ae->un.AttrString, sizeof(ae->un.AttrString), "%s", 3019 vport->phba->os_host_name); 3020 3021 len = strnlen(ae->un.AttrString, sizeof(ae->un.AttrString)); 3022 len += (len & 3) ? (4 - (len & 3)) : 4; 3023 size = FOURBYTES + len; 3024 ad->AttrLen = cpu_to_be16(size); 3025 ad->AttrType = cpu_to_be16(RPRT_HOST_NAME); 3026 return size; 3027 } 3028 3029 static int 3030 lpfc_fdmi_port_attr_wwnn(struct lpfc_vport *vport, 3031 struct lpfc_fdmi_attr_def *ad) 3032 { 3033 struct lpfc_fdmi_attr_entry *ae; 3034 uint32_t size; 3035 3036 ae = &ad->AttrValue; 3037 memset(ae, 0, sizeof(*ae)); 3038 3039 memcpy(&ae->un.AttrWWN, &vport->fc_sparam.nodeName, 3040 sizeof(struct lpfc_name)); 3041 size = FOURBYTES + sizeof(struct lpfc_name); 3042 ad->AttrLen = cpu_to_be16(size); 3043 ad->AttrType = cpu_to_be16(RPRT_NODENAME); 3044 return size; 3045 } 3046 3047 static int 3048 lpfc_fdmi_port_attr_wwpn(struct lpfc_vport *vport, 3049 struct lpfc_fdmi_attr_def *ad) 3050 { 3051 struct lpfc_fdmi_attr_entry *ae; 3052 uint32_t size; 3053 3054 ae = &ad->AttrValue; 3055 memset(ae, 0, sizeof(*ae)); 3056 3057 memcpy(&ae->un.AttrWWN, &vport->fc_sparam.portName, 3058 sizeof(struct lpfc_name)); 3059 size = FOURBYTES + sizeof(struct lpfc_name); 3060 ad->AttrLen = cpu_to_be16(size); 3061 ad->AttrType = cpu_to_be16(RPRT_PORTNAME); 3062 return size; 3063 } 3064 3065 static int 3066 lpfc_fdmi_port_attr_symbolic_name(struct lpfc_vport *vport, 3067 struct lpfc_fdmi_attr_def *ad) 3068 { 3069 struct lpfc_fdmi_attr_entry *ae; 3070 uint32_t len, size; 3071 3072 ae = &ad->AttrValue; 3073 memset(ae, 0, sizeof(*ae)); 3074 3075 len = lpfc_vport_symbolic_port_name(vport, ae->un.AttrString, 256); 3076 len += (len & 3) ? (4 - (len & 3)) : 4; 3077 size = FOURBYTES + len; 3078 ad->AttrLen = cpu_to_be16(size); 3079 ad->AttrType = cpu_to_be16(RPRT_SYM_PORTNAME); 3080 return size; 3081 } 3082 3083 static int 3084 lpfc_fdmi_port_attr_port_type(struct lpfc_vport *vport, 3085 struct lpfc_fdmi_attr_def *ad) 3086 { 3087 struct lpfc_hba *phba = vport->phba; 3088 struct lpfc_fdmi_attr_entry *ae; 3089 uint32_t size; 3090 3091 ae = &ad->AttrValue; 3092 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) 3093 ae->un.AttrInt = cpu_to_be32(LPFC_FDMI_PORTTYPE_NLPORT); 3094 else 3095 ae->un.AttrInt = cpu_to_be32(LPFC_FDMI_PORTTYPE_NPORT); 3096 size = FOURBYTES + sizeof(uint32_t); 3097 ad->AttrLen = cpu_to_be16(size); 3098 ad->AttrType = cpu_to_be16(RPRT_PORT_TYPE); 3099 return size; 3100 } 3101 3102 static int 3103 lpfc_fdmi_port_attr_class(struct lpfc_vport *vport, 3104 struct lpfc_fdmi_attr_def *ad) 3105 { 3106 struct lpfc_fdmi_attr_entry *ae; 3107 uint32_t size; 3108 3109 ae = &ad->AttrValue; 3110 ae->un.AttrInt = cpu_to_be32(FC_COS_CLASS2 | FC_COS_CLASS3); 3111 size = FOURBYTES + sizeof(uint32_t); 3112 ad->AttrLen = cpu_to_be16(size); 3113 ad->AttrType = cpu_to_be16(RPRT_SUPPORTED_CLASS); 3114 return size; 3115 } 3116 3117 static int 3118 lpfc_fdmi_port_attr_fabric_wwpn(struct lpfc_vport *vport, 3119 struct lpfc_fdmi_attr_def *ad) 3120 { 3121 struct lpfc_fdmi_attr_entry *ae; 3122 uint32_t size; 3123 3124 ae = &ad->AttrValue; 3125 memset(ae, 0, sizeof(*ae)); 3126 3127 memcpy(&ae->un.AttrWWN, &vport->fabric_portname, 3128 sizeof(struct lpfc_name)); 3129 size = FOURBYTES + sizeof(struct lpfc_name); 3130 ad->AttrLen = cpu_to_be16(size); 3131 ad->AttrType = cpu_to_be16(RPRT_FABRICNAME); 3132 return size; 3133 } 3134 3135 static int 3136 lpfc_fdmi_port_attr_active_fc4type(struct lpfc_vport *vport, 3137 struct lpfc_fdmi_attr_def *ad) 3138 { 3139 struct lpfc_fdmi_attr_entry *ae; 3140 uint32_t size; 3141 3142 ae = &ad->AttrValue; 3143 memset(ae, 0, sizeof(*ae)); 3144 3145 ae->un.AttrTypes[2] = 0x01; /* Type 0x8 - FCP */ 3146 ae->un.AttrTypes[7] = 0x01; /* Type 0x20 - CT */ 3147 3148 /* Check to see if NVME is configured or not */ 3149 if (vport->phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) 3150 ae->un.AttrTypes[6] = 0x1; /* Type 0x28 - NVME */ 3151 3152 size = FOURBYTES + 32; 3153 ad->AttrLen = cpu_to_be16(size); 3154 ad->AttrType = cpu_to_be16(RPRT_ACTIVE_FC4_TYPES); 3155 return size; 3156 } 3157 3158 static int 3159 lpfc_fdmi_port_attr_port_state(struct lpfc_vport *vport, 3160 struct lpfc_fdmi_attr_def *ad) 3161 { 3162 struct lpfc_fdmi_attr_entry *ae; 3163 uint32_t size; 3164 3165 ae = &ad->AttrValue; 3166 /* Link Up - operational */ 3167 ae->un.AttrInt = cpu_to_be32(LPFC_FDMI_PORTSTATE_ONLINE); 3168 size = FOURBYTES + sizeof(uint32_t); 3169 ad->AttrLen = cpu_to_be16(size); 3170 ad->AttrType = cpu_to_be16(RPRT_PORT_STATE); 3171 return size; 3172 } 3173 3174 static int 3175 lpfc_fdmi_port_attr_num_disc(struct lpfc_vport *vport, 3176 struct lpfc_fdmi_attr_def *ad) 3177 { 3178 struct lpfc_fdmi_attr_entry *ae; 3179 uint32_t size; 3180 3181 ae = &ad->AttrValue; 3182 vport->fdmi_num_disc = lpfc_find_map_node(vport); 3183 ae->un.AttrInt = cpu_to_be32(vport->fdmi_num_disc); 3184 size = FOURBYTES + sizeof(uint32_t); 3185 ad->AttrLen = cpu_to_be16(size); 3186 ad->AttrType = cpu_to_be16(RPRT_DISC_PORT); 3187 return size; 3188 } 3189 3190 static int 3191 lpfc_fdmi_port_attr_nportid(struct lpfc_vport *vport, 3192 struct lpfc_fdmi_attr_def *ad) 3193 { 3194 struct lpfc_fdmi_attr_entry *ae; 3195 uint32_t size; 3196 3197 ae = &ad->AttrValue; 3198 ae->un.AttrInt = cpu_to_be32(vport->fc_myDID); 3199 size = FOURBYTES + sizeof(uint32_t); 3200 ad->AttrLen = cpu_to_be16(size); 3201 ad->AttrType = cpu_to_be16(RPRT_PORT_ID); 3202 return size; 3203 } 3204 3205 static int 3206 lpfc_fdmi_smart_attr_service(struct lpfc_vport *vport, 3207 struct lpfc_fdmi_attr_def *ad) 3208 { 3209 struct lpfc_fdmi_attr_entry *ae; 3210 uint32_t len, size; 3211 3212 ae = &ad->AttrValue; 3213 memset(ae, 0, sizeof(*ae)); 3214 3215 strncpy(ae->un.AttrString, "Smart SAN Initiator", 3216 sizeof(ae->un.AttrString)); 3217 len = strnlen(ae->un.AttrString, 3218 sizeof(ae->un.AttrString)); 3219 len += (len & 3) ? (4 - (len & 3)) : 4; 3220 size = FOURBYTES + len; 3221 ad->AttrLen = cpu_to_be16(size); 3222 ad->AttrType = cpu_to_be16(RPRT_SMART_SERVICE); 3223 return size; 3224 } 3225 3226 static int 3227 lpfc_fdmi_smart_attr_guid(struct lpfc_vport *vport, 3228 struct lpfc_fdmi_attr_def *ad) 3229 { 3230 struct lpfc_fdmi_attr_entry *ae; 3231 uint32_t size; 3232 3233 ae = &ad->AttrValue; 3234 memset(ae, 0, sizeof(*ae)); 3235 3236 memcpy(&ae->un.AttrString, &vport->fc_sparam.nodeName, 3237 sizeof(struct lpfc_name)); 3238 memcpy((((uint8_t *)&ae->un.AttrString) + 3239 sizeof(struct lpfc_name)), 3240 &vport->fc_sparam.portName, sizeof(struct lpfc_name)); 3241 size = FOURBYTES + (2 * sizeof(struct lpfc_name)); 3242 ad->AttrLen = cpu_to_be16(size); 3243 ad->AttrType = cpu_to_be16(RPRT_SMART_GUID); 3244 return size; 3245 } 3246 3247 static int 3248 lpfc_fdmi_smart_attr_version(struct lpfc_vport *vport, 3249 struct lpfc_fdmi_attr_def *ad) 3250 { 3251 struct lpfc_fdmi_attr_entry *ae; 3252 uint32_t len, size; 3253 3254 ae = &ad->AttrValue; 3255 memset(ae, 0, sizeof(*ae)); 3256 3257 strncpy(ae->un.AttrString, "Smart SAN Version 2.0", 3258 sizeof(ae->un.AttrString)); 3259 len = strnlen(ae->un.AttrString, 3260 sizeof(ae->un.AttrString)); 3261 len += (len & 3) ? (4 - (len & 3)) : 4; 3262 size = FOURBYTES + len; 3263 ad->AttrLen = cpu_to_be16(size); 3264 ad->AttrType = cpu_to_be16(RPRT_SMART_VERSION); 3265 return size; 3266 } 3267 3268 static int 3269 lpfc_fdmi_smart_attr_model(struct lpfc_vport *vport, 3270 struct lpfc_fdmi_attr_def *ad) 3271 { 3272 struct lpfc_hba *phba = vport->phba; 3273 struct lpfc_fdmi_attr_entry *ae; 3274 uint32_t len, size; 3275 3276 ae = &ad->AttrValue; 3277 memset(ae, 0, sizeof(*ae)); 3278 3279 strncpy(ae->un.AttrString, phba->ModelName, 3280 sizeof(ae->un.AttrString)); 3281 len = strnlen(ae->un.AttrString, sizeof(ae->un.AttrString)); 3282 len += (len & 3) ? (4 - (len & 3)) : 4; 3283 size = FOURBYTES + len; 3284 ad->AttrLen = cpu_to_be16(size); 3285 ad->AttrType = cpu_to_be16(RPRT_SMART_MODEL); 3286 return size; 3287 } 3288 3289 static int 3290 lpfc_fdmi_smart_attr_port_info(struct lpfc_vport *vport, 3291 struct lpfc_fdmi_attr_def *ad) 3292 { 3293 struct lpfc_fdmi_attr_entry *ae; 3294 uint32_t size; 3295 3296 ae = &ad->AttrValue; 3297 3298 /* SRIOV (type 3) is not supported */ 3299 if (vport->vpi) 3300 ae->un.AttrInt = cpu_to_be32(2); /* NPIV */ 3301 else 3302 ae->un.AttrInt = cpu_to_be32(1); /* Physical */ 3303 size = FOURBYTES + sizeof(uint32_t); 3304 ad->AttrLen = cpu_to_be16(size); 3305 ad->AttrType = cpu_to_be16(RPRT_SMART_PORT_INFO); 3306 return size; 3307 } 3308 3309 static int 3310 lpfc_fdmi_smart_attr_qos(struct lpfc_vport *vport, 3311 struct lpfc_fdmi_attr_def *ad) 3312 { 3313 struct lpfc_fdmi_attr_entry *ae; 3314 uint32_t size; 3315 3316 ae = &ad->AttrValue; 3317 ae->un.AttrInt = cpu_to_be32(0); 3318 size = FOURBYTES + sizeof(uint32_t); 3319 ad->AttrLen = cpu_to_be16(size); 3320 ad->AttrType = cpu_to_be16(RPRT_SMART_QOS); 3321 return size; 3322 } 3323 3324 static int 3325 lpfc_fdmi_smart_attr_security(struct lpfc_vport *vport, 3326 struct lpfc_fdmi_attr_def *ad) 3327 { 3328 struct lpfc_fdmi_attr_entry *ae; 3329 uint32_t size; 3330 3331 ae = &ad->AttrValue; 3332 ae->un.AttrInt = cpu_to_be32(1); 3333 size = FOURBYTES + sizeof(uint32_t); 3334 ad->AttrLen = cpu_to_be16(size); 3335 ad->AttrType = cpu_to_be16(RPRT_SMART_SECURITY); 3336 return size; 3337 } 3338 3339 static int 3340 lpfc_fdmi_vendor_attr_mi(struct lpfc_vport *vport, 3341 struct lpfc_fdmi_attr_def *ad) 3342 { 3343 struct lpfc_hba *phba = vport->phba; 3344 struct lpfc_fdmi_attr_entry *ae; 3345 uint32_t len, size; 3346 char mibrevision[16]; 3347 3348 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue; 3349 memset(ae, 0, 256); 3350 sprintf(mibrevision, "ELXE2EM:%04d", 3351 phba->sli4_hba.pc_sli4_params.mi_value); 3352 strncpy(ae->un.AttrString, &mibrevision[0], sizeof(ae->un.AttrString)); 3353 len = strnlen(ae->un.AttrString, sizeof(ae->un.AttrString)); 3354 len += (len & 3) ? (4 - (len & 3)) : 4; 3355 size = FOURBYTES + len; 3356 ad->AttrLen = cpu_to_be16(size); 3357 ad->AttrType = cpu_to_be16(RPRT_VENDOR_MI); 3358 return size; 3359 } 3360 3361 /* RHBA attribute jump table */ 3362 int (*lpfc_fdmi_hba_action[]) 3363 (struct lpfc_vport *vport, struct lpfc_fdmi_attr_def *ad) = { 3364 /* Action routine Mask bit Attribute type */ 3365 lpfc_fdmi_hba_attr_wwnn, /* bit0 RHBA_NODENAME */ 3366 lpfc_fdmi_hba_attr_manufacturer, /* bit1 RHBA_MANUFACTURER */ 3367 lpfc_fdmi_hba_attr_sn, /* bit2 RHBA_SERIAL_NUMBER */ 3368 lpfc_fdmi_hba_attr_model, /* bit3 RHBA_MODEL */ 3369 lpfc_fdmi_hba_attr_description, /* bit4 RHBA_MODEL_DESCRIPTION */ 3370 lpfc_fdmi_hba_attr_hdw_ver, /* bit5 RHBA_HARDWARE_VERSION */ 3371 lpfc_fdmi_hba_attr_drvr_ver, /* bit6 RHBA_DRIVER_VERSION */ 3372 lpfc_fdmi_hba_attr_rom_ver, /* bit7 RHBA_OPTION_ROM_VERSION */ 3373 lpfc_fdmi_hba_attr_fmw_ver, /* bit8 RHBA_FIRMWARE_VERSION */ 3374 lpfc_fdmi_hba_attr_os_ver, /* bit9 RHBA_OS_NAME_VERSION */ 3375 lpfc_fdmi_hba_attr_ct_len, /* bit10 RHBA_MAX_CT_PAYLOAD_LEN */ 3376 lpfc_fdmi_hba_attr_symbolic_name, /* bit11 RHBA_SYM_NODENAME */ 3377 lpfc_fdmi_hba_attr_vendor_info, /* bit12 RHBA_VENDOR_INFO */ 3378 lpfc_fdmi_hba_attr_num_ports, /* bit13 RHBA_NUM_PORTS */ 3379 lpfc_fdmi_hba_attr_fabric_wwnn, /* bit14 RHBA_FABRIC_WWNN */ 3380 lpfc_fdmi_hba_attr_bios_ver, /* bit15 RHBA_BIOS_VERSION */ 3381 lpfc_fdmi_hba_attr_bios_state, /* bit16 RHBA_BIOS_STATE */ 3382 lpfc_fdmi_hba_attr_vendor_id, /* bit17 RHBA_VENDOR_ID */ 3383 }; 3384 3385 /* RPA / RPRT attribute jump table */ 3386 int (*lpfc_fdmi_port_action[]) 3387 (struct lpfc_vport *vport, struct lpfc_fdmi_attr_def *ad) = { 3388 /* Action routine Mask bit Attribute type */ 3389 lpfc_fdmi_port_attr_fc4type, /* bit0 RPRT_SUPPORT_FC4_TYPES */ 3390 lpfc_fdmi_port_attr_support_speed, /* bit1 RPRT_SUPPORTED_SPEED */ 3391 lpfc_fdmi_port_attr_speed, /* bit2 RPRT_PORT_SPEED */ 3392 lpfc_fdmi_port_attr_max_frame, /* bit3 RPRT_MAX_FRAME_SIZE */ 3393 lpfc_fdmi_port_attr_os_devname, /* bit4 RPRT_OS_DEVICE_NAME */ 3394 lpfc_fdmi_port_attr_host_name, /* bit5 RPRT_HOST_NAME */ 3395 lpfc_fdmi_port_attr_wwnn, /* bit6 RPRT_NODENAME */ 3396 lpfc_fdmi_port_attr_wwpn, /* bit7 RPRT_PORTNAME */ 3397 lpfc_fdmi_port_attr_symbolic_name, /* bit8 RPRT_SYM_PORTNAME */ 3398 lpfc_fdmi_port_attr_port_type, /* bit9 RPRT_PORT_TYPE */ 3399 lpfc_fdmi_port_attr_class, /* bit10 RPRT_SUPPORTED_CLASS */ 3400 lpfc_fdmi_port_attr_fabric_wwpn, /* bit11 RPRT_FABRICNAME */ 3401 lpfc_fdmi_port_attr_active_fc4type, /* bit12 RPRT_ACTIVE_FC4_TYPES */ 3402 lpfc_fdmi_port_attr_port_state, /* bit13 RPRT_PORT_STATE */ 3403 lpfc_fdmi_port_attr_num_disc, /* bit14 RPRT_DISC_PORT */ 3404 lpfc_fdmi_port_attr_nportid, /* bit15 RPRT_PORT_ID */ 3405 lpfc_fdmi_smart_attr_service, /* bit16 RPRT_SMART_SERVICE */ 3406 lpfc_fdmi_smart_attr_guid, /* bit17 RPRT_SMART_GUID */ 3407 lpfc_fdmi_smart_attr_version, /* bit18 RPRT_SMART_VERSION */ 3408 lpfc_fdmi_smart_attr_model, /* bit19 RPRT_SMART_MODEL */ 3409 lpfc_fdmi_smart_attr_port_info, /* bit20 RPRT_SMART_PORT_INFO */ 3410 lpfc_fdmi_smart_attr_qos, /* bit21 RPRT_SMART_QOS */ 3411 lpfc_fdmi_smart_attr_security, /* bit22 RPRT_SMART_SECURITY */ 3412 lpfc_fdmi_vendor_attr_mi, /* bit23 RPRT_VENDOR_MI */ 3413 }; 3414 3415 /** 3416 * lpfc_fdmi_cmd - Build and send a FDMI cmd to the specified NPort 3417 * @vport: pointer to a host virtual N_Port data structure. 3418 * @ndlp: ndlp to send FDMI cmd to (if NULL use FDMI_DID) 3419 * @cmdcode: FDMI command to send 3420 * @new_mask: Mask of HBA or PORT Attributes to send 3421 * 3422 * Builds and sends a FDMI command using the CT subsystem. 3423 */ 3424 int 3425 lpfc_fdmi_cmd(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, 3426 int cmdcode, uint32_t new_mask) 3427 { 3428 struct lpfc_hba *phba = vport->phba; 3429 struct lpfc_dmabuf *mp, *bmp; 3430 struct lpfc_sli_ct_request *CtReq; 3431 struct ulp_bde64 *bpl; 3432 uint32_t bit_pos; 3433 uint32_t size; 3434 uint32_t rsp_size; 3435 uint32_t mask; 3436 struct lpfc_fdmi_reg_hba *rh; 3437 struct lpfc_fdmi_port_entry *pe; 3438 struct lpfc_fdmi_reg_portattr *pab = NULL; 3439 struct lpfc_fdmi_attr_block *ab = NULL; 3440 int (*func)(struct lpfc_vport *vport, struct lpfc_fdmi_attr_def *ad); 3441 void (*cmpl)(struct lpfc_hba *, struct lpfc_iocbq *, 3442 struct lpfc_iocbq *); 3443 3444 if (!ndlp) 3445 return 0; 3446 3447 cmpl = lpfc_cmpl_ct_disc_fdmi; /* called from discovery */ 3448 3449 /* fill in BDEs for command */ 3450 /* Allocate buffer for command payload */ 3451 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); 3452 if (!mp) 3453 goto fdmi_cmd_exit; 3454 3455 mp->virt = lpfc_mbuf_alloc(phba, 0, &(mp->phys)); 3456 if (!mp->virt) 3457 goto fdmi_cmd_free_mp; 3458 3459 /* Allocate buffer for Buffer ptr list */ 3460 bmp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); 3461 if (!bmp) 3462 goto fdmi_cmd_free_mpvirt; 3463 3464 bmp->virt = lpfc_mbuf_alloc(phba, 0, &(bmp->phys)); 3465 if (!bmp->virt) 3466 goto fdmi_cmd_free_bmp; 3467 3468 INIT_LIST_HEAD(&mp->list); 3469 INIT_LIST_HEAD(&bmp->list); 3470 3471 /* FDMI request */ 3472 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, 3473 "0218 FDMI Request Data: x%x x%x x%x\n", 3474 vport->fc_flag, vport->port_state, cmdcode); 3475 CtReq = (struct lpfc_sli_ct_request *)mp->virt; 3476 3477 /* First populate the CT_IU preamble */ 3478 memset(CtReq, 0, sizeof(struct lpfc_sli_ct_request)); 3479 CtReq->RevisionId.bits.Revision = SLI_CT_REVISION; 3480 CtReq->RevisionId.bits.InId = 0; 3481 3482 CtReq->FsType = SLI_CT_MANAGEMENT_SERVICE; 3483 CtReq->FsSubType = SLI_CT_FDMI_Subtypes; 3484 3485 CtReq->CommandResponse.bits.CmdRsp = cpu_to_be16(cmdcode); 3486 rsp_size = LPFC_BPL_SIZE; 3487 size = 0; 3488 3489 /* Next fill in the specific FDMI cmd information */ 3490 switch (cmdcode) { 3491 case SLI_MGMT_RHAT: 3492 case SLI_MGMT_RHBA: 3493 rh = (struct lpfc_fdmi_reg_hba *)&CtReq->un.PortID; 3494 /* HBA Identifier */ 3495 memcpy(&rh->hi.PortName, &phba->pport->fc_sparam.portName, 3496 sizeof(struct lpfc_name)); 3497 3498 if (cmdcode == SLI_MGMT_RHBA) { 3499 /* Registered Port List */ 3500 /* One entry (port) per adapter */ 3501 rh->rpl.EntryCnt = cpu_to_be32(1); 3502 memcpy(&rh->rpl.pe.PortName, 3503 &phba->pport->fc_sparam.portName, 3504 sizeof(struct lpfc_name)); 3505 3506 /* point to the HBA attribute block */ 3507 size = 2 * sizeof(struct lpfc_name) + 3508 FOURBYTES; 3509 } else { 3510 size = sizeof(struct lpfc_name); 3511 } 3512 ab = (struct lpfc_fdmi_attr_block *)((uint8_t *)rh + size); 3513 ab->EntryCnt = 0; 3514 size += FOURBYTES; 3515 bit_pos = 0; 3516 if (new_mask) 3517 mask = new_mask; 3518 else 3519 mask = vport->fdmi_hba_mask; 3520 3521 /* Mask will dictate what attributes to build in the request */ 3522 while (mask) { 3523 if (mask & 0x1) { 3524 func = lpfc_fdmi_hba_action[bit_pos]; 3525 size += func(vport, 3526 (struct lpfc_fdmi_attr_def *) 3527 ((uint8_t *)rh + size)); 3528 ab->EntryCnt++; 3529 if ((size + 256) > 3530 (LPFC_BPL_SIZE - LPFC_CT_PREAMBLE)) 3531 goto hba_out; 3532 } 3533 mask = mask >> 1; 3534 bit_pos++; 3535 } 3536 hba_out: 3537 ab->EntryCnt = cpu_to_be32(ab->EntryCnt); 3538 /* Total size */ 3539 size = GID_REQUEST_SZ - 4 + size; 3540 break; 3541 3542 case SLI_MGMT_RPRT: 3543 case SLI_MGMT_RPA: 3544 pab = (struct lpfc_fdmi_reg_portattr *)&CtReq->un.PortID; 3545 if (cmdcode == SLI_MGMT_RPRT) { 3546 rh = (struct lpfc_fdmi_reg_hba *)pab; 3547 /* HBA Identifier */ 3548 memcpy(&rh->hi.PortName, 3549 &phba->pport->fc_sparam.portName, 3550 sizeof(struct lpfc_name)); 3551 pab = (struct lpfc_fdmi_reg_portattr *) 3552 ((uint8_t *)pab + sizeof(struct lpfc_name)); 3553 } 3554 3555 memcpy((uint8_t *)&pab->PortName, 3556 (uint8_t *)&vport->fc_sparam.portName, 3557 sizeof(struct lpfc_name)); 3558 size += sizeof(struct lpfc_name) + FOURBYTES; 3559 pab->ab.EntryCnt = 0; 3560 bit_pos = 0; 3561 if (new_mask) 3562 mask = new_mask; 3563 else 3564 mask = vport->fdmi_port_mask; 3565 3566 /* Mask will dictate what attributes to build in the request */ 3567 while (mask) { 3568 if (mask & 0x1) { 3569 func = lpfc_fdmi_port_action[bit_pos]; 3570 size += func(vport, 3571 (struct lpfc_fdmi_attr_def *) 3572 ((uint8_t *)pab + size)); 3573 pab->ab.EntryCnt++; 3574 if ((size + 256) > 3575 (LPFC_BPL_SIZE - LPFC_CT_PREAMBLE)) 3576 goto port_out; 3577 } 3578 mask = mask >> 1; 3579 bit_pos++; 3580 } 3581 port_out: 3582 pab->ab.EntryCnt = cpu_to_be32(pab->ab.EntryCnt); 3583 /* Total size */ 3584 if (cmdcode == SLI_MGMT_RPRT) 3585 size += sizeof(struct lpfc_name); 3586 size = GID_REQUEST_SZ - 4 + size; 3587 break; 3588 3589 case SLI_MGMT_GHAT: 3590 case SLI_MGMT_GRPL: 3591 rsp_size = FC_MAX_NS_RSP; 3592 fallthrough; 3593 case SLI_MGMT_DHBA: 3594 case SLI_MGMT_DHAT: 3595 pe = (struct lpfc_fdmi_port_entry *)&CtReq->un.PortID; 3596 memcpy((uint8_t *)&pe->PortName, 3597 (uint8_t *)&vport->fc_sparam.portName, 3598 sizeof(struct lpfc_name)); 3599 size = GID_REQUEST_SZ - 4 + sizeof(struct lpfc_name); 3600 break; 3601 3602 case SLI_MGMT_GPAT: 3603 case SLI_MGMT_GPAS: 3604 rsp_size = FC_MAX_NS_RSP; 3605 fallthrough; 3606 case SLI_MGMT_DPRT: 3607 case SLI_MGMT_DPA: 3608 pe = (struct lpfc_fdmi_port_entry *)&CtReq->un.PortID; 3609 memcpy((uint8_t *)&pe->PortName, 3610 (uint8_t *)&vport->fc_sparam.portName, 3611 sizeof(struct lpfc_name)); 3612 size = GID_REQUEST_SZ - 4 + sizeof(struct lpfc_name); 3613 break; 3614 case SLI_MGMT_GRHL: 3615 size = GID_REQUEST_SZ - 4; 3616 break; 3617 default: 3618 lpfc_printf_vlog(vport, KERN_WARNING, LOG_DISCOVERY, 3619 "0298 FDMI cmdcode x%x not supported\n", 3620 cmdcode); 3621 goto fdmi_cmd_free_bmpvirt; 3622 } 3623 CtReq->CommandResponse.bits.Size = cpu_to_be16(rsp_size); 3624 3625 bpl = (struct ulp_bde64 *)bmp->virt; 3626 bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys)); 3627 bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys)); 3628 bpl->tus.f.bdeFlags = 0; 3629 bpl->tus.f.bdeSize = size; 3630 3631 /* 3632 * The lpfc_ct_cmd/lpfc_get_req shall increment ndlp reference count 3633 * to hold ndlp reference for the corresponding callback function. 3634 */ 3635 if (!lpfc_ct_cmd(vport, mp, bmp, ndlp, cmpl, rsp_size, 0)) 3636 return 0; 3637 3638 fdmi_cmd_free_bmpvirt: 3639 lpfc_mbuf_free(phba, bmp->virt, bmp->phys); 3640 fdmi_cmd_free_bmp: 3641 kfree(bmp); 3642 fdmi_cmd_free_mpvirt: 3643 lpfc_mbuf_free(phba, mp->virt, mp->phys); 3644 fdmi_cmd_free_mp: 3645 kfree(mp); 3646 fdmi_cmd_exit: 3647 /* Issue FDMI request failed */ 3648 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, 3649 "0244 Issue FDMI request failed Data: x%x\n", 3650 cmdcode); 3651 return 1; 3652 } 3653 3654 /** 3655 * lpfc_delayed_disc_tmo - Timeout handler for delayed discovery timer. 3656 * @t: Context object of the timer. 3657 * 3658 * This function set the WORKER_DELAYED_DISC_TMO flag and wake up 3659 * the worker thread. 3660 **/ 3661 void 3662 lpfc_delayed_disc_tmo(struct timer_list *t) 3663 { 3664 struct lpfc_vport *vport = from_timer(vport, t, delayed_disc_tmo); 3665 struct lpfc_hba *phba = vport->phba; 3666 uint32_t tmo_posted; 3667 unsigned long iflag; 3668 3669 spin_lock_irqsave(&vport->work_port_lock, iflag); 3670 tmo_posted = vport->work_port_events & WORKER_DELAYED_DISC_TMO; 3671 if (!tmo_posted) 3672 vport->work_port_events |= WORKER_DELAYED_DISC_TMO; 3673 spin_unlock_irqrestore(&vport->work_port_lock, iflag); 3674 3675 if (!tmo_posted) 3676 lpfc_worker_wake_up(phba); 3677 return; 3678 } 3679 3680 /** 3681 * lpfc_delayed_disc_timeout_handler - Function called by worker thread to 3682 * handle delayed discovery. 3683 * @vport: pointer to a host virtual N_Port data structure. 3684 * 3685 * This function start nport discovery of the vport. 3686 **/ 3687 void 3688 lpfc_delayed_disc_timeout_handler(struct lpfc_vport *vport) 3689 { 3690 struct Scsi_Host *shost = lpfc_shost_from_vport(vport); 3691 3692 spin_lock_irq(shost->host_lock); 3693 if (!(vport->fc_flag & FC_DISC_DELAYED)) { 3694 spin_unlock_irq(shost->host_lock); 3695 return; 3696 } 3697 vport->fc_flag &= ~FC_DISC_DELAYED; 3698 spin_unlock_irq(shost->host_lock); 3699 3700 lpfc_do_scr_ns_plogi(vport->phba, vport); 3701 } 3702 3703 void 3704 lpfc_decode_firmware_rev(struct lpfc_hba *phba, char *fwrevision, int flag) 3705 { 3706 struct lpfc_sli *psli = &phba->sli; 3707 lpfc_vpd_t *vp = &phba->vpd; 3708 uint32_t b1, b2, b3, b4, i, rev; 3709 char c; 3710 uint32_t *ptr, str[4]; 3711 uint8_t *fwname; 3712 3713 if (phba->sli_rev == LPFC_SLI_REV4) 3714 snprintf(fwrevision, FW_REV_STR_SIZE, "%s", vp->rev.opFwName); 3715 else if (vp->rev.rBit) { 3716 if (psli->sli_flag & LPFC_SLI_ACTIVE) 3717 rev = vp->rev.sli2FwRev; 3718 else 3719 rev = vp->rev.sli1FwRev; 3720 3721 b1 = (rev & 0x0000f000) >> 12; 3722 b2 = (rev & 0x00000f00) >> 8; 3723 b3 = (rev & 0x000000c0) >> 6; 3724 b4 = (rev & 0x00000030) >> 4; 3725 3726 switch (b4) { 3727 case 0: 3728 c = 'N'; 3729 break; 3730 case 1: 3731 c = 'A'; 3732 break; 3733 case 2: 3734 c = 'B'; 3735 break; 3736 case 3: 3737 c = 'X'; 3738 break; 3739 default: 3740 c = 0; 3741 break; 3742 } 3743 b4 = (rev & 0x0000000f); 3744 3745 if (psli->sli_flag & LPFC_SLI_ACTIVE) 3746 fwname = vp->rev.sli2FwName; 3747 else 3748 fwname = vp->rev.sli1FwName; 3749 3750 for (i = 0; i < 16; i++) 3751 if (fwname[i] == 0x20) 3752 fwname[i] = 0; 3753 3754 ptr = (uint32_t*)fwname; 3755 3756 for (i = 0; i < 3; i++) 3757 str[i] = be32_to_cpu(*ptr++); 3758 3759 if (c == 0) { 3760 if (flag) 3761 sprintf(fwrevision, "%d.%d%d (%s)", 3762 b1, b2, b3, (char *)str); 3763 else 3764 sprintf(fwrevision, "%d.%d%d", b1, 3765 b2, b3); 3766 } else { 3767 if (flag) 3768 sprintf(fwrevision, "%d.%d%d%c%d (%s)", 3769 b1, b2, b3, c, 3770 b4, (char *)str); 3771 else 3772 sprintf(fwrevision, "%d.%d%d%c%d", 3773 b1, b2, b3, c, b4); 3774 } 3775 } else { 3776 rev = vp->rev.smFwRev; 3777 3778 b1 = (rev & 0xff000000) >> 24; 3779 b2 = (rev & 0x00f00000) >> 20; 3780 b3 = (rev & 0x000f0000) >> 16; 3781 c = (rev & 0x0000ff00) >> 8; 3782 b4 = (rev & 0x000000ff); 3783 3784 sprintf(fwrevision, "%d.%d%d%c%d", b1, b2, b3, c, b4); 3785 } 3786 return; 3787 } 3788 3789 static void 3790 lpfc_cmpl_ct_cmd_vmid(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, 3791 struct lpfc_iocbq *rspiocb) 3792 { 3793 struct lpfc_vport *vport = cmdiocb->vport; 3794 struct lpfc_dmabuf *inp = cmdiocb->context1; 3795 struct lpfc_dmabuf *outp = cmdiocb->context2; 3796 struct lpfc_sli_ct_request *ctcmd = inp->virt; 3797 struct lpfc_sli_ct_request *ctrsp = outp->virt; 3798 u16 rsp = ctrsp->CommandResponse.bits.CmdRsp; 3799 struct app_id_object *app; 3800 u32 cmd, hash, bucket; 3801 struct lpfc_vmid *vmp, *cur; 3802 u8 *data = outp->virt; 3803 int i; 3804 3805 cmd = be16_to_cpu(ctcmd->CommandResponse.bits.CmdRsp); 3806 if (cmd == SLI_CTAS_DALLAPP_ID) 3807 lpfc_ct_free_iocb(phba, cmdiocb); 3808 3809 if (lpfc_els_chk_latt(vport) || rspiocb->iocb.ulpStatus) { 3810 if (cmd != SLI_CTAS_DALLAPP_ID) 3811 return; 3812 } 3813 /* Check for a CT LS_RJT response */ 3814 if (rsp == be16_to_cpu(SLI_CT_RESPONSE_FS_RJT)) { 3815 if (cmd != SLI_CTAS_DALLAPP_ID) 3816 lpfc_printf_vlog(vport, KERN_DEBUG, LOG_DISCOVERY, 3817 "3306 VMID FS_RJT Data: x%x x%x x%x\n", 3818 cmd, ctrsp->ReasonCode, 3819 ctrsp->Explanation); 3820 if ((cmd != SLI_CTAS_DALLAPP_ID) || 3821 (ctrsp->ReasonCode != SLI_CT_UNABLE_TO_PERFORM_REQ) || 3822 (ctrsp->Explanation != SLI_CT_APP_ID_NOT_AVAILABLE)) { 3823 /* If DALLAPP_ID failed retry later */ 3824 if (cmd == SLI_CTAS_DALLAPP_ID) 3825 vport->load_flag |= FC_DEREGISTER_ALL_APP_ID; 3826 return; 3827 } 3828 } 3829 3830 switch (cmd) { 3831 case SLI_CTAS_RAPP_IDENT: 3832 app = (struct app_id_object *)(RAPP_IDENT_OFFSET + data); 3833 lpfc_printf_vlog(vport, KERN_DEBUG, LOG_DISCOVERY, 3834 "6712 RAPP_IDENT app id %d port id x%x id " 3835 "len %d\n", be32_to_cpu(app->app_id), 3836 be32_to_cpu(app->port_id), 3837 app->obj.entity_id_len); 3838 3839 if (app->obj.entity_id_len == 0 || app->port_id == 0) 3840 return; 3841 3842 hash = lpfc_vmid_hash_fn(app->obj.entity_id, 3843 app->obj.entity_id_len); 3844 vmp = lpfc_get_vmid_from_hashtable(vport, hash, 3845 app->obj.entity_id); 3846 if (vmp) { 3847 write_lock(&vport->vmid_lock); 3848 vmp->un.app_id = be32_to_cpu(app->app_id); 3849 vmp->flag |= LPFC_VMID_REGISTERED; 3850 vmp->flag &= ~LPFC_VMID_REQ_REGISTER; 3851 write_unlock(&vport->vmid_lock); 3852 /* Set IN USE flag */ 3853 vport->vmid_flag |= LPFC_VMID_IN_USE; 3854 } else { 3855 lpfc_printf_vlog(vport, KERN_DEBUG, LOG_DISCOVERY, 3856 "6901 No entry found %s hash %d\n", 3857 app->obj.entity_id, hash); 3858 } 3859 break; 3860 case SLI_CTAS_DAPP_IDENT: 3861 app = (struct app_id_object *)(DAPP_IDENT_OFFSET + data); 3862 lpfc_printf_vlog(vport, KERN_DEBUG, LOG_DISCOVERY, 3863 "6713 DAPP_IDENT app id %d port id x%x\n", 3864 be32_to_cpu(app->app_id), 3865 be32_to_cpu(app->port_id)); 3866 break; 3867 case SLI_CTAS_DALLAPP_ID: 3868 lpfc_printf_vlog(vport, KERN_DEBUG, LOG_DISCOVERY, 3869 "8856 Deregistered all app ids\n"); 3870 read_lock(&vport->vmid_lock); 3871 for (i = 0; i < phba->cfg_max_vmid; i++) { 3872 vmp = &vport->vmid[i]; 3873 if (vmp->flag != LPFC_VMID_SLOT_FREE) 3874 memset(vmp, 0, sizeof(struct lpfc_vmid)); 3875 } 3876 read_unlock(&vport->vmid_lock); 3877 /* for all elements in the hash table */ 3878 if (!hash_empty(vport->hash_table)) 3879 hash_for_each(vport->hash_table, bucket, cur, hnode) 3880 hash_del(&cur->hnode); 3881 vport->load_flag |= FC_ALLOW_VMID; 3882 break; 3883 default: 3884 lpfc_printf_vlog(vport, KERN_DEBUG, LOG_DISCOVERY, 3885 "8857 Invalid command code\n"); 3886 } 3887 } 3888 3889 /** 3890 * lpfc_vmid_cmd - Build and send a FDMI cmd to the specified NPort 3891 * @vport: pointer to a host virtual N_Port data structure. 3892 * @cmdcode: application server command code to send 3893 * @vmid: pointer to vmid info structure 3894 * 3895 * Builds and sends a FDMI command using the CT subsystem. 3896 */ 3897 int 3898 lpfc_vmid_cmd(struct lpfc_vport *vport, 3899 int cmdcode, struct lpfc_vmid *vmid) 3900 { 3901 struct lpfc_hba *phba = vport->phba; 3902 struct lpfc_dmabuf *mp, *bmp; 3903 struct lpfc_sli_ct_request *ctreq; 3904 struct ulp_bde64 *bpl; 3905 u32 size; 3906 u32 rsp_size; 3907 u8 *data; 3908 struct lpfc_vmid_rapp_ident_list *rap; 3909 struct lpfc_vmid_dapp_ident_list *dap; 3910 u8 retry = 0; 3911 struct lpfc_nodelist *ndlp; 3912 3913 void (*cmpl)(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, 3914 struct lpfc_iocbq *rspiocb); 3915 3916 ndlp = lpfc_findnode_did(vport, FDMI_DID); 3917 if (!ndlp || ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) 3918 return 0; 3919 3920 cmpl = lpfc_cmpl_ct_cmd_vmid; 3921 3922 /* fill in BDEs for command */ 3923 /* Allocate buffer for command payload */ 3924 mp = kmalloc(sizeof(*mp), GFP_KERNEL); 3925 if (!mp) 3926 goto vmid_free_mp_exit; 3927 3928 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys); 3929 if (!mp->virt) 3930 goto vmid_free_mp_virt_exit; 3931 3932 /* Allocate buffer for Buffer ptr list */ 3933 bmp = kmalloc(sizeof(*bmp), GFP_KERNEL); 3934 if (!bmp) 3935 goto vmid_free_bmp_exit; 3936 3937 bmp->virt = lpfc_mbuf_alloc(phba, 0, &bmp->phys); 3938 if (!bmp->virt) 3939 goto vmid_free_bmp_virt_exit; 3940 3941 INIT_LIST_HEAD(&mp->list); 3942 INIT_LIST_HEAD(&bmp->list); 3943 3944 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, 3945 "3275 VMID Request Data: x%x x%x x%x\n", 3946 vport->fc_flag, vport->port_state, cmdcode); 3947 ctreq = (struct lpfc_sli_ct_request *)mp->virt; 3948 data = mp->virt; 3949 /* First populate the CT_IU preamble */ 3950 memset(data, 0, LPFC_BPL_SIZE); 3951 ctreq->RevisionId.bits.Revision = SLI_CT_REVISION; 3952 ctreq->RevisionId.bits.InId = 0; 3953 3954 ctreq->FsType = SLI_CT_MANAGEMENT_SERVICE; 3955 ctreq->FsSubType = SLI_CT_APP_SEV_Subtypes; 3956 3957 ctreq->CommandResponse.bits.CmdRsp = cpu_to_be16(cmdcode); 3958 rsp_size = LPFC_BPL_SIZE; 3959 size = 0; 3960 3961 switch (cmdcode) { 3962 case SLI_CTAS_RAPP_IDENT: 3963 lpfc_printf_vlog(vport, KERN_DEBUG, LOG_DISCOVERY, 3964 "1329 RAPP_IDENT for %s\n", vmid->host_vmid); 3965 ctreq->un.PortID = cpu_to_be32(vport->fc_myDID); 3966 rap = (struct lpfc_vmid_rapp_ident_list *) 3967 (DAPP_IDENT_OFFSET + data); 3968 rap->no_of_objects = cpu_to_be32(1); 3969 rap->obj[0].entity_id_len = vmid->vmid_len; 3970 memcpy(rap->obj[0].entity_id, vmid->host_vmid, vmid->vmid_len); 3971 size = RAPP_IDENT_OFFSET + 3972 sizeof(struct lpfc_vmid_rapp_ident_list); 3973 retry = 1; 3974 break; 3975 3976 case SLI_CTAS_GALLAPPIA_ID: 3977 ctreq->un.PortID = cpu_to_be32(vport->fc_myDID); 3978 size = GALLAPPIA_ID_SIZE; 3979 break; 3980 3981 case SLI_CTAS_DAPP_IDENT: 3982 lpfc_printf_vlog(vport, KERN_DEBUG, LOG_DISCOVERY, 3983 "1469 DAPP_IDENT for %s\n", vmid->host_vmid); 3984 ctreq->un.PortID = cpu_to_be32(vport->fc_myDID); 3985 dap = (struct lpfc_vmid_dapp_ident_list *) 3986 (DAPP_IDENT_OFFSET + data); 3987 dap->no_of_objects = cpu_to_be32(1); 3988 dap->obj[0].entity_id_len = vmid->vmid_len; 3989 memcpy(dap->obj[0].entity_id, vmid->host_vmid, vmid->vmid_len); 3990 size = DAPP_IDENT_OFFSET + 3991 sizeof(struct lpfc_vmid_dapp_ident_list); 3992 write_lock(&vport->vmid_lock); 3993 vmid->flag &= ~LPFC_VMID_REGISTERED; 3994 write_unlock(&vport->vmid_lock); 3995 retry = 1; 3996 break; 3997 3998 case SLI_CTAS_DALLAPP_ID: 3999 ctreq->un.PortID = cpu_to_be32(vport->fc_myDID); 4000 size = DALLAPP_ID_SIZE; 4001 break; 4002 4003 default: 4004 lpfc_printf_vlog(vport, KERN_DEBUG, LOG_DISCOVERY, 4005 "7062 VMID cmdcode x%x not supported\n", 4006 cmdcode); 4007 goto vmid_free_all_mem; 4008 } 4009 4010 ctreq->CommandResponse.bits.Size = cpu_to_be16(rsp_size); 4011 4012 bpl = (struct ulp_bde64 *)bmp->virt; 4013 bpl->addrHigh = putPaddrHigh(mp->phys); 4014 bpl->addrLow = putPaddrLow(mp->phys); 4015 bpl->tus.f.bdeFlags = 0; 4016 bpl->tus.f.bdeSize = size; 4017 4018 /* The lpfc_ct_cmd/lpfc_get_req shall increment ndlp reference count 4019 * to hold ndlp reference for the corresponding callback function. 4020 */ 4021 if (!lpfc_ct_cmd(vport, mp, bmp, ndlp, cmpl, rsp_size, retry)) 4022 return 0; 4023 4024 vmid_free_all_mem: 4025 lpfc_mbuf_free(phba, bmp->virt, bmp->phys); 4026 vmid_free_bmp_virt_exit: 4027 kfree(bmp); 4028 vmid_free_bmp_exit: 4029 lpfc_mbuf_free(phba, mp->virt, mp->phys); 4030 vmid_free_mp_virt_exit: 4031 kfree(mp); 4032 vmid_free_mp_exit: 4033 4034 /* Issue CT request failed */ 4035 lpfc_printf_vlog(vport, KERN_DEBUG, LOG_DISCOVERY, 4036 "3276 VMID CT request failed Data: x%x\n", cmdcode); 4037 return -EIO; 4038 } 4039