1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2004-2006 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
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>
37 #include "lpfc_disc.h"
38 #include "lpfc_scsi.h"
40 #include "lpfc_logmsg.h"
41 #include "lpfc_crtn.h"
42 #include "lpfc_version.h"
44 #define HBA_PORTSPEED_UNKNOWN 0 /* Unknown - transceiver
45 * incapable of reporting */
46 #define HBA_PORTSPEED_1GBIT 1 /* 1 GBit/sec */
47 #define HBA_PORTSPEED_2GBIT 2 /* 2 GBit/sec */
48 #define HBA_PORTSPEED_4GBIT 8 /* 4 GBit/sec */
49 #define HBA_PORTSPEED_8GBIT 16 /* 8 GBit/sec */
50 #define HBA_PORTSPEED_10GBIT 4 /* 10 GBit/sec */
51 #define HBA_PORTSPEED_NOT_NEGOTIATED 5 /* Speed not established */
56 static char *lpfc_release_version = LPFC_DRIVER_VERSION;
62 lpfc_ct_unsol_event(struct lpfc_hba * phba,
63 struct lpfc_sli_ring * pring, struct lpfc_iocbq * piocbq)
66 struct lpfc_iocbq *next_piocbq;
67 struct lpfc_dmabuf *pmbuf = NULL;
68 struct lpfc_dmabuf *matp, *next_matp;
69 uint32_t ctx = 0, size = 0, cnt = 0;
70 IOCB_t *icmd = &piocbq->iocb;
71 IOCB_t *save_icmd = icmd;
73 struct list_head head;
75 if ((icmd->ulpStatus == IOSTAT_LOCAL_REJECT) &&
76 ((icmd->un.ulpWord[4] & 0xff) == IOERR_RCV_BUFFER_WAITING)) {
77 /* Not enough posted buffers; Try posting more buffers */
78 phba->fc_stat.NoRcvBuf++;
79 lpfc_post_buffer(phba, pring, 0, 1);
83 /* If there are no BDEs associated with this IOCB,
84 * there is nothing to do.
86 if (icmd->ulpBdeCount == 0)
89 INIT_LIST_HEAD(&head);
90 list_add_tail(&head, &piocbq->list);
92 list_for_each_entry_safe(piocbq, next_piocbq, &head, list) {
95 ctx = (uint32_t) (icmd->ulpContext);
96 if (icmd->ulpBdeCount == 0)
99 for (i = 0; i < icmd->ulpBdeCount; i++) {
100 matp = lpfc_sli_ringpostbuf_get(phba, pring,
108 /* Insert lpfc log message here */
109 lpfc_post_buffer(phba, pring, cnt, 1);
111 goto ct_unsol_event_exit_piocbq;
114 /* Typically for Unsolicited CT requests */
117 INIT_LIST_HEAD(&pmbuf->list);
119 list_add_tail(&matp->list, &pmbuf->list);
121 size += icmd->un.cont64[i].tus.f.bdeSize;
125 icmd->ulpBdeCount = 0;
128 lpfc_post_buffer(phba, pring, cnt, 1);
129 if (save_icmd->ulpStatus) {
133 ct_unsol_event_exit_piocbq:
135 list_for_each_entry_safe(matp, next_matp, &pmbuf->list, list) {
136 lpfc_mbuf_free(phba, matp->virt, matp->phys);
137 list_del(&matp->list);
140 lpfc_mbuf_free(phba, pmbuf->virt, pmbuf->phys);
147 lpfc_free_ct_rsp(struct lpfc_hba * phba, struct lpfc_dmabuf * mlist)
149 struct lpfc_dmabuf *mlast, *next_mlast;
151 list_for_each_entry_safe(mlast, next_mlast, &mlist->list, list) {
152 lpfc_mbuf_free(phba, mlast->virt, mlast->phys);
153 list_del(&mlast->list);
156 lpfc_mbuf_free(phba, mlist->virt, mlist->phys);
161 static struct lpfc_dmabuf *
162 lpfc_alloc_ct_rsp(struct lpfc_hba * phba, int cmdcode, struct ulp_bde64 * bpl,
163 uint32_t size, int *entries)
165 struct lpfc_dmabuf *mlist = NULL;
166 struct lpfc_dmabuf *mp;
169 /* We get chucks of FCELSSIZE */
170 cnt = size > FCELSSIZE ? FCELSSIZE: size;
173 /* Allocate buffer for rsp payload */
174 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
177 lpfc_free_ct_rsp(phba, mlist);
181 INIT_LIST_HEAD(&mp->list);
183 if (cmdcode == be16_to_cpu(SLI_CTNS_GID_FT))
184 mp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(mp->phys));
186 mp->virt = lpfc_mbuf_alloc(phba, 0, &(mp->phys));
190 lpfc_free_ct_rsp(phba, mlist);
194 /* Queue it to a linked list */
198 list_add_tail(&mp->list, &mlist->list);
200 bpl->tus.f.bdeFlags = BUFF_USE_RCV;
201 /* build buffer ptr list for IOCB */
202 bpl->addrLow = le32_to_cpu( putPaddrLow(mp->phys) );
203 bpl->addrHigh = le32_to_cpu( putPaddrHigh(mp->phys) );
204 bpl->tus.f.bdeSize = (uint16_t) cnt;
205 bpl->tus.w = le32_to_cpu(bpl->tus.w);
217 lpfc_gen_req(struct lpfc_hba *phba, struct lpfc_dmabuf *bmp,
218 struct lpfc_dmabuf *inp, struct lpfc_dmabuf *outp,
219 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
220 struct lpfc_iocbq *),
221 struct lpfc_nodelist *ndlp, uint32_t usr_flg, uint32_t num_entry,
225 struct lpfc_sli *psli = &phba->sli;
226 struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
228 struct lpfc_iocbq *geniocb;
230 /* Allocate buffer for command iocb */
231 spin_lock_irq(phba->host->host_lock);
232 geniocb = lpfc_sli_get_iocbq(phba);
233 spin_unlock_irq(phba->host->host_lock);
238 icmd = &geniocb->iocb;
239 icmd->un.genreq64.bdl.ulpIoTag32 = 0;
240 icmd->un.genreq64.bdl.addrHigh = putPaddrHigh(bmp->phys);
241 icmd->un.genreq64.bdl.addrLow = putPaddrLow(bmp->phys);
242 icmd->un.genreq64.bdl.bdeFlags = BUFF_TYPE_BDL;
243 icmd->un.genreq64.bdl.bdeSize = (num_entry * sizeof (struct ulp_bde64));
246 geniocb->context3 = NULL;
248 geniocb->context3 = (uint8_t *) bmp;
250 /* Save for completion so we can release these resources */
251 geniocb->context1 = (uint8_t *) inp;
252 geniocb->context2 = (uint8_t *) outp;
254 /* Fill in payload, bp points to frame payload */
255 icmd->ulpCommand = CMD_GEN_REQUEST64_CR;
257 /* Fill in rest of iocb */
258 icmd->un.genreq64.w5.hcsw.Fctl = (SI | LA);
259 icmd->un.genreq64.w5.hcsw.Dfctl = 0;
260 icmd->un.genreq64.w5.hcsw.Rctl = FC_UNSOL_CTL;
261 icmd->un.genreq64.w5.hcsw.Type = FC_COMMON_TRANSPORT_ULP;
264 /* FC spec states we need 3 * ratov for CT requests */
265 tmo = (3 * phba->fc_ratov);
267 icmd->ulpTimeout = tmo;
268 icmd->ulpBdeCount = 1;
270 icmd->ulpClass = CLASS3;
271 icmd->ulpContext = ndlp->nlp_rpi;
273 /* Issue GEN REQ IOCB for NPORT <did> */
274 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
275 "%d:0119 Issue GEN REQ IOCB for NPORT x%x "
276 "Data: x%x x%x\n", phba->brd_no, icmd->un.ulpWord[5],
277 icmd->ulpIoTag, phba->hba_state);
278 geniocb->iocb_cmpl = cmpl;
279 geniocb->drvrTimeout = icmd->ulpTimeout + LPFC_DRVR_TIMEOUT;
280 spin_lock_irq(phba->host->host_lock);
281 if (lpfc_sli_issue_iocb(phba, pring, geniocb, 0) == IOCB_ERROR) {
282 lpfc_sli_release_iocbq(phba, geniocb);
283 spin_unlock_irq(phba->host->host_lock);
286 spin_unlock_irq(phba->host->host_lock);
292 lpfc_ct_cmd(struct lpfc_hba *phba, struct lpfc_dmabuf *inmp,
293 struct lpfc_dmabuf *bmp, struct lpfc_nodelist *ndlp,
294 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
295 struct lpfc_iocbq *),
298 struct ulp_bde64 *bpl = (struct ulp_bde64 *) bmp->virt;
299 struct lpfc_dmabuf *outmp;
301 int cmdcode = ((struct lpfc_sli_ct_request *) inmp->virt)->
302 CommandResponse.bits.CmdRsp;
304 bpl++; /* Skip past ct request */
306 /* Put buffer(s) for ct rsp in bpl */
307 outmp = lpfc_alloc_ct_rsp(phba, cmdcode, bpl, rsp_size, &cnt);
311 status = lpfc_gen_req(phba, bmp, inmp, outmp, cmpl, ndlp, 0,
314 lpfc_free_ct_rsp(phba, outmp);
321 lpfc_ns_rsp(struct lpfc_hba * phba, struct lpfc_dmabuf * mp, uint32_t Size)
323 struct lpfc_sli_ct_request *Response =
324 (struct lpfc_sli_ct_request *) mp->virt;
325 struct lpfc_nodelist *ndlp = NULL;
326 struct lpfc_nodelist *next_ndlp;
327 struct lpfc_dmabuf *mlast, *next_mp;
328 uint32_t *ctptr = (uint32_t *) & Response->un.gid.PortType;
332 struct list_head head;
334 lpfc_set_disctmo(phba);
336 Cnt = Size > FCELSSIZE ? FCELSSIZE : Size;
338 list_add_tail(&head, &mp->list);
339 list_for_each_entry_safe(mp, next_mp, &head, list) {
345 ctptr = (uint32_t *) mlast->virt;
347 Cnt -= 16; /* subtract length of CT header */
349 /* Loop through entire NameServer list of DIDs */
352 /* Get next DID from NameServer List */
354 Did = ((be32_to_cpu(CTentry)) & Mask_DID);
357 if (Did != phba->fc_myDID) {
358 /* Check for rscn processing or not */
359 ndlp = lpfc_setup_disc_node(phba, Did);
361 /* Mark all node table entries that are in the
365 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
366 "%d:0238 Process x%x NameServer"
367 " Rsp Data: x%x x%x x%x\n",
371 phba->fc_rscn_id_cnt);
374 lpfc_printf_log(phba,
377 "%d:0239 Skip x%x NameServer "
378 "Rsp Data: x%x x%x x%x\n",
380 Did, Size, phba->fc_flag,
381 phba->fc_rscn_id_cnt);
384 if (CTentry & (be32_to_cpu(SLI_CT_LAST_ENTRY)))
386 Cnt -= sizeof (uint32_t);
396 * The driver has cycled through all Nports in the RSCN payload.
397 * Complete the handling by cleaning up and marking the
398 * current driver state.
400 if (phba->hba_state == LPFC_HBA_READY) {
403 * Switch ports that connect a loop of multiple targets need
404 * special consideration. The driver wants to unregister the
405 * rpi only on the target that was pulled from the loop. On
406 * RSCN, the driver wants to rediscover an NPort only if the
407 * driver flagged it as NLP_NPR_2B_DISC. Provided adisc is
408 * not enabled and the NPort is not capable of retransmissions
409 * (FC Tape) prevent timing races with the scsi error handler by
410 * unregistering the Nport's RPI. This action causes all
411 * outstanding IO to flush back to the midlayer.
413 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_npr_list,
415 if (!(ndlp->nlp_flag & NLP_NPR_2B_DISC) &&
416 (lpfc_rscn_payload_check(phba, ndlp->nlp_DID))) {
417 if ((phba->cfg_use_adisc == 0) &&
418 !(ndlp->nlp_fcp_info &
420 lpfc_unreg_rpi(phba, ndlp);
421 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
425 lpfc_els_flush_rscn(phba);
426 spin_lock_irq(phba->host->host_lock);
427 phba->fc_flag |= FC_RSCN_MODE; /* we are still in RSCN mode */
428 spin_unlock_irq(phba->host->host_lock);
437 lpfc_cmpl_ct_cmd_gid_ft(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
438 struct lpfc_iocbq * rspiocb)
441 struct lpfc_sli *psli;
442 struct lpfc_dmabuf *bmp;
443 struct lpfc_dmabuf *inp;
444 struct lpfc_dmabuf *outp;
445 struct lpfc_nodelist *ndlp;
446 struct lpfc_sli_ct_request *CTrsp;
449 /* we pass cmdiocb to state machine which needs rspiocb as well */
450 cmdiocb->context_un.rsp_iocb = rspiocb;
452 inp = (struct lpfc_dmabuf *) cmdiocb->context1;
453 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
454 bmp = (struct lpfc_dmabuf *) cmdiocb->context3;
456 irsp = &rspiocb->iocb;
457 if (irsp->ulpStatus) {
458 if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
459 ((irsp->un.ulpWord[4] == IOERR_SLI_DOWN) ||
460 (irsp->un.ulpWord[4] == IOERR_SLI_ABORTED))) {
464 /* Check for retry */
465 if (phba->fc_ns_retry < LPFC_MAX_NS_RETRY) {
467 /* CT command is being retried */
469 lpfc_findnode_did(phba, NLP_SEARCH_UNMAPPED,
472 if (lpfc_ns_cmd(phba, ndlp, SLI_CTNS_GID_FT) ==
479 /* Good status, continue checking */
480 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
481 if (CTrsp->CommandResponse.bits.CmdRsp ==
482 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC)) {
483 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
484 "%d:0239 NameServer Rsp "
488 lpfc_ns_rsp(phba, outp,
489 (uint32_t) (irsp->un.genreq64.bdl.bdeSize));
490 } else if (CTrsp->CommandResponse.bits.CmdRsp ==
491 be16_to_cpu(SLI_CT_RESPONSE_FS_RJT)) {
492 /* NameServer Rsp Error */
493 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
494 "%d:0240 NameServer Rsp Error "
495 "Data: x%x x%x x%x x%x\n",
497 CTrsp->CommandResponse.bits.CmdRsp,
498 (uint32_t) CTrsp->ReasonCode,
499 (uint32_t) CTrsp->Explanation,
502 /* NameServer Rsp Error */
503 lpfc_printf_log(phba,
506 "%d:0241 NameServer Rsp Error "
507 "Data: x%x x%x x%x x%x\n",
509 CTrsp->CommandResponse.bits.CmdRsp,
510 (uint32_t) CTrsp->ReasonCode,
511 (uint32_t) CTrsp->Explanation,
515 /* Link up / RSCN discovery */
516 lpfc_disc_start(phba);
518 lpfc_free_ct_rsp(phba, outp);
519 lpfc_mbuf_free(phba, inp->virt, inp->phys);
520 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
523 spin_lock_irq(phba->host->host_lock);
524 lpfc_sli_release_iocbq(phba, cmdiocb);
525 spin_unlock_irq(phba->host->host_lock);
530 lpfc_cmpl_ct_cmd_rft_id(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
531 struct lpfc_iocbq * rspiocb)
533 struct lpfc_sli *psli;
534 struct lpfc_dmabuf *bmp;
535 struct lpfc_dmabuf *inp;
536 struct lpfc_dmabuf *outp;
538 struct lpfc_sli_ct_request *CTrsp;
541 /* we pass cmdiocb to state machine which needs rspiocb as well */
542 cmdiocb->context_un.rsp_iocb = rspiocb;
544 inp = (struct lpfc_dmabuf *) cmdiocb->context1;
545 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
546 bmp = (struct lpfc_dmabuf *) cmdiocb->context3;
547 irsp = &rspiocb->iocb;
549 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
551 /* RFT request completes status <ulpStatus> CmdRsp <CmdRsp> */
552 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
553 "%d:0209 RFT request completes ulpStatus x%x "
554 "CmdRsp x%x\n", phba->brd_no, irsp->ulpStatus,
555 CTrsp->CommandResponse.bits.CmdRsp);
557 lpfc_free_ct_rsp(phba, outp);
558 lpfc_mbuf_free(phba, inp->virt, inp->phys);
559 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
562 spin_lock_irq(phba->host->host_lock);
563 lpfc_sli_release_iocbq(phba, cmdiocb);
564 spin_unlock_irq(phba->host->host_lock);
569 lpfc_cmpl_ct_cmd_rnn_id(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
570 struct lpfc_iocbq * rspiocb)
572 lpfc_cmpl_ct_cmd_rft_id(phba, cmdiocb, rspiocb);
577 lpfc_cmpl_ct_cmd_rsnn_nn(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
578 struct lpfc_iocbq * rspiocb)
580 lpfc_cmpl_ct_cmd_rft_id(phba, cmdiocb, rspiocb);
585 lpfc_get_hba_sym_node_name(struct lpfc_hba * phba, uint8_t * symbp)
589 lpfc_decode_firmware_rev(phba, fwrev, 0);
592 sprintf(symbp, "Emulex %s Port %s FV%s DV%s", phba->ModelName,
593 phba->Port, fwrev, lpfc_release_version);
595 sprintf(symbp, "Emulex %s FV%s DV%s", phba->ModelName,
596 fwrev, lpfc_release_version);
603 * Issue Cmd to NameServer
608 lpfc_ns_cmd(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp, int cmdcode)
610 struct lpfc_dmabuf *mp, *bmp;
611 struct lpfc_sli_ct_request *CtReq;
612 struct ulp_bde64 *bpl;
613 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
614 struct lpfc_iocbq *) = NULL;
615 uint32_t rsp_size = 1024;
617 /* fill in BDEs for command */
618 /* Allocate buffer for command payload */
619 mp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
623 INIT_LIST_HEAD(&mp->list);
624 mp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(mp->phys));
628 /* Allocate buffer for Buffer ptr list */
629 bmp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
631 goto ns_cmd_free_mpvirt;
633 INIT_LIST_HEAD(&bmp->list);
634 bmp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(bmp->phys));
636 goto ns_cmd_free_bmp;
639 lpfc_printf_log(phba,
642 "%d:0236 NameServer Req Data: x%x x%x x%x\n",
643 phba->brd_no, cmdcode, phba->fc_flag,
644 phba->fc_rscn_id_cnt);
646 bpl = (struct ulp_bde64 *) bmp->virt;
647 memset(bpl, 0, sizeof(struct ulp_bde64));
648 bpl->addrHigh = le32_to_cpu( putPaddrHigh(mp->phys) );
649 bpl->addrLow = le32_to_cpu( putPaddrLow(mp->phys) );
650 bpl->tus.f.bdeFlags = 0;
651 if (cmdcode == SLI_CTNS_GID_FT)
652 bpl->tus.f.bdeSize = GID_REQUEST_SZ;
653 else if (cmdcode == SLI_CTNS_RFT_ID)
654 bpl->tus.f.bdeSize = RFT_REQUEST_SZ;
655 else if (cmdcode == SLI_CTNS_RNN_ID)
656 bpl->tus.f.bdeSize = RNN_REQUEST_SZ;
657 else if (cmdcode == SLI_CTNS_RSNN_NN)
658 bpl->tus.f.bdeSize = RSNN_REQUEST_SZ;
660 bpl->tus.f.bdeSize = 0;
661 bpl->tus.w = le32_to_cpu(bpl->tus.w);
663 CtReq = (struct lpfc_sli_ct_request *) mp->virt;
664 memset(CtReq, 0, sizeof (struct lpfc_sli_ct_request));
665 CtReq->RevisionId.bits.Revision = SLI_CT_REVISION;
666 CtReq->RevisionId.bits.InId = 0;
667 CtReq->FsType = SLI_CT_DIRECTORY_SERVICE;
668 CtReq->FsSubType = SLI_CT_DIRECTORY_NAME_SERVER;
669 CtReq->CommandResponse.bits.Size = 0;
671 case SLI_CTNS_GID_FT:
672 CtReq->CommandResponse.bits.CmdRsp =
673 be16_to_cpu(SLI_CTNS_GID_FT);
674 CtReq->un.gid.Fc4Type = SLI_CTPT_FCP;
675 if (phba->hba_state < LPFC_HBA_READY)
676 phba->hba_state = LPFC_NS_QRY;
677 lpfc_set_disctmo(phba);
678 cmpl = lpfc_cmpl_ct_cmd_gid_ft;
679 rsp_size = FC_MAX_NS_RSP;
682 case SLI_CTNS_RFT_ID:
683 CtReq->CommandResponse.bits.CmdRsp =
684 be16_to_cpu(SLI_CTNS_RFT_ID);
685 CtReq->un.rft.PortId = be32_to_cpu(phba->fc_myDID);
686 CtReq->un.rft.fcpReg = 1;
687 cmpl = lpfc_cmpl_ct_cmd_rft_id;
690 case SLI_CTNS_RNN_ID:
691 CtReq->CommandResponse.bits.CmdRsp =
692 be16_to_cpu(SLI_CTNS_RNN_ID);
693 CtReq->un.rnn.PortId = be32_to_cpu(phba->fc_myDID);
694 memcpy(CtReq->un.rnn.wwnn, &phba->fc_nodename,
695 sizeof (struct lpfc_name));
696 cmpl = lpfc_cmpl_ct_cmd_rnn_id;
699 case SLI_CTNS_RSNN_NN:
700 CtReq->CommandResponse.bits.CmdRsp =
701 be16_to_cpu(SLI_CTNS_RSNN_NN);
702 memcpy(CtReq->un.rsnn.wwnn, &phba->fc_nodename,
703 sizeof (struct lpfc_name));
704 lpfc_get_hba_sym_node_name(phba, CtReq->un.rsnn.symbname);
705 CtReq->un.rsnn.len = strlen(CtReq->un.rsnn.symbname);
706 cmpl = lpfc_cmpl_ct_cmd_rsnn_nn;
710 if (!lpfc_ct_cmd(phba, mp, bmp, ndlp, cmpl, rsp_size))
711 /* On success, The cmpl function will free the buffers */
714 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
718 lpfc_mbuf_free(phba, mp->virt, mp->phys);
726 lpfc_cmpl_ct_cmd_fdmi(struct lpfc_hba * phba,
727 struct lpfc_iocbq * cmdiocb, struct lpfc_iocbq * rspiocb)
729 struct lpfc_dmabuf *bmp = cmdiocb->context3;
730 struct lpfc_dmabuf *inp = cmdiocb->context1;
731 struct lpfc_dmabuf *outp = cmdiocb->context2;
732 struct lpfc_sli_ct_request *CTrsp = outp->virt;
733 struct lpfc_sli_ct_request *CTcmd = inp->virt;
734 struct lpfc_nodelist *ndlp;
735 uint16_t fdmi_cmd = CTcmd->CommandResponse.bits.CmdRsp;
736 uint16_t fdmi_rsp = CTrsp->CommandResponse.bits.CmdRsp;
738 ndlp = lpfc_findnode_did(phba, NLP_SEARCH_ALL, FDMI_DID);
739 if (fdmi_rsp == be16_to_cpu(SLI_CT_RESPONSE_FS_RJT)) {
740 /* FDMI rsp failed */
741 lpfc_printf_log(phba,
744 "%d:0220 FDMI rsp failed Data: x%x\n",
746 be16_to_cpu(fdmi_cmd));
749 switch (be16_to_cpu(fdmi_cmd)) {
751 lpfc_fdmi_cmd(phba, ndlp, SLI_MGMT_RPA);
758 lpfc_fdmi_cmd(phba, ndlp, SLI_MGMT_DPRT);
762 lpfc_fdmi_cmd(phba, ndlp, SLI_MGMT_RHBA);
766 lpfc_free_ct_rsp(phba, outp);
767 lpfc_mbuf_free(phba, inp->virt, inp->phys);
768 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
771 spin_lock_irq(phba->host->host_lock);
772 lpfc_sli_release_iocbq(phba, cmdiocb);
773 spin_unlock_irq(phba->host->host_lock);
777 lpfc_fdmi_cmd(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp, int cmdcode)
779 struct lpfc_dmabuf *mp, *bmp;
780 struct lpfc_sli_ct_request *CtReq;
781 struct ulp_bde64 *bpl;
785 REG_PORT_ATTRIBUTE *pab;
788 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
789 struct lpfc_iocbq *);
792 /* fill in BDEs for command */
793 /* Allocate buffer for command payload */
794 mp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
798 mp->virt = lpfc_mbuf_alloc(phba, 0, &(mp->phys));
800 goto fdmi_cmd_free_mp;
802 /* Allocate buffer for Buffer ptr list */
803 bmp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
805 goto fdmi_cmd_free_mpvirt;
807 bmp->virt = lpfc_mbuf_alloc(phba, 0, &(bmp->phys));
809 goto fdmi_cmd_free_bmp;
811 INIT_LIST_HEAD(&mp->list);
812 INIT_LIST_HEAD(&bmp->list);
815 lpfc_printf_log(phba,
818 "%d:0218 FDMI Request Data: x%x x%x x%x\n",
820 phba->fc_flag, phba->hba_state, cmdcode);
822 CtReq = (struct lpfc_sli_ct_request *) mp->virt;
824 memset(CtReq, 0, sizeof(struct lpfc_sli_ct_request));
825 CtReq->RevisionId.bits.Revision = SLI_CT_REVISION;
826 CtReq->RevisionId.bits.InId = 0;
828 CtReq->FsType = SLI_CT_MANAGEMENT_SERVICE;
829 CtReq->FsSubType = SLI_CT_FDMI_Subtypes;
835 lpfc_vpd_t *vp = &phba->vpd;
839 CtReq->CommandResponse.bits.CmdRsp =
840 be16_to_cpu(SLI_MGMT_RHBA);
841 CtReq->CommandResponse.bits.Size = 0;
842 rh = (REG_HBA *) & CtReq->un.PortID;
843 memcpy(&rh->hi.PortName, &phba->fc_sparam.portName,
844 sizeof (struct lpfc_name));
845 /* One entry (port) per adapter */
846 rh->rpl.EntryCnt = be32_to_cpu(1);
847 memcpy(&rh->rpl.pe, &phba->fc_sparam.portName,
848 sizeof (struct lpfc_name));
850 /* point to the HBA attribute block */
851 size = 2 * sizeof (struct lpfc_name) + FOURBYTES;
852 ab = (ATTRIBUTE_BLOCK *) ((uint8_t *) rh + size);
855 /* Point to the beginning of the first HBA attribute
857 /* #1 HBA attribute entry */
859 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
860 ae->ad.bits.AttrType = be16_to_cpu(NODE_NAME);
861 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES
862 + sizeof (struct lpfc_name));
863 memcpy(&ae->un.NodeName, &phba->fc_sparam.nodeName,
864 sizeof (struct lpfc_name));
866 size += FOURBYTES + sizeof (struct lpfc_name);
868 /* #2 HBA attribute entry */
869 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
870 ae->ad.bits.AttrType = be16_to_cpu(MANUFACTURER);
871 strcpy(ae->un.Manufacturer, "Emulex Corporation");
872 len = strlen(ae->un.Manufacturer);
873 len += (len & 3) ? (4 - (len & 3)) : 4;
874 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
876 size += FOURBYTES + len;
878 /* #3 HBA attribute entry */
879 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
880 ae->ad.bits.AttrType = be16_to_cpu(SERIAL_NUMBER);
881 strcpy(ae->un.SerialNumber, phba->SerialNumber);
882 len = strlen(ae->un.SerialNumber);
883 len += (len & 3) ? (4 - (len & 3)) : 4;
884 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
886 size += FOURBYTES + len;
888 /* #4 HBA attribute entry */
889 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
890 ae->ad.bits.AttrType = be16_to_cpu(MODEL);
891 strcpy(ae->un.Model, phba->ModelName);
892 len = strlen(ae->un.Model);
893 len += (len & 3) ? (4 - (len & 3)) : 4;
894 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
896 size += FOURBYTES + len;
898 /* #5 HBA attribute entry */
899 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
900 ae->ad.bits.AttrType = be16_to_cpu(MODEL_DESCRIPTION);
901 strcpy(ae->un.ModelDescription, phba->ModelDesc);
902 len = strlen(ae->un.ModelDescription);
903 len += (len & 3) ? (4 - (len & 3)) : 4;
904 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
906 size += FOURBYTES + len;
908 /* #6 HBA attribute entry */
909 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
910 ae->ad.bits.AttrType = be16_to_cpu(HARDWARE_VERSION);
911 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 8);
912 /* Convert JEDEC ID to ascii for hardware version */
913 incr = vp->rev.biuRev;
914 for (i = 0; i < 8; i++) {
917 ae->un.HardwareVersion[7 - i] =
918 (char)((uint8_t) 0x30 +
921 ae->un.HardwareVersion[7 - i] =
922 (char)((uint8_t) 0x61 +
927 size += FOURBYTES + 8;
929 /* #7 HBA attribute entry */
930 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
931 ae->ad.bits.AttrType = be16_to_cpu(DRIVER_VERSION);
932 strcpy(ae->un.DriverVersion, lpfc_release_version);
933 len = strlen(ae->un.DriverVersion);
934 len += (len & 3) ? (4 - (len & 3)) : 4;
935 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
937 size += FOURBYTES + len;
939 /* #8 HBA attribute entry */
940 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
941 ae->ad.bits.AttrType = be16_to_cpu(OPTION_ROM_VERSION);
942 strcpy(ae->un.OptionROMVersion, phba->OptionROMVersion);
943 len = strlen(ae->un.OptionROMVersion);
944 len += (len & 3) ? (4 - (len & 3)) : 4;
945 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
947 size += FOURBYTES + len;
949 /* #9 HBA attribute entry */
950 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
951 ae->ad.bits.AttrType = be16_to_cpu(FIRMWARE_VERSION);
952 lpfc_decode_firmware_rev(phba, ae->un.FirmwareVersion,
954 len = strlen(ae->un.FirmwareVersion);
955 len += (len & 3) ? (4 - (len & 3)) : 4;
956 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
958 size += FOURBYTES + len;
960 /* #10 HBA attribute entry */
961 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
962 ae->ad.bits.AttrType = be16_to_cpu(OS_NAME_VERSION);
963 sprintf(ae->un.OsNameVersion, "%s %s %s",
964 system_utsname.sysname, system_utsname.release,
965 system_utsname.version);
966 len = strlen(ae->un.OsNameVersion);
967 len += (len & 3) ? (4 - (len & 3)) : 4;
968 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
970 size += FOURBYTES + len;
972 /* #11 HBA attribute entry */
973 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
974 ae->ad.bits.AttrType = be16_to_cpu(MAX_CT_PAYLOAD_LEN);
975 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
976 ae->un.MaxCTPayloadLen = (65 * 4096);
978 size += FOURBYTES + 4;
980 ab->EntryCnt = be32_to_cpu(ab->EntryCnt);
982 size = GID_REQUEST_SZ - 4 + size;
989 struct serv_parm *hsp;
994 CtReq->CommandResponse.bits.CmdRsp =
995 be16_to_cpu(SLI_MGMT_RPA);
996 CtReq->CommandResponse.bits.Size = 0;
997 pab = (REG_PORT_ATTRIBUTE *) & CtReq->un.PortID;
998 size = sizeof (struct lpfc_name) + FOURBYTES;
999 memcpy((uint8_t *) & pab->PortName,
1000 (uint8_t *) & phba->fc_sparam.portName,
1001 sizeof (struct lpfc_name));
1002 pab->ab.EntryCnt = 0;
1004 /* #1 Port attribute entry */
1005 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
1006 ae->ad.bits.AttrType = be16_to_cpu(SUPPORTED_FC4_TYPES);
1007 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 32);
1008 ae->un.SupportFC4Types[2] = 1;
1009 ae->un.SupportFC4Types[7] = 1;
1011 size += FOURBYTES + 32;
1013 /* #2 Port attribute entry */
1014 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
1015 ae->ad.bits.AttrType = be16_to_cpu(SUPPORTED_SPEED);
1016 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
1018 ae->un.SupportSpeed = 0;
1019 if (phba->lmt & LMT_10Gb)
1020 ae->un.SupportSpeed = HBA_PORTSPEED_10GBIT;
1021 if (phba->lmt & LMT_8Gb)
1022 ae->un.SupportSpeed |= HBA_PORTSPEED_8GBIT;
1023 if (phba->lmt & LMT_4Gb)
1024 ae->un.SupportSpeed |= HBA_PORTSPEED_4GBIT;
1025 if (phba->lmt & LMT_2Gb)
1026 ae->un.SupportSpeed |= HBA_PORTSPEED_2GBIT;
1027 if (phba->lmt & LMT_1Gb)
1028 ae->un.SupportSpeed |= HBA_PORTSPEED_1GBIT;
1031 size += FOURBYTES + 4;
1033 /* #3 Port attribute entry */
1034 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
1035 ae->ad.bits.AttrType = be16_to_cpu(PORT_SPEED);
1036 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
1037 switch(phba->fc_linkspeed) {
1039 ae->un.PortSpeed = HBA_PORTSPEED_1GBIT;
1042 ae->un.PortSpeed = HBA_PORTSPEED_2GBIT;
1045 ae->un.PortSpeed = HBA_PORTSPEED_4GBIT;
1049 HBA_PORTSPEED_UNKNOWN;
1053 size += FOURBYTES + 4;
1055 /* #4 Port attribute entry */
1056 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
1057 ae->ad.bits.AttrType = be16_to_cpu(MAX_FRAME_SIZE);
1058 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
1059 hsp = (struct serv_parm *) & phba->fc_sparam;
1060 ae->un.MaxFrameSize =
1061 (((uint32_t) hsp->cmn.
1062 bbRcvSizeMsb) << 8) | (uint32_t) hsp->cmn.
1065 size += FOURBYTES + 4;
1067 /* #5 Port attribute entry */
1068 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
1069 ae->ad.bits.AttrType = be16_to_cpu(OS_DEVICE_NAME);
1070 strcpy((char *)ae->un.OsDeviceName, LPFC_DRIVER_NAME);
1071 len = strlen((char *)ae->un.OsDeviceName);
1072 len += (len & 3) ? (4 - (len & 3)) : 4;
1073 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1075 size += FOURBYTES + len;
1077 if (phba->cfg_fdmi_on == 2) {
1078 /* #6 Port attribute entry */
1079 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab +
1081 ae->ad.bits.AttrType = be16_to_cpu(HOST_NAME);
1082 sprintf(ae->un.HostName, "%s",
1083 system_utsname.nodename);
1084 len = strlen(ae->un.HostName);
1085 len += (len & 3) ? (4 - (len & 3)) : 4;
1086 ae->ad.bits.AttrLen =
1087 be16_to_cpu(FOURBYTES + len);
1089 size += FOURBYTES + len;
1092 pab->ab.EntryCnt = be32_to_cpu(pab->ab.EntryCnt);
1094 size = GID_REQUEST_SZ - 4 + size;
1099 CtReq->CommandResponse.bits.CmdRsp = be16_to_cpu(SLI_MGMT_DHBA);
1100 CtReq->CommandResponse.bits.Size = 0;
1101 pe = (PORT_ENTRY *) & CtReq->un.PortID;
1102 memcpy((uint8_t *) & pe->PortName,
1103 (uint8_t *) & phba->fc_sparam.portName,
1104 sizeof (struct lpfc_name));
1105 size = GID_REQUEST_SZ - 4 + sizeof (struct lpfc_name);
1109 CtReq->CommandResponse.bits.CmdRsp = be16_to_cpu(SLI_MGMT_DPRT);
1110 CtReq->CommandResponse.bits.Size = 0;
1111 pe = (PORT_ENTRY *) & CtReq->un.PortID;
1112 memcpy((uint8_t *) & pe->PortName,
1113 (uint8_t *) & phba->fc_sparam.portName,
1114 sizeof (struct lpfc_name));
1115 size = GID_REQUEST_SZ - 4 + sizeof (struct lpfc_name);
1119 bpl = (struct ulp_bde64 *) bmp->virt;
1120 bpl->addrHigh = le32_to_cpu( putPaddrHigh(mp->phys) );
1121 bpl->addrLow = le32_to_cpu( putPaddrLow(mp->phys) );
1122 bpl->tus.f.bdeFlags = 0;
1123 bpl->tus.f.bdeSize = size;
1124 bpl->tus.w = le32_to_cpu(bpl->tus.w);
1126 cmpl = lpfc_cmpl_ct_cmd_fdmi;
1128 if (!lpfc_ct_cmd(phba, mp, bmp, ndlp, cmpl, FC_MAX_NS_RSP))
1131 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
1134 fdmi_cmd_free_mpvirt:
1135 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1139 /* Issue FDMI request failed */
1140 lpfc_printf_log(phba,
1143 "%d:0244 Issue FDMI request failed Data: x%x\n",
1150 lpfc_fdmi_tmo(unsigned long ptr)
1152 struct lpfc_hba *phba = (struct lpfc_hba *)ptr;
1153 unsigned long iflag;
1155 spin_lock_irqsave(phba->host->host_lock, iflag);
1156 if (!(phba->work_hba_events & WORKER_FDMI_TMO)) {
1157 phba->work_hba_events |= WORKER_FDMI_TMO;
1158 if (phba->work_wait)
1159 wake_up(phba->work_wait);
1161 spin_unlock_irqrestore(phba->host->host_lock,iflag);
1165 lpfc_fdmi_tmo_handler(struct lpfc_hba *phba)
1167 struct lpfc_nodelist *ndlp;
1169 ndlp = lpfc_findnode_did(phba, NLP_SEARCH_ALL, FDMI_DID);
1171 if (system_utsname.nodename[0] != '\0') {
1172 lpfc_fdmi_cmd(phba, ndlp, SLI_MGMT_DHBA);
1174 mod_timer(&phba->fc_fdmitmo, jiffies + HZ * 60);
1182 lpfc_decode_firmware_rev(struct lpfc_hba * phba, char *fwrevision, int flag)
1184 struct lpfc_sli *psli = &phba->sli;
1185 lpfc_vpd_t *vp = &phba->vpd;
1186 uint32_t b1, b2, b3, b4, i, rev;
1188 uint32_t *ptr, str[4];
1192 if (psli->sli_flag & LPFC_SLI2_ACTIVE)
1193 rev = vp->rev.sli2FwRev;
1195 rev = vp->rev.sli1FwRev;
1197 b1 = (rev & 0x0000f000) >> 12;
1198 b2 = (rev & 0x00000f00) >> 8;
1199 b3 = (rev & 0x000000c0) >> 6;
1200 b4 = (rev & 0x00000030) >> 4;
1216 b4 = (rev & 0x0000000f);
1218 if (psli->sli_flag & LPFC_SLI2_ACTIVE)
1219 fwname = vp->rev.sli2FwName;
1221 fwname = vp->rev.sli1FwName;
1223 for (i = 0; i < 16; i++)
1224 if (fwname[i] == 0x20)
1227 ptr = (uint32_t*)fwname;
1229 for (i = 0; i < 3; i++)
1230 str[i] = be32_to_cpu(*ptr++);
1234 sprintf(fwrevision, "%d.%d%d (%s)",
1235 b1, b2, b3, (char *)str);
1237 sprintf(fwrevision, "%d.%d%d", b1,
1241 sprintf(fwrevision, "%d.%d%d%c%d (%s)",
1245 sprintf(fwrevision, "%d.%d%d%c%d",
1249 rev = vp->rev.smFwRev;
1251 b1 = (rev & 0xff000000) >> 24;
1252 b2 = (rev & 0x00f00000) >> 20;
1253 b3 = (rev & 0x000f0000) >> 16;
1254 c = (rev & 0x0000ff00) >> 8;
1255 b4 = (rev & 0x000000ff);
1258 sprintf(fwrevision, "%d.%d%d%c%d ", b1,
1261 sprintf(fwrevision, "%d.%d%d%c%d ", b1,