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 lpfc_sli_release_iocbq(phba, geniocb);
398 * lpfc_ct_cmd - Build and issue a CT command
399 * @vport: pointer to a host virtual N_Port data structure.
400 * @inmp: Pointer to data buffer for response data.
401 * @bmp: Pointer to BPL for SLI command
402 * @ndlp: Destination NPort nodelist entry
403 * @cmpl: completion routine to call when command completes
405 * This function is called for issuing a CT command.
408 lpfc_ct_cmd(struct lpfc_vport *vport, struct lpfc_dmabuf *inmp,
409 struct lpfc_dmabuf *bmp, struct lpfc_nodelist *ndlp,
410 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
411 struct lpfc_iocbq *),
412 uint32_t rsp_size, uint8_t retry)
414 struct lpfc_hba *phba = vport->phba;
415 struct ulp_bde64 *bpl = (struct ulp_bde64 *) bmp->virt;
416 struct lpfc_dmabuf *outmp;
418 int cmdcode = ((struct lpfc_sli_ct_request *) inmp->virt)->
419 CommandResponse.bits.CmdRsp;
421 bpl++; /* Skip past ct request */
423 /* Put buffer(s) for ct rsp in bpl */
424 outmp = lpfc_alloc_ct_rsp(phba, cmdcode, bpl, rsp_size, &cnt);
428 * Form the CT IOCB. The total number of BDEs in this IOCB
429 * is the single command plus response count from
433 status = lpfc_gen_req(vport, bmp, inmp, outmp, cmpl, ndlp, 0,
436 lpfc_free_ct_rsp(phba, outmp);
443 lpfc_find_vport_by_did(struct lpfc_hba *phba, uint32_t did) {
444 struct lpfc_vport *vport_curr;
447 spin_lock_irqsave(&phba->port_list_lock, flags);
448 list_for_each_entry(vport_curr, &phba->port_list, listentry) {
449 if ((vport_curr->fc_myDID) && (vport_curr->fc_myDID == did)) {
450 spin_unlock_irqrestore(&phba->port_list_lock, flags);
454 spin_unlock_irqrestore(&phba->port_list_lock, flags);
459 lpfc_prep_node_fc4type(struct lpfc_vport *vport, uint32_t Did, uint8_t fc4_type)
461 struct lpfc_nodelist *ndlp;
463 if ((vport->port_type != LPFC_NPIV_PORT) ||
464 !(vport->ct_flags & FC_CT_RFF_ID) || !vport->cfg_restrict_login) {
466 ndlp = lpfc_setup_disc_node(vport, Did);
468 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
469 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
470 "Parse GID_FTrsp: did:x%x flg:x%x x%x",
471 Did, ndlp->nlp_flag, vport->fc_flag);
473 /* By default, the driver expects to support FCP FC4 */
474 if (fc4_type == FC_TYPE_FCP)
475 ndlp->nlp_fc4_type |= NLP_FC4_FCP;
477 if (fc4_type == FC_TYPE_NVME)
478 ndlp->nlp_fc4_type |= NLP_FC4_NVME;
480 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
481 "0238 Process x%06x NameServer Rsp "
482 "Data: x%x x%x x%x x%x x%x\n", Did,
483 ndlp->nlp_flag, ndlp->nlp_fc4_type,
484 ndlp->nlp_state, vport->fc_flag,
485 vport->fc_rscn_id_cnt);
487 /* if ndlp needs to be discovered and prior
488 * state of ndlp hit devloss, change state to
491 if (ndlp->nlp_flag & NLP_NPR_2B_DISC &&
492 ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
493 lpfc_nlp_set_state(vport, ndlp,
497 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
498 "Skip1 GID_FTrsp: did:x%x flg:x%x cnt:%d",
499 Did, vport->fc_flag, vport->fc_rscn_id_cnt);
501 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
502 "0239 Skip x%06x NameServer Rsp "
503 "Data: x%x x%x %p\n",
505 vport->fc_rscn_id_cnt, ndlp);
508 if (!(vport->fc_flag & FC_RSCN_MODE) ||
509 lpfc_rscn_payload_check(vport, Did)) {
510 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
511 "Query GID_FTrsp: did:x%x flg:x%x cnt:%d",
512 Did, vport->fc_flag, vport->fc_rscn_id_cnt);
515 * This NPortID was previously a FCP/NVMe target,
516 * Don't even bother to send GFF_ID.
518 ndlp = lpfc_findnode_did(vport, Did);
519 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
521 (NLP_FCP_TARGET | NLP_NVME_TARGET))) {
522 if (fc4_type == FC_TYPE_FCP)
523 ndlp->nlp_fc4_type |= NLP_FC4_FCP;
524 if (fc4_type == FC_TYPE_NVME)
525 ndlp->nlp_fc4_type |= NLP_FC4_NVME;
526 lpfc_setup_disc_node(vport, Did);
527 } else if (lpfc_ns_cmd(vport, SLI_CTNS_GFF_ID,
529 vport->num_disc_nodes++;
531 lpfc_setup_disc_node(vport, Did);
533 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
534 "Skip2 GID_FTrsp: did:x%x flg:x%x cnt:%d",
535 Did, vport->fc_flag, vport->fc_rscn_id_cnt);
537 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
538 "0245 Skip x%06x NameServer Rsp "
539 "Data: x%x x%x\n", Did,
541 vport->fc_rscn_id_cnt);
547 lpfc_ns_rsp_audit_did(struct lpfc_vport *vport, uint32_t Did, uint8_t fc4_type)
549 struct lpfc_hba *phba = vport->phba;
550 struct lpfc_nodelist *ndlp = NULL;
551 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
554 if (phba->cfg_ns_query == LPFC_NS_QUERY_GID_FT)
558 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
559 "6430 Process %s rsp for %08x type %x %s %s\n",
561 (fc4_type == FC_TYPE_FCP) ? "FCP" : " ",
562 (fc4_type == FC_TYPE_NVME) ? "NVME" : " ");
564 * To conserve rpi's, filter out addresses for other
565 * vports on the same physical HBAs.
567 if (Did != vport->fc_myDID &&
568 (!lpfc_find_vport_by_did(phba, Did) ||
569 vport->cfg_peer_port_login)) {
570 if (!phba->nvmet_support) {
571 /* FCPI/NVMEI path. Process Did */
572 lpfc_prep_node_fc4type(vport, Did, fc4_type);
575 /* NVMET path. NVMET only cares about NVMEI nodes. */
576 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
577 if (ndlp->nlp_type != NLP_NVME_INITIATOR ||
578 ndlp->nlp_state != NLP_STE_UNMAPPED_NODE)
580 spin_lock_irq(shost->host_lock);
581 if (ndlp->nlp_DID == Did)
582 ndlp->nlp_flag &= ~NLP_NVMET_RECOV;
584 ndlp->nlp_flag |= NLP_NVMET_RECOV;
585 spin_unlock_irq(shost->host_lock);
591 lpfc_ns_rsp(struct lpfc_vport *vport, struct lpfc_dmabuf *mp, uint8_t fc4_type,
594 struct lpfc_sli_ct_request *Response =
595 (struct lpfc_sli_ct_request *) mp->virt;
596 struct lpfc_dmabuf *mlast, *next_mp;
597 uint32_t *ctptr = (uint32_t *) & Response->un.gid.PortType;
598 uint32_t Did, CTentry;
600 struct list_head head;
601 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
602 struct lpfc_nodelist *ndlp = NULL;
604 lpfc_set_disctmo(vport);
605 vport->num_disc_nodes = 0;
606 vport->fc_ns_retry = 0;
609 list_add_tail(&head, &mp->list);
610 list_for_each_entry_safe(mp, next_mp, &head, list) {
613 Cnt = Size > FCELSSIZE ? FCELSSIZE : Size;
618 ctptr = (uint32_t *) mlast->virt;
620 Cnt -= 16; /* subtract length of CT header */
622 /* Loop through entire NameServer list of DIDs */
623 while (Cnt >= sizeof(uint32_t)) {
624 /* Get next DID from NameServer List */
626 Did = ((be32_to_cpu(CTentry)) & Mask_DID);
627 lpfc_ns_rsp_audit_did(vport, Did, fc4_type);
628 if (CTentry & (cpu_to_be32(SLI_CT_LAST_ENTRY)))
631 Cnt -= sizeof(uint32_t);
637 /* All GID_FT entries processed. If the driver is running in
638 * in target mode, put impacted nodes into recovery and drop
639 * the RPI to flush outstanding IO.
641 if (vport->phba->nvmet_support) {
642 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
643 if (!(ndlp->nlp_flag & NLP_NVMET_RECOV))
645 lpfc_disc_state_machine(vport, ndlp, NULL,
646 NLP_EVT_DEVICE_RECOVERY);
647 spin_lock_irq(shost->host_lock);
648 ndlp->nlp_flag &= ~NLP_NVMET_RECOV;
649 spin_unlock_irq(shost->host_lock);
659 lpfc_cmpl_ct_cmd_gid_ft(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
660 struct lpfc_iocbq *rspiocb)
662 struct lpfc_vport *vport = cmdiocb->vport;
663 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
665 struct lpfc_dmabuf *outp;
666 struct lpfc_dmabuf *inp;
667 struct lpfc_sli_ct_request *CTrsp;
668 struct lpfc_sli_ct_request *CTreq;
669 struct lpfc_nodelist *ndlp;
672 /* First save ndlp, before we overwrite it */
673 ndlp = cmdiocb->context_un.ndlp;
675 /* we pass cmdiocb to state machine which needs rspiocb as well */
676 cmdiocb->context_un.rsp_iocb = rspiocb;
677 inp = (struct lpfc_dmabuf *) cmdiocb->context1;
678 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
679 irsp = &rspiocb->iocb;
681 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
682 "GID_FT cmpl: status:x%x/x%x rtry:%d",
683 irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_ns_retry);
685 /* Don't bother processing response if vport is being torn down. */
686 if (vport->load_flag & FC_UNLOADING) {
687 if (vport->fc_flag & FC_RSCN_MODE)
688 lpfc_els_flush_rscn(vport);
692 if (lpfc_els_chk_latt(vport)) {
693 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
694 "0216 Link event during NS query\n");
695 if (vport->fc_flag & FC_RSCN_MODE)
696 lpfc_els_flush_rscn(vport);
697 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
700 if (lpfc_error_lost_link(irsp)) {
701 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
702 "0226 NS query failed due to link event\n");
703 if (vport->fc_flag & FC_RSCN_MODE)
704 lpfc_els_flush_rscn(vport);
708 spin_lock_irq(shost->host_lock);
709 if (vport->fc_flag & FC_RSCN_DEFERRED) {
710 vport->fc_flag &= ~FC_RSCN_DEFERRED;
711 spin_unlock_irq(shost->host_lock);
713 /* This is a GID_FT completing so the gidft_inp counter was
714 * incremented before the GID_FT was issued to the wire.
716 if (vport->gidft_inp)
720 * Skip processing the NS response
721 * Re-issue the NS cmd
723 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
724 "0151 Process Deferred RSCN Data: x%x x%x\n",
725 vport->fc_flag, vport->fc_rscn_id_cnt);
726 lpfc_els_handle_rscn(vport);
730 spin_unlock_irq(shost->host_lock);
732 if (irsp->ulpStatus) {
733 /* Check for retry */
734 if (vport->fc_ns_retry < LPFC_MAX_NS_RETRY) {
735 if (irsp->ulpStatus != IOSTAT_LOCAL_REJECT ||
736 (irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
738 vport->fc_ns_retry++;
740 type = lpfc_get_gidft_type(vport, cmdiocb);
744 /* CT command is being retried */
745 rc = lpfc_ns_cmd(vport, SLI_CTNS_GID_FT,
746 vport->fc_ns_retry, type);
749 else { /* Unable to send NS cmd */
750 if (vport->gidft_inp)
754 if (vport->fc_flag & FC_RSCN_MODE)
755 lpfc_els_flush_rscn(vport);
756 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
757 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
758 "0257 GID_FT Query error: 0x%x 0x%x\n",
759 irsp->ulpStatus, vport->fc_ns_retry);
761 /* Good status, continue checking */
762 CTreq = (struct lpfc_sli_ct_request *) inp->virt;
763 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
764 if (CTrsp->CommandResponse.bits.CmdRsp ==
765 cpu_to_be16(SLI_CT_RESPONSE_FS_ACC)) {
766 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
767 "0208 NameServer Rsp Data: x%x x%x "
770 CTreq->un.gid.Fc4Type,
771 vport->num_disc_nodes,
773 irsp->un.genreq64.bdl.bdeSize);
777 CTreq->un.gid.Fc4Type,
778 (uint32_t) (irsp->un.genreq64.bdl.bdeSize));
779 } else if (CTrsp->CommandResponse.bits.CmdRsp ==
780 be16_to_cpu(SLI_CT_RESPONSE_FS_RJT)) {
781 /* NameServer Rsp Error */
782 if ((CTrsp->ReasonCode == SLI_CT_UNABLE_TO_PERFORM_REQ)
783 && (CTrsp->Explanation == SLI_CT_NO_FC4_TYPES)) {
784 lpfc_printf_vlog(vport, KERN_INFO,
786 "0269 No NameServer Entries "
787 "Data: x%x x%x x%x x%x\n",
788 CTrsp->CommandResponse.bits.CmdRsp,
789 (uint32_t) CTrsp->ReasonCode,
790 (uint32_t) CTrsp->Explanation,
793 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
794 "GID_FT no entry cmd:x%x rsn:x%x exp:x%x",
795 (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
796 (uint32_t) CTrsp->ReasonCode,
797 (uint32_t) CTrsp->Explanation);
799 lpfc_printf_vlog(vport, KERN_INFO,
801 "0240 NameServer Rsp Error "
802 "Data: x%x x%x x%x x%x\n",
803 CTrsp->CommandResponse.bits.CmdRsp,
804 (uint32_t) CTrsp->ReasonCode,
805 (uint32_t) CTrsp->Explanation,
808 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
809 "GID_FT rsp err1 cmd:x%x rsn:x%x exp:x%x",
810 (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
811 (uint32_t) CTrsp->ReasonCode,
812 (uint32_t) CTrsp->Explanation);
817 /* NameServer Rsp Error */
818 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
819 "0241 NameServer Rsp Error "
820 "Data: x%x x%x x%x x%x\n",
821 CTrsp->CommandResponse.bits.CmdRsp,
822 (uint32_t) CTrsp->ReasonCode,
823 (uint32_t) CTrsp->Explanation,
826 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
827 "GID_FT rsp err2 cmd:x%x rsn:x%x exp:x%x",
828 (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
829 (uint32_t) CTrsp->ReasonCode,
830 (uint32_t) CTrsp->Explanation);
832 if (vport->gidft_inp)
836 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
837 "4216 GID_FT cmpl inp %d disc %d\n",
838 vport->gidft_inp, vport->num_disc_nodes);
840 /* Link up / RSCN discovery */
841 if ((vport->num_disc_nodes == 0) &&
842 (vport->gidft_inp == 0)) {
844 * The driver has cycled through all Nports in the RSCN payload.
845 * Complete the handling by cleaning up and marking the
846 * current driver state.
848 if (vport->port_state >= LPFC_DISC_AUTH) {
849 if (vport->fc_flag & FC_RSCN_MODE) {
850 lpfc_els_flush_rscn(vport);
851 spin_lock_irq(shost->host_lock);
852 vport->fc_flag |= FC_RSCN_MODE; /* RSCN still */
853 spin_unlock_irq(shost->host_lock);
856 lpfc_els_flush_rscn(vport);
859 lpfc_disc_start(vport);
862 cmdiocb->context_un.ndlp = ndlp; /* Now restore ndlp for free */
863 lpfc_ct_free_iocb(phba, cmdiocb);
868 lpfc_cmpl_ct_cmd_gid_pt(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
869 struct lpfc_iocbq *rspiocb)
871 struct lpfc_vport *vport = cmdiocb->vport;
872 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
874 struct lpfc_dmabuf *outp;
875 struct lpfc_dmabuf *inp;
876 struct lpfc_sli_ct_request *CTrsp;
877 struct lpfc_sli_ct_request *CTreq;
878 struct lpfc_nodelist *ndlp;
881 /* First save ndlp, before we overwrite it */
882 ndlp = cmdiocb->context_un.ndlp;
884 /* we pass cmdiocb to state machine which needs rspiocb as well */
885 cmdiocb->context_un.rsp_iocb = rspiocb;
886 inp = (struct lpfc_dmabuf *)cmdiocb->context1;
887 outp = (struct lpfc_dmabuf *)cmdiocb->context2;
888 irsp = &rspiocb->iocb;
890 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
891 "GID_PT cmpl: status:x%x/x%x rtry:%d",
892 irsp->ulpStatus, irsp->un.ulpWord[4],
895 /* Don't bother processing response if vport is being torn down. */
896 if (vport->load_flag & FC_UNLOADING) {
897 if (vport->fc_flag & FC_RSCN_MODE)
898 lpfc_els_flush_rscn(vport);
902 if (lpfc_els_chk_latt(vport)) {
903 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
904 "4108 Link event during NS query\n");
905 if (vport->fc_flag & FC_RSCN_MODE)
906 lpfc_els_flush_rscn(vport);
907 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
910 if (lpfc_error_lost_link(irsp)) {
911 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
912 "4166 NS query failed due to link event\n");
913 if (vport->fc_flag & FC_RSCN_MODE)
914 lpfc_els_flush_rscn(vport);
918 spin_lock_irq(shost->host_lock);
919 if (vport->fc_flag & FC_RSCN_DEFERRED) {
920 vport->fc_flag &= ~FC_RSCN_DEFERRED;
921 spin_unlock_irq(shost->host_lock);
923 /* This is a GID_PT completing so the gidft_inp counter was
924 * incremented before the GID_PT was issued to the wire.
926 if (vport->gidft_inp)
930 * Skip processing the NS response
931 * Re-issue the NS cmd
933 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
934 "4167 Process Deferred RSCN Data: x%x x%x\n",
935 vport->fc_flag, vport->fc_rscn_id_cnt);
936 lpfc_els_handle_rscn(vport);
940 spin_unlock_irq(shost->host_lock);
942 if (irsp->ulpStatus) {
943 /* Check for retry */
944 if (vport->fc_ns_retry < LPFC_MAX_NS_RETRY) {
945 if (irsp->ulpStatus != IOSTAT_LOCAL_REJECT ||
946 (irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
948 vport->fc_ns_retry++;
950 /* CT command is being retried */
951 rc = lpfc_ns_cmd(vport, SLI_CTNS_GID_PT,
952 vport->fc_ns_retry, GID_PT_N_PORT);
955 else { /* Unable to send NS cmd */
956 if (vport->gidft_inp)
960 if (vport->fc_flag & FC_RSCN_MODE)
961 lpfc_els_flush_rscn(vport);
962 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
963 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
964 "4103 GID_FT Query error: 0x%x 0x%x\n",
965 irsp->ulpStatus, vport->fc_ns_retry);
967 /* Good status, continue checking */
968 CTreq = (struct lpfc_sli_ct_request *)inp->virt;
969 CTrsp = (struct lpfc_sli_ct_request *)outp->virt;
970 if (CTrsp->CommandResponse.bits.CmdRsp ==
971 cpu_to_be16(SLI_CT_RESPONSE_FS_ACC)) {
972 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
973 "4105 NameServer Rsp Data: x%x x%x "
976 CTreq->un.gid.Fc4Type,
977 vport->num_disc_nodes,
979 irsp->un.genreq64.bdl.bdeSize);
983 CTreq->un.gid.Fc4Type,
984 (uint32_t)(irsp->un.genreq64.bdl.bdeSize));
985 } else if (CTrsp->CommandResponse.bits.CmdRsp ==
986 be16_to_cpu(SLI_CT_RESPONSE_FS_RJT)) {
987 /* NameServer Rsp Error */
988 if ((CTrsp->ReasonCode == SLI_CT_UNABLE_TO_PERFORM_REQ)
989 && (CTrsp->Explanation == SLI_CT_NO_FC4_TYPES)) {
991 vport, KERN_INFO, LOG_DISCOVERY,
992 "4106 No NameServer Entries "
993 "Data: x%x x%x x%x x%x\n",
994 CTrsp->CommandResponse.bits.CmdRsp,
995 (uint32_t)CTrsp->ReasonCode,
996 (uint32_t)CTrsp->Explanation,
999 lpfc_debugfs_disc_trc(
1000 vport, LPFC_DISC_TRC_CT,
1001 "GID_PT no entry cmd:x%x rsn:x%x exp:x%x",
1002 (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
1003 (uint32_t)CTrsp->ReasonCode,
1004 (uint32_t)CTrsp->Explanation);
1007 vport, KERN_INFO, LOG_DISCOVERY,
1008 "4107 NameServer Rsp Error "
1009 "Data: x%x x%x x%x x%x\n",
1010 CTrsp->CommandResponse.bits.CmdRsp,
1011 (uint32_t)CTrsp->ReasonCode,
1012 (uint32_t)CTrsp->Explanation,
1015 lpfc_debugfs_disc_trc(
1016 vport, LPFC_DISC_TRC_CT,
1017 "GID_PT rsp err1 cmd:x%x rsn:x%x exp:x%x",
1018 (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
1019 (uint32_t)CTrsp->ReasonCode,
1020 (uint32_t)CTrsp->Explanation);
1023 /* NameServer Rsp Error */
1024 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1025 "4109 NameServer Rsp Error "
1026 "Data: x%x x%x x%x x%x\n",
1027 CTrsp->CommandResponse.bits.CmdRsp,
1028 (uint32_t)CTrsp->ReasonCode,
1029 (uint32_t)CTrsp->Explanation,
1032 lpfc_debugfs_disc_trc(
1033 vport, LPFC_DISC_TRC_CT,
1034 "GID_PT rsp err2 cmd:x%x rsn:x%x exp:x%x",
1035 (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
1036 (uint32_t)CTrsp->ReasonCode,
1037 (uint32_t)CTrsp->Explanation);
1039 if (vport->gidft_inp)
1043 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1044 "6450 GID_PT cmpl inp %d disc %d\n",
1045 vport->gidft_inp, vport->num_disc_nodes);
1047 /* Link up / RSCN discovery */
1048 if ((vport->num_disc_nodes == 0) &&
1049 (vport->gidft_inp == 0)) {
1051 * The driver has cycled through all Nports in the RSCN payload.
1052 * Complete the handling by cleaning up and marking the
1053 * current driver state.
1055 if (vport->port_state >= LPFC_DISC_AUTH) {
1056 if (vport->fc_flag & FC_RSCN_MODE) {
1057 lpfc_els_flush_rscn(vport);
1058 spin_lock_irq(shost->host_lock);
1059 vport->fc_flag |= FC_RSCN_MODE; /* RSCN still */
1060 spin_unlock_irq(shost->host_lock);
1062 lpfc_els_flush_rscn(vport);
1066 lpfc_disc_start(vport);
1069 cmdiocb->context_un.ndlp = ndlp; /* Now restore ndlp for free */
1070 lpfc_ct_free_iocb(phba, cmdiocb);
1074 lpfc_cmpl_ct_cmd_gff_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1075 struct lpfc_iocbq *rspiocb)
1077 struct lpfc_vport *vport = cmdiocb->vport;
1078 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1079 IOCB_t *irsp = &rspiocb->iocb;
1080 struct lpfc_dmabuf *inp = (struct lpfc_dmabuf *) cmdiocb->context1;
1081 struct lpfc_dmabuf *outp = (struct lpfc_dmabuf *) cmdiocb->context2;
1082 struct lpfc_sli_ct_request *CTrsp;
1085 struct lpfc_nodelist *ndlp;
1087 did = ((struct lpfc_sli_ct_request *) inp->virt)->un.gff.PortId;
1088 did = be32_to_cpu(did);
1090 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
1091 "GFF_ID cmpl: status:x%x/x%x did:x%x",
1092 irsp->ulpStatus, irsp->un.ulpWord[4], did);
1094 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
1095 /* Good status, continue checking */
1096 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
1097 fbits = CTrsp->un.gff_acc.fbits[FCP_TYPE_FEATURE_OFFSET];
1099 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1100 "6431 Process GFF_ID rsp for %08x "
1101 "fbits %02x %s %s\n",
1103 (fbits & FC4_FEATURE_INIT) ? "Initiator" : " ",
1104 (fbits & FC4_FEATURE_TARGET) ? "Target" : " ");
1106 if (CTrsp->CommandResponse.bits.CmdRsp ==
1107 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC)) {
1108 if ((fbits & FC4_FEATURE_INIT) &&
1109 !(fbits & FC4_FEATURE_TARGET)) {
1110 lpfc_printf_vlog(vport, KERN_INFO,
1112 "0270 Skip x%x GFF "
1113 "NameServer Rsp Data: (init) "
1114 "x%x x%x\n", did, fbits,
1115 vport->fc_rscn_id_cnt);
1121 /* Check for retry */
1122 if (cmdiocb->retry < LPFC_MAX_NS_RETRY) {
1124 if (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) {
1125 switch ((irsp->un.ulpWord[4] &
1126 IOERR_PARAM_MASK)) {
1128 case IOERR_NO_RESOURCES:
1129 /* We don't increment the retry
1130 * count for this case.
1133 case IOERR_LINK_DOWN:
1134 case IOERR_SLI_ABORTED:
1135 case IOERR_SLI_DOWN:
1146 /* CT command is being retried */
1147 rc = lpfc_ns_cmd(vport, SLI_CTNS_GFF_ID,
1148 cmdiocb->retry, did);
1151 lpfc_ct_free_iocb(phba, cmdiocb);
1156 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1157 "0267 NameServer GFF Rsp "
1158 "x%x Error (%d %d) Data: x%x x%x\n",
1159 did, irsp->ulpStatus, irsp->un.ulpWord[4],
1160 vport->fc_flag, vport->fc_rscn_id_cnt);
1163 /* This is a target port, unregistered port, or the GFF_ID failed */
1164 ndlp = lpfc_setup_disc_node(vport, did);
1165 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
1166 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1167 "0242 Process x%x GFF "
1168 "NameServer Rsp Data: x%x x%x x%x\n",
1169 did, ndlp->nlp_flag, vport->fc_flag,
1170 vport->fc_rscn_id_cnt);
1172 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1173 "0243 Skip x%x GFF "
1174 "NameServer Rsp Data: x%x x%x\n", did,
1175 vport->fc_flag, vport->fc_rscn_id_cnt);
1178 /* Link up / RSCN discovery */
1179 if (vport->num_disc_nodes)
1180 vport->num_disc_nodes--;
1182 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1183 "6451 GFF_ID cmpl inp %d disc %d\n",
1184 vport->gidft_inp, vport->num_disc_nodes);
1186 if (vport->num_disc_nodes == 0) {
1188 * The driver has cycled through all Nports in the RSCN payload.
1189 * Complete the handling by cleaning up and marking the
1190 * current driver state.
1192 if (vport->port_state >= LPFC_DISC_AUTH) {
1193 if (vport->fc_flag & FC_RSCN_MODE) {
1194 lpfc_els_flush_rscn(vport);
1195 spin_lock_irq(shost->host_lock);
1196 vport->fc_flag |= FC_RSCN_MODE; /* RSCN still */
1197 spin_unlock_irq(shost->host_lock);
1200 lpfc_els_flush_rscn(vport);
1202 lpfc_disc_start(vport);
1204 lpfc_ct_free_iocb(phba, cmdiocb);
1209 lpfc_cmpl_ct_cmd_gft_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1210 struct lpfc_iocbq *rspiocb)
1212 struct lpfc_vport *vport = cmdiocb->vport;
1213 IOCB_t *irsp = &rspiocb->iocb;
1214 struct lpfc_dmabuf *inp = (struct lpfc_dmabuf *)cmdiocb->context1;
1215 struct lpfc_dmabuf *outp = (struct lpfc_dmabuf *)cmdiocb->context2;
1216 struct lpfc_sli_ct_request *CTrsp;
1218 struct lpfc_nodelist *ndlp;
1219 uint32_t fc4_data_0, fc4_data_1;
1221 did = ((struct lpfc_sli_ct_request *)inp->virt)->un.gft.PortId;
1222 did = be32_to_cpu(did);
1224 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
1225 "GFT_ID cmpl: status:x%x/x%x did:x%x",
1226 irsp->ulpStatus, irsp->un.ulpWord[4], did);
1228 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
1229 /* Good status, continue checking */
1230 CTrsp = (struct lpfc_sli_ct_request *)outp->virt;
1231 fc4_data_0 = be32_to_cpu(CTrsp->un.gft_acc.fc4_types[0]);
1232 fc4_data_1 = be32_to_cpu(CTrsp->un.gft_acc.fc4_types[1]);
1234 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1235 "6432 Process GFT_ID rsp for %08x "
1236 "Data %08x %08x %s %s\n",
1237 did, fc4_data_0, fc4_data_1,
1238 (fc4_data_0 & LPFC_FC4_TYPE_BITMASK) ?
1240 (fc4_data_1 & LPFC_FC4_TYPE_BITMASK) ?
1243 ndlp = lpfc_findnode_did(vport, did);
1245 /* The bitmask value for FCP and NVME FCP types is
1246 * the same because they are 32 bits distant from
1247 * each other in word0 and word0.
1249 if (fc4_data_0 & LPFC_FC4_TYPE_BITMASK)
1250 ndlp->nlp_fc4_type |= NLP_FC4_FCP;
1251 if (fc4_data_1 & LPFC_FC4_TYPE_BITMASK)
1252 ndlp->nlp_fc4_type |= NLP_FC4_NVME;
1253 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1254 "3064 Setting ndlp x%px, DID x%06x "
1255 "with FC4 x%08x, Data: x%08x x%08x "
1257 ndlp, did, ndlp->nlp_fc4_type,
1258 FC_TYPE_FCP, FC_TYPE_NVME,
1261 if (ndlp->nlp_state == NLP_STE_REG_LOGIN_ISSUE &&
1262 ndlp->nlp_fc4_type) {
1263 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1265 lpfc_nlp_set_state(vport, ndlp,
1266 NLP_STE_PRLI_ISSUE);
1267 lpfc_issue_els_prli(vport, ndlp, 0);
1268 } else if (!ndlp->nlp_fc4_type) {
1269 /* If fc4 type is still unknown, then LOGO */
1270 lpfc_printf_vlog(vport, KERN_INFO,
1272 "6443 Sending LOGO ndlp x%px,"
1273 "DID x%06x with fc4_type: "
1274 "x%08x, state: %d\n",
1275 ndlp, did, ndlp->nlp_fc4_type,
1277 lpfc_issue_els_logo(vport, ndlp, 0);
1278 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1279 lpfc_nlp_set_state(vport, ndlp,
1284 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1285 "3065 GFT_ID failed x%08x\n", irsp->ulpStatus);
1287 lpfc_ct_free_iocb(phba, cmdiocb);
1291 lpfc_cmpl_ct(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1292 struct lpfc_iocbq *rspiocb)
1294 struct lpfc_vport *vport = cmdiocb->vport;
1295 struct lpfc_dmabuf *inp;
1296 struct lpfc_dmabuf *outp;
1298 struct lpfc_sli_ct_request *CTrsp;
1299 struct lpfc_nodelist *ndlp;
1304 /* First save ndlp, before we overwrite it */
1305 ndlp = cmdiocb->context_un.ndlp;
1307 /* we pass cmdiocb to state machine which needs rspiocb as well */
1308 cmdiocb->context_un.rsp_iocb = rspiocb;
1310 inp = (struct lpfc_dmabuf *) cmdiocb->context1;
1311 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
1312 irsp = &rspiocb->iocb;
1314 cmdcode = be16_to_cpu(((struct lpfc_sli_ct_request *) inp->virt)->
1315 CommandResponse.bits.CmdRsp);
1316 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
1318 latt = lpfc_els_chk_latt(vport);
1320 /* RFT request completes status <ulpStatus> CmdRsp <CmdRsp> */
1321 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1322 "0209 CT Request completes, latt %d, "
1323 "ulpStatus x%x CmdRsp x%x, Context x%x, Tag x%x\n",
1324 latt, irsp->ulpStatus,
1325 CTrsp->CommandResponse.bits.CmdRsp,
1326 cmdiocb->iocb.ulpContext, cmdiocb->iocb.ulpIoTag);
1328 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
1329 "CT cmd cmpl: status:x%x/x%x cmd:x%x",
1330 irsp->ulpStatus, irsp->un.ulpWord[4], cmdcode);
1332 if (irsp->ulpStatus) {
1333 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1334 "0268 NS cmd x%x Error (x%x x%x)\n",
1335 cmdcode, irsp->ulpStatus, irsp->un.ulpWord[4]);
1337 if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
1338 (((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
1340 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
1341 IOERR_SLI_ABORTED)))
1344 retry = cmdiocb->retry;
1345 if (retry >= LPFC_MAX_NS_RETRY)
1349 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1350 "0250 Retrying NS cmd %x\n", cmdcode);
1351 rc = lpfc_ns_cmd(vport, cmdcode, retry, 0);
1357 cmdiocb->context_un.ndlp = ndlp; /* Now restore ndlp for free */
1358 lpfc_ct_free_iocb(phba, cmdiocb);
1363 lpfc_cmpl_ct_cmd_rft_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1364 struct lpfc_iocbq *rspiocb)
1366 IOCB_t *irsp = &rspiocb->iocb;
1367 struct lpfc_vport *vport = cmdiocb->vport;
1369 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
1370 struct lpfc_dmabuf *outp;
1371 struct lpfc_sli_ct_request *CTrsp;
1373 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
1374 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
1375 if (CTrsp->CommandResponse.bits.CmdRsp ==
1376 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
1377 vport->ct_flags |= FC_CT_RFT_ID;
1379 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
1384 lpfc_cmpl_ct_cmd_rnn_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1385 struct lpfc_iocbq *rspiocb)
1387 IOCB_t *irsp = &rspiocb->iocb;
1388 struct lpfc_vport *vport = cmdiocb->vport;
1390 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
1391 struct lpfc_dmabuf *outp;
1392 struct lpfc_sli_ct_request *CTrsp;
1394 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
1395 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
1396 if (CTrsp->CommandResponse.bits.CmdRsp ==
1397 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
1398 vport->ct_flags |= FC_CT_RNN_ID;
1400 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
1405 lpfc_cmpl_ct_cmd_rspn_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1406 struct lpfc_iocbq *rspiocb)
1408 IOCB_t *irsp = &rspiocb->iocb;
1409 struct lpfc_vport *vport = cmdiocb->vport;
1411 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
1412 struct lpfc_dmabuf *outp;
1413 struct lpfc_sli_ct_request *CTrsp;
1415 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
1416 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
1417 if (CTrsp->CommandResponse.bits.CmdRsp ==
1418 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
1419 vport->ct_flags |= FC_CT_RSPN_ID;
1421 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
1426 lpfc_cmpl_ct_cmd_rsnn_nn(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1427 struct lpfc_iocbq *rspiocb)
1429 IOCB_t *irsp = &rspiocb->iocb;
1430 struct lpfc_vport *vport = cmdiocb->vport;
1432 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
1433 struct lpfc_dmabuf *outp;
1434 struct lpfc_sli_ct_request *CTrsp;
1436 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
1437 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
1438 if (CTrsp->CommandResponse.bits.CmdRsp ==
1439 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
1440 vport->ct_flags |= FC_CT_RSNN_NN;
1442 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
1447 lpfc_cmpl_ct_cmd_da_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1448 struct lpfc_iocbq *rspiocb)
1450 struct lpfc_vport *vport = cmdiocb->vport;
1452 /* even if it fails we will act as though it succeeded. */
1453 vport->ct_flags = 0;
1454 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
1459 lpfc_cmpl_ct_cmd_rff_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1460 struct lpfc_iocbq *rspiocb)
1462 IOCB_t *irsp = &rspiocb->iocb;
1463 struct lpfc_vport *vport = cmdiocb->vport;
1465 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
1466 struct lpfc_dmabuf *outp;
1467 struct lpfc_sli_ct_request *CTrsp;
1469 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
1470 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
1471 if (CTrsp->CommandResponse.bits.CmdRsp ==
1472 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
1473 vport->ct_flags |= FC_CT_RFF_ID;
1475 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
1480 * Although the symbolic port name is thought to be an integer
1481 * as of January 18, 2016, leave it as a string until more of
1482 * the record state becomes defined.
1485 lpfc_vport_symbolic_port_name(struct lpfc_vport *vport, char *symbol,
1491 * Use the lpfc board number as the Symbolic Port
1492 * Name object. NPIV is not in play so this integer
1493 * value is sufficient and unique per FC-ID.
1495 n = scnprintf(symbol, size, "%d", vport->phba->brd_no);
1501 lpfc_vport_symbolic_node_name(struct lpfc_vport *vport, char *symbol,
1504 char fwrev[FW_REV_STR_SIZE] = {0};
1505 char tmp[MAXHOSTNAMELEN] = {0};
1507 memset(symbol, 0, size);
1509 scnprintf(tmp, sizeof(tmp), "Emulex %s", vport->phba->ModelName);
1510 if (strlcat(symbol, tmp, size) >= size)
1513 lpfc_decode_firmware_rev(vport->phba, fwrev, 0);
1514 scnprintf(tmp, sizeof(tmp), " FV%s", fwrev);
1515 if (strlcat(symbol, tmp, size) >= size)
1518 scnprintf(tmp, sizeof(tmp), " DV%s", lpfc_release_version);
1519 if (strlcat(symbol, tmp, size) >= size)
1522 scnprintf(tmp, sizeof(tmp), " HN:%s", vport->phba->os_host_name);
1523 if (strlcat(symbol, tmp, size) >= size)
1526 /* Note :- OS name is "Linux" */
1527 scnprintf(tmp, sizeof(tmp), " OS:%s", init_utsname()->sysname);
1528 strlcat(symbol, tmp, size);
1531 return strnlen(symbol, size);
1536 lpfc_find_map_node(struct lpfc_vport *vport)
1538 struct lpfc_nodelist *ndlp, *next_ndlp;
1539 struct Scsi_Host *shost;
1542 shost = lpfc_shost_from_vport(vport);
1543 spin_lock_irq(shost->host_lock);
1544 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
1545 if (ndlp->nlp_type & NLP_FABRIC)
1547 if ((ndlp->nlp_state == NLP_STE_MAPPED_NODE) ||
1548 (ndlp->nlp_state == NLP_STE_UNMAPPED_NODE))
1551 spin_unlock_irq(shost->host_lock);
1556 * This routine will return the FC4 Type associated with the CT
1560 lpfc_get_gidft_type(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb)
1562 struct lpfc_sli_ct_request *CtReq;
1563 struct lpfc_dmabuf *mp;
1566 mp = cmdiocb->context1;
1569 CtReq = (struct lpfc_sli_ct_request *)mp->virt;
1570 type = (uint32_t)CtReq->un.gid.Fc4Type;
1571 if ((type != SLI_CTPT_FCP) && (type != SLI_CTPT_NVME))
1579 * Issue Cmd to NameServer
1584 lpfc_ns_cmd(struct lpfc_vport *vport, int cmdcode,
1585 uint8_t retry, uint32_t context)
1587 struct lpfc_nodelist * ndlp;
1588 struct lpfc_hba *phba = vport->phba;
1589 struct lpfc_dmabuf *mp, *bmp;
1590 struct lpfc_sli_ct_request *CtReq;
1591 struct ulp_bde64 *bpl;
1592 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
1593 struct lpfc_iocbq *) = NULL;
1595 uint32_t rsp_size = 1024;
1599 ndlp = lpfc_findnode_did(vport, NameServer_DID);
1600 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)
1601 || ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) {
1606 /* fill in BDEs for command */
1607 /* Allocate buffer for command payload */
1608 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
1614 INIT_LIST_HEAD(&mp->list);
1615 mp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(mp->phys));
1618 goto ns_cmd_free_mp;
1621 /* Allocate buffer for Buffer ptr list */
1622 bmp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
1625 goto ns_cmd_free_mpvirt;
1628 INIT_LIST_HEAD(&bmp->list);
1629 bmp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(bmp->phys));
1632 goto ns_cmd_free_bmp;
1635 /* NameServer Req */
1636 lpfc_printf_vlog(vport, KERN_INFO ,LOG_DISCOVERY,
1637 "0236 NameServer Req Data: x%x x%x x%x x%x\n",
1638 cmdcode, vport->fc_flag, vport->fc_rscn_id_cnt,
1641 bpl = (struct ulp_bde64 *) bmp->virt;
1642 memset(bpl, 0, sizeof(struct ulp_bde64));
1643 bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys) );
1644 bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys) );
1645 bpl->tus.f.bdeFlags = 0;
1646 if (cmdcode == SLI_CTNS_GID_FT)
1647 bpl->tus.f.bdeSize = GID_REQUEST_SZ;
1648 else if (cmdcode == SLI_CTNS_GID_PT)
1649 bpl->tus.f.bdeSize = GID_REQUEST_SZ;
1650 else if (cmdcode == SLI_CTNS_GFF_ID)
1651 bpl->tus.f.bdeSize = GFF_REQUEST_SZ;
1652 else if (cmdcode == SLI_CTNS_GFT_ID)
1653 bpl->tus.f.bdeSize = GFT_REQUEST_SZ;
1654 else if (cmdcode == SLI_CTNS_RFT_ID)
1655 bpl->tus.f.bdeSize = RFT_REQUEST_SZ;
1656 else if (cmdcode == SLI_CTNS_RNN_ID)
1657 bpl->tus.f.bdeSize = RNN_REQUEST_SZ;
1658 else if (cmdcode == SLI_CTNS_RSPN_ID)
1659 bpl->tus.f.bdeSize = RSPN_REQUEST_SZ;
1660 else if (cmdcode == SLI_CTNS_RSNN_NN)
1661 bpl->tus.f.bdeSize = RSNN_REQUEST_SZ;
1662 else if (cmdcode == SLI_CTNS_DA_ID)
1663 bpl->tus.f.bdeSize = DA_ID_REQUEST_SZ;
1664 else if (cmdcode == SLI_CTNS_RFF_ID)
1665 bpl->tus.f.bdeSize = RFF_REQUEST_SZ;
1667 bpl->tus.f.bdeSize = 0;
1668 bpl->tus.w = le32_to_cpu(bpl->tus.w);
1670 CtReq = (struct lpfc_sli_ct_request *) mp->virt;
1671 memset(CtReq, 0, sizeof(struct lpfc_sli_ct_request));
1672 CtReq->RevisionId.bits.Revision = SLI_CT_REVISION;
1673 CtReq->RevisionId.bits.InId = 0;
1674 CtReq->FsType = SLI_CT_DIRECTORY_SERVICE;
1675 CtReq->FsSubType = SLI_CT_DIRECTORY_NAME_SERVER;
1676 CtReq->CommandResponse.bits.Size = 0;
1678 case SLI_CTNS_GID_FT:
1679 CtReq->CommandResponse.bits.CmdRsp =
1680 cpu_to_be16(SLI_CTNS_GID_FT);
1681 CtReq->un.gid.Fc4Type = context;
1683 if (vport->port_state < LPFC_NS_QRY)
1684 vport->port_state = LPFC_NS_QRY;
1685 lpfc_set_disctmo(vport);
1686 cmpl = lpfc_cmpl_ct_cmd_gid_ft;
1687 rsp_size = FC_MAX_NS_RSP;
1690 case SLI_CTNS_GID_PT:
1691 CtReq->CommandResponse.bits.CmdRsp =
1692 cpu_to_be16(SLI_CTNS_GID_PT);
1693 CtReq->un.gid.PortType = context;
1695 if (vport->port_state < LPFC_NS_QRY)
1696 vport->port_state = LPFC_NS_QRY;
1697 lpfc_set_disctmo(vport);
1698 cmpl = lpfc_cmpl_ct_cmd_gid_pt;
1699 rsp_size = FC_MAX_NS_RSP;
1702 case SLI_CTNS_GFF_ID:
1703 CtReq->CommandResponse.bits.CmdRsp =
1704 cpu_to_be16(SLI_CTNS_GFF_ID);
1705 CtReq->un.gff.PortId = cpu_to_be32(context);
1706 cmpl = lpfc_cmpl_ct_cmd_gff_id;
1709 case SLI_CTNS_GFT_ID:
1710 CtReq->CommandResponse.bits.CmdRsp =
1711 cpu_to_be16(SLI_CTNS_GFT_ID);
1712 CtReq->un.gft.PortId = cpu_to_be32(context);
1713 cmpl = lpfc_cmpl_ct_cmd_gft_id;
1716 case SLI_CTNS_RFT_ID:
1717 vport->ct_flags &= ~FC_CT_RFT_ID;
1718 CtReq->CommandResponse.bits.CmdRsp =
1719 cpu_to_be16(SLI_CTNS_RFT_ID);
1720 CtReq->un.rft.PortId = cpu_to_be32(vport->fc_myDID);
1722 /* Register FC4 FCP type if enabled. */
1723 if (vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH ||
1724 vport->cfg_enable_fc4_type == LPFC_ENABLE_FCP)
1725 CtReq->un.rft.fcpReg = 1;
1727 /* Register NVME type if enabled. Defined LE and swapped.
1728 * rsvd[0] is used as word1 because of the hard-coded
1729 * word0 usage in the ct_request data structure.
1731 if (vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH ||
1732 vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME)
1733 CtReq->un.rft.rsvd[0] =
1734 cpu_to_be32(LPFC_FC4_TYPE_BITMASK);
1736 ptr = (uint32_t *)CtReq;
1737 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1738 "6433 Issue RFT (%s %s): %08x %08x %08x %08x "
1739 "%08x %08x %08x %08x\n",
1740 CtReq->un.rft.fcpReg ? "FCP" : " ",
1741 CtReq->un.rft.rsvd[0] ? "NVME" : " ",
1742 *ptr, *(ptr + 1), *(ptr + 2), *(ptr + 3),
1743 *(ptr + 4), *(ptr + 5),
1744 *(ptr + 6), *(ptr + 7));
1745 cmpl = lpfc_cmpl_ct_cmd_rft_id;
1748 case SLI_CTNS_RNN_ID:
1749 vport->ct_flags &= ~FC_CT_RNN_ID;
1750 CtReq->CommandResponse.bits.CmdRsp =
1751 cpu_to_be16(SLI_CTNS_RNN_ID);
1752 CtReq->un.rnn.PortId = cpu_to_be32(vport->fc_myDID);
1753 memcpy(CtReq->un.rnn.wwnn, &vport->fc_nodename,
1754 sizeof(struct lpfc_name));
1755 cmpl = lpfc_cmpl_ct_cmd_rnn_id;
1758 case SLI_CTNS_RSPN_ID:
1759 vport->ct_flags &= ~FC_CT_RSPN_ID;
1760 CtReq->CommandResponse.bits.CmdRsp =
1761 cpu_to_be16(SLI_CTNS_RSPN_ID);
1762 CtReq->un.rspn.PortId = cpu_to_be32(vport->fc_myDID);
1763 size = sizeof(CtReq->un.rspn.symbname);
1764 CtReq->un.rspn.len =
1765 lpfc_vport_symbolic_port_name(vport,
1766 CtReq->un.rspn.symbname, size);
1767 cmpl = lpfc_cmpl_ct_cmd_rspn_id;
1769 case SLI_CTNS_RSNN_NN:
1770 vport->ct_flags &= ~FC_CT_RSNN_NN;
1771 CtReq->CommandResponse.bits.CmdRsp =
1772 cpu_to_be16(SLI_CTNS_RSNN_NN);
1773 memcpy(CtReq->un.rsnn.wwnn, &vport->fc_nodename,
1774 sizeof(struct lpfc_name));
1775 size = sizeof(CtReq->un.rsnn.symbname);
1776 CtReq->un.rsnn.len =
1777 lpfc_vport_symbolic_node_name(vport,
1778 CtReq->un.rsnn.symbname, size);
1779 cmpl = lpfc_cmpl_ct_cmd_rsnn_nn;
1781 case SLI_CTNS_DA_ID:
1782 /* Implement DA_ID Nameserver request */
1783 CtReq->CommandResponse.bits.CmdRsp =
1784 cpu_to_be16(SLI_CTNS_DA_ID);
1785 CtReq->un.da_id.port_id = cpu_to_be32(vport->fc_myDID);
1786 cmpl = lpfc_cmpl_ct_cmd_da_id;
1788 case SLI_CTNS_RFF_ID:
1789 vport->ct_flags &= ~FC_CT_RFF_ID;
1790 CtReq->CommandResponse.bits.CmdRsp =
1791 cpu_to_be16(SLI_CTNS_RFF_ID);
1792 CtReq->un.rff.PortId = cpu_to_be32(vport->fc_myDID);
1793 CtReq->un.rff.fbits = FC4_FEATURE_INIT;
1795 /* The driver always supports FC_TYPE_FCP. However, the
1796 * caller can specify NVME (type x28) as well. But only
1797 * these that FC4 type is supported.
1799 if (((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
1800 (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) &&
1801 (context == FC_TYPE_NVME)) {
1802 if ((vport == phba->pport) && phba->nvmet_support) {
1803 CtReq->un.rff.fbits = (FC4_FEATURE_TARGET |
1804 FC4_FEATURE_NVME_DISC);
1805 lpfc_nvmet_update_targetport(phba);
1807 lpfc_nvme_update_localport(vport);
1809 CtReq->un.rff.type_code = context;
1811 } else if (((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
1812 (vport->cfg_enable_fc4_type == LPFC_ENABLE_FCP)) &&
1813 (context == FC_TYPE_FCP))
1814 CtReq->un.rff.type_code = context;
1817 goto ns_cmd_free_bmpvirt;
1819 ptr = (uint32_t *)CtReq;
1820 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1821 "6434 Issue RFF (%s): %08x %08x %08x %08x "
1822 "%08x %08x %08x %08x\n",
1823 (context == FC_TYPE_NVME) ? "NVME" : "FCP",
1824 *ptr, *(ptr + 1), *(ptr + 2), *(ptr + 3),
1825 *(ptr + 4), *(ptr + 5),
1826 *(ptr + 6), *(ptr + 7));
1827 cmpl = lpfc_cmpl_ct_cmd_rff_id;
1830 /* The lpfc_ct_cmd/lpfc_get_req shall increment ndlp reference count
1831 * to hold ndlp reference for the corresponding callback function.
1833 if (!lpfc_ct_cmd(vport, mp, bmp, ndlp, cmpl, rsp_size, retry)) {
1834 /* On success, The cmpl function will free the buffers */
1835 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
1836 "Issue CT cmd: cmd:x%x did:x%x",
1837 cmdcode, ndlp->nlp_DID, 0);
1842 /* Decrement ndlp reference count to release ndlp reference held
1843 * for the failed command's callback function.
1847 ns_cmd_free_bmpvirt:
1848 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
1852 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1856 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1857 "0266 Issue NameServer Req x%x err %d Data: x%x x%x\n",
1858 cmdcode, rc, vport->fc_flag, vport->fc_rscn_id_cnt);
1863 * lpfc_cmpl_ct_disc_fdmi - Handle a discovery FDMI completion
1864 * @phba: Pointer to HBA context object.
1865 * @cmdiocb: Pointer to the command IOCBQ.
1866 * @rspiocb: Pointer to the response IOCBQ.
1868 * This function to handle the completion of a driver initiated FDMI
1869 * CT command issued during discovery.
1872 lpfc_cmpl_ct_disc_fdmi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1873 struct lpfc_iocbq *rspiocb)
1875 struct lpfc_vport *vport = cmdiocb->vport;
1876 struct lpfc_dmabuf *inp = cmdiocb->context1;
1877 struct lpfc_dmabuf *outp = cmdiocb->context2;
1878 struct lpfc_sli_ct_request *CTcmd = inp->virt;
1879 struct lpfc_sli_ct_request *CTrsp = outp->virt;
1880 uint16_t fdmi_cmd = CTcmd->CommandResponse.bits.CmdRsp;
1881 uint16_t fdmi_rsp = CTrsp->CommandResponse.bits.CmdRsp;
1882 IOCB_t *irsp = &rspiocb->iocb;
1883 struct lpfc_nodelist *ndlp;
1884 uint32_t latt, cmd, err;
1886 latt = lpfc_els_chk_latt(vport);
1887 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
1888 "FDMI cmpl: status:x%x/x%x latt:%d",
1889 irsp->ulpStatus, irsp->un.ulpWord[4], latt);
1891 if (latt || irsp->ulpStatus) {
1893 /* Look for a retryable error */
1894 if (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) {
1895 switch ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK)) {
1896 case IOERR_SLI_ABORTED:
1897 case IOERR_SLI_DOWN:
1898 /* Driver aborted this IO. No retry as error
1899 * is likely Offline->Online or some adapter
1900 * error. Recovery will try again.
1903 case IOERR_ABORT_IN_PROGRESS:
1904 case IOERR_SEQUENCE_TIMEOUT:
1905 case IOERR_ILLEGAL_FRAME:
1906 case IOERR_NO_RESOURCES:
1907 case IOERR_ILLEGAL_COMMAND:
1909 if (cmdiocb->retry >= LPFC_FDMI_MAX_RETRY)
1912 /* Retry the same FDMI command */
1913 err = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING,
1915 if (err == IOCB_ERROR)
1923 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1924 "0229 FDMI cmd %04x failed, latt = %d "
1925 "ulpStatus: x%x, rid x%x\n",
1926 be16_to_cpu(fdmi_cmd), latt, irsp->ulpStatus,
1927 irsp->un.ulpWord[4]);
1929 lpfc_ct_free_iocb(phba, cmdiocb);
1931 ndlp = lpfc_findnode_did(vport, FDMI_DID);
1932 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
1935 /* Check for a CT LS_RJT response */
1936 cmd = be16_to_cpu(fdmi_cmd);
1937 if (fdmi_rsp == cpu_to_be16(SLI_CT_RESPONSE_FS_RJT)) {
1938 /* FDMI rsp failed */
1939 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1940 "0220 FDMI cmd failed FS_RJT Data: x%x", cmd);
1942 /* Should we fallback to FDMI-2 / FDMI-1 ? */
1945 if (vport->fdmi_hba_mask == LPFC_FDMI2_HBA_ATTR) {
1946 /* Fallback to FDMI-1 */
1947 vport->fdmi_hba_mask = LPFC_FDMI1_HBA_ATTR;
1948 vport->fdmi_port_mask = LPFC_FDMI1_PORT_ATTR;
1950 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA, 0);
1955 if (vport->fdmi_port_mask == LPFC_FDMI2_PORT_ATTR) {
1956 /* Fallback to FDMI-1 */
1957 vport->fdmi_port_mask = LPFC_FDMI1_PORT_ATTR;
1959 lpfc_fdmi_cmd(vport, ndlp, cmd, 0);
1961 if (vport->fdmi_port_mask == LPFC_FDMI2_SMART_ATTR) {
1962 vport->fdmi_port_mask = LPFC_FDMI2_PORT_ATTR;
1963 /* Retry the same command */
1964 lpfc_fdmi_cmd(vport, ndlp, cmd, 0);
1969 if (vport->fdmi_port_mask == LPFC_FDMI2_PORT_ATTR) {
1970 /* Fallback to FDMI-1 */
1971 vport->fdmi_hba_mask = LPFC_FDMI1_HBA_ATTR;
1972 vport->fdmi_port_mask = LPFC_FDMI1_PORT_ATTR;
1974 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA, 0);
1976 if (vport->fdmi_port_mask == LPFC_FDMI2_SMART_ATTR) {
1977 vport->fdmi_port_mask = LPFC_FDMI2_PORT_ATTR;
1978 /* Retry the same command */
1979 lpfc_fdmi_cmd(vport, ndlp, cmd, 0);
1986 * On success, need to cycle thru FDMI registration for discovery
1987 * DHBA -> DPRT -> RHBA -> RPA (physical port)
1988 * DPRT -> RPRT (vports)
1992 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RPA, 0);
1996 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DPRT, 0);
2000 if (vport->port_type == LPFC_PHYSICAL_PORT)
2001 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RHBA, 0);
2003 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RPRT, 0);
2011 * lpfc_fdmi_change_check - Check for changed FDMI parameters
2012 * @vport: pointer to a host virtual N_Port data structure.
2014 * Check how many mapped NPorts we are connected to
2015 * Check if our hostname changed
2016 * Called from hbeat timeout routine to check if any FDMI parameters
2017 * changed. If so, re-register those Attributes.
2020 lpfc_fdmi_change_check(struct lpfc_vport *vport)
2022 struct lpfc_hba *phba = vport->phba;
2023 struct lpfc_nodelist *ndlp;
2026 if (!lpfc_is_link_up(phba))
2029 /* Must be connected to a Fabric */
2030 if (!(vport->fc_flag & FC_FABRIC))
2033 ndlp = lpfc_findnode_did(vport, FDMI_DID);
2034 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
2037 /* Check if system hostname changed */
2038 if (strcmp(phba->os_host_name, init_utsname()->nodename)) {
2039 memset(phba->os_host_name, 0, sizeof(phba->os_host_name));
2040 scnprintf(phba->os_host_name, sizeof(phba->os_host_name), "%s",
2041 init_utsname()->nodename);
2042 lpfc_ns_cmd(vport, SLI_CTNS_RSNN_NN, 0, 0);
2044 /* Since this effects multiple HBA and PORT attributes, we need
2045 * de-register and go thru the whole FDMI registration cycle.
2046 * DHBA -> DPRT -> RHBA -> RPA (physical port)
2047 * DPRT -> RPRT (vports)
2049 if (vport->port_type == LPFC_PHYSICAL_PORT)
2050 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA, 0);
2052 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DPRT, 0);
2054 /* Since this code path registers all the port attributes
2055 * we can just return without further checking.
2060 if (!(vport->fdmi_port_mask & LPFC_FDMI_PORT_ATTR_num_disc))
2063 /* Check if the number of mapped NPorts changed */
2064 cnt = lpfc_find_map_node(vport);
2065 if (cnt == vport->fdmi_num_disc)
2068 if (vport->port_type == LPFC_PHYSICAL_PORT) {
2069 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RPA,
2070 LPFC_FDMI_PORT_ATTR_num_disc);
2072 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RPRT,
2073 LPFC_FDMI_PORT_ATTR_num_disc);
2077 /* Routines for all individual HBA attributes */
2079 lpfc_fdmi_hba_attr_wwnn(struct lpfc_vport *vport, struct lpfc_fdmi_attr_def *ad)
2081 struct lpfc_fdmi_attr_entry *ae;
2084 ae = &ad->AttrValue;
2085 memset(ae, 0, sizeof(*ae));
2087 memcpy(&ae->un.AttrWWN, &vport->fc_sparam.nodeName,
2088 sizeof(struct lpfc_name));
2089 size = FOURBYTES + sizeof(struct lpfc_name);
2090 ad->AttrLen = cpu_to_be16(size);
2091 ad->AttrType = cpu_to_be16(RHBA_NODENAME);
2095 lpfc_fdmi_hba_attr_manufacturer(struct lpfc_vport *vport,
2096 struct lpfc_fdmi_attr_def *ad)
2098 struct lpfc_fdmi_attr_entry *ae;
2101 ae = &ad->AttrValue;
2102 memset(ae, 0, sizeof(*ae));
2104 /* This string MUST be consistent with other FC platforms
2105 * supported by Broadcom.
2107 strncpy(ae->un.AttrString,
2108 "Emulex Corporation",
2109 sizeof(ae->un.AttrString));
2110 len = strnlen(ae->un.AttrString,
2111 sizeof(ae->un.AttrString));
2112 len += (len & 3) ? (4 - (len & 3)) : 4;
2113 size = FOURBYTES + len;
2114 ad->AttrLen = cpu_to_be16(size);
2115 ad->AttrType = cpu_to_be16(RHBA_MANUFACTURER);
2120 lpfc_fdmi_hba_attr_sn(struct lpfc_vport *vport, struct lpfc_fdmi_attr_def *ad)
2122 struct lpfc_hba *phba = vport->phba;
2123 struct lpfc_fdmi_attr_entry *ae;
2126 ae = &ad->AttrValue;
2127 memset(ae, 0, sizeof(*ae));
2129 strncpy(ae->un.AttrString, phba->SerialNumber,
2130 sizeof(ae->un.AttrString));
2131 len = strnlen(ae->un.AttrString,
2132 sizeof(ae->un.AttrString));
2133 len += (len & 3) ? (4 - (len & 3)) : 4;
2134 size = FOURBYTES + len;
2135 ad->AttrLen = cpu_to_be16(size);
2136 ad->AttrType = cpu_to_be16(RHBA_SERIAL_NUMBER);
2141 lpfc_fdmi_hba_attr_model(struct lpfc_vport *vport,
2142 struct lpfc_fdmi_attr_def *ad)
2144 struct lpfc_hba *phba = vport->phba;
2145 struct lpfc_fdmi_attr_entry *ae;
2148 ae = &ad->AttrValue;
2149 memset(ae, 0, sizeof(*ae));
2151 strncpy(ae->un.AttrString, phba->ModelName,
2152 sizeof(ae->un.AttrString));
2153 len = strnlen(ae->un.AttrString, sizeof(ae->un.AttrString));
2154 len += (len & 3) ? (4 - (len & 3)) : 4;
2155 size = FOURBYTES + len;
2156 ad->AttrLen = cpu_to_be16(size);
2157 ad->AttrType = cpu_to_be16(RHBA_MODEL);
2162 lpfc_fdmi_hba_attr_description(struct lpfc_vport *vport,
2163 struct lpfc_fdmi_attr_def *ad)
2165 struct lpfc_hba *phba = vport->phba;
2166 struct lpfc_fdmi_attr_entry *ae;
2169 ae = &ad->AttrValue;
2170 memset(ae, 0, sizeof(*ae));
2172 strncpy(ae->un.AttrString, phba->ModelDesc,
2173 sizeof(ae->un.AttrString));
2174 len = strnlen(ae->un.AttrString,
2175 sizeof(ae->un.AttrString));
2176 len += (len & 3) ? (4 - (len & 3)) : 4;
2177 size = FOURBYTES + len;
2178 ad->AttrLen = cpu_to_be16(size);
2179 ad->AttrType = cpu_to_be16(RHBA_MODEL_DESCRIPTION);
2184 lpfc_fdmi_hba_attr_hdw_ver(struct lpfc_vport *vport,
2185 struct lpfc_fdmi_attr_def *ad)
2187 struct lpfc_hba *phba = vport->phba;
2188 lpfc_vpd_t *vp = &phba->vpd;
2189 struct lpfc_fdmi_attr_entry *ae;
2190 uint32_t i, j, incr, size;
2192 ae = &ad->AttrValue;
2193 memset(ae, 0, sizeof(*ae));
2195 /* Convert JEDEC ID to ascii for hardware version */
2196 incr = vp->rev.biuRev;
2197 for (i = 0; i < 8; i++) {
2200 ae->un.AttrString[7 - i] =
2201 (char)((uint8_t) 0x30 +
2204 ae->un.AttrString[7 - i] =
2205 (char)((uint8_t) 0x61 +
2206 (uint8_t) (j - 10));
2209 size = FOURBYTES + 8;
2210 ad->AttrLen = cpu_to_be16(size);
2211 ad->AttrType = cpu_to_be16(RHBA_HARDWARE_VERSION);
2216 lpfc_fdmi_hba_attr_drvr_ver(struct lpfc_vport *vport,
2217 struct lpfc_fdmi_attr_def *ad)
2219 struct lpfc_fdmi_attr_entry *ae;
2222 ae = &ad->AttrValue;
2223 memset(ae, 0, sizeof(*ae));
2225 strncpy(ae->un.AttrString, lpfc_release_version,
2226 sizeof(ae->un.AttrString));
2227 len = strnlen(ae->un.AttrString,
2228 sizeof(ae->un.AttrString));
2229 len += (len & 3) ? (4 - (len & 3)) : 4;
2230 size = FOURBYTES + len;
2231 ad->AttrLen = cpu_to_be16(size);
2232 ad->AttrType = cpu_to_be16(RHBA_DRIVER_VERSION);
2237 lpfc_fdmi_hba_attr_rom_ver(struct lpfc_vport *vport,
2238 struct lpfc_fdmi_attr_def *ad)
2240 struct lpfc_hba *phba = vport->phba;
2241 struct lpfc_fdmi_attr_entry *ae;
2244 ae = &ad->AttrValue;
2245 memset(ae, 0, sizeof(*ae));
2247 if (phba->sli_rev == LPFC_SLI_REV4)
2248 lpfc_decode_firmware_rev(phba, ae->un.AttrString, 1);
2250 strncpy(ae->un.AttrString, phba->OptionROMVersion,
2251 sizeof(ae->un.AttrString));
2252 len = strnlen(ae->un.AttrString,
2253 sizeof(ae->un.AttrString));
2254 len += (len & 3) ? (4 - (len & 3)) : 4;
2255 size = FOURBYTES + len;
2256 ad->AttrLen = cpu_to_be16(size);
2257 ad->AttrType = cpu_to_be16(RHBA_OPTION_ROM_VERSION);
2262 lpfc_fdmi_hba_attr_fmw_ver(struct lpfc_vport *vport,
2263 struct lpfc_fdmi_attr_def *ad)
2265 struct lpfc_hba *phba = vport->phba;
2266 struct lpfc_fdmi_attr_entry *ae;
2269 ae = &ad->AttrValue;
2270 memset(ae, 0, sizeof(*ae));
2272 lpfc_decode_firmware_rev(phba, ae->un.AttrString, 1);
2273 len = strnlen(ae->un.AttrString,
2274 sizeof(ae->un.AttrString));
2275 len += (len & 3) ? (4 - (len & 3)) : 4;
2276 size = FOURBYTES + len;
2277 ad->AttrLen = cpu_to_be16(size);
2278 ad->AttrType = cpu_to_be16(RHBA_FIRMWARE_VERSION);
2283 lpfc_fdmi_hba_attr_os_ver(struct lpfc_vport *vport,
2284 struct lpfc_fdmi_attr_def *ad)
2286 struct lpfc_fdmi_attr_entry *ae;
2289 ae = &ad->AttrValue;
2290 memset(ae, 0, sizeof(*ae));
2292 snprintf(ae->un.AttrString, sizeof(ae->un.AttrString), "%s %s %s",
2293 init_utsname()->sysname,
2294 init_utsname()->release,
2295 init_utsname()->version);
2297 len = strnlen(ae->un.AttrString, sizeof(ae->un.AttrString));
2298 len += (len & 3) ? (4 - (len & 3)) : 4;
2299 size = FOURBYTES + len;
2300 ad->AttrLen = cpu_to_be16(size);
2301 ad->AttrType = cpu_to_be16(RHBA_OS_NAME_VERSION);
2306 lpfc_fdmi_hba_attr_ct_len(struct lpfc_vport *vport,
2307 struct lpfc_fdmi_attr_def *ad)
2309 struct lpfc_fdmi_attr_entry *ae;
2312 ae = &ad->AttrValue;
2314 ae->un.AttrInt = cpu_to_be32(LPFC_MAX_CT_SIZE);
2315 size = FOURBYTES + sizeof(uint32_t);
2316 ad->AttrLen = cpu_to_be16(size);
2317 ad->AttrType = cpu_to_be16(RHBA_MAX_CT_PAYLOAD_LEN);
2322 lpfc_fdmi_hba_attr_symbolic_name(struct lpfc_vport *vport,
2323 struct lpfc_fdmi_attr_def *ad)
2325 struct lpfc_fdmi_attr_entry *ae;
2328 ae = &ad->AttrValue;
2329 memset(ae, 0, sizeof(*ae));
2331 len = lpfc_vport_symbolic_node_name(vport,
2332 ae->un.AttrString, 256);
2333 len += (len & 3) ? (4 - (len & 3)) : 4;
2334 size = FOURBYTES + len;
2335 ad->AttrLen = cpu_to_be16(size);
2336 ad->AttrType = cpu_to_be16(RHBA_SYM_NODENAME);
2341 lpfc_fdmi_hba_attr_vendor_info(struct lpfc_vport *vport,
2342 struct lpfc_fdmi_attr_def *ad)
2344 struct lpfc_fdmi_attr_entry *ae;
2347 ae = &ad->AttrValue;
2349 /* Nothing is defined for this currently */
2350 ae->un.AttrInt = cpu_to_be32(0);
2351 size = FOURBYTES + sizeof(uint32_t);
2352 ad->AttrLen = cpu_to_be16(size);
2353 ad->AttrType = cpu_to_be16(RHBA_VENDOR_INFO);
2358 lpfc_fdmi_hba_attr_num_ports(struct lpfc_vport *vport,
2359 struct lpfc_fdmi_attr_def *ad)
2361 struct lpfc_fdmi_attr_entry *ae;
2364 ae = &ad->AttrValue;
2366 /* Each driver instance corresponds to a single port */
2367 ae->un.AttrInt = cpu_to_be32(1);
2368 size = FOURBYTES + sizeof(uint32_t);
2369 ad->AttrLen = cpu_to_be16(size);
2370 ad->AttrType = cpu_to_be16(RHBA_NUM_PORTS);
2375 lpfc_fdmi_hba_attr_fabric_wwnn(struct lpfc_vport *vport,
2376 struct lpfc_fdmi_attr_def *ad)
2378 struct lpfc_fdmi_attr_entry *ae;
2381 ae = &ad->AttrValue;
2382 memset(ae, 0, sizeof(*ae));
2384 memcpy(&ae->un.AttrWWN, &vport->fabric_nodename,
2385 sizeof(struct lpfc_name));
2386 size = FOURBYTES + sizeof(struct lpfc_name);
2387 ad->AttrLen = cpu_to_be16(size);
2388 ad->AttrType = cpu_to_be16(RHBA_FABRIC_WWNN);
2393 lpfc_fdmi_hba_attr_bios_ver(struct lpfc_vport *vport,
2394 struct lpfc_fdmi_attr_def *ad)
2396 struct lpfc_hba *phba = vport->phba;
2397 struct lpfc_fdmi_attr_entry *ae;
2400 ae = &ad->AttrValue;
2401 memset(ae, 0, sizeof(*ae));
2403 strlcat(ae->un.AttrString, phba->BIOSVersion,
2404 sizeof(ae->un.AttrString));
2405 len = strnlen(ae->un.AttrString,
2406 sizeof(ae->un.AttrString));
2407 len += (len & 3) ? (4 - (len & 3)) : 4;
2408 size = FOURBYTES + len;
2409 ad->AttrLen = cpu_to_be16(size);
2410 ad->AttrType = cpu_to_be16(RHBA_BIOS_VERSION);
2415 lpfc_fdmi_hba_attr_bios_state(struct lpfc_vport *vport,
2416 struct lpfc_fdmi_attr_def *ad)
2418 struct lpfc_fdmi_attr_entry *ae;
2421 ae = &ad->AttrValue;
2423 /* Driver doesn't have access to this information */
2424 ae->un.AttrInt = cpu_to_be32(0);
2425 size = FOURBYTES + sizeof(uint32_t);
2426 ad->AttrLen = cpu_to_be16(size);
2427 ad->AttrType = cpu_to_be16(RHBA_BIOS_STATE);
2432 lpfc_fdmi_hba_attr_vendor_id(struct lpfc_vport *vport,
2433 struct lpfc_fdmi_attr_def *ad)
2435 struct lpfc_fdmi_attr_entry *ae;
2438 ae = &ad->AttrValue;
2439 memset(ae, 0, sizeof(*ae));
2441 strncpy(ae->un.AttrString, "EMULEX",
2442 sizeof(ae->un.AttrString));
2443 len = strnlen(ae->un.AttrString,
2444 sizeof(ae->un.AttrString));
2445 len += (len & 3) ? (4 - (len & 3)) : 4;
2446 size = FOURBYTES + len;
2447 ad->AttrLen = cpu_to_be16(size);
2448 ad->AttrType = cpu_to_be16(RHBA_VENDOR_ID);
2452 /* Routines for all individual PORT attributes */
2454 lpfc_fdmi_port_attr_fc4type(struct lpfc_vport *vport,
2455 struct lpfc_fdmi_attr_def *ad)
2457 struct lpfc_hba *phba = vport->phba;
2458 struct lpfc_fdmi_attr_entry *ae;
2461 ae = &ad->AttrValue;
2462 memset(ae, 0, sizeof(*ae));
2464 ae->un.AttrTypes[2] = 0x01; /* Type 0x8 - FCP */
2465 ae->un.AttrTypes[7] = 0x01; /* Type 0x20 - CT */
2467 /* Check to see if Firmware supports NVME and on physical port */
2468 if ((phba->sli_rev == LPFC_SLI_REV4) && (vport == phba->pport) &&
2469 phba->sli4_hba.pc_sli4_params.nvme)
2470 ae->un.AttrTypes[6] = 0x01; /* Type 0x28 - NVME */
2472 size = FOURBYTES + 32;
2473 ad->AttrLen = cpu_to_be16(size);
2474 ad->AttrType = cpu_to_be16(RPRT_SUPPORTED_FC4_TYPES);
2479 lpfc_fdmi_port_attr_support_speed(struct lpfc_vport *vport,
2480 struct lpfc_fdmi_attr_def *ad)
2482 struct lpfc_hba *phba = vport->phba;
2483 struct lpfc_fdmi_attr_entry *ae;
2486 ae = &ad->AttrValue;
2489 if (!(phba->hba_flag & HBA_FCOE_MODE)) {
2490 if (phba->lmt & LMT_128Gb)
2491 ae->un.AttrInt |= HBA_PORTSPEED_128GFC;
2492 if (phba->lmt & LMT_64Gb)
2493 ae->un.AttrInt |= HBA_PORTSPEED_64GFC;
2494 if (phba->lmt & LMT_32Gb)
2495 ae->un.AttrInt |= HBA_PORTSPEED_32GFC;
2496 if (phba->lmt & LMT_16Gb)
2497 ae->un.AttrInt |= HBA_PORTSPEED_16GFC;
2498 if (phba->lmt & LMT_10Gb)
2499 ae->un.AttrInt |= HBA_PORTSPEED_10GFC;
2500 if (phba->lmt & LMT_8Gb)
2501 ae->un.AttrInt |= HBA_PORTSPEED_8GFC;
2502 if (phba->lmt & LMT_4Gb)
2503 ae->un.AttrInt |= HBA_PORTSPEED_4GFC;
2504 if (phba->lmt & LMT_2Gb)
2505 ae->un.AttrInt |= HBA_PORTSPEED_2GFC;
2506 if (phba->lmt & LMT_1Gb)
2507 ae->un.AttrInt |= HBA_PORTSPEED_1GFC;
2509 /* FCoE links support only one speed */
2510 switch (phba->fc_linkspeed) {
2511 case LPFC_ASYNC_LINK_SPEED_10GBPS:
2512 ae->un.AttrInt = HBA_PORTSPEED_10GE;
2514 case LPFC_ASYNC_LINK_SPEED_25GBPS:
2515 ae->un.AttrInt = HBA_PORTSPEED_25GE;
2517 case LPFC_ASYNC_LINK_SPEED_40GBPS:
2518 ae->un.AttrInt = HBA_PORTSPEED_40GE;
2520 case LPFC_ASYNC_LINK_SPEED_100GBPS:
2521 ae->un.AttrInt = HBA_PORTSPEED_100GE;
2525 ae->un.AttrInt = cpu_to_be32(ae->un.AttrInt);
2526 size = FOURBYTES + sizeof(uint32_t);
2527 ad->AttrLen = cpu_to_be16(size);
2528 ad->AttrType = cpu_to_be16(RPRT_SUPPORTED_SPEED);
2533 lpfc_fdmi_port_attr_speed(struct lpfc_vport *vport,
2534 struct lpfc_fdmi_attr_def *ad)
2536 struct lpfc_hba *phba = vport->phba;
2537 struct lpfc_fdmi_attr_entry *ae;
2540 ae = &ad->AttrValue;
2542 if (!(phba->hba_flag & HBA_FCOE_MODE)) {
2543 switch (phba->fc_linkspeed) {
2544 case LPFC_LINK_SPEED_1GHZ:
2545 ae->un.AttrInt = HBA_PORTSPEED_1GFC;
2547 case LPFC_LINK_SPEED_2GHZ:
2548 ae->un.AttrInt = HBA_PORTSPEED_2GFC;
2550 case LPFC_LINK_SPEED_4GHZ:
2551 ae->un.AttrInt = HBA_PORTSPEED_4GFC;
2553 case LPFC_LINK_SPEED_8GHZ:
2554 ae->un.AttrInt = HBA_PORTSPEED_8GFC;
2556 case LPFC_LINK_SPEED_10GHZ:
2557 ae->un.AttrInt = HBA_PORTSPEED_10GFC;
2559 case LPFC_LINK_SPEED_16GHZ:
2560 ae->un.AttrInt = HBA_PORTSPEED_16GFC;
2562 case LPFC_LINK_SPEED_32GHZ:
2563 ae->un.AttrInt = HBA_PORTSPEED_32GFC;
2565 case LPFC_LINK_SPEED_64GHZ:
2566 ae->un.AttrInt = HBA_PORTSPEED_64GFC;
2568 case LPFC_LINK_SPEED_128GHZ:
2569 ae->un.AttrInt = HBA_PORTSPEED_128GFC;
2572 ae->un.AttrInt = HBA_PORTSPEED_UNKNOWN;
2576 switch (phba->fc_linkspeed) {
2577 case LPFC_ASYNC_LINK_SPEED_10GBPS:
2578 ae->un.AttrInt = HBA_PORTSPEED_10GE;
2580 case LPFC_ASYNC_LINK_SPEED_25GBPS:
2581 ae->un.AttrInt = HBA_PORTSPEED_25GE;
2583 case LPFC_ASYNC_LINK_SPEED_40GBPS:
2584 ae->un.AttrInt = HBA_PORTSPEED_40GE;
2586 case LPFC_ASYNC_LINK_SPEED_100GBPS:
2587 ae->un.AttrInt = HBA_PORTSPEED_100GE;
2590 ae->un.AttrInt = HBA_PORTSPEED_UNKNOWN;
2595 ae->un.AttrInt = cpu_to_be32(ae->un.AttrInt);
2596 size = FOURBYTES + sizeof(uint32_t);
2597 ad->AttrLen = cpu_to_be16(size);
2598 ad->AttrType = cpu_to_be16(RPRT_PORT_SPEED);
2603 lpfc_fdmi_port_attr_max_frame(struct lpfc_vport *vport,
2604 struct lpfc_fdmi_attr_def *ad)
2606 struct serv_parm *hsp;
2607 struct lpfc_fdmi_attr_entry *ae;
2610 ae = &ad->AttrValue;
2612 hsp = (struct serv_parm *)&vport->fc_sparam;
2613 ae->un.AttrInt = (((uint32_t) hsp->cmn.bbRcvSizeMsb & 0x0F) << 8) |
2614 (uint32_t) hsp->cmn.bbRcvSizeLsb;
2615 ae->un.AttrInt = cpu_to_be32(ae->un.AttrInt);
2616 size = FOURBYTES + sizeof(uint32_t);
2617 ad->AttrLen = cpu_to_be16(size);
2618 ad->AttrType = cpu_to_be16(RPRT_MAX_FRAME_SIZE);
2623 lpfc_fdmi_port_attr_os_devname(struct lpfc_vport *vport,
2624 struct lpfc_fdmi_attr_def *ad)
2626 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2627 struct lpfc_fdmi_attr_entry *ae;
2630 ae = &ad->AttrValue;
2631 memset(ae, 0, sizeof(*ae));
2633 snprintf(ae->un.AttrString, sizeof(ae->un.AttrString),
2634 "/sys/class/scsi_host/host%d", shost->host_no);
2635 len = strnlen((char *)ae->un.AttrString,
2636 sizeof(ae->un.AttrString));
2637 len += (len & 3) ? (4 - (len & 3)) : 4;
2638 size = FOURBYTES + len;
2639 ad->AttrLen = cpu_to_be16(size);
2640 ad->AttrType = cpu_to_be16(RPRT_OS_DEVICE_NAME);
2645 lpfc_fdmi_port_attr_host_name(struct lpfc_vport *vport,
2646 struct lpfc_fdmi_attr_def *ad)
2648 struct lpfc_fdmi_attr_entry *ae;
2651 ae = &ad->AttrValue;
2652 memset(ae, 0, sizeof(*ae));
2654 scnprintf(ae->un.AttrString, sizeof(ae->un.AttrString), "%s",
2655 vport->phba->os_host_name);
2657 len = strnlen(ae->un.AttrString, sizeof(ae->un.AttrString));
2658 len += (len & 3) ? (4 - (len & 3)) : 4;
2659 size = FOURBYTES + len;
2660 ad->AttrLen = cpu_to_be16(size);
2661 ad->AttrType = cpu_to_be16(RPRT_HOST_NAME);
2666 lpfc_fdmi_port_attr_wwnn(struct lpfc_vport *vport,
2667 struct lpfc_fdmi_attr_def *ad)
2669 struct lpfc_fdmi_attr_entry *ae;
2672 ae = &ad->AttrValue;
2673 memset(ae, 0, sizeof(*ae));
2675 memcpy(&ae->un.AttrWWN, &vport->fc_sparam.nodeName,
2676 sizeof(struct lpfc_name));
2677 size = FOURBYTES + sizeof(struct lpfc_name);
2678 ad->AttrLen = cpu_to_be16(size);
2679 ad->AttrType = cpu_to_be16(RPRT_NODENAME);
2684 lpfc_fdmi_port_attr_wwpn(struct lpfc_vport *vport,
2685 struct lpfc_fdmi_attr_def *ad)
2687 struct lpfc_fdmi_attr_entry *ae;
2690 ae = &ad->AttrValue;
2691 memset(ae, 0, sizeof(*ae));
2693 memcpy(&ae->un.AttrWWN, &vport->fc_sparam.portName,
2694 sizeof(struct lpfc_name));
2695 size = FOURBYTES + sizeof(struct lpfc_name);
2696 ad->AttrLen = cpu_to_be16(size);
2697 ad->AttrType = cpu_to_be16(RPRT_PORTNAME);
2702 lpfc_fdmi_port_attr_symbolic_name(struct lpfc_vport *vport,
2703 struct lpfc_fdmi_attr_def *ad)
2705 struct lpfc_fdmi_attr_entry *ae;
2708 ae = &ad->AttrValue;
2709 memset(ae, 0, sizeof(*ae));
2711 len = lpfc_vport_symbolic_port_name(vport, ae->un.AttrString, 256);
2712 len += (len & 3) ? (4 - (len & 3)) : 4;
2713 size = FOURBYTES + len;
2714 ad->AttrLen = cpu_to_be16(size);
2715 ad->AttrType = cpu_to_be16(RPRT_SYM_PORTNAME);
2720 lpfc_fdmi_port_attr_port_type(struct lpfc_vport *vport,
2721 struct lpfc_fdmi_attr_def *ad)
2723 struct lpfc_hba *phba = vport->phba;
2724 struct lpfc_fdmi_attr_entry *ae;
2727 ae = &ad->AttrValue;
2728 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP)
2729 ae->un.AttrInt = cpu_to_be32(LPFC_FDMI_PORTTYPE_NLPORT);
2731 ae->un.AttrInt = cpu_to_be32(LPFC_FDMI_PORTTYPE_NPORT);
2732 size = FOURBYTES + sizeof(uint32_t);
2733 ad->AttrLen = cpu_to_be16(size);
2734 ad->AttrType = cpu_to_be16(RPRT_PORT_TYPE);
2739 lpfc_fdmi_port_attr_class(struct lpfc_vport *vport,
2740 struct lpfc_fdmi_attr_def *ad)
2742 struct lpfc_fdmi_attr_entry *ae;
2745 ae = &ad->AttrValue;
2746 ae->un.AttrInt = cpu_to_be32(FC_COS_CLASS2 | FC_COS_CLASS3);
2747 size = FOURBYTES + sizeof(uint32_t);
2748 ad->AttrLen = cpu_to_be16(size);
2749 ad->AttrType = cpu_to_be16(RPRT_SUPPORTED_CLASS);
2754 lpfc_fdmi_port_attr_fabric_wwpn(struct lpfc_vport *vport,
2755 struct lpfc_fdmi_attr_def *ad)
2757 struct lpfc_fdmi_attr_entry *ae;
2760 ae = &ad->AttrValue;
2761 memset(ae, 0, sizeof(*ae));
2763 memcpy(&ae->un.AttrWWN, &vport->fabric_portname,
2764 sizeof(struct lpfc_name));
2765 size = FOURBYTES + sizeof(struct lpfc_name);
2766 ad->AttrLen = cpu_to_be16(size);
2767 ad->AttrType = cpu_to_be16(RPRT_FABRICNAME);
2772 lpfc_fdmi_port_attr_active_fc4type(struct lpfc_vport *vport,
2773 struct lpfc_fdmi_attr_def *ad)
2775 struct lpfc_fdmi_attr_entry *ae;
2778 ae = &ad->AttrValue;
2779 memset(ae, 0, sizeof(*ae));
2781 ae->un.AttrTypes[2] = 0x01; /* Type 0x8 - FCP */
2782 ae->un.AttrTypes[7] = 0x01; /* Type 0x20 - CT */
2784 /* Check to see if NVME is configured or not */
2785 if (vport->phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)
2786 ae->un.AttrTypes[6] = 0x1; /* Type 0x28 - NVME */
2788 size = FOURBYTES + 32;
2789 ad->AttrLen = cpu_to_be16(size);
2790 ad->AttrType = cpu_to_be16(RPRT_ACTIVE_FC4_TYPES);
2795 lpfc_fdmi_port_attr_port_state(struct lpfc_vport *vport,
2796 struct lpfc_fdmi_attr_def *ad)
2798 struct lpfc_fdmi_attr_entry *ae;
2801 ae = &ad->AttrValue;
2802 /* Link Up - operational */
2803 ae->un.AttrInt = cpu_to_be32(LPFC_FDMI_PORTSTATE_ONLINE);
2804 size = FOURBYTES + sizeof(uint32_t);
2805 ad->AttrLen = cpu_to_be16(size);
2806 ad->AttrType = cpu_to_be16(RPRT_PORT_STATE);
2811 lpfc_fdmi_port_attr_num_disc(struct lpfc_vport *vport,
2812 struct lpfc_fdmi_attr_def *ad)
2814 struct lpfc_fdmi_attr_entry *ae;
2817 ae = &ad->AttrValue;
2818 vport->fdmi_num_disc = lpfc_find_map_node(vport);
2819 ae->un.AttrInt = cpu_to_be32(vport->fdmi_num_disc);
2820 size = FOURBYTES + sizeof(uint32_t);
2821 ad->AttrLen = cpu_to_be16(size);
2822 ad->AttrType = cpu_to_be16(RPRT_DISC_PORT);
2827 lpfc_fdmi_port_attr_nportid(struct lpfc_vport *vport,
2828 struct lpfc_fdmi_attr_def *ad)
2830 struct lpfc_fdmi_attr_entry *ae;
2833 ae = &ad->AttrValue;
2834 ae->un.AttrInt = cpu_to_be32(vport->fc_myDID);
2835 size = FOURBYTES + sizeof(uint32_t);
2836 ad->AttrLen = cpu_to_be16(size);
2837 ad->AttrType = cpu_to_be16(RPRT_PORT_ID);
2842 lpfc_fdmi_smart_attr_service(struct lpfc_vport *vport,
2843 struct lpfc_fdmi_attr_def *ad)
2845 struct lpfc_fdmi_attr_entry *ae;
2848 ae = &ad->AttrValue;
2849 memset(ae, 0, sizeof(*ae));
2851 strncpy(ae->un.AttrString, "Smart SAN Initiator",
2852 sizeof(ae->un.AttrString));
2853 len = strnlen(ae->un.AttrString,
2854 sizeof(ae->un.AttrString));
2855 len += (len & 3) ? (4 - (len & 3)) : 4;
2856 size = FOURBYTES + len;
2857 ad->AttrLen = cpu_to_be16(size);
2858 ad->AttrType = cpu_to_be16(RPRT_SMART_SERVICE);
2863 lpfc_fdmi_smart_attr_guid(struct lpfc_vport *vport,
2864 struct lpfc_fdmi_attr_def *ad)
2866 struct lpfc_fdmi_attr_entry *ae;
2869 ae = &ad->AttrValue;
2870 memset(ae, 0, sizeof(*ae));
2872 memcpy(&ae->un.AttrString, &vport->fc_sparam.nodeName,
2873 sizeof(struct lpfc_name));
2874 memcpy((((uint8_t *)&ae->un.AttrString) +
2875 sizeof(struct lpfc_name)),
2876 &vport->fc_sparam.portName, sizeof(struct lpfc_name));
2877 size = FOURBYTES + (2 * sizeof(struct lpfc_name));
2878 ad->AttrLen = cpu_to_be16(size);
2879 ad->AttrType = cpu_to_be16(RPRT_SMART_GUID);
2884 lpfc_fdmi_smart_attr_version(struct lpfc_vport *vport,
2885 struct lpfc_fdmi_attr_def *ad)
2887 struct lpfc_fdmi_attr_entry *ae;
2890 ae = &ad->AttrValue;
2891 memset(ae, 0, sizeof(*ae));
2893 strncpy(ae->un.AttrString, "Smart SAN Version 2.0",
2894 sizeof(ae->un.AttrString));
2895 len = strnlen(ae->un.AttrString,
2896 sizeof(ae->un.AttrString));
2897 len += (len & 3) ? (4 - (len & 3)) : 4;
2898 size = FOURBYTES + len;
2899 ad->AttrLen = cpu_to_be16(size);
2900 ad->AttrType = cpu_to_be16(RPRT_SMART_VERSION);
2905 lpfc_fdmi_smart_attr_model(struct lpfc_vport *vport,
2906 struct lpfc_fdmi_attr_def *ad)
2908 struct lpfc_hba *phba = vport->phba;
2909 struct lpfc_fdmi_attr_entry *ae;
2912 ae = &ad->AttrValue;
2913 memset(ae, 0, sizeof(*ae));
2915 strncpy(ae->un.AttrString, phba->ModelName,
2916 sizeof(ae->un.AttrString));
2917 len = strnlen(ae->un.AttrString, sizeof(ae->un.AttrString));
2918 len += (len & 3) ? (4 - (len & 3)) : 4;
2919 size = FOURBYTES + len;
2920 ad->AttrLen = cpu_to_be16(size);
2921 ad->AttrType = cpu_to_be16(RPRT_SMART_MODEL);
2926 lpfc_fdmi_smart_attr_port_info(struct lpfc_vport *vport,
2927 struct lpfc_fdmi_attr_def *ad)
2929 struct lpfc_fdmi_attr_entry *ae;
2932 ae = &ad->AttrValue;
2934 /* SRIOV (type 3) is not supported */
2936 ae->un.AttrInt = cpu_to_be32(2); /* NPIV */
2938 ae->un.AttrInt = cpu_to_be32(1); /* Physical */
2939 size = FOURBYTES + sizeof(uint32_t);
2940 ad->AttrLen = cpu_to_be16(size);
2941 ad->AttrType = cpu_to_be16(RPRT_SMART_PORT_INFO);
2946 lpfc_fdmi_smart_attr_qos(struct lpfc_vport *vport,
2947 struct lpfc_fdmi_attr_def *ad)
2949 struct lpfc_fdmi_attr_entry *ae;
2952 ae = &ad->AttrValue;
2953 ae->un.AttrInt = cpu_to_be32(0);
2954 size = FOURBYTES + sizeof(uint32_t);
2955 ad->AttrLen = cpu_to_be16(size);
2956 ad->AttrType = cpu_to_be16(RPRT_SMART_QOS);
2961 lpfc_fdmi_smart_attr_security(struct lpfc_vport *vport,
2962 struct lpfc_fdmi_attr_def *ad)
2964 struct lpfc_fdmi_attr_entry *ae;
2967 ae = &ad->AttrValue;
2968 ae->un.AttrInt = cpu_to_be32(1);
2969 size = FOURBYTES + sizeof(uint32_t);
2970 ad->AttrLen = cpu_to_be16(size);
2971 ad->AttrType = cpu_to_be16(RPRT_SMART_SECURITY);
2975 /* RHBA attribute jump table */
2976 int (*lpfc_fdmi_hba_action[])
2977 (struct lpfc_vport *vport, struct lpfc_fdmi_attr_def *ad) = {
2978 /* Action routine Mask bit Attribute type */
2979 lpfc_fdmi_hba_attr_wwnn, /* bit0 RHBA_NODENAME */
2980 lpfc_fdmi_hba_attr_manufacturer, /* bit1 RHBA_MANUFACTURER */
2981 lpfc_fdmi_hba_attr_sn, /* bit2 RHBA_SERIAL_NUMBER */
2982 lpfc_fdmi_hba_attr_model, /* bit3 RHBA_MODEL */
2983 lpfc_fdmi_hba_attr_description, /* bit4 RHBA_MODEL_DESCRIPTION */
2984 lpfc_fdmi_hba_attr_hdw_ver, /* bit5 RHBA_HARDWARE_VERSION */
2985 lpfc_fdmi_hba_attr_drvr_ver, /* bit6 RHBA_DRIVER_VERSION */
2986 lpfc_fdmi_hba_attr_rom_ver, /* bit7 RHBA_OPTION_ROM_VERSION */
2987 lpfc_fdmi_hba_attr_fmw_ver, /* bit8 RHBA_FIRMWARE_VERSION */
2988 lpfc_fdmi_hba_attr_os_ver, /* bit9 RHBA_OS_NAME_VERSION */
2989 lpfc_fdmi_hba_attr_ct_len, /* bit10 RHBA_MAX_CT_PAYLOAD_LEN */
2990 lpfc_fdmi_hba_attr_symbolic_name, /* bit11 RHBA_SYM_NODENAME */
2991 lpfc_fdmi_hba_attr_vendor_info, /* bit12 RHBA_VENDOR_INFO */
2992 lpfc_fdmi_hba_attr_num_ports, /* bit13 RHBA_NUM_PORTS */
2993 lpfc_fdmi_hba_attr_fabric_wwnn, /* bit14 RHBA_FABRIC_WWNN */
2994 lpfc_fdmi_hba_attr_bios_ver, /* bit15 RHBA_BIOS_VERSION */
2995 lpfc_fdmi_hba_attr_bios_state, /* bit16 RHBA_BIOS_STATE */
2996 lpfc_fdmi_hba_attr_vendor_id, /* bit17 RHBA_VENDOR_ID */
2999 /* RPA / RPRT attribute jump table */
3000 int (*lpfc_fdmi_port_action[])
3001 (struct lpfc_vport *vport, struct lpfc_fdmi_attr_def *ad) = {
3002 /* Action routine Mask bit Attribute type */
3003 lpfc_fdmi_port_attr_fc4type, /* bit0 RPRT_SUPPORT_FC4_TYPES */
3004 lpfc_fdmi_port_attr_support_speed, /* bit1 RPRT_SUPPORTED_SPEED */
3005 lpfc_fdmi_port_attr_speed, /* bit2 RPRT_PORT_SPEED */
3006 lpfc_fdmi_port_attr_max_frame, /* bit3 RPRT_MAX_FRAME_SIZE */
3007 lpfc_fdmi_port_attr_os_devname, /* bit4 RPRT_OS_DEVICE_NAME */
3008 lpfc_fdmi_port_attr_host_name, /* bit5 RPRT_HOST_NAME */
3009 lpfc_fdmi_port_attr_wwnn, /* bit6 RPRT_NODENAME */
3010 lpfc_fdmi_port_attr_wwpn, /* bit7 RPRT_PORTNAME */
3011 lpfc_fdmi_port_attr_symbolic_name, /* bit8 RPRT_SYM_PORTNAME */
3012 lpfc_fdmi_port_attr_port_type, /* bit9 RPRT_PORT_TYPE */
3013 lpfc_fdmi_port_attr_class, /* bit10 RPRT_SUPPORTED_CLASS */
3014 lpfc_fdmi_port_attr_fabric_wwpn, /* bit11 RPRT_FABRICNAME */
3015 lpfc_fdmi_port_attr_active_fc4type, /* bit12 RPRT_ACTIVE_FC4_TYPES */
3016 lpfc_fdmi_port_attr_port_state, /* bit13 RPRT_PORT_STATE */
3017 lpfc_fdmi_port_attr_num_disc, /* bit14 RPRT_DISC_PORT */
3018 lpfc_fdmi_port_attr_nportid, /* bit15 RPRT_PORT_ID */
3019 lpfc_fdmi_smart_attr_service, /* bit16 RPRT_SMART_SERVICE */
3020 lpfc_fdmi_smart_attr_guid, /* bit17 RPRT_SMART_GUID */
3021 lpfc_fdmi_smart_attr_version, /* bit18 RPRT_SMART_VERSION */
3022 lpfc_fdmi_smart_attr_model, /* bit19 RPRT_SMART_MODEL */
3023 lpfc_fdmi_smart_attr_port_info, /* bit20 RPRT_SMART_PORT_INFO */
3024 lpfc_fdmi_smart_attr_qos, /* bit21 RPRT_SMART_QOS */
3025 lpfc_fdmi_smart_attr_security, /* bit22 RPRT_SMART_SECURITY */
3029 * lpfc_fdmi_cmd - Build and send a FDMI cmd to the specified NPort
3030 * @vport: pointer to a host virtual N_Port data structure.
3031 * @ndlp: ndlp to send FDMI cmd to (if NULL use FDMI_DID)
3032 * @cmdcode: FDMI command to send
3033 * @new_mask: Mask of HBA or PORT Attributes to send
3035 * Builds and sends a FDMI command using the CT subsystem.
3038 lpfc_fdmi_cmd(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
3039 int cmdcode, uint32_t new_mask)
3041 struct lpfc_hba *phba = vport->phba;
3042 struct lpfc_dmabuf *mp, *bmp;
3043 struct lpfc_sli_ct_request *CtReq;
3044 struct ulp_bde64 *bpl;
3049 struct lpfc_fdmi_reg_hba *rh;
3050 struct lpfc_fdmi_port_entry *pe;
3051 struct lpfc_fdmi_reg_portattr *pab = NULL;
3052 struct lpfc_fdmi_attr_block *ab = NULL;
3053 int (*func)(struct lpfc_vport *vport, struct lpfc_fdmi_attr_def *ad);
3054 void (*cmpl)(struct lpfc_hba *, struct lpfc_iocbq *,
3055 struct lpfc_iocbq *);
3057 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
3060 cmpl = lpfc_cmpl_ct_disc_fdmi; /* called from discovery */
3062 /* fill in BDEs for command */
3063 /* Allocate buffer for command payload */
3064 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
3068 mp->virt = lpfc_mbuf_alloc(phba, 0, &(mp->phys));
3070 goto fdmi_cmd_free_mp;
3072 /* Allocate buffer for Buffer ptr list */
3073 bmp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
3075 goto fdmi_cmd_free_mpvirt;
3077 bmp->virt = lpfc_mbuf_alloc(phba, 0, &(bmp->phys));
3079 goto fdmi_cmd_free_bmp;
3081 INIT_LIST_HEAD(&mp->list);
3082 INIT_LIST_HEAD(&bmp->list);
3085 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
3086 "0218 FDMI Request Data: x%x x%x x%x\n",
3087 vport->fc_flag, vport->port_state, cmdcode);
3088 CtReq = (struct lpfc_sli_ct_request *)mp->virt;
3090 /* First populate the CT_IU preamble */
3091 memset(CtReq, 0, sizeof(struct lpfc_sli_ct_request));
3092 CtReq->RevisionId.bits.Revision = SLI_CT_REVISION;
3093 CtReq->RevisionId.bits.InId = 0;
3095 CtReq->FsType = SLI_CT_MANAGEMENT_SERVICE;
3096 CtReq->FsSubType = SLI_CT_FDMI_Subtypes;
3098 CtReq->CommandResponse.bits.CmdRsp = cpu_to_be16(cmdcode);
3099 rsp_size = LPFC_BPL_SIZE;
3102 /* Next fill in the specific FDMI cmd information */
3106 rh = (struct lpfc_fdmi_reg_hba *)&CtReq->un.PortID;
3107 /* HBA Identifier */
3108 memcpy(&rh->hi.PortName, &phba->pport->fc_sparam.portName,
3109 sizeof(struct lpfc_name));
3111 if (cmdcode == SLI_MGMT_RHBA) {
3112 /* Registered Port List */
3113 /* One entry (port) per adapter */
3114 rh->rpl.EntryCnt = cpu_to_be32(1);
3115 memcpy(&rh->rpl.pe.PortName,
3116 &phba->pport->fc_sparam.portName,
3117 sizeof(struct lpfc_name));
3119 /* point to the HBA attribute block */
3120 size = 2 * sizeof(struct lpfc_name) +
3123 size = sizeof(struct lpfc_name);
3125 ab = (struct lpfc_fdmi_attr_block *)((uint8_t *)rh + size);
3132 mask = vport->fdmi_hba_mask;
3134 /* Mask will dictate what attributes to build in the request */
3137 func = lpfc_fdmi_hba_action[bit_pos];
3139 (struct lpfc_fdmi_attr_def *)
3140 ((uint8_t *)rh + size));
3143 (LPFC_BPL_SIZE - LPFC_CT_PREAMBLE))
3150 ab->EntryCnt = cpu_to_be32(ab->EntryCnt);
3152 size = GID_REQUEST_SZ - 4 + size;
3157 pab = (struct lpfc_fdmi_reg_portattr *)&CtReq->un.PortID;
3158 if (cmdcode == SLI_MGMT_RPRT) {
3159 rh = (struct lpfc_fdmi_reg_hba *)pab;
3160 /* HBA Identifier */
3161 memcpy(&rh->hi.PortName,
3162 &phba->pport->fc_sparam.portName,
3163 sizeof(struct lpfc_name));
3164 pab = (struct lpfc_fdmi_reg_portattr *)
3165 ((uint8_t *)pab + sizeof(struct lpfc_name));
3168 memcpy((uint8_t *)&pab->PortName,
3169 (uint8_t *)&vport->fc_sparam.portName,
3170 sizeof(struct lpfc_name));
3171 size += sizeof(struct lpfc_name) + FOURBYTES;
3172 pab->ab.EntryCnt = 0;
3177 mask = vport->fdmi_port_mask;
3179 /* Mask will dictate what attributes to build in the request */
3182 func = lpfc_fdmi_port_action[bit_pos];
3184 (struct lpfc_fdmi_attr_def *)
3185 ((uint8_t *)pab + size));
3188 (LPFC_BPL_SIZE - LPFC_CT_PREAMBLE))
3195 pab->ab.EntryCnt = cpu_to_be32(pab->ab.EntryCnt);
3197 if (cmdcode == SLI_MGMT_RPRT)
3198 size += sizeof(struct lpfc_name);
3199 size = GID_REQUEST_SZ - 4 + size;
3204 rsp_size = FC_MAX_NS_RSP;
3208 pe = (struct lpfc_fdmi_port_entry *)&CtReq->un.PortID;
3209 memcpy((uint8_t *)&pe->PortName,
3210 (uint8_t *)&vport->fc_sparam.portName,
3211 sizeof(struct lpfc_name));
3212 size = GID_REQUEST_SZ - 4 + sizeof(struct lpfc_name);
3217 rsp_size = FC_MAX_NS_RSP;
3221 pe = (struct lpfc_fdmi_port_entry *)&CtReq->un.PortID;
3222 memcpy((uint8_t *)&pe->PortName,
3223 (uint8_t *)&vport->fc_sparam.portName,
3224 sizeof(struct lpfc_name));
3225 size = GID_REQUEST_SZ - 4 + sizeof(struct lpfc_name);
3228 size = GID_REQUEST_SZ - 4;
3231 lpfc_printf_vlog(vport, KERN_WARNING, LOG_DISCOVERY,
3232 "0298 FDMI cmdcode x%x not supported\n",
3234 goto fdmi_cmd_free_bmpvirt;
3236 CtReq->CommandResponse.bits.Size = cpu_to_be16(rsp_size);
3238 bpl = (struct ulp_bde64 *)bmp->virt;
3239 bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys));
3240 bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys));
3241 bpl->tus.f.bdeFlags = 0;
3242 bpl->tus.f.bdeSize = size;
3245 * The lpfc_ct_cmd/lpfc_get_req shall increment ndlp reference count
3246 * to hold ndlp reference for the corresponding callback function.
3248 if (!lpfc_ct_cmd(vport, mp, bmp, ndlp, cmpl, rsp_size, 0))
3252 * Decrement ndlp reference count to release ndlp reference held
3253 * for the failed command's callback function.
3257 fdmi_cmd_free_bmpvirt:
3258 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
3261 fdmi_cmd_free_mpvirt:
3262 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3266 /* Issue FDMI request failed */
3267 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
3268 "0244 Issue FDMI request failed Data: x%x\n",
3274 * lpfc_delayed_disc_tmo - Timeout handler for delayed discovery timer.
3275 * @t: Context object of the timer.
3277 * This function set the WORKER_DELAYED_DISC_TMO flag and wake up
3278 * the worker thread.
3281 lpfc_delayed_disc_tmo(struct timer_list *t)
3283 struct lpfc_vport *vport = from_timer(vport, t, delayed_disc_tmo);
3284 struct lpfc_hba *phba = vport->phba;
3285 uint32_t tmo_posted;
3286 unsigned long iflag;
3288 spin_lock_irqsave(&vport->work_port_lock, iflag);
3289 tmo_posted = vport->work_port_events & WORKER_DELAYED_DISC_TMO;
3291 vport->work_port_events |= WORKER_DELAYED_DISC_TMO;
3292 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
3295 lpfc_worker_wake_up(phba);
3300 * lpfc_delayed_disc_timeout_handler - Function called by worker thread to
3301 * handle delayed discovery.
3302 * @vport: pointer to a host virtual N_Port data structure.
3304 * This function start nport discovery of the vport.
3307 lpfc_delayed_disc_timeout_handler(struct lpfc_vport *vport)
3309 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3311 spin_lock_irq(shost->host_lock);
3312 if (!(vport->fc_flag & FC_DISC_DELAYED)) {
3313 spin_unlock_irq(shost->host_lock);
3316 vport->fc_flag &= ~FC_DISC_DELAYED;
3317 spin_unlock_irq(shost->host_lock);
3319 lpfc_do_scr_ns_plogi(vport->phba, vport);
3323 lpfc_decode_firmware_rev(struct lpfc_hba *phba, char *fwrevision, int flag)
3325 struct lpfc_sli *psli = &phba->sli;
3326 lpfc_vpd_t *vp = &phba->vpd;
3327 uint32_t b1, b2, b3, b4, i, rev;
3329 uint32_t *ptr, str[4];
3332 if (phba->sli_rev == LPFC_SLI_REV4)
3333 snprintf(fwrevision, FW_REV_STR_SIZE, "%s", vp->rev.opFwName);
3334 else if (vp->rev.rBit) {
3335 if (psli->sli_flag & LPFC_SLI_ACTIVE)
3336 rev = vp->rev.sli2FwRev;
3338 rev = vp->rev.sli1FwRev;
3340 b1 = (rev & 0x0000f000) >> 12;
3341 b2 = (rev & 0x00000f00) >> 8;
3342 b3 = (rev & 0x000000c0) >> 6;
3343 b4 = (rev & 0x00000030) >> 4;
3362 b4 = (rev & 0x0000000f);
3364 if (psli->sli_flag & LPFC_SLI_ACTIVE)
3365 fwname = vp->rev.sli2FwName;
3367 fwname = vp->rev.sli1FwName;
3369 for (i = 0; i < 16; i++)
3370 if (fwname[i] == 0x20)
3373 ptr = (uint32_t*)fwname;
3375 for (i = 0; i < 3; i++)
3376 str[i] = be32_to_cpu(*ptr++);
3380 sprintf(fwrevision, "%d.%d%d (%s)",
3381 b1, b2, b3, (char *)str);
3383 sprintf(fwrevision, "%d.%d%d", b1,
3387 sprintf(fwrevision, "%d.%d%d%c%d (%s)",
3391 sprintf(fwrevision, "%d.%d%d%c%d",
3395 rev = vp->rev.smFwRev;
3397 b1 = (rev & 0xff000000) >> 24;
3398 b2 = (rev & 0x00f00000) >> 20;
3399 b3 = (rev & 0x000f0000) >> 16;
3400 c = (rev & 0x0000ff00) >> 8;
3401 b4 = (rev & 0x000000ff);
3403 sprintf(fwrevision, "%d.%d%d%c%d", b1, b2, b3, c, b4);