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_nvme.h"
48 #include "lpfc_logmsg.h"
49 #include "lpfc_crtn.h"
50 #include "lpfc_version.h"
51 #include "lpfc_vport.h"
52 #include "lpfc_debugfs.h"
54 /* FDMI Port Speed definitions - FC-GS-7 */
55 #define HBA_PORTSPEED_1GFC 0x00000001 /* 1G FC */
56 #define HBA_PORTSPEED_2GFC 0x00000002 /* 2G FC */
57 #define HBA_PORTSPEED_4GFC 0x00000008 /* 4G FC */
58 #define HBA_PORTSPEED_10GFC 0x00000004 /* 10G FC */
59 #define HBA_PORTSPEED_8GFC 0x00000010 /* 8G FC */
60 #define HBA_PORTSPEED_16GFC 0x00000020 /* 16G FC */
61 #define HBA_PORTSPEED_32GFC 0x00000040 /* 32G FC */
62 #define HBA_PORTSPEED_20GFC 0x00000080 /* 20G FC */
63 #define HBA_PORTSPEED_40GFC 0x00000100 /* 40G FC */
64 #define HBA_PORTSPEED_128GFC 0x00000200 /* 128G FC */
65 #define HBA_PORTSPEED_64GFC 0x00000400 /* 64G FC */
66 #define HBA_PORTSPEED_256GFC 0x00000800 /* 256G FC */
67 #define HBA_PORTSPEED_UNKNOWN 0x00008000 /* Unknown */
68 #define HBA_PORTSPEED_10GE 0x00010000 /* 10G E */
69 #define HBA_PORTSPEED_40GE 0x00020000 /* 40G E */
70 #define HBA_PORTSPEED_100GE 0x00040000 /* 100G E */
71 #define HBA_PORTSPEED_25GE 0x00080000 /* 25G E */
72 #define HBA_PORTSPEED_50GE 0x00100000 /* 50G E */
73 #define HBA_PORTSPEED_400GE 0x00200000 /* 400G E */
78 static char *lpfc_release_version = LPFC_DRIVER_VERSION;
81 lpfc_ct_ignore_hbq_buffer(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq,
82 struct lpfc_dmabuf *mp, uint32_t size)
85 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
86 "0146 Ignoring unsolicited CT No HBQ "
88 piocbq->iocb.ulpStatus);
90 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
91 "0145 Ignoring unsolicted CT HBQ Size:%d "
93 size, piocbq->iocb.ulpStatus);
97 lpfc_ct_unsol_buffer(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq,
98 struct lpfc_dmabuf *mp, uint32_t size)
100 lpfc_ct_ignore_hbq_buffer(phba, piocbq, mp, size);
104 lpfc_ct_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
105 struct lpfc_iocbq *piocbq)
107 struct lpfc_dmabuf *mp = NULL;
108 IOCB_t *icmd = &piocbq->iocb;
110 struct lpfc_iocbq *iocbq;
113 struct list_head head;
114 struct lpfc_dmabuf *bdeBuf;
116 if (lpfc_bsg_ct_unsol_event(phba, pring, piocbq) == 0)
119 if (unlikely(icmd->ulpStatus == IOSTAT_NEED_BUFFER)) {
120 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
121 } else if ((icmd->ulpStatus == IOSTAT_LOCAL_REJECT) &&
122 ((icmd->un.ulpWord[4] & IOERR_PARAM_MASK) ==
123 IOERR_RCV_BUFFER_WAITING)) {
124 /* Not enough posted buffers; Try posting more buffers */
125 phba->fc_stat.NoRcvBuf++;
126 if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
127 lpfc_post_buffer(phba, pring, 2);
131 /* If there are no BDEs associated with this IOCB,
132 * there is nothing to do.
134 if (icmd->ulpBdeCount == 0)
137 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
138 INIT_LIST_HEAD(&head);
139 list_add_tail(&head, &piocbq->list);
140 list_for_each_entry(iocbq, &head, list) {
142 if (icmd->ulpBdeCount == 0)
144 bdeBuf = iocbq->context2;
145 iocbq->context2 = NULL;
146 size = icmd->un.cont64[0].tus.f.bdeSize;
147 lpfc_ct_unsol_buffer(phba, piocbq, bdeBuf, size);
148 lpfc_in_buf_free(phba, bdeBuf);
149 if (icmd->ulpBdeCount == 2) {
150 bdeBuf = iocbq->context3;
151 iocbq->context3 = NULL;
152 size = icmd->unsli3.rcvsli3.bde2.tus.f.bdeSize;
153 lpfc_ct_unsol_buffer(phba, piocbq, bdeBuf,
155 lpfc_in_buf_free(phba, bdeBuf);
160 INIT_LIST_HEAD(&head);
161 list_add_tail(&head, &piocbq->list);
162 list_for_each_entry(iocbq, &head, list) {
164 if (icmd->ulpBdeCount == 0)
165 lpfc_ct_unsol_buffer(phba, iocbq, NULL, 0);
166 for (i = 0; i < icmd->ulpBdeCount; i++) {
167 paddr = getPaddr(icmd->un.cont64[i].addrHigh,
168 icmd->un.cont64[i].addrLow);
169 mp = lpfc_sli_ringpostbuf_get(phba, pring,
171 size = icmd->un.cont64[i].tus.f.bdeSize;
172 lpfc_ct_unsol_buffer(phba, iocbq, mp, size);
173 lpfc_in_buf_free(phba, mp);
175 lpfc_post_buffer(phba, pring, i);
182 * lpfc_ct_handle_unsol_abort - ct upper level protocol abort handler
183 * @phba: Pointer to HBA context object.
184 * @dmabuf: pointer to a dmabuf that describes the FC sequence
186 * This function serves as the upper level protocol abort handler for CT
189 * Return 1 if abort has been handled, 0 otherwise.
192 lpfc_ct_handle_unsol_abort(struct lpfc_hba *phba, struct hbq_dmabuf *dmabuf)
196 /* CT upper level goes through BSG */
197 handled = lpfc_bsg_ct_unsol_abort(phba, dmabuf);
203 lpfc_free_ct_rsp(struct lpfc_hba *phba, struct lpfc_dmabuf *mlist)
205 struct lpfc_dmabuf *mlast, *next_mlast;
207 list_for_each_entry_safe(mlast, next_mlast, &mlist->list, list) {
208 lpfc_mbuf_free(phba, mlast->virt, mlast->phys);
209 list_del(&mlast->list);
212 lpfc_mbuf_free(phba, mlist->virt, mlist->phys);
217 static struct lpfc_dmabuf *
218 lpfc_alloc_ct_rsp(struct lpfc_hba *phba, int cmdcode, struct ulp_bde64 *bpl,
219 uint32_t size, int *entries)
221 struct lpfc_dmabuf *mlist = NULL;
222 struct lpfc_dmabuf *mp;
225 /* We get chunks of FCELSSIZE */
226 cnt = size > FCELSSIZE ? FCELSSIZE: size;
229 /* Allocate buffer for rsp payload */
230 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
233 lpfc_free_ct_rsp(phba, mlist);
237 INIT_LIST_HEAD(&mp->list);
239 if (cmdcode == be16_to_cpu(SLI_CTNS_GID_FT) ||
240 cmdcode == be16_to_cpu(SLI_CTNS_GFF_ID))
241 mp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(mp->phys));
243 mp->virt = lpfc_mbuf_alloc(phba, 0, &(mp->phys));
248 lpfc_free_ct_rsp(phba, mlist);
252 /* Queue it to a linked list */
256 list_add_tail(&mp->list, &mlist->list);
258 bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64I;
259 /* build buffer ptr list for IOCB */
260 bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys) );
261 bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys) );
262 bpl->tus.f.bdeSize = (uint16_t) cnt;
263 bpl->tus.w = le32_to_cpu(bpl->tus.w);
275 lpfc_ct_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *ctiocb)
277 struct lpfc_dmabuf *buf_ptr;
279 if (ctiocb->context_un.ndlp) {
280 lpfc_nlp_put(ctiocb->context_un.ndlp);
281 ctiocb->context_un.ndlp = NULL;
283 if (ctiocb->context1) {
284 buf_ptr = (struct lpfc_dmabuf *) ctiocb->context1;
285 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
287 ctiocb->context1 = NULL;
289 if (ctiocb->context2) {
290 lpfc_free_ct_rsp(phba, (struct lpfc_dmabuf *) ctiocb->context2);
291 ctiocb->context2 = NULL;
294 if (ctiocb->context3) {
295 buf_ptr = (struct lpfc_dmabuf *) ctiocb->context3;
296 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
298 ctiocb->context3 = NULL;
300 lpfc_sli_release_iocbq(phba, ctiocb);
305 * lpfc_gen_req - Build and issue a GEN_REQUEST command to the SLI Layer
306 * @vport: pointer to a host virtual N_Port data structure.
307 * @bmp: Pointer to BPL for SLI command
308 * @inp: Pointer to data buffer for response data.
309 * @outp: Pointer to data buffer that hold the CT command.
310 * @cmpl: completion routine to call when command completes
311 * @ndlp: Destination NPort nodelist entry
313 * This function as the final part for issuing a CT command.
316 lpfc_gen_req(struct lpfc_vport *vport, struct lpfc_dmabuf *bmp,
317 struct lpfc_dmabuf *inp, struct lpfc_dmabuf *outp,
318 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
319 struct lpfc_iocbq *),
320 struct lpfc_nodelist *ndlp, uint32_t usr_flg, uint32_t num_entry,
321 uint32_t tmo, uint8_t retry)
323 struct lpfc_hba *phba = vport->phba;
325 struct lpfc_iocbq *geniocb;
328 /* Allocate buffer for command iocb */
329 geniocb = lpfc_sli_get_iocbq(phba);
334 icmd = &geniocb->iocb;
335 icmd->un.genreq64.bdl.ulpIoTag32 = 0;
336 icmd->un.genreq64.bdl.addrHigh = putPaddrHigh(bmp->phys);
337 icmd->un.genreq64.bdl.addrLow = putPaddrLow(bmp->phys);
338 icmd->un.genreq64.bdl.bdeFlags = BUFF_TYPE_BLP_64;
339 icmd->un.genreq64.bdl.bdeSize = (num_entry * sizeof(struct ulp_bde64));
342 geniocb->context3 = NULL;
344 geniocb->context3 = (uint8_t *) bmp;
346 /* Save for completion so we can release these resources */
347 geniocb->context1 = (uint8_t *) inp;
348 geniocb->context2 = (uint8_t *) outp;
349 geniocb->context_un.ndlp = lpfc_nlp_get(ndlp);
351 /* Fill in payload, bp points to frame payload */
352 icmd->ulpCommand = CMD_GEN_REQUEST64_CR;
354 /* Fill in rest of iocb */
355 icmd->un.genreq64.w5.hcsw.Fctl = (SI | LA);
356 icmd->un.genreq64.w5.hcsw.Dfctl = 0;
357 icmd->un.genreq64.w5.hcsw.Rctl = FC_RCTL_DD_UNSOL_CTL;
358 icmd->un.genreq64.w5.hcsw.Type = FC_TYPE_CT;
361 /* FC spec states we need 3 * ratov for CT requests */
362 tmo = (3 * phba->fc_ratov);
364 icmd->ulpTimeout = tmo;
365 icmd->ulpBdeCount = 1;
367 icmd->ulpClass = CLASS3;
368 icmd->ulpContext = ndlp->nlp_rpi;
369 if (phba->sli_rev == LPFC_SLI_REV4)
370 icmd->ulpContext = phba->sli4_hba.rpi_ids[ndlp->nlp_rpi];
372 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
373 /* For GEN_REQUEST64_CR, use the RPI */
378 /* Issue GEN REQ IOCB for NPORT <did> */
379 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
380 "0119 Issue GEN REQ IOCB to NPORT x%x "
382 ndlp->nlp_DID, icmd->ulpIoTag,
384 geniocb->iocb_cmpl = cmpl;
385 geniocb->drvrTimeout = icmd->ulpTimeout + LPFC_DRVR_TIMEOUT;
386 geniocb->vport = vport;
387 geniocb->retry = retry;
388 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, geniocb, 0);
390 if (rc == IOCB_ERROR) {
391 lpfc_sli_release_iocbq(phba, geniocb);
399 * lpfc_ct_cmd - Build and issue a CT command
400 * @vport: pointer to a host virtual N_Port data structure.
401 * @inmp: Pointer to data buffer for response data.
402 * @bmp: Pointer to BPL for SLI command
403 * @ndlp: Destination NPort nodelist entry
404 * @cmpl: completion routine to call when command completes
406 * This function is called for issuing a CT command.
409 lpfc_ct_cmd(struct lpfc_vport *vport, struct lpfc_dmabuf *inmp,
410 struct lpfc_dmabuf *bmp, struct lpfc_nodelist *ndlp,
411 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
412 struct lpfc_iocbq *),
413 uint32_t rsp_size, uint8_t retry)
415 struct lpfc_hba *phba = vport->phba;
416 struct ulp_bde64 *bpl = (struct ulp_bde64 *) bmp->virt;
417 struct lpfc_dmabuf *outmp;
419 int cmdcode = ((struct lpfc_sli_ct_request *) inmp->virt)->
420 CommandResponse.bits.CmdRsp;
422 bpl++; /* Skip past ct request */
424 /* Put buffer(s) for ct rsp in bpl */
425 outmp = lpfc_alloc_ct_rsp(phba, cmdcode, bpl, rsp_size, &cnt);
429 * Form the CT IOCB. The total number of BDEs in this IOCB
430 * is the single command plus response count from
434 status = lpfc_gen_req(vport, bmp, inmp, outmp, cmpl, ndlp, 0,
437 lpfc_free_ct_rsp(phba, outmp);
444 lpfc_find_vport_by_did(struct lpfc_hba *phba, uint32_t did) {
445 struct lpfc_vport *vport_curr;
448 spin_lock_irqsave(&phba->port_list_lock, flags);
449 list_for_each_entry(vport_curr, &phba->port_list, listentry) {
450 if ((vport_curr->fc_myDID) && (vport_curr->fc_myDID == did)) {
451 spin_unlock_irqrestore(&phba->port_list_lock, flags);
455 spin_unlock_irqrestore(&phba->port_list_lock, flags);
460 lpfc_prep_node_fc4type(struct lpfc_vport *vport, uint32_t Did, uint8_t fc4_type)
462 struct lpfc_nodelist *ndlp;
464 if ((vport->port_type != LPFC_NPIV_PORT) ||
465 !(vport->ct_flags & FC_CT_RFF_ID) || !vport->cfg_restrict_login) {
467 ndlp = lpfc_setup_disc_node(vport, Did);
469 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
470 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
471 "Parse GID_FTrsp: did:x%x flg:x%x x%x",
472 Did, ndlp->nlp_flag, vport->fc_flag);
474 /* By default, the driver expects to support FCP FC4 */
475 if (fc4_type == FC_TYPE_FCP)
476 ndlp->nlp_fc4_type |= NLP_FC4_FCP;
478 if (fc4_type == FC_TYPE_NVME)
479 ndlp->nlp_fc4_type |= NLP_FC4_NVME;
481 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
482 "0238 Process x%06x NameServer Rsp "
483 "Data: x%x x%x x%x x%x x%x\n", Did,
484 ndlp->nlp_flag, ndlp->nlp_fc4_type,
485 ndlp->nlp_state, vport->fc_flag,
486 vport->fc_rscn_id_cnt);
488 /* if ndlp needs to be discovered and prior
489 * state of ndlp hit devloss, change state to
492 if (ndlp->nlp_flag & NLP_NPR_2B_DISC &&
493 ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
494 lpfc_nlp_set_state(vport, ndlp,
498 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
499 "Skip1 GID_FTrsp: did:x%x flg:x%x cnt:%d",
500 Did, vport->fc_flag, vport->fc_rscn_id_cnt);
502 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
503 "0239 Skip x%06x NameServer Rsp "
504 "Data: x%x x%x %p\n",
506 vport->fc_rscn_id_cnt, ndlp);
509 if (!(vport->fc_flag & FC_RSCN_MODE) ||
510 lpfc_rscn_payload_check(vport, Did)) {
511 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
512 "Query GID_FTrsp: did:x%x flg:x%x cnt:%d",
513 Did, vport->fc_flag, vport->fc_rscn_id_cnt);
516 * This NPortID was previously a FCP/NVMe target,
517 * Don't even bother to send GFF_ID.
519 ndlp = lpfc_findnode_did(vport, Did);
520 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
522 (NLP_FCP_TARGET | NLP_NVME_TARGET))) {
523 if (fc4_type == FC_TYPE_FCP)
524 ndlp->nlp_fc4_type |= NLP_FC4_FCP;
525 if (fc4_type == FC_TYPE_NVME)
526 ndlp->nlp_fc4_type |= NLP_FC4_NVME;
527 lpfc_setup_disc_node(vport, Did);
528 } else if (lpfc_ns_cmd(vport, SLI_CTNS_GFF_ID,
530 vport->num_disc_nodes++;
532 lpfc_setup_disc_node(vport, Did);
534 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
535 "Skip2 GID_FTrsp: did:x%x flg:x%x cnt:%d",
536 Did, vport->fc_flag, vport->fc_rscn_id_cnt);
538 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
539 "0245 Skip x%06x NameServer Rsp "
540 "Data: x%x x%x\n", Did,
542 vport->fc_rscn_id_cnt);
548 lpfc_ns_rsp_audit_did(struct lpfc_vport *vport, uint32_t Did, uint8_t fc4_type)
550 struct lpfc_hba *phba = vport->phba;
551 struct lpfc_nodelist *ndlp = NULL;
552 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
555 if (phba->cfg_ns_query == LPFC_NS_QUERY_GID_FT)
559 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
560 "6430 Process %s rsp for %08x type %x %s %s\n",
562 (fc4_type == FC_TYPE_FCP) ? "FCP" : " ",
563 (fc4_type == FC_TYPE_NVME) ? "NVME" : " ");
565 * To conserve rpi's, filter out addresses for other
566 * vports on the same physical HBAs.
568 if (Did != vport->fc_myDID &&
569 (!lpfc_find_vport_by_did(phba, Did) ||
570 vport->cfg_peer_port_login)) {
571 if (!phba->nvmet_support) {
572 /* FCPI/NVMEI path. Process Did */
573 lpfc_prep_node_fc4type(vport, Did, fc4_type);
576 /* NVMET path. NVMET only cares about NVMEI nodes. */
577 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
578 if (ndlp->nlp_type != NLP_NVME_INITIATOR ||
579 ndlp->nlp_state != NLP_STE_UNMAPPED_NODE)
581 spin_lock_irq(shost->host_lock);
582 if (ndlp->nlp_DID == Did)
583 ndlp->nlp_flag &= ~NLP_NVMET_RECOV;
585 ndlp->nlp_flag |= NLP_NVMET_RECOV;
586 spin_unlock_irq(shost->host_lock);
592 lpfc_ns_rsp(struct lpfc_vport *vport, struct lpfc_dmabuf *mp, uint8_t fc4_type,
595 struct lpfc_sli_ct_request *Response =
596 (struct lpfc_sli_ct_request *) mp->virt;
597 struct lpfc_dmabuf *mlast, *next_mp;
598 uint32_t *ctptr = (uint32_t *) & Response->un.gid.PortType;
599 uint32_t Did, CTentry;
601 struct list_head head;
602 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
603 struct lpfc_nodelist *ndlp = NULL;
605 lpfc_set_disctmo(vport);
606 vport->num_disc_nodes = 0;
607 vport->fc_ns_retry = 0;
610 list_add_tail(&head, &mp->list);
611 list_for_each_entry_safe(mp, next_mp, &head, list) {
614 Cnt = Size > FCELSSIZE ? FCELSSIZE : Size;
619 ctptr = (uint32_t *) mlast->virt;
621 Cnt -= 16; /* subtract length of CT header */
623 /* Loop through entire NameServer list of DIDs */
624 while (Cnt >= sizeof(uint32_t)) {
625 /* Get next DID from NameServer List */
627 Did = ((be32_to_cpu(CTentry)) & Mask_DID);
628 lpfc_ns_rsp_audit_did(vport, Did, fc4_type);
629 if (CTentry & (cpu_to_be32(SLI_CT_LAST_ENTRY)))
632 Cnt -= sizeof(uint32_t);
638 /* All GID_FT entries processed. If the driver is running in
639 * in target mode, put impacted nodes into recovery and drop
640 * the RPI to flush outstanding IO.
642 if (vport->phba->nvmet_support) {
643 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
644 if (!(ndlp->nlp_flag & NLP_NVMET_RECOV))
646 lpfc_disc_state_machine(vport, ndlp, NULL,
647 NLP_EVT_DEVICE_RECOVERY);
648 spin_lock_irq(shost->host_lock);
649 ndlp->nlp_flag &= ~NLP_NVMET_RECOV;
650 spin_unlock_irq(shost->host_lock);
660 lpfc_cmpl_ct_cmd_gid_ft(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
661 struct lpfc_iocbq *rspiocb)
663 struct lpfc_vport *vport = cmdiocb->vport;
664 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
666 struct lpfc_dmabuf *outp;
667 struct lpfc_dmabuf *inp;
668 struct lpfc_sli_ct_request *CTrsp;
669 struct lpfc_sli_ct_request *CTreq;
670 struct lpfc_nodelist *ndlp;
673 /* First save ndlp, before we overwrite it */
674 ndlp = cmdiocb->context_un.ndlp;
676 /* we pass cmdiocb to state machine which needs rspiocb as well */
677 cmdiocb->context_un.rsp_iocb = rspiocb;
678 inp = (struct lpfc_dmabuf *) cmdiocb->context1;
679 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
680 irsp = &rspiocb->iocb;
682 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
683 "GID_FT cmpl: status:x%x/x%x rtry:%d",
684 irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_ns_retry);
686 /* Don't bother processing response if vport is being torn down. */
687 if (vport->load_flag & FC_UNLOADING) {
688 if (vport->fc_flag & FC_RSCN_MODE)
689 lpfc_els_flush_rscn(vport);
693 if (lpfc_els_chk_latt(vport)) {
694 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
695 "0216 Link event during NS query\n");
696 if (vport->fc_flag & FC_RSCN_MODE)
697 lpfc_els_flush_rscn(vport);
698 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
701 if (lpfc_error_lost_link(irsp)) {
702 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
703 "0226 NS query failed due to link event\n");
704 if (vport->fc_flag & FC_RSCN_MODE)
705 lpfc_els_flush_rscn(vport);
709 spin_lock_irq(shost->host_lock);
710 if (vport->fc_flag & FC_RSCN_DEFERRED) {
711 vport->fc_flag &= ~FC_RSCN_DEFERRED;
712 spin_unlock_irq(shost->host_lock);
714 /* This is a GID_FT completing so the gidft_inp counter was
715 * incremented before the GID_FT was issued to the wire.
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 */
746 rc = lpfc_ns_cmd(vport, SLI_CTNS_GID_FT,
747 vport->fc_ns_retry, type);
751 if (vport->fc_flag & FC_RSCN_MODE)
752 lpfc_els_flush_rscn(vport);
753 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
754 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
755 "0257 GID_FT Query error: 0x%x 0x%x\n",
756 irsp->ulpStatus, vport->fc_ns_retry);
758 /* Good status, continue checking */
759 CTreq = (struct lpfc_sli_ct_request *) inp->virt;
760 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
761 if (CTrsp->CommandResponse.bits.CmdRsp ==
762 cpu_to_be16(SLI_CT_RESPONSE_FS_ACC)) {
763 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
764 "0208 NameServer Rsp Data: x%x x%x "
767 CTreq->un.gid.Fc4Type,
768 vport->num_disc_nodes,
770 irsp->un.genreq64.bdl.bdeSize);
774 CTreq->un.gid.Fc4Type,
775 (uint32_t) (irsp->un.genreq64.bdl.bdeSize));
776 } else if (CTrsp->CommandResponse.bits.CmdRsp ==
777 be16_to_cpu(SLI_CT_RESPONSE_FS_RJT)) {
778 /* NameServer Rsp Error */
779 if ((CTrsp->ReasonCode == SLI_CT_UNABLE_TO_PERFORM_REQ)
780 && (CTrsp->Explanation == SLI_CT_NO_FC4_TYPES)) {
781 lpfc_printf_vlog(vport, KERN_INFO,
783 "0269 No NameServer Entries "
784 "Data: x%x x%x x%x x%x\n",
785 CTrsp->CommandResponse.bits.CmdRsp,
786 (uint32_t) CTrsp->ReasonCode,
787 (uint32_t) CTrsp->Explanation,
790 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
791 "GID_FT no entry cmd:x%x rsn:x%x exp:x%x",
792 (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
793 (uint32_t) CTrsp->ReasonCode,
794 (uint32_t) CTrsp->Explanation);
796 lpfc_printf_vlog(vport, KERN_INFO,
798 "0240 NameServer Rsp Error "
799 "Data: x%x x%x x%x x%x\n",
800 CTrsp->CommandResponse.bits.CmdRsp,
801 (uint32_t) CTrsp->ReasonCode,
802 (uint32_t) CTrsp->Explanation,
805 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
806 "GID_FT rsp err1 cmd:x%x rsn:x%x exp:x%x",
807 (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
808 (uint32_t) CTrsp->ReasonCode,
809 (uint32_t) CTrsp->Explanation);
814 /* NameServer Rsp Error */
815 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
816 "0241 NameServer Rsp Error "
817 "Data: x%x x%x x%x x%x\n",
818 CTrsp->CommandResponse.bits.CmdRsp,
819 (uint32_t) CTrsp->ReasonCode,
820 (uint32_t) CTrsp->Explanation,
823 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
824 "GID_FT rsp err2 cmd:x%x rsn:x%x exp:x%x",
825 (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
826 (uint32_t) CTrsp->ReasonCode,
827 (uint32_t) CTrsp->Explanation);
832 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
833 "4216 GID_FT cmpl inp %d disc %d\n",
834 vport->gidft_inp, vport->num_disc_nodes);
836 /* Link up / RSCN discovery */
837 if ((vport->num_disc_nodes == 0) &&
838 (vport->gidft_inp == 0)) {
840 * The driver has cycled through all Nports in the RSCN payload.
841 * Complete the handling by cleaning up and marking the
842 * current driver state.
844 if (vport->port_state >= LPFC_DISC_AUTH) {
845 if (vport->fc_flag & FC_RSCN_MODE) {
846 lpfc_els_flush_rscn(vport);
847 spin_lock_irq(shost->host_lock);
848 vport->fc_flag |= FC_RSCN_MODE; /* RSCN still */
849 spin_unlock_irq(shost->host_lock);
852 lpfc_els_flush_rscn(vport);
855 lpfc_disc_start(vport);
858 cmdiocb->context_un.ndlp = ndlp; /* Now restore ndlp for free */
859 lpfc_ct_free_iocb(phba, cmdiocb);
864 lpfc_cmpl_ct_cmd_gid_pt(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
865 struct lpfc_iocbq *rspiocb)
867 struct lpfc_vport *vport = cmdiocb->vport;
868 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
870 struct lpfc_dmabuf *outp;
871 struct lpfc_dmabuf *inp;
872 struct lpfc_sli_ct_request *CTrsp;
873 struct lpfc_sli_ct_request *CTreq;
874 struct lpfc_nodelist *ndlp;
877 /* First save ndlp, before we overwrite it */
878 ndlp = cmdiocb->context_un.ndlp;
880 /* we pass cmdiocb to state machine which needs rspiocb as well */
881 cmdiocb->context_un.rsp_iocb = rspiocb;
882 inp = (struct lpfc_dmabuf *)cmdiocb->context1;
883 outp = (struct lpfc_dmabuf *)cmdiocb->context2;
884 irsp = &rspiocb->iocb;
886 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
887 "GID_PT cmpl: status:x%x/x%x rtry:%d",
888 irsp->ulpStatus, irsp->un.ulpWord[4],
891 /* Don't bother processing response if vport is being torn down. */
892 if (vport->load_flag & FC_UNLOADING) {
893 if (vport->fc_flag & FC_RSCN_MODE)
894 lpfc_els_flush_rscn(vport);
898 if (lpfc_els_chk_latt(vport)) {
899 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
900 "4108 Link event during NS query\n");
901 if (vport->fc_flag & FC_RSCN_MODE)
902 lpfc_els_flush_rscn(vport);
903 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
906 if (lpfc_error_lost_link(irsp)) {
907 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
908 "4166 NS query failed due to link event\n");
909 if (vport->fc_flag & FC_RSCN_MODE)
910 lpfc_els_flush_rscn(vport);
914 spin_lock_irq(shost->host_lock);
915 if (vport->fc_flag & FC_RSCN_DEFERRED) {
916 vport->fc_flag &= ~FC_RSCN_DEFERRED;
917 spin_unlock_irq(shost->host_lock);
919 /* This is a GID_PT completing so the gidft_inp counter was
920 * incremented before the GID_PT was issued to the wire.
925 * Skip processing the NS response
926 * Re-issue the NS cmd
928 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
929 "4167 Process Deferred RSCN Data: x%x x%x\n",
930 vport->fc_flag, vport->fc_rscn_id_cnt);
931 lpfc_els_handle_rscn(vport);
935 spin_unlock_irq(shost->host_lock);
937 if (irsp->ulpStatus) {
938 /* Check for retry */
939 if (vport->fc_ns_retry < LPFC_MAX_NS_RETRY) {
940 if (irsp->ulpStatus != IOSTAT_LOCAL_REJECT ||
941 (irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
943 vport->fc_ns_retry++;
945 /* CT command is being retried */
947 rc = lpfc_ns_cmd(vport, SLI_CTNS_GID_PT,
948 vport->fc_ns_retry, GID_PT_N_PORT);
952 if (vport->fc_flag & FC_RSCN_MODE)
953 lpfc_els_flush_rscn(vport);
954 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
955 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
956 "4103 GID_FT Query error: 0x%x 0x%x\n",
957 irsp->ulpStatus, vport->fc_ns_retry);
959 /* Good status, continue checking */
960 CTreq = (struct lpfc_sli_ct_request *)inp->virt;
961 CTrsp = (struct lpfc_sli_ct_request *)outp->virt;
962 if (CTrsp->CommandResponse.bits.CmdRsp ==
963 cpu_to_be16(SLI_CT_RESPONSE_FS_ACC)) {
964 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
965 "4105 NameServer Rsp Data: x%x x%x "
968 CTreq->un.gid.Fc4Type,
969 vport->num_disc_nodes,
971 irsp->un.genreq64.bdl.bdeSize);
975 CTreq->un.gid.Fc4Type,
976 (uint32_t)(irsp->un.genreq64.bdl.bdeSize));
977 } else if (CTrsp->CommandResponse.bits.CmdRsp ==
978 be16_to_cpu(SLI_CT_RESPONSE_FS_RJT)) {
979 /* NameServer Rsp Error */
980 if ((CTrsp->ReasonCode == SLI_CT_UNABLE_TO_PERFORM_REQ)
981 && (CTrsp->Explanation == SLI_CT_NO_FC4_TYPES)) {
983 vport, KERN_INFO, LOG_DISCOVERY,
984 "4106 No NameServer Entries "
985 "Data: x%x x%x x%x x%x\n",
986 CTrsp->CommandResponse.bits.CmdRsp,
987 (uint32_t)CTrsp->ReasonCode,
988 (uint32_t)CTrsp->Explanation,
991 lpfc_debugfs_disc_trc(
992 vport, LPFC_DISC_TRC_CT,
993 "GID_PT no entry cmd:x%x rsn:x%x exp:x%x",
994 (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
995 (uint32_t)CTrsp->ReasonCode,
996 (uint32_t)CTrsp->Explanation);
999 vport, KERN_INFO, LOG_DISCOVERY,
1000 "4107 NameServer Rsp Error "
1001 "Data: x%x x%x x%x x%x\n",
1002 CTrsp->CommandResponse.bits.CmdRsp,
1003 (uint32_t)CTrsp->ReasonCode,
1004 (uint32_t)CTrsp->Explanation,
1007 lpfc_debugfs_disc_trc(
1008 vport, LPFC_DISC_TRC_CT,
1009 "GID_PT rsp err1 cmd:x%x rsn:x%x exp:x%x",
1010 (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
1011 (uint32_t)CTrsp->ReasonCode,
1012 (uint32_t)CTrsp->Explanation);
1015 /* NameServer Rsp Error */
1016 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
1017 "4109 NameServer Rsp Error "
1018 "Data: x%x x%x x%x x%x\n",
1019 CTrsp->CommandResponse.bits.CmdRsp,
1020 (uint32_t)CTrsp->ReasonCode,
1021 (uint32_t)CTrsp->Explanation,
1024 lpfc_debugfs_disc_trc(
1025 vport, LPFC_DISC_TRC_CT,
1026 "GID_PT rsp err2 cmd:x%x rsn:x%x exp:x%x",
1027 (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
1028 (uint32_t)CTrsp->ReasonCode,
1029 (uint32_t)CTrsp->Explanation);
1034 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1035 "6450 GID_PT cmpl inp %d disc %d\n",
1036 vport->gidft_inp, vport->num_disc_nodes);
1038 /* Link up / RSCN discovery */
1039 if ((vport->num_disc_nodes == 0) &&
1040 (vport->gidft_inp == 0)) {
1042 * The driver has cycled through all Nports in the RSCN payload.
1043 * Complete the handling by cleaning up and marking the
1044 * current driver state.
1046 if (vport->port_state >= LPFC_DISC_AUTH) {
1047 if (vport->fc_flag & FC_RSCN_MODE) {
1048 lpfc_els_flush_rscn(vport);
1049 spin_lock_irq(shost->host_lock);
1050 vport->fc_flag |= FC_RSCN_MODE; /* RSCN still */
1051 spin_unlock_irq(shost->host_lock);
1053 lpfc_els_flush_rscn(vport);
1057 lpfc_disc_start(vport);
1060 cmdiocb->context_un.ndlp = ndlp; /* Now restore ndlp for free */
1061 lpfc_ct_free_iocb(phba, cmdiocb);
1065 lpfc_cmpl_ct_cmd_gff_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1066 struct lpfc_iocbq *rspiocb)
1068 struct lpfc_vport *vport = cmdiocb->vport;
1069 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1070 IOCB_t *irsp = &rspiocb->iocb;
1071 struct lpfc_dmabuf *inp = (struct lpfc_dmabuf *) cmdiocb->context1;
1072 struct lpfc_dmabuf *outp = (struct lpfc_dmabuf *) cmdiocb->context2;
1073 struct lpfc_sli_ct_request *CTrsp;
1076 struct lpfc_nodelist *ndlp;
1078 did = ((struct lpfc_sli_ct_request *) inp->virt)->un.gff.PortId;
1079 did = be32_to_cpu(did);
1081 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
1082 "GFF_ID cmpl: status:x%x/x%x did:x%x",
1083 irsp->ulpStatus, irsp->un.ulpWord[4], did);
1085 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
1086 /* Good status, continue checking */
1087 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
1088 fbits = CTrsp->un.gff_acc.fbits[FCP_TYPE_FEATURE_OFFSET];
1090 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1091 "6431 Process GFF_ID rsp for %08x "
1092 "fbits %02x %s %s\n",
1094 (fbits & FC4_FEATURE_INIT) ? "Initiator" : " ",
1095 (fbits & FC4_FEATURE_TARGET) ? "Target" : " ");
1097 if (CTrsp->CommandResponse.bits.CmdRsp ==
1098 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC)) {
1099 if ((fbits & FC4_FEATURE_INIT) &&
1100 !(fbits & FC4_FEATURE_TARGET)) {
1101 lpfc_printf_vlog(vport, KERN_INFO,
1103 "0270 Skip x%x GFF "
1104 "NameServer Rsp Data: (init) "
1105 "x%x x%x\n", did, fbits,
1106 vport->fc_rscn_id_cnt);
1112 /* Check for retry */
1113 if (cmdiocb->retry < LPFC_MAX_NS_RETRY) {
1115 if (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) {
1116 switch ((irsp->un.ulpWord[4] &
1117 IOERR_PARAM_MASK)) {
1119 case IOERR_NO_RESOURCES:
1120 /* We don't increment the retry
1121 * count for this case.
1124 case IOERR_LINK_DOWN:
1125 case IOERR_SLI_ABORTED:
1126 case IOERR_SLI_DOWN:
1137 /* CT command is being retried */
1138 rc = lpfc_ns_cmd(vport, SLI_CTNS_GFF_ID,
1139 cmdiocb->retry, did);
1142 lpfc_ct_free_iocb(phba, cmdiocb);
1147 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
1148 "0267 NameServer GFF Rsp "
1149 "x%x Error (%d %d) Data: x%x x%x\n",
1150 did, irsp->ulpStatus, irsp->un.ulpWord[4],
1151 vport->fc_flag, vport->fc_rscn_id_cnt);
1154 /* This is a target port, unregistered port, or the GFF_ID failed */
1155 ndlp = lpfc_setup_disc_node(vport, did);
1156 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
1157 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1158 "0242 Process x%x GFF "
1159 "NameServer Rsp Data: x%x x%x x%x\n",
1160 did, ndlp->nlp_flag, vport->fc_flag,
1161 vport->fc_rscn_id_cnt);
1163 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1164 "0243 Skip x%x GFF "
1165 "NameServer Rsp Data: x%x x%x\n", did,
1166 vport->fc_flag, vport->fc_rscn_id_cnt);
1169 /* Link up / RSCN discovery */
1170 if (vport->num_disc_nodes)
1171 vport->num_disc_nodes--;
1173 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1174 "6451 GFF_ID cmpl inp %d disc %d\n",
1175 vport->gidft_inp, vport->num_disc_nodes);
1177 if (vport->num_disc_nodes == 0) {
1179 * The driver has cycled through all Nports in the RSCN payload.
1180 * Complete the handling by cleaning up and marking the
1181 * current driver state.
1183 if (vport->port_state >= LPFC_DISC_AUTH) {
1184 if (vport->fc_flag & FC_RSCN_MODE) {
1185 lpfc_els_flush_rscn(vport);
1186 spin_lock_irq(shost->host_lock);
1187 vport->fc_flag |= FC_RSCN_MODE; /* RSCN still */
1188 spin_unlock_irq(shost->host_lock);
1191 lpfc_els_flush_rscn(vport);
1193 lpfc_disc_start(vport);
1195 lpfc_ct_free_iocb(phba, cmdiocb);
1200 lpfc_cmpl_ct_cmd_gft_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1201 struct lpfc_iocbq *rspiocb)
1203 struct lpfc_vport *vport = cmdiocb->vport;
1204 IOCB_t *irsp = &rspiocb->iocb;
1205 struct lpfc_dmabuf *inp = (struct lpfc_dmabuf *)cmdiocb->context1;
1206 struct lpfc_dmabuf *outp = (struct lpfc_dmabuf *)cmdiocb->context2;
1207 struct lpfc_sli_ct_request *CTrsp;
1209 struct lpfc_nodelist *ndlp;
1210 uint32_t fc4_data_0, fc4_data_1;
1212 did = ((struct lpfc_sli_ct_request *)inp->virt)->un.gft.PortId;
1213 did = be32_to_cpu(did);
1215 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
1216 "GFT_ID cmpl: status:x%x/x%x did:x%x",
1217 irsp->ulpStatus, irsp->un.ulpWord[4], did);
1219 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
1220 /* Good status, continue checking */
1221 CTrsp = (struct lpfc_sli_ct_request *)outp->virt;
1222 fc4_data_0 = be32_to_cpu(CTrsp->un.gft_acc.fc4_types[0]);
1223 fc4_data_1 = be32_to_cpu(CTrsp->un.gft_acc.fc4_types[1]);
1225 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1226 "6432 Process GFT_ID rsp for %08x "
1227 "Data %08x %08x %s %s\n",
1228 did, fc4_data_0, fc4_data_1,
1229 (fc4_data_0 & LPFC_FC4_TYPE_BITMASK) ?
1231 (fc4_data_1 & LPFC_FC4_TYPE_BITMASK) ?
1234 ndlp = lpfc_findnode_did(vport, did);
1236 /* The bitmask value for FCP and NVME FCP types is
1237 * the same because they are 32 bits distant from
1238 * each other in word0 and word0.
1240 if (fc4_data_0 & LPFC_FC4_TYPE_BITMASK)
1241 ndlp->nlp_fc4_type |= NLP_FC4_FCP;
1242 if (fc4_data_1 & LPFC_FC4_TYPE_BITMASK)
1243 ndlp->nlp_fc4_type |= NLP_FC4_NVME;
1244 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1245 "3064 Setting ndlp x%px, DID x%06x "
1246 "with FC4 x%08x, Data: x%08x x%08x "
1248 ndlp, did, ndlp->nlp_fc4_type,
1249 FC_TYPE_FCP, FC_TYPE_NVME,
1252 if (ndlp->nlp_state == NLP_STE_REG_LOGIN_ISSUE &&
1253 ndlp->nlp_fc4_type) {
1254 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1256 lpfc_nlp_set_state(vport, ndlp,
1257 NLP_STE_PRLI_ISSUE);
1258 lpfc_issue_els_prli(vport, ndlp, 0);
1259 } else if (!ndlp->nlp_fc4_type) {
1260 /* If fc4 type is still unknown, then LOGO */
1261 lpfc_printf_vlog(vport, KERN_INFO,
1263 "6443 Sending LOGO ndlp x%px,"
1264 "DID x%06x with fc4_type: "
1265 "x%08x, state: %d\n",
1266 ndlp, did, ndlp->nlp_fc4_type,
1268 lpfc_issue_els_logo(vport, ndlp, 0);
1269 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1270 lpfc_nlp_set_state(vport, ndlp,
1275 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
1276 "3065 GFT_ID failed x%08x\n", irsp->ulpStatus);
1278 lpfc_ct_free_iocb(phba, cmdiocb);
1282 lpfc_cmpl_ct(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1283 struct lpfc_iocbq *rspiocb)
1285 struct lpfc_vport *vport = cmdiocb->vport;
1286 struct lpfc_dmabuf *inp;
1287 struct lpfc_dmabuf *outp;
1289 struct lpfc_sli_ct_request *CTrsp;
1290 struct lpfc_nodelist *ndlp;
1295 /* First save ndlp, before we overwrite it */
1296 ndlp = cmdiocb->context_un.ndlp;
1298 /* we pass cmdiocb to state machine which needs rspiocb as well */
1299 cmdiocb->context_un.rsp_iocb = rspiocb;
1301 inp = (struct lpfc_dmabuf *) cmdiocb->context1;
1302 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
1303 irsp = &rspiocb->iocb;
1305 cmdcode = be16_to_cpu(((struct lpfc_sli_ct_request *) inp->virt)->
1306 CommandResponse.bits.CmdRsp);
1307 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
1309 latt = lpfc_els_chk_latt(vport);
1311 /* RFT request completes status <ulpStatus> CmdRsp <CmdRsp> */
1312 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1313 "0209 CT Request completes, latt %d, "
1314 "ulpStatus x%x CmdRsp x%x, Context x%x, Tag x%x\n",
1315 latt, irsp->ulpStatus,
1316 CTrsp->CommandResponse.bits.CmdRsp,
1317 cmdiocb->iocb.ulpContext, cmdiocb->iocb.ulpIoTag);
1319 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
1320 "CT cmd cmpl: status:x%x/x%x cmd:x%x",
1321 irsp->ulpStatus, irsp->un.ulpWord[4], cmdcode);
1323 if (irsp->ulpStatus) {
1324 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
1325 "0268 NS cmd x%x Error (x%x x%x)\n",
1326 cmdcode, irsp->ulpStatus, irsp->un.ulpWord[4]);
1328 if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
1329 (((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
1331 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
1332 IOERR_SLI_ABORTED)))
1335 retry = cmdiocb->retry;
1336 if (retry >= LPFC_MAX_NS_RETRY)
1340 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1341 "0250 Retrying NS cmd %x\n", cmdcode);
1342 rc = lpfc_ns_cmd(vport, cmdcode, retry, 0);
1348 cmdiocb->context_un.ndlp = ndlp; /* Now restore ndlp for free */
1349 lpfc_ct_free_iocb(phba, cmdiocb);
1354 lpfc_cmpl_ct_cmd_rft_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1355 struct lpfc_iocbq *rspiocb)
1357 IOCB_t *irsp = &rspiocb->iocb;
1358 struct lpfc_vport *vport = cmdiocb->vport;
1360 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
1361 struct lpfc_dmabuf *outp;
1362 struct lpfc_sli_ct_request *CTrsp;
1364 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
1365 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
1366 if (CTrsp->CommandResponse.bits.CmdRsp ==
1367 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
1368 vport->ct_flags |= FC_CT_RFT_ID;
1370 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
1375 lpfc_cmpl_ct_cmd_rnn_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1376 struct lpfc_iocbq *rspiocb)
1378 IOCB_t *irsp = &rspiocb->iocb;
1379 struct lpfc_vport *vport = cmdiocb->vport;
1381 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
1382 struct lpfc_dmabuf *outp;
1383 struct lpfc_sli_ct_request *CTrsp;
1385 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
1386 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
1387 if (CTrsp->CommandResponse.bits.CmdRsp ==
1388 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
1389 vport->ct_flags |= FC_CT_RNN_ID;
1391 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
1396 lpfc_cmpl_ct_cmd_rspn_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1397 struct lpfc_iocbq *rspiocb)
1399 IOCB_t *irsp = &rspiocb->iocb;
1400 struct lpfc_vport *vport = cmdiocb->vport;
1402 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
1403 struct lpfc_dmabuf *outp;
1404 struct lpfc_sli_ct_request *CTrsp;
1406 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
1407 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
1408 if (CTrsp->CommandResponse.bits.CmdRsp ==
1409 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
1410 vport->ct_flags |= FC_CT_RSPN_ID;
1412 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
1417 lpfc_cmpl_ct_cmd_rsnn_nn(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1418 struct lpfc_iocbq *rspiocb)
1420 IOCB_t *irsp = &rspiocb->iocb;
1421 struct lpfc_vport *vport = cmdiocb->vport;
1423 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
1424 struct lpfc_dmabuf *outp;
1425 struct lpfc_sli_ct_request *CTrsp;
1427 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
1428 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
1429 if (CTrsp->CommandResponse.bits.CmdRsp ==
1430 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
1431 vport->ct_flags |= FC_CT_RSNN_NN;
1433 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
1438 lpfc_cmpl_ct_cmd_da_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1439 struct lpfc_iocbq *rspiocb)
1441 struct lpfc_vport *vport = cmdiocb->vport;
1443 /* even if it fails we will act as though it succeeded. */
1444 vport->ct_flags = 0;
1445 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
1450 lpfc_cmpl_ct_cmd_rff_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1451 struct lpfc_iocbq *rspiocb)
1453 IOCB_t *irsp = &rspiocb->iocb;
1454 struct lpfc_vport *vport = cmdiocb->vport;
1456 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
1457 struct lpfc_dmabuf *outp;
1458 struct lpfc_sli_ct_request *CTrsp;
1460 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
1461 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
1462 if (CTrsp->CommandResponse.bits.CmdRsp ==
1463 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
1464 vport->ct_flags |= FC_CT_RFF_ID;
1466 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
1471 * Although the symbolic port name is thought to be an integer
1472 * as of January 18, 2016, leave it as a string until more of
1473 * the record state becomes defined.
1476 lpfc_vport_symbolic_port_name(struct lpfc_vport *vport, char *symbol,
1482 * Use the lpfc board number as the Symbolic Port
1483 * Name object. NPIV is not in play so this integer
1484 * value is sufficient and unique per FC-ID.
1486 n = scnprintf(symbol, size, "%d", vport->phba->brd_no);
1492 lpfc_vport_symbolic_node_name(struct lpfc_vport *vport, char *symbol,
1495 char fwrev[FW_REV_STR_SIZE] = {0};
1496 char tmp[MAXHOSTNAMELEN] = {0};
1498 memset(symbol, 0, size);
1500 scnprintf(tmp, sizeof(tmp), "Emulex %s", vport->phba->ModelName);
1501 if (strlcat(symbol, tmp, size) >= size)
1504 lpfc_decode_firmware_rev(vport->phba, fwrev, 0);
1505 scnprintf(tmp, sizeof(tmp), " FV%s", fwrev);
1506 if (strlcat(symbol, tmp, size) >= size)
1509 scnprintf(tmp, sizeof(tmp), " DV%s", lpfc_release_version);
1510 if (strlcat(symbol, tmp, size) >= size)
1513 scnprintf(tmp, sizeof(tmp), " HN:%s", vport->phba->os_host_name);
1514 if (strlcat(symbol, tmp, size) >= size)
1517 /* Note :- OS name is "Linux" */
1518 scnprintf(tmp, sizeof(tmp), " OS:%s", init_utsname()->sysname);
1519 strlcat(symbol, tmp, size);
1522 return strnlen(symbol, size);
1527 lpfc_find_map_node(struct lpfc_vport *vport)
1529 struct lpfc_nodelist *ndlp, *next_ndlp;
1530 struct Scsi_Host *shost;
1533 shost = lpfc_shost_from_vport(vport);
1534 spin_lock_irq(shost->host_lock);
1535 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
1536 if (ndlp->nlp_type & NLP_FABRIC)
1538 if ((ndlp->nlp_state == NLP_STE_MAPPED_NODE) ||
1539 (ndlp->nlp_state == NLP_STE_UNMAPPED_NODE))
1542 spin_unlock_irq(shost->host_lock);
1547 * This routine will return the FC4 Type associated with the CT
1551 lpfc_get_gidft_type(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb)
1553 struct lpfc_sli_ct_request *CtReq;
1554 struct lpfc_dmabuf *mp;
1557 mp = cmdiocb->context1;
1560 CtReq = (struct lpfc_sli_ct_request *)mp->virt;
1561 type = (uint32_t)CtReq->un.gid.Fc4Type;
1562 if ((type != SLI_CTPT_FCP) && (type != SLI_CTPT_NVME))
1570 * Issue Cmd to NameServer
1575 lpfc_ns_cmd(struct lpfc_vport *vport, int cmdcode,
1576 uint8_t retry, uint32_t context)
1578 struct lpfc_nodelist * ndlp;
1579 struct lpfc_hba *phba = vport->phba;
1580 struct lpfc_dmabuf *mp, *bmp;
1581 struct lpfc_sli_ct_request *CtReq;
1582 struct ulp_bde64 *bpl;
1583 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
1584 struct lpfc_iocbq *) = NULL;
1586 uint32_t rsp_size = 1024;
1590 ndlp = lpfc_findnode_did(vport, NameServer_DID);
1591 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)
1592 || ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) {
1597 /* fill in BDEs for command */
1598 /* Allocate buffer for command payload */
1599 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
1605 INIT_LIST_HEAD(&mp->list);
1606 mp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(mp->phys));
1609 goto ns_cmd_free_mp;
1612 /* Allocate buffer for Buffer ptr list */
1613 bmp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
1616 goto ns_cmd_free_mpvirt;
1619 INIT_LIST_HEAD(&bmp->list);
1620 bmp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(bmp->phys));
1623 goto ns_cmd_free_bmp;
1626 /* NameServer Req */
1627 lpfc_printf_vlog(vport, KERN_INFO ,LOG_DISCOVERY,
1628 "0236 NameServer Req Data: x%x x%x x%x x%x\n",
1629 cmdcode, vport->fc_flag, vport->fc_rscn_id_cnt,
1632 bpl = (struct ulp_bde64 *) bmp->virt;
1633 memset(bpl, 0, sizeof(struct ulp_bde64));
1634 bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys) );
1635 bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys) );
1636 bpl->tus.f.bdeFlags = 0;
1637 if (cmdcode == SLI_CTNS_GID_FT)
1638 bpl->tus.f.bdeSize = GID_REQUEST_SZ;
1639 else if (cmdcode == SLI_CTNS_GID_PT)
1640 bpl->tus.f.bdeSize = GID_REQUEST_SZ;
1641 else if (cmdcode == SLI_CTNS_GFF_ID)
1642 bpl->tus.f.bdeSize = GFF_REQUEST_SZ;
1643 else if (cmdcode == SLI_CTNS_GFT_ID)
1644 bpl->tus.f.bdeSize = GFT_REQUEST_SZ;
1645 else if (cmdcode == SLI_CTNS_RFT_ID)
1646 bpl->tus.f.bdeSize = RFT_REQUEST_SZ;
1647 else if (cmdcode == SLI_CTNS_RNN_ID)
1648 bpl->tus.f.bdeSize = RNN_REQUEST_SZ;
1649 else if (cmdcode == SLI_CTNS_RSPN_ID)
1650 bpl->tus.f.bdeSize = RSPN_REQUEST_SZ;
1651 else if (cmdcode == SLI_CTNS_RSNN_NN)
1652 bpl->tus.f.bdeSize = RSNN_REQUEST_SZ;
1653 else if (cmdcode == SLI_CTNS_DA_ID)
1654 bpl->tus.f.bdeSize = DA_ID_REQUEST_SZ;
1655 else if (cmdcode == SLI_CTNS_RFF_ID)
1656 bpl->tus.f.bdeSize = RFF_REQUEST_SZ;
1658 bpl->tus.f.bdeSize = 0;
1659 bpl->tus.w = le32_to_cpu(bpl->tus.w);
1661 CtReq = (struct lpfc_sli_ct_request *) mp->virt;
1662 memset(CtReq, 0, sizeof(struct lpfc_sli_ct_request));
1663 CtReq->RevisionId.bits.Revision = SLI_CT_REVISION;
1664 CtReq->RevisionId.bits.InId = 0;
1665 CtReq->FsType = SLI_CT_DIRECTORY_SERVICE;
1666 CtReq->FsSubType = SLI_CT_DIRECTORY_NAME_SERVER;
1667 CtReq->CommandResponse.bits.Size = 0;
1669 case SLI_CTNS_GID_FT:
1670 CtReq->CommandResponse.bits.CmdRsp =
1671 cpu_to_be16(SLI_CTNS_GID_FT);
1672 CtReq->un.gid.Fc4Type = context;
1674 if (vport->port_state < LPFC_NS_QRY)
1675 vport->port_state = LPFC_NS_QRY;
1676 lpfc_set_disctmo(vport);
1677 cmpl = lpfc_cmpl_ct_cmd_gid_ft;
1678 rsp_size = FC_MAX_NS_RSP;
1681 case SLI_CTNS_GID_PT:
1682 CtReq->CommandResponse.bits.CmdRsp =
1683 cpu_to_be16(SLI_CTNS_GID_PT);
1684 CtReq->un.gid.PortType = context;
1686 if (vport->port_state < LPFC_NS_QRY)
1687 vport->port_state = LPFC_NS_QRY;
1688 lpfc_set_disctmo(vport);
1689 cmpl = lpfc_cmpl_ct_cmd_gid_pt;
1690 rsp_size = FC_MAX_NS_RSP;
1693 case SLI_CTNS_GFF_ID:
1694 CtReq->CommandResponse.bits.CmdRsp =
1695 cpu_to_be16(SLI_CTNS_GFF_ID);
1696 CtReq->un.gff.PortId = cpu_to_be32(context);
1697 cmpl = lpfc_cmpl_ct_cmd_gff_id;
1700 case SLI_CTNS_GFT_ID:
1701 CtReq->CommandResponse.bits.CmdRsp =
1702 cpu_to_be16(SLI_CTNS_GFT_ID);
1703 CtReq->un.gft.PortId = cpu_to_be32(context);
1704 cmpl = lpfc_cmpl_ct_cmd_gft_id;
1707 case SLI_CTNS_RFT_ID:
1708 vport->ct_flags &= ~FC_CT_RFT_ID;
1709 CtReq->CommandResponse.bits.CmdRsp =
1710 cpu_to_be16(SLI_CTNS_RFT_ID);
1711 CtReq->un.rft.PortId = cpu_to_be32(vport->fc_myDID);
1713 /* Register FC4 FCP type if enabled. */
1714 if (vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH ||
1715 vport->cfg_enable_fc4_type == LPFC_ENABLE_FCP)
1716 CtReq->un.rft.fcpReg = 1;
1718 /* Register NVME type if enabled. Defined LE and swapped.
1719 * rsvd[0] is used as word1 because of the hard-coded
1720 * word0 usage in the ct_request data structure.
1722 if (vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH ||
1723 vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME)
1724 CtReq->un.rft.rsvd[0] =
1725 cpu_to_be32(LPFC_FC4_TYPE_BITMASK);
1727 ptr = (uint32_t *)CtReq;
1728 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1729 "6433 Issue RFT (%s %s): %08x %08x %08x %08x "
1730 "%08x %08x %08x %08x\n",
1731 CtReq->un.rft.fcpReg ? "FCP" : " ",
1732 CtReq->un.rft.rsvd[0] ? "NVME" : " ",
1733 *ptr, *(ptr + 1), *(ptr + 2), *(ptr + 3),
1734 *(ptr + 4), *(ptr + 5),
1735 *(ptr + 6), *(ptr + 7));
1736 cmpl = lpfc_cmpl_ct_cmd_rft_id;
1739 case SLI_CTNS_RNN_ID:
1740 vport->ct_flags &= ~FC_CT_RNN_ID;
1741 CtReq->CommandResponse.bits.CmdRsp =
1742 cpu_to_be16(SLI_CTNS_RNN_ID);
1743 CtReq->un.rnn.PortId = cpu_to_be32(vport->fc_myDID);
1744 memcpy(CtReq->un.rnn.wwnn, &vport->fc_nodename,
1745 sizeof(struct lpfc_name));
1746 cmpl = lpfc_cmpl_ct_cmd_rnn_id;
1749 case SLI_CTNS_RSPN_ID:
1750 vport->ct_flags &= ~FC_CT_RSPN_ID;
1751 CtReq->CommandResponse.bits.CmdRsp =
1752 cpu_to_be16(SLI_CTNS_RSPN_ID);
1753 CtReq->un.rspn.PortId = cpu_to_be32(vport->fc_myDID);
1754 size = sizeof(CtReq->un.rspn.symbname);
1755 CtReq->un.rspn.len =
1756 lpfc_vport_symbolic_port_name(vport,
1757 CtReq->un.rspn.symbname, size);
1758 cmpl = lpfc_cmpl_ct_cmd_rspn_id;
1760 case SLI_CTNS_RSNN_NN:
1761 vport->ct_flags &= ~FC_CT_RSNN_NN;
1762 CtReq->CommandResponse.bits.CmdRsp =
1763 cpu_to_be16(SLI_CTNS_RSNN_NN);
1764 memcpy(CtReq->un.rsnn.wwnn, &vport->fc_nodename,
1765 sizeof(struct lpfc_name));
1766 size = sizeof(CtReq->un.rsnn.symbname);
1767 CtReq->un.rsnn.len =
1768 lpfc_vport_symbolic_node_name(vport,
1769 CtReq->un.rsnn.symbname, size);
1770 cmpl = lpfc_cmpl_ct_cmd_rsnn_nn;
1772 case SLI_CTNS_DA_ID:
1773 /* Implement DA_ID Nameserver request */
1774 CtReq->CommandResponse.bits.CmdRsp =
1775 cpu_to_be16(SLI_CTNS_DA_ID);
1776 CtReq->un.da_id.port_id = cpu_to_be32(vport->fc_myDID);
1777 cmpl = lpfc_cmpl_ct_cmd_da_id;
1779 case SLI_CTNS_RFF_ID:
1780 vport->ct_flags &= ~FC_CT_RFF_ID;
1781 CtReq->CommandResponse.bits.CmdRsp =
1782 cpu_to_be16(SLI_CTNS_RFF_ID);
1783 CtReq->un.rff.PortId = cpu_to_be32(vport->fc_myDID);
1784 CtReq->un.rff.fbits = FC4_FEATURE_INIT;
1786 /* The driver always supports FC_TYPE_FCP. However, the
1787 * caller can specify NVME (type x28) as well. But only
1788 * these that FC4 type is supported.
1790 if (((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
1791 (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) &&
1792 (context == FC_TYPE_NVME)) {
1793 if ((vport == phba->pport) && phba->nvmet_support) {
1794 CtReq->un.rff.fbits = (FC4_FEATURE_TARGET |
1795 FC4_FEATURE_NVME_DISC);
1796 lpfc_nvmet_update_targetport(phba);
1798 lpfc_nvme_update_localport(vport);
1800 CtReq->un.rff.type_code = context;
1802 } else if (((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
1803 (vport->cfg_enable_fc4_type == LPFC_ENABLE_FCP)) &&
1804 (context == FC_TYPE_FCP))
1805 CtReq->un.rff.type_code = context;
1808 goto ns_cmd_free_bmpvirt;
1810 ptr = (uint32_t *)CtReq;
1811 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1812 "6434 Issue RFF (%s): %08x %08x %08x %08x "
1813 "%08x %08x %08x %08x\n",
1814 (context == FC_TYPE_NVME) ? "NVME" : "FCP",
1815 *ptr, *(ptr + 1), *(ptr + 2), *(ptr + 3),
1816 *(ptr + 4), *(ptr + 5),
1817 *(ptr + 6), *(ptr + 7));
1818 cmpl = lpfc_cmpl_ct_cmd_rff_id;
1821 /* The lpfc_ct_cmd/lpfc_get_req shall increment ndlp reference count
1822 * to hold ndlp reference for the corresponding callback function.
1824 if (!lpfc_ct_cmd(vport, mp, bmp, ndlp, cmpl, rsp_size, retry)) {
1825 /* On success, The cmpl function will free the buffers */
1826 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
1827 "Issue CT cmd: cmd:x%x did:x%x",
1828 cmdcode, ndlp->nlp_DID, 0);
1833 /* Decrement ndlp reference count to release ndlp reference held
1834 * for the failed command's callback function.
1838 ns_cmd_free_bmpvirt:
1839 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
1843 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1847 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
1848 "0266 Issue NameServer Req x%x err %d Data: x%x x%x\n",
1849 cmdcode, rc, vport->fc_flag, vport->fc_rscn_id_cnt);
1854 * lpfc_cmpl_ct_disc_fdmi - Handle a discovery FDMI completion
1855 * @phba: Pointer to HBA context object.
1856 * @cmdiocb: Pointer to the command IOCBQ.
1857 * @rspiocb: Pointer to the response IOCBQ.
1859 * This function to handle the completion of a driver initiated FDMI
1860 * CT command issued during discovery.
1863 lpfc_cmpl_ct_disc_fdmi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1864 struct lpfc_iocbq *rspiocb)
1866 struct lpfc_vport *vport = cmdiocb->vport;
1867 struct lpfc_dmabuf *inp = cmdiocb->context1;
1868 struct lpfc_dmabuf *outp = cmdiocb->context2;
1869 struct lpfc_sli_ct_request *CTcmd = inp->virt;
1870 struct lpfc_sli_ct_request *CTrsp = outp->virt;
1871 uint16_t fdmi_cmd = CTcmd->CommandResponse.bits.CmdRsp;
1872 uint16_t fdmi_rsp = CTrsp->CommandResponse.bits.CmdRsp;
1873 IOCB_t *irsp = &rspiocb->iocb;
1874 struct lpfc_nodelist *ndlp;
1875 uint32_t latt, cmd, err;
1877 latt = lpfc_els_chk_latt(vport);
1878 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
1879 "FDMI cmpl: status:x%x/x%x latt:%d",
1880 irsp->ulpStatus, irsp->un.ulpWord[4], latt);
1882 if (latt || irsp->ulpStatus) {
1884 /* Look for a retryable error */
1885 if (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) {
1886 switch ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK)) {
1887 case IOERR_SLI_ABORTED:
1888 case IOERR_SLI_DOWN:
1889 /* Driver aborted this IO. No retry as error
1890 * is likely Offline->Online or some adapter
1891 * error. Recovery will try again.
1894 case IOERR_ABORT_IN_PROGRESS:
1895 case IOERR_SEQUENCE_TIMEOUT:
1896 case IOERR_ILLEGAL_FRAME:
1897 case IOERR_NO_RESOURCES:
1898 case IOERR_ILLEGAL_COMMAND:
1900 if (cmdiocb->retry >= LPFC_FDMI_MAX_RETRY)
1903 /* Retry the same FDMI command */
1904 err = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING,
1906 if (err == IOCB_ERROR)
1914 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1915 "0229 FDMI cmd %04x failed, latt = %d "
1916 "ulpStatus: x%x, rid x%x\n",
1917 be16_to_cpu(fdmi_cmd), latt, irsp->ulpStatus,
1918 irsp->un.ulpWord[4]);
1920 lpfc_ct_free_iocb(phba, cmdiocb);
1922 ndlp = lpfc_findnode_did(vport, FDMI_DID);
1923 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
1926 /* Check for a CT LS_RJT response */
1927 cmd = be16_to_cpu(fdmi_cmd);
1928 if (fdmi_rsp == cpu_to_be16(SLI_CT_RESPONSE_FS_RJT)) {
1929 /* FDMI rsp failed */
1930 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1931 "0220 FDMI cmd failed FS_RJT Data: x%x", cmd);
1933 /* Should we fallback to FDMI-2 / FDMI-1 ? */
1936 if (vport->fdmi_hba_mask == LPFC_FDMI2_HBA_ATTR) {
1937 /* Fallback to FDMI-1 */
1938 vport->fdmi_hba_mask = LPFC_FDMI1_HBA_ATTR;
1939 vport->fdmi_port_mask = LPFC_FDMI1_PORT_ATTR;
1941 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA, 0);
1946 if (vport->fdmi_port_mask == LPFC_FDMI2_PORT_ATTR) {
1947 /* Fallback to FDMI-1 */
1948 vport->fdmi_port_mask = LPFC_FDMI1_PORT_ATTR;
1950 lpfc_fdmi_cmd(vport, ndlp, cmd, 0);
1952 if (vport->fdmi_port_mask == LPFC_FDMI2_SMART_ATTR) {
1953 vport->fdmi_port_mask = LPFC_FDMI2_PORT_ATTR;
1954 /* Retry the same command */
1955 lpfc_fdmi_cmd(vport, ndlp, cmd, 0);
1960 if (vport->fdmi_port_mask == LPFC_FDMI2_PORT_ATTR) {
1961 /* Fallback to FDMI-1 */
1962 vport->fdmi_hba_mask = LPFC_FDMI1_HBA_ATTR;
1963 vport->fdmi_port_mask = LPFC_FDMI1_PORT_ATTR;
1965 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA, 0);
1967 if (vport->fdmi_port_mask == LPFC_FDMI2_SMART_ATTR) {
1968 vport->fdmi_port_mask = LPFC_FDMI2_PORT_ATTR;
1969 /* Retry the same command */
1970 lpfc_fdmi_cmd(vport, ndlp, cmd, 0);
1977 * On success, need to cycle thru FDMI registration for discovery
1978 * DHBA -> DPRT -> RHBA -> RPA (physical port)
1979 * DPRT -> RPRT (vports)
1983 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RPA, 0);
1987 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DPRT, 0);
1991 if (vport->port_type == LPFC_PHYSICAL_PORT)
1992 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RHBA, 0);
1994 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RPRT, 0);
2002 * lpfc_fdmi_change_check - Check for changed FDMI parameters
2003 * @vport: pointer to a host virtual N_Port data structure.
2005 * Check how many mapped NPorts we are connected to
2006 * Check if our hostname changed
2007 * Called from hbeat timeout routine to check if any FDMI parameters
2008 * changed. If so, re-register those Attributes.
2011 lpfc_fdmi_change_check(struct lpfc_vport *vport)
2013 struct lpfc_hba *phba = vport->phba;
2014 struct lpfc_nodelist *ndlp;
2017 if (!lpfc_is_link_up(phba))
2020 /* Must be connected to a Fabric */
2021 if (!(vport->fc_flag & FC_FABRIC))
2024 ndlp = lpfc_findnode_did(vport, FDMI_DID);
2025 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
2028 /* Check if system hostname changed */
2029 if (strcmp(phba->os_host_name, init_utsname()->nodename)) {
2030 memset(phba->os_host_name, 0, sizeof(phba->os_host_name));
2031 scnprintf(phba->os_host_name, sizeof(phba->os_host_name), "%s",
2032 init_utsname()->nodename);
2033 lpfc_ns_cmd(vport, SLI_CTNS_RSNN_NN, 0, 0);
2035 /* Since this effects multiple HBA and PORT attributes, we need
2036 * de-register and go thru the whole FDMI registration cycle.
2037 * DHBA -> DPRT -> RHBA -> RPA (physical port)
2038 * DPRT -> RPRT (vports)
2040 if (vport->port_type == LPFC_PHYSICAL_PORT)
2041 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA, 0);
2043 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DPRT, 0);
2045 /* Since this code path registers all the port attributes
2046 * we can just return without further checking.
2051 if (!(vport->fdmi_port_mask & LPFC_FDMI_PORT_ATTR_num_disc))
2054 /* Check if the number of mapped NPorts changed */
2055 cnt = lpfc_find_map_node(vport);
2056 if (cnt == vport->fdmi_num_disc)
2059 if (vport->port_type == LPFC_PHYSICAL_PORT) {
2060 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RPA,
2061 LPFC_FDMI_PORT_ATTR_num_disc);
2063 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RPRT,
2064 LPFC_FDMI_PORT_ATTR_num_disc);
2068 /* Routines for all individual HBA attributes */
2070 lpfc_fdmi_hba_attr_wwnn(struct lpfc_vport *vport, struct lpfc_fdmi_attr_def *ad)
2072 struct lpfc_fdmi_attr_entry *ae;
2075 ae = &ad->AttrValue;
2076 memset(ae, 0, sizeof(*ae));
2078 memcpy(&ae->un.AttrWWN, &vport->fc_sparam.nodeName,
2079 sizeof(struct lpfc_name));
2080 size = FOURBYTES + sizeof(struct lpfc_name);
2081 ad->AttrLen = cpu_to_be16(size);
2082 ad->AttrType = cpu_to_be16(RHBA_NODENAME);
2086 lpfc_fdmi_hba_attr_manufacturer(struct lpfc_vport *vport,
2087 struct lpfc_fdmi_attr_def *ad)
2089 struct lpfc_fdmi_attr_entry *ae;
2092 ae = &ad->AttrValue;
2093 memset(ae, 0, sizeof(*ae));
2095 /* This string MUST be consistent with other FC platforms
2096 * supported by Broadcom.
2098 strncpy(ae->un.AttrString,
2099 "Emulex Corporation",
2100 sizeof(ae->un.AttrString));
2101 len = strnlen(ae->un.AttrString,
2102 sizeof(ae->un.AttrString));
2103 len += (len & 3) ? (4 - (len & 3)) : 4;
2104 size = FOURBYTES + len;
2105 ad->AttrLen = cpu_to_be16(size);
2106 ad->AttrType = cpu_to_be16(RHBA_MANUFACTURER);
2111 lpfc_fdmi_hba_attr_sn(struct lpfc_vport *vport, struct lpfc_fdmi_attr_def *ad)
2113 struct lpfc_hba *phba = vport->phba;
2114 struct lpfc_fdmi_attr_entry *ae;
2117 ae = &ad->AttrValue;
2118 memset(ae, 0, sizeof(*ae));
2120 strncpy(ae->un.AttrString, phba->SerialNumber,
2121 sizeof(ae->un.AttrString));
2122 len = strnlen(ae->un.AttrString,
2123 sizeof(ae->un.AttrString));
2124 len += (len & 3) ? (4 - (len & 3)) : 4;
2125 size = FOURBYTES + len;
2126 ad->AttrLen = cpu_to_be16(size);
2127 ad->AttrType = cpu_to_be16(RHBA_SERIAL_NUMBER);
2132 lpfc_fdmi_hba_attr_model(struct lpfc_vport *vport,
2133 struct lpfc_fdmi_attr_def *ad)
2135 struct lpfc_hba *phba = vport->phba;
2136 struct lpfc_fdmi_attr_entry *ae;
2139 ae = &ad->AttrValue;
2140 memset(ae, 0, sizeof(*ae));
2142 strncpy(ae->un.AttrString, phba->ModelName,
2143 sizeof(ae->un.AttrString));
2144 len = strnlen(ae->un.AttrString, sizeof(ae->un.AttrString));
2145 len += (len & 3) ? (4 - (len & 3)) : 4;
2146 size = FOURBYTES + len;
2147 ad->AttrLen = cpu_to_be16(size);
2148 ad->AttrType = cpu_to_be16(RHBA_MODEL);
2153 lpfc_fdmi_hba_attr_description(struct lpfc_vport *vport,
2154 struct lpfc_fdmi_attr_def *ad)
2156 struct lpfc_hba *phba = vport->phba;
2157 struct lpfc_fdmi_attr_entry *ae;
2160 ae = &ad->AttrValue;
2161 memset(ae, 0, sizeof(*ae));
2163 strncpy(ae->un.AttrString, phba->ModelDesc,
2164 sizeof(ae->un.AttrString));
2165 len = strnlen(ae->un.AttrString,
2166 sizeof(ae->un.AttrString));
2167 len += (len & 3) ? (4 - (len & 3)) : 4;
2168 size = FOURBYTES + len;
2169 ad->AttrLen = cpu_to_be16(size);
2170 ad->AttrType = cpu_to_be16(RHBA_MODEL_DESCRIPTION);
2175 lpfc_fdmi_hba_attr_hdw_ver(struct lpfc_vport *vport,
2176 struct lpfc_fdmi_attr_def *ad)
2178 struct lpfc_hba *phba = vport->phba;
2179 lpfc_vpd_t *vp = &phba->vpd;
2180 struct lpfc_fdmi_attr_entry *ae;
2181 uint32_t i, j, incr, size;
2183 ae = &ad->AttrValue;
2184 memset(ae, 0, sizeof(*ae));
2186 /* Convert JEDEC ID to ascii for hardware version */
2187 incr = vp->rev.biuRev;
2188 for (i = 0; i < 8; i++) {
2191 ae->un.AttrString[7 - i] =
2192 (char)((uint8_t) 0x30 +
2195 ae->un.AttrString[7 - i] =
2196 (char)((uint8_t) 0x61 +
2197 (uint8_t) (j - 10));
2200 size = FOURBYTES + 8;
2201 ad->AttrLen = cpu_to_be16(size);
2202 ad->AttrType = cpu_to_be16(RHBA_HARDWARE_VERSION);
2207 lpfc_fdmi_hba_attr_drvr_ver(struct lpfc_vport *vport,
2208 struct lpfc_fdmi_attr_def *ad)
2210 struct lpfc_fdmi_attr_entry *ae;
2213 ae = &ad->AttrValue;
2214 memset(ae, 0, sizeof(*ae));
2216 strncpy(ae->un.AttrString, lpfc_release_version,
2217 sizeof(ae->un.AttrString));
2218 len = strnlen(ae->un.AttrString,
2219 sizeof(ae->un.AttrString));
2220 len += (len & 3) ? (4 - (len & 3)) : 4;
2221 size = FOURBYTES + len;
2222 ad->AttrLen = cpu_to_be16(size);
2223 ad->AttrType = cpu_to_be16(RHBA_DRIVER_VERSION);
2228 lpfc_fdmi_hba_attr_rom_ver(struct lpfc_vport *vport,
2229 struct lpfc_fdmi_attr_def *ad)
2231 struct lpfc_hba *phba = vport->phba;
2232 struct lpfc_fdmi_attr_entry *ae;
2235 ae = &ad->AttrValue;
2236 memset(ae, 0, sizeof(*ae));
2238 if (phba->sli_rev == LPFC_SLI_REV4)
2239 lpfc_decode_firmware_rev(phba, ae->un.AttrString, 1);
2241 strncpy(ae->un.AttrString, phba->OptionROMVersion,
2242 sizeof(ae->un.AttrString));
2243 len = strnlen(ae->un.AttrString,
2244 sizeof(ae->un.AttrString));
2245 len += (len & 3) ? (4 - (len & 3)) : 4;
2246 size = FOURBYTES + len;
2247 ad->AttrLen = cpu_to_be16(size);
2248 ad->AttrType = cpu_to_be16(RHBA_OPTION_ROM_VERSION);
2253 lpfc_fdmi_hba_attr_fmw_ver(struct lpfc_vport *vport,
2254 struct lpfc_fdmi_attr_def *ad)
2256 struct lpfc_hba *phba = vport->phba;
2257 struct lpfc_fdmi_attr_entry *ae;
2260 ae = &ad->AttrValue;
2261 memset(ae, 0, sizeof(*ae));
2263 lpfc_decode_firmware_rev(phba, ae->un.AttrString, 1);
2264 len = strnlen(ae->un.AttrString,
2265 sizeof(ae->un.AttrString));
2266 len += (len & 3) ? (4 - (len & 3)) : 4;
2267 size = FOURBYTES + len;
2268 ad->AttrLen = cpu_to_be16(size);
2269 ad->AttrType = cpu_to_be16(RHBA_FIRMWARE_VERSION);
2274 lpfc_fdmi_hba_attr_os_ver(struct lpfc_vport *vport,
2275 struct lpfc_fdmi_attr_def *ad)
2277 struct lpfc_fdmi_attr_entry *ae;
2280 ae = &ad->AttrValue;
2281 memset(ae, 0, sizeof(*ae));
2283 snprintf(ae->un.AttrString, sizeof(ae->un.AttrString), "%s %s %s",
2284 init_utsname()->sysname,
2285 init_utsname()->release,
2286 init_utsname()->version);
2288 len = strnlen(ae->un.AttrString, sizeof(ae->un.AttrString));
2289 len += (len & 3) ? (4 - (len & 3)) : 4;
2290 size = FOURBYTES + len;
2291 ad->AttrLen = cpu_to_be16(size);
2292 ad->AttrType = cpu_to_be16(RHBA_OS_NAME_VERSION);
2297 lpfc_fdmi_hba_attr_ct_len(struct lpfc_vport *vport,
2298 struct lpfc_fdmi_attr_def *ad)
2300 struct lpfc_fdmi_attr_entry *ae;
2303 ae = &ad->AttrValue;
2305 ae->un.AttrInt = cpu_to_be32(LPFC_MAX_CT_SIZE);
2306 size = FOURBYTES + sizeof(uint32_t);
2307 ad->AttrLen = cpu_to_be16(size);
2308 ad->AttrType = cpu_to_be16(RHBA_MAX_CT_PAYLOAD_LEN);
2313 lpfc_fdmi_hba_attr_symbolic_name(struct lpfc_vport *vport,
2314 struct lpfc_fdmi_attr_def *ad)
2316 struct lpfc_fdmi_attr_entry *ae;
2319 ae = &ad->AttrValue;
2320 memset(ae, 0, sizeof(*ae));
2322 len = lpfc_vport_symbolic_node_name(vport,
2323 ae->un.AttrString, 256);
2324 len += (len & 3) ? (4 - (len & 3)) : 4;
2325 size = FOURBYTES + len;
2326 ad->AttrLen = cpu_to_be16(size);
2327 ad->AttrType = cpu_to_be16(RHBA_SYM_NODENAME);
2332 lpfc_fdmi_hba_attr_vendor_info(struct lpfc_vport *vport,
2333 struct lpfc_fdmi_attr_def *ad)
2335 struct lpfc_fdmi_attr_entry *ae;
2338 ae = &ad->AttrValue;
2340 /* Nothing is defined for this currently */
2341 ae->un.AttrInt = cpu_to_be32(0);
2342 size = FOURBYTES + sizeof(uint32_t);
2343 ad->AttrLen = cpu_to_be16(size);
2344 ad->AttrType = cpu_to_be16(RHBA_VENDOR_INFO);
2349 lpfc_fdmi_hba_attr_num_ports(struct lpfc_vport *vport,
2350 struct lpfc_fdmi_attr_def *ad)
2352 struct lpfc_fdmi_attr_entry *ae;
2355 ae = &ad->AttrValue;
2357 /* Each driver instance corresponds to a single port */
2358 ae->un.AttrInt = cpu_to_be32(1);
2359 size = FOURBYTES + sizeof(uint32_t);
2360 ad->AttrLen = cpu_to_be16(size);
2361 ad->AttrType = cpu_to_be16(RHBA_NUM_PORTS);
2366 lpfc_fdmi_hba_attr_fabric_wwnn(struct lpfc_vport *vport,
2367 struct lpfc_fdmi_attr_def *ad)
2369 struct lpfc_fdmi_attr_entry *ae;
2372 ae = &ad->AttrValue;
2373 memset(ae, 0, sizeof(*ae));
2375 memcpy(&ae->un.AttrWWN, &vport->fabric_nodename,
2376 sizeof(struct lpfc_name));
2377 size = FOURBYTES + sizeof(struct lpfc_name);
2378 ad->AttrLen = cpu_to_be16(size);
2379 ad->AttrType = cpu_to_be16(RHBA_FABRIC_WWNN);
2384 lpfc_fdmi_hba_attr_bios_ver(struct lpfc_vport *vport,
2385 struct lpfc_fdmi_attr_def *ad)
2387 struct lpfc_hba *phba = vport->phba;
2388 struct lpfc_fdmi_attr_entry *ae;
2391 ae = &ad->AttrValue;
2392 memset(ae, 0, sizeof(*ae));
2394 strlcat(ae->un.AttrString, phba->BIOSVersion,
2395 sizeof(ae->un.AttrString));
2396 len = strnlen(ae->un.AttrString,
2397 sizeof(ae->un.AttrString));
2398 len += (len & 3) ? (4 - (len & 3)) : 4;
2399 size = FOURBYTES + len;
2400 ad->AttrLen = cpu_to_be16(size);
2401 ad->AttrType = cpu_to_be16(RHBA_BIOS_VERSION);
2406 lpfc_fdmi_hba_attr_bios_state(struct lpfc_vport *vport,
2407 struct lpfc_fdmi_attr_def *ad)
2409 struct lpfc_fdmi_attr_entry *ae;
2412 ae = &ad->AttrValue;
2414 /* Driver doesn't have access to this information */
2415 ae->un.AttrInt = cpu_to_be32(0);
2416 size = FOURBYTES + sizeof(uint32_t);
2417 ad->AttrLen = cpu_to_be16(size);
2418 ad->AttrType = cpu_to_be16(RHBA_BIOS_STATE);
2423 lpfc_fdmi_hba_attr_vendor_id(struct lpfc_vport *vport,
2424 struct lpfc_fdmi_attr_def *ad)
2426 struct lpfc_fdmi_attr_entry *ae;
2429 ae = &ad->AttrValue;
2430 memset(ae, 0, sizeof(*ae));
2432 strncpy(ae->un.AttrString, "EMULEX",
2433 sizeof(ae->un.AttrString));
2434 len = strnlen(ae->un.AttrString,
2435 sizeof(ae->un.AttrString));
2436 len += (len & 3) ? (4 - (len & 3)) : 4;
2437 size = FOURBYTES + len;
2438 ad->AttrLen = cpu_to_be16(size);
2439 ad->AttrType = cpu_to_be16(RHBA_VENDOR_ID);
2443 /* Routines for all individual PORT attributes */
2445 lpfc_fdmi_port_attr_fc4type(struct lpfc_vport *vport,
2446 struct lpfc_fdmi_attr_def *ad)
2448 struct lpfc_hba *phba = vport->phba;
2449 struct lpfc_fdmi_attr_entry *ae;
2452 ae = &ad->AttrValue;
2453 memset(ae, 0, sizeof(*ae));
2455 ae->un.AttrTypes[2] = 0x01; /* Type 0x8 - FCP */
2456 ae->un.AttrTypes[7] = 0x01; /* Type 0x20 - CT */
2458 /* Check to see if Firmware supports NVME and on physical port */
2459 if ((phba->sli_rev == LPFC_SLI_REV4) && (vport == phba->pport) &&
2460 phba->sli4_hba.pc_sli4_params.nvme)
2461 ae->un.AttrTypes[6] = 0x01; /* Type 0x28 - NVME */
2463 size = FOURBYTES + 32;
2464 ad->AttrLen = cpu_to_be16(size);
2465 ad->AttrType = cpu_to_be16(RPRT_SUPPORTED_FC4_TYPES);
2470 lpfc_fdmi_port_attr_support_speed(struct lpfc_vport *vport,
2471 struct lpfc_fdmi_attr_def *ad)
2473 struct lpfc_hba *phba = vport->phba;
2474 struct lpfc_fdmi_attr_entry *ae;
2477 ae = &ad->AttrValue;
2480 if (!(phba->hba_flag & HBA_FCOE_MODE)) {
2481 if (phba->lmt & LMT_128Gb)
2482 ae->un.AttrInt |= HBA_PORTSPEED_128GFC;
2483 if (phba->lmt & LMT_64Gb)
2484 ae->un.AttrInt |= HBA_PORTSPEED_64GFC;
2485 if (phba->lmt & LMT_32Gb)
2486 ae->un.AttrInt |= HBA_PORTSPEED_32GFC;
2487 if (phba->lmt & LMT_16Gb)
2488 ae->un.AttrInt |= HBA_PORTSPEED_16GFC;
2489 if (phba->lmt & LMT_10Gb)
2490 ae->un.AttrInt |= HBA_PORTSPEED_10GFC;
2491 if (phba->lmt & LMT_8Gb)
2492 ae->un.AttrInt |= HBA_PORTSPEED_8GFC;
2493 if (phba->lmt & LMT_4Gb)
2494 ae->un.AttrInt |= HBA_PORTSPEED_4GFC;
2495 if (phba->lmt & LMT_2Gb)
2496 ae->un.AttrInt |= HBA_PORTSPEED_2GFC;
2497 if (phba->lmt & LMT_1Gb)
2498 ae->un.AttrInt |= HBA_PORTSPEED_1GFC;
2500 /* FCoE links support only one speed */
2501 switch (phba->fc_linkspeed) {
2502 case LPFC_ASYNC_LINK_SPEED_10GBPS:
2503 ae->un.AttrInt = HBA_PORTSPEED_10GE;
2505 case LPFC_ASYNC_LINK_SPEED_25GBPS:
2506 ae->un.AttrInt = HBA_PORTSPEED_25GE;
2508 case LPFC_ASYNC_LINK_SPEED_40GBPS:
2509 ae->un.AttrInt = HBA_PORTSPEED_40GE;
2511 case LPFC_ASYNC_LINK_SPEED_100GBPS:
2512 ae->un.AttrInt = HBA_PORTSPEED_100GE;
2516 ae->un.AttrInt = cpu_to_be32(ae->un.AttrInt);
2517 size = FOURBYTES + sizeof(uint32_t);
2518 ad->AttrLen = cpu_to_be16(size);
2519 ad->AttrType = cpu_to_be16(RPRT_SUPPORTED_SPEED);
2524 lpfc_fdmi_port_attr_speed(struct lpfc_vport *vport,
2525 struct lpfc_fdmi_attr_def *ad)
2527 struct lpfc_hba *phba = vport->phba;
2528 struct lpfc_fdmi_attr_entry *ae;
2531 ae = &ad->AttrValue;
2533 if (!(phba->hba_flag & HBA_FCOE_MODE)) {
2534 switch (phba->fc_linkspeed) {
2535 case LPFC_LINK_SPEED_1GHZ:
2536 ae->un.AttrInt = HBA_PORTSPEED_1GFC;
2538 case LPFC_LINK_SPEED_2GHZ:
2539 ae->un.AttrInt = HBA_PORTSPEED_2GFC;
2541 case LPFC_LINK_SPEED_4GHZ:
2542 ae->un.AttrInt = HBA_PORTSPEED_4GFC;
2544 case LPFC_LINK_SPEED_8GHZ:
2545 ae->un.AttrInt = HBA_PORTSPEED_8GFC;
2547 case LPFC_LINK_SPEED_10GHZ:
2548 ae->un.AttrInt = HBA_PORTSPEED_10GFC;
2550 case LPFC_LINK_SPEED_16GHZ:
2551 ae->un.AttrInt = HBA_PORTSPEED_16GFC;
2553 case LPFC_LINK_SPEED_32GHZ:
2554 ae->un.AttrInt = HBA_PORTSPEED_32GFC;
2556 case LPFC_LINK_SPEED_64GHZ:
2557 ae->un.AttrInt = HBA_PORTSPEED_64GFC;
2559 case LPFC_LINK_SPEED_128GHZ:
2560 ae->un.AttrInt = HBA_PORTSPEED_128GFC;
2563 ae->un.AttrInt = HBA_PORTSPEED_UNKNOWN;
2567 switch (phba->fc_linkspeed) {
2568 case LPFC_ASYNC_LINK_SPEED_10GBPS:
2569 ae->un.AttrInt = HBA_PORTSPEED_10GE;
2571 case LPFC_ASYNC_LINK_SPEED_25GBPS:
2572 ae->un.AttrInt = HBA_PORTSPEED_25GE;
2574 case LPFC_ASYNC_LINK_SPEED_40GBPS:
2575 ae->un.AttrInt = HBA_PORTSPEED_40GE;
2577 case LPFC_ASYNC_LINK_SPEED_100GBPS:
2578 ae->un.AttrInt = HBA_PORTSPEED_100GE;
2581 ae->un.AttrInt = HBA_PORTSPEED_UNKNOWN;
2586 ae->un.AttrInt = cpu_to_be32(ae->un.AttrInt);
2587 size = FOURBYTES + sizeof(uint32_t);
2588 ad->AttrLen = cpu_to_be16(size);
2589 ad->AttrType = cpu_to_be16(RPRT_PORT_SPEED);
2594 lpfc_fdmi_port_attr_max_frame(struct lpfc_vport *vport,
2595 struct lpfc_fdmi_attr_def *ad)
2597 struct serv_parm *hsp;
2598 struct lpfc_fdmi_attr_entry *ae;
2601 ae = &ad->AttrValue;
2603 hsp = (struct serv_parm *)&vport->fc_sparam;
2604 ae->un.AttrInt = (((uint32_t) hsp->cmn.bbRcvSizeMsb & 0x0F) << 8) |
2605 (uint32_t) hsp->cmn.bbRcvSizeLsb;
2606 ae->un.AttrInt = cpu_to_be32(ae->un.AttrInt);
2607 size = FOURBYTES + sizeof(uint32_t);
2608 ad->AttrLen = cpu_to_be16(size);
2609 ad->AttrType = cpu_to_be16(RPRT_MAX_FRAME_SIZE);
2614 lpfc_fdmi_port_attr_os_devname(struct lpfc_vport *vport,
2615 struct lpfc_fdmi_attr_def *ad)
2617 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2618 struct lpfc_fdmi_attr_entry *ae;
2621 ae = &ad->AttrValue;
2622 memset(ae, 0, sizeof(*ae));
2624 snprintf(ae->un.AttrString, sizeof(ae->un.AttrString),
2625 "/sys/class/scsi_host/host%d", shost->host_no);
2626 len = strnlen((char *)ae->un.AttrString,
2627 sizeof(ae->un.AttrString));
2628 len += (len & 3) ? (4 - (len & 3)) : 4;
2629 size = FOURBYTES + len;
2630 ad->AttrLen = cpu_to_be16(size);
2631 ad->AttrType = cpu_to_be16(RPRT_OS_DEVICE_NAME);
2636 lpfc_fdmi_port_attr_host_name(struct lpfc_vport *vport,
2637 struct lpfc_fdmi_attr_def *ad)
2639 struct lpfc_fdmi_attr_entry *ae;
2642 ae = &ad->AttrValue;
2643 memset(ae, 0, sizeof(*ae));
2645 scnprintf(ae->un.AttrString, sizeof(ae->un.AttrString), "%s",
2646 vport->phba->os_host_name);
2648 len = strnlen(ae->un.AttrString, sizeof(ae->un.AttrString));
2649 len += (len & 3) ? (4 - (len & 3)) : 4;
2650 size = FOURBYTES + len;
2651 ad->AttrLen = cpu_to_be16(size);
2652 ad->AttrType = cpu_to_be16(RPRT_HOST_NAME);
2657 lpfc_fdmi_port_attr_wwnn(struct lpfc_vport *vport,
2658 struct lpfc_fdmi_attr_def *ad)
2660 struct lpfc_fdmi_attr_entry *ae;
2663 ae = &ad->AttrValue;
2664 memset(ae, 0, sizeof(*ae));
2666 memcpy(&ae->un.AttrWWN, &vport->fc_sparam.nodeName,
2667 sizeof(struct lpfc_name));
2668 size = FOURBYTES + sizeof(struct lpfc_name);
2669 ad->AttrLen = cpu_to_be16(size);
2670 ad->AttrType = cpu_to_be16(RPRT_NODENAME);
2675 lpfc_fdmi_port_attr_wwpn(struct lpfc_vport *vport,
2676 struct lpfc_fdmi_attr_def *ad)
2678 struct lpfc_fdmi_attr_entry *ae;
2681 ae = &ad->AttrValue;
2682 memset(ae, 0, sizeof(*ae));
2684 memcpy(&ae->un.AttrWWN, &vport->fc_sparam.portName,
2685 sizeof(struct lpfc_name));
2686 size = FOURBYTES + sizeof(struct lpfc_name);
2687 ad->AttrLen = cpu_to_be16(size);
2688 ad->AttrType = cpu_to_be16(RPRT_PORTNAME);
2693 lpfc_fdmi_port_attr_symbolic_name(struct lpfc_vport *vport,
2694 struct lpfc_fdmi_attr_def *ad)
2696 struct lpfc_fdmi_attr_entry *ae;
2699 ae = &ad->AttrValue;
2700 memset(ae, 0, sizeof(*ae));
2702 len = lpfc_vport_symbolic_port_name(vport, ae->un.AttrString, 256);
2703 len += (len & 3) ? (4 - (len & 3)) : 4;
2704 size = FOURBYTES + len;
2705 ad->AttrLen = cpu_to_be16(size);
2706 ad->AttrType = cpu_to_be16(RPRT_SYM_PORTNAME);
2711 lpfc_fdmi_port_attr_port_type(struct lpfc_vport *vport,
2712 struct lpfc_fdmi_attr_def *ad)
2714 struct lpfc_hba *phba = vport->phba;
2715 struct lpfc_fdmi_attr_entry *ae;
2718 ae = &ad->AttrValue;
2719 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP)
2720 ae->un.AttrInt = cpu_to_be32(LPFC_FDMI_PORTTYPE_NLPORT);
2722 ae->un.AttrInt = cpu_to_be32(LPFC_FDMI_PORTTYPE_NPORT);
2723 size = FOURBYTES + sizeof(uint32_t);
2724 ad->AttrLen = cpu_to_be16(size);
2725 ad->AttrType = cpu_to_be16(RPRT_PORT_TYPE);
2730 lpfc_fdmi_port_attr_class(struct lpfc_vport *vport,
2731 struct lpfc_fdmi_attr_def *ad)
2733 struct lpfc_fdmi_attr_entry *ae;
2736 ae = &ad->AttrValue;
2737 ae->un.AttrInt = cpu_to_be32(FC_COS_CLASS2 | FC_COS_CLASS3);
2738 size = FOURBYTES + sizeof(uint32_t);
2739 ad->AttrLen = cpu_to_be16(size);
2740 ad->AttrType = cpu_to_be16(RPRT_SUPPORTED_CLASS);
2745 lpfc_fdmi_port_attr_fabric_wwpn(struct lpfc_vport *vport,
2746 struct lpfc_fdmi_attr_def *ad)
2748 struct lpfc_fdmi_attr_entry *ae;
2751 ae = &ad->AttrValue;
2752 memset(ae, 0, sizeof(*ae));
2754 memcpy(&ae->un.AttrWWN, &vport->fabric_portname,
2755 sizeof(struct lpfc_name));
2756 size = FOURBYTES + sizeof(struct lpfc_name);
2757 ad->AttrLen = cpu_to_be16(size);
2758 ad->AttrType = cpu_to_be16(RPRT_FABRICNAME);
2763 lpfc_fdmi_port_attr_active_fc4type(struct lpfc_vport *vport,
2764 struct lpfc_fdmi_attr_def *ad)
2766 struct lpfc_fdmi_attr_entry *ae;
2769 ae = &ad->AttrValue;
2770 memset(ae, 0, sizeof(*ae));
2772 ae->un.AttrTypes[2] = 0x01; /* Type 0x8 - FCP */
2773 ae->un.AttrTypes[7] = 0x01; /* Type 0x20 - CT */
2775 /* Check to see if NVME is configured or not */
2776 if (vport->phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)
2777 ae->un.AttrTypes[6] = 0x1; /* Type 0x28 - NVME */
2779 size = FOURBYTES + 32;
2780 ad->AttrLen = cpu_to_be16(size);
2781 ad->AttrType = cpu_to_be16(RPRT_ACTIVE_FC4_TYPES);
2786 lpfc_fdmi_port_attr_port_state(struct lpfc_vport *vport,
2787 struct lpfc_fdmi_attr_def *ad)
2789 struct lpfc_fdmi_attr_entry *ae;
2792 ae = &ad->AttrValue;
2793 /* Link Up - operational */
2794 ae->un.AttrInt = cpu_to_be32(LPFC_FDMI_PORTSTATE_ONLINE);
2795 size = FOURBYTES + sizeof(uint32_t);
2796 ad->AttrLen = cpu_to_be16(size);
2797 ad->AttrType = cpu_to_be16(RPRT_PORT_STATE);
2802 lpfc_fdmi_port_attr_num_disc(struct lpfc_vport *vport,
2803 struct lpfc_fdmi_attr_def *ad)
2805 struct lpfc_fdmi_attr_entry *ae;
2808 ae = &ad->AttrValue;
2809 vport->fdmi_num_disc = lpfc_find_map_node(vport);
2810 ae->un.AttrInt = cpu_to_be32(vport->fdmi_num_disc);
2811 size = FOURBYTES + sizeof(uint32_t);
2812 ad->AttrLen = cpu_to_be16(size);
2813 ad->AttrType = cpu_to_be16(RPRT_DISC_PORT);
2818 lpfc_fdmi_port_attr_nportid(struct lpfc_vport *vport,
2819 struct lpfc_fdmi_attr_def *ad)
2821 struct lpfc_fdmi_attr_entry *ae;
2824 ae = &ad->AttrValue;
2825 ae->un.AttrInt = cpu_to_be32(vport->fc_myDID);
2826 size = FOURBYTES + sizeof(uint32_t);
2827 ad->AttrLen = cpu_to_be16(size);
2828 ad->AttrType = cpu_to_be16(RPRT_PORT_ID);
2833 lpfc_fdmi_smart_attr_service(struct lpfc_vport *vport,
2834 struct lpfc_fdmi_attr_def *ad)
2836 struct lpfc_fdmi_attr_entry *ae;
2839 ae = &ad->AttrValue;
2840 memset(ae, 0, sizeof(*ae));
2842 strncpy(ae->un.AttrString, "Smart SAN Initiator",
2843 sizeof(ae->un.AttrString));
2844 len = strnlen(ae->un.AttrString,
2845 sizeof(ae->un.AttrString));
2846 len += (len & 3) ? (4 - (len & 3)) : 4;
2847 size = FOURBYTES + len;
2848 ad->AttrLen = cpu_to_be16(size);
2849 ad->AttrType = cpu_to_be16(RPRT_SMART_SERVICE);
2854 lpfc_fdmi_smart_attr_guid(struct lpfc_vport *vport,
2855 struct lpfc_fdmi_attr_def *ad)
2857 struct lpfc_fdmi_attr_entry *ae;
2860 ae = &ad->AttrValue;
2861 memset(ae, 0, sizeof(*ae));
2863 memcpy(&ae->un.AttrString, &vport->fc_sparam.nodeName,
2864 sizeof(struct lpfc_name));
2865 memcpy((((uint8_t *)&ae->un.AttrString) +
2866 sizeof(struct lpfc_name)),
2867 &vport->fc_sparam.portName, sizeof(struct lpfc_name));
2868 size = FOURBYTES + (2 * sizeof(struct lpfc_name));
2869 ad->AttrLen = cpu_to_be16(size);
2870 ad->AttrType = cpu_to_be16(RPRT_SMART_GUID);
2875 lpfc_fdmi_smart_attr_version(struct lpfc_vport *vport,
2876 struct lpfc_fdmi_attr_def *ad)
2878 struct lpfc_fdmi_attr_entry *ae;
2881 ae = &ad->AttrValue;
2882 memset(ae, 0, sizeof(*ae));
2884 strncpy(ae->un.AttrString, "Smart SAN Version 2.0",
2885 sizeof(ae->un.AttrString));
2886 len = strnlen(ae->un.AttrString,
2887 sizeof(ae->un.AttrString));
2888 len += (len & 3) ? (4 - (len & 3)) : 4;
2889 size = FOURBYTES + len;
2890 ad->AttrLen = cpu_to_be16(size);
2891 ad->AttrType = cpu_to_be16(RPRT_SMART_VERSION);
2896 lpfc_fdmi_smart_attr_model(struct lpfc_vport *vport,
2897 struct lpfc_fdmi_attr_def *ad)
2899 struct lpfc_hba *phba = vport->phba;
2900 struct lpfc_fdmi_attr_entry *ae;
2903 ae = &ad->AttrValue;
2904 memset(ae, 0, sizeof(*ae));
2906 strncpy(ae->un.AttrString, phba->ModelName,
2907 sizeof(ae->un.AttrString));
2908 len = strnlen(ae->un.AttrString, sizeof(ae->un.AttrString));
2909 len += (len & 3) ? (4 - (len & 3)) : 4;
2910 size = FOURBYTES + len;
2911 ad->AttrLen = cpu_to_be16(size);
2912 ad->AttrType = cpu_to_be16(RPRT_SMART_MODEL);
2917 lpfc_fdmi_smart_attr_port_info(struct lpfc_vport *vport,
2918 struct lpfc_fdmi_attr_def *ad)
2920 struct lpfc_fdmi_attr_entry *ae;
2923 ae = &ad->AttrValue;
2925 /* SRIOV (type 3) is not supported */
2927 ae->un.AttrInt = cpu_to_be32(2); /* NPIV */
2929 ae->un.AttrInt = cpu_to_be32(1); /* Physical */
2930 size = FOURBYTES + sizeof(uint32_t);
2931 ad->AttrLen = cpu_to_be16(size);
2932 ad->AttrType = cpu_to_be16(RPRT_SMART_PORT_INFO);
2937 lpfc_fdmi_smart_attr_qos(struct lpfc_vport *vport,
2938 struct lpfc_fdmi_attr_def *ad)
2940 struct lpfc_fdmi_attr_entry *ae;
2943 ae = &ad->AttrValue;
2944 ae->un.AttrInt = cpu_to_be32(0);
2945 size = FOURBYTES + sizeof(uint32_t);
2946 ad->AttrLen = cpu_to_be16(size);
2947 ad->AttrType = cpu_to_be16(RPRT_SMART_QOS);
2952 lpfc_fdmi_smart_attr_security(struct lpfc_vport *vport,
2953 struct lpfc_fdmi_attr_def *ad)
2955 struct lpfc_fdmi_attr_entry *ae;
2958 ae = &ad->AttrValue;
2959 ae->un.AttrInt = cpu_to_be32(1);
2960 size = FOURBYTES + sizeof(uint32_t);
2961 ad->AttrLen = cpu_to_be16(size);
2962 ad->AttrType = cpu_to_be16(RPRT_SMART_SECURITY);
2966 /* RHBA attribute jump table */
2967 int (*lpfc_fdmi_hba_action[])
2968 (struct lpfc_vport *vport, struct lpfc_fdmi_attr_def *ad) = {
2969 /* Action routine Mask bit Attribute type */
2970 lpfc_fdmi_hba_attr_wwnn, /* bit0 RHBA_NODENAME */
2971 lpfc_fdmi_hba_attr_manufacturer, /* bit1 RHBA_MANUFACTURER */
2972 lpfc_fdmi_hba_attr_sn, /* bit2 RHBA_SERIAL_NUMBER */
2973 lpfc_fdmi_hba_attr_model, /* bit3 RHBA_MODEL */
2974 lpfc_fdmi_hba_attr_description, /* bit4 RHBA_MODEL_DESCRIPTION */
2975 lpfc_fdmi_hba_attr_hdw_ver, /* bit5 RHBA_HARDWARE_VERSION */
2976 lpfc_fdmi_hba_attr_drvr_ver, /* bit6 RHBA_DRIVER_VERSION */
2977 lpfc_fdmi_hba_attr_rom_ver, /* bit7 RHBA_OPTION_ROM_VERSION */
2978 lpfc_fdmi_hba_attr_fmw_ver, /* bit8 RHBA_FIRMWARE_VERSION */
2979 lpfc_fdmi_hba_attr_os_ver, /* bit9 RHBA_OS_NAME_VERSION */
2980 lpfc_fdmi_hba_attr_ct_len, /* bit10 RHBA_MAX_CT_PAYLOAD_LEN */
2981 lpfc_fdmi_hba_attr_symbolic_name, /* bit11 RHBA_SYM_NODENAME */
2982 lpfc_fdmi_hba_attr_vendor_info, /* bit12 RHBA_VENDOR_INFO */
2983 lpfc_fdmi_hba_attr_num_ports, /* bit13 RHBA_NUM_PORTS */
2984 lpfc_fdmi_hba_attr_fabric_wwnn, /* bit14 RHBA_FABRIC_WWNN */
2985 lpfc_fdmi_hba_attr_bios_ver, /* bit15 RHBA_BIOS_VERSION */
2986 lpfc_fdmi_hba_attr_bios_state, /* bit16 RHBA_BIOS_STATE */
2987 lpfc_fdmi_hba_attr_vendor_id, /* bit17 RHBA_VENDOR_ID */
2990 /* RPA / RPRT attribute jump table */
2991 int (*lpfc_fdmi_port_action[])
2992 (struct lpfc_vport *vport, struct lpfc_fdmi_attr_def *ad) = {
2993 /* Action routine Mask bit Attribute type */
2994 lpfc_fdmi_port_attr_fc4type, /* bit0 RPRT_SUPPORT_FC4_TYPES */
2995 lpfc_fdmi_port_attr_support_speed, /* bit1 RPRT_SUPPORTED_SPEED */
2996 lpfc_fdmi_port_attr_speed, /* bit2 RPRT_PORT_SPEED */
2997 lpfc_fdmi_port_attr_max_frame, /* bit3 RPRT_MAX_FRAME_SIZE */
2998 lpfc_fdmi_port_attr_os_devname, /* bit4 RPRT_OS_DEVICE_NAME */
2999 lpfc_fdmi_port_attr_host_name, /* bit5 RPRT_HOST_NAME */
3000 lpfc_fdmi_port_attr_wwnn, /* bit6 RPRT_NODENAME */
3001 lpfc_fdmi_port_attr_wwpn, /* bit7 RPRT_PORTNAME */
3002 lpfc_fdmi_port_attr_symbolic_name, /* bit8 RPRT_SYM_PORTNAME */
3003 lpfc_fdmi_port_attr_port_type, /* bit9 RPRT_PORT_TYPE */
3004 lpfc_fdmi_port_attr_class, /* bit10 RPRT_SUPPORTED_CLASS */
3005 lpfc_fdmi_port_attr_fabric_wwpn, /* bit11 RPRT_FABRICNAME */
3006 lpfc_fdmi_port_attr_active_fc4type, /* bit12 RPRT_ACTIVE_FC4_TYPES */
3007 lpfc_fdmi_port_attr_port_state, /* bit13 RPRT_PORT_STATE */
3008 lpfc_fdmi_port_attr_num_disc, /* bit14 RPRT_DISC_PORT */
3009 lpfc_fdmi_port_attr_nportid, /* bit15 RPRT_PORT_ID */
3010 lpfc_fdmi_smart_attr_service, /* bit16 RPRT_SMART_SERVICE */
3011 lpfc_fdmi_smart_attr_guid, /* bit17 RPRT_SMART_GUID */
3012 lpfc_fdmi_smart_attr_version, /* bit18 RPRT_SMART_VERSION */
3013 lpfc_fdmi_smart_attr_model, /* bit19 RPRT_SMART_MODEL */
3014 lpfc_fdmi_smart_attr_port_info, /* bit20 RPRT_SMART_PORT_INFO */
3015 lpfc_fdmi_smart_attr_qos, /* bit21 RPRT_SMART_QOS */
3016 lpfc_fdmi_smart_attr_security, /* bit22 RPRT_SMART_SECURITY */
3020 * lpfc_fdmi_cmd - Build and send a FDMI cmd to the specified NPort
3021 * @vport: pointer to a host virtual N_Port data structure.
3022 * @ndlp: ndlp to send FDMI cmd to (if NULL use FDMI_DID)
3023 * cmdcode: FDMI command to send
3024 * mask: Mask of HBA or PORT Attributes to send
3026 * Builds and sends a FDMI command using the CT subsystem.
3029 lpfc_fdmi_cmd(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
3030 int cmdcode, uint32_t new_mask)
3032 struct lpfc_hba *phba = vport->phba;
3033 struct lpfc_dmabuf *mp, *bmp;
3034 struct lpfc_sli_ct_request *CtReq;
3035 struct ulp_bde64 *bpl;
3040 struct lpfc_fdmi_reg_hba *rh;
3041 struct lpfc_fdmi_port_entry *pe;
3042 struct lpfc_fdmi_reg_portattr *pab = NULL;
3043 struct lpfc_fdmi_attr_block *ab = NULL;
3044 int (*func)(struct lpfc_vport *vport, struct lpfc_fdmi_attr_def *ad);
3045 void (*cmpl)(struct lpfc_hba *, struct lpfc_iocbq *,
3046 struct lpfc_iocbq *);
3048 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
3051 cmpl = lpfc_cmpl_ct_disc_fdmi; /* called from discovery */
3053 /* fill in BDEs for command */
3054 /* Allocate buffer for command payload */
3055 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
3059 mp->virt = lpfc_mbuf_alloc(phba, 0, &(mp->phys));
3061 goto fdmi_cmd_free_mp;
3063 /* Allocate buffer for Buffer ptr list */
3064 bmp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
3066 goto fdmi_cmd_free_mpvirt;
3068 bmp->virt = lpfc_mbuf_alloc(phba, 0, &(bmp->phys));
3070 goto fdmi_cmd_free_bmp;
3072 INIT_LIST_HEAD(&mp->list);
3073 INIT_LIST_HEAD(&bmp->list);
3076 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
3077 "0218 FDMI Request Data: x%x x%x x%x\n",
3078 vport->fc_flag, vport->port_state, cmdcode);
3079 CtReq = (struct lpfc_sli_ct_request *)mp->virt;
3081 /* First populate the CT_IU preamble */
3082 memset(CtReq, 0, sizeof(struct lpfc_sli_ct_request));
3083 CtReq->RevisionId.bits.Revision = SLI_CT_REVISION;
3084 CtReq->RevisionId.bits.InId = 0;
3086 CtReq->FsType = SLI_CT_MANAGEMENT_SERVICE;
3087 CtReq->FsSubType = SLI_CT_FDMI_Subtypes;
3089 CtReq->CommandResponse.bits.CmdRsp = cpu_to_be16(cmdcode);
3090 rsp_size = LPFC_BPL_SIZE;
3093 /* Next fill in the specific FDMI cmd information */
3097 rh = (struct lpfc_fdmi_reg_hba *)&CtReq->un.PortID;
3098 /* HBA Identifier */
3099 memcpy(&rh->hi.PortName, &phba->pport->fc_sparam.portName,
3100 sizeof(struct lpfc_name));
3102 if (cmdcode == SLI_MGMT_RHBA) {
3103 /* Registered Port List */
3104 /* One entry (port) per adapter */
3105 rh->rpl.EntryCnt = cpu_to_be32(1);
3106 memcpy(&rh->rpl.pe.PortName,
3107 &phba->pport->fc_sparam.portName,
3108 sizeof(struct lpfc_name));
3110 /* point to the HBA attribute block */
3111 size = 2 * sizeof(struct lpfc_name) +
3114 size = sizeof(struct lpfc_name);
3116 ab = (struct lpfc_fdmi_attr_block *)((uint8_t *)rh + size);
3123 mask = vport->fdmi_hba_mask;
3125 /* Mask will dictate what attributes to build in the request */
3128 func = lpfc_fdmi_hba_action[bit_pos];
3130 (struct lpfc_fdmi_attr_def *)
3131 ((uint8_t *)rh + size));
3134 (LPFC_BPL_SIZE - LPFC_CT_PREAMBLE))
3141 ab->EntryCnt = cpu_to_be32(ab->EntryCnt);
3143 size = GID_REQUEST_SZ - 4 + size;
3148 pab = (struct lpfc_fdmi_reg_portattr *)&CtReq->un.PortID;
3149 if (cmdcode == SLI_MGMT_RPRT) {
3150 rh = (struct lpfc_fdmi_reg_hba *)pab;
3151 /* HBA Identifier */
3152 memcpy(&rh->hi.PortName,
3153 &phba->pport->fc_sparam.portName,
3154 sizeof(struct lpfc_name));
3155 pab = (struct lpfc_fdmi_reg_portattr *)
3156 ((uint8_t *)pab + sizeof(struct lpfc_name));
3159 memcpy((uint8_t *)&pab->PortName,
3160 (uint8_t *)&vport->fc_sparam.portName,
3161 sizeof(struct lpfc_name));
3162 size += sizeof(struct lpfc_name) + FOURBYTES;
3163 pab->ab.EntryCnt = 0;
3168 mask = vport->fdmi_port_mask;
3170 /* Mask will dictate what attributes to build in the request */
3173 func = lpfc_fdmi_port_action[bit_pos];
3175 (struct lpfc_fdmi_attr_def *)
3176 ((uint8_t *)pab + size));
3179 (LPFC_BPL_SIZE - LPFC_CT_PREAMBLE))
3186 pab->ab.EntryCnt = cpu_to_be32(pab->ab.EntryCnt);
3188 if (cmdcode == SLI_MGMT_RPRT)
3189 size += sizeof(struct lpfc_name);
3190 size = GID_REQUEST_SZ - 4 + size;
3195 rsp_size = FC_MAX_NS_RSP;
3199 pe = (struct lpfc_fdmi_port_entry *)&CtReq->un.PortID;
3200 memcpy((uint8_t *)&pe->PortName,
3201 (uint8_t *)&vport->fc_sparam.portName,
3202 sizeof(struct lpfc_name));
3203 size = GID_REQUEST_SZ - 4 + sizeof(struct lpfc_name);
3208 rsp_size = FC_MAX_NS_RSP;
3212 pe = (struct lpfc_fdmi_port_entry *)&CtReq->un.PortID;
3213 memcpy((uint8_t *)&pe->PortName,
3214 (uint8_t *)&vport->fc_sparam.portName,
3215 sizeof(struct lpfc_name));
3216 size = GID_REQUEST_SZ - 4 + sizeof(struct lpfc_name);
3219 size = GID_REQUEST_SZ - 4;
3222 lpfc_printf_vlog(vport, KERN_WARNING, LOG_DISCOVERY,
3223 "0298 FDMI cmdcode x%x not supported\n",
3225 goto fdmi_cmd_free_bmpvirt;
3227 CtReq->CommandResponse.bits.Size = cpu_to_be16(rsp_size);
3229 bpl = (struct ulp_bde64 *)bmp->virt;
3230 bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys));
3231 bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys));
3232 bpl->tus.f.bdeFlags = 0;
3233 bpl->tus.f.bdeSize = size;
3236 * The lpfc_ct_cmd/lpfc_get_req shall increment ndlp reference count
3237 * to hold ndlp reference for the corresponding callback function.
3239 if (!lpfc_ct_cmd(vport, mp, bmp, ndlp, cmpl, rsp_size, 0))
3243 * Decrement ndlp reference count to release ndlp reference held
3244 * for the failed command's callback function.
3248 fdmi_cmd_free_bmpvirt:
3249 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
3252 fdmi_cmd_free_mpvirt:
3253 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3257 /* Issue FDMI request failed */
3258 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
3259 "0244 Issue FDMI request failed Data: x%x\n",
3265 * lpfc_delayed_disc_tmo - Timeout handler for delayed discovery timer.
3266 * @ptr - Context object of the timer.
3268 * This function set the WORKER_DELAYED_DISC_TMO flag and wake up
3269 * the worker thread.
3272 lpfc_delayed_disc_tmo(struct timer_list *t)
3274 struct lpfc_vport *vport = from_timer(vport, t, delayed_disc_tmo);
3275 struct lpfc_hba *phba = vport->phba;
3276 uint32_t tmo_posted;
3277 unsigned long iflag;
3279 spin_lock_irqsave(&vport->work_port_lock, iflag);
3280 tmo_posted = vport->work_port_events & WORKER_DELAYED_DISC_TMO;
3282 vport->work_port_events |= WORKER_DELAYED_DISC_TMO;
3283 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
3286 lpfc_worker_wake_up(phba);
3291 * lpfc_delayed_disc_timeout_handler - Function called by worker thread to
3292 * handle delayed discovery.
3293 * @vport: pointer to a host virtual N_Port data structure.
3295 * This function start nport discovery of the vport.
3298 lpfc_delayed_disc_timeout_handler(struct lpfc_vport *vport)
3300 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3302 spin_lock_irq(shost->host_lock);
3303 if (!(vport->fc_flag & FC_DISC_DELAYED)) {
3304 spin_unlock_irq(shost->host_lock);
3307 vport->fc_flag &= ~FC_DISC_DELAYED;
3308 spin_unlock_irq(shost->host_lock);
3310 lpfc_do_scr_ns_plogi(vport->phba, vport);
3314 lpfc_decode_firmware_rev(struct lpfc_hba *phba, char *fwrevision, int flag)
3316 struct lpfc_sli *psli = &phba->sli;
3317 lpfc_vpd_t *vp = &phba->vpd;
3318 uint32_t b1, b2, b3, b4, i, rev;
3320 uint32_t *ptr, str[4];
3323 if (phba->sli_rev == LPFC_SLI_REV4)
3324 snprintf(fwrevision, FW_REV_STR_SIZE, "%s", vp->rev.opFwName);
3325 else if (vp->rev.rBit) {
3326 if (psli->sli_flag & LPFC_SLI_ACTIVE)
3327 rev = vp->rev.sli2FwRev;
3329 rev = vp->rev.sli1FwRev;
3331 b1 = (rev & 0x0000f000) >> 12;
3332 b2 = (rev & 0x00000f00) >> 8;
3333 b3 = (rev & 0x000000c0) >> 6;
3334 b4 = (rev & 0x00000030) >> 4;
3353 b4 = (rev & 0x0000000f);
3355 if (psli->sli_flag & LPFC_SLI_ACTIVE)
3356 fwname = vp->rev.sli2FwName;
3358 fwname = vp->rev.sli1FwName;
3360 for (i = 0; i < 16; i++)
3361 if (fwname[i] == 0x20)
3364 ptr = (uint32_t*)fwname;
3366 for (i = 0; i < 3; i++)
3367 str[i] = be32_to_cpu(*ptr++);
3371 sprintf(fwrevision, "%d.%d%d (%s)",
3372 b1, b2, b3, (char *)str);
3374 sprintf(fwrevision, "%d.%d%d", b1,
3378 sprintf(fwrevision, "%d.%d%d%c%d (%s)",
3382 sprintf(fwrevision, "%d.%d%d%c%d",
3386 rev = vp->rev.smFwRev;
3388 b1 = (rev & 0xff000000) >> 24;
3389 b2 = (rev & 0x00f00000) >> 20;
3390 b3 = (rev & 0x000f0000) >> 16;
3391 c = (rev & 0x0000ff00) >> 8;
3392 b4 = (rev & 0x000000ff);
3394 sprintf(fwrevision, "%d.%d%d%c%d", b1, b2, b3, c, b4);