1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2017 Broadcom. All Rights Reserved. The term *
5 * “Broadcom” refers to Broadcom Limited and/or its subsidiaries. *
6 * Copyright (C) 2004-2016 Emulex. All rights reserved. *
7 * EMULEX and SLI are trademarks of Emulex. *
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 /* By default, the driver expects to support FCP FC4 */
475 if (fc4_type == FC_TYPE_FCP)
476 ndlp->nlp_fc4_type |= NLP_FC4_FCP;
478 if (fc4_type == FC_TYPE_NVME)
479 ndlp->nlp_fc4_type |= NLP_FC4_NVME;
481 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
482 "0238 Process x%06x NameServer Rsp "
483 "Data: x%x x%x x%x x%x\n", Did,
484 ndlp->nlp_flag, ndlp->nlp_fc4_type,
486 vport->fc_rscn_id_cnt);
488 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
489 "Skip1 GID_FTrsp: did:x%x flg:x%x cnt:%d",
490 Did, vport->fc_flag, vport->fc_rscn_id_cnt);
492 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
493 "0239 Skip x%06x NameServer Rsp "
494 "Data: x%x x%x\n", Did,
496 vport->fc_rscn_id_cnt);
499 if (!(vport->fc_flag & FC_RSCN_MODE) ||
500 lpfc_rscn_payload_check(vport, Did)) {
501 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
502 "Query GID_FTrsp: did:x%x flg:x%x cnt:%d",
503 Did, vport->fc_flag, vport->fc_rscn_id_cnt);
506 * This NPortID was previously a FCP/NVMe target,
507 * Don't even bother to send GFF_ID.
509 ndlp = lpfc_findnode_did(vport, Did);
510 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
512 (NLP_FCP_TARGET | NLP_NVME_TARGET))) {
513 if (fc4_type == FC_TYPE_FCP)
514 ndlp->nlp_fc4_type |= NLP_FC4_FCP;
515 if (fc4_type == FC_TYPE_NVME)
516 ndlp->nlp_fc4_type |= NLP_FC4_NVME;
517 lpfc_setup_disc_node(vport, Did);
518 } else if (lpfc_ns_cmd(vport, SLI_CTNS_GFF_ID,
520 vport->num_disc_nodes++;
522 lpfc_setup_disc_node(vport, Did);
524 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
525 "Skip2 GID_FTrsp: did:x%x flg:x%x cnt:%d",
526 Did, vport->fc_flag, vport->fc_rscn_id_cnt);
528 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
529 "0245 Skip x%06x NameServer Rsp "
530 "Data: x%x x%x\n", Did,
532 vport->fc_rscn_id_cnt);
538 lpfc_ns_rsp_audit_did(struct lpfc_vport *vport, uint32_t Did, uint8_t fc4_type)
540 struct lpfc_hba *phba = vport->phba;
541 struct lpfc_nodelist *ndlp = NULL;
542 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
545 * To conserve rpi's, filter out addresses for other
546 * vports on the same physical HBAs.
548 if (Did != vport->fc_myDID &&
549 (!lpfc_find_vport_by_did(phba, Did) ||
550 vport->cfg_peer_port_login)) {
551 if (!phba->nvmet_support) {
552 /* FCPI/NVMEI path. Process Did */
553 lpfc_prep_node_fc4type(vport, Did, fc4_type);
556 /* NVMET path. NVMET only cares about NVMEI nodes. */
557 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
558 if (ndlp->nlp_type != NLP_NVME_INITIATOR ||
559 ndlp->nlp_state != NLP_STE_UNMAPPED_NODE)
561 spin_lock_irq(shost->host_lock);
562 if (ndlp->nlp_DID == Did)
563 ndlp->nlp_flag &= ~NLP_NVMET_RECOV;
565 ndlp->nlp_flag |= NLP_NVMET_RECOV;
566 spin_unlock_irq(shost->host_lock);
572 lpfc_ns_rsp(struct lpfc_vport *vport, struct lpfc_dmabuf *mp, uint8_t fc4_type,
575 struct lpfc_sli_ct_request *Response =
576 (struct lpfc_sli_ct_request *) mp->virt;
577 struct lpfc_dmabuf *mlast, *next_mp;
578 uint32_t *ctptr = (uint32_t *) & Response->un.gid.PortType;
579 uint32_t Did, CTentry;
581 struct list_head head;
582 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
583 struct lpfc_nodelist *ndlp = NULL;
585 lpfc_set_disctmo(vport);
586 vport->num_disc_nodes = 0;
587 vport->fc_ns_retry = 0;
590 list_add_tail(&head, &mp->list);
591 list_for_each_entry_safe(mp, next_mp, &head, list) {
594 Cnt = Size > FCELSSIZE ? FCELSSIZE : Size;
599 ctptr = (uint32_t *) mlast->virt;
601 Cnt -= 16; /* subtract length of CT header */
603 /* Loop through entire NameServer list of DIDs */
604 while (Cnt >= sizeof(uint32_t)) {
605 /* Get next DID from NameServer List */
607 Did = ((be32_to_cpu(CTentry)) & Mask_DID);
608 lpfc_ns_rsp_audit_did(vport, Did, fc4_type);
609 if (CTentry & (cpu_to_be32(SLI_CT_LAST_ENTRY)))
612 Cnt -= sizeof(uint32_t);
618 /* All GID_FT entries processed. If the driver is running in
619 * in target mode, put impacted nodes into recovery and drop
620 * the RPI to flush outstanding IO.
622 if (vport->phba->nvmet_support) {
623 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
624 if (!(ndlp->nlp_flag & NLP_NVMET_RECOV))
626 lpfc_disc_state_machine(vport, ndlp, NULL,
627 NLP_EVT_DEVICE_RECOVERY);
628 spin_lock_irq(shost->host_lock);
629 ndlp->nlp_flag &= ~NLP_NVMET_RECOV;
630 spin_unlock_irq(shost->host_lock);
640 lpfc_cmpl_ct_cmd_gid_ft(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
641 struct lpfc_iocbq *rspiocb)
643 struct lpfc_vport *vport = cmdiocb->vport;
644 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
646 struct lpfc_dmabuf *outp;
647 struct lpfc_dmabuf *inp;
648 struct lpfc_sli_ct_request *CTrsp;
649 struct lpfc_sli_ct_request *CTreq;
650 struct lpfc_nodelist *ndlp;
653 /* First save ndlp, before we overwrite it */
654 ndlp = cmdiocb->context_un.ndlp;
656 /* we pass cmdiocb to state machine which needs rspiocb as well */
657 cmdiocb->context_un.rsp_iocb = rspiocb;
658 inp = (struct lpfc_dmabuf *) cmdiocb->context1;
659 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
660 irsp = &rspiocb->iocb;
662 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
663 "GID_FT cmpl: status:x%x/x%x rtry:%d",
664 irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_ns_retry);
666 /* Don't bother processing response if vport is being torn down. */
667 if (vport->load_flag & FC_UNLOADING) {
668 if (vport->fc_flag & FC_RSCN_MODE)
669 lpfc_els_flush_rscn(vport);
673 if (lpfc_els_chk_latt(vport)) {
674 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
675 "0216 Link event during NS query\n");
676 if (vport->fc_flag & FC_RSCN_MODE)
677 lpfc_els_flush_rscn(vport);
678 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
681 if (lpfc_error_lost_link(irsp)) {
682 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
683 "0226 NS query failed due to link event\n");
684 if (vport->fc_flag & FC_RSCN_MODE)
685 lpfc_els_flush_rscn(vport);
688 if (irsp->ulpStatus) {
689 /* Check for retry */
690 if (vport->fc_ns_retry < LPFC_MAX_NS_RETRY) {
691 if (irsp->ulpStatus != IOSTAT_LOCAL_REJECT ||
692 (irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
694 vport->fc_ns_retry++;
696 type = lpfc_get_gidft_type(vport, cmdiocb);
700 /* CT command is being retried */
702 rc = lpfc_ns_cmd(vport, SLI_CTNS_GID_FT,
703 vport->fc_ns_retry, type);
707 if (vport->fc_flag & FC_RSCN_MODE)
708 lpfc_els_flush_rscn(vport);
709 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
710 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
711 "0257 GID_FT Query error: 0x%x 0x%x\n",
712 irsp->ulpStatus, vport->fc_ns_retry);
714 /* Good status, continue checking */
715 CTreq = (struct lpfc_sli_ct_request *) inp->virt;
716 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
717 if (CTrsp->CommandResponse.bits.CmdRsp ==
718 cpu_to_be16(SLI_CT_RESPONSE_FS_ACC)) {
719 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
720 "0208 NameServer Rsp Data: x%x x%x\n",
722 CTreq->un.gid.Fc4Type);
726 CTreq->un.gid.Fc4Type,
727 (uint32_t) (irsp->un.genreq64.bdl.bdeSize));
728 } else if (CTrsp->CommandResponse.bits.CmdRsp ==
729 be16_to_cpu(SLI_CT_RESPONSE_FS_RJT)) {
730 /* NameServer Rsp Error */
731 if ((CTrsp->ReasonCode == SLI_CT_UNABLE_TO_PERFORM_REQ)
732 && (CTrsp->Explanation == SLI_CT_NO_FC4_TYPES)) {
733 lpfc_printf_vlog(vport, KERN_INFO,
735 "0269 No NameServer Entries "
736 "Data: x%x x%x x%x x%x\n",
737 CTrsp->CommandResponse.bits.CmdRsp,
738 (uint32_t) CTrsp->ReasonCode,
739 (uint32_t) CTrsp->Explanation,
742 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
743 "GID_FT no entry cmd:x%x rsn:x%x exp:x%x",
744 (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
745 (uint32_t) CTrsp->ReasonCode,
746 (uint32_t) CTrsp->Explanation);
748 lpfc_printf_vlog(vport, KERN_INFO,
750 "0240 NameServer Rsp Error "
751 "Data: x%x x%x x%x x%x\n",
752 CTrsp->CommandResponse.bits.CmdRsp,
753 (uint32_t) CTrsp->ReasonCode,
754 (uint32_t) CTrsp->Explanation,
757 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
758 "GID_FT rsp err1 cmd:x%x rsn:x%x exp:x%x",
759 (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
760 (uint32_t) CTrsp->ReasonCode,
761 (uint32_t) CTrsp->Explanation);
766 /* NameServer Rsp Error */
767 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
768 "0241 NameServer Rsp Error "
769 "Data: x%x x%x x%x x%x\n",
770 CTrsp->CommandResponse.bits.CmdRsp,
771 (uint32_t) CTrsp->ReasonCode,
772 (uint32_t) CTrsp->Explanation,
775 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
776 "GID_FT rsp err2 cmd:x%x rsn:x%x exp:x%x",
777 (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
778 (uint32_t) CTrsp->ReasonCode,
779 (uint32_t) CTrsp->Explanation);
783 /* Link up / RSCN discovery */
784 if ((vport->num_disc_nodes == 0) &&
785 (vport->gidft_inp == 0)) {
787 * The driver has cycled through all Nports in the RSCN payload.
788 * Complete the handling by cleaning up and marking the
789 * current driver state.
791 if (vport->port_state >= LPFC_DISC_AUTH) {
792 if (vport->fc_flag & FC_RSCN_MODE) {
793 lpfc_els_flush_rscn(vport);
794 spin_lock_irq(shost->host_lock);
795 vport->fc_flag |= FC_RSCN_MODE; /* RSCN still */
796 spin_unlock_irq(shost->host_lock);
799 lpfc_els_flush_rscn(vport);
802 lpfc_disc_start(vport);
805 cmdiocb->context_un.ndlp = ndlp; /* Now restore ndlp for free */
806 lpfc_ct_free_iocb(phba, cmdiocb);
811 lpfc_cmpl_ct_cmd_gff_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
812 struct lpfc_iocbq *rspiocb)
814 struct lpfc_vport *vport = cmdiocb->vport;
815 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
816 IOCB_t *irsp = &rspiocb->iocb;
817 struct lpfc_dmabuf *inp = (struct lpfc_dmabuf *) cmdiocb->context1;
818 struct lpfc_dmabuf *outp = (struct lpfc_dmabuf *) cmdiocb->context2;
819 struct lpfc_sli_ct_request *CTrsp;
822 struct lpfc_nodelist *ndlp;
824 did = ((struct lpfc_sli_ct_request *) inp->virt)->un.gff.PortId;
825 did = be32_to_cpu(did);
827 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
828 "GFF_ID cmpl: status:x%x/x%x did:x%x",
829 irsp->ulpStatus, irsp->un.ulpWord[4], did);
831 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
832 /* Good status, continue checking */
833 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
834 fbits = CTrsp->un.gff_acc.fbits[FCP_TYPE_FEATURE_OFFSET];
836 if (CTrsp->CommandResponse.bits.CmdRsp ==
837 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC)) {
838 if ((fbits & FC4_FEATURE_INIT) &&
839 !(fbits & FC4_FEATURE_TARGET)) {
840 lpfc_printf_vlog(vport, KERN_INFO,
843 "NameServer Rsp Data: (init) "
844 "x%x x%x\n", did, fbits,
845 vport->fc_rscn_id_cnt);
851 /* Check for retry */
852 if (cmdiocb->retry < LPFC_MAX_NS_RETRY) {
854 if (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) {
855 switch ((irsp->un.ulpWord[4] &
858 case IOERR_NO_RESOURCES:
859 /* We don't increment the retry
860 * count for this case.
863 case IOERR_LINK_DOWN:
864 case IOERR_SLI_ABORTED:
876 /* CT command is being retried */
877 rc = lpfc_ns_cmd(vport, SLI_CTNS_GFF_ID,
878 cmdiocb->retry, did);
881 lpfc_ct_free_iocb(phba, cmdiocb);
886 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
887 "0267 NameServer GFF Rsp "
888 "x%x Error (%d %d) Data: x%x x%x\n",
889 did, irsp->ulpStatus, irsp->un.ulpWord[4],
890 vport->fc_flag, vport->fc_rscn_id_cnt);
893 /* This is a target port, unregistered port, or the GFF_ID failed */
894 ndlp = lpfc_setup_disc_node(vport, did);
895 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
896 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
897 "0242 Process x%x GFF "
898 "NameServer Rsp Data: x%x x%x x%x\n",
899 did, ndlp->nlp_flag, vport->fc_flag,
900 vport->fc_rscn_id_cnt);
902 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
904 "NameServer Rsp Data: x%x x%x\n", did,
905 vport->fc_flag, vport->fc_rscn_id_cnt);
908 /* Link up / RSCN discovery */
909 if (vport->num_disc_nodes)
910 vport->num_disc_nodes--;
911 if (vport->num_disc_nodes == 0) {
913 * The driver has cycled through all Nports in the RSCN payload.
914 * Complete the handling by cleaning up and marking the
915 * current driver state.
917 if (vport->port_state >= LPFC_DISC_AUTH) {
918 if (vport->fc_flag & FC_RSCN_MODE) {
919 lpfc_els_flush_rscn(vport);
920 spin_lock_irq(shost->host_lock);
921 vport->fc_flag |= FC_RSCN_MODE; /* RSCN still */
922 spin_unlock_irq(shost->host_lock);
925 lpfc_els_flush_rscn(vport);
927 lpfc_disc_start(vport);
929 lpfc_ct_free_iocb(phba, cmdiocb);
934 lpfc_cmpl_ct_cmd_gft_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
935 struct lpfc_iocbq *rspiocb)
937 struct lpfc_vport *vport = cmdiocb->vport;
938 IOCB_t *irsp = &rspiocb->iocb;
939 struct lpfc_dmabuf *inp = (struct lpfc_dmabuf *)cmdiocb->context1;
940 struct lpfc_dmabuf *outp = (struct lpfc_dmabuf *)cmdiocb->context2;
941 struct lpfc_sli_ct_request *CTrsp;
943 struct lpfc_nodelist *ndlp;
944 uint32_t fc4_data_0, fc4_data_1;
946 did = ((struct lpfc_sli_ct_request *)inp->virt)->un.gft.PortId;
947 did = be32_to_cpu(did);
949 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
950 "GFT_ID cmpl: status:x%x/x%x did:x%x",
951 irsp->ulpStatus, irsp->un.ulpWord[4], did);
953 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
954 /* Good status, continue checking */
955 CTrsp = (struct lpfc_sli_ct_request *)outp->virt;
956 fc4_data_0 = be32_to_cpu(CTrsp->un.gft_acc.fc4_types[0]);
957 fc4_data_1 = be32_to_cpu(CTrsp->un.gft_acc.fc4_types[1]);
958 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
959 "3062 DID x%06x GFT Wd0 x%08x Wd1 x%08x\n",
960 did, fc4_data_0, fc4_data_1);
962 ndlp = lpfc_findnode_did(vport, did);
964 /* The bitmask value for FCP and NVME FCP types is
965 * the same because they are 32 bits distant from
966 * each other in word0 and word0.
968 if (fc4_data_0 & LPFC_FC4_TYPE_BITMASK)
969 ndlp->nlp_fc4_type |= NLP_FC4_FCP;
970 if (fc4_data_1 & LPFC_FC4_TYPE_BITMASK)
971 ndlp->nlp_fc4_type |= NLP_FC4_NVME;
972 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
973 "3064 Setting ndlp %p, DID x%06x with "
974 "FC4 x%08x, Data: x%08x x%08x\n",
975 ndlp, did, ndlp->nlp_fc4_type,
976 FC_TYPE_FCP, FC_TYPE_NVME);
977 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
979 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
980 lpfc_issue_els_prli(vport, ndlp, 0);
983 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
984 "3065 GFT_ID failed x%08x\n", irsp->ulpStatus);
986 lpfc_ct_free_iocb(phba, cmdiocb);
990 lpfc_cmpl_ct(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
991 struct lpfc_iocbq *rspiocb)
993 struct lpfc_vport *vport = cmdiocb->vport;
994 struct lpfc_dmabuf *inp;
995 struct lpfc_dmabuf *outp;
997 struct lpfc_sli_ct_request *CTrsp;
998 struct lpfc_nodelist *ndlp;
1003 /* First save ndlp, before we overwrite it */
1004 ndlp = cmdiocb->context_un.ndlp;
1006 /* we pass cmdiocb to state machine which needs rspiocb as well */
1007 cmdiocb->context_un.rsp_iocb = rspiocb;
1009 inp = (struct lpfc_dmabuf *) cmdiocb->context1;
1010 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
1011 irsp = &rspiocb->iocb;
1013 cmdcode = be16_to_cpu(((struct lpfc_sli_ct_request *) inp->virt)->
1014 CommandResponse.bits.CmdRsp);
1015 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
1017 latt = lpfc_els_chk_latt(vport);
1019 /* RFT request completes status <ulpStatus> CmdRsp <CmdRsp> */
1020 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1021 "0209 CT Request completes, latt %d, "
1022 "ulpStatus x%x CmdRsp x%x, Context x%x, Tag x%x\n",
1023 latt, irsp->ulpStatus,
1024 CTrsp->CommandResponse.bits.CmdRsp,
1025 cmdiocb->iocb.ulpContext, cmdiocb->iocb.ulpIoTag);
1027 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
1028 "CT cmd cmpl: status:x%x/x%x cmd:x%x",
1029 irsp->ulpStatus, irsp->un.ulpWord[4], cmdcode);
1031 if (irsp->ulpStatus) {
1032 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
1033 "0268 NS cmd x%x Error (x%x x%x)\n",
1034 cmdcode, irsp->ulpStatus, irsp->un.ulpWord[4]);
1036 if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
1037 (((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
1039 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
1040 IOERR_SLI_ABORTED)))
1043 retry = cmdiocb->retry;
1044 if (retry >= LPFC_MAX_NS_RETRY)
1048 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1049 "0250 Retrying NS cmd %x\n", cmdcode);
1050 rc = lpfc_ns_cmd(vport, cmdcode, retry, 0);
1056 cmdiocb->context_un.ndlp = ndlp; /* Now restore ndlp for free */
1057 lpfc_ct_free_iocb(phba, cmdiocb);
1062 lpfc_cmpl_ct_cmd_rft_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1063 struct lpfc_iocbq *rspiocb)
1065 IOCB_t *irsp = &rspiocb->iocb;
1066 struct lpfc_vport *vport = cmdiocb->vport;
1068 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
1069 struct lpfc_dmabuf *outp;
1070 struct lpfc_sli_ct_request *CTrsp;
1072 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
1073 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
1074 if (CTrsp->CommandResponse.bits.CmdRsp ==
1075 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
1076 vport->ct_flags |= FC_CT_RFT_ID;
1078 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
1083 lpfc_cmpl_ct_cmd_rnn_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1084 struct lpfc_iocbq *rspiocb)
1086 IOCB_t *irsp = &rspiocb->iocb;
1087 struct lpfc_vport *vport = cmdiocb->vport;
1089 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
1090 struct lpfc_dmabuf *outp;
1091 struct lpfc_sli_ct_request *CTrsp;
1093 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
1094 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
1095 if (CTrsp->CommandResponse.bits.CmdRsp ==
1096 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
1097 vport->ct_flags |= FC_CT_RNN_ID;
1099 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
1104 lpfc_cmpl_ct_cmd_rspn_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1105 struct lpfc_iocbq *rspiocb)
1107 IOCB_t *irsp = &rspiocb->iocb;
1108 struct lpfc_vport *vport = cmdiocb->vport;
1110 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
1111 struct lpfc_dmabuf *outp;
1112 struct lpfc_sli_ct_request *CTrsp;
1114 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
1115 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
1116 if (CTrsp->CommandResponse.bits.CmdRsp ==
1117 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
1118 vport->ct_flags |= FC_CT_RSPN_ID;
1120 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
1125 lpfc_cmpl_ct_cmd_rsnn_nn(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1126 struct lpfc_iocbq *rspiocb)
1128 IOCB_t *irsp = &rspiocb->iocb;
1129 struct lpfc_vport *vport = cmdiocb->vport;
1131 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
1132 struct lpfc_dmabuf *outp;
1133 struct lpfc_sli_ct_request *CTrsp;
1135 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
1136 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
1137 if (CTrsp->CommandResponse.bits.CmdRsp ==
1138 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
1139 vport->ct_flags |= FC_CT_RSNN_NN;
1141 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
1146 lpfc_cmpl_ct_cmd_da_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1147 struct lpfc_iocbq *rspiocb)
1149 struct lpfc_vport *vport = cmdiocb->vport;
1151 /* even if it fails we will act as though it succeeded. */
1152 vport->ct_flags = 0;
1153 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
1158 lpfc_cmpl_ct_cmd_rff_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1159 struct lpfc_iocbq *rspiocb)
1161 IOCB_t *irsp = &rspiocb->iocb;
1162 struct lpfc_vport *vport = cmdiocb->vport;
1164 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
1165 struct lpfc_dmabuf *outp;
1166 struct lpfc_sli_ct_request *CTrsp;
1168 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
1169 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
1170 if (CTrsp->CommandResponse.bits.CmdRsp ==
1171 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
1172 vport->ct_flags |= FC_CT_RFF_ID;
1174 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
1179 * Although the symbolic port name is thought to be an integer
1180 * as of January 18, 2016, leave it as a string until more of
1181 * the record state becomes defined.
1184 lpfc_vport_symbolic_port_name(struct lpfc_vport *vport, char *symbol,
1190 * Use the lpfc board number as the Symbolic Port
1191 * Name object. NPIV is not in play so this integer
1192 * value is sufficient and unique per FC-ID.
1194 n = snprintf(symbol, size, "%d", vport->phba->brd_no);
1200 lpfc_vport_symbolic_node_name(struct lpfc_vport *vport, char *symbol,
1203 char fwrev[FW_REV_STR_SIZE];
1206 lpfc_decode_firmware_rev(vport->phba, fwrev, 0);
1208 n = snprintf(symbol, size, "Emulex %s", vport->phba->ModelName);
1212 n += snprintf(symbol + n, size - n, " FV%s", fwrev);
1216 n += snprintf(symbol + n, size - n, " DV%s.",
1217 lpfc_release_version);
1221 n += snprintf(symbol + n, size - n, " HN:%s.",
1222 init_utsname()->nodename);
1226 /* Note :- OS name is "Linux" */
1227 n += snprintf(symbol + n, size - n, " OS:%s\n",
1228 init_utsname()->sysname);
1233 lpfc_find_map_node(struct lpfc_vport *vport)
1235 struct lpfc_nodelist *ndlp, *next_ndlp;
1236 struct Scsi_Host *shost;
1239 shost = lpfc_shost_from_vport(vport);
1240 spin_lock_irq(shost->host_lock);
1241 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
1242 if (ndlp->nlp_type & NLP_FABRIC)
1244 if ((ndlp->nlp_state == NLP_STE_MAPPED_NODE) ||
1245 (ndlp->nlp_state == NLP_STE_UNMAPPED_NODE))
1248 spin_unlock_irq(shost->host_lock);
1253 * This routine will return the FC4 Type associated with the CT
1257 lpfc_get_gidft_type(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb)
1259 struct lpfc_sli_ct_request *CtReq;
1260 struct lpfc_dmabuf *mp;
1263 mp = cmdiocb->context1;
1266 CtReq = (struct lpfc_sli_ct_request *)mp->virt;
1267 type = (uint32_t)CtReq->un.gid.Fc4Type;
1268 if ((type != SLI_CTPT_FCP) && (type != SLI_CTPT_NVME))
1276 * Issue Cmd to NameServer
1281 lpfc_ns_cmd(struct lpfc_vport *vport, int cmdcode,
1282 uint8_t retry, uint32_t context)
1284 struct lpfc_nodelist * ndlp;
1285 struct lpfc_hba *phba = vport->phba;
1286 struct lpfc_dmabuf *mp, *bmp;
1287 struct lpfc_sli_ct_request *CtReq;
1288 struct ulp_bde64 *bpl;
1289 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
1290 struct lpfc_iocbq *) = NULL;
1291 uint32_t rsp_size = 1024;
1295 ndlp = lpfc_findnode_did(vport, NameServer_DID);
1296 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)
1297 || ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) {
1302 /* fill in BDEs for command */
1303 /* Allocate buffer for command payload */
1304 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
1310 INIT_LIST_HEAD(&mp->list);
1311 mp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(mp->phys));
1314 goto ns_cmd_free_mp;
1317 /* Allocate buffer for Buffer ptr list */
1318 bmp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
1321 goto ns_cmd_free_mpvirt;
1324 INIT_LIST_HEAD(&bmp->list);
1325 bmp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(bmp->phys));
1328 goto ns_cmd_free_bmp;
1331 /* NameServer Req */
1332 lpfc_printf_vlog(vport, KERN_INFO ,LOG_DISCOVERY,
1333 "0236 NameServer Req Data: x%x x%x x%x x%x\n",
1334 cmdcode, vport->fc_flag, vport->fc_rscn_id_cnt,
1337 bpl = (struct ulp_bde64 *) bmp->virt;
1338 memset(bpl, 0, sizeof(struct ulp_bde64));
1339 bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys) );
1340 bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys) );
1341 bpl->tus.f.bdeFlags = 0;
1342 if (cmdcode == SLI_CTNS_GID_FT)
1343 bpl->tus.f.bdeSize = GID_REQUEST_SZ;
1344 else if (cmdcode == SLI_CTNS_GFF_ID)
1345 bpl->tus.f.bdeSize = GFF_REQUEST_SZ;
1346 else if (cmdcode == SLI_CTNS_GFT_ID)
1347 bpl->tus.f.bdeSize = GFT_REQUEST_SZ;
1348 else if (cmdcode == SLI_CTNS_RFT_ID)
1349 bpl->tus.f.bdeSize = RFT_REQUEST_SZ;
1350 else if (cmdcode == SLI_CTNS_RNN_ID)
1351 bpl->tus.f.bdeSize = RNN_REQUEST_SZ;
1352 else if (cmdcode == SLI_CTNS_RSPN_ID)
1353 bpl->tus.f.bdeSize = RSPN_REQUEST_SZ;
1354 else if (cmdcode == SLI_CTNS_RSNN_NN)
1355 bpl->tus.f.bdeSize = RSNN_REQUEST_SZ;
1356 else if (cmdcode == SLI_CTNS_DA_ID)
1357 bpl->tus.f.bdeSize = DA_ID_REQUEST_SZ;
1358 else if (cmdcode == SLI_CTNS_RFF_ID)
1359 bpl->tus.f.bdeSize = RFF_REQUEST_SZ;
1361 bpl->tus.f.bdeSize = 0;
1362 bpl->tus.w = le32_to_cpu(bpl->tus.w);
1364 CtReq = (struct lpfc_sli_ct_request *) mp->virt;
1365 memset(CtReq, 0, sizeof(struct lpfc_sli_ct_request));
1366 CtReq->RevisionId.bits.Revision = SLI_CT_REVISION;
1367 CtReq->RevisionId.bits.InId = 0;
1368 CtReq->FsType = SLI_CT_DIRECTORY_SERVICE;
1369 CtReq->FsSubType = SLI_CT_DIRECTORY_NAME_SERVER;
1370 CtReq->CommandResponse.bits.Size = 0;
1372 case SLI_CTNS_GID_FT:
1373 CtReq->CommandResponse.bits.CmdRsp =
1374 cpu_to_be16(SLI_CTNS_GID_FT);
1375 CtReq->un.gid.Fc4Type = context;
1377 if (vport->port_state < LPFC_NS_QRY)
1378 vport->port_state = LPFC_NS_QRY;
1379 lpfc_set_disctmo(vport);
1380 cmpl = lpfc_cmpl_ct_cmd_gid_ft;
1381 rsp_size = FC_MAX_NS_RSP;
1384 case SLI_CTNS_GFF_ID:
1385 CtReq->CommandResponse.bits.CmdRsp =
1386 cpu_to_be16(SLI_CTNS_GFF_ID);
1387 CtReq->un.gff.PortId = cpu_to_be32(context);
1388 cmpl = lpfc_cmpl_ct_cmd_gff_id;
1391 case SLI_CTNS_GFT_ID:
1392 CtReq->CommandResponse.bits.CmdRsp =
1393 cpu_to_be16(SLI_CTNS_GFT_ID);
1394 CtReq->un.gft.PortId = cpu_to_be32(context);
1395 cmpl = lpfc_cmpl_ct_cmd_gft_id;
1398 case SLI_CTNS_RFT_ID:
1399 vport->ct_flags &= ~FC_CT_RFT_ID;
1400 CtReq->CommandResponse.bits.CmdRsp =
1401 cpu_to_be16(SLI_CTNS_RFT_ID);
1402 CtReq->un.rft.PortId = cpu_to_be32(vport->fc_myDID);
1404 /* Register FC4 FCP type if enabled. */
1405 if ((phba->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
1406 (phba->cfg_enable_fc4_type == LPFC_ENABLE_FCP))
1407 CtReq->un.rft.fcpReg = 1;
1409 /* Register NVME type if enabled. Defined LE and swapped.
1410 * rsvd[0] is used as word1 because of the hard-coded
1411 * word0 usage in the ct_request data structure.
1413 if ((phba->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
1414 (phba->cfg_enable_fc4_type == LPFC_ENABLE_NVME))
1415 CtReq->un.rft.rsvd[0] = cpu_to_be32(0x00000100);
1417 cmpl = lpfc_cmpl_ct_cmd_rft_id;
1420 case SLI_CTNS_RNN_ID:
1421 vport->ct_flags &= ~FC_CT_RNN_ID;
1422 CtReq->CommandResponse.bits.CmdRsp =
1423 cpu_to_be16(SLI_CTNS_RNN_ID);
1424 CtReq->un.rnn.PortId = cpu_to_be32(vport->fc_myDID);
1425 memcpy(CtReq->un.rnn.wwnn, &vport->fc_nodename,
1426 sizeof(struct lpfc_name));
1427 cmpl = lpfc_cmpl_ct_cmd_rnn_id;
1430 case SLI_CTNS_RSPN_ID:
1431 vport->ct_flags &= ~FC_CT_RSPN_ID;
1432 CtReq->CommandResponse.bits.CmdRsp =
1433 cpu_to_be16(SLI_CTNS_RSPN_ID);
1434 CtReq->un.rspn.PortId = cpu_to_be32(vport->fc_myDID);
1435 size = sizeof(CtReq->un.rspn.symbname);
1436 CtReq->un.rspn.len =
1437 lpfc_vport_symbolic_port_name(vport,
1438 CtReq->un.rspn.symbname, size);
1439 cmpl = lpfc_cmpl_ct_cmd_rspn_id;
1441 case SLI_CTNS_RSNN_NN:
1442 vport->ct_flags &= ~FC_CT_RSNN_NN;
1443 CtReq->CommandResponse.bits.CmdRsp =
1444 cpu_to_be16(SLI_CTNS_RSNN_NN);
1445 memcpy(CtReq->un.rsnn.wwnn, &vport->fc_nodename,
1446 sizeof(struct lpfc_name));
1447 size = sizeof(CtReq->un.rsnn.symbname);
1448 CtReq->un.rsnn.len =
1449 lpfc_vport_symbolic_node_name(vport,
1450 CtReq->un.rsnn.symbname, size);
1451 cmpl = lpfc_cmpl_ct_cmd_rsnn_nn;
1453 case SLI_CTNS_DA_ID:
1454 /* Implement DA_ID Nameserver request */
1455 CtReq->CommandResponse.bits.CmdRsp =
1456 cpu_to_be16(SLI_CTNS_DA_ID);
1457 CtReq->un.da_id.port_id = cpu_to_be32(vport->fc_myDID);
1458 cmpl = lpfc_cmpl_ct_cmd_da_id;
1460 case SLI_CTNS_RFF_ID:
1461 vport->ct_flags &= ~FC_CT_RFF_ID;
1462 CtReq->CommandResponse.bits.CmdRsp =
1463 cpu_to_be16(SLI_CTNS_RFF_ID);
1464 CtReq->un.rff.PortId = cpu_to_be32(vport->fc_myDID);
1465 CtReq->un.rff.fbits = FC4_FEATURE_INIT;
1467 /* The driver always supports FC_TYPE_FCP. However, the
1468 * caller can specify NVME (type x28) as well. But only
1469 * these that FC4 type is supported.
1471 if (((phba->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
1472 (phba->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) &&
1473 (context == FC_TYPE_NVME)) {
1474 if ((vport == phba->pport) && phba->nvmet_support) {
1475 CtReq->un.rff.fbits = (FC4_FEATURE_TARGET |
1476 FC4_FEATURE_NVME_DISC);
1477 lpfc_nvmet_update_targetport(phba);
1479 lpfc_nvme_update_localport(vport);
1481 CtReq->un.rff.type_code = context;
1483 } else if (((phba->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
1484 (phba->cfg_enable_fc4_type == LPFC_ENABLE_FCP)) &&
1485 (context == FC_TYPE_FCP))
1486 CtReq->un.rff.type_code = context;
1489 goto ns_cmd_free_bmpvirt;
1491 cmpl = lpfc_cmpl_ct_cmd_rff_id;
1494 /* The lpfc_ct_cmd/lpfc_get_req shall increment ndlp reference count
1495 * to hold ndlp reference for the corresponding callback function.
1497 if (!lpfc_ct_cmd(vport, mp, bmp, ndlp, cmpl, rsp_size, retry)) {
1498 /* On success, The cmpl function will free the buffers */
1499 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
1500 "Issue CT cmd: cmd:x%x did:x%x",
1501 cmdcode, ndlp->nlp_DID, 0);
1506 /* Decrement ndlp reference count to release ndlp reference held
1507 * for the failed command's callback function.
1511 ns_cmd_free_bmpvirt:
1512 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
1516 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1520 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
1521 "0266 Issue NameServer Req x%x err %d Data: x%x x%x\n",
1522 cmdcode, rc, vport->fc_flag, vport->fc_rscn_id_cnt);
1527 * lpfc_cmpl_ct_disc_fdmi - Handle a discovery FDMI completion
1528 * @phba: Pointer to HBA context object.
1529 * @cmdiocb: Pointer to the command IOCBQ.
1530 * @rspiocb: Pointer to the response IOCBQ.
1532 * This function to handle the completion of a driver initiated FDMI
1533 * CT command issued during discovery.
1536 lpfc_cmpl_ct_disc_fdmi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1537 struct lpfc_iocbq *rspiocb)
1539 struct lpfc_vport *vport = cmdiocb->vport;
1540 struct lpfc_dmabuf *inp = cmdiocb->context1;
1541 struct lpfc_dmabuf *outp = cmdiocb->context2;
1542 struct lpfc_sli_ct_request *CTcmd = inp->virt;
1543 struct lpfc_sli_ct_request *CTrsp = outp->virt;
1544 uint16_t fdmi_cmd = CTcmd->CommandResponse.bits.CmdRsp;
1545 uint16_t fdmi_rsp = CTrsp->CommandResponse.bits.CmdRsp;
1546 IOCB_t *irsp = &rspiocb->iocb;
1547 struct lpfc_nodelist *ndlp;
1548 uint32_t latt, cmd, err;
1550 latt = lpfc_els_chk_latt(vport);
1551 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
1552 "FDMI cmpl: status:x%x/x%x latt:%d",
1553 irsp->ulpStatus, irsp->un.ulpWord[4], latt);
1555 if (latt || irsp->ulpStatus) {
1557 /* Look for a retryable error */
1558 if (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) {
1559 switch ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK)) {
1560 case IOERR_SLI_ABORTED:
1561 case IOERR_ABORT_IN_PROGRESS:
1562 case IOERR_SEQUENCE_TIMEOUT:
1563 case IOERR_ILLEGAL_FRAME:
1564 case IOERR_NO_RESOURCES:
1565 case IOERR_ILLEGAL_COMMAND:
1567 if (cmdiocb->retry >= LPFC_FDMI_MAX_RETRY)
1570 /* Retry the same FDMI command */
1571 err = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING,
1573 if (err == IOCB_ERROR)
1581 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1582 "0229 FDMI cmd %04x failed, latt = %d "
1583 "ulpStatus: x%x, rid x%x\n",
1584 be16_to_cpu(fdmi_cmd), latt, irsp->ulpStatus,
1585 irsp->un.ulpWord[4]);
1587 lpfc_ct_free_iocb(phba, cmdiocb);
1589 ndlp = lpfc_findnode_did(vport, FDMI_DID);
1590 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
1593 /* Check for a CT LS_RJT response */
1594 cmd = be16_to_cpu(fdmi_cmd);
1595 if (fdmi_rsp == cpu_to_be16(SLI_CT_RESPONSE_FS_RJT)) {
1596 /* FDMI rsp failed */
1597 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1598 "0220 FDMI cmd failed FS_RJT Data: x%x", cmd);
1600 /* Should we fallback to FDMI-2 / FDMI-1 ? */
1603 if (vport->fdmi_hba_mask == LPFC_FDMI2_HBA_ATTR) {
1604 /* Fallback to FDMI-1 */
1605 vport->fdmi_hba_mask = LPFC_FDMI1_HBA_ATTR;
1606 vport->fdmi_port_mask = LPFC_FDMI1_PORT_ATTR;
1608 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA, 0);
1613 if (vport->fdmi_port_mask == LPFC_FDMI2_PORT_ATTR) {
1614 /* Fallback to FDMI-1 */
1615 vport->fdmi_port_mask = LPFC_FDMI1_PORT_ATTR;
1617 lpfc_fdmi_cmd(vport, ndlp, cmd, 0);
1619 if (vport->fdmi_port_mask == LPFC_FDMI2_SMART_ATTR) {
1620 vport->fdmi_port_mask = LPFC_FDMI2_PORT_ATTR;
1621 /* Retry the same command */
1622 lpfc_fdmi_cmd(vport, ndlp, cmd, 0);
1627 if (vport->fdmi_port_mask == LPFC_FDMI2_PORT_ATTR) {
1628 /* Fallback to FDMI-1 */
1629 vport->fdmi_hba_mask = LPFC_FDMI1_HBA_ATTR;
1630 vport->fdmi_port_mask = LPFC_FDMI1_PORT_ATTR;
1632 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA, 0);
1634 if (vport->fdmi_port_mask == LPFC_FDMI2_SMART_ATTR) {
1635 vport->fdmi_port_mask = LPFC_FDMI2_PORT_ATTR;
1636 /* Retry the same command */
1637 lpfc_fdmi_cmd(vport, ndlp, cmd, 0);
1644 * On success, need to cycle thru FDMI registration for discovery
1645 * DHBA -> DPRT -> RHBA -> RPA (physical port)
1646 * DPRT -> RPRT (vports)
1650 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RPA, 0);
1654 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DPRT, 0);
1658 if (vport->port_type == LPFC_PHYSICAL_PORT)
1659 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RHBA, 0);
1661 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RPRT, 0);
1669 * lpfc_fdmi_num_disc_check - Check how many mapped NPorts we are connected to
1670 * @vport: pointer to a host virtual N_Port data structure.
1672 * Called from hbeat timeout routine to check if the number of discovered
1673 * ports has changed. If so, re-register thar port Attribute.
1676 lpfc_fdmi_num_disc_check(struct lpfc_vport *vport)
1678 struct lpfc_hba *phba = vport->phba;
1679 struct lpfc_nodelist *ndlp;
1682 if (!lpfc_is_link_up(phba))
1685 /* Must be connected to a Fabric */
1686 if (!(vport->fc_flag & FC_FABRIC))
1689 if (!(vport->fdmi_port_mask & LPFC_FDMI_PORT_ATTR_num_disc))
1692 cnt = lpfc_find_map_node(vport);
1693 if (cnt == vport->fdmi_num_disc)
1696 ndlp = lpfc_findnode_did(vport, FDMI_DID);
1697 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
1700 if (vport->port_type == LPFC_PHYSICAL_PORT) {
1701 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RPA,
1702 LPFC_FDMI_PORT_ATTR_num_disc);
1704 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RPRT,
1705 LPFC_FDMI_PORT_ATTR_num_disc);
1709 /* Routines for all individual HBA attributes */
1711 lpfc_fdmi_hba_attr_wwnn(struct lpfc_vport *vport, struct lpfc_fdmi_attr_def *ad)
1713 struct lpfc_fdmi_attr_entry *ae;
1716 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
1717 memset(ae, 0, sizeof(struct lpfc_name));
1719 memcpy(&ae->un.AttrWWN, &vport->fc_sparam.nodeName,
1720 sizeof(struct lpfc_name));
1721 size = FOURBYTES + sizeof(struct lpfc_name);
1722 ad->AttrLen = cpu_to_be16(size);
1723 ad->AttrType = cpu_to_be16(RHBA_NODENAME);
1727 lpfc_fdmi_hba_attr_manufacturer(struct lpfc_vport *vport,
1728 struct lpfc_fdmi_attr_def *ad)
1730 struct lpfc_fdmi_attr_entry *ae;
1733 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
1736 strncpy(ae->un.AttrString,
1737 "Emulex Corporation",
1738 sizeof(ae->un.AttrString));
1739 len = strnlen(ae->un.AttrString,
1740 sizeof(ae->un.AttrString));
1741 len += (len & 3) ? (4 - (len & 3)) : 4;
1742 size = FOURBYTES + len;
1743 ad->AttrLen = cpu_to_be16(size);
1744 ad->AttrType = cpu_to_be16(RHBA_MANUFACTURER);
1749 lpfc_fdmi_hba_attr_sn(struct lpfc_vport *vport, struct lpfc_fdmi_attr_def *ad)
1751 struct lpfc_hba *phba = vport->phba;
1752 struct lpfc_fdmi_attr_entry *ae;
1755 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
1758 strncpy(ae->un.AttrString, phba->SerialNumber,
1759 sizeof(ae->un.AttrString));
1760 len = strnlen(ae->un.AttrString,
1761 sizeof(ae->un.AttrString));
1762 len += (len & 3) ? (4 - (len & 3)) : 4;
1763 size = FOURBYTES + len;
1764 ad->AttrLen = cpu_to_be16(size);
1765 ad->AttrType = cpu_to_be16(RHBA_SERIAL_NUMBER);
1770 lpfc_fdmi_hba_attr_model(struct lpfc_vport *vport,
1771 struct lpfc_fdmi_attr_def *ad)
1773 struct lpfc_hba *phba = vport->phba;
1774 struct lpfc_fdmi_attr_entry *ae;
1777 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
1780 strncpy(ae->un.AttrString, phba->ModelName,
1781 sizeof(ae->un.AttrString));
1782 len = strnlen(ae->un.AttrString, sizeof(ae->un.AttrString));
1783 len += (len & 3) ? (4 - (len & 3)) : 4;
1784 size = FOURBYTES + len;
1785 ad->AttrLen = cpu_to_be16(size);
1786 ad->AttrType = cpu_to_be16(RHBA_MODEL);
1791 lpfc_fdmi_hba_attr_description(struct lpfc_vport *vport,
1792 struct lpfc_fdmi_attr_def *ad)
1794 struct lpfc_hba *phba = vport->phba;
1795 struct lpfc_fdmi_attr_entry *ae;
1798 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
1801 strncpy(ae->un.AttrString, phba->ModelDesc,
1802 sizeof(ae->un.AttrString));
1803 len = strnlen(ae->un.AttrString,
1804 sizeof(ae->un.AttrString));
1805 len += (len & 3) ? (4 - (len & 3)) : 4;
1806 size = FOURBYTES + len;
1807 ad->AttrLen = cpu_to_be16(size);
1808 ad->AttrType = cpu_to_be16(RHBA_MODEL_DESCRIPTION);
1813 lpfc_fdmi_hba_attr_hdw_ver(struct lpfc_vport *vport,
1814 struct lpfc_fdmi_attr_def *ad)
1816 struct lpfc_hba *phba = vport->phba;
1817 lpfc_vpd_t *vp = &phba->vpd;
1818 struct lpfc_fdmi_attr_entry *ae;
1819 uint32_t i, j, incr, size;
1821 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
1824 /* Convert JEDEC ID to ascii for hardware version */
1825 incr = vp->rev.biuRev;
1826 for (i = 0; i < 8; i++) {
1829 ae->un.AttrString[7 - i] =
1830 (char)((uint8_t) 0x30 +
1833 ae->un.AttrString[7 - i] =
1834 (char)((uint8_t) 0x61 +
1835 (uint8_t) (j - 10));
1838 size = FOURBYTES + 8;
1839 ad->AttrLen = cpu_to_be16(size);
1840 ad->AttrType = cpu_to_be16(RHBA_HARDWARE_VERSION);
1845 lpfc_fdmi_hba_attr_drvr_ver(struct lpfc_vport *vport,
1846 struct lpfc_fdmi_attr_def *ad)
1848 struct lpfc_fdmi_attr_entry *ae;
1851 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
1854 strncpy(ae->un.AttrString, lpfc_release_version,
1855 sizeof(ae->un.AttrString));
1856 len = strnlen(ae->un.AttrString,
1857 sizeof(ae->un.AttrString));
1858 len += (len & 3) ? (4 - (len & 3)) : 4;
1859 size = FOURBYTES + len;
1860 ad->AttrLen = cpu_to_be16(size);
1861 ad->AttrType = cpu_to_be16(RHBA_DRIVER_VERSION);
1866 lpfc_fdmi_hba_attr_rom_ver(struct lpfc_vport *vport,
1867 struct lpfc_fdmi_attr_def *ad)
1869 struct lpfc_hba *phba = vport->phba;
1870 struct lpfc_fdmi_attr_entry *ae;
1873 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
1876 if (phba->sli_rev == LPFC_SLI_REV4)
1877 lpfc_decode_firmware_rev(phba, ae->un.AttrString, 1);
1879 strncpy(ae->un.AttrString, phba->OptionROMVersion,
1880 sizeof(ae->un.AttrString));
1881 len = strnlen(ae->un.AttrString,
1882 sizeof(ae->un.AttrString));
1883 len += (len & 3) ? (4 - (len & 3)) : 4;
1884 size = FOURBYTES + len;
1885 ad->AttrLen = cpu_to_be16(size);
1886 ad->AttrType = cpu_to_be16(RHBA_OPTION_ROM_VERSION);
1891 lpfc_fdmi_hba_attr_fmw_ver(struct lpfc_vport *vport,
1892 struct lpfc_fdmi_attr_def *ad)
1894 struct lpfc_hba *phba = vport->phba;
1895 struct lpfc_fdmi_attr_entry *ae;
1898 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
1901 lpfc_decode_firmware_rev(phba, ae->un.AttrString, 1);
1902 len = strnlen(ae->un.AttrString,
1903 sizeof(ae->un.AttrString));
1904 len += (len & 3) ? (4 - (len & 3)) : 4;
1905 size = FOURBYTES + len;
1906 ad->AttrLen = cpu_to_be16(size);
1907 ad->AttrType = cpu_to_be16(RHBA_FIRMWARE_VERSION);
1912 lpfc_fdmi_hba_attr_os_ver(struct lpfc_vport *vport,
1913 struct lpfc_fdmi_attr_def *ad)
1915 struct lpfc_fdmi_attr_entry *ae;
1918 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
1921 snprintf(ae->un.AttrString, sizeof(ae->un.AttrString), "%s %s %s",
1922 init_utsname()->sysname,
1923 init_utsname()->release,
1924 init_utsname()->version);
1926 len = strnlen(ae->un.AttrString, sizeof(ae->un.AttrString));
1927 len += (len & 3) ? (4 - (len & 3)) : 4;
1928 size = FOURBYTES + len;
1929 ad->AttrLen = cpu_to_be16(size);
1930 ad->AttrType = cpu_to_be16(RHBA_OS_NAME_VERSION);
1935 lpfc_fdmi_hba_attr_ct_len(struct lpfc_vport *vport,
1936 struct lpfc_fdmi_attr_def *ad)
1938 struct lpfc_fdmi_attr_entry *ae;
1941 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
1943 ae->un.AttrInt = cpu_to_be32(LPFC_MAX_CT_SIZE);
1944 size = FOURBYTES + sizeof(uint32_t);
1945 ad->AttrLen = cpu_to_be16(size);
1946 ad->AttrType = cpu_to_be16(RHBA_MAX_CT_PAYLOAD_LEN);
1951 lpfc_fdmi_hba_attr_symbolic_name(struct lpfc_vport *vport,
1952 struct lpfc_fdmi_attr_def *ad)
1954 struct lpfc_fdmi_attr_entry *ae;
1957 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
1960 len = lpfc_vport_symbolic_node_name(vport,
1961 ae->un.AttrString, 256);
1962 len += (len & 3) ? (4 - (len & 3)) : 4;
1963 size = FOURBYTES + len;
1964 ad->AttrLen = cpu_to_be16(size);
1965 ad->AttrType = cpu_to_be16(RHBA_SYM_NODENAME);
1970 lpfc_fdmi_hba_attr_vendor_info(struct lpfc_vport *vport,
1971 struct lpfc_fdmi_attr_def *ad)
1973 struct lpfc_fdmi_attr_entry *ae;
1976 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
1978 /* Nothing is defined for this currently */
1979 ae->un.AttrInt = cpu_to_be32(0);
1980 size = FOURBYTES + sizeof(uint32_t);
1981 ad->AttrLen = cpu_to_be16(size);
1982 ad->AttrType = cpu_to_be16(RHBA_VENDOR_INFO);
1987 lpfc_fdmi_hba_attr_num_ports(struct lpfc_vport *vport,
1988 struct lpfc_fdmi_attr_def *ad)
1990 struct lpfc_fdmi_attr_entry *ae;
1993 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
1995 /* Each driver instance corresponds to a single port */
1996 ae->un.AttrInt = cpu_to_be32(1);
1997 size = FOURBYTES + sizeof(uint32_t);
1998 ad->AttrLen = cpu_to_be16(size);
1999 ad->AttrType = cpu_to_be16(RHBA_NUM_PORTS);
2004 lpfc_fdmi_hba_attr_fabric_wwnn(struct lpfc_vport *vport,
2005 struct lpfc_fdmi_attr_def *ad)
2007 struct lpfc_fdmi_attr_entry *ae;
2010 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2011 memset(ae, 0, sizeof(struct lpfc_name));
2013 memcpy(&ae->un.AttrWWN, &vport->fabric_nodename,
2014 sizeof(struct lpfc_name));
2015 size = FOURBYTES + sizeof(struct lpfc_name);
2016 ad->AttrLen = cpu_to_be16(size);
2017 ad->AttrType = cpu_to_be16(RHBA_FABRIC_WWNN);
2022 lpfc_fdmi_hba_attr_bios_ver(struct lpfc_vport *vport,
2023 struct lpfc_fdmi_attr_def *ad)
2025 struct lpfc_hba *phba = vport->phba;
2026 struct lpfc_fdmi_attr_entry *ae;
2029 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2032 lpfc_decode_firmware_rev(phba, ae->un.AttrString, 1);
2033 len = strnlen(ae->un.AttrString,
2034 sizeof(ae->un.AttrString));
2035 len += (len & 3) ? (4 - (len & 3)) : 4;
2036 size = FOURBYTES + len;
2037 ad->AttrLen = cpu_to_be16(size);
2038 ad->AttrType = cpu_to_be16(RHBA_BIOS_VERSION);
2043 lpfc_fdmi_hba_attr_bios_state(struct lpfc_vport *vport,
2044 struct lpfc_fdmi_attr_def *ad)
2046 struct lpfc_fdmi_attr_entry *ae;
2049 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2051 /* Driver doesn't have access to this information */
2052 ae->un.AttrInt = cpu_to_be32(0);
2053 size = FOURBYTES + sizeof(uint32_t);
2054 ad->AttrLen = cpu_to_be16(size);
2055 ad->AttrType = cpu_to_be16(RHBA_BIOS_STATE);
2060 lpfc_fdmi_hba_attr_vendor_id(struct lpfc_vport *vport,
2061 struct lpfc_fdmi_attr_def *ad)
2063 struct lpfc_fdmi_attr_entry *ae;
2066 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2069 strncpy(ae->un.AttrString, "EMULEX",
2070 sizeof(ae->un.AttrString));
2071 len = strnlen(ae->un.AttrString,
2072 sizeof(ae->un.AttrString));
2073 len += (len & 3) ? (4 - (len & 3)) : 4;
2074 size = FOURBYTES + len;
2075 ad->AttrLen = cpu_to_be16(size);
2076 ad->AttrType = cpu_to_be16(RHBA_VENDOR_ID);
2080 /* Routines for all individual PORT attributes */
2082 lpfc_fdmi_port_attr_fc4type(struct lpfc_vport *vport,
2083 struct lpfc_fdmi_attr_def *ad)
2085 struct lpfc_fdmi_attr_entry *ae;
2088 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2091 ae->un.AttrTypes[3] = 0x02; /* Type 1 - ELS */
2092 ae->un.AttrTypes[2] = 0x01; /* Type 8 - FCP */
2093 ae->un.AttrTypes[6] = 0x01; /* Type 40 - NVME */
2094 ae->un.AttrTypes[7] = 0x01; /* Type 32 - CT */
2095 size = FOURBYTES + 32;
2096 ad->AttrLen = cpu_to_be16(size);
2097 ad->AttrType = cpu_to_be16(RPRT_SUPPORTED_FC4_TYPES);
2102 lpfc_fdmi_port_attr_support_speed(struct lpfc_vport *vport,
2103 struct lpfc_fdmi_attr_def *ad)
2105 struct lpfc_hba *phba = vport->phba;
2106 struct lpfc_fdmi_attr_entry *ae;
2109 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2112 if (!(phba->hba_flag & HBA_FCOE_MODE)) {
2113 if (phba->lmt & LMT_32Gb)
2114 ae->un.AttrInt |= HBA_PORTSPEED_32GFC;
2115 if (phba->lmt & LMT_16Gb)
2116 ae->un.AttrInt |= HBA_PORTSPEED_16GFC;
2117 if (phba->lmt & LMT_10Gb)
2118 ae->un.AttrInt |= HBA_PORTSPEED_10GFC;
2119 if (phba->lmt & LMT_8Gb)
2120 ae->un.AttrInt |= HBA_PORTSPEED_8GFC;
2121 if (phba->lmt & LMT_4Gb)
2122 ae->un.AttrInt |= HBA_PORTSPEED_4GFC;
2123 if (phba->lmt & LMT_2Gb)
2124 ae->un.AttrInt |= HBA_PORTSPEED_2GFC;
2125 if (phba->lmt & LMT_1Gb)
2126 ae->un.AttrInt |= HBA_PORTSPEED_1GFC;
2128 /* FCoE links support only one speed */
2129 switch (phba->fc_linkspeed) {
2130 case LPFC_ASYNC_LINK_SPEED_10GBPS:
2131 ae->un.AttrInt = HBA_PORTSPEED_10GE;
2133 case LPFC_ASYNC_LINK_SPEED_25GBPS:
2134 ae->un.AttrInt = HBA_PORTSPEED_25GE;
2136 case LPFC_ASYNC_LINK_SPEED_40GBPS:
2137 ae->un.AttrInt = HBA_PORTSPEED_40GE;
2139 case LPFC_ASYNC_LINK_SPEED_100GBPS:
2140 ae->un.AttrInt = HBA_PORTSPEED_100GE;
2144 ae->un.AttrInt = cpu_to_be32(ae->un.AttrInt);
2145 size = FOURBYTES + sizeof(uint32_t);
2146 ad->AttrLen = cpu_to_be16(size);
2147 ad->AttrType = cpu_to_be16(RPRT_SUPPORTED_SPEED);
2152 lpfc_fdmi_port_attr_speed(struct lpfc_vport *vport,
2153 struct lpfc_fdmi_attr_def *ad)
2155 struct lpfc_hba *phba = vport->phba;
2156 struct lpfc_fdmi_attr_entry *ae;
2159 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2161 if (!(phba->hba_flag & HBA_FCOE_MODE)) {
2162 switch (phba->fc_linkspeed) {
2163 case LPFC_LINK_SPEED_1GHZ:
2164 ae->un.AttrInt = HBA_PORTSPEED_1GFC;
2166 case LPFC_LINK_SPEED_2GHZ:
2167 ae->un.AttrInt = HBA_PORTSPEED_2GFC;
2169 case LPFC_LINK_SPEED_4GHZ:
2170 ae->un.AttrInt = HBA_PORTSPEED_4GFC;
2172 case LPFC_LINK_SPEED_8GHZ:
2173 ae->un.AttrInt = HBA_PORTSPEED_8GFC;
2175 case LPFC_LINK_SPEED_10GHZ:
2176 ae->un.AttrInt = HBA_PORTSPEED_10GFC;
2178 case LPFC_LINK_SPEED_16GHZ:
2179 ae->un.AttrInt = HBA_PORTSPEED_16GFC;
2181 case LPFC_LINK_SPEED_32GHZ:
2182 ae->un.AttrInt = HBA_PORTSPEED_32GFC;
2185 ae->un.AttrInt = HBA_PORTSPEED_UNKNOWN;
2189 switch (phba->fc_linkspeed) {
2190 case LPFC_ASYNC_LINK_SPEED_10GBPS:
2191 ae->un.AttrInt = HBA_PORTSPEED_10GE;
2193 case LPFC_ASYNC_LINK_SPEED_25GBPS:
2194 ae->un.AttrInt = HBA_PORTSPEED_25GE;
2196 case LPFC_ASYNC_LINK_SPEED_40GBPS:
2197 ae->un.AttrInt = HBA_PORTSPEED_40GE;
2199 case LPFC_ASYNC_LINK_SPEED_100GBPS:
2200 ae->un.AttrInt = HBA_PORTSPEED_100GE;
2203 ae->un.AttrInt = HBA_PORTSPEED_UNKNOWN;
2208 ae->un.AttrInt = cpu_to_be32(ae->un.AttrInt);
2209 size = FOURBYTES + sizeof(uint32_t);
2210 ad->AttrLen = cpu_to_be16(size);
2211 ad->AttrType = cpu_to_be16(RPRT_PORT_SPEED);
2216 lpfc_fdmi_port_attr_max_frame(struct lpfc_vport *vport,
2217 struct lpfc_fdmi_attr_def *ad)
2219 struct serv_parm *hsp;
2220 struct lpfc_fdmi_attr_entry *ae;
2223 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2225 hsp = (struct serv_parm *)&vport->fc_sparam;
2226 ae->un.AttrInt = (((uint32_t) hsp->cmn.bbRcvSizeMsb) << 8) |
2227 (uint32_t) hsp->cmn.bbRcvSizeLsb;
2228 ae->un.AttrInt = cpu_to_be32(ae->un.AttrInt);
2229 size = FOURBYTES + sizeof(uint32_t);
2230 ad->AttrLen = cpu_to_be16(size);
2231 ad->AttrType = cpu_to_be16(RPRT_MAX_FRAME_SIZE);
2236 lpfc_fdmi_port_attr_os_devname(struct lpfc_vport *vport,
2237 struct lpfc_fdmi_attr_def *ad)
2239 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2240 struct lpfc_fdmi_attr_entry *ae;
2243 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2246 snprintf(ae->un.AttrString, sizeof(ae->un.AttrString),
2247 "/sys/class/scsi_host/host%d", shost->host_no);
2248 len = strnlen((char *)ae->un.AttrString,
2249 sizeof(ae->un.AttrString));
2250 len += (len & 3) ? (4 - (len & 3)) : 4;
2251 size = FOURBYTES + len;
2252 ad->AttrLen = cpu_to_be16(size);
2253 ad->AttrType = cpu_to_be16(RPRT_OS_DEVICE_NAME);
2258 lpfc_fdmi_port_attr_host_name(struct lpfc_vport *vport,
2259 struct lpfc_fdmi_attr_def *ad)
2261 struct lpfc_fdmi_attr_entry *ae;
2264 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2267 snprintf(ae->un.AttrString, sizeof(ae->un.AttrString), "%s",
2268 init_utsname()->nodename);
2270 len = strnlen(ae->un.AttrString, sizeof(ae->un.AttrString));
2271 len += (len & 3) ? (4 - (len & 3)) : 4;
2272 size = FOURBYTES + len;
2273 ad->AttrLen = cpu_to_be16(size);
2274 ad->AttrType = cpu_to_be16(RPRT_HOST_NAME);
2279 lpfc_fdmi_port_attr_wwnn(struct lpfc_vport *vport,
2280 struct lpfc_fdmi_attr_def *ad)
2282 struct lpfc_fdmi_attr_entry *ae;
2285 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2286 memset(ae, 0, sizeof(struct lpfc_name));
2288 memcpy(&ae->un.AttrWWN, &vport->fc_sparam.nodeName,
2289 sizeof(struct lpfc_name));
2290 size = FOURBYTES + sizeof(struct lpfc_name);
2291 ad->AttrLen = cpu_to_be16(size);
2292 ad->AttrType = cpu_to_be16(RPRT_NODENAME);
2297 lpfc_fdmi_port_attr_wwpn(struct lpfc_vport *vport,
2298 struct lpfc_fdmi_attr_def *ad)
2300 struct lpfc_fdmi_attr_entry *ae;
2303 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2304 memset(ae, 0, sizeof(struct lpfc_name));
2306 memcpy(&ae->un.AttrWWN, &vport->fc_sparam.portName,
2307 sizeof(struct lpfc_name));
2308 size = FOURBYTES + sizeof(struct lpfc_name);
2309 ad->AttrLen = cpu_to_be16(size);
2310 ad->AttrType = cpu_to_be16(RPRT_PORTNAME);
2315 lpfc_fdmi_port_attr_symbolic_name(struct lpfc_vport *vport,
2316 struct lpfc_fdmi_attr_def *ad)
2318 struct lpfc_fdmi_attr_entry *ae;
2321 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2324 len = lpfc_vport_symbolic_port_name(vport, 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(RPRT_SYM_PORTNAME);
2333 lpfc_fdmi_port_attr_port_type(struct lpfc_vport *vport,
2334 struct lpfc_fdmi_attr_def *ad)
2336 struct lpfc_hba *phba = vport->phba;
2337 struct lpfc_fdmi_attr_entry *ae;
2340 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2341 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP)
2342 ae->un.AttrInt = cpu_to_be32(LPFC_FDMI_PORTTYPE_NLPORT);
2344 ae->un.AttrInt = cpu_to_be32(LPFC_FDMI_PORTTYPE_NPORT);
2345 size = FOURBYTES + sizeof(uint32_t);
2346 ad->AttrLen = cpu_to_be16(size);
2347 ad->AttrType = cpu_to_be16(RPRT_PORT_TYPE);
2352 lpfc_fdmi_port_attr_class(struct lpfc_vport *vport,
2353 struct lpfc_fdmi_attr_def *ad)
2355 struct lpfc_fdmi_attr_entry *ae;
2358 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2359 ae->un.AttrInt = cpu_to_be32(FC_COS_CLASS2 | FC_COS_CLASS3);
2360 size = FOURBYTES + sizeof(uint32_t);
2361 ad->AttrLen = cpu_to_be16(size);
2362 ad->AttrType = cpu_to_be16(RPRT_SUPPORTED_CLASS);
2367 lpfc_fdmi_port_attr_fabric_wwpn(struct lpfc_vport *vport,
2368 struct lpfc_fdmi_attr_def *ad)
2370 struct lpfc_fdmi_attr_entry *ae;
2373 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2374 memset(ae, 0, sizeof(struct lpfc_name));
2376 memcpy(&ae->un.AttrWWN, &vport->fabric_portname,
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(RPRT_FABRICNAME);
2385 lpfc_fdmi_port_attr_active_fc4type(struct lpfc_vport *vport,
2386 struct lpfc_fdmi_attr_def *ad)
2388 struct lpfc_fdmi_attr_entry *ae;
2391 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2394 ae->un.AttrTypes[3] = 0x02; /* Type 1 - ELS */
2395 ae->un.AttrTypes[2] = 0x01; /* Type 8 - FCP */
2396 ae->un.AttrTypes[7] = 0x01; /* Type 32 - CT */
2397 size = FOURBYTES + 32;
2398 ad->AttrLen = cpu_to_be16(size);
2399 ad->AttrType = cpu_to_be16(RPRT_ACTIVE_FC4_TYPES);
2404 lpfc_fdmi_port_attr_port_state(struct lpfc_vport *vport,
2405 struct lpfc_fdmi_attr_def *ad)
2407 struct lpfc_fdmi_attr_entry *ae;
2410 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2411 /* Link Up - operational */
2412 ae->un.AttrInt = cpu_to_be32(LPFC_FDMI_PORTSTATE_ONLINE);
2413 size = FOURBYTES + sizeof(uint32_t);
2414 ad->AttrLen = cpu_to_be16(size);
2415 ad->AttrType = cpu_to_be16(RPRT_PORT_STATE);
2420 lpfc_fdmi_port_attr_num_disc(struct lpfc_vport *vport,
2421 struct lpfc_fdmi_attr_def *ad)
2423 struct lpfc_fdmi_attr_entry *ae;
2426 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2427 vport->fdmi_num_disc = lpfc_find_map_node(vport);
2428 ae->un.AttrInt = cpu_to_be32(vport->fdmi_num_disc);
2429 size = FOURBYTES + sizeof(uint32_t);
2430 ad->AttrLen = cpu_to_be16(size);
2431 ad->AttrType = cpu_to_be16(RPRT_DISC_PORT);
2436 lpfc_fdmi_port_attr_nportid(struct lpfc_vport *vport,
2437 struct lpfc_fdmi_attr_def *ad)
2439 struct lpfc_fdmi_attr_entry *ae;
2442 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2443 ae->un.AttrInt = cpu_to_be32(vport->fc_myDID);
2444 size = FOURBYTES + sizeof(uint32_t);
2445 ad->AttrLen = cpu_to_be16(size);
2446 ad->AttrType = cpu_to_be16(RPRT_PORT_ID);
2451 lpfc_fdmi_smart_attr_service(struct lpfc_vport *vport,
2452 struct lpfc_fdmi_attr_def *ad)
2454 struct lpfc_fdmi_attr_entry *ae;
2457 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2460 strncpy(ae->un.AttrString, "Smart SAN Initiator",
2461 sizeof(ae->un.AttrString));
2462 len = strnlen(ae->un.AttrString,
2463 sizeof(ae->un.AttrString));
2464 len += (len & 3) ? (4 - (len & 3)) : 4;
2465 size = FOURBYTES + len;
2466 ad->AttrLen = cpu_to_be16(size);
2467 ad->AttrType = cpu_to_be16(RPRT_SMART_SERVICE);
2472 lpfc_fdmi_smart_attr_guid(struct lpfc_vport *vport,
2473 struct lpfc_fdmi_attr_def *ad)
2475 struct lpfc_fdmi_attr_entry *ae;
2478 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2481 memcpy(&ae->un.AttrString, &vport->fc_sparam.nodeName,
2482 sizeof(struct lpfc_name));
2483 memcpy((((uint8_t *)&ae->un.AttrString) +
2484 sizeof(struct lpfc_name)),
2485 &vport->fc_sparam.portName, sizeof(struct lpfc_name));
2486 size = FOURBYTES + (2 * sizeof(struct lpfc_name));
2487 ad->AttrLen = cpu_to_be16(size);
2488 ad->AttrType = cpu_to_be16(RPRT_SMART_GUID);
2493 lpfc_fdmi_smart_attr_version(struct lpfc_vport *vport,
2494 struct lpfc_fdmi_attr_def *ad)
2496 struct lpfc_fdmi_attr_entry *ae;
2499 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2502 strncpy(ae->un.AttrString, "Smart SAN Version 2.0",
2503 sizeof(ae->un.AttrString));
2504 len = strnlen(ae->un.AttrString,
2505 sizeof(ae->un.AttrString));
2506 len += (len & 3) ? (4 - (len & 3)) : 4;
2507 size = FOURBYTES + len;
2508 ad->AttrLen = cpu_to_be16(size);
2509 ad->AttrType = cpu_to_be16(RPRT_SMART_VERSION);
2514 lpfc_fdmi_smart_attr_model(struct lpfc_vport *vport,
2515 struct lpfc_fdmi_attr_def *ad)
2517 struct lpfc_hba *phba = vport->phba;
2518 struct lpfc_fdmi_attr_entry *ae;
2521 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2524 strncpy(ae->un.AttrString, phba->ModelName,
2525 sizeof(ae->un.AttrString));
2526 len = strnlen(ae->un.AttrString, sizeof(ae->un.AttrString));
2527 len += (len & 3) ? (4 - (len & 3)) : 4;
2528 size = FOURBYTES + len;
2529 ad->AttrLen = cpu_to_be16(size);
2530 ad->AttrType = cpu_to_be16(RPRT_SMART_MODEL);
2535 lpfc_fdmi_smart_attr_port_info(struct lpfc_vport *vport,
2536 struct lpfc_fdmi_attr_def *ad)
2538 struct lpfc_fdmi_attr_entry *ae;
2541 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2543 /* SRIOV (type 3) is not supported */
2545 ae->un.AttrInt = cpu_to_be32(2); /* NPIV */
2547 ae->un.AttrInt = cpu_to_be32(1); /* Physical */
2548 size = FOURBYTES + sizeof(uint32_t);
2549 ad->AttrLen = cpu_to_be16(size);
2550 ad->AttrType = cpu_to_be16(RPRT_SMART_PORT_INFO);
2555 lpfc_fdmi_smart_attr_qos(struct lpfc_vport *vport,
2556 struct lpfc_fdmi_attr_def *ad)
2558 struct lpfc_fdmi_attr_entry *ae;
2561 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2562 ae->un.AttrInt = cpu_to_be32(0);
2563 size = FOURBYTES + sizeof(uint32_t);
2564 ad->AttrLen = cpu_to_be16(size);
2565 ad->AttrType = cpu_to_be16(RPRT_SMART_QOS);
2570 lpfc_fdmi_smart_attr_security(struct lpfc_vport *vport,
2571 struct lpfc_fdmi_attr_def *ad)
2573 struct lpfc_fdmi_attr_entry *ae;
2576 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2577 ae->un.AttrInt = cpu_to_be32(1);
2578 size = FOURBYTES + sizeof(uint32_t);
2579 ad->AttrLen = cpu_to_be16(size);
2580 ad->AttrType = cpu_to_be16(RPRT_SMART_SECURITY);
2584 /* RHBA attribute jump table */
2585 int (*lpfc_fdmi_hba_action[])
2586 (struct lpfc_vport *vport, struct lpfc_fdmi_attr_def *ad) = {
2587 /* Action routine Mask bit Attribute type */
2588 lpfc_fdmi_hba_attr_wwnn, /* bit0 RHBA_NODENAME */
2589 lpfc_fdmi_hba_attr_manufacturer, /* bit1 RHBA_MANUFACTURER */
2590 lpfc_fdmi_hba_attr_sn, /* bit2 RHBA_SERIAL_NUMBER */
2591 lpfc_fdmi_hba_attr_model, /* bit3 RHBA_MODEL */
2592 lpfc_fdmi_hba_attr_description, /* bit4 RHBA_MODEL_DESCRIPTION */
2593 lpfc_fdmi_hba_attr_hdw_ver, /* bit5 RHBA_HARDWARE_VERSION */
2594 lpfc_fdmi_hba_attr_drvr_ver, /* bit6 RHBA_DRIVER_VERSION */
2595 lpfc_fdmi_hba_attr_rom_ver, /* bit7 RHBA_OPTION_ROM_VERSION */
2596 lpfc_fdmi_hba_attr_fmw_ver, /* bit8 RHBA_FIRMWARE_VERSION */
2597 lpfc_fdmi_hba_attr_os_ver, /* bit9 RHBA_OS_NAME_VERSION */
2598 lpfc_fdmi_hba_attr_ct_len, /* bit10 RHBA_MAX_CT_PAYLOAD_LEN */
2599 lpfc_fdmi_hba_attr_symbolic_name, /* bit11 RHBA_SYM_NODENAME */
2600 lpfc_fdmi_hba_attr_vendor_info, /* bit12 RHBA_VENDOR_INFO */
2601 lpfc_fdmi_hba_attr_num_ports, /* bit13 RHBA_NUM_PORTS */
2602 lpfc_fdmi_hba_attr_fabric_wwnn, /* bit14 RHBA_FABRIC_WWNN */
2603 lpfc_fdmi_hba_attr_bios_ver, /* bit15 RHBA_BIOS_VERSION */
2604 lpfc_fdmi_hba_attr_bios_state, /* bit16 RHBA_BIOS_STATE */
2605 lpfc_fdmi_hba_attr_vendor_id, /* bit17 RHBA_VENDOR_ID */
2608 /* RPA / RPRT attribute jump table */
2609 int (*lpfc_fdmi_port_action[])
2610 (struct lpfc_vport *vport, struct lpfc_fdmi_attr_def *ad) = {
2611 /* Action routine Mask bit Attribute type */
2612 lpfc_fdmi_port_attr_fc4type, /* bit0 RPRT_SUPPORT_FC4_TYPES */
2613 lpfc_fdmi_port_attr_support_speed, /* bit1 RPRT_SUPPORTED_SPEED */
2614 lpfc_fdmi_port_attr_speed, /* bit2 RPRT_PORT_SPEED */
2615 lpfc_fdmi_port_attr_max_frame, /* bit3 RPRT_MAX_FRAME_SIZE */
2616 lpfc_fdmi_port_attr_os_devname, /* bit4 RPRT_OS_DEVICE_NAME */
2617 lpfc_fdmi_port_attr_host_name, /* bit5 RPRT_HOST_NAME */
2618 lpfc_fdmi_port_attr_wwnn, /* bit6 RPRT_NODENAME */
2619 lpfc_fdmi_port_attr_wwpn, /* bit7 RPRT_PORTNAME */
2620 lpfc_fdmi_port_attr_symbolic_name, /* bit8 RPRT_SYM_PORTNAME */
2621 lpfc_fdmi_port_attr_port_type, /* bit9 RPRT_PORT_TYPE */
2622 lpfc_fdmi_port_attr_class, /* bit10 RPRT_SUPPORTED_CLASS */
2623 lpfc_fdmi_port_attr_fabric_wwpn, /* bit11 RPRT_FABRICNAME */
2624 lpfc_fdmi_port_attr_active_fc4type, /* bit12 RPRT_ACTIVE_FC4_TYPES */
2625 lpfc_fdmi_port_attr_port_state, /* bit13 RPRT_PORT_STATE */
2626 lpfc_fdmi_port_attr_num_disc, /* bit14 RPRT_DISC_PORT */
2627 lpfc_fdmi_port_attr_nportid, /* bit15 RPRT_PORT_ID */
2628 lpfc_fdmi_smart_attr_service, /* bit16 RPRT_SMART_SERVICE */
2629 lpfc_fdmi_smart_attr_guid, /* bit17 RPRT_SMART_GUID */
2630 lpfc_fdmi_smart_attr_version, /* bit18 RPRT_SMART_VERSION */
2631 lpfc_fdmi_smart_attr_model, /* bit19 RPRT_SMART_MODEL */
2632 lpfc_fdmi_smart_attr_port_info, /* bit20 RPRT_SMART_PORT_INFO */
2633 lpfc_fdmi_smart_attr_qos, /* bit21 RPRT_SMART_QOS */
2634 lpfc_fdmi_smart_attr_security, /* bit22 RPRT_SMART_SECURITY */
2638 * lpfc_fdmi_cmd - Build and send a FDMI cmd to the specified NPort
2639 * @vport: pointer to a host virtual N_Port data structure.
2640 * @ndlp: ndlp to send FDMI cmd to (if NULL use FDMI_DID)
2641 * cmdcode: FDMI command to send
2642 * mask: Mask of HBA or PORT Attributes to send
2644 * Builds and sends a FDMI command using the CT subsystem.
2647 lpfc_fdmi_cmd(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2648 int cmdcode, uint32_t new_mask)
2650 struct lpfc_hba *phba = vport->phba;
2651 struct lpfc_dmabuf *mp, *bmp;
2652 struct lpfc_sli_ct_request *CtReq;
2653 struct ulp_bde64 *bpl;
2658 struct lpfc_fdmi_reg_hba *rh;
2659 struct lpfc_fdmi_port_entry *pe;
2660 struct lpfc_fdmi_reg_portattr *pab = NULL;
2661 struct lpfc_fdmi_attr_block *ab = NULL;
2662 int (*func)(struct lpfc_vport *vport, struct lpfc_fdmi_attr_def *ad);
2663 void (*cmpl)(struct lpfc_hba *, struct lpfc_iocbq *,
2664 struct lpfc_iocbq *);
2666 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
2669 cmpl = lpfc_cmpl_ct_disc_fdmi; /* called from discovery */
2671 /* fill in BDEs for command */
2672 /* Allocate buffer for command payload */
2673 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
2677 mp->virt = lpfc_mbuf_alloc(phba, 0, &(mp->phys));
2679 goto fdmi_cmd_free_mp;
2681 /* Allocate buffer for Buffer ptr list */
2682 bmp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
2684 goto fdmi_cmd_free_mpvirt;
2686 bmp->virt = lpfc_mbuf_alloc(phba, 0, &(bmp->phys));
2688 goto fdmi_cmd_free_bmp;
2690 INIT_LIST_HEAD(&mp->list);
2691 INIT_LIST_HEAD(&bmp->list);
2694 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2695 "0218 FDMI Request Data: x%x x%x x%x\n",
2696 vport->fc_flag, vport->port_state, cmdcode);
2697 CtReq = (struct lpfc_sli_ct_request *)mp->virt;
2699 /* First populate the CT_IU preamble */
2700 memset(CtReq, 0, sizeof(struct lpfc_sli_ct_request));
2701 CtReq->RevisionId.bits.Revision = SLI_CT_REVISION;
2702 CtReq->RevisionId.bits.InId = 0;
2704 CtReq->FsType = SLI_CT_MANAGEMENT_SERVICE;
2705 CtReq->FsSubType = SLI_CT_FDMI_Subtypes;
2707 CtReq->CommandResponse.bits.CmdRsp = cpu_to_be16(cmdcode);
2708 rsp_size = LPFC_BPL_SIZE;
2711 /* Next fill in the specific FDMI cmd information */
2715 rh = (struct lpfc_fdmi_reg_hba *)&CtReq->un.PortID;
2716 /* HBA Identifier */
2717 memcpy(&rh->hi.PortName, &phba->pport->fc_sparam.portName,
2718 sizeof(struct lpfc_name));
2720 if (cmdcode == SLI_MGMT_RHBA) {
2721 /* Registered Port List */
2722 /* One entry (port) per adapter */
2723 rh->rpl.EntryCnt = cpu_to_be32(1);
2724 memcpy(&rh->rpl.pe, &phba->pport->fc_sparam.portName,
2725 sizeof(struct lpfc_name));
2727 /* point to the HBA attribute block */
2728 size = 2 * sizeof(struct lpfc_name) +
2731 size = sizeof(struct lpfc_name);
2733 ab = (struct lpfc_fdmi_attr_block *)((uint8_t *)rh + size);
2740 mask = vport->fdmi_hba_mask;
2742 /* Mask will dictate what attributes to build in the request */
2745 func = lpfc_fdmi_hba_action[bit_pos];
2747 (struct lpfc_fdmi_attr_def *)
2748 ((uint8_t *)rh + size));
2751 (LPFC_BPL_SIZE - LPFC_CT_PREAMBLE))
2758 ab->EntryCnt = cpu_to_be32(ab->EntryCnt);
2760 size = GID_REQUEST_SZ - 4 + size;
2765 pab = (struct lpfc_fdmi_reg_portattr *)&CtReq->un.PortID;
2766 if (cmdcode == SLI_MGMT_RPRT) {
2767 rh = (struct lpfc_fdmi_reg_hba *)pab;
2768 /* HBA Identifier */
2769 memcpy(&rh->hi.PortName,
2770 &phba->pport->fc_sparam.portName,
2771 sizeof(struct lpfc_name));
2772 pab = (struct lpfc_fdmi_reg_portattr *)
2773 ((uint8_t *)pab + sizeof(struct lpfc_name));
2776 memcpy((uint8_t *)&pab->PortName,
2777 (uint8_t *)&vport->fc_sparam.portName,
2778 sizeof(struct lpfc_name));
2779 size += sizeof(struct lpfc_name) + FOURBYTES;
2780 pab->ab.EntryCnt = 0;
2785 mask = vport->fdmi_port_mask;
2787 /* Mask will dictate what attributes to build in the request */
2790 func = lpfc_fdmi_port_action[bit_pos];
2792 (struct lpfc_fdmi_attr_def *)
2793 ((uint8_t *)pab + size));
2796 (LPFC_BPL_SIZE - LPFC_CT_PREAMBLE))
2803 pab->ab.EntryCnt = cpu_to_be32(pab->ab.EntryCnt);
2805 if (cmdcode == SLI_MGMT_RPRT)
2806 size += sizeof(struct lpfc_name);
2807 size = GID_REQUEST_SZ - 4 + size;
2812 rsp_size = FC_MAX_NS_RSP;
2815 pe = (struct lpfc_fdmi_port_entry *)&CtReq->un.PortID;
2816 memcpy((uint8_t *)&pe->PortName,
2817 (uint8_t *)&vport->fc_sparam.portName,
2818 sizeof(struct lpfc_name));
2819 size = GID_REQUEST_SZ - 4 + sizeof(struct lpfc_name);
2824 rsp_size = FC_MAX_NS_RSP;
2827 pe = (struct lpfc_fdmi_port_entry *)&CtReq->un.PortID;
2828 memcpy((uint8_t *)&pe->PortName,
2829 (uint8_t *)&vport->fc_sparam.portName,
2830 sizeof(struct lpfc_name));
2831 size = GID_REQUEST_SZ - 4 + sizeof(struct lpfc_name);
2834 size = GID_REQUEST_SZ - 4;
2837 lpfc_printf_vlog(vport, KERN_WARNING, LOG_DISCOVERY,
2838 "0298 FDMI cmdcode x%x not supported\n",
2840 goto fdmi_cmd_free_bmpvirt;
2842 CtReq->CommandResponse.bits.Size = cpu_to_be16(rsp_size);
2844 bpl = (struct ulp_bde64 *)bmp->virt;
2845 bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys));
2846 bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys));
2847 bpl->tus.f.bdeFlags = 0;
2848 bpl->tus.f.bdeSize = size;
2851 * The lpfc_ct_cmd/lpfc_get_req shall increment ndlp reference count
2852 * to hold ndlp reference for the corresponding callback function.
2854 if (!lpfc_ct_cmd(vport, mp, bmp, ndlp, cmpl, rsp_size, 0))
2858 * Decrement ndlp reference count to release ndlp reference held
2859 * for the failed command's callback function.
2863 fdmi_cmd_free_bmpvirt:
2864 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
2867 fdmi_cmd_free_mpvirt:
2868 lpfc_mbuf_free(phba, mp->virt, mp->phys);
2872 /* Issue FDMI request failed */
2873 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2874 "0244 Issue FDMI request failed Data: x%x\n",
2880 * lpfc_delayed_disc_tmo - Timeout handler for delayed discovery timer.
2881 * @ptr - Context object of the timer.
2883 * This function set the WORKER_DELAYED_DISC_TMO flag and wake up
2884 * the worker thread.
2887 lpfc_delayed_disc_tmo(unsigned long ptr)
2889 struct lpfc_vport *vport = (struct lpfc_vport *)ptr;
2890 struct lpfc_hba *phba = vport->phba;
2891 uint32_t tmo_posted;
2892 unsigned long iflag;
2894 spin_lock_irqsave(&vport->work_port_lock, iflag);
2895 tmo_posted = vport->work_port_events & WORKER_DELAYED_DISC_TMO;
2897 vport->work_port_events |= WORKER_DELAYED_DISC_TMO;
2898 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
2901 lpfc_worker_wake_up(phba);
2906 * lpfc_delayed_disc_timeout_handler - Function called by worker thread to
2907 * handle delayed discovery.
2908 * @vport: pointer to a host virtual N_Port data structure.
2910 * This function start nport discovery of the vport.
2913 lpfc_delayed_disc_timeout_handler(struct lpfc_vport *vport)
2915 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2917 spin_lock_irq(shost->host_lock);
2918 if (!(vport->fc_flag & FC_DISC_DELAYED)) {
2919 spin_unlock_irq(shost->host_lock);
2922 vport->fc_flag &= ~FC_DISC_DELAYED;
2923 spin_unlock_irq(shost->host_lock);
2925 lpfc_do_scr_ns_plogi(vport->phba, vport);
2929 lpfc_decode_firmware_rev(struct lpfc_hba *phba, char *fwrevision, int flag)
2931 struct lpfc_sli *psli = &phba->sli;
2932 lpfc_vpd_t *vp = &phba->vpd;
2933 uint32_t b1, b2, b3, b4, i, rev;
2935 uint32_t *ptr, str[4];
2938 if (phba->sli_rev == LPFC_SLI_REV4)
2939 snprintf(fwrevision, FW_REV_STR_SIZE, "%s", vp->rev.opFwName);
2940 else if (vp->rev.rBit) {
2941 if (psli->sli_flag & LPFC_SLI_ACTIVE)
2942 rev = vp->rev.sli2FwRev;
2944 rev = vp->rev.sli1FwRev;
2946 b1 = (rev & 0x0000f000) >> 12;
2947 b2 = (rev & 0x00000f00) >> 8;
2948 b3 = (rev & 0x000000c0) >> 6;
2949 b4 = (rev & 0x00000030) >> 4;
2968 b4 = (rev & 0x0000000f);
2970 if (psli->sli_flag & LPFC_SLI_ACTIVE)
2971 fwname = vp->rev.sli2FwName;
2973 fwname = vp->rev.sli1FwName;
2975 for (i = 0; i < 16; i++)
2976 if (fwname[i] == 0x20)
2979 ptr = (uint32_t*)fwname;
2981 for (i = 0; i < 3; i++)
2982 str[i] = be32_to_cpu(*ptr++);
2986 sprintf(fwrevision, "%d.%d%d (%s)",
2987 b1, b2, b3, (char *)str);
2989 sprintf(fwrevision, "%d.%d%d", b1,
2993 sprintf(fwrevision, "%d.%d%d%c%d (%s)",
2997 sprintf(fwrevision, "%d.%d%d%c%d",
3001 rev = vp->rev.smFwRev;
3003 b1 = (rev & 0xff000000) >> 24;
3004 b2 = (rev & 0x00f00000) >> 20;
3005 b3 = (rev & 0x000f0000) >> 16;
3006 c = (rev & 0x0000ff00) >> 8;
3007 b4 = (rev & 0x000000ff);
3009 sprintf(fwrevision, "%d.%d%d%c%d", b1, b2, b3, c, b4);