1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2017-2018 Broadcom. All Rights Reserved. The term *
5 * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. *
6 * Copyright (C) 2004-2016 Emulex. All rights reserved. *
7 * EMULEX and SLI are trademarks of Emulex. *
10 * This program is free software; you can redistribute it and/or *
11 * modify it under the terms of version 2 of the GNU General *
12 * Public License as published by the Free Software Foundation. *
13 * This program is distributed in the hope that it will be useful. *
14 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
15 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
16 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
17 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
18 * TO BE LEGALLY INVALID. See the GNU General Public License for *
19 * more details, a copy of which can be found in the file COPYING *
20 * included with this package. *
21 *******************************************************************/
24 * Fibre Channel SCSI LAN Device Driver CT support: FC Generic Services FC-GS
27 #include <linux/blkdev.h>
28 #include <linux/pci.h>
29 #include <linux/interrupt.h>
30 #include <linux/slab.h>
31 #include <linux/utsname.h>
33 #include <scsi/scsi.h>
34 #include <scsi/scsi_device.h>
35 #include <scsi/scsi_host.h>
36 #include <scsi/scsi_transport_fc.h>
37 #include <scsi/fc/fc_fs.h>
42 #include "lpfc_sli4.h"
44 #include "lpfc_disc.h"
46 #include "lpfc_scsi.h"
47 #include "lpfc_nvme.h"
48 #include "lpfc_logmsg.h"
49 #include "lpfc_crtn.h"
50 #include "lpfc_version.h"
51 #include "lpfc_vport.h"
52 #include "lpfc_debugfs.h"
54 /* FDMI Port Speed definitions - FC-GS-7 */
55 #define HBA_PORTSPEED_1GFC 0x00000001 /* 1G FC */
56 #define HBA_PORTSPEED_2GFC 0x00000002 /* 2G FC */
57 #define HBA_PORTSPEED_4GFC 0x00000008 /* 4G FC */
58 #define HBA_PORTSPEED_10GFC 0x00000004 /* 10G FC */
59 #define HBA_PORTSPEED_8GFC 0x00000010 /* 8G FC */
60 #define HBA_PORTSPEED_16GFC 0x00000020 /* 16G FC */
61 #define HBA_PORTSPEED_32GFC 0x00000040 /* 32G FC */
62 #define HBA_PORTSPEED_20GFC 0x00000080 /* 20G FC */
63 #define HBA_PORTSPEED_40GFC 0x00000100 /* 40G FC */
64 #define HBA_PORTSPEED_128GFC 0x00000200 /* 128G FC */
65 #define HBA_PORTSPEED_64GFC 0x00000400 /* 64G FC */
66 #define HBA_PORTSPEED_256GFC 0x00000800 /* 256G FC */
67 #define HBA_PORTSPEED_UNKNOWN 0x00008000 /* Unknown */
68 #define HBA_PORTSPEED_10GE 0x00010000 /* 10G E */
69 #define HBA_PORTSPEED_40GE 0x00020000 /* 40G E */
70 #define HBA_PORTSPEED_100GE 0x00040000 /* 100G E */
71 #define HBA_PORTSPEED_25GE 0x00080000 /* 25G E */
72 #define HBA_PORTSPEED_50GE 0x00100000 /* 50G E */
73 #define HBA_PORTSPEED_400GE 0x00200000 /* 400G E */
78 static char *lpfc_release_version = LPFC_DRIVER_VERSION;
81 lpfc_ct_ignore_hbq_buffer(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq,
82 struct lpfc_dmabuf *mp, uint32_t size)
85 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
86 "0146 Ignoring unsolicited CT No HBQ "
88 piocbq->iocb.ulpStatus);
90 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
91 "0145 Ignoring unsolicted CT HBQ Size:%d "
93 size, piocbq->iocb.ulpStatus);
97 lpfc_ct_unsol_buffer(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq,
98 struct lpfc_dmabuf *mp, uint32_t size)
100 lpfc_ct_ignore_hbq_buffer(phba, piocbq, mp, size);
104 lpfc_ct_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
105 struct lpfc_iocbq *piocbq)
107 struct lpfc_dmabuf *mp = NULL;
108 IOCB_t *icmd = &piocbq->iocb;
110 struct lpfc_iocbq *iocbq;
113 struct list_head head;
114 struct lpfc_dmabuf *bdeBuf;
116 if (lpfc_bsg_ct_unsol_event(phba, pring, piocbq) == 0)
119 if (unlikely(icmd->ulpStatus == IOSTAT_NEED_BUFFER)) {
120 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
121 } else if ((icmd->ulpStatus == IOSTAT_LOCAL_REJECT) &&
122 ((icmd->un.ulpWord[4] & IOERR_PARAM_MASK) ==
123 IOERR_RCV_BUFFER_WAITING)) {
124 /* Not enough posted buffers; Try posting more buffers */
125 phba->fc_stat.NoRcvBuf++;
126 if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
127 lpfc_post_buffer(phba, pring, 2);
131 /* If there are no BDEs associated with this IOCB,
132 * there is nothing to do.
134 if (icmd->ulpBdeCount == 0)
137 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
138 INIT_LIST_HEAD(&head);
139 list_add_tail(&head, &piocbq->list);
140 list_for_each_entry(iocbq, &head, list) {
142 if (icmd->ulpBdeCount == 0)
144 bdeBuf = iocbq->context2;
145 iocbq->context2 = NULL;
146 size = icmd->un.cont64[0].tus.f.bdeSize;
147 lpfc_ct_unsol_buffer(phba, piocbq, bdeBuf, size);
148 lpfc_in_buf_free(phba, bdeBuf);
149 if (icmd->ulpBdeCount == 2) {
150 bdeBuf = iocbq->context3;
151 iocbq->context3 = NULL;
152 size = icmd->unsli3.rcvsli3.bde2.tus.f.bdeSize;
153 lpfc_ct_unsol_buffer(phba, piocbq, bdeBuf,
155 lpfc_in_buf_free(phba, bdeBuf);
160 INIT_LIST_HEAD(&head);
161 list_add_tail(&head, &piocbq->list);
162 list_for_each_entry(iocbq, &head, list) {
164 if (icmd->ulpBdeCount == 0)
165 lpfc_ct_unsol_buffer(phba, iocbq, NULL, 0);
166 for (i = 0; i < icmd->ulpBdeCount; i++) {
167 paddr = getPaddr(icmd->un.cont64[i].addrHigh,
168 icmd->un.cont64[i].addrLow);
169 mp = lpfc_sli_ringpostbuf_get(phba, pring,
171 size = icmd->un.cont64[i].tus.f.bdeSize;
172 lpfc_ct_unsol_buffer(phba, iocbq, mp, size);
173 lpfc_in_buf_free(phba, mp);
175 lpfc_post_buffer(phba, pring, i);
182 * lpfc_ct_handle_unsol_abort - ct upper level protocol abort handler
183 * @phba: Pointer to HBA context object.
184 * @dmabuf: pointer to a dmabuf that describes the FC sequence
186 * This function serves as the upper level protocol abort handler for CT
189 * Return 1 if abort has been handled, 0 otherwise.
192 lpfc_ct_handle_unsol_abort(struct lpfc_hba *phba, struct hbq_dmabuf *dmabuf)
196 /* CT upper level goes through BSG */
197 handled = lpfc_bsg_ct_unsol_abort(phba, dmabuf);
203 lpfc_free_ct_rsp(struct lpfc_hba *phba, struct lpfc_dmabuf *mlist)
205 struct lpfc_dmabuf *mlast, *next_mlast;
207 list_for_each_entry_safe(mlast, next_mlast, &mlist->list, list) {
208 lpfc_mbuf_free(phba, mlast->virt, mlast->phys);
209 list_del(&mlast->list);
212 lpfc_mbuf_free(phba, mlist->virt, mlist->phys);
217 static struct lpfc_dmabuf *
218 lpfc_alloc_ct_rsp(struct lpfc_hba *phba, int cmdcode, struct ulp_bde64 *bpl,
219 uint32_t size, int *entries)
221 struct lpfc_dmabuf *mlist = NULL;
222 struct lpfc_dmabuf *mp;
225 /* We get chunks of FCELSSIZE */
226 cnt = size > FCELSSIZE ? FCELSSIZE: size;
229 /* Allocate buffer for rsp payload */
230 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
233 lpfc_free_ct_rsp(phba, mlist);
237 INIT_LIST_HEAD(&mp->list);
239 if (cmdcode == be16_to_cpu(SLI_CTNS_GID_FT) ||
240 cmdcode == be16_to_cpu(SLI_CTNS_GFF_ID))
241 mp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(mp->phys));
243 mp->virt = lpfc_mbuf_alloc(phba, 0, &(mp->phys));
248 lpfc_free_ct_rsp(phba, mlist);
252 /* Queue it to a linked list */
256 list_add_tail(&mp->list, &mlist->list);
258 bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64I;
259 /* build buffer ptr list for IOCB */
260 bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys) );
261 bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys) );
262 bpl->tus.f.bdeSize = (uint16_t) cnt;
263 bpl->tus.w = le32_to_cpu(bpl->tus.w);
275 lpfc_ct_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *ctiocb)
277 struct lpfc_dmabuf *buf_ptr;
279 if (ctiocb->context_un.ndlp) {
280 lpfc_nlp_put(ctiocb->context_un.ndlp);
281 ctiocb->context_un.ndlp = NULL;
283 if (ctiocb->context1) {
284 buf_ptr = (struct lpfc_dmabuf *) ctiocb->context1;
285 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
287 ctiocb->context1 = NULL;
289 if (ctiocb->context2) {
290 lpfc_free_ct_rsp(phba, (struct lpfc_dmabuf *) ctiocb->context2);
291 ctiocb->context2 = NULL;
294 if (ctiocb->context3) {
295 buf_ptr = (struct lpfc_dmabuf *) ctiocb->context3;
296 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
298 ctiocb->context3 = NULL;
300 lpfc_sli_release_iocbq(phba, ctiocb);
305 * lpfc_gen_req - Build and issue a GEN_REQUEST command to the SLI Layer
306 * @vport: pointer to a host virtual N_Port data structure.
307 * @bmp: Pointer to BPL for SLI command
308 * @inp: Pointer to data buffer for response data.
309 * @outp: Pointer to data buffer that hold the CT command.
310 * @cmpl: completion routine to call when command completes
311 * @ndlp: Destination NPort nodelist entry
313 * This function as the final part for issuing a CT command.
316 lpfc_gen_req(struct lpfc_vport *vport, struct lpfc_dmabuf *bmp,
317 struct lpfc_dmabuf *inp, struct lpfc_dmabuf *outp,
318 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
319 struct lpfc_iocbq *),
320 struct lpfc_nodelist *ndlp, uint32_t usr_flg, uint32_t num_entry,
321 uint32_t tmo, uint8_t retry)
323 struct lpfc_hba *phba = vport->phba;
325 struct lpfc_iocbq *geniocb;
328 /* Allocate buffer for command iocb */
329 geniocb = lpfc_sli_get_iocbq(phba);
334 icmd = &geniocb->iocb;
335 icmd->un.genreq64.bdl.ulpIoTag32 = 0;
336 icmd->un.genreq64.bdl.addrHigh = putPaddrHigh(bmp->phys);
337 icmd->un.genreq64.bdl.addrLow = putPaddrLow(bmp->phys);
338 icmd->un.genreq64.bdl.bdeFlags = BUFF_TYPE_BLP_64;
339 icmd->un.genreq64.bdl.bdeSize = (num_entry * sizeof(struct ulp_bde64));
342 geniocb->context3 = NULL;
344 geniocb->context3 = (uint8_t *) bmp;
346 /* Save for completion so we can release these resources */
347 geniocb->context1 = (uint8_t *) inp;
348 geniocb->context2 = (uint8_t *) outp;
349 geniocb->context_un.ndlp = lpfc_nlp_get(ndlp);
351 /* Fill in payload, bp points to frame payload */
352 icmd->ulpCommand = CMD_GEN_REQUEST64_CR;
354 /* Fill in rest of iocb */
355 icmd->un.genreq64.w5.hcsw.Fctl = (SI | LA);
356 icmd->un.genreq64.w5.hcsw.Dfctl = 0;
357 icmd->un.genreq64.w5.hcsw.Rctl = FC_RCTL_DD_UNSOL_CTL;
358 icmd->un.genreq64.w5.hcsw.Type = FC_TYPE_CT;
361 /* FC spec states we need 3 * ratov for CT requests */
362 tmo = (3 * phba->fc_ratov);
364 icmd->ulpTimeout = tmo;
365 icmd->ulpBdeCount = 1;
367 icmd->ulpClass = CLASS3;
368 icmd->ulpContext = ndlp->nlp_rpi;
369 if (phba->sli_rev == LPFC_SLI_REV4)
370 icmd->ulpContext = phba->sli4_hba.rpi_ids[ndlp->nlp_rpi];
372 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
373 /* For GEN_REQUEST64_CR, use the RPI */
378 /* Issue GEN REQ IOCB for NPORT <did> */
379 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
380 "0119 Issue GEN REQ IOCB to NPORT x%x "
382 ndlp->nlp_DID, icmd->ulpIoTag,
384 geniocb->iocb_cmpl = cmpl;
385 geniocb->drvrTimeout = icmd->ulpTimeout + LPFC_DRVR_TIMEOUT;
386 geniocb->vport = vport;
387 geniocb->retry = retry;
388 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, geniocb, 0);
390 if (rc == IOCB_ERROR) {
391 lpfc_sli_release_iocbq(phba, geniocb);
399 * lpfc_ct_cmd - Build and issue a CT command
400 * @vport: pointer to a host virtual N_Port data structure.
401 * @inmp: Pointer to data buffer for response data.
402 * @bmp: Pointer to BPL for SLI command
403 * @ndlp: Destination NPort nodelist entry
404 * @cmpl: completion routine to call when command completes
406 * This function is called for issuing a CT command.
409 lpfc_ct_cmd(struct lpfc_vport *vport, struct lpfc_dmabuf *inmp,
410 struct lpfc_dmabuf *bmp, struct lpfc_nodelist *ndlp,
411 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
412 struct lpfc_iocbq *),
413 uint32_t rsp_size, uint8_t retry)
415 struct lpfc_hba *phba = vport->phba;
416 struct ulp_bde64 *bpl = (struct ulp_bde64 *) bmp->virt;
417 struct lpfc_dmabuf *outmp;
419 int cmdcode = ((struct lpfc_sli_ct_request *) inmp->virt)->
420 CommandResponse.bits.CmdRsp;
422 bpl++; /* Skip past ct request */
424 /* Put buffer(s) for ct rsp in bpl */
425 outmp = lpfc_alloc_ct_rsp(phba, cmdcode, bpl, rsp_size, &cnt);
429 * Form the CT IOCB. The total number of BDEs in this IOCB
430 * is the single command plus response count from
434 status = lpfc_gen_req(vport, bmp, inmp, outmp, cmpl, ndlp, 0,
437 lpfc_free_ct_rsp(phba, outmp);
444 lpfc_find_vport_by_did(struct lpfc_hba *phba, uint32_t did) {
445 struct lpfc_vport *vport_curr;
448 spin_lock_irqsave(&phba->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 * 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);
689 spin_lock_irq(shost->host_lock);
690 if (vport->fc_flag & FC_RSCN_DEFERRED) {
691 vport->fc_flag &= ~FC_RSCN_DEFERRED;
692 spin_unlock_irq(shost->host_lock);
694 /* This is a GID_FT completing so the gidft_inp counter was
695 * incremented before the GID_FT was issued to the wire.
700 * Skip processing the NS response
701 * Re-issue the NS cmd
703 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
704 "0151 Process Deferred RSCN Data: x%x x%x\n",
705 vport->fc_flag, vport->fc_rscn_id_cnt);
706 lpfc_els_handle_rscn(vport);
710 spin_unlock_irq(shost->host_lock);
712 if (irsp->ulpStatus) {
713 /* Check for retry */
714 if (vport->fc_ns_retry < LPFC_MAX_NS_RETRY) {
715 if (irsp->ulpStatus != IOSTAT_LOCAL_REJECT ||
716 (irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
718 vport->fc_ns_retry++;
720 type = lpfc_get_gidft_type(vport, cmdiocb);
724 /* CT command is being retried */
726 rc = lpfc_ns_cmd(vport, SLI_CTNS_GID_FT,
727 vport->fc_ns_retry, type);
731 if (vport->fc_flag & FC_RSCN_MODE)
732 lpfc_els_flush_rscn(vport);
733 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
734 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
735 "0257 GID_FT Query error: 0x%x 0x%x\n",
736 irsp->ulpStatus, vport->fc_ns_retry);
738 /* Good status, continue checking */
739 CTreq = (struct lpfc_sli_ct_request *) inp->virt;
740 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
741 if (CTrsp->CommandResponse.bits.CmdRsp ==
742 cpu_to_be16(SLI_CT_RESPONSE_FS_ACC)) {
743 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
744 "0208 NameServer Rsp Data: x%x x%x\n",
746 CTreq->un.gid.Fc4Type);
750 CTreq->un.gid.Fc4Type,
751 (uint32_t) (irsp->un.genreq64.bdl.bdeSize));
752 } else if (CTrsp->CommandResponse.bits.CmdRsp ==
753 be16_to_cpu(SLI_CT_RESPONSE_FS_RJT)) {
754 /* NameServer Rsp Error */
755 if ((CTrsp->ReasonCode == SLI_CT_UNABLE_TO_PERFORM_REQ)
756 && (CTrsp->Explanation == SLI_CT_NO_FC4_TYPES)) {
757 lpfc_printf_vlog(vport, KERN_INFO,
759 "0269 No NameServer Entries "
760 "Data: x%x x%x x%x x%x\n",
761 CTrsp->CommandResponse.bits.CmdRsp,
762 (uint32_t) CTrsp->ReasonCode,
763 (uint32_t) CTrsp->Explanation,
766 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
767 "GID_FT no entry cmd:x%x rsn:x%x exp:x%x",
768 (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
769 (uint32_t) CTrsp->ReasonCode,
770 (uint32_t) CTrsp->Explanation);
772 lpfc_printf_vlog(vport, KERN_INFO,
774 "0240 NameServer Rsp Error "
775 "Data: x%x x%x x%x x%x\n",
776 CTrsp->CommandResponse.bits.CmdRsp,
777 (uint32_t) CTrsp->ReasonCode,
778 (uint32_t) CTrsp->Explanation,
781 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
782 "GID_FT rsp err1 cmd:x%x rsn:x%x exp:x%x",
783 (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
784 (uint32_t) CTrsp->ReasonCode,
785 (uint32_t) CTrsp->Explanation);
790 /* NameServer Rsp Error */
791 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
792 "0241 NameServer Rsp Error "
793 "Data: x%x x%x x%x x%x\n",
794 CTrsp->CommandResponse.bits.CmdRsp,
795 (uint32_t) CTrsp->ReasonCode,
796 (uint32_t) CTrsp->Explanation,
799 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
800 "GID_FT rsp err2 cmd:x%x rsn:x%x exp:x%x",
801 (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
802 (uint32_t) CTrsp->ReasonCode,
803 (uint32_t) CTrsp->Explanation);
807 /* Link up / RSCN discovery */
808 if ((vport->num_disc_nodes == 0) &&
809 (vport->gidft_inp == 0)) {
811 * The driver has cycled through all Nports in the RSCN payload.
812 * Complete the handling by cleaning up and marking the
813 * current driver state.
815 if (vport->port_state >= LPFC_DISC_AUTH) {
816 if (vport->fc_flag & FC_RSCN_MODE) {
817 lpfc_els_flush_rscn(vport);
818 spin_lock_irq(shost->host_lock);
819 vport->fc_flag |= FC_RSCN_MODE; /* RSCN still */
820 spin_unlock_irq(shost->host_lock);
823 lpfc_els_flush_rscn(vport);
826 lpfc_disc_start(vport);
829 cmdiocb->context_un.ndlp = ndlp; /* Now restore ndlp for free */
830 lpfc_ct_free_iocb(phba, cmdiocb);
835 lpfc_cmpl_ct_cmd_gid_pt(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
836 struct lpfc_iocbq *rspiocb)
838 struct lpfc_vport *vport = cmdiocb->vport;
839 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
841 struct lpfc_dmabuf *outp;
842 struct lpfc_dmabuf *inp;
843 struct lpfc_sli_ct_request *CTrsp;
844 struct lpfc_sli_ct_request *CTreq;
845 struct lpfc_nodelist *ndlp;
848 /* First save ndlp, before we overwrite it */
849 ndlp = cmdiocb->context_un.ndlp;
851 /* we pass cmdiocb to state machine which needs rspiocb as well */
852 cmdiocb->context_un.rsp_iocb = rspiocb;
853 inp = (struct lpfc_dmabuf *)cmdiocb->context1;
854 outp = (struct lpfc_dmabuf *)cmdiocb->context2;
855 irsp = &rspiocb->iocb;
857 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
858 "GID_PT cmpl: status:x%x/x%x rtry:%d",
859 irsp->ulpStatus, irsp->un.ulpWord[4],
862 /* Don't bother processing response if vport is being torn down. */
863 if (vport->load_flag & FC_UNLOADING) {
864 if (vport->fc_flag & FC_RSCN_MODE)
865 lpfc_els_flush_rscn(vport);
869 if (lpfc_els_chk_latt(vport)) {
870 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
871 "4108 Link event during NS query\n");
872 if (vport->fc_flag & FC_RSCN_MODE)
873 lpfc_els_flush_rscn(vport);
874 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
877 if (lpfc_error_lost_link(irsp)) {
878 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
879 "4101 NS query failed due to link event\n");
880 if (vport->fc_flag & FC_RSCN_MODE)
881 lpfc_els_flush_rscn(vport);
885 spin_lock_irq(shost->host_lock);
886 if (vport->fc_flag & FC_RSCN_DEFERRED) {
887 vport->fc_flag &= ~FC_RSCN_DEFERRED;
888 spin_unlock_irq(shost->host_lock);
890 /* This is a GID_PT completing so the gidft_inp counter was
891 * incremented before the GID_PT was issued to the wire.
896 * Skip processing the NS response
897 * Re-issue the NS cmd
899 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
900 "4102 Process Deferred RSCN Data: x%x x%x\n",
901 vport->fc_flag, vport->fc_rscn_id_cnt);
902 lpfc_els_handle_rscn(vport);
906 spin_unlock_irq(shost->host_lock);
908 if (irsp->ulpStatus) {
909 /* Check for retry */
910 if (vport->fc_ns_retry < LPFC_MAX_NS_RETRY) {
911 if (irsp->ulpStatus != IOSTAT_LOCAL_REJECT ||
912 (irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
914 vport->fc_ns_retry++;
916 /* CT command is being retried */
918 rc = lpfc_ns_cmd(vport, SLI_CTNS_GID_PT,
919 vport->fc_ns_retry, GID_PT_N_PORT);
923 if (vport->fc_flag & FC_RSCN_MODE)
924 lpfc_els_flush_rscn(vport);
925 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
926 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
927 "4103 GID_FT Query error: 0x%x 0x%x\n",
928 irsp->ulpStatus, vport->fc_ns_retry);
930 /* Good status, continue checking */
931 CTreq = (struct lpfc_sli_ct_request *)inp->virt;
932 CTrsp = (struct lpfc_sli_ct_request *)outp->virt;
933 if (CTrsp->CommandResponse.bits.CmdRsp ==
934 cpu_to_be16(SLI_CT_RESPONSE_FS_ACC)) {
935 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
936 "4105 NameServer Rsp Data: x%x x%x\n",
938 CTreq->un.gid.Fc4Type);
942 CTreq->un.gid.Fc4Type,
943 (uint32_t)(irsp->un.genreq64.bdl.bdeSize));
944 } else if (CTrsp->CommandResponse.bits.CmdRsp ==
945 be16_to_cpu(SLI_CT_RESPONSE_FS_RJT)) {
946 /* NameServer Rsp Error */
947 if ((CTrsp->ReasonCode == SLI_CT_UNABLE_TO_PERFORM_REQ)
948 && (CTrsp->Explanation == SLI_CT_NO_FC4_TYPES)) {
950 vport, KERN_INFO, LOG_DISCOVERY,
951 "4106 No NameServer Entries "
952 "Data: x%x x%x x%x x%x\n",
953 CTrsp->CommandResponse.bits.CmdRsp,
954 (uint32_t)CTrsp->ReasonCode,
955 (uint32_t)CTrsp->Explanation,
958 lpfc_debugfs_disc_trc(
959 vport, LPFC_DISC_TRC_CT,
960 "GID_PT no entry cmd:x%x rsn:x%x exp:x%x",
961 (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
962 (uint32_t)CTrsp->ReasonCode,
963 (uint32_t)CTrsp->Explanation);
966 vport, KERN_INFO, LOG_DISCOVERY,
967 "4107 NameServer Rsp Error "
968 "Data: x%x x%x x%x x%x\n",
969 CTrsp->CommandResponse.bits.CmdRsp,
970 (uint32_t)CTrsp->ReasonCode,
971 (uint32_t)CTrsp->Explanation,
974 lpfc_debugfs_disc_trc(
975 vport, LPFC_DISC_TRC_CT,
976 "GID_PT rsp err1 cmd:x%x rsn:x%x exp:x%x",
977 (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
978 (uint32_t)CTrsp->ReasonCode,
979 (uint32_t)CTrsp->Explanation);
982 /* NameServer Rsp Error */
983 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
984 "4109 NameServer Rsp Error "
985 "Data: x%x x%x x%x x%x\n",
986 CTrsp->CommandResponse.bits.CmdRsp,
987 (uint32_t)CTrsp->ReasonCode,
988 (uint32_t)CTrsp->Explanation,
991 lpfc_debugfs_disc_trc(
992 vport, LPFC_DISC_TRC_CT,
993 "GID_PT rsp err2 cmd:x%x rsn:x%x exp:x%x",
994 (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
995 (uint32_t)CTrsp->ReasonCode,
996 (uint32_t)CTrsp->Explanation);
1000 /* Link up / RSCN discovery */
1001 if ((vport->num_disc_nodes == 0) &&
1002 (vport->gidft_inp == 0)) {
1004 * The driver has cycled through all Nports in the RSCN payload.
1005 * Complete the handling by cleaning up and marking the
1006 * current driver state.
1008 if (vport->port_state >= LPFC_DISC_AUTH) {
1009 if (vport->fc_flag & FC_RSCN_MODE) {
1010 lpfc_els_flush_rscn(vport);
1011 spin_lock_irq(shost->host_lock);
1012 vport->fc_flag |= FC_RSCN_MODE; /* RSCN still */
1013 spin_unlock_irq(shost->host_lock);
1015 lpfc_els_flush_rscn(vport);
1019 lpfc_disc_start(vport);
1022 cmdiocb->context_un.ndlp = ndlp; /* Now restore ndlp for free */
1023 lpfc_ct_free_iocb(phba, cmdiocb);
1027 lpfc_cmpl_ct_cmd_gff_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1028 struct lpfc_iocbq *rspiocb)
1030 struct lpfc_vport *vport = cmdiocb->vport;
1031 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1032 IOCB_t *irsp = &rspiocb->iocb;
1033 struct lpfc_dmabuf *inp = (struct lpfc_dmabuf *) cmdiocb->context1;
1034 struct lpfc_dmabuf *outp = (struct lpfc_dmabuf *) cmdiocb->context2;
1035 struct lpfc_sli_ct_request *CTrsp;
1038 struct lpfc_nodelist *ndlp;
1040 did = ((struct lpfc_sli_ct_request *) inp->virt)->un.gff.PortId;
1041 did = be32_to_cpu(did);
1043 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
1044 "GFF_ID cmpl: status:x%x/x%x did:x%x",
1045 irsp->ulpStatus, irsp->un.ulpWord[4], did);
1047 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
1048 /* Good status, continue checking */
1049 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
1050 fbits = CTrsp->un.gff_acc.fbits[FCP_TYPE_FEATURE_OFFSET];
1052 if (CTrsp->CommandResponse.bits.CmdRsp ==
1053 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC)) {
1054 if ((fbits & FC4_FEATURE_INIT) &&
1055 !(fbits & FC4_FEATURE_TARGET)) {
1056 lpfc_printf_vlog(vport, KERN_INFO,
1058 "0270 Skip x%x GFF "
1059 "NameServer Rsp Data: (init) "
1060 "x%x x%x\n", did, fbits,
1061 vport->fc_rscn_id_cnt);
1067 /* Check for retry */
1068 if (cmdiocb->retry < LPFC_MAX_NS_RETRY) {
1070 if (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) {
1071 switch ((irsp->un.ulpWord[4] &
1072 IOERR_PARAM_MASK)) {
1074 case IOERR_NO_RESOURCES:
1075 /* We don't increment the retry
1076 * count for this case.
1079 case IOERR_LINK_DOWN:
1080 case IOERR_SLI_ABORTED:
1081 case IOERR_SLI_DOWN:
1092 /* CT command is being retried */
1093 rc = lpfc_ns_cmd(vport, SLI_CTNS_GFF_ID,
1094 cmdiocb->retry, did);
1097 lpfc_ct_free_iocb(phba, cmdiocb);
1102 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
1103 "0267 NameServer GFF Rsp "
1104 "x%x Error (%d %d) Data: x%x x%x\n",
1105 did, irsp->ulpStatus, irsp->un.ulpWord[4],
1106 vport->fc_flag, vport->fc_rscn_id_cnt);
1109 /* This is a target port, unregistered port, or the GFF_ID failed */
1110 ndlp = lpfc_setup_disc_node(vport, did);
1111 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
1112 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1113 "0242 Process x%x GFF "
1114 "NameServer Rsp Data: x%x x%x x%x\n",
1115 did, ndlp->nlp_flag, vport->fc_flag,
1116 vport->fc_rscn_id_cnt);
1118 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1119 "0243 Skip x%x GFF "
1120 "NameServer Rsp Data: x%x x%x\n", did,
1121 vport->fc_flag, vport->fc_rscn_id_cnt);
1124 /* Link up / RSCN discovery */
1125 if (vport->num_disc_nodes)
1126 vport->num_disc_nodes--;
1127 if (vport->num_disc_nodes == 0) {
1129 * The driver has cycled through all Nports in the RSCN payload.
1130 * Complete the handling by cleaning up and marking the
1131 * current driver state.
1133 if (vport->port_state >= LPFC_DISC_AUTH) {
1134 if (vport->fc_flag & FC_RSCN_MODE) {
1135 lpfc_els_flush_rscn(vport);
1136 spin_lock_irq(shost->host_lock);
1137 vport->fc_flag |= FC_RSCN_MODE; /* RSCN still */
1138 spin_unlock_irq(shost->host_lock);
1141 lpfc_els_flush_rscn(vport);
1143 lpfc_disc_start(vport);
1145 lpfc_ct_free_iocb(phba, cmdiocb);
1150 lpfc_cmpl_ct_cmd_gft_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1151 struct lpfc_iocbq *rspiocb)
1153 struct lpfc_vport *vport = cmdiocb->vport;
1154 IOCB_t *irsp = &rspiocb->iocb;
1155 struct lpfc_dmabuf *inp = (struct lpfc_dmabuf *)cmdiocb->context1;
1156 struct lpfc_dmabuf *outp = (struct lpfc_dmabuf *)cmdiocb->context2;
1157 struct lpfc_sli_ct_request *CTrsp;
1159 struct lpfc_nodelist *ndlp;
1160 uint32_t fc4_data_0, fc4_data_1;
1162 did = ((struct lpfc_sli_ct_request *)inp->virt)->un.gft.PortId;
1163 did = be32_to_cpu(did);
1165 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
1166 "GFT_ID cmpl: status:x%x/x%x did:x%x",
1167 irsp->ulpStatus, irsp->un.ulpWord[4], did);
1169 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
1170 /* Good status, continue checking */
1171 CTrsp = (struct lpfc_sli_ct_request *)outp->virt;
1172 fc4_data_0 = be32_to_cpu(CTrsp->un.gft_acc.fc4_types[0]);
1173 fc4_data_1 = be32_to_cpu(CTrsp->un.gft_acc.fc4_types[1]);
1174 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1175 "3062 DID x%06x GFT Wd0 x%08x Wd1 x%08x\n",
1176 did, fc4_data_0, fc4_data_1);
1178 ndlp = lpfc_findnode_did(vport, did);
1180 /* The bitmask value for FCP and NVME FCP types is
1181 * the same because they are 32 bits distant from
1182 * each other in word0 and word0.
1184 if (fc4_data_0 & LPFC_FC4_TYPE_BITMASK)
1185 ndlp->nlp_fc4_type |= NLP_FC4_FCP;
1186 if (fc4_data_1 & LPFC_FC4_TYPE_BITMASK)
1187 ndlp->nlp_fc4_type |= NLP_FC4_NVME;
1188 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1189 "3064 Setting ndlp %p, DID x%06x with "
1190 "FC4 x%08x, Data: x%08x x%08x\n",
1191 ndlp, did, ndlp->nlp_fc4_type,
1192 FC_TYPE_FCP, FC_TYPE_NVME);
1193 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1195 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
1196 lpfc_issue_els_prli(vport, ndlp, 0);
1199 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
1200 "3065 GFT_ID failed x%08x\n", irsp->ulpStatus);
1202 lpfc_ct_free_iocb(phba, cmdiocb);
1206 lpfc_cmpl_ct(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1207 struct lpfc_iocbq *rspiocb)
1209 struct lpfc_vport *vport = cmdiocb->vport;
1210 struct lpfc_dmabuf *inp;
1211 struct lpfc_dmabuf *outp;
1213 struct lpfc_sli_ct_request *CTrsp;
1214 struct lpfc_nodelist *ndlp;
1219 /* First save ndlp, before we overwrite it */
1220 ndlp = cmdiocb->context_un.ndlp;
1222 /* we pass cmdiocb to state machine which needs rspiocb as well */
1223 cmdiocb->context_un.rsp_iocb = rspiocb;
1225 inp = (struct lpfc_dmabuf *) cmdiocb->context1;
1226 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
1227 irsp = &rspiocb->iocb;
1229 cmdcode = be16_to_cpu(((struct lpfc_sli_ct_request *) inp->virt)->
1230 CommandResponse.bits.CmdRsp);
1231 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
1233 latt = lpfc_els_chk_latt(vport);
1235 /* RFT request completes status <ulpStatus> CmdRsp <CmdRsp> */
1236 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1237 "0209 CT Request completes, latt %d, "
1238 "ulpStatus x%x CmdRsp x%x, Context x%x, Tag x%x\n",
1239 latt, irsp->ulpStatus,
1240 CTrsp->CommandResponse.bits.CmdRsp,
1241 cmdiocb->iocb.ulpContext, cmdiocb->iocb.ulpIoTag);
1243 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
1244 "CT cmd cmpl: status:x%x/x%x cmd:x%x",
1245 irsp->ulpStatus, irsp->un.ulpWord[4], cmdcode);
1247 if (irsp->ulpStatus) {
1248 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
1249 "0268 NS cmd x%x Error (x%x x%x)\n",
1250 cmdcode, irsp->ulpStatus, irsp->un.ulpWord[4]);
1252 if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
1253 (((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
1255 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
1256 IOERR_SLI_ABORTED)))
1259 retry = cmdiocb->retry;
1260 if (retry >= LPFC_MAX_NS_RETRY)
1264 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1265 "0250 Retrying NS cmd %x\n", cmdcode);
1266 rc = lpfc_ns_cmd(vport, cmdcode, retry, 0);
1272 cmdiocb->context_un.ndlp = ndlp; /* Now restore ndlp for free */
1273 lpfc_ct_free_iocb(phba, cmdiocb);
1278 lpfc_cmpl_ct_cmd_rft_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1279 struct lpfc_iocbq *rspiocb)
1281 IOCB_t *irsp = &rspiocb->iocb;
1282 struct lpfc_vport *vport = cmdiocb->vport;
1284 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
1285 struct lpfc_dmabuf *outp;
1286 struct lpfc_sli_ct_request *CTrsp;
1288 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
1289 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
1290 if (CTrsp->CommandResponse.bits.CmdRsp ==
1291 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
1292 vport->ct_flags |= FC_CT_RFT_ID;
1294 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
1299 lpfc_cmpl_ct_cmd_rnn_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1300 struct lpfc_iocbq *rspiocb)
1302 IOCB_t *irsp = &rspiocb->iocb;
1303 struct lpfc_vport *vport = cmdiocb->vport;
1305 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
1306 struct lpfc_dmabuf *outp;
1307 struct lpfc_sli_ct_request *CTrsp;
1309 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
1310 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
1311 if (CTrsp->CommandResponse.bits.CmdRsp ==
1312 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
1313 vport->ct_flags |= FC_CT_RNN_ID;
1315 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
1320 lpfc_cmpl_ct_cmd_rspn_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1321 struct lpfc_iocbq *rspiocb)
1323 IOCB_t *irsp = &rspiocb->iocb;
1324 struct lpfc_vport *vport = cmdiocb->vport;
1326 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
1327 struct lpfc_dmabuf *outp;
1328 struct lpfc_sli_ct_request *CTrsp;
1330 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
1331 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
1332 if (CTrsp->CommandResponse.bits.CmdRsp ==
1333 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
1334 vport->ct_flags |= FC_CT_RSPN_ID;
1336 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
1341 lpfc_cmpl_ct_cmd_rsnn_nn(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1342 struct lpfc_iocbq *rspiocb)
1344 IOCB_t *irsp = &rspiocb->iocb;
1345 struct lpfc_vport *vport = cmdiocb->vport;
1347 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
1348 struct lpfc_dmabuf *outp;
1349 struct lpfc_sli_ct_request *CTrsp;
1351 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
1352 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
1353 if (CTrsp->CommandResponse.bits.CmdRsp ==
1354 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
1355 vport->ct_flags |= FC_CT_RSNN_NN;
1357 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
1362 lpfc_cmpl_ct_cmd_da_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1363 struct lpfc_iocbq *rspiocb)
1365 struct lpfc_vport *vport = cmdiocb->vport;
1367 /* even if it fails we will act as though it succeeded. */
1368 vport->ct_flags = 0;
1369 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
1374 lpfc_cmpl_ct_cmd_rff_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1375 struct lpfc_iocbq *rspiocb)
1377 IOCB_t *irsp = &rspiocb->iocb;
1378 struct lpfc_vport *vport = cmdiocb->vport;
1380 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
1381 struct lpfc_dmabuf *outp;
1382 struct lpfc_sli_ct_request *CTrsp;
1384 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
1385 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
1386 if (CTrsp->CommandResponse.bits.CmdRsp ==
1387 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
1388 vport->ct_flags |= FC_CT_RFF_ID;
1390 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
1395 * Although the symbolic port name is thought to be an integer
1396 * as of January 18, 2016, leave it as a string until more of
1397 * the record state becomes defined.
1400 lpfc_vport_symbolic_port_name(struct lpfc_vport *vport, char *symbol,
1406 * Use the lpfc board number as the Symbolic Port
1407 * Name object. NPIV is not in play so this integer
1408 * value is sufficient and unique per FC-ID.
1410 n = snprintf(symbol, size, "%d", vport->phba->brd_no);
1416 lpfc_vport_symbolic_node_name(struct lpfc_vport *vport, char *symbol,
1419 char fwrev[FW_REV_STR_SIZE];
1422 lpfc_decode_firmware_rev(vport->phba, fwrev, 0);
1424 n = snprintf(symbol, size, "Emulex %s", vport->phba->ModelName);
1428 n += snprintf(symbol + n, size - n, " FV%s", fwrev);
1432 n += snprintf(symbol + n, size - n, " DV%s.",
1433 lpfc_release_version);
1437 n += snprintf(symbol + n, size - n, " HN:%s.",
1438 init_utsname()->nodename);
1442 /* Note :- OS name is "Linux" */
1443 n += snprintf(symbol + n, size - n, " OS:%s\n",
1444 init_utsname()->sysname);
1449 lpfc_find_map_node(struct lpfc_vport *vport)
1451 struct lpfc_nodelist *ndlp, *next_ndlp;
1452 struct Scsi_Host *shost;
1455 shost = lpfc_shost_from_vport(vport);
1456 spin_lock_irq(shost->host_lock);
1457 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
1458 if (ndlp->nlp_type & NLP_FABRIC)
1460 if ((ndlp->nlp_state == NLP_STE_MAPPED_NODE) ||
1461 (ndlp->nlp_state == NLP_STE_UNMAPPED_NODE))
1464 spin_unlock_irq(shost->host_lock);
1469 * This routine will return the FC4 Type associated with the CT
1473 lpfc_get_gidft_type(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb)
1475 struct lpfc_sli_ct_request *CtReq;
1476 struct lpfc_dmabuf *mp;
1479 mp = cmdiocb->context1;
1482 CtReq = (struct lpfc_sli_ct_request *)mp->virt;
1483 type = (uint32_t)CtReq->un.gid.Fc4Type;
1484 if ((type != SLI_CTPT_FCP) && (type != SLI_CTPT_NVME))
1492 * Issue Cmd to NameServer
1497 lpfc_ns_cmd(struct lpfc_vport *vport, int cmdcode,
1498 uint8_t retry, uint32_t context)
1500 struct lpfc_nodelist * ndlp;
1501 struct lpfc_hba *phba = vport->phba;
1502 struct lpfc_dmabuf *mp, *bmp;
1503 struct lpfc_sli_ct_request *CtReq;
1504 struct ulp_bde64 *bpl;
1505 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
1506 struct lpfc_iocbq *) = NULL;
1507 uint32_t rsp_size = 1024;
1511 ndlp = lpfc_findnode_did(vport, NameServer_DID);
1512 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)
1513 || ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) {
1518 /* fill in BDEs for command */
1519 /* Allocate buffer for command payload */
1520 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
1526 INIT_LIST_HEAD(&mp->list);
1527 mp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(mp->phys));
1530 goto ns_cmd_free_mp;
1533 /* Allocate buffer for Buffer ptr list */
1534 bmp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
1537 goto ns_cmd_free_mpvirt;
1540 INIT_LIST_HEAD(&bmp->list);
1541 bmp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(bmp->phys));
1544 goto ns_cmd_free_bmp;
1547 /* NameServer Req */
1548 lpfc_printf_vlog(vport, KERN_INFO ,LOG_DISCOVERY,
1549 "0236 NameServer Req Data: x%x x%x x%x x%x\n",
1550 cmdcode, vport->fc_flag, vport->fc_rscn_id_cnt,
1553 bpl = (struct ulp_bde64 *) bmp->virt;
1554 memset(bpl, 0, sizeof(struct ulp_bde64));
1555 bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys) );
1556 bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys) );
1557 bpl->tus.f.bdeFlags = 0;
1558 if (cmdcode == SLI_CTNS_GID_FT)
1559 bpl->tus.f.bdeSize = GID_REQUEST_SZ;
1560 else if (cmdcode == SLI_CTNS_GID_PT)
1561 bpl->tus.f.bdeSize = GID_REQUEST_SZ;
1562 else if (cmdcode == SLI_CTNS_GFF_ID)
1563 bpl->tus.f.bdeSize = GFF_REQUEST_SZ;
1564 else if (cmdcode == SLI_CTNS_GFT_ID)
1565 bpl->tus.f.bdeSize = GFT_REQUEST_SZ;
1566 else if (cmdcode == SLI_CTNS_RFT_ID)
1567 bpl->tus.f.bdeSize = RFT_REQUEST_SZ;
1568 else if (cmdcode == SLI_CTNS_RNN_ID)
1569 bpl->tus.f.bdeSize = RNN_REQUEST_SZ;
1570 else if (cmdcode == SLI_CTNS_RSPN_ID)
1571 bpl->tus.f.bdeSize = RSPN_REQUEST_SZ;
1572 else if (cmdcode == SLI_CTNS_RSNN_NN)
1573 bpl->tus.f.bdeSize = RSNN_REQUEST_SZ;
1574 else if (cmdcode == SLI_CTNS_DA_ID)
1575 bpl->tus.f.bdeSize = DA_ID_REQUEST_SZ;
1576 else if (cmdcode == SLI_CTNS_RFF_ID)
1577 bpl->tus.f.bdeSize = RFF_REQUEST_SZ;
1579 bpl->tus.f.bdeSize = 0;
1580 bpl->tus.w = le32_to_cpu(bpl->tus.w);
1582 CtReq = (struct lpfc_sli_ct_request *) mp->virt;
1583 memset(CtReq, 0, sizeof(struct lpfc_sli_ct_request));
1584 CtReq->RevisionId.bits.Revision = SLI_CT_REVISION;
1585 CtReq->RevisionId.bits.InId = 0;
1586 CtReq->FsType = SLI_CT_DIRECTORY_SERVICE;
1587 CtReq->FsSubType = SLI_CT_DIRECTORY_NAME_SERVER;
1588 CtReq->CommandResponse.bits.Size = 0;
1590 case SLI_CTNS_GID_FT:
1591 CtReq->CommandResponse.bits.CmdRsp =
1592 cpu_to_be16(SLI_CTNS_GID_FT);
1593 CtReq->un.gid.Fc4Type = context;
1595 if (vport->port_state < LPFC_NS_QRY)
1596 vport->port_state = LPFC_NS_QRY;
1597 lpfc_set_disctmo(vport);
1598 cmpl = lpfc_cmpl_ct_cmd_gid_ft;
1599 rsp_size = FC_MAX_NS_RSP;
1602 case SLI_CTNS_GID_PT:
1603 CtReq->CommandResponse.bits.CmdRsp =
1604 cpu_to_be16(SLI_CTNS_GID_PT);
1605 CtReq->un.gid.PortType = context;
1607 if (vport->port_state < LPFC_NS_QRY)
1608 vport->port_state = LPFC_NS_QRY;
1609 lpfc_set_disctmo(vport);
1610 cmpl = lpfc_cmpl_ct_cmd_gid_pt;
1611 rsp_size = FC_MAX_NS_RSP;
1614 case SLI_CTNS_GFF_ID:
1615 CtReq->CommandResponse.bits.CmdRsp =
1616 cpu_to_be16(SLI_CTNS_GFF_ID);
1617 CtReq->un.gff.PortId = cpu_to_be32(context);
1618 cmpl = lpfc_cmpl_ct_cmd_gff_id;
1621 case SLI_CTNS_GFT_ID:
1622 CtReq->CommandResponse.bits.CmdRsp =
1623 cpu_to_be16(SLI_CTNS_GFT_ID);
1624 CtReq->un.gft.PortId = cpu_to_be32(context);
1625 cmpl = lpfc_cmpl_ct_cmd_gft_id;
1628 case SLI_CTNS_RFT_ID:
1629 vport->ct_flags &= ~FC_CT_RFT_ID;
1630 CtReq->CommandResponse.bits.CmdRsp =
1631 cpu_to_be16(SLI_CTNS_RFT_ID);
1632 CtReq->un.rft.PortId = cpu_to_be32(vport->fc_myDID);
1634 /* Register FC4 FCP type if enabled. */
1635 if ((phba->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
1636 (phba->cfg_enable_fc4_type == LPFC_ENABLE_FCP))
1637 CtReq->un.rft.fcpReg = 1;
1639 /* Register NVME type if enabled. Defined LE and swapped.
1640 * rsvd[0] is used as word1 because of the hard-coded
1641 * word0 usage in the ct_request data structure.
1643 if ((phba->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
1644 (phba->cfg_enable_fc4_type == LPFC_ENABLE_NVME))
1645 CtReq->un.rft.rsvd[0] = cpu_to_be32(0x00000100);
1647 cmpl = lpfc_cmpl_ct_cmd_rft_id;
1650 case SLI_CTNS_RNN_ID:
1651 vport->ct_flags &= ~FC_CT_RNN_ID;
1652 CtReq->CommandResponse.bits.CmdRsp =
1653 cpu_to_be16(SLI_CTNS_RNN_ID);
1654 CtReq->un.rnn.PortId = cpu_to_be32(vport->fc_myDID);
1655 memcpy(CtReq->un.rnn.wwnn, &vport->fc_nodename,
1656 sizeof(struct lpfc_name));
1657 cmpl = lpfc_cmpl_ct_cmd_rnn_id;
1660 case SLI_CTNS_RSPN_ID:
1661 vport->ct_flags &= ~FC_CT_RSPN_ID;
1662 CtReq->CommandResponse.bits.CmdRsp =
1663 cpu_to_be16(SLI_CTNS_RSPN_ID);
1664 CtReq->un.rspn.PortId = cpu_to_be32(vport->fc_myDID);
1665 size = sizeof(CtReq->un.rspn.symbname);
1666 CtReq->un.rspn.len =
1667 lpfc_vport_symbolic_port_name(vport,
1668 CtReq->un.rspn.symbname, size);
1669 cmpl = lpfc_cmpl_ct_cmd_rspn_id;
1671 case SLI_CTNS_RSNN_NN:
1672 vport->ct_flags &= ~FC_CT_RSNN_NN;
1673 CtReq->CommandResponse.bits.CmdRsp =
1674 cpu_to_be16(SLI_CTNS_RSNN_NN);
1675 memcpy(CtReq->un.rsnn.wwnn, &vport->fc_nodename,
1676 sizeof(struct lpfc_name));
1677 size = sizeof(CtReq->un.rsnn.symbname);
1678 CtReq->un.rsnn.len =
1679 lpfc_vport_symbolic_node_name(vport,
1680 CtReq->un.rsnn.symbname, size);
1681 cmpl = lpfc_cmpl_ct_cmd_rsnn_nn;
1683 case SLI_CTNS_DA_ID:
1684 /* Implement DA_ID Nameserver request */
1685 CtReq->CommandResponse.bits.CmdRsp =
1686 cpu_to_be16(SLI_CTNS_DA_ID);
1687 CtReq->un.da_id.port_id = cpu_to_be32(vport->fc_myDID);
1688 cmpl = lpfc_cmpl_ct_cmd_da_id;
1690 case SLI_CTNS_RFF_ID:
1691 vport->ct_flags &= ~FC_CT_RFF_ID;
1692 CtReq->CommandResponse.bits.CmdRsp =
1693 cpu_to_be16(SLI_CTNS_RFF_ID);
1694 CtReq->un.rff.PortId = cpu_to_be32(vport->fc_myDID);
1695 CtReq->un.rff.fbits = FC4_FEATURE_INIT;
1697 /* The driver always supports FC_TYPE_FCP. However, the
1698 * caller can specify NVME (type x28) as well. But only
1699 * these that FC4 type is supported.
1701 if (((phba->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
1702 (phba->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) &&
1703 (context == FC_TYPE_NVME)) {
1704 if ((vport == phba->pport) && phba->nvmet_support) {
1705 CtReq->un.rff.fbits = (FC4_FEATURE_TARGET |
1706 FC4_FEATURE_NVME_DISC);
1707 lpfc_nvmet_update_targetport(phba);
1709 lpfc_nvme_update_localport(vport);
1711 CtReq->un.rff.type_code = context;
1713 } else if (((phba->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
1714 (phba->cfg_enable_fc4_type == LPFC_ENABLE_FCP)) &&
1715 (context == FC_TYPE_FCP))
1716 CtReq->un.rff.type_code = context;
1719 goto ns_cmd_free_bmpvirt;
1721 cmpl = lpfc_cmpl_ct_cmd_rff_id;
1724 /* The lpfc_ct_cmd/lpfc_get_req shall increment ndlp reference count
1725 * to hold ndlp reference for the corresponding callback function.
1727 if (!lpfc_ct_cmd(vport, mp, bmp, ndlp, cmpl, rsp_size, retry)) {
1728 /* On success, The cmpl function will free the buffers */
1729 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
1730 "Issue CT cmd: cmd:x%x did:x%x",
1731 cmdcode, ndlp->nlp_DID, 0);
1736 /* Decrement ndlp reference count to release ndlp reference held
1737 * for the failed command's callback function.
1741 ns_cmd_free_bmpvirt:
1742 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
1746 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1750 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
1751 "0266 Issue NameServer Req x%x err %d Data: x%x x%x\n",
1752 cmdcode, rc, vport->fc_flag, vport->fc_rscn_id_cnt);
1757 * lpfc_cmpl_ct_disc_fdmi - Handle a discovery FDMI completion
1758 * @phba: Pointer to HBA context object.
1759 * @cmdiocb: Pointer to the command IOCBQ.
1760 * @rspiocb: Pointer to the response IOCBQ.
1762 * This function to handle the completion of a driver initiated FDMI
1763 * CT command issued during discovery.
1766 lpfc_cmpl_ct_disc_fdmi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1767 struct lpfc_iocbq *rspiocb)
1769 struct lpfc_vport *vport = cmdiocb->vport;
1770 struct lpfc_dmabuf *inp = cmdiocb->context1;
1771 struct lpfc_dmabuf *outp = cmdiocb->context2;
1772 struct lpfc_sli_ct_request *CTcmd = inp->virt;
1773 struct lpfc_sli_ct_request *CTrsp = outp->virt;
1774 uint16_t fdmi_cmd = CTcmd->CommandResponse.bits.CmdRsp;
1775 uint16_t fdmi_rsp = CTrsp->CommandResponse.bits.CmdRsp;
1776 IOCB_t *irsp = &rspiocb->iocb;
1777 struct lpfc_nodelist *ndlp;
1778 uint32_t latt, cmd, err;
1780 latt = lpfc_els_chk_latt(vport);
1781 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
1782 "FDMI cmpl: status:x%x/x%x latt:%d",
1783 irsp->ulpStatus, irsp->un.ulpWord[4], latt);
1785 if (latt || irsp->ulpStatus) {
1787 /* Look for a retryable error */
1788 if (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) {
1789 switch ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK)) {
1790 case IOERR_SLI_ABORTED:
1791 case IOERR_ABORT_IN_PROGRESS:
1792 case IOERR_SEQUENCE_TIMEOUT:
1793 case IOERR_ILLEGAL_FRAME:
1794 case IOERR_NO_RESOURCES:
1795 case IOERR_ILLEGAL_COMMAND:
1797 if (cmdiocb->retry >= LPFC_FDMI_MAX_RETRY)
1800 /* Retry the same FDMI command */
1801 err = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING,
1803 if (err == IOCB_ERROR)
1811 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1812 "0229 FDMI cmd %04x failed, latt = %d "
1813 "ulpStatus: x%x, rid x%x\n",
1814 be16_to_cpu(fdmi_cmd), latt, irsp->ulpStatus,
1815 irsp->un.ulpWord[4]);
1817 lpfc_ct_free_iocb(phba, cmdiocb);
1819 ndlp = lpfc_findnode_did(vport, FDMI_DID);
1820 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
1823 /* Check for a CT LS_RJT response */
1824 cmd = be16_to_cpu(fdmi_cmd);
1825 if (fdmi_rsp == cpu_to_be16(SLI_CT_RESPONSE_FS_RJT)) {
1826 /* FDMI rsp failed */
1827 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1828 "0220 FDMI cmd failed FS_RJT Data: x%x", cmd);
1830 /* Should we fallback to FDMI-2 / FDMI-1 ? */
1833 if (vport->fdmi_hba_mask == LPFC_FDMI2_HBA_ATTR) {
1834 /* Fallback to FDMI-1 */
1835 vport->fdmi_hba_mask = LPFC_FDMI1_HBA_ATTR;
1836 vport->fdmi_port_mask = LPFC_FDMI1_PORT_ATTR;
1838 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA, 0);
1843 if (vport->fdmi_port_mask == LPFC_FDMI2_PORT_ATTR) {
1844 /* Fallback to FDMI-1 */
1845 vport->fdmi_port_mask = LPFC_FDMI1_PORT_ATTR;
1847 lpfc_fdmi_cmd(vport, ndlp, cmd, 0);
1849 if (vport->fdmi_port_mask == LPFC_FDMI2_SMART_ATTR) {
1850 vport->fdmi_port_mask = LPFC_FDMI2_PORT_ATTR;
1851 /* Retry the same command */
1852 lpfc_fdmi_cmd(vport, ndlp, cmd, 0);
1857 if (vport->fdmi_port_mask == LPFC_FDMI2_PORT_ATTR) {
1858 /* Fallback to FDMI-1 */
1859 vport->fdmi_hba_mask = LPFC_FDMI1_HBA_ATTR;
1860 vport->fdmi_port_mask = LPFC_FDMI1_PORT_ATTR;
1862 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA, 0);
1864 if (vport->fdmi_port_mask == LPFC_FDMI2_SMART_ATTR) {
1865 vport->fdmi_port_mask = LPFC_FDMI2_PORT_ATTR;
1866 /* Retry the same command */
1867 lpfc_fdmi_cmd(vport, ndlp, cmd, 0);
1874 * On success, need to cycle thru FDMI registration for discovery
1875 * DHBA -> DPRT -> RHBA -> RPA (physical port)
1876 * DPRT -> RPRT (vports)
1880 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RPA, 0);
1884 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DPRT, 0);
1888 if (vport->port_type == LPFC_PHYSICAL_PORT)
1889 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RHBA, 0);
1891 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RPRT, 0);
1899 * lpfc_fdmi_num_disc_check - Check how many mapped NPorts we are connected to
1900 * @vport: pointer to a host virtual N_Port data structure.
1902 * Called from hbeat timeout routine to check if the number of discovered
1903 * ports has changed. If so, re-register thar port Attribute.
1906 lpfc_fdmi_num_disc_check(struct lpfc_vport *vport)
1908 struct lpfc_hba *phba = vport->phba;
1909 struct lpfc_nodelist *ndlp;
1912 if (!lpfc_is_link_up(phba))
1915 /* Must be connected to a Fabric */
1916 if (!(vport->fc_flag & FC_FABRIC))
1919 if (!(vport->fdmi_port_mask & LPFC_FDMI_PORT_ATTR_num_disc))
1922 cnt = lpfc_find_map_node(vport);
1923 if (cnt == vport->fdmi_num_disc)
1926 ndlp = lpfc_findnode_did(vport, FDMI_DID);
1927 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
1930 if (vport->port_type == LPFC_PHYSICAL_PORT) {
1931 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RPA,
1932 LPFC_FDMI_PORT_ATTR_num_disc);
1934 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RPRT,
1935 LPFC_FDMI_PORT_ATTR_num_disc);
1939 /* Routines for all individual HBA attributes */
1941 lpfc_fdmi_hba_attr_wwnn(struct lpfc_vport *vport, struct lpfc_fdmi_attr_def *ad)
1943 struct lpfc_fdmi_attr_entry *ae;
1946 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
1947 memset(ae, 0, sizeof(struct lpfc_name));
1949 memcpy(&ae->un.AttrWWN, &vport->fc_sparam.nodeName,
1950 sizeof(struct lpfc_name));
1951 size = FOURBYTES + sizeof(struct lpfc_name);
1952 ad->AttrLen = cpu_to_be16(size);
1953 ad->AttrType = cpu_to_be16(RHBA_NODENAME);
1957 lpfc_fdmi_hba_attr_manufacturer(struct lpfc_vport *vport,
1958 struct lpfc_fdmi_attr_def *ad)
1960 struct lpfc_fdmi_attr_entry *ae;
1963 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
1966 strncpy(ae->un.AttrString,
1968 sizeof(ae->un.AttrString));
1969 len = strnlen(ae->un.AttrString,
1970 sizeof(ae->un.AttrString));
1971 len += (len & 3) ? (4 - (len & 3)) : 4;
1972 size = FOURBYTES + len;
1973 ad->AttrLen = cpu_to_be16(size);
1974 ad->AttrType = cpu_to_be16(RHBA_MANUFACTURER);
1979 lpfc_fdmi_hba_attr_sn(struct lpfc_vport *vport, struct lpfc_fdmi_attr_def *ad)
1981 struct lpfc_hba *phba = vport->phba;
1982 struct lpfc_fdmi_attr_entry *ae;
1985 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
1988 strncpy(ae->un.AttrString, phba->SerialNumber,
1989 sizeof(ae->un.AttrString));
1990 len = strnlen(ae->un.AttrString,
1991 sizeof(ae->un.AttrString));
1992 len += (len & 3) ? (4 - (len & 3)) : 4;
1993 size = FOURBYTES + len;
1994 ad->AttrLen = cpu_to_be16(size);
1995 ad->AttrType = cpu_to_be16(RHBA_SERIAL_NUMBER);
2000 lpfc_fdmi_hba_attr_model(struct lpfc_vport *vport,
2001 struct lpfc_fdmi_attr_def *ad)
2003 struct lpfc_hba *phba = vport->phba;
2004 struct lpfc_fdmi_attr_entry *ae;
2007 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2010 strncpy(ae->un.AttrString, phba->ModelName,
2011 sizeof(ae->un.AttrString));
2012 len = strnlen(ae->un.AttrString, sizeof(ae->un.AttrString));
2013 len += (len & 3) ? (4 - (len & 3)) : 4;
2014 size = FOURBYTES + len;
2015 ad->AttrLen = cpu_to_be16(size);
2016 ad->AttrType = cpu_to_be16(RHBA_MODEL);
2021 lpfc_fdmi_hba_attr_description(struct lpfc_vport *vport,
2022 struct lpfc_fdmi_attr_def *ad)
2024 struct lpfc_hba *phba = vport->phba;
2025 struct lpfc_fdmi_attr_entry *ae;
2028 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2031 strncpy(ae->un.AttrString, phba->ModelDesc,
2032 sizeof(ae->un.AttrString));
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_MODEL_DESCRIPTION);
2043 lpfc_fdmi_hba_attr_hdw_ver(struct lpfc_vport *vport,
2044 struct lpfc_fdmi_attr_def *ad)
2046 struct lpfc_hba *phba = vport->phba;
2047 lpfc_vpd_t *vp = &phba->vpd;
2048 struct lpfc_fdmi_attr_entry *ae;
2049 uint32_t i, j, incr, size;
2051 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2054 /* Convert JEDEC ID to ascii for hardware version */
2055 incr = vp->rev.biuRev;
2056 for (i = 0; i < 8; i++) {
2059 ae->un.AttrString[7 - i] =
2060 (char)((uint8_t) 0x30 +
2063 ae->un.AttrString[7 - i] =
2064 (char)((uint8_t) 0x61 +
2065 (uint8_t) (j - 10));
2068 size = FOURBYTES + 8;
2069 ad->AttrLen = cpu_to_be16(size);
2070 ad->AttrType = cpu_to_be16(RHBA_HARDWARE_VERSION);
2075 lpfc_fdmi_hba_attr_drvr_ver(struct lpfc_vport *vport,
2076 struct lpfc_fdmi_attr_def *ad)
2078 struct lpfc_fdmi_attr_entry *ae;
2081 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2084 strncpy(ae->un.AttrString, lpfc_release_version,
2085 sizeof(ae->un.AttrString));
2086 len = strnlen(ae->un.AttrString,
2087 sizeof(ae->un.AttrString));
2088 len += (len & 3) ? (4 - (len & 3)) : 4;
2089 size = FOURBYTES + len;
2090 ad->AttrLen = cpu_to_be16(size);
2091 ad->AttrType = cpu_to_be16(RHBA_DRIVER_VERSION);
2096 lpfc_fdmi_hba_attr_rom_ver(struct lpfc_vport *vport,
2097 struct lpfc_fdmi_attr_def *ad)
2099 struct lpfc_hba *phba = vport->phba;
2100 struct lpfc_fdmi_attr_entry *ae;
2103 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2106 if (phba->sli_rev == LPFC_SLI_REV4)
2107 lpfc_decode_firmware_rev(phba, ae->un.AttrString, 1);
2109 strncpy(ae->un.AttrString, phba->OptionROMVersion,
2110 sizeof(ae->un.AttrString));
2111 len = strnlen(ae->un.AttrString,
2112 sizeof(ae->un.AttrString));
2113 len += (len & 3) ? (4 - (len & 3)) : 4;
2114 size = FOURBYTES + len;
2115 ad->AttrLen = cpu_to_be16(size);
2116 ad->AttrType = cpu_to_be16(RHBA_OPTION_ROM_VERSION);
2121 lpfc_fdmi_hba_attr_fmw_ver(struct lpfc_vport *vport,
2122 struct lpfc_fdmi_attr_def *ad)
2124 struct lpfc_hba *phba = vport->phba;
2125 struct lpfc_fdmi_attr_entry *ae;
2128 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2131 lpfc_decode_firmware_rev(phba, ae->un.AttrString, 1);
2132 len = strnlen(ae->un.AttrString,
2133 sizeof(ae->un.AttrString));
2134 len += (len & 3) ? (4 - (len & 3)) : 4;
2135 size = FOURBYTES + len;
2136 ad->AttrLen = cpu_to_be16(size);
2137 ad->AttrType = cpu_to_be16(RHBA_FIRMWARE_VERSION);
2142 lpfc_fdmi_hba_attr_os_ver(struct lpfc_vport *vport,
2143 struct lpfc_fdmi_attr_def *ad)
2145 struct lpfc_fdmi_attr_entry *ae;
2148 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2151 snprintf(ae->un.AttrString, sizeof(ae->un.AttrString), "%s %s %s",
2152 init_utsname()->sysname,
2153 init_utsname()->release,
2154 init_utsname()->version);
2156 len = strnlen(ae->un.AttrString, sizeof(ae->un.AttrString));
2157 len += (len & 3) ? (4 - (len & 3)) : 4;
2158 size = FOURBYTES + len;
2159 ad->AttrLen = cpu_to_be16(size);
2160 ad->AttrType = cpu_to_be16(RHBA_OS_NAME_VERSION);
2165 lpfc_fdmi_hba_attr_ct_len(struct lpfc_vport *vport,
2166 struct lpfc_fdmi_attr_def *ad)
2168 struct lpfc_fdmi_attr_entry *ae;
2171 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2173 ae->un.AttrInt = cpu_to_be32(LPFC_MAX_CT_SIZE);
2174 size = FOURBYTES + sizeof(uint32_t);
2175 ad->AttrLen = cpu_to_be16(size);
2176 ad->AttrType = cpu_to_be16(RHBA_MAX_CT_PAYLOAD_LEN);
2181 lpfc_fdmi_hba_attr_symbolic_name(struct lpfc_vport *vport,
2182 struct lpfc_fdmi_attr_def *ad)
2184 struct lpfc_fdmi_attr_entry *ae;
2187 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2190 len = lpfc_vport_symbolic_node_name(vport,
2191 ae->un.AttrString, 256);
2192 len += (len & 3) ? (4 - (len & 3)) : 4;
2193 size = FOURBYTES + len;
2194 ad->AttrLen = cpu_to_be16(size);
2195 ad->AttrType = cpu_to_be16(RHBA_SYM_NODENAME);
2200 lpfc_fdmi_hba_attr_vendor_info(struct lpfc_vport *vport,
2201 struct lpfc_fdmi_attr_def *ad)
2203 struct lpfc_fdmi_attr_entry *ae;
2206 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2208 /* Nothing is defined for this currently */
2209 ae->un.AttrInt = cpu_to_be32(0);
2210 size = FOURBYTES + sizeof(uint32_t);
2211 ad->AttrLen = cpu_to_be16(size);
2212 ad->AttrType = cpu_to_be16(RHBA_VENDOR_INFO);
2217 lpfc_fdmi_hba_attr_num_ports(struct lpfc_vport *vport,
2218 struct lpfc_fdmi_attr_def *ad)
2220 struct lpfc_fdmi_attr_entry *ae;
2223 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2225 /* Each driver instance corresponds to a single port */
2226 ae->un.AttrInt = cpu_to_be32(1);
2227 size = FOURBYTES + sizeof(uint32_t);
2228 ad->AttrLen = cpu_to_be16(size);
2229 ad->AttrType = cpu_to_be16(RHBA_NUM_PORTS);
2234 lpfc_fdmi_hba_attr_fabric_wwnn(struct lpfc_vport *vport,
2235 struct lpfc_fdmi_attr_def *ad)
2237 struct lpfc_fdmi_attr_entry *ae;
2240 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2241 memset(ae, 0, sizeof(struct lpfc_name));
2243 memcpy(&ae->un.AttrWWN, &vport->fabric_nodename,
2244 sizeof(struct lpfc_name));
2245 size = FOURBYTES + sizeof(struct lpfc_name);
2246 ad->AttrLen = cpu_to_be16(size);
2247 ad->AttrType = cpu_to_be16(RHBA_FABRIC_WWNN);
2252 lpfc_fdmi_hba_attr_bios_ver(struct lpfc_vport *vport,
2253 struct lpfc_fdmi_attr_def *ad)
2255 struct lpfc_hba *phba = vport->phba;
2256 struct lpfc_fdmi_attr_entry *ae;
2259 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2262 lpfc_decode_firmware_rev(phba, ae->un.AttrString, 1);
2263 len = strnlen(ae->un.AttrString,
2264 sizeof(ae->un.AttrString));
2265 len += (len & 3) ? (4 - (len & 3)) : 4;
2266 size = FOURBYTES + len;
2267 ad->AttrLen = cpu_to_be16(size);
2268 ad->AttrType = cpu_to_be16(RHBA_BIOS_VERSION);
2273 lpfc_fdmi_hba_attr_bios_state(struct lpfc_vport *vport,
2274 struct lpfc_fdmi_attr_def *ad)
2276 struct lpfc_fdmi_attr_entry *ae;
2279 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2281 /* Driver doesn't have access to this information */
2282 ae->un.AttrInt = cpu_to_be32(0);
2283 size = FOURBYTES + sizeof(uint32_t);
2284 ad->AttrLen = cpu_to_be16(size);
2285 ad->AttrType = cpu_to_be16(RHBA_BIOS_STATE);
2290 lpfc_fdmi_hba_attr_vendor_id(struct lpfc_vport *vport,
2291 struct lpfc_fdmi_attr_def *ad)
2293 struct lpfc_fdmi_attr_entry *ae;
2296 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2299 strncpy(ae->un.AttrString, "EMULEX",
2300 sizeof(ae->un.AttrString));
2301 len = strnlen(ae->un.AttrString,
2302 sizeof(ae->un.AttrString));
2303 len += (len & 3) ? (4 - (len & 3)) : 4;
2304 size = FOURBYTES + len;
2305 ad->AttrLen = cpu_to_be16(size);
2306 ad->AttrType = cpu_to_be16(RHBA_VENDOR_ID);
2310 /* Routines for all individual PORT attributes */
2312 lpfc_fdmi_port_attr_fc4type(struct lpfc_vport *vport,
2313 struct lpfc_fdmi_attr_def *ad)
2315 struct lpfc_fdmi_attr_entry *ae;
2318 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2321 ae->un.AttrTypes[3] = 0x02; /* Type 1 - ELS */
2322 ae->un.AttrTypes[2] = 0x01; /* Type 8 - FCP */
2323 ae->un.AttrTypes[6] = 0x01; /* Type 40 - NVME */
2324 ae->un.AttrTypes[7] = 0x01; /* Type 32 - CT */
2325 size = FOURBYTES + 32;
2326 ad->AttrLen = cpu_to_be16(size);
2327 ad->AttrType = cpu_to_be16(RPRT_SUPPORTED_FC4_TYPES);
2332 lpfc_fdmi_port_attr_support_speed(struct lpfc_vport *vport,
2333 struct lpfc_fdmi_attr_def *ad)
2335 struct lpfc_hba *phba = vport->phba;
2336 struct lpfc_fdmi_attr_entry *ae;
2339 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2342 if (!(phba->hba_flag & HBA_FCOE_MODE)) {
2343 if (phba->lmt & LMT_128Gb)
2344 ae->un.AttrInt |= HBA_PORTSPEED_128GFC;
2345 if (phba->lmt & LMT_64Gb)
2346 ae->un.AttrInt |= HBA_PORTSPEED_64GFC;
2347 if (phba->lmt & LMT_32Gb)
2348 ae->un.AttrInt |= HBA_PORTSPEED_32GFC;
2349 if (phba->lmt & LMT_16Gb)
2350 ae->un.AttrInt |= HBA_PORTSPEED_16GFC;
2351 if (phba->lmt & LMT_10Gb)
2352 ae->un.AttrInt |= HBA_PORTSPEED_10GFC;
2353 if (phba->lmt & LMT_8Gb)
2354 ae->un.AttrInt |= HBA_PORTSPEED_8GFC;
2355 if (phba->lmt & LMT_4Gb)
2356 ae->un.AttrInt |= HBA_PORTSPEED_4GFC;
2357 if (phba->lmt & LMT_2Gb)
2358 ae->un.AttrInt |= HBA_PORTSPEED_2GFC;
2359 if (phba->lmt & LMT_1Gb)
2360 ae->un.AttrInt |= HBA_PORTSPEED_1GFC;
2362 /* FCoE links support only one speed */
2363 switch (phba->fc_linkspeed) {
2364 case LPFC_ASYNC_LINK_SPEED_10GBPS:
2365 ae->un.AttrInt = HBA_PORTSPEED_10GE;
2367 case LPFC_ASYNC_LINK_SPEED_25GBPS:
2368 ae->un.AttrInt = HBA_PORTSPEED_25GE;
2370 case LPFC_ASYNC_LINK_SPEED_40GBPS:
2371 ae->un.AttrInt = HBA_PORTSPEED_40GE;
2373 case LPFC_ASYNC_LINK_SPEED_100GBPS:
2374 ae->un.AttrInt = HBA_PORTSPEED_100GE;
2378 ae->un.AttrInt = cpu_to_be32(ae->un.AttrInt);
2379 size = FOURBYTES + sizeof(uint32_t);
2380 ad->AttrLen = cpu_to_be16(size);
2381 ad->AttrType = cpu_to_be16(RPRT_SUPPORTED_SPEED);
2386 lpfc_fdmi_port_attr_speed(struct lpfc_vport *vport,
2387 struct lpfc_fdmi_attr_def *ad)
2389 struct lpfc_hba *phba = vport->phba;
2390 struct lpfc_fdmi_attr_entry *ae;
2393 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2395 if (!(phba->hba_flag & HBA_FCOE_MODE)) {
2396 switch (phba->fc_linkspeed) {
2397 case LPFC_LINK_SPEED_1GHZ:
2398 ae->un.AttrInt = HBA_PORTSPEED_1GFC;
2400 case LPFC_LINK_SPEED_2GHZ:
2401 ae->un.AttrInt = HBA_PORTSPEED_2GFC;
2403 case LPFC_LINK_SPEED_4GHZ:
2404 ae->un.AttrInt = HBA_PORTSPEED_4GFC;
2406 case LPFC_LINK_SPEED_8GHZ:
2407 ae->un.AttrInt = HBA_PORTSPEED_8GFC;
2409 case LPFC_LINK_SPEED_10GHZ:
2410 ae->un.AttrInt = HBA_PORTSPEED_10GFC;
2412 case LPFC_LINK_SPEED_16GHZ:
2413 ae->un.AttrInt = HBA_PORTSPEED_16GFC;
2415 case LPFC_LINK_SPEED_32GHZ:
2416 ae->un.AttrInt = HBA_PORTSPEED_32GFC;
2418 case LPFC_LINK_SPEED_64GHZ:
2419 ae->un.AttrInt = HBA_PORTSPEED_64GFC;
2421 case LPFC_LINK_SPEED_128GHZ:
2422 ae->un.AttrInt = HBA_PORTSPEED_128GFC;
2425 ae->un.AttrInt = HBA_PORTSPEED_UNKNOWN;
2429 switch (phba->fc_linkspeed) {
2430 case LPFC_ASYNC_LINK_SPEED_10GBPS:
2431 ae->un.AttrInt = HBA_PORTSPEED_10GE;
2433 case LPFC_ASYNC_LINK_SPEED_25GBPS:
2434 ae->un.AttrInt = HBA_PORTSPEED_25GE;
2436 case LPFC_ASYNC_LINK_SPEED_40GBPS:
2437 ae->un.AttrInt = HBA_PORTSPEED_40GE;
2439 case LPFC_ASYNC_LINK_SPEED_100GBPS:
2440 ae->un.AttrInt = HBA_PORTSPEED_100GE;
2443 ae->un.AttrInt = HBA_PORTSPEED_UNKNOWN;
2448 ae->un.AttrInt = cpu_to_be32(ae->un.AttrInt);
2449 size = FOURBYTES + sizeof(uint32_t);
2450 ad->AttrLen = cpu_to_be16(size);
2451 ad->AttrType = cpu_to_be16(RPRT_PORT_SPEED);
2456 lpfc_fdmi_port_attr_max_frame(struct lpfc_vport *vport,
2457 struct lpfc_fdmi_attr_def *ad)
2459 struct serv_parm *hsp;
2460 struct lpfc_fdmi_attr_entry *ae;
2463 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2465 hsp = (struct serv_parm *)&vport->fc_sparam;
2466 ae->un.AttrInt = (((uint32_t) hsp->cmn.bbRcvSizeMsb) << 8) |
2467 (uint32_t) hsp->cmn.bbRcvSizeLsb;
2468 ae->un.AttrInt = cpu_to_be32(ae->un.AttrInt);
2469 size = FOURBYTES + sizeof(uint32_t);
2470 ad->AttrLen = cpu_to_be16(size);
2471 ad->AttrType = cpu_to_be16(RPRT_MAX_FRAME_SIZE);
2476 lpfc_fdmi_port_attr_os_devname(struct lpfc_vport *vport,
2477 struct lpfc_fdmi_attr_def *ad)
2479 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2480 struct lpfc_fdmi_attr_entry *ae;
2483 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2486 snprintf(ae->un.AttrString, sizeof(ae->un.AttrString),
2487 "/sys/class/scsi_host/host%d", shost->host_no);
2488 len = strnlen((char *)ae->un.AttrString,
2489 sizeof(ae->un.AttrString));
2490 len += (len & 3) ? (4 - (len & 3)) : 4;
2491 size = FOURBYTES + len;
2492 ad->AttrLen = cpu_to_be16(size);
2493 ad->AttrType = cpu_to_be16(RPRT_OS_DEVICE_NAME);
2498 lpfc_fdmi_port_attr_host_name(struct lpfc_vport *vport,
2499 struct lpfc_fdmi_attr_def *ad)
2501 struct lpfc_fdmi_attr_entry *ae;
2504 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2507 snprintf(ae->un.AttrString, sizeof(ae->un.AttrString), "%s",
2508 init_utsname()->nodename);
2510 len = strnlen(ae->un.AttrString, sizeof(ae->un.AttrString));
2511 len += (len & 3) ? (4 - (len & 3)) : 4;
2512 size = FOURBYTES + len;
2513 ad->AttrLen = cpu_to_be16(size);
2514 ad->AttrType = cpu_to_be16(RPRT_HOST_NAME);
2519 lpfc_fdmi_port_attr_wwnn(struct lpfc_vport *vport,
2520 struct lpfc_fdmi_attr_def *ad)
2522 struct lpfc_fdmi_attr_entry *ae;
2525 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2526 memset(ae, 0, sizeof(struct lpfc_name));
2528 memcpy(&ae->un.AttrWWN, &vport->fc_sparam.nodeName,
2529 sizeof(struct lpfc_name));
2530 size = FOURBYTES + sizeof(struct lpfc_name);
2531 ad->AttrLen = cpu_to_be16(size);
2532 ad->AttrType = cpu_to_be16(RPRT_NODENAME);
2537 lpfc_fdmi_port_attr_wwpn(struct lpfc_vport *vport,
2538 struct lpfc_fdmi_attr_def *ad)
2540 struct lpfc_fdmi_attr_entry *ae;
2543 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2544 memset(ae, 0, sizeof(struct lpfc_name));
2546 memcpy(&ae->un.AttrWWN, &vport->fc_sparam.portName,
2547 sizeof(struct lpfc_name));
2548 size = FOURBYTES + sizeof(struct lpfc_name);
2549 ad->AttrLen = cpu_to_be16(size);
2550 ad->AttrType = cpu_to_be16(RPRT_PORTNAME);
2555 lpfc_fdmi_port_attr_symbolic_name(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;
2564 len = lpfc_vport_symbolic_port_name(vport, ae->un.AttrString, 256);
2565 len += (len & 3) ? (4 - (len & 3)) : 4;
2566 size = FOURBYTES + len;
2567 ad->AttrLen = cpu_to_be16(size);
2568 ad->AttrType = cpu_to_be16(RPRT_SYM_PORTNAME);
2573 lpfc_fdmi_port_attr_port_type(struct lpfc_vport *vport,
2574 struct lpfc_fdmi_attr_def *ad)
2576 struct lpfc_hba *phba = vport->phba;
2577 struct lpfc_fdmi_attr_entry *ae;
2580 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2581 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP)
2582 ae->un.AttrInt = cpu_to_be32(LPFC_FDMI_PORTTYPE_NLPORT);
2584 ae->un.AttrInt = cpu_to_be32(LPFC_FDMI_PORTTYPE_NPORT);
2585 size = FOURBYTES + sizeof(uint32_t);
2586 ad->AttrLen = cpu_to_be16(size);
2587 ad->AttrType = cpu_to_be16(RPRT_PORT_TYPE);
2592 lpfc_fdmi_port_attr_class(struct lpfc_vport *vport,
2593 struct lpfc_fdmi_attr_def *ad)
2595 struct lpfc_fdmi_attr_entry *ae;
2598 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2599 ae->un.AttrInt = cpu_to_be32(FC_COS_CLASS2 | FC_COS_CLASS3);
2600 size = FOURBYTES + sizeof(uint32_t);
2601 ad->AttrLen = cpu_to_be16(size);
2602 ad->AttrType = cpu_to_be16(RPRT_SUPPORTED_CLASS);
2607 lpfc_fdmi_port_attr_fabric_wwpn(struct lpfc_vport *vport,
2608 struct lpfc_fdmi_attr_def *ad)
2610 struct lpfc_fdmi_attr_entry *ae;
2613 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2614 memset(ae, 0, sizeof(struct lpfc_name));
2616 memcpy(&ae->un.AttrWWN, &vport->fabric_portname,
2617 sizeof(struct lpfc_name));
2618 size = FOURBYTES + sizeof(struct lpfc_name);
2619 ad->AttrLen = cpu_to_be16(size);
2620 ad->AttrType = cpu_to_be16(RPRT_FABRICNAME);
2625 lpfc_fdmi_port_attr_active_fc4type(struct lpfc_vport *vport,
2626 struct lpfc_fdmi_attr_def *ad)
2628 struct lpfc_fdmi_attr_entry *ae;
2631 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2634 ae->un.AttrTypes[3] = 0x02; /* Type 1 - ELS */
2635 ae->un.AttrTypes[2] = 0x01; /* Type 8 - FCP */
2636 ae->un.AttrTypes[7] = 0x01; /* Type 32 - CT */
2637 size = FOURBYTES + 32;
2638 ad->AttrLen = cpu_to_be16(size);
2639 ad->AttrType = cpu_to_be16(RPRT_ACTIVE_FC4_TYPES);
2644 lpfc_fdmi_port_attr_port_state(struct lpfc_vport *vport,
2645 struct lpfc_fdmi_attr_def *ad)
2647 struct lpfc_fdmi_attr_entry *ae;
2650 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2651 /* Link Up - operational */
2652 ae->un.AttrInt = cpu_to_be32(LPFC_FDMI_PORTSTATE_ONLINE);
2653 size = FOURBYTES + sizeof(uint32_t);
2654 ad->AttrLen = cpu_to_be16(size);
2655 ad->AttrType = cpu_to_be16(RPRT_PORT_STATE);
2660 lpfc_fdmi_port_attr_num_disc(struct lpfc_vport *vport,
2661 struct lpfc_fdmi_attr_def *ad)
2663 struct lpfc_fdmi_attr_entry *ae;
2666 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2667 vport->fdmi_num_disc = lpfc_find_map_node(vport);
2668 ae->un.AttrInt = cpu_to_be32(vport->fdmi_num_disc);
2669 size = FOURBYTES + sizeof(uint32_t);
2670 ad->AttrLen = cpu_to_be16(size);
2671 ad->AttrType = cpu_to_be16(RPRT_DISC_PORT);
2676 lpfc_fdmi_port_attr_nportid(struct lpfc_vport *vport,
2677 struct lpfc_fdmi_attr_def *ad)
2679 struct lpfc_fdmi_attr_entry *ae;
2682 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2683 ae->un.AttrInt = cpu_to_be32(vport->fc_myDID);
2684 size = FOURBYTES + sizeof(uint32_t);
2685 ad->AttrLen = cpu_to_be16(size);
2686 ad->AttrType = cpu_to_be16(RPRT_PORT_ID);
2691 lpfc_fdmi_smart_attr_service(struct lpfc_vport *vport,
2692 struct lpfc_fdmi_attr_def *ad)
2694 struct lpfc_fdmi_attr_entry *ae;
2697 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2700 strncpy(ae->un.AttrString, "Smart SAN Initiator",
2701 sizeof(ae->un.AttrString));
2702 len = strnlen(ae->un.AttrString,
2703 sizeof(ae->un.AttrString));
2704 len += (len & 3) ? (4 - (len & 3)) : 4;
2705 size = FOURBYTES + len;
2706 ad->AttrLen = cpu_to_be16(size);
2707 ad->AttrType = cpu_to_be16(RPRT_SMART_SERVICE);
2712 lpfc_fdmi_smart_attr_guid(struct lpfc_vport *vport,
2713 struct lpfc_fdmi_attr_def *ad)
2715 struct lpfc_fdmi_attr_entry *ae;
2718 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2721 memcpy(&ae->un.AttrString, &vport->fc_sparam.nodeName,
2722 sizeof(struct lpfc_name));
2723 memcpy((((uint8_t *)&ae->un.AttrString) +
2724 sizeof(struct lpfc_name)),
2725 &vport->fc_sparam.portName, sizeof(struct lpfc_name));
2726 size = FOURBYTES + (2 * sizeof(struct lpfc_name));
2727 ad->AttrLen = cpu_to_be16(size);
2728 ad->AttrType = cpu_to_be16(RPRT_SMART_GUID);
2733 lpfc_fdmi_smart_attr_version(struct lpfc_vport *vport,
2734 struct lpfc_fdmi_attr_def *ad)
2736 struct lpfc_fdmi_attr_entry *ae;
2739 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2742 strncpy(ae->un.AttrString, "Smart SAN Version 2.0",
2743 sizeof(ae->un.AttrString));
2744 len = strnlen(ae->un.AttrString,
2745 sizeof(ae->un.AttrString));
2746 len += (len & 3) ? (4 - (len & 3)) : 4;
2747 size = FOURBYTES + len;
2748 ad->AttrLen = cpu_to_be16(size);
2749 ad->AttrType = cpu_to_be16(RPRT_SMART_VERSION);
2754 lpfc_fdmi_smart_attr_model(struct lpfc_vport *vport,
2755 struct lpfc_fdmi_attr_def *ad)
2757 struct lpfc_hba *phba = vport->phba;
2758 struct lpfc_fdmi_attr_entry *ae;
2761 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2764 strncpy(ae->un.AttrString, phba->ModelName,
2765 sizeof(ae->un.AttrString));
2766 len = strnlen(ae->un.AttrString, sizeof(ae->un.AttrString));
2767 len += (len & 3) ? (4 - (len & 3)) : 4;
2768 size = FOURBYTES + len;
2769 ad->AttrLen = cpu_to_be16(size);
2770 ad->AttrType = cpu_to_be16(RPRT_SMART_MODEL);
2775 lpfc_fdmi_smart_attr_port_info(struct lpfc_vport *vport,
2776 struct lpfc_fdmi_attr_def *ad)
2778 struct lpfc_fdmi_attr_entry *ae;
2781 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2783 /* SRIOV (type 3) is not supported */
2785 ae->un.AttrInt = cpu_to_be32(2); /* NPIV */
2787 ae->un.AttrInt = cpu_to_be32(1); /* Physical */
2788 size = FOURBYTES + sizeof(uint32_t);
2789 ad->AttrLen = cpu_to_be16(size);
2790 ad->AttrType = cpu_to_be16(RPRT_SMART_PORT_INFO);
2795 lpfc_fdmi_smart_attr_qos(struct lpfc_vport *vport,
2796 struct lpfc_fdmi_attr_def *ad)
2798 struct lpfc_fdmi_attr_entry *ae;
2801 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2802 ae->un.AttrInt = cpu_to_be32(0);
2803 size = FOURBYTES + sizeof(uint32_t);
2804 ad->AttrLen = cpu_to_be16(size);
2805 ad->AttrType = cpu_to_be16(RPRT_SMART_QOS);
2810 lpfc_fdmi_smart_attr_security(struct lpfc_vport *vport,
2811 struct lpfc_fdmi_attr_def *ad)
2813 struct lpfc_fdmi_attr_entry *ae;
2816 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2817 ae->un.AttrInt = cpu_to_be32(1);
2818 size = FOURBYTES + sizeof(uint32_t);
2819 ad->AttrLen = cpu_to_be16(size);
2820 ad->AttrType = cpu_to_be16(RPRT_SMART_SECURITY);
2824 /* RHBA attribute jump table */
2825 int (*lpfc_fdmi_hba_action[])
2826 (struct lpfc_vport *vport, struct lpfc_fdmi_attr_def *ad) = {
2827 /* Action routine Mask bit Attribute type */
2828 lpfc_fdmi_hba_attr_wwnn, /* bit0 RHBA_NODENAME */
2829 lpfc_fdmi_hba_attr_manufacturer, /* bit1 RHBA_MANUFACTURER */
2830 lpfc_fdmi_hba_attr_sn, /* bit2 RHBA_SERIAL_NUMBER */
2831 lpfc_fdmi_hba_attr_model, /* bit3 RHBA_MODEL */
2832 lpfc_fdmi_hba_attr_description, /* bit4 RHBA_MODEL_DESCRIPTION */
2833 lpfc_fdmi_hba_attr_hdw_ver, /* bit5 RHBA_HARDWARE_VERSION */
2834 lpfc_fdmi_hba_attr_drvr_ver, /* bit6 RHBA_DRIVER_VERSION */
2835 lpfc_fdmi_hba_attr_rom_ver, /* bit7 RHBA_OPTION_ROM_VERSION */
2836 lpfc_fdmi_hba_attr_fmw_ver, /* bit8 RHBA_FIRMWARE_VERSION */
2837 lpfc_fdmi_hba_attr_os_ver, /* bit9 RHBA_OS_NAME_VERSION */
2838 lpfc_fdmi_hba_attr_ct_len, /* bit10 RHBA_MAX_CT_PAYLOAD_LEN */
2839 lpfc_fdmi_hba_attr_symbolic_name, /* bit11 RHBA_SYM_NODENAME */
2840 lpfc_fdmi_hba_attr_vendor_info, /* bit12 RHBA_VENDOR_INFO */
2841 lpfc_fdmi_hba_attr_num_ports, /* bit13 RHBA_NUM_PORTS */
2842 lpfc_fdmi_hba_attr_fabric_wwnn, /* bit14 RHBA_FABRIC_WWNN */
2843 lpfc_fdmi_hba_attr_bios_ver, /* bit15 RHBA_BIOS_VERSION */
2844 lpfc_fdmi_hba_attr_bios_state, /* bit16 RHBA_BIOS_STATE */
2845 lpfc_fdmi_hba_attr_vendor_id, /* bit17 RHBA_VENDOR_ID */
2848 /* RPA / RPRT attribute jump table */
2849 int (*lpfc_fdmi_port_action[])
2850 (struct lpfc_vport *vport, struct lpfc_fdmi_attr_def *ad) = {
2851 /* Action routine Mask bit Attribute type */
2852 lpfc_fdmi_port_attr_fc4type, /* bit0 RPRT_SUPPORT_FC4_TYPES */
2853 lpfc_fdmi_port_attr_support_speed, /* bit1 RPRT_SUPPORTED_SPEED */
2854 lpfc_fdmi_port_attr_speed, /* bit2 RPRT_PORT_SPEED */
2855 lpfc_fdmi_port_attr_max_frame, /* bit3 RPRT_MAX_FRAME_SIZE */
2856 lpfc_fdmi_port_attr_os_devname, /* bit4 RPRT_OS_DEVICE_NAME */
2857 lpfc_fdmi_port_attr_host_name, /* bit5 RPRT_HOST_NAME */
2858 lpfc_fdmi_port_attr_wwnn, /* bit6 RPRT_NODENAME */
2859 lpfc_fdmi_port_attr_wwpn, /* bit7 RPRT_PORTNAME */
2860 lpfc_fdmi_port_attr_symbolic_name, /* bit8 RPRT_SYM_PORTNAME */
2861 lpfc_fdmi_port_attr_port_type, /* bit9 RPRT_PORT_TYPE */
2862 lpfc_fdmi_port_attr_class, /* bit10 RPRT_SUPPORTED_CLASS */
2863 lpfc_fdmi_port_attr_fabric_wwpn, /* bit11 RPRT_FABRICNAME */
2864 lpfc_fdmi_port_attr_active_fc4type, /* bit12 RPRT_ACTIVE_FC4_TYPES */
2865 lpfc_fdmi_port_attr_port_state, /* bit13 RPRT_PORT_STATE */
2866 lpfc_fdmi_port_attr_num_disc, /* bit14 RPRT_DISC_PORT */
2867 lpfc_fdmi_port_attr_nportid, /* bit15 RPRT_PORT_ID */
2868 lpfc_fdmi_smart_attr_service, /* bit16 RPRT_SMART_SERVICE */
2869 lpfc_fdmi_smart_attr_guid, /* bit17 RPRT_SMART_GUID */
2870 lpfc_fdmi_smart_attr_version, /* bit18 RPRT_SMART_VERSION */
2871 lpfc_fdmi_smart_attr_model, /* bit19 RPRT_SMART_MODEL */
2872 lpfc_fdmi_smart_attr_port_info, /* bit20 RPRT_SMART_PORT_INFO */
2873 lpfc_fdmi_smart_attr_qos, /* bit21 RPRT_SMART_QOS */
2874 lpfc_fdmi_smart_attr_security, /* bit22 RPRT_SMART_SECURITY */
2878 * lpfc_fdmi_cmd - Build and send a FDMI cmd to the specified NPort
2879 * @vport: pointer to a host virtual N_Port data structure.
2880 * @ndlp: ndlp to send FDMI cmd to (if NULL use FDMI_DID)
2881 * cmdcode: FDMI command to send
2882 * mask: Mask of HBA or PORT Attributes to send
2884 * Builds and sends a FDMI command using the CT subsystem.
2887 lpfc_fdmi_cmd(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2888 int cmdcode, uint32_t new_mask)
2890 struct lpfc_hba *phba = vport->phba;
2891 struct lpfc_dmabuf *mp, *bmp;
2892 struct lpfc_sli_ct_request *CtReq;
2893 struct ulp_bde64 *bpl;
2898 struct lpfc_fdmi_reg_hba *rh;
2899 struct lpfc_fdmi_port_entry *pe;
2900 struct lpfc_fdmi_reg_portattr *pab = NULL;
2901 struct lpfc_fdmi_attr_block *ab = NULL;
2902 int (*func)(struct lpfc_vport *vport, struct lpfc_fdmi_attr_def *ad);
2903 void (*cmpl)(struct lpfc_hba *, struct lpfc_iocbq *,
2904 struct lpfc_iocbq *);
2906 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
2909 cmpl = lpfc_cmpl_ct_disc_fdmi; /* called from discovery */
2911 /* fill in BDEs for command */
2912 /* Allocate buffer for command payload */
2913 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
2917 mp->virt = lpfc_mbuf_alloc(phba, 0, &(mp->phys));
2919 goto fdmi_cmd_free_mp;
2921 /* Allocate buffer for Buffer ptr list */
2922 bmp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
2924 goto fdmi_cmd_free_mpvirt;
2926 bmp->virt = lpfc_mbuf_alloc(phba, 0, &(bmp->phys));
2928 goto fdmi_cmd_free_bmp;
2930 INIT_LIST_HEAD(&mp->list);
2931 INIT_LIST_HEAD(&bmp->list);
2934 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2935 "0218 FDMI Request Data: x%x x%x x%x\n",
2936 vport->fc_flag, vport->port_state, cmdcode);
2937 CtReq = (struct lpfc_sli_ct_request *)mp->virt;
2939 /* First populate the CT_IU preamble */
2940 memset(CtReq, 0, sizeof(struct lpfc_sli_ct_request));
2941 CtReq->RevisionId.bits.Revision = SLI_CT_REVISION;
2942 CtReq->RevisionId.bits.InId = 0;
2944 CtReq->FsType = SLI_CT_MANAGEMENT_SERVICE;
2945 CtReq->FsSubType = SLI_CT_FDMI_Subtypes;
2947 CtReq->CommandResponse.bits.CmdRsp = cpu_to_be16(cmdcode);
2948 rsp_size = LPFC_BPL_SIZE;
2951 /* Next fill in the specific FDMI cmd information */
2955 rh = (struct lpfc_fdmi_reg_hba *)&CtReq->un.PortID;
2956 /* HBA Identifier */
2957 memcpy(&rh->hi.PortName, &phba->pport->fc_sparam.portName,
2958 sizeof(struct lpfc_name));
2960 if (cmdcode == SLI_MGMT_RHBA) {
2961 /* Registered Port List */
2962 /* One entry (port) per adapter */
2963 rh->rpl.EntryCnt = cpu_to_be32(1);
2964 memcpy(&rh->rpl.pe, &phba->pport->fc_sparam.portName,
2965 sizeof(struct lpfc_name));
2967 /* point to the HBA attribute block */
2968 size = 2 * sizeof(struct lpfc_name) +
2971 size = sizeof(struct lpfc_name);
2973 ab = (struct lpfc_fdmi_attr_block *)((uint8_t *)rh + size);
2980 mask = vport->fdmi_hba_mask;
2982 /* Mask will dictate what attributes to build in the request */
2985 func = lpfc_fdmi_hba_action[bit_pos];
2987 (struct lpfc_fdmi_attr_def *)
2988 ((uint8_t *)rh + size));
2991 (LPFC_BPL_SIZE - LPFC_CT_PREAMBLE))
2998 ab->EntryCnt = cpu_to_be32(ab->EntryCnt);
3000 size = GID_REQUEST_SZ - 4 + size;
3005 pab = (struct lpfc_fdmi_reg_portattr *)&CtReq->un.PortID;
3006 if (cmdcode == SLI_MGMT_RPRT) {
3007 rh = (struct lpfc_fdmi_reg_hba *)pab;
3008 /* HBA Identifier */
3009 memcpy(&rh->hi.PortName,
3010 &phba->pport->fc_sparam.portName,
3011 sizeof(struct lpfc_name));
3012 pab = (struct lpfc_fdmi_reg_portattr *)
3013 ((uint8_t *)pab + sizeof(struct lpfc_name));
3016 memcpy((uint8_t *)&pab->PortName,
3017 (uint8_t *)&vport->fc_sparam.portName,
3018 sizeof(struct lpfc_name));
3019 size += sizeof(struct lpfc_name) + FOURBYTES;
3020 pab->ab.EntryCnt = 0;
3025 mask = vport->fdmi_port_mask;
3027 /* Mask will dictate what attributes to build in the request */
3030 func = lpfc_fdmi_port_action[bit_pos];
3032 (struct lpfc_fdmi_attr_def *)
3033 ((uint8_t *)pab + size));
3036 (LPFC_BPL_SIZE - LPFC_CT_PREAMBLE))
3043 pab->ab.EntryCnt = cpu_to_be32(pab->ab.EntryCnt);
3045 if (cmdcode == SLI_MGMT_RPRT)
3046 size += sizeof(struct lpfc_name);
3047 size = GID_REQUEST_SZ - 4 + size;
3052 rsp_size = FC_MAX_NS_RSP;
3055 pe = (struct lpfc_fdmi_port_entry *)&CtReq->un.PortID;
3056 memcpy((uint8_t *)&pe->PortName,
3057 (uint8_t *)&vport->fc_sparam.portName,
3058 sizeof(struct lpfc_name));
3059 size = GID_REQUEST_SZ - 4 + sizeof(struct lpfc_name);
3064 rsp_size = FC_MAX_NS_RSP;
3067 pe = (struct lpfc_fdmi_port_entry *)&CtReq->un.PortID;
3068 memcpy((uint8_t *)&pe->PortName,
3069 (uint8_t *)&vport->fc_sparam.portName,
3070 sizeof(struct lpfc_name));
3071 size = GID_REQUEST_SZ - 4 + sizeof(struct lpfc_name);
3074 size = GID_REQUEST_SZ - 4;
3077 lpfc_printf_vlog(vport, KERN_WARNING, LOG_DISCOVERY,
3078 "0298 FDMI cmdcode x%x not supported\n",
3080 goto fdmi_cmd_free_bmpvirt;
3082 CtReq->CommandResponse.bits.Size = cpu_to_be16(rsp_size);
3084 bpl = (struct ulp_bde64 *)bmp->virt;
3085 bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys));
3086 bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys));
3087 bpl->tus.f.bdeFlags = 0;
3088 bpl->tus.f.bdeSize = size;
3091 * The lpfc_ct_cmd/lpfc_get_req shall increment ndlp reference count
3092 * to hold ndlp reference for the corresponding callback function.
3094 if (!lpfc_ct_cmd(vport, mp, bmp, ndlp, cmpl, rsp_size, 0))
3098 * Decrement ndlp reference count to release ndlp reference held
3099 * for the failed command's callback function.
3103 fdmi_cmd_free_bmpvirt:
3104 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
3107 fdmi_cmd_free_mpvirt:
3108 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3112 /* Issue FDMI request failed */
3113 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
3114 "0244 Issue FDMI request failed Data: x%x\n",
3120 * lpfc_delayed_disc_tmo - Timeout handler for delayed discovery timer.
3121 * @ptr - Context object of the timer.
3123 * This function set the WORKER_DELAYED_DISC_TMO flag and wake up
3124 * the worker thread.
3127 lpfc_delayed_disc_tmo(struct timer_list *t)
3129 struct lpfc_vport *vport = from_timer(vport, t, delayed_disc_tmo);
3130 struct lpfc_hba *phba = vport->phba;
3131 uint32_t tmo_posted;
3132 unsigned long iflag;
3134 spin_lock_irqsave(&vport->work_port_lock, iflag);
3135 tmo_posted = vport->work_port_events & WORKER_DELAYED_DISC_TMO;
3137 vport->work_port_events |= WORKER_DELAYED_DISC_TMO;
3138 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
3141 lpfc_worker_wake_up(phba);
3146 * lpfc_delayed_disc_timeout_handler - Function called by worker thread to
3147 * handle delayed discovery.
3148 * @vport: pointer to a host virtual N_Port data structure.
3150 * This function start nport discovery of the vport.
3153 lpfc_delayed_disc_timeout_handler(struct lpfc_vport *vport)
3155 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3157 spin_lock_irq(shost->host_lock);
3158 if (!(vport->fc_flag & FC_DISC_DELAYED)) {
3159 spin_unlock_irq(shost->host_lock);
3162 vport->fc_flag &= ~FC_DISC_DELAYED;
3163 spin_unlock_irq(shost->host_lock);
3165 lpfc_do_scr_ns_plogi(vport->phba, vport);
3169 lpfc_decode_firmware_rev(struct lpfc_hba *phba, char *fwrevision, int flag)
3171 struct lpfc_sli *psli = &phba->sli;
3172 lpfc_vpd_t *vp = &phba->vpd;
3173 uint32_t b1, b2, b3, b4, i, rev;
3175 uint32_t *ptr, str[4];
3178 if (phba->sli_rev == LPFC_SLI_REV4)
3179 snprintf(fwrevision, FW_REV_STR_SIZE, "%s", vp->rev.opFwName);
3180 else if (vp->rev.rBit) {
3181 if (psli->sli_flag & LPFC_SLI_ACTIVE)
3182 rev = vp->rev.sli2FwRev;
3184 rev = vp->rev.sli1FwRev;
3186 b1 = (rev & 0x0000f000) >> 12;
3187 b2 = (rev & 0x00000f00) >> 8;
3188 b3 = (rev & 0x000000c0) >> 6;
3189 b4 = (rev & 0x00000030) >> 4;
3208 b4 = (rev & 0x0000000f);
3210 if (psli->sli_flag & LPFC_SLI_ACTIVE)
3211 fwname = vp->rev.sli2FwName;
3213 fwname = vp->rev.sli1FwName;
3215 for (i = 0; i < 16; i++)
3216 if (fwname[i] == 0x20)
3219 ptr = (uint32_t*)fwname;
3221 for (i = 0; i < 3; i++)
3222 str[i] = be32_to_cpu(*ptr++);
3226 sprintf(fwrevision, "%d.%d%d (%s)",
3227 b1, b2, b3, (char *)str);
3229 sprintf(fwrevision, "%d.%d%d", b1,
3233 sprintf(fwrevision, "%d.%d%d%c%d (%s)",
3237 sprintf(fwrevision, "%d.%d%d%c%d",
3241 rev = vp->rev.smFwRev;
3243 b1 = (rev & 0xff000000) >> 24;
3244 b2 = (rev & 0x00f00000) >> 20;
3245 b3 = (rev & 0x000f0000) >> 16;
3246 c = (rev & 0x0000ff00) >> 8;
3247 b4 = (rev & 0x000000ff);
3249 sprintf(fwrevision, "%d.%d%d%c%d", b1, b2, b3, c, b4);