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;
79 lpfc_cmpl_ct_cmd_vmid(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
80 struct lpfc_iocbq *rspiocb);
83 lpfc_ct_ignore_hbq_buffer(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq,
84 struct lpfc_dmabuf *mp, uint32_t size)
87 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
88 "0146 Ignoring unsolicited CT No HBQ "
90 piocbq->iocb.ulpStatus);
92 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
93 "0145 Ignoring unsolicted CT HBQ Size:%d "
95 size, piocbq->iocb.ulpStatus);
99 lpfc_ct_unsol_buffer(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq,
100 struct lpfc_dmabuf *mp, uint32_t size)
102 lpfc_ct_ignore_hbq_buffer(phba, piocbq, mp, size);
106 * lpfc_ct_unsol_cmpl : Completion callback function for unsol ct commands
107 * @phba : pointer to lpfc hba data structure.
108 * @cmdiocb : pointer to lpfc command iocb data structure.
109 * @rspiocb : pointer to lpfc response iocb data structure.
111 * This routine is the callback function for issuing unsol ct reject command.
112 * The memory allocated in the reject command path is freed up here.
115 lpfc_ct_unsol_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
116 struct lpfc_iocbq *rspiocb)
118 struct lpfc_nodelist *ndlp;
119 struct lpfc_dmabuf *mp, *bmp;
121 ndlp = (struct lpfc_nodelist *)cmdiocb->context1;
125 mp = cmdiocb->context2;
126 bmp = cmdiocb->context3;
128 lpfc_mbuf_free(phba, mp->virt, mp->phys);
130 cmdiocb->context2 = NULL;
134 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
136 cmdiocb->context3 = NULL;
139 lpfc_sli_release_iocbq(phba, cmdiocb);
143 * lpfc_ct_reject_event - Issue reject for unhandled CT MIB commands
144 * @ndlp: pointer to a node-list data structure.
145 * @ct_req: pointer to the CT request data structure.
146 * @rx_id: rx_id of the received UNSOL CT command
147 * @ox_id: ox_id of the UNSOL CT command
149 * This routine is invoked by the lpfc_ct_handle_mibreq routine for sending
150 * a reject response. Reject response is sent for the unhandled commands.
153 lpfc_ct_reject_event(struct lpfc_nodelist *ndlp,
154 struct lpfc_sli_ct_request *ct_req,
155 u16 rx_id, u16 ox_id)
157 struct lpfc_vport *vport = ndlp->vport;
158 struct lpfc_hba *phba = vport->phba;
159 struct lpfc_sli_ct_request *ct_rsp;
160 struct lpfc_iocbq *cmdiocbq = NULL;
161 struct lpfc_dmabuf *bmp = NULL;
162 struct lpfc_dmabuf *mp = NULL;
163 struct ulp_bde64 *bpl;
167 /* fill in BDEs for command */
168 mp = kmalloc(sizeof(*mp), GFP_KERNEL);
174 mp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &mp->phys);
180 /* Allocate buffer for Buffer ptr list */
181 bmp = kmalloc(sizeof(*bmp), GFP_KERNEL);
187 bmp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &bmp->phys);
193 INIT_LIST_HEAD(&mp->list);
194 INIT_LIST_HEAD(&bmp->list);
196 bpl = (struct ulp_bde64 *)bmp->virt;
197 memset(bpl, 0, sizeof(struct ulp_bde64));
198 bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys));
199 bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys));
200 bpl->tus.f.bdeFlags = BUFF_TYPE_BLP_64;
201 bpl->tus.f.bdeSize = (LPFC_CT_PREAMBLE - 4);
202 bpl->tus.w = le32_to_cpu(bpl->tus.w);
204 ct_rsp = (struct lpfc_sli_ct_request *)mp->virt;
205 memset(ct_rsp, 0, sizeof(struct lpfc_sli_ct_request));
207 ct_rsp->RevisionId.bits.Revision = SLI_CT_REVISION;
208 ct_rsp->RevisionId.bits.InId = 0;
209 ct_rsp->FsType = ct_req->FsType;
210 ct_rsp->FsSubType = ct_req->FsSubType;
211 ct_rsp->CommandResponse.bits.Size = 0;
212 ct_rsp->CommandResponse.bits.CmdRsp =
213 cpu_to_be16(SLI_CT_RESPONSE_FS_RJT);
214 ct_rsp->ReasonCode = SLI_CT_REQ_NOT_SUPPORTED;
215 ct_rsp->Explanation = SLI_CT_NO_ADDITIONAL_EXPL;
217 cmdiocbq = lpfc_sli_get_iocbq(phba);
220 goto ct_free_bmpvirt;
223 icmd = &cmdiocbq->iocb;
224 icmd->un.genreq64.bdl.ulpIoTag32 = 0;
225 icmd->un.genreq64.bdl.addrHigh = putPaddrHigh(bmp->phys);
226 icmd->un.genreq64.bdl.addrLow = putPaddrLow(bmp->phys);
227 icmd->un.genreq64.bdl.bdeFlags = BUFF_TYPE_BLP_64;
228 icmd->un.genreq64.bdl.bdeSize = sizeof(struct ulp_bde64);
229 icmd->un.genreq64.w5.hcsw.Fctl = (LS | LA);
230 icmd->un.genreq64.w5.hcsw.Dfctl = 0;
231 icmd->un.genreq64.w5.hcsw.Rctl = FC_RCTL_DD_SOL_CTL;
232 icmd->un.genreq64.w5.hcsw.Type = FC_TYPE_CT;
233 icmd->ulpCommand = CMD_XMIT_SEQUENCE64_CX;
234 icmd->ulpBdeCount = 1;
236 icmd->ulpClass = CLASS3;
238 /* Save for completion so we can release these resources */
239 cmdiocbq->context1 = lpfc_nlp_get(ndlp);
240 cmdiocbq->context2 = (uint8_t *)mp;
241 cmdiocbq->context3 = (uint8_t *)bmp;
242 cmdiocbq->iocb_cmpl = lpfc_ct_unsol_cmpl;
243 icmd->ulpContext = rx_id; /* Xri / rx_id */
244 icmd->unsli3.rcvsli3.ox_id = ox_id;
245 icmd->un.ulpWord[3] =
246 phba->sli4_hba.rpi_ids[ndlp->nlp_rpi];
247 icmd->ulpTimeout = (3 * phba->fc_ratov);
250 cmdiocbq->vport = vport;
251 cmdiocbq->context_un.ndlp = NULL;
252 cmdiocbq->drvrTimeout = icmd->ulpTimeout + LPFC_DRVR_TIMEOUT;
254 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, cmdiocbq, 0);
260 lpfc_sli_release_iocbq(phba, cmdiocbq);
262 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
266 lpfc_mbuf_free(phba, mp->virt, mp->phys);
270 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
271 "6440 Unsol CT: Rsp err %d Data: x%x\n",
276 * lpfc_ct_handle_mibreq - Process an unsolicited CT MIB request data buffer
277 * @phba: pointer to lpfc hba data structure.
278 * @ctiocbq: pointer to lpfc CT command iocb data structure.
280 * This routine is used for processing the IOCB associated with a unsolicited
281 * CT MIB request. It first determines whether there is an existing ndlp that
282 * matches the DID from the unsolicited IOCB. If not, it will return.
285 lpfc_ct_handle_mibreq(struct lpfc_hba *phba, struct lpfc_iocbq *ctiocbq)
287 struct lpfc_sli_ct_request *ct_req;
288 struct lpfc_nodelist *ndlp = NULL;
289 struct lpfc_vport *vport = NULL;
290 IOCB_t *icmd = &ctiocbq->iocb;
294 vpi = ctiocbq->iocb.unsli3.rcvsli3.vpi;
295 vport = lpfc_find_vport_by_vpid(phba, vpi);
297 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
298 "6437 Unsol CT: VPORT NULL vpi : x%x\n",
303 did = ctiocbq->iocb.un.rcvels.remoteID;
304 if (icmd->ulpStatus) {
305 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
306 "6438 Unsol CT: status:x%x/x%x did : x%x\n",
307 icmd->ulpStatus, icmd->un.ulpWord[4], did);
311 /* Ignore traffic received during vport shutdown */
312 if (vport->fc_flag & FC_UNLOADING)
315 ndlp = lpfc_findnode_did(vport, did);
317 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
318 "6439 Unsol CT: NDLP Not Found for DID : x%x",
323 ct_req = ((struct lpfc_sli_ct_request *)
324 (((struct lpfc_dmabuf *)ctiocbq->context2)->virt));
326 mi_cmd = ct_req->CommandResponse.bits.CmdRsp;
327 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
328 "6442 : MI Cmd : x%x Not Supported\n", mi_cmd);
329 lpfc_ct_reject_event(ndlp, ct_req,
330 ctiocbq->iocb.ulpContext,
331 ctiocbq->iocb.unsli3.rcvsli3.ox_id);
335 * lpfc_ct_unsol_event - Process an unsolicited event from a ct sli ring
336 * @phba: pointer to lpfc hba data structure.
337 * @pring: pointer to a SLI ring.
338 * @ctiocbq: pointer to lpfc ct iocb data structure.
340 * This routine is used to process an unsolicited event received from a SLI
341 * (Service Level Interface) ring. The actual processing of the data buffer
342 * associated with the unsolicited event is done by invoking appropriate routine
343 * after properly set up the iocb buffer from the SLI ring on which the
344 * unsolicited event was received.
347 lpfc_ct_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
348 struct lpfc_iocbq *ctiocbq)
350 struct lpfc_dmabuf *mp = NULL;
351 IOCB_t *icmd = &ctiocbq->iocb;
353 struct lpfc_iocbq *iocbq;
356 struct list_head head;
357 struct lpfc_sli_ct_request *ct_req;
358 struct lpfc_dmabuf *bdeBuf1 = ctiocbq->context2;
359 struct lpfc_dmabuf *bdeBuf2 = ctiocbq->context3;
361 ctiocbq->context1 = NULL;
362 ctiocbq->context2 = NULL;
363 ctiocbq->context3 = NULL;
365 if (unlikely(icmd->ulpStatus == IOSTAT_NEED_BUFFER)) {
366 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
367 } else if ((icmd->ulpStatus == IOSTAT_LOCAL_REJECT) &&
368 ((icmd->un.ulpWord[4] & IOERR_PARAM_MASK) ==
369 IOERR_RCV_BUFFER_WAITING)) {
370 /* Not enough posted buffers; Try posting more buffers */
371 phba->fc_stat.NoRcvBuf++;
372 if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
373 lpfc_post_buffer(phba, pring, 2);
377 /* If there are no BDEs associated
378 * with this IOCB, there is nothing to do.
380 if (icmd->ulpBdeCount == 0)
383 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
384 ctiocbq->context2 = bdeBuf1;
385 if (icmd->ulpBdeCount == 2)
386 ctiocbq->context3 = bdeBuf2;
388 dma_addr = getPaddr(icmd->un.cont64[0].addrHigh,
389 icmd->un.cont64[0].addrLow);
390 ctiocbq->context2 = lpfc_sli_ringpostbuf_get(phba, pring,
392 if (icmd->ulpBdeCount == 2) {
393 dma_addr = getPaddr(icmd->un.cont64[1].addrHigh,
394 icmd->un.cont64[1].addrLow);
395 ctiocbq->context3 = lpfc_sli_ringpostbuf_get(phba,
401 ct_req = ((struct lpfc_sli_ct_request *)
402 (((struct lpfc_dmabuf *)ctiocbq->context2)->virt));
404 if (ct_req->FsType == SLI_CT_MANAGEMENT_SERVICE &&
405 ct_req->FsSubType == SLI_CT_MIB_Subtypes) {
406 lpfc_ct_handle_mibreq(phba, ctiocbq);
408 if (!lpfc_bsg_ct_unsol_event(phba, pring, ctiocbq))
412 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
413 INIT_LIST_HEAD(&head);
414 list_add_tail(&head, &ctiocbq->list);
415 list_for_each_entry(iocbq, &head, list) {
417 if (icmd->ulpBdeCount == 0)
419 bdeBuf1 = iocbq->context2;
420 iocbq->context2 = NULL;
421 size = icmd->un.cont64[0].tus.f.bdeSize;
422 lpfc_ct_unsol_buffer(phba, ctiocbq, bdeBuf1, size);
423 lpfc_in_buf_free(phba, bdeBuf1);
424 if (icmd->ulpBdeCount == 2) {
425 bdeBuf2 = iocbq->context3;
426 iocbq->context3 = NULL;
427 size = icmd->unsli3.rcvsli3.bde2.tus.f.bdeSize;
428 lpfc_ct_unsol_buffer(phba, ctiocbq, bdeBuf2,
430 lpfc_in_buf_free(phba, bdeBuf2);
435 INIT_LIST_HEAD(&head);
436 list_add_tail(&head, &ctiocbq->list);
437 list_for_each_entry(iocbq, &head, list) {
439 if (icmd->ulpBdeCount == 0)
440 lpfc_ct_unsol_buffer(phba, iocbq, NULL, 0);
441 for (i = 0; i < icmd->ulpBdeCount; i++) {
442 dma_addr = getPaddr(icmd->un.cont64[i].addrHigh,
443 icmd->un.cont64[i].addrLow);
444 mp = lpfc_sli_ringpostbuf_get(phba, pring,
446 size = icmd->un.cont64[i].tus.f.bdeSize;
447 lpfc_ct_unsol_buffer(phba, iocbq, mp, size);
448 lpfc_in_buf_free(phba, mp);
450 lpfc_post_buffer(phba, pring, i);
457 * lpfc_ct_handle_unsol_abort - ct upper level protocol abort handler
458 * @phba: Pointer to HBA context object.
459 * @dmabuf: pointer to a dmabuf that describes the FC sequence
461 * This function serves as the upper level protocol abort handler for CT
464 * Return 1 if abort has been handled, 0 otherwise.
467 lpfc_ct_handle_unsol_abort(struct lpfc_hba *phba, struct hbq_dmabuf *dmabuf)
471 /* CT upper level goes through BSG */
472 handled = lpfc_bsg_ct_unsol_abort(phba, dmabuf);
478 lpfc_free_ct_rsp(struct lpfc_hba *phba, struct lpfc_dmabuf *mlist)
480 struct lpfc_dmabuf *mlast, *next_mlast;
482 list_for_each_entry_safe(mlast, next_mlast, &mlist->list, list) {
483 lpfc_mbuf_free(phba, mlast->virt, mlast->phys);
484 list_del(&mlast->list);
487 lpfc_mbuf_free(phba, mlist->virt, mlist->phys);
492 static struct lpfc_dmabuf *
493 lpfc_alloc_ct_rsp(struct lpfc_hba *phba, int cmdcode, struct ulp_bde64 *bpl,
494 uint32_t size, int *entries)
496 struct lpfc_dmabuf *mlist = NULL;
497 struct lpfc_dmabuf *mp;
500 /* We get chunks of FCELSSIZE */
501 cnt = size > FCELSSIZE ? FCELSSIZE: size;
504 /* Allocate buffer for rsp payload */
505 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
508 lpfc_free_ct_rsp(phba, mlist);
512 INIT_LIST_HEAD(&mp->list);
514 if (cmdcode == be16_to_cpu(SLI_CTNS_GID_FT) ||
515 cmdcode == be16_to_cpu(SLI_CTNS_GFF_ID))
516 mp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(mp->phys));
518 mp->virt = lpfc_mbuf_alloc(phba, 0, &(mp->phys));
523 lpfc_free_ct_rsp(phba, mlist);
527 /* Queue it to a linked list */
531 list_add_tail(&mp->list, &mlist->list);
533 bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64I;
534 /* build buffer ptr list for IOCB */
535 bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys) );
536 bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys) );
537 bpl->tus.f.bdeSize = (uint16_t) cnt;
538 bpl->tus.w = le32_to_cpu(bpl->tus.w);
550 lpfc_ct_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *ctiocb)
552 struct lpfc_dmabuf *buf_ptr;
554 /* I/O job is complete so context is now invalid*/
555 ctiocb->context_un.ndlp = NULL;
556 if (ctiocb->context1) {
557 buf_ptr = (struct lpfc_dmabuf *) ctiocb->context1;
558 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
560 ctiocb->context1 = NULL;
562 if (ctiocb->context2) {
563 lpfc_free_ct_rsp(phba, (struct lpfc_dmabuf *) ctiocb->context2);
564 ctiocb->context2 = NULL;
567 if (ctiocb->context3) {
568 buf_ptr = (struct lpfc_dmabuf *) ctiocb->context3;
569 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
571 ctiocb->context3 = NULL;
573 lpfc_sli_release_iocbq(phba, ctiocb);
578 * lpfc_gen_req - Build and issue a GEN_REQUEST command to the SLI Layer
579 * @vport: pointer to a host virtual N_Port data structure.
580 * @bmp: Pointer to BPL for SLI command
581 * @inp: Pointer to data buffer for response data.
582 * @outp: Pointer to data buffer that hold the CT command.
583 * @cmpl: completion routine to call when command completes
584 * @ndlp: Destination NPort nodelist entry
586 * This function as the final part for issuing a CT command.
589 lpfc_gen_req(struct lpfc_vport *vport, struct lpfc_dmabuf *bmp,
590 struct lpfc_dmabuf *inp, struct lpfc_dmabuf *outp,
591 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
592 struct lpfc_iocbq *),
593 struct lpfc_nodelist *ndlp, uint32_t event_tag, uint32_t num_entry,
594 uint32_t tmo, uint8_t retry)
596 struct lpfc_hba *phba = vport->phba;
598 struct lpfc_iocbq *geniocb;
601 /* Allocate buffer for command iocb */
602 geniocb = lpfc_sli_get_iocbq(phba);
607 icmd = &geniocb->iocb;
608 icmd->un.genreq64.bdl.ulpIoTag32 = 0;
609 icmd->un.genreq64.bdl.addrHigh = putPaddrHigh(bmp->phys);
610 icmd->un.genreq64.bdl.addrLow = putPaddrLow(bmp->phys);
611 icmd->un.genreq64.bdl.bdeFlags = BUFF_TYPE_BLP_64;
612 icmd->un.genreq64.bdl.bdeSize = (num_entry * sizeof(struct ulp_bde64));
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 geniocb->event_tag = event_tag;
622 /* Fill in payload, bp points to frame payload */
623 icmd->ulpCommand = CMD_GEN_REQUEST64_CR;
625 /* Fill in rest of iocb */
626 icmd->un.genreq64.w5.hcsw.Fctl = (SI | LA);
627 icmd->un.genreq64.w5.hcsw.Dfctl = 0;
628 icmd->un.genreq64.w5.hcsw.Rctl = FC_RCTL_DD_UNSOL_CTL;
629 icmd->un.genreq64.w5.hcsw.Type = FC_TYPE_CT;
632 /* FC spec states we need 3 * ratov for CT requests */
633 tmo = (3 * phba->fc_ratov);
635 icmd->ulpTimeout = tmo;
636 icmd->ulpBdeCount = 1;
638 icmd->ulpClass = CLASS3;
639 icmd->ulpContext = ndlp->nlp_rpi;
640 if (phba->sli_rev == LPFC_SLI_REV4)
641 icmd->ulpContext = phba->sli4_hba.rpi_ids[ndlp->nlp_rpi];
643 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
644 /* For GEN_REQUEST64_CR, use the RPI */
649 /* Issue GEN REQ IOCB for NPORT <did> */
650 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
651 "0119 Issue GEN REQ IOCB to NPORT x%x "
653 ndlp->nlp_DID, icmd->ulpIoTag,
655 geniocb->iocb_cmpl = cmpl;
656 geniocb->drvrTimeout = icmd->ulpTimeout + LPFC_DRVR_TIMEOUT;
657 geniocb->vport = vport;
658 geniocb->retry = retry;
659 geniocb->context_un.ndlp = lpfc_nlp_get(ndlp);
660 if (!geniocb->context_un.ndlp)
662 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, geniocb, 0);
664 if (rc == IOCB_ERROR) {
665 geniocb->context_un.ndlp = NULL;
672 lpfc_sli_release_iocbq(phba, geniocb);
677 * lpfc_ct_cmd - Build and issue a CT command
678 * @vport: pointer to a host virtual N_Port data structure.
679 * @inmp: Pointer to data buffer for response data.
680 * @bmp: Pointer to BPL for SLI command
681 * @ndlp: Destination NPort nodelist entry
682 * @cmpl: completion routine to call when command completes
684 * This function is called for issuing a CT command.
687 lpfc_ct_cmd(struct lpfc_vport *vport, struct lpfc_dmabuf *inmp,
688 struct lpfc_dmabuf *bmp, struct lpfc_nodelist *ndlp,
689 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
690 struct lpfc_iocbq *),
691 uint32_t rsp_size, uint8_t retry)
693 struct lpfc_hba *phba = vport->phba;
694 struct ulp_bde64 *bpl = (struct ulp_bde64 *) bmp->virt;
695 struct lpfc_dmabuf *outmp;
697 int cmdcode = ((struct lpfc_sli_ct_request *) inmp->virt)->
698 CommandResponse.bits.CmdRsp;
700 bpl++; /* Skip past ct request */
702 /* Put buffer(s) for ct rsp in bpl */
703 outmp = lpfc_alloc_ct_rsp(phba, cmdcode, bpl, rsp_size, &cnt);
707 * Form the CT IOCB. The total number of BDEs in this IOCB
708 * is the single command plus response count from
712 status = lpfc_gen_req(vport, bmp, inmp, outmp, cmpl, ndlp,
713 phba->fc_eventTag, cnt, 0, retry);
715 lpfc_free_ct_rsp(phba, outmp);
722 lpfc_find_vport_by_did(struct lpfc_hba *phba, uint32_t did) {
723 struct lpfc_vport *vport_curr;
726 spin_lock_irqsave(&phba->port_list_lock, flags);
727 list_for_each_entry(vport_curr, &phba->port_list, listentry) {
728 if ((vport_curr->fc_myDID) && (vport_curr->fc_myDID == did)) {
729 spin_unlock_irqrestore(&phba->port_list_lock, flags);
733 spin_unlock_irqrestore(&phba->port_list_lock, flags);
738 lpfc_prep_node_fc4type(struct lpfc_vport *vport, uint32_t Did, uint8_t fc4_type)
740 struct lpfc_nodelist *ndlp;
742 if ((vport->port_type != LPFC_NPIV_PORT) ||
743 !(vport->ct_flags & FC_CT_RFF_ID) || !vport->cfg_restrict_login) {
745 ndlp = lpfc_setup_disc_node(vport, Did);
748 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
749 "Parse GID_FTrsp: did:x%x flg:x%x x%x",
750 Did, ndlp->nlp_flag, vport->fc_flag);
752 /* By default, the driver expects to support FCP FC4 */
753 if (fc4_type == FC_TYPE_FCP)
754 ndlp->nlp_fc4_type |= NLP_FC4_FCP;
756 if (fc4_type == FC_TYPE_NVME)
757 ndlp->nlp_fc4_type |= NLP_FC4_NVME;
759 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
760 "0238 Process x%06x NameServer Rsp "
761 "Data: x%x x%x x%x x%x x%x\n", Did,
762 ndlp->nlp_flag, ndlp->nlp_fc4_type,
763 ndlp->nlp_state, vport->fc_flag,
764 vport->fc_rscn_id_cnt);
766 /* if ndlp needs to be discovered and prior
767 * state of ndlp hit devloss, change state to
770 if (ndlp->nlp_flag & NLP_NPR_2B_DISC &&
771 ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
772 lpfc_nlp_set_state(vport, ndlp,
776 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
777 "Skip1 GID_FTrsp: did:x%x flg:x%x cnt:%d",
778 Did, vport->fc_flag, vport->fc_rscn_id_cnt);
780 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
781 "0239 Skip x%06x NameServer Rsp "
782 "Data: x%x x%x x%px\n",
784 vport->fc_rscn_id_cnt, ndlp);
787 if (!(vport->fc_flag & FC_RSCN_MODE) ||
788 lpfc_rscn_payload_check(vport, Did)) {
789 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
790 "Query GID_FTrsp: did:x%x flg:x%x cnt:%d",
791 Did, vport->fc_flag, vport->fc_rscn_id_cnt);
794 * This NPortID was previously a FCP/NVMe target,
795 * Don't even bother to send GFF_ID.
797 ndlp = lpfc_findnode_did(vport, Did);
800 (NLP_FCP_TARGET | NLP_NVME_TARGET))) {
801 if (fc4_type == FC_TYPE_FCP)
802 ndlp->nlp_fc4_type |= NLP_FC4_FCP;
803 if (fc4_type == FC_TYPE_NVME)
804 ndlp->nlp_fc4_type |= NLP_FC4_NVME;
805 lpfc_setup_disc_node(vport, Did);
806 } else if (lpfc_ns_cmd(vport, SLI_CTNS_GFF_ID,
808 vport->num_disc_nodes++;
810 lpfc_setup_disc_node(vport, Did);
812 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
813 "Skip2 GID_FTrsp: did:x%x flg:x%x cnt:%d",
814 Did, vport->fc_flag, vport->fc_rscn_id_cnt);
816 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
817 "0245 Skip x%06x NameServer Rsp "
818 "Data: x%x x%x\n", Did,
820 vport->fc_rscn_id_cnt);
826 lpfc_ns_rsp_audit_did(struct lpfc_vport *vport, uint32_t Did, uint8_t fc4_type)
828 struct lpfc_hba *phba = vport->phba;
829 struct lpfc_nodelist *ndlp = NULL;
832 if (phba->cfg_ns_query == LPFC_NS_QUERY_GID_FT)
836 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
837 "6430 Process %s rsp for %08x type %x %s %s\n",
839 (fc4_type == FC_TYPE_FCP) ? "FCP" : " ",
840 (fc4_type == FC_TYPE_NVME) ? "NVME" : " ");
842 * To conserve rpi's, filter out addresses for other
843 * vports on the same physical HBAs.
845 if (Did != vport->fc_myDID &&
846 (!lpfc_find_vport_by_did(phba, Did) ||
847 vport->cfg_peer_port_login)) {
848 if (!phba->nvmet_support) {
849 /* FCPI/NVMEI path. Process Did */
850 lpfc_prep_node_fc4type(vport, Did, fc4_type);
853 /* NVMET path. NVMET only cares about NVMEI nodes. */
854 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
855 if (ndlp->nlp_type != NLP_NVME_INITIATOR ||
856 ndlp->nlp_state != NLP_STE_UNMAPPED_NODE)
858 spin_lock_irq(&ndlp->lock);
859 if (ndlp->nlp_DID == Did)
860 ndlp->nlp_flag &= ~NLP_NVMET_RECOV;
862 ndlp->nlp_flag |= NLP_NVMET_RECOV;
863 spin_unlock_irq(&ndlp->lock);
869 lpfc_ns_rsp(struct lpfc_vport *vport, struct lpfc_dmabuf *mp, uint8_t fc4_type,
872 struct lpfc_sli_ct_request *Response =
873 (struct lpfc_sli_ct_request *) mp->virt;
874 struct lpfc_dmabuf *mlast, *next_mp;
875 uint32_t *ctptr = (uint32_t *) & Response->un.gid.PortType;
876 uint32_t Did, CTentry;
878 struct list_head head;
879 struct lpfc_nodelist *ndlp = NULL;
881 lpfc_set_disctmo(vport);
882 vport->num_disc_nodes = 0;
883 vport->fc_ns_retry = 0;
886 list_add_tail(&head, &mp->list);
887 list_for_each_entry_safe(mp, next_mp, &head, list) {
890 Cnt = Size > FCELSSIZE ? FCELSSIZE : Size;
895 ctptr = (uint32_t *) mlast->virt;
897 Cnt -= 16; /* subtract length of CT header */
899 /* Loop through entire NameServer list of DIDs */
900 while (Cnt >= sizeof(uint32_t)) {
901 /* Get next DID from NameServer List */
903 Did = ((be32_to_cpu(CTentry)) & Mask_DID);
904 lpfc_ns_rsp_audit_did(vport, Did, fc4_type);
905 if (CTentry & (cpu_to_be32(SLI_CT_LAST_ENTRY)))
908 Cnt -= sizeof(uint32_t);
914 /* All GID_FT entries processed. If the driver is running in
915 * in target mode, put impacted nodes into recovery and drop
916 * the RPI to flush outstanding IO.
918 if (vport->phba->nvmet_support) {
919 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
920 if (!(ndlp->nlp_flag & NLP_NVMET_RECOV))
922 lpfc_disc_state_machine(vport, ndlp, NULL,
923 NLP_EVT_DEVICE_RECOVERY);
924 spin_lock_irq(&ndlp->lock);
925 ndlp->nlp_flag &= ~NLP_NVMET_RECOV;
926 spin_unlock_irq(&ndlp->lock);
936 lpfc_cmpl_ct_cmd_gid_ft(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
937 struct lpfc_iocbq *rspiocb)
939 struct lpfc_vport *vport = cmdiocb->vport;
940 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
942 struct lpfc_dmabuf *outp;
943 struct lpfc_dmabuf *inp;
944 struct lpfc_sli_ct_request *CTrsp;
945 struct lpfc_sli_ct_request *CTreq;
946 struct lpfc_nodelist *ndlp;
949 /* First save ndlp, before we overwrite it */
950 ndlp = cmdiocb->context_un.ndlp;
952 /* we pass cmdiocb to state machine which needs rspiocb as well */
953 cmdiocb->context_un.rsp_iocb = rspiocb;
954 inp = (struct lpfc_dmabuf *) cmdiocb->context1;
955 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
956 irsp = &rspiocb->iocb;
958 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
959 "GID_FT cmpl: status:x%x/x%x rtry:%d",
960 irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_ns_retry);
962 /* Ignore response if link flipped after this request was made */
963 if (cmdiocb->event_tag != phba->fc_eventTag) {
964 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
965 "9043 Event tag mismatch. Ignoring NS rsp\n");
969 /* Don't bother processing response if vport is being torn down. */
970 if (vport->load_flag & FC_UNLOADING) {
971 if (vport->fc_flag & FC_RSCN_MODE)
972 lpfc_els_flush_rscn(vport);
976 if (lpfc_els_chk_latt(vport)) {
977 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
978 "0216 Link event during NS query\n");
979 if (vport->fc_flag & FC_RSCN_MODE)
980 lpfc_els_flush_rscn(vport);
981 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
984 if (lpfc_error_lost_link(irsp)) {
985 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
986 "0226 NS query failed due to link event\n");
987 if (vport->fc_flag & FC_RSCN_MODE)
988 lpfc_els_flush_rscn(vport);
992 spin_lock_irq(shost->host_lock);
993 if (vport->fc_flag & FC_RSCN_DEFERRED) {
994 vport->fc_flag &= ~FC_RSCN_DEFERRED;
995 spin_unlock_irq(shost->host_lock);
997 /* This is a GID_FT completing so the gidft_inp counter was
998 * incremented before the GID_FT was issued to the wire.
1000 if (vport->gidft_inp)
1004 * Skip processing the NS response
1005 * Re-issue the NS cmd
1007 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1008 "0151 Process Deferred RSCN Data: x%x x%x\n",
1009 vport->fc_flag, vport->fc_rscn_id_cnt);
1010 lpfc_els_handle_rscn(vport);
1014 spin_unlock_irq(shost->host_lock);
1016 if (irsp->ulpStatus) {
1017 /* Check for retry */
1018 if (vport->fc_ns_retry < LPFC_MAX_NS_RETRY) {
1019 if (irsp->ulpStatus != IOSTAT_LOCAL_REJECT ||
1020 (irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
1022 vport->fc_ns_retry++;
1024 type = lpfc_get_gidft_type(vport, cmdiocb);
1028 /* CT command is being retried */
1029 rc = lpfc_ns_cmd(vport, SLI_CTNS_GID_FT,
1030 vport->fc_ns_retry, type);
1033 else { /* Unable to send NS cmd */
1034 if (vport->gidft_inp)
1038 if (vport->fc_flag & FC_RSCN_MODE)
1039 lpfc_els_flush_rscn(vport);
1040 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
1041 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1042 "0257 GID_FT Query error: 0x%x 0x%x\n",
1043 irsp->ulpStatus, vport->fc_ns_retry);
1045 /* Good status, continue checking */
1046 CTreq = (struct lpfc_sli_ct_request *) inp->virt;
1047 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
1048 if (CTrsp->CommandResponse.bits.CmdRsp ==
1049 cpu_to_be16(SLI_CT_RESPONSE_FS_ACC)) {
1050 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1051 "0208 NameServer Rsp Data: x%x x%x "
1054 CTreq->un.gid.Fc4Type,
1055 vport->num_disc_nodes,
1057 irsp->un.genreq64.bdl.bdeSize);
1061 CTreq->un.gid.Fc4Type,
1062 (uint32_t) (irsp->un.genreq64.bdl.bdeSize));
1063 } else if (CTrsp->CommandResponse.bits.CmdRsp ==
1064 be16_to_cpu(SLI_CT_RESPONSE_FS_RJT)) {
1065 /* NameServer Rsp Error */
1066 if ((CTrsp->ReasonCode == SLI_CT_UNABLE_TO_PERFORM_REQ)
1067 && (CTrsp->Explanation == SLI_CT_NO_FC4_TYPES)) {
1068 lpfc_printf_vlog(vport, KERN_INFO,
1070 "0269 No NameServer Entries "
1071 "Data: x%x x%x x%x x%x\n",
1072 CTrsp->CommandResponse.bits.CmdRsp,
1073 (uint32_t) CTrsp->ReasonCode,
1074 (uint32_t) CTrsp->Explanation,
1077 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
1078 "GID_FT no entry cmd:x%x rsn:x%x exp:x%x",
1079 (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
1080 (uint32_t) CTrsp->ReasonCode,
1081 (uint32_t) CTrsp->Explanation);
1083 lpfc_printf_vlog(vport, KERN_INFO,
1085 "0240 NameServer Rsp Error "
1086 "Data: x%x x%x x%x x%x\n",
1087 CTrsp->CommandResponse.bits.CmdRsp,
1088 (uint32_t) CTrsp->ReasonCode,
1089 (uint32_t) CTrsp->Explanation,
1092 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
1093 "GID_FT rsp err1 cmd:x%x rsn:x%x exp:x%x",
1094 (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
1095 (uint32_t) CTrsp->ReasonCode,
1096 (uint32_t) CTrsp->Explanation);
1101 /* NameServer Rsp Error */
1102 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1103 "0241 NameServer Rsp Error "
1104 "Data: x%x x%x x%x x%x\n",
1105 CTrsp->CommandResponse.bits.CmdRsp,
1106 (uint32_t) CTrsp->ReasonCode,
1107 (uint32_t) CTrsp->Explanation,
1110 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
1111 "GID_FT rsp err2 cmd:x%x rsn:x%x exp:x%x",
1112 (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
1113 (uint32_t) CTrsp->ReasonCode,
1114 (uint32_t) CTrsp->Explanation);
1116 if (vport->gidft_inp)
1120 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1121 "4216 GID_FT cmpl inp %d disc %d\n",
1122 vport->gidft_inp, vport->num_disc_nodes);
1124 /* Link up / RSCN discovery */
1125 if ((vport->num_disc_nodes == 0) &&
1126 (vport->gidft_inp == 0)) {
1128 * The driver has cycled through all Nports in the RSCN payload.
1129 * Complete the handling by cleaning up and marking the
1130 * current driver state.
1132 if (vport->port_state >= LPFC_DISC_AUTH) {
1133 if (vport->fc_flag & FC_RSCN_MODE) {
1134 lpfc_els_flush_rscn(vport);
1135 spin_lock_irq(shost->host_lock);
1136 vport->fc_flag |= FC_RSCN_MODE; /* RSCN still */
1137 spin_unlock_irq(shost->host_lock);
1140 lpfc_els_flush_rscn(vport);
1143 lpfc_disc_start(vport);
1146 lpfc_ct_free_iocb(phba, cmdiocb);
1152 lpfc_cmpl_ct_cmd_gid_pt(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1153 struct lpfc_iocbq *rspiocb)
1155 struct lpfc_vport *vport = cmdiocb->vport;
1156 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1158 struct lpfc_dmabuf *outp;
1159 struct lpfc_dmabuf *inp;
1160 struct lpfc_sli_ct_request *CTrsp;
1161 struct lpfc_sli_ct_request *CTreq;
1162 struct lpfc_nodelist *ndlp;
1165 /* First save ndlp, before we overwrite it */
1166 ndlp = cmdiocb->context_un.ndlp;
1168 /* we pass cmdiocb to state machine which needs rspiocb as well */
1169 cmdiocb->context_un.rsp_iocb = rspiocb;
1170 inp = (struct lpfc_dmabuf *)cmdiocb->context1;
1171 outp = (struct lpfc_dmabuf *)cmdiocb->context2;
1172 irsp = &rspiocb->iocb;
1174 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
1175 "GID_PT cmpl: status:x%x/x%x rtry:%d",
1176 irsp->ulpStatus, irsp->un.ulpWord[4],
1177 vport->fc_ns_retry);
1179 /* Ignore response if link flipped after this request was made */
1180 if (cmdiocb->event_tag != phba->fc_eventTag) {
1181 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1182 "9044 Event tag mismatch. Ignoring NS rsp\n");
1186 /* Don't bother processing response if vport is being torn down. */
1187 if (vport->load_flag & FC_UNLOADING) {
1188 if (vport->fc_flag & FC_RSCN_MODE)
1189 lpfc_els_flush_rscn(vport);
1193 if (lpfc_els_chk_latt(vport)) {
1194 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1195 "4108 Link event during NS query\n");
1196 if (vport->fc_flag & FC_RSCN_MODE)
1197 lpfc_els_flush_rscn(vport);
1198 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
1201 if (lpfc_error_lost_link(irsp)) {
1202 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1203 "4166 NS query failed due to link event\n");
1204 if (vport->fc_flag & FC_RSCN_MODE)
1205 lpfc_els_flush_rscn(vport);
1209 spin_lock_irq(shost->host_lock);
1210 if (vport->fc_flag & FC_RSCN_DEFERRED) {
1211 vport->fc_flag &= ~FC_RSCN_DEFERRED;
1212 spin_unlock_irq(shost->host_lock);
1214 /* This is a GID_PT completing so the gidft_inp counter was
1215 * incremented before the GID_PT was issued to the wire.
1217 if (vport->gidft_inp)
1221 * Skip processing the NS response
1222 * Re-issue the NS cmd
1224 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1225 "4167 Process Deferred RSCN Data: x%x x%x\n",
1226 vport->fc_flag, vport->fc_rscn_id_cnt);
1227 lpfc_els_handle_rscn(vport);
1231 spin_unlock_irq(shost->host_lock);
1233 if (irsp->ulpStatus) {
1234 /* Check for retry */
1235 if (vport->fc_ns_retry < LPFC_MAX_NS_RETRY) {
1236 if (irsp->ulpStatus != IOSTAT_LOCAL_REJECT ||
1237 (irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
1239 vport->fc_ns_retry++;
1241 /* CT command is being retried */
1242 rc = lpfc_ns_cmd(vport, SLI_CTNS_GID_PT,
1243 vport->fc_ns_retry, GID_PT_N_PORT);
1246 else { /* Unable to send NS cmd */
1247 if (vport->gidft_inp)
1251 if (vport->fc_flag & FC_RSCN_MODE)
1252 lpfc_els_flush_rscn(vport);
1253 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
1254 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1255 "4103 GID_FT Query error: 0x%x 0x%x\n",
1256 irsp->ulpStatus, vport->fc_ns_retry);
1258 /* Good status, continue checking */
1259 CTreq = (struct lpfc_sli_ct_request *)inp->virt;
1260 CTrsp = (struct lpfc_sli_ct_request *)outp->virt;
1261 if (CTrsp->CommandResponse.bits.CmdRsp ==
1262 cpu_to_be16(SLI_CT_RESPONSE_FS_ACC)) {
1263 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1264 "4105 NameServer Rsp Data: x%x x%x "
1267 CTreq->un.gid.Fc4Type,
1268 vport->num_disc_nodes,
1270 irsp->un.genreq64.bdl.bdeSize);
1274 CTreq->un.gid.Fc4Type,
1275 (uint32_t)(irsp->un.genreq64.bdl.bdeSize));
1276 } else if (CTrsp->CommandResponse.bits.CmdRsp ==
1277 be16_to_cpu(SLI_CT_RESPONSE_FS_RJT)) {
1278 /* NameServer Rsp Error */
1279 if ((CTrsp->ReasonCode == SLI_CT_UNABLE_TO_PERFORM_REQ)
1280 && (CTrsp->Explanation == SLI_CT_NO_FC4_TYPES)) {
1282 vport, KERN_INFO, LOG_DISCOVERY,
1283 "4106 No NameServer Entries "
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 no entry 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 vport, KERN_INFO, LOG_DISCOVERY,
1299 "4107 NameServer Rsp Error "
1300 "Data: x%x x%x x%x x%x\n",
1301 CTrsp->CommandResponse.bits.CmdRsp,
1302 (uint32_t)CTrsp->ReasonCode,
1303 (uint32_t)CTrsp->Explanation,
1306 lpfc_debugfs_disc_trc(
1307 vport, LPFC_DISC_TRC_CT,
1308 "GID_PT rsp err1 cmd:x%x rsn:x%x exp:x%x",
1309 (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
1310 (uint32_t)CTrsp->ReasonCode,
1311 (uint32_t)CTrsp->Explanation);
1314 /* NameServer Rsp Error */
1315 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1316 "4109 NameServer Rsp Error "
1317 "Data: x%x x%x x%x x%x\n",
1318 CTrsp->CommandResponse.bits.CmdRsp,
1319 (uint32_t)CTrsp->ReasonCode,
1320 (uint32_t)CTrsp->Explanation,
1323 lpfc_debugfs_disc_trc(
1324 vport, LPFC_DISC_TRC_CT,
1325 "GID_PT rsp err2 cmd:x%x rsn:x%x exp:x%x",
1326 (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
1327 (uint32_t)CTrsp->ReasonCode,
1328 (uint32_t)CTrsp->Explanation);
1330 if (vport->gidft_inp)
1334 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1335 "6450 GID_PT cmpl inp %d disc %d\n",
1336 vport->gidft_inp, vport->num_disc_nodes);
1338 /* Link up / RSCN discovery */
1339 if ((vport->num_disc_nodes == 0) &&
1340 (vport->gidft_inp == 0)) {
1342 * The driver has cycled through all Nports in the RSCN payload.
1343 * Complete the handling by cleaning up and marking the
1344 * current driver state.
1346 if (vport->port_state >= LPFC_DISC_AUTH) {
1347 if (vport->fc_flag & FC_RSCN_MODE) {
1348 lpfc_els_flush_rscn(vport);
1349 spin_lock_irq(shost->host_lock);
1350 vport->fc_flag |= FC_RSCN_MODE; /* RSCN still */
1351 spin_unlock_irq(shost->host_lock);
1353 lpfc_els_flush_rscn(vport);
1357 lpfc_disc_start(vport);
1360 lpfc_ct_free_iocb(phba, cmdiocb);
1365 lpfc_cmpl_ct_cmd_gff_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1366 struct lpfc_iocbq *rspiocb)
1368 struct lpfc_vport *vport = cmdiocb->vport;
1369 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1370 IOCB_t *irsp = &rspiocb->iocb;
1371 struct lpfc_dmabuf *inp = (struct lpfc_dmabuf *) cmdiocb->context1;
1372 struct lpfc_dmabuf *outp = (struct lpfc_dmabuf *) cmdiocb->context2;
1373 struct lpfc_sli_ct_request *CTrsp;
1376 struct lpfc_nodelist *ndlp = NULL, *free_ndlp = NULL;
1378 did = ((struct lpfc_sli_ct_request *) inp->virt)->un.gff.PortId;
1379 did = be32_to_cpu(did);
1381 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
1382 "GFF_ID cmpl: status:x%x/x%x did:x%x",
1383 irsp->ulpStatus, irsp->un.ulpWord[4], did);
1385 /* Ignore response if link flipped after this request was made */
1386 if (cmdiocb->event_tag != phba->fc_eventTag) {
1387 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1388 "9045 Event tag mismatch. Ignoring NS rsp\n");
1392 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
1393 /* Good status, continue checking */
1394 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
1395 fbits = CTrsp->un.gff_acc.fbits[FCP_TYPE_FEATURE_OFFSET];
1397 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1398 "6431 Process GFF_ID rsp for %08x "
1399 "fbits %02x %s %s\n",
1401 (fbits & FC4_FEATURE_INIT) ? "Initiator" : " ",
1402 (fbits & FC4_FEATURE_TARGET) ? "Target" : " ");
1404 if (CTrsp->CommandResponse.bits.CmdRsp ==
1405 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC)) {
1406 if ((fbits & FC4_FEATURE_INIT) &&
1407 !(fbits & FC4_FEATURE_TARGET)) {
1408 lpfc_printf_vlog(vport, KERN_INFO,
1410 "0270 Skip x%x GFF "
1411 "NameServer Rsp Data: (init) "
1412 "x%x x%x\n", did, fbits,
1413 vport->fc_rscn_id_cnt);
1419 /* Check for retry */
1420 if (cmdiocb->retry < LPFC_MAX_NS_RETRY) {
1422 if (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) {
1423 switch ((irsp->un.ulpWord[4] &
1424 IOERR_PARAM_MASK)) {
1426 case IOERR_NO_RESOURCES:
1427 /* We don't increment the retry
1428 * count for this case.
1431 case IOERR_LINK_DOWN:
1432 case IOERR_SLI_ABORTED:
1433 case IOERR_SLI_DOWN:
1444 /* CT command is being retried */
1445 rc = lpfc_ns_cmd(vport, SLI_CTNS_GFF_ID,
1446 cmdiocb->retry, did);
1449 free_ndlp = cmdiocb->context_un.ndlp;
1450 lpfc_ct_free_iocb(phba, cmdiocb);
1451 lpfc_nlp_put(free_ndlp);
1456 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1457 "0267 NameServer GFF Rsp "
1458 "x%x Error (%d %d) Data: x%x x%x\n",
1459 did, irsp->ulpStatus, irsp->un.ulpWord[4],
1460 vport->fc_flag, vport->fc_rscn_id_cnt);
1463 /* This is a target port, unregistered port, or the GFF_ID failed */
1464 ndlp = lpfc_setup_disc_node(vport, did);
1466 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1467 "0242 Process x%x GFF "
1468 "NameServer Rsp Data: x%x x%x x%x\n",
1469 did, ndlp->nlp_flag, vport->fc_flag,
1470 vport->fc_rscn_id_cnt);
1472 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1473 "0243 Skip x%x GFF "
1474 "NameServer Rsp Data: x%x x%x\n", did,
1475 vport->fc_flag, vport->fc_rscn_id_cnt);
1478 /* Link up / RSCN discovery */
1479 if (vport->num_disc_nodes)
1480 vport->num_disc_nodes--;
1482 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1483 "6451 GFF_ID cmpl inp %d disc %d\n",
1484 vport->gidft_inp, vport->num_disc_nodes);
1486 if (vport->num_disc_nodes == 0) {
1488 * The driver has cycled through all Nports in the RSCN payload.
1489 * Complete the handling by cleaning up and marking the
1490 * current driver state.
1492 if (vport->port_state >= LPFC_DISC_AUTH) {
1493 if (vport->fc_flag & FC_RSCN_MODE) {
1494 lpfc_els_flush_rscn(vport);
1495 spin_lock_irq(shost->host_lock);
1496 vport->fc_flag |= FC_RSCN_MODE; /* RSCN still */
1497 spin_unlock_irq(shost->host_lock);
1500 lpfc_els_flush_rscn(vport);
1502 lpfc_disc_start(vport);
1506 free_ndlp = cmdiocb->context_un.ndlp;
1507 lpfc_ct_free_iocb(phba, cmdiocb);
1508 lpfc_nlp_put(free_ndlp);
1513 lpfc_cmpl_ct_cmd_gft_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1514 struct lpfc_iocbq *rspiocb)
1516 struct lpfc_vport *vport = cmdiocb->vport;
1517 IOCB_t *irsp = &rspiocb->iocb;
1518 struct lpfc_dmabuf *inp = (struct lpfc_dmabuf *)cmdiocb->context1;
1519 struct lpfc_dmabuf *outp = (struct lpfc_dmabuf *)cmdiocb->context2;
1520 struct lpfc_sli_ct_request *CTrsp;
1522 struct lpfc_nodelist *ndlp = NULL;
1523 struct lpfc_nodelist *ns_ndlp = NULL;
1524 uint32_t fc4_data_0, fc4_data_1;
1526 did = ((struct lpfc_sli_ct_request *)inp->virt)->un.gft.PortId;
1527 did = be32_to_cpu(did);
1529 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
1530 "GFT_ID cmpl: status:x%x/x%x did:x%x",
1531 irsp->ulpStatus, irsp->un.ulpWord[4], did);
1533 /* Ignore response if link flipped after this request was made */
1534 if ((uint32_t) cmdiocb->event_tag != phba->fc_eventTag) {
1535 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1536 "9046 Event tag mismatch. Ignoring NS rsp\n");
1540 /* Preserve the nameserver node to release the reference. */
1541 ns_ndlp = cmdiocb->context_un.ndlp;
1543 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
1544 /* Good status, continue checking */
1545 CTrsp = (struct lpfc_sli_ct_request *)outp->virt;
1546 fc4_data_0 = be32_to_cpu(CTrsp->un.gft_acc.fc4_types[0]);
1547 fc4_data_1 = be32_to_cpu(CTrsp->un.gft_acc.fc4_types[1]);
1549 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1550 "6432 Process GFT_ID rsp for %08x "
1551 "Data %08x %08x %s %s\n",
1552 did, fc4_data_0, fc4_data_1,
1553 (fc4_data_0 & LPFC_FC4_TYPE_BITMASK) ?
1555 (fc4_data_1 & LPFC_FC4_TYPE_BITMASK) ?
1558 /* Lookup the NPort_ID queried in the GFT_ID and find the
1559 * driver's local node. It's an error if the driver
1562 ndlp = lpfc_findnode_did(vport, did);
1564 /* The bitmask value for FCP and NVME FCP types is
1565 * the same because they are 32 bits distant from
1566 * each other in word0 and word0.
1568 if (fc4_data_0 & LPFC_FC4_TYPE_BITMASK)
1569 ndlp->nlp_fc4_type |= NLP_FC4_FCP;
1570 if (fc4_data_1 & LPFC_FC4_TYPE_BITMASK)
1571 ndlp->nlp_fc4_type |= NLP_FC4_NVME;
1572 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1573 "3064 Setting ndlp x%px, DID x%06x "
1574 "with FC4 x%08x, Data: x%08x x%08x "
1576 ndlp, did, ndlp->nlp_fc4_type,
1577 FC_TYPE_FCP, FC_TYPE_NVME,
1580 if (ndlp->nlp_state == NLP_STE_REG_LOGIN_ISSUE &&
1581 ndlp->nlp_fc4_type) {
1582 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1584 lpfc_nlp_set_state(vport, ndlp,
1585 NLP_STE_PRLI_ISSUE);
1586 lpfc_issue_els_prli(vport, ndlp, 0);
1587 } else if (!ndlp->nlp_fc4_type) {
1588 /* If fc4 type is still unknown, then LOGO */
1589 lpfc_printf_vlog(vport, KERN_INFO,
1591 "6443 Sending LOGO ndlp x%px,"
1592 "DID x%06x with fc4_type: "
1593 "x%08x, state: %d\n",
1594 ndlp, did, ndlp->nlp_fc4_type,
1596 lpfc_issue_els_logo(vport, ndlp, 0);
1597 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1598 lpfc_nlp_set_state(vport, ndlp,
1603 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1604 "3065 GFT_ID failed x%08x\n", irsp->ulpStatus);
1607 lpfc_ct_free_iocb(phba, cmdiocb);
1608 lpfc_nlp_put(ns_ndlp);
1612 lpfc_cmpl_ct(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1613 struct lpfc_iocbq *rspiocb)
1615 struct lpfc_vport *vport = cmdiocb->vport;
1616 struct lpfc_dmabuf *inp;
1617 struct lpfc_dmabuf *outp;
1619 struct lpfc_sli_ct_request *CTrsp;
1620 struct lpfc_nodelist *ndlp;
1625 /* First save ndlp, before we overwrite it */
1626 ndlp = cmdiocb->context_un.ndlp;
1628 /* we pass cmdiocb to state machine which needs rspiocb as well */
1629 cmdiocb->context_un.rsp_iocb = rspiocb;
1631 inp = (struct lpfc_dmabuf *) cmdiocb->context1;
1632 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
1633 irsp = &rspiocb->iocb;
1635 cmdcode = be16_to_cpu(((struct lpfc_sli_ct_request *) inp->virt)->
1636 CommandResponse.bits.CmdRsp);
1637 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
1639 latt = lpfc_els_chk_latt(vport);
1641 /* RFT request completes status <ulpStatus> CmdRsp <CmdRsp> */
1642 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1643 "0209 CT Request completes, latt %d, "
1644 "ulpStatus x%x CmdRsp x%x, Context x%x, Tag x%x\n",
1645 latt, irsp->ulpStatus,
1646 CTrsp->CommandResponse.bits.CmdRsp,
1647 cmdiocb->iocb.ulpContext, cmdiocb->iocb.ulpIoTag);
1649 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
1650 "CT cmd cmpl: status:x%x/x%x cmd:x%x",
1651 irsp->ulpStatus, irsp->un.ulpWord[4], cmdcode);
1653 if (irsp->ulpStatus) {
1654 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1655 "0268 NS cmd x%x Error (x%x x%x)\n",
1656 cmdcode, irsp->ulpStatus, irsp->un.ulpWord[4]);
1658 if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
1659 (((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
1661 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
1662 IOERR_SLI_ABORTED)))
1665 retry = cmdiocb->retry;
1666 if (retry >= LPFC_MAX_NS_RETRY)
1670 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1671 "0250 Retrying NS cmd %x\n", cmdcode);
1672 rc = lpfc_ns_cmd(vport, cmdcode, retry, 0);
1678 lpfc_ct_free_iocb(phba, cmdiocb);
1684 lpfc_cmpl_ct_cmd_rft_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1685 struct lpfc_iocbq *rspiocb)
1687 IOCB_t *irsp = &rspiocb->iocb;
1688 struct lpfc_vport *vport = cmdiocb->vport;
1690 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
1691 struct lpfc_dmabuf *outp;
1692 struct lpfc_sli_ct_request *CTrsp;
1694 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
1695 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
1696 if (CTrsp->CommandResponse.bits.CmdRsp ==
1697 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
1698 vport->ct_flags |= FC_CT_RFT_ID;
1700 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
1705 lpfc_cmpl_ct_cmd_rnn_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1706 struct lpfc_iocbq *rspiocb)
1708 IOCB_t *irsp = &rspiocb->iocb;
1709 struct lpfc_vport *vport = cmdiocb->vport;
1711 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
1712 struct lpfc_dmabuf *outp;
1713 struct lpfc_sli_ct_request *CTrsp;
1715 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
1716 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
1717 if (CTrsp->CommandResponse.bits.CmdRsp ==
1718 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
1719 vport->ct_flags |= FC_CT_RNN_ID;
1721 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
1726 lpfc_cmpl_ct_cmd_rspn_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1727 struct lpfc_iocbq *rspiocb)
1729 IOCB_t *irsp = &rspiocb->iocb;
1730 struct lpfc_vport *vport = cmdiocb->vport;
1732 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
1733 struct lpfc_dmabuf *outp;
1734 struct lpfc_sli_ct_request *CTrsp;
1736 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
1737 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
1738 if (CTrsp->CommandResponse.bits.CmdRsp ==
1739 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
1740 vport->ct_flags |= FC_CT_RSPN_ID;
1742 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
1747 lpfc_cmpl_ct_cmd_rsnn_nn(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1748 struct lpfc_iocbq *rspiocb)
1750 IOCB_t *irsp = &rspiocb->iocb;
1751 struct lpfc_vport *vport = cmdiocb->vport;
1753 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
1754 struct lpfc_dmabuf *outp;
1755 struct lpfc_sli_ct_request *CTrsp;
1757 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
1758 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
1759 if (CTrsp->CommandResponse.bits.CmdRsp ==
1760 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
1761 vport->ct_flags |= FC_CT_RSNN_NN;
1763 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
1768 lpfc_cmpl_ct_cmd_da_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1769 struct lpfc_iocbq *rspiocb)
1771 struct lpfc_vport *vport = cmdiocb->vport;
1773 /* even if it fails we will act as though it succeeded. */
1774 vport->ct_flags = 0;
1775 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
1780 lpfc_cmpl_ct_cmd_rff_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1781 struct lpfc_iocbq *rspiocb)
1783 IOCB_t *irsp = &rspiocb->iocb;
1784 struct lpfc_vport *vport = cmdiocb->vport;
1786 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
1787 struct lpfc_dmabuf *outp;
1788 struct lpfc_sli_ct_request *CTrsp;
1790 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
1791 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
1792 if (CTrsp->CommandResponse.bits.CmdRsp ==
1793 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
1794 vport->ct_flags |= FC_CT_RFF_ID;
1796 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
1801 * Although the symbolic port name is thought to be an integer
1802 * as of January 18, 2016, leave it as a string until more of
1803 * the record state becomes defined.
1806 lpfc_vport_symbolic_port_name(struct lpfc_vport *vport, char *symbol,
1812 * Use the lpfc board number as the Symbolic Port
1813 * Name object. NPIV is not in play so this integer
1814 * value is sufficient and unique per FC-ID.
1816 n = scnprintf(symbol, size, "%d", vport->phba->brd_no);
1822 lpfc_vport_symbolic_node_name(struct lpfc_vport *vport, char *symbol,
1825 char fwrev[FW_REV_STR_SIZE] = {0};
1826 char tmp[MAXHOSTNAMELEN] = {0};
1828 memset(symbol, 0, size);
1830 scnprintf(tmp, sizeof(tmp), "Emulex %s", vport->phba->ModelName);
1831 if (strlcat(symbol, tmp, size) >= size)
1834 lpfc_decode_firmware_rev(vport->phba, fwrev, 0);
1835 scnprintf(tmp, sizeof(tmp), " FV%s", fwrev);
1836 if (strlcat(symbol, tmp, size) >= size)
1839 scnprintf(tmp, sizeof(tmp), " DV%s", lpfc_release_version);
1840 if (strlcat(symbol, tmp, size) >= size)
1843 scnprintf(tmp, sizeof(tmp), " HN:%s", vport->phba->os_host_name);
1844 if (strlcat(symbol, tmp, size) >= size)
1847 /* Note :- OS name is "Linux" */
1848 scnprintf(tmp, sizeof(tmp), " OS:%s", init_utsname()->sysname);
1849 strlcat(symbol, tmp, size);
1852 return strnlen(symbol, size);
1857 lpfc_find_map_node(struct lpfc_vport *vport)
1859 struct lpfc_nodelist *ndlp, *next_ndlp;
1860 struct Scsi_Host *shost;
1863 shost = lpfc_shost_from_vport(vport);
1864 spin_lock_irq(shost->host_lock);
1865 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
1866 if (ndlp->nlp_type & NLP_FABRIC)
1868 if ((ndlp->nlp_state == NLP_STE_MAPPED_NODE) ||
1869 (ndlp->nlp_state == NLP_STE_UNMAPPED_NODE))
1872 spin_unlock_irq(shost->host_lock);
1877 * This routine will return the FC4 Type associated with the CT
1881 lpfc_get_gidft_type(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb)
1883 struct lpfc_sli_ct_request *CtReq;
1884 struct lpfc_dmabuf *mp;
1887 mp = cmdiocb->context1;
1890 CtReq = (struct lpfc_sli_ct_request *)mp->virt;
1891 type = (uint32_t)CtReq->un.gid.Fc4Type;
1892 if ((type != SLI_CTPT_FCP) && (type != SLI_CTPT_NVME))
1900 * Issue Cmd to NameServer
1905 lpfc_ns_cmd(struct lpfc_vport *vport, int cmdcode,
1906 uint8_t retry, uint32_t context)
1908 struct lpfc_nodelist * ndlp;
1909 struct lpfc_hba *phba = vport->phba;
1910 struct lpfc_dmabuf *mp, *bmp;
1911 struct lpfc_sli_ct_request *CtReq;
1912 struct ulp_bde64 *bpl;
1913 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
1914 struct lpfc_iocbq *) = NULL;
1916 uint32_t rsp_size = 1024;
1920 ndlp = lpfc_findnode_did(vport, NameServer_DID);
1921 if (!ndlp || ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) {
1926 /* fill in BDEs for command */
1927 /* Allocate buffer for command payload */
1928 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
1934 INIT_LIST_HEAD(&mp->list);
1935 mp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(mp->phys));
1938 goto ns_cmd_free_mp;
1941 /* Allocate buffer for Buffer ptr list */
1942 bmp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
1945 goto ns_cmd_free_mpvirt;
1948 INIT_LIST_HEAD(&bmp->list);
1949 bmp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(bmp->phys));
1952 goto ns_cmd_free_bmp;
1955 /* NameServer Req */
1956 lpfc_printf_vlog(vport, KERN_INFO ,LOG_DISCOVERY,
1957 "0236 NameServer Req Data: x%x x%x x%x x%x\n",
1958 cmdcode, vport->fc_flag, vport->fc_rscn_id_cnt,
1961 bpl = (struct ulp_bde64 *) bmp->virt;
1962 memset(bpl, 0, sizeof(struct ulp_bde64));
1963 bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys) );
1964 bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys) );
1965 bpl->tus.f.bdeFlags = 0;
1966 if (cmdcode == SLI_CTNS_GID_FT)
1967 bpl->tus.f.bdeSize = GID_REQUEST_SZ;
1968 else if (cmdcode == SLI_CTNS_GID_PT)
1969 bpl->tus.f.bdeSize = GID_REQUEST_SZ;
1970 else if (cmdcode == SLI_CTNS_GFF_ID)
1971 bpl->tus.f.bdeSize = GFF_REQUEST_SZ;
1972 else if (cmdcode == SLI_CTNS_GFT_ID)
1973 bpl->tus.f.bdeSize = GFT_REQUEST_SZ;
1974 else if (cmdcode == SLI_CTNS_RFT_ID)
1975 bpl->tus.f.bdeSize = RFT_REQUEST_SZ;
1976 else if (cmdcode == SLI_CTNS_RNN_ID)
1977 bpl->tus.f.bdeSize = RNN_REQUEST_SZ;
1978 else if (cmdcode == SLI_CTNS_RSPN_ID)
1979 bpl->tus.f.bdeSize = RSPN_REQUEST_SZ;
1980 else if (cmdcode == SLI_CTNS_RSNN_NN)
1981 bpl->tus.f.bdeSize = RSNN_REQUEST_SZ;
1982 else if (cmdcode == SLI_CTNS_DA_ID)
1983 bpl->tus.f.bdeSize = DA_ID_REQUEST_SZ;
1984 else if (cmdcode == SLI_CTNS_RFF_ID)
1985 bpl->tus.f.bdeSize = RFF_REQUEST_SZ;
1987 bpl->tus.f.bdeSize = 0;
1988 bpl->tus.w = le32_to_cpu(bpl->tus.w);
1990 CtReq = (struct lpfc_sli_ct_request *) mp->virt;
1991 memset(CtReq, 0, sizeof(struct lpfc_sli_ct_request));
1992 CtReq->RevisionId.bits.Revision = SLI_CT_REVISION;
1993 CtReq->RevisionId.bits.InId = 0;
1994 CtReq->FsType = SLI_CT_DIRECTORY_SERVICE;
1995 CtReq->FsSubType = SLI_CT_DIRECTORY_NAME_SERVER;
1996 CtReq->CommandResponse.bits.Size = 0;
1998 case SLI_CTNS_GID_FT:
1999 CtReq->CommandResponse.bits.CmdRsp =
2000 cpu_to_be16(SLI_CTNS_GID_FT);
2001 CtReq->un.gid.Fc4Type = context;
2003 if (vport->port_state < LPFC_NS_QRY)
2004 vport->port_state = LPFC_NS_QRY;
2005 lpfc_set_disctmo(vport);
2006 cmpl = lpfc_cmpl_ct_cmd_gid_ft;
2007 rsp_size = FC_MAX_NS_RSP;
2010 case SLI_CTNS_GID_PT:
2011 CtReq->CommandResponse.bits.CmdRsp =
2012 cpu_to_be16(SLI_CTNS_GID_PT);
2013 CtReq->un.gid.PortType = context;
2015 if (vport->port_state < LPFC_NS_QRY)
2016 vport->port_state = LPFC_NS_QRY;
2017 lpfc_set_disctmo(vport);
2018 cmpl = lpfc_cmpl_ct_cmd_gid_pt;
2019 rsp_size = FC_MAX_NS_RSP;
2022 case SLI_CTNS_GFF_ID:
2023 CtReq->CommandResponse.bits.CmdRsp =
2024 cpu_to_be16(SLI_CTNS_GFF_ID);
2025 CtReq->un.gff.PortId = cpu_to_be32(context);
2026 cmpl = lpfc_cmpl_ct_cmd_gff_id;
2029 case SLI_CTNS_GFT_ID:
2030 CtReq->CommandResponse.bits.CmdRsp =
2031 cpu_to_be16(SLI_CTNS_GFT_ID);
2032 CtReq->un.gft.PortId = cpu_to_be32(context);
2033 cmpl = lpfc_cmpl_ct_cmd_gft_id;
2036 case SLI_CTNS_RFT_ID:
2037 vport->ct_flags &= ~FC_CT_RFT_ID;
2038 CtReq->CommandResponse.bits.CmdRsp =
2039 cpu_to_be16(SLI_CTNS_RFT_ID);
2040 CtReq->un.rft.PortId = cpu_to_be32(vport->fc_myDID);
2042 /* Register FC4 FCP type if enabled. */
2043 if (vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH ||
2044 vport->cfg_enable_fc4_type == LPFC_ENABLE_FCP)
2045 CtReq->un.rft.fcpReg = 1;
2047 /* Register NVME type if enabled. Defined LE and swapped.
2048 * rsvd[0] is used as word1 because of the hard-coded
2049 * word0 usage in the ct_request data structure.
2051 if (vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH ||
2052 vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME)
2053 CtReq->un.rft.rsvd[0] =
2054 cpu_to_be32(LPFC_FC4_TYPE_BITMASK);
2056 ptr = (uint32_t *)CtReq;
2057 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2058 "6433 Issue RFT (%s %s): %08x %08x %08x %08x "
2059 "%08x %08x %08x %08x\n",
2060 CtReq->un.rft.fcpReg ? "FCP" : " ",
2061 CtReq->un.rft.rsvd[0] ? "NVME" : " ",
2062 *ptr, *(ptr + 1), *(ptr + 2), *(ptr + 3),
2063 *(ptr + 4), *(ptr + 5),
2064 *(ptr + 6), *(ptr + 7));
2065 cmpl = lpfc_cmpl_ct_cmd_rft_id;
2068 case SLI_CTNS_RNN_ID:
2069 vport->ct_flags &= ~FC_CT_RNN_ID;
2070 CtReq->CommandResponse.bits.CmdRsp =
2071 cpu_to_be16(SLI_CTNS_RNN_ID);
2072 CtReq->un.rnn.PortId = cpu_to_be32(vport->fc_myDID);
2073 memcpy(CtReq->un.rnn.wwnn, &vport->fc_nodename,
2074 sizeof(struct lpfc_name));
2075 cmpl = lpfc_cmpl_ct_cmd_rnn_id;
2078 case SLI_CTNS_RSPN_ID:
2079 vport->ct_flags &= ~FC_CT_RSPN_ID;
2080 CtReq->CommandResponse.bits.CmdRsp =
2081 cpu_to_be16(SLI_CTNS_RSPN_ID);
2082 CtReq->un.rspn.PortId = cpu_to_be32(vport->fc_myDID);
2083 size = sizeof(CtReq->un.rspn.symbname);
2084 CtReq->un.rspn.len =
2085 lpfc_vport_symbolic_port_name(vport,
2086 CtReq->un.rspn.symbname, size);
2087 cmpl = lpfc_cmpl_ct_cmd_rspn_id;
2089 case SLI_CTNS_RSNN_NN:
2090 vport->ct_flags &= ~FC_CT_RSNN_NN;
2091 CtReq->CommandResponse.bits.CmdRsp =
2092 cpu_to_be16(SLI_CTNS_RSNN_NN);
2093 memcpy(CtReq->un.rsnn.wwnn, &vport->fc_nodename,
2094 sizeof(struct lpfc_name));
2095 size = sizeof(CtReq->un.rsnn.symbname);
2096 CtReq->un.rsnn.len =
2097 lpfc_vport_symbolic_node_name(vport,
2098 CtReq->un.rsnn.symbname, size);
2099 cmpl = lpfc_cmpl_ct_cmd_rsnn_nn;
2101 case SLI_CTNS_DA_ID:
2102 /* Implement DA_ID Nameserver request */
2103 CtReq->CommandResponse.bits.CmdRsp =
2104 cpu_to_be16(SLI_CTNS_DA_ID);
2105 CtReq->un.da_id.port_id = cpu_to_be32(vport->fc_myDID);
2106 cmpl = lpfc_cmpl_ct_cmd_da_id;
2108 case SLI_CTNS_RFF_ID:
2109 vport->ct_flags &= ~FC_CT_RFF_ID;
2110 CtReq->CommandResponse.bits.CmdRsp =
2111 cpu_to_be16(SLI_CTNS_RFF_ID);
2112 CtReq->un.rff.PortId = cpu_to_be32(vport->fc_myDID);
2113 CtReq->un.rff.fbits = FC4_FEATURE_INIT;
2115 /* The driver always supports FC_TYPE_FCP. However, the
2116 * caller can specify NVME (type x28) as well. But only
2117 * these that FC4 type is supported.
2119 if (((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
2120 (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) &&
2121 (context == FC_TYPE_NVME)) {
2122 if ((vport == phba->pport) && phba->nvmet_support) {
2123 CtReq->un.rff.fbits = (FC4_FEATURE_TARGET |
2124 FC4_FEATURE_NVME_DISC);
2125 lpfc_nvmet_update_targetport(phba);
2127 lpfc_nvme_update_localport(vport);
2129 CtReq->un.rff.type_code = context;
2131 } else if (((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
2132 (vport->cfg_enable_fc4_type == LPFC_ENABLE_FCP)) &&
2133 (context == FC_TYPE_FCP))
2134 CtReq->un.rff.type_code = context;
2137 goto ns_cmd_free_bmpvirt;
2139 ptr = (uint32_t *)CtReq;
2140 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2141 "6434 Issue RFF (%s): %08x %08x %08x %08x "
2142 "%08x %08x %08x %08x\n",
2143 (context == FC_TYPE_NVME) ? "NVME" : "FCP",
2144 *ptr, *(ptr + 1), *(ptr + 2), *(ptr + 3),
2145 *(ptr + 4), *(ptr + 5),
2146 *(ptr + 6), *(ptr + 7));
2147 cmpl = lpfc_cmpl_ct_cmd_rff_id;
2150 /* The lpfc_ct_cmd/lpfc_get_req shall increment ndlp reference count
2151 * to hold ndlp reference for the corresponding callback function.
2153 if (!lpfc_ct_cmd(vport, mp, bmp, ndlp, cmpl, rsp_size, retry)) {
2154 /* On success, The cmpl function will free the buffers */
2155 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
2156 "Issue CT cmd: cmd:x%x did:x%x",
2157 cmdcode, ndlp->nlp_DID, 0);
2162 ns_cmd_free_bmpvirt:
2163 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
2167 lpfc_mbuf_free(phba, mp->virt, mp->phys);
2171 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
2172 "0266 Issue NameServer Req x%x err %d Data: x%x x%x\n",
2173 cmdcode, rc, vport->fc_flag, vport->fc_rscn_id_cnt);
2178 * lpfc_cmpl_ct_disc_fdmi - Handle a discovery FDMI completion
2179 * @phba: Pointer to HBA context object.
2180 * @cmdiocb: Pointer to the command IOCBQ.
2181 * @rspiocb: Pointer to the response IOCBQ.
2183 * This function to handle the completion of a driver initiated FDMI
2184 * CT command issued during discovery.
2187 lpfc_cmpl_ct_disc_fdmi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2188 struct lpfc_iocbq *rspiocb)
2190 struct lpfc_vport *vport = cmdiocb->vport;
2191 struct lpfc_dmabuf *inp = cmdiocb->context1;
2192 struct lpfc_dmabuf *outp = cmdiocb->context2;
2193 struct lpfc_sli_ct_request *CTcmd = inp->virt;
2194 struct lpfc_sli_ct_request *CTrsp = outp->virt;
2195 uint16_t fdmi_cmd = CTcmd->CommandResponse.bits.CmdRsp;
2196 uint16_t fdmi_rsp = CTrsp->CommandResponse.bits.CmdRsp;
2197 IOCB_t *irsp = &rspiocb->iocb;
2198 struct lpfc_nodelist *ndlp, *free_ndlp = NULL;
2199 uint32_t latt, cmd, err;
2201 latt = lpfc_els_chk_latt(vport);
2202 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
2203 "FDMI cmpl: status:x%x/x%x latt:%d",
2204 irsp->ulpStatus, irsp->un.ulpWord[4], latt);
2206 if (latt || irsp->ulpStatus) {
2208 /* Look for a retryable error */
2209 if (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) {
2210 switch ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK)) {
2211 case IOERR_SLI_ABORTED:
2212 case IOERR_SLI_DOWN:
2213 /* Driver aborted this IO. No retry as error
2214 * is likely Offline->Online or some adapter
2215 * error. Recovery will try again.
2218 case IOERR_ABORT_IN_PROGRESS:
2219 case IOERR_SEQUENCE_TIMEOUT:
2220 case IOERR_ILLEGAL_FRAME:
2221 case IOERR_NO_RESOURCES:
2222 case IOERR_ILLEGAL_COMMAND:
2224 if (cmdiocb->retry >= LPFC_FDMI_MAX_RETRY)
2227 /* Retry the same FDMI command */
2228 err = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING,
2230 if (err == IOCB_ERROR)
2238 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2239 "0229 FDMI cmd %04x failed, latt = %d "
2240 "ulpStatus: x%x, rid x%x\n",
2241 be16_to_cpu(fdmi_cmd), latt, irsp->ulpStatus,
2242 irsp->un.ulpWord[4]);
2245 free_ndlp = cmdiocb->context_un.ndlp;
2246 lpfc_ct_free_iocb(phba, cmdiocb);
2247 lpfc_nlp_put(free_ndlp);
2249 ndlp = lpfc_findnode_did(vport, FDMI_DID);
2253 /* Check for a CT LS_RJT response */
2254 cmd = be16_to_cpu(fdmi_cmd);
2255 if (fdmi_rsp == cpu_to_be16(SLI_CT_RESPONSE_FS_RJT)) {
2256 /* FDMI rsp failed */
2257 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2258 "0220 FDMI cmd failed FS_RJT Data: x%x", cmd);
2260 /* Should we fallback to FDMI-2 / FDMI-1 ? */
2263 if (vport->fdmi_hba_mask == LPFC_FDMI2_HBA_ATTR) {
2264 /* Fallback to FDMI-1 */
2265 vport->fdmi_hba_mask = LPFC_FDMI1_HBA_ATTR;
2266 vport->fdmi_port_mask = LPFC_FDMI1_PORT_ATTR;
2268 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA, 0);
2273 if (vport->fdmi_port_mask == LPFC_FDMI2_PORT_ATTR) {
2274 /* Fallback to FDMI-1 */
2275 vport->fdmi_port_mask = LPFC_FDMI1_PORT_ATTR;
2277 lpfc_fdmi_cmd(vport, ndlp, cmd, 0);
2280 if (vport->fdmi_port_mask == LPFC_FDMI2_SMART_ATTR) {
2281 vport->fdmi_port_mask = LPFC_FDMI2_PORT_ATTR;
2282 /* Retry the same command */
2283 lpfc_fdmi_cmd(vport, ndlp, cmd, 0);
2288 /* No retry on Vendor, RPA only done on physical port */
2289 if (phba->link_flag & LS_CT_VEN_RPA) {
2290 phba->link_flag &= ~LS_CT_VEN_RPA;
2291 if (phba->cmf_active_mode == LPFC_CFG_OFF)
2293 lpfc_printf_log(phba, KERN_ERR,
2294 LOG_DISCOVERY | LOG_ELS,
2295 "6460 VEN FDMI RPA failure\n");
2298 if (vport->fdmi_port_mask == LPFC_FDMI2_PORT_ATTR) {
2299 /* Fallback to FDMI-1 */
2300 vport->fdmi_hba_mask = LPFC_FDMI1_HBA_ATTR;
2301 vport->fdmi_port_mask = LPFC_FDMI1_PORT_ATTR;
2303 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA, 0);
2306 if (vport->fdmi_port_mask == LPFC_FDMI2_SMART_ATTR) {
2307 vport->fdmi_port_mask = LPFC_FDMI2_PORT_ATTR;
2308 /* Retry the same command */
2309 lpfc_fdmi_cmd(vport, ndlp, cmd, 0);
2316 * On success, need to cycle thru FDMI registration for discovery
2317 * DHBA -> DPRT -> RHBA -> RPA (physical port)
2318 * DPRT -> RPRT (vports)
2322 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RPA, 0);
2326 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DPRT, 0);
2330 if (vport->port_type == LPFC_PHYSICAL_PORT)
2331 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RHBA, 0);
2333 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RPRT, 0);
2336 if (vport->port_type == LPFC_PHYSICAL_PORT &&
2337 phba->sli4_hba.pc_sli4_params.mi_ver) {
2338 /* mi is only for the phyical port, no vports */
2339 if (phba->link_flag & LS_CT_VEN_RPA) {
2340 lpfc_printf_vlog(vport, KERN_INFO,
2341 LOG_DISCOVERY | LOG_ELS |
2343 "6449 VEN RPA FDMI Success\n");
2344 phba->link_flag &= ~LS_CT_VEN_RPA;
2348 lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT,
2349 "6210 Issue Vendor MI FDMI %x\n",
2350 phba->sli4_hba.pc_sli4_params.mi_ver);
2352 /* CGN is only for the physical port, no vports */
2353 if (lpfc_fdmi_cmd(vport, ndlp, cmd,
2354 LPFC_FDMI_VENDOR_ATTR_mi) == 0)
2355 phba->link_flag |= LS_CT_VEN_RPA;
2356 lpfc_printf_log(phba, KERN_INFO,
2357 LOG_DISCOVERY | LOG_ELS,
2358 "6458 Send MI FDMI:%x Flag x%x\n",
2359 phba->sli4_hba.pc_sli4_params.mi_ver,
2362 lpfc_printf_log(phba, KERN_INFO,
2363 LOG_DISCOVERY | LOG_ELS,
2364 "6459 No FDMI VEN MI support - "
2374 * lpfc_fdmi_change_check - Check for changed FDMI parameters
2375 * @vport: pointer to a host virtual N_Port data structure.
2377 * Check how many mapped NPorts we are connected to
2378 * Check if our hostname changed
2379 * Called from hbeat timeout routine to check if any FDMI parameters
2380 * changed. If so, re-register those Attributes.
2383 lpfc_fdmi_change_check(struct lpfc_vport *vport)
2385 struct lpfc_hba *phba = vport->phba;
2386 struct lpfc_nodelist *ndlp;
2389 if (!lpfc_is_link_up(phba))
2392 /* Must be connected to a Fabric */
2393 if (!(vport->fc_flag & FC_FABRIC))
2396 ndlp = lpfc_findnode_did(vport, FDMI_DID);
2400 /* Check if system hostname changed */
2401 if (strcmp(phba->os_host_name, init_utsname()->nodename)) {
2402 memset(phba->os_host_name, 0, sizeof(phba->os_host_name));
2403 scnprintf(phba->os_host_name, sizeof(phba->os_host_name), "%s",
2404 init_utsname()->nodename);
2405 lpfc_ns_cmd(vport, SLI_CTNS_RSNN_NN, 0, 0);
2407 /* Since this effects multiple HBA and PORT attributes, we need
2408 * de-register and go thru the whole FDMI registration cycle.
2409 * DHBA -> DPRT -> RHBA -> RPA (physical port)
2410 * DPRT -> RPRT (vports)
2412 if (vport->port_type == LPFC_PHYSICAL_PORT) {
2413 /* For extra Vendor RPA */
2414 phba->link_flag &= ~LS_CT_VEN_RPA;
2415 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA, 0);
2417 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DPRT, 0);
2420 /* Since this code path registers all the port attributes
2421 * we can just return without further checking.
2426 if (!(vport->fdmi_port_mask & LPFC_FDMI_PORT_ATTR_num_disc))
2429 /* Check if the number of mapped NPorts changed */
2430 cnt = lpfc_find_map_node(vport);
2431 if (cnt == vport->fdmi_num_disc)
2434 if (vport->port_type == LPFC_PHYSICAL_PORT) {
2435 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RPA,
2436 LPFC_FDMI_PORT_ATTR_num_disc);
2438 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RPRT,
2439 LPFC_FDMI_PORT_ATTR_num_disc);
2443 /* Routines for all individual HBA attributes */
2445 lpfc_fdmi_hba_attr_wwnn(struct lpfc_vport *vport, struct lpfc_fdmi_attr_def *ad)
2447 struct lpfc_fdmi_attr_entry *ae;
2450 ae = &ad->AttrValue;
2451 memset(ae, 0, sizeof(*ae));
2453 memcpy(&ae->un.AttrWWN, &vport->fc_sparam.nodeName,
2454 sizeof(struct lpfc_name));
2455 size = FOURBYTES + sizeof(struct lpfc_name);
2456 ad->AttrLen = cpu_to_be16(size);
2457 ad->AttrType = cpu_to_be16(RHBA_NODENAME);
2461 lpfc_fdmi_hba_attr_manufacturer(struct lpfc_vport *vport,
2462 struct lpfc_fdmi_attr_def *ad)
2464 struct lpfc_fdmi_attr_entry *ae;
2467 ae = &ad->AttrValue;
2468 memset(ae, 0, sizeof(*ae));
2470 /* This string MUST be consistent with other FC platforms
2471 * supported by Broadcom.
2473 strncpy(ae->un.AttrString,
2474 "Emulex Corporation",
2475 sizeof(ae->un.AttrString));
2476 len = strnlen(ae->un.AttrString,
2477 sizeof(ae->un.AttrString));
2478 len += (len & 3) ? (4 - (len & 3)) : 4;
2479 size = FOURBYTES + len;
2480 ad->AttrLen = cpu_to_be16(size);
2481 ad->AttrType = cpu_to_be16(RHBA_MANUFACTURER);
2486 lpfc_fdmi_hba_attr_sn(struct lpfc_vport *vport, struct lpfc_fdmi_attr_def *ad)
2488 struct lpfc_hba *phba = vport->phba;
2489 struct lpfc_fdmi_attr_entry *ae;
2492 ae = &ad->AttrValue;
2493 memset(ae, 0, sizeof(*ae));
2495 strncpy(ae->un.AttrString, phba->SerialNumber,
2496 sizeof(ae->un.AttrString));
2497 len = strnlen(ae->un.AttrString,
2498 sizeof(ae->un.AttrString));
2499 len += (len & 3) ? (4 - (len & 3)) : 4;
2500 size = FOURBYTES + len;
2501 ad->AttrLen = cpu_to_be16(size);
2502 ad->AttrType = cpu_to_be16(RHBA_SERIAL_NUMBER);
2507 lpfc_fdmi_hba_attr_model(struct lpfc_vport *vport,
2508 struct lpfc_fdmi_attr_def *ad)
2510 struct lpfc_hba *phba = vport->phba;
2511 struct lpfc_fdmi_attr_entry *ae;
2514 ae = &ad->AttrValue;
2515 memset(ae, 0, sizeof(*ae));
2517 strncpy(ae->un.AttrString, phba->ModelName,
2518 sizeof(ae->un.AttrString));
2519 len = strnlen(ae->un.AttrString, sizeof(ae->un.AttrString));
2520 len += (len & 3) ? (4 - (len & 3)) : 4;
2521 size = FOURBYTES + len;
2522 ad->AttrLen = cpu_to_be16(size);
2523 ad->AttrType = cpu_to_be16(RHBA_MODEL);
2528 lpfc_fdmi_hba_attr_description(struct lpfc_vport *vport,
2529 struct lpfc_fdmi_attr_def *ad)
2531 struct lpfc_hba *phba = vport->phba;
2532 struct lpfc_fdmi_attr_entry *ae;
2535 ae = &ad->AttrValue;
2536 memset(ae, 0, sizeof(*ae));
2538 strncpy(ae->un.AttrString, phba->ModelDesc,
2539 sizeof(ae->un.AttrString));
2540 len = strnlen(ae->un.AttrString,
2541 sizeof(ae->un.AttrString));
2542 len += (len & 3) ? (4 - (len & 3)) : 4;
2543 size = FOURBYTES + len;
2544 ad->AttrLen = cpu_to_be16(size);
2545 ad->AttrType = cpu_to_be16(RHBA_MODEL_DESCRIPTION);
2550 lpfc_fdmi_hba_attr_hdw_ver(struct lpfc_vport *vport,
2551 struct lpfc_fdmi_attr_def *ad)
2553 struct lpfc_hba *phba = vport->phba;
2554 lpfc_vpd_t *vp = &phba->vpd;
2555 struct lpfc_fdmi_attr_entry *ae;
2556 uint32_t i, j, incr, size;
2558 ae = &ad->AttrValue;
2559 memset(ae, 0, sizeof(*ae));
2561 /* Convert JEDEC ID to ascii for hardware version */
2562 incr = vp->rev.biuRev;
2563 for (i = 0; i < 8; i++) {
2566 ae->un.AttrString[7 - i] =
2567 (char)((uint8_t) 0x30 +
2570 ae->un.AttrString[7 - i] =
2571 (char)((uint8_t) 0x61 +
2572 (uint8_t) (j - 10));
2575 size = FOURBYTES + 8;
2576 ad->AttrLen = cpu_to_be16(size);
2577 ad->AttrType = cpu_to_be16(RHBA_HARDWARE_VERSION);
2582 lpfc_fdmi_hba_attr_drvr_ver(struct lpfc_vport *vport,
2583 struct lpfc_fdmi_attr_def *ad)
2585 struct lpfc_fdmi_attr_entry *ae;
2588 ae = &ad->AttrValue;
2589 memset(ae, 0, sizeof(*ae));
2591 strncpy(ae->un.AttrString, lpfc_release_version,
2592 sizeof(ae->un.AttrString));
2593 len = strnlen(ae->un.AttrString,
2594 sizeof(ae->un.AttrString));
2595 len += (len & 3) ? (4 - (len & 3)) : 4;
2596 size = FOURBYTES + len;
2597 ad->AttrLen = cpu_to_be16(size);
2598 ad->AttrType = cpu_to_be16(RHBA_DRIVER_VERSION);
2603 lpfc_fdmi_hba_attr_rom_ver(struct lpfc_vport *vport,
2604 struct lpfc_fdmi_attr_def *ad)
2606 struct lpfc_hba *phba = vport->phba;
2607 struct lpfc_fdmi_attr_entry *ae;
2610 ae = &ad->AttrValue;
2611 memset(ae, 0, sizeof(*ae));
2613 if (phba->sli_rev == LPFC_SLI_REV4)
2614 lpfc_decode_firmware_rev(phba, ae->un.AttrString, 1);
2616 strncpy(ae->un.AttrString, phba->OptionROMVersion,
2617 sizeof(ae->un.AttrString));
2618 len = strnlen(ae->un.AttrString,
2619 sizeof(ae->un.AttrString));
2620 len += (len & 3) ? (4 - (len & 3)) : 4;
2621 size = FOURBYTES + len;
2622 ad->AttrLen = cpu_to_be16(size);
2623 ad->AttrType = cpu_to_be16(RHBA_OPTION_ROM_VERSION);
2628 lpfc_fdmi_hba_attr_fmw_ver(struct lpfc_vport *vport,
2629 struct lpfc_fdmi_attr_def *ad)
2631 struct lpfc_hba *phba = vport->phba;
2632 struct lpfc_fdmi_attr_entry *ae;
2635 ae = &ad->AttrValue;
2636 memset(ae, 0, sizeof(*ae));
2638 lpfc_decode_firmware_rev(phba, ae->un.AttrString, 1);
2639 len = strnlen(ae->un.AttrString,
2640 sizeof(ae->un.AttrString));
2641 len += (len & 3) ? (4 - (len & 3)) : 4;
2642 size = FOURBYTES + len;
2643 ad->AttrLen = cpu_to_be16(size);
2644 ad->AttrType = cpu_to_be16(RHBA_FIRMWARE_VERSION);
2649 lpfc_fdmi_hba_attr_os_ver(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 snprintf(ae->un.AttrString, sizeof(ae->un.AttrString), "%s %s %s",
2659 init_utsname()->sysname,
2660 init_utsname()->release,
2661 init_utsname()->version);
2663 len = strnlen(ae->un.AttrString, sizeof(ae->un.AttrString));
2664 len += (len & 3) ? (4 - (len & 3)) : 4;
2665 size = FOURBYTES + len;
2666 ad->AttrLen = cpu_to_be16(size);
2667 ad->AttrType = cpu_to_be16(RHBA_OS_NAME_VERSION);
2672 lpfc_fdmi_hba_attr_ct_len(struct lpfc_vport *vport,
2673 struct lpfc_fdmi_attr_def *ad)
2675 struct lpfc_fdmi_attr_entry *ae;
2678 ae = &ad->AttrValue;
2680 ae->un.AttrInt = cpu_to_be32(LPFC_MAX_CT_SIZE);
2681 size = FOURBYTES + sizeof(uint32_t);
2682 ad->AttrLen = cpu_to_be16(size);
2683 ad->AttrType = cpu_to_be16(RHBA_MAX_CT_PAYLOAD_LEN);
2688 lpfc_fdmi_hba_attr_symbolic_name(struct lpfc_vport *vport,
2689 struct lpfc_fdmi_attr_def *ad)
2691 struct lpfc_fdmi_attr_entry *ae;
2694 ae = &ad->AttrValue;
2695 memset(ae, 0, sizeof(*ae));
2697 len = lpfc_vport_symbolic_node_name(vport,
2698 ae->un.AttrString, 256);
2699 len += (len & 3) ? (4 - (len & 3)) : 4;
2700 size = FOURBYTES + len;
2701 ad->AttrLen = cpu_to_be16(size);
2702 ad->AttrType = cpu_to_be16(RHBA_SYM_NODENAME);
2707 lpfc_fdmi_hba_attr_vendor_info(struct lpfc_vport *vport,
2708 struct lpfc_fdmi_attr_def *ad)
2710 struct lpfc_fdmi_attr_entry *ae;
2713 ae = &ad->AttrValue;
2715 /* Nothing is defined for this currently */
2716 ae->un.AttrInt = cpu_to_be32(0);
2717 size = FOURBYTES + sizeof(uint32_t);
2718 ad->AttrLen = cpu_to_be16(size);
2719 ad->AttrType = cpu_to_be16(RHBA_VENDOR_INFO);
2724 lpfc_fdmi_hba_attr_num_ports(struct lpfc_vport *vport,
2725 struct lpfc_fdmi_attr_def *ad)
2727 struct lpfc_fdmi_attr_entry *ae;
2730 ae = &ad->AttrValue;
2732 /* Each driver instance corresponds to a single port */
2733 ae->un.AttrInt = cpu_to_be32(1);
2734 size = FOURBYTES + sizeof(uint32_t);
2735 ad->AttrLen = cpu_to_be16(size);
2736 ad->AttrType = cpu_to_be16(RHBA_NUM_PORTS);
2741 lpfc_fdmi_hba_attr_fabric_wwnn(struct lpfc_vport *vport,
2742 struct lpfc_fdmi_attr_def *ad)
2744 struct lpfc_fdmi_attr_entry *ae;
2747 ae = &ad->AttrValue;
2748 memset(ae, 0, sizeof(*ae));
2750 memcpy(&ae->un.AttrWWN, &vport->fabric_nodename,
2751 sizeof(struct lpfc_name));
2752 size = FOURBYTES + sizeof(struct lpfc_name);
2753 ad->AttrLen = cpu_to_be16(size);
2754 ad->AttrType = cpu_to_be16(RHBA_FABRIC_WWNN);
2759 lpfc_fdmi_hba_attr_bios_ver(struct lpfc_vport *vport,
2760 struct lpfc_fdmi_attr_def *ad)
2762 struct lpfc_hba *phba = vport->phba;
2763 struct lpfc_fdmi_attr_entry *ae;
2766 ae = &ad->AttrValue;
2767 memset(ae, 0, sizeof(*ae));
2769 strlcat(ae->un.AttrString, phba->BIOSVersion,
2770 sizeof(ae->un.AttrString));
2771 len = strnlen(ae->un.AttrString,
2772 sizeof(ae->un.AttrString));
2773 len += (len & 3) ? (4 - (len & 3)) : 4;
2774 size = FOURBYTES + len;
2775 ad->AttrLen = cpu_to_be16(size);
2776 ad->AttrType = cpu_to_be16(RHBA_BIOS_VERSION);
2781 lpfc_fdmi_hba_attr_bios_state(struct lpfc_vport *vport,
2782 struct lpfc_fdmi_attr_def *ad)
2784 struct lpfc_fdmi_attr_entry *ae;
2787 ae = &ad->AttrValue;
2789 /* Driver doesn't have access to this information */
2790 ae->un.AttrInt = cpu_to_be32(0);
2791 size = FOURBYTES + sizeof(uint32_t);
2792 ad->AttrLen = cpu_to_be16(size);
2793 ad->AttrType = cpu_to_be16(RHBA_BIOS_STATE);
2798 lpfc_fdmi_hba_attr_vendor_id(struct lpfc_vport *vport,
2799 struct lpfc_fdmi_attr_def *ad)
2801 struct lpfc_fdmi_attr_entry *ae;
2804 ae = &ad->AttrValue;
2805 memset(ae, 0, sizeof(*ae));
2807 strncpy(ae->un.AttrString, "EMULEX",
2808 sizeof(ae->un.AttrString));
2809 len = strnlen(ae->un.AttrString,
2810 sizeof(ae->un.AttrString));
2811 len += (len & 3) ? (4 - (len & 3)) : 4;
2812 size = FOURBYTES + len;
2813 ad->AttrLen = cpu_to_be16(size);
2814 ad->AttrType = cpu_to_be16(RHBA_VENDOR_ID);
2818 /* Routines for all individual PORT attributes */
2820 lpfc_fdmi_port_attr_fc4type(struct lpfc_vport *vport,
2821 struct lpfc_fdmi_attr_def *ad)
2823 struct lpfc_hba *phba = vport->phba;
2824 struct lpfc_fdmi_attr_entry *ae;
2827 ae = &ad->AttrValue;
2828 memset(ae, 0, sizeof(*ae));
2830 ae->un.AttrTypes[2] = 0x01; /* Type 0x8 - FCP */
2831 ae->un.AttrTypes[7] = 0x01; /* Type 0x20 - CT */
2833 /* Check to see if Firmware supports NVME and on physical port */
2834 if ((phba->sli_rev == LPFC_SLI_REV4) && (vport == phba->pport) &&
2835 phba->sli4_hba.pc_sli4_params.nvme)
2836 ae->un.AttrTypes[6] = 0x01; /* Type 0x28 - NVME */
2838 size = FOURBYTES + 32;
2839 ad->AttrLen = cpu_to_be16(size);
2840 ad->AttrType = cpu_to_be16(RPRT_SUPPORTED_FC4_TYPES);
2845 lpfc_fdmi_port_attr_support_speed(struct lpfc_vport *vport,
2846 struct lpfc_fdmi_attr_def *ad)
2848 struct lpfc_hba *phba = vport->phba;
2849 struct lpfc_fdmi_attr_entry *ae;
2852 ae = &ad->AttrValue;
2855 if (!(phba->hba_flag & HBA_FCOE_MODE)) {
2856 if (phba->lmt & LMT_256Gb)
2857 ae->un.AttrInt |= HBA_PORTSPEED_256GFC;
2858 if (phba->lmt & LMT_128Gb)
2859 ae->un.AttrInt |= HBA_PORTSPEED_128GFC;
2860 if (phba->lmt & LMT_64Gb)
2861 ae->un.AttrInt |= HBA_PORTSPEED_64GFC;
2862 if (phba->lmt & LMT_32Gb)
2863 ae->un.AttrInt |= HBA_PORTSPEED_32GFC;
2864 if (phba->lmt & LMT_16Gb)
2865 ae->un.AttrInt |= HBA_PORTSPEED_16GFC;
2866 if (phba->lmt & LMT_10Gb)
2867 ae->un.AttrInt |= HBA_PORTSPEED_10GFC;
2868 if (phba->lmt & LMT_8Gb)
2869 ae->un.AttrInt |= HBA_PORTSPEED_8GFC;
2870 if (phba->lmt & LMT_4Gb)
2871 ae->un.AttrInt |= HBA_PORTSPEED_4GFC;
2872 if (phba->lmt & LMT_2Gb)
2873 ae->un.AttrInt |= HBA_PORTSPEED_2GFC;
2874 if (phba->lmt & LMT_1Gb)
2875 ae->un.AttrInt |= HBA_PORTSPEED_1GFC;
2877 /* FCoE links support only one speed */
2878 switch (phba->fc_linkspeed) {
2879 case LPFC_ASYNC_LINK_SPEED_10GBPS:
2880 ae->un.AttrInt = HBA_PORTSPEED_10GE;
2882 case LPFC_ASYNC_LINK_SPEED_25GBPS:
2883 ae->un.AttrInt = HBA_PORTSPEED_25GE;
2885 case LPFC_ASYNC_LINK_SPEED_40GBPS:
2886 ae->un.AttrInt = HBA_PORTSPEED_40GE;
2888 case LPFC_ASYNC_LINK_SPEED_100GBPS:
2889 ae->un.AttrInt = HBA_PORTSPEED_100GE;
2893 ae->un.AttrInt = cpu_to_be32(ae->un.AttrInt);
2894 size = FOURBYTES + sizeof(uint32_t);
2895 ad->AttrLen = cpu_to_be16(size);
2896 ad->AttrType = cpu_to_be16(RPRT_SUPPORTED_SPEED);
2901 lpfc_fdmi_port_attr_speed(struct lpfc_vport *vport,
2902 struct lpfc_fdmi_attr_def *ad)
2904 struct lpfc_hba *phba = vport->phba;
2905 struct lpfc_fdmi_attr_entry *ae;
2908 ae = &ad->AttrValue;
2910 if (!(phba->hba_flag & HBA_FCOE_MODE)) {
2911 switch (phba->fc_linkspeed) {
2912 case LPFC_LINK_SPEED_1GHZ:
2913 ae->un.AttrInt = HBA_PORTSPEED_1GFC;
2915 case LPFC_LINK_SPEED_2GHZ:
2916 ae->un.AttrInt = HBA_PORTSPEED_2GFC;
2918 case LPFC_LINK_SPEED_4GHZ:
2919 ae->un.AttrInt = HBA_PORTSPEED_4GFC;
2921 case LPFC_LINK_SPEED_8GHZ:
2922 ae->un.AttrInt = HBA_PORTSPEED_8GFC;
2924 case LPFC_LINK_SPEED_10GHZ:
2925 ae->un.AttrInt = HBA_PORTSPEED_10GFC;
2927 case LPFC_LINK_SPEED_16GHZ:
2928 ae->un.AttrInt = HBA_PORTSPEED_16GFC;
2930 case LPFC_LINK_SPEED_32GHZ:
2931 ae->un.AttrInt = HBA_PORTSPEED_32GFC;
2933 case LPFC_LINK_SPEED_64GHZ:
2934 ae->un.AttrInt = HBA_PORTSPEED_64GFC;
2936 case LPFC_LINK_SPEED_128GHZ:
2937 ae->un.AttrInt = HBA_PORTSPEED_128GFC;
2939 case LPFC_LINK_SPEED_256GHZ:
2940 ae->un.AttrInt = HBA_PORTSPEED_256GFC;
2943 ae->un.AttrInt = HBA_PORTSPEED_UNKNOWN;
2947 switch (phba->fc_linkspeed) {
2948 case LPFC_ASYNC_LINK_SPEED_10GBPS:
2949 ae->un.AttrInt = HBA_PORTSPEED_10GE;
2951 case LPFC_ASYNC_LINK_SPEED_25GBPS:
2952 ae->un.AttrInt = HBA_PORTSPEED_25GE;
2954 case LPFC_ASYNC_LINK_SPEED_40GBPS:
2955 ae->un.AttrInt = HBA_PORTSPEED_40GE;
2957 case LPFC_ASYNC_LINK_SPEED_100GBPS:
2958 ae->un.AttrInt = HBA_PORTSPEED_100GE;
2961 ae->un.AttrInt = HBA_PORTSPEED_UNKNOWN;
2966 ae->un.AttrInt = cpu_to_be32(ae->un.AttrInt);
2967 size = FOURBYTES + sizeof(uint32_t);
2968 ad->AttrLen = cpu_to_be16(size);
2969 ad->AttrType = cpu_to_be16(RPRT_PORT_SPEED);
2974 lpfc_fdmi_port_attr_max_frame(struct lpfc_vport *vport,
2975 struct lpfc_fdmi_attr_def *ad)
2977 struct serv_parm *hsp;
2978 struct lpfc_fdmi_attr_entry *ae;
2981 ae = &ad->AttrValue;
2983 hsp = (struct serv_parm *)&vport->fc_sparam;
2984 ae->un.AttrInt = (((uint32_t) hsp->cmn.bbRcvSizeMsb & 0x0F) << 8) |
2985 (uint32_t) hsp->cmn.bbRcvSizeLsb;
2986 ae->un.AttrInt = cpu_to_be32(ae->un.AttrInt);
2987 size = FOURBYTES + sizeof(uint32_t);
2988 ad->AttrLen = cpu_to_be16(size);
2989 ad->AttrType = cpu_to_be16(RPRT_MAX_FRAME_SIZE);
2994 lpfc_fdmi_port_attr_os_devname(struct lpfc_vport *vport,
2995 struct lpfc_fdmi_attr_def *ad)
2997 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2998 struct lpfc_fdmi_attr_entry *ae;
3001 ae = &ad->AttrValue;
3002 memset(ae, 0, sizeof(*ae));
3004 snprintf(ae->un.AttrString, sizeof(ae->un.AttrString),
3005 "/sys/class/scsi_host/host%d", shost->host_no);
3006 len = strnlen((char *)ae->un.AttrString,
3007 sizeof(ae->un.AttrString));
3008 len += (len & 3) ? (4 - (len & 3)) : 4;
3009 size = FOURBYTES + len;
3010 ad->AttrLen = cpu_to_be16(size);
3011 ad->AttrType = cpu_to_be16(RPRT_OS_DEVICE_NAME);
3016 lpfc_fdmi_port_attr_host_name(struct lpfc_vport *vport,
3017 struct lpfc_fdmi_attr_def *ad)
3019 struct lpfc_fdmi_attr_entry *ae;
3022 ae = &ad->AttrValue;
3023 memset(ae, 0, sizeof(*ae));
3025 scnprintf(ae->un.AttrString, sizeof(ae->un.AttrString), "%s",
3026 vport->phba->os_host_name);
3028 len = strnlen(ae->un.AttrString, sizeof(ae->un.AttrString));
3029 len += (len & 3) ? (4 - (len & 3)) : 4;
3030 size = FOURBYTES + len;
3031 ad->AttrLen = cpu_to_be16(size);
3032 ad->AttrType = cpu_to_be16(RPRT_HOST_NAME);
3037 lpfc_fdmi_port_attr_wwnn(struct lpfc_vport *vport,
3038 struct lpfc_fdmi_attr_def *ad)
3040 struct lpfc_fdmi_attr_entry *ae;
3043 ae = &ad->AttrValue;
3044 memset(ae, 0, sizeof(*ae));
3046 memcpy(&ae->un.AttrWWN, &vport->fc_sparam.nodeName,
3047 sizeof(struct lpfc_name));
3048 size = FOURBYTES + sizeof(struct lpfc_name);
3049 ad->AttrLen = cpu_to_be16(size);
3050 ad->AttrType = cpu_to_be16(RPRT_NODENAME);
3055 lpfc_fdmi_port_attr_wwpn(struct lpfc_vport *vport,
3056 struct lpfc_fdmi_attr_def *ad)
3058 struct lpfc_fdmi_attr_entry *ae;
3061 ae = &ad->AttrValue;
3062 memset(ae, 0, sizeof(*ae));
3064 memcpy(&ae->un.AttrWWN, &vport->fc_sparam.portName,
3065 sizeof(struct lpfc_name));
3066 size = FOURBYTES + sizeof(struct lpfc_name);
3067 ad->AttrLen = cpu_to_be16(size);
3068 ad->AttrType = cpu_to_be16(RPRT_PORTNAME);
3073 lpfc_fdmi_port_attr_symbolic_name(struct lpfc_vport *vport,
3074 struct lpfc_fdmi_attr_def *ad)
3076 struct lpfc_fdmi_attr_entry *ae;
3079 ae = &ad->AttrValue;
3080 memset(ae, 0, sizeof(*ae));
3082 len = lpfc_vport_symbolic_port_name(vport, ae->un.AttrString, 256);
3083 len += (len & 3) ? (4 - (len & 3)) : 4;
3084 size = FOURBYTES + len;
3085 ad->AttrLen = cpu_to_be16(size);
3086 ad->AttrType = cpu_to_be16(RPRT_SYM_PORTNAME);
3091 lpfc_fdmi_port_attr_port_type(struct lpfc_vport *vport,
3092 struct lpfc_fdmi_attr_def *ad)
3094 struct lpfc_hba *phba = vport->phba;
3095 struct lpfc_fdmi_attr_entry *ae;
3098 ae = &ad->AttrValue;
3099 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP)
3100 ae->un.AttrInt = cpu_to_be32(LPFC_FDMI_PORTTYPE_NLPORT);
3102 ae->un.AttrInt = cpu_to_be32(LPFC_FDMI_PORTTYPE_NPORT);
3103 size = FOURBYTES + sizeof(uint32_t);
3104 ad->AttrLen = cpu_to_be16(size);
3105 ad->AttrType = cpu_to_be16(RPRT_PORT_TYPE);
3110 lpfc_fdmi_port_attr_class(struct lpfc_vport *vport,
3111 struct lpfc_fdmi_attr_def *ad)
3113 struct lpfc_fdmi_attr_entry *ae;
3116 ae = &ad->AttrValue;
3117 ae->un.AttrInt = cpu_to_be32(FC_COS_CLASS2 | FC_COS_CLASS3);
3118 size = FOURBYTES + sizeof(uint32_t);
3119 ad->AttrLen = cpu_to_be16(size);
3120 ad->AttrType = cpu_to_be16(RPRT_SUPPORTED_CLASS);
3125 lpfc_fdmi_port_attr_fabric_wwpn(struct lpfc_vport *vport,
3126 struct lpfc_fdmi_attr_def *ad)
3128 struct lpfc_fdmi_attr_entry *ae;
3131 ae = &ad->AttrValue;
3132 memset(ae, 0, sizeof(*ae));
3134 memcpy(&ae->un.AttrWWN, &vport->fabric_portname,
3135 sizeof(struct lpfc_name));
3136 size = FOURBYTES + sizeof(struct lpfc_name);
3137 ad->AttrLen = cpu_to_be16(size);
3138 ad->AttrType = cpu_to_be16(RPRT_FABRICNAME);
3143 lpfc_fdmi_port_attr_active_fc4type(struct lpfc_vport *vport,
3144 struct lpfc_fdmi_attr_def *ad)
3146 struct lpfc_fdmi_attr_entry *ae;
3149 ae = &ad->AttrValue;
3150 memset(ae, 0, sizeof(*ae));
3152 ae->un.AttrTypes[2] = 0x01; /* Type 0x8 - FCP */
3153 ae->un.AttrTypes[7] = 0x01; /* Type 0x20 - CT */
3155 /* Check to see if NVME is configured or not */
3156 if (vport->phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)
3157 ae->un.AttrTypes[6] = 0x1; /* Type 0x28 - NVME */
3159 size = FOURBYTES + 32;
3160 ad->AttrLen = cpu_to_be16(size);
3161 ad->AttrType = cpu_to_be16(RPRT_ACTIVE_FC4_TYPES);
3166 lpfc_fdmi_port_attr_port_state(struct lpfc_vport *vport,
3167 struct lpfc_fdmi_attr_def *ad)
3169 struct lpfc_fdmi_attr_entry *ae;
3172 ae = &ad->AttrValue;
3173 /* Link Up - operational */
3174 ae->un.AttrInt = cpu_to_be32(LPFC_FDMI_PORTSTATE_ONLINE);
3175 size = FOURBYTES + sizeof(uint32_t);
3176 ad->AttrLen = cpu_to_be16(size);
3177 ad->AttrType = cpu_to_be16(RPRT_PORT_STATE);
3182 lpfc_fdmi_port_attr_num_disc(struct lpfc_vport *vport,
3183 struct lpfc_fdmi_attr_def *ad)
3185 struct lpfc_fdmi_attr_entry *ae;
3188 ae = &ad->AttrValue;
3189 vport->fdmi_num_disc = lpfc_find_map_node(vport);
3190 ae->un.AttrInt = cpu_to_be32(vport->fdmi_num_disc);
3191 size = FOURBYTES + sizeof(uint32_t);
3192 ad->AttrLen = cpu_to_be16(size);
3193 ad->AttrType = cpu_to_be16(RPRT_DISC_PORT);
3198 lpfc_fdmi_port_attr_nportid(struct lpfc_vport *vport,
3199 struct lpfc_fdmi_attr_def *ad)
3201 struct lpfc_fdmi_attr_entry *ae;
3204 ae = &ad->AttrValue;
3205 ae->un.AttrInt = cpu_to_be32(vport->fc_myDID);
3206 size = FOURBYTES + sizeof(uint32_t);
3207 ad->AttrLen = cpu_to_be16(size);
3208 ad->AttrType = cpu_to_be16(RPRT_PORT_ID);
3213 lpfc_fdmi_smart_attr_service(struct lpfc_vport *vport,
3214 struct lpfc_fdmi_attr_def *ad)
3216 struct lpfc_fdmi_attr_entry *ae;
3219 ae = &ad->AttrValue;
3220 memset(ae, 0, sizeof(*ae));
3222 strncpy(ae->un.AttrString, "Smart SAN Initiator",
3223 sizeof(ae->un.AttrString));
3224 len = strnlen(ae->un.AttrString,
3225 sizeof(ae->un.AttrString));
3226 len += (len & 3) ? (4 - (len & 3)) : 4;
3227 size = FOURBYTES + len;
3228 ad->AttrLen = cpu_to_be16(size);
3229 ad->AttrType = cpu_to_be16(RPRT_SMART_SERVICE);
3234 lpfc_fdmi_smart_attr_guid(struct lpfc_vport *vport,
3235 struct lpfc_fdmi_attr_def *ad)
3237 struct lpfc_fdmi_attr_entry *ae;
3240 ae = &ad->AttrValue;
3241 memset(ae, 0, sizeof(*ae));
3243 memcpy(&ae->un.AttrString, &vport->fc_sparam.nodeName,
3244 sizeof(struct lpfc_name));
3245 memcpy((((uint8_t *)&ae->un.AttrString) +
3246 sizeof(struct lpfc_name)),
3247 &vport->fc_sparam.portName, sizeof(struct lpfc_name));
3248 size = FOURBYTES + (2 * sizeof(struct lpfc_name));
3249 ad->AttrLen = cpu_to_be16(size);
3250 ad->AttrType = cpu_to_be16(RPRT_SMART_GUID);
3255 lpfc_fdmi_smart_attr_version(struct lpfc_vport *vport,
3256 struct lpfc_fdmi_attr_def *ad)
3258 struct lpfc_fdmi_attr_entry *ae;
3261 ae = &ad->AttrValue;
3262 memset(ae, 0, sizeof(*ae));
3264 strncpy(ae->un.AttrString, "Smart SAN Version 2.0",
3265 sizeof(ae->un.AttrString));
3266 len = strnlen(ae->un.AttrString,
3267 sizeof(ae->un.AttrString));
3268 len += (len & 3) ? (4 - (len & 3)) : 4;
3269 size = FOURBYTES + len;
3270 ad->AttrLen = cpu_to_be16(size);
3271 ad->AttrType = cpu_to_be16(RPRT_SMART_VERSION);
3276 lpfc_fdmi_smart_attr_model(struct lpfc_vport *vport,
3277 struct lpfc_fdmi_attr_def *ad)
3279 struct lpfc_hba *phba = vport->phba;
3280 struct lpfc_fdmi_attr_entry *ae;
3283 ae = &ad->AttrValue;
3284 memset(ae, 0, sizeof(*ae));
3286 strncpy(ae->un.AttrString, phba->ModelName,
3287 sizeof(ae->un.AttrString));
3288 len = strnlen(ae->un.AttrString, sizeof(ae->un.AttrString));
3289 len += (len & 3) ? (4 - (len & 3)) : 4;
3290 size = FOURBYTES + len;
3291 ad->AttrLen = cpu_to_be16(size);
3292 ad->AttrType = cpu_to_be16(RPRT_SMART_MODEL);
3297 lpfc_fdmi_smart_attr_port_info(struct lpfc_vport *vport,
3298 struct lpfc_fdmi_attr_def *ad)
3300 struct lpfc_fdmi_attr_entry *ae;
3303 ae = &ad->AttrValue;
3305 /* SRIOV (type 3) is not supported */
3307 ae->un.AttrInt = cpu_to_be32(2); /* NPIV */
3309 ae->un.AttrInt = cpu_to_be32(1); /* Physical */
3310 size = FOURBYTES + sizeof(uint32_t);
3311 ad->AttrLen = cpu_to_be16(size);
3312 ad->AttrType = cpu_to_be16(RPRT_SMART_PORT_INFO);
3317 lpfc_fdmi_smart_attr_qos(struct lpfc_vport *vport,
3318 struct lpfc_fdmi_attr_def *ad)
3320 struct lpfc_fdmi_attr_entry *ae;
3323 ae = &ad->AttrValue;
3324 ae->un.AttrInt = cpu_to_be32(0);
3325 size = FOURBYTES + sizeof(uint32_t);
3326 ad->AttrLen = cpu_to_be16(size);
3327 ad->AttrType = cpu_to_be16(RPRT_SMART_QOS);
3332 lpfc_fdmi_smart_attr_security(struct lpfc_vport *vport,
3333 struct lpfc_fdmi_attr_def *ad)
3335 struct lpfc_fdmi_attr_entry *ae;
3338 ae = &ad->AttrValue;
3339 ae->un.AttrInt = cpu_to_be32(1);
3340 size = FOURBYTES + sizeof(uint32_t);
3341 ad->AttrLen = cpu_to_be16(size);
3342 ad->AttrType = cpu_to_be16(RPRT_SMART_SECURITY);
3347 lpfc_fdmi_vendor_attr_mi(struct lpfc_vport *vport,
3348 struct lpfc_fdmi_attr_def *ad)
3350 struct lpfc_hba *phba = vport->phba;
3351 struct lpfc_fdmi_attr_entry *ae;
3353 char mibrevision[16];
3355 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
3357 sprintf(mibrevision, "ELXE2EM:%04d",
3358 phba->sli4_hba.pc_sli4_params.mi_ver);
3359 strncpy(ae->un.AttrString, &mibrevision[0], sizeof(ae->un.AttrString));
3360 len = strnlen(ae->un.AttrString, sizeof(ae->un.AttrString));
3361 len += (len & 3) ? (4 - (len & 3)) : 4;
3362 size = FOURBYTES + len;
3363 ad->AttrLen = cpu_to_be16(size);
3364 ad->AttrType = cpu_to_be16(RPRT_VENDOR_MI);
3368 /* RHBA attribute jump table */
3369 int (*lpfc_fdmi_hba_action[])
3370 (struct lpfc_vport *vport, struct lpfc_fdmi_attr_def *ad) = {
3371 /* Action routine Mask bit Attribute type */
3372 lpfc_fdmi_hba_attr_wwnn, /* bit0 RHBA_NODENAME */
3373 lpfc_fdmi_hba_attr_manufacturer, /* bit1 RHBA_MANUFACTURER */
3374 lpfc_fdmi_hba_attr_sn, /* bit2 RHBA_SERIAL_NUMBER */
3375 lpfc_fdmi_hba_attr_model, /* bit3 RHBA_MODEL */
3376 lpfc_fdmi_hba_attr_description, /* bit4 RHBA_MODEL_DESCRIPTION */
3377 lpfc_fdmi_hba_attr_hdw_ver, /* bit5 RHBA_HARDWARE_VERSION */
3378 lpfc_fdmi_hba_attr_drvr_ver, /* bit6 RHBA_DRIVER_VERSION */
3379 lpfc_fdmi_hba_attr_rom_ver, /* bit7 RHBA_OPTION_ROM_VERSION */
3380 lpfc_fdmi_hba_attr_fmw_ver, /* bit8 RHBA_FIRMWARE_VERSION */
3381 lpfc_fdmi_hba_attr_os_ver, /* bit9 RHBA_OS_NAME_VERSION */
3382 lpfc_fdmi_hba_attr_ct_len, /* bit10 RHBA_MAX_CT_PAYLOAD_LEN */
3383 lpfc_fdmi_hba_attr_symbolic_name, /* bit11 RHBA_SYM_NODENAME */
3384 lpfc_fdmi_hba_attr_vendor_info, /* bit12 RHBA_VENDOR_INFO */
3385 lpfc_fdmi_hba_attr_num_ports, /* bit13 RHBA_NUM_PORTS */
3386 lpfc_fdmi_hba_attr_fabric_wwnn, /* bit14 RHBA_FABRIC_WWNN */
3387 lpfc_fdmi_hba_attr_bios_ver, /* bit15 RHBA_BIOS_VERSION */
3388 lpfc_fdmi_hba_attr_bios_state, /* bit16 RHBA_BIOS_STATE */
3389 lpfc_fdmi_hba_attr_vendor_id, /* bit17 RHBA_VENDOR_ID */
3392 /* RPA / RPRT attribute jump table */
3393 int (*lpfc_fdmi_port_action[])
3394 (struct lpfc_vport *vport, struct lpfc_fdmi_attr_def *ad) = {
3395 /* Action routine Mask bit Attribute type */
3396 lpfc_fdmi_port_attr_fc4type, /* bit0 RPRT_SUPPORT_FC4_TYPES */
3397 lpfc_fdmi_port_attr_support_speed, /* bit1 RPRT_SUPPORTED_SPEED */
3398 lpfc_fdmi_port_attr_speed, /* bit2 RPRT_PORT_SPEED */
3399 lpfc_fdmi_port_attr_max_frame, /* bit3 RPRT_MAX_FRAME_SIZE */
3400 lpfc_fdmi_port_attr_os_devname, /* bit4 RPRT_OS_DEVICE_NAME */
3401 lpfc_fdmi_port_attr_host_name, /* bit5 RPRT_HOST_NAME */
3402 lpfc_fdmi_port_attr_wwnn, /* bit6 RPRT_NODENAME */
3403 lpfc_fdmi_port_attr_wwpn, /* bit7 RPRT_PORTNAME */
3404 lpfc_fdmi_port_attr_symbolic_name, /* bit8 RPRT_SYM_PORTNAME */
3405 lpfc_fdmi_port_attr_port_type, /* bit9 RPRT_PORT_TYPE */
3406 lpfc_fdmi_port_attr_class, /* bit10 RPRT_SUPPORTED_CLASS */
3407 lpfc_fdmi_port_attr_fabric_wwpn, /* bit11 RPRT_FABRICNAME */
3408 lpfc_fdmi_port_attr_active_fc4type, /* bit12 RPRT_ACTIVE_FC4_TYPES */
3409 lpfc_fdmi_port_attr_port_state, /* bit13 RPRT_PORT_STATE */
3410 lpfc_fdmi_port_attr_num_disc, /* bit14 RPRT_DISC_PORT */
3411 lpfc_fdmi_port_attr_nportid, /* bit15 RPRT_PORT_ID */
3412 lpfc_fdmi_smart_attr_service, /* bit16 RPRT_SMART_SERVICE */
3413 lpfc_fdmi_smart_attr_guid, /* bit17 RPRT_SMART_GUID */
3414 lpfc_fdmi_smart_attr_version, /* bit18 RPRT_SMART_VERSION */
3415 lpfc_fdmi_smart_attr_model, /* bit19 RPRT_SMART_MODEL */
3416 lpfc_fdmi_smart_attr_port_info, /* bit20 RPRT_SMART_PORT_INFO */
3417 lpfc_fdmi_smart_attr_qos, /* bit21 RPRT_SMART_QOS */
3418 lpfc_fdmi_smart_attr_security, /* bit22 RPRT_SMART_SECURITY */
3419 lpfc_fdmi_vendor_attr_mi, /* bit23 RPRT_VENDOR_MI */
3423 * lpfc_fdmi_cmd - Build and send a FDMI cmd to the specified NPort
3424 * @vport: pointer to a host virtual N_Port data structure.
3425 * @ndlp: ndlp to send FDMI cmd to (if NULL use FDMI_DID)
3426 * @cmdcode: FDMI command to send
3427 * @new_mask: Mask of HBA or PORT Attributes to send
3429 * Builds and sends a FDMI command using the CT subsystem.
3432 lpfc_fdmi_cmd(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
3433 int cmdcode, uint32_t new_mask)
3435 struct lpfc_hba *phba = vport->phba;
3436 struct lpfc_dmabuf *mp, *bmp;
3437 struct lpfc_sli_ct_request *CtReq;
3438 struct ulp_bde64 *bpl;
3443 struct lpfc_fdmi_reg_hba *rh;
3444 struct lpfc_fdmi_port_entry *pe;
3445 struct lpfc_fdmi_reg_portattr *pab = NULL;
3446 struct lpfc_fdmi_attr_block *ab = NULL;
3447 int (*func)(struct lpfc_vport *vport, struct lpfc_fdmi_attr_def *ad);
3448 void (*cmpl)(struct lpfc_hba *, struct lpfc_iocbq *,
3449 struct lpfc_iocbq *);
3454 cmpl = lpfc_cmpl_ct_disc_fdmi; /* called from discovery */
3456 /* fill in BDEs for command */
3457 /* Allocate buffer for command payload */
3458 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
3462 mp->virt = lpfc_mbuf_alloc(phba, 0, &(mp->phys));
3464 goto fdmi_cmd_free_mp;
3466 /* Allocate buffer for Buffer ptr list */
3467 bmp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
3469 goto fdmi_cmd_free_mpvirt;
3471 bmp->virt = lpfc_mbuf_alloc(phba, 0, &(bmp->phys));
3473 goto fdmi_cmd_free_bmp;
3475 INIT_LIST_HEAD(&mp->list);
3476 INIT_LIST_HEAD(&bmp->list);
3479 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
3480 "0218 FDMI Request Data: x%x x%x x%x\n",
3481 vport->fc_flag, vport->port_state, cmdcode);
3482 CtReq = (struct lpfc_sli_ct_request *)mp->virt;
3484 /* First populate the CT_IU preamble */
3485 memset(CtReq, 0, sizeof(struct lpfc_sli_ct_request));
3486 CtReq->RevisionId.bits.Revision = SLI_CT_REVISION;
3487 CtReq->RevisionId.bits.InId = 0;
3489 CtReq->FsType = SLI_CT_MANAGEMENT_SERVICE;
3490 CtReq->FsSubType = SLI_CT_FDMI_Subtypes;
3492 CtReq->CommandResponse.bits.CmdRsp = cpu_to_be16(cmdcode);
3493 rsp_size = LPFC_BPL_SIZE;
3496 /* Next fill in the specific FDMI cmd information */
3500 rh = (struct lpfc_fdmi_reg_hba *)&CtReq->un.PortID;
3501 /* HBA Identifier */
3502 memcpy(&rh->hi.PortName, &phba->pport->fc_sparam.portName,
3503 sizeof(struct lpfc_name));
3505 if (cmdcode == SLI_MGMT_RHBA) {
3506 /* Registered Port List */
3507 /* One entry (port) per adapter */
3508 rh->rpl.EntryCnt = cpu_to_be32(1);
3509 memcpy(&rh->rpl.pe.PortName,
3510 &phba->pport->fc_sparam.portName,
3511 sizeof(struct lpfc_name));
3513 /* point to the HBA attribute block */
3514 size = 2 * sizeof(struct lpfc_name) +
3517 size = sizeof(struct lpfc_name);
3519 ab = (struct lpfc_fdmi_attr_block *)((uint8_t *)rh + size);
3526 mask = vport->fdmi_hba_mask;
3528 /* Mask will dictate what attributes to build in the request */
3531 func = lpfc_fdmi_hba_action[bit_pos];
3533 (struct lpfc_fdmi_attr_def *)
3534 ((uint8_t *)rh + size));
3537 (LPFC_BPL_SIZE - LPFC_CT_PREAMBLE))
3544 ab->EntryCnt = cpu_to_be32(ab->EntryCnt);
3546 size = GID_REQUEST_SZ - 4 + size;
3551 pab = (struct lpfc_fdmi_reg_portattr *)&CtReq->un.PortID;
3552 if (cmdcode == SLI_MGMT_RPRT) {
3553 rh = (struct lpfc_fdmi_reg_hba *)pab;
3554 /* HBA Identifier */
3555 memcpy(&rh->hi.PortName,
3556 &phba->pport->fc_sparam.portName,
3557 sizeof(struct lpfc_name));
3558 pab = (struct lpfc_fdmi_reg_portattr *)
3559 ((uint8_t *)pab + sizeof(struct lpfc_name));
3562 memcpy((uint8_t *)&pab->PortName,
3563 (uint8_t *)&vport->fc_sparam.portName,
3564 sizeof(struct lpfc_name));
3565 size += sizeof(struct lpfc_name) + FOURBYTES;
3566 pab->ab.EntryCnt = 0;
3571 mask = vport->fdmi_port_mask;
3573 /* Mask will dictate what attributes to build in the request */
3576 func = lpfc_fdmi_port_action[bit_pos];
3578 (struct lpfc_fdmi_attr_def *)
3579 ((uint8_t *)pab + size));
3582 (LPFC_BPL_SIZE - LPFC_CT_PREAMBLE))
3589 pab->ab.EntryCnt = cpu_to_be32(pab->ab.EntryCnt);
3591 if (cmdcode == SLI_MGMT_RPRT)
3592 size += sizeof(struct lpfc_name);
3593 size = GID_REQUEST_SZ - 4 + size;
3598 rsp_size = FC_MAX_NS_RSP;
3602 pe = (struct lpfc_fdmi_port_entry *)&CtReq->un.PortID;
3603 memcpy((uint8_t *)&pe->PortName,
3604 (uint8_t *)&vport->fc_sparam.portName,
3605 sizeof(struct lpfc_name));
3606 size = GID_REQUEST_SZ - 4 + sizeof(struct lpfc_name);
3611 rsp_size = FC_MAX_NS_RSP;
3615 pe = (struct lpfc_fdmi_port_entry *)&CtReq->un.PortID;
3616 memcpy((uint8_t *)&pe->PortName,
3617 (uint8_t *)&vport->fc_sparam.portName,
3618 sizeof(struct lpfc_name));
3619 size = GID_REQUEST_SZ - 4 + sizeof(struct lpfc_name);
3622 size = GID_REQUEST_SZ - 4;
3625 lpfc_printf_vlog(vport, KERN_WARNING, LOG_DISCOVERY,
3626 "0298 FDMI cmdcode x%x not supported\n",
3628 goto fdmi_cmd_free_bmpvirt;
3630 CtReq->CommandResponse.bits.Size = cpu_to_be16(rsp_size);
3632 bpl = (struct ulp_bde64 *)bmp->virt;
3633 bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys));
3634 bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys));
3635 bpl->tus.f.bdeFlags = 0;
3636 bpl->tus.f.bdeSize = size;
3639 * The lpfc_ct_cmd/lpfc_get_req shall increment ndlp reference count
3640 * to hold ndlp reference for the corresponding callback function.
3642 if (!lpfc_ct_cmd(vport, mp, bmp, ndlp, cmpl, rsp_size, 0))
3645 fdmi_cmd_free_bmpvirt:
3646 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
3649 fdmi_cmd_free_mpvirt:
3650 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3654 /* Issue FDMI request failed */
3655 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
3656 "0244 Issue FDMI request failed Data: x%x\n",
3662 * lpfc_delayed_disc_tmo - Timeout handler for delayed discovery timer.
3663 * @t: Context object of the timer.
3665 * This function set the WORKER_DELAYED_DISC_TMO flag and wake up
3666 * the worker thread.
3669 lpfc_delayed_disc_tmo(struct timer_list *t)
3671 struct lpfc_vport *vport = from_timer(vport, t, delayed_disc_tmo);
3672 struct lpfc_hba *phba = vport->phba;
3673 uint32_t tmo_posted;
3674 unsigned long iflag;
3676 spin_lock_irqsave(&vport->work_port_lock, iflag);
3677 tmo_posted = vport->work_port_events & WORKER_DELAYED_DISC_TMO;
3679 vport->work_port_events |= WORKER_DELAYED_DISC_TMO;
3680 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
3683 lpfc_worker_wake_up(phba);
3688 * lpfc_delayed_disc_timeout_handler - Function called by worker thread to
3689 * handle delayed discovery.
3690 * @vport: pointer to a host virtual N_Port data structure.
3692 * This function start nport discovery of the vport.
3695 lpfc_delayed_disc_timeout_handler(struct lpfc_vport *vport)
3697 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3699 spin_lock_irq(shost->host_lock);
3700 if (!(vport->fc_flag & FC_DISC_DELAYED)) {
3701 spin_unlock_irq(shost->host_lock);
3704 vport->fc_flag &= ~FC_DISC_DELAYED;
3705 spin_unlock_irq(shost->host_lock);
3707 lpfc_do_scr_ns_plogi(vport->phba, vport);
3711 lpfc_decode_firmware_rev(struct lpfc_hba *phba, char *fwrevision, int flag)
3713 struct lpfc_sli *psli = &phba->sli;
3714 lpfc_vpd_t *vp = &phba->vpd;
3715 uint32_t b1, b2, b3, b4, i, rev;
3717 uint32_t *ptr, str[4];
3720 if (phba->sli_rev == LPFC_SLI_REV4)
3721 snprintf(fwrevision, FW_REV_STR_SIZE, "%s", vp->rev.opFwName);
3722 else if (vp->rev.rBit) {
3723 if (psli->sli_flag & LPFC_SLI_ACTIVE)
3724 rev = vp->rev.sli2FwRev;
3726 rev = vp->rev.sli1FwRev;
3728 b1 = (rev & 0x0000f000) >> 12;
3729 b2 = (rev & 0x00000f00) >> 8;
3730 b3 = (rev & 0x000000c0) >> 6;
3731 b4 = (rev & 0x00000030) >> 4;
3750 b4 = (rev & 0x0000000f);
3752 if (psli->sli_flag & LPFC_SLI_ACTIVE)
3753 fwname = vp->rev.sli2FwName;
3755 fwname = vp->rev.sli1FwName;
3757 for (i = 0; i < 16; i++)
3758 if (fwname[i] == 0x20)
3761 ptr = (uint32_t*)fwname;
3763 for (i = 0; i < 3; i++)
3764 str[i] = be32_to_cpu(*ptr++);
3768 sprintf(fwrevision, "%d.%d%d (%s)",
3769 b1, b2, b3, (char *)str);
3771 sprintf(fwrevision, "%d.%d%d", b1,
3775 sprintf(fwrevision, "%d.%d%d%c%d (%s)",
3779 sprintf(fwrevision, "%d.%d%d%c%d",
3783 rev = vp->rev.smFwRev;
3785 b1 = (rev & 0xff000000) >> 24;
3786 b2 = (rev & 0x00f00000) >> 20;
3787 b3 = (rev & 0x000f0000) >> 16;
3788 c = (rev & 0x0000ff00) >> 8;
3789 b4 = (rev & 0x000000ff);
3791 sprintf(fwrevision, "%d.%d%d%c%d", b1, b2, b3, c, b4);
3797 lpfc_cmpl_ct_cmd_vmid(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3798 struct lpfc_iocbq *rspiocb)
3800 struct lpfc_vport *vport = cmdiocb->vport;
3801 struct lpfc_dmabuf *inp = cmdiocb->context1;
3802 struct lpfc_dmabuf *outp = cmdiocb->context2;
3803 struct lpfc_sli_ct_request *ctcmd = inp->virt;
3804 struct lpfc_sli_ct_request *ctrsp = outp->virt;
3805 u16 rsp = ctrsp->CommandResponse.bits.CmdRsp;
3806 struct app_id_object *app;
3807 u32 cmd, hash, bucket;
3808 struct lpfc_vmid *vmp, *cur;
3809 u8 *data = outp->virt;
3812 cmd = be16_to_cpu(ctcmd->CommandResponse.bits.CmdRsp);
3813 if (cmd == SLI_CTAS_DALLAPP_ID)
3814 lpfc_ct_free_iocb(phba, cmdiocb);
3816 if (lpfc_els_chk_latt(vport) || rspiocb->iocb.ulpStatus) {
3817 if (cmd != SLI_CTAS_DALLAPP_ID)
3820 /* Check for a CT LS_RJT response */
3821 if (rsp == be16_to_cpu(SLI_CT_RESPONSE_FS_RJT)) {
3822 if (cmd != SLI_CTAS_DALLAPP_ID)
3823 lpfc_printf_vlog(vport, KERN_DEBUG, LOG_DISCOVERY,
3824 "3306 VMID FS_RJT Data: x%x x%x x%x\n",
3825 cmd, ctrsp->ReasonCode,
3826 ctrsp->Explanation);
3827 if ((cmd != SLI_CTAS_DALLAPP_ID) ||
3828 (ctrsp->ReasonCode != SLI_CT_UNABLE_TO_PERFORM_REQ) ||
3829 (ctrsp->Explanation != SLI_CT_APP_ID_NOT_AVAILABLE)) {
3830 /* If DALLAPP_ID failed retry later */
3831 if (cmd == SLI_CTAS_DALLAPP_ID)
3832 vport->load_flag |= FC_DEREGISTER_ALL_APP_ID;
3838 case SLI_CTAS_RAPP_IDENT:
3839 app = (struct app_id_object *)(RAPP_IDENT_OFFSET + data);
3840 lpfc_printf_vlog(vport, KERN_DEBUG, LOG_DISCOVERY,
3841 "6712 RAPP_IDENT app id %d port id x%x id "
3842 "len %d\n", be32_to_cpu(app->app_id),
3843 be32_to_cpu(app->port_id),
3844 app->obj.entity_id_len);
3846 if (app->obj.entity_id_len == 0 || app->port_id == 0)
3849 hash = lpfc_vmid_hash_fn(app->obj.entity_id,
3850 app->obj.entity_id_len);
3851 vmp = lpfc_get_vmid_from_hashtable(vport, hash,
3852 app->obj.entity_id);
3854 write_lock(&vport->vmid_lock);
3855 vmp->un.app_id = be32_to_cpu(app->app_id);
3856 vmp->flag |= LPFC_VMID_REGISTERED;
3857 vmp->flag &= ~LPFC_VMID_REQ_REGISTER;
3858 write_unlock(&vport->vmid_lock);
3859 /* Set IN USE flag */
3860 vport->vmid_flag |= LPFC_VMID_IN_USE;
3862 lpfc_printf_vlog(vport, KERN_DEBUG, LOG_DISCOVERY,
3863 "6901 No entry found %s hash %d\n",
3864 app->obj.entity_id, hash);
3867 case SLI_CTAS_DAPP_IDENT:
3868 app = (struct app_id_object *)(DAPP_IDENT_OFFSET + data);
3869 lpfc_printf_vlog(vport, KERN_DEBUG, LOG_DISCOVERY,
3870 "6713 DAPP_IDENT app id %d port id x%x\n",
3871 be32_to_cpu(app->app_id),
3872 be32_to_cpu(app->port_id));
3874 case SLI_CTAS_DALLAPP_ID:
3875 lpfc_printf_vlog(vport, KERN_DEBUG, LOG_DISCOVERY,
3876 "8856 Deregistered all app ids\n");
3877 read_lock(&vport->vmid_lock);
3878 for (i = 0; i < phba->cfg_max_vmid; i++) {
3879 vmp = &vport->vmid[i];
3880 if (vmp->flag != LPFC_VMID_SLOT_FREE)
3881 memset(vmp, 0, sizeof(struct lpfc_vmid));
3883 read_unlock(&vport->vmid_lock);
3884 /* for all elements in the hash table */
3885 if (!hash_empty(vport->hash_table))
3886 hash_for_each(vport->hash_table, bucket, cur, hnode)
3887 hash_del(&cur->hnode);
3888 vport->load_flag |= FC_ALLOW_VMID;
3891 lpfc_printf_vlog(vport, KERN_DEBUG, LOG_DISCOVERY,
3892 "8857 Invalid command code\n");
3897 * lpfc_vmid_cmd - Build and send a FDMI cmd to the specified NPort
3898 * @vport: pointer to a host virtual N_Port data structure.
3899 * @cmdcode: application server command code to send
3900 * @vmid: pointer to vmid info structure
3902 * Builds and sends a FDMI command using the CT subsystem.
3905 lpfc_vmid_cmd(struct lpfc_vport *vport,
3906 int cmdcode, struct lpfc_vmid *vmid)
3908 struct lpfc_hba *phba = vport->phba;
3909 struct lpfc_dmabuf *mp, *bmp;
3910 struct lpfc_sli_ct_request *ctreq;
3911 struct ulp_bde64 *bpl;
3915 struct lpfc_vmid_rapp_ident_list *rap;
3916 struct lpfc_vmid_dapp_ident_list *dap;
3918 struct lpfc_nodelist *ndlp;
3920 void (*cmpl)(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3921 struct lpfc_iocbq *rspiocb);
3923 ndlp = lpfc_findnode_did(vport, FDMI_DID);
3924 if (!ndlp || ndlp->nlp_state != NLP_STE_UNMAPPED_NODE)
3927 cmpl = lpfc_cmpl_ct_cmd_vmid;
3929 /* fill in BDEs for command */
3930 /* Allocate buffer for command payload */
3931 mp = kmalloc(sizeof(*mp), GFP_KERNEL);
3933 goto vmid_free_mp_exit;
3935 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
3937 goto vmid_free_mp_virt_exit;
3939 /* Allocate buffer for Buffer ptr list */
3940 bmp = kmalloc(sizeof(*bmp), GFP_KERNEL);
3942 goto vmid_free_bmp_exit;
3944 bmp->virt = lpfc_mbuf_alloc(phba, 0, &bmp->phys);
3946 goto vmid_free_bmp_virt_exit;
3948 INIT_LIST_HEAD(&mp->list);
3949 INIT_LIST_HEAD(&bmp->list);
3951 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
3952 "3275 VMID Request Data: x%x x%x x%x\n",
3953 vport->fc_flag, vport->port_state, cmdcode);
3954 ctreq = (struct lpfc_sli_ct_request *)mp->virt;
3956 /* First populate the CT_IU preamble */
3957 memset(data, 0, LPFC_BPL_SIZE);
3958 ctreq->RevisionId.bits.Revision = SLI_CT_REVISION;
3959 ctreq->RevisionId.bits.InId = 0;
3961 ctreq->FsType = SLI_CT_MANAGEMENT_SERVICE;
3962 ctreq->FsSubType = SLI_CT_APP_SEV_Subtypes;
3964 ctreq->CommandResponse.bits.CmdRsp = cpu_to_be16(cmdcode);
3965 rsp_size = LPFC_BPL_SIZE;
3969 case SLI_CTAS_RAPP_IDENT:
3970 lpfc_printf_vlog(vport, KERN_DEBUG, LOG_DISCOVERY,
3971 "1329 RAPP_IDENT for %s\n", vmid->host_vmid);
3972 ctreq->un.PortID = cpu_to_be32(vport->fc_myDID);
3973 rap = (struct lpfc_vmid_rapp_ident_list *)
3974 (DAPP_IDENT_OFFSET + data);
3975 rap->no_of_objects = cpu_to_be32(1);
3976 rap->obj[0].entity_id_len = vmid->vmid_len;
3977 memcpy(rap->obj[0].entity_id, vmid->host_vmid, vmid->vmid_len);
3978 size = RAPP_IDENT_OFFSET +
3979 sizeof(struct lpfc_vmid_rapp_ident_list);
3983 case SLI_CTAS_GALLAPPIA_ID:
3984 ctreq->un.PortID = cpu_to_be32(vport->fc_myDID);
3985 size = GALLAPPIA_ID_SIZE;
3988 case SLI_CTAS_DAPP_IDENT:
3989 lpfc_printf_vlog(vport, KERN_DEBUG, LOG_DISCOVERY,
3990 "1469 DAPP_IDENT for %s\n", vmid->host_vmid);
3991 ctreq->un.PortID = cpu_to_be32(vport->fc_myDID);
3992 dap = (struct lpfc_vmid_dapp_ident_list *)
3993 (DAPP_IDENT_OFFSET + data);
3994 dap->no_of_objects = cpu_to_be32(1);
3995 dap->obj[0].entity_id_len = vmid->vmid_len;
3996 memcpy(dap->obj[0].entity_id, vmid->host_vmid, vmid->vmid_len);
3997 size = DAPP_IDENT_OFFSET +
3998 sizeof(struct lpfc_vmid_dapp_ident_list);
3999 write_lock(&vport->vmid_lock);
4000 vmid->flag &= ~LPFC_VMID_REGISTERED;
4001 write_unlock(&vport->vmid_lock);
4005 case SLI_CTAS_DALLAPP_ID:
4006 ctreq->un.PortID = cpu_to_be32(vport->fc_myDID);
4007 size = DALLAPP_ID_SIZE;
4011 lpfc_printf_vlog(vport, KERN_DEBUG, LOG_DISCOVERY,
4012 "7062 VMID cmdcode x%x not supported\n",
4014 goto vmid_free_all_mem;
4017 ctreq->CommandResponse.bits.Size = cpu_to_be16(rsp_size);
4019 bpl = (struct ulp_bde64 *)bmp->virt;
4020 bpl->addrHigh = putPaddrHigh(mp->phys);
4021 bpl->addrLow = putPaddrLow(mp->phys);
4022 bpl->tus.f.bdeFlags = 0;
4023 bpl->tus.f.bdeSize = size;
4025 /* The lpfc_ct_cmd/lpfc_get_req shall increment ndlp reference count
4026 * to hold ndlp reference for the corresponding callback function.
4028 if (!lpfc_ct_cmd(vport, mp, bmp, ndlp, cmpl, rsp_size, retry))
4032 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
4033 vmid_free_bmp_virt_exit:
4036 lpfc_mbuf_free(phba, mp->virt, mp->phys);
4037 vmid_free_mp_virt_exit:
4041 /* Issue CT request failed */
4042 lpfc_printf_vlog(vport, KERN_DEBUG, LOG_DISCOVERY,
4043 "3276 VMID CT request failed Data: x%x\n", cmdcode);