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>
38 #include "lpfc_sli4.h"
40 #include "lpfc_disc.h"
41 #include "lpfc_scsi.h"
43 #include "lpfc_logmsg.h"
44 #include "lpfc_crtn.h"
45 #include "lpfc_version.h"
46 #include "lpfc_vport.h"
47 #include "lpfc_debugfs.h"
49 #define HBA_PORTSPEED_UNKNOWN 0 /* Unknown - transceiver
50 * incapable of reporting */
51 #define HBA_PORTSPEED_1GBIT 1 /* 1 GBit/sec */
52 #define HBA_PORTSPEED_2GBIT 2 /* 2 GBit/sec */
53 #define HBA_PORTSPEED_4GBIT 8 /* 4 GBit/sec */
54 #define HBA_PORTSPEED_8GBIT 16 /* 8 GBit/sec */
55 #define HBA_PORTSPEED_10GBIT 4 /* 10 GBit/sec */
56 #define HBA_PORTSPEED_NOT_NEGOTIATED 5 /* Speed not established */
61 static char *lpfc_release_version = LPFC_DRIVER_VERSION;
64 lpfc_ct_ignore_hbq_buffer(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq,
65 struct lpfc_dmabuf *mp, uint32_t size)
68 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
69 "0146 Ignoring unsolicited CT No HBQ "
71 piocbq->iocb.ulpStatus);
73 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
74 "0145 Ignoring unsolicted CT HBQ Size:%d "
76 size, piocbq->iocb.ulpStatus);
80 lpfc_ct_unsol_buffer(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq,
81 struct lpfc_dmabuf *mp, uint32_t size)
83 lpfc_ct_ignore_hbq_buffer(phba, piocbq, mp, size);
87 lpfc_ct_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
88 struct lpfc_iocbq *piocbq)
90 struct lpfc_dmabuf *mp = NULL;
91 IOCB_t *icmd = &piocbq->iocb;
93 struct lpfc_iocbq *iocbq;
96 struct list_head head;
97 struct lpfc_dmabuf *bdeBuf;
99 lpfc_bsg_ct_unsol_event(phba, pring, piocbq);
101 if (unlikely(icmd->ulpStatus == IOSTAT_NEED_BUFFER)) {
102 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
103 } else if ((icmd->ulpStatus == IOSTAT_LOCAL_REJECT) &&
104 ((icmd->un.ulpWord[4] & 0xff) == IOERR_RCV_BUFFER_WAITING)) {
105 /* Not enough posted buffers; Try posting more buffers */
106 phba->fc_stat.NoRcvBuf++;
107 if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
108 lpfc_post_buffer(phba, pring, 2);
112 /* If there are no BDEs associated with this IOCB,
113 * there is nothing to do.
115 if (icmd->ulpBdeCount == 0)
118 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
119 INIT_LIST_HEAD(&head);
120 list_add_tail(&head, &piocbq->list);
121 list_for_each_entry(iocbq, &head, list) {
123 if (icmd->ulpBdeCount == 0)
125 bdeBuf = iocbq->context2;
126 iocbq->context2 = NULL;
127 size = icmd->un.cont64[0].tus.f.bdeSize;
128 lpfc_ct_unsol_buffer(phba, piocbq, bdeBuf, size);
129 lpfc_in_buf_free(phba, bdeBuf);
130 if (icmd->ulpBdeCount == 2) {
131 bdeBuf = iocbq->context3;
132 iocbq->context3 = NULL;
133 size = icmd->unsli3.rcvsli3.bde2.tus.f.bdeSize;
134 lpfc_ct_unsol_buffer(phba, piocbq, bdeBuf,
136 lpfc_in_buf_free(phba, bdeBuf);
141 INIT_LIST_HEAD(&head);
142 list_add_tail(&head, &piocbq->list);
143 list_for_each_entry(iocbq, &head, list) {
145 if (icmd->ulpBdeCount == 0)
146 lpfc_ct_unsol_buffer(phba, iocbq, NULL, 0);
147 for (i = 0; i < icmd->ulpBdeCount; i++) {
148 paddr = getPaddr(icmd->un.cont64[i].addrHigh,
149 icmd->un.cont64[i].addrLow);
150 mp = lpfc_sli_ringpostbuf_get(phba, pring,
152 size = icmd->un.cont64[i].tus.f.bdeSize;
153 lpfc_ct_unsol_buffer(phba, iocbq, mp, size);
154 lpfc_in_buf_free(phba, mp);
156 lpfc_post_buffer(phba, pring, i);
163 * lpfc_sli4_ct_abort_unsol_event - Default handle for sli4 unsol abort
164 * @phba: Pointer to HBA context object.
165 * @pring: Pointer to the driver internal I/O ring.
166 * @piocbq: Pointer to the IOCBQ.
168 * This function serves as the default handler for the sli4 unsolicited
169 * abort event. It shall be invoked when there is no application interface
170 * registered unsolicited abort handler. This handler does nothing but
171 * just simply releases the dma buffer used by the unsol abort event.
174 lpfc_sli4_ct_abort_unsol_event(struct lpfc_hba *phba,
175 struct lpfc_sli_ring *pring,
176 struct lpfc_iocbq *piocbq)
178 IOCB_t *icmd = &piocbq->iocb;
179 struct lpfc_dmabuf *bdeBuf;
182 /* Forward abort event to any process registered to receive ct event */
183 lpfc_bsg_ct_unsol_event(phba, pring, piocbq);
185 /* If there is no BDE associated with IOCB, there is nothing to do */
186 if (icmd->ulpBdeCount == 0)
188 bdeBuf = piocbq->context2;
189 piocbq->context2 = NULL;
190 size = icmd->un.cont64[0].tus.f.bdeSize;
191 lpfc_ct_unsol_buffer(phba, piocbq, bdeBuf, size);
192 lpfc_in_buf_free(phba, bdeBuf);
196 lpfc_free_ct_rsp(struct lpfc_hba *phba, struct lpfc_dmabuf *mlist)
198 struct lpfc_dmabuf *mlast, *next_mlast;
200 list_for_each_entry_safe(mlast, next_mlast, &mlist->list, list) {
201 lpfc_mbuf_free(phba, mlast->virt, mlast->phys);
202 list_del(&mlast->list);
205 lpfc_mbuf_free(phba, mlist->virt, mlist->phys);
210 static struct lpfc_dmabuf *
211 lpfc_alloc_ct_rsp(struct lpfc_hba *phba, int cmdcode, struct ulp_bde64 *bpl,
212 uint32_t size, int *entries)
214 struct lpfc_dmabuf *mlist = NULL;
215 struct lpfc_dmabuf *mp;
218 /* We get chunks of FCELSSIZE */
219 cnt = size > FCELSSIZE ? FCELSSIZE: size;
222 /* Allocate buffer for rsp payload */
223 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
226 lpfc_free_ct_rsp(phba, mlist);
230 INIT_LIST_HEAD(&mp->list);
232 if (cmdcode == be16_to_cpu(SLI_CTNS_GID_FT) ||
233 cmdcode == be16_to_cpu(SLI_CTNS_GFF_ID))
234 mp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(mp->phys));
236 mp->virt = lpfc_mbuf_alloc(phba, 0, &(mp->phys));
241 lpfc_free_ct_rsp(phba, mlist);
245 /* Queue it to a linked list */
249 list_add_tail(&mp->list, &mlist->list);
251 bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64I;
252 /* build buffer ptr list for IOCB */
253 bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys) );
254 bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys) );
255 bpl->tus.f.bdeSize = (uint16_t) cnt;
256 bpl->tus.w = le32_to_cpu(bpl->tus.w);
268 lpfc_ct_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *ctiocb)
270 struct lpfc_dmabuf *buf_ptr;
272 if (ctiocb->context_un.ndlp) {
273 lpfc_nlp_put(ctiocb->context_un.ndlp);
274 ctiocb->context_un.ndlp = NULL;
276 if (ctiocb->context1) {
277 buf_ptr = (struct lpfc_dmabuf *) ctiocb->context1;
278 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
280 ctiocb->context1 = NULL;
282 if (ctiocb->context2) {
283 lpfc_free_ct_rsp(phba, (struct lpfc_dmabuf *) ctiocb->context2);
284 ctiocb->context2 = NULL;
287 if (ctiocb->context3) {
288 buf_ptr = (struct lpfc_dmabuf *) ctiocb->context3;
289 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
291 ctiocb->context1 = NULL;
293 lpfc_sli_release_iocbq(phba, ctiocb);
298 lpfc_gen_req(struct lpfc_vport *vport, struct lpfc_dmabuf *bmp,
299 struct lpfc_dmabuf *inp, struct lpfc_dmabuf *outp,
300 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
301 struct lpfc_iocbq *),
302 struct lpfc_nodelist *ndlp, uint32_t usr_flg, uint32_t num_entry,
303 uint32_t tmo, uint8_t retry)
305 struct lpfc_hba *phba = vport->phba;
307 struct lpfc_iocbq *geniocb;
310 /* Allocate buffer for command iocb */
311 geniocb = lpfc_sli_get_iocbq(phba);
316 icmd = &geniocb->iocb;
317 icmd->un.genreq64.bdl.ulpIoTag32 = 0;
318 icmd->un.genreq64.bdl.addrHigh = putPaddrHigh(bmp->phys);
319 icmd->un.genreq64.bdl.addrLow = putPaddrLow(bmp->phys);
320 icmd->un.genreq64.bdl.bdeFlags = BUFF_TYPE_BLP_64;
321 icmd->un.genreq64.bdl.bdeSize = (num_entry * sizeof (struct ulp_bde64));
324 geniocb->context3 = NULL;
326 geniocb->context3 = (uint8_t *) bmp;
328 /* Save for completion so we can release these resources */
329 geniocb->context1 = (uint8_t *) inp;
330 geniocb->context2 = (uint8_t *) outp;
331 geniocb->context_un.ndlp = lpfc_nlp_get(ndlp);
333 /* Fill in payload, bp points to frame payload */
334 icmd->ulpCommand = CMD_GEN_REQUEST64_CR;
336 /* Fill in rest of iocb */
337 icmd->un.genreq64.w5.hcsw.Fctl = (SI | LA);
338 icmd->un.genreq64.w5.hcsw.Dfctl = 0;
339 icmd->un.genreq64.w5.hcsw.Rctl = FC_UNSOL_CTL;
340 icmd->un.genreq64.w5.hcsw.Type = FC_COMMON_TRANSPORT_ULP;
343 /* FC spec states we need 3 * ratov for CT requests */
344 tmo = (3 * phba->fc_ratov);
346 icmd->ulpTimeout = tmo;
347 icmd->ulpBdeCount = 1;
349 icmd->ulpClass = CLASS3;
350 icmd->ulpContext = ndlp->nlp_rpi;
352 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
353 /* For GEN_REQUEST64_CR, use the RPI */
358 /* Issue GEN REQ IOCB for NPORT <did> */
359 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
360 "0119 Issue GEN REQ IOCB to NPORT x%x "
362 ndlp->nlp_DID, icmd->ulpIoTag,
364 geniocb->iocb_cmpl = cmpl;
365 geniocb->drvrTimeout = icmd->ulpTimeout + LPFC_DRVR_TIMEOUT;
366 geniocb->vport = vport;
367 geniocb->retry = retry;
368 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, geniocb, 0);
370 if (rc == IOCB_ERROR) {
371 lpfc_sli_release_iocbq(phba, geniocb);
379 lpfc_ct_cmd(struct lpfc_vport *vport, struct lpfc_dmabuf *inmp,
380 struct lpfc_dmabuf *bmp, struct lpfc_nodelist *ndlp,
381 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
382 struct lpfc_iocbq *),
383 uint32_t rsp_size, uint8_t retry)
385 struct lpfc_hba *phba = vport->phba;
386 struct ulp_bde64 *bpl = (struct ulp_bde64 *) bmp->virt;
387 struct lpfc_dmabuf *outmp;
389 int cmdcode = ((struct lpfc_sli_ct_request *) inmp->virt)->
390 CommandResponse.bits.CmdRsp;
392 bpl++; /* Skip past ct request */
394 /* Put buffer(s) for ct rsp in bpl */
395 outmp = lpfc_alloc_ct_rsp(phba, cmdcode, bpl, rsp_size, &cnt);
399 status = lpfc_gen_req(vport, bmp, inmp, outmp, cmpl, ndlp, 0,
402 lpfc_free_ct_rsp(phba, outmp);
409 lpfc_find_vport_by_did(struct lpfc_hba *phba, uint32_t did) {
410 struct lpfc_vport *vport_curr;
413 spin_lock_irqsave(&phba->hbalock, flags);
414 list_for_each_entry(vport_curr, &phba->port_list, listentry) {
415 if ((vport_curr->fc_myDID) && (vport_curr->fc_myDID == did)) {
416 spin_unlock_irqrestore(&phba->hbalock, flags);
420 spin_unlock_irqrestore(&phba->hbalock, flags);
425 lpfc_ns_rsp(struct lpfc_vport *vport, struct lpfc_dmabuf *mp, uint32_t Size)
427 struct lpfc_hba *phba = vport->phba;
428 struct lpfc_sli_ct_request *Response =
429 (struct lpfc_sli_ct_request *) mp->virt;
430 struct lpfc_nodelist *ndlp = NULL;
431 struct lpfc_dmabuf *mlast, *next_mp;
432 uint32_t *ctptr = (uint32_t *) & Response->un.gid.PortType;
433 uint32_t Did, CTentry;
435 struct list_head head;
437 lpfc_set_disctmo(vport);
438 vport->num_disc_nodes = 0;
439 vport->fc_ns_retry = 0;
442 list_add_tail(&head, &mp->list);
443 list_for_each_entry_safe(mp, next_mp, &head, list) {
446 Cnt = Size > FCELSSIZE ? FCELSSIZE : Size;
451 ctptr = (uint32_t *) mlast->virt;
453 Cnt -= 16; /* subtract length of CT header */
455 /* Loop through entire NameServer list of DIDs */
456 while (Cnt >= sizeof (uint32_t)) {
457 /* Get next DID from NameServer List */
459 Did = ((be32_to_cpu(CTentry)) & Mask_DID);
464 * Check for rscn processing or not
465 * To conserve rpi's, filter out addresses for other
466 * vports on the same physical HBAs.
468 if ((Did != vport->fc_myDID) &&
469 ((lpfc_find_vport_by_did(phba, Did) == NULL) ||
470 vport->cfg_peer_port_login)) {
471 if ((vport->port_type != LPFC_NPIV_PORT) ||
472 (!(vport->ct_flags & FC_CT_RFF_ID)) ||
473 (!vport->cfg_restrict_login)) {
474 ndlp = lpfc_setup_disc_node(vport, Did);
475 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
476 lpfc_debugfs_disc_trc(vport,
479 "did:x%x flg:x%x x%x",
483 lpfc_printf_vlog(vport,
488 "Data: x%x x%x x%x\n",
491 vport->fc_rscn_id_cnt);
493 lpfc_debugfs_disc_trc(vport,
496 "did:x%x flg:x%x cnt:%d",
498 vport->fc_rscn_id_cnt);
500 lpfc_printf_vlog(vport,
504 "NameServer Rsp Data: "
507 vport->fc_rscn_id_cnt);
511 if (!(vport->fc_flag & FC_RSCN_MODE) ||
512 (lpfc_rscn_payload_check(vport, Did))) {
513 lpfc_debugfs_disc_trc(vport,
516 "did:x%x flg:x%x cnt:%d",
518 vport->fc_rscn_id_cnt);
520 /* This NPortID was previously
521 * a FCP target, * Don't even
522 * bother to send GFF_ID.
524 ndlp = lpfc_findnode_did(vport,
527 NLP_CHK_NODE_ACT(ndlp)
532 else if (lpfc_ns_cmd(vport,
535 vport->num_disc_nodes++;
538 lpfc_debugfs_disc_trc(vport,
541 "did:x%x flg:x%x cnt:%d",
543 vport->fc_rscn_id_cnt);
545 lpfc_printf_vlog(vport,
549 "NameServer Rsp Data: "
552 vport->fc_rscn_id_cnt);
556 if (CTentry & (be32_to_cpu(SLI_CT_LAST_ENTRY)))
558 Cnt -= sizeof (uint32_t);
570 lpfc_cmpl_ct_cmd_gid_ft(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
571 struct lpfc_iocbq *rspiocb)
573 struct lpfc_vport *vport = cmdiocb->vport;
574 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
576 struct lpfc_dmabuf *bmp;
577 struct lpfc_dmabuf *outp;
578 struct lpfc_sli_ct_request *CTrsp;
579 struct lpfc_nodelist *ndlp;
582 /* First save ndlp, before we overwrite it */
583 ndlp = cmdiocb->context_un.ndlp;
585 /* we pass cmdiocb to state machine which needs rspiocb as well */
586 cmdiocb->context_un.rsp_iocb = rspiocb;
588 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
589 bmp = (struct lpfc_dmabuf *) cmdiocb->context3;
590 irsp = &rspiocb->iocb;
592 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
593 "GID_FT cmpl: status:x%x/x%x rtry:%d",
594 irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_ns_retry);
596 /* Don't bother processing response if vport is being torn down. */
597 if (vport->load_flag & FC_UNLOADING) {
598 if (vport->fc_flag & FC_RSCN_MODE)
599 lpfc_els_flush_rscn(vport);
603 if (lpfc_els_chk_latt(vport)) {
604 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
605 "0216 Link event during NS query\n");
606 if (vport->fc_flag & FC_RSCN_MODE)
607 lpfc_els_flush_rscn(vport);
608 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
611 if (lpfc_error_lost_link(irsp)) {
612 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
613 "0226 NS query failed due to link event\n");
614 if (vport->fc_flag & FC_RSCN_MODE)
615 lpfc_els_flush_rscn(vport);
618 if (irsp->ulpStatus) {
619 /* Check for retry */
620 if (vport->fc_ns_retry < LPFC_MAX_NS_RETRY) {
621 if (irsp->ulpStatus != IOSTAT_LOCAL_REJECT ||
622 irsp->un.ulpWord[4] != IOERR_NO_RESOURCES)
623 vport->fc_ns_retry++;
625 /* CT command is being retried */
626 rc = lpfc_ns_cmd(vport, SLI_CTNS_GID_FT,
627 vport->fc_ns_retry, 0);
631 if (vport->fc_flag & FC_RSCN_MODE)
632 lpfc_els_flush_rscn(vport);
633 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
634 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
635 "0257 GID_FT Query error: 0x%x 0x%x\n",
636 irsp->ulpStatus, vport->fc_ns_retry);
638 /* Good status, continue checking */
639 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
640 if (CTrsp->CommandResponse.bits.CmdRsp ==
641 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC)) {
642 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
643 "0208 NameServer Rsp Data: x%x\n",
645 lpfc_ns_rsp(vport, outp,
646 (uint32_t) (irsp->un.genreq64.bdl.bdeSize));
647 } else if (CTrsp->CommandResponse.bits.CmdRsp ==
648 be16_to_cpu(SLI_CT_RESPONSE_FS_RJT)) {
649 /* NameServer Rsp Error */
650 if ((CTrsp->ReasonCode == SLI_CT_UNABLE_TO_PERFORM_REQ)
651 && (CTrsp->Explanation == SLI_CT_NO_FC4_TYPES)) {
652 lpfc_printf_vlog(vport, KERN_INFO,
654 "0269 No NameServer Entries "
655 "Data: x%x x%x x%x x%x\n",
656 CTrsp->CommandResponse.bits.CmdRsp,
657 (uint32_t) CTrsp->ReasonCode,
658 (uint32_t) CTrsp->Explanation,
661 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
662 "GID_FT no entry cmd:x%x rsn:x%x exp:x%x",
663 (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
664 (uint32_t) CTrsp->ReasonCode,
665 (uint32_t) CTrsp->Explanation);
667 lpfc_printf_vlog(vport, KERN_INFO,
669 "0240 NameServer Rsp Error "
670 "Data: x%x x%x x%x x%x\n",
671 CTrsp->CommandResponse.bits.CmdRsp,
672 (uint32_t) CTrsp->ReasonCode,
673 (uint32_t) CTrsp->Explanation,
676 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
677 "GID_FT rsp err1 cmd:x%x rsn:x%x exp:x%x",
678 (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
679 (uint32_t) CTrsp->ReasonCode,
680 (uint32_t) CTrsp->Explanation);
685 /* NameServer Rsp Error */
686 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
687 "0241 NameServer Rsp Error "
688 "Data: x%x x%x x%x x%x\n",
689 CTrsp->CommandResponse.bits.CmdRsp,
690 (uint32_t) CTrsp->ReasonCode,
691 (uint32_t) CTrsp->Explanation,
694 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
695 "GID_FT rsp err2 cmd:x%x rsn:x%x exp:x%x",
696 (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
697 (uint32_t) CTrsp->ReasonCode,
698 (uint32_t) CTrsp->Explanation);
701 /* Link up / RSCN discovery */
702 if (vport->num_disc_nodes == 0) {
704 * The driver has cycled through all Nports in the RSCN payload.
705 * Complete the handling by cleaning up and marking the
706 * current driver state.
708 if (vport->port_state >= LPFC_DISC_AUTH) {
709 if (vport->fc_flag & FC_RSCN_MODE) {
710 lpfc_els_flush_rscn(vport);
711 spin_lock_irq(shost->host_lock);
712 vport->fc_flag |= FC_RSCN_MODE; /* RSCN still */
713 spin_unlock_irq(shost->host_lock);
716 lpfc_els_flush_rscn(vport);
719 lpfc_disc_start(vport);
722 cmdiocb->context_un.ndlp = ndlp; /* Now restore ndlp for free */
723 lpfc_ct_free_iocb(phba, cmdiocb);
728 lpfc_cmpl_ct_cmd_gff_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
729 struct lpfc_iocbq *rspiocb)
731 struct lpfc_vport *vport = cmdiocb->vport;
732 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
733 IOCB_t *irsp = &rspiocb->iocb;
734 struct lpfc_dmabuf *inp = (struct lpfc_dmabuf *) cmdiocb->context1;
735 struct lpfc_dmabuf *outp = (struct lpfc_dmabuf *) cmdiocb->context2;
736 struct lpfc_sli_ct_request *CTrsp;
739 struct lpfc_nodelist *ndlp;
741 did = ((struct lpfc_sli_ct_request *) inp->virt)->un.gff.PortId;
742 did = be32_to_cpu(did);
744 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
745 "GFF_ID cmpl: status:x%x/x%x did:x%x",
746 irsp->ulpStatus, irsp->un.ulpWord[4], did);
748 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
749 /* Good status, continue checking */
750 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
751 fbits = CTrsp->un.gff_acc.fbits[FCP_TYPE_FEATURE_OFFSET];
753 if (CTrsp->CommandResponse.bits.CmdRsp ==
754 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC)) {
755 if ((fbits & FC4_FEATURE_INIT) &&
756 !(fbits & FC4_FEATURE_TARGET)) {
757 lpfc_printf_vlog(vport, KERN_INFO,
760 "NameServer Rsp Data: (init) "
761 "x%x x%x\n", did, fbits,
762 vport->fc_rscn_id_cnt);
768 /* Check for retry */
769 if (cmdiocb->retry < LPFC_MAX_NS_RETRY) {
771 if (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) {
772 switch (irsp->un.ulpWord[4]) {
773 case IOERR_NO_RESOURCES:
774 /* We don't increment the retry
775 * count for this case.
778 case IOERR_LINK_DOWN:
779 case IOERR_SLI_ABORTED:
791 /* CT command is being retried */
792 rc = lpfc_ns_cmd(vport, SLI_CTNS_GFF_ID,
793 cmdiocb->retry, did);
796 lpfc_ct_free_iocb(phba, cmdiocb);
801 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
802 "0267 NameServer GFF Rsp "
803 "x%x Error (%d %d) Data: x%x x%x\n",
804 did, irsp->ulpStatus, irsp->un.ulpWord[4],
805 vport->fc_flag, vport->fc_rscn_id_cnt);
808 /* This is a target port, unregistered port, or the GFF_ID failed */
809 ndlp = lpfc_setup_disc_node(vport, did);
810 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
811 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
812 "0242 Process x%x GFF "
813 "NameServer Rsp Data: x%x x%x x%x\n",
814 did, ndlp->nlp_flag, vport->fc_flag,
815 vport->fc_rscn_id_cnt);
817 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
819 "NameServer Rsp Data: x%x x%x\n", did,
820 vport->fc_flag, vport->fc_rscn_id_cnt);
823 /* Link up / RSCN discovery */
824 if (vport->num_disc_nodes)
825 vport->num_disc_nodes--;
826 if (vport->num_disc_nodes == 0) {
828 * The driver has cycled through all Nports in the RSCN payload.
829 * Complete the handling by cleaning up and marking the
830 * current driver state.
832 if (vport->port_state >= LPFC_DISC_AUTH) {
833 if (vport->fc_flag & FC_RSCN_MODE) {
834 lpfc_els_flush_rscn(vport);
835 spin_lock_irq(shost->host_lock);
836 vport->fc_flag |= FC_RSCN_MODE; /* RSCN still */
837 spin_unlock_irq(shost->host_lock);
840 lpfc_els_flush_rscn(vport);
842 lpfc_disc_start(vport);
844 lpfc_ct_free_iocb(phba, cmdiocb);
850 lpfc_cmpl_ct(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
851 struct lpfc_iocbq *rspiocb)
853 struct lpfc_vport *vport = cmdiocb->vport;
854 struct lpfc_dmabuf *inp;
855 struct lpfc_dmabuf *outp;
857 struct lpfc_sli_ct_request *CTrsp;
858 struct lpfc_nodelist *ndlp;
863 /* First save ndlp, before we overwrite it */
864 ndlp = cmdiocb->context_un.ndlp;
866 /* we pass cmdiocb to state machine which needs rspiocb as well */
867 cmdiocb->context_un.rsp_iocb = rspiocb;
869 inp = (struct lpfc_dmabuf *) cmdiocb->context1;
870 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
871 irsp = &rspiocb->iocb;
873 cmdcode = be16_to_cpu(((struct lpfc_sli_ct_request *) inp->virt)->
874 CommandResponse.bits.CmdRsp);
875 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
877 latt = lpfc_els_chk_latt(vport);
879 /* RFT request completes status <ulpStatus> CmdRsp <CmdRsp> */
880 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
881 "0209 CT Request completes, latt %d, "
882 "ulpStatus x%x CmdRsp x%x, Context x%x, Tag x%x\n",
883 latt, irsp->ulpStatus,
884 CTrsp->CommandResponse.bits.CmdRsp,
885 cmdiocb->iocb.ulpContext, cmdiocb->iocb.ulpIoTag);
887 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
888 "CT cmd cmpl: status:x%x/x%x cmd:x%x",
889 irsp->ulpStatus, irsp->un.ulpWord[4], cmdcode);
891 if (irsp->ulpStatus) {
892 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
893 "0268 NS cmd %x Error (%d %d)\n",
894 cmdcode, irsp->ulpStatus, irsp->un.ulpWord[4]);
896 if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
897 ((irsp->un.ulpWord[4] == IOERR_SLI_DOWN) ||
898 (irsp->un.ulpWord[4] == IOERR_SLI_ABORTED)))
901 retry = cmdiocb->retry;
902 if (retry >= LPFC_MAX_NS_RETRY)
906 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
907 "0250 Retrying NS cmd %x\n", cmdcode);
908 rc = lpfc_ns_cmd(vport, cmdcode, retry, 0);
914 cmdiocb->context_un.ndlp = ndlp; /* Now restore ndlp for free */
915 lpfc_ct_free_iocb(phba, cmdiocb);
920 lpfc_cmpl_ct_cmd_rft_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
921 struct lpfc_iocbq *rspiocb)
923 IOCB_t *irsp = &rspiocb->iocb;
924 struct lpfc_vport *vport = cmdiocb->vport;
926 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
927 struct lpfc_dmabuf *outp;
928 struct lpfc_sli_ct_request *CTrsp;
930 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
931 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
932 if (CTrsp->CommandResponse.bits.CmdRsp ==
933 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
934 vport->ct_flags |= FC_CT_RFT_ID;
936 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
941 lpfc_cmpl_ct_cmd_rnn_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
942 struct lpfc_iocbq *rspiocb)
944 IOCB_t *irsp = &rspiocb->iocb;
945 struct lpfc_vport *vport = cmdiocb->vport;
947 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
948 struct lpfc_dmabuf *outp;
949 struct lpfc_sli_ct_request *CTrsp;
951 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
952 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
953 if (CTrsp->CommandResponse.bits.CmdRsp ==
954 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
955 vport->ct_flags |= FC_CT_RNN_ID;
957 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
962 lpfc_cmpl_ct_cmd_rspn_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
963 struct lpfc_iocbq *rspiocb)
965 IOCB_t *irsp = &rspiocb->iocb;
966 struct lpfc_vport *vport = cmdiocb->vport;
968 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
969 struct lpfc_dmabuf *outp;
970 struct lpfc_sli_ct_request *CTrsp;
972 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
973 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
974 if (CTrsp->CommandResponse.bits.CmdRsp ==
975 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
976 vport->ct_flags |= FC_CT_RSPN_ID;
978 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
983 lpfc_cmpl_ct_cmd_rsnn_nn(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
984 struct lpfc_iocbq *rspiocb)
986 IOCB_t *irsp = &rspiocb->iocb;
987 struct lpfc_vport *vport = cmdiocb->vport;
989 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
990 struct lpfc_dmabuf *outp;
991 struct lpfc_sli_ct_request *CTrsp;
993 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
994 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
995 if (CTrsp->CommandResponse.bits.CmdRsp ==
996 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
997 vport->ct_flags |= FC_CT_RSNN_NN;
999 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
1004 lpfc_cmpl_ct_cmd_da_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1005 struct lpfc_iocbq *rspiocb)
1007 struct lpfc_vport *vport = cmdiocb->vport;
1009 /* even if it fails we will act as though it succeeded. */
1010 vport->ct_flags = 0;
1011 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
1016 lpfc_cmpl_ct_cmd_rff_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1017 struct lpfc_iocbq *rspiocb)
1019 IOCB_t *irsp = &rspiocb->iocb;
1020 struct lpfc_vport *vport = cmdiocb->vport;
1022 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
1023 struct lpfc_dmabuf *outp;
1024 struct lpfc_sli_ct_request *CTrsp;
1026 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
1027 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
1028 if (CTrsp->CommandResponse.bits.CmdRsp ==
1029 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
1030 vport->ct_flags |= FC_CT_RFF_ID;
1032 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
1037 lpfc_vport_symbolic_port_name(struct lpfc_vport *vport, char *symbol,
1041 uint8_t *wwn = vport->phba->wwpn;
1043 n = snprintf(symbol, size,
1044 "Emulex PPN-%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x",
1045 wwn[0], wwn[1], wwn[2], wwn[3],
1046 wwn[4], wwn[5], wwn[6], wwn[7]);
1048 if (vport->port_type == LPFC_PHYSICAL_PORT)
1052 n += snprintf(symbol + n, size - n, " VPort-%d", vport->vpi);
1055 strlen(vport->fc_vport->symbolic_name))
1056 n += snprintf(symbol + n, size - n, " VName-%s",
1057 vport->fc_vport->symbolic_name);
1062 lpfc_vport_symbolic_node_name(struct lpfc_vport *vport, char *symbol,
1068 lpfc_decode_firmware_rev(vport->phba, fwrev, 0);
1070 n = snprintf(symbol, size, "Emulex %s FV%s DV%s",
1071 vport->phba->ModelName, fwrev, lpfc_release_version);
1078 * Issue Cmd to NameServer
1083 lpfc_ns_cmd(struct lpfc_vport *vport, int cmdcode,
1084 uint8_t retry, uint32_t context)
1086 struct lpfc_nodelist * ndlp;
1087 struct lpfc_hba *phba = vport->phba;
1088 struct lpfc_dmabuf *mp, *bmp;
1089 struct lpfc_sli_ct_request *CtReq;
1090 struct ulp_bde64 *bpl;
1091 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
1092 struct lpfc_iocbq *) = NULL;
1093 uint32_t rsp_size = 1024;
1097 ndlp = lpfc_findnode_did(vport, NameServer_DID);
1098 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)
1099 || ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) {
1104 /* fill in BDEs for command */
1105 /* Allocate buffer for command payload */
1106 mp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
1112 INIT_LIST_HEAD(&mp->list);
1113 mp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(mp->phys));
1116 goto ns_cmd_free_mp;
1119 /* Allocate buffer for Buffer ptr list */
1120 bmp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
1123 goto ns_cmd_free_mpvirt;
1126 INIT_LIST_HEAD(&bmp->list);
1127 bmp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(bmp->phys));
1130 goto ns_cmd_free_bmp;
1133 /* NameServer Req */
1134 lpfc_printf_vlog(vport, KERN_INFO ,LOG_DISCOVERY,
1135 "0236 NameServer Req Data: x%x x%x x%x\n",
1136 cmdcode, vport->fc_flag, vport->fc_rscn_id_cnt);
1138 bpl = (struct ulp_bde64 *) bmp->virt;
1139 memset(bpl, 0, sizeof(struct ulp_bde64));
1140 bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys) );
1141 bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys) );
1142 bpl->tus.f.bdeFlags = 0;
1143 if (cmdcode == SLI_CTNS_GID_FT)
1144 bpl->tus.f.bdeSize = GID_REQUEST_SZ;
1145 else if (cmdcode == SLI_CTNS_GFF_ID)
1146 bpl->tus.f.bdeSize = GFF_REQUEST_SZ;
1147 else if (cmdcode == SLI_CTNS_RFT_ID)
1148 bpl->tus.f.bdeSize = RFT_REQUEST_SZ;
1149 else if (cmdcode == SLI_CTNS_RNN_ID)
1150 bpl->tus.f.bdeSize = RNN_REQUEST_SZ;
1151 else if (cmdcode == SLI_CTNS_RSPN_ID)
1152 bpl->tus.f.bdeSize = RSPN_REQUEST_SZ;
1153 else if (cmdcode == SLI_CTNS_RSNN_NN)
1154 bpl->tus.f.bdeSize = RSNN_REQUEST_SZ;
1155 else if (cmdcode == SLI_CTNS_DA_ID)
1156 bpl->tus.f.bdeSize = DA_ID_REQUEST_SZ;
1157 else if (cmdcode == SLI_CTNS_RFF_ID)
1158 bpl->tus.f.bdeSize = RFF_REQUEST_SZ;
1160 bpl->tus.f.bdeSize = 0;
1161 bpl->tus.w = le32_to_cpu(bpl->tus.w);
1163 CtReq = (struct lpfc_sli_ct_request *) mp->virt;
1164 memset(CtReq, 0, sizeof (struct lpfc_sli_ct_request));
1165 CtReq->RevisionId.bits.Revision = SLI_CT_REVISION;
1166 CtReq->RevisionId.bits.InId = 0;
1167 CtReq->FsType = SLI_CT_DIRECTORY_SERVICE;
1168 CtReq->FsSubType = SLI_CT_DIRECTORY_NAME_SERVER;
1169 CtReq->CommandResponse.bits.Size = 0;
1171 case SLI_CTNS_GID_FT:
1172 CtReq->CommandResponse.bits.CmdRsp =
1173 be16_to_cpu(SLI_CTNS_GID_FT);
1174 CtReq->un.gid.Fc4Type = SLI_CTPT_FCP;
1175 if (vport->port_state < LPFC_NS_QRY)
1176 vport->port_state = LPFC_NS_QRY;
1177 lpfc_set_disctmo(vport);
1178 cmpl = lpfc_cmpl_ct_cmd_gid_ft;
1179 rsp_size = FC_MAX_NS_RSP;
1182 case SLI_CTNS_GFF_ID:
1183 CtReq->CommandResponse.bits.CmdRsp =
1184 be16_to_cpu(SLI_CTNS_GFF_ID);
1185 CtReq->un.gff.PortId = cpu_to_be32(context);
1186 cmpl = lpfc_cmpl_ct_cmd_gff_id;
1189 case SLI_CTNS_RFT_ID:
1190 vport->ct_flags &= ~FC_CT_RFT_ID;
1191 CtReq->CommandResponse.bits.CmdRsp =
1192 be16_to_cpu(SLI_CTNS_RFT_ID);
1193 CtReq->un.rft.PortId = cpu_to_be32(vport->fc_myDID);
1194 CtReq->un.rft.fcpReg = 1;
1195 cmpl = lpfc_cmpl_ct_cmd_rft_id;
1198 case SLI_CTNS_RNN_ID:
1199 vport->ct_flags &= ~FC_CT_RNN_ID;
1200 CtReq->CommandResponse.bits.CmdRsp =
1201 be16_to_cpu(SLI_CTNS_RNN_ID);
1202 CtReq->un.rnn.PortId = cpu_to_be32(vport->fc_myDID);
1203 memcpy(CtReq->un.rnn.wwnn, &vport->fc_nodename,
1204 sizeof (struct lpfc_name));
1205 cmpl = lpfc_cmpl_ct_cmd_rnn_id;
1208 case SLI_CTNS_RSPN_ID:
1209 vport->ct_flags &= ~FC_CT_RSPN_ID;
1210 CtReq->CommandResponse.bits.CmdRsp =
1211 be16_to_cpu(SLI_CTNS_RSPN_ID);
1212 CtReq->un.rspn.PortId = cpu_to_be32(vport->fc_myDID);
1213 size = sizeof(CtReq->un.rspn.symbname);
1214 CtReq->un.rspn.len =
1215 lpfc_vport_symbolic_port_name(vport,
1216 CtReq->un.rspn.symbname, size);
1217 cmpl = lpfc_cmpl_ct_cmd_rspn_id;
1219 case SLI_CTNS_RSNN_NN:
1220 vport->ct_flags &= ~FC_CT_RSNN_NN;
1221 CtReq->CommandResponse.bits.CmdRsp =
1222 be16_to_cpu(SLI_CTNS_RSNN_NN);
1223 memcpy(CtReq->un.rsnn.wwnn, &vport->fc_nodename,
1224 sizeof (struct lpfc_name));
1225 size = sizeof(CtReq->un.rsnn.symbname);
1226 CtReq->un.rsnn.len =
1227 lpfc_vport_symbolic_node_name(vport,
1228 CtReq->un.rsnn.symbname, size);
1229 cmpl = lpfc_cmpl_ct_cmd_rsnn_nn;
1231 case SLI_CTNS_DA_ID:
1232 /* Implement DA_ID Nameserver request */
1233 CtReq->CommandResponse.bits.CmdRsp =
1234 be16_to_cpu(SLI_CTNS_DA_ID);
1235 CtReq->un.da_id.port_id = cpu_to_be32(vport->fc_myDID);
1236 cmpl = lpfc_cmpl_ct_cmd_da_id;
1238 case SLI_CTNS_RFF_ID:
1239 vport->ct_flags &= ~FC_CT_RFF_ID;
1240 CtReq->CommandResponse.bits.CmdRsp =
1241 be16_to_cpu(SLI_CTNS_RFF_ID);
1242 CtReq->un.rff.PortId = cpu_to_be32(vport->fc_myDID);
1243 CtReq->un.rff.fbits = FC4_FEATURE_INIT;
1244 CtReq->un.rff.type_code = FC_FCP_DATA;
1245 cmpl = lpfc_cmpl_ct_cmd_rff_id;
1248 /* The lpfc_ct_cmd/lpfc_get_req shall increment ndlp reference count
1249 * to hold ndlp reference for the corresponding callback function.
1251 if (!lpfc_ct_cmd(vport, mp, bmp, ndlp, cmpl, rsp_size, retry)) {
1252 /* On success, The cmpl function will free the buffers */
1253 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
1254 "Issue CT cmd: cmd:x%x did:x%x",
1255 cmdcode, ndlp->nlp_DID, 0);
1260 /* Decrement ndlp reference count to release ndlp reference held
1261 * for the failed command's callback function.
1265 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
1269 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1273 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
1274 "0266 Issue NameServer Req x%x err %d Data: x%x x%x\n",
1275 cmdcode, rc, vport->fc_flag, vport->fc_rscn_id_cnt);
1280 lpfc_cmpl_ct_cmd_fdmi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1281 struct lpfc_iocbq * rspiocb)
1283 struct lpfc_dmabuf *inp = cmdiocb->context1;
1284 struct lpfc_dmabuf *outp = cmdiocb->context2;
1285 struct lpfc_sli_ct_request *CTrsp = outp->virt;
1286 struct lpfc_sli_ct_request *CTcmd = inp->virt;
1287 struct lpfc_nodelist *ndlp;
1288 uint16_t fdmi_cmd = CTcmd->CommandResponse.bits.CmdRsp;
1289 uint16_t fdmi_rsp = CTrsp->CommandResponse.bits.CmdRsp;
1290 struct lpfc_vport *vport = cmdiocb->vport;
1291 IOCB_t *irsp = &rspiocb->iocb;
1294 latt = lpfc_els_chk_latt(vport);
1296 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
1297 "FDMI cmpl: status:x%x/x%x latt:%d",
1298 irsp->ulpStatus, irsp->un.ulpWord[4], latt);
1300 if (latt || irsp->ulpStatus) {
1301 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1302 "0229 FDMI cmd %04x failed, latt = %d "
1303 "ulpStatus: x%x, rid x%x\n",
1304 be16_to_cpu(fdmi_cmd), latt, irsp->ulpStatus,
1305 irsp->un.ulpWord[4]);
1306 lpfc_ct_free_iocb(phba, cmdiocb);
1310 ndlp = lpfc_findnode_did(vport, FDMI_DID);
1311 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
1314 if (fdmi_rsp == be16_to_cpu(SLI_CT_RESPONSE_FS_RJT)) {
1315 /* FDMI rsp failed */
1316 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1317 "0220 FDMI rsp failed Data: x%x\n",
1318 be16_to_cpu(fdmi_cmd));
1321 switch (be16_to_cpu(fdmi_cmd)) {
1323 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RPA);
1330 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DPRT);
1334 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RHBA);
1339 lpfc_ct_free_iocb(phba, cmdiocb);
1344 lpfc_fdmi_cmd(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, int cmdcode)
1346 struct lpfc_hba *phba = vport->phba;
1347 struct lpfc_dmabuf *mp, *bmp;
1348 struct lpfc_sli_ct_request *CtReq;
1349 struct ulp_bde64 *bpl;
1353 REG_PORT_ATTRIBUTE *pab;
1354 ATTRIBUTE_BLOCK *ab;
1355 ATTRIBUTE_ENTRY *ae;
1356 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
1357 struct lpfc_iocbq *);
1360 /* fill in BDEs for command */
1361 /* Allocate buffer for command payload */
1362 mp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
1366 mp->virt = lpfc_mbuf_alloc(phba, 0, &(mp->phys));
1368 goto fdmi_cmd_free_mp;
1370 /* Allocate buffer for Buffer ptr list */
1371 bmp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
1373 goto fdmi_cmd_free_mpvirt;
1375 bmp->virt = lpfc_mbuf_alloc(phba, 0, &(bmp->phys));
1377 goto fdmi_cmd_free_bmp;
1379 INIT_LIST_HEAD(&mp->list);
1380 INIT_LIST_HEAD(&bmp->list);
1383 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1384 "0218 FDMI Request Data: x%x x%x x%x\n",
1385 vport->fc_flag, vport->port_state, cmdcode);
1386 CtReq = (struct lpfc_sli_ct_request *) mp->virt;
1388 memset(CtReq, 0, sizeof(struct lpfc_sli_ct_request));
1389 CtReq->RevisionId.bits.Revision = SLI_CT_REVISION;
1390 CtReq->RevisionId.bits.InId = 0;
1392 CtReq->FsType = SLI_CT_MANAGEMENT_SERVICE;
1393 CtReq->FsSubType = SLI_CT_FDMI_Subtypes;
1399 lpfc_vpd_t *vp = &phba->vpd;
1400 uint32_t i, j, incr;
1403 CtReq->CommandResponse.bits.CmdRsp =
1404 be16_to_cpu(SLI_MGMT_RHBA);
1405 CtReq->CommandResponse.bits.Size = 0;
1406 rh = (REG_HBA *) & CtReq->un.PortID;
1407 memcpy(&rh->hi.PortName, &vport->fc_sparam.portName,
1408 sizeof (struct lpfc_name));
1409 /* One entry (port) per adapter */
1410 rh->rpl.EntryCnt = be32_to_cpu(1);
1411 memcpy(&rh->rpl.pe, &vport->fc_sparam.portName,
1412 sizeof (struct lpfc_name));
1414 /* point to the HBA attribute block */
1415 size = 2 * sizeof (struct lpfc_name) + FOURBYTES;
1416 ab = (ATTRIBUTE_BLOCK *) ((uint8_t *) rh + size);
1419 /* Point to the beginning of the first HBA attribute
1421 /* #1 HBA attribute entry */
1423 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1424 ae->ad.bits.AttrType = be16_to_cpu(NODE_NAME);
1425 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES
1426 + sizeof (struct lpfc_name));
1427 memcpy(&ae->un.NodeName, &vport->fc_sparam.nodeName,
1428 sizeof (struct lpfc_name));
1430 size += FOURBYTES + sizeof (struct lpfc_name);
1432 /* #2 HBA attribute entry */
1433 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1434 ae->ad.bits.AttrType = be16_to_cpu(MANUFACTURER);
1435 strcpy(ae->un.Manufacturer, "Emulex Corporation");
1436 len = strlen(ae->un.Manufacturer);
1437 len += (len & 3) ? (4 - (len & 3)) : 4;
1438 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1440 size += FOURBYTES + len;
1442 /* #3 HBA attribute entry */
1443 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1444 ae->ad.bits.AttrType = be16_to_cpu(SERIAL_NUMBER);
1445 strcpy(ae->un.SerialNumber, phba->SerialNumber);
1446 len = strlen(ae->un.SerialNumber);
1447 len += (len & 3) ? (4 - (len & 3)) : 4;
1448 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1450 size += FOURBYTES + len;
1452 /* #4 HBA attribute entry */
1453 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1454 ae->ad.bits.AttrType = be16_to_cpu(MODEL);
1455 strcpy(ae->un.Model, phba->ModelName);
1456 len = strlen(ae->un.Model);
1457 len += (len & 3) ? (4 - (len & 3)) : 4;
1458 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1460 size += FOURBYTES + len;
1462 /* #5 HBA attribute entry */
1463 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1464 ae->ad.bits.AttrType = be16_to_cpu(MODEL_DESCRIPTION);
1465 strcpy(ae->un.ModelDescription, phba->ModelDesc);
1466 len = strlen(ae->un.ModelDescription);
1467 len += (len & 3) ? (4 - (len & 3)) : 4;
1468 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1470 size += FOURBYTES + len;
1472 /* #6 HBA attribute entry */
1473 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1474 ae->ad.bits.AttrType = be16_to_cpu(HARDWARE_VERSION);
1475 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 8);
1476 /* Convert JEDEC ID to ascii for hardware version */
1477 incr = vp->rev.biuRev;
1478 for (i = 0; i < 8; i++) {
1481 ae->un.HardwareVersion[7 - i] =
1482 (char)((uint8_t) 0x30 +
1485 ae->un.HardwareVersion[7 - i] =
1486 (char)((uint8_t) 0x61 +
1487 (uint8_t) (j - 10));
1491 size += FOURBYTES + 8;
1493 /* #7 HBA attribute entry */
1494 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1495 ae->ad.bits.AttrType = be16_to_cpu(DRIVER_VERSION);
1496 strcpy(ae->un.DriverVersion, lpfc_release_version);
1497 len = strlen(ae->un.DriverVersion);
1498 len += (len & 3) ? (4 - (len & 3)) : 4;
1499 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1501 size += FOURBYTES + len;
1503 /* #8 HBA attribute entry */
1504 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1505 ae->ad.bits.AttrType = be16_to_cpu(OPTION_ROM_VERSION);
1506 strcpy(ae->un.OptionROMVersion, phba->OptionROMVersion);
1507 len = strlen(ae->un.OptionROMVersion);
1508 len += (len & 3) ? (4 - (len & 3)) : 4;
1509 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1511 size += FOURBYTES + len;
1513 /* #9 HBA attribute entry */
1514 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1515 ae->ad.bits.AttrType = be16_to_cpu(FIRMWARE_VERSION);
1516 lpfc_decode_firmware_rev(phba, ae->un.FirmwareVersion,
1518 len = strlen(ae->un.FirmwareVersion);
1519 len += (len & 3) ? (4 - (len & 3)) : 4;
1520 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1522 size += FOURBYTES + len;
1524 /* #10 HBA attribute entry */
1525 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1526 ae->ad.bits.AttrType = be16_to_cpu(OS_NAME_VERSION);
1527 sprintf(ae->un.OsNameVersion, "%s %s %s",
1528 init_utsname()->sysname,
1529 init_utsname()->release,
1530 init_utsname()->version);
1531 len = strlen(ae->un.OsNameVersion);
1532 len += (len & 3) ? (4 - (len & 3)) : 4;
1533 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1535 size += FOURBYTES + len;
1537 /* #11 HBA attribute entry */
1538 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1539 ae->ad.bits.AttrType = be16_to_cpu(MAX_CT_PAYLOAD_LEN);
1540 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
1541 ae->un.MaxCTPayloadLen = (65 * 4096);
1543 size += FOURBYTES + 4;
1545 ab->EntryCnt = be32_to_cpu(ab->EntryCnt);
1547 size = GID_REQUEST_SZ - 4 + size;
1554 struct serv_parm *hsp;
1559 CtReq->CommandResponse.bits.CmdRsp =
1560 be16_to_cpu(SLI_MGMT_RPA);
1561 CtReq->CommandResponse.bits.Size = 0;
1562 pab = (REG_PORT_ATTRIBUTE *) & CtReq->un.PortID;
1563 size = sizeof (struct lpfc_name) + FOURBYTES;
1564 memcpy((uint8_t *) & pab->PortName,
1565 (uint8_t *) & vport->fc_sparam.portName,
1566 sizeof (struct lpfc_name));
1567 pab->ab.EntryCnt = 0;
1569 /* #1 Port attribute entry */
1570 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
1571 ae->ad.bits.AttrType = be16_to_cpu(SUPPORTED_FC4_TYPES);
1572 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 32);
1573 ae->un.SupportFC4Types[2] = 1;
1574 ae->un.SupportFC4Types[7] = 1;
1576 size += FOURBYTES + 32;
1578 /* #2 Port attribute entry */
1579 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
1580 ae->ad.bits.AttrType = be16_to_cpu(SUPPORTED_SPEED);
1581 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
1583 ae->un.SupportSpeed = 0;
1584 if (phba->lmt & LMT_10Gb)
1585 ae->un.SupportSpeed = HBA_PORTSPEED_10GBIT;
1586 if (phba->lmt & LMT_8Gb)
1587 ae->un.SupportSpeed |= HBA_PORTSPEED_8GBIT;
1588 if (phba->lmt & LMT_4Gb)
1589 ae->un.SupportSpeed |= HBA_PORTSPEED_4GBIT;
1590 if (phba->lmt & LMT_2Gb)
1591 ae->un.SupportSpeed |= HBA_PORTSPEED_2GBIT;
1592 if (phba->lmt & LMT_1Gb)
1593 ae->un.SupportSpeed |= HBA_PORTSPEED_1GBIT;
1596 size += FOURBYTES + 4;
1598 /* #3 Port attribute entry */
1599 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
1600 ae->ad.bits.AttrType = be16_to_cpu(PORT_SPEED);
1601 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
1602 switch(phba->fc_linkspeed) {
1604 ae->un.PortSpeed = HBA_PORTSPEED_1GBIT;
1607 ae->un.PortSpeed = HBA_PORTSPEED_2GBIT;
1610 ae->un.PortSpeed = HBA_PORTSPEED_4GBIT;
1613 ae->un.PortSpeed = HBA_PORTSPEED_8GBIT;
1616 ae->un.PortSpeed = HBA_PORTSPEED_10GBIT;
1620 HBA_PORTSPEED_UNKNOWN;
1624 size += FOURBYTES + 4;
1626 /* #4 Port attribute entry */
1627 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
1628 ae->ad.bits.AttrType = be16_to_cpu(MAX_FRAME_SIZE);
1629 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
1630 hsp = (struct serv_parm *) & vport->fc_sparam;
1631 ae->un.MaxFrameSize =
1632 (((uint32_t) hsp->cmn.
1633 bbRcvSizeMsb) << 8) | (uint32_t) hsp->cmn.
1636 size += FOURBYTES + 4;
1638 /* #5 Port attribute entry */
1639 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
1640 ae->ad.bits.AttrType = be16_to_cpu(OS_DEVICE_NAME);
1641 strcpy((char *)ae->un.OsDeviceName, LPFC_DRIVER_NAME);
1642 len = strlen((char *)ae->un.OsDeviceName);
1643 len += (len & 3) ? (4 - (len & 3)) : 4;
1644 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1646 size += FOURBYTES + len;
1648 if (vport->cfg_fdmi_on == 2) {
1649 /* #6 Port attribute entry */
1650 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab +
1652 ae->ad.bits.AttrType = be16_to_cpu(HOST_NAME);
1653 sprintf(ae->un.HostName, "%s",
1654 init_utsname()->nodename);
1655 len = strlen(ae->un.HostName);
1656 len += (len & 3) ? (4 - (len & 3)) : 4;
1657 ae->ad.bits.AttrLen =
1658 be16_to_cpu(FOURBYTES + len);
1660 size += FOURBYTES + len;
1663 pab->ab.EntryCnt = be32_to_cpu(pab->ab.EntryCnt);
1665 size = GID_REQUEST_SZ - 4 + size;
1670 CtReq->CommandResponse.bits.CmdRsp = be16_to_cpu(SLI_MGMT_DHBA);
1671 CtReq->CommandResponse.bits.Size = 0;
1672 pe = (PORT_ENTRY *) & CtReq->un.PortID;
1673 memcpy((uint8_t *) & pe->PortName,
1674 (uint8_t *) & vport->fc_sparam.portName,
1675 sizeof (struct lpfc_name));
1676 size = GID_REQUEST_SZ - 4 + sizeof (struct lpfc_name);
1680 CtReq->CommandResponse.bits.CmdRsp = be16_to_cpu(SLI_MGMT_DPRT);
1681 CtReq->CommandResponse.bits.Size = 0;
1682 pe = (PORT_ENTRY *) & CtReq->un.PortID;
1683 memcpy((uint8_t *) & pe->PortName,
1684 (uint8_t *) & vport->fc_sparam.portName,
1685 sizeof (struct lpfc_name));
1686 size = GID_REQUEST_SZ - 4 + sizeof (struct lpfc_name);
1690 bpl = (struct ulp_bde64 *) bmp->virt;
1691 bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys) );
1692 bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys) );
1693 bpl->tus.f.bdeFlags = 0;
1694 bpl->tus.f.bdeSize = size;
1695 bpl->tus.w = le32_to_cpu(bpl->tus.w);
1697 cmpl = lpfc_cmpl_ct_cmd_fdmi;
1699 /* The lpfc_ct_cmd/lpfc_get_req shall increment ndlp reference count
1700 * to hold ndlp reference for the corresponding callback function.
1702 if (!lpfc_ct_cmd(vport, mp, bmp, ndlp, cmpl, FC_MAX_NS_RSP, 0))
1705 /* Decrement ndlp reference count to release ndlp reference held
1706 * for the failed command's callback function.
1710 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
1713 fdmi_cmd_free_mpvirt:
1714 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1718 /* Issue FDMI request failed */
1719 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1720 "0244 Issue FDMI request failed Data: x%x\n",
1726 lpfc_fdmi_tmo(unsigned long ptr)
1728 struct lpfc_vport *vport = (struct lpfc_vport *)ptr;
1729 struct lpfc_hba *phba = vport->phba;
1730 uint32_t tmo_posted;
1731 unsigned long iflag;
1733 spin_lock_irqsave(&vport->work_port_lock, iflag);
1734 tmo_posted = vport->work_port_events & WORKER_FDMI_TMO;
1736 vport->work_port_events |= WORKER_FDMI_TMO;
1737 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
1740 lpfc_worker_wake_up(phba);
1745 lpfc_fdmi_timeout_handler(struct lpfc_vport *vport)
1747 struct lpfc_nodelist *ndlp;
1749 ndlp = lpfc_findnode_did(vport, FDMI_DID);
1750 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
1751 if (init_utsname()->nodename[0] != '\0')
1752 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA);
1754 mod_timer(&vport->fc_fdmitmo, jiffies + HZ * 60);
1760 lpfc_decode_firmware_rev(struct lpfc_hba *phba, char *fwrevision, int flag)
1762 struct lpfc_sli *psli = &phba->sli;
1763 lpfc_vpd_t *vp = &phba->vpd;
1764 uint32_t b1, b2, b3, b4, i, rev;
1766 uint32_t *ptr, str[4];
1769 if (phba->sli_rev == LPFC_SLI_REV4)
1770 sprintf(fwrevision, "%s", vp->rev.opFwName);
1771 else if (vp->rev.rBit) {
1772 if (psli->sli_flag & LPFC_SLI_ACTIVE)
1773 rev = vp->rev.sli2FwRev;
1775 rev = vp->rev.sli1FwRev;
1777 b1 = (rev & 0x0000f000) >> 12;
1778 b2 = (rev & 0x00000f00) >> 8;
1779 b3 = (rev & 0x000000c0) >> 6;
1780 b4 = (rev & 0x00000030) >> 4;
1796 b4 = (rev & 0x0000000f);
1798 if (psli->sli_flag & LPFC_SLI_ACTIVE)
1799 fwname = vp->rev.sli2FwName;
1801 fwname = vp->rev.sli1FwName;
1803 for (i = 0; i < 16; i++)
1804 if (fwname[i] == 0x20)
1807 ptr = (uint32_t*)fwname;
1809 for (i = 0; i < 3; i++)
1810 str[i] = be32_to_cpu(*ptr++);
1814 sprintf(fwrevision, "%d.%d%d (%s)",
1815 b1, b2, b3, (char *)str);
1817 sprintf(fwrevision, "%d.%d%d", b1,
1821 sprintf(fwrevision, "%d.%d%d%c%d (%s)",
1825 sprintf(fwrevision, "%d.%d%d%c%d",
1829 rev = vp->rev.smFwRev;
1831 b1 = (rev & 0xff000000) >> 24;
1832 b2 = (rev & 0x00f00000) >> 20;
1833 b3 = (rev & 0x000f0000) >> 16;
1834 c = (rev & 0x0000ff00) >> 8;
1835 b4 = (rev & 0x000000ff);
1838 sprintf(fwrevision, "%d.%d%d%c%d ", b1,
1841 sprintf(fwrevision, "%d.%d%d%c%d ", b1,