1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2017 Broadcom. All Rights Reserved. The term *
5 * “Broadcom” refers to Broadcom Limited and/or its subsidiaries. *
6 * Copyright (C) 2004-2016 Emulex. All rights reserved. *
7 * EMULEX and SLI are trademarks of Emulex. *
10 * This program is free software; you can redistribute it and/or *
11 * modify it under the terms of version 2 of the GNU General *
12 * Public License as published by the Free Software Foundation. *
13 * This program is distributed in the hope that it will be useful. *
14 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
15 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
16 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
17 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
18 * TO BE LEGALLY INVALID. See the GNU General Public License for *
19 * more details, a copy of which can be found in the file COPYING *
20 * included with this package. *
21 *******************************************************************/
24 * Fibre Channel SCSI LAN Device Driver CT support: FC Generic Services FC-GS
27 #include <linux/blkdev.h>
28 #include <linux/pci.h>
29 #include <linux/interrupt.h>
30 #include <linux/slab.h>
31 #include <linux/utsname.h>
33 #include <scsi/scsi.h>
34 #include <scsi/scsi_device.h>
35 #include <scsi/scsi_host.h>
36 #include <scsi/scsi_transport_fc.h>
37 #include <scsi/fc/fc_fs.h>
42 #include "lpfc_sli4.h"
44 #include "lpfc_disc.h"
46 #include "lpfc_scsi.h"
47 #include "lpfc_nvme.h"
48 #include "lpfc_logmsg.h"
49 #include "lpfc_crtn.h"
50 #include "lpfc_version.h"
51 #include "lpfc_vport.h"
52 #include "lpfc_debugfs.h"
54 /* FDMI Port Speed definitions - FC-GS-7 */
55 #define HBA_PORTSPEED_1GFC 0x00000001 /* 1G FC */
56 #define HBA_PORTSPEED_2GFC 0x00000002 /* 2G FC */
57 #define HBA_PORTSPEED_4GFC 0x00000008 /* 4G FC */
58 #define HBA_PORTSPEED_10GFC 0x00000004 /* 10G FC */
59 #define HBA_PORTSPEED_8GFC 0x00000010 /* 8G FC */
60 #define HBA_PORTSPEED_16GFC 0x00000020 /* 16G FC */
61 #define HBA_PORTSPEED_32GFC 0x00000040 /* 32G FC */
62 #define HBA_PORTSPEED_20GFC 0x00000080 /* 20G FC */
63 #define HBA_PORTSPEED_40GFC 0x00000100 /* 40G FC */
64 #define HBA_PORTSPEED_128GFC 0x00000200 /* 128G FC */
65 #define HBA_PORTSPEED_64GFC 0x00000400 /* 64G FC */
66 #define HBA_PORTSPEED_256GFC 0x00000800 /* 256G FC */
67 #define HBA_PORTSPEED_UNKNOWN 0x00008000 /* Unknown */
68 #define HBA_PORTSPEED_10GE 0x00010000 /* 10G E */
69 #define HBA_PORTSPEED_40GE 0x00020000 /* 40G E */
70 #define HBA_PORTSPEED_100GE 0x00040000 /* 100G E */
71 #define HBA_PORTSPEED_25GE 0x00080000 /* 25G E */
72 #define HBA_PORTSPEED_50GE 0x00100000 /* 50G E */
73 #define HBA_PORTSPEED_400GE 0x00200000 /* 400G E */
78 static char *lpfc_release_version
= LPFC_DRIVER_VERSION
;
81 lpfc_ct_ignore_hbq_buffer(struct lpfc_hba
*phba
, struct lpfc_iocbq
*piocbq
,
82 struct lpfc_dmabuf
*mp
, uint32_t size
)
85 lpfc_printf_log(phba
, KERN_INFO
, LOG_ELS
,
86 "0146 Ignoring unsolicited CT No HBQ "
88 piocbq
->iocb
.ulpStatus
);
90 lpfc_printf_log(phba
, KERN_INFO
, LOG_ELS
,
91 "0145 Ignoring unsolicted CT HBQ Size:%d "
93 size
, piocbq
->iocb
.ulpStatus
);
97 lpfc_ct_unsol_buffer(struct lpfc_hba
*phba
, struct lpfc_iocbq
*piocbq
,
98 struct lpfc_dmabuf
*mp
, uint32_t size
)
100 lpfc_ct_ignore_hbq_buffer(phba
, piocbq
, mp
, size
);
104 lpfc_ct_unsol_event(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
105 struct lpfc_iocbq
*piocbq
)
107 struct lpfc_dmabuf
*mp
= NULL
;
108 IOCB_t
*icmd
= &piocbq
->iocb
;
110 struct lpfc_iocbq
*iocbq
;
113 struct list_head head
;
114 struct lpfc_dmabuf
*bdeBuf
;
116 if (lpfc_bsg_ct_unsol_event(phba
, pring
, piocbq
) == 0)
119 if (unlikely(icmd
->ulpStatus
== IOSTAT_NEED_BUFFER
)) {
120 lpfc_sli_hbqbuf_add_hbqs(phba
, LPFC_ELS_HBQ
);
121 } else if ((icmd
->ulpStatus
== IOSTAT_LOCAL_REJECT
) &&
122 ((icmd
->un
.ulpWord
[4] & IOERR_PARAM_MASK
) ==
123 IOERR_RCV_BUFFER_WAITING
)) {
124 /* Not enough posted buffers; Try posting more buffers */
125 phba
->fc_stat
.NoRcvBuf
++;
126 if (!(phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
))
127 lpfc_post_buffer(phba
, pring
, 2);
131 /* If there are no BDEs associated with this IOCB,
132 * there is nothing to do.
134 if (icmd
->ulpBdeCount
== 0)
137 if (phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
) {
138 INIT_LIST_HEAD(&head
);
139 list_add_tail(&head
, &piocbq
->list
);
140 list_for_each_entry(iocbq
, &head
, list
) {
142 if (icmd
->ulpBdeCount
== 0)
144 bdeBuf
= iocbq
->context2
;
145 iocbq
->context2
= NULL
;
146 size
= icmd
->un
.cont64
[0].tus
.f
.bdeSize
;
147 lpfc_ct_unsol_buffer(phba
, piocbq
, bdeBuf
, size
);
148 lpfc_in_buf_free(phba
, bdeBuf
);
149 if (icmd
->ulpBdeCount
== 2) {
150 bdeBuf
= iocbq
->context3
;
151 iocbq
->context3
= NULL
;
152 size
= icmd
->unsli3
.rcvsli3
.bde2
.tus
.f
.bdeSize
;
153 lpfc_ct_unsol_buffer(phba
, piocbq
, bdeBuf
,
155 lpfc_in_buf_free(phba
, bdeBuf
);
160 INIT_LIST_HEAD(&head
);
161 list_add_tail(&head
, &piocbq
->list
);
162 list_for_each_entry(iocbq
, &head
, list
) {
164 if (icmd
->ulpBdeCount
== 0)
165 lpfc_ct_unsol_buffer(phba
, iocbq
, NULL
, 0);
166 for (i
= 0; i
< icmd
->ulpBdeCount
; i
++) {
167 paddr
= getPaddr(icmd
->un
.cont64
[i
].addrHigh
,
168 icmd
->un
.cont64
[i
].addrLow
);
169 mp
= lpfc_sli_ringpostbuf_get(phba
, pring
,
171 size
= icmd
->un
.cont64
[i
].tus
.f
.bdeSize
;
172 lpfc_ct_unsol_buffer(phba
, iocbq
, mp
, size
);
173 lpfc_in_buf_free(phba
, mp
);
175 lpfc_post_buffer(phba
, pring
, i
);
182 * lpfc_ct_handle_unsol_abort - ct upper level protocol abort handler
183 * @phba: Pointer to HBA context object.
184 * @dmabuf: pointer to a dmabuf that describes the FC sequence
186 * This function serves as the upper level protocol abort handler for CT
189 * Return 1 if abort has been handled, 0 otherwise.
192 lpfc_ct_handle_unsol_abort(struct lpfc_hba
*phba
, struct hbq_dmabuf
*dmabuf
)
196 /* CT upper level goes through BSG */
197 handled
= lpfc_bsg_ct_unsol_abort(phba
, dmabuf
);
203 lpfc_free_ct_rsp(struct lpfc_hba
*phba
, struct lpfc_dmabuf
*mlist
)
205 struct lpfc_dmabuf
*mlast
, *next_mlast
;
207 list_for_each_entry_safe(mlast
, next_mlast
, &mlist
->list
, list
) {
208 lpfc_mbuf_free(phba
, mlast
->virt
, mlast
->phys
);
209 list_del(&mlast
->list
);
212 lpfc_mbuf_free(phba
, mlist
->virt
, mlist
->phys
);
217 static struct lpfc_dmabuf
*
218 lpfc_alloc_ct_rsp(struct lpfc_hba
*phba
, int cmdcode
, struct ulp_bde64
*bpl
,
219 uint32_t size
, int *entries
)
221 struct lpfc_dmabuf
*mlist
= NULL
;
222 struct lpfc_dmabuf
*mp
;
225 /* We get chunks of FCELSSIZE */
226 cnt
= size
> FCELSSIZE
? FCELSSIZE
: size
;
229 /* Allocate buffer for rsp payload */
230 mp
= kmalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
233 lpfc_free_ct_rsp(phba
, mlist
);
237 INIT_LIST_HEAD(&mp
->list
);
239 if (cmdcode
== be16_to_cpu(SLI_CTNS_GID_FT
) ||
240 cmdcode
== be16_to_cpu(SLI_CTNS_GFF_ID
))
241 mp
->virt
= lpfc_mbuf_alloc(phba
, MEM_PRI
, &(mp
->phys
));
243 mp
->virt
= lpfc_mbuf_alloc(phba
, 0, &(mp
->phys
));
248 lpfc_free_ct_rsp(phba
, mlist
);
252 /* Queue it to a linked list */
256 list_add_tail(&mp
->list
, &mlist
->list
);
258 bpl
->tus
.f
.bdeFlags
= BUFF_TYPE_BDE_64I
;
259 /* build buffer ptr list for IOCB */
260 bpl
->addrLow
= le32_to_cpu(putPaddrLow(mp
->phys
) );
261 bpl
->addrHigh
= le32_to_cpu(putPaddrHigh(mp
->phys
) );
262 bpl
->tus
.f
.bdeSize
= (uint16_t) cnt
;
263 bpl
->tus
.w
= le32_to_cpu(bpl
->tus
.w
);
275 lpfc_ct_free_iocb(struct lpfc_hba
*phba
, struct lpfc_iocbq
*ctiocb
)
277 struct lpfc_dmabuf
*buf_ptr
;
279 if (ctiocb
->context_un
.ndlp
) {
280 lpfc_nlp_put(ctiocb
->context_un
.ndlp
);
281 ctiocb
->context_un
.ndlp
= NULL
;
283 if (ctiocb
->context1
) {
284 buf_ptr
= (struct lpfc_dmabuf
*) ctiocb
->context1
;
285 lpfc_mbuf_free(phba
, buf_ptr
->virt
, buf_ptr
->phys
);
287 ctiocb
->context1
= NULL
;
289 if (ctiocb
->context2
) {
290 lpfc_free_ct_rsp(phba
, (struct lpfc_dmabuf
*) ctiocb
->context2
);
291 ctiocb
->context2
= NULL
;
294 if (ctiocb
->context3
) {
295 buf_ptr
= (struct lpfc_dmabuf
*) ctiocb
->context3
;
296 lpfc_mbuf_free(phba
, buf_ptr
->virt
, buf_ptr
->phys
);
298 ctiocb
->context3
= NULL
;
300 lpfc_sli_release_iocbq(phba
, ctiocb
);
305 * lpfc_gen_req - Build and issue a GEN_REQUEST command to the SLI Layer
306 * @vport: pointer to a host virtual N_Port data structure.
307 * @bmp: Pointer to BPL for SLI command
308 * @inp: Pointer to data buffer for response data.
309 * @outp: Pointer to data buffer that hold the CT command.
310 * @cmpl: completion routine to call when command completes
311 * @ndlp: Destination NPort nodelist entry
313 * This function as the final part for issuing a CT command.
316 lpfc_gen_req(struct lpfc_vport
*vport
, struct lpfc_dmabuf
*bmp
,
317 struct lpfc_dmabuf
*inp
, struct lpfc_dmabuf
*outp
,
318 void (*cmpl
) (struct lpfc_hba
*, struct lpfc_iocbq
*,
319 struct lpfc_iocbq
*),
320 struct lpfc_nodelist
*ndlp
, uint32_t usr_flg
, uint32_t num_entry
,
321 uint32_t tmo
, uint8_t retry
)
323 struct lpfc_hba
*phba
= vport
->phba
;
325 struct lpfc_iocbq
*geniocb
;
328 /* Allocate buffer for command iocb */
329 geniocb
= lpfc_sli_get_iocbq(phba
);
334 icmd
= &geniocb
->iocb
;
335 icmd
->un
.genreq64
.bdl
.ulpIoTag32
= 0;
336 icmd
->un
.genreq64
.bdl
.addrHigh
= putPaddrHigh(bmp
->phys
);
337 icmd
->un
.genreq64
.bdl
.addrLow
= putPaddrLow(bmp
->phys
);
338 icmd
->un
.genreq64
.bdl
.bdeFlags
= BUFF_TYPE_BLP_64
;
339 icmd
->un
.genreq64
.bdl
.bdeSize
= (num_entry
* sizeof(struct ulp_bde64
));
342 geniocb
->context3
= NULL
;
344 geniocb
->context3
= (uint8_t *) bmp
;
346 /* Save for completion so we can release these resources */
347 geniocb
->context1
= (uint8_t *) inp
;
348 geniocb
->context2
= (uint8_t *) outp
;
349 geniocb
->context_un
.ndlp
= lpfc_nlp_get(ndlp
);
351 /* Fill in payload, bp points to frame payload */
352 icmd
->ulpCommand
= CMD_GEN_REQUEST64_CR
;
354 /* Fill in rest of iocb */
355 icmd
->un
.genreq64
.w5
.hcsw
.Fctl
= (SI
| LA
);
356 icmd
->un
.genreq64
.w5
.hcsw
.Dfctl
= 0;
357 icmd
->un
.genreq64
.w5
.hcsw
.Rctl
= FC_RCTL_DD_UNSOL_CTL
;
358 icmd
->un
.genreq64
.w5
.hcsw
.Type
= FC_TYPE_CT
;
361 /* FC spec states we need 3 * ratov for CT requests */
362 tmo
= (3 * phba
->fc_ratov
);
364 icmd
->ulpTimeout
= tmo
;
365 icmd
->ulpBdeCount
= 1;
367 icmd
->ulpClass
= CLASS3
;
368 icmd
->ulpContext
= ndlp
->nlp_rpi
;
369 if (phba
->sli_rev
== LPFC_SLI_REV4
)
370 icmd
->ulpContext
= phba
->sli4_hba
.rpi_ids
[ndlp
->nlp_rpi
];
372 if (phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
) {
373 /* For GEN_REQUEST64_CR, use the RPI */
378 /* Issue GEN REQ IOCB for NPORT <did> */
379 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
380 "0119 Issue GEN REQ IOCB to NPORT x%x "
382 ndlp
->nlp_DID
, icmd
->ulpIoTag
,
384 geniocb
->iocb_cmpl
= cmpl
;
385 geniocb
->drvrTimeout
= icmd
->ulpTimeout
+ LPFC_DRVR_TIMEOUT
;
386 geniocb
->vport
= vport
;
387 geniocb
->retry
= retry
;
388 rc
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, geniocb
, 0);
390 if (rc
== IOCB_ERROR
) {
391 lpfc_sli_release_iocbq(phba
, geniocb
);
399 * lpfc_ct_cmd - Build and issue a CT command
400 * @vport: pointer to a host virtual N_Port data structure.
401 * @inmp: Pointer to data buffer for response data.
402 * @bmp: Pointer to BPL for SLI command
403 * @ndlp: Destination NPort nodelist entry
404 * @cmpl: completion routine to call when command completes
406 * This function is called for issuing a CT command.
409 lpfc_ct_cmd(struct lpfc_vport
*vport
, struct lpfc_dmabuf
*inmp
,
410 struct lpfc_dmabuf
*bmp
, struct lpfc_nodelist
*ndlp
,
411 void (*cmpl
) (struct lpfc_hba
*, struct lpfc_iocbq
*,
412 struct lpfc_iocbq
*),
413 uint32_t rsp_size
, uint8_t retry
)
415 struct lpfc_hba
*phba
= vport
->phba
;
416 struct ulp_bde64
*bpl
= (struct ulp_bde64
*) bmp
->virt
;
417 struct lpfc_dmabuf
*outmp
;
419 int cmdcode
= ((struct lpfc_sli_ct_request
*) inmp
->virt
)->
420 CommandResponse
.bits
.CmdRsp
;
422 bpl
++; /* Skip past ct request */
424 /* Put buffer(s) for ct rsp in bpl */
425 outmp
= lpfc_alloc_ct_rsp(phba
, cmdcode
, bpl
, rsp_size
, &cnt
);
429 * Form the CT IOCB. The total number of BDEs in this IOCB
430 * is the single command plus response count from
434 status
= lpfc_gen_req(vport
, bmp
, inmp
, outmp
, cmpl
, ndlp
, 0,
437 lpfc_free_ct_rsp(phba
, outmp
);
444 lpfc_find_vport_by_did(struct lpfc_hba
*phba
, uint32_t did
) {
445 struct lpfc_vport
*vport_curr
;
448 spin_lock_irqsave(&phba
->hbalock
, flags
);
449 list_for_each_entry(vport_curr
, &phba
->port_list
, listentry
) {
450 if ((vport_curr
->fc_myDID
) && (vport_curr
->fc_myDID
== did
)) {
451 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
455 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
460 lpfc_prep_node_fc4type(struct lpfc_vport
*vport
, uint32_t Did
, uint8_t fc4_type
)
462 struct lpfc_nodelist
*ndlp
;
464 if ((vport
->port_type
!= LPFC_NPIV_PORT
) ||
465 !(vport
->ct_flags
& FC_CT_RFF_ID
) || !vport
->cfg_restrict_login
) {
467 ndlp
= lpfc_setup_disc_node(vport
, Did
);
469 if (ndlp
&& NLP_CHK_NODE_ACT(ndlp
)) {
470 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_CT
,
471 "Parse GID_FTrsp: did:x%x flg:x%x x%x",
472 Did
, ndlp
->nlp_flag
, vport
->fc_flag
);
474 ndlp
->nlp_fc4_type
&= ~(NLP_FC4_FCP
| NLP_FC4_NVME
);
475 /* By default, the driver expects to support FCP FC4 */
476 if (fc4_type
== FC_TYPE_FCP
)
477 ndlp
->nlp_fc4_type
|= NLP_FC4_FCP
;
479 if (fc4_type
== FC_TYPE_NVME
)
480 ndlp
->nlp_fc4_type
|= NLP_FC4_NVME
;
482 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
483 "0238 Process x%06x NameServer Rsp "
484 "Data: x%x x%x x%x x%x\n", Did
,
485 ndlp
->nlp_flag
, ndlp
->nlp_fc4_type
,
487 vport
->fc_rscn_id_cnt
);
489 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_CT
,
490 "Skip1 GID_FTrsp: did:x%x flg:x%x cnt:%d",
491 Did
, vport
->fc_flag
, vport
->fc_rscn_id_cnt
);
493 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
494 "0239 Skip x%06x NameServer Rsp "
495 "Data: x%x x%x\n", Did
,
497 vport
->fc_rscn_id_cnt
);
500 if (!(vport
->fc_flag
& FC_RSCN_MODE
) ||
501 lpfc_rscn_payload_check(vport
, Did
)) {
502 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_CT
,
503 "Query GID_FTrsp: did:x%x flg:x%x cnt:%d",
504 Did
, vport
->fc_flag
, vport
->fc_rscn_id_cnt
);
507 * This NPortID was previously a FCP/NVMe target,
508 * Don't even bother to send GFF_ID.
510 ndlp
= lpfc_findnode_did(vport
, Did
);
511 if (ndlp
&& NLP_CHK_NODE_ACT(ndlp
) &&
513 (NLP_FCP_TARGET
| NLP_NVME_TARGET
))) {
514 if (fc4_type
== FC_TYPE_FCP
)
515 ndlp
->nlp_fc4_type
|= NLP_FC4_FCP
;
516 if (fc4_type
== FC_TYPE_NVME
)
517 ndlp
->nlp_fc4_type
|= NLP_FC4_NVME
;
518 lpfc_setup_disc_node(vport
, Did
);
519 } else if (lpfc_ns_cmd(vport
, SLI_CTNS_GFF_ID
,
521 vport
->num_disc_nodes
++;
523 lpfc_setup_disc_node(vport
, Did
);
525 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_CT
,
526 "Skip2 GID_FTrsp: did:x%x flg:x%x cnt:%d",
527 Did
, vport
->fc_flag
, vport
->fc_rscn_id_cnt
);
529 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
530 "0245 Skip x%06x NameServer Rsp "
531 "Data: x%x x%x\n", Did
,
533 vport
->fc_rscn_id_cnt
);
539 lpfc_ns_rsp_audit_did(struct lpfc_vport
*vport
, uint32_t Did
, uint8_t fc4_type
)
541 struct lpfc_hba
*phba
= vport
->phba
;
542 struct lpfc_nodelist
*ndlp
= NULL
;
543 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
546 * To conserve rpi's, filter out addresses for other
547 * vports on the same physical HBAs.
549 if (Did
!= vport
->fc_myDID
&&
550 (!lpfc_find_vport_by_did(phba
, Did
) ||
551 vport
->cfg_peer_port_login
)) {
552 if (!phba
->nvmet_support
) {
553 /* FCPI/NVMEI path. Process Did */
554 lpfc_prep_node_fc4type(vport
, Did
, fc4_type
);
557 /* NVMET path. NVMET only cares about NVMEI nodes. */
558 list_for_each_entry(ndlp
, &vport
->fc_nodes
, nlp_listp
) {
559 if (ndlp
->nlp_type
!= NLP_NVME_INITIATOR
||
560 ndlp
->nlp_state
!= NLP_STE_UNMAPPED_NODE
)
562 spin_lock_irq(shost
->host_lock
);
563 if (ndlp
->nlp_DID
== Did
)
564 ndlp
->nlp_flag
&= ~NLP_NVMET_RECOV
;
566 ndlp
->nlp_flag
|= NLP_NVMET_RECOV
;
567 spin_unlock_irq(shost
->host_lock
);
573 lpfc_ns_rsp(struct lpfc_vport
*vport
, struct lpfc_dmabuf
*mp
, uint8_t fc4_type
,
576 struct lpfc_sli_ct_request
*Response
=
577 (struct lpfc_sli_ct_request
*) mp
->virt
;
578 struct lpfc_dmabuf
*mlast
, *next_mp
;
579 uint32_t *ctptr
= (uint32_t *) & Response
->un
.gid
.PortType
;
580 uint32_t Did
, CTentry
;
582 struct list_head head
;
583 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
584 struct lpfc_nodelist
*ndlp
= NULL
;
586 lpfc_set_disctmo(vport
);
587 vport
->num_disc_nodes
= 0;
588 vport
->fc_ns_retry
= 0;
591 list_add_tail(&head
, &mp
->list
);
592 list_for_each_entry_safe(mp
, next_mp
, &head
, list
) {
595 Cnt
= Size
> FCELSSIZE
? FCELSSIZE
: Size
;
600 ctptr
= (uint32_t *) mlast
->virt
;
602 Cnt
-= 16; /* subtract length of CT header */
604 /* Loop through entire NameServer list of DIDs */
605 while (Cnt
>= sizeof(uint32_t)) {
606 /* Get next DID from NameServer List */
608 Did
= ((be32_to_cpu(CTentry
)) & Mask_DID
);
609 lpfc_ns_rsp_audit_did(vport
, Did
, fc4_type
);
610 if (CTentry
& (cpu_to_be32(SLI_CT_LAST_ENTRY
)))
613 Cnt
-= sizeof(uint32_t);
619 /* All GID_FT entries processed. If the driver is running in
620 * in target mode, put impacted nodes into recovery and drop
621 * the RPI to flush outstanding IO.
623 if (vport
->phba
->nvmet_support
) {
624 list_for_each_entry(ndlp
, &vport
->fc_nodes
, nlp_listp
) {
625 if (!(ndlp
->nlp_flag
& NLP_NVMET_RECOV
))
627 lpfc_disc_state_machine(vport
, ndlp
, NULL
,
628 NLP_EVT_DEVICE_RECOVERY
);
629 spin_lock_irq(shost
->host_lock
);
630 ndlp
->nlp_flag
&= ~NLP_NVMET_RECOV
;
631 spin_unlock_irq(shost
->host_lock
);
641 lpfc_cmpl_ct_cmd_gid_ft(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
642 struct lpfc_iocbq
*rspiocb
)
644 struct lpfc_vport
*vport
= cmdiocb
->vport
;
645 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
647 struct lpfc_dmabuf
*outp
;
648 struct lpfc_dmabuf
*inp
;
649 struct lpfc_sli_ct_request
*CTrsp
;
650 struct lpfc_sli_ct_request
*CTreq
;
651 struct lpfc_nodelist
*ndlp
;
654 /* First save ndlp, before we overwrite it */
655 ndlp
= cmdiocb
->context_un
.ndlp
;
657 /* we pass cmdiocb to state machine which needs rspiocb as well */
658 cmdiocb
->context_un
.rsp_iocb
= rspiocb
;
659 inp
= (struct lpfc_dmabuf
*) cmdiocb
->context1
;
660 outp
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
661 irsp
= &rspiocb
->iocb
;
663 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_CT
,
664 "GID_FT cmpl: status:x%x/x%x rtry:%d",
665 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4], vport
->fc_ns_retry
);
667 /* Don't bother processing response if vport is being torn down. */
668 if (vport
->load_flag
& FC_UNLOADING
) {
669 if (vport
->fc_flag
& FC_RSCN_MODE
)
670 lpfc_els_flush_rscn(vport
);
674 if (lpfc_els_chk_latt(vport
)) {
675 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
676 "0216 Link event during NS query\n");
677 if (vport
->fc_flag
& FC_RSCN_MODE
)
678 lpfc_els_flush_rscn(vport
);
679 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
682 if (lpfc_error_lost_link(irsp
)) {
683 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
684 "0226 NS query failed due to link event\n");
685 if (vport
->fc_flag
& FC_RSCN_MODE
)
686 lpfc_els_flush_rscn(vport
);
690 spin_lock_irq(shost
->host_lock
);
691 if (vport
->fc_flag
& FC_RSCN_DEFERRED
) {
692 vport
->fc_flag
&= ~FC_RSCN_DEFERRED
;
693 spin_unlock_irq(shost
->host_lock
);
696 * Skip processing the NS response
697 * Re-issue the NS cmd
699 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
700 "0151 Process Deferred RSCN Data: x%x x%x\n",
701 vport
->fc_flag
, vport
->fc_rscn_id_cnt
);
702 lpfc_els_handle_rscn(vport
);
706 spin_unlock_irq(shost
->host_lock
);
708 if (irsp
->ulpStatus
) {
709 /* Check for retry */
710 if (vport
->fc_ns_retry
< LPFC_MAX_NS_RETRY
) {
711 if (irsp
->ulpStatus
!= IOSTAT_LOCAL_REJECT
||
712 (irsp
->un
.ulpWord
[4] & IOERR_PARAM_MASK
) !=
714 vport
->fc_ns_retry
++;
716 type
= lpfc_get_gidft_type(vport
, cmdiocb
);
720 /* CT command is being retried */
722 rc
= lpfc_ns_cmd(vport
, SLI_CTNS_GID_FT
,
723 vport
->fc_ns_retry
, type
);
727 if (vport
->fc_flag
& FC_RSCN_MODE
)
728 lpfc_els_flush_rscn(vport
);
729 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
730 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
731 "0257 GID_FT Query error: 0x%x 0x%x\n",
732 irsp
->ulpStatus
, vport
->fc_ns_retry
);
734 /* Good status, continue checking */
735 CTreq
= (struct lpfc_sli_ct_request
*) inp
->virt
;
736 CTrsp
= (struct lpfc_sli_ct_request
*) outp
->virt
;
737 if (CTrsp
->CommandResponse
.bits
.CmdRsp
==
738 cpu_to_be16(SLI_CT_RESPONSE_FS_ACC
)) {
739 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
740 "0208 NameServer Rsp Data: x%x x%x\n",
742 CTreq
->un
.gid
.Fc4Type
);
746 CTreq
->un
.gid
.Fc4Type
,
747 (uint32_t) (irsp
->un
.genreq64
.bdl
.bdeSize
));
748 } else if (CTrsp
->CommandResponse
.bits
.CmdRsp
==
749 be16_to_cpu(SLI_CT_RESPONSE_FS_RJT
)) {
750 /* NameServer Rsp Error */
751 if ((CTrsp
->ReasonCode
== SLI_CT_UNABLE_TO_PERFORM_REQ
)
752 && (CTrsp
->Explanation
== SLI_CT_NO_FC4_TYPES
)) {
753 lpfc_printf_vlog(vport
, KERN_INFO
,
755 "0269 No NameServer Entries "
756 "Data: x%x x%x x%x x%x\n",
757 CTrsp
->CommandResponse
.bits
.CmdRsp
,
758 (uint32_t) CTrsp
->ReasonCode
,
759 (uint32_t) CTrsp
->Explanation
,
762 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_CT
,
763 "GID_FT no entry cmd:x%x rsn:x%x exp:x%x",
764 (uint32_t)CTrsp
->CommandResponse
.bits
.CmdRsp
,
765 (uint32_t) CTrsp
->ReasonCode
,
766 (uint32_t) CTrsp
->Explanation
);
768 lpfc_printf_vlog(vport
, KERN_INFO
,
770 "0240 NameServer Rsp Error "
771 "Data: x%x x%x x%x x%x\n",
772 CTrsp
->CommandResponse
.bits
.CmdRsp
,
773 (uint32_t) CTrsp
->ReasonCode
,
774 (uint32_t) CTrsp
->Explanation
,
777 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_CT
,
778 "GID_FT rsp err1 cmd:x%x rsn:x%x exp:x%x",
779 (uint32_t)CTrsp
->CommandResponse
.bits
.CmdRsp
,
780 (uint32_t) CTrsp
->ReasonCode
,
781 (uint32_t) CTrsp
->Explanation
);
786 /* NameServer Rsp Error */
787 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_DISCOVERY
,
788 "0241 NameServer Rsp Error "
789 "Data: x%x x%x x%x x%x\n",
790 CTrsp
->CommandResponse
.bits
.CmdRsp
,
791 (uint32_t) CTrsp
->ReasonCode
,
792 (uint32_t) CTrsp
->Explanation
,
795 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_CT
,
796 "GID_FT rsp err2 cmd:x%x rsn:x%x exp:x%x",
797 (uint32_t)CTrsp
->CommandResponse
.bits
.CmdRsp
,
798 (uint32_t) CTrsp
->ReasonCode
,
799 (uint32_t) CTrsp
->Explanation
);
803 /* Link up / RSCN discovery */
804 if ((vport
->num_disc_nodes
== 0) &&
805 (vport
->gidft_inp
== 0)) {
807 * The driver has cycled through all Nports in the RSCN payload.
808 * Complete the handling by cleaning up and marking the
809 * current driver state.
811 if (vport
->port_state
>= LPFC_DISC_AUTH
) {
812 if (vport
->fc_flag
& FC_RSCN_MODE
) {
813 lpfc_els_flush_rscn(vport
);
814 spin_lock_irq(shost
->host_lock
);
815 vport
->fc_flag
|= FC_RSCN_MODE
; /* RSCN still */
816 spin_unlock_irq(shost
->host_lock
);
819 lpfc_els_flush_rscn(vport
);
822 lpfc_disc_start(vport
);
825 cmdiocb
->context_un
.ndlp
= ndlp
; /* Now restore ndlp for free */
826 lpfc_ct_free_iocb(phba
, cmdiocb
);
831 lpfc_cmpl_ct_cmd_gff_id(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
832 struct lpfc_iocbq
*rspiocb
)
834 struct lpfc_vport
*vport
= cmdiocb
->vport
;
835 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
836 IOCB_t
*irsp
= &rspiocb
->iocb
;
837 struct lpfc_dmabuf
*inp
= (struct lpfc_dmabuf
*) cmdiocb
->context1
;
838 struct lpfc_dmabuf
*outp
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
839 struct lpfc_sli_ct_request
*CTrsp
;
842 struct lpfc_nodelist
*ndlp
;
844 did
= ((struct lpfc_sli_ct_request
*) inp
->virt
)->un
.gff
.PortId
;
845 did
= be32_to_cpu(did
);
847 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_CT
,
848 "GFF_ID cmpl: status:x%x/x%x did:x%x",
849 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4], did
);
851 if (irsp
->ulpStatus
== IOSTAT_SUCCESS
) {
852 /* Good status, continue checking */
853 CTrsp
= (struct lpfc_sli_ct_request
*) outp
->virt
;
854 fbits
= CTrsp
->un
.gff_acc
.fbits
[FCP_TYPE_FEATURE_OFFSET
];
856 if (CTrsp
->CommandResponse
.bits
.CmdRsp
==
857 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC
)) {
858 if ((fbits
& FC4_FEATURE_INIT
) &&
859 !(fbits
& FC4_FEATURE_TARGET
)) {
860 lpfc_printf_vlog(vport
, KERN_INFO
,
863 "NameServer Rsp Data: (init) "
864 "x%x x%x\n", did
, fbits
,
865 vport
->fc_rscn_id_cnt
);
871 /* Check for retry */
872 if (cmdiocb
->retry
< LPFC_MAX_NS_RETRY
) {
874 if (irsp
->ulpStatus
== IOSTAT_LOCAL_REJECT
) {
875 switch ((irsp
->un
.ulpWord
[4] &
878 case IOERR_NO_RESOURCES
:
879 /* We don't increment the retry
880 * count for this case.
883 case IOERR_LINK_DOWN
:
884 case IOERR_SLI_ABORTED
:
896 /* CT command is being retried */
897 rc
= lpfc_ns_cmd(vport
, SLI_CTNS_GFF_ID
,
898 cmdiocb
->retry
, did
);
901 lpfc_ct_free_iocb(phba
, cmdiocb
);
906 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_DISCOVERY
,
907 "0267 NameServer GFF Rsp "
908 "x%x Error (%d %d) Data: x%x x%x\n",
909 did
, irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
910 vport
->fc_flag
, vport
->fc_rscn_id_cnt
);
913 /* This is a target port, unregistered port, or the GFF_ID failed */
914 ndlp
= lpfc_setup_disc_node(vport
, did
);
915 if (ndlp
&& NLP_CHK_NODE_ACT(ndlp
)) {
916 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
917 "0242 Process x%x GFF "
918 "NameServer Rsp Data: x%x x%x x%x\n",
919 did
, ndlp
->nlp_flag
, vport
->fc_flag
,
920 vport
->fc_rscn_id_cnt
);
922 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
924 "NameServer Rsp Data: x%x x%x\n", did
,
925 vport
->fc_flag
, vport
->fc_rscn_id_cnt
);
928 /* Link up / RSCN discovery */
929 if (vport
->num_disc_nodes
)
930 vport
->num_disc_nodes
--;
931 if (vport
->num_disc_nodes
== 0) {
933 * The driver has cycled through all Nports in the RSCN payload.
934 * Complete the handling by cleaning up and marking the
935 * current driver state.
937 if (vport
->port_state
>= LPFC_DISC_AUTH
) {
938 if (vport
->fc_flag
& FC_RSCN_MODE
) {
939 lpfc_els_flush_rscn(vport
);
940 spin_lock_irq(shost
->host_lock
);
941 vport
->fc_flag
|= FC_RSCN_MODE
; /* RSCN still */
942 spin_unlock_irq(shost
->host_lock
);
945 lpfc_els_flush_rscn(vport
);
947 lpfc_disc_start(vport
);
949 lpfc_ct_free_iocb(phba
, cmdiocb
);
954 lpfc_cmpl_ct_cmd_gft_id(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
955 struct lpfc_iocbq
*rspiocb
)
957 struct lpfc_vport
*vport
= cmdiocb
->vport
;
958 IOCB_t
*irsp
= &rspiocb
->iocb
;
959 struct lpfc_dmabuf
*inp
= (struct lpfc_dmabuf
*)cmdiocb
->context1
;
960 struct lpfc_dmabuf
*outp
= (struct lpfc_dmabuf
*)cmdiocb
->context2
;
961 struct lpfc_sli_ct_request
*CTrsp
;
963 struct lpfc_nodelist
*ndlp
;
964 uint32_t fc4_data_0
, fc4_data_1
;
966 did
= ((struct lpfc_sli_ct_request
*)inp
->virt
)->un
.gft
.PortId
;
967 did
= be32_to_cpu(did
);
969 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_CT
,
970 "GFT_ID cmpl: status:x%x/x%x did:x%x",
971 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4], did
);
973 if (irsp
->ulpStatus
== IOSTAT_SUCCESS
) {
974 /* Good status, continue checking */
975 CTrsp
= (struct lpfc_sli_ct_request
*)outp
->virt
;
976 fc4_data_0
= be32_to_cpu(CTrsp
->un
.gft_acc
.fc4_types
[0]);
977 fc4_data_1
= be32_to_cpu(CTrsp
->un
.gft_acc
.fc4_types
[1]);
978 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
979 "3062 DID x%06x GFT Wd0 x%08x Wd1 x%08x\n",
980 did
, fc4_data_0
, fc4_data_1
);
982 ndlp
= lpfc_findnode_did(vport
, did
);
984 /* The bitmask value for FCP and NVME FCP types is
985 * the same because they are 32 bits distant from
986 * each other in word0 and word0.
988 if (fc4_data_0
& LPFC_FC4_TYPE_BITMASK
)
989 ndlp
->nlp_fc4_type
|= NLP_FC4_FCP
;
990 if (fc4_data_1
& LPFC_FC4_TYPE_BITMASK
)
991 ndlp
->nlp_fc4_type
|= NLP_FC4_NVME
;
992 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
993 "3064 Setting ndlp %p, DID x%06x with "
994 "FC4 x%08x, Data: x%08x x%08x\n",
995 ndlp
, did
, ndlp
->nlp_fc4_type
,
996 FC_TYPE_FCP
, FC_TYPE_NVME
);
997 ndlp
->nlp_prev_state
= NLP_STE_REG_LOGIN_ISSUE
;
999 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_PRLI_ISSUE
);
1000 lpfc_issue_els_prli(vport
, ndlp
, 0);
1003 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_DISCOVERY
,
1004 "3065 GFT_ID failed x%08x\n", irsp
->ulpStatus
);
1006 lpfc_ct_free_iocb(phba
, cmdiocb
);
1010 lpfc_cmpl_ct(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
1011 struct lpfc_iocbq
*rspiocb
)
1013 struct lpfc_vport
*vport
= cmdiocb
->vport
;
1014 struct lpfc_dmabuf
*inp
;
1015 struct lpfc_dmabuf
*outp
;
1017 struct lpfc_sli_ct_request
*CTrsp
;
1018 struct lpfc_nodelist
*ndlp
;
1023 /* First save ndlp, before we overwrite it */
1024 ndlp
= cmdiocb
->context_un
.ndlp
;
1026 /* we pass cmdiocb to state machine which needs rspiocb as well */
1027 cmdiocb
->context_un
.rsp_iocb
= rspiocb
;
1029 inp
= (struct lpfc_dmabuf
*) cmdiocb
->context1
;
1030 outp
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
1031 irsp
= &rspiocb
->iocb
;
1033 cmdcode
= be16_to_cpu(((struct lpfc_sli_ct_request
*) inp
->virt
)->
1034 CommandResponse
.bits
.CmdRsp
);
1035 CTrsp
= (struct lpfc_sli_ct_request
*) outp
->virt
;
1037 latt
= lpfc_els_chk_latt(vport
);
1039 /* RFT request completes status <ulpStatus> CmdRsp <CmdRsp> */
1040 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
1041 "0209 CT Request completes, latt %d, "
1042 "ulpStatus x%x CmdRsp x%x, Context x%x, Tag x%x\n",
1043 latt
, irsp
->ulpStatus
,
1044 CTrsp
->CommandResponse
.bits
.CmdRsp
,
1045 cmdiocb
->iocb
.ulpContext
, cmdiocb
->iocb
.ulpIoTag
);
1047 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_CT
,
1048 "CT cmd cmpl: status:x%x/x%x cmd:x%x",
1049 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4], cmdcode
);
1051 if (irsp
->ulpStatus
) {
1052 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_DISCOVERY
,
1053 "0268 NS cmd x%x Error (x%x x%x)\n",
1054 cmdcode
, irsp
->ulpStatus
, irsp
->un
.ulpWord
[4]);
1056 if ((irsp
->ulpStatus
== IOSTAT_LOCAL_REJECT
) &&
1057 (((irsp
->un
.ulpWord
[4] & IOERR_PARAM_MASK
) ==
1059 ((irsp
->un
.ulpWord
[4] & IOERR_PARAM_MASK
) ==
1060 IOERR_SLI_ABORTED
)))
1063 retry
= cmdiocb
->retry
;
1064 if (retry
>= LPFC_MAX_NS_RETRY
)
1068 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
1069 "0250 Retrying NS cmd %x\n", cmdcode
);
1070 rc
= lpfc_ns_cmd(vport
, cmdcode
, retry
, 0);
1076 cmdiocb
->context_un
.ndlp
= ndlp
; /* Now restore ndlp for free */
1077 lpfc_ct_free_iocb(phba
, cmdiocb
);
1082 lpfc_cmpl_ct_cmd_rft_id(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
1083 struct lpfc_iocbq
*rspiocb
)
1085 IOCB_t
*irsp
= &rspiocb
->iocb
;
1086 struct lpfc_vport
*vport
= cmdiocb
->vport
;
1088 if (irsp
->ulpStatus
== IOSTAT_SUCCESS
) {
1089 struct lpfc_dmabuf
*outp
;
1090 struct lpfc_sli_ct_request
*CTrsp
;
1092 outp
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
1093 CTrsp
= (struct lpfc_sli_ct_request
*) outp
->virt
;
1094 if (CTrsp
->CommandResponse
.bits
.CmdRsp
==
1095 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC
))
1096 vport
->ct_flags
|= FC_CT_RFT_ID
;
1098 lpfc_cmpl_ct(phba
, cmdiocb
, rspiocb
);
1103 lpfc_cmpl_ct_cmd_rnn_id(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
1104 struct lpfc_iocbq
*rspiocb
)
1106 IOCB_t
*irsp
= &rspiocb
->iocb
;
1107 struct lpfc_vport
*vport
= cmdiocb
->vport
;
1109 if (irsp
->ulpStatus
== IOSTAT_SUCCESS
) {
1110 struct lpfc_dmabuf
*outp
;
1111 struct lpfc_sli_ct_request
*CTrsp
;
1113 outp
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
1114 CTrsp
= (struct lpfc_sli_ct_request
*) outp
->virt
;
1115 if (CTrsp
->CommandResponse
.bits
.CmdRsp
==
1116 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC
))
1117 vport
->ct_flags
|= FC_CT_RNN_ID
;
1119 lpfc_cmpl_ct(phba
, cmdiocb
, rspiocb
);
1124 lpfc_cmpl_ct_cmd_rspn_id(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
1125 struct lpfc_iocbq
*rspiocb
)
1127 IOCB_t
*irsp
= &rspiocb
->iocb
;
1128 struct lpfc_vport
*vport
= cmdiocb
->vport
;
1130 if (irsp
->ulpStatus
== IOSTAT_SUCCESS
) {
1131 struct lpfc_dmabuf
*outp
;
1132 struct lpfc_sli_ct_request
*CTrsp
;
1134 outp
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
1135 CTrsp
= (struct lpfc_sli_ct_request
*) outp
->virt
;
1136 if (CTrsp
->CommandResponse
.bits
.CmdRsp
==
1137 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC
))
1138 vport
->ct_flags
|= FC_CT_RSPN_ID
;
1140 lpfc_cmpl_ct(phba
, cmdiocb
, rspiocb
);
1145 lpfc_cmpl_ct_cmd_rsnn_nn(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
1146 struct lpfc_iocbq
*rspiocb
)
1148 IOCB_t
*irsp
= &rspiocb
->iocb
;
1149 struct lpfc_vport
*vport
= cmdiocb
->vport
;
1151 if (irsp
->ulpStatus
== IOSTAT_SUCCESS
) {
1152 struct lpfc_dmabuf
*outp
;
1153 struct lpfc_sli_ct_request
*CTrsp
;
1155 outp
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
1156 CTrsp
= (struct lpfc_sli_ct_request
*) outp
->virt
;
1157 if (CTrsp
->CommandResponse
.bits
.CmdRsp
==
1158 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC
))
1159 vport
->ct_flags
|= FC_CT_RSNN_NN
;
1161 lpfc_cmpl_ct(phba
, cmdiocb
, rspiocb
);
1166 lpfc_cmpl_ct_cmd_da_id(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
1167 struct lpfc_iocbq
*rspiocb
)
1169 struct lpfc_vport
*vport
= cmdiocb
->vport
;
1171 /* even if it fails we will act as though it succeeded. */
1172 vport
->ct_flags
= 0;
1173 lpfc_cmpl_ct(phba
, cmdiocb
, rspiocb
);
1178 lpfc_cmpl_ct_cmd_rff_id(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
1179 struct lpfc_iocbq
*rspiocb
)
1181 IOCB_t
*irsp
= &rspiocb
->iocb
;
1182 struct lpfc_vport
*vport
= cmdiocb
->vport
;
1184 if (irsp
->ulpStatus
== IOSTAT_SUCCESS
) {
1185 struct lpfc_dmabuf
*outp
;
1186 struct lpfc_sli_ct_request
*CTrsp
;
1188 outp
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
1189 CTrsp
= (struct lpfc_sli_ct_request
*) outp
->virt
;
1190 if (CTrsp
->CommandResponse
.bits
.CmdRsp
==
1191 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC
))
1192 vport
->ct_flags
|= FC_CT_RFF_ID
;
1194 lpfc_cmpl_ct(phba
, cmdiocb
, rspiocb
);
1199 * Although the symbolic port name is thought to be an integer
1200 * as of January 18, 2016, leave it as a string until more of
1201 * the record state becomes defined.
1204 lpfc_vport_symbolic_port_name(struct lpfc_vport
*vport
, char *symbol
,
1210 * Use the lpfc board number as the Symbolic Port
1211 * Name object. NPIV is not in play so this integer
1212 * value is sufficient and unique per FC-ID.
1214 n
= snprintf(symbol
, size
, "%d", vport
->phba
->brd_no
);
1220 lpfc_vport_symbolic_node_name(struct lpfc_vport
*vport
, char *symbol
,
1223 char fwrev
[FW_REV_STR_SIZE
];
1226 lpfc_decode_firmware_rev(vport
->phba
, fwrev
, 0);
1228 n
= snprintf(symbol
, size
, "Emulex %s", vport
->phba
->ModelName
);
1232 n
+= snprintf(symbol
+ n
, size
- n
, " FV%s", fwrev
);
1236 n
+= snprintf(symbol
+ n
, size
- n
, " DV%s.",
1237 lpfc_release_version
);
1241 n
+= snprintf(symbol
+ n
, size
- n
, " HN:%s.",
1242 init_utsname()->nodename
);
1246 /* Note :- OS name is "Linux" */
1247 n
+= snprintf(symbol
+ n
, size
- n
, " OS:%s\n",
1248 init_utsname()->sysname
);
1253 lpfc_find_map_node(struct lpfc_vport
*vport
)
1255 struct lpfc_nodelist
*ndlp
, *next_ndlp
;
1256 struct Scsi_Host
*shost
;
1259 shost
= lpfc_shost_from_vport(vport
);
1260 spin_lock_irq(shost
->host_lock
);
1261 list_for_each_entry_safe(ndlp
, next_ndlp
, &vport
->fc_nodes
, nlp_listp
) {
1262 if (ndlp
->nlp_type
& NLP_FABRIC
)
1264 if ((ndlp
->nlp_state
== NLP_STE_MAPPED_NODE
) ||
1265 (ndlp
->nlp_state
== NLP_STE_UNMAPPED_NODE
))
1268 spin_unlock_irq(shost
->host_lock
);
1273 * This routine will return the FC4 Type associated with the CT
1277 lpfc_get_gidft_type(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
)
1279 struct lpfc_sli_ct_request
*CtReq
;
1280 struct lpfc_dmabuf
*mp
;
1283 mp
= cmdiocb
->context1
;
1286 CtReq
= (struct lpfc_sli_ct_request
*)mp
->virt
;
1287 type
= (uint32_t)CtReq
->un
.gid
.Fc4Type
;
1288 if ((type
!= SLI_CTPT_FCP
) && (type
!= SLI_CTPT_NVME
))
1296 * Issue Cmd to NameServer
1301 lpfc_ns_cmd(struct lpfc_vport
*vport
, int cmdcode
,
1302 uint8_t retry
, uint32_t context
)
1304 struct lpfc_nodelist
* ndlp
;
1305 struct lpfc_hba
*phba
= vport
->phba
;
1306 struct lpfc_dmabuf
*mp
, *bmp
;
1307 struct lpfc_sli_ct_request
*CtReq
;
1308 struct ulp_bde64
*bpl
;
1309 void (*cmpl
) (struct lpfc_hba
*, struct lpfc_iocbq
*,
1310 struct lpfc_iocbq
*) = NULL
;
1311 uint32_t rsp_size
= 1024;
1315 ndlp
= lpfc_findnode_did(vport
, NameServer_DID
);
1316 if (!ndlp
|| !NLP_CHK_NODE_ACT(ndlp
)
1317 || ndlp
->nlp_state
!= NLP_STE_UNMAPPED_NODE
) {
1322 /* fill in BDEs for command */
1323 /* Allocate buffer for command payload */
1324 mp
= kmalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
1330 INIT_LIST_HEAD(&mp
->list
);
1331 mp
->virt
= lpfc_mbuf_alloc(phba
, MEM_PRI
, &(mp
->phys
));
1334 goto ns_cmd_free_mp
;
1337 /* Allocate buffer for Buffer ptr list */
1338 bmp
= kmalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
1341 goto ns_cmd_free_mpvirt
;
1344 INIT_LIST_HEAD(&bmp
->list
);
1345 bmp
->virt
= lpfc_mbuf_alloc(phba
, MEM_PRI
, &(bmp
->phys
));
1348 goto ns_cmd_free_bmp
;
1351 /* NameServer Req */
1352 lpfc_printf_vlog(vport
, KERN_INFO
,LOG_DISCOVERY
,
1353 "0236 NameServer Req Data: x%x x%x x%x x%x\n",
1354 cmdcode
, vport
->fc_flag
, vport
->fc_rscn_id_cnt
,
1357 bpl
= (struct ulp_bde64
*) bmp
->virt
;
1358 memset(bpl
, 0, sizeof(struct ulp_bde64
));
1359 bpl
->addrHigh
= le32_to_cpu(putPaddrHigh(mp
->phys
) );
1360 bpl
->addrLow
= le32_to_cpu(putPaddrLow(mp
->phys
) );
1361 bpl
->tus
.f
.bdeFlags
= 0;
1362 if (cmdcode
== SLI_CTNS_GID_FT
)
1363 bpl
->tus
.f
.bdeSize
= GID_REQUEST_SZ
;
1364 else if (cmdcode
== SLI_CTNS_GFF_ID
)
1365 bpl
->tus
.f
.bdeSize
= GFF_REQUEST_SZ
;
1366 else if (cmdcode
== SLI_CTNS_GFT_ID
)
1367 bpl
->tus
.f
.bdeSize
= GFT_REQUEST_SZ
;
1368 else if (cmdcode
== SLI_CTNS_RFT_ID
)
1369 bpl
->tus
.f
.bdeSize
= RFT_REQUEST_SZ
;
1370 else if (cmdcode
== SLI_CTNS_RNN_ID
)
1371 bpl
->tus
.f
.bdeSize
= RNN_REQUEST_SZ
;
1372 else if (cmdcode
== SLI_CTNS_RSPN_ID
)
1373 bpl
->tus
.f
.bdeSize
= RSPN_REQUEST_SZ
;
1374 else if (cmdcode
== SLI_CTNS_RSNN_NN
)
1375 bpl
->tus
.f
.bdeSize
= RSNN_REQUEST_SZ
;
1376 else if (cmdcode
== SLI_CTNS_DA_ID
)
1377 bpl
->tus
.f
.bdeSize
= DA_ID_REQUEST_SZ
;
1378 else if (cmdcode
== SLI_CTNS_RFF_ID
)
1379 bpl
->tus
.f
.bdeSize
= RFF_REQUEST_SZ
;
1381 bpl
->tus
.f
.bdeSize
= 0;
1382 bpl
->tus
.w
= le32_to_cpu(bpl
->tus
.w
);
1384 CtReq
= (struct lpfc_sli_ct_request
*) mp
->virt
;
1385 memset(CtReq
, 0, sizeof(struct lpfc_sli_ct_request
));
1386 CtReq
->RevisionId
.bits
.Revision
= SLI_CT_REVISION
;
1387 CtReq
->RevisionId
.bits
.InId
= 0;
1388 CtReq
->FsType
= SLI_CT_DIRECTORY_SERVICE
;
1389 CtReq
->FsSubType
= SLI_CT_DIRECTORY_NAME_SERVER
;
1390 CtReq
->CommandResponse
.bits
.Size
= 0;
1392 case SLI_CTNS_GID_FT
:
1393 CtReq
->CommandResponse
.bits
.CmdRsp
=
1394 cpu_to_be16(SLI_CTNS_GID_FT
);
1395 CtReq
->un
.gid
.Fc4Type
= context
;
1397 if (vport
->port_state
< LPFC_NS_QRY
)
1398 vport
->port_state
= LPFC_NS_QRY
;
1399 lpfc_set_disctmo(vport
);
1400 cmpl
= lpfc_cmpl_ct_cmd_gid_ft
;
1401 rsp_size
= FC_MAX_NS_RSP
;
1404 case SLI_CTNS_GFF_ID
:
1405 CtReq
->CommandResponse
.bits
.CmdRsp
=
1406 cpu_to_be16(SLI_CTNS_GFF_ID
);
1407 CtReq
->un
.gff
.PortId
= cpu_to_be32(context
);
1408 cmpl
= lpfc_cmpl_ct_cmd_gff_id
;
1411 case SLI_CTNS_GFT_ID
:
1412 CtReq
->CommandResponse
.bits
.CmdRsp
=
1413 cpu_to_be16(SLI_CTNS_GFT_ID
);
1414 CtReq
->un
.gft
.PortId
= cpu_to_be32(context
);
1415 cmpl
= lpfc_cmpl_ct_cmd_gft_id
;
1418 case SLI_CTNS_RFT_ID
:
1419 vport
->ct_flags
&= ~FC_CT_RFT_ID
;
1420 CtReq
->CommandResponse
.bits
.CmdRsp
=
1421 cpu_to_be16(SLI_CTNS_RFT_ID
);
1422 CtReq
->un
.rft
.PortId
= cpu_to_be32(vport
->fc_myDID
);
1424 /* Register FC4 FCP type if enabled. */
1425 if ((phba
->cfg_enable_fc4_type
== LPFC_ENABLE_BOTH
) ||
1426 (phba
->cfg_enable_fc4_type
== LPFC_ENABLE_FCP
))
1427 CtReq
->un
.rft
.fcpReg
= 1;
1429 /* Register NVME type if enabled. Defined LE and swapped.
1430 * rsvd[0] is used as word1 because of the hard-coded
1431 * word0 usage in the ct_request data structure.
1433 if ((phba
->cfg_enable_fc4_type
== LPFC_ENABLE_BOTH
) ||
1434 (phba
->cfg_enable_fc4_type
== LPFC_ENABLE_NVME
))
1435 CtReq
->un
.rft
.rsvd
[0] = cpu_to_be32(0x00000100);
1437 cmpl
= lpfc_cmpl_ct_cmd_rft_id
;
1440 case SLI_CTNS_RNN_ID
:
1441 vport
->ct_flags
&= ~FC_CT_RNN_ID
;
1442 CtReq
->CommandResponse
.bits
.CmdRsp
=
1443 cpu_to_be16(SLI_CTNS_RNN_ID
);
1444 CtReq
->un
.rnn
.PortId
= cpu_to_be32(vport
->fc_myDID
);
1445 memcpy(CtReq
->un
.rnn
.wwnn
, &vport
->fc_nodename
,
1446 sizeof(struct lpfc_name
));
1447 cmpl
= lpfc_cmpl_ct_cmd_rnn_id
;
1450 case SLI_CTNS_RSPN_ID
:
1451 vport
->ct_flags
&= ~FC_CT_RSPN_ID
;
1452 CtReq
->CommandResponse
.bits
.CmdRsp
=
1453 cpu_to_be16(SLI_CTNS_RSPN_ID
);
1454 CtReq
->un
.rspn
.PortId
= cpu_to_be32(vport
->fc_myDID
);
1455 size
= sizeof(CtReq
->un
.rspn
.symbname
);
1456 CtReq
->un
.rspn
.len
=
1457 lpfc_vport_symbolic_port_name(vport
,
1458 CtReq
->un
.rspn
.symbname
, size
);
1459 cmpl
= lpfc_cmpl_ct_cmd_rspn_id
;
1461 case SLI_CTNS_RSNN_NN
:
1462 vport
->ct_flags
&= ~FC_CT_RSNN_NN
;
1463 CtReq
->CommandResponse
.bits
.CmdRsp
=
1464 cpu_to_be16(SLI_CTNS_RSNN_NN
);
1465 memcpy(CtReq
->un
.rsnn
.wwnn
, &vport
->fc_nodename
,
1466 sizeof(struct lpfc_name
));
1467 size
= sizeof(CtReq
->un
.rsnn
.symbname
);
1468 CtReq
->un
.rsnn
.len
=
1469 lpfc_vport_symbolic_node_name(vport
,
1470 CtReq
->un
.rsnn
.symbname
, size
);
1471 cmpl
= lpfc_cmpl_ct_cmd_rsnn_nn
;
1473 case SLI_CTNS_DA_ID
:
1474 /* Implement DA_ID Nameserver request */
1475 CtReq
->CommandResponse
.bits
.CmdRsp
=
1476 cpu_to_be16(SLI_CTNS_DA_ID
);
1477 CtReq
->un
.da_id
.port_id
= cpu_to_be32(vport
->fc_myDID
);
1478 cmpl
= lpfc_cmpl_ct_cmd_da_id
;
1480 case SLI_CTNS_RFF_ID
:
1481 vport
->ct_flags
&= ~FC_CT_RFF_ID
;
1482 CtReq
->CommandResponse
.bits
.CmdRsp
=
1483 cpu_to_be16(SLI_CTNS_RFF_ID
);
1484 CtReq
->un
.rff
.PortId
= cpu_to_be32(vport
->fc_myDID
);
1485 CtReq
->un
.rff
.fbits
= FC4_FEATURE_INIT
;
1487 /* The driver always supports FC_TYPE_FCP. However, the
1488 * caller can specify NVME (type x28) as well. But only
1489 * these that FC4 type is supported.
1491 if (((phba
->cfg_enable_fc4_type
== LPFC_ENABLE_BOTH
) ||
1492 (phba
->cfg_enable_fc4_type
== LPFC_ENABLE_NVME
)) &&
1493 (context
== FC_TYPE_NVME
)) {
1494 if ((vport
== phba
->pport
) && phba
->nvmet_support
) {
1495 CtReq
->un
.rff
.fbits
= (FC4_FEATURE_TARGET
|
1496 FC4_FEATURE_NVME_DISC
);
1497 lpfc_nvmet_update_targetport(phba
);
1499 lpfc_nvme_update_localport(vport
);
1501 CtReq
->un
.rff
.type_code
= context
;
1503 } else if (((phba
->cfg_enable_fc4_type
== LPFC_ENABLE_BOTH
) ||
1504 (phba
->cfg_enable_fc4_type
== LPFC_ENABLE_FCP
)) &&
1505 (context
== FC_TYPE_FCP
))
1506 CtReq
->un
.rff
.type_code
= context
;
1509 goto ns_cmd_free_bmpvirt
;
1511 cmpl
= lpfc_cmpl_ct_cmd_rff_id
;
1514 /* The lpfc_ct_cmd/lpfc_get_req shall increment ndlp reference count
1515 * to hold ndlp reference for the corresponding callback function.
1517 if (!lpfc_ct_cmd(vport
, mp
, bmp
, ndlp
, cmpl
, rsp_size
, retry
)) {
1518 /* On success, The cmpl function will free the buffers */
1519 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_CT
,
1520 "Issue CT cmd: cmd:x%x did:x%x",
1521 cmdcode
, ndlp
->nlp_DID
, 0);
1526 /* Decrement ndlp reference count to release ndlp reference held
1527 * for the failed command's callback function.
1531 ns_cmd_free_bmpvirt
:
1532 lpfc_mbuf_free(phba
, bmp
->virt
, bmp
->phys
);
1536 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
1540 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_DISCOVERY
,
1541 "0266 Issue NameServer Req x%x err %d Data: x%x x%x\n",
1542 cmdcode
, rc
, vport
->fc_flag
, vport
->fc_rscn_id_cnt
);
1547 * lpfc_cmpl_ct_disc_fdmi - Handle a discovery FDMI completion
1548 * @phba: Pointer to HBA context object.
1549 * @cmdiocb: Pointer to the command IOCBQ.
1550 * @rspiocb: Pointer to the response IOCBQ.
1552 * This function to handle the completion of a driver initiated FDMI
1553 * CT command issued during discovery.
1556 lpfc_cmpl_ct_disc_fdmi(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
1557 struct lpfc_iocbq
*rspiocb
)
1559 struct lpfc_vport
*vport
= cmdiocb
->vport
;
1560 struct lpfc_dmabuf
*inp
= cmdiocb
->context1
;
1561 struct lpfc_dmabuf
*outp
= cmdiocb
->context2
;
1562 struct lpfc_sli_ct_request
*CTcmd
= inp
->virt
;
1563 struct lpfc_sli_ct_request
*CTrsp
= outp
->virt
;
1564 uint16_t fdmi_cmd
= CTcmd
->CommandResponse
.bits
.CmdRsp
;
1565 uint16_t fdmi_rsp
= CTrsp
->CommandResponse
.bits
.CmdRsp
;
1566 IOCB_t
*irsp
= &rspiocb
->iocb
;
1567 struct lpfc_nodelist
*ndlp
;
1568 uint32_t latt
, cmd
, err
;
1570 latt
= lpfc_els_chk_latt(vport
);
1571 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_CT
,
1572 "FDMI cmpl: status:x%x/x%x latt:%d",
1573 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4], latt
);
1575 if (latt
|| irsp
->ulpStatus
) {
1577 /* Look for a retryable error */
1578 if (irsp
->ulpStatus
== IOSTAT_LOCAL_REJECT
) {
1579 switch ((irsp
->un
.ulpWord
[4] & IOERR_PARAM_MASK
)) {
1580 case IOERR_SLI_ABORTED
:
1581 case IOERR_ABORT_IN_PROGRESS
:
1582 case IOERR_SEQUENCE_TIMEOUT
:
1583 case IOERR_ILLEGAL_FRAME
:
1584 case IOERR_NO_RESOURCES
:
1585 case IOERR_ILLEGAL_COMMAND
:
1587 if (cmdiocb
->retry
>= LPFC_FDMI_MAX_RETRY
)
1590 /* Retry the same FDMI command */
1591 err
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
,
1593 if (err
== IOCB_ERROR
)
1601 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
1602 "0229 FDMI cmd %04x failed, latt = %d "
1603 "ulpStatus: x%x, rid x%x\n",
1604 be16_to_cpu(fdmi_cmd
), latt
, irsp
->ulpStatus
,
1605 irsp
->un
.ulpWord
[4]);
1607 lpfc_ct_free_iocb(phba
, cmdiocb
);
1609 ndlp
= lpfc_findnode_did(vport
, FDMI_DID
);
1610 if (!ndlp
|| !NLP_CHK_NODE_ACT(ndlp
))
1613 /* Check for a CT LS_RJT response */
1614 cmd
= be16_to_cpu(fdmi_cmd
);
1615 if (fdmi_rsp
== cpu_to_be16(SLI_CT_RESPONSE_FS_RJT
)) {
1616 /* FDMI rsp failed */
1617 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
1618 "0220 FDMI cmd failed FS_RJT Data: x%x", cmd
);
1620 /* Should we fallback to FDMI-2 / FDMI-1 ? */
1623 if (vport
->fdmi_hba_mask
== LPFC_FDMI2_HBA_ATTR
) {
1624 /* Fallback to FDMI-1 */
1625 vport
->fdmi_hba_mask
= LPFC_FDMI1_HBA_ATTR
;
1626 vport
->fdmi_port_mask
= LPFC_FDMI1_PORT_ATTR
;
1628 lpfc_fdmi_cmd(vport
, ndlp
, SLI_MGMT_DHBA
, 0);
1633 if (vport
->fdmi_port_mask
== LPFC_FDMI2_PORT_ATTR
) {
1634 /* Fallback to FDMI-1 */
1635 vport
->fdmi_port_mask
= LPFC_FDMI1_PORT_ATTR
;
1637 lpfc_fdmi_cmd(vport
, ndlp
, cmd
, 0);
1639 if (vport
->fdmi_port_mask
== LPFC_FDMI2_SMART_ATTR
) {
1640 vport
->fdmi_port_mask
= LPFC_FDMI2_PORT_ATTR
;
1641 /* Retry the same command */
1642 lpfc_fdmi_cmd(vport
, ndlp
, cmd
, 0);
1647 if (vport
->fdmi_port_mask
== LPFC_FDMI2_PORT_ATTR
) {
1648 /* Fallback to FDMI-1 */
1649 vport
->fdmi_hba_mask
= LPFC_FDMI1_HBA_ATTR
;
1650 vport
->fdmi_port_mask
= LPFC_FDMI1_PORT_ATTR
;
1652 lpfc_fdmi_cmd(vport
, ndlp
, SLI_MGMT_DHBA
, 0);
1654 if (vport
->fdmi_port_mask
== LPFC_FDMI2_SMART_ATTR
) {
1655 vport
->fdmi_port_mask
= LPFC_FDMI2_PORT_ATTR
;
1656 /* Retry the same command */
1657 lpfc_fdmi_cmd(vport
, ndlp
, cmd
, 0);
1664 * On success, need to cycle thru FDMI registration for discovery
1665 * DHBA -> DPRT -> RHBA -> RPA (physical port)
1666 * DPRT -> RPRT (vports)
1670 lpfc_fdmi_cmd(vport
, ndlp
, SLI_MGMT_RPA
, 0);
1674 lpfc_fdmi_cmd(vport
, ndlp
, SLI_MGMT_DPRT
, 0);
1678 if (vport
->port_type
== LPFC_PHYSICAL_PORT
)
1679 lpfc_fdmi_cmd(vport
, ndlp
, SLI_MGMT_RHBA
, 0);
1681 lpfc_fdmi_cmd(vport
, ndlp
, SLI_MGMT_RPRT
, 0);
1689 * lpfc_fdmi_num_disc_check - Check how many mapped NPorts we are connected to
1690 * @vport: pointer to a host virtual N_Port data structure.
1692 * Called from hbeat timeout routine to check if the number of discovered
1693 * ports has changed. If so, re-register thar port Attribute.
1696 lpfc_fdmi_num_disc_check(struct lpfc_vport
*vport
)
1698 struct lpfc_hba
*phba
= vport
->phba
;
1699 struct lpfc_nodelist
*ndlp
;
1702 if (!lpfc_is_link_up(phba
))
1705 /* Must be connected to a Fabric */
1706 if (!(vport
->fc_flag
& FC_FABRIC
))
1709 if (!(vport
->fdmi_port_mask
& LPFC_FDMI_PORT_ATTR_num_disc
))
1712 cnt
= lpfc_find_map_node(vport
);
1713 if (cnt
== vport
->fdmi_num_disc
)
1716 ndlp
= lpfc_findnode_did(vport
, FDMI_DID
);
1717 if (!ndlp
|| !NLP_CHK_NODE_ACT(ndlp
))
1720 if (vport
->port_type
== LPFC_PHYSICAL_PORT
) {
1721 lpfc_fdmi_cmd(vport
, ndlp
, SLI_MGMT_RPA
,
1722 LPFC_FDMI_PORT_ATTR_num_disc
);
1724 lpfc_fdmi_cmd(vport
, ndlp
, SLI_MGMT_RPRT
,
1725 LPFC_FDMI_PORT_ATTR_num_disc
);
1729 /* Routines for all individual HBA attributes */
1731 lpfc_fdmi_hba_attr_wwnn(struct lpfc_vport
*vport
, struct lpfc_fdmi_attr_def
*ad
)
1733 struct lpfc_fdmi_attr_entry
*ae
;
1736 ae
= (struct lpfc_fdmi_attr_entry
*)&ad
->AttrValue
;
1737 memset(ae
, 0, sizeof(struct lpfc_name
));
1739 memcpy(&ae
->un
.AttrWWN
, &vport
->fc_sparam
.nodeName
,
1740 sizeof(struct lpfc_name
));
1741 size
= FOURBYTES
+ sizeof(struct lpfc_name
);
1742 ad
->AttrLen
= cpu_to_be16(size
);
1743 ad
->AttrType
= cpu_to_be16(RHBA_NODENAME
);
1747 lpfc_fdmi_hba_attr_manufacturer(struct lpfc_vport
*vport
,
1748 struct lpfc_fdmi_attr_def
*ad
)
1750 struct lpfc_fdmi_attr_entry
*ae
;
1753 ae
= (struct lpfc_fdmi_attr_entry
*)&ad
->AttrValue
;
1756 strncpy(ae
->un
.AttrString
,
1757 "Emulex Corporation",
1758 sizeof(ae
->un
.AttrString
));
1759 len
= strnlen(ae
->un
.AttrString
,
1760 sizeof(ae
->un
.AttrString
));
1761 len
+= (len
& 3) ? (4 - (len
& 3)) : 4;
1762 size
= FOURBYTES
+ len
;
1763 ad
->AttrLen
= cpu_to_be16(size
);
1764 ad
->AttrType
= cpu_to_be16(RHBA_MANUFACTURER
);
1769 lpfc_fdmi_hba_attr_sn(struct lpfc_vport
*vport
, struct lpfc_fdmi_attr_def
*ad
)
1771 struct lpfc_hba
*phba
= vport
->phba
;
1772 struct lpfc_fdmi_attr_entry
*ae
;
1775 ae
= (struct lpfc_fdmi_attr_entry
*)&ad
->AttrValue
;
1778 strncpy(ae
->un
.AttrString
, phba
->SerialNumber
,
1779 sizeof(ae
->un
.AttrString
));
1780 len
= strnlen(ae
->un
.AttrString
,
1781 sizeof(ae
->un
.AttrString
));
1782 len
+= (len
& 3) ? (4 - (len
& 3)) : 4;
1783 size
= FOURBYTES
+ len
;
1784 ad
->AttrLen
= cpu_to_be16(size
);
1785 ad
->AttrType
= cpu_to_be16(RHBA_SERIAL_NUMBER
);
1790 lpfc_fdmi_hba_attr_model(struct lpfc_vport
*vport
,
1791 struct lpfc_fdmi_attr_def
*ad
)
1793 struct lpfc_hba
*phba
= vport
->phba
;
1794 struct lpfc_fdmi_attr_entry
*ae
;
1797 ae
= (struct lpfc_fdmi_attr_entry
*)&ad
->AttrValue
;
1800 strncpy(ae
->un
.AttrString
, phba
->ModelName
,
1801 sizeof(ae
->un
.AttrString
));
1802 len
= strnlen(ae
->un
.AttrString
, sizeof(ae
->un
.AttrString
));
1803 len
+= (len
& 3) ? (4 - (len
& 3)) : 4;
1804 size
= FOURBYTES
+ len
;
1805 ad
->AttrLen
= cpu_to_be16(size
);
1806 ad
->AttrType
= cpu_to_be16(RHBA_MODEL
);
1811 lpfc_fdmi_hba_attr_description(struct lpfc_vport
*vport
,
1812 struct lpfc_fdmi_attr_def
*ad
)
1814 struct lpfc_hba
*phba
= vport
->phba
;
1815 struct lpfc_fdmi_attr_entry
*ae
;
1818 ae
= (struct lpfc_fdmi_attr_entry
*)&ad
->AttrValue
;
1821 strncpy(ae
->un
.AttrString
, phba
->ModelDesc
,
1822 sizeof(ae
->un
.AttrString
));
1823 len
= strnlen(ae
->un
.AttrString
,
1824 sizeof(ae
->un
.AttrString
));
1825 len
+= (len
& 3) ? (4 - (len
& 3)) : 4;
1826 size
= FOURBYTES
+ len
;
1827 ad
->AttrLen
= cpu_to_be16(size
);
1828 ad
->AttrType
= cpu_to_be16(RHBA_MODEL_DESCRIPTION
);
1833 lpfc_fdmi_hba_attr_hdw_ver(struct lpfc_vport
*vport
,
1834 struct lpfc_fdmi_attr_def
*ad
)
1836 struct lpfc_hba
*phba
= vport
->phba
;
1837 lpfc_vpd_t
*vp
= &phba
->vpd
;
1838 struct lpfc_fdmi_attr_entry
*ae
;
1839 uint32_t i
, j
, incr
, size
;
1841 ae
= (struct lpfc_fdmi_attr_entry
*)&ad
->AttrValue
;
1844 /* Convert JEDEC ID to ascii for hardware version */
1845 incr
= vp
->rev
.biuRev
;
1846 for (i
= 0; i
< 8; i
++) {
1849 ae
->un
.AttrString
[7 - i
] =
1850 (char)((uint8_t) 0x30 +
1853 ae
->un
.AttrString
[7 - i
] =
1854 (char)((uint8_t) 0x61 +
1855 (uint8_t) (j
- 10));
1858 size
= FOURBYTES
+ 8;
1859 ad
->AttrLen
= cpu_to_be16(size
);
1860 ad
->AttrType
= cpu_to_be16(RHBA_HARDWARE_VERSION
);
1865 lpfc_fdmi_hba_attr_drvr_ver(struct lpfc_vport
*vport
,
1866 struct lpfc_fdmi_attr_def
*ad
)
1868 struct lpfc_fdmi_attr_entry
*ae
;
1871 ae
= (struct lpfc_fdmi_attr_entry
*)&ad
->AttrValue
;
1874 strncpy(ae
->un
.AttrString
, lpfc_release_version
,
1875 sizeof(ae
->un
.AttrString
));
1876 len
= strnlen(ae
->un
.AttrString
,
1877 sizeof(ae
->un
.AttrString
));
1878 len
+= (len
& 3) ? (4 - (len
& 3)) : 4;
1879 size
= FOURBYTES
+ len
;
1880 ad
->AttrLen
= cpu_to_be16(size
);
1881 ad
->AttrType
= cpu_to_be16(RHBA_DRIVER_VERSION
);
1886 lpfc_fdmi_hba_attr_rom_ver(struct lpfc_vport
*vport
,
1887 struct lpfc_fdmi_attr_def
*ad
)
1889 struct lpfc_hba
*phba
= vport
->phba
;
1890 struct lpfc_fdmi_attr_entry
*ae
;
1893 ae
= (struct lpfc_fdmi_attr_entry
*)&ad
->AttrValue
;
1896 if (phba
->sli_rev
== LPFC_SLI_REV4
)
1897 lpfc_decode_firmware_rev(phba
, ae
->un
.AttrString
, 1);
1899 strncpy(ae
->un
.AttrString
, phba
->OptionROMVersion
,
1900 sizeof(ae
->un
.AttrString
));
1901 len
= strnlen(ae
->un
.AttrString
,
1902 sizeof(ae
->un
.AttrString
));
1903 len
+= (len
& 3) ? (4 - (len
& 3)) : 4;
1904 size
= FOURBYTES
+ len
;
1905 ad
->AttrLen
= cpu_to_be16(size
);
1906 ad
->AttrType
= cpu_to_be16(RHBA_OPTION_ROM_VERSION
);
1911 lpfc_fdmi_hba_attr_fmw_ver(struct lpfc_vport
*vport
,
1912 struct lpfc_fdmi_attr_def
*ad
)
1914 struct lpfc_hba
*phba
= vport
->phba
;
1915 struct lpfc_fdmi_attr_entry
*ae
;
1918 ae
= (struct lpfc_fdmi_attr_entry
*)&ad
->AttrValue
;
1921 lpfc_decode_firmware_rev(phba
, ae
->un
.AttrString
, 1);
1922 len
= strnlen(ae
->un
.AttrString
,
1923 sizeof(ae
->un
.AttrString
));
1924 len
+= (len
& 3) ? (4 - (len
& 3)) : 4;
1925 size
= FOURBYTES
+ len
;
1926 ad
->AttrLen
= cpu_to_be16(size
);
1927 ad
->AttrType
= cpu_to_be16(RHBA_FIRMWARE_VERSION
);
1932 lpfc_fdmi_hba_attr_os_ver(struct lpfc_vport
*vport
,
1933 struct lpfc_fdmi_attr_def
*ad
)
1935 struct lpfc_fdmi_attr_entry
*ae
;
1938 ae
= (struct lpfc_fdmi_attr_entry
*)&ad
->AttrValue
;
1941 snprintf(ae
->un
.AttrString
, sizeof(ae
->un
.AttrString
), "%s %s %s",
1942 init_utsname()->sysname
,
1943 init_utsname()->release
,
1944 init_utsname()->version
);
1946 len
= strnlen(ae
->un
.AttrString
, sizeof(ae
->un
.AttrString
));
1947 len
+= (len
& 3) ? (4 - (len
& 3)) : 4;
1948 size
= FOURBYTES
+ len
;
1949 ad
->AttrLen
= cpu_to_be16(size
);
1950 ad
->AttrType
= cpu_to_be16(RHBA_OS_NAME_VERSION
);
1955 lpfc_fdmi_hba_attr_ct_len(struct lpfc_vport
*vport
,
1956 struct lpfc_fdmi_attr_def
*ad
)
1958 struct lpfc_fdmi_attr_entry
*ae
;
1961 ae
= (struct lpfc_fdmi_attr_entry
*)&ad
->AttrValue
;
1963 ae
->un
.AttrInt
= cpu_to_be32(LPFC_MAX_CT_SIZE
);
1964 size
= FOURBYTES
+ sizeof(uint32_t);
1965 ad
->AttrLen
= cpu_to_be16(size
);
1966 ad
->AttrType
= cpu_to_be16(RHBA_MAX_CT_PAYLOAD_LEN
);
1971 lpfc_fdmi_hba_attr_symbolic_name(struct lpfc_vport
*vport
,
1972 struct lpfc_fdmi_attr_def
*ad
)
1974 struct lpfc_fdmi_attr_entry
*ae
;
1977 ae
= (struct lpfc_fdmi_attr_entry
*)&ad
->AttrValue
;
1980 len
= lpfc_vport_symbolic_node_name(vport
,
1981 ae
->un
.AttrString
, 256);
1982 len
+= (len
& 3) ? (4 - (len
& 3)) : 4;
1983 size
= FOURBYTES
+ len
;
1984 ad
->AttrLen
= cpu_to_be16(size
);
1985 ad
->AttrType
= cpu_to_be16(RHBA_SYM_NODENAME
);
1990 lpfc_fdmi_hba_attr_vendor_info(struct lpfc_vport
*vport
,
1991 struct lpfc_fdmi_attr_def
*ad
)
1993 struct lpfc_fdmi_attr_entry
*ae
;
1996 ae
= (struct lpfc_fdmi_attr_entry
*)&ad
->AttrValue
;
1998 /* Nothing is defined for this currently */
1999 ae
->un
.AttrInt
= cpu_to_be32(0);
2000 size
= FOURBYTES
+ sizeof(uint32_t);
2001 ad
->AttrLen
= cpu_to_be16(size
);
2002 ad
->AttrType
= cpu_to_be16(RHBA_VENDOR_INFO
);
2007 lpfc_fdmi_hba_attr_num_ports(struct lpfc_vport
*vport
,
2008 struct lpfc_fdmi_attr_def
*ad
)
2010 struct lpfc_fdmi_attr_entry
*ae
;
2013 ae
= (struct lpfc_fdmi_attr_entry
*)&ad
->AttrValue
;
2015 /* Each driver instance corresponds to a single port */
2016 ae
->un
.AttrInt
= cpu_to_be32(1);
2017 size
= FOURBYTES
+ sizeof(uint32_t);
2018 ad
->AttrLen
= cpu_to_be16(size
);
2019 ad
->AttrType
= cpu_to_be16(RHBA_NUM_PORTS
);
2024 lpfc_fdmi_hba_attr_fabric_wwnn(struct lpfc_vport
*vport
,
2025 struct lpfc_fdmi_attr_def
*ad
)
2027 struct lpfc_fdmi_attr_entry
*ae
;
2030 ae
= (struct lpfc_fdmi_attr_entry
*)&ad
->AttrValue
;
2031 memset(ae
, 0, sizeof(struct lpfc_name
));
2033 memcpy(&ae
->un
.AttrWWN
, &vport
->fabric_nodename
,
2034 sizeof(struct lpfc_name
));
2035 size
= FOURBYTES
+ sizeof(struct lpfc_name
);
2036 ad
->AttrLen
= cpu_to_be16(size
);
2037 ad
->AttrType
= cpu_to_be16(RHBA_FABRIC_WWNN
);
2042 lpfc_fdmi_hba_attr_bios_ver(struct lpfc_vport
*vport
,
2043 struct lpfc_fdmi_attr_def
*ad
)
2045 struct lpfc_hba
*phba
= vport
->phba
;
2046 struct lpfc_fdmi_attr_entry
*ae
;
2049 ae
= (struct lpfc_fdmi_attr_entry
*)&ad
->AttrValue
;
2052 lpfc_decode_firmware_rev(phba
, ae
->un
.AttrString
, 1);
2053 len
= strnlen(ae
->un
.AttrString
,
2054 sizeof(ae
->un
.AttrString
));
2055 len
+= (len
& 3) ? (4 - (len
& 3)) : 4;
2056 size
= FOURBYTES
+ len
;
2057 ad
->AttrLen
= cpu_to_be16(size
);
2058 ad
->AttrType
= cpu_to_be16(RHBA_BIOS_VERSION
);
2063 lpfc_fdmi_hba_attr_bios_state(struct lpfc_vport
*vport
,
2064 struct lpfc_fdmi_attr_def
*ad
)
2066 struct lpfc_fdmi_attr_entry
*ae
;
2069 ae
= (struct lpfc_fdmi_attr_entry
*)&ad
->AttrValue
;
2071 /* Driver doesn't have access to this information */
2072 ae
->un
.AttrInt
= cpu_to_be32(0);
2073 size
= FOURBYTES
+ sizeof(uint32_t);
2074 ad
->AttrLen
= cpu_to_be16(size
);
2075 ad
->AttrType
= cpu_to_be16(RHBA_BIOS_STATE
);
2080 lpfc_fdmi_hba_attr_vendor_id(struct lpfc_vport
*vport
,
2081 struct lpfc_fdmi_attr_def
*ad
)
2083 struct lpfc_fdmi_attr_entry
*ae
;
2086 ae
= (struct lpfc_fdmi_attr_entry
*)&ad
->AttrValue
;
2089 strncpy(ae
->un
.AttrString
, "EMULEX",
2090 sizeof(ae
->un
.AttrString
));
2091 len
= strnlen(ae
->un
.AttrString
,
2092 sizeof(ae
->un
.AttrString
));
2093 len
+= (len
& 3) ? (4 - (len
& 3)) : 4;
2094 size
= FOURBYTES
+ len
;
2095 ad
->AttrLen
= cpu_to_be16(size
);
2096 ad
->AttrType
= cpu_to_be16(RHBA_VENDOR_ID
);
2100 /* Routines for all individual PORT attributes */
2102 lpfc_fdmi_port_attr_fc4type(struct lpfc_vport
*vport
,
2103 struct lpfc_fdmi_attr_def
*ad
)
2105 struct lpfc_fdmi_attr_entry
*ae
;
2108 ae
= (struct lpfc_fdmi_attr_entry
*)&ad
->AttrValue
;
2111 ae
->un
.AttrTypes
[3] = 0x02; /* Type 1 - ELS */
2112 ae
->un
.AttrTypes
[2] = 0x01; /* Type 8 - FCP */
2113 ae
->un
.AttrTypes
[6] = 0x01; /* Type 40 - NVME */
2114 ae
->un
.AttrTypes
[7] = 0x01; /* Type 32 - CT */
2115 size
= FOURBYTES
+ 32;
2116 ad
->AttrLen
= cpu_to_be16(size
);
2117 ad
->AttrType
= cpu_to_be16(RPRT_SUPPORTED_FC4_TYPES
);
2122 lpfc_fdmi_port_attr_support_speed(struct lpfc_vport
*vport
,
2123 struct lpfc_fdmi_attr_def
*ad
)
2125 struct lpfc_hba
*phba
= vport
->phba
;
2126 struct lpfc_fdmi_attr_entry
*ae
;
2129 ae
= (struct lpfc_fdmi_attr_entry
*)&ad
->AttrValue
;
2132 if (!(phba
->hba_flag
& HBA_FCOE_MODE
)) {
2133 if (phba
->lmt
& LMT_32Gb
)
2134 ae
->un
.AttrInt
|= HBA_PORTSPEED_32GFC
;
2135 if (phba
->lmt
& LMT_16Gb
)
2136 ae
->un
.AttrInt
|= HBA_PORTSPEED_16GFC
;
2137 if (phba
->lmt
& LMT_10Gb
)
2138 ae
->un
.AttrInt
|= HBA_PORTSPEED_10GFC
;
2139 if (phba
->lmt
& LMT_8Gb
)
2140 ae
->un
.AttrInt
|= HBA_PORTSPEED_8GFC
;
2141 if (phba
->lmt
& LMT_4Gb
)
2142 ae
->un
.AttrInt
|= HBA_PORTSPEED_4GFC
;
2143 if (phba
->lmt
& LMT_2Gb
)
2144 ae
->un
.AttrInt
|= HBA_PORTSPEED_2GFC
;
2145 if (phba
->lmt
& LMT_1Gb
)
2146 ae
->un
.AttrInt
|= HBA_PORTSPEED_1GFC
;
2148 /* FCoE links support only one speed */
2149 switch (phba
->fc_linkspeed
) {
2150 case LPFC_ASYNC_LINK_SPEED_10GBPS
:
2151 ae
->un
.AttrInt
= HBA_PORTSPEED_10GE
;
2153 case LPFC_ASYNC_LINK_SPEED_25GBPS
:
2154 ae
->un
.AttrInt
= HBA_PORTSPEED_25GE
;
2156 case LPFC_ASYNC_LINK_SPEED_40GBPS
:
2157 ae
->un
.AttrInt
= HBA_PORTSPEED_40GE
;
2159 case LPFC_ASYNC_LINK_SPEED_100GBPS
:
2160 ae
->un
.AttrInt
= HBA_PORTSPEED_100GE
;
2164 ae
->un
.AttrInt
= cpu_to_be32(ae
->un
.AttrInt
);
2165 size
= FOURBYTES
+ sizeof(uint32_t);
2166 ad
->AttrLen
= cpu_to_be16(size
);
2167 ad
->AttrType
= cpu_to_be16(RPRT_SUPPORTED_SPEED
);
2172 lpfc_fdmi_port_attr_speed(struct lpfc_vport
*vport
,
2173 struct lpfc_fdmi_attr_def
*ad
)
2175 struct lpfc_hba
*phba
= vport
->phba
;
2176 struct lpfc_fdmi_attr_entry
*ae
;
2179 ae
= (struct lpfc_fdmi_attr_entry
*)&ad
->AttrValue
;
2181 if (!(phba
->hba_flag
& HBA_FCOE_MODE
)) {
2182 switch (phba
->fc_linkspeed
) {
2183 case LPFC_LINK_SPEED_1GHZ
:
2184 ae
->un
.AttrInt
= HBA_PORTSPEED_1GFC
;
2186 case LPFC_LINK_SPEED_2GHZ
:
2187 ae
->un
.AttrInt
= HBA_PORTSPEED_2GFC
;
2189 case LPFC_LINK_SPEED_4GHZ
:
2190 ae
->un
.AttrInt
= HBA_PORTSPEED_4GFC
;
2192 case LPFC_LINK_SPEED_8GHZ
:
2193 ae
->un
.AttrInt
= HBA_PORTSPEED_8GFC
;
2195 case LPFC_LINK_SPEED_10GHZ
:
2196 ae
->un
.AttrInt
= HBA_PORTSPEED_10GFC
;
2198 case LPFC_LINK_SPEED_16GHZ
:
2199 ae
->un
.AttrInt
= HBA_PORTSPEED_16GFC
;
2201 case LPFC_LINK_SPEED_32GHZ
:
2202 ae
->un
.AttrInt
= HBA_PORTSPEED_32GFC
;
2205 ae
->un
.AttrInt
= HBA_PORTSPEED_UNKNOWN
;
2209 switch (phba
->fc_linkspeed
) {
2210 case LPFC_ASYNC_LINK_SPEED_10GBPS
:
2211 ae
->un
.AttrInt
= HBA_PORTSPEED_10GE
;
2213 case LPFC_ASYNC_LINK_SPEED_25GBPS
:
2214 ae
->un
.AttrInt
= HBA_PORTSPEED_25GE
;
2216 case LPFC_ASYNC_LINK_SPEED_40GBPS
:
2217 ae
->un
.AttrInt
= HBA_PORTSPEED_40GE
;
2219 case LPFC_ASYNC_LINK_SPEED_100GBPS
:
2220 ae
->un
.AttrInt
= HBA_PORTSPEED_100GE
;
2223 ae
->un
.AttrInt
= HBA_PORTSPEED_UNKNOWN
;
2228 ae
->un
.AttrInt
= cpu_to_be32(ae
->un
.AttrInt
);
2229 size
= FOURBYTES
+ sizeof(uint32_t);
2230 ad
->AttrLen
= cpu_to_be16(size
);
2231 ad
->AttrType
= cpu_to_be16(RPRT_PORT_SPEED
);
2236 lpfc_fdmi_port_attr_max_frame(struct lpfc_vport
*vport
,
2237 struct lpfc_fdmi_attr_def
*ad
)
2239 struct serv_parm
*hsp
;
2240 struct lpfc_fdmi_attr_entry
*ae
;
2243 ae
= (struct lpfc_fdmi_attr_entry
*)&ad
->AttrValue
;
2245 hsp
= (struct serv_parm
*)&vport
->fc_sparam
;
2246 ae
->un
.AttrInt
= (((uint32_t) hsp
->cmn
.bbRcvSizeMsb
) << 8) |
2247 (uint32_t) hsp
->cmn
.bbRcvSizeLsb
;
2248 ae
->un
.AttrInt
= cpu_to_be32(ae
->un
.AttrInt
);
2249 size
= FOURBYTES
+ sizeof(uint32_t);
2250 ad
->AttrLen
= cpu_to_be16(size
);
2251 ad
->AttrType
= cpu_to_be16(RPRT_MAX_FRAME_SIZE
);
2256 lpfc_fdmi_port_attr_os_devname(struct lpfc_vport
*vport
,
2257 struct lpfc_fdmi_attr_def
*ad
)
2259 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2260 struct lpfc_fdmi_attr_entry
*ae
;
2263 ae
= (struct lpfc_fdmi_attr_entry
*)&ad
->AttrValue
;
2266 snprintf(ae
->un
.AttrString
, sizeof(ae
->un
.AttrString
),
2267 "/sys/class/scsi_host/host%d", shost
->host_no
);
2268 len
= strnlen((char *)ae
->un
.AttrString
,
2269 sizeof(ae
->un
.AttrString
));
2270 len
+= (len
& 3) ? (4 - (len
& 3)) : 4;
2271 size
= FOURBYTES
+ len
;
2272 ad
->AttrLen
= cpu_to_be16(size
);
2273 ad
->AttrType
= cpu_to_be16(RPRT_OS_DEVICE_NAME
);
2278 lpfc_fdmi_port_attr_host_name(struct lpfc_vport
*vport
,
2279 struct lpfc_fdmi_attr_def
*ad
)
2281 struct lpfc_fdmi_attr_entry
*ae
;
2284 ae
= (struct lpfc_fdmi_attr_entry
*)&ad
->AttrValue
;
2287 snprintf(ae
->un
.AttrString
, sizeof(ae
->un
.AttrString
), "%s",
2288 init_utsname()->nodename
);
2290 len
= strnlen(ae
->un
.AttrString
, sizeof(ae
->un
.AttrString
));
2291 len
+= (len
& 3) ? (4 - (len
& 3)) : 4;
2292 size
= FOURBYTES
+ len
;
2293 ad
->AttrLen
= cpu_to_be16(size
);
2294 ad
->AttrType
= cpu_to_be16(RPRT_HOST_NAME
);
2299 lpfc_fdmi_port_attr_wwnn(struct lpfc_vport
*vport
,
2300 struct lpfc_fdmi_attr_def
*ad
)
2302 struct lpfc_fdmi_attr_entry
*ae
;
2305 ae
= (struct lpfc_fdmi_attr_entry
*)&ad
->AttrValue
;
2306 memset(ae
, 0, sizeof(struct lpfc_name
));
2308 memcpy(&ae
->un
.AttrWWN
, &vport
->fc_sparam
.nodeName
,
2309 sizeof(struct lpfc_name
));
2310 size
= FOURBYTES
+ sizeof(struct lpfc_name
);
2311 ad
->AttrLen
= cpu_to_be16(size
);
2312 ad
->AttrType
= cpu_to_be16(RPRT_NODENAME
);
2317 lpfc_fdmi_port_attr_wwpn(struct lpfc_vport
*vport
,
2318 struct lpfc_fdmi_attr_def
*ad
)
2320 struct lpfc_fdmi_attr_entry
*ae
;
2323 ae
= (struct lpfc_fdmi_attr_entry
*)&ad
->AttrValue
;
2324 memset(ae
, 0, sizeof(struct lpfc_name
));
2326 memcpy(&ae
->un
.AttrWWN
, &vport
->fc_sparam
.portName
,
2327 sizeof(struct lpfc_name
));
2328 size
= FOURBYTES
+ sizeof(struct lpfc_name
);
2329 ad
->AttrLen
= cpu_to_be16(size
);
2330 ad
->AttrType
= cpu_to_be16(RPRT_PORTNAME
);
2335 lpfc_fdmi_port_attr_symbolic_name(struct lpfc_vport
*vport
,
2336 struct lpfc_fdmi_attr_def
*ad
)
2338 struct lpfc_fdmi_attr_entry
*ae
;
2341 ae
= (struct lpfc_fdmi_attr_entry
*)&ad
->AttrValue
;
2344 len
= lpfc_vport_symbolic_port_name(vport
, ae
->un
.AttrString
, 256);
2345 len
+= (len
& 3) ? (4 - (len
& 3)) : 4;
2346 size
= FOURBYTES
+ len
;
2347 ad
->AttrLen
= cpu_to_be16(size
);
2348 ad
->AttrType
= cpu_to_be16(RPRT_SYM_PORTNAME
);
2353 lpfc_fdmi_port_attr_port_type(struct lpfc_vport
*vport
,
2354 struct lpfc_fdmi_attr_def
*ad
)
2356 struct lpfc_hba
*phba
= vport
->phba
;
2357 struct lpfc_fdmi_attr_entry
*ae
;
2360 ae
= (struct lpfc_fdmi_attr_entry
*)&ad
->AttrValue
;
2361 if (phba
->fc_topology
== LPFC_TOPOLOGY_LOOP
)
2362 ae
->un
.AttrInt
= cpu_to_be32(LPFC_FDMI_PORTTYPE_NLPORT
);
2364 ae
->un
.AttrInt
= cpu_to_be32(LPFC_FDMI_PORTTYPE_NPORT
);
2365 size
= FOURBYTES
+ sizeof(uint32_t);
2366 ad
->AttrLen
= cpu_to_be16(size
);
2367 ad
->AttrType
= cpu_to_be16(RPRT_PORT_TYPE
);
2372 lpfc_fdmi_port_attr_class(struct lpfc_vport
*vport
,
2373 struct lpfc_fdmi_attr_def
*ad
)
2375 struct lpfc_fdmi_attr_entry
*ae
;
2378 ae
= (struct lpfc_fdmi_attr_entry
*)&ad
->AttrValue
;
2379 ae
->un
.AttrInt
= cpu_to_be32(FC_COS_CLASS2
| FC_COS_CLASS3
);
2380 size
= FOURBYTES
+ sizeof(uint32_t);
2381 ad
->AttrLen
= cpu_to_be16(size
);
2382 ad
->AttrType
= cpu_to_be16(RPRT_SUPPORTED_CLASS
);
2387 lpfc_fdmi_port_attr_fabric_wwpn(struct lpfc_vport
*vport
,
2388 struct lpfc_fdmi_attr_def
*ad
)
2390 struct lpfc_fdmi_attr_entry
*ae
;
2393 ae
= (struct lpfc_fdmi_attr_entry
*)&ad
->AttrValue
;
2394 memset(ae
, 0, sizeof(struct lpfc_name
));
2396 memcpy(&ae
->un
.AttrWWN
, &vport
->fabric_portname
,
2397 sizeof(struct lpfc_name
));
2398 size
= FOURBYTES
+ sizeof(struct lpfc_name
);
2399 ad
->AttrLen
= cpu_to_be16(size
);
2400 ad
->AttrType
= cpu_to_be16(RPRT_FABRICNAME
);
2405 lpfc_fdmi_port_attr_active_fc4type(struct lpfc_vport
*vport
,
2406 struct lpfc_fdmi_attr_def
*ad
)
2408 struct lpfc_fdmi_attr_entry
*ae
;
2411 ae
= (struct lpfc_fdmi_attr_entry
*)&ad
->AttrValue
;
2414 ae
->un
.AttrTypes
[3] = 0x02; /* Type 1 - ELS */
2415 ae
->un
.AttrTypes
[2] = 0x01; /* Type 8 - FCP */
2416 ae
->un
.AttrTypes
[7] = 0x01; /* Type 32 - CT */
2417 size
= FOURBYTES
+ 32;
2418 ad
->AttrLen
= cpu_to_be16(size
);
2419 ad
->AttrType
= cpu_to_be16(RPRT_ACTIVE_FC4_TYPES
);
2424 lpfc_fdmi_port_attr_port_state(struct lpfc_vport
*vport
,
2425 struct lpfc_fdmi_attr_def
*ad
)
2427 struct lpfc_fdmi_attr_entry
*ae
;
2430 ae
= (struct lpfc_fdmi_attr_entry
*)&ad
->AttrValue
;
2431 /* Link Up - operational */
2432 ae
->un
.AttrInt
= cpu_to_be32(LPFC_FDMI_PORTSTATE_ONLINE
);
2433 size
= FOURBYTES
+ sizeof(uint32_t);
2434 ad
->AttrLen
= cpu_to_be16(size
);
2435 ad
->AttrType
= cpu_to_be16(RPRT_PORT_STATE
);
2440 lpfc_fdmi_port_attr_num_disc(struct lpfc_vport
*vport
,
2441 struct lpfc_fdmi_attr_def
*ad
)
2443 struct lpfc_fdmi_attr_entry
*ae
;
2446 ae
= (struct lpfc_fdmi_attr_entry
*)&ad
->AttrValue
;
2447 vport
->fdmi_num_disc
= lpfc_find_map_node(vport
);
2448 ae
->un
.AttrInt
= cpu_to_be32(vport
->fdmi_num_disc
);
2449 size
= FOURBYTES
+ sizeof(uint32_t);
2450 ad
->AttrLen
= cpu_to_be16(size
);
2451 ad
->AttrType
= cpu_to_be16(RPRT_DISC_PORT
);
2456 lpfc_fdmi_port_attr_nportid(struct lpfc_vport
*vport
,
2457 struct lpfc_fdmi_attr_def
*ad
)
2459 struct lpfc_fdmi_attr_entry
*ae
;
2462 ae
= (struct lpfc_fdmi_attr_entry
*)&ad
->AttrValue
;
2463 ae
->un
.AttrInt
= cpu_to_be32(vport
->fc_myDID
);
2464 size
= FOURBYTES
+ sizeof(uint32_t);
2465 ad
->AttrLen
= cpu_to_be16(size
);
2466 ad
->AttrType
= cpu_to_be16(RPRT_PORT_ID
);
2471 lpfc_fdmi_smart_attr_service(struct lpfc_vport
*vport
,
2472 struct lpfc_fdmi_attr_def
*ad
)
2474 struct lpfc_fdmi_attr_entry
*ae
;
2477 ae
= (struct lpfc_fdmi_attr_entry
*)&ad
->AttrValue
;
2480 strncpy(ae
->un
.AttrString
, "Smart SAN Initiator",
2481 sizeof(ae
->un
.AttrString
));
2482 len
= strnlen(ae
->un
.AttrString
,
2483 sizeof(ae
->un
.AttrString
));
2484 len
+= (len
& 3) ? (4 - (len
& 3)) : 4;
2485 size
= FOURBYTES
+ len
;
2486 ad
->AttrLen
= cpu_to_be16(size
);
2487 ad
->AttrType
= cpu_to_be16(RPRT_SMART_SERVICE
);
2492 lpfc_fdmi_smart_attr_guid(struct lpfc_vport
*vport
,
2493 struct lpfc_fdmi_attr_def
*ad
)
2495 struct lpfc_fdmi_attr_entry
*ae
;
2498 ae
= (struct lpfc_fdmi_attr_entry
*)&ad
->AttrValue
;
2501 memcpy(&ae
->un
.AttrString
, &vport
->fc_sparam
.nodeName
,
2502 sizeof(struct lpfc_name
));
2503 memcpy((((uint8_t *)&ae
->un
.AttrString
) +
2504 sizeof(struct lpfc_name
)),
2505 &vport
->fc_sparam
.portName
, sizeof(struct lpfc_name
));
2506 size
= FOURBYTES
+ (2 * sizeof(struct lpfc_name
));
2507 ad
->AttrLen
= cpu_to_be16(size
);
2508 ad
->AttrType
= cpu_to_be16(RPRT_SMART_GUID
);
2513 lpfc_fdmi_smart_attr_version(struct lpfc_vport
*vport
,
2514 struct lpfc_fdmi_attr_def
*ad
)
2516 struct lpfc_fdmi_attr_entry
*ae
;
2519 ae
= (struct lpfc_fdmi_attr_entry
*)&ad
->AttrValue
;
2522 strncpy(ae
->un
.AttrString
, "Smart SAN Version 2.0",
2523 sizeof(ae
->un
.AttrString
));
2524 len
= strnlen(ae
->un
.AttrString
,
2525 sizeof(ae
->un
.AttrString
));
2526 len
+= (len
& 3) ? (4 - (len
& 3)) : 4;
2527 size
= FOURBYTES
+ len
;
2528 ad
->AttrLen
= cpu_to_be16(size
);
2529 ad
->AttrType
= cpu_to_be16(RPRT_SMART_VERSION
);
2534 lpfc_fdmi_smart_attr_model(struct lpfc_vport
*vport
,
2535 struct lpfc_fdmi_attr_def
*ad
)
2537 struct lpfc_hba
*phba
= vport
->phba
;
2538 struct lpfc_fdmi_attr_entry
*ae
;
2541 ae
= (struct lpfc_fdmi_attr_entry
*)&ad
->AttrValue
;
2544 strncpy(ae
->un
.AttrString
, phba
->ModelName
,
2545 sizeof(ae
->un
.AttrString
));
2546 len
= strnlen(ae
->un
.AttrString
, sizeof(ae
->un
.AttrString
));
2547 len
+= (len
& 3) ? (4 - (len
& 3)) : 4;
2548 size
= FOURBYTES
+ len
;
2549 ad
->AttrLen
= cpu_to_be16(size
);
2550 ad
->AttrType
= cpu_to_be16(RPRT_SMART_MODEL
);
2555 lpfc_fdmi_smart_attr_port_info(struct lpfc_vport
*vport
,
2556 struct lpfc_fdmi_attr_def
*ad
)
2558 struct lpfc_fdmi_attr_entry
*ae
;
2561 ae
= (struct lpfc_fdmi_attr_entry
*)&ad
->AttrValue
;
2563 /* SRIOV (type 3) is not supported */
2565 ae
->un
.AttrInt
= cpu_to_be32(2); /* NPIV */
2567 ae
->un
.AttrInt
= cpu_to_be32(1); /* Physical */
2568 size
= FOURBYTES
+ sizeof(uint32_t);
2569 ad
->AttrLen
= cpu_to_be16(size
);
2570 ad
->AttrType
= cpu_to_be16(RPRT_SMART_PORT_INFO
);
2575 lpfc_fdmi_smart_attr_qos(struct lpfc_vport
*vport
,
2576 struct lpfc_fdmi_attr_def
*ad
)
2578 struct lpfc_fdmi_attr_entry
*ae
;
2581 ae
= (struct lpfc_fdmi_attr_entry
*)&ad
->AttrValue
;
2582 ae
->un
.AttrInt
= cpu_to_be32(0);
2583 size
= FOURBYTES
+ sizeof(uint32_t);
2584 ad
->AttrLen
= cpu_to_be16(size
);
2585 ad
->AttrType
= cpu_to_be16(RPRT_SMART_QOS
);
2590 lpfc_fdmi_smart_attr_security(struct lpfc_vport
*vport
,
2591 struct lpfc_fdmi_attr_def
*ad
)
2593 struct lpfc_fdmi_attr_entry
*ae
;
2596 ae
= (struct lpfc_fdmi_attr_entry
*)&ad
->AttrValue
;
2597 ae
->un
.AttrInt
= cpu_to_be32(1);
2598 size
= FOURBYTES
+ sizeof(uint32_t);
2599 ad
->AttrLen
= cpu_to_be16(size
);
2600 ad
->AttrType
= cpu_to_be16(RPRT_SMART_SECURITY
);
2604 /* RHBA attribute jump table */
2605 int (*lpfc_fdmi_hba_action
[])
2606 (struct lpfc_vport
*vport
, struct lpfc_fdmi_attr_def
*ad
) = {
2607 /* Action routine Mask bit Attribute type */
2608 lpfc_fdmi_hba_attr_wwnn
, /* bit0 RHBA_NODENAME */
2609 lpfc_fdmi_hba_attr_manufacturer
, /* bit1 RHBA_MANUFACTURER */
2610 lpfc_fdmi_hba_attr_sn
, /* bit2 RHBA_SERIAL_NUMBER */
2611 lpfc_fdmi_hba_attr_model
, /* bit3 RHBA_MODEL */
2612 lpfc_fdmi_hba_attr_description
, /* bit4 RHBA_MODEL_DESCRIPTION */
2613 lpfc_fdmi_hba_attr_hdw_ver
, /* bit5 RHBA_HARDWARE_VERSION */
2614 lpfc_fdmi_hba_attr_drvr_ver
, /* bit6 RHBA_DRIVER_VERSION */
2615 lpfc_fdmi_hba_attr_rom_ver
, /* bit7 RHBA_OPTION_ROM_VERSION */
2616 lpfc_fdmi_hba_attr_fmw_ver
, /* bit8 RHBA_FIRMWARE_VERSION */
2617 lpfc_fdmi_hba_attr_os_ver
, /* bit9 RHBA_OS_NAME_VERSION */
2618 lpfc_fdmi_hba_attr_ct_len
, /* bit10 RHBA_MAX_CT_PAYLOAD_LEN */
2619 lpfc_fdmi_hba_attr_symbolic_name
, /* bit11 RHBA_SYM_NODENAME */
2620 lpfc_fdmi_hba_attr_vendor_info
, /* bit12 RHBA_VENDOR_INFO */
2621 lpfc_fdmi_hba_attr_num_ports
, /* bit13 RHBA_NUM_PORTS */
2622 lpfc_fdmi_hba_attr_fabric_wwnn
, /* bit14 RHBA_FABRIC_WWNN */
2623 lpfc_fdmi_hba_attr_bios_ver
, /* bit15 RHBA_BIOS_VERSION */
2624 lpfc_fdmi_hba_attr_bios_state
, /* bit16 RHBA_BIOS_STATE */
2625 lpfc_fdmi_hba_attr_vendor_id
, /* bit17 RHBA_VENDOR_ID */
2628 /* RPA / RPRT attribute jump table */
2629 int (*lpfc_fdmi_port_action
[])
2630 (struct lpfc_vport
*vport
, struct lpfc_fdmi_attr_def
*ad
) = {
2631 /* Action routine Mask bit Attribute type */
2632 lpfc_fdmi_port_attr_fc4type
, /* bit0 RPRT_SUPPORT_FC4_TYPES */
2633 lpfc_fdmi_port_attr_support_speed
, /* bit1 RPRT_SUPPORTED_SPEED */
2634 lpfc_fdmi_port_attr_speed
, /* bit2 RPRT_PORT_SPEED */
2635 lpfc_fdmi_port_attr_max_frame
, /* bit3 RPRT_MAX_FRAME_SIZE */
2636 lpfc_fdmi_port_attr_os_devname
, /* bit4 RPRT_OS_DEVICE_NAME */
2637 lpfc_fdmi_port_attr_host_name
, /* bit5 RPRT_HOST_NAME */
2638 lpfc_fdmi_port_attr_wwnn
, /* bit6 RPRT_NODENAME */
2639 lpfc_fdmi_port_attr_wwpn
, /* bit7 RPRT_PORTNAME */
2640 lpfc_fdmi_port_attr_symbolic_name
, /* bit8 RPRT_SYM_PORTNAME */
2641 lpfc_fdmi_port_attr_port_type
, /* bit9 RPRT_PORT_TYPE */
2642 lpfc_fdmi_port_attr_class
, /* bit10 RPRT_SUPPORTED_CLASS */
2643 lpfc_fdmi_port_attr_fabric_wwpn
, /* bit11 RPRT_FABRICNAME */
2644 lpfc_fdmi_port_attr_active_fc4type
, /* bit12 RPRT_ACTIVE_FC4_TYPES */
2645 lpfc_fdmi_port_attr_port_state
, /* bit13 RPRT_PORT_STATE */
2646 lpfc_fdmi_port_attr_num_disc
, /* bit14 RPRT_DISC_PORT */
2647 lpfc_fdmi_port_attr_nportid
, /* bit15 RPRT_PORT_ID */
2648 lpfc_fdmi_smart_attr_service
, /* bit16 RPRT_SMART_SERVICE */
2649 lpfc_fdmi_smart_attr_guid
, /* bit17 RPRT_SMART_GUID */
2650 lpfc_fdmi_smart_attr_version
, /* bit18 RPRT_SMART_VERSION */
2651 lpfc_fdmi_smart_attr_model
, /* bit19 RPRT_SMART_MODEL */
2652 lpfc_fdmi_smart_attr_port_info
, /* bit20 RPRT_SMART_PORT_INFO */
2653 lpfc_fdmi_smart_attr_qos
, /* bit21 RPRT_SMART_QOS */
2654 lpfc_fdmi_smart_attr_security
, /* bit22 RPRT_SMART_SECURITY */
2658 * lpfc_fdmi_cmd - Build and send a FDMI cmd to the specified NPort
2659 * @vport: pointer to a host virtual N_Port data structure.
2660 * @ndlp: ndlp to send FDMI cmd to (if NULL use FDMI_DID)
2661 * cmdcode: FDMI command to send
2662 * mask: Mask of HBA or PORT Attributes to send
2664 * Builds and sends a FDMI command using the CT subsystem.
2667 lpfc_fdmi_cmd(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2668 int cmdcode
, uint32_t new_mask
)
2670 struct lpfc_hba
*phba
= vport
->phba
;
2671 struct lpfc_dmabuf
*mp
, *bmp
;
2672 struct lpfc_sli_ct_request
*CtReq
;
2673 struct ulp_bde64
*bpl
;
2678 struct lpfc_fdmi_reg_hba
*rh
;
2679 struct lpfc_fdmi_port_entry
*pe
;
2680 struct lpfc_fdmi_reg_portattr
*pab
= NULL
;
2681 struct lpfc_fdmi_attr_block
*ab
= NULL
;
2682 int (*func
)(struct lpfc_vport
*vport
, struct lpfc_fdmi_attr_def
*ad
);
2683 void (*cmpl
)(struct lpfc_hba
*, struct lpfc_iocbq
*,
2684 struct lpfc_iocbq
*);
2686 if (!ndlp
|| !NLP_CHK_NODE_ACT(ndlp
))
2689 cmpl
= lpfc_cmpl_ct_disc_fdmi
; /* called from discovery */
2691 /* fill in BDEs for command */
2692 /* Allocate buffer for command payload */
2693 mp
= kmalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
2697 mp
->virt
= lpfc_mbuf_alloc(phba
, 0, &(mp
->phys
));
2699 goto fdmi_cmd_free_mp
;
2701 /* Allocate buffer for Buffer ptr list */
2702 bmp
= kmalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
2704 goto fdmi_cmd_free_mpvirt
;
2706 bmp
->virt
= lpfc_mbuf_alloc(phba
, 0, &(bmp
->phys
));
2708 goto fdmi_cmd_free_bmp
;
2710 INIT_LIST_HEAD(&mp
->list
);
2711 INIT_LIST_HEAD(&bmp
->list
);
2714 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
2715 "0218 FDMI Request Data: x%x x%x x%x\n",
2716 vport
->fc_flag
, vport
->port_state
, cmdcode
);
2717 CtReq
= (struct lpfc_sli_ct_request
*)mp
->virt
;
2719 /* First populate the CT_IU preamble */
2720 memset(CtReq
, 0, sizeof(struct lpfc_sli_ct_request
));
2721 CtReq
->RevisionId
.bits
.Revision
= SLI_CT_REVISION
;
2722 CtReq
->RevisionId
.bits
.InId
= 0;
2724 CtReq
->FsType
= SLI_CT_MANAGEMENT_SERVICE
;
2725 CtReq
->FsSubType
= SLI_CT_FDMI_Subtypes
;
2727 CtReq
->CommandResponse
.bits
.CmdRsp
= cpu_to_be16(cmdcode
);
2728 rsp_size
= LPFC_BPL_SIZE
;
2731 /* Next fill in the specific FDMI cmd information */
2735 rh
= (struct lpfc_fdmi_reg_hba
*)&CtReq
->un
.PortID
;
2736 /* HBA Identifier */
2737 memcpy(&rh
->hi
.PortName
, &phba
->pport
->fc_sparam
.portName
,
2738 sizeof(struct lpfc_name
));
2740 if (cmdcode
== SLI_MGMT_RHBA
) {
2741 /* Registered Port List */
2742 /* One entry (port) per adapter */
2743 rh
->rpl
.EntryCnt
= cpu_to_be32(1);
2744 memcpy(&rh
->rpl
.pe
, &phba
->pport
->fc_sparam
.portName
,
2745 sizeof(struct lpfc_name
));
2747 /* point to the HBA attribute block */
2748 size
= 2 * sizeof(struct lpfc_name
) +
2751 size
= sizeof(struct lpfc_name
);
2753 ab
= (struct lpfc_fdmi_attr_block
*)((uint8_t *)rh
+ size
);
2760 mask
= vport
->fdmi_hba_mask
;
2762 /* Mask will dictate what attributes to build in the request */
2765 func
= lpfc_fdmi_hba_action
[bit_pos
];
2767 (struct lpfc_fdmi_attr_def
*)
2768 ((uint8_t *)rh
+ size
));
2771 (LPFC_BPL_SIZE
- LPFC_CT_PREAMBLE
))
2778 ab
->EntryCnt
= cpu_to_be32(ab
->EntryCnt
);
2780 size
= GID_REQUEST_SZ
- 4 + size
;
2785 pab
= (struct lpfc_fdmi_reg_portattr
*)&CtReq
->un
.PortID
;
2786 if (cmdcode
== SLI_MGMT_RPRT
) {
2787 rh
= (struct lpfc_fdmi_reg_hba
*)pab
;
2788 /* HBA Identifier */
2789 memcpy(&rh
->hi
.PortName
,
2790 &phba
->pport
->fc_sparam
.portName
,
2791 sizeof(struct lpfc_name
));
2792 pab
= (struct lpfc_fdmi_reg_portattr
*)
2793 ((uint8_t *)pab
+ sizeof(struct lpfc_name
));
2796 memcpy((uint8_t *)&pab
->PortName
,
2797 (uint8_t *)&vport
->fc_sparam
.portName
,
2798 sizeof(struct lpfc_name
));
2799 size
+= sizeof(struct lpfc_name
) + FOURBYTES
;
2800 pab
->ab
.EntryCnt
= 0;
2805 mask
= vport
->fdmi_port_mask
;
2807 /* Mask will dictate what attributes to build in the request */
2810 func
= lpfc_fdmi_port_action
[bit_pos
];
2812 (struct lpfc_fdmi_attr_def
*)
2813 ((uint8_t *)pab
+ size
));
2816 (LPFC_BPL_SIZE
- LPFC_CT_PREAMBLE
))
2823 pab
->ab
.EntryCnt
= cpu_to_be32(pab
->ab
.EntryCnt
);
2825 if (cmdcode
== SLI_MGMT_RPRT
)
2826 size
+= sizeof(struct lpfc_name
);
2827 size
= GID_REQUEST_SZ
- 4 + size
;
2832 rsp_size
= FC_MAX_NS_RSP
;
2835 pe
= (struct lpfc_fdmi_port_entry
*)&CtReq
->un
.PortID
;
2836 memcpy((uint8_t *)&pe
->PortName
,
2837 (uint8_t *)&vport
->fc_sparam
.portName
,
2838 sizeof(struct lpfc_name
));
2839 size
= GID_REQUEST_SZ
- 4 + sizeof(struct lpfc_name
);
2844 rsp_size
= FC_MAX_NS_RSP
;
2847 pe
= (struct lpfc_fdmi_port_entry
*)&CtReq
->un
.PortID
;
2848 memcpy((uint8_t *)&pe
->PortName
,
2849 (uint8_t *)&vport
->fc_sparam
.portName
,
2850 sizeof(struct lpfc_name
));
2851 size
= GID_REQUEST_SZ
- 4 + sizeof(struct lpfc_name
);
2854 size
= GID_REQUEST_SZ
- 4;
2857 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_DISCOVERY
,
2858 "0298 FDMI cmdcode x%x not supported\n",
2860 goto fdmi_cmd_free_bmpvirt
;
2862 CtReq
->CommandResponse
.bits
.Size
= cpu_to_be16(rsp_size
);
2864 bpl
= (struct ulp_bde64
*)bmp
->virt
;
2865 bpl
->addrHigh
= le32_to_cpu(putPaddrHigh(mp
->phys
));
2866 bpl
->addrLow
= le32_to_cpu(putPaddrLow(mp
->phys
));
2867 bpl
->tus
.f
.bdeFlags
= 0;
2868 bpl
->tus
.f
.bdeSize
= size
;
2871 * The lpfc_ct_cmd/lpfc_get_req shall increment ndlp reference count
2872 * to hold ndlp reference for the corresponding callback function.
2874 if (!lpfc_ct_cmd(vport
, mp
, bmp
, ndlp
, cmpl
, rsp_size
, 0))
2878 * Decrement ndlp reference count to release ndlp reference held
2879 * for the failed command's callback function.
2883 fdmi_cmd_free_bmpvirt
:
2884 lpfc_mbuf_free(phba
, bmp
->virt
, bmp
->phys
);
2887 fdmi_cmd_free_mpvirt
:
2888 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
2892 /* Issue FDMI request failed */
2893 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
2894 "0244 Issue FDMI request failed Data: x%x\n",
2900 * lpfc_delayed_disc_tmo - Timeout handler for delayed discovery timer.
2901 * @ptr - Context object of the timer.
2903 * This function set the WORKER_DELAYED_DISC_TMO flag and wake up
2904 * the worker thread.
2907 lpfc_delayed_disc_tmo(struct timer_list
*t
)
2909 struct lpfc_vport
*vport
= from_timer(vport
, t
, delayed_disc_tmo
);
2910 struct lpfc_hba
*phba
= vport
->phba
;
2911 uint32_t tmo_posted
;
2912 unsigned long iflag
;
2914 spin_lock_irqsave(&vport
->work_port_lock
, iflag
);
2915 tmo_posted
= vport
->work_port_events
& WORKER_DELAYED_DISC_TMO
;
2917 vport
->work_port_events
|= WORKER_DELAYED_DISC_TMO
;
2918 spin_unlock_irqrestore(&vport
->work_port_lock
, iflag
);
2921 lpfc_worker_wake_up(phba
);
2926 * lpfc_delayed_disc_timeout_handler - Function called by worker thread to
2927 * handle delayed discovery.
2928 * @vport: pointer to a host virtual N_Port data structure.
2930 * This function start nport discovery of the vport.
2933 lpfc_delayed_disc_timeout_handler(struct lpfc_vport
*vport
)
2935 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2937 spin_lock_irq(shost
->host_lock
);
2938 if (!(vport
->fc_flag
& FC_DISC_DELAYED
)) {
2939 spin_unlock_irq(shost
->host_lock
);
2942 vport
->fc_flag
&= ~FC_DISC_DELAYED
;
2943 spin_unlock_irq(shost
->host_lock
);
2945 lpfc_do_scr_ns_plogi(vport
->phba
, vport
);
2949 lpfc_decode_firmware_rev(struct lpfc_hba
*phba
, char *fwrevision
, int flag
)
2951 struct lpfc_sli
*psli
= &phba
->sli
;
2952 lpfc_vpd_t
*vp
= &phba
->vpd
;
2953 uint32_t b1
, b2
, b3
, b4
, i
, rev
;
2955 uint32_t *ptr
, str
[4];
2958 if (phba
->sli_rev
== LPFC_SLI_REV4
)
2959 snprintf(fwrevision
, FW_REV_STR_SIZE
, "%s", vp
->rev
.opFwName
);
2960 else if (vp
->rev
.rBit
) {
2961 if (psli
->sli_flag
& LPFC_SLI_ACTIVE
)
2962 rev
= vp
->rev
.sli2FwRev
;
2964 rev
= vp
->rev
.sli1FwRev
;
2966 b1
= (rev
& 0x0000f000) >> 12;
2967 b2
= (rev
& 0x00000f00) >> 8;
2968 b3
= (rev
& 0x000000c0) >> 6;
2969 b4
= (rev
& 0x00000030) >> 4;
2988 b4
= (rev
& 0x0000000f);
2990 if (psli
->sli_flag
& LPFC_SLI_ACTIVE
)
2991 fwname
= vp
->rev
.sli2FwName
;
2993 fwname
= vp
->rev
.sli1FwName
;
2995 for (i
= 0; i
< 16; i
++)
2996 if (fwname
[i
] == 0x20)
2999 ptr
= (uint32_t*)fwname
;
3001 for (i
= 0; i
< 3; i
++)
3002 str
[i
] = be32_to_cpu(*ptr
++);
3006 sprintf(fwrevision
, "%d.%d%d (%s)",
3007 b1
, b2
, b3
, (char *)str
);
3009 sprintf(fwrevision
, "%d.%d%d", b1
,
3013 sprintf(fwrevision
, "%d.%d%d%c%d (%s)",
3017 sprintf(fwrevision
, "%d.%d%d%c%d",
3021 rev
= vp
->rev
.smFwRev
;
3023 b1
= (rev
& 0xff000000) >> 24;
3024 b2
= (rev
& 0x00f00000) >> 20;
3025 b3
= (rev
& 0x000f0000) >> 16;
3026 c
= (rev
& 0x0000ff00) >> 8;
3027 b4
= (rev
& 0x000000ff);
3029 sprintf(fwrevision
, "%d.%d%d%c%d", b1
, b2
, b3
, c
, b4
);