1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2017-2018 Broadcom. All Rights Reserved. The term *
5 * “Broadcom” refers to Broadcom 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->hbalock, flags);
449 list_for_each_entry(vport_curr, &phba->port_list, listentry) {
450 if ((vport_curr->fc_myDID) && (vport_curr->fc_myDID == did)) {
451 spin_unlock_irqrestore(&phba->hbalock, flags);
455 spin_unlock_irqrestore(&phba->hbalock, 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 !(vport->ct_flags & FC_CT_RFF_ID) || !vport->cfg_restrict_login) {
467 ndlp = lpfc_setup_disc_node(vport, Did);
469 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
470 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
471 "Parse GID_FTrsp: did:x%x flg:x%x x%x",
472 Did, ndlp->nlp_flag, vport->fc_flag);
474 /* Don't assume the rport is always the previous
477 ndlp->nlp_fc4_type &= ~(NLP_FC4_FCP | NLP_FC4_NVME);
479 /* By default, the driver expects to support FCP FC4 */
480 if (fc4_type == FC_TYPE_FCP)
481 ndlp->nlp_fc4_type |= NLP_FC4_FCP;
483 if (fc4_type == FC_TYPE_NVME)
484 ndlp->nlp_fc4_type |= NLP_FC4_NVME;
486 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
487 "0238 Process x%06x NameServer Rsp "
488 "Data: x%x x%x x%x x%x\n", Did,
489 ndlp->nlp_flag, ndlp->nlp_fc4_type,
491 vport->fc_rscn_id_cnt);
493 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
494 "Skip1 GID_FTrsp: did:x%x flg:x%x cnt:%d",
495 Did, vport->fc_flag, vport->fc_rscn_id_cnt);
497 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
498 "0239 Skip x%06x NameServer Rsp "
499 "Data: x%x x%x\n", Did,
501 vport->fc_rscn_id_cnt);
504 if (!(vport->fc_flag & FC_RSCN_MODE) ||
505 lpfc_rscn_payload_check(vport, Did)) {
506 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
507 "Query GID_FTrsp: did:x%x flg:x%x cnt:%d",
508 Did, vport->fc_flag, vport->fc_rscn_id_cnt);
511 * This NPortID was previously a FCP/NVMe target,
512 * Don't even bother to send GFF_ID.
514 ndlp = lpfc_findnode_did(vport, Did);
515 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
517 (NLP_FCP_TARGET | NLP_NVME_TARGET))) {
518 if (fc4_type == FC_TYPE_FCP)
519 ndlp->nlp_fc4_type |= NLP_FC4_FCP;
520 if (fc4_type == FC_TYPE_NVME)
521 ndlp->nlp_fc4_type |= NLP_FC4_NVME;
522 lpfc_setup_disc_node(vport, Did);
523 } else if (lpfc_ns_cmd(vport, SLI_CTNS_GFF_ID,
525 vport->num_disc_nodes++;
527 lpfc_setup_disc_node(vport, Did);
529 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
530 "Skip2 GID_FTrsp: did:x%x flg:x%x cnt:%d",
531 Did, vport->fc_flag, vport->fc_rscn_id_cnt);
533 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
534 "0245 Skip x%06x NameServer Rsp "
535 "Data: x%x x%x\n", Did,
537 vport->fc_rscn_id_cnt);
543 lpfc_ns_rsp_audit_did(struct lpfc_vport *vport, uint32_t Did, uint8_t fc4_type)
545 struct lpfc_hba *phba = vport->phba;
546 struct lpfc_nodelist *ndlp = NULL;
547 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
550 * To conserve rpi's, filter out addresses for other
551 * vports on the same physical HBAs.
553 if (Did != vport->fc_myDID &&
554 (!lpfc_find_vport_by_did(phba, Did) ||
555 vport->cfg_peer_port_login)) {
556 if (!phba->nvmet_support) {
557 /* FCPI/NVMEI path. Process Did */
558 lpfc_prep_node_fc4type(vport, Did, fc4_type);
561 /* NVMET path. NVMET only cares about NVMEI nodes. */
562 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
563 if (ndlp->nlp_type != NLP_NVME_INITIATOR ||
564 ndlp->nlp_state != NLP_STE_UNMAPPED_NODE)
566 spin_lock_irq(shost->host_lock);
567 if (ndlp->nlp_DID == Did)
568 ndlp->nlp_flag &= ~NLP_NVMET_RECOV;
570 ndlp->nlp_flag |= NLP_NVMET_RECOV;
571 spin_unlock_irq(shost->host_lock);
577 lpfc_ns_rsp(struct lpfc_vport *vport, struct lpfc_dmabuf *mp, uint8_t fc4_type,
580 struct lpfc_sli_ct_request *Response =
581 (struct lpfc_sli_ct_request *) mp->virt;
582 struct lpfc_dmabuf *mlast, *next_mp;
583 uint32_t *ctptr = (uint32_t *) & Response->un.gid.PortType;
584 uint32_t Did, CTentry;
586 struct list_head head;
587 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
588 struct lpfc_nodelist *ndlp = NULL;
590 lpfc_set_disctmo(vport);
591 vport->num_disc_nodes = 0;
592 vport->fc_ns_retry = 0;
595 list_add_tail(&head, &mp->list);
596 list_for_each_entry_safe(mp, next_mp, &head, list) {
599 Cnt = Size > FCELSSIZE ? FCELSSIZE : Size;
604 ctptr = (uint32_t *) mlast->virt;
606 Cnt -= 16; /* subtract length of CT header */
608 /* Loop through entire NameServer list of DIDs */
609 while (Cnt >= sizeof(uint32_t)) {
610 /* Get next DID from NameServer List */
612 Did = ((be32_to_cpu(CTentry)) & Mask_DID);
613 lpfc_ns_rsp_audit_did(vport, Did, fc4_type);
614 if (CTentry & (cpu_to_be32(SLI_CT_LAST_ENTRY)))
617 Cnt -= sizeof(uint32_t);
623 /* All GID_FT entries processed. If the driver is running in
624 * in target mode, put impacted nodes into recovery and drop
625 * the RPI to flush outstanding IO.
627 if (vport->phba->nvmet_support) {
628 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
629 if (!(ndlp->nlp_flag & NLP_NVMET_RECOV))
631 lpfc_disc_state_machine(vport, ndlp, NULL,
632 NLP_EVT_DEVICE_RECOVERY);
633 spin_lock_irq(shost->host_lock);
634 ndlp->nlp_flag &= ~NLP_NVMET_RECOV;
635 spin_unlock_irq(shost->host_lock);
645 lpfc_cmpl_ct_cmd_gid_ft(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
646 struct lpfc_iocbq *rspiocb)
648 struct lpfc_vport *vport = cmdiocb->vport;
649 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
651 struct lpfc_dmabuf *outp;
652 struct lpfc_dmabuf *inp;
653 struct lpfc_sli_ct_request *CTrsp;
654 struct lpfc_sli_ct_request *CTreq;
655 struct lpfc_nodelist *ndlp;
658 /* First save ndlp, before we overwrite it */
659 ndlp = cmdiocb->context_un.ndlp;
661 /* we pass cmdiocb to state machine which needs rspiocb as well */
662 cmdiocb->context_un.rsp_iocb = rspiocb;
663 inp = (struct lpfc_dmabuf *) cmdiocb->context1;
664 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
665 irsp = &rspiocb->iocb;
667 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
668 "GID_FT cmpl: status:x%x/x%x rtry:%d",
669 irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_ns_retry);
671 /* Don't bother processing response if vport is being torn down. */
672 if (vport->load_flag & FC_UNLOADING) {
673 if (vport->fc_flag & FC_RSCN_MODE)
674 lpfc_els_flush_rscn(vport);
678 if (lpfc_els_chk_latt(vport)) {
679 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
680 "0216 Link event during NS query\n");
681 if (vport->fc_flag & FC_RSCN_MODE)
682 lpfc_els_flush_rscn(vport);
683 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
686 if (lpfc_error_lost_link(irsp)) {
687 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
688 "0226 NS query failed due to link event\n");
689 if (vport->fc_flag & FC_RSCN_MODE)
690 lpfc_els_flush_rscn(vport);
694 spin_lock_irq(shost->host_lock);
695 if (vport->fc_flag & FC_RSCN_DEFERRED) {
696 vport->fc_flag &= ~FC_RSCN_DEFERRED;
697 spin_unlock_irq(shost->host_lock);
699 /* This is a GID_FT completing so the gidft_inp counter was
700 * incremented before the GID_FT was issued to the wire.
705 * Skip processing the NS response
706 * Re-issue the NS cmd
708 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
709 "0151 Process Deferred RSCN Data: x%x x%x\n",
710 vport->fc_flag, vport->fc_rscn_id_cnt);
711 lpfc_els_handle_rscn(vport);
715 spin_unlock_irq(shost->host_lock);
717 if (irsp->ulpStatus) {
718 /* Check for retry */
719 if (vport->fc_ns_retry < LPFC_MAX_NS_RETRY) {
720 if (irsp->ulpStatus != IOSTAT_LOCAL_REJECT ||
721 (irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
723 vport->fc_ns_retry++;
725 type = lpfc_get_gidft_type(vport, cmdiocb);
729 /* CT command is being retried */
731 rc = lpfc_ns_cmd(vport, SLI_CTNS_GID_FT,
732 vport->fc_ns_retry, type);
736 if (vport->fc_flag & FC_RSCN_MODE)
737 lpfc_els_flush_rscn(vport);
738 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
739 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
740 "0257 GID_FT Query error: 0x%x 0x%x\n",
741 irsp->ulpStatus, vport->fc_ns_retry);
743 /* Good status, continue checking */
744 CTreq = (struct lpfc_sli_ct_request *) inp->virt;
745 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
746 if (CTrsp->CommandResponse.bits.CmdRsp ==
747 cpu_to_be16(SLI_CT_RESPONSE_FS_ACC)) {
748 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
749 "0208 NameServer Rsp Data: x%x x%x\n",
751 CTreq->un.gid.Fc4Type);
755 CTreq->un.gid.Fc4Type,
756 (uint32_t) (irsp->un.genreq64.bdl.bdeSize));
757 } else if (CTrsp->CommandResponse.bits.CmdRsp ==
758 be16_to_cpu(SLI_CT_RESPONSE_FS_RJT)) {
759 /* NameServer Rsp Error */
760 if ((CTrsp->ReasonCode == SLI_CT_UNABLE_TO_PERFORM_REQ)
761 && (CTrsp->Explanation == SLI_CT_NO_FC4_TYPES)) {
762 lpfc_printf_vlog(vport, KERN_INFO,
764 "0269 No NameServer Entries "
765 "Data: x%x x%x x%x x%x\n",
766 CTrsp->CommandResponse.bits.CmdRsp,
767 (uint32_t) CTrsp->ReasonCode,
768 (uint32_t) CTrsp->Explanation,
771 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
772 "GID_FT no entry cmd:x%x rsn:x%x exp:x%x",
773 (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
774 (uint32_t) CTrsp->ReasonCode,
775 (uint32_t) CTrsp->Explanation);
777 lpfc_printf_vlog(vport, KERN_INFO,
779 "0240 NameServer Rsp Error "
780 "Data: x%x x%x x%x x%x\n",
781 CTrsp->CommandResponse.bits.CmdRsp,
782 (uint32_t) CTrsp->ReasonCode,
783 (uint32_t) CTrsp->Explanation,
786 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
787 "GID_FT rsp err1 cmd:x%x rsn:x%x exp:x%x",
788 (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
789 (uint32_t) CTrsp->ReasonCode,
790 (uint32_t) CTrsp->Explanation);
795 /* NameServer Rsp Error */
796 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
797 "0241 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 err2 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);
812 /* Link up / RSCN discovery */
813 if ((vport->num_disc_nodes == 0) &&
814 (vport->gidft_inp == 0)) {
816 * The driver has cycled through all Nports in the RSCN payload.
817 * Complete the handling by cleaning up and marking the
818 * current driver state.
820 if (vport->port_state >= LPFC_DISC_AUTH) {
821 if (vport->fc_flag & FC_RSCN_MODE) {
822 lpfc_els_flush_rscn(vport);
823 spin_lock_irq(shost->host_lock);
824 vport->fc_flag |= FC_RSCN_MODE; /* RSCN still */
825 spin_unlock_irq(shost->host_lock);
828 lpfc_els_flush_rscn(vport);
831 lpfc_disc_start(vport);
834 cmdiocb->context_un.ndlp = ndlp; /* Now restore ndlp for free */
835 lpfc_ct_free_iocb(phba, cmdiocb);
840 lpfc_cmpl_ct_cmd_gff_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
841 struct lpfc_iocbq *rspiocb)
843 struct lpfc_vport *vport = cmdiocb->vport;
844 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
845 IOCB_t *irsp = &rspiocb->iocb;
846 struct lpfc_dmabuf *inp = (struct lpfc_dmabuf *) cmdiocb->context1;
847 struct lpfc_dmabuf *outp = (struct lpfc_dmabuf *) cmdiocb->context2;
848 struct lpfc_sli_ct_request *CTrsp;
851 struct lpfc_nodelist *ndlp;
853 did = ((struct lpfc_sli_ct_request *) inp->virt)->un.gff.PortId;
854 did = be32_to_cpu(did);
856 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
857 "GFF_ID cmpl: status:x%x/x%x did:x%x",
858 irsp->ulpStatus, irsp->un.ulpWord[4], did);
860 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
861 /* Good status, continue checking */
862 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
863 fbits = CTrsp->un.gff_acc.fbits[FCP_TYPE_FEATURE_OFFSET];
865 if (CTrsp->CommandResponse.bits.CmdRsp ==
866 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC)) {
867 if ((fbits & FC4_FEATURE_INIT) &&
868 !(fbits & FC4_FEATURE_TARGET)) {
869 lpfc_printf_vlog(vport, KERN_INFO,
872 "NameServer Rsp Data: (init) "
873 "x%x x%x\n", did, fbits,
874 vport->fc_rscn_id_cnt);
880 /* Check for retry */
881 if (cmdiocb->retry < LPFC_MAX_NS_RETRY) {
883 if (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) {
884 switch ((irsp->un.ulpWord[4] &
887 case IOERR_NO_RESOURCES:
888 /* We don't increment the retry
889 * count for this case.
892 case IOERR_LINK_DOWN:
893 case IOERR_SLI_ABORTED:
905 /* CT command is being retried */
906 rc = lpfc_ns_cmd(vport, SLI_CTNS_GFF_ID,
907 cmdiocb->retry, did);
910 lpfc_ct_free_iocb(phba, cmdiocb);
915 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
916 "0267 NameServer GFF Rsp "
917 "x%x Error (%d %d) Data: x%x x%x\n",
918 did, irsp->ulpStatus, irsp->un.ulpWord[4],
919 vport->fc_flag, vport->fc_rscn_id_cnt);
922 /* This is a target port, unregistered port, or the GFF_ID failed */
923 ndlp = lpfc_setup_disc_node(vport, did);
924 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
925 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
926 "0242 Process x%x GFF "
927 "NameServer Rsp Data: x%x x%x x%x\n",
928 did, ndlp->nlp_flag, vport->fc_flag,
929 vport->fc_rscn_id_cnt);
931 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
933 "NameServer Rsp Data: x%x x%x\n", did,
934 vport->fc_flag, vport->fc_rscn_id_cnt);
937 /* Link up / RSCN discovery */
938 if (vport->num_disc_nodes)
939 vport->num_disc_nodes--;
940 if (vport->num_disc_nodes == 0) {
942 * The driver has cycled through all Nports in the RSCN payload.
943 * Complete the handling by cleaning up and marking the
944 * current driver state.
946 if (vport->port_state >= LPFC_DISC_AUTH) {
947 if (vport->fc_flag & FC_RSCN_MODE) {
948 lpfc_els_flush_rscn(vport);
949 spin_lock_irq(shost->host_lock);
950 vport->fc_flag |= FC_RSCN_MODE; /* RSCN still */
951 spin_unlock_irq(shost->host_lock);
954 lpfc_els_flush_rscn(vport);
956 lpfc_disc_start(vport);
958 lpfc_ct_free_iocb(phba, cmdiocb);
963 lpfc_cmpl_ct_cmd_gft_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
964 struct lpfc_iocbq *rspiocb)
966 struct lpfc_vport *vport = cmdiocb->vport;
967 IOCB_t *irsp = &rspiocb->iocb;
968 struct lpfc_dmabuf *inp = (struct lpfc_dmabuf *)cmdiocb->context1;
969 struct lpfc_dmabuf *outp = (struct lpfc_dmabuf *)cmdiocb->context2;
970 struct lpfc_sli_ct_request *CTrsp;
972 struct lpfc_nodelist *ndlp;
973 uint32_t fc4_data_0, fc4_data_1;
975 did = ((struct lpfc_sli_ct_request *)inp->virt)->un.gft.PortId;
976 did = be32_to_cpu(did);
978 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
979 "GFT_ID cmpl: status:x%x/x%x did:x%x",
980 irsp->ulpStatus, irsp->un.ulpWord[4], did);
982 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
983 /* Good status, continue checking */
984 CTrsp = (struct lpfc_sli_ct_request *)outp->virt;
985 fc4_data_0 = be32_to_cpu(CTrsp->un.gft_acc.fc4_types[0]);
986 fc4_data_1 = be32_to_cpu(CTrsp->un.gft_acc.fc4_types[1]);
987 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
988 "3062 DID x%06x GFT Wd0 x%08x Wd1 x%08x\n",
989 did, fc4_data_0, fc4_data_1);
991 ndlp = lpfc_findnode_did(vport, did);
993 /* The bitmask value for FCP and NVME FCP types is
994 * the same because they are 32 bits distant from
995 * each other in word0 and word0.
997 if (fc4_data_0 & LPFC_FC4_TYPE_BITMASK)
998 ndlp->nlp_fc4_type |= NLP_FC4_FCP;
999 if (fc4_data_1 & LPFC_FC4_TYPE_BITMASK)
1000 ndlp->nlp_fc4_type |= NLP_FC4_NVME;
1001 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1002 "3064 Setting ndlp %p, DID x%06x with "
1003 "FC4 x%08x, Data: x%08x x%08x\n",
1004 ndlp, did, ndlp->nlp_fc4_type,
1005 FC_TYPE_FCP, FC_TYPE_NVME);
1006 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1008 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
1009 lpfc_issue_els_prli(vport, ndlp, 0);
1012 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
1013 "3065 GFT_ID failed x%08x\n", irsp->ulpStatus);
1015 lpfc_ct_free_iocb(phba, cmdiocb);
1019 lpfc_cmpl_ct(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1020 struct lpfc_iocbq *rspiocb)
1022 struct lpfc_vport *vport = cmdiocb->vport;
1023 struct lpfc_dmabuf *inp;
1024 struct lpfc_dmabuf *outp;
1026 struct lpfc_sli_ct_request *CTrsp;
1027 struct lpfc_nodelist *ndlp;
1032 /* First save ndlp, before we overwrite it */
1033 ndlp = cmdiocb->context_un.ndlp;
1035 /* we pass cmdiocb to state machine which needs rspiocb as well */
1036 cmdiocb->context_un.rsp_iocb = rspiocb;
1038 inp = (struct lpfc_dmabuf *) cmdiocb->context1;
1039 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
1040 irsp = &rspiocb->iocb;
1042 cmdcode = be16_to_cpu(((struct lpfc_sli_ct_request *) inp->virt)->
1043 CommandResponse.bits.CmdRsp);
1044 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
1046 latt = lpfc_els_chk_latt(vport);
1048 /* RFT request completes status <ulpStatus> CmdRsp <CmdRsp> */
1049 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1050 "0209 CT Request completes, latt %d, "
1051 "ulpStatus x%x CmdRsp x%x, Context x%x, Tag x%x\n",
1052 latt, irsp->ulpStatus,
1053 CTrsp->CommandResponse.bits.CmdRsp,
1054 cmdiocb->iocb.ulpContext, cmdiocb->iocb.ulpIoTag);
1056 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
1057 "CT cmd cmpl: status:x%x/x%x cmd:x%x",
1058 irsp->ulpStatus, irsp->un.ulpWord[4], cmdcode);
1060 if (irsp->ulpStatus) {
1061 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
1062 "0268 NS cmd x%x Error (x%x x%x)\n",
1063 cmdcode, irsp->ulpStatus, irsp->un.ulpWord[4]);
1065 if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
1066 (((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
1068 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
1069 IOERR_SLI_ABORTED)))
1072 retry = cmdiocb->retry;
1073 if (retry >= LPFC_MAX_NS_RETRY)
1077 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1078 "0250 Retrying NS cmd %x\n", cmdcode);
1079 rc = lpfc_ns_cmd(vport, cmdcode, retry, 0);
1085 cmdiocb->context_un.ndlp = ndlp; /* Now restore ndlp for free */
1086 lpfc_ct_free_iocb(phba, cmdiocb);
1091 lpfc_cmpl_ct_cmd_rft_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1092 struct lpfc_iocbq *rspiocb)
1094 IOCB_t *irsp = &rspiocb->iocb;
1095 struct lpfc_vport *vport = cmdiocb->vport;
1097 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
1098 struct lpfc_dmabuf *outp;
1099 struct lpfc_sli_ct_request *CTrsp;
1101 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
1102 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
1103 if (CTrsp->CommandResponse.bits.CmdRsp ==
1104 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
1105 vport->ct_flags |= FC_CT_RFT_ID;
1107 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
1112 lpfc_cmpl_ct_cmd_rnn_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1113 struct lpfc_iocbq *rspiocb)
1115 IOCB_t *irsp = &rspiocb->iocb;
1116 struct lpfc_vport *vport = cmdiocb->vport;
1118 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
1119 struct lpfc_dmabuf *outp;
1120 struct lpfc_sli_ct_request *CTrsp;
1122 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
1123 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
1124 if (CTrsp->CommandResponse.bits.CmdRsp ==
1125 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
1126 vport->ct_flags |= FC_CT_RNN_ID;
1128 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
1133 lpfc_cmpl_ct_cmd_rspn_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1134 struct lpfc_iocbq *rspiocb)
1136 IOCB_t *irsp = &rspiocb->iocb;
1137 struct lpfc_vport *vport = cmdiocb->vport;
1139 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
1140 struct lpfc_dmabuf *outp;
1141 struct lpfc_sli_ct_request *CTrsp;
1143 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
1144 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
1145 if (CTrsp->CommandResponse.bits.CmdRsp ==
1146 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
1147 vport->ct_flags |= FC_CT_RSPN_ID;
1149 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
1154 lpfc_cmpl_ct_cmd_rsnn_nn(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1155 struct lpfc_iocbq *rspiocb)
1157 IOCB_t *irsp = &rspiocb->iocb;
1158 struct lpfc_vport *vport = cmdiocb->vport;
1160 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
1161 struct lpfc_dmabuf *outp;
1162 struct lpfc_sli_ct_request *CTrsp;
1164 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
1165 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
1166 if (CTrsp->CommandResponse.bits.CmdRsp ==
1167 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
1168 vport->ct_flags |= FC_CT_RSNN_NN;
1170 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
1175 lpfc_cmpl_ct_cmd_da_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1176 struct lpfc_iocbq *rspiocb)
1178 struct lpfc_vport *vport = cmdiocb->vport;
1180 /* even if it fails we will act as though it succeeded. */
1181 vport->ct_flags = 0;
1182 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
1187 lpfc_cmpl_ct_cmd_rff_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1188 struct lpfc_iocbq *rspiocb)
1190 IOCB_t *irsp = &rspiocb->iocb;
1191 struct lpfc_vport *vport = cmdiocb->vport;
1193 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
1194 struct lpfc_dmabuf *outp;
1195 struct lpfc_sli_ct_request *CTrsp;
1197 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
1198 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
1199 if (CTrsp->CommandResponse.bits.CmdRsp ==
1200 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
1201 vport->ct_flags |= FC_CT_RFF_ID;
1203 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
1208 * Although the symbolic port name is thought to be an integer
1209 * as of January 18, 2016, leave it as a string until more of
1210 * the record state becomes defined.
1213 lpfc_vport_symbolic_port_name(struct lpfc_vport *vport, char *symbol,
1219 * Use the lpfc board number as the Symbolic Port
1220 * Name object. NPIV is not in play so this integer
1221 * value is sufficient and unique per FC-ID.
1223 n = snprintf(symbol, size, "%d", vport->phba->brd_no);
1229 lpfc_vport_symbolic_node_name(struct lpfc_vport *vport, char *symbol,
1232 char fwrev[FW_REV_STR_SIZE];
1235 lpfc_decode_firmware_rev(vport->phba, fwrev, 0);
1237 n = snprintf(symbol, size, "Emulex %s", vport->phba->ModelName);
1241 n += snprintf(symbol + n, size - n, " FV%s", fwrev);
1245 n += snprintf(symbol + n, size - n, " DV%s.",
1246 lpfc_release_version);
1250 n += snprintf(symbol + n, size - n, " HN:%s.",
1251 init_utsname()->nodename);
1255 /* Note :- OS name is "Linux" */
1256 n += snprintf(symbol + n, size - n, " OS:%s\n",
1257 init_utsname()->sysname);
1262 lpfc_find_map_node(struct lpfc_vport *vport)
1264 struct lpfc_nodelist *ndlp, *next_ndlp;
1265 struct Scsi_Host *shost;
1268 shost = lpfc_shost_from_vport(vport);
1269 spin_lock_irq(shost->host_lock);
1270 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
1271 if (ndlp->nlp_type & NLP_FABRIC)
1273 if ((ndlp->nlp_state == NLP_STE_MAPPED_NODE) ||
1274 (ndlp->nlp_state == NLP_STE_UNMAPPED_NODE))
1277 spin_unlock_irq(shost->host_lock);
1282 * This routine will return the FC4 Type associated with the CT
1286 lpfc_get_gidft_type(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb)
1288 struct lpfc_sli_ct_request *CtReq;
1289 struct lpfc_dmabuf *mp;
1292 mp = cmdiocb->context1;
1295 CtReq = (struct lpfc_sli_ct_request *)mp->virt;
1296 type = (uint32_t)CtReq->un.gid.Fc4Type;
1297 if ((type != SLI_CTPT_FCP) && (type != SLI_CTPT_NVME))
1305 * Issue Cmd to NameServer
1310 lpfc_ns_cmd(struct lpfc_vport *vport, int cmdcode,
1311 uint8_t retry, uint32_t context)
1313 struct lpfc_nodelist * ndlp;
1314 struct lpfc_hba *phba = vport->phba;
1315 struct lpfc_dmabuf *mp, *bmp;
1316 struct lpfc_sli_ct_request *CtReq;
1317 struct ulp_bde64 *bpl;
1318 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
1319 struct lpfc_iocbq *) = NULL;
1320 uint32_t rsp_size = 1024;
1324 ndlp = lpfc_findnode_did(vport, NameServer_DID);
1325 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)
1326 || ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) {
1331 /* fill in BDEs for command */
1332 /* Allocate buffer for command payload */
1333 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
1339 INIT_LIST_HEAD(&mp->list);
1340 mp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(mp->phys));
1343 goto ns_cmd_free_mp;
1346 /* Allocate buffer for Buffer ptr list */
1347 bmp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
1350 goto ns_cmd_free_mpvirt;
1353 INIT_LIST_HEAD(&bmp->list);
1354 bmp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(bmp->phys));
1357 goto ns_cmd_free_bmp;
1360 /* NameServer Req */
1361 lpfc_printf_vlog(vport, KERN_INFO ,LOG_DISCOVERY,
1362 "0236 NameServer Req Data: x%x x%x x%x x%x\n",
1363 cmdcode, vport->fc_flag, vport->fc_rscn_id_cnt,
1366 bpl = (struct ulp_bde64 *) bmp->virt;
1367 memset(bpl, 0, sizeof(struct ulp_bde64));
1368 bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys) );
1369 bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys) );
1370 bpl->tus.f.bdeFlags = 0;
1371 if (cmdcode == SLI_CTNS_GID_FT)
1372 bpl->tus.f.bdeSize = GID_REQUEST_SZ;
1373 else if (cmdcode == SLI_CTNS_GFF_ID)
1374 bpl->tus.f.bdeSize = GFF_REQUEST_SZ;
1375 else if (cmdcode == SLI_CTNS_GFT_ID)
1376 bpl->tus.f.bdeSize = GFT_REQUEST_SZ;
1377 else if (cmdcode == SLI_CTNS_RFT_ID)
1378 bpl->tus.f.bdeSize = RFT_REQUEST_SZ;
1379 else if (cmdcode == SLI_CTNS_RNN_ID)
1380 bpl->tus.f.bdeSize = RNN_REQUEST_SZ;
1381 else if (cmdcode == SLI_CTNS_RSPN_ID)
1382 bpl->tus.f.bdeSize = RSPN_REQUEST_SZ;
1383 else if (cmdcode == SLI_CTNS_RSNN_NN)
1384 bpl->tus.f.bdeSize = RSNN_REQUEST_SZ;
1385 else if (cmdcode == SLI_CTNS_DA_ID)
1386 bpl->tus.f.bdeSize = DA_ID_REQUEST_SZ;
1387 else if (cmdcode == SLI_CTNS_RFF_ID)
1388 bpl->tus.f.bdeSize = RFF_REQUEST_SZ;
1390 bpl->tus.f.bdeSize = 0;
1391 bpl->tus.w = le32_to_cpu(bpl->tus.w);
1393 CtReq = (struct lpfc_sli_ct_request *) mp->virt;
1394 memset(CtReq, 0, sizeof(struct lpfc_sli_ct_request));
1395 CtReq->RevisionId.bits.Revision = SLI_CT_REVISION;
1396 CtReq->RevisionId.bits.InId = 0;
1397 CtReq->FsType = SLI_CT_DIRECTORY_SERVICE;
1398 CtReq->FsSubType = SLI_CT_DIRECTORY_NAME_SERVER;
1399 CtReq->CommandResponse.bits.Size = 0;
1401 case SLI_CTNS_GID_FT:
1402 CtReq->CommandResponse.bits.CmdRsp =
1403 cpu_to_be16(SLI_CTNS_GID_FT);
1404 CtReq->un.gid.Fc4Type = context;
1406 if (vport->port_state < LPFC_NS_QRY)
1407 vport->port_state = LPFC_NS_QRY;
1408 lpfc_set_disctmo(vport);
1409 cmpl = lpfc_cmpl_ct_cmd_gid_ft;
1410 rsp_size = FC_MAX_NS_RSP;
1413 case SLI_CTNS_GFF_ID:
1414 CtReq->CommandResponse.bits.CmdRsp =
1415 cpu_to_be16(SLI_CTNS_GFF_ID);
1416 CtReq->un.gff.PortId = cpu_to_be32(context);
1417 cmpl = lpfc_cmpl_ct_cmd_gff_id;
1420 case SLI_CTNS_GFT_ID:
1421 CtReq->CommandResponse.bits.CmdRsp =
1422 cpu_to_be16(SLI_CTNS_GFT_ID);
1423 CtReq->un.gft.PortId = cpu_to_be32(context);
1424 cmpl = lpfc_cmpl_ct_cmd_gft_id;
1427 case SLI_CTNS_RFT_ID:
1428 vport->ct_flags &= ~FC_CT_RFT_ID;
1429 CtReq->CommandResponse.bits.CmdRsp =
1430 cpu_to_be16(SLI_CTNS_RFT_ID);
1431 CtReq->un.rft.PortId = cpu_to_be32(vport->fc_myDID);
1433 /* Register FC4 FCP type if enabled. */
1434 if ((phba->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
1435 (phba->cfg_enable_fc4_type == LPFC_ENABLE_FCP))
1436 CtReq->un.rft.fcpReg = 1;
1438 /* Register NVME type if enabled. Defined LE and swapped.
1439 * rsvd[0] is used as word1 because of the hard-coded
1440 * word0 usage in the ct_request data structure.
1442 if ((phba->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
1443 (phba->cfg_enable_fc4_type == LPFC_ENABLE_NVME))
1444 CtReq->un.rft.rsvd[0] = cpu_to_be32(0x00000100);
1446 cmpl = lpfc_cmpl_ct_cmd_rft_id;
1449 case SLI_CTNS_RNN_ID:
1450 vport->ct_flags &= ~FC_CT_RNN_ID;
1451 CtReq->CommandResponse.bits.CmdRsp =
1452 cpu_to_be16(SLI_CTNS_RNN_ID);
1453 CtReq->un.rnn.PortId = cpu_to_be32(vport->fc_myDID);
1454 memcpy(CtReq->un.rnn.wwnn, &vport->fc_nodename,
1455 sizeof(struct lpfc_name));
1456 cmpl = lpfc_cmpl_ct_cmd_rnn_id;
1459 case SLI_CTNS_RSPN_ID:
1460 vport->ct_flags &= ~FC_CT_RSPN_ID;
1461 CtReq->CommandResponse.bits.CmdRsp =
1462 cpu_to_be16(SLI_CTNS_RSPN_ID);
1463 CtReq->un.rspn.PortId = cpu_to_be32(vport->fc_myDID);
1464 size = sizeof(CtReq->un.rspn.symbname);
1465 CtReq->un.rspn.len =
1466 lpfc_vport_symbolic_port_name(vport,
1467 CtReq->un.rspn.symbname, size);
1468 cmpl = lpfc_cmpl_ct_cmd_rspn_id;
1470 case SLI_CTNS_RSNN_NN:
1471 vport->ct_flags &= ~FC_CT_RSNN_NN;
1472 CtReq->CommandResponse.bits.CmdRsp =
1473 cpu_to_be16(SLI_CTNS_RSNN_NN);
1474 memcpy(CtReq->un.rsnn.wwnn, &vport->fc_nodename,
1475 sizeof(struct lpfc_name));
1476 size = sizeof(CtReq->un.rsnn.symbname);
1477 CtReq->un.rsnn.len =
1478 lpfc_vport_symbolic_node_name(vport,
1479 CtReq->un.rsnn.symbname, size);
1480 cmpl = lpfc_cmpl_ct_cmd_rsnn_nn;
1482 case SLI_CTNS_DA_ID:
1483 /* Implement DA_ID Nameserver request */
1484 CtReq->CommandResponse.bits.CmdRsp =
1485 cpu_to_be16(SLI_CTNS_DA_ID);
1486 CtReq->un.da_id.port_id = cpu_to_be32(vport->fc_myDID);
1487 cmpl = lpfc_cmpl_ct_cmd_da_id;
1489 case SLI_CTNS_RFF_ID:
1490 vport->ct_flags &= ~FC_CT_RFF_ID;
1491 CtReq->CommandResponse.bits.CmdRsp =
1492 cpu_to_be16(SLI_CTNS_RFF_ID);
1493 CtReq->un.rff.PortId = cpu_to_be32(vport->fc_myDID);
1494 CtReq->un.rff.fbits = FC4_FEATURE_INIT;
1496 /* The driver always supports FC_TYPE_FCP. However, the
1497 * caller can specify NVME (type x28) as well. But only
1498 * these that FC4 type is supported.
1500 if (((phba->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
1501 (phba->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) &&
1502 (context == FC_TYPE_NVME)) {
1503 if ((vport == phba->pport) && phba->nvmet_support) {
1504 CtReq->un.rff.fbits = (FC4_FEATURE_TARGET |
1505 FC4_FEATURE_NVME_DISC);
1506 lpfc_nvmet_update_targetport(phba);
1508 lpfc_nvme_update_localport(vport);
1510 CtReq->un.rff.type_code = context;
1512 } else if (((phba->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
1513 (phba->cfg_enable_fc4_type == LPFC_ENABLE_FCP)) &&
1514 (context == FC_TYPE_FCP))
1515 CtReq->un.rff.type_code = context;
1518 goto ns_cmd_free_bmpvirt;
1520 cmpl = lpfc_cmpl_ct_cmd_rff_id;
1523 /* The lpfc_ct_cmd/lpfc_get_req shall increment ndlp reference count
1524 * to hold ndlp reference for the corresponding callback function.
1526 if (!lpfc_ct_cmd(vport, mp, bmp, ndlp, cmpl, rsp_size, retry)) {
1527 /* On success, The cmpl function will free the buffers */
1528 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
1529 "Issue CT cmd: cmd:x%x did:x%x",
1530 cmdcode, ndlp->nlp_DID, 0);
1535 /* Decrement ndlp reference count to release ndlp reference held
1536 * for the failed command's callback function.
1540 ns_cmd_free_bmpvirt:
1541 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
1545 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1549 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
1550 "0266 Issue NameServer Req x%x err %d Data: x%x x%x\n",
1551 cmdcode, rc, vport->fc_flag, vport->fc_rscn_id_cnt);
1556 * lpfc_cmpl_ct_disc_fdmi - Handle a discovery FDMI completion
1557 * @phba: Pointer to HBA context object.
1558 * @cmdiocb: Pointer to the command IOCBQ.
1559 * @rspiocb: Pointer to the response IOCBQ.
1561 * This function to handle the completion of a driver initiated FDMI
1562 * CT command issued during discovery.
1565 lpfc_cmpl_ct_disc_fdmi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1566 struct lpfc_iocbq *rspiocb)
1568 struct lpfc_vport *vport = cmdiocb->vport;
1569 struct lpfc_dmabuf *inp = cmdiocb->context1;
1570 struct lpfc_dmabuf *outp = cmdiocb->context2;
1571 struct lpfc_sli_ct_request *CTcmd = inp->virt;
1572 struct lpfc_sli_ct_request *CTrsp = outp->virt;
1573 uint16_t fdmi_cmd = CTcmd->CommandResponse.bits.CmdRsp;
1574 uint16_t fdmi_rsp = CTrsp->CommandResponse.bits.CmdRsp;
1575 IOCB_t *irsp = &rspiocb->iocb;
1576 struct lpfc_nodelist *ndlp;
1577 uint32_t latt, cmd, err;
1579 latt = lpfc_els_chk_latt(vport);
1580 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
1581 "FDMI cmpl: status:x%x/x%x latt:%d",
1582 irsp->ulpStatus, irsp->un.ulpWord[4], latt);
1584 if (latt || irsp->ulpStatus) {
1586 /* Look for a retryable error */
1587 if (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) {
1588 switch ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK)) {
1589 case IOERR_SLI_ABORTED:
1590 case IOERR_ABORT_IN_PROGRESS:
1591 case IOERR_SEQUENCE_TIMEOUT:
1592 case IOERR_ILLEGAL_FRAME:
1593 case IOERR_NO_RESOURCES:
1594 case IOERR_ILLEGAL_COMMAND:
1596 if (cmdiocb->retry >= LPFC_FDMI_MAX_RETRY)
1599 /* Retry the same FDMI command */
1600 err = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING,
1602 if (err == IOCB_ERROR)
1610 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1611 "0229 FDMI cmd %04x failed, latt = %d "
1612 "ulpStatus: x%x, rid x%x\n",
1613 be16_to_cpu(fdmi_cmd), latt, irsp->ulpStatus,
1614 irsp->un.ulpWord[4]);
1616 lpfc_ct_free_iocb(phba, cmdiocb);
1618 ndlp = lpfc_findnode_did(vport, FDMI_DID);
1619 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
1622 /* Check for a CT LS_RJT response */
1623 cmd = be16_to_cpu(fdmi_cmd);
1624 if (fdmi_rsp == cpu_to_be16(SLI_CT_RESPONSE_FS_RJT)) {
1625 /* FDMI rsp failed */
1626 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1627 "0220 FDMI cmd failed FS_RJT Data: x%x", cmd);
1629 /* Should we fallback to FDMI-2 / FDMI-1 ? */
1632 if (vport->fdmi_hba_mask == LPFC_FDMI2_HBA_ATTR) {
1633 /* Fallback to FDMI-1 */
1634 vport->fdmi_hba_mask = LPFC_FDMI1_HBA_ATTR;
1635 vport->fdmi_port_mask = LPFC_FDMI1_PORT_ATTR;
1637 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA, 0);
1642 if (vport->fdmi_port_mask == LPFC_FDMI2_PORT_ATTR) {
1643 /* Fallback to FDMI-1 */
1644 vport->fdmi_port_mask = LPFC_FDMI1_PORT_ATTR;
1646 lpfc_fdmi_cmd(vport, ndlp, cmd, 0);
1648 if (vport->fdmi_port_mask == LPFC_FDMI2_SMART_ATTR) {
1649 vport->fdmi_port_mask = LPFC_FDMI2_PORT_ATTR;
1650 /* Retry the same command */
1651 lpfc_fdmi_cmd(vport, ndlp, cmd, 0);
1656 if (vport->fdmi_port_mask == LPFC_FDMI2_PORT_ATTR) {
1657 /* Fallback to FDMI-1 */
1658 vport->fdmi_hba_mask = LPFC_FDMI1_HBA_ATTR;
1659 vport->fdmi_port_mask = LPFC_FDMI1_PORT_ATTR;
1661 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA, 0);
1663 if (vport->fdmi_port_mask == LPFC_FDMI2_SMART_ATTR) {
1664 vport->fdmi_port_mask = LPFC_FDMI2_PORT_ATTR;
1665 /* Retry the same command */
1666 lpfc_fdmi_cmd(vport, ndlp, cmd, 0);
1673 * On success, need to cycle thru FDMI registration for discovery
1674 * DHBA -> DPRT -> RHBA -> RPA (physical port)
1675 * DPRT -> RPRT (vports)
1679 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RPA, 0);
1683 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DPRT, 0);
1687 if (vport->port_type == LPFC_PHYSICAL_PORT)
1688 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RHBA, 0);
1690 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RPRT, 0);
1698 * lpfc_fdmi_num_disc_check - Check how many mapped NPorts we are connected to
1699 * @vport: pointer to a host virtual N_Port data structure.
1701 * Called from hbeat timeout routine to check if the number of discovered
1702 * ports has changed. If so, re-register thar port Attribute.
1705 lpfc_fdmi_num_disc_check(struct lpfc_vport *vport)
1707 struct lpfc_hba *phba = vport->phba;
1708 struct lpfc_nodelist *ndlp;
1711 if (!lpfc_is_link_up(phba))
1714 /* Must be connected to a Fabric */
1715 if (!(vport->fc_flag & FC_FABRIC))
1718 if (!(vport->fdmi_port_mask & LPFC_FDMI_PORT_ATTR_num_disc))
1721 cnt = lpfc_find_map_node(vport);
1722 if (cnt == vport->fdmi_num_disc)
1725 ndlp = lpfc_findnode_did(vport, FDMI_DID);
1726 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
1729 if (vport->port_type == LPFC_PHYSICAL_PORT) {
1730 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RPA,
1731 LPFC_FDMI_PORT_ATTR_num_disc);
1733 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RPRT,
1734 LPFC_FDMI_PORT_ATTR_num_disc);
1738 /* Routines for all individual HBA attributes */
1740 lpfc_fdmi_hba_attr_wwnn(struct lpfc_vport *vport, struct lpfc_fdmi_attr_def *ad)
1742 struct lpfc_fdmi_attr_entry *ae;
1745 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
1746 memset(ae, 0, sizeof(struct lpfc_name));
1748 memcpy(&ae->un.AttrWWN, &vport->fc_sparam.nodeName,
1749 sizeof(struct lpfc_name));
1750 size = FOURBYTES + sizeof(struct lpfc_name);
1751 ad->AttrLen = cpu_to_be16(size);
1752 ad->AttrType = cpu_to_be16(RHBA_NODENAME);
1756 lpfc_fdmi_hba_attr_manufacturer(struct lpfc_vport *vport,
1757 struct lpfc_fdmi_attr_def *ad)
1759 struct lpfc_fdmi_attr_entry *ae;
1762 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
1765 strncpy(ae->un.AttrString,
1766 "Emulex Corporation",
1767 sizeof(ae->un.AttrString));
1768 len = strnlen(ae->un.AttrString,
1769 sizeof(ae->un.AttrString));
1770 len += (len & 3) ? (4 - (len & 3)) : 4;
1771 size = FOURBYTES + len;
1772 ad->AttrLen = cpu_to_be16(size);
1773 ad->AttrType = cpu_to_be16(RHBA_MANUFACTURER);
1778 lpfc_fdmi_hba_attr_sn(struct lpfc_vport *vport, struct lpfc_fdmi_attr_def *ad)
1780 struct lpfc_hba *phba = vport->phba;
1781 struct lpfc_fdmi_attr_entry *ae;
1784 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
1787 strncpy(ae->un.AttrString, phba->SerialNumber,
1788 sizeof(ae->un.AttrString));
1789 len = strnlen(ae->un.AttrString,
1790 sizeof(ae->un.AttrString));
1791 len += (len & 3) ? (4 - (len & 3)) : 4;
1792 size = FOURBYTES + len;
1793 ad->AttrLen = cpu_to_be16(size);
1794 ad->AttrType = cpu_to_be16(RHBA_SERIAL_NUMBER);
1799 lpfc_fdmi_hba_attr_model(struct lpfc_vport *vport,
1800 struct lpfc_fdmi_attr_def *ad)
1802 struct lpfc_hba *phba = vport->phba;
1803 struct lpfc_fdmi_attr_entry *ae;
1806 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
1809 strncpy(ae->un.AttrString, phba->ModelName,
1810 sizeof(ae->un.AttrString));
1811 len = strnlen(ae->un.AttrString, sizeof(ae->un.AttrString));
1812 len += (len & 3) ? (4 - (len & 3)) : 4;
1813 size = FOURBYTES + len;
1814 ad->AttrLen = cpu_to_be16(size);
1815 ad->AttrType = cpu_to_be16(RHBA_MODEL);
1820 lpfc_fdmi_hba_attr_description(struct lpfc_vport *vport,
1821 struct lpfc_fdmi_attr_def *ad)
1823 struct lpfc_hba *phba = vport->phba;
1824 struct lpfc_fdmi_attr_entry *ae;
1827 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
1830 strncpy(ae->un.AttrString, phba->ModelDesc,
1831 sizeof(ae->un.AttrString));
1832 len = strnlen(ae->un.AttrString,
1833 sizeof(ae->un.AttrString));
1834 len += (len & 3) ? (4 - (len & 3)) : 4;
1835 size = FOURBYTES + len;
1836 ad->AttrLen = cpu_to_be16(size);
1837 ad->AttrType = cpu_to_be16(RHBA_MODEL_DESCRIPTION);
1842 lpfc_fdmi_hba_attr_hdw_ver(struct lpfc_vport *vport,
1843 struct lpfc_fdmi_attr_def *ad)
1845 struct lpfc_hba *phba = vport->phba;
1846 lpfc_vpd_t *vp = &phba->vpd;
1847 struct lpfc_fdmi_attr_entry *ae;
1848 uint32_t i, j, incr, size;
1850 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
1853 /* Convert JEDEC ID to ascii for hardware version */
1854 incr = vp->rev.biuRev;
1855 for (i = 0; i < 8; i++) {
1858 ae->un.AttrString[7 - i] =
1859 (char)((uint8_t) 0x30 +
1862 ae->un.AttrString[7 - i] =
1863 (char)((uint8_t) 0x61 +
1864 (uint8_t) (j - 10));
1867 size = FOURBYTES + 8;
1868 ad->AttrLen = cpu_to_be16(size);
1869 ad->AttrType = cpu_to_be16(RHBA_HARDWARE_VERSION);
1874 lpfc_fdmi_hba_attr_drvr_ver(struct lpfc_vport *vport,
1875 struct lpfc_fdmi_attr_def *ad)
1877 struct lpfc_fdmi_attr_entry *ae;
1880 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
1883 strncpy(ae->un.AttrString, lpfc_release_version,
1884 sizeof(ae->un.AttrString));
1885 len = strnlen(ae->un.AttrString,
1886 sizeof(ae->un.AttrString));
1887 len += (len & 3) ? (4 - (len & 3)) : 4;
1888 size = FOURBYTES + len;
1889 ad->AttrLen = cpu_to_be16(size);
1890 ad->AttrType = cpu_to_be16(RHBA_DRIVER_VERSION);
1895 lpfc_fdmi_hba_attr_rom_ver(struct lpfc_vport *vport,
1896 struct lpfc_fdmi_attr_def *ad)
1898 struct lpfc_hba *phba = vport->phba;
1899 struct lpfc_fdmi_attr_entry *ae;
1902 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
1905 if (phba->sli_rev == LPFC_SLI_REV4)
1906 lpfc_decode_firmware_rev(phba, ae->un.AttrString, 1);
1908 strncpy(ae->un.AttrString, phba->OptionROMVersion,
1909 sizeof(ae->un.AttrString));
1910 len = strnlen(ae->un.AttrString,
1911 sizeof(ae->un.AttrString));
1912 len += (len & 3) ? (4 - (len & 3)) : 4;
1913 size = FOURBYTES + len;
1914 ad->AttrLen = cpu_to_be16(size);
1915 ad->AttrType = cpu_to_be16(RHBA_OPTION_ROM_VERSION);
1920 lpfc_fdmi_hba_attr_fmw_ver(struct lpfc_vport *vport,
1921 struct lpfc_fdmi_attr_def *ad)
1923 struct lpfc_hba *phba = vport->phba;
1924 struct lpfc_fdmi_attr_entry *ae;
1927 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
1930 lpfc_decode_firmware_rev(phba, ae->un.AttrString, 1);
1931 len = strnlen(ae->un.AttrString,
1932 sizeof(ae->un.AttrString));
1933 len += (len & 3) ? (4 - (len & 3)) : 4;
1934 size = FOURBYTES + len;
1935 ad->AttrLen = cpu_to_be16(size);
1936 ad->AttrType = cpu_to_be16(RHBA_FIRMWARE_VERSION);
1941 lpfc_fdmi_hba_attr_os_ver(struct lpfc_vport *vport,
1942 struct lpfc_fdmi_attr_def *ad)
1944 struct lpfc_fdmi_attr_entry *ae;
1947 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
1950 snprintf(ae->un.AttrString, sizeof(ae->un.AttrString), "%s %s %s",
1951 init_utsname()->sysname,
1952 init_utsname()->release,
1953 init_utsname()->version);
1955 len = strnlen(ae->un.AttrString, sizeof(ae->un.AttrString));
1956 len += (len & 3) ? (4 - (len & 3)) : 4;
1957 size = FOURBYTES + len;
1958 ad->AttrLen = cpu_to_be16(size);
1959 ad->AttrType = cpu_to_be16(RHBA_OS_NAME_VERSION);
1964 lpfc_fdmi_hba_attr_ct_len(struct lpfc_vport *vport,
1965 struct lpfc_fdmi_attr_def *ad)
1967 struct lpfc_fdmi_attr_entry *ae;
1970 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
1972 ae->un.AttrInt = cpu_to_be32(LPFC_MAX_CT_SIZE);
1973 size = FOURBYTES + sizeof(uint32_t);
1974 ad->AttrLen = cpu_to_be16(size);
1975 ad->AttrType = cpu_to_be16(RHBA_MAX_CT_PAYLOAD_LEN);
1980 lpfc_fdmi_hba_attr_symbolic_name(struct lpfc_vport *vport,
1981 struct lpfc_fdmi_attr_def *ad)
1983 struct lpfc_fdmi_attr_entry *ae;
1986 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
1989 len = lpfc_vport_symbolic_node_name(vport,
1990 ae->un.AttrString, 256);
1991 len += (len & 3) ? (4 - (len & 3)) : 4;
1992 size = FOURBYTES + len;
1993 ad->AttrLen = cpu_to_be16(size);
1994 ad->AttrType = cpu_to_be16(RHBA_SYM_NODENAME);
1999 lpfc_fdmi_hba_attr_vendor_info(struct lpfc_vport *vport,
2000 struct lpfc_fdmi_attr_def *ad)
2002 struct lpfc_fdmi_attr_entry *ae;
2005 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2007 /* Nothing is defined for this currently */
2008 ae->un.AttrInt = cpu_to_be32(0);
2009 size = FOURBYTES + sizeof(uint32_t);
2010 ad->AttrLen = cpu_to_be16(size);
2011 ad->AttrType = cpu_to_be16(RHBA_VENDOR_INFO);
2016 lpfc_fdmi_hba_attr_num_ports(struct lpfc_vport *vport,
2017 struct lpfc_fdmi_attr_def *ad)
2019 struct lpfc_fdmi_attr_entry *ae;
2022 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2024 /* Each driver instance corresponds to a single port */
2025 ae->un.AttrInt = cpu_to_be32(1);
2026 size = FOURBYTES + sizeof(uint32_t);
2027 ad->AttrLen = cpu_to_be16(size);
2028 ad->AttrType = cpu_to_be16(RHBA_NUM_PORTS);
2033 lpfc_fdmi_hba_attr_fabric_wwnn(struct lpfc_vport *vport,
2034 struct lpfc_fdmi_attr_def *ad)
2036 struct lpfc_fdmi_attr_entry *ae;
2039 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2040 memset(ae, 0, sizeof(struct lpfc_name));
2042 memcpy(&ae->un.AttrWWN, &vport->fabric_nodename,
2043 sizeof(struct lpfc_name));
2044 size = FOURBYTES + sizeof(struct lpfc_name);
2045 ad->AttrLen = cpu_to_be16(size);
2046 ad->AttrType = cpu_to_be16(RHBA_FABRIC_WWNN);
2051 lpfc_fdmi_hba_attr_bios_ver(struct lpfc_vport *vport,
2052 struct lpfc_fdmi_attr_def *ad)
2054 struct lpfc_hba *phba = vport->phba;
2055 struct lpfc_fdmi_attr_entry *ae;
2058 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2061 lpfc_decode_firmware_rev(phba, ae->un.AttrString, 1);
2062 len = strnlen(ae->un.AttrString,
2063 sizeof(ae->un.AttrString));
2064 len += (len & 3) ? (4 - (len & 3)) : 4;
2065 size = FOURBYTES + len;
2066 ad->AttrLen = cpu_to_be16(size);
2067 ad->AttrType = cpu_to_be16(RHBA_BIOS_VERSION);
2072 lpfc_fdmi_hba_attr_bios_state(struct lpfc_vport *vport,
2073 struct lpfc_fdmi_attr_def *ad)
2075 struct lpfc_fdmi_attr_entry *ae;
2078 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2080 /* Driver doesn't have access to this information */
2081 ae->un.AttrInt = cpu_to_be32(0);
2082 size = FOURBYTES + sizeof(uint32_t);
2083 ad->AttrLen = cpu_to_be16(size);
2084 ad->AttrType = cpu_to_be16(RHBA_BIOS_STATE);
2089 lpfc_fdmi_hba_attr_vendor_id(struct lpfc_vport *vport,
2090 struct lpfc_fdmi_attr_def *ad)
2092 struct lpfc_fdmi_attr_entry *ae;
2095 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2098 strncpy(ae->un.AttrString, "EMULEX",
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_VENDOR_ID);
2109 /* Routines for all individual PORT attributes */
2111 lpfc_fdmi_port_attr_fc4type(struct lpfc_vport *vport,
2112 struct lpfc_fdmi_attr_def *ad)
2114 struct lpfc_fdmi_attr_entry *ae;
2117 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2120 ae->un.AttrTypes[3] = 0x02; /* Type 1 - ELS */
2121 ae->un.AttrTypes[2] = 0x01; /* Type 8 - FCP */
2122 ae->un.AttrTypes[6] = 0x01; /* Type 40 - NVME */
2123 ae->un.AttrTypes[7] = 0x01; /* Type 32 - CT */
2124 size = FOURBYTES + 32;
2125 ad->AttrLen = cpu_to_be16(size);
2126 ad->AttrType = cpu_to_be16(RPRT_SUPPORTED_FC4_TYPES);
2131 lpfc_fdmi_port_attr_support_speed(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 = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2141 if (!(phba->hba_flag & HBA_FCOE_MODE)) {
2142 if (phba->lmt & LMT_64Gb)
2143 ae->un.AttrInt |= HBA_PORTSPEED_64GFC;
2144 if (phba->lmt & LMT_32Gb)
2145 ae->un.AttrInt |= HBA_PORTSPEED_32GFC;
2146 if (phba->lmt & LMT_16Gb)
2147 ae->un.AttrInt |= HBA_PORTSPEED_16GFC;
2148 if (phba->lmt & LMT_10Gb)
2149 ae->un.AttrInt |= HBA_PORTSPEED_10GFC;
2150 if (phba->lmt & LMT_8Gb)
2151 ae->un.AttrInt |= HBA_PORTSPEED_8GFC;
2152 if (phba->lmt & LMT_4Gb)
2153 ae->un.AttrInt |= HBA_PORTSPEED_4GFC;
2154 if (phba->lmt & LMT_2Gb)
2155 ae->un.AttrInt |= HBA_PORTSPEED_2GFC;
2156 if (phba->lmt & LMT_1Gb)
2157 ae->un.AttrInt |= HBA_PORTSPEED_1GFC;
2159 /* FCoE links support only one speed */
2160 switch (phba->fc_linkspeed) {
2161 case LPFC_ASYNC_LINK_SPEED_10GBPS:
2162 ae->un.AttrInt = HBA_PORTSPEED_10GE;
2164 case LPFC_ASYNC_LINK_SPEED_25GBPS:
2165 ae->un.AttrInt = HBA_PORTSPEED_25GE;
2167 case LPFC_ASYNC_LINK_SPEED_40GBPS:
2168 ae->un.AttrInt = HBA_PORTSPEED_40GE;
2170 case LPFC_ASYNC_LINK_SPEED_100GBPS:
2171 ae->un.AttrInt = HBA_PORTSPEED_100GE;
2175 ae->un.AttrInt = cpu_to_be32(ae->un.AttrInt);
2176 size = FOURBYTES + sizeof(uint32_t);
2177 ad->AttrLen = cpu_to_be16(size);
2178 ad->AttrType = cpu_to_be16(RPRT_SUPPORTED_SPEED);
2183 lpfc_fdmi_port_attr_speed(struct lpfc_vport *vport,
2184 struct lpfc_fdmi_attr_def *ad)
2186 struct lpfc_hba *phba = vport->phba;
2187 struct lpfc_fdmi_attr_entry *ae;
2190 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2192 if (!(phba->hba_flag & HBA_FCOE_MODE)) {
2193 switch (phba->fc_linkspeed) {
2194 case LPFC_LINK_SPEED_1GHZ:
2195 ae->un.AttrInt = HBA_PORTSPEED_1GFC;
2197 case LPFC_LINK_SPEED_2GHZ:
2198 ae->un.AttrInt = HBA_PORTSPEED_2GFC;
2200 case LPFC_LINK_SPEED_4GHZ:
2201 ae->un.AttrInt = HBA_PORTSPEED_4GFC;
2203 case LPFC_LINK_SPEED_8GHZ:
2204 ae->un.AttrInt = HBA_PORTSPEED_8GFC;
2206 case LPFC_LINK_SPEED_10GHZ:
2207 ae->un.AttrInt = HBA_PORTSPEED_10GFC;
2209 case LPFC_LINK_SPEED_16GHZ:
2210 ae->un.AttrInt = HBA_PORTSPEED_16GFC;
2212 case LPFC_LINK_SPEED_32GHZ:
2213 ae->un.AttrInt = HBA_PORTSPEED_32GFC;
2215 case LPFC_LINK_SPEED_64GHZ:
2216 ae->un.AttrInt = HBA_PORTSPEED_64GFC;
2219 ae->un.AttrInt = HBA_PORTSPEED_UNKNOWN;
2223 switch (phba->fc_linkspeed) {
2224 case LPFC_ASYNC_LINK_SPEED_10GBPS:
2225 ae->un.AttrInt = HBA_PORTSPEED_10GE;
2227 case LPFC_ASYNC_LINK_SPEED_25GBPS:
2228 ae->un.AttrInt = HBA_PORTSPEED_25GE;
2230 case LPFC_ASYNC_LINK_SPEED_40GBPS:
2231 ae->un.AttrInt = HBA_PORTSPEED_40GE;
2233 case LPFC_ASYNC_LINK_SPEED_100GBPS:
2234 ae->un.AttrInt = HBA_PORTSPEED_100GE;
2237 ae->un.AttrInt = HBA_PORTSPEED_UNKNOWN;
2242 ae->un.AttrInt = cpu_to_be32(ae->un.AttrInt);
2243 size = FOURBYTES + sizeof(uint32_t);
2244 ad->AttrLen = cpu_to_be16(size);
2245 ad->AttrType = cpu_to_be16(RPRT_PORT_SPEED);
2250 lpfc_fdmi_port_attr_max_frame(struct lpfc_vport *vport,
2251 struct lpfc_fdmi_attr_def *ad)
2253 struct serv_parm *hsp;
2254 struct lpfc_fdmi_attr_entry *ae;
2257 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2259 hsp = (struct serv_parm *)&vport->fc_sparam;
2260 ae->un.AttrInt = (((uint32_t) hsp->cmn.bbRcvSizeMsb) << 8) |
2261 (uint32_t) hsp->cmn.bbRcvSizeLsb;
2262 ae->un.AttrInt = cpu_to_be32(ae->un.AttrInt);
2263 size = FOURBYTES + sizeof(uint32_t);
2264 ad->AttrLen = cpu_to_be16(size);
2265 ad->AttrType = cpu_to_be16(RPRT_MAX_FRAME_SIZE);
2270 lpfc_fdmi_port_attr_os_devname(struct lpfc_vport *vport,
2271 struct lpfc_fdmi_attr_def *ad)
2273 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2274 struct lpfc_fdmi_attr_entry *ae;
2277 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2280 snprintf(ae->un.AttrString, sizeof(ae->un.AttrString),
2281 "/sys/class/scsi_host/host%d", shost->host_no);
2282 len = strnlen((char *)ae->un.AttrString,
2283 sizeof(ae->un.AttrString));
2284 len += (len & 3) ? (4 - (len & 3)) : 4;
2285 size = FOURBYTES + len;
2286 ad->AttrLen = cpu_to_be16(size);
2287 ad->AttrType = cpu_to_be16(RPRT_OS_DEVICE_NAME);
2292 lpfc_fdmi_port_attr_host_name(struct lpfc_vport *vport,
2293 struct lpfc_fdmi_attr_def *ad)
2295 struct lpfc_fdmi_attr_entry *ae;
2298 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2301 snprintf(ae->un.AttrString, sizeof(ae->un.AttrString), "%s",
2302 init_utsname()->nodename);
2304 len = strnlen(ae->un.AttrString, sizeof(ae->un.AttrString));
2305 len += (len & 3) ? (4 - (len & 3)) : 4;
2306 size = FOURBYTES + len;
2307 ad->AttrLen = cpu_to_be16(size);
2308 ad->AttrType = cpu_to_be16(RPRT_HOST_NAME);
2313 lpfc_fdmi_port_attr_wwnn(struct lpfc_vport *vport,
2314 struct lpfc_fdmi_attr_def *ad)
2316 struct lpfc_fdmi_attr_entry *ae;
2319 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2320 memset(ae, 0, sizeof(struct lpfc_name));
2322 memcpy(&ae->un.AttrWWN, &vport->fc_sparam.nodeName,
2323 sizeof(struct lpfc_name));
2324 size = FOURBYTES + sizeof(struct lpfc_name);
2325 ad->AttrLen = cpu_to_be16(size);
2326 ad->AttrType = cpu_to_be16(RPRT_NODENAME);
2331 lpfc_fdmi_port_attr_wwpn(struct lpfc_vport *vport,
2332 struct lpfc_fdmi_attr_def *ad)
2334 struct lpfc_fdmi_attr_entry *ae;
2337 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2338 memset(ae, 0, sizeof(struct lpfc_name));
2340 memcpy(&ae->un.AttrWWN, &vport->fc_sparam.portName,
2341 sizeof(struct lpfc_name));
2342 size = FOURBYTES + sizeof(struct lpfc_name);
2343 ad->AttrLen = cpu_to_be16(size);
2344 ad->AttrType = cpu_to_be16(RPRT_PORTNAME);
2349 lpfc_fdmi_port_attr_symbolic_name(struct lpfc_vport *vport,
2350 struct lpfc_fdmi_attr_def *ad)
2352 struct lpfc_fdmi_attr_entry *ae;
2355 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2358 len = lpfc_vport_symbolic_port_name(vport, ae->un.AttrString, 256);
2359 len += (len & 3) ? (4 - (len & 3)) : 4;
2360 size = FOURBYTES + len;
2361 ad->AttrLen = cpu_to_be16(size);
2362 ad->AttrType = cpu_to_be16(RPRT_SYM_PORTNAME);
2367 lpfc_fdmi_port_attr_port_type(struct lpfc_vport *vport,
2368 struct lpfc_fdmi_attr_def *ad)
2370 struct lpfc_hba *phba = vport->phba;
2371 struct lpfc_fdmi_attr_entry *ae;
2374 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2375 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP)
2376 ae->un.AttrInt = cpu_to_be32(LPFC_FDMI_PORTTYPE_NLPORT);
2378 ae->un.AttrInt = cpu_to_be32(LPFC_FDMI_PORTTYPE_NPORT);
2379 size = FOURBYTES + sizeof(uint32_t);
2380 ad->AttrLen = cpu_to_be16(size);
2381 ad->AttrType = cpu_to_be16(RPRT_PORT_TYPE);
2386 lpfc_fdmi_port_attr_class(struct lpfc_vport *vport,
2387 struct lpfc_fdmi_attr_def *ad)
2389 struct lpfc_fdmi_attr_entry *ae;
2392 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2393 ae->un.AttrInt = cpu_to_be32(FC_COS_CLASS2 | FC_COS_CLASS3);
2394 size = FOURBYTES + sizeof(uint32_t);
2395 ad->AttrLen = cpu_to_be16(size);
2396 ad->AttrType = cpu_to_be16(RPRT_SUPPORTED_CLASS);
2401 lpfc_fdmi_port_attr_fabric_wwpn(struct lpfc_vport *vport,
2402 struct lpfc_fdmi_attr_def *ad)
2404 struct lpfc_fdmi_attr_entry *ae;
2407 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2408 memset(ae, 0, sizeof(struct lpfc_name));
2410 memcpy(&ae->un.AttrWWN, &vport->fabric_portname,
2411 sizeof(struct lpfc_name));
2412 size = FOURBYTES + sizeof(struct lpfc_name);
2413 ad->AttrLen = cpu_to_be16(size);
2414 ad->AttrType = cpu_to_be16(RPRT_FABRICNAME);
2419 lpfc_fdmi_port_attr_active_fc4type(struct lpfc_vport *vport,
2420 struct lpfc_fdmi_attr_def *ad)
2422 struct lpfc_fdmi_attr_entry *ae;
2425 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2428 ae->un.AttrTypes[3] = 0x02; /* Type 1 - ELS */
2429 ae->un.AttrTypes[2] = 0x01; /* Type 8 - FCP */
2430 ae->un.AttrTypes[7] = 0x01; /* Type 32 - CT */
2431 size = FOURBYTES + 32;
2432 ad->AttrLen = cpu_to_be16(size);
2433 ad->AttrType = cpu_to_be16(RPRT_ACTIVE_FC4_TYPES);
2438 lpfc_fdmi_port_attr_port_state(struct lpfc_vport *vport,
2439 struct lpfc_fdmi_attr_def *ad)
2441 struct lpfc_fdmi_attr_entry *ae;
2444 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2445 /* Link Up - operational */
2446 ae->un.AttrInt = cpu_to_be32(LPFC_FDMI_PORTSTATE_ONLINE);
2447 size = FOURBYTES + sizeof(uint32_t);
2448 ad->AttrLen = cpu_to_be16(size);
2449 ad->AttrType = cpu_to_be16(RPRT_PORT_STATE);
2454 lpfc_fdmi_port_attr_num_disc(struct lpfc_vport *vport,
2455 struct lpfc_fdmi_attr_def *ad)
2457 struct lpfc_fdmi_attr_entry *ae;
2460 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2461 vport->fdmi_num_disc = lpfc_find_map_node(vport);
2462 ae->un.AttrInt = cpu_to_be32(vport->fdmi_num_disc);
2463 size = FOURBYTES + sizeof(uint32_t);
2464 ad->AttrLen = cpu_to_be16(size);
2465 ad->AttrType = cpu_to_be16(RPRT_DISC_PORT);
2470 lpfc_fdmi_port_attr_nportid(struct lpfc_vport *vport,
2471 struct lpfc_fdmi_attr_def *ad)
2473 struct lpfc_fdmi_attr_entry *ae;
2476 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2477 ae->un.AttrInt = cpu_to_be32(vport->fc_myDID);
2478 size = FOURBYTES + sizeof(uint32_t);
2479 ad->AttrLen = cpu_to_be16(size);
2480 ad->AttrType = cpu_to_be16(RPRT_PORT_ID);
2485 lpfc_fdmi_smart_attr_service(struct lpfc_vport *vport,
2486 struct lpfc_fdmi_attr_def *ad)
2488 struct lpfc_fdmi_attr_entry *ae;
2491 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2494 strncpy(ae->un.AttrString, "Smart SAN Initiator",
2495 sizeof(ae->un.AttrString));
2496 len = strnlen(ae->un.AttrString,
2497 sizeof(ae->un.AttrString));
2498 len += (len & 3) ? (4 - (len & 3)) : 4;
2499 size = FOURBYTES + len;
2500 ad->AttrLen = cpu_to_be16(size);
2501 ad->AttrType = cpu_to_be16(RPRT_SMART_SERVICE);
2506 lpfc_fdmi_smart_attr_guid(struct lpfc_vport *vport,
2507 struct lpfc_fdmi_attr_def *ad)
2509 struct lpfc_fdmi_attr_entry *ae;
2512 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2515 memcpy(&ae->un.AttrString, &vport->fc_sparam.nodeName,
2516 sizeof(struct lpfc_name));
2517 memcpy((((uint8_t *)&ae->un.AttrString) +
2518 sizeof(struct lpfc_name)),
2519 &vport->fc_sparam.portName, sizeof(struct lpfc_name));
2520 size = FOURBYTES + (2 * sizeof(struct lpfc_name));
2521 ad->AttrLen = cpu_to_be16(size);
2522 ad->AttrType = cpu_to_be16(RPRT_SMART_GUID);
2527 lpfc_fdmi_smart_attr_version(struct lpfc_vport *vport,
2528 struct lpfc_fdmi_attr_def *ad)
2530 struct lpfc_fdmi_attr_entry *ae;
2533 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2536 strncpy(ae->un.AttrString, "Smart SAN Version 2.0",
2537 sizeof(ae->un.AttrString));
2538 len = strnlen(ae->un.AttrString,
2539 sizeof(ae->un.AttrString));
2540 len += (len & 3) ? (4 - (len & 3)) : 4;
2541 size = FOURBYTES + len;
2542 ad->AttrLen = cpu_to_be16(size);
2543 ad->AttrType = cpu_to_be16(RPRT_SMART_VERSION);
2548 lpfc_fdmi_smart_attr_model(struct lpfc_vport *vport,
2549 struct lpfc_fdmi_attr_def *ad)
2551 struct lpfc_hba *phba = vport->phba;
2552 struct lpfc_fdmi_attr_entry *ae;
2555 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2558 strncpy(ae->un.AttrString, phba->ModelName,
2559 sizeof(ae->un.AttrString));
2560 len = strnlen(ae->un.AttrString, sizeof(ae->un.AttrString));
2561 len += (len & 3) ? (4 - (len & 3)) : 4;
2562 size = FOURBYTES + len;
2563 ad->AttrLen = cpu_to_be16(size);
2564 ad->AttrType = cpu_to_be16(RPRT_SMART_MODEL);
2569 lpfc_fdmi_smart_attr_port_info(struct lpfc_vport *vport,
2570 struct lpfc_fdmi_attr_def *ad)
2572 struct lpfc_fdmi_attr_entry *ae;
2575 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2577 /* SRIOV (type 3) is not supported */
2579 ae->un.AttrInt = cpu_to_be32(2); /* NPIV */
2581 ae->un.AttrInt = cpu_to_be32(1); /* Physical */
2582 size = FOURBYTES + sizeof(uint32_t);
2583 ad->AttrLen = cpu_to_be16(size);
2584 ad->AttrType = cpu_to_be16(RPRT_SMART_PORT_INFO);
2589 lpfc_fdmi_smart_attr_qos(struct lpfc_vport *vport,
2590 struct lpfc_fdmi_attr_def *ad)
2592 struct lpfc_fdmi_attr_entry *ae;
2595 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2596 ae->un.AttrInt = cpu_to_be32(0);
2597 size = FOURBYTES + sizeof(uint32_t);
2598 ad->AttrLen = cpu_to_be16(size);
2599 ad->AttrType = cpu_to_be16(RPRT_SMART_QOS);
2604 lpfc_fdmi_smart_attr_security(struct lpfc_vport *vport,
2605 struct lpfc_fdmi_attr_def *ad)
2607 struct lpfc_fdmi_attr_entry *ae;
2610 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2611 ae->un.AttrInt = cpu_to_be32(1);
2612 size = FOURBYTES + sizeof(uint32_t);
2613 ad->AttrLen = cpu_to_be16(size);
2614 ad->AttrType = cpu_to_be16(RPRT_SMART_SECURITY);
2618 /* RHBA attribute jump table */
2619 int (*lpfc_fdmi_hba_action[])
2620 (struct lpfc_vport *vport, struct lpfc_fdmi_attr_def *ad) = {
2621 /* Action routine Mask bit Attribute type */
2622 lpfc_fdmi_hba_attr_wwnn, /* bit0 RHBA_NODENAME */
2623 lpfc_fdmi_hba_attr_manufacturer, /* bit1 RHBA_MANUFACTURER */
2624 lpfc_fdmi_hba_attr_sn, /* bit2 RHBA_SERIAL_NUMBER */
2625 lpfc_fdmi_hba_attr_model, /* bit3 RHBA_MODEL */
2626 lpfc_fdmi_hba_attr_description, /* bit4 RHBA_MODEL_DESCRIPTION */
2627 lpfc_fdmi_hba_attr_hdw_ver, /* bit5 RHBA_HARDWARE_VERSION */
2628 lpfc_fdmi_hba_attr_drvr_ver, /* bit6 RHBA_DRIVER_VERSION */
2629 lpfc_fdmi_hba_attr_rom_ver, /* bit7 RHBA_OPTION_ROM_VERSION */
2630 lpfc_fdmi_hba_attr_fmw_ver, /* bit8 RHBA_FIRMWARE_VERSION */
2631 lpfc_fdmi_hba_attr_os_ver, /* bit9 RHBA_OS_NAME_VERSION */
2632 lpfc_fdmi_hba_attr_ct_len, /* bit10 RHBA_MAX_CT_PAYLOAD_LEN */
2633 lpfc_fdmi_hba_attr_symbolic_name, /* bit11 RHBA_SYM_NODENAME */
2634 lpfc_fdmi_hba_attr_vendor_info, /* bit12 RHBA_VENDOR_INFO */
2635 lpfc_fdmi_hba_attr_num_ports, /* bit13 RHBA_NUM_PORTS */
2636 lpfc_fdmi_hba_attr_fabric_wwnn, /* bit14 RHBA_FABRIC_WWNN */
2637 lpfc_fdmi_hba_attr_bios_ver, /* bit15 RHBA_BIOS_VERSION */
2638 lpfc_fdmi_hba_attr_bios_state, /* bit16 RHBA_BIOS_STATE */
2639 lpfc_fdmi_hba_attr_vendor_id, /* bit17 RHBA_VENDOR_ID */
2642 /* RPA / RPRT attribute jump table */
2643 int (*lpfc_fdmi_port_action[])
2644 (struct lpfc_vport *vport, struct lpfc_fdmi_attr_def *ad) = {
2645 /* Action routine Mask bit Attribute type */
2646 lpfc_fdmi_port_attr_fc4type, /* bit0 RPRT_SUPPORT_FC4_TYPES */
2647 lpfc_fdmi_port_attr_support_speed, /* bit1 RPRT_SUPPORTED_SPEED */
2648 lpfc_fdmi_port_attr_speed, /* bit2 RPRT_PORT_SPEED */
2649 lpfc_fdmi_port_attr_max_frame, /* bit3 RPRT_MAX_FRAME_SIZE */
2650 lpfc_fdmi_port_attr_os_devname, /* bit4 RPRT_OS_DEVICE_NAME */
2651 lpfc_fdmi_port_attr_host_name, /* bit5 RPRT_HOST_NAME */
2652 lpfc_fdmi_port_attr_wwnn, /* bit6 RPRT_NODENAME */
2653 lpfc_fdmi_port_attr_wwpn, /* bit7 RPRT_PORTNAME */
2654 lpfc_fdmi_port_attr_symbolic_name, /* bit8 RPRT_SYM_PORTNAME */
2655 lpfc_fdmi_port_attr_port_type, /* bit9 RPRT_PORT_TYPE */
2656 lpfc_fdmi_port_attr_class, /* bit10 RPRT_SUPPORTED_CLASS */
2657 lpfc_fdmi_port_attr_fabric_wwpn, /* bit11 RPRT_FABRICNAME */
2658 lpfc_fdmi_port_attr_active_fc4type, /* bit12 RPRT_ACTIVE_FC4_TYPES */
2659 lpfc_fdmi_port_attr_port_state, /* bit13 RPRT_PORT_STATE */
2660 lpfc_fdmi_port_attr_num_disc, /* bit14 RPRT_DISC_PORT */
2661 lpfc_fdmi_port_attr_nportid, /* bit15 RPRT_PORT_ID */
2662 lpfc_fdmi_smart_attr_service, /* bit16 RPRT_SMART_SERVICE */
2663 lpfc_fdmi_smart_attr_guid, /* bit17 RPRT_SMART_GUID */
2664 lpfc_fdmi_smart_attr_version, /* bit18 RPRT_SMART_VERSION */
2665 lpfc_fdmi_smart_attr_model, /* bit19 RPRT_SMART_MODEL */
2666 lpfc_fdmi_smart_attr_port_info, /* bit20 RPRT_SMART_PORT_INFO */
2667 lpfc_fdmi_smart_attr_qos, /* bit21 RPRT_SMART_QOS */
2668 lpfc_fdmi_smart_attr_security, /* bit22 RPRT_SMART_SECURITY */
2672 * lpfc_fdmi_cmd - Build and send a FDMI cmd to the specified NPort
2673 * @vport: pointer to a host virtual N_Port data structure.
2674 * @ndlp: ndlp to send FDMI cmd to (if NULL use FDMI_DID)
2675 * cmdcode: FDMI command to send
2676 * mask: Mask of HBA or PORT Attributes to send
2678 * Builds and sends a FDMI command using the CT subsystem.
2681 lpfc_fdmi_cmd(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2682 int cmdcode, uint32_t new_mask)
2684 struct lpfc_hba *phba = vport->phba;
2685 struct lpfc_dmabuf *mp, *bmp;
2686 struct lpfc_sli_ct_request *CtReq;
2687 struct ulp_bde64 *bpl;
2692 struct lpfc_fdmi_reg_hba *rh;
2693 struct lpfc_fdmi_port_entry *pe;
2694 struct lpfc_fdmi_reg_portattr *pab = NULL;
2695 struct lpfc_fdmi_attr_block *ab = NULL;
2696 int (*func)(struct lpfc_vport *vport, struct lpfc_fdmi_attr_def *ad);
2697 void (*cmpl)(struct lpfc_hba *, struct lpfc_iocbq *,
2698 struct lpfc_iocbq *);
2700 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
2703 cmpl = lpfc_cmpl_ct_disc_fdmi; /* called from discovery */
2705 /* fill in BDEs for command */
2706 /* Allocate buffer for command payload */
2707 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
2711 mp->virt = lpfc_mbuf_alloc(phba, 0, &(mp->phys));
2713 goto fdmi_cmd_free_mp;
2715 /* Allocate buffer for Buffer ptr list */
2716 bmp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
2718 goto fdmi_cmd_free_mpvirt;
2720 bmp->virt = lpfc_mbuf_alloc(phba, 0, &(bmp->phys));
2722 goto fdmi_cmd_free_bmp;
2724 INIT_LIST_HEAD(&mp->list);
2725 INIT_LIST_HEAD(&bmp->list);
2728 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2729 "0218 FDMI Request Data: x%x x%x x%x\n",
2730 vport->fc_flag, vport->port_state, cmdcode);
2731 CtReq = (struct lpfc_sli_ct_request *)mp->virt;
2733 /* First populate the CT_IU preamble */
2734 memset(CtReq, 0, sizeof(struct lpfc_sli_ct_request));
2735 CtReq->RevisionId.bits.Revision = SLI_CT_REVISION;
2736 CtReq->RevisionId.bits.InId = 0;
2738 CtReq->FsType = SLI_CT_MANAGEMENT_SERVICE;
2739 CtReq->FsSubType = SLI_CT_FDMI_Subtypes;
2741 CtReq->CommandResponse.bits.CmdRsp = cpu_to_be16(cmdcode);
2742 rsp_size = LPFC_BPL_SIZE;
2745 /* Next fill in the specific FDMI cmd information */
2749 rh = (struct lpfc_fdmi_reg_hba *)&CtReq->un.PortID;
2750 /* HBA Identifier */
2751 memcpy(&rh->hi.PortName, &phba->pport->fc_sparam.portName,
2752 sizeof(struct lpfc_name));
2754 if (cmdcode == SLI_MGMT_RHBA) {
2755 /* Registered Port List */
2756 /* One entry (port) per adapter */
2757 rh->rpl.EntryCnt = cpu_to_be32(1);
2758 memcpy(&rh->rpl.pe, &phba->pport->fc_sparam.portName,
2759 sizeof(struct lpfc_name));
2761 /* point to the HBA attribute block */
2762 size = 2 * sizeof(struct lpfc_name) +
2765 size = sizeof(struct lpfc_name);
2767 ab = (struct lpfc_fdmi_attr_block *)((uint8_t *)rh + size);
2774 mask = vport->fdmi_hba_mask;
2776 /* Mask will dictate what attributes to build in the request */
2779 func = lpfc_fdmi_hba_action[bit_pos];
2781 (struct lpfc_fdmi_attr_def *)
2782 ((uint8_t *)rh + size));
2785 (LPFC_BPL_SIZE - LPFC_CT_PREAMBLE))
2792 ab->EntryCnt = cpu_to_be32(ab->EntryCnt);
2794 size = GID_REQUEST_SZ - 4 + size;
2799 pab = (struct lpfc_fdmi_reg_portattr *)&CtReq->un.PortID;
2800 if (cmdcode == SLI_MGMT_RPRT) {
2801 rh = (struct lpfc_fdmi_reg_hba *)pab;
2802 /* HBA Identifier */
2803 memcpy(&rh->hi.PortName,
2804 &phba->pport->fc_sparam.portName,
2805 sizeof(struct lpfc_name));
2806 pab = (struct lpfc_fdmi_reg_portattr *)
2807 ((uint8_t *)pab + sizeof(struct lpfc_name));
2810 memcpy((uint8_t *)&pab->PortName,
2811 (uint8_t *)&vport->fc_sparam.portName,
2812 sizeof(struct lpfc_name));
2813 size += sizeof(struct lpfc_name) + FOURBYTES;
2814 pab->ab.EntryCnt = 0;
2819 mask = vport->fdmi_port_mask;
2821 /* Mask will dictate what attributes to build in the request */
2824 func = lpfc_fdmi_port_action[bit_pos];
2826 (struct lpfc_fdmi_attr_def *)
2827 ((uint8_t *)pab + size));
2830 (LPFC_BPL_SIZE - LPFC_CT_PREAMBLE))
2837 pab->ab.EntryCnt = cpu_to_be32(pab->ab.EntryCnt);
2839 if (cmdcode == SLI_MGMT_RPRT)
2840 size += sizeof(struct lpfc_name);
2841 size = GID_REQUEST_SZ - 4 + size;
2846 rsp_size = FC_MAX_NS_RSP;
2849 pe = (struct lpfc_fdmi_port_entry *)&CtReq->un.PortID;
2850 memcpy((uint8_t *)&pe->PortName,
2851 (uint8_t *)&vport->fc_sparam.portName,
2852 sizeof(struct lpfc_name));
2853 size = GID_REQUEST_SZ - 4 + sizeof(struct lpfc_name);
2858 rsp_size = FC_MAX_NS_RSP;
2861 pe = (struct lpfc_fdmi_port_entry *)&CtReq->un.PortID;
2862 memcpy((uint8_t *)&pe->PortName,
2863 (uint8_t *)&vport->fc_sparam.portName,
2864 sizeof(struct lpfc_name));
2865 size = GID_REQUEST_SZ - 4 + sizeof(struct lpfc_name);
2868 size = GID_REQUEST_SZ - 4;
2871 lpfc_printf_vlog(vport, KERN_WARNING, LOG_DISCOVERY,
2872 "0298 FDMI cmdcode x%x not supported\n",
2874 goto fdmi_cmd_free_bmpvirt;
2876 CtReq->CommandResponse.bits.Size = cpu_to_be16(rsp_size);
2878 bpl = (struct ulp_bde64 *)bmp->virt;
2879 bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys));
2880 bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys));
2881 bpl->tus.f.bdeFlags = 0;
2882 bpl->tus.f.bdeSize = size;
2885 * The lpfc_ct_cmd/lpfc_get_req shall increment ndlp reference count
2886 * to hold ndlp reference for the corresponding callback function.
2888 if (!lpfc_ct_cmd(vport, mp, bmp, ndlp, cmpl, rsp_size, 0))
2892 * Decrement ndlp reference count to release ndlp reference held
2893 * for the failed command's callback function.
2897 fdmi_cmd_free_bmpvirt:
2898 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
2901 fdmi_cmd_free_mpvirt:
2902 lpfc_mbuf_free(phba, mp->virt, mp->phys);
2906 /* Issue FDMI request failed */
2907 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2908 "0244 Issue FDMI request failed Data: x%x\n",
2914 * lpfc_delayed_disc_tmo - Timeout handler for delayed discovery timer.
2915 * @ptr - Context object of the timer.
2917 * This function set the WORKER_DELAYED_DISC_TMO flag and wake up
2918 * the worker thread.
2921 lpfc_delayed_disc_tmo(struct timer_list *t)
2923 struct lpfc_vport *vport = from_timer(vport, t, delayed_disc_tmo);
2924 struct lpfc_hba *phba = vport->phba;
2925 uint32_t tmo_posted;
2926 unsigned long iflag;
2928 spin_lock_irqsave(&vport->work_port_lock, iflag);
2929 tmo_posted = vport->work_port_events & WORKER_DELAYED_DISC_TMO;
2931 vport->work_port_events |= WORKER_DELAYED_DISC_TMO;
2932 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
2935 lpfc_worker_wake_up(phba);
2940 * lpfc_delayed_disc_timeout_handler - Function called by worker thread to
2941 * handle delayed discovery.
2942 * @vport: pointer to a host virtual N_Port data structure.
2944 * This function start nport discovery of the vport.
2947 lpfc_delayed_disc_timeout_handler(struct lpfc_vport *vport)
2949 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2951 spin_lock_irq(shost->host_lock);
2952 if (!(vport->fc_flag & FC_DISC_DELAYED)) {
2953 spin_unlock_irq(shost->host_lock);
2956 vport->fc_flag &= ~FC_DISC_DELAYED;
2957 spin_unlock_irq(shost->host_lock);
2959 lpfc_do_scr_ns_plogi(vport->phba, vport);
2963 lpfc_decode_firmware_rev(struct lpfc_hba *phba, char *fwrevision, int flag)
2965 struct lpfc_sli *psli = &phba->sli;
2966 lpfc_vpd_t *vp = &phba->vpd;
2967 uint32_t b1, b2, b3, b4, i, rev;
2969 uint32_t *ptr, str[4];
2972 if (phba->sli_rev == LPFC_SLI_REV4)
2973 snprintf(fwrevision, FW_REV_STR_SIZE, "%s", vp->rev.opFwName);
2974 else if (vp->rev.rBit) {
2975 if (psli->sli_flag & LPFC_SLI_ACTIVE)
2976 rev = vp->rev.sli2FwRev;
2978 rev = vp->rev.sli1FwRev;
2980 b1 = (rev & 0x0000f000) >> 12;
2981 b2 = (rev & 0x00000f00) >> 8;
2982 b3 = (rev & 0x000000c0) >> 6;
2983 b4 = (rev & 0x00000030) >> 4;
3002 b4 = (rev & 0x0000000f);
3004 if (psli->sli_flag & LPFC_SLI_ACTIVE)
3005 fwname = vp->rev.sli2FwName;
3007 fwname = vp->rev.sli1FwName;
3009 for (i = 0; i < 16; i++)
3010 if (fwname[i] == 0x20)
3013 ptr = (uint32_t*)fwname;
3015 for (i = 0; i < 3; i++)
3016 str[i] = be32_to_cpu(*ptr++);
3020 sprintf(fwrevision, "%d.%d%d (%s)",
3021 b1, b2, b3, (char *)str);
3023 sprintf(fwrevision, "%d.%d%d", b1,
3027 sprintf(fwrevision, "%d.%d%d%c%d (%s)",
3031 sprintf(fwrevision, "%d.%d%d%c%d",
3035 rev = vp->rev.smFwRev;
3037 b1 = (rev & 0xff000000) >> 24;
3038 b2 = (rev & 0x00f00000) >> 20;
3039 b3 = (rev & 0x000f0000) >> 16;
3040 c = (rev & 0x0000ff00) >> 8;
3041 b4 = (rev & 0x000000ff);
3043 sprintf(fwrevision, "%d.%d%d%c%d", b1, b2, b3, c, b4);