1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2017-2020 Broadcom. All Rights Reserved. The term *
5 * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. *
6 * Copyright (C) 2004-2016 Emulex. All rights reserved. *
7 * EMULEX and SLI are trademarks of Emulex. *
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 *******************************************************************/
24 * Fibre Channel SCSI LAN Device Driver CT support: FC Generic Services FC-GS
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>
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>
42 #include "lpfc_sli4.h"
44 #include "lpfc_disc.h"
46 #include "lpfc_scsi.h"
47 #include "lpfc_logmsg.h"
48 #include "lpfc_crtn.h"
49 #include "lpfc_version.h"
50 #include "lpfc_vport.h"
51 #include "lpfc_debugfs.h"
53 /* FDMI Port Speed definitions - FC-GS-7 */
54 #define HBA_PORTSPEED_1GFC 0x00000001 /* 1G FC */
55 #define HBA_PORTSPEED_2GFC 0x00000002 /* 2G FC */
56 #define HBA_PORTSPEED_4GFC 0x00000008 /* 4G FC */
57 #define HBA_PORTSPEED_10GFC 0x00000004 /* 10G FC */
58 #define HBA_PORTSPEED_8GFC 0x00000010 /* 8G FC */
59 #define HBA_PORTSPEED_16GFC 0x00000020 /* 16G FC */
60 #define HBA_PORTSPEED_32GFC 0x00000040 /* 32G FC */
61 #define HBA_PORTSPEED_20GFC 0x00000080 /* 20G FC */
62 #define HBA_PORTSPEED_40GFC 0x00000100 /* 40G FC */
63 #define HBA_PORTSPEED_128GFC 0x00000200 /* 128G FC */
64 #define HBA_PORTSPEED_64GFC 0x00000400 /* 64G FC */
65 #define HBA_PORTSPEED_256GFC 0x00000800 /* 256G FC */
66 #define HBA_PORTSPEED_UNKNOWN 0x00008000 /* Unknown */
67 #define HBA_PORTSPEED_10GE 0x00010000 /* 10G E */
68 #define HBA_PORTSPEED_40GE 0x00020000 /* 40G E */
69 #define HBA_PORTSPEED_100GE 0x00040000 /* 100G E */
70 #define HBA_PORTSPEED_25GE 0x00080000 /* 25G E */
71 #define HBA_PORTSPEED_50GE 0x00100000 /* 50G E */
72 #define HBA_PORTSPEED_400GE 0x00200000 /* 400G E */
77 static char *lpfc_release_version = LPFC_DRIVER_VERSION;
80 lpfc_ct_ignore_hbq_buffer(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq,
81 struct lpfc_dmabuf *mp, uint32_t size)
84 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
85 "0146 Ignoring unsolicited CT No HBQ "
87 piocbq->iocb.ulpStatus);
89 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
90 "0145 Ignoring unsolicted CT HBQ Size:%d "
92 size, piocbq->iocb.ulpStatus);
96 lpfc_ct_unsol_buffer(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq,
97 struct lpfc_dmabuf *mp, uint32_t size)
99 lpfc_ct_ignore_hbq_buffer(phba, piocbq, mp, size);
103 lpfc_ct_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
104 struct lpfc_iocbq *piocbq)
106 struct lpfc_dmabuf *mp = NULL;
107 IOCB_t *icmd = &piocbq->iocb;
109 struct lpfc_iocbq *iocbq;
112 struct list_head head;
113 struct lpfc_dmabuf *bdeBuf;
115 if (lpfc_bsg_ct_unsol_event(phba, pring, piocbq) == 0)
118 if (unlikely(icmd->ulpStatus == IOSTAT_NEED_BUFFER)) {
119 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
120 } else if ((icmd->ulpStatus == IOSTAT_LOCAL_REJECT) &&
121 ((icmd->un.ulpWord[4] & IOERR_PARAM_MASK) ==
122 IOERR_RCV_BUFFER_WAITING)) {
123 /* Not enough posted buffers; Try posting more buffers */
124 phba->fc_stat.NoRcvBuf++;
125 if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
126 lpfc_post_buffer(phba, pring, 2);
130 /* If there are no BDEs associated with this IOCB,
131 * there is nothing to do.
133 if (icmd->ulpBdeCount == 0)
136 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
137 INIT_LIST_HEAD(&head);
138 list_add_tail(&head, &piocbq->list);
139 list_for_each_entry(iocbq, &head, list) {
141 if (icmd->ulpBdeCount == 0)
143 bdeBuf = iocbq->context2;
144 iocbq->context2 = NULL;
145 size = icmd->un.cont64[0].tus.f.bdeSize;
146 lpfc_ct_unsol_buffer(phba, piocbq, bdeBuf, size);
147 lpfc_in_buf_free(phba, bdeBuf);
148 if (icmd->ulpBdeCount == 2) {
149 bdeBuf = iocbq->context3;
150 iocbq->context3 = NULL;
151 size = icmd->unsli3.rcvsli3.bde2.tus.f.bdeSize;
152 lpfc_ct_unsol_buffer(phba, piocbq, bdeBuf,
154 lpfc_in_buf_free(phba, bdeBuf);
159 INIT_LIST_HEAD(&head);
160 list_add_tail(&head, &piocbq->list);
161 list_for_each_entry(iocbq, &head, list) {
163 if (icmd->ulpBdeCount == 0)
164 lpfc_ct_unsol_buffer(phba, iocbq, NULL, 0);
165 for (i = 0; i < icmd->ulpBdeCount; i++) {
166 paddr = getPaddr(icmd->un.cont64[i].addrHigh,
167 icmd->un.cont64[i].addrLow);
168 mp = lpfc_sli_ringpostbuf_get(phba, pring,
170 size = icmd->un.cont64[i].tus.f.bdeSize;
171 lpfc_ct_unsol_buffer(phba, iocbq, mp, size);
172 lpfc_in_buf_free(phba, mp);
174 lpfc_post_buffer(phba, pring, i);
181 * lpfc_ct_handle_unsol_abort - ct upper level protocol abort handler
182 * @phba: Pointer to HBA context object.
183 * @dmabuf: pointer to a dmabuf that describes the FC sequence
185 * This function serves as the upper level protocol abort handler for CT
188 * Return 1 if abort has been handled, 0 otherwise.
191 lpfc_ct_handle_unsol_abort(struct lpfc_hba *phba, struct hbq_dmabuf *dmabuf)
195 /* CT upper level goes through BSG */
196 handled = lpfc_bsg_ct_unsol_abort(phba, dmabuf);
202 lpfc_free_ct_rsp(struct lpfc_hba *phba, struct lpfc_dmabuf *mlist)
204 struct lpfc_dmabuf *mlast, *next_mlast;
206 list_for_each_entry_safe(mlast, next_mlast, &mlist->list, list) {
207 lpfc_mbuf_free(phba, mlast->virt, mlast->phys);
208 list_del(&mlast->list);
211 lpfc_mbuf_free(phba, mlist->virt, mlist->phys);
216 static struct lpfc_dmabuf *
217 lpfc_alloc_ct_rsp(struct lpfc_hba *phba, int cmdcode, struct ulp_bde64 *bpl,
218 uint32_t size, int *entries)
220 struct lpfc_dmabuf *mlist = NULL;
221 struct lpfc_dmabuf *mp;
224 /* We get chunks of FCELSSIZE */
225 cnt = size > FCELSSIZE ? FCELSSIZE: size;
228 /* Allocate buffer for rsp payload */
229 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
232 lpfc_free_ct_rsp(phba, mlist);
236 INIT_LIST_HEAD(&mp->list);
238 if (cmdcode == be16_to_cpu(SLI_CTNS_GID_FT) ||
239 cmdcode == be16_to_cpu(SLI_CTNS_GFF_ID))
240 mp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(mp->phys));
242 mp->virt = lpfc_mbuf_alloc(phba, 0, &(mp->phys));
247 lpfc_free_ct_rsp(phba, mlist);
251 /* Queue it to a linked list */
255 list_add_tail(&mp->list, &mlist->list);
257 bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64I;
258 /* build buffer ptr list for IOCB */
259 bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys) );
260 bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys) );
261 bpl->tus.f.bdeSize = (uint16_t) cnt;
262 bpl->tus.w = le32_to_cpu(bpl->tus.w);
274 lpfc_ct_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *ctiocb)
276 struct lpfc_dmabuf *buf_ptr;
278 if (ctiocb->context_un.ndlp) {
279 lpfc_nlp_put(ctiocb->context_un.ndlp);
280 ctiocb->context_un.ndlp = NULL;
282 if (ctiocb->context1) {
283 buf_ptr = (struct lpfc_dmabuf *) ctiocb->context1;
284 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
286 ctiocb->context1 = NULL;
288 if (ctiocb->context2) {
289 lpfc_free_ct_rsp(phba, (struct lpfc_dmabuf *) ctiocb->context2);
290 ctiocb->context2 = NULL;
293 if (ctiocb->context3) {
294 buf_ptr = (struct lpfc_dmabuf *) ctiocb->context3;
295 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
297 ctiocb->context3 = NULL;
299 lpfc_sli_release_iocbq(phba, ctiocb);
304 * lpfc_gen_req - Build and issue a GEN_REQUEST command to the SLI Layer
305 * @vport: pointer to a host virtual N_Port data structure.
306 * @bmp: Pointer to BPL for SLI command
307 * @inp: Pointer to data buffer for response data.
308 * @outp: Pointer to data buffer that hold the CT command.
309 * @cmpl: completion routine to call when command completes
310 * @ndlp: Destination NPort nodelist entry
312 * This function as the final part for issuing a CT command.
315 lpfc_gen_req(struct lpfc_vport *vport, struct lpfc_dmabuf *bmp,
316 struct lpfc_dmabuf *inp, struct lpfc_dmabuf *outp,
317 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
318 struct lpfc_iocbq *),
319 struct lpfc_nodelist *ndlp, uint32_t usr_flg, uint32_t num_entry,
320 uint32_t tmo, uint8_t retry)
322 struct lpfc_hba *phba = vport->phba;
324 struct lpfc_iocbq *geniocb;
327 /* Allocate buffer for command iocb */
328 geniocb = lpfc_sli_get_iocbq(phba);
333 icmd = &geniocb->iocb;
334 icmd->un.genreq64.bdl.ulpIoTag32 = 0;
335 icmd->un.genreq64.bdl.addrHigh = putPaddrHigh(bmp->phys);
336 icmd->un.genreq64.bdl.addrLow = putPaddrLow(bmp->phys);
337 icmd->un.genreq64.bdl.bdeFlags = BUFF_TYPE_BLP_64;
338 icmd->un.genreq64.bdl.bdeSize = (num_entry * sizeof(struct ulp_bde64));
341 geniocb->context3 = NULL;
343 geniocb->context3 = (uint8_t *) bmp;
345 /* Save for completion so we can release these resources */
346 geniocb->context1 = (uint8_t *) inp;
347 geniocb->context2 = (uint8_t *) outp;
348 geniocb->context_un.ndlp = lpfc_nlp_get(ndlp);
350 /* Fill in payload, bp points to frame payload */
351 icmd->ulpCommand = CMD_GEN_REQUEST64_CR;
353 /* Fill in rest of iocb */
354 icmd->un.genreq64.w5.hcsw.Fctl = (SI | LA);
355 icmd->un.genreq64.w5.hcsw.Dfctl = 0;
356 icmd->un.genreq64.w5.hcsw.Rctl = FC_RCTL_DD_UNSOL_CTL;
357 icmd->un.genreq64.w5.hcsw.Type = FC_TYPE_CT;
360 /* FC spec states we need 3 * ratov for CT requests */
361 tmo = (3 * phba->fc_ratov);
363 icmd->ulpTimeout = tmo;
364 icmd->ulpBdeCount = 1;
366 icmd->ulpClass = CLASS3;
367 icmd->ulpContext = ndlp->nlp_rpi;
368 if (phba->sli_rev == LPFC_SLI_REV4)
369 icmd->ulpContext = phba->sli4_hba.rpi_ids[ndlp->nlp_rpi];
371 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
372 /* For GEN_REQUEST64_CR, use the RPI */
377 /* Issue GEN REQ IOCB for NPORT <did> */
378 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
379 "0119 Issue GEN REQ IOCB to NPORT x%x "
381 ndlp->nlp_DID, icmd->ulpIoTag,
383 geniocb->iocb_cmpl = cmpl;
384 geniocb->drvrTimeout = icmd->ulpTimeout + LPFC_DRVR_TIMEOUT;
385 geniocb->vport = vport;
386 geniocb->retry = retry;
387 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, geniocb, 0);
389 if (rc == IOCB_ERROR) {
390 lpfc_sli_release_iocbq(phba, geniocb);
398 * lpfc_ct_cmd - Build and issue a CT command
399 * @vport: pointer to a host virtual N_Port data structure.
400 * @inmp: Pointer to data buffer for response data.
401 * @bmp: Pointer to BPL for SLI command
402 * @ndlp: Destination NPort nodelist entry
403 * @cmpl: completion routine to call when command completes
405 * This function is called for issuing a CT command.
408 lpfc_ct_cmd(struct lpfc_vport *vport, struct lpfc_dmabuf *inmp,
409 struct lpfc_dmabuf *bmp, struct lpfc_nodelist *ndlp,
410 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
411 struct lpfc_iocbq *),
412 uint32_t rsp_size, uint8_t retry)
414 struct lpfc_hba *phba = vport->phba;
415 struct ulp_bde64 *bpl = (struct ulp_bde64 *) bmp->virt;
416 struct lpfc_dmabuf *outmp;
418 int cmdcode = ((struct lpfc_sli_ct_request *) inmp->virt)->
419 CommandResponse.bits.CmdRsp;
421 bpl++; /* Skip past ct request */
423 /* Put buffer(s) for ct rsp in bpl */
424 outmp = lpfc_alloc_ct_rsp(phba, cmdcode, bpl, rsp_size, &cnt);
428 * Form the CT IOCB. The total number of BDEs in this IOCB
429 * is the single command plus response count from
433 status = lpfc_gen_req(vport, bmp, inmp, outmp, cmpl, ndlp, 0,
436 lpfc_free_ct_rsp(phba, outmp);
443 lpfc_find_vport_by_did(struct lpfc_hba *phba, uint32_t did) {
444 struct lpfc_vport *vport_curr;
447 spin_lock_irqsave(&phba->port_list_lock, flags);
448 list_for_each_entry(vport_curr, &phba->port_list, listentry) {
449 if ((vport_curr->fc_myDID) && (vport_curr->fc_myDID == did)) {
450 spin_unlock_irqrestore(&phba->port_list_lock, flags);
454 spin_unlock_irqrestore(&phba->port_list_lock, flags);
459 lpfc_prep_node_fc4type(struct lpfc_vport *vport, uint32_t Did, uint8_t fc4_type)
461 struct lpfc_nodelist *ndlp;
463 if ((vport->port_type != LPFC_NPIV_PORT) ||
464 !(vport->ct_flags & FC_CT_RFF_ID) || !vport->cfg_restrict_login) {
466 ndlp = lpfc_setup_disc_node(vport, Did);
468 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
469 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
470 "Parse GID_FTrsp: did:x%x flg:x%x x%x",
471 Did, ndlp->nlp_flag, vport->fc_flag);
473 /* By default, the driver expects to support FCP FC4 */
474 if (fc4_type == FC_TYPE_FCP)
475 ndlp->nlp_fc4_type |= NLP_FC4_FCP;
477 if (fc4_type == FC_TYPE_NVME)
478 ndlp->nlp_fc4_type |= NLP_FC4_NVME;
480 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
481 "0238 Process x%06x NameServer Rsp "
482 "Data: x%x x%x x%x x%x x%x\n", Did,
483 ndlp->nlp_flag, ndlp->nlp_fc4_type,
484 ndlp->nlp_state, vport->fc_flag,
485 vport->fc_rscn_id_cnt);
487 /* if ndlp needs to be discovered and prior
488 * state of ndlp hit devloss, change state to
491 if (ndlp->nlp_flag & NLP_NPR_2B_DISC &&
492 ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
493 lpfc_nlp_set_state(vport, ndlp,
497 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
498 "Skip1 GID_FTrsp: did:x%x flg:x%x cnt:%d",
499 Did, vport->fc_flag, vport->fc_rscn_id_cnt);
501 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
502 "0239 Skip x%06x NameServer Rsp "
503 "Data: x%x x%x %p\n",
505 vport->fc_rscn_id_cnt, ndlp);
508 if (!(vport->fc_flag & FC_RSCN_MODE) ||
509 lpfc_rscn_payload_check(vport, Did)) {
510 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
511 "Query GID_FTrsp: did:x%x flg:x%x cnt:%d",
512 Did, vport->fc_flag, vport->fc_rscn_id_cnt);
515 * This NPortID was previously a FCP/NVMe target,
516 * Don't even bother to send GFF_ID.
518 ndlp = lpfc_findnode_did(vport, Did);
519 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
521 (NLP_FCP_TARGET | NLP_NVME_TARGET))) {
522 if (fc4_type == FC_TYPE_FCP)
523 ndlp->nlp_fc4_type |= NLP_FC4_FCP;
524 if (fc4_type == FC_TYPE_NVME)
525 ndlp->nlp_fc4_type |= NLP_FC4_NVME;
526 lpfc_setup_disc_node(vport, Did);
527 } else if (lpfc_ns_cmd(vport, SLI_CTNS_GFF_ID,
529 vport->num_disc_nodes++;
531 lpfc_setup_disc_node(vport, Did);
533 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
534 "Skip2 GID_FTrsp: did:x%x flg:x%x cnt:%d",
535 Did, vport->fc_flag, vport->fc_rscn_id_cnt);
537 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
538 "0245 Skip x%06x NameServer Rsp "
539 "Data: x%x x%x\n", Did,
541 vport->fc_rscn_id_cnt);
547 lpfc_ns_rsp_audit_did(struct lpfc_vport *vport, uint32_t Did, uint8_t fc4_type)
549 struct lpfc_hba *phba = vport->phba;
550 struct lpfc_nodelist *ndlp = NULL;
551 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
554 if (phba->cfg_ns_query == LPFC_NS_QUERY_GID_FT)
558 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
559 "6430 Process %s rsp for %08x type %x %s %s\n",
561 (fc4_type == FC_TYPE_FCP) ? "FCP" : " ",
562 (fc4_type == FC_TYPE_NVME) ? "NVME" : " ");
564 * To conserve rpi's, filter out addresses for other
565 * vports on the same physical HBAs.
567 if (Did != vport->fc_myDID &&
568 (!lpfc_find_vport_by_did(phba, Did) ||
569 vport->cfg_peer_port_login)) {
570 if (!phba->nvmet_support) {
571 /* FCPI/NVMEI path. Process Did */
572 lpfc_prep_node_fc4type(vport, Did, fc4_type);
575 /* NVMET path. NVMET only cares about NVMEI nodes. */
576 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
577 if (ndlp->nlp_type != NLP_NVME_INITIATOR ||
578 ndlp->nlp_state != NLP_STE_UNMAPPED_NODE)
580 spin_lock_irq(shost->host_lock);
581 if (ndlp->nlp_DID == Did)
582 ndlp->nlp_flag &= ~NLP_NVMET_RECOV;
584 ndlp->nlp_flag |= NLP_NVMET_RECOV;
585 spin_unlock_irq(shost->host_lock);
591 lpfc_ns_rsp(struct lpfc_vport *vport, struct lpfc_dmabuf *mp, uint8_t fc4_type,
594 struct lpfc_sli_ct_request *Response =
595 (struct lpfc_sli_ct_request *) mp->virt;
596 struct lpfc_dmabuf *mlast, *next_mp;
597 uint32_t *ctptr = (uint32_t *) & Response->un.gid.PortType;
598 uint32_t Did, CTentry;
600 struct list_head head;
601 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
602 struct lpfc_nodelist *ndlp = NULL;
604 lpfc_set_disctmo(vport);
605 vport->num_disc_nodes = 0;
606 vport->fc_ns_retry = 0;
609 list_add_tail(&head, &mp->list);
610 list_for_each_entry_safe(mp, next_mp, &head, list) {
613 Cnt = Size > FCELSSIZE ? FCELSSIZE : Size;
618 ctptr = (uint32_t *) mlast->virt;
620 Cnt -= 16; /* subtract length of CT header */
622 /* Loop through entire NameServer list of DIDs */
623 while (Cnt >= sizeof(uint32_t)) {
624 /* Get next DID from NameServer List */
626 Did = ((be32_to_cpu(CTentry)) & Mask_DID);
627 lpfc_ns_rsp_audit_did(vport, Did, fc4_type);
628 if (CTentry & (cpu_to_be32(SLI_CT_LAST_ENTRY)))
631 Cnt -= sizeof(uint32_t);
637 /* All GID_FT entries processed. If the driver is running in
638 * in target mode, put impacted nodes into recovery and drop
639 * the RPI to flush outstanding IO.
641 if (vport->phba->nvmet_support) {
642 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
643 if (!(ndlp->nlp_flag & NLP_NVMET_RECOV))
645 lpfc_disc_state_machine(vport, ndlp, NULL,
646 NLP_EVT_DEVICE_RECOVERY);
647 spin_lock_irq(shost->host_lock);
648 ndlp->nlp_flag &= ~NLP_NVMET_RECOV;
649 spin_unlock_irq(shost->host_lock);
659 lpfc_cmpl_ct_cmd_gid_ft(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
660 struct lpfc_iocbq *rspiocb)
662 struct lpfc_vport *vport = cmdiocb->vport;
663 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
665 struct lpfc_dmabuf *outp;
666 struct lpfc_dmabuf *inp;
667 struct lpfc_sli_ct_request *CTrsp;
668 struct lpfc_sli_ct_request *CTreq;
669 struct lpfc_nodelist *ndlp;
672 /* First save ndlp, before we overwrite it */
673 ndlp = cmdiocb->context_un.ndlp;
675 /* we pass cmdiocb to state machine which needs rspiocb as well */
676 cmdiocb->context_un.rsp_iocb = rspiocb;
677 inp = (struct lpfc_dmabuf *) cmdiocb->context1;
678 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
679 irsp = &rspiocb->iocb;
681 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
682 "GID_FT cmpl: status:x%x/x%x rtry:%d",
683 irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_ns_retry);
685 /* Don't bother processing response if vport is being torn down. */
686 if (vport->load_flag & FC_UNLOADING) {
687 if (vport->fc_flag & FC_RSCN_MODE)
688 lpfc_els_flush_rscn(vport);
692 if (lpfc_els_chk_latt(vport)) {
693 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
694 "0216 Link event during NS query\n");
695 if (vport->fc_flag & FC_RSCN_MODE)
696 lpfc_els_flush_rscn(vport);
697 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
700 if (lpfc_error_lost_link(irsp)) {
701 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
702 "0226 NS query failed due to link event\n");
703 if (vport->fc_flag & FC_RSCN_MODE)
704 lpfc_els_flush_rscn(vport);
708 spin_lock_irq(shost->host_lock);
709 if (vport->fc_flag & FC_RSCN_DEFERRED) {
710 vport->fc_flag &= ~FC_RSCN_DEFERRED;
711 spin_unlock_irq(shost->host_lock);
713 /* This is a GID_FT completing so the gidft_inp counter was
714 * incremented before the GID_FT was issued to the wire.
719 * Skip processing the NS response
720 * Re-issue the NS cmd
722 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
723 "0151 Process Deferred RSCN Data: x%x x%x\n",
724 vport->fc_flag, vport->fc_rscn_id_cnt);
725 lpfc_els_handle_rscn(vport);
729 spin_unlock_irq(shost->host_lock);
731 if (irsp->ulpStatus) {
732 /* Check for retry */
733 if (vport->fc_ns_retry < LPFC_MAX_NS_RETRY) {
734 if (irsp->ulpStatus != IOSTAT_LOCAL_REJECT ||
735 (irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
737 vport->fc_ns_retry++;
739 type = lpfc_get_gidft_type(vport, cmdiocb);
743 /* CT command is being retried */
745 rc = lpfc_ns_cmd(vport, SLI_CTNS_GID_FT,
746 vport->fc_ns_retry, type);
750 if (vport->fc_flag & FC_RSCN_MODE)
751 lpfc_els_flush_rscn(vport);
752 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
753 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
754 "0257 GID_FT Query error: 0x%x 0x%x\n",
755 irsp->ulpStatus, vport->fc_ns_retry);
757 /* Good status, continue checking */
758 CTreq = (struct lpfc_sli_ct_request *) inp->virt;
759 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
760 if (CTrsp->CommandResponse.bits.CmdRsp ==
761 cpu_to_be16(SLI_CT_RESPONSE_FS_ACC)) {
762 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
763 "0208 NameServer Rsp Data: x%x x%x "
766 CTreq->un.gid.Fc4Type,
767 vport->num_disc_nodes,
769 irsp->un.genreq64.bdl.bdeSize);
773 CTreq->un.gid.Fc4Type,
774 (uint32_t) (irsp->un.genreq64.bdl.bdeSize));
775 } else if (CTrsp->CommandResponse.bits.CmdRsp ==
776 be16_to_cpu(SLI_CT_RESPONSE_FS_RJT)) {
777 /* NameServer Rsp Error */
778 if ((CTrsp->ReasonCode == SLI_CT_UNABLE_TO_PERFORM_REQ)
779 && (CTrsp->Explanation == SLI_CT_NO_FC4_TYPES)) {
780 lpfc_printf_vlog(vport, KERN_INFO,
782 "0269 No NameServer Entries "
783 "Data: x%x x%x x%x x%x\n",
784 CTrsp->CommandResponse.bits.CmdRsp,
785 (uint32_t) CTrsp->ReasonCode,
786 (uint32_t) CTrsp->Explanation,
789 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
790 "GID_FT no entry cmd:x%x rsn:x%x exp:x%x",
791 (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
792 (uint32_t) CTrsp->ReasonCode,
793 (uint32_t) CTrsp->Explanation);
795 lpfc_printf_vlog(vport, KERN_INFO,
797 "0240 NameServer Rsp Error "
798 "Data: x%x x%x x%x x%x\n",
799 CTrsp->CommandResponse.bits.CmdRsp,
800 (uint32_t) CTrsp->ReasonCode,
801 (uint32_t) CTrsp->Explanation,
804 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
805 "GID_FT rsp err1 cmd:x%x rsn:x%x exp:x%x",
806 (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
807 (uint32_t) CTrsp->ReasonCode,
808 (uint32_t) CTrsp->Explanation);
813 /* NameServer Rsp Error */
814 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
815 "0241 NameServer Rsp Error "
816 "Data: x%x x%x x%x x%x\n",
817 CTrsp->CommandResponse.bits.CmdRsp,
818 (uint32_t) CTrsp->ReasonCode,
819 (uint32_t) CTrsp->Explanation,
822 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
823 "GID_FT rsp err2 cmd:x%x rsn:x%x exp:x%x",
824 (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
825 (uint32_t) CTrsp->ReasonCode,
826 (uint32_t) CTrsp->Explanation);
831 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
832 "4216 GID_FT cmpl inp %d disc %d\n",
833 vport->gidft_inp, vport->num_disc_nodes);
835 /* Link up / RSCN discovery */
836 if ((vport->num_disc_nodes == 0) &&
837 (vport->gidft_inp == 0)) {
839 * The driver has cycled through all Nports in the RSCN payload.
840 * Complete the handling by cleaning up and marking the
841 * current driver state.
843 if (vport->port_state >= LPFC_DISC_AUTH) {
844 if (vport->fc_flag & FC_RSCN_MODE) {
845 lpfc_els_flush_rscn(vport);
846 spin_lock_irq(shost->host_lock);
847 vport->fc_flag |= FC_RSCN_MODE; /* RSCN still */
848 spin_unlock_irq(shost->host_lock);
851 lpfc_els_flush_rscn(vport);
854 lpfc_disc_start(vport);
857 cmdiocb->context_un.ndlp = ndlp; /* Now restore ndlp for free */
858 lpfc_ct_free_iocb(phba, cmdiocb);
863 lpfc_cmpl_ct_cmd_gid_pt(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
864 struct lpfc_iocbq *rspiocb)
866 struct lpfc_vport *vport = cmdiocb->vport;
867 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
869 struct lpfc_dmabuf *outp;
870 struct lpfc_dmabuf *inp;
871 struct lpfc_sli_ct_request *CTrsp;
872 struct lpfc_sli_ct_request *CTreq;
873 struct lpfc_nodelist *ndlp;
876 /* First save ndlp, before we overwrite it */
877 ndlp = cmdiocb->context_un.ndlp;
879 /* we pass cmdiocb to state machine which needs rspiocb as well */
880 cmdiocb->context_un.rsp_iocb = rspiocb;
881 inp = (struct lpfc_dmabuf *)cmdiocb->context1;
882 outp = (struct lpfc_dmabuf *)cmdiocb->context2;
883 irsp = &rspiocb->iocb;
885 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
886 "GID_PT cmpl: status:x%x/x%x rtry:%d",
887 irsp->ulpStatus, irsp->un.ulpWord[4],
890 /* Don't bother processing response if vport is being torn down. */
891 if (vport->load_flag & FC_UNLOADING) {
892 if (vport->fc_flag & FC_RSCN_MODE)
893 lpfc_els_flush_rscn(vport);
897 if (lpfc_els_chk_latt(vport)) {
898 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
899 "4108 Link event during NS query\n");
900 if (vport->fc_flag & FC_RSCN_MODE)
901 lpfc_els_flush_rscn(vport);
902 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
905 if (lpfc_error_lost_link(irsp)) {
906 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
907 "4166 NS query failed due to link event\n");
908 if (vport->fc_flag & FC_RSCN_MODE)
909 lpfc_els_flush_rscn(vport);
913 spin_lock_irq(shost->host_lock);
914 if (vport->fc_flag & FC_RSCN_DEFERRED) {
915 vport->fc_flag &= ~FC_RSCN_DEFERRED;
916 spin_unlock_irq(shost->host_lock);
918 /* This is a GID_PT completing so the gidft_inp counter was
919 * incremented before the GID_PT was issued to the wire.
924 * Skip processing the NS response
925 * Re-issue the NS cmd
927 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
928 "4167 Process Deferred RSCN Data: x%x x%x\n",
929 vport->fc_flag, vport->fc_rscn_id_cnt);
930 lpfc_els_handle_rscn(vport);
934 spin_unlock_irq(shost->host_lock);
936 if (irsp->ulpStatus) {
937 /* Check for retry */
938 if (vport->fc_ns_retry < LPFC_MAX_NS_RETRY) {
939 if (irsp->ulpStatus != IOSTAT_LOCAL_REJECT ||
940 (irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
942 vport->fc_ns_retry++;
944 /* CT command is being retried */
946 rc = lpfc_ns_cmd(vport, SLI_CTNS_GID_PT,
947 vport->fc_ns_retry, GID_PT_N_PORT);
951 if (vport->fc_flag & FC_RSCN_MODE)
952 lpfc_els_flush_rscn(vport);
953 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
954 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
955 "4103 GID_FT Query error: 0x%x 0x%x\n",
956 irsp->ulpStatus, vport->fc_ns_retry);
958 /* Good status, continue checking */
959 CTreq = (struct lpfc_sli_ct_request *)inp->virt;
960 CTrsp = (struct lpfc_sli_ct_request *)outp->virt;
961 if (CTrsp->CommandResponse.bits.CmdRsp ==
962 cpu_to_be16(SLI_CT_RESPONSE_FS_ACC)) {
963 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
964 "4105 NameServer Rsp Data: x%x x%x "
967 CTreq->un.gid.Fc4Type,
968 vport->num_disc_nodes,
970 irsp->un.genreq64.bdl.bdeSize);
974 CTreq->un.gid.Fc4Type,
975 (uint32_t)(irsp->un.genreq64.bdl.bdeSize));
976 } else if (CTrsp->CommandResponse.bits.CmdRsp ==
977 be16_to_cpu(SLI_CT_RESPONSE_FS_RJT)) {
978 /* NameServer Rsp Error */
979 if ((CTrsp->ReasonCode == SLI_CT_UNABLE_TO_PERFORM_REQ)
980 && (CTrsp->Explanation == SLI_CT_NO_FC4_TYPES)) {
982 vport, KERN_INFO, LOG_DISCOVERY,
983 "4106 No NameServer Entries "
984 "Data: x%x x%x x%x x%x\n",
985 CTrsp->CommandResponse.bits.CmdRsp,
986 (uint32_t)CTrsp->ReasonCode,
987 (uint32_t)CTrsp->Explanation,
990 lpfc_debugfs_disc_trc(
991 vport, LPFC_DISC_TRC_CT,
992 "GID_PT no entry cmd:x%x rsn:x%x exp:x%x",
993 (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
994 (uint32_t)CTrsp->ReasonCode,
995 (uint32_t)CTrsp->Explanation);
998 vport, KERN_INFO, LOG_DISCOVERY,
999 "4107 NameServer Rsp Error "
1000 "Data: x%x x%x x%x x%x\n",
1001 CTrsp->CommandResponse.bits.CmdRsp,
1002 (uint32_t)CTrsp->ReasonCode,
1003 (uint32_t)CTrsp->Explanation,
1006 lpfc_debugfs_disc_trc(
1007 vport, LPFC_DISC_TRC_CT,
1008 "GID_PT rsp err1 cmd:x%x rsn:x%x exp:x%x",
1009 (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
1010 (uint32_t)CTrsp->ReasonCode,
1011 (uint32_t)CTrsp->Explanation);
1014 /* NameServer Rsp Error */
1015 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
1016 "4109 NameServer Rsp Error "
1017 "Data: x%x x%x x%x x%x\n",
1018 CTrsp->CommandResponse.bits.CmdRsp,
1019 (uint32_t)CTrsp->ReasonCode,
1020 (uint32_t)CTrsp->Explanation,
1023 lpfc_debugfs_disc_trc(
1024 vport, LPFC_DISC_TRC_CT,
1025 "GID_PT rsp err2 cmd:x%x rsn:x%x exp:x%x",
1026 (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
1027 (uint32_t)CTrsp->ReasonCode,
1028 (uint32_t)CTrsp->Explanation);
1033 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1034 "6450 GID_PT cmpl inp %d disc %d\n",
1035 vport->gidft_inp, vport->num_disc_nodes);
1037 /* Link up / RSCN discovery */
1038 if ((vport->num_disc_nodes == 0) &&
1039 (vport->gidft_inp == 0)) {
1041 * The driver has cycled through all Nports in the RSCN payload.
1042 * Complete the handling by cleaning up and marking the
1043 * current driver state.
1045 if (vport->port_state >= LPFC_DISC_AUTH) {
1046 if (vport->fc_flag & FC_RSCN_MODE) {
1047 lpfc_els_flush_rscn(vport);
1048 spin_lock_irq(shost->host_lock);
1049 vport->fc_flag |= FC_RSCN_MODE; /* RSCN still */
1050 spin_unlock_irq(shost->host_lock);
1052 lpfc_els_flush_rscn(vport);
1056 lpfc_disc_start(vport);
1059 cmdiocb->context_un.ndlp = ndlp; /* Now restore ndlp for free */
1060 lpfc_ct_free_iocb(phba, cmdiocb);
1064 lpfc_cmpl_ct_cmd_gff_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1065 struct lpfc_iocbq *rspiocb)
1067 struct lpfc_vport *vport = cmdiocb->vport;
1068 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1069 IOCB_t *irsp = &rspiocb->iocb;
1070 struct lpfc_dmabuf *inp = (struct lpfc_dmabuf *) cmdiocb->context1;
1071 struct lpfc_dmabuf *outp = (struct lpfc_dmabuf *) cmdiocb->context2;
1072 struct lpfc_sli_ct_request *CTrsp;
1075 struct lpfc_nodelist *ndlp;
1077 did = ((struct lpfc_sli_ct_request *) inp->virt)->un.gff.PortId;
1078 did = be32_to_cpu(did);
1080 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
1081 "GFF_ID cmpl: status:x%x/x%x did:x%x",
1082 irsp->ulpStatus, irsp->un.ulpWord[4], did);
1084 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
1085 /* Good status, continue checking */
1086 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
1087 fbits = CTrsp->un.gff_acc.fbits[FCP_TYPE_FEATURE_OFFSET];
1089 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1090 "6431 Process GFF_ID rsp for %08x "
1091 "fbits %02x %s %s\n",
1093 (fbits & FC4_FEATURE_INIT) ? "Initiator" : " ",
1094 (fbits & FC4_FEATURE_TARGET) ? "Target" : " ");
1096 if (CTrsp->CommandResponse.bits.CmdRsp ==
1097 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC)) {
1098 if ((fbits & FC4_FEATURE_INIT) &&
1099 !(fbits & FC4_FEATURE_TARGET)) {
1100 lpfc_printf_vlog(vport, KERN_INFO,
1102 "0270 Skip x%x GFF "
1103 "NameServer Rsp Data: (init) "
1104 "x%x x%x\n", did, fbits,
1105 vport->fc_rscn_id_cnt);
1111 /* Check for retry */
1112 if (cmdiocb->retry < LPFC_MAX_NS_RETRY) {
1114 if (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) {
1115 switch ((irsp->un.ulpWord[4] &
1116 IOERR_PARAM_MASK)) {
1118 case IOERR_NO_RESOURCES:
1119 /* We don't increment the retry
1120 * count for this case.
1123 case IOERR_LINK_DOWN:
1124 case IOERR_SLI_ABORTED:
1125 case IOERR_SLI_DOWN:
1136 /* CT command is being retried */
1137 rc = lpfc_ns_cmd(vport, SLI_CTNS_GFF_ID,
1138 cmdiocb->retry, did);
1141 lpfc_ct_free_iocb(phba, cmdiocb);
1146 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
1147 "0267 NameServer GFF Rsp "
1148 "x%x Error (%d %d) Data: x%x x%x\n",
1149 did, irsp->ulpStatus, irsp->un.ulpWord[4],
1150 vport->fc_flag, vport->fc_rscn_id_cnt);
1153 /* This is a target port, unregistered port, or the GFF_ID failed */
1154 ndlp = lpfc_setup_disc_node(vport, did);
1155 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
1156 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1157 "0242 Process x%x GFF "
1158 "NameServer Rsp Data: x%x x%x x%x\n",
1159 did, ndlp->nlp_flag, vport->fc_flag,
1160 vport->fc_rscn_id_cnt);
1162 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1163 "0243 Skip x%x GFF "
1164 "NameServer Rsp Data: x%x x%x\n", did,
1165 vport->fc_flag, vport->fc_rscn_id_cnt);
1168 /* Link up / RSCN discovery */
1169 if (vport->num_disc_nodes)
1170 vport->num_disc_nodes--;
1172 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1173 "6451 GFF_ID cmpl inp %d disc %d\n",
1174 vport->gidft_inp, vport->num_disc_nodes);
1176 if (vport->num_disc_nodes == 0) {
1178 * The driver has cycled through all Nports in the RSCN payload.
1179 * Complete the handling by cleaning up and marking the
1180 * current driver state.
1182 if (vport->port_state >= LPFC_DISC_AUTH) {
1183 if (vport->fc_flag & FC_RSCN_MODE) {
1184 lpfc_els_flush_rscn(vport);
1185 spin_lock_irq(shost->host_lock);
1186 vport->fc_flag |= FC_RSCN_MODE; /* RSCN still */
1187 spin_unlock_irq(shost->host_lock);
1190 lpfc_els_flush_rscn(vport);
1192 lpfc_disc_start(vport);
1194 lpfc_ct_free_iocb(phba, cmdiocb);
1199 lpfc_cmpl_ct_cmd_gft_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1200 struct lpfc_iocbq *rspiocb)
1202 struct lpfc_vport *vport = cmdiocb->vport;
1203 IOCB_t *irsp = &rspiocb->iocb;
1204 struct lpfc_dmabuf *inp = (struct lpfc_dmabuf *)cmdiocb->context1;
1205 struct lpfc_dmabuf *outp = (struct lpfc_dmabuf *)cmdiocb->context2;
1206 struct lpfc_sli_ct_request *CTrsp;
1208 struct lpfc_nodelist *ndlp;
1209 uint32_t fc4_data_0, fc4_data_1;
1211 did = ((struct lpfc_sli_ct_request *)inp->virt)->un.gft.PortId;
1212 did = be32_to_cpu(did);
1214 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
1215 "GFT_ID cmpl: status:x%x/x%x did:x%x",
1216 irsp->ulpStatus, irsp->un.ulpWord[4], did);
1218 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
1219 /* Good status, continue checking */
1220 CTrsp = (struct lpfc_sli_ct_request *)outp->virt;
1221 fc4_data_0 = be32_to_cpu(CTrsp->un.gft_acc.fc4_types[0]);
1222 fc4_data_1 = be32_to_cpu(CTrsp->un.gft_acc.fc4_types[1]);
1224 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1225 "6432 Process GFT_ID rsp for %08x "
1226 "Data %08x %08x %s %s\n",
1227 did, fc4_data_0, fc4_data_1,
1228 (fc4_data_0 & LPFC_FC4_TYPE_BITMASK) ?
1230 (fc4_data_1 & LPFC_FC4_TYPE_BITMASK) ?
1233 ndlp = lpfc_findnode_did(vport, did);
1235 /* The bitmask value for FCP and NVME FCP types is
1236 * the same because they are 32 bits distant from
1237 * each other in word0 and word0.
1239 if (fc4_data_0 & LPFC_FC4_TYPE_BITMASK)
1240 ndlp->nlp_fc4_type |= NLP_FC4_FCP;
1241 if (fc4_data_1 & LPFC_FC4_TYPE_BITMASK)
1242 ndlp->nlp_fc4_type |= NLP_FC4_NVME;
1243 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1244 "3064 Setting ndlp x%px, DID x%06x "
1245 "with FC4 x%08x, Data: x%08x x%08x "
1247 ndlp, did, ndlp->nlp_fc4_type,
1248 FC_TYPE_FCP, FC_TYPE_NVME,
1251 if (ndlp->nlp_state == NLP_STE_REG_LOGIN_ISSUE &&
1252 ndlp->nlp_fc4_type) {
1253 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1255 lpfc_nlp_set_state(vport, ndlp,
1256 NLP_STE_PRLI_ISSUE);
1257 lpfc_issue_els_prli(vport, ndlp, 0);
1258 } else if (!ndlp->nlp_fc4_type) {
1259 /* If fc4 type is still unknown, then LOGO */
1260 lpfc_printf_vlog(vport, KERN_INFO,
1262 "6443 Sending LOGO ndlp x%px,"
1263 "DID x%06x with fc4_type: "
1264 "x%08x, state: %d\n",
1265 ndlp, did, ndlp->nlp_fc4_type,
1267 lpfc_issue_els_logo(vport, ndlp, 0);
1268 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1269 lpfc_nlp_set_state(vport, ndlp,
1274 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
1275 "3065 GFT_ID failed x%08x\n", irsp->ulpStatus);
1277 lpfc_ct_free_iocb(phba, cmdiocb);
1281 lpfc_cmpl_ct(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1282 struct lpfc_iocbq *rspiocb)
1284 struct lpfc_vport *vport = cmdiocb->vport;
1285 struct lpfc_dmabuf *inp;
1286 struct lpfc_dmabuf *outp;
1288 struct lpfc_sli_ct_request *CTrsp;
1289 struct lpfc_nodelist *ndlp;
1294 /* First save ndlp, before we overwrite it */
1295 ndlp = cmdiocb->context_un.ndlp;
1297 /* we pass cmdiocb to state machine which needs rspiocb as well */
1298 cmdiocb->context_un.rsp_iocb = rspiocb;
1300 inp = (struct lpfc_dmabuf *) cmdiocb->context1;
1301 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
1302 irsp = &rspiocb->iocb;
1304 cmdcode = be16_to_cpu(((struct lpfc_sli_ct_request *) inp->virt)->
1305 CommandResponse.bits.CmdRsp);
1306 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
1308 latt = lpfc_els_chk_latt(vport);
1310 /* RFT request completes status <ulpStatus> CmdRsp <CmdRsp> */
1311 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1312 "0209 CT Request completes, latt %d, "
1313 "ulpStatus x%x CmdRsp x%x, Context x%x, Tag x%x\n",
1314 latt, irsp->ulpStatus,
1315 CTrsp->CommandResponse.bits.CmdRsp,
1316 cmdiocb->iocb.ulpContext, cmdiocb->iocb.ulpIoTag);
1318 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
1319 "CT cmd cmpl: status:x%x/x%x cmd:x%x",
1320 irsp->ulpStatus, irsp->un.ulpWord[4], cmdcode);
1322 if (irsp->ulpStatus) {
1323 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
1324 "0268 NS cmd x%x Error (x%x x%x)\n",
1325 cmdcode, irsp->ulpStatus, irsp->un.ulpWord[4]);
1327 if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
1328 (((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
1330 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
1331 IOERR_SLI_ABORTED)))
1334 retry = cmdiocb->retry;
1335 if (retry >= LPFC_MAX_NS_RETRY)
1339 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1340 "0250 Retrying NS cmd %x\n", cmdcode);
1341 rc = lpfc_ns_cmd(vport, cmdcode, retry, 0);
1347 cmdiocb->context_un.ndlp = ndlp; /* Now restore ndlp for free */
1348 lpfc_ct_free_iocb(phba, cmdiocb);
1353 lpfc_cmpl_ct_cmd_rft_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1354 struct lpfc_iocbq *rspiocb)
1356 IOCB_t *irsp = &rspiocb->iocb;
1357 struct lpfc_vport *vport = cmdiocb->vport;
1359 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
1360 struct lpfc_dmabuf *outp;
1361 struct lpfc_sli_ct_request *CTrsp;
1363 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
1364 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
1365 if (CTrsp->CommandResponse.bits.CmdRsp ==
1366 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
1367 vport->ct_flags |= FC_CT_RFT_ID;
1369 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
1374 lpfc_cmpl_ct_cmd_rnn_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1375 struct lpfc_iocbq *rspiocb)
1377 IOCB_t *irsp = &rspiocb->iocb;
1378 struct lpfc_vport *vport = cmdiocb->vport;
1380 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
1381 struct lpfc_dmabuf *outp;
1382 struct lpfc_sli_ct_request *CTrsp;
1384 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
1385 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
1386 if (CTrsp->CommandResponse.bits.CmdRsp ==
1387 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
1388 vport->ct_flags |= FC_CT_RNN_ID;
1390 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
1395 lpfc_cmpl_ct_cmd_rspn_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1396 struct lpfc_iocbq *rspiocb)
1398 IOCB_t *irsp = &rspiocb->iocb;
1399 struct lpfc_vport *vport = cmdiocb->vport;
1401 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
1402 struct lpfc_dmabuf *outp;
1403 struct lpfc_sli_ct_request *CTrsp;
1405 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
1406 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
1407 if (CTrsp->CommandResponse.bits.CmdRsp ==
1408 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
1409 vport->ct_flags |= FC_CT_RSPN_ID;
1411 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
1416 lpfc_cmpl_ct_cmd_rsnn_nn(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1417 struct lpfc_iocbq *rspiocb)
1419 IOCB_t *irsp = &rspiocb->iocb;
1420 struct lpfc_vport *vport = cmdiocb->vport;
1422 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
1423 struct lpfc_dmabuf *outp;
1424 struct lpfc_sli_ct_request *CTrsp;
1426 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
1427 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
1428 if (CTrsp->CommandResponse.bits.CmdRsp ==
1429 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
1430 vport->ct_flags |= FC_CT_RSNN_NN;
1432 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
1437 lpfc_cmpl_ct_cmd_da_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1438 struct lpfc_iocbq *rspiocb)
1440 struct lpfc_vport *vport = cmdiocb->vport;
1442 /* even if it fails we will act as though it succeeded. */
1443 vport->ct_flags = 0;
1444 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
1449 lpfc_cmpl_ct_cmd_rff_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1450 struct lpfc_iocbq *rspiocb)
1452 IOCB_t *irsp = &rspiocb->iocb;
1453 struct lpfc_vport *vport = cmdiocb->vport;
1455 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
1456 struct lpfc_dmabuf *outp;
1457 struct lpfc_sli_ct_request *CTrsp;
1459 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
1460 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
1461 if (CTrsp->CommandResponse.bits.CmdRsp ==
1462 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
1463 vport->ct_flags |= FC_CT_RFF_ID;
1465 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
1470 * Although the symbolic port name is thought to be an integer
1471 * as of January 18, 2016, leave it as a string until more of
1472 * the record state becomes defined.
1475 lpfc_vport_symbolic_port_name(struct lpfc_vport *vport, char *symbol,
1481 * Use the lpfc board number as the Symbolic Port
1482 * Name object. NPIV is not in play so this integer
1483 * value is sufficient and unique per FC-ID.
1485 n = scnprintf(symbol, size, "%d", vport->phba->brd_no);
1491 lpfc_vport_symbolic_node_name(struct lpfc_vport *vport, char *symbol,
1494 char fwrev[FW_REV_STR_SIZE] = {0};
1495 char tmp[MAXHOSTNAMELEN] = {0};
1497 memset(symbol, 0, size);
1499 scnprintf(tmp, sizeof(tmp), "Emulex %s", vport->phba->ModelName);
1500 if (strlcat(symbol, tmp, size) >= size)
1503 lpfc_decode_firmware_rev(vport->phba, fwrev, 0);
1504 scnprintf(tmp, sizeof(tmp), " FV%s", fwrev);
1505 if (strlcat(symbol, tmp, size) >= size)
1508 scnprintf(tmp, sizeof(tmp), " DV%s", lpfc_release_version);
1509 if (strlcat(symbol, tmp, size) >= size)
1512 scnprintf(tmp, sizeof(tmp), " HN:%s", vport->phba->os_host_name);
1513 if (strlcat(symbol, tmp, size) >= size)
1516 /* Note :- OS name is "Linux" */
1517 scnprintf(tmp, sizeof(tmp), " OS:%s", init_utsname()->sysname);
1518 strlcat(symbol, tmp, size);
1521 return strnlen(symbol, size);
1526 lpfc_find_map_node(struct lpfc_vport *vport)
1528 struct lpfc_nodelist *ndlp, *next_ndlp;
1529 struct Scsi_Host *shost;
1532 shost = lpfc_shost_from_vport(vport);
1533 spin_lock_irq(shost->host_lock);
1534 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
1535 if (ndlp->nlp_type & NLP_FABRIC)
1537 if ((ndlp->nlp_state == NLP_STE_MAPPED_NODE) ||
1538 (ndlp->nlp_state == NLP_STE_UNMAPPED_NODE))
1541 spin_unlock_irq(shost->host_lock);
1546 * This routine will return the FC4 Type associated with the CT
1550 lpfc_get_gidft_type(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb)
1552 struct lpfc_sli_ct_request *CtReq;
1553 struct lpfc_dmabuf *mp;
1556 mp = cmdiocb->context1;
1559 CtReq = (struct lpfc_sli_ct_request *)mp->virt;
1560 type = (uint32_t)CtReq->un.gid.Fc4Type;
1561 if ((type != SLI_CTPT_FCP) && (type != SLI_CTPT_NVME))
1569 * Issue Cmd to NameServer
1574 lpfc_ns_cmd(struct lpfc_vport *vport, int cmdcode,
1575 uint8_t retry, uint32_t context)
1577 struct lpfc_nodelist * ndlp;
1578 struct lpfc_hba *phba = vport->phba;
1579 struct lpfc_dmabuf *mp, *bmp;
1580 struct lpfc_sli_ct_request *CtReq;
1581 struct ulp_bde64 *bpl;
1582 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
1583 struct lpfc_iocbq *) = NULL;
1585 uint32_t rsp_size = 1024;
1589 ndlp = lpfc_findnode_did(vport, NameServer_DID);
1590 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)
1591 || ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) {
1596 /* fill in BDEs for command */
1597 /* Allocate buffer for command payload */
1598 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
1604 INIT_LIST_HEAD(&mp->list);
1605 mp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(mp->phys));
1608 goto ns_cmd_free_mp;
1611 /* Allocate buffer for Buffer ptr list */
1612 bmp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
1615 goto ns_cmd_free_mpvirt;
1618 INIT_LIST_HEAD(&bmp->list);
1619 bmp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(bmp->phys));
1622 goto ns_cmd_free_bmp;
1625 /* NameServer Req */
1626 lpfc_printf_vlog(vport, KERN_INFO ,LOG_DISCOVERY,
1627 "0236 NameServer Req Data: x%x x%x x%x x%x\n",
1628 cmdcode, vport->fc_flag, vport->fc_rscn_id_cnt,
1631 bpl = (struct ulp_bde64 *) bmp->virt;
1632 memset(bpl, 0, sizeof(struct ulp_bde64));
1633 bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys) );
1634 bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys) );
1635 bpl->tus.f.bdeFlags = 0;
1636 if (cmdcode == SLI_CTNS_GID_FT)
1637 bpl->tus.f.bdeSize = GID_REQUEST_SZ;
1638 else if (cmdcode == SLI_CTNS_GID_PT)
1639 bpl->tus.f.bdeSize = GID_REQUEST_SZ;
1640 else if (cmdcode == SLI_CTNS_GFF_ID)
1641 bpl->tus.f.bdeSize = GFF_REQUEST_SZ;
1642 else if (cmdcode == SLI_CTNS_GFT_ID)
1643 bpl->tus.f.bdeSize = GFT_REQUEST_SZ;
1644 else if (cmdcode == SLI_CTNS_RFT_ID)
1645 bpl->tus.f.bdeSize = RFT_REQUEST_SZ;
1646 else if (cmdcode == SLI_CTNS_RNN_ID)
1647 bpl->tus.f.bdeSize = RNN_REQUEST_SZ;
1648 else if (cmdcode == SLI_CTNS_RSPN_ID)
1649 bpl->tus.f.bdeSize = RSPN_REQUEST_SZ;
1650 else if (cmdcode == SLI_CTNS_RSNN_NN)
1651 bpl->tus.f.bdeSize = RSNN_REQUEST_SZ;
1652 else if (cmdcode == SLI_CTNS_DA_ID)
1653 bpl->tus.f.bdeSize = DA_ID_REQUEST_SZ;
1654 else if (cmdcode == SLI_CTNS_RFF_ID)
1655 bpl->tus.f.bdeSize = RFF_REQUEST_SZ;
1657 bpl->tus.f.bdeSize = 0;
1658 bpl->tus.w = le32_to_cpu(bpl->tus.w);
1660 CtReq = (struct lpfc_sli_ct_request *) mp->virt;
1661 memset(CtReq, 0, sizeof(struct lpfc_sli_ct_request));
1662 CtReq->RevisionId.bits.Revision = SLI_CT_REVISION;
1663 CtReq->RevisionId.bits.InId = 0;
1664 CtReq->FsType = SLI_CT_DIRECTORY_SERVICE;
1665 CtReq->FsSubType = SLI_CT_DIRECTORY_NAME_SERVER;
1666 CtReq->CommandResponse.bits.Size = 0;
1668 case SLI_CTNS_GID_FT:
1669 CtReq->CommandResponse.bits.CmdRsp =
1670 cpu_to_be16(SLI_CTNS_GID_FT);
1671 CtReq->un.gid.Fc4Type = context;
1673 if (vport->port_state < LPFC_NS_QRY)
1674 vport->port_state = LPFC_NS_QRY;
1675 lpfc_set_disctmo(vport);
1676 cmpl = lpfc_cmpl_ct_cmd_gid_ft;
1677 rsp_size = FC_MAX_NS_RSP;
1680 case SLI_CTNS_GID_PT:
1681 CtReq->CommandResponse.bits.CmdRsp =
1682 cpu_to_be16(SLI_CTNS_GID_PT);
1683 CtReq->un.gid.PortType = context;
1685 if (vport->port_state < LPFC_NS_QRY)
1686 vport->port_state = LPFC_NS_QRY;
1687 lpfc_set_disctmo(vport);
1688 cmpl = lpfc_cmpl_ct_cmd_gid_pt;
1689 rsp_size = FC_MAX_NS_RSP;
1692 case SLI_CTNS_GFF_ID:
1693 CtReq->CommandResponse.bits.CmdRsp =
1694 cpu_to_be16(SLI_CTNS_GFF_ID);
1695 CtReq->un.gff.PortId = cpu_to_be32(context);
1696 cmpl = lpfc_cmpl_ct_cmd_gff_id;
1699 case SLI_CTNS_GFT_ID:
1700 CtReq->CommandResponse.bits.CmdRsp =
1701 cpu_to_be16(SLI_CTNS_GFT_ID);
1702 CtReq->un.gft.PortId = cpu_to_be32(context);
1703 cmpl = lpfc_cmpl_ct_cmd_gft_id;
1706 case SLI_CTNS_RFT_ID:
1707 vport->ct_flags &= ~FC_CT_RFT_ID;
1708 CtReq->CommandResponse.bits.CmdRsp =
1709 cpu_to_be16(SLI_CTNS_RFT_ID);
1710 CtReq->un.rft.PortId = cpu_to_be32(vport->fc_myDID);
1712 /* Register FC4 FCP type if enabled. */
1713 if (vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH ||
1714 vport->cfg_enable_fc4_type == LPFC_ENABLE_FCP)
1715 CtReq->un.rft.fcpReg = 1;
1717 /* Register NVME type if enabled. Defined LE and swapped.
1718 * rsvd[0] is used as word1 because of the hard-coded
1719 * word0 usage in the ct_request data structure.
1721 if (vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH ||
1722 vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME)
1723 CtReq->un.rft.rsvd[0] =
1724 cpu_to_be32(LPFC_FC4_TYPE_BITMASK);
1726 ptr = (uint32_t *)CtReq;
1727 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1728 "6433 Issue RFT (%s %s): %08x %08x %08x %08x "
1729 "%08x %08x %08x %08x\n",
1730 CtReq->un.rft.fcpReg ? "FCP" : " ",
1731 CtReq->un.rft.rsvd[0] ? "NVME" : " ",
1732 *ptr, *(ptr + 1), *(ptr + 2), *(ptr + 3),
1733 *(ptr + 4), *(ptr + 5),
1734 *(ptr + 6), *(ptr + 7));
1735 cmpl = lpfc_cmpl_ct_cmd_rft_id;
1738 case SLI_CTNS_RNN_ID:
1739 vport->ct_flags &= ~FC_CT_RNN_ID;
1740 CtReq->CommandResponse.bits.CmdRsp =
1741 cpu_to_be16(SLI_CTNS_RNN_ID);
1742 CtReq->un.rnn.PortId = cpu_to_be32(vport->fc_myDID);
1743 memcpy(CtReq->un.rnn.wwnn, &vport->fc_nodename,
1744 sizeof(struct lpfc_name));
1745 cmpl = lpfc_cmpl_ct_cmd_rnn_id;
1748 case SLI_CTNS_RSPN_ID:
1749 vport->ct_flags &= ~FC_CT_RSPN_ID;
1750 CtReq->CommandResponse.bits.CmdRsp =
1751 cpu_to_be16(SLI_CTNS_RSPN_ID);
1752 CtReq->un.rspn.PortId = cpu_to_be32(vport->fc_myDID);
1753 size = sizeof(CtReq->un.rspn.symbname);
1754 CtReq->un.rspn.len =
1755 lpfc_vport_symbolic_port_name(vport,
1756 CtReq->un.rspn.symbname, size);
1757 cmpl = lpfc_cmpl_ct_cmd_rspn_id;
1759 case SLI_CTNS_RSNN_NN:
1760 vport->ct_flags &= ~FC_CT_RSNN_NN;
1761 CtReq->CommandResponse.bits.CmdRsp =
1762 cpu_to_be16(SLI_CTNS_RSNN_NN);
1763 memcpy(CtReq->un.rsnn.wwnn, &vport->fc_nodename,
1764 sizeof(struct lpfc_name));
1765 size = sizeof(CtReq->un.rsnn.symbname);
1766 CtReq->un.rsnn.len =
1767 lpfc_vport_symbolic_node_name(vport,
1768 CtReq->un.rsnn.symbname, size);
1769 cmpl = lpfc_cmpl_ct_cmd_rsnn_nn;
1771 case SLI_CTNS_DA_ID:
1772 /* Implement DA_ID Nameserver request */
1773 CtReq->CommandResponse.bits.CmdRsp =
1774 cpu_to_be16(SLI_CTNS_DA_ID);
1775 CtReq->un.da_id.port_id = cpu_to_be32(vport->fc_myDID);
1776 cmpl = lpfc_cmpl_ct_cmd_da_id;
1778 case SLI_CTNS_RFF_ID:
1779 vport->ct_flags &= ~FC_CT_RFF_ID;
1780 CtReq->CommandResponse.bits.CmdRsp =
1781 cpu_to_be16(SLI_CTNS_RFF_ID);
1782 CtReq->un.rff.PortId = cpu_to_be32(vport->fc_myDID);
1783 CtReq->un.rff.fbits = FC4_FEATURE_INIT;
1785 /* The driver always supports FC_TYPE_FCP. However, the
1786 * caller can specify NVME (type x28) as well. But only
1787 * these that FC4 type is supported.
1789 if (((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
1790 (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) &&
1791 (context == FC_TYPE_NVME)) {
1792 if ((vport == phba->pport) && phba->nvmet_support) {
1793 CtReq->un.rff.fbits = (FC4_FEATURE_TARGET |
1794 FC4_FEATURE_NVME_DISC);
1795 lpfc_nvmet_update_targetport(phba);
1797 lpfc_nvme_update_localport(vport);
1799 CtReq->un.rff.type_code = context;
1801 } else if (((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
1802 (vport->cfg_enable_fc4_type == LPFC_ENABLE_FCP)) &&
1803 (context == FC_TYPE_FCP))
1804 CtReq->un.rff.type_code = context;
1807 goto ns_cmd_free_bmpvirt;
1809 ptr = (uint32_t *)CtReq;
1810 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1811 "6434 Issue RFF (%s): %08x %08x %08x %08x "
1812 "%08x %08x %08x %08x\n",
1813 (context == FC_TYPE_NVME) ? "NVME" : "FCP",
1814 *ptr, *(ptr + 1), *(ptr + 2), *(ptr + 3),
1815 *(ptr + 4), *(ptr + 5),
1816 *(ptr + 6), *(ptr + 7));
1817 cmpl = lpfc_cmpl_ct_cmd_rff_id;
1820 /* The lpfc_ct_cmd/lpfc_get_req shall increment ndlp reference count
1821 * to hold ndlp reference for the corresponding callback function.
1823 if (!lpfc_ct_cmd(vport, mp, bmp, ndlp, cmpl, rsp_size, retry)) {
1824 /* On success, The cmpl function will free the buffers */
1825 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
1826 "Issue CT cmd: cmd:x%x did:x%x",
1827 cmdcode, ndlp->nlp_DID, 0);
1832 /* Decrement ndlp reference count to release ndlp reference held
1833 * for the failed command's callback function.
1837 ns_cmd_free_bmpvirt:
1838 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
1842 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1846 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
1847 "0266 Issue NameServer Req x%x err %d Data: x%x x%x\n",
1848 cmdcode, rc, vport->fc_flag, vport->fc_rscn_id_cnt);
1853 * lpfc_cmpl_ct_disc_fdmi - Handle a discovery FDMI completion
1854 * @phba: Pointer to HBA context object.
1855 * @cmdiocb: Pointer to the command IOCBQ.
1856 * @rspiocb: Pointer to the response IOCBQ.
1858 * This function to handle the completion of a driver initiated FDMI
1859 * CT command issued during discovery.
1862 lpfc_cmpl_ct_disc_fdmi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1863 struct lpfc_iocbq *rspiocb)
1865 struct lpfc_vport *vport = cmdiocb->vport;
1866 struct lpfc_dmabuf *inp = cmdiocb->context1;
1867 struct lpfc_dmabuf *outp = cmdiocb->context2;
1868 struct lpfc_sli_ct_request *CTcmd = inp->virt;
1869 struct lpfc_sli_ct_request *CTrsp = outp->virt;
1870 uint16_t fdmi_cmd = CTcmd->CommandResponse.bits.CmdRsp;
1871 uint16_t fdmi_rsp = CTrsp->CommandResponse.bits.CmdRsp;
1872 IOCB_t *irsp = &rspiocb->iocb;
1873 struct lpfc_nodelist *ndlp;
1874 uint32_t latt, cmd, err;
1876 latt = lpfc_els_chk_latt(vport);
1877 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
1878 "FDMI cmpl: status:x%x/x%x latt:%d",
1879 irsp->ulpStatus, irsp->un.ulpWord[4], latt);
1881 if (latt || irsp->ulpStatus) {
1883 /* Look for a retryable error */
1884 if (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) {
1885 switch ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK)) {
1886 case IOERR_SLI_ABORTED:
1887 case IOERR_SLI_DOWN:
1888 /* Driver aborted this IO. No retry as error
1889 * is likely Offline->Online or some adapter
1890 * error. Recovery will try again.
1893 case IOERR_ABORT_IN_PROGRESS:
1894 case IOERR_SEQUENCE_TIMEOUT:
1895 case IOERR_ILLEGAL_FRAME:
1896 case IOERR_NO_RESOURCES:
1897 case IOERR_ILLEGAL_COMMAND:
1899 if (cmdiocb->retry >= LPFC_FDMI_MAX_RETRY)
1902 /* Retry the same FDMI command */
1903 err = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING,
1905 if (err == IOCB_ERROR)
1913 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1914 "0229 FDMI cmd %04x failed, latt = %d "
1915 "ulpStatus: x%x, rid x%x\n",
1916 be16_to_cpu(fdmi_cmd), latt, irsp->ulpStatus,
1917 irsp->un.ulpWord[4]);
1919 lpfc_ct_free_iocb(phba, cmdiocb);
1921 ndlp = lpfc_findnode_did(vport, FDMI_DID);
1922 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
1925 /* Check for a CT LS_RJT response */
1926 cmd = be16_to_cpu(fdmi_cmd);
1927 if (fdmi_rsp == cpu_to_be16(SLI_CT_RESPONSE_FS_RJT)) {
1928 /* FDMI rsp failed */
1929 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1930 "0220 FDMI cmd failed FS_RJT Data: x%x", cmd);
1932 /* Should we fallback to FDMI-2 / FDMI-1 ? */
1935 if (vport->fdmi_hba_mask == LPFC_FDMI2_HBA_ATTR) {
1936 /* Fallback to FDMI-1 */
1937 vport->fdmi_hba_mask = LPFC_FDMI1_HBA_ATTR;
1938 vport->fdmi_port_mask = LPFC_FDMI1_PORT_ATTR;
1940 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA, 0);
1945 if (vport->fdmi_port_mask == LPFC_FDMI2_PORT_ATTR) {
1946 /* Fallback to FDMI-1 */
1947 vport->fdmi_port_mask = LPFC_FDMI1_PORT_ATTR;
1949 lpfc_fdmi_cmd(vport, ndlp, cmd, 0);
1951 if (vport->fdmi_port_mask == LPFC_FDMI2_SMART_ATTR) {
1952 vport->fdmi_port_mask = LPFC_FDMI2_PORT_ATTR;
1953 /* Retry the same command */
1954 lpfc_fdmi_cmd(vport, ndlp, cmd, 0);
1959 if (vport->fdmi_port_mask == LPFC_FDMI2_PORT_ATTR) {
1960 /* Fallback to FDMI-1 */
1961 vport->fdmi_hba_mask = LPFC_FDMI1_HBA_ATTR;
1962 vport->fdmi_port_mask = LPFC_FDMI1_PORT_ATTR;
1964 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA, 0);
1966 if (vport->fdmi_port_mask == LPFC_FDMI2_SMART_ATTR) {
1967 vport->fdmi_port_mask = LPFC_FDMI2_PORT_ATTR;
1968 /* Retry the same command */
1969 lpfc_fdmi_cmd(vport, ndlp, cmd, 0);
1976 * On success, need to cycle thru FDMI registration for discovery
1977 * DHBA -> DPRT -> RHBA -> RPA (physical port)
1978 * DPRT -> RPRT (vports)
1982 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RPA, 0);
1986 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DPRT, 0);
1990 if (vport->port_type == LPFC_PHYSICAL_PORT)
1991 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RHBA, 0);
1993 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RPRT, 0);
2001 * lpfc_fdmi_change_check - Check for changed FDMI parameters
2002 * @vport: pointer to a host virtual N_Port data structure.
2004 * Check how many mapped NPorts we are connected to
2005 * Check if our hostname changed
2006 * Called from hbeat timeout routine to check if any FDMI parameters
2007 * changed. If so, re-register those Attributes.
2010 lpfc_fdmi_change_check(struct lpfc_vport *vport)
2012 struct lpfc_hba *phba = vport->phba;
2013 struct lpfc_nodelist *ndlp;
2016 if (!lpfc_is_link_up(phba))
2019 /* Must be connected to a Fabric */
2020 if (!(vport->fc_flag & FC_FABRIC))
2023 ndlp = lpfc_findnode_did(vport, FDMI_DID);
2024 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
2027 /* Check if system hostname changed */
2028 if (strcmp(phba->os_host_name, init_utsname()->nodename)) {
2029 memset(phba->os_host_name, 0, sizeof(phba->os_host_name));
2030 scnprintf(phba->os_host_name, sizeof(phba->os_host_name), "%s",
2031 init_utsname()->nodename);
2032 lpfc_ns_cmd(vport, SLI_CTNS_RSNN_NN, 0, 0);
2034 /* Since this effects multiple HBA and PORT attributes, we need
2035 * de-register and go thru the whole FDMI registration cycle.
2036 * DHBA -> DPRT -> RHBA -> RPA (physical port)
2037 * DPRT -> RPRT (vports)
2039 if (vport->port_type == LPFC_PHYSICAL_PORT)
2040 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA, 0);
2042 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DPRT, 0);
2044 /* Since this code path registers all the port attributes
2045 * we can just return without further checking.
2050 if (!(vport->fdmi_port_mask & LPFC_FDMI_PORT_ATTR_num_disc))
2053 /* Check if the number of mapped NPorts changed */
2054 cnt = lpfc_find_map_node(vport);
2055 if (cnt == vport->fdmi_num_disc)
2058 if (vport->port_type == LPFC_PHYSICAL_PORT) {
2059 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RPA,
2060 LPFC_FDMI_PORT_ATTR_num_disc);
2062 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RPRT,
2063 LPFC_FDMI_PORT_ATTR_num_disc);
2067 /* Routines for all individual HBA attributes */
2069 lpfc_fdmi_hba_attr_wwnn(struct lpfc_vport *vport, struct lpfc_fdmi_attr_def *ad)
2071 struct lpfc_fdmi_attr_entry *ae;
2074 ae = &ad->AttrValue;
2075 memset(ae, 0, sizeof(*ae));
2077 memcpy(&ae->un.AttrWWN, &vport->fc_sparam.nodeName,
2078 sizeof(struct lpfc_name));
2079 size = FOURBYTES + sizeof(struct lpfc_name);
2080 ad->AttrLen = cpu_to_be16(size);
2081 ad->AttrType = cpu_to_be16(RHBA_NODENAME);
2085 lpfc_fdmi_hba_attr_manufacturer(struct lpfc_vport *vport,
2086 struct lpfc_fdmi_attr_def *ad)
2088 struct lpfc_fdmi_attr_entry *ae;
2091 ae = &ad->AttrValue;
2092 memset(ae, 0, sizeof(*ae));
2094 /* This string MUST be consistent with other FC platforms
2095 * supported by Broadcom.
2097 strncpy(ae->un.AttrString,
2098 "Emulex Corporation",
2099 sizeof(ae->un.AttrString));
2100 len = strnlen(ae->un.AttrString,
2101 sizeof(ae->un.AttrString));
2102 len += (len & 3) ? (4 - (len & 3)) : 4;
2103 size = FOURBYTES + len;
2104 ad->AttrLen = cpu_to_be16(size);
2105 ad->AttrType = cpu_to_be16(RHBA_MANUFACTURER);
2110 lpfc_fdmi_hba_attr_sn(struct lpfc_vport *vport, struct lpfc_fdmi_attr_def *ad)
2112 struct lpfc_hba *phba = vport->phba;
2113 struct lpfc_fdmi_attr_entry *ae;
2116 ae = &ad->AttrValue;
2117 memset(ae, 0, sizeof(*ae));
2119 strncpy(ae->un.AttrString, phba->SerialNumber,
2120 sizeof(ae->un.AttrString));
2121 len = strnlen(ae->un.AttrString,
2122 sizeof(ae->un.AttrString));
2123 len += (len & 3) ? (4 - (len & 3)) : 4;
2124 size = FOURBYTES + len;
2125 ad->AttrLen = cpu_to_be16(size);
2126 ad->AttrType = cpu_to_be16(RHBA_SERIAL_NUMBER);
2131 lpfc_fdmi_hba_attr_model(struct lpfc_vport *vport,
2132 struct lpfc_fdmi_attr_def *ad)
2134 struct lpfc_hba *phba = vport->phba;
2135 struct lpfc_fdmi_attr_entry *ae;
2138 ae = &ad->AttrValue;
2139 memset(ae, 0, sizeof(*ae));
2141 strncpy(ae->un.AttrString, phba->ModelName,
2142 sizeof(ae->un.AttrString));
2143 len = strnlen(ae->un.AttrString, sizeof(ae->un.AttrString));
2144 len += (len & 3) ? (4 - (len & 3)) : 4;
2145 size = FOURBYTES + len;
2146 ad->AttrLen = cpu_to_be16(size);
2147 ad->AttrType = cpu_to_be16(RHBA_MODEL);
2152 lpfc_fdmi_hba_attr_description(struct lpfc_vport *vport,
2153 struct lpfc_fdmi_attr_def *ad)
2155 struct lpfc_hba *phba = vport->phba;
2156 struct lpfc_fdmi_attr_entry *ae;
2159 ae = &ad->AttrValue;
2160 memset(ae, 0, sizeof(*ae));
2162 strncpy(ae->un.AttrString, phba->ModelDesc,
2163 sizeof(ae->un.AttrString));
2164 len = strnlen(ae->un.AttrString,
2165 sizeof(ae->un.AttrString));
2166 len += (len & 3) ? (4 - (len & 3)) : 4;
2167 size = FOURBYTES + len;
2168 ad->AttrLen = cpu_to_be16(size);
2169 ad->AttrType = cpu_to_be16(RHBA_MODEL_DESCRIPTION);
2174 lpfc_fdmi_hba_attr_hdw_ver(struct lpfc_vport *vport,
2175 struct lpfc_fdmi_attr_def *ad)
2177 struct lpfc_hba *phba = vport->phba;
2178 lpfc_vpd_t *vp = &phba->vpd;
2179 struct lpfc_fdmi_attr_entry *ae;
2180 uint32_t i, j, incr, size;
2182 ae = &ad->AttrValue;
2183 memset(ae, 0, sizeof(*ae));
2185 /* Convert JEDEC ID to ascii for hardware version */
2186 incr = vp->rev.biuRev;
2187 for (i = 0; i < 8; i++) {
2190 ae->un.AttrString[7 - i] =
2191 (char)((uint8_t) 0x30 +
2194 ae->un.AttrString[7 - i] =
2195 (char)((uint8_t) 0x61 +
2196 (uint8_t) (j - 10));
2199 size = FOURBYTES + 8;
2200 ad->AttrLen = cpu_to_be16(size);
2201 ad->AttrType = cpu_to_be16(RHBA_HARDWARE_VERSION);
2206 lpfc_fdmi_hba_attr_drvr_ver(struct lpfc_vport *vport,
2207 struct lpfc_fdmi_attr_def *ad)
2209 struct lpfc_fdmi_attr_entry *ae;
2212 ae = &ad->AttrValue;
2213 memset(ae, 0, sizeof(*ae));
2215 strncpy(ae->un.AttrString, lpfc_release_version,
2216 sizeof(ae->un.AttrString));
2217 len = strnlen(ae->un.AttrString,
2218 sizeof(ae->un.AttrString));
2219 len += (len & 3) ? (4 - (len & 3)) : 4;
2220 size = FOURBYTES + len;
2221 ad->AttrLen = cpu_to_be16(size);
2222 ad->AttrType = cpu_to_be16(RHBA_DRIVER_VERSION);
2227 lpfc_fdmi_hba_attr_rom_ver(struct lpfc_vport *vport,
2228 struct lpfc_fdmi_attr_def *ad)
2230 struct lpfc_hba *phba = vport->phba;
2231 struct lpfc_fdmi_attr_entry *ae;
2234 ae = &ad->AttrValue;
2235 memset(ae, 0, sizeof(*ae));
2237 if (phba->sli_rev == LPFC_SLI_REV4)
2238 lpfc_decode_firmware_rev(phba, ae->un.AttrString, 1);
2240 strncpy(ae->un.AttrString, phba->OptionROMVersion,
2241 sizeof(ae->un.AttrString));
2242 len = strnlen(ae->un.AttrString,
2243 sizeof(ae->un.AttrString));
2244 len += (len & 3) ? (4 - (len & 3)) : 4;
2245 size = FOURBYTES + len;
2246 ad->AttrLen = cpu_to_be16(size);
2247 ad->AttrType = cpu_to_be16(RHBA_OPTION_ROM_VERSION);
2252 lpfc_fdmi_hba_attr_fmw_ver(struct lpfc_vport *vport,
2253 struct lpfc_fdmi_attr_def *ad)
2255 struct lpfc_hba *phba = vport->phba;
2256 struct lpfc_fdmi_attr_entry *ae;
2259 ae = &ad->AttrValue;
2260 memset(ae, 0, sizeof(*ae));
2262 lpfc_decode_firmware_rev(phba, ae->un.AttrString, 1);
2263 len = strnlen(ae->un.AttrString,
2264 sizeof(ae->un.AttrString));
2265 len += (len & 3) ? (4 - (len & 3)) : 4;
2266 size = FOURBYTES + len;
2267 ad->AttrLen = cpu_to_be16(size);
2268 ad->AttrType = cpu_to_be16(RHBA_FIRMWARE_VERSION);
2273 lpfc_fdmi_hba_attr_os_ver(struct lpfc_vport *vport,
2274 struct lpfc_fdmi_attr_def *ad)
2276 struct lpfc_fdmi_attr_entry *ae;
2279 ae = &ad->AttrValue;
2280 memset(ae, 0, sizeof(*ae));
2282 snprintf(ae->un.AttrString, sizeof(ae->un.AttrString), "%s %s %s",
2283 init_utsname()->sysname,
2284 init_utsname()->release,
2285 init_utsname()->version);
2287 len = strnlen(ae->un.AttrString, sizeof(ae->un.AttrString));
2288 len += (len & 3) ? (4 - (len & 3)) : 4;
2289 size = FOURBYTES + len;
2290 ad->AttrLen = cpu_to_be16(size);
2291 ad->AttrType = cpu_to_be16(RHBA_OS_NAME_VERSION);
2296 lpfc_fdmi_hba_attr_ct_len(struct lpfc_vport *vport,
2297 struct lpfc_fdmi_attr_def *ad)
2299 struct lpfc_fdmi_attr_entry *ae;
2302 ae = &ad->AttrValue;
2304 ae->un.AttrInt = cpu_to_be32(LPFC_MAX_CT_SIZE);
2305 size = FOURBYTES + sizeof(uint32_t);
2306 ad->AttrLen = cpu_to_be16(size);
2307 ad->AttrType = cpu_to_be16(RHBA_MAX_CT_PAYLOAD_LEN);
2312 lpfc_fdmi_hba_attr_symbolic_name(struct lpfc_vport *vport,
2313 struct lpfc_fdmi_attr_def *ad)
2315 struct lpfc_fdmi_attr_entry *ae;
2318 ae = &ad->AttrValue;
2319 memset(ae, 0, sizeof(*ae));
2321 len = lpfc_vport_symbolic_node_name(vport,
2322 ae->un.AttrString, 256);
2323 len += (len & 3) ? (4 - (len & 3)) : 4;
2324 size = FOURBYTES + len;
2325 ad->AttrLen = cpu_to_be16(size);
2326 ad->AttrType = cpu_to_be16(RHBA_SYM_NODENAME);
2331 lpfc_fdmi_hba_attr_vendor_info(struct lpfc_vport *vport,
2332 struct lpfc_fdmi_attr_def *ad)
2334 struct lpfc_fdmi_attr_entry *ae;
2337 ae = &ad->AttrValue;
2339 /* Nothing is defined for this currently */
2340 ae->un.AttrInt = cpu_to_be32(0);
2341 size = FOURBYTES + sizeof(uint32_t);
2342 ad->AttrLen = cpu_to_be16(size);
2343 ad->AttrType = cpu_to_be16(RHBA_VENDOR_INFO);
2348 lpfc_fdmi_hba_attr_num_ports(struct lpfc_vport *vport,
2349 struct lpfc_fdmi_attr_def *ad)
2351 struct lpfc_fdmi_attr_entry *ae;
2354 ae = &ad->AttrValue;
2356 /* Each driver instance corresponds to a single port */
2357 ae->un.AttrInt = cpu_to_be32(1);
2358 size = FOURBYTES + sizeof(uint32_t);
2359 ad->AttrLen = cpu_to_be16(size);
2360 ad->AttrType = cpu_to_be16(RHBA_NUM_PORTS);
2365 lpfc_fdmi_hba_attr_fabric_wwnn(struct lpfc_vport *vport,
2366 struct lpfc_fdmi_attr_def *ad)
2368 struct lpfc_fdmi_attr_entry *ae;
2371 ae = &ad->AttrValue;
2372 memset(ae, 0, sizeof(*ae));
2374 memcpy(&ae->un.AttrWWN, &vport->fabric_nodename,
2375 sizeof(struct lpfc_name));
2376 size = FOURBYTES + sizeof(struct lpfc_name);
2377 ad->AttrLen = cpu_to_be16(size);
2378 ad->AttrType = cpu_to_be16(RHBA_FABRIC_WWNN);
2383 lpfc_fdmi_hba_attr_bios_ver(struct lpfc_vport *vport,
2384 struct lpfc_fdmi_attr_def *ad)
2386 struct lpfc_hba *phba = vport->phba;
2387 struct lpfc_fdmi_attr_entry *ae;
2390 ae = &ad->AttrValue;
2391 memset(ae, 0, sizeof(*ae));
2393 strlcat(ae->un.AttrString, phba->BIOSVersion,
2394 sizeof(ae->un.AttrString));
2395 len = strnlen(ae->un.AttrString,
2396 sizeof(ae->un.AttrString));
2397 len += (len & 3) ? (4 - (len & 3)) : 4;
2398 size = FOURBYTES + len;
2399 ad->AttrLen = cpu_to_be16(size);
2400 ad->AttrType = cpu_to_be16(RHBA_BIOS_VERSION);
2405 lpfc_fdmi_hba_attr_bios_state(struct lpfc_vport *vport,
2406 struct lpfc_fdmi_attr_def *ad)
2408 struct lpfc_fdmi_attr_entry *ae;
2411 ae = &ad->AttrValue;
2413 /* Driver doesn't have access to this information */
2414 ae->un.AttrInt = cpu_to_be32(0);
2415 size = FOURBYTES + sizeof(uint32_t);
2416 ad->AttrLen = cpu_to_be16(size);
2417 ad->AttrType = cpu_to_be16(RHBA_BIOS_STATE);
2422 lpfc_fdmi_hba_attr_vendor_id(struct lpfc_vport *vport,
2423 struct lpfc_fdmi_attr_def *ad)
2425 struct lpfc_fdmi_attr_entry *ae;
2428 ae = &ad->AttrValue;
2429 memset(ae, 0, sizeof(*ae));
2431 strncpy(ae->un.AttrString, "EMULEX",
2432 sizeof(ae->un.AttrString));
2433 len = strnlen(ae->un.AttrString,
2434 sizeof(ae->un.AttrString));
2435 len += (len & 3) ? (4 - (len & 3)) : 4;
2436 size = FOURBYTES + len;
2437 ad->AttrLen = cpu_to_be16(size);
2438 ad->AttrType = cpu_to_be16(RHBA_VENDOR_ID);
2442 /* Routines for all individual PORT attributes */
2444 lpfc_fdmi_port_attr_fc4type(struct lpfc_vport *vport,
2445 struct lpfc_fdmi_attr_def *ad)
2447 struct lpfc_hba *phba = vport->phba;
2448 struct lpfc_fdmi_attr_entry *ae;
2451 ae = &ad->AttrValue;
2452 memset(ae, 0, sizeof(*ae));
2454 ae->un.AttrTypes[2] = 0x01; /* Type 0x8 - FCP */
2455 ae->un.AttrTypes[7] = 0x01; /* Type 0x20 - CT */
2457 /* Check to see if Firmware supports NVME and on physical port */
2458 if ((phba->sli_rev == LPFC_SLI_REV4) && (vport == phba->pport) &&
2459 phba->sli4_hba.pc_sli4_params.nvme)
2460 ae->un.AttrTypes[6] = 0x01; /* Type 0x28 - NVME */
2462 size = FOURBYTES + 32;
2463 ad->AttrLen = cpu_to_be16(size);
2464 ad->AttrType = cpu_to_be16(RPRT_SUPPORTED_FC4_TYPES);
2469 lpfc_fdmi_port_attr_support_speed(struct lpfc_vport *vport,
2470 struct lpfc_fdmi_attr_def *ad)
2472 struct lpfc_hba *phba = vport->phba;
2473 struct lpfc_fdmi_attr_entry *ae;
2476 ae = &ad->AttrValue;
2479 if (!(phba->hba_flag & HBA_FCOE_MODE)) {
2480 if (phba->lmt & LMT_128Gb)
2481 ae->un.AttrInt |= HBA_PORTSPEED_128GFC;
2482 if (phba->lmt & LMT_64Gb)
2483 ae->un.AttrInt |= HBA_PORTSPEED_64GFC;
2484 if (phba->lmt & LMT_32Gb)
2485 ae->un.AttrInt |= HBA_PORTSPEED_32GFC;
2486 if (phba->lmt & LMT_16Gb)
2487 ae->un.AttrInt |= HBA_PORTSPEED_16GFC;
2488 if (phba->lmt & LMT_10Gb)
2489 ae->un.AttrInt |= HBA_PORTSPEED_10GFC;
2490 if (phba->lmt & LMT_8Gb)
2491 ae->un.AttrInt |= HBA_PORTSPEED_8GFC;
2492 if (phba->lmt & LMT_4Gb)
2493 ae->un.AttrInt |= HBA_PORTSPEED_4GFC;
2494 if (phba->lmt & LMT_2Gb)
2495 ae->un.AttrInt |= HBA_PORTSPEED_2GFC;
2496 if (phba->lmt & LMT_1Gb)
2497 ae->un.AttrInt |= HBA_PORTSPEED_1GFC;
2499 /* FCoE links support only one speed */
2500 switch (phba->fc_linkspeed) {
2501 case LPFC_ASYNC_LINK_SPEED_10GBPS:
2502 ae->un.AttrInt = HBA_PORTSPEED_10GE;
2504 case LPFC_ASYNC_LINK_SPEED_25GBPS:
2505 ae->un.AttrInt = HBA_PORTSPEED_25GE;
2507 case LPFC_ASYNC_LINK_SPEED_40GBPS:
2508 ae->un.AttrInt = HBA_PORTSPEED_40GE;
2510 case LPFC_ASYNC_LINK_SPEED_100GBPS:
2511 ae->un.AttrInt = HBA_PORTSPEED_100GE;
2515 ae->un.AttrInt = cpu_to_be32(ae->un.AttrInt);
2516 size = FOURBYTES + sizeof(uint32_t);
2517 ad->AttrLen = cpu_to_be16(size);
2518 ad->AttrType = cpu_to_be16(RPRT_SUPPORTED_SPEED);
2523 lpfc_fdmi_port_attr_speed(struct lpfc_vport *vport,
2524 struct lpfc_fdmi_attr_def *ad)
2526 struct lpfc_hba *phba = vport->phba;
2527 struct lpfc_fdmi_attr_entry *ae;
2530 ae = &ad->AttrValue;
2532 if (!(phba->hba_flag & HBA_FCOE_MODE)) {
2533 switch (phba->fc_linkspeed) {
2534 case LPFC_LINK_SPEED_1GHZ:
2535 ae->un.AttrInt = HBA_PORTSPEED_1GFC;
2537 case LPFC_LINK_SPEED_2GHZ:
2538 ae->un.AttrInt = HBA_PORTSPEED_2GFC;
2540 case LPFC_LINK_SPEED_4GHZ:
2541 ae->un.AttrInt = HBA_PORTSPEED_4GFC;
2543 case LPFC_LINK_SPEED_8GHZ:
2544 ae->un.AttrInt = HBA_PORTSPEED_8GFC;
2546 case LPFC_LINK_SPEED_10GHZ:
2547 ae->un.AttrInt = HBA_PORTSPEED_10GFC;
2549 case LPFC_LINK_SPEED_16GHZ:
2550 ae->un.AttrInt = HBA_PORTSPEED_16GFC;
2552 case LPFC_LINK_SPEED_32GHZ:
2553 ae->un.AttrInt = HBA_PORTSPEED_32GFC;
2555 case LPFC_LINK_SPEED_64GHZ:
2556 ae->un.AttrInt = HBA_PORTSPEED_64GFC;
2558 case LPFC_LINK_SPEED_128GHZ:
2559 ae->un.AttrInt = HBA_PORTSPEED_128GFC;
2562 ae->un.AttrInt = HBA_PORTSPEED_UNKNOWN;
2566 switch (phba->fc_linkspeed) {
2567 case LPFC_ASYNC_LINK_SPEED_10GBPS:
2568 ae->un.AttrInt = HBA_PORTSPEED_10GE;
2570 case LPFC_ASYNC_LINK_SPEED_25GBPS:
2571 ae->un.AttrInt = HBA_PORTSPEED_25GE;
2573 case LPFC_ASYNC_LINK_SPEED_40GBPS:
2574 ae->un.AttrInt = HBA_PORTSPEED_40GE;
2576 case LPFC_ASYNC_LINK_SPEED_100GBPS:
2577 ae->un.AttrInt = HBA_PORTSPEED_100GE;
2580 ae->un.AttrInt = HBA_PORTSPEED_UNKNOWN;
2585 ae->un.AttrInt = cpu_to_be32(ae->un.AttrInt);
2586 size = FOURBYTES + sizeof(uint32_t);
2587 ad->AttrLen = cpu_to_be16(size);
2588 ad->AttrType = cpu_to_be16(RPRT_PORT_SPEED);
2593 lpfc_fdmi_port_attr_max_frame(struct lpfc_vport *vport,
2594 struct lpfc_fdmi_attr_def *ad)
2596 struct serv_parm *hsp;
2597 struct lpfc_fdmi_attr_entry *ae;
2600 ae = &ad->AttrValue;
2602 hsp = (struct serv_parm *)&vport->fc_sparam;
2603 ae->un.AttrInt = (((uint32_t) hsp->cmn.bbRcvSizeMsb & 0x0F) << 8) |
2604 (uint32_t) hsp->cmn.bbRcvSizeLsb;
2605 ae->un.AttrInt = cpu_to_be32(ae->un.AttrInt);
2606 size = FOURBYTES + sizeof(uint32_t);
2607 ad->AttrLen = cpu_to_be16(size);
2608 ad->AttrType = cpu_to_be16(RPRT_MAX_FRAME_SIZE);
2613 lpfc_fdmi_port_attr_os_devname(struct lpfc_vport *vport,
2614 struct lpfc_fdmi_attr_def *ad)
2616 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2617 struct lpfc_fdmi_attr_entry *ae;
2620 ae = &ad->AttrValue;
2621 memset(ae, 0, sizeof(*ae));
2623 snprintf(ae->un.AttrString, sizeof(ae->un.AttrString),
2624 "/sys/class/scsi_host/host%d", shost->host_no);
2625 len = strnlen((char *)ae->un.AttrString,
2626 sizeof(ae->un.AttrString));
2627 len += (len & 3) ? (4 - (len & 3)) : 4;
2628 size = FOURBYTES + len;
2629 ad->AttrLen = cpu_to_be16(size);
2630 ad->AttrType = cpu_to_be16(RPRT_OS_DEVICE_NAME);
2635 lpfc_fdmi_port_attr_host_name(struct lpfc_vport *vport,
2636 struct lpfc_fdmi_attr_def *ad)
2638 struct lpfc_fdmi_attr_entry *ae;
2641 ae = &ad->AttrValue;
2642 memset(ae, 0, sizeof(*ae));
2644 scnprintf(ae->un.AttrString, sizeof(ae->un.AttrString), "%s",
2645 vport->phba->os_host_name);
2647 len = strnlen(ae->un.AttrString, sizeof(ae->un.AttrString));
2648 len += (len & 3) ? (4 - (len & 3)) : 4;
2649 size = FOURBYTES + len;
2650 ad->AttrLen = cpu_to_be16(size);
2651 ad->AttrType = cpu_to_be16(RPRT_HOST_NAME);
2656 lpfc_fdmi_port_attr_wwnn(struct lpfc_vport *vport,
2657 struct lpfc_fdmi_attr_def *ad)
2659 struct lpfc_fdmi_attr_entry *ae;
2662 ae = &ad->AttrValue;
2663 memset(ae, 0, sizeof(*ae));
2665 memcpy(&ae->un.AttrWWN, &vport->fc_sparam.nodeName,
2666 sizeof(struct lpfc_name));
2667 size = FOURBYTES + sizeof(struct lpfc_name);
2668 ad->AttrLen = cpu_to_be16(size);
2669 ad->AttrType = cpu_to_be16(RPRT_NODENAME);
2674 lpfc_fdmi_port_attr_wwpn(struct lpfc_vport *vport,
2675 struct lpfc_fdmi_attr_def *ad)
2677 struct lpfc_fdmi_attr_entry *ae;
2680 ae = &ad->AttrValue;
2681 memset(ae, 0, sizeof(*ae));
2683 memcpy(&ae->un.AttrWWN, &vport->fc_sparam.portName,
2684 sizeof(struct lpfc_name));
2685 size = FOURBYTES + sizeof(struct lpfc_name);
2686 ad->AttrLen = cpu_to_be16(size);
2687 ad->AttrType = cpu_to_be16(RPRT_PORTNAME);
2692 lpfc_fdmi_port_attr_symbolic_name(struct lpfc_vport *vport,
2693 struct lpfc_fdmi_attr_def *ad)
2695 struct lpfc_fdmi_attr_entry *ae;
2698 ae = &ad->AttrValue;
2699 memset(ae, 0, sizeof(*ae));
2701 len = lpfc_vport_symbolic_port_name(vport, ae->un.AttrString, 256);
2702 len += (len & 3) ? (4 - (len & 3)) : 4;
2703 size = FOURBYTES + len;
2704 ad->AttrLen = cpu_to_be16(size);
2705 ad->AttrType = cpu_to_be16(RPRT_SYM_PORTNAME);
2710 lpfc_fdmi_port_attr_port_type(struct lpfc_vport *vport,
2711 struct lpfc_fdmi_attr_def *ad)
2713 struct lpfc_hba *phba = vport->phba;
2714 struct lpfc_fdmi_attr_entry *ae;
2717 ae = &ad->AttrValue;
2718 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP)
2719 ae->un.AttrInt = cpu_to_be32(LPFC_FDMI_PORTTYPE_NLPORT);
2721 ae->un.AttrInt = cpu_to_be32(LPFC_FDMI_PORTTYPE_NPORT);
2722 size = FOURBYTES + sizeof(uint32_t);
2723 ad->AttrLen = cpu_to_be16(size);
2724 ad->AttrType = cpu_to_be16(RPRT_PORT_TYPE);
2729 lpfc_fdmi_port_attr_class(struct lpfc_vport *vport,
2730 struct lpfc_fdmi_attr_def *ad)
2732 struct lpfc_fdmi_attr_entry *ae;
2735 ae = &ad->AttrValue;
2736 ae->un.AttrInt = cpu_to_be32(FC_COS_CLASS2 | FC_COS_CLASS3);
2737 size = FOURBYTES + sizeof(uint32_t);
2738 ad->AttrLen = cpu_to_be16(size);
2739 ad->AttrType = cpu_to_be16(RPRT_SUPPORTED_CLASS);
2744 lpfc_fdmi_port_attr_fabric_wwpn(struct lpfc_vport *vport,
2745 struct lpfc_fdmi_attr_def *ad)
2747 struct lpfc_fdmi_attr_entry *ae;
2750 ae = &ad->AttrValue;
2751 memset(ae, 0, sizeof(*ae));
2753 memcpy(&ae->un.AttrWWN, &vport->fabric_portname,
2754 sizeof(struct lpfc_name));
2755 size = FOURBYTES + sizeof(struct lpfc_name);
2756 ad->AttrLen = cpu_to_be16(size);
2757 ad->AttrType = cpu_to_be16(RPRT_FABRICNAME);
2762 lpfc_fdmi_port_attr_active_fc4type(struct lpfc_vport *vport,
2763 struct lpfc_fdmi_attr_def *ad)
2765 struct lpfc_fdmi_attr_entry *ae;
2768 ae = &ad->AttrValue;
2769 memset(ae, 0, sizeof(*ae));
2771 ae->un.AttrTypes[2] = 0x01; /* Type 0x8 - FCP */
2772 ae->un.AttrTypes[7] = 0x01; /* Type 0x20 - CT */
2774 /* Check to see if NVME is configured or not */
2775 if (vport->phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)
2776 ae->un.AttrTypes[6] = 0x1; /* Type 0x28 - NVME */
2778 size = FOURBYTES + 32;
2779 ad->AttrLen = cpu_to_be16(size);
2780 ad->AttrType = cpu_to_be16(RPRT_ACTIVE_FC4_TYPES);
2785 lpfc_fdmi_port_attr_port_state(struct lpfc_vport *vport,
2786 struct lpfc_fdmi_attr_def *ad)
2788 struct lpfc_fdmi_attr_entry *ae;
2791 ae = &ad->AttrValue;
2792 /* Link Up - operational */
2793 ae->un.AttrInt = cpu_to_be32(LPFC_FDMI_PORTSTATE_ONLINE);
2794 size = FOURBYTES + sizeof(uint32_t);
2795 ad->AttrLen = cpu_to_be16(size);
2796 ad->AttrType = cpu_to_be16(RPRT_PORT_STATE);
2801 lpfc_fdmi_port_attr_num_disc(struct lpfc_vport *vport,
2802 struct lpfc_fdmi_attr_def *ad)
2804 struct lpfc_fdmi_attr_entry *ae;
2807 ae = &ad->AttrValue;
2808 vport->fdmi_num_disc = lpfc_find_map_node(vport);
2809 ae->un.AttrInt = cpu_to_be32(vport->fdmi_num_disc);
2810 size = FOURBYTES + sizeof(uint32_t);
2811 ad->AttrLen = cpu_to_be16(size);
2812 ad->AttrType = cpu_to_be16(RPRT_DISC_PORT);
2817 lpfc_fdmi_port_attr_nportid(struct lpfc_vport *vport,
2818 struct lpfc_fdmi_attr_def *ad)
2820 struct lpfc_fdmi_attr_entry *ae;
2823 ae = &ad->AttrValue;
2824 ae->un.AttrInt = cpu_to_be32(vport->fc_myDID);
2825 size = FOURBYTES + sizeof(uint32_t);
2826 ad->AttrLen = cpu_to_be16(size);
2827 ad->AttrType = cpu_to_be16(RPRT_PORT_ID);
2832 lpfc_fdmi_smart_attr_service(struct lpfc_vport *vport,
2833 struct lpfc_fdmi_attr_def *ad)
2835 struct lpfc_fdmi_attr_entry *ae;
2838 ae = &ad->AttrValue;
2839 memset(ae, 0, sizeof(*ae));
2841 strncpy(ae->un.AttrString, "Smart SAN Initiator",
2842 sizeof(ae->un.AttrString));
2843 len = strnlen(ae->un.AttrString,
2844 sizeof(ae->un.AttrString));
2845 len += (len & 3) ? (4 - (len & 3)) : 4;
2846 size = FOURBYTES + len;
2847 ad->AttrLen = cpu_to_be16(size);
2848 ad->AttrType = cpu_to_be16(RPRT_SMART_SERVICE);
2853 lpfc_fdmi_smart_attr_guid(struct lpfc_vport *vport,
2854 struct lpfc_fdmi_attr_def *ad)
2856 struct lpfc_fdmi_attr_entry *ae;
2859 ae = &ad->AttrValue;
2860 memset(ae, 0, sizeof(*ae));
2862 memcpy(&ae->un.AttrString, &vport->fc_sparam.nodeName,
2863 sizeof(struct lpfc_name));
2864 memcpy((((uint8_t *)&ae->un.AttrString) +
2865 sizeof(struct lpfc_name)),
2866 &vport->fc_sparam.portName, sizeof(struct lpfc_name));
2867 size = FOURBYTES + (2 * sizeof(struct lpfc_name));
2868 ad->AttrLen = cpu_to_be16(size);
2869 ad->AttrType = cpu_to_be16(RPRT_SMART_GUID);
2874 lpfc_fdmi_smart_attr_version(struct lpfc_vport *vport,
2875 struct lpfc_fdmi_attr_def *ad)
2877 struct lpfc_fdmi_attr_entry *ae;
2880 ae = &ad->AttrValue;
2881 memset(ae, 0, sizeof(*ae));
2883 strncpy(ae->un.AttrString, "Smart SAN Version 2.0",
2884 sizeof(ae->un.AttrString));
2885 len = strnlen(ae->un.AttrString,
2886 sizeof(ae->un.AttrString));
2887 len += (len & 3) ? (4 - (len & 3)) : 4;
2888 size = FOURBYTES + len;
2889 ad->AttrLen = cpu_to_be16(size);
2890 ad->AttrType = cpu_to_be16(RPRT_SMART_VERSION);
2895 lpfc_fdmi_smart_attr_model(struct lpfc_vport *vport,
2896 struct lpfc_fdmi_attr_def *ad)
2898 struct lpfc_hba *phba = vport->phba;
2899 struct lpfc_fdmi_attr_entry *ae;
2902 ae = &ad->AttrValue;
2903 memset(ae, 0, sizeof(*ae));
2905 strncpy(ae->un.AttrString, phba->ModelName,
2906 sizeof(ae->un.AttrString));
2907 len = strnlen(ae->un.AttrString, sizeof(ae->un.AttrString));
2908 len += (len & 3) ? (4 - (len & 3)) : 4;
2909 size = FOURBYTES + len;
2910 ad->AttrLen = cpu_to_be16(size);
2911 ad->AttrType = cpu_to_be16(RPRT_SMART_MODEL);
2916 lpfc_fdmi_smart_attr_port_info(struct lpfc_vport *vport,
2917 struct lpfc_fdmi_attr_def *ad)
2919 struct lpfc_fdmi_attr_entry *ae;
2922 ae = &ad->AttrValue;
2924 /* SRIOV (type 3) is not supported */
2926 ae->un.AttrInt = cpu_to_be32(2); /* NPIV */
2928 ae->un.AttrInt = cpu_to_be32(1); /* Physical */
2929 size = FOURBYTES + sizeof(uint32_t);
2930 ad->AttrLen = cpu_to_be16(size);
2931 ad->AttrType = cpu_to_be16(RPRT_SMART_PORT_INFO);
2936 lpfc_fdmi_smart_attr_qos(struct lpfc_vport *vport,
2937 struct lpfc_fdmi_attr_def *ad)
2939 struct lpfc_fdmi_attr_entry *ae;
2942 ae = &ad->AttrValue;
2943 ae->un.AttrInt = cpu_to_be32(0);
2944 size = FOURBYTES + sizeof(uint32_t);
2945 ad->AttrLen = cpu_to_be16(size);
2946 ad->AttrType = cpu_to_be16(RPRT_SMART_QOS);
2951 lpfc_fdmi_smart_attr_security(struct lpfc_vport *vport,
2952 struct lpfc_fdmi_attr_def *ad)
2954 struct lpfc_fdmi_attr_entry *ae;
2957 ae = &ad->AttrValue;
2958 ae->un.AttrInt = cpu_to_be32(1);
2959 size = FOURBYTES + sizeof(uint32_t);
2960 ad->AttrLen = cpu_to_be16(size);
2961 ad->AttrType = cpu_to_be16(RPRT_SMART_SECURITY);
2965 /* RHBA attribute jump table */
2966 int (*lpfc_fdmi_hba_action[])
2967 (struct lpfc_vport *vport, struct lpfc_fdmi_attr_def *ad) = {
2968 /* Action routine Mask bit Attribute type */
2969 lpfc_fdmi_hba_attr_wwnn, /* bit0 RHBA_NODENAME */
2970 lpfc_fdmi_hba_attr_manufacturer, /* bit1 RHBA_MANUFACTURER */
2971 lpfc_fdmi_hba_attr_sn, /* bit2 RHBA_SERIAL_NUMBER */
2972 lpfc_fdmi_hba_attr_model, /* bit3 RHBA_MODEL */
2973 lpfc_fdmi_hba_attr_description, /* bit4 RHBA_MODEL_DESCRIPTION */
2974 lpfc_fdmi_hba_attr_hdw_ver, /* bit5 RHBA_HARDWARE_VERSION */
2975 lpfc_fdmi_hba_attr_drvr_ver, /* bit6 RHBA_DRIVER_VERSION */
2976 lpfc_fdmi_hba_attr_rom_ver, /* bit7 RHBA_OPTION_ROM_VERSION */
2977 lpfc_fdmi_hba_attr_fmw_ver, /* bit8 RHBA_FIRMWARE_VERSION */
2978 lpfc_fdmi_hba_attr_os_ver, /* bit9 RHBA_OS_NAME_VERSION */
2979 lpfc_fdmi_hba_attr_ct_len, /* bit10 RHBA_MAX_CT_PAYLOAD_LEN */
2980 lpfc_fdmi_hba_attr_symbolic_name, /* bit11 RHBA_SYM_NODENAME */
2981 lpfc_fdmi_hba_attr_vendor_info, /* bit12 RHBA_VENDOR_INFO */
2982 lpfc_fdmi_hba_attr_num_ports, /* bit13 RHBA_NUM_PORTS */
2983 lpfc_fdmi_hba_attr_fabric_wwnn, /* bit14 RHBA_FABRIC_WWNN */
2984 lpfc_fdmi_hba_attr_bios_ver, /* bit15 RHBA_BIOS_VERSION */
2985 lpfc_fdmi_hba_attr_bios_state, /* bit16 RHBA_BIOS_STATE */
2986 lpfc_fdmi_hba_attr_vendor_id, /* bit17 RHBA_VENDOR_ID */
2989 /* RPA / RPRT attribute jump table */
2990 int (*lpfc_fdmi_port_action[])
2991 (struct lpfc_vport *vport, struct lpfc_fdmi_attr_def *ad) = {
2992 /* Action routine Mask bit Attribute type */
2993 lpfc_fdmi_port_attr_fc4type, /* bit0 RPRT_SUPPORT_FC4_TYPES */
2994 lpfc_fdmi_port_attr_support_speed, /* bit1 RPRT_SUPPORTED_SPEED */
2995 lpfc_fdmi_port_attr_speed, /* bit2 RPRT_PORT_SPEED */
2996 lpfc_fdmi_port_attr_max_frame, /* bit3 RPRT_MAX_FRAME_SIZE */
2997 lpfc_fdmi_port_attr_os_devname, /* bit4 RPRT_OS_DEVICE_NAME */
2998 lpfc_fdmi_port_attr_host_name, /* bit5 RPRT_HOST_NAME */
2999 lpfc_fdmi_port_attr_wwnn, /* bit6 RPRT_NODENAME */
3000 lpfc_fdmi_port_attr_wwpn, /* bit7 RPRT_PORTNAME */
3001 lpfc_fdmi_port_attr_symbolic_name, /* bit8 RPRT_SYM_PORTNAME */
3002 lpfc_fdmi_port_attr_port_type, /* bit9 RPRT_PORT_TYPE */
3003 lpfc_fdmi_port_attr_class, /* bit10 RPRT_SUPPORTED_CLASS */
3004 lpfc_fdmi_port_attr_fabric_wwpn, /* bit11 RPRT_FABRICNAME */
3005 lpfc_fdmi_port_attr_active_fc4type, /* bit12 RPRT_ACTIVE_FC4_TYPES */
3006 lpfc_fdmi_port_attr_port_state, /* bit13 RPRT_PORT_STATE */
3007 lpfc_fdmi_port_attr_num_disc, /* bit14 RPRT_DISC_PORT */
3008 lpfc_fdmi_port_attr_nportid, /* bit15 RPRT_PORT_ID */
3009 lpfc_fdmi_smart_attr_service, /* bit16 RPRT_SMART_SERVICE */
3010 lpfc_fdmi_smart_attr_guid, /* bit17 RPRT_SMART_GUID */
3011 lpfc_fdmi_smart_attr_version, /* bit18 RPRT_SMART_VERSION */
3012 lpfc_fdmi_smart_attr_model, /* bit19 RPRT_SMART_MODEL */
3013 lpfc_fdmi_smart_attr_port_info, /* bit20 RPRT_SMART_PORT_INFO */
3014 lpfc_fdmi_smart_attr_qos, /* bit21 RPRT_SMART_QOS */
3015 lpfc_fdmi_smart_attr_security, /* bit22 RPRT_SMART_SECURITY */
3019 * lpfc_fdmi_cmd - Build and send a FDMI cmd to the specified NPort
3020 * @vport: pointer to a host virtual N_Port data structure.
3021 * @ndlp: ndlp to send FDMI cmd to (if NULL use FDMI_DID)
3022 * cmdcode: FDMI command to send
3023 * mask: Mask of HBA or PORT Attributes to send
3025 * Builds and sends a FDMI command using the CT subsystem.
3028 lpfc_fdmi_cmd(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
3029 int cmdcode, uint32_t new_mask)
3031 struct lpfc_hba *phba = vport->phba;
3032 struct lpfc_dmabuf *mp, *bmp;
3033 struct lpfc_sli_ct_request *CtReq;
3034 struct ulp_bde64 *bpl;
3039 struct lpfc_fdmi_reg_hba *rh;
3040 struct lpfc_fdmi_port_entry *pe;
3041 struct lpfc_fdmi_reg_portattr *pab = NULL;
3042 struct lpfc_fdmi_attr_block *ab = NULL;
3043 int (*func)(struct lpfc_vport *vport, struct lpfc_fdmi_attr_def *ad);
3044 void (*cmpl)(struct lpfc_hba *, struct lpfc_iocbq *,
3045 struct lpfc_iocbq *);
3047 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
3050 cmpl = lpfc_cmpl_ct_disc_fdmi; /* called from discovery */
3052 /* fill in BDEs for command */
3053 /* Allocate buffer for command payload */
3054 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
3058 mp->virt = lpfc_mbuf_alloc(phba, 0, &(mp->phys));
3060 goto fdmi_cmd_free_mp;
3062 /* Allocate buffer for Buffer ptr list */
3063 bmp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
3065 goto fdmi_cmd_free_mpvirt;
3067 bmp->virt = lpfc_mbuf_alloc(phba, 0, &(bmp->phys));
3069 goto fdmi_cmd_free_bmp;
3071 INIT_LIST_HEAD(&mp->list);
3072 INIT_LIST_HEAD(&bmp->list);
3075 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
3076 "0218 FDMI Request Data: x%x x%x x%x\n",
3077 vport->fc_flag, vport->port_state, cmdcode);
3078 CtReq = (struct lpfc_sli_ct_request *)mp->virt;
3080 /* First populate the CT_IU preamble */
3081 memset(CtReq, 0, sizeof(struct lpfc_sli_ct_request));
3082 CtReq->RevisionId.bits.Revision = SLI_CT_REVISION;
3083 CtReq->RevisionId.bits.InId = 0;
3085 CtReq->FsType = SLI_CT_MANAGEMENT_SERVICE;
3086 CtReq->FsSubType = SLI_CT_FDMI_Subtypes;
3088 CtReq->CommandResponse.bits.CmdRsp = cpu_to_be16(cmdcode);
3089 rsp_size = LPFC_BPL_SIZE;
3092 /* Next fill in the specific FDMI cmd information */
3096 rh = (struct lpfc_fdmi_reg_hba *)&CtReq->un.PortID;
3097 /* HBA Identifier */
3098 memcpy(&rh->hi.PortName, &phba->pport->fc_sparam.portName,
3099 sizeof(struct lpfc_name));
3101 if (cmdcode == SLI_MGMT_RHBA) {
3102 /* Registered Port List */
3103 /* One entry (port) per adapter */
3104 rh->rpl.EntryCnt = cpu_to_be32(1);
3105 memcpy(&rh->rpl.pe.PortName,
3106 &phba->pport->fc_sparam.portName,
3107 sizeof(struct lpfc_name));
3109 /* point to the HBA attribute block */
3110 size = 2 * sizeof(struct lpfc_name) +
3113 size = sizeof(struct lpfc_name);
3115 ab = (struct lpfc_fdmi_attr_block *)((uint8_t *)rh + size);
3122 mask = vport->fdmi_hba_mask;
3124 /* Mask will dictate what attributes to build in the request */
3127 func = lpfc_fdmi_hba_action[bit_pos];
3129 (struct lpfc_fdmi_attr_def *)
3130 ((uint8_t *)rh + size));
3133 (LPFC_BPL_SIZE - LPFC_CT_PREAMBLE))
3140 ab->EntryCnt = cpu_to_be32(ab->EntryCnt);
3142 size = GID_REQUEST_SZ - 4 + size;
3147 pab = (struct lpfc_fdmi_reg_portattr *)&CtReq->un.PortID;
3148 if (cmdcode == SLI_MGMT_RPRT) {
3149 rh = (struct lpfc_fdmi_reg_hba *)pab;
3150 /* HBA Identifier */
3151 memcpy(&rh->hi.PortName,
3152 &phba->pport->fc_sparam.portName,
3153 sizeof(struct lpfc_name));
3154 pab = (struct lpfc_fdmi_reg_portattr *)
3155 ((uint8_t *)pab + sizeof(struct lpfc_name));
3158 memcpy((uint8_t *)&pab->PortName,
3159 (uint8_t *)&vport->fc_sparam.portName,
3160 sizeof(struct lpfc_name));
3161 size += sizeof(struct lpfc_name) + FOURBYTES;
3162 pab->ab.EntryCnt = 0;
3167 mask = vport->fdmi_port_mask;
3169 /* Mask will dictate what attributes to build in the request */
3172 func = lpfc_fdmi_port_action[bit_pos];
3174 (struct lpfc_fdmi_attr_def *)
3175 ((uint8_t *)pab + size));
3178 (LPFC_BPL_SIZE - LPFC_CT_PREAMBLE))
3185 pab->ab.EntryCnt = cpu_to_be32(pab->ab.EntryCnt);
3187 if (cmdcode == SLI_MGMT_RPRT)
3188 size += sizeof(struct lpfc_name);
3189 size = GID_REQUEST_SZ - 4 + size;
3194 rsp_size = FC_MAX_NS_RSP;
3198 pe = (struct lpfc_fdmi_port_entry *)&CtReq->un.PortID;
3199 memcpy((uint8_t *)&pe->PortName,
3200 (uint8_t *)&vport->fc_sparam.portName,
3201 sizeof(struct lpfc_name));
3202 size = GID_REQUEST_SZ - 4 + sizeof(struct lpfc_name);
3207 rsp_size = FC_MAX_NS_RSP;
3211 pe = (struct lpfc_fdmi_port_entry *)&CtReq->un.PortID;
3212 memcpy((uint8_t *)&pe->PortName,
3213 (uint8_t *)&vport->fc_sparam.portName,
3214 sizeof(struct lpfc_name));
3215 size = GID_REQUEST_SZ - 4 + sizeof(struct lpfc_name);
3218 size = GID_REQUEST_SZ - 4;
3221 lpfc_printf_vlog(vport, KERN_WARNING, LOG_DISCOVERY,
3222 "0298 FDMI cmdcode x%x not supported\n",
3224 goto fdmi_cmd_free_bmpvirt;
3226 CtReq->CommandResponse.bits.Size = cpu_to_be16(rsp_size);
3228 bpl = (struct ulp_bde64 *)bmp->virt;
3229 bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys));
3230 bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys));
3231 bpl->tus.f.bdeFlags = 0;
3232 bpl->tus.f.bdeSize = size;
3235 * The lpfc_ct_cmd/lpfc_get_req shall increment ndlp reference count
3236 * to hold ndlp reference for the corresponding callback function.
3238 if (!lpfc_ct_cmd(vport, mp, bmp, ndlp, cmpl, rsp_size, 0))
3242 * Decrement ndlp reference count to release ndlp reference held
3243 * for the failed command's callback function.
3247 fdmi_cmd_free_bmpvirt:
3248 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
3251 fdmi_cmd_free_mpvirt:
3252 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3256 /* Issue FDMI request failed */
3257 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
3258 "0244 Issue FDMI request failed Data: x%x\n",
3264 * lpfc_delayed_disc_tmo - Timeout handler for delayed discovery timer.
3265 * @ptr - Context object of the timer.
3267 * This function set the WORKER_DELAYED_DISC_TMO flag and wake up
3268 * the worker thread.
3271 lpfc_delayed_disc_tmo(struct timer_list *t)
3273 struct lpfc_vport *vport = from_timer(vport, t, delayed_disc_tmo);
3274 struct lpfc_hba *phba = vport->phba;
3275 uint32_t tmo_posted;
3276 unsigned long iflag;
3278 spin_lock_irqsave(&vport->work_port_lock, iflag);
3279 tmo_posted = vport->work_port_events & WORKER_DELAYED_DISC_TMO;
3281 vport->work_port_events |= WORKER_DELAYED_DISC_TMO;
3282 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
3285 lpfc_worker_wake_up(phba);
3290 * lpfc_delayed_disc_timeout_handler - Function called by worker thread to
3291 * handle delayed discovery.
3292 * @vport: pointer to a host virtual N_Port data structure.
3294 * This function start nport discovery of the vport.
3297 lpfc_delayed_disc_timeout_handler(struct lpfc_vport *vport)
3299 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3301 spin_lock_irq(shost->host_lock);
3302 if (!(vport->fc_flag & FC_DISC_DELAYED)) {
3303 spin_unlock_irq(shost->host_lock);
3306 vport->fc_flag &= ~FC_DISC_DELAYED;
3307 spin_unlock_irq(shost->host_lock);
3309 lpfc_do_scr_ns_plogi(vport->phba, vport);
3313 lpfc_decode_firmware_rev(struct lpfc_hba *phba, char *fwrevision, int flag)
3315 struct lpfc_sli *psli = &phba->sli;
3316 lpfc_vpd_t *vp = &phba->vpd;
3317 uint32_t b1, b2, b3, b4, i, rev;
3319 uint32_t *ptr, str[4];
3322 if (phba->sli_rev == LPFC_SLI_REV4)
3323 snprintf(fwrevision, FW_REV_STR_SIZE, "%s", vp->rev.opFwName);
3324 else if (vp->rev.rBit) {
3325 if (psli->sli_flag & LPFC_SLI_ACTIVE)
3326 rev = vp->rev.sli2FwRev;
3328 rev = vp->rev.sli1FwRev;
3330 b1 = (rev & 0x0000f000) >> 12;
3331 b2 = (rev & 0x00000f00) >> 8;
3332 b3 = (rev & 0x000000c0) >> 6;
3333 b4 = (rev & 0x00000030) >> 4;
3352 b4 = (rev & 0x0000000f);
3354 if (psli->sli_flag & LPFC_SLI_ACTIVE)
3355 fwname = vp->rev.sli2FwName;
3357 fwname = vp->rev.sli1FwName;
3359 for (i = 0; i < 16; i++)
3360 if (fwname[i] == 0x20)
3363 ptr = (uint32_t*)fwname;
3365 for (i = 0; i < 3; i++)
3366 str[i] = be32_to_cpu(*ptr++);
3370 sprintf(fwrevision, "%d.%d%d (%s)",
3371 b1, b2, b3, (char *)str);
3373 sprintf(fwrevision, "%d.%d%d", b1,
3377 sprintf(fwrevision, "%d.%d%d%c%d (%s)",
3381 sprintf(fwrevision, "%d.%d%d%c%d",
3385 rev = vp->rev.smFwRev;
3387 b1 = (rev & 0xff000000) >> 24;
3388 b2 = (rev & 0x00f00000) >> 20;
3389 b3 = (rev & 0x000f0000) >> 16;
3390 c = (rev & 0x0000ff00) >> 8;
3391 b4 = (rev & 0x000000ff);
3393 sprintf(fwrevision, "%d.%d%d%c%d", b1, b2, b3, c, b4);