1 /******************************************************************* 2 * This file is part of the Emulex Linux Device Driver for * 3 * Fibre Channel Host Bus Adapters. * 4 * Copyright (C) 2017-2018 Broadcom. All Rights Reserved. The term * 5 * “Broadcom” refers to Broadcom Limited 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_nvme.h" 48 #include "lpfc_logmsg.h" 49 #include "lpfc_crtn.h" 50 #include "lpfc_version.h" 51 #include "lpfc_vport.h" 52 #include "lpfc_debugfs.h" 53 54 /* FDMI Port Speed definitions - FC-GS-7 */ 55 #define HBA_PORTSPEED_1GFC 0x00000001 /* 1G FC */ 56 #define HBA_PORTSPEED_2GFC 0x00000002 /* 2G FC */ 57 #define HBA_PORTSPEED_4GFC 0x00000008 /* 4G FC */ 58 #define HBA_PORTSPEED_10GFC 0x00000004 /* 10G FC */ 59 #define HBA_PORTSPEED_8GFC 0x00000010 /* 8G FC */ 60 #define HBA_PORTSPEED_16GFC 0x00000020 /* 16G FC */ 61 #define HBA_PORTSPEED_32GFC 0x00000040 /* 32G FC */ 62 #define HBA_PORTSPEED_20GFC 0x00000080 /* 20G FC */ 63 #define HBA_PORTSPEED_40GFC 0x00000100 /* 40G FC */ 64 #define HBA_PORTSPEED_128GFC 0x00000200 /* 128G FC */ 65 #define HBA_PORTSPEED_64GFC 0x00000400 /* 64G FC */ 66 #define HBA_PORTSPEED_256GFC 0x00000800 /* 256G FC */ 67 #define HBA_PORTSPEED_UNKNOWN 0x00008000 /* Unknown */ 68 #define HBA_PORTSPEED_10GE 0x00010000 /* 10G E */ 69 #define HBA_PORTSPEED_40GE 0x00020000 /* 40G E */ 70 #define HBA_PORTSPEED_100GE 0x00040000 /* 100G E */ 71 #define HBA_PORTSPEED_25GE 0x00080000 /* 25G E */ 72 #define HBA_PORTSPEED_50GE 0x00100000 /* 50G E */ 73 #define HBA_PORTSPEED_400GE 0x00200000 /* 400G E */ 74 75 #define FOURBYTES 4 76 77 78 static char *lpfc_release_version = LPFC_DRIVER_VERSION; 79 80 static void 81 lpfc_ct_ignore_hbq_buffer(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq, 82 struct lpfc_dmabuf *mp, uint32_t size) 83 { 84 if (!mp) { 85 lpfc_printf_log(phba, KERN_INFO, LOG_ELS, 86 "0146 Ignoring unsolicited CT No HBQ " 87 "status = x%x\n", 88 piocbq->iocb.ulpStatus); 89 } 90 lpfc_printf_log(phba, KERN_INFO, LOG_ELS, 91 "0145 Ignoring unsolicted CT HBQ Size:%d " 92 "status = x%x\n", 93 size, piocbq->iocb.ulpStatus); 94 } 95 96 static void 97 lpfc_ct_unsol_buffer(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq, 98 struct lpfc_dmabuf *mp, uint32_t size) 99 { 100 lpfc_ct_ignore_hbq_buffer(phba, piocbq, mp, size); 101 } 102 103 void 104 lpfc_ct_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, 105 struct lpfc_iocbq *piocbq) 106 { 107 struct lpfc_dmabuf *mp = NULL; 108 IOCB_t *icmd = &piocbq->iocb; 109 int i; 110 struct lpfc_iocbq *iocbq; 111 dma_addr_t paddr; 112 uint32_t size; 113 struct list_head head; 114 struct lpfc_dmabuf *bdeBuf; 115 116 if (lpfc_bsg_ct_unsol_event(phba, pring, piocbq) == 0) 117 return; 118 119 if (unlikely(icmd->ulpStatus == IOSTAT_NEED_BUFFER)) { 120 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ); 121 } else if ((icmd->ulpStatus == IOSTAT_LOCAL_REJECT) && 122 ((icmd->un.ulpWord[4] & IOERR_PARAM_MASK) == 123 IOERR_RCV_BUFFER_WAITING)) { 124 /* Not enough posted buffers; Try posting more buffers */ 125 phba->fc_stat.NoRcvBuf++; 126 if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) 127 lpfc_post_buffer(phba, pring, 2); 128 return; 129 } 130 131 /* If there are no BDEs associated with this IOCB, 132 * there is nothing to do. 133 */ 134 if (icmd->ulpBdeCount == 0) 135 return; 136 137 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) { 138 INIT_LIST_HEAD(&head); 139 list_add_tail(&head, &piocbq->list); 140 list_for_each_entry(iocbq, &head, list) { 141 icmd = &iocbq->iocb; 142 if (icmd->ulpBdeCount == 0) 143 continue; 144 bdeBuf = iocbq->context2; 145 iocbq->context2 = NULL; 146 size = icmd->un.cont64[0].tus.f.bdeSize; 147 lpfc_ct_unsol_buffer(phba, piocbq, bdeBuf, size); 148 lpfc_in_buf_free(phba, bdeBuf); 149 if (icmd->ulpBdeCount == 2) { 150 bdeBuf = iocbq->context3; 151 iocbq->context3 = NULL; 152 size = icmd->unsli3.rcvsli3.bde2.tus.f.bdeSize; 153 lpfc_ct_unsol_buffer(phba, piocbq, bdeBuf, 154 size); 155 lpfc_in_buf_free(phba, bdeBuf); 156 } 157 } 158 list_del(&head); 159 } else { 160 INIT_LIST_HEAD(&head); 161 list_add_tail(&head, &piocbq->list); 162 list_for_each_entry(iocbq, &head, list) { 163 icmd = &iocbq->iocb; 164 if (icmd->ulpBdeCount == 0) 165 lpfc_ct_unsol_buffer(phba, iocbq, NULL, 0); 166 for (i = 0; i < icmd->ulpBdeCount; i++) { 167 paddr = getPaddr(icmd->un.cont64[i].addrHigh, 168 icmd->un.cont64[i].addrLow); 169 mp = lpfc_sli_ringpostbuf_get(phba, pring, 170 paddr); 171 size = icmd->un.cont64[i].tus.f.bdeSize; 172 lpfc_ct_unsol_buffer(phba, iocbq, mp, size); 173 lpfc_in_buf_free(phba, mp); 174 } 175 lpfc_post_buffer(phba, pring, i); 176 } 177 list_del(&head); 178 } 179 } 180 181 /** 182 * lpfc_ct_handle_unsol_abort - ct upper level protocol abort handler 183 * @phba: Pointer to HBA context object. 184 * @dmabuf: pointer to a dmabuf that describes the FC sequence 185 * 186 * This function serves as the upper level protocol abort handler for CT 187 * protocol. 188 * 189 * Return 1 if abort has been handled, 0 otherwise. 190 **/ 191 int 192 lpfc_ct_handle_unsol_abort(struct lpfc_hba *phba, struct hbq_dmabuf *dmabuf) 193 { 194 int handled; 195 196 /* CT upper level goes through BSG */ 197 handled = lpfc_bsg_ct_unsol_abort(phba, dmabuf); 198 199 return handled; 200 } 201 202 static void 203 lpfc_free_ct_rsp(struct lpfc_hba *phba, struct lpfc_dmabuf *mlist) 204 { 205 struct lpfc_dmabuf *mlast, *next_mlast; 206 207 list_for_each_entry_safe(mlast, next_mlast, &mlist->list, list) { 208 lpfc_mbuf_free(phba, mlast->virt, mlast->phys); 209 list_del(&mlast->list); 210 kfree(mlast); 211 } 212 lpfc_mbuf_free(phba, mlist->virt, mlist->phys); 213 kfree(mlist); 214 return; 215 } 216 217 static struct lpfc_dmabuf * 218 lpfc_alloc_ct_rsp(struct lpfc_hba *phba, int cmdcode, struct ulp_bde64 *bpl, 219 uint32_t size, int *entries) 220 { 221 struct lpfc_dmabuf *mlist = NULL; 222 struct lpfc_dmabuf *mp; 223 int cnt, i = 0; 224 225 /* We get chunks of FCELSSIZE */ 226 cnt = size > FCELSSIZE ? FCELSSIZE: size; 227 228 while (size) { 229 /* Allocate buffer for rsp payload */ 230 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); 231 if (!mp) { 232 if (mlist) 233 lpfc_free_ct_rsp(phba, mlist); 234 return NULL; 235 } 236 237 INIT_LIST_HEAD(&mp->list); 238 239 if (cmdcode == be16_to_cpu(SLI_CTNS_GID_FT) || 240 cmdcode == be16_to_cpu(SLI_CTNS_GFF_ID)) 241 mp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(mp->phys)); 242 else 243 mp->virt = lpfc_mbuf_alloc(phba, 0, &(mp->phys)); 244 245 if (!mp->virt) { 246 kfree(mp); 247 if (mlist) 248 lpfc_free_ct_rsp(phba, mlist); 249 return NULL; 250 } 251 252 /* Queue it to a linked list */ 253 if (!mlist) 254 mlist = mp; 255 else 256 list_add_tail(&mp->list, &mlist->list); 257 258 bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64I; 259 /* build buffer ptr list for IOCB */ 260 bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys) ); 261 bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys) ); 262 bpl->tus.f.bdeSize = (uint16_t) cnt; 263 bpl->tus.w = le32_to_cpu(bpl->tus.w); 264 bpl++; 265 266 i++; 267 size -= cnt; 268 } 269 270 *entries = i; 271 return mlist; 272 } 273 274 int 275 lpfc_ct_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *ctiocb) 276 { 277 struct lpfc_dmabuf *buf_ptr; 278 279 if (ctiocb->context_un.ndlp) { 280 lpfc_nlp_put(ctiocb->context_un.ndlp); 281 ctiocb->context_un.ndlp = NULL; 282 } 283 if (ctiocb->context1) { 284 buf_ptr = (struct lpfc_dmabuf *) ctiocb->context1; 285 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); 286 kfree(buf_ptr); 287 ctiocb->context1 = NULL; 288 } 289 if (ctiocb->context2) { 290 lpfc_free_ct_rsp(phba, (struct lpfc_dmabuf *) ctiocb->context2); 291 ctiocb->context2 = NULL; 292 } 293 294 if (ctiocb->context3) { 295 buf_ptr = (struct lpfc_dmabuf *) ctiocb->context3; 296 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); 297 kfree(buf_ptr); 298 ctiocb->context3 = NULL; 299 } 300 lpfc_sli_release_iocbq(phba, ctiocb); 301 return 0; 302 } 303 304 /** 305 * lpfc_gen_req - Build and issue a GEN_REQUEST command to the SLI Layer 306 * @vport: pointer to a host virtual N_Port data structure. 307 * @bmp: Pointer to BPL for SLI command 308 * @inp: Pointer to data buffer for response data. 309 * @outp: Pointer to data buffer that hold the CT command. 310 * @cmpl: completion routine to call when command completes 311 * @ndlp: Destination NPort nodelist entry 312 * 313 * This function as the final part for issuing a CT command. 314 */ 315 static int 316 lpfc_gen_req(struct lpfc_vport *vport, struct lpfc_dmabuf *bmp, 317 struct lpfc_dmabuf *inp, struct lpfc_dmabuf *outp, 318 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *, 319 struct lpfc_iocbq *), 320 struct lpfc_nodelist *ndlp, uint32_t usr_flg, uint32_t num_entry, 321 uint32_t tmo, uint8_t retry) 322 { 323 struct lpfc_hba *phba = vport->phba; 324 IOCB_t *icmd; 325 struct lpfc_iocbq *geniocb; 326 int rc; 327 328 /* Allocate buffer for command iocb */ 329 geniocb = lpfc_sli_get_iocbq(phba); 330 331 if (geniocb == NULL) 332 return 1; 333 334 icmd = &geniocb->iocb; 335 icmd->un.genreq64.bdl.ulpIoTag32 = 0; 336 icmd->un.genreq64.bdl.addrHigh = putPaddrHigh(bmp->phys); 337 icmd->un.genreq64.bdl.addrLow = putPaddrLow(bmp->phys); 338 icmd->un.genreq64.bdl.bdeFlags = BUFF_TYPE_BLP_64; 339 icmd->un.genreq64.bdl.bdeSize = (num_entry * sizeof(struct ulp_bde64)); 340 341 if (usr_flg) 342 geniocb->context3 = NULL; 343 else 344 geniocb->context3 = (uint8_t *) bmp; 345 346 /* Save for completion so we can release these resources */ 347 geniocb->context1 = (uint8_t *) inp; 348 geniocb->context2 = (uint8_t *) outp; 349 geniocb->context_un.ndlp = lpfc_nlp_get(ndlp); 350 351 /* Fill in payload, bp points to frame payload */ 352 icmd->ulpCommand = CMD_GEN_REQUEST64_CR; 353 354 /* Fill in rest of iocb */ 355 icmd->un.genreq64.w5.hcsw.Fctl = (SI | LA); 356 icmd->un.genreq64.w5.hcsw.Dfctl = 0; 357 icmd->un.genreq64.w5.hcsw.Rctl = FC_RCTL_DD_UNSOL_CTL; 358 icmd->un.genreq64.w5.hcsw.Type = FC_TYPE_CT; 359 360 if (!tmo) { 361 /* FC spec states we need 3 * ratov for CT requests */ 362 tmo = (3 * phba->fc_ratov); 363 } 364 icmd->ulpTimeout = tmo; 365 icmd->ulpBdeCount = 1; 366 icmd->ulpLe = 1; 367 icmd->ulpClass = CLASS3; 368 icmd->ulpContext = ndlp->nlp_rpi; 369 if (phba->sli_rev == LPFC_SLI_REV4) 370 icmd->ulpContext = phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]; 371 372 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) { 373 /* For GEN_REQUEST64_CR, use the RPI */ 374 icmd->ulpCt_h = 0; 375 icmd->ulpCt_l = 0; 376 } 377 378 /* Issue GEN REQ IOCB for NPORT <did> */ 379 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, 380 "0119 Issue GEN REQ IOCB to NPORT x%x " 381 "Data: x%x x%x\n", 382 ndlp->nlp_DID, icmd->ulpIoTag, 383 vport->port_state); 384 geniocb->iocb_cmpl = cmpl; 385 geniocb->drvrTimeout = icmd->ulpTimeout + LPFC_DRVR_TIMEOUT; 386 geniocb->vport = vport; 387 geniocb->retry = retry; 388 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, geniocb, 0); 389 390 if (rc == IOCB_ERROR) { 391 lpfc_sli_release_iocbq(phba, geniocb); 392 return 1; 393 } 394 395 return 0; 396 } 397 398 /** 399 * lpfc_ct_cmd - Build and issue a CT command 400 * @vport: pointer to a host virtual N_Port data structure. 401 * @inmp: Pointer to data buffer for response data. 402 * @bmp: Pointer to BPL for SLI command 403 * @ndlp: Destination NPort nodelist entry 404 * @cmpl: completion routine to call when command completes 405 * 406 * This function is called for issuing a CT command. 407 */ 408 static int 409 lpfc_ct_cmd(struct lpfc_vport *vport, struct lpfc_dmabuf *inmp, 410 struct lpfc_dmabuf *bmp, struct lpfc_nodelist *ndlp, 411 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *, 412 struct lpfc_iocbq *), 413 uint32_t rsp_size, uint8_t retry) 414 { 415 struct lpfc_hba *phba = vport->phba; 416 struct ulp_bde64 *bpl = (struct ulp_bde64 *) bmp->virt; 417 struct lpfc_dmabuf *outmp; 418 int cnt = 0, status; 419 int cmdcode = ((struct lpfc_sli_ct_request *) inmp->virt)-> 420 CommandResponse.bits.CmdRsp; 421 422 bpl++; /* Skip past ct request */ 423 424 /* Put buffer(s) for ct rsp in bpl */ 425 outmp = lpfc_alloc_ct_rsp(phba, cmdcode, bpl, rsp_size, &cnt); 426 if (!outmp) 427 return -ENOMEM; 428 /* 429 * Form the CT IOCB. The total number of BDEs in this IOCB 430 * is the single command plus response count from 431 * lpfc_alloc_ct_rsp. 432 */ 433 cnt += 1; 434 status = lpfc_gen_req(vport, bmp, inmp, outmp, cmpl, ndlp, 0, 435 cnt, 0, retry); 436 if (status) { 437 lpfc_free_ct_rsp(phba, outmp); 438 return -ENOMEM; 439 } 440 return 0; 441 } 442 443 struct lpfc_vport * 444 lpfc_find_vport_by_did(struct lpfc_hba *phba, uint32_t did) { 445 struct lpfc_vport *vport_curr; 446 unsigned long flags; 447 448 spin_lock_irqsave(&phba->hbalock, flags); 449 list_for_each_entry(vport_curr, &phba->port_list, listentry) { 450 if ((vport_curr->fc_myDID) && (vport_curr->fc_myDID == did)) { 451 spin_unlock_irqrestore(&phba->hbalock, flags); 452 return vport_curr; 453 } 454 } 455 spin_unlock_irqrestore(&phba->hbalock, flags); 456 return NULL; 457 } 458 459 static void 460 lpfc_prep_node_fc4type(struct lpfc_vport *vport, uint32_t Did, uint8_t fc4_type) 461 { 462 struct lpfc_nodelist *ndlp; 463 464 if ((vport->port_type != LPFC_NPIV_PORT) || 465 !(vport->ct_flags & FC_CT_RFF_ID) || !vport->cfg_restrict_login) { 466 467 ndlp = lpfc_setup_disc_node(vport, Did); 468 469 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) { 470 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT, 471 "Parse GID_FTrsp: did:x%x flg:x%x x%x", 472 Did, ndlp->nlp_flag, vport->fc_flag); 473 474 /* By default, the driver expects to support FCP FC4 */ 475 if (fc4_type == FC_TYPE_FCP) 476 ndlp->nlp_fc4_type |= NLP_FC4_FCP; 477 478 if (fc4_type == FC_TYPE_NVME) 479 ndlp->nlp_fc4_type |= NLP_FC4_NVME; 480 481 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, 482 "0238 Process x%06x NameServer Rsp " 483 "Data: x%x x%x x%x x%x\n", Did, 484 ndlp->nlp_flag, ndlp->nlp_fc4_type, 485 vport->fc_flag, 486 vport->fc_rscn_id_cnt); 487 } else { 488 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT, 489 "Skip1 GID_FTrsp: did:x%x flg:x%x cnt:%d", 490 Did, vport->fc_flag, vport->fc_rscn_id_cnt); 491 492 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, 493 "0239 Skip x%06x NameServer Rsp " 494 "Data: x%x x%x\n", Did, 495 vport->fc_flag, 496 vport->fc_rscn_id_cnt); 497 } 498 } else { 499 if (!(vport->fc_flag & FC_RSCN_MODE) || 500 lpfc_rscn_payload_check(vport, Did)) { 501 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT, 502 "Query GID_FTrsp: did:x%x flg:x%x cnt:%d", 503 Did, vport->fc_flag, vport->fc_rscn_id_cnt); 504 505 /* 506 * This NPortID was previously a FCP/NVMe target, 507 * Don't even bother to send GFF_ID. 508 */ 509 ndlp = lpfc_findnode_did(vport, Did); 510 if (ndlp && NLP_CHK_NODE_ACT(ndlp) && 511 (ndlp->nlp_type & 512 (NLP_FCP_TARGET | NLP_NVME_TARGET))) { 513 if (fc4_type == FC_TYPE_FCP) 514 ndlp->nlp_fc4_type |= NLP_FC4_FCP; 515 if (fc4_type == FC_TYPE_NVME) 516 ndlp->nlp_fc4_type |= NLP_FC4_NVME; 517 lpfc_setup_disc_node(vport, Did); 518 } else if (lpfc_ns_cmd(vport, SLI_CTNS_GFF_ID, 519 0, Did) == 0) 520 vport->num_disc_nodes++; 521 else 522 lpfc_setup_disc_node(vport, Did); 523 } else { 524 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT, 525 "Skip2 GID_FTrsp: did:x%x flg:x%x cnt:%d", 526 Did, vport->fc_flag, vport->fc_rscn_id_cnt); 527 528 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, 529 "0245 Skip x%06x NameServer Rsp " 530 "Data: x%x x%x\n", Did, 531 vport->fc_flag, 532 vport->fc_rscn_id_cnt); 533 } 534 } 535 } 536 537 static void 538 lpfc_ns_rsp_audit_did(struct lpfc_vport *vport, uint32_t Did, uint8_t fc4_type) 539 { 540 struct lpfc_hba *phba = vport->phba; 541 struct lpfc_nodelist *ndlp = NULL; 542 struct Scsi_Host *shost = lpfc_shost_from_vport(vport); 543 544 /* 545 * To conserve rpi's, filter out addresses for other 546 * vports on the same physical HBAs. 547 */ 548 if (Did != vport->fc_myDID && 549 (!lpfc_find_vport_by_did(phba, Did) || 550 vport->cfg_peer_port_login)) { 551 if (!phba->nvmet_support) { 552 /* FCPI/NVMEI path. Process Did */ 553 lpfc_prep_node_fc4type(vport, Did, fc4_type); 554 return; 555 } 556 /* NVMET path. NVMET only cares about NVMEI nodes. */ 557 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) { 558 if (ndlp->nlp_type != NLP_NVME_INITIATOR || 559 ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) 560 continue; 561 spin_lock_irq(shost->host_lock); 562 if (ndlp->nlp_DID == Did) 563 ndlp->nlp_flag &= ~NLP_NVMET_RECOV; 564 else 565 ndlp->nlp_flag |= NLP_NVMET_RECOV; 566 spin_unlock_irq(shost->host_lock); 567 } 568 } 569 } 570 571 static int 572 lpfc_ns_rsp(struct lpfc_vport *vport, struct lpfc_dmabuf *mp, uint8_t fc4_type, 573 uint32_t Size) 574 { 575 struct lpfc_sli_ct_request *Response = 576 (struct lpfc_sli_ct_request *) mp->virt; 577 struct lpfc_dmabuf *mlast, *next_mp; 578 uint32_t *ctptr = (uint32_t *) & Response->un.gid.PortType; 579 uint32_t Did, CTentry; 580 int Cnt; 581 struct list_head head; 582 struct Scsi_Host *shost = lpfc_shost_from_vport(vport); 583 struct lpfc_nodelist *ndlp = NULL; 584 585 lpfc_set_disctmo(vport); 586 vport->num_disc_nodes = 0; 587 vport->fc_ns_retry = 0; 588 589 590 list_add_tail(&head, &mp->list); 591 list_for_each_entry_safe(mp, next_mp, &head, list) { 592 mlast = mp; 593 594 Cnt = Size > FCELSSIZE ? FCELSSIZE : Size; 595 596 Size -= Cnt; 597 598 if (!ctptr) { 599 ctptr = (uint32_t *) mlast->virt; 600 } else 601 Cnt -= 16; /* subtract length of CT header */ 602 603 /* Loop through entire NameServer list of DIDs */ 604 while (Cnt >= sizeof(uint32_t)) { 605 /* Get next DID from NameServer List */ 606 CTentry = *ctptr++; 607 Did = ((be32_to_cpu(CTentry)) & Mask_DID); 608 lpfc_ns_rsp_audit_did(vport, Did, fc4_type); 609 if (CTentry & (cpu_to_be32(SLI_CT_LAST_ENTRY))) 610 goto nsout1; 611 612 Cnt -= sizeof(uint32_t); 613 } 614 ctptr = NULL; 615 616 } 617 618 /* All GID_FT entries processed. If the driver is running in 619 * in target mode, put impacted nodes into recovery and drop 620 * the RPI to flush outstanding IO. 621 */ 622 if (vport->phba->nvmet_support) { 623 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) { 624 if (!(ndlp->nlp_flag & NLP_NVMET_RECOV)) 625 continue; 626 lpfc_disc_state_machine(vport, ndlp, NULL, 627 NLP_EVT_DEVICE_RECOVERY); 628 spin_lock_irq(shost->host_lock); 629 ndlp->nlp_flag &= ~NLP_NVMET_RECOV; 630 spin_unlock_irq(shost->host_lock); 631 } 632 } 633 634 nsout1: 635 list_del(&head); 636 return 0; 637 } 638 639 static void 640 lpfc_cmpl_ct_cmd_gid_ft(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, 641 struct lpfc_iocbq *rspiocb) 642 { 643 struct lpfc_vport *vport = cmdiocb->vport; 644 struct Scsi_Host *shost = lpfc_shost_from_vport(vport); 645 IOCB_t *irsp; 646 struct lpfc_dmabuf *outp; 647 struct lpfc_dmabuf *inp; 648 struct lpfc_sli_ct_request *CTrsp; 649 struct lpfc_sli_ct_request *CTreq; 650 struct lpfc_nodelist *ndlp; 651 int rc, type; 652 653 /* First save ndlp, before we overwrite it */ 654 ndlp = cmdiocb->context_un.ndlp; 655 656 /* we pass cmdiocb to state machine which needs rspiocb as well */ 657 cmdiocb->context_un.rsp_iocb = rspiocb; 658 inp = (struct lpfc_dmabuf *) cmdiocb->context1; 659 outp = (struct lpfc_dmabuf *) cmdiocb->context2; 660 irsp = &rspiocb->iocb; 661 662 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT, 663 "GID_FT cmpl: status:x%x/x%x rtry:%d", 664 irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_ns_retry); 665 666 /* Don't bother processing response if vport is being torn down. */ 667 if (vport->load_flag & FC_UNLOADING) { 668 if (vport->fc_flag & FC_RSCN_MODE) 669 lpfc_els_flush_rscn(vport); 670 goto out; 671 } 672 673 if (lpfc_els_chk_latt(vport)) { 674 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, 675 "0216 Link event during NS query\n"); 676 if (vport->fc_flag & FC_RSCN_MODE) 677 lpfc_els_flush_rscn(vport); 678 lpfc_vport_set_state(vport, FC_VPORT_FAILED); 679 goto out; 680 } 681 if (lpfc_error_lost_link(irsp)) { 682 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, 683 "0226 NS query failed due to link event\n"); 684 if (vport->fc_flag & FC_RSCN_MODE) 685 lpfc_els_flush_rscn(vport); 686 goto out; 687 } 688 689 spin_lock_irq(shost->host_lock); 690 if (vport->fc_flag & FC_RSCN_DEFERRED) { 691 vport->fc_flag &= ~FC_RSCN_DEFERRED; 692 spin_unlock_irq(shost->host_lock); 693 694 /* 695 * Skip processing the NS response 696 * Re-issue the NS cmd 697 */ 698 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, 699 "0151 Process Deferred RSCN Data: x%x x%x\n", 700 vport->fc_flag, vport->fc_rscn_id_cnt); 701 lpfc_els_handle_rscn(vport); 702 703 goto out; 704 } 705 spin_unlock_irq(shost->host_lock); 706 707 if (irsp->ulpStatus) { 708 /* Check for retry */ 709 if (vport->fc_ns_retry < LPFC_MAX_NS_RETRY) { 710 if (irsp->ulpStatus != IOSTAT_LOCAL_REJECT || 711 (irsp->un.ulpWord[4] & IOERR_PARAM_MASK) != 712 IOERR_NO_RESOURCES) 713 vport->fc_ns_retry++; 714 715 type = lpfc_get_gidft_type(vport, cmdiocb); 716 if (type == 0) 717 goto out; 718 719 /* CT command is being retried */ 720 vport->gidft_inp--; 721 rc = lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 722 vport->fc_ns_retry, type); 723 if (rc == 0) 724 goto out; 725 } 726 if (vport->fc_flag & FC_RSCN_MODE) 727 lpfc_els_flush_rscn(vport); 728 lpfc_vport_set_state(vport, FC_VPORT_FAILED); 729 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, 730 "0257 GID_FT Query error: 0x%x 0x%x\n", 731 irsp->ulpStatus, vport->fc_ns_retry); 732 } else { 733 /* Good status, continue checking */ 734 CTreq = (struct lpfc_sli_ct_request *) inp->virt; 735 CTrsp = (struct lpfc_sli_ct_request *) outp->virt; 736 if (CTrsp->CommandResponse.bits.CmdRsp == 737 cpu_to_be16(SLI_CT_RESPONSE_FS_ACC)) { 738 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, 739 "0208 NameServer Rsp Data: x%x x%x\n", 740 vport->fc_flag, 741 CTreq->un.gid.Fc4Type); 742 743 lpfc_ns_rsp(vport, 744 outp, 745 CTreq->un.gid.Fc4Type, 746 (uint32_t) (irsp->un.genreq64.bdl.bdeSize)); 747 } else if (CTrsp->CommandResponse.bits.CmdRsp == 748 be16_to_cpu(SLI_CT_RESPONSE_FS_RJT)) { 749 /* NameServer Rsp Error */ 750 if ((CTrsp->ReasonCode == SLI_CT_UNABLE_TO_PERFORM_REQ) 751 && (CTrsp->Explanation == SLI_CT_NO_FC4_TYPES)) { 752 lpfc_printf_vlog(vport, KERN_INFO, 753 LOG_DISCOVERY, 754 "0269 No NameServer Entries " 755 "Data: x%x x%x x%x x%x\n", 756 CTrsp->CommandResponse.bits.CmdRsp, 757 (uint32_t) CTrsp->ReasonCode, 758 (uint32_t) CTrsp->Explanation, 759 vport->fc_flag); 760 761 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT, 762 "GID_FT no entry cmd:x%x rsn:x%x exp:x%x", 763 (uint32_t)CTrsp->CommandResponse.bits.CmdRsp, 764 (uint32_t) CTrsp->ReasonCode, 765 (uint32_t) CTrsp->Explanation); 766 } else { 767 lpfc_printf_vlog(vport, KERN_INFO, 768 LOG_DISCOVERY, 769 "0240 NameServer Rsp Error " 770 "Data: x%x x%x x%x x%x\n", 771 CTrsp->CommandResponse.bits.CmdRsp, 772 (uint32_t) CTrsp->ReasonCode, 773 (uint32_t) CTrsp->Explanation, 774 vport->fc_flag); 775 776 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT, 777 "GID_FT rsp err1 cmd:x%x rsn:x%x exp:x%x", 778 (uint32_t)CTrsp->CommandResponse.bits.CmdRsp, 779 (uint32_t) CTrsp->ReasonCode, 780 (uint32_t) CTrsp->Explanation); 781 } 782 783 784 } else { 785 /* NameServer Rsp Error */ 786 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, 787 "0241 NameServer Rsp Error " 788 "Data: x%x x%x x%x x%x\n", 789 CTrsp->CommandResponse.bits.CmdRsp, 790 (uint32_t) CTrsp->ReasonCode, 791 (uint32_t) CTrsp->Explanation, 792 vport->fc_flag); 793 794 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT, 795 "GID_FT rsp err2 cmd:x%x rsn:x%x exp:x%x", 796 (uint32_t)CTrsp->CommandResponse.bits.CmdRsp, 797 (uint32_t) CTrsp->ReasonCode, 798 (uint32_t) CTrsp->Explanation); 799 } 800 vport->gidft_inp--; 801 } 802 /* Link up / RSCN discovery */ 803 if ((vport->num_disc_nodes == 0) && 804 (vport->gidft_inp == 0)) { 805 /* 806 * The driver has cycled through all Nports in the RSCN payload. 807 * Complete the handling by cleaning up and marking the 808 * current driver state. 809 */ 810 if (vport->port_state >= LPFC_DISC_AUTH) { 811 if (vport->fc_flag & FC_RSCN_MODE) { 812 lpfc_els_flush_rscn(vport); 813 spin_lock_irq(shost->host_lock); 814 vport->fc_flag |= FC_RSCN_MODE; /* RSCN still */ 815 spin_unlock_irq(shost->host_lock); 816 } 817 else 818 lpfc_els_flush_rscn(vport); 819 } 820 821 lpfc_disc_start(vport); 822 } 823 out: 824 cmdiocb->context_un.ndlp = ndlp; /* Now restore ndlp for free */ 825 lpfc_ct_free_iocb(phba, cmdiocb); 826 return; 827 } 828 829 static void 830 lpfc_cmpl_ct_cmd_gff_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, 831 struct lpfc_iocbq *rspiocb) 832 { 833 struct lpfc_vport *vport = cmdiocb->vport; 834 struct Scsi_Host *shost = lpfc_shost_from_vport(vport); 835 IOCB_t *irsp = &rspiocb->iocb; 836 struct lpfc_dmabuf *inp = (struct lpfc_dmabuf *) cmdiocb->context1; 837 struct lpfc_dmabuf *outp = (struct lpfc_dmabuf *) cmdiocb->context2; 838 struct lpfc_sli_ct_request *CTrsp; 839 int did, rc, retry; 840 uint8_t fbits; 841 struct lpfc_nodelist *ndlp; 842 843 did = ((struct lpfc_sli_ct_request *) inp->virt)->un.gff.PortId; 844 did = be32_to_cpu(did); 845 846 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT, 847 "GFF_ID cmpl: status:x%x/x%x did:x%x", 848 irsp->ulpStatus, irsp->un.ulpWord[4], did); 849 850 if (irsp->ulpStatus == IOSTAT_SUCCESS) { 851 /* Good status, continue checking */ 852 CTrsp = (struct lpfc_sli_ct_request *) outp->virt; 853 fbits = CTrsp->un.gff_acc.fbits[FCP_TYPE_FEATURE_OFFSET]; 854 855 if (CTrsp->CommandResponse.bits.CmdRsp == 856 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC)) { 857 if ((fbits & FC4_FEATURE_INIT) && 858 !(fbits & FC4_FEATURE_TARGET)) { 859 lpfc_printf_vlog(vport, KERN_INFO, 860 LOG_DISCOVERY, 861 "0270 Skip x%x GFF " 862 "NameServer Rsp Data: (init) " 863 "x%x x%x\n", did, fbits, 864 vport->fc_rscn_id_cnt); 865 goto out; 866 } 867 } 868 } 869 else { 870 /* Check for retry */ 871 if (cmdiocb->retry < LPFC_MAX_NS_RETRY) { 872 retry = 1; 873 if (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) { 874 switch ((irsp->un.ulpWord[4] & 875 IOERR_PARAM_MASK)) { 876 877 case IOERR_NO_RESOURCES: 878 /* We don't increment the retry 879 * count for this case. 880 */ 881 break; 882 case IOERR_LINK_DOWN: 883 case IOERR_SLI_ABORTED: 884 case IOERR_SLI_DOWN: 885 retry = 0; 886 break; 887 default: 888 cmdiocb->retry++; 889 } 890 } 891 else 892 cmdiocb->retry++; 893 894 if (retry) { 895 /* CT command is being retried */ 896 rc = lpfc_ns_cmd(vport, SLI_CTNS_GFF_ID, 897 cmdiocb->retry, did); 898 if (rc == 0) { 899 /* success */ 900 lpfc_ct_free_iocb(phba, cmdiocb); 901 return; 902 } 903 } 904 } 905 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, 906 "0267 NameServer GFF Rsp " 907 "x%x Error (%d %d) Data: x%x x%x\n", 908 did, irsp->ulpStatus, irsp->un.ulpWord[4], 909 vport->fc_flag, vport->fc_rscn_id_cnt); 910 } 911 912 /* This is a target port, unregistered port, or the GFF_ID failed */ 913 ndlp = lpfc_setup_disc_node(vport, did); 914 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) { 915 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, 916 "0242 Process x%x GFF " 917 "NameServer Rsp Data: x%x x%x x%x\n", 918 did, ndlp->nlp_flag, vport->fc_flag, 919 vport->fc_rscn_id_cnt); 920 } else { 921 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, 922 "0243 Skip x%x GFF " 923 "NameServer Rsp Data: x%x x%x\n", did, 924 vport->fc_flag, vport->fc_rscn_id_cnt); 925 } 926 out: 927 /* Link up / RSCN discovery */ 928 if (vport->num_disc_nodes) 929 vport->num_disc_nodes--; 930 if (vport->num_disc_nodes == 0) { 931 /* 932 * The driver has cycled through all Nports in the RSCN payload. 933 * Complete the handling by cleaning up and marking the 934 * current driver state. 935 */ 936 if (vport->port_state >= LPFC_DISC_AUTH) { 937 if (vport->fc_flag & FC_RSCN_MODE) { 938 lpfc_els_flush_rscn(vport); 939 spin_lock_irq(shost->host_lock); 940 vport->fc_flag |= FC_RSCN_MODE; /* RSCN still */ 941 spin_unlock_irq(shost->host_lock); 942 } 943 else 944 lpfc_els_flush_rscn(vport); 945 } 946 lpfc_disc_start(vport); 947 } 948 lpfc_ct_free_iocb(phba, cmdiocb); 949 return; 950 } 951 952 static void 953 lpfc_cmpl_ct_cmd_gft_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, 954 struct lpfc_iocbq *rspiocb) 955 { 956 struct lpfc_vport *vport = cmdiocb->vport; 957 IOCB_t *irsp = &rspiocb->iocb; 958 struct lpfc_dmabuf *inp = (struct lpfc_dmabuf *)cmdiocb->context1; 959 struct lpfc_dmabuf *outp = (struct lpfc_dmabuf *)cmdiocb->context2; 960 struct lpfc_sli_ct_request *CTrsp; 961 int did; 962 struct lpfc_nodelist *ndlp; 963 uint32_t fc4_data_0, fc4_data_1; 964 965 did = ((struct lpfc_sli_ct_request *)inp->virt)->un.gft.PortId; 966 did = be32_to_cpu(did); 967 968 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT, 969 "GFT_ID cmpl: status:x%x/x%x did:x%x", 970 irsp->ulpStatus, irsp->un.ulpWord[4], did); 971 972 if (irsp->ulpStatus == IOSTAT_SUCCESS) { 973 /* Good status, continue checking */ 974 CTrsp = (struct lpfc_sli_ct_request *)outp->virt; 975 fc4_data_0 = be32_to_cpu(CTrsp->un.gft_acc.fc4_types[0]); 976 fc4_data_1 = be32_to_cpu(CTrsp->un.gft_acc.fc4_types[1]); 977 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, 978 "3062 DID x%06x GFT Wd0 x%08x Wd1 x%08x\n", 979 did, fc4_data_0, fc4_data_1); 980 981 ndlp = lpfc_findnode_did(vport, did); 982 if (ndlp) { 983 /* The bitmask value for FCP and NVME FCP types is 984 * the same because they are 32 bits distant from 985 * each other in word0 and word0. 986 */ 987 if (fc4_data_0 & LPFC_FC4_TYPE_BITMASK) 988 ndlp->nlp_fc4_type |= NLP_FC4_FCP; 989 if (fc4_data_1 & LPFC_FC4_TYPE_BITMASK) 990 ndlp->nlp_fc4_type |= NLP_FC4_NVME; 991 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, 992 "3064 Setting ndlp %p, DID x%06x with " 993 "FC4 x%08x, Data: x%08x x%08x\n", 994 ndlp, did, ndlp->nlp_fc4_type, 995 FC_TYPE_FCP, FC_TYPE_NVME); 996 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE; 997 998 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE); 999 lpfc_issue_els_prli(vport, ndlp, 0); 1000 } 1001 } else 1002 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, 1003 "3065 GFT_ID failed x%08x\n", irsp->ulpStatus); 1004 1005 lpfc_ct_free_iocb(phba, cmdiocb); 1006 } 1007 1008 static void 1009 lpfc_cmpl_ct(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, 1010 struct lpfc_iocbq *rspiocb) 1011 { 1012 struct lpfc_vport *vport = cmdiocb->vport; 1013 struct lpfc_dmabuf *inp; 1014 struct lpfc_dmabuf *outp; 1015 IOCB_t *irsp; 1016 struct lpfc_sli_ct_request *CTrsp; 1017 struct lpfc_nodelist *ndlp; 1018 int cmdcode, rc; 1019 uint8_t retry; 1020 uint32_t latt; 1021 1022 /* First save ndlp, before we overwrite it */ 1023 ndlp = cmdiocb->context_un.ndlp; 1024 1025 /* we pass cmdiocb to state machine which needs rspiocb as well */ 1026 cmdiocb->context_un.rsp_iocb = rspiocb; 1027 1028 inp = (struct lpfc_dmabuf *) cmdiocb->context1; 1029 outp = (struct lpfc_dmabuf *) cmdiocb->context2; 1030 irsp = &rspiocb->iocb; 1031 1032 cmdcode = be16_to_cpu(((struct lpfc_sli_ct_request *) inp->virt)-> 1033 CommandResponse.bits.CmdRsp); 1034 CTrsp = (struct lpfc_sli_ct_request *) outp->virt; 1035 1036 latt = lpfc_els_chk_latt(vport); 1037 1038 /* RFT request completes status <ulpStatus> CmdRsp <CmdRsp> */ 1039 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, 1040 "0209 CT Request completes, latt %d, " 1041 "ulpStatus x%x CmdRsp x%x, Context x%x, Tag x%x\n", 1042 latt, irsp->ulpStatus, 1043 CTrsp->CommandResponse.bits.CmdRsp, 1044 cmdiocb->iocb.ulpContext, cmdiocb->iocb.ulpIoTag); 1045 1046 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT, 1047 "CT cmd cmpl: status:x%x/x%x cmd:x%x", 1048 irsp->ulpStatus, irsp->un.ulpWord[4], cmdcode); 1049 1050 if (irsp->ulpStatus) { 1051 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, 1052 "0268 NS cmd x%x Error (x%x x%x)\n", 1053 cmdcode, irsp->ulpStatus, irsp->un.ulpWord[4]); 1054 1055 if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) && 1056 (((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) == 1057 IOERR_SLI_DOWN) || 1058 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) == 1059 IOERR_SLI_ABORTED))) 1060 goto out; 1061 1062 retry = cmdiocb->retry; 1063 if (retry >= LPFC_MAX_NS_RETRY) 1064 goto out; 1065 1066 retry++; 1067 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, 1068 "0250 Retrying NS cmd %x\n", cmdcode); 1069 rc = lpfc_ns_cmd(vport, cmdcode, retry, 0); 1070 if (rc == 0) 1071 goto out; 1072 } 1073 1074 out: 1075 cmdiocb->context_un.ndlp = ndlp; /* Now restore ndlp for free */ 1076 lpfc_ct_free_iocb(phba, cmdiocb); 1077 return; 1078 } 1079 1080 static void 1081 lpfc_cmpl_ct_cmd_rft_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, 1082 struct lpfc_iocbq *rspiocb) 1083 { 1084 IOCB_t *irsp = &rspiocb->iocb; 1085 struct lpfc_vport *vport = cmdiocb->vport; 1086 1087 if (irsp->ulpStatus == IOSTAT_SUCCESS) { 1088 struct lpfc_dmabuf *outp; 1089 struct lpfc_sli_ct_request *CTrsp; 1090 1091 outp = (struct lpfc_dmabuf *) cmdiocb->context2; 1092 CTrsp = (struct lpfc_sli_ct_request *) outp->virt; 1093 if (CTrsp->CommandResponse.bits.CmdRsp == 1094 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC)) 1095 vport->ct_flags |= FC_CT_RFT_ID; 1096 } 1097 lpfc_cmpl_ct(phba, cmdiocb, rspiocb); 1098 return; 1099 } 1100 1101 static void 1102 lpfc_cmpl_ct_cmd_rnn_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, 1103 struct lpfc_iocbq *rspiocb) 1104 { 1105 IOCB_t *irsp = &rspiocb->iocb; 1106 struct lpfc_vport *vport = cmdiocb->vport; 1107 1108 if (irsp->ulpStatus == IOSTAT_SUCCESS) { 1109 struct lpfc_dmabuf *outp; 1110 struct lpfc_sli_ct_request *CTrsp; 1111 1112 outp = (struct lpfc_dmabuf *) cmdiocb->context2; 1113 CTrsp = (struct lpfc_sli_ct_request *) outp->virt; 1114 if (CTrsp->CommandResponse.bits.CmdRsp == 1115 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC)) 1116 vport->ct_flags |= FC_CT_RNN_ID; 1117 } 1118 lpfc_cmpl_ct(phba, cmdiocb, rspiocb); 1119 return; 1120 } 1121 1122 static void 1123 lpfc_cmpl_ct_cmd_rspn_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, 1124 struct lpfc_iocbq *rspiocb) 1125 { 1126 IOCB_t *irsp = &rspiocb->iocb; 1127 struct lpfc_vport *vport = cmdiocb->vport; 1128 1129 if (irsp->ulpStatus == IOSTAT_SUCCESS) { 1130 struct lpfc_dmabuf *outp; 1131 struct lpfc_sli_ct_request *CTrsp; 1132 1133 outp = (struct lpfc_dmabuf *) cmdiocb->context2; 1134 CTrsp = (struct lpfc_sli_ct_request *) outp->virt; 1135 if (CTrsp->CommandResponse.bits.CmdRsp == 1136 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC)) 1137 vport->ct_flags |= FC_CT_RSPN_ID; 1138 } 1139 lpfc_cmpl_ct(phba, cmdiocb, rspiocb); 1140 return; 1141 } 1142 1143 static void 1144 lpfc_cmpl_ct_cmd_rsnn_nn(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, 1145 struct lpfc_iocbq *rspiocb) 1146 { 1147 IOCB_t *irsp = &rspiocb->iocb; 1148 struct lpfc_vport *vport = cmdiocb->vport; 1149 1150 if (irsp->ulpStatus == IOSTAT_SUCCESS) { 1151 struct lpfc_dmabuf *outp; 1152 struct lpfc_sli_ct_request *CTrsp; 1153 1154 outp = (struct lpfc_dmabuf *) cmdiocb->context2; 1155 CTrsp = (struct lpfc_sli_ct_request *) outp->virt; 1156 if (CTrsp->CommandResponse.bits.CmdRsp == 1157 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC)) 1158 vport->ct_flags |= FC_CT_RSNN_NN; 1159 } 1160 lpfc_cmpl_ct(phba, cmdiocb, rspiocb); 1161 return; 1162 } 1163 1164 static void 1165 lpfc_cmpl_ct_cmd_da_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, 1166 struct lpfc_iocbq *rspiocb) 1167 { 1168 struct lpfc_vport *vport = cmdiocb->vport; 1169 1170 /* even if it fails we will act as though it succeeded. */ 1171 vport->ct_flags = 0; 1172 lpfc_cmpl_ct(phba, cmdiocb, rspiocb); 1173 return; 1174 } 1175 1176 static void 1177 lpfc_cmpl_ct_cmd_rff_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, 1178 struct lpfc_iocbq *rspiocb) 1179 { 1180 IOCB_t *irsp = &rspiocb->iocb; 1181 struct lpfc_vport *vport = cmdiocb->vport; 1182 1183 if (irsp->ulpStatus == IOSTAT_SUCCESS) { 1184 struct lpfc_dmabuf *outp; 1185 struct lpfc_sli_ct_request *CTrsp; 1186 1187 outp = (struct lpfc_dmabuf *) cmdiocb->context2; 1188 CTrsp = (struct lpfc_sli_ct_request *) outp->virt; 1189 if (CTrsp->CommandResponse.bits.CmdRsp == 1190 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC)) 1191 vport->ct_flags |= FC_CT_RFF_ID; 1192 } 1193 lpfc_cmpl_ct(phba, cmdiocb, rspiocb); 1194 return; 1195 } 1196 1197 /* 1198 * Although the symbolic port name is thought to be an integer 1199 * as of January 18, 2016, leave it as a string until more of 1200 * the record state becomes defined. 1201 */ 1202 int 1203 lpfc_vport_symbolic_port_name(struct lpfc_vport *vport, char *symbol, 1204 size_t size) 1205 { 1206 int n; 1207 1208 /* 1209 * Use the lpfc board number as the Symbolic Port 1210 * Name object. NPIV is not in play so this integer 1211 * value is sufficient and unique per FC-ID. 1212 */ 1213 n = snprintf(symbol, size, "%d", vport->phba->brd_no); 1214 return n; 1215 } 1216 1217 1218 int 1219 lpfc_vport_symbolic_node_name(struct lpfc_vport *vport, char *symbol, 1220 size_t size) 1221 { 1222 char fwrev[FW_REV_STR_SIZE]; 1223 int n; 1224 1225 lpfc_decode_firmware_rev(vport->phba, fwrev, 0); 1226 1227 n = snprintf(symbol, size, "Emulex %s", vport->phba->ModelName); 1228 if (size < n) 1229 return n; 1230 1231 n += snprintf(symbol + n, size - n, " FV%s", fwrev); 1232 if (size < n) 1233 return n; 1234 1235 n += snprintf(symbol + n, size - n, " DV%s.", 1236 lpfc_release_version); 1237 if (size < n) 1238 return n; 1239 1240 n += snprintf(symbol + n, size - n, " HN:%s.", 1241 init_utsname()->nodename); 1242 if (size < n) 1243 return n; 1244 1245 /* Note :- OS name is "Linux" */ 1246 n += snprintf(symbol + n, size - n, " OS:%s\n", 1247 init_utsname()->sysname); 1248 return n; 1249 } 1250 1251 static uint32_t 1252 lpfc_find_map_node(struct lpfc_vport *vport) 1253 { 1254 struct lpfc_nodelist *ndlp, *next_ndlp; 1255 struct Scsi_Host *shost; 1256 uint32_t cnt = 0; 1257 1258 shost = lpfc_shost_from_vport(vport); 1259 spin_lock_irq(shost->host_lock); 1260 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) { 1261 if (ndlp->nlp_type & NLP_FABRIC) 1262 continue; 1263 if ((ndlp->nlp_state == NLP_STE_MAPPED_NODE) || 1264 (ndlp->nlp_state == NLP_STE_UNMAPPED_NODE)) 1265 cnt++; 1266 } 1267 spin_unlock_irq(shost->host_lock); 1268 return cnt; 1269 } 1270 1271 /* 1272 * This routine will return the FC4 Type associated with the CT 1273 * GID_FT command. 1274 */ 1275 int 1276 lpfc_get_gidft_type(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb) 1277 { 1278 struct lpfc_sli_ct_request *CtReq; 1279 struct lpfc_dmabuf *mp; 1280 uint32_t type; 1281 1282 mp = cmdiocb->context1; 1283 if (mp == NULL) 1284 return 0; 1285 CtReq = (struct lpfc_sli_ct_request *)mp->virt; 1286 type = (uint32_t)CtReq->un.gid.Fc4Type; 1287 if ((type != SLI_CTPT_FCP) && (type != SLI_CTPT_NVME)) 1288 return 0; 1289 return type; 1290 } 1291 1292 /* 1293 * lpfc_ns_cmd 1294 * Description: 1295 * Issue Cmd to NameServer 1296 * SLI_CTNS_GID_FT 1297 * LI_CTNS_RFT_ID 1298 */ 1299 int 1300 lpfc_ns_cmd(struct lpfc_vport *vport, int cmdcode, 1301 uint8_t retry, uint32_t context) 1302 { 1303 struct lpfc_nodelist * ndlp; 1304 struct lpfc_hba *phba = vport->phba; 1305 struct lpfc_dmabuf *mp, *bmp; 1306 struct lpfc_sli_ct_request *CtReq; 1307 struct ulp_bde64 *bpl; 1308 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *, 1309 struct lpfc_iocbq *) = NULL; 1310 uint32_t rsp_size = 1024; 1311 size_t size; 1312 int rc = 0; 1313 1314 ndlp = lpfc_findnode_did(vport, NameServer_DID); 1315 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) 1316 || ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) { 1317 rc=1; 1318 goto ns_cmd_exit; 1319 } 1320 1321 /* fill in BDEs for command */ 1322 /* Allocate buffer for command payload */ 1323 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); 1324 if (!mp) { 1325 rc=2; 1326 goto ns_cmd_exit; 1327 } 1328 1329 INIT_LIST_HEAD(&mp->list); 1330 mp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(mp->phys)); 1331 if (!mp->virt) { 1332 rc=3; 1333 goto ns_cmd_free_mp; 1334 } 1335 1336 /* Allocate buffer for Buffer ptr list */ 1337 bmp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); 1338 if (!bmp) { 1339 rc=4; 1340 goto ns_cmd_free_mpvirt; 1341 } 1342 1343 INIT_LIST_HEAD(&bmp->list); 1344 bmp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(bmp->phys)); 1345 if (!bmp->virt) { 1346 rc=5; 1347 goto ns_cmd_free_bmp; 1348 } 1349 1350 /* NameServer Req */ 1351 lpfc_printf_vlog(vport, KERN_INFO ,LOG_DISCOVERY, 1352 "0236 NameServer Req Data: x%x x%x x%x x%x\n", 1353 cmdcode, vport->fc_flag, vport->fc_rscn_id_cnt, 1354 context); 1355 1356 bpl = (struct ulp_bde64 *) bmp->virt; 1357 memset(bpl, 0, sizeof(struct ulp_bde64)); 1358 bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys) ); 1359 bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys) ); 1360 bpl->tus.f.bdeFlags = 0; 1361 if (cmdcode == SLI_CTNS_GID_FT) 1362 bpl->tus.f.bdeSize = GID_REQUEST_SZ; 1363 else if (cmdcode == SLI_CTNS_GFF_ID) 1364 bpl->tus.f.bdeSize = GFF_REQUEST_SZ; 1365 else if (cmdcode == SLI_CTNS_GFT_ID) 1366 bpl->tus.f.bdeSize = GFT_REQUEST_SZ; 1367 else if (cmdcode == SLI_CTNS_RFT_ID) 1368 bpl->tus.f.bdeSize = RFT_REQUEST_SZ; 1369 else if (cmdcode == SLI_CTNS_RNN_ID) 1370 bpl->tus.f.bdeSize = RNN_REQUEST_SZ; 1371 else if (cmdcode == SLI_CTNS_RSPN_ID) 1372 bpl->tus.f.bdeSize = RSPN_REQUEST_SZ; 1373 else if (cmdcode == SLI_CTNS_RSNN_NN) 1374 bpl->tus.f.bdeSize = RSNN_REQUEST_SZ; 1375 else if (cmdcode == SLI_CTNS_DA_ID) 1376 bpl->tus.f.bdeSize = DA_ID_REQUEST_SZ; 1377 else if (cmdcode == SLI_CTNS_RFF_ID) 1378 bpl->tus.f.bdeSize = RFF_REQUEST_SZ; 1379 else 1380 bpl->tus.f.bdeSize = 0; 1381 bpl->tus.w = le32_to_cpu(bpl->tus.w); 1382 1383 CtReq = (struct lpfc_sli_ct_request *) mp->virt; 1384 memset(CtReq, 0, sizeof(struct lpfc_sli_ct_request)); 1385 CtReq->RevisionId.bits.Revision = SLI_CT_REVISION; 1386 CtReq->RevisionId.bits.InId = 0; 1387 CtReq->FsType = SLI_CT_DIRECTORY_SERVICE; 1388 CtReq->FsSubType = SLI_CT_DIRECTORY_NAME_SERVER; 1389 CtReq->CommandResponse.bits.Size = 0; 1390 switch (cmdcode) { 1391 case SLI_CTNS_GID_FT: 1392 CtReq->CommandResponse.bits.CmdRsp = 1393 cpu_to_be16(SLI_CTNS_GID_FT); 1394 CtReq->un.gid.Fc4Type = context; 1395 1396 if (vport->port_state < LPFC_NS_QRY) 1397 vport->port_state = LPFC_NS_QRY; 1398 lpfc_set_disctmo(vport); 1399 cmpl = lpfc_cmpl_ct_cmd_gid_ft; 1400 rsp_size = FC_MAX_NS_RSP; 1401 break; 1402 1403 case SLI_CTNS_GFF_ID: 1404 CtReq->CommandResponse.bits.CmdRsp = 1405 cpu_to_be16(SLI_CTNS_GFF_ID); 1406 CtReq->un.gff.PortId = cpu_to_be32(context); 1407 cmpl = lpfc_cmpl_ct_cmd_gff_id; 1408 break; 1409 1410 case SLI_CTNS_GFT_ID: 1411 CtReq->CommandResponse.bits.CmdRsp = 1412 cpu_to_be16(SLI_CTNS_GFT_ID); 1413 CtReq->un.gft.PortId = cpu_to_be32(context); 1414 cmpl = lpfc_cmpl_ct_cmd_gft_id; 1415 break; 1416 1417 case SLI_CTNS_RFT_ID: 1418 vport->ct_flags &= ~FC_CT_RFT_ID; 1419 CtReq->CommandResponse.bits.CmdRsp = 1420 cpu_to_be16(SLI_CTNS_RFT_ID); 1421 CtReq->un.rft.PortId = cpu_to_be32(vport->fc_myDID); 1422 1423 /* Register FC4 FCP type if enabled. */ 1424 if ((phba->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) || 1425 (phba->cfg_enable_fc4_type == LPFC_ENABLE_FCP)) 1426 CtReq->un.rft.fcpReg = 1; 1427 1428 /* Register NVME type if enabled. Defined LE and swapped. 1429 * rsvd[0] is used as word1 because of the hard-coded 1430 * word0 usage in the ct_request data structure. 1431 */ 1432 if ((phba->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) || 1433 (phba->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) 1434 CtReq->un.rft.rsvd[0] = cpu_to_be32(0x00000100); 1435 1436 cmpl = lpfc_cmpl_ct_cmd_rft_id; 1437 break; 1438 1439 case SLI_CTNS_RNN_ID: 1440 vport->ct_flags &= ~FC_CT_RNN_ID; 1441 CtReq->CommandResponse.bits.CmdRsp = 1442 cpu_to_be16(SLI_CTNS_RNN_ID); 1443 CtReq->un.rnn.PortId = cpu_to_be32(vport->fc_myDID); 1444 memcpy(CtReq->un.rnn.wwnn, &vport->fc_nodename, 1445 sizeof(struct lpfc_name)); 1446 cmpl = lpfc_cmpl_ct_cmd_rnn_id; 1447 break; 1448 1449 case SLI_CTNS_RSPN_ID: 1450 vport->ct_flags &= ~FC_CT_RSPN_ID; 1451 CtReq->CommandResponse.bits.CmdRsp = 1452 cpu_to_be16(SLI_CTNS_RSPN_ID); 1453 CtReq->un.rspn.PortId = cpu_to_be32(vport->fc_myDID); 1454 size = sizeof(CtReq->un.rspn.symbname); 1455 CtReq->un.rspn.len = 1456 lpfc_vport_symbolic_port_name(vport, 1457 CtReq->un.rspn.symbname, size); 1458 cmpl = lpfc_cmpl_ct_cmd_rspn_id; 1459 break; 1460 case SLI_CTNS_RSNN_NN: 1461 vport->ct_flags &= ~FC_CT_RSNN_NN; 1462 CtReq->CommandResponse.bits.CmdRsp = 1463 cpu_to_be16(SLI_CTNS_RSNN_NN); 1464 memcpy(CtReq->un.rsnn.wwnn, &vport->fc_nodename, 1465 sizeof(struct lpfc_name)); 1466 size = sizeof(CtReq->un.rsnn.symbname); 1467 CtReq->un.rsnn.len = 1468 lpfc_vport_symbolic_node_name(vport, 1469 CtReq->un.rsnn.symbname, size); 1470 cmpl = lpfc_cmpl_ct_cmd_rsnn_nn; 1471 break; 1472 case SLI_CTNS_DA_ID: 1473 /* Implement DA_ID Nameserver request */ 1474 CtReq->CommandResponse.bits.CmdRsp = 1475 cpu_to_be16(SLI_CTNS_DA_ID); 1476 CtReq->un.da_id.port_id = cpu_to_be32(vport->fc_myDID); 1477 cmpl = lpfc_cmpl_ct_cmd_da_id; 1478 break; 1479 case SLI_CTNS_RFF_ID: 1480 vport->ct_flags &= ~FC_CT_RFF_ID; 1481 CtReq->CommandResponse.bits.CmdRsp = 1482 cpu_to_be16(SLI_CTNS_RFF_ID); 1483 CtReq->un.rff.PortId = cpu_to_be32(vport->fc_myDID); 1484 CtReq->un.rff.fbits = FC4_FEATURE_INIT; 1485 1486 /* The driver always supports FC_TYPE_FCP. However, the 1487 * caller can specify NVME (type x28) as well. But only 1488 * these that FC4 type is supported. 1489 */ 1490 if (((phba->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) || 1491 (phba->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) && 1492 (context == FC_TYPE_NVME)) { 1493 if ((vport == phba->pport) && phba->nvmet_support) { 1494 CtReq->un.rff.fbits = (FC4_FEATURE_TARGET | 1495 FC4_FEATURE_NVME_DISC); 1496 lpfc_nvmet_update_targetport(phba); 1497 } else { 1498 lpfc_nvme_update_localport(vport); 1499 } 1500 CtReq->un.rff.type_code = context; 1501 1502 } else if (((phba->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) || 1503 (phba->cfg_enable_fc4_type == LPFC_ENABLE_FCP)) && 1504 (context == FC_TYPE_FCP)) 1505 CtReq->un.rff.type_code = context; 1506 1507 else 1508 goto ns_cmd_free_bmpvirt; 1509 1510 cmpl = lpfc_cmpl_ct_cmd_rff_id; 1511 break; 1512 } 1513 /* The lpfc_ct_cmd/lpfc_get_req shall increment ndlp reference count 1514 * to hold ndlp reference for the corresponding callback function. 1515 */ 1516 if (!lpfc_ct_cmd(vport, mp, bmp, ndlp, cmpl, rsp_size, retry)) { 1517 /* On success, The cmpl function will free the buffers */ 1518 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT, 1519 "Issue CT cmd: cmd:x%x did:x%x", 1520 cmdcode, ndlp->nlp_DID, 0); 1521 return 0; 1522 } 1523 rc=6; 1524 1525 /* Decrement ndlp reference count to release ndlp reference held 1526 * for the failed command's callback function. 1527 */ 1528 lpfc_nlp_put(ndlp); 1529 1530 ns_cmd_free_bmpvirt: 1531 lpfc_mbuf_free(phba, bmp->virt, bmp->phys); 1532 ns_cmd_free_bmp: 1533 kfree(bmp); 1534 ns_cmd_free_mpvirt: 1535 lpfc_mbuf_free(phba, mp->virt, mp->phys); 1536 ns_cmd_free_mp: 1537 kfree(mp); 1538 ns_cmd_exit: 1539 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, 1540 "0266 Issue NameServer Req x%x err %d Data: x%x x%x\n", 1541 cmdcode, rc, vport->fc_flag, vport->fc_rscn_id_cnt); 1542 return 1; 1543 } 1544 1545 /** 1546 * lpfc_cmpl_ct_disc_fdmi - Handle a discovery FDMI completion 1547 * @phba: Pointer to HBA context object. 1548 * @cmdiocb: Pointer to the command IOCBQ. 1549 * @rspiocb: Pointer to the response IOCBQ. 1550 * 1551 * This function to handle the completion of a driver initiated FDMI 1552 * CT command issued during discovery. 1553 */ 1554 static void 1555 lpfc_cmpl_ct_disc_fdmi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, 1556 struct lpfc_iocbq *rspiocb) 1557 { 1558 struct lpfc_vport *vport = cmdiocb->vport; 1559 struct lpfc_dmabuf *inp = cmdiocb->context1; 1560 struct lpfc_dmabuf *outp = cmdiocb->context2; 1561 struct lpfc_sli_ct_request *CTcmd = inp->virt; 1562 struct lpfc_sli_ct_request *CTrsp = outp->virt; 1563 uint16_t fdmi_cmd = CTcmd->CommandResponse.bits.CmdRsp; 1564 uint16_t fdmi_rsp = CTrsp->CommandResponse.bits.CmdRsp; 1565 IOCB_t *irsp = &rspiocb->iocb; 1566 struct lpfc_nodelist *ndlp; 1567 uint32_t latt, cmd, err; 1568 1569 latt = lpfc_els_chk_latt(vport); 1570 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT, 1571 "FDMI cmpl: status:x%x/x%x latt:%d", 1572 irsp->ulpStatus, irsp->un.ulpWord[4], latt); 1573 1574 if (latt || irsp->ulpStatus) { 1575 1576 /* Look for a retryable error */ 1577 if (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) { 1578 switch ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK)) { 1579 case IOERR_SLI_ABORTED: 1580 case IOERR_ABORT_IN_PROGRESS: 1581 case IOERR_SEQUENCE_TIMEOUT: 1582 case IOERR_ILLEGAL_FRAME: 1583 case IOERR_NO_RESOURCES: 1584 case IOERR_ILLEGAL_COMMAND: 1585 cmdiocb->retry++; 1586 if (cmdiocb->retry >= LPFC_FDMI_MAX_RETRY) 1587 break; 1588 1589 /* Retry the same FDMI command */ 1590 err = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, 1591 cmdiocb, 0); 1592 if (err == IOCB_ERROR) 1593 break; 1594 return; 1595 default: 1596 break; 1597 } 1598 } 1599 1600 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, 1601 "0229 FDMI cmd %04x failed, latt = %d " 1602 "ulpStatus: x%x, rid x%x\n", 1603 be16_to_cpu(fdmi_cmd), latt, irsp->ulpStatus, 1604 irsp->un.ulpWord[4]); 1605 } 1606 lpfc_ct_free_iocb(phba, cmdiocb); 1607 1608 ndlp = lpfc_findnode_did(vport, FDMI_DID); 1609 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) 1610 return; 1611 1612 /* Check for a CT LS_RJT response */ 1613 cmd = be16_to_cpu(fdmi_cmd); 1614 if (fdmi_rsp == cpu_to_be16(SLI_CT_RESPONSE_FS_RJT)) { 1615 /* FDMI rsp failed */ 1616 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, 1617 "0220 FDMI cmd failed FS_RJT Data: x%x", cmd); 1618 1619 /* Should we fallback to FDMI-2 / FDMI-1 ? */ 1620 switch (cmd) { 1621 case SLI_MGMT_RHBA: 1622 if (vport->fdmi_hba_mask == LPFC_FDMI2_HBA_ATTR) { 1623 /* Fallback to FDMI-1 */ 1624 vport->fdmi_hba_mask = LPFC_FDMI1_HBA_ATTR; 1625 vport->fdmi_port_mask = LPFC_FDMI1_PORT_ATTR; 1626 /* Start over */ 1627 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA, 0); 1628 } 1629 return; 1630 1631 case SLI_MGMT_RPRT: 1632 if (vport->fdmi_port_mask == LPFC_FDMI2_PORT_ATTR) { 1633 /* Fallback to FDMI-1 */ 1634 vport->fdmi_port_mask = LPFC_FDMI1_PORT_ATTR; 1635 /* Start over */ 1636 lpfc_fdmi_cmd(vport, ndlp, cmd, 0); 1637 } 1638 if (vport->fdmi_port_mask == LPFC_FDMI2_SMART_ATTR) { 1639 vport->fdmi_port_mask = LPFC_FDMI2_PORT_ATTR; 1640 /* Retry the same command */ 1641 lpfc_fdmi_cmd(vport, ndlp, cmd, 0); 1642 } 1643 return; 1644 1645 case SLI_MGMT_RPA: 1646 if (vport->fdmi_port_mask == LPFC_FDMI2_PORT_ATTR) { 1647 /* Fallback to FDMI-1 */ 1648 vport->fdmi_hba_mask = LPFC_FDMI1_HBA_ATTR; 1649 vport->fdmi_port_mask = LPFC_FDMI1_PORT_ATTR; 1650 /* Start over */ 1651 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA, 0); 1652 } 1653 if (vport->fdmi_port_mask == LPFC_FDMI2_SMART_ATTR) { 1654 vport->fdmi_port_mask = LPFC_FDMI2_PORT_ATTR; 1655 /* Retry the same command */ 1656 lpfc_fdmi_cmd(vport, ndlp, cmd, 0); 1657 } 1658 return; 1659 } 1660 } 1661 1662 /* 1663 * On success, need to cycle thru FDMI registration for discovery 1664 * DHBA -> DPRT -> RHBA -> RPA (physical port) 1665 * DPRT -> RPRT (vports) 1666 */ 1667 switch (cmd) { 1668 case SLI_MGMT_RHBA: 1669 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RPA, 0); 1670 break; 1671 1672 case SLI_MGMT_DHBA: 1673 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DPRT, 0); 1674 break; 1675 1676 case SLI_MGMT_DPRT: 1677 if (vport->port_type == LPFC_PHYSICAL_PORT) 1678 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RHBA, 0); 1679 else 1680 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RPRT, 0); 1681 break; 1682 } 1683 return; 1684 } 1685 1686 1687 /** 1688 * lpfc_fdmi_num_disc_check - Check how many mapped NPorts we are connected to 1689 * @vport: pointer to a host virtual N_Port data structure. 1690 * 1691 * Called from hbeat timeout routine to check if the number of discovered 1692 * ports has changed. If so, re-register thar port Attribute. 1693 */ 1694 void 1695 lpfc_fdmi_num_disc_check(struct lpfc_vport *vport) 1696 { 1697 struct lpfc_hba *phba = vport->phba; 1698 struct lpfc_nodelist *ndlp; 1699 uint16_t cnt; 1700 1701 if (!lpfc_is_link_up(phba)) 1702 return; 1703 1704 /* Must be connected to a Fabric */ 1705 if (!(vport->fc_flag & FC_FABRIC)) 1706 return; 1707 1708 if (!(vport->fdmi_port_mask & LPFC_FDMI_PORT_ATTR_num_disc)) 1709 return; 1710 1711 cnt = lpfc_find_map_node(vport); 1712 if (cnt == vport->fdmi_num_disc) 1713 return; 1714 1715 ndlp = lpfc_findnode_did(vport, FDMI_DID); 1716 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) 1717 return; 1718 1719 if (vport->port_type == LPFC_PHYSICAL_PORT) { 1720 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RPA, 1721 LPFC_FDMI_PORT_ATTR_num_disc); 1722 } else { 1723 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RPRT, 1724 LPFC_FDMI_PORT_ATTR_num_disc); 1725 } 1726 } 1727 1728 /* Routines for all individual HBA attributes */ 1729 static int 1730 lpfc_fdmi_hba_attr_wwnn(struct lpfc_vport *vport, struct lpfc_fdmi_attr_def *ad) 1731 { 1732 struct lpfc_fdmi_attr_entry *ae; 1733 uint32_t size; 1734 1735 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue; 1736 memset(ae, 0, sizeof(struct lpfc_name)); 1737 1738 memcpy(&ae->un.AttrWWN, &vport->fc_sparam.nodeName, 1739 sizeof(struct lpfc_name)); 1740 size = FOURBYTES + sizeof(struct lpfc_name); 1741 ad->AttrLen = cpu_to_be16(size); 1742 ad->AttrType = cpu_to_be16(RHBA_NODENAME); 1743 return size; 1744 } 1745 static int 1746 lpfc_fdmi_hba_attr_manufacturer(struct lpfc_vport *vport, 1747 struct lpfc_fdmi_attr_def *ad) 1748 { 1749 struct lpfc_fdmi_attr_entry *ae; 1750 uint32_t len, size; 1751 1752 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue; 1753 memset(ae, 0, 256); 1754 1755 strncpy(ae->un.AttrString, 1756 "Emulex Corporation", 1757 sizeof(ae->un.AttrString)); 1758 len = strnlen(ae->un.AttrString, 1759 sizeof(ae->un.AttrString)); 1760 len += (len & 3) ? (4 - (len & 3)) : 4; 1761 size = FOURBYTES + len; 1762 ad->AttrLen = cpu_to_be16(size); 1763 ad->AttrType = cpu_to_be16(RHBA_MANUFACTURER); 1764 return size; 1765 } 1766 1767 static int 1768 lpfc_fdmi_hba_attr_sn(struct lpfc_vport *vport, struct lpfc_fdmi_attr_def *ad) 1769 { 1770 struct lpfc_hba *phba = vport->phba; 1771 struct lpfc_fdmi_attr_entry *ae; 1772 uint32_t len, size; 1773 1774 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue; 1775 memset(ae, 0, 256); 1776 1777 strncpy(ae->un.AttrString, phba->SerialNumber, 1778 sizeof(ae->un.AttrString)); 1779 len = strnlen(ae->un.AttrString, 1780 sizeof(ae->un.AttrString)); 1781 len += (len & 3) ? (4 - (len & 3)) : 4; 1782 size = FOURBYTES + len; 1783 ad->AttrLen = cpu_to_be16(size); 1784 ad->AttrType = cpu_to_be16(RHBA_SERIAL_NUMBER); 1785 return size; 1786 } 1787 1788 static int 1789 lpfc_fdmi_hba_attr_model(struct lpfc_vport *vport, 1790 struct lpfc_fdmi_attr_def *ad) 1791 { 1792 struct lpfc_hba *phba = vport->phba; 1793 struct lpfc_fdmi_attr_entry *ae; 1794 uint32_t len, size; 1795 1796 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue; 1797 memset(ae, 0, 256); 1798 1799 strncpy(ae->un.AttrString, phba->ModelName, 1800 sizeof(ae->un.AttrString)); 1801 len = strnlen(ae->un.AttrString, sizeof(ae->un.AttrString)); 1802 len += (len & 3) ? (4 - (len & 3)) : 4; 1803 size = FOURBYTES + len; 1804 ad->AttrLen = cpu_to_be16(size); 1805 ad->AttrType = cpu_to_be16(RHBA_MODEL); 1806 return size; 1807 } 1808 1809 static int 1810 lpfc_fdmi_hba_attr_description(struct lpfc_vport *vport, 1811 struct lpfc_fdmi_attr_def *ad) 1812 { 1813 struct lpfc_hba *phba = vport->phba; 1814 struct lpfc_fdmi_attr_entry *ae; 1815 uint32_t len, size; 1816 1817 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue; 1818 memset(ae, 0, 256); 1819 1820 strncpy(ae->un.AttrString, phba->ModelDesc, 1821 sizeof(ae->un.AttrString)); 1822 len = strnlen(ae->un.AttrString, 1823 sizeof(ae->un.AttrString)); 1824 len += (len & 3) ? (4 - (len & 3)) : 4; 1825 size = FOURBYTES + len; 1826 ad->AttrLen = cpu_to_be16(size); 1827 ad->AttrType = cpu_to_be16(RHBA_MODEL_DESCRIPTION); 1828 return size; 1829 } 1830 1831 static int 1832 lpfc_fdmi_hba_attr_hdw_ver(struct lpfc_vport *vport, 1833 struct lpfc_fdmi_attr_def *ad) 1834 { 1835 struct lpfc_hba *phba = vport->phba; 1836 lpfc_vpd_t *vp = &phba->vpd; 1837 struct lpfc_fdmi_attr_entry *ae; 1838 uint32_t i, j, incr, size; 1839 1840 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue; 1841 memset(ae, 0, 256); 1842 1843 /* Convert JEDEC ID to ascii for hardware version */ 1844 incr = vp->rev.biuRev; 1845 for (i = 0; i < 8; i++) { 1846 j = (incr & 0xf); 1847 if (j <= 9) 1848 ae->un.AttrString[7 - i] = 1849 (char)((uint8_t) 0x30 + 1850 (uint8_t) j); 1851 else 1852 ae->un.AttrString[7 - i] = 1853 (char)((uint8_t) 0x61 + 1854 (uint8_t) (j - 10)); 1855 incr = (incr >> 4); 1856 } 1857 size = FOURBYTES + 8; 1858 ad->AttrLen = cpu_to_be16(size); 1859 ad->AttrType = cpu_to_be16(RHBA_HARDWARE_VERSION); 1860 return size; 1861 } 1862 1863 static int 1864 lpfc_fdmi_hba_attr_drvr_ver(struct lpfc_vport *vport, 1865 struct lpfc_fdmi_attr_def *ad) 1866 { 1867 struct lpfc_fdmi_attr_entry *ae; 1868 uint32_t len, size; 1869 1870 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue; 1871 memset(ae, 0, 256); 1872 1873 strncpy(ae->un.AttrString, lpfc_release_version, 1874 sizeof(ae->un.AttrString)); 1875 len = strnlen(ae->un.AttrString, 1876 sizeof(ae->un.AttrString)); 1877 len += (len & 3) ? (4 - (len & 3)) : 4; 1878 size = FOURBYTES + len; 1879 ad->AttrLen = cpu_to_be16(size); 1880 ad->AttrType = cpu_to_be16(RHBA_DRIVER_VERSION); 1881 return size; 1882 } 1883 1884 static int 1885 lpfc_fdmi_hba_attr_rom_ver(struct lpfc_vport *vport, 1886 struct lpfc_fdmi_attr_def *ad) 1887 { 1888 struct lpfc_hba *phba = vport->phba; 1889 struct lpfc_fdmi_attr_entry *ae; 1890 uint32_t len, size; 1891 1892 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue; 1893 memset(ae, 0, 256); 1894 1895 if (phba->sli_rev == LPFC_SLI_REV4) 1896 lpfc_decode_firmware_rev(phba, ae->un.AttrString, 1); 1897 else 1898 strncpy(ae->un.AttrString, phba->OptionROMVersion, 1899 sizeof(ae->un.AttrString)); 1900 len = strnlen(ae->un.AttrString, 1901 sizeof(ae->un.AttrString)); 1902 len += (len & 3) ? (4 - (len & 3)) : 4; 1903 size = FOURBYTES + len; 1904 ad->AttrLen = cpu_to_be16(size); 1905 ad->AttrType = cpu_to_be16(RHBA_OPTION_ROM_VERSION); 1906 return size; 1907 } 1908 1909 static int 1910 lpfc_fdmi_hba_attr_fmw_ver(struct lpfc_vport *vport, 1911 struct lpfc_fdmi_attr_def *ad) 1912 { 1913 struct lpfc_hba *phba = vport->phba; 1914 struct lpfc_fdmi_attr_entry *ae; 1915 uint32_t len, size; 1916 1917 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue; 1918 memset(ae, 0, 256); 1919 1920 lpfc_decode_firmware_rev(phba, ae->un.AttrString, 1); 1921 len = strnlen(ae->un.AttrString, 1922 sizeof(ae->un.AttrString)); 1923 len += (len & 3) ? (4 - (len & 3)) : 4; 1924 size = FOURBYTES + len; 1925 ad->AttrLen = cpu_to_be16(size); 1926 ad->AttrType = cpu_to_be16(RHBA_FIRMWARE_VERSION); 1927 return size; 1928 } 1929 1930 static int 1931 lpfc_fdmi_hba_attr_os_ver(struct lpfc_vport *vport, 1932 struct lpfc_fdmi_attr_def *ad) 1933 { 1934 struct lpfc_fdmi_attr_entry *ae; 1935 uint32_t len, size; 1936 1937 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue; 1938 memset(ae, 0, 256); 1939 1940 snprintf(ae->un.AttrString, sizeof(ae->un.AttrString), "%s %s %s", 1941 init_utsname()->sysname, 1942 init_utsname()->release, 1943 init_utsname()->version); 1944 1945 len = strnlen(ae->un.AttrString, sizeof(ae->un.AttrString)); 1946 len += (len & 3) ? (4 - (len & 3)) : 4; 1947 size = FOURBYTES + len; 1948 ad->AttrLen = cpu_to_be16(size); 1949 ad->AttrType = cpu_to_be16(RHBA_OS_NAME_VERSION); 1950 return size; 1951 } 1952 1953 static int 1954 lpfc_fdmi_hba_attr_ct_len(struct lpfc_vport *vport, 1955 struct lpfc_fdmi_attr_def *ad) 1956 { 1957 struct lpfc_fdmi_attr_entry *ae; 1958 uint32_t size; 1959 1960 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue; 1961 1962 ae->un.AttrInt = cpu_to_be32(LPFC_MAX_CT_SIZE); 1963 size = FOURBYTES + sizeof(uint32_t); 1964 ad->AttrLen = cpu_to_be16(size); 1965 ad->AttrType = cpu_to_be16(RHBA_MAX_CT_PAYLOAD_LEN); 1966 return size; 1967 } 1968 1969 static int 1970 lpfc_fdmi_hba_attr_symbolic_name(struct lpfc_vport *vport, 1971 struct lpfc_fdmi_attr_def *ad) 1972 { 1973 struct lpfc_fdmi_attr_entry *ae; 1974 uint32_t len, size; 1975 1976 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue; 1977 memset(ae, 0, 256); 1978 1979 len = lpfc_vport_symbolic_node_name(vport, 1980 ae->un.AttrString, 256); 1981 len += (len & 3) ? (4 - (len & 3)) : 4; 1982 size = FOURBYTES + len; 1983 ad->AttrLen = cpu_to_be16(size); 1984 ad->AttrType = cpu_to_be16(RHBA_SYM_NODENAME); 1985 return size; 1986 } 1987 1988 static int 1989 lpfc_fdmi_hba_attr_vendor_info(struct lpfc_vport *vport, 1990 struct lpfc_fdmi_attr_def *ad) 1991 { 1992 struct lpfc_fdmi_attr_entry *ae; 1993 uint32_t size; 1994 1995 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue; 1996 1997 /* Nothing is defined for this currently */ 1998 ae->un.AttrInt = cpu_to_be32(0); 1999 size = FOURBYTES + sizeof(uint32_t); 2000 ad->AttrLen = cpu_to_be16(size); 2001 ad->AttrType = cpu_to_be16(RHBA_VENDOR_INFO); 2002 return size; 2003 } 2004 2005 static int 2006 lpfc_fdmi_hba_attr_num_ports(struct lpfc_vport *vport, 2007 struct lpfc_fdmi_attr_def *ad) 2008 { 2009 struct lpfc_fdmi_attr_entry *ae; 2010 uint32_t size; 2011 2012 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue; 2013 2014 /* Each driver instance corresponds to a single port */ 2015 ae->un.AttrInt = cpu_to_be32(1); 2016 size = FOURBYTES + sizeof(uint32_t); 2017 ad->AttrLen = cpu_to_be16(size); 2018 ad->AttrType = cpu_to_be16(RHBA_NUM_PORTS); 2019 return size; 2020 } 2021 2022 static int 2023 lpfc_fdmi_hba_attr_fabric_wwnn(struct lpfc_vport *vport, 2024 struct lpfc_fdmi_attr_def *ad) 2025 { 2026 struct lpfc_fdmi_attr_entry *ae; 2027 uint32_t size; 2028 2029 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue; 2030 memset(ae, 0, sizeof(struct lpfc_name)); 2031 2032 memcpy(&ae->un.AttrWWN, &vport->fabric_nodename, 2033 sizeof(struct lpfc_name)); 2034 size = FOURBYTES + sizeof(struct lpfc_name); 2035 ad->AttrLen = cpu_to_be16(size); 2036 ad->AttrType = cpu_to_be16(RHBA_FABRIC_WWNN); 2037 return size; 2038 } 2039 2040 static int 2041 lpfc_fdmi_hba_attr_bios_ver(struct lpfc_vport *vport, 2042 struct lpfc_fdmi_attr_def *ad) 2043 { 2044 struct lpfc_hba *phba = vport->phba; 2045 struct lpfc_fdmi_attr_entry *ae; 2046 uint32_t len, size; 2047 2048 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue; 2049 memset(ae, 0, 256); 2050 2051 lpfc_decode_firmware_rev(phba, ae->un.AttrString, 1); 2052 len = strnlen(ae->un.AttrString, 2053 sizeof(ae->un.AttrString)); 2054 len += (len & 3) ? (4 - (len & 3)) : 4; 2055 size = FOURBYTES + len; 2056 ad->AttrLen = cpu_to_be16(size); 2057 ad->AttrType = cpu_to_be16(RHBA_BIOS_VERSION); 2058 return size; 2059 } 2060 2061 static int 2062 lpfc_fdmi_hba_attr_bios_state(struct lpfc_vport *vport, 2063 struct lpfc_fdmi_attr_def *ad) 2064 { 2065 struct lpfc_fdmi_attr_entry *ae; 2066 uint32_t size; 2067 2068 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue; 2069 2070 /* Driver doesn't have access to this information */ 2071 ae->un.AttrInt = cpu_to_be32(0); 2072 size = FOURBYTES + sizeof(uint32_t); 2073 ad->AttrLen = cpu_to_be16(size); 2074 ad->AttrType = cpu_to_be16(RHBA_BIOS_STATE); 2075 return size; 2076 } 2077 2078 static int 2079 lpfc_fdmi_hba_attr_vendor_id(struct lpfc_vport *vport, 2080 struct lpfc_fdmi_attr_def *ad) 2081 { 2082 struct lpfc_fdmi_attr_entry *ae; 2083 uint32_t len, size; 2084 2085 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue; 2086 memset(ae, 0, 256); 2087 2088 strncpy(ae->un.AttrString, "EMULEX", 2089 sizeof(ae->un.AttrString)); 2090 len = strnlen(ae->un.AttrString, 2091 sizeof(ae->un.AttrString)); 2092 len += (len & 3) ? (4 - (len & 3)) : 4; 2093 size = FOURBYTES + len; 2094 ad->AttrLen = cpu_to_be16(size); 2095 ad->AttrType = cpu_to_be16(RHBA_VENDOR_ID); 2096 return size; 2097 } 2098 2099 /* Routines for all individual PORT attributes */ 2100 static int 2101 lpfc_fdmi_port_attr_fc4type(struct lpfc_vport *vport, 2102 struct lpfc_fdmi_attr_def *ad) 2103 { 2104 struct lpfc_fdmi_attr_entry *ae; 2105 uint32_t size; 2106 2107 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue; 2108 memset(ae, 0, 32); 2109 2110 ae->un.AttrTypes[3] = 0x02; /* Type 1 - ELS */ 2111 ae->un.AttrTypes[2] = 0x01; /* Type 8 - FCP */ 2112 ae->un.AttrTypes[6] = 0x01; /* Type 40 - NVME */ 2113 ae->un.AttrTypes[7] = 0x01; /* Type 32 - CT */ 2114 size = FOURBYTES + 32; 2115 ad->AttrLen = cpu_to_be16(size); 2116 ad->AttrType = cpu_to_be16(RPRT_SUPPORTED_FC4_TYPES); 2117 return size; 2118 } 2119 2120 static int 2121 lpfc_fdmi_port_attr_support_speed(struct lpfc_vport *vport, 2122 struct lpfc_fdmi_attr_def *ad) 2123 { 2124 struct lpfc_hba *phba = vport->phba; 2125 struct lpfc_fdmi_attr_entry *ae; 2126 uint32_t size; 2127 2128 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue; 2129 2130 ae->un.AttrInt = 0; 2131 if (!(phba->hba_flag & HBA_FCOE_MODE)) { 2132 if (phba->lmt & LMT_64Gb) 2133 ae->un.AttrInt |= HBA_PORTSPEED_64GFC; 2134 if (phba->lmt & LMT_32Gb) 2135 ae->un.AttrInt |= HBA_PORTSPEED_32GFC; 2136 if (phba->lmt & LMT_16Gb) 2137 ae->un.AttrInt |= HBA_PORTSPEED_16GFC; 2138 if (phba->lmt & LMT_10Gb) 2139 ae->un.AttrInt |= HBA_PORTSPEED_10GFC; 2140 if (phba->lmt & LMT_8Gb) 2141 ae->un.AttrInt |= HBA_PORTSPEED_8GFC; 2142 if (phba->lmt & LMT_4Gb) 2143 ae->un.AttrInt |= HBA_PORTSPEED_4GFC; 2144 if (phba->lmt & LMT_2Gb) 2145 ae->un.AttrInt |= HBA_PORTSPEED_2GFC; 2146 if (phba->lmt & LMT_1Gb) 2147 ae->un.AttrInt |= HBA_PORTSPEED_1GFC; 2148 } else { 2149 /* FCoE links support only one speed */ 2150 switch (phba->fc_linkspeed) { 2151 case LPFC_ASYNC_LINK_SPEED_10GBPS: 2152 ae->un.AttrInt = HBA_PORTSPEED_10GE; 2153 break; 2154 case LPFC_ASYNC_LINK_SPEED_25GBPS: 2155 ae->un.AttrInt = HBA_PORTSPEED_25GE; 2156 break; 2157 case LPFC_ASYNC_LINK_SPEED_40GBPS: 2158 ae->un.AttrInt = HBA_PORTSPEED_40GE; 2159 break; 2160 case LPFC_ASYNC_LINK_SPEED_100GBPS: 2161 ae->un.AttrInt = HBA_PORTSPEED_100GE; 2162 break; 2163 } 2164 } 2165 ae->un.AttrInt = cpu_to_be32(ae->un.AttrInt); 2166 size = FOURBYTES + sizeof(uint32_t); 2167 ad->AttrLen = cpu_to_be16(size); 2168 ad->AttrType = cpu_to_be16(RPRT_SUPPORTED_SPEED); 2169 return size; 2170 } 2171 2172 static int 2173 lpfc_fdmi_port_attr_speed(struct lpfc_vport *vport, 2174 struct lpfc_fdmi_attr_def *ad) 2175 { 2176 struct lpfc_hba *phba = vport->phba; 2177 struct lpfc_fdmi_attr_entry *ae; 2178 uint32_t size; 2179 2180 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue; 2181 2182 if (!(phba->hba_flag & HBA_FCOE_MODE)) { 2183 switch (phba->fc_linkspeed) { 2184 case LPFC_LINK_SPEED_1GHZ: 2185 ae->un.AttrInt = HBA_PORTSPEED_1GFC; 2186 break; 2187 case LPFC_LINK_SPEED_2GHZ: 2188 ae->un.AttrInt = HBA_PORTSPEED_2GFC; 2189 break; 2190 case LPFC_LINK_SPEED_4GHZ: 2191 ae->un.AttrInt = HBA_PORTSPEED_4GFC; 2192 break; 2193 case LPFC_LINK_SPEED_8GHZ: 2194 ae->un.AttrInt = HBA_PORTSPEED_8GFC; 2195 break; 2196 case LPFC_LINK_SPEED_10GHZ: 2197 ae->un.AttrInt = HBA_PORTSPEED_10GFC; 2198 break; 2199 case LPFC_LINK_SPEED_16GHZ: 2200 ae->un.AttrInt = HBA_PORTSPEED_16GFC; 2201 break; 2202 case LPFC_LINK_SPEED_32GHZ: 2203 ae->un.AttrInt = HBA_PORTSPEED_32GFC; 2204 break; 2205 case LPFC_LINK_SPEED_64GHZ: 2206 ae->un.AttrInt = HBA_PORTSPEED_64GFC; 2207 break; 2208 default: 2209 ae->un.AttrInt = HBA_PORTSPEED_UNKNOWN; 2210 break; 2211 } 2212 } else { 2213 switch (phba->fc_linkspeed) { 2214 case LPFC_ASYNC_LINK_SPEED_10GBPS: 2215 ae->un.AttrInt = HBA_PORTSPEED_10GE; 2216 break; 2217 case LPFC_ASYNC_LINK_SPEED_25GBPS: 2218 ae->un.AttrInt = HBA_PORTSPEED_25GE; 2219 break; 2220 case LPFC_ASYNC_LINK_SPEED_40GBPS: 2221 ae->un.AttrInt = HBA_PORTSPEED_40GE; 2222 break; 2223 case LPFC_ASYNC_LINK_SPEED_100GBPS: 2224 ae->un.AttrInt = HBA_PORTSPEED_100GE; 2225 break; 2226 default: 2227 ae->un.AttrInt = HBA_PORTSPEED_UNKNOWN; 2228 break; 2229 } 2230 } 2231 2232 ae->un.AttrInt = cpu_to_be32(ae->un.AttrInt); 2233 size = FOURBYTES + sizeof(uint32_t); 2234 ad->AttrLen = cpu_to_be16(size); 2235 ad->AttrType = cpu_to_be16(RPRT_PORT_SPEED); 2236 return size; 2237 } 2238 2239 static int 2240 lpfc_fdmi_port_attr_max_frame(struct lpfc_vport *vport, 2241 struct lpfc_fdmi_attr_def *ad) 2242 { 2243 struct serv_parm *hsp; 2244 struct lpfc_fdmi_attr_entry *ae; 2245 uint32_t size; 2246 2247 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue; 2248 2249 hsp = (struct serv_parm *)&vport->fc_sparam; 2250 ae->un.AttrInt = (((uint32_t) hsp->cmn.bbRcvSizeMsb) << 8) | 2251 (uint32_t) hsp->cmn.bbRcvSizeLsb; 2252 ae->un.AttrInt = cpu_to_be32(ae->un.AttrInt); 2253 size = FOURBYTES + sizeof(uint32_t); 2254 ad->AttrLen = cpu_to_be16(size); 2255 ad->AttrType = cpu_to_be16(RPRT_MAX_FRAME_SIZE); 2256 return size; 2257 } 2258 2259 static int 2260 lpfc_fdmi_port_attr_os_devname(struct lpfc_vport *vport, 2261 struct lpfc_fdmi_attr_def *ad) 2262 { 2263 struct Scsi_Host *shost = lpfc_shost_from_vport(vport); 2264 struct lpfc_fdmi_attr_entry *ae; 2265 uint32_t len, size; 2266 2267 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue; 2268 memset(ae, 0, 256); 2269 2270 snprintf(ae->un.AttrString, sizeof(ae->un.AttrString), 2271 "/sys/class/scsi_host/host%d", shost->host_no); 2272 len = strnlen((char *)ae->un.AttrString, 2273 sizeof(ae->un.AttrString)); 2274 len += (len & 3) ? (4 - (len & 3)) : 4; 2275 size = FOURBYTES + len; 2276 ad->AttrLen = cpu_to_be16(size); 2277 ad->AttrType = cpu_to_be16(RPRT_OS_DEVICE_NAME); 2278 return size; 2279 } 2280 2281 static int 2282 lpfc_fdmi_port_attr_host_name(struct lpfc_vport *vport, 2283 struct lpfc_fdmi_attr_def *ad) 2284 { 2285 struct lpfc_fdmi_attr_entry *ae; 2286 uint32_t len, size; 2287 2288 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue; 2289 memset(ae, 0, 256); 2290 2291 snprintf(ae->un.AttrString, sizeof(ae->un.AttrString), "%s", 2292 init_utsname()->nodename); 2293 2294 len = strnlen(ae->un.AttrString, sizeof(ae->un.AttrString)); 2295 len += (len & 3) ? (4 - (len & 3)) : 4; 2296 size = FOURBYTES + len; 2297 ad->AttrLen = cpu_to_be16(size); 2298 ad->AttrType = cpu_to_be16(RPRT_HOST_NAME); 2299 return size; 2300 } 2301 2302 static int 2303 lpfc_fdmi_port_attr_wwnn(struct lpfc_vport *vport, 2304 struct lpfc_fdmi_attr_def *ad) 2305 { 2306 struct lpfc_fdmi_attr_entry *ae; 2307 uint32_t size; 2308 2309 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue; 2310 memset(ae, 0, sizeof(struct lpfc_name)); 2311 2312 memcpy(&ae->un.AttrWWN, &vport->fc_sparam.nodeName, 2313 sizeof(struct lpfc_name)); 2314 size = FOURBYTES + sizeof(struct lpfc_name); 2315 ad->AttrLen = cpu_to_be16(size); 2316 ad->AttrType = cpu_to_be16(RPRT_NODENAME); 2317 return size; 2318 } 2319 2320 static int 2321 lpfc_fdmi_port_attr_wwpn(struct lpfc_vport *vport, 2322 struct lpfc_fdmi_attr_def *ad) 2323 { 2324 struct lpfc_fdmi_attr_entry *ae; 2325 uint32_t size; 2326 2327 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue; 2328 memset(ae, 0, sizeof(struct lpfc_name)); 2329 2330 memcpy(&ae->un.AttrWWN, &vport->fc_sparam.portName, 2331 sizeof(struct lpfc_name)); 2332 size = FOURBYTES + sizeof(struct lpfc_name); 2333 ad->AttrLen = cpu_to_be16(size); 2334 ad->AttrType = cpu_to_be16(RPRT_PORTNAME); 2335 return size; 2336 } 2337 2338 static int 2339 lpfc_fdmi_port_attr_symbolic_name(struct lpfc_vport *vport, 2340 struct lpfc_fdmi_attr_def *ad) 2341 { 2342 struct lpfc_fdmi_attr_entry *ae; 2343 uint32_t len, size; 2344 2345 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue; 2346 memset(ae, 0, 256); 2347 2348 len = lpfc_vport_symbolic_port_name(vport, ae->un.AttrString, 256); 2349 len += (len & 3) ? (4 - (len & 3)) : 4; 2350 size = FOURBYTES + len; 2351 ad->AttrLen = cpu_to_be16(size); 2352 ad->AttrType = cpu_to_be16(RPRT_SYM_PORTNAME); 2353 return size; 2354 } 2355 2356 static int 2357 lpfc_fdmi_port_attr_port_type(struct lpfc_vport *vport, 2358 struct lpfc_fdmi_attr_def *ad) 2359 { 2360 struct lpfc_hba *phba = vport->phba; 2361 struct lpfc_fdmi_attr_entry *ae; 2362 uint32_t size; 2363 2364 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue; 2365 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) 2366 ae->un.AttrInt = cpu_to_be32(LPFC_FDMI_PORTTYPE_NLPORT); 2367 else 2368 ae->un.AttrInt = cpu_to_be32(LPFC_FDMI_PORTTYPE_NPORT); 2369 size = FOURBYTES + sizeof(uint32_t); 2370 ad->AttrLen = cpu_to_be16(size); 2371 ad->AttrType = cpu_to_be16(RPRT_PORT_TYPE); 2372 return size; 2373 } 2374 2375 static int 2376 lpfc_fdmi_port_attr_class(struct lpfc_vport *vport, 2377 struct lpfc_fdmi_attr_def *ad) 2378 { 2379 struct lpfc_fdmi_attr_entry *ae; 2380 uint32_t size; 2381 2382 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue; 2383 ae->un.AttrInt = cpu_to_be32(FC_COS_CLASS2 | FC_COS_CLASS3); 2384 size = FOURBYTES + sizeof(uint32_t); 2385 ad->AttrLen = cpu_to_be16(size); 2386 ad->AttrType = cpu_to_be16(RPRT_SUPPORTED_CLASS); 2387 return size; 2388 } 2389 2390 static int 2391 lpfc_fdmi_port_attr_fabric_wwpn(struct lpfc_vport *vport, 2392 struct lpfc_fdmi_attr_def *ad) 2393 { 2394 struct lpfc_fdmi_attr_entry *ae; 2395 uint32_t size; 2396 2397 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue; 2398 memset(ae, 0, sizeof(struct lpfc_name)); 2399 2400 memcpy(&ae->un.AttrWWN, &vport->fabric_portname, 2401 sizeof(struct lpfc_name)); 2402 size = FOURBYTES + sizeof(struct lpfc_name); 2403 ad->AttrLen = cpu_to_be16(size); 2404 ad->AttrType = cpu_to_be16(RPRT_FABRICNAME); 2405 return size; 2406 } 2407 2408 static int 2409 lpfc_fdmi_port_attr_active_fc4type(struct lpfc_vport *vport, 2410 struct lpfc_fdmi_attr_def *ad) 2411 { 2412 struct lpfc_fdmi_attr_entry *ae; 2413 uint32_t size; 2414 2415 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue; 2416 memset(ae, 0, 32); 2417 2418 ae->un.AttrTypes[3] = 0x02; /* Type 1 - ELS */ 2419 ae->un.AttrTypes[2] = 0x01; /* Type 8 - FCP */ 2420 ae->un.AttrTypes[7] = 0x01; /* Type 32 - CT */ 2421 size = FOURBYTES + 32; 2422 ad->AttrLen = cpu_to_be16(size); 2423 ad->AttrType = cpu_to_be16(RPRT_ACTIVE_FC4_TYPES); 2424 return size; 2425 } 2426 2427 static int 2428 lpfc_fdmi_port_attr_port_state(struct lpfc_vport *vport, 2429 struct lpfc_fdmi_attr_def *ad) 2430 { 2431 struct lpfc_fdmi_attr_entry *ae; 2432 uint32_t size; 2433 2434 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue; 2435 /* Link Up - operational */ 2436 ae->un.AttrInt = cpu_to_be32(LPFC_FDMI_PORTSTATE_ONLINE); 2437 size = FOURBYTES + sizeof(uint32_t); 2438 ad->AttrLen = cpu_to_be16(size); 2439 ad->AttrType = cpu_to_be16(RPRT_PORT_STATE); 2440 return size; 2441 } 2442 2443 static int 2444 lpfc_fdmi_port_attr_num_disc(struct lpfc_vport *vport, 2445 struct lpfc_fdmi_attr_def *ad) 2446 { 2447 struct lpfc_fdmi_attr_entry *ae; 2448 uint32_t size; 2449 2450 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue; 2451 vport->fdmi_num_disc = lpfc_find_map_node(vport); 2452 ae->un.AttrInt = cpu_to_be32(vport->fdmi_num_disc); 2453 size = FOURBYTES + sizeof(uint32_t); 2454 ad->AttrLen = cpu_to_be16(size); 2455 ad->AttrType = cpu_to_be16(RPRT_DISC_PORT); 2456 return size; 2457 } 2458 2459 static int 2460 lpfc_fdmi_port_attr_nportid(struct lpfc_vport *vport, 2461 struct lpfc_fdmi_attr_def *ad) 2462 { 2463 struct lpfc_fdmi_attr_entry *ae; 2464 uint32_t size; 2465 2466 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue; 2467 ae->un.AttrInt = cpu_to_be32(vport->fc_myDID); 2468 size = FOURBYTES + sizeof(uint32_t); 2469 ad->AttrLen = cpu_to_be16(size); 2470 ad->AttrType = cpu_to_be16(RPRT_PORT_ID); 2471 return size; 2472 } 2473 2474 static int 2475 lpfc_fdmi_smart_attr_service(struct lpfc_vport *vport, 2476 struct lpfc_fdmi_attr_def *ad) 2477 { 2478 struct lpfc_fdmi_attr_entry *ae; 2479 uint32_t len, size; 2480 2481 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue; 2482 memset(ae, 0, 256); 2483 2484 strncpy(ae->un.AttrString, "Smart SAN Initiator", 2485 sizeof(ae->un.AttrString)); 2486 len = strnlen(ae->un.AttrString, 2487 sizeof(ae->un.AttrString)); 2488 len += (len & 3) ? (4 - (len & 3)) : 4; 2489 size = FOURBYTES + len; 2490 ad->AttrLen = cpu_to_be16(size); 2491 ad->AttrType = cpu_to_be16(RPRT_SMART_SERVICE); 2492 return size; 2493 } 2494 2495 static int 2496 lpfc_fdmi_smart_attr_guid(struct lpfc_vport *vport, 2497 struct lpfc_fdmi_attr_def *ad) 2498 { 2499 struct lpfc_fdmi_attr_entry *ae; 2500 uint32_t size; 2501 2502 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue; 2503 memset(ae, 0, 256); 2504 2505 memcpy(&ae->un.AttrString, &vport->fc_sparam.nodeName, 2506 sizeof(struct lpfc_name)); 2507 memcpy((((uint8_t *)&ae->un.AttrString) + 2508 sizeof(struct lpfc_name)), 2509 &vport->fc_sparam.portName, sizeof(struct lpfc_name)); 2510 size = FOURBYTES + (2 * sizeof(struct lpfc_name)); 2511 ad->AttrLen = cpu_to_be16(size); 2512 ad->AttrType = cpu_to_be16(RPRT_SMART_GUID); 2513 return size; 2514 } 2515 2516 static int 2517 lpfc_fdmi_smart_attr_version(struct lpfc_vport *vport, 2518 struct lpfc_fdmi_attr_def *ad) 2519 { 2520 struct lpfc_fdmi_attr_entry *ae; 2521 uint32_t len, size; 2522 2523 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue; 2524 memset(ae, 0, 256); 2525 2526 strncpy(ae->un.AttrString, "Smart SAN Version 2.0", 2527 sizeof(ae->un.AttrString)); 2528 len = strnlen(ae->un.AttrString, 2529 sizeof(ae->un.AttrString)); 2530 len += (len & 3) ? (4 - (len & 3)) : 4; 2531 size = FOURBYTES + len; 2532 ad->AttrLen = cpu_to_be16(size); 2533 ad->AttrType = cpu_to_be16(RPRT_SMART_VERSION); 2534 return size; 2535 } 2536 2537 static int 2538 lpfc_fdmi_smart_attr_model(struct lpfc_vport *vport, 2539 struct lpfc_fdmi_attr_def *ad) 2540 { 2541 struct lpfc_hba *phba = vport->phba; 2542 struct lpfc_fdmi_attr_entry *ae; 2543 uint32_t len, size; 2544 2545 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue; 2546 memset(ae, 0, 256); 2547 2548 strncpy(ae->un.AttrString, phba->ModelName, 2549 sizeof(ae->un.AttrString)); 2550 len = strnlen(ae->un.AttrString, sizeof(ae->un.AttrString)); 2551 len += (len & 3) ? (4 - (len & 3)) : 4; 2552 size = FOURBYTES + len; 2553 ad->AttrLen = cpu_to_be16(size); 2554 ad->AttrType = cpu_to_be16(RPRT_SMART_MODEL); 2555 return size; 2556 } 2557 2558 static int 2559 lpfc_fdmi_smart_attr_port_info(struct lpfc_vport *vport, 2560 struct lpfc_fdmi_attr_def *ad) 2561 { 2562 struct lpfc_fdmi_attr_entry *ae; 2563 uint32_t size; 2564 2565 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue; 2566 2567 /* SRIOV (type 3) is not supported */ 2568 if (vport->vpi) 2569 ae->un.AttrInt = cpu_to_be32(2); /* NPIV */ 2570 else 2571 ae->un.AttrInt = cpu_to_be32(1); /* Physical */ 2572 size = FOURBYTES + sizeof(uint32_t); 2573 ad->AttrLen = cpu_to_be16(size); 2574 ad->AttrType = cpu_to_be16(RPRT_SMART_PORT_INFO); 2575 return size; 2576 } 2577 2578 static int 2579 lpfc_fdmi_smart_attr_qos(struct lpfc_vport *vport, 2580 struct lpfc_fdmi_attr_def *ad) 2581 { 2582 struct lpfc_fdmi_attr_entry *ae; 2583 uint32_t size; 2584 2585 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue; 2586 ae->un.AttrInt = cpu_to_be32(0); 2587 size = FOURBYTES + sizeof(uint32_t); 2588 ad->AttrLen = cpu_to_be16(size); 2589 ad->AttrType = cpu_to_be16(RPRT_SMART_QOS); 2590 return size; 2591 } 2592 2593 static int 2594 lpfc_fdmi_smart_attr_security(struct lpfc_vport *vport, 2595 struct lpfc_fdmi_attr_def *ad) 2596 { 2597 struct lpfc_fdmi_attr_entry *ae; 2598 uint32_t size; 2599 2600 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue; 2601 ae->un.AttrInt = cpu_to_be32(1); 2602 size = FOURBYTES + sizeof(uint32_t); 2603 ad->AttrLen = cpu_to_be16(size); 2604 ad->AttrType = cpu_to_be16(RPRT_SMART_SECURITY); 2605 return size; 2606 } 2607 2608 /* RHBA attribute jump table */ 2609 int (*lpfc_fdmi_hba_action[]) 2610 (struct lpfc_vport *vport, struct lpfc_fdmi_attr_def *ad) = { 2611 /* Action routine Mask bit Attribute type */ 2612 lpfc_fdmi_hba_attr_wwnn, /* bit0 RHBA_NODENAME */ 2613 lpfc_fdmi_hba_attr_manufacturer, /* bit1 RHBA_MANUFACTURER */ 2614 lpfc_fdmi_hba_attr_sn, /* bit2 RHBA_SERIAL_NUMBER */ 2615 lpfc_fdmi_hba_attr_model, /* bit3 RHBA_MODEL */ 2616 lpfc_fdmi_hba_attr_description, /* bit4 RHBA_MODEL_DESCRIPTION */ 2617 lpfc_fdmi_hba_attr_hdw_ver, /* bit5 RHBA_HARDWARE_VERSION */ 2618 lpfc_fdmi_hba_attr_drvr_ver, /* bit6 RHBA_DRIVER_VERSION */ 2619 lpfc_fdmi_hba_attr_rom_ver, /* bit7 RHBA_OPTION_ROM_VERSION */ 2620 lpfc_fdmi_hba_attr_fmw_ver, /* bit8 RHBA_FIRMWARE_VERSION */ 2621 lpfc_fdmi_hba_attr_os_ver, /* bit9 RHBA_OS_NAME_VERSION */ 2622 lpfc_fdmi_hba_attr_ct_len, /* bit10 RHBA_MAX_CT_PAYLOAD_LEN */ 2623 lpfc_fdmi_hba_attr_symbolic_name, /* bit11 RHBA_SYM_NODENAME */ 2624 lpfc_fdmi_hba_attr_vendor_info, /* bit12 RHBA_VENDOR_INFO */ 2625 lpfc_fdmi_hba_attr_num_ports, /* bit13 RHBA_NUM_PORTS */ 2626 lpfc_fdmi_hba_attr_fabric_wwnn, /* bit14 RHBA_FABRIC_WWNN */ 2627 lpfc_fdmi_hba_attr_bios_ver, /* bit15 RHBA_BIOS_VERSION */ 2628 lpfc_fdmi_hba_attr_bios_state, /* bit16 RHBA_BIOS_STATE */ 2629 lpfc_fdmi_hba_attr_vendor_id, /* bit17 RHBA_VENDOR_ID */ 2630 }; 2631 2632 /* RPA / RPRT attribute jump table */ 2633 int (*lpfc_fdmi_port_action[]) 2634 (struct lpfc_vport *vport, struct lpfc_fdmi_attr_def *ad) = { 2635 /* Action routine Mask bit Attribute type */ 2636 lpfc_fdmi_port_attr_fc4type, /* bit0 RPRT_SUPPORT_FC4_TYPES */ 2637 lpfc_fdmi_port_attr_support_speed, /* bit1 RPRT_SUPPORTED_SPEED */ 2638 lpfc_fdmi_port_attr_speed, /* bit2 RPRT_PORT_SPEED */ 2639 lpfc_fdmi_port_attr_max_frame, /* bit3 RPRT_MAX_FRAME_SIZE */ 2640 lpfc_fdmi_port_attr_os_devname, /* bit4 RPRT_OS_DEVICE_NAME */ 2641 lpfc_fdmi_port_attr_host_name, /* bit5 RPRT_HOST_NAME */ 2642 lpfc_fdmi_port_attr_wwnn, /* bit6 RPRT_NODENAME */ 2643 lpfc_fdmi_port_attr_wwpn, /* bit7 RPRT_PORTNAME */ 2644 lpfc_fdmi_port_attr_symbolic_name, /* bit8 RPRT_SYM_PORTNAME */ 2645 lpfc_fdmi_port_attr_port_type, /* bit9 RPRT_PORT_TYPE */ 2646 lpfc_fdmi_port_attr_class, /* bit10 RPRT_SUPPORTED_CLASS */ 2647 lpfc_fdmi_port_attr_fabric_wwpn, /* bit11 RPRT_FABRICNAME */ 2648 lpfc_fdmi_port_attr_active_fc4type, /* bit12 RPRT_ACTIVE_FC4_TYPES */ 2649 lpfc_fdmi_port_attr_port_state, /* bit13 RPRT_PORT_STATE */ 2650 lpfc_fdmi_port_attr_num_disc, /* bit14 RPRT_DISC_PORT */ 2651 lpfc_fdmi_port_attr_nportid, /* bit15 RPRT_PORT_ID */ 2652 lpfc_fdmi_smart_attr_service, /* bit16 RPRT_SMART_SERVICE */ 2653 lpfc_fdmi_smart_attr_guid, /* bit17 RPRT_SMART_GUID */ 2654 lpfc_fdmi_smart_attr_version, /* bit18 RPRT_SMART_VERSION */ 2655 lpfc_fdmi_smart_attr_model, /* bit19 RPRT_SMART_MODEL */ 2656 lpfc_fdmi_smart_attr_port_info, /* bit20 RPRT_SMART_PORT_INFO */ 2657 lpfc_fdmi_smart_attr_qos, /* bit21 RPRT_SMART_QOS */ 2658 lpfc_fdmi_smart_attr_security, /* bit22 RPRT_SMART_SECURITY */ 2659 }; 2660 2661 /** 2662 * lpfc_fdmi_cmd - Build and send a FDMI cmd to the specified NPort 2663 * @vport: pointer to a host virtual N_Port data structure. 2664 * @ndlp: ndlp to send FDMI cmd to (if NULL use FDMI_DID) 2665 * cmdcode: FDMI command to send 2666 * mask: Mask of HBA or PORT Attributes to send 2667 * 2668 * Builds and sends a FDMI command using the CT subsystem. 2669 */ 2670 int 2671 lpfc_fdmi_cmd(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, 2672 int cmdcode, uint32_t new_mask) 2673 { 2674 struct lpfc_hba *phba = vport->phba; 2675 struct lpfc_dmabuf *mp, *bmp; 2676 struct lpfc_sli_ct_request *CtReq; 2677 struct ulp_bde64 *bpl; 2678 uint32_t bit_pos; 2679 uint32_t size; 2680 uint32_t rsp_size; 2681 uint32_t mask; 2682 struct lpfc_fdmi_reg_hba *rh; 2683 struct lpfc_fdmi_port_entry *pe; 2684 struct lpfc_fdmi_reg_portattr *pab = NULL; 2685 struct lpfc_fdmi_attr_block *ab = NULL; 2686 int (*func)(struct lpfc_vport *vport, struct lpfc_fdmi_attr_def *ad); 2687 void (*cmpl)(struct lpfc_hba *, struct lpfc_iocbq *, 2688 struct lpfc_iocbq *); 2689 2690 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) 2691 return 0; 2692 2693 cmpl = lpfc_cmpl_ct_disc_fdmi; /* called from discovery */ 2694 2695 /* fill in BDEs for command */ 2696 /* Allocate buffer for command payload */ 2697 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); 2698 if (!mp) 2699 goto fdmi_cmd_exit; 2700 2701 mp->virt = lpfc_mbuf_alloc(phba, 0, &(mp->phys)); 2702 if (!mp->virt) 2703 goto fdmi_cmd_free_mp; 2704 2705 /* Allocate buffer for Buffer ptr list */ 2706 bmp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); 2707 if (!bmp) 2708 goto fdmi_cmd_free_mpvirt; 2709 2710 bmp->virt = lpfc_mbuf_alloc(phba, 0, &(bmp->phys)); 2711 if (!bmp->virt) 2712 goto fdmi_cmd_free_bmp; 2713 2714 INIT_LIST_HEAD(&mp->list); 2715 INIT_LIST_HEAD(&bmp->list); 2716 2717 /* FDMI request */ 2718 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, 2719 "0218 FDMI Request Data: x%x x%x x%x\n", 2720 vport->fc_flag, vport->port_state, cmdcode); 2721 CtReq = (struct lpfc_sli_ct_request *)mp->virt; 2722 2723 /* First populate the CT_IU preamble */ 2724 memset(CtReq, 0, sizeof(struct lpfc_sli_ct_request)); 2725 CtReq->RevisionId.bits.Revision = SLI_CT_REVISION; 2726 CtReq->RevisionId.bits.InId = 0; 2727 2728 CtReq->FsType = SLI_CT_MANAGEMENT_SERVICE; 2729 CtReq->FsSubType = SLI_CT_FDMI_Subtypes; 2730 2731 CtReq->CommandResponse.bits.CmdRsp = cpu_to_be16(cmdcode); 2732 rsp_size = LPFC_BPL_SIZE; 2733 size = 0; 2734 2735 /* Next fill in the specific FDMI cmd information */ 2736 switch (cmdcode) { 2737 case SLI_MGMT_RHAT: 2738 case SLI_MGMT_RHBA: 2739 rh = (struct lpfc_fdmi_reg_hba *)&CtReq->un.PortID; 2740 /* HBA Identifier */ 2741 memcpy(&rh->hi.PortName, &phba->pport->fc_sparam.portName, 2742 sizeof(struct lpfc_name)); 2743 2744 if (cmdcode == SLI_MGMT_RHBA) { 2745 /* Registered Port List */ 2746 /* One entry (port) per adapter */ 2747 rh->rpl.EntryCnt = cpu_to_be32(1); 2748 memcpy(&rh->rpl.pe, &phba->pport->fc_sparam.portName, 2749 sizeof(struct lpfc_name)); 2750 2751 /* point to the HBA attribute block */ 2752 size = 2 * sizeof(struct lpfc_name) + 2753 FOURBYTES; 2754 } else { 2755 size = sizeof(struct lpfc_name); 2756 } 2757 ab = (struct lpfc_fdmi_attr_block *)((uint8_t *)rh + size); 2758 ab->EntryCnt = 0; 2759 size += FOURBYTES; 2760 bit_pos = 0; 2761 if (new_mask) 2762 mask = new_mask; 2763 else 2764 mask = vport->fdmi_hba_mask; 2765 2766 /* Mask will dictate what attributes to build in the request */ 2767 while (mask) { 2768 if (mask & 0x1) { 2769 func = lpfc_fdmi_hba_action[bit_pos]; 2770 size += func(vport, 2771 (struct lpfc_fdmi_attr_def *) 2772 ((uint8_t *)rh + size)); 2773 ab->EntryCnt++; 2774 if ((size + 256) > 2775 (LPFC_BPL_SIZE - LPFC_CT_PREAMBLE)) 2776 goto hba_out; 2777 } 2778 mask = mask >> 1; 2779 bit_pos++; 2780 } 2781 hba_out: 2782 ab->EntryCnt = cpu_to_be32(ab->EntryCnt); 2783 /* Total size */ 2784 size = GID_REQUEST_SZ - 4 + size; 2785 break; 2786 2787 case SLI_MGMT_RPRT: 2788 case SLI_MGMT_RPA: 2789 pab = (struct lpfc_fdmi_reg_portattr *)&CtReq->un.PortID; 2790 if (cmdcode == SLI_MGMT_RPRT) { 2791 rh = (struct lpfc_fdmi_reg_hba *)pab; 2792 /* HBA Identifier */ 2793 memcpy(&rh->hi.PortName, 2794 &phba->pport->fc_sparam.portName, 2795 sizeof(struct lpfc_name)); 2796 pab = (struct lpfc_fdmi_reg_portattr *) 2797 ((uint8_t *)pab + sizeof(struct lpfc_name)); 2798 } 2799 2800 memcpy((uint8_t *)&pab->PortName, 2801 (uint8_t *)&vport->fc_sparam.portName, 2802 sizeof(struct lpfc_name)); 2803 size += sizeof(struct lpfc_name) + FOURBYTES; 2804 pab->ab.EntryCnt = 0; 2805 bit_pos = 0; 2806 if (new_mask) 2807 mask = new_mask; 2808 else 2809 mask = vport->fdmi_port_mask; 2810 2811 /* Mask will dictate what attributes to build in the request */ 2812 while (mask) { 2813 if (mask & 0x1) { 2814 func = lpfc_fdmi_port_action[bit_pos]; 2815 size += func(vport, 2816 (struct lpfc_fdmi_attr_def *) 2817 ((uint8_t *)pab + size)); 2818 pab->ab.EntryCnt++; 2819 if ((size + 256) > 2820 (LPFC_BPL_SIZE - LPFC_CT_PREAMBLE)) 2821 goto port_out; 2822 } 2823 mask = mask >> 1; 2824 bit_pos++; 2825 } 2826 port_out: 2827 pab->ab.EntryCnt = cpu_to_be32(pab->ab.EntryCnt); 2828 /* Total size */ 2829 if (cmdcode == SLI_MGMT_RPRT) 2830 size += sizeof(struct lpfc_name); 2831 size = GID_REQUEST_SZ - 4 + size; 2832 break; 2833 2834 case SLI_MGMT_GHAT: 2835 case SLI_MGMT_GRPL: 2836 rsp_size = FC_MAX_NS_RSP; 2837 case SLI_MGMT_DHBA: 2838 case SLI_MGMT_DHAT: 2839 pe = (struct lpfc_fdmi_port_entry *)&CtReq->un.PortID; 2840 memcpy((uint8_t *)&pe->PortName, 2841 (uint8_t *)&vport->fc_sparam.portName, 2842 sizeof(struct lpfc_name)); 2843 size = GID_REQUEST_SZ - 4 + sizeof(struct lpfc_name); 2844 break; 2845 2846 case SLI_MGMT_GPAT: 2847 case SLI_MGMT_GPAS: 2848 rsp_size = FC_MAX_NS_RSP; 2849 case SLI_MGMT_DPRT: 2850 case SLI_MGMT_DPA: 2851 pe = (struct lpfc_fdmi_port_entry *)&CtReq->un.PortID; 2852 memcpy((uint8_t *)&pe->PortName, 2853 (uint8_t *)&vport->fc_sparam.portName, 2854 sizeof(struct lpfc_name)); 2855 size = GID_REQUEST_SZ - 4 + sizeof(struct lpfc_name); 2856 break; 2857 case SLI_MGMT_GRHL: 2858 size = GID_REQUEST_SZ - 4; 2859 break; 2860 default: 2861 lpfc_printf_vlog(vport, KERN_WARNING, LOG_DISCOVERY, 2862 "0298 FDMI cmdcode x%x not supported\n", 2863 cmdcode); 2864 goto fdmi_cmd_free_bmpvirt; 2865 } 2866 CtReq->CommandResponse.bits.Size = cpu_to_be16(rsp_size); 2867 2868 bpl = (struct ulp_bde64 *)bmp->virt; 2869 bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys)); 2870 bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys)); 2871 bpl->tus.f.bdeFlags = 0; 2872 bpl->tus.f.bdeSize = size; 2873 2874 /* 2875 * The lpfc_ct_cmd/lpfc_get_req shall increment ndlp reference count 2876 * to hold ndlp reference for the corresponding callback function. 2877 */ 2878 if (!lpfc_ct_cmd(vport, mp, bmp, ndlp, cmpl, rsp_size, 0)) 2879 return 0; 2880 2881 /* 2882 * Decrement ndlp reference count to release ndlp reference held 2883 * for the failed command's callback function. 2884 */ 2885 lpfc_nlp_put(ndlp); 2886 2887 fdmi_cmd_free_bmpvirt: 2888 lpfc_mbuf_free(phba, bmp->virt, bmp->phys); 2889 fdmi_cmd_free_bmp: 2890 kfree(bmp); 2891 fdmi_cmd_free_mpvirt: 2892 lpfc_mbuf_free(phba, mp->virt, mp->phys); 2893 fdmi_cmd_free_mp: 2894 kfree(mp); 2895 fdmi_cmd_exit: 2896 /* Issue FDMI request failed */ 2897 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, 2898 "0244 Issue FDMI request failed Data: x%x\n", 2899 cmdcode); 2900 return 1; 2901 } 2902 2903 /** 2904 * lpfc_delayed_disc_tmo - Timeout handler for delayed discovery timer. 2905 * @ptr - Context object of the timer. 2906 * 2907 * This function set the WORKER_DELAYED_DISC_TMO flag and wake up 2908 * the worker thread. 2909 **/ 2910 void 2911 lpfc_delayed_disc_tmo(struct timer_list *t) 2912 { 2913 struct lpfc_vport *vport = from_timer(vport, t, delayed_disc_tmo); 2914 struct lpfc_hba *phba = vport->phba; 2915 uint32_t tmo_posted; 2916 unsigned long iflag; 2917 2918 spin_lock_irqsave(&vport->work_port_lock, iflag); 2919 tmo_posted = vport->work_port_events & WORKER_DELAYED_DISC_TMO; 2920 if (!tmo_posted) 2921 vport->work_port_events |= WORKER_DELAYED_DISC_TMO; 2922 spin_unlock_irqrestore(&vport->work_port_lock, iflag); 2923 2924 if (!tmo_posted) 2925 lpfc_worker_wake_up(phba); 2926 return; 2927 } 2928 2929 /** 2930 * lpfc_delayed_disc_timeout_handler - Function called by worker thread to 2931 * handle delayed discovery. 2932 * @vport: pointer to a host virtual N_Port data structure. 2933 * 2934 * This function start nport discovery of the vport. 2935 **/ 2936 void 2937 lpfc_delayed_disc_timeout_handler(struct lpfc_vport *vport) 2938 { 2939 struct Scsi_Host *shost = lpfc_shost_from_vport(vport); 2940 2941 spin_lock_irq(shost->host_lock); 2942 if (!(vport->fc_flag & FC_DISC_DELAYED)) { 2943 spin_unlock_irq(shost->host_lock); 2944 return; 2945 } 2946 vport->fc_flag &= ~FC_DISC_DELAYED; 2947 spin_unlock_irq(shost->host_lock); 2948 2949 lpfc_do_scr_ns_plogi(vport->phba, vport); 2950 } 2951 2952 void 2953 lpfc_decode_firmware_rev(struct lpfc_hba *phba, char *fwrevision, int flag) 2954 { 2955 struct lpfc_sli *psli = &phba->sli; 2956 lpfc_vpd_t *vp = &phba->vpd; 2957 uint32_t b1, b2, b3, b4, i, rev; 2958 char c; 2959 uint32_t *ptr, str[4]; 2960 uint8_t *fwname; 2961 2962 if (phba->sli_rev == LPFC_SLI_REV4) 2963 snprintf(fwrevision, FW_REV_STR_SIZE, "%s", vp->rev.opFwName); 2964 else if (vp->rev.rBit) { 2965 if (psli->sli_flag & LPFC_SLI_ACTIVE) 2966 rev = vp->rev.sli2FwRev; 2967 else 2968 rev = vp->rev.sli1FwRev; 2969 2970 b1 = (rev & 0x0000f000) >> 12; 2971 b2 = (rev & 0x00000f00) >> 8; 2972 b3 = (rev & 0x000000c0) >> 6; 2973 b4 = (rev & 0x00000030) >> 4; 2974 2975 switch (b4) { 2976 case 0: 2977 c = 'N'; 2978 break; 2979 case 1: 2980 c = 'A'; 2981 break; 2982 case 2: 2983 c = 'B'; 2984 break; 2985 case 3: 2986 c = 'X'; 2987 break; 2988 default: 2989 c = 0; 2990 break; 2991 } 2992 b4 = (rev & 0x0000000f); 2993 2994 if (psli->sli_flag & LPFC_SLI_ACTIVE) 2995 fwname = vp->rev.sli2FwName; 2996 else 2997 fwname = vp->rev.sli1FwName; 2998 2999 for (i = 0; i < 16; i++) 3000 if (fwname[i] == 0x20) 3001 fwname[i] = 0; 3002 3003 ptr = (uint32_t*)fwname; 3004 3005 for (i = 0; i < 3; i++) 3006 str[i] = be32_to_cpu(*ptr++); 3007 3008 if (c == 0) { 3009 if (flag) 3010 sprintf(fwrevision, "%d.%d%d (%s)", 3011 b1, b2, b3, (char *)str); 3012 else 3013 sprintf(fwrevision, "%d.%d%d", b1, 3014 b2, b3); 3015 } else { 3016 if (flag) 3017 sprintf(fwrevision, "%d.%d%d%c%d (%s)", 3018 b1, b2, b3, c, 3019 b4, (char *)str); 3020 else 3021 sprintf(fwrevision, "%d.%d%d%c%d", 3022 b1, b2, b3, c, b4); 3023 } 3024 } else { 3025 rev = vp->rev.smFwRev; 3026 3027 b1 = (rev & 0xff000000) >> 24; 3028 b2 = (rev & 0x00f00000) >> 20; 3029 b3 = (rev & 0x000f0000) >> 16; 3030 c = (rev & 0x0000ff00) >> 8; 3031 b4 = (rev & 0x000000ff); 3032 3033 sprintf(fwrevision, "%d.%d%d%c%d", b1, b2, b3, c, b4); 3034 } 3035 return; 3036 } 3037