1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2004-2009 Emulex. All rights reserved. *
5 * EMULEX and SLI are trademarks of Emulex. *
8 * This program is free software; you can redistribute it and/or *
9 * modify it under the terms of version 2 of the GNU General *
10 * Public License as published by the Free Software Foundation. *
11 * This program is distributed in the hope that it will be useful. *
12 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
13 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
14 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
15 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
16 * TO BE LEGALLY INVALID. See the GNU General Public License for *
17 * more details, a copy of which can be found in the file COPYING *
18 * included with this package. *
19 *******************************************************************/
22 * Fibre Channel SCSI LAN Device Driver CT support: FC Generic Services FC-GS
25 #include <linux/blkdev.h>
26 #include <linux/pci.h>
27 #include <linux/interrupt.h>
28 #include <linux/utsname.h>
30 #include <scsi/scsi.h>
31 #include <scsi/scsi_device.h>
32 #include <scsi/scsi_host.h>
33 #include <scsi/scsi_transport_fc.h>
34 #include <scsi/fc/fc_fs.h>
39 #include "lpfc_sli4.h"
41 #include "lpfc_disc.h"
42 #include "lpfc_scsi.h"
44 #include "lpfc_logmsg.h"
45 #include "lpfc_crtn.h"
46 #include "lpfc_version.h"
47 #include "lpfc_vport.h"
48 #include "lpfc_debugfs.h"
50 #define HBA_PORTSPEED_UNKNOWN 0 /* Unknown - transceiver
51 * incapable of reporting */
52 #define HBA_PORTSPEED_1GBIT 1 /* 1 GBit/sec */
53 #define HBA_PORTSPEED_2GBIT 2 /* 2 GBit/sec */
54 #define HBA_PORTSPEED_4GBIT 8 /* 4 GBit/sec */
55 #define HBA_PORTSPEED_8GBIT 16 /* 8 GBit/sec */
56 #define HBA_PORTSPEED_10GBIT 4 /* 10 GBit/sec */
57 #define HBA_PORTSPEED_NOT_NEGOTIATED 5 /* Speed not established */
62 static char *lpfc_release_version = LPFC_DRIVER_VERSION;
65 lpfc_ct_ignore_hbq_buffer(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq,
66 struct lpfc_dmabuf *mp, uint32_t size)
69 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
70 "0146 Ignoring unsolicited CT No HBQ "
72 piocbq->iocb.ulpStatus);
74 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
75 "0145 Ignoring unsolicted CT HBQ Size:%d "
77 size, piocbq->iocb.ulpStatus);
81 lpfc_ct_unsol_buffer(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq,
82 struct lpfc_dmabuf *mp, uint32_t size)
84 lpfc_ct_ignore_hbq_buffer(phba, piocbq, mp, size);
88 lpfc_ct_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
89 struct lpfc_iocbq *piocbq)
91 struct lpfc_dmabuf *mp = NULL;
92 IOCB_t *icmd = &piocbq->iocb;
94 struct lpfc_iocbq *iocbq;
97 struct list_head head;
98 struct lpfc_dmabuf *bdeBuf;
100 lpfc_bsg_ct_unsol_event(phba, pring, piocbq);
102 if (unlikely(icmd->ulpStatus == IOSTAT_NEED_BUFFER)) {
103 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
104 } else if ((icmd->ulpStatus == IOSTAT_LOCAL_REJECT) &&
105 ((icmd->un.ulpWord[4] & 0xff) == IOERR_RCV_BUFFER_WAITING)) {
106 /* Not enough posted buffers; Try posting more buffers */
107 phba->fc_stat.NoRcvBuf++;
108 if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
109 lpfc_post_buffer(phba, pring, 2);
113 /* If there are no BDEs associated with this IOCB,
114 * there is nothing to do.
116 if (icmd->ulpBdeCount == 0)
119 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
120 INIT_LIST_HEAD(&head);
121 list_add_tail(&head, &piocbq->list);
122 list_for_each_entry(iocbq, &head, list) {
124 if (icmd->ulpBdeCount == 0)
126 bdeBuf = iocbq->context2;
127 iocbq->context2 = NULL;
128 size = icmd->un.cont64[0].tus.f.bdeSize;
129 lpfc_ct_unsol_buffer(phba, piocbq, bdeBuf, size);
130 lpfc_in_buf_free(phba, bdeBuf);
131 if (icmd->ulpBdeCount == 2) {
132 bdeBuf = iocbq->context3;
133 iocbq->context3 = NULL;
134 size = icmd->unsli3.rcvsli3.bde2.tus.f.bdeSize;
135 lpfc_ct_unsol_buffer(phba, piocbq, bdeBuf,
137 lpfc_in_buf_free(phba, bdeBuf);
142 INIT_LIST_HEAD(&head);
143 list_add_tail(&head, &piocbq->list);
144 list_for_each_entry(iocbq, &head, list) {
146 if (icmd->ulpBdeCount == 0)
147 lpfc_ct_unsol_buffer(phba, iocbq, NULL, 0);
148 for (i = 0; i < icmd->ulpBdeCount; i++) {
149 paddr = getPaddr(icmd->un.cont64[i].addrHigh,
150 icmd->un.cont64[i].addrLow);
151 mp = lpfc_sli_ringpostbuf_get(phba, pring,
153 size = icmd->un.cont64[i].tus.f.bdeSize;
154 lpfc_ct_unsol_buffer(phba, iocbq, mp, size);
155 lpfc_in_buf_free(phba, mp);
157 lpfc_post_buffer(phba, pring, i);
164 * lpfc_sli4_ct_abort_unsol_event - Default handle for sli4 unsol abort
165 * @phba: Pointer to HBA context object.
166 * @pring: Pointer to the driver internal I/O ring.
167 * @piocbq: Pointer to the IOCBQ.
169 * This function serves as the default handler for the sli4 unsolicited
170 * abort event. It shall be invoked when there is no application interface
171 * registered unsolicited abort handler. This handler does nothing but
172 * just simply releases the dma buffer used by the unsol abort event.
175 lpfc_sli4_ct_abort_unsol_event(struct lpfc_hba *phba,
176 struct lpfc_sli_ring *pring,
177 struct lpfc_iocbq *piocbq)
179 IOCB_t *icmd = &piocbq->iocb;
180 struct lpfc_dmabuf *bdeBuf;
183 /* Forward abort event to any process registered to receive ct event */
184 lpfc_bsg_ct_unsol_event(phba, pring, piocbq);
186 /* If there is no BDE associated with IOCB, there is nothing to do */
187 if (icmd->ulpBdeCount == 0)
189 bdeBuf = piocbq->context2;
190 piocbq->context2 = NULL;
191 size = icmd->un.cont64[0].tus.f.bdeSize;
192 lpfc_ct_unsol_buffer(phba, piocbq, bdeBuf, size);
193 lpfc_in_buf_free(phba, bdeBuf);
197 lpfc_free_ct_rsp(struct lpfc_hba *phba, struct lpfc_dmabuf *mlist)
199 struct lpfc_dmabuf *mlast, *next_mlast;
201 list_for_each_entry_safe(mlast, next_mlast, &mlist->list, list) {
202 lpfc_mbuf_free(phba, mlast->virt, mlast->phys);
203 list_del(&mlast->list);
206 lpfc_mbuf_free(phba, mlist->virt, mlist->phys);
211 static struct lpfc_dmabuf *
212 lpfc_alloc_ct_rsp(struct lpfc_hba *phba, int cmdcode, struct ulp_bde64 *bpl,
213 uint32_t size, int *entries)
215 struct lpfc_dmabuf *mlist = NULL;
216 struct lpfc_dmabuf *mp;
219 /* We get chunks of FCELSSIZE */
220 cnt = size > FCELSSIZE ? FCELSSIZE: size;
223 /* Allocate buffer for rsp payload */
224 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
227 lpfc_free_ct_rsp(phba, mlist);
231 INIT_LIST_HEAD(&mp->list);
233 if (cmdcode == be16_to_cpu(SLI_CTNS_GID_FT) ||
234 cmdcode == be16_to_cpu(SLI_CTNS_GFF_ID))
235 mp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(mp->phys));
237 mp->virt = lpfc_mbuf_alloc(phba, 0, &(mp->phys));
242 lpfc_free_ct_rsp(phba, mlist);
246 /* Queue it to a linked list */
250 list_add_tail(&mp->list, &mlist->list);
252 bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64I;
253 /* build buffer ptr list for IOCB */
254 bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys) );
255 bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys) );
256 bpl->tus.f.bdeSize = (uint16_t) cnt;
257 bpl->tus.w = le32_to_cpu(bpl->tus.w);
269 lpfc_ct_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *ctiocb)
271 struct lpfc_dmabuf *buf_ptr;
273 if (ctiocb->context_un.ndlp) {
274 lpfc_nlp_put(ctiocb->context_un.ndlp);
275 ctiocb->context_un.ndlp = NULL;
277 if (ctiocb->context1) {
278 buf_ptr = (struct lpfc_dmabuf *) ctiocb->context1;
279 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
281 ctiocb->context1 = NULL;
283 if (ctiocb->context2) {
284 lpfc_free_ct_rsp(phba, (struct lpfc_dmabuf *) ctiocb->context2);
285 ctiocb->context2 = NULL;
288 if (ctiocb->context3) {
289 buf_ptr = (struct lpfc_dmabuf *) ctiocb->context3;
290 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
292 ctiocb->context1 = NULL;
294 lpfc_sli_release_iocbq(phba, ctiocb);
299 lpfc_gen_req(struct lpfc_vport *vport, struct lpfc_dmabuf *bmp,
300 struct lpfc_dmabuf *inp, struct lpfc_dmabuf *outp,
301 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
302 struct lpfc_iocbq *),
303 struct lpfc_nodelist *ndlp, uint32_t usr_flg, uint32_t num_entry,
304 uint32_t tmo, uint8_t retry)
306 struct lpfc_hba *phba = vport->phba;
308 struct lpfc_iocbq *geniocb;
311 /* Allocate buffer for command iocb */
312 geniocb = lpfc_sli_get_iocbq(phba);
317 icmd = &geniocb->iocb;
318 icmd->un.genreq64.bdl.ulpIoTag32 = 0;
319 icmd->un.genreq64.bdl.addrHigh = putPaddrHigh(bmp->phys);
320 icmd->un.genreq64.bdl.addrLow = putPaddrLow(bmp->phys);
321 icmd->un.genreq64.bdl.bdeFlags = BUFF_TYPE_BLP_64;
322 icmd->un.genreq64.bdl.bdeSize = (num_entry * sizeof (struct ulp_bde64));
325 geniocb->context3 = NULL;
327 geniocb->context3 = (uint8_t *) bmp;
329 /* Save for completion so we can release these resources */
330 geniocb->context1 = (uint8_t *) inp;
331 geniocb->context2 = (uint8_t *) outp;
332 geniocb->context_un.ndlp = lpfc_nlp_get(ndlp);
334 /* Fill in payload, bp points to frame payload */
335 icmd->ulpCommand = CMD_GEN_REQUEST64_CR;
337 /* Fill in rest of iocb */
338 icmd->un.genreq64.w5.hcsw.Fctl = (SI | LA);
339 icmd->un.genreq64.w5.hcsw.Dfctl = 0;
340 icmd->un.genreq64.w5.hcsw.Rctl = FC_RCTL_DD_UNSOL_CTL;
341 icmd->un.genreq64.w5.hcsw.Type = FC_TYPE_CT;
344 /* FC spec states we need 3 * ratov for CT requests */
345 tmo = (3 * phba->fc_ratov);
347 icmd->ulpTimeout = tmo;
348 icmd->ulpBdeCount = 1;
350 icmd->ulpClass = CLASS3;
351 icmd->ulpContext = ndlp->nlp_rpi;
353 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
354 /* For GEN_REQUEST64_CR, use the RPI */
359 /* Issue GEN REQ IOCB for NPORT <did> */
360 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
361 "0119 Issue GEN REQ IOCB to NPORT x%x "
363 ndlp->nlp_DID, icmd->ulpIoTag,
365 geniocb->iocb_cmpl = cmpl;
366 geniocb->drvrTimeout = icmd->ulpTimeout + LPFC_DRVR_TIMEOUT;
367 geniocb->vport = vport;
368 geniocb->retry = retry;
369 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, geniocb, 0);
371 if (rc == IOCB_ERROR) {
372 lpfc_sli_release_iocbq(phba, geniocb);
380 lpfc_ct_cmd(struct lpfc_vport *vport, struct lpfc_dmabuf *inmp,
381 struct lpfc_dmabuf *bmp, struct lpfc_nodelist *ndlp,
382 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
383 struct lpfc_iocbq *),
384 uint32_t rsp_size, uint8_t retry)
386 struct lpfc_hba *phba = vport->phba;
387 struct ulp_bde64 *bpl = (struct ulp_bde64 *) bmp->virt;
388 struct lpfc_dmabuf *outmp;
390 int cmdcode = ((struct lpfc_sli_ct_request *) inmp->virt)->
391 CommandResponse.bits.CmdRsp;
393 bpl++; /* Skip past ct request */
395 /* Put buffer(s) for ct rsp in bpl */
396 outmp = lpfc_alloc_ct_rsp(phba, cmdcode, bpl, rsp_size, &cnt);
400 * Form the CT IOCB. The total number of BDEs in this IOCB
401 * is the single command plus response count from
405 status = lpfc_gen_req(vport, bmp, inmp, outmp, cmpl, ndlp, 0,
408 lpfc_free_ct_rsp(phba, outmp);
415 lpfc_find_vport_by_did(struct lpfc_hba *phba, uint32_t did) {
416 struct lpfc_vport *vport_curr;
419 spin_lock_irqsave(&phba->hbalock, flags);
420 list_for_each_entry(vport_curr, &phba->port_list, listentry) {
421 if ((vport_curr->fc_myDID) && (vport_curr->fc_myDID == did)) {
422 spin_unlock_irqrestore(&phba->hbalock, flags);
426 spin_unlock_irqrestore(&phba->hbalock, flags);
431 lpfc_ns_rsp(struct lpfc_vport *vport, struct lpfc_dmabuf *mp, uint32_t Size)
433 struct lpfc_hba *phba = vport->phba;
434 struct lpfc_sli_ct_request *Response =
435 (struct lpfc_sli_ct_request *) mp->virt;
436 struct lpfc_nodelist *ndlp = NULL;
437 struct lpfc_dmabuf *mlast, *next_mp;
438 uint32_t *ctptr = (uint32_t *) & Response->un.gid.PortType;
439 uint32_t Did, CTentry;
441 struct list_head head;
443 lpfc_set_disctmo(vport);
444 vport->num_disc_nodes = 0;
445 vport->fc_ns_retry = 0;
448 list_add_tail(&head, &mp->list);
449 list_for_each_entry_safe(mp, next_mp, &head, list) {
452 Cnt = Size > FCELSSIZE ? FCELSSIZE : Size;
457 ctptr = (uint32_t *) mlast->virt;
459 Cnt -= 16; /* subtract length of CT header */
461 /* Loop through entire NameServer list of DIDs */
462 while (Cnt >= sizeof (uint32_t)) {
463 /* Get next DID from NameServer List */
465 Did = ((be32_to_cpu(CTentry)) & Mask_DID);
470 * Check for rscn processing or not
471 * To conserve rpi's, filter out addresses for other
472 * vports on the same physical HBAs.
474 if ((Did != vport->fc_myDID) &&
475 ((lpfc_find_vport_by_did(phba, Did) == NULL) ||
476 vport->cfg_peer_port_login)) {
477 if ((vport->port_type != LPFC_NPIV_PORT) ||
478 (!(vport->ct_flags & FC_CT_RFF_ID)) ||
479 (!vport->cfg_restrict_login)) {
480 ndlp = lpfc_setup_disc_node(vport, Did);
481 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
482 lpfc_debugfs_disc_trc(vport,
485 "did:x%x flg:x%x x%x",
489 lpfc_printf_vlog(vport,
494 "Data: x%x x%x x%x\n",
497 vport->fc_rscn_id_cnt);
499 lpfc_debugfs_disc_trc(vport,
502 "did:x%x flg:x%x cnt:%d",
504 vport->fc_rscn_id_cnt);
506 lpfc_printf_vlog(vport,
510 "NameServer Rsp Data: "
513 vport->fc_rscn_id_cnt);
517 if (!(vport->fc_flag & FC_RSCN_MODE) ||
518 (lpfc_rscn_payload_check(vport, Did))) {
519 lpfc_debugfs_disc_trc(vport,
522 "did:x%x flg:x%x cnt:%d",
524 vport->fc_rscn_id_cnt);
526 /* This NPortID was previously
527 * a FCP target, * Don't even
528 * bother to send GFF_ID.
530 ndlp = lpfc_findnode_did(vport,
533 NLP_CHK_NODE_ACT(ndlp)
538 else if (lpfc_ns_cmd(vport,
541 vport->num_disc_nodes++;
547 lpfc_debugfs_disc_trc(vport,
550 "did:x%x flg:x%x cnt:%d",
552 vport->fc_rscn_id_cnt);
554 lpfc_printf_vlog(vport,
558 "NameServer Rsp Data: "
561 vport->fc_rscn_id_cnt);
565 if (CTentry & (be32_to_cpu(SLI_CT_LAST_ENTRY)))
567 Cnt -= sizeof (uint32_t);
579 lpfc_cmpl_ct_cmd_gid_ft(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
580 struct lpfc_iocbq *rspiocb)
582 struct lpfc_vport *vport = cmdiocb->vport;
583 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
585 struct lpfc_dmabuf *bmp;
586 struct lpfc_dmabuf *outp;
587 struct lpfc_sli_ct_request *CTrsp;
588 struct lpfc_nodelist *ndlp;
591 /* First save ndlp, before we overwrite it */
592 ndlp = cmdiocb->context_un.ndlp;
594 /* we pass cmdiocb to state machine which needs rspiocb as well */
595 cmdiocb->context_un.rsp_iocb = rspiocb;
597 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
598 bmp = (struct lpfc_dmabuf *) cmdiocb->context3;
599 irsp = &rspiocb->iocb;
601 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
602 "GID_FT cmpl: status:x%x/x%x rtry:%d",
603 irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_ns_retry);
605 /* Don't bother processing response if vport is being torn down. */
606 if (vport->load_flag & FC_UNLOADING) {
607 if (vport->fc_flag & FC_RSCN_MODE)
608 lpfc_els_flush_rscn(vport);
612 if (lpfc_els_chk_latt(vport)) {
613 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
614 "0216 Link event during NS query\n");
615 if (vport->fc_flag & FC_RSCN_MODE)
616 lpfc_els_flush_rscn(vport);
617 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
620 if (lpfc_error_lost_link(irsp)) {
621 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
622 "0226 NS query failed due to link event\n");
623 if (vport->fc_flag & FC_RSCN_MODE)
624 lpfc_els_flush_rscn(vport);
627 if (irsp->ulpStatus) {
628 /* Check for retry */
629 if (vport->fc_ns_retry < LPFC_MAX_NS_RETRY) {
630 if (irsp->ulpStatus != IOSTAT_LOCAL_REJECT ||
631 irsp->un.ulpWord[4] != IOERR_NO_RESOURCES)
632 vport->fc_ns_retry++;
634 /* CT command is being retried */
635 rc = lpfc_ns_cmd(vport, SLI_CTNS_GID_FT,
636 vport->fc_ns_retry, 0);
640 if (vport->fc_flag & FC_RSCN_MODE)
641 lpfc_els_flush_rscn(vport);
642 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
643 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
644 "0257 GID_FT Query error: 0x%x 0x%x\n",
645 irsp->ulpStatus, vport->fc_ns_retry);
647 /* Good status, continue checking */
648 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
649 if (CTrsp->CommandResponse.bits.CmdRsp ==
650 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC)) {
651 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
652 "0208 NameServer Rsp Data: x%x\n",
654 lpfc_ns_rsp(vport, outp,
655 (uint32_t) (irsp->un.genreq64.bdl.bdeSize));
656 } else if (CTrsp->CommandResponse.bits.CmdRsp ==
657 be16_to_cpu(SLI_CT_RESPONSE_FS_RJT)) {
658 /* NameServer Rsp Error */
659 if ((CTrsp->ReasonCode == SLI_CT_UNABLE_TO_PERFORM_REQ)
660 && (CTrsp->Explanation == SLI_CT_NO_FC4_TYPES)) {
661 lpfc_printf_vlog(vport, KERN_INFO,
663 "0269 No NameServer Entries "
664 "Data: x%x x%x x%x x%x\n",
665 CTrsp->CommandResponse.bits.CmdRsp,
666 (uint32_t) CTrsp->ReasonCode,
667 (uint32_t) CTrsp->Explanation,
670 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
671 "GID_FT no entry cmd:x%x rsn:x%x exp:x%x",
672 (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
673 (uint32_t) CTrsp->ReasonCode,
674 (uint32_t) CTrsp->Explanation);
676 lpfc_printf_vlog(vport, KERN_INFO,
678 "0240 NameServer Rsp Error "
679 "Data: x%x x%x x%x x%x\n",
680 CTrsp->CommandResponse.bits.CmdRsp,
681 (uint32_t) CTrsp->ReasonCode,
682 (uint32_t) CTrsp->Explanation,
685 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
686 "GID_FT rsp err1 cmd:x%x rsn:x%x exp:x%x",
687 (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
688 (uint32_t) CTrsp->ReasonCode,
689 (uint32_t) CTrsp->Explanation);
694 /* NameServer Rsp Error */
695 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
696 "0241 NameServer Rsp Error "
697 "Data: x%x x%x x%x x%x\n",
698 CTrsp->CommandResponse.bits.CmdRsp,
699 (uint32_t) CTrsp->ReasonCode,
700 (uint32_t) CTrsp->Explanation,
703 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
704 "GID_FT rsp err2 cmd:x%x rsn:x%x exp:x%x",
705 (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
706 (uint32_t) CTrsp->ReasonCode,
707 (uint32_t) CTrsp->Explanation);
710 /* Link up / RSCN discovery */
711 if (vport->num_disc_nodes == 0) {
713 * The driver has cycled through all Nports in the RSCN payload.
714 * Complete the handling by cleaning up and marking the
715 * current driver state.
717 if (vport->port_state >= LPFC_DISC_AUTH) {
718 if (vport->fc_flag & FC_RSCN_MODE) {
719 lpfc_els_flush_rscn(vport);
720 spin_lock_irq(shost->host_lock);
721 vport->fc_flag |= FC_RSCN_MODE; /* RSCN still */
722 spin_unlock_irq(shost->host_lock);
725 lpfc_els_flush_rscn(vport);
728 lpfc_disc_start(vport);
731 cmdiocb->context_un.ndlp = ndlp; /* Now restore ndlp for free */
732 lpfc_ct_free_iocb(phba, cmdiocb);
737 lpfc_cmpl_ct_cmd_gff_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
738 struct lpfc_iocbq *rspiocb)
740 struct lpfc_vport *vport = cmdiocb->vport;
741 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
742 IOCB_t *irsp = &rspiocb->iocb;
743 struct lpfc_dmabuf *inp = (struct lpfc_dmabuf *) cmdiocb->context1;
744 struct lpfc_dmabuf *outp = (struct lpfc_dmabuf *) cmdiocb->context2;
745 struct lpfc_sli_ct_request *CTrsp;
748 struct lpfc_nodelist *ndlp;
750 did = ((struct lpfc_sli_ct_request *) inp->virt)->un.gff.PortId;
751 did = be32_to_cpu(did);
753 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
754 "GFF_ID cmpl: status:x%x/x%x did:x%x",
755 irsp->ulpStatus, irsp->un.ulpWord[4], did);
757 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
758 /* Good status, continue checking */
759 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
760 fbits = CTrsp->un.gff_acc.fbits[FCP_TYPE_FEATURE_OFFSET];
762 if (CTrsp->CommandResponse.bits.CmdRsp ==
763 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC)) {
764 if ((fbits & FC4_FEATURE_INIT) &&
765 !(fbits & FC4_FEATURE_TARGET)) {
766 lpfc_printf_vlog(vport, KERN_INFO,
769 "NameServer Rsp Data: (init) "
770 "x%x x%x\n", did, fbits,
771 vport->fc_rscn_id_cnt);
777 /* Check for retry */
778 if (cmdiocb->retry < LPFC_MAX_NS_RETRY) {
780 if (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) {
781 switch (irsp->un.ulpWord[4]) {
782 case IOERR_NO_RESOURCES:
783 /* We don't increment the retry
784 * count for this case.
787 case IOERR_LINK_DOWN:
788 case IOERR_SLI_ABORTED:
800 /* CT command is being retried */
801 rc = lpfc_ns_cmd(vport, SLI_CTNS_GFF_ID,
802 cmdiocb->retry, did);
805 lpfc_ct_free_iocb(phba, cmdiocb);
810 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
811 "0267 NameServer GFF Rsp "
812 "x%x Error (%d %d) Data: x%x x%x\n",
813 did, irsp->ulpStatus, irsp->un.ulpWord[4],
814 vport->fc_flag, vport->fc_rscn_id_cnt);
817 /* This is a target port, unregistered port, or the GFF_ID failed */
818 ndlp = lpfc_setup_disc_node(vport, did);
819 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
820 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
821 "0242 Process x%x GFF "
822 "NameServer Rsp Data: x%x x%x x%x\n",
823 did, ndlp->nlp_flag, vport->fc_flag,
824 vport->fc_rscn_id_cnt);
826 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
828 "NameServer Rsp Data: x%x x%x\n", did,
829 vport->fc_flag, vport->fc_rscn_id_cnt);
832 /* Link up / RSCN discovery */
833 if (vport->num_disc_nodes)
834 vport->num_disc_nodes--;
835 if (vport->num_disc_nodes == 0) {
837 * The driver has cycled through all Nports in the RSCN payload.
838 * Complete the handling by cleaning up and marking the
839 * current driver state.
841 if (vport->port_state >= LPFC_DISC_AUTH) {
842 if (vport->fc_flag & FC_RSCN_MODE) {
843 lpfc_els_flush_rscn(vport);
844 spin_lock_irq(shost->host_lock);
845 vport->fc_flag |= FC_RSCN_MODE; /* RSCN still */
846 spin_unlock_irq(shost->host_lock);
849 lpfc_els_flush_rscn(vport);
851 lpfc_disc_start(vport);
853 lpfc_ct_free_iocb(phba, cmdiocb);
859 lpfc_cmpl_ct(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
860 struct lpfc_iocbq *rspiocb)
862 struct lpfc_vport *vport = cmdiocb->vport;
863 struct lpfc_dmabuf *inp;
864 struct lpfc_dmabuf *outp;
866 struct lpfc_sli_ct_request *CTrsp;
867 struct lpfc_nodelist *ndlp;
872 /* First save ndlp, before we overwrite it */
873 ndlp = cmdiocb->context_un.ndlp;
875 /* we pass cmdiocb to state machine which needs rspiocb as well */
876 cmdiocb->context_un.rsp_iocb = rspiocb;
878 inp = (struct lpfc_dmabuf *) cmdiocb->context1;
879 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
880 irsp = &rspiocb->iocb;
882 cmdcode = be16_to_cpu(((struct lpfc_sli_ct_request *) inp->virt)->
883 CommandResponse.bits.CmdRsp);
884 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
886 latt = lpfc_els_chk_latt(vport);
888 /* RFT request completes status <ulpStatus> CmdRsp <CmdRsp> */
889 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
890 "0209 CT Request completes, latt %d, "
891 "ulpStatus x%x CmdRsp x%x, Context x%x, Tag x%x\n",
892 latt, irsp->ulpStatus,
893 CTrsp->CommandResponse.bits.CmdRsp,
894 cmdiocb->iocb.ulpContext, cmdiocb->iocb.ulpIoTag);
896 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
897 "CT cmd cmpl: status:x%x/x%x cmd:x%x",
898 irsp->ulpStatus, irsp->un.ulpWord[4], cmdcode);
900 if (irsp->ulpStatus) {
901 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
902 "0268 NS cmd %x Error (%d %d)\n",
903 cmdcode, irsp->ulpStatus, irsp->un.ulpWord[4]);
905 if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
906 ((irsp->un.ulpWord[4] == IOERR_SLI_DOWN) ||
907 (irsp->un.ulpWord[4] == IOERR_SLI_ABORTED)))
910 retry = cmdiocb->retry;
911 if (retry >= LPFC_MAX_NS_RETRY)
915 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
916 "0250 Retrying NS cmd %x\n", cmdcode);
917 rc = lpfc_ns_cmd(vport, cmdcode, retry, 0);
923 cmdiocb->context_un.ndlp = ndlp; /* Now restore ndlp for free */
924 lpfc_ct_free_iocb(phba, cmdiocb);
929 lpfc_cmpl_ct_cmd_rft_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
930 struct lpfc_iocbq *rspiocb)
932 IOCB_t *irsp = &rspiocb->iocb;
933 struct lpfc_vport *vport = cmdiocb->vport;
935 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
936 struct lpfc_dmabuf *outp;
937 struct lpfc_sli_ct_request *CTrsp;
939 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
940 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
941 if (CTrsp->CommandResponse.bits.CmdRsp ==
942 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
943 vport->ct_flags |= FC_CT_RFT_ID;
945 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
950 lpfc_cmpl_ct_cmd_rnn_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
951 struct lpfc_iocbq *rspiocb)
953 IOCB_t *irsp = &rspiocb->iocb;
954 struct lpfc_vport *vport = cmdiocb->vport;
956 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
957 struct lpfc_dmabuf *outp;
958 struct lpfc_sli_ct_request *CTrsp;
960 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
961 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
962 if (CTrsp->CommandResponse.bits.CmdRsp ==
963 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
964 vport->ct_flags |= FC_CT_RNN_ID;
966 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
971 lpfc_cmpl_ct_cmd_rspn_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
972 struct lpfc_iocbq *rspiocb)
974 IOCB_t *irsp = &rspiocb->iocb;
975 struct lpfc_vport *vport = cmdiocb->vport;
977 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
978 struct lpfc_dmabuf *outp;
979 struct lpfc_sli_ct_request *CTrsp;
981 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
982 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
983 if (CTrsp->CommandResponse.bits.CmdRsp ==
984 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
985 vport->ct_flags |= FC_CT_RSPN_ID;
987 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
992 lpfc_cmpl_ct_cmd_rsnn_nn(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
993 struct lpfc_iocbq *rspiocb)
995 IOCB_t *irsp = &rspiocb->iocb;
996 struct lpfc_vport *vport = cmdiocb->vport;
998 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
999 struct lpfc_dmabuf *outp;
1000 struct lpfc_sli_ct_request *CTrsp;
1002 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
1003 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
1004 if (CTrsp->CommandResponse.bits.CmdRsp ==
1005 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
1006 vport->ct_flags |= FC_CT_RSNN_NN;
1008 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
1013 lpfc_cmpl_ct_cmd_da_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1014 struct lpfc_iocbq *rspiocb)
1016 struct lpfc_vport *vport = cmdiocb->vport;
1018 /* even if it fails we will act as though it succeeded. */
1019 vport->ct_flags = 0;
1020 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
1025 lpfc_cmpl_ct_cmd_rff_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1026 struct lpfc_iocbq *rspiocb)
1028 IOCB_t *irsp = &rspiocb->iocb;
1029 struct lpfc_vport *vport = cmdiocb->vport;
1031 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
1032 struct lpfc_dmabuf *outp;
1033 struct lpfc_sli_ct_request *CTrsp;
1035 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
1036 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
1037 if (CTrsp->CommandResponse.bits.CmdRsp ==
1038 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
1039 vport->ct_flags |= FC_CT_RFF_ID;
1041 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
1046 lpfc_vport_symbolic_port_name(struct lpfc_vport *vport, char *symbol,
1050 uint8_t *wwn = vport->phba->wwpn;
1052 n = snprintf(symbol, size,
1053 "Emulex PPN-%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x",
1054 wwn[0], wwn[1], wwn[2], wwn[3],
1055 wwn[4], wwn[5], wwn[6], wwn[7]);
1057 if (vport->port_type == LPFC_PHYSICAL_PORT)
1061 n += snprintf(symbol + n, size - n, " VPort-%d", vport->vpi);
1064 strlen(vport->fc_vport->symbolic_name))
1065 n += snprintf(symbol + n, size - n, " VName-%s",
1066 vport->fc_vport->symbolic_name);
1071 lpfc_vport_symbolic_node_name(struct lpfc_vport *vport, char *symbol,
1077 lpfc_decode_firmware_rev(vport->phba, fwrev, 0);
1079 n = snprintf(symbol, size, "Emulex %s FV%s DV%s",
1080 vport->phba->ModelName, fwrev, lpfc_release_version);
1087 * Issue Cmd to NameServer
1092 lpfc_ns_cmd(struct lpfc_vport *vport, int cmdcode,
1093 uint8_t retry, uint32_t context)
1095 struct lpfc_nodelist * ndlp;
1096 struct lpfc_hba *phba = vport->phba;
1097 struct lpfc_dmabuf *mp, *bmp;
1098 struct lpfc_sli_ct_request *CtReq;
1099 struct ulp_bde64 *bpl;
1100 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
1101 struct lpfc_iocbq *) = NULL;
1102 uint32_t rsp_size = 1024;
1106 ndlp = lpfc_findnode_did(vport, NameServer_DID);
1107 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)
1108 || ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) {
1113 /* fill in BDEs for command */
1114 /* Allocate buffer for command payload */
1115 mp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
1121 INIT_LIST_HEAD(&mp->list);
1122 mp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(mp->phys));
1125 goto ns_cmd_free_mp;
1128 /* Allocate buffer for Buffer ptr list */
1129 bmp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
1132 goto ns_cmd_free_mpvirt;
1135 INIT_LIST_HEAD(&bmp->list);
1136 bmp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(bmp->phys));
1139 goto ns_cmd_free_bmp;
1142 /* NameServer Req */
1143 lpfc_printf_vlog(vport, KERN_INFO ,LOG_DISCOVERY,
1144 "0236 NameServer Req Data: x%x x%x x%x\n",
1145 cmdcode, vport->fc_flag, vport->fc_rscn_id_cnt);
1147 bpl = (struct ulp_bde64 *) bmp->virt;
1148 memset(bpl, 0, sizeof(struct ulp_bde64));
1149 bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys) );
1150 bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys) );
1151 bpl->tus.f.bdeFlags = 0;
1152 if (cmdcode == SLI_CTNS_GID_FT)
1153 bpl->tus.f.bdeSize = GID_REQUEST_SZ;
1154 else if (cmdcode == SLI_CTNS_GFF_ID)
1155 bpl->tus.f.bdeSize = GFF_REQUEST_SZ;
1156 else if (cmdcode == SLI_CTNS_RFT_ID)
1157 bpl->tus.f.bdeSize = RFT_REQUEST_SZ;
1158 else if (cmdcode == SLI_CTNS_RNN_ID)
1159 bpl->tus.f.bdeSize = RNN_REQUEST_SZ;
1160 else if (cmdcode == SLI_CTNS_RSPN_ID)
1161 bpl->tus.f.bdeSize = RSPN_REQUEST_SZ;
1162 else if (cmdcode == SLI_CTNS_RSNN_NN)
1163 bpl->tus.f.bdeSize = RSNN_REQUEST_SZ;
1164 else if (cmdcode == SLI_CTNS_DA_ID)
1165 bpl->tus.f.bdeSize = DA_ID_REQUEST_SZ;
1166 else if (cmdcode == SLI_CTNS_RFF_ID)
1167 bpl->tus.f.bdeSize = RFF_REQUEST_SZ;
1169 bpl->tus.f.bdeSize = 0;
1170 bpl->tus.w = le32_to_cpu(bpl->tus.w);
1172 CtReq = (struct lpfc_sli_ct_request *) mp->virt;
1173 memset(CtReq, 0, sizeof (struct lpfc_sli_ct_request));
1174 CtReq->RevisionId.bits.Revision = SLI_CT_REVISION;
1175 CtReq->RevisionId.bits.InId = 0;
1176 CtReq->FsType = SLI_CT_DIRECTORY_SERVICE;
1177 CtReq->FsSubType = SLI_CT_DIRECTORY_NAME_SERVER;
1178 CtReq->CommandResponse.bits.Size = 0;
1180 case SLI_CTNS_GID_FT:
1181 CtReq->CommandResponse.bits.CmdRsp =
1182 be16_to_cpu(SLI_CTNS_GID_FT);
1183 CtReq->un.gid.Fc4Type = SLI_CTPT_FCP;
1184 if (vport->port_state < LPFC_NS_QRY)
1185 vport->port_state = LPFC_NS_QRY;
1186 lpfc_set_disctmo(vport);
1187 cmpl = lpfc_cmpl_ct_cmd_gid_ft;
1188 rsp_size = FC_MAX_NS_RSP;
1191 case SLI_CTNS_GFF_ID:
1192 CtReq->CommandResponse.bits.CmdRsp =
1193 be16_to_cpu(SLI_CTNS_GFF_ID);
1194 CtReq->un.gff.PortId = cpu_to_be32(context);
1195 cmpl = lpfc_cmpl_ct_cmd_gff_id;
1198 case SLI_CTNS_RFT_ID:
1199 vport->ct_flags &= ~FC_CT_RFT_ID;
1200 CtReq->CommandResponse.bits.CmdRsp =
1201 be16_to_cpu(SLI_CTNS_RFT_ID);
1202 CtReq->un.rft.PortId = cpu_to_be32(vport->fc_myDID);
1203 CtReq->un.rft.fcpReg = 1;
1204 cmpl = lpfc_cmpl_ct_cmd_rft_id;
1207 case SLI_CTNS_RNN_ID:
1208 vport->ct_flags &= ~FC_CT_RNN_ID;
1209 CtReq->CommandResponse.bits.CmdRsp =
1210 be16_to_cpu(SLI_CTNS_RNN_ID);
1211 CtReq->un.rnn.PortId = cpu_to_be32(vport->fc_myDID);
1212 memcpy(CtReq->un.rnn.wwnn, &vport->fc_nodename,
1213 sizeof (struct lpfc_name));
1214 cmpl = lpfc_cmpl_ct_cmd_rnn_id;
1217 case SLI_CTNS_RSPN_ID:
1218 vport->ct_flags &= ~FC_CT_RSPN_ID;
1219 CtReq->CommandResponse.bits.CmdRsp =
1220 be16_to_cpu(SLI_CTNS_RSPN_ID);
1221 CtReq->un.rspn.PortId = cpu_to_be32(vport->fc_myDID);
1222 size = sizeof(CtReq->un.rspn.symbname);
1223 CtReq->un.rspn.len =
1224 lpfc_vport_symbolic_port_name(vport,
1225 CtReq->un.rspn.symbname, size);
1226 cmpl = lpfc_cmpl_ct_cmd_rspn_id;
1228 case SLI_CTNS_RSNN_NN:
1229 vport->ct_flags &= ~FC_CT_RSNN_NN;
1230 CtReq->CommandResponse.bits.CmdRsp =
1231 be16_to_cpu(SLI_CTNS_RSNN_NN);
1232 memcpy(CtReq->un.rsnn.wwnn, &vport->fc_nodename,
1233 sizeof (struct lpfc_name));
1234 size = sizeof(CtReq->un.rsnn.symbname);
1235 CtReq->un.rsnn.len =
1236 lpfc_vport_symbolic_node_name(vport,
1237 CtReq->un.rsnn.symbname, size);
1238 cmpl = lpfc_cmpl_ct_cmd_rsnn_nn;
1240 case SLI_CTNS_DA_ID:
1241 /* Implement DA_ID Nameserver request */
1242 CtReq->CommandResponse.bits.CmdRsp =
1243 be16_to_cpu(SLI_CTNS_DA_ID);
1244 CtReq->un.da_id.port_id = cpu_to_be32(vport->fc_myDID);
1245 cmpl = lpfc_cmpl_ct_cmd_da_id;
1247 case SLI_CTNS_RFF_ID:
1248 vport->ct_flags &= ~FC_CT_RFF_ID;
1249 CtReq->CommandResponse.bits.CmdRsp =
1250 be16_to_cpu(SLI_CTNS_RFF_ID);
1251 CtReq->un.rff.PortId = cpu_to_be32(vport->fc_myDID);
1252 CtReq->un.rff.fbits = FC4_FEATURE_INIT;
1253 CtReq->un.rff.type_code = FC_TYPE_FCP;
1254 cmpl = lpfc_cmpl_ct_cmd_rff_id;
1257 /* The lpfc_ct_cmd/lpfc_get_req shall increment ndlp reference count
1258 * to hold ndlp reference for the corresponding callback function.
1260 if (!lpfc_ct_cmd(vport, mp, bmp, ndlp, cmpl, rsp_size, retry)) {
1261 /* On success, The cmpl function will free the buffers */
1262 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
1263 "Issue CT cmd: cmd:x%x did:x%x",
1264 cmdcode, ndlp->nlp_DID, 0);
1269 /* Decrement ndlp reference count to release ndlp reference held
1270 * for the failed command's callback function.
1274 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
1278 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1282 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
1283 "0266 Issue NameServer Req x%x err %d Data: x%x x%x\n",
1284 cmdcode, rc, vport->fc_flag, vport->fc_rscn_id_cnt);
1289 lpfc_cmpl_ct_cmd_fdmi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1290 struct lpfc_iocbq * rspiocb)
1292 struct lpfc_dmabuf *inp = cmdiocb->context1;
1293 struct lpfc_dmabuf *outp = cmdiocb->context2;
1294 struct lpfc_sli_ct_request *CTrsp = outp->virt;
1295 struct lpfc_sli_ct_request *CTcmd = inp->virt;
1296 struct lpfc_nodelist *ndlp;
1297 uint16_t fdmi_cmd = CTcmd->CommandResponse.bits.CmdRsp;
1298 uint16_t fdmi_rsp = CTrsp->CommandResponse.bits.CmdRsp;
1299 struct lpfc_vport *vport = cmdiocb->vport;
1300 IOCB_t *irsp = &rspiocb->iocb;
1303 latt = lpfc_els_chk_latt(vport);
1305 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
1306 "FDMI cmpl: status:x%x/x%x latt:%d",
1307 irsp->ulpStatus, irsp->un.ulpWord[4], latt);
1309 if (latt || irsp->ulpStatus) {
1310 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1311 "0229 FDMI cmd %04x failed, latt = %d "
1312 "ulpStatus: x%x, rid x%x\n",
1313 be16_to_cpu(fdmi_cmd), latt, irsp->ulpStatus,
1314 irsp->un.ulpWord[4]);
1315 lpfc_ct_free_iocb(phba, cmdiocb);
1319 ndlp = lpfc_findnode_did(vport, FDMI_DID);
1320 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
1323 if (fdmi_rsp == be16_to_cpu(SLI_CT_RESPONSE_FS_RJT)) {
1324 /* FDMI rsp failed */
1325 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1326 "0220 FDMI rsp failed Data: x%x\n",
1327 be16_to_cpu(fdmi_cmd));
1330 switch (be16_to_cpu(fdmi_cmd)) {
1332 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RPA);
1339 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DPRT);
1343 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RHBA);
1348 lpfc_ct_free_iocb(phba, cmdiocb);
1353 lpfc_fdmi_cmd(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, int cmdcode)
1355 struct lpfc_hba *phba = vport->phba;
1356 struct lpfc_dmabuf *mp, *bmp;
1357 struct lpfc_sli_ct_request *CtReq;
1358 struct ulp_bde64 *bpl;
1362 REG_PORT_ATTRIBUTE *pab;
1363 ATTRIBUTE_BLOCK *ab;
1364 ATTRIBUTE_ENTRY *ae;
1365 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
1366 struct lpfc_iocbq *);
1369 /* fill in BDEs for command */
1370 /* Allocate buffer for command payload */
1371 mp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
1375 mp->virt = lpfc_mbuf_alloc(phba, 0, &(mp->phys));
1377 goto fdmi_cmd_free_mp;
1379 /* Allocate buffer for Buffer ptr list */
1380 bmp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
1382 goto fdmi_cmd_free_mpvirt;
1384 bmp->virt = lpfc_mbuf_alloc(phba, 0, &(bmp->phys));
1386 goto fdmi_cmd_free_bmp;
1388 INIT_LIST_HEAD(&mp->list);
1389 INIT_LIST_HEAD(&bmp->list);
1392 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1393 "0218 FDMI Request Data: x%x x%x x%x\n",
1394 vport->fc_flag, vport->port_state, cmdcode);
1395 CtReq = (struct lpfc_sli_ct_request *) mp->virt;
1397 memset(CtReq, 0, sizeof(struct lpfc_sli_ct_request));
1398 CtReq->RevisionId.bits.Revision = SLI_CT_REVISION;
1399 CtReq->RevisionId.bits.InId = 0;
1401 CtReq->FsType = SLI_CT_MANAGEMENT_SERVICE;
1402 CtReq->FsSubType = SLI_CT_FDMI_Subtypes;
1408 lpfc_vpd_t *vp = &phba->vpd;
1409 uint32_t i, j, incr;
1412 CtReq->CommandResponse.bits.CmdRsp =
1413 be16_to_cpu(SLI_MGMT_RHBA);
1414 CtReq->CommandResponse.bits.Size = 0;
1415 rh = (REG_HBA *) & CtReq->un.PortID;
1416 memcpy(&rh->hi.PortName, &vport->fc_sparam.portName,
1417 sizeof (struct lpfc_name));
1418 /* One entry (port) per adapter */
1419 rh->rpl.EntryCnt = be32_to_cpu(1);
1420 memcpy(&rh->rpl.pe, &vport->fc_sparam.portName,
1421 sizeof (struct lpfc_name));
1423 /* point to the HBA attribute block */
1424 size = 2 * sizeof (struct lpfc_name) + FOURBYTES;
1425 ab = (ATTRIBUTE_BLOCK *) ((uint8_t *) rh + size);
1428 /* Point to the beginning of the first HBA attribute
1430 /* #1 HBA attribute entry */
1432 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1433 ae->ad.bits.AttrType = be16_to_cpu(NODE_NAME);
1434 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES
1435 + sizeof (struct lpfc_name));
1436 memcpy(&ae->un.NodeName, &vport->fc_sparam.nodeName,
1437 sizeof (struct lpfc_name));
1439 size += FOURBYTES + sizeof (struct lpfc_name);
1441 /* #2 HBA attribute entry */
1442 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1443 ae->ad.bits.AttrType = be16_to_cpu(MANUFACTURER);
1444 strcpy(ae->un.Manufacturer, "Emulex Corporation");
1445 len = strlen(ae->un.Manufacturer);
1446 len += (len & 3) ? (4 - (len & 3)) : 4;
1447 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1449 size += FOURBYTES + len;
1451 /* #3 HBA attribute entry */
1452 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1453 ae->ad.bits.AttrType = be16_to_cpu(SERIAL_NUMBER);
1454 strcpy(ae->un.SerialNumber, phba->SerialNumber);
1455 len = strlen(ae->un.SerialNumber);
1456 len += (len & 3) ? (4 - (len & 3)) : 4;
1457 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1459 size += FOURBYTES + len;
1461 /* #4 HBA attribute entry */
1462 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1463 ae->ad.bits.AttrType = be16_to_cpu(MODEL);
1464 strcpy(ae->un.Model, phba->ModelName);
1465 len = strlen(ae->un.Model);
1466 len += (len & 3) ? (4 - (len & 3)) : 4;
1467 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1469 size += FOURBYTES + len;
1471 /* #5 HBA attribute entry */
1472 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1473 ae->ad.bits.AttrType = be16_to_cpu(MODEL_DESCRIPTION);
1474 strcpy(ae->un.ModelDescription, phba->ModelDesc);
1475 len = strlen(ae->un.ModelDescription);
1476 len += (len & 3) ? (4 - (len & 3)) : 4;
1477 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1479 size += FOURBYTES + len;
1481 /* #6 HBA attribute entry */
1482 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1483 ae->ad.bits.AttrType = be16_to_cpu(HARDWARE_VERSION);
1484 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 8);
1485 /* Convert JEDEC ID to ascii for hardware version */
1486 incr = vp->rev.biuRev;
1487 for (i = 0; i < 8; i++) {
1490 ae->un.HardwareVersion[7 - i] =
1491 (char)((uint8_t) 0x30 +
1494 ae->un.HardwareVersion[7 - i] =
1495 (char)((uint8_t) 0x61 +
1496 (uint8_t) (j - 10));
1500 size += FOURBYTES + 8;
1502 /* #7 HBA attribute entry */
1503 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1504 ae->ad.bits.AttrType = be16_to_cpu(DRIVER_VERSION);
1505 strcpy(ae->un.DriverVersion, lpfc_release_version);
1506 len = strlen(ae->un.DriverVersion);
1507 len += (len & 3) ? (4 - (len & 3)) : 4;
1508 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1510 size += FOURBYTES + len;
1512 /* #8 HBA attribute entry */
1513 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1514 ae->ad.bits.AttrType = be16_to_cpu(OPTION_ROM_VERSION);
1515 strcpy(ae->un.OptionROMVersion, phba->OptionROMVersion);
1516 len = strlen(ae->un.OptionROMVersion);
1517 len += (len & 3) ? (4 - (len & 3)) : 4;
1518 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1520 size += FOURBYTES + len;
1522 /* #9 HBA attribute entry */
1523 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1524 ae->ad.bits.AttrType = be16_to_cpu(FIRMWARE_VERSION);
1525 lpfc_decode_firmware_rev(phba, ae->un.FirmwareVersion,
1527 len = strlen(ae->un.FirmwareVersion);
1528 len += (len & 3) ? (4 - (len & 3)) : 4;
1529 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1531 size += FOURBYTES + len;
1533 /* #10 HBA attribute entry */
1534 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1535 ae->ad.bits.AttrType = be16_to_cpu(OS_NAME_VERSION);
1536 sprintf(ae->un.OsNameVersion, "%s %s %s",
1537 init_utsname()->sysname,
1538 init_utsname()->release,
1539 init_utsname()->version);
1540 len = strlen(ae->un.OsNameVersion);
1541 len += (len & 3) ? (4 - (len & 3)) : 4;
1542 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1544 size += FOURBYTES + len;
1546 /* #11 HBA attribute entry */
1547 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1548 ae->ad.bits.AttrType = be16_to_cpu(MAX_CT_PAYLOAD_LEN);
1549 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
1550 ae->un.MaxCTPayloadLen = (65 * 4096);
1552 size += FOURBYTES + 4;
1554 ab->EntryCnt = be32_to_cpu(ab->EntryCnt);
1556 size = GID_REQUEST_SZ - 4 + size;
1563 struct serv_parm *hsp;
1568 CtReq->CommandResponse.bits.CmdRsp =
1569 be16_to_cpu(SLI_MGMT_RPA);
1570 CtReq->CommandResponse.bits.Size = 0;
1571 pab = (REG_PORT_ATTRIBUTE *) & CtReq->un.PortID;
1572 size = sizeof (struct lpfc_name) + FOURBYTES;
1573 memcpy((uint8_t *) & pab->PortName,
1574 (uint8_t *) & vport->fc_sparam.portName,
1575 sizeof (struct lpfc_name));
1576 pab->ab.EntryCnt = 0;
1578 /* #1 Port attribute entry */
1579 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
1580 ae->ad.bits.AttrType = be16_to_cpu(SUPPORTED_FC4_TYPES);
1581 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 32);
1582 ae->un.SupportFC4Types[2] = 1;
1583 ae->un.SupportFC4Types[7] = 1;
1585 size += FOURBYTES + 32;
1587 /* #2 Port attribute entry */
1588 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
1589 ae->ad.bits.AttrType = be16_to_cpu(SUPPORTED_SPEED);
1590 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
1592 ae->un.SupportSpeed = 0;
1593 if (phba->lmt & LMT_10Gb)
1594 ae->un.SupportSpeed = HBA_PORTSPEED_10GBIT;
1595 if (phba->lmt & LMT_8Gb)
1596 ae->un.SupportSpeed |= HBA_PORTSPEED_8GBIT;
1597 if (phba->lmt & LMT_4Gb)
1598 ae->un.SupportSpeed |= HBA_PORTSPEED_4GBIT;
1599 if (phba->lmt & LMT_2Gb)
1600 ae->un.SupportSpeed |= HBA_PORTSPEED_2GBIT;
1601 if (phba->lmt & LMT_1Gb)
1602 ae->un.SupportSpeed |= HBA_PORTSPEED_1GBIT;
1605 size += FOURBYTES + 4;
1607 /* #3 Port attribute entry */
1608 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
1609 ae->ad.bits.AttrType = be16_to_cpu(PORT_SPEED);
1610 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
1611 switch(phba->fc_linkspeed) {
1613 ae->un.PortSpeed = HBA_PORTSPEED_1GBIT;
1616 ae->un.PortSpeed = HBA_PORTSPEED_2GBIT;
1619 ae->un.PortSpeed = HBA_PORTSPEED_4GBIT;
1622 ae->un.PortSpeed = HBA_PORTSPEED_8GBIT;
1625 ae->un.PortSpeed = HBA_PORTSPEED_10GBIT;
1629 HBA_PORTSPEED_UNKNOWN;
1633 size += FOURBYTES + 4;
1635 /* #4 Port attribute entry */
1636 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
1637 ae->ad.bits.AttrType = be16_to_cpu(MAX_FRAME_SIZE);
1638 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
1639 hsp = (struct serv_parm *) & vport->fc_sparam;
1640 ae->un.MaxFrameSize =
1641 (((uint32_t) hsp->cmn.
1642 bbRcvSizeMsb) << 8) | (uint32_t) hsp->cmn.
1645 size += FOURBYTES + 4;
1647 /* #5 Port attribute entry */
1648 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
1649 ae->ad.bits.AttrType = be16_to_cpu(OS_DEVICE_NAME);
1650 strcpy((char *)ae->un.OsDeviceName, LPFC_DRIVER_NAME);
1651 len = strlen((char *)ae->un.OsDeviceName);
1652 len += (len & 3) ? (4 - (len & 3)) : 4;
1653 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1655 size += FOURBYTES + len;
1657 if (vport->cfg_fdmi_on == 2) {
1658 /* #6 Port attribute entry */
1659 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab +
1661 ae->ad.bits.AttrType = be16_to_cpu(HOST_NAME);
1662 sprintf(ae->un.HostName, "%s",
1663 init_utsname()->nodename);
1664 len = strlen(ae->un.HostName);
1665 len += (len & 3) ? (4 - (len & 3)) : 4;
1666 ae->ad.bits.AttrLen =
1667 be16_to_cpu(FOURBYTES + len);
1669 size += FOURBYTES + len;
1672 pab->ab.EntryCnt = be32_to_cpu(pab->ab.EntryCnt);
1674 size = GID_REQUEST_SZ - 4 + size;
1679 CtReq->CommandResponse.bits.CmdRsp = be16_to_cpu(SLI_MGMT_DHBA);
1680 CtReq->CommandResponse.bits.Size = 0;
1681 pe = (PORT_ENTRY *) & CtReq->un.PortID;
1682 memcpy((uint8_t *) & pe->PortName,
1683 (uint8_t *) & vport->fc_sparam.portName,
1684 sizeof (struct lpfc_name));
1685 size = GID_REQUEST_SZ - 4 + sizeof (struct lpfc_name);
1689 CtReq->CommandResponse.bits.CmdRsp = be16_to_cpu(SLI_MGMT_DPRT);
1690 CtReq->CommandResponse.bits.Size = 0;
1691 pe = (PORT_ENTRY *) & CtReq->un.PortID;
1692 memcpy((uint8_t *) & pe->PortName,
1693 (uint8_t *) & vport->fc_sparam.portName,
1694 sizeof (struct lpfc_name));
1695 size = GID_REQUEST_SZ - 4 + sizeof (struct lpfc_name);
1699 bpl = (struct ulp_bde64 *) bmp->virt;
1700 bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys) );
1701 bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys) );
1702 bpl->tus.f.bdeFlags = 0;
1703 bpl->tus.f.bdeSize = size;
1704 bpl->tus.w = le32_to_cpu(bpl->tus.w);
1706 cmpl = lpfc_cmpl_ct_cmd_fdmi;
1708 /* The lpfc_ct_cmd/lpfc_get_req shall increment ndlp reference count
1709 * to hold ndlp reference for the corresponding callback function.
1711 if (!lpfc_ct_cmd(vport, mp, bmp, ndlp, cmpl, FC_MAX_NS_RSP, 0))
1714 /* Decrement ndlp reference count to release ndlp reference held
1715 * for the failed command's callback function.
1719 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
1722 fdmi_cmd_free_mpvirt:
1723 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1727 /* Issue FDMI request failed */
1728 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1729 "0244 Issue FDMI request failed Data: x%x\n",
1735 lpfc_fdmi_tmo(unsigned long ptr)
1737 struct lpfc_vport *vport = (struct lpfc_vport *)ptr;
1738 struct lpfc_hba *phba = vport->phba;
1739 uint32_t tmo_posted;
1740 unsigned long iflag;
1742 spin_lock_irqsave(&vport->work_port_lock, iflag);
1743 tmo_posted = vport->work_port_events & WORKER_FDMI_TMO;
1745 vport->work_port_events |= WORKER_FDMI_TMO;
1746 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
1749 lpfc_worker_wake_up(phba);
1754 lpfc_fdmi_timeout_handler(struct lpfc_vport *vport)
1756 struct lpfc_nodelist *ndlp;
1758 ndlp = lpfc_findnode_did(vport, FDMI_DID);
1759 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
1760 if (init_utsname()->nodename[0] != '\0')
1761 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA);
1763 mod_timer(&vport->fc_fdmitmo, jiffies + HZ * 60);
1769 lpfc_decode_firmware_rev(struct lpfc_hba *phba, char *fwrevision, int flag)
1771 struct lpfc_sli *psli = &phba->sli;
1772 lpfc_vpd_t *vp = &phba->vpd;
1773 uint32_t b1, b2, b3, b4, i, rev;
1775 uint32_t *ptr, str[4];
1778 if (phba->sli_rev == LPFC_SLI_REV4)
1779 sprintf(fwrevision, "%s", vp->rev.opFwName);
1780 else if (vp->rev.rBit) {
1781 if (psli->sli_flag & LPFC_SLI_ACTIVE)
1782 rev = vp->rev.sli2FwRev;
1784 rev = vp->rev.sli1FwRev;
1786 b1 = (rev & 0x0000f000) >> 12;
1787 b2 = (rev & 0x00000f00) >> 8;
1788 b3 = (rev & 0x000000c0) >> 6;
1789 b4 = (rev & 0x00000030) >> 4;
1805 b4 = (rev & 0x0000000f);
1807 if (psli->sli_flag & LPFC_SLI_ACTIVE)
1808 fwname = vp->rev.sli2FwName;
1810 fwname = vp->rev.sli1FwName;
1812 for (i = 0; i < 16; i++)
1813 if (fwname[i] == 0x20)
1816 ptr = (uint32_t*)fwname;
1818 for (i = 0; i < 3; i++)
1819 str[i] = be32_to_cpu(*ptr++);
1823 sprintf(fwrevision, "%d.%d%d (%s)",
1824 b1, b2, b3, (char *)str);
1826 sprintf(fwrevision, "%d.%d%d", b1,
1830 sprintf(fwrevision, "%d.%d%d%c%d (%s)",
1834 sprintf(fwrevision, "%d.%d%d%c%d",
1838 rev = vp->rev.smFwRev;
1840 b1 = (rev & 0xff000000) >> 24;
1841 b2 = (rev & 0x00f00000) >> 20;
1842 b3 = (rev & 0x000f0000) >> 16;
1843 c = (rev & 0x0000ff00) >> 8;
1844 b4 = (rev & 0x000000ff);
1847 sprintf(fwrevision, "%d.%d%d%c%d ", b1,
1850 sprintf(fwrevision, "%d.%d%d%c%d ", b1,