1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2017-2021 Broadcom. All Rights Reserved. The term *
5 * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. *
6 * Copyright (C) 2004-2016 Emulex. All rights reserved. *
7 * EMULEX and SLI are trademarks of Emulex. *
10 * This program is free software; you can redistribute it and/or *
11 * modify it under the terms of version 2 of the GNU General *
12 * Public License as published by the Free Software Foundation. *
13 * This program is distributed in the hope that it will be useful. *
14 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
15 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
16 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
17 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
18 * TO BE LEGALLY INVALID. See the GNU General Public License for *
19 * more details, a copy of which can be found in the file COPYING *
20 * included with this package. *
21 *******************************************************************/
24 * Fibre Channel SCSI LAN Device Driver CT support: FC Generic Services FC-GS
27 #include <linux/blkdev.h>
28 #include <linux/pci.h>
29 #include <linux/interrupt.h>
30 #include <linux/slab.h>
31 #include <linux/utsname.h>
33 #include <scsi/scsi.h>
34 #include <scsi/scsi_device.h>
35 #include <scsi/scsi_host.h>
36 #include <scsi/scsi_transport_fc.h>
37 #include <scsi/fc/fc_fs.h>
42 #include "lpfc_sli4.h"
44 #include "lpfc_disc.h"
46 #include "lpfc_scsi.h"
47 #include "lpfc_logmsg.h"
48 #include "lpfc_crtn.h"
49 #include "lpfc_version.h"
50 #include "lpfc_vport.h"
51 #include "lpfc_debugfs.h"
53 /* FDMI Port Speed definitions - FC-GS-7 */
54 #define HBA_PORTSPEED_1GFC 0x00000001 /* 1G FC */
55 #define HBA_PORTSPEED_2GFC 0x00000002 /* 2G FC */
56 #define HBA_PORTSPEED_4GFC 0x00000008 /* 4G FC */
57 #define HBA_PORTSPEED_10GFC 0x00000004 /* 10G FC */
58 #define HBA_PORTSPEED_8GFC 0x00000010 /* 8G FC */
59 #define HBA_PORTSPEED_16GFC 0x00000020 /* 16G FC */
60 #define HBA_PORTSPEED_32GFC 0x00000040 /* 32G FC */
61 #define HBA_PORTSPEED_20GFC 0x00000080 /* 20G FC */
62 #define HBA_PORTSPEED_40GFC 0x00000100 /* 40G FC */
63 #define HBA_PORTSPEED_128GFC 0x00000200 /* 128G FC */
64 #define HBA_PORTSPEED_64GFC 0x00000400 /* 64G FC */
65 #define HBA_PORTSPEED_256GFC 0x00000800 /* 256G FC */
66 #define HBA_PORTSPEED_UNKNOWN 0x00008000 /* Unknown */
67 #define HBA_PORTSPEED_10GE 0x00010000 /* 10G E */
68 #define HBA_PORTSPEED_40GE 0x00020000 /* 40G E */
69 #define HBA_PORTSPEED_100GE 0x00040000 /* 100G E */
70 #define HBA_PORTSPEED_25GE 0x00080000 /* 25G E */
71 #define HBA_PORTSPEED_50GE 0x00100000 /* 50G E */
72 #define HBA_PORTSPEED_400GE 0x00200000 /* 400G E */
77 static char *lpfc_release_version = LPFC_DRIVER_VERSION;
80 lpfc_ct_ignore_hbq_buffer(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq,
81 struct lpfc_dmabuf *mp, uint32_t size)
84 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
85 "0146 Ignoring unsolicited CT No HBQ "
87 piocbq->iocb.ulpStatus);
89 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
90 "0145 Ignoring unsolicted CT HBQ Size:%d "
92 size, piocbq->iocb.ulpStatus);
96 lpfc_ct_unsol_buffer(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq,
97 struct lpfc_dmabuf *mp, uint32_t size)
99 lpfc_ct_ignore_hbq_buffer(phba, piocbq, mp, size);
103 * lpfc_ct_unsol_cmpl : Completion callback function for unsol ct commands
104 * @phba : pointer to lpfc hba data structure.
105 * @cmdiocb : pointer to lpfc command iocb data structure.
106 * @rspiocb : pointer to lpfc response iocb data structure.
108 * This routine is the callback function for issuing unsol ct reject command.
109 * The memory allocated in the reject command path is freed up here.
112 lpfc_ct_unsol_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
113 struct lpfc_iocbq *rspiocb)
115 struct lpfc_nodelist *ndlp;
116 struct lpfc_dmabuf *mp, *bmp;
118 ndlp = (struct lpfc_nodelist *)cmdiocb->context1;
122 mp = cmdiocb->context2;
123 bmp = cmdiocb->context3;
125 lpfc_mbuf_free(phba, mp->virt, mp->phys);
127 cmdiocb->context2 = NULL;
131 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
133 cmdiocb->context3 = NULL;
136 lpfc_sli_release_iocbq(phba, cmdiocb);
140 * lpfc_ct_reject_event - Issue reject for unhandled CT MIB commands
141 * @ndlp: pointer to a node-list data structure.
142 * @ct_req: pointer to the CT request data structure.
143 * @rx_id: rx_id of the received UNSOL CT command
144 * @ox_id: ox_id of the UNSOL CT command
146 * This routine is invoked by the lpfc_ct_handle_mibreq routine for sending
147 * a reject response. Reject response is sent for the unhandled commands.
150 lpfc_ct_reject_event(struct lpfc_nodelist *ndlp,
151 struct lpfc_sli_ct_request *ct_req,
152 u16 rx_id, u16 ox_id)
154 struct lpfc_vport *vport = ndlp->vport;
155 struct lpfc_hba *phba = vport->phba;
156 struct lpfc_sli_ct_request *ct_rsp;
157 struct lpfc_iocbq *cmdiocbq = NULL;
158 struct lpfc_dmabuf *bmp = NULL;
159 struct lpfc_dmabuf *mp = NULL;
160 struct ulp_bde64 *bpl;
164 /* fill in BDEs for command */
165 mp = kmalloc(sizeof(*mp), GFP_KERNEL);
171 mp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &mp->phys);
177 /* Allocate buffer for Buffer ptr list */
178 bmp = kmalloc(sizeof(*bmp), GFP_KERNEL);
184 bmp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &bmp->phys);
190 INIT_LIST_HEAD(&mp->list);
191 INIT_LIST_HEAD(&bmp->list);
193 bpl = (struct ulp_bde64 *)bmp->virt;
194 memset(bpl, 0, sizeof(struct ulp_bde64));
195 bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys));
196 bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys));
197 bpl->tus.f.bdeFlags = BUFF_TYPE_BLP_64;
198 bpl->tus.f.bdeSize = (LPFC_CT_PREAMBLE - 4);
199 bpl->tus.w = le32_to_cpu(bpl->tus.w);
201 ct_rsp = (struct lpfc_sli_ct_request *)mp->virt;
202 memset(ct_rsp, 0, sizeof(struct lpfc_sli_ct_request));
204 ct_rsp->RevisionId.bits.Revision = SLI_CT_REVISION;
205 ct_rsp->RevisionId.bits.InId = 0;
206 ct_rsp->FsType = ct_req->FsType;
207 ct_rsp->FsSubType = ct_req->FsSubType;
208 ct_rsp->CommandResponse.bits.Size = 0;
209 ct_rsp->CommandResponse.bits.CmdRsp =
210 cpu_to_be16(SLI_CT_RESPONSE_FS_RJT);
211 ct_rsp->ReasonCode = SLI_CT_REQ_NOT_SUPPORTED;
212 ct_rsp->Explanation = SLI_CT_NO_ADDITIONAL_EXPL;
214 cmdiocbq = lpfc_sli_get_iocbq(phba);
217 goto ct_free_bmpvirt;
220 icmd = &cmdiocbq->iocb;
221 icmd->un.genreq64.bdl.ulpIoTag32 = 0;
222 icmd->un.genreq64.bdl.addrHigh = putPaddrHigh(bmp->phys);
223 icmd->un.genreq64.bdl.addrLow = putPaddrLow(bmp->phys);
224 icmd->un.genreq64.bdl.bdeFlags = BUFF_TYPE_BLP_64;
225 icmd->un.genreq64.bdl.bdeSize = sizeof(struct ulp_bde64);
226 icmd->un.genreq64.w5.hcsw.Fctl = (LS | LA);
227 icmd->un.genreq64.w5.hcsw.Dfctl = 0;
228 icmd->un.genreq64.w5.hcsw.Rctl = FC_RCTL_DD_SOL_CTL;
229 icmd->un.genreq64.w5.hcsw.Type = FC_TYPE_CT;
230 icmd->ulpCommand = CMD_XMIT_SEQUENCE64_CX;
231 icmd->ulpBdeCount = 1;
233 icmd->ulpClass = CLASS3;
235 /* Save for completion so we can release these resources */
236 cmdiocbq->context1 = lpfc_nlp_get(ndlp);
237 cmdiocbq->context2 = (uint8_t *)mp;
238 cmdiocbq->context3 = (uint8_t *)bmp;
239 cmdiocbq->iocb_cmpl = lpfc_ct_unsol_cmpl;
240 icmd->ulpContext = rx_id; /* Xri / rx_id */
241 icmd->unsli3.rcvsli3.ox_id = ox_id;
242 icmd->un.ulpWord[3] =
243 phba->sli4_hba.rpi_ids[ndlp->nlp_rpi];
244 icmd->ulpTimeout = (3 * phba->fc_ratov);
247 cmdiocbq->vport = vport;
248 cmdiocbq->context_un.ndlp = NULL;
249 cmdiocbq->drvrTimeout = icmd->ulpTimeout + LPFC_DRVR_TIMEOUT;
251 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, cmdiocbq, 0);
257 lpfc_sli_release_iocbq(phba, cmdiocbq);
259 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
263 lpfc_mbuf_free(phba, mp->virt, mp->phys);
267 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
268 "6440 Unsol CT: Rsp err %d Data: x%x\n",
273 * lpfc_ct_handle_mibreq - Process an unsolicited CT MIB request data buffer
274 * @phba: pointer to lpfc hba data structure.
275 * @ctiocbq: pointer to lpfc CT command iocb data structure.
277 * This routine is used for processing the IOCB associated with a unsolicited
278 * CT MIB request. It first determines whether there is an existing ndlp that
279 * matches the DID from the unsolicited IOCB. If not, it will return.
282 lpfc_ct_handle_mibreq(struct lpfc_hba *phba, struct lpfc_iocbq *ctiocbq)
284 struct lpfc_sli_ct_request *ct_req;
285 struct lpfc_nodelist *ndlp = NULL;
286 struct lpfc_vport *vport = NULL;
287 IOCB_t *icmd = &ctiocbq->iocb;
291 vpi = ctiocbq->iocb.unsli3.rcvsli3.vpi;
292 vport = lpfc_find_vport_by_vpid(phba, vpi);
294 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
295 "6437 Unsol CT: VPORT NULL vpi : x%x\n",
300 did = ctiocbq->iocb.un.rcvels.remoteID;
301 if (icmd->ulpStatus) {
302 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
303 "6438 Unsol CT: status:x%x/x%x did : x%x\n",
304 icmd->ulpStatus, icmd->un.ulpWord[4], did);
308 /* Ignore traffic received during vport shutdown */
309 if (vport->fc_flag & FC_UNLOADING)
312 ndlp = lpfc_findnode_did(vport, did);
314 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
315 "6439 Unsol CT: NDLP Not Found for DID : x%x",
320 ct_req = ((struct lpfc_sli_ct_request *)
321 (((struct lpfc_dmabuf *)ctiocbq->context2)->virt));
323 mi_cmd = ct_req->CommandResponse.bits.CmdRsp;
324 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
325 "6442 : MI Cmd : x%x Not Supported\n", mi_cmd);
326 lpfc_ct_reject_event(ndlp, ct_req,
327 ctiocbq->iocb.ulpContext,
328 ctiocbq->iocb.unsli3.rcvsli3.ox_id);
332 * lpfc_ct_unsol_event - Process an unsolicited event from a ct sli ring
333 * @phba: pointer to lpfc hba data structure.
334 * @pring: pointer to a SLI ring.
335 * @ctiocbq: pointer to lpfc ct iocb data structure.
337 * This routine is used to process an unsolicited event received from a SLI
338 * (Service Level Interface) ring. The actual processing of the data buffer
339 * associated with the unsolicited event is done by invoking appropriate routine
340 * after properly set up the iocb buffer from the SLI ring on which the
341 * unsolicited event was received.
344 lpfc_ct_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
345 struct lpfc_iocbq *ctiocbq)
347 struct lpfc_dmabuf *mp = NULL;
348 IOCB_t *icmd = &ctiocbq->iocb;
350 struct lpfc_iocbq *iocbq;
353 struct list_head head;
354 struct lpfc_sli_ct_request *ct_req;
355 struct lpfc_dmabuf *bdeBuf1 = ctiocbq->context2;
356 struct lpfc_dmabuf *bdeBuf2 = ctiocbq->context3;
358 ctiocbq->context1 = NULL;
359 ctiocbq->context2 = NULL;
360 ctiocbq->context3 = NULL;
362 if (unlikely(icmd->ulpStatus == IOSTAT_NEED_BUFFER)) {
363 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
364 } else if ((icmd->ulpStatus == IOSTAT_LOCAL_REJECT) &&
365 ((icmd->un.ulpWord[4] & IOERR_PARAM_MASK) ==
366 IOERR_RCV_BUFFER_WAITING)) {
367 /* Not enough posted buffers; Try posting more buffers */
368 phba->fc_stat.NoRcvBuf++;
369 if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
370 lpfc_post_buffer(phba, pring, 2);
374 /* If there are no BDEs associated
375 * with this IOCB, there is nothing to do.
377 if (icmd->ulpBdeCount == 0)
380 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
381 ctiocbq->context2 = bdeBuf1;
382 if (icmd->ulpBdeCount == 2)
383 ctiocbq->context3 = bdeBuf2;
385 dma_addr = getPaddr(icmd->un.cont64[0].addrHigh,
386 icmd->un.cont64[0].addrLow);
387 ctiocbq->context2 = lpfc_sli_ringpostbuf_get(phba, pring,
389 if (icmd->ulpBdeCount == 2) {
390 dma_addr = getPaddr(icmd->un.cont64[1].addrHigh,
391 icmd->un.cont64[1].addrLow);
392 ctiocbq->context3 = lpfc_sli_ringpostbuf_get(phba,
398 ct_req = ((struct lpfc_sli_ct_request *)
399 (((struct lpfc_dmabuf *)ctiocbq->context2)->virt));
401 if (ct_req->FsType == SLI_CT_MANAGEMENT_SERVICE &&
402 ct_req->FsSubType == SLI_CT_MIB_Subtypes) {
403 lpfc_ct_handle_mibreq(phba, ctiocbq);
405 if (!lpfc_bsg_ct_unsol_event(phba, pring, ctiocbq))
409 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
410 INIT_LIST_HEAD(&head);
411 list_add_tail(&head, &ctiocbq->list);
412 list_for_each_entry(iocbq, &head, list) {
414 if (icmd->ulpBdeCount == 0)
416 bdeBuf1 = iocbq->context2;
417 iocbq->context2 = NULL;
418 size = icmd->un.cont64[0].tus.f.bdeSize;
419 lpfc_ct_unsol_buffer(phba, ctiocbq, bdeBuf1, size);
420 lpfc_in_buf_free(phba, bdeBuf1);
421 if (icmd->ulpBdeCount == 2) {
422 bdeBuf2 = iocbq->context3;
423 iocbq->context3 = NULL;
424 size = icmd->unsli3.rcvsli3.bde2.tus.f.bdeSize;
425 lpfc_ct_unsol_buffer(phba, ctiocbq, bdeBuf2,
427 lpfc_in_buf_free(phba, bdeBuf2);
432 INIT_LIST_HEAD(&head);
433 list_add_tail(&head, &ctiocbq->list);
434 list_for_each_entry(iocbq, &head, list) {
436 if (icmd->ulpBdeCount == 0)
437 lpfc_ct_unsol_buffer(phba, iocbq, NULL, 0);
438 for (i = 0; i < icmd->ulpBdeCount; i++) {
439 dma_addr = getPaddr(icmd->un.cont64[i].addrHigh,
440 icmd->un.cont64[i].addrLow);
441 mp = lpfc_sli_ringpostbuf_get(phba, pring,
443 size = icmd->un.cont64[i].tus.f.bdeSize;
444 lpfc_ct_unsol_buffer(phba, iocbq, mp, size);
445 lpfc_in_buf_free(phba, mp);
447 lpfc_post_buffer(phba, pring, i);
454 * lpfc_ct_handle_unsol_abort - ct upper level protocol abort handler
455 * @phba: Pointer to HBA context object.
456 * @dmabuf: pointer to a dmabuf that describes the FC sequence
458 * This function serves as the upper level protocol abort handler for CT
461 * Return 1 if abort has been handled, 0 otherwise.
464 lpfc_ct_handle_unsol_abort(struct lpfc_hba *phba, struct hbq_dmabuf *dmabuf)
468 /* CT upper level goes through BSG */
469 handled = lpfc_bsg_ct_unsol_abort(phba, dmabuf);
475 lpfc_free_ct_rsp(struct lpfc_hba *phba, struct lpfc_dmabuf *mlist)
477 struct lpfc_dmabuf *mlast, *next_mlast;
479 list_for_each_entry_safe(mlast, next_mlast, &mlist->list, list) {
480 lpfc_mbuf_free(phba, mlast->virt, mlast->phys);
481 list_del(&mlast->list);
484 lpfc_mbuf_free(phba, mlist->virt, mlist->phys);
489 static struct lpfc_dmabuf *
490 lpfc_alloc_ct_rsp(struct lpfc_hba *phba, int cmdcode, struct ulp_bde64 *bpl,
491 uint32_t size, int *entries)
493 struct lpfc_dmabuf *mlist = NULL;
494 struct lpfc_dmabuf *mp;
497 /* We get chunks of FCELSSIZE */
498 cnt = size > FCELSSIZE ? FCELSSIZE: size;
501 /* Allocate buffer for rsp payload */
502 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
505 lpfc_free_ct_rsp(phba, mlist);
509 INIT_LIST_HEAD(&mp->list);
511 if (cmdcode == be16_to_cpu(SLI_CTNS_GID_FT) ||
512 cmdcode == be16_to_cpu(SLI_CTNS_GFF_ID))
513 mp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(mp->phys));
515 mp->virt = lpfc_mbuf_alloc(phba, 0, &(mp->phys));
520 lpfc_free_ct_rsp(phba, mlist);
524 /* Queue it to a linked list */
528 list_add_tail(&mp->list, &mlist->list);
530 bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64I;
531 /* build buffer ptr list for IOCB */
532 bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys) );
533 bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys) );
534 bpl->tus.f.bdeSize = (uint16_t) cnt;
535 bpl->tus.w = le32_to_cpu(bpl->tus.w);
547 lpfc_ct_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *ctiocb)
549 struct lpfc_dmabuf *buf_ptr;
551 /* I/O job is complete so context is now invalid*/
552 ctiocb->context_un.ndlp = NULL;
553 if (ctiocb->context1) {
554 buf_ptr = (struct lpfc_dmabuf *) ctiocb->context1;
555 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
557 ctiocb->context1 = NULL;
559 if (ctiocb->context2) {
560 lpfc_free_ct_rsp(phba, (struct lpfc_dmabuf *) ctiocb->context2);
561 ctiocb->context2 = NULL;
564 if (ctiocb->context3) {
565 buf_ptr = (struct lpfc_dmabuf *) ctiocb->context3;
566 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
568 ctiocb->context3 = NULL;
570 lpfc_sli_release_iocbq(phba, ctiocb);
575 * lpfc_gen_req - Build and issue a GEN_REQUEST command to the SLI Layer
576 * @vport: pointer to a host virtual N_Port data structure.
577 * @bmp: Pointer to BPL for SLI command
578 * @inp: Pointer to data buffer for response data.
579 * @outp: Pointer to data buffer that hold the CT command.
580 * @cmpl: completion routine to call when command completes
581 * @ndlp: Destination NPort nodelist entry
583 * This function as the final part for issuing a CT command.
586 lpfc_gen_req(struct lpfc_vport *vport, struct lpfc_dmabuf *bmp,
587 struct lpfc_dmabuf *inp, struct lpfc_dmabuf *outp,
588 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
589 struct lpfc_iocbq *),
590 struct lpfc_nodelist *ndlp, uint32_t usr_flg, uint32_t num_entry,
591 uint32_t tmo, uint8_t retry)
593 struct lpfc_hba *phba = vport->phba;
595 struct lpfc_iocbq *geniocb;
598 /* Allocate buffer for command iocb */
599 geniocb = lpfc_sli_get_iocbq(phba);
604 icmd = &geniocb->iocb;
605 icmd->un.genreq64.bdl.ulpIoTag32 = 0;
606 icmd->un.genreq64.bdl.addrHigh = putPaddrHigh(bmp->phys);
607 icmd->un.genreq64.bdl.addrLow = putPaddrLow(bmp->phys);
608 icmd->un.genreq64.bdl.bdeFlags = BUFF_TYPE_BLP_64;
609 icmd->un.genreq64.bdl.bdeSize = (num_entry * sizeof(struct ulp_bde64));
612 geniocb->context3 = NULL;
614 geniocb->context3 = (uint8_t *) bmp;
616 /* Save for completion so we can release these resources */
617 geniocb->context1 = (uint8_t *) inp;
618 geniocb->context2 = (uint8_t *) outp;
620 /* Fill in payload, bp points to frame payload */
621 icmd->ulpCommand = CMD_GEN_REQUEST64_CR;
623 /* Fill in rest of iocb */
624 icmd->un.genreq64.w5.hcsw.Fctl = (SI | LA);
625 icmd->un.genreq64.w5.hcsw.Dfctl = 0;
626 icmd->un.genreq64.w5.hcsw.Rctl = FC_RCTL_DD_UNSOL_CTL;
627 icmd->un.genreq64.w5.hcsw.Type = FC_TYPE_CT;
630 /* FC spec states we need 3 * ratov for CT requests */
631 tmo = (3 * phba->fc_ratov);
633 icmd->ulpTimeout = tmo;
634 icmd->ulpBdeCount = 1;
636 icmd->ulpClass = CLASS3;
637 icmd->ulpContext = ndlp->nlp_rpi;
638 if (phba->sli_rev == LPFC_SLI_REV4)
639 icmd->ulpContext = phba->sli4_hba.rpi_ids[ndlp->nlp_rpi];
641 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
642 /* For GEN_REQUEST64_CR, use the RPI */
647 /* Issue GEN REQ IOCB for NPORT <did> */
648 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
649 "0119 Issue GEN REQ IOCB to NPORT x%x "
651 ndlp->nlp_DID, icmd->ulpIoTag,
653 geniocb->iocb_cmpl = cmpl;
654 geniocb->drvrTimeout = icmd->ulpTimeout + LPFC_DRVR_TIMEOUT;
655 geniocb->vport = vport;
656 geniocb->retry = retry;
657 geniocb->context_un.ndlp = lpfc_nlp_get(ndlp);
658 if (!geniocb->context_un.ndlp)
660 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, geniocb, 0);
662 if (rc == IOCB_ERROR) {
663 geniocb->context_un.ndlp = NULL;
670 lpfc_sli_release_iocbq(phba, geniocb);
675 * lpfc_ct_cmd - Build and issue a CT command
676 * @vport: pointer to a host virtual N_Port data structure.
677 * @inmp: Pointer to data buffer for response data.
678 * @bmp: Pointer to BPL for SLI command
679 * @ndlp: Destination NPort nodelist entry
680 * @cmpl: completion routine to call when command completes
682 * This function is called for issuing a CT command.
685 lpfc_ct_cmd(struct lpfc_vport *vport, struct lpfc_dmabuf *inmp,
686 struct lpfc_dmabuf *bmp, struct lpfc_nodelist *ndlp,
687 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
688 struct lpfc_iocbq *),
689 uint32_t rsp_size, uint8_t retry)
691 struct lpfc_hba *phba = vport->phba;
692 struct ulp_bde64 *bpl = (struct ulp_bde64 *) bmp->virt;
693 struct lpfc_dmabuf *outmp;
695 int cmdcode = ((struct lpfc_sli_ct_request *) inmp->virt)->
696 CommandResponse.bits.CmdRsp;
698 bpl++; /* Skip past ct request */
700 /* Put buffer(s) for ct rsp in bpl */
701 outmp = lpfc_alloc_ct_rsp(phba, cmdcode, bpl, rsp_size, &cnt);
705 * Form the CT IOCB. The total number of BDEs in this IOCB
706 * is the single command plus response count from
710 status = lpfc_gen_req(vport, bmp, inmp, outmp, cmpl, ndlp, 0,
713 lpfc_free_ct_rsp(phba, outmp);
720 lpfc_find_vport_by_did(struct lpfc_hba *phba, uint32_t did) {
721 struct lpfc_vport *vport_curr;
724 spin_lock_irqsave(&phba->port_list_lock, flags);
725 list_for_each_entry(vport_curr, &phba->port_list, listentry) {
726 if ((vport_curr->fc_myDID) && (vport_curr->fc_myDID == did)) {
727 spin_unlock_irqrestore(&phba->port_list_lock, flags);
731 spin_unlock_irqrestore(&phba->port_list_lock, flags);
736 lpfc_prep_node_fc4type(struct lpfc_vport *vport, uint32_t Did, uint8_t fc4_type)
738 struct lpfc_nodelist *ndlp;
740 if ((vport->port_type != LPFC_NPIV_PORT) ||
741 !(vport->ct_flags & FC_CT_RFF_ID) || !vport->cfg_restrict_login) {
743 ndlp = lpfc_setup_disc_node(vport, Did);
746 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
747 "Parse GID_FTrsp: did:x%x flg:x%x x%x",
748 Did, ndlp->nlp_flag, vport->fc_flag);
750 /* By default, the driver expects to support FCP FC4 */
751 if (fc4_type == FC_TYPE_FCP)
752 ndlp->nlp_fc4_type |= NLP_FC4_FCP;
754 if (fc4_type == FC_TYPE_NVME)
755 ndlp->nlp_fc4_type |= NLP_FC4_NVME;
757 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
758 "0238 Process x%06x NameServer Rsp "
759 "Data: x%x x%x x%x x%x x%x\n", Did,
760 ndlp->nlp_flag, ndlp->nlp_fc4_type,
761 ndlp->nlp_state, vport->fc_flag,
762 vport->fc_rscn_id_cnt);
764 /* if ndlp needs to be discovered and prior
765 * state of ndlp hit devloss, change state to
768 if (ndlp->nlp_flag & NLP_NPR_2B_DISC &&
769 ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
770 lpfc_nlp_set_state(vport, ndlp,
774 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
775 "Skip1 GID_FTrsp: did:x%x flg:x%x cnt:%d",
776 Did, vport->fc_flag, vport->fc_rscn_id_cnt);
778 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
779 "0239 Skip x%06x NameServer Rsp "
780 "Data: x%x x%x x%px\n",
782 vport->fc_rscn_id_cnt, ndlp);
785 if (!(vport->fc_flag & FC_RSCN_MODE) ||
786 lpfc_rscn_payload_check(vport, Did)) {
787 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
788 "Query GID_FTrsp: did:x%x flg:x%x cnt:%d",
789 Did, vport->fc_flag, vport->fc_rscn_id_cnt);
792 * This NPortID was previously a FCP/NVMe target,
793 * Don't even bother to send GFF_ID.
795 ndlp = lpfc_findnode_did(vport, Did);
798 (NLP_FCP_TARGET | NLP_NVME_TARGET))) {
799 if (fc4_type == FC_TYPE_FCP)
800 ndlp->nlp_fc4_type |= NLP_FC4_FCP;
801 if (fc4_type == FC_TYPE_NVME)
802 ndlp->nlp_fc4_type |= NLP_FC4_NVME;
803 lpfc_setup_disc_node(vport, Did);
804 } else if (lpfc_ns_cmd(vport, SLI_CTNS_GFF_ID,
806 vport->num_disc_nodes++;
808 lpfc_setup_disc_node(vport, Did);
810 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
811 "Skip2 GID_FTrsp: did:x%x flg:x%x cnt:%d",
812 Did, vport->fc_flag, vport->fc_rscn_id_cnt);
814 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
815 "0245 Skip x%06x NameServer Rsp "
816 "Data: x%x x%x\n", Did,
818 vport->fc_rscn_id_cnt);
824 lpfc_ns_rsp_audit_did(struct lpfc_vport *vport, uint32_t Did, uint8_t fc4_type)
826 struct lpfc_hba *phba = vport->phba;
827 struct lpfc_nodelist *ndlp = NULL;
830 if (phba->cfg_ns_query == LPFC_NS_QUERY_GID_FT)
834 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
835 "6430 Process %s rsp for %08x type %x %s %s\n",
837 (fc4_type == FC_TYPE_FCP) ? "FCP" : " ",
838 (fc4_type == FC_TYPE_NVME) ? "NVME" : " ");
840 * To conserve rpi's, filter out addresses for other
841 * vports on the same physical HBAs.
843 if (Did != vport->fc_myDID &&
844 (!lpfc_find_vport_by_did(phba, Did) ||
845 vport->cfg_peer_port_login)) {
846 if (!phba->nvmet_support) {
847 /* FCPI/NVMEI path. Process Did */
848 lpfc_prep_node_fc4type(vport, Did, fc4_type);
851 /* NVMET path. NVMET only cares about NVMEI nodes. */
852 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
853 if (ndlp->nlp_type != NLP_NVME_INITIATOR ||
854 ndlp->nlp_state != NLP_STE_UNMAPPED_NODE)
856 spin_lock_irq(&ndlp->lock);
857 if (ndlp->nlp_DID == Did)
858 ndlp->nlp_flag &= ~NLP_NVMET_RECOV;
860 ndlp->nlp_flag |= NLP_NVMET_RECOV;
861 spin_unlock_irq(&ndlp->lock);
867 lpfc_ns_rsp(struct lpfc_vport *vport, struct lpfc_dmabuf *mp, uint8_t fc4_type,
870 struct lpfc_sli_ct_request *Response =
871 (struct lpfc_sli_ct_request *) mp->virt;
872 struct lpfc_dmabuf *mlast, *next_mp;
873 uint32_t *ctptr = (uint32_t *) & Response->un.gid.PortType;
874 uint32_t Did, CTentry;
876 struct list_head head;
877 struct lpfc_nodelist *ndlp = NULL;
879 lpfc_set_disctmo(vport);
880 vport->num_disc_nodes = 0;
881 vport->fc_ns_retry = 0;
884 list_add_tail(&head, &mp->list);
885 list_for_each_entry_safe(mp, next_mp, &head, list) {
888 Cnt = Size > FCELSSIZE ? FCELSSIZE : Size;
893 ctptr = (uint32_t *) mlast->virt;
895 Cnt -= 16; /* subtract length of CT header */
897 /* Loop through entire NameServer list of DIDs */
898 while (Cnt >= sizeof(uint32_t)) {
899 /* Get next DID from NameServer List */
901 Did = ((be32_to_cpu(CTentry)) & Mask_DID);
902 lpfc_ns_rsp_audit_did(vport, Did, fc4_type);
903 if (CTentry & (cpu_to_be32(SLI_CT_LAST_ENTRY)))
906 Cnt -= sizeof(uint32_t);
912 /* All GID_FT entries processed. If the driver is running in
913 * in target mode, put impacted nodes into recovery and drop
914 * the RPI to flush outstanding IO.
916 if (vport->phba->nvmet_support) {
917 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
918 if (!(ndlp->nlp_flag & NLP_NVMET_RECOV))
920 lpfc_disc_state_machine(vport, ndlp, NULL,
921 NLP_EVT_DEVICE_RECOVERY);
922 spin_lock_irq(&ndlp->lock);
923 ndlp->nlp_flag &= ~NLP_NVMET_RECOV;
924 spin_unlock_irq(&ndlp->lock);
934 lpfc_cmpl_ct_cmd_gid_ft(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
935 struct lpfc_iocbq *rspiocb)
937 struct lpfc_vport *vport = cmdiocb->vport;
938 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
940 struct lpfc_dmabuf *outp;
941 struct lpfc_dmabuf *inp;
942 struct lpfc_sli_ct_request *CTrsp;
943 struct lpfc_sli_ct_request *CTreq;
944 struct lpfc_nodelist *ndlp;
947 /* First save ndlp, before we overwrite it */
948 ndlp = cmdiocb->context_un.ndlp;
950 /* we pass cmdiocb to state machine which needs rspiocb as well */
951 cmdiocb->context_un.rsp_iocb = rspiocb;
952 inp = (struct lpfc_dmabuf *) cmdiocb->context1;
953 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
954 irsp = &rspiocb->iocb;
956 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
957 "GID_FT cmpl: status:x%x/x%x rtry:%d",
958 irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_ns_retry);
960 /* Don't bother processing response if vport is being torn down. */
961 if (vport->load_flag & FC_UNLOADING) {
962 if (vport->fc_flag & FC_RSCN_MODE)
963 lpfc_els_flush_rscn(vport);
967 if (lpfc_els_chk_latt(vport)) {
968 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
969 "0216 Link event during NS query\n");
970 if (vport->fc_flag & FC_RSCN_MODE)
971 lpfc_els_flush_rscn(vport);
972 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
975 if (lpfc_error_lost_link(irsp)) {
976 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
977 "0226 NS query failed due to link event\n");
978 if (vport->fc_flag & FC_RSCN_MODE)
979 lpfc_els_flush_rscn(vport);
983 spin_lock_irq(shost->host_lock);
984 if (vport->fc_flag & FC_RSCN_DEFERRED) {
985 vport->fc_flag &= ~FC_RSCN_DEFERRED;
986 spin_unlock_irq(shost->host_lock);
988 /* This is a GID_FT completing so the gidft_inp counter was
989 * incremented before the GID_FT was issued to the wire.
991 if (vport->gidft_inp)
995 * Skip processing the NS response
996 * Re-issue the NS cmd
998 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
999 "0151 Process Deferred RSCN Data: x%x x%x\n",
1000 vport->fc_flag, vport->fc_rscn_id_cnt);
1001 lpfc_els_handle_rscn(vport);
1005 spin_unlock_irq(shost->host_lock);
1007 if (irsp->ulpStatus) {
1008 /* Check for retry */
1009 if (vport->fc_ns_retry < LPFC_MAX_NS_RETRY) {
1010 if (irsp->ulpStatus != IOSTAT_LOCAL_REJECT ||
1011 (irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
1013 vport->fc_ns_retry++;
1015 type = lpfc_get_gidft_type(vport, cmdiocb);
1019 /* CT command is being retried */
1020 rc = lpfc_ns_cmd(vport, SLI_CTNS_GID_FT,
1021 vport->fc_ns_retry, type);
1024 else { /* Unable to send NS cmd */
1025 if (vport->gidft_inp)
1029 if (vport->fc_flag & FC_RSCN_MODE)
1030 lpfc_els_flush_rscn(vport);
1031 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
1032 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1033 "0257 GID_FT Query error: 0x%x 0x%x\n",
1034 irsp->ulpStatus, vport->fc_ns_retry);
1036 /* Good status, continue checking */
1037 CTreq = (struct lpfc_sli_ct_request *) inp->virt;
1038 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
1039 if (CTrsp->CommandResponse.bits.CmdRsp ==
1040 cpu_to_be16(SLI_CT_RESPONSE_FS_ACC)) {
1041 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1042 "0208 NameServer Rsp Data: x%x x%x "
1045 CTreq->un.gid.Fc4Type,
1046 vport->num_disc_nodes,
1048 irsp->un.genreq64.bdl.bdeSize);
1052 CTreq->un.gid.Fc4Type,
1053 (uint32_t) (irsp->un.genreq64.bdl.bdeSize));
1054 } else if (CTrsp->CommandResponse.bits.CmdRsp ==
1055 be16_to_cpu(SLI_CT_RESPONSE_FS_RJT)) {
1056 /* NameServer Rsp Error */
1057 if ((CTrsp->ReasonCode == SLI_CT_UNABLE_TO_PERFORM_REQ)
1058 && (CTrsp->Explanation == SLI_CT_NO_FC4_TYPES)) {
1059 lpfc_printf_vlog(vport, KERN_INFO,
1061 "0269 No NameServer Entries "
1062 "Data: x%x x%x x%x x%x\n",
1063 CTrsp->CommandResponse.bits.CmdRsp,
1064 (uint32_t) CTrsp->ReasonCode,
1065 (uint32_t) CTrsp->Explanation,
1068 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
1069 "GID_FT no entry cmd:x%x rsn:x%x exp:x%x",
1070 (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
1071 (uint32_t) CTrsp->ReasonCode,
1072 (uint32_t) CTrsp->Explanation);
1074 lpfc_printf_vlog(vport, KERN_INFO,
1076 "0240 NameServer Rsp Error "
1077 "Data: x%x x%x x%x x%x\n",
1078 CTrsp->CommandResponse.bits.CmdRsp,
1079 (uint32_t) CTrsp->ReasonCode,
1080 (uint32_t) CTrsp->Explanation,
1083 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
1084 "GID_FT rsp err1 cmd:x%x rsn:x%x exp:x%x",
1085 (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
1086 (uint32_t) CTrsp->ReasonCode,
1087 (uint32_t) CTrsp->Explanation);
1092 /* NameServer Rsp Error */
1093 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1094 "0241 NameServer Rsp Error "
1095 "Data: x%x x%x x%x x%x\n",
1096 CTrsp->CommandResponse.bits.CmdRsp,
1097 (uint32_t) CTrsp->ReasonCode,
1098 (uint32_t) CTrsp->Explanation,
1101 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
1102 "GID_FT rsp err2 cmd:x%x rsn:x%x exp:x%x",
1103 (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
1104 (uint32_t) CTrsp->ReasonCode,
1105 (uint32_t) CTrsp->Explanation);
1107 if (vport->gidft_inp)
1111 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1112 "4216 GID_FT cmpl inp %d disc %d\n",
1113 vport->gidft_inp, vport->num_disc_nodes);
1115 /* Link up / RSCN discovery */
1116 if ((vport->num_disc_nodes == 0) &&
1117 (vport->gidft_inp == 0)) {
1119 * The driver has cycled through all Nports in the RSCN payload.
1120 * Complete the handling by cleaning up and marking the
1121 * current driver state.
1123 if (vport->port_state >= LPFC_DISC_AUTH) {
1124 if (vport->fc_flag & FC_RSCN_MODE) {
1125 lpfc_els_flush_rscn(vport);
1126 spin_lock_irq(shost->host_lock);
1127 vport->fc_flag |= FC_RSCN_MODE; /* RSCN still */
1128 spin_unlock_irq(shost->host_lock);
1131 lpfc_els_flush_rscn(vport);
1134 lpfc_disc_start(vport);
1137 lpfc_ct_free_iocb(phba, cmdiocb);
1143 lpfc_cmpl_ct_cmd_gid_pt(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1144 struct lpfc_iocbq *rspiocb)
1146 struct lpfc_vport *vport = cmdiocb->vport;
1147 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1149 struct lpfc_dmabuf *outp;
1150 struct lpfc_dmabuf *inp;
1151 struct lpfc_sli_ct_request *CTrsp;
1152 struct lpfc_sli_ct_request *CTreq;
1153 struct lpfc_nodelist *ndlp;
1156 /* First save ndlp, before we overwrite it */
1157 ndlp = cmdiocb->context_un.ndlp;
1159 /* we pass cmdiocb to state machine which needs rspiocb as well */
1160 cmdiocb->context_un.rsp_iocb = rspiocb;
1161 inp = (struct lpfc_dmabuf *)cmdiocb->context1;
1162 outp = (struct lpfc_dmabuf *)cmdiocb->context2;
1163 irsp = &rspiocb->iocb;
1165 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
1166 "GID_PT cmpl: status:x%x/x%x rtry:%d",
1167 irsp->ulpStatus, irsp->un.ulpWord[4],
1168 vport->fc_ns_retry);
1170 /* Don't bother processing response if vport is being torn down. */
1171 if (vport->load_flag & FC_UNLOADING) {
1172 if (vport->fc_flag & FC_RSCN_MODE)
1173 lpfc_els_flush_rscn(vport);
1177 if (lpfc_els_chk_latt(vport)) {
1178 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1179 "4108 Link event during NS query\n");
1180 if (vport->fc_flag & FC_RSCN_MODE)
1181 lpfc_els_flush_rscn(vport);
1182 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
1185 if (lpfc_error_lost_link(irsp)) {
1186 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1187 "4166 NS query failed due to link event\n");
1188 if (vport->fc_flag & FC_RSCN_MODE)
1189 lpfc_els_flush_rscn(vport);
1193 spin_lock_irq(shost->host_lock);
1194 if (vport->fc_flag & FC_RSCN_DEFERRED) {
1195 vport->fc_flag &= ~FC_RSCN_DEFERRED;
1196 spin_unlock_irq(shost->host_lock);
1198 /* This is a GID_PT completing so the gidft_inp counter was
1199 * incremented before the GID_PT was issued to the wire.
1201 if (vport->gidft_inp)
1205 * Skip processing the NS response
1206 * Re-issue the NS cmd
1208 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1209 "4167 Process Deferred RSCN Data: x%x x%x\n",
1210 vport->fc_flag, vport->fc_rscn_id_cnt);
1211 lpfc_els_handle_rscn(vport);
1215 spin_unlock_irq(shost->host_lock);
1217 if (irsp->ulpStatus) {
1218 /* Check for retry */
1219 if (vport->fc_ns_retry < LPFC_MAX_NS_RETRY) {
1220 if (irsp->ulpStatus != IOSTAT_LOCAL_REJECT ||
1221 (irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
1223 vport->fc_ns_retry++;
1225 /* CT command is being retried */
1226 rc = lpfc_ns_cmd(vport, SLI_CTNS_GID_PT,
1227 vport->fc_ns_retry, GID_PT_N_PORT);
1230 else { /* Unable to send NS cmd */
1231 if (vport->gidft_inp)
1235 if (vport->fc_flag & FC_RSCN_MODE)
1236 lpfc_els_flush_rscn(vport);
1237 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
1238 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1239 "4103 GID_FT Query error: 0x%x 0x%x\n",
1240 irsp->ulpStatus, vport->fc_ns_retry);
1242 /* Good status, continue checking */
1243 CTreq = (struct lpfc_sli_ct_request *)inp->virt;
1244 CTrsp = (struct lpfc_sli_ct_request *)outp->virt;
1245 if (CTrsp->CommandResponse.bits.CmdRsp ==
1246 cpu_to_be16(SLI_CT_RESPONSE_FS_ACC)) {
1247 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1248 "4105 NameServer Rsp Data: x%x x%x "
1251 CTreq->un.gid.Fc4Type,
1252 vport->num_disc_nodes,
1254 irsp->un.genreq64.bdl.bdeSize);
1258 CTreq->un.gid.Fc4Type,
1259 (uint32_t)(irsp->un.genreq64.bdl.bdeSize));
1260 } else if (CTrsp->CommandResponse.bits.CmdRsp ==
1261 be16_to_cpu(SLI_CT_RESPONSE_FS_RJT)) {
1262 /* NameServer Rsp Error */
1263 if ((CTrsp->ReasonCode == SLI_CT_UNABLE_TO_PERFORM_REQ)
1264 && (CTrsp->Explanation == SLI_CT_NO_FC4_TYPES)) {
1266 vport, KERN_INFO, LOG_DISCOVERY,
1267 "4106 No NameServer Entries "
1268 "Data: x%x x%x x%x x%x\n",
1269 CTrsp->CommandResponse.bits.CmdRsp,
1270 (uint32_t)CTrsp->ReasonCode,
1271 (uint32_t)CTrsp->Explanation,
1274 lpfc_debugfs_disc_trc(
1275 vport, LPFC_DISC_TRC_CT,
1276 "GID_PT no entry cmd:x%x rsn:x%x exp:x%x",
1277 (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
1278 (uint32_t)CTrsp->ReasonCode,
1279 (uint32_t)CTrsp->Explanation);
1282 vport, KERN_INFO, LOG_DISCOVERY,
1283 "4107 NameServer Rsp Error "
1284 "Data: x%x x%x x%x x%x\n",
1285 CTrsp->CommandResponse.bits.CmdRsp,
1286 (uint32_t)CTrsp->ReasonCode,
1287 (uint32_t)CTrsp->Explanation,
1290 lpfc_debugfs_disc_trc(
1291 vport, LPFC_DISC_TRC_CT,
1292 "GID_PT rsp err1 cmd:x%x rsn:x%x exp:x%x",
1293 (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
1294 (uint32_t)CTrsp->ReasonCode,
1295 (uint32_t)CTrsp->Explanation);
1298 /* NameServer Rsp Error */
1299 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1300 "4109 NameServer Rsp Error "
1301 "Data: x%x x%x x%x x%x\n",
1302 CTrsp->CommandResponse.bits.CmdRsp,
1303 (uint32_t)CTrsp->ReasonCode,
1304 (uint32_t)CTrsp->Explanation,
1307 lpfc_debugfs_disc_trc(
1308 vport, LPFC_DISC_TRC_CT,
1309 "GID_PT rsp err2 cmd:x%x rsn:x%x exp:x%x",
1310 (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
1311 (uint32_t)CTrsp->ReasonCode,
1312 (uint32_t)CTrsp->Explanation);
1314 if (vport->gidft_inp)
1318 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1319 "6450 GID_PT cmpl inp %d disc %d\n",
1320 vport->gidft_inp, vport->num_disc_nodes);
1322 /* Link up / RSCN discovery */
1323 if ((vport->num_disc_nodes == 0) &&
1324 (vport->gidft_inp == 0)) {
1326 * The driver has cycled through all Nports in the RSCN payload.
1327 * Complete the handling by cleaning up and marking the
1328 * current driver state.
1330 if (vport->port_state >= LPFC_DISC_AUTH) {
1331 if (vport->fc_flag & FC_RSCN_MODE) {
1332 lpfc_els_flush_rscn(vport);
1333 spin_lock_irq(shost->host_lock);
1334 vport->fc_flag |= FC_RSCN_MODE; /* RSCN still */
1335 spin_unlock_irq(shost->host_lock);
1337 lpfc_els_flush_rscn(vport);
1341 lpfc_disc_start(vport);
1344 lpfc_ct_free_iocb(phba, cmdiocb);
1349 lpfc_cmpl_ct_cmd_gff_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1350 struct lpfc_iocbq *rspiocb)
1352 struct lpfc_vport *vport = cmdiocb->vport;
1353 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1354 IOCB_t *irsp = &rspiocb->iocb;
1355 struct lpfc_dmabuf *inp = (struct lpfc_dmabuf *) cmdiocb->context1;
1356 struct lpfc_dmabuf *outp = (struct lpfc_dmabuf *) cmdiocb->context2;
1357 struct lpfc_sli_ct_request *CTrsp;
1360 struct lpfc_nodelist *ndlp = NULL, *free_ndlp = NULL;
1362 did = ((struct lpfc_sli_ct_request *) inp->virt)->un.gff.PortId;
1363 did = be32_to_cpu(did);
1365 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
1366 "GFF_ID cmpl: status:x%x/x%x did:x%x",
1367 irsp->ulpStatus, irsp->un.ulpWord[4], did);
1369 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
1370 /* Good status, continue checking */
1371 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
1372 fbits = CTrsp->un.gff_acc.fbits[FCP_TYPE_FEATURE_OFFSET];
1374 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1375 "6431 Process GFF_ID rsp for %08x "
1376 "fbits %02x %s %s\n",
1378 (fbits & FC4_FEATURE_INIT) ? "Initiator" : " ",
1379 (fbits & FC4_FEATURE_TARGET) ? "Target" : " ");
1381 if (CTrsp->CommandResponse.bits.CmdRsp ==
1382 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC)) {
1383 if ((fbits & FC4_FEATURE_INIT) &&
1384 !(fbits & FC4_FEATURE_TARGET)) {
1385 lpfc_printf_vlog(vport, KERN_INFO,
1387 "0270 Skip x%x GFF "
1388 "NameServer Rsp Data: (init) "
1389 "x%x x%x\n", did, fbits,
1390 vport->fc_rscn_id_cnt);
1396 /* Check for retry */
1397 if (cmdiocb->retry < LPFC_MAX_NS_RETRY) {
1399 if (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) {
1400 switch ((irsp->un.ulpWord[4] &
1401 IOERR_PARAM_MASK)) {
1403 case IOERR_NO_RESOURCES:
1404 /* We don't increment the retry
1405 * count for this case.
1408 case IOERR_LINK_DOWN:
1409 case IOERR_SLI_ABORTED:
1410 case IOERR_SLI_DOWN:
1421 /* CT command is being retried */
1422 rc = lpfc_ns_cmd(vport, SLI_CTNS_GFF_ID,
1423 cmdiocb->retry, did);
1426 free_ndlp = cmdiocb->context_un.ndlp;
1427 lpfc_ct_free_iocb(phba, cmdiocb);
1428 lpfc_nlp_put(free_ndlp);
1433 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1434 "0267 NameServer GFF Rsp "
1435 "x%x Error (%d %d) Data: x%x x%x\n",
1436 did, irsp->ulpStatus, irsp->un.ulpWord[4],
1437 vport->fc_flag, vport->fc_rscn_id_cnt);
1440 /* This is a target port, unregistered port, or the GFF_ID failed */
1441 ndlp = lpfc_setup_disc_node(vport, did);
1443 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1444 "0242 Process x%x GFF "
1445 "NameServer Rsp Data: x%x x%x x%x\n",
1446 did, ndlp->nlp_flag, vport->fc_flag,
1447 vport->fc_rscn_id_cnt);
1449 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1450 "0243 Skip x%x GFF "
1451 "NameServer Rsp Data: x%x x%x\n", did,
1452 vport->fc_flag, vport->fc_rscn_id_cnt);
1455 /* Link up / RSCN discovery */
1456 if (vport->num_disc_nodes)
1457 vport->num_disc_nodes--;
1459 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1460 "6451 GFF_ID cmpl inp %d disc %d\n",
1461 vport->gidft_inp, vport->num_disc_nodes);
1463 if (vport->num_disc_nodes == 0) {
1465 * The driver has cycled through all Nports in the RSCN payload.
1466 * Complete the handling by cleaning up and marking the
1467 * current driver state.
1469 if (vport->port_state >= LPFC_DISC_AUTH) {
1470 if (vport->fc_flag & FC_RSCN_MODE) {
1471 lpfc_els_flush_rscn(vport);
1472 spin_lock_irq(shost->host_lock);
1473 vport->fc_flag |= FC_RSCN_MODE; /* RSCN still */
1474 spin_unlock_irq(shost->host_lock);
1477 lpfc_els_flush_rscn(vport);
1479 lpfc_disc_start(vport);
1482 free_ndlp = cmdiocb->context_un.ndlp;
1483 lpfc_ct_free_iocb(phba, cmdiocb);
1484 lpfc_nlp_put(free_ndlp);
1489 lpfc_cmpl_ct_cmd_gft_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1490 struct lpfc_iocbq *rspiocb)
1492 struct lpfc_vport *vport = cmdiocb->vport;
1493 IOCB_t *irsp = &rspiocb->iocb;
1494 struct lpfc_dmabuf *inp = (struct lpfc_dmabuf *)cmdiocb->context1;
1495 struct lpfc_dmabuf *outp = (struct lpfc_dmabuf *)cmdiocb->context2;
1496 struct lpfc_sli_ct_request *CTrsp;
1498 struct lpfc_nodelist *ndlp = NULL;
1499 struct lpfc_nodelist *ns_ndlp = NULL;
1500 uint32_t fc4_data_0, fc4_data_1;
1502 did = ((struct lpfc_sli_ct_request *)inp->virt)->un.gft.PortId;
1503 did = be32_to_cpu(did);
1505 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
1506 "GFT_ID cmpl: status:x%x/x%x did:x%x",
1507 irsp->ulpStatus, irsp->un.ulpWord[4], did);
1509 /* Preserve the nameserver node to release the reference. */
1510 ns_ndlp = cmdiocb->context_un.ndlp;
1512 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
1513 /* Good status, continue checking */
1514 CTrsp = (struct lpfc_sli_ct_request *)outp->virt;
1515 fc4_data_0 = be32_to_cpu(CTrsp->un.gft_acc.fc4_types[0]);
1516 fc4_data_1 = be32_to_cpu(CTrsp->un.gft_acc.fc4_types[1]);
1518 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1519 "6432 Process GFT_ID rsp for %08x "
1520 "Data %08x %08x %s %s\n",
1521 did, fc4_data_0, fc4_data_1,
1522 (fc4_data_0 & LPFC_FC4_TYPE_BITMASK) ?
1524 (fc4_data_1 & LPFC_FC4_TYPE_BITMASK) ?
1527 /* Lookup the NPort_ID queried in the GFT_ID and find the
1528 * driver's local node. It's an error if the driver
1531 ndlp = lpfc_findnode_did(vport, did);
1533 /* The bitmask value for FCP and NVME FCP types is
1534 * the same because they are 32 bits distant from
1535 * each other in word0 and word0.
1537 if (fc4_data_0 & LPFC_FC4_TYPE_BITMASK)
1538 ndlp->nlp_fc4_type |= NLP_FC4_FCP;
1539 if (fc4_data_1 & LPFC_FC4_TYPE_BITMASK)
1540 ndlp->nlp_fc4_type |= NLP_FC4_NVME;
1541 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1542 "3064 Setting ndlp x%px, DID x%06x "
1543 "with FC4 x%08x, Data: x%08x x%08x "
1545 ndlp, did, ndlp->nlp_fc4_type,
1546 FC_TYPE_FCP, FC_TYPE_NVME,
1549 if (ndlp->nlp_state == NLP_STE_REG_LOGIN_ISSUE &&
1550 ndlp->nlp_fc4_type) {
1551 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1553 lpfc_nlp_set_state(vport, ndlp,
1554 NLP_STE_PRLI_ISSUE);
1555 lpfc_issue_els_prli(vport, ndlp, 0);
1556 } else if (!ndlp->nlp_fc4_type) {
1557 /* If fc4 type is still unknown, then LOGO */
1558 lpfc_printf_vlog(vport, KERN_INFO,
1560 "6443 Sending LOGO ndlp x%px,"
1561 "DID x%06x with fc4_type: "
1562 "x%08x, state: %d\n",
1563 ndlp, did, ndlp->nlp_fc4_type,
1565 lpfc_issue_els_logo(vport, ndlp, 0);
1566 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1567 lpfc_nlp_set_state(vport, ndlp,
1572 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1573 "3065 GFT_ID failed x%08x\n", irsp->ulpStatus);
1575 lpfc_ct_free_iocb(phba, cmdiocb);
1576 lpfc_nlp_put(ns_ndlp);
1580 lpfc_cmpl_ct(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1581 struct lpfc_iocbq *rspiocb)
1583 struct lpfc_vport *vport = cmdiocb->vport;
1584 struct lpfc_dmabuf *inp;
1585 struct lpfc_dmabuf *outp;
1587 struct lpfc_sli_ct_request *CTrsp;
1588 struct lpfc_nodelist *ndlp;
1593 /* First save ndlp, before we overwrite it */
1594 ndlp = cmdiocb->context_un.ndlp;
1596 /* we pass cmdiocb to state machine which needs rspiocb as well */
1597 cmdiocb->context_un.rsp_iocb = rspiocb;
1599 inp = (struct lpfc_dmabuf *) cmdiocb->context1;
1600 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
1601 irsp = &rspiocb->iocb;
1603 cmdcode = be16_to_cpu(((struct lpfc_sli_ct_request *) inp->virt)->
1604 CommandResponse.bits.CmdRsp);
1605 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
1607 latt = lpfc_els_chk_latt(vport);
1609 /* RFT request completes status <ulpStatus> CmdRsp <CmdRsp> */
1610 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1611 "0209 CT Request completes, latt %d, "
1612 "ulpStatus x%x CmdRsp x%x, Context x%x, Tag x%x\n",
1613 latt, irsp->ulpStatus,
1614 CTrsp->CommandResponse.bits.CmdRsp,
1615 cmdiocb->iocb.ulpContext, cmdiocb->iocb.ulpIoTag);
1617 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
1618 "CT cmd cmpl: status:x%x/x%x cmd:x%x",
1619 irsp->ulpStatus, irsp->un.ulpWord[4], cmdcode);
1621 if (irsp->ulpStatus) {
1622 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1623 "0268 NS cmd x%x Error (x%x x%x)\n",
1624 cmdcode, irsp->ulpStatus, irsp->un.ulpWord[4]);
1626 if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
1627 (((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
1629 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
1630 IOERR_SLI_ABORTED)))
1633 retry = cmdiocb->retry;
1634 if (retry >= LPFC_MAX_NS_RETRY)
1638 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1639 "0250 Retrying NS cmd %x\n", cmdcode);
1640 rc = lpfc_ns_cmd(vport, cmdcode, retry, 0);
1646 lpfc_ct_free_iocb(phba, cmdiocb);
1652 lpfc_cmpl_ct_cmd_rft_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1653 struct lpfc_iocbq *rspiocb)
1655 IOCB_t *irsp = &rspiocb->iocb;
1656 struct lpfc_vport *vport = cmdiocb->vport;
1658 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
1659 struct lpfc_dmabuf *outp;
1660 struct lpfc_sli_ct_request *CTrsp;
1662 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
1663 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
1664 if (CTrsp->CommandResponse.bits.CmdRsp ==
1665 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
1666 vport->ct_flags |= FC_CT_RFT_ID;
1668 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
1673 lpfc_cmpl_ct_cmd_rnn_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1674 struct lpfc_iocbq *rspiocb)
1676 IOCB_t *irsp = &rspiocb->iocb;
1677 struct lpfc_vport *vport = cmdiocb->vport;
1679 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
1680 struct lpfc_dmabuf *outp;
1681 struct lpfc_sli_ct_request *CTrsp;
1683 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
1684 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
1685 if (CTrsp->CommandResponse.bits.CmdRsp ==
1686 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
1687 vport->ct_flags |= FC_CT_RNN_ID;
1689 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
1694 lpfc_cmpl_ct_cmd_rspn_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1695 struct lpfc_iocbq *rspiocb)
1697 IOCB_t *irsp = &rspiocb->iocb;
1698 struct lpfc_vport *vport = cmdiocb->vport;
1700 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
1701 struct lpfc_dmabuf *outp;
1702 struct lpfc_sli_ct_request *CTrsp;
1704 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
1705 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
1706 if (CTrsp->CommandResponse.bits.CmdRsp ==
1707 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
1708 vport->ct_flags |= FC_CT_RSPN_ID;
1710 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
1715 lpfc_cmpl_ct_cmd_rsnn_nn(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1716 struct lpfc_iocbq *rspiocb)
1718 IOCB_t *irsp = &rspiocb->iocb;
1719 struct lpfc_vport *vport = cmdiocb->vport;
1721 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
1722 struct lpfc_dmabuf *outp;
1723 struct lpfc_sli_ct_request *CTrsp;
1725 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
1726 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
1727 if (CTrsp->CommandResponse.bits.CmdRsp ==
1728 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
1729 vport->ct_flags |= FC_CT_RSNN_NN;
1731 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
1736 lpfc_cmpl_ct_cmd_da_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1737 struct lpfc_iocbq *rspiocb)
1739 struct lpfc_vport *vport = cmdiocb->vport;
1741 /* even if it fails we will act as though it succeeded. */
1742 vport->ct_flags = 0;
1743 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
1748 lpfc_cmpl_ct_cmd_rff_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1749 struct lpfc_iocbq *rspiocb)
1751 IOCB_t *irsp = &rspiocb->iocb;
1752 struct lpfc_vport *vport = cmdiocb->vport;
1754 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
1755 struct lpfc_dmabuf *outp;
1756 struct lpfc_sli_ct_request *CTrsp;
1758 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
1759 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
1760 if (CTrsp->CommandResponse.bits.CmdRsp ==
1761 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
1762 vport->ct_flags |= FC_CT_RFF_ID;
1764 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
1769 * Although the symbolic port name is thought to be an integer
1770 * as of January 18, 2016, leave it as a string until more of
1771 * the record state becomes defined.
1774 lpfc_vport_symbolic_port_name(struct lpfc_vport *vport, char *symbol,
1780 * Use the lpfc board number as the Symbolic Port
1781 * Name object. NPIV is not in play so this integer
1782 * value is sufficient and unique per FC-ID.
1784 n = scnprintf(symbol, size, "%d", vport->phba->brd_no);
1790 lpfc_vport_symbolic_node_name(struct lpfc_vport *vport, char *symbol,
1793 char fwrev[FW_REV_STR_SIZE] = {0};
1794 char tmp[MAXHOSTNAMELEN] = {0};
1796 memset(symbol, 0, size);
1798 scnprintf(tmp, sizeof(tmp), "Emulex %s", vport->phba->ModelName);
1799 if (strlcat(symbol, tmp, size) >= size)
1802 lpfc_decode_firmware_rev(vport->phba, fwrev, 0);
1803 scnprintf(tmp, sizeof(tmp), " FV%s", fwrev);
1804 if (strlcat(symbol, tmp, size) >= size)
1807 scnprintf(tmp, sizeof(tmp), " DV%s", lpfc_release_version);
1808 if (strlcat(symbol, tmp, size) >= size)
1811 scnprintf(tmp, sizeof(tmp), " HN:%s", vport->phba->os_host_name);
1812 if (strlcat(symbol, tmp, size) >= size)
1815 /* Note :- OS name is "Linux" */
1816 scnprintf(tmp, sizeof(tmp), " OS:%s", init_utsname()->sysname);
1817 strlcat(symbol, tmp, size);
1820 return strnlen(symbol, size);
1825 lpfc_find_map_node(struct lpfc_vport *vport)
1827 struct lpfc_nodelist *ndlp, *next_ndlp;
1828 struct Scsi_Host *shost;
1831 shost = lpfc_shost_from_vport(vport);
1832 spin_lock_irq(shost->host_lock);
1833 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
1834 if (ndlp->nlp_type & NLP_FABRIC)
1836 if ((ndlp->nlp_state == NLP_STE_MAPPED_NODE) ||
1837 (ndlp->nlp_state == NLP_STE_UNMAPPED_NODE))
1840 spin_unlock_irq(shost->host_lock);
1845 * This routine will return the FC4 Type associated with the CT
1849 lpfc_get_gidft_type(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb)
1851 struct lpfc_sli_ct_request *CtReq;
1852 struct lpfc_dmabuf *mp;
1855 mp = cmdiocb->context1;
1858 CtReq = (struct lpfc_sli_ct_request *)mp->virt;
1859 type = (uint32_t)CtReq->un.gid.Fc4Type;
1860 if ((type != SLI_CTPT_FCP) && (type != SLI_CTPT_NVME))
1868 * Issue Cmd to NameServer
1873 lpfc_ns_cmd(struct lpfc_vport *vport, int cmdcode,
1874 uint8_t retry, uint32_t context)
1876 struct lpfc_nodelist * ndlp;
1877 struct lpfc_hba *phba = vport->phba;
1878 struct lpfc_dmabuf *mp, *bmp;
1879 struct lpfc_sli_ct_request *CtReq;
1880 struct ulp_bde64 *bpl;
1881 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
1882 struct lpfc_iocbq *) = NULL;
1884 uint32_t rsp_size = 1024;
1888 ndlp = lpfc_findnode_did(vport, NameServer_DID);
1889 if (!ndlp || ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) {
1894 /* fill in BDEs for command */
1895 /* Allocate buffer for command payload */
1896 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
1902 INIT_LIST_HEAD(&mp->list);
1903 mp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(mp->phys));
1906 goto ns_cmd_free_mp;
1909 /* Allocate buffer for Buffer ptr list */
1910 bmp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
1913 goto ns_cmd_free_mpvirt;
1916 INIT_LIST_HEAD(&bmp->list);
1917 bmp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(bmp->phys));
1920 goto ns_cmd_free_bmp;
1923 /* NameServer Req */
1924 lpfc_printf_vlog(vport, KERN_INFO ,LOG_DISCOVERY,
1925 "0236 NameServer Req Data: x%x x%x x%x x%x\n",
1926 cmdcode, vport->fc_flag, vport->fc_rscn_id_cnt,
1929 bpl = (struct ulp_bde64 *) bmp->virt;
1930 memset(bpl, 0, sizeof(struct ulp_bde64));
1931 bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys) );
1932 bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys) );
1933 bpl->tus.f.bdeFlags = 0;
1934 if (cmdcode == SLI_CTNS_GID_FT)
1935 bpl->tus.f.bdeSize = GID_REQUEST_SZ;
1936 else if (cmdcode == SLI_CTNS_GID_PT)
1937 bpl->tus.f.bdeSize = GID_REQUEST_SZ;
1938 else if (cmdcode == SLI_CTNS_GFF_ID)
1939 bpl->tus.f.bdeSize = GFF_REQUEST_SZ;
1940 else if (cmdcode == SLI_CTNS_GFT_ID)
1941 bpl->tus.f.bdeSize = GFT_REQUEST_SZ;
1942 else if (cmdcode == SLI_CTNS_RFT_ID)
1943 bpl->tus.f.bdeSize = RFT_REQUEST_SZ;
1944 else if (cmdcode == SLI_CTNS_RNN_ID)
1945 bpl->tus.f.bdeSize = RNN_REQUEST_SZ;
1946 else if (cmdcode == SLI_CTNS_RSPN_ID)
1947 bpl->tus.f.bdeSize = RSPN_REQUEST_SZ;
1948 else if (cmdcode == SLI_CTNS_RSNN_NN)
1949 bpl->tus.f.bdeSize = RSNN_REQUEST_SZ;
1950 else if (cmdcode == SLI_CTNS_DA_ID)
1951 bpl->tus.f.bdeSize = DA_ID_REQUEST_SZ;
1952 else if (cmdcode == SLI_CTNS_RFF_ID)
1953 bpl->tus.f.bdeSize = RFF_REQUEST_SZ;
1955 bpl->tus.f.bdeSize = 0;
1956 bpl->tus.w = le32_to_cpu(bpl->tus.w);
1958 CtReq = (struct lpfc_sli_ct_request *) mp->virt;
1959 memset(CtReq, 0, sizeof(struct lpfc_sli_ct_request));
1960 CtReq->RevisionId.bits.Revision = SLI_CT_REVISION;
1961 CtReq->RevisionId.bits.InId = 0;
1962 CtReq->FsType = SLI_CT_DIRECTORY_SERVICE;
1963 CtReq->FsSubType = SLI_CT_DIRECTORY_NAME_SERVER;
1964 CtReq->CommandResponse.bits.Size = 0;
1966 case SLI_CTNS_GID_FT:
1967 CtReq->CommandResponse.bits.CmdRsp =
1968 cpu_to_be16(SLI_CTNS_GID_FT);
1969 CtReq->un.gid.Fc4Type = context;
1971 if (vport->port_state < LPFC_NS_QRY)
1972 vport->port_state = LPFC_NS_QRY;
1973 lpfc_set_disctmo(vport);
1974 cmpl = lpfc_cmpl_ct_cmd_gid_ft;
1975 rsp_size = FC_MAX_NS_RSP;
1978 case SLI_CTNS_GID_PT:
1979 CtReq->CommandResponse.bits.CmdRsp =
1980 cpu_to_be16(SLI_CTNS_GID_PT);
1981 CtReq->un.gid.PortType = context;
1983 if (vport->port_state < LPFC_NS_QRY)
1984 vport->port_state = LPFC_NS_QRY;
1985 lpfc_set_disctmo(vport);
1986 cmpl = lpfc_cmpl_ct_cmd_gid_pt;
1987 rsp_size = FC_MAX_NS_RSP;
1990 case SLI_CTNS_GFF_ID:
1991 CtReq->CommandResponse.bits.CmdRsp =
1992 cpu_to_be16(SLI_CTNS_GFF_ID);
1993 CtReq->un.gff.PortId = cpu_to_be32(context);
1994 cmpl = lpfc_cmpl_ct_cmd_gff_id;
1997 case SLI_CTNS_GFT_ID:
1998 CtReq->CommandResponse.bits.CmdRsp =
1999 cpu_to_be16(SLI_CTNS_GFT_ID);
2000 CtReq->un.gft.PortId = cpu_to_be32(context);
2001 cmpl = lpfc_cmpl_ct_cmd_gft_id;
2004 case SLI_CTNS_RFT_ID:
2005 vport->ct_flags &= ~FC_CT_RFT_ID;
2006 CtReq->CommandResponse.bits.CmdRsp =
2007 cpu_to_be16(SLI_CTNS_RFT_ID);
2008 CtReq->un.rft.PortId = cpu_to_be32(vport->fc_myDID);
2010 /* Register FC4 FCP type if enabled. */
2011 if (vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH ||
2012 vport->cfg_enable_fc4_type == LPFC_ENABLE_FCP)
2013 CtReq->un.rft.fcpReg = 1;
2015 /* Register NVME type if enabled. Defined LE and swapped.
2016 * rsvd[0] is used as word1 because of the hard-coded
2017 * word0 usage in the ct_request data structure.
2019 if (vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH ||
2020 vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME)
2021 CtReq->un.rft.rsvd[0] =
2022 cpu_to_be32(LPFC_FC4_TYPE_BITMASK);
2024 ptr = (uint32_t *)CtReq;
2025 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2026 "6433 Issue RFT (%s %s): %08x %08x %08x %08x "
2027 "%08x %08x %08x %08x\n",
2028 CtReq->un.rft.fcpReg ? "FCP" : " ",
2029 CtReq->un.rft.rsvd[0] ? "NVME" : " ",
2030 *ptr, *(ptr + 1), *(ptr + 2), *(ptr + 3),
2031 *(ptr + 4), *(ptr + 5),
2032 *(ptr + 6), *(ptr + 7));
2033 cmpl = lpfc_cmpl_ct_cmd_rft_id;
2036 case SLI_CTNS_RNN_ID:
2037 vport->ct_flags &= ~FC_CT_RNN_ID;
2038 CtReq->CommandResponse.bits.CmdRsp =
2039 cpu_to_be16(SLI_CTNS_RNN_ID);
2040 CtReq->un.rnn.PortId = cpu_to_be32(vport->fc_myDID);
2041 memcpy(CtReq->un.rnn.wwnn, &vport->fc_nodename,
2042 sizeof(struct lpfc_name));
2043 cmpl = lpfc_cmpl_ct_cmd_rnn_id;
2046 case SLI_CTNS_RSPN_ID:
2047 vport->ct_flags &= ~FC_CT_RSPN_ID;
2048 CtReq->CommandResponse.bits.CmdRsp =
2049 cpu_to_be16(SLI_CTNS_RSPN_ID);
2050 CtReq->un.rspn.PortId = cpu_to_be32(vport->fc_myDID);
2051 size = sizeof(CtReq->un.rspn.symbname);
2052 CtReq->un.rspn.len =
2053 lpfc_vport_symbolic_port_name(vport,
2054 CtReq->un.rspn.symbname, size);
2055 cmpl = lpfc_cmpl_ct_cmd_rspn_id;
2057 case SLI_CTNS_RSNN_NN:
2058 vport->ct_flags &= ~FC_CT_RSNN_NN;
2059 CtReq->CommandResponse.bits.CmdRsp =
2060 cpu_to_be16(SLI_CTNS_RSNN_NN);
2061 memcpy(CtReq->un.rsnn.wwnn, &vport->fc_nodename,
2062 sizeof(struct lpfc_name));
2063 size = sizeof(CtReq->un.rsnn.symbname);
2064 CtReq->un.rsnn.len =
2065 lpfc_vport_symbolic_node_name(vport,
2066 CtReq->un.rsnn.symbname, size);
2067 cmpl = lpfc_cmpl_ct_cmd_rsnn_nn;
2069 case SLI_CTNS_DA_ID:
2070 /* Implement DA_ID Nameserver request */
2071 CtReq->CommandResponse.bits.CmdRsp =
2072 cpu_to_be16(SLI_CTNS_DA_ID);
2073 CtReq->un.da_id.port_id = cpu_to_be32(vport->fc_myDID);
2074 cmpl = lpfc_cmpl_ct_cmd_da_id;
2076 case SLI_CTNS_RFF_ID:
2077 vport->ct_flags &= ~FC_CT_RFF_ID;
2078 CtReq->CommandResponse.bits.CmdRsp =
2079 cpu_to_be16(SLI_CTNS_RFF_ID);
2080 CtReq->un.rff.PortId = cpu_to_be32(vport->fc_myDID);
2081 CtReq->un.rff.fbits = FC4_FEATURE_INIT;
2083 /* The driver always supports FC_TYPE_FCP. However, the
2084 * caller can specify NVME (type x28) as well. But only
2085 * these that FC4 type is supported.
2087 if (((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
2088 (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) &&
2089 (context == FC_TYPE_NVME)) {
2090 if ((vport == phba->pport) && phba->nvmet_support) {
2091 CtReq->un.rff.fbits = (FC4_FEATURE_TARGET |
2092 FC4_FEATURE_NVME_DISC);
2093 lpfc_nvmet_update_targetport(phba);
2095 lpfc_nvme_update_localport(vport);
2097 CtReq->un.rff.type_code = context;
2099 } else if (((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
2100 (vport->cfg_enable_fc4_type == LPFC_ENABLE_FCP)) &&
2101 (context == FC_TYPE_FCP))
2102 CtReq->un.rff.type_code = context;
2105 goto ns_cmd_free_bmpvirt;
2107 ptr = (uint32_t *)CtReq;
2108 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2109 "6434 Issue RFF (%s): %08x %08x %08x %08x "
2110 "%08x %08x %08x %08x\n",
2111 (context == FC_TYPE_NVME) ? "NVME" : "FCP",
2112 *ptr, *(ptr + 1), *(ptr + 2), *(ptr + 3),
2113 *(ptr + 4), *(ptr + 5),
2114 *(ptr + 6), *(ptr + 7));
2115 cmpl = lpfc_cmpl_ct_cmd_rff_id;
2118 /* The lpfc_ct_cmd/lpfc_get_req shall increment ndlp reference count
2119 * to hold ndlp reference for the corresponding callback function.
2121 if (!lpfc_ct_cmd(vport, mp, bmp, ndlp, cmpl, rsp_size, retry)) {
2122 /* On success, The cmpl function will free the buffers */
2123 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
2124 "Issue CT cmd: cmd:x%x did:x%x",
2125 cmdcode, ndlp->nlp_DID, 0);
2130 ns_cmd_free_bmpvirt:
2131 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
2135 lpfc_mbuf_free(phba, mp->virt, mp->phys);
2139 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
2140 "0266 Issue NameServer Req x%x err %d Data: x%x x%x\n",
2141 cmdcode, rc, vport->fc_flag, vport->fc_rscn_id_cnt);
2146 * lpfc_cmpl_ct_disc_fdmi - Handle a discovery FDMI completion
2147 * @phba: Pointer to HBA context object.
2148 * @cmdiocb: Pointer to the command IOCBQ.
2149 * @rspiocb: Pointer to the response IOCBQ.
2151 * This function to handle the completion of a driver initiated FDMI
2152 * CT command issued during discovery.
2155 lpfc_cmpl_ct_disc_fdmi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2156 struct lpfc_iocbq *rspiocb)
2158 struct lpfc_vport *vport = cmdiocb->vport;
2159 struct lpfc_dmabuf *inp = cmdiocb->context1;
2160 struct lpfc_dmabuf *outp = cmdiocb->context2;
2161 struct lpfc_sli_ct_request *CTcmd = inp->virt;
2162 struct lpfc_sli_ct_request *CTrsp = outp->virt;
2163 uint16_t fdmi_cmd = CTcmd->CommandResponse.bits.CmdRsp;
2164 uint16_t fdmi_rsp = CTrsp->CommandResponse.bits.CmdRsp;
2165 IOCB_t *irsp = &rspiocb->iocb;
2166 struct lpfc_nodelist *ndlp, *free_ndlp = NULL;
2167 uint32_t latt, cmd, err;
2169 latt = lpfc_els_chk_latt(vport);
2170 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
2171 "FDMI cmpl: status:x%x/x%x latt:%d",
2172 irsp->ulpStatus, irsp->un.ulpWord[4], latt);
2174 if (latt || irsp->ulpStatus) {
2176 /* Look for a retryable error */
2177 if (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) {
2178 switch ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK)) {
2179 case IOERR_SLI_ABORTED:
2180 case IOERR_SLI_DOWN:
2181 /* Driver aborted this IO. No retry as error
2182 * is likely Offline->Online or some adapter
2183 * error. Recovery will try again.
2186 case IOERR_ABORT_IN_PROGRESS:
2187 case IOERR_SEQUENCE_TIMEOUT:
2188 case IOERR_ILLEGAL_FRAME:
2189 case IOERR_NO_RESOURCES:
2190 case IOERR_ILLEGAL_COMMAND:
2192 if (cmdiocb->retry >= LPFC_FDMI_MAX_RETRY)
2195 /* Retry the same FDMI command */
2196 err = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING,
2198 if (err == IOCB_ERROR)
2206 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2207 "0229 FDMI cmd %04x failed, latt = %d "
2208 "ulpStatus: x%x, rid x%x\n",
2209 be16_to_cpu(fdmi_cmd), latt, irsp->ulpStatus,
2210 irsp->un.ulpWord[4]);
2213 free_ndlp = cmdiocb->context_un.ndlp;
2214 lpfc_ct_free_iocb(phba, cmdiocb);
2215 lpfc_nlp_put(free_ndlp);
2217 ndlp = lpfc_findnode_did(vport, FDMI_DID);
2221 /* Check for a CT LS_RJT response */
2222 cmd = be16_to_cpu(fdmi_cmd);
2223 if (fdmi_rsp == cpu_to_be16(SLI_CT_RESPONSE_FS_RJT)) {
2224 /* FDMI rsp failed */
2225 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2226 "0220 FDMI cmd failed FS_RJT Data: x%x", cmd);
2228 /* Should we fallback to FDMI-2 / FDMI-1 ? */
2231 if (vport->fdmi_hba_mask == LPFC_FDMI2_HBA_ATTR) {
2232 /* Fallback to FDMI-1 */
2233 vport->fdmi_hba_mask = LPFC_FDMI1_HBA_ATTR;
2234 vport->fdmi_port_mask = LPFC_FDMI1_PORT_ATTR;
2236 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA, 0);
2241 if (vport->fdmi_port_mask == LPFC_FDMI2_PORT_ATTR) {
2242 /* Fallback to FDMI-1 */
2243 vport->fdmi_port_mask = LPFC_FDMI1_PORT_ATTR;
2245 lpfc_fdmi_cmd(vport, ndlp, cmd, 0);
2248 if (vport->fdmi_port_mask == LPFC_FDMI2_SMART_ATTR) {
2249 vport->fdmi_port_mask = LPFC_FDMI2_PORT_ATTR;
2250 /* Retry the same command */
2251 lpfc_fdmi_cmd(vport, ndlp, cmd, 0);
2256 /* No retry on Vendor, RPA only done on physical port */
2257 if (phba->link_flag & LS_CT_VEN_RPA) {
2258 phba->link_flag &= ~LS_CT_VEN_RPA;
2259 lpfc_printf_log(phba, KERN_ERR,
2260 LOG_DISCOVERY | LOG_ELS,
2261 "6460 VEN FDMI RPA failure\n");
2264 if (vport->fdmi_port_mask == LPFC_FDMI2_PORT_ATTR) {
2265 /* Fallback to FDMI-1 */
2266 vport->fdmi_hba_mask = LPFC_FDMI1_HBA_ATTR;
2267 vport->fdmi_port_mask = LPFC_FDMI1_PORT_ATTR;
2269 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA, 0);
2272 if (vport->fdmi_port_mask == LPFC_FDMI2_SMART_ATTR) {
2273 vport->fdmi_port_mask = LPFC_FDMI2_PORT_ATTR;
2274 /* Retry the same command */
2275 lpfc_fdmi_cmd(vport, ndlp, cmd, 0);
2282 * On success, need to cycle thru FDMI registration for discovery
2283 * DHBA -> DPRT -> RHBA -> RPA (physical port)
2284 * DPRT -> RPRT (vports)
2288 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RPA, 0);
2292 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DPRT, 0);
2296 if (vport->port_type == LPFC_PHYSICAL_PORT)
2297 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RHBA, 0);
2299 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RPRT, 0);
2302 if (vport->port_type == LPFC_PHYSICAL_PORT &&
2303 phba->cfg_enable_mi &&
2304 phba->sli4_hba.pc_sli4_params.mi_ver > LPFC_MIB1_SUPPORT) {
2305 /* mi is only for the phyical port, no vports */
2306 if (phba->link_flag & LS_CT_VEN_RPA) {
2307 lpfc_printf_vlog(vport, KERN_INFO,
2308 LOG_DISCOVERY | LOG_ELS,
2309 "6449 VEN RPA FDMI Success\n");
2310 phba->link_flag &= ~LS_CT_VEN_RPA;
2314 if (lpfc_fdmi_cmd(vport, ndlp, cmd,
2315 LPFC_FDMI_VENDOR_ATTR_mi) == 0)
2316 phba->link_flag |= LS_CT_VEN_RPA;
2317 lpfc_printf_log(phba, KERN_INFO,
2318 LOG_DISCOVERY | LOG_ELS,
2319 "6458 Send MI FDMI:%x Flag x%x\n",
2320 phba->sli4_hba.pc_sli4_params.mi_value,
2323 lpfc_printf_log(phba, KERN_INFO,
2324 LOG_DISCOVERY | LOG_ELS,
2325 "6459 No FDMI VEN MI support - "
2335 * lpfc_fdmi_change_check - Check for changed FDMI parameters
2336 * @vport: pointer to a host virtual N_Port data structure.
2338 * Check how many mapped NPorts we are connected to
2339 * Check if our hostname changed
2340 * Called from hbeat timeout routine to check if any FDMI parameters
2341 * changed. If so, re-register those Attributes.
2344 lpfc_fdmi_change_check(struct lpfc_vport *vport)
2346 struct lpfc_hba *phba = vport->phba;
2347 struct lpfc_nodelist *ndlp;
2350 if (!lpfc_is_link_up(phba))
2353 /* Must be connected to a Fabric */
2354 if (!(vport->fc_flag & FC_FABRIC))
2357 ndlp = lpfc_findnode_did(vport, FDMI_DID);
2361 /* Check if system hostname changed */
2362 if (strcmp(phba->os_host_name, init_utsname()->nodename)) {
2363 memset(phba->os_host_name, 0, sizeof(phba->os_host_name));
2364 scnprintf(phba->os_host_name, sizeof(phba->os_host_name), "%s",
2365 init_utsname()->nodename);
2366 lpfc_ns_cmd(vport, SLI_CTNS_RSNN_NN, 0, 0);
2368 /* Since this effects multiple HBA and PORT attributes, we need
2369 * de-register and go thru the whole FDMI registration cycle.
2370 * DHBA -> DPRT -> RHBA -> RPA (physical port)
2371 * DPRT -> RPRT (vports)
2373 if (vport->port_type == LPFC_PHYSICAL_PORT) {
2374 /* For extra Vendor RPA */
2375 phba->link_flag &= ~LS_CT_VEN_RPA;
2376 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA, 0);
2378 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DPRT, 0);
2381 /* Since this code path registers all the port attributes
2382 * we can just return without further checking.
2387 if (!(vport->fdmi_port_mask & LPFC_FDMI_PORT_ATTR_num_disc))
2390 /* Check if the number of mapped NPorts changed */
2391 cnt = lpfc_find_map_node(vport);
2392 if (cnt == vport->fdmi_num_disc)
2395 if (vport->port_type == LPFC_PHYSICAL_PORT) {
2396 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RPA,
2397 LPFC_FDMI_PORT_ATTR_num_disc);
2399 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RPRT,
2400 LPFC_FDMI_PORT_ATTR_num_disc);
2404 /* Routines for all individual HBA attributes */
2406 lpfc_fdmi_hba_attr_wwnn(struct lpfc_vport *vport, struct lpfc_fdmi_attr_def *ad)
2408 struct lpfc_fdmi_attr_entry *ae;
2411 ae = &ad->AttrValue;
2412 memset(ae, 0, sizeof(*ae));
2414 memcpy(&ae->un.AttrWWN, &vport->fc_sparam.nodeName,
2415 sizeof(struct lpfc_name));
2416 size = FOURBYTES + sizeof(struct lpfc_name);
2417 ad->AttrLen = cpu_to_be16(size);
2418 ad->AttrType = cpu_to_be16(RHBA_NODENAME);
2422 lpfc_fdmi_hba_attr_manufacturer(struct lpfc_vport *vport,
2423 struct lpfc_fdmi_attr_def *ad)
2425 struct lpfc_fdmi_attr_entry *ae;
2428 ae = &ad->AttrValue;
2429 memset(ae, 0, sizeof(*ae));
2431 /* This string MUST be consistent with other FC platforms
2432 * supported by Broadcom.
2434 strncpy(ae->un.AttrString,
2435 "Emulex Corporation",
2436 sizeof(ae->un.AttrString));
2437 len = strnlen(ae->un.AttrString,
2438 sizeof(ae->un.AttrString));
2439 len += (len & 3) ? (4 - (len & 3)) : 4;
2440 size = FOURBYTES + len;
2441 ad->AttrLen = cpu_to_be16(size);
2442 ad->AttrType = cpu_to_be16(RHBA_MANUFACTURER);
2447 lpfc_fdmi_hba_attr_sn(struct lpfc_vport *vport, struct lpfc_fdmi_attr_def *ad)
2449 struct lpfc_hba *phba = vport->phba;
2450 struct lpfc_fdmi_attr_entry *ae;
2453 ae = &ad->AttrValue;
2454 memset(ae, 0, sizeof(*ae));
2456 strncpy(ae->un.AttrString, phba->SerialNumber,
2457 sizeof(ae->un.AttrString));
2458 len = strnlen(ae->un.AttrString,
2459 sizeof(ae->un.AttrString));
2460 len += (len & 3) ? (4 - (len & 3)) : 4;
2461 size = FOURBYTES + len;
2462 ad->AttrLen = cpu_to_be16(size);
2463 ad->AttrType = cpu_to_be16(RHBA_SERIAL_NUMBER);
2468 lpfc_fdmi_hba_attr_model(struct lpfc_vport *vport,
2469 struct lpfc_fdmi_attr_def *ad)
2471 struct lpfc_hba *phba = vport->phba;
2472 struct lpfc_fdmi_attr_entry *ae;
2475 ae = &ad->AttrValue;
2476 memset(ae, 0, sizeof(*ae));
2478 strncpy(ae->un.AttrString, phba->ModelName,
2479 sizeof(ae->un.AttrString));
2480 len = strnlen(ae->un.AttrString, sizeof(ae->un.AttrString));
2481 len += (len & 3) ? (4 - (len & 3)) : 4;
2482 size = FOURBYTES + len;
2483 ad->AttrLen = cpu_to_be16(size);
2484 ad->AttrType = cpu_to_be16(RHBA_MODEL);
2489 lpfc_fdmi_hba_attr_description(struct lpfc_vport *vport,
2490 struct lpfc_fdmi_attr_def *ad)
2492 struct lpfc_hba *phba = vport->phba;
2493 struct lpfc_fdmi_attr_entry *ae;
2496 ae = &ad->AttrValue;
2497 memset(ae, 0, sizeof(*ae));
2499 strncpy(ae->un.AttrString, phba->ModelDesc,
2500 sizeof(ae->un.AttrString));
2501 len = strnlen(ae->un.AttrString,
2502 sizeof(ae->un.AttrString));
2503 len += (len & 3) ? (4 - (len & 3)) : 4;
2504 size = FOURBYTES + len;
2505 ad->AttrLen = cpu_to_be16(size);
2506 ad->AttrType = cpu_to_be16(RHBA_MODEL_DESCRIPTION);
2511 lpfc_fdmi_hba_attr_hdw_ver(struct lpfc_vport *vport,
2512 struct lpfc_fdmi_attr_def *ad)
2514 struct lpfc_hba *phba = vport->phba;
2515 lpfc_vpd_t *vp = &phba->vpd;
2516 struct lpfc_fdmi_attr_entry *ae;
2517 uint32_t i, j, incr, size;
2519 ae = &ad->AttrValue;
2520 memset(ae, 0, sizeof(*ae));
2522 /* Convert JEDEC ID to ascii for hardware version */
2523 incr = vp->rev.biuRev;
2524 for (i = 0; i < 8; i++) {
2527 ae->un.AttrString[7 - i] =
2528 (char)((uint8_t) 0x30 +
2531 ae->un.AttrString[7 - i] =
2532 (char)((uint8_t) 0x61 +
2533 (uint8_t) (j - 10));
2536 size = FOURBYTES + 8;
2537 ad->AttrLen = cpu_to_be16(size);
2538 ad->AttrType = cpu_to_be16(RHBA_HARDWARE_VERSION);
2543 lpfc_fdmi_hba_attr_drvr_ver(struct lpfc_vport *vport,
2544 struct lpfc_fdmi_attr_def *ad)
2546 struct lpfc_fdmi_attr_entry *ae;
2549 ae = &ad->AttrValue;
2550 memset(ae, 0, sizeof(*ae));
2552 strncpy(ae->un.AttrString, lpfc_release_version,
2553 sizeof(ae->un.AttrString));
2554 len = strnlen(ae->un.AttrString,
2555 sizeof(ae->un.AttrString));
2556 len += (len & 3) ? (4 - (len & 3)) : 4;
2557 size = FOURBYTES + len;
2558 ad->AttrLen = cpu_to_be16(size);
2559 ad->AttrType = cpu_to_be16(RHBA_DRIVER_VERSION);
2564 lpfc_fdmi_hba_attr_rom_ver(struct lpfc_vport *vport,
2565 struct lpfc_fdmi_attr_def *ad)
2567 struct lpfc_hba *phba = vport->phba;
2568 struct lpfc_fdmi_attr_entry *ae;
2571 ae = &ad->AttrValue;
2572 memset(ae, 0, sizeof(*ae));
2574 if (phba->sli_rev == LPFC_SLI_REV4)
2575 lpfc_decode_firmware_rev(phba, ae->un.AttrString, 1);
2577 strncpy(ae->un.AttrString, phba->OptionROMVersion,
2578 sizeof(ae->un.AttrString));
2579 len = strnlen(ae->un.AttrString,
2580 sizeof(ae->un.AttrString));
2581 len += (len & 3) ? (4 - (len & 3)) : 4;
2582 size = FOURBYTES + len;
2583 ad->AttrLen = cpu_to_be16(size);
2584 ad->AttrType = cpu_to_be16(RHBA_OPTION_ROM_VERSION);
2589 lpfc_fdmi_hba_attr_fmw_ver(struct lpfc_vport *vport,
2590 struct lpfc_fdmi_attr_def *ad)
2592 struct lpfc_hba *phba = vport->phba;
2593 struct lpfc_fdmi_attr_entry *ae;
2596 ae = &ad->AttrValue;
2597 memset(ae, 0, sizeof(*ae));
2599 lpfc_decode_firmware_rev(phba, ae->un.AttrString, 1);
2600 len = strnlen(ae->un.AttrString,
2601 sizeof(ae->un.AttrString));
2602 len += (len & 3) ? (4 - (len & 3)) : 4;
2603 size = FOURBYTES + len;
2604 ad->AttrLen = cpu_to_be16(size);
2605 ad->AttrType = cpu_to_be16(RHBA_FIRMWARE_VERSION);
2610 lpfc_fdmi_hba_attr_os_ver(struct lpfc_vport *vport,
2611 struct lpfc_fdmi_attr_def *ad)
2613 struct lpfc_fdmi_attr_entry *ae;
2616 ae = &ad->AttrValue;
2617 memset(ae, 0, sizeof(*ae));
2619 snprintf(ae->un.AttrString, sizeof(ae->un.AttrString), "%s %s %s",
2620 init_utsname()->sysname,
2621 init_utsname()->release,
2622 init_utsname()->version);
2624 len = strnlen(ae->un.AttrString, sizeof(ae->un.AttrString));
2625 len += (len & 3) ? (4 - (len & 3)) : 4;
2626 size = FOURBYTES + len;
2627 ad->AttrLen = cpu_to_be16(size);
2628 ad->AttrType = cpu_to_be16(RHBA_OS_NAME_VERSION);
2633 lpfc_fdmi_hba_attr_ct_len(struct lpfc_vport *vport,
2634 struct lpfc_fdmi_attr_def *ad)
2636 struct lpfc_fdmi_attr_entry *ae;
2639 ae = &ad->AttrValue;
2641 ae->un.AttrInt = cpu_to_be32(LPFC_MAX_CT_SIZE);
2642 size = FOURBYTES + sizeof(uint32_t);
2643 ad->AttrLen = cpu_to_be16(size);
2644 ad->AttrType = cpu_to_be16(RHBA_MAX_CT_PAYLOAD_LEN);
2649 lpfc_fdmi_hba_attr_symbolic_name(struct lpfc_vport *vport,
2650 struct lpfc_fdmi_attr_def *ad)
2652 struct lpfc_fdmi_attr_entry *ae;
2655 ae = &ad->AttrValue;
2656 memset(ae, 0, sizeof(*ae));
2658 len = lpfc_vport_symbolic_node_name(vport,
2659 ae->un.AttrString, 256);
2660 len += (len & 3) ? (4 - (len & 3)) : 4;
2661 size = FOURBYTES + len;
2662 ad->AttrLen = cpu_to_be16(size);
2663 ad->AttrType = cpu_to_be16(RHBA_SYM_NODENAME);
2668 lpfc_fdmi_hba_attr_vendor_info(struct lpfc_vport *vport,
2669 struct lpfc_fdmi_attr_def *ad)
2671 struct lpfc_fdmi_attr_entry *ae;
2674 ae = &ad->AttrValue;
2676 /* Nothing is defined for this currently */
2677 ae->un.AttrInt = cpu_to_be32(0);
2678 size = FOURBYTES + sizeof(uint32_t);
2679 ad->AttrLen = cpu_to_be16(size);
2680 ad->AttrType = cpu_to_be16(RHBA_VENDOR_INFO);
2685 lpfc_fdmi_hba_attr_num_ports(struct lpfc_vport *vport,
2686 struct lpfc_fdmi_attr_def *ad)
2688 struct lpfc_fdmi_attr_entry *ae;
2691 ae = &ad->AttrValue;
2693 /* Each driver instance corresponds to a single port */
2694 ae->un.AttrInt = cpu_to_be32(1);
2695 size = FOURBYTES + sizeof(uint32_t);
2696 ad->AttrLen = cpu_to_be16(size);
2697 ad->AttrType = cpu_to_be16(RHBA_NUM_PORTS);
2702 lpfc_fdmi_hba_attr_fabric_wwnn(struct lpfc_vport *vport,
2703 struct lpfc_fdmi_attr_def *ad)
2705 struct lpfc_fdmi_attr_entry *ae;
2708 ae = &ad->AttrValue;
2709 memset(ae, 0, sizeof(*ae));
2711 memcpy(&ae->un.AttrWWN, &vport->fabric_nodename,
2712 sizeof(struct lpfc_name));
2713 size = FOURBYTES + sizeof(struct lpfc_name);
2714 ad->AttrLen = cpu_to_be16(size);
2715 ad->AttrType = cpu_to_be16(RHBA_FABRIC_WWNN);
2720 lpfc_fdmi_hba_attr_bios_ver(struct lpfc_vport *vport,
2721 struct lpfc_fdmi_attr_def *ad)
2723 struct lpfc_hba *phba = vport->phba;
2724 struct lpfc_fdmi_attr_entry *ae;
2727 ae = &ad->AttrValue;
2728 memset(ae, 0, sizeof(*ae));
2730 strlcat(ae->un.AttrString, phba->BIOSVersion,
2731 sizeof(ae->un.AttrString));
2732 len = strnlen(ae->un.AttrString,
2733 sizeof(ae->un.AttrString));
2734 len += (len & 3) ? (4 - (len & 3)) : 4;
2735 size = FOURBYTES + len;
2736 ad->AttrLen = cpu_to_be16(size);
2737 ad->AttrType = cpu_to_be16(RHBA_BIOS_VERSION);
2742 lpfc_fdmi_hba_attr_bios_state(struct lpfc_vport *vport,
2743 struct lpfc_fdmi_attr_def *ad)
2745 struct lpfc_fdmi_attr_entry *ae;
2748 ae = &ad->AttrValue;
2750 /* Driver doesn't have access to this information */
2751 ae->un.AttrInt = cpu_to_be32(0);
2752 size = FOURBYTES + sizeof(uint32_t);
2753 ad->AttrLen = cpu_to_be16(size);
2754 ad->AttrType = cpu_to_be16(RHBA_BIOS_STATE);
2759 lpfc_fdmi_hba_attr_vendor_id(struct lpfc_vport *vport,
2760 struct lpfc_fdmi_attr_def *ad)
2762 struct lpfc_fdmi_attr_entry *ae;
2765 ae = &ad->AttrValue;
2766 memset(ae, 0, sizeof(*ae));
2768 strncpy(ae->un.AttrString, "EMULEX",
2769 sizeof(ae->un.AttrString));
2770 len = strnlen(ae->un.AttrString,
2771 sizeof(ae->un.AttrString));
2772 len += (len & 3) ? (4 - (len & 3)) : 4;
2773 size = FOURBYTES + len;
2774 ad->AttrLen = cpu_to_be16(size);
2775 ad->AttrType = cpu_to_be16(RHBA_VENDOR_ID);
2779 /* Routines for all individual PORT attributes */
2781 lpfc_fdmi_port_attr_fc4type(struct lpfc_vport *vport,
2782 struct lpfc_fdmi_attr_def *ad)
2784 struct lpfc_hba *phba = vport->phba;
2785 struct lpfc_fdmi_attr_entry *ae;
2788 ae = &ad->AttrValue;
2789 memset(ae, 0, sizeof(*ae));
2791 ae->un.AttrTypes[2] = 0x01; /* Type 0x8 - FCP */
2792 ae->un.AttrTypes[7] = 0x01; /* Type 0x20 - CT */
2794 /* Check to see if Firmware supports NVME and on physical port */
2795 if ((phba->sli_rev == LPFC_SLI_REV4) && (vport == phba->pport) &&
2796 phba->sli4_hba.pc_sli4_params.nvme)
2797 ae->un.AttrTypes[6] = 0x01; /* Type 0x28 - NVME */
2799 size = FOURBYTES + 32;
2800 ad->AttrLen = cpu_to_be16(size);
2801 ad->AttrType = cpu_to_be16(RPRT_SUPPORTED_FC4_TYPES);
2806 lpfc_fdmi_port_attr_support_speed(struct lpfc_vport *vport,
2807 struct lpfc_fdmi_attr_def *ad)
2809 struct lpfc_hba *phba = vport->phba;
2810 struct lpfc_fdmi_attr_entry *ae;
2813 ae = &ad->AttrValue;
2816 if (!(phba->hba_flag & HBA_FCOE_MODE)) {
2817 if (phba->lmt & LMT_128Gb)
2818 ae->un.AttrInt |= HBA_PORTSPEED_128GFC;
2819 if (phba->lmt & LMT_64Gb)
2820 ae->un.AttrInt |= HBA_PORTSPEED_64GFC;
2821 if (phba->lmt & LMT_32Gb)
2822 ae->un.AttrInt |= HBA_PORTSPEED_32GFC;
2823 if (phba->lmt & LMT_16Gb)
2824 ae->un.AttrInt |= HBA_PORTSPEED_16GFC;
2825 if (phba->lmt & LMT_10Gb)
2826 ae->un.AttrInt |= HBA_PORTSPEED_10GFC;
2827 if (phba->lmt & LMT_8Gb)
2828 ae->un.AttrInt |= HBA_PORTSPEED_8GFC;
2829 if (phba->lmt & LMT_4Gb)
2830 ae->un.AttrInt |= HBA_PORTSPEED_4GFC;
2831 if (phba->lmt & LMT_2Gb)
2832 ae->un.AttrInt |= HBA_PORTSPEED_2GFC;
2833 if (phba->lmt & LMT_1Gb)
2834 ae->un.AttrInt |= HBA_PORTSPEED_1GFC;
2836 /* FCoE links support only one speed */
2837 switch (phba->fc_linkspeed) {
2838 case LPFC_ASYNC_LINK_SPEED_10GBPS:
2839 ae->un.AttrInt = HBA_PORTSPEED_10GE;
2841 case LPFC_ASYNC_LINK_SPEED_25GBPS:
2842 ae->un.AttrInt = HBA_PORTSPEED_25GE;
2844 case LPFC_ASYNC_LINK_SPEED_40GBPS:
2845 ae->un.AttrInt = HBA_PORTSPEED_40GE;
2847 case LPFC_ASYNC_LINK_SPEED_100GBPS:
2848 ae->un.AttrInt = HBA_PORTSPEED_100GE;
2852 ae->un.AttrInt = cpu_to_be32(ae->un.AttrInt);
2853 size = FOURBYTES + sizeof(uint32_t);
2854 ad->AttrLen = cpu_to_be16(size);
2855 ad->AttrType = cpu_to_be16(RPRT_SUPPORTED_SPEED);
2860 lpfc_fdmi_port_attr_speed(struct lpfc_vport *vport,
2861 struct lpfc_fdmi_attr_def *ad)
2863 struct lpfc_hba *phba = vport->phba;
2864 struct lpfc_fdmi_attr_entry *ae;
2867 ae = &ad->AttrValue;
2869 if (!(phba->hba_flag & HBA_FCOE_MODE)) {
2870 switch (phba->fc_linkspeed) {
2871 case LPFC_LINK_SPEED_1GHZ:
2872 ae->un.AttrInt = HBA_PORTSPEED_1GFC;
2874 case LPFC_LINK_SPEED_2GHZ:
2875 ae->un.AttrInt = HBA_PORTSPEED_2GFC;
2877 case LPFC_LINK_SPEED_4GHZ:
2878 ae->un.AttrInt = HBA_PORTSPEED_4GFC;
2880 case LPFC_LINK_SPEED_8GHZ:
2881 ae->un.AttrInt = HBA_PORTSPEED_8GFC;
2883 case LPFC_LINK_SPEED_10GHZ:
2884 ae->un.AttrInt = HBA_PORTSPEED_10GFC;
2886 case LPFC_LINK_SPEED_16GHZ:
2887 ae->un.AttrInt = HBA_PORTSPEED_16GFC;
2889 case LPFC_LINK_SPEED_32GHZ:
2890 ae->un.AttrInt = HBA_PORTSPEED_32GFC;
2892 case LPFC_LINK_SPEED_64GHZ:
2893 ae->un.AttrInt = HBA_PORTSPEED_64GFC;
2895 case LPFC_LINK_SPEED_128GHZ:
2896 ae->un.AttrInt = HBA_PORTSPEED_128GFC;
2899 ae->un.AttrInt = HBA_PORTSPEED_UNKNOWN;
2903 switch (phba->fc_linkspeed) {
2904 case LPFC_ASYNC_LINK_SPEED_10GBPS:
2905 ae->un.AttrInt = HBA_PORTSPEED_10GE;
2907 case LPFC_ASYNC_LINK_SPEED_25GBPS:
2908 ae->un.AttrInt = HBA_PORTSPEED_25GE;
2910 case LPFC_ASYNC_LINK_SPEED_40GBPS:
2911 ae->un.AttrInt = HBA_PORTSPEED_40GE;
2913 case LPFC_ASYNC_LINK_SPEED_100GBPS:
2914 ae->un.AttrInt = HBA_PORTSPEED_100GE;
2917 ae->un.AttrInt = HBA_PORTSPEED_UNKNOWN;
2922 ae->un.AttrInt = cpu_to_be32(ae->un.AttrInt);
2923 size = FOURBYTES + sizeof(uint32_t);
2924 ad->AttrLen = cpu_to_be16(size);
2925 ad->AttrType = cpu_to_be16(RPRT_PORT_SPEED);
2930 lpfc_fdmi_port_attr_max_frame(struct lpfc_vport *vport,
2931 struct lpfc_fdmi_attr_def *ad)
2933 struct serv_parm *hsp;
2934 struct lpfc_fdmi_attr_entry *ae;
2937 ae = &ad->AttrValue;
2939 hsp = (struct serv_parm *)&vport->fc_sparam;
2940 ae->un.AttrInt = (((uint32_t) hsp->cmn.bbRcvSizeMsb & 0x0F) << 8) |
2941 (uint32_t) hsp->cmn.bbRcvSizeLsb;
2942 ae->un.AttrInt = cpu_to_be32(ae->un.AttrInt);
2943 size = FOURBYTES + sizeof(uint32_t);
2944 ad->AttrLen = cpu_to_be16(size);
2945 ad->AttrType = cpu_to_be16(RPRT_MAX_FRAME_SIZE);
2950 lpfc_fdmi_port_attr_os_devname(struct lpfc_vport *vport,
2951 struct lpfc_fdmi_attr_def *ad)
2953 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2954 struct lpfc_fdmi_attr_entry *ae;
2957 ae = &ad->AttrValue;
2958 memset(ae, 0, sizeof(*ae));
2960 snprintf(ae->un.AttrString, sizeof(ae->un.AttrString),
2961 "/sys/class/scsi_host/host%d", shost->host_no);
2962 len = strnlen((char *)ae->un.AttrString,
2963 sizeof(ae->un.AttrString));
2964 len += (len & 3) ? (4 - (len & 3)) : 4;
2965 size = FOURBYTES + len;
2966 ad->AttrLen = cpu_to_be16(size);
2967 ad->AttrType = cpu_to_be16(RPRT_OS_DEVICE_NAME);
2972 lpfc_fdmi_port_attr_host_name(struct lpfc_vport *vport,
2973 struct lpfc_fdmi_attr_def *ad)
2975 struct lpfc_fdmi_attr_entry *ae;
2978 ae = &ad->AttrValue;
2979 memset(ae, 0, sizeof(*ae));
2981 scnprintf(ae->un.AttrString, sizeof(ae->un.AttrString), "%s",
2982 vport->phba->os_host_name);
2984 len = strnlen(ae->un.AttrString, sizeof(ae->un.AttrString));
2985 len += (len & 3) ? (4 - (len & 3)) : 4;
2986 size = FOURBYTES + len;
2987 ad->AttrLen = cpu_to_be16(size);
2988 ad->AttrType = cpu_to_be16(RPRT_HOST_NAME);
2993 lpfc_fdmi_port_attr_wwnn(struct lpfc_vport *vport,
2994 struct lpfc_fdmi_attr_def *ad)
2996 struct lpfc_fdmi_attr_entry *ae;
2999 ae = &ad->AttrValue;
3000 memset(ae, 0, sizeof(*ae));
3002 memcpy(&ae->un.AttrWWN, &vport->fc_sparam.nodeName,
3003 sizeof(struct lpfc_name));
3004 size = FOURBYTES + sizeof(struct lpfc_name);
3005 ad->AttrLen = cpu_to_be16(size);
3006 ad->AttrType = cpu_to_be16(RPRT_NODENAME);
3011 lpfc_fdmi_port_attr_wwpn(struct lpfc_vport *vport,
3012 struct lpfc_fdmi_attr_def *ad)
3014 struct lpfc_fdmi_attr_entry *ae;
3017 ae = &ad->AttrValue;
3018 memset(ae, 0, sizeof(*ae));
3020 memcpy(&ae->un.AttrWWN, &vport->fc_sparam.portName,
3021 sizeof(struct lpfc_name));
3022 size = FOURBYTES + sizeof(struct lpfc_name);
3023 ad->AttrLen = cpu_to_be16(size);
3024 ad->AttrType = cpu_to_be16(RPRT_PORTNAME);
3029 lpfc_fdmi_port_attr_symbolic_name(struct lpfc_vport *vport,
3030 struct lpfc_fdmi_attr_def *ad)
3032 struct lpfc_fdmi_attr_entry *ae;
3035 ae = &ad->AttrValue;
3036 memset(ae, 0, sizeof(*ae));
3038 len = lpfc_vport_symbolic_port_name(vport, ae->un.AttrString, 256);
3039 len += (len & 3) ? (4 - (len & 3)) : 4;
3040 size = FOURBYTES + len;
3041 ad->AttrLen = cpu_to_be16(size);
3042 ad->AttrType = cpu_to_be16(RPRT_SYM_PORTNAME);
3047 lpfc_fdmi_port_attr_port_type(struct lpfc_vport *vport,
3048 struct lpfc_fdmi_attr_def *ad)
3050 struct lpfc_hba *phba = vport->phba;
3051 struct lpfc_fdmi_attr_entry *ae;
3054 ae = &ad->AttrValue;
3055 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP)
3056 ae->un.AttrInt = cpu_to_be32(LPFC_FDMI_PORTTYPE_NLPORT);
3058 ae->un.AttrInt = cpu_to_be32(LPFC_FDMI_PORTTYPE_NPORT);
3059 size = FOURBYTES + sizeof(uint32_t);
3060 ad->AttrLen = cpu_to_be16(size);
3061 ad->AttrType = cpu_to_be16(RPRT_PORT_TYPE);
3066 lpfc_fdmi_port_attr_class(struct lpfc_vport *vport,
3067 struct lpfc_fdmi_attr_def *ad)
3069 struct lpfc_fdmi_attr_entry *ae;
3072 ae = &ad->AttrValue;
3073 ae->un.AttrInt = cpu_to_be32(FC_COS_CLASS2 | FC_COS_CLASS3);
3074 size = FOURBYTES + sizeof(uint32_t);
3075 ad->AttrLen = cpu_to_be16(size);
3076 ad->AttrType = cpu_to_be16(RPRT_SUPPORTED_CLASS);
3081 lpfc_fdmi_port_attr_fabric_wwpn(struct lpfc_vport *vport,
3082 struct lpfc_fdmi_attr_def *ad)
3084 struct lpfc_fdmi_attr_entry *ae;
3087 ae = &ad->AttrValue;
3088 memset(ae, 0, sizeof(*ae));
3090 memcpy(&ae->un.AttrWWN, &vport->fabric_portname,
3091 sizeof(struct lpfc_name));
3092 size = FOURBYTES + sizeof(struct lpfc_name);
3093 ad->AttrLen = cpu_to_be16(size);
3094 ad->AttrType = cpu_to_be16(RPRT_FABRICNAME);
3099 lpfc_fdmi_port_attr_active_fc4type(struct lpfc_vport *vport,
3100 struct lpfc_fdmi_attr_def *ad)
3102 struct lpfc_fdmi_attr_entry *ae;
3105 ae = &ad->AttrValue;
3106 memset(ae, 0, sizeof(*ae));
3108 ae->un.AttrTypes[2] = 0x01; /* Type 0x8 - FCP */
3109 ae->un.AttrTypes[7] = 0x01; /* Type 0x20 - CT */
3111 /* Check to see if NVME is configured or not */
3112 if (vport->phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)
3113 ae->un.AttrTypes[6] = 0x1; /* Type 0x28 - NVME */
3115 size = FOURBYTES + 32;
3116 ad->AttrLen = cpu_to_be16(size);
3117 ad->AttrType = cpu_to_be16(RPRT_ACTIVE_FC4_TYPES);
3122 lpfc_fdmi_port_attr_port_state(struct lpfc_vport *vport,
3123 struct lpfc_fdmi_attr_def *ad)
3125 struct lpfc_fdmi_attr_entry *ae;
3128 ae = &ad->AttrValue;
3129 /* Link Up - operational */
3130 ae->un.AttrInt = cpu_to_be32(LPFC_FDMI_PORTSTATE_ONLINE);
3131 size = FOURBYTES + sizeof(uint32_t);
3132 ad->AttrLen = cpu_to_be16(size);
3133 ad->AttrType = cpu_to_be16(RPRT_PORT_STATE);
3138 lpfc_fdmi_port_attr_num_disc(struct lpfc_vport *vport,
3139 struct lpfc_fdmi_attr_def *ad)
3141 struct lpfc_fdmi_attr_entry *ae;
3144 ae = &ad->AttrValue;
3145 vport->fdmi_num_disc = lpfc_find_map_node(vport);
3146 ae->un.AttrInt = cpu_to_be32(vport->fdmi_num_disc);
3147 size = FOURBYTES + sizeof(uint32_t);
3148 ad->AttrLen = cpu_to_be16(size);
3149 ad->AttrType = cpu_to_be16(RPRT_DISC_PORT);
3154 lpfc_fdmi_port_attr_nportid(struct lpfc_vport *vport,
3155 struct lpfc_fdmi_attr_def *ad)
3157 struct lpfc_fdmi_attr_entry *ae;
3160 ae = &ad->AttrValue;
3161 ae->un.AttrInt = cpu_to_be32(vport->fc_myDID);
3162 size = FOURBYTES + sizeof(uint32_t);
3163 ad->AttrLen = cpu_to_be16(size);
3164 ad->AttrType = cpu_to_be16(RPRT_PORT_ID);
3169 lpfc_fdmi_smart_attr_service(struct lpfc_vport *vport,
3170 struct lpfc_fdmi_attr_def *ad)
3172 struct lpfc_fdmi_attr_entry *ae;
3175 ae = &ad->AttrValue;
3176 memset(ae, 0, sizeof(*ae));
3178 strncpy(ae->un.AttrString, "Smart SAN Initiator",
3179 sizeof(ae->un.AttrString));
3180 len = strnlen(ae->un.AttrString,
3181 sizeof(ae->un.AttrString));
3182 len += (len & 3) ? (4 - (len & 3)) : 4;
3183 size = FOURBYTES + len;
3184 ad->AttrLen = cpu_to_be16(size);
3185 ad->AttrType = cpu_to_be16(RPRT_SMART_SERVICE);
3190 lpfc_fdmi_smart_attr_guid(struct lpfc_vport *vport,
3191 struct lpfc_fdmi_attr_def *ad)
3193 struct lpfc_fdmi_attr_entry *ae;
3196 ae = &ad->AttrValue;
3197 memset(ae, 0, sizeof(*ae));
3199 memcpy(&ae->un.AttrString, &vport->fc_sparam.nodeName,
3200 sizeof(struct lpfc_name));
3201 memcpy((((uint8_t *)&ae->un.AttrString) +
3202 sizeof(struct lpfc_name)),
3203 &vport->fc_sparam.portName, sizeof(struct lpfc_name));
3204 size = FOURBYTES + (2 * sizeof(struct lpfc_name));
3205 ad->AttrLen = cpu_to_be16(size);
3206 ad->AttrType = cpu_to_be16(RPRT_SMART_GUID);
3211 lpfc_fdmi_smart_attr_version(struct lpfc_vport *vport,
3212 struct lpfc_fdmi_attr_def *ad)
3214 struct lpfc_fdmi_attr_entry *ae;
3217 ae = &ad->AttrValue;
3218 memset(ae, 0, sizeof(*ae));
3220 strncpy(ae->un.AttrString, "Smart SAN Version 2.0",
3221 sizeof(ae->un.AttrString));
3222 len = strnlen(ae->un.AttrString,
3223 sizeof(ae->un.AttrString));
3224 len += (len & 3) ? (4 - (len & 3)) : 4;
3225 size = FOURBYTES + len;
3226 ad->AttrLen = cpu_to_be16(size);
3227 ad->AttrType = cpu_to_be16(RPRT_SMART_VERSION);
3232 lpfc_fdmi_smart_attr_model(struct lpfc_vport *vport,
3233 struct lpfc_fdmi_attr_def *ad)
3235 struct lpfc_hba *phba = vport->phba;
3236 struct lpfc_fdmi_attr_entry *ae;
3239 ae = &ad->AttrValue;
3240 memset(ae, 0, sizeof(*ae));
3242 strncpy(ae->un.AttrString, phba->ModelName,
3243 sizeof(ae->un.AttrString));
3244 len = strnlen(ae->un.AttrString, sizeof(ae->un.AttrString));
3245 len += (len & 3) ? (4 - (len & 3)) : 4;
3246 size = FOURBYTES + len;
3247 ad->AttrLen = cpu_to_be16(size);
3248 ad->AttrType = cpu_to_be16(RPRT_SMART_MODEL);
3253 lpfc_fdmi_smart_attr_port_info(struct lpfc_vport *vport,
3254 struct lpfc_fdmi_attr_def *ad)
3256 struct lpfc_fdmi_attr_entry *ae;
3259 ae = &ad->AttrValue;
3261 /* SRIOV (type 3) is not supported */
3263 ae->un.AttrInt = cpu_to_be32(2); /* NPIV */
3265 ae->un.AttrInt = cpu_to_be32(1); /* Physical */
3266 size = FOURBYTES + sizeof(uint32_t);
3267 ad->AttrLen = cpu_to_be16(size);
3268 ad->AttrType = cpu_to_be16(RPRT_SMART_PORT_INFO);
3273 lpfc_fdmi_smart_attr_qos(struct lpfc_vport *vport,
3274 struct lpfc_fdmi_attr_def *ad)
3276 struct lpfc_fdmi_attr_entry *ae;
3279 ae = &ad->AttrValue;
3280 ae->un.AttrInt = cpu_to_be32(0);
3281 size = FOURBYTES + sizeof(uint32_t);
3282 ad->AttrLen = cpu_to_be16(size);
3283 ad->AttrType = cpu_to_be16(RPRT_SMART_QOS);
3288 lpfc_fdmi_smart_attr_security(struct lpfc_vport *vport,
3289 struct lpfc_fdmi_attr_def *ad)
3291 struct lpfc_fdmi_attr_entry *ae;
3294 ae = &ad->AttrValue;
3295 ae->un.AttrInt = cpu_to_be32(1);
3296 size = FOURBYTES + sizeof(uint32_t);
3297 ad->AttrLen = cpu_to_be16(size);
3298 ad->AttrType = cpu_to_be16(RPRT_SMART_SECURITY);
3303 lpfc_fdmi_vendor_attr_mi(struct lpfc_vport *vport,
3304 struct lpfc_fdmi_attr_def *ad)
3306 struct lpfc_hba *phba = vport->phba;
3307 struct lpfc_fdmi_attr_entry *ae;
3309 char mibrevision[16];
3311 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
3313 sprintf(mibrevision, "ELXE2EM:%04d",
3314 phba->sli4_hba.pc_sli4_params.mi_value);
3315 strncpy(ae->un.AttrString, &mibrevision[0], sizeof(ae->un.AttrString));
3316 len = strnlen(ae->un.AttrString, sizeof(ae->un.AttrString));
3317 len += (len & 3) ? (4 - (len & 3)) : 4;
3318 size = FOURBYTES + len;
3319 ad->AttrLen = cpu_to_be16(size);
3320 ad->AttrType = cpu_to_be16(RPRT_VENDOR_MI);
3324 /* RHBA attribute jump table */
3325 int (*lpfc_fdmi_hba_action[])
3326 (struct lpfc_vport *vport, struct lpfc_fdmi_attr_def *ad) = {
3327 /* Action routine Mask bit Attribute type */
3328 lpfc_fdmi_hba_attr_wwnn, /* bit0 RHBA_NODENAME */
3329 lpfc_fdmi_hba_attr_manufacturer, /* bit1 RHBA_MANUFACTURER */
3330 lpfc_fdmi_hba_attr_sn, /* bit2 RHBA_SERIAL_NUMBER */
3331 lpfc_fdmi_hba_attr_model, /* bit3 RHBA_MODEL */
3332 lpfc_fdmi_hba_attr_description, /* bit4 RHBA_MODEL_DESCRIPTION */
3333 lpfc_fdmi_hba_attr_hdw_ver, /* bit5 RHBA_HARDWARE_VERSION */
3334 lpfc_fdmi_hba_attr_drvr_ver, /* bit6 RHBA_DRIVER_VERSION */
3335 lpfc_fdmi_hba_attr_rom_ver, /* bit7 RHBA_OPTION_ROM_VERSION */
3336 lpfc_fdmi_hba_attr_fmw_ver, /* bit8 RHBA_FIRMWARE_VERSION */
3337 lpfc_fdmi_hba_attr_os_ver, /* bit9 RHBA_OS_NAME_VERSION */
3338 lpfc_fdmi_hba_attr_ct_len, /* bit10 RHBA_MAX_CT_PAYLOAD_LEN */
3339 lpfc_fdmi_hba_attr_symbolic_name, /* bit11 RHBA_SYM_NODENAME */
3340 lpfc_fdmi_hba_attr_vendor_info, /* bit12 RHBA_VENDOR_INFO */
3341 lpfc_fdmi_hba_attr_num_ports, /* bit13 RHBA_NUM_PORTS */
3342 lpfc_fdmi_hba_attr_fabric_wwnn, /* bit14 RHBA_FABRIC_WWNN */
3343 lpfc_fdmi_hba_attr_bios_ver, /* bit15 RHBA_BIOS_VERSION */
3344 lpfc_fdmi_hba_attr_bios_state, /* bit16 RHBA_BIOS_STATE */
3345 lpfc_fdmi_hba_attr_vendor_id, /* bit17 RHBA_VENDOR_ID */
3348 /* RPA / RPRT attribute jump table */
3349 int (*lpfc_fdmi_port_action[])
3350 (struct lpfc_vport *vport, struct lpfc_fdmi_attr_def *ad) = {
3351 /* Action routine Mask bit Attribute type */
3352 lpfc_fdmi_port_attr_fc4type, /* bit0 RPRT_SUPPORT_FC4_TYPES */
3353 lpfc_fdmi_port_attr_support_speed, /* bit1 RPRT_SUPPORTED_SPEED */
3354 lpfc_fdmi_port_attr_speed, /* bit2 RPRT_PORT_SPEED */
3355 lpfc_fdmi_port_attr_max_frame, /* bit3 RPRT_MAX_FRAME_SIZE */
3356 lpfc_fdmi_port_attr_os_devname, /* bit4 RPRT_OS_DEVICE_NAME */
3357 lpfc_fdmi_port_attr_host_name, /* bit5 RPRT_HOST_NAME */
3358 lpfc_fdmi_port_attr_wwnn, /* bit6 RPRT_NODENAME */
3359 lpfc_fdmi_port_attr_wwpn, /* bit7 RPRT_PORTNAME */
3360 lpfc_fdmi_port_attr_symbolic_name, /* bit8 RPRT_SYM_PORTNAME */
3361 lpfc_fdmi_port_attr_port_type, /* bit9 RPRT_PORT_TYPE */
3362 lpfc_fdmi_port_attr_class, /* bit10 RPRT_SUPPORTED_CLASS */
3363 lpfc_fdmi_port_attr_fabric_wwpn, /* bit11 RPRT_FABRICNAME */
3364 lpfc_fdmi_port_attr_active_fc4type, /* bit12 RPRT_ACTIVE_FC4_TYPES */
3365 lpfc_fdmi_port_attr_port_state, /* bit13 RPRT_PORT_STATE */
3366 lpfc_fdmi_port_attr_num_disc, /* bit14 RPRT_DISC_PORT */
3367 lpfc_fdmi_port_attr_nportid, /* bit15 RPRT_PORT_ID */
3368 lpfc_fdmi_smart_attr_service, /* bit16 RPRT_SMART_SERVICE */
3369 lpfc_fdmi_smart_attr_guid, /* bit17 RPRT_SMART_GUID */
3370 lpfc_fdmi_smart_attr_version, /* bit18 RPRT_SMART_VERSION */
3371 lpfc_fdmi_smart_attr_model, /* bit19 RPRT_SMART_MODEL */
3372 lpfc_fdmi_smart_attr_port_info, /* bit20 RPRT_SMART_PORT_INFO */
3373 lpfc_fdmi_smart_attr_qos, /* bit21 RPRT_SMART_QOS */
3374 lpfc_fdmi_smart_attr_security, /* bit22 RPRT_SMART_SECURITY */
3375 lpfc_fdmi_vendor_attr_mi, /* bit23 RPRT_VENDOR_MI */
3379 * lpfc_fdmi_cmd - Build and send a FDMI cmd to the specified NPort
3380 * @vport: pointer to a host virtual N_Port data structure.
3381 * @ndlp: ndlp to send FDMI cmd to (if NULL use FDMI_DID)
3382 * @cmdcode: FDMI command to send
3383 * @new_mask: Mask of HBA or PORT Attributes to send
3385 * Builds and sends a FDMI command using the CT subsystem.
3388 lpfc_fdmi_cmd(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
3389 int cmdcode, uint32_t new_mask)
3391 struct lpfc_hba *phba = vport->phba;
3392 struct lpfc_dmabuf *mp, *bmp;
3393 struct lpfc_sli_ct_request *CtReq;
3394 struct ulp_bde64 *bpl;
3399 struct lpfc_fdmi_reg_hba *rh;
3400 struct lpfc_fdmi_port_entry *pe;
3401 struct lpfc_fdmi_reg_portattr *pab = NULL;
3402 struct lpfc_fdmi_attr_block *ab = NULL;
3403 int (*func)(struct lpfc_vport *vport, struct lpfc_fdmi_attr_def *ad);
3404 void (*cmpl)(struct lpfc_hba *, struct lpfc_iocbq *,
3405 struct lpfc_iocbq *);
3410 cmpl = lpfc_cmpl_ct_disc_fdmi; /* called from discovery */
3412 /* fill in BDEs for command */
3413 /* Allocate buffer for command payload */
3414 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
3418 mp->virt = lpfc_mbuf_alloc(phba, 0, &(mp->phys));
3420 goto fdmi_cmd_free_mp;
3422 /* Allocate buffer for Buffer ptr list */
3423 bmp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
3425 goto fdmi_cmd_free_mpvirt;
3427 bmp->virt = lpfc_mbuf_alloc(phba, 0, &(bmp->phys));
3429 goto fdmi_cmd_free_bmp;
3431 INIT_LIST_HEAD(&mp->list);
3432 INIT_LIST_HEAD(&bmp->list);
3435 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
3436 "0218 FDMI Request Data: x%x x%x x%x\n",
3437 vport->fc_flag, vport->port_state, cmdcode);
3438 CtReq = (struct lpfc_sli_ct_request *)mp->virt;
3440 /* First populate the CT_IU preamble */
3441 memset(CtReq, 0, sizeof(struct lpfc_sli_ct_request));
3442 CtReq->RevisionId.bits.Revision = SLI_CT_REVISION;
3443 CtReq->RevisionId.bits.InId = 0;
3445 CtReq->FsType = SLI_CT_MANAGEMENT_SERVICE;
3446 CtReq->FsSubType = SLI_CT_FDMI_Subtypes;
3448 CtReq->CommandResponse.bits.CmdRsp = cpu_to_be16(cmdcode);
3449 rsp_size = LPFC_BPL_SIZE;
3452 /* Next fill in the specific FDMI cmd information */
3456 rh = (struct lpfc_fdmi_reg_hba *)&CtReq->un.PortID;
3457 /* HBA Identifier */
3458 memcpy(&rh->hi.PortName, &phba->pport->fc_sparam.portName,
3459 sizeof(struct lpfc_name));
3461 if (cmdcode == SLI_MGMT_RHBA) {
3462 /* Registered Port List */
3463 /* One entry (port) per adapter */
3464 rh->rpl.EntryCnt = cpu_to_be32(1);
3465 memcpy(&rh->rpl.pe.PortName,
3466 &phba->pport->fc_sparam.portName,
3467 sizeof(struct lpfc_name));
3469 /* point to the HBA attribute block */
3470 size = 2 * sizeof(struct lpfc_name) +
3473 size = sizeof(struct lpfc_name);
3475 ab = (struct lpfc_fdmi_attr_block *)((uint8_t *)rh + size);
3482 mask = vport->fdmi_hba_mask;
3484 /* Mask will dictate what attributes to build in the request */
3487 func = lpfc_fdmi_hba_action[bit_pos];
3489 (struct lpfc_fdmi_attr_def *)
3490 ((uint8_t *)rh + size));
3493 (LPFC_BPL_SIZE - LPFC_CT_PREAMBLE))
3500 ab->EntryCnt = cpu_to_be32(ab->EntryCnt);
3502 size = GID_REQUEST_SZ - 4 + size;
3507 pab = (struct lpfc_fdmi_reg_portattr *)&CtReq->un.PortID;
3508 if (cmdcode == SLI_MGMT_RPRT) {
3509 rh = (struct lpfc_fdmi_reg_hba *)pab;
3510 /* HBA Identifier */
3511 memcpy(&rh->hi.PortName,
3512 &phba->pport->fc_sparam.portName,
3513 sizeof(struct lpfc_name));
3514 pab = (struct lpfc_fdmi_reg_portattr *)
3515 ((uint8_t *)pab + sizeof(struct lpfc_name));
3518 memcpy((uint8_t *)&pab->PortName,
3519 (uint8_t *)&vport->fc_sparam.portName,
3520 sizeof(struct lpfc_name));
3521 size += sizeof(struct lpfc_name) + FOURBYTES;
3522 pab->ab.EntryCnt = 0;
3527 mask = vport->fdmi_port_mask;
3529 /* Mask will dictate what attributes to build in the request */
3532 func = lpfc_fdmi_port_action[bit_pos];
3534 (struct lpfc_fdmi_attr_def *)
3535 ((uint8_t *)pab + size));
3538 (LPFC_BPL_SIZE - LPFC_CT_PREAMBLE))
3545 pab->ab.EntryCnt = cpu_to_be32(pab->ab.EntryCnt);
3547 if (cmdcode == SLI_MGMT_RPRT)
3548 size += sizeof(struct lpfc_name);
3549 size = GID_REQUEST_SZ - 4 + size;
3554 rsp_size = FC_MAX_NS_RSP;
3558 pe = (struct lpfc_fdmi_port_entry *)&CtReq->un.PortID;
3559 memcpy((uint8_t *)&pe->PortName,
3560 (uint8_t *)&vport->fc_sparam.portName,
3561 sizeof(struct lpfc_name));
3562 size = GID_REQUEST_SZ - 4 + sizeof(struct lpfc_name);
3567 rsp_size = FC_MAX_NS_RSP;
3571 pe = (struct lpfc_fdmi_port_entry *)&CtReq->un.PortID;
3572 memcpy((uint8_t *)&pe->PortName,
3573 (uint8_t *)&vport->fc_sparam.portName,
3574 sizeof(struct lpfc_name));
3575 size = GID_REQUEST_SZ - 4 + sizeof(struct lpfc_name);
3578 size = GID_REQUEST_SZ - 4;
3581 lpfc_printf_vlog(vport, KERN_WARNING, LOG_DISCOVERY,
3582 "0298 FDMI cmdcode x%x not supported\n",
3584 goto fdmi_cmd_free_bmpvirt;
3586 CtReq->CommandResponse.bits.Size = cpu_to_be16(rsp_size);
3588 bpl = (struct ulp_bde64 *)bmp->virt;
3589 bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys));
3590 bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys));
3591 bpl->tus.f.bdeFlags = 0;
3592 bpl->tus.f.bdeSize = size;
3595 * The lpfc_ct_cmd/lpfc_get_req shall increment ndlp reference count
3596 * to hold ndlp reference for the corresponding callback function.
3598 if (!lpfc_ct_cmd(vport, mp, bmp, ndlp, cmpl, rsp_size, 0))
3601 fdmi_cmd_free_bmpvirt:
3602 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
3605 fdmi_cmd_free_mpvirt:
3606 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3610 /* Issue FDMI request failed */
3611 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
3612 "0244 Issue FDMI request failed Data: x%x\n",
3618 * lpfc_delayed_disc_tmo - Timeout handler for delayed discovery timer.
3619 * @t: Context object of the timer.
3621 * This function set the WORKER_DELAYED_DISC_TMO flag and wake up
3622 * the worker thread.
3625 lpfc_delayed_disc_tmo(struct timer_list *t)
3627 struct lpfc_vport *vport = from_timer(vport, t, delayed_disc_tmo);
3628 struct lpfc_hba *phba = vport->phba;
3629 uint32_t tmo_posted;
3630 unsigned long iflag;
3632 spin_lock_irqsave(&vport->work_port_lock, iflag);
3633 tmo_posted = vport->work_port_events & WORKER_DELAYED_DISC_TMO;
3635 vport->work_port_events |= WORKER_DELAYED_DISC_TMO;
3636 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
3639 lpfc_worker_wake_up(phba);
3644 * lpfc_delayed_disc_timeout_handler - Function called by worker thread to
3645 * handle delayed discovery.
3646 * @vport: pointer to a host virtual N_Port data structure.
3648 * This function start nport discovery of the vport.
3651 lpfc_delayed_disc_timeout_handler(struct lpfc_vport *vport)
3653 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3655 spin_lock_irq(shost->host_lock);
3656 if (!(vport->fc_flag & FC_DISC_DELAYED)) {
3657 spin_unlock_irq(shost->host_lock);
3660 vport->fc_flag &= ~FC_DISC_DELAYED;
3661 spin_unlock_irq(shost->host_lock);
3663 lpfc_do_scr_ns_plogi(vport->phba, vport);
3667 lpfc_decode_firmware_rev(struct lpfc_hba *phba, char *fwrevision, int flag)
3669 struct lpfc_sli *psli = &phba->sli;
3670 lpfc_vpd_t *vp = &phba->vpd;
3671 uint32_t b1, b2, b3, b4, i, rev;
3673 uint32_t *ptr, str[4];
3676 if (phba->sli_rev == LPFC_SLI_REV4)
3677 snprintf(fwrevision, FW_REV_STR_SIZE, "%s", vp->rev.opFwName);
3678 else if (vp->rev.rBit) {
3679 if (psli->sli_flag & LPFC_SLI_ACTIVE)
3680 rev = vp->rev.sli2FwRev;
3682 rev = vp->rev.sli1FwRev;
3684 b1 = (rev & 0x0000f000) >> 12;
3685 b2 = (rev & 0x00000f00) >> 8;
3686 b3 = (rev & 0x000000c0) >> 6;
3687 b4 = (rev & 0x00000030) >> 4;
3706 b4 = (rev & 0x0000000f);
3708 if (psli->sli_flag & LPFC_SLI_ACTIVE)
3709 fwname = vp->rev.sli2FwName;
3711 fwname = vp->rev.sli1FwName;
3713 for (i = 0; i < 16; i++)
3714 if (fwname[i] == 0x20)
3717 ptr = (uint32_t*)fwname;
3719 for (i = 0; i < 3; i++)
3720 str[i] = be32_to_cpu(*ptr++);
3724 sprintf(fwrevision, "%d.%d%d (%s)",
3725 b1, b2, b3, (char *)str);
3727 sprintf(fwrevision, "%d.%d%d", b1,
3731 sprintf(fwrevision, "%d.%d%d%c%d (%s)",
3735 sprintf(fwrevision, "%d.%d%d%c%d",
3739 rev = vp->rev.smFwRev;
3741 b1 = (rev & 0xff000000) >> 24;
3742 b2 = (rev & 0x00f00000) >> 20;
3743 b3 = (rev & 0x000f0000) >> 16;
3744 c = (rev & 0x0000ff00) >> 8;
3745 b4 = (rev & 0x000000ff);
3747 sprintf(fwrevision, "%d.%d%d%c%d", b1, b2, b3, c, b4);