Linux 4.18.10
[linux/fpc-iii.git] / drivers / scsi / lpfc / lpfc_ct.c
blobd4a200ae5a6fcaa08fd0d7a99e5860cea8672854
1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2017-2018 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. *
8 * www.broadcom.com *
9 * *
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>
39 #include "lpfc_hw4.h"
40 #include "lpfc_hw.h"
41 #include "lpfc_sli.h"
42 #include "lpfc_sli4.h"
43 #include "lpfc_nl.h"
44 #include "lpfc_disc.h"
45 #include "lpfc.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 */
75 #define FOURBYTES 4
78 static char *lpfc_release_version = LPFC_DRIVER_VERSION;
80 static void
81 lpfc_ct_ignore_hbq_buffer(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq,
82 struct lpfc_dmabuf *mp, uint32_t size)
84 if (!mp) {
85 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
86 "0146 Ignoring unsolicited CT No HBQ "
87 "status = x%x\n",
88 piocbq->iocb.ulpStatus);
90 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
91 "0145 Ignoring unsolicted CT HBQ Size:%d "
92 "status = x%x\n",
93 size, piocbq->iocb.ulpStatus);
96 static void
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);
103 void
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;
109 int i;
110 struct lpfc_iocbq *iocbq;
111 dma_addr_t paddr;
112 uint32_t size;
113 struct list_head head;
114 struct lpfc_dmabuf *bdeBuf;
116 if (lpfc_bsg_ct_unsol_event(phba, pring, piocbq) == 0)
117 return;
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);
128 return;
131 /* If there are no BDEs associated with this IOCB,
132 * there is nothing to do.
134 if (icmd->ulpBdeCount == 0)
135 return;
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) {
141 icmd = &iocbq->iocb;
142 if (icmd->ulpBdeCount == 0)
143 continue;
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,
154 size);
155 lpfc_in_buf_free(phba, bdeBuf);
158 list_del(&head);
159 } else {
160 INIT_LIST_HEAD(&head);
161 list_add_tail(&head, &piocbq->list);
162 list_for_each_entry(iocbq, &head, list) {
163 icmd = &iocbq->iocb;
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,
170 paddr);
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);
177 list_del(&head);
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
187 * protocol.
189 * Return 1 if abort has been handled, 0 otherwise.
192 lpfc_ct_handle_unsol_abort(struct lpfc_hba *phba, struct hbq_dmabuf *dmabuf)
194 int handled;
196 /* CT upper level goes through BSG */
197 handled = lpfc_bsg_ct_unsol_abort(phba, dmabuf);
199 return handled;
202 static void
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);
210 kfree(mlast);
212 lpfc_mbuf_free(phba, mlist->virt, mlist->phys);
213 kfree(mlist);
214 return;
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;
223 int cnt, i = 0;
225 /* We get chunks of FCELSSIZE */
226 cnt = size > FCELSSIZE ? FCELSSIZE: size;
228 while (size) {
229 /* Allocate buffer for rsp payload */
230 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
231 if (!mp) {
232 if (mlist)
233 lpfc_free_ct_rsp(phba, mlist);
234 return NULL;
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));
242 else
243 mp->virt = lpfc_mbuf_alloc(phba, 0, &(mp->phys));
245 if (!mp->virt) {
246 kfree(mp);
247 if (mlist)
248 lpfc_free_ct_rsp(phba, mlist);
249 return NULL;
252 /* Queue it to a linked list */
253 if (!mlist)
254 mlist = mp;
255 else
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);
264 bpl++;
266 i++;
267 size -= cnt;
270 *entries = i;
271 return mlist;
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);
286 kfree(buf_ptr);
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);
297 kfree(buf_ptr);
298 ctiocb->context3 = NULL;
300 lpfc_sli_release_iocbq(phba, ctiocb);
301 return 0;
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.
315 static int
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;
324 IOCB_t *icmd;
325 struct lpfc_iocbq *geniocb;
326 int rc;
328 /* Allocate buffer for command iocb */
329 geniocb = lpfc_sli_get_iocbq(phba);
331 if (geniocb == NULL)
332 return 1;
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));
341 if (usr_flg)
342 geniocb->context3 = NULL;
343 else
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;
360 if (!tmo) {
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;
366 icmd->ulpLe = 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 */
374 icmd->ulpCt_h = 0;
375 icmd->ulpCt_l = 0;
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 "
381 "Data: x%x x%x\n",
382 ndlp->nlp_DID, icmd->ulpIoTag,
383 vport->port_state);
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);
392 return 1;
395 return 0;
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.
408 static int
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;
418 int cnt = 0, status;
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);
426 if (!outmp)
427 return -ENOMEM;
429 * Form the CT IOCB. The total number of BDEs in this IOCB
430 * is the single command plus response count from
431 * lpfc_alloc_ct_rsp.
433 cnt += 1;
434 status = lpfc_gen_req(vport, bmp, inmp, outmp, cmpl, ndlp, 0,
435 cnt, 0, retry);
436 if (status) {
437 lpfc_free_ct_rsp(phba, outmp);
438 return -ENOMEM;
440 return 0;
443 struct lpfc_vport *
444 lpfc_find_vport_by_did(struct lpfc_hba *phba, uint32_t did) {
445 struct lpfc_vport *vport_curr;
446 unsigned long flags;
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);
452 return vport_curr;
455 spin_unlock_irqrestore(&phba->hbalock, flags);
456 return NULL;
459 static void
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 /* Don't assume the rport is always the previous
475 * FC4 type.
477 ndlp->nlp_fc4_type &= ~(NLP_FC4_FCP | NLP_FC4_NVME);
479 /* By default, the driver expects to support FCP FC4 */
480 if (fc4_type == FC_TYPE_FCP)
481 ndlp->nlp_fc4_type |= NLP_FC4_FCP;
483 if (fc4_type == FC_TYPE_NVME)
484 ndlp->nlp_fc4_type |= NLP_FC4_NVME;
486 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
487 "0238 Process x%06x NameServer Rsp "
488 "Data: x%x x%x x%x x%x\n", Did,
489 ndlp->nlp_flag, ndlp->nlp_fc4_type,
490 vport->fc_flag,
491 vport->fc_rscn_id_cnt);
492 } else {
493 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
494 "Skip1 GID_FTrsp: did:x%x flg:x%x cnt:%d",
495 Did, vport->fc_flag, vport->fc_rscn_id_cnt);
497 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
498 "0239 Skip x%06x NameServer Rsp "
499 "Data: x%x x%x\n", Did,
500 vport->fc_flag,
501 vport->fc_rscn_id_cnt);
503 } else {
504 if (!(vport->fc_flag & FC_RSCN_MODE) ||
505 lpfc_rscn_payload_check(vport, Did)) {
506 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
507 "Query GID_FTrsp: did:x%x flg:x%x cnt:%d",
508 Did, vport->fc_flag, vport->fc_rscn_id_cnt);
511 * This NPortID was previously a FCP/NVMe target,
512 * Don't even bother to send GFF_ID.
514 ndlp = lpfc_findnode_did(vport, Did);
515 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
516 (ndlp->nlp_type &
517 (NLP_FCP_TARGET | NLP_NVME_TARGET))) {
518 if (fc4_type == FC_TYPE_FCP)
519 ndlp->nlp_fc4_type |= NLP_FC4_FCP;
520 if (fc4_type == FC_TYPE_NVME)
521 ndlp->nlp_fc4_type |= NLP_FC4_NVME;
522 lpfc_setup_disc_node(vport, Did);
523 } else if (lpfc_ns_cmd(vport, SLI_CTNS_GFF_ID,
524 0, Did) == 0)
525 vport->num_disc_nodes++;
526 else
527 lpfc_setup_disc_node(vport, Did);
528 } else {
529 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
530 "Skip2 GID_FTrsp: did:x%x flg:x%x cnt:%d",
531 Did, vport->fc_flag, vport->fc_rscn_id_cnt);
533 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
534 "0245 Skip x%06x NameServer Rsp "
535 "Data: x%x x%x\n", Did,
536 vport->fc_flag,
537 vport->fc_rscn_id_cnt);
542 static void
543 lpfc_ns_rsp_audit_did(struct lpfc_vport *vport, uint32_t Did, uint8_t fc4_type)
545 struct lpfc_hba *phba = vport->phba;
546 struct lpfc_nodelist *ndlp = NULL;
547 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
550 * To conserve rpi's, filter out addresses for other
551 * vports on the same physical HBAs.
553 if (Did != vport->fc_myDID &&
554 (!lpfc_find_vport_by_did(phba, Did) ||
555 vport->cfg_peer_port_login)) {
556 if (!phba->nvmet_support) {
557 /* FCPI/NVMEI path. Process Did */
558 lpfc_prep_node_fc4type(vport, Did, fc4_type);
559 return;
561 /* NVMET path. NVMET only cares about NVMEI nodes. */
562 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
563 if (ndlp->nlp_type != NLP_NVME_INITIATOR ||
564 ndlp->nlp_state != NLP_STE_UNMAPPED_NODE)
565 continue;
566 spin_lock_irq(shost->host_lock);
567 if (ndlp->nlp_DID == Did)
568 ndlp->nlp_flag &= ~NLP_NVMET_RECOV;
569 else
570 ndlp->nlp_flag |= NLP_NVMET_RECOV;
571 spin_unlock_irq(shost->host_lock);
576 static int
577 lpfc_ns_rsp(struct lpfc_vport *vport, struct lpfc_dmabuf *mp, uint8_t fc4_type,
578 uint32_t Size)
580 struct lpfc_sli_ct_request *Response =
581 (struct lpfc_sli_ct_request *) mp->virt;
582 struct lpfc_dmabuf *mlast, *next_mp;
583 uint32_t *ctptr = (uint32_t *) & Response->un.gid.PortType;
584 uint32_t Did, CTentry;
585 int Cnt;
586 struct list_head head;
587 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
588 struct lpfc_nodelist *ndlp = NULL;
590 lpfc_set_disctmo(vport);
591 vport->num_disc_nodes = 0;
592 vport->fc_ns_retry = 0;
595 list_add_tail(&head, &mp->list);
596 list_for_each_entry_safe(mp, next_mp, &head, list) {
597 mlast = mp;
599 Cnt = Size > FCELSSIZE ? FCELSSIZE : Size;
601 Size -= Cnt;
603 if (!ctptr) {
604 ctptr = (uint32_t *) mlast->virt;
605 } else
606 Cnt -= 16; /* subtract length of CT header */
608 /* Loop through entire NameServer list of DIDs */
609 while (Cnt >= sizeof(uint32_t)) {
610 /* Get next DID from NameServer List */
611 CTentry = *ctptr++;
612 Did = ((be32_to_cpu(CTentry)) & Mask_DID);
613 lpfc_ns_rsp_audit_did(vport, Did, fc4_type);
614 if (CTentry & (cpu_to_be32(SLI_CT_LAST_ENTRY)))
615 goto nsout1;
617 Cnt -= sizeof(uint32_t);
619 ctptr = NULL;
623 /* All GID_FT entries processed. If the driver is running in
624 * in target mode, put impacted nodes into recovery and drop
625 * the RPI to flush outstanding IO.
627 if (vport->phba->nvmet_support) {
628 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
629 if (!(ndlp->nlp_flag & NLP_NVMET_RECOV))
630 continue;
631 lpfc_disc_state_machine(vport, ndlp, NULL,
632 NLP_EVT_DEVICE_RECOVERY);
633 spin_lock_irq(shost->host_lock);
634 ndlp->nlp_flag &= ~NLP_NVMET_RECOV;
635 spin_unlock_irq(shost->host_lock);
639 nsout1:
640 list_del(&head);
641 return 0;
644 static void
645 lpfc_cmpl_ct_cmd_gid_ft(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
646 struct lpfc_iocbq *rspiocb)
648 struct lpfc_vport *vport = cmdiocb->vport;
649 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
650 IOCB_t *irsp;
651 struct lpfc_dmabuf *outp;
652 struct lpfc_dmabuf *inp;
653 struct lpfc_sli_ct_request *CTrsp;
654 struct lpfc_sli_ct_request *CTreq;
655 struct lpfc_nodelist *ndlp;
656 int rc, type;
658 /* First save ndlp, before we overwrite it */
659 ndlp = cmdiocb->context_un.ndlp;
661 /* we pass cmdiocb to state machine which needs rspiocb as well */
662 cmdiocb->context_un.rsp_iocb = rspiocb;
663 inp = (struct lpfc_dmabuf *) cmdiocb->context1;
664 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
665 irsp = &rspiocb->iocb;
667 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
668 "GID_FT cmpl: status:x%x/x%x rtry:%d",
669 irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_ns_retry);
671 /* Don't bother processing response if vport is being torn down. */
672 if (vport->load_flag & FC_UNLOADING) {
673 if (vport->fc_flag & FC_RSCN_MODE)
674 lpfc_els_flush_rscn(vport);
675 goto out;
678 if (lpfc_els_chk_latt(vport)) {
679 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
680 "0216 Link event during NS query\n");
681 if (vport->fc_flag & FC_RSCN_MODE)
682 lpfc_els_flush_rscn(vport);
683 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
684 goto out;
686 if (lpfc_error_lost_link(irsp)) {
687 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
688 "0226 NS query failed due to link event\n");
689 if (vport->fc_flag & FC_RSCN_MODE)
690 lpfc_els_flush_rscn(vport);
691 goto out;
694 spin_lock_irq(shost->host_lock);
695 if (vport->fc_flag & FC_RSCN_DEFERRED) {
696 vport->fc_flag &= ~FC_RSCN_DEFERRED;
697 spin_unlock_irq(shost->host_lock);
699 /* This is a GID_FT completing so the gidft_inp counter was
700 * incremented before the GID_FT was issued to the wire.
702 vport->gidft_inp--;
705 * Skip processing the NS response
706 * Re-issue the NS cmd
708 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
709 "0151 Process Deferred RSCN Data: x%x x%x\n",
710 vport->fc_flag, vport->fc_rscn_id_cnt);
711 lpfc_els_handle_rscn(vport);
713 goto out;
715 spin_unlock_irq(shost->host_lock);
717 if (irsp->ulpStatus) {
718 /* Check for retry */
719 if (vport->fc_ns_retry < LPFC_MAX_NS_RETRY) {
720 if (irsp->ulpStatus != IOSTAT_LOCAL_REJECT ||
721 (irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
722 IOERR_NO_RESOURCES)
723 vport->fc_ns_retry++;
725 type = lpfc_get_gidft_type(vport, cmdiocb);
726 if (type == 0)
727 goto out;
729 /* CT command is being retried */
730 vport->gidft_inp--;
731 rc = lpfc_ns_cmd(vport, SLI_CTNS_GID_FT,
732 vport->fc_ns_retry, type);
733 if (rc == 0)
734 goto out;
736 if (vport->fc_flag & FC_RSCN_MODE)
737 lpfc_els_flush_rscn(vport);
738 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
739 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
740 "0257 GID_FT Query error: 0x%x 0x%x\n",
741 irsp->ulpStatus, vport->fc_ns_retry);
742 } else {
743 /* Good status, continue checking */
744 CTreq = (struct lpfc_sli_ct_request *) inp->virt;
745 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
746 if (CTrsp->CommandResponse.bits.CmdRsp ==
747 cpu_to_be16(SLI_CT_RESPONSE_FS_ACC)) {
748 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
749 "0208 NameServer Rsp Data: x%x x%x\n",
750 vport->fc_flag,
751 CTreq->un.gid.Fc4Type);
753 lpfc_ns_rsp(vport,
754 outp,
755 CTreq->un.gid.Fc4Type,
756 (uint32_t) (irsp->un.genreq64.bdl.bdeSize));
757 } else if (CTrsp->CommandResponse.bits.CmdRsp ==
758 be16_to_cpu(SLI_CT_RESPONSE_FS_RJT)) {
759 /* NameServer Rsp Error */
760 if ((CTrsp->ReasonCode == SLI_CT_UNABLE_TO_PERFORM_REQ)
761 && (CTrsp->Explanation == SLI_CT_NO_FC4_TYPES)) {
762 lpfc_printf_vlog(vport, KERN_INFO,
763 LOG_DISCOVERY,
764 "0269 No NameServer Entries "
765 "Data: x%x x%x x%x x%x\n",
766 CTrsp->CommandResponse.bits.CmdRsp,
767 (uint32_t) CTrsp->ReasonCode,
768 (uint32_t) CTrsp->Explanation,
769 vport->fc_flag);
771 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
772 "GID_FT no entry cmd:x%x rsn:x%x exp:x%x",
773 (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
774 (uint32_t) CTrsp->ReasonCode,
775 (uint32_t) CTrsp->Explanation);
776 } else {
777 lpfc_printf_vlog(vport, KERN_INFO,
778 LOG_DISCOVERY,
779 "0240 NameServer Rsp Error "
780 "Data: x%x x%x x%x x%x\n",
781 CTrsp->CommandResponse.bits.CmdRsp,
782 (uint32_t) CTrsp->ReasonCode,
783 (uint32_t) CTrsp->Explanation,
784 vport->fc_flag);
786 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
787 "GID_FT rsp err1 cmd:x%x rsn:x%x exp:x%x",
788 (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
789 (uint32_t) CTrsp->ReasonCode,
790 (uint32_t) CTrsp->Explanation);
794 } else {
795 /* NameServer Rsp Error */
796 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
797 "0241 NameServer Rsp Error "
798 "Data: x%x x%x x%x x%x\n",
799 CTrsp->CommandResponse.bits.CmdRsp,
800 (uint32_t) CTrsp->ReasonCode,
801 (uint32_t) CTrsp->Explanation,
802 vport->fc_flag);
804 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
805 "GID_FT rsp err2 cmd:x%x rsn:x%x exp:x%x",
806 (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
807 (uint32_t) CTrsp->ReasonCode,
808 (uint32_t) CTrsp->Explanation);
810 vport->gidft_inp--;
812 /* Link up / RSCN discovery */
813 if ((vport->num_disc_nodes == 0) &&
814 (vport->gidft_inp == 0)) {
816 * The driver has cycled through all Nports in the RSCN payload.
817 * Complete the handling by cleaning up and marking the
818 * current driver state.
820 if (vport->port_state >= LPFC_DISC_AUTH) {
821 if (vport->fc_flag & FC_RSCN_MODE) {
822 lpfc_els_flush_rscn(vport);
823 spin_lock_irq(shost->host_lock);
824 vport->fc_flag |= FC_RSCN_MODE; /* RSCN still */
825 spin_unlock_irq(shost->host_lock);
827 else
828 lpfc_els_flush_rscn(vport);
831 lpfc_disc_start(vport);
833 out:
834 cmdiocb->context_un.ndlp = ndlp; /* Now restore ndlp for free */
835 lpfc_ct_free_iocb(phba, cmdiocb);
836 return;
839 static void
840 lpfc_cmpl_ct_cmd_gff_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
841 struct lpfc_iocbq *rspiocb)
843 struct lpfc_vport *vport = cmdiocb->vport;
844 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
845 IOCB_t *irsp = &rspiocb->iocb;
846 struct lpfc_dmabuf *inp = (struct lpfc_dmabuf *) cmdiocb->context1;
847 struct lpfc_dmabuf *outp = (struct lpfc_dmabuf *) cmdiocb->context2;
848 struct lpfc_sli_ct_request *CTrsp;
849 int did, rc, retry;
850 uint8_t fbits;
851 struct lpfc_nodelist *ndlp;
853 did = ((struct lpfc_sli_ct_request *) inp->virt)->un.gff.PortId;
854 did = be32_to_cpu(did);
856 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
857 "GFF_ID cmpl: status:x%x/x%x did:x%x",
858 irsp->ulpStatus, irsp->un.ulpWord[4], did);
860 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
861 /* Good status, continue checking */
862 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
863 fbits = CTrsp->un.gff_acc.fbits[FCP_TYPE_FEATURE_OFFSET];
865 if (CTrsp->CommandResponse.bits.CmdRsp ==
866 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC)) {
867 if ((fbits & FC4_FEATURE_INIT) &&
868 !(fbits & FC4_FEATURE_TARGET)) {
869 lpfc_printf_vlog(vport, KERN_INFO,
870 LOG_DISCOVERY,
871 "0270 Skip x%x GFF "
872 "NameServer Rsp Data: (init) "
873 "x%x x%x\n", did, fbits,
874 vport->fc_rscn_id_cnt);
875 goto out;
879 else {
880 /* Check for retry */
881 if (cmdiocb->retry < LPFC_MAX_NS_RETRY) {
882 retry = 1;
883 if (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) {
884 switch ((irsp->un.ulpWord[4] &
885 IOERR_PARAM_MASK)) {
887 case IOERR_NO_RESOURCES:
888 /* We don't increment the retry
889 * count for this case.
891 break;
892 case IOERR_LINK_DOWN:
893 case IOERR_SLI_ABORTED:
894 case IOERR_SLI_DOWN:
895 retry = 0;
896 break;
897 default:
898 cmdiocb->retry++;
901 else
902 cmdiocb->retry++;
904 if (retry) {
905 /* CT command is being retried */
906 rc = lpfc_ns_cmd(vport, SLI_CTNS_GFF_ID,
907 cmdiocb->retry, did);
908 if (rc == 0) {
909 /* success */
910 lpfc_ct_free_iocb(phba, cmdiocb);
911 return;
915 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
916 "0267 NameServer GFF Rsp "
917 "x%x Error (%d %d) Data: x%x x%x\n",
918 did, irsp->ulpStatus, irsp->un.ulpWord[4],
919 vport->fc_flag, vport->fc_rscn_id_cnt);
922 /* This is a target port, unregistered port, or the GFF_ID failed */
923 ndlp = lpfc_setup_disc_node(vport, did);
924 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
925 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
926 "0242 Process x%x GFF "
927 "NameServer Rsp Data: x%x x%x x%x\n",
928 did, ndlp->nlp_flag, vport->fc_flag,
929 vport->fc_rscn_id_cnt);
930 } else {
931 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
932 "0243 Skip x%x GFF "
933 "NameServer Rsp Data: x%x x%x\n", did,
934 vport->fc_flag, vport->fc_rscn_id_cnt);
936 out:
937 /* Link up / RSCN discovery */
938 if (vport->num_disc_nodes)
939 vport->num_disc_nodes--;
940 if (vport->num_disc_nodes == 0) {
942 * The driver has cycled through all Nports in the RSCN payload.
943 * Complete the handling by cleaning up and marking the
944 * current driver state.
946 if (vport->port_state >= LPFC_DISC_AUTH) {
947 if (vport->fc_flag & FC_RSCN_MODE) {
948 lpfc_els_flush_rscn(vport);
949 spin_lock_irq(shost->host_lock);
950 vport->fc_flag |= FC_RSCN_MODE; /* RSCN still */
951 spin_unlock_irq(shost->host_lock);
953 else
954 lpfc_els_flush_rscn(vport);
956 lpfc_disc_start(vport);
958 lpfc_ct_free_iocb(phba, cmdiocb);
959 return;
962 static void
963 lpfc_cmpl_ct_cmd_gft_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
964 struct lpfc_iocbq *rspiocb)
966 struct lpfc_vport *vport = cmdiocb->vport;
967 IOCB_t *irsp = &rspiocb->iocb;
968 struct lpfc_dmabuf *inp = (struct lpfc_dmabuf *)cmdiocb->context1;
969 struct lpfc_dmabuf *outp = (struct lpfc_dmabuf *)cmdiocb->context2;
970 struct lpfc_sli_ct_request *CTrsp;
971 int did;
972 struct lpfc_nodelist *ndlp;
973 uint32_t fc4_data_0, fc4_data_1;
975 did = ((struct lpfc_sli_ct_request *)inp->virt)->un.gft.PortId;
976 did = be32_to_cpu(did);
978 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
979 "GFT_ID cmpl: status:x%x/x%x did:x%x",
980 irsp->ulpStatus, irsp->un.ulpWord[4], did);
982 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
983 /* Good status, continue checking */
984 CTrsp = (struct lpfc_sli_ct_request *)outp->virt;
985 fc4_data_0 = be32_to_cpu(CTrsp->un.gft_acc.fc4_types[0]);
986 fc4_data_1 = be32_to_cpu(CTrsp->un.gft_acc.fc4_types[1]);
987 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
988 "3062 DID x%06x GFT Wd0 x%08x Wd1 x%08x\n",
989 did, fc4_data_0, fc4_data_1);
991 ndlp = lpfc_findnode_did(vport, did);
992 if (ndlp) {
993 /* The bitmask value for FCP and NVME FCP types is
994 * the same because they are 32 bits distant from
995 * each other in word0 and word0.
997 if (fc4_data_0 & LPFC_FC4_TYPE_BITMASK)
998 ndlp->nlp_fc4_type |= NLP_FC4_FCP;
999 if (fc4_data_1 & LPFC_FC4_TYPE_BITMASK)
1000 ndlp->nlp_fc4_type |= NLP_FC4_NVME;
1001 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1002 "3064 Setting ndlp %p, DID x%06x with "
1003 "FC4 x%08x, Data: x%08x x%08x\n",
1004 ndlp, did, ndlp->nlp_fc4_type,
1005 FC_TYPE_FCP, FC_TYPE_NVME);
1006 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1008 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
1009 lpfc_issue_els_prli(vport, ndlp, 0);
1011 } else
1012 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
1013 "3065 GFT_ID failed x%08x\n", irsp->ulpStatus);
1015 lpfc_ct_free_iocb(phba, cmdiocb);
1018 static void
1019 lpfc_cmpl_ct(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1020 struct lpfc_iocbq *rspiocb)
1022 struct lpfc_vport *vport = cmdiocb->vport;
1023 struct lpfc_dmabuf *inp;
1024 struct lpfc_dmabuf *outp;
1025 IOCB_t *irsp;
1026 struct lpfc_sli_ct_request *CTrsp;
1027 struct lpfc_nodelist *ndlp;
1028 int cmdcode, rc;
1029 uint8_t retry;
1030 uint32_t latt;
1032 /* First save ndlp, before we overwrite it */
1033 ndlp = cmdiocb->context_un.ndlp;
1035 /* we pass cmdiocb to state machine which needs rspiocb as well */
1036 cmdiocb->context_un.rsp_iocb = rspiocb;
1038 inp = (struct lpfc_dmabuf *) cmdiocb->context1;
1039 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
1040 irsp = &rspiocb->iocb;
1042 cmdcode = be16_to_cpu(((struct lpfc_sli_ct_request *) inp->virt)->
1043 CommandResponse.bits.CmdRsp);
1044 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
1046 latt = lpfc_els_chk_latt(vport);
1048 /* RFT request completes status <ulpStatus> CmdRsp <CmdRsp> */
1049 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1050 "0209 CT Request completes, latt %d, "
1051 "ulpStatus x%x CmdRsp x%x, Context x%x, Tag x%x\n",
1052 latt, irsp->ulpStatus,
1053 CTrsp->CommandResponse.bits.CmdRsp,
1054 cmdiocb->iocb.ulpContext, cmdiocb->iocb.ulpIoTag);
1056 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
1057 "CT cmd cmpl: status:x%x/x%x cmd:x%x",
1058 irsp->ulpStatus, irsp->un.ulpWord[4], cmdcode);
1060 if (irsp->ulpStatus) {
1061 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
1062 "0268 NS cmd x%x Error (x%x x%x)\n",
1063 cmdcode, irsp->ulpStatus, irsp->un.ulpWord[4]);
1065 if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
1066 (((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
1067 IOERR_SLI_DOWN) ||
1068 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
1069 IOERR_SLI_ABORTED)))
1070 goto out;
1072 retry = cmdiocb->retry;
1073 if (retry >= LPFC_MAX_NS_RETRY)
1074 goto out;
1076 retry++;
1077 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1078 "0250 Retrying NS cmd %x\n", cmdcode);
1079 rc = lpfc_ns_cmd(vport, cmdcode, retry, 0);
1080 if (rc == 0)
1081 goto out;
1084 out:
1085 cmdiocb->context_un.ndlp = ndlp; /* Now restore ndlp for free */
1086 lpfc_ct_free_iocb(phba, cmdiocb);
1087 return;
1090 static void
1091 lpfc_cmpl_ct_cmd_rft_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1092 struct lpfc_iocbq *rspiocb)
1094 IOCB_t *irsp = &rspiocb->iocb;
1095 struct lpfc_vport *vport = cmdiocb->vport;
1097 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
1098 struct lpfc_dmabuf *outp;
1099 struct lpfc_sli_ct_request *CTrsp;
1101 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
1102 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
1103 if (CTrsp->CommandResponse.bits.CmdRsp ==
1104 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
1105 vport->ct_flags |= FC_CT_RFT_ID;
1107 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
1108 return;
1111 static void
1112 lpfc_cmpl_ct_cmd_rnn_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1113 struct lpfc_iocbq *rspiocb)
1115 IOCB_t *irsp = &rspiocb->iocb;
1116 struct lpfc_vport *vport = cmdiocb->vport;
1118 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
1119 struct lpfc_dmabuf *outp;
1120 struct lpfc_sli_ct_request *CTrsp;
1122 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
1123 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
1124 if (CTrsp->CommandResponse.bits.CmdRsp ==
1125 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
1126 vport->ct_flags |= FC_CT_RNN_ID;
1128 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
1129 return;
1132 static void
1133 lpfc_cmpl_ct_cmd_rspn_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1134 struct lpfc_iocbq *rspiocb)
1136 IOCB_t *irsp = &rspiocb->iocb;
1137 struct lpfc_vport *vport = cmdiocb->vport;
1139 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
1140 struct lpfc_dmabuf *outp;
1141 struct lpfc_sli_ct_request *CTrsp;
1143 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
1144 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
1145 if (CTrsp->CommandResponse.bits.CmdRsp ==
1146 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
1147 vport->ct_flags |= FC_CT_RSPN_ID;
1149 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
1150 return;
1153 static void
1154 lpfc_cmpl_ct_cmd_rsnn_nn(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1155 struct lpfc_iocbq *rspiocb)
1157 IOCB_t *irsp = &rspiocb->iocb;
1158 struct lpfc_vport *vport = cmdiocb->vport;
1160 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
1161 struct lpfc_dmabuf *outp;
1162 struct lpfc_sli_ct_request *CTrsp;
1164 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
1165 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
1166 if (CTrsp->CommandResponse.bits.CmdRsp ==
1167 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
1168 vport->ct_flags |= FC_CT_RSNN_NN;
1170 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
1171 return;
1174 static void
1175 lpfc_cmpl_ct_cmd_da_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1176 struct lpfc_iocbq *rspiocb)
1178 struct lpfc_vport *vport = cmdiocb->vport;
1180 /* even if it fails we will act as though it succeeded. */
1181 vport->ct_flags = 0;
1182 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
1183 return;
1186 static void
1187 lpfc_cmpl_ct_cmd_rff_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1188 struct lpfc_iocbq *rspiocb)
1190 IOCB_t *irsp = &rspiocb->iocb;
1191 struct lpfc_vport *vport = cmdiocb->vport;
1193 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
1194 struct lpfc_dmabuf *outp;
1195 struct lpfc_sli_ct_request *CTrsp;
1197 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
1198 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
1199 if (CTrsp->CommandResponse.bits.CmdRsp ==
1200 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
1201 vport->ct_flags |= FC_CT_RFF_ID;
1203 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
1204 return;
1208 * Although the symbolic port name is thought to be an integer
1209 * as of January 18, 2016, leave it as a string until more of
1210 * the record state becomes defined.
1213 lpfc_vport_symbolic_port_name(struct lpfc_vport *vport, char *symbol,
1214 size_t size)
1216 int n;
1219 * Use the lpfc board number as the Symbolic Port
1220 * Name object. NPIV is not in play so this integer
1221 * value is sufficient and unique per FC-ID.
1223 n = snprintf(symbol, size, "%d", vport->phba->brd_no);
1224 return n;
1229 lpfc_vport_symbolic_node_name(struct lpfc_vport *vport, char *symbol,
1230 size_t size)
1232 char fwrev[FW_REV_STR_SIZE];
1233 int n;
1235 lpfc_decode_firmware_rev(vport->phba, fwrev, 0);
1237 n = snprintf(symbol, size, "Emulex %s", vport->phba->ModelName);
1238 if (size < n)
1239 return n;
1241 n += snprintf(symbol + n, size - n, " FV%s", fwrev);
1242 if (size < n)
1243 return n;
1245 n += snprintf(symbol + n, size - n, " DV%s.",
1246 lpfc_release_version);
1247 if (size < n)
1248 return n;
1250 n += snprintf(symbol + n, size - n, " HN:%s.",
1251 init_utsname()->nodename);
1252 if (size < n)
1253 return n;
1255 /* Note :- OS name is "Linux" */
1256 n += snprintf(symbol + n, size - n, " OS:%s\n",
1257 init_utsname()->sysname);
1258 return n;
1261 static uint32_t
1262 lpfc_find_map_node(struct lpfc_vport *vport)
1264 struct lpfc_nodelist *ndlp, *next_ndlp;
1265 struct Scsi_Host *shost;
1266 uint32_t cnt = 0;
1268 shost = lpfc_shost_from_vport(vport);
1269 spin_lock_irq(shost->host_lock);
1270 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
1271 if (ndlp->nlp_type & NLP_FABRIC)
1272 continue;
1273 if ((ndlp->nlp_state == NLP_STE_MAPPED_NODE) ||
1274 (ndlp->nlp_state == NLP_STE_UNMAPPED_NODE))
1275 cnt++;
1277 spin_unlock_irq(shost->host_lock);
1278 return cnt;
1282 * This routine will return the FC4 Type associated with the CT
1283 * GID_FT command.
1286 lpfc_get_gidft_type(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb)
1288 struct lpfc_sli_ct_request *CtReq;
1289 struct lpfc_dmabuf *mp;
1290 uint32_t type;
1292 mp = cmdiocb->context1;
1293 if (mp == NULL)
1294 return 0;
1295 CtReq = (struct lpfc_sli_ct_request *)mp->virt;
1296 type = (uint32_t)CtReq->un.gid.Fc4Type;
1297 if ((type != SLI_CTPT_FCP) && (type != SLI_CTPT_NVME))
1298 return 0;
1299 return type;
1303 * lpfc_ns_cmd
1304 * Description:
1305 * Issue Cmd to NameServer
1306 * SLI_CTNS_GID_FT
1307 * LI_CTNS_RFT_ID
1310 lpfc_ns_cmd(struct lpfc_vport *vport, int cmdcode,
1311 uint8_t retry, uint32_t context)
1313 struct lpfc_nodelist * ndlp;
1314 struct lpfc_hba *phba = vport->phba;
1315 struct lpfc_dmabuf *mp, *bmp;
1316 struct lpfc_sli_ct_request *CtReq;
1317 struct ulp_bde64 *bpl;
1318 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
1319 struct lpfc_iocbq *) = NULL;
1320 uint32_t rsp_size = 1024;
1321 size_t size;
1322 int rc = 0;
1324 ndlp = lpfc_findnode_did(vport, NameServer_DID);
1325 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)
1326 || ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) {
1327 rc=1;
1328 goto ns_cmd_exit;
1331 /* fill in BDEs for command */
1332 /* Allocate buffer for command payload */
1333 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
1334 if (!mp) {
1335 rc=2;
1336 goto ns_cmd_exit;
1339 INIT_LIST_HEAD(&mp->list);
1340 mp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(mp->phys));
1341 if (!mp->virt) {
1342 rc=3;
1343 goto ns_cmd_free_mp;
1346 /* Allocate buffer for Buffer ptr list */
1347 bmp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
1348 if (!bmp) {
1349 rc=4;
1350 goto ns_cmd_free_mpvirt;
1353 INIT_LIST_HEAD(&bmp->list);
1354 bmp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(bmp->phys));
1355 if (!bmp->virt) {
1356 rc=5;
1357 goto ns_cmd_free_bmp;
1360 /* NameServer Req */
1361 lpfc_printf_vlog(vport, KERN_INFO ,LOG_DISCOVERY,
1362 "0236 NameServer Req Data: x%x x%x x%x x%x\n",
1363 cmdcode, vport->fc_flag, vport->fc_rscn_id_cnt,
1364 context);
1366 bpl = (struct ulp_bde64 *) bmp->virt;
1367 memset(bpl, 0, sizeof(struct ulp_bde64));
1368 bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys) );
1369 bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys) );
1370 bpl->tus.f.bdeFlags = 0;
1371 if (cmdcode == SLI_CTNS_GID_FT)
1372 bpl->tus.f.bdeSize = GID_REQUEST_SZ;
1373 else if (cmdcode == SLI_CTNS_GFF_ID)
1374 bpl->tus.f.bdeSize = GFF_REQUEST_SZ;
1375 else if (cmdcode == SLI_CTNS_GFT_ID)
1376 bpl->tus.f.bdeSize = GFT_REQUEST_SZ;
1377 else if (cmdcode == SLI_CTNS_RFT_ID)
1378 bpl->tus.f.bdeSize = RFT_REQUEST_SZ;
1379 else if (cmdcode == SLI_CTNS_RNN_ID)
1380 bpl->tus.f.bdeSize = RNN_REQUEST_SZ;
1381 else if (cmdcode == SLI_CTNS_RSPN_ID)
1382 bpl->tus.f.bdeSize = RSPN_REQUEST_SZ;
1383 else if (cmdcode == SLI_CTNS_RSNN_NN)
1384 bpl->tus.f.bdeSize = RSNN_REQUEST_SZ;
1385 else if (cmdcode == SLI_CTNS_DA_ID)
1386 bpl->tus.f.bdeSize = DA_ID_REQUEST_SZ;
1387 else if (cmdcode == SLI_CTNS_RFF_ID)
1388 bpl->tus.f.bdeSize = RFF_REQUEST_SZ;
1389 else
1390 bpl->tus.f.bdeSize = 0;
1391 bpl->tus.w = le32_to_cpu(bpl->tus.w);
1393 CtReq = (struct lpfc_sli_ct_request *) mp->virt;
1394 memset(CtReq, 0, sizeof(struct lpfc_sli_ct_request));
1395 CtReq->RevisionId.bits.Revision = SLI_CT_REVISION;
1396 CtReq->RevisionId.bits.InId = 0;
1397 CtReq->FsType = SLI_CT_DIRECTORY_SERVICE;
1398 CtReq->FsSubType = SLI_CT_DIRECTORY_NAME_SERVER;
1399 CtReq->CommandResponse.bits.Size = 0;
1400 switch (cmdcode) {
1401 case SLI_CTNS_GID_FT:
1402 CtReq->CommandResponse.bits.CmdRsp =
1403 cpu_to_be16(SLI_CTNS_GID_FT);
1404 CtReq->un.gid.Fc4Type = context;
1406 if (vport->port_state < LPFC_NS_QRY)
1407 vport->port_state = LPFC_NS_QRY;
1408 lpfc_set_disctmo(vport);
1409 cmpl = lpfc_cmpl_ct_cmd_gid_ft;
1410 rsp_size = FC_MAX_NS_RSP;
1411 break;
1413 case SLI_CTNS_GFF_ID:
1414 CtReq->CommandResponse.bits.CmdRsp =
1415 cpu_to_be16(SLI_CTNS_GFF_ID);
1416 CtReq->un.gff.PortId = cpu_to_be32(context);
1417 cmpl = lpfc_cmpl_ct_cmd_gff_id;
1418 break;
1420 case SLI_CTNS_GFT_ID:
1421 CtReq->CommandResponse.bits.CmdRsp =
1422 cpu_to_be16(SLI_CTNS_GFT_ID);
1423 CtReq->un.gft.PortId = cpu_to_be32(context);
1424 cmpl = lpfc_cmpl_ct_cmd_gft_id;
1425 break;
1427 case SLI_CTNS_RFT_ID:
1428 vport->ct_flags &= ~FC_CT_RFT_ID;
1429 CtReq->CommandResponse.bits.CmdRsp =
1430 cpu_to_be16(SLI_CTNS_RFT_ID);
1431 CtReq->un.rft.PortId = cpu_to_be32(vport->fc_myDID);
1433 /* Register FC4 FCP type if enabled. */
1434 if ((phba->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
1435 (phba->cfg_enable_fc4_type == LPFC_ENABLE_FCP))
1436 CtReq->un.rft.fcpReg = 1;
1438 /* Register NVME type if enabled. Defined LE and swapped.
1439 * rsvd[0] is used as word1 because of the hard-coded
1440 * word0 usage in the ct_request data structure.
1442 if ((phba->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
1443 (phba->cfg_enable_fc4_type == LPFC_ENABLE_NVME))
1444 CtReq->un.rft.rsvd[0] = cpu_to_be32(0x00000100);
1446 cmpl = lpfc_cmpl_ct_cmd_rft_id;
1447 break;
1449 case SLI_CTNS_RNN_ID:
1450 vport->ct_flags &= ~FC_CT_RNN_ID;
1451 CtReq->CommandResponse.bits.CmdRsp =
1452 cpu_to_be16(SLI_CTNS_RNN_ID);
1453 CtReq->un.rnn.PortId = cpu_to_be32(vport->fc_myDID);
1454 memcpy(CtReq->un.rnn.wwnn, &vport->fc_nodename,
1455 sizeof(struct lpfc_name));
1456 cmpl = lpfc_cmpl_ct_cmd_rnn_id;
1457 break;
1459 case SLI_CTNS_RSPN_ID:
1460 vport->ct_flags &= ~FC_CT_RSPN_ID;
1461 CtReq->CommandResponse.bits.CmdRsp =
1462 cpu_to_be16(SLI_CTNS_RSPN_ID);
1463 CtReq->un.rspn.PortId = cpu_to_be32(vport->fc_myDID);
1464 size = sizeof(CtReq->un.rspn.symbname);
1465 CtReq->un.rspn.len =
1466 lpfc_vport_symbolic_port_name(vport,
1467 CtReq->un.rspn.symbname, size);
1468 cmpl = lpfc_cmpl_ct_cmd_rspn_id;
1469 break;
1470 case SLI_CTNS_RSNN_NN:
1471 vport->ct_flags &= ~FC_CT_RSNN_NN;
1472 CtReq->CommandResponse.bits.CmdRsp =
1473 cpu_to_be16(SLI_CTNS_RSNN_NN);
1474 memcpy(CtReq->un.rsnn.wwnn, &vport->fc_nodename,
1475 sizeof(struct lpfc_name));
1476 size = sizeof(CtReq->un.rsnn.symbname);
1477 CtReq->un.rsnn.len =
1478 lpfc_vport_symbolic_node_name(vport,
1479 CtReq->un.rsnn.symbname, size);
1480 cmpl = lpfc_cmpl_ct_cmd_rsnn_nn;
1481 break;
1482 case SLI_CTNS_DA_ID:
1483 /* Implement DA_ID Nameserver request */
1484 CtReq->CommandResponse.bits.CmdRsp =
1485 cpu_to_be16(SLI_CTNS_DA_ID);
1486 CtReq->un.da_id.port_id = cpu_to_be32(vport->fc_myDID);
1487 cmpl = lpfc_cmpl_ct_cmd_da_id;
1488 break;
1489 case SLI_CTNS_RFF_ID:
1490 vport->ct_flags &= ~FC_CT_RFF_ID;
1491 CtReq->CommandResponse.bits.CmdRsp =
1492 cpu_to_be16(SLI_CTNS_RFF_ID);
1493 CtReq->un.rff.PortId = cpu_to_be32(vport->fc_myDID);
1494 CtReq->un.rff.fbits = FC4_FEATURE_INIT;
1496 /* The driver always supports FC_TYPE_FCP. However, the
1497 * caller can specify NVME (type x28) as well. But only
1498 * these that FC4 type is supported.
1500 if (((phba->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
1501 (phba->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) &&
1502 (context == FC_TYPE_NVME)) {
1503 if ((vport == phba->pport) && phba->nvmet_support) {
1504 CtReq->un.rff.fbits = (FC4_FEATURE_TARGET |
1505 FC4_FEATURE_NVME_DISC);
1506 lpfc_nvmet_update_targetport(phba);
1507 } else {
1508 lpfc_nvme_update_localport(vport);
1510 CtReq->un.rff.type_code = context;
1512 } else if (((phba->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
1513 (phba->cfg_enable_fc4_type == LPFC_ENABLE_FCP)) &&
1514 (context == FC_TYPE_FCP))
1515 CtReq->un.rff.type_code = context;
1517 else
1518 goto ns_cmd_free_bmpvirt;
1520 cmpl = lpfc_cmpl_ct_cmd_rff_id;
1521 break;
1523 /* The lpfc_ct_cmd/lpfc_get_req shall increment ndlp reference count
1524 * to hold ndlp reference for the corresponding callback function.
1526 if (!lpfc_ct_cmd(vport, mp, bmp, ndlp, cmpl, rsp_size, retry)) {
1527 /* On success, The cmpl function will free the buffers */
1528 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
1529 "Issue CT cmd: cmd:x%x did:x%x",
1530 cmdcode, ndlp->nlp_DID, 0);
1531 return 0;
1533 rc=6;
1535 /* Decrement ndlp reference count to release ndlp reference held
1536 * for the failed command's callback function.
1538 lpfc_nlp_put(ndlp);
1540 ns_cmd_free_bmpvirt:
1541 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
1542 ns_cmd_free_bmp:
1543 kfree(bmp);
1544 ns_cmd_free_mpvirt:
1545 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1546 ns_cmd_free_mp:
1547 kfree(mp);
1548 ns_cmd_exit:
1549 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
1550 "0266 Issue NameServer Req x%x err %d Data: x%x x%x\n",
1551 cmdcode, rc, vport->fc_flag, vport->fc_rscn_id_cnt);
1552 return 1;
1556 * lpfc_cmpl_ct_disc_fdmi - Handle a discovery FDMI completion
1557 * @phba: Pointer to HBA context object.
1558 * @cmdiocb: Pointer to the command IOCBQ.
1559 * @rspiocb: Pointer to the response IOCBQ.
1561 * This function to handle the completion of a driver initiated FDMI
1562 * CT command issued during discovery.
1564 static void
1565 lpfc_cmpl_ct_disc_fdmi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1566 struct lpfc_iocbq *rspiocb)
1568 struct lpfc_vport *vport = cmdiocb->vport;
1569 struct lpfc_dmabuf *inp = cmdiocb->context1;
1570 struct lpfc_dmabuf *outp = cmdiocb->context2;
1571 struct lpfc_sli_ct_request *CTcmd = inp->virt;
1572 struct lpfc_sli_ct_request *CTrsp = outp->virt;
1573 uint16_t fdmi_cmd = CTcmd->CommandResponse.bits.CmdRsp;
1574 uint16_t fdmi_rsp = CTrsp->CommandResponse.bits.CmdRsp;
1575 IOCB_t *irsp = &rspiocb->iocb;
1576 struct lpfc_nodelist *ndlp;
1577 uint32_t latt, cmd, err;
1579 latt = lpfc_els_chk_latt(vport);
1580 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
1581 "FDMI cmpl: status:x%x/x%x latt:%d",
1582 irsp->ulpStatus, irsp->un.ulpWord[4], latt);
1584 if (latt || irsp->ulpStatus) {
1586 /* Look for a retryable error */
1587 if (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) {
1588 switch ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK)) {
1589 case IOERR_SLI_ABORTED:
1590 case IOERR_ABORT_IN_PROGRESS:
1591 case IOERR_SEQUENCE_TIMEOUT:
1592 case IOERR_ILLEGAL_FRAME:
1593 case IOERR_NO_RESOURCES:
1594 case IOERR_ILLEGAL_COMMAND:
1595 cmdiocb->retry++;
1596 if (cmdiocb->retry >= LPFC_FDMI_MAX_RETRY)
1597 break;
1599 /* Retry the same FDMI command */
1600 err = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING,
1601 cmdiocb, 0);
1602 if (err == IOCB_ERROR)
1603 break;
1604 return;
1605 default:
1606 break;
1610 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1611 "0229 FDMI cmd %04x failed, latt = %d "
1612 "ulpStatus: x%x, rid x%x\n",
1613 be16_to_cpu(fdmi_cmd), latt, irsp->ulpStatus,
1614 irsp->un.ulpWord[4]);
1616 lpfc_ct_free_iocb(phba, cmdiocb);
1618 ndlp = lpfc_findnode_did(vport, FDMI_DID);
1619 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
1620 return;
1622 /* Check for a CT LS_RJT response */
1623 cmd = be16_to_cpu(fdmi_cmd);
1624 if (fdmi_rsp == cpu_to_be16(SLI_CT_RESPONSE_FS_RJT)) {
1625 /* FDMI rsp failed */
1626 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1627 "0220 FDMI cmd failed FS_RJT Data: x%x", cmd);
1629 /* Should we fallback to FDMI-2 / FDMI-1 ? */
1630 switch (cmd) {
1631 case SLI_MGMT_RHBA:
1632 if (vport->fdmi_hba_mask == LPFC_FDMI2_HBA_ATTR) {
1633 /* Fallback to FDMI-1 */
1634 vport->fdmi_hba_mask = LPFC_FDMI1_HBA_ATTR;
1635 vport->fdmi_port_mask = LPFC_FDMI1_PORT_ATTR;
1636 /* Start over */
1637 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA, 0);
1639 return;
1641 case SLI_MGMT_RPRT:
1642 if (vport->fdmi_port_mask == LPFC_FDMI2_PORT_ATTR) {
1643 /* Fallback to FDMI-1 */
1644 vport->fdmi_port_mask = LPFC_FDMI1_PORT_ATTR;
1645 /* Start over */
1646 lpfc_fdmi_cmd(vport, ndlp, cmd, 0);
1648 if (vport->fdmi_port_mask == LPFC_FDMI2_SMART_ATTR) {
1649 vport->fdmi_port_mask = LPFC_FDMI2_PORT_ATTR;
1650 /* Retry the same command */
1651 lpfc_fdmi_cmd(vport, ndlp, cmd, 0);
1653 return;
1655 case SLI_MGMT_RPA:
1656 if (vport->fdmi_port_mask == LPFC_FDMI2_PORT_ATTR) {
1657 /* Fallback to FDMI-1 */
1658 vport->fdmi_hba_mask = LPFC_FDMI1_HBA_ATTR;
1659 vport->fdmi_port_mask = LPFC_FDMI1_PORT_ATTR;
1660 /* Start over */
1661 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA, 0);
1663 if (vport->fdmi_port_mask == LPFC_FDMI2_SMART_ATTR) {
1664 vport->fdmi_port_mask = LPFC_FDMI2_PORT_ATTR;
1665 /* Retry the same command */
1666 lpfc_fdmi_cmd(vport, ndlp, cmd, 0);
1668 return;
1673 * On success, need to cycle thru FDMI registration for discovery
1674 * DHBA -> DPRT -> RHBA -> RPA (physical port)
1675 * DPRT -> RPRT (vports)
1677 switch (cmd) {
1678 case SLI_MGMT_RHBA:
1679 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RPA, 0);
1680 break;
1682 case SLI_MGMT_DHBA:
1683 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DPRT, 0);
1684 break;
1686 case SLI_MGMT_DPRT:
1687 if (vport->port_type == LPFC_PHYSICAL_PORT)
1688 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RHBA, 0);
1689 else
1690 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RPRT, 0);
1691 break;
1693 return;
1698 * lpfc_fdmi_num_disc_check - Check how many mapped NPorts we are connected to
1699 * @vport: pointer to a host virtual N_Port data structure.
1701 * Called from hbeat timeout routine to check if the number of discovered
1702 * ports has changed. If so, re-register thar port Attribute.
1704 void
1705 lpfc_fdmi_num_disc_check(struct lpfc_vport *vport)
1707 struct lpfc_hba *phba = vport->phba;
1708 struct lpfc_nodelist *ndlp;
1709 uint16_t cnt;
1711 if (!lpfc_is_link_up(phba))
1712 return;
1714 /* Must be connected to a Fabric */
1715 if (!(vport->fc_flag & FC_FABRIC))
1716 return;
1718 if (!(vport->fdmi_port_mask & LPFC_FDMI_PORT_ATTR_num_disc))
1719 return;
1721 cnt = lpfc_find_map_node(vport);
1722 if (cnt == vport->fdmi_num_disc)
1723 return;
1725 ndlp = lpfc_findnode_did(vport, FDMI_DID);
1726 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
1727 return;
1729 if (vport->port_type == LPFC_PHYSICAL_PORT) {
1730 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RPA,
1731 LPFC_FDMI_PORT_ATTR_num_disc);
1732 } else {
1733 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RPRT,
1734 LPFC_FDMI_PORT_ATTR_num_disc);
1738 /* Routines for all individual HBA attributes */
1739 static int
1740 lpfc_fdmi_hba_attr_wwnn(struct lpfc_vport *vport, struct lpfc_fdmi_attr_def *ad)
1742 struct lpfc_fdmi_attr_entry *ae;
1743 uint32_t size;
1745 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
1746 memset(ae, 0, sizeof(struct lpfc_name));
1748 memcpy(&ae->un.AttrWWN, &vport->fc_sparam.nodeName,
1749 sizeof(struct lpfc_name));
1750 size = FOURBYTES + sizeof(struct lpfc_name);
1751 ad->AttrLen = cpu_to_be16(size);
1752 ad->AttrType = cpu_to_be16(RHBA_NODENAME);
1753 return size;
1755 static int
1756 lpfc_fdmi_hba_attr_manufacturer(struct lpfc_vport *vport,
1757 struct lpfc_fdmi_attr_def *ad)
1759 struct lpfc_fdmi_attr_entry *ae;
1760 uint32_t len, size;
1762 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
1763 memset(ae, 0, 256);
1765 strncpy(ae->un.AttrString,
1766 "Emulex Corporation",
1767 sizeof(ae->un.AttrString));
1768 len = strnlen(ae->un.AttrString,
1769 sizeof(ae->un.AttrString));
1770 len += (len & 3) ? (4 - (len & 3)) : 4;
1771 size = FOURBYTES + len;
1772 ad->AttrLen = cpu_to_be16(size);
1773 ad->AttrType = cpu_to_be16(RHBA_MANUFACTURER);
1774 return size;
1777 static int
1778 lpfc_fdmi_hba_attr_sn(struct lpfc_vport *vport, struct lpfc_fdmi_attr_def *ad)
1780 struct lpfc_hba *phba = vport->phba;
1781 struct lpfc_fdmi_attr_entry *ae;
1782 uint32_t len, size;
1784 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
1785 memset(ae, 0, 256);
1787 strncpy(ae->un.AttrString, phba->SerialNumber,
1788 sizeof(ae->un.AttrString));
1789 len = strnlen(ae->un.AttrString,
1790 sizeof(ae->un.AttrString));
1791 len += (len & 3) ? (4 - (len & 3)) : 4;
1792 size = FOURBYTES + len;
1793 ad->AttrLen = cpu_to_be16(size);
1794 ad->AttrType = cpu_to_be16(RHBA_SERIAL_NUMBER);
1795 return size;
1798 static int
1799 lpfc_fdmi_hba_attr_model(struct lpfc_vport *vport,
1800 struct lpfc_fdmi_attr_def *ad)
1802 struct lpfc_hba *phba = vport->phba;
1803 struct lpfc_fdmi_attr_entry *ae;
1804 uint32_t len, size;
1806 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
1807 memset(ae, 0, 256);
1809 strncpy(ae->un.AttrString, phba->ModelName,
1810 sizeof(ae->un.AttrString));
1811 len = strnlen(ae->un.AttrString, sizeof(ae->un.AttrString));
1812 len += (len & 3) ? (4 - (len & 3)) : 4;
1813 size = FOURBYTES + len;
1814 ad->AttrLen = cpu_to_be16(size);
1815 ad->AttrType = cpu_to_be16(RHBA_MODEL);
1816 return size;
1819 static int
1820 lpfc_fdmi_hba_attr_description(struct lpfc_vport *vport,
1821 struct lpfc_fdmi_attr_def *ad)
1823 struct lpfc_hba *phba = vport->phba;
1824 struct lpfc_fdmi_attr_entry *ae;
1825 uint32_t len, size;
1827 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
1828 memset(ae, 0, 256);
1830 strncpy(ae->un.AttrString, phba->ModelDesc,
1831 sizeof(ae->un.AttrString));
1832 len = strnlen(ae->un.AttrString,
1833 sizeof(ae->un.AttrString));
1834 len += (len & 3) ? (4 - (len & 3)) : 4;
1835 size = FOURBYTES + len;
1836 ad->AttrLen = cpu_to_be16(size);
1837 ad->AttrType = cpu_to_be16(RHBA_MODEL_DESCRIPTION);
1838 return size;
1841 static int
1842 lpfc_fdmi_hba_attr_hdw_ver(struct lpfc_vport *vport,
1843 struct lpfc_fdmi_attr_def *ad)
1845 struct lpfc_hba *phba = vport->phba;
1846 lpfc_vpd_t *vp = &phba->vpd;
1847 struct lpfc_fdmi_attr_entry *ae;
1848 uint32_t i, j, incr, size;
1850 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
1851 memset(ae, 0, 256);
1853 /* Convert JEDEC ID to ascii for hardware version */
1854 incr = vp->rev.biuRev;
1855 for (i = 0; i < 8; i++) {
1856 j = (incr & 0xf);
1857 if (j <= 9)
1858 ae->un.AttrString[7 - i] =
1859 (char)((uint8_t) 0x30 +
1860 (uint8_t) j);
1861 else
1862 ae->un.AttrString[7 - i] =
1863 (char)((uint8_t) 0x61 +
1864 (uint8_t) (j - 10));
1865 incr = (incr >> 4);
1867 size = FOURBYTES + 8;
1868 ad->AttrLen = cpu_to_be16(size);
1869 ad->AttrType = cpu_to_be16(RHBA_HARDWARE_VERSION);
1870 return size;
1873 static int
1874 lpfc_fdmi_hba_attr_drvr_ver(struct lpfc_vport *vport,
1875 struct lpfc_fdmi_attr_def *ad)
1877 struct lpfc_fdmi_attr_entry *ae;
1878 uint32_t len, size;
1880 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
1881 memset(ae, 0, 256);
1883 strncpy(ae->un.AttrString, lpfc_release_version,
1884 sizeof(ae->un.AttrString));
1885 len = strnlen(ae->un.AttrString,
1886 sizeof(ae->un.AttrString));
1887 len += (len & 3) ? (4 - (len & 3)) : 4;
1888 size = FOURBYTES + len;
1889 ad->AttrLen = cpu_to_be16(size);
1890 ad->AttrType = cpu_to_be16(RHBA_DRIVER_VERSION);
1891 return size;
1894 static int
1895 lpfc_fdmi_hba_attr_rom_ver(struct lpfc_vport *vport,
1896 struct lpfc_fdmi_attr_def *ad)
1898 struct lpfc_hba *phba = vport->phba;
1899 struct lpfc_fdmi_attr_entry *ae;
1900 uint32_t len, size;
1902 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
1903 memset(ae, 0, 256);
1905 if (phba->sli_rev == LPFC_SLI_REV4)
1906 lpfc_decode_firmware_rev(phba, ae->un.AttrString, 1);
1907 else
1908 strncpy(ae->un.AttrString, phba->OptionROMVersion,
1909 sizeof(ae->un.AttrString));
1910 len = strnlen(ae->un.AttrString,
1911 sizeof(ae->un.AttrString));
1912 len += (len & 3) ? (4 - (len & 3)) : 4;
1913 size = FOURBYTES + len;
1914 ad->AttrLen = cpu_to_be16(size);
1915 ad->AttrType = cpu_to_be16(RHBA_OPTION_ROM_VERSION);
1916 return size;
1919 static int
1920 lpfc_fdmi_hba_attr_fmw_ver(struct lpfc_vport *vport,
1921 struct lpfc_fdmi_attr_def *ad)
1923 struct lpfc_hba *phba = vport->phba;
1924 struct lpfc_fdmi_attr_entry *ae;
1925 uint32_t len, size;
1927 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
1928 memset(ae, 0, 256);
1930 lpfc_decode_firmware_rev(phba, ae->un.AttrString, 1);
1931 len = strnlen(ae->un.AttrString,
1932 sizeof(ae->un.AttrString));
1933 len += (len & 3) ? (4 - (len & 3)) : 4;
1934 size = FOURBYTES + len;
1935 ad->AttrLen = cpu_to_be16(size);
1936 ad->AttrType = cpu_to_be16(RHBA_FIRMWARE_VERSION);
1937 return size;
1940 static int
1941 lpfc_fdmi_hba_attr_os_ver(struct lpfc_vport *vport,
1942 struct lpfc_fdmi_attr_def *ad)
1944 struct lpfc_fdmi_attr_entry *ae;
1945 uint32_t len, size;
1947 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
1948 memset(ae, 0, 256);
1950 snprintf(ae->un.AttrString, sizeof(ae->un.AttrString), "%s %s %s",
1951 init_utsname()->sysname,
1952 init_utsname()->release,
1953 init_utsname()->version);
1955 len = strnlen(ae->un.AttrString, sizeof(ae->un.AttrString));
1956 len += (len & 3) ? (4 - (len & 3)) : 4;
1957 size = FOURBYTES + len;
1958 ad->AttrLen = cpu_to_be16(size);
1959 ad->AttrType = cpu_to_be16(RHBA_OS_NAME_VERSION);
1960 return size;
1963 static int
1964 lpfc_fdmi_hba_attr_ct_len(struct lpfc_vport *vport,
1965 struct lpfc_fdmi_attr_def *ad)
1967 struct lpfc_fdmi_attr_entry *ae;
1968 uint32_t size;
1970 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
1972 ae->un.AttrInt = cpu_to_be32(LPFC_MAX_CT_SIZE);
1973 size = FOURBYTES + sizeof(uint32_t);
1974 ad->AttrLen = cpu_to_be16(size);
1975 ad->AttrType = cpu_to_be16(RHBA_MAX_CT_PAYLOAD_LEN);
1976 return size;
1979 static int
1980 lpfc_fdmi_hba_attr_symbolic_name(struct lpfc_vport *vport,
1981 struct lpfc_fdmi_attr_def *ad)
1983 struct lpfc_fdmi_attr_entry *ae;
1984 uint32_t len, size;
1986 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
1987 memset(ae, 0, 256);
1989 len = lpfc_vport_symbolic_node_name(vport,
1990 ae->un.AttrString, 256);
1991 len += (len & 3) ? (4 - (len & 3)) : 4;
1992 size = FOURBYTES + len;
1993 ad->AttrLen = cpu_to_be16(size);
1994 ad->AttrType = cpu_to_be16(RHBA_SYM_NODENAME);
1995 return size;
1998 static int
1999 lpfc_fdmi_hba_attr_vendor_info(struct lpfc_vport *vport,
2000 struct lpfc_fdmi_attr_def *ad)
2002 struct lpfc_fdmi_attr_entry *ae;
2003 uint32_t size;
2005 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2007 /* Nothing is defined for this currently */
2008 ae->un.AttrInt = cpu_to_be32(0);
2009 size = FOURBYTES + sizeof(uint32_t);
2010 ad->AttrLen = cpu_to_be16(size);
2011 ad->AttrType = cpu_to_be16(RHBA_VENDOR_INFO);
2012 return size;
2015 static int
2016 lpfc_fdmi_hba_attr_num_ports(struct lpfc_vport *vport,
2017 struct lpfc_fdmi_attr_def *ad)
2019 struct lpfc_fdmi_attr_entry *ae;
2020 uint32_t size;
2022 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2024 /* Each driver instance corresponds to a single port */
2025 ae->un.AttrInt = cpu_to_be32(1);
2026 size = FOURBYTES + sizeof(uint32_t);
2027 ad->AttrLen = cpu_to_be16(size);
2028 ad->AttrType = cpu_to_be16(RHBA_NUM_PORTS);
2029 return size;
2032 static int
2033 lpfc_fdmi_hba_attr_fabric_wwnn(struct lpfc_vport *vport,
2034 struct lpfc_fdmi_attr_def *ad)
2036 struct lpfc_fdmi_attr_entry *ae;
2037 uint32_t size;
2039 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2040 memset(ae, 0, sizeof(struct lpfc_name));
2042 memcpy(&ae->un.AttrWWN, &vport->fabric_nodename,
2043 sizeof(struct lpfc_name));
2044 size = FOURBYTES + sizeof(struct lpfc_name);
2045 ad->AttrLen = cpu_to_be16(size);
2046 ad->AttrType = cpu_to_be16(RHBA_FABRIC_WWNN);
2047 return size;
2050 static int
2051 lpfc_fdmi_hba_attr_bios_ver(struct lpfc_vport *vport,
2052 struct lpfc_fdmi_attr_def *ad)
2054 struct lpfc_hba *phba = vport->phba;
2055 struct lpfc_fdmi_attr_entry *ae;
2056 uint32_t len, size;
2058 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2059 memset(ae, 0, 256);
2061 lpfc_decode_firmware_rev(phba, ae->un.AttrString, 1);
2062 len = strnlen(ae->un.AttrString,
2063 sizeof(ae->un.AttrString));
2064 len += (len & 3) ? (4 - (len & 3)) : 4;
2065 size = FOURBYTES + len;
2066 ad->AttrLen = cpu_to_be16(size);
2067 ad->AttrType = cpu_to_be16(RHBA_BIOS_VERSION);
2068 return size;
2071 static int
2072 lpfc_fdmi_hba_attr_bios_state(struct lpfc_vport *vport,
2073 struct lpfc_fdmi_attr_def *ad)
2075 struct lpfc_fdmi_attr_entry *ae;
2076 uint32_t size;
2078 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2080 /* Driver doesn't have access to this information */
2081 ae->un.AttrInt = cpu_to_be32(0);
2082 size = FOURBYTES + sizeof(uint32_t);
2083 ad->AttrLen = cpu_to_be16(size);
2084 ad->AttrType = cpu_to_be16(RHBA_BIOS_STATE);
2085 return size;
2088 static int
2089 lpfc_fdmi_hba_attr_vendor_id(struct lpfc_vport *vport,
2090 struct lpfc_fdmi_attr_def *ad)
2092 struct lpfc_fdmi_attr_entry *ae;
2093 uint32_t len, size;
2095 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2096 memset(ae, 0, 256);
2098 strncpy(ae->un.AttrString, "EMULEX",
2099 sizeof(ae->un.AttrString));
2100 len = strnlen(ae->un.AttrString,
2101 sizeof(ae->un.AttrString));
2102 len += (len & 3) ? (4 - (len & 3)) : 4;
2103 size = FOURBYTES + len;
2104 ad->AttrLen = cpu_to_be16(size);
2105 ad->AttrType = cpu_to_be16(RHBA_VENDOR_ID);
2106 return size;
2109 /* Routines for all individual PORT attributes */
2110 static int
2111 lpfc_fdmi_port_attr_fc4type(struct lpfc_vport *vport,
2112 struct lpfc_fdmi_attr_def *ad)
2114 struct lpfc_fdmi_attr_entry *ae;
2115 uint32_t size;
2117 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2118 memset(ae, 0, 32);
2120 ae->un.AttrTypes[3] = 0x02; /* Type 1 - ELS */
2121 ae->un.AttrTypes[2] = 0x01; /* Type 8 - FCP */
2122 ae->un.AttrTypes[6] = 0x01; /* Type 40 - NVME */
2123 ae->un.AttrTypes[7] = 0x01; /* Type 32 - CT */
2124 size = FOURBYTES + 32;
2125 ad->AttrLen = cpu_to_be16(size);
2126 ad->AttrType = cpu_to_be16(RPRT_SUPPORTED_FC4_TYPES);
2127 return size;
2130 static int
2131 lpfc_fdmi_port_attr_support_speed(struct lpfc_vport *vport,
2132 struct lpfc_fdmi_attr_def *ad)
2134 struct lpfc_hba *phba = vport->phba;
2135 struct lpfc_fdmi_attr_entry *ae;
2136 uint32_t size;
2138 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2140 ae->un.AttrInt = 0;
2141 if (!(phba->hba_flag & HBA_FCOE_MODE)) {
2142 if (phba->lmt & LMT_64Gb)
2143 ae->un.AttrInt |= HBA_PORTSPEED_64GFC;
2144 if (phba->lmt & LMT_32Gb)
2145 ae->un.AttrInt |= HBA_PORTSPEED_32GFC;
2146 if (phba->lmt & LMT_16Gb)
2147 ae->un.AttrInt |= HBA_PORTSPEED_16GFC;
2148 if (phba->lmt & LMT_10Gb)
2149 ae->un.AttrInt |= HBA_PORTSPEED_10GFC;
2150 if (phba->lmt & LMT_8Gb)
2151 ae->un.AttrInt |= HBA_PORTSPEED_8GFC;
2152 if (phba->lmt & LMT_4Gb)
2153 ae->un.AttrInt |= HBA_PORTSPEED_4GFC;
2154 if (phba->lmt & LMT_2Gb)
2155 ae->un.AttrInt |= HBA_PORTSPEED_2GFC;
2156 if (phba->lmt & LMT_1Gb)
2157 ae->un.AttrInt |= HBA_PORTSPEED_1GFC;
2158 } else {
2159 /* FCoE links support only one speed */
2160 switch (phba->fc_linkspeed) {
2161 case LPFC_ASYNC_LINK_SPEED_10GBPS:
2162 ae->un.AttrInt = HBA_PORTSPEED_10GE;
2163 break;
2164 case LPFC_ASYNC_LINK_SPEED_25GBPS:
2165 ae->un.AttrInt = HBA_PORTSPEED_25GE;
2166 break;
2167 case LPFC_ASYNC_LINK_SPEED_40GBPS:
2168 ae->un.AttrInt = HBA_PORTSPEED_40GE;
2169 break;
2170 case LPFC_ASYNC_LINK_SPEED_100GBPS:
2171 ae->un.AttrInt = HBA_PORTSPEED_100GE;
2172 break;
2175 ae->un.AttrInt = cpu_to_be32(ae->un.AttrInt);
2176 size = FOURBYTES + sizeof(uint32_t);
2177 ad->AttrLen = cpu_to_be16(size);
2178 ad->AttrType = cpu_to_be16(RPRT_SUPPORTED_SPEED);
2179 return size;
2182 static int
2183 lpfc_fdmi_port_attr_speed(struct lpfc_vport *vport,
2184 struct lpfc_fdmi_attr_def *ad)
2186 struct lpfc_hba *phba = vport->phba;
2187 struct lpfc_fdmi_attr_entry *ae;
2188 uint32_t size;
2190 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2192 if (!(phba->hba_flag & HBA_FCOE_MODE)) {
2193 switch (phba->fc_linkspeed) {
2194 case LPFC_LINK_SPEED_1GHZ:
2195 ae->un.AttrInt = HBA_PORTSPEED_1GFC;
2196 break;
2197 case LPFC_LINK_SPEED_2GHZ:
2198 ae->un.AttrInt = HBA_PORTSPEED_2GFC;
2199 break;
2200 case LPFC_LINK_SPEED_4GHZ:
2201 ae->un.AttrInt = HBA_PORTSPEED_4GFC;
2202 break;
2203 case LPFC_LINK_SPEED_8GHZ:
2204 ae->un.AttrInt = HBA_PORTSPEED_8GFC;
2205 break;
2206 case LPFC_LINK_SPEED_10GHZ:
2207 ae->un.AttrInt = HBA_PORTSPEED_10GFC;
2208 break;
2209 case LPFC_LINK_SPEED_16GHZ:
2210 ae->un.AttrInt = HBA_PORTSPEED_16GFC;
2211 break;
2212 case LPFC_LINK_SPEED_32GHZ:
2213 ae->un.AttrInt = HBA_PORTSPEED_32GFC;
2214 break;
2215 case LPFC_LINK_SPEED_64GHZ:
2216 ae->un.AttrInt = HBA_PORTSPEED_64GFC;
2217 break;
2218 default:
2219 ae->un.AttrInt = HBA_PORTSPEED_UNKNOWN;
2220 break;
2222 } else {
2223 switch (phba->fc_linkspeed) {
2224 case LPFC_ASYNC_LINK_SPEED_10GBPS:
2225 ae->un.AttrInt = HBA_PORTSPEED_10GE;
2226 break;
2227 case LPFC_ASYNC_LINK_SPEED_25GBPS:
2228 ae->un.AttrInt = HBA_PORTSPEED_25GE;
2229 break;
2230 case LPFC_ASYNC_LINK_SPEED_40GBPS:
2231 ae->un.AttrInt = HBA_PORTSPEED_40GE;
2232 break;
2233 case LPFC_ASYNC_LINK_SPEED_100GBPS:
2234 ae->un.AttrInt = HBA_PORTSPEED_100GE;
2235 break;
2236 default:
2237 ae->un.AttrInt = HBA_PORTSPEED_UNKNOWN;
2238 break;
2242 ae->un.AttrInt = cpu_to_be32(ae->un.AttrInt);
2243 size = FOURBYTES + sizeof(uint32_t);
2244 ad->AttrLen = cpu_to_be16(size);
2245 ad->AttrType = cpu_to_be16(RPRT_PORT_SPEED);
2246 return size;
2249 static int
2250 lpfc_fdmi_port_attr_max_frame(struct lpfc_vport *vport,
2251 struct lpfc_fdmi_attr_def *ad)
2253 struct serv_parm *hsp;
2254 struct lpfc_fdmi_attr_entry *ae;
2255 uint32_t size;
2257 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2259 hsp = (struct serv_parm *)&vport->fc_sparam;
2260 ae->un.AttrInt = (((uint32_t) hsp->cmn.bbRcvSizeMsb) << 8) |
2261 (uint32_t) hsp->cmn.bbRcvSizeLsb;
2262 ae->un.AttrInt = cpu_to_be32(ae->un.AttrInt);
2263 size = FOURBYTES + sizeof(uint32_t);
2264 ad->AttrLen = cpu_to_be16(size);
2265 ad->AttrType = cpu_to_be16(RPRT_MAX_FRAME_SIZE);
2266 return size;
2269 static int
2270 lpfc_fdmi_port_attr_os_devname(struct lpfc_vport *vport,
2271 struct lpfc_fdmi_attr_def *ad)
2273 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2274 struct lpfc_fdmi_attr_entry *ae;
2275 uint32_t len, size;
2277 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2278 memset(ae, 0, 256);
2280 snprintf(ae->un.AttrString, sizeof(ae->un.AttrString),
2281 "/sys/class/scsi_host/host%d", shost->host_no);
2282 len = strnlen((char *)ae->un.AttrString,
2283 sizeof(ae->un.AttrString));
2284 len += (len & 3) ? (4 - (len & 3)) : 4;
2285 size = FOURBYTES + len;
2286 ad->AttrLen = cpu_to_be16(size);
2287 ad->AttrType = cpu_to_be16(RPRT_OS_DEVICE_NAME);
2288 return size;
2291 static int
2292 lpfc_fdmi_port_attr_host_name(struct lpfc_vport *vport,
2293 struct lpfc_fdmi_attr_def *ad)
2295 struct lpfc_fdmi_attr_entry *ae;
2296 uint32_t len, size;
2298 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2299 memset(ae, 0, 256);
2301 snprintf(ae->un.AttrString, sizeof(ae->un.AttrString), "%s",
2302 init_utsname()->nodename);
2304 len = strnlen(ae->un.AttrString, sizeof(ae->un.AttrString));
2305 len += (len & 3) ? (4 - (len & 3)) : 4;
2306 size = FOURBYTES + len;
2307 ad->AttrLen = cpu_to_be16(size);
2308 ad->AttrType = cpu_to_be16(RPRT_HOST_NAME);
2309 return size;
2312 static int
2313 lpfc_fdmi_port_attr_wwnn(struct lpfc_vport *vport,
2314 struct lpfc_fdmi_attr_def *ad)
2316 struct lpfc_fdmi_attr_entry *ae;
2317 uint32_t size;
2319 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2320 memset(ae, 0, sizeof(struct lpfc_name));
2322 memcpy(&ae->un.AttrWWN, &vport->fc_sparam.nodeName,
2323 sizeof(struct lpfc_name));
2324 size = FOURBYTES + sizeof(struct lpfc_name);
2325 ad->AttrLen = cpu_to_be16(size);
2326 ad->AttrType = cpu_to_be16(RPRT_NODENAME);
2327 return size;
2330 static int
2331 lpfc_fdmi_port_attr_wwpn(struct lpfc_vport *vport,
2332 struct lpfc_fdmi_attr_def *ad)
2334 struct lpfc_fdmi_attr_entry *ae;
2335 uint32_t size;
2337 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2338 memset(ae, 0, sizeof(struct lpfc_name));
2340 memcpy(&ae->un.AttrWWN, &vport->fc_sparam.portName,
2341 sizeof(struct lpfc_name));
2342 size = FOURBYTES + sizeof(struct lpfc_name);
2343 ad->AttrLen = cpu_to_be16(size);
2344 ad->AttrType = cpu_to_be16(RPRT_PORTNAME);
2345 return size;
2348 static int
2349 lpfc_fdmi_port_attr_symbolic_name(struct lpfc_vport *vport,
2350 struct lpfc_fdmi_attr_def *ad)
2352 struct lpfc_fdmi_attr_entry *ae;
2353 uint32_t len, size;
2355 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2356 memset(ae, 0, 256);
2358 len = lpfc_vport_symbolic_port_name(vport, ae->un.AttrString, 256);
2359 len += (len & 3) ? (4 - (len & 3)) : 4;
2360 size = FOURBYTES + len;
2361 ad->AttrLen = cpu_to_be16(size);
2362 ad->AttrType = cpu_to_be16(RPRT_SYM_PORTNAME);
2363 return size;
2366 static int
2367 lpfc_fdmi_port_attr_port_type(struct lpfc_vport *vport,
2368 struct lpfc_fdmi_attr_def *ad)
2370 struct lpfc_hba *phba = vport->phba;
2371 struct lpfc_fdmi_attr_entry *ae;
2372 uint32_t size;
2374 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2375 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP)
2376 ae->un.AttrInt = cpu_to_be32(LPFC_FDMI_PORTTYPE_NLPORT);
2377 else
2378 ae->un.AttrInt = cpu_to_be32(LPFC_FDMI_PORTTYPE_NPORT);
2379 size = FOURBYTES + sizeof(uint32_t);
2380 ad->AttrLen = cpu_to_be16(size);
2381 ad->AttrType = cpu_to_be16(RPRT_PORT_TYPE);
2382 return size;
2385 static int
2386 lpfc_fdmi_port_attr_class(struct lpfc_vport *vport,
2387 struct lpfc_fdmi_attr_def *ad)
2389 struct lpfc_fdmi_attr_entry *ae;
2390 uint32_t size;
2392 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2393 ae->un.AttrInt = cpu_to_be32(FC_COS_CLASS2 | FC_COS_CLASS3);
2394 size = FOURBYTES + sizeof(uint32_t);
2395 ad->AttrLen = cpu_to_be16(size);
2396 ad->AttrType = cpu_to_be16(RPRT_SUPPORTED_CLASS);
2397 return size;
2400 static int
2401 lpfc_fdmi_port_attr_fabric_wwpn(struct lpfc_vport *vport,
2402 struct lpfc_fdmi_attr_def *ad)
2404 struct lpfc_fdmi_attr_entry *ae;
2405 uint32_t size;
2407 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2408 memset(ae, 0, sizeof(struct lpfc_name));
2410 memcpy(&ae->un.AttrWWN, &vport->fabric_portname,
2411 sizeof(struct lpfc_name));
2412 size = FOURBYTES + sizeof(struct lpfc_name);
2413 ad->AttrLen = cpu_to_be16(size);
2414 ad->AttrType = cpu_to_be16(RPRT_FABRICNAME);
2415 return size;
2418 static int
2419 lpfc_fdmi_port_attr_active_fc4type(struct lpfc_vport *vport,
2420 struct lpfc_fdmi_attr_def *ad)
2422 struct lpfc_fdmi_attr_entry *ae;
2423 uint32_t size;
2425 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2426 memset(ae, 0, 32);
2428 ae->un.AttrTypes[3] = 0x02; /* Type 1 - ELS */
2429 ae->un.AttrTypes[2] = 0x01; /* Type 8 - FCP */
2430 ae->un.AttrTypes[7] = 0x01; /* Type 32 - CT */
2431 size = FOURBYTES + 32;
2432 ad->AttrLen = cpu_to_be16(size);
2433 ad->AttrType = cpu_to_be16(RPRT_ACTIVE_FC4_TYPES);
2434 return size;
2437 static int
2438 lpfc_fdmi_port_attr_port_state(struct lpfc_vport *vport,
2439 struct lpfc_fdmi_attr_def *ad)
2441 struct lpfc_fdmi_attr_entry *ae;
2442 uint32_t size;
2444 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2445 /* Link Up - operational */
2446 ae->un.AttrInt = cpu_to_be32(LPFC_FDMI_PORTSTATE_ONLINE);
2447 size = FOURBYTES + sizeof(uint32_t);
2448 ad->AttrLen = cpu_to_be16(size);
2449 ad->AttrType = cpu_to_be16(RPRT_PORT_STATE);
2450 return size;
2453 static int
2454 lpfc_fdmi_port_attr_num_disc(struct lpfc_vport *vport,
2455 struct lpfc_fdmi_attr_def *ad)
2457 struct lpfc_fdmi_attr_entry *ae;
2458 uint32_t size;
2460 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2461 vport->fdmi_num_disc = lpfc_find_map_node(vport);
2462 ae->un.AttrInt = cpu_to_be32(vport->fdmi_num_disc);
2463 size = FOURBYTES + sizeof(uint32_t);
2464 ad->AttrLen = cpu_to_be16(size);
2465 ad->AttrType = cpu_to_be16(RPRT_DISC_PORT);
2466 return size;
2469 static int
2470 lpfc_fdmi_port_attr_nportid(struct lpfc_vport *vport,
2471 struct lpfc_fdmi_attr_def *ad)
2473 struct lpfc_fdmi_attr_entry *ae;
2474 uint32_t size;
2476 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2477 ae->un.AttrInt = cpu_to_be32(vport->fc_myDID);
2478 size = FOURBYTES + sizeof(uint32_t);
2479 ad->AttrLen = cpu_to_be16(size);
2480 ad->AttrType = cpu_to_be16(RPRT_PORT_ID);
2481 return size;
2484 static int
2485 lpfc_fdmi_smart_attr_service(struct lpfc_vport *vport,
2486 struct lpfc_fdmi_attr_def *ad)
2488 struct lpfc_fdmi_attr_entry *ae;
2489 uint32_t len, size;
2491 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2492 memset(ae, 0, 256);
2494 strncpy(ae->un.AttrString, "Smart SAN Initiator",
2495 sizeof(ae->un.AttrString));
2496 len = strnlen(ae->un.AttrString,
2497 sizeof(ae->un.AttrString));
2498 len += (len & 3) ? (4 - (len & 3)) : 4;
2499 size = FOURBYTES + len;
2500 ad->AttrLen = cpu_to_be16(size);
2501 ad->AttrType = cpu_to_be16(RPRT_SMART_SERVICE);
2502 return size;
2505 static int
2506 lpfc_fdmi_smart_attr_guid(struct lpfc_vport *vport,
2507 struct lpfc_fdmi_attr_def *ad)
2509 struct lpfc_fdmi_attr_entry *ae;
2510 uint32_t size;
2512 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2513 memset(ae, 0, 256);
2515 memcpy(&ae->un.AttrString, &vport->fc_sparam.nodeName,
2516 sizeof(struct lpfc_name));
2517 memcpy((((uint8_t *)&ae->un.AttrString) +
2518 sizeof(struct lpfc_name)),
2519 &vport->fc_sparam.portName, sizeof(struct lpfc_name));
2520 size = FOURBYTES + (2 * sizeof(struct lpfc_name));
2521 ad->AttrLen = cpu_to_be16(size);
2522 ad->AttrType = cpu_to_be16(RPRT_SMART_GUID);
2523 return size;
2526 static int
2527 lpfc_fdmi_smart_attr_version(struct lpfc_vport *vport,
2528 struct lpfc_fdmi_attr_def *ad)
2530 struct lpfc_fdmi_attr_entry *ae;
2531 uint32_t len, size;
2533 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2534 memset(ae, 0, 256);
2536 strncpy(ae->un.AttrString, "Smart SAN Version 2.0",
2537 sizeof(ae->un.AttrString));
2538 len = strnlen(ae->un.AttrString,
2539 sizeof(ae->un.AttrString));
2540 len += (len & 3) ? (4 - (len & 3)) : 4;
2541 size = FOURBYTES + len;
2542 ad->AttrLen = cpu_to_be16(size);
2543 ad->AttrType = cpu_to_be16(RPRT_SMART_VERSION);
2544 return size;
2547 static int
2548 lpfc_fdmi_smart_attr_model(struct lpfc_vport *vport,
2549 struct lpfc_fdmi_attr_def *ad)
2551 struct lpfc_hba *phba = vport->phba;
2552 struct lpfc_fdmi_attr_entry *ae;
2553 uint32_t len, size;
2555 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2556 memset(ae, 0, 256);
2558 strncpy(ae->un.AttrString, phba->ModelName,
2559 sizeof(ae->un.AttrString));
2560 len = strnlen(ae->un.AttrString, sizeof(ae->un.AttrString));
2561 len += (len & 3) ? (4 - (len & 3)) : 4;
2562 size = FOURBYTES + len;
2563 ad->AttrLen = cpu_to_be16(size);
2564 ad->AttrType = cpu_to_be16(RPRT_SMART_MODEL);
2565 return size;
2568 static int
2569 lpfc_fdmi_smart_attr_port_info(struct lpfc_vport *vport,
2570 struct lpfc_fdmi_attr_def *ad)
2572 struct lpfc_fdmi_attr_entry *ae;
2573 uint32_t size;
2575 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2577 /* SRIOV (type 3) is not supported */
2578 if (vport->vpi)
2579 ae->un.AttrInt = cpu_to_be32(2); /* NPIV */
2580 else
2581 ae->un.AttrInt = cpu_to_be32(1); /* Physical */
2582 size = FOURBYTES + sizeof(uint32_t);
2583 ad->AttrLen = cpu_to_be16(size);
2584 ad->AttrType = cpu_to_be16(RPRT_SMART_PORT_INFO);
2585 return size;
2588 static int
2589 lpfc_fdmi_smart_attr_qos(struct lpfc_vport *vport,
2590 struct lpfc_fdmi_attr_def *ad)
2592 struct lpfc_fdmi_attr_entry *ae;
2593 uint32_t size;
2595 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2596 ae->un.AttrInt = cpu_to_be32(0);
2597 size = FOURBYTES + sizeof(uint32_t);
2598 ad->AttrLen = cpu_to_be16(size);
2599 ad->AttrType = cpu_to_be16(RPRT_SMART_QOS);
2600 return size;
2603 static int
2604 lpfc_fdmi_smart_attr_security(struct lpfc_vport *vport,
2605 struct lpfc_fdmi_attr_def *ad)
2607 struct lpfc_fdmi_attr_entry *ae;
2608 uint32_t size;
2610 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2611 ae->un.AttrInt = cpu_to_be32(1);
2612 size = FOURBYTES + sizeof(uint32_t);
2613 ad->AttrLen = cpu_to_be16(size);
2614 ad->AttrType = cpu_to_be16(RPRT_SMART_SECURITY);
2615 return size;
2618 /* RHBA attribute jump table */
2619 int (*lpfc_fdmi_hba_action[])
2620 (struct lpfc_vport *vport, struct lpfc_fdmi_attr_def *ad) = {
2621 /* Action routine Mask bit Attribute type */
2622 lpfc_fdmi_hba_attr_wwnn, /* bit0 RHBA_NODENAME */
2623 lpfc_fdmi_hba_attr_manufacturer, /* bit1 RHBA_MANUFACTURER */
2624 lpfc_fdmi_hba_attr_sn, /* bit2 RHBA_SERIAL_NUMBER */
2625 lpfc_fdmi_hba_attr_model, /* bit3 RHBA_MODEL */
2626 lpfc_fdmi_hba_attr_description, /* bit4 RHBA_MODEL_DESCRIPTION */
2627 lpfc_fdmi_hba_attr_hdw_ver, /* bit5 RHBA_HARDWARE_VERSION */
2628 lpfc_fdmi_hba_attr_drvr_ver, /* bit6 RHBA_DRIVER_VERSION */
2629 lpfc_fdmi_hba_attr_rom_ver, /* bit7 RHBA_OPTION_ROM_VERSION */
2630 lpfc_fdmi_hba_attr_fmw_ver, /* bit8 RHBA_FIRMWARE_VERSION */
2631 lpfc_fdmi_hba_attr_os_ver, /* bit9 RHBA_OS_NAME_VERSION */
2632 lpfc_fdmi_hba_attr_ct_len, /* bit10 RHBA_MAX_CT_PAYLOAD_LEN */
2633 lpfc_fdmi_hba_attr_symbolic_name, /* bit11 RHBA_SYM_NODENAME */
2634 lpfc_fdmi_hba_attr_vendor_info, /* bit12 RHBA_VENDOR_INFO */
2635 lpfc_fdmi_hba_attr_num_ports, /* bit13 RHBA_NUM_PORTS */
2636 lpfc_fdmi_hba_attr_fabric_wwnn, /* bit14 RHBA_FABRIC_WWNN */
2637 lpfc_fdmi_hba_attr_bios_ver, /* bit15 RHBA_BIOS_VERSION */
2638 lpfc_fdmi_hba_attr_bios_state, /* bit16 RHBA_BIOS_STATE */
2639 lpfc_fdmi_hba_attr_vendor_id, /* bit17 RHBA_VENDOR_ID */
2642 /* RPA / RPRT attribute jump table */
2643 int (*lpfc_fdmi_port_action[])
2644 (struct lpfc_vport *vport, struct lpfc_fdmi_attr_def *ad) = {
2645 /* Action routine Mask bit Attribute type */
2646 lpfc_fdmi_port_attr_fc4type, /* bit0 RPRT_SUPPORT_FC4_TYPES */
2647 lpfc_fdmi_port_attr_support_speed, /* bit1 RPRT_SUPPORTED_SPEED */
2648 lpfc_fdmi_port_attr_speed, /* bit2 RPRT_PORT_SPEED */
2649 lpfc_fdmi_port_attr_max_frame, /* bit3 RPRT_MAX_FRAME_SIZE */
2650 lpfc_fdmi_port_attr_os_devname, /* bit4 RPRT_OS_DEVICE_NAME */
2651 lpfc_fdmi_port_attr_host_name, /* bit5 RPRT_HOST_NAME */
2652 lpfc_fdmi_port_attr_wwnn, /* bit6 RPRT_NODENAME */
2653 lpfc_fdmi_port_attr_wwpn, /* bit7 RPRT_PORTNAME */
2654 lpfc_fdmi_port_attr_symbolic_name, /* bit8 RPRT_SYM_PORTNAME */
2655 lpfc_fdmi_port_attr_port_type, /* bit9 RPRT_PORT_TYPE */
2656 lpfc_fdmi_port_attr_class, /* bit10 RPRT_SUPPORTED_CLASS */
2657 lpfc_fdmi_port_attr_fabric_wwpn, /* bit11 RPRT_FABRICNAME */
2658 lpfc_fdmi_port_attr_active_fc4type, /* bit12 RPRT_ACTIVE_FC4_TYPES */
2659 lpfc_fdmi_port_attr_port_state, /* bit13 RPRT_PORT_STATE */
2660 lpfc_fdmi_port_attr_num_disc, /* bit14 RPRT_DISC_PORT */
2661 lpfc_fdmi_port_attr_nportid, /* bit15 RPRT_PORT_ID */
2662 lpfc_fdmi_smart_attr_service, /* bit16 RPRT_SMART_SERVICE */
2663 lpfc_fdmi_smart_attr_guid, /* bit17 RPRT_SMART_GUID */
2664 lpfc_fdmi_smart_attr_version, /* bit18 RPRT_SMART_VERSION */
2665 lpfc_fdmi_smart_attr_model, /* bit19 RPRT_SMART_MODEL */
2666 lpfc_fdmi_smart_attr_port_info, /* bit20 RPRT_SMART_PORT_INFO */
2667 lpfc_fdmi_smart_attr_qos, /* bit21 RPRT_SMART_QOS */
2668 lpfc_fdmi_smart_attr_security, /* bit22 RPRT_SMART_SECURITY */
2672 * lpfc_fdmi_cmd - Build and send a FDMI cmd to the specified NPort
2673 * @vport: pointer to a host virtual N_Port data structure.
2674 * @ndlp: ndlp to send FDMI cmd to (if NULL use FDMI_DID)
2675 * cmdcode: FDMI command to send
2676 * mask: Mask of HBA or PORT Attributes to send
2678 * Builds and sends a FDMI command using the CT subsystem.
2681 lpfc_fdmi_cmd(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2682 int cmdcode, uint32_t new_mask)
2684 struct lpfc_hba *phba = vport->phba;
2685 struct lpfc_dmabuf *mp, *bmp;
2686 struct lpfc_sli_ct_request *CtReq;
2687 struct ulp_bde64 *bpl;
2688 uint32_t bit_pos;
2689 uint32_t size;
2690 uint32_t rsp_size;
2691 uint32_t mask;
2692 struct lpfc_fdmi_reg_hba *rh;
2693 struct lpfc_fdmi_port_entry *pe;
2694 struct lpfc_fdmi_reg_portattr *pab = NULL;
2695 struct lpfc_fdmi_attr_block *ab = NULL;
2696 int (*func)(struct lpfc_vport *vport, struct lpfc_fdmi_attr_def *ad);
2697 void (*cmpl)(struct lpfc_hba *, struct lpfc_iocbq *,
2698 struct lpfc_iocbq *);
2700 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
2701 return 0;
2703 cmpl = lpfc_cmpl_ct_disc_fdmi; /* called from discovery */
2705 /* fill in BDEs for command */
2706 /* Allocate buffer for command payload */
2707 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
2708 if (!mp)
2709 goto fdmi_cmd_exit;
2711 mp->virt = lpfc_mbuf_alloc(phba, 0, &(mp->phys));
2712 if (!mp->virt)
2713 goto fdmi_cmd_free_mp;
2715 /* Allocate buffer for Buffer ptr list */
2716 bmp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
2717 if (!bmp)
2718 goto fdmi_cmd_free_mpvirt;
2720 bmp->virt = lpfc_mbuf_alloc(phba, 0, &(bmp->phys));
2721 if (!bmp->virt)
2722 goto fdmi_cmd_free_bmp;
2724 INIT_LIST_HEAD(&mp->list);
2725 INIT_LIST_HEAD(&bmp->list);
2727 /* FDMI request */
2728 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2729 "0218 FDMI Request Data: x%x x%x x%x\n",
2730 vport->fc_flag, vport->port_state, cmdcode);
2731 CtReq = (struct lpfc_sli_ct_request *)mp->virt;
2733 /* First populate the CT_IU preamble */
2734 memset(CtReq, 0, sizeof(struct lpfc_sli_ct_request));
2735 CtReq->RevisionId.bits.Revision = SLI_CT_REVISION;
2736 CtReq->RevisionId.bits.InId = 0;
2738 CtReq->FsType = SLI_CT_MANAGEMENT_SERVICE;
2739 CtReq->FsSubType = SLI_CT_FDMI_Subtypes;
2741 CtReq->CommandResponse.bits.CmdRsp = cpu_to_be16(cmdcode);
2742 rsp_size = LPFC_BPL_SIZE;
2743 size = 0;
2745 /* Next fill in the specific FDMI cmd information */
2746 switch (cmdcode) {
2747 case SLI_MGMT_RHAT:
2748 case SLI_MGMT_RHBA:
2749 rh = (struct lpfc_fdmi_reg_hba *)&CtReq->un.PortID;
2750 /* HBA Identifier */
2751 memcpy(&rh->hi.PortName, &phba->pport->fc_sparam.portName,
2752 sizeof(struct lpfc_name));
2754 if (cmdcode == SLI_MGMT_RHBA) {
2755 /* Registered Port List */
2756 /* One entry (port) per adapter */
2757 rh->rpl.EntryCnt = cpu_to_be32(1);
2758 memcpy(&rh->rpl.pe, &phba->pport->fc_sparam.portName,
2759 sizeof(struct lpfc_name));
2761 /* point to the HBA attribute block */
2762 size = 2 * sizeof(struct lpfc_name) +
2763 FOURBYTES;
2764 } else {
2765 size = sizeof(struct lpfc_name);
2767 ab = (struct lpfc_fdmi_attr_block *)((uint8_t *)rh + size);
2768 ab->EntryCnt = 0;
2769 size += FOURBYTES;
2770 bit_pos = 0;
2771 if (new_mask)
2772 mask = new_mask;
2773 else
2774 mask = vport->fdmi_hba_mask;
2776 /* Mask will dictate what attributes to build in the request */
2777 while (mask) {
2778 if (mask & 0x1) {
2779 func = lpfc_fdmi_hba_action[bit_pos];
2780 size += func(vport,
2781 (struct lpfc_fdmi_attr_def *)
2782 ((uint8_t *)rh + size));
2783 ab->EntryCnt++;
2784 if ((size + 256) >
2785 (LPFC_BPL_SIZE - LPFC_CT_PREAMBLE))
2786 goto hba_out;
2788 mask = mask >> 1;
2789 bit_pos++;
2791 hba_out:
2792 ab->EntryCnt = cpu_to_be32(ab->EntryCnt);
2793 /* Total size */
2794 size = GID_REQUEST_SZ - 4 + size;
2795 break;
2797 case SLI_MGMT_RPRT:
2798 case SLI_MGMT_RPA:
2799 pab = (struct lpfc_fdmi_reg_portattr *)&CtReq->un.PortID;
2800 if (cmdcode == SLI_MGMT_RPRT) {
2801 rh = (struct lpfc_fdmi_reg_hba *)pab;
2802 /* HBA Identifier */
2803 memcpy(&rh->hi.PortName,
2804 &phba->pport->fc_sparam.portName,
2805 sizeof(struct lpfc_name));
2806 pab = (struct lpfc_fdmi_reg_portattr *)
2807 ((uint8_t *)pab + sizeof(struct lpfc_name));
2810 memcpy((uint8_t *)&pab->PortName,
2811 (uint8_t *)&vport->fc_sparam.portName,
2812 sizeof(struct lpfc_name));
2813 size += sizeof(struct lpfc_name) + FOURBYTES;
2814 pab->ab.EntryCnt = 0;
2815 bit_pos = 0;
2816 if (new_mask)
2817 mask = new_mask;
2818 else
2819 mask = vport->fdmi_port_mask;
2821 /* Mask will dictate what attributes to build in the request */
2822 while (mask) {
2823 if (mask & 0x1) {
2824 func = lpfc_fdmi_port_action[bit_pos];
2825 size += func(vport,
2826 (struct lpfc_fdmi_attr_def *)
2827 ((uint8_t *)pab + size));
2828 pab->ab.EntryCnt++;
2829 if ((size + 256) >
2830 (LPFC_BPL_SIZE - LPFC_CT_PREAMBLE))
2831 goto port_out;
2833 mask = mask >> 1;
2834 bit_pos++;
2836 port_out:
2837 pab->ab.EntryCnt = cpu_to_be32(pab->ab.EntryCnt);
2838 /* Total size */
2839 if (cmdcode == SLI_MGMT_RPRT)
2840 size += sizeof(struct lpfc_name);
2841 size = GID_REQUEST_SZ - 4 + size;
2842 break;
2844 case SLI_MGMT_GHAT:
2845 case SLI_MGMT_GRPL:
2846 rsp_size = FC_MAX_NS_RSP;
2847 case SLI_MGMT_DHBA:
2848 case SLI_MGMT_DHAT:
2849 pe = (struct lpfc_fdmi_port_entry *)&CtReq->un.PortID;
2850 memcpy((uint8_t *)&pe->PortName,
2851 (uint8_t *)&vport->fc_sparam.portName,
2852 sizeof(struct lpfc_name));
2853 size = GID_REQUEST_SZ - 4 + sizeof(struct lpfc_name);
2854 break;
2856 case SLI_MGMT_GPAT:
2857 case SLI_MGMT_GPAS:
2858 rsp_size = FC_MAX_NS_RSP;
2859 case SLI_MGMT_DPRT:
2860 case SLI_MGMT_DPA:
2861 pe = (struct lpfc_fdmi_port_entry *)&CtReq->un.PortID;
2862 memcpy((uint8_t *)&pe->PortName,
2863 (uint8_t *)&vport->fc_sparam.portName,
2864 sizeof(struct lpfc_name));
2865 size = GID_REQUEST_SZ - 4 + sizeof(struct lpfc_name);
2866 break;
2867 case SLI_MGMT_GRHL:
2868 size = GID_REQUEST_SZ - 4;
2869 break;
2870 default:
2871 lpfc_printf_vlog(vport, KERN_WARNING, LOG_DISCOVERY,
2872 "0298 FDMI cmdcode x%x not supported\n",
2873 cmdcode);
2874 goto fdmi_cmd_free_bmpvirt;
2876 CtReq->CommandResponse.bits.Size = cpu_to_be16(rsp_size);
2878 bpl = (struct ulp_bde64 *)bmp->virt;
2879 bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys));
2880 bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys));
2881 bpl->tus.f.bdeFlags = 0;
2882 bpl->tus.f.bdeSize = size;
2885 * The lpfc_ct_cmd/lpfc_get_req shall increment ndlp reference count
2886 * to hold ndlp reference for the corresponding callback function.
2888 if (!lpfc_ct_cmd(vport, mp, bmp, ndlp, cmpl, rsp_size, 0))
2889 return 0;
2892 * Decrement ndlp reference count to release ndlp reference held
2893 * for the failed command's callback function.
2895 lpfc_nlp_put(ndlp);
2897 fdmi_cmd_free_bmpvirt:
2898 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
2899 fdmi_cmd_free_bmp:
2900 kfree(bmp);
2901 fdmi_cmd_free_mpvirt:
2902 lpfc_mbuf_free(phba, mp->virt, mp->phys);
2903 fdmi_cmd_free_mp:
2904 kfree(mp);
2905 fdmi_cmd_exit:
2906 /* Issue FDMI request failed */
2907 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2908 "0244 Issue FDMI request failed Data: x%x\n",
2909 cmdcode);
2910 return 1;
2914 * lpfc_delayed_disc_tmo - Timeout handler for delayed discovery timer.
2915 * @ptr - Context object of the timer.
2917 * This function set the WORKER_DELAYED_DISC_TMO flag and wake up
2918 * the worker thread.
2920 void
2921 lpfc_delayed_disc_tmo(struct timer_list *t)
2923 struct lpfc_vport *vport = from_timer(vport, t, delayed_disc_tmo);
2924 struct lpfc_hba *phba = vport->phba;
2925 uint32_t tmo_posted;
2926 unsigned long iflag;
2928 spin_lock_irqsave(&vport->work_port_lock, iflag);
2929 tmo_posted = vport->work_port_events & WORKER_DELAYED_DISC_TMO;
2930 if (!tmo_posted)
2931 vport->work_port_events |= WORKER_DELAYED_DISC_TMO;
2932 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
2934 if (!tmo_posted)
2935 lpfc_worker_wake_up(phba);
2936 return;
2940 * lpfc_delayed_disc_timeout_handler - Function called by worker thread to
2941 * handle delayed discovery.
2942 * @vport: pointer to a host virtual N_Port data structure.
2944 * This function start nport discovery of the vport.
2946 void
2947 lpfc_delayed_disc_timeout_handler(struct lpfc_vport *vport)
2949 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2951 spin_lock_irq(shost->host_lock);
2952 if (!(vport->fc_flag & FC_DISC_DELAYED)) {
2953 spin_unlock_irq(shost->host_lock);
2954 return;
2956 vport->fc_flag &= ~FC_DISC_DELAYED;
2957 spin_unlock_irq(shost->host_lock);
2959 lpfc_do_scr_ns_plogi(vport->phba, vport);
2962 void
2963 lpfc_decode_firmware_rev(struct lpfc_hba *phba, char *fwrevision, int flag)
2965 struct lpfc_sli *psli = &phba->sli;
2966 lpfc_vpd_t *vp = &phba->vpd;
2967 uint32_t b1, b2, b3, b4, i, rev;
2968 char c;
2969 uint32_t *ptr, str[4];
2970 uint8_t *fwname;
2972 if (phba->sli_rev == LPFC_SLI_REV4)
2973 snprintf(fwrevision, FW_REV_STR_SIZE, "%s", vp->rev.opFwName);
2974 else if (vp->rev.rBit) {
2975 if (psli->sli_flag & LPFC_SLI_ACTIVE)
2976 rev = vp->rev.sli2FwRev;
2977 else
2978 rev = vp->rev.sli1FwRev;
2980 b1 = (rev & 0x0000f000) >> 12;
2981 b2 = (rev & 0x00000f00) >> 8;
2982 b3 = (rev & 0x000000c0) >> 6;
2983 b4 = (rev & 0x00000030) >> 4;
2985 switch (b4) {
2986 case 0:
2987 c = 'N';
2988 break;
2989 case 1:
2990 c = 'A';
2991 break;
2992 case 2:
2993 c = 'B';
2994 break;
2995 case 3:
2996 c = 'X';
2997 break;
2998 default:
2999 c = 0;
3000 break;
3002 b4 = (rev & 0x0000000f);
3004 if (psli->sli_flag & LPFC_SLI_ACTIVE)
3005 fwname = vp->rev.sli2FwName;
3006 else
3007 fwname = vp->rev.sli1FwName;
3009 for (i = 0; i < 16; i++)
3010 if (fwname[i] == 0x20)
3011 fwname[i] = 0;
3013 ptr = (uint32_t*)fwname;
3015 for (i = 0; i < 3; i++)
3016 str[i] = be32_to_cpu(*ptr++);
3018 if (c == 0) {
3019 if (flag)
3020 sprintf(fwrevision, "%d.%d%d (%s)",
3021 b1, b2, b3, (char *)str);
3022 else
3023 sprintf(fwrevision, "%d.%d%d", b1,
3024 b2, b3);
3025 } else {
3026 if (flag)
3027 sprintf(fwrevision, "%d.%d%d%c%d (%s)",
3028 b1, b2, b3, c,
3029 b4, (char *)str);
3030 else
3031 sprintf(fwrevision, "%d.%d%d%c%d",
3032 b1, b2, b3, c, b4);
3034 } else {
3035 rev = vp->rev.smFwRev;
3037 b1 = (rev & 0xff000000) >> 24;
3038 b2 = (rev & 0x00f00000) >> 20;
3039 b3 = (rev & 0x000f0000) >> 16;
3040 c = (rev & 0x0000ff00) >> 8;
3041 b4 = (rev & 0x000000ff);
3043 sprintf(fwrevision, "%d.%d%d%c%d", b1, b2, b3, c, b4);
3045 return;