1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2017 Broadcom. All Rights Reserved. The term *
5 * “Broadcom” refers to Broadcom Limited 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->hbalock, 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->hbalock, flags);
455 spin_unlock_irqrestore(&phba->hbalock, 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 ndlp->nlp_fc4_type &= ~(NLP_FC4_FCP | NLP_FC4_NVME);
475 /* By default, the driver expects to support FCP FC4 */
476 if (fc4_type == FC_TYPE_FCP)
477 ndlp->nlp_fc4_type |= NLP_FC4_FCP;
479 if (fc4_type == FC_TYPE_NVME)
480 ndlp->nlp_fc4_type |= NLP_FC4_NVME;
482 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
483 "0238 Process x%06x NameServer Rsp "
484 "Data: x%x x%x x%x x%x\n", Did,
485 ndlp->nlp_flag, ndlp->nlp_fc4_type,
487 vport->fc_rscn_id_cnt);
489 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
490 "Skip1 GID_FTrsp: did:x%x flg:x%x cnt:%d",
491 Did, vport->fc_flag, vport->fc_rscn_id_cnt);
493 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
494 "0239 Skip x%06x NameServer Rsp "
495 "Data: x%x x%x\n", Did,
497 vport->fc_rscn_id_cnt);
500 if (!(vport->fc_flag & FC_RSCN_MODE) ||
501 lpfc_rscn_payload_check(vport, Did)) {
502 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
503 "Query GID_FTrsp: did:x%x flg:x%x cnt:%d",
504 Did, vport->fc_flag, vport->fc_rscn_id_cnt);
507 * This NPortID was previously a FCP/NVMe target,
508 * Don't even bother to send GFF_ID.
510 ndlp = lpfc_findnode_did(vport, Did);
511 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
513 (NLP_FCP_TARGET | NLP_NVME_TARGET))) {
514 if (fc4_type == FC_TYPE_FCP)
515 ndlp->nlp_fc4_type |= NLP_FC4_FCP;
516 if (fc4_type == FC_TYPE_NVME)
517 ndlp->nlp_fc4_type |= NLP_FC4_NVME;
518 lpfc_setup_disc_node(vport, Did);
519 } else if (lpfc_ns_cmd(vport, SLI_CTNS_GFF_ID,
521 vport->num_disc_nodes++;
523 lpfc_setup_disc_node(vport, Did);
525 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
526 "Skip2 GID_FTrsp: did:x%x flg:x%x cnt:%d",
527 Did, vport->fc_flag, vport->fc_rscn_id_cnt);
529 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
530 "0245 Skip x%06x NameServer Rsp "
531 "Data: x%x x%x\n", Did,
533 vport->fc_rscn_id_cnt);
539 lpfc_ns_rsp_audit_did(struct lpfc_vport *vport, uint32_t Did, uint8_t fc4_type)
541 struct lpfc_hba *phba = vport->phba;
542 struct lpfc_nodelist *ndlp = NULL;
543 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
546 * To conserve rpi's, filter out addresses for other
547 * vports on the same physical HBAs.
549 if (Did != vport->fc_myDID &&
550 (!lpfc_find_vport_by_did(phba, Did) ||
551 vport->cfg_peer_port_login)) {
552 if (!phba->nvmet_support) {
553 /* FCPI/NVMEI path. Process Did */
554 lpfc_prep_node_fc4type(vport, Did, fc4_type);
557 /* NVMET path. NVMET only cares about NVMEI nodes. */
558 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
559 if (ndlp->nlp_type != NLP_NVME_INITIATOR ||
560 ndlp->nlp_state != NLP_STE_UNMAPPED_NODE)
562 spin_lock_irq(shost->host_lock);
563 if (ndlp->nlp_DID == Did)
564 ndlp->nlp_flag &= ~NLP_NVMET_RECOV;
566 ndlp->nlp_flag |= NLP_NVMET_RECOV;
567 spin_unlock_irq(shost->host_lock);
573 lpfc_ns_rsp(struct lpfc_vport *vport, struct lpfc_dmabuf *mp, uint8_t fc4_type,
576 struct lpfc_sli_ct_request *Response =
577 (struct lpfc_sli_ct_request *) mp->virt;
578 struct lpfc_dmabuf *mlast, *next_mp;
579 uint32_t *ctptr = (uint32_t *) & Response->un.gid.PortType;
580 uint32_t Did, CTentry;
582 struct list_head head;
583 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
584 struct lpfc_nodelist *ndlp = NULL;
586 lpfc_set_disctmo(vport);
587 vport->num_disc_nodes = 0;
588 vport->fc_ns_retry = 0;
591 list_add_tail(&head, &mp->list);
592 list_for_each_entry_safe(mp, next_mp, &head, list) {
595 Cnt = Size > FCELSSIZE ? FCELSSIZE : Size;
600 ctptr = (uint32_t *) mlast->virt;
602 Cnt -= 16; /* subtract length of CT header */
604 /* Loop through entire NameServer list of DIDs */
605 while (Cnt >= sizeof(uint32_t)) {
606 /* Get next DID from NameServer List */
608 Did = ((be32_to_cpu(CTentry)) & Mask_DID);
609 lpfc_ns_rsp_audit_did(vport, Did, fc4_type);
610 if (CTentry & (cpu_to_be32(SLI_CT_LAST_ENTRY)))
613 Cnt -= sizeof(uint32_t);
619 /* All GID_FT entries processed. If the driver is running in
620 * in target mode, put impacted nodes into recovery and drop
621 * the RPI to flush outstanding IO.
623 if (vport->phba->nvmet_support) {
624 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
625 if (!(ndlp->nlp_flag & NLP_NVMET_RECOV))
627 lpfc_disc_state_machine(vport, ndlp, NULL,
628 NLP_EVT_DEVICE_RECOVERY);
629 spin_lock_irq(shost->host_lock);
630 ndlp->nlp_flag &= ~NLP_NVMET_RECOV;
631 spin_unlock_irq(shost->host_lock);
641 lpfc_cmpl_ct_cmd_gid_ft(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
642 struct lpfc_iocbq *rspiocb)
644 struct lpfc_vport *vport = cmdiocb->vport;
645 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
647 struct lpfc_dmabuf *outp;
648 struct lpfc_dmabuf *inp;
649 struct lpfc_sli_ct_request *CTrsp;
650 struct lpfc_sli_ct_request *CTreq;
651 struct lpfc_nodelist *ndlp;
654 /* First save ndlp, before we overwrite it */
655 ndlp = cmdiocb->context_un.ndlp;
657 /* we pass cmdiocb to state machine which needs rspiocb as well */
658 cmdiocb->context_un.rsp_iocb = rspiocb;
659 inp = (struct lpfc_dmabuf *) cmdiocb->context1;
660 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
661 irsp = &rspiocb->iocb;
663 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
664 "GID_FT cmpl: status:x%x/x%x rtry:%d",
665 irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_ns_retry);
667 /* Don't bother processing response if vport is being torn down. */
668 if (vport->load_flag & FC_UNLOADING) {
669 if (vport->fc_flag & FC_RSCN_MODE)
670 lpfc_els_flush_rscn(vport);
674 if (lpfc_els_chk_latt(vport)) {
675 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
676 "0216 Link event during NS query\n");
677 if (vport->fc_flag & FC_RSCN_MODE)
678 lpfc_els_flush_rscn(vport);
679 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
682 if (lpfc_error_lost_link(irsp)) {
683 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
684 "0226 NS query failed due to link event\n");
685 if (vport->fc_flag & FC_RSCN_MODE)
686 lpfc_els_flush_rscn(vport);
689 if (irsp->ulpStatus) {
690 /* Check for retry */
691 if (vport->fc_ns_retry < LPFC_MAX_NS_RETRY) {
692 if (irsp->ulpStatus != IOSTAT_LOCAL_REJECT ||
693 (irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
695 vport->fc_ns_retry++;
697 type = lpfc_get_gidft_type(vport, cmdiocb);
701 /* CT command is being retried */
703 rc = lpfc_ns_cmd(vport, SLI_CTNS_GID_FT,
704 vport->fc_ns_retry, type);
708 if (vport->fc_flag & FC_RSCN_MODE)
709 lpfc_els_flush_rscn(vport);
710 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
711 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
712 "0257 GID_FT Query error: 0x%x 0x%x\n",
713 irsp->ulpStatus, vport->fc_ns_retry);
715 /* Good status, continue checking */
716 CTreq = (struct lpfc_sli_ct_request *) inp->virt;
717 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
718 if (CTrsp->CommandResponse.bits.CmdRsp ==
719 cpu_to_be16(SLI_CT_RESPONSE_FS_ACC)) {
720 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
721 "0208 NameServer Rsp Data: x%x x%x\n",
723 CTreq->un.gid.Fc4Type);
727 CTreq->un.gid.Fc4Type,
728 (uint32_t) (irsp->un.genreq64.bdl.bdeSize));
729 } else if (CTrsp->CommandResponse.bits.CmdRsp ==
730 be16_to_cpu(SLI_CT_RESPONSE_FS_RJT)) {
731 /* NameServer Rsp Error */
732 if ((CTrsp->ReasonCode == SLI_CT_UNABLE_TO_PERFORM_REQ)
733 && (CTrsp->Explanation == SLI_CT_NO_FC4_TYPES)) {
734 lpfc_printf_vlog(vport, KERN_INFO,
736 "0269 No NameServer Entries "
737 "Data: x%x x%x x%x x%x\n",
738 CTrsp->CommandResponse.bits.CmdRsp,
739 (uint32_t) CTrsp->ReasonCode,
740 (uint32_t) CTrsp->Explanation,
743 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
744 "GID_FT no entry cmd:x%x rsn:x%x exp:x%x",
745 (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
746 (uint32_t) CTrsp->ReasonCode,
747 (uint32_t) CTrsp->Explanation);
749 lpfc_printf_vlog(vport, KERN_INFO,
751 "0240 NameServer Rsp Error "
752 "Data: x%x x%x x%x x%x\n",
753 CTrsp->CommandResponse.bits.CmdRsp,
754 (uint32_t) CTrsp->ReasonCode,
755 (uint32_t) CTrsp->Explanation,
758 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
759 "GID_FT rsp err1 cmd:x%x rsn:x%x exp:x%x",
760 (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
761 (uint32_t) CTrsp->ReasonCode,
762 (uint32_t) CTrsp->Explanation);
767 /* NameServer Rsp Error */
768 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
769 "0241 NameServer Rsp Error "
770 "Data: x%x x%x x%x x%x\n",
771 CTrsp->CommandResponse.bits.CmdRsp,
772 (uint32_t) CTrsp->ReasonCode,
773 (uint32_t) CTrsp->Explanation,
776 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
777 "GID_FT rsp err2 cmd:x%x rsn:x%x exp:x%x",
778 (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
779 (uint32_t) CTrsp->ReasonCode,
780 (uint32_t) CTrsp->Explanation);
784 /* Link up / RSCN discovery */
785 if ((vport->num_disc_nodes == 0) &&
786 (vport->gidft_inp == 0)) {
788 * The driver has cycled through all Nports in the RSCN payload.
789 * Complete the handling by cleaning up and marking the
790 * current driver state.
792 if (vport->port_state >= LPFC_DISC_AUTH) {
793 if (vport->fc_flag & FC_RSCN_MODE) {
794 lpfc_els_flush_rscn(vport);
795 spin_lock_irq(shost->host_lock);
796 vport->fc_flag |= FC_RSCN_MODE; /* RSCN still */
797 spin_unlock_irq(shost->host_lock);
800 lpfc_els_flush_rscn(vport);
803 lpfc_disc_start(vport);
806 cmdiocb->context_un.ndlp = ndlp; /* Now restore ndlp for free */
807 lpfc_ct_free_iocb(phba, cmdiocb);
812 lpfc_cmpl_ct_cmd_gff_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
813 struct lpfc_iocbq *rspiocb)
815 struct lpfc_vport *vport = cmdiocb->vport;
816 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
817 IOCB_t *irsp = &rspiocb->iocb;
818 struct lpfc_dmabuf *inp = (struct lpfc_dmabuf *) cmdiocb->context1;
819 struct lpfc_dmabuf *outp = (struct lpfc_dmabuf *) cmdiocb->context2;
820 struct lpfc_sli_ct_request *CTrsp;
823 struct lpfc_nodelist *ndlp;
825 did = ((struct lpfc_sli_ct_request *) inp->virt)->un.gff.PortId;
826 did = be32_to_cpu(did);
828 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
829 "GFF_ID cmpl: status:x%x/x%x did:x%x",
830 irsp->ulpStatus, irsp->un.ulpWord[4], did);
832 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
833 /* Good status, continue checking */
834 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
835 fbits = CTrsp->un.gff_acc.fbits[FCP_TYPE_FEATURE_OFFSET];
837 if (CTrsp->CommandResponse.bits.CmdRsp ==
838 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC)) {
839 if ((fbits & FC4_FEATURE_INIT) &&
840 !(fbits & FC4_FEATURE_TARGET)) {
841 lpfc_printf_vlog(vport, KERN_INFO,
844 "NameServer Rsp Data: (init) "
845 "x%x x%x\n", did, fbits,
846 vport->fc_rscn_id_cnt);
852 /* Check for retry */
853 if (cmdiocb->retry < LPFC_MAX_NS_RETRY) {
855 if (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) {
856 switch ((irsp->un.ulpWord[4] &
859 case IOERR_NO_RESOURCES:
860 /* We don't increment the retry
861 * count for this case.
864 case IOERR_LINK_DOWN:
865 case IOERR_SLI_ABORTED:
877 /* CT command is being retried */
878 rc = lpfc_ns_cmd(vport, SLI_CTNS_GFF_ID,
879 cmdiocb->retry, did);
882 lpfc_ct_free_iocb(phba, cmdiocb);
887 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
888 "0267 NameServer GFF Rsp "
889 "x%x Error (%d %d) Data: x%x x%x\n",
890 did, irsp->ulpStatus, irsp->un.ulpWord[4],
891 vport->fc_flag, vport->fc_rscn_id_cnt);
894 /* This is a target port, unregistered port, or the GFF_ID failed */
895 ndlp = lpfc_setup_disc_node(vport, did);
896 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
897 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
898 "0242 Process x%x GFF "
899 "NameServer Rsp Data: x%x x%x x%x\n",
900 did, ndlp->nlp_flag, vport->fc_flag,
901 vport->fc_rscn_id_cnt);
903 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
905 "NameServer Rsp Data: x%x x%x\n", did,
906 vport->fc_flag, vport->fc_rscn_id_cnt);
909 /* Link up / RSCN discovery */
910 if (vport->num_disc_nodes)
911 vport->num_disc_nodes--;
912 if (vport->num_disc_nodes == 0) {
914 * The driver has cycled through all Nports in the RSCN payload.
915 * Complete the handling by cleaning up and marking the
916 * current driver state.
918 if (vport->port_state >= LPFC_DISC_AUTH) {
919 if (vport->fc_flag & FC_RSCN_MODE) {
920 lpfc_els_flush_rscn(vport);
921 spin_lock_irq(shost->host_lock);
922 vport->fc_flag |= FC_RSCN_MODE; /* RSCN still */
923 spin_unlock_irq(shost->host_lock);
926 lpfc_els_flush_rscn(vport);
928 lpfc_disc_start(vport);
930 lpfc_ct_free_iocb(phba, cmdiocb);
935 lpfc_cmpl_ct_cmd_gft_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
936 struct lpfc_iocbq *rspiocb)
938 struct lpfc_vport *vport = cmdiocb->vport;
939 IOCB_t *irsp = &rspiocb->iocb;
940 struct lpfc_dmabuf *inp = (struct lpfc_dmabuf *)cmdiocb->context1;
941 struct lpfc_dmabuf *outp = (struct lpfc_dmabuf *)cmdiocb->context2;
942 struct lpfc_sli_ct_request *CTrsp;
944 struct lpfc_nodelist *ndlp;
945 uint32_t fc4_data_0, fc4_data_1;
947 did = ((struct lpfc_sli_ct_request *)inp->virt)->un.gft.PortId;
948 did = be32_to_cpu(did);
950 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
951 "GFT_ID cmpl: status:x%x/x%x did:x%x",
952 irsp->ulpStatus, irsp->un.ulpWord[4], did);
954 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
955 /* Good status, continue checking */
956 CTrsp = (struct lpfc_sli_ct_request *)outp->virt;
957 fc4_data_0 = be32_to_cpu(CTrsp->un.gft_acc.fc4_types[0]);
958 fc4_data_1 = be32_to_cpu(CTrsp->un.gft_acc.fc4_types[1]);
959 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
960 "3062 DID x%06x GFT Wd0 x%08x Wd1 x%08x\n",
961 did, fc4_data_0, fc4_data_1);
963 ndlp = lpfc_findnode_did(vport, did);
965 /* The bitmask value for FCP and NVME FCP types is
966 * the same because they are 32 bits distant from
967 * each other in word0 and word0.
969 if (fc4_data_0 & LPFC_FC4_TYPE_BITMASK)
970 ndlp->nlp_fc4_type |= NLP_FC4_FCP;
971 if (fc4_data_1 & LPFC_FC4_TYPE_BITMASK)
972 ndlp->nlp_fc4_type |= NLP_FC4_NVME;
973 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
974 "3064 Setting ndlp %p, DID x%06x with "
975 "FC4 x%08x, Data: x%08x x%08x\n",
976 ndlp, did, ndlp->nlp_fc4_type,
977 FC_TYPE_FCP, FC_TYPE_NVME);
978 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
980 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
981 lpfc_issue_els_prli(vport, ndlp, 0);
984 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
985 "3065 GFT_ID failed x%08x\n", irsp->ulpStatus);
987 lpfc_ct_free_iocb(phba, cmdiocb);
991 lpfc_cmpl_ct(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
992 struct lpfc_iocbq *rspiocb)
994 struct lpfc_vport *vport = cmdiocb->vport;
995 struct lpfc_dmabuf *inp;
996 struct lpfc_dmabuf *outp;
998 struct lpfc_sli_ct_request *CTrsp;
999 struct lpfc_nodelist *ndlp;
1004 /* First save ndlp, before we overwrite it */
1005 ndlp = cmdiocb->context_un.ndlp;
1007 /* we pass cmdiocb to state machine which needs rspiocb as well */
1008 cmdiocb->context_un.rsp_iocb = rspiocb;
1010 inp = (struct lpfc_dmabuf *) cmdiocb->context1;
1011 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
1012 irsp = &rspiocb->iocb;
1014 cmdcode = be16_to_cpu(((struct lpfc_sli_ct_request *) inp->virt)->
1015 CommandResponse.bits.CmdRsp);
1016 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
1018 latt = lpfc_els_chk_latt(vport);
1020 /* RFT request completes status <ulpStatus> CmdRsp <CmdRsp> */
1021 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1022 "0209 CT Request completes, latt %d, "
1023 "ulpStatus x%x CmdRsp x%x, Context x%x, Tag x%x\n",
1024 latt, irsp->ulpStatus,
1025 CTrsp->CommandResponse.bits.CmdRsp,
1026 cmdiocb->iocb.ulpContext, cmdiocb->iocb.ulpIoTag);
1028 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
1029 "CT cmd cmpl: status:x%x/x%x cmd:x%x",
1030 irsp->ulpStatus, irsp->un.ulpWord[4], cmdcode);
1032 if (irsp->ulpStatus) {
1033 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
1034 "0268 NS cmd x%x Error (x%x x%x)\n",
1035 cmdcode, irsp->ulpStatus, irsp->un.ulpWord[4]);
1037 if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
1038 (((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
1040 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
1041 IOERR_SLI_ABORTED)))
1044 retry = cmdiocb->retry;
1045 if (retry >= LPFC_MAX_NS_RETRY)
1049 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1050 "0250 Retrying NS cmd %x\n", cmdcode);
1051 rc = lpfc_ns_cmd(vport, cmdcode, retry, 0);
1057 cmdiocb->context_un.ndlp = ndlp; /* Now restore ndlp for free */
1058 lpfc_ct_free_iocb(phba, cmdiocb);
1063 lpfc_cmpl_ct_cmd_rft_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1064 struct lpfc_iocbq *rspiocb)
1066 IOCB_t *irsp = &rspiocb->iocb;
1067 struct lpfc_vport *vport = cmdiocb->vport;
1069 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
1070 struct lpfc_dmabuf *outp;
1071 struct lpfc_sli_ct_request *CTrsp;
1073 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
1074 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
1075 if (CTrsp->CommandResponse.bits.CmdRsp ==
1076 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
1077 vport->ct_flags |= FC_CT_RFT_ID;
1079 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
1084 lpfc_cmpl_ct_cmd_rnn_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1085 struct lpfc_iocbq *rspiocb)
1087 IOCB_t *irsp = &rspiocb->iocb;
1088 struct lpfc_vport *vport = cmdiocb->vport;
1090 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
1091 struct lpfc_dmabuf *outp;
1092 struct lpfc_sli_ct_request *CTrsp;
1094 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
1095 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
1096 if (CTrsp->CommandResponse.bits.CmdRsp ==
1097 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
1098 vport->ct_flags |= FC_CT_RNN_ID;
1100 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
1105 lpfc_cmpl_ct_cmd_rspn_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1106 struct lpfc_iocbq *rspiocb)
1108 IOCB_t *irsp = &rspiocb->iocb;
1109 struct lpfc_vport *vport = cmdiocb->vport;
1111 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
1112 struct lpfc_dmabuf *outp;
1113 struct lpfc_sli_ct_request *CTrsp;
1115 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
1116 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
1117 if (CTrsp->CommandResponse.bits.CmdRsp ==
1118 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
1119 vport->ct_flags |= FC_CT_RSPN_ID;
1121 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
1126 lpfc_cmpl_ct_cmd_rsnn_nn(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1127 struct lpfc_iocbq *rspiocb)
1129 IOCB_t *irsp = &rspiocb->iocb;
1130 struct lpfc_vport *vport = cmdiocb->vport;
1132 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
1133 struct lpfc_dmabuf *outp;
1134 struct lpfc_sli_ct_request *CTrsp;
1136 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
1137 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
1138 if (CTrsp->CommandResponse.bits.CmdRsp ==
1139 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
1140 vport->ct_flags |= FC_CT_RSNN_NN;
1142 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
1147 lpfc_cmpl_ct_cmd_da_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1148 struct lpfc_iocbq *rspiocb)
1150 struct lpfc_vport *vport = cmdiocb->vport;
1152 /* even if it fails we will act as though it succeeded. */
1153 vport->ct_flags = 0;
1154 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
1159 lpfc_cmpl_ct_cmd_rff_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1160 struct lpfc_iocbq *rspiocb)
1162 IOCB_t *irsp = &rspiocb->iocb;
1163 struct lpfc_vport *vport = cmdiocb->vport;
1165 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
1166 struct lpfc_dmabuf *outp;
1167 struct lpfc_sli_ct_request *CTrsp;
1169 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
1170 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
1171 if (CTrsp->CommandResponse.bits.CmdRsp ==
1172 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
1173 vport->ct_flags |= FC_CT_RFF_ID;
1175 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
1180 * Although the symbolic port name is thought to be an integer
1181 * as of January 18, 2016, leave it as a string until more of
1182 * the record state becomes defined.
1185 lpfc_vport_symbolic_port_name(struct lpfc_vport *vport, char *symbol,
1191 * Use the lpfc board number as the Symbolic Port
1192 * Name object. NPIV is not in play so this integer
1193 * value is sufficient and unique per FC-ID.
1195 n = snprintf(symbol, size, "%d", vport->phba->brd_no);
1201 lpfc_vport_symbolic_node_name(struct lpfc_vport *vport, char *symbol,
1204 char fwrev[FW_REV_STR_SIZE];
1207 lpfc_decode_firmware_rev(vport->phba, fwrev, 0);
1209 n = snprintf(symbol, size, "Emulex %s", vport->phba->ModelName);
1213 n += snprintf(symbol + n, size - n, " FV%s", fwrev);
1217 n += snprintf(symbol + n, size - n, " DV%s.",
1218 lpfc_release_version);
1222 n += snprintf(symbol + n, size - n, " HN:%s.",
1223 init_utsname()->nodename);
1227 /* Note :- OS name is "Linux" */
1228 n += snprintf(symbol + n, size - n, " OS:%s\n",
1229 init_utsname()->sysname);
1234 lpfc_find_map_node(struct lpfc_vport *vport)
1236 struct lpfc_nodelist *ndlp, *next_ndlp;
1237 struct Scsi_Host *shost;
1240 shost = lpfc_shost_from_vport(vport);
1241 spin_lock_irq(shost->host_lock);
1242 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
1243 if (ndlp->nlp_type & NLP_FABRIC)
1245 if ((ndlp->nlp_state == NLP_STE_MAPPED_NODE) ||
1246 (ndlp->nlp_state == NLP_STE_UNMAPPED_NODE))
1249 spin_unlock_irq(shost->host_lock);
1254 * This routine will return the FC4 Type associated with the CT
1258 lpfc_get_gidft_type(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb)
1260 struct lpfc_sli_ct_request *CtReq;
1261 struct lpfc_dmabuf *mp;
1264 mp = cmdiocb->context1;
1267 CtReq = (struct lpfc_sli_ct_request *)mp->virt;
1268 type = (uint32_t)CtReq->un.gid.Fc4Type;
1269 if ((type != SLI_CTPT_FCP) && (type != SLI_CTPT_NVME))
1277 * Issue Cmd to NameServer
1282 lpfc_ns_cmd(struct lpfc_vport *vport, int cmdcode,
1283 uint8_t retry, uint32_t context)
1285 struct lpfc_nodelist * ndlp;
1286 struct lpfc_hba *phba = vport->phba;
1287 struct lpfc_dmabuf *mp, *bmp;
1288 struct lpfc_sli_ct_request *CtReq;
1289 struct ulp_bde64 *bpl;
1290 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
1291 struct lpfc_iocbq *) = NULL;
1292 uint32_t rsp_size = 1024;
1296 ndlp = lpfc_findnode_did(vport, NameServer_DID);
1297 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)
1298 || ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) {
1303 /* fill in BDEs for command */
1304 /* Allocate buffer for command payload */
1305 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
1311 INIT_LIST_HEAD(&mp->list);
1312 mp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(mp->phys));
1315 goto ns_cmd_free_mp;
1318 /* Allocate buffer for Buffer ptr list */
1319 bmp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
1322 goto ns_cmd_free_mpvirt;
1325 INIT_LIST_HEAD(&bmp->list);
1326 bmp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(bmp->phys));
1329 goto ns_cmd_free_bmp;
1332 /* NameServer Req */
1333 lpfc_printf_vlog(vport, KERN_INFO ,LOG_DISCOVERY,
1334 "0236 NameServer Req Data: x%x x%x x%x x%x\n",
1335 cmdcode, vport->fc_flag, vport->fc_rscn_id_cnt,
1338 bpl = (struct ulp_bde64 *) bmp->virt;
1339 memset(bpl, 0, sizeof(struct ulp_bde64));
1340 bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys) );
1341 bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys) );
1342 bpl->tus.f.bdeFlags = 0;
1343 if (cmdcode == SLI_CTNS_GID_FT)
1344 bpl->tus.f.bdeSize = GID_REQUEST_SZ;
1345 else if (cmdcode == SLI_CTNS_GFF_ID)
1346 bpl->tus.f.bdeSize = GFF_REQUEST_SZ;
1347 else if (cmdcode == SLI_CTNS_GFT_ID)
1348 bpl->tus.f.bdeSize = GFT_REQUEST_SZ;
1349 else if (cmdcode == SLI_CTNS_RFT_ID)
1350 bpl->tus.f.bdeSize = RFT_REQUEST_SZ;
1351 else if (cmdcode == SLI_CTNS_RNN_ID)
1352 bpl->tus.f.bdeSize = RNN_REQUEST_SZ;
1353 else if (cmdcode == SLI_CTNS_RSPN_ID)
1354 bpl->tus.f.bdeSize = RSPN_REQUEST_SZ;
1355 else if (cmdcode == SLI_CTNS_RSNN_NN)
1356 bpl->tus.f.bdeSize = RSNN_REQUEST_SZ;
1357 else if (cmdcode == SLI_CTNS_DA_ID)
1358 bpl->tus.f.bdeSize = DA_ID_REQUEST_SZ;
1359 else if (cmdcode == SLI_CTNS_RFF_ID)
1360 bpl->tus.f.bdeSize = RFF_REQUEST_SZ;
1362 bpl->tus.f.bdeSize = 0;
1363 bpl->tus.w = le32_to_cpu(bpl->tus.w);
1365 CtReq = (struct lpfc_sli_ct_request *) mp->virt;
1366 memset(CtReq, 0, sizeof(struct lpfc_sli_ct_request));
1367 CtReq->RevisionId.bits.Revision = SLI_CT_REVISION;
1368 CtReq->RevisionId.bits.InId = 0;
1369 CtReq->FsType = SLI_CT_DIRECTORY_SERVICE;
1370 CtReq->FsSubType = SLI_CT_DIRECTORY_NAME_SERVER;
1371 CtReq->CommandResponse.bits.Size = 0;
1373 case SLI_CTNS_GID_FT:
1374 CtReq->CommandResponse.bits.CmdRsp =
1375 cpu_to_be16(SLI_CTNS_GID_FT);
1376 CtReq->un.gid.Fc4Type = context;
1378 if (vport->port_state < LPFC_NS_QRY)
1379 vport->port_state = LPFC_NS_QRY;
1380 lpfc_set_disctmo(vport);
1381 cmpl = lpfc_cmpl_ct_cmd_gid_ft;
1382 rsp_size = FC_MAX_NS_RSP;
1385 case SLI_CTNS_GFF_ID:
1386 CtReq->CommandResponse.bits.CmdRsp =
1387 cpu_to_be16(SLI_CTNS_GFF_ID);
1388 CtReq->un.gff.PortId = cpu_to_be32(context);
1389 cmpl = lpfc_cmpl_ct_cmd_gff_id;
1392 case SLI_CTNS_GFT_ID:
1393 CtReq->CommandResponse.bits.CmdRsp =
1394 cpu_to_be16(SLI_CTNS_GFT_ID);
1395 CtReq->un.gft.PortId = cpu_to_be32(context);
1396 cmpl = lpfc_cmpl_ct_cmd_gft_id;
1399 case SLI_CTNS_RFT_ID:
1400 vport->ct_flags &= ~FC_CT_RFT_ID;
1401 CtReq->CommandResponse.bits.CmdRsp =
1402 cpu_to_be16(SLI_CTNS_RFT_ID);
1403 CtReq->un.rft.PortId = cpu_to_be32(vport->fc_myDID);
1405 /* Register FC4 FCP type if enabled. */
1406 if ((phba->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
1407 (phba->cfg_enable_fc4_type == LPFC_ENABLE_FCP))
1408 CtReq->un.rft.fcpReg = 1;
1410 /* Register NVME type if enabled. Defined LE and swapped.
1411 * rsvd[0] is used as word1 because of the hard-coded
1412 * word0 usage in the ct_request data structure.
1414 if ((phba->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
1415 (phba->cfg_enable_fc4_type == LPFC_ENABLE_NVME))
1416 CtReq->un.rft.rsvd[0] = cpu_to_be32(0x00000100);
1418 cmpl = lpfc_cmpl_ct_cmd_rft_id;
1421 case SLI_CTNS_RNN_ID:
1422 vport->ct_flags &= ~FC_CT_RNN_ID;
1423 CtReq->CommandResponse.bits.CmdRsp =
1424 cpu_to_be16(SLI_CTNS_RNN_ID);
1425 CtReq->un.rnn.PortId = cpu_to_be32(vport->fc_myDID);
1426 memcpy(CtReq->un.rnn.wwnn, &vport->fc_nodename,
1427 sizeof(struct lpfc_name));
1428 cmpl = lpfc_cmpl_ct_cmd_rnn_id;
1431 case SLI_CTNS_RSPN_ID:
1432 vport->ct_flags &= ~FC_CT_RSPN_ID;
1433 CtReq->CommandResponse.bits.CmdRsp =
1434 cpu_to_be16(SLI_CTNS_RSPN_ID);
1435 CtReq->un.rspn.PortId = cpu_to_be32(vport->fc_myDID);
1436 size = sizeof(CtReq->un.rspn.symbname);
1437 CtReq->un.rspn.len =
1438 lpfc_vport_symbolic_port_name(vport,
1439 CtReq->un.rspn.symbname, size);
1440 cmpl = lpfc_cmpl_ct_cmd_rspn_id;
1442 case SLI_CTNS_RSNN_NN:
1443 vport->ct_flags &= ~FC_CT_RSNN_NN;
1444 CtReq->CommandResponse.bits.CmdRsp =
1445 cpu_to_be16(SLI_CTNS_RSNN_NN);
1446 memcpy(CtReq->un.rsnn.wwnn, &vport->fc_nodename,
1447 sizeof(struct lpfc_name));
1448 size = sizeof(CtReq->un.rsnn.symbname);
1449 CtReq->un.rsnn.len =
1450 lpfc_vport_symbolic_node_name(vport,
1451 CtReq->un.rsnn.symbname, size);
1452 cmpl = lpfc_cmpl_ct_cmd_rsnn_nn;
1454 case SLI_CTNS_DA_ID:
1455 /* Implement DA_ID Nameserver request */
1456 CtReq->CommandResponse.bits.CmdRsp =
1457 cpu_to_be16(SLI_CTNS_DA_ID);
1458 CtReq->un.da_id.port_id = cpu_to_be32(vport->fc_myDID);
1459 cmpl = lpfc_cmpl_ct_cmd_da_id;
1461 case SLI_CTNS_RFF_ID:
1462 vport->ct_flags &= ~FC_CT_RFF_ID;
1463 CtReq->CommandResponse.bits.CmdRsp =
1464 cpu_to_be16(SLI_CTNS_RFF_ID);
1465 CtReq->un.rff.PortId = cpu_to_be32(vport->fc_myDID);
1466 CtReq->un.rff.fbits = FC4_FEATURE_INIT;
1468 /* The driver always supports FC_TYPE_FCP. However, the
1469 * caller can specify NVME (type x28) as well. But only
1470 * these that FC4 type is supported.
1472 if (((phba->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
1473 (phba->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) &&
1474 (context == FC_TYPE_NVME)) {
1475 if ((vport == phba->pport) && phba->nvmet_support) {
1476 CtReq->un.rff.fbits = (FC4_FEATURE_TARGET |
1477 FC4_FEATURE_NVME_DISC);
1478 lpfc_nvmet_update_targetport(phba);
1480 lpfc_nvme_update_localport(vport);
1482 CtReq->un.rff.type_code = context;
1484 } else if (((phba->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
1485 (phba->cfg_enable_fc4_type == LPFC_ENABLE_FCP)) &&
1486 (context == FC_TYPE_FCP))
1487 CtReq->un.rff.type_code = context;
1490 goto ns_cmd_free_bmpvirt;
1492 cmpl = lpfc_cmpl_ct_cmd_rff_id;
1495 /* The lpfc_ct_cmd/lpfc_get_req shall increment ndlp reference count
1496 * to hold ndlp reference for the corresponding callback function.
1498 if (!lpfc_ct_cmd(vport, mp, bmp, ndlp, cmpl, rsp_size, retry)) {
1499 /* On success, The cmpl function will free the buffers */
1500 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
1501 "Issue CT cmd: cmd:x%x did:x%x",
1502 cmdcode, ndlp->nlp_DID, 0);
1507 /* Decrement ndlp reference count to release ndlp reference held
1508 * for the failed command's callback function.
1512 ns_cmd_free_bmpvirt:
1513 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
1517 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1521 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
1522 "0266 Issue NameServer Req x%x err %d Data: x%x x%x\n",
1523 cmdcode, rc, vport->fc_flag, vport->fc_rscn_id_cnt);
1528 * lpfc_cmpl_ct_disc_fdmi - Handle a discovery FDMI completion
1529 * @phba: Pointer to HBA context object.
1530 * @cmdiocb: Pointer to the command IOCBQ.
1531 * @rspiocb: Pointer to the response IOCBQ.
1533 * This function to handle the completion of a driver initiated FDMI
1534 * CT command issued during discovery.
1537 lpfc_cmpl_ct_disc_fdmi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1538 struct lpfc_iocbq *rspiocb)
1540 struct lpfc_vport *vport = cmdiocb->vport;
1541 struct lpfc_dmabuf *inp = cmdiocb->context1;
1542 struct lpfc_dmabuf *outp = cmdiocb->context2;
1543 struct lpfc_sli_ct_request *CTcmd = inp->virt;
1544 struct lpfc_sli_ct_request *CTrsp = outp->virt;
1545 uint16_t fdmi_cmd = CTcmd->CommandResponse.bits.CmdRsp;
1546 uint16_t fdmi_rsp = CTrsp->CommandResponse.bits.CmdRsp;
1547 IOCB_t *irsp = &rspiocb->iocb;
1548 struct lpfc_nodelist *ndlp;
1549 uint32_t latt, cmd, err;
1551 latt = lpfc_els_chk_latt(vport);
1552 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
1553 "FDMI cmpl: status:x%x/x%x latt:%d",
1554 irsp->ulpStatus, irsp->un.ulpWord[4], latt);
1556 if (latt || irsp->ulpStatus) {
1558 /* Look for a retryable error */
1559 if (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) {
1560 switch ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK)) {
1561 case IOERR_SLI_ABORTED:
1562 case IOERR_ABORT_IN_PROGRESS:
1563 case IOERR_SEQUENCE_TIMEOUT:
1564 case IOERR_ILLEGAL_FRAME:
1565 case IOERR_NO_RESOURCES:
1566 case IOERR_ILLEGAL_COMMAND:
1568 if (cmdiocb->retry >= LPFC_FDMI_MAX_RETRY)
1571 /* Retry the same FDMI command */
1572 err = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING,
1574 if (err == IOCB_ERROR)
1582 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1583 "0229 FDMI cmd %04x failed, latt = %d "
1584 "ulpStatus: x%x, rid x%x\n",
1585 be16_to_cpu(fdmi_cmd), latt, irsp->ulpStatus,
1586 irsp->un.ulpWord[4]);
1588 lpfc_ct_free_iocb(phba, cmdiocb);
1590 ndlp = lpfc_findnode_did(vport, FDMI_DID);
1591 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
1594 /* Check for a CT LS_RJT response */
1595 cmd = be16_to_cpu(fdmi_cmd);
1596 if (fdmi_rsp == cpu_to_be16(SLI_CT_RESPONSE_FS_RJT)) {
1597 /* FDMI rsp failed */
1598 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1599 "0220 FDMI cmd failed FS_RJT Data: x%x", cmd);
1601 /* Should we fallback to FDMI-2 / FDMI-1 ? */
1604 if (vport->fdmi_hba_mask == LPFC_FDMI2_HBA_ATTR) {
1605 /* Fallback to FDMI-1 */
1606 vport->fdmi_hba_mask = LPFC_FDMI1_HBA_ATTR;
1607 vport->fdmi_port_mask = LPFC_FDMI1_PORT_ATTR;
1609 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA, 0);
1614 if (vport->fdmi_port_mask == LPFC_FDMI2_PORT_ATTR) {
1615 /* Fallback to FDMI-1 */
1616 vport->fdmi_port_mask = LPFC_FDMI1_PORT_ATTR;
1618 lpfc_fdmi_cmd(vport, ndlp, cmd, 0);
1620 if (vport->fdmi_port_mask == LPFC_FDMI2_SMART_ATTR) {
1621 vport->fdmi_port_mask = LPFC_FDMI2_PORT_ATTR;
1622 /* Retry the same command */
1623 lpfc_fdmi_cmd(vport, ndlp, cmd, 0);
1628 if (vport->fdmi_port_mask == LPFC_FDMI2_PORT_ATTR) {
1629 /* Fallback to FDMI-1 */
1630 vport->fdmi_hba_mask = LPFC_FDMI1_HBA_ATTR;
1631 vport->fdmi_port_mask = LPFC_FDMI1_PORT_ATTR;
1633 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA, 0);
1635 if (vport->fdmi_port_mask == LPFC_FDMI2_SMART_ATTR) {
1636 vport->fdmi_port_mask = LPFC_FDMI2_PORT_ATTR;
1637 /* Retry the same command */
1638 lpfc_fdmi_cmd(vport, ndlp, cmd, 0);
1645 * On success, need to cycle thru FDMI registration for discovery
1646 * DHBA -> DPRT -> RHBA -> RPA (physical port)
1647 * DPRT -> RPRT (vports)
1651 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RPA, 0);
1655 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DPRT, 0);
1659 if (vport->port_type == LPFC_PHYSICAL_PORT)
1660 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RHBA, 0);
1662 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RPRT, 0);
1670 * lpfc_fdmi_num_disc_check - Check how many mapped NPorts we are connected to
1671 * @vport: pointer to a host virtual N_Port data structure.
1673 * Called from hbeat timeout routine to check if the number of discovered
1674 * ports has changed. If so, re-register thar port Attribute.
1677 lpfc_fdmi_num_disc_check(struct lpfc_vport *vport)
1679 struct lpfc_hba *phba = vport->phba;
1680 struct lpfc_nodelist *ndlp;
1683 if (!lpfc_is_link_up(phba))
1686 /* Must be connected to a Fabric */
1687 if (!(vport->fc_flag & FC_FABRIC))
1690 if (!(vport->fdmi_port_mask & LPFC_FDMI_PORT_ATTR_num_disc))
1693 cnt = lpfc_find_map_node(vport);
1694 if (cnt == vport->fdmi_num_disc)
1697 ndlp = lpfc_findnode_did(vport, FDMI_DID);
1698 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
1701 if (vport->port_type == LPFC_PHYSICAL_PORT) {
1702 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RPA,
1703 LPFC_FDMI_PORT_ATTR_num_disc);
1705 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RPRT,
1706 LPFC_FDMI_PORT_ATTR_num_disc);
1710 /* Routines for all individual HBA attributes */
1712 lpfc_fdmi_hba_attr_wwnn(struct lpfc_vport *vport, struct lpfc_fdmi_attr_def *ad)
1714 struct lpfc_fdmi_attr_entry *ae;
1717 ae = &ad->AttrValue;
1718 memset(ae, 0, sizeof(*ae));
1720 memcpy(&ae->un.AttrWWN, &vport->fc_sparam.nodeName,
1721 sizeof(struct lpfc_name));
1722 size = FOURBYTES + sizeof(struct lpfc_name);
1723 ad->AttrLen = cpu_to_be16(size);
1724 ad->AttrType = cpu_to_be16(RHBA_NODENAME);
1728 lpfc_fdmi_hba_attr_manufacturer(struct lpfc_vport *vport,
1729 struct lpfc_fdmi_attr_def *ad)
1731 struct lpfc_fdmi_attr_entry *ae;
1734 ae = &ad->AttrValue;
1735 memset(ae, 0, sizeof(*ae));
1737 /* This string MUST be consistent with other FC platforms
1738 * supported by Broadcom.
1740 strncpy(ae->un.AttrString,
1741 "Emulex Corporation",
1742 sizeof(ae->un.AttrString));
1743 len = strnlen(ae->un.AttrString,
1744 sizeof(ae->un.AttrString));
1745 len += (len & 3) ? (4 - (len & 3)) : 4;
1746 size = FOURBYTES + len;
1747 ad->AttrLen = cpu_to_be16(size);
1748 ad->AttrType = cpu_to_be16(RHBA_MANUFACTURER);
1753 lpfc_fdmi_hba_attr_sn(struct lpfc_vport *vport, struct lpfc_fdmi_attr_def *ad)
1755 struct lpfc_hba *phba = vport->phba;
1756 struct lpfc_fdmi_attr_entry *ae;
1759 ae = &ad->AttrValue;
1760 memset(ae, 0, sizeof(*ae));
1762 strncpy(ae->un.AttrString, phba->SerialNumber,
1763 sizeof(ae->un.AttrString));
1764 len = strnlen(ae->un.AttrString,
1765 sizeof(ae->un.AttrString));
1766 len += (len & 3) ? (4 - (len & 3)) : 4;
1767 size = FOURBYTES + len;
1768 ad->AttrLen = cpu_to_be16(size);
1769 ad->AttrType = cpu_to_be16(RHBA_SERIAL_NUMBER);
1774 lpfc_fdmi_hba_attr_model(struct lpfc_vport *vport,
1775 struct lpfc_fdmi_attr_def *ad)
1777 struct lpfc_hba *phba = vport->phba;
1778 struct lpfc_fdmi_attr_entry *ae;
1781 ae = &ad->AttrValue;
1782 memset(ae, 0, sizeof(*ae));
1784 strncpy(ae->un.AttrString, phba->ModelName,
1785 sizeof(ae->un.AttrString));
1786 len = strnlen(ae->un.AttrString, sizeof(ae->un.AttrString));
1787 len += (len & 3) ? (4 - (len & 3)) : 4;
1788 size = FOURBYTES + len;
1789 ad->AttrLen = cpu_to_be16(size);
1790 ad->AttrType = cpu_to_be16(RHBA_MODEL);
1795 lpfc_fdmi_hba_attr_description(struct lpfc_vport *vport,
1796 struct lpfc_fdmi_attr_def *ad)
1798 struct lpfc_hba *phba = vport->phba;
1799 struct lpfc_fdmi_attr_entry *ae;
1802 ae = &ad->AttrValue;
1803 memset(ae, 0, sizeof(*ae));
1805 strncpy(ae->un.AttrString, phba->ModelDesc,
1806 sizeof(ae->un.AttrString));
1807 len = strnlen(ae->un.AttrString,
1808 sizeof(ae->un.AttrString));
1809 len += (len & 3) ? (4 - (len & 3)) : 4;
1810 size = FOURBYTES + len;
1811 ad->AttrLen = cpu_to_be16(size);
1812 ad->AttrType = cpu_to_be16(RHBA_MODEL_DESCRIPTION);
1817 lpfc_fdmi_hba_attr_hdw_ver(struct lpfc_vport *vport,
1818 struct lpfc_fdmi_attr_def *ad)
1820 struct lpfc_hba *phba = vport->phba;
1821 lpfc_vpd_t *vp = &phba->vpd;
1822 struct lpfc_fdmi_attr_entry *ae;
1823 uint32_t i, j, incr, size;
1825 ae = &ad->AttrValue;
1826 memset(ae, 0, sizeof(*ae));
1828 /* Convert JEDEC ID to ascii for hardware version */
1829 incr = vp->rev.biuRev;
1830 for (i = 0; i < 8; i++) {
1833 ae->un.AttrString[7 - i] =
1834 (char)((uint8_t) 0x30 +
1837 ae->un.AttrString[7 - i] =
1838 (char)((uint8_t) 0x61 +
1839 (uint8_t) (j - 10));
1842 size = FOURBYTES + 8;
1843 ad->AttrLen = cpu_to_be16(size);
1844 ad->AttrType = cpu_to_be16(RHBA_HARDWARE_VERSION);
1849 lpfc_fdmi_hba_attr_drvr_ver(struct lpfc_vport *vport,
1850 struct lpfc_fdmi_attr_def *ad)
1852 struct lpfc_fdmi_attr_entry *ae;
1855 ae = &ad->AttrValue;
1856 memset(ae, 0, sizeof(*ae));
1858 strncpy(ae->un.AttrString, lpfc_release_version,
1859 sizeof(ae->un.AttrString));
1860 len = strnlen(ae->un.AttrString,
1861 sizeof(ae->un.AttrString));
1862 len += (len & 3) ? (4 - (len & 3)) : 4;
1863 size = FOURBYTES + len;
1864 ad->AttrLen = cpu_to_be16(size);
1865 ad->AttrType = cpu_to_be16(RHBA_DRIVER_VERSION);
1870 lpfc_fdmi_hba_attr_rom_ver(struct lpfc_vport *vport,
1871 struct lpfc_fdmi_attr_def *ad)
1873 struct lpfc_hba *phba = vport->phba;
1874 struct lpfc_fdmi_attr_entry *ae;
1877 ae = &ad->AttrValue;
1878 memset(ae, 0, sizeof(*ae));
1880 if (phba->sli_rev == LPFC_SLI_REV4)
1881 lpfc_decode_firmware_rev(phba, ae->un.AttrString, 1);
1883 strncpy(ae->un.AttrString, phba->OptionROMVersion,
1884 sizeof(ae->un.AttrString));
1885 len = strnlen(ae->un.AttrString,
1886 sizeof(ae->un.AttrString));
1887 len += (len & 3) ? (4 - (len & 3)) : 4;
1888 size = FOURBYTES + len;
1889 ad->AttrLen = cpu_to_be16(size);
1890 ad->AttrType = cpu_to_be16(RHBA_OPTION_ROM_VERSION);
1895 lpfc_fdmi_hba_attr_fmw_ver(struct lpfc_vport *vport,
1896 struct lpfc_fdmi_attr_def *ad)
1898 struct lpfc_hba *phba = vport->phba;
1899 struct lpfc_fdmi_attr_entry *ae;
1902 ae = &ad->AttrValue;
1903 memset(ae, 0, sizeof(*ae));
1905 lpfc_decode_firmware_rev(phba, ae->un.AttrString, 1);
1906 len = strnlen(ae->un.AttrString,
1907 sizeof(ae->un.AttrString));
1908 len += (len & 3) ? (4 - (len & 3)) : 4;
1909 size = FOURBYTES + len;
1910 ad->AttrLen = cpu_to_be16(size);
1911 ad->AttrType = cpu_to_be16(RHBA_FIRMWARE_VERSION);
1916 lpfc_fdmi_hba_attr_os_ver(struct lpfc_vport *vport,
1917 struct lpfc_fdmi_attr_def *ad)
1919 struct lpfc_fdmi_attr_entry *ae;
1922 ae = &ad->AttrValue;
1923 memset(ae, 0, sizeof(*ae));
1925 snprintf(ae->un.AttrString, sizeof(ae->un.AttrString), "%s %s %s",
1926 init_utsname()->sysname,
1927 init_utsname()->release,
1928 init_utsname()->version);
1930 len = strnlen(ae->un.AttrString, sizeof(ae->un.AttrString));
1931 len += (len & 3) ? (4 - (len & 3)) : 4;
1932 size = FOURBYTES + len;
1933 ad->AttrLen = cpu_to_be16(size);
1934 ad->AttrType = cpu_to_be16(RHBA_OS_NAME_VERSION);
1939 lpfc_fdmi_hba_attr_ct_len(struct lpfc_vport *vport,
1940 struct lpfc_fdmi_attr_def *ad)
1942 struct lpfc_fdmi_attr_entry *ae;
1945 ae = &ad->AttrValue;
1947 ae->un.AttrInt = cpu_to_be32(LPFC_MAX_CT_SIZE);
1948 size = FOURBYTES + sizeof(uint32_t);
1949 ad->AttrLen = cpu_to_be16(size);
1950 ad->AttrType = cpu_to_be16(RHBA_MAX_CT_PAYLOAD_LEN);
1955 lpfc_fdmi_hba_attr_symbolic_name(struct lpfc_vport *vport,
1956 struct lpfc_fdmi_attr_def *ad)
1958 struct lpfc_fdmi_attr_entry *ae;
1961 ae = &ad->AttrValue;
1962 memset(ae, 0, sizeof(*ae));
1964 len = lpfc_vport_symbolic_node_name(vport,
1965 ae->un.AttrString, 256);
1966 len += (len & 3) ? (4 - (len & 3)) : 4;
1967 size = FOURBYTES + len;
1968 ad->AttrLen = cpu_to_be16(size);
1969 ad->AttrType = cpu_to_be16(RHBA_SYM_NODENAME);
1974 lpfc_fdmi_hba_attr_vendor_info(struct lpfc_vport *vport,
1975 struct lpfc_fdmi_attr_def *ad)
1977 struct lpfc_fdmi_attr_entry *ae;
1980 ae = &ad->AttrValue;
1982 /* Nothing is defined for this currently */
1983 ae->un.AttrInt = cpu_to_be32(0);
1984 size = FOURBYTES + sizeof(uint32_t);
1985 ad->AttrLen = cpu_to_be16(size);
1986 ad->AttrType = cpu_to_be16(RHBA_VENDOR_INFO);
1991 lpfc_fdmi_hba_attr_num_ports(struct lpfc_vport *vport,
1992 struct lpfc_fdmi_attr_def *ad)
1994 struct lpfc_fdmi_attr_entry *ae;
1997 ae = &ad->AttrValue;
1999 /* Each driver instance corresponds to a single port */
2000 ae->un.AttrInt = cpu_to_be32(1);
2001 size = FOURBYTES + sizeof(uint32_t);
2002 ad->AttrLen = cpu_to_be16(size);
2003 ad->AttrType = cpu_to_be16(RHBA_NUM_PORTS);
2008 lpfc_fdmi_hba_attr_fabric_wwnn(struct lpfc_vport *vport,
2009 struct lpfc_fdmi_attr_def *ad)
2011 struct lpfc_fdmi_attr_entry *ae;
2014 ae = &ad->AttrValue;
2015 memset(ae, 0, sizeof(*ae));
2017 memcpy(&ae->un.AttrWWN, &vport->fabric_nodename,
2018 sizeof(struct lpfc_name));
2019 size = FOURBYTES + sizeof(struct lpfc_name);
2020 ad->AttrLen = cpu_to_be16(size);
2021 ad->AttrType = cpu_to_be16(RHBA_FABRIC_WWNN);
2026 lpfc_fdmi_hba_attr_bios_ver(struct lpfc_vport *vport,
2027 struct lpfc_fdmi_attr_def *ad)
2029 struct lpfc_hba *phba = vport->phba;
2030 struct lpfc_fdmi_attr_entry *ae;
2033 ae = &ad->AttrValue;
2034 memset(ae, 0, sizeof(*ae));
2036 lpfc_decode_firmware_rev(phba, ae->un.AttrString, 1);
2037 len = strnlen(ae->un.AttrString,
2038 sizeof(ae->un.AttrString));
2039 len += (len & 3) ? (4 - (len & 3)) : 4;
2040 size = FOURBYTES + len;
2041 ad->AttrLen = cpu_to_be16(size);
2042 ad->AttrType = cpu_to_be16(RHBA_BIOS_VERSION);
2047 lpfc_fdmi_hba_attr_bios_state(struct lpfc_vport *vport,
2048 struct lpfc_fdmi_attr_def *ad)
2050 struct lpfc_fdmi_attr_entry *ae;
2053 ae = &ad->AttrValue;
2055 /* Driver doesn't have access to this information */
2056 ae->un.AttrInt = cpu_to_be32(0);
2057 size = FOURBYTES + sizeof(uint32_t);
2058 ad->AttrLen = cpu_to_be16(size);
2059 ad->AttrType = cpu_to_be16(RHBA_BIOS_STATE);
2064 lpfc_fdmi_hba_attr_vendor_id(struct lpfc_vport *vport,
2065 struct lpfc_fdmi_attr_def *ad)
2067 struct lpfc_fdmi_attr_entry *ae;
2070 ae = &ad->AttrValue;
2071 memset(ae, 0, sizeof(*ae));
2073 strncpy(ae->un.AttrString, "EMULEX",
2074 sizeof(ae->un.AttrString));
2075 len = strnlen(ae->un.AttrString,
2076 sizeof(ae->un.AttrString));
2077 len += (len & 3) ? (4 - (len & 3)) : 4;
2078 size = FOURBYTES + len;
2079 ad->AttrLen = cpu_to_be16(size);
2080 ad->AttrType = cpu_to_be16(RHBA_VENDOR_ID);
2084 /* Routines for all individual PORT attributes */
2086 lpfc_fdmi_port_attr_fc4type(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 ae->un.AttrTypes[3] = 0x02; /* Type 0x1 - ELS */
2096 ae->un.AttrTypes[2] = 0x01; /* Type 0x8 - FCP */
2097 if (vport->nvmei_support || vport->phba->nvmet_support)
2098 ae->un.AttrTypes[6] = 0x01; /* Type 0x28 - NVME */
2099 ae->un.AttrTypes[7] = 0x01; /* Type 0x20 - CT */
2100 size = FOURBYTES + 32;
2101 ad->AttrLen = cpu_to_be16(size);
2102 ad->AttrType = cpu_to_be16(RPRT_SUPPORTED_FC4_TYPES);
2107 lpfc_fdmi_port_attr_support_speed(struct lpfc_vport *vport,
2108 struct lpfc_fdmi_attr_def *ad)
2110 struct lpfc_hba *phba = vport->phba;
2111 struct lpfc_fdmi_attr_entry *ae;
2114 ae = &ad->AttrValue;
2117 if (!(phba->hba_flag & HBA_FCOE_MODE)) {
2118 if (phba->lmt & LMT_32Gb)
2119 ae->un.AttrInt |= HBA_PORTSPEED_32GFC;
2120 if (phba->lmt & LMT_16Gb)
2121 ae->un.AttrInt |= HBA_PORTSPEED_16GFC;
2122 if (phba->lmt & LMT_10Gb)
2123 ae->un.AttrInt |= HBA_PORTSPEED_10GFC;
2124 if (phba->lmt & LMT_8Gb)
2125 ae->un.AttrInt |= HBA_PORTSPEED_8GFC;
2126 if (phba->lmt & LMT_4Gb)
2127 ae->un.AttrInt |= HBA_PORTSPEED_4GFC;
2128 if (phba->lmt & LMT_2Gb)
2129 ae->un.AttrInt |= HBA_PORTSPEED_2GFC;
2130 if (phba->lmt & LMT_1Gb)
2131 ae->un.AttrInt |= HBA_PORTSPEED_1GFC;
2133 /* FCoE links support only one speed */
2134 switch (phba->fc_linkspeed) {
2135 case LPFC_ASYNC_LINK_SPEED_10GBPS:
2136 ae->un.AttrInt = HBA_PORTSPEED_10GE;
2138 case LPFC_ASYNC_LINK_SPEED_25GBPS:
2139 ae->un.AttrInt = HBA_PORTSPEED_25GE;
2141 case LPFC_ASYNC_LINK_SPEED_40GBPS:
2142 ae->un.AttrInt = HBA_PORTSPEED_40GE;
2144 case LPFC_ASYNC_LINK_SPEED_100GBPS:
2145 ae->un.AttrInt = HBA_PORTSPEED_100GE;
2149 ae->un.AttrInt = cpu_to_be32(ae->un.AttrInt);
2150 size = FOURBYTES + sizeof(uint32_t);
2151 ad->AttrLen = cpu_to_be16(size);
2152 ad->AttrType = cpu_to_be16(RPRT_SUPPORTED_SPEED);
2157 lpfc_fdmi_port_attr_speed(struct lpfc_vport *vport,
2158 struct lpfc_fdmi_attr_def *ad)
2160 struct lpfc_hba *phba = vport->phba;
2161 struct lpfc_fdmi_attr_entry *ae;
2164 ae = &ad->AttrValue;
2166 if (!(phba->hba_flag & HBA_FCOE_MODE)) {
2167 switch (phba->fc_linkspeed) {
2168 case LPFC_LINK_SPEED_1GHZ:
2169 ae->un.AttrInt = HBA_PORTSPEED_1GFC;
2171 case LPFC_LINK_SPEED_2GHZ:
2172 ae->un.AttrInt = HBA_PORTSPEED_2GFC;
2174 case LPFC_LINK_SPEED_4GHZ:
2175 ae->un.AttrInt = HBA_PORTSPEED_4GFC;
2177 case LPFC_LINK_SPEED_8GHZ:
2178 ae->un.AttrInt = HBA_PORTSPEED_8GFC;
2180 case LPFC_LINK_SPEED_10GHZ:
2181 ae->un.AttrInt = HBA_PORTSPEED_10GFC;
2183 case LPFC_LINK_SPEED_16GHZ:
2184 ae->un.AttrInt = HBA_PORTSPEED_16GFC;
2186 case LPFC_LINK_SPEED_32GHZ:
2187 ae->un.AttrInt = HBA_PORTSPEED_32GFC;
2190 ae->un.AttrInt = HBA_PORTSPEED_UNKNOWN;
2194 switch (phba->fc_linkspeed) {
2195 case LPFC_ASYNC_LINK_SPEED_10GBPS:
2196 ae->un.AttrInt = HBA_PORTSPEED_10GE;
2198 case LPFC_ASYNC_LINK_SPEED_25GBPS:
2199 ae->un.AttrInt = HBA_PORTSPEED_25GE;
2201 case LPFC_ASYNC_LINK_SPEED_40GBPS:
2202 ae->un.AttrInt = HBA_PORTSPEED_40GE;
2204 case LPFC_ASYNC_LINK_SPEED_100GBPS:
2205 ae->un.AttrInt = HBA_PORTSPEED_100GE;
2208 ae->un.AttrInt = HBA_PORTSPEED_UNKNOWN;
2213 ae->un.AttrInt = cpu_to_be32(ae->un.AttrInt);
2214 size = FOURBYTES + sizeof(uint32_t);
2215 ad->AttrLen = cpu_to_be16(size);
2216 ad->AttrType = cpu_to_be16(RPRT_PORT_SPEED);
2221 lpfc_fdmi_port_attr_max_frame(struct lpfc_vport *vport,
2222 struct lpfc_fdmi_attr_def *ad)
2224 struct serv_parm *hsp;
2225 struct lpfc_fdmi_attr_entry *ae;
2228 ae = &ad->AttrValue;
2230 hsp = (struct serv_parm *)&vport->fc_sparam;
2231 ae->un.AttrInt = (((uint32_t) hsp->cmn.bbRcvSizeMsb) << 8) |
2232 (uint32_t) hsp->cmn.bbRcvSizeLsb;
2233 ae->un.AttrInt = cpu_to_be32(ae->un.AttrInt);
2234 size = FOURBYTES + sizeof(uint32_t);
2235 ad->AttrLen = cpu_to_be16(size);
2236 ad->AttrType = cpu_to_be16(RPRT_MAX_FRAME_SIZE);
2241 lpfc_fdmi_port_attr_os_devname(struct lpfc_vport *vport,
2242 struct lpfc_fdmi_attr_def *ad)
2244 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2245 struct lpfc_fdmi_attr_entry *ae;
2248 ae = &ad->AttrValue;
2249 memset(ae, 0, sizeof(*ae));
2251 snprintf(ae->un.AttrString, sizeof(ae->un.AttrString),
2252 "/sys/class/scsi_host/host%d", shost->host_no);
2253 len = strnlen((char *)ae->un.AttrString,
2254 sizeof(ae->un.AttrString));
2255 len += (len & 3) ? (4 - (len & 3)) : 4;
2256 size = FOURBYTES + len;
2257 ad->AttrLen = cpu_to_be16(size);
2258 ad->AttrType = cpu_to_be16(RPRT_OS_DEVICE_NAME);
2263 lpfc_fdmi_port_attr_host_name(struct lpfc_vport *vport,
2264 struct lpfc_fdmi_attr_def *ad)
2266 struct lpfc_fdmi_attr_entry *ae;
2269 ae = &ad->AttrValue;
2270 memset(ae, 0, sizeof(*ae));
2272 snprintf(ae->un.AttrString, sizeof(ae->un.AttrString), "%s",
2273 init_utsname()->nodename);
2275 len = strnlen(ae->un.AttrString, sizeof(ae->un.AttrString));
2276 len += (len & 3) ? (4 - (len & 3)) : 4;
2277 size = FOURBYTES + len;
2278 ad->AttrLen = cpu_to_be16(size);
2279 ad->AttrType = cpu_to_be16(RPRT_HOST_NAME);
2284 lpfc_fdmi_port_attr_wwnn(struct lpfc_vport *vport,
2285 struct lpfc_fdmi_attr_def *ad)
2287 struct lpfc_fdmi_attr_entry *ae;
2290 ae = &ad->AttrValue;
2291 memset(ae, 0, sizeof(*ae));
2293 memcpy(&ae->un.AttrWWN, &vport->fc_sparam.nodeName,
2294 sizeof(struct lpfc_name));
2295 size = FOURBYTES + sizeof(struct lpfc_name);
2296 ad->AttrLen = cpu_to_be16(size);
2297 ad->AttrType = cpu_to_be16(RPRT_NODENAME);
2302 lpfc_fdmi_port_attr_wwpn(struct lpfc_vport *vport,
2303 struct lpfc_fdmi_attr_def *ad)
2305 struct lpfc_fdmi_attr_entry *ae;
2308 ae = &ad->AttrValue;
2309 memset(ae, 0, sizeof(*ae));
2311 memcpy(&ae->un.AttrWWN, &vport->fc_sparam.portName,
2312 sizeof(struct lpfc_name));
2313 size = FOURBYTES + sizeof(struct lpfc_name);
2314 ad->AttrLen = cpu_to_be16(size);
2315 ad->AttrType = cpu_to_be16(RPRT_PORTNAME);
2320 lpfc_fdmi_port_attr_symbolic_name(struct lpfc_vport *vport,
2321 struct lpfc_fdmi_attr_def *ad)
2323 struct lpfc_fdmi_attr_entry *ae;
2326 ae = &ad->AttrValue;
2327 memset(ae, 0, sizeof(*ae));
2329 len = lpfc_vport_symbolic_port_name(vport, ae->un.AttrString, 256);
2330 len += (len & 3) ? (4 - (len & 3)) : 4;
2331 size = FOURBYTES + len;
2332 ad->AttrLen = cpu_to_be16(size);
2333 ad->AttrType = cpu_to_be16(RPRT_SYM_PORTNAME);
2338 lpfc_fdmi_port_attr_port_type(struct lpfc_vport *vport,
2339 struct lpfc_fdmi_attr_def *ad)
2341 struct lpfc_hba *phba = vport->phba;
2342 struct lpfc_fdmi_attr_entry *ae;
2345 ae = &ad->AttrValue;
2346 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP)
2347 ae->un.AttrInt = cpu_to_be32(LPFC_FDMI_PORTTYPE_NLPORT);
2349 ae->un.AttrInt = cpu_to_be32(LPFC_FDMI_PORTTYPE_NPORT);
2350 size = FOURBYTES + sizeof(uint32_t);
2351 ad->AttrLen = cpu_to_be16(size);
2352 ad->AttrType = cpu_to_be16(RPRT_PORT_TYPE);
2357 lpfc_fdmi_port_attr_class(struct lpfc_vport *vport,
2358 struct lpfc_fdmi_attr_def *ad)
2360 struct lpfc_fdmi_attr_entry *ae;
2363 ae = &ad->AttrValue;
2364 ae->un.AttrInt = cpu_to_be32(FC_COS_CLASS2 | FC_COS_CLASS3);
2365 size = FOURBYTES + sizeof(uint32_t);
2366 ad->AttrLen = cpu_to_be16(size);
2367 ad->AttrType = cpu_to_be16(RPRT_SUPPORTED_CLASS);
2372 lpfc_fdmi_port_attr_fabric_wwpn(struct lpfc_vport *vport,
2373 struct lpfc_fdmi_attr_def *ad)
2375 struct lpfc_fdmi_attr_entry *ae;
2378 ae = &ad->AttrValue;
2379 memset(ae, 0, sizeof(*ae));
2381 memcpy(&ae->un.AttrWWN, &vport->fabric_portname,
2382 sizeof(struct lpfc_name));
2383 size = FOURBYTES + sizeof(struct lpfc_name);
2384 ad->AttrLen = cpu_to_be16(size);
2385 ad->AttrType = cpu_to_be16(RPRT_FABRICNAME);
2390 lpfc_fdmi_port_attr_active_fc4type(struct lpfc_vport *vport,
2391 struct lpfc_fdmi_attr_def *ad)
2393 struct lpfc_fdmi_attr_entry *ae;
2396 ae = &ad->AttrValue;
2397 memset(ae, 0, sizeof(*ae));
2399 ae->un.AttrTypes[3] = 0x02; /* Type 0x1 - ELS */
2400 ae->un.AttrTypes[2] = 0x01; /* Type 0x8 - FCP */
2401 if (vport->phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)
2402 ae->un.AttrTypes[6] = 0x1; /* Type 0x28 - NVME */
2403 ae->un.AttrTypes[7] = 0x01; /* Type 0x20 - CT */
2404 size = FOURBYTES + 32;
2405 ad->AttrLen = cpu_to_be16(size);
2406 ad->AttrType = cpu_to_be16(RPRT_ACTIVE_FC4_TYPES);
2411 lpfc_fdmi_port_attr_port_state(struct lpfc_vport *vport,
2412 struct lpfc_fdmi_attr_def *ad)
2414 struct lpfc_fdmi_attr_entry *ae;
2417 ae = &ad->AttrValue;
2418 /* Link Up - operational */
2419 ae->un.AttrInt = cpu_to_be32(LPFC_FDMI_PORTSTATE_ONLINE);
2420 size = FOURBYTES + sizeof(uint32_t);
2421 ad->AttrLen = cpu_to_be16(size);
2422 ad->AttrType = cpu_to_be16(RPRT_PORT_STATE);
2427 lpfc_fdmi_port_attr_num_disc(struct lpfc_vport *vport,
2428 struct lpfc_fdmi_attr_def *ad)
2430 struct lpfc_fdmi_attr_entry *ae;
2433 ae = &ad->AttrValue;
2434 vport->fdmi_num_disc = lpfc_find_map_node(vport);
2435 ae->un.AttrInt = cpu_to_be32(vport->fdmi_num_disc);
2436 size = FOURBYTES + sizeof(uint32_t);
2437 ad->AttrLen = cpu_to_be16(size);
2438 ad->AttrType = cpu_to_be16(RPRT_DISC_PORT);
2443 lpfc_fdmi_port_attr_nportid(struct lpfc_vport *vport,
2444 struct lpfc_fdmi_attr_def *ad)
2446 struct lpfc_fdmi_attr_entry *ae;
2449 ae = &ad->AttrValue;
2450 ae->un.AttrInt = cpu_to_be32(vport->fc_myDID);
2451 size = FOURBYTES + sizeof(uint32_t);
2452 ad->AttrLen = cpu_to_be16(size);
2453 ad->AttrType = cpu_to_be16(RPRT_PORT_ID);
2458 lpfc_fdmi_smart_attr_service(struct lpfc_vport *vport,
2459 struct lpfc_fdmi_attr_def *ad)
2461 struct lpfc_fdmi_attr_entry *ae;
2464 ae = &ad->AttrValue;
2465 memset(ae, 0, sizeof(*ae));
2467 strncpy(ae->un.AttrString, "Smart SAN Initiator",
2468 sizeof(ae->un.AttrString));
2469 len = strnlen(ae->un.AttrString,
2470 sizeof(ae->un.AttrString));
2471 len += (len & 3) ? (4 - (len & 3)) : 4;
2472 size = FOURBYTES + len;
2473 ad->AttrLen = cpu_to_be16(size);
2474 ad->AttrType = cpu_to_be16(RPRT_SMART_SERVICE);
2479 lpfc_fdmi_smart_attr_guid(struct lpfc_vport *vport,
2480 struct lpfc_fdmi_attr_def *ad)
2482 struct lpfc_fdmi_attr_entry *ae;
2485 ae = &ad->AttrValue;
2486 memset(ae, 0, sizeof(*ae));
2488 memcpy(&ae->un.AttrString, &vport->fc_sparam.nodeName,
2489 sizeof(struct lpfc_name));
2490 memcpy((((uint8_t *)&ae->un.AttrString) +
2491 sizeof(struct lpfc_name)),
2492 &vport->fc_sparam.portName, sizeof(struct lpfc_name));
2493 size = FOURBYTES + (2 * sizeof(struct lpfc_name));
2494 ad->AttrLen = cpu_to_be16(size);
2495 ad->AttrType = cpu_to_be16(RPRT_SMART_GUID);
2500 lpfc_fdmi_smart_attr_version(struct lpfc_vport *vport,
2501 struct lpfc_fdmi_attr_def *ad)
2503 struct lpfc_fdmi_attr_entry *ae;
2506 ae = &ad->AttrValue;
2507 memset(ae, 0, sizeof(*ae));
2509 strncpy(ae->un.AttrString, "Smart SAN Version 2.0",
2510 sizeof(ae->un.AttrString));
2511 len = strnlen(ae->un.AttrString,
2512 sizeof(ae->un.AttrString));
2513 len += (len & 3) ? (4 - (len & 3)) : 4;
2514 size = FOURBYTES + len;
2515 ad->AttrLen = cpu_to_be16(size);
2516 ad->AttrType = cpu_to_be16(RPRT_SMART_VERSION);
2521 lpfc_fdmi_smart_attr_model(struct lpfc_vport *vport,
2522 struct lpfc_fdmi_attr_def *ad)
2524 struct lpfc_hba *phba = vport->phba;
2525 struct lpfc_fdmi_attr_entry *ae;
2528 ae = &ad->AttrValue;
2529 memset(ae, 0, sizeof(*ae));
2531 strncpy(ae->un.AttrString, phba->ModelName,
2532 sizeof(ae->un.AttrString));
2533 len = strnlen(ae->un.AttrString, sizeof(ae->un.AttrString));
2534 len += (len & 3) ? (4 - (len & 3)) : 4;
2535 size = FOURBYTES + len;
2536 ad->AttrLen = cpu_to_be16(size);
2537 ad->AttrType = cpu_to_be16(RPRT_SMART_MODEL);
2542 lpfc_fdmi_smart_attr_port_info(struct lpfc_vport *vport,
2543 struct lpfc_fdmi_attr_def *ad)
2545 struct lpfc_fdmi_attr_entry *ae;
2548 ae = &ad->AttrValue;
2550 /* SRIOV (type 3) is not supported */
2552 ae->un.AttrInt = cpu_to_be32(2); /* NPIV */
2554 ae->un.AttrInt = cpu_to_be32(1); /* Physical */
2555 size = FOURBYTES + sizeof(uint32_t);
2556 ad->AttrLen = cpu_to_be16(size);
2557 ad->AttrType = cpu_to_be16(RPRT_SMART_PORT_INFO);
2562 lpfc_fdmi_smart_attr_qos(struct lpfc_vport *vport,
2563 struct lpfc_fdmi_attr_def *ad)
2565 struct lpfc_fdmi_attr_entry *ae;
2568 ae = &ad->AttrValue;
2569 ae->un.AttrInt = cpu_to_be32(0);
2570 size = FOURBYTES + sizeof(uint32_t);
2571 ad->AttrLen = cpu_to_be16(size);
2572 ad->AttrType = cpu_to_be16(RPRT_SMART_QOS);
2577 lpfc_fdmi_smart_attr_security(struct lpfc_vport *vport,
2578 struct lpfc_fdmi_attr_def *ad)
2580 struct lpfc_fdmi_attr_entry *ae;
2583 ae = &ad->AttrValue;
2584 ae->un.AttrInt = cpu_to_be32(1);
2585 size = FOURBYTES + sizeof(uint32_t);
2586 ad->AttrLen = cpu_to_be16(size);
2587 ad->AttrType = cpu_to_be16(RPRT_SMART_SECURITY);
2591 /* RHBA attribute jump table */
2592 int (*lpfc_fdmi_hba_action[])
2593 (struct lpfc_vport *vport, struct lpfc_fdmi_attr_def *ad) = {
2594 /* Action routine Mask bit Attribute type */
2595 lpfc_fdmi_hba_attr_wwnn, /* bit0 RHBA_NODENAME */
2596 lpfc_fdmi_hba_attr_manufacturer, /* bit1 RHBA_MANUFACTURER */
2597 lpfc_fdmi_hba_attr_sn, /* bit2 RHBA_SERIAL_NUMBER */
2598 lpfc_fdmi_hba_attr_model, /* bit3 RHBA_MODEL */
2599 lpfc_fdmi_hba_attr_description, /* bit4 RHBA_MODEL_DESCRIPTION */
2600 lpfc_fdmi_hba_attr_hdw_ver, /* bit5 RHBA_HARDWARE_VERSION */
2601 lpfc_fdmi_hba_attr_drvr_ver, /* bit6 RHBA_DRIVER_VERSION */
2602 lpfc_fdmi_hba_attr_rom_ver, /* bit7 RHBA_OPTION_ROM_VERSION */
2603 lpfc_fdmi_hba_attr_fmw_ver, /* bit8 RHBA_FIRMWARE_VERSION */
2604 lpfc_fdmi_hba_attr_os_ver, /* bit9 RHBA_OS_NAME_VERSION */
2605 lpfc_fdmi_hba_attr_ct_len, /* bit10 RHBA_MAX_CT_PAYLOAD_LEN */
2606 lpfc_fdmi_hba_attr_symbolic_name, /* bit11 RHBA_SYM_NODENAME */
2607 lpfc_fdmi_hba_attr_vendor_info, /* bit12 RHBA_VENDOR_INFO */
2608 lpfc_fdmi_hba_attr_num_ports, /* bit13 RHBA_NUM_PORTS */
2609 lpfc_fdmi_hba_attr_fabric_wwnn, /* bit14 RHBA_FABRIC_WWNN */
2610 lpfc_fdmi_hba_attr_bios_ver, /* bit15 RHBA_BIOS_VERSION */
2611 lpfc_fdmi_hba_attr_bios_state, /* bit16 RHBA_BIOS_STATE */
2612 lpfc_fdmi_hba_attr_vendor_id, /* bit17 RHBA_VENDOR_ID */
2615 /* RPA / RPRT attribute jump table */
2616 int (*lpfc_fdmi_port_action[])
2617 (struct lpfc_vport *vport, struct lpfc_fdmi_attr_def *ad) = {
2618 /* Action routine Mask bit Attribute type */
2619 lpfc_fdmi_port_attr_fc4type, /* bit0 RPRT_SUPPORT_FC4_TYPES */
2620 lpfc_fdmi_port_attr_support_speed, /* bit1 RPRT_SUPPORTED_SPEED */
2621 lpfc_fdmi_port_attr_speed, /* bit2 RPRT_PORT_SPEED */
2622 lpfc_fdmi_port_attr_max_frame, /* bit3 RPRT_MAX_FRAME_SIZE */
2623 lpfc_fdmi_port_attr_os_devname, /* bit4 RPRT_OS_DEVICE_NAME */
2624 lpfc_fdmi_port_attr_host_name, /* bit5 RPRT_HOST_NAME */
2625 lpfc_fdmi_port_attr_wwnn, /* bit6 RPRT_NODENAME */
2626 lpfc_fdmi_port_attr_wwpn, /* bit7 RPRT_PORTNAME */
2627 lpfc_fdmi_port_attr_symbolic_name, /* bit8 RPRT_SYM_PORTNAME */
2628 lpfc_fdmi_port_attr_port_type, /* bit9 RPRT_PORT_TYPE */
2629 lpfc_fdmi_port_attr_class, /* bit10 RPRT_SUPPORTED_CLASS */
2630 lpfc_fdmi_port_attr_fabric_wwpn, /* bit11 RPRT_FABRICNAME */
2631 lpfc_fdmi_port_attr_active_fc4type, /* bit12 RPRT_ACTIVE_FC4_TYPES */
2632 lpfc_fdmi_port_attr_port_state, /* bit13 RPRT_PORT_STATE */
2633 lpfc_fdmi_port_attr_num_disc, /* bit14 RPRT_DISC_PORT */
2634 lpfc_fdmi_port_attr_nportid, /* bit15 RPRT_PORT_ID */
2635 lpfc_fdmi_smart_attr_service, /* bit16 RPRT_SMART_SERVICE */
2636 lpfc_fdmi_smart_attr_guid, /* bit17 RPRT_SMART_GUID */
2637 lpfc_fdmi_smart_attr_version, /* bit18 RPRT_SMART_VERSION */
2638 lpfc_fdmi_smart_attr_model, /* bit19 RPRT_SMART_MODEL */
2639 lpfc_fdmi_smart_attr_port_info, /* bit20 RPRT_SMART_PORT_INFO */
2640 lpfc_fdmi_smart_attr_qos, /* bit21 RPRT_SMART_QOS */
2641 lpfc_fdmi_smart_attr_security, /* bit22 RPRT_SMART_SECURITY */
2645 * lpfc_fdmi_cmd - Build and send a FDMI cmd to the specified NPort
2646 * @vport: pointer to a host virtual N_Port data structure.
2647 * @ndlp: ndlp to send FDMI cmd to (if NULL use FDMI_DID)
2648 * cmdcode: FDMI command to send
2649 * mask: Mask of HBA or PORT Attributes to send
2651 * Builds and sends a FDMI command using the CT subsystem.
2654 lpfc_fdmi_cmd(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2655 int cmdcode, uint32_t new_mask)
2657 struct lpfc_hba *phba = vport->phba;
2658 struct lpfc_dmabuf *mp, *bmp;
2659 struct lpfc_sli_ct_request *CtReq;
2660 struct ulp_bde64 *bpl;
2665 struct lpfc_fdmi_reg_hba *rh;
2666 struct lpfc_fdmi_port_entry *pe;
2667 struct lpfc_fdmi_reg_portattr *pab = NULL;
2668 struct lpfc_fdmi_attr_block *ab = NULL;
2669 int (*func)(struct lpfc_vport *vport, struct lpfc_fdmi_attr_def *ad);
2670 void (*cmpl)(struct lpfc_hba *, struct lpfc_iocbq *,
2671 struct lpfc_iocbq *);
2673 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
2676 cmpl = lpfc_cmpl_ct_disc_fdmi; /* called from discovery */
2678 /* fill in BDEs for command */
2679 /* Allocate buffer for command payload */
2680 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
2684 mp->virt = lpfc_mbuf_alloc(phba, 0, &(mp->phys));
2686 goto fdmi_cmd_free_mp;
2688 /* Allocate buffer for Buffer ptr list */
2689 bmp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
2691 goto fdmi_cmd_free_mpvirt;
2693 bmp->virt = lpfc_mbuf_alloc(phba, 0, &(bmp->phys));
2695 goto fdmi_cmd_free_bmp;
2697 INIT_LIST_HEAD(&mp->list);
2698 INIT_LIST_HEAD(&bmp->list);
2701 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2702 "0218 FDMI Request Data: x%x x%x x%x\n",
2703 vport->fc_flag, vport->port_state, cmdcode);
2704 CtReq = (struct lpfc_sli_ct_request *)mp->virt;
2706 /* First populate the CT_IU preamble */
2707 memset(CtReq, 0, sizeof(struct lpfc_sli_ct_request));
2708 CtReq->RevisionId.bits.Revision = SLI_CT_REVISION;
2709 CtReq->RevisionId.bits.InId = 0;
2711 CtReq->FsType = SLI_CT_MANAGEMENT_SERVICE;
2712 CtReq->FsSubType = SLI_CT_FDMI_Subtypes;
2714 CtReq->CommandResponse.bits.CmdRsp = cpu_to_be16(cmdcode);
2715 rsp_size = LPFC_BPL_SIZE;
2718 /* Next fill in the specific FDMI cmd information */
2722 rh = (struct lpfc_fdmi_reg_hba *)&CtReq->un.PortID;
2723 /* HBA Identifier */
2724 memcpy(&rh->hi.PortName, &phba->pport->fc_sparam.portName,
2725 sizeof(struct lpfc_name));
2727 if (cmdcode == SLI_MGMT_RHBA) {
2728 /* Registered Port List */
2729 /* One entry (port) per adapter */
2730 rh->rpl.EntryCnt = cpu_to_be32(1);
2731 memcpy(&rh->rpl.pe.PortName,
2732 &phba->pport->fc_sparam.portName,
2733 sizeof(struct lpfc_name));
2735 /* point to the HBA attribute block */
2736 size = 2 * sizeof(struct lpfc_name) +
2739 size = sizeof(struct lpfc_name);
2741 ab = (struct lpfc_fdmi_attr_block *)((uint8_t *)rh + size);
2748 mask = vport->fdmi_hba_mask;
2750 /* Mask will dictate what attributes to build in the request */
2753 func = lpfc_fdmi_hba_action[bit_pos];
2755 (struct lpfc_fdmi_attr_def *)
2756 ((uint8_t *)rh + size));
2759 (LPFC_BPL_SIZE - LPFC_CT_PREAMBLE))
2766 ab->EntryCnt = cpu_to_be32(ab->EntryCnt);
2768 size = GID_REQUEST_SZ - 4 + size;
2773 pab = (struct lpfc_fdmi_reg_portattr *)&CtReq->un.PortID;
2774 if (cmdcode == SLI_MGMT_RPRT) {
2775 rh = (struct lpfc_fdmi_reg_hba *)pab;
2776 /* HBA Identifier */
2777 memcpy(&rh->hi.PortName,
2778 &phba->pport->fc_sparam.portName,
2779 sizeof(struct lpfc_name));
2780 pab = (struct lpfc_fdmi_reg_portattr *)
2781 ((uint8_t *)pab + sizeof(struct lpfc_name));
2784 memcpy((uint8_t *)&pab->PortName,
2785 (uint8_t *)&vport->fc_sparam.portName,
2786 sizeof(struct lpfc_name));
2787 size += sizeof(struct lpfc_name) + FOURBYTES;
2788 pab->ab.EntryCnt = 0;
2793 mask = vport->fdmi_port_mask;
2795 /* Mask will dictate what attributes to build in the request */
2798 func = lpfc_fdmi_port_action[bit_pos];
2800 (struct lpfc_fdmi_attr_def *)
2801 ((uint8_t *)pab + size));
2804 (LPFC_BPL_SIZE - LPFC_CT_PREAMBLE))
2811 pab->ab.EntryCnt = cpu_to_be32(pab->ab.EntryCnt);
2813 if (cmdcode == SLI_MGMT_RPRT)
2814 size += sizeof(struct lpfc_name);
2815 size = GID_REQUEST_SZ - 4 + size;
2820 rsp_size = FC_MAX_NS_RSP;
2823 pe = (struct lpfc_fdmi_port_entry *)&CtReq->un.PortID;
2824 memcpy((uint8_t *)&pe->PortName,
2825 (uint8_t *)&vport->fc_sparam.portName,
2826 sizeof(struct lpfc_name));
2827 size = GID_REQUEST_SZ - 4 + sizeof(struct lpfc_name);
2832 rsp_size = FC_MAX_NS_RSP;
2835 pe = (struct lpfc_fdmi_port_entry *)&CtReq->un.PortID;
2836 memcpy((uint8_t *)&pe->PortName,
2837 (uint8_t *)&vport->fc_sparam.portName,
2838 sizeof(struct lpfc_name));
2839 size = GID_REQUEST_SZ - 4 + sizeof(struct lpfc_name);
2842 size = GID_REQUEST_SZ - 4;
2845 lpfc_printf_vlog(vport, KERN_WARNING, LOG_DISCOVERY,
2846 "0298 FDMI cmdcode x%x not supported\n",
2848 goto fdmi_cmd_free_bmpvirt;
2850 CtReq->CommandResponse.bits.Size = cpu_to_be16(rsp_size);
2852 bpl = (struct ulp_bde64 *)bmp->virt;
2853 bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys));
2854 bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys));
2855 bpl->tus.f.bdeFlags = 0;
2856 bpl->tus.f.bdeSize = size;
2859 * The lpfc_ct_cmd/lpfc_get_req shall increment ndlp reference count
2860 * to hold ndlp reference for the corresponding callback function.
2862 if (!lpfc_ct_cmd(vport, mp, bmp, ndlp, cmpl, rsp_size, 0))
2866 * Decrement ndlp reference count to release ndlp reference held
2867 * for the failed command's callback function.
2871 fdmi_cmd_free_bmpvirt:
2872 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
2875 fdmi_cmd_free_mpvirt:
2876 lpfc_mbuf_free(phba, mp->virt, mp->phys);
2880 /* Issue FDMI request failed */
2881 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2882 "0244 Issue FDMI request failed Data: x%x\n",
2888 * lpfc_delayed_disc_tmo - Timeout handler for delayed discovery timer.
2889 * @ptr - Context object of the timer.
2891 * This function set the WORKER_DELAYED_DISC_TMO flag and wake up
2892 * the worker thread.
2895 lpfc_delayed_disc_tmo(unsigned long ptr)
2897 struct lpfc_vport *vport = (struct lpfc_vport *)ptr;
2898 struct lpfc_hba *phba = vport->phba;
2899 uint32_t tmo_posted;
2900 unsigned long iflag;
2902 spin_lock_irqsave(&vport->work_port_lock, iflag);
2903 tmo_posted = vport->work_port_events & WORKER_DELAYED_DISC_TMO;
2905 vport->work_port_events |= WORKER_DELAYED_DISC_TMO;
2906 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
2909 lpfc_worker_wake_up(phba);
2914 * lpfc_delayed_disc_timeout_handler - Function called by worker thread to
2915 * handle delayed discovery.
2916 * @vport: pointer to a host virtual N_Port data structure.
2918 * This function start nport discovery of the vport.
2921 lpfc_delayed_disc_timeout_handler(struct lpfc_vport *vport)
2923 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2925 spin_lock_irq(shost->host_lock);
2926 if (!(vport->fc_flag & FC_DISC_DELAYED)) {
2927 spin_unlock_irq(shost->host_lock);
2930 vport->fc_flag &= ~FC_DISC_DELAYED;
2931 spin_unlock_irq(shost->host_lock);
2933 lpfc_do_scr_ns_plogi(vport->phba, vport);
2937 lpfc_decode_firmware_rev(struct lpfc_hba *phba, char *fwrevision, int flag)
2939 struct lpfc_sli *psli = &phba->sli;
2940 lpfc_vpd_t *vp = &phba->vpd;
2941 uint32_t b1, b2, b3, b4, i, rev;
2943 uint32_t *ptr, str[4];
2946 if (phba->sli_rev == LPFC_SLI_REV4)
2947 snprintf(fwrevision, FW_REV_STR_SIZE, "%s", vp->rev.opFwName);
2948 else if (vp->rev.rBit) {
2949 if (psli->sli_flag & LPFC_SLI_ACTIVE)
2950 rev = vp->rev.sli2FwRev;
2952 rev = vp->rev.sli1FwRev;
2954 b1 = (rev & 0x0000f000) >> 12;
2955 b2 = (rev & 0x00000f00) >> 8;
2956 b3 = (rev & 0x000000c0) >> 6;
2957 b4 = (rev & 0x00000030) >> 4;
2976 b4 = (rev & 0x0000000f);
2978 if (psli->sli_flag & LPFC_SLI_ACTIVE)
2979 fwname = vp->rev.sli2FwName;
2981 fwname = vp->rev.sli1FwName;
2983 for (i = 0; i < 16; i++)
2984 if (fwname[i] == 0x20)
2987 ptr = (uint32_t*)fwname;
2989 for (i = 0; i < 3; i++)
2990 str[i] = be32_to_cpu(*ptr++);
2994 sprintf(fwrevision, "%d.%d%d (%s)",
2995 b1, b2, b3, (char *)str);
2997 sprintf(fwrevision, "%d.%d%d", b1,
3001 sprintf(fwrevision, "%d.%d%d%c%d (%s)",
3005 sprintf(fwrevision, "%d.%d%d%c%d",
3009 rev = vp->rev.smFwRev;
3011 b1 = (rev & 0xff000000) >> 24;
3012 b2 = (rev & 0x00f00000) >> 20;
3013 b3 = (rev & 0x000f0000) >> 16;
3014 c = (rev & 0x0000ff00) >> 8;
3015 b4 = (rev & 0x000000ff);
3017 sprintf(fwrevision, "%d.%d%d%c%d", b1, b2, b3, c, b4);