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 lpfc_printf_log(phba, KERN_ERR,
2292 LOG_DISCOVERY | LOG_ELS,
2293 "6460 VEN FDMI RPA failure\n");
2296 if (vport->fdmi_port_mask == LPFC_FDMI2_PORT_ATTR) {
2297 /* Fallback to FDMI-1 */
2298 vport->fdmi_hba_mask = LPFC_FDMI1_HBA_ATTR;
2299 vport->fdmi_port_mask = LPFC_FDMI1_PORT_ATTR;
2301 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA, 0);
2304 if (vport->fdmi_port_mask == LPFC_FDMI2_SMART_ATTR) {
2305 vport->fdmi_port_mask = LPFC_FDMI2_PORT_ATTR;
2306 /* Retry the same command */
2307 lpfc_fdmi_cmd(vport, ndlp, cmd, 0);
2314 * On success, need to cycle thru FDMI registration for discovery
2315 * DHBA -> DPRT -> RHBA -> RPA (physical port)
2316 * DPRT -> RPRT (vports)
2320 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RPA, 0);
2324 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DPRT, 0);
2328 if (vport->port_type == LPFC_PHYSICAL_PORT)
2329 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RHBA, 0);
2331 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RPRT, 0);
2334 if (vport->port_type == LPFC_PHYSICAL_PORT &&
2335 phba->cfg_enable_mi &&
2336 phba->sli4_hba.pc_sli4_params.mi_ver > LPFC_MIB1_SUPPORT) {
2337 /* mi is only for the phyical port, no vports */
2338 if (phba->link_flag & LS_CT_VEN_RPA) {
2339 lpfc_printf_vlog(vport, KERN_INFO,
2340 LOG_DISCOVERY | LOG_ELS,
2341 "6449 VEN RPA FDMI Success\n");
2342 phba->link_flag &= ~LS_CT_VEN_RPA;
2346 if (lpfc_fdmi_cmd(vport, ndlp, cmd,
2347 LPFC_FDMI_VENDOR_ATTR_mi) == 0)
2348 phba->link_flag |= LS_CT_VEN_RPA;
2349 lpfc_printf_log(phba, KERN_INFO,
2350 LOG_DISCOVERY | LOG_ELS,
2351 "6458 Send MI FDMI:%x Flag x%x\n",
2352 phba->sli4_hba.pc_sli4_params.mi_value,
2355 lpfc_printf_log(phba, KERN_INFO,
2356 LOG_DISCOVERY | LOG_ELS,
2357 "6459 No FDMI VEN MI support - "
2367 * lpfc_fdmi_change_check - Check for changed FDMI parameters
2368 * @vport: pointer to a host virtual N_Port data structure.
2370 * Check how many mapped NPorts we are connected to
2371 * Check if our hostname changed
2372 * Called from hbeat timeout routine to check if any FDMI parameters
2373 * changed. If so, re-register those Attributes.
2376 lpfc_fdmi_change_check(struct lpfc_vport *vport)
2378 struct lpfc_hba *phba = vport->phba;
2379 struct lpfc_nodelist *ndlp;
2382 if (!lpfc_is_link_up(phba))
2385 /* Must be connected to a Fabric */
2386 if (!(vport->fc_flag & FC_FABRIC))
2389 ndlp = lpfc_findnode_did(vport, FDMI_DID);
2393 /* Check if system hostname changed */
2394 if (strcmp(phba->os_host_name, init_utsname()->nodename)) {
2395 memset(phba->os_host_name, 0, sizeof(phba->os_host_name));
2396 scnprintf(phba->os_host_name, sizeof(phba->os_host_name), "%s",
2397 init_utsname()->nodename);
2398 lpfc_ns_cmd(vport, SLI_CTNS_RSNN_NN, 0, 0);
2400 /* Since this effects multiple HBA and PORT attributes, we need
2401 * de-register and go thru the whole FDMI registration cycle.
2402 * DHBA -> DPRT -> RHBA -> RPA (physical port)
2403 * DPRT -> RPRT (vports)
2405 if (vport->port_type == LPFC_PHYSICAL_PORT) {
2406 /* For extra Vendor RPA */
2407 phba->link_flag &= ~LS_CT_VEN_RPA;
2408 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA, 0);
2410 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DPRT, 0);
2413 /* Since this code path registers all the port attributes
2414 * we can just return without further checking.
2419 if (!(vport->fdmi_port_mask & LPFC_FDMI_PORT_ATTR_num_disc))
2422 /* Check if the number of mapped NPorts changed */
2423 cnt = lpfc_find_map_node(vport);
2424 if (cnt == vport->fdmi_num_disc)
2427 if (vport->port_type == LPFC_PHYSICAL_PORT) {
2428 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RPA,
2429 LPFC_FDMI_PORT_ATTR_num_disc);
2431 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RPRT,
2432 LPFC_FDMI_PORT_ATTR_num_disc);
2436 /* Routines for all individual HBA attributes */
2438 lpfc_fdmi_hba_attr_wwnn(struct lpfc_vport *vport, struct lpfc_fdmi_attr_def *ad)
2440 struct lpfc_fdmi_attr_entry *ae;
2443 ae = &ad->AttrValue;
2444 memset(ae, 0, sizeof(*ae));
2446 memcpy(&ae->un.AttrWWN, &vport->fc_sparam.nodeName,
2447 sizeof(struct lpfc_name));
2448 size = FOURBYTES + sizeof(struct lpfc_name);
2449 ad->AttrLen = cpu_to_be16(size);
2450 ad->AttrType = cpu_to_be16(RHBA_NODENAME);
2454 lpfc_fdmi_hba_attr_manufacturer(struct lpfc_vport *vport,
2455 struct lpfc_fdmi_attr_def *ad)
2457 struct lpfc_fdmi_attr_entry *ae;
2460 ae = &ad->AttrValue;
2461 memset(ae, 0, sizeof(*ae));
2463 /* This string MUST be consistent with other FC platforms
2464 * supported by Broadcom.
2466 strncpy(ae->un.AttrString,
2467 "Emulex Corporation",
2468 sizeof(ae->un.AttrString));
2469 len = strnlen(ae->un.AttrString,
2470 sizeof(ae->un.AttrString));
2471 len += (len & 3) ? (4 - (len & 3)) : 4;
2472 size = FOURBYTES + len;
2473 ad->AttrLen = cpu_to_be16(size);
2474 ad->AttrType = cpu_to_be16(RHBA_MANUFACTURER);
2479 lpfc_fdmi_hba_attr_sn(struct lpfc_vport *vport, struct lpfc_fdmi_attr_def *ad)
2481 struct lpfc_hba *phba = vport->phba;
2482 struct lpfc_fdmi_attr_entry *ae;
2485 ae = &ad->AttrValue;
2486 memset(ae, 0, sizeof(*ae));
2488 strncpy(ae->un.AttrString, phba->SerialNumber,
2489 sizeof(ae->un.AttrString));
2490 len = strnlen(ae->un.AttrString,
2491 sizeof(ae->un.AttrString));
2492 len += (len & 3) ? (4 - (len & 3)) : 4;
2493 size = FOURBYTES + len;
2494 ad->AttrLen = cpu_to_be16(size);
2495 ad->AttrType = cpu_to_be16(RHBA_SERIAL_NUMBER);
2500 lpfc_fdmi_hba_attr_model(struct lpfc_vport *vport,
2501 struct lpfc_fdmi_attr_def *ad)
2503 struct lpfc_hba *phba = vport->phba;
2504 struct lpfc_fdmi_attr_entry *ae;
2507 ae = &ad->AttrValue;
2508 memset(ae, 0, sizeof(*ae));
2510 strncpy(ae->un.AttrString, phba->ModelName,
2511 sizeof(ae->un.AttrString));
2512 len = strnlen(ae->un.AttrString, sizeof(ae->un.AttrString));
2513 len += (len & 3) ? (4 - (len & 3)) : 4;
2514 size = FOURBYTES + len;
2515 ad->AttrLen = cpu_to_be16(size);
2516 ad->AttrType = cpu_to_be16(RHBA_MODEL);
2521 lpfc_fdmi_hba_attr_description(struct lpfc_vport *vport,
2522 struct lpfc_fdmi_attr_def *ad)
2524 struct lpfc_hba *phba = vport->phba;
2525 struct lpfc_fdmi_attr_entry *ae;
2528 ae = &ad->AttrValue;
2529 memset(ae, 0, sizeof(*ae));
2531 strncpy(ae->un.AttrString, phba->ModelDesc,
2532 sizeof(ae->un.AttrString));
2533 len = strnlen(ae->un.AttrString,
2534 sizeof(ae->un.AttrString));
2535 len += (len & 3) ? (4 - (len & 3)) : 4;
2536 size = FOURBYTES + len;
2537 ad->AttrLen = cpu_to_be16(size);
2538 ad->AttrType = cpu_to_be16(RHBA_MODEL_DESCRIPTION);
2543 lpfc_fdmi_hba_attr_hdw_ver(struct lpfc_vport *vport,
2544 struct lpfc_fdmi_attr_def *ad)
2546 struct lpfc_hba *phba = vport->phba;
2547 lpfc_vpd_t *vp = &phba->vpd;
2548 struct lpfc_fdmi_attr_entry *ae;
2549 uint32_t i, j, incr, size;
2551 ae = &ad->AttrValue;
2552 memset(ae, 0, sizeof(*ae));
2554 /* Convert JEDEC ID to ascii for hardware version */
2555 incr = vp->rev.biuRev;
2556 for (i = 0; i < 8; i++) {
2559 ae->un.AttrString[7 - i] =
2560 (char)((uint8_t) 0x30 +
2563 ae->un.AttrString[7 - i] =
2564 (char)((uint8_t) 0x61 +
2565 (uint8_t) (j - 10));
2568 size = FOURBYTES + 8;
2569 ad->AttrLen = cpu_to_be16(size);
2570 ad->AttrType = cpu_to_be16(RHBA_HARDWARE_VERSION);
2575 lpfc_fdmi_hba_attr_drvr_ver(struct lpfc_vport *vport,
2576 struct lpfc_fdmi_attr_def *ad)
2578 struct lpfc_fdmi_attr_entry *ae;
2581 ae = &ad->AttrValue;
2582 memset(ae, 0, sizeof(*ae));
2584 strncpy(ae->un.AttrString, lpfc_release_version,
2585 sizeof(ae->un.AttrString));
2586 len = strnlen(ae->un.AttrString,
2587 sizeof(ae->un.AttrString));
2588 len += (len & 3) ? (4 - (len & 3)) : 4;
2589 size = FOURBYTES + len;
2590 ad->AttrLen = cpu_to_be16(size);
2591 ad->AttrType = cpu_to_be16(RHBA_DRIVER_VERSION);
2596 lpfc_fdmi_hba_attr_rom_ver(struct lpfc_vport *vport,
2597 struct lpfc_fdmi_attr_def *ad)
2599 struct lpfc_hba *phba = vport->phba;
2600 struct lpfc_fdmi_attr_entry *ae;
2603 ae = &ad->AttrValue;
2604 memset(ae, 0, sizeof(*ae));
2606 if (phba->sli_rev == LPFC_SLI_REV4)
2607 lpfc_decode_firmware_rev(phba, ae->un.AttrString, 1);
2609 strncpy(ae->un.AttrString, phba->OptionROMVersion,
2610 sizeof(ae->un.AttrString));
2611 len = strnlen(ae->un.AttrString,
2612 sizeof(ae->un.AttrString));
2613 len += (len & 3) ? (4 - (len & 3)) : 4;
2614 size = FOURBYTES + len;
2615 ad->AttrLen = cpu_to_be16(size);
2616 ad->AttrType = cpu_to_be16(RHBA_OPTION_ROM_VERSION);
2621 lpfc_fdmi_hba_attr_fmw_ver(struct lpfc_vport *vport,
2622 struct lpfc_fdmi_attr_def *ad)
2624 struct lpfc_hba *phba = vport->phba;
2625 struct lpfc_fdmi_attr_entry *ae;
2628 ae = &ad->AttrValue;
2629 memset(ae, 0, sizeof(*ae));
2631 lpfc_decode_firmware_rev(phba, ae->un.AttrString, 1);
2632 len = strnlen(ae->un.AttrString,
2633 sizeof(ae->un.AttrString));
2634 len += (len & 3) ? (4 - (len & 3)) : 4;
2635 size = FOURBYTES + len;
2636 ad->AttrLen = cpu_to_be16(size);
2637 ad->AttrType = cpu_to_be16(RHBA_FIRMWARE_VERSION);
2642 lpfc_fdmi_hba_attr_os_ver(struct lpfc_vport *vport,
2643 struct lpfc_fdmi_attr_def *ad)
2645 struct lpfc_fdmi_attr_entry *ae;
2648 ae = &ad->AttrValue;
2649 memset(ae, 0, sizeof(*ae));
2651 snprintf(ae->un.AttrString, sizeof(ae->un.AttrString), "%s %s %s",
2652 init_utsname()->sysname,
2653 init_utsname()->release,
2654 init_utsname()->version);
2656 len = strnlen(ae->un.AttrString, sizeof(ae->un.AttrString));
2657 len += (len & 3) ? (4 - (len & 3)) : 4;
2658 size = FOURBYTES + len;
2659 ad->AttrLen = cpu_to_be16(size);
2660 ad->AttrType = cpu_to_be16(RHBA_OS_NAME_VERSION);
2665 lpfc_fdmi_hba_attr_ct_len(struct lpfc_vport *vport,
2666 struct lpfc_fdmi_attr_def *ad)
2668 struct lpfc_fdmi_attr_entry *ae;
2671 ae = &ad->AttrValue;
2673 ae->un.AttrInt = cpu_to_be32(LPFC_MAX_CT_SIZE);
2674 size = FOURBYTES + sizeof(uint32_t);
2675 ad->AttrLen = cpu_to_be16(size);
2676 ad->AttrType = cpu_to_be16(RHBA_MAX_CT_PAYLOAD_LEN);
2681 lpfc_fdmi_hba_attr_symbolic_name(struct lpfc_vport *vport,
2682 struct lpfc_fdmi_attr_def *ad)
2684 struct lpfc_fdmi_attr_entry *ae;
2687 ae = &ad->AttrValue;
2688 memset(ae, 0, sizeof(*ae));
2690 len = lpfc_vport_symbolic_node_name(vport,
2691 ae->un.AttrString, 256);
2692 len += (len & 3) ? (4 - (len & 3)) : 4;
2693 size = FOURBYTES + len;
2694 ad->AttrLen = cpu_to_be16(size);
2695 ad->AttrType = cpu_to_be16(RHBA_SYM_NODENAME);
2700 lpfc_fdmi_hba_attr_vendor_info(struct lpfc_vport *vport,
2701 struct lpfc_fdmi_attr_def *ad)
2703 struct lpfc_fdmi_attr_entry *ae;
2706 ae = &ad->AttrValue;
2708 /* Nothing is defined for this currently */
2709 ae->un.AttrInt = cpu_to_be32(0);
2710 size = FOURBYTES + sizeof(uint32_t);
2711 ad->AttrLen = cpu_to_be16(size);
2712 ad->AttrType = cpu_to_be16(RHBA_VENDOR_INFO);
2717 lpfc_fdmi_hba_attr_num_ports(struct lpfc_vport *vport,
2718 struct lpfc_fdmi_attr_def *ad)
2720 struct lpfc_fdmi_attr_entry *ae;
2723 ae = &ad->AttrValue;
2725 /* Each driver instance corresponds to a single port */
2726 ae->un.AttrInt = cpu_to_be32(1);
2727 size = FOURBYTES + sizeof(uint32_t);
2728 ad->AttrLen = cpu_to_be16(size);
2729 ad->AttrType = cpu_to_be16(RHBA_NUM_PORTS);
2734 lpfc_fdmi_hba_attr_fabric_wwnn(struct lpfc_vport *vport,
2735 struct lpfc_fdmi_attr_def *ad)
2737 struct lpfc_fdmi_attr_entry *ae;
2740 ae = &ad->AttrValue;
2741 memset(ae, 0, sizeof(*ae));
2743 memcpy(&ae->un.AttrWWN, &vport->fabric_nodename,
2744 sizeof(struct lpfc_name));
2745 size = FOURBYTES + sizeof(struct lpfc_name);
2746 ad->AttrLen = cpu_to_be16(size);
2747 ad->AttrType = cpu_to_be16(RHBA_FABRIC_WWNN);
2752 lpfc_fdmi_hba_attr_bios_ver(struct lpfc_vport *vport,
2753 struct lpfc_fdmi_attr_def *ad)
2755 struct lpfc_hba *phba = vport->phba;
2756 struct lpfc_fdmi_attr_entry *ae;
2759 ae = &ad->AttrValue;
2760 memset(ae, 0, sizeof(*ae));
2762 strlcat(ae->un.AttrString, phba->BIOSVersion,
2763 sizeof(ae->un.AttrString));
2764 len = strnlen(ae->un.AttrString,
2765 sizeof(ae->un.AttrString));
2766 len += (len & 3) ? (4 - (len & 3)) : 4;
2767 size = FOURBYTES + len;
2768 ad->AttrLen = cpu_to_be16(size);
2769 ad->AttrType = cpu_to_be16(RHBA_BIOS_VERSION);
2774 lpfc_fdmi_hba_attr_bios_state(struct lpfc_vport *vport,
2775 struct lpfc_fdmi_attr_def *ad)
2777 struct lpfc_fdmi_attr_entry *ae;
2780 ae = &ad->AttrValue;
2782 /* Driver doesn't have access to this information */
2783 ae->un.AttrInt = cpu_to_be32(0);
2784 size = FOURBYTES + sizeof(uint32_t);
2785 ad->AttrLen = cpu_to_be16(size);
2786 ad->AttrType = cpu_to_be16(RHBA_BIOS_STATE);
2791 lpfc_fdmi_hba_attr_vendor_id(struct lpfc_vport *vport,
2792 struct lpfc_fdmi_attr_def *ad)
2794 struct lpfc_fdmi_attr_entry *ae;
2797 ae = &ad->AttrValue;
2798 memset(ae, 0, sizeof(*ae));
2800 strncpy(ae->un.AttrString, "EMULEX",
2801 sizeof(ae->un.AttrString));
2802 len = strnlen(ae->un.AttrString,
2803 sizeof(ae->un.AttrString));
2804 len += (len & 3) ? (4 - (len & 3)) : 4;
2805 size = FOURBYTES + len;
2806 ad->AttrLen = cpu_to_be16(size);
2807 ad->AttrType = cpu_to_be16(RHBA_VENDOR_ID);
2811 /* Routines for all individual PORT attributes */
2813 lpfc_fdmi_port_attr_fc4type(struct lpfc_vport *vport,
2814 struct lpfc_fdmi_attr_def *ad)
2816 struct lpfc_hba *phba = vport->phba;
2817 struct lpfc_fdmi_attr_entry *ae;
2820 ae = &ad->AttrValue;
2821 memset(ae, 0, sizeof(*ae));
2823 ae->un.AttrTypes[2] = 0x01; /* Type 0x8 - FCP */
2824 ae->un.AttrTypes[7] = 0x01; /* Type 0x20 - CT */
2826 /* Check to see if Firmware supports NVME and on physical port */
2827 if ((phba->sli_rev == LPFC_SLI_REV4) && (vport == phba->pport) &&
2828 phba->sli4_hba.pc_sli4_params.nvme)
2829 ae->un.AttrTypes[6] = 0x01; /* Type 0x28 - NVME */
2831 size = FOURBYTES + 32;
2832 ad->AttrLen = cpu_to_be16(size);
2833 ad->AttrType = cpu_to_be16(RPRT_SUPPORTED_FC4_TYPES);
2838 lpfc_fdmi_port_attr_support_speed(struct lpfc_vport *vport,
2839 struct lpfc_fdmi_attr_def *ad)
2841 struct lpfc_hba *phba = vport->phba;
2842 struct lpfc_fdmi_attr_entry *ae;
2845 ae = &ad->AttrValue;
2848 if (!(phba->hba_flag & HBA_FCOE_MODE)) {
2849 if (phba->lmt & LMT_128Gb)
2850 ae->un.AttrInt |= HBA_PORTSPEED_128GFC;
2851 if (phba->lmt & LMT_64Gb)
2852 ae->un.AttrInt |= HBA_PORTSPEED_64GFC;
2853 if (phba->lmt & LMT_32Gb)
2854 ae->un.AttrInt |= HBA_PORTSPEED_32GFC;
2855 if (phba->lmt & LMT_16Gb)
2856 ae->un.AttrInt |= HBA_PORTSPEED_16GFC;
2857 if (phba->lmt & LMT_10Gb)
2858 ae->un.AttrInt |= HBA_PORTSPEED_10GFC;
2859 if (phba->lmt & LMT_8Gb)
2860 ae->un.AttrInt |= HBA_PORTSPEED_8GFC;
2861 if (phba->lmt & LMT_4Gb)
2862 ae->un.AttrInt |= HBA_PORTSPEED_4GFC;
2863 if (phba->lmt & LMT_2Gb)
2864 ae->un.AttrInt |= HBA_PORTSPEED_2GFC;
2865 if (phba->lmt & LMT_1Gb)
2866 ae->un.AttrInt |= HBA_PORTSPEED_1GFC;
2868 /* FCoE links support only one speed */
2869 switch (phba->fc_linkspeed) {
2870 case LPFC_ASYNC_LINK_SPEED_10GBPS:
2871 ae->un.AttrInt = HBA_PORTSPEED_10GE;
2873 case LPFC_ASYNC_LINK_SPEED_25GBPS:
2874 ae->un.AttrInt = HBA_PORTSPEED_25GE;
2876 case LPFC_ASYNC_LINK_SPEED_40GBPS:
2877 ae->un.AttrInt = HBA_PORTSPEED_40GE;
2879 case LPFC_ASYNC_LINK_SPEED_100GBPS:
2880 ae->un.AttrInt = HBA_PORTSPEED_100GE;
2884 ae->un.AttrInt = cpu_to_be32(ae->un.AttrInt);
2885 size = FOURBYTES + sizeof(uint32_t);
2886 ad->AttrLen = cpu_to_be16(size);
2887 ad->AttrType = cpu_to_be16(RPRT_SUPPORTED_SPEED);
2892 lpfc_fdmi_port_attr_speed(struct lpfc_vport *vport,
2893 struct lpfc_fdmi_attr_def *ad)
2895 struct lpfc_hba *phba = vport->phba;
2896 struct lpfc_fdmi_attr_entry *ae;
2899 ae = &ad->AttrValue;
2901 if (!(phba->hba_flag & HBA_FCOE_MODE)) {
2902 switch (phba->fc_linkspeed) {
2903 case LPFC_LINK_SPEED_1GHZ:
2904 ae->un.AttrInt = HBA_PORTSPEED_1GFC;
2906 case LPFC_LINK_SPEED_2GHZ:
2907 ae->un.AttrInt = HBA_PORTSPEED_2GFC;
2909 case LPFC_LINK_SPEED_4GHZ:
2910 ae->un.AttrInt = HBA_PORTSPEED_4GFC;
2912 case LPFC_LINK_SPEED_8GHZ:
2913 ae->un.AttrInt = HBA_PORTSPEED_8GFC;
2915 case LPFC_LINK_SPEED_10GHZ:
2916 ae->un.AttrInt = HBA_PORTSPEED_10GFC;
2918 case LPFC_LINK_SPEED_16GHZ:
2919 ae->un.AttrInt = HBA_PORTSPEED_16GFC;
2921 case LPFC_LINK_SPEED_32GHZ:
2922 ae->un.AttrInt = HBA_PORTSPEED_32GFC;
2924 case LPFC_LINK_SPEED_64GHZ:
2925 ae->un.AttrInt = HBA_PORTSPEED_64GFC;
2927 case LPFC_LINK_SPEED_128GHZ:
2928 ae->un.AttrInt = HBA_PORTSPEED_128GFC;
2931 ae->un.AttrInt = HBA_PORTSPEED_UNKNOWN;
2935 switch (phba->fc_linkspeed) {
2936 case LPFC_ASYNC_LINK_SPEED_10GBPS:
2937 ae->un.AttrInt = HBA_PORTSPEED_10GE;
2939 case LPFC_ASYNC_LINK_SPEED_25GBPS:
2940 ae->un.AttrInt = HBA_PORTSPEED_25GE;
2942 case LPFC_ASYNC_LINK_SPEED_40GBPS:
2943 ae->un.AttrInt = HBA_PORTSPEED_40GE;
2945 case LPFC_ASYNC_LINK_SPEED_100GBPS:
2946 ae->un.AttrInt = HBA_PORTSPEED_100GE;
2949 ae->un.AttrInt = HBA_PORTSPEED_UNKNOWN;
2954 ae->un.AttrInt = cpu_to_be32(ae->un.AttrInt);
2955 size = FOURBYTES + sizeof(uint32_t);
2956 ad->AttrLen = cpu_to_be16(size);
2957 ad->AttrType = cpu_to_be16(RPRT_PORT_SPEED);
2962 lpfc_fdmi_port_attr_max_frame(struct lpfc_vport *vport,
2963 struct lpfc_fdmi_attr_def *ad)
2965 struct serv_parm *hsp;
2966 struct lpfc_fdmi_attr_entry *ae;
2969 ae = &ad->AttrValue;
2971 hsp = (struct serv_parm *)&vport->fc_sparam;
2972 ae->un.AttrInt = (((uint32_t) hsp->cmn.bbRcvSizeMsb & 0x0F) << 8) |
2973 (uint32_t) hsp->cmn.bbRcvSizeLsb;
2974 ae->un.AttrInt = cpu_to_be32(ae->un.AttrInt);
2975 size = FOURBYTES + sizeof(uint32_t);
2976 ad->AttrLen = cpu_to_be16(size);
2977 ad->AttrType = cpu_to_be16(RPRT_MAX_FRAME_SIZE);
2982 lpfc_fdmi_port_attr_os_devname(struct lpfc_vport *vport,
2983 struct lpfc_fdmi_attr_def *ad)
2985 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2986 struct lpfc_fdmi_attr_entry *ae;
2989 ae = &ad->AttrValue;
2990 memset(ae, 0, sizeof(*ae));
2992 snprintf(ae->un.AttrString, sizeof(ae->un.AttrString),
2993 "/sys/class/scsi_host/host%d", shost->host_no);
2994 len = strnlen((char *)ae->un.AttrString,
2995 sizeof(ae->un.AttrString));
2996 len += (len & 3) ? (4 - (len & 3)) : 4;
2997 size = FOURBYTES + len;
2998 ad->AttrLen = cpu_to_be16(size);
2999 ad->AttrType = cpu_to_be16(RPRT_OS_DEVICE_NAME);
3004 lpfc_fdmi_port_attr_host_name(struct lpfc_vport *vport,
3005 struct lpfc_fdmi_attr_def *ad)
3007 struct lpfc_fdmi_attr_entry *ae;
3010 ae = &ad->AttrValue;
3011 memset(ae, 0, sizeof(*ae));
3013 scnprintf(ae->un.AttrString, sizeof(ae->un.AttrString), "%s",
3014 vport->phba->os_host_name);
3016 len = strnlen(ae->un.AttrString, sizeof(ae->un.AttrString));
3017 len += (len & 3) ? (4 - (len & 3)) : 4;
3018 size = FOURBYTES + len;
3019 ad->AttrLen = cpu_to_be16(size);
3020 ad->AttrType = cpu_to_be16(RPRT_HOST_NAME);
3025 lpfc_fdmi_port_attr_wwnn(struct lpfc_vport *vport,
3026 struct lpfc_fdmi_attr_def *ad)
3028 struct lpfc_fdmi_attr_entry *ae;
3031 ae = &ad->AttrValue;
3032 memset(ae, 0, sizeof(*ae));
3034 memcpy(&ae->un.AttrWWN, &vport->fc_sparam.nodeName,
3035 sizeof(struct lpfc_name));
3036 size = FOURBYTES + sizeof(struct lpfc_name);
3037 ad->AttrLen = cpu_to_be16(size);
3038 ad->AttrType = cpu_to_be16(RPRT_NODENAME);
3043 lpfc_fdmi_port_attr_wwpn(struct lpfc_vport *vport,
3044 struct lpfc_fdmi_attr_def *ad)
3046 struct lpfc_fdmi_attr_entry *ae;
3049 ae = &ad->AttrValue;
3050 memset(ae, 0, sizeof(*ae));
3052 memcpy(&ae->un.AttrWWN, &vport->fc_sparam.portName,
3053 sizeof(struct lpfc_name));
3054 size = FOURBYTES + sizeof(struct lpfc_name);
3055 ad->AttrLen = cpu_to_be16(size);
3056 ad->AttrType = cpu_to_be16(RPRT_PORTNAME);
3061 lpfc_fdmi_port_attr_symbolic_name(struct lpfc_vport *vport,
3062 struct lpfc_fdmi_attr_def *ad)
3064 struct lpfc_fdmi_attr_entry *ae;
3067 ae = &ad->AttrValue;
3068 memset(ae, 0, sizeof(*ae));
3070 len = lpfc_vport_symbolic_port_name(vport, ae->un.AttrString, 256);
3071 len += (len & 3) ? (4 - (len & 3)) : 4;
3072 size = FOURBYTES + len;
3073 ad->AttrLen = cpu_to_be16(size);
3074 ad->AttrType = cpu_to_be16(RPRT_SYM_PORTNAME);
3079 lpfc_fdmi_port_attr_port_type(struct lpfc_vport *vport,
3080 struct lpfc_fdmi_attr_def *ad)
3082 struct lpfc_hba *phba = vport->phba;
3083 struct lpfc_fdmi_attr_entry *ae;
3086 ae = &ad->AttrValue;
3087 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP)
3088 ae->un.AttrInt = cpu_to_be32(LPFC_FDMI_PORTTYPE_NLPORT);
3090 ae->un.AttrInt = cpu_to_be32(LPFC_FDMI_PORTTYPE_NPORT);
3091 size = FOURBYTES + sizeof(uint32_t);
3092 ad->AttrLen = cpu_to_be16(size);
3093 ad->AttrType = cpu_to_be16(RPRT_PORT_TYPE);
3098 lpfc_fdmi_port_attr_class(struct lpfc_vport *vport,
3099 struct lpfc_fdmi_attr_def *ad)
3101 struct lpfc_fdmi_attr_entry *ae;
3104 ae = &ad->AttrValue;
3105 ae->un.AttrInt = cpu_to_be32(FC_COS_CLASS2 | FC_COS_CLASS3);
3106 size = FOURBYTES + sizeof(uint32_t);
3107 ad->AttrLen = cpu_to_be16(size);
3108 ad->AttrType = cpu_to_be16(RPRT_SUPPORTED_CLASS);
3113 lpfc_fdmi_port_attr_fabric_wwpn(struct lpfc_vport *vport,
3114 struct lpfc_fdmi_attr_def *ad)
3116 struct lpfc_fdmi_attr_entry *ae;
3119 ae = &ad->AttrValue;
3120 memset(ae, 0, sizeof(*ae));
3122 memcpy(&ae->un.AttrWWN, &vport->fabric_portname,
3123 sizeof(struct lpfc_name));
3124 size = FOURBYTES + sizeof(struct lpfc_name);
3125 ad->AttrLen = cpu_to_be16(size);
3126 ad->AttrType = cpu_to_be16(RPRT_FABRICNAME);
3131 lpfc_fdmi_port_attr_active_fc4type(struct lpfc_vport *vport,
3132 struct lpfc_fdmi_attr_def *ad)
3134 struct lpfc_fdmi_attr_entry *ae;
3137 ae = &ad->AttrValue;
3138 memset(ae, 0, sizeof(*ae));
3140 ae->un.AttrTypes[2] = 0x01; /* Type 0x8 - FCP */
3141 ae->un.AttrTypes[7] = 0x01; /* Type 0x20 - CT */
3143 /* Check to see if NVME is configured or not */
3144 if (vport->phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)
3145 ae->un.AttrTypes[6] = 0x1; /* Type 0x28 - NVME */
3147 size = FOURBYTES + 32;
3148 ad->AttrLen = cpu_to_be16(size);
3149 ad->AttrType = cpu_to_be16(RPRT_ACTIVE_FC4_TYPES);
3154 lpfc_fdmi_port_attr_port_state(struct lpfc_vport *vport,
3155 struct lpfc_fdmi_attr_def *ad)
3157 struct lpfc_fdmi_attr_entry *ae;
3160 ae = &ad->AttrValue;
3161 /* Link Up - operational */
3162 ae->un.AttrInt = cpu_to_be32(LPFC_FDMI_PORTSTATE_ONLINE);
3163 size = FOURBYTES + sizeof(uint32_t);
3164 ad->AttrLen = cpu_to_be16(size);
3165 ad->AttrType = cpu_to_be16(RPRT_PORT_STATE);
3170 lpfc_fdmi_port_attr_num_disc(struct lpfc_vport *vport,
3171 struct lpfc_fdmi_attr_def *ad)
3173 struct lpfc_fdmi_attr_entry *ae;
3176 ae = &ad->AttrValue;
3177 vport->fdmi_num_disc = lpfc_find_map_node(vport);
3178 ae->un.AttrInt = cpu_to_be32(vport->fdmi_num_disc);
3179 size = FOURBYTES + sizeof(uint32_t);
3180 ad->AttrLen = cpu_to_be16(size);
3181 ad->AttrType = cpu_to_be16(RPRT_DISC_PORT);
3186 lpfc_fdmi_port_attr_nportid(struct lpfc_vport *vport,
3187 struct lpfc_fdmi_attr_def *ad)
3189 struct lpfc_fdmi_attr_entry *ae;
3192 ae = &ad->AttrValue;
3193 ae->un.AttrInt = cpu_to_be32(vport->fc_myDID);
3194 size = FOURBYTES + sizeof(uint32_t);
3195 ad->AttrLen = cpu_to_be16(size);
3196 ad->AttrType = cpu_to_be16(RPRT_PORT_ID);
3201 lpfc_fdmi_smart_attr_service(struct lpfc_vport *vport,
3202 struct lpfc_fdmi_attr_def *ad)
3204 struct lpfc_fdmi_attr_entry *ae;
3207 ae = &ad->AttrValue;
3208 memset(ae, 0, sizeof(*ae));
3210 strncpy(ae->un.AttrString, "Smart SAN Initiator",
3211 sizeof(ae->un.AttrString));
3212 len = strnlen(ae->un.AttrString,
3213 sizeof(ae->un.AttrString));
3214 len += (len & 3) ? (4 - (len & 3)) : 4;
3215 size = FOURBYTES + len;
3216 ad->AttrLen = cpu_to_be16(size);
3217 ad->AttrType = cpu_to_be16(RPRT_SMART_SERVICE);
3222 lpfc_fdmi_smart_attr_guid(struct lpfc_vport *vport,
3223 struct lpfc_fdmi_attr_def *ad)
3225 struct lpfc_fdmi_attr_entry *ae;
3228 ae = &ad->AttrValue;
3229 memset(ae, 0, sizeof(*ae));
3231 memcpy(&ae->un.AttrString, &vport->fc_sparam.nodeName,
3232 sizeof(struct lpfc_name));
3233 memcpy((((uint8_t *)&ae->un.AttrString) +
3234 sizeof(struct lpfc_name)),
3235 &vport->fc_sparam.portName, sizeof(struct lpfc_name));
3236 size = FOURBYTES + (2 * sizeof(struct lpfc_name));
3237 ad->AttrLen = cpu_to_be16(size);
3238 ad->AttrType = cpu_to_be16(RPRT_SMART_GUID);
3243 lpfc_fdmi_smart_attr_version(struct lpfc_vport *vport,
3244 struct lpfc_fdmi_attr_def *ad)
3246 struct lpfc_fdmi_attr_entry *ae;
3249 ae = &ad->AttrValue;
3250 memset(ae, 0, sizeof(*ae));
3252 strncpy(ae->un.AttrString, "Smart SAN Version 2.0",
3253 sizeof(ae->un.AttrString));
3254 len = strnlen(ae->un.AttrString,
3255 sizeof(ae->un.AttrString));
3256 len += (len & 3) ? (4 - (len & 3)) : 4;
3257 size = FOURBYTES + len;
3258 ad->AttrLen = cpu_to_be16(size);
3259 ad->AttrType = cpu_to_be16(RPRT_SMART_VERSION);
3264 lpfc_fdmi_smart_attr_model(struct lpfc_vport *vport,
3265 struct lpfc_fdmi_attr_def *ad)
3267 struct lpfc_hba *phba = vport->phba;
3268 struct lpfc_fdmi_attr_entry *ae;
3271 ae = &ad->AttrValue;
3272 memset(ae, 0, sizeof(*ae));
3274 strncpy(ae->un.AttrString, phba->ModelName,
3275 sizeof(ae->un.AttrString));
3276 len = strnlen(ae->un.AttrString, sizeof(ae->un.AttrString));
3277 len += (len & 3) ? (4 - (len & 3)) : 4;
3278 size = FOURBYTES + len;
3279 ad->AttrLen = cpu_to_be16(size);
3280 ad->AttrType = cpu_to_be16(RPRT_SMART_MODEL);
3285 lpfc_fdmi_smart_attr_port_info(struct lpfc_vport *vport,
3286 struct lpfc_fdmi_attr_def *ad)
3288 struct lpfc_fdmi_attr_entry *ae;
3291 ae = &ad->AttrValue;
3293 /* SRIOV (type 3) is not supported */
3295 ae->un.AttrInt = cpu_to_be32(2); /* NPIV */
3297 ae->un.AttrInt = cpu_to_be32(1); /* Physical */
3298 size = FOURBYTES + sizeof(uint32_t);
3299 ad->AttrLen = cpu_to_be16(size);
3300 ad->AttrType = cpu_to_be16(RPRT_SMART_PORT_INFO);
3305 lpfc_fdmi_smart_attr_qos(struct lpfc_vport *vport,
3306 struct lpfc_fdmi_attr_def *ad)
3308 struct lpfc_fdmi_attr_entry *ae;
3311 ae = &ad->AttrValue;
3312 ae->un.AttrInt = cpu_to_be32(0);
3313 size = FOURBYTES + sizeof(uint32_t);
3314 ad->AttrLen = cpu_to_be16(size);
3315 ad->AttrType = cpu_to_be16(RPRT_SMART_QOS);
3320 lpfc_fdmi_smart_attr_security(struct lpfc_vport *vport,
3321 struct lpfc_fdmi_attr_def *ad)
3323 struct lpfc_fdmi_attr_entry *ae;
3326 ae = &ad->AttrValue;
3327 ae->un.AttrInt = cpu_to_be32(1);
3328 size = FOURBYTES + sizeof(uint32_t);
3329 ad->AttrLen = cpu_to_be16(size);
3330 ad->AttrType = cpu_to_be16(RPRT_SMART_SECURITY);
3335 lpfc_fdmi_vendor_attr_mi(struct lpfc_vport *vport,
3336 struct lpfc_fdmi_attr_def *ad)
3338 struct lpfc_hba *phba = vport->phba;
3339 struct lpfc_fdmi_attr_entry *ae;
3341 char mibrevision[16];
3343 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
3345 sprintf(mibrevision, "ELXE2EM:%04d",
3346 phba->sli4_hba.pc_sli4_params.mi_value);
3347 strncpy(ae->un.AttrString, &mibrevision[0], sizeof(ae->un.AttrString));
3348 len = strnlen(ae->un.AttrString, sizeof(ae->un.AttrString));
3349 len += (len & 3) ? (4 - (len & 3)) : 4;
3350 size = FOURBYTES + len;
3351 ad->AttrLen = cpu_to_be16(size);
3352 ad->AttrType = cpu_to_be16(RPRT_VENDOR_MI);
3356 /* RHBA attribute jump table */
3357 int (*lpfc_fdmi_hba_action[])
3358 (struct lpfc_vport *vport, struct lpfc_fdmi_attr_def *ad) = {
3359 /* Action routine Mask bit Attribute type */
3360 lpfc_fdmi_hba_attr_wwnn, /* bit0 RHBA_NODENAME */
3361 lpfc_fdmi_hba_attr_manufacturer, /* bit1 RHBA_MANUFACTURER */
3362 lpfc_fdmi_hba_attr_sn, /* bit2 RHBA_SERIAL_NUMBER */
3363 lpfc_fdmi_hba_attr_model, /* bit3 RHBA_MODEL */
3364 lpfc_fdmi_hba_attr_description, /* bit4 RHBA_MODEL_DESCRIPTION */
3365 lpfc_fdmi_hba_attr_hdw_ver, /* bit5 RHBA_HARDWARE_VERSION */
3366 lpfc_fdmi_hba_attr_drvr_ver, /* bit6 RHBA_DRIVER_VERSION */
3367 lpfc_fdmi_hba_attr_rom_ver, /* bit7 RHBA_OPTION_ROM_VERSION */
3368 lpfc_fdmi_hba_attr_fmw_ver, /* bit8 RHBA_FIRMWARE_VERSION */
3369 lpfc_fdmi_hba_attr_os_ver, /* bit9 RHBA_OS_NAME_VERSION */
3370 lpfc_fdmi_hba_attr_ct_len, /* bit10 RHBA_MAX_CT_PAYLOAD_LEN */
3371 lpfc_fdmi_hba_attr_symbolic_name, /* bit11 RHBA_SYM_NODENAME */
3372 lpfc_fdmi_hba_attr_vendor_info, /* bit12 RHBA_VENDOR_INFO */
3373 lpfc_fdmi_hba_attr_num_ports, /* bit13 RHBA_NUM_PORTS */
3374 lpfc_fdmi_hba_attr_fabric_wwnn, /* bit14 RHBA_FABRIC_WWNN */
3375 lpfc_fdmi_hba_attr_bios_ver, /* bit15 RHBA_BIOS_VERSION */
3376 lpfc_fdmi_hba_attr_bios_state, /* bit16 RHBA_BIOS_STATE */
3377 lpfc_fdmi_hba_attr_vendor_id, /* bit17 RHBA_VENDOR_ID */
3380 /* RPA / RPRT attribute jump table */
3381 int (*lpfc_fdmi_port_action[])
3382 (struct lpfc_vport *vport, struct lpfc_fdmi_attr_def *ad) = {
3383 /* Action routine Mask bit Attribute type */
3384 lpfc_fdmi_port_attr_fc4type, /* bit0 RPRT_SUPPORT_FC4_TYPES */
3385 lpfc_fdmi_port_attr_support_speed, /* bit1 RPRT_SUPPORTED_SPEED */
3386 lpfc_fdmi_port_attr_speed, /* bit2 RPRT_PORT_SPEED */
3387 lpfc_fdmi_port_attr_max_frame, /* bit3 RPRT_MAX_FRAME_SIZE */
3388 lpfc_fdmi_port_attr_os_devname, /* bit4 RPRT_OS_DEVICE_NAME */
3389 lpfc_fdmi_port_attr_host_name, /* bit5 RPRT_HOST_NAME */
3390 lpfc_fdmi_port_attr_wwnn, /* bit6 RPRT_NODENAME */
3391 lpfc_fdmi_port_attr_wwpn, /* bit7 RPRT_PORTNAME */
3392 lpfc_fdmi_port_attr_symbolic_name, /* bit8 RPRT_SYM_PORTNAME */
3393 lpfc_fdmi_port_attr_port_type, /* bit9 RPRT_PORT_TYPE */
3394 lpfc_fdmi_port_attr_class, /* bit10 RPRT_SUPPORTED_CLASS */
3395 lpfc_fdmi_port_attr_fabric_wwpn, /* bit11 RPRT_FABRICNAME */
3396 lpfc_fdmi_port_attr_active_fc4type, /* bit12 RPRT_ACTIVE_FC4_TYPES */
3397 lpfc_fdmi_port_attr_port_state, /* bit13 RPRT_PORT_STATE */
3398 lpfc_fdmi_port_attr_num_disc, /* bit14 RPRT_DISC_PORT */
3399 lpfc_fdmi_port_attr_nportid, /* bit15 RPRT_PORT_ID */
3400 lpfc_fdmi_smart_attr_service, /* bit16 RPRT_SMART_SERVICE */
3401 lpfc_fdmi_smart_attr_guid, /* bit17 RPRT_SMART_GUID */
3402 lpfc_fdmi_smart_attr_version, /* bit18 RPRT_SMART_VERSION */
3403 lpfc_fdmi_smart_attr_model, /* bit19 RPRT_SMART_MODEL */
3404 lpfc_fdmi_smart_attr_port_info, /* bit20 RPRT_SMART_PORT_INFO */
3405 lpfc_fdmi_smart_attr_qos, /* bit21 RPRT_SMART_QOS */
3406 lpfc_fdmi_smart_attr_security, /* bit22 RPRT_SMART_SECURITY */
3407 lpfc_fdmi_vendor_attr_mi, /* bit23 RPRT_VENDOR_MI */
3411 * lpfc_fdmi_cmd - Build and send a FDMI cmd to the specified NPort
3412 * @vport: pointer to a host virtual N_Port data structure.
3413 * @ndlp: ndlp to send FDMI cmd to (if NULL use FDMI_DID)
3414 * @cmdcode: FDMI command to send
3415 * @new_mask: Mask of HBA or PORT Attributes to send
3417 * Builds and sends a FDMI command using the CT subsystem.
3420 lpfc_fdmi_cmd(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
3421 int cmdcode, uint32_t new_mask)
3423 struct lpfc_hba *phba = vport->phba;
3424 struct lpfc_dmabuf *mp, *bmp;
3425 struct lpfc_sli_ct_request *CtReq;
3426 struct ulp_bde64 *bpl;
3431 struct lpfc_fdmi_reg_hba *rh;
3432 struct lpfc_fdmi_port_entry *pe;
3433 struct lpfc_fdmi_reg_portattr *pab = NULL;
3434 struct lpfc_fdmi_attr_block *ab = NULL;
3435 int (*func)(struct lpfc_vport *vport, struct lpfc_fdmi_attr_def *ad);
3436 void (*cmpl)(struct lpfc_hba *, struct lpfc_iocbq *,
3437 struct lpfc_iocbq *);
3442 cmpl = lpfc_cmpl_ct_disc_fdmi; /* called from discovery */
3444 /* fill in BDEs for command */
3445 /* Allocate buffer for command payload */
3446 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
3450 mp->virt = lpfc_mbuf_alloc(phba, 0, &(mp->phys));
3452 goto fdmi_cmd_free_mp;
3454 /* Allocate buffer for Buffer ptr list */
3455 bmp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
3457 goto fdmi_cmd_free_mpvirt;
3459 bmp->virt = lpfc_mbuf_alloc(phba, 0, &(bmp->phys));
3461 goto fdmi_cmd_free_bmp;
3463 INIT_LIST_HEAD(&mp->list);
3464 INIT_LIST_HEAD(&bmp->list);
3467 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
3468 "0218 FDMI Request Data: x%x x%x x%x\n",
3469 vport->fc_flag, vport->port_state, cmdcode);
3470 CtReq = (struct lpfc_sli_ct_request *)mp->virt;
3472 /* First populate the CT_IU preamble */
3473 memset(CtReq, 0, sizeof(struct lpfc_sli_ct_request));
3474 CtReq->RevisionId.bits.Revision = SLI_CT_REVISION;
3475 CtReq->RevisionId.bits.InId = 0;
3477 CtReq->FsType = SLI_CT_MANAGEMENT_SERVICE;
3478 CtReq->FsSubType = SLI_CT_FDMI_Subtypes;
3480 CtReq->CommandResponse.bits.CmdRsp = cpu_to_be16(cmdcode);
3481 rsp_size = LPFC_BPL_SIZE;
3484 /* Next fill in the specific FDMI cmd information */
3488 rh = (struct lpfc_fdmi_reg_hba *)&CtReq->un.PortID;
3489 /* HBA Identifier */
3490 memcpy(&rh->hi.PortName, &phba->pport->fc_sparam.portName,
3491 sizeof(struct lpfc_name));
3493 if (cmdcode == SLI_MGMT_RHBA) {
3494 /* Registered Port List */
3495 /* One entry (port) per adapter */
3496 rh->rpl.EntryCnt = cpu_to_be32(1);
3497 memcpy(&rh->rpl.pe.PortName,
3498 &phba->pport->fc_sparam.portName,
3499 sizeof(struct lpfc_name));
3501 /* point to the HBA attribute block */
3502 size = 2 * sizeof(struct lpfc_name) +
3505 size = sizeof(struct lpfc_name);
3507 ab = (struct lpfc_fdmi_attr_block *)((uint8_t *)rh + size);
3514 mask = vport->fdmi_hba_mask;
3516 /* Mask will dictate what attributes to build in the request */
3519 func = lpfc_fdmi_hba_action[bit_pos];
3521 (struct lpfc_fdmi_attr_def *)
3522 ((uint8_t *)rh + size));
3525 (LPFC_BPL_SIZE - LPFC_CT_PREAMBLE))
3532 ab->EntryCnt = cpu_to_be32(ab->EntryCnt);
3534 size = GID_REQUEST_SZ - 4 + size;
3539 pab = (struct lpfc_fdmi_reg_portattr *)&CtReq->un.PortID;
3540 if (cmdcode == SLI_MGMT_RPRT) {
3541 rh = (struct lpfc_fdmi_reg_hba *)pab;
3542 /* HBA Identifier */
3543 memcpy(&rh->hi.PortName,
3544 &phba->pport->fc_sparam.portName,
3545 sizeof(struct lpfc_name));
3546 pab = (struct lpfc_fdmi_reg_portattr *)
3547 ((uint8_t *)pab + sizeof(struct lpfc_name));
3550 memcpy((uint8_t *)&pab->PortName,
3551 (uint8_t *)&vport->fc_sparam.portName,
3552 sizeof(struct lpfc_name));
3553 size += sizeof(struct lpfc_name) + FOURBYTES;
3554 pab->ab.EntryCnt = 0;
3559 mask = vport->fdmi_port_mask;
3561 /* Mask will dictate what attributes to build in the request */
3564 func = lpfc_fdmi_port_action[bit_pos];
3566 (struct lpfc_fdmi_attr_def *)
3567 ((uint8_t *)pab + size));
3570 (LPFC_BPL_SIZE - LPFC_CT_PREAMBLE))
3577 pab->ab.EntryCnt = cpu_to_be32(pab->ab.EntryCnt);
3579 if (cmdcode == SLI_MGMT_RPRT)
3580 size += sizeof(struct lpfc_name);
3581 size = GID_REQUEST_SZ - 4 + size;
3586 rsp_size = FC_MAX_NS_RSP;
3590 pe = (struct lpfc_fdmi_port_entry *)&CtReq->un.PortID;
3591 memcpy((uint8_t *)&pe->PortName,
3592 (uint8_t *)&vport->fc_sparam.portName,
3593 sizeof(struct lpfc_name));
3594 size = GID_REQUEST_SZ - 4 + sizeof(struct lpfc_name);
3599 rsp_size = FC_MAX_NS_RSP;
3603 pe = (struct lpfc_fdmi_port_entry *)&CtReq->un.PortID;
3604 memcpy((uint8_t *)&pe->PortName,
3605 (uint8_t *)&vport->fc_sparam.portName,
3606 sizeof(struct lpfc_name));
3607 size = GID_REQUEST_SZ - 4 + sizeof(struct lpfc_name);
3610 size = GID_REQUEST_SZ - 4;
3613 lpfc_printf_vlog(vport, KERN_WARNING, LOG_DISCOVERY,
3614 "0298 FDMI cmdcode x%x not supported\n",
3616 goto fdmi_cmd_free_bmpvirt;
3618 CtReq->CommandResponse.bits.Size = cpu_to_be16(rsp_size);
3620 bpl = (struct ulp_bde64 *)bmp->virt;
3621 bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys));
3622 bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys));
3623 bpl->tus.f.bdeFlags = 0;
3624 bpl->tus.f.bdeSize = size;
3627 * The lpfc_ct_cmd/lpfc_get_req shall increment ndlp reference count
3628 * to hold ndlp reference for the corresponding callback function.
3630 if (!lpfc_ct_cmd(vport, mp, bmp, ndlp, cmpl, rsp_size, 0))
3633 fdmi_cmd_free_bmpvirt:
3634 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
3637 fdmi_cmd_free_mpvirt:
3638 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3642 /* Issue FDMI request failed */
3643 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
3644 "0244 Issue FDMI request failed Data: x%x\n",
3650 * lpfc_delayed_disc_tmo - Timeout handler for delayed discovery timer.
3651 * @t: Context object of the timer.
3653 * This function set the WORKER_DELAYED_DISC_TMO flag and wake up
3654 * the worker thread.
3657 lpfc_delayed_disc_tmo(struct timer_list *t)
3659 struct lpfc_vport *vport = from_timer(vport, t, delayed_disc_tmo);
3660 struct lpfc_hba *phba = vport->phba;
3661 uint32_t tmo_posted;
3662 unsigned long iflag;
3664 spin_lock_irqsave(&vport->work_port_lock, iflag);
3665 tmo_posted = vport->work_port_events & WORKER_DELAYED_DISC_TMO;
3667 vport->work_port_events |= WORKER_DELAYED_DISC_TMO;
3668 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
3671 lpfc_worker_wake_up(phba);
3676 * lpfc_delayed_disc_timeout_handler - Function called by worker thread to
3677 * handle delayed discovery.
3678 * @vport: pointer to a host virtual N_Port data structure.
3680 * This function start nport discovery of the vport.
3683 lpfc_delayed_disc_timeout_handler(struct lpfc_vport *vport)
3685 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3687 spin_lock_irq(shost->host_lock);
3688 if (!(vport->fc_flag & FC_DISC_DELAYED)) {
3689 spin_unlock_irq(shost->host_lock);
3692 vport->fc_flag &= ~FC_DISC_DELAYED;
3693 spin_unlock_irq(shost->host_lock);
3695 lpfc_do_scr_ns_plogi(vport->phba, vport);
3699 lpfc_decode_firmware_rev(struct lpfc_hba *phba, char *fwrevision, int flag)
3701 struct lpfc_sli *psli = &phba->sli;
3702 lpfc_vpd_t *vp = &phba->vpd;
3703 uint32_t b1, b2, b3, b4, i, rev;
3705 uint32_t *ptr, str[4];
3708 if (phba->sli_rev == LPFC_SLI_REV4)
3709 snprintf(fwrevision, FW_REV_STR_SIZE, "%s", vp->rev.opFwName);
3710 else if (vp->rev.rBit) {
3711 if (psli->sli_flag & LPFC_SLI_ACTIVE)
3712 rev = vp->rev.sli2FwRev;
3714 rev = vp->rev.sli1FwRev;
3716 b1 = (rev & 0x0000f000) >> 12;
3717 b2 = (rev & 0x00000f00) >> 8;
3718 b3 = (rev & 0x000000c0) >> 6;
3719 b4 = (rev & 0x00000030) >> 4;
3738 b4 = (rev & 0x0000000f);
3740 if (psli->sli_flag & LPFC_SLI_ACTIVE)
3741 fwname = vp->rev.sli2FwName;
3743 fwname = vp->rev.sli1FwName;
3745 for (i = 0; i < 16; i++)
3746 if (fwname[i] == 0x20)
3749 ptr = (uint32_t*)fwname;
3751 for (i = 0; i < 3; i++)
3752 str[i] = be32_to_cpu(*ptr++);
3756 sprintf(fwrevision, "%d.%d%d (%s)",
3757 b1, b2, b3, (char *)str);
3759 sprintf(fwrevision, "%d.%d%d", b1,
3763 sprintf(fwrevision, "%d.%d%d%c%d (%s)",
3767 sprintf(fwrevision, "%d.%d%d%c%d",
3771 rev = vp->rev.smFwRev;
3773 b1 = (rev & 0xff000000) >> 24;
3774 b2 = (rev & 0x00f00000) >> 20;
3775 b3 = (rev & 0x000f0000) >> 16;
3776 c = (rev & 0x0000ff00) >> 8;
3777 b4 = (rev & 0x000000ff);
3779 sprintf(fwrevision, "%d.%d%d%c%d", b1, b2, b3, c, b4);
3785 lpfc_cmpl_ct_cmd_vmid(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3786 struct lpfc_iocbq *rspiocb)
3788 struct lpfc_vport *vport = cmdiocb->vport;
3789 struct lpfc_dmabuf *inp = cmdiocb->context1;
3790 struct lpfc_dmabuf *outp = cmdiocb->context2;
3791 struct lpfc_sli_ct_request *ctcmd = inp->virt;
3792 struct lpfc_sli_ct_request *ctrsp = outp->virt;
3793 u16 rsp = ctrsp->CommandResponse.bits.CmdRsp;
3794 struct app_id_object *app;
3795 u32 cmd, hash, bucket;
3796 struct lpfc_vmid *vmp, *cur;
3797 u8 *data = outp->virt;
3800 cmd = be16_to_cpu(ctcmd->CommandResponse.bits.CmdRsp);
3801 if (cmd == SLI_CTAS_DALLAPP_ID)
3802 lpfc_ct_free_iocb(phba, cmdiocb);
3804 if (lpfc_els_chk_latt(vport) || rspiocb->iocb.ulpStatus) {
3805 if (cmd != SLI_CTAS_DALLAPP_ID)
3808 /* Check for a CT LS_RJT response */
3809 if (rsp == be16_to_cpu(SLI_CT_RESPONSE_FS_RJT)) {
3810 if (cmd != SLI_CTAS_DALLAPP_ID)
3811 lpfc_printf_vlog(vport, KERN_DEBUG, LOG_DISCOVERY,
3812 "3306 VMID FS_RJT Data: x%x x%x x%x\n",
3813 cmd, ctrsp->ReasonCode,
3814 ctrsp->Explanation);
3815 if ((cmd != SLI_CTAS_DALLAPP_ID) ||
3816 (ctrsp->ReasonCode != SLI_CT_UNABLE_TO_PERFORM_REQ) ||
3817 (ctrsp->Explanation != SLI_CT_APP_ID_NOT_AVAILABLE)) {
3818 /* If DALLAPP_ID failed retry later */
3819 if (cmd == SLI_CTAS_DALLAPP_ID)
3820 vport->load_flag |= FC_DEREGISTER_ALL_APP_ID;
3826 case SLI_CTAS_RAPP_IDENT:
3827 app = (struct app_id_object *)(RAPP_IDENT_OFFSET + data);
3828 lpfc_printf_vlog(vport, KERN_DEBUG, LOG_DISCOVERY,
3829 "6712 RAPP_IDENT app id %d port id x%x id "
3830 "len %d\n", be32_to_cpu(app->app_id),
3831 be32_to_cpu(app->port_id),
3832 app->obj.entity_id_len);
3834 if (app->obj.entity_id_len == 0 || app->port_id == 0)
3837 hash = lpfc_vmid_hash_fn(app->obj.entity_id,
3838 app->obj.entity_id_len);
3839 vmp = lpfc_get_vmid_from_hashtable(vport, hash,
3840 app->obj.entity_id);
3842 write_lock(&vport->vmid_lock);
3843 vmp->un.app_id = be32_to_cpu(app->app_id);
3844 vmp->flag |= LPFC_VMID_REGISTERED;
3845 vmp->flag &= ~LPFC_VMID_REQ_REGISTER;
3846 write_unlock(&vport->vmid_lock);
3847 /* Set IN USE flag */
3848 vport->vmid_flag |= LPFC_VMID_IN_USE;
3850 lpfc_printf_vlog(vport, KERN_DEBUG, LOG_DISCOVERY,
3851 "6901 No entry found %s hash %d\n",
3852 app->obj.entity_id, hash);
3855 case SLI_CTAS_DAPP_IDENT:
3856 app = (struct app_id_object *)(DAPP_IDENT_OFFSET + data);
3857 lpfc_printf_vlog(vport, KERN_DEBUG, LOG_DISCOVERY,
3858 "6713 DAPP_IDENT app id %d port id x%x\n",
3859 be32_to_cpu(app->app_id),
3860 be32_to_cpu(app->port_id));
3862 case SLI_CTAS_DALLAPP_ID:
3863 lpfc_printf_vlog(vport, KERN_DEBUG, LOG_DISCOVERY,
3864 "8856 Deregistered all app ids\n");
3865 read_lock(&vport->vmid_lock);
3866 for (i = 0; i < phba->cfg_max_vmid; i++) {
3867 vmp = &vport->vmid[i];
3868 if (vmp->flag != LPFC_VMID_SLOT_FREE)
3869 memset(vmp, 0, sizeof(struct lpfc_vmid));
3871 read_unlock(&vport->vmid_lock);
3872 /* for all elements in the hash table */
3873 if (!hash_empty(vport->hash_table))
3874 hash_for_each(vport->hash_table, bucket, cur, hnode)
3875 hash_del(&cur->hnode);
3876 vport->load_flag |= FC_ALLOW_VMID;
3879 lpfc_printf_vlog(vport, KERN_DEBUG, LOG_DISCOVERY,
3880 "8857 Invalid command code\n");
3885 * lpfc_vmid_cmd - Build and send a FDMI cmd to the specified NPort
3886 * @vport: pointer to a host virtual N_Port data structure.
3887 * @ndlp: ndlp to send FDMI cmd to (if NULL use FDMI_DID)
3888 * cmdcode: FDMI command to send
3889 * mask: Mask of HBA or PORT Attributes to send
3891 * Builds and sends a FDMI command using the CT subsystem.
3894 lpfc_vmid_cmd(struct lpfc_vport *vport,
3895 int cmdcode, struct lpfc_vmid *vmid)
3897 struct lpfc_hba *phba = vport->phba;
3898 struct lpfc_dmabuf *mp, *bmp;
3899 struct lpfc_sli_ct_request *ctreq;
3900 struct ulp_bde64 *bpl;
3904 struct lpfc_vmid_rapp_ident_list *rap;
3905 struct lpfc_vmid_dapp_ident_list *dap;
3907 struct lpfc_nodelist *ndlp;
3909 void (*cmpl)(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3910 struct lpfc_iocbq *rspiocb);
3912 ndlp = lpfc_findnode_did(vport, FDMI_DID);
3913 if (!ndlp || ndlp->nlp_state != NLP_STE_UNMAPPED_NODE)
3916 cmpl = lpfc_cmpl_ct_cmd_vmid;
3918 /* fill in BDEs for command */
3919 /* Allocate buffer for command payload */
3920 mp = kmalloc(sizeof(*mp), GFP_KERNEL);
3922 goto vmid_free_mp_exit;
3924 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
3926 goto vmid_free_mp_virt_exit;
3928 /* Allocate buffer for Buffer ptr list */
3929 bmp = kmalloc(sizeof(*bmp), GFP_KERNEL);
3931 goto vmid_free_bmp_exit;
3933 bmp->virt = lpfc_mbuf_alloc(phba, 0, &bmp->phys);
3935 goto vmid_free_bmp_virt_exit;
3937 INIT_LIST_HEAD(&mp->list);
3938 INIT_LIST_HEAD(&bmp->list);
3940 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
3941 "3275 VMID Request Data: x%x x%x x%x\n",
3942 vport->fc_flag, vport->port_state, cmdcode);
3943 ctreq = (struct lpfc_sli_ct_request *)mp->virt;
3945 /* First populate the CT_IU preamble */
3946 memset(data, 0, LPFC_BPL_SIZE);
3947 ctreq->RevisionId.bits.Revision = SLI_CT_REVISION;
3948 ctreq->RevisionId.bits.InId = 0;
3950 ctreq->FsType = SLI_CT_MANAGEMENT_SERVICE;
3951 ctreq->FsSubType = SLI_CT_APP_SEV_Subtypes;
3953 ctreq->CommandResponse.bits.CmdRsp = cpu_to_be16(cmdcode);
3954 rsp_size = LPFC_BPL_SIZE;
3958 case SLI_CTAS_RAPP_IDENT:
3959 lpfc_printf_vlog(vport, KERN_DEBUG, LOG_DISCOVERY,
3960 "1329 RAPP_IDENT for %s\n", vmid->host_vmid);
3961 ctreq->un.PortID = cpu_to_be32(vport->fc_myDID);
3962 rap = (struct lpfc_vmid_rapp_ident_list *)
3963 (DAPP_IDENT_OFFSET + data);
3964 rap->no_of_objects = cpu_to_be32(1);
3965 rap->obj[0].entity_id_len = vmid->vmid_len;
3966 memcpy(rap->obj[0].entity_id, vmid->host_vmid, vmid->vmid_len);
3967 size = RAPP_IDENT_OFFSET +
3968 sizeof(struct lpfc_vmid_rapp_ident_list);
3972 case SLI_CTAS_GALLAPPIA_ID:
3973 ctreq->un.PortID = cpu_to_be32(vport->fc_myDID);
3974 size = GALLAPPIA_ID_SIZE;
3977 case SLI_CTAS_DAPP_IDENT:
3978 lpfc_printf_vlog(vport, KERN_DEBUG, LOG_DISCOVERY,
3979 "1469 DAPP_IDENT for %s\n", vmid->host_vmid);
3980 ctreq->un.PortID = cpu_to_be32(vport->fc_myDID);
3981 dap = (struct lpfc_vmid_dapp_ident_list *)
3982 (DAPP_IDENT_OFFSET + data);
3983 dap->no_of_objects = cpu_to_be32(1);
3984 dap->obj[0].entity_id_len = vmid->vmid_len;
3985 memcpy(dap->obj[0].entity_id, vmid->host_vmid, vmid->vmid_len);
3986 size = DAPP_IDENT_OFFSET +
3987 sizeof(struct lpfc_vmid_dapp_ident_list);
3988 write_lock(&vport->vmid_lock);
3989 vmid->flag &= ~LPFC_VMID_REGISTERED;
3990 write_unlock(&vport->vmid_lock);
3994 case SLI_CTAS_DALLAPP_ID:
3995 ctreq->un.PortID = cpu_to_be32(vport->fc_myDID);
3996 size = DALLAPP_ID_SIZE;
4000 lpfc_printf_vlog(vport, KERN_DEBUG, LOG_DISCOVERY,
4001 "7062 VMID cmdcode x%x not supported\n",
4003 goto vmid_free_all_mem;
4006 ctreq->CommandResponse.bits.Size = cpu_to_be16(rsp_size);
4008 bpl = (struct ulp_bde64 *)bmp->virt;
4009 bpl->addrHigh = putPaddrHigh(mp->phys);
4010 bpl->addrLow = putPaddrLow(mp->phys);
4011 bpl->tus.f.bdeFlags = 0;
4012 bpl->tus.f.bdeSize = size;
4014 /* The lpfc_ct_cmd/lpfc_get_req shall increment ndlp reference count
4015 * to hold ndlp reference for the corresponding callback function.
4017 if (!lpfc_ct_cmd(vport, mp, bmp, ndlp, cmpl, rsp_size, retry))
4021 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
4022 vmid_free_bmp_virt_exit:
4025 lpfc_mbuf_free(phba, mp->virt, mp->phys);
4026 vmid_free_mp_virt_exit:
4030 /* Issue CT request failed */
4031 lpfc_printf_vlog(vport, KERN_DEBUG, LOG_DISCOVERY,
4032 "3276 VMID CT request failed Data: x%x\n", cmdcode);