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_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"
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 */
78 static char *lpfc_release_version = LPFC_DRIVER_VERSION;
81 lpfc_ct_ignore_hbq_buffer(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq,
82 struct lpfc_dmabuf *mp, uint32_t size)
85 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
86 "0146 Ignoring unsolicited CT No HBQ "
88 piocbq->iocb.ulpStatus);
90 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
91 "0145 Ignoring unsolicted CT HBQ Size:%d "
93 size, piocbq->iocb.ulpStatus);
97 lpfc_ct_unsol_buffer(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq,
98 struct lpfc_dmabuf *mp, uint32_t size)
100 lpfc_ct_ignore_hbq_buffer(phba, piocbq, mp, size);
104 lpfc_ct_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
105 struct lpfc_iocbq *piocbq)
107 struct lpfc_dmabuf *mp = NULL;
108 IOCB_t *icmd = &piocbq->iocb;
110 struct lpfc_iocbq *iocbq;
113 struct list_head head;
114 struct lpfc_dmabuf *bdeBuf;
116 if (lpfc_bsg_ct_unsol_event(phba, pring, piocbq) == 0)
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);
131 /* If there are no BDEs associated with this IOCB,
132 * there is nothing to do.
134 if (icmd->ulpBdeCount == 0)
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) {
142 if (icmd->ulpBdeCount == 0)
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,
155 lpfc_in_buf_free(phba, bdeBuf);
160 INIT_LIST_HEAD(&head);
161 list_add_tail(&head, &piocbq->list);
162 list_for_each_entry(iocbq, &head, list) {
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,
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);
175 lpfc_post_buffer(phba, pring, i);
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
186 * This function serves as the upper level protocol abort handler for CT
189 * Return 1 if abort has been handled, 0 otherwise.
192 lpfc_ct_handle_unsol_abort(struct lpfc_hba *phba, struct hbq_dmabuf *dmabuf)
196 /* CT upper level goes through BSG */
197 handled = lpfc_bsg_ct_unsol_abort(phba, dmabuf);
203 lpfc_free_ct_rsp(struct lpfc_hba *phba, struct lpfc_dmabuf *mlist)
205 struct lpfc_dmabuf *mlast, *next_mlast;
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);
212 lpfc_mbuf_free(phba, mlist->virt, mlist->phys);
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)
221 struct lpfc_dmabuf *mlist = NULL;
222 struct lpfc_dmabuf *mp;
225 /* We get chunks of FCELSSIZE */
226 cnt = size > FCELSSIZE ? FCELSSIZE: size;
229 /* Allocate buffer for rsp payload */
230 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
233 lpfc_free_ct_rsp(phba, mlist);
237 INIT_LIST_HEAD(&mp->list);
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));
243 mp->virt = lpfc_mbuf_alloc(phba, 0, &(mp->phys));
248 lpfc_free_ct_rsp(phba, mlist);
252 /* Queue it to a linked list */
256 list_add_tail(&mp->list, &mlist->list);
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);
275 lpfc_ct_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *ctiocb)
277 struct lpfc_dmabuf *buf_ptr;
279 if (ctiocb->context_un.ndlp) {
280 lpfc_nlp_put(ctiocb->context_un.ndlp);
281 ctiocb->context_un.ndlp = NULL;
283 if (ctiocb->context1) {
284 buf_ptr = (struct lpfc_dmabuf *) ctiocb->context1;
285 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
287 ctiocb->context1 = NULL;
289 if (ctiocb->context2) {
290 lpfc_free_ct_rsp(phba, (struct lpfc_dmabuf *) ctiocb->context2);
291 ctiocb->context2 = NULL;
294 if (ctiocb->context3) {
295 buf_ptr = (struct lpfc_dmabuf *) ctiocb->context3;
296 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
298 ctiocb->context3 = NULL;
300 lpfc_sli_release_iocbq(phba, ctiocb);
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
313 * This function as the final part for issuing a CT command.
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)
323 struct lpfc_hba *phba = vport->phba;
325 struct lpfc_iocbq *geniocb;
328 /* Allocate buffer for command iocb */
329 geniocb = lpfc_sli_get_iocbq(phba);
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));
342 geniocb->context3 = NULL;
344 geniocb->context3 = (uint8_t *) bmp;
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);
351 /* Fill in payload, bp points to frame payload */
352 icmd->ulpCommand = CMD_GEN_REQUEST64_CR;
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;
361 /* FC spec states we need 3 * ratov for CT requests */
362 tmo = (3 * phba->fc_ratov);
364 icmd->ulpTimeout = tmo;
365 icmd->ulpBdeCount = 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];
372 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
373 /* For GEN_REQUEST64_CR, use the RPI */
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 "
382 ndlp->nlp_DID, icmd->ulpIoTag,
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);
390 if (rc == IOCB_ERROR) {
391 lpfc_sli_release_iocbq(phba, geniocb);
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
406 * This function is called for issuing a CT command.
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)
415 struct lpfc_hba *phba = vport->phba;
416 struct ulp_bde64 *bpl = (struct ulp_bde64 *) bmp->virt;
417 struct lpfc_dmabuf *outmp;
419 int cmdcode = ((struct lpfc_sli_ct_request *) inmp->virt)->
420 CommandResponse.bits.CmdRsp;
422 bpl++; /* Skip past ct request */
424 /* Put buffer(s) for ct rsp in bpl */
425 outmp = lpfc_alloc_ct_rsp(phba, cmdcode, bpl, rsp_size, &cnt);
429 * Form the CT IOCB. The total number of BDEs in this IOCB
430 * is the single command plus response count from
434 status = lpfc_gen_req(vport, bmp, inmp, outmp, cmpl, ndlp, 0,
437 lpfc_free_ct_rsp(phba, outmp);
444 lpfc_find_vport_by_did(struct lpfc_hba *phba, uint32_t did) {
445 struct lpfc_vport *vport_curr;
448 spin_lock_irqsave(&phba->port_list_lock, 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->port_list_lock, flags);
455 spin_unlock_irqrestore(&phba->port_list_lock, flags);
460 lpfc_prep_node_fc4type(struct lpfc_vport *vport, uint32_t Did, uint8_t fc4_type)
462 struct lpfc_nodelist *ndlp;
464 if ((vport->port_type != LPFC_NPIV_PORT) ||
465 (fc4_type == FC_TYPE_FCP) ||
466 !(vport->ct_flags & FC_CT_RFF_ID) || !vport->cfg_restrict_login) {
468 ndlp = lpfc_setup_disc_node(vport, Did);
470 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
471 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
472 "Parse GID_FTrsp: did:x%x flg:x%x x%x",
473 Did, ndlp->nlp_flag, vport->fc_flag);
475 /* By default, the driver expects to support FCP FC4 */
476 if (fc4_type == FC_TYPE_FCP)
477 ndlp->nlp_fc4_type |= NLP_FC4_FCP;
479 if (fc4_type == FC_TYPE_NVME)
480 ndlp->nlp_fc4_type |= NLP_FC4_NVME;
482 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
483 "0238 Process x%06x NameServer Rsp "
484 "Data: x%x x%x x%x x%x x%x\n", Did,
485 ndlp->nlp_flag, ndlp->nlp_fc4_type,
486 ndlp->nlp_state, vport->fc_flag,
487 vport->fc_rscn_id_cnt);
489 /* if ndlp needs to be discovered and prior
490 * state of ndlp hit devloss, change state to
493 if (ndlp->nlp_flag & NLP_NPR_2B_DISC &&
494 ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
495 lpfc_nlp_set_state(vport, ndlp,
499 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
500 "Skip1 GID_FTrsp: did:x%x flg:x%x cnt:%d",
501 Did, vport->fc_flag, vport->fc_rscn_id_cnt);
503 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
504 "0239 Skip x%06x NameServer Rsp "
505 "Data: x%x x%x %p\n",
507 vport->fc_rscn_id_cnt, ndlp);
510 if (!(vport->fc_flag & FC_RSCN_MODE) ||
511 lpfc_rscn_payload_check(vport, Did)) {
512 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
513 "Query GID_FTrsp: did:x%x flg:x%x cnt:%d",
514 Did, vport->fc_flag, vport->fc_rscn_id_cnt);
517 * This NPortID was previously a FCP/NVMe target,
518 * Don't even bother to send GFF_ID.
520 ndlp = lpfc_findnode_did(vport, Did);
521 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
523 (NLP_FCP_TARGET | NLP_NVME_TARGET))) {
524 if (fc4_type == FC_TYPE_FCP)
525 ndlp->nlp_fc4_type |= NLP_FC4_FCP;
526 if (fc4_type == FC_TYPE_NVME)
527 ndlp->nlp_fc4_type |= NLP_FC4_NVME;
528 lpfc_setup_disc_node(vport, Did);
529 } else if (lpfc_ns_cmd(vport, SLI_CTNS_GFF_ID,
531 vport->num_disc_nodes++;
533 lpfc_setup_disc_node(vport, Did);
535 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
536 "Skip2 GID_FTrsp: did:x%x flg:x%x cnt:%d",
537 Did, vport->fc_flag, vport->fc_rscn_id_cnt);
539 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
540 "0245 Skip x%06x NameServer Rsp "
541 "Data: x%x x%x\n", Did,
543 vport->fc_rscn_id_cnt);
549 lpfc_ns_rsp_audit_did(struct lpfc_vport *vport, uint32_t Did, uint8_t fc4_type)
551 struct lpfc_hba *phba = vport->phba;
552 struct lpfc_nodelist *ndlp = NULL;
553 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
556 if (phba->cfg_ns_query == LPFC_NS_QUERY_GID_FT)
560 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
561 "6430 Process %s rsp for %08x type %x %s %s\n",
563 (fc4_type == FC_TYPE_FCP) ? "FCP" : " ",
564 (fc4_type == FC_TYPE_NVME) ? "NVME" : " ");
566 * To conserve rpi's, filter out addresses for other
567 * vports on the same physical HBAs.
569 if (Did != vport->fc_myDID &&
570 (!lpfc_find_vport_by_did(phba, Did) ||
571 vport->cfg_peer_port_login)) {
572 if (!phba->nvmet_support) {
573 /* FCPI/NVMEI path. Process Did */
574 lpfc_prep_node_fc4type(vport, Did, fc4_type);
577 /* NVMET path. NVMET only cares about NVMEI nodes. */
578 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
579 if (ndlp->nlp_type != NLP_NVME_INITIATOR ||
580 ndlp->nlp_state != NLP_STE_UNMAPPED_NODE)
582 spin_lock_irq(shost->host_lock);
583 if (ndlp->nlp_DID == Did)
584 ndlp->nlp_flag &= ~NLP_NVMET_RECOV;
586 ndlp->nlp_flag |= NLP_NVMET_RECOV;
587 spin_unlock_irq(shost->host_lock);
593 lpfc_ns_rsp(struct lpfc_vport *vport, struct lpfc_dmabuf *mp, uint8_t fc4_type,
596 struct lpfc_sli_ct_request *Response =
597 (struct lpfc_sli_ct_request *) mp->virt;
598 struct lpfc_dmabuf *mlast, *next_mp;
599 uint32_t *ctptr = (uint32_t *) & Response->un.gid.PortType;
600 uint32_t Did, CTentry;
602 struct list_head head;
603 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
604 struct lpfc_nodelist *ndlp = NULL;
606 lpfc_set_disctmo(vport);
607 vport->num_disc_nodes = 0;
608 vport->fc_ns_retry = 0;
611 list_add_tail(&head, &mp->list);
612 list_for_each_entry_safe(mp, next_mp, &head, list) {
615 Cnt = Size > FCELSSIZE ? FCELSSIZE : Size;
620 ctptr = (uint32_t *) mlast->virt;
622 Cnt -= 16; /* subtract length of CT header */
624 /* Loop through entire NameServer list of DIDs */
625 while (Cnt >= sizeof(uint32_t)) {
626 /* Get next DID from NameServer List */
628 Did = ((be32_to_cpu(CTentry)) & Mask_DID);
629 lpfc_ns_rsp_audit_did(vport, Did, fc4_type);
630 if (CTentry & (cpu_to_be32(SLI_CT_LAST_ENTRY)))
633 Cnt -= sizeof(uint32_t);
639 /* All GID_FT entries processed. If the driver is running in
640 * in target mode, put impacted nodes into recovery and drop
641 * the RPI to flush outstanding IO.
643 if (vport->phba->nvmet_support) {
644 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
645 if (!(ndlp->nlp_flag & NLP_NVMET_RECOV))
647 lpfc_disc_state_machine(vport, ndlp, NULL,
648 NLP_EVT_DEVICE_RECOVERY);
649 spin_lock_irq(shost->host_lock);
650 ndlp->nlp_flag &= ~NLP_NVMET_RECOV;
651 spin_unlock_irq(shost->host_lock);
661 lpfc_cmpl_ct_cmd_gid_ft(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
662 struct lpfc_iocbq *rspiocb)
664 struct lpfc_vport *vport = cmdiocb->vport;
665 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
667 struct lpfc_dmabuf *outp;
668 struct lpfc_dmabuf *inp;
669 struct lpfc_sli_ct_request *CTrsp;
670 struct lpfc_sli_ct_request *CTreq;
671 struct lpfc_nodelist *ndlp;
674 /* First save ndlp, before we overwrite it */
675 ndlp = cmdiocb->context_un.ndlp;
677 /* we pass cmdiocb to state machine which needs rspiocb as well */
678 cmdiocb->context_un.rsp_iocb = rspiocb;
679 inp = (struct lpfc_dmabuf *) cmdiocb->context1;
680 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
681 irsp = &rspiocb->iocb;
683 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
684 "GID_FT cmpl: status:x%x/x%x rtry:%d",
685 irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_ns_retry);
687 /* Don't bother processing response if vport is being torn down. */
688 if (vport->load_flag & FC_UNLOADING) {
689 if (vport->fc_flag & FC_RSCN_MODE)
690 lpfc_els_flush_rscn(vport);
694 if (lpfc_els_chk_latt(vport)) {
695 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
696 "0216 Link event during NS query\n");
697 if (vport->fc_flag & FC_RSCN_MODE)
698 lpfc_els_flush_rscn(vport);
699 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
702 if (lpfc_error_lost_link(irsp)) {
703 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
704 "0226 NS query failed due to link event\n");
705 if (vport->fc_flag & FC_RSCN_MODE)
706 lpfc_els_flush_rscn(vport);
710 spin_lock_irq(shost->host_lock);
711 if (vport->fc_flag & FC_RSCN_DEFERRED) {
712 vport->fc_flag &= ~FC_RSCN_DEFERRED;
713 spin_unlock_irq(shost->host_lock);
715 /* This is a GID_FT completing so the gidft_inp counter was
716 * incremented before the GID_FT was issued to the wire.
721 * Skip processing the NS response
722 * Re-issue the NS cmd
724 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
725 "0151 Process Deferred RSCN Data: x%x x%x\n",
726 vport->fc_flag, vport->fc_rscn_id_cnt);
727 lpfc_els_handle_rscn(vport);
731 spin_unlock_irq(shost->host_lock);
733 if (irsp->ulpStatus) {
734 /* Check for retry */
735 if (vport->fc_ns_retry < LPFC_MAX_NS_RETRY) {
736 if (irsp->ulpStatus != IOSTAT_LOCAL_REJECT ||
737 (irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
739 vport->fc_ns_retry++;
741 type = lpfc_get_gidft_type(vport, cmdiocb);
745 /* CT command is being retried */
747 rc = lpfc_ns_cmd(vport, SLI_CTNS_GID_FT,
748 vport->fc_ns_retry, type);
752 if (vport->fc_flag & FC_RSCN_MODE)
753 lpfc_els_flush_rscn(vport);
754 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
755 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
756 "0257 GID_FT Query error: 0x%x 0x%x\n",
757 irsp->ulpStatus, vport->fc_ns_retry);
759 /* Good status, continue checking */
760 CTreq = (struct lpfc_sli_ct_request *) inp->virt;
761 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
762 if (CTrsp->CommandResponse.bits.CmdRsp ==
763 cpu_to_be16(SLI_CT_RESPONSE_FS_ACC)) {
764 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
765 "0208 NameServer Rsp Data: x%x x%x "
768 CTreq->un.gid.Fc4Type,
769 vport->num_disc_nodes,
771 irsp->un.genreq64.bdl.bdeSize);
775 CTreq->un.gid.Fc4Type,
776 (uint32_t) (irsp->un.genreq64.bdl.bdeSize));
777 } else if (CTrsp->CommandResponse.bits.CmdRsp ==
778 be16_to_cpu(SLI_CT_RESPONSE_FS_RJT)) {
779 /* NameServer Rsp Error */
780 if ((CTrsp->ReasonCode == SLI_CT_UNABLE_TO_PERFORM_REQ)
781 && (CTrsp->Explanation == SLI_CT_NO_FC4_TYPES)) {
782 lpfc_printf_vlog(vport, KERN_INFO,
784 "0269 No NameServer Entries "
785 "Data: x%x x%x x%x x%x\n",
786 CTrsp->CommandResponse.bits.CmdRsp,
787 (uint32_t) CTrsp->ReasonCode,
788 (uint32_t) CTrsp->Explanation,
791 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
792 "GID_FT no entry cmd:x%x rsn:x%x exp:x%x",
793 (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
794 (uint32_t) CTrsp->ReasonCode,
795 (uint32_t) CTrsp->Explanation);
797 lpfc_printf_vlog(vport, KERN_INFO,
799 "0240 NameServer Rsp Error "
800 "Data: x%x x%x x%x x%x\n",
801 CTrsp->CommandResponse.bits.CmdRsp,
802 (uint32_t) CTrsp->ReasonCode,
803 (uint32_t) CTrsp->Explanation,
806 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
807 "GID_FT rsp err1 cmd:x%x rsn:x%x exp:x%x",
808 (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
809 (uint32_t) CTrsp->ReasonCode,
810 (uint32_t) CTrsp->Explanation);
815 /* NameServer Rsp Error */
816 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
817 "0241 NameServer Rsp Error "
818 "Data: x%x x%x x%x x%x\n",
819 CTrsp->CommandResponse.bits.CmdRsp,
820 (uint32_t) CTrsp->ReasonCode,
821 (uint32_t) CTrsp->Explanation,
824 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
825 "GID_FT rsp err2 cmd:x%x rsn:x%x exp:x%x",
826 (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
827 (uint32_t) CTrsp->ReasonCode,
828 (uint32_t) CTrsp->Explanation);
833 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
834 "4216 GID_FT cmpl inp %d disc %d\n",
835 vport->gidft_inp, vport->num_disc_nodes);
837 /* Link up / RSCN discovery */
838 if ((vport->num_disc_nodes == 0) &&
839 (vport->gidft_inp == 0)) {
841 * The driver has cycled through all Nports in the RSCN payload.
842 * Complete the handling by cleaning up and marking the
843 * current driver state.
845 if (vport->port_state >= LPFC_DISC_AUTH) {
846 if (vport->fc_flag & FC_RSCN_MODE) {
847 lpfc_els_flush_rscn(vport);
848 spin_lock_irq(shost->host_lock);
849 vport->fc_flag |= FC_RSCN_MODE; /* RSCN still */
850 spin_unlock_irq(shost->host_lock);
853 lpfc_els_flush_rscn(vport);
856 lpfc_disc_start(vport);
859 cmdiocb->context_un.ndlp = ndlp; /* Now restore ndlp for free */
860 lpfc_ct_free_iocb(phba, cmdiocb);
865 lpfc_cmpl_ct_cmd_gid_pt(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
866 struct lpfc_iocbq *rspiocb)
868 struct lpfc_vport *vport = cmdiocb->vport;
869 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
871 struct lpfc_dmabuf *outp;
872 struct lpfc_dmabuf *inp;
873 struct lpfc_sli_ct_request *CTrsp;
874 struct lpfc_sli_ct_request *CTreq;
875 struct lpfc_nodelist *ndlp;
878 /* First save ndlp, before we overwrite it */
879 ndlp = cmdiocb->context_un.ndlp;
881 /* we pass cmdiocb to state machine which needs rspiocb as well */
882 cmdiocb->context_un.rsp_iocb = rspiocb;
883 inp = (struct lpfc_dmabuf *)cmdiocb->context1;
884 outp = (struct lpfc_dmabuf *)cmdiocb->context2;
885 irsp = &rspiocb->iocb;
887 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
888 "GID_PT cmpl: status:x%x/x%x rtry:%d",
889 irsp->ulpStatus, irsp->un.ulpWord[4],
892 /* Don't bother processing response if vport is being torn down. */
893 if (vport->load_flag & FC_UNLOADING) {
894 if (vport->fc_flag & FC_RSCN_MODE)
895 lpfc_els_flush_rscn(vport);
899 if (lpfc_els_chk_latt(vport)) {
900 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
901 "4108 Link event during NS query\n");
902 if (vport->fc_flag & FC_RSCN_MODE)
903 lpfc_els_flush_rscn(vport);
904 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
907 if (lpfc_error_lost_link(irsp)) {
908 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
909 "4166 NS query failed due to link event\n");
910 if (vport->fc_flag & FC_RSCN_MODE)
911 lpfc_els_flush_rscn(vport);
915 spin_lock_irq(shost->host_lock);
916 if (vport->fc_flag & FC_RSCN_DEFERRED) {
917 vport->fc_flag &= ~FC_RSCN_DEFERRED;
918 spin_unlock_irq(shost->host_lock);
920 /* This is a GID_PT completing so the gidft_inp counter was
921 * incremented before the GID_PT was issued to the wire.
926 * Skip processing the NS response
927 * Re-issue the NS cmd
929 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
930 "4167 Process Deferred RSCN Data: x%x x%x\n",
931 vport->fc_flag, vport->fc_rscn_id_cnt);
932 lpfc_els_handle_rscn(vport);
936 spin_unlock_irq(shost->host_lock);
938 if (irsp->ulpStatus) {
939 /* Check for retry */
940 if (vport->fc_ns_retry < LPFC_MAX_NS_RETRY) {
941 if (irsp->ulpStatus != IOSTAT_LOCAL_REJECT ||
942 (irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
944 vport->fc_ns_retry++;
946 /* CT command is being retried */
948 rc = lpfc_ns_cmd(vport, SLI_CTNS_GID_PT,
949 vport->fc_ns_retry, GID_PT_N_PORT);
953 if (vport->fc_flag & FC_RSCN_MODE)
954 lpfc_els_flush_rscn(vport);
955 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
956 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
957 "4103 GID_FT Query error: 0x%x 0x%x\n",
958 irsp->ulpStatus, vport->fc_ns_retry);
960 /* Good status, continue checking */
961 CTreq = (struct lpfc_sli_ct_request *)inp->virt;
962 CTrsp = (struct lpfc_sli_ct_request *)outp->virt;
963 if (CTrsp->CommandResponse.bits.CmdRsp ==
964 cpu_to_be16(SLI_CT_RESPONSE_FS_ACC)) {
965 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
966 "4105 NameServer Rsp Data: x%x x%x "
969 CTreq->un.gid.Fc4Type,
970 vport->num_disc_nodes,
972 irsp->un.genreq64.bdl.bdeSize);
976 CTreq->un.gid.Fc4Type,
977 (uint32_t)(irsp->un.genreq64.bdl.bdeSize));
978 } else if (CTrsp->CommandResponse.bits.CmdRsp ==
979 be16_to_cpu(SLI_CT_RESPONSE_FS_RJT)) {
980 /* NameServer Rsp Error */
981 if ((CTrsp->ReasonCode == SLI_CT_UNABLE_TO_PERFORM_REQ)
982 && (CTrsp->Explanation == SLI_CT_NO_FC4_TYPES)) {
984 vport, KERN_INFO, LOG_DISCOVERY,
985 "4106 No NameServer Entries "
986 "Data: x%x x%x x%x x%x\n",
987 CTrsp->CommandResponse.bits.CmdRsp,
988 (uint32_t)CTrsp->ReasonCode,
989 (uint32_t)CTrsp->Explanation,
992 lpfc_debugfs_disc_trc(
993 vport, LPFC_DISC_TRC_CT,
994 "GID_PT no entry cmd:x%x rsn:x%x exp:x%x",
995 (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
996 (uint32_t)CTrsp->ReasonCode,
997 (uint32_t)CTrsp->Explanation);
1000 vport, KERN_INFO, LOG_DISCOVERY,
1001 "4107 NameServer Rsp Error "
1002 "Data: x%x x%x x%x x%x\n",
1003 CTrsp->CommandResponse.bits.CmdRsp,
1004 (uint32_t)CTrsp->ReasonCode,
1005 (uint32_t)CTrsp->Explanation,
1008 lpfc_debugfs_disc_trc(
1009 vport, LPFC_DISC_TRC_CT,
1010 "GID_PT rsp err1 cmd:x%x rsn:x%x exp:x%x",
1011 (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
1012 (uint32_t)CTrsp->ReasonCode,
1013 (uint32_t)CTrsp->Explanation);
1016 /* NameServer Rsp Error */
1017 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
1018 "4109 NameServer Rsp Error "
1019 "Data: x%x x%x x%x x%x\n",
1020 CTrsp->CommandResponse.bits.CmdRsp,
1021 (uint32_t)CTrsp->ReasonCode,
1022 (uint32_t)CTrsp->Explanation,
1025 lpfc_debugfs_disc_trc(
1026 vport, LPFC_DISC_TRC_CT,
1027 "GID_PT rsp err2 cmd:x%x rsn:x%x exp:x%x",
1028 (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
1029 (uint32_t)CTrsp->ReasonCode,
1030 (uint32_t)CTrsp->Explanation);
1035 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1036 "6450 GID_PT cmpl inp %d disc %d\n",
1037 vport->gidft_inp, vport->num_disc_nodes);
1039 /* Link up / RSCN discovery */
1040 if ((vport->num_disc_nodes == 0) &&
1041 (vport->gidft_inp == 0)) {
1043 * The driver has cycled through all Nports in the RSCN payload.
1044 * Complete the handling by cleaning up and marking the
1045 * current driver state.
1047 if (vport->port_state >= LPFC_DISC_AUTH) {
1048 if (vport->fc_flag & FC_RSCN_MODE) {
1049 lpfc_els_flush_rscn(vport);
1050 spin_lock_irq(shost->host_lock);
1051 vport->fc_flag |= FC_RSCN_MODE; /* RSCN still */
1052 spin_unlock_irq(shost->host_lock);
1054 lpfc_els_flush_rscn(vport);
1058 lpfc_disc_start(vport);
1061 cmdiocb->context_un.ndlp = ndlp; /* Now restore ndlp for free */
1062 lpfc_ct_free_iocb(phba, cmdiocb);
1066 lpfc_cmpl_ct_cmd_gff_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1067 struct lpfc_iocbq *rspiocb)
1069 struct lpfc_vport *vport = cmdiocb->vport;
1070 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1071 IOCB_t *irsp = &rspiocb->iocb;
1072 struct lpfc_dmabuf *inp = (struct lpfc_dmabuf *) cmdiocb->context1;
1073 struct lpfc_dmabuf *outp = (struct lpfc_dmabuf *) cmdiocb->context2;
1074 struct lpfc_sli_ct_request *CTrsp;
1077 struct lpfc_nodelist *ndlp;
1079 did = ((struct lpfc_sli_ct_request *) inp->virt)->un.gff.PortId;
1080 did = be32_to_cpu(did);
1082 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
1083 "GFF_ID cmpl: status:x%x/x%x did:x%x",
1084 irsp->ulpStatus, irsp->un.ulpWord[4], did);
1086 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
1087 /* Good status, continue checking */
1088 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
1089 fbits = CTrsp->un.gff_acc.fbits[FCP_TYPE_FEATURE_OFFSET];
1091 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1092 "6431 Process GFF_ID rsp for %08x "
1093 "fbits %02x %s %s\n",
1095 (fbits & FC4_FEATURE_INIT) ? "Initiator" : " ",
1096 (fbits & FC4_FEATURE_TARGET) ? "Target" : " ");
1098 if (CTrsp->CommandResponse.bits.CmdRsp ==
1099 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC)) {
1100 if ((fbits & FC4_FEATURE_INIT) &&
1101 !(fbits & FC4_FEATURE_TARGET)) {
1102 lpfc_printf_vlog(vport, KERN_INFO,
1104 "0270 Skip x%x GFF "
1105 "NameServer Rsp Data: (init) "
1106 "x%x x%x\n", did, fbits,
1107 vport->fc_rscn_id_cnt);
1113 /* Check for retry */
1114 if (cmdiocb->retry < LPFC_MAX_NS_RETRY) {
1116 if (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) {
1117 switch ((irsp->un.ulpWord[4] &
1118 IOERR_PARAM_MASK)) {
1120 case IOERR_NO_RESOURCES:
1121 /* We don't increment the retry
1122 * count for this case.
1125 case IOERR_LINK_DOWN:
1126 case IOERR_SLI_ABORTED:
1127 case IOERR_SLI_DOWN:
1138 /* CT command is being retried */
1139 rc = lpfc_ns_cmd(vport, SLI_CTNS_GFF_ID,
1140 cmdiocb->retry, did);
1143 lpfc_ct_free_iocb(phba, cmdiocb);
1148 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
1149 "0267 NameServer GFF Rsp "
1150 "x%x Error (%d %d) Data: x%x x%x\n",
1151 did, irsp->ulpStatus, irsp->un.ulpWord[4],
1152 vport->fc_flag, vport->fc_rscn_id_cnt);
1155 /* This is a target port, unregistered port, or the GFF_ID failed */
1156 ndlp = lpfc_setup_disc_node(vport, did);
1157 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
1158 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1159 "0242 Process x%x GFF "
1160 "NameServer Rsp Data: x%x x%x x%x\n",
1161 did, ndlp->nlp_flag, vport->fc_flag,
1162 vport->fc_rscn_id_cnt);
1164 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1165 "0243 Skip x%x GFF "
1166 "NameServer Rsp Data: x%x x%x\n", did,
1167 vport->fc_flag, vport->fc_rscn_id_cnt);
1170 /* Link up / RSCN discovery */
1171 if (vport->num_disc_nodes)
1172 vport->num_disc_nodes--;
1174 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1175 "6451 GFF_ID cmpl inp %d disc %d\n",
1176 vport->gidft_inp, vport->num_disc_nodes);
1178 if (vport->num_disc_nodes == 0) {
1180 * The driver has cycled through all Nports in the RSCN payload.
1181 * Complete the handling by cleaning up and marking the
1182 * current driver state.
1184 if (vport->port_state >= LPFC_DISC_AUTH) {
1185 if (vport->fc_flag & FC_RSCN_MODE) {
1186 lpfc_els_flush_rscn(vport);
1187 spin_lock_irq(shost->host_lock);
1188 vport->fc_flag |= FC_RSCN_MODE; /* RSCN still */
1189 spin_unlock_irq(shost->host_lock);
1192 lpfc_els_flush_rscn(vport);
1194 lpfc_disc_start(vport);
1196 lpfc_ct_free_iocb(phba, cmdiocb);
1201 lpfc_cmpl_ct_cmd_gft_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1202 struct lpfc_iocbq *rspiocb)
1204 struct lpfc_vport *vport = cmdiocb->vport;
1205 IOCB_t *irsp = &rspiocb->iocb;
1206 struct lpfc_dmabuf *inp = (struct lpfc_dmabuf *)cmdiocb->context1;
1207 struct lpfc_dmabuf *outp = (struct lpfc_dmabuf *)cmdiocb->context2;
1208 struct lpfc_sli_ct_request *CTrsp;
1210 struct lpfc_nodelist *ndlp;
1211 uint32_t fc4_data_0, fc4_data_1;
1213 did = ((struct lpfc_sli_ct_request *)inp->virt)->un.gft.PortId;
1214 did = be32_to_cpu(did);
1216 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
1217 "GFT_ID cmpl: status:x%x/x%x did:x%x",
1218 irsp->ulpStatus, irsp->un.ulpWord[4], did);
1220 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
1221 /* Good status, continue checking */
1222 CTrsp = (struct lpfc_sli_ct_request *)outp->virt;
1223 fc4_data_0 = be32_to_cpu(CTrsp->un.gft_acc.fc4_types[0]);
1224 fc4_data_1 = be32_to_cpu(CTrsp->un.gft_acc.fc4_types[1]);
1226 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1227 "6432 Process GFT_ID rsp for %08x "
1228 "Data %08x %08x %s %s\n",
1229 did, fc4_data_0, fc4_data_1,
1230 (fc4_data_0 & LPFC_FC4_TYPE_BITMASK) ?
1232 (fc4_data_1 & LPFC_FC4_TYPE_BITMASK) ?
1235 ndlp = lpfc_findnode_did(vport, did);
1237 /* The bitmask value for FCP and NVME FCP types is
1238 * the same because they are 32 bits distant from
1239 * each other in word0 and word0.
1241 if (fc4_data_0 & LPFC_FC4_TYPE_BITMASK)
1242 ndlp->nlp_fc4_type |= NLP_FC4_FCP;
1243 if (fc4_data_1 & LPFC_FC4_TYPE_BITMASK)
1244 ndlp->nlp_fc4_type |= NLP_FC4_NVME;
1245 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1246 "3064 Setting ndlp x%px, DID x%06x "
1247 "with FC4 x%08x, Data: x%08x x%08x "
1249 ndlp, did, ndlp->nlp_fc4_type,
1250 FC_TYPE_FCP, FC_TYPE_NVME,
1253 if (ndlp->nlp_state == NLP_STE_REG_LOGIN_ISSUE &&
1254 ndlp->nlp_fc4_type) {
1255 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1257 lpfc_nlp_set_state(vport, ndlp,
1258 NLP_STE_PRLI_ISSUE);
1259 lpfc_issue_els_prli(vport, ndlp, 0);
1260 } else if (!ndlp->nlp_fc4_type) {
1261 /* If fc4 type is still unknown, then LOGO */
1262 lpfc_printf_vlog(vport, KERN_INFO,
1264 "6443 Sending LOGO ndlp x%px,"
1265 "DID x%06x with fc4_type: "
1266 "x%08x, state: %d\n",
1267 ndlp, did, ndlp->nlp_fc4_type,
1269 lpfc_issue_els_logo(vport, ndlp, 0);
1270 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1271 lpfc_nlp_set_state(vport, ndlp,
1276 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
1277 "3065 GFT_ID failed x%08x\n", irsp->ulpStatus);
1279 lpfc_ct_free_iocb(phba, cmdiocb);
1283 lpfc_cmpl_ct(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1284 struct lpfc_iocbq *rspiocb)
1286 struct lpfc_vport *vport = cmdiocb->vport;
1287 struct lpfc_dmabuf *inp;
1288 struct lpfc_dmabuf *outp;
1290 struct lpfc_sli_ct_request *CTrsp;
1291 struct lpfc_nodelist *ndlp;
1296 /* First save ndlp, before we overwrite it */
1297 ndlp = cmdiocb->context_un.ndlp;
1299 /* we pass cmdiocb to state machine which needs rspiocb as well */
1300 cmdiocb->context_un.rsp_iocb = rspiocb;
1302 inp = (struct lpfc_dmabuf *) cmdiocb->context1;
1303 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
1304 irsp = &rspiocb->iocb;
1306 cmdcode = be16_to_cpu(((struct lpfc_sli_ct_request *) inp->virt)->
1307 CommandResponse.bits.CmdRsp);
1308 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
1310 latt = lpfc_els_chk_latt(vport);
1312 /* RFT request completes status <ulpStatus> CmdRsp <CmdRsp> */
1313 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1314 "0209 CT Request completes, latt %d, "
1315 "ulpStatus x%x CmdRsp x%x, Context x%x, Tag x%x\n",
1316 latt, irsp->ulpStatus,
1317 CTrsp->CommandResponse.bits.CmdRsp,
1318 cmdiocb->iocb.ulpContext, cmdiocb->iocb.ulpIoTag);
1320 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
1321 "CT cmd cmpl: status:x%x/x%x cmd:x%x",
1322 irsp->ulpStatus, irsp->un.ulpWord[4], cmdcode);
1324 if (irsp->ulpStatus) {
1325 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
1326 "0268 NS cmd x%x Error (x%x x%x)\n",
1327 cmdcode, irsp->ulpStatus, irsp->un.ulpWord[4]);
1329 if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
1330 (((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
1332 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
1333 IOERR_SLI_ABORTED)))
1336 retry = cmdiocb->retry;
1337 if (retry >= LPFC_MAX_NS_RETRY)
1341 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1342 "0250 Retrying NS cmd %x\n", cmdcode);
1343 rc = lpfc_ns_cmd(vport, cmdcode, retry, 0);
1349 cmdiocb->context_un.ndlp = ndlp; /* Now restore ndlp for free */
1350 lpfc_ct_free_iocb(phba, cmdiocb);
1355 lpfc_cmpl_ct_cmd_rft_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1356 struct lpfc_iocbq *rspiocb)
1358 IOCB_t *irsp = &rspiocb->iocb;
1359 struct lpfc_vport *vport = cmdiocb->vport;
1361 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
1362 struct lpfc_dmabuf *outp;
1363 struct lpfc_sli_ct_request *CTrsp;
1365 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
1366 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
1367 if (CTrsp->CommandResponse.bits.CmdRsp ==
1368 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
1369 vport->ct_flags |= FC_CT_RFT_ID;
1371 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
1376 lpfc_cmpl_ct_cmd_rnn_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1377 struct lpfc_iocbq *rspiocb)
1379 IOCB_t *irsp = &rspiocb->iocb;
1380 struct lpfc_vport *vport = cmdiocb->vport;
1382 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
1383 struct lpfc_dmabuf *outp;
1384 struct lpfc_sli_ct_request *CTrsp;
1386 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
1387 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
1388 if (CTrsp->CommandResponse.bits.CmdRsp ==
1389 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
1390 vport->ct_flags |= FC_CT_RNN_ID;
1392 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
1397 lpfc_cmpl_ct_cmd_rspn_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1398 struct lpfc_iocbq *rspiocb)
1400 IOCB_t *irsp = &rspiocb->iocb;
1401 struct lpfc_vport *vport = cmdiocb->vport;
1403 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
1404 struct lpfc_dmabuf *outp;
1405 struct lpfc_sli_ct_request *CTrsp;
1407 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
1408 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
1409 if (CTrsp->CommandResponse.bits.CmdRsp ==
1410 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
1411 vport->ct_flags |= FC_CT_RSPN_ID;
1413 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
1418 lpfc_cmpl_ct_cmd_rsnn_nn(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1419 struct lpfc_iocbq *rspiocb)
1421 IOCB_t *irsp = &rspiocb->iocb;
1422 struct lpfc_vport *vport = cmdiocb->vport;
1424 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
1425 struct lpfc_dmabuf *outp;
1426 struct lpfc_sli_ct_request *CTrsp;
1428 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
1429 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
1430 if (CTrsp->CommandResponse.bits.CmdRsp ==
1431 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
1432 vport->ct_flags |= FC_CT_RSNN_NN;
1434 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
1439 lpfc_cmpl_ct_cmd_da_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1440 struct lpfc_iocbq *rspiocb)
1442 struct lpfc_vport *vport = cmdiocb->vport;
1444 /* even if it fails we will act as though it succeeded. */
1445 vport->ct_flags = 0;
1446 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
1451 lpfc_cmpl_ct_cmd_rff_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1452 struct lpfc_iocbq *rspiocb)
1454 IOCB_t *irsp = &rspiocb->iocb;
1455 struct lpfc_vport *vport = cmdiocb->vport;
1457 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
1458 struct lpfc_dmabuf *outp;
1459 struct lpfc_sli_ct_request *CTrsp;
1461 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
1462 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
1463 if (CTrsp->CommandResponse.bits.CmdRsp ==
1464 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
1465 vport->ct_flags |= FC_CT_RFF_ID;
1467 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
1472 * Although the symbolic port name is thought to be an integer
1473 * as of January 18, 2016, leave it as a string until more of
1474 * the record state becomes defined.
1477 lpfc_vport_symbolic_port_name(struct lpfc_vport *vport, char *symbol,
1483 * Use the lpfc board number as the Symbolic Port
1484 * Name object. NPIV is not in play so this integer
1485 * value is sufficient and unique per FC-ID.
1487 n = scnprintf(symbol, size, "%d", vport->phba->brd_no);
1493 lpfc_vport_symbolic_node_name(struct lpfc_vport *vport, char *symbol,
1496 char fwrev[FW_REV_STR_SIZE] = {0};
1497 char tmp[MAXHOSTNAMELEN] = {0};
1499 memset(symbol, 0, size);
1501 scnprintf(tmp, sizeof(tmp), "Emulex %s", vport->phba->ModelName);
1502 if (strlcat(symbol, tmp, size) >= size)
1505 lpfc_decode_firmware_rev(vport->phba, fwrev, 0);
1506 scnprintf(tmp, sizeof(tmp), " FV%s", fwrev);
1507 if (strlcat(symbol, tmp, size) >= size)
1510 scnprintf(tmp, sizeof(tmp), " DV%s", lpfc_release_version);
1511 if (strlcat(symbol, tmp, size) >= size)
1514 scnprintf(tmp, sizeof(tmp), " HN:%s", vport->phba->os_host_name);
1515 if (strlcat(symbol, tmp, size) >= size)
1518 /* Note :- OS name is "Linux" */
1519 scnprintf(tmp, sizeof(tmp), " OS:%s", init_utsname()->sysname);
1520 strlcat(symbol, tmp, size);
1523 return strnlen(symbol, size);
1528 lpfc_find_map_node(struct lpfc_vport *vport)
1530 struct lpfc_nodelist *ndlp, *next_ndlp;
1531 struct Scsi_Host *shost;
1534 shost = lpfc_shost_from_vport(vport);
1535 spin_lock_irq(shost->host_lock);
1536 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
1537 if (ndlp->nlp_type & NLP_FABRIC)
1539 if ((ndlp->nlp_state == NLP_STE_MAPPED_NODE) ||
1540 (ndlp->nlp_state == NLP_STE_UNMAPPED_NODE))
1543 spin_unlock_irq(shost->host_lock);
1548 * This routine will return the FC4 Type associated with the CT
1552 lpfc_get_gidft_type(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb)
1554 struct lpfc_sli_ct_request *CtReq;
1555 struct lpfc_dmabuf *mp;
1558 mp = cmdiocb->context1;
1561 CtReq = (struct lpfc_sli_ct_request *)mp->virt;
1562 type = (uint32_t)CtReq->un.gid.Fc4Type;
1563 if ((type != SLI_CTPT_FCP) && (type != SLI_CTPT_NVME))
1571 * Issue Cmd to NameServer
1576 lpfc_ns_cmd(struct lpfc_vport *vport, int cmdcode,
1577 uint8_t retry, uint32_t context)
1579 struct lpfc_nodelist * ndlp;
1580 struct lpfc_hba *phba = vport->phba;
1581 struct lpfc_dmabuf *mp, *bmp;
1582 struct lpfc_sli_ct_request *CtReq;
1583 struct ulp_bde64 *bpl;
1584 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
1585 struct lpfc_iocbq *) = NULL;
1587 uint32_t rsp_size = 1024;
1591 ndlp = lpfc_findnode_did(vport, NameServer_DID);
1592 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)
1593 || ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) {
1598 /* fill in BDEs for command */
1599 /* Allocate buffer for command payload */
1600 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
1606 INIT_LIST_HEAD(&mp->list);
1607 mp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(mp->phys));
1610 goto ns_cmd_free_mp;
1613 /* Allocate buffer for Buffer ptr list */
1614 bmp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
1617 goto ns_cmd_free_mpvirt;
1620 INIT_LIST_HEAD(&bmp->list);
1621 bmp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(bmp->phys));
1624 goto ns_cmd_free_bmp;
1627 /* NameServer Req */
1628 lpfc_printf_vlog(vport, KERN_INFO ,LOG_DISCOVERY,
1629 "0236 NameServer Req Data: x%x x%x x%x x%x\n",
1630 cmdcode, vport->fc_flag, vport->fc_rscn_id_cnt,
1633 bpl = (struct ulp_bde64 *) bmp->virt;
1634 memset(bpl, 0, sizeof(struct ulp_bde64));
1635 bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys) );
1636 bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys) );
1637 bpl->tus.f.bdeFlags = 0;
1638 if (cmdcode == SLI_CTNS_GID_FT)
1639 bpl->tus.f.bdeSize = GID_REQUEST_SZ;
1640 else if (cmdcode == SLI_CTNS_GID_PT)
1641 bpl->tus.f.bdeSize = GID_REQUEST_SZ;
1642 else if (cmdcode == SLI_CTNS_GFF_ID)
1643 bpl->tus.f.bdeSize = GFF_REQUEST_SZ;
1644 else if (cmdcode == SLI_CTNS_GFT_ID)
1645 bpl->tus.f.bdeSize = GFT_REQUEST_SZ;
1646 else if (cmdcode == SLI_CTNS_RFT_ID)
1647 bpl->tus.f.bdeSize = RFT_REQUEST_SZ;
1648 else if (cmdcode == SLI_CTNS_RNN_ID)
1649 bpl->tus.f.bdeSize = RNN_REQUEST_SZ;
1650 else if (cmdcode == SLI_CTNS_RSPN_ID)
1651 bpl->tus.f.bdeSize = RSPN_REQUEST_SZ;
1652 else if (cmdcode == SLI_CTNS_RSNN_NN)
1653 bpl->tus.f.bdeSize = RSNN_REQUEST_SZ;
1654 else if (cmdcode == SLI_CTNS_DA_ID)
1655 bpl->tus.f.bdeSize = DA_ID_REQUEST_SZ;
1656 else if (cmdcode == SLI_CTNS_RFF_ID)
1657 bpl->tus.f.bdeSize = RFF_REQUEST_SZ;
1659 bpl->tus.f.bdeSize = 0;
1660 bpl->tus.w = le32_to_cpu(bpl->tus.w);
1662 CtReq = (struct lpfc_sli_ct_request *) mp->virt;
1663 memset(CtReq, 0, sizeof(struct lpfc_sli_ct_request));
1664 CtReq->RevisionId.bits.Revision = SLI_CT_REVISION;
1665 CtReq->RevisionId.bits.InId = 0;
1666 CtReq->FsType = SLI_CT_DIRECTORY_SERVICE;
1667 CtReq->FsSubType = SLI_CT_DIRECTORY_NAME_SERVER;
1668 CtReq->CommandResponse.bits.Size = 0;
1670 case SLI_CTNS_GID_FT:
1671 CtReq->CommandResponse.bits.CmdRsp =
1672 cpu_to_be16(SLI_CTNS_GID_FT);
1673 CtReq->un.gid.Fc4Type = context;
1675 if (vport->port_state < LPFC_NS_QRY)
1676 vport->port_state = LPFC_NS_QRY;
1677 lpfc_set_disctmo(vport);
1678 cmpl = lpfc_cmpl_ct_cmd_gid_ft;
1679 rsp_size = FC_MAX_NS_RSP;
1682 case SLI_CTNS_GID_PT:
1683 CtReq->CommandResponse.bits.CmdRsp =
1684 cpu_to_be16(SLI_CTNS_GID_PT);
1685 CtReq->un.gid.PortType = context;
1687 if (vport->port_state < LPFC_NS_QRY)
1688 vport->port_state = LPFC_NS_QRY;
1689 lpfc_set_disctmo(vport);
1690 cmpl = lpfc_cmpl_ct_cmd_gid_pt;
1691 rsp_size = FC_MAX_NS_RSP;
1694 case SLI_CTNS_GFF_ID:
1695 CtReq->CommandResponse.bits.CmdRsp =
1696 cpu_to_be16(SLI_CTNS_GFF_ID);
1697 CtReq->un.gff.PortId = cpu_to_be32(context);
1698 cmpl = lpfc_cmpl_ct_cmd_gff_id;
1701 case SLI_CTNS_GFT_ID:
1702 CtReq->CommandResponse.bits.CmdRsp =
1703 cpu_to_be16(SLI_CTNS_GFT_ID);
1704 CtReq->un.gft.PortId = cpu_to_be32(context);
1705 cmpl = lpfc_cmpl_ct_cmd_gft_id;
1708 case SLI_CTNS_RFT_ID:
1709 vport->ct_flags &= ~FC_CT_RFT_ID;
1710 CtReq->CommandResponse.bits.CmdRsp =
1711 cpu_to_be16(SLI_CTNS_RFT_ID);
1712 CtReq->un.rft.PortId = cpu_to_be32(vport->fc_myDID);
1714 /* Register FC4 FCP type if enabled. */
1715 if (vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH ||
1716 vport->cfg_enable_fc4_type == LPFC_ENABLE_FCP)
1717 CtReq->un.rft.fcpReg = 1;
1719 /* Register NVME type if enabled. Defined LE and swapped.
1720 * rsvd[0] is used as word1 because of the hard-coded
1721 * word0 usage in the ct_request data structure.
1723 if (vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH ||
1724 vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME)
1725 CtReq->un.rft.rsvd[0] =
1726 cpu_to_be32(LPFC_FC4_TYPE_BITMASK);
1728 ptr = (uint32_t *)CtReq;
1729 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1730 "6433 Issue RFT (%s %s): %08x %08x %08x %08x "
1731 "%08x %08x %08x %08x\n",
1732 CtReq->un.rft.fcpReg ? "FCP" : " ",
1733 CtReq->un.rft.rsvd[0] ? "NVME" : " ",
1734 *ptr, *(ptr + 1), *(ptr + 2), *(ptr + 3),
1735 *(ptr + 4), *(ptr + 5),
1736 *(ptr + 6), *(ptr + 7));
1737 cmpl = lpfc_cmpl_ct_cmd_rft_id;
1740 case SLI_CTNS_RNN_ID:
1741 vport->ct_flags &= ~FC_CT_RNN_ID;
1742 CtReq->CommandResponse.bits.CmdRsp =
1743 cpu_to_be16(SLI_CTNS_RNN_ID);
1744 CtReq->un.rnn.PortId = cpu_to_be32(vport->fc_myDID);
1745 memcpy(CtReq->un.rnn.wwnn, &vport->fc_nodename,
1746 sizeof(struct lpfc_name));
1747 cmpl = lpfc_cmpl_ct_cmd_rnn_id;
1750 case SLI_CTNS_RSPN_ID:
1751 vport->ct_flags &= ~FC_CT_RSPN_ID;
1752 CtReq->CommandResponse.bits.CmdRsp =
1753 cpu_to_be16(SLI_CTNS_RSPN_ID);
1754 CtReq->un.rspn.PortId = cpu_to_be32(vport->fc_myDID);
1755 size = sizeof(CtReq->un.rspn.symbname);
1756 CtReq->un.rspn.len =
1757 lpfc_vport_symbolic_port_name(vport,
1758 CtReq->un.rspn.symbname, size);
1759 cmpl = lpfc_cmpl_ct_cmd_rspn_id;
1761 case SLI_CTNS_RSNN_NN:
1762 vport->ct_flags &= ~FC_CT_RSNN_NN;
1763 CtReq->CommandResponse.bits.CmdRsp =
1764 cpu_to_be16(SLI_CTNS_RSNN_NN);
1765 memcpy(CtReq->un.rsnn.wwnn, &vport->fc_nodename,
1766 sizeof(struct lpfc_name));
1767 size = sizeof(CtReq->un.rsnn.symbname);
1768 CtReq->un.rsnn.len =
1769 lpfc_vport_symbolic_node_name(vport,
1770 CtReq->un.rsnn.symbname, size);
1771 cmpl = lpfc_cmpl_ct_cmd_rsnn_nn;
1773 case SLI_CTNS_DA_ID:
1774 /* Implement DA_ID Nameserver request */
1775 CtReq->CommandResponse.bits.CmdRsp =
1776 cpu_to_be16(SLI_CTNS_DA_ID);
1777 CtReq->un.da_id.port_id = cpu_to_be32(vport->fc_myDID);
1778 cmpl = lpfc_cmpl_ct_cmd_da_id;
1780 case SLI_CTNS_RFF_ID:
1781 vport->ct_flags &= ~FC_CT_RFF_ID;
1782 CtReq->CommandResponse.bits.CmdRsp =
1783 cpu_to_be16(SLI_CTNS_RFF_ID);
1784 CtReq->un.rff.PortId = cpu_to_be32(vport->fc_myDID);
1785 CtReq->un.rff.fbits = FC4_FEATURE_INIT;
1787 /* The driver always supports FC_TYPE_FCP. However, the
1788 * caller can specify NVME (type x28) as well. But only
1789 * these that FC4 type is supported.
1791 if (((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
1792 (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) &&
1793 (context == FC_TYPE_NVME)) {
1794 if ((vport == phba->pport) && phba->nvmet_support) {
1795 CtReq->un.rff.fbits = (FC4_FEATURE_TARGET |
1796 FC4_FEATURE_NVME_DISC);
1797 lpfc_nvmet_update_targetport(phba);
1799 lpfc_nvme_update_localport(vport);
1801 CtReq->un.rff.type_code = context;
1803 } else if (((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
1804 (vport->cfg_enable_fc4_type == LPFC_ENABLE_FCP)) &&
1805 (context == FC_TYPE_FCP))
1806 CtReq->un.rff.type_code = context;
1809 goto ns_cmd_free_bmpvirt;
1811 ptr = (uint32_t *)CtReq;
1812 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1813 "6434 Issue RFF (%s): %08x %08x %08x %08x "
1814 "%08x %08x %08x %08x\n",
1815 (context == FC_TYPE_NVME) ? "NVME" : "FCP",
1816 *ptr, *(ptr + 1), *(ptr + 2), *(ptr + 3),
1817 *(ptr + 4), *(ptr + 5),
1818 *(ptr + 6), *(ptr + 7));
1819 cmpl = lpfc_cmpl_ct_cmd_rff_id;
1822 /* The lpfc_ct_cmd/lpfc_get_req shall increment ndlp reference count
1823 * to hold ndlp reference for the corresponding callback function.
1825 if (!lpfc_ct_cmd(vport, mp, bmp, ndlp, cmpl, rsp_size, retry)) {
1826 /* On success, The cmpl function will free the buffers */
1827 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
1828 "Issue CT cmd: cmd:x%x did:x%x",
1829 cmdcode, ndlp->nlp_DID, 0);
1834 /* Decrement ndlp reference count to release ndlp reference held
1835 * for the failed command's callback function.
1839 ns_cmd_free_bmpvirt:
1840 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
1844 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1848 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
1849 "0266 Issue NameServer Req x%x err %d Data: x%x x%x\n",
1850 cmdcode, rc, vport->fc_flag, vport->fc_rscn_id_cnt);
1855 * lpfc_cmpl_ct_disc_fdmi - Handle a discovery FDMI completion
1856 * @phba: Pointer to HBA context object.
1857 * @cmdiocb: Pointer to the command IOCBQ.
1858 * @rspiocb: Pointer to the response IOCBQ.
1860 * This function to handle the completion of a driver initiated FDMI
1861 * CT command issued during discovery.
1864 lpfc_cmpl_ct_disc_fdmi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1865 struct lpfc_iocbq *rspiocb)
1867 struct lpfc_vport *vport = cmdiocb->vport;
1868 struct lpfc_dmabuf *inp = cmdiocb->context1;
1869 struct lpfc_dmabuf *outp = cmdiocb->context2;
1870 struct lpfc_sli_ct_request *CTcmd = inp->virt;
1871 struct lpfc_sli_ct_request *CTrsp = outp->virt;
1872 uint16_t fdmi_cmd = CTcmd->CommandResponse.bits.CmdRsp;
1873 uint16_t fdmi_rsp = CTrsp->CommandResponse.bits.CmdRsp;
1874 IOCB_t *irsp = &rspiocb->iocb;
1875 struct lpfc_nodelist *ndlp;
1876 uint32_t latt, cmd, err;
1878 latt = lpfc_els_chk_latt(vport);
1879 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
1880 "FDMI cmpl: status:x%x/x%x latt:%d",
1881 irsp->ulpStatus, irsp->un.ulpWord[4], latt);
1883 if (latt || irsp->ulpStatus) {
1885 /* Look for a retryable error */
1886 if (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) {
1887 switch ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK)) {
1888 case IOERR_SLI_ABORTED:
1889 case IOERR_SLI_DOWN:
1890 /* Driver aborted this IO. No retry as error
1891 * is likely Offline->Online or some adapter
1892 * error. Recovery will try again.
1895 case IOERR_ABORT_IN_PROGRESS:
1896 case IOERR_SEQUENCE_TIMEOUT:
1897 case IOERR_ILLEGAL_FRAME:
1898 case IOERR_NO_RESOURCES:
1899 case IOERR_ILLEGAL_COMMAND:
1901 if (cmdiocb->retry >= LPFC_FDMI_MAX_RETRY)
1904 /* Retry the same FDMI command */
1905 err = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING,
1907 if (err == IOCB_ERROR)
1915 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1916 "0229 FDMI cmd %04x failed, latt = %d "
1917 "ulpStatus: x%x, rid x%x\n",
1918 be16_to_cpu(fdmi_cmd), latt, irsp->ulpStatus,
1919 irsp->un.ulpWord[4]);
1921 lpfc_ct_free_iocb(phba, cmdiocb);
1923 ndlp = lpfc_findnode_did(vport, FDMI_DID);
1924 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
1927 /* Check for a CT LS_RJT response */
1928 cmd = be16_to_cpu(fdmi_cmd);
1929 if (fdmi_rsp == cpu_to_be16(SLI_CT_RESPONSE_FS_RJT)) {
1930 /* FDMI rsp failed */
1931 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1932 "0220 FDMI cmd failed FS_RJT Data: x%x", cmd);
1934 /* Should we fallback to FDMI-2 / FDMI-1 ? */
1937 if (vport->fdmi_hba_mask == LPFC_FDMI2_HBA_ATTR) {
1938 /* Fallback to FDMI-1 */
1939 vport->fdmi_hba_mask = LPFC_FDMI1_HBA_ATTR;
1940 vport->fdmi_port_mask = LPFC_FDMI1_PORT_ATTR;
1942 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA, 0);
1947 if (vport->fdmi_port_mask == LPFC_FDMI2_PORT_ATTR) {
1948 /* Fallback to FDMI-1 */
1949 vport->fdmi_port_mask = LPFC_FDMI1_PORT_ATTR;
1951 lpfc_fdmi_cmd(vport, ndlp, cmd, 0);
1953 if (vport->fdmi_port_mask == LPFC_FDMI2_SMART_ATTR) {
1954 vport->fdmi_port_mask = LPFC_FDMI2_PORT_ATTR;
1955 /* Retry the same command */
1956 lpfc_fdmi_cmd(vport, ndlp, cmd, 0);
1961 if (vport->fdmi_port_mask == LPFC_FDMI2_PORT_ATTR) {
1962 /* Fallback to FDMI-1 */
1963 vport->fdmi_hba_mask = LPFC_FDMI1_HBA_ATTR;
1964 vport->fdmi_port_mask = LPFC_FDMI1_PORT_ATTR;
1966 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA, 0);
1968 if (vport->fdmi_port_mask == LPFC_FDMI2_SMART_ATTR) {
1969 vport->fdmi_port_mask = LPFC_FDMI2_PORT_ATTR;
1970 /* Retry the same command */
1971 lpfc_fdmi_cmd(vport, ndlp, cmd, 0);
1978 * On success, need to cycle thru FDMI registration for discovery
1979 * DHBA -> DPRT -> RHBA -> RPA (physical port)
1980 * DPRT -> RPRT (vports)
1984 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RPA, 0);
1988 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DPRT, 0);
1992 if (vport->port_type == LPFC_PHYSICAL_PORT)
1993 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RHBA, 0);
1995 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RPRT, 0);
2003 * lpfc_fdmi_change_check - Check for changed FDMI parameters
2004 * @vport: pointer to a host virtual N_Port data structure.
2006 * Check how many mapped NPorts we are connected to
2007 * Check if our hostname changed
2008 * Called from hbeat timeout routine to check if any FDMI parameters
2009 * changed. If so, re-register those Attributes.
2012 lpfc_fdmi_change_check(struct lpfc_vport *vport)
2014 struct lpfc_hba *phba = vport->phba;
2015 struct lpfc_nodelist *ndlp;
2018 if (!lpfc_is_link_up(phba))
2021 /* Must be connected to a Fabric */
2022 if (!(vport->fc_flag & FC_FABRIC))
2025 ndlp = lpfc_findnode_did(vport, FDMI_DID);
2026 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
2029 /* Check if system hostname changed */
2030 if (strcmp(phba->os_host_name, init_utsname()->nodename)) {
2031 memset(phba->os_host_name, 0, sizeof(phba->os_host_name));
2032 scnprintf(phba->os_host_name, sizeof(phba->os_host_name), "%s",
2033 init_utsname()->nodename);
2034 lpfc_ns_cmd(vport, SLI_CTNS_RSNN_NN, 0, 0);
2036 /* Since this effects multiple HBA and PORT attributes, we need
2037 * de-register and go thru the whole FDMI registration cycle.
2038 * DHBA -> DPRT -> RHBA -> RPA (physical port)
2039 * DPRT -> RPRT (vports)
2041 if (vport->port_type == LPFC_PHYSICAL_PORT)
2042 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA, 0);
2044 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DPRT, 0);
2046 /* Since this code path registers all the port attributes
2047 * we can just return without further checking.
2052 if (!(vport->fdmi_port_mask & LPFC_FDMI_PORT_ATTR_num_disc))
2055 /* Check if the number of mapped NPorts changed */
2056 cnt = lpfc_find_map_node(vport);
2057 if (cnt == vport->fdmi_num_disc)
2060 if (vport->port_type == LPFC_PHYSICAL_PORT) {
2061 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RPA,
2062 LPFC_FDMI_PORT_ATTR_num_disc);
2064 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RPRT,
2065 LPFC_FDMI_PORT_ATTR_num_disc);
2069 /* Routines for all individual HBA attributes */
2071 lpfc_fdmi_hba_attr_wwnn(struct lpfc_vport *vport, struct lpfc_fdmi_attr_def *ad)
2073 struct lpfc_fdmi_attr_entry *ae;
2076 ae = &ad->AttrValue;
2077 memset(ae, 0, sizeof(*ae));
2079 memcpy(&ae->un.AttrWWN, &vport->fc_sparam.nodeName,
2080 sizeof(struct lpfc_name));
2081 size = FOURBYTES + sizeof(struct lpfc_name);
2082 ad->AttrLen = cpu_to_be16(size);
2083 ad->AttrType = cpu_to_be16(RHBA_NODENAME);
2087 lpfc_fdmi_hba_attr_manufacturer(struct lpfc_vport *vport,
2088 struct lpfc_fdmi_attr_def *ad)
2090 struct lpfc_fdmi_attr_entry *ae;
2093 ae = &ad->AttrValue;
2094 memset(ae, 0, sizeof(*ae));
2096 /* This string MUST be consistent with other FC platforms
2097 * supported by Broadcom.
2099 strncpy(ae->un.AttrString,
2100 "Emulex Corporation",
2101 sizeof(ae->un.AttrString));
2102 len = strnlen(ae->un.AttrString,
2103 sizeof(ae->un.AttrString));
2104 len += (len & 3) ? (4 - (len & 3)) : 4;
2105 size = FOURBYTES + len;
2106 ad->AttrLen = cpu_to_be16(size);
2107 ad->AttrType = cpu_to_be16(RHBA_MANUFACTURER);
2112 lpfc_fdmi_hba_attr_sn(struct lpfc_vport *vport, struct lpfc_fdmi_attr_def *ad)
2114 struct lpfc_hba *phba = vport->phba;
2115 struct lpfc_fdmi_attr_entry *ae;
2118 ae = &ad->AttrValue;
2119 memset(ae, 0, sizeof(*ae));
2121 strncpy(ae->un.AttrString, phba->SerialNumber,
2122 sizeof(ae->un.AttrString));
2123 len = strnlen(ae->un.AttrString,
2124 sizeof(ae->un.AttrString));
2125 len += (len & 3) ? (4 - (len & 3)) : 4;
2126 size = FOURBYTES + len;
2127 ad->AttrLen = cpu_to_be16(size);
2128 ad->AttrType = cpu_to_be16(RHBA_SERIAL_NUMBER);
2133 lpfc_fdmi_hba_attr_model(struct lpfc_vport *vport,
2134 struct lpfc_fdmi_attr_def *ad)
2136 struct lpfc_hba *phba = vport->phba;
2137 struct lpfc_fdmi_attr_entry *ae;
2140 ae = &ad->AttrValue;
2141 memset(ae, 0, sizeof(*ae));
2143 strncpy(ae->un.AttrString, phba->ModelName,
2144 sizeof(ae->un.AttrString));
2145 len = strnlen(ae->un.AttrString, sizeof(ae->un.AttrString));
2146 len += (len & 3) ? (4 - (len & 3)) : 4;
2147 size = FOURBYTES + len;
2148 ad->AttrLen = cpu_to_be16(size);
2149 ad->AttrType = cpu_to_be16(RHBA_MODEL);
2154 lpfc_fdmi_hba_attr_description(struct lpfc_vport *vport,
2155 struct lpfc_fdmi_attr_def *ad)
2157 struct lpfc_hba *phba = vport->phba;
2158 struct lpfc_fdmi_attr_entry *ae;
2161 ae = &ad->AttrValue;
2162 memset(ae, 0, sizeof(*ae));
2164 strncpy(ae->un.AttrString, phba->ModelDesc,
2165 sizeof(ae->un.AttrString));
2166 len = strnlen(ae->un.AttrString,
2167 sizeof(ae->un.AttrString));
2168 len += (len & 3) ? (4 - (len & 3)) : 4;
2169 size = FOURBYTES + len;
2170 ad->AttrLen = cpu_to_be16(size);
2171 ad->AttrType = cpu_to_be16(RHBA_MODEL_DESCRIPTION);
2176 lpfc_fdmi_hba_attr_hdw_ver(struct lpfc_vport *vport,
2177 struct lpfc_fdmi_attr_def *ad)
2179 struct lpfc_hba *phba = vport->phba;
2180 lpfc_vpd_t *vp = &phba->vpd;
2181 struct lpfc_fdmi_attr_entry *ae;
2182 uint32_t i, j, incr, size;
2184 ae = &ad->AttrValue;
2185 memset(ae, 0, sizeof(*ae));
2187 /* Convert JEDEC ID to ascii for hardware version */
2188 incr = vp->rev.biuRev;
2189 for (i = 0; i < 8; i++) {
2192 ae->un.AttrString[7 - i] =
2193 (char)((uint8_t) 0x30 +
2196 ae->un.AttrString[7 - i] =
2197 (char)((uint8_t) 0x61 +
2198 (uint8_t) (j - 10));
2201 size = FOURBYTES + 8;
2202 ad->AttrLen = cpu_to_be16(size);
2203 ad->AttrType = cpu_to_be16(RHBA_HARDWARE_VERSION);
2208 lpfc_fdmi_hba_attr_drvr_ver(struct lpfc_vport *vport,
2209 struct lpfc_fdmi_attr_def *ad)
2211 struct lpfc_fdmi_attr_entry *ae;
2214 ae = &ad->AttrValue;
2215 memset(ae, 0, sizeof(*ae));
2217 strncpy(ae->un.AttrString, lpfc_release_version,
2218 sizeof(ae->un.AttrString));
2219 len = strnlen(ae->un.AttrString,
2220 sizeof(ae->un.AttrString));
2221 len += (len & 3) ? (4 - (len & 3)) : 4;
2222 size = FOURBYTES + len;
2223 ad->AttrLen = cpu_to_be16(size);
2224 ad->AttrType = cpu_to_be16(RHBA_DRIVER_VERSION);
2229 lpfc_fdmi_hba_attr_rom_ver(struct lpfc_vport *vport,
2230 struct lpfc_fdmi_attr_def *ad)
2232 struct lpfc_hba *phba = vport->phba;
2233 struct lpfc_fdmi_attr_entry *ae;
2236 ae = &ad->AttrValue;
2237 memset(ae, 0, sizeof(*ae));
2239 if (phba->sli_rev == LPFC_SLI_REV4)
2240 lpfc_decode_firmware_rev(phba, ae->un.AttrString, 1);
2242 strncpy(ae->un.AttrString, phba->OptionROMVersion,
2243 sizeof(ae->un.AttrString));
2244 len = strnlen(ae->un.AttrString,
2245 sizeof(ae->un.AttrString));
2246 len += (len & 3) ? (4 - (len & 3)) : 4;
2247 size = FOURBYTES + len;
2248 ad->AttrLen = cpu_to_be16(size);
2249 ad->AttrType = cpu_to_be16(RHBA_OPTION_ROM_VERSION);
2254 lpfc_fdmi_hba_attr_fmw_ver(struct lpfc_vport *vport,
2255 struct lpfc_fdmi_attr_def *ad)
2257 struct lpfc_hba *phba = vport->phba;
2258 struct lpfc_fdmi_attr_entry *ae;
2261 ae = &ad->AttrValue;
2262 memset(ae, 0, sizeof(*ae));
2264 lpfc_decode_firmware_rev(phba, ae->un.AttrString, 1);
2265 len = strnlen(ae->un.AttrString,
2266 sizeof(ae->un.AttrString));
2267 len += (len & 3) ? (4 - (len & 3)) : 4;
2268 size = FOURBYTES + len;
2269 ad->AttrLen = cpu_to_be16(size);
2270 ad->AttrType = cpu_to_be16(RHBA_FIRMWARE_VERSION);
2275 lpfc_fdmi_hba_attr_os_ver(struct lpfc_vport *vport,
2276 struct lpfc_fdmi_attr_def *ad)
2278 struct lpfc_fdmi_attr_entry *ae;
2281 ae = &ad->AttrValue;
2282 memset(ae, 0, sizeof(*ae));
2284 snprintf(ae->un.AttrString, sizeof(ae->un.AttrString), "%s %s %s",
2285 init_utsname()->sysname,
2286 init_utsname()->release,
2287 init_utsname()->version);
2289 len = strnlen(ae->un.AttrString, sizeof(ae->un.AttrString));
2290 len += (len & 3) ? (4 - (len & 3)) : 4;
2291 size = FOURBYTES + len;
2292 ad->AttrLen = cpu_to_be16(size);
2293 ad->AttrType = cpu_to_be16(RHBA_OS_NAME_VERSION);
2298 lpfc_fdmi_hba_attr_ct_len(struct lpfc_vport *vport,
2299 struct lpfc_fdmi_attr_def *ad)
2301 struct lpfc_fdmi_attr_entry *ae;
2304 ae = &ad->AttrValue;
2306 ae->un.AttrInt = cpu_to_be32(LPFC_MAX_CT_SIZE);
2307 size = FOURBYTES + sizeof(uint32_t);
2308 ad->AttrLen = cpu_to_be16(size);
2309 ad->AttrType = cpu_to_be16(RHBA_MAX_CT_PAYLOAD_LEN);
2314 lpfc_fdmi_hba_attr_symbolic_name(struct lpfc_vport *vport,
2315 struct lpfc_fdmi_attr_def *ad)
2317 struct lpfc_fdmi_attr_entry *ae;
2320 ae = &ad->AttrValue;
2321 memset(ae, 0, sizeof(*ae));
2323 len = lpfc_vport_symbolic_node_name(vport,
2324 ae->un.AttrString, 256);
2325 len += (len & 3) ? (4 - (len & 3)) : 4;
2326 size = FOURBYTES + len;
2327 ad->AttrLen = cpu_to_be16(size);
2328 ad->AttrType = cpu_to_be16(RHBA_SYM_NODENAME);
2333 lpfc_fdmi_hba_attr_vendor_info(struct lpfc_vport *vport,
2334 struct lpfc_fdmi_attr_def *ad)
2336 struct lpfc_fdmi_attr_entry *ae;
2339 ae = &ad->AttrValue;
2341 /* Nothing is defined for this currently */
2342 ae->un.AttrInt = cpu_to_be32(0);
2343 size = FOURBYTES + sizeof(uint32_t);
2344 ad->AttrLen = cpu_to_be16(size);
2345 ad->AttrType = cpu_to_be16(RHBA_VENDOR_INFO);
2350 lpfc_fdmi_hba_attr_num_ports(struct lpfc_vport *vport,
2351 struct lpfc_fdmi_attr_def *ad)
2353 struct lpfc_fdmi_attr_entry *ae;
2356 ae = &ad->AttrValue;
2358 /* Each driver instance corresponds to a single port */
2359 ae->un.AttrInt = cpu_to_be32(1);
2360 size = FOURBYTES + sizeof(uint32_t);
2361 ad->AttrLen = cpu_to_be16(size);
2362 ad->AttrType = cpu_to_be16(RHBA_NUM_PORTS);
2367 lpfc_fdmi_hba_attr_fabric_wwnn(struct lpfc_vport *vport,
2368 struct lpfc_fdmi_attr_def *ad)
2370 struct lpfc_fdmi_attr_entry *ae;
2373 ae = &ad->AttrValue;
2374 memset(ae, 0, sizeof(*ae));
2376 memcpy(&ae->un.AttrWWN, &vport->fabric_nodename,
2377 sizeof(struct lpfc_name));
2378 size = FOURBYTES + sizeof(struct lpfc_name);
2379 ad->AttrLen = cpu_to_be16(size);
2380 ad->AttrType = cpu_to_be16(RHBA_FABRIC_WWNN);
2385 lpfc_fdmi_hba_attr_bios_ver(struct lpfc_vport *vport,
2386 struct lpfc_fdmi_attr_def *ad)
2388 struct lpfc_hba *phba = vport->phba;
2389 struct lpfc_fdmi_attr_entry *ae;
2392 ae = &ad->AttrValue;
2393 memset(ae, 0, sizeof(*ae));
2395 strlcat(ae->un.AttrString, phba->BIOSVersion,
2396 sizeof(ae->un.AttrString));
2397 len = strnlen(ae->un.AttrString,
2398 sizeof(ae->un.AttrString));
2399 len += (len & 3) ? (4 - (len & 3)) : 4;
2400 size = FOURBYTES + len;
2401 ad->AttrLen = cpu_to_be16(size);
2402 ad->AttrType = cpu_to_be16(RHBA_BIOS_VERSION);
2407 lpfc_fdmi_hba_attr_bios_state(struct lpfc_vport *vport,
2408 struct lpfc_fdmi_attr_def *ad)
2410 struct lpfc_fdmi_attr_entry *ae;
2413 ae = &ad->AttrValue;
2415 /* Driver doesn't have access to this information */
2416 ae->un.AttrInt = cpu_to_be32(0);
2417 size = FOURBYTES + sizeof(uint32_t);
2418 ad->AttrLen = cpu_to_be16(size);
2419 ad->AttrType = cpu_to_be16(RHBA_BIOS_STATE);
2424 lpfc_fdmi_hba_attr_vendor_id(struct lpfc_vport *vport,
2425 struct lpfc_fdmi_attr_def *ad)
2427 struct lpfc_fdmi_attr_entry *ae;
2430 ae = &ad->AttrValue;
2431 memset(ae, 0, sizeof(*ae));
2433 strncpy(ae->un.AttrString, "EMULEX",
2434 sizeof(ae->un.AttrString));
2435 len = strnlen(ae->un.AttrString,
2436 sizeof(ae->un.AttrString));
2437 len += (len & 3) ? (4 - (len & 3)) : 4;
2438 size = FOURBYTES + len;
2439 ad->AttrLen = cpu_to_be16(size);
2440 ad->AttrType = cpu_to_be16(RHBA_VENDOR_ID);
2444 /* Routines for all individual PORT attributes */
2446 lpfc_fdmi_port_attr_fc4type(struct lpfc_vport *vport,
2447 struct lpfc_fdmi_attr_def *ad)
2449 struct lpfc_hba *phba = vport->phba;
2450 struct lpfc_fdmi_attr_entry *ae;
2453 ae = &ad->AttrValue;
2454 memset(ae, 0, sizeof(*ae));
2456 ae->un.AttrTypes[2] = 0x01; /* Type 0x8 - FCP */
2457 ae->un.AttrTypes[7] = 0x01; /* Type 0x20 - CT */
2459 /* Check to see if Firmware supports NVME and on physical port */
2460 if ((phba->sli_rev == LPFC_SLI_REV4) && (vport == phba->pport) &&
2461 phba->sli4_hba.pc_sli4_params.nvme)
2462 ae->un.AttrTypes[6] = 0x01; /* Type 0x28 - NVME */
2464 size = FOURBYTES + 32;
2465 ad->AttrLen = cpu_to_be16(size);
2466 ad->AttrType = cpu_to_be16(RPRT_SUPPORTED_FC4_TYPES);
2471 lpfc_fdmi_port_attr_support_speed(struct lpfc_vport *vport,
2472 struct lpfc_fdmi_attr_def *ad)
2474 struct lpfc_hba *phba = vport->phba;
2475 struct lpfc_fdmi_attr_entry *ae;
2478 ae = &ad->AttrValue;
2481 if (!(phba->hba_flag & HBA_FCOE_MODE)) {
2482 if (phba->lmt & LMT_128Gb)
2483 ae->un.AttrInt |= HBA_PORTSPEED_128GFC;
2484 if (phba->lmt & LMT_64Gb)
2485 ae->un.AttrInt |= HBA_PORTSPEED_64GFC;
2486 if (phba->lmt & LMT_32Gb)
2487 ae->un.AttrInt |= HBA_PORTSPEED_32GFC;
2488 if (phba->lmt & LMT_16Gb)
2489 ae->un.AttrInt |= HBA_PORTSPEED_16GFC;
2490 if (phba->lmt & LMT_10Gb)
2491 ae->un.AttrInt |= HBA_PORTSPEED_10GFC;
2492 if (phba->lmt & LMT_8Gb)
2493 ae->un.AttrInt |= HBA_PORTSPEED_8GFC;
2494 if (phba->lmt & LMT_4Gb)
2495 ae->un.AttrInt |= HBA_PORTSPEED_4GFC;
2496 if (phba->lmt & LMT_2Gb)
2497 ae->un.AttrInt |= HBA_PORTSPEED_2GFC;
2498 if (phba->lmt & LMT_1Gb)
2499 ae->un.AttrInt |= HBA_PORTSPEED_1GFC;
2501 /* FCoE links support only one speed */
2502 switch (phba->fc_linkspeed) {
2503 case LPFC_ASYNC_LINK_SPEED_10GBPS:
2504 ae->un.AttrInt = HBA_PORTSPEED_10GE;
2506 case LPFC_ASYNC_LINK_SPEED_25GBPS:
2507 ae->un.AttrInt = HBA_PORTSPEED_25GE;
2509 case LPFC_ASYNC_LINK_SPEED_40GBPS:
2510 ae->un.AttrInt = HBA_PORTSPEED_40GE;
2512 case LPFC_ASYNC_LINK_SPEED_100GBPS:
2513 ae->un.AttrInt = HBA_PORTSPEED_100GE;
2517 ae->un.AttrInt = cpu_to_be32(ae->un.AttrInt);
2518 size = FOURBYTES + sizeof(uint32_t);
2519 ad->AttrLen = cpu_to_be16(size);
2520 ad->AttrType = cpu_to_be16(RPRT_SUPPORTED_SPEED);
2525 lpfc_fdmi_port_attr_speed(struct lpfc_vport *vport,
2526 struct lpfc_fdmi_attr_def *ad)
2528 struct lpfc_hba *phba = vport->phba;
2529 struct lpfc_fdmi_attr_entry *ae;
2532 ae = &ad->AttrValue;
2534 if (!(phba->hba_flag & HBA_FCOE_MODE)) {
2535 switch (phba->fc_linkspeed) {
2536 case LPFC_LINK_SPEED_1GHZ:
2537 ae->un.AttrInt = HBA_PORTSPEED_1GFC;
2539 case LPFC_LINK_SPEED_2GHZ:
2540 ae->un.AttrInt = HBA_PORTSPEED_2GFC;
2542 case LPFC_LINK_SPEED_4GHZ:
2543 ae->un.AttrInt = HBA_PORTSPEED_4GFC;
2545 case LPFC_LINK_SPEED_8GHZ:
2546 ae->un.AttrInt = HBA_PORTSPEED_8GFC;
2548 case LPFC_LINK_SPEED_10GHZ:
2549 ae->un.AttrInt = HBA_PORTSPEED_10GFC;
2551 case LPFC_LINK_SPEED_16GHZ:
2552 ae->un.AttrInt = HBA_PORTSPEED_16GFC;
2554 case LPFC_LINK_SPEED_32GHZ:
2555 ae->un.AttrInt = HBA_PORTSPEED_32GFC;
2557 case LPFC_LINK_SPEED_64GHZ:
2558 ae->un.AttrInt = HBA_PORTSPEED_64GFC;
2560 case LPFC_LINK_SPEED_128GHZ:
2561 ae->un.AttrInt = HBA_PORTSPEED_128GFC;
2564 ae->un.AttrInt = HBA_PORTSPEED_UNKNOWN;
2568 switch (phba->fc_linkspeed) {
2569 case LPFC_ASYNC_LINK_SPEED_10GBPS:
2570 ae->un.AttrInt = HBA_PORTSPEED_10GE;
2572 case LPFC_ASYNC_LINK_SPEED_25GBPS:
2573 ae->un.AttrInt = HBA_PORTSPEED_25GE;
2575 case LPFC_ASYNC_LINK_SPEED_40GBPS:
2576 ae->un.AttrInt = HBA_PORTSPEED_40GE;
2578 case LPFC_ASYNC_LINK_SPEED_100GBPS:
2579 ae->un.AttrInt = HBA_PORTSPEED_100GE;
2582 ae->un.AttrInt = HBA_PORTSPEED_UNKNOWN;
2587 ae->un.AttrInt = cpu_to_be32(ae->un.AttrInt);
2588 size = FOURBYTES + sizeof(uint32_t);
2589 ad->AttrLen = cpu_to_be16(size);
2590 ad->AttrType = cpu_to_be16(RPRT_PORT_SPEED);
2595 lpfc_fdmi_port_attr_max_frame(struct lpfc_vport *vport,
2596 struct lpfc_fdmi_attr_def *ad)
2598 struct serv_parm *hsp;
2599 struct lpfc_fdmi_attr_entry *ae;
2602 ae = &ad->AttrValue;
2604 hsp = (struct serv_parm *)&vport->fc_sparam;
2605 ae->un.AttrInt = (((uint32_t) hsp->cmn.bbRcvSizeMsb & 0x0F) << 8) |
2606 (uint32_t) hsp->cmn.bbRcvSizeLsb;
2607 ae->un.AttrInt = cpu_to_be32(ae->un.AttrInt);
2608 size = FOURBYTES + sizeof(uint32_t);
2609 ad->AttrLen = cpu_to_be16(size);
2610 ad->AttrType = cpu_to_be16(RPRT_MAX_FRAME_SIZE);
2615 lpfc_fdmi_port_attr_os_devname(struct lpfc_vport *vport,
2616 struct lpfc_fdmi_attr_def *ad)
2618 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2619 struct lpfc_fdmi_attr_entry *ae;
2622 ae = &ad->AttrValue;
2623 memset(ae, 0, sizeof(*ae));
2625 snprintf(ae->un.AttrString, sizeof(ae->un.AttrString),
2626 "/sys/class/scsi_host/host%d", shost->host_no);
2627 len = strnlen((char *)ae->un.AttrString,
2628 sizeof(ae->un.AttrString));
2629 len += (len & 3) ? (4 - (len & 3)) : 4;
2630 size = FOURBYTES + len;
2631 ad->AttrLen = cpu_to_be16(size);
2632 ad->AttrType = cpu_to_be16(RPRT_OS_DEVICE_NAME);
2637 lpfc_fdmi_port_attr_host_name(struct lpfc_vport *vport,
2638 struct lpfc_fdmi_attr_def *ad)
2640 struct lpfc_fdmi_attr_entry *ae;
2643 ae = &ad->AttrValue;
2644 memset(ae, 0, sizeof(*ae));
2646 scnprintf(ae->un.AttrString, sizeof(ae->un.AttrString), "%s",
2647 vport->phba->os_host_name);
2649 len = strnlen(ae->un.AttrString, sizeof(ae->un.AttrString));
2650 len += (len & 3) ? (4 - (len & 3)) : 4;
2651 size = FOURBYTES + len;
2652 ad->AttrLen = cpu_to_be16(size);
2653 ad->AttrType = cpu_to_be16(RPRT_HOST_NAME);
2658 lpfc_fdmi_port_attr_wwnn(struct lpfc_vport *vport,
2659 struct lpfc_fdmi_attr_def *ad)
2661 struct lpfc_fdmi_attr_entry *ae;
2664 ae = &ad->AttrValue;
2665 memset(ae, 0, sizeof(*ae));
2667 memcpy(&ae->un.AttrWWN, &vport->fc_sparam.nodeName,
2668 sizeof(struct lpfc_name));
2669 size = FOURBYTES + sizeof(struct lpfc_name);
2670 ad->AttrLen = cpu_to_be16(size);
2671 ad->AttrType = cpu_to_be16(RPRT_NODENAME);
2676 lpfc_fdmi_port_attr_wwpn(struct lpfc_vport *vport,
2677 struct lpfc_fdmi_attr_def *ad)
2679 struct lpfc_fdmi_attr_entry *ae;
2682 ae = &ad->AttrValue;
2683 memset(ae, 0, sizeof(*ae));
2685 memcpy(&ae->un.AttrWWN, &vport->fc_sparam.portName,
2686 sizeof(struct lpfc_name));
2687 size = FOURBYTES + sizeof(struct lpfc_name);
2688 ad->AttrLen = cpu_to_be16(size);
2689 ad->AttrType = cpu_to_be16(RPRT_PORTNAME);
2694 lpfc_fdmi_port_attr_symbolic_name(struct lpfc_vport *vport,
2695 struct lpfc_fdmi_attr_def *ad)
2697 struct lpfc_fdmi_attr_entry *ae;
2700 ae = &ad->AttrValue;
2701 memset(ae, 0, sizeof(*ae));
2703 len = lpfc_vport_symbolic_port_name(vport, ae->un.AttrString, 256);
2704 len += (len & 3) ? (4 - (len & 3)) : 4;
2705 size = FOURBYTES + len;
2706 ad->AttrLen = cpu_to_be16(size);
2707 ad->AttrType = cpu_to_be16(RPRT_SYM_PORTNAME);
2712 lpfc_fdmi_port_attr_port_type(struct lpfc_vport *vport,
2713 struct lpfc_fdmi_attr_def *ad)
2715 struct lpfc_hba *phba = vport->phba;
2716 struct lpfc_fdmi_attr_entry *ae;
2719 ae = &ad->AttrValue;
2720 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP)
2721 ae->un.AttrInt = cpu_to_be32(LPFC_FDMI_PORTTYPE_NLPORT);
2723 ae->un.AttrInt = cpu_to_be32(LPFC_FDMI_PORTTYPE_NPORT);
2724 size = FOURBYTES + sizeof(uint32_t);
2725 ad->AttrLen = cpu_to_be16(size);
2726 ad->AttrType = cpu_to_be16(RPRT_PORT_TYPE);
2731 lpfc_fdmi_port_attr_class(struct lpfc_vport *vport,
2732 struct lpfc_fdmi_attr_def *ad)
2734 struct lpfc_fdmi_attr_entry *ae;
2737 ae = &ad->AttrValue;
2738 ae->un.AttrInt = cpu_to_be32(FC_COS_CLASS2 | FC_COS_CLASS3);
2739 size = FOURBYTES + sizeof(uint32_t);
2740 ad->AttrLen = cpu_to_be16(size);
2741 ad->AttrType = cpu_to_be16(RPRT_SUPPORTED_CLASS);
2746 lpfc_fdmi_port_attr_fabric_wwpn(struct lpfc_vport *vport,
2747 struct lpfc_fdmi_attr_def *ad)
2749 struct lpfc_fdmi_attr_entry *ae;
2752 ae = &ad->AttrValue;
2753 memset(ae, 0, sizeof(*ae));
2755 memcpy(&ae->un.AttrWWN, &vport->fabric_portname,
2756 sizeof(struct lpfc_name));
2757 size = FOURBYTES + sizeof(struct lpfc_name);
2758 ad->AttrLen = cpu_to_be16(size);
2759 ad->AttrType = cpu_to_be16(RPRT_FABRICNAME);
2764 lpfc_fdmi_port_attr_active_fc4type(struct lpfc_vport *vport,
2765 struct lpfc_fdmi_attr_def *ad)
2767 struct lpfc_fdmi_attr_entry *ae;
2770 ae = &ad->AttrValue;
2771 memset(ae, 0, sizeof(*ae));
2773 ae->un.AttrTypes[2] = 0x01; /* Type 0x8 - FCP */
2774 ae->un.AttrTypes[7] = 0x01; /* Type 0x20 - CT */
2776 /* Check to see if NVME is configured or not */
2777 if (vport->phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)
2778 ae->un.AttrTypes[6] = 0x1; /* Type 0x28 - NVME */
2780 size = FOURBYTES + 32;
2781 ad->AttrLen = cpu_to_be16(size);
2782 ad->AttrType = cpu_to_be16(RPRT_ACTIVE_FC4_TYPES);
2787 lpfc_fdmi_port_attr_port_state(struct lpfc_vport *vport,
2788 struct lpfc_fdmi_attr_def *ad)
2790 struct lpfc_fdmi_attr_entry *ae;
2793 ae = &ad->AttrValue;
2794 /* Link Up - operational */
2795 ae->un.AttrInt = cpu_to_be32(LPFC_FDMI_PORTSTATE_ONLINE);
2796 size = FOURBYTES + sizeof(uint32_t);
2797 ad->AttrLen = cpu_to_be16(size);
2798 ad->AttrType = cpu_to_be16(RPRT_PORT_STATE);
2803 lpfc_fdmi_port_attr_num_disc(struct lpfc_vport *vport,
2804 struct lpfc_fdmi_attr_def *ad)
2806 struct lpfc_fdmi_attr_entry *ae;
2809 ae = &ad->AttrValue;
2810 vport->fdmi_num_disc = lpfc_find_map_node(vport);
2811 ae->un.AttrInt = cpu_to_be32(vport->fdmi_num_disc);
2812 size = FOURBYTES + sizeof(uint32_t);
2813 ad->AttrLen = cpu_to_be16(size);
2814 ad->AttrType = cpu_to_be16(RPRT_DISC_PORT);
2819 lpfc_fdmi_port_attr_nportid(struct lpfc_vport *vport,
2820 struct lpfc_fdmi_attr_def *ad)
2822 struct lpfc_fdmi_attr_entry *ae;
2825 ae = &ad->AttrValue;
2826 ae->un.AttrInt = cpu_to_be32(vport->fc_myDID);
2827 size = FOURBYTES + sizeof(uint32_t);
2828 ad->AttrLen = cpu_to_be16(size);
2829 ad->AttrType = cpu_to_be16(RPRT_PORT_ID);
2834 lpfc_fdmi_smart_attr_service(struct lpfc_vport *vport,
2835 struct lpfc_fdmi_attr_def *ad)
2837 struct lpfc_fdmi_attr_entry *ae;
2840 ae = &ad->AttrValue;
2841 memset(ae, 0, sizeof(*ae));
2843 strncpy(ae->un.AttrString, "Smart SAN Initiator",
2844 sizeof(ae->un.AttrString));
2845 len = strnlen(ae->un.AttrString,
2846 sizeof(ae->un.AttrString));
2847 len += (len & 3) ? (4 - (len & 3)) : 4;
2848 size = FOURBYTES + len;
2849 ad->AttrLen = cpu_to_be16(size);
2850 ad->AttrType = cpu_to_be16(RPRT_SMART_SERVICE);
2855 lpfc_fdmi_smart_attr_guid(struct lpfc_vport *vport,
2856 struct lpfc_fdmi_attr_def *ad)
2858 struct lpfc_fdmi_attr_entry *ae;
2861 ae = &ad->AttrValue;
2862 memset(ae, 0, sizeof(*ae));
2864 memcpy(&ae->un.AttrString, &vport->fc_sparam.nodeName,
2865 sizeof(struct lpfc_name));
2866 memcpy((((uint8_t *)&ae->un.AttrString) +
2867 sizeof(struct lpfc_name)),
2868 &vport->fc_sparam.portName, sizeof(struct lpfc_name));
2869 size = FOURBYTES + (2 * sizeof(struct lpfc_name));
2870 ad->AttrLen = cpu_to_be16(size);
2871 ad->AttrType = cpu_to_be16(RPRT_SMART_GUID);
2876 lpfc_fdmi_smart_attr_version(struct lpfc_vport *vport,
2877 struct lpfc_fdmi_attr_def *ad)
2879 struct lpfc_fdmi_attr_entry *ae;
2882 ae = &ad->AttrValue;
2883 memset(ae, 0, sizeof(*ae));
2885 strncpy(ae->un.AttrString, "Smart SAN Version 2.0",
2886 sizeof(ae->un.AttrString));
2887 len = strnlen(ae->un.AttrString,
2888 sizeof(ae->un.AttrString));
2889 len += (len & 3) ? (4 - (len & 3)) : 4;
2890 size = FOURBYTES + len;
2891 ad->AttrLen = cpu_to_be16(size);
2892 ad->AttrType = cpu_to_be16(RPRT_SMART_VERSION);
2897 lpfc_fdmi_smart_attr_model(struct lpfc_vport *vport,
2898 struct lpfc_fdmi_attr_def *ad)
2900 struct lpfc_hba *phba = vport->phba;
2901 struct lpfc_fdmi_attr_entry *ae;
2904 ae = &ad->AttrValue;
2905 memset(ae, 0, sizeof(*ae));
2907 strncpy(ae->un.AttrString, phba->ModelName,
2908 sizeof(ae->un.AttrString));
2909 len = strnlen(ae->un.AttrString, sizeof(ae->un.AttrString));
2910 len += (len & 3) ? (4 - (len & 3)) : 4;
2911 size = FOURBYTES + len;
2912 ad->AttrLen = cpu_to_be16(size);
2913 ad->AttrType = cpu_to_be16(RPRT_SMART_MODEL);
2918 lpfc_fdmi_smart_attr_port_info(struct lpfc_vport *vport,
2919 struct lpfc_fdmi_attr_def *ad)
2921 struct lpfc_fdmi_attr_entry *ae;
2924 ae = &ad->AttrValue;
2926 /* SRIOV (type 3) is not supported */
2928 ae->un.AttrInt = cpu_to_be32(2); /* NPIV */
2930 ae->un.AttrInt = cpu_to_be32(1); /* Physical */
2931 size = FOURBYTES + sizeof(uint32_t);
2932 ad->AttrLen = cpu_to_be16(size);
2933 ad->AttrType = cpu_to_be16(RPRT_SMART_PORT_INFO);
2938 lpfc_fdmi_smart_attr_qos(struct lpfc_vport *vport,
2939 struct lpfc_fdmi_attr_def *ad)
2941 struct lpfc_fdmi_attr_entry *ae;
2944 ae = &ad->AttrValue;
2945 ae->un.AttrInt = cpu_to_be32(0);
2946 size = FOURBYTES + sizeof(uint32_t);
2947 ad->AttrLen = cpu_to_be16(size);
2948 ad->AttrType = cpu_to_be16(RPRT_SMART_QOS);
2953 lpfc_fdmi_smart_attr_security(struct lpfc_vport *vport,
2954 struct lpfc_fdmi_attr_def *ad)
2956 struct lpfc_fdmi_attr_entry *ae;
2959 ae = &ad->AttrValue;
2960 ae->un.AttrInt = cpu_to_be32(1);
2961 size = FOURBYTES + sizeof(uint32_t);
2962 ad->AttrLen = cpu_to_be16(size);
2963 ad->AttrType = cpu_to_be16(RPRT_SMART_SECURITY);
2967 /* RHBA attribute jump table */
2968 int (*lpfc_fdmi_hba_action[])
2969 (struct lpfc_vport *vport, struct lpfc_fdmi_attr_def *ad) = {
2970 /* Action routine Mask bit Attribute type */
2971 lpfc_fdmi_hba_attr_wwnn, /* bit0 RHBA_NODENAME */
2972 lpfc_fdmi_hba_attr_manufacturer, /* bit1 RHBA_MANUFACTURER */
2973 lpfc_fdmi_hba_attr_sn, /* bit2 RHBA_SERIAL_NUMBER */
2974 lpfc_fdmi_hba_attr_model, /* bit3 RHBA_MODEL */
2975 lpfc_fdmi_hba_attr_description, /* bit4 RHBA_MODEL_DESCRIPTION */
2976 lpfc_fdmi_hba_attr_hdw_ver, /* bit5 RHBA_HARDWARE_VERSION */
2977 lpfc_fdmi_hba_attr_drvr_ver, /* bit6 RHBA_DRIVER_VERSION */
2978 lpfc_fdmi_hba_attr_rom_ver, /* bit7 RHBA_OPTION_ROM_VERSION */
2979 lpfc_fdmi_hba_attr_fmw_ver, /* bit8 RHBA_FIRMWARE_VERSION */
2980 lpfc_fdmi_hba_attr_os_ver, /* bit9 RHBA_OS_NAME_VERSION */
2981 lpfc_fdmi_hba_attr_ct_len, /* bit10 RHBA_MAX_CT_PAYLOAD_LEN */
2982 lpfc_fdmi_hba_attr_symbolic_name, /* bit11 RHBA_SYM_NODENAME */
2983 lpfc_fdmi_hba_attr_vendor_info, /* bit12 RHBA_VENDOR_INFO */
2984 lpfc_fdmi_hba_attr_num_ports, /* bit13 RHBA_NUM_PORTS */
2985 lpfc_fdmi_hba_attr_fabric_wwnn, /* bit14 RHBA_FABRIC_WWNN */
2986 lpfc_fdmi_hba_attr_bios_ver, /* bit15 RHBA_BIOS_VERSION */
2987 lpfc_fdmi_hba_attr_bios_state, /* bit16 RHBA_BIOS_STATE */
2988 lpfc_fdmi_hba_attr_vendor_id, /* bit17 RHBA_VENDOR_ID */
2991 /* RPA / RPRT attribute jump table */
2992 int (*lpfc_fdmi_port_action[])
2993 (struct lpfc_vport *vport, struct lpfc_fdmi_attr_def *ad) = {
2994 /* Action routine Mask bit Attribute type */
2995 lpfc_fdmi_port_attr_fc4type, /* bit0 RPRT_SUPPORT_FC4_TYPES */
2996 lpfc_fdmi_port_attr_support_speed, /* bit1 RPRT_SUPPORTED_SPEED */
2997 lpfc_fdmi_port_attr_speed, /* bit2 RPRT_PORT_SPEED */
2998 lpfc_fdmi_port_attr_max_frame, /* bit3 RPRT_MAX_FRAME_SIZE */
2999 lpfc_fdmi_port_attr_os_devname, /* bit4 RPRT_OS_DEVICE_NAME */
3000 lpfc_fdmi_port_attr_host_name, /* bit5 RPRT_HOST_NAME */
3001 lpfc_fdmi_port_attr_wwnn, /* bit6 RPRT_NODENAME */
3002 lpfc_fdmi_port_attr_wwpn, /* bit7 RPRT_PORTNAME */
3003 lpfc_fdmi_port_attr_symbolic_name, /* bit8 RPRT_SYM_PORTNAME */
3004 lpfc_fdmi_port_attr_port_type, /* bit9 RPRT_PORT_TYPE */
3005 lpfc_fdmi_port_attr_class, /* bit10 RPRT_SUPPORTED_CLASS */
3006 lpfc_fdmi_port_attr_fabric_wwpn, /* bit11 RPRT_FABRICNAME */
3007 lpfc_fdmi_port_attr_active_fc4type, /* bit12 RPRT_ACTIVE_FC4_TYPES */
3008 lpfc_fdmi_port_attr_port_state, /* bit13 RPRT_PORT_STATE */
3009 lpfc_fdmi_port_attr_num_disc, /* bit14 RPRT_DISC_PORT */
3010 lpfc_fdmi_port_attr_nportid, /* bit15 RPRT_PORT_ID */
3011 lpfc_fdmi_smart_attr_service, /* bit16 RPRT_SMART_SERVICE */
3012 lpfc_fdmi_smart_attr_guid, /* bit17 RPRT_SMART_GUID */
3013 lpfc_fdmi_smart_attr_version, /* bit18 RPRT_SMART_VERSION */
3014 lpfc_fdmi_smart_attr_model, /* bit19 RPRT_SMART_MODEL */
3015 lpfc_fdmi_smart_attr_port_info, /* bit20 RPRT_SMART_PORT_INFO */
3016 lpfc_fdmi_smart_attr_qos, /* bit21 RPRT_SMART_QOS */
3017 lpfc_fdmi_smart_attr_security, /* bit22 RPRT_SMART_SECURITY */
3021 * lpfc_fdmi_cmd - Build and send a FDMI cmd to the specified NPort
3022 * @vport: pointer to a host virtual N_Port data structure.
3023 * @ndlp: ndlp to send FDMI cmd to (if NULL use FDMI_DID)
3024 * cmdcode: FDMI command to send
3025 * mask: Mask of HBA or PORT Attributes to send
3027 * Builds and sends a FDMI command using the CT subsystem.
3030 lpfc_fdmi_cmd(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
3031 int cmdcode, uint32_t new_mask)
3033 struct lpfc_hba *phba = vport->phba;
3034 struct lpfc_dmabuf *mp, *bmp;
3035 struct lpfc_sli_ct_request *CtReq;
3036 struct ulp_bde64 *bpl;
3041 struct lpfc_fdmi_reg_hba *rh;
3042 struct lpfc_fdmi_port_entry *pe;
3043 struct lpfc_fdmi_reg_portattr *pab = NULL;
3044 struct lpfc_fdmi_attr_block *ab = NULL;
3045 int (*func)(struct lpfc_vport *vport, struct lpfc_fdmi_attr_def *ad);
3046 void (*cmpl)(struct lpfc_hba *, struct lpfc_iocbq *,
3047 struct lpfc_iocbq *);
3049 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
3052 cmpl = lpfc_cmpl_ct_disc_fdmi; /* called from discovery */
3054 /* fill in BDEs for command */
3055 /* Allocate buffer for command payload */
3056 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
3060 mp->virt = lpfc_mbuf_alloc(phba, 0, &(mp->phys));
3062 goto fdmi_cmd_free_mp;
3064 /* Allocate buffer for Buffer ptr list */
3065 bmp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
3067 goto fdmi_cmd_free_mpvirt;
3069 bmp->virt = lpfc_mbuf_alloc(phba, 0, &(bmp->phys));
3071 goto fdmi_cmd_free_bmp;
3073 INIT_LIST_HEAD(&mp->list);
3074 INIT_LIST_HEAD(&bmp->list);
3077 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
3078 "0218 FDMI Request Data: x%x x%x x%x\n",
3079 vport->fc_flag, vport->port_state, cmdcode);
3080 CtReq = (struct lpfc_sli_ct_request *)mp->virt;
3082 /* First populate the CT_IU preamble */
3083 memset(CtReq, 0, sizeof(struct lpfc_sli_ct_request));
3084 CtReq->RevisionId.bits.Revision = SLI_CT_REVISION;
3085 CtReq->RevisionId.bits.InId = 0;
3087 CtReq->FsType = SLI_CT_MANAGEMENT_SERVICE;
3088 CtReq->FsSubType = SLI_CT_FDMI_Subtypes;
3090 CtReq->CommandResponse.bits.CmdRsp = cpu_to_be16(cmdcode);
3091 rsp_size = LPFC_BPL_SIZE;
3094 /* Next fill in the specific FDMI cmd information */
3098 rh = (struct lpfc_fdmi_reg_hba *)&CtReq->un.PortID;
3099 /* HBA Identifier */
3100 memcpy(&rh->hi.PortName, &phba->pport->fc_sparam.portName,
3101 sizeof(struct lpfc_name));
3103 if (cmdcode == SLI_MGMT_RHBA) {
3104 /* Registered Port List */
3105 /* One entry (port) per adapter */
3106 rh->rpl.EntryCnt = cpu_to_be32(1);
3107 memcpy(&rh->rpl.pe.PortName,
3108 &phba->pport->fc_sparam.portName,
3109 sizeof(struct lpfc_name));
3111 /* point to the HBA attribute block */
3112 size = 2 * sizeof(struct lpfc_name) +
3115 size = sizeof(struct lpfc_name);
3117 ab = (struct lpfc_fdmi_attr_block *)((uint8_t *)rh + size);
3124 mask = vport->fdmi_hba_mask;
3126 /* Mask will dictate what attributes to build in the request */
3129 func = lpfc_fdmi_hba_action[bit_pos];
3131 (struct lpfc_fdmi_attr_def *)
3132 ((uint8_t *)rh + size));
3135 (LPFC_BPL_SIZE - LPFC_CT_PREAMBLE))
3142 ab->EntryCnt = cpu_to_be32(ab->EntryCnt);
3144 size = GID_REQUEST_SZ - 4 + size;
3149 pab = (struct lpfc_fdmi_reg_portattr *)&CtReq->un.PortID;
3150 if (cmdcode == SLI_MGMT_RPRT) {
3151 rh = (struct lpfc_fdmi_reg_hba *)pab;
3152 /* HBA Identifier */
3153 memcpy(&rh->hi.PortName,
3154 &phba->pport->fc_sparam.portName,
3155 sizeof(struct lpfc_name));
3156 pab = (struct lpfc_fdmi_reg_portattr *)
3157 ((uint8_t *)pab + sizeof(struct lpfc_name));
3160 memcpy((uint8_t *)&pab->PortName,
3161 (uint8_t *)&vport->fc_sparam.portName,
3162 sizeof(struct lpfc_name));
3163 size += sizeof(struct lpfc_name) + FOURBYTES;
3164 pab->ab.EntryCnt = 0;
3169 mask = vport->fdmi_port_mask;
3171 /* Mask will dictate what attributes to build in the request */
3174 func = lpfc_fdmi_port_action[bit_pos];
3176 (struct lpfc_fdmi_attr_def *)
3177 ((uint8_t *)pab + size));
3180 (LPFC_BPL_SIZE - LPFC_CT_PREAMBLE))
3187 pab->ab.EntryCnt = cpu_to_be32(pab->ab.EntryCnt);
3189 if (cmdcode == SLI_MGMT_RPRT)
3190 size += sizeof(struct lpfc_name);
3191 size = GID_REQUEST_SZ - 4 + size;
3196 rsp_size = FC_MAX_NS_RSP;
3200 pe = (struct lpfc_fdmi_port_entry *)&CtReq->un.PortID;
3201 memcpy((uint8_t *)&pe->PortName,
3202 (uint8_t *)&vport->fc_sparam.portName,
3203 sizeof(struct lpfc_name));
3204 size = GID_REQUEST_SZ - 4 + sizeof(struct lpfc_name);
3209 rsp_size = FC_MAX_NS_RSP;
3213 pe = (struct lpfc_fdmi_port_entry *)&CtReq->un.PortID;
3214 memcpy((uint8_t *)&pe->PortName,
3215 (uint8_t *)&vport->fc_sparam.portName,
3216 sizeof(struct lpfc_name));
3217 size = GID_REQUEST_SZ - 4 + sizeof(struct lpfc_name);
3220 size = GID_REQUEST_SZ - 4;
3223 lpfc_printf_vlog(vport, KERN_WARNING, LOG_DISCOVERY,
3224 "0298 FDMI cmdcode x%x not supported\n",
3226 goto fdmi_cmd_free_bmpvirt;
3228 CtReq->CommandResponse.bits.Size = cpu_to_be16(rsp_size);
3230 bpl = (struct ulp_bde64 *)bmp->virt;
3231 bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys));
3232 bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys));
3233 bpl->tus.f.bdeFlags = 0;
3234 bpl->tus.f.bdeSize = size;
3237 * The lpfc_ct_cmd/lpfc_get_req shall increment ndlp reference count
3238 * to hold ndlp reference for the corresponding callback function.
3240 if (!lpfc_ct_cmd(vport, mp, bmp, ndlp, cmpl, rsp_size, 0))
3244 * Decrement ndlp reference count to release ndlp reference held
3245 * for the failed command's callback function.
3249 fdmi_cmd_free_bmpvirt:
3250 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
3253 fdmi_cmd_free_mpvirt:
3254 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3258 /* Issue FDMI request failed */
3259 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
3260 "0244 Issue FDMI request failed Data: x%x\n",
3266 * lpfc_delayed_disc_tmo - Timeout handler for delayed discovery timer.
3267 * @ptr - Context object of the timer.
3269 * This function set the WORKER_DELAYED_DISC_TMO flag and wake up
3270 * the worker thread.
3273 lpfc_delayed_disc_tmo(struct timer_list *t)
3275 struct lpfc_vport *vport = from_timer(vport, t, delayed_disc_tmo);
3276 struct lpfc_hba *phba = vport->phba;
3277 uint32_t tmo_posted;
3278 unsigned long iflag;
3280 spin_lock_irqsave(&vport->work_port_lock, iflag);
3281 tmo_posted = vport->work_port_events & WORKER_DELAYED_DISC_TMO;
3283 vport->work_port_events |= WORKER_DELAYED_DISC_TMO;
3284 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
3287 lpfc_worker_wake_up(phba);
3292 * lpfc_delayed_disc_timeout_handler - Function called by worker thread to
3293 * handle delayed discovery.
3294 * @vport: pointer to a host virtual N_Port data structure.
3296 * This function start nport discovery of the vport.
3299 lpfc_delayed_disc_timeout_handler(struct lpfc_vport *vport)
3301 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3303 spin_lock_irq(shost->host_lock);
3304 if (!(vport->fc_flag & FC_DISC_DELAYED)) {
3305 spin_unlock_irq(shost->host_lock);
3308 vport->fc_flag &= ~FC_DISC_DELAYED;
3309 spin_unlock_irq(shost->host_lock);
3311 lpfc_do_scr_ns_plogi(vport->phba, vport);
3315 lpfc_decode_firmware_rev(struct lpfc_hba *phba, char *fwrevision, int flag)
3317 struct lpfc_sli *psli = &phba->sli;
3318 lpfc_vpd_t *vp = &phba->vpd;
3319 uint32_t b1, b2, b3, b4, i, rev;
3321 uint32_t *ptr, str[4];
3324 if (phba->sli_rev == LPFC_SLI_REV4)
3325 snprintf(fwrevision, FW_REV_STR_SIZE, "%s", vp->rev.opFwName);
3326 else if (vp->rev.rBit) {
3327 if (psli->sli_flag & LPFC_SLI_ACTIVE)
3328 rev = vp->rev.sli2FwRev;
3330 rev = vp->rev.sli1FwRev;
3332 b1 = (rev & 0x0000f000) >> 12;
3333 b2 = (rev & 0x00000f00) >> 8;
3334 b3 = (rev & 0x000000c0) >> 6;
3335 b4 = (rev & 0x00000030) >> 4;
3354 b4 = (rev & 0x0000000f);
3356 if (psli->sli_flag & LPFC_SLI_ACTIVE)
3357 fwname = vp->rev.sli2FwName;
3359 fwname = vp->rev.sli1FwName;
3361 for (i = 0; i < 16; i++)
3362 if (fwname[i] == 0x20)
3365 ptr = (uint32_t*)fwname;
3367 for (i = 0; i < 3; i++)
3368 str[i] = be32_to_cpu(*ptr++);
3372 sprintf(fwrevision, "%d.%d%d (%s)",
3373 b1, b2, b3, (char *)str);
3375 sprintf(fwrevision, "%d.%d%d", b1,
3379 sprintf(fwrevision, "%d.%d%d%c%d (%s)",
3383 sprintf(fwrevision, "%d.%d%d%c%d",
3387 rev = vp->rev.smFwRev;
3389 b1 = (rev & 0xff000000) >> 24;
3390 b2 = (rev & 0x00f00000) >> 20;
3391 b3 = (rev & 0x000f0000) >> 16;
3392 c = (rev & 0x0000ff00) >> 8;
3393 b4 = (rev & 0x000000ff);
3395 sprintf(fwrevision, "%d.%d%d%c%d", b1, b2, b3, c, b4);