1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Enterprise Fibre Channel Host Bus Adapters. *
4 * Refer to the README file included with this package for *
5 * driver version and adapter support. *
6 * Copyright (C) 2004 Emulex Corporation. *
9 * This program is free software; you can redistribute it and/or *
10 * modify it under the terms of the GNU General Public License *
11 * as published by the Free Software Foundation; either version 2 *
12 * of the License, or (at your option) any later version. *
14 * This program is distributed in the hope that it will be useful, *
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
17 * GNU General Public License for more details, a copy of which *
18 * can be found in the file COPYING included with this package. *
19 *******************************************************************/
22 * $Id: lpfc_ct.c 1.143 2004/11/17 14:50:38EST sf_support Exp $
24 * Fibre Channel SCSI LAN Device Driver CT support
27 #include <linux/version.h>
28 #include <linux/blkdev.h>
29 #include <linux/dma-mapping.h>
30 #include <linux/pci.h>
31 #include <linux/spinlock.h>
32 #include <linux/utsname.h>
33 #include <scsi/scsi_device.h>
34 #include <scsi/scsi_host.h>
36 #include "lpfc_disc.h"
37 #include "lpfc_scsi.h"
39 #include "lpfc_crtn.h"
41 #include "lpfc_logmsg.h"
43 #include "lpfc_version.h"
46 #define HBA_PORTSPEED_UNKNOWN 0 /* Unknown - transceiver
47 * incapable of reporting */
48 #define HBA_PORTSPEED_1GBIT 1 /* 1 GBit/sec */
49 #define HBA_PORTSPEED_2GBIT 2 /* 2 GBit/sec */
50 #define HBA_PORTSPEED_4GBIT 8 /* 4 GBit/sec */
51 #define HBA_PORTSPEED_8GBIT 16 /* 8 GBit/sec */
52 #define HBA_PORTSPEED_10GBIT 4 /* 10 GBit/sec */
53 #define HBA_PORTSPEED_NOT_NEGOTIATED 5 /* Speed not established */
58 static char *lpfc_release_version = LPFC_DRIVER_VERSION;
64 lpfc_ct_unsol_event(struct lpfc_hba * phba,
65 struct lpfc_sli_ring * pring, struct lpfc_iocbq * piocbq)
68 struct lpfc_iocbq *next_piocbq;
69 struct lpfc_dmabuf *pmbuf = NULL;
70 struct lpfc_dmabuf *matp, *next_matp;
71 uint32_t ctx = 0, count = 0;
72 IOCB_t *icmd = &piocbq->iocb;
73 int i, status, go_exit = 0;
74 struct list_head head;
79 list_add_tail(&head, &piocbq->list);
80 list_for_each_entry_safe(piocbq, next_piocbq, &head, list) {
83 ctx = (uint32_t) (icmd->ulpContext);
84 if (icmd->ulpStatus) {
85 if ((icmd->ulpStatus == IOSTAT_LOCAL_REJECT) &&
86 ((icmd->un.ulpWord[4] & 0xff)
87 == IOERR_RCV_BUFFER_WAITING)) {
88 phba->fc_stat.NoRcvBuf++;
89 lpfc_post_buffer(phba, pring, 0, 1);
92 goto ct_unsol_event_exit_piocbq;
95 if (icmd->ulpBdeCount == 0)
98 for (i = 0; i < icmd->ulpBdeCount; i++) {
99 matp = lpfc_sli_ringpostbuf_get(phba, pring,
107 /* Insert lpfc log message here */
109 goto ct_unsol_event_exit_piocbq;
112 /* Typically for Unsolicited CT requests */
115 INIT_LIST_HEAD(&pmbuf->list);
117 list_add_tail(&matp->list, &pmbuf->list);
119 count += icmd->un.cont64[i].tus.f.bdeSize;
122 lpfc_post_buffer(phba, pring, i, 1);
123 icmd->ulpBdeCount = 0;
125 ct_unsol_event_exit_piocbq:
128 * if not early-exiting and there is pmbuf,
129 * then do FC_REG_CT_EVENT for libdfc
131 if (!go_exit && pmbuf) {
132 status = lpfc_put_event(phba, FC_REG_CT_EVENT, ctx,
133 (void *)pmbuf, count, 0);
135 /* Need to free IOCB buffer ? */
139 list_for_each_entry_safe(matp, next_matp, &pmbuf->list, list) {
140 lpfc_mbuf_free(phba, matp->virt, matp->phys);
141 list_del(&matp->list);
144 lpfc_mbuf_free(phba, pmbuf->virt, pmbuf->phys);
151 lpfc_free_ct_rsp(struct lpfc_hba * phba, struct lpfc_dmabuf * mlist)
153 struct lpfc_dmabuf *mlast, *next_mlast;
155 list_for_each_entry_safe(mlast, next_mlast, &mlist->list, list) {
156 lpfc_mbuf_free(phba, mlast->virt, mlast->phys);
157 list_del(&mlast->list);
160 lpfc_mbuf_free(phba, mlist->virt, mlist->phys);
165 static struct lpfc_dmabuf *
166 lpfc_alloc_ct_rsp(struct lpfc_hba * phba, int cmdcode, struct ulp_bde64 * bpl,
167 uint32_t size, int *entries)
169 struct lpfc_dmabuf *mlist = NULL;
170 struct lpfc_dmabuf *mp;
173 /* We get chucks of FCELSSIZE */
174 cnt = size > FCELSSIZE ? FCELSSIZE: size;
177 /* Allocate buffer for rsp payload */
178 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_ATOMIC);
181 lpfc_free_ct_rsp(phba, mlist);
185 INIT_LIST_HEAD(&mp->list);
187 if (cmdcode == be16_to_cpu(SLI_CTNS_GID_FT))
188 mp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(mp->phys));
190 mp->virt = lpfc_mbuf_alloc(phba, 0, &(mp->phys));
194 lpfc_free_ct_rsp(phba, mlist);
198 /* Queue it to a linked list */
202 list_add_tail(&mp->list, &mlist->list);
204 bpl->tus.f.bdeFlags = BUFF_USE_RCV;
205 /* build buffer ptr list for IOCB */
206 bpl->addrLow = le32_to_cpu( putPaddrLow(mp->phys) );
207 bpl->addrHigh = le32_to_cpu( putPaddrHigh(mp->phys) );
208 bpl->tus.f.bdeSize = (uint16_t) cnt;
209 bpl->tus.w = le32_to_cpu(bpl->tus.w);
221 lpfc_gen_req(struct lpfc_hba *phba, struct lpfc_dmabuf *bmp,
222 struct lpfc_dmabuf *inp, struct lpfc_dmabuf *outp,
223 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
224 struct lpfc_iocbq *),
225 struct lpfc_nodelist *ndlp, uint32_t usr_flg, uint32_t num_entry,
229 struct lpfc_sli *psli = &phba->sli;
230 struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
232 struct lpfc_iocbq *geniocb;
234 /* Allocate buffer for command iocb */
235 geniocb = mempool_alloc(phba->iocb_mem_pool, GFP_ATOMIC);
239 memset(geniocb, 0, sizeof (struct lpfc_iocbq));
240 icmd = &geniocb->iocb;
242 icmd->un.genreq64.bdl.ulpIoTag32 = 0;
243 icmd->un.genreq64.bdl.addrHigh = putPaddrHigh(bmp->phys);
244 icmd->un.genreq64.bdl.addrLow = putPaddrLow(bmp->phys);
245 icmd->un.genreq64.bdl.bdeFlags = BUFF_TYPE_BDL;
246 icmd->un.genreq64.bdl.bdeSize = (num_entry * sizeof (struct ulp_bde64));
249 geniocb->context3 = NULL;
251 geniocb->context3 = (uint8_t *) bmp;
253 /* Save for completion so we can release these resources */
254 geniocb->context1 = (uint8_t *) inp;
255 geniocb->context2 = (uint8_t *) outp;
257 /* Fill in payload, bp points to frame payload */
258 icmd->ulpCommand = CMD_GEN_REQUEST64_CR;
260 pci_dma_sync_single_for_device(phba->pcidev, bmp->phys,
261 LPFC_BPL_SIZE, PCI_DMA_TODEVICE);
263 icmd->ulpIoTag = lpfc_sli_next_iotag(phba, pring);
265 /* Fill in rest of iocb */
266 icmd->un.genreq64.w5.hcsw.Fctl = (SI | LA);
267 icmd->un.genreq64.w5.hcsw.Dfctl = 0;
268 icmd->un.genreq64.w5.hcsw.Rctl = FC_UNSOL_CTL;
269 icmd->un.genreq64.w5.hcsw.Type = FC_COMMON_TRANSPORT_ULP;
272 tmo = (2 * phba->fc_ratov) + 1;
273 icmd->ulpTimeout = tmo;
274 icmd->ulpBdeCount = 1;
276 icmd->ulpClass = CLASS3;
277 icmd->ulpContext = ndlp->nlp_rpi;
279 /* Issue GEN REQ IOCB for NPORT <did> */
280 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
281 "%d:0119 Issue GEN REQ IOCB for NPORT x%x "
282 "Data: x%x x%x\n", phba->brd_no, icmd->un.ulpWord[5],
283 icmd->ulpIoTag, phba->hba_state);
284 geniocb->iocb_cmpl = cmpl;
285 geniocb->drvrTimeout = icmd->ulpTimeout + LPFC_DRVR_TIMEOUT;
286 if (lpfc_sli_issue_iocb(phba, pring, geniocb, 0) == IOCB_ERROR) {
287 mempool_free( geniocb, phba->iocb_mem_pool);
295 lpfc_ct_cmd(struct lpfc_hba *phba, struct lpfc_dmabuf *inmp,
296 struct lpfc_dmabuf *bmp, struct lpfc_nodelist *ndlp,
297 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
298 struct lpfc_iocbq *),
301 struct ulp_bde64 *bpl = (struct ulp_bde64 *) bmp->virt;
302 struct lpfc_dmabuf *outmp;
304 int cmdcode = ((struct lpfc_sli_ct_request *) inmp->virt)->
305 CommandResponse.bits.CmdRsp;
307 bpl++; /* Skip past ct request */
309 /* Put buffer(s) for ct rsp in bpl */
310 outmp = lpfc_alloc_ct_rsp(phba, cmdcode, bpl, rsp_size, &cnt);
314 status = lpfc_gen_req(phba, bmp, inmp, outmp, cmpl, ndlp, 0,
317 lpfc_free_ct_rsp(phba, outmp);
324 lpfc_ns_rsp(struct lpfc_hba * phba, struct lpfc_dmabuf * mp, uint32_t Size)
326 struct lpfc_sli_ct_request *Response =
327 (struct lpfc_sli_ct_request *) mp->virt;
328 struct lpfc_nodelist *ndlp = NULL;
329 struct lpfc_dmabuf *mlast, *next_mp;
330 uint32_t *ctptr = (uint32_t *) & Response->un.gid.PortType;
334 struct list_head head;
336 lpfc_set_disctmo(phba);
338 Cnt = Size > FCELSSIZE ? FCELSSIZE : Size;
340 list_add_tail(&head, &mp->list);
341 list_for_each_entry_safe(mp, next_mp, &head, list) {
343 pci_dma_sync_single_for_cpu(phba->pcidev, mp->phys,
344 LPFC_BPL_SIZE, PCI_DMA_FROMDEVICE);
349 ctptr = (uint32_t *) mlast->virt;
351 Cnt -= 16; /* subtract length of CT header */
353 /* Loop through entire NameServer list of DIDs */
356 /* Get next DID from NameServer List */
358 Did = ((be32_to_cpu(CTentry)) & Mask_DID);
361 if (Did != phba->fc_myDID) {
362 /* Check for rscn processing or not */
363 ndlp = lpfc_setup_disc_node(phba, Did);
365 /* Mark all node table entries that are in the
369 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
370 "%d:0238 Process x%x NameServer"
371 " Rsp Data: x%x x%x x%x\n",
375 phba->fc_rscn_id_cnt);
378 lpfc_printf_log(phba,
381 "%d:0239 Skip x%x NameServer "
382 "Rsp Data: x%x x%x x%x\n",
384 Did, Size, phba->fc_flag,
385 phba->fc_rscn_id_cnt);
388 if (CTentry & (be32_to_cpu(SLI_CT_LAST_ENTRY)))
390 Cnt -= sizeof (uint32_t);
399 /* Here we are finished in the case RSCN */
400 if (phba->hba_state == LPFC_HBA_READY) {
401 lpfc_els_flush_rscn(phba);
402 phba->fc_flag |= FC_RSCN_MODE; /* we are still in RSCN mode */
411 lpfc_cmpl_ct_cmd_gid_ft(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
412 struct lpfc_iocbq * rspiocb)
415 struct lpfc_sli *psli;
416 struct lpfc_dmabuf *bmp;
417 struct lpfc_dmabuf *inp;
418 struct lpfc_dmabuf *outp;
419 struct lpfc_nodelist *ndlp;
420 struct lpfc_sli_ct_request *CTrsp;
423 /* we pass cmdiocb to state machine which needs rspiocb as well */
424 cmdiocb->context_un.rsp_iocb = rspiocb;
426 inp = (struct lpfc_dmabuf *) cmdiocb->context1;
427 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
428 bmp = (struct lpfc_dmabuf *) cmdiocb->context3;
430 irsp = &rspiocb->iocb;
431 if (irsp->ulpStatus) {
432 if((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
433 ((irsp->un.ulpWord[4] == IOERR_SLI_DOWN) ||
434 (irsp->un.ulpWord[4] == IOERR_SLI_ABORTED))) {
438 /* Check for retry */
439 if (phba->fc_ns_retry < LPFC_MAX_NS_RETRY) {
441 /* CT command is being retried */
443 lpfc_findnode_did(phba, NLP_SEARCH_UNMAPPED,
446 if (lpfc_ns_cmd(phba, ndlp, SLI_CTNS_GID_FT) ==
453 /* Good status, continue checking */
454 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
455 if (CTrsp->CommandResponse.bits.CmdRsp ==
456 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC)) {
457 lpfc_ns_rsp(phba, outp,
458 (uint32_t) (irsp->un.genreq64.bdl.bdeSize));
459 } else if (CTrsp->CommandResponse.bits.CmdRsp ==
460 be16_to_cpu(SLI_CT_RESPONSE_FS_RJT)) {
461 /* NameServer Rsp Error */
462 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
463 "%d:0240 NameServer Rsp Error "
464 "Data: x%x x%x x%x x%x\n",
466 CTrsp->CommandResponse.bits.CmdRsp,
467 (uint32_t) CTrsp->ReasonCode,
468 (uint32_t) CTrsp->Explanation,
471 /* NameServer Rsp Error */
472 lpfc_printf_log(phba,
475 "%d:0241 NameServer Rsp Error "
476 "Data: x%x x%x x%x x%x\n",
478 CTrsp->CommandResponse.bits.CmdRsp,
479 (uint32_t) CTrsp->ReasonCode,
480 (uint32_t) CTrsp->Explanation,
484 /* Link up / RSCN discovery */
485 lpfc_disc_start(phba);
487 lpfc_free_ct_rsp(phba, outp);
488 lpfc_mbuf_free(phba, inp->virt, inp->phys);
489 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
492 mempool_free( cmdiocb, phba->iocb_mem_pool);
497 lpfc_cmpl_ct_cmd_rft_id(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
498 struct lpfc_iocbq * rspiocb)
500 struct lpfc_sli *psli;
501 struct lpfc_dmabuf *bmp;
502 struct lpfc_dmabuf *inp;
503 struct lpfc_dmabuf *outp;
505 struct lpfc_sli_ct_request *CTrsp;
508 /* we pass cmdiocb to state machine which needs rspiocb as well */
509 cmdiocb->context_un.rsp_iocb = rspiocb;
511 inp = (struct lpfc_dmabuf *) cmdiocb->context1;
512 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
513 bmp = (struct lpfc_dmabuf *) cmdiocb->context3;
514 irsp = &rspiocb->iocb;
516 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
518 /* RFT request completes status <ulpStatus> CmdRsp <CmdRsp> */
519 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
520 "%d:0209 RFT request completes ulpStatus x%x "
521 "CmdRsp x%x\n", phba->brd_no, irsp->ulpStatus,
522 CTrsp->CommandResponse.bits.CmdRsp);
524 lpfc_free_ct_rsp(phba, outp);
525 lpfc_mbuf_free(phba, inp->virt, inp->phys);
526 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
529 mempool_free( cmdiocb, phba->iocb_mem_pool);
534 lpfc_cmpl_ct_cmd_rnn_id(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
535 struct lpfc_iocbq * rspiocb)
537 lpfc_cmpl_ct_cmd_rft_id(phba, cmdiocb, rspiocb);
542 lpfc_cmpl_ct_cmd_rsnn_nn(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
543 struct lpfc_iocbq * rspiocb)
545 lpfc_cmpl_ct_cmd_rft_id(phba, cmdiocb, rspiocb);
550 lpfc_get_hba_sym_node_name(struct lpfc_hba * phba, uint8_t * symbp)
555 lpfc_decode_firmware_rev(phba, fwrev, 0);
556 lpfc_get_hba_model_desc(phba, buf, NULL);
557 sprintf(symbp, "Emulex %s FV%s DV%s", buf, fwrev, lpfc_release_version);
563 * Issue Cmd to NameServer
568 lpfc_ns_cmd(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp, int cmdcode)
570 struct lpfc_dmabuf *mp, *bmp;
571 struct lpfc_sli_ct_request *CtReq;
572 struct ulp_bde64 *bpl;
573 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
574 struct lpfc_iocbq *) = NULL;
575 uint32_t rsp_size = 1024;
577 /* fill in BDEs for command */
578 /* Allocate buffer for command payload */
579 mp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_ATOMIC);
583 INIT_LIST_HEAD(&mp->list);
584 mp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(mp->phys));
588 /* Allocate buffer for Buffer ptr list */
589 bmp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_ATOMIC);
591 goto ns_cmd_free_mpvirt;
593 INIT_LIST_HEAD(&bmp->list);
594 bmp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(bmp->phys));
596 goto ns_cmd_free_bmp;
599 lpfc_printf_log(phba,
602 "%d:0236 NameServer Req Data: x%x x%x x%x\n",
603 phba->brd_no, cmdcode, phba->fc_flag,
604 phba->fc_rscn_id_cnt);
606 bpl = (struct ulp_bde64 *) bmp->virt;
607 memset(bpl, 0, sizeof(struct ulp_bde64));
608 bpl->addrHigh = le32_to_cpu( putPaddrHigh(mp->phys) );
609 bpl->addrLow = le32_to_cpu( putPaddrLow(mp->phys) );
610 bpl->tus.f.bdeFlags = 0;
611 if (cmdcode == SLI_CTNS_GID_FT)
612 bpl->tus.f.bdeSize = GID_REQUEST_SZ;
613 else if (cmdcode == SLI_CTNS_RFT_ID)
614 bpl->tus.f.bdeSize = RFT_REQUEST_SZ;
615 else if (cmdcode == SLI_CTNS_RNN_ID)
616 bpl->tus.f.bdeSize = RNN_REQUEST_SZ;
617 else if (cmdcode == SLI_CTNS_RSNN_NN)
618 bpl->tus.f.bdeSize = RSNN_REQUEST_SZ;
620 bpl->tus.f.bdeSize = 0;
621 bpl->tus.w = le32_to_cpu(bpl->tus.w);
623 CtReq = (struct lpfc_sli_ct_request *) mp->virt;
624 memset(CtReq, 0, sizeof (struct lpfc_sli_ct_request));
625 CtReq->RevisionId.bits.Revision = SLI_CT_REVISION;
626 CtReq->RevisionId.bits.InId = 0;
627 CtReq->FsType = SLI_CT_DIRECTORY_SERVICE;
628 CtReq->FsSubType = SLI_CT_DIRECTORY_NAME_SERVER;
629 CtReq->CommandResponse.bits.Size = 0;
631 case SLI_CTNS_GID_FT:
632 CtReq->CommandResponse.bits.CmdRsp =
633 be16_to_cpu(SLI_CTNS_GID_FT);
634 CtReq->un.gid.Fc4Type = SLI_CTPT_FCP;
635 if (phba->hba_state < LPFC_HBA_READY)
636 phba->hba_state = LPFC_NS_QRY;
637 lpfc_set_disctmo(phba);
638 cmpl = lpfc_cmpl_ct_cmd_gid_ft;
639 rsp_size = FC_MAX_NS_RSP;
642 case SLI_CTNS_RFT_ID:
643 CtReq->CommandResponse.bits.CmdRsp =
644 be16_to_cpu(SLI_CTNS_RFT_ID);
645 CtReq->un.rft.PortId = be32_to_cpu(phba->fc_myDID);
646 CtReq->un.rft.fcpReg = 1;
647 cmpl = lpfc_cmpl_ct_cmd_rft_id;
650 case SLI_CTNS_RNN_ID:
651 CtReq->CommandResponse.bits.CmdRsp =
652 be16_to_cpu(SLI_CTNS_RNN_ID);
653 CtReq->un.rnn.PortId = be32_to_cpu(phba->fc_myDID);
654 memcpy(CtReq->un.rnn.wwnn, &phba->fc_nodename,
655 sizeof (struct lpfc_name));
656 cmpl = lpfc_cmpl_ct_cmd_rnn_id;
659 case SLI_CTNS_RSNN_NN:
660 CtReq->CommandResponse.bits.CmdRsp =
661 be16_to_cpu(SLI_CTNS_RSNN_NN);
662 memcpy(CtReq->un.rsnn.wwnn, &phba->fc_nodename,
663 sizeof (struct lpfc_name));
664 lpfc_get_hba_sym_node_name(phba, CtReq->un.rsnn.symbname);
665 CtReq->un.rsnn.len = strlen(CtReq->un.rsnn.symbname);
666 cmpl = lpfc_cmpl_ct_cmd_rsnn_nn;
670 if (!lpfc_ct_cmd(phba, mp, bmp, ndlp, cmpl, rsp_size))
671 /* On success, The cmpl function will free the buffers */
674 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
678 lpfc_mbuf_free(phba, mp->virt, mp->phys);
686 lpfc_cmpl_ct_cmd_fdmi(struct lpfc_hba * phba,
687 struct lpfc_iocbq * cmdiocb, struct lpfc_iocbq * rspiocb)
689 struct lpfc_dmabuf *bmp = cmdiocb->context3;
690 struct lpfc_dmabuf *inp = cmdiocb->context1;
691 struct lpfc_dmabuf *outp = cmdiocb->context2;
692 struct lpfc_sli_ct_request *CTrsp = outp->virt;
693 struct lpfc_sli_ct_request *CTcmd = inp->virt;
694 struct lpfc_nodelist *ndlp;
695 uint16_t fdmi_cmd = CTcmd->CommandResponse.bits.CmdRsp;
696 uint16_t fdmi_rsp = CTrsp->CommandResponse.bits.CmdRsp;
698 ndlp = lpfc_findnode_did(phba, NLP_SEARCH_ALL, FDMI_DID);
699 if (fdmi_rsp == be16_to_cpu(SLI_CT_RESPONSE_FS_RJT)) {
700 /* FDMI rsp failed */
701 lpfc_printf_log(phba,
704 "%d:0220 FDMI rsp failed Data: x%x\n",
706 be16_to_cpu(fdmi_cmd));
709 switch (be16_to_cpu(fdmi_cmd)) {
711 lpfc_fdmi_cmd(phba, ndlp, SLI_MGMT_RPA);
718 lpfc_fdmi_cmd(phba, ndlp, SLI_MGMT_DPRT);
722 lpfc_fdmi_cmd(phba, ndlp, SLI_MGMT_RHBA);
726 lpfc_free_ct_rsp(phba, outp);
727 lpfc_mbuf_free(phba, inp->virt, inp->phys);
728 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
731 mempool_free(cmdiocb, phba->iocb_mem_pool);
735 lpfc_fdmi_cmd(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp, int cmdcode)
737 struct lpfc_dmabuf *mp, *bmp;
738 struct lpfc_sli_ct_request *CtReq;
739 struct ulp_bde64 *bpl;
743 REG_PORT_ATTRIBUTE *pab;
746 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
747 struct lpfc_iocbq *);
750 /* fill in BDEs for command */
751 /* Allocate buffer for command payload */
752 mp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_ATOMIC);
756 mp->virt = lpfc_mbuf_alloc(phba, 0, &(mp->phys));
758 goto fdmi_cmd_free_mp;
760 /* Allocate buffer for Buffer ptr list */
761 bmp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_ATOMIC);
763 goto fdmi_cmd_free_mpvirt;
765 bmp->virt = lpfc_mbuf_alloc(phba, 0, &(bmp->phys));
767 goto fdmi_cmd_free_bmp;
769 INIT_LIST_HEAD(&mp->list);
770 INIT_LIST_HEAD(&bmp->list);
773 lpfc_printf_log(phba,
776 "%d:0218 FDMI Request Data: x%x x%x x%x\n",
778 phba->fc_flag, phba->hba_state, cmdcode);
780 CtReq = (struct lpfc_sli_ct_request *) mp->virt;
782 memset(CtReq, 0, sizeof(struct lpfc_sli_ct_request));
783 CtReq->RevisionId.bits.Revision = SLI_CT_REVISION;
784 CtReq->RevisionId.bits.InId = 0;
786 CtReq->FsType = SLI_CT_MANAGEMENT_SERVICE;
787 CtReq->FsSubType = SLI_CT_FDMI_Subtypes;
793 lpfc_vpd_t *vp = &phba->vpd;
797 CtReq->CommandResponse.bits.CmdRsp =
798 be16_to_cpu(SLI_MGMT_RHBA);
799 CtReq->CommandResponse.bits.Size = 0;
800 rh = (REG_HBA *) & CtReq->un.PortID;
801 memcpy(&rh->hi.PortName, &phba->fc_sparam.portName,
802 sizeof (struct lpfc_name));
803 /* One entry (port) per adapter */
804 rh->rpl.EntryCnt = be32_to_cpu(1);
805 memcpy(&rh->rpl.pe, &phba->fc_sparam.portName,
806 sizeof (struct lpfc_name));
808 /* point to the HBA attribute block */
809 size = 2 * sizeof (struct lpfc_name) + FOURBYTES;
810 ab = (ATTRIBUTE_BLOCK *) ((uint8_t *) rh + size);
813 /* Point to the beginning of the first HBA attribute
815 /* #1 HBA attribute entry */
817 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
818 ae->ad.bits.AttrType = be16_to_cpu(NODE_NAME);
819 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES
820 + sizeof (struct lpfc_name));
821 memcpy(&ae->un.NodeName, &phba->fc_sparam.nodeName,
822 sizeof (struct lpfc_name));
824 size += FOURBYTES + sizeof (struct lpfc_name);
826 /* #2 HBA attribute entry */
827 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
828 ae->ad.bits.AttrType = be16_to_cpu(MANUFACTURER);
829 strcpy(ae->un.Manufacturer, "Emulex Corporation");
830 len = strlen(ae->un.Manufacturer);
831 len += (len & 3) ? (4 - (len & 3)) : 4;
832 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
834 size += FOURBYTES + len;
836 /* #3 HBA attribute entry */
837 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
838 ae->ad.bits.AttrType = be16_to_cpu(SERIAL_NUMBER);
839 strcpy(ae->un.SerialNumber, phba->SerialNumber);
840 len = strlen(ae->un.SerialNumber);
841 len += (len & 3) ? (4 - (len & 3)) : 4;
842 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
844 size += FOURBYTES + len;
846 /* #4 HBA attribute entry */
847 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
848 ae->ad.bits.AttrType = be16_to_cpu(MODEL);
849 lpfc_get_hba_model_desc(phba, ae->un.Model, NULL);
850 len = strlen(ae->un.Model);
851 len += (len & 3) ? (4 - (len & 3)) : 4;
852 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
854 size += FOURBYTES + len;
856 /* #5 HBA attribute entry */
857 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
858 ae->ad.bits.AttrType = be16_to_cpu(MODEL_DESCRIPTION);
859 lpfc_get_hba_model_desc(phba, NULL,
860 ae->un.ModelDescription);
861 len = strlen(ae->un.ModelDescription);
862 len += (len & 3) ? (4 - (len & 3)) : 4;
863 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
865 size += FOURBYTES + len;
867 /* #6 HBA attribute entry */
868 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
869 ae->ad.bits.AttrType = be16_to_cpu(HARDWARE_VERSION);
870 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 8);
871 /* Convert JEDEC ID to ascii for hardware version */
872 incr = vp->rev.biuRev;
873 for (i = 0; i < 8; i++) {
876 ae->un.HardwareVersion[7 - i] =
877 (char)((uint8_t) 0x30 +
880 ae->un.HardwareVersion[7 - i] =
881 (char)((uint8_t) 0x61 +
886 size += FOURBYTES + 8;
888 /* #7 HBA attribute entry */
889 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
890 ae->ad.bits.AttrType = be16_to_cpu(DRIVER_VERSION);
891 strcpy(ae->un.DriverVersion, lpfc_release_version);
892 len = strlen(ae->un.DriverVersion);
893 len += (len & 3) ? (4 - (len & 3)) : 4;
894 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
896 size += FOURBYTES + len;
898 /* #8 HBA attribute entry */
899 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
900 ae->ad.bits.AttrType = be16_to_cpu(OPTION_ROM_VERSION);
901 strcpy(ae->un.OptionROMVersion, phba->OptionROMVersion);
902 len = strlen(ae->un.OptionROMVersion);
903 len += (len & 3) ? (4 - (len & 3)) : 4;
904 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
906 size += FOURBYTES + len;
908 /* #9 HBA attribute entry */
909 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
910 ae->ad.bits.AttrType = be16_to_cpu(FIRMWARE_VERSION);
911 lpfc_decode_firmware_rev(phba, ae->un.FirmwareVersion,
913 len = strlen(ae->un.FirmwareVersion);
914 len += (len & 3) ? (4 - (len & 3)) : 4;
915 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
917 size += FOURBYTES + len;
919 /* #10 HBA attribute entry */
920 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
921 ae->ad.bits.AttrType = be16_to_cpu(OS_NAME_VERSION);
922 sprintf(ae->un.OsNameVersion, "%s %s %s",
923 system_utsname.sysname, system_utsname.release,
924 system_utsname.version);
925 len = strlen(ae->un.OsNameVersion);
926 len += (len & 3) ? (4 - (len & 3)) : 4;
927 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
929 size += FOURBYTES + len;
931 /* #11 HBA attribute entry */
932 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
933 ae->ad.bits.AttrType = be16_to_cpu(MAX_CT_PAYLOAD_LEN);
934 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
935 ae->un.MaxCTPayloadLen = (65 * 4096);
937 size += FOURBYTES + 4;
939 ab->EntryCnt = be32_to_cpu(ab->EntryCnt);
941 size = GID_REQUEST_SZ - 4 + size;
948 struct serv_parm *hsp;
953 CtReq->CommandResponse.bits.CmdRsp =
954 be16_to_cpu(SLI_MGMT_RPA);
955 CtReq->CommandResponse.bits.Size = 0;
956 pab = (REG_PORT_ATTRIBUTE *) & CtReq->un.PortID;
957 size = sizeof (struct lpfc_name) + FOURBYTES;
958 memcpy((uint8_t *) & pab->PortName,
959 (uint8_t *) & phba->fc_sparam.portName,
960 sizeof (struct lpfc_name));
961 pab->ab.EntryCnt = 0;
963 /* #1 Port attribute entry */
964 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
965 ae->ad.bits.AttrType = be16_to_cpu(SUPPORTED_FC4_TYPES);
966 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 32);
967 ae->un.SupportFC4Types[2] = 1;
968 ae->un.SupportFC4Types[7] = 1;
970 size += FOURBYTES + 32;
972 /* #2 Port attribute entry */
973 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
974 ae->ad.bits.AttrType = be16_to_cpu(SUPPORTED_SPEED);
975 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
976 if (FC_JEDEC_ID(vp->rev.biuRev) == VIPER_JEDEC_ID)
977 ae->un.SupportSpeed = HBA_PORTSPEED_10GBIT;
978 else if (FC_JEDEC_ID(vp->rev.biuRev) == HELIOS_JEDEC_ID)
979 ae->un.SupportSpeed = HBA_PORTSPEED_4GBIT;
980 else if ((FC_JEDEC_ID(vp->rev.biuRev) ==
982 || (FC_JEDEC_ID(vp->rev.biuRev) ==
984 || (FC_JEDEC_ID(vp->rev.biuRev) ==
986 ae->un.SupportSpeed = HBA_PORTSPEED_2GBIT;
988 ae->un.SupportSpeed = HBA_PORTSPEED_1GBIT;
990 size += FOURBYTES + 4;
992 /* #3 Port attribute entry */
993 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
994 ae->ad.bits.AttrType = be16_to_cpu(PORT_SPEED);
995 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
996 switch(phba->fc_linkspeed) {
998 ae->un.PortSpeed = HBA_PORTSPEED_1GBIT;
1001 ae->un.PortSpeed = HBA_PORTSPEED_2GBIT;
1004 ae->un.PortSpeed = HBA_PORTSPEED_4GBIT;
1008 HBA_PORTSPEED_UNKNOWN;
1012 size += FOURBYTES + 4;
1014 /* #4 Port attribute entry */
1015 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
1016 ae->ad.bits.AttrType = be16_to_cpu(MAX_FRAME_SIZE);
1017 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
1018 hsp = (struct serv_parm *) & phba->fc_sparam;
1019 ae->un.MaxFrameSize =
1020 (((uint32_t) hsp->cmn.
1021 bbRcvSizeMsb) << 8) | (uint32_t) hsp->cmn.
1024 size += FOURBYTES + 4;
1026 /* #5 Port attribute entry */
1027 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
1028 ae->ad.bits.AttrType = be16_to_cpu(OS_DEVICE_NAME);
1029 strcpy((char *)ae->un.OsDeviceName, LPFC_DRIVER_NAME);
1030 len = strlen((char *)ae->un.OsDeviceName);
1031 len += (len & 3) ? (4 - (len & 3)) : 4;
1032 ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
1034 size += FOURBYTES + len;
1036 if (phba->cfg_fdmi_on == 2) {
1037 /* #6 Port attribute entry */
1038 ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab +
1040 ae->ad.bits.AttrType = be16_to_cpu(HOST_NAME);
1041 sprintf(ae->un.HostName, "%s",
1042 system_utsname.nodename);
1043 len = strlen(ae->un.HostName);
1044 len += (len & 3) ? (4 - (len & 3)) : 4;
1045 ae->ad.bits.AttrLen =
1046 be16_to_cpu(FOURBYTES + len);
1048 size += FOURBYTES + len;
1051 pab->ab.EntryCnt = be32_to_cpu(pab->ab.EntryCnt);
1053 size = GID_REQUEST_SZ - 4 + size;
1058 CtReq->CommandResponse.bits.CmdRsp = be16_to_cpu(SLI_MGMT_DHBA);
1059 CtReq->CommandResponse.bits.Size = 0;
1060 pe = (PORT_ENTRY *) & CtReq->un.PortID;
1061 memcpy((uint8_t *) & pe->PortName,
1062 (uint8_t *) & phba->fc_sparam.portName,
1063 sizeof (struct lpfc_name));
1064 size = GID_REQUEST_SZ - 4 + sizeof (struct lpfc_name);
1068 CtReq->CommandResponse.bits.CmdRsp = be16_to_cpu(SLI_MGMT_DPRT);
1069 CtReq->CommandResponse.bits.Size = 0;
1070 pe = (PORT_ENTRY *) & CtReq->un.PortID;
1071 memcpy((uint8_t *) & pe->PortName,
1072 (uint8_t *) & phba->fc_sparam.portName,
1073 sizeof (struct lpfc_name));
1074 size = GID_REQUEST_SZ - 4 + sizeof (struct lpfc_name);
1078 bpl = (struct ulp_bde64 *) bmp->virt;
1079 bpl->addrHigh = le32_to_cpu( putPaddrHigh(mp->phys) );
1080 bpl->addrLow = le32_to_cpu( putPaddrLow(mp->phys) );
1081 bpl->tus.f.bdeFlags = 0;
1082 bpl->tus.f.bdeSize = size;
1083 bpl->tus.w = le32_to_cpu(bpl->tus.w);
1085 cmpl = lpfc_cmpl_ct_cmd_fdmi;
1087 if (!lpfc_ct_cmd(phba, mp, bmp, ndlp, cmpl, FC_MAX_NS_RSP))
1090 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
1093 fdmi_cmd_free_mpvirt:
1094 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1098 /* Issue FDMI request failed */
1099 lpfc_printf_log(phba,
1102 "%d:0244 Issue FDMI request failed Data: x%x\n",
1110 lpfc_fdmi_tmo(unsigned long ptr)
1112 struct lpfc_hba *phba = (struct lpfc_hba*)ptr;
1113 struct lpfc_nodelist *ndlp;
1114 unsigned long iflag;
1116 spin_lock_irqsave(phba->host->host_lock, iflag);
1117 ndlp = lpfc_findnode_did(phba, NLP_SEARCH_ALL, FDMI_DID);
1119 if (system_utsname.nodename[0] != '\0') {
1120 lpfc_fdmi_cmd(phba, ndlp, SLI_MGMT_DHBA);
1122 mod_timer(&phba->fc_fdmitmo, jiffies + HZ * 60);
1125 spin_unlock_irqrestore(phba->host->host_lock, iflag);
1131 lpfc_decode_firmware_rev(struct lpfc_hba * phba, char *fwrevision, int flag)
1133 struct lpfc_sli *psli = &phba->sli;
1134 lpfc_vpd_t *vp = &phba->vpd;
1135 uint32_t b1, b2, b3, b4, i, rev;
1137 uint32_t *ptr, str[4];
1141 if (psli->sliinit.sli_flag & LPFC_SLI2_ACTIVE)
1142 rev = vp->rev.sli2FwRev;
1144 rev = vp->rev.sli1FwRev;
1146 b1 = (rev & 0x0000f000) >> 12;
1147 b2 = (rev & 0x00000f00) >> 8;
1148 b3 = (rev & 0x000000c0) >> 6;
1149 b4 = (rev & 0x00000030) >> 4;
1165 b4 = (rev & 0x0000000f);
1167 if (psli->sliinit.sli_flag & LPFC_SLI2_ACTIVE)
1168 fwname = vp->rev.sli2FwName;
1170 fwname = vp->rev.sli1FwName;
1172 for (i = 0; i < 16; i++)
1173 if(fwname[i] == 0x20)
1176 ptr = (uint32_t*)fwname;
1178 for (i = 0; i < 3; i++)
1179 str[i] = be32_to_cpu(*ptr++);
1183 sprintf(fwrevision, "%d.%d%d (%s)",
1184 b1, b2, b3, (char *)str);
1186 sprintf(fwrevision, "%d.%d%d", b1,
1190 sprintf(fwrevision, "%d.%d%d%c%d (%s)",
1194 sprintf(fwrevision, "%d.%d%d%c%d",
1198 rev = vp->rev.smFwRev;
1200 b1 = (rev & 0xff000000) >> 24;
1201 b2 = (rev & 0x00f00000) >> 20;
1202 b3 = (rev & 0x000f0000) >> 16;
1203 c = (rev & 0x0000ff00) >> 8;
1204 b4 = (rev & 0x000000ff);
1207 sprintf(fwrevision, "%d.%d%d%c%d ", b1,
1210 sprintf(fwrevision, "%d.%d%d%c%d ", b1,
1217 lpfc_get_hba_model_desc(struct lpfc_hba * phba, uint8_t * mdp, uint8_t * descp)
1224 pci_read_config_dword(phba->pcidev, PCI_VENDOR_ID, &id);
1226 switch ((id >> 16) & 0xffff) {
1227 case PCI_DEVICE_ID_SUPERFLY:
1228 if (vp->rev.biuRev >= 1 && vp->rev.biuRev <= 3)
1229 strcpy(str, "LP7000 1");
1231 strcpy(str, "LP7000E 1");
1233 case PCI_DEVICE_ID_DRAGONFLY:
1234 strcpy(str, "LP8000 1");
1236 case PCI_DEVICE_ID_CENTAUR:
1237 if (FC_JEDEC_ID(vp->rev.biuRev) == CENTAUR_2G_JEDEC_ID)
1238 strcpy(str, "LP9002 2");
1240 strcpy(str, "LP9000 1");
1242 case PCI_DEVICE_ID_RFLY:
1243 strcpy(str, "LP952 2");
1245 case PCI_DEVICE_ID_PEGASUS:
1246 strcpy(str, "LP9802 2");
1248 case PCI_DEVICE_ID_THOR:
1249 strcpy(str, "LP10000 2");
1251 case PCI_DEVICE_ID_VIPER:
1252 strcpy(str, "LPX1000 10");
1254 case PCI_DEVICE_ID_PFLY:
1255 strcpy(str, "LP982 2");
1257 case PCI_DEVICE_ID_TFLY:
1258 strcpy(str, "LP1050 2");
1260 case PCI_DEVICE_ID_HELIOS:
1261 strcpy(str, "LP11000 4");
1263 case PCI_DEVICE_ID_BMID:
1264 strcpy(str, "LP1150 4");
1266 case PCI_DEVICE_ID_BSMB:
1267 strcpy(str, "LP111 4");
1269 case PCI_DEVICE_ID_ZEPHYR:
1270 strcpy(str, "LP11000e 4");
1272 case PCI_DEVICE_ID_ZMID:
1273 strcpy(str, "LP1150e 4");
1275 case PCI_DEVICE_ID_ZSMB:
1276 strcpy(str, "LP111e 4");
1278 case PCI_DEVICE_ID_LP101:
1279 strcpy(str, "LP101 2");
1283 sscanf(str, "%s", mdp);
1285 sprintf(descp, "Emulex LightPulse %s Gigabit PCI Fibre "
1286 "Channel Adapter", str);