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_dmabuf *mlast, *next_mp;
327 uint32_t *ctptr = (uint32_t *) & Response->un.gid.PortType;
331 struct list_head head;
333 lpfc_set_disctmo(phba);
335 Cnt = Size > FCELSSIZE ? FCELSSIZE : Size;
337 list_add_tail(&head, &mp->list);
338 list_for_each_entry_safe(mp, next_mp, &head, list) {
344 ctptr = (uint32_t *) mlast->virt;
346 Cnt -= 16; /* subtract length of CT header */
348 /* Loop through entire NameServer list of DIDs */
351 /* Get next DID from NameServer List */
353 Did = ((be32_to_cpu(CTentry)) & Mask_DID);
356 if (Did != phba->fc_myDID) {
357 /* Check for rscn processing or not */
358 ndlp = lpfc_setup_disc_node(phba, Did);
360 /* Mark all node table entries that are in the
364 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
365 "%d:0238 Process x%x NameServer"
366 " Rsp Data: x%x x%x x%x\n",
370 phba->fc_rscn_id_cnt);
373 lpfc_printf_log(phba,
376 "%d:0239 Skip x%x NameServer "
377 "Rsp Data: x%x x%x x%x\n",
379 Did, Size, phba->fc_flag,
380 phba->fc_rscn_id_cnt);
383 if (CTentry & (be32_to_cpu(SLI_CT_LAST_ENTRY)))
385 Cnt -= sizeof (uint32_t);
394 /* Here we are finished in the case RSCN */
395 if (phba->hba_state == LPFC_HBA_READY) {
396 lpfc_els_flush_rscn(phba);
397 spin_lock_irq(phba->host->host_lock);
398 phba->fc_flag |= FC_RSCN_MODE; /* we are still in RSCN mode */
399 spin_unlock_irq(phba->host->host_lock);
408 lpfc_cmpl_ct_cmd_gid_ft(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
409 struct lpfc_iocbq * rspiocb)
412 struct lpfc_sli *psli;
413 struct lpfc_dmabuf *bmp;
414 struct lpfc_dmabuf *inp;
415 struct lpfc_dmabuf *outp;
416 struct lpfc_nodelist *ndlp;
417 struct lpfc_sli_ct_request *CTrsp;
420 /* we pass cmdiocb to state machine which needs rspiocb as well */
421 cmdiocb->context_un.rsp_iocb = rspiocb;
423 inp = (struct lpfc_dmabuf *) cmdiocb->context1;
424 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
425 bmp = (struct lpfc_dmabuf *) cmdiocb->context3;
427 irsp = &rspiocb->iocb;
428 if (irsp->ulpStatus) {
429 if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
430 ((irsp->un.ulpWord[4] == IOERR_SLI_DOWN) ||
431 (irsp->un.ulpWord[4] == IOERR_SLI_ABORTED))) {
435 /* Check for retry */
436 if (phba->fc_ns_retry < LPFC_MAX_NS_RETRY) {
438 /* CT command is being retried */
440 lpfc_findnode_did(phba, NLP_SEARCH_UNMAPPED,
443 if (lpfc_ns_cmd(phba, ndlp, SLI_CTNS_GID_FT) ==
450 /* Good status, continue checking */
451 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
452 if (CTrsp->CommandResponse.bits.CmdRsp ==
453 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC)) {
454 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
455 "%d:0239 NameServer Rsp "
459 lpfc_ns_rsp(phba, outp,
460 (uint32_t) (irsp->un.genreq64.bdl.bdeSize));
461 } else if (CTrsp->CommandResponse.bits.CmdRsp ==
462 be16_to_cpu(SLI_CT_RESPONSE_FS_RJT)) {
463 /* NameServer Rsp Error */
464 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
465 "%d:0240 NameServer Rsp Error "
466 "Data: x%x x%x x%x x%x\n",
468 CTrsp->CommandResponse.bits.CmdRsp,
469 (uint32_t) CTrsp->ReasonCode,
470 (uint32_t) CTrsp->Explanation,
473 /* NameServer Rsp Error */
474 lpfc_printf_log(phba,
477 "%d:0241 NameServer Rsp Error "
478 "Data: x%x x%x x%x x%x\n",
480 CTrsp->CommandResponse.bits.CmdRsp,
481 (uint32_t) CTrsp->ReasonCode,
482 (uint32_t) CTrsp->Explanation,
486 /* Link up / RSCN discovery */
487 lpfc_disc_start(phba);
489 lpfc_free_ct_rsp(phba, outp);
490 lpfc_mbuf_free(phba, inp->virt, inp->phys);
491 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
494 spin_lock_irq(phba->host->host_lock);
495 lpfc_sli_release_iocbq(phba, cmdiocb);
496 spin_unlock_irq(phba->host->host_lock);
501 lpfc_cmpl_ct_cmd_rft_id(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
502 struct lpfc_iocbq * rspiocb)
504 struct lpfc_sli *psli;
505 struct lpfc_dmabuf *bmp;
506 struct lpfc_dmabuf *inp;
507 struct lpfc_dmabuf *outp;
509 struct lpfc_sli_ct_request *CTrsp;
512 /* we pass cmdiocb to state machine which needs rspiocb as well */
513 cmdiocb->context_un.rsp_iocb = rspiocb;
515 inp = (struct lpfc_dmabuf *) cmdiocb->context1;
516 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
517 bmp = (struct lpfc_dmabuf *) cmdiocb->context3;
518 irsp = &rspiocb->iocb;
520 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
522 /* RFT request completes status <ulpStatus> CmdRsp <CmdRsp> */
523 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
524 "%d:0209 RFT request completes ulpStatus x%x "
525 "CmdRsp x%x\n", phba->brd_no, irsp->ulpStatus,
526 CTrsp->CommandResponse.bits.CmdRsp);
528 lpfc_free_ct_rsp(phba, outp);
529 lpfc_mbuf_free(phba, inp->virt, inp->phys);
530 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
533 spin_lock_irq(phba->host->host_lock);
534 lpfc_sli_release_iocbq(phba, cmdiocb);
535 spin_unlock_irq(phba->host->host_lock);
540 lpfc_cmpl_ct_cmd_rnn_id(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
541 struct lpfc_iocbq * rspiocb)
543 lpfc_cmpl_ct_cmd_rft_id(phba, cmdiocb, rspiocb);
548 lpfc_cmpl_ct_cmd_rsnn_nn(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
549 struct lpfc_iocbq * rspiocb)
551 lpfc_cmpl_ct_cmd_rft_id(phba, cmdiocb, rspiocb);
556 lpfc_get_hba_sym_node_name(struct lpfc_hba * phba, uint8_t * symbp)
560 lpfc_decode_firmware_rev(phba, fwrev, 0);
563 sprintf(symbp, "Emulex %s Port %s FV%s DV%s", phba->ModelName,
564 phba->Port, fwrev, lpfc_release_version);
566 sprintf(symbp, "Emulex %s FV%s DV%s", phba->ModelName,
567 fwrev, lpfc_release_version);
574 * Issue Cmd to NameServer
579 lpfc_ns_cmd(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp, int cmdcode)
581 struct lpfc_dmabuf *mp, *bmp;
582 struct lpfc_sli_ct_request *CtReq;
583 struct ulp_bde64 *bpl;
584 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
585 struct lpfc_iocbq *) = NULL;
586 uint32_t rsp_size = 1024;
588 /* fill in BDEs for command */
589 /* Allocate buffer for command payload */
590 mp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
594 INIT_LIST_HEAD(&mp->list);
595 mp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(mp->phys));
599 /* Allocate buffer for Buffer ptr list */
600 bmp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
602 goto ns_cmd_free_mpvirt;
604 INIT_LIST_HEAD(&bmp->list);
605 bmp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(bmp->phys));
607 goto ns_cmd_free_bmp;
610 lpfc_printf_log(phba,
613 "%d:0236 NameServer Req Data: x%x x%x x%x\n",
614 phba->brd_no, cmdcode, phba->fc_flag,
615 phba->fc_rscn_id_cnt);
617 bpl = (struct ulp_bde64 *) bmp->virt;
618 memset(bpl, 0, sizeof(struct ulp_bde64));
619 bpl->addrHigh = le32_to_cpu( putPaddrHigh(mp->phys) );
620 bpl->addrLow = le32_to_cpu( putPaddrLow(mp->phys) );
621 bpl->tus.f.bdeFlags = 0;
622 if (cmdcode == SLI_CTNS_GID_FT)
623 bpl->tus.f.bdeSize = GID_REQUEST_SZ;
624 else if (cmdcode == SLI_CTNS_RFT_ID)
625 bpl->tus.f.bdeSize = RFT_REQUEST_SZ;
626 else if (cmdcode == SLI_CTNS_RNN_ID)
627 bpl->tus.f.bdeSize = RNN_REQUEST_SZ;
628 else if (cmdcode == SLI_CTNS_RSNN_NN)
629 bpl->tus.f.bdeSize = RSNN_REQUEST_SZ;
631 bpl->tus.f.bdeSize = 0;
632 bpl->tus.w = le32_to_cpu(bpl->tus.w);
634 CtReq = (struct lpfc_sli_ct_request *) mp->virt;
635 memset(CtReq, 0, sizeof (struct lpfc_sli_ct_request));
636 CtReq->RevisionId.bits.Revision = SLI_CT_REVISION;
637 CtReq->RevisionId.bits.InId = 0;
638 CtReq->FsType = SLI_CT_DIRECTORY_SERVICE;
639 CtReq->FsSubType = SLI_CT_DIRECTORY_NAME_SERVER;
640 CtReq->CommandResponse.bits.Size = 0;
642 case SLI_CTNS_GID_FT:
643 CtReq->CommandResponse.bits.CmdRsp =
644 be16_to_cpu(SLI_CTNS_GID_FT);
645 CtReq->un.gid.Fc4Type = SLI_CTPT_FCP;
646 if (phba->hba_state < LPFC_HBA_READY)
647 phba->hba_state = LPFC_NS_QRY;
648 lpfc_set_disctmo(phba);
649 cmpl = lpfc_cmpl_ct_cmd_gid_ft;
650 rsp_size = FC_MAX_NS_RSP;
653 case SLI_CTNS_RFT_ID:
654 CtReq->CommandResponse.bits.CmdRsp =
655 be16_to_cpu(SLI_CTNS_RFT_ID);
656 CtReq->un.rft.PortId = be32_to_cpu(phba->fc_myDID);
657 CtReq->un.rft.fcpReg = 1;
658 cmpl = lpfc_cmpl_ct_cmd_rft_id;
661 case SLI_CTNS_RNN_ID:
662 CtReq->CommandResponse.bits.CmdRsp =
663 be16_to_cpu(SLI_CTNS_RNN_ID);
664 CtReq->un.rnn.PortId = be32_to_cpu(phba->fc_myDID);
665 memcpy(CtReq->un.rnn.wwnn, &phba->fc_nodename,
666 sizeof (struct lpfc_name));
667 cmpl = lpfc_cmpl_ct_cmd_rnn_id;
670 case SLI_CTNS_RSNN_NN:
671 CtReq->CommandResponse.bits.CmdRsp =
672 be16_to_cpu(SLI_CTNS_RSNN_NN);
673 memcpy(CtReq->un.rsnn.wwnn, &phba->fc_nodename,
674 sizeof (struct lpfc_name));
675 lpfc_get_hba_sym_node_name(phba, CtReq->un.rsnn.symbname);
676 CtReq->un.rsnn.len = strlen(CtReq->un.rsnn.symbname);
677 cmpl = lpfc_cmpl_ct_cmd_rsnn_nn;
681 if (!lpfc_ct_cmd(phba, mp, bmp, ndlp, cmpl, rsp_size))
682 /* On success, The cmpl function will free the buffers */
685 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
689 lpfc_mbuf_free(phba, mp->virt, mp->phys);
697 lpfc_cmpl_ct_cmd_fdmi(struct lpfc_hba * phba,
698 struct lpfc_iocbq * cmdiocb, struct lpfc_iocbq * rspiocb)
700 struct lpfc_dmabuf *bmp = cmdiocb->context3;
701 struct lpfc_dmabuf *inp = cmdiocb->context1;
702 struct lpfc_dmabuf *outp = cmdiocb->context2;
703 struct lpfc_sli_ct_request *CTrsp = outp->virt;
704 struct lpfc_sli_ct_request *CTcmd = inp->virt;
705 struct lpfc_nodelist *ndlp;
706 uint16_t fdmi_cmd = CTcmd->CommandResponse.bits.CmdRsp;
707 uint16_t fdmi_rsp = CTrsp->CommandResponse.bits.CmdRsp;
709 ndlp = lpfc_findnode_did(phba, NLP_SEARCH_ALL, FDMI_DID);
710 if (fdmi_rsp == be16_to_cpu(SLI_CT_RESPONSE_FS_RJT)) {
711 /* FDMI rsp failed */
712 lpfc_printf_log(phba,
715 "%d:0220 FDMI rsp failed Data: x%x\n",
717 be16_to_cpu(fdmi_cmd));
720 switch (be16_to_cpu(fdmi_cmd)) {
722 lpfc_fdmi_cmd(phba, ndlp, SLI_MGMT_RPA);
729 lpfc_fdmi_cmd(phba, ndlp, SLI_MGMT_DPRT);
733 lpfc_fdmi_cmd(phba, ndlp, SLI_MGMT_RHBA);
737 lpfc_free_ct_rsp(phba, outp);
738 lpfc_mbuf_free(phba, inp->virt, inp->phys);
739 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
742 spin_lock_irq(phba->host->host_lock);
743 lpfc_sli_release_iocbq(phba, cmdiocb);
744 spin_unlock_irq(phba->host->host_lock);
748 lpfc_fdmi_cmd(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp, int cmdcode)
750 struct lpfc_dmabuf *mp, *bmp;
751 struct lpfc_sli_ct_request *CtReq;
752 struct ulp_bde64 *bpl;
756 REG_PORT_ATTRIBUTE *pab;
759 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
760 struct lpfc_iocbq *);
763 /* fill in BDEs for command */
764 /* Allocate buffer for command payload */
765 mp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
769 mp->virt = lpfc_mbuf_alloc(phba, 0, &(mp->phys));
771 goto fdmi_cmd_free_mp;
773 /* Allocate buffer for Buffer ptr list */
774 bmp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
776 goto fdmi_cmd_free_mpvirt;
778 bmp->virt = lpfc_mbuf_alloc(phba, 0, &(bmp->phys));
780 goto fdmi_cmd_free_bmp;
782 INIT_LIST_HEAD(&mp->list);
783 INIT_LIST_HEAD(&bmp->list);
786 lpfc_printf_log(phba,
789 "%d:0218 FDMI Request Data: x%x x%x x%x\n",
791 phba->fc_flag, phba->hba_state, cmdcode);
793 CtReq = (struct lpfc_sli_ct_request *) mp->virt;
795 memset(CtReq, 0, sizeof(struct lpfc_sli_ct_request));
796 CtReq->RevisionId.bits.Revision = SLI_CT_REVISION;
797 CtReq->RevisionId.bits.InId = 0;
799 CtReq->FsType = SLI_CT_MANAGEMENT_SERVICE;
800 CtReq->FsSubType = SLI_CT_FDMI_Subtypes;
806 lpfc_vpd_t *vp = &phba->vpd;
810 CtReq->CommandResponse.bits.CmdRsp =
811 be16_to_cpu(SLI_MGMT_RHBA);
812 CtReq->CommandResponse.bits.Size = 0;
813 rh = (REG_HBA *) & CtReq->un.PortID;
814 memcpy(&rh->hi.PortName, &phba->fc_sparam.portName,
815 sizeof (struct lpfc_name));
816 /* One entry (port) per adapter */
817 rh->rpl.EntryCnt = be32_to_cpu(1);
818 memcpy(&rh->rpl.pe, &phba->fc_sparam.portName,
819 sizeof (struct lpfc_name));
821 /* point to the HBA attribute block */
822 size = 2 * sizeof (struct lpfc_name) + FOURBYTES;
823 ab = (ATTRIBUTE_BLOCK *) ((uint8_t *) rh + size);
826 /* Point to the beginning of the first HBA attribute
828 /* #1 HBA attribute entry */
830 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
831 ae->ad.bits.AttrType = be16_to_cpu(NODE_NAME);
832 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES
833 + sizeof (struct lpfc_name));
834 memcpy(&ae->un.NodeName, &phba->fc_sparam.nodeName,
835 sizeof (struct lpfc_name));
837 size += FOURBYTES + sizeof (struct lpfc_name);
839 /* #2 HBA attribute entry */
840 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
841 ae->ad.bits.AttrType = be16_to_cpu(MANUFACTURER);
842 strcpy(ae->un.Manufacturer, "Emulex Corporation");
843 len = strlen(ae->un.Manufacturer);
844 len += (len & 3) ? (4 - (len & 3)) : 4;
845 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
847 size += FOURBYTES + len;
849 /* #3 HBA attribute entry */
850 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
851 ae->ad.bits.AttrType = be16_to_cpu(SERIAL_NUMBER);
852 strcpy(ae->un.SerialNumber, phba->SerialNumber);
853 len = strlen(ae->un.SerialNumber);
854 len += (len & 3) ? (4 - (len & 3)) : 4;
855 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
857 size += FOURBYTES + len;
859 /* #4 HBA attribute entry */
860 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
861 ae->ad.bits.AttrType = be16_to_cpu(MODEL);
862 strcpy(ae->un.Model, phba->ModelName);
863 len = strlen(ae->un.Model);
864 len += (len & 3) ? (4 - (len & 3)) : 4;
865 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
867 size += FOURBYTES + len;
869 /* #5 HBA attribute entry */
870 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
871 ae->ad.bits.AttrType = be16_to_cpu(MODEL_DESCRIPTION);
872 strcpy(ae->un.ModelDescription, phba->ModelDesc);
873 len = strlen(ae->un.ModelDescription);
874 len += (len & 3) ? (4 - (len & 3)) : 4;
875 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
877 size += FOURBYTES + len;
879 /* #6 HBA attribute entry */
880 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
881 ae->ad.bits.AttrType = be16_to_cpu(HARDWARE_VERSION);
882 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 8);
883 /* Convert JEDEC ID to ascii for hardware version */
884 incr = vp->rev.biuRev;
885 for (i = 0; i < 8; i++) {
888 ae->un.HardwareVersion[7 - i] =
889 (char)((uint8_t) 0x30 +
892 ae->un.HardwareVersion[7 - i] =
893 (char)((uint8_t) 0x61 +
898 size += FOURBYTES + 8;
900 /* #7 HBA attribute entry */
901 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
902 ae->ad.bits.AttrType = be16_to_cpu(DRIVER_VERSION);
903 strcpy(ae->un.DriverVersion, lpfc_release_version);
904 len = strlen(ae->un.DriverVersion);
905 len += (len & 3) ? (4 - (len & 3)) : 4;
906 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
908 size += FOURBYTES + len;
910 /* #8 HBA attribute entry */
911 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
912 ae->ad.bits.AttrType = be16_to_cpu(OPTION_ROM_VERSION);
913 strcpy(ae->un.OptionROMVersion, phba->OptionROMVersion);
914 len = strlen(ae->un.OptionROMVersion);
915 len += (len & 3) ? (4 - (len & 3)) : 4;
916 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
918 size += FOURBYTES + len;
920 /* #9 HBA attribute entry */
921 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
922 ae->ad.bits.AttrType = be16_to_cpu(FIRMWARE_VERSION);
923 lpfc_decode_firmware_rev(phba, ae->un.FirmwareVersion,
925 len = strlen(ae->un.FirmwareVersion);
926 len += (len & 3) ? (4 - (len & 3)) : 4;
927 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
929 size += FOURBYTES + len;
931 /* #10 HBA attribute entry */
932 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
933 ae->ad.bits.AttrType = be16_to_cpu(OS_NAME_VERSION);
934 sprintf(ae->un.OsNameVersion, "%s %s %s",
935 system_utsname.sysname, system_utsname.release,
936 system_utsname.version);
937 len = strlen(ae->un.OsNameVersion);
938 len += (len & 3) ? (4 - (len & 3)) : 4;
939 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
941 size += FOURBYTES + len;
943 /* #11 HBA attribute entry */
944 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
945 ae->ad.bits.AttrType = be16_to_cpu(MAX_CT_PAYLOAD_LEN);
946 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
947 ae->un.MaxCTPayloadLen = (65 * 4096);
949 size += FOURBYTES + 4;
951 ab->EntryCnt = be32_to_cpu(ab->EntryCnt);
953 size = GID_REQUEST_SZ - 4 + size;
960 struct serv_parm *hsp;
965 CtReq->CommandResponse.bits.CmdRsp =
966 be16_to_cpu(SLI_MGMT_RPA);
967 CtReq->CommandResponse.bits.Size = 0;
968 pab = (REG_PORT_ATTRIBUTE *) & CtReq->un.PortID;
969 size = sizeof (struct lpfc_name) + FOURBYTES;
970 memcpy((uint8_t *) & pab->PortName,
971 (uint8_t *) & phba->fc_sparam.portName,
972 sizeof (struct lpfc_name));
973 pab->ab.EntryCnt = 0;
975 /* #1 Port attribute entry */
976 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
977 ae->ad.bits.AttrType = be16_to_cpu(SUPPORTED_FC4_TYPES);
978 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 32);
979 ae->un.SupportFC4Types[2] = 1;
980 ae->un.SupportFC4Types[7] = 1;
982 size += FOURBYTES + 32;
984 /* #2 Port attribute entry */
985 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
986 ae->ad.bits.AttrType = be16_to_cpu(SUPPORTED_SPEED);
987 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
988 if (FC_JEDEC_ID(vp->rev.biuRev) == VIPER_JEDEC_ID)
989 ae->un.SupportSpeed = HBA_PORTSPEED_10GBIT;
990 else if (FC_JEDEC_ID(vp->rev.biuRev) == HELIOS_JEDEC_ID)
991 ae->un.SupportSpeed = HBA_PORTSPEED_4GBIT;
992 else if ((FC_JEDEC_ID(vp->rev.biuRev) ==
994 || (FC_JEDEC_ID(vp->rev.biuRev) ==
996 || (FC_JEDEC_ID(vp->rev.biuRev) ==
998 ae->un.SupportSpeed = HBA_PORTSPEED_2GBIT;
1000 ae->un.SupportSpeed = HBA_PORTSPEED_1GBIT;
1002 size += FOURBYTES + 4;
1004 /* #3 Port attribute entry */
1005 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
1006 ae->ad.bits.AttrType = be16_to_cpu(PORT_SPEED);
1007 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
1008 switch(phba->fc_linkspeed) {
1010 ae->un.PortSpeed = HBA_PORTSPEED_1GBIT;
1013 ae->un.PortSpeed = HBA_PORTSPEED_2GBIT;
1016 ae->un.PortSpeed = HBA_PORTSPEED_4GBIT;
1020 HBA_PORTSPEED_UNKNOWN;
1024 size += FOURBYTES + 4;
1026 /* #4 Port attribute entry */
1027 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
1028 ae->ad.bits.AttrType = be16_to_cpu(MAX_FRAME_SIZE);
1029 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
1030 hsp = (struct serv_parm *) & phba->fc_sparam;
1031 ae->un.MaxFrameSize =
1032 (((uint32_t) hsp->cmn.
1033 bbRcvSizeMsb) << 8) | (uint32_t) hsp->cmn.
1036 size += FOURBYTES + 4;
1038 /* #5 Port attribute entry */
1039 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
1040 ae->ad.bits.AttrType = be16_to_cpu(OS_DEVICE_NAME);
1041 strcpy((char *)ae->un.OsDeviceName, LPFC_DRIVER_NAME);
1042 len = strlen((char *)ae->un.OsDeviceName);
1043 len += (len & 3) ? (4 - (len & 3)) : 4;
1044 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1046 size += FOURBYTES + len;
1048 if (phba->cfg_fdmi_on == 2) {
1049 /* #6 Port attribute entry */
1050 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab +
1052 ae->ad.bits.AttrType = be16_to_cpu(HOST_NAME);
1053 sprintf(ae->un.HostName, "%s",
1054 system_utsname.nodename);
1055 len = strlen(ae->un.HostName);
1056 len += (len & 3) ? (4 - (len & 3)) : 4;
1057 ae->ad.bits.AttrLen =
1058 be16_to_cpu(FOURBYTES + len);
1060 size += FOURBYTES + len;
1063 pab->ab.EntryCnt = be32_to_cpu(pab->ab.EntryCnt);
1065 size = GID_REQUEST_SZ - 4 + size;
1070 CtReq->CommandResponse.bits.CmdRsp = be16_to_cpu(SLI_MGMT_DHBA);
1071 CtReq->CommandResponse.bits.Size = 0;
1072 pe = (PORT_ENTRY *) & CtReq->un.PortID;
1073 memcpy((uint8_t *) & pe->PortName,
1074 (uint8_t *) & phba->fc_sparam.portName,
1075 sizeof (struct lpfc_name));
1076 size = GID_REQUEST_SZ - 4 + sizeof (struct lpfc_name);
1080 CtReq->CommandResponse.bits.CmdRsp = be16_to_cpu(SLI_MGMT_DPRT);
1081 CtReq->CommandResponse.bits.Size = 0;
1082 pe = (PORT_ENTRY *) & CtReq->un.PortID;
1083 memcpy((uint8_t *) & pe->PortName,
1084 (uint8_t *) & phba->fc_sparam.portName,
1085 sizeof (struct lpfc_name));
1086 size = GID_REQUEST_SZ - 4 + sizeof (struct lpfc_name);
1090 bpl = (struct ulp_bde64 *) bmp->virt;
1091 bpl->addrHigh = le32_to_cpu( putPaddrHigh(mp->phys) );
1092 bpl->addrLow = le32_to_cpu( putPaddrLow(mp->phys) );
1093 bpl->tus.f.bdeFlags = 0;
1094 bpl->tus.f.bdeSize = size;
1095 bpl->tus.w = le32_to_cpu(bpl->tus.w);
1097 cmpl = lpfc_cmpl_ct_cmd_fdmi;
1099 if (!lpfc_ct_cmd(phba, mp, bmp, ndlp, cmpl, FC_MAX_NS_RSP))
1102 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
1105 fdmi_cmd_free_mpvirt:
1106 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1110 /* Issue FDMI request failed */
1111 lpfc_printf_log(phba,
1114 "%d:0244 Issue FDMI request failed Data: x%x\n",
1121 lpfc_fdmi_tmo(unsigned long ptr)
1123 struct lpfc_hba *phba = (struct lpfc_hba *)ptr;
1124 unsigned long iflag;
1126 spin_lock_irqsave(phba->host->host_lock, iflag);
1127 if (!(phba->work_hba_events & WORKER_FDMI_TMO)) {
1128 phba->work_hba_events |= WORKER_FDMI_TMO;
1129 if (phba->work_wait)
1130 wake_up(phba->work_wait);
1132 spin_unlock_irqrestore(phba->host->host_lock,iflag);
1136 lpfc_fdmi_tmo_handler(struct lpfc_hba *phba)
1138 struct lpfc_nodelist *ndlp;
1140 spin_lock_irq(phba->host->host_lock);
1141 if (!(phba->work_hba_events & WORKER_FDMI_TMO)) {
1142 spin_unlock_irq(phba->host->host_lock);
1145 ndlp = lpfc_findnode_did(phba, NLP_SEARCH_ALL, FDMI_DID);
1147 if (system_utsname.nodename[0] != '\0') {
1148 lpfc_fdmi_cmd(phba, ndlp, SLI_MGMT_DHBA);
1150 mod_timer(&phba->fc_fdmitmo, jiffies + HZ * 60);
1153 spin_unlock_irq(phba->host->host_lock);
1159 lpfc_decode_firmware_rev(struct lpfc_hba * phba, char *fwrevision, int flag)
1161 struct lpfc_sli *psli = &phba->sli;
1162 lpfc_vpd_t *vp = &phba->vpd;
1163 uint32_t b1, b2, b3, b4, i, rev;
1165 uint32_t *ptr, str[4];
1169 if (psli->sli_flag & LPFC_SLI2_ACTIVE)
1170 rev = vp->rev.sli2FwRev;
1172 rev = vp->rev.sli1FwRev;
1174 b1 = (rev & 0x0000f000) >> 12;
1175 b2 = (rev & 0x00000f00) >> 8;
1176 b3 = (rev & 0x000000c0) >> 6;
1177 b4 = (rev & 0x00000030) >> 4;
1193 b4 = (rev & 0x0000000f);
1195 if (psli->sli_flag & LPFC_SLI2_ACTIVE)
1196 fwname = vp->rev.sli2FwName;
1198 fwname = vp->rev.sli1FwName;
1200 for (i = 0; i < 16; i++)
1201 if (fwname[i] == 0x20)
1204 ptr = (uint32_t*)fwname;
1206 for (i = 0; i < 3; i++)
1207 str[i] = be32_to_cpu(*ptr++);
1211 sprintf(fwrevision, "%d.%d%d (%s)",
1212 b1, b2, b3, (char *)str);
1214 sprintf(fwrevision, "%d.%d%d", b1,
1218 sprintf(fwrevision, "%d.%d%d%c%d (%s)",
1222 sprintf(fwrevision, "%d.%d%d%c%d",
1226 rev = vp->rev.smFwRev;
1228 b1 = (rev & 0xff000000) >> 24;
1229 b2 = (rev & 0x00f00000) >> 20;
1230 b3 = (rev & 0x000f0000) >> 16;
1231 c = (rev & 0x0000ff00) >> 8;
1232 b4 = (rev & 0x000000ff);
1235 sprintf(fwrevision, "%d.%d%d%c%d ", b1,
1238 sprintf(fwrevision, "%d.%d%d%c%d ", b1,