1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2017-2020 Broadcom. All Rights Reserved. The term *
5 * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. *
6 * Copyright (C) 2004-2016 Emulex. All rights reserved. *
7 * EMULEX and SLI are trademarks of Emulex. *
10 * This program is free software; you can redistribute it and/or *
11 * modify it under the terms of version 2 of the GNU General *
12 * Public License as published by the Free Software Foundation. *
13 * This program is distributed in the hope that it will be useful. *
14 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
15 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
16 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
17 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
18 * TO BE LEGALLY INVALID. See the GNU General Public License for *
19 * more details, a copy of which can be found in the file COPYING *
20 * included with this package. *
21 *******************************************************************/
24 * Fibre Channel SCSI LAN Device Driver CT support: FC Generic Services FC-GS
27 #include <linux/blkdev.h>
28 #include <linux/pci.h>
29 #include <linux/interrupt.h>
30 #include <linux/slab.h>
31 #include <linux/utsname.h>
33 #include <scsi/scsi.h>
34 #include <scsi/scsi_device.h>
35 #include <scsi/scsi_host.h>
36 #include <scsi/scsi_transport_fc.h>
37 #include <scsi/fc/fc_fs.h>
42 #include "lpfc_sli4.h"
44 #include "lpfc_disc.h"
46 #include "lpfc_scsi.h"
47 #include "lpfc_logmsg.h"
48 #include "lpfc_crtn.h"
49 #include "lpfc_version.h"
50 #include "lpfc_vport.h"
51 #include "lpfc_debugfs.h"
53 /* FDMI Port Speed definitions - FC-GS-7 */
54 #define HBA_PORTSPEED_1GFC 0x00000001 /* 1G FC */
55 #define HBA_PORTSPEED_2GFC 0x00000002 /* 2G FC */
56 #define HBA_PORTSPEED_4GFC 0x00000008 /* 4G FC */
57 #define HBA_PORTSPEED_10GFC 0x00000004 /* 10G FC */
58 #define HBA_PORTSPEED_8GFC 0x00000010 /* 8G FC */
59 #define HBA_PORTSPEED_16GFC 0x00000020 /* 16G FC */
60 #define HBA_PORTSPEED_32GFC 0x00000040 /* 32G FC */
61 #define HBA_PORTSPEED_20GFC 0x00000080 /* 20G FC */
62 #define HBA_PORTSPEED_40GFC 0x00000100 /* 40G FC */
63 #define HBA_PORTSPEED_128GFC 0x00000200 /* 128G FC */
64 #define HBA_PORTSPEED_64GFC 0x00000400 /* 64G FC */
65 #define HBA_PORTSPEED_256GFC 0x00000800 /* 256G FC */
66 #define HBA_PORTSPEED_UNKNOWN 0x00008000 /* Unknown */
67 #define HBA_PORTSPEED_10GE 0x00010000 /* 10G E */
68 #define HBA_PORTSPEED_40GE 0x00020000 /* 40G E */
69 #define HBA_PORTSPEED_100GE 0x00040000 /* 100G E */
70 #define HBA_PORTSPEED_25GE 0x00080000 /* 25G E */
71 #define HBA_PORTSPEED_50GE 0x00100000 /* 50G E */
72 #define HBA_PORTSPEED_400GE 0x00200000 /* 400G E */
77 static char *lpfc_release_version = LPFC_DRIVER_VERSION;
80 lpfc_ct_ignore_hbq_buffer(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq,
81 struct lpfc_dmabuf *mp, uint32_t size)
84 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
85 "0146 Ignoring unsolicited CT No HBQ "
87 piocbq->iocb.ulpStatus);
89 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
90 "0145 Ignoring unsolicted CT HBQ Size:%d "
92 size, piocbq->iocb.ulpStatus);
96 lpfc_ct_unsol_buffer(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq,
97 struct lpfc_dmabuf *mp, uint32_t size)
99 lpfc_ct_ignore_hbq_buffer(phba, piocbq, mp, size);
103 lpfc_ct_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
104 struct lpfc_iocbq *piocbq)
106 struct lpfc_dmabuf *mp = NULL;
107 IOCB_t *icmd = &piocbq->iocb;
109 struct lpfc_iocbq *iocbq;
112 struct list_head head;
113 struct lpfc_dmabuf *bdeBuf;
115 if (lpfc_bsg_ct_unsol_event(phba, pring, piocbq) == 0)
118 if (unlikely(icmd->ulpStatus == IOSTAT_NEED_BUFFER)) {
119 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
120 } else if ((icmd->ulpStatus == IOSTAT_LOCAL_REJECT) &&
121 ((icmd->un.ulpWord[4] & IOERR_PARAM_MASK) ==
122 IOERR_RCV_BUFFER_WAITING)) {
123 /* Not enough posted buffers; Try posting more buffers */
124 phba->fc_stat.NoRcvBuf++;
125 if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
126 lpfc_post_buffer(phba, pring, 2);
130 /* If there are no BDEs associated with this IOCB,
131 * there is nothing to do.
133 if (icmd->ulpBdeCount == 0)
136 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
137 INIT_LIST_HEAD(&head);
138 list_add_tail(&head, &piocbq->list);
139 list_for_each_entry(iocbq, &head, list) {
141 if (icmd->ulpBdeCount == 0)
143 bdeBuf = iocbq->context2;
144 iocbq->context2 = NULL;
145 size = icmd->un.cont64[0].tus.f.bdeSize;
146 lpfc_ct_unsol_buffer(phba, piocbq, bdeBuf, size);
147 lpfc_in_buf_free(phba, bdeBuf);
148 if (icmd->ulpBdeCount == 2) {
149 bdeBuf = iocbq->context3;
150 iocbq->context3 = NULL;
151 size = icmd->unsli3.rcvsli3.bde2.tus.f.bdeSize;
152 lpfc_ct_unsol_buffer(phba, piocbq, bdeBuf,
154 lpfc_in_buf_free(phba, bdeBuf);
159 INIT_LIST_HEAD(&head);
160 list_add_tail(&head, &piocbq->list);
161 list_for_each_entry(iocbq, &head, list) {
163 if (icmd->ulpBdeCount == 0)
164 lpfc_ct_unsol_buffer(phba, iocbq, NULL, 0);
165 for (i = 0; i < icmd->ulpBdeCount; i++) {
166 paddr = getPaddr(icmd->un.cont64[i].addrHigh,
167 icmd->un.cont64[i].addrLow);
168 mp = lpfc_sli_ringpostbuf_get(phba, pring,
170 size = icmd->un.cont64[i].tus.f.bdeSize;
171 lpfc_ct_unsol_buffer(phba, iocbq, mp, size);
172 lpfc_in_buf_free(phba, mp);
174 lpfc_post_buffer(phba, pring, i);
181 * lpfc_ct_handle_unsol_abort - ct upper level protocol abort handler
182 * @phba: Pointer to HBA context object.
183 * @dmabuf: pointer to a dmabuf that describes the FC sequence
185 * This function serves as the upper level protocol abort handler for CT
188 * Return 1 if abort has been handled, 0 otherwise.
191 lpfc_ct_handle_unsol_abort(struct lpfc_hba *phba, struct hbq_dmabuf *dmabuf)
195 /* CT upper level goes through BSG */
196 handled = lpfc_bsg_ct_unsol_abort(phba, dmabuf);
202 lpfc_free_ct_rsp(struct lpfc_hba *phba, struct lpfc_dmabuf *mlist)
204 struct lpfc_dmabuf *mlast, *next_mlast;
206 list_for_each_entry_safe(mlast, next_mlast, &mlist->list, list) {
207 lpfc_mbuf_free(phba, mlast->virt, mlast->phys);
208 list_del(&mlast->list);
211 lpfc_mbuf_free(phba, mlist->virt, mlist->phys);
216 static struct lpfc_dmabuf *
217 lpfc_alloc_ct_rsp(struct lpfc_hba *phba, int cmdcode, struct ulp_bde64 *bpl,
218 uint32_t size, int *entries)
220 struct lpfc_dmabuf *mlist = NULL;
221 struct lpfc_dmabuf *mp;
224 /* We get chunks of FCELSSIZE */
225 cnt = size > FCELSSIZE ? FCELSSIZE: size;
228 /* Allocate buffer for rsp payload */
229 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
232 lpfc_free_ct_rsp(phba, mlist);
236 INIT_LIST_HEAD(&mp->list);
238 if (cmdcode == be16_to_cpu(SLI_CTNS_GID_FT) ||
239 cmdcode == be16_to_cpu(SLI_CTNS_GFF_ID))
240 mp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(mp->phys));
242 mp->virt = lpfc_mbuf_alloc(phba, 0, &(mp->phys));
247 lpfc_free_ct_rsp(phba, mlist);
251 /* Queue it to a linked list */
255 list_add_tail(&mp->list, &mlist->list);
257 bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64I;
258 /* build buffer ptr list for IOCB */
259 bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys) );
260 bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys) );
261 bpl->tus.f.bdeSize = (uint16_t) cnt;
262 bpl->tus.w = le32_to_cpu(bpl->tus.w);
274 lpfc_ct_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *ctiocb)
276 struct lpfc_dmabuf *buf_ptr;
278 if (ctiocb->context_un.ndlp) {
279 lpfc_nlp_put(ctiocb->context_un.ndlp);
280 ctiocb->context_un.ndlp = NULL;
282 if (ctiocb->context1) {
283 buf_ptr = (struct lpfc_dmabuf *) ctiocb->context1;
284 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
286 ctiocb->context1 = NULL;
288 if (ctiocb->context2) {
289 lpfc_free_ct_rsp(phba, (struct lpfc_dmabuf *) ctiocb->context2);
290 ctiocb->context2 = NULL;
293 if (ctiocb->context3) {
294 buf_ptr = (struct lpfc_dmabuf *) ctiocb->context3;
295 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
297 ctiocb->context3 = NULL;
299 lpfc_sli_release_iocbq(phba, ctiocb);
304 * lpfc_gen_req - Build and issue a GEN_REQUEST command to the SLI Layer
305 * @vport: pointer to a host virtual N_Port data structure.
306 * @bmp: Pointer to BPL for SLI command
307 * @inp: Pointer to data buffer for response data.
308 * @outp: Pointer to data buffer that hold the CT command.
309 * @cmpl: completion routine to call when command completes
310 * @ndlp: Destination NPort nodelist entry
312 * This function as the final part for issuing a CT command.
315 lpfc_gen_req(struct lpfc_vport *vport, struct lpfc_dmabuf *bmp,
316 struct lpfc_dmabuf *inp, struct lpfc_dmabuf *outp,
317 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
318 struct lpfc_iocbq *),
319 struct lpfc_nodelist *ndlp, uint32_t usr_flg, uint32_t num_entry,
320 uint32_t tmo, uint8_t retry)
322 struct lpfc_hba *phba = vport->phba;
324 struct lpfc_iocbq *geniocb;
327 /* Allocate buffer for command iocb */
328 geniocb = lpfc_sli_get_iocbq(phba);
333 icmd = &geniocb->iocb;
334 icmd->un.genreq64.bdl.ulpIoTag32 = 0;
335 icmd->un.genreq64.bdl.addrHigh = putPaddrHigh(bmp->phys);
336 icmd->un.genreq64.bdl.addrLow = putPaddrLow(bmp->phys);
337 icmd->un.genreq64.bdl.bdeFlags = BUFF_TYPE_BLP_64;
338 icmd->un.genreq64.bdl.bdeSize = (num_entry * sizeof(struct ulp_bde64));
341 geniocb->context3 = NULL;
343 geniocb->context3 = (uint8_t *) bmp;
345 /* Save for completion so we can release these resources */
346 geniocb->context1 = (uint8_t *) inp;
347 geniocb->context2 = (uint8_t *) outp;
348 geniocb->context_un.ndlp = lpfc_nlp_get(ndlp);
350 /* Fill in payload, bp points to frame payload */
351 icmd->ulpCommand = CMD_GEN_REQUEST64_CR;
353 /* Fill in rest of iocb */
354 icmd->un.genreq64.w5.hcsw.Fctl = (SI | LA);
355 icmd->un.genreq64.w5.hcsw.Dfctl = 0;
356 icmd->un.genreq64.w5.hcsw.Rctl = FC_RCTL_DD_UNSOL_CTL;
357 icmd->un.genreq64.w5.hcsw.Type = FC_TYPE_CT;
360 /* FC spec states we need 3 * ratov for CT requests */
361 tmo = (3 * phba->fc_ratov);
363 icmd->ulpTimeout = tmo;
364 icmd->ulpBdeCount = 1;
366 icmd->ulpClass = CLASS3;
367 icmd->ulpContext = ndlp->nlp_rpi;
368 if (phba->sli_rev == LPFC_SLI_REV4)
369 icmd->ulpContext = phba->sli4_hba.rpi_ids[ndlp->nlp_rpi];
371 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
372 /* For GEN_REQUEST64_CR, use the RPI */
377 /* Issue GEN REQ IOCB for NPORT <did> */
378 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
379 "0119 Issue GEN REQ IOCB to NPORT x%x "
381 ndlp->nlp_DID, icmd->ulpIoTag,
383 geniocb->iocb_cmpl = cmpl;
384 geniocb->drvrTimeout = icmd->ulpTimeout + LPFC_DRVR_TIMEOUT;
385 geniocb->vport = vport;
386 geniocb->retry = retry;
387 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, geniocb, 0);
389 if (rc == IOCB_ERROR) {
390 geniocb->context_un.ndlp = NULL;
392 lpfc_sli_release_iocbq(phba, geniocb);
400 * lpfc_ct_cmd - Build and issue a CT command
401 * @vport: pointer to a host virtual N_Port data structure.
402 * @inmp: Pointer to data buffer for response data.
403 * @bmp: Pointer to BPL for SLI command
404 * @ndlp: Destination NPort nodelist entry
405 * @cmpl: completion routine to call when command completes
407 * This function is called for issuing a CT command.
410 lpfc_ct_cmd(struct lpfc_vport *vport, struct lpfc_dmabuf *inmp,
411 struct lpfc_dmabuf *bmp, struct lpfc_nodelist *ndlp,
412 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
413 struct lpfc_iocbq *),
414 uint32_t rsp_size, uint8_t retry)
416 struct lpfc_hba *phba = vport->phba;
417 struct ulp_bde64 *bpl = (struct ulp_bde64 *) bmp->virt;
418 struct lpfc_dmabuf *outmp;
420 int cmdcode = ((struct lpfc_sli_ct_request *) inmp->virt)->
421 CommandResponse.bits.CmdRsp;
423 bpl++; /* Skip past ct request */
425 /* Put buffer(s) for ct rsp in bpl */
426 outmp = lpfc_alloc_ct_rsp(phba, cmdcode, bpl, rsp_size, &cnt);
430 * Form the CT IOCB. The total number of BDEs in this IOCB
431 * is the single command plus response count from
435 status = lpfc_gen_req(vport, bmp, inmp, outmp, cmpl, ndlp, 0,
438 lpfc_free_ct_rsp(phba, outmp);
445 lpfc_find_vport_by_did(struct lpfc_hba *phba, uint32_t did) {
446 struct lpfc_vport *vport_curr;
449 spin_lock_irqsave(&phba->port_list_lock, flags);
450 list_for_each_entry(vport_curr, &phba->port_list, listentry) {
451 if ((vport_curr->fc_myDID) && (vport_curr->fc_myDID == did)) {
452 spin_unlock_irqrestore(&phba->port_list_lock, flags);
456 spin_unlock_irqrestore(&phba->port_list_lock, flags);
461 lpfc_prep_node_fc4type(struct lpfc_vport *vport, uint32_t Did, uint8_t fc4_type)
463 struct lpfc_nodelist *ndlp;
465 if ((vport->port_type != LPFC_NPIV_PORT) ||
466 !(vport->ct_flags & FC_CT_RFF_ID) || !vport->cfg_restrict_login) {
468 ndlp = lpfc_setup_disc_node(vport, Did);
470 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
471 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
472 "Parse GID_FTrsp: did:x%x flg:x%x x%x",
473 Did, ndlp->nlp_flag, vport->fc_flag);
475 /* By default, the driver expects to support FCP FC4 */
476 if (fc4_type == FC_TYPE_FCP)
477 ndlp->nlp_fc4_type |= NLP_FC4_FCP;
479 if (fc4_type == FC_TYPE_NVME)
480 ndlp->nlp_fc4_type |= NLP_FC4_NVME;
482 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
483 "0238 Process x%06x NameServer Rsp "
484 "Data: x%x x%x x%x x%x x%x\n", Did,
485 ndlp->nlp_flag, ndlp->nlp_fc4_type,
486 ndlp->nlp_state, vport->fc_flag,
487 vport->fc_rscn_id_cnt);
489 /* if ndlp needs to be discovered and prior
490 * state of ndlp hit devloss, change state to
493 if (ndlp->nlp_flag & NLP_NPR_2B_DISC &&
494 ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
495 lpfc_nlp_set_state(vport, ndlp,
499 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
500 "Skip1 GID_FTrsp: did:x%x flg:x%x cnt:%d",
501 Did, vport->fc_flag, vport->fc_rscn_id_cnt);
503 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
504 "0239 Skip x%06x NameServer Rsp "
505 "Data: x%x x%x %p\n",
507 vport->fc_rscn_id_cnt, ndlp);
510 if (!(vport->fc_flag & FC_RSCN_MODE) ||
511 lpfc_rscn_payload_check(vport, Did)) {
512 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
513 "Query GID_FTrsp: did:x%x flg:x%x cnt:%d",
514 Did, vport->fc_flag, vport->fc_rscn_id_cnt);
517 * This NPortID was previously a FCP/NVMe target,
518 * Don't even bother to send GFF_ID.
520 ndlp = lpfc_findnode_did(vport, Did);
521 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
523 (NLP_FCP_TARGET | NLP_NVME_TARGET))) {
524 if (fc4_type == FC_TYPE_FCP)
525 ndlp->nlp_fc4_type |= NLP_FC4_FCP;
526 if (fc4_type == FC_TYPE_NVME)
527 ndlp->nlp_fc4_type |= NLP_FC4_NVME;
528 lpfc_setup_disc_node(vport, Did);
529 } else if (lpfc_ns_cmd(vport, SLI_CTNS_GFF_ID,
531 vport->num_disc_nodes++;
533 lpfc_setup_disc_node(vport, Did);
535 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
536 "Skip2 GID_FTrsp: did:x%x flg:x%x cnt:%d",
537 Did, vport->fc_flag, vport->fc_rscn_id_cnt);
539 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
540 "0245 Skip x%06x NameServer Rsp "
541 "Data: x%x x%x\n", Did,
543 vport->fc_rscn_id_cnt);
549 lpfc_ns_rsp_audit_did(struct lpfc_vport *vport, uint32_t Did, uint8_t fc4_type)
551 struct lpfc_hba *phba = vport->phba;
552 struct lpfc_nodelist *ndlp = NULL;
553 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
556 if (phba->cfg_ns_query == LPFC_NS_QUERY_GID_FT)
560 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
561 "6430 Process %s rsp for %08x type %x %s %s\n",
563 (fc4_type == FC_TYPE_FCP) ? "FCP" : " ",
564 (fc4_type == FC_TYPE_NVME) ? "NVME" : " ");
566 * To conserve rpi's, filter out addresses for other
567 * vports on the same physical HBAs.
569 if (Did != vport->fc_myDID &&
570 (!lpfc_find_vport_by_did(phba, Did) ||
571 vport->cfg_peer_port_login)) {
572 if (!phba->nvmet_support) {
573 /* FCPI/NVMEI path. Process Did */
574 lpfc_prep_node_fc4type(vport, Did, fc4_type);
577 /* NVMET path. NVMET only cares about NVMEI nodes. */
578 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
579 if (ndlp->nlp_type != NLP_NVME_INITIATOR ||
580 ndlp->nlp_state != NLP_STE_UNMAPPED_NODE)
582 spin_lock_irq(shost->host_lock);
583 if (ndlp->nlp_DID == Did)
584 ndlp->nlp_flag &= ~NLP_NVMET_RECOV;
586 ndlp->nlp_flag |= NLP_NVMET_RECOV;
587 spin_unlock_irq(shost->host_lock);
593 lpfc_ns_rsp(struct lpfc_vport *vport, struct lpfc_dmabuf *mp, uint8_t fc4_type,
596 struct lpfc_sli_ct_request *Response =
597 (struct lpfc_sli_ct_request *) mp->virt;
598 struct lpfc_dmabuf *mlast, *next_mp;
599 uint32_t *ctptr = (uint32_t *) & Response->un.gid.PortType;
600 uint32_t Did, CTentry;
602 struct list_head head;
603 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
604 struct lpfc_nodelist *ndlp = NULL;
606 lpfc_set_disctmo(vport);
607 vport->num_disc_nodes = 0;
608 vport->fc_ns_retry = 0;
611 list_add_tail(&head, &mp->list);
612 list_for_each_entry_safe(mp, next_mp, &head, list) {
615 Cnt = Size > FCELSSIZE ? FCELSSIZE : Size;
620 ctptr = (uint32_t *) mlast->virt;
622 Cnt -= 16; /* subtract length of CT header */
624 /* Loop through entire NameServer list of DIDs */
625 while (Cnt >= sizeof(uint32_t)) {
626 /* Get next DID from NameServer List */
628 Did = ((be32_to_cpu(CTentry)) & Mask_DID);
629 lpfc_ns_rsp_audit_did(vport, Did, fc4_type);
630 if (CTentry & (cpu_to_be32(SLI_CT_LAST_ENTRY)))
633 Cnt -= sizeof(uint32_t);
639 /* All GID_FT entries processed. If the driver is running in
640 * in target mode, put impacted nodes into recovery and drop
641 * the RPI to flush outstanding IO.
643 if (vport->phba->nvmet_support) {
644 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
645 if (!(ndlp->nlp_flag & NLP_NVMET_RECOV))
647 lpfc_disc_state_machine(vport, ndlp, NULL,
648 NLP_EVT_DEVICE_RECOVERY);
649 spin_lock_irq(shost->host_lock);
650 ndlp->nlp_flag &= ~NLP_NVMET_RECOV;
651 spin_unlock_irq(shost->host_lock);
661 lpfc_cmpl_ct_cmd_gid_ft(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
662 struct lpfc_iocbq *rspiocb)
664 struct lpfc_vport *vport = cmdiocb->vport;
665 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
667 struct lpfc_dmabuf *outp;
668 struct lpfc_dmabuf *inp;
669 struct lpfc_sli_ct_request *CTrsp;
670 struct lpfc_sli_ct_request *CTreq;
671 struct lpfc_nodelist *ndlp;
674 /* First save ndlp, before we overwrite it */
675 ndlp = cmdiocb->context_un.ndlp;
677 /* we pass cmdiocb to state machine which needs rspiocb as well */
678 cmdiocb->context_un.rsp_iocb = rspiocb;
679 inp = (struct lpfc_dmabuf *) cmdiocb->context1;
680 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
681 irsp = &rspiocb->iocb;
683 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
684 "GID_FT cmpl: status:x%x/x%x rtry:%d",
685 irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_ns_retry);
687 /* Don't bother processing response if vport is being torn down. */
688 if (vport->load_flag & FC_UNLOADING) {
689 if (vport->fc_flag & FC_RSCN_MODE)
690 lpfc_els_flush_rscn(vport);
694 if (lpfc_els_chk_latt(vport)) {
695 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
696 "0216 Link event during NS query\n");
697 if (vport->fc_flag & FC_RSCN_MODE)
698 lpfc_els_flush_rscn(vport);
699 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
702 if (lpfc_error_lost_link(irsp)) {
703 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
704 "0226 NS query failed due to link event\n");
705 if (vport->fc_flag & FC_RSCN_MODE)
706 lpfc_els_flush_rscn(vport);
710 spin_lock_irq(shost->host_lock);
711 if (vport->fc_flag & FC_RSCN_DEFERRED) {
712 vport->fc_flag &= ~FC_RSCN_DEFERRED;
713 spin_unlock_irq(shost->host_lock);
715 /* This is a GID_FT completing so the gidft_inp counter was
716 * incremented before the GID_FT was issued to the wire.
718 if (vport->gidft_inp)
722 * Skip processing the NS response
723 * Re-issue the NS cmd
725 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
726 "0151 Process Deferred RSCN Data: x%x x%x\n",
727 vport->fc_flag, vport->fc_rscn_id_cnt);
728 lpfc_els_handle_rscn(vport);
732 spin_unlock_irq(shost->host_lock);
734 if (irsp->ulpStatus) {
735 /* Check for retry */
736 if (vport->fc_ns_retry < LPFC_MAX_NS_RETRY) {
737 if (irsp->ulpStatus != IOSTAT_LOCAL_REJECT ||
738 (irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
740 vport->fc_ns_retry++;
742 type = lpfc_get_gidft_type(vport, cmdiocb);
746 /* CT command is being retried */
747 rc = lpfc_ns_cmd(vport, SLI_CTNS_GID_FT,
748 vport->fc_ns_retry, type);
751 else { /* Unable to send NS cmd */
752 if (vport->gidft_inp)
756 if (vport->fc_flag & FC_RSCN_MODE)
757 lpfc_els_flush_rscn(vport);
758 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
759 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
760 "0257 GID_FT Query error: 0x%x 0x%x\n",
761 irsp->ulpStatus, vport->fc_ns_retry);
763 /* Good status, continue checking */
764 CTreq = (struct lpfc_sli_ct_request *) inp->virt;
765 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
766 if (CTrsp->CommandResponse.bits.CmdRsp ==
767 cpu_to_be16(SLI_CT_RESPONSE_FS_ACC)) {
768 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
769 "0208 NameServer Rsp Data: x%x x%x "
772 CTreq->un.gid.Fc4Type,
773 vport->num_disc_nodes,
775 irsp->un.genreq64.bdl.bdeSize);
779 CTreq->un.gid.Fc4Type,
780 (uint32_t) (irsp->un.genreq64.bdl.bdeSize));
781 } else if (CTrsp->CommandResponse.bits.CmdRsp ==
782 be16_to_cpu(SLI_CT_RESPONSE_FS_RJT)) {
783 /* NameServer Rsp Error */
784 if ((CTrsp->ReasonCode == SLI_CT_UNABLE_TO_PERFORM_REQ)
785 && (CTrsp->Explanation == SLI_CT_NO_FC4_TYPES)) {
786 lpfc_printf_vlog(vport, KERN_INFO,
788 "0269 No NameServer Entries "
789 "Data: x%x x%x x%x x%x\n",
790 CTrsp->CommandResponse.bits.CmdRsp,
791 (uint32_t) CTrsp->ReasonCode,
792 (uint32_t) CTrsp->Explanation,
795 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
796 "GID_FT no entry cmd:x%x rsn:x%x exp:x%x",
797 (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
798 (uint32_t) CTrsp->ReasonCode,
799 (uint32_t) CTrsp->Explanation);
801 lpfc_printf_vlog(vport, KERN_INFO,
803 "0240 NameServer Rsp Error "
804 "Data: x%x x%x x%x x%x\n",
805 CTrsp->CommandResponse.bits.CmdRsp,
806 (uint32_t) CTrsp->ReasonCode,
807 (uint32_t) CTrsp->Explanation,
810 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
811 "GID_FT rsp err1 cmd:x%x rsn:x%x exp:x%x",
812 (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
813 (uint32_t) CTrsp->ReasonCode,
814 (uint32_t) CTrsp->Explanation);
819 /* NameServer Rsp Error */
820 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
821 "0241 NameServer Rsp Error "
822 "Data: x%x x%x x%x x%x\n",
823 CTrsp->CommandResponse.bits.CmdRsp,
824 (uint32_t) CTrsp->ReasonCode,
825 (uint32_t) CTrsp->Explanation,
828 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
829 "GID_FT rsp err2 cmd:x%x rsn:x%x exp:x%x",
830 (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
831 (uint32_t) CTrsp->ReasonCode,
832 (uint32_t) CTrsp->Explanation);
834 if (vport->gidft_inp)
838 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
839 "4216 GID_FT cmpl inp %d disc %d\n",
840 vport->gidft_inp, vport->num_disc_nodes);
842 /* Link up / RSCN discovery */
843 if ((vport->num_disc_nodes == 0) &&
844 (vport->gidft_inp == 0)) {
846 * The driver has cycled through all Nports in the RSCN payload.
847 * Complete the handling by cleaning up and marking the
848 * current driver state.
850 if (vport->port_state >= LPFC_DISC_AUTH) {
851 if (vport->fc_flag & FC_RSCN_MODE) {
852 lpfc_els_flush_rscn(vport);
853 spin_lock_irq(shost->host_lock);
854 vport->fc_flag |= FC_RSCN_MODE; /* RSCN still */
855 spin_unlock_irq(shost->host_lock);
858 lpfc_els_flush_rscn(vport);
861 lpfc_disc_start(vport);
864 cmdiocb->context_un.ndlp = ndlp; /* Now restore ndlp for free */
865 lpfc_ct_free_iocb(phba, cmdiocb);
870 lpfc_cmpl_ct_cmd_gid_pt(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
871 struct lpfc_iocbq *rspiocb)
873 struct lpfc_vport *vport = cmdiocb->vport;
874 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
876 struct lpfc_dmabuf *outp;
877 struct lpfc_dmabuf *inp;
878 struct lpfc_sli_ct_request *CTrsp;
879 struct lpfc_sli_ct_request *CTreq;
880 struct lpfc_nodelist *ndlp;
883 /* First save ndlp, before we overwrite it */
884 ndlp = cmdiocb->context_un.ndlp;
886 /* we pass cmdiocb to state machine which needs rspiocb as well */
887 cmdiocb->context_un.rsp_iocb = rspiocb;
888 inp = (struct lpfc_dmabuf *)cmdiocb->context1;
889 outp = (struct lpfc_dmabuf *)cmdiocb->context2;
890 irsp = &rspiocb->iocb;
892 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
893 "GID_PT cmpl: status:x%x/x%x rtry:%d",
894 irsp->ulpStatus, irsp->un.ulpWord[4],
897 /* Don't bother processing response if vport is being torn down. */
898 if (vport->load_flag & FC_UNLOADING) {
899 if (vport->fc_flag & FC_RSCN_MODE)
900 lpfc_els_flush_rscn(vport);
904 if (lpfc_els_chk_latt(vport)) {
905 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
906 "4108 Link event during NS query\n");
907 if (vport->fc_flag & FC_RSCN_MODE)
908 lpfc_els_flush_rscn(vport);
909 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
912 if (lpfc_error_lost_link(irsp)) {
913 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
914 "4166 NS query failed due to link event\n");
915 if (vport->fc_flag & FC_RSCN_MODE)
916 lpfc_els_flush_rscn(vport);
920 spin_lock_irq(shost->host_lock);
921 if (vport->fc_flag & FC_RSCN_DEFERRED) {
922 vport->fc_flag &= ~FC_RSCN_DEFERRED;
923 spin_unlock_irq(shost->host_lock);
925 /* This is a GID_PT completing so the gidft_inp counter was
926 * incremented before the GID_PT was issued to the wire.
928 if (vport->gidft_inp)
932 * Skip processing the NS response
933 * Re-issue the NS cmd
935 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
936 "4167 Process Deferred RSCN Data: x%x x%x\n",
937 vport->fc_flag, vport->fc_rscn_id_cnt);
938 lpfc_els_handle_rscn(vport);
942 spin_unlock_irq(shost->host_lock);
944 if (irsp->ulpStatus) {
945 /* Check for retry */
946 if (vport->fc_ns_retry < LPFC_MAX_NS_RETRY) {
947 if (irsp->ulpStatus != IOSTAT_LOCAL_REJECT ||
948 (irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
950 vport->fc_ns_retry++;
952 /* CT command is being retried */
953 rc = lpfc_ns_cmd(vport, SLI_CTNS_GID_PT,
954 vport->fc_ns_retry, GID_PT_N_PORT);
957 else { /* Unable to send NS cmd */
958 if (vport->gidft_inp)
962 if (vport->fc_flag & FC_RSCN_MODE)
963 lpfc_els_flush_rscn(vport);
964 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
965 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
966 "4103 GID_FT Query error: 0x%x 0x%x\n",
967 irsp->ulpStatus, vport->fc_ns_retry);
969 /* Good status, continue checking */
970 CTreq = (struct lpfc_sli_ct_request *)inp->virt;
971 CTrsp = (struct lpfc_sli_ct_request *)outp->virt;
972 if (CTrsp->CommandResponse.bits.CmdRsp ==
973 cpu_to_be16(SLI_CT_RESPONSE_FS_ACC)) {
974 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
975 "4105 NameServer Rsp Data: x%x x%x "
978 CTreq->un.gid.Fc4Type,
979 vport->num_disc_nodes,
981 irsp->un.genreq64.bdl.bdeSize);
985 CTreq->un.gid.Fc4Type,
986 (uint32_t)(irsp->un.genreq64.bdl.bdeSize));
987 } else if (CTrsp->CommandResponse.bits.CmdRsp ==
988 be16_to_cpu(SLI_CT_RESPONSE_FS_RJT)) {
989 /* NameServer Rsp Error */
990 if ((CTrsp->ReasonCode == SLI_CT_UNABLE_TO_PERFORM_REQ)
991 && (CTrsp->Explanation == SLI_CT_NO_FC4_TYPES)) {
993 vport, KERN_INFO, LOG_DISCOVERY,
994 "4106 No NameServer Entries "
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 no entry 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);
1009 vport, KERN_INFO, LOG_DISCOVERY,
1010 "4107 NameServer Rsp Error "
1011 "Data: x%x x%x x%x x%x\n",
1012 CTrsp->CommandResponse.bits.CmdRsp,
1013 (uint32_t)CTrsp->ReasonCode,
1014 (uint32_t)CTrsp->Explanation,
1017 lpfc_debugfs_disc_trc(
1018 vport, LPFC_DISC_TRC_CT,
1019 "GID_PT rsp err1 cmd:x%x rsn:x%x exp:x%x",
1020 (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
1021 (uint32_t)CTrsp->ReasonCode,
1022 (uint32_t)CTrsp->Explanation);
1025 /* NameServer Rsp Error */
1026 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1027 "4109 NameServer Rsp Error "
1028 "Data: x%x x%x x%x x%x\n",
1029 CTrsp->CommandResponse.bits.CmdRsp,
1030 (uint32_t)CTrsp->ReasonCode,
1031 (uint32_t)CTrsp->Explanation,
1034 lpfc_debugfs_disc_trc(
1035 vport, LPFC_DISC_TRC_CT,
1036 "GID_PT rsp err2 cmd:x%x rsn:x%x exp:x%x",
1037 (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
1038 (uint32_t)CTrsp->ReasonCode,
1039 (uint32_t)CTrsp->Explanation);
1041 if (vport->gidft_inp)
1045 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1046 "6450 GID_PT cmpl inp %d disc %d\n",
1047 vport->gidft_inp, vport->num_disc_nodes);
1049 /* Link up / RSCN discovery */
1050 if ((vport->num_disc_nodes == 0) &&
1051 (vport->gidft_inp == 0)) {
1053 * The driver has cycled through all Nports in the RSCN payload.
1054 * Complete the handling by cleaning up and marking the
1055 * current driver state.
1057 if (vport->port_state >= LPFC_DISC_AUTH) {
1058 if (vport->fc_flag & FC_RSCN_MODE) {
1059 lpfc_els_flush_rscn(vport);
1060 spin_lock_irq(shost->host_lock);
1061 vport->fc_flag |= FC_RSCN_MODE; /* RSCN still */
1062 spin_unlock_irq(shost->host_lock);
1064 lpfc_els_flush_rscn(vport);
1068 lpfc_disc_start(vport);
1071 cmdiocb->context_un.ndlp = ndlp; /* Now restore ndlp for free */
1072 lpfc_ct_free_iocb(phba, cmdiocb);
1076 lpfc_cmpl_ct_cmd_gff_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1077 struct lpfc_iocbq *rspiocb)
1079 struct lpfc_vport *vport = cmdiocb->vport;
1080 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1081 IOCB_t *irsp = &rspiocb->iocb;
1082 struct lpfc_dmabuf *inp = (struct lpfc_dmabuf *) cmdiocb->context1;
1083 struct lpfc_dmabuf *outp = (struct lpfc_dmabuf *) cmdiocb->context2;
1084 struct lpfc_sli_ct_request *CTrsp;
1087 struct lpfc_nodelist *ndlp;
1089 did = ((struct lpfc_sli_ct_request *) inp->virt)->un.gff.PortId;
1090 did = be32_to_cpu(did);
1092 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
1093 "GFF_ID cmpl: status:x%x/x%x did:x%x",
1094 irsp->ulpStatus, irsp->un.ulpWord[4], did);
1096 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
1097 /* Good status, continue checking */
1098 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
1099 fbits = CTrsp->un.gff_acc.fbits[FCP_TYPE_FEATURE_OFFSET];
1101 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1102 "6431 Process GFF_ID rsp for %08x "
1103 "fbits %02x %s %s\n",
1105 (fbits & FC4_FEATURE_INIT) ? "Initiator" : " ",
1106 (fbits & FC4_FEATURE_TARGET) ? "Target" : " ");
1108 if (CTrsp->CommandResponse.bits.CmdRsp ==
1109 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC)) {
1110 if ((fbits & FC4_FEATURE_INIT) &&
1111 !(fbits & FC4_FEATURE_TARGET)) {
1112 lpfc_printf_vlog(vport, KERN_INFO,
1114 "0270 Skip x%x GFF "
1115 "NameServer Rsp Data: (init) "
1116 "x%x x%x\n", did, fbits,
1117 vport->fc_rscn_id_cnt);
1123 /* Check for retry */
1124 if (cmdiocb->retry < LPFC_MAX_NS_RETRY) {
1126 if (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) {
1127 switch ((irsp->un.ulpWord[4] &
1128 IOERR_PARAM_MASK)) {
1130 case IOERR_NO_RESOURCES:
1131 /* We don't increment the retry
1132 * count for this case.
1135 case IOERR_LINK_DOWN:
1136 case IOERR_SLI_ABORTED:
1137 case IOERR_SLI_DOWN:
1148 /* CT command is being retried */
1149 rc = lpfc_ns_cmd(vport, SLI_CTNS_GFF_ID,
1150 cmdiocb->retry, did);
1153 lpfc_ct_free_iocb(phba, cmdiocb);
1158 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1159 "0267 NameServer GFF Rsp "
1160 "x%x Error (%d %d) Data: x%x x%x\n",
1161 did, irsp->ulpStatus, irsp->un.ulpWord[4],
1162 vport->fc_flag, vport->fc_rscn_id_cnt);
1165 /* This is a target port, unregistered port, or the GFF_ID failed */
1166 ndlp = lpfc_setup_disc_node(vport, did);
1167 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
1168 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1169 "0242 Process x%x GFF "
1170 "NameServer Rsp Data: x%x x%x x%x\n",
1171 did, ndlp->nlp_flag, vport->fc_flag,
1172 vport->fc_rscn_id_cnt);
1174 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1175 "0243 Skip x%x GFF "
1176 "NameServer Rsp Data: x%x x%x\n", did,
1177 vport->fc_flag, vport->fc_rscn_id_cnt);
1180 /* Link up / RSCN discovery */
1181 if (vport->num_disc_nodes)
1182 vport->num_disc_nodes--;
1184 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1185 "6451 GFF_ID cmpl inp %d disc %d\n",
1186 vport->gidft_inp, vport->num_disc_nodes);
1188 if (vport->num_disc_nodes == 0) {
1190 * The driver has cycled through all Nports in the RSCN payload.
1191 * Complete the handling by cleaning up and marking the
1192 * current driver state.
1194 if (vport->port_state >= LPFC_DISC_AUTH) {
1195 if (vport->fc_flag & FC_RSCN_MODE) {
1196 lpfc_els_flush_rscn(vport);
1197 spin_lock_irq(shost->host_lock);
1198 vport->fc_flag |= FC_RSCN_MODE; /* RSCN still */
1199 spin_unlock_irq(shost->host_lock);
1202 lpfc_els_flush_rscn(vport);
1204 lpfc_disc_start(vport);
1206 lpfc_ct_free_iocb(phba, cmdiocb);
1211 lpfc_cmpl_ct_cmd_gft_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1212 struct lpfc_iocbq *rspiocb)
1214 struct lpfc_vport *vport = cmdiocb->vport;
1215 IOCB_t *irsp = &rspiocb->iocb;
1216 struct lpfc_dmabuf *inp = (struct lpfc_dmabuf *)cmdiocb->context1;
1217 struct lpfc_dmabuf *outp = (struct lpfc_dmabuf *)cmdiocb->context2;
1218 struct lpfc_sli_ct_request *CTrsp;
1220 struct lpfc_nodelist *ndlp;
1221 uint32_t fc4_data_0, fc4_data_1;
1223 did = ((struct lpfc_sli_ct_request *)inp->virt)->un.gft.PortId;
1224 did = be32_to_cpu(did);
1226 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
1227 "GFT_ID cmpl: status:x%x/x%x did:x%x",
1228 irsp->ulpStatus, irsp->un.ulpWord[4], did);
1230 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
1231 /* Good status, continue checking */
1232 CTrsp = (struct lpfc_sli_ct_request *)outp->virt;
1233 fc4_data_0 = be32_to_cpu(CTrsp->un.gft_acc.fc4_types[0]);
1234 fc4_data_1 = be32_to_cpu(CTrsp->un.gft_acc.fc4_types[1]);
1236 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1237 "6432 Process GFT_ID rsp for %08x "
1238 "Data %08x %08x %s %s\n",
1239 did, fc4_data_0, fc4_data_1,
1240 (fc4_data_0 & LPFC_FC4_TYPE_BITMASK) ?
1242 (fc4_data_1 & LPFC_FC4_TYPE_BITMASK) ?
1245 ndlp = lpfc_findnode_did(vport, did);
1247 /* The bitmask value for FCP and NVME FCP types is
1248 * the same because they are 32 bits distant from
1249 * each other in word0 and word0.
1251 if (fc4_data_0 & LPFC_FC4_TYPE_BITMASK)
1252 ndlp->nlp_fc4_type |= NLP_FC4_FCP;
1253 if (fc4_data_1 & LPFC_FC4_TYPE_BITMASK)
1254 ndlp->nlp_fc4_type |= NLP_FC4_NVME;
1255 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1256 "3064 Setting ndlp x%px, DID x%06x "
1257 "with FC4 x%08x, Data: x%08x x%08x "
1259 ndlp, did, ndlp->nlp_fc4_type,
1260 FC_TYPE_FCP, FC_TYPE_NVME,
1263 if (ndlp->nlp_state == NLP_STE_REG_LOGIN_ISSUE &&
1264 ndlp->nlp_fc4_type) {
1265 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1267 lpfc_nlp_set_state(vport, ndlp,
1268 NLP_STE_PRLI_ISSUE);
1269 lpfc_issue_els_prli(vport, ndlp, 0);
1270 } else if (!ndlp->nlp_fc4_type) {
1271 /* If fc4 type is still unknown, then LOGO */
1272 lpfc_printf_vlog(vport, KERN_INFO,
1274 "6443 Sending LOGO ndlp x%px,"
1275 "DID x%06x with fc4_type: "
1276 "x%08x, state: %d\n",
1277 ndlp, did, ndlp->nlp_fc4_type,
1279 lpfc_issue_els_logo(vport, ndlp, 0);
1280 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1281 lpfc_nlp_set_state(vport, ndlp,
1286 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1287 "3065 GFT_ID failed x%08x\n", irsp->ulpStatus);
1289 lpfc_ct_free_iocb(phba, cmdiocb);
1293 lpfc_cmpl_ct(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1294 struct lpfc_iocbq *rspiocb)
1296 struct lpfc_vport *vport = cmdiocb->vport;
1297 struct lpfc_dmabuf *inp;
1298 struct lpfc_dmabuf *outp;
1300 struct lpfc_sli_ct_request *CTrsp;
1301 struct lpfc_nodelist *ndlp;
1306 /* First save ndlp, before we overwrite it */
1307 ndlp = cmdiocb->context_un.ndlp;
1309 /* we pass cmdiocb to state machine which needs rspiocb as well */
1310 cmdiocb->context_un.rsp_iocb = rspiocb;
1312 inp = (struct lpfc_dmabuf *) cmdiocb->context1;
1313 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
1314 irsp = &rspiocb->iocb;
1316 cmdcode = be16_to_cpu(((struct lpfc_sli_ct_request *) inp->virt)->
1317 CommandResponse.bits.CmdRsp);
1318 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
1320 latt = lpfc_els_chk_latt(vport);
1322 /* RFT request completes status <ulpStatus> CmdRsp <CmdRsp> */
1323 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1324 "0209 CT Request completes, latt %d, "
1325 "ulpStatus x%x CmdRsp x%x, Context x%x, Tag x%x\n",
1326 latt, irsp->ulpStatus,
1327 CTrsp->CommandResponse.bits.CmdRsp,
1328 cmdiocb->iocb.ulpContext, cmdiocb->iocb.ulpIoTag);
1330 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
1331 "CT cmd cmpl: status:x%x/x%x cmd:x%x",
1332 irsp->ulpStatus, irsp->un.ulpWord[4], cmdcode);
1334 if (irsp->ulpStatus) {
1335 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1336 "0268 NS cmd x%x Error (x%x x%x)\n",
1337 cmdcode, irsp->ulpStatus, irsp->un.ulpWord[4]);
1339 if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
1340 (((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
1342 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
1343 IOERR_SLI_ABORTED)))
1346 retry = cmdiocb->retry;
1347 if (retry >= LPFC_MAX_NS_RETRY)
1351 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1352 "0250 Retrying NS cmd %x\n", cmdcode);
1353 rc = lpfc_ns_cmd(vport, cmdcode, retry, 0);
1359 cmdiocb->context_un.ndlp = ndlp; /* Now restore ndlp for free */
1360 lpfc_ct_free_iocb(phba, cmdiocb);
1365 lpfc_cmpl_ct_cmd_rft_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1366 struct lpfc_iocbq *rspiocb)
1368 IOCB_t *irsp = &rspiocb->iocb;
1369 struct lpfc_vport *vport = cmdiocb->vport;
1371 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
1372 struct lpfc_dmabuf *outp;
1373 struct lpfc_sli_ct_request *CTrsp;
1375 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
1376 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
1377 if (CTrsp->CommandResponse.bits.CmdRsp ==
1378 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
1379 vport->ct_flags |= FC_CT_RFT_ID;
1381 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
1386 lpfc_cmpl_ct_cmd_rnn_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1387 struct lpfc_iocbq *rspiocb)
1389 IOCB_t *irsp = &rspiocb->iocb;
1390 struct lpfc_vport *vport = cmdiocb->vport;
1392 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
1393 struct lpfc_dmabuf *outp;
1394 struct lpfc_sli_ct_request *CTrsp;
1396 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
1397 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
1398 if (CTrsp->CommandResponse.bits.CmdRsp ==
1399 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
1400 vport->ct_flags |= FC_CT_RNN_ID;
1402 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
1407 lpfc_cmpl_ct_cmd_rspn_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1408 struct lpfc_iocbq *rspiocb)
1410 IOCB_t *irsp = &rspiocb->iocb;
1411 struct lpfc_vport *vport = cmdiocb->vport;
1413 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
1414 struct lpfc_dmabuf *outp;
1415 struct lpfc_sli_ct_request *CTrsp;
1417 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
1418 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
1419 if (CTrsp->CommandResponse.bits.CmdRsp ==
1420 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
1421 vport->ct_flags |= FC_CT_RSPN_ID;
1423 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
1428 lpfc_cmpl_ct_cmd_rsnn_nn(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1429 struct lpfc_iocbq *rspiocb)
1431 IOCB_t *irsp = &rspiocb->iocb;
1432 struct lpfc_vport *vport = cmdiocb->vport;
1434 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
1435 struct lpfc_dmabuf *outp;
1436 struct lpfc_sli_ct_request *CTrsp;
1438 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
1439 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
1440 if (CTrsp->CommandResponse.bits.CmdRsp ==
1441 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
1442 vport->ct_flags |= FC_CT_RSNN_NN;
1444 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
1449 lpfc_cmpl_ct_cmd_da_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1450 struct lpfc_iocbq *rspiocb)
1452 struct lpfc_vport *vport = cmdiocb->vport;
1454 /* even if it fails we will act as though it succeeded. */
1455 vport->ct_flags = 0;
1456 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
1461 lpfc_cmpl_ct_cmd_rff_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1462 struct lpfc_iocbq *rspiocb)
1464 IOCB_t *irsp = &rspiocb->iocb;
1465 struct lpfc_vport *vport = cmdiocb->vport;
1467 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
1468 struct lpfc_dmabuf *outp;
1469 struct lpfc_sli_ct_request *CTrsp;
1471 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
1472 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
1473 if (CTrsp->CommandResponse.bits.CmdRsp ==
1474 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
1475 vport->ct_flags |= FC_CT_RFF_ID;
1477 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
1482 * Although the symbolic port name is thought to be an integer
1483 * as of January 18, 2016, leave it as a string until more of
1484 * the record state becomes defined.
1487 lpfc_vport_symbolic_port_name(struct lpfc_vport *vport, char *symbol,
1493 * Use the lpfc board number as the Symbolic Port
1494 * Name object. NPIV is not in play so this integer
1495 * value is sufficient and unique per FC-ID.
1497 n = scnprintf(symbol, size, "%d", vport->phba->brd_no);
1503 lpfc_vport_symbolic_node_name(struct lpfc_vport *vport, char *symbol,
1506 char fwrev[FW_REV_STR_SIZE] = {0};
1507 char tmp[MAXHOSTNAMELEN] = {0};
1509 memset(symbol, 0, size);
1511 scnprintf(tmp, sizeof(tmp), "Emulex %s", vport->phba->ModelName);
1512 if (strlcat(symbol, tmp, size) >= size)
1515 lpfc_decode_firmware_rev(vport->phba, fwrev, 0);
1516 scnprintf(tmp, sizeof(tmp), " FV%s", fwrev);
1517 if (strlcat(symbol, tmp, size) >= size)
1520 scnprintf(tmp, sizeof(tmp), " DV%s", lpfc_release_version);
1521 if (strlcat(symbol, tmp, size) >= size)
1524 scnprintf(tmp, sizeof(tmp), " HN:%s", vport->phba->os_host_name);
1525 if (strlcat(symbol, tmp, size) >= size)
1528 /* Note :- OS name is "Linux" */
1529 scnprintf(tmp, sizeof(tmp), " OS:%s", init_utsname()->sysname);
1530 strlcat(symbol, tmp, size);
1533 return strnlen(symbol, size);
1538 lpfc_find_map_node(struct lpfc_vport *vport)
1540 struct lpfc_nodelist *ndlp, *next_ndlp;
1541 struct Scsi_Host *shost;
1544 shost = lpfc_shost_from_vport(vport);
1545 spin_lock_irq(shost->host_lock);
1546 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
1547 if (ndlp->nlp_type & NLP_FABRIC)
1549 if ((ndlp->nlp_state == NLP_STE_MAPPED_NODE) ||
1550 (ndlp->nlp_state == NLP_STE_UNMAPPED_NODE))
1553 spin_unlock_irq(shost->host_lock);
1558 * This routine will return the FC4 Type associated with the CT
1562 lpfc_get_gidft_type(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb)
1564 struct lpfc_sli_ct_request *CtReq;
1565 struct lpfc_dmabuf *mp;
1568 mp = cmdiocb->context1;
1571 CtReq = (struct lpfc_sli_ct_request *)mp->virt;
1572 type = (uint32_t)CtReq->un.gid.Fc4Type;
1573 if ((type != SLI_CTPT_FCP) && (type != SLI_CTPT_NVME))
1581 * Issue Cmd to NameServer
1586 lpfc_ns_cmd(struct lpfc_vport *vport, int cmdcode,
1587 uint8_t retry, uint32_t context)
1589 struct lpfc_nodelist * ndlp;
1590 struct lpfc_hba *phba = vport->phba;
1591 struct lpfc_dmabuf *mp, *bmp;
1592 struct lpfc_sli_ct_request *CtReq;
1593 struct ulp_bde64 *bpl;
1594 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
1595 struct lpfc_iocbq *) = NULL;
1597 uint32_t rsp_size = 1024;
1601 ndlp = lpfc_findnode_did(vport, NameServer_DID);
1602 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)
1603 || ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) {
1608 /* fill in BDEs for command */
1609 /* Allocate buffer for command payload */
1610 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
1616 INIT_LIST_HEAD(&mp->list);
1617 mp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(mp->phys));
1620 goto ns_cmd_free_mp;
1623 /* Allocate buffer for Buffer ptr list */
1624 bmp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
1627 goto ns_cmd_free_mpvirt;
1630 INIT_LIST_HEAD(&bmp->list);
1631 bmp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(bmp->phys));
1634 goto ns_cmd_free_bmp;
1637 /* NameServer Req */
1638 lpfc_printf_vlog(vport, KERN_INFO ,LOG_DISCOVERY,
1639 "0236 NameServer Req Data: x%x x%x x%x x%x\n",
1640 cmdcode, vport->fc_flag, vport->fc_rscn_id_cnt,
1643 bpl = (struct ulp_bde64 *) bmp->virt;
1644 memset(bpl, 0, sizeof(struct ulp_bde64));
1645 bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys) );
1646 bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys) );
1647 bpl->tus.f.bdeFlags = 0;
1648 if (cmdcode == SLI_CTNS_GID_FT)
1649 bpl->tus.f.bdeSize = GID_REQUEST_SZ;
1650 else if (cmdcode == SLI_CTNS_GID_PT)
1651 bpl->tus.f.bdeSize = GID_REQUEST_SZ;
1652 else if (cmdcode == SLI_CTNS_GFF_ID)
1653 bpl->tus.f.bdeSize = GFF_REQUEST_SZ;
1654 else if (cmdcode == SLI_CTNS_GFT_ID)
1655 bpl->tus.f.bdeSize = GFT_REQUEST_SZ;
1656 else if (cmdcode == SLI_CTNS_RFT_ID)
1657 bpl->tus.f.bdeSize = RFT_REQUEST_SZ;
1658 else if (cmdcode == SLI_CTNS_RNN_ID)
1659 bpl->tus.f.bdeSize = RNN_REQUEST_SZ;
1660 else if (cmdcode == SLI_CTNS_RSPN_ID)
1661 bpl->tus.f.bdeSize = RSPN_REQUEST_SZ;
1662 else if (cmdcode == SLI_CTNS_RSNN_NN)
1663 bpl->tus.f.bdeSize = RSNN_REQUEST_SZ;
1664 else if (cmdcode == SLI_CTNS_DA_ID)
1665 bpl->tus.f.bdeSize = DA_ID_REQUEST_SZ;
1666 else if (cmdcode == SLI_CTNS_RFF_ID)
1667 bpl->tus.f.bdeSize = RFF_REQUEST_SZ;
1669 bpl->tus.f.bdeSize = 0;
1670 bpl->tus.w = le32_to_cpu(bpl->tus.w);
1672 CtReq = (struct lpfc_sli_ct_request *) mp->virt;
1673 memset(CtReq, 0, sizeof(struct lpfc_sli_ct_request));
1674 CtReq->RevisionId.bits.Revision = SLI_CT_REVISION;
1675 CtReq->RevisionId.bits.InId = 0;
1676 CtReq->FsType = SLI_CT_DIRECTORY_SERVICE;
1677 CtReq->FsSubType = SLI_CT_DIRECTORY_NAME_SERVER;
1678 CtReq->CommandResponse.bits.Size = 0;
1680 case SLI_CTNS_GID_FT:
1681 CtReq->CommandResponse.bits.CmdRsp =
1682 cpu_to_be16(SLI_CTNS_GID_FT);
1683 CtReq->un.gid.Fc4Type = context;
1685 if (vport->port_state < LPFC_NS_QRY)
1686 vport->port_state = LPFC_NS_QRY;
1687 lpfc_set_disctmo(vport);
1688 cmpl = lpfc_cmpl_ct_cmd_gid_ft;
1689 rsp_size = FC_MAX_NS_RSP;
1692 case SLI_CTNS_GID_PT:
1693 CtReq->CommandResponse.bits.CmdRsp =
1694 cpu_to_be16(SLI_CTNS_GID_PT);
1695 CtReq->un.gid.PortType = context;
1697 if (vport->port_state < LPFC_NS_QRY)
1698 vport->port_state = LPFC_NS_QRY;
1699 lpfc_set_disctmo(vport);
1700 cmpl = lpfc_cmpl_ct_cmd_gid_pt;
1701 rsp_size = FC_MAX_NS_RSP;
1704 case SLI_CTNS_GFF_ID:
1705 CtReq->CommandResponse.bits.CmdRsp =
1706 cpu_to_be16(SLI_CTNS_GFF_ID);
1707 CtReq->un.gff.PortId = cpu_to_be32(context);
1708 cmpl = lpfc_cmpl_ct_cmd_gff_id;
1711 case SLI_CTNS_GFT_ID:
1712 CtReq->CommandResponse.bits.CmdRsp =
1713 cpu_to_be16(SLI_CTNS_GFT_ID);
1714 CtReq->un.gft.PortId = cpu_to_be32(context);
1715 cmpl = lpfc_cmpl_ct_cmd_gft_id;
1718 case SLI_CTNS_RFT_ID:
1719 vport->ct_flags &= ~FC_CT_RFT_ID;
1720 CtReq->CommandResponse.bits.CmdRsp =
1721 cpu_to_be16(SLI_CTNS_RFT_ID);
1722 CtReq->un.rft.PortId = cpu_to_be32(vport->fc_myDID);
1724 /* Register FC4 FCP type if enabled. */
1725 if (vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH ||
1726 vport->cfg_enable_fc4_type == LPFC_ENABLE_FCP)
1727 CtReq->un.rft.fcpReg = 1;
1729 /* Register NVME type if enabled. Defined LE and swapped.
1730 * rsvd[0] is used as word1 because of the hard-coded
1731 * word0 usage in the ct_request data structure.
1733 if (vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH ||
1734 vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME)
1735 CtReq->un.rft.rsvd[0] =
1736 cpu_to_be32(LPFC_FC4_TYPE_BITMASK);
1738 ptr = (uint32_t *)CtReq;
1739 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1740 "6433 Issue RFT (%s %s): %08x %08x %08x %08x "
1741 "%08x %08x %08x %08x\n",
1742 CtReq->un.rft.fcpReg ? "FCP" : " ",
1743 CtReq->un.rft.rsvd[0] ? "NVME" : " ",
1744 *ptr, *(ptr + 1), *(ptr + 2), *(ptr + 3),
1745 *(ptr + 4), *(ptr + 5),
1746 *(ptr + 6), *(ptr + 7));
1747 cmpl = lpfc_cmpl_ct_cmd_rft_id;
1750 case SLI_CTNS_RNN_ID:
1751 vport->ct_flags &= ~FC_CT_RNN_ID;
1752 CtReq->CommandResponse.bits.CmdRsp =
1753 cpu_to_be16(SLI_CTNS_RNN_ID);
1754 CtReq->un.rnn.PortId = cpu_to_be32(vport->fc_myDID);
1755 memcpy(CtReq->un.rnn.wwnn, &vport->fc_nodename,
1756 sizeof(struct lpfc_name));
1757 cmpl = lpfc_cmpl_ct_cmd_rnn_id;
1760 case SLI_CTNS_RSPN_ID:
1761 vport->ct_flags &= ~FC_CT_RSPN_ID;
1762 CtReq->CommandResponse.bits.CmdRsp =
1763 cpu_to_be16(SLI_CTNS_RSPN_ID);
1764 CtReq->un.rspn.PortId = cpu_to_be32(vport->fc_myDID);
1765 size = sizeof(CtReq->un.rspn.symbname);
1766 CtReq->un.rspn.len =
1767 lpfc_vport_symbolic_port_name(vport,
1768 CtReq->un.rspn.symbname, size);
1769 cmpl = lpfc_cmpl_ct_cmd_rspn_id;
1771 case SLI_CTNS_RSNN_NN:
1772 vport->ct_flags &= ~FC_CT_RSNN_NN;
1773 CtReq->CommandResponse.bits.CmdRsp =
1774 cpu_to_be16(SLI_CTNS_RSNN_NN);
1775 memcpy(CtReq->un.rsnn.wwnn, &vport->fc_nodename,
1776 sizeof(struct lpfc_name));
1777 size = sizeof(CtReq->un.rsnn.symbname);
1778 CtReq->un.rsnn.len =
1779 lpfc_vport_symbolic_node_name(vport,
1780 CtReq->un.rsnn.symbname, size);
1781 cmpl = lpfc_cmpl_ct_cmd_rsnn_nn;
1783 case SLI_CTNS_DA_ID:
1784 /* Implement DA_ID Nameserver request */
1785 CtReq->CommandResponse.bits.CmdRsp =
1786 cpu_to_be16(SLI_CTNS_DA_ID);
1787 CtReq->un.da_id.port_id = cpu_to_be32(vport->fc_myDID);
1788 cmpl = lpfc_cmpl_ct_cmd_da_id;
1790 case SLI_CTNS_RFF_ID:
1791 vport->ct_flags &= ~FC_CT_RFF_ID;
1792 CtReq->CommandResponse.bits.CmdRsp =
1793 cpu_to_be16(SLI_CTNS_RFF_ID);
1794 CtReq->un.rff.PortId = cpu_to_be32(vport->fc_myDID);
1795 CtReq->un.rff.fbits = FC4_FEATURE_INIT;
1797 /* The driver always supports FC_TYPE_FCP. However, the
1798 * caller can specify NVME (type x28) as well. But only
1799 * these that FC4 type is supported.
1801 if (((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
1802 (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) &&
1803 (context == FC_TYPE_NVME)) {
1804 if ((vport == phba->pport) && phba->nvmet_support) {
1805 CtReq->un.rff.fbits = (FC4_FEATURE_TARGET |
1806 FC4_FEATURE_NVME_DISC);
1807 lpfc_nvmet_update_targetport(phba);
1809 lpfc_nvme_update_localport(vport);
1811 CtReq->un.rff.type_code = context;
1813 } else if (((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
1814 (vport->cfg_enable_fc4_type == LPFC_ENABLE_FCP)) &&
1815 (context == FC_TYPE_FCP))
1816 CtReq->un.rff.type_code = context;
1819 goto ns_cmd_free_bmpvirt;
1821 ptr = (uint32_t *)CtReq;
1822 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1823 "6434 Issue RFF (%s): %08x %08x %08x %08x "
1824 "%08x %08x %08x %08x\n",
1825 (context == FC_TYPE_NVME) ? "NVME" : "FCP",
1826 *ptr, *(ptr + 1), *(ptr + 2), *(ptr + 3),
1827 *(ptr + 4), *(ptr + 5),
1828 *(ptr + 6), *(ptr + 7));
1829 cmpl = lpfc_cmpl_ct_cmd_rff_id;
1832 /* The lpfc_ct_cmd/lpfc_get_req shall increment ndlp reference count
1833 * to hold ndlp reference for the corresponding callback function.
1835 if (!lpfc_ct_cmd(vport, mp, bmp, ndlp, cmpl, rsp_size, retry)) {
1836 /* On success, The cmpl function will free the buffers */
1837 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
1838 "Issue CT cmd: cmd:x%x did:x%x",
1839 cmdcode, ndlp->nlp_DID, 0);
1844 /* Decrement ndlp reference count to release ndlp reference held
1845 * for the failed command's callback function.
1849 ns_cmd_free_bmpvirt:
1850 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
1854 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1858 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1859 "0266 Issue NameServer Req x%x err %d Data: x%x x%x\n",
1860 cmdcode, rc, vport->fc_flag, vport->fc_rscn_id_cnt);
1865 * lpfc_cmpl_ct_disc_fdmi - Handle a discovery FDMI completion
1866 * @phba: Pointer to HBA context object.
1867 * @cmdiocb: Pointer to the command IOCBQ.
1868 * @rspiocb: Pointer to the response IOCBQ.
1870 * This function to handle the completion of a driver initiated FDMI
1871 * CT command issued during discovery.
1874 lpfc_cmpl_ct_disc_fdmi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1875 struct lpfc_iocbq *rspiocb)
1877 struct lpfc_vport *vport = cmdiocb->vport;
1878 struct lpfc_dmabuf *inp = cmdiocb->context1;
1879 struct lpfc_dmabuf *outp = cmdiocb->context2;
1880 struct lpfc_sli_ct_request *CTcmd = inp->virt;
1881 struct lpfc_sli_ct_request *CTrsp = outp->virt;
1882 uint16_t fdmi_cmd = CTcmd->CommandResponse.bits.CmdRsp;
1883 uint16_t fdmi_rsp = CTrsp->CommandResponse.bits.CmdRsp;
1884 IOCB_t *irsp = &rspiocb->iocb;
1885 struct lpfc_nodelist *ndlp;
1886 uint32_t latt, cmd, err;
1888 latt = lpfc_els_chk_latt(vport);
1889 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
1890 "FDMI cmpl: status:x%x/x%x latt:%d",
1891 irsp->ulpStatus, irsp->un.ulpWord[4], latt);
1893 if (latt || irsp->ulpStatus) {
1895 /* Look for a retryable error */
1896 if (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) {
1897 switch ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK)) {
1898 case IOERR_SLI_ABORTED:
1899 case IOERR_SLI_DOWN:
1900 /* Driver aborted this IO. No retry as error
1901 * is likely Offline->Online or some adapter
1902 * error. Recovery will try again.
1905 case IOERR_ABORT_IN_PROGRESS:
1906 case IOERR_SEQUENCE_TIMEOUT:
1907 case IOERR_ILLEGAL_FRAME:
1908 case IOERR_NO_RESOURCES:
1909 case IOERR_ILLEGAL_COMMAND:
1911 if (cmdiocb->retry >= LPFC_FDMI_MAX_RETRY)
1914 /* Retry the same FDMI command */
1915 err = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING,
1917 if (err == IOCB_ERROR)
1925 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1926 "0229 FDMI cmd %04x failed, latt = %d "
1927 "ulpStatus: x%x, rid x%x\n",
1928 be16_to_cpu(fdmi_cmd), latt, irsp->ulpStatus,
1929 irsp->un.ulpWord[4]);
1931 lpfc_ct_free_iocb(phba, cmdiocb);
1933 ndlp = lpfc_findnode_did(vport, FDMI_DID);
1934 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
1937 /* Check for a CT LS_RJT response */
1938 cmd = be16_to_cpu(fdmi_cmd);
1939 if (fdmi_rsp == cpu_to_be16(SLI_CT_RESPONSE_FS_RJT)) {
1940 /* FDMI rsp failed */
1941 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1942 "0220 FDMI cmd failed FS_RJT Data: x%x", cmd);
1944 /* Should we fallback to FDMI-2 / FDMI-1 ? */
1947 if (vport->fdmi_hba_mask == LPFC_FDMI2_HBA_ATTR) {
1948 /* Fallback to FDMI-1 */
1949 vport->fdmi_hba_mask = LPFC_FDMI1_HBA_ATTR;
1950 vport->fdmi_port_mask = LPFC_FDMI1_PORT_ATTR;
1952 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA, 0);
1957 if (vport->fdmi_port_mask == LPFC_FDMI2_PORT_ATTR) {
1958 /* Fallback to FDMI-1 */
1959 vport->fdmi_port_mask = LPFC_FDMI1_PORT_ATTR;
1961 lpfc_fdmi_cmd(vport, ndlp, cmd, 0);
1963 if (vport->fdmi_port_mask == LPFC_FDMI2_SMART_ATTR) {
1964 vport->fdmi_port_mask = LPFC_FDMI2_PORT_ATTR;
1965 /* Retry the same command */
1966 lpfc_fdmi_cmd(vport, ndlp, cmd, 0);
1971 if (vport->fdmi_port_mask == LPFC_FDMI2_PORT_ATTR) {
1972 /* Fallback to FDMI-1 */
1973 vport->fdmi_hba_mask = LPFC_FDMI1_HBA_ATTR;
1974 vport->fdmi_port_mask = LPFC_FDMI1_PORT_ATTR;
1976 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA, 0);
1978 if (vport->fdmi_port_mask == LPFC_FDMI2_SMART_ATTR) {
1979 vport->fdmi_port_mask = LPFC_FDMI2_PORT_ATTR;
1980 /* Retry the same command */
1981 lpfc_fdmi_cmd(vport, ndlp, cmd, 0);
1988 * On success, need to cycle thru FDMI registration for discovery
1989 * DHBA -> DPRT -> RHBA -> RPA (physical port)
1990 * DPRT -> RPRT (vports)
1994 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RPA, 0);
1998 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DPRT, 0);
2002 if (vport->port_type == LPFC_PHYSICAL_PORT)
2003 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RHBA, 0);
2005 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RPRT, 0);
2013 * lpfc_fdmi_change_check - Check for changed FDMI parameters
2014 * @vport: pointer to a host virtual N_Port data structure.
2016 * Check how many mapped NPorts we are connected to
2017 * Check if our hostname changed
2018 * Called from hbeat timeout routine to check if any FDMI parameters
2019 * changed. If so, re-register those Attributes.
2022 lpfc_fdmi_change_check(struct lpfc_vport *vport)
2024 struct lpfc_hba *phba = vport->phba;
2025 struct lpfc_nodelist *ndlp;
2028 if (!lpfc_is_link_up(phba))
2031 /* Must be connected to a Fabric */
2032 if (!(vport->fc_flag & FC_FABRIC))
2035 ndlp = lpfc_findnode_did(vport, FDMI_DID);
2036 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
2039 /* Check if system hostname changed */
2040 if (strcmp(phba->os_host_name, init_utsname()->nodename)) {
2041 memset(phba->os_host_name, 0, sizeof(phba->os_host_name));
2042 scnprintf(phba->os_host_name, sizeof(phba->os_host_name), "%s",
2043 init_utsname()->nodename);
2044 lpfc_ns_cmd(vport, SLI_CTNS_RSNN_NN, 0, 0);
2046 /* Since this effects multiple HBA and PORT attributes, we need
2047 * de-register and go thru the whole FDMI registration cycle.
2048 * DHBA -> DPRT -> RHBA -> RPA (physical port)
2049 * DPRT -> RPRT (vports)
2051 if (vport->port_type == LPFC_PHYSICAL_PORT)
2052 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA, 0);
2054 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DPRT, 0);
2056 /* Since this code path registers all the port attributes
2057 * we can just return without further checking.
2062 if (!(vport->fdmi_port_mask & LPFC_FDMI_PORT_ATTR_num_disc))
2065 /* Check if the number of mapped NPorts changed */
2066 cnt = lpfc_find_map_node(vport);
2067 if (cnt == vport->fdmi_num_disc)
2070 if (vport->port_type == LPFC_PHYSICAL_PORT) {
2071 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RPA,
2072 LPFC_FDMI_PORT_ATTR_num_disc);
2074 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RPRT,
2075 LPFC_FDMI_PORT_ATTR_num_disc);
2079 /* Routines for all individual HBA attributes */
2081 lpfc_fdmi_hba_attr_wwnn(struct lpfc_vport *vport, struct lpfc_fdmi_attr_def *ad)
2083 struct lpfc_fdmi_attr_entry *ae;
2086 ae = &ad->AttrValue;
2087 memset(ae, 0, sizeof(*ae));
2089 memcpy(&ae->un.AttrWWN, &vport->fc_sparam.nodeName,
2090 sizeof(struct lpfc_name));
2091 size = FOURBYTES + sizeof(struct lpfc_name);
2092 ad->AttrLen = cpu_to_be16(size);
2093 ad->AttrType = cpu_to_be16(RHBA_NODENAME);
2097 lpfc_fdmi_hba_attr_manufacturer(struct lpfc_vport *vport,
2098 struct lpfc_fdmi_attr_def *ad)
2100 struct lpfc_fdmi_attr_entry *ae;
2103 ae = &ad->AttrValue;
2104 memset(ae, 0, sizeof(*ae));
2106 /* This string MUST be consistent with other FC platforms
2107 * supported by Broadcom.
2109 strncpy(ae->un.AttrString,
2110 "Emulex Corporation",
2111 sizeof(ae->un.AttrString));
2112 len = strnlen(ae->un.AttrString,
2113 sizeof(ae->un.AttrString));
2114 len += (len & 3) ? (4 - (len & 3)) : 4;
2115 size = FOURBYTES + len;
2116 ad->AttrLen = cpu_to_be16(size);
2117 ad->AttrType = cpu_to_be16(RHBA_MANUFACTURER);
2122 lpfc_fdmi_hba_attr_sn(struct lpfc_vport *vport, struct lpfc_fdmi_attr_def *ad)
2124 struct lpfc_hba *phba = vport->phba;
2125 struct lpfc_fdmi_attr_entry *ae;
2128 ae = &ad->AttrValue;
2129 memset(ae, 0, sizeof(*ae));
2131 strncpy(ae->un.AttrString, phba->SerialNumber,
2132 sizeof(ae->un.AttrString));
2133 len = strnlen(ae->un.AttrString,
2134 sizeof(ae->un.AttrString));
2135 len += (len & 3) ? (4 - (len & 3)) : 4;
2136 size = FOURBYTES + len;
2137 ad->AttrLen = cpu_to_be16(size);
2138 ad->AttrType = cpu_to_be16(RHBA_SERIAL_NUMBER);
2143 lpfc_fdmi_hba_attr_model(struct lpfc_vport *vport,
2144 struct lpfc_fdmi_attr_def *ad)
2146 struct lpfc_hba *phba = vport->phba;
2147 struct lpfc_fdmi_attr_entry *ae;
2150 ae = &ad->AttrValue;
2151 memset(ae, 0, sizeof(*ae));
2153 strncpy(ae->un.AttrString, phba->ModelName,
2154 sizeof(ae->un.AttrString));
2155 len = strnlen(ae->un.AttrString, sizeof(ae->un.AttrString));
2156 len += (len & 3) ? (4 - (len & 3)) : 4;
2157 size = FOURBYTES + len;
2158 ad->AttrLen = cpu_to_be16(size);
2159 ad->AttrType = cpu_to_be16(RHBA_MODEL);
2164 lpfc_fdmi_hba_attr_description(struct lpfc_vport *vport,
2165 struct lpfc_fdmi_attr_def *ad)
2167 struct lpfc_hba *phba = vport->phba;
2168 struct lpfc_fdmi_attr_entry *ae;
2171 ae = &ad->AttrValue;
2172 memset(ae, 0, sizeof(*ae));
2174 strncpy(ae->un.AttrString, phba->ModelDesc,
2175 sizeof(ae->un.AttrString));
2176 len = strnlen(ae->un.AttrString,
2177 sizeof(ae->un.AttrString));
2178 len += (len & 3) ? (4 - (len & 3)) : 4;
2179 size = FOURBYTES + len;
2180 ad->AttrLen = cpu_to_be16(size);
2181 ad->AttrType = cpu_to_be16(RHBA_MODEL_DESCRIPTION);
2186 lpfc_fdmi_hba_attr_hdw_ver(struct lpfc_vport *vport,
2187 struct lpfc_fdmi_attr_def *ad)
2189 struct lpfc_hba *phba = vport->phba;
2190 lpfc_vpd_t *vp = &phba->vpd;
2191 struct lpfc_fdmi_attr_entry *ae;
2192 uint32_t i, j, incr, size;
2194 ae = &ad->AttrValue;
2195 memset(ae, 0, sizeof(*ae));
2197 /* Convert JEDEC ID to ascii for hardware version */
2198 incr = vp->rev.biuRev;
2199 for (i = 0; i < 8; i++) {
2202 ae->un.AttrString[7 - i] =
2203 (char)((uint8_t) 0x30 +
2206 ae->un.AttrString[7 - i] =
2207 (char)((uint8_t) 0x61 +
2208 (uint8_t) (j - 10));
2211 size = FOURBYTES + 8;
2212 ad->AttrLen = cpu_to_be16(size);
2213 ad->AttrType = cpu_to_be16(RHBA_HARDWARE_VERSION);
2218 lpfc_fdmi_hba_attr_drvr_ver(struct lpfc_vport *vport,
2219 struct lpfc_fdmi_attr_def *ad)
2221 struct lpfc_fdmi_attr_entry *ae;
2224 ae = &ad->AttrValue;
2225 memset(ae, 0, sizeof(*ae));
2227 strncpy(ae->un.AttrString, lpfc_release_version,
2228 sizeof(ae->un.AttrString));
2229 len = strnlen(ae->un.AttrString,
2230 sizeof(ae->un.AttrString));
2231 len += (len & 3) ? (4 - (len & 3)) : 4;
2232 size = FOURBYTES + len;
2233 ad->AttrLen = cpu_to_be16(size);
2234 ad->AttrType = cpu_to_be16(RHBA_DRIVER_VERSION);
2239 lpfc_fdmi_hba_attr_rom_ver(struct lpfc_vport *vport,
2240 struct lpfc_fdmi_attr_def *ad)
2242 struct lpfc_hba *phba = vport->phba;
2243 struct lpfc_fdmi_attr_entry *ae;
2246 ae = &ad->AttrValue;
2247 memset(ae, 0, sizeof(*ae));
2249 if (phba->sli_rev == LPFC_SLI_REV4)
2250 lpfc_decode_firmware_rev(phba, ae->un.AttrString, 1);
2252 strncpy(ae->un.AttrString, phba->OptionROMVersion,
2253 sizeof(ae->un.AttrString));
2254 len = strnlen(ae->un.AttrString,
2255 sizeof(ae->un.AttrString));
2256 len += (len & 3) ? (4 - (len & 3)) : 4;
2257 size = FOURBYTES + len;
2258 ad->AttrLen = cpu_to_be16(size);
2259 ad->AttrType = cpu_to_be16(RHBA_OPTION_ROM_VERSION);
2264 lpfc_fdmi_hba_attr_fmw_ver(struct lpfc_vport *vport,
2265 struct lpfc_fdmi_attr_def *ad)
2267 struct lpfc_hba *phba = vport->phba;
2268 struct lpfc_fdmi_attr_entry *ae;
2271 ae = &ad->AttrValue;
2272 memset(ae, 0, sizeof(*ae));
2274 lpfc_decode_firmware_rev(phba, ae->un.AttrString, 1);
2275 len = strnlen(ae->un.AttrString,
2276 sizeof(ae->un.AttrString));
2277 len += (len & 3) ? (4 - (len & 3)) : 4;
2278 size = FOURBYTES + len;
2279 ad->AttrLen = cpu_to_be16(size);
2280 ad->AttrType = cpu_to_be16(RHBA_FIRMWARE_VERSION);
2285 lpfc_fdmi_hba_attr_os_ver(struct lpfc_vport *vport,
2286 struct lpfc_fdmi_attr_def *ad)
2288 struct lpfc_fdmi_attr_entry *ae;
2291 ae = &ad->AttrValue;
2292 memset(ae, 0, sizeof(*ae));
2294 snprintf(ae->un.AttrString, sizeof(ae->un.AttrString), "%s %s %s",
2295 init_utsname()->sysname,
2296 init_utsname()->release,
2297 init_utsname()->version);
2299 len = strnlen(ae->un.AttrString, sizeof(ae->un.AttrString));
2300 len += (len & 3) ? (4 - (len & 3)) : 4;
2301 size = FOURBYTES + len;
2302 ad->AttrLen = cpu_to_be16(size);
2303 ad->AttrType = cpu_to_be16(RHBA_OS_NAME_VERSION);
2308 lpfc_fdmi_hba_attr_ct_len(struct lpfc_vport *vport,
2309 struct lpfc_fdmi_attr_def *ad)
2311 struct lpfc_fdmi_attr_entry *ae;
2314 ae = &ad->AttrValue;
2316 ae->un.AttrInt = cpu_to_be32(LPFC_MAX_CT_SIZE);
2317 size = FOURBYTES + sizeof(uint32_t);
2318 ad->AttrLen = cpu_to_be16(size);
2319 ad->AttrType = cpu_to_be16(RHBA_MAX_CT_PAYLOAD_LEN);
2324 lpfc_fdmi_hba_attr_symbolic_name(struct lpfc_vport *vport,
2325 struct lpfc_fdmi_attr_def *ad)
2327 struct lpfc_fdmi_attr_entry *ae;
2330 ae = &ad->AttrValue;
2331 memset(ae, 0, sizeof(*ae));
2333 len = lpfc_vport_symbolic_node_name(vport,
2334 ae->un.AttrString, 256);
2335 len += (len & 3) ? (4 - (len & 3)) : 4;
2336 size = FOURBYTES + len;
2337 ad->AttrLen = cpu_to_be16(size);
2338 ad->AttrType = cpu_to_be16(RHBA_SYM_NODENAME);
2343 lpfc_fdmi_hba_attr_vendor_info(struct lpfc_vport *vport,
2344 struct lpfc_fdmi_attr_def *ad)
2346 struct lpfc_fdmi_attr_entry *ae;
2349 ae = &ad->AttrValue;
2351 /* Nothing is defined for this currently */
2352 ae->un.AttrInt = cpu_to_be32(0);
2353 size = FOURBYTES + sizeof(uint32_t);
2354 ad->AttrLen = cpu_to_be16(size);
2355 ad->AttrType = cpu_to_be16(RHBA_VENDOR_INFO);
2360 lpfc_fdmi_hba_attr_num_ports(struct lpfc_vport *vport,
2361 struct lpfc_fdmi_attr_def *ad)
2363 struct lpfc_fdmi_attr_entry *ae;
2366 ae = &ad->AttrValue;
2368 /* Each driver instance corresponds to a single port */
2369 ae->un.AttrInt = cpu_to_be32(1);
2370 size = FOURBYTES + sizeof(uint32_t);
2371 ad->AttrLen = cpu_to_be16(size);
2372 ad->AttrType = cpu_to_be16(RHBA_NUM_PORTS);
2377 lpfc_fdmi_hba_attr_fabric_wwnn(struct lpfc_vport *vport,
2378 struct lpfc_fdmi_attr_def *ad)
2380 struct lpfc_fdmi_attr_entry *ae;
2383 ae = &ad->AttrValue;
2384 memset(ae, 0, sizeof(*ae));
2386 memcpy(&ae->un.AttrWWN, &vport->fabric_nodename,
2387 sizeof(struct lpfc_name));
2388 size = FOURBYTES + sizeof(struct lpfc_name);
2389 ad->AttrLen = cpu_to_be16(size);
2390 ad->AttrType = cpu_to_be16(RHBA_FABRIC_WWNN);
2395 lpfc_fdmi_hba_attr_bios_ver(struct lpfc_vport *vport,
2396 struct lpfc_fdmi_attr_def *ad)
2398 struct lpfc_hba *phba = vport->phba;
2399 struct lpfc_fdmi_attr_entry *ae;
2402 ae = &ad->AttrValue;
2403 memset(ae, 0, sizeof(*ae));
2405 strlcat(ae->un.AttrString, phba->BIOSVersion,
2406 sizeof(ae->un.AttrString));
2407 len = strnlen(ae->un.AttrString,
2408 sizeof(ae->un.AttrString));
2409 len += (len & 3) ? (4 - (len & 3)) : 4;
2410 size = FOURBYTES + len;
2411 ad->AttrLen = cpu_to_be16(size);
2412 ad->AttrType = cpu_to_be16(RHBA_BIOS_VERSION);
2417 lpfc_fdmi_hba_attr_bios_state(struct lpfc_vport *vport,
2418 struct lpfc_fdmi_attr_def *ad)
2420 struct lpfc_fdmi_attr_entry *ae;
2423 ae = &ad->AttrValue;
2425 /* Driver doesn't have access to this information */
2426 ae->un.AttrInt = cpu_to_be32(0);
2427 size = FOURBYTES + sizeof(uint32_t);
2428 ad->AttrLen = cpu_to_be16(size);
2429 ad->AttrType = cpu_to_be16(RHBA_BIOS_STATE);
2434 lpfc_fdmi_hba_attr_vendor_id(struct lpfc_vport *vport,
2435 struct lpfc_fdmi_attr_def *ad)
2437 struct lpfc_fdmi_attr_entry *ae;
2440 ae = &ad->AttrValue;
2441 memset(ae, 0, sizeof(*ae));
2443 strncpy(ae->un.AttrString, "EMULEX",
2444 sizeof(ae->un.AttrString));
2445 len = strnlen(ae->un.AttrString,
2446 sizeof(ae->un.AttrString));
2447 len += (len & 3) ? (4 - (len & 3)) : 4;
2448 size = FOURBYTES + len;
2449 ad->AttrLen = cpu_to_be16(size);
2450 ad->AttrType = cpu_to_be16(RHBA_VENDOR_ID);
2454 /* Routines for all individual PORT attributes */
2456 lpfc_fdmi_port_attr_fc4type(struct lpfc_vport *vport,
2457 struct lpfc_fdmi_attr_def *ad)
2459 struct lpfc_hba *phba = vport->phba;
2460 struct lpfc_fdmi_attr_entry *ae;
2463 ae = &ad->AttrValue;
2464 memset(ae, 0, sizeof(*ae));
2466 ae->un.AttrTypes[2] = 0x01; /* Type 0x8 - FCP */
2467 ae->un.AttrTypes[7] = 0x01; /* Type 0x20 - CT */
2469 /* Check to see if Firmware supports NVME and on physical port */
2470 if ((phba->sli_rev == LPFC_SLI_REV4) && (vport == phba->pport) &&
2471 phba->sli4_hba.pc_sli4_params.nvme)
2472 ae->un.AttrTypes[6] = 0x01; /* Type 0x28 - NVME */
2474 size = FOURBYTES + 32;
2475 ad->AttrLen = cpu_to_be16(size);
2476 ad->AttrType = cpu_to_be16(RPRT_SUPPORTED_FC4_TYPES);
2481 lpfc_fdmi_port_attr_support_speed(struct lpfc_vport *vport,
2482 struct lpfc_fdmi_attr_def *ad)
2484 struct lpfc_hba *phba = vport->phba;
2485 struct lpfc_fdmi_attr_entry *ae;
2488 ae = &ad->AttrValue;
2491 if (!(phba->hba_flag & HBA_FCOE_MODE)) {
2492 if (phba->lmt & LMT_128Gb)
2493 ae->un.AttrInt |= HBA_PORTSPEED_128GFC;
2494 if (phba->lmt & LMT_64Gb)
2495 ae->un.AttrInt |= HBA_PORTSPEED_64GFC;
2496 if (phba->lmt & LMT_32Gb)
2497 ae->un.AttrInt |= HBA_PORTSPEED_32GFC;
2498 if (phba->lmt & LMT_16Gb)
2499 ae->un.AttrInt |= HBA_PORTSPEED_16GFC;
2500 if (phba->lmt & LMT_10Gb)
2501 ae->un.AttrInt |= HBA_PORTSPEED_10GFC;
2502 if (phba->lmt & LMT_8Gb)
2503 ae->un.AttrInt |= HBA_PORTSPEED_8GFC;
2504 if (phba->lmt & LMT_4Gb)
2505 ae->un.AttrInt |= HBA_PORTSPEED_4GFC;
2506 if (phba->lmt & LMT_2Gb)
2507 ae->un.AttrInt |= HBA_PORTSPEED_2GFC;
2508 if (phba->lmt & LMT_1Gb)
2509 ae->un.AttrInt |= HBA_PORTSPEED_1GFC;
2511 /* FCoE links support only one speed */
2512 switch (phba->fc_linkspeed) {
2513 case LPFC_ASYNC_LINK_SPEED_10GBPS:
2514 ae->un.AttrInt = HBA_PORTSPEED_10GE;
2516 case LPFC_ASYNC_LINK_SPEED_25GBPS:
2517 ae->un.AttrInt = HBA_PORTSPEED_25GE;
2519 case LPFC_ASYNC_LINK_SPEED_40GBPS:
2520 ae->un.AttrInt = HBA_PORTSPEED_40GE;
2522 case LPFC_ASYNC_LINK_SPEED_100GBPS:
2523 ae->un.AttrInt = HBA_PORTSPEED_100GE;
2527 ae->un.AttrInt = cpu_to_be32(ae->un.AttrInt);
2528 size = FOURBYTES + sizeof(uint32_t);
2529 ad->AttrLen = cpu_to_be16(size);
2530 ad->AttrType = cpu_to_be16(RPRT_SUPPORTED_SPEED);
2535 lpfc_fdmi_port_attr_speed(struct lpfc_vport *vport,
2536 struct lpfc_fdmi_attr_def *ad)
2538 struct lpfc_hba *phba = vport->phba;
2539 struct lpfc_fdmi_attr_entry *ae;
2542 ae = &ad->AttrValue;
2544 if (!(phba->hba_flag & HBA_FCOE_MODE)) {
2545 switch (phba->fc_linkspeed) {
2546 case LPFC_LINK_SPEED_1GHZ:
2547 ae->un.AttrInt = HBA_PORTSPEED_1GFC;
2549 case LPFC_LINK_SPEED_2GHZ:
2550 ae->un.AttrInt = HBA_PORTSPEED_2GFC;
2552 case LPFC_LINK_SPEED_4GHZ:
2553 ae->un.AttrInt = HBA_PORTSPEED_4GFC;
2555 case LPFC_LINK_SPEED_8GHZ:
2556 ae->un.AttrInt = HBA_PORTSPEED_8GFC;
2558 case LPFC_LINK_SPEED_10GHZ:
2559 ae->un.AttrInt = HBA_PORTSPEED_10GFC;
2561 case LPFC_LINK_SPEED_16GHZ:
2562 ae->un.AttrInt = HBA_PORTSPEED_16GFC;
2564 case LPFC_LINK_SPEED_32GHZ:
2565 ae->un.AttrInt = HBA_PORTSPEED_32GFC;
2567 case LPFC_LINK_SPEED_64GHZ:
2568 ae->un.AttrInt = HBA_PORTSPEED_64GFC;
2570 case LPFC_LINK_SPEED_128GHZ:
2571 ae->un.AttrInt = HBA_PORTSPEED_128GFC;
2574 ae->un.AttrInt = HBA_PORTSPEED_UNKNOWN;
2578 switch (phba->fc_linkspeed) {
2579 case LPFC_ASYNC_LINK_SPEED_10GBPS:
2580 ae->un.AttrInt = HBA_PORTSPEED_10GE;
2582 case LPFC_ASYNC_LINK_SPEED_25GBPS:
2583 ae->un.AttrInt = HBA_PORTSPEED_25GE;
2585 case LPFC_ASYNC_LINK_SPEED_40GBPS:
2586 ae->un.AttrInt = HBA_PORTSPEED_40GE;
2588 case LPFC_ASYNC_LINK_SPEED_100GBPS:
2589 ae->un.AttrInt = HBA_PORTSPEED_100GE;
2592 ae->un.AttrInt = HBA_PORTSPEED_UNKNOWN;
2597 ae->un.AttrInt = cpu_to_be32(ae->un.AttrInt);
2598 size = FOURBYTES + sizeof(uint32_t);
2599 ad->AttrLen = cpu_to_be16(size);
2600 ad->AttrType = cpu_to_be16(RPRT_PORT_SPEED);
2605 lpfc_fdmi_port_attr_max_frame(struct lpfc_vport *vport,
2606 struct lpfc_fdmi_attr_def *ad)
2608 struct serv_parm *hsp;
2609 struct lpfc_fdmi_attr_entry *ae;
2612 ae = &ad->AttrValue;
2614 hsp = (struct serv_parm *)&vport->fc_sparam;
2615 ae->un.AttrInt = (((uint32_t) hsp->cmn.bbRcvSizeMsb & 0x0F) << 8) |
2616 (uint32_t) hsp->cmn.bbRcvSizeLsb;
2617 ae->un.AttrInt = cpu_to_be32(ae->un.AttrInt);
2618 size = FOURBYTES + sizeof(uint32_t);
2619 ad->AttrLen = cpu_to_be16(size);
2620 ad->AttrType = cpu_to_be16(RPRT_MAX_FRAME_SIZE);
2625 lpfc_fdmi_port_attr_os_devname(struct lpfc_vport *vport,
2626 struct lpfc_fdmi_attr_def *ad)
2628 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2629 struct lpfc_fdmi_attr_entry *ae;
2632 ae = &ad->AttrValue;
2633 memset(ae, 0, sizeof(*ae));
2635 snprintf(ae->un.AttrString, sizeof(ae->un.AttrString),
2636 "/sys/class/scsi_host/host%d", shost->host_no);
2637 len = strnlen((char *)ae->un.AttrString,
2638 sizeof(ae->un.AttrString));
2639 len += (len & 3) ? (4 - (len & 3)) : 4;
2640 size = FOURBYTES + len;
2641 ad->AttrLen = cpu_to_be16(size);
2642 ad->AttrType = cpu_to_be16(RPRT_OS_DEVICE_NAME);
2647 lpfc_fdmi_port_attr_host_name(struct lpfc_vport *vport,
2648 struct lpfc_fdmi_attr_def *ad)
2650 struct lpfc_fdmi_attr_entry *ae;
2653 ae = &ad->AttrValue;
2654 memset(ae, 0, sizeof(*ae));
2656 scnprintf(ae->un.AttrString, sizeof(ae->un.AttrString), "%s",
2657 vport->phba->os_host_name);
2659 len = strnlen(ae->un.AttrString, sizeof(ae->un.AttrString));
2660 len += (len & 3) ? (4 - (len & 3)) : 4;
2661 size = FOURBYTES + len;
2662 ad->AttrLen = cpu_to_be16(size);
2663 ad->AttrType = cpu_to_be16(RPRT_HOST_NAME);
2668 lpfc_fdmi_port_attr_wwnn(struct lpfc_vport *vport,
2669 struct lpfc_fdmi_attr_def *ad)
2671 struct lpfc_fdmi_attr_entry *ae;
2674 ae = &ad->AttrValue;
2675 memset(ae, 0, sizeof(*ae));
2677 memcpy(&ae->un.AttrWWN, &vport->fc_sparam.nodeName,
2678 sizeof(struct lpfc_name));
2679 size = FOURBYTES + sizeof(struct lpfc_name);
2680 ad->AttrLen = cpu_to_be16(size);
2681 ad->AttrType = cpu_to_be16(RPRT_NODENAME);
2686 lpfc_fdmi_port_attr_wwpn(struct lpfc_vport *vport,
2687 struct lpfc_fdmi_attr_def *ad)
2689 struct lpfc_fdmi_attr_entry *ae;
2692 ae = &ad->AttrValue;
2693 memset(ae, 0, sizeof(*ae));
2695 memcpy(&ae->un.AttrWWN, &vport->fc_sparam.portName,
2696 sizeof(struct lpfc_name));
2697 size = FOURBYTES + sizeof(struct lpfc_name);
2698 ad->AttrLen = cpu_to_be16(size);
2699 ad->AttrType = cpu_to_be16(RPRT_PORTNAME);
2704 lpfc_fdmi_port_attr_symbolic_name(struct lpfc_vport *vport,
2705 struct lpfc_fdmi_attr_def *ad)
2707 struct lpfc_fdmi_attr_entry *ae;
2710 ae = &ad->AttrValue;
2711 memset(ae, 0, sizeof(*ae));
2713 len = lpfc_vport_symbolic_port_name(vport, ae->un.AttrString, 256);
2714 len += (len & 3) ? (4 - (len & 3)) : 4;
2715 size = FOURBYTES + len;
2716 ad->AttrLen = cpu_to_be16(size);
2717 ad->AttrType = cpu_to_be16(RPRT_SYM_PORTNAME);
2722 lpfc_fdmi_port_attr_port_type(struct lpfc_vport *vport,
2723 struct lpfc_fdmi_attr_def *ad)
2725 struct lpfc_hba *phba = vport->phba;
2726 struct lpfc_fdmi_attr_entry *ae;
2729 ae = &ad->AttrValue;
2730 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP)
2731 ae->un.AttrInt = cpu_to_be32(LPFC_FDMI_PORTTYPE_NLPORT);
2733 ae->un.AttrInt = cpu_to_be32(LPFC_FDMI_PORTTYPE_NPORT);
2734 size = FOURBYTES + sizeof(uint32_t);
2735 ad->AttrLen = cpu_to_be16(size);
2736 ad->AttrType = cpu_to_be16(RPRT_PORT_TYPE);
2741 lpfc_fdmi_port_attr_class(struct lpfc_vport *vport,
2742 struct lpfc_fdmi_attr_def *ad)
2744 struct lpfc_fdmi_attr_entry *ae;
2747 ae = &ad->AttrValue;
2748 ae->un.AttrInt = cpu_to_be32(FC_COS_CLASS2 | FC_COS_CLASS3);
2749 size = FOURBYTES + sizeof(uint32_t);
2750 ad->AttrLen = cpu_to_be16(size);
2751 ad->AttrType = cpu_to_be16(RPRT_SUPPORTED_CLASS);
2756 lpfc_fdmi_port_attr_fabric_wwpn(struct lpfc_vport *vport,
2757 struct lpfc_fdmi_attr_def *ad)
2759 struct lpfc_fdmi_attr_entry *ae;
2762 ae = &ad->AttrValue;
2763 memset(ae, 0, sizeof(*ae));
2765 memcpy(&ae->un.AttrWWN, &vport->fabric_portname,
2766 sizeof(struct lpfc_name));
2767 size = FOURBYTES + sizeof(struct lpfc_name);
2768 ad->AttrLen = cpu_to_be16(size);
2769 ad->AttrType = cpu_to_be16(RPRT_FABRICNAME);
2774 lpfc_fdmi_port_attr_active_fc4type(struct lpfc_vport *vport,
2775 struct lpfc_fdmi_attr_def *ad)
2777 struct lpfc_fdmi_attr_entry *ae;
2780 ae = &ad->AttrValue;
2781 memset(ae, 0, sizeof(*ae));
2783 ae->un.AttrTypes[2] = 0x01; /* Type 0x8 - FCP */
2784 ae->un.AttrTypes[7] = 0x01; /* Type 0x20 - CT */
2786 /* Check to see if NVME is configured or not */
2787 if (vport->phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)
2788 ae->un.AttrTypes[6] = 0x1; /* Type 0x28 - NVME */
2790 size = FOURBYTES + 32;
2791 ad->AttrLen = cpu_to_be16(size);
2792 ad->AttrType = cpu_to_be16(RPRT_ACTIVE_FC4_TYPES);
2797 lpfc_fdmi_port_attr_port_state(struct lpfc_vport *vport,
2798 struct lpfc_fdmi_attr_def *ad)
2800 struct lpfc_fdmi_attr_entry *ae;
2803 ae = &ad->AttrValue;
2804 /* Link Up - operational */
2805 ae->un.AttrInt = cpu_to_be32(LPFC_FDMI_PORTSTATE_ONLINE);
2806 size = FOURBYTES + sizeof(uint32_t);
2807 ad->AttrLen = cpu_to_be16(size);
2808 ad->AttrType = cpu_to_be16(RPRT_PORT_STATE);
2813 lpfc_fdmi_port_attr_num_disc(struct lpfc_vport *vport,
2814 struct lpfc_fdmi_attr_def *ad)
2816 struct lpfc_fdmi_attr_entry *ae;
2819 ae = &ad->AttrValue;
2820 vport->fdmi_num_disc = lpfc_find_map_node(vport);
2821 ae->un.AttrInt = cpu_to_be32(vport->fdmi_num_disc);
2822 size = FOURBYTES + sizeof(uint32_t);
2823 ad->AttrLen = cpu_to_be16(size);
2824 ad->AttrType = cpu_to_be16(RPRT_DISC_PORT);
2829 lpfc_fdmi_port_attr_nportid(struct lpfc_vport *vport,
2830 struct lpfc_fdmi_attr_def *ad)
2832 struct lpfc_fdmi_attr_entry *ae;
2835 ae = &ad->AttrValue;
2836 ae->un.AttrInt = cpu_to_be32(vport->fc_myDID);
2837 size = FOURBYTES + sizeof(uint32_t);
2838 ad->AttrLen = cpu_to_be16(size);
2839 ad->AttrType = cpu_to_be16(RPRT_PORT_ID);
2844 lpfc_fdmi_smart_attr_service(struct lpfc_vport *vport,
2845 struct lpfc_fdmi_attr_def *ad)
2847 struct lpfc_fdmi_attr_entry *ae;
2850 ae = &ad->AttrValue;
2851 memset(ae, 0, sizeof(*ae));
2853 strncpy(ae->un.AttrString, "Smart SAN Initiator",
2854 sizeof(ae->un.AttrString));
2855 len = strnlen(ae->un.AttrString,
2856 sizeof(ae->un.AttrString));
2857 len += (len & 3) ? (4 - (len & 3)) : 4;
2858 size = FOURBYTES + len;
2859 ad->AttrLen = cpu_to_be16(size);
2860 ad->AttrType = cpu_to_be16(RPRT_SMART_SERVICE);
2865 lpfc_fdmi_smart_attr_guid(struct lpfc_vport *vport,
2866 struct lpfc_fdmi_attr_def *ad)
2868 struct lpfc_fdmi_attr_entry *ae;
2871 ae = &ad->AttrValue;
2872 memset(ae, 0, sizeof(*ae));
2874 memcpy(&ae->un.AttrString, &vport->fc_sparam.nodeName,
2875 sizeof(struct lpfc_name));
2876 memcpy((((uint8_t *)&ae->un.AttrString) +
2877 sizeof(struct lpfc_name)),
2878 &vport->fc_sparam.portName, sizeof(struct lpfc_name));
2879 size = FOURBYTES + (2 * sizeof(struct lpfc_name));
2880 ad->AttrLen = cpu_to_be16(size);
2881 ad->AttrType = cpu_to_be16(RPRT_SMART_GUID);
2886 lpfc_fdmi_smart_attr_version(struct lpfc_vport *vport,
2887 struct lpfc_fdmi_attr_def *ad)
2889 struct lpfc_fdmi_attr_entry *ae;
2892 ae = &ad->AttrValue;
2893 memset(ae, 0, sizeof(*ae));
2895 strncpy(ae->un.AttrString, "Smart SAN Version 2.0",
2896 sizeof(ae->un.AttrString));
2897 len = strnlen(ae->un.AttrString,
2898 sizeof(ae->un.AttrString));
2899 len += (len & 3) ? (4 - (len & 3)) : 4;
2900 size = FOURBYTES + len;
2901 ad->AttrLen = cpu_to_be16(size);
2902 ad->AttrType = cpu_to_be16(RPRT_SMART_VERSION);
2907 lpfc_fdmi_smart_attr_model(struct lpfc_vport *vport,
2908 struct lpfc_fdmi_attr_def *ad)
2910 struct lpfc_hba *phba = vport->phba;
2911 struct lpfc_fdmi_attr_entry *ae;
2914 ae = &ad->AttrValue;
2915 memset(ae, 0, sizeof(*ae));
2917 strncpy(ae->un.AttrString, phba->ModelName,
2918 sizeof(ae->un.AttrString));
2919 len = strnlen(ae->un.AttrString, sizeof(ae->un.AttrString));
2920 len += (len & 3) ? (4 - (len & 3)) : 4;
2921 size = FOURBYTES + len;
2922 ad->AttrLen = cpu_to_be16(size);
2923 ad->AttrType = cpu_to_be16(RPRT_SMART_MODEL);
2928 lpfc_fdmi_smart_attr_port_info(struct lpfc_vport *vport,
2929 struct lpfc_fdmi_attr_def *ad)
2931 struct lpfc_fdmi_attr_entry *ae;
2934 ae = &ad->AttrValue;
2936 /* SRIOV (type 3) is not supported */
2938 ae->un.AttrInt = cpu_to_be32(2); /* NPIV */
2940 ae->un.AttrInt = cpu_to_be32(1); /* Physical */
2941 size = FOURBYTES + sizeof(uint32_t);
2942 ad->AttrLen = cpu_to_be16(size);
2943 ad->AttrType = cpu_to_be16(RPRT_SMART_PORT_INFO);
2948 lpfc_fdmi_smart_attr_qos(struct lpfc_vport *vport,
2949 struct lpfc_fdmi_attr_def *ad)
2951 struct lpfc_fdmi_attr_entry *ae;
2954 ae = &ad->AttrValue;
2955 ae->un.AttrInt = cpu_to_be32(0);
2956 size = FOURBYTES + sizeof(uint32_t);
2957 ad->AttrLen = cpu_to_be16(size);
2958 ad->AttrType = cpu_to_be16(RPRT_SMART_QOS);
2963 lpfc_fdmi_smart_attr_security(struct lpfc_vport *vport,
2964 struct lpfc_fdmi_attr_def *ad)
2966 struct lpfc_fdmi_attr_entry *ae;
2969 ae = &ad->AttrValue;
2970 ae->un.AttrInt = cpu_to_be32(1);
2971 size = FOURBYTES + sizeof(uint32_t);
2972 ad->AttrLen = cpu_to_be16(size);
2973 ad->AttrType = cpu_to_be16(RPRT_SMART_SECURITY);
2977 /* RHBA attribute jump table */
2978 int (*lpfc_fdmi_hba_action[])
2979 (struct lpfc_vport *vport, struct lpfc_fdmi_attr_def *ad) = {
2980 /* Action routine Mask bit Attribute type */
2981 lpfc_fdmi_hba_attr_wwnn, /* bit0 RHBA_NODENAME */
2982 lpfc_fdmi_hba_attr_manufacturer, /* bit1 RHBA_MANUFACTURER */
2983 lpfc_fdmi_hba_attr_sn, /* bit2 RHBA_SERIAL_NUMBER */
2984 lpfc_fdmi_hba_attr_model, /* bit3 RHBA_MODEL */
2985 lpfc_fdmi_hba_attr_description, /* bit4 RHBA_MODEL_DESCRIPTION */
2986 lpfc_fdmi_hba_attr_hdw_ver, /* bit5 RHBA_HARDWARE_VERSION */
2987 lpfc_fdmi_hba_attr_drvr_ver, /* bit6 RHBA_DRIVER_VERSION */
2988 lpfc_fdmi_hba_attr_rom_ver, /* bit7 RHBA_OPTION_ROM_VERSION */
2989 lpfc_fdmi_hba_attr_fmw_ver, /* bit8 RHBA_FIRMWARE_VERSION */
2990 lpfc_fdmi_hba_attr_os_ver, /* bit9 RHBA_OS_NAME_VERSION */
2991 lpfc_fdmi_hba_attr_ct_len, /* bit10 RHBA_MAX_CT_PAYLOAD_LEN */
2992 lpfc_fdmi_hba_attr_symbolic_name, /* bit11 RHBA_SYM_NODENAME */
2993 lpfc_fdmi_hba_attr_vendor_info, /* bit12 RHBA_VENDOR_INFO */
2994 lpfc_fdmi_hba_attr_num_ports, /* bit13 RHBA_NUM_PORTS */
2995 lpfc_fdmi_hba_attr_fabric_wwnn, /* bit14 RHBA_FABRIC_WWNN */
2996 lpfc_fdmi_hba_attr_bios_ver, /* bit15 RHBA_BIOS_VERSION */
2997 lpfc_fdmi_hba_attr_bios_state, /* bit16 RHBA_BIOS_STATE */
2998 lpfc_fdmi_hba_attr_vendor_id, /* bit17 RHBA_VENDOR_ID */
3001 /* RPA / RPRT attribute jump table */
3002 int (*lpfc_fdmi_port_action[])
3003 (struct lpfc_vport *vport, struct lpfc_fdmi_attr_def *ad) = {
3004 /* Action routine Mask bit Attribute type */
3005 lpfc_fdmi_port_attr_fc4type, /* bit0 RPRT_SUPPORT_FC4_TYPES */
3006 lpfc_fdmi_port_attr_support_speed, /* bit1 RPRT_SUPPORTED_SPEED */
3007 lpfc_fdmi_port_attr_speed, /* bit2 RPRT_PORT_SPEED */
3008 lpfc_fdmi_port_attr_max_frame, /* bit3 RPRT_MAX_FRAME_SIZE */
3009 lpfc_fdmi_port_attr_os_devname, /* bit4 RPRT_OS_DEVICE_NAME */
3010 lpfc_fdmi_port_attr_host_name, /* bit5 RPRT_HOST_NAME */
3011 lpfc_fdmi_port_attr_wwnn, /* bit6 RPRT_NODENAME */
3012 lpfc_fdmi_port_attr_wwpn, /* bit7 RPRT_PORTNAME */
3013 lpfc_fdmi_port_attr_symbolic_name, /* bit8 RPRT_SYM_PORTNAME */
3014 lpfc_fdmi_port_attr_port_type, /* bit9 RPRT_PORT_TYPE */
3015 lpfc_fdmi_port_attr_class, /* bit10 RPRT_SUPPORTED_CLASS */
3016 lpfc_fdmi_port_attr_fabric_wwpn, /* bit11 RPRT_FABRICNAME */
3017 lpfc_fdmi_port_attr_active_fc4type, /* bit12 RPRT_ACTIVE_FC4_TYPES */
3018 lpfc_fdmi_port_attr_port_state, /* bit13 RPRT_PORT_STATE */
3019 lpfc_fdmi_port_attr_num_disc, /* bit14 RPRT_DISC_PORT */
3020 lpfc_fdmi_port_attr_nportid, /* bit15 RPRT_PORT_ID */
3021 lpfc_fdmi_smart_attr_service, /* bit16 RPRT_SMART_SERVICE */
3022 lpfc_fdmi_smart_attr_guid, /* bit17 RPRT_SMART_GUID */
3023 lpfc_fdmi_smart_attr_version, /* bit18 RPRT_SMART_VERSION */
3024 lpfc_fdmi_smart_attr_model, /* bit19 RPRT_SMART_MODEL */
3025 lpfc_fdmi_smart_attr_port_info, /* bit20 RPRT_SMART_PORT_INFO */
3026 lpfc_fdmi_smart_attr_qos, /* bit21 RPRT_SMART_QOS */
3027 lpfc_fdmi_smart_attr_security, /* bit22 RPRT_SMART_SECURITY */
3031 * lpfc_fdmi_cmd - Build and send a FDMI cmd to the specified NPort
3032 * @vport: pointer to a host virtual N_Port data structure.
3033 * @ndlp: ndlp to send FDMI cmd to (if NULL use FDMI_DID)
3034 * @cmdcode: FDMI command to send
3035 * @new_mask: Mask of HBA or PORT Attributes to send
3037 * Builds and sends a FDMI command using the CT subsystem.
3040 lpfc_fdmi_cmd(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
3041 int cmdcode, uint32_t new_mask)
3043 struct lpfc_hba *phba = vport->phba;
3044 struct lpfc_dmabuf *mp, *bmp;
3045 struct lpfc_sli_ct_request *CtReq;
3046 struct ulp_bde64 *bpl;
3051 struct lpfc_fdmi_reg_hba *rh;
3052 struct lpfc_fdmi_port_entry *pe;
3053 struct lpfc_fdmi_reg_portattr *pab = NULL;
3054 struct lpfc_fdmi_attr_block *ab = NULL;
3055 int (*func)(struct lpfc_vport *vport, struct lpfc_fdmi_attr_def *ad);
3056 void (*cmpl)(struct lpfc_hba *, struct lpfc_iocbq *,
3057 struct lpfc_iocbq *);
3059 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
3062 cmpl = lpfc_cmpl_ct_disc_fdmi; /* called from discovery */
3064 /* fill in BDEs for command */
3065 /* Allocate buffer for command payload */
3066 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
3070 mp->virt = lpfc_mbuf_alloc(phba, 0, &(mp->phys));
3072 goto fdmi_cmd_free_mp;
3074 /* Allocate buffer for Buffer ptr list */
3075 bmp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
3077 goto fdmi_cmd_free_mpvirt;
3079 bmp->virt = lpfc_mbuf_alloc(phba, 0, &(bmp->phys));
3081 goto fdmi_cmd_free_bmp;
3083 INIT_LIST_HEAD(&mp->list);
3084 INIT_LIST_HEAD(&bmp->list);
3087 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
3088 "0218 FDMI Request Data: x%x x%x x%x\n",
3089 vport->fc_flag, vport->port_state, cmdcode);
3090 CtReq = (struct lpfc_sli_ct_request *)mp->virt;
3092 /* First populate the CT_IU preamble */
3093 memset(CtReq, 0, sizeof(struct lpfc_sli_ct_request));
3094 CtReq->RevisionId.bits.Revision = SLI_CT_REVISION;
3095 CtReq->RevisionId.bits.InId = 0;
3097 CtReq->FsType = SLI_CT_MANAGEMENT_SERVICE;
3098 CtReq->FsSubType = SLI_CT_FDMI_Subtypes;
3100 CtReq->CommandResponse.bits.CmdRsp = cpu_to_be16(cmdcode);
3101 rsp_size = LPFC_BPL_SIZE;
3104 /* Next fill in the specific FDMI cmd information */
3108 rh = (struct lpfc_fdmi_reg_hba *)&CtReq->un.PortID;
3109 /* HBA Identifier */
3110 memcpy(&rh->hi.PortName, &phba->pport->fc_sparam.portName,
3111 sizeof(struct lpfc_name));
3113 if (cmdcode == SLI_MGMT_RHBA) {
3114 /* Registered Port List */
3115 /* One entry (port) per adapter */
3116 rh->rpl.EntryCnt = cpu_to_be32(1);
3117 memcpy(&rh->rpl.pe.PortName,
3118 &phba->pport->fc_sparam.portName,
3119 sizeof(struct lpfc_name));
3121 /* point to the HBA attribute block */
3122 size = 2 * sizeof(struct lpfc_name) +
3125 size = sizeof(struct lpfc_name);
3127 ab = (struct lpfc_fdmi_attr_block *)((uint8_t *)rh + size);
3134 mask = vport->fdmi_hba_mask;
3136 /* Mask will dictate what attributes to build in the request */
3139 func = lpfc_fdmi_hba_action[bit_pos];
3141 (struct lpfc_fdmi_attr_def *)
3142 ((uint8_t *)rh + size));
3145 (LPFC_BPL_SIZE - LPFC_CT_PREAMBLE))
3152 ab->EntryCnt = cpu_to_be32(ab->EntryCnt);
3154 size = GID_REQUEST_SZ - 4 + size;
3159 pab = (struct lpfc_fdmi_reg_portattr *)&CtReq->un.PortID;
3160 if (cmdcode == SLI_MGMT_RPRT) {
3161 rh = (struct lpfc_fdmi_reg_hba *)pab;
3162 /* HBA Identifier */
3163 memcpy(&rh->hi.PortName,
3164 &phba->pport->fc_sparam.portName,
3165 sizeof(struct lpfc_name));
3166 pab = (struct lpfc_fdmi_reg_portattr *)
3167 ((uint8_t *)pab + sizeof(struct lpfc_name));
3170 memcpy((uint8_t *)&pab->PortName,
3171 (uint8_t *)&vport->fc_sparam.portName,
3172 sizeof(struct lpfc_name));
3173 size += sizeof(struct lpfc_name) + FOURBYTES;
3174 pab->ab.EntryCnt = 0;
3179 mask = vport->fdmi_port_mask;
3181 /* Mask will dictate what attributes to build in the request */
3184 func = lpfc_fdmi_port_action[bit_pos];
3186 (struct lpfc_fdmi_attr_def *)
3187 ((uint8_t *)pab + size));
3190 (LPFC_BPL_SIZE - LPFC_CT_PREAMBLE))
3197 pab->ab.EntryCnt = cpu_to_be32(pab->ab.EntryCnt);
3199 if (cmdcode == SLI_MGMT_RPRT)
3200 size += sizeof(struct lpfc_name);
3201 size = GID_REQUEST_SZ - 4 + size;
3206 rsp_size = FC_MAX_NS_RSP;
3210 pe = (struct lpfc_fdmi_port_entry *)&CtReq->un.PortID;
3211 memcpy((uint8_t *)&pe->PortName,
3212 (uint8_t *)&vport->fc_sparam.portName,
3213 sizeof(struct lpfc_name));
3214 size = GID_REQUEST_SZ - 4 + sizeof(struct lpfc_name);
3219 rsp_size = FC_MAX_NS_RSP;
3223 pe = (struct lpfc_fdmi_port_entry *)&CtReq->un.PortID;
3224 memcpy((uint8_t *)&pe->PortName,
3225 (uint8_t *)&vport->fc_sparam.portName,
3226 sizeof(struct lpfc_name));
3227 size = GID_REQUEST_SZ - 4 + sizeof(struct lpfc_name);
3230 size = GID_REQUEST_SZ - 4;
3233 lpfc_printf_vlog(vport, KERN_WARNING, LOG_DISCOVERY,
3234 "0298 FDMI cmdcode x%x not supported\n",
3236 goto fdmi_cmd_free_bmpvirt;
3238 CtReq->CommandResponse.bits.Size = cpu_to_be16(rsp_size);
3240 bpl = (struct ulp_bde64 *)bmp->virt;
3241 bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys));
3242 bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys));
3243 bpl->tus.f.bdeFlags = 0;
3244 bpl->tus.f.bdeSize = size;
3247 * The lpfc_ct_cmd/lpfc_get_req shall increment ndlp reference count
3248 * to hold ndlp reference for the corresponding callback function.
3250 if (!lpfc_ct_cmd(vport, mp, bmp, ndlp, cmpl, rsp_size, 0))
3254 * Decrement ndlp reference count to release ndlp reference held
3255 * for the failed command's callback function.
3259 fdmi_cmd_free_bmpvirt:
3260 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
3263 fdmi_cmd_free_mpvirt:
3264 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3268 /* Issue FDMI request failed */
3269 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
3270 "0244 Issue FDMI request failed Data: x%x\n",
3276 * lpfc_delayed_disc_tmo - Timeout handler for delayed discovery timer.
3277 * @t: Context object of the timer.
3279 * This function set the WORKER_DELAYED_DISC_TMO flag and wake up
3280 * the worker thread.
3283 lpfc_delayed_disc_tmo(struct timer_list *t)
3285 struct lpfc_vport *vport = from_timer(vport, t, delayed_disc_tmo);
3286 struct lpfc_hba *phba = vport->phba;
3287 uint32_t tmo_posted;
3288 unsigned long iflag;
3290 spin_lock_irqsave(&vport->work_port_lock, iflag);
3291 tmo_posted = vport->work_port_events & WORKER_DELAYED_DISC_TMO;
3293 vport->work_port_events |= WORKER_DELAYED_DISC_TMO;
3294 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
3297 lpfc_worker_wake_up(phba);
3302 * lpfc_delayed_disc_timeout_handler - Function called by worker thread to
3303 * handle delayed discovery.
3304 * @vport: pointer to a host virtual N_Port data structure.
3306 * This function start nport discovery of the vport.
3309 lpfc_delayed_disc_timeout_handler(struct lpfc_vport *vport)
3311 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3313 spin_lock_irq(shost->host_lock);
3314 if (!(vport->fc_flag & FC_DISC_DELAYED)) {
3315 spin_unlock_irq(shost->host_lock);
3318 vport->fc_flag &= ~FC_DISC_DELAYED;
3319 spin_unlock_irq(shost->host_lock);
3321 lpfc_do_scr_ns_plogi(vport->phba, vport);
3325 lpfc_decode_firmware_rev(struct lpfc_hba *phba, char *fwrevision, int flag)
3327 struct lpfc_sli *psli = &phba->sli;
3328 lpfc_vpd_t *vp = &phba->vpd;
3329 uint32_t b1, b2, b3, b4, i, rev;
3331 uint32_t *ptr, str[4];
3334 if (phba->sli_rev == LPFC_SLI_REV4)
3335 snprintf(fwrevision, FW_REV_STR_SIZE, "%s", vp->rev.opFwName);
3336 else if (vp->rev.rBit) {
3337 if (psli->sli_flag & LPFC_SLI_ACTIVE)
3338 rev = vp->rev.sli2FwRev;
3340 rev = vp->rev.sli1FwRev;
3342 b1 = (rev & 0x0000f000) >> 12;
3343 b2 = (rev & 0x00000f00) >> 8;
3344 b3 = (rev & 0x000000c0) >> 6;
3345 b4 = (rev & 0x00000030) >> 4;
3364 b4 = (rev & 0x0000000f);
3366 if (psli->sli_flag & LPFC_SLI_ACTIVE)
3367 fwname = vp->rev.sli2FwName;
3369 fwname = vp->rev.sli1FwName;
3371 for (i = 0; i < 16; i++)
3372 if (fwname[i] == 0x20)
3375 ptr = (uint32_t*)fwname;
3377 for (i = 0; i < 3; i++)
3378 str[i] = be32_to_cpu(*ptr++);
3382 sprintf(fwrevision, "%d.%d%d (%s)",
3383 b1, b2, b3, (char *)str);
3385 sprintf(fwrevision, "%d.%d%d", b1,
3389 sprintf(fwrevision, "%d.%d%d%c%d (%s)",
3393 sprintf(fwrevision, "%d.%d%d%c%d",
3397 rev = vp->rev.smFwRev;
3399 b1 = (rev & 0xff000000) >> 24;
3400 b2 = (rev & 0x00f00000) >> 20;
3401 b3 = (rev & 0x000f0000) >> 16;
3402 c = (rev & 0x0000ff00) >> 8;
3403 b4 = (rev & 0x000000ff);
3405 sprintf(fwrevision, "%d.%d%d%c%d", b1, b2, b3, c, b4);