1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2004-2010 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 if (lpfc_bsg_ct_unsol_event(phba, pring, piocbq) == 0)
103 if (unlikely(icmd->ulpStatus == IOSTAT_NEED_BUFFER)) {
104 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
105 } else if ((icmd->ulpStatus == IOSTAT_LOCAL_REJECT) &&
106 ((icmd->un.ulpWord[4] & 0xff) == IOERR_RCV_BUFFER_WAITING)) {
107 /* Not enough posted buffers; Try posting more buffers */
108 phba->fc_stat.NoRcvBuf++;
109 if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
110 lpfc_post_buffer(phba, pring, 2);
114 /* If there are no BDEs associated with this IOCB,
115 * there is nothing to do.
117 if (icmd->ulpBdeCount == 0)
120 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
121 INIT_LIST_HEAD(&head);
122 list_add_tail(&head, &piocbq->list);
123 list_for_each_entry(iocbq, &head, list) {
125 if (icmd->ulpBdeCount == 0)
127 bdeBuf = iocbq->context2;
128 iocbq->context2 = NULL;
129 size = icmd->un.cont64[0].tus.f.bdeSize;
130 lpfc_ct_unsol_buffer(phba, piocbq, bdeBuf, size);
131 lpfc_in_buf_free(phba, bdeBuf);
132 if (icmd->ulpBdeCount == 2) {
133 bdeBuf = iocbq->context3;
134 iocbq->context3 = NULL;
135 size = icmd->unsli3.rcvsli3.bde2.tus.f.bdeSize;
136 lpfc_ct_unsol_buffer(phba, piocbq, bdeBuf,
138 lpfc_in_buf_free(phba, bdeBuf);
143 INIT_LIST_HEAD(&head);
144 list_add_tail(&head, &piocbq->list);
145 list_for_each_entry(iocbq, &head, list) {
147 if (icmd->ulpBdeCount == 0)
148 lpfc_ct_unsol_buffer(phba, iocbq, NULL, 0);
149 for (i = 0; i < icmd->ulpBdeCount; i++) {
150 paddr = getPaddr(icmd->un.cont64[i].addrHigh,
151 icmd->un.cont64[i].addrLow);
152 mp = lpfc_sli_ringpostbuf_get(phba, pring,
154 size = icmd->un.cont64[i].tus.f.bdeSize;
155 lpfc_ct_unsol_buffer(phba, iocbq, mp, size);
156 lpfc_in_buf_free(phba, mp);
158 lpfc_post_buffer(phba, pring, i);
165 * lpfc_sli4_ct_abort_unsol_event - Default handle for sli4 unsol abort
166 * @phba: Pointer to HBA context object.
167 * @pring: Pointer to the driver internal I/O ring.
168 * @piocbq: Pointer to the IOCBQ.
170 * This function serves as the default handler for the sli4 unsolicited
171 * abort event. It shall be invoked when there is no application interface
172 * registered unsolicited abort handler. This handler does nothing but
173 * just simply releases the dma buffer used by the unsol abort event.
176 lpfc_sli4_ct_abort_unsol_event(struct lpfc_hba *phba,
177 struct lpfc_sli_ring *pring,
178 struct lpfc_iocbq *piocbq)
180 IOCB_t *icmd = &piocbq->iocb;
181 struct lpfc_dmabuf *bdeBuf;
184 /* Forward abort event to any process registered to receive ct event */
185 if (lpfc_bsg_ct_unsol_event(phba, pring, piocbq) == 0)
188 /* If there is no BDE associated with IOCB, there is nothing to do */
189 if (icmd->ulpBdeCount == 0)
191 bdeBuf = piocbq->context2;
192 piocbq->context2 = NULL;
193 size = icmd->un.cont64[0].tus.f.bdeSize;
194 lpfc_ct_unsol_buffer(phba, piocbq, bdeBuf, size);
195 lpfc_in_buf_free(phba, bdeBuf);
199 lpfc_free_ct_rsp(struct lpfc_hba *phba, struct lpfc_dmabuf *mlist)
201 struct lpfc_dmabuf *mlast, *next_mlast;
203 list_for_each_entry_safe(mlast, next_mlast, &mlist->list, list) {
204 lpfc_mbuf_free(phba, mlast->virt, mlast->phys);
205 list_del(&mlast->list);
208 lpfc_mbuf_free(phba, mlist->virt, mlist->phys);
213 static struct lpfc_dmabuf *
214 lpfc_alloc_ct_rsp(struct lpfc_hba *phba, int cmdcode, struct ulp_bde64 *bpl,
215 uint32_t size, int *entries)
217 struct lpfc_dmabuf *mlist = NULL;
218 struct lpfc_dmabuf *mp;
221 /* We get chunks of FCELSSIZE */
222 cnt = size > FCELSSIZE ? FCELSSIZE: size;
225 /* Allocate buffer for rsp payload */
226 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
229 lpfc_free_ct_rsp(phba, mlist);
233 INIT_LIST_HEAD(&mp->list);
235 if (cmdcode == be16_to_cpu(SLI_CTNS_GID_FT) ||
236 cmdcode == be16_to_cpu(SLI_CTNS_GFF_ID))
237 mp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(mp->phys));
239 mp->virt = lpfc_mbuf_alloc(phba, 0, &(mp->phys));
244 lpfc_free_ct_rsp(phba, mlist);
248 /* Queue it to a linked list */
252 list_add_tail(&mp->list, &mlist->list);
254 bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64I;
255 /* build buffer ptr list for IOCB */
256 bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys) );
257 bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys) );
258 bpl->tus.f.bdeSize = (uint16_t) cnt;
259 bpl->tus.w = le32_to_cpu(bpl->tus.w);
271 lpfc_ct_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *ctiocb)
273 struct lpfc_dmabuf *buf_ptr;
275 if (ctiocb->context_un.ndlp) {
276 lpfc_nlp_put(ctiocb->context_un.ndlp);
277 ctiocb->context_un.ndlp = NULL;
279 if (ctiocb->context1) {
280 buf_ptr = (struct lpfc_dmabuf *) ctiocb->context1;
281 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
283 ctiocb->context1 = NULL;
285 if (ctiocb->context2) {
286 lpfc_free_ct_rsp(phba, (struct lpfc_dmabuf *) ctiocb->context2);
287 ctiocb->context2 = NULL;
290 if (ctiocb->context3) {
291 buf_ptr = (struct lpfc_dmabuf *) ctiocb->context3;
292 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
294 ctiocb->context1 = NULL;
296 lpfc_sli_release_iocbq(phba, ctiocb);
301 lpfc_gen_req(struct lpfc_vport *vport, struct lpfc_dmabuf *bmp,
302 struct lpfc_dmabuf *inp, struct lpfc_dmabuf *outp,
303 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
304 struct lpfc_iocbq *),
305 struct lpfc_nodelist *ndlp, uint32_t usr_flg, uint32_t num_entry,
306 uint32_t tmo, uint8_t retry)
308 struct lpfc_hba *phba = vport->phba;
310 struct lpfc_iocbq *geniocb;
313 /* Allocate buffer for command iocb */
314 geniocb = lpfc_sli_get_iocbq(phba);
319 icmd = &geniocb->iocb;
320 icmd->un.genreq64.bdl.ulpIoTag32 = 0;
321 icmd->un.genreq64.bdl.addrHigh = putPaddrHigh(bmp->phys);
322 icmd->un.genreq64.bdl.addrLow = putPaddrLow(bmp->phys);
323 icmd->un.genreq64.bdl.bdeFlags = BUFF_TYPE_BLP_64;
324 icmd->un.genreq64.bdl.bdeSize = (num_entry * sizeof (struct ulp_bde64));
327 geniocb->context3 = NULL;
329 geniocb->context3 = (uint8_t *) bmp;
331 /* Save for completion so we can release these resources */
332 geniocb->context1 = (uint8_t *) inp;
333 geniocb->context2 = (uint8_t *) outp;
334 geniocb->context_un.ndlp = lpfc_nlp_get(ndlp);
336 /* Fill in payload, bp points to frame payload */
337 icmd->ulpCommand = CMD_GEN_REQUEST64_CR;
339 /* Fill in rest of iocb */
340 icmd->un.genreq64.w5.hcsw.Fctl = (SI | LA);
341 icmd->un.genreq64.w5.hcsw.Dfctl = 0;
342 icmd->un.genreq64.w5.hcsw.Rctl = FC_RCTL_DD_UNSOL_CTL;
343 icmd->un.genreq64.w5.hcsw.Type = FC_TYPE_CT;
346 /* FC spec states we need 3 * ratov for CT requests */
347 tmo = (3 * phba->fc_ratov);
349 icmd->ulpTimeout = tmo;
350 icmd->ulpBdeCount = 1;
352 icmd->ulpClass = CLASS3;
353 icmd->ulpContext = ndlp->nlp_rpi;
355 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
356 /* For GEN_REQUEST64_CR, use the RPI */
361 /* Issue GEN REQ IOCB for NPORT <did> */
362 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
363 "0119 Issue GEN REQ IOCB to NPORT x%x "
365 ndlp->nlp_DID, icmd->ulpIoTag,
367 geniocb->iocb_cmpl = cmpl;
368 geniocb->drvrTimeout = icmd->ulpTimeout + LPFC_DRVR_TIMEOUT;
369 geniocb->vport = vport;
370 geniocb->retry = retry;
371 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, geniocb, 0);
373 if (rc == IOCB_ERROR) {
374 lpfc_sli_release_iocbq(phba, geniocb);
382 lpfc_ct_cmd(struct lpfc_vport *vport, struct lpfc_dmabuf *inmp,
383 struct lpfc_dmabuf *bmp, struct lpfc_nodelist *ndlp,
384 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
385 struct lpfc_iocbq *),
386 uint32_t rsp_size, uint8_t retry)
388 struct lpfc_hba *phba = vport->phba;
389 struct ulp_bde64 *bpl = (struct ulp_bde64 *) bmp->virt;
390 struct lpfc_dmabuf *outmp;
392 int cmdcode = ((struct lpfc_sli_ct_request *) inmp->virt)->
393 CommandResponse.bits.CmdRsp;
395 bpl++; /* Skip past ct request */
397 /* Put buffer(s) for ct rsp in bpl */
398 outmp = lpfc_alloc_ct_rsp(phba, cmdcode, bpl, rsp_size, &cnt);
402 * Form the CT IOCB. The total number of BDEs in this IOCB
403 * is the single command plus response count from
407 status = lpfc_gen_req(vport, bmp, inmp, outmp, cmpl, ndlp, 0,
410 lpfc_free_ct_rsp(phba, outmp);
417 lpfc_find_vport_by_did(struct lpfc_hba *phba, uint32_t did) {
418 struct lpfc_vport *vport_curr;
421 spin_lock_irqsave(&phba->hbalock, flags);
422 list_for_each_entry(vport_curr, &phba->port_list, listentry) {
423 if ((vport_curr->fc_myDID) && (vport_curr->fc_myDID == did)) {
424 spin_unlock_irqrestore(&phba->hbalock, flags);
428 spin_unlock_irqrestore(&phba->hbalock, flags);
433 lpfc_ns_rsp(struct lpfc_vport *vport, struct lpfc_dmabuf *mp, uint32_t Size)
435 struct lpfc_hba *phba = vport->phba;
436 struct lpfc_sli_ct_request *Response =
437 (struct lpfc_sli_ct_request *) mp->virt;
438 struct lpfc_nodelist *ndlp = NULL;
439 struct lpfc_dmabuf *mlast, *next_mp;
440 uint32_t *ctptr = (uint32_t *) & Response->un.gid.PortType;
441 uint32_t Did, CTentry;
443 struct list_head head;
445 lpfc_set_disctmo(vport);
446 vport->num_disc_nodes = 0;
447 vport->fc_ns_retry = 0;
450 list_add_tail(&head, &mp->list);
451 list_for_each_entry_safe(mp, next_mp, &head, list) {
454 Cnt = Size > FCELSSIZE ? FCELSSIZE : Size;
459 ctptr = (uint32_t *) mlast->virt;
461 Cnt -= 16; /* subtract length of CT header */
463 /* Loop through entire NameServer list of DIDs */
464 while (Cnt >= sizeof (uint32_t)) {
465 /* Get next DID from NameServer List */
467 Did = ((be32_to_cpu(CTentry)) & Mask_DID);
472 * Check for rscn processing or not
473 * To conserve rpi's, filter out addresses for other
474 * vports on the same physical HBAs.
476 if ((Did != vport->fc_myDID) &&
477 ((lpfc_find_vport_by_did(phba, Did) == NULL) ||
478 vport->cfg_peer_port_login)) {
479 if ((vport->port_type != LPFC_NPIV_PORT) ||
480 (!(vport->ct_flags & FC_CT_RFF_ID)) ||
481 (!vport->cfg_restrict_login)) {
482 ndlp = lpfc_setup_disc_node(vport, Did);
483 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
484 lpfc_debugfs_disc_trc(vport,
487 "did:x%x flg:x%x x%x",
491 lpfc_printf_vlog(vport,
496 "Data: x%x x%x x%x\n",
499 vport->fc_rscn_id_cnt);
501 lpfc_debugfs_disc_trc(vport,
504 "did:x%x flg:x%x cnt:%d",
506 vport->fc_rscn_id_cnt);
508 lpfc_printf_vlog(vport,
512 "NameServer Rsp Data: "
515 vport->fc_rscn_id_cnt);
519 if (!(vport->fc_flag & FC_RSCN_MODE) ||
520 (lpfc_rscn_payload_check(vport, Did))) {
521 lpfc_debugfs_disc_trc(vport,
524 "did:x%x flg:x%x cnt:%d",
526 vport->fc_rscn_id_cnt);
528 /* This NPortID was previously
529 * a FCP target, * Don't even
530 * bother to send GFF_ID.
532 ndlp = lpfc_findnode_did(vport,
535 NLP_CHK_NODE_ACT(ndlp)
540 else if (lpfc_ns_cmd(vport,
543 vport->num_disc_nodes++;
549 lpfc_debugfs_disc_trc(vport,
552 "did:x%x flg:x%x cnt:%d",
554 vport->fc_rscn_id_cnt);
556 lpfc_printf_vlog(vport,
560 "NameServer Rsp Data: "
563 vport->fc_rscn_id_cnt);
567 if (CTentry & (be32_to_cpu(SLI_CT_LAST_ENTRY)))
569 Cnt -= sizeof (uint32_t);
581 lpfc_cmpl_ct_cmd_gid_ft(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
582 struct lpfc_iocbq *rspiocb)
584 struct lpfc_vport *vport = cmdiocb->vport;
585 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
587 struct lpfc_dmabuf *bmp;
588 struct lpfc_dmabuf *outp;
589 struct lpfc_sli_ct_request *CTrsp;
590 struct lpfc_nodelist *ndlp;
593 /* First save ndlp, before we overwrite it */
594 ndlp = cmdiocb->context_un.ndlp;
596 /* we pass cmdiocb to state machine which needs rspiocb as well */
597 cmdiocb->context_un.rsp_iocb = rspiocb;
599 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
600 bmp = (struct lpfc_dmabuf *) cmdiocb->context3;
601 irsp = &rspiocb->iocb;
603 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
604 "GID_FT cmpl: status:x%x/x%x rtry:%d",
605 irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_ns_retry);
607 /* Don't bother processing response if vport is being torn down. */
608 if (vport->load_flag & FC_UNLOADING) {
609 if (vport->fc_flag & FC_RSCN_MODE)
610 lpfc_els_flush_rscn(vport);
614 if (lpfc_els_chk_latt(vport)) {
615 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
616 "0216 Link event during NS query\n");
617 if (vport->fc_flag & FC_RSCN_MODE)
618 lpfc_els_flush_rscn(vport);
619 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
622 if (lpfc_error_lost_link(irsp)) {
623 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
624 "0226 NS query failed due to link event\n");
625 if (vport->fc_flag & FC_RSCN_MODE)
626 lpfc_els_flush_rscn(vport);
629 if (irsp->ulpStatus) {
630 /* Check for retry */
631 if (vport->fc_ns_retry < LPFC_MAX_NS_RETRY) {
632 if (irsp->ulpStatus != IOSTAT_LOCAL_REJECT ||
633 irsp->un.ulpWord[4] != IOERR_NO_RESOURCES)
634 vport->fc_ns_retry++;
636 /* CT command is being retried */
637 rc = lpfc_ns_cmd(vport, SLI_CTNS_GID_FT,
638 vport->fc_ns_retry, 0);
642 if (vport->fc_flag & FC_RSCN_MODE)
643 lpfc_els_flush_rscn(vport);
644 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
645 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
646 "0257 GID_FT Query error: 0x%x 0x%x\n",
647 irsp->ulpStatus, vport->fc_ns_retry);
649 /* Good status, continue checking */
650 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
651 if (CTrsp->CommandResponse.bits.CmdRsp ==
652 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC)) {
653 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
654 "0208 NameServer Rsp Data: x%x\n",
656 lpfc_ns_rsp(vport, outp,
657 (uint32_t) (irsp->un.genreq64.bdl.bdeSize));
658 } else if (CTrsp->CommandResponse.bits.CmdRsp ==
659 be16_to_cpu(SLI_CT_RESPONSE_FS_RJT)) {
660 /* NameServer Rsp Error */
661 if ((CTrsp->ReasonCode == SLI_CT_UNABLE_TO_PERFORM_REQ)
662 && (CTrsp->Explanation == SLI_CT_NO_FC4_TYPES)) {
663 lpfc_printf_vlog(vport, KERN_INFO,
665 "0269 No NameServer Entries "
666 "Data: x%x x%x x%x x%x\n",
667 CTrsp->CommandResponse.bits.CmdRsp,
668 (uint32_t) CTrsp->ReasonCode,
669 (uint32_t) CTrsp->Explanation,
672 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
673 "GID_FT no entry cmd:x%x rsn:x%x exp:x%x",
674 (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
675 (uint32_t) CTrsp->ReasonCode,
676 (uint32_t) CTrsp->Explanation);
678 lpfc_printf_vlog(vport, KERN_INFO,
680 "0240 NameServer Rsp Error "
681 "Data: x%x x%x x%x x%x\n",
682 CTrsp->CommandResponse.bits.CmdRsp,
683 (uint32_t) CTrsp->ReasonCode,
684 (uint32_t) CTrsp->Explanation,
687 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
688 "GID_FT rsp err1 cmd:x%x rsn:x%x exp:x%x",
689 (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
690 (uint32_t) CTrsp->ReasonCode,
691 (uint32_t) CTrsp->Explanation);
696 /* NameServer Rsp Error */
697 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
698 "0241 NameServer Rsp Error "
699 "Data: x%x x%x x%x x%x\n",
700 CTrsp->CommandResponse.bits.CmdRsp,
701 (uint32_t) CTrsp->ReasonCode,
702 (uint32_t) CTrsp->Explanation,
705 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
706 "GID_FT rsp err2 cmd:x%x rsn:x%x exp:x%x",
707 (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
708 (uint32_t) CTrsp->ReasonCode,
709 (uint32_t) CTrsp->Explanation);
712 /* Link up / RSCN discovery */
713 if (vport->num_disc_nodes == 0) {
715 * The driver has cycled through all Nports in the RSCN payload.
716 * Complete the handling by cleaning up and marking the
717 * current driver state.
719 if (vport->port_state >= LPFC_DISC_AUTH) {
720 if (vport->fc_flag & FC_RSCN_MODE) {
721 lpfc_els_flush_rscn(vport);
722 spin_lock_irq(shost->host_lock);
723 vport->fc_flag |= FC_RSCN_MODE; /* RSCN still */
724 spin_unlock_irq(shost->host_lock);
727 lpfc_els_flush_rscn(vport);
730 lpfc_disc_start(vport);
733 cmdiocb->context_un.ndlp = ndlp; /* Now restore ndlp for free */
734 lpfc_ct_free_iocb(phba, cmdiocb);
739 lpfc_cmpl_ct_cmd_gff_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
740 struct lpfc_iocbq *rspiocb)
742 struct lpfc_vport *vport = cmdiocb->vport;
743 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
744 IOCB_t *irsp = &rspiocb->iocb;
745 struct lpfc_dmabuf *inp = (struct lpfc_dmabuf *) cmdiocb->context1;
746 struct lpfc_dmabuf *outp = (struct lpfc_dmabuf *) cmdiocb->context2;
747 struct lpfc_sli_ct_request *CTrsp;
750 struct lpfc_nodelist *ndlp;
752 did = ((struct lpfc_sli_ct_request *) inp->virt)->un.gff.PortId;
753 did = be32_to_cpu(did);
755 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
756 "GFF_ID cmpl: status:x%x/x%x did:x%x",
757 irsp->ulpStatus, irsp->un.ulpWord[4], did);
759 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
760 /* Good status, continue checking */
761 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
762 fbits = CTrsp->un.gff_acc.fbits[FCP_TYPE_FEATURE_OFFSET];
764 if (CTrsp->CommandResponse.bits.CmdRsp ==
765 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC)) {
766 if ((fbits & FC4_FEATURE_INIT) &&
767 !(fbits & FC4_FEATURE_TARGET)) {
768 lpfc_printf_vlog(vport, KERN_INFO,
771 "NameServer Rsp Data: (init) "
772 "x%x x%x\n", did, fbits,
773 vport->fc_rscn_id_cnt);
779 /* Check for retry */
780 if (cmdiocb->retry < LPFC_MAX_NS_RETRY) {
782 if (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) {
783 switch (irsp->un.ulpWord[4]) {
784 case IOERR_NO_RESOURCES:
785 /* We don't increment the retry
786 * count for this case.
789 case IOERR_LINK_DOWN:
790 case IOERR_SLI_ABORTED:
802 /* CT command is being retried */
803 rc = lpfc_ns_cmd(vport, SLI_CTNS_GFF_ID,
804 cmdiocb->retry, did);
807 lpfc_ct_free_iocb(phba, cmdiocb);
812 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
813 "0267 NameServer GFF Rsp "
814 "x%x Error (%d %d) Data: x%x x%x\n",
815 did, irsp->ulpStatus, irsp->un.ulpWord[4],
816 vport->fc_flag, vport->fc_rscn_id_cnt);
819 /* This is a target port, unregistered port, or the GFF_ID failed */
820 ndlp = lpfc_setup_disc_node(vport, did);
821 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
822 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
823 "0242 Process x%x GFF "
824 "NameServer Rsp Data: x%x x%x x%x\n",
825 did, ndlp->nlp_flag, vport->fc_flag,
826 vport->fc_rscn_id_cnt);
828 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
830 "NameServer Rsp Data: x%x x%x\n", did,
831 vport->fc_flag, vport->fc_rscn_id_cnt);
834 /* Link up / RSCN discovery */
835 if (vport->num_disc_nodes)
836 vport->num_disc_nodes--;
837 if (vport->num_disc_nodes == 0) {
839 * The driver has cycled through all Nports in the RSCN payload.
840 * Complete the handling by cleaning up and marking the
841 * current driver state.
843 if (vport->port_state >= LPFC_DISC_AUTH) {
844 if (vport->fc_flag & FC_RSCN_MODE) {
845 lpfc_els_flush_rscn(vport);
846 spin_lock_irq(shost->host_lock);
847 vport->fc_flag |= FC_RSCN_MODE; /* RSCN still */
848 spin_unlock_irq(shost->host_lock);
851 lpfc_els_flush_rscn(vport);
853 lpfc_disc_start(vport);
855 lpfc_ct_free_iocb(phba, cmdiocb);
861 lpfc_cmpl_ct(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
862 struct lpfc_iocbq *rspiocb)
864 struct lpfc_vport *vport = cmdiocb->vport;
865 struct lpfc_dmabuf *inp;
866 struct lpfc_dmabuf *outp;
868 struct lpfc_sli_ct_request *CTrsp;
869 struct lpfc_nodelist *ndlp;
874 /* First save ndlp, before we overwrite it */
875 ndlp = cmdiocb->context_un.ndlp;
877 /* we pass cmdiocb to state machine which needs rspiocb as well */
878 cmdiocb->context_un.rsp_iocb = rspiocb;
880 inp = (struct lpfc_dmabuf *) cmdiocb->context1;
881 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
882 irsp = &rspiocb->iocb;
884 cmdcode = be16_to_cpu(((struct lpfc_sli_ct_request *) inp->virt)->
885 CommandResponse.bits.CmdRsp);
886 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
888 latt = lpfc_els_chk_latt(vport);
890 /* RFT request completes status <ulpStatus> CmdRsp <CmdRsp> */
891 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
892 "0209 CT Request completes, latt %d, "
893 "ulpStatus x%x CmdRsp x%x, Context x%x, Tag x%x\n",
894 latt, irsp->ulpStatus,
895 CTrsp->CommandResponse.bits.CmdRsp,
896 cmdiocb->iocb.ulpContext, cmdiocb->iocb.ulpIoTag);
898 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
899 "CT cmd cmpl: status:x%x/x%x cmd:x%x",
900 irsp->ulpStatus, irsp->un.ulpWord[4], cmdcode);
902 if (irsp->ulpStatus) {
903 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
904 "0268 NS cmd %x Error (%d %d)\n",
905 cmdcode, irsp->ulpStatus, irsp->un.ulpWord[4]);
907 if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
908 ((irsp->un.ulpWord[4] == IOERR_SLI_DOWN) ||
909 (irsp->un.ulpWord[4] == IOERR_SLI_ABORTED)))
912 retry = cmdiocb->retry;
913 if (retry >= LPFC_MAX_NS_RETRY)
917 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
918 "0250 Retrying NS cmd %x\n", cmdcode);
919 rc = lpfc_ns_cmd(vport, cmdcode, retry, 0);
925 cmdiocb->context_un.ndlp = ndlp; /* Now restore ndlp for free */
926 lpfc_ct_free_iocb(phba, cmdiocb);
931 lpfc_cmpl_ct_cmd_rft_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
932 struct lpfc_iocbq *rspiocb)
934 IOCB_t *irsp = &rspiocb->iocb;
935 struct lpfc_vport *vport = cmdiocb->vport;
937 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
938 struct lpfc_dmabuf *outp;
939 struct lpfc_sli_ct_request *CTrsp;
941 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
942 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
943 if (CTrsp->CommandResponse.bits.CmdRsp ==
944 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
945 vport->ct_flags |= FC_CT_RFT_ID;
947 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
952 lpfc_cmpl_ct_cmd_rnn_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
953 struct lpfc_iocbq *rspiocb)
955 IOCB_t *irsp = &rspiocb->iocb;
956 struct lpfc_vport *vport = cmdiocb->vport;
958 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
959 struct lpfc_dmabuf *outp;
960 struct lpfc_sli_ct_request *CTrsp;
962 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
963 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
964 if (CTrsp->CommandResponse.bits.CmdRsp ==
965 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
966 vport->ct_flags |= FC_CT_RNN_ID;
968 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
973 lpfc_cmpl_ct_cmd_rspn_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
974 struct lpfc_iocbq *rspiocb)
976 IOCB_t *irsp = &rspiocb->iocb;
977 struct lpfc_vport *vport = cmdiocb->vport;
979 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
980 struct lpfc_dmabuf *outp;
981 struct lpfc_sli_ct_request *CTrsp;
983 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
984 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
985 if (CTrsp->CommandResponse.bits.CmdRsp ==
986 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
987 vport->ct_flags |= FC_CT_RSPN_ID;
989 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
994 lpfc_cmpl_ct_cmd_rsnn_nn(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
995 struct lpfc_iocbq *rspiocb)
997 IOCB_t *irsp = &rspiocb->iocb;
998 struct lpfc_vport *vport = cmdiocb->vport;
1000 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
1001 struct lpfc_dmabuf *outp;
1002 struct lpfc_sli_ct_request *CTrsp;
1004 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
1005 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
1006 if (CTrsp->CommandResponse.bits.CmdRsp ==
1007 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
1008 vport->ct_flags |= FC_CT_RSNN_NN;
1010 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
1015 lpfc_cmpl_ct_cmd_da_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1016 struct lpfc_iocbq *rspiocb)
1018 struct lpfc_vport *vport = cmdiocb->vport;
1020 /* even if it fails we will act as though it succeeded. */
1021 vport->ct_flags = 0;
1022 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
1027 lpfc_cmpl_ct_cmd_rff_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1028 struct lpfc_iocbq *rspiocb)
1030 IOCB_t *irsp = &rspiocb->iocb;
1031 struct lpfc_vport *vport = cmdiocb->vport;
1033 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
1034 struct lpfc_dmabuf *outp;
1035 struct lpfc_sli_ct_request *CTrsp;
1037 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
1038 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
1039 if (CTrsp->CommandResponse.bits.CmdRsp ==
1040 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
1041 vport->ct_flags |= FC_CT_RFF_ID;
1043 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
1048 lpfc_vport_symbolic_port_name(struct lpfc_vport *vport, char *symbol,
1052 uint8_t *wwn = vport->phba->wwpn;
1054 n = snprintf(symbol, size,
1055 "Emulex PPN-%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x",
1056 wwn[0], wwn[1], wwn[2], wwn[3],
1057 wwn[4], wwn[5], wwn[6], wwn[7]);
1059 if (vport->port_type == LPFC_PHYSICAL_PORT)
1063 n += snprintf(symbol + n, size - n, " VPort-%d", vport->vpi);
1066 strlen(vport->fc_vport->symbolic_name))
1067 n += snprintf(symbol + n, size - n, " VName-%s",
1068 vport->fc_vport->symbolic_name);
1073 lpfc_vport_symbolic_node_name(struct lpfc_vport *vport, char *symbol,
1079 lpfc_decode_firmware_rev(vport->phba, fwrev, 0);
1081 n = snprintf(symbol, size, "Emulex %s FV%s DV%s",
1082 vport->phba->ModelName, fwrev, lpfc_release_version);
1089 * Issue Cmd to NameServer
1094 lpfc_ns_cmd(struct lpfc_vport *vport, int cmdcode,
1095 uint8_t retry, uint32_t context)
1097 struct lpfc_nodelist * ndlp;
1098 struct lpfc_hba *phba = vport->phba;
1099 struct lpfc_dmabuf *mp, *bmp;
1100 struct lpfc_sli_ct_request *CtReq;
1101 struct ulp_bde64 *bpl;
1102 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
1103 struct lpfc_iocbq *) = NULL;
1104 uint32_t rsp_size = 1024;
1108 ndlp = lpfc_findnode_did(vport, NameServer_DID);
1109 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)
1110 || ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) {
1115 /* fill in BDEs for command */
1116 /* Allocate buffer for command payload */
1117 mp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
1123 INIT_LIST_HEAD(&mp->list);
1124 mp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(mp->phys));
1127 goto ns_cmd_free_mp;
1130 /* Allocate buffer for Buffer ptr list */
1131 bmp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
1134 goto ns_cmd_free_mpvirt;
1137 INIT_LIST_HEAD(&bmp->list);
1138 bmp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(bmp->phys));
1141 goto ns_cmd_free_bmp;
1144 /* NameServer Req */
1145 lpfc_printf_vlog(vport, KERN_INFO ,LOG_DISCOVERY,
1146 "0236 NameServer Req Data: x%x x%x x%x\n",
1147 cmdcode, vport->fc_flag, vport->fc_rscn_id_cnt);
1149 bpl = (struct ulp_bde64 *) bmp->virt;
1150 memset(bpl, 0, sizeof(struct ulp_bde64));
1151 bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys) );
1152 bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys) );
1153 bpl->tus.f.bdeFlags = 0;
1154 if (cmdcode == SLI_CTNS_GID_FT)
1155 bpl->tus.f.bdeSize = GID_REQUEST_SZ;
1156 else if (cmdcode == SLI_CTNS_GFF_ID)
1157 bpl->tus.f.bdeSize = GFF_REQUEST_SZ;
1158 else if (cmdcode == SLI_CTNS_RFT_ID)
1159 bpl->tus.f.bdeSize = RFT_REQUEST_SZ;
1160 else if (cmdcode == SLI_CTNS_RNN_ID)
1161 bpl->tus.f.bdeSize = RNN_REQUEST_SZ;
1162 else if (cmdcode == SLI_CTNS_RSPN_ID)
1163 bpl->tus.f.bdeSize = RSPN_REQUEST_SZ;
1164 else if (cmdcode == SLI_CTNS_RSNN_NN)
1165 bpl->tus.f.bdeSize = RSNN_REQUEST_SZ;
1166 else if (cmdcode == SLI_CTNS_DA_ID)
1167 bpl->tus.f.bdeSize = DA_ID_REQUEST_SZ;
1168 else if (cmdcode == SLI_CTNS_RFF_ID)
1169 bpl->tus.f.bdeSize = RFF_REQUEST_SZ;
1171 bpl->tus.f.bdeSize = 0;
1172 bpl->tus.w = le32_to_cpu(bpl->tus.w);
1174 CtReq = (struct lpfc_sli_ct_request *) mp->virt;
1175 memset(CtReq, 0, sizeof (struct lpfc_sli_ct_request));
1176 CtReq->RevisionId.bits.Revision = SLI_CT_REVISION;
1177 CtReq->RevisionId.bits.InId = 0;
1178 CtReq->FsType = SLI_CT_DIRECTORY_SERVICE;
1179 CtReq->FsSubType = SLI_CT_DIRECTORY_NAME_SERVER;
1180 CtReq->CommandResponse.bits.Size = 0;
1182 case SLI_CTNS_GID_FT:
1183 CtReq->CommandResponse.bits.CmdRsp =
1184 be16_to_cpu(SLI_CTNS_GID_FT);
1185 CtReq->un.gid.Fc4Type = SLI_CTPT_FCP;
1186 if (vport->port_state < LPFC_NS_QRY)
1187 vport->port_state = LPFC_NS_QRY;
1188 lpfc_set_disctmo(vport);
1189 cmpl = lpfc_cmpl_ct_cmd_gid_ft;
1190 rsp_size = FC_MAX_NS_RSP;
1193 case SLI_CTNS_GFF_ID:
1194 CtReq->CommandResponse.bits.CmdRsp =
1195 be16_to_cpu(SLI_CTNS_GFF_ID);
1196 CtReq->un.gff.PortId = cpu_to_be32(context);
1197 cmpl = lpfc_cmpl_ct_cmd_gff_id;
1200 case SLI_CTNS_RFT_ID:
1201 vport->ct_flags &= ~FC_CT_RFT_ID;
1202 CtReq->CommandResponse.bits.CmdRsp =
1203 be16_to_cpu(SLI_CTNS_RFT_ID);
1204 CtReq->un.rft.PortId = cpu_to_be32(vport->fc_myDID);
1205 CtReq->un.rft.fcpReg = 1;
1206 cmpl = lpfc_cmpl_ct_cmd_rft_id;
1209 case SLI_CTNS_RNN_ID:
1210 vport->ct_flags &= ~FC_CT_RNN_ID;
1211 CtReq->CommandResponse.bits.CmdRsp =
1212 be16_to_cpu(SLI_CTNS_RNN_ID);
1213 CtReq->un.rnn.PortId = cpu_to_be32(vport->fc_myDID);
1214 memcpy(CtReq->un.rnn.wwnn, &vport->fc_nodename,
1215 sizeof (struct lpfc_name));
1216 cmpl = lpfc_cmpl_ct_cmd_rnn_id;
1219 case SLI_CTNS_RSPN_ID:
1220 vport->ct_flags &= ~FC_CT_RSPN_ID;
1221 CtReq->CommandResponse.bits.CmdRsp =
1222 be16_to_cpu(SLI_CTNS_RSPN_ID);
1223 CtReq->un.rspn.PortId = cpu_to_be32(vport->fc_myDID);
1224 size = sizeof(CtReq->un.rspn.symbname);
1225 CtReq->un.rspn.len =
1226 lpfc_vport_symbolic_port_name(vport,
1227 CtReq->un.rspn.symbname, size);
1228 cmpl = lpfc_cmpl_ct_cmd_rspn_id;
1230 case SLI_CTNS_RSNN_NN:
1231 vport->ct_flags &= ~FC_CT_RSNN_NN;
1232 CtReq->CommandResponse.bits.CmdRsp =
1233 be16_to_cpu(SLI_CTNS_RSNN_NN);
1234 memcpy(CtReq->un.rsnn.wwnn, &vport->fc_nodename,
1235 sizeof (struct lpfc_name));
1236 size = sizeof(CtReq->un.rsnn.symbname);
1237 CtReq->un.rsnn.len =
1238 lpfc_vport_symbolic_node_name(vport,
1239 CtReq->un.rsnn.symbname, size);
1240 cmpl = lpfc_cmpl_ct_cmd_rsnn_nn;
1242 case SLI_CTNS_DA_ID:
1243 /* Implement DA_ID Nameserver request */
1244 CtReq->CommandResponse.bits.CmdRsp =
1245 be16_to_cpu(SLI_CTNS_DA_ID);
1246 CtReq->un.da_id.port_id = cpu_to_be32(vport->fc_myDID);
1247 cmpl = lpfc_cmpl_ct_cmd_da_id;
1249 case SLI_CTNS_RFF_ID:
1250 vport->ct_flags &= ~FC_CT_RFF_ID;
1251 CtReq->CommandResponse.bits.CmdRsp =
1252 be16_to_cpu(SLI_CTNS_RFF_ID);
1253 CtReq->un.rff.PortId = cpu_to_be32(vport->fc_myDID);
1254 CtReq->un.rff.fbits = FC4_FEATURE_INIT;
1255 CtReq->un.rff.type_code = FC_TYPE_FCP;
1256 cmpl = lpfc_cmpl_ct_cmd_rff_id;
1259 /* The lpfc_ct_cmd/lpfc_get_req shall increment ndlp reference count
1260 * to hold ndlp reference for the corresponding callback function.
1262 if (!lpfc_ct_cmd(vport, mp, bmp, ndlp, cmpl, rsp_size, retry)) {
1263 /* On success, The cmpl function will free the buffers */
1264 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
1265 "Issue CT cmd: cmd:x%x did:x%x",
1266 cmdcode, ndlp->nlp_DID, 0);
1271 /* Decrement ndlp reference count to release ndlp reference held
1272 * for the failed command's callback function.
1276 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
1280 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1284 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
1285 "0266 Issue NameServer Req x%x err %d Data: x%x x%x\n",
1286 cmdcode, rc, vport->fc_flag, vport->fc_rscn_id_cnt);
1291 lpfc_cmpl_ct_cmd_fdmi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1292 struct lpfc_iocbq * rspiocb)
1294 struct lpfc_dmabuf *inp = cmdiocb->context1;
1295 struct lpfc_dmabuf *outp = cmdiocb->context2;
1296 struct lpfc_sli_ct_request *CTrsp = outp->virt;
1297 struct lpfc_sli_ct_request *CTcmd = inp->virt;
1298 struct lpfc_nodelist *ndlp;
1299 uint16_t fdmi_cmd = CTcmd->CommandResponse.bits.CmdRsp;
1300 uint16_t fdmi_rsp = CTrsp->CommandResponse.bits.CmdRsp;
1301 struct lpfc_vport *vport = cmdiocb->vport;
1302 IOCB_t *irsp = &rspiocb->iocb;
1305 latt = lpfc_els_chk_latt(vport);
1307 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
1308 "FDMI cmpl: status:x%x/x%x latt:%d",
1309 irsp->ulpStatus, irsp->un.ulpWord[4], latt);
1311 if (latt || irsp->ulpStatus) {
1312 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1313 "0229 FDMI cmd %04x failed, latt = %d "
1314 "ulpStatus: x%x, rid x%x\n",
1315 be16_to_cpu(fdmi_cmd), latt, irsp->ulpStatus,
1316 irsp->un.ulpWord[4]);
1317 lpfc_ct_free_iocb(phba, cmdiocb);
1321 ndlp = lpfc_findnode_did(vport, FDMI_DID);
1322 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
1325 if (fdmi_rsp == be16_to_cpu(SLI_CT_RESPONSE_FS_RJT)) {
1326 /* FDMI rsp failed */
1327 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1328 "0220 FDMI rsp failed Data: x%x\n",
1329 be16_to_cpu(fdmi_cmd));
1332 switch (be16_to_cpu(fdmi_cmd)) {
1334 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RPA);
1341 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DPRT);
1345 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RHBA);
1350 lpfc_ct_free_iocb(phba, cmdiocb);
1355 lpfc_fdmi_cmd(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, int cmdcode)
1357 struct lpfc_hba *phba = vport->phba;
1358 struct lpfc_dmabuf *mp, *bmp;
1359 struct lpfc_sli_ct_request *CtReq;
1360 struct ulp_bde64 *bpl;
1364 REG_PORT_ATTRIBUTE *pab;
1365 ATTRIBUTE_BLOCK *ab;
1366 ATTRIBUTE_ENTRY *ae;
1367 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
1368 struct lpfc_iocbq *);
1371 /* fill in BDEs for command */
1372 /* Allocate buffer for command payload */
1373 mp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
1377 mp->virt = lpfc_mbuf_alloc(phba, 0, &(mp->phys));
1379 goto fdmi_cmd_free_mp;
1381 /* Allocate buffer for Buffer ptr list */
1382 bmp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
1384 goto fdmi_cmd_free_mpvirt;
1386 bmp->virt = lpfc_mbuf_alloc(phba, 0, &(bmp->phys));
1388 goto fdmi_cmd_free_bmp;
1390 INIT_LIST_HEAD(&mp->list);
1391 INIT_LIST_HEAD(&bmp->list);
1394 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1395 "0218 FDMI Request Data: x%x x%x x%x\n",
1396 vport->fc_flag, vport->port_state, cmdcode);
1397 CtReq = (struct lpfc_sli_ct_request *) mp->virt;
1399 memset(CtReq, 0, sizeof(struct lpfc_sli_ct_request));
1400 CtReq->RevisionId.bits.Revision = SLI_CT_REVISION;
1401 CtReq->RevisionId.bits.InId = 0;
1403 CtReq->FsType = SLI_CT_MANAGEMENT_SERVICE;
1404 CtReq->FsSubType = SLI_CT_FDMI_Subtypes;
1410 lpfc_vpd_t *vp = &phba->vpd;
1411 uint32_t i, j, incr;
1414 CtReq->CommandResponse.bits.CmdRsp =
1415 be16_to_cpu(SLI_MGMT_RHBA);
1416 CtReq->CommandResponse.bits.Size = 0;
1417 rh = (REG_HBA *) & CtReq->un.PortID;
1418 memcpy(&rh->hi.PortName, &vport->fc_sparam.portName,
1419 sizeof (struct lpfc_name));
1420 /* One entry (port) per adapter */
1421 rh->rpl.EntryCnt = be32_to_cpu(1);
1422 memcpy(&rh->rpl.pe, &vport->fc_sparam.portName,
1423 sizeof (struct lpfc_name));
1425 /* point to the HBA attribute block */
1426 size = 2 * sizeof (struct lpfc_name) + FOURBYTES;
1427 ab = (ATTRIBUTE_BLOCK *) ((uint8_t *) rh + size);
1430 /* Point to the beginning of the first HBA attribute
1432 /* #1 HBA attribute entry */
1434 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1435 ae->ad.bits.AttrType = be16_to_cpu(NODE_NAME);
1436 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES
1437 + sizeof (struct lpfc_name));
1438 memcpy(&ae->un.NodeName, &vport->fc_sparam.nodeName,
1439 sizeof (struct lpfc_name));
1441 size += FOURBYTES + sizeof (struct lpfc_name);
1443 /* #2 HBA attribute entry */
1444 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1445 ae->ad.bits.AttrType = be16_to_cpu(MANUFACTURER);
1446 strcpy(ae->un.Manufacturer, "Emulex Corporation");
1447 len = strlen(ae->un.Manufacturer);
1448 len += (len & 3) ? (4 - (len & 3)) : 4;
1449 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1451 size += FOURBYTES + len;
1453 /* #3 HBA attribute entry */
1454 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1455 ae->ad.bits.AttrType = be16_to_cpu(SERIAL_NUMBER);
1456 strcpy(ae->un.SerialNumber, phba->SerialNumber);
1457 len = strlen(ae->un.SerialNumber);
1458 len += (len & 3) ? (4 - (len & 3)) : 4;
1459 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1461 size += FOURBYTES + len;
1463 /* #4 HBA attribute entry */
1464 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1465 ae->ad.bits.AttrType = be16_to_cpu(MODEL);
1466 strcpy(ae->un.Model, phba->ModelName);
1467 len = strlen(ae->un.Model);
1468 len += (len & 3) ? (4 - (len & 3)) : 4;
1469 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1471 size += FOURBYTES + len;
1473 /* #5 HBA attribute entry */
1474 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1475 ae->ad.bits.AttrType = be16_to_cpu(MODEL_DESCRIPTION);
1476 strcpy(ae->un.ModelDescription, phba->ModelDesc);
1477 len = strlen(ae->un.ModelDescription);
1478 len += (len & 3) ? (4 - (len & 3)) : 4;
1479 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1481 size += FOURBYTES + len;
1483 /* #6 HBA attribute entry */
1484 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1485 ae->ad.bits.AttrType = be16_to_cpu(HARDWARE_VERSION);
1486 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 8);
1487 /* Convert JEDEC ID to ascii for hardware version */
1488 incr = vp->rev.biuRev;
1489 for (i = 0; i < 8; i++) {
1492 ae->un.HardwareVersion[7 - i] =
1493 (char)((uint8_t) 0x30 +
1496 ae->un.HardwareVersion[7 - i] =
1497 (char)((uint8_t) 0x61 +
1498 (uint8_t) (j - 10));
1502 size += FOURBYTES + 8;
1504 /* #7 HBA attribute entry */
1505 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1506 ae->ad.bits.AttrType = be16_to_cpu(DRIVER_VERSION);
1507 strcpy(ae->un.DriverVersion, lpfc_release_version);
1508 len = strlen(ae->un.DriverVersion);
1509 len += (len & 3) ? (4 - (len & 3)) : 4;
1510 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1512 size += FOURBYTES + len;
1514 /* #8 HBA attribute entry */
1515 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1516 ae->ad.bits.AttrType = be16_to_cpu(OPTION_ROM_VERSION);
1517 strcpy(ae->un.OptionROMVersion, phba->OptionROMVersion);
1518 len = strlen(ae->un.OptionROMVersion);
1519 len += (len & 3) ? (4 - (len & 3)) : 4;
1520 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1522 size += FOURBYTES + len;
1524 /* #9 HBA attribute entry */
1525 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1526 ae->ad.bits.AttrType = be16_to_cpu(FIRMWARE_VERSION);
1527 lpfc_decode_firmware_rev(phba, ae->un.FirmwareVersion,
1529 len = strlen(ae->un.FirmwareVersion);
1530 len += (len & 3) ? (4 - (len & 3)) : 4;
1531 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1533 size += FOURBYTES + len;
1535 /* #10 HBA attribute entry */
1536 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1537 ae->ad.bits.AttrType = be16_to_cpu(OS_NAME_VERSION);
1538 sprintf(ae->un.OsNameVersion, "%s %s %s",
1539 init_utsname()->sysname,
1540 init_utsname()->release,
1541 init_utsname()->version);
1542 len = strlen(ae->un.OsNameVersion);
1543 len += (len & 3) ? (4 - (len & 3)) : 4;
1544 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1546 size += FOURBYTES + len;
1548 /* #11 HBA attribute entry */
1549 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
1550 ae->ad.bits.AttrType = be16_to_cpu(MAX_CT_PAYLOAD_LEN);
1551 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
1552 ae->un.MaxCTPayloadLen = (65 * 4096);
1554 size += FOURBYTES + 4;
1556 ab->EntryCnt = be32_to_cpu(ab->EntryCnt);
1558 size = GID_REQUEST_SZ - 4 + size;
1565 struct serv_parm *hsp;
1570 CtReq->CommandResponse.bits.CmdRsp =
1571 be16_to_cpu(SLI_MGMT_RPA);
1572 CtReq->CommandResponse.bits.Size = 0;
1573 pab = (REG_PORT_ATTRIBUTE *) & CtReq->un.PortID;
1574 size = sizeof (struct lpfc_name) + FOURBYTES;
1575 memcpy((uint8_t *) & pab->PortName,
1576 (uint8_t *) & vport->fc_sparam.portName,
1577 sizeof (struct lpfc_name));
1578 pab->ab.EntryCnt = 0;
1580 /* #1 Port attribute entry */
1581 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
1582 ae->ad.bits.AttrType = be16_to_cpu(SUPPORTED_FC4_TYPES);
1583 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 32);
1584 ae->un.SupportFC4Types[2] = 1;
1585 ae->un.SupportFC4Types[7] = 1;
1587 size += FOURBYTES + 32;
1589 /* #2 Port attribute entry */
1590 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
1591 ae->ad.bits.AttrType = be16_to_cpu(SUPPORTED_SPEED);
1592 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
1594 ae->un.SupportSpeed = 0;
1595 if (phba->lmt & LMT_10Gb)
1596 ae->un.SupportSpeed = HBA_PORTSPEED_10GBIT;
1597 if (phba->lmt & LMT_8Gb)
1598 ae->un.SupportSpeed |= HBA_PORTSPEED_8GBIT;
1599 if (phba->lmt & LMT_4Gb)
1600 ae->un.SupportSpeed |= HBA_PORTSPEED_4GBIT;
1601 if (phba->lmt & LMT_2Gb)
1602 ae->un.SupportSpeed |= HBA_PORTSPEED_2GBIT;
1603 if (phba->lmt & LMT_1Gb)
1604 ae->un.SupportSpeed |= HBA_PORTSPEED_1GBIT;
1607 size += FOURBYTES + 4;
1609 /* #3 Port attribute entry */
1610 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
1611 ae->ad.bits.AttrType = be16_to_cpu(PORT_SPEED);
1612 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
1613 switch(phba->fc_linkspeed) {
1615 ae->un.PortSpeed = HBA_PORTSPEED_1GBIT;
1618 ae->un.PortSpeed = HBA_PORTSPEED_2GBIT;
1621 ae->un.PortSpeed = HBA_PORTSPEED_4GBIT;
1624 ae->un.PortSpeed = HBA_PORTSPEED_8GBIT;
1627 ae->un.PortSpeed = HBA_PORTSPEED_10GBIT;
1631 HBA_PORTSPEED_UNKNOWN;
1635 size += FOURBYTES + 4;
1637 /* #4 Port attribute entry */
1638 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
1639 ae->ad.bits.AttrType = be16_to_cpu(MAX_FRAME_SIZE);
1640 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
1641 hsp = (struct serv_parm *) & vport->fc_sparam;
1642 ae->un.MaxFrameSize =
1643 (((uint32_t) hsp->cmn.
1644 bbRcvSizeMsb) << 8) | (uint32_t) hsp->cmn.
1647 size += FOURBYTES + 4;
1649 /* #5 Port attribute entry */
1650 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
1651 ae->ad.bits.AttrType = be16_to_cpu(OS_DEVICE_NAME);
1652 strcpy((char *)ae->un.OsDeviceName, LPFC_DRIVER_NAME);
1653 len = strlen((char *)ae->un.OsDeviceName);
1654 len += (len & 3) ? (4 - (len & 3)) : 4;
1655 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1657 size += FOURBYTES + len;
1659 if (vport->cfg_fdmi_on == 2) {
1660 /* #6 Port attribute entry */
1661 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab +
1663 ae->ad.bits.AttrType = be16_to_cpu(HOST_NAME);
1664 sprintf(ae->un.HostName, "%s",
1665 init_utsname()->nodename);
1666 len = strlen(ae->un.HostName);
1667 len += (len & 3) ? (4 - (len & 3)) : 4;
1668 ae->ad.bits.AttrLen =
1669 be16_to_cpu(FOURBYTES + len);
1671 size += FOURBYTES + len;
1674 pab->ab.EntryCnt = be32_to_cpu(pab->ab.EntryCnt);
1676 size = GID_REQUEST_SZ - 4 + size;
1681 CtReq->CommandResponse.bits.CmdRsp = be16_to_cpu(SLI_MGMT_DHBA);
1682 CtReq->CommandResponse.bits.Size = 0;
1683 pe = (PORT_ENTRY *) & CtReq->un.PortID;
1684 memcpy((uint8_t *) & pe->PortName,
1685 (uint8_t *) & vport->fc_sparam.portName,
1686 sizeof (struct lpfc_name));
1687 size = GID_REQUEST_SZ - 4 + sizeof (struct lpfc_name);
1691 CtReq->CommandResponse.bits.CmdRsp = be16_to_cpu(SLI_MGMT_DPRT);
1692 CtReq->CommandResponse.bits.Size = 0;
1693 pe = (PORT_ENTRY *) & CtReq->un.PortID;
1694 memcpy((uint8_t *) & pe->PortName,
1695 (uint8_t *) & vport->fc_sparam.portName,
1696 sizeof (struct lpfc_name));
1697 size = GID_REQUEST_SZ - 4 + sizeof (struct lpfc_name);
1701 bpl = (struct ulp_bde64 *) bmp->virt;
1702 bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys) );
1703 bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys) );
1704 bpl->tus.f.bdeFlags = 0;
1705 bpl->tus.f.bdeSize = size;
1706 bpl->tus.w = le32_to_cpu(bpl->tus.w);
1708 cmpl = lpfc_cmpl_ct_cmd_fdmi;
1710 /* The lpfc_ct_cmd/lpfc_get_req shall increment ndlp reference count
1711 * to hold ndlp reference for the corresponding callback function.
1713 if (!lpfc_ct_cmd(vport, mp, bmp, ndlp, cmpl, FC_MAX_NS_RSP, 0))
1716 /* Decrement ndlp reference count to release ndlp reference held
1717 * for the failed command's callback function.
1721 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
1724 fdmi_cmd_free_mpvirt:
1725 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1729 /* Issue FDMI request failed */
1730 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1731 "0244 Issue FDMI request failed Data: x%x\n",
1737 lpfc_fdmi_tmo(unsigned long ptr)
1739 struct lpfc_vport *vport = (struct lpfc_vport *)ptr;
1740 struct lpfc_hba *phba = vport->phba;
1741 uint32_t tmo_posted;
1742 unsigned long iflag;
1744 spin_lock_irqsave(&vport->work_port_lock, iflag);
1745 tmo_posted = vport->work_port_events & WORKER_FDMI_TMO;
1747 vport->work_port_events |= WORKER_FDMI_TMO;
1748 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
1751 lpfc_worker_wake_up(phba);
1756 lpfc_fdmi_timeout_handler(struct lpfc_vport *vport)
1758 struct lpfc_nodelist *ndlp;
1760 ndlp = lpfc_findnode_did(vport, FDMI_DID);
1761 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
1762 if (init_utsname()->nodename[0] != '\0')
1763 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA);
1765 mod_timer(&vport->fc_fdmitmo, jiffies + HZ * 60);
1771 lpfc_decode_firmware_rev(struct lpfc_hba *phba, char *fwrevision, int flag)
1773 struct lpfc_sli *psli = &phba->sli;
1774 lpfc_vpd_t *vp = &phba->vpd;
1775 uint32_t b1, b2, b3, b4, i, rev;
1777 uint32_t *ptr, str[4];
1780 if (phba->sli_rev == LPFC_SLI_REV4)
1781 sprintf(fwrevision, "%s", vp->rev.opFwName);
1782 else if (vp->rev.rBit) {
1783 if (psli->sli_flag & LPFC_SLI_ACTIVE)
1784 rev = vp->rev.sli2FwRev;
1786 rev = vp->rev.sli1FwRev;
1788 b1 = (rev & 0x0000f000) >> 12;
1789 b2 = (rev & 0x00000f00) >> 8;
1790 b3 = (rev & 0x000000c0) >> 6;
1791 b4 = (rev & 0x00000030) >> 4;
1807 b4 = (rev & 0x0000000f);
1809 if (psli->sli_flag & LPFC_SLI_ACTIVE)
1810 fwname = vp->rev.sli2FwName;
1812 fwname = vp->rev.sli1FwName;
1814 for (i = 0; i < 16; i++)
1815 if (fwname[i] == 0x20)
1818 ptr = (uint32_t*)fwname;
1820 for (i = 0; i < 3; i++)
1821 str[i] = be32_to_cpu(*ptr++);
1825 sprintf(fwrevision, "%d.%d%d (%s)",
1826 b1, b2, b3, (char *)str);
1828 sprintf(fwrevision, "%d.%d%d", b1,
1832 sprintf(fwrevision, "%d.%d%d%c%d (%s)",
1836 sprintf(fwrevision, "%d.%d%d%c%d",
1840 rev = vp->rev.smFwRev;
1842 b1 = (rev & 0xff000000) >> 24;
1843 b2 = (rev & 0x00f00000) >> 20;
1844 b3 = (rev & 0x000f0000) >> 16;
1845 c = (rev & 0x0000ff00) >> 8;
1846 b4 = (rev & 0x000000ff);
1848 sprintf(fwrevision, "%d.%d%d%c%d", b1, b2, b3, c, b4);