1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2017-2019 Broadcom. All Rights Reserved. The term *
5 * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. *
6 * Copyright (C) 2004-2016 Emulex. All rights reserved. *
7 * EMULEX and SLI are trademarks of Emulex. *
10 * This program is free software; you can redistribute it and/or *
11 * modify it under the terms of version 2 of the GNU General *
12 * Public License as published by the Free Software Foundation. *
13 * This program is distributed in the hope that it will be useful. *
14 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
15 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
16 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
17 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
18 * TO BE LEGALLY INVALID. See the GNU General Public License for *
19 * more details, a copy of which can be found in the file COPYING *
20 * included with this package. *
21 *******************************************************************/
24 * Fibre Channel SCSI LAN Device Driver CT support: FC Generic Services FC-GS
27 #include <linux/blkdev.h>
28 #include <linux/pci.h>
29 #include <linux/interrupt.h>
30 #include <linux/slab.h>
31 #include <linux/utsname.h>
33 #include <scsi/scsi.h>
34 #include <scsi/scsi_device.h>
35 #include <scsi/scsi_host.h>
36 #include <scsi/scsi_transport_fc.h>
37 #include <scsi/fc/fc_fs.h>
42 #include "lpfc_sli4.h"
44 #include "lpfc_disc.h"
46 #include "lpfc_scsi.h"
47 #include "lpfc_nvme.h"
48 #include "lpfc_logmsg.h"
49 #include "lpfc_crtn.h"
50 #include "lpfc_version.h"
51 #include "lpfc_vport.h"
52 #include "lpfc_debugfs.h"
54 /* FDMI Port Speed definitions - FC-GS-7 */
55 #define HBA_PORTSPEED_1GFC 0x00000001 /* 1G FC */
56 #define HBA_PORTSPEED_2GFC 0x00000002 /* 2G FC */
57 #define HBA_PORTSPEED_4GFC 0x00000008 /* 4G FC */
58 #define HBA_PORTSPEED_10GFC 0x00000004 /* 10G FC */
59 #define HBA_PORTSPEED_8GFC 0x00000010 /* 8G FC */
60 #define HBA_PORTSPEED_16GFC 0x00000020 /* 16G FC */
61 #define HBA_PORTSPEED_32GFC 0x00000040 /* 32G FC */
62 #define HBA_PORTSPEED_20GFC 0x00000080 /* 20G FC */
63 #define HBA_PORTSPEED_40GFC 0x00000100 /* 40G FC */
64 #define HBA_PORTSPEED_128GFC 0x00000200 /* 128G FC */
65 #define HBA_PORTSPEED_64GFC 0x00000400 /* 64G FC */
66 #define HBA_PORTSPEED_256GFC 0x00000800 /* 256G FC */
67 #define HBA_PORTSPEED_UNKNOWN 0x00008000 /* Unknown */
68 #define HBA_PORTSPEED_10GE 0x00010000 /* 10G E */
69 #define HBA_PORTSPEED_40GE 0x00020000 /* 40G E */
70 #define HBA_PORTSPEED_100GE 0x00040000 /* 100G E */
71 #define HBA_PORTSPEED_25GE 0x00080000 /* 25G E */
72 #define HBA_PORTSPEED_50GE 0x00100000 /* 50G E */
73 #define HBA_PORTSPEED_400GE 0x00200000 /* 400G E */
78 static char *lpfc_release_version = LPFC_DRIVER_VERSION;
81 lpfc_ct_ignore_hbq_buffer(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq,
82 struct lpfc_dmabuf *mp, uint32_t size)
85 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
86 "0146 Ignoring unsolicited CT No HBQ "
88 piocbq->iocb.ulpStatus);
90 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
91 "0145 Ignoring unsolicted CT HBQ Size:%d "
93 size, piocbq->iocb.ulpStatus);
97 lpfc_ct_unsol_buffer(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq,
98 struct lpfc_dmabuf *mp, uint32_t size)
100 lpfc_ct_ignore_hbq_buffer(phba, piocbq, mp, size);
104 lpfc_ct_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
105 struct lpfc_iocbq *piocbq)
107 struct lpfc_dmabuf *mp = NULL;
108 IOCB_t *icmd = &piocbq->iocb;
110 struct lpfc_iocbq *iocbq;
113 struct list_head head;
114 struct lpfc_dmabuf *bdeBuf;
116 if (lpfc_bsg_ct_unsol_event(phba, pring, piocbq) == 0)
119 if (unlikely(icmd->ulpStatus == IOSTAT_NEED_BUFFER)) {
120 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
121 } else if ((icmd->ulpStatus == IOSTAT_LOCAL_REJECT) &&
122 ((icmd->un.ulpWord[4] & IOERR_PARAM_MASK) ==
123 IOERR_RCV_BUFFER_WAITING)) {
124 /* Not enough posted buffers; Try posting more buffers */
125 phba->fc_stat.NoRcvBuf++;
126 if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
127 lpfc_post_buffer(phba, pring, 2);
131 /* If there are no BDEs associated with this IOCB,
132 * there is nothing to do.
134 if (icmd->ulpBdeCount == 0)
137 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
138 INIT_LIST_HEAD(&head);
139 list_add_tail(&head, &piocbq->list);
140 list_for_each_entry(iocbq, &head, list) {
142 if (icmd->ulpBdeCount == 0)
144 bdeBuf = iocbq->context2;
145 iocbq->context2 = NULL;
146 size = icmd->un.cont64[0].tus.f.bdeSize;
147 lpfc_ct_unsol_buffer(phba, piocbq, bdeBuf, size);
148 lpfc_in_buf_free(phba, bdeBuf);
149 if (icmd->ulpBdeCount == 2) {
150 bdeBuf = iocbq->context3;
151 iocbq->context3 = NULL;
152 size = icmd->unsli3.rcvsli3.bde2.tus.f.bdeSize;
153 lpfc_ct_unsol_buffer(phba, piocbq, bdeBuf,
155 lpfc_in_buf_free(phba, bdeBuf);
160 INIT_LIST_HEAD(&head);
161 list_add_tail(&head, &piocbq->list);
162 list_for_each_entry(iocbq, &head, list) {
164 if (icmd->ulpBdeCount == 0)
165 lpfc_ct_unsol_buffer(phba, iocbq, NULL, 0);
166 for (i = 0; i < icmd->ulpBdeCount; i++) {
167 paddr = getPaddr(icmd->un.cont64[i].addrHigh,
168 icmd->un.cont64[i].addrLow);
169 mp = lpfc_sli_ringpostbuf_get(phba, pring,
171 size = icmd->un.cont64[i].tus.f.bdeSize;
172 lpfc_ct_unsol_buffer(phba, iocbq, mp, size);
173 lpfc_in_buf_free(phba, mp);
175 lpfc_post_buffer(phba, pring, i);
182 * lpfc_ct_handle_unsol_abort - ct upper level protocol abort handler
183 * @phba: Pointer to HBA context object.
184 * @dmabuf: pointer to a dmabuf that describes the FC sequence
186 * This function serves as the upper level protocol abort handler for CT
189 * Return 1 if abort has been handled, 0 otherwise.
192 lpfc_ct_handle_unsol_abort(struct lpfc_hba *phba, struct hbq_dmabuf *dmabuf)
196 /* CT upper level goes through BSG */
197 handled = lpfc_bsg_ct_unsol_abort(phba, dmabuf);
203 lpfc_free_ct_rsp(struct lpfc_hba *phba, struct lpfc_dmabuf *mlist)
205 struct lpfc_dmabuf *mlast, *next_mlast;
207 list_for_each_entry_safe(mlast, next_mlast, &mlist->list, list) {
208 lpfc_mbuf_free(phba, mlast->virt, mlast->phys);
209 list_del(&mlast->list);
212 lpfc_mbuf_free(phba, mlist->virt, mlist->phys);
217 static struct lpfc_dmabuf *
218 lpfc_alloc_ct_rsp(struct lpfc_hba *phba, int cmdcode, struct ulp_bde64 *bpl,
219 uint32_t size, int *entries)
221 struct lpfc_dmabuf *mlist = NULL;
222 struct lpfc_dmabuf *mp;
225 /* We get chunks of FCELSSIZE */
226 cnt = size > FCELSSIZE ? FCELSSIZE: size;
229 /* Allocate buffer for rsp payload */
230 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
233 lpfc_free_ct_rsp(phba, mlist);
237 INIT_LIST_HEAD(&mp->list);
239 if (cmdcode == be16_to_cpu(SLI_CTNS_GID_FT) ||
240 cmdcode == be16_to_cpu(SLI_CTNS_GFF_ID))
241 mp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(mp->phys));
243 mp->virt = lpfc_mbuf_alloc(phba, 0, &(mp->phys));
248 lpfc_free_ct_rsp(phba, mlist);
252 /* Queue it to a linked list */
256 list_add_tail(&mp->list, &mlist->list);
258 bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64I;
259 /* build buffer ptr list for IOCB */
260 bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys) );
261 bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys) );
262 bpl->tus.f.bdeSize = (uint16_t) cnt;
263 bpl->tus.w = le32_to_cpu(bpl->tus.w);
275 lpfc_ct_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *ctiocb)
277 struct lpfc_dmabuf *buf_ptr;
279 if (ctiocb->context_un.ndlp) {
280 lpfc_nlp_put(ctiocb->context_un.ndlp);
281 ctiocb->context_un.ndlp = NULL;
283 if (ctiocb->context1) {
284 buf_ptr = (struct lpfc_dmabuf *) ctiocb->context1;
285 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
287 ctiocb->context1 = NULL;
289 if (ctiocb->context2) {
290 lpfc_free_ct_rsp(phba, (struct lpfc_dmabuf *) ctiocb->context2);
291 ctiocb->context2 = NULL;
294 if (ctiocb->context3) {
295 buf_ptr = (struct lpfc_dmabuf *) ctiocb->context3;
296 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
298 ctiocb->context3 = NULL;
300 lpfc_sli_release_iocbq(phba, ctiocb);
305 * lpfc_gen_req - Build and issue a GEN_REQUEST command to the SLI Layer
306 * @vport: pointer to a host virtual N_Port data structure.
307 * @bmp: Pointer to BPL for SLI command
308 * @inp: Pointer to data buffer for response data.
309 * @outp: Pointer to data buffer that hold the CT command.
310 * @cmpl: completion routine to call when command completes
311 * @ndlp: Destination NPort nodelist entry
313 * This function as the final part for issuing a CT command.
316 lpfc_gen_req(struct lpfc_vport *vport, struct lpfc_dmabuf *bmp,
317 struct lpfc_dmabuf *inp, struct lpfc_dmabuf *outp,
318 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
319 struct lpfc_iocbq *),
320 struct lpfc_nodelist *ndlp, uint32_t usr_flg, uint32_t num_entry,
321 uint32_t tmo, uint8_t retry)
323 struct lpfc_hba *phba = vport->phba;
325 struct lpfc_iocbq *geniocb;
328 /* Allocate buffer for command iocb */
329 geniocb = lpfc_sli_get_iocbq(phba);
334 icmd = &geniocb->iocb;
335 icmd->un.genreq64.bdl.ulpIoTag32 = 0;
336 icmd->un.genreq64.bdl.addrHigh = putPaddrHigh(bmp->phys);
337 icmd->un.genreq64.bdl.addrLow = putPaddrLow(bmp->phys);
338 icmd->un.genreq64.bdl.bdeFlags = BUFF_TYPE_BLP_64;
339 icmd->un.genreq64.bdl.bdeSize = (num_entry * sizeof(struct ulp_bde64));
342 geniocb->context3 = NULL;
344 geniocb->context3 = (uint8_t *) bmp;
346 /* Save for completion so we can release these resources */
347 geniocb->context1 = (uint8_t *) inp;
348 geniocb->context2 = (uint8_t *) outp;
349 geniocb->context_un.ndlp = lpfc_nlp_get(ndlp);
351 /* Fill in payload, bp points to frame payload */
352 icmd->ulpCommand = CMD_GEN_REQUEST64_CR;
354 /* Fill in rest of iocb */
355 icmd->un.genreq64.w5.hcsw.Fctl = (SI | LA);
356 icmd->un.genreq64.w5.hcsw.Dfctl = 0;
357 icmd->un.genreq64.w5.hcsw.Rctl = FC_RCTL_DD_UNSOL_CTL;
358 icmd->un.genreq64.w5.hcsw.Type = FC_TYPE_CT;
361 /* FC spec states we need 3 * ratov for CT requests */
362 tmo = (3 * phba->fc_ratov);
364 icmd->ulpTimeout = tmo;
365 icmd->ulpBdeCount = 1;
367 icmd->ulpClass = CLASS3;
368 icmd->ulpContext = ndlp->nlp_rpi;
369 if (phba->sli_rev == LPFC_SLI_REV4)
370 icmd->ulpContext = phba->sli4_hba.rpi_ids[ndlp->nlp_rpi];
372 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
373 /* For GEN_REQUEST64_CR, use the RPI */
378 /* Issue GEN REQ IOCB for NPORT <did> */
379 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
380 "0119 Issue GEN REQ IOCB to NPORT x%x "
382 ndlp->nlp_DID, icmd->ulpIoTag,
384 geniocb->iocb_cmpl = cmpl;
385 geniocb->drvrTimeout = icmd->ulpTimeout + LPFC_DRVR_TIMEOUT;
386 geniocb->vport = vport;
387 geniocb->retry = retry;
388 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, geniocb, 0);
390 if (rc == IOCB_ERROR) {
391 lpfc_sli_release_iocbq(phba, geniocb);
399 * lpfc_ct_cmd - Build and issue a CT command
400 * @vport: pointer to a host virtual N_Port data structure.
401 * @inmp: Pointer to data buffer for response data.
402 * @bmp: Pointer to BPL for SLI command
403 * @ndlp: Destination NPort nodelist entry
404 * @cmpl: completion routine to call when command completes
406 * This function is called for issuing a CT command.
409 lpfc_ct_cmd(struct lpfc_vport *vport, struct lpfc_dmabuf *inmp,
410 struct lpfc_dmabuf *bmp, struct lpfc_nodelist *ndlp,
411 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
412 struct lpfc_iocbq *),
413 uint32_t rsp_size, uint8_t retry)
415 struct lpfc_hba *phba = vport->phba;
416 struct ulp_bde64 *bpl = (struct ulp_bde64 *) bmp->virt;
417 struct lpfc_dmabuf *outmp;
419 int cmdcode = ((struct lpfc_sli_ct_request *) inmp->virt)->
420 CommandResponse.bits.CmdRsp;
422 bpl++; /* Skip past ct request */
424 /* Put buffer(s) for ct rsp in bpl */
425 outmp = lpfc_alloc_ct_rsp(phba, cmdcode, bpl, rsp_size, &cnt);
429 * Form the CT IOCB. The total number of BDEs in this IOCB
430 * is the single command plus response count from
434 status = lpfc_gen_req(vport, bmp, inmp, outmp, cmpl, ndlp, 0,
437 lpfc_free_ct_rsp(phba, outmp);
444 lpfc_find_vport_by_did(struct lpfc_hba *phba, uint32_t did) {
445 struct lpfc_vport *vport_curr;
448 spin_lock_irqsave(&phba->port_list_lock, flags);
449 list_for_each_entry(vport_curr, &phba->port_list, listentry) {
450 if ((vport_curr->fc_myDID) && (vport_curr->fc_myDID == did)) {
451 spin_unlock_irqrestore(&phba->port_list_lock, flags);
455 spin_unlock_irqrestore(&phba->port_list_lock, flags);
460 lpfc_prep_node_fc4type(struct lpfc_vport *vport, uint32_t Did, uint8_t fc4_type)
462 struct lpfc_nodelist *ndlp;
464 if ((vport->port_type != LPFC_NPIV_PORT) ||
465 !(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 if (phba->cfg_ns_query == LPFC_NS_QUERY_GID_FT)
549 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
550 "6430 Process %s rsp for %08x type %x %s %s\n",
552 (fc4_type == FC_TYPE_FCP) ? "FCP" : " ",
553 (fc4_type == FC_TYPE_NVME) ? "NVME" : " ");
555 * To conserve rpi's, filter out addresses for other
556 * vports on the same physical HBAs.
558 if (Did != vport->fc_myDID &&
559 (!lpfc_find_vport_by_did(phba, Did) ||
560 vport->cfg_peer_port_login)) {
561 if (!phba->nvmet_support) {
562 /* FCPI/NVMEI path. Process Did */
563 lpfc_prep_node_fc4type(vport, Did, fc4_type);
566 /* NVMET path. NVMET only cares about NVMEI nodes. */
567 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
568 if (ndlp->nlp_type != NLP_NVME_INITIATOR ||
569 ndlp->nlp_state != NLP_STE_UNMAPPED_NODE)
571 spin_lock_irq(shost->host_lock);
572 if (ndlp->nlp_DID == Did)
573 ndlp->nlp_flag &= ~NLP_NVMET_RECOV;
575 ndlp->nlp_flag |= NLP_NVMET_RECOV;
576 spin_unlock_irq(shost->host_lock);
582 lpfc_ns_rsp(struct lpfc_vport *vport, struct lpfc_dmabuf *mp, uint8_t fc4_type,
585 struct lpfc_sli_ct_request *Response =
586 (struct lpfc_sli_ct_request *) mp->virt;
587 struct lpfc_dmabuf *mlast, *next_mp;
588 uint32_t *ctptr = (uint32_t *) & Response->un.gid.PortType;
589 uint32_t Did, CTentry;
591 struct list_head head;
592 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
593 struct lpfc_nodelist *ndlp = NULL;
595 lpfc_set_disctmo(vport);
596 vport->num_disc_nodes = 0;
597 vport->fc_ns_retry = 0;
600 list_add_tail(&head, &mp->list);
601 list_for_each_entry_safe(mp, next_mp, &head, list) {
604 Cnt = Size > FCELSSIZE ? FCELSSIZE : Size;
609 ctptr = (uint32_t *) mlast->virt;
611 Cnt -= 16; /* subtract length of CT header */
613 /* Loop through entire NameServer list of DIDs */
614 while (Cnt >= sizeof(uint32_t)) {
615 /* Get next DID from NameServer List */
617 Did = ((be32_to_cpu(CTentry)) & Mask_DID);
618 lpfc_ns_rsp_audit_did(vport, Did, fc4_type);
619 if (CTentry & (cpu_to_be32(SLI_CT_LAST_ENTRY)))
622 Cnt -= sizeof(uint32_t);
628 /* All GID_FT entries processed. If the driver is running in
629 * in target mode, put impacted nodes into recovery and drop
630 * the RPI to flush outstanding IO.
632 if (vport->phba->nvmet_support) {
633 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
634 if (!(ndlp->nlp_flag & NLP_NVMET_RECOV))
636 lpfc_disc_state_machine(vport, ndlp, NULL,
637 NLP_EVT_DEVICE_RECOVERY);
638 spin_lock_irq(shost->host_lock);
639 ndlp->nlp_flag &= ~NLP_NVMET_RECOV;
640 spin_unlock_irq(shost->host_lock);
650 lpfc_cmpl_ct_cmd_gid_ft(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
651 struct lpfc_iocbq *rspiocb)
653 struct lpfc_vport *vport = cmdiocb->vport;
654 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
656 struct lpfc_dmabuf *outp;
657 struct lpfc_dmabuf *inp;
658 struct lpfc_sli_ct_request *CTrsp;
659 struct lpfc_sli_ct_request *CTreq;
660 struct lpfc_nodelist *ndlp;
663 /* First save ndlp, before we overwrite it */
664 ndlp = cmdiocb->context_un.ndlp;
666 /* we pass cmdiocb to state machine which needs rspiocb as well */
667 cmdiocb->context_un.rsp_iocb = rspiocb;
668 inp = (struct lpfc_dmabuf *) cmdiocb->context1;
669 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
670 irsp = &rspiocb->iocb;
672 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
673 "GID_FT cmpl: status:x%x/x%x rtry:%d",
674 irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_ns_retry);
676 /* Don't bother processing response if vport is being torn down. */
677 if (vport->load_flag & FC_UNLOADING) {
678 if (vport->fc_flag & FC_RSCN_MODE)
679 lpfc_els_flush_rscn(vport);
683 if (lpfc_els_chk_latt(vport)) {
684 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
685 "0216 Link event during NS query\n");
686 if (vport->fc_flag & FC_RSCN_MODE)
687 lpfc_els_flush_rscn(vport);
688 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
691 if (lpfc_error_lost_link(irsp)) {
692 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
693 "0226 NS query failed due to link event\n");
694 if (vport->fc_flag & FC_RSCN_MODE)
695 lpfc_els_flush_rscn(vport);
699 spin_lock_irq(shost->host_lock);
700 if (vport->fc_flag & FC_RSCN_DEFERRED) {
701 vport->fc_flag &= ~FC_RSCN_DEFERRED;
702 spin_unlock_irq(shost->host_lock);
704 /* This is a GID_FT completing so the gidft_inp counter was
705 * incremented before the GID_FT was issued to the wire.
710 * Skip processing the NS response
711 * Re-issue the NS cmd
713 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
714 "0151 Process Deferred RSCN Data: x%x x%x\n",
715 vport->fc_flag, vport->fc_rscn_id_cnt);
716 lpfc_els_handle_rscn(vport);
720 spin_unlock_irq(shost->host_lock);
722 if (irsp->ulpStatus) {
723 /* Check for retry */
724 if (vport->fc_ns_retry < LPFC_MAX_NS_RETRY) {
725 if (irsp->ulpStatus != IOSTAT_LOCAL_REJECT ||
726 (irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
728 vport->fc_ns_retry++;
730 type = lpfc_get_gidft_type(vport, cmdiocb);
734 /* CT command is being retried */
736 rc = lpfc_ns_cmd(vport, SLI_CTNS_GID_FT,
737 vport->fc_ns_retry, type);
741 if (vport->fc_flag & FC_RSCN_MODE)
742 lpfc_els_flush_rscn(vport);
743 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
744 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
745 "0257 GID_FT Query error: 0x%x 0x%x\n",
746 irsp->ulpStatus, vport->fc_ns_retry);
748 /* Good status, continue checking */
749 CTreq = (struct lpfc_sli_ct_request *) inp->virt;
750 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
751 if (CTrsp->CommandResponse.bits.CmdRsp ==
752 cpu_to_be16(SLI_CT_RESPONSE_FS_ACC)) {
753 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
754 "0208 NameServer Rsp Data: x%x x%x\n",
756 CTreq->un.gid.Fc4Type);
760 CTreq->un.gid.Fc4Type,
761 (uint32_t) (irsp->un.genreq64.bdl.bdeSize));
762 } else if (CTrsp->CommandResponse.bits.CmdRsp ==
763 be16_to_cpu(SLI_CT_RESPONSE_FS_RJT)) {
764 /* NameServer Rsp Error */
765 if ((CTrsp->ReasonCode == SLI_CT_UNABLE_TO_PERFORM_REQ)
766 && (CTrsp->Explanation == SLI_CT_NO_FC4_TYPES)) {
767 lpfc_printf_vlog(vport, KERN_INFO,
769 "0269 No NameServer Entries "
770 "Data: x%x x%x x%x x%x\n",
771 CTrsp->CommandResponse.bits.CmdRsp,
772 (uint32_t) CTrsp->ReasonCode,
773 (uint32_t) CTrsp->Explanation,
776 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
777 "GID_FT no entry cmd:x%x rsn:x%x exp:x%x",
778 (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
779 (uint32_t) CTrsp->ReasonCode,
780 (uint32_t) CTrsp->Explanation);
782 lpfc_printf_vlog(vport, KERN_INFO,
784 "0240 NameServer Rsp Error "
785 "Data: x%x x%x x%x x%x\n",
786 CTrsp->CommandResponse.bits.CmdRsp,
787 (uint32_t) CTrsp->ReasonCode,
788 (uint32_t) CTrsp->Explanation,
791 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
792 "GID_FT rsp err1 cmd:x%x rsn:x%x exp:x%x",
793 (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
794 (uint32_t) CTrsp->ReasonCode,
795 (uint32_t) CTrsp->Explanation);
800 /* NameServer Rsp Error */
801 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
802 "0241 NameServer Rsp Error "
803 "Data: x%x x%x x%x x%x\n",
804 CTrsp->CommandResponse.bits.CmdRsp,
805 (uint32_t) CTrsp->ReasonCode,
806 (uint32_t) CTrsp->Explanation,
809 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
810 "GID_FT rsp err2 cmd:x%x rsn:x%x exp:x%x",
811 (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
812 (uint32_t) CTrsp->ReasonCode,
813 (uint32_t) CTrsp->Explanation);
817 /* Link up / RSCN discovery */
818 if ((vport->num_disc_nodes == 0) &&
819 (vport->gidft_inp == 0)) {
821 * The driver has cycled through all Nports in the RSCN payload.
822 * Complete the handling by cleaning up and marking the
823 * current driver state.
825 if (vport->port_state >= LPFC_DISC_AUTH) {
826 if (vport->fc_flag & FC_RSCN_MODE) {
827 lpfc_els_flush_rscn(vport);
828 spin_lock_irq(shost->host_lock);
829 vport->fc_flag |= FC_RSCN_MODE; /* RSCN still */
830 spin_unlock_irq(shost->host_lock);
833 lpfc_els_flush_rscn(vport);
836 lpfc_disc_start(vport);
839 cmdiocb->context_un.ndlp = ndlp; /* Now restore ndlp for free */
840 lpfc_ct_free_iocb(phba, cmdiocb);
845 lpfc_cmpl_ct_cmd_gid_pt(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
846 struct lpfc_iocbq *rspiocb)
848 struct lpfc_vport *vport = cmdiocb->vport;
849 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
851 struct lpfc_dmabuf *outp;
852 struct lpfc_dmabuf *inp;
853 struct lpfc_sli_ct_request *CTrsp;
854 struct lpfc_sli_ct_request *CTreq;
855 struct lpfc_nodelist *ndlp;
858 /* First save ndlp, before we overwrite it */
859 ndlp = cmdiocb->context_un.ndlp;
861 /* we pass cmdiocb to state machine which needs rspiocb as well */
862 cmdiocb->context_un.rsp_iocb = rspiocb;
863 inp = (struct lpfc_dmabuf *)cmdiocb->context1;
864 outp = (struct lpfc_dmabuf *)cmdiocb->context2;
865 irsp = &rspiocb->iocb;
867 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
868 "GID_PT cmpl: status:x%x/x%x rtry:%d",
869 irsp->ulpStatus, irsp->un.ulpWord[4],
872 /* Don't bother processing response if vport is being torn down. */
873 if (vport->load_flag & FC_UNLOADING) {
874 if (vport->fc_flag & FC_RSCN_MODE)
875 lpfc_els_flush_rscn(vport);
879 if (lpfc_els_chk_latt(vport)) {
880 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
881 "4108 Link event during NS query\n");
882 if (vport->fc_flag & FC_RSCN_MODE)
883 lpfc_els_flush_rscn(vport);
884 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
887 if (lpfc_error_lost_link(irsp)) {
888 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
889 "4101 NS query failed due to link event\n");
890 if (vport->fc_flag & FC_RSCN_MODE)
891 lpfc_els_flush_rscn(vport);
895 spin_lock_irq(shost->host_lock);
896 if (vport->fc_flag & FC_RSCN_DEFERRED) {
897 vport->fc_flag &= ~FC_RSCN_DEFERRED;
898 spin_unlock_irq(shost->host_lock);
900 /* This is a GID_PT completing so the gidft_inp counter was
901 * incremented before the GID_PT was issued to the wire.
906 * Skip processing the NS response
907 * Re-issue the NS cmd
909 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
910 "4102 Process Deferred RSCN Data: x%x x%x\n",
911 vport->fc_flag, vport->fc_rscn_id_cnt);
912 lpfc_els_handle_rscn(vport);
916 spin_unlock_irq(shost->host_lock);
918 if (irsp->ulpStatus) {
919 /* Check for retry */
920 if (vport->fc_ns_retry < LPFC_MAX_NS_RETRY) {
921 if (irsp->ulpStatus != IOSTAT_LOCAL_REJECT ||
922 (irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
924 vport->fc_ns_retry++;
926 /* CT command is being retried */
928 rc = lpfc_ns_cmd(vport, SLI_CTNS_GID_PT,
929 vport->fc_ns_retry, GID_PT_N_PORT);
933 if (vport->fc_flag & FC_RSCN_MODE)
934 lpfc_els_flush_rscn(vport);
935 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
936 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
937 "4103 GID_FT Query error: 0x%x 0x%x\n",
938 irsp->ulpStatus, vport->fc_ns_retry);
940 /* Good status, continue checking */
941 CTreq = (struct lpfc_sli_ct_request *)inp->virt;
942 CTrsp = (struct lpfc_sli_ct_request *)outp->virt;
943 if (CTrsp->CommandResponse.bits.CmdRsp ==
944 cpu_to_be16(SLI_CT_RESPONSE_FS_ACC)) {
945 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
946 "4105 NameServer Rsp Data: x%x x%x\n",
948 CTreq->un.gid.Fc4Type);
952 CTreq->un.gid.Fc4Type,
953 (uint32_t)(irsp->un.genreq64.bdl.bdeSize));
954 } else if (CTrsp->CommandResponse.bits.CmdRsp ==
955 be16_to_cpu(SLI_CT_RESPONSE_FS_RJT)) {
956 /* NameServer Rsp Error */
957 if ((CTrsp->ReasonCode == SLI_CT_UNABLE_TO_PERFORM_REQ)
958 && (CTrsp->Explanation == SLI_CT_NO_FC4_TYPES)) {
960 vport, KERN_INFO, LOG_DISCOVERY,
961 "4106 No NameServer Entries "
962 "Data: x%x x%x x%x x%x\n",
963 CTrsp->CommandResponse.bits.CmdRsp,
964 (uint32_t)CTrsp->ReasonCode,
965 (uint32_t)CTrsp->Explanation,
968 lpfc_debugfs_disc_trc(
969 vport, LPFC_DISC_TRC_CT,
970 "GID_PT no entry cmd:x%x rsn:x%x exp:x%x",
971 (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
972 (uint32_t)CTrsp->ReasonCode,
973 (uint32_t)CTrsp->Explanation);
976 vport, KERN_INFO, LOG_DISCOVERY,
977 "4107 NameServer Rsp Error "
978 "Data: x%x x%x x%x x%x\n",
979 CTrsp->CommandResponse.bits.CmdRsp,
980 (uint32_t)CTrsp->ReasonCode,
981 (uint32_t)CTrsp->Explanation,
984 lpfc_debugfs_disc_trc(
985 vport, LPFC_DISC_TRC_CT,
986 "GID_PT rsp err1 cmd:x%x rsn:x%x exp:x%x",
987 (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
988 (uint32_t)CTrsp->ReasonCode,
989 (uint32_t)CTrsp->Explanation);
992 /* NameServer Rsp Error */
993 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
994 "4109 NameServer Rsp Error "
995 "Data: x%x x%x x%x x%x\n",
996 CTrsp->CommandResponse.bits.CmdRsp,
997 (uint32_t)CTrsp->ReasonCode,
998 (uint32_t)CTrsp->Explanation,
1001 lpfc_debugfs_disc_trc(
1002 vport, LPFC_DISC_TRC_CT,
1003 "GID_PT rsp err2 cmd:x%x rsn:x%x exp:x%x",
1004 (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
1005 (uint32_t)CTrsp->ReasonCode,
1006 (uint32_t)CTrsp->Explanation);
1010 /* Link up / RSCN discovery */
1011 if ((vport->num_disc_nodes == 0) &&
1012 (vport->gidft_inp == 0)) {
1014 * The driver has cycled through all Nports in the RSCN payload.
1015 * Complete the handling by cleaning up and marking the
1016 * current driver state.
1018 if (vport->port_state >= LPFC_DISC_AUTH) {
1019 if (vport->fc_flag & FC_RSCN_MODE) {
1020 lpfc_els_flush_rscn(vport);
1021 spin_lock_irq(shost->host_lock);
1022 vport->fc_flag |= FC_RSCN_MODE; /* RSCN still */
1023 spin_unlock_irq(shost->host_lock);
1025 lpfc_els_flush_rscn(vport);
1029 lpfc_disc_start(vport);
1032 cmdiocb->context_un.ndlp = ndlp; /* Now restore ndlp for free */
1033 lpfc_ct_free_iocb(phba, cmdiocb);
1037 lpfc_cmpl_ct_cmd_gff_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1038 struct lpfc_iocbq *rspiocb)
1040 struct lpfc_vport *vport = cmdiocb->vport;
1041 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1042 IOCB_t *irsp = &rspiocb->iocb;
1043 struct lpfc_dmabuf *inp = (struct lpfc_dmabuf *) cmdiocb->context1;
1044 struct lpfc_dmabuf *outp = (struct lpfc_dmabuf *) cmdiocb->context2;
1045 struct lpfc_sli_ct_request *CTrsp;
1048 struct lpfc_nodelist *ndlp;
1050 did = ((struct lpfc_sli_ct_request *) inp->virt)->un.gff.PortId;
1051 did = be32_to_cpu(did);
1053 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
1054 "GFF_ID cmpl: status:x%x/x%x did:x%x",
1055 irsp->ulpStatus, irsp->un.ulpWord[4], did);
1057 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
1058 /* Good status, continue checking */
1059 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
1060 fbits = CTrsp->un.gff_acc.fbits[FCP_TYPE_FEATURE_OFFSET];
1062 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1063 "6431 Process GFF_ID rsp for %08x "
1064 "fbits %02x %s %s\n",
1066 (fbits & FC4_FEATURE_INIT) ? "Initiator" : " ",
1067 (fbits & FC4_FEATURE_TARGET) ? "Target" : " ");
1069 if (CTrsp->CommandResponse.bits.CmdRsp ==
1070 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC)) {
1071 if ((fbits & FC4_FEATURE_INIT) &&
1072 !(fbits & FC4_FEATURE_TARGET)) {
1073 lpfc_printf_vlog(vport, KERN_INFO,
1075 "0270 Skip x%x GFF "
1076 "NameServer Rsp Data: (init) "
1077 "x%x x%x\n", did, fbits,
1078 vport->fc_rscn_id_cnt);
1084 /* Check for retry */
1085 if (cmdiocb->retry < LPFC_MAX_NS_RETRY) {
1087 if (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) {
1088 switch ((irsp->un.ulpWord[4] &
1089 IOERR_PARAM_MASK)) {
1091 case IOERR_NO_RESOURCES:
1092 /* We don't increment the retry
1093 * count for this case.
1096 case IOERR_LINK_DOWN:
1097 case IOERR_SLI_ABORTED:
1098 case IOERR_SLI_DOWN:
1109 /* CT command is being retried */
1110 rc = lpfc_ns_cmd(vport, SLI_CTNS_GFF_ID,
1111 cmdiocb->retry, did);
1114 lpfc_ct_free_iocb(phba, cmdiocb);
1119 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
1120 "0267 NameServer GFF Rsp "
1121 "x%x Error (%d %d) Data: x%x x%x\n",
1122 did, irsp->ulpStatus, irsp->un.ulpWord[4],
1123 vport->fc_flag, vport->fc_rscn_id_cnt);
1126 /* This is a target port, unregistered port, or the GFF_ID failed */
1127 ndlp = lpfc_setup_disc_node(vport, did);
1128 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
1129 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1130 "0242 Process x%x GFF "
1131 "NameServer Rsp Data: x%x x%x x%x\n",
1132 did, ndlp->nlp_flag, vport->fc_flag,
1133 vport->fc_rscn_id_cnt);
1135 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1136 "0243 Skip x%x GFF "
1137 "NameServer Rsp Data: x%x x%x\n", did,
1138 vport->fc_flag, vport->fc_rscn_id_cnt);
1141 /* Link up / RSCN discovery */
1142 if (vport->num_disc_nodes)
1143 vport->num_disc_nodes--;
1144 if (vport->num_disc_nodes == 0) {
1146 * The driver has cycled through all Nports in the RSCN payload.
1147 * Complete the handling by cleaning up and marking the
1148 * current driver state.
1150 if (vport->port_state >= LPFC_DISC_AUTH) {
1151 if (vport->fc_flag & FC_RSCN_MODE) {
1152 lpfc_els_flush_rscn(vport);
1153 spin_lock_irq(shost->host_lock);
1154 vport->fc_flag |= FC_RSCN_MODE; /* RSCN still */
1155 spin_unlock_irq(shost->host_lock);
1158 lpfc_els_flush_rscn(vport);
1160 lpfc_disc_start(vport);
1162 lpfc_ct_free_iocb(phba, cmdiocb);
1167 lpfc_cmpl_ct_cmd_gft_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1168 struct lpfc_iocbq *rspiocb)
1170 struct lpfc_vport *vport = cmdiocb->vport;
1171 IOCB_t *irsp = &rspiocb->iocb;
1172 struct lpfc_dmabuf *inp = (struct lpfc_dmabuf *)cmdiocb->context1;
1173 struct lpfc_dmabuf *outp = (struct lpfc_dmabuf *)cmdiocb->context2;
1174 struct lpfc_sli_ct_request *CTrsp;
1176 struct lpfc_nodelist *ndlp;
1177 uint32_t fc4_data_0, fc4_data_1;
1179 did = ((struct lpfc_sli_ct_request *)inp->virt)->un.gft.PortId;
1180 did = be32_to_cpu(did);
1182 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
1183 "GFT_ID cmpl: status:x%x/x%x did:x%x",
1184 irsp->ulpStatus, irsp->un.ulpWord[4], did);
1186 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
1187 /* Good status, continue checking */
1188 CTrsp = (struct lpfc_sli_ct_request *)outp->virt;
1189 fc4_data_0 = be32_to_cpu(CTrsp->un.gft_acc.fc4_types[0]);
1190 fc4_data_1 = be32_to_cpu(CTrsp->un.gft_acc.fc4_types[1]);
1192 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1193 "6432 Process GFT_ID rsp for %08x "
1194 "Data %08x %08x %s %s\n",
1195 did, fc4_data_0, fc4_data_1,
1196 (fc4_data_0 & LPFC_FC4_TYPE_BITMASK) ?
1198 (fc4_data_1 & LPFC_FC4_TYPE_BITMASK) ?
1201 ndlp = lpfc_findnode_did(vport, did);
1203 /* The bitmask value for FCP and NVME FCP types is
1204 * the same because they are 32 bits distant from
1205 * each other in word0 and word0.
1207 if (fc4_data_0 & LPFC_FC4_TYPE_BITMASK)
1208 ndlp->nlp_fc4_type |= NLP_FC4_FCP;
1209 if (fc4_data_1 & LPFC_FC4_TYPE_BITMASK)
1210 ndlp->nlp_fc4_type |= NLP_FC4_NVME;
1211 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1212 "3064 Setting ndlp %p, DID x%06x with "
1213 "FC4 x%08x, Data: x%08x x%08x\n",
1214 ndlp, did, ndlp->nlp_fc4_type,
1215 FC_TYPE_FCP, FC_TYPE_NVME);
1216 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1218 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
1219 lpfc_issue_els_prli(vport, ndlp, 0);
1222 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
1223 "3065 GFT_ID failed x%08x\n", irsp->ulpStatus);
1225 lpfc_ct_free_iocb(phba, cmdiocb);
1229 lpfc_cmpl_ct(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1230 struct lpfc_iocbq *rspiocb)
1232 struct lpfc_vport *vport = cmdiocb->vport;
1233 struct lpfc_dmabuf *inp;
1234 struct lpfc_dmabuf *outp;
1236 struct lpfc_sli_ct_request *CTrsp;
1237 struct lpfc_nodelist *ndlp;
1242 /* First save ndlp, before we overwrite it */
1243 ndlp = cmdiocb->context_un.ndlp;
1245 /* we pass cmdiocb to state machine which needs rspiocb as well */
1246 cmdiocb->context_un.rsp_iocb = rspiocb;
1248 inp = (struct lpfc_dmabuf *) cmdiocb->context1;
1249 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
1250 irsp = &rspiocb->iocb;
1252 cmdcode = be16_to_cpu(((struct lpfc_sli_ct_request *) inp->virt)->
1253 CommandResponse.bits.CmdRsp);
1254 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
1256 latt = lpfc_els_chk_latt(vport);
1258 /* RFT request completes status <ulpStatus> CmdRsp <CmdRsp> */
1259 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1260 "0209 CT Request completes, latt %d, "
1261 "ulpStatus x%x CmdRsp x%x, Context x%x, Tag x%x\n",
1262 latt, irsp->ulpStatus,
1263 CTrsp->CommandResponse.bits.CmdRsp,
1264 cmdiocb->iocb.ulpContext, cmdiocb->iocb.ulpIoTag);
1266 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
1267 "CT cmd cmpl: status:x%x/x%x cmd:x%x",
1268 irsp->ulpStatus, irsp->un.ulpWord[4], cmdcode);
1270 if (irsp->ulpStatus) {
1271 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
1272 "0268 NS cmd x%x Error (x%x x%x)\n",
1273 cmdcode, irsp->ulpStatus, irsp->un.ulpWord[4]);
1275 if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
1276 (((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
1278 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
1279 IOERR_SLI_ABORTED)))
1282 retry = cmdiocb->retry;
1283 if (retry >= LPFC_MAX_NS_RETRY)
1287 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1288 "0250 Retrying NS cmd %x\n", cmdcode);
1289 rc = lpfc_ns_cmd(vport, cmdcode, retry, 0);
1295 cmdiocb->context_un.ndlp = ndlp; /* Now restore ndlp for free */
1296 lpfc_ct_free_iocb(phba, cmdiocb);
1301 lpfc_cmpl_ct_cmd_rft_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1302 struct lpfc_iocbq *rspiocb)
1304 IOCB_t *irsp = &rspiocb->iocb;
1305 struct lpfc_vport *vport = cmdiocb->vport;
1307 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
1308 struct lpfc_dmabuf *outp;
1309 struct lpfc_sli_ct_request *CTrsp;
1311 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
1312 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
1313 if (CTrsp->CommandResponse.bits.CmdRsp ==
1314 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
1315 vport->ct_flags |= FC_CT_RFT_ID;
1317 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
1322 lpfc_cmpl_ct_cmd_rnn_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1323 struct lpfc_iocbq *rspiocb)
1325 IOCB_t *irsp = &rspiocb->iocb;
1326 struct lpfc_vport *vport = cmdiocb->vport;
1328 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
1329 struct lpfc_dmabuf *outp;
1330 struct lpfc_sli_ct_request *CTrsp;
1332 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
1333 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
1334 if (CTrsp->CommandResponse.bits.CmdRsp ==
1335 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
1336 vport->ct_flags |= FC_CT_RNN_ID;
1338 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
1343 lpfc_cmpl_ct_cmd_rspn_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1344 struct lpfc_iocbq *rspiocb)
1346 IOCB_t *irsp = &rspiocb->iocb;
1347 struct lpfc_vport *vport = cmdiocb->vport;
1349 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
1350 struct lpfc_dmabuf *outp;
1351 struct lpfc_sli_ct_request *CTrsp;
1353 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
1354 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
1355 if (CTrsp->CommandResponse.bits.CmdRsp ==
1356 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
1357 vport->ct_flags |= FC_CT_RSPN_ID;
1359 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
1364 lpfc_cmpl_ct_cmd_rsnn_nn(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1365 struct lpfc_iocbq *rspiocb)
1367 IOCB_t *irsp = &rspiocb->iocb;
1368 struct lpfc_vport *vport = cmdiocb->vport;
1370 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
1371 struct lpfc_dmabuf *outp;
1372 struct lpfc_sli_ct_request *CTrsp;
1374 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
1375 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
1376 if (CTrsp->CommandResponse.bits.CmdRsp ==
1377 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
1378 vport->ct_flags |= FC_CT_RSNN_NN;
1380 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
1385 lpfc_cmpl_ct_cmd_da_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1386 struct lpfc_iocbq *rspiocb)
1388 struct lpfc_vport *vport = cmdiocb->vport;
1390 /* even if it fails we will act as though it succeeded. */
1391 vport->ct_flags = 0;
1392 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
1397 lpfc_cmpl_ct_cmd_rff_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1398 struct lpfc_iocbq *rspiocb)
1400 IOCB_t *irsp = &rspiocb->iocb;
1401 struct lpfc_vport *vport = cmdiocb->vport;
1403 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
1404 struct lpfc_dmabuf *outp;
1405 struct lpfc_sli_ct_request *CTrsp;
1407 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
1408 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
1409 if (CTrsp->CommandResponse.bits.CmdRsp ==
1410 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
1411 vport->ct_flags |= FC_CT_RFF_ID;
1413 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
1418 * Although the symbolic port name is thought to be an integer
1419 * as of January 18, 2016, leave it as a string until more of
1420 * the record state becomes defined.
1423 lpfc_vport_symbolic_port_name(struct lpfc_vport *vport, char *symbol,
1429 * Use the lpfc board number as the Symbolic Port
1430 * Name object. NPIV is not in play so this integer
1431 * value is sufficient and unique per FC-ID.
1433 n = snprintf(symbol, size, "%d", vport->phba->brd_no);
1439 lpfc_vport_symbolic_node_name(struct lpfc_vport *vport, char *symbol,
1442 char fwrev[FW_REV_STR_SIZE];
1445 lpfc_decode_firmware_rev(vport->phba, fwrev, 0);
1447 n = snprintf(symbol, size, "Emulex %s", vport->phba->ModelName);
1451 n += snprintf(symbol + n, size - n, " FV%s", fwrev);
1455 n += snprintf(symbol + n, size - n, " DV%s.",
1456 lpfc_release_version);
1460 n += snprintf(symbol + n, size - n, " HN:%s.",
1461 init_utsname()->nodename);
1465 /* Note :- OS name is "Linux" */
1466 n += snprintf(symbol + n, size - n, " OS:%s",
1467 init_utsname()->sysname);
1472 lpfc_find_map_node(struct lpfc_vport *vport)
1474 struct lpfc_nodelist *ndlp, *next_ndlp;
1475 struct Scsi_Host *shost;
1478 shost = lpfc_shost_from_vport(vport);
1479 spin_lock_irq(shost->host_lock);
1480 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
1481 if (ndlp->nlp_type & NLP_FABRIC)
1483 if ((ndlp->nlp_state == NLP_STE_MAPPED_NODE) ||
1484 (ndlp->nlp_state == NLP_STE_UNMAPPED_NODE))
1487 spin_unlock_irq(shost->host_lock);
1492 * This routine will return the FC4 Type associated with the CT
1496 lpfc_get_gidft_type(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb)
1498 struct lpfc_sli_ct_request *CtReq;
1499 struct lpfc_dmabuf *mp;
1502 mp = cmdiocb->context1;
1505 CtReq = (struct lpfc_sli_ct_request *)mp->virt;
1506 type = (uint32_t)CtReq->un.gid.Fc4Type;
1507 if ((type != SLI_CTPT_FCP) && (type != SLI_CTPT_NVME))
1515 * Issue Cmd to NameServer
1520 lpfc_ns_cmd(struct lpfc_vport *vport, int cmdcode,
1521 uint8_t retry, uint32_t context)
1523 struct lpfc_nodelist * ndlp;
1524 struct lpfc_hba *phba = vport->phba;
1525 struct lpfc_dmabuf *mp, *bmp;
1526 struct lpfc_sli_ct_request *CtReq;
1527 struct ulp_bde64 *bpl;
1528 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
1529 struct lpfc_iocbq *) = NULL;
1531 uint32_t rsp_size = 1024;
1535 ndlp = lpfc_findnode_did(vport, NameServer_DID);
1536 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)
1537 || ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) {
1542 /* fill in BDEs for command */
1543 /* Allocate buffer for command payload */
1544 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
1550 INIT_LIST_HEAD(&mp->list);
1551 mp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(mp->phys));
1554 goto ns_cmd_free_mp;
1557 /* Allocate buffer for Buffer ptr list */
1558 bmp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
1561 goto ns_cmd_free_mpvirt;
1564 INIT_LIST_HEAD(&bmp->list);
1565 bmp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(bmp->phys));
1568 goto ns_cmd_free_bmp;
1571 /* NameServer Req */
1572 lpfc_printf_vlog(vport, KERN_INFO ,LOG_DISCOVERY,
1573 "0236 NameServer Req Data: x%x x%x x%x x%x\n",
1574 cmdcode, vport->fc_flag, vport->fc_rscn_id_cnt,
1577 bpl = (struct ulp_bde64 *) bmp->virt;
1578 memset(bpl, 0, sizeof(struct ulp_bde64));
1579 bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys) );
1580 bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys) );
1581 bpl->tus.f.bdeFlags = 0;
1582 if (cmdcode == SLI_CTNS_GID_FT)
1583 bpl->tus.f.bdeSize = GID_REQUEST_SZ;
1584 else if (cmdcode == SLI_CTNS_GID_PT)
1585 bpl->tus.f.bdeSize = GID_REQUEST_SZ;
1586 else if (cmdcode == SLI_CTNS_GFF_ID)
1587 bpl->tus.f.bdeSize = GFF_REQUEST_SZ;
1588 else if (cmdcode == SLI_CTNS_GFT_ID)
1589 bpl->tus.f.bdeSize = GFT_REQUEST_SZ;
1590 else if (cmdcode == SLI_CTNS_RFT_ID)
1591 bpl->tus.f.bdeSize = RFT_REQUEST_SZ;
1592 else if (cmdcode == SLI_CTNS_RNN_ID)
1593 bpl->tus.f.bdeSize = RNN_REQUEST_SZ;
1594 else if (cmdcode == SLI_CTNS_RSPN_ID)
1595 bpl->tus.f.bdeSize = RSPN_REQUEST_SZ;
1596 else if (cmdcode == SLI_CTNS_RSNN_NN)
1597 bpl->tus.f.bdeSize = RSNN_REQUEST_SZ;
1598 else if (cmdcode == SLI_CTNS_DA_ID)
1599 bpl->tus.f.bdeSize = DA_ID_REQUEST_SZ;
1600 else if (cmdcode == SLI_CTNS_RFF_ID)
1601 bpl->tus.f.bdeSize = RFF_REQUEST_SZ;
1603 bpl->tus.f.bdeSize = 0;
1604 bpl->tus.w = le32_to_cpu(bpl->tus.w);
1606 CtReq = (struct lpfc_sli_ct_request *) mp->virt;
1607 memset(CtReq, 0, sizeof(struct lpfc_sli_ct_request));
1608 CtReq->RevisionId.bits.Revision = SLI_CT_REVISION;
1609 CtReq->RevisionId.bits.InId = 0;
1610 CtReq->FsType = SLI_CT_DIRECTORY_SERVICE;
1611 CtReq->FsSubType = SLI_CT_DIRECTORY_NAME_SERVER;
1612 CtReq->CommandResponse.bits.Size = 0;
1614 case SLI_CTNS_GID_FT:
1615 CtReq->CommandResponse.bits.CmdRsp =
1616 cpu_to_be16(SLI_CTNS_GID_FT);
1617 CtReq->un.gid.Fc4Type = context;
1619 if (vport->port_state < LPFC_NS_QRY)
1620 vport->port_state = LPFC_NS_QRY;
1621 lpfc_set_disctmo(vport);
1622 cmpl = lpfc_cmpl_ct_cmd_gid_ft;
1623 rsp_size = FC_MAX_NS_RSP;
1626 case SLI_CTNS_GID_PT:
1627 CtReq->CommandResponse.bits.CmdRsp =
1628 cpu_to_be16(SLI_CTNS_GID_PT);
1629 CtReq->un.gid.PortType = context;
1631 if (vport->port_state < LPFC_NS_QRY)
1632 vport->port_state = LPFC_NS_QRY;
1633 lpfc_set_disctmo(vport);
1634 cmpl = lpfc_cmpl_ct_cmd_gid_pt;
1635 rsp_size = FC_MAX_NS_RSP;
1638 case SLI_CTNS_GFF_ID:
1639 CtReq->CommandResponse.bits.CmdRsp =
1640 cpu_to_be16(SLI_CTNS_GFF_ID);
1641 CtReq->un.gff.PortId = cpu_to_be32(context);
1642 cmpl = lpfc_cmpl_ct_cmd_gff_id;
1645 case SLI_CTNS_GFT_ID:
1646 CtReq->CommandResponse.bits.CmdRsp =
1647 cpu_to_be16(SLI_CTNS_GFT_ID);
1648 CtReq->un.gft.PortId = cpu_to_be32(context);
1649 cmpl = lpfc_cmpl_ct_cmd_gft_id;
1652 case SLI_CTNS_RFT_ID:
1653 vport->ct_flags &= ~FC_CT_RFT_ID;
1654 CtReq->CommandResponse.bits.CmdRsp =
1655 cpu_to_be16(SLI_CTNS_RFT_ID);
1656 CtReq->un.rft.PortId = cpu_to_be32(vport->fc_myDID);
1658 /* Register FC4 FCP type if enabled. */
1659 if (vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH ||
1660 vport->cfg_enable_fc4_type == LPFC_ENABLE_FCP)
1661 CtReq->un.rft.fcpReg = 1;
1663 /* Register NVME type if enabled. Defined LE and swapped.
1664 * rsvd[0] is used as word1 because of the hard-coded
1665 * word0 usage in the ct_request data structure.
1667 if (vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH ||
1668 vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME)
1669 CtReq->un.rft.rsvd[0] =
1670 cpu_to_be32(LPFC_FC4_TYPE_BITMASK);
1672 ptr = (uint32_t *)CtReq;
1673 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1674 "6433 Issue RFT (%s %s): %08x %08x %08x %08x "
1675 "%08x %08x %08x %08x\n",
1676 CtReq->un.rft.fcpReg ? "FCP" : " ",
1677 CtReq->un.rft.rsvd[0] ? "NVME" : " ",
1678 *ptr, *(ptr + 1), *(ptr + 2), *(ptr + 3),
1679 *(ptr + 4), *(ptr + 5),
1680 *(ptr + 6), *(ptr + 7));
1681 cmpl = lpfc_cmpl_ct_cmd_rft_id;
1684 case SLI_CTNS_RNN_ID:
1685 vport->ct_flags &= ~FC_CT_RNN_ID;
1686 CtReq->CommandResponse.bits.CmdRsp =
1687 cpu_to_be16(SLI_CTNS_RNN_ID);
1688 CtReq->un.rnn.PortId = cpu_to_be32(vport->fc_myDID);
1689 memcpy(CtReq->un.rnn.wwnn, &vport->fc_nodename,
1690 sizeof(struct lpfc_name));
1691 cmpl = lpfc_cmpl_ct_cmd_rnn_id;
1694 case SLI_CTNS_RSPN_ID:
1695 vport->ct_flags &= ~FC_CT_RSPN_ID;
1696 CtReq->CommandResponse.bits.CmdRsp =
1697 cpu_to_be16(SLI_CTNS_RSPN_ID);
1698 CtReq->un.rspn.PortId = cpu_to_be32(vport->fc_myDID);
1699 size = sizeof(CtReq->un.rspn.symbname);
1700 CtReq->un.rspn.len =
1701 lpfc_vport_symbolic_port_name(vport,
1702 CtReq->un.rspn.symbname, size);
1703 cmpl = lpfc_cmpl_ct_cmd_rspn_id;
1705 case SLI_CTNS_RSNN_NN:
1706 vport->ct_flags &= ~FC_CT_RSNN_NN;
1707 CtReq->CommandResponse.bits.CmdRsp =
1708 cpu_to_be16(SLI_CTNS_RSNN_NN);
1709 memcpy(CtReq->un.rsnn.wwnn, &vport->fc_nodename,
1710 sizeof(struct lpfc_name));
1711 size = sizeof(CtReq->un.rsnn.symbname);
1712 CtReq->un.rsnn.len =
1713 lpfc_vport_symbolic_node_name(vport,
1714 CtReq->un.rsnn.symbname, size);
1715 cmpl = lpfc_cmpl_ct_cmd_rsnn_nn;
1717 case SLI_CTNS_DA_ID:
1718 /* Implement DA_ID Nameserver request */
1719 CtReq->CommandResponse.bits.CmdRsp =
1720 cpu_to_be16(SLI_CTNS_DA_ID);
1721 CtReq->un.da_id.port_id = cpu_to_be32(vport->fc_myDID);
1722 cmpl = lpfc_cmpl_ct_cmd_da_id;
1724 case SLI_CTNS_RFF_ID:
1725 vport->ct_flags &= ~FC_CT_RFF_ID;
1726 CtReq->CommandResponse.bits.CmdRsp =
1727 cpu_to_be16(SLI_CTNS_RFF_ID);
1728 CtReq->un.rff.PortId = cpu_to_be32(vport->fc_myDID);
1729 CtReq->un.rff.fbits = FC4_FEATURE_INIT;
1731 /* The driver always supports FC_TYPE_FCP. However, the
1732 * caller can specify NVME (type x28) as well. But only
1733 * these that FC4 type is supported.
1735 if (((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
1736 (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) &&
1737 (context == FC_TYPE_NVME)) {
1738 if ((vport == phba->pport) && phba->nvmet_support) {
1739 CtReq->un.rff.fbits = (FC4_FEATURE_TARGET |
1740 FC4_FEATURE_NVME_DISC);
1741 lpfc_nvmet_update_targetport(phba);
1743 lpfc_nvme_update_localport(vport);
1745 CtReq->un.rff.type_code = context;
1747 } else if (((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
1748 (vport->cfg_enable_fc4_type == LPFC_ENABLE_FCP)) &&
1749 (context == FC_TYPE_FCP))
1750 CtReq->un.rff.type_code = context;
1753 goto ns_cmd_free_bmpvirt;
1755 ptr = (uint32_t *)CtReq;
1756 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1757 "6434 Issue RFF (%s): %08x %08x %08x %08x "
1758 "%08x %08x %08x %08x\n",
1759 (context == FC_TYPE_NVME) ? "NVME" : "FCP",
1760 *ptr, *(ptr + 1), *(ptr + 2), *(ptr + 3),
1761 *(ptr + 4), *(ptr + 5),
1762 *(ptr + 6), *(ptr + 7));
1763 cmpl = lpfc_cmpl_ct_cmd_rff_id;
1766 /* The lpfc_ct_cmd/lpfc_get_req shall increment ndlp reference count
1767 * to hold ndlp reference for the corresponding callback function.
1769 if (!lpfc_ct_cmd(vport, mp, bmp, ndlp, cmpl, rsp_size, retry)) {
1770 /* On success, The cmpl function will free the buffers */
1771 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
1772 "Issue CT cmd: cmd:x%x did:x%x",
1773 cmdcode, ndlp->nlp_DID, 0);
1778 /* Decrement ndlp reference count to release ndlp reference held
1779 * for the failed command's callback function.
1783 ns_cmd_free_bmpvirt:
1784 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
1788 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1792 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
1793 "0266 Issue NameServer Req x%x err %d Data: x%x x%x\n",
1794 cmdcode, rc, vport->fc_flag, vport->fc_rscn_id_cnt);
1799 * lpfc_cmpl_ct_disc_fdmi - Handle a discovery FDMI completion
1800 * @phba: Pointer to HBA context object.
1801 * @cmdiocb: Pointer to the command IOCBQ.
1802 * @rspiocb: Pointer to the response IOCBQ.
1804 * This function to handle the completion of a driver initiated FDMI
1805 * CT command issued during discovery.
1808 lpfc_cmpl_ct_disc_fdmi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1809 struct lpfc_iocbq *rspiocb)
1811 struct lpfc_vport *vport = cmdiocb->vport;
1812 struct lpfc_dmabuf *inp = cmdiocb->context1;
1813 struct lpfc_dmabuf *outp = cmdiocb->context2;
1814 struct lpfc_sli_ct_request *CTcmd = inp->virt;
1815 struct lpfc_sli_ct_request *CTrsp = outp->virt;
1816 uint16_t fdmi_cmd = CTcmd->CommandResponse.bits.CmdRsp;
1817 uint16_t fdmi_rsp = CTrsp->CommandResponse.bits.CmdRsp;
1818 IOCB_t *irsp = &rspiocb->iocb;
1819 struct lpfc_nodelist *ndlp;
1820 uint32_t latt, cmd, err;
1822 latt = lpfc_els_chk_latt(vport);
1823 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
1824 "FDMI cmpl: status:x%x/x%x latt:%d",
1825 irsp->ulpStatus, irsp->un.ulpWord[4], latt);
1827 if (latt || irsp->ulpStatus) {
1829 /* Look for a retryable error */
1830 if (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) {
1831 switch ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK)) {
1832 case IOERR_SLI_ABORTED:
1833 case IOERR_ABORT_IN_PROGRESS:
1834 case IOERR_SEQUENCE_TIMEOUT:
1835 case IOERR_ILLEGAL_FRAME:
1836 case IOERR_NO_RESOURCES:
1837 case IOERR_ILLEGAL_COMMAND:
1839 if (cmdiocb->retry >= LPFC_FDMI_MAX_RETRY)
1842 /* Retry the same FDMI command */
1843 err = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING,
1845 if (err == IOCB_ERROR)
1853 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1854 "0229 FDMI cmd %04x failed, latt = %d "
1855 "ulpStatus: x%x, rid x%x\n",
1856 be16_to_cpu(fdmi_cmd), latt, irsp->ulpStatus,
1857 irsp->un.ulpWord[4]);
1859 lpfc_ct_free_iocb(phba, cmdiocb);
1861 ndlp = lpfc_findnode_did(vport, FDMI_DID);
1862 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
1865 /* Check for a CT LS_RJT response */
1866 cmd = be16_to_cpu(fdmi_cmd);
1867 if (fdmi_rsp == cpu_to_be16(SLI_CT_RESPONSE_FS_RJT)) {
1868 /* FDMI rsp failed */
1869 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1870 "0220 FDMI cmd failed FS_RJT Data: x%x", cmd);
1872 /* Should we fallback to FDMI-2 / FDMI-1 ? */
1875 if (vport->fdmi_hba_mask == LPFC_FDMI2_HBA_ATTR) {
1876 /* Fallback to FDMI-1 */
1877 vport->fdmi_hba_mask = LPFC_FDMI1_HBA_ATTR;
1878 vport->fdmi_port_mask = LPFC_FDMI1_PORT_ATTR;
1880 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA, 0);
1885 if (vport->fdmi_port_mask == LPFC_FDMI2_PORT_ATTR) {
1886 /* Fallback to FDMI-1 */
1887 vport->fdmi_port_mask = LPFC_FDMI1_PORT_ATTR;
1889 lpfc_fdmi_cmd(vport, ndlp, cmd, 0);
1891 if (vport->fdmi_port_mask == LPFC_FDMI2_SMART_ATTR) {
1892 vport->fdmi_port_mask = LPFC_FDMI2_PORT_ATTR;
1893 /* Retry the same command */
1894 lpfc_fdmi_cmd(vport, ndlp, cmd, 0);
1899 if (vport->fdmi_port_mask == LPFC_FDMI2_PORT_ATTR) {
1900 /* Fallback to FDMI-1 */
1901 vport->fdmi_hba_mask = LPFC_FDMI1_HBA_ATTR;
1902 vport->fdmi_port_mask = LPFC_FDMI1_PORT_ATTR;
1904 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA, 0);
1906 if (vport->fdmi_port_mask == LPFC_FDMI2_SMART_ATTR) {
1907 vport->fdmi_port_mask = LPFC_FDMI2_PORT_ATTR;
1908 /* Retry the same command */
1909 lpfc_fdmi_cmd(vport, ndlp, cmd, 0);
1916 * On success, need to cycle thru FDMI registration for discovery
1917 * DHBA -> DPRT -> RHBA -> RPA (physical port)
1918 * DPRT -> RPRT (vports)
1922 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RPA, 0);
1926 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DPRT, 0);
1930 if (vport->port_type == LPFC_PHYSICAL_PORT)
1931 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RHBA, 0);
1933 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RPRT, 0);
1941 * lpfc_fdmi_num_disc_check - Check how many mapped NPorts we are connected to
1942 * @vport: pointer to a host virtual N_Port data structure.
1944 * Called from hbeat timeout routine to check if the number of discovered
1945 * ports has changed. If so, re-register thar port Attribute.
1948 lpfc_fdmi_num_disc_check(struct lpfc_vport *vport)
1950 struct lpfc_hba *phba = vport->phba;
1951 struct lpfc_nodelist *ndlp;
1954 if (!lpfc_is_link_up(phba))
1957 /* Must be connected to a Fabric */
1958 if (!(vport->fc_flag & FC_FABRIC))
1961 if (!(vport->fdmi_port_mask & LPFC_FDMI_PORT_ATTR_num_disc))
1964 cnt = lpfc_find_map_node(vport);
1965 if (cnt == vport->fdmi_num_disc)
1968 ndlp = lpfc_findnode_did(vport, FDMI_DID);
1969 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
1972 if (vport->port_type == LPFC_PHYSICAL_PORT) {
1973 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RPA,
1974 LPFC_FDMI_PORT_ATTR_num_disc);
1976 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RPRT,
1977 LPFC_FDMI_PORT_ATTR_num_disc);
1981 /* Routines for all individual HBA attributes */
1983 lpfc_fdmi_hba_attr_wwnn(struct lpfc_vport *vport, struct lpfc_fdmi_attr_def *ad)
1985 struct lpfc_fdmi_attr_entry *ae;
1988 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
1989 memset(ae, 0, sizeof(struct lpfc_name));
1991 memcpy(&ae->un.AttrWWN, &vport->fc_sparam.nodeName,
1992 sizeof(struct lpfc_name));
1993 size = FOURBYTES + sizeof(struct lpfc_name);
1994 ad->AttrLen = cpu_to_be16(size);
1995 ad->AttrType = cpu_to_be16(RHBA_NODENAME);
1999 lpfc_fdmi_hba_attr_manufacturer(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;
2008 /* This string MUST be consistent with other FC platforms
2009 * supported by Broadcom.
2011 strncpy(ae->un.AttrString,
2012 "Emulex Corporation",
2013 sizeof(ae->un.AttrString));
2014 len = strnlen(ae->un.AttrString,
2015 sizeof(ae->un.AttrString));
2016 len += (len & 3) ? (4 - (len & 3)) : 4;
2017 size = FOURBYTES + len;
2018 ad->AttrLen = cpu_to_be16(size);
2019 ad->AttrType = cpu_to_be16(RHBA_MANUFACTURER);
2024 lpfc_fdmi_hba_attr_sn(struct lpfc_vport *vport, struct lpfc_fdmi_attr_def *ad)
2026 struct lpfc_hba *phba = vport->phba;
2027 struct lpfc_fdmi_attr_entry *ae;
2030 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2033 strncpy(ae->un.AttrString, phba->SerialNumber,
2034 sizeof(ae->un.AttrString));
2035 len = strnlen(ae->un.AttrString,
2036 sizeof(ae->un.AttrString));
2037 len += (len & 3) ? (4 - (len & 3)) : 4;
2038 size = FOURBYTES + len;
2039 ad->AttrLen = cpu_to_be16(size);
2040 ad->AttrType = cpu_to_be16(RHBA_SERIAL_NUMBER);
2045 lpfc_fdmi_hba_attr_model(struct lpfc_vport *vport,
2046 struct lpfc_fdmi_attr_def *ad)
2048 struct lpfc_hba *phba = vport->phba;
2049 struct lpfc_fdmi_attr_entry *ae;
2052 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2055 strncpy(ae->un.AttrString, phba->ModelName,
2056 sizeof(ae->un.AttrString));
2057 len = strnlen(ae->un.AttrString, sizeof(ae->un.AttrString));
2058 len += (len & 3) ? (4 - (len & 3)) : 4;
2059 size = FOURBYTES + len;
2060 ad->AttrLen = cpu_to_be16(size);
2061 ad->AttrType = cpu_to_be16(RHBA_MODEL);
2066 lpfc_fdmi_hba_attr_description(struct lpfc_vport *vport,
2067 struct lpfc_fdmi_attr_def *ad)
2069 struct lpfc_hba *phba = vport->phba;
2070 struct lpfc_fdmi_attr_entry *ae;
2073 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2076 strncpy(ae->un.AttrString, phba->ModelDesc,
2077 sizeof(ae->un.AttrString));
2078 len = strnlen(ae->un.AttrString,
2079 sizeof(ae->un.AttrString));
2080 len += (len & 3) ? (4 - (len & 3)) : 4;
2081 size = FOURBYTES + len;
2082 ad->AttrLen = cpu_to_be16(size);
2083 ad->AttrType = cpu_to_be16(RHBA_MODEL_DESCRIPTION);
2088 lpfc_fdmi_hba_attr_hdw_ver(struct lpfc_vport *vport,
2089 struct lpfc_fdmi_attr_def *ad)
2091 struct lpfc_hba *phba = vport->phba;
2092 lpfc_vpd_t *vp = &phba->vpd;
2093 struct lpfc_fdmi_attr_entry *ae;
2094 uint32_t i, j, incr, size;
2096 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2099 /* Convert JEDEC ID to ascii for hardware version */
2100 incr = vp->rev.biuRev;
2101 for (i = 0; i < 8; i++) {
2104 ae->un.AttrString[7 - i] =
2105 (char)((uint8_t) 0x30 +
2108 ae->un.AttrString[7 - i] =
2109 (char)((uint8_t) 0x61 +
2110 (uint8_t) (j - 10));
2113 size = FOURBYTES + 8;
2114 ad->AttrLen = cpu_to_be16(size);
2115 ad->AttrType = cpu_to_be16(RHBA_HARDWARE_VERSION);
2120 lpfc_fdmi_hba_attr_drvr_ver(struct lpfc_vport *vport,
2121 struct lpfc_fdmi_attr_def *ad)
2123 struct lpfc_fdmi_attr_entry *ae;
2126 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2129 strncpy(ae->un.AttrString, lpfc_release_version,
2130 sizeof(ae->un.AttrString));
2131 len = strnlen(ae->un.AttrString,
2132 sizeof(ae->un.AttrString));
2133 len += (len & 3) ? (4 - (len & 3)) : 4;
2134 size = FOURBYTES + len;
2135 ad->AttrLen = cpu_to_be16(size);
2136 ad->AttrType = cpu_to_be16(RHBA_DRIVER_VERSION);
2141 lpfc_fdmi_hba_attr_rom_ver(struct lpfc_vport *vport,
2142 struct lpfc_fdmi_attr_def *ad)
2144 struct lpfc_hba *phba = vport->phba;
2145 struct lpfc_fdmi_attr_entry *ae;
2148 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2151 if (phba->sli_rev == LPFC_SLI_REV4)
2152 lpfc_decode_firmware_rev(phba, ae->un.AttrString, 1);
2154 strncpy(ae->un.AttrString, phba->OptionROMVersion,
2155 sizeof(ae->un.AttrString));
2156 len = strnlen(ae->un.AttrString,
2157 sizeof(ae->un.AttrString));
2158 len += (len & 3) ? (4 - (len & 3)) : 4;
2159 size = FOURBYTES + len;
2160 ad->AttrLen = cpu_to_be16(size);
2161 ad->AttrType = cpu_to_be16(RHBA_OPTION_ROM_VERSION);
2166 lpfc_fdmi_hba_attr_fmw_ver(struct lpfc_vport *vport,
2167 struct lpfc_fdmi_attr_def *ad)
2169 struct lpfc_hba *phba = vport->phba;
2170 struct lpfc_fdmi_attr_entry *ae;
2173 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2176 lpfc_decode_firmware_rev(phba, ae->un.AttrString, 1);
2177 len = strnlen(ae->un.AttrString,
2178 sizeof(ae->un.AttrString));
2179 len += (len & 3) ? (4 - (len & 3)) : 4;
2180 size = FOURBYTES + len;
2181 ad->AttrLen = cpu_to_be16(size);
2182 ad->AttrType = cpu_to_be16(RHBA_FIRMWARE_VERSION);
2187 lpfc_fdmi_hba_attr_os_ver(struct lpfc_vport *vport,
2188 struct lpfc_fdmi_attr_def *ad)
2190 struct lpfc_fdmi_attr_entry *ae;
2193 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2196 snprintf(ae->un.AttrString, sizeof(ae->un.AttrString), "%s %s %s",
2197 init_utsname()->sysname,
2198 init_utsname()->release,
2199 init_utsname()->version);
2201 len = strnlen(ae->un.AttrString, sizeof(ae->un.AttrString));
2202 len += (len & 3) ? (4 - (len & 3)) : 4;
2203 size = FOURBYTES + len;
2204 ad->AttrLen = cpu_to_be16(size);
2205 ad->AttrType = cpu_to_be16(RHBA_OS_NAME_VERSION);
2210 lpfc_fdmi_hba_attr_ct_len(struct lpfc_vport *vport,
2211 struct lpfc_fdmi_attr_def *ad)
2213 struct lpfc_fdmi_attr_entry *ae;
2216 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2218 ae->un.AttrInt = cpu_to_be32(LPFC_MAX_CT_SIZE);
2219 size = FOURBYTES + sizeof(uint32_t);
2220 ad->AttrLen = cpu_to_be16(size);
2221 ad->AttrType = cpu_to_be16(RHBA_MAX_CT_PAYLOAD_LEN);
2226 lpfc_fdmi_hba_attr_symbolic_name(struct lpfc_vport *vport,
2227 struct lpfc_fdmi_attr_def *ad)
2229 struct lpfc_fdmi_attr_entry *ae;
2232 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2235 len = lpfc_vport_symbolic_node_name(vport,
2236 ae->un.AttrString, 256);
2237 len += (len & 3) ? (4 - (len & 3)) : 4;
2238 size = FOURBYTES + len;
2239 ad->AttrLen = cpu_to_be16(size);
2240 ad->AttrType = cpu_to_be16(RHBA_SYM_NODENAME);
2245 lpfc_fdmi_hba_attr_vendor_info(struct lpfc_vport *vport,
2246 struct lpfc_fdmi_attr_def *ad)
2248 struct lpfc_fdmi_attr_entry *ae;
2251 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2253 /* Nothing is defined for this currently */
2254 ae->un.AttrInt = cpu_to_be32(0);
2255 size = FOURBYTES + sizeof(uint32_t);
2256 ad->AttrLen = cpu_to_be16(size);
2257 ad->AttrType = cpu_to_be16(RHBA_VENDOR_INFO);
2262 lpfc_fdmi_hba_attr_num_ports(struct lpfc_vport *vport,
2263 struct lpfc_fdmi_attr_def *ad)
2265 struct lpfc_fdmi_attr_entry *ae;
2268 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2270 /* Each driver instance corresponds to a single port */
2271 ae->un.AttrInt = cpu_to_be32(1);
2272 size = FOURBYTES + sizeof(uint32_t);
2273 ad->AttrLen = cpu_to_be16(size);
2274 ad->AttrType = cpu_to_be16(RHBA_NUM_PORTS);
2279 lpfc_fdmi_hba_attr_fabric_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->fabric_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(RHBA_FABRIC_WWNN);
2297 lpfc_fdmi_hba_attr_bios_ver(struct lpfc_vport *vport,
2298 struct lpfc_fdmi_attr_def *ad)
2300 struct lpfc_hba *phba = vport->phba;
2301 struct lpfc_fdmi_attr_entry *ae;
2304 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2307 lpfc_decode_firmware_rev(phba, ae->un.AttrString, 1);
2308 len = strnlen(ae->un.AttrString,
2309 sizeof(ae->un.AttrString));
2310 len += (len & 3) ? (4 - (len & 3)) : 4;
2311 size = FOURBYTES + len;
2312 ad->AttrLen = cpu_to_be16(size);
2313 ad->AttrType = cpu_to_be16(RHBA_BIOS_VERSION);
2318 lpfc_fdmi_hba_attr_bios_state(struct lpfc_vport *vport,
2319 struct lpfc_fdmi_attr_def *ad)
2321 struct lpfc_fdmi_attr_entry *ae;
2324 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2326 /* Driver doesn't have access to this information */
2327 ae->un.AttrInt = cpu_to_be32(0);
2328 size = FOURBYTES + sizeof(uint32_t);
2329 ad->AttrLen = cpu_to_be16(size);
2330 ad->AttrType = cpu_to_be16(RHBA_BIOS_STATE);
2335 lpfc_fdmi_hba_attr_vendor_id(struct lpfc_vport *vport,
2336 struct lpfc_fdmi_attr_def *ad)
2338 struct lpfc_fdmi_attr_entry *ae;
2341 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2344 strncpy(ae->un.AttrString, "EMULEX",
2345 sizeof(ae->un.AttrString));
2346 len = strnlen(ae->un.AttrString,
2347 sizeof(ae->un.AttrString));
2348 len += (len & 3) ? (4 - (len & 3)) : 4;
2349 size = FOURBYTES + len;
2350 ad->AttrLen = cpu_to_be16(size);
2351 ad->AttrType = cpu_to_be16(RHBA_VENDOR_ID);
2355 /* Routines for all individual PORT attributes */
2357 lpfc_fdmi_port_attr_fc4type(struct lpfc_vport *vport,
2358 struct lpfc_fdmi_attr_def *ad)
2360 struct lpfc_fdmi_attr_entry *ae;
2363 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2366 ae->un.AttrTypes[3] = 0x02; /* Type 0x1 - ELS */
2367 ae->un.AttrTypes[2] = 0x01; /* Type 0x8 - FCP */
2368 if (vport->nvmei_support || vport->phba->nvmet_support)
2369 ae->un.AttrTypes[6] = 0x01; /* Type 0x28 - NVME */
2370 ae->un.AttrTypes[7] = 0x01; /* Type 0x20 - CT */
2371 size = FOURBYTES + 32;
2372 ad->AttrLen = cpu_to_be16(size);
2373 ad->AttrType = cpu_to_be16(RPRT_SUPPORTED_FC4_TYPES);
2378 lpfc_fdmi_port_attr_support_speed(struct lpfc_vport *vport,
2379 struct lpfc_fdmi_attr_def *ad)
2381 struct lpfc_hba *phba = vport->phba;
2382 struct lpfc_fdmi_attr_entry *ae;
2385 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2388 if (!(phba->hba_flag & HBA_FCOE_MODE)) {
2389 if (phba->lmt & LMT_128Gb)
2390 ae->un.AttrInt |= HBA_PORTSPEED_128GFC;
2391 if (phba->lmt & LMT_64Gb)
2392 ae->un.AttrInt |= HBA_PORTSPEED_64GFC;
2393 if (phba->lmt & LMT_32Gb)
2394 ae->un.AttrInt |= HBA_PORTSPEED_32GFC;
2395 if (phba->lmt & LMT_16Gb)
2396 ae->un.AttrInt |= HBA_PORTSPEED_16GFC;
2397 if (phba->lmt & LMT_10Gb)
2398 ae->un.AttrInt |= HBA_PORTSPEED_10GFC;
2399 if (phba->lmt & LMT_8Gb)
2400 ae->un.AttrInt |= HBA_PORTSPEED_8GFC;
2401 if (phba->lmt & LMT_4Gb)
2402 ae->un.AttrInt |= HBA_PORTSPEED_4GFC;
2403 if (phba->lmt & LMT_2Gb)
2404 ae->un.AttrInt |= HBA_PORTSPEED_2GFC;
2405 if (phba->lmt & LMT_1Gb)
2406 ae->un.AttrInt |= HBA_PORTSPEED_1GFC;
2408 /* FCoE links support only one speed */
2409 switch (phba->fc_linkspeed) {
2410 case LPFC_ASYNC_LINK_SPEED_10GBPS:
2411 ae->un.AttrInt = HBA_PORTSPEED_10GE;
2413 case LPFC_ASYNC_LINK_SPEED_25GBPS:
2414 ae->un.AttrInt = HBA_PORTSPEED_25GE;
2416 case LPFC_ASYNC_LINK_SPEED_40GBPS:
2417 ae->un.AttrInt = HBA_PORTSPEED_40GE;
2419 case LPFC_ASYNC_LINK_SPEED_100GBPS:
2420 ae->un.AttrInt = HBA_PORTSPEED_100GE;
2424 ae->un.AttrInt = cpu_to_be32(ae->un.AttrInt);
2425 size = FOURBYTES + sizeof(uint32_t);
2426 ad->AttrLen = cpu_to_be16(size);
2427 ad->AttrType = cpu_to_be16(RPRT_SUPPORTED_SPEED);
2432 lpfc_fdmi_port_attr_speed(struct lpfc_vport *vport,
2433 struct lpfc_fdmi_attr_def *ad)
2435 struct lpfc_hba *phba = vport->phba;
2436 struct lpfc_fdmi_attr_entry *ae;
2439 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2441 if (!(phba->hba_flag & HBA_FCOE_MODE)) {
2442 switch (phba->fc_linkspeed) {
2443 case LPFC_LINK_SPEED_1GHZ:
2444 ae->un.AttrInt = HBA_PORTSPEED_1GFC;
2446 case LPFC_LINK_SPEED_2GHZ:
2447 ae->un.AttrInt = HBA_PORTSPEED_2GFC;
2449 case LPFC_LINK_SPEED_4GHZ:
2450 ae->un.AttrInt = HBA_PORTSPEED_4GFC;
2452 case LPFC_LINK_SPEED_8GHZ:
2453 ae->un.AttrInt = HBA_PORTSPEED_8GFC;
2455 case LPFC_LINK_SPEED_10GHZ:
2456 ae->un.AttrInt = HBA_PORTSPEED_10GFC;
2458 case LPFC_LINK_SPEED_16GHZ:
2459 ae->un.AttrInt = HBA_PORTSPEED_16GFC;
2461 case LPFC_LINK_SPEED_32GHZ:
2462 ae->un.AttrInt = HBA_PORTSPEED_32GFC;
2464 case LPFC_LINK_SPEED_64GHZ:
2465 ae->un.AttrInt = HBA_PORTSPEED_64GFC;
2467 case LPFC_LINK_SPEED_128GHZ:
2468 ae->un.AttrInt = HBA_PORTSPEED_128GFC;
2471 ae->un.AttrInt = HBA_PORTSPEED_UNKNOWN;
2475 switch (phba->fc_linkspeed) {
2476 case LPFC_ASYNC_LINK_SPEED_10GBPS:
2477 ae->un.AttrInt = HBA_PORTSPEED_10GE;
2479 case LPFC_ASYNC_LINK_SPEED_25GBPS:
2480 ae->un.AttrInt = HBA_PORTSPEED_25GE;
2482 case LPFC_ASYNC_LINK_SPEED_40GBPS:
2483 ae->un.AttrInt = HBA_PORTSPEED_40GE;
2485 case LPFC_ASYNC_LINK_SPEED_100GBPS:
2486 ae->un.AttrInt = HBA_PORTSPEED_100GE;
2489 ae->un.AttrInt = HBA_PORTSPEED_UNKNOWN;
2494 ae->un.AttrInt = cpu_to_be32(ae->un.AttrInt);
2495 size = FOURBYTES + sizeof(uint32_t);
2496 ad->AttrLen = cpu_to_be16(size);
2497 ad->AttrType = cpu_to_be16(RPRT_PORT_SPEED);
2502 lpfc_fdmi_port_attr_max_frame(struct lpfc_vport *vport,
2503 struct lpfc_fdmi_attr_def *ad)
2505 struct serv_parm *hsp;
2506 struct lpfc_fdmi_attr_entry *ae;
2509 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2511 hsp = (struct serv_parm *)&vport->fc_sparam;
2512 ae->un.AttrInt = (((uint32_t) hsp->cmn.bbRcvSizeMsb) << 8) |
2513 (uint32_t) hsp->cmn.bbRcvSizeLsb;
2514 ae->un.AttrInt = cpu_to_be32(ae->un.AttrInt);
2515 size = FOURBYTES + sizeof(uint32_t);
2516 ad->AttrLen = cpu_to_be16(size);
2517 ad->AttrType = cpu_to_be16(RPRT_MAX_FRAME_SIZE);
2522 lpfc_fdmi_port_attr_os_devname(struct lpfc_vport *vport,
2523 struct lpfc_fdmi_attr_def *ad)
2525 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2526 struct lpfc_fdmi_attr_entry *ae;
2529 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2532 snprintf(ae->un.AttrString, sizeof(ae->un.AttrString),
2533 "/sys/class/scsi_host/host%d", shost->host_no);
2534 len = strnlen((char *)ae->un.AttrString,
2535 sizeof(ae->un.AttrString));
2536 len += (len & 3) ? (4 - (len & 3)) : 4;
2537 size = FOURBYTES + len;
2538 ad->AttrLen = cpu_to_be16(size);
2539 ad->AttrType = cpu_to_be16(RPRT_OS_DEVICE_NAME);
2544 lpfc_fdmi_port_attr_host_name(struct lpfc_vport *vport,
2545 struct lpfc_fdmi_attr_def *ad)
2547 struct lpfc_fdmi_attr_entry *ae;
2550 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2553 snprintf(ae->un.AttrString, sizeof(ae->un.AttrString), "%s",
2554 init_utsname()->nodename);
2556 len = strnlen(ae->un.AttrString, sizeof(ae->un.AttrString));
2557 len += (len & 3) ? (4 - (len & 3)) : 4;
2558 size = FOURBYTES + len;
2559 ad->AttrLen = cpu_to_be16(size);
2560 ad->AttrType = cpu_to_be16(RPRT_HOST_NAME);
2565 lpfc_fdmi_port_attr_wwnn(struct lpfc_vport *vport,
2566 struct lpfc_fdmi_attr_def *ad)
2568 struct lpfc_fdmi_attr_entry *ae;
2571 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2572 memset(ae, 0, sizeof(struct lpfc_name));
2574 memcpy(&ae->un.AttrWWN, &vport->fc_sparam.nodeName,
2575 sizeof(struct lpfc_name));
2576 size = FOURBYTES + sizeof(struct lpfc_name);
2577 ad->AttrLen = cpu_to_be16(size);
2578 ad->AttrType = cpu_to_be16(RPRT_NODENAME);
2583 lpfc_fdmi_port_attr_wwpn(struct lpfc_vport *vport,
2584 struct lpfc_fdmi_attr_def *ad)
2586 struct lpfc_fdmi_attr_entry *ae;
2589 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2590 memset(ae, 0, sizeof(struct lpfc_name));
2592 memcpy(&ae->un.AttrWWN, &vport->fc_sparam.portName,
2593 sizeof(struct lpfc_name));
2594 size = FOURBYTES + sizeof(struct lpfc_name);
2595 ad->AttrLen = cpu_to_be16(size);
2596 ad->AttrType = cpu_to_be16(RPRT_PORTNAME);
2601 lpfc_fdmi_port_attr_symbolic_name(struct lpfc_vport *vport,
2602 struct lpfc_fdmi_attr_def *ad)
2604 struct lpfc_fdmi_attr_entry *ae;
2607 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2610 len = lpfc_vport_symbolic_port_name(vport, ae->un.AttrString, 256);
2611 len += (len & 3) ? (4 - (len & 3)) : 4;
2612 size = FOURBYTES + len;
2613 ad->AttrLen = cpu_to_be16(size);
2614 ad->AttrType = cpu_to_be16(RPRT_SYM_PORTNAME);
2619 lpfc_fdmi_port_attr_port_type(struct lpfc_vport *vport,
2620 struct lpfc_fdmi_attr_def *ad)
2622 struct lpfc_hba *phba = vport->phba;
2623 struct lpfc_fdmi_attr_entry *ae;
2626 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2627 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP)
2628 ae->un.AttrInt = cpu_to_be32(LPFC_FDMI_PORTTYPE_NLPORT);
2630 ae->un.AttrInt = cpu_to_be32(LPFC_FDMI_PORTTYPE_NPORT);
2631 size = FOURBYTES + sizeof(uint32_t);
2632 ad->AttrLen = cpu_to_be16(size);
2633 ad->AttrType = cpu_to_be16(RPRT_PORT_TYPE);
2638 lpfc_fdmi_port_attr_class(struct lpfc_vport *vport,
2639 struct lpfc_fdmi_attr_def *ad)
2641 struct lpfc_fdmi_attr_entry *ae;
2644 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2645 ae->un.AttrInt = cpu_to_be32(FC_COS_CLASS2 | FC_COS_CLASS3);
2646 size = FOURBYTES + sizeof(uint32_t);
2647 ad->AttrLen = cpu_to_be16(size);
2648 ad->AttrType = cpu_to_be16(RPRT_SUPPORTED_CLASS);
2653 lpfc_fdmi_port_attr_fabric_wwpn(struct lpfc_vport *vport,
2654 struct lpfc_fdmi_attr_def *ad)
2656 struct lpfc_fdmi_attr_entry *ae;
2659 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2660 memset(ae, 0, sizeof(struct lpfc_name));
2662 memcpy(&ae->un.AttrWWN, &vport->fabric_portname,
2663 sizeof(struct lpfc_name));
2664 size = FOURBYTES + sizeof(struct lpfc_name);
2665 ad->AttrLen = cpu_to_be16(size);
2666 ad->AttrType = cpu_to_be16(RPRT_FABRICNAME);
2671 lpfc_fdmi_port_attr_active_fc4type(struct lpfc_vport *vport,
2672 struct lpfc_fdmi_attr_def *ad)
2674 struct lpfc_fdmi_attr_entry *ae;
2677 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2680 ae->un.AttrTypes[3] = 0x02; /* Type 0x1 - ELS */
2681 ae->un.AttrTypes[2] = 0x01; /* Type 0x8 - FCP */
2682 if (vport->phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)
2683 ae->un.AttrTypes[6] = 0x1; /* Type 0x28 - NVME */
2684 ae->un.AttrTypes[7] = 0x01; /* Type 0x20 - CT */
2685 size = FOURBYTES + 32;
2686 ad->AttrLen = cpu_to_be16(size);
2687 ad->AttrType = cpu_to_be16(RPRT_ACTIVE_FC4_TYPES);
2692 lpfc_fdmi_port_attr_port_state(struct lpfc_vport *vport,
2693 struct lpfc_fdmi_attr_def *ad)
2695 struct lpfc_fdmi_attr_entry *ae;
2698 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2699 /* Link Up - operational */
2700 ae->un.AttrInt = cpu_to_be32(LPFC_FDMI_PORTSTATE_ONLINE);
2701 size = FOURBYTES + sizeof(uint32_t);
2702 ad->AttrLen = cpu_to_be16(size);
2703 ad->AttrType = cpu_to_be16(RPRT_PORT_STATE);
2708 lpfc_fdmi_port_attr_num_disc(struct lpfc_vport *vport,
2709 struct lpfc_fdmi_attr_def *ad)
2711 struct lpfc_fdmi_attr_entry *ae;
2714 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2715 vport->fdmi_num_disc = lpfc_find_map_node(vport);
2716 ae->un.AttrInt = cpu_to_be32(vport->fdmi_num_disc);
2717 size = FOURBYTES + sizeof(uint32_t);
2718 ad->AttrLen = cpu_to_be16(size);
2719 ad->AttrType = cpu_to_be16(RPRT_DISC_PORT);
2724 lpfc_fdmi_port_attr_nportid(struct lpfc_vport *vport,
2725 struct lpfc_fdmi_attr_def *ad)
2727 struct lpfc_fdmi_attr_entry *ae;
2730 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2731 ae->un.AttrInt = cpu_to_be32(vport->fc_myDID);
2732 size = FOURBYTES + sizeof(uint32_t);
2733 ad->AttrLen = cpu_to_be16(size);
2734 ad->AttrType = cpu_to_be16(RPRT_PORT_ID);
2739 lpfc_fdmi_smart_attr_service(struct lpfc_vport *vport,
2740 struct lpfc_fdmi_attr_def *ad)
2742 struct lpfc_fdmi_attr_entry *ae;
2745 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2748 strncpy(ae->un.AttrString, "Smart SAN Initiator",
2749 sizeof(ae->un.AttrString));
2750 len = strnlen(ae->un.AttrString,
2751 sizeof(ae->un.AttrString));
2752 len += (len & 3) ? (4 - (len & 3)) : 4;
2753 size = FOURBYTES + len;
2754 ad->AttrLen = cpu_to_be16(size);
2755 ad->AttrType = cpu_to_be16(RPRT_SMART_SERVICE);
2760 lpfc_fdmi_smart_attr_guid(struct lpfc_vport *vport,
2761 struct lpfc_fdmi_attr_def *ad)
2763 struct lpfc_fdmi_attr_entry *ae;
2766 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2769 memcpy(&ae->un.AttrString, &vport->fc_sparam.nodeName,
2770 sizeof(struct lpfc_name));
2771 memcpy((((uint8_t *)&ae->un.AttrString) +
2772 sizeof(struct lpfc_name)),
2773 &vport->fc_sparam.portName, sizeof(struct lpfc_name));
2774 size = FOURBYTES + (2 * sizeof(struct lpfc_name));
2775 ad->AttrLen = cpu_to_be16(size);
2776 ad->AttrType = cpu_to_be16(RPRT_SMART_GUID);
2781 lpfc_fdmi_smart_attr_version(struct lpfc_vport *vport,
2782 struct lpfc_fdmi_attr_def *ad)
2784 struct lpfc_fdmi_attr_entry *ae;
2787 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2790 strncpy(ae->un.AttrString, "Smart SAN Version 2.0",
2791 sizeof(ae->un.AttrString));
2792 len = strnlen(ae->un.AttrString,
2793 sizeof(ae->un.AttrString));
2794 len += (len & 3) ? (4 - (len & 3)) : 4;
2795 size = FOURBYTES + len;
2796 ad->AttrLen = cpu_to_be16(size);
2797 ad->AttrType = cpu_to_be16(RPRT_SMART_VERSION);
2802 lpfc_fdmi_smart_attr_model(struct lpfc_vport *vport,
2803 struct lpfc_fdmi_attr_def *ad)
2805 struct lpfc_hba *phba = vport->phba;
2806 struct lpfc_fdmi_attr_entry *ae;
2809 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2812 strncpy(ae->un.AttrString, phba->ModelName,
2813 sizeof(ae->un.AttrString));
2814 len = strnlen(ae->un.AttrString, sizeof(ae->un.AttrString));
2815 len += (len & 3) ? (4 - (len & 3)) : 4;
2816 size = FOURBYTES + len;
2817 ad->AttrLen = cpu_to_be16(size);
2818 ad->AttrType = cpu_to_be16(RPRT_SMART_MODEL);
2823 lpfc_fdmi_smart_attr_port_info(struct lpfc_vport *vport,
2824 struct lpfc_fdmi_attr_def *ad)
2826 struct lpfc_fdmi_attr_entry *ae;
2829 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2831 /* SRIOV (type 3) is not supported */
2833 ae->un.AttrInt = cpu_to_be32(2); /* NPIV */
2835 ae->un.AttrInt = cpu_to_be32(1); /* Physical */
2836 size = FOURBYTES + sizeof(uint32_t);
2837 ad->AttrLen = cpu_to_be16(size);
2838 ad->AttrType = cpu_to_be16(RPRT_SMART_PORT_INFO);
2843 lpfc_fdmi_smart_attr_qos(struct lpfc_vport *vport,
2844 struct lpfc_fdmi_attr_def *ad)
2846 struct lpfc_fdmi_attr_entry *ae;
2849 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2850 ae->un.AttrInt = cpu_to_be32(0);
2851 size = FOURBYTES + sizeof(uint32_t);
2852 ad->AttrLen = cpu_to_be16(size);
2853 ad->AttrType = cpu_to_be16(RPRT_SMART_QOS);
2858 lpfc_fdmi_smart_attr_security(struct lpfc_vport *vport,
2859 struct lpfc_fdmi_attr_def *ad)
2861 struct lpfc_fdmi_attr_entry *ae;
2864 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2865 ae->un.AttrInt = cpu_to_be32(1);
2866 size = FOURBYTES + sizeof(uint32_t);
2867 ad->AttrLen = cpu_to_be16(size);
2868 ad->AttrType = cpu_to_be16(RPRT_SMART_SECURITY);
2872 /* RHBA attribute jump table */
2873 int (*lpfc_fdmi_hba_action[])
2874 (struct lpfc_vport *vport, struct lpfc_fdmi_attr_def *ad) = {
2875 /* Action routine Mask bit Attribute type */
2876 lpfc_fdmi_hba_attr_wwnn, /* bit0 RHBA_NODENAME */
2877 lpfc_fdmi_hba_attr_manufacturer, /* bit1 RHBA_MANUFACTURER */
2878 lpfc_fdmi_hba_attr_sn, /* bit2 RHBA_SERIAL_NUMBER */
2879 lpfc_fdmi_hba_attr_model, /* bit3 RHBA_MODEL */
2880 lpfc_fdmi_hba_attr_description, /* bit4 RHBA_MODEL_DESCRIPTION */
2881 lpfc_fdmi_hba_attr_hdw_ver, /* bit5 RHBA_HARDWARE_VERSION */
2882 lpfc_fdmi_hba_attr_drvr_ver, /* bit6 RHBA_DRIVER_VERSION */
2883 lpfc_fdmi_hba_attr_rom_ver, /* bit7 RHBA_OPTION_ROM_VERSION */
2884 lpfc_fdmi_hba_attr_fmw_ver, /* bit8 RHBA_FIRMWARE_VERSION */
2885 lpfc_fdmi_hba_attr_os_ver, /* bit9 RHBA_OS_NAME_VERSION */
2886 lpfc_fdmi_hba_attr_ct_len, /* bit10 RHBA_MAX_CT_PAYLOAD_LEN */
2887 lpfc_fdmi_hba_attr_symbolic_name, /* bit11 RHBA_SYM_NODENAME */
2888 lpfc_fdmi_hba_attr_vendor_info, /* bit12 RHBA_VENDOR_INFO */
2889 lpfc_fdmi_hba_attr_num_ports, /* bit13 RHBA_NUM_PORTS */
2890 lpfc_fdmi_hba_attr_fabric_wwnn, /* bit14 RHBA_FABRIC_WWNN */
2891 lpfc_fdmi_hba_attr_bios_ver, /* bit15 RHBA_BIOS_VERSION */
2892 lpfc_fdmi_hba_attr_bios_state, /* bit16 RHBA_BIOS_STATE */
2893 lpfc_fdmi_hba_attr_vendor_id, /* bit17 RHBA_VENDOR_ID */
2896 /* RPA / RPRT attribute jump table */
2897 int (*lpfc_fdmi_port_action[])
2898 (struct lpfc_vport *vport, struct lpfc_fdmi_attr_def *ad) = {
2899 /* Action routine Mask bit Attribute type */
2900 lpfc_fdmi_port_attr_fc4type, /* bit0 RPRT_SUPPORT_FC4_TYPES */
2901 lpfc_fdmi_port_attr_support_speed, /* bit1 RPRT_SUPPORTED_SPEED */
2902 lpfc_fdmi_port_attr_speed, /* bit2 RPRT_PORT_SPEED */
2903 lpfc_fdmi_port_attr_max_frame, /* bit3 RPRT_MAX_FRAME_SIZE */
2904 lpfc_fdmi_port_attr_os_devname, /* bit4 RPRT_OS_DEVICE_NAME */
2905 lpfc_fdmi_port_attr_host_name, /* bit5 RPRT_HOST_NAME */
2906 lpfc_fdmi_port_attr_wwnn, /* bit6 RPRT_NODENAME */
2907 lpfc_fdmi_port_attr_wwpn, /* bit7 RPRT_PORTNAME */
2908 lpfc_fdmi_port_attr_symbolic_name, /* bit8 RPRT_SYM_PORTNAME */
2909 lpfc_fdmi_port_attr_port_type, /* bit9 RPRT_PORT_TYPE */
2910 lpfc_fdmi_port_attr_class, /* bit10 RPRT_SUPPORTED_CLASS */
2911 lpfc_fdmi_port_attr_fabric_wwpn, /* bit11 RPRT_FABRICNAME */
2912 lpfc_fdmi_port_attr_active_fc4type, /* bit12 RPRT_ACTIVE_FC4_TYPES */
2913 lpfc_fdmi_port_attr_port_state, /* bit13 RPRT_PORT_STATE */
2914 lpfc_fdmi_port_attr_num_disc, /* bit14 RPRT_DISC_PORT */
2915 lpfc_fdmi_port_attr_nportid, /* bit15 RPRT_PORT_ID */
2916 lpfc_fdmi_smart_attr_service, /* bit16 RPRT_SMART_SERVICE */
2917 lpfc_fdmi_smart_attr_guid, /* bit17 RPRT_SMART_GUID */
2918 lpfc_fdmi_smart_attr_version, /* bit18 RPRT_SMART_VERSION */
2919 lpfc_fdmi_smart_attr_model, /* bit19 RPRT_SMART_MODEL */
2920 lpfc_fdmi_smart_attr_port_info, /* bit20 RPRT_SMART_PORT_INFO */
2921 lpfc_fdmi_smart_attr_qos, /* bit21 RPRT_SMART_QOS */
2922 lpfc_fdmi_smart_attr_security, /* bit22 RPRT_SMART_SECURITY */
2926 * lpfc_fdmi_cmd - Build and send a FDMI cmd to the specified NPort
2927 * @vport: pointer to a host virtual N_Port data structure.
2928 * @ndlp: ndlp to send FDMI cmd to (if NULL use FDMI_DID)
2929 * cmdcode: FDMI command to send
2930 * mask: Mask of HBA or PORT Attributes to send
2932 * Builds and sends a FDMI command using the CT subsystem.
2935 lpfc_fdmi_cmd(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2936 int cmdcode, uint32_t new_mask)
2938 struct lpfc_hba *phba = vport->phba;
2939 struct lpfc_dmabuf *mp, *bmp;
2940 struct lpfc_sli_ct_request *CtReq;
2941 struct ulp_bde64 *bpl;
2946 struct lpfc_fdmi_reg_hba *rh;
2947 struct lpfc_fdmi_port_entry *pe;
2948 struct lpfc_fdmi_reg_portattr *pab = NULL;
2949 struct lpfc_fdmi_attr_block *ab = NULL;
2950 int (*func)(struct lpfc_vport *vport, struct lpfc_fdmi_attr_def *ad);
2951 void (*cmpl)(struct lpfc_hba *, struct lpfc_iocbq *,
2952 struct lpfc_iocbq *);
2954 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
2957 cmpl = lpfc_cmpl_ct_disc_fdmi; /* called from discovery */
2959 /* fill in BDEs for command */
2960 /* Allocate buffer for command payload */
2961 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
2965 mp->virt = lpfc_mbuf_alloc(phba, 0, &(mp->phys));
2967 goto fdmi_cmd_free_mp;
2969 /* Allocate buffer for Buffer ptr list */
2970 bmp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
2972 goto fdmi_cmd_free_mpvirt;
2974 bmp->virt = lpfc_mbuf_alloc(phba, 0, &(bmp->phys));
2976 goto fdmi_cmd_free_bmp;
2978 INIT_LIST_HEAD(&mp->list);
2979 INIT_LIST_HEAD(&bmp->list);
2982 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2983 "0218 FDMI Request Data: x%x x%x x%x\n",
2984 vport->fc_flag, vport->port_state, cmdcode);
2985 CtReq = (struct lpfc_sli_ct_request *)mp->virt;
2987 /* First populate the CT_IU preamble */
2988 memset(CtReq, 0, sizeof(struct lpfc_sli_ct_request));
2989 CtReq->RevisionId.bits.Revision = SLI_CT_REVISION;
2990 CtReq->RevisionId.bits.InId = 0;
2992 CtReq->FsType = SLI_CT_MANAGEMENT_SERVICE;
2993 CtReq->FsSubType = SLI_CT_FDMI_Subtypes;
2995 CtReq->CommandResponse.bits.CmdRsp = cpu_to_be16(cmdcode);
2996 rsp_size = LPFC_BPL_SIZE;
2999 /* Next fill in the specific FDMI cmd information */
3003 rh = (struct lpfc_fdmi_reg_hba *)&CtReq->un.PortID;
3004 /* HBA Identifier */
3005 memcpy(&rh->hi.PortName, &phba->pport->fc_sparam.portName,
3006 sizeof(struct lpfc_name));
3008 if (cmdcode == SLI_MGMT_RHBA) {
3009 /* Registered Port List */
3010 /* One entry (port) per adapter */
3011 rh->rpl.EntryCnt = cpu_to_be32(1);
3012 memcpy(&rh->rpl.pe, &phba->pport->fc_sparam.portName,
3013 sizeof(struct lpfc_name));
3015 /* point to the HBA attribute block */
3016 size = 2 * sizeof(struct lpfc_name) +
3019 size = sizeof(struct lpfc_name);
3021 ab = (struct lpfc_fdmi_attr_block *)((uint8_t *)rh + size);
3028 mask = vport->fdmi_hba_mask;
3030 /* Mask will dictate what attributes to build in the request */
3033 func = lpfc_fdmi_hba_action[bit_pos];
3035 (struct lpfc_fdmi_attr_def *)
3036 ((uint8_t *)rh + size));
3039 (LPFC_BPL_SIZE - LPFC_CT_PREAMBLE))
3046 ab->EntryCnt = cpu_to_be32(ab->EntryCnt);
3048 size = GID_REQUEST_SZ - 4 + size;
3053 pab = (struct lpfc_fdmi_reg_portattr *)&CtReq->un.PortID;
3054 if (cmdcode == SLI_MGMT_RPRT) {
3055 rh = (struct lpfc_fdmi_reg_hba *)pab;
3056 /* HBA Identifier */
3057 memcpy(&rh->hi.PortName,
3058 &phba->pport->fc_sparam.portName,
3059 sizeof(struct lpfc_name));
3060 pab = (struct lpfc_fdmi_reg_portattr *)
3061 ((uint8_t *)pab + sizeof(struct lpfc_name));
3064 memcpy((uint8_t *)&pab->PortName,
3065 (uint8_t *)&vport->fc_sparam.portName,
3066 sizeof(struct lpfc_name));
3067 size += sizeof(struct lpfc_name) + FOURBYTES;
3068 pab->ab.EntryCnt = 0;
3073 mask = vport->fdmi_port_mask;
3075 /* Mask will dictate what attributes to build in the request */
3078 func = lpfc_fdmi_port_action[bit_pos];
3080 (struct lpfc_fdmi_attr_def *)
3081 ((uint8_t *)pab + size));
3084 (LPFC_BPL_SIZE - LPFC_CT_PREAMBLE))
3091 pab->ab.EntryCnt = cpu_to_be32(pab->ab.EntryCnt);
3093 if (cmdcode == SLI_MGMT_RPRT)
3094 size += sizeof(struct lpfc_name);
3095 size = GID_REQUEST_SZ - 4 + size;
3100 rsp_size = FC_MAX_NS_RSP;
3103 pe = (struct lpfc_fdmi_port_entry *)&CtReq->un.PortID;
3104 memcpy((uint8_t *)&pe->PortName,
3105 (uint8_t *)&vport->fc_sparam.portName,
3106 sizeof(struct lpfc_name));
3107 size = GID_REQUEST_SZ - 4 + sizeof(struct lpfc_name);
3112 rsp_size = FC_MAX_NS_RSP;
3115 pe = (struct lpfc_fdmi_port_entry *)&CtReq->un.PortID;
3116 memcpy((uint8_t *)&pe->PortName,
3117 (uint8_t *)&vport->fc_sparam.portName,
3118 sizeof(struct lpfc_name));
3119 size = GID_REQUEST_SZ - 4 + sizeof(struct lpfc_name);
3122 size = GID_REQUEST_SZ - 4;
3125 lpfc_printf_vlog(vport, KERN_WARNING, LOG_DISCOVERY,
3126 "0298 FDMI cmdcode x%x not supported\n",
3128 goto fdmi_cmd_free_bmpvirt;
3130 CtReq->CommandResponse.bits.Size = cpu_to_be16(rsp_size);
3132 bpl = (struct ulp_bde64 *)bmp->virt;
3133 bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys));
3134 bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys));
3135 bpl->tus.f.bdeFlags = 0;
3136 bpl->tus.f.bdeSize = size;
3139 * The lpfc_ct_cmd/lpfc_get_req shall increment ndlp reference count
3140 * to hold ndlp reference for the corresponding callback function.
3142 if (!lpfc_ct_cmd(vport, mp, bmp, ndlp, cmpl, rsp_size, 0))
3146 * Decrement ndlp reference count to release ndlp reference held
3147 * for the failed command's callback function.
3151 fdmi_cmd_free_bmpvirt:
3152 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
3155 fdmi_cmd_free_mpvirt:
3156 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3160 /* Issue FDMI request failed */
3161 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
3162 "0244 Issue FDMI request failed Data: x%x\n",
3168 * lpfc_delayed_disc_tmo - Timeout handler for delayed discovery timer.
3169 * @ptr - Context object of the timer.
3171 * This function set the WORKER_DELAYED_DISC_TMO flag and wake up
3172 * the worker thread.
3175 lpfc_delayed_disc_tmo(struct timer_list *t)
3177 struct lpfc_vport *vport = from_timer(vport, t, delayed_disc_tmo);
3178 struct lpfc_hba *phba = vport->phba;
3179 uint32_t tmo_posted;
3180 unsigned long iflag;
3182 spin_lock_irqsave(&vport->work_port_lock, iflag);
3183 tmo_posted = vport->work_port_events & WORKER_DELAYED_DISC_TMO;
3185 vport->work_port_events |= WORKER_DELAYED_DISC_TMO;
3186 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
3189 lpfc_worker_wake_up(phba);
3194 * lpfc_delayed_disc_timeout_handler - Function called by worker thread to
3195 * handle delayed discovery.
3196 * @vport: pointer to a host virtual N_Port data structure.
3198 * This function start nport discovery of the vport.
3201 lpfc_delayed_disc_timeout_handler(struct lpfc_vport *vport)
3203 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3205 spin_lock_irq(shost->host_lock);
3206 if (!(vport->fc_flag & FC_DISC_DELAYED)) {
3207 spin_unlock_irq(shost->host_lock);
3210 vport->fc_flag &= ~FC_DISC_DELAYED;
3211 spin_unlock_irq(shost->host_lock);
3213 lpfc_do_scr_ns_plogi(vport->phba, vport);
3217 lpfc_decode_firmware_rev(struct lpfc_hba *phba, char *fwrevision, int flag)
3219 struct lpfc_sli *psli = &phba->sli;
3220 lpfc_vpd_t *vp = &phba->vpd;
3221 uint32_t b1, b2, b3, b4, i, rev;
3223 uint32_t *ptr, str[4];
3226 if (phba->sli_rev == LPFC_SLI_REV4)
3227 snprintf(fwrevision, FW_REV_STR_SIZE, "%s", vp->rev.opFwName);
3228 else if (vp->rev.rBit) {
3229 if (psli->sli_flag & LPFC_SLI_ACTIVE)
3230 rev = vp->rev.sli2FwRev;
3232 rev = vp->rev.sli1FwRev;
3234 b1 = (rev & 0x0000f000) >> 12;
3235 b2 = (rev & 0x00000f00) >> 8;
3236 b3 = (rev & 0x000000c0) >> 6;
3237 b4 = (rev & 0x00000030) >> 4;
3256 b4 = (rev & 0x0000000f);
3258 if (psli->sli_flag & LPFC_SLI_ACTIVE)
3259 fwname = vp->rev.sli2FwName;
3261 fwname = vp->rev.sli1FwName;
3263 for (i = 0; i < 16; i++)
3264 if (fwname[i] == 0x20)
3267 ptr = (uint32_t*)fwname;
3269 for (i = 0; i < 3; i++)
3270 str[i] = be32_to_cpu(*ptr++);
3274 sprintf(fwrevision, "%d.%d%d (%s)",
3275 b1, b2, b3, (char *)str);
3277 sprintf(fwrevision, "%d.%d%d", b1,
3281 sprintf(fwrevision, "%d.%d%d%c%d (%s)",
3285 sprintf(fwrevision, "%d.%d%d%c%d",
3289 rev = vp->rev.smFwRev;
3291 b1 = (rev & 0xff000000) >> 24;
3292 b2 = (rev & 0x00f00000) >> 20;
3293 b3 = (rev & 0x000f0000) >> 16;
3294 c = (rev & 0x0000ff00) >> 8;
3295 b4 = (rev & 0x000000ff);
3297 sprintf(fwrevision, "%d.%d%d%c%d", b1, b2, b3, c, b4);